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

    <tr>
        <th>Summary</th>
        <td>
            [flang] Flang fails to interpret `-x f95-cpp-input` and related modes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          inaki-amatria
      </td>
    </tr>
</table>

<pre>
    - `flang` version is: `flang version 21.0.0git (https://github.com/llvm/llvm-project.git a3dc77c00a012bb613cb08e669dab4fadf88e935)`.
- Reduced test case:
```f90
! foo.f90

program main
  print *, __FILE__, __LINE__
end
```
- `flang` invocation is: `flang -x f95-cpp-input -c foo.f90`.
- Expected behavior is: The code compiles successfully.
- Actual behavior: Compilation aborts with the following error:
```
error: Semantic errors foo.f90
foo.f90:4:12: error: No explicit type declared for '__file__'
    print *, __FILE__, __LINE__
             ^^^^^^^^
foo.f90:4:22: error: No explicit type declared for '__line__'
    print *, __FILE__, __LINE__
 ^^^^^^^^
```
- Analysis: It appears that `flang` does not correctly interpret `-x f95-cpp-input`. This option should enable preprocessing (equivalent to `flang -x f95 -cpp -c foo.f90`), but instead, it is not recognized correctly. Additionally, `flang` does not properly recognize the following language modes:
  - `-x f77` should map to `-ffixed-form`.
  - `-x f77-cpp-input` should map to `-x f77 -cpp` (i.e., `-ffixed-form -cpp`).

  `gfortran` correctly applies `-ffixed-form -cpp` when given `-x f77-cpp-input`:
```bash
$ cat foo.f90
#ifdef __FILE__
subroutine foo()
end
#endif
$ gfortran -x f77-cpp-input foo.f90 
foo.f90:2:2:

 2 | subroutine foo()
      |  1
Error: Non-numeric character in statement label at (1)
foo.f90:3:2:

    3 | end
      |  1
Error: Non-numeric character in statement label at (1)
```
- Request: The `-x` flag should correctly recognize and apply the appropiate Fortran language modes. This is required to compile codes such as [MESA](https://github.com/MESAHub/mesa/tree/62ad83ac055e09c8b9001664378e879e57355112) ([MESA's Makefile](https://github.com/MESAHub/mesa/blob/62ad83ac055e09c8b9001664378e879e57355112/utils/makefile_header#L153)) with `flang`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVktv2z4S_zT0ZWCBoqzXwQc1jbEF2h7a3oMRNbK4pUmVpNJ4P_2Cshw_kHY3wD9QEj3m8ZuZ38wQvVd7Q7Rl-QeWf1zhFAbrtsrgT7XGAwancNXa7rhdAyt4r9HsWcHhmZxX1oDyLGtev7y-FmnCE75XAZiohhDGKMbEjondXoVhahNpD0zstH4-_1uPzv6bZEiiFmadLEvJOfJUtG2RZrLlFRVF3WG76bHrq4rqLGeiZgVPGG_W8I26SVIHgXwAiZ6iS96wgp-uvubxUaTQW5ssT7wZnd07PMABlWG8ARidMhF3w8QDPD3tPn1-fHo63X_-9DXe84ZMd2169n-dHmWercTwRobWL9DX-VqO41qZcQqwlq94zpE8vowkA3XQ0oDPyrrFyI-BQNou_jmMSpMHP0lJ3veT1seTbiPDhPpVM6o9zNInNNhaFzz8VmGAMBD0Vmv7W5k9kHOz-F1c59fwnQ5ogpInQX-VxPNd1mxY1qQiSr-qfbVAL6NWUgUIx5GgI6nRUQe9dcBE-fTUK00xw-Wc_v-vAHD9w_LHt697bOLd2LQy78f2Fzy3lGkM6qM_FfdTABxHQuchDBhu6NRZ8mBsAGmdIxn0EZQJ5EZHs-A9qSKT4MegPNhxLrsf7KQ7IIOtJhgdjc5G4sTCM1HRr0k9oyYTINh7rkK0e0vT2HbiAdopgDI-EHbxUQVQJ5iOpN0b9R_qLogTaLpORTSo9THKvxnh6OxITh8vNu54GjUm3BMcbEf-RFiA9TkNZRnNLfEecFwCWve9eqFu3Vt3WPrsRukmd2-oz0JzJuJ3JiqVULIEcW37LMJEnZzmC0SRfW9dcGii8qWGOI5akf-TDfg9kIG9eibzB6B37dqiH-YRtwGJ4XrMiUz1HfUXxvLGT62zU1AmJtcyUcWivk42kZHpVL9YO8OHewx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