diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1594,7 +1594,8 @@ if (!hasUnwindExceptions(LangOpts)) B.addAttribute(llvm::Attribute::NoUnwind); - if (D && D->hasAttr()) + if (LangOpts.getStackProtector() == LangOptions::SSPOff || + (D && D->hasAttr())) B.addAttribute(llvm::Attribute::NoStackProtect); else if (LangOpts.getStackProtector() == LangOptions::SSPOn) B.addAttribute(llvm::Attribute::StackProtect); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3013,6 +3013,8 @@ StackProtectorLevel = LangOptions::SSPStrong; else if (A->getOption().matches(options::OPT_fstack_protector_all)) StackProtectorLevel = LangOptions::SSPReq; + else if (A->getOption().matches(options::OPT_fno_stack_protector)) + StackProtectorLevel = LangOptions::SSPOff; } else { StackProtectorLevel = DefaultStackProtectorLevel; } diff --git a/clang/test/Driver/stack-protector.c b/clang/test/Driver/stack-protector.c --- a/clang/test/Driver/stack-protector.c +++ b/clang/test/Driver/stack-protector.c @@ -1,6 +1,6 @@ // RUN: %clang -fno-stack-protector -### %s 2>&1 | FileCheck %s -check-prefix=NOSSP -// NOSSP-NOT: "-stack-protector" -// NOSSP-NOT: "-stack-protector-buffer-size" +// NOSSP: "-stack-protector" "0" +// NOSSP-NOT: "-stack-protector-buffer-size" // RUN: %clang -target i386-unknown-linux -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=SSP // SSP: "-stack-protector" "1"