[PATCH] D142160: [mem2reg][debuginfo] Handle op_deref when converting dbg.declare

Felipe de Azevedo Piovezan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 19 14:29:25 PST 2023


fdeazeve created this revision.
Herald added subscribers: nlopes, hiraditya.
Herald added a project: All.
fdeazeve requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The conversion of dbg.declare into dbg.values doesn't take into account
the DIExpression attached to the intrinsic. In particular, when
converting:

  store %val, ptr %alloca
  dbg.declare(ptr %alloca, !SomeVar, !DIExpression())

Mem2Reg will try to figure out if `%val` has the size of `!SomeVar`. If
it does, then a non-undef dbg.value is inserted:

  dbg.value(%val, !SomeVar, !DIExpression())

This makes sense: the alloca is _the_ address of the variable. So a
store to the alloca is a store to the variable. However, if the
expression in the original intrinsic is a `DW_OP_deref`, this logic is
not applicable:

  store ptr %val, ptr %alloca
  dbg.declare(ptr %alloca, !SomeVar, !DIExpression(DW_OP_deref))

Here, the alloca is *not* the address of the variable. A store to the
alloca is *not* a store to the variable. As such, querying whether
`%val` has the same size as `!SomeVar` is meaningless.

This patch addresses the issue by:

1. Allowing the conversion when the expression is _only_ a `DW_OP_deref`

without any other expressions (see code comment).

2. Checking that the expression does not start with a `DW_OP_deref`

before applying the logic that checks whether the value being stored and
the variable have the same length.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142160

Files:
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/Transforms/Utils/Local.cpp
  llvm/test/Transforms/Mem2Reg/dbg_declare_to_value_conversions.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142160.490661.patch
Type: text/x-patch
Size: 6136 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230119/a9d44847/attachment.bin>


More information about the llvm-commits mailing list