This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Add missing DW_OP_deref when an NRVO pointer is spilled
ClosedPublic

Authored by rnk on Sep 15 2017, 1:44 PM.

Details

Summary

Fixes PR34513.

Indirect DBG_VALUEs typically come from dbg.declares of non-trivially
copyable C++ objects that must be passed by address. We were already
handling the case where the virtual register gets allocated to a
physical register and is later spilled. That's what usually happens for
normal parameters that aren't NRVO variables: they usually appear in
physical register parameters, and are spilled later in the function,
which would correctly add deref.

NRVO variables are different because the dbg.declare can come much later
after earlier instructions cause the incoming virtual register to be
spilled.

Also, clean up this code. We only need to look at the first operand of a
DBG_VALUE, which eliminates the operand loop.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk created this revision.Sep 15 2017, 1:44 PM
aprantl accepted this revision.Sep 15 2017, 2:34 PM
aprantl added inline comments.
llvm/lib/CodeGen/RegAllocFast.cpp
894 ↗(On Diff #115480)

Nice.

llvm/test/DebugInfo/X86/dbg-declare-arg.ll
4 ↗(On Diff #115480)

According to the radar, the testcase was:

class A { public: int x; int y; int z; int o; ~A() { x = 1; }};

A foo(int i) {
  int j = 0;
  if (i == 42) {
    j = i + 1;
  };
  A a;
  a.x = j;
  return a;
}

Can you verify that end-to-end, this still works?
Apparently older versions of the testcase never checked for the expressions so it is hard to tell what it originally was.

This revision is now accepted and ready to land.Sep 15 2017, 2:34 PM

Do you think you could craft a debuginfo-tests test from PR34513, so we can avoid regressing in the future?

rnk added a comment.Sep 15 2017, 2:42 PM

Do you think you could craft a debuginfo-tests test from PR34513, so we can avoid regressing in the future?

Yep, once we have -O0 and -O1 working I'll commit one that tests both cases.

rnk added inline comments.Sep 15 2017, 2:45 PM
llvm/test/DebugInfo/X86/dbg-declare-arg.ll
4 ↗(On Diff #115480)

I verified this does the right thing now on gdb on Linux.

This revision was automatically updated to reflect the committed changes.