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

[Flang] Typed procedure pointer with implicit interface cannot pointer assign to a function reference that returns a procedure pointer with the explicit interface that has the same TKR.

Open DanielCChen opened this issue 2 years ago • 4 comments

Consider the following code:

interface
  integer function bar()
  end
  function foo()
   import
   procedure(bar), pointer :: foo
  end
end interface
procedure(integer), pointer :: p1
p1 => foo()
end

Flang currently issues an error as:

error: Semantic errors in t.f
./t.f:10:1: error: Procedure pointer 'p1' associated with result of reference to function 'foo' that is an incompatible procedure pointer: incompatible procedure attributes: ImplicitInterface
  p1 => foo()
  ^^^^^^^^^^^
./t.f:9:32: Declaration of 'p1'
  procedure(integer), pointer :: p1
                                 ^^

According to the standard (F2018) [10.2.2.4 Procedure pointer assignment]

" 5. If the pointer object has an implicit interface and is explicitly typed or referenced as a function, the pointer target shall be a function. ....

6 If the pointer object is a function with an implicit interface, the pointer target shall be a function with the same type; corresponding type parameters shall have the same value. "

It seems the above code is conforming.

DanielCChen avatar Feb 15 '24 17:02 DanielCChen

@llvm/issue-subscribers-flang-frontend

Author: Daniel Chen (DanielCChen)

Consider the following code: ``` interface integer function bar() end function foo() import procedure(bar), pointer :: foo end end interface procedure(integer), pointer :: p1 p1 => foo() end ```

Flang currently issues an error as:

error: Semantic errors in t.f
./t.f:10:1: error: Procedure pointer 'p1' associated with result of reference to function 'foo' that is an incompatible procedure pointer: incompatible procedure attributes: ImplicitInterface
  p1 => foo()
  ^^^^^^^^^^^
./t.f:9:32: Declaration of 'p1'
  procedure(integer), pointer :: p1
                                 ^^

According to the standard (F2018) [10.2.2.4 Procedure pointer assignment]

" 5. If the pointer object has an implicit interface and is explicitly typed or referenced as a function, the pointer target shall be a function. ....

6 If the pointer object is a function with an implicit interface, the pointer target shall be a function with the same type; corresponding type parameters shall have the same value. "

It seems the above code is conforming.

llvmbot avatar Feb 15 '24 17:02 llvmbot

@llvm/issue-subscribers-bug

Author: Daniel Chen (DanielCChen)

Consider the following code: ``` interface integer function bar() end function foo() import procedure(bar), pointer :: foo end end interface procedure(integer), pointer :: p1 p1 => foo() end ```

Flang currently issues an error as:

error: Semantic errors in t.f
./t.f:10:1: error: Procedure pointer 'p1' associated with result of reference to function 'foo' that is an incompatible procedure pointer: incompatible procedure attributes: ImplicitInterface
  p1 => foo()
  ^^^^^^^^^^^
./t.f:9:32: Declaration of 'p1'
  procedure(integer), pointer :: p1
                                 ^^

According to the standard (F2018) [10.2.2.4 Procedure pointer assignment]

" 5. If the pointer object has an implicit interface and is explicitly typed or referenced as a function, the pointer target shall be a function. ....

6 If the pointer object is a function with an implicit interface, the pointer target shall be a function with the same type; corresponding type parameters shall have the same value. "

It seems the above code is conforming.

llvmbot avatar Feb 15 '24 19:02 llvmbot

https://github.com/llvm/llvm-project/pull/82796

klausler avatar Feb 23 '24 17:02 klausler

I have verified PR #82796 has fixed the reproducer in the issue as well as the origin test case. Thanks for the quick fix! @klausler I will leave it and let the merging of the PR to close this issue.

DanielCChen avatar Feb 27 '24 15:02 DanielCChen