llvm-project
llvm-project copied to clipboard
[DWARF] DW_TAG_pointer_type DIE duplicated unnecessarily
target x86_64-unknown-linux-gnu using clang built at 54586582d3e1 (17th Dec 2021)
$ test.cpp
struct A {
int B;
A(): B(0) {}
} C;
$ clang++ test.cpp -c -gdwarf-5 -o - | llvm-dwarfdump - -o -
<snip>
0x00000043: DW_TAG_subprogram
DW_AT_name ("A")
DW_AT_decl_file ("test.cpp")
DW_AT_decl_line (3)
DW_AT_declaration (true)
DW_AT_external (true)
0x00000047: DW_TAG_formal_parameter
DW_AT_type (0x00000052 "A *")
DW_AT_artificial (true)
<snip>
0x00000052: DW_TAG_pointer_type
DW_AT_type (0x00000034 "A")
0x00000057: DW_TAG_subprogram
DW_AT_low_pc (0x0000000000000000)
DW_AT_high_pc (0x0000000000000014)
DW_AT_frame_base (DW_OP_reg6 RBP)
DW_AT_object_pointer (0x00000068)
DW_AT_linkage_name ("_ZN1AC2Ev")
DW_AT_specification (0x00000043 "A")
0x00000068: DW_TAG_formal_parameter
DW_AT_location (DW_OP_fbreg -8)
DW_AT_name ("this")
DW_AT_type (0x00000086 "A *")
DW_AT_artificial (true)
<snip>
0x00000086: DW_TAG_pointer_type
DW_AT_type (0x00000034 "A")
There are two instances of DW_TAG_pointer_type(DW_AT_type(A)): 0x00000052 and 0x00000086. We only need one of these - each extra is unnecessary.
Looks like an IR representational issue (not entirely Clang's fault, may have to change how the IR works though):
!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
...
!27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
End up as two distinct types. The extra flags on the type are used to create the DW_AT_object_pointer on the DW_TAG_subprogram and the DW_AT_artificial on the DW_TAG_formal_parameter - so maybe they could be stored on a separate wrapper DIDerivedType that could be stripped off.