@@ -4067,7 +4067,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
40674067 ArrayRef<llvm::Value *> FnArgs,
40684068 SanitizerHandler CheckHandler,
40694069 CheckRecoverableKind RecoverKind, bool IsFatal,
4070- llvm::BasicBlock *ContBB) {
4070+ llvm::BasicBlock *ContBB, bool NoMerge ) {
40714071 assert (IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
40724072 std::optional<ApplyDebugLocation> DL;
40734073 if (!CGF.Builder .getCurrentDebugLocation ()) {
@@ -4102,10 +4102,9 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
41024102 llvm::AttributeList::FunctionIndex, B),
41034103 /* Local=*/ true );
41044104 llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall (Fn, FnArgs);
4105- bool NoMerge =
4106- ClSanitizeDebugDeoptimization ||
4107- !CGF.CGM .getCodeGenOpts ().OptimizationLevel ||
4108- (CGF.CurCodeDecl && CGF.CurCodeDecl ->hasAttr <OptimizeNoneAttr>());
4105+ NoMerge = NoMerge || ClSanitizeDebugDeoptimization ||
4106+ !CGF.CGM .getCodeGenOpts ().OptimizationLevel ||
4107+ (CGF.CurCodeDecl && CGF.CurCodeDecl ->hasAttr <OptimizeNoneAttr>());
41094108 if (NoMerge)
41104109 HandlerCall->addFnAttr (llvm::Attribute::NoMerge);
41114110 if (!MayReturn) {
@@ -4129,6 +4128,7 @@ void CodeGenFunction::EmitCheck(
41294128 llvm::Value *FatalCond = nullptr ;
41304129 llvm::Value *RecoverableCond = nullptr ;
41314130 llvm::Value *TrapCond = nullptr ;
4131+ bool NoMerge = false ;
41324132 for (int i = 0 , n = Checked.size (); i < n; ++i) {
41334133 llvm::Value *Check = Checked[i].first ;
41344134 // -fsanitize-trap= overrides -fsanitize-recover=.
@@ -4139,6 +4139,9 @@ void CodeGenFunction::EmitCheck(
41394139 ? RecoverableCond
41404140 : FatalCond;
41414141 Cond = Cond ? Builder.CreateAnd (Cond, Check) : Check;
4142+
4143+ if (!CGM.getCodeGenOpts ().SanitizeMergeHandlers .has (Checked[i].second ))
4144+ NoMerge = true ;
41424145 }
41434146
41444147 if (ClSanitizeGuardChecks) {
@@ -4153,7 +4156,7 @@ void CodeGenFunction::EmitCheck(
41534156 }
41544157
41554158 if (TrapCond)
4156- EmitTrapCheck (TrapCond, CheckHandler);
4159+ EmitTrapCheck (TrapCond, CheckHandler, NoMerge );
41574160 if (!FatalCond && !RecoverableCond)
41584161 return ;
41594162
@@ -4219,7 +4222,7 @@ void CodeGenFunction::EmitCheck(
42194222 // Simple case: we need to generate a single handler call, either
42204223 // fatal, or non-fatal.
42214224 emitCheckHandlerCall (*this , FnType, Args, CheckHandler, RecoverKind,
4222- (FatalCond != nullptr ), Cont);
4225+ (FatalCond != nullptr ), Cont, NoMerge );
42234226 } else {
42244227 // Emit two handler calls: first one for set of unrecoverable checks,
42254228 // another one for recoverable.
@@ -4229,10 +4232,10 @@ void CodeGenFunction::EmitCheck(
42294232 Builder.CreateCondBr (FatalCond, NonFatalHandlerBB, FatalHandlerBB);
42304233 EmitBlock (FatalHandlerBB);
42314234 emitCheckHandlerCall (*this , FnType, Args, CheckHandler, RecoverKind, true ,
4232- NonFatalHandlerBB);
4235+ NonFatalHandlerBB, NoMerge );
42334236 EmitBlock (NonFatalHandlerBB);
42344237 emitCheckHandlerCall (*this , FnType, Args, CheckHandler, RecoverKind, false ,
4235- Cont);
4238+ Cont, NoMerge );
42364239 }
42374240
42384241 EmitBlock (Cont);
@@ -4423,6 +4426,7 @@ void CodeGenFunction::EmitUnreachable(SourceLocation Loc) {
44234426
44244427void CodeGenFunction::EmitTrapCheck (llvm::Value *Checked,
44254428 SanitizerHandler CheckHandlerID,
4429+ bool NoMerge,
44264430 /* TO_UPSTREAM(BoundsSafety) ON*/
44274431 StringRef Annotation,
44284432 StringRef TrapMessage) {
@@ -4444,9 +4448,9 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
44444448 }
44454449 /* TO_UPSTREAM(BoundsSafety) OFF*/
44464450
4447- bool NoMerge = ClSanitizeDebugDeoptimization ||
4448- !CGM.getCodeGenOpts ().OptimizationLevel ||
4449- (CurCodeDecl && CurCodeDecl->hasAttr <OptimizeNoneAttr>());
4451+ NoMerge = NoMerge || ClSanitizeDebugDeoptimization ||
4452+ !CGM.getCodeGenOpts ().OptimizationLevel ||
4453+ (CurCodeDecl && CurCodeDecl->hasAttr <OptimizeNoneAttr>());
44504454
44514455 /* TO_UPSTREAM(BoundsSafety) ON*/
44524456 NoMerge |= CGM.getCodeGenOpts ().TrapFuncReturns ;
0 commit comments