@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
3546
3546
ArrayRef<llvm::Value *> FnArgs,
3547
3547
SanitizerHandler CheckHandler,
3548
3548
CheckRecoverableKind RecoverKind, bool IsFatal,
3549
- llvm::BasicBlock *ContBB) {
3549
+ llvm::BasicBlock *ContBB, bool NoMerge ) {
3550
3550
assert (IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
3551
3551
std::optional<ApplyDebugLocation> DL;
3552
3552
if (!CGF.Builder .getCurrentDebugLocation ()) {
@@ -3581,10 +3581,9 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
3581
3581
llvm::AttributeList::FunctionIndex, B),
3582
3582
/* Local=*/ true );
3583
3583
llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall (Fn, FnArgs);
3584
- bool NoMerge =
3585
- ClSanitizeDebugDeoptimization ||
3586
- !CGF.CGM .getCodeGenOpts ().OptimizationLevel ||
3587
- (CGF.CurCodeDecl && CGF.CurCodeDecl ->hasAttr <OptimizeNoneAttr>());
3584
+ NoMerge = NoMerge || ClSanitizeDebugDeoptimization ||
3585
+ !CGF.CGM .getCodeGenOpts ().OptimizationLevel ||
3586
+ (CGF.CurCodeDecl && CGF.CurCodeDecl ->hasAttr <OptimizeNoneAttr>());
3588
3587
if (NoMerge)
3589
3588
HandlerCall->addFnAttr (llvm::Attribute::NoMerge);
3590
3589
if (!MayReturn) {
@@ -3608,6 +3607,7 @@ void CodeGenFunction::EmitCheck(
3608
3607
llvm::Value *FatalCond = nullptr ;
3609
3608
llvm::Value *RecoverableCond = nullptr ;
3610
3609
llvm::Value *TrapCond = nullptr ;
3610
+ bool NoMerge = false ;
3611
3611
for (int i = 0 , n = Checked.size (); i < n; ++i) {
3612
3612
llvm::Value *Check = Checked[i].first ;
3613
3613
// -fsanitize-trap= overrides -fsanitize-recover=.
@@ -3618,6 +3618,9 @@ void CodeGenFunction::EmitCheck(
3618
3618
? RecoverableCond
3619
3619
: FatalCond;
3620
3620
Cond = Cond ? Builder.CreateAnd (Cond, Check) : Check;
3621
+
3622
+ if (!CGM.getCodeGenOpts ().SanitizeMergeHandlers .has (Checked[i].second ))
3623
+ NoMerge = true ;
3621
3624
}
3622
3625
3623
3626
if (ClSanitizeGuardChecks) {
@@ -3632,7 +3635,7 @@ void CodeGenFunction::EmitCheck(
3632
3635
}
3633
3636
3634
3637
if (TrapCond)
3635
- EmitTrapCheck (TrapCond, CheckHandler);
3638
+ EmitTrapCheck (TrapCond, CheckHandler, NoMerge );
3636
3639
if (!FatalCond && !RecoverableCond)
3637
3640
return ;
3638
3641
@@ -3698,7 +3701,7 @@ void CodeGenFunction::EmitCheck(
3698
3701
// Simple case: we need to generate a single handler call, either
3699
3702
// fatal, or non-fatal.
3700
3703
emitCheckHandlerCall (*this , FnType, Args, CheckHandler, RecoverKind,
3701
- (FatalCond != nullptr ), Cont);
3704
+ (FatalCond != nullptr ), Cont, NoMerge );
3702
3705
} else {
3703
3706
// Emit two handler calls: first one for set of unrecoverable checks,
3704
3707
// another one for recoverable.
@@ -3708,10 +3711,10 @@ void CodeGenFunction::EmitCheck(
3708
3711
Builder.CreateCondBr (FatalCond, NonFatalHandlerBB, FatalHandlerBB);
3709
3712
EmitBlock (FatalHandlerBB);
3710
3713
emitCheckHandlerCall (*this , FnType, Args, CheckHandler, RecoverKind, true ,
3711
- NonFatalHandlerBB);
3714
+ NonFatalHandlerBB, NoMerge );
3712
3715
EmitBlock (NonFatalHandlerBB);
3713
3716
emitCheckHandlerCall (*this , FnType, Args, CheckHandler, RecoverKind, false ,
3714
- Cont);
3717
+ Cont, NoMerge );
3715
3718
}
3716
3719
3717
3720
EmitBlock (Cont);
@@ -3901,7 +3904,8 @@ void CodeGenFunction::EmitUnreachable(SourceLocation Loc) {
3901
3904
}
3902
3905
3903
3906
void CodeGenFunction::EmitTrapCheck (llvm::Value *Checked,
3904
- SanitizerHandler CheckHandlerID) {
3907
+ SanitizerHandler CheckHandlerID,
3908
+ bool NoMerge) {
3905
3909
llvm::BasicBlock *Cont = createBasicBlock (" cont" );
3906
3910
3907
3911
// If we're optimizing, collapse all calls to trap down to just one per
@@ -3911,9 +3915,9 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
3911
3915
3912
3916
llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID];
3913
3917
3914
- bool NoMerge = ClSanitizeDebugDeoptimization ||
3915
- !CGM.getCodeGenOpts ().OptimizationLevel ||
3916
- (CurCodeDecl && CurCodeDecl->hasAttr <OptimizeNoneAttr>());
3918
+ NoMerge = NoMerge || ClSanitizeDebugDeoptimization ||
3919
+ !CGM.getCodeGenOpts ().OptimizationLevel ||
3920
+ (CurCodeDecl && CurCodeDecl->hasAttr <OptimizeNoneAttr>());
3917
3921
3918
3922
if (TrapBB && !NoMerge) {
3919
3923
auto Call = TrapBB->begin ();
0 commit comments