llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.21k stars 11.14k forks source link

Misleading parsing error message for OpenMP directives #96901

Open skatrak opened 1 month ago

skatrak commented 1 month ago

Currently, the expected behavior when encountering an invalid OpenMP directive is that the parser emits an "error: expected OpenMP construct". For example:

$ cat test.f90
subroutine foo
  integer :: x = 10
  !$omp invalid_directive
  ! ...
end subroutine foo

$ flang-new -fc1 -fopenmp -fsyntax-only test.f90
error: Could not parse test.f90
./test.f90:3:10: error: expected OpenMP construct
    !$omp invalid_directive
           ^
./test.f90:3:3: in the context: specification construct
...

However, if there is an assignment operation preceding the invalid OpenMP directive, the error message becomes something else without any mention of the possibility that there is an invalid OpenMP directive. For example:

$ cat test.f90
subroutine foo
  integer :: x
  x = 10
  !$omp invalid_directive
  ! ...
end subroutine foo

$ flang-new -fc1 -fopenmp -fsyntax-only test.f90
error: Could not parse test.f90
./test.f90:4:9: error: expected 'END'
    !$omp invalid_directive
          ^
./test.f90:4:3: in the context: execution part construct
...

This makes identifying problems related to typos or to trying to use unsupported OpenMP compound constructs hard to troubleshoot on large applications.

llvmbot commented 1 month ago

@llvm/issue-subscribers-flang-frontend

Author: Sergio Afonso (skatrak)

Currently, the expected behavior when encountering an invalid OpenMP directive is that the parser emits an "error: expected OpenMP construct". For example: ``` $ cat test.f90 subroutine foo integer :: x = 10 !$omp invalid_directive ! ... end subroutine foo $ flang-new -fc1 -fopenmp -fsyntax-only test.f90 error: Could not parse test.f90 ./test.f90:3:10: error: expected OpenMP construct !$omp invalid_directive ^ ./test.f90:3:3: in the context: specification construct ... ``` However, if there is an assignment operation preceding the invalid OpenMP directive, the error message becomes something else without any mention of the possibility that there is an invalid OpenMP directive. For example: ``` $ cat test.f90 subroutine foo integer :: x x = 10 !$omp invalid_directive ! ... end subroutine foo $ flang-new -fc1 -fopenmp -fsyntax-only test.f90 error: Could not parse test.f90 ./test.f90:4:9: error: expected 'END' !$omp invalid_directive ^ ./test.f90:4:3: in the context: execution part construct ... ``` This makes identifying problems related to typos or to trying to use unsupported OpenMP compound constructs hard to troubleshoot on large applications.