[PATCH] D99877: [Clang] Allow processing of attributes on statements by plugins

2021-04-22 Thread Josh Junon via Phabricator via cfe-commits
Qix- abandoned this revision.
Qix- added a comment.

Closing in favor of more complete plugin attribute changes discussed in IRC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99877

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99877: [Clang] Allow processing of attributes on statements by plugins

2021-04-08 Thread Josh Junon via Phabricator via cfe-commits
Qix- updated this revision to Diff 336172.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99877

Files:
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Sema/SemaStmtAttr.cpp


Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -430,11 +430,12 @@
   case ParsedAttr::AT_Unlikely:
 return handleUnlikely(S, St, A, Range);
   default:
-// N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
-// declaration attribute is not written on a statement, but this code is
-// needed for attributes in Attr.td that do not list any subjects.
-S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
-<< A << St->getBeginLoc();
+if (A.getInfo().handleStmtAttribute(S, St, A) == 
ParsedAttrInfo::NotHandled)
+  // N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
+  // declaration attribute is not written on a statement, but this code is
+  // needed for attributes in Attr.td that do not list any subjects.
+  S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
+  << A << St->getBeginLoc();
 return nullptr;
   }
 }
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -117,6 +117,13 @@
const ParsedAttr ) const {
 return NotHandled;
   }
+  /// If this ParsedAttrInfo knows how to handle this ParsedAttr applied to 
this
+  /// Stmt then do so and return either AttributeApplied if it was applied or
+  /// AttributeNotApplied if it wasn't. Otherwise return NotHandled.
+  virtual AttrHandling handleStmtAttribute(Sema , Stmt *St,
+   const ParsedAttr ) const {
+return NotHandled;
+  }
 
   static const ParsedAttrInfo (const AttributeCommonInfo );
 };


Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -430,11 +430,12 @@
   case ParsedAttr::AT_Unlikely:
 return handleUnlikely(S, St, A, Range);
   default:
-// N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
-// declaration attribute is not written on a statement, but this code is
-// needed for attributes in Attr.td that do not list any subjects.
-S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
-<< A << St->getBeginLoc();
+if (A.getInfo().handleStmtAttribute(S, St, A) == ParsedAttrInfo::NotHandled)
+  // N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
+  // declaration attribute is not written on a statement, but this code is
+  // needed for attributes in Attr.td that do not list any subjects.
+  S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
+  << A << St->getBeginLoc();
 return nullptr;
   }
 }
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -117,6 +117,13 @@
const ParsedAttr ) const {
 return NotHandled;
   }
+  /// If this ParsedAttrInfo knows how to handle this ParsedAttr applied to this
+  /// Stmt then do so and return either AttributeApplied if it was applied or
+  /// AttributeNotApplied if it wasn't. Otherwise return NotHandled.
+  virtual AttrHandling handleStmtAttribute(Sema , Stmt *St,
+   const ParsedAttr ) const {
+return NotHandled;
+  }
 
   static const ParsedAttrInfo (const AttributeCommonInfo );
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99877: [Clang] Allow processing of attributes on statements by plugins

2021-04-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for the patch! Btw, can you add more context to the patch when you 
generate it (I usually use `-U 999` when making patches)?

The changes look good so far, but I think `docs\ClangPlugins.rst` should be 
updated to document the new functionality and it would be nice to add example 
usage (in lieu of tests) to `examples\Attribute`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99877

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99877: [Clang] Allow processing of attributes on statements by plugins

2021-04-05 Thread Josh Junon via Phabricator via cfe-commits
Qix- created this revision.
Qix- added a reviewer: aaron.ballman.
Qix- added a project: clang.
Qix- requested review of this revision.
Herald added a subscriber: cfe-commits.

Pretty cut and dry; currently plugins can create attributes for declarations 
but any that are not recognized produce a diagnostic, leaving no hook for 
plugins to react to them.

This adds a quick check to the attribute to see if the implementation would 
like to handle it first, akin to how declarations are handled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99877

Files:
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Sema/SemaStmtAttr.cpp


Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -430,11 +430,12 @@
   case ParsedAttr::AT_Unlikely:
 return handleUnlikely(S, St, A, Range);
   default:
-// N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
-// declaration attribute is not written on a statement, but this code is
-// needed for attributes in Attr.td that do not list any subjects.
-S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
-<< A << St->getBeginLoc();
+if (A.getInfo().handleStmtAttribute(S, St, A) == 
ParsedAttrInfo::NotHandled)
+  // N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
+  // declaration attribute is not written on a statement, but this code is
+  // needed for attributes in Attr.td that do not list any subjects.
+  S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
+  << A << St->getBeginLoc();
 return nullptr;
   }
 }
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -117,6 +117,13 @@
const ParsedAttr ) const {
 return NotHandled;
   }
+  /// If this ParsedAttrInfo knows how to handle this ParsedAttr applied to 
this
+  /// Stmt then do so and return either AttributeApplied if it was applied or
+  /// AttributeNotApplied if it wasn't. Otherwise return NotHandled.
+  virtual AttrHandling handleStmtAttribute(Sema , Stmt *St,
+   const ParsedAttr ) const {
+return NotHandled;
+  }

   static const ParsedAttrInfo (const AttributeCommonInfo );
 };


Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -430,11 +430,12 @@
   case ParsedAttr::AT_Unlikely:
 return handleUnlikely(S, St, A, Range);
   default:
-// N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
-// declaration attribute is not written on a statement, but this code is
-// needed for attributes in Attr.td that do not list any subjects.
-S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
-<< A << St->getBeginLoc();
+if (A.getInfo().handleStmtAttribute(S, St, A) == ParsedAttrInfo::NotHandled)
+  // N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
+  // declaration attribute is not written on a statement, but this code is
+  // needed for attributes in Attr.td that do not list any subjects.
+  S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
+  << A << St->getBeginLoc();
 return nullptr;
   }
 }
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -117,6 +117,13 @@
const ParsedAttr ) const {
 return NotHandled;
   }
+  /// If this ParsedAttrInfo knows how to handle this ParsedAttr applied to this
+  /// Stmt then do so and return either AttributeApplied if it was applied or
+  /// AttributeNotApplied if it wasn't. Otherwise return NotHandled.
+  virtual AttrHandling handleStmtAttribute(Sema , Stmt *St,
+   const ParsedAttr ) const {
+return NotHandled;
+  }

   static const ParsedAttrInfo (const AttributeCommonInfo );
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits