aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFraser Cormack <fraser@codeplay.com>2024-10-09 16:17:43 +0100
committerGitHub <noreply@github.com>2024-10-09 16:17:43 +0100
commit72a957ba4c8ef059f1572f6d4ee0cba8dc615268 (patch)
tree964a910dc70c42fe8cb54afc110648e1bbd247b7
parente637a5c9fef866158018dcaecc3c385d157460f5 (diff)
downloadllvm-72a957ba4c8ef059f1572f6d4ee0cba8dc615268.zip
llvm-72a957ba4c8ef059f1572f6d4ee0cba8dc615268.tar.gz
llvm-72a957ba4c8ef059f1572f6d4ee0cba8dc615268.tar.bz2
[Cuda] Handle -fcuda-short-ptr even with -nocudalib (#111682)
When passed -nocudalib/-nogpulib, Cuda's argument handling would bail out before handling -fcuda-short-ptr, meaning the frontend and backend data layouts would mismatch.
-rw-r--r--clang/lib/Driver/ToolChains/Cuda.cpp8
-rw-r--r--clang/test/Driver/cuda-short-ptr.cu6
2 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index 509cd87..7a70cf1 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -848,6 +848,10 @@ void CudaToolChain::addClangTargetOptions(
if (CudaInstallation.version() >= CudaVersion::CUDA_90)
CC1Args.push_back("-fcuda-allow-variadic-functions");
+ if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
+ options::OPT_fno_cuda_short_ptr, false))
+ CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
+
if (DriverArgs.hasArg(options::OPT_nogpulib))
return;
@@ -873,10 +877,6 @@ void CudaToolChain::addClangTargetOptions(
clang::CudaVersion CudaInstallationVersion = CudaInstallation.version();
- if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
- options::OPT_fno_cuda_short_ptr, false))
- CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
-
if (CudaInstallationVersion >= CudaVersion::UNKNOWN)
CC1Args.push_back(
DriverArgs.MakeArgString(Twine("-target-sdk-version=") +
diff --git a/clang/test/Driver/cuda-short-ptr.cu b/clang/test/Driver/cuda-short-ptr.cu
new file mode 100644
index 0000000..e0ae450
--- /dev/null
+++ b/clang/test/Driver/cuda-short-ptr.cu
@@ -0,0 +1,6 @@
+// Checks that cuda compilation does the right thing when passed -fcuda-short-ptr
+
+// RUN: %clang -### --target=x86_64-linux-gnu -c -march=haswell --cuda-gpu-arch=sm_20 -fcuda-short-ptr -nocudainc -nocudalib --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 | FileCheck %s
+
+// CHECK: "-mllvm" "--nvptx-short-ptr"
+// CHECK-SAME: "-fcuda-short-ptr"