llvm / llvm/llvm-project

[llvm][DebugInfo] LLVM adds redundant DW_AT_data_member_location to C++ union members

Open
#160,708 4 comments 0 reactions 0 assignees View on GitHub
clang:codegen debuginfo
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

GCC and LLVM diverge in this. GCC chooses to omit `DW_AT_data_member_location` for union members because it's going to be `0x0` anyway. LLVM still adds the attribute: [Godbolt](https://godbolt.org/z/jvfMj9Ko7)

Here's the LLVM DWARF:
```
0x00000034: DW_TAG_member
DW_AT_name ("x")
DW_AT_type (0x00000047 "int")
DW_AT_decl_file ("/app/example.cpp")
DW_AT_decl_line (2)
DW_AT_data_member_location (0x00)

0x0000003d: DW_TAG_member
DW_AT_name ("y")
DW_AT_type (0x00000047 "int")
DW_AT_decl_file ("/app/example.cpp")
DW_AT_decl_line (3)
DW_AT_data_member_location (0x00)
```

This came up in https://github.com/llvm/llvm-project/pull/159401. LLDB already knows how to handle both cases, so LLVM could choose to omit it. Not sure if the size benefits would be particularly appealing, to warrant the extra complexity. Though if it's just a case of "don't emit DW_AT_data_member_location for union types", that's rather trivial to implement.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.