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 &Attr) 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 &S, Stmt *St,
+ const ParsedAttr &Attr) const {
+ return NotHandled;
+ }
static const ParsedAttrInfo &get(const AttributeCommonInfo &A);
};
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 &Attr) 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 &S, Stmt *St,
+ const ParsedAttr &Attr) const {
+ return NotHandled;
+ }
static const ParsedAttrInfo &get(const AttributeCommonInfo &A);
};
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits