[PATCH] D13178: Fix SafeStack debug locations

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 14:12:20 PDT 2015


eugenis created this revision.
eugenis added reviewers: echristo, dblaikie, samsonov, pcc.
eugenis added a subscriber: llvm-commits.
eugenis set the repository for this revision to rL LLVM.

This change tweaks debug locations for the local variables moved onto the unsafe stack so that they don't get "optimized out".

Instead of describing these locations via an IR temp that is likely to be optimized out (even at -O0!), we base the locations off the unsafe stack pointer which is always present. This required a few tweaks in other parts of LLVM:

1. The location expression changed from *tmp to *tmp - offset, hence the need to support DW_OP_minus in the AsmPrinter.
2. SDAG plainly refuses to emit debug locations on anything other that an alloca or a function parameter. I could not find any adverse effects from allowing those on any IR temps, and it works perfectly in our case, when the temp is a load from some thread-local variable. FastISel already supports that.
3. replaceDbgDeclareForAlloca places the new dbg.declare at the end of the basic block of the original alloca. There is a problem with that: SDAG ignores a dbg.declare that does not precede at least one use of the variable, and we lose the location. Changed to insert right after the original alloca.

With this, debug locations for the unsafe allocas seem to reliably survive -O2.


Repository:
  rL LLVM

http://reviews.llvm.org/D13178

Files:
  include/llvm/Transforms/Utils/Local.h
  lib/CodeGen/AsmPrinter/DwarfExpression.cpp
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  lib/IR/DebugInfoMetadata.cpp
  lib/Transforms/Instrumentation/SafeStack.cpp
  lib/Transforms/Utils/Local.cpp
  test/DebugInfo/Generic/dw_op_minus.ll
  test/Transforms/Inline/inline_dbg_declare.ll
  test/Transforms/SafeStack/debug-loc.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13178.35763.patch
Type: text/x-patch
Size: 15819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150925/caf370e7/attachment.bin>


More information about the llvm-commits mailing list