[PATCH] D102586: [Clang] Do not discard arguments for non-builtin CXX11-style attributes

Till Schnittka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 16 13:56:28 PDT 2021


Till created this revision.
Till requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When parsing unkown CXX11-style attributes, clang discards the
argument lists, propably to skip over non-c++ expressions.

However, it seems like this has not been updated for user-defined
attributes using the ParsedAttrInfoRegistry (e.G. in
clang/examples/Attribute/Attribute.cpp);
clang::hasAttribute only returns a version number for builtin
attributes.

This uses ParsedAttrInfo::get to check if an attribute is known
to the attribute registry, because this is currently the only
place where these attributes are instanciated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102586

Files:
  clang/lib/Parse/ParseDeclCXX.cpp


Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -4098,11 +4098,18 @@
   const LangOptions &LO = getLangOpts();
   ParsedAttr::Syntax Syntax =
       LO.CPlusPlus ? ParsedAttr::AS_CXX11 : ParsedAttr::AS_C2x;
+  bool IsKnownRegisteredAttribute =
+      ParsedAttrInfo::get(AttributeCommonInfo(AttrName, ScopeName,
+                                              SourceRange(LParenLoc, *EndLoc),
+                                              *EndLoc,
+                                              AttributeCommonInfo::AS_CXX11))
+          .AttrKind != AttributeCommonInfo::UnknownAttribute;
 
   // If the attribute isn't known, we will not attempt to parse any
   // arguments.
   if (!hasAttribute(LO.CPlusPlus ? AttrSyntax::CXX : AttrSyntax::C, ScopeName,
-                    AttrName, getTargetInfo(), getLangOpts())) {
+                    AttrName, getTargetInfo(), getLangOpts()) &&
+      !IsKnownRegisteredAttribute) {
     // Eat the left paren, then skip to the ending right paren.
     ConsumeParen();
     SkipUntil(tok::r_paren);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102586.345726.patch
Type: text/x-patch
Size: 1181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210516/6d007c56/attachment-0001.bin>


More information about the cfe-commits mailing list