This program finishes successfully with 4.9 and crashes with 5.3.1 The generic resolution selects wrong procedure. The calling procedure happens to have the same binding-name as the name of the correct specific procedure and gets called recursively instead of the correct one. See also similar: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66695 (I have already 15 still open bugs in gfortran and this is the 16th!) Output: > gfortran-5 bug1.F90 > ./a.out Segmentation fault > gfortran-5 -fcheck=all bug1.F90 > ./a.out At line 22 of file bug1.F90 Fortran runtime error: Recursive call to nonrecursive procedure 'p_execute' module first private public execute interface execute module procedure random_name end interface contains subroutine random_name() end subroutine end module module test use first implicit none contains subroutine p_execute(i) bind(C, name="random_name") integer :: i call execute() end subroutine end module use test call p_execute(1) end
-fdump-tree-original random_name () { } p_execute (integer(kind=4) & restrict i) { p_execute (); } MAIN__ () { { static integer(kind=4) C.3388 = 1; p_execute (&C.3388); } } main (integer(kind=4) argc, character(kind=1) * * argv) { static integer(kind=4) options.0[9] = {68, 1023, 0, 0, 1, 1, 0, 0, 31}; _gfortran_set_args (argc, argv); _gfortran_set_options (9, &options.0[0]); MAIN__ (); return 0; }
Confirmed, 4.9.0+ fail for me, 4.8.5 works.
Indeed, 4.9 crashes as well, my first description is incorrect. It was running well in 4.8.5.
There is an even simpler reproducer and slightly different twist, but I suspect it's the same bug: test.c: void bar(); int main(int argc, char* argv[]) { bar(); return 0; } works as expected with any version with gcc and the following Fortran file: foo_c_standalone.f90: module foo_c use iso_c_binding contains subroutine bar() write(*,*) "bar" end subroutine c_bar() bind(C, name="bar") write(*,*) "c_bar" call bar() end end module while it terminates with a segfault due to the recursive call with gcc-5.3.1, gcc-7.3.0 (and probably also gcc-4.9+) but works with gcc-4.8.5 with the following code instead: foo_c.f90: module foo_c use iso_c_binding use foo contains subroutine c_bar() bind(C, name="bar") write(*,*) "c_bar" call bar() end end module foo.f90: module foo contains subroutine bar() write(*,*) "bar" end end
GCC 6 branch is being closed
Author: tkoenig Date: Wed Mar 13 07:21:33 2019 New Revision: 269635 URL: https://gcc.gnu.org/viewcvs?rev=269635&root=gcc&view=rev Log: 2019-03-13 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/66695 PR fortran/77746 PR fortran/79485 * gfortran.h (gfc_symbol): Add bind_c component. (gfc_get_gsymbol): Add argument bind_c. * decl.c (add_global_entry): Add bind_c argument to gfc_get_symbol. * parse.c (parse_block_data): Likewise. (parse_module): Likewise. (add_global_procedure): Likewise. (add_global_program): Likewise. * resolve.c (resolve_common_blocks): Likewise. (resolve_global_procedure): Likewise. (gfc_verify_binding_labels): Likewise. * symbol.c (gfc_get_gsymbol): Add argument bind_c. Set bind_c in gsym. * trans-decl.c (gfc_get_module_backend_decl): Add bind_c argument to gfc_get_symbol. (gfc_get_extern_function_decl): If the sym has a binding label and it cannot be found in the global symbol tabel, it is the wrong one and vice versa. 2019-03-13 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/66695 PR fortran/77746 PR fortran/79485 * gfortran.dg/binding_label_tests_30.f90: New test. * gfortran.dg/binding_label_tests_31.f90: New test. * gfortran.dg/binding_label_tests_32.f90: New test. * gfortran.dg/binding_label_tests_33.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/binding_label_tests_30.f90 trunk/gcc/testsuite/gfortran.dg/binding_label_tests_31.f90 trunk/gcc/testsuite/gfortran.dg/binding_label_tests_32.f90 trunk/gcc/testsuite/gfortran.dg/binding_label_tests_33.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/decl.c trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/parse.c trunk/gcc/fortran/resolve.c trunk/gcc/fortran/symbol.c trunk/gcc/fortran/trans-decl.c trunk/gcc/testsuite/ChangeLog
Author: tkoenig Date: Sat Mar 16 13:16:11 2019 New Revision: 269722 URL: https://gcc.gnu.org/viewcvs?rev=269722&root=gcc&view=rev Log: 2019-03-16 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/66695 PR fortran/77746 PR fortran/79485 Backport from trunk * gfortran.h (gfc_symbol): Add bind_c component. (gfc_get_gsymbol): Add argument bind_c. * decl.c (add_global_entry): Add bind_c argument to gfc_get_symbol. * parse.c (parse_block_data): Likewise. (parse_module): Likewise. (add_global_procedure): Likewise. (add_global_program): Likewise. * resolve.c (resolve_common_blocks): Likewise. (resolve_global_procedure): Likewise. (gfc_verify_binding_labels): Likewise. * symbol.c (gfc_get_gsymbol): Add argument bind_c. Set bind_c in gsym. * trans-decl.c (gfc_get_module_backend_decl): Add bind_c argument to gfc_get_symbol. (gfc_get_extern_function_decl): If the sym has a binding label and it cannot be found in the global symbol tabel, it is the wrong one and vice versa. 2019-03-16 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/66695 PR fortran/77746 PR fortran/79485 Backport from trunk * gfortran.dg/binding_label_tests_30.f90: New test. * gfortran.dg/binding_label_tests_31.f90: New test. * gfortran.dg/binding_label_tests_32.f90: New test. * gfortran.dg/binding_label_tests_33.f90: New test. Added: branches/gcc-8-branch/gcc/testsuite/gfortran.dg/binding_label_tests_30.f90 branches/gcc-8-branch/gcc/testsuite/gfortran.dg/binding_label_tests_31.f90 branches/gcc-8-branch/gcc/testsuite/gfortran.dg/binding_label_tests_32.f90 branches/gcc-8-branch/gcc/testsuite/gfortran.dg/binding_label_tests_33.f90 Modified: branches/gcc-8-branch/gcc/fortran/ChangeLog branches/gcc-8-branch/gcc/fortran/decl.c branches/gcc-8-branch/gcc/fortran/gfortran.h branches/gcc-8-branch/gcc/fortran/parse.c branches/gcc-8-branch/gcc/fortran/resolve.c branches/gcc-8-branch/gcc/fortran/symbol.c branches/gcc-8-branch/gcc/fortran/trans-decl.c branches/gcc-8-branch/gcc/testsuite/ChangeLog
Author: tkoenig Date: Sat Mar 16 13:24:40 2019 New Revision: 269723 URL: https://gcc.gnu.org/viewcvs?rev=269723&root=gcc&view=rev Log: 2019-03-16 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/66695 PR fortran/77746 PR fortran/79485 Backport from trunk * gfortran.h (gfc_symbol): Add bind_c component. (gfc_get_gsymbol): Add argument bind_c. * decl.c (add_global_entry): Add bind_c argument to gfc_get_symbol. * parse.c (parse_block_data): Likewise. (parse_module): Likewise. (add_global_procedure): Likewise. (add_global_program): Likewise. * resolve.c (resolve_common_blocks): Likewise. (resolve_global_procedure): Likewise. (gfc_verify_binding_labels): Likewise. * symbol.c (gfc_get_gsymbol): Add argument bind_c. Set bind_c in gsym. * trans-decl.c (gfc_get_module_backend_decl): Add bind_c argument to gfc_get_symbol. (gfc_get_extern_function_decl): If the sym has a binding label and it cannot be found in the global symbol tabel, it is the wrong one and vice versa. 2019-03-16 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/66695 PR fortran/77746 PR fortran/79485 Backport from trunk * gfortran.dg/binding_label_tests_30.f90: New test. * gfortran.dg/binding_label_tests_31.f90: New test. * gfortran.dg/binding_label_tests_32.f90: New test. * gfortran.dg/binding_label_tests_33.f90: New test. Added: branches/gcc-7-branch/gcc/testsuite/gfortran.dg/binding_label_tests_30.f90 branches/gcc-7-branch/gcc/testsuite/gfortran.dg/binding_label_tests_31.f90 branches/gcc-7-branch/gcc/testsuite/gfortran.dg/binding_label_tests_32.f90 branches/gcc-7-branch/gcc/testsuite/gfortran.dg/binding_label_tests_33.f90 Modified: branches/gcc-7-branch/gcc/fortran/ChangeLog branches/gcc-7-branch/gcc/fortran/decl.c branches/gcc-7-branch/gcc/fortran/gfortran.h branches/gcc-7-branch/gcc/fortran/parse.c branches/gcc-7-branch/gcc/fortran/resolve.c branches/gcc-7-branch/gcc/fortran/symbol.c branches/gcc-7-branch/gcc/fortran/trans-decl.c branches/gcc-7-branch/gcc/testsuite/ChangeLog
Fixed on all open branches, closing. ... and for this one, too.