Bug 79485 - [7/8 Regression] Bind(c) and module procedure renaming causes wrong procedure to be called
Summary: [7/8 Regression] Bind(c) and module procedure renaming causes wrong procedure...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 6.3.0
: P4 normal
Target Milestone: 7.5
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2017-02-13 10:22 UTC by Vladimir Fuka
Modified: 2019-03-16 13:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.5
Known to fail: 4.9.0, 4.9.4, 5.3.1, 6.2.0, 7.0
Last reconfirmed: 2017-02-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Fuka 2017-02-13 10:22:39 UTC
Reported at http://stackoverflow.com/questions/42189625/renaming-a-subroutine-in-a-fortran-module-when-using-iso-c-binding

Related to bug77746 and bug66695.


The following code finishes as expected in gfortran 4.8 and crashes due to stack overflow in 6.3 (and likely alredy in 4.9) because procedure `foo` in `fmod2` calls itself ad infinitum.

module fmod1

  contains

  subroutine foo(i)
    implicit none

    integer, intent(inout) :: i

    i=i+1

  end subroutine foo

end module fmod1

module fmod2
  use iso_c_binding
  use fmod1, only : foo_first => foo

  contains

  subroutine foo(i) bind(c)
    implicit none

    integer, intent(inout) :: i

    i=i+2
    call foo_first(i)

  end subroutine foo

end module fmod2

  use fmod2
  
  call foo(i)
end
Comment 1 Dominique d'Humieres 2017-02-22 17:20:05 UTC
> Related to bug77746 and bug66695.

At least it starts to fail in the same revision range. Likely related to the fixes of pr48858.
Comment 2 Jakub Jelinek 2018-10-26 10:18:24 UTC
GCC 6 branch is being closed
Comment 3 Thomas Koenig 2019-03-13 07:22:05 UTC
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
Comment 4 Thomas Koenig 2019-03-16 13:16:43 UTC
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
Comment 5 Thomas Koenig 2019-03-16 13:25:34 UTC
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
Comment 6 Thomas Koenig 2019-03-16 13:26:57 UTC
Fixed on all open branches, closing.

Also thanks for the bug report!