Bug 90112 - internal procedure using module procedure instead of "sibling" internal procedure
Summary: internal procedure using module procedure instead of "sibling" internal proce...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 8.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2019-04-16 10:57 UTC by Ignacio Fernández Galván
Modified: 2020-07-26 21:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-05-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ignacio Fernández Galván 2019-04-16 10:57:15 UTC
In some cases an internal procedure will use a module procedure instead of another internal procedure (in the same host unit) with the same name. In the example below, R(x) calls f(x), but it uses the module's f(x) instead of the one internal to g(x) (as probably intended).

module test_functions

contains

subroutine f(x)
  implicit none
  real, intent(inout) :: x
  x = 2 * x
end subroutine f

subroutine g(x)
  implicit none
  real, intent(inout) :: x
  call R(x)
  contains
    subroutine R(x)
      implicit none
      real, intent(inout) :: x
      call f(x)
    end subroutine R
    subroutine f(x)
      implicit none
      real, intent(inout) :: x
      x = 3 * x
    end subroutine f
  end subroutine g
end module

program scope
  use test_functions
  real :: x = 3.0, y = 3.0
  call f(x)
  call g(y)
  write(*, *) x, y
end program


Compiling and running with gfortran 5.4, 7.4, 8.1, gives:

   6.00000000       6.00000000

Compiling and running with ifort 18.0 gives:

   6.000000       9.000000    


This does not happen if f(x) is a function instead of a subroutine, or if the call to f(x) is made directly in g(x) rather than in R(x).
Comment 1 Dominique d'Humieres 2019-05-04 12:45:58 UTC
Confirmed from at least 4.8 up to trunk (10.0).
Comment 2 anlauf 2020-07-26 21:23:14 UTC
The issue depends on the order of the internal procedures R and f of g.
Placing f in front of R leads to correct results.