[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


================
@@ -1731,6 +1731,28 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
                                     SI->getIterator());
 }
 
+static DIExpression *dropInitialDeref(const DIExpression *DIExpr) {
+  assert(DIExpr->startsWithDeref() &&
+         "DIExpression doesn't start with DW_OP_deref!");
+  SmallVector<uint64_t> Ops(DIExpr->getElements().begin() + 1,
+                            DIExpr->getElements().end());
+  return DIExpression::get(DIExpr->getContext(), Ops);
----------------
SLTozer wrote:

Technically, `DIExpression::startsWithDeref()` doesn't guarantee that the expression starts with `DW_OP_deref` - it could also start with `DW_OP_LLVM_arg, 0, DW_OP_deref`. I don't think those expressions should exist at this point, but it should probably either be accounted for or asserted against. Also nit, I don't think we need the stack variable.
```suggestion
  assert(DIExpr->getElements()[0] != dwarf::DW_OP_LLVM_arg &&
         "Unexpected variadic DIExpression.");
  return DIExpression::get(DIExpr->getContext(),
                           DIExpr->getElements().drop_front());
  // Or alternatively...
  int NumEltDropped = DIExpr->getElements()[0] == dwarf::DW_OP_LLVM_arg ? 3 : 1;
  return DIExpression::get(DIExpr->getContext(),
                           DIExpr->getElements().drop_front(NumEltDropped));
```

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


More information about the llvm-commits mailing list