[clang] [llvm] [DebugInfo] Update DIBuilder insertion to take InsertPosition (PR #126059)

Harald van Dijk via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 07:35:26 PST 2025


================
@@ -1686,7 +1686,8 @@ LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordBefore(
   DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
       unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
       unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
-      unwrap<Instruction>(Instr));
+      Instr ? InsertPosition(unwrap<Instruction>(Instr)->getIterator())
+            : nullptr);
----------------
hvdijk wrote:

You're right. Previously, a call with `!Instr` would result in a call to `insertDeclare(..., /*InsertBefore=*/nullptr)` which results in `insertDeclare(..., /*InsertBB=*/nullptr->getParent(), /*InsertBefore=*/nullptr)`, so it would (on typical systems) result in a crash already.

At the same time, previously, `insertLabel(..., /*InsertBefore=*/nullptr)` would result in `insertLabel(..., /*InsertBB=*/nullptr, /*InsertBefore=*/nullptr)` which specifically does not insert anything.

And `insertDbgValueIntrinsic(..., /*InsertBefore=*/nullptr)` is special-cased to call `insertDbgValueIntrinsic(..., /*InsertBB=*/nullptr, /*InsertBefore=*/nullptr)` the same way, *but* the latter calls `insertDbgVariableRecord` unconditionally and hits the existing `assert(InsertBefore || InsertBB);` assert.

This is a messy situation and in this PR I tried to just keep that exactly the same. What previously worked should still work. What previously didn't work should still not work.

https://github.com/llvm/llvm-project/pull/126059


More information about the cfe-commits mailing list