Skip to content

Commit e228f8b

Browse files
committed
[Offload] Do not pass -fcf-protection= for offloading
Summary: This patch prevents the `-fcf-protection=` flag from being passed to the device compilation during offloading. This is not supported on CUDA and AMD devices, but if the user is compiling with fcf protection for the host it will fail to compile. We have a lot of these cases with various hacked together solutions, it would be nice to have a single solution to detect from the driver if a feature like this can be used for offloading, but for now this should resolve the issue. Fixe: #86450
1 parent fad1470 commit e228f8b

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6867,8 +6867,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
68676867
CmdArgs.push_back("-nogpulib");
68686868

68696869
if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
6870-
CmdArgs.push_back(
6871-
Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
6870+
// Do not pass this argument to the offloading device if the target does not
6871+
// support it.
6872+
// TODO: We need a better way to detect incompatible options for offloading.
6873+
if (JA.getOffloadingDeviceKind() == Action::OFK_None ||
6874+
(!TC.getTriple().isAMDGPU() && !TC.getTriple().isNVPTX() &&
6875+
!TC.getTriple().isSPIRV()))
6876+
CmdArgs.push_back(
6877+
Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
68726878
}
68736879

68746880
if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Check that -fcf-protection does not get passed to the device-side
2+
// compilation.
3+
4+
// RUN: %clang -### -x cuda --target=x86_64-unknown-linux-gnu -nogpulib \
5+
// RUN: -nogpuinc --offload-arch=sm_52 -fcf-protection=full -c %s 2>&1 \
6+
// RUN: | FileCheck %s --check-prefix=CUDA
7+
8+
// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda"
9+
// CUDA-NOT: "-fcf-protection=full"
10+
// CUDA: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
11+
// CUDA: "-fcf-protection=full"
12+
13+
// RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu -nogpulib \
14+
// RUN: -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
15+
// RUN: | FileCheck %s --check-prefix=HIP
16+
17+
// HIP: "-cc1" "-triple" "amdgcn-amd-amdhsa"
18+
// HIP-NOT: "-fcf-protection=full"
19+
// HIP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
20+
// HIP: "-fcf-protection=full"
21+
22+
// RUN: %clang -### -x c --target=x86_64-unknown-linux-gnu -nogpulib -fopenmp=libomp \
23+
// RUN: -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
24+
// RUN: | FileCheck %s --check-prefix=OMP
25+
26+
// OMP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
27+
// OMP: "-fcf-protection=full"
28+
// OMP: "-cc1" "-triple" "amdgcn-amd-amdhsa"
29+
// OMP-NOT: "-fcf-protection=full"
30+
// OMP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
31+
// OMP: "-fcf-protection=full"
32+
33+
// RUN: %clang -### -x c --target=nvptx64-nvidia-cuda -nogpulib -nogpuinc \
34+
// RUN: -march=sm_52 -fcf-protection=full -c %s 2>&1 \
35+
// RUN: | FileCheck %s --check-prefix=DIRECT
36+
// RUN: %clang -### -x c --target=amdgcn-amd-amdhsa -nogpulib -nogpuinc \
37+
// RUN: -mcpu=gfx90a -fcf-protection=full -c %s 2>&1 \
38+
// RUN: | FileCheck %s --check-prefix=DIRECT
39+
// DIRECT: "-fcf-protection=full"

0 commit comments

Comments
 (0)