<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 - DwarfUnit::constructMemberDIE computes incorrect member location"
   href="https://bugs.llvm.org/show_bug.cgi?id=36654">36654</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>DwarfUnit::constructMemberDIE computes incorrect member location
          </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>tom@tromey.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>A recent version of the Rust compiler (using LLVM 6) can generate
DWARF like this for an enum:

 <2><2c92>: Abbrev Number: 10 (DW_TAG_union_type)
    <2c93>   DW_AT_name        : (indirect string, offset: 0x28bf):
MoreComplicated
    <2c97>   DW_AT_byte_size   : 24
    <2c98>   DW_AT_alignment   : 8
 <3><2c99>: Abbrev Number: 18 (DW_TAG_member)
    <2c9a>   DW_AT_type        : <0x2cc8>
    <2c9e>   DW_AT_byte_size   : 24
    <2c9f>   DW_AT_bit_size    : 8
    <2ca0>   DW_AT_bit_offset  : 56
    <2ca1>   DW_AT_data_member_location: 0x1ffffffffffffff0
[...]


First, and most importantly, the data member location is wrong.

Second, I don't believe it is valid to emit both a byte size and a bit size.
DWARF documents these as exclusive.


The data member location comes from the code starting here:

<a href="https://github.com/llvm-mirror/llvm/blob/master/lib/CodeGen/AsmPrinter/DwarfUnit.cpp#L1505">https://github.com/llvm-mirror/llvm/blob/master/lib/CodeGen/AsmPrinter/DwarfUnit.cpp#L1505</a>

In particular what I believe is going wrong is that here:

<a href="https://github.com/llvm-mirror/llvm/blob/master/lib/CodeGen/AsmPrinter/DwarfUnit.cpp#L1500-L1501">https://github.com/llvm-mirror/llvm/blob/master/lib/CodeGen/AsmPrinter/DwarfUnit.cpp#L1500-L1501</a>

we have Size==8 and FieldSize==192.  However, the alignment computation
(which per the comment already seems suspect):

      // We can't use DT->getAlignInBits() here: AlignInBits for member type
      // is non-zero if and only if alignment was forced (e.g. _Alignas()),
      // which can't be done with bitfields. Thus we use FieldSize here.
      uint32_t AlignInBits = FieldSize;
      uint32_t AlignMask = ~(AlignInBits - 1);

... only works properly when the field size is a power of 2.


One option for this code might be to tighten the definition of "bitfield"
to only encompass things that actually require sub-byte resolution.

If negative data member locations are desirable (Rust doesn't need them but
maybe something does) then the code that gets the byte offset from the
field offset probably has to be done using a signed type.</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>