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

Sirui Mu via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 13 17:56:09 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/3] [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/3] [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

>From e9d2bcb0d6fc4ddf0acde5deed2096c6a515ab3c Mon Sep 17 00:00:00 2001
From: Sirui Mu <msrlancern at gmail.com>
Date: Thu, 14 Dec 2023 01:55:09 +0000
Subject: [PATCH 3/3] [clang] Move no_stack_protector parsing tests to
 test/Sema

---
 clang/test/Parser/gnu-attributes.c     | 4 ----
 clang/test/Parser/gnu-attributes.cpp   | 4 ----
 clang/test/Sema/no_stack_protector.c   | 5 ++++-
 clang/test/Sema/no_stack_protector.cpp | 5 +++++
 4 files changed, 9 insertions(+), 9 deletions(-)
 delete mode 100644 clang/test/Parser/gnu-attributes.c
 delete mode 100644 clang/test/Parser/gnu-attributes.cpp
 create mode 100644 clang/test/Sema/no_stack_protector.cpp

diff --git a/clang/test/Parser/gnu-attributes.c b/clang/test/Parser/gnu-attributes.c
deleted file mode 100644
index f75728915b685d..00000000000000
--- a/clang/test/Parser/gnu-attributes.c
+++ /dev/null
@@ -1,4 +0,0 @@
-// 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
deleted file mode 100644
index a1c3c7abe92ed8..00000000000000
--- a/clang/test/Parser/gnu-attributes.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-// 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
diff --git a/clang/test/Sema/no_stack_protector.c b/clang/test/Sema/no_stack_protector.c
index 0007435901e840..1ecd46bc624ceb 100644
--- a/clang/test/Sema/no_stack_protector.c
+++ b/clang/test/Sema/no_stack_protector.c
@@ -1,4 +1,7 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s
+
+[[gnu::no_stack_protector]] void test1(void) {}
+[[clang::no_stack_protector]] void test2(void) {}
 
 void __attribute__((no_stack_protector)) foo(void) {}
 int __attribute__((no_stack_protector)) var; // expected-warning {{'no_stack_protector' attribute only applies to functions}}
diff --git a/clang/test/Sema/no_stack_protector.cpp b/clang/test/Sema/no_stack_protector.cpp
new file mode 100644
index 00000000000000..160e3d32a9389a
--- /dev/null
+++ b/clang/test/Sema/no_stack_protector.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// expected-no-diagnostics
+
+[[gnu::no_stack_protector]] void test1() {}
+[[clang::no_stack_protector]] void test2() {}



More information about the cfe-commits mailing list