Skip to content

Incomplete debug information for _BitInt(N) when N differs from store size #61952

@dstenb

Description

@dstenb

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 ("/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 ("/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: '/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: /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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.debuginfo

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions