Skip to content

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

@k-arrows

Description

@k-arrows

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'
  ^

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions