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

[Flang] Incorrect diagnose on procedure pointer dummy with corresponding actual being a function that returns a procedure pointer

Open DanielCChen opened this issue 2 years ago • 3 comments

Consider the following code.

  PROGRAM main
    INTERFACE
      integer FUNCTION IntF(Arg)
        integer, INTENT(IN) :: Arg
      END FUNCTION
    END INTERFACE
  PROCEDURE(IntF) :: ExtFun

  CALL IntSub(IntFun1(ExtFun))

  CONTAINS

  FUNCTION IntFun1(Proc)
  PROCEDURE(IntF) :: Proc
  PROCEDURE(IntF), POINTER :: IntFun1
    IntFun1 => Proc
  END FUNCTION

  SUBROUTINE IntSub(ProcPtr0)
  PROCEDURE(IntF), POINTER :: ProcPtr0
  END SUBROUTINE

  END

Flang currently issues an error as:

 error: Actual argument associated with procedure pointer dummy argument 'procptr0=' must be a pointer unless INTENT(IN)
  CALL IntSub( IntFun1(ExtFun))
               ^^^^^^^^^^^^^^^

It seems the diagnose here is incorrect. The code is conforming and should be compiled successfully.

DanielCChen avatar Feb 16 '24 16:02 DanielCChen

@llvm/issue-subscribers-flang-frontend

Author: Daniel Chen (DanielCChen)

Consider the following code. ``` PROGRAM main INTERFACE integer FUNCTION IntF(Arg) integer, INTENT(IN) :: Arg END FUNCTION END INTERFACE PROCEDURE(IntF) :: ExtFun

CALL IntSub(IntFun1(ExtFun))

CONTAINS

FUNCTION IntFun1(Proc) PROCEDURE(IntF) :: Proc PROCEDURE(IntF), POINTER :: IntFun1 IntFun1 => Proc END FUNCTION

SUBROUTINE IntSub(ProcPtr0) PROCEDURE(IntF), POINTER :: ProcPtr0 END SUBROUTINE

END


Flang currently issues an error as:

error: Actual argument associated with procedure pointer dummy argument 'procptr0=' must be a pointer unless INTENT(IN) CALL IntSub( IntFun1(ExtFun)) ^^^^^^^^^^^^^^^


It seems the diagnose here is incorrect. The code is conforming and should be compiled successfully.
</details>

llvmbot avatar Feb 16 '24 16:02 llvmbot

@llvm/issue-subscribers-bug

Author: Daniel Chen (DanielCChen)

Consider the following code. ``` PROGRAM main INTERFACE integer FUNCTION IntF(Arg) integer, INTENT(IN) :: Arg END FUNCTION END INTERFACE PROCEDURE(IntF) :: ExtFun

CALL IntSub(IntFun1(ExtFun))

CONTAINS

FUNCTION IntFun1(Proc) PROCEDURE(IntF) :: Proc PROCEDURE(IntF), POINTER :: IntFun1 IntFun1 => Proc END FUNCTION

SUBROUTINE IntSub(ProcPtr0) PROCEDURE(IntF), POINTER :: ProcPtr0 END SUBROUTINE

END


Flang currently issues an error as:

error: Actual argument associated with procedure pointer dummy argument 'procptr0=' must be a pointer unless INTENT(IN) CALL IntSub( IntFun1(ExtFun)) ^^^^^^^^^^^^^^^


It seems the diagnose here is incorrect. The code is conforming and should be compiled successfully.
</details>

llvmbot avatar Feb 16 '24 16:02 llvmbot

Discussed with @klausler and I agreed that Flang's current behavior is correct.

DanielCChen avatar Feb 23 '24 21:02 DanielCChen