[flang-commits] [clang] [flang] [Flang][Driver] Fix -foffload-device misspelling (PR #201857)

Michael Kruse via flang-commits flang-commits at lists.llvm.org
Fri Jun 5 08:22:30 PDT 2026


https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/201857

>From 115eb15ed7228ca7fc0571de70237ac1df56cf2d Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 5 Jun 2026 16:44:32 +0200
Subject: [PATCH] Put the 'f' prefix into -foffload-device

---
 clang/lib/Driver/ToolChains/Flang.cpp |  4 ++--
 flang/test/Driver/offload-device.f90  | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Driver/offload-device.f90

diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index ae9ae8176e281..a7e92254d2768 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -692,8 +692,8 @@ void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs,
 
   // Tell the frontend when it is compiling for an offloading device, regardless
   // of offloading programming model.
-  if (IsHostOffloadingAction)
-    CmdArgs.push_back("-offload-device");
+  if (JA.getOffloadingDeviceKind() > Action::OFK_Host)
+    CmdArgs.push_back("-foffload-device");
 
   // Skips the primary input file, which is the input file that the compilation
   // proccess will be executed upon (e.g. the host bitcode file) and
diff --git a/flang/test/Driver/offload-device.f90 b/flang/test/Driver/offload-device.f90
new file mode 100644
index 0000000000000..a5b2cbd10078a
--- /dev/null
+++ b/flang/test/Driver/offload-device.f90
@@ -0,0 +1,24 @@
+! -foffload-device tells the frontend we are compiling for the auxiliary target,
+! i.e. not the host device.
+
+! RUN: %flang -target aarch64-linux-gnu --offload-arch=sm_80 --offload-arch=gfx90a -### %s -fopenmp 2>&1 | FileCheck %s --check-prefixes=CHECK,OPENMP
+! RUN: %flang -target aarch64-linux-gnu --offload-arch=sm_80 -### -xcuda %s 2>&1 | FileCheck %s --check-prefixes=CHECK,CUDA
+
+! Compiled as CUDA, device-compilation is done first
+! CUDA: flang{{(\.exe)?}}" "-fc1" "-triple" "nvptx64-nvidia-cuda"
+! CUDA-SAME: "-foffload-device"
+
+! Host invocation
+! CHECK: flang{{(\.exe)?}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
+! CHECK-NOT: -foffload-device
+
+! Compiled as OpenMP, device-code is compiled after host-code compilation,
+! once for each --offload-arch argument
+! OPENMP: flang{{(\.exe)?}}" "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! OPENMP-SAME: "-foffload-device"
+! OPENMP: flang{{(\.exe)?}}" "-fc1" "-triple" "nvptx64-nvidia-cuda"
+! OPENMP-SAME: "-foffload-device"
+
+
+module device_modfile
+end module



More information about the flang-commits mailing list