<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61952>61952</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Incomplete debug information for _BitInt(N) when N differs from store size
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          dstenb
      </td>
    </tr>
</table>

<pre>
    Sorry in case there already is a ticket for this. I have tried to dig to understand the history of this looking back at _ExtInt, and have searched for tickets that cover this issue for either _ExtInt or _BitInt, but haven't found one.

Currently Clang emits base types for _BitInt(N) types with the name "unsigned _BitInt" or "_BitInt", with the DW_AT_byte_size value being the store size. There is no information regarding the number of bits, N, which leaves the debugger unable to (at least) properly print negative values when N differs from the store size, as it then prints a DW_AT_byte_size-sized value including the zero-valued padding bits.

Example:

```
_BitInt(15) a = -1wb;
_BitInt(16) b = -1wb;
int main() { return 0; }
```

Running:

```
$ build/bin/clang -g bitint.c -o bitint.out
```

gives:

```
0x00000023: DW_TAG_variable
                DW_AT_name      ("a")
 DW_AT_type      (0x0000002e "_BitInt")
                DW_AT_external (true)
                DW_AT_decl_file ("/repo/edasten/upstream/llvm-project/bitint.c")
 DW_AT_decl_line (1)
                DW_AT_location  (DW_OP_addrx 0x0)

0x0000002e:   DW_TAG_base_type
                DW_AT_name ("_BitInt")
                DW_AT_encoding  (DW_ATE_signed)
 DW_AT_byte_size (0x02)

0x00000032:   DW_TAG_variable
 DW_AT_name      ("b")
                DW_AT_type      (0x0000002e "_BitInt")
                DW_AT_external  (true)
 DW_AT_decl_file ("/repo/edasten/upstream/llvm-project/bitint.c")
 DW_AT_decl_line (2)
                DW_AT_location  (DW_OP_addrx 0x1)
```

LLDB (trunk):

```
$ build/bin/lldb bitint.out
(lldb) b main
Breakpoint 1: where = bitint.out`main + 11 at bitint.c:3:14, address = 0x000000000000069b
(lldb) run
Process 158466 launched: '/repo/edasten/upstream/llvm-project/bitint.out' (x86_64)
Process 158466 stopped
* thread #1, name = 'bitint.out', stop reason = breakpoint 1.1
    frame #0: 0x000055555555469b bitint.out`main at bitint.c:3:14
   1    _BitInt(15) a = -1wb;
   2    _BitInt(16) b = -1wb;
-> 3    int main() { return 0; }
(lldb) p a
(short) 32767
(lldb) p b
(short) -1
```

GDB (version 11.1, I have not tried a latter version yet):

```
(gdb) b main
Breakpoint 1 at 0x69b: file bitint.c, line 3.
(gdb) run
Starting program: /repo/edasten/upstream/llvm-project/bitint.out 

Breakpoint 1, main () at bitint.c:3
3       int main() { return 0; }
(gdb) p a
$1 = 32767
(gdb) p b
$2 = -1
```
The debugger must be informed in some way of the number of bits in the _BitInt, either expressed in the type itself, or we need to make sure that the locations include an explicit signed cast from the number of data bits to the store size.

Has there been any work related to this?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8V1tv4roT_zTmZQRKHAjwwAOUsv-VVvtfna20j8hOhsSnwY5sh8t--qNxArTAtt3V0YmqtHXm8purZ4RzqtCIMzZasNGyJxpfGjvLnUcte9Lkx9l3Y-0RlIZMOARfokUQlUWRH0E5EOBV9oweNsaCL5UbwGcoxQ7BW4U5eAO5KuhXo3O0zgudkxQolfPGHsFsAhtUxjwrXYAU2TMID-vHg_-sPeMPQCxBpENhsxLzVlnQ68CXwkNmdtjqB-Vcg4ECFcE9SQJjYb1QJ6Gy8UGoZnxM6Budg9E4YNGSRfP2_dBYi9pXR3iohC4At8o7kMERxxpd0HKWOfnK-LT7sFe-DGZqsUVgnDc6eDq_kHMCxDi_HBCsM-Pyx3r-tJZHj2unfiLsRNUgSCQf0XfyHgJ9GsBTiIpyoA0ovTF2K7wyGiwWwuYnDt1sJVpyuFTekbKvQWOpshIqFDt0gS5H2RQFWmi0kBVS7BifCE80zpONtTU12uoItVXag8ZCeLXrMDrYl6jhK-Rqs0HrYGPN9gpyiKoD5elct2Iol66M7tMr70xXOqu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