[llvm] Handle #dbg_values in SROA. (PR #94070)

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 16 04:50:58 PDT 2024


================
@@ -5000,10 +5000,25 @@ static void insertNewDbgInst(DIBuilder &DIB, DbgVariableRecord *Orig,
                                                    BeforeInst->getIterator());
     return;
   }
+
+  if (Orig->isDbgValue()) {
+    // Drop debug information if the expression doesn't start with a
+    // DW_OP_deref. This is because without a DW_OP_deref, the #dbg_value
+    // describers the address of alloca rather than the value inside the alloca.
+    if (!NewFragmentExpr->startsWithDeref())
+      return;
----------------
SLTozer wrote:

Looking at this again, and the changes in the auto-generated SROA tests below, I think this may be incorrect - I believe we should "kill" the debug value (i.e. produce a dbg_value with an `undef` value) rather than outright delete it as we do here. In the common case (as produced by Swift) it doesn't make a difference, because a variable that only has undef debug records is equivalent to one with no debug records at all; since these are dbg_values rather than dbg_declares though, it's probably good practice to not assume that all records for the variable are necessarily dead here. The later remove-redundant-debug-records step will take care of deleting the excess debug records if that's the case.

Open to any thoughts from @adrian-prantl about this reasoning, but I think this change shouldn't result in us deleting dbg_values that would previously have just been set undef.

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


More information about the llvm-commits mailing list