[PATCH] D140507: Parse: handle another case of invalid handling for attributes
Saleem Abdulrasool via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 21 15:09:49 PST 2022
compnerd created this revision.
compnerd added a reviewer: aaron.ballman.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
compnerd requested review of this revision.
Herald added a project: clang.
clang would improperly disallow GNU attributes before C++ standard
attributes when a declaration had a linkage specifier. Handle this
similarly to the previous case of invalid parsing. We now better match
the parsing rules from GCC.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D140507
Files:
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/Parser/cxx-attributes.cpp
Index: clang/test/Parser/cxx-attributes.cpp
===================================================================
--- clang/test/Parser/cxx-attributes.cpp
+++ clang/test/Parser/cxx-attributes.cpp
@@ -3,6 +3,8 @@
// GH#58229 - rejects-valid
__attribute__((__visibility__("default"))) [[nodiscard]] int f();
[[nodiscard]] __attribute__((__visibility__("default"))) int f();
+extern "C" __attribute__((__visibility__("default"))) [[nodiscard]]
+int g() { return 32; }
class c {
virtual void f1(const char* a, ...)
Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -359,8 +359,11 @@
Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation());
ParsedAttributes DeclAttrs(AttrFactory);
- MaybeParseCXX11Attributes(DeclAttrs);
- ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
+ ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+ while (MaybeParseCXX11Attributes(DeclAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+ ;
if (Tok.isNot(tok::l_brace)) {
// Reset the source range in DS, as the leading "extern"
@@ -369,7 +372,7 @@
DS.SetRangeEnd(SourceLocation());
// ... but anyway remember that such an "extern" was seen.
DS.setExternInLinkageSpec(true);
- ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs, &DS);
+ ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs, &DS);
return LinkageSpec ? Actions.ActOnFinishLinkageSpecification(
getCurScope(), LinkageSpec, SourceLocation())
: nullptr;
@@ -411,7 +414,7 @@
default:
ParsedAttributes DeclAttrs(AttrFactory);
MaybeParseCXX11Attributes(DeclAttrs);
- ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
+ ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
continue;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140507.484691.patch
Type: text/x-patch
Size: 1939 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221221/87fb8bf6/attachment-0001.bin>
More information about the cfe-commits
mailing list