Author: Thurston Dang Date: 2024-12-10T15:25:24-08:00 New Revision: 67bd04facf48206c1e3a4c2664c2240e787bd6af
URL: https://github.com/llvm/llvm-project/commit/67bd04facf48206c1e3a4c2664c2240e787bd6af DIFF: https://github.com/llvm/llvm-project/commit/67bd04facf48206c1e3a4c2664c2240e787bd6af.diff LOG: [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. Added: Modified: clang/lib/CodeGen/CGExpr.cpp clang/test/CodeGen/ubsan-trap-merge.c clang/test/CodeGenCXX/catch-undef-behavior.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 0d16408aa4de9d..79955f55714164 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3581,6 +3581,12 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF, llvm::AttributeList::FunctionIndex, B), /*Local=*/true); llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs); + bool NoMerge = + ClSanitizeDebugDeoptimization || + !CGF.CGM.getCodeGenOpts().OptimizationLevel || + (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr<OptimizeNoneAttr>()); + if (NoMerge) + HandlerCall->addFnAttr(llvm::Attribute::NoMerge); if (!MayReturn) { HandlerCall->setDoesNotReturn(); CGF.Builder.CreateUnreachable(); diff --git a/clang/test/CodeGen/ubsan-trap-merge.c b/clang/test/CodeGen/ubsan-trap-merge.c index e48681ce09377d..412ec7b09744ef 100644 --- a/clang/test/CodeGen/ubsan-trap-merge.c +++ b/clang/test/CodeGen/ubsan-trap-merge.c @@ -265,5 +265,5 @@ int m(int x, int y) { return f(x) + g(y); } // TRAP: attributes #[[ATTR4]] = { nomerge noreturn nounwind } -// HANDLER: attributes #[[ATTR4]] = { noreturn nounwind } -// MINRT: attributes #[[ATTR4]] = { noreturn nounwind } +// HANDLER: attributes #[[ATTR4]] = { nomerge noreturn nounwind } +// MINRT: attributes #[[ATTR4]] = { nomerge noreturn nounwind } diff --git a/clang/test/CodeGenCXX/catch-undef-behavior.cpp b/clang/test/CodeGenCXX/catch-undef-behavior.cpp index a985183129911c..419d1292551a08 100644 --- a/clang/test/CodeGenCXX/catch-undef-behavior.cpp +++ b/clang/test/CodeGenCXX/catch-undef-behavior.cpp @@ -734,6 +734,6 @@ void ThisAlign::this_align_lambda_2() { p(); } -// CHECK: attributes [[NR_NUW]] = { noreturn nounwind } +// CHECK: attributes [[NR_NUW]] = { nomerge noreturn nounwind } // CHECK-FUNCSAN: ![[FUNCSAN]] = !{i32 -1056584962, i32 -1000226989} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits