Skip to content

Commit 67bd04f

Browse files
authoredDec 10, 2024··
[ubsan] Don't merge non-trap handlers if -ubsan-unique-traps or not optimized (#119302)
UBSan handler calls are sometimes merged by the backend, which complicates debugging. Merging is currently disabled for UBSan traps if -ubsan-unique-traps is specified or if optimization is disabled. This patch applies the same policy to non-trap handler calls. N.B. "-ubsan-unique-traps" becomes somewhat of a misnomer since it will now apply to non-trap handler calls as well as traps; nonetheless, we keep the naming for backwards compatibility.
1 parent cafb6b9 commit 67bd04f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed
 

‎clang/lib/CodeGen/CGExpr.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -3581,6 +3581,12 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
35813581
llvm::AttributeList::FunctionIndex, B),
35823582
/*Local=*/true);
35833583
llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
3584+
bool NoMerge =
3585+
ClSanitizeDebugDeoptimization ||
3586+
!CGF.CGM.getCodeGenOpts().OptimizationLevel ||
3587+
(CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr<OptimizeNoneAttr>());
3588+
if (NoMerge)
3589+
HandlerCall->addFnAttr(llvm::Attribute::NoMerge);
35843590
if (!MayReturn) {
35853591
HandlerCall->setDoesNotReturn();
35863592
CGF.Builder.CreateUnreachable();

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,5 @@ int m(int x, int y) {
265265
return f(x) + g(y);
266266
}
267267
// TRAP: attributes #[[ATTR4]] = { nomerge noreturn nounwind }
268-
// HANDLER: attributes #[[ATTR4]] = { noreturn nounwind }
269-
// MINRT: attributes #[[ATTR4]] = { noreturn nounwind }
268+
// HANDLER: attributes #[[ATTR4]] = { nomerge noreturn nounwind }
269+
// MINRT: attributes #[[ATTR4]] = { nomerge noreturn nounwind }

‎clang/test/CodeGenCXX/catch-undef-behavior.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,6 @@ void ThisAlign::this_align_lambda_2() {
734734
p();
735735
}
736736

737-
// CHECK: attributes [[NR_NUW]] = { noreturn nounwind }
737+
// CHECK: attributes [[NR_NUW]] = { nomerge noreturn nounwind }
738738

739739
// CHECK-FUNCSAN: ![[FUNCSAN]] = !{i32 -1056584962, i32 -1000226989}

0 commit comments

Comments
 (0)
Please sign in to comment.