[llvm] [OMPIRBuilder] Avoid crash in BasicBlock::splice. (PR #154987)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 29 07:58:42 PDT 2025
================
@@ -307,7 +307,14 @@ void llvm::spliceBB(IRBuilderBase::InsertPoint IP, BasicBlock *New,
// Move instructions to new block.
BasicBlock *Old = IP.getBlock();
- if (!Old->empty() || !New->empty())
+ // If the Old block is empty then there are no instructions to move. But in
+ // the new debug scheme, it could have trailing debug records which will be
+ // moved to New in spliceDebugInfoEmptyBlock. We dont want that for 2 reasons:
+ // 1. If New is also empty, it could cause a crash.
+ // 2. Even if New is not empty, we want to keep those debug records in the
+ // Old as that was the behavior with the old scheme (debug intrinsics).
----------------
Meinersbur wrote:
```suggestion
// 2. Even if New is not empty, we want to keep those debug records in the
// Old as that was the behavior with the old scheme (debug intrinsics).
```
[nit] Just being the legacy scheme doesn't mean it is more correct. Consider something that mentions the rationale from `BasicBlock::spliceDebugInfoEmptyBlock`:
```
// If the source block is completely empty, including no terminator, then
// transfer any trailing DbgRecords that are still hanging around. This can
// occur when a block is optimised away and the terminator has been moved
// somewhere else.
```
which does not apply here since we still want to use `Old` BB (like adding a BrInst with `CreateBranch`).
https://github.com/llvm/llvm-project/pull/154987
More information about the llvm-commits
mailing list