[llvm-bugs] [Bug 44601] New: DWARF incorrect for natively-sized bitfields

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 21 01:33:01 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=44601

            Bug ID: 44601
           Summary: DWARF incorrect for natively-sized bitfields
           Product: libraries
           Version: 8.0
          Hardware: PC
                OS: other
            Status: NEW
          Severity: normal
          Priority: P
         Component: DebugInfo
          Assignee: unassignedbugs at nondot.org
          Reporter: levon at movementarian.org
                CC: jdevlieghere at apple.com, keith.walker at arm.com,
                    llvm-bugs at lists.llvm.org,
                    paul_robinson at playstation.sony.com

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:

https://github.com/llvm-mirror/llvm/blob/master/lib/CodeGen/AsmPrinter/DwarfUnit.cpp#L1481

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

Comparing the bitfield size against the bitfield's type's size is not
sufficient in this case.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200121/4ced824f/attachment.html>


More information about the llvm-bugs mailing list