From 2a858065809eeb828109ced4c3efbea4a31f12a7 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 25 Jan 2025 06:11:46 -0800 Subject: [PATCH] Ensure blockExpr lifetimeStart doesn't insert above phi nodes --- IDEHelper/Compiler/BfIRCodeGen.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/IDEHelper/Compiler/BfIRCodeGen.cpp b/IDEHelper/Compiler/BfIRCodeGen.cpp index cd56d070..5515a416 100644 --- a/IDEHelper/Compiler/BfIRCodeGen.cpp +++ b/IDEHelper/Compiler/BfIRCodeGen.cpp @@ -3105,7 +3105,17 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_SetInsertPointAtStart: { CMD_PARAM(llvm::BasicBlock*, block); - mIRBuilder->SetInsertPoint(block, block->begin()); + + auto itr = block->begin(); + if (itr != block->end()) + { + // Some instructructions MUST be at start of the block + auto instType = itr->getType(); + if (llvm::PHINode::classof(&*itr)) + ++itr; + } + + mIRBuilder->SetInsertPoint(block, itr); // SetInsertPoint can clear the debug loc so reset it here mIRBuilder->SetCurrentDebugLocation(mDebugLoc); }