Skip to content

Commit 5e27cb1

Browse files
committed
[ubsan] Assert that each check only has one SanitizerKind
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 the code, but will make it easier for maintainers to reason about and extend the `EmitCheck` function.
1 parent ba704d5 commit 5e27cb1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3603,6 +3603,8 @@ void CodeGenFunction::EmitCheck(
36033603
llvm::Value *TrapCond = nullptr;
36043604
bool NoMerge = false;
36053605
for (int i = 0, n = Checked.size(); i < n; ++i) {
3606+
assert(Checked[i].second.isPowerOf2());
3607+
36063608
llvm::Value *Check = Checked[i].first;
36073609
// -fsanitize-trap= overrides -fsanitize-recover=.
36083610
llvm::Value *&Cond =

0 commit comments

Comments
 (0)