Author: jlebar Date: Sun Feb 19 13:05:32 2017 New Revision: 295609 URL: http://llvm.org/viewvc/llvm-project?rev=295609&view=rev Log: [CUDA] Don't pass -stack-protector to NVPTX compilations.
We can't support stack-protector on NVPTX because NVPTX doesn't expose a stack to the compiler! Fixes PR32009. Added: cfe/trunk/test/Driver/cuda-no-stack-protector.cu Modified: cfe/trunk/lib/Driver/Tools.cpp Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=295609&r1=295608&r2=295609&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Sun Feb 19 13:05:32 2017 @@ -5544,25 +5544,29 @@ void Clang::ConstructJob(Compilation &C, // -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"); Added: cfe/trunk/test/Driver/cuda-no-stack-protector.cu URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-no-stack-protector.cu?rev=295609&view=auto ============================================================================== --- cfe/trunk/test/Driver/cuda-no-stack-protector.cu (added) +++ cfe/trunk/test/Driver/cuda-no-stack-protector.cu Sun Feb 19 13:05:32 2017 @@ -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" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits