Skip to content

Commit 1c8829a

Browse files
committed
[CUDA] pass -fno-threadsafe-statics to GPU sub-compilations.
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 #117023
1 parent c58c226 commit 1c8829a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
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
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Check that -fno-thread-safe-statics get passed down to device-side
2+
// compilation only.
3+
//
4+
// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s 2>&1 \
5+
// RUN: | FileCheck %s
6+
//
7+
// CHECK: "-fcuda-is-device"
8+
// CHECK-SAME: "-fno-threadsafe-statics"
9+
// CHECK: "-triple" "x86_64-unknown-linux-gnu"
10+
// CHECK-NOT: "-fno-threadsafe-statics"

0 commit comments

Comments
 (0)