diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 0810b02b54e0..4322dd44badb 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,15 @@ +2007-11-03 Francois-Xavier Coudert + + * gfortran.h: Shorten comment. + * trans-types.c (gfc_get_function_type): Allow argument to have + flavor FL_PROGRAM. + * trans-decl.c (gfc_sym_mangled_function_id): Mangle main program + name into MAIN__. + (build_function_decl): Fix comment. + * parse.c (main_program_symbol): Give the main program its proper + name, if any. Set its flavor to FL_PROGRAM. + (gfc_parse_file): Likewise. + 2007-11-02 Francois-Xavier Coudert * intrinsic.texi (ALLOCATED): Fix typo. diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index bc8fad67ee8e..39fd3a10f205 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -665,9 +665,7 @@ typedef struct /* Set if the symbol has ambiguous interfaces. */ unsigned ambiguous_interfaces:1; - /* Set if the is the symbol for the main program. This is the least - cumbersome way to communicate this function property without - strcmp'ing with __MAIN everywhere. */ + /* Set if this is the symbol for the main program. */ unsigned is_main_program:1; /* Mutually exclusive multibit attributes. */ diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c index f60ea9a0057e..3e20b78fba26 100644 --- a/gcc/fortran/parse.c +++ b/gcc/fortran/parse.c @@ -1237,14 +1237,14 @@ gfc_ascii_statement (gfc_statement st) /* Create a symbol for the main program and assign it to ns->proc_name. */ static void -main_program_symbol (gfc_namespace *ns) +main_program_symbol (gfc_namespace *ns, const char *name) { gfc_symbol *main_program; symbol_attribute attr; - gfc_get_symbol ("MAIN__", ns, &main_program); + gfc_get_symbol (name, ns, &main_program); gfc_clear_attr (&attr); - attr.flavor = FL_PROCEDURE; + attr.flavor = FL_PROGRAM; attr.proc = PROC_UNKNOWN; attr.subroutine = 1; attr.access = ACCESS_PUBLIC; @@ -3331,7 +3331,7 @@ loop: prog_locus = gfc_current_locus; push_state (&s, COMP_PROGRAM, gfc_new_block); - main_program_symbol(gfc_current_ns); + main_program_symbol(gfc_current_ns, gfc_new_block->name); accept_statement (st); add_global_program (); parse_progunit (ST_NONE); @@ -3373,7 +3373,7 @@ loop: prog_locus = gfc_current_locus; push_state (&s, COMP_PROGRAM, gfc_new_block); - main_program_symbol (gfc_current_ns); + main_program_symbol (gfc_current_ns, "MAIN__"); parse_progunit (st); break; } diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 3542b1e9c554..198fec791991 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -7581,6 +7581,9 @@ resolve_symbol (gfc_symbol *sym) if (sym->attr.procedure && sym->interface && sym->attr.if_source != IFSRC_DECL) { + while (sym->interface->interface) + sym->interface = sym->interface->interface; + /* Get the attributes from the interface (now resolved). */ if (sym->interface->attr.if_source || sym->interface->attr.intrinsic) { diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 5b6b88bde631..4b114df728b4 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -324,8 +324,12 @@ gfc_sym_mangled_function_id (gfc_symbol * sym) || (sym->module != NULL && (sym->attr.external || sym->attr.if_source == IFSRC_IFBODY))) { - if (strcmp (sym->name, "MAIN__") == 0 - || sym->attr.proc == PROC_INTRINSIC) + /* Main program is mangled into MAIN__. */ + if (sym->attr.is_main_program) + return get_identifier ("MAIN__"); + + /* Intrinsic procedures are never mangled. */ + if (sym->attr.proc == PROC_INTRINSIC) return get_identifier (sym->name); if (gfc_option.flag_underscoring) @@ -1321,7 +1325,7 @@ build_function_decl (gfc_symbol * sym) TREE_SIDE_EFFECTS (fndecl) = 0; } - /* For -fwhole-program to work well, MAIN__ needs to have the + /* For -fwhole-program to work well, the main program needs to have the "externally_visible" attribute. */ if (attr.is_main_program) DECL_ATTRIBUTES (fndecl) diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index e8368612b272..88066a38f38f 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -1924,8 +1924,10 @@ gfc_get_function_type (gfc_symbol * sym) int nstr; int alternate_return; - /* Make sure this symbol is a function or a subroutine. */ - gcc_assert (sym->attr.flavor == FL_PROCEDURE); + /* Make sure this symbol is a function, a subroutine or the main + program. */ + gcc_assert (sym->attr.flavor == FL_PROCEDURE + || sym->attr.flavor == FL_PROGRAM); if (sym->backend_decl) return TREE_TYPE (sym->backend_decl);