@@ -5466,11 +5466,19 @@ void IRGenSILFunction::visitCondFailInst(swift::CondFailInst *i) {
5466
5466
Explosion e = getLoweredExplosion (i->getOperand ());
5467
5467
llvm::Value *cond = e.claimNext ();
5468
5468
5469
+ // The condition should be false, or we die.
5470
+ auto expectedCond = Builder.CreateExpect (cond,
5471
+ llvm::ConstantInt::get (IGM.Int1Ty , 0 ));
5472
+
5469
5473
// Emit individual fail blocks so that we can map the failure back to a source
5470
5474
// line.
5475
+ auto origInsertionPoint = Builder.GetInsertBlock ();
5476
+
5471
5477
llvm::BasicBlock *failBB = llvm::BasicBlock::Create (IGM.getLLVMContext ());
5472
5478
llvm::BasicBlock *contBB = llvm::BasicBlock::Create (IGM.getLLVMContext ());
5473
- Builder.CreateCondBr (cond, failBB, contBB);
5479
+ Builder.CreateCondBr (expectedCond, failBB, contBB);
5480
+
5481
+ Builder.SetInsertPoint (&CurFn->back ());
5474
5482
Builder.emitBlock (failBB);
5475
5483
if (IGM.DebugInfo )
5476
5484
// If we are emitting DWARF, this does nothing. Otherwise the ``llvm.trap``
@@ -5479,6 +5487,8 @@ void IRGenSILFunction::visitCondFailInst(swift::CondFailInst *i) {
5479
5487
// in CodeView.
5480
5488
IGM.DebugInfo ->setInlinedTrapLocation (Builder, i->getDebugScope ());
5481
5489
emitTrap (i->getMessage (), /* EmitUnreachable=*/ true );
5490
+
5491
+ Builder.SetInsertPoint (origInsertionPoint);
5482
5492
Builder.emitBlock (contBB);
5483
5493
FailBBs.push_back (failBB);
5484
5494
}
0 commit comments