Skip to content

Commit 7564cff

Browse files
authored
[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.
1 parent 3ca2f00 commit 7564cff

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,8 @@ void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs,
698698

699699
// Tell the frontend when it is compiling for an offloading device, regardless
700700
// of offloading programming model.
701-
if (IsHostOffloadingAction)
702-
CmdArgs.push_back("-offload-device");
701+
if (JA.getOffloadingDeviceKind() > Action::OFK_Host)
702+
CmdArgs.push_back("-foffload-device");
703703

704704
// Skips the primary input file, which is the input file that the compilation
705705
// proccess will be executed upon (e.g. the host bitcode file) and
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
! -foffload-device tells the frontend we are compiling for the auxiliary target,
2+
! i.e. not the host device. Test for CUDA and OpenMP offloading modes.
3+
4+
! 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
5+
! RUN: %flang -target aarch64-linux-gnu --no-offloadlib --offload-arch=sm_80 -xcuda %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK,CUDA
6+
7+
! Compiled as CUDA, device-compilation is done first
8+
! CUDA: flang{{(\.exe)?}}" "-fc1" "-triple" "nvptx64-nvidia-cuda"
9+
! CUDA-SAME: "-foffload-device"
10+
11+
! Host invocation
12+
! CHECK: flang{{(\.exe)?}}" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
13+
! CHECK-NOT: -foffload-device
14+
15+
! Compiled as OpenMP, device-code is compiled after host-code compilation,
16+
! once for each --offload-arch argument
17+
! OPENMP: flang{{(\.exe)?}}" "-fc1" "-triple" "amdgcn-amd-amdhsa"
18+
! OPENMP-SAME: "-foffload-device"
19+
! OPENMP: flang{{(\.exe)?}}" "-fc1" "-triple" "nvptx64-nvidia-cuda"
20+
! OPENMP-SAME: "-foffload-device"
21+
22+
23+
module offload_device
24+
end module

0 commit comments

Comments
 (0)