@@ -1298,9 +1298,11 @@ static void takeDeclAttributes(ParsedAttributes &attrs,
1298
1298
// / '(' objc-type-qualifiers[opt] type-name ')'
1299
1299
// / '(' objc-type-qualifiers[opt] ')'
1300
1300
// /
1301
+ // / TO_UPSTREAM(BoundsSafety) Added LateParsedAttrs
1301
1302
ParsedType Parser::ParseObjCTypeName (ObjCDeclSpec &DS,
1302
1303
DeclaratorContext context,
1303
- ParsedAttributes *paramAttrs) {
1304
+ ParsedAttributes *paramAttrs,
1305
+ LateParsedAttrList *LateParsedAttrs) {
1304
1306
assert (context == DeclaratorContext::ObjCParameter ||
1305
1307
context == DeclaratorContext::ObjCResult);
1306
1308
assert ((paramAttrs != nullptr ) ==
@@ -1325,9 +1327,10 @@ ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS,
1325
1327
DeclSpecContext dsContext = DeclSpecContext::DSC_normal;
1326
1328
if (context == DeclaratorContext::ObjCResult)
1327
1329
dsContext = DeclSpecContext::DSC_objc_method_result;
1328
- ParseSpecifierQualifierList (declSpec, AS_none, dsContext);
1330
+ ParseSpecifierQualifierList (declSpec, AS_none, dsContext, LateParsedAttrs );
1329
1331
Declarator declarator (declSpec, ParsedAttributesView::none (), context);
1330
1332
ParseDeclarator (declarator);
1333
+ DistributeCLateParsedAttrs (declarator, nullptr , LateParsedAttrs);
1331
1334
1332
1335
// If that's not invalid, extract a type.
1333
1336
if (!declarator.isInvalidType ()) {
@@ -1406,17 +1409,25 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
1406
1409
return nullptr ;
1407
1410
}
1408
1411
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
+
1409
1420
// Parse the return type if present.
1410
1421
ParsedType ReturnType;
1411
1422
ObjCDeclSpec DSRet;
1412
1423
if (Tok.is (tok::l_paren))
1413
- ReturnType =
1414
- ParseObjCTypeName (DSRet, DeclaratorContext::ObjCResult, nullptr );
1424
+ ReturnType = ParseObjCTypeName (DSRet, DeclaratorContext::ObjCResult,
1425
+ nullptr , &LateParsedReturnAttrs );
1415
1426
1416
1427
// If attributes exist before the method, parse them.
1417
1428
ParsedAttributes methodAttrs (AttrFactory);
1418
1429
MaybeParseAttributes (PAKM_CXX11 | (getLangOpts ().ObjC ? PAKM_GNU : 0 ),
1419
- methodAttrs);
1430
+ methodAttrs, &LateParsedReturnAttrs );
1420
1431
1421
1432
if (Tok.is (tok::code_completion)) {
1422
1433
cutOffParsing ();
@@ -1450,33 +1461,51 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
1450
1461
selLoc, Sel, nullptr , CParamInfo.data (), CParamInfo.size (), methodAttrs,
1451
1462
MethodImplKind, false , MethodDefinition);
1452
1463
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 */
1453
1474
return Result;
1454
1475
}
1455
1476
1456
1477
SmallVector<const IdentifierInfo *, 12 > KeyIdents;
1457
1478
SmallVector<SourceLocation, 12 > KeyLocs;
1458
1479
SmallVector<SemaObjC::ObjCArgInfo, 12 > ArgInfos;
1480
+ /* TO_UPSTREAM(BoundsSafety) ON */
1481
+ SmallVector<LateParsedAttrList, 12 > LateParamAttrs;
1482
+ /* TO_UPSTREAM(BoundsSafety) OFF */
1459
1483
ParseScope PrototypeScope (this , Scope::FunctionPrototypeScope |
1460
1484
Scope::FunctionDeclarationScope | Scope::DeclScope);
1461
1485
1462
1486
AttributePool allParamAttrs (AttrFactory);
1463
1487
while (true ) {
1464
1488
ParsedAttributes paramAttrs (AttrFactory);
1465
1489
SemaObjC::ObjCArgInfo ArgInfo;
1490
+ /* TO_UPSTREAM(BoundsSafety) ON */
1491
+ LateParsedAttrList LateAttrs (/* PSoon*/ false ,
1492
+ /* LateAttrParseExperimentalExtOnly*/ true );
1493
+ /* TO_UPSTREAM(BoundsSafety) OFF */
1466
1494
1467
1495
// Each iteration parses a single keyword argument.
1468
1496
if (ExpectAndConsume (tok::colon))
1469
1497
break ;
1470
1498
1471
1499
ArgInfo.Type = nullptr ;
1472
1500
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);
1475
1504
1476
1505
// If attributes exist before the argument name, parse them.
1477
1506
// Regardless, collect all the attributes we've parsed so far.
1478
1507
MaybeParseAttributes (PAKM_CXX11 | (getLangOpts ().ObjC ? PAKM_GNU : 0 ),
1479
- paramAttrs);
1508
+ paramAttrs, &LateAttrs );
1480
1509
ArgInfo.ArgAttrs = paramAttrs;
1481
1510
1482
1511
// Code completion for the next piece of the selector.
@@ -1497,6 +1526,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
1497
1526
ConsumeToken (); // Eat the identifier.
1498
1527
1499
1528
ArgInfos.push_back (ArgInfo);
1529
+ LateParamAttrs.push_back (LateAttrs); // TO_UPSTREAM(BoundsSafety)
1500
1530
KeyIdents.push_back (SelIdent);
1501
1531
KeyLocs.push_back (selLoc);
1502
1532
@@ -1543,13 +1573,23 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
1543
1573
}
1544
1574
DeclSpec DS (AttrFactory);
1545
1575
ParsedTemplateInfo TemplateInfo;
1546
- ParseDeclarationSpecifiers (DS, TemplateInfo);
1576
+ ParseDeclarationSpecifiers (
1577
+ DS, TemplateInfo,
1578
+ /* AccessSpecifier AS */ AS_none,
1579
+ /* DeclSpecContext DSC */ DeclSpecContext::DSC_normal,
1580
+ &LateParsedAttrs);
1547
1581
// Parse the declarator.
1548
1582
Declarator ParmDecl (DS, ParsedAttributesView::none (),
1549
1583
DeclaratorContext::Prototype);
1550
1584
ParseDeclarator (ParmDecl);
1551
1585
const IdentifierInfo *ParmII = ParmDecl.getIdentifier ();
1552
1586
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 */
1553
1593
CParamInfo.push_back (DeclaratorChunk::ParamInfo (ParmII,
1554
1594
ParmDecl.getIdentifierLoc (),
1555
1595
Param,
@@ -1561,9 +1601,18 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
1561
1601
// instance, if a method declares a parameter called "id", that parameter must
1562
1602
// not shadow the "id" type.)
1563
1603
SmallVector<ParmVarDecl *, 12 > ObjCParamInfo;
1564
- for (auto &ArgInfo : ArgInfos) {
1604
+ for (const auto &[ ArgInfo, LateAttrs] : llvm::zip ( ArgInfos, LateParamAttrs) ) {
1565
1605
ParmVarDecl *Param = Actions.ObjC ().ActOnMethodParmDeclaration (
1566
1606
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 */
1567
1616
ObjCParamInfo.push_back (Param);
1568
1617
}
1569
1618
@@ -1581,6 +1630,17 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
1581
1630
getCurScope (), mLoc , Tok.getLocation (), mType , DSRet, ReturnType, KeyLocs,
1582
1631
Sel, ObjCParamInfo.data (), CParamInfo.data (), CParamInfo.size (),
1583
1632
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 */
1584
1644
1585
1645
PD.complete (Result);
1586
1646
return Result;
0 commit comments