Description
flang
version is:flang version 21.0.0git (https://github.com/llvm/llvm-project.git a3dc77c00a012bb613cb08e669dab4fadf88e935)
.- Reduced test case:
! 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 toflang -x f95 -cpp -c foo.f90
), but instead, it is not recognized correctly. Additionally,flang
does not properly recognize the following language modes:-x f95
should map to whatever the file extension is or command-line option is passed.-x f77
should map to-ffixed-form
.-x f77-cpp-input
should map to-x f77 -cpp
(i.e.,-ffixed-form -cpp
).
flang
incorrectly applies-ffixed-form
when given-x f95
(see [flang] Flang fails to interpret-x f95-cpp-input
and related modes #127617 (comment)):$ cat foo.f90 program main print *, __FILE__, __LINE__ end $ flang -x f95 -cpp foo.f90 foo.f90:1:1: warning: Character in fixed-form label field must be a digit program main ^ foo.f90:2:3: warning: Character in fixed-form label field must be a digit print *, __FILE__, __LINE__ ^ foo.f90:3:1: warning: Character in fixed-form label field must be a digit end ^
gfortran
correctly applies-ffixed-form -cpp
when given-x f77-cpp-input
:$ 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 (MESA's Makefile) withflang
. It is unclear whetherflang
aims to mimicgfortran
's behavior in its driver. However, sinceflang
explicitly supportsf95
andf95-cpp-input
, we believe it should at least align withgfortran
's behavior for this option.