[clang] Allow the no_stack_protector attribute on local variables (PR #173311)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 6 11:12:38 PST 2026


================
@@ -2726,7 +2726,7 @@ def : MutualExclusions<[AlwaysInline, NotTailCalled]>;
 def NoStackProtector : InheritableAttr {
   let Spellings = [Clang<"no_stack_protector">, CXX11<"gnu", "no_stack_protector">,
                    C23<"gnu", "no_stack_protector">, Declspec<"safebuffers">];
-  let Subjects = SubjectList<[Function]>;
+  let Subjects = SubjectList<[Function, LocalVar]>;
----------------
AaronBallman wrote:

GCC does not appear to support this behavior: https://godbolt.org/z/ef1zWrEn9
MSVC does not appear to support this behavior either: https://godbolt.org/z/hK4ezrTfv

Do you know if either of those projects intend to allow this on a local variable as well? If not, I would expect to see `SimpleHandler` removed here and code added to SemaDeclAttr.cpp to reject a local variable when those spellings are used.

The hard problem is what to do with `__attribute__((no_stack_protector))` because that's somewhere between GCC and Clang in terms of who "owns" its behavior. I think it's probably fine to extend the functionality there, but with a GCC-compat warning. WDYT @erichkeane ?

https://github.com/llvm/llvm-project/pull/173311


More information about the cfe-commits mailing list