https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118117
Bug ID: 118117 Summary: Array Of Nested Structs Makes Inner Struct Anonymous Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lgomez at windhoverlabs dot com Target Milestone: --- Given the following code ``` #define USE_VIRTUAL #define USE_ARRAY struct t1 { typedef struct { } t2; #ifdef USE_VIRTUAL virtual void f1(); #endif }; t1::t2 v1 #ifdef USE_ARRAY [1] #endif ; ``` "v1" shows up as anonymous on DWARF: <source>: file format elf32-littlearm .debug_info contents: 0x00000000: Compile Unit: length = 0x00000051, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x04 (next unit at 0x00000055) 0x0000000c: DW_TAG_compile_unit DW_AT_producer ("GNU C++17 14.2.0 -mcpu=arm7tdmi -mfloat-abi=soft -marm -march=armv4t -g") DW_AT_language (DW_LANG_C_plus_plus_14) DW_AT_name ("/app/example.cpp") DW_AT_comp_dir ("/app") DW_AT_stmt_list (0x00000000) 0x0000001e: DW_TAG_structure_type DW_AT_name ("t1") DW_AT_declaration (true) DW_AT_sibling (0x0000002c) 0x00000026: DW_TAG_structure_type DW_AT_byte_size (0x01) DW_AT_decl_file ("/app/example.cpp") DW_AT_decl_line (3) DW_AT_decl_column (20) 0x0000002b: NULL 0x0000002c: DW_TAG_array_type DW_AT_type (0x00000026 "t1::structure ") DW_AT_sibling (0x0000003c) 0x00000035: DW_TAG_subrange_type DW_AT_type (0x0000003c "unsigned int") DW_AT_upper_bound (0x00) 0x0000003b: NULL 0x0000003c: DW_TAG_base_type DW_AT_byte_size (0x04) DW_AT_encoding (DW_ATE_unsigned) DW_AT_name ("unsigned int") 0x00000043: DW_TAG_variable DW_AT_name ("v1") DW_AT_decl_file ("/app/example.cpp") DW_AT_decl_line (10) DW_AT_decl_column (8) DW_AT_type (0x0000002c "t1::structure [1]") DW_AT_external (true) DW_AT_location (DW_OP_addr 0x0) 0x00000054: NULL Notice that "v1" points to an array which points to an anonymous struct (a DW_TAG_structure_type with no DW_AT_name attribute) If I were to undef "USE_ARRAY" I get the following output: <source>: file format elf32-littlearm .debug_info contents: 0x00000000: Compile Unit: length = 0x00000049, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x04 (next unit at 0x0000004d) 0x0000000c: DW_TAG_compile_unit DW_AT_producer ("GNU C++17 14.2.0 -mcpu=arm7tdmi -mfloat-abi=soft -marm -march=armv4t -g") DW_AT_language (DW_LANG_C_plus_plus_14) DW_AT_name ("/app/example.cpp") DW_AT_comp_dir ("/app") DW_AT_stmt_list (0x00000000) 0x0000001e: DW_TAG_structure_type DW_AT_name ("t1") DW_AT_declaration (true) DW_AT_sibling (0x0000003b) 0x00000026: DW_TAG_structure_type DW_AT_byte_size (0x01) DW_AT_decl_file ("/app/example.cpp") DW_AT_decl_line (3) DW_AT_decl_column (20) DW_AT_linkage_name ("N2t12t2E") 0x0000002f: DW_TAG_typedef DW_AT_name ("t2") DW_AT_decl_file ("/app/example.cpp") DW_AT_decl_line (4) DW_AT_decl_column (7) DW_AT_type (0x00000026 "t1::structure ") 0x0000003a: NULL 0x0000003b: DW_TAG_variable DW_AT_name ("v1") DW_AT_decl_file ("/app/example.cpp") DW_AT_decl_line (10) DW_AT_decl_column (8) DW_AT_type (0x0000002f "t1::t2") DW_AT_external (true) DW_AT_location (DW_OP_addr 0x0) 0x0000004c: NULL Which is one what one would expect since in source code I can refer to the type "t1::t2" pretty concretely. I should point out that this DOES NOT happen in clang x86-64 19.10: ``` <source>: file format elf64-x86-64 .debug_info contents: 0x00000000: Compile Unit: length = 0x00000059, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000005d) 0x0000000b: DW_TAG_compile_unit DW_AT_producer ("clang version 19.1.0 (https://github.com/llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)") DW_AT_language (DW_LANG_C_plus_plus_14) DW_AT_name ("/app/example.cpp") DW_AT_stmt_list (0x00000000) DW_AT_comp_dir ("/app") 0x0000001e: DW_TAG_variable DW_AT_name ("v1") DW_AT_type (0x00000033 "t1::t2[1]") DW_AT_external (true) DW_AT_decl_file ("/app/example.cpp") DW_AT_decl_line (11) DW_AT_location (DW_OP_addr 0x0) 0x00000033: DW_TAG_array_type DW_AT_type (0x00000044 "t1::t2") 0x00000038: DW_TAG_subrange_type DW_AT_type (0x00000055 "__ARRAY_SIZE_TYPE__") DW_AT_count (0x01) 0x0000003e: NULL 0x0000003f: DW_TAG_structure_type DW_AT_name ("t1") DW_AT_declaration (true) 0x00000044: DW_TAG_typedef DW_AT_type (0x0000004f "t1::structure ") DW_AT_name ("t2") DW_AT_decl_file ("/app/example.cpp") DW_AT_decl_line (4) 0x0000004f: DW_TAG_structure_type DW_AT_calling_convention (DW_CC_pass_by_value) DW_AT_byte_size (0x01) DW_AT_decl_file ("/app/example.cpp") DW_AT_decl_line (3) 0x00000054: NULL 0x00000055: DW_TAG_base_type DW_AT_name ("__ARRAY_SIZE_TYPE__") DW_AT_byte_size (0x08) DW_AT_encoding (DW_ATE_unsigned) 0x0000005c: NULL ``` If you want to explore the code:https://godbolt.org/z/n6MfoGhGd Hope this report was clear and concise. Thanks Lorenzo