[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-05-20 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,39 @@
+// Check that -fcf-protection does not get passed to the device-side

MaskRay wrote:

We also have unsupported-option-gpu.c to test various ignored options for GPU.

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

I'm wondering if it would be better to make this something that the toolchains 
handle in `TranslateArgs`. That way we can prevent it from being added at all. 
Although I don't know how that would allow us to override stuff. There's not 
really a way to "override" flags like this if we ignore it at all. We could 
"assume" that if someone does `-Xarch_device -foo` they want the device to use 
it, but that's not really what the flag means.

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Artem Belevich via cfe-commits


@@ -6867,8 +6867,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-nogpulib");
 
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
-CmdArgs.push_back(
-Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
+// Do not pass this argument to the offloading device if the target does 
not
+// support it.
+// TODO: We need a better way to detect incompatible options for 
offloading.
+if (JA.getOffloadingDeviceKind() == Action::OFK_None ||
+(!TC.getTriple().isAMDGPU() && !TC.getTriple().isNVPTX() &&
+ !TC.getTriple().isSPIRV()))

Artem-B wrote:

+1. We have grown too many offloading cases all over the place over time. It 
was fine when there was only CUDA/NVPTX, was sort of OK when AMDGPU got added, 
now it gets to be a bit too much.

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B commented:

LGTM in principle.

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B edited 
https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Artem Belevich via cfe-commits


@@ -6867,8 +6867,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-nogpulib");
 
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
-CmdArgs.push_back(
-Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
+// Do not pass this argument to the offloading device if the target does 
not
+// support it.
+// TODO: We need a better way to detect incompatible options for 
offloading.
+if (JA.getOffloadingDeviceKind() == Action::OFK_None ||
+(!TC.getTriple().isAMDGPU() && !TC.getTriple().isNVPTX() &&

Artem-B wrote:

Nit: I'd collapse negations into one:

```
!(TC.getTriple().isAMDGPU() || TC.getTriple().isNVPTX() || 
TC.getTriple().isSPIRV())
```

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Matt Arsenault via cfe-commits


@@ -6867,8 +6867,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-nogpulib");
 
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
-CmdArgs.push_back(
-Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
+// Do not pass this argument to the offloading device if the target does 
not
+// support it.
+// TODO: We need a better way to detect incompatible options for 
offloading.
+if (JA.getOffloadingDeviceKind() == Action::OFK_None ||
+(!TC.getTriple().isAMDGPU() && !TC.getTriple().isNVPTX() &&
+ !TC.getTriple().isSPIRV()))

arsenm wrote:

It is 100% better 

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,39 @@
+// Check that -fcf-protection does not get passed to the device-side
+// compilation.
+
+// RUN: %clang -### -x cuda --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=sm_52 -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CUDA
+
+// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-NOT: "-fcf-protection=full"
+// CUDA: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// CUDA: "-fcf-protection=full"
+
+// RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=HIP
+
+// HIP: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// HIP-NOT: "-fcf-protection=full"
+// HIP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// HIP: "-fcf-protection=full"
+

jhuber6 wrote:

I don't know how that would be possible. We have options like `-Xarch_device`, 
but those are stripped by the time we create the synthetic arguments that make 
it to the tool builder. Potentially we could do this logic where we build the 
args and just prevent the offloading toolchain from seeing it at all?

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Joseph Huber via cfe-commits


@@ -6867,8 +6867,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-nogpulib");
 
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
-CmdArgs.push_back(
-Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
+// Do not pass this argument to the offloading device if the target does 
not
+// support it.
+// TODO: We need a better way to detect incompatible options for 
offloading.
+if (JA.getOffloadingDeviceKind() == Action::OFK_None ||
+(!TC.getTriple().isAMDGPU() && !TC.getTriple().isNVPTX() &&
+ !TC.getTriple().isSPIRV()))

jhuber6 wrote:

I mean we could potentially just have some toolchain check like 
`isToolchainGPU`, but I don't know if that's exactly any better.

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,39 @@
+// Check that -fcf-protection does not get passed to the device-side
+// compilation.
+
+// RUN: %clang -### -x cuda --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=sm_52 -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CUDA
+
+// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-NOT: "-fcf-protection=full"
+// CUDA: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// CUDA: "-fcf-protection=full"
+
+// RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=HIP
+
+// HIP: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// HIP-NOT: "-fcf-protection=full"
+// HIP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// HIP: "-fcf-protection=full"
+
+// RUN: %clang -### -x c --target=x86_64-unknown-linux-gnu -nogpulib 
-fopenmp=libomp \
+// RUN:   -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=OMP
+
+// OMP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// OMP: "-fcf-protection=full"
+// OMP: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// OMP-NOT: "-fcf-protection=full"
+// OMP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// OMP: "-fcf-protection=full"
+
+// RUN: %clang -### -x c --target=nvptx64-nvidia-cuda -nogpulib -nogpuinc \
+// RUN:   -march=sm_52 -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=DIRECT
+// RUN: %clang -### -x c --target=amdgcn-amd-amdhsa -nogpulib -nogpuinc \
+// RUN:   -mcpu=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=DIRECT
+// DIRECT: "-fcf-protection=full"

arsenm wrote:

Missing spirv run lines 

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,39 @@
+// Check that -fcf-protection does not get passed to the device-side
+// compilation.
+
+// RUN: %clang -### -x cuda --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=sm_52 -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CUDA
+
+// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-NOT: "-fcf-protection=full"
+// CUDA: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// CUDA: "-fcf-protection=full"
+
+// RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=HIP
+
+// HIP: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// HIP-NOT: "-fcf-protection=full"
+// HIP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// HIP: "-fcf-protection=full"
+

arsenm wrote:

Can you check explicitly passing this through to the device? 

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-12 Thread Matt Arsenault via cfe-commits


@@ -6867,8 +6867,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-nogpulib");
 
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
-CmdArgs.push_back(
-Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
+// Do not pass this argument to the offloading device if the target does 
not
+// support it.
+// TODO: We need a better way to detect incompatible options for 
offloading.
+if (JA.getOffloadingDeviceKind() == Action::OFK_None ||
+(!TC.getTriple().isAMDGPU() && !TC.getTriple().isNVPTX() &&
+ !TC.getTriple().isSPIRV()))

arsenm wrote:

Can we avoid adding yet another one of these arbitrary architecture list cases 

https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-11 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/88402

>From 9b9cbaa09425a706eaf3bb8e85a824ef89b61a9f Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 11 Apr 2024 10:36:15 -0500
Subject: [PATCH] [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: https://github.com/llvm/llvm-project/issues/86450
---
 clang/lib/Driver/ToolChains/Clang.cpp | 10 -
 clang/test/Driver/hip-options.hip |  8 ++--
 clang/test/Driver/offload-no-fcf-protection.c | 39 +++
 3 files changed, 51 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/Driver/offload-no-fcf-protection.c

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 766a9b91e3c0ad..1264ffa1ef7c8e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6867,8 +6867,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-nogpulib");
 
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
-CmdArgs.push_back(
-Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
+// Do not pass this argument to the offloading device if the target does 
not
+// support it.
+// TODO: We need a better way to detect incompatible options for 
offloading.
+if (JA.getOffloadingDeviceKind() == Action::OFK_None ||
+(!TC.getTriple().isAMDGPU() && !TC.getTriple().isNVPTX() &&
+ !TC.getTriple().isSPIRV()))
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
diff --git a/clang/test/Driver/hip-options.hip 
b/clang/test/Driver/hip-options.hip
index 2ba9032f16946b..679f3084ace14e 100644
--- a/clang/test/Driver/hip-options.hip
+++ b/clang/test/Driver/hip-options.hip
@@ -43,10 +43,10 @@
 // MLLVM-NOT: 
"-mllvm"{{.*}}"-amdgpu-early-inline-all=true"{{.*}}"-mllvm"{{.*}}"-amdgpu-early-inline-all=true"
 
 // RUN: %clang -### -Xarch_device -g -nogpulib -nogpuinc 
--cuda-gpu-arch=gfx900 \
-// RUN:   -Xarch_device -fcf-protection=branch -Xarch_device 
-mllvm=--inline-threshold=100 \
+// RUN:   -Xarch_device -mllvm=--inline-threshold=100 \
 // RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=DEV %s
-// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" 
{{.*}} "-fcf-protection=branch" {{.*}}"-mllvm" "--inline-threshold=100"
-// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" 
{{.*}} "-fcf-protection=branch" {{.*}}"-mllvm" "--inline-threshold=100"
+// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} 
"-debug-info-kind={{.*}}"{{.*}}"-mllvm" "--inline-threshold=100"
+// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} 
"-debug-info-kind={{.*}}"{{.*}}"-mllvm" "--inline-threshold=100"
 // DEV-NOT: clang{{.*}} {{.*}} "-debug-info-kind={{.*}}"
 
 // RUN: %clang -### -Xarch_host -g -nogpulib -nogpuinc --cuda-gpu-arch=gfx900 \
@@ -244,4 +244,4 @@
 // RUN:   2>&1 | FileCheck -check-prefix=NO-WARN-ATOMIC %s
 // NO-WARN-ATOMIC: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} 
"-Werror=atomic-alignment" {{.*}} "-Wno-error=atomic-alignment"
 // NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-Werror=atomic-alignment"
-// NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-Wno-error=atomic-alignment"
\ No newline at end of file
+// NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-Wno-error=atomic-alignment"
diff --git a/clang/test/Driver/offload-no-fcf-protection.c 
b/clang/test/Driver/offload-no-fcf-protection.c
new file mode 100644
index 00..ef275881edbaf1
--- /dev/null
+++ b/clang/test/Driver/offload-no-fcf-protection.c
@@ -0,0 +1,39 @@
+// Check that -fcf-protection does not get passed to the device-side
+// compilation.
+
+// RUN: %clang -### -x cuda --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=sm_52 -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CUDA
+
+// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-NOT: "-fcf-protection=full"
+// CUDA: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// CUDA: "-fcf-protection=full"
+
+// RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=HIP
+
+// HIP: "-cc1" "-

[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-11 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Joseph Huber (jhuber6)


Changes

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.

Fixes: https://github.com/llvm/llvm-project/issues/86450


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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+8-2) 
- (added) clang/test/Driver/offload-no-fcf-protection.c (+39) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 766a9b91e3c0ad..1264ffa1ef7c8e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6867,8 +6867,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-nogpulib");
 
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
-CmdArgs.push_back(
-Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
+// Do not pass this argument to the offloading device if the target does 
not
+// support it.
+// TODO: We need a better way to detect incompatible options for 
offloading.
+if (JA.getOffloadingDeviceKind() == Action::OFK_None ||
+(!TC.getTriple().isAMDGPU() && !TC.getTriple().isNVPTX() &&
+ !TC.getTriple().isSPIRV()))
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
diff --git a/clang/test/Driver/offload-no-fcf-protection.c 
b/clang/test/Driver/offload-no-fcf-protection.c
new file mode 100644
index 00..ef275881edbaf1
--- /dev/null
+++ b/clang/test/Driver/offload-no-fcf-protection.c
@@ -0,0 +1,39 @@
+// Check that -fcf-protection does not get passed to the device-side
+// compilation.
+
+// RUN: %clang -### -x cuda --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=sm_52 -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CUDA
+
+// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-NOT: "-fcf-protection=full"
+// CUDA: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// CUDA: "-fcf-protection=full"
+
+// RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=HIP
+
+// HIP: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// HIP-NOT: "-fcf-protection=full"
+// HIP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// HIP: "-fcf-protection=full"
+
+// RUN: %clang -### -x c --target=x86_64-unknown-linux-gnu -nogpulib 
-fopenmp=libomp \
+// RUN:   -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=OMP
+
+// OMP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// OMP: "-fcf-protection=full"
+// OMP: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// OMP-NOT: "-fcf-protection=full"
+// OMP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// OMP: "-fcf-protection=full"
+
+// RUN: %clang -### -x c --target=nvptx64-nvidia-cuda -nogpulib -nogpuinc \
+// RUN:   -march=sm_52 -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=DIRECT
+// RUN: %clang -### -x c --target=amdgcn-amd-amdhsa -nogpulib -nogpuinc \
+// RUN:   -mcpu=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=DIRECT
+// DIRECT: "-fcf-protection=full"

``




https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-11 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 edited 
https://github.com/llvm/llvm-project/pull/88402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Offload] Do not pass `-fcf-protection=` for offloading (PR #88402)

2024-04-11 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/88402

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: https://github.com/llvm/llvm-project/issues/86450


>From e228f8bb81bd44bc3c76d0d61836f068612a9d1e Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 11 Apr 2024 10:36:15 -0500
Subject: [PATCH] [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: https://github.com/llvm/llvm-project/issues/86450
---
 clang/lib/Driver/ToolChains/Clang.cpp | 10 -
 clang/test/Driver/offload-no-fcf-protection.c | 39 +++
 2 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/offload-no-fcf-protection.c

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 766a9b91e3c0ad..1264ffa1ef7c8e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6867,8 +6867,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-nogpulib");
 
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
-CmdArgs.push_back(
-Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
+// Do not pass this argument to the offloading device if the target does 
not
+// support it.
+// TODO: We need a better way to detect incompatible options for 
offloading.
+if (JA.getOffloadingDeviceKind() == Action::OFK_None ||
+(!TC.getTriple().isAMDGPU() && !TC.getTriple().isNVPTX() &&
+ !TC.getTriple().isSPIRV()))
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
diff --git a/clang/test/Driver/offload-no-fcf-protection.c 
b/clang/test/Driver/offload-no-fcf-protection.c
new file mode 100644
index 00..ef275881edbaf1
--- /dev/null
+++ b/clang/test/Driver/offload-no-fcf-protection.c
@@ -0,0 +1,39 @@
+// Check that -fcf-protection does not get passed to the device-side
+// compilation.
+
+// RUN: %clang -### -x cuda --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=sm_52 -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CUDA
+
+// CUDA: "-cc1" "-triple" "nvptx64-nvidia-cuda"
+// CUDA-NOT: "-fcf-protection=full"
+// CUDA: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// CUDA: "-fcf-protection=full"
+
+// RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu -nogpulib \
+// RUN:   -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=HIP
+
+// HIP: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// HIP-NOT: "-fcf-protection=full"
+// HIP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// HIP: "-fcf-protection=full"
+
+// RUN: %clang -### -x c --target=x86_64-unknown-linux-gnu -nogpulib 
-fopenmp=libomp \
+// RUN:   -nogpuinc --offload-arch=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=OMP
+
+// OMP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// OMP: "-fcf-protection=full"
+// OMP: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// OMP-NOT: "-fcf-protection=full"
+// OMP: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// OMP: "-fcf-protection=full"
+
+// RUN: %clang -### -x c --target=nvptx64-nvidia-cuda -nogpulib -nogpuinc \
+// RUN:   -march=sm_52 -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=DIRECT
+// RUN: %clang -### -x c --target=amdgcn-amd-amdhsa -nogpulib -nogpuinc \
+// RUN:   -mcpu=gfx90a -fcf-protection=full -c %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=DIRECT
+// DIRECT: "-fcf-protection=full"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits