Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanielCChen opened this issue Feb 16, 2024 · 8 comments · Fixed by #82835
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior flang:frontend

Comments

@DanielCChen
Copy link
Contributor

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 DanielCChen added flang:frontend flang Flang issues not falling into any other category flang:semantics labels Feb 16, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 16, 2024

@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.

@EugeneZelenko EugeneZelenko removed flang Flang issues not falling into any other category flang:semantics labels Feb 16, 2024
@psteinfeld psteinfeld added the bug Indicates an unexpected problem or unintended behavior label Feb 16, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 16, 2024

@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.

@DanielCChen DanielCChen changed the title [Flang] Incorrect diagnose when declare a procedure with explicit typing in multiple statement [Flang] Incorrect diagnose when declare a procedure with explicit typing in multiple statements Feb 16, 2024
klausler added a commit to klausler/llvm-project that referenced this issue Feb 23, 2024
Fortran allows a procedure declaration statement with no interface
or type, with an explicit type declaration statement elsewhere
being used to define a function's result.

Fixes llvm#82006.
@klausler
Copy link
Contributor

#82835

@klausler klausler self-assigned this Feb 23, 2024
@DanielCChen
Copy link
Contributor Author

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

@klausler
Copy link
Contributor

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

@DanielCChen
Copy link
Contributor Author

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").

@klausler
Copy link
Contributor

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

@DanielCChen
Copy link
Contributor Author

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

klausler added a commit that referenced this issue Mar 2, 2024
Fortran allows a procedure declaration statement with no interface or
type, with an explicit type declaration statement elsewhere being used
to define a function's result.

Fixes #82006.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior flang:frontend
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants