<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/96901>96901</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Misleading parsing error message for OpenMP directives
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:openmp,
            flang:parser
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          skatrak
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzclUGP6jYQxz-NcxkRJU6AzSEHujzUy2t76L1ykkniruOxPA4L375ywrLvbR_q9tBLEQgy2P__zPg3smLWg0WsxfYnsT0mag4j-ZpfVPDqJWmou9bPs_dog7kK-QxhRMCLwzZgBw2O6qzJw-uIFtC2NNuAXtsBlAVtz8roDn51aL_-Bp322AZ9RtAMYVRh0XLKM3rASQeOm4SU6D15URzefW4KLVkOfm6DkDKFE3nAi5qcQVEcRHYU2UHsstt7fZQltNEIOaR9dYvy3Hiag7YIPdEaA9A24IAeolZxgAuI4gh59va3kLmQJU3uraw_7vV8swTSNF0f0XbwI6P3xHqj7LCx-Aqbvs1h05NDOznY9Hy1QV02ZM31Q-r31jzTbDqwFNYGfliWCnm6R4pDIYpDni0d_efW3or5VMX3l9h-eegcP6Dtctot2YCXECPssNW9blXQZD_639v44UB_plc8o48g6j4q-oUmZWEFeUIbgBz6VdV5bLGLOEbzRzzesY7NgQmZ1YDQYEsTMjBNGMaogYYRXnUYaQ6g7BWiW7ShfkWZmHWjjQ7XO9_3_B6Z_-ccv8X_T0CXojhUP-ZZyP2XX45C7v8NyI_wLR_jixds5xUy5cNn-f191AyTekEG3UV6-msky3lqDE4MHo2KVQSCcHXEQH757ZdlgWBmhNny7Bz578Z3cjTb7j0PhlH5VcjT3BjkkSgAWTDKDwjKOXMbPk6Tri66qqhUgnW-z6uykjLfJ2O9xad9J3fbrm8w7zCTZSXLXKld_lT1265IdC0zWWY7uc9lWRT7VOa57LKi3DVdu1e7J1FmOCltUmPOU0p-SDTzjHW1q7I8MapBw8vlI-XCjygOKzZCSiGfvwmvN0UMb4-Jr6PeppkHFmVmNAd-dwg6GKy_ajaolumPW5cJ_m7Ce_J_G0dOZm_qMQTHcYDkScjToMM4N2lLk5CnaHL72jhPf2K8jU5LTSzkaS3rXMu_AgAA__9FTVfA">