<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - LLVM should store register parameters to the stack at -O0 for debugability"
   href="https://bugs.llvm.org/show_bug.cgi?id=34227">34227</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM should store register parameters to the stack at -O0 for debugability
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rnk@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>aprantl@apple.com, llvm-bugs@lists.llvm.org, llvm@inglorion.net
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider this C++ code:

struct Foo { int x; Foo(); ~Foo(); };
void g(int x);
void f(Foo f, int n) {
  while (--n)
    g(0);
}

Clang will emit a dbg.declare for f:f that looks like this:

define void @_Z1f3Fooi(%struct.Foo* nocapture readnone %f, i32 %n)
local_unnamed_addr #0 !dbg !7 {
entry:
  tail call void @llvm.dbg.declare(metadata %struct.Foo* %f, metadata !20,
metadata !22), !dbg !23

The location is not a static alloca, so we must emit DBG_VALUE instructions
rather than recording a simple frame index in a table. On Linux, the value is
in RDI, which is soon killed by the call to g(0), as we can see in the
assembly:

_Z1f3Fooi:                              # @_Z1f3Fooi
        pushq   %rbx
        #DEBUG_VALUE: f:f <- [%RDI+0]
        cmpl    $1, %esi
        je      .LBB0_3
        #DEBUG_VALUE: f:f <- [%RDI+0]
        movl    $1, %ebx
        subl    %esi, %ebx
        #DEBUG_VALUE: f:f <- [%RDI+0]
        xorl    %edi, %edi    # RDI killed here
        callq   _Z1gi

Debuggers won't be able to print 'f' after the first iteration of the loop.

This would also remove the need for swift to add extra empty inline asm
statements to function epilogues just to keep unused parameters alive for the
entire function, or to emit extra allocas just so it can dbg.declare them. Many
other non-C frontends also directly emit SSA without any intermediate allocas,
and this would improve things for them too.

Debug info quality aside, users have also requested functionality equivalent to
MSVC's /homeparams flag (-msave-regs
<a href="http://lists.llvm.org/pipermail/llvm-dev/2017-April/112431.html">http://lists.llvm.org/pipermail/llvm-dev/2017-April/112431.html</a>), so that even
in optimized builds without debug info, they can find initial parameter values.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>