Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BoundsSan] Update BoundsChecking.cpp to use no-merge attribute where applicable #120620

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/test/CodeGen/bounds-checking.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ char B2[10];
// NOOPTLOCAL-LABEL: @f8
// NOOPTARRAY-LABEL: @f8
void f8(int i, int k) {
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 3)
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) #[[ATTR1:[0-9]+]]
// NOOPTARRAY: call void @llvm.ubsantrap(i8 18) #[[ATTR2:[0-9]+]]
B[i] = '\0';

// NOOPTLOCAL: call void @llvm.ubsantrap(i8 5)
// NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) #[[ATTR1:[0-9]+]]
// NOOPTARRAY: call void @llvm.ubsantrap(i8 18) #[[ATTR2:[0-9]+]]
B2[k] = '\0';
}
Expand All @@ -102,4 +102,5 @@ struct S {
struct S *f9(int i) {
return &s[i];
}
// NOOPTLOCAL: attributes #[[ATTR1]] = { nomerge noreturn nounwind }
// NOOPTARRAY: attributes #[[ATTR2]] = { nomerge noreturn nounwind }
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI,

CallInst *TrapCall;
if (DebugTrapBB) {
// Ideally we would use the SanitizerHandler::OutOfBounds constant
TrapCall = IRB.CreateIntrinsic(
IntrID, {}, ConstantInt::get(IRB.getInt8Ty(), Fn->size()));
TrapCall->addFnAttr(llvm::Attribute::NoMerge);
} else {
TrapCall = IRB.CreateIntrinsic(IntrID, {}, {});
}
Expand Down Expand Up @@ -251,4 +253,4 @@ void BoundsCheckingPass::printPipeline(
OS << "<rt-abort>";
break;
}
}
}
Loading