]> granicus.if.org Git - clang/commitdiff
[CUDA] Don't pass -stack-protector to NVPTX compilations.
authorJustin Lebar <jlebar@google.com>
Sun, 19 Feb 2017 19:05:32 +0000 (19:05 +0000)
committerJustin Lebar <jlebar@google.com>
Sun, 19 Feb 2017 19:05:32 +0000 (19:05 +0000)
We can't support stack-protector on NVPTX because NVPTX doesn't expose a
stack to the compiler!

Fixes PR32009.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295609 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/cuda-no-stack-protector.cu [new file with mode: 0644]

index bc0796ff2a75d6211914f1b9ea7db6e5c0d7a5d7..9a8eebcc9aec166734904fff97dc5b2f57c60042 100644 (file)
@@ -5544,25 +5544,29 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
 
   // -stack-protector=0 is default.
   unsigned StackProtectorLevel = 0;
-  if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
-                               options::OPT_fstack_protector_all,
-                               options::OPT_fstack_protector_strong,
-                               options::OPT_fstack_protector)) {
-    if (A->getOption().matches(options::OPT_fstack_protector)) {
-      StackProtectorLevel = std::max<unsigned>(
-          LangOptions::SSPOn,
-          getToolChain().GetDefaultStackProtectorLevel(KernelOrKext));
-    } else if (A->getOption().matches(options::OPT_fstack_protector_strong))
-      StackProtectorLevel = LangOptions::SSPStrong;
-    else if (A->getOption().matches(options::OPT_fstack_protector_all))
-      StackProtectorLevel = LangOptions::SSPReq;
-  } else {
-    StackProtectorLevel =
-        getToolChain().GetDefaultStackProtectorLevel(KernelOrKext);
-    // Only use a default stack protector on Darwin in case -ffreestanding
-    // is not specified.
-    if (Triple.isOSDarwin() && !IsHosted)
-      StackProtectorLevel = 0;
+  // NVPTX doesn't support stack protectors; from the compiler's perspective, it
+  // doesn't even have a stack!
+  if (!Triple.isNVPTX()) {
+    if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
+                                 options::OPT_fstack_protector_all,
+                                 options::OPT_fstack_protector_strong,
+                                 options::OPT_fstack_protector)) {
+      if (A->getOption().matches(options::OPT_fstack_protector)) {
+        StackProtectorLevel = std::max<unsigned>(
+            LangOptions::SSPOn,
+            getToolChain().GetDefaultStackProtectorLevel(KernelOrKext));
+      } else if (A->getOption().matches(options::OPT_fstack_protector_strong))
+        StackProtectorLevel = LangOptions::SSPStrong;
+      else if (A->getOption().matches(options::OPT_fstack_protector_all))
+        StackProtectorLevel = LangOptions::SSPReq;
+    } else {
+      StackProtectorLevel =
+          getToolChain().GetDefaultStackProtectorLevel(KernelOrKext);
+      // Only use a default stack protector on Darwin in case -ffreestanding
+      // is not specified.
+      if (Triple.isOSDarwin() && !IsHosted)
+        StackProtectorLevel = 0;
+    }
   }
   if (StackProtectorLevel) {
     CmdArgs.push_back("-stack-protector");
diff --git a/test/Driver/cuda-no-stack-protector.cu b/test/Driver/cuda-no-stack-protector.cu
new file mode 100644 (file)
index 0000000..f94cc18
--- /dev/null
@@ -0,0 +1,23 @@
+// Check that -stack-protector 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 \
+// RUN:   -fstack-protector-all %s 2>&1 | \
+// RUN: FileCheck %s
+//
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
+// RUN:   -fstack-protector-strong %s 2>&1 | \
+// RUN: FileCheck %s
+//
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
+// RUN:   -fstack-protector %s 2>&1 | \
+// RUN: FileCheck %s
+//
+// CHECK-NOT: error: unsupported option '-fstack-protector
+// CHECK-DAG: "-fcuda-is-device"
+// CHECK-NOT: "-stack-protector"
+// CHECK-NOT: "-stack-protector-buffer-size"
+// CHECK-DAG: "-triple" "x86_64--linux-gnu"
+// CHECK: "-stack-protector"