[llvm] [DebugInfo] Emit negative DW_AT_bit_offset in explicit signed form (PR #87994)

Victor Campos via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 8 08:32:12 PDT 2024


vhscampos wrote:

This is apparent in packed structs with bitfields:

```c
struct {
  char : 3;
  char a : 6;
} __attribute__((__packed__)) b;
```

gcc produces the following debug information with `-gdwarf-3`:
.debug_abbrev:
```
  3      DW_TAG_member    [no children]
    DW_AT_name         DW_FORM_string
    DW_AT_decl_file    DW_FORM_data1
    DW_AT_decl_line    DW_FORM_data1
    DW_AT_decl_column  DW_FORM_data1
    DW_AT_type         DW_FORM_ref4
    DW_AT_byte_size    DW_FORM_data1
    DW_AT_bit_size     DW_FORM_data1
    DW_AT_bit_offset   DW_FORM_sdata
    DW_AT_data_member_location DW_FORM_data1
```

.debug_info:
```
 <2><26>: Abbrev Number: 3 (DW_TAG_member)
    <27>   DW_AT_name        : a
    <29>   DW_AT_decl_file   : 1
    <2a>   DW_AT_decl_line   : 3
    <2b>   DW_AT_decl_column : 8
    <2c>   DW_AT_type        : <0x35>
    <30>   DW_AT_byte_size   : 1
    <31>   DW_AT_bit_size    : 6
    <32>   DW_AT_bit_offset  : -1
    <33>   DW_AT_data_member_location: 0
```

In contract, clang generates this:
.debug_abbrev:
```
   4      DW_TAG_member    [no children]
    DW_AT_name         DW_FORM_strp
    DW_AT_type         DW_FORM_ref4
    DW_AT_decl_file    DW_FORM_data1
    DW_AT_decl_line    DW_FORM_data1
    DW_AT_byte_size    DW_FORM_data1
    DW_AT_bit_size     DW_FORM_data1
    DW_AT_bit_offset   DW_FORM_data8
    DW_AT_data_member_location DW_FORM_udata
```

.debug_info:
```
 <2><38>: Abbrev Number: 4 (DW_TAG_member)
    <39>   DW_AT_name        : (indirect string, offset: 0x34): a
    <3d>   DW_AT_type        : <0x4f>
    <41>   DW_AT_decl_file   : 1
    <42>   DW_AT_decl_line   : 3
    <43>   DW_AT_byte_size   : 1
    <44>   DW_AT_bit_size    : 6
    <45>   DW_AT_bit_offset  : 0xffffffffffffffff
    <4d>   DW_AT_data_member_location: 0
```

Note how clang uses DW_FORM_data8 and a value of 0xffffffffffffffff

https://github.com/llvm/llvm-project/pull/87994


More information about the llvm-commits mailing list