Skip to content

Commit 689c532

Browse files
authored
[CUDA] pass -fno-threadsafe-statics to GPU sub-compilations. (llvm#117074)
We do not have support for the threadsafe statics on the GPU side. However, we do sometimes end up with empty local static initializers, and those happen to trigger calls to `__cxa_guard*`, which breaks compilation. Partially addresses llvm#117023
1 parent 4be09f0 commit 689c532

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,9 @@ void CudaToolChain::addClangTargetOptions(
856856
DeviceOffloadingKind == Action::OFK_Cuda) &&
857857
"Only OpenMP or CUDA offloading kinds are supported for NVIDIA GPUs.");
858858

859-
CC1Args.append(
860-
{"-fcuda-is-device", "-mllvm", "-enable-memcpyopt-without-libcalls"});
859+
CC1Args.append({"-fcuda-is-device", "-mllvm",
860+
"-enable-memcpyopt-without-libcalls",
861+
"-fno-threadsafe-statics"});
861862

862863
// Unsized function arguments used for variadics were introduced in CUDA-9.0
863864
// We still do not support generating code that actually uses variadic

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void HIPAMDToolChain::addClangTargetOptions(
238238
assert(DeviceOffloadingKind == Action::OFK_HIP &&
239239
"Only HIP offloading kinds are supported for GPUs.");
240240

241-
CC1Args.push_back("-fcuda-is-device");
241+
CC1Args.append({"-fcuda-is-device", "-fno-threadsafe-statics"});
242242

243243
if (!DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
244244
false))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Check that -fno-thread-safe-statics get passed down to device-side
2+
// compilation only.
3+
//
4+
// RUN: %clang -### -x cuda --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s \
5+
// RUN: -nocudainc -nocudalib 2>&1 | FileCheck %s
6+
7+
// RUN: %clang -### -x hip --target=x86_64-linux-gnu -c --cuda-gpu-arch=gfx1010 %s \
8+
// RUN: -nocudainc -nocudalib 2>&1 | FileCheck %s
9+
//
10+
// CHECK: "-fcuda-is-device"
11+
// CHECK-SAME: "-fno-threadsafe-statics"
12+
// CHECK: "-triple" "x86_64-unknown-linux-gnu"
13+
// CHECK-NOT: "-fno-threadsafe-statics"

0 commit comments

Comments
 (0)