nickdesaulniers created this revision.
nickdesaulniers added reviewers: void, manojgupta.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nickdesaulniers requested review of this revision.

`-fno-stack-protector` now explicitly sets `-stack-protector 0` for the
invocation of cc1. In turn, -stack-protector 0 will set nossp IR fn attr
on all functions defined in the translation unit.

Fixes pr/47479.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90348

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/stack-protector.c


Index: clang/test/Driver/stack-protector.c
===================================================================
--- clang/test/Driver/stack-protector.c
+++ 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"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ 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;
   }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1594,7 +1594,8 @@
   if (!hasUnwindExceptions(LangOpts))
     B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (D && D->hasAttr<NoStackProtectorAttr>())
+  if (LangOpts.getStackProtector() == LangOptions::SSPOff ||
+      (D && D->hasAttr<NoStackProtectorAttr>()))
     B.addAttribute(llvm::Attribute::NoStackProtect);
   else if (LangOpts.getStackProtector() == LangOptions::SSPOn)
     B.addAttribute(llvm::Attribute::StackProtect);


Index: clang/test/Driver/stack-protector.c
===================================================================
--- clang/test/Driver/stack-protector.c
+++ 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"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ 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;
   }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1594,7 +1594,8 @@
   if (!hasUnwindExceptions(LangOpts))
     B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (D && D->hasAttr<NoStackProtectorAttr>())
+  if (LangOpts.getStackProtector() == LangOptions::SSPOff ||
+      (D && D->hasAttr<NoStackProtectorAttr>()))
     B.addAttribute(llvm::Attribute::NoStackProtect);
   else if (LangOpts.getStackProtector() == LangOptions::SSPOn)
     B.addAttribute(llvm::Attribute::StackProtect);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to