Author: Michael Kruse
Date: 2026-06-06T15:33:11+02:00
New Revision: 7564cffdad802e80a595b2b3ce032fab7656df35

URL: 
https://github.com/llvm/llvm-project/commit/7564cffdad802e80a595b2b3ce032fab7656df35
DIFF: 
https://github.com/llvm/llvm-project/commit/7564cffdad802e80a595b2b3ce032fab7656df35.diff

LOG: [Flang][Driver] Fix -foffload-device misspelling (#201857)

#200863 added a new `-foffload-device` argument for informing the
frontend that it compiling for the device-side (and as a consequence
must not overwrite any module files compiled for the host), but the
driver was mistakenly adding `-offload-device`.

Also fix the condition and add a regression test for the driver.

Added: 
    flang/test/Driver/offload-device.f90

Modified: 
    clang/lib/Driver/ToolChains/Flang.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index ecdf5e46565b6..224ece3239efd 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -698,8 +698,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..2bab35ff93d5b
--- /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. Test for CUDA and OpenMP offloading modes.
+
+! RUN: %flang -target aarch64-linux-gnu --no-offloadlib --offload-arch=sm_80 
--offload-arch=gfx90a %s -fopenmp -### 2>&1 | FileCheck %s 
--check-prefixes=CHECK,OPENMP
+! RUN: %flang -target aarch64-linux-gnu --no-offloadlib --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 offload_device
+end module


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to