[clang] [ubsan] Assert that each check only has one SanitizerKind (PR #122392)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 9 16:08:30 PST 2025
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<std::pair<llvm::Value *, SanitizerMask>>`. 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
More information about the cfe-commits
mailing list