[clang] [clang] Parse attribute [[gnu::no_stack_protector]] (PR #75289)

Sirui Mu via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 13 05:00:57 PST 2023


https://github.com/Lancern updated https://github.com/llvm/llvm-project/pull/75289

>From d8de529580101ba68dc1c981aec8711aa0c58da4 Mon Sep 17 00:00:00 2001
From: Sirui Mu <msrlancern at gmail.com>
Date: Wed, 13 Dec 2023 06:51:09 +0000
Subject: [PATCH 1/2] [clang] Parse attribute [[gnu::no_stack_protector]]

This commit adds relative TableGen definitions to parse the
[[gnu::no_stack_protector]] attribute.
---
 clang/include/clang/Basic/Attr.td | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 0d94ea2851c9ab..0344fa23e15369 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2212,7 +2212,8 @@ def NotTailCalled : InheritableAttr {
 def : MutualExclusions<[AlwaysInline, NotTailCalled]>;
 
 def NoStackProtector : InheritableAttr {
-  let Spellings = [Clang<"no_stack_protector">, Declspec<"safebuffers">];
+  let Spellings = [Clang<"no_stack_protector">, CXX11<"gnu", "no_stack_protector">,
+                   C23<"gnu", "no_stack_protector">, Declspec<"safebuffers">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [NoStackProtectorDocs];
   let SimpleHandler = 1;

>From 0efedf8a3af361077ccccc59174b008862cc8a0a Mon Sep 17 00:00:00 2001
From: Sirui Mu <msrlancern at gmail.com>
Date: Wed, 13 Dec 2023 14:29:12 +0800
Subject: [PATCH 2/2] [clang] Add unit tests for parsing
 [[gnu::no_stack_protector]]

---
 clang/test/Parser/gnu-attributes.c   | 4 ++++
 clang/test/Parser/gnu-attributes.cpp | 4 ++++
 2 files changed, 8 insertions(+)
 create mode 100644 clang/test/Parser/gnu-attributes.c
 create mode 100644 clang/test/Parser/gnu-attributes.cpp

diff --git a/clang/test/Parser/gnu-attributes.c b/clang/test/Parser/gnu-attributes.c
new file mode 100644
index 00000000000000..f75728915b685d
--- /dev/null
+++ b/clang/test/Parser/gnu-attributes.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s
+// expected-no-diagnostics
+
+[[gnu::no_stack_protector]] void test1(int i) {} // ok
diff --git a/clang/test/Parser/gnu-attributes.cpp b/clang/test/Parser/gnu-attributes.cpp
new file mode 100644
index 00000000000000..a1c3c7abe92ed8
--- /dev/null
+++ b/clang/test/Parser/gnu-attributes.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
+// expected-no-diagnostics
+
+[[gnu::no_stack_protector]] void test1(int i) {} // ok



More information about the cfe-commits mailing list