Follow-up to PR42072. Consider this simple program: contains subroutine setpointer (p) procedure(), pointer :: p end subroutine end Compiling this with -fdump-tree-original shows: setpointer (void (*<T62>) (void) * p) { (void) 0; } MAIN__ () { static void setpointer (void (*<T62>) (void)); (void) 0; } As one can see, the static declaration inside MAIN__ differs from the actual declaration of 'setpointer'.
Confirmed. This is where it comes from: Index: gcc/fortran/trans-decl.c =================================================================== *** gcc/fortran/trans-decl.c (revision 155192) --- gcc/fortran/trans-decl.c (working copy) *************** build_function_decl (gfc_symbol * sym) *** 1644,1653 **** if (DECL_CONTEXT (fndecl) == NULL_TREE && !sym->attr.entry_master && !sym->attr.is_main_program) TREE_PUBLIC (fndecl) = 1; ! /* TREE_STATIC means the function body is defined here. */ TREE_STATIC (fndecl) = 1; ! /* Set attributes for PURE functions. A call to a PURE function in the Fortran 95 sense is both pure and without side effects in the C sense. */ --- 1644,1653 ---- if (DECL_CONTEXT (fndecl) == NULL_TREE && !sym->attr.entry_master && !sym->attr.is_main_program) TREE_PUBLIC (fndecl) = 1; ! #if 0 /* TREE_STATIC means the function body is defined here. */ TREE_STATIC (fndecl) = 1; ! #endif /* Set attributes for PURE functions. A call to a PURE function in the Fortran 95 sense is both pure and without side effects in the C sense. */ Paul
Hm? The TREE_STATIC is ok, the bug is that the actual arguments are different and maybe that inside the __MAIN BLOCK vars there shouldn't be a function decl.
With gcc 4.8 up to trunk (8.0) the dump is setpointer (void (*<T4bb>) () * p) { } MAIN__ () { static void setpointer (void (*<T4bb>) ()); } Is this eight-year old PR fixed or not?
> Is this eight-year old PR fixed or not? Should I close this PR as FIXED to get an answer?
Not fixed.
Also crashes with -fdump-global-original: MAIN__ setpointer main==4365== Invalid read of size 8 ==4365== at 0x8F8B0D: gfc_traverse_gsymbol(gfc_gsymbol*, void (*)(gfc_gsymbol*, void*), void*) (symbol.c:4365) ==4365== by 0x8BDAB1: gfc_parse_file() (parse.c:6374) ==4365== by 0x906D4F: gfc_be_parse_file() (f95-lang.c:204) ==4365== by 0xE35CBF: compile_file() (toplev.c:456) ==4365== by 0x829190: do_compile (toplev.c:2190) ==4365== by 0x829190: toplev::main(int, char**) (toplev.c:2325) ==4365== by 0x82CCBE: main (main.c:39) ==4365== Address 0x8 is not stack'd, malloc'd or (recently) free'd ==4365== decl.f90:6:0: 6 | end subroutine | interner Compiler-Fehler: Speicherzugriffsfehler Bitte senden Sie einen vollständigen Fehlerbericht auf Englisch ein; inclusive vorverarbeitetem Quellcode, wenn es dienlich ist. Weitere Hinweise finden Sie unter »<https://gcc.gnu.org/bugs/>«. ==4365==
The master branch has been updated by Thomas Kथà¤nig <tkoenig@gcc.gnu.org>: https://gcc.gnu.org/g:3de12cc548c7a37bb68ea10937709dc6385a3b2b commit r11-1299-g3de12cc548c7a37bb68ea10937709dc6385a3b2b Author: Thomas Koenig <tkoenig@gcc.gnu.org> Date: Sun Jun 14 17:37:49 2020 +0200 Avoid crash when global symbol table is empty with -fdump-fortran-global. This just avoids a crash with -fdump-fortran-global when the global symbol table is empty. This is strictly a developer's option, no user impact. gcc/fortran/ChangeLog: 2020-06-14 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/42122 * dump-parse-tree.c (gfc_dump_global_symbols): If the symroot is empty, just output "empty".