[PATCH] D23042: [CUDA] Do not allow using NVPTX target for host compilation.
Artem Belevich via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 1 17:25:32 PDT 2016
tra created this revision.
tra added a reviewer: jlebar.
tra added a subscriber: cfe-commits.
It does not make sense and violates enough assumptions in the code to crash compiler.
https://reviews.llvm.org/D23042
Files:
include/clang/Basic/DiagnosticDriverKinds.td
lib/Driver/ToolChains.cpp
lib/Driver/Tools.cpp
test/Driver/cuda-bad-arch.cu
test/Preprocessor/cuda-types.cu
Index: test/Preprocessor/cuda-types.cu
===================================================================
--- test/Preprocessor/cuda-types.cu
+++ test/Preprocessor/cuda-types.cu
@@ -19,9 +19,3 @@
// RUN: grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF\|WIDTH\)' %T/powerpc64-host-defines | grep -v '__LDBL\|_LONG_DOUBLE' > %T/powerpc64-host-defines-filtered
// RUN: grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF\|WIDTH\)' %T/powerpc64-device-defines | grep -v '__LDBL\|_LONG_DOUBLE' > %T/powerpc64-device-defines-filtered
// RUN: diff %T/powerpc64-host-defines-filtered %T/powerpc64-device-defines-filtered
-
-// RUN: %clang --cuda-host-only -nocudainc -target nvptx-nvidia-cuda -x cuda -E -dM -o - /dev/null > %T/nvptx-host-defines
-// RUN: %clang --cuda-device-only -nocudainc -target nvptx-nvidia-cuda -x cuda -E -dM -o - /dev/null > %T/nvptx-device-defines
-// RUN: grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF\|WIDTH\)' %T/nvptx-host-defines | grep -v '__LDBL\|_LONG_DOUBLE' > %T/nvptx-host-defines-filtered
-// RUN: grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF\|WIDTH\)' %T/nvptx-device-defines | grep -v '__LDBL\|_LONG_DOUBLE' > %T/nvptx-device-defines-filtered
-// RUN: diff %T/nvptx-host-defines-filtered %T/nvptx-device-defines-filtered
Index: test/Driver/cuda-bad-arch.cu
===================================================================
--- test/Driver/cuda-bad-arch.cu
+++ test/Driver/cuda-bad-arch.cu
@@ -19,4 +19,9 @@
// RUN: %clang -### -target x86_64-linux-gnu -c %s 2>&1 \
// RUN: | FileCheck -check-prefix OK %s
+// We don't allow using NVPTX for host compilation.
+// RUN: %clang -### --cuda-host-only -target nvptx-nvidia-cuda -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix HOST_NVPTX %s
+
// OK-NOT: error: Unsupported CUDA gpu architecture
+// HOST_NVPTX: error: unsupported use of NVPTX for host compilation.
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -11248,7 +11248,10 @@
assert(TC.getTriple().isNVPTX() && "Wrong platform");
// Obtain architecture from the action.
- CudaArch gpu_arch = StringToCudaArch(JA.getOffloadingArch());
+ const char *ArchName = JA.getOffloadingArch();
+ if (ArchName == nullptr)
+ return; // Bail out. Driver has already reported the error.
+ CudaArch gpu_arch = StringToCudaArch(ArchName);
assert(gpu_arch != CudaArch::UNKNOWN &&
"Device action expected to have an architecture.");
Index: lib/Driver/ToolChains.cpp
===================================================================
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -4779,7 +4779,8 @@
if (!DriverArgs.hasArg(options::OPT_nocudainc) &&
!DriverArgs.hasArg(options::OPT_no_cuda_version_check)) {
StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
- assert(!Arch.empty() && "Must have an explicit GPU arch.");
+ if (Arch.empty())
+ return; // Driver has already reported the error.
CudaInstallation.CheckCudaVersionSupportsArch(StringToCudaArch(Arch));
}
Linux::AddCudaIncludeArgs(DriverArgs, CC1Args);
@@ -4828,6 +4829,8 @@
if (BoundArch) {
DAL->eraseArg(options::OPT_march_EQ);
DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch);
+ } else {
+ getDriver().Diag(diag::err_drv_cuda_nvptx_host);
}
return DAL;
}
Index: include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -30,6 +30,7 @@
"GPU arch %1 requires CUDA version at least %3, but installation at %0 is %2. "
"Use --cuda-path to specify a different CUDA install, or pass "
"--no-cuda-version-check.">;
+def err_drv_cuda_nvptx_host : Error<"unsupported use of NVPTX for host compilation.">;
def err_drv_invalid_thread_model_for_target : Error<
"invalid thread model '%0' in '%1' for this target">;
def err_drv_invalid_linker_name : Error<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23042.66405.patch
Type: text/x-patch
Size: 4032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160802/53a7952e/attachment-0001.bin>
More information about the cfe-commits
mailing list