Skip to content

Commit 09252c7

Browse files
committed
Don't apply nomerge for the first instance of each TrapBB type, per
Vitaly's feedback
1 parent 8c7eb2b commit 09252c7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3915,6 +3915,7 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
39153915
Builder.getCurrentDebugLocation());
39163916
Builder.CreateCondBr(Checked, Cont, TrapBB);
39173917
} else {
3918+
bool NewTrapBB = (TrapBB == nullptr);
39183919
TrapBB = createBasicBlock("trap");
39193920
Builder.CreateCondBr(Checked, Cont, TrapBB);
39203921
EmitBlock(TrapBB);
@@ -3928,7 +3929,8 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
39283929
CGM.getCodeGenOpts().TrapFuncName);
39293930
TrapCall->addFnAttr(A);
39303931
}
3931-
TrapCall->addFnAttr(llvm::Attribute::NoMerge);
3932+
if (!NewTrapBB)
3933+
TrapCall->addFnAttr(llvm::Attribute::NoMerge);
39323934
TrapCall->setDoesNotReturn();
39333935
TrapCall->setDoesNotThrow();
39343936
Builder.CreateUnreachable();

clang/test/CodeGen/ubsan-trap-merge.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int g(int x) {
5555
// CHECK-NEXT: [[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP2]], 1, !nosanitize [[META2]]
5656
// CHECK-NEXT: br i1 [[TMP3]], label %[[TRAP1:.*]], label %[[CONT2:.*]], !nosanitize [[META2]]
5757
// CHECK: [[TRAP1]]:
58-
// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 0) #[[ATTR4]], !nosanitize [[META2]]
58+
// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 0) #[[ATTR5:[0-9]+]], !nosanitize [[META2]]
5959
// CHECK-NEXT: unreachable, !nosanitize [[META2]]
6060
// CHECK: [[CONT2]]:
6161
// CHECK-NEXT: [[TMP4:%.*]] = extractvalue { i32, i1 } [[TMP2]], 0, !nosanitize [[META2]]
@@ -102,4 +102,5 @@ int m(int x, int y) {
102102
return f(x) + g(y);
103103
}
104104
//.
105-
// CHECK: attributes #[[ATTR4]] = { nomerge noreturn nounwind }
105+
// CHECK: attributes #[[ATTR4]] = { noreturn nounwind }
106+
// CHECK: attributes #[[ATTR5]] = { nomerge noreturn nounwind }

0 commit comments

Comments
 (0)