[flang-commits] [clang] [flang] [flang] Do not hardcode "flang" in the driver (PR #200438)
Kelvin Li via flang-commits
flang-commits at lists.llvm.org
Mon Jun 15 09:48:27 PDT 2026
https://github.com/kkwli updated https://github.com/llvm/llvm-project/pull/200438
>From d1b3016e88622a1e0a013d276217ac6b703200ec Mon Sep 17 00:00:00 2001
From: Kelvin Li <kli at ca.ibm.com>
Date: Fri, 29 May 2026 11:42:04 -0400
Subject: [PATCH 1/3] [flang] Do not hardcode "flang" in the driver
Currently, the driver program hardcodes "flang" as the frontend to
invoke. This patch is to make the driver invoke the frontend that
has the same name as the driver program.
---
clang/lib/Driver/ToolChains/Flang.cpp | 2 +-
flang/test/Driver/large-data-threshold.f90 | 6 +-
flang/test/Driver/omp-driver-offload.f90 | 58 +++++++++----------
.../Driver/supported-suffices/f03-suffix.f03 | 2 +-
.../Driver/supported-suffices/f08-suffix.f08 | 2 +-
flang/test/Driver/version-loops.f90 | 14 ++---
6 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index ce503b74295e4..5b941f611e0b6 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -1282,7 +1282,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
Input.getInputArg().renderAsInput(Args, CmdArgs);
}
- const char *Exec = Args.MakeArgString(D.GetProgramPath("flang", TC));
+ const char *Exec = D.getClangProgramPath();
C.addCommand(std::make_unique<Command>(JA, *this,
ResponseFileSupport::AtFileUTF8(),
Exec, CmdArgs, Inputs, Output));
diff --git a/flang/test/Driver/large-data-threshold.f90 b/flang/test/Driver/large-data-threshold.f90
index fa2d4aef911e3..78ed756bc4403 100644
--- a/flang/test/Driver/large-data-threshold.f90
+++ b/flang/test/Driver/large-data-threshold.f90
@@ -7,11 +7,11 @@
! RUN: not %flang -### -c --target=aarch64 -mcmodel=small -mlarge-data-threshold=32768 %s 2>&1 | FileCheck %s --check-prefix=NOT-SUPPORTED
-! CHECK: "{{.*}}flang" "-fc1"
+! CHECK: "{{.*}}flang{{.*}}" "-fc1"
! CHECK-SAME: "-mlarge-data-threshold=32768"
-! CHECK-59000: "{{.*}}flang" "-fc1"
+! CHECK-59000: "{{.*}}flang{{.*}}" "-fc1"
! CHECK-59000-SAME: "-mlarge-data-threshold=59000"
-! CHECK-1M: "{{.*}}flang" "-fc1"
+! CHECK-1M: "{{.*}}flang{{.*}}" "-fc1"
! CHECK-1M-SAME: "-mlarge-data-threshold=1048576"
! NO-MCMODEL: 'mlarge-data-threshold=' only applies to medium and large code models
! INVALID: error: invalid value 'nonsense' in '-mlarge-data-threshold='
diff --git a/flang/test/Driver/omp-driver-offload.f90 b/flang/test/Driver/omp-driver-offload.f90
index a4184f11bf3b0..4f56ea04b4a13 100644
--- a/flang/test/Driver/omp-driver-offload.f90
+++ b/flang/test/Driver/omp-driver-offload.f90
@@ -8,7 +8,7 @@
! Test regular -fopenmp with no offload
! RUN: %flang -### -fopenmp %s 2>&1 | FileCheck --check-prefixes=CHECK-OPENMP %s
-! CHECK-OPENMP: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}}.f90"
+! CHECK-OPENMP: "{{[^"]*}}flang{{[^"]*}}" "-fc1" {{.*}} "-fopenmp" {{.*}}.f90"
! CHECK-OPENMP-NOT: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" {{.*}}.f90"
! Test regular -fopenmp with offload, and invocation filtering options
@@ -22,17 +22,17 @@
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
-! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
-! OFFLOAD-HOST-AND-DEVICE-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa"
-! OFFLOAD-HOST-AND-DEVICE-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "nvptx64-nvidia-cuda"
-! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! OFFLOAD-HOST-AND-DEVICE-NEXT: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! OFFLOAD-HOST-AND-DEVICE-NEXT: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "nvptx64-nvidia-cuda"
+! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
! RUN: %flang -S -### %s -o %t 2>&1 \
! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-host-only \
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST
-! OFFLOAD-HOST: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! OFFLOAD-HOST: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
! OFFLOAD-HOST-NOT: "-triple" "amdgcn-amd-amdhsa"
! OFFLOAD-HOST-NOT: "-triple" "nvptx64-nvidia-cuda"
! OFFLOAD-HOST-NOT: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
@@ -42,27 +42,27 @@
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
! RUN: | FileCheck %s --check-prefix=OFFLOAD-DEVICE
-! OFFLOAD-DEVICE: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
-! OFFLOAD-DEVICE-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa"
-! OFFLOAD-DEVICE-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "nvptx64-nvidia-cuda"
-! OFFLOAD-DEVICE-NOT: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! OFFLOAD-DEVICE: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! OFFLOAD-DEVICE-NEXT: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! OFFLOAD-DEVICE-NEXT: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "nvptx64-nvidia-cuda"
+! OFFLOAD-DEVICE-NOT: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
! Test regular -fopenmp with offload for basic fopenmp-is-target-device flag addition and correct fopenmp
! RUN: %flang -### -fopenmp --offload-arch=gfx90a -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib %s 2>&1 | FileCheck --check-prefixes=CHECK-OPENMP-IS-TARGET-DEVICE %s
-! CHECK-OPENMP-IS-TARGET-DEVICE: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" {{.*}}.f90"
+! CHECK-OPENMP-IS-TARGET-DEVICE: "{{[^"]*}}flang{{[^"]*}}" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" {{.*}}.f90"
! Testing appropriate flags are gnerated and appropriately assigned by the driver when offloading
! RUN: %flang -S -### %s -o %t 2>&1 \
! RUN: -fopenmp --offload-arch=gfx90a \
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
! RUN: | FileCheck %s --check-prefix=OPENMP-OFFLOAD-ARGS
-! OPENMP-OFFLOAD-ARGS: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}}.f90"
-! OPENMP-OFFLOAD-ARGS-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! OPENMP-OFFLOAD-ARGS: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}}.f90"
+! OPENMP-OFFLOAD-ARGS-NEXT: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "amdgcn-amd-amdhsa"
! OPENMP-OFFLOAD-ARGS-SAME: "-fopenmp"
! OPENMP-OFFLOAD-ARGS-SAME: "-fopenmp-host-ir-file-path" "{{.*}}.bc" "-fopenmp-is-target-device"
! OPENMP-OFFLOAD-ARGS-SAME: {{.*}}.f90"
! OPENMP-OFFLOAD-ARGS: "{{[^"]*}}llvm-offload-binary{{.*}}" {{.*}} "--image=file={{.*}}.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"
-! OPENMP-OFFLOAD-ARGS-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! OPENMP-OFFLOAD-ARGS-NEXT: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
! OPENMP-OFFLOAD-ARGS-SAME: "-fopenmp"
! OPENMP-OFFLOAD-ARGS-SAME: "-fembed-offload-object={{.*}}.out" {{.*}}.bc"
@@ -77,7 +77,7 @@
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
! RUN: -fopenmp-assume-threads-oversubscription -nogpulib \
! RUN: | FileCheck %s --check-prefixes=CHECK-THREADS-OVS
-! CHECK-THREADS-OVS: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-threads-oversubscription" {{.*}}.f90"
+! CHECK-THREADS-OVS: "{{[^"]*}}flang{{[^"]*}}" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-threads-oversubscription" {{.*}}.f90"
! RUN: %flang -### %s -o %t 2>&1 \
! RUN: -fopenmp --offload-arch=gfx90a \
@@ -89,7 +89,7 @@
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
! RUN: -fopenmp-assume-teams-oversubscription -nogpulib \
! RUN: | FileCheck %s --check-prefixes=CHECK-TEAMS-OVS
-! CHECK-TEAMS-OVS: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-teams-oversubscription" {{.*}}.f90"
+! CHECK-TEAMS-OVS: "{{[^"]*}}flang{{[^"]*}}" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-teams-oversubscription" {{.*}}.f90"
! RUN: %flang -### %s -o %t 2>&1 \
! RUN: -fopenmp --offload-arch=gfx90a \
@@ -101,7 +101,7 @@
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
! RUN: -fopenmp-assume-no-nested-parallelism -nogpulib \
! RUN: | FileCheck %s --check-prefixes=CHECK-NEST-PAR
-! CHECK-NEST-PAR: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-no-nested-parallelism" {{.*}}.f90"
+! CHECK-NEST-PAR: "{{[^"]*}}flang{{[^"]*}}" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-no-nested-parallelism" {{.*}}.f90"
! RUN: %flang -### %s -o %t 2>&1 \
! RUN: -fopenmp --offload-arch=gfx90a \
@@ -113,7 +113,7 @@
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
! RUN: -fopenmp-assume-no-thread-state -nogpulib \
! RUN: | FileCheck %s --check-prefixes=CHECK-THREAD-STATE
-! CHECK-THREAD-STATE: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-no-thread-state" {{.*}}.f90"
+! CHECK-THREAD-STATE: "{{[^"]*}}flang{{[^"]*}}" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-no-thread-state" {{.*}}.f90"
! RUN: %flang -### %s -o %t 2>&1 \
! RUN: -fopenmp --offload-arch=gfx90a \
@@ -125,7 +125,7 @@
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
! RUN: -fopenmp-target-debug -nogpulib \
! RUN: | FileCheck %s --check-prefixes=CHECK-TARGET-DEBUG
-! CHECK-TARGET-DEBUG: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug" {{.*}}.f90"
+! CHECK-TARGET-DEBUG: "{{[^"]*}}flang{{[^"]*}}" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug" {{.*}}.f90"
! RUN: %flang -### %s -o %t 2>&1 \
! RUN: -fopenmp --offload-arch=gfx90a \
@@ -137,7 +137,7 @@
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
! RUN: -fopenmp-target-debug=111 -nogpulib \
! RUN: | FileCheck %s --check-prefixes=CHECK-TARGET-DEBUG-EQ
-! CHECK-TARGET-DEBUG-EQ: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug=111" {{.*}}.f90"
+! CHECK-TARGET-DEBUG-EQ: "{{[^"]*}}flang{{[^"]*}}" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug=111" {{.*}}.f90"
! RUN: %flang -S -### %s -o %t 2>&1 \
! RUN: -fopenmp --offload-arch=gfx90a \
@@ -153,7 +153,7 @@
! RUN: -fopenmp-assume-teams-oversubscription -fopenmp-assume-no-nested-parallelism \
! RUN: -fopenmp-assume-no-thread-state -nogpulib \
! RUN: | FileCheck %s --check-prefixes=CHECK-RTL-ALL
-! CHECK-RTL-ALL: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug" "-fopenmp-assume-teams-oversubscription"
+! CHECK-RTL-ALL: "{{[^"]*}}flang{{[^"]*}}" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug" "-fopenmp-assume-teams-oversubscription"
! CHECK-RTL-ALL: "-fopenmp-assume-threads-oversubscription" "-fopenmp-assume-no-thread-state" "-fopenmp-assume-no-nested-parallelism"
! CHECK-RTL-ALL: {{.*}}.f90"
@@ -167,7 +167,7 @@
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
! RUN: -fopenmp-version=45 -nogpulib \
! RUN: | FileCheck %s --check-prefixes=CHECK-OPENMP-VERSION
-! CHECK-OPENMP-VERSION: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" "-fopenmp-version=45" {{.*}}.f90"
+! CHECK-OPENMP-VERSION: "{{[^"]*}}flang{{[^"]*}}" "-fc1" {{.*}} "-fopenmp" "-fopenmp-version=45" {{.*}}.f90"
! Test diagnostic error when host IR file is non-existent
! RUN: not %flang_fc1 %s -o %t 2>&1 -fopenmp -fopenmp-is-target-device \
@@ -192,7 +192,7 @@
! RUN: --target=aarch64-unknown-linux-gnu \
! RUN: | FileCheck %s --check-prefix=FORCE-USM-NO-OFFLOAD
-! FORCE-USM-NO-OFFLOAD: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! FORCE-USM-NO-OFFLOAD: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
! FORCE-USM-NO-OFFLOAD-SAME: "-fopenmp" "-fopenmp-force-usm"
! Test -fopenmp-force-usm option with offload
@@ -201,16 +201,16 @@
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
! RUN: | FileCheck %s --check-prefix=FORCE-USM-OFFLOAD
-! FORCE-USM-OFFLOAD: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! FORCE-USM-OFFLOAD: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
! FORCE-USM-OFFLOAD-SAME: "-fopenmp" "-fopenmp-force-usm"
-! FORCE-USM-OFFLOAD-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! FORCE-USM-OFFLOAD-NEXT: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "amdgcn-amd-amdhsa"
! FORCE-USM-OFFLOAD-SAME: "-fopenmp" "-fopenmp-force-usm"
! RUN: %flang -### -v --target=x86_64-unknown-linux-gnu -fopenmp \
! RUN: --offload-arch=gfx900 \
! RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
! RUN: | FileCheck --check-prefix=MLINK-BUILTIN-BITCODE %s
-! MLINK-BUILTIN-BITCODE: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! MLINK-BUILTIN-BITCODE: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "amdgcn-amd-amdhsa"
! MLINK-BUILTIN-BITCODE-SAME: "-mlink-builtin-bitcode" {{.*Inputs.*rocm.*amdgcn.*bitcode.*}}oclc_isa_version_900.bc
! Test that the -fopenmp-targets option is added to host compilation invocations
@@ -224,9 +224,9 @@
! RUN: --target=x86_64-unknown-linux-gnu -nogpulib \
! RUN: | FileCheck %s --check-prefix=OFFLOAD-TARGETS
-! OFFLOAD-TARGETS: "{{[^"]*}}flang" "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! OFFLOAD-TARGETS: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "x86_64-unknown-linux-gnu"
! OFFLOAD-TARGETS-SAME: "--offload-targets=amdgcn-amd-amdhsa"
-! OFFLOAD-TARGETS-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! OFFLOAD-TARGETS-NEXT: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "amdgcn-amd-amdhsa"
! OFFLOAD-TARGETS-NOT: --offload-targets
-! OFFLOAD-TARGETS: "{{[^"]*}}flang" "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! OFFLOAD-TARGETS: "{{[^"]*}}flang{{[^"]*}}" "-fc1" "-triple" "x86_64-unknown-linux-gnu"
! OFFLOAD-TARGETS-SAME: "--offload-targets=amdgcn-amd-amdhsa"
diff --git a/flang/test/Driver/supported-suffices/f03-suffix.f03 b/flang/test/Driver/supported-suffices/f03-suffix.f03
index 1d850305cd040..16d250fd0696f 100644
--- a/flang/test/Driver/supported-suffices/f03-suffix.f03
+++ b/flang/test/Driver/supported-suffices/f03-suffix.f03
@@ -1,5 +1,5 @@
! RUN: %flang -### %s 2>&1 | FileCheck %s
-! CHECK: "{{.*}}flang" "-fc1" {{.*}} "-o" "{{.*}}.o"
+! CHECK: "{{.*}}flang{{.*}}" "-fc1" {{.*}} "-o" "{{.*}}.o"
program f03
end program f03
diff --git a/flang/test/Driver/supported-suffices/f08-suffix.f08 b/flang/test/Driver/supported-suffices/f08-suffix.f08
index 2b31e4c21876a..5c3c53edf76ee 100644
--- a/flang/test/Driver/supported-suffices/f08-suffix.f08
+++ b/flang/test/Driver/supported-suffices/f08-suffix.f08
@@ -1,5 +1,5 @@
! RUN: %flang -### %s 2>&1 | FileCheck %s
-! CHECK: "{{.*}}flang" "-fc1" {{.*}} "-o" "{{.*}}.o"
+! CHECK: "{{.*}}flang{{.*}}" "-fc1" {{.*}} "-o" "{{.*}}.o"
program f08
end program f08
diff --git a/flang/test/Driver/version-loops.f90 b/flang/test/Driver/version-loops.f90
index c4caf4688ab43..055a0231f19d9 100644
--- a/flang/test/Driver/version-loops.f90
+++ b/flang/test/Driver/version-loops.f90
@@ -23,32 +23,32 @@
! RUN: %flang -### %s -o %t 2>&1 -O3 -fno-version-loops-for-stride \
! RUN: | FileCheck %s --check-prefix=CHECK-O3-no
-! CHECK: "{{.*}}flang" "-fc1"
+! CHECK: "{{.*}}flang{{.*}}" "-fc1"
! CHECK-SAME: "-fversion-loops-for-stride"
! CHECK-SAME: "-O3"
-! CHECK-O2: "{{.*}}flang" "-fc1"
+! CHECK-O2: "{{.*}}flang{{.*}}" "-fc1"
! CHECK-O2-NOT: "-fversion-loops-for-stride"
! CHECK-O2-SAME: "-O2"
-! CHECK-O2-with: "{{.*}}flang" "-fc1"
+! CHECK-O2-with: "{{.*}}flang{{.*}}" "-fc1"
! CHECK-O2-with-SAME: "-fversion-loops-for-stride"
! CHECK-O2-with-SAME: "-O2"
-! CHECK-O4: "{{.*}}flang" "-fc1"
+! CHECK-O4: "{{.*}}flang{{.*}}" "-fc1"
! CHECK-O4-SAME: "-fversion-loops-for-stride"
! CHECK-O4-SAME: "-O3"
-! CHECK-Ofast: "{{.*}}flang" "-fc1"
+! CHECK-Ofast: "{{.*}}flang{{.*}}" "-fc1"
! CHECK-Ofast-SAME: "-ffast-math"
! CHECK-Ofast-SAME: "-fversion-loops-for-stride"
! CHECK-Ofast-SAME: "-O3"
-! CHECK-Ofast-no: "{{.*}}flang" "-fc1"
+! CHECK-Ofast-no: "{{.*}}flang{{.*}}" "-fc1"
! CHECK-Ofast-no-SAME: "-ffast-math"
! CHECK-Ofast-no-NOT: "-fversion-loops-for-stride"
! CHECK-Ofast-no-SAME: "-O3"
-! CHECK-O3-no: "{{.*}}flang" "-fc1"
+! CHECK-O3-no: "{{.*}}flang{{.*}}" "-fc1"
! CHECK-O3-no-NOT: "-fversion-loops-for-stride"
! CHECK-O3-no-SAME: "-O3"
>From 3ad122cc791d72535ef076d9abe1e0fa195698d7 Mon Sep 17 00:00:00 2001
From: Kelvin Li <kli at ca.ibm.com>
Date: Thu, 4 Jun 2026 17:45:47 -0400
Subject: [PATCH 2/3] handle clang --driver-mode=flang case
---
clang/lib/Driver/ToolChains/Flang.cpp | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index c921b8b80799b..95e641112afb0 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -1320,7 +1320,18 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
Input.getInputArg().renderAsInput(Args, CmdArgs);
}
- const char *Exec = D.getClangProgramPath();
+ // Handle "clang --driver-mode=flang" case
+ bool isClangDriverWithFlangMode = false;
+ if (D.Name.find("clang") != std::string_view::npos) {
+ if (const Arg *A = Args.getLastArg(options::OPT_driver_mode)) {
+ if (std::string_view(A->getValue()) == "flang") {
+ isClangDriverWithFlangMode = true;
+ }
+ }
+ }
+ const char *Exec = isClangDriverWithFlangMode
+ ? Args.MakeArgString(D.GetProgramPath("flang", TC))
+ : D.getDriverProgramPath();
C.addCommand(std::make_unique<Command>(JA, *this,
ResponseFileSupport::AtFileUTF8(),
Exec, CmdArgs, Inputs, Output));
>From b53d3cdef03c85e2ab5b81391cf61c32fdc026b4 Mon Sep 17 00:00:00 2001
From: Kelvin Li <kli at ca.ibm.com>
Date: Mon, 15 Jun 2026 12:46:25 -0400
Subject: [PATCH 3/3] address review comments
---
clang/lib/Driver/ToolChains/Flang.cpp | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 95e641112afb0..8243c041f95c0 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -1322,13 +1322,11 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
// Handle "clang --driver-mode=flang" case
bool isClangDriverWithFlangMode = false;
- if (D.Name.find("clang") != std::string_view::npos) {
- if (const Arg *A = Args.getLastArg(options::OPT_driver_mode)) {
- if (std::string_view(A->getValue()) == "flang") {
+ if (D.Name.find("clang") != std::string_view::npos)
+ if (const Arg *A = Args.getLastArg(options::OPT_driver_mode))
+ if (StringRef(A->getValue()) == "flang")
isClangDriverWithFlangMode = true;
- }
- }
- }
+
const char *Exec = isClangDriverWithFlangMode
? Args.MakeArgString(D.GetProgramPath("flang", TC))
: D.getDriverProgramPath();
More information about the flang-commits
mailing list