From e5b1675528722f816f06359daf618ab9e35f915a Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Mon, 4 Oct 2010 09:19:55 +0000 Subject: [PATCH] f95-lang.c (current_translation_unit): New global variable. 2010-10-04 Richard Guenther * f95-lang.c (current_translation_unit): New global variable. (gfc_create_decls): Build a translation-unit decl. (pushdecl): In the global binding-level use the translation-unit decl as DECL_CONTEXT. * trans-decl.c (gfc_get_symbol_decl): Use DECL_FILE_SCOPE_P. (build_function_decl): Likewise. Delay setting the assembler name, leave setting of DECL_CONTEXT to pushdecl. (trans_function_start): Use DECL_FILE_SCOPE_P. (gfc_create_module_variable): Likewise. Remove questionable asserts. * trans.c (gfc_generate_module_code): Likewise. From-SVN: r164928 --- gcc/fortran/ChangeLog | 14 ++++++++++++++ gcc/fortran/f95-lang.c | 12 ++++++++++-- gcc/fortran/trans-decl.c | 24 +++++++++++------------- gcc/fortran/trans.c | 2 -- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index fe38d30..f8606c8 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,17 @@ +2010-10-04 Richard Guenther + + * f95-lang.c (current_translation_unit): New global variable. + (gfc_create_decls): Build a translation-unit decl. + (pushdecl): In the global binding-level use the + translation-unit decl as DECL_CONTEXT. + * trans-decl.c (gfc_get_symbol_decl): Use DECL_FILE_SCOPE_P. + (build_function_decl): Likewise. Delay setting the assembler + name, leave setting of DECL_CONTEXT to pushdecl. + (trans_function_start): Use DECL_FILE_SCOPE_P. + (gfc_create_module_variable): Likewise. Remove questionable + asserts. + * trans.c (gfc_generate_module_code): Likewise. + 2010-10-03 Francois-Xavier Coudert * cpp.c (cpp_define_builtins): Call functions from cppbuiltin.c diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c index f222139..55280bd 100644 --- a/gcc/fortran/f95-lang.c +++ b/gcc/fortran/f95-lang.c @@ -172,6 +172,9 @@ tree *ridpointers = NULL; /* True means we've initialized exception handling. */ bool gfc_eh_initialized_p; +/* The current translation unit. */ +static GTY(()) tree current_translation_unit; + /* Prepare expr to be an argument of a TRUTH_NOT_EXPR, or validate its data type for an `if' or `while' statement or ?..: exp. @@ -229,6 +232,9 @@ gfc_create_decls (void) gfc_build_builtin_function_decls (); gfc_init_constants (); + + /* Build our translation-unit decl. */ + current_translation_unit = build_translation_unit_decl (NULL_TREE); } @@ -491,8 +497,10 @@ tree pushdecl (tree decl) { /* External objects aren't nested, other objects may be. */ - if ((DECL_EXTERNAL (decl)) || (decl == current_function_decl)) - DECL_CONTEXT (decl) = 0; + if (DECL_EXTERNAL (decl)) + DECL_CONTEXT (decl) = NULL_TREE; + else if (global_bindings_p ()) + DECL_CONTEXT (decl) = current_translation_unit; else DECL_CONTEXT (decl) = current_function_decl; diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 457e8f6..ddcc735 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1090,7 +1090,7 @@ gfc_get_symbol_decl (gfc_symbol * sym) else length = sym->ts.u.cl->backend_decl; if (TREE_CODE (length) == VAR_DECL - && DECL_CONTEXT (length) == NULL_TREE) + && DECL_FILE_SCOPE_P (length)) { /* Add the string length to the same context as the symbol. */ if (DECL_CONTEXT (sym->backend_decl) == current_function_decl) @@ -1646,9 +1646,9 @@ build_function_decl (gfc_symbol * sym, bool global) /* Allow only one nesting level. Allow public declarations. */ gcc_assert (current_function_decl == NULL_TREE - || DECL_CONTEXT (current_function_decl) == NULL_TREE - || TREE_CODE (DECL_CONTEXT (current_function_decl)) - == NAMESPACE_DECL); + || DECL_FILE_SCOPE_P (current_function_decl) + || (TREE_CODE (DECL_CONTEXT (current_function_decl)) + == NAMESPACE_DECL)); type = gfc_get_function_type (sym); fndecl = build_decl (input_location, @@ -1659,10 +1659,6 @@ build_function_decl (gfc_symbol * sym, bool global) attributes = add_attributes_to_decl (attr, NULL_TREE); decl_attributes (&fndecl, attributes, 0); - /* Perform name mangling if this is a top level or module procedure. */ - if (current_function_decl == NULL_TREE) - gfc_set_decl_assembler_name (fndecl, gfc_sym_mangled_function_id (sym)); - /* Figure out the return type of the declared function, and build a RESULT_DECL for it. If this is a subroutine with alternate returns, build a RESULT_DECL for it. */ @@ -1710,12 +1706,11 @@ build_function_decl (gfc_symbol * sym, bool global) layout_decl (result_decl, 0); */ /* Set up all attributes for the function. */ - DECL_CONTEXT (fndecl) = current_function_decl; DECL_EXTERNAL (fndecl) = 0; /* This specifies if a function is globally visible, i.e. it is the opposite of declaring static in C. */ - if (DECL_CONTEXT (fndecl) == NULL_TREE + if (!current_function_decl && !sym->attr.entry_master && !sym->attr.is_main_program) TREE_PUBLIC (fndecl) = 1; @@ -1744,6 +1739,10 @@ build_function_decl (gfc_symbol * sym, bool global) else pushdecl (fndecl); + /* Perform name mangling if this is a top level or module procedure. */ + if (current_function_decl == NULL_TREE) + gfc_set_decl_assembler_name (fndecl, gfc_sym_mangled_function_id (sym)); + sym->backend_decl = fndecl; } @@ -1991,7 +1990,7 @@ trans_function_start (gfc_symbol * sym) /* Let the world know what we're about to do. */ announce_function (fndecl); - if (DECL_CONTEXT (fndecl) == NULL_TREE) + if (DECL_FILE_SCOPE_P (fndecl)) { /* Create RTL for function declaration. */ rest_of_decl_compilation (fndecl, 1, 0); @@ -3598,7 +3597,7 @@ gfc_create_module_variable (gfc_symbol * sym) if ((sym->attr.in_common || sym->attr.in_equivalence) && sym->backend_decl) { decl = sym->backend_decl; - gcc_assert (DECL_CONTEXT (decl) == NULL_TREE); + gcc_assert (DECL_FILE_SCOPE_P (decl)); gcc_assert (sym->ns->proc_name->attr.flavor == FL_MODULE); DECL_CONTEXT (decl) = sym->ns->proc_name->backend_decl; gfc_module_add_decl (cur_module, decl); @@ -3625,7 +3624,6 @@ gfc_create_module_variable (gfc_symbol * sym) /* Create the variable. */ pushdecl (decl); - gcc_assert (DECL_CONTEXT (decl) == NULL_TREE); gcc_assert (sym->ns->proc_name->attr.flavor == FL_MODULE); DECL_CONTEXT (decl) = sym->ns->proc_name->backend_decl; rest_of_decl_compilation (decl, 1, 0); diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c index a608fb1..117d345 100644 --- a/gcc/fortran/trans.c +++ b/gcc/fortran/trans.c @@ -1414,12 +1414,10 @@ gfc_generate_module_code (gfc_namespace * ns) continue; gfc_create_function_decl (n, false); - gcc_assert (DECL_CONTEXT (n->proc_name->backend_decl) == NULL_TREE); DECL_CONTEXT (n->proc_name->backend_decl) = ns->proc_name->backend_decl; gfc_module_add_decl (entry, n->proc_name->backend_decl); for (el = ns->entries; el; el = el->next) { - gcc_assert (DECL_CONTEXT (el->sym->backend_decl) == NULL_TREE); DECL_CONTEXT (el->sym->backend_decl) = ns->proc_name->backend_decl; gfc_module_add_decl (entry, el->sym->backend_decl); } -- 2.7.4