Should "imports" list in DICompileUnit have duplication of DIImportedEntity?

Hi,

It looks like Clang FE does not treat imported entities list (“imports”) as a set that has no duplication.

In the below simple example, imported entities list contains a duplication for same DIImportedEntity, which will end up having duplication of this imported entity in the dwarf debug info section (see below).

Should “imports” list in DICompileUnit have duplication of DIImportedEntity?

Do you think we should fix Clang to assure the “imports” list is a unique set?

Notice that there is no added value to have the same entity duplicated!

Thanks,
Amjad

The example (using the attached files):

Command-line: clang -cc1 -S -emit-llvm -o - -debug-info-kind=limited TestIM.cpp
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: “clang version 3.9.0 (trunk 261634) (llvm/trunk 261633)”, isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, imports: !3)
!1 = !DIFile(filename: " ", directory: “\”)
!2 = !{}
!3 = !{!4, !4} <---------------------------- Bug: same entity appears twice in the imported entities list!
!4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !7, line: 8)
!5 = !DINamespace(name: “Y”, scope: null, file: !6, line: 7)

Command-line: clang -cc1 -S -emit-obj -o - -debug-info-kind=limited TestIM.cpp | llvm-dwarfdump.exe -debug-dump=info –

0x0000000b: DW_TAG_compile_unit [1] *

DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000000] = “clang version 3.9.0 (trunk 259349) (llvm/trunk 259357)”)

DW_AT_language [DW_FORM_data2] (DW_LANG_C_plus_plus)

DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000037] = " ")

DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000)

DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x0000004e] = " \ ")

0x0000001e: DW_TAG_namespace [2] *

DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000074] = “Y”)

DW_AT_decl_file [DW_FORM_data1] (“TestIM.h”)

DW_AT_decl_line [DW_FORM_data1] (7)

0x00000025: DW_TAG_imported_declaration [3]

DW_AT_decl_file [DW_FORM_data1] (“TestIM.h”)

DW_AT_decl_line [DW_FORM_data1] (8)

DW_AT_import [DW_FORM_ref4] (cu + 0x003b => {0x0000003b})

0x0000002c: DW_TAG_imported_declaration [3] <---------------------------- duplication of 0x00000025

DW_AT_decl_file [DW_FORM_data1] (“TestIM.h”)

DW_AT_decl_line [DW_FORM_data1] (8)

DW_AT_import [DW_FORM_ref4] (cu + 0x003b => {0x0000003b})

0x00000033: NULL

TestIM.H (85 Bytes)

TestIM.CPP (46 Bytes)

Hi,
It looks like Clang FE does not treat imported entities list (“imports”) as a set that has no duplication.
In the below simple example, imported entities list contains a duplication for same DIImportedEntity, which will end up having duplication of this imported entity in the dwarf debug info section (see below).

It looks like we get into this situation easily since DIBuilder::createImportedModule will add every namespace mentioned in a using directive.

Should "imports" list in DICompileUnit have duplication of DIImportedEntity?

Right now I can’t think of a good reason where this would be useful. And if it is useful, we can always use distinct MDNodes to work around the problem.

Do you think we should fix Clang to assure the "imports" list is a unique set?

I would also take a look at the DIBuilder interface — it may or may not be better to unique them there.

Notice that there is no added value to have the same entity duplicated!

thanks for noticing!

adrian

Yeah, I can’t see any reason we’d benefit from them either.