Skip to content

Commit

Permalink
Don't apply nomerge for the first instance of each TrapBB type, per
Browse files Browse the repository at this point in the history
Vitaly's feedback
  • Loading branch information
thurstond committed Nov 26, 2024
1 parent d06aeec commit 5107ce1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3915,6 +3915,7 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
Builder.getCurrentDebugLocation());
Builder.CreateCondBr(Checked, Cont, TrapBB);
} else {
bool NewTrapBB = (TrapBB == nullptr);
TrapBB = createBasicBlock("trap");
Builder.CreateCondBr(Checked, Cont, TrapBB);
EmitBlock(TrapBB);
Expand All @@ -3928,7 +3929,8 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
CGM.getCodeGenOpts().TrapFuncName);
TrapCall->addFnAttr(A);
}
TrapCall->addFnAttr(llvm::Attribute::NoMerge);
if (!NewTrapBB)
TrapCall->addFnAttr(llvm::Attribute::NoMerge);
TrapCall->setDoesNotReturn();
TrapCall->setDoesNotThrow();
Builder.CreateUnreachable();
Expand Down
5 changes: 3 additions & 2 deletions clang/test/CodeGen/ubsan-trap-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int g(int x) {
// CHECK-NEXT: [[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP2]], 1, !nosanitize [[META2]]
// CHECK-NEXT: br i1 [[TMP3]], label %[[TRAP1:.*]], label %[[CONT2:.*]], !nosanitize [[META2]]
// CHECK: [[TRAP1]]:
// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 0) #[[ATTR4]], !nosanitize [[META2]]
// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 0) #[[ATTR5:[0-9]+]], !nosanitize [[META2]]
// CHECK-NEXT: unreachable, !nosanitize [[META2]]
// CHECK: [[CONT2]]:
// CHECK-NEXT: [[TMP4:%.*]] = extractvalue { i32, i1 } [[TMP2]], 0, !nosanitize [[META2]]
Expand Down Expand Up @@ -102,4 +102,5 @@ int m(int x, int y) {
return f(x) + g(y);
}
//.
// CHECK: attributes #[[ATTR4]] = { nomerge noreturn nounwind }
// CHECK: attributes #[[ATTR4]] = { noreturn nounwind }
// CHECK: attributes #[[ATTR5]] = { nomerge noreturn nounwind }

0 comments on commit 5107ce1

Please sign in to comment.