@@ -1094,9 +1094,11 @@ static void takeDeclAttributes(ParsedAttributes &attrs,
10941094 takeDeclAttributes (attrs, D.getTypeObject (i).getAttrs ());
10951095}
10961096
1097+ // / TO_UPSTREAM(BoundsSafety) Added LateParsedAttrs
10971098ParsedType Parser::ParseObjCTypeName (ObjCDeclSpec &DS,
10981099 DeclaratorContext context,
1099- ParsedAttributes *paramAttrs) {
1100+ ParsedAttributes *paramAttrs,
1101+ LateParsedAttrList *LateParsedAttrs) {
11001102 assert (context == DeclaratorContext::ObjCParameter ||
11011103 context == DeclaratorContext::ObjCResult);
11021104 assert ((paramAttrs != nullptr ) ==
@@ -1121,9 +1123,10 @@ ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS,
11211123 DeclSpecContext dsContext = DeclSpecContext::DSC_normal;
11221124 if (context == DeclaratorContext::ObjCResult)
11231125 dsContext = DeclSpecContext::DSC_objc_method_result;
1124- ParseSpecifierQualifierList (declSpec, AS_none, dsContext);
1126+ ParseSpecifierQualifierList (declSpec, AS_none, dsContext, LateParsedAttrs );
11251127 Declarator declarator (declSpec, ParsedAttributesView::none (), context);
11261128 ParseDeclarator (declarator);
1129+ DistributeCLateParsedAttrs (declarator, nullptr , LateParsedAttrs);
11271130
11281131 // If that's not invalid, extract a type.
11291132 if (!declarator.isInvalidType ()) {
@@ -1174,17 +1177,25 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
11741177 return nullptr ;
11751178 }
11761179
1180+ /* TO_UPSTREAM(BoundsSafety) ON */
1181+ LateParsedAttrList LateParsedAttrs (/* PSoon=*/ true ,
1182+ /* LateAttrParseExperimentalExtOnly=*/ true );
1183+ LateParsedAttrList LateParsedReturnAttrs (
1184+ /* PSoon=*/ false ,
1185+ /* LateAttrParseExperimentalExtOnly=*/ true );
1186+ /* TO_UPSTREAM(BoundsSafety) OFF */
1187+
11771188 // Parse the return type if present.
11781189 ParsedType ReturnType;
11791190 ObjCDeclSpec DSRet;
11801191 if (Tok.is (tok::l_paren))
1181- ReturnType =
1182- ParseObjCTypeName (DSRet, DeclaratorContext::ObjCResult, nullptr );
1192+ ReturnType = ParseObjCTypeName (DSRet, DeclaratorContext::ObjCResult,
1193+ nullptr , &LateParsedReturnAttrs );
11831194
11841195 // If attributes exist before the method, parse them.
11851196 ParsedAttributes methodAttrs (AttrFactory);
11861197 MaybeParseAttributes (PAKM_CXX11 | (getLangOpts ().ObjC ? PAKM_GNU : 0 ),
1187- methodAttrs);
1198+ methodAttrs, &LateParsedReturnAttrs );
11881199
11891200 if (Tok.is (tok::code_completion)) {
11901201 cutOffParsing ();
@@ -1218,33 +1229,51 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
12181229 selLoc, Sel, nullptr , CParamInfo.data (), CParamInfo.size (), methodAttrs,
12191230 MethodImplKind, false , MethodDefinition);
12201231 PD.complete (Result);
1232+ /* TO_UPSTREAM(BoundsSafety) ON */
1233+ if (Result) {
1234+ for (auto *LateAttr : LateParsedReturnAttrs) {
1235+ // there are no parameters with late attrs to parse
1236+ assert (LateAttr->Decls .empty ());
1237+ LateAttr->addDecl (Result);
1238+ ParseLexedCAttribute (*LateAttr, true );
1239+ }
1240+ }
1241+ /* TO_UPSTREAM(BoundsSafety) OFF */
12211242 return Result;
12221243 }
12231244
12241245 SmallVector<const IdentifierInfo *, 12 > KeyIdents;
12251246 SmallVector<SourceLocation, 12 > KeyLocs;
12261247 SmallVector<SemaObjC::ObjCArgInfo, 12 > ArgInfos;
1248+ /* TO_UPSTREAM(BoundsSafety) ON */
1249+ SmallVector<LateParsedAttrList, 12 > LateParamAttrs;
1250+ /* TO_UPSTREAM(BoundsSafety) OFF */
12271251 ParseScope PrototypeScope (this , Scope::FunctionPrototypeScope |
12281252 Scope::FunctionDeclarationScope | Scope::DeclScope);
12291253
12301254 AttributePool allParamAttrs (AttrFactory);
12311255 while (true ) {
12321256 ParsedAttributes paramAttrs (AttrFactory);
12331257 SemaObjC::ObjCArgInfo ArgInfo;
1258+ /* TO_UPSTREAM(BoundsSafety) ON */
1259+ LateParsedAttrList LateAttrs (/* PSoon*/ false ,
1260+ /* LateAttrParseExperimentalExtOnly*/ true );
1261+ /* TO_UPSTREAM(BoundsSafety) OFF */
12341262
12351263 // Each iteration parses a single keyword argument.
12361264 if (ExpectAndConsume (tok::colon))
12371265 break ;
12381266
12391267 ArgInfo.Type = nullptr ;
12401268 if (Tok.is (tok::l_paren)) // Parse the argument type if present.
1241- ArgInfo.Type = ParseObjCTypeName (
1242- ArgInfo.DeclSpec , DeclaratorContext::ObjCParameter, ¶mAttrs);
1269+ ArgInfo.Type =
1270+ ParseObjCTypeName (ArgInfo.DeclSpec , DeclaratorContext::ObjCParameter,
1271+ ¶mAttrs, &LateAttrs);
12431272
12441273 // If attributes exist before the argument name, parse them.
12451274 // Regardless, collect all the attributes we've parsed so far.
12461275 MaybeParseAttributes (PAKM_CXX11 | (getLangOpts ().ObjC ? PAKM_GNU : 0 ),
1247- paramAttrs);
1276+ paramAttrs, &LateAttrs );
12481277 ArgInfo.ArgAttrs = paramAttrs;
12491278
12501279 // Code completion for the next piece of the selector.
@@ -1265,6 +1294,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
12651294 ConsumeToken (); // Eat the identifier.
12661295
12671296 ArgInfos.push_back (ArgInfo);
1297+ LateParamAttrs.push_back (LateAttrs); // TO_UPSTREAM(BoundsSafety)
12681298 KeyIdents.push_back (SelIdent);
12691299 KeyLocs.push_back (selLoc);
12701300
@@ -1311,13 +1341,23 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
13111341 }
13121342 DeclSpec DS (AttrFactory);
13131343 ParsedTemplateInfo TemplateInfo;
1314- ParseDeclarationSpecifiers (DS, TemplateInfo);
1344+ ParseDeclarationSpecifiers (
1345+ DS, TemplateInfo,
1346+ /* AccessSpecifier AS */ AS_none,
1347+ /* DeclSpecContext DSC */ DeclSpecContext::DSC_normal,
1348+ &LateParsedAttrs);
13151349 // Parse the declarator.
13161350 Declarator ParmDecl (DS, ParsedAttributesView::none (),
13171351 DeclaratorContext::Prototype);
13181352 ParseDeclarator (ParmDecl);
13191353 const IdentifierInfo *ParmII = ParmDecl.getIdentifier ();
13201354 Decl *Param = Actions.ActOnParamDeclarator (getCurScope (), ParmDecl);
1355+ /* TO_UPSTREAM(BoundsSafety) ON */
1356+ // This will add Param to any late attrs that do not already have an
1357+ // assigned decl, so it's important that other late attrs are not mixed
1358+ // in to LateParsedAttrs without a decl at this point
1359+ DistributeCLateParsedAttrs (ParmDecl, Param, &LateParsedAttrs);
1360+ /* TO_UPSTREAM(BoundsSafety) OFF */
13211361 CParamInfo.push_back (DeclaratorChunk::ParamInfo (ParmII,
13221362 ParmDecl.getIdentifierLoc (),
13231363 Param,
@@ -1329,9 +1369,18 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
13291369 // instance, if a method declares a parameter called "id", that parameter must
13301370 // not shadow the "id" type.)
13311371 SmallVector<ParmVarDecl *, 12 > ObjCParamInfo;
1332- for (auto &ArgInfo : ArgInfos) {
1372+ for (const auto &[ ArgInfo, LateAttrs] : llvm::zip ( ArgInfos, LateParamAttrs) ) {
13331373 ParmVarDecl *Param = Actions.ObjC ().ActOnMethodParmDeclaration (
13341374 getCurScope (), ArgInfo, ObjCParamInfo.size (), MethodDefinition);
1375+ /* TO_UPSTREAM(BoundsSafety) ON */
1376+ if (Param) {
1377+ for (auto *LateAttr : LateAttrs) {
1378+ assert (LateAttr->Decls .empty ());
1379+ LateAttr->addDecl (Param);
1380+ }
1381+ LateParsedAttrs.append (LateAttrs);
1382+ }
1383+ /* TO_UPSTREAM(BoundsSafety) OFF */
13351384 ObjCParamInfo.push_back (Param);
13361385 }
13371386
@@ -1349,6 +1398,17 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
13491398 getCurScope (), mLoc , Tok.getLocation (), mType , DSRet, ReturnType, KeyLocs,
13501399 Sel, ObjCParamInfo.data (), CParamInfo.data (), CParamInfo.size (),
13511400 methodAttrs, MethodImplKind, isVariadic, MethodDefinition);
1401+ /* TO_UPSTREAM(BoundsSafety) ON */
1402+ if (Result) {
1403+ for (auto *LateAttr : LateParsedReturnAttrs) {
1404+ assert (LateAttr->Decls .empty ());
1405+ LateAttr->addDecl (Result);
1406+ }
1407+ LateParsedAttrs.append (LateParsedReturnAttrs);
1408+ ParseLexedCAttributeList (LateParsedAttrs,
1409+ /* we already have parameters in scope*/ false );
1410+ }
1411+ /* TO_UPSTREAM(BoundsSafety) OFF */
13521412
13531413 PD.complete (Result);
13541414 return Result;
0 commit comments