llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[flang] procedure interface from declaration statement can be used before it is declared

Open ivan-pi opened this issue 2 months ago • 2 comments

Consider the contrived program below:

module m
implicit none
abstract interface
  subroutine s_iface()
  end subroutine
end interface
procedure(q), pointer :: r      ! <-- illegal: q declared afterward
procedure(s_iface), pointer :: q
end module
use m
end

flang runs this without any warnings, although it appears to be a disallowed (J3/24-007, 15.4.3.6 p1):

C1515 (R1516) The name shall be the name of an abstract interface or of a procedure that has an explicit interface. If name is declared by a procedure-declaration-stmt it shall be previously declared. (emphasis added) If name denotes an intrinsic procedure it shall be one that is listed in Table 16.2.

gfortran rejects this case: Error: Interface 'q' at (1) is declared in a later PROCEDURE statement. When the statements declaring r and q are swapped, the program is accepted.

nvfortran also rejects it: NVFORTRAN-S-0155-Illegal procedure interface - q (/app/example.f90: 10).

Found using Claude when looking at the conformity of named constraint checks.

ivan-pi avatar Oct 05 '26 21:10 ivan-pi

Opened #232928 with a fix for this.

Glitch-On avatar Oct 16 '26 20:10 Glitch-On

@llvm/issue-subscribers-flang-frontend

Author: Ivan Pribec (ivan-pi)

Consider the contrived program below:
module m
implicit none
abstract interface
  subroutine s_iface()
  end subroutine
end interface
procedure(q), pointer :: r      ! &lt;-- illegal: q declared afterward
procedure(s_iface), pointer :: q
end module
use m
end

flang runs this without any warnings, although it appears to be a disallowed (J3/24-007, 15.4.3.6 p1):

> C1515 (R1516) The name shall be the name of an abstract interface or of a procedure that has an explicit interface. If name is declared by a procedure-declaration-stmt it shall be previously declared. (emphasis added) If name denotes an intrinsic procedure it shall be one that is listed in Table 16.2.

gfortran rejects this case: Error: Interface 'q' at (1) is declared in a later PROCEDURE statement. When the statements declaring r and q are swapped, the program is accepted.

nvfortran also rejects it: NVFORTRAN-S-0155-Illegal procedure interface - q (/app/example.f90: 10).

Found using Claude when looking at the conformity of named constraint checks.