llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-codegen Author: Anthony Tran (anthonyhatran) <details> <summary>Changes</summary> --- Patch is 25.66 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/145967.diff 26 Files Affected: - (modified) clang/lib/CodeGen/CGExpr.cpp (+98-2) - (added) clang/test/CodeGen/ubsan-trap-reason-add-overflow.c (+10) - (added) clang/test/CodeGen/ubsan-trap-reason-alignment-assumption.c (+14) - (added) clang/test/CodeGen/ubsan-trap-reason-builtin-unreachable.c (+11) - (added) clang/test/CodeGen/ubsan-trap-reason-cfi-check-fail.c (+27) - (added) clang/test/CodeGen/ubsan-trap-reason-div-rem-overflow.c (+10) - (added) clang/test/CodeGen/ubsan-trap-reason-dynamic-type-cache-miss.cpp (+23) - (added) clang/test/CodeGen/ubsan-trap-reason-float-cast-overflow.c (+10) - (added) clang/test/CodeGen/ubsan-trap-reason-function-type-mismatch.c (+16) - (added) clang/test/CodeGen/ubsan-trap-reason-implicit-conversion.c (+13) - (added) clang/test/CodeGen/ubsan-trap-reason-invalid-builtin.c (+11) - (added) clang/test/CodeGen/ubsan-trap-reason-invalid-objc-cast.m (+31) - (added) clang/test/CodeGen/ubsan-trap-reason-load-invalid-value.c (+15) - (added) clang/test/CodeGen/ubsan-trap-reason-missing-return.cpp (+12) - (added) clang/test/CodeGen/ubsan-trap-reason-mul-overflow.c (+10) - (added) clang/test/CodeGen/ubsan-trap-reason-negate-overflow.c (+12) - (added) clang/test/CodeGen/ubsan-trap-reason-nonnull-arg.c (+16) - (added) clang/test/CodeGen/ubsan-trap-reason-nonnull-return.c (+15) - (added) clang/test/CodeGen/ubsan-trap-reason-nullability-arg.c (+18) - (added) clang/test/CodeGen/ubsan-trap-reason-nullability-return.c (+18) - (added) clang/test/CodeGen/ubsan-trap-reason-out-of-bounds.c (+12) - (added) clang/test/CodeGen/ubsan-trap-reason-pointer-overflow.c (+16) - (added) clang/test/CodeGen/ubsan-trap-reason-shift-out-of-bounds.c (+12) - (added) clang/test/CodeGen/ubsan-trap-reason-sub-overflow.c (+10) - (added) clang/test/CodeGen/ubsan-trap-reason-type-mismatch.c (+11) - (added) clang/test/CodeGen/ubsan-trap-reason-vla-bound-not-positive.c (+14) ``````````diff diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 85c768807572f..34fd8b4aef0f2 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -85,6 +85,94 @@ enum VariableTypeDescriptorKind : uint16_t { // Miscellaneous Helper Methods //===--------------------------------------------------------------------===// +static llvm::StringRef GetUBSanTrapForHandler(SanitizerHandler ID) { + switch (ID) { + case SanitizerHandler::AddOverflow: + return "Signed integer addition overflowed"; + + case SanitizerHandler::BuiltinUnreachable: + return "_builtin_unreachable(), execution reached an unreachable program " + "point"; + + case SanitizerHandler::CFICheckFail: + return "Control flow integrity check failed"; + + case SanitizerHandler::DivremOverflow: + return "Signed integer divide or remainder overflowed"; + + case SanitizerHandler::DynamicTypeCacheMiss: + return "Dynamic-type cache miss"; + + case SanitizerHandler::FloatCastOverflow: + return "Floating-point to integer conversion overflowed"; + + case SanitizerHandler::FunctionTypeMismatch: + return "Function called with mismatched signature"; + + case SanitizerHandler::ImplicitConversion: + return "Implicit integer conversion overflowed or lost data"; + + case SanitizerHandler::InvalidBuiltin: + return "Invalid use of builtin function"; + + case SanitizerHandler::InvalidObjCCast: + return "Invalid Objective-C cast"; + + case SanitizerHandler::LoadInvalidValue: + return "Loaded an invalid or uninitialized value for the type"; + + case SanitizerHandler::MissingReturn: + return "Execution reached the end of a value-returning function without " + "returning a value"; + + case SanitizerHandler::MulOverflow: + return "Signed integer multiplication overflowed"; + + case SanitizerHandler::NegateOverflow: + return "Signed integer negation overflowed"; + + case SanitizerHandler::NullabilityArg: + return "Passing null as an argument 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 pointer as an argument which is declared to never be " + "null"; + + case SanitizerHandler::NonnullReturn: + return "Returning null pointer from a function which is declared to never " + "return null"; + + case SanitizerHandler::OutOfBounds: + return "Array index out of bounds"; + + case SanitizerHandler::PointerOverflow: + return "Pointer arithmetic overflowed bounds"; + + case SanitizerHandler::ShiftOutOfBounds: + return "Shift exponent is too large for the type"; + + case SanitizerHandler::SubOverflow: + return "Signed integer subtraction overflowed"; + + case SanitizerHandler::TypeMismatch: + return "Type mismatch in operation"; + + case SanitizerHandler::AlignmentAssumption: + return "Alignment assumption violated"; + + case SanitizerHandler::VLABoundNotPositive: + return "Variable length array bound evaluates to non-positive value"; + + case SanitizerHandler::BoundsSafety: + return {}; + } +} + /// CreateTempAlloca - This creates a alloca and inserts it into the entry /// block. RawAddress @@ -4051,6 +4139,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID]; + llvm::DILocation *TrapLocation = Builder.getCurrentDebugLocation(); + llvm::StringRef TrapMessage = GetUBSanTrapForHandler(CheckHandlerID); + + if (getDebugInfo()) { + TrapLocation = getDebugInfo()->CreateTrapFailureMessageFor( + TrapLocation, "Undefined Behavior Sanitizer", TrapMessage); + } + NoMerge = NoMerge || !CGM.getCodeGenOpts().OptimizationLevel || (CurCodeDecl && CurCodeDecl->hasAttr<OptimizeNoneAttr>()); @@ -4059,8 +4155,8 @@ 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(), TrapLocation); + Builder.CreateCondBr(Checked, Cont, TrapBB, MDHelper.createLikelyBranchWeights()); } else { 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..4b3881ae9c7dc --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-add-overflow.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -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 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$Undefined Behavior Sanitizer diff --git a/clang/test/CodeGen/ubsan-trap-reason-alignment-assumption.c b/clang/test/CodeGen/ubsan-trap-reason-alignment-assumption.c new file mode 100644 index 0000000000000..a41a238eaf129 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-alignment-assumption.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - | FileCheck %s + +#include <stdint.h> +int32_t* get_int(void) __attribute__((assume_aligned(16))); + +void retrieve_int(void) { + int* i = get_int(); + *i = 7; +} + +// CHECK: call void @llvm.ubsantrap(i8 23) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$Undefined Behavior Sanitizer \ No newline at end of file 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..a85d92319cb7b --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-builtin-unreachable.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=unreachable -fsanitize-trap=unreachable -emit-llvm %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$Undefined Behavior Sanitizer \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-cfi-check-fail.c b/clang/test/CodeGen/ubsan-trap-reason-cfi-check-fail.c new file mode 100644 index 0000000000000..da6c9bc7fb2f9 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-cfi-check-fail.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -emit-llvm %s -o - | FileCheck %s + +typedef int (*fp_t)(int); + +int good(int x) { + return x + 1; +} + +int bad(void) { + return 0; +} + +int cfi_trigger(int a) { + fp_t p = good; + int r1 = p(a); + + p = (fp_t)(void*)bad; + int r2 = p(a); + + return r1 + r2; +} + + +// CHECK: call void @llvm.ubsantrap(i8 2) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$Undefined Behavior Sanitizer \ 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..f98927399272f --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-div-rem-overflow.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -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 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$Undefined Behavior Sanitizer \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-dynamic-type-cache-miss.cpp b/clang/test/CodeGen/ubsan-trap-reason-dynamic-type-cache-miss.cpp new file mode 100644 index 0000000000000..e279626f09227 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-dynamic-type-cache-miss.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=vptr -fsanitize-trap=vptr -emit-llvm %s -o - | FileCheck %s + +struct A { + virtual void foo(); +}; +struct B { + virtual void bar(); +}; + +void A::foo() { } +void B::bar() { } + +int dynamic_type_cache_miss() { + B b; + A &a = reinterpret_cast<A&>(b); + a.foo(); + return 0; +} + +// CHECK: call void @llvm.ubsantrap(i8 4) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$Undefined Behavior Sanitizer 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..0524d8bbf9373 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-float-cast-overflow.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=float-cast-overflow -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$Undefined Behavior Sanitizer \ 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..8811a064a51c0 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-function-type-mismatch.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=function -fsanitize-trap=function -emit-llvm %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$Undefined Behavior Sanitizer \ 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..6e98aeacb17c9 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-implicit-conversion.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=implicit-unsigned-integer-truncation -fsanitize-trap=implicit-unsigned-integer-truncation -emit-llvm %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$Undefined Behavior Sanitizer \ 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..4703518e11e6e --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-invalid-builtin.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=builtin -fsanitize-trap=builtin -emit-llvm %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$Undefined Behavior Sanitizer \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-invalid-objc-cast.m b/clang/test/CodeGen/ubsan-trap-reason-invalid-objc-cast.m new file mode 100644 index 0000000000000..f7460b186b9b3 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-invalid-objc-cast.m @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=objc-cast -fsanitize-trap=objc-cast -emit-llvm %s -o - | FileCheck %s + +@interface NSFastEnumerationState +@end + +#define NSUInteger unsigned int + +@interface NSArray ++(NSArray*) arrayWithObjects: (id) first, ...; +- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *) state + objects:(id[]) buffer + count:(NSUInteger) len; +-(unsigned) count; +@end +@interface NSString +-(const char*) cString; +@end + +void receive_NSString(NSString*); + +void t0(void) { + NSArray *array = [NSArray arrayWithObjects: @"0", @"1", (void*)0]; + for (NSString *i in array) { + receive_NSString(i); + } +} + +// CHECK: call void @llvm.ubsantrap(i8 9) {{.*}}!dbg [[LOC:![0-9]+]] +// CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) +// CHECK: distinct !DISubprogram(name: "__clang_trap_msg$Undefined Behavior Sanitizer \ 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..e751d5135a50e --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-load-invalid-value.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=bool -fsanitize-trap=bool -emit-llvm %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$Undefined Behavior Sanitizer \ 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..d97523e503eff --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-missing-return.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=return -fsanitize-trap=return -emit-llvm %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$Undefined Behavior Sanitizer \ 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..5250e70e61b43 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-mul-overflow.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -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 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$Undefined Behavior Sanitizer \ No newline at end of file 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..4273efaced40d --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-negate-overflow.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -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 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$Undefined Behavior Sanitizer \ 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..e0849c6b81c32 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-nonnull-arg.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=nonnull-attribute -fsanitize-trap=nonnull-attribute -emit-llvm %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$Undefined Behavior Sanitizer \ 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..b513957775c86 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-nonnull-return.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=returns-nonnull-attribute -fsanitize-trap=returns-nonnull-attribute -emit-llvm %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$Undefined Behavior Sanitizer \ 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..e8012d05e3741 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-reason-nullability-arg.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple arm64-apple-macosx14.0.0 -O0 -debug-info-kind=standalone -dwarf-version=5 \ +// RUN: -fsanitize=nullability-arg -fsanitize-trap=nullability-arg -emit-llvm %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$Undefined Behavior Sanitizer \ No newline at end of file diff --git a/clang/test/CodeGen/ubsan-trap-reason-nullability-return.c b/clang/test/Code... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/145967 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits