[clang] [flang] [flang] Complete alignment of -x language modes with gfortran (PR #133775)
David Truby via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 10 04:13:26 PDT 2025
https://github.com/DavidTruby updated https://github.com/llvm/llvm-project/pull/133775
>From aeca7c2c7bf4cc7aef87374f3890f2a42e61d07d Mon Sep 17 00:00:00 2001
From: David Truby <david.truby at arm.com>
Date: Mon, 31 Mar 2025 19:39:37 +0100
Subject: [PATCH 1/3] [flang] Complete alignment of -x language modes with
gfortran
This fixes an issue where, since the alignment of the -x lanaguage
modes, .f90 files were being preprocessed by default. This patch
completes the alignment of the meaning of the f95-pp-input and f95
language modes to match gfortran, fixing that issue.
---
clang/include/clang/Driver/Types.def | 4 ++--
.../Driver/input-from-stdin/input-from-stdin.f90 | 2 +-
flang/test/Driver/phases.f90 | 12 ++++++------
flang/test/Driver/pp-fixed-form.f90 | 16 ++++++++--------
4 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/clang/include/clang/Driver/Types.def b/clang/include/clang/Driver/Types.def
index 214c5e7a789f9..2b6b3e75c1c97 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -88,8 +88,8 @@ TYPE("assembler-with-cpp", Asm, PP_Asm, "S", phases
// modules when Flang needs to emit pre-processed files. Therefore, the
// `PP_TYPE` is set to `PP_Fortran` so that the driver is fine with
// "pre-processing a pre-processed file".
-TYPE("f95", PP_Fortran, PP_Fortran, "i", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("f95-cpp-input", Fortran, PP_Fortran, nullptr, phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("f95", Fortran, PP_Fortran, nullptr, phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("f95-cpp-input", PP_Fortran, PP_Fortran, "i", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("java", Java, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
// LLVM IR/LTO types. We define separate types for IR and LTO because LTO
diff --git a/flang/test/Driver/input-from-stdin/input-from-stdin.f90 b/flang/test/Driver/input-from-stdin/input-from-stdin.f90
index 1fcc0340a64ba..285f0751b35d8 100644
--- a/flang/test/Driver/input-from-stdin/input-from-stdin.f90
+++ b/flang/test/Driver/input-from-stdin/input-from-stdin.f90
@@ -6,7 +6,7 @@
! Input type is implicit
! RUN: cat %s | %flang -E -cpp - | FileCheck %s --check-prefix=PP-NOT-DEFINED
! RUN: cat %s | %flang -DNEW -E -cpp - | FileCheck %s --check-prefix=PP-DEFINED
-! RUN: cat %s | %flang -DNEW -E - | FileCheck %s --check-prefix=PP-DEFINED
+! RUN: cat %s | %flang -DNEW -E - | FileCheck %s --check-prefix=PP-NOT-DEFINED
! RUN: cat %s | %flang -DNEW -E -nocpp - | FileCheck %s --check-prefix=PP-NOT-DEFINED
! Input type is explicit
diff --git a/flang/test/Driver/phases.f90 b/flang/test/Driver/phases.f90
index b688600dae035..9346773c883ef 100644
--- a/flang/test/Driver/phases.f90
+++ b/flang/test/Driver/phases.f90
@@ -4,15 +4,15 @@
! RUN: %flang -fsyntax-only -ccc-print-phases %s 2>&1 | FileCheck %s --check-prefix=COMPILE
! RUN: %flang -c -ccc-print-phases %s 2>&1 | FileCheck %s --check-prefix=EMIT_OBJ
-! PP: +- 0: input, "{{.*}}phases.f90", f95-cpp-input
-! PP-NEXT: 1: preprocessor, {0}, f95
+! PP: +- 0: input, "{{.*}}phases.f90", f95
+! PP-NEXT: 1: preprocessor, {0}, f95-cpp-input
-! COMPILE: +- 0: input, "{{.*}}phases.f90", f95-cpp-input
-! COMPILE-NEXT: 1: preprocessor, {0}, f95
+! COMPILE: +- 0: input, "{{.*}}phases.f90", f95
+! COMPILE-NEXT: 1: preprocessor, {0}, f95-cpp-input
! COMPILE-NEXT: 2: compiler, {1}, none
-! EMIT_OBJ: +- 0: input, "{{.*}}phases.f90", f95-cpp-input
-! EMIT_OBJ-NEXT: 1: preprocessor, {0}, f95
+! EMIT_OBJ: +- 0: input, "{{.*}}phases.f90", f95
+! EMIT_OBJ-NEXT: 1: preprocessor, {0}, f95-cpp-input
! EMIT_OBJ-NEXT: 2: compiler, {1}, ir
! EMIT_OBJ-NEXT: +- 3: backend, {2}, assembler
! EMIT_OBJ-NEXT: 4: assembler, {3}, object
diff --git a/flang/test/Driver/pp-fixed-form.f90 b/flang/test/Driver/pp-fixed-form.f90
index 4695da78763ae..bb869cd3341a7 100644
--- a/flang/test/Driver/pp-fixed-form.f90
+++ b/flang/test/Driver/pp-fixed-form.f90
@@ -1,19 +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"
+FREE: "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95" "{{.*}}/free-form-test.f90"
+FREE-NEXT: "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95-cpp-input" "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"
+FIXED: "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95" "{{.*}}/fixed-form-test.f"
+FIXED-NEXT: "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95-cpp-input" "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: "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95" "{{.*}}/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"
+FREE-FLAG-SAME: "-x" "f95-cpp-input" "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: "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95" "{{.*}}/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"
+FIXED-FLAG-SAME: "-x" "f95-cpp-input" "fixed-form-test.i"
>From f66a10105fb0ee3ca4199eeb0a47b69e17b5038a Mon Sep 17 00:00:00 2001
From: David Truby <david.truby at arm.com>
Date: Wed, 2 Apr 2025 14:36:59 +0100
Subject: [PATCH 2/3] Fix whitespace
---
clang/include/clang/Driver/Types.def | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/Driver/Types.def b/clang/include/clang/Driver/Types.def
index 2b6b3e75c1c97..76944ec656917 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -88,8 +88,8 @@ TYPE("assembler-with-cpp", Asm, PP_Asm, "S", phases
// modules when Flang needs to emit pre-processed files. Therefore, the
// `PP_TYPE` is set to `PP_Fortran` so that the driver is fine with
// "pre-processing a pre-processed file".
-TYPE("f95", Fortran, PP_Fortran, nullptr, phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("f95-cpp-input", PP_Fortran, PP_Fortran, "i", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("f95", Fortran, PP_Fortran, nullptr, phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("f95-cpp-input", PP_Fortran, PP_Fortran, "i", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("java", Java, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
// LLVM IR/LTO types. We define separate types for IR and LTO because LTO
>From 9ba9109999c5c895836fd147cd3f2ce1d1feec4e Mon Sep 17 00:00:00 2001
From: David Truby <david.truby at arm.com>
Date: Thu, 10 Apr 2025 12:12:04 +0100
Subject: [PATCH 3/3] Fix clang driver test
---
clang/test/Driver/fortran.f95 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/test/Driver/fortran.f95 b/clang/test/Driver/fortran.f95
index 275b1886b2fda..1447312b8bb58 100644
--- a/clang/test/Driver/fortran.f95
+++ b/clang/test/Driver/fortran.f95
@@ -5,14 +5,14 @@
! RUN: | FileCheck --check-prefix=CHECK-OBJECT %s
! CHECK-OBJECT: gcc
! CHECK-OBJECT: "-c"
-! CHECK-OBJECT: "-x" "f95"
+! CHECK-OBJECT: "-x" "f95-cpp-input"
! CHECK-OBJECT-NOT: "-cc1as"
! RUN: %clang --target=x86_64-unknown-linux-gnu -integrated-as -S %s -### 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-ASM %s
! CHECK-ASM: gcc
! CHECK-ASM: "-S"
-! CHECK-ASM: "-x" "f95"
+! CHECK-ASM: "-x" "f95-cpp-input"
! CHECK-ASM-NOT: "-cc1"
! RUN: %clang -Wall --target=x86_64-unknown-linux-gnu -integrated-as %s -### 2>&1 | FileCheck --check-prefix=CHECK-WARN %s
More information about the cfe-commits
mailing list