[llvm-bugs] [Bug 36654] New: DwarfUnit::constructMemberDIE computes incorrect member location

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 8 13:05:48 PST 2018


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

            Bug ID: 36654
           Summary: DwarfUnit::constructMemberDIE computes incorrect
                    member location
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: DebugInfo
          Assignee: unassignedbugs at nondot.org
          Reporter: tom at tromey.com
                CC: llvm-bugs at lists.llvm.org

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:

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

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

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

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.

-- 
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/20180308/1cbe77ce/attachment.html>


More information about the llvm-bugs mailing list