Skip to content

Commit f8f9835

Browse files
committed
[OMPIRBuilder] Avoid crash in BasicBlock::splice.
Calling splice when both Old and New are empty is a nop currently but it can cause a crash once debug records are used instead of debug intrinsics. This PR makes the call conditional on at least one of Old or New being non-empty. Consider the following mlir: omp.target map_entries() { llvm.intr.dbg.declare ... llvm.intr.dbg.declare ... omp.teams ... ... } Current code would translate llvm.intr to llvm intrinsics and we will have 2 of them in the Old BB by the time omp.teams implementation starts. This implementation creates many BasicBlocks by calling splitBB. In the new scheme (using debug records), there will be no instruction in the Old BB after llvm.intr get translated but just 2 trailing debug records. So effectively both Old and New are empty. When control reaches BasicBlock::splice, it calls spliceDebugInfoEmptyBlock. This funtion expects that in this case (Src is empty but has trailing debug records), the ToIt is valid and it can call adoptDbgRecords on it. This assumption is not true in this case as New is empty and ToIt is pointing to end().
1 parent d5c5ed3 commit f8f9835

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ void llvm::spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New,
307307

308308
// Move instructions to new block.
309309
BasicBlock *Old = IP.getBlock();
310-
New->splice(New->begin(), Old, IP.getPoint(), Old->end());
310+
if (!Old->empty() || !New->empty())
311+
New->splice(New->begin(), Old, IP.getPoint(), Old->end());
311312

312313
if (CreateBranch) {
313314
auto *NewBr = BranchInst::Create(New, Old);

0 commit comments

Comments
 (0)