[PATCH] D31343: Add an attribute plugin example

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 27 12:23:25 PST 2020


aaron.ballman added inline comments.


================
Comment at: clang/examples/Attribute/Attribute.cpp:35
+  }
+  virtual bool handleDeclAttribute(Sema &S, Decl *D,
+                                   const ParsedAttr &Attr) const {
----------------
john.brawn wrote:
> aaron.ballman wrote:
> > It is unclear to me how a user would add an attribute that needs to follow the merge pattern we use in `mergeDeclAttribute()`.
> I'm guessing it's probably not possible, from a quick look at mergeDeclAttribute.
That... seems like a problem that we should fix (or at least have a plan for fixing). Merging attributes is important so that we can have attributes with consistency checks between declarations for anything other than basic attribute inheritance. FWIW, there are 20+ attributes that already need this functionality, so it does get used relatively often.


================
Comment at: clang/examples/Attribute/Attribute.cpp:35
+    Spellings.push_back({ParsedAttr::AS_GNU, "example"});
+    Spellings.push_back({ParsedAttr::AS_CXX11, "::example"});
+    Spellings.push_back({ParsedAttr::AS_CXX11, "plugin::example"});
----------------
This is not a valid spelling for an attribute (we should probably assert that an attribute-scoped-token does not have an empty scope).


================
Comment at: clang/examples/Attribute/Attribute.cpp:42
+    // This attribute appertains to functions only.
+    if (!D || !isa<FunctionDecl>(D)) {
+      S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type_str)
----------------
I don't think `D` can ever be null, can it?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D31343/new/

https://reviews.llvm.org/D31343





More information about the cfe-commits mailing list