Skip to content

Commit d33a2c5

Browse files
authored
[BoundsSan] Update BoundsChecking.cpp to use no-merge attribute where applicable (#120620)
#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 9e322c5 commit d33a2c5

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
@@ -85,11 +85,11 @@ char B2[10];
8585
// NOOPTLOCAL-LABEL: @f8
8686
// NOOPTARRAY-LABEL: @f8
8787
void f8(int i, int k) {
88-
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 3)
88+
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) #[[ATTR1:[0-9]+]]
8989
// NOOPTARRAY: call void @llvm.ubsantrap(i8 18) #[[ATTR2:[0-9]+]]
9090
B[i] = '\0';
9191

92-
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 5)
92+
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) #[[ATTR1:[0-9]+]]
9393
// NOOPTARRAY: call void @llvm.ubsantrap(i8 18) #[[ATTR2:[0-9]+]]
9494
B2[k] = '\0';
9595
}
@@ -102,4 +102,5 @@ struct S {
102102
struct S *f9(int i) {
103103
return &s[i];
104104
}
105+
// NOOPTLOCAL: attributes #[[ATTR1]] = { nomerge noreturn nounwind }
105106
// NOOPTARRAY: attributes #[[ATTR2]] = { 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)