<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 - DWARF incorrect for natively-sized bitfields"
   href="https://bugs.llvm.org/show_bug.cgi?id=44601">44601</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>DWARF incorrect for natively-sized bitfields
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>8.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>other
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>levon@movementarian.org
          </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>This test case comes via Robert Mustacchi.

$ llvm-config --version
8.0.1
$ clang --version
clang version 8.0.1 (tags/RELEASE_801/final)
Target: i386-pc-solaris2.11

$ cat a.c

struct bitfields {
        unsigned int first:7;
        unsigned int second:32;
} __attribute__((packed));

struct bitfields mb;

$ clang -gdwarf-4 -m32 -c -o a.o a.c
$ gobjdump --dwarf a.o >dwarf.out

The DWARF produced has:

 74  <1><1e>: Abbrev Number: 2 (DW_TAG_variable)
 75     <1f>   DW_AT_name        : (indirect string, offset: 0x41): mb
 76     <23>   DW_AT_type        : <0x2f>
 77     <27>   DW_AT_external    : 1
 78     <27>   DW_AT_decl_file   : 1
 79     <28>   DW_AT_decl_line   : 7
 80     <29>   DW_AT_location    : 5 byte block: 3 0 0 0 0  (DW_OP_addr: 0)
 81  <1><2f>: Abbrev Number: 3 (DW_TAG_structure_type)
 82     <30>   DW_AT_name        : (indirect string, offset: 0x5e): bitfields
 83     <34>   DW_AT_byte_size   : 5
 84     <35>   DW_AT_decl_file   : 1
 85     <36>   DW_AT_decl_line   : 2
 86  <2><37>: Abbrev Number: 4 (DW_TAG_member)
 87     <38>   DW_AT_name        : (indirect string, offset: 0x44): first
 88     <3c>   DW_AT_type        : <0x53>
 89     <40>   DW_AT_decl_file   : 1
 90     <41>   DW_AT_decl_line   : 3
 91     <42>   DW_AT_byte_size   : 4
 92     <43>   DW_AT_bit_size    : 7
 93     <44>   DW_AT_bit_offset  : 25
 94     <45>   DW_AT_data_member_location: 0
 95  <2><46>: Abbrev Number: 5 (DW_TAG_member)
 96     <47>   DW_AT_name        : (indirect string, offset: 0x57): second
 97     <4b>   DW_AT_type        : <0x53>
 98     <4f>   DW_AT_decl_file   : 1
 99     <50>   DW_AT_decl_line   : 4
100     <51>   DW_AT_data_member_location: 0

Note the lack of bit_offset and such for the 'second' member. GCC for the same
structure member produces (correctly I believe):

 32  <2><38>: Abbrev Number: 4 (DW_TAG_member)
 33     <39>   DW_AT_name        : (indirect string, offset: 0x23): second
 34     <3d>   DW_AT_decl_file   : 1
 35     <3e>   DW_AT_decl_line   : 4
 36     <3f>   DW_AT_type        : <0x48>
 37     <43>   DW_AT_byte_size   : 4
 38     <44>   DW_AT_bit_size    : 32
 39     <45>   DW_AT_bit_offset  : -7
 40     <46>   DW_AT_data_member_location: 0


I haven't proven it, but this line seems suspiciously pertinent:

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

 1481   bool IsBitfield = FieldSize && Size != FieldSize;

Comparing the bitfield size against the bitfield's type's size is not
sufficient in this case.</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>