Skip to content

Commit 954e3e4

Browse files
committed
[BoundsSan] Update BoundsChecking.cpp to use no-merge attribute where applicable
#65972 introduced -ubsan-unique-traps and -bounds-checking-unique-traps, which attach the function size to the ubsantrap intrinsic. #117651 changed ubsan-unique-traps to use nomerge instead of the function size, but did not update -bounds-checking-unique-traps. This patch adds nomerge to bounds-checking-unique-traps.
1 parent c2dd612 commit 954e3e4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

clang/test/CodeGen/bounds-checking.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ char B[10];
7373
char B2[10];
7474
// CHECK-LABEL: @f8
7575
void f8(int i, int k) {
76-
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 3)
76+
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) #[[ATTR1:[0-9]+]]
7777
// NOOPTARRAY: call void @llvm.ubsantrap(i8 18)
7878
B[i] = '\0';
7979

80-
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 5)
80+
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) #[[ATTR1:[0-9]+]]
8181
// NOOPTARRAY: call void @llvm.ubsantrap(i8 18)
8282
B2[k] = '\0';
8383
}
@@ -90,3 +90,4 @@ struct S {
9090
struct S *f9(int i) {
9191
return &s[i];
9292
}
93+
// NOOPTLOCAL: attributes #[[ATTR1]] = { nomerge noreturn nounwind }

llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI,
196196

197197
CallInst *TrapCall;
198198
if (DebugTrapBB) {
199+
// Ideally we would use the SanitizerHandler::OutOfBounds constant
199200
TrapCall = IRB.CreateIntrinsic(
200201
IntrID, {}, ConstantInt::get(IRB.getInt8Ty(), Fn->size()));
202+
TrapCall->addFnAttr(llvm::Attribute::NoMerge);
201203
} else {
202204
TrapCall = IRB.CreateIntrinsic(IntrID, {}, {});
203205
}
@@ -251,4 +253,4 @@ void BoundsCheckingPass::printPipeline(
251253
OS << "<rt-abort>";
252254
break;
253255
}
254-
}
256+
}

0 commit comments

Comments
 (0)