diff options
author | Thurston Dang <thurston@google.com> | 2025-06-06 14:59:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-06 14:59:32 -0700 |
commit | 428afa62b0aa1bb0ac344cbfc62429a60c42b265 (patch) | |
tree | 8ecd95edfec80811713ecd9dc8560d1e99c52d47 /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | a42bb8b57a6dcf298789ae88b36bbbba19e151fb (diff) | |
download | llvm-428afa62b0aa1bb0ac344cbfc62429a60c42b265.zip llvm-428afa62b0aa1bb0ac344cbfc62429a60c42b265.tar.gz llvm-428afa62b0aa1bb0ac344cbfc62429a60c42b265.tar.bz2 |
[ubsan] Add more -fsanitize-annotate-debug-info checks (#141997)
This extends https://github.com/llvm/llvm-project/pull/138577 to more UBSan checks, by changing SanitizerDebugLocation (formerly SanitizerScope) to add annotations if enabled for the specified ordinals.
Annotations will use the ordinal name if there is exactly one ordinal specified in the SanitizerDebugLocation; otherwise, it will use the handler name.
Updates the tests from https://github.com/llvm/llvm-project/pull/141814.
---------
Co-authored-by: Vitaly Buka <vitalybuka@google.com>
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 3302abad..5656200 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1636,10 +1636,11 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn, CGM.getCodeGenOpts().StrictReturn || !CGM.MayDropFunctionReturn(FD->getASTContext(), FD->getReturnType()); if (SanOpts.has(SanitizerKind::Return)) { - SanitizerScope SanScope(this); + auto CheckOrdinal = SanitizerKind::SO_Return; + auto CheckHandler = SanitizerHandler::MissingReturn; + SanitizerDebugLocation SanScope(this, {CheckOrdinal}, CheckHandler); llvm::Value *IsFalse = Builder.getFalse(); - EmitCheck(std::make_pair(IsFalse, SanitizerKind::SO_Return), - SanitizerHandler::MissingReturn, + EmitCheck(std::make_pair(IsFalse, CheckOrdinal), CheckHandler, EmitCheckSourceLocation(FD->getLocation()), {}); } else if (ShouldEmitUnreachable) { if (CGM.getCodeGenOpts().OptimizationLevel == 0) @@ -2541,7 +2542,9 @@ void CodeGenFunction::EmitVariablyModifiedType(QualType type) { // expression [...] each time it is evaluated it shall have a value // greater than zero. if (SanOpts.has(SanitizerKind::VLABound)) { - SanitizerScope SanScope(this); + auto CheckOrdinal = SanitizerKind::SO_VLABound; + auto CheckHandler = SanitizerHandler::VLABoundNotPositive; + SanitizerDebugLocation SanScope(this, {CheckOrdinal}, CheckHandler); llvm::Value *Zero = llvm::Constant::getNullValue(size->getType()); clang::QualType SEType = sizeExpr->getType(); llvm::Value *CheckCondition = @@ -2551,9 +2554,8 @@ void CodeGenFunction::EmitVariablyModifiedType(QualType type) { llvm::Constant *StaticArgs[] = { EmitCheckSourceLocation(sizeExpr->getBeginLoc()), EmitCheckTypeDescriptor(SEType)}; - EmitCheck( - std::make_pair(CheckCondition, SanitizerKind::SO_VLABound), - SanitizerHandler::VLABoundNotPositive, StaticArgs, size); + EmitCheck(std::make_pair(CheckCondition, CheckOrdinal), + CheckHandler, StaticArgs, size); } // Always zexting here would be wrong if it weren't @@ -3196,7 +3198,9 @@ void CodeGenFunction::emitAlignmentAssumptionCheck( Assumption->removeFromParent(); { - SanitizerScope SanScope(this); + auto CheckOrdinal = SanitizerKind::SO_Alignment; + auto CheckHandler = SanitizerHandler::AlignmentAssumption; + SanitizerDebugLocation SanScope(this, {CheckOrdinal}, CheckHandler); if (!OffsetValue) OffsetValue = Builder.getInt1(false); // no offset. @@ -3205,8 +3209,8 @@ void CodeGenFunction::emitAlignmentAssumptionCheck( EmitCheckSourceLocation(SecondaryLoc), EmitCheckTypeDescriptor(Ty)}; llvm::Value *DynamicData[] = {Ptr, Alignment, OffsetValue}; - EmitCheck({std::make_pair(TheCheck, SanitizerKind::SO_Alignment)}, - SanitizerHandler::AlignmentAssumption, StaticData, DynamicData); + EmitCheck({std::make_pair(TheCheck, CheckOrdinal)}, CheckHandler, + StaticData, DynamicData); } // We are now in the (new, empty) "cont" basic block. |