================
@@ -4896,6 +4896,54 @@ void
Parser::ParseLexedTypeAttribute(LateParsedTypeAttribute &LA,
OutAttrs.takeAllAppendingFrom(Attrs);
}
+void Parser::CompleteLateParsedTypeAttributes(
+ SmallVectorImpl<LateParsedTypeAttribute *> &LateTypeAttrs) {
+ for (LateParsedTypeAttribute *LTA : LateTypeAttrs) {
+ // Read these out before parsing, which destroys the attribute. The type is
+ // null if construction rejected the attribute, in which case the
diagnostic
+ // has already been emitted and there is nothing to complete.
+ BoundsAttributedType *BATy = LTA->TypeToComplete;
+ // Rejected during construction (already diagnosed); the cached tokens are
+ // self-contained, so there is nothing to drain — just discard it.
+ if (!BATy) {
+ delete LTA;
+ continue;
+ }
+ // The fields were
+ // attached in ParseStructDeclaration as each declarator was completed;
more
+ // than one appears when several declarators share a
+ // declaration-specifier-position attribute.
+ SmallVector<Decl *, 2> Fields(LTA->Decls);
+
+ AttributeFactory AF;
+ ParsedAttributes Attrs(AF);
+ ParseLexedTypeAttribute(*LTA, Attrs);
+ delete LTA;
+
+ // An unparseable argument leaves no attribute behind; already diagnosed.
+ if (Attrs.empty())
+ continue;
+ assert(Attrs.size() == 1);
+
+ Expr *Arg = Attrs[0].getArgAsExpr(0);
+ assert(Arg);
+
+ // No field means the attribute never reached a field declarator (for
+ // instance the type was rejected during construction, which unwraps the
----------------
rapidsna wrote:
That's fair. I've turned the cases that shouldn't happen into assertions. Two
checks remain, both reachable from invalid code and already diagnosed:
-
[R4905](https://github.com/llvm/llvm-project/pull/224556/changes#diff-bf37b284dfa0a76af702a5493cde01dec7f88619533c1be15e74654862299770R4905):
Here, TypeToComplete is null when ActOnLateParsedTypeAttr rejected the
attribute's type.
-
[R4915](https://github.com/llvm/llvm-project/pull/224556/changes#diff-bf37b284dfa0a76af702a5493cde01dec7f88619533c1be15e74654862299770R4915):
Here, ParseLexedTypeAttribute returns Attrs empty if parsing the attribute was
rejected within the function. An alternative is to return an error condition
from ParseLexedTypeAttribute, but it just followed the ParseLexedAttribute
family's convention.
https://github.com/llvm/llvm-project/pull/224556
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits