[clang] 72a957b - [Cuda] Handle -fcuda-short-ptr even with -nocudalib (#111682)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 9 08:17:46 PDT 2024
Author: Fraser Cormack
Date: 2024-10-09T16:17:43+01:00
New Revision: 72a957ba4c8ef059f1572f6d4ee0cba8dc615268
URL: https://github.com/llvm/llvm-project/commit/72a957ba4c8ef059f1572f6d4ee0cba8dc615268
DIFF: https://github.com/llvm/llvm-project/commit/72a957ba4c8ef059f1572f6d4ee0cba8dc615268.diff
LOG: [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.
Added:
clang/test/Driver/cuda-short-ptr.cu
Modified:
clang/lib/Driver/ToolChains/Cuda.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index 509cd87b28c37e..7a70cf1c5694fd 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 00000000000000..e0ae4505e0b567
--- /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"
More information about the cfe-commits
mailing list