Skip to content

[Flang][Driver] Fix -foffload-device misspelling#201857

Merged
Meinersbur merged 2 commits into
llvm:mainfrom
Meinersbur:flang_driver_foffload-device
Jun 6, 2026
Merged

[Flang][Driver] Fix -foffload-device misspelling#201857
Meinersbur merged 2 commits into
llvm:mainfrom
Meinersbur:flang_driver_foffload-device

Conversation

@Meinersbur
Copy link
Copy Markdown
Member

@Meinersbur Meinersbur commented Jun 5, 2026

#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.

@Meinersbur Meinersbur requested a review from jhuber6 June 5, 2026 15:03
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

🐧 Linux x64 Test Results

  • 122894 tests passed
  • 5024 tests skipped

✅ The build succeeded and all tests passed.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

🪟 Windows x64 Test Results

  • 60051 tests passed
  • 2882 tests skipped

✅ The build succeeded and all tests passed.

@Meinersbur Meinersbur force-pushed the flang_driver_foffload-device branch from 8c1fd56 to 115eb15 Compare June 5, 2026 15:22
@Meinersbur Meinersbur marked this pull request as ready for review June 5, 2026 20:56
@llvmorg-github-actions llvmorg-github-actions Bot added clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' flang:driver flang Flang issues not falling into any other category labels Jun 5, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-flang-driver

Author: Michael Kruse (Meinersbur)

Changes

#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.


Full diff: https://github.com/llvm/llvm-project/pull/201857.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2-2)
  • (added) flang/test/Driver/offload-device.f90 (+24)
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..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

@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-clang-driver

Author: Michael Kruse (Meinersbur)

Changes

#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.


Full diff: https://github.com/llvm/llvm-project/pull/201857.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2-2)
  • (added) flang/test/Driver/offload-device.f90 (+24)
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..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

@Meinersbur Meinersbur merged commit 7564cff into llvm:main Jun 6, 2026
15 checks passed
Meinersbur added a commit to ROCm/llvm-project that referenced this pull request Jun 8, 2026
llvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' flang:driver flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants