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

[Flang] Incorrect diagnose when declare a procedure with explicit typing in multiple statements

Open DanielCChen opened this issue 2 years ago • 8 comments

Consider the following code.

integer :: proc
procedure() :: proc
end

Flang currently issues an error as

2:16: error: The interface for procedure 'proc' has already been declared
  procedure() :: proc
                 ^^^^
./t.f:2:16: Declaration of 'proc'
  procedure() :: proc
                 ^^^^

It seems incorrect. This code should be equivalent to procedure(integer) :: proc.

DanielCChen avatar Feb 16 '24 16:02 DanielCChen

@llvm/issue-subscribers-flang-frontend

Author: Daniel Chen (DanielCChen)

Consider the following code. ``` integer :: proc procedure() :: proc end ```

Flang currently issues an error as

2:16: error: The interface for procedure 'proc' has already been declared
  procedure() :: proc
                 ^^^^
./t.f:2:16: Declaration of 'proc'
  procedure() :: proc
                 ^^^^

It seems incorrect. This code should be equivalent to procedure(integer) :: proc.

llvmbot avatar Feb 16 '24 16:02 llvmbot

@llvm/issue-subscribers-bug

Author: Daniel Chen (DanielCChen)

Consider the following code. ``` integer :: proc procedure() :: proc end ```

Flang currently issues an error as

2:16: error: The interface for procedure 'proc' has already been declared
  procedure() :: proc
                 ^^^^
./t.f:2:16: Declaration of 'proc'
  procedure() :: proc
                 ^^^^

It seems incorrect. This code should be equivalent to procedure(integer) :: proc.

llvmbot avatar Feb 16 '24 16:02 llvmbot

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

klausler avatar Feb 23 '24 21:02 klausler

Thanks for the quick fix! @klausler PR #82935 fixed the reproducer and some of the original test cases.

However, one variation still fails.

The reproducer is as follows.

integer :: proc
procedure(integer) :: proc
end

DanielCChen avatar Feb 27 '24 15:02 DanielCChen

That case has multiple type declarations for the same symbol; gfortran and NAG also emit errors.

klausler avatar Feb 27 '24 16:02 klausler

Yeah, I saw gfortran issuing an error, but both XLF and ifort accept it. It seems a harmless thing to do as the procedure declaration statement declares proc to be a function that has integer return type, which is consistent with the previous type declaration statement. Of course, if the type are different, it would definitely be an error. I can't think of a bad thing about this. Would this be an extension candidate if the standard doesn't allow it (admitted I didn't check it closely to say "yes" or "no").

DanielCChen avatar Feb 27 '24 16:02 DanielCChen

Go right ahead and implement it if that's what you want.

klausler avatar Feb 27 '24 16:02 klausler

Thanks for confirming that. I will open a new issue to track that and let the merging of PR #82835 to close this one.

DanielCChen avatar Feb 27 '24 16:02 DanielCChen