Issue 127617
Summary [flang] Flang fails to interpret `-x f95-cpp-input` and related modes
Labels
Assignees
Reporter inaki-amatria
    - `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`.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to