[Flang] Incorrect diagnose when pointer assign to intrinsic INDEX.
Consider the following code:
MODULE M
INTERFACE
FUNCTION ExtINDEX(Arg1, Arg2, Arg3, Arg4)
INTEGER :: ExtINDEX
CHARACTER(*), INTENT(IN) :: Arg1, Arg2
LOGICAL, OPTIONAL, INTENT(IN) :: Arg3
INTEGER, OPTIONAL, INTENT(IN) :: Arg4
END FUNCTION
END INTERFACE
END MODULE
PROGRAM PtrAssignProcNameIntrin4
USE M
IMPLICIT NONE
PROCEDURE(ExtINDEX), POINTER :: PtrINDEX
PtrINDEX => index
END
Flang currently issues an error:
./t.f:19:3: error: Procedure pointer 'ptrindex' associated with incompatible procedure designator 'index': distinct numbers of dummy arguments
PtrINDEX => index
^^^^^^^^^^^^^^^^^
./t.f:18:36: Declaration of 'ptrindex'
PROCEDURE(ExtINDEX), POINTER :: PtrINDEX
^^^^^^^^
The code seems conforming to me.
@llvm/issue-subscribers-flang-frontend
Author: Daniel Chen (DanielCChen)
INTERFACE FUNCTION ExtINDEX(Arg1, Arg2, Arg3, Arg4) INTEGER :: ExtINDEX CHARACTER(*), INTENT(IN) :: Arg1, Arg2 LOGICAL, OPTIONAL, INTENT(IN) :: Arg3 INTEGER, OPTIONAL, INTENT(IN) :: Arg4 END FUNCTION END INTERFACE
END MODULE
PROGRAM PtrAssignProcNameIntrin4 USE M IMPLICIT NONE
PROCEDURE(ExtINDEX), POINTER :: PtrINDEX PtrINDEX => index
END
Flang currently issues an error:
./t.f:19:3: error: Procedure pointer 'ptrindex' associated with incompatible procedure designator 'index': distinct numbers of dummy arguments PtrINDEX => index ^^^^^^^^^^^^^^^^^ ./t.f:18:36: Declaration of 'ptrindex' PROCEDURE(ExtINDEX), POINTER :: PtrINDEX ^^^^^^^^
The code seems conforming to me.
</details>
@llvm/issue-subscribers-bug
Author: Daniel Chen (DanielCChen)
INTERFACE FUNCTION ExtINDEX(Arg1, Arg2, Arg3, Arg4) INTEGER :: ExtINDEX CHARACTER(*), INTENT(IN) :: Arg1, Arg2 LOGICAL, OPTIONAL, INTENT(IN) :: Arg3 INTEGER, OPTIONAL, INTENT(IN) :: Arg4 END FUNCTION END INTERFACE
END MODULE
PROGRAM PtrAssignProcNameIntrin4 USE M IMPLICIT NONE
PROCEDURE(ExtINDEX), POINTER :: PtrINDEX PtrINDEX => index
END
Flang currently issues an error:
./t.f:19:3: error: Procedure pointer 'ptrindex' associated with incompatible procedure designator 'index': distinct numbers of dummy arguments PtrINDEX => index ^^^^^^^^^^^^^^^^^ ./t.f:18:36: Declaration of 'ptrindex' PROCEDURE(ExtINDEX), POINTER :: PtrINDEX ^^^^^^^^
The code seems conforming to me.
</details>
That's basically the same error message that comes out for this test from both NAG and XLF. Using INDEX as a specific intrinsic procedure is somewhat fraught because the fourth optional argument (KIND=) can't determine the kind of the integer result type.
I messed up the code. I updated it with only 3 arguments. XLF compiles the updated code successfully.
I messed up the code. I updated it with only 3 arguments. XLF compiles the updated code successfully.
If there is still a bug to be fixed in f18, please post the updated test case; otherwise, please close this bug report.
MODULE M
INTERFACE
FUNCTION ExtINDEX(Arg1, Arg2, Arg3)!, Arg4)
INTEGER :: ExtINDEX
CHARACTER(*), INTENT(IN) :: Arg1, Arg2
LOGICAL, OPTIONAL, INTENT(IN) :: Arg3
! INTEGER, OPTIONAL, INTENT(IN) :: Arg4
END FUNCTION
END INTERFACE
END MODULE
PROGRAM PtrAssignProcNameIntrin4
USE M
IMPLICIT NONE
PROCEDURE(ExtINDEX), POINTER :: PtrINDEX
PtrINDEX => index
END
Both XLF and ifort accept this updated test case, but gfortran and Flang reject it.
https://github.com/llvm/llvm-project/pull/83073
I have verified PR #83073 has fixed the reproducer and the original test case. Thanks for the quick fix! @klausler
Referencing the procptr segfaults as:
MODULE M
INTERFACE
FUNCTION ExtINDEX(Arg1, Arg2, Arg3)
INTEGER :: ExtINDEX
CHARACTER(*), INTENT(IN) :: Arg1, Arg2
LOGICAL, OPTIONAL, INTENT(IN) :: Arg3
END FUNCTION
END INTERFACE
END MODULE
PROGRAM PtrAssignProcNameIntrin4
USE M
IMPLICIT NONE
integer :: res
PROCEDURE(ExtINDEX), POINTER :: PtrINDEX
PtrINDEX => index
res = PtrINDEX('FORTRAN', 'R')
END
Not sure yet if it is a FE bug or codegen.
Fortran '77 and Fortran '90 both document the unrestricted specific function INDEX with exactly two arguments. Later editions of the standards omit the argument information from the table of unrestricted specific intrinsic functions. Jean and I believe that the correct interpretation remains the one with two arguments, as we can't get a three-argument form with optional BACK= to work correctly with any other compiler, and that is what I have merged.