Skip to content

Commit 9109557

Browse files
committed
Remove placeholder attr name for annotation
Signed-off-by: acassagnes <acassagnes@bloomberg.net>
1 parent 3319fc6 commit 9109557

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

clang/include/clang/Basic/AttributeCommonInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class AttributeCommonInfo {
193193
return Form(getSyntax(), SpellingIndex, IsAlignas,
194194
IsRegularKeywordAttribute);
195195
}
196+
196197
const IdentifierInfo *getAttrName() const { return AttrName; }
197198
void setAttrName(const IdentifierInfo *AttrNameII) { AttrName = AttrNameII; }
198199
SourceLocation getLoc() const { return AttrRange.getBegin(); }

clang/include/clang/Sema/ParsedAttr.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,20 @@ class ParsedAttr final
216216
memcpy(getArgsBuffer(), args, numArgs * sizeof(ArgsUnion));
217217
}
218218

219+
/// Constructor for an annotation with expression argument
220+
ParsedAttr(SourceRange attrRange, AttributeScopeInfo scope, ArgsUnion *args,
221+
unsigned numArgs, Form formUsed, SourceLocation ellipsisLoc)
222+
: AttributeCommonInfo(attrRange, ParsedAttr::Kind::AT_CXX26Annotation,
223+
ParsedAttr::Form::Annotation()),
224+
EllipsisLoc(ellipsisLoc), NumArgs(numArgs), Invalid(false),
225+
UsedAsTypeAttr(false), IsAvailability(false),
226+
IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
227+
HasProcessingCache(false), IsPragmaClangAttribute(false),
228+
Info(ParsedAttrInfo::get(*this)) {
229+
assert(numArgs == 1);
230+
memcpy(getArgsBuffer(), args, sizeof(ArgsUnion));
231+
}
232+
219233
/// Constructor for availability attributes.
220234
ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange,
221235
AttributeScopeInfo scope, IdentifierLoc *Parm,
@@ -504,6 +518,7 @@ class ParsedAttr final
504518
/// error. Returns false if a diagnostic is produced.
505519
bool checkAtMostNumArgs(class Sema &S, unsigned Num) const;
506520

521+
bool isAnnotationAttr() const;
507522
bool isTargetSpecificAttr() const;
508523
bool isTypeAttr() const;
509524
bool isStmtAttr() const;
@@ -732,6 +747,22 @@ class AttributePool {
732747
/// them at the end of this \c AttributePool.
733748
void takeFrom(ParsedAttributesView &List, AttributePool &Pool);
734749

750+
// Create a Cxx26 annotation
751+
ParsedAttr *create(SourceRange attrRange, AttributeScopeInfo scope,
752+
ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form,
753+
SourceLocation ellipsisLoc = SourceLocation()) {
754+
// Only annotations are allowed to pass through without an identifier
755+
assert(form.getSyntax() == ParsedAttr::Syntax::AS_Annotation);
756+
757+
void *memory = allocate(
758+
ParsedAttr::totalSizeToAlloc<ArgsUnion, detail::AvailabilityData,
759+
detail::TypeTagForDatatypeData, ParsedType,
760+
detail::PropertyData>(numArgs, 0, 0, 0,
761+
0));
762+
return add(new (memory) ParsedAttr(attrRange, scope, args, numArgs, form,
763+
ellipsisLoc));
764+
}
765+
735766
ParsedAttr *create(IdentifierInfo *attrName, SourceRange attrRange,
736767
AttributeScopeInfo scope, ArgsUnion *args,
737768
unsigned numArgs, ParsedAttr::Form form,
@@ -974,6 +1005,16 @@ class ParsedAttributes : public ParsedAttributesView {
9741005
Range = SourceRange();
9751006
}
9761007

1008+
/// Add annotation with expression argument
1009+
ParsedAttr *addNew(SourceRange attrRange, AttributeScopeInfo scope,
1010+
ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form,
1011+
SourceLocation ellipsisLoc = SourceLocation()) {
1012+
ParsedAttr *attr =
1013+
pool.create(attrRange, scope, args, numArgs, form, ellipsisLoc);
1014+
addAtEnd(attr);
1015+
return attr;
1016+
}
1017+
9771018
/// Add attribute with expression arguments.
9781019
ParsedAttr *addNew(IdentifierInfo *attrName, SourceRange attrRange,
9791020
AttributeScopeInfo scope, ArgsUnion *args,

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4452,13 +4452,9 @@ void Parser::ParseAnnotationSpecifier(ParsedAttributes &Attrs,
44524452
if (AnnotExpr.isInvalid() || AnnotExpr.get()->containsErrors())
44534453
return;
44544454

4455-
IdentifierTable &IT = Actions.PP.getIdentifierTable();
4456-
IdentifierInfo &Placeholder = IT.get("__annotation_placeholder");
4457-
44584455
ArgsVector ArgExprs;
44594456
ArgExprs.push_back(AnnotExpr.get());
4460-
Attrs.addNew(&Placeholder, EqLoc, {}, ArgExprs.data(), 1,
4461-
ParsedAttr::Form::Annotation());
4457+
Attrs.addNew(EqLoc, {}, ArgExprs.data(), 1, ParsedAttr::Form::Annotation());
44624458

44634459
if (EndLoc)
44644460
*EndLoc = AnnotExpr.get()->getEndLoc();

clang/lib/Sema/ParsedAttr.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ bool ParsedAttr::isTargetSpecificAttr() const {
203203
return getInfo().IsTargetSpecific;
204204
}
205205

206+
bool ParsedAttr::isAnnotationAttr() const {
207+
return getParsedKind() == AT_CXX26Annotation;
208+
}
209+
206210
bool ParsedAttr::isTypeAttr() const { return getInfo().IsType; }
207211

208212
bool ParsedAttr::isStmtAttr() const { return getInfo().IsStmt; }
@@ -213,8 +217,8 @@ bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
213217
// If the attribute has a target-specific spelling, check that it exists.
214218
// Only call this if the attr is not ignored/unknown. For most targets, this
215219
// function just returns true.
216-
bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
217-
K != NoSemaHandlerAttribute;
220+
bool HasSpelling = !isAnnotationAttr() && K != IgnoredAttribute &&
221+
K != UnknownAttribute && K != NoSemaHandlerAttribute;
218222
bool TargetSpecificSpellingExists =
219223
!HasSpelling ||
220224
getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());

0 commit comments

Comments
 (0)