[flang-commits] [clang] [flang] [flang] Preserve fixed form in fc1 -x value (PR #117563)
via flang-commits
flang-commits at lists.llvm.org
Mon Dec 2 05:30:12 PST 2024
https://github.com/macurtis-amd updated https://github.com/llvm/llvm-project/pull/117563
>From 2b61143e7bac96ee01cfbded4a26ac8206d6b247 Mon Sep 17 00:00:00 2001
From: Matthew Curtis <macurtis at amd.com>
Date: Mon, 2 Dec 2024 07:16:28 -0600
Subject: [PATCH] [flang] Treat pre-processed input as fixed
---
clang/lib/Driver/ToolChains/Flang.cpp | 9 +++++++++
flang/test/Driver/pp-fixed-form.f90 | 19 +++++++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 flang/test/Driver/pp-fixed-form.f90
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 8c18c88fbde7f7..4c6ba5532af984 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -777,6 +777,15 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
addFortranDialectOptions(Args, CmdArgs);
+ // 'flang -E' always produces output that is suitable for use as fixed form
+ // Fortran. However it is only valid free form source if the original is also
+ // free form.
+ if (InputType == types::TY_PP_Fortran &&
+ !Args.hasArg(options::OPT_ffixed_form) &&
+ !Args.hasArg(options::OPT_ffree_form)) {
+ CmdArgs.push_back("-ffixed-form");
+ }
+
handleColorDiagnosticsArgs(D, Args, CmdArgs);
// LTO mode is parsed by the Clang driver library.
diff --git a/flang/test/Driver/pp-fixed-form.f90 b/flang/test/Driver/pp-fixed-form.f90
new file mode 100644
index 00000000000000..4695da78763ae5
--- /dev/null
+++ b/flang/test/Driver/pp-fixed-form.f90
@@ -0,0 +1,19 @@
+!RUN: %flang -save-temps -### %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FREE
+FREE: "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/free-form-test.f90"
+FREE-NEXT: "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "free-form-test.i"
+
+!RUN: %flang -save-temps -### %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=FIXED
+FIXED: "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/fixed-form-test.f"
+FIXED-NEXT: "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "fixed-form-test.i"
+
+!RUN: %flang -save-temps -### -ffree-form %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FREE-FLAG
+FREE-FLAG: "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/free-form-test.f90"
+FREE-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" "-ffree-form"
+FREE-FLAG-NOT: "-ffixed-form"
+FREE-FLAG-SAME: "-x" "f95" "free-form-test.i"
+
+!RUN: %flang -save-temps -### -ffixed-form %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=FIXED-FLAG
+FIXED-FLAG: "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/fixed-form-test.f"
+FIXED-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" "-ffixed-form"
+FIXED-FLAG-NOT: "-ffixed-form"
+FIXED-FLAG-SAME: "-x" "f95" "fixed-form-test.i"
More information about the flang-commits
mailing list