llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Daniel Petrovic (daniel-petrovic) <details> <summary>Changes</summary> Parse leading GNU and standard attributes in namespace scope using the same loop as global declarations. Previously, a standard attribute following a GNU attribute was rejected with "an attribute list cannot appear here". Fixes #<!-- -->240537. --- Full diff: https://github.com/llvm/llvm-project/pull/240734.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.md (+3) - (modified) clang/lib/Parse/ParseDeclCXX.cpp (+5-3) - (modified) clang/test/Parser/attr-order.cpp (+16) ``````````diff diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index ae351da057cc8d..2a3ba538d24027 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -926,6 +926,9 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and #### Bug Fixes to Attribute Support +- Fixed rejection of standard attributes following GNU attributes on + declarations inside namespaces. (#GH240537) + - Fixed a crash when using a zero-argument call to an undeclared `__CFStringMakeConstantString` as a format string. (#GH225034) diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index d78a630d0805f8..c7135b2ff9ba6d 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -227,9 +227,11 @@ void Parser::ParseInnerNamespace(const InnerNamespaceInfoList &InnerNSs, while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); - ParsedAttributes EmptyDeclSpecAttrs(AttrFactory); - ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs); + ParsedAttributes DeclSpecAttrs(AttrFactory); + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) + ; + ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); } // The caller is what called check -- we are simply calling diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 21e30e5b6f9df1..5d94f493ddbf80 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -44,3 +44,19 @@ extern "C" { extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int p(int); // ok extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int q(int); // ok + +// Mixed GNU and standard attributes also work in namespace scope (GH240537). +namespace { +__attribute__((section(".bss"))) [[maybe_unused]] int x; +[[maybe_unused]] __attribute__((section(".bss"))) int y; +__attribute__((section(".bss"))) [[maybe_unused]] +__attribute__((aligned(16))) [[]] int z; +static_assert(__alignof__(z) == 16, "GNU attributes must be preserved"); +} + +namespace N { +__attribute__((warn_unused_result)) [[maybe_unused]] int f(); +[[maybe_unused]] __attribute__((warn_unused_result)) int g(); +[[maybe_unused]] __attribute__((warn_unused_result)) [[]] +__attribute__((nothrow)) [[nodiscard]] int h(); +} `````````` </details> https://github.com/llvm/llvm-project/pull/240734 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
