llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Thurston Dang (thurstond)

<details>
<summary>Changes</summary>

The `Checked` parameter of `CodeGenFunction::EmitCheck` is of type 
`ArrayRef&lt;std::pair&lt;llvm::Value *, SanitizerMask&gt;&gt;`. In the general 
case, SanitizerMask can denote that zero or more sanitizers are enabled, but I 
believe (from tests and inspecting the code) that `EmitCheck` assumes exactly 
one sanitizer enabled per SanitizerMask. This patch adds an assertion for this 
invariant.

This is not intended to change the functionality of UBSan, but will make it 
easier for maintainers to reason about and extend the `EmitCheck` function.

---
Full diff: https://github.com/llvm/llvm-project/pull/122392.diff


1 Files Affected:

- (modified) clang/lib/CodeGen/CGExpr.cpp (+2) 


``````````diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 1bad7a722da07a..792fe05025e393 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3603,6 +3603,8 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *TrapCond = nullptr;
   bool NoMerge = false;
   for (int i = 0, n = Checked.size(); i < n; ++i) {
+    assert(Checked[i].second.isPowerOf2());
+
     llvm::Value *Check = Checked[i].first;
     // -fsanitize-trap= overrides -fsanitize-recover=.
     llvm::Value *&Cond =

``````````

</details>


https://github.com/llvm/llvm-project/pull/122392
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to