aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorThurston Dang <thurston@google.com>2025-01-10 12:40:57 -0800
committerGitHub <noreply@github.com>2025-01-10 12:40:57 -0800
commit55b587506e5dccb436e5405b7236671112b36244 (patch)
tree86c8416bf05dd11886cb836ebfa0447fee859d8d /clang/lib/CodeGen/CodeGenFunction.cpp
parent8e6261fff122590a75604340cb3fcaa121e85b46 (diff)
downloadllvm-55b587506e5dccb436e5405b7236671112b36244.zip
llvm-55b587506e5dccb436e5405b7236671112b36244.tar.gz
llvm-55b587506e5dccb436e5405b7236671112b36244.tar.bz2
[ubsan][NFCI] Use SanitizerOrdinal instead of SanitizerMask for EmitCheck (exactly one sanitizer is required) (#122511)
The `Checked` parameter of `CodeGenFunction::EmitCheck` is of type `ArrayRef<std::pair<llvm::Value *, SanitizerMask>>`, which is overly generalized: SanitizerMask can denote that zero or more sanitizers are enabled, but `EmitCheck` requires that exactly one sanitizer is specified in the SanitizerMask (e.g., `SanitizeTrap.has(Checked[i].second)` enforces that). This patch replaces SanitizerMask with SanitizerOrdinal in the `Checked` parameter of `EmitCheck` and code that transitively relies on it. This should not affect the behavior of UBSan, but it has the advantages that: - the code is clearer: it avoids ambiguity in EmitCheck about what to do if multiple bits are set - specifying the wrong number of sanitizers in `Checked[i].second` will be detected as a compile-time error, rather than a runtime assertion failure Suggested by Vitaly in https://github.com/llvm/llvm-project/pull/122392 as an alternative to adding an explicit runtime assertion that the SanitizerMask contains exactly one sanitizer.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 27ec68b..d6f3716 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1600,7 +1600,7 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
if (SanOpts.has(SanitizerKind::Return)) {
SanitizerScope SanScope(this);
llvm::Value *IsFalse = Builder.getFalse();
- EmitCheck(std::make_pair(IsFalse, SanitizerKind::Return),
+ EmitCheck(std::make_pair(IsFalse, SanitizerKind::SO_Return),
SanitizerHandler::MissingReturn,
EmitCheckSourceLocation(FD->getLocation()), {});
} else if (ShouldEmitUnreachable) {
@@ -2484,8 +2484,9 @@ void CodeGenFunction::EmitVariablyModifiedType(QualType type) {
llvm::Constant *StaticArgs[] = {
EmitCheckSourceLocation(sizeExpr->getBeginLoc()),
EmitCheckTypeDescriptor(SEType)};
- EmitCheck(std::make_pair(CheckCondition, SanitizerKind::VLABound),
- SanitizerHandler::VLABoundNotPositive, StaticArgs, size);
+ EmitCheck(
+ std::make_pair(CheckCondition, SanitizerKind::SO_VLABound),
+ SanitizerHandler::VLABoundNotPositive, StaticArgs, size);
}
// Always zexting here would be wrong if it weren't
@@ -3139,7 +3140,7 @@ void CodeGenFunction::emitAlignmentAssumptionCheck(
llvm::Value *DynamicData[] = {EmitCheckValue(Ptr),
EmitCheckValue(Alignment),
EmitCheckValue(OffsetValue)};
- EmitCheck({std::make_pair(TheCheck, SanitizerKind::Alignment)},
+ EmitCheck({std::make_pair(TheCheck, SanitizerKind::SO_Alignment)},
SanitizerHandler::AlignmentAssumption, StaticData, DynamicData);
}