<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 - [DebugInfo] Sign-extended variable is described by smaller stack slot, resulting in parts being filled with garbage data"
   href="https://bugs.llvm.org/show_bug.cgi?id=39996">39996</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[DebugInfo] Sign-extended variable is described by smaller stack slot, resulting in parts being filled with garbage data
          </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>Linux
          </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>DebugInfo
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>david.stenberg@ericsson.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>jdevlieghere@apple.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Reproduced on r348837.

Compiling the following file:

    #include <stdint.h>

    int g;

    __attribute__((noinline))
    void bar(int64_t a) {
      g = a; // Side effect to keep the call.
    }

    __attribute__((noinline))
    void foo(int32_t a, uint32_t b) {
      int64_t al = a;
      int64_t rl = 6;
      bar(al);
      bar(b);
    }

    int32_t value = -123;
    uint32_t junk = 0xcccccccc;

    int main() {
      foo(value, junk);
      return 0;
    }

using:

    $ clang -m32 -O3 -g foo.c -o foo.out

results in the 64-bit variable `al', which contains the sign-extended value of
`a', incorrectly being described by the stack slot for the 32-bit parameter
`a':

    0x000000d8:     DW_TAG_variable
                      DW_AT_location        (0x00000000
                         [0x0804838c,  0x08048394): DW_OP_breg4 ESP+16)
                      DW_AT_name    ("al")
                      DW_AT_decl_file       ("/path/to/foo.c")
                      DW_AT_decl_line       (12)
                      DW_AT_type    (0x000000fd "int64_t")

When printing the variable in LLDB and GDB, the 32 highest bits are printed by
using data from the second argument's stack slot:

    $ lldb-6.0 foo.out
    (lldb) target create "foo.out"
    Current executable set to 'foo.out' (i386).
    (lldb) b foo
    Breakpoint 1: where = foo.out`foo + 17 at foo.c:14, address = 0x08048391
    (lldb) run
    Process 992 launched: '/tmp/foo.out' (i386)
    Process 992 stopped
    * thread #1, name = 'foo.out', stop reason = breakpoint 1.1
        frame #0: 0x08048391 foo.out`foo(a=-123, b=3435973836) at foo.c:14
    (lldb) frame variable al -f hex
    (int64_t) al = 0xccccccccffffff85</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>