@@ -1298,9 +1298,11 @@ static void takeDeclAttributes(ParsedAttributes &attrs,
12981298// / '(' objc-type-qualifiers[opt] type-name ')'
12991299// / '(' objc-type-qualifiers[opt] ')'
13001300// /
1301+ // / TO_UPSTREAM(BoundsSafety) Added LateParsedAttrs
13011302ParsedType Parser::ParseObjCTypeName (ObjCDeclSpec &DS,
13021303 DeclaratorContext context,
1303- ParsedAttributes *paramAttrs) {
1304+ ParsedAttributes *paramAttrs,
1305+ LateParsedAttrList *LateParsedAttrs) {
13041306 assert (context == DeclaratorContext::ObjCParameter ||
13051307 context == DeclaratorContext::ObjCResult);
13061308 assert ((paramAttrs != nullptr ) ==
@@ -1325,9 +1327,10 @@ ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS,
13251327 DeclSpecContext dsContext = DeclSpecContext::DSC_normal;
13261328 if (context == DeclaratorContext::ObjCResult)
13271329 dsContext = DeclSpecContext::DSC_objc_method_result;
1328- ParseSpecifierQualifierList (declSpec, AS_none, dsContext);
1330+ ParseSpecifierQualifierList (declSpec, AS_none, dsContext, LateParsedAttrs );
13291331 Declarator declarator (declSpec, ParsedAttributesView::none (), context);
13301332 ParseDeclarator (declarator);
1333+ DistributeCLateParsedAttrs (declarator, nullptr , LateParsedAttrs);
13311334
13321335 // If that's not invalid, extract a type.
13331336 if (!declarator.isInvalidType ()) {
@@ -1406,17 +1409,25 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
14061409 return nullptr ;
14071410 }
14081411
1412+ /* TO_UPSTREAM(BoundsSafety) ON */
1413+ LateParsedAttrList LateParsedAttrs (/* PSoon=*/ true ,
1414+ /* LateAttrParseExperimentalExtOnly=*/ true );
1415+ LateParsedAttrList LateParsedReturnAttrs (
1416+ /* PSoon=*/ false ,
1417+ /* LateAttrParseExperimentalExtOnly=*/ true );
1418+ /* TO_UPSTREAM(BoundsSafety) OFF */
1419+
14091420 // Parse the return type if present.
14101421 ParsedType ReturnType;
14111422 ObjCDeclSpec DSRet;
14121423 if (Tok.is (tok::l_paren))
1413- ReturnType =
1414- ParseObjCTypeName (DSRet, DeclaratorContext::ObjCResult, nullptr );
1424+ ReturnType = ParseObjCTypeName (DSRet, DeclaratorContext::ObjCResult,
1425+ nullptr , &LateParsedReturnAttrs );
14151426
14161427 // If attributes exist before the method, parse them.
14171428 ParsedAttributes methodAttrs (AttrFactory);
14181429 MaybeParseAttributes (PAKM_CXX11 | (getLangOpts ().ObjC ? PAKM_GNU : 0 ),
1419- methodAttrs);
1430+ methodAttrs, &LateParsedReturnAttrs );
14201431
14211432 if (Tok.is (tok::code_completion)) {
14221433 cutOffParsing ();
@@ -1450,33 +1461,51 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
14501461 selLoc, Sel, nullptr , CParamInfo.data (), CParamInfo.size (), methodAttrs,
14511462 MethodImplKind, false , MethodDefinition);
14521463 PD.complete (Result);
1464+ /* TO_UPSTREAM(BoundsSafety) ON */
1465+ if (Result) {
1466+ for (auto *LateAttr : LateParsedReturnAttrs) {
1467+ // there are no parameters with late attrs to parse
1468+ assert (LateAttr->Decls .empty ());
1469+ LateAttr->addDecl (Result);
1470+ ParseLexedCAttribute (*LateAttr, true );
1471+ }
1472+ }
1473+ /* TO_UPSTREAM(BoundsSafety) OFF */
14531474 return Result;
14541475 }
14551476
14561477 SmallVector<const IdentifierInfo *, 12 > KeyIdents;
14571478 SmallVector<SourceLocation, 12 > KeyLocs;
14581479 SmallVector<SemaObjC::ObjCArgInfo, 12 > ArgInfos;
1480+ /* TO_UPSTREAM(BoundsSafety) ON */
1481+ SmallVector<LateParsedAttrList, 12 > LateParamAttrs;
1482+ /* TO_UPSTREAM(BoundsSafety) OFF */
14591483 ParseScope PrototypeScope (this , Scope::FunctionPrototypeScope |
14601484 Scope::FunctionDeclarationScope | Scope::DeclScope);
14611485
14621486 AttributePool allParamAttrs (AttrFactory);
14631487 while (true ) {
14641488 ParsedAttributes paramAttrs (AttrFactory);
14651489 SemaObjC::ObjCArgInfo ArgInfo;
1490+ /* TO_UPSTREAM(BoundsSafety) ON */
1491+ LateParsedAttrList LateAttrs (/* PSoon*/ false ,
1492+ /* LateAttrParseExperimentalExtOnly*/ true );
1493+ /* TO_UPSTREAM(BoundsSafety) OFF */
14661494
14671495 // Each iteration parses a single keyword argument.
14681496 if (ExpectAndConsume (tok::colon))
14691497 break ;
14701498
14711499 ArgInfo.Type = nullptr ;
14721500 if (Tok.is (tok::l_paren)) // Parse the argument type if present.
1473- ArgInfo.Type = ParseObjCTypeName (
1474- ArgInfo.DeclSpec , DeclaratorContext::ObjCParameter, ¶mAttrs);
1501+ ArgInfo.Type =
1502+ ParseObjCTypeName (ArgInfo.DeclSpec , DeclaratorContext::ObjCParameter,
1503+ ¶mAttrs, &LateAttrs);
14751504
14761505 // If attributes exist before the argument name, parse them.
14771506 // Regardless, collect all the attributes we've parsed so far.
14781507 MaybeParseAttributes (PAKM_CXX11 | (getLangOpts ().ObjC ? PAKM_GNU : 0 ),
1479- paramAttrs);
1508+ paramAttrs, &LateAttrs );
14801509 ArgInfo.ArgAttrs = paramAttrs;
14811510
14821511 // Code completion for the next piece of the selector.
@@ -1497,6 +1526,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
14971526 ConsumeToken (); // Eat the identifier.
14981527
14991528 ArgInfos.push_back (ArgInfo);
1529+ LateParamAttrs.push_back (LateAttrs); // TO_UPSTREAM(BoundsSafety)
15001530 KeyIdents.push_back (SelIdent);
15011531 KeyLocs.push_back (selLoc);
15021532
@@ -1543,13 +1573,23 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
15431573 }
15441574 DeclSpec DS (AttrFactory);
15451575 ParsedTemplateInfo TemplateInfo;
1546- ParseDeclarationSpecifiers (DS, TemplateInfo);
1576+ ParseDeclarationSpecifiers (
1577+ DS, TemplateInfo,
1578+ /* AccessSpecifier AS */ AS_none,
1579+ /* DeclSpecContext DSC */ DeclSpecContext::DSC_normal,
1580+ &LateParsedAttrs);
15471581 // Parse the declarator.
15481582 Declarator ParmDecl (DS, ParsedAttributesView::none (),
15491583 DeclaratorContext::Prototype);
15501584 ParseDeclarator (ParmDecl);
15511585 const IdentifierInfo *ParmII = ParmDecl.getIdentifier ();
15521586 Decl *Param = Actions.ActOnParamDeclarator (getCurScope (), ParmDecl);
1587+ /* TO_UPSTREAM(BoundsSafety) ON */
1588+ // This will add Param to any late attrs that do not already have an
1589+ // assigned decl, so it's important that other late attrs are not mixed
1590+ // in to LateParsedAttrs without a decl at this point
1591+ DistributeCLateParsedAttrs (ParmDecl, Param, &LateParsedAttrs);
1592+ /* TO_UPSTREAM(BoundsSafety) OFF */
15531593 CParamInfo.push_back (DeclaratorChunk::ParamInfo (ParmII,
15541594 ParmDecl.getIdentifierLoc (),
15551595 Param,
@@ -1561,9 +1601,18 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
15611601 // instance, if a method declares a parameter called "id", that parameter must
15621602 // not shadow the "id" type.)
15631603 SmallVector<ParmVarDecl *, 12 > ObjCParamInfo;
1564- for (auto &ArgInfo : ArgInfos) {
1604+ for (const auto &[ ArgInfo, LateAttrs] : llvm::zip ( ArgInfos, LateParamAttrs) ) {
15651605 ParmVarDecl *Param = Actions.ObjC ().ActOnMethodParmDeclaration (
15661606 getCurScope (), ArgInfo, ObjCParamInfo.size (), MethodDefinition);
1607+ /* TO_UPSTREAM(BoundsSafety) ON */
1608+ if (Param) {
1609+ for (auto *LateAttr : LateAttrs) {
1610+ assert (LateAttr->Decls .empty ());
1611+ LateAttr->addDecl (Param);
1612+ }
1613+ LateParsedAttrs.append (LateAttrs);
1614+ }
1615+ /* TO_UPSTREAM(BoundsSafety) OFF */
15671616 ObjCParamInfo.push_back (Param);
15681617 }
15691618
@@ -1581,6 +1630,17 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
15811630 getCurScope (), mLoc , Tok.getLocation (), mType , DSRet, ReturnType, KeyLocs,
15821631 Sel, ObjCParamInfo.data (), CParamInfo.data (), CParamInfo.size (),
15831632 methodAttrs, MethodImplKind, isVariadic, MethodDefinition);
1633+ /* TO_UPSTREAM(BoundsSafety) ON */
1634+ if (Result) {
1635+ for (auto *LateAttr : LateParsedReturnAttrs) {
1636+ assert (LateAttr->Decls .empty ());
1637+ LateAttr->addDecl (Result);
1638+ }
1639+ LateParsedAttrs.append (LateParsedReturnAttrs);
1640+ ParseLexedCAttributeList (LateParsedAttrs,
1641+ /* we already have parameters in scope*/ false );
1642+ }
1643+ /* TO_UPSTREAM(BoundsSafety) OFF */
15841644
15851645 PD.complete (Result);
15861646 return Result;
0 commit comments