diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 0d16408aa4de9..79955f5571416 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()); + 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 e48681ce09377..412ec7b09744e 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 a985183129911..419d1292551a0 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}