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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] `!$` output by preprocessor results in scan error with -fopenmp
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          kawashima-fj
      </td>
    </tr>
</table>

<pre>
    #133959 changed behavior of the preprocessor.

`test1.f`:

```fortran
c$   !1
 end
```

One-pass compilation succeeds.

```console
$ flang -S -fopenmp test1.f
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
$
```

Two-pass compilation via a proprocessed file fails.

```console
$ flang -E -fopenmp test1.f -o test1.pp.f
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
$ cat test1.pp.f
#line "./test1.f" 1
!$    &1
 end
$ flang -S -fopenmp test1.pp.f
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
error: Could not scan test1.pp.f
./test1.f:1:7: error: bad character ('&') in Fortran token
  !$ &1
        ^
$
```

The following is another example.

`test2.f`:

```fortran
C$   
 end
```

```console
$ flang -S -fopenmp test2.f
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
$
```

```console
$ flang -E -fopenmp test2.f -o test2.pp.f
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
$ cat test2.pp.f
#line "./test2.f" 1
!$    & end
              end
$ flang -S -fopenmp test2.pp.f
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
error: Could not scan test2.pp.f
./test2.f:1:7: error: bad character ('&') in Fortran token
  !$    & end
        ^
```

Before #133959, two-pass compilation succeeded.

@klausler Is this an intended behavior?

This issue was detected as a regression by the following tests in the [Fujitsu Compiler Test Suite](https://github.com/fujitsu/compiler-test-suite/).

- Fortran/0213/0213_0000.f
- Fortran/0213/0213_0001.f
- Fortran/0213/0213_0008.f
- Fortran/0213/0213_0009.f
- Fortran/0213/0213_0011.f
- Fortran/0213/0213_0012.f
- Fortran/0213/0213_0013.f
- Fortran/0213/0213_0017.f
- Fortran/0213/0213_0020.f
- Fortran/0213/0213_0026.f
- Fortran/0213/0213_0028.f
- Fortran/0213/0213_0032.f

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzElt9vozgQx_8a52VEZIYfIQ88pO0i3cNpT9qV7vFkYAhuHRvZptn9708mpE2223ArnboIATIz9nzH87EtnJN7TVSy7I4hPikxOkWWIbLsYSVG3xtbPomjcL08iKh7XNWm_V4yTOIk2WZbaHqh99RCTb14lsaC6cD3BIOlwZqGnDN2zfgu3Dn35Hy87ljOWbJ7aT3dnbHeCs34rmGYAgDDOGZ8B6TbS7uT22dN0SCcg8YcBqmEl0aDG5uGqHXrH7pujHZGUWjCFDol9B6iLxB1ZiB9GOAcFt9N_yKMWbKDo7Ba6n34_DyQ_vMvcOMwGOtB6rkT6cB5qRTQt4GsPJD2QgHL7qK_L1siM4T4WPZwCuGtnK9H81bOsxQgYLBmziS10ElF0Amp_pvGT280QmTmz2H4QMXQCH89LsNESU3AENcMq_MUIEI8_Y1PRQAM88squDF_HyeIrDU2dHpvRtWCNh5cI_R1HJeqkl0IZxNcXnxr0QZ6rGg8WWBYMNwwzKfnNsRXnYAAb54oYDERERJwTsl8sezTu2XVE3RGKXOUJ6lCG9-TBfomDoOiazJxkcz7mcz3qPwl4vC3EvdL4OArOPibwMEb4OA74MyTBFfXEkgfKfAWSPgjSPi_g_TTLM04XVfLHXXGhpzP-x7De_A_W7PnLYjaM1opP2-q8IcD308QgtSedHuxb7KkOiMrHUjnRoKjcNCSp8ZTC8KBAEt7S86Fgerv0z77SndIkQtyQzPL7qrxUXo3wv0UHVn4Ss7Dl1F6CsnHovd-cIF2rBhWe-n7sV435sCw6k6-DKtm9o5C95GbvIP9dtYXnbPLsOIYJ_PrH845n2bvh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