[clang] 6cbd96e - [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (#102864)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 15 11:42:42 PDT 2024
Author: Oleksandr T.
Date: 2024-08-15T14:42:39-04:00
New Revision: 6cbd96e24c6a60cbc3dbb849d2ed7afc39c77a80
URL: https://github.com/llvm/llvm-project/commit/6cbd96e24c6a60cbc3dbb849d2ed7afc39c77a80
DIFF: https://github.com/llvm/llvm-project/commit/6cbd96e24c6a60cbc3dbb849d2ed7afc39c77a80.diff
LOG: [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (#102864)
Fixes #101990
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/Parser/attr-order.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5ba9fcb040e3a6..68cf79928bda02 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -257,6 +257,7 @@ Bug Fixes to C++ Support
- Properly reject defaulted relational operators with invalid types for explicit object parameters,
e.g., ``bool operator==(this int, const Foo&)`` (#GH100329), and rvalue reference parameters.
- Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter.
+- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990).
- Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025).
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..21e30e5b6f9df1 100644
--- a/clang/test/Parser/attr-order.cpp
+++ b/clang/test/Parser/attr-order.cpp
@@ -31,3 +31,16 @@ 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
+ __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] static int o (int x) { return x; }; // ok
+}
+
+extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int p(int); // ok
+extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int q(int); // ok
More information about the cfe-commits
mailing list