https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105785
Bug ID: 105785 Summary: DIEs for local types are emitted at wrong scope in DWARF debug info Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: wrong-debug Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: nils-christian.kempke at intel dot com Target Milestone: --- This was tested with ------------------------------------------------------------------- >> gfortran --version GNU Fortran (GCC) 13.0.0 20220510 (experimental) ... ------------------------------------------------------------------- Compiling a Fortran program with a locally defined type as in ------------------------------------------------------------------- >> cat f.f90 program prog type :: test integer :: int end type test type (test) :: test_var test_var%int = 33 print *, test_var end program prog >> gfortran -O0 -g ./f.f90 >> ------------------------------------------------------------------- and checking its debug info we see ------------------------------------------------------------------- >> objdump --dwarf=info ./a.out ... <0><c>: Abbrev Number: 3 (DW_TAG_compile_unit) ... <1><2f>: Abbrev Number: 4 (DW_TAG_structure_type) <30> DW_AT_name : (indirect string, offset: 0x117): test ... <38> DW_AT_sibling : <0x4a> <2><3c>: Abbrev Number: 5 (DW_TAG_member) <3d> DW_AT_name : int ... <2><49>: Abbrev Number: 0 ... <1><9f>: Abbrev Number: 9 (DW_TAG_subprogram) <a0> DW_AT_name : (indirect string, offset: 0x20): prog ... <2><ba>: Abbrev Number: 10 (DW_TAG_variable) <bb> DW_AT_name : (indirect string, offset: 0x17): test_var ... <2><c9>: Abbrev Number: 0 <1><ca>: Abbrev Number: 0 ------------------------------------------------------------------- The type declared inside the Fortran program prog is emitted as a child of the whole compile unit even though its visibility is limited to the scope of prog. It should instead be emitted as a child of the DW_TAG_subprogram prog (as to limit its visibility appropriately).