[PATCH] D69028: [DebugInfo] Correctly place DW_OP_derefs for arguments passed on stack

Jeremy Morse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 16 04:50:00 PDT 2019


jmorse created this revision.
jmorse added reviewers: uabelho, aprantl, vsk, bjope.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Following on from D68945 <https://reviews.llvm.org/D68945>, @uabelho pointed out a scenario where there's some confusion about where a DW_OP_deref should be added for arguments passed on the stack. A Value/Argument that gets placed in memory requires the stack slot it lands in to be dereferenced, and that deref would go at the start of the expression so that it operates on the slot. If the argument is the operand to a dbg.declare, then it might require a deref at the end of the expression as well, to make it a memory location.

In SelectionDAG::EmitFuncArgumentDbgValue that's what I've implemented, best illustrated by the `baz` function in the attached test:

  define i8 @baz(i32 *%blah) !dbg !40 {
  entry:
    call void @llvm.dbg.declare(metadata i32* %blah, metadata !43, metadata !DIExpression(DW_OP_plus_uconst, 4)), !dbg !41
    ret i8 0, !dbg !41
  }

%blah is an incoming pointer, but it arrives in a stack slot, which must be dereferenced first. And because it is used by a dbg.declare, we append a deref to force it to be a memory location. With this patch, we get the DBG_VALUE:

  DBG_VALUE %fixed-stack.0, $noreg, !123, !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 4, DW_OP_deref)

i.e., "load the stack slot, fiddle with the pointer, then be a memory location". I've added llvm-dwarfdump checks to ensure this comes out the far end in the correct format (I'm 97% the encoding is correct there).

I've deleted the "IsIndirect" var in EmitFuncArgumentDbgValue, as it wasn't doing anything useful IMO.


Repository:
  rL LLVM

https://reviews.llvm.org/D69028

Files:
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  test/DebugInfo/X86/stack-arg-deref.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69028.225193.patch
Type: text/x-patch
Size: 6173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191016/9b8f1466/attachment.bin>


More information about the llvm-commits mailing list