https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/102864

>From b0e53b1c8a687165fa28bd21200f83bf1b1a9234 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.taras...@outlook.com>
Date: Mon, 12 Aug 2024 13:56:30 +0300
Subject: [PATCH] [Clang] handle both gnu and cpp11 attributes to ensure
 correct parsing inside extern block

---
 clang/docs/ReleaseNotes.rst      | 1 +
 clang/lib/Parse/ParseDeclCXX.cpp | 5 ++++-
 clang/test/Parser/attr-order.cpp | 8 ++++++++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6796a619ba97f8..00a663fdd23454 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,7 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Clang now properly handles the order of attributes in `extern` blocks. 
(#GH101990).
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index aac89d910bbc83..d45a738fe4c596 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, 
DeclaratorContext Context) {
       [[fallthrough]];
     default:
       ParsedAttributes DeclAttrs(AttrFactory);
-      MaybeParseCXX11Attributes(DeclAttrs);
+      ParsedAttributes DeclSpecAttrs(AttrFactory);
+      while (MaybeParseCXX11Attributes(DeclAttrs) ||
+             MaybeParseGNUAttributes(DeclSpecAttrs))
+        ;
       ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
       continue;
     }
diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp
index 10bad38cac6447..369941ab24ee69 100644
--- a/clang/test/Parser/attr-order.cpp
+++ b/clang/test/Parser/attr-order.cpp
@@ -31,3 +31,11 @@ template <int a>
 
 template <int a>
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok
+
+extern "C" {
+  __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // 
ok
+  [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // 
ok
+}
+
+extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int 
n(int); // ok
+extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int 
o(int); // ok

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to