[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 12 01:58:18 PDT 2024
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/102864
Fixes #101990
>From d08d3f318ff64b1c7ff06ac3183c8b83de4021ed Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Mon, 12 Aug 2024 11:55:52 +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
More information about the cfe-commits
mailing list