Skip to content

Commit 72a957b

Browse files
authored
[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.
1 parent e637a5c commit 72a957b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,10 @@ void CudaToolChain::addClangTargetOptions(
848848
if (CudaInstallation.version() >= CudaVersion::CUDA_90)
849849
CC1Args.push_back("-fcuda-allow-variadic-functions");
850850

851+
if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
852+
options::OPT_fno_cuda_short_ptr, false))
853+
CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
854+
851855
if (DriverArgs.hasArg(options::OPT_nogpulib))
852856
return;
853857

@@ -873,10 +877,6 @@ void CudaToolChain::addClangTargetOptions(
873877

874878
clang::CudaVersion CudaInstallationVersion = CudaInstallation.version();
875879

876-
if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
877-
options::OPT_fno_cuda_short_ptr, false))
878-
CC1Args.append({"-mllvm", "--nvptx-short-ptr"});
879-
880880
if (CudaInstallationVersion >= CudaVersion::UNKNOWN)
881881
CC1Args.push_back(
882882
DriverArgs.MakeArgString(Twine("-target-sdk-version=") +

clang/test/Driver/cuda-short-ptr.cu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Checks that cuda compilation does the right thing when passed -fcuda-short-ptr
2+
3+
// 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
4+
5+
// CHECK: "-mllvm" "--nvptx-short-ptr"
6+
// CHECK-SAME: "-fcuda-short-ptr"

0 commit comments

Comments
 (0)