Skip to content
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

[flang] cannot parse a program where write statement is incorrectly positioned in contains section #109609

Closed
k-arrows opened this issue Sep 23, 2024 · 2 comments · Fixed by #109698
Assignees

Comments

@k-arrows
Copy link

Consider the following invalid Fortran program.

write(*, *) 'OK'
contains
write(*, *) 'NG'
end

If you compile the above program with gfortran, the following error message is obtained. The message correctly points out an error in the program.

$ gfortran test.f90
test.f90:3:16:

    3 | write(*, *) 'NG'
      |                1
Error: Unexpected WRITE statement in CONTAINS section at (1)

With flang-new, the following not-so-kind error message is obtained.

$ flang-new test.f90
error: Could not parse test.f90
./test.f90:3:1: error: expected 'END'
  write(*, *) 'NG'
  ^
./test.f90:3:1: in the context: END PROGRAM statement
  write(*, *) 'NG'
  ^
./test.f90:1:1: in the context: main program
  write(*, *) 'OK'
  ^
./test.f90:3:1: error: expected 'END PROGRAM'
  write(*, *) 'NG'
  ^
./test.f90:3:1: in the context: END PROGRAM statement
  write(*, *) 'NG'
  ^
./test.f90:1:1: in the context: main program
  write(*, *) 'OK'
  ^
@github-actions github-actions bot added the flang Flang issues not falling into any other category label Sep 23, 2024
@k-arrows k-arrows added flang:frontend and removed flang Flang issues not falling into any other category labels Sep 23, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 23, 2024

@llvm/issue-subscribers-flang-frontend

Author: None (k-arrows)

Consider the following invalid Fortran program. ```f90 write(*, *) 'OK' contains write(*, *) 'NG' end ``` If you compile the above program with gfortran, the following error message is obtained. The message correctly points out an error in the program. ```console $ gfortran test.f90 test.f90:3:16:
3 | write(*, *) 'NG'
  |                1

Error: Unexpected WRITE statement in CONTAINS section at (1)

With flang-new, the following not-so-kind error message is obtained.
```console
$ flang-new test.f90
error: Could not parse test.f90
./test.f90:3:1: error: expected 'END'
  write(*, *) 'NG'
  ^
./test.f90:3:1: in the context: END PROGRAM statement
  write(*, *) 'NG'
  ^
./test.f90:1:1: in the context: main program
  write(*, *) 'OK'
  ^
./test.f90:3:1: error: expected 'END PROGRAM'
  write(*, *) 'NG'
  ^
./test.f90:3:1: in the context: END PROGRAM statement
  write(*, *) 'NG'
  ^
./test.f90:1:1: in the context: main program
  write(*, *) 'OK'
  ^

@klausler klausler self-assigned this Sep 23, 2024
@klausler
Copy link
Contributor

#109698

klausler added a commit to klausler/llvm-project that referenced this issue Sep 23, 2024
After a CONTAINS statement in a program unit, a statement that
cannot begin a subprogram will trigger catastrophic error recovery.
But the compiler is presently emitting multiple errors for the
same location about expected variations of END statements.
Emit fewer messages.

Fixes llvm#109609.
klausler added a commit that referenced this issue Sep 30, 2024
)

After a CONTAINS statement in a program unit, a statement that cannot
begin a subprogram will trigger catastrophic error recovery. But the
compiler is presently emitting multiple errors for the same location
about expected variations of END statements. Emit fewer messages.

Fixes #109609.
puja2196 pushed a commit to puja2196/LLVM-tutorial that referenced this issue Oct 2, 2024
…698)

After a CONTAINS statement in a program unit, a statement that cannot
begin a subprogram will trigger catastrophic error recovery. But the
compiler is presently emitting multiple errors for the same location
about expected variations of END statements. Emit fewer messages.

Fixes llvm/llvm-project#109609.
VitaNuo pushed a commit to VitaNuo/llvm-project that referenced this issue Oct 2, 2024
…#109698)

After a CONTAINS statement in a program unit, a statement that cannot
begin a subprogram will trigger catastrophic error recovery. But the
compiler is presently emitting multiple errors for the same location
about expected variations of END statements. Emit fewer messages.

Fixes llvm#109609.
VitaNuo pushed a commit to VitaNuo/llvm-project that referenced this issue Oct 2, 2024
…#109698)

After a CONTAINS statement in a program unit, a statement that cannot
begin a subprogram will trigger catastrophic error recovery. But the
compiler is presently emitting multiple errors for the same location
about expected variations of END statements. Emit fewer messages.

Fixes llvm#109609.
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this issue Oct 3, 2024
…#109698)

After a CONTAINS statement in a program unit, a statement that cannot
begin a subprogram will trigger catastrophic error recovery. But the
compiler is presently emitting multiple errors for the same location
about expected variations of END statements. Emit fewer messages.

Fixes llvm#109609.
xgupta pushed a commit to xgupta/llvm-project that referenced this issue Oct 4, 2024
…#109698)

After a CONTAINS statement in a program unit, a statement that cannot
begin a subprogram will trigger catastrophic error recovery. But the
compiler is presently emitting multiple errors for the same location
about expected variations of END statements. Emit fewer messages.

Fixes llvm#109609.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants