From a082c85a4365cc2a9b73ecc6547075d3c352d46c Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sat, 9 Nov 1996 01:32:56 +0000 Subject: [PATCH] x From-SVN: r13116 --- gcc/dwarf2out.c | 38 ++++++++++++++++++++++++++++---------- gcc/stor-layout.c | 2 +- gcc/toplev.c | 8 ++------ gcc/tree.def | 10 ++++++---- gcc/tree.h | 5 +++-- gcc/varasm.c | 38 ++++++++++++++++++++++++-------------- 6 files changed, 64 insertions(+), 37 deletions(-) diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index bfc47ad..e5e2182 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -6358,6 +6358,7 @@ gen_enumeration_type_die (type, context_die) if (TYPE_SIZE (type)) { register tree link; + TREE_ASM_WRITTEN (type) = 1; add_byte_size_attribute (type_die, type); for (link = TYPE_FIELDS (type); link != NULL; link = TREE_CHAIN (link)) @@ -7119,18 +7120,26 @@ gen_struct_or_union_type_die (type, context_die) register dw_die_ref context_die; { register dw_die_ref type_die = lookup_type_die (type); + register dw_die_ref scope_die = 0; + register int nested = 0; if (type_die && ! TYPE_SIZE (type)) return; - else if (! type_die - || (TYPE_CONTEXT (type) - && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')) + + if (TYPE_CONTEXT (type) + && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't') + nested = 1; + + if (! type_die || nested) + scope_die = scope_die_for (type, context_die); + + if (! type_die || (nested && scope_die == comp_unit_die)) /* First occurrence of type or toplevel definition of nested class. */ { register dw_die_ref old_die = type_die; type_die = new_die (TREE_CODE (type) == RECORD_TYPE ? DW_TAG_structure_type : DW_TAG_union_type, - scope_die_for (type, context_die)); + scope_die); equate_type_number_to_die (type, type_die); add_name_attribute (type_die, type_tag (type)); if (old_die) @@ -7141,7 +7150,11 @@ gen_struct_or_union_type_die (type, context_die) /* If this type has been completed, then give it a byte_size attribute and then give a list of members. */ - if (TYPE_SIZE (type)) + if (TYPE_SIZE (type) + /* If we're getting a reference to one nested class from another + nested class, don't recurse. */ + && ! (nested && scope_die != context_die + && scope_die == lookup_type_die (TYPE_CONTEXT (type)))) { /* Prevent infinite recursion in cases where the type of some member of this type is expressed in terms of this type itself. */ @@ -7279,16 +7292,21 @@ gen_type_die (type, context_die) case RECORD_TYPE: case UNION_TYPE: case QUAL_UNION_TYPE: - if (TREE_CODE (type) == ENUMERAL_TYPE) + /* If this is a nested type whose containing class hasn't been + written out yet, writing it out will cover this one, too. */ + if (TYPE_CONTEXT (type) + && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't' + && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) + gen_type_die (TYPE_CONTEXT (type), context_die); + else if (TREE_CODE (type) == ENUMERAL_TYPE) gen_enumeration_type_die (type, context_die); else gen_struct_or_union_type_die (type, context_die); /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix - it up if it is ever completed. */ - if (TYPE_SIZE (type) == NULL_TREE) - return; - break; + it up if it is ever completed. gen_*_type_die will set it for us + when appropriate. */ + return; case VOID_TYPE: case INTEGER_TYPE: diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index b0b64d2..e7af7d2 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -336,7 +336,7 @@ layout_record (rec) In both cases, all we do is lay out the decl, and we do it *after* the record is laid out. */ - if (TREE_STATIC (field)) + if (TREE_CODE (field) == VAR_DECL) { pending_statics = tree_cons (NULL_TREE, field, pending_statics); continue; diff --git a/gcc/toplev.c b/gcc/toplev.c index b080e19..96fa07a 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -2752,12 +2752,8 @@ rest_of_type_compilation (type, toplev) TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev)); #endif #ifdef DWARF_DEBUGGING_INFO - /* If this is a file-scope type or a class-scope type - for which the containing class has already been completed, write it - out now to avoid ordering headaches with member functions. */ - if (write_symbols == DWARF_DEBUG - && (TYPE_CONTEXT (type) == NULL_TREE - || TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))) + /* Don't write out function-scope types here. */ + if (write_symbols == DWARF_DEBUG && toplev) TIMEVAR (symout_time, dwarfout_file_scope_decl (TYPE_STUB_DECL (type), 0)); #endif } diff --git a/gcc/tree.def b/gcc/tree.def index c016fcf..8ba266a 100644 --- a/gcc/tree.def +++ b/gcc/tree.def @@ -208,7 +208,9 @@ DEFTREECODE (SET_TYPE, "set_type", "t", 0) /* Struct in C, or record in Pascal. */ /* Special fields: - TYPE_FIELDS chain of FIELD_DECLs for the fields of the struct. + TYPE_FIELDS chain of FIELD_DECLs for the fields of the struct, + and VAR_DECLs, TYPE_DECLs and CONST_DECLs for record-scope variables, + types and enumerators. A few may need to be added for Pascal. */ /* See the comment above, before ENUMERAL_TYPE, for how forward references to struct tags are handled in C. */ @@ -271,9 +273,9 @@ DEFTREECODE (STRING_CST, "string_cst", "c", 3) this declaration has its scope. For FIELD_DECLs, this is the RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node that the field is a member of. For VAR_DECL, PARM_DECL, FUNCTION_DECL, LABEL_DECL, - and CONST_DECL nodes, this points to the FUNCTION_DECL for the - containing function, or else yields NULL_TREE if the given decl - has "file scope". + and CONST_DECL nodes, this points to either the FUNCTION_DECL for the + containing function, the RECORD_TYPE or UNION_TYPE for the containing + type, or NULL_TREE if the given decl has "file scope". DECL_ABSTRACT_ORIGIN, if non-NULL, points to the original (abstract) ..._DECL node of which this decl is an (inlined or template expanded) instance. diff --git a/gcc/tree.h b/gcc/tree.h index 2d37be9..a89ae50 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -880,8 +880,9 @@ struct tree_type /* For FIELD_DECLs, this is the RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node that the field is a member of. For VAR_DECL, PARM_DECL, FUNCTION_DECL, LABEL_DECL, - and CONST_DECL nodes, this points to the FUNCTION_DECL for the - containing function, or else yields NULL_TREE if the given decl has "file scope". */ + and CONST_DECL nodes, this points to either the FUNCTION_DECL for the + containing function, the RECORD_TYPE or UNION_TYPE for the containing + type, or NULL_TREE if the given decl has "file scope". */ #define DECL_CONTEXT(NODE) ((NODE)->decl.context) #define DECL_FIELD_CONTEXT(NODE) ((NODE)->decl.context) /* In a DECL this is the field where configuration dependent machine diff --git a/gcc/varasm.c b/gcc/varasm.c index 7779828..e7a5663 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -1175,15 +1175,20 @@ assemble_variable (decl, top_level, at_end, dont_output_data) && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0)) sdbout_symbol (decl, 0); #endif +#ifdef DWARF_DEBUGGING_INFO + if (write_symbols == DWARF_DEBUG && top_level + && DECL_CONTEXT (decl)) + dwarfout_file_scope_decl (decl, 0); +#endif } - /* Don't output any DWARF debugging information for variables here. - In the case of local variables, the information for them is output - when we do our recursive traversal of the tree representation for - the entire containing function. In the case of file-scope variables, - we output information for all of them at the very end of compilation - while we are doing our final traversal of the chain of file-scope - declarations. */ + /* Only output DWARF debugging information for record-scope variables + here. In the case of function-scope variables, the information + for them is output when we do our recursive traversal of the tree + representation for the entire containing function. In the case of + file-scope variables, we output information for all of them at the + very end of compilation while we are doing our final traversal of + the chain of file-scope declarations. */ return; } @@ -1298,14 +1303,19 @@ assemble_variable (decl, top_level, at_end, dont_output_data) && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0)) sdbout_symbol (decl, 0); #endif +#ifdef DWARF_DEBUGGING_INFO + if (write_symbols == DWARF_DEBUG && top_level + && DECL_CONTEXT (decl)) + dwarfout_file_scope_decl (decl, 0); +#endif - /* Don't output any DWARF debugging information for variables here. - In the case of local variables, the information for them is output - when we do our recursive traversal of the tree representation for - the entire containing function. In the case of file-scope variables, - we output information for all of them at the very end of compilation - while we are doing our final traversal of the chain of file-scope - declarations. */ + /* Only output DWARF debugging information for record-scope variables + here. In the case of function-scope variables, the information + for them is output when we do our recursive traversal of the tree + representation for the entire containing function. In the case of + file-scope variables, we output information for all of them at the + very end of compilation while we are doing our final traversal of + the chain of file-scope declarations. */ #if 0 /* ??? We should either delete this or add a comment describing what it was intended to do and why we shouldn't delete it. */ -- 2.7.4