Skip to content

Commit cee353c

Browse files
committed
d: Fix forward referenced enums missing type names in debug info [PR118309]
Calling `rest_of_type_compilation' as the D types were built meant that debug info was being emitted before all forward references were resolved, resulting in DW_AT_name's to be missing. Instead, defer outputting type debug information until all modules have been parsed and generated in `d_finish_compilation'. PR d/118309 gcc/d/ChangeLog: * modules.cc: Include debug.h (d_finish_compilation): Call debug_hooks->type_decl on all TYPE_DECLs. * types.cc: Remove toplev.h include. (finish_aggregate_type): Don't call rest_of_type_compilation or rest_of_decl_compilation on type. (TypeVisitor::visit (TypeEnum *)): Likewise. gcc/testsuite/ChangeLog: * gdc.dg/debug/dwarf2/pr118309.d: New test.
1 parent 8df0de9 commit cee353c

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

gcc/d/modules.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see
3030
#include "function.h"
3131
#include "cgraph.h"
3232
#include "stor-layout.h"
33+
#include "debug.h"
3334
#include "toplev.h"
3435
#include "target.h"
3536
#include "common/common-target.h"
@@ -927,6 +928,14 @@ d_finish_compilation (tree *vec, int len)
927928
/* Complete all generated thunks. */
928929
symtab->process_same_body_aliases ();
929930

931+
/* Output debug information for all type declarations in this unit. */
932+
for (int i = 0; i < len; i++)
933+
{
934+
tree decl = vec[i];
935+
if (TREE_CODE (decl) == TYPE_DECL)
936+
debug_hooks->type_decl (decl, false);
937+
}
938+
930939
/* Process all file scopes in this compilation, and the external_scope,
931940
through wrapup_global_declarations. */
932941
for (int i = 0; i < len; i++)

gcc/d/types.cc

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ along with GCC; see the file COPYING3. If not see
3333
#include "langhooks.h"
3434
#include "tm.h"
3535
#include "function.h"
36-
#include "toplev.h"
3736
#include "target.h"
3837
#include "stringpool.h"
3938
#include "stor-layout.h"
@@ -709,13 +708,8 @@ finish_aggregate_type (unsigned structsize, unsigned alignsize, tree type)
709708
TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
710709
}
711710

712-
/* Finish debugging output for this type. */
713-
rest_of_type_compilation (type, TYPE_FILE_SCOPE_P (type));
711+
/* Complete any other forward-referenced fields of this aggregate type. */
714712
finish_incomplete_fields (type);
715-
716-
/* Finish processing of TYPE_DECL. */
717-
rest_of_decl_compilation (TYPE_NAME (type),
718-
DECL_FILE_SCOPE_P (TYPE_NAME (type)), 0);
719713
}
720714

721715
/* Returns true if the class or struct type TYPE has already been layed out by
@@ -1185,13 +1179,8 @@ class TypeVisitor : public Visitor
11851179

11861180
layout_type (t->ctype);
11871181

1188-
/* Finish debugging output for this type. */
1189-
rest_of_type_compilation (t->ctype, TYPE_FILE_SCOPE_P (t->ctype));
1182+
/* Complete forward-referenced fields of this enum type. */
11901183
finish_incomplete_fields (t->ctype);
1191-
1192-
/* Finish processing of TYPE_DECL. */
1193-
rest_of_decl_compilation (TYPE_NAME (t->ctype),
1194-
DECL_FILE_SCOPE_P (TYPE_NAME (t->ctype)), 0);
11951184
}
11961185
}
11971186

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// { dg-do compile }
2+
// { dg-options "-fno-druntime -gdwarf-4 -dA -fno-merge-debug-strings" }
3+
// { dg-final { scan-assembler-times "DIE\[^\n\r\]*DW_TAG_enumeration_type" 1 } }
4+
// { dg-final { scan-assembler-times " DW_AT_enum_class" 1 } }
5+
// { dg-final { scan-assembler-times "\"E..\"\[^\n\]*DW_AT_name" 1 } }
6+
// { dg-final { scan-assembler-times "\"E1..\"\[^\n\]*DW_AT_name" 1 } }
7+
// { dg-final { scan-assembler-times "\"C1..\"\[^\n\]*DW_AT_name" 1 } }
8+
// { dg-final { scan-assembler-times "\"C2..\"\[^\n\]*DW_AT_name" 1 } }
9+
// { dg-final { scan-assembler-times "\"C3..\"\[^\n\]*DW_AT_name" 1 } }
10+
// { dg-final { scan-assembler-times "\"C4..\"\[^\n\]*DW_AT_name" 1 } }
11+
// { dg-final { scan-assembler-times "\"S1..\"\[^\n\]*DW_AT_name" 1 } }
12+
13+
module expression;
14+
extern (C++):
15+
class C1
16+
{
17+
bool bfn() { return true; }
18+
}
19+
class C2 : C1
20+
{
21+
C4 cfn() { return null; }
22+
}
23+
class C3 : C2
24+
{
25+
S1.E s;
26+
}
27+
class C4 : C3
28+
{
29+
S1 s;
30+
}
31+
struct S1
32+
{
33+
enum E : ubyte { E1 }
34+
E e;
35+
C3 c;
36+
}

0 commit comments

Comments
 (0)