Skip to content

Commit 81d82ca

Browse files
authored
[flang] Treat pre-processed input as fixed (#117563)
Fixes an issue introduced by 9fb2db1 [flang] Retain spaces when preprocessing fixed-form source Where flang -fc1 fails to parse preprocessor output because it now remains in fixed form.
1 parent a639312 commit 81d82ca

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
777777

778778
addFortranDialectOptions(Args, CmdArgs);
779779

780+
// 'flang -E' always produces output that is suitable for use as fixed form
781+
// Fortran. However it is only valid free form source if the original is also
782+
// free form.
783+
if (InputType == types::TY_PP_Fortran &&
784+
!Args.getLastArg(options::OPT_ffixed_form, options::OPT_ffree_form))
785+
CmdArgs.push_back("-ffixed-form");
786+
780787
handleColorDiagnosticsArgs(D, Args, CmdArgs);
781788

782789
// LTO mode is parsed by the Clang driver library.

flang/test/Driver/pp-fixed-form.f90

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
!RUN: %flang -save-temps -### %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FREE
2+
FREE: "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/free-form-test.f90"
3+
FREE-NEXT: "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "free-form-test.i"
4+
5+
!RUN: %flang -save-temps -### %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=FIXED
6+
FIXED: "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/fixed-form-test.f"
7+
FIXED-NEXT: "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "fixed-form-test.i"
8+
9+
!RUN: %flang -save-temps -### -ffree-form %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FREE-FLAG
10+
FREE-FLAG: "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/free-form-test.f90"
11+
FREE-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" "-ffree-form"
12+
FREE-FLAG-NOT: "-ffixed-form"
13+
FREE-FLAG-SAME: "-x" "f95" "free-form-test.i"
14+
15+
!RUN: %flang -save-temps -### -ffixed-form %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=FIXED-FLAG
16+
FIXED-FLAG: "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/fixed-form-test.f"
17+
FIXED-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" "-ffixed-form"
18+
FIXED-FLAG-NOT: "-ffixed-form"
19+
FIXED-FLAG-SAME: "-x" "f95" "fixed-form-test.i"

0 commit comments

Comments
 (0)