[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.

llvm-svn: 295609
This commit is contained in:
Justin Lebar 2017-02-19 19:05:32 +00:00
parent 4271186f9c
commit 63152d10c9
2 changed files with 46 additions and 19 deletions

View File

@ -5544,25 +5544,29 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// -stack-protector=0 is default. // -stack-protector=0 is default.
unsigned StackProtectorLevel = 0; unsigned StackProtectorLevel = 0;
if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, // NVPTX doesn't support stack protectors; from the compiler's perspective, it
options::OPT_fstack_protector_all, // doesn't even have a stack!
options::OPT_fstack_protector_strong, if (!Triple.isNVPTX()) {
options::OPT_fstack_protector)) { if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
if (A->getOption().matches(options::OPT_fstack_protector)) { options::OPT_fstack_protector_all,
StackProtectorLevel = std::max<unsigned>( options::OPT_fstack_protector_strong,
LangOptions::SSPOn, options::OPT_fstack_protector)) {
getToolChain().GetDefaultStackProtectorLevel(KernelOrKext)); if (A->getOption().matches(options::OPT_fstack_protector)) {
} else if (A->getOption().matches(options::OPT_fstack_protector_strong)) StackProtectorLevel = std::max<unsigned>(
StackProtectorLevel = LangOptions::SSPStrong; LangOptions::SSPOn,
else if (A->getOption().matches(options::OPT_fstack_protector_all)) getToolChain().GetDefaultStackProtectorLevel(KernelOrKext));
StackProtectorLevel = LangOptions::SSPReq; } else if (A->getOption().matches(options::OPT_fstack_protector_strong))
} else { StackProtectorLevel = LangOptions::SSPStrong;
StackProtectorLevel = else if (A->getOption().matches(options::OPT_fstack_protector_all))
getToolChain().GetDefaultStackProtectorLevel(KernelOrKext); StackProtectorLevel = LangOptions::SSPReq;
// Only use a default stack protector on Darwin in case -ffreestanding } else {
// is not specified. StackProtectorLevel =
if (Triple.isOSDarwin() && !IsHosted) getToolChain().GetDefaultStackProtectorLevel(KernelOrKext);
StackProtectorLevel = 0; // Only use a default stack protector on Darwin in case -ffreestanding
// is not specified.
if (Triple.isOSDarwin() && !IsHosted)
StackProtectorLevel = 0;
}
} }
if (StackProtectorLevel) { if (StackProtectorLevel) {
CmdArgs.push_back("-stack-protector"); CmdArgs.push_back("-stack-protector");

View File

@ -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"