https://github.com/anthonyhatran updated https://github.com/llvm/llvm-project/pull/143758
>From 0cf31b41838d449835296d4ec290209bd5aae1e6 Mon Sep 17 00:00:00 2001 From: Anthony Tran <anthonyt...@anthonys-air.lan> Date: Wed, 11 Jun 2025 10:11:09 -0700 Subject: [PATCH 1/2] Added Trap messages in debug info --- clang/lib/CodeGen/CGExpr.cpp | 117 +++++++++++++++++- clang/lib/CodeGen/CodeGenFunction.h | 3 +- .../CodeGen/ubsan-trap-reason-add-overflow.c | 10 ++ .../ubsan-trap-reason-builtin-unreachable.c | 12 ++ .../ubsan-trap-reason-div-rem-overflow.c | 10 ++ .../ubsan-trap-reason-float-cast-overflow.c | 10 ++ ...ubsan-trap-reason-function-type-mismatch.c | 16 +++ .../ubsan-trap-reason-implicit-conversion.c | 13 ++ .../ubsan-trap-reason-invalid-builtin.c | 12 ++ .../ubsan-trap-reason-load-invalid-value.c | 15 +++ .../ubsan-trap-reason-missing-return.cpp | 12 ++ .../CodeGen/ubsan-trap-reason-mul-overflow.c | 10 ++ .../ubsan-trap-reason-negate-overflow.c | 12 ++ .../CodeGen/ubsan-trap-reason-nonnull-arg.c | 17 +++ .../ubsan-trap-reason-nonnull-return.c | 15 +++ .../ubsan-trap-reason-nullability-arg.c | 19 +++ .../ubsan-trap-reason-nullability-return.c | 19 +++ .../CodeGen/ubsan-trap-reason-out-of-bounds.c | 12 ++ .../ubsan-trap-reason-pointer-overflow.c | 16 +++ .../ubsan-trap-reason-shift-out-of-bounds.c | 12 ++ .../CodeGen/ubsan-trap-reason-sub-overflow.c | 10 ++ .../CodeGen/ubsan-trap-reason-type-mismatch.c | 11 ++ 22 files changed, 379 insertions(+), 4 deletions(-) create mode 100644 clang/test/CodeGen/ubsan-trap-reason-add-overflow.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-builtin-unreachable.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-div-rem-overflow.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-float-cast-overflow.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-function-type-mismatch.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-implicit-conversion.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-invalid-builtin.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-load-invalid-value.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-missing-return.cpp create mode 100644 clang/test/CodeGen/ubsan-trap-reason-mul-overflow.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-negate-overflow.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-nonnull-arg.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-nonnull-return.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-nullability-arg.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-nullability-return.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-out-of-bounds.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-pointer-overflow.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-shift-out-of-bounds.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-sub-overflow.c create mode 100644 clang/test/CodeGen/ubsan-trap-reason-type-mismatch.c diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 85c768807572f..e37eaf948eb1a 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -85,6 +85,98 @@ enum VariableTypeDescriptorKind : uint16_t { // Miscellaneous Helper Methods //===--------------------------------------------------------------------===// +static llvm::StringRef GetTrapMessageForHandler(SanitizerHandler ID) { + switch (ID) { + case SanitizerHandler::AddOverflow: + return "The addition of two signed integers resulted in overflow."; + + case SanitizerHandler::BuiltinUnreachable: + return "_builtin_unreachable encountered."; + + case SanitizerHandler::CFICheckFail: + return "Control flow integrity check failed."; + + case SanitizerHandler::DivremOverflow: // Unsure + return "stub"; + + case SanitizerHandler::DynamicTypeCacheMiss: // Unsure + return "Data requested for dynamic type not found in cache memory."; + + case SanitizerHandler::FloatCastOverflow: // Pasted from LLVM docs, maybe + // something better to put here. + return "Conversion to, from, or between floating-point types which would " + "overflow the destination."; + + case SanitizerHandler::FunctionTypeMismatch: + return "Function called with arguments of a different data type than " + "expected"; + + case SanitizerHandler::ImplicitConversion: + return "Implicit conversion occurred."; + + case SanitizerHandler::InvalidBuiltin: + return "Built-in function or keyword not recognized."; + + case SanitizerHandler::InvalidObjCCast: + return "Invalid Objective-C cast."; + + case SanitizerHandler::LoadInvalidValue: + return "stub"; + + case SanitizerHandler::MissingReturn: + return "Function is missing a return."; + + case SanitizerHandler::MulOverflow: + return "The multiplication of two signed integers resulted in overflow."; + + case SanitizerHandler::NegateOverflow: + return "Underflow/negative overflow occurred."; + + case SanitizerHandler:: + NullabilityArg: // Next 4 pasted from + // https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html + return "Passing null as a function parameter which is annotated with " + "_Nonnull"; + + case SanitizerHandler::NullabilityReturn: + return "Returning null from a function with a return type annotated with " + "_Nonnull"; + + case SanitizerHandler::NonnullArg: + return "Passing null as a function parameter which is declared to never be " + "null"; + + case SanitizerHandler::NonnullReturn: + return "Returning null pointer from a function which is declared to never " + "be null"; + + case SanitizerHandler::OutOfBounds: + return "Out of bounds -- memory accessed outside of expected boundaries."; + + case SanitizerHandler::PointerOverflow: + return "stub"; + + case SanitizerHandler::ShiftOutOfBounds: + return "Bit shift attempted to move bits beyond boundaries of data type's " + "bit size."; + + case SanitizerHandler::SubOverflow: + return "The subtraction of two signed integers resulted in overflow."; + + case SanitizerHandler::TypeMismatch: + return "Type mismatch -- value type used does not match type expected."; + + case SanitizerHandler::AlignmentAssumption: // Help on bottom 2 + return "stub"; + + case SanitizerHandler::VLABoundNotPositive: + return "stub"; + + default: + return ""; + } +} + /// CreateTempAlloca - This creates a alloca and inserts it into the entry /// block. RawAddress @@ -4041,7 +4133,8 @@ void CodeGenFunction::EmitUnreachable(SourceLocation Loc) { void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID, - bool NoMerge) { + bool NoMerge, StringRef Annotation, + StringRef TrapMessage) { llvm::BasicBlock *Cont = createBasicBlock("cont"); // If we're optimizing, collapse all calls to trap down to just one per @@ -4051,6 +4144,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID]; + llvm::DILocation *TrapLocation = Builder.getCurrentDebugLocation(); + llvm::StringRef Category = GetTrapMessageForHandler(CheckHandlerID); + + if (getDebugInfo() && !Category.empty()) { + TrapLocation = getDebugInfo()->CreateTrapFailureMessageFor( + TrapLocation, Category, TrapMessage); + } + NoMerge = NoMerge || !CGM.getCodeGenOpts().OptimizationLevel || (CurCodeDecl && CurCodeDecl->hasAttr<OptimizeNoneAttr>()); @@ -4059,8 +4160,16 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, auto Call = TrapBB->begin(); assert(isa<llvm::CallInst>(Call) && "Expected call in trap BB"); - Call->applyMergedLocation(Call->getDebugLoc(), - Builder.getCurrentDebugLocation()); + // Call->applyMergedLocation(Call->getDebugLoc(), + // Builder.getCurrentDebugLocation()); + Call->applyMergedLocation(Call->getDebugLoc(), TrapLocation); + + auto Unreachable = ++TrapBB->begin(); + if (isa<llvm::UnreachableInst>(Unreachable)) { + Unreachable->applyMergedLocation(Unreachable->getDebugLoc(), + TrapLocation); + } + Builder.CreateCondBr(Checked, Cont, TrapBB, MDHelper.createLikelyBranchWeights()); } else { @@ -4069,6 +4178,8 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, MDHelper.createLikelyBranchWeights()); EmitBlock(TrapBB); + ApplyDebugLocation applyTrapDI(*this, TrapLocation); + llvm::CallInst *TrapCall = Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 59f14b3e35fd0..bd7f87647a35c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -5287,7 +5287,8 @@ class CodeGenFunction : public CodeGenTypeCache { /// Create a basic block that will call the trap intrinsic, and emit a /// conditional branch to it, for the -ftrapv checks. void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID, - bool NoMerge = false); + bool NoMerge = false, StringRef Annotation = "", + StringRef TrapMessage = ""); /// Emit a call to trap or debugtrap and attach function attribute /// "trap-func-name" if specified. diff --git a/clang/test/CodeGen/ubsan-trap-reason-add-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-add-overflow.c new file mode 100644 index 0000000000000..822a1c003d16a --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-add-overflow.c @@ -0,0 +1,10 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=undefined \ +// RUN: -fsanitize-trap=undefined -emit-llvm -S -c %s -o - | FileCheck %s + +int add_overflow(int a, int b) { + return a + b; +} + +// CHECK: call void @llvm.ubsantrap(i8 0) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ diff --git a/clang/test/CodeGen/ubsan-trap-reason-builtin-unreachable.c b/clang/test/CodeGen/ubsan-trap-reason-builtin-unreachable.c new file mode 100644 index 0000000000000..ada4c372a92b7 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-builtin-unreachable.c @@ -0,0 +1,12 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=unreachable \ +// RUN: -fsanitize-trap=unreachable -emit-llvm -S -c %s -o - | FileCheck %s + +int call_builtin_unreachable() +{ + __builtin_unreachable(); +} + + +// CHECK: call void @llvm.ubsantrap(i8 1) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-div-rem-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-div-rem-overflow.c new file mode 100644 index 0000000000000..17b6dca16cc62 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-div-rem-overflow.c @@ -0,0 +1,10 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=undefined \ +// RUN: -fsanitize-trap=undefined -emit-llvm -S -c %s -o - | FileCheck %s + +int div_rem_overflow(int a, int b) { + return a / b; +} + +// CHECK: call void @llvm.ubsantrap(i8 3) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ diff --git a/clang/test/CodeGen/ubsan-trap-reason-float-cast-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-float-cast-overflow.c new file mode 100644 index 0000000000000..b761e638c5293 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-float-cast-overflow.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O0 -debug-info-kind=standalone -dwarf-version=5 -fsanitize=float-cast-overflow \ +// RUN: -fsanitize-trap=float-cast-overflow -emit-llvm %s -o - | FileCheck %s + +int f(float x) { + return (int)x; +} + +// CHECK: call void @llvm.ubsantrap(i8 5) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-function-type-mismatch.c b/clang/test/CodeGen/ubsan-trap-reason-function-type-mismatch.c new file mode 100644 index 0000000000000..25063b69a894c --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-function-type-mismatch.c @@ -0,0 +1,16 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=undefined \ +// RUN: -fsanitize-trap=undefined -emit-llvm -S -c %s -o - | FileCheck %s + +void target() { } + +int function_type_mismatch() { + int (*fp_int)(int); + + fp_int = (int (*)(int))(void *)target; + + return fp_int(42); +} + +// CHECK: call void @llvm.ubsantrap(i8 6) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-implicit-conversion.c b/clang/test/CodeGen/ubsan-trap-reason-implicit-conversion.c new file mode 100644 index 0000000000000..48eb86d09b51a --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-implicit-conversion.c @@ -0,0 +1,13 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=implicit-conversion \ +// RUN: -fsanitize-trap=implicit-conversion -emit-llvm -S -c %s -o - | FileCheck %s + +unsigned long long big; + +unsigned implicit_conversion() +{ + return big; +} + +// CHECK: call void @llvm.ubsantrap(i8 7) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-invalid-builtin.c b/clang/test/CodeGen/ubsan-trap-reason-invalid-builtin.c new file mode 100644 index 0000000000000..cd136df2f0ed4 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-invalid-builtin.c @@ -0,0 +1,12 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=builtin \ +// RUN: -fsanitize-trap=builtin -emit-llvm -S -c %s -o - | FileCheck %s + +unsigned invalid_builtin(unsigned x) +{ + return __builtin_clz(x); +} + + +// CHECK: call void @llvm.ubsantrap(i8 8) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-load-invalid-value.c b/clang/test/CodeGen/ubsan-trap-reason-load-invalid-value.c new file mode 100644 index 0000000000000..09d8d588f0a32 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-load-invalid-value.c @@ -0,0 +1,15 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=undefined \ +// RUN: -fsanitize-trap=undefined -emit-llvm -S -c %s -o - | FileCheck %s +#include <stdbool.h> + +unsigned char bad_byte; + +bool load_invalid_value() +{ + return *((bool *)&bad_byte); +} + + +// CHECK: call void @llvm.ubsantrap(i8 10) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-missing-return.cpp b/clang/test/CodeGen/ubsan-trap-reason-missing-return.cpp new file mode 100644 index 0000000000000..7f0265abd2305 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-missing-return.cpp @@ -0,0 +1,12 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=return \ +// RUN: -fsanitize-trap=return -emit-llvm -S -c %s -o - | FileCheck %s + +int missing_return(int x) +{ + if (x > 0) + return x; +} + +// CHECK: call void @llvm.ubsantrap(i8 11) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-mul-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-mul-overflow.c new file mode 100644 index 0000000000000..e9f76b87455c9 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-mul-overflow.c @@ -0,0 +1,10 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=undefined \ +// RUN: -fsanitize-trap=undefined -emit-llvm -S -c %s -o - | FileCheck %s + +int mul_overflow(int a, int b) { + return a * b; +} + +// CHECK: call void @llvm.ubsantrap(i8 12) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ diff --git a/clang/test/CodeGen/ubsan-trap-reason-negate-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-negate-overflow.c new file mode 100644 index 0000000000000..5660c6bb08d03 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-negate-overflow.c @@ -0,0 +1,12 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=undefined \ +// RUN: -fsanitize-trap=undefined -emit-llvm -S -c %s -o - | FileCheck %s + +int negate_overflow() +{ + int x; + return -x; +} + +// CHECK: call void @llvm.ubsantrap(i8 13) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-nonnull-arg.c b/clang/test/CodeGen/ubsan-trap-reason-nonnull-arg.c new file mode 100644 index 0000000000000..e648f91b86b27 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-nonnull-arg.c @@ -0,0 +1,17 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=nonnull-attribute \ +// RUN: -fsanitize-trap=nonnull-attribute -emit-llvm -S -c %s -o - | FileCheck %s + +__attribute__((nonnull)) +void nonnull_arg(int *p) { + (void)p; +} + +void trigger_nonnull_arg() +{ + nonnull_arg(0); +} + + +// CHECK: call void @llvm.ubsantrap(i8 16) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-nonnull-return.c b/clang/test/CodeGen/ubsan-trap-reason-nonnull-return.c new file mode 100644 index 0000000000000..9b14004d96a02 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-nonnull-return.c @@ -0,0 +1,15 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=returns-nonnull-attribute \ +// RUN: -fsanitize-trap=returns-nonnull-attribute -emit-llvm -S -c %s -o - | FileCheck %s + +__attribute__((returns_nonnull)) +int* must_return_nonnull(int bad) +{ + if (bad) + return 0; + static int x = 1; + return &x; +} + +// CHECK: call void @llvm.ubsantrap(i8 17) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-nullability-arg.c b/clang/test/CodeGen/ubsan-trap-reason-nullability-arg.c new file mode 100644 index 0000000000000..e0d6a79b27c02 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-nullability-arg.c @@ -0,0 +1,19 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=nullability-arg \ +// RUN: -fsanitize-trap=nullability-arg -emit-llvm -S -c %s -o - | FileCheck %s + +#include <stddef.h> + +int nullability_arg(int* _Nonnull p) +{ + return *p; +} + +int trigger_nullability_arg() +{ + return nullability_arg(NULL); +} + + +// CHECK: call void @llvm.ubsantrap(i8 14) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-nullability-return.c b/clang/test/CodeGen/ubsan-trap-reason-nullability-return.c new file mode 100644 index 0000000000000..e10fc5b225221 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-nullability-return.c @@ -0,0 +1,19 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=nullability-return \ +// RUN: -fsanitize-trap=nullability-return -emit-llvm -S -c %s -o - | FileCheck %s + +#include <stdbool.h> +#include <stddef.h> + +int* _Nonnull nullability_return(bool fail) +{ + if (fail) + return NULL; + + static int x = 0; + return &x; +} + + +// CHECK: call void @llvm.ubsantrap(i8 15) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-out-of-bounds.c b/clang/test/CodeGen/ubsan-trap-reason-out-of-bounds.c new file mode 100644 index 0000000000000..9ed093fc528ed --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-out-of-bounds.c @@ -0,0 +1,12 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=bounds \ +// RUN: -fsanitize-trap=bounds -emit-llvm -S -c %s -o - | FileCheck %s + +int out_of_bounds() +{ + int a[1] = {0}; + return a[1]; +} + +// CHECK: call void @llvm.ubsantrap(i8 18) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-pointer-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-pointer-overflow.c new file mode 100644 index 0000000000000..93ae42208520f --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-pointer-overflow.c @@ -0,0 +1,16 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=pointer-overflow \ +// RUN: -fsanitize-trap=pointer-overflow -emit-llvm -S -c %s -o - | FileCheck %s + +#include <stddef.h> +#include <stdint.h> + +int* pointer_overflow(void) +{ + int buf[4]; + volatile size_t n = (SIZE_MAX / sizeof(int)) - 1; + return buf + n; +} + +// CHECK: call void @llvm.ubsantrap(i8 19) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-shift-out-of-bounds.c b/clang/test/CodeGen/ubsan-trap-reason-shift-out-of-bounds.c new file mode 100644 index 0000000000000..6f5aff7cd197a --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-shift-out-of-bounds.c @@ -0,0 +1,12 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=shift \ +// RUN: -fsanitize-trap=shift -emit-llvm -S -c %s -o - | FileCheck %s + +int shift_out_of_bounds() +{ + int sh = 32; + return 1 << sh; +} + +// CHECK: call void @llvm.ubsantrap(i8 20) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-sub-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-sub-overflow.c new file mode 100644 index 0000000000000..3f7c5639aecf7 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-sub-overflow.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow -emit-llvm %s -o - | FileCheck %s + +int sub_overflow(int a, int b) { + return a - b; +} + +// CHECK: call void @llvm.ubsantrap(i8 21) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-type-mismatch.c b/clang/test/CodeGen/ubsan-trap-reason-type-mismatch.c new file mode 100644 index 0000000000000..3907e8e239a04 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-type-mismatch.c @@ -0,0 +1,11 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=undefined \ +// RUN: -fsanitize-trap=undefined -emit-llvm -S -c %s -o - | FileCheck %s + +int type_mismatch(int *p) +{ + return *p; +} + +// CHECK: call void @llvm.ubsantrap(i8 22) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file >From e40a02746df3d20e426cea7042e8ac9faf0f2c7b Mon Sep 17 00:00:00 2001 From: Anthony Tran <anthonyt...@anthonys-air.lan> Date: Mon, 23 Jun 2025 03:08:16 -0700 Subject: [PATCH 2/2] Address Michael's review and changed string descriptions --- clang/lib/CodeGen/CGExpr.cpp | 60 +++++++++---------- clang/lib/CodeGen/CodeGenFunction.h | 3 +- .../CodeGen/ubsan-trap-reason-add-overflow.c | 2 +- .../ubsan-trap-reason-builtin-unreachable.c | 2 +- .../ubsan-trap-reason-div-rem-overflow.c | 2 +- .../ubsan-trap-reason-float-cast-overflow.c | 2 +- ...ubsan-trap-reason-function-type-mismatch.c | 2 +- .../ubsan-trap-reason-implicit-conversion.c | 2 +- .../ubsan-trap-reason-invalid-builtin.c | 2 +- .../ubsan-trap-reason-load-invalid-value.c | 2 +- .../ubsan-trap-reason-missing-return.cpp | 2 +- .../CodeGen/ubsan-trap-reason-mul-overflow.c | 2 +- .../ubsan-trap-reason-negate-overflow.c | 2 +- .../CodeGen/ubsan-trap-reason-nonnull-arg.c | 2 +- .../ubsan-trap-reason-nonnull-return.c | 2 +- .../ubsan-trap-reason-nullability-arg.c | 2 +- .../ubsan-trap-reason-nullability-return.c | 2 +- .../CodeGen/ubsan-trap-reason-out-of-bounds.c | 2 +- .../ubsan-trap-reason-pointer-overflow.c | 2 +- .../ubsan-trap-reason-shift-out-of-bounds.c | 2 +- .../CodeGen/ubsan-trap-reason-sub-overflow.c | 2 +- .../CodeGen/ubsan-trap-reason-type-mismatch.c | 2 +- ...ubsan-trap-reason-vla-bound-not-positive.c | 14 +++++ 23 files changed, 62 insertions(+), 55 deletions(-) create mode 100644 clang/test/CodeGen/ubsan-trap-reason-vla-bound-not-positive.c diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index e37eaf948eb1a..126286e073628 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -88,53 +88,48 @@ enum VariableTypeDescriptorKind : uint16_t { static llvm::StringRef GetTrapMessageForHandler(SanitizerHandler ID) { switch (ID) { case SanitizerHandler::AddOverflow: - return "The addition of two signed integers resulted in overflow."; + return "Signed integer addition overflowed."; case SanitizerHandler::BuiltinUnreachable: - return "_builtin_unreachable encountered."; + return "_builtin_unreachable() executed."; case SanitizerHandler::CFICheckFail: - return "Control flow integrity check failed."; + return "Control flow integrity check failed"; - case SanitizerHandler::DivremOverflow: // Unsure - return "stub"; + case SanitizerHandler::DivremOverflow: + return "Signed integer divide or remainder overflowed"; - case SanitizerHandler::DynamicTypeCacheMiss: // Unsure - return "Data requested for dynamic type not found in cache memory."; + case SanitizerHandler::DynamicTypeCacheMiss: + return "Dynamic-type cache miss"; - case SanitizerHandler::FloatCastOverflow: // Pasted from LLVM docs, maybe - // something better to put here. - return "Conversion to, from, or between floating-point types which would " - "overflow the destination."; + case SanitizerHandler::FloatCastOverflow: + return "Floating-point to integer conversion overflowed"; case SanitizerHandler::FunctionTypeMismatch: - return "Function called with arguments of a different data type than " - "expected"; + return "Function called with mismatched signature"; case SanitizerHandler::ImplicitConversion: - return "Implicit conversion occurred."; + return "Implicit integer conversion overflowed or lost data"; case SanitizerHandler::InvalidBuiltin: - return "Built-in function or keyword not recognized."; + return "Invalid use of builtin function"; case SanitizerHandler::InvalidObjCCast: return "Invalid Objective-C cast."; case SanitizerHandler::LoadInvalidValue: - return "stub"; + return "Loaded an invalid or uninitialized value"; case SanitizerHandler::MissingReturn: - return "Function is missing a return."; + return "Non-void function fell off end without return"; case SanitizerHandler::MulOverflow: - return "The multiplication of two signed integers resulted in overflow."; + return "Signed integer multiplication overflowed"; case SanitizerHandler::NegateOverflow: - return "Underflow/negative overflow occurred."; + return "Signed integer negation overflowed"; - case SanitizerHandler:: - NullabilityArg: // Next 4 pasted from - // https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html + case SanitizerHandler::NullabilityArg: return "Passing null as a function parameter which is annotated with " "_Nonnull"; @@ -151,26 +146,25 @@ static llvm::StringRef GetTrapMessageForHandler(SanitizerHandler ID) { "be null"; case SanitizerHandler::OutOfBounds: - return "Out of bounds -- memory accessed outside of expected boundaries."; + return "Array index out of bounds"; case SanitizerHandler::PointerOverflow: - return "stub"; + return "Pointer arithmetic overflowed bounds"; case SanitizerHandler::ShiftOutOfBounds: - return "Bit shift attempted to move bits beyond boundaries of data type's " - "bit size."; + return "Shift amount exceeds bit-width of operand"; case SanitizerHandler::SubOverflow: - return "The subtraction of two signed integers resulted in overflow."; + return "Signed integer subtraction overflowed"; case SanitizerHandler::TypeMismatch: - return "Type mismatch -- value type used does not match type expected."; + return "Type mismatch in operation"; case SanitizerHandler::AlignmentAssumption: // Help on bottom 2 - return "stub"; + return "Alignment assumption violated"; case SanitizerHandler::VLABoundNotPositive: - return "stub"; + return "Variable-length array bound is not positive"; default: return ""; @@ -4133,8 +4127,7 @@ void CodeGenFunction::EmitUnreachable(SourceLocation Loc) { void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID, - bool NoMerge, StringRef Annotation, - StringRef TrapMessage) { + bool NoMerge) { llvm::BasicBlock *Cont = createBasicBlock("cont"); // If we're optimizing, collapse all calls to trap down to just one per @@ -4145,7 +4138,8 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID]; llvm::DILocation *TrapLocation = Builder.getCurrentDebugLocation(); - llvm::StringRef Category = GetTrapMessageForHandler(CheckHandlerID); + llvm::StringRef Category = "UBSan Trap Reason"; + llvm::StringRef TrapMessage = GetTrapMessageForHandler(CheckHandlerID); if (getDebugInfo() && !Category.empty()) { TrapLocation = getDebugInfo()->CreateTrapFailureMessageFor( diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index bd7f87647a35c..59f14b3e35fd0 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -5287,8 +5287,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// Create a basic block that will call the trap intrinsic, and emit a /// conditional branch to it, for the -ftrapv checks. void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID, - bool NoMerge = false, StringRef Annotation = "", - StringRef TrapMessage = ""); + bool NoMerge = false); /// Emit a call to trap or debugtrap and attach function attribute /// "trap-func-name" if specified. diff --git a/clang/test/CodeGen/ubsan-trap-reason-add-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-add-overflow.c index 822a1c003d16a..e141ec515c260 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-add-overflow.c +++ b/clang/test/CodeGen/ubsan-trap-reason-add-overflow.c @@ -7,4 +7,4 @@ int add_overflow(int a, int b) { // CHECK: call void @llvm.ubsantrap(i8 0) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason diff --git a/clang/test/CodeGen/ubsan-trap-reason-builtin-unreachable.c b/clang/test/CodeGen/ubsan-trap-reason-builtin-unreachable.c index ada4c372a92b7..f64b50fb110dd 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-builtin-unreachable.c +++ b/clang/test/CodeGen/ubsan-trap-reason-builtin-unreachable.c @@ -9,4 +9,4 @@ int call_builtin_unreachable() // CHECK: call void @llvm.ubsantrap(i8 1) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-div-rem-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-div-rem-overflow.c index 17b6dca16cc62..91b37fa5d2f95 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-div-rem-overflow.c +++ b/clang/test/CodeGen/ubsan-trap-reason-div-rem-overflow.c @@ -7,4 +7,4 @@ int div_rem_overflow(int a, int b) { // CHECK: call void @llvm.ubsantrap(i8 3) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason diff --git a/clang/test/CodeGen/ubsan-trap-reason-float-cast-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-float-cast-overflow.c index b761e638c5293..79b36495c5dcb 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-float-cast-overflow.c +++ b/clang/test/CodeGen/ubsan-trap-reason-float-cast-overflow.c @@ -7,4 +7,4 @@ int f(float x) { // CHECK: call void @llvm.ubsantrap(i8 5) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-function-type-mismatch.c b/clang/test/CodeGen/ubsan-trap-reason-function-type-mismatch.c index 25063b69a894c..140cbc61107d5 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-function-type-mismatch.c +++ b/clang/test/CodeGen/ubsan-trap-reason-function-type-mismatch.c @@ -13,4 +13,4 @@ int function_type_mismatch() { // CHECK: call void @llvm.ubsantrap(i8 6) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-implicit-conversion.c b/clang/test/CodeGen/ubsan-trap-reason-implicit-conversion.c index 48eb86d09b51a..f4ce6c37533b2 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-implicit-conversion.c +++ b/clang/test/CodeGen/ubsan-trap-reason-implicit-conversion.c @@ -10,4 +10,4 @@ unsigned implicit_conversion() // CHECK: call void @llvm.ubsantrap(i8 7) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-invalid-builtin.c b/clang/test/CodeGen/ubsan-trap-reason-invalid-builtin.c index cd136df2f0ed4..7f1c5505732c1 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-invalid-builtin.c +++ b/clang/test/CodeGen/ubsan-trap-reason-invalid-builtin.c @@ -9,4 +9,4 @@ unsigned invalid_builtin(unsigned x) // CHECK: call void @llvm.ubsantrap(i8 8) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-load-invalid-value.c b/clang/test/CodeGen/ubsan-trap-reason-load-invalid-value.c index 09d8d588f0a32..aee62441d3b9a 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-load-invalid-value.c +++ b/clang/test/CodeGen/ubsan-trap-reason-load-invalid-value.c @@ -12,4 +12,4 @@ bool load_invalid_value() // CHECK: call void @llvm.ubsantrap(i8 10) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-missing-return.cpp b/clang/test/CodeGen/ubsan-trap-reason-missing-return.cpp index 7f0265abd2305..cc43815dd9066 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-missing-return.cpp +++ b/clang/test/CodeGen/ubsan-trap-reason-missing-return.cpp @@ -9,4 +9,4 @@ int missing_return(int x) // CHECK: call void @llvm.ubsantrap(i8 11) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-mul-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-mul-overflow.c index e9f76b87455c9..a56dba170f01f 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-mul-overflow.c +++ b/clang/test/CodeGen/ubsan-trap-reason-mul-overflow.c @@ -7,4 +7,4 @@ int mul_overflow(int a, int b) { // CHECK: call void @llvm.ubsantrap(i8 12) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason diff --git a/clang/test/CodeGen/ubsan-trap-reason-negate-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-negate-overflow.c index 5660c6bb08d03..f395770e37adf 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-negate-overflow.c +++ b/clang/test/CodeGen/ubsan-trap-reason-negate-overflow.c @@ -9,4 +9,4 @@ int negate_overflow() // CHECK: call void @llvm.ubsantrap(i8 13) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-nonnull-arg.c b/clang/test/CodeGen/ubsan-trap-reason-nonnull-arg.c index e648f91b86b27..16c9ce1101626 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-nonnull-arg.c +++ b/clang/test/CodeGen/ubsan-trap-reason-nonnull-arg.c @@ -14,4 +14,4 @@ void trigger_nonnull_arg() // CHECK: call void @llvm.ubsantrap(i8 16) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-nonnull-return.c b/clang/test/CodeGen/ubsan-trap-reason-nonnull-return.c index 9b14004d96a02..ca55ac201cb4d 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-nonnull-return.c +++ b/clang/test/CodeGen/ubsan-trap-reason-nonnull-return.c @@ -12,4 +12,4 @@ int* must_return_nonnull(int bad) // CHECK: call void @llvm.ubsantrap(i8 17) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-nullability-arg.c b/clang/test/CodeGen/ubsan-trap-reason-nullability-arg.c index e0d6a79b27c02..0520473e51104 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-nullability-arg.c +++ b/clang/test/CodeGen/ubsan-trap-reason-nullability-arg.c @@ -16,4 +16,4 @@ int trigger_nullability_arg() // CHECK: call void @llvm.ubsantrap(i8 14) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-nullability-return.c b/clang/test/CodeGen/ubsan-trap-reason-nullability-return.c index e10fc5b225221..a9b4bb570f6cb 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-nullability-return.c +++ b/clang/test/CodeGen/ubsan-trap-reason-nullability-return.c @@ -16,4 +16,4 @@ int* _Nonnull nullability_return(bool fail) // CHECK: call void @llvm.ubsantrap(i8 15) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-out-of-bounds.c b/clang/test/CodeGen/ubsan-trap-reason-out-of-bounds.c index 9ed093fc528ed..dcfbdf30d10b4 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-out-of-bounds.c +++ b/clang/test/CodeGen/ubsan-trap-reason-out-of-bounds.c @@ -9,4 +9,4 @@ int out_of_bounds() // CHECK: call void @llvm.ubsantrap(i8 18) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-pointer-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-pointer-overflow.c index 93ae42208520f..b80c127323966 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-pointer-overflow.c +++ b/clang/test/CodeGen/ubsan-trap-reason-pointer-overflow.c @@ -13,4 +13,4 @@ int* pointer_overflow(void) // CHECK: call void @llvm.ubsantrap(i8 19) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-shift-out-of-bounds.c b/clang/test/CodeGen/ubsan-trap-reason-shift-out-of-bounds.c index 6f5aff7cd197a..d79bea14af457 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-shift-out-of-bounds.c +++ b/clang/test/CodeGen/ubsan-trap-reason-shift-out-of-bounds.c @@ -9,4 +9,4 @@ int shift_out_of_bounds() // CHECK: call void @llvm.ubsantrap(i8 20) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-sub-overflow.c b/clang/test/CodeGen/ubsan-trap-reason-sub-overflow.c index 3f7c5639aecf7..45f7b67c5c4d4 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-sub-overflow.c +++ b/clang/test/CodeGen/ubsan-trap-reason-sub-overflow.c @@ -7,4 +7,4 @@ int sub_overflow(int a, int b) { // CHECK: call void @llvm.ubsantrap(i8 21) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-type-mismatch.c b/clang/test/CodeGen/ubsan-trap-reason-type-mismatch.c index 3907e8e239a04..fd64916d5ac2c 100644 --- a/clang/test/CodeGen/ubsan-trap-reason-type-mismatch.c +++ b/clang/test/CodeGen/ubsan-trap-reason-type-mismatch.c @@ -8,4 +8,4 @@ int type_mismatch(int *p) // CHECK: call void @llvm.ubsantrap(i8 22) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$ \ No newline at end of file +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-vla-bound-not-positive.c b/clang/test/CodeGen/ubsan-trap-reason-vla-bound-not-positive.c new file mode 100644 index 0000000000000..d128c3e2de77a --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-vla-bound-not-positive.c @@ -0,0 +1,14 @@ +// RUN: %clang -O0 -g -debug-info-kind=standalone -dwarf-version=5 -fsanitize=undefined \ +// RUN: -fsanitize-trap=undefined -emit-llvm -S -c %s -o - | FileCheck %s + +int n = 0; + +int vla_bound_not_positive() +{ + int a[n]; + return sizeof a; +} + +// CHECK: call void @llvm.ubsantrap(i8 24) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$UBSan Trap Reason \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits