[CUDA] Don't try to run sanitizers on NVPTX.
authorJustin Lebar <jlebar@google.com>
Thu, 15 Sep 2016 23:44:13 +0000 (23:44 +0000)
committerJustin Lebar <jlebar@google.com>
Thu, 15 Sep 2016 23:44:13 +0000 (23:44 +0000)
Summary:
Sanitizers aren't supported on NVPTX -- don't try to run them.

This lets you e.g. pass -fsanitize=address and get asan on your host
code.

Reviewers: kcc

Subscribers: cfe-commits, tra, jhen

Differential Revision: https://reviews.llvm.org/D24640

llvm-svn: 281680

clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/cuda-no-sanitizers.cu [new file with mode: 0644]

index 8ba8e53..7f1f671 100644 (file)
@@ -608,6 +608,12 @@ static void addIncludeLinkerOption(const ToolChain &TC,
 void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
                             llvm::opt::ArgStringList &CmdArgs,
                             types::ID InputType) const {
+  // NVPTX doesn't currently support sanitizers.  Bailing out here means that
+  // e.g. -fsanitize=address applies only to host code, which is what we want
+  // for now.
+  if (TC.getTriple().isNVPTX())
+    return;
+
   // Translate available CoverageFeatures to corresponding clang-cc1 flags.
   // Do it even if Sanitizers.empty() since some forms of coverage don't require
   // sanitizers.
diff --git a/clang/test/Driver/cuda-no-sanitizers.cu b/clang/test/Driver/cuda-no-sanitizers.cu
new file mode 100644 (file)
index 0000000..e344f90
--- /dev/null
@@ -0,0 +1,12 @@
+// Check that -fsanitize=foo doesn't get passed down to device-side
+// compilation.
+//
+// REQUIRES: clang-driver
+//
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 -fsanitize=address %s 2>&1 | \
+// RUN:   FileCheck %s
+
+// CHECK-DAG: "-fcuda-is-device"
+// CHECK-NOT: "-fsanitize=address"
+// CHECK-DAG: "-triple" "x86_64--linux-gnu"
+// CHECK: "-fsanitize=address"