[clang] [flang] [clang][Driver] Make the offload arch detection tool option visible to flang (PR #247265)

Ivan R. Ivanov via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 30 21:21:56 PST 2026


https://github.com/ivanradanov updated https://github.com/llvm/llvm-project/pull/247265

>From c001a13489420ea1abfd41d85f7739a42fb500b2 Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov <iivanov at nvidia.com>
Date: Mon, 30 Nov 2026 08:17:03 -0800
Subject: [PATCH 1/2] [clang][Driver] Make the offload arch detection tool
 option visible to flang

--offload-arch-tool= chooses the tool that detects the architecture of the GPUs
of the system, for --offload-arch=native and when no architecture is given. It
was only visible to the clang driver. Make it visible to flang, so that the
flang driver can be pointed at a tool, and tested without a GPU.

Assisted-by: Claude Sonnet 5.5
---
 clang/include/clang/Options/Options.td  |  1 +
 flang/test/Driver/offload-arch-tool.f90 | 30 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 flang/test/Driver/offload-arch-tool.f90

diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 9ff712eaa0e7fd..da24da89870fb6 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -1309,6 +1309,7 @@ def gpu_use_aux_triple_only : Flag<["--"], "gpu-use-aux-triple-only">,
   InternalDriverOpt, HelpText<"Prepare '-aux-triple' only without populating "
                               "'-aux-target-cpu' and '-aux-target-feature'.">;
 def offload_arch_tool_EQ : Joined<["--"], "offload-arch-tool=">,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Tool used for detecting offloading architectures in the system.">;
 def amdgpu_arch_tool_EQ : Joined<["--"], "amdgpu-arch-tool=">,
   Alias<offload_arch_tool_EQ>;
diff --git a/flang/test/Driver/offload-arch-tool.f90 b/flang/test/Driver/offload-arch-tool.f90
new file mode 100644
index 00000000000000..c5a4ad7f69e106
--- /dev/null
+++ b/flang/test/Driver/offload-arch-tool.f90
@@ -0,0 +1,30 @@
+! Test that the tools that detect the architecture of the GPUs of the system
+! can be given to the flang driver, like they can to the clang driver.
+
+! Needs chmod
+! UNSUPPORTED: system-windows
+! On macOS CI, running the fake arch tools can take longer than
+! CLANG_TOOLCHAIN_PROGRAM_TIMEOUT, see
+! https://github.com/llvm/llvm-project/issues/238903.
+! UNSUPPORTED: system-darwin
+! XFAIL: target={{.*}}-zos{{.*}}
+
+! RUN: rm -rf %t && mkdir -p %t
+! RUN: printf '#!/bin/sh\necho sm_70\n' > %t/arch_sm_70
+! RUN: printf '#!/bin/sh\nexit 1\n' > %t/arch_fail
+! RUN: chmod +x %t/arch_sm_70 %t/arch_fail
+
+! The architecture is detected with the given tool.
+! RUN: %flang -### -fopenmp --offload-arch=native \
+! RUN:   --offload-arch-tool=%t/arch_sm_70 \
+! RUN:   --target=x86_64-unknown-linux-gnu -nogpulib %s 2>&1 \
+! RUN:   | FileCheck %s --check-prefix=DETECTED
+! DETECTED: "-fc1" "-triple" "nvptx64-nvidia-cuda"
+! DETECTED-SAME: "-target-cpu" "sm_70"
+
+! The detection fails.
+! RUN: not %flang -### -fopenmp --offload-arch=native \
+! RUN:   --offload-arch-tool=%t/arch_fail \
+! RUN:   --target=x86_64-unknown-linux-gnu -nogpulib %s 2>&1 \
+! RUN:   | FileCheck %s --check-prefix=FAILED
+! FAILED: error: cannot determine {{.*}} architecture

>From f44514ad50636bf0e949cf180ce7b05062621bcf Mon Sep 17 00:00:00 2001
From: "Ivan R. Ivanov" <iivanov at nvidia.com>
Date: Tue, 1 Dec 2026 06:21:46 +0100
Subject: [PATCH 2/2] Update flang/test/Driver/offload-arch-tool.f90

Co-authored-by: Tarun Prabhu <tarun at lanl.gov>
---
 flang/test/Driver/offload-arch-tool.f90 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/test/Driver/offload-arch-tool.f90 b/flang/test/Driver/offload-arch-tool.f90
index c5a4ad7f69e106..550e4e9c269810 100644
--- a/flang/test/Driver/offload-arch-tool.f90
+++ b/flang/test/Driver/offload-arch-tool.f90
@@ -1,5 +1,5 @@
 ! Test that the tools that detect the architecture of the GPUs of the system
-! can be given to the flang driver, like they can to the clang driver.
+! can be given to the flang driver.
 
 ! Needs chmod
 ! UNSUPPORTED: system-windows



More information about the cfe-commits mailing list