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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Incorrect location information for OpenMP constructs/clauses
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    @clementval reports that the location information for OpenMP constructs and clauses is incorrect. 

In lowering, the `getCurrentLocation` function is used. `getCurrentLocation`  refers to the location of the last Fortran construct. The same issue in OpenACC was fixed in https://reviews.llvm.org/D131659 using the `genLocation` function. A similar approach could be used for OpenMP as well.

**Reproducer**

For the following Fortran OpenMP program,
```
$ cat openmp_loc.f90 
subroutine sb(x,y)
  integer :: x, y
  !$omp parallel
      x = y
  !$omp end parallel
end subroutine
```
we get the following location information. As can be seen the location of the OpenMP construct is printed as loc1 (= line 1 column 1), this is incorrect.
```
$ ./bin/flang-new -fc1 -fopenmp  -emit-fir -mmlir --mlir-print-debuginfo openmp_loc.f90 -o -
#loc1 = loc("./openmp_loc.f90":1:1)
module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.target_triple = "aarch64-unknown-linux-gnu"} {
  func.func @_QPsb(%arg0: !fir.ref<i32> {fir.bindc_name = "x"} loc("./openmp_loc.f90":1:1), %arg1: !fir.ref<i32> {fir.bindc_name = "y"} loc("./openmp_loc.f90":1:1)) {
    omp.parallel   {
      %0 = fir.load %arg1 : !fir.ref<i32> loc(#loc2)
      fir.store %0 to %arg0 : !fir.ref<i32> loc(#loc2)
      omp.terminator loc(#loc1)
    } loc(#loc1)
    return loc(#loc3)
  } loc(#loc1)
} loc(#loc0)
#loc0 = loc(unknown)
#loc2 = loc("./openmp_loc.f90":4:7)
#loc3 = loc("./openmp_loc.f90":6:1
```
</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