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

[Flang] Incorrect diagnose on procedure pointer assignment target being the containing function

Open DanielCChen opened this issue 2 years ago • 4 comments

Consider the following code:

  PROCEDURE(ModFun), POINTER :: ProcPtr
  CONTAINS

  RECURSIVE FUNCTION ModFun() RESULT(res)
    REAL      :: ModFun
    ProcPtr => ModFun
    ModFun = 1.0
  END FUNCTION

  END

Flang currently issues an error:

./t.f:5:18: error: 'modfun' is already declared in this scoping unit
      REAL      :: ModFun
                   ^^^^^^
./t.f:4:22: Previous declaration of 'modfun'
    RECURSIVE FUNCTION ModFun() RESULT(res)

I can't find anything in the standard that disallow this code.

DanielCChen avatar Feb 21 '24 19:02 DanielCChen

@llvm/issue-subscribers-flang-frontend

Author: Daniel Chen (DanielCChen)

Consider the following code: ``` PROCEDURE(ModFun), POINTER :: ProcPtr CONTAINS

RECURSIVE FUNCTION ModFun() REAL :: ModFun ProcPtr => ModFun ModFun = 1.0 END FUNCTION

END


Flang currently issues an error:

./t.f:6:5: error: In assignment to procedure pointer 'procptr', the target is not a procedure or procedure pointer ProcPtr => ModFun ^^^^^^^^^^^^^^^^^ ./t.f:5:18: Declaration of 'modfun' REAL :: ModFun ^^^^^^


I can't find anything in the standard that disallow this code.
</details>

llvmbot avatar Feb 21 '24 19:02 llvmbot

@llvm/issue-subscribers-bug

Author: Daniel Chen (DanielCChen)

Consider the following code: ``` PROCEDURE(ModFun), POINTER :: ProcPtr CONTAINS

RECURSIVE FUNCTION ModFun() REAL :: ModFun ProcPtr => ModFun ModFun = 1.0 END FUNCTION

END


Flang currently issues an error:

./t.f:6:5: error: In assignment to procedure pointer 'procptr', the target is not a procedure or procedure pointer ProcPtr => ModFun ^^^^^^^^^^^^^^^^^ ./t.f:5:18: Declaration of 'modfun' REAL :: ModFun ^^^^^^


I can't find anything in the standard that disallow this code.
</details>

llvmbot avatar Feb 21 '24 19:02 llvmbot

The error is valid. The name of ModFun is present in its scope to permit recursive calls.

klausler avatar Feb 23 '24 23:02 klausler

You are right. The intended code is supposed to be

  PROCEDURE(ModFun), POINTER :: ProcPtr
  CONTAINS

  RECURSIVE FUNCTION ModFun() RESULT(res)
    REAL      :: res
    ProcPtr => ModFun
    res = 1.0
  END FUNCTION

  END

DanielCChen avatar Feb 24 '24 15:02 DanielCChen