aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorMartin Boehme <mboehme@google.com>2022-06-15 08:08:10 +0200
committerMartin Boehme <mboehme@google.com>2022-06-15 09:47:28 +0200
commit665da187ccf338bad1560e8a960e8feaebb5c9d9 (patch)
treebfcb0201061bcf086c66606bcb077e5ea76f28ab /clang/lib/Parse/ParseDecl.cpp
parent3151fb5ef7249d5d0a293daea6af756856800005 (diff)
downloadllvm-665da187ccf338bad1560e8a960e8feaebb5c9d9.zip
llvm-665da187ccf338bad1560e8a960e8feaebb5c9d9.tar.gz
llvm-665da187ccf338bad1560e8a960e8feaebb5c9d9.tar.bz2
[Clang] Add the `annotate_type` attribute
This is an analog to the `annotate` attribute but for types. The intent is to allow adding arbitrary annotations to types for use in static analysis tools. For details, see this RFC: https://discourse.llvm.org/t/rfc-new-attribute-annotate-type-iteration-2/61378 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D111548
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index a1a768b..12af519 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3176,10 +3176,23 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
if (!AttrsLastTime)
ProhibitAttributes(attrs);
else {
- // Reject C++11 attributes that appertain to decl specifiers as
- // we don't support any C++11 attributes that appertain to decl
- // specifiers. This also conforms to what g++ 4.8 is doing.
- ProhibitCXX11Attributes(attrs, diag::err_attribute_not_type_attr);
+ // Reject most C++11 / C2x attributes on the decl-specifier-seq, but
+ // allow `annotate_type` as a special case.
+ // FIXME: We should more generally allow type attributes to be placed
+ // on the decl-specifier-seq; https://reviews.llvm.org/D126061 will
+ // make this change.
+ for (const ParsedAttr &PA : attrs) {
+ if (!PA.isCXX11Attribute() && !PA.isC2xAttribute())
+ continue;
+ if (PA.getKind() == ParsedAttr::UnknownAttribute)
+ // We will warn about the unknown attribute elsewhere (in
+ // SemaDeclAttr.cpp)
+ continue;
+ if (PA.getKind() == ParsedAttr::AT_AnnotateType)
+ continue;
+ Diag(PA.getLoc(), diag::err_attribute_not_type_attr) << PA;
+ PA.setInvalid();
+ }
DS.takeAttributesFrom(attrs);
}