Issue 177502
Summary [Flang] Compilation error occurs when calling recursive procedure pointers with ENTRY statement
Labels flang
Assignees
Reporter nakazawa-fj
    ```
Version of flang : 22.0.0git(2f7e218017db69454ea84e1849fcb9a11b1f7fef)/AArch64
```
The ENTRY statement is classified as an obsolescent feature in Fortran 2008/2018/2023, but it is still part of the standard.
Although Flang supports the ENTRY statement, it appears to fail when handling recursive procedure pointer calls involving
an additional procedure defined by an ENTRY statement.
This failure occurs specifically when the recursive function itself contains a procedure pointer whose target is the additional
procedure defined by an ENTRY statement.
Replacing the function with a subroutine avoids the problem.

Reference:
Fortran 2023 Standard
B.3 Obsolescent features
B.3.9 ENTRY statements


sample.f90
```fortran
module m
 integer::k
contains
  recursive function f() result(r)
    real::r
 entry e() result(r)
    procedure(e),pointer::ptr=>e
    k=k+1
 r=20.0
    if (k==1) then
       if(ptr()/=20)print*,"err 101"
    end if
  end function f
end module m

program main
  use m
  k=0
 if(e().ne.20.0)print*,"error 102"
  print*,"PASS"
end program main
```

flang
```
$ flang sample.f90
error: Semantic errors in sample.f90
./sample.f90:11:11: error: Cannot call subroutine 'ptr' like a function
         if(ptr()/=20)print*,"err 101"
 ^^^
./sample.f90:7:27: Declaration of 'ptr'
 procedure(e),pointer::ptr=>e
 ^^^
./sample.f90:11:11: Referenced as a procedure
 if(ptr()/=20)print*,"err 101"
            ^^^
```
gfortran
```
$ gfortran sample.f90; ./a.out
 PASS
```
ifx
```
$ ifx sample.f90
sample.f90(11): error #6553: A function reference is invoking a subroutine subprogram.   [PTR]
       if(ptr()/=20)print*,"err 101"
----------^
sample.f90(11): error #7021: Name is invalid in this context.   [PTR]
       if(ptr()/=20)print*,"err 101"
----------^
sample.f90(7): error #8178: The procedure pointer and the procedure target must have matching arguments.
 procedure(e),pointer::ptr=>e
--------------------------^
sample.f90(17): error #7013: This module file was not generated by any release of this compiler.   [M]
  use m
------^
compilation aborted for sample.f90 (code 1)


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to