diff options
author | yronglin <yronglin777@gmail.com> | 2025-04-17 22:40:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-17 22:40:47 +0800 |
commit | d83b639b4c62924deef504f46e573e7d995ea10d (patch) | |
tree | fda59205ff14c0c04d49ec15db174456c5cb42fa /clang/lib/Sema | |
parent | 78857e7263ba555fb40b286c6b40fcd35a85a65a (diff) | |
download | llvm-d83b639b4c62924deef504f46e573e7d995ea10d.zip llvm-d83b639b4c62924deef504f46e573e7d995ea10d.tar.gz llvm-d83b639b4c62924deef504f46e573e7d995ea10d.tar.bz2 |
Reland [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (#136077)
This PR reland https://github.com/llvm/llvm-project/pull/135808, fixed
some missed changes in LLDB.
I found this issue when I working on
https://github.com/llvm/llvm-project/pull/107168.
Currently we have many similiar data structures like:
- std::pair<IdentifierInfo *, SourceLocation>.
- Element type of ModuleIdPath.
- IdentifierLocPair.
- IdentifierLoc.
This PR unify these data structures to IdentifierLoc, moved
IdentifierLoc definition to SourceLocation.h, and deleted other similer
data structures.
---------
Signed-off-by: yronglin <yronglin777@gmail.com>
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/ParsedAttr.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaARM.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 124 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclObjC.cpp | 35 | ||||
-rw-r--r-- | clang/lib/Sema/SemaHLSL.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Sema/SemaModule.cpp | 42 | ||||
-rw-r--r-- | clang/lib/Sema/SemaObjC.cpp | 45 | ||||
-rw-r--r-- | clang/lib/Sema/SemaOpenACCClause.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Sema/SemaStmtAttr.cpp | 29 | ||||
-rw-r--r-- | clang/lib/Sema/SemaSwift.cpp | 24 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateVariadic.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Sema/SemaType.cpp | 13 |
13 files changed, 186 insertions, 177 deletions
diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp index b19a02b..c149cef4 100644 --- a/clang/lib/Sema/ParsedAttr.cpp +++ b/clang/lib/Sema/ParsedAttr.cpp @@ -23,14 +23,6 @@ using namespace clang; -IdentifierLoc *IdentifierLoc::create(ASTContext &Ctx, SourceLocation Loc, - IdentifierInfo *Ident) { - IdentifierLoc *Result = new (Ctx) IdentifierLoc; - Result->Loc = Loc; - Result->Ident = Ident; - return Result; -} - size_t ParsedAttr::allocated_size() const { if (IsAvailability) return AttributeFactory::AvailabilityAllocSize; else if (IsTypeTagForDatatype) diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp index 3f53fb2..5bcbe78 100644 --- a/clang/lib/Sema/SemaARM.cpp +++ b/clang/lib/Sema/SemaARM.cpp @@ -1178,7 +1178,7 @@ void SemaARM::handleBuiltinAliasAttr(Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *Ident = AL.getArgAsIdent(0)->getIdentifierInfo(); unsigned BuiltinID = Ident->getBuiltinID(); StringRef AliasName = cast<FunctionDecl>(D)->getIdentifier()->getName(); diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index f6ec4cb..1e4e6fd 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -8718,7 +8718,7 @@ static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext, } void SemaCodeCompletion::CodeCompleteObjCProtocolReferences( - ArrayRef<IdentifierLocPair> Protocols) { + ArrayRef<IdentifierLoc> Protocols) { ResultBuilder Results(SemaRef, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_ObjCProtocolName); @@ -8729,9 +8729,9 @@ void SemaCodeCompletion::CodeCompleteObjCProtocolReferences( // Tell the result set to ignore all of the protocols we have // already seen. // FIXME: This doesn't work when caching code-completion results. - for (const IdentifierLocPair &Pair : Protocols) - if (ObjCProtocolDecl *Protocol = - SemaRef.ObjC().LookupProtocol(Pair.first, Pair.second)) + for (const IdentifierLoc &Pair : Protocols) + if (ObjCProtocolDecl *Protocol = SemaRef.ObjC().LookupProtocol( + Pair.getIdentifierInfo(), Pair.getLoc())) Results.Ignore(Protocol); // Add all protocols. diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index bc891fb..7dd20a8 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -135,13 +135,13 @@ bool Sema::checkStringLiteralArgumentAttr(const ParsedAttr &AL, unsigned ArgNum, // Look for identifiers. If we have one emit a hint to fix it to a literal. if (AL.isArgIdent(ArgNum)) { IdentifierLoc *Loc = AL.getArgAsIdent(ArgNum); - Diag(Loc->Loc, diag::err_attribute_argument_type) + Diag(Loc->getLoc(), diag::err_attribute_argument_type) << AL << AANT_ArgumentString - << FixItHint::CreateInsertion(Loc->Loc, "\"") - << FixItHint::CreateInsertion(getLocForEndOfToken(Loc->Loc), "\""); - Str = Loc->Ident->getName(); + << FixItHint::CreateInsertion(Loc->getLoc(), "\"") + << FixItHint::CreateInsertion(getLocForEndOfToken(Loc->getLoc()), "\""); + Str = Loc->getIdentifierInfo()->getName(); if (ArgLocation) - *ArgLocation = Loc->Loc; + *ArgLocation = Loc->getLoc(); return true; } @@ -768,7 +768,7 @@ static void handleDiagnoseAsBuiltinAttr(Sema &S, Decl *D, auto Union = AL.getArg(Index - 1); if (auto *E = dyn_cast<Expr *>(Union)) return E->getBeginLoc(); - return cast<IdentifierLoc *>(Union)->Loc; + return cast<IdentifierLoc *>(Union)->getLoc(); }(); S.Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T; @@ -960,10 +960,10 @@ static void handleConsumableAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (AL.isArgIdent(0)) { IdentifierLoc *IL = AL.getArgAsIdent(0); - if (!ConsumableAttr::ConvertStrToConsumedState(IL->Ident->getName(), - DefaultState)) { - S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL - << IL->Ident; + if (!ConsumableAttr::ConvertStrToConsumedState( + IL->getIdentifierInfo()->getName(), DefaultState)) { + S.Diag(IL->getLoc(), diag::warn_attribute_type_not_supported) + << AL << IL->getIdentifierInfo(); return; } } else { @@ -1005,8 +1005,8 @@ static void handleCallableWhenAttr(Sema &S, Decl *D, const ParsedAttr &AL) { SourceLocation Loc; if (AL.isArgIdent(ArgIndex)) { IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex); - StateString = Ident->Ident->getName(); - Loc = Ident->Loc; + StateString = Ident->getIdentifierInfo()->getName(); + Loc = Ident->getLoc(); } else { if (!S.checkStringLiteralArgumentAttr(AL, ArgIndex, StateString, &Loc)) return; @@ -1030,11 +1030,11 @@ static void handleParamTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (AL.isArgIdent(0)) { IdentifierLoc *Ident = AL.getArgAsIdent(0); - StringRef StateString = Ident->Ident->getName(); + StringRef StateString = Ident->getIdentifierInfo()->getName(); if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString, ParamState)) { - S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) + S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported) << AL << StateString; return; } @@ -1064,10 +1064,10 @@ static void handleReturnTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (AL.isArgIdent(0)) { IdentifierLoc *IL = AL.getArgAsIdent(0); - if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->Ident->getName(), - ReturnState)) { - S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL - << IL->Ident; + if (!ReturnTypestateAttr::ConvertStrToConsumedState( + IL->getIdentifierInfo()->getName(), ReturnState)) { + S.Diag(IL->getLoc(), diag::warn_attribute_type_not_supported) + << AL << IL->getIdentifierInfo(); return; } } else { @@ -1111,10 +1111,10 @@ static void handleSetTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { SetTypestateAttr::ConsumedState NewState; if (AL.isArgIdent(0)) { IdentifierLoc *Ident = AL.getArgAsIdent(0); - StringRef Param = Ident->Ident->getName(); + StringRef Param = Ident->getIdentifierInfo()->getName(); if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) { - S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL - << Param; + S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported) + << AL << Param; return; } } else { @@ -1133,10 +1133,10 @@ static void handleTestTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { TestTypestateAttr::ConsumedState TestState; if (AL.isArgIdent(0)) { IdentifierLoc *Ident = AL.getArgAsIdent(0); - StringRef Param = Ident->Ident->getName(); + StringRef Param = Ident->getIdentifierInfo()->getName(); if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) { - S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL - << Param; + S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported) + << AL << Param; return; } } else { @@ -1497,7 +1497,7 @@ static void handleOwnershipAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *Module = AL.getArgAsIdent(0)->getIdentifierInfo(); StringRef ModuleName = Module->getName(); if (normalizeName(ModuleName)) { @@ -1864,10 +1864,10 @@ static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) { } IdentifierLoc *CPUArg = AL.getArgAsIdent(ArgNo); - StringRef CPUName = CPUArg->Ident->getName().trim(); + StringRef CPUName = CPUArg->getIdentifierInfo()->getName().trim(); if (!S.Context.getTargetInfo().validateCPUSpecificCPUDispatch(CPUName)) { - S.Diag(CPUArg->Loc, diag::err_invalid_cpu_specific_dispatch_value) + S.Diag(CPUArg->getLoc(), diag::err_invalid_cpu_specific_dispatch_value) << CPUName << (AL.getKind() == ParsedAttr::AT_CPUDispatch); return; } @@ -1880,7 +1880,7 @@ static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) { S.Diag(AL.getLoc(), diag::warn_multiversion_duplicate_entries); return; } - CPUs.push_back(CPUArg->Ident); + CPUs.push_back(CPUArg->getIdentifierInfo()); } FD->setIsMultiVersion(true); @@ -2358,10 +2358,10 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; IdentifierLoc *Platform = AL.getArgAsIdent(0); - IdentifierInfo *II = Platform->Ident; + IdentifierInfo *II = Platform->getIdentifierInfo(); if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty()) - S.Diag(Platform->Loc, diag::warn_availability_unknown_platform) - << Platform->Ident; + S.Diag(Platform->getLoc(), diag::warn_availability_unknown_platform) + << Platform->getIdentifierInfo(); auto *ND = dyn_cast<NamedDecl>(D); if (!ND) // We warned about this already, so just return. @@ -2410,14 +2410,16 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { IdentifierInfo *IIEnvironment = nullptr; if (EnvironmentLoc) { if (S.getLangOpts().HLSL) { - IIEnvironment = EnvironmentLoc->Ident; + IIEnvironment = EnvironmentLoc->getIdentifierInfo(); if (AvailabilityAttr::getEnvironmentType( - EnvironmentLoc->Ident->getName()) == + EnvironmentLoc->getIdentifierInfo()->getName()) == llvm::Triple::EnvironmentType::UnknownEnvironment) - S.Diag(EnvironmentLoc->Loc, diag::warn_availability_unknown_environment) - << EnvironmentLoc->Ident; + S.Diag(EnvironmentLoc->getLoc(), + diag::warn_availability_unknown_environment) + << EnvironmentLoc->getIdentifierInfo(); } else { - S.Diag(EnvironmentLoc->Loc, diag::err_availability_unexpected_parameter) + S.Diag(EnvironmentLoc->getLoc(), + diag::err_availability_unexpected_parameter) << "environment" << /* C/C++ */ 1; } } @@ -3630,7 +3632,7 @@ static void handleEnumExtensibilityAttr(Sema &S, Decl *D, } EnumExtensibilityAttr::Kind ExtensibilityKind; - IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); if (!EnumExtensibilityAttr::ConvertStrToKind(II->getName(), ExtensibilityKind)) { S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; @@ -3853,7 +3855,7 @@ static bool handleFormatAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, bool HasImplicitThisParam = isInstanceMethod(D); Info->NumArgs = getFunctionOrMethodNumParams(D) + HasImplicitThisParam; - Info->Identifier = AL.getArgAsIdent(0)->Ident; + Info->Identifier = AL.getArgAsIdent(0)->getIdentifierInfo(); StringRef Format = Info->Identifier->getName(); if (normalizeName(Format)) { @@ -4017,14 +4019,14 @@ static void handleCallbackAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (AL.isArgIdent(I)) { IdentifierLoc *IdLoc = AL.getArgAsIdent(I); - auto It = NameIdxMapping.find(IdLoc->Ident->getName()); + auto It = NameIdxMapping.find(IdLoc->getIdentifierInfo()->getName()); if (It == UnknownName) { S.Diag(AL.getLoc(), diag::err_callback_attribute_argument_unknown) - << IdLoc->Ident << IdLoc->Loc; + << IdLoc->getIdentifierInfo() << IdLoc->getLoc(); return; } - SR = SourceRange(IdLoc->Loc); + SR = SourceRange(IdLoc->getLoc()); ArgIdx = It->second; } else if (AL.isArgExpr(I)) { Expr *IdxExpr = AL.getArgAsExpr(I); @@ -4142,13 +4144,14 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL, } assert(AL.isArgIdent(I)); IdentifierLoc *IdLoc = AL.getArgAsIdent(I); - if (IdLoc->Ident->getName() == ParamName) { - Diag(IdLoc->Loc, diag::err_capture_by_references_itself) << IdLoc->Loc; + if (IdLoc->getIdentifierInfo()->getName() == ParamName) { + Diag(IdLoc->getLoc(), diag::err_capture_by_references_itself) + << IdLoc->getLoc(); IsValid = false; continue; } - ParamIdents[I] = IdLoc->Ident; - ParamLocs[I] = IdLoc->Loc; + ParamIdents[I] = IdLoc->getIdentifierInfo(); + ParamLocs[I] = IdLoc->getLoc(); } if (!IsValid) return nullptr; @@ -4754,7 +4757,7 @@ static void handleModeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *Name = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *Name = AL.getArgAsIdent(0)->getIdentifierInfo(); S.AddModeAttr(D, AL, Name); } @@ -5727,8 +5730,8 @@ static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D, } D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr( - S.Context, AL, AL.getArgAsIdent(0)->Ident, ArgumentIdx, TypeTagIdx, - IsPointer)); + S.Context, AL, AL.getArgAsIdent(0)->getIdentifierInfo(), ArgumentIdx, + TypeTagIdx, IsPointer)); } static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, @@ -5748,7 +5751,7 @@ static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, return; } - IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->getIdentifierInfo(); TypeSourceInfo *MatchingCTypeLoc = nullptr; S.GetTypeFromParser(AL.getMatchingCType(), &MatchingCTypeLoc); assert(MatchingCTypeLoc && "no type source info for attribute argument"); @@ -5819,7 +5822,7 @@ static void handleBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *Ident = AL.getArgAsIdent(0)->getIdentifierInfo(); unsigned BuiltinID = Ident->getBuiltinID(); StringRef AliasName = cast<FunctionDecl>(D)->getIdentifier()->getName(); @@ -6585,7 +6588,7 @@ static void handleCFGuardAttr(Sema &S, Decl *D, const ParsedAttr &AL) { } CFGuardAttr::GuardArg Arg; - IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); if (!CFGuardAttr::ConvertStrToGuardArg(II->getName(), Arg)) { S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; return; @@ -6687,8 +6690,9 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D, if (AL.isArgIdent(0)) { IdentifierLoc *IL = AL.getArgAsIdent(0); if (!VTablePointerAuthenticationAttr::ConvertStrToVPtrAuthKeyType( - IL->Ident->getName(), KeyType)) { - S.Diag(IL->Loc, diag::err_invalid_authentication_key) << IL->Ident; + IL->getIdentifierInfo()->getName(), KeyType)) { + S.Diag(IL->getLoc(), diag::err_invalid_authentication_key) + << IL->getIdentifierInfo(); AL.setInvalid(); } if (KeyType == VTablePointerAuthenticationAttr::DefaultKey && @@ -6708,15 +6712,16 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D, if (AL.isArgIdent(1)) { IdentifierLoc *IL = AL.getArgAsIdent(1); if (!VTablePointerAuthenticationAttr:: - ConvertStrToAddressDiscriminationMode(IL->Ident->getName(), - AddressDiversityMode)) { - S.Diag(IL->Loc, diag::err_invalid_address_discrimination) << IL->Ident; + ConvertStrToAddressDiscriminationMode( + IL->getIdentifierInfo()->getName(), AddressDiversityMode)) { + S.Diag(IL->getLoc(), diag::err_invalid_address_discrimination) + << IL->getIdentifierInfo(); AL.setInvalid(); } if (AddressDiversityMode == VTablePointerAuthenticationAttr::DefaultAddressDiscrimination && !S.getLangOpts().PointerAuthCalls) { - S.Diag(IL->Loc, diag::err_no_default_vtable_pointer_auth) << 1; + S.Diag(IL->getLoc(), diag::err_no_default_vtable_pointer_auth) << 1; AL.setInvalid(); } } else { @@ -6731,8 +6736,9 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D, if (AL.isArgIdent(2)) { IdentifierLoc *IL = AL.getArgAsIdent(2); if (!VTablePointerAuthenticationAttr::ConvertStrToExtraDiscrimination( - IL->Ident->getName(), ED)) { - S.Diag(IL->Loc, diag::err_invalid_extra_discrimination) << IL->Ident; + IL->getIdentifierInfo()->getName(), ED)) { + S.Diag(IL->getLoc(), diag::err_invalid_extra_discrimination) + << IL->getIdentifierInfo(); AL.setInvalid(); } if (ED == VTablePointerAuthenticationAttr::DefaultExtraDiscrimination && diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index ba9d3dc..0a14ce2 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -1310,24 +1310,26 @@ static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl, /// protocol declarations in its 'Protocols' argument. void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, - ArrayRef<IdentifierLocPair> ProtocolId, + ArrayRef<IdentifierLoc> ProtocolId, SmallVectorImpl<Decl *> &Protocols) { - for (const IdentifierLocPair &Pair : ProtocolId) { - ObjCProtocolDecl *PDecl = LookupProtocol(Pair.first, Pair.second); + for (const IdentifierLoc &Pair : ProtocolId) { + ObjCProtocolDecl *PDecl = + LookupProtocol(Pair.getIdentifierInfo(), Pair.getLoc()); if (!PDecl) { DeclFilterCCC<ObjCProtocolDecl> CCC{}; - TypoCorrection Corrected = - SemaRef.CorrectTypo(DeclarationNameInfo(Pair.first, Pair.second), - Sema::LookupObjCProtocolName, SemaRef.TUScope, - nullptr, CCC, Sema::CTK_ErrorRecovery); + TypoCorrection Corrected = SemaRef.CorrectTypo( + DeclarationNameInfo(Pair.getIdentifierInfo(), Pair.getLoc()), + Sema::LookupObjCProtocolName, SemaRef.TUScope, nullptr, CCC, + Sema::CTK_ErrorRecovery); if ((PDecl = Corrected.getCorrectionDeclAs<ObjCProtocolDecl>())) SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_undeclared_protocol_suggest) - << Pair.first); + << Pair.getIdentifierInfo()); } if (!PDecl) { - Diag(Pair.second, diag::err_undeclared_protocol) << Pair.first; + Diag(Pair.getLoc(), diag::err_undeclared_protocol) + << Pair.getIdentifierInfo(); continue; } // If this is a forward protocol declaration, get its definition. @@ -1337,7 +1339,7 @@ void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations, // For an objc container, delay protocol reference checking until after we // can set the objc decl as the availability context, otherwise check now. if (!ForObjCContainer) { - (void)SemaRef.DiagnoseUseOfDecl(PDecl, Pair.second); + (void)SemaRef.DiagnoseUseOfDecl(PDecl, Pair.getLoc()); } // If this is a forward declaration and we are supposed to warn in this @@ -1347,7 +1349,8 @@ void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations, if (WarnOnDeclarations && NestedProtocolHasNoDefinition(PDecl, UndefinedProtocol)) { - Diag(Pair.second, diag::warn_undef_protocolref) << Pair.first; + Diag(Pair.getLoc(), diag::warn_undef_protocolref) + << Pair.getIdentifierInfo(); Diag(UndefinedProtocol->getLocation(), diag::note_protocol_decl_undefined) << UndefinedProtocol; } @@ -1784,17 +1787,17 @@ void SemaObjC::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, /// ActOnForwardProtocolDeclaration - Handle \@protocol foo; SemaObjC::DeclGroupPtrTy SemaObjC::ActOnForwardProtocolDeclaration( - SourceLocation AtProtocolLoc, ArrayRef<IdentifierLocPair> IdentList, + SourceLocation AtProtocolLoc, ArrayRef<IdentifierLoc> IdentList, const ParsedAttributesView &attrList) { ASTContext &Context = getASTContext(); SmallVector<Decl *, 8> DeclsInGroup; - for (const IdentifierLocPair &IdentPair : IdentList) { - IdentifierInfo *Ident = IdentPair.first; + for (const IdentifierLoc &IdentPair : IdentList) { + IdentifierInfo *Ident = IdentPair.getIdentifierInfo(); ObjCProtocolDecl *PrevDecl = LookupProtocol( - Ident, IdentPair.second, SemaRef.forRedeclarationInCurContext()); + Ident, IdentPair.getLoc(), SemaRef.forRedeclarationInCurContext()); ObjCProtocolDecl *PDecl = ObjCProtocolDecl::Create(Context, SemaRef.CurContext, Ident, - IdentPair.second, AtProtocolLoc, PrevDecl); + IdentPair.getLoc(), AtProtocolLoc, PrevDecl); SemaRef.PushOnScopeChains(PDecl, SemaRef.TUScope); CheckObjCDeclScope(PDecl); diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 76fb81d..10c2281 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -1282,8 +1282,8 @@ bool SemaHLSL::handleResourceTypeAttr(QualType T, const ParsedAttr &AL) { } IdentifierLoc *Loc = AL.getArgAsIdent(0); - StringRef Identifier = Loc->Ident->getName(); - SourceLocation ArgLoc = Loc->Loc; + StringRef Identifier = Loc->getIdentifierInfo()->getName(); + SourceLocation ArgLoc = Loc->getLoc(); // Validate resource class value ResourceClass RC; @@ -1542,8 +1542,8 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) { } IdentifierLoc *Loc = AL.getArgAsIdent(0); - StringRef Str = Loc->Ident->getName(); - SourceLocation ArgLoc = Loc->Loc; + StringRef Str = Loc->getIdentifierInfo()->getName(); + SourceLocation ArgLoc = Loc->getLoc(); SourceLocation SpaceArgLoc; bool SpecifiedSpace = false; @@ -1557,8 +1557,8 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) { } IdentifierLoc *Loc = AL.getArgAsIdent(1); - Space = Loc->Ident->getName(); - SpaceArgLoc = Loc->Loc; + Space = Loc->getIdentifierInfo()->getName(); + SpaceArgLoc = Loc->getLoc(); } else { Slot = Str; } diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 76589bf..4bba571 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -15,6 +15,7 @@ #include "clang/AST/ASTMutationListener.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Sema/ParsedAttr.h" #include "clang/Sema/SemaInternal.h" #include "llvm/ADT/StringExtras.h" @@ -68,7 +69,7 @@ static std::string stringFromPath(ModuleIdPath Path) { for (auto &Piece : Path) { if (!Name.empty()) Name += "."; - Name += Piece.first->getName(); + Name += Piece.getIdentifierInfo()->getName(); } return Name; } @@ -350,17 +351,18 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // Test the first part of the path to see if it's std[0-9]+ but allow the // name in a system header. - StringRef FirstComponentName = Path[0].first->getName(); - if (!getSourceManager().isInSystemHeader(Path[0].second) && + StringRef FirstComponentName = Path[0].getIdentifierInfo()->getName(); + if (!getSourceManager().isInSystemHeader(Path[0].getLoc()) && (FirstComponentName == "std" || (FirstComponentName.starts_with("std") && llvm::all_of(FirstComponentName.drop_front(3), &llvm::isDigit)))) - Diag(Path[0].second, diag::warn_reserved_module_name) << Path[0].first; + Diag(Path[0].getLoc(), diag::warn_reserved_module_name) + << Path[0].getIdentifierInfo(); // Then test all of the components in the path to see if any of them are // using another kind of reserved or invalid identifier. for (auto Part : Path) { - if (DiagReservedModuleName(*this, Part.first, Part.second)) + if (DiagReservedModuleName(*this, Part.getIdentifierInfo(), Part.getLoc())) return nullptr; } @@ -376,10 +378,10 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // correct. if (!getLangOpts().CurrentModule.empty() && getLangOpts().CurrentModule != ModuleName) { - Diag(Path.front().second, diag::err_current_module_name_mismatch) - << SourceRange(Path.front().second, IsPartition - ? Partition.back().second - : Path.back().second) + Diag(Path.front().getLoc(), diag::err_current_module_name_mismatch) + << SourceRange(Path.front().getLoc(), IsPartition + ? Partition.back().getLoc() + : Path.back().getLoc()) << getLangOpts().CurrentModule; return nullptr; } @@ -394,7 +396,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // We can't have parsed or imported a definition of this module or parsed a // module map defining it already. if (auto *M = Map.findModule(ModuleName)) { - Diag(Path[0].second, diag::err_module_redefinition) << ModuleName; + Diag(Path[0].getLoc(), diag::err_module_redefinition) << ModuleName; if (M->DefinitionLoc.isValid()) Diag(M->DefinitionLoc, diag::note_prev_module_definition); else if (OptionalFileEntryRef FE = M->getASTFile()) @@ -417,8 +419,8 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // keyword nor a module-partition implicitly imports the primary // module interface unit of the module as if by a module-import- // declaration. - std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc( - PP.getIdentifierInfo(ModuleName), Path[0].second); + IdentifierLoc ModuleNameLoc(Path[0].getLoc(), + PP.getIdentifierInfo(ModuleName)); // The module loader will assume we're trying to import the module that // we're building if `LangOpts.CurrentModule` equals to 'ModuleName'. @@ -490,7 +492,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // Make the import decl for the interface in the impl module. ImportDecl *Import = ImportDecl::Create(Context, CurContext, ModuleLoc, - Interface, Path[0].second); + Interface, Path[0].getLoc()); CurContext->addDecl(Import); // Sequence initialization of the imported module before that of the current @@ -579,7 +581,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, // For a C++20 module name, flatten into a single identifier with the source // location of the first component. - std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc; + IdentifierLoc ModuleNameLoc; std::string ModuleName; if (IsPartition) { @@ -591,11 +593,13 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, ModuleName = NamedMod->getPrimaryModuleInterfaceName().str(); ModuleName += ":"; ModuleName += stringFromPath(Path); - ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second}; + ModuleNameLoc = + IdentifierLoc(Path[0].getLoc(), PP.getIdentifierInfo(ModuleName)); Path = ModuleIdPath(ModuleNameLoc); } else if (getLangOpts().CPlusPlusModules) { ModuleName = stringFromPath(Path); - ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second}; + ModuleNameLoc = + IdentifierLoc(Path[0].getLoc(), PP.getIdentifierInfo(ModuleName)); Path = ModuleIdPath(ModuleNameLoc); } @@ -680,7 +684,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, IdentifierLocs.push_back(SourceLocation()); } else if (getLangOpts().CPlusPlusModules && !Mod->Parent) { // A single identifier for the whole name. - IdentifierLocs.push_back(Path[0].second); + IdentifierLocs.push_back(Path[0].getLoc()); } else { Module *ModCheck = Mod; for (unsigned I = 0, N = Path.size(); I != N; ++I) { @@ -690,7 +694,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, break; ModCheck = ModCheck->Parent; - IdentifierLocs.push_back(Path[I].second); + IdentifierLocs.push_back(Path[I].getLoc()); } } @@ -707,7 +711,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, if (getLangOpts().CPlusPlusModules && ExportLoc.isValid() && Mod->Kind == Module::ModuleKind::ModulePartitionImplementation) { Diag(ExportLoc, diag::err_export_partition_impl) - << SourceRange(ExportLoc, Path.back().second); + << SourceRange(ExportLoc, Path.back().getLoc()); } else if (!ModuleScopes.empty() && !currentModuleIsImplementation()) { // Re-export the module if the imported module is exported. // Note that we don't need to add re-exported module to Imports field diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index 073d979..9b24b5f 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -1446,10 +1446,8 @@ SemaObjC::ObjCSubscriptKind SemaObjC::CheckSubscriptingKind(Expr *FromE) { void SemaObjC::AddCFAuditedAttribute(Decl *D) { ASTContext &Context = getASTContext(); - IdentifierInfo *Ident; - SourceLocation Loc; - std::tie(Ident, Loc) = SemaRef.PP.getPragmaARCCFCodeAuditedInfo(); - if (!Loc.isValid()) + auto IdLoc = SemaRef.PP.getPragmaARCCFCodeAuditedInfo(); + if (!IdLoc.getLoc().isValid()) return; // Don't add a redundant or conflicting attribute. @@ -1457,7 +1455,8 @@ void SemaObjC::AddCFAuditedAttribute(Decl *D) { D->hasAttr<CFUnknownTransferAttr>()) return; - AttributeCommonInfo Info(Ident, SourceRange(Loc), + AttributeCommonInfo Info(IdLoc.getIdentifierInfo(), + SourceRange(IdLoc.getLoc()), AttributeCommonInfo::Form::Pragma()); D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info)); } @@ -1642,8 +1641,10 @@ void SemaObjC::handleMethodFamilyAttr(Decl *D, const ParsedAttr &AL) { IdentifierLoc *IL = AL.getArgAsIdent(0); ObjCMethodFamilyAttr::FamilyKind F; - if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->Ident->getName(), F)) { - Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL << IL->Ident; + if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind( + IL->getIdentifierInfo()->getName(), F)) { + Diag(IL->getLoc(), diag::warn_attribute_type_not_supported) + << AL << IL->getIdentifierInfo(); return; } @@ -1706,7 +1707,7 @@ void SemaObjC::handleBlocksAttr(Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); BlocksAttr::BlockType type; if (!BlocksAttr::ConvertStrToBlockType(II->getName(), type)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; @@ -1998,7 +1999,7 @@ void SemaObjC::handleNSErrorDomain(Decl *D, const ParsedAttr &Attr) { IdentifierLoc *IdentLoc = Attr.isArgIdent(0) ? Attr.getArgAsIdent(0) : nullptr; - if (!IdentLoc || !IdentLoc->Ident) { + if (!IdentLoc || !IdentLoc->getIdentifierInfo()) { // Try to locate the argument directly. SourceLocation Loc = Attr.getLoc(); if (Attr.isArgExpr(0) && Attr.getArgAsExpr(0)) @@ -2009,18 +2010,18 @@ void SemaObjC::handleNSErrorDomain(Decl *D, const ParsedAttr &Attr) { } // Verify that the identifier is a valid decl in the C decl namespace. - LookupResult Result(SemaRef, DeclarationName(IdentLoc->Ident), + LookupResult Result(SemaRef, DeclarationName(IdentLoc->getIdentifierInfo()), SourceLocation(), Sema::LookupNameKind::LookupOrdinaryName); if (!SemaRef.LookupName(Result, SemaRef.TUScope) || !Result.getAsSingle<VarDecl>()) { - Diag(IdentLoc->Loc, diag::err_nserrordomain_invalid_decl) - << 1 << IdentLoc->Ident; + Diag(IdentLoc->getLoc(), diag::err_nserrordomain_invalid_decl) + << 1 << IdentLoc->getIdentifierInfo(); return; } - D->addAttr(::new (getASTContext()) - NSErrorDomainAttr(getASTContext(), Attr, IdentLoc->Ident)); + D->addAttr(::new (getASTContext()) NSErrorDomainAttr( + getASTContext(), Attr, IdentLoc->getIdentifierInfo())); } void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) { @@ -2033,7 +2034,7 @@ void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) { // Typedefs only allow objc_bridge(id) and have some additional checking. if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) { - if (!Parm->Ident->isStr("id")) { + if (!Parm->getIdentifierInfo()->isStr("id")) { Diag(AL.getLoc(), diag::err_objc_attr_typedef_not_id) << AL; return; } @@ -2046,8 +2047,8 @@ void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) { } } - D->addAttr(::new (getASTContext()) - ObjCBridgeAttr(getASTContext(), AL, Parm->Ident)); + D->addAttr(::new (getASTContext()) ObjCBridgeAttr(getASTContext(), AL, + Parm->getIdentifierInfo())); } void SemaObjC::handleBridgeMutableAttr(Decl *D, const ParsedAttr &AL) { @@ -2058,21 +2059,21 @@ void SemaObjC::handleBridgeMutableAttr(Decl *D, const ParsedAttr &AL) { return; } - D->addAttr(::new (getASTContext()) - ObjCBridgeMutableAttr(getASTContext(), AL, Parm->Ident)); + D->addAttr(::new (getASTContext()) ObjCBridgeMutableAttr( + getASTContext(), AL, Parm->getIdentifierInfo())); } void SemaObjC::handleBridgeRelatedAttr(Decl *D, const ParsedAttr &AL) { IdentifierInfo *RelatedClass = - AL.isArgIdent(0) ? AL.getArgAsIdent(0)->Ident : nullptr; + AL.isArgIdent(0) ? AL.getArgAsIdent(0)->getIdentifierInfo() : nullptr; if (!RelatedClass) { Diag(D->getBeginLoc(), diag::err_objc_attr_not_id) << AL << 0; return; } IdentifierInfo *ClassMethod = - AL.getArgAsIdent(1) ? AL.getArgAsIdent(1)->Ident : nullptr; + AL.getArgAsIdent(1) ? AL.getArgAsIdent(1)->getIdentifierInfo() : nullptr; IdentifierInfo *InstanceMethod = - AL.getArgAsIdent(2) ? AL.getArgAsIdent(2)->Ident : nullptr; + AL.getArgAsIdent(2) ? AL.getArgAsIdent(2)->getIdentifierInfo() : nullptr; D->addAttr(::new (getASTContext()) ObjCBridgeRelatedAttr( getASTContext(), AL, RelatedClass, ClassMethod, InstanceMethod)); } diff --git a/clang/lib/Sema/SemaOpenACCClause.cpp b/clang/lib/Sema/SemaOpenACCClause.cpp index ab25dcf..049baea 100644 --- a/clang/lib/Sema/SemaOpenACCClause.cpp +++ b/clang/lib/Sema/SemaOpenACCClause.cpp @@ -1343,7 +1343,7 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause( // the limitation, since the Dialect requires this. if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Set && Clause.getDeviceTypeArchitectures().size() > 1) { - SemaRef.Diag(Clause.getDeviceTypeArchitectures()[1].second, + SemaRef.Diag(Clause.getDeviceTypeArchitectures()[1].getLoc(), diag::err_acc_device_type_multiple_archs); return nullptr; } @@ -1369,16 +1369,17 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause( bool Diagnosed = false; auto FilterPred = [&](const DeviceTypeArgument &Arch) { // The '*' case. - if (!Arch.first) + if (!Arch.getIdentifierInfo()) return false; return llvm::find_if(ValidValues, [&](StringRef RHS) { - return Arch.first->getName().equals_insensitive(RHS); + return Arch.getIdentifierInfo()->getName().equals_insensitive(RHS); }) == ValidValues.end(); }; auto Diagnose = [&](const DeviceTypeArgument &Arch) { - Diagnosed = SemaRef.Diag(Arch.second, diag::err_acc_invalid_default_type) - << Arch.first << Clause.getClauseKind() << ValidValuesString; + Diagnosed = SemaRef.Diag(Arch.getLoc(), diag::err_acc_invalid_default_type) + << Arch.getIdentifierInfo() << Clause.getClauseKind() + << ValidValuesString; }; // There aren't stable enumertor versions of 'for-each-then-erase', so do it diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index 2f719c6..a09626c 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -79,9 +79,10 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, Expr *ValueExpr = A.getArgAsExpr(3); StringRef PragmaName = - llvm::StringSwitch<StringRef>(PragmaNameLoc->Ident->getName()) + llvm::StringSwitch<StringRef>( + PragmaNameLoc->getIdentifierInfo()->getName()) .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam", - PragmaNameLoc->Ident->getName()) + PragmaNameLoc->getIdentifierInfo()->getName()) .Default("clang loop"); // This could be handled automatically by adding a Subjects definition in @@ -127,10 +128,10 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Enable); } else { // #pragma clang loop ... - assert(OptionLoc && OptionLoc->Ident && + assert(OptionLoc && OptionLoc->getIdentifierInfo() && "Attribute must have valid option info."); Option = llvm::StringSwitch<LoopHintAttr::OptionType>( - OptionLoc->Ident->getName()) + OptionLoc->getIdentifierInfo()->getName()) .Case("vectorize", LoopHintAttr::Vectorize) .Case("vectorize_width", LoopHintAttr::VectorizeWidth) .Case("interleave", LoopHintAttr::Interleave) @@ -144,12 +145,13 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, .Case("distribute", LoopHintAttr::Distribute) .Default(LoopHintAttr::Vectorize); if (Option == LoopHintAttr::VectorizeWidth) { - assert((ValueExpr || (StateLoc && StateLoc->Ident)) && + assert((ValueExpr || (StateLoc && StateLoc->getIdentifierInfo())) && "Attribute must have a valid value expression or argument."); if (ValueExpr && S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc(), /*AllowZero=*/false)) return nullptr; - if (StateLoc && StateLoc->Ident && StateLoc->Ident->isStr("scalable")) + if (StateLoc && StateLoc->getIdentifierInfo() && + StateLoc->getIdentifierInfo()->isStr("scalable")) State = LoopHintAttr::ScalableWidth; else State = LoopHintAttr::FixedWidth; @@ -167,14 +169,15 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, Option == LoopHintAttr::Unroll || Option == LoopHintAttr::Distribute || Option == LoopHintAttr::PipelineDisabled) { - assert(StateLoc && StateLoc->Ident && "Loop hint must have an argument"); - if (StateLoc->Ident->isStr("disable")) + assert(StateLoc && StateLoc->getIdentifierInfo() && + "Loop hint must have an argument"); + if (StateLoc->getIdentifierInfo()->isStr("disable")) State = LoopHintAttr::Disable; - else if (StateLoc->Ident->isStr("assume_safety")) + else if (StateLoc->getIdentifierInfo()->isStr("assume_safety")) State = LoopHintAttr::AssumeSafety; - else if (StateLoc->Ident->isStr("full")) + else if (StateLoc->getIdentifierInfo()->isStr("full")) State = LoopHintAttr::Full; - else if (StateLoc->Ident->isStr("enable")) + else if (StateLoc->getIdentifierInfo()->isStr("enable")) State = LoopHintAttr::Enable; else llvm_unreachable("bad loop hint argument"); @@ -644,8 +647,8 @@ static Attr *handleAtomicAttr(Sema &S, Stmt *St, const ParsedAttr &AL, } IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex); - OptionString = Ident->Ident->getName(); - Loc = Ident->Loc; + OptionString = Ident->getIdentifierInfo()->getName(); + Loc = Ident->getLoc(); if (!AtomicAttr::ConvertStrToConsumedOption(OptionString, Option)) { S.Diag(Loc, diag::err_attribute_invalid_atomic_argument) << OptionString; return nullptr; diff --git a/clang/lib/Sema/SemaSwift.cpp b/clang/lib/Sema/SemaSwift.cpp index fe72d6c..4aae855 100644 --- a/clang/lib/Sema/SemaSwift.cpp +++ b/clang/lib/Sema/SemaSwift.cpp @@ -148,8 +148,8 @@ void SemaSwift::handleError(Decl *D, const ParsedAttr &AL) { return true; S.Diag(AL.getLoc(), diag::err_attr_swift_error_return_type) - << AL << AL.getArgAsIdent(0)->Ident->getName() << isa<ObjCMethodDecl>(D) - << /*pointer*/ 1; + << AL << AL.getArgAsIdent(0)->getIdentifierInfo()->getName() + << isa<ObjCMethodDecl>(D) << /*pointer*/ 1; return false; }; @@ -159,8 +159,8 @@ void SemaSwift::handleError(Decl *D, const ParsedAttr &AL) { return true; S.Diag(AL.getLoc(), diag::err_attr_swift_error_return_type) - << AL << AL.getArgAsIdent(0)->Ident->getName() << isa<ObjCMethodDecl>(D) - << /*integral*/ 0; + << AL << AL.getArgAsIdent(0)->getIdentifierInfo()->getName() + << isa<ObjCMethodDecl>(D) << /*integral*/ 0; return false; }; @@ -169,10 +169,10 @@ void SemaSwift::handleError(Decl *D, const ParsedAttr &AL) { IdentifierLoc *Loc = AL.getArgAsIdent(0); SwiftErrorAttr::ConventionKind Convention; - if (!SwiftErrorAttr::ConvertStrToConventionKind(Loc->Ident->getName(), - Convention)) { + if (!SwiftErrorAttr::ConvertStrToConventionKind( + Loc->getIdentifierInfo()->getName(), Convention)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) - << AL << Loc->Ident; + << AL << Loc->getIdentifierInfo(); return; } @@ -287,10 +287,10 @@ static void checkSwiftAsyncErrorBlock(Sema &S, Decl *D, void SemaSwift::handleAsyncError(Decl *D, const ParsedAttr &AL) { IdentifierLoc *IDLoc = AL.getArgAsIdent(0); SwiftAsyncErrorAttr::ConventionKind ConvKind; - if (!SwiftAsyncErrorAttr::ConvertStrToConventionKind(IDLoc->Ident->getName(), - ConvKind)) { + if (!SwiftAsyncErrorAttr::ConvertStrToConventionKind( + IDLoc->getIdentifierInfo()->getName(), ConvKind)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) - << AL << IDLoc->Ident; + << AL << IDLoc->getIdentifierInfo(); return; } @@ -643,7 +643,7 @@ void SemaSwift::handleNewType(Decl *D, const ParsedAttr &AL) { } SwiftNewTypeAttr::NewtypeKind Kind; - IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); if (!SwiftNewTypeAttr::ConvertStrToNewtypeKind(II->getName(), Kind)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; return; @@ -667,7 +667,7 @@ void SemaSwift::handleAsyncAttr(Decl *D, const ParsedAttr &AL) { } SwiftAsyncAttr::Kind Kind; - IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); if (!SwiftAsyncAttr::ConvertStrToKind(II->getName(), Kind)) { Diag(AL.getLoc(), diag::err_swift_async_no_access) << AL << II; return; diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp index dc7e3a0..8768223 100644 --- a/clang/lib/Sema/SemaTemplateVariadic.cpp +++ b/clang/lib/Sema/SemaTemplateVariadic.cpp @@ -14,6 +14,7 @@ #include "clang/AST/ExprObjC.h" #include "clang/AST/TypeLoc.h" #include "clang/Sema/Lookup.h" +#include "clang/Sema/ParsedAttr.h" #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/ScopeInfo.h" #include "clang/Sema/Sema.h" @@ -755,7 +756,7 @@ bool Sema::CheckParameterPacksForExpansion( bool &RetainExpansion, UnsignedOrNone &NumExpansions) { ShouldExpand = true; RetainExpansion = false; - std::pair<IdentifierInfo *, SourceLocation> FirstPack; + IdentifierLoc FirstPack; bool HaveFirstPack = false; UnsignedOrNone NumPartialExpansions = std::nullopt; SourceLocation PartiallySubstitutedPackLoc; @@ -867,8 +868,7 @@ bool Sema::CheckParameterPacksForExpansion( // This is the first pack we've seen for which we have an argument. // Record it. NumExpansions = NewPackSize; - FirstPack.first = Name; - FirstPack.second = ParmPack.second; + FirstPack = IdentifierLoc(ParmPack.second, Name); HaveFirstPack = true; continue; } @@ -905,9 +905,9 @@ bool Sema::CheckParameterPacksForExpansion( // the same number of arguments specified. if (HaveFirstPack) Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict) - << FirstPack.first << Name << *NumExpansions + << FirstPack.getIdentifierInfo() << Name << *NumExpansions << (LeastNewPackSize != NewPackSize) << LeastNewPackSize - << SourceRange(FirstPack.second) << SourceRange(ParmPack.second); + << SourceRange(FirstPack.getLoc()) << SourceRange(ParmPack.second); else Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel) << Name << *NumExpansions << (LeastNewPackSize != NewPackSize) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index eba7267..6e7ee8b 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -99,8 +99,8 @@ static void diagnoseBadTypeAttribute(Sema &S, const ParsedAttr &attr, StringRef name = attr.getAttrName()->getName(); // The GC attributes are usually written with macros; special-case them. - IdentifierInfo *II = attr.isArgIdent(0) ? attr.getArgAsIdent(0)->Ident - : nullptr; + IdentifierInfo *II = + attr.isArgIdent(0) ? attr.getArgAsIdent(0)->getIdentifierInfo() : nullptr; if (useExpansionLoc && loc.isMacroID() && II) { if (II->isStr("strong")) { if (S.findMacroSpelling(loc, "__strong")) name = "__strong"; @@ -5732,8 +5732,7 @@ static void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state, } IdentifierLoc *Arg = new (S.Context) IdentifierLoc; - Arg->Ident = &S.Context.Idents.get(attrStr); - Arg->Loc = SourceLocation(); + Arg->setIdentifierInfo(&S.Context.Idents.get(attrStr)); ArgsUnion Args(Arg); @@ -6633,7 +6632,7 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state, return true; } - IdentifierInfo *II = attr.getArgAsIdent(0)->Ident; + IdentifierInfo *II = attr.getArgAsIdent(0)->getIdentifierInfo(); Qualifiers::ObjCLifetime lifetime; if (II->isStr("none")) lifetime = Qualifiers::OCL_ExplicitNone; @@ -6811,7 +6810,7 @@ static bool handleObjCGCTypeAttr(TypeProcessingState &state, ParsedAttr &attr, return true; } - IdentifierInfo *II = attr.getArgAsIdent(0)->Ident; + IdentifierInfo *II = attr.getArgAsIdent(0)->getIdentifierInfo(); if (II->isStr("weak")) GCAttr = Qualifiers::Weak; else if (II->isStr("strong")) @@ -7541,7 +7540,7 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr) { if (Attr.isArgExpr(0)) Str = cast<StringLiteral>(Attr.getArgAsExpr(0))->getString(); else - Str = Attr.getArgAsIdent(0)->Ident->getName(); + Str = Attr.getArgAsIdent(0)->getIdentifierInfo()->getName(); PcsAttr::PCSType Type; if (!PcsAttr::ConvertStrToPCSType(Str, Type)) llvm_unreachable("already validated the attribute"); |