This is an archive of the discontinued LLVM Phabricator instance.

Fix SafeStack debug locations
ClosedPublic

Authored by eugenis on Sep 25 2015, 2:12 PM.

Details

Summary

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.

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

Diff Detail

Repository
rL LLVM

Event Timeline

eugenis updated this revision to Diff 35763.Sep 25 2015, 2:12 PM
eugenis retitled this revision from to Fix SafeStack debug locations.
eugenis updated this object.
eugenis added reviewers: echristo, dblaikie, samsonov, pcc.
eugenis set the repository for this revision to rL LLVM.
eugenis added a subscriber: llvm-commits.
eugenis updated this revision to Diff 35930.Sep 28 2015, 6:16 PM

Rebased on top of D13230.
Verified that this CL passes the gdb test suite.
PTAL

eugenis updated this object.Sep 28 2015, 6:17 PM
samsonov edited edge metadata.Sep 29 2015, 3:16 PM

Nice!

include/llvm/Transforms/Utils/Local.h
276

Please elaborate what's actually going on - whether you rewrite expr to be (*orig + offset), or *(orig + offset) - it's not entirely clear from comment

lib/IR/DebugInfoMetadata.cpp
519

This looks weird to me: why don't we use std::advance(I, I->getSize()) instead?

samsonov accepted this revision.Sep 30 2015, 10:35 AM
samsonov edited edge metadata.

LGTM

include/llvm/Transforms/Utils/Local.h
276

Please disregard this, I probably misread the new comment.

lib/IR/DebugInfoMetadata.cpp
519

That's fine: expr_op iterator will handle this.

This revision is now accepted and ready to land.Sep 30 2015, 10:35 AM
eugenis closed this revision.Sep 30 2015, 1:02 PM

Committed as r248933