<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 - Incorrect debug values for parameters that are smaller than stack slots"
   href="https://bugs.llvm.org/show_bug.cgi?id=40973">40973</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Incorrect debug values for parameters that are smaller than stack slots
          </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>Spawned out from D58831.

When compiling the following test case:

    extern void bar(short);

    void foo(int p0, int p1, int p2, int p3, short p4, short p5) {
      bar(p4);
    }

using clang from trunk (r355379):

    $ clang --target=arm -mbig-endian -O2 -g

we land up with the following debug information for p4 and p5:

0x0000006d:     DW_TAG_formal_parameter
                  DW_AT_name    ("p4")
                  DW_AT_decl_file      
("/home/user/upstream/master/stack_dbg_values.c")
                  DW_AT_decl_line       (3)
                  DW_AT_type    (0x0000008e "short")

0x00000078:     DW_TAG_formal_parameter
                  DW_AT_location        (DW_OP_breg13 SP+4)
                  DW_AT_name    ("p5")
                  DW_AT_decl_file      
("/home/user/upstream/master/stack_dbg_values.c")
                  DW_AT_decl_line       (3)
                  DW_AT_type    (0x0000008e "short")

I think there are two issues here. For p4, we do not consider truncates when
searching for the FI in SelectionDAGBuilder::EmitFuncArgumentDbgValue(),
meaning that we are left with a $noreg DBG_VALUE, ultimately leading to no
location being emitted for the parameter. For p5, we say that it is located on
the stack at offset 4, but as we are on a big-endian target the two-byte short
parameter is located in the lower two bytes of the 4-byte stack slot, meaning
that the offset should really be 6.

Compare this with the output from GCC (5.4.1):

$ arm-none-eabi-gcc -O1 -g -mbig-endian stack_dbg_values.c -c

0x00000072:     DW_TAG_formal_parameter
                  DW_AT_name    ("p4")
                  DW_AT_decl_file      
("/home/user/upstream/master/stack_dbg_values.c")
                  DW_AT_decl_line       (3)
                  DW_AT_type    (0x000000a6 "short int")
                  DW_AT_location        (DW_OP_fbreg +2)

0x0000007f:     DW_TAG_formal_parameter
                  DW_AT_name    ("p5")
                  DW_AT_decl_file      
("/home/user/upstream/master/stack_dbg_values.c")
                  DW_AT_decl_line       (3)
                  DW_AT_type    (0x000000a6 "short int")
                  DW_AT_location        (DW_OP_fbreg +6)</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>