diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp index 4c916fa30685b..3bb30fd15b2e1 100644 --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp @@ -547,8 +547,8 @@ void PPCallbacksTracker::appendArgument(const char *Name, ModuleIdPath Value) { if (I) SS << ", "; SS << "{" - << "Name: " << Value[I].getIdentifierInfo()->getName() << ", " - << "Loc: " << getSourceLocationString(PP, Value[I].getLoc()) << "}"; + << "Name: " << Value[I].first->getName() << ", " + << "Loc: " << getSourceLocationString(PP, Value[I].second) << "}"; } SS << "]"; appendArgument(Name, SS.str()); diff --git a/clang/include/clang/AST/OpenACCClause.h b/clang/include/clang/AST/OpenACCClause.h index f18a6cf62f2c5..681567228cbb0 100644 --- a/clang/include/clang/AST/OpenACCClause.h +++ b/clang/include/clang/AST/OpenACCClause.h @@ -258,7 +258,7 @@ inline bool operator!=(const OpenACCBindClause &LHS, return !(LHS == RHS); } -using DeviceTypeArgument = IdentifierLoc; +using DeviceTypeArgument = std::pair; /// A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or /// an identifier. The 'asterisk' means 'the rest'. class OpenACCDeviceTypeClause final @@ -280,16 +280,16 @@ class OpenACCDeviceTypeClause final "Invalid clause kind for device-type"); assert(!llvm::any_of(Archs, [](const DeviceTypeArgument &Arg) { - return Arg.getLoc().isInvalid(); + return Arg.second.isInvalid(); }) && "Invalid SourceLocation for an argument"); - assert((Archs.size() == 1 || - !llvm::any_of(Archs, - [](const DeviceTypeArgument &Arg) { - return Arg.getIdentifierInfo() == nullptr; - })) && - "Only a single asterisk version is permitted, and must be the " - "only one"); + assert( + (Archs.size() == 1 || !llvm::any_of(Archs, + [](const DeviceTypeArgument &Arg) { + return Arg.first == nullptr; + })) && + "Only a single asterisk version is permitted, and must be the " + "only one"); std::uninitialized_copy(Archs.begin(), Archs.end(), getTrailingObjects()); @@ -302,7 +302,7 @@ class OpenACCDeviceTypeClause final } bool hasAsterisk() const { return getArchitectures().size() > 0 && - getArchitectures()[0].getIdentifierInfo() == nullptr; + getArchitectures()[0].first == nullptr; } ArrayRef getArchitectures() const { diff --git a/clang/include/clang/Basic/IdentifierTable.h b/clang/include/clang/Basic/IdentifierTable.h index 1275b056227b5..0347880244a40 100644 --- a/clang/include/clang/Basic/IdentifierTable.h +++ b/clang/include/clang/Basic/IdentifierTable.h @@ -18,7 +18,6 @@ #include "clang/Basic/Builtins.h" #include "clang/Basic/DiagnosticIDs.h" #include "clang/Basic/LLVM.h" -#include "clang/Basic/SourceLocation.h" #include "clang/Basic/TokenKinds.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/FoldingSet.h" @@ -77,6 +76,9 @@ inline bool isReservedInAllContexts(ReservedIdentifierStatus Status) { Status != ReservedIdentifierStatus::StartsWithUnderscoreAndIsExternC; } +/// A simple pair of identifier info and location. +using IdentifierLocPair = std::pair; + /// IdentifierInfo and other related classes are aligned to /// 8 bytes so that DeclarationName can use the lower 3 bits /// of a pointer to one of these classes. @@ -1163,28 +1165,6 @@ class SelectorTable { static std::string getPropertyNameFromSetterSelector(Selector Sel); }; -/// A simple pair of identifier info and location. -class IdentifierLoc { - SourceLocation Loc; - IdentifierInfo *II = nullptr; - -public: - IdentifierLoc() = default; - IdentifierLoc(SourceLocation L, IdentifierInfo *Ident) : Loc(L), II(Ident) {} - - void setLoc(SourceLocation L) { Loc = L; } - void setIdentifierInfo(IdentifierInfo *Ident) { II = Ident; } - SourceLocation getLoc() const { return Loc; } - IdentifierInfo *getIdentifierInfo() const { return II; } - - bool operator==(const IdentifierLoc &X) const { - return Loc == X.Loc && II == X.II; - } - - bool operator!=(const IdentifierLoc &X) const { - return Loc != X.Loc || II != X.II; - } -}; } // namespace clang namespace llvm { diff --git a/clang/include/clang/Lex/ModuleLoader.h b/clang/include/clang/Lex/ModuleLoader.h index a58407200c41c..f880a9091a2ed 100644 --- a/clang/include/clang/Lex/ModuleLoader.h +++ b/clang/include/clang/Lex/ModuleLoader.h @@ -14,7 +14,6 @@ #ifndef LLVM_CLANG_LEX_MODULELOADER_H #define LLVM_CLANG_LEX_MODULELOADER_H -#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/Module.h" #include "clang/Basic/SourceLocation.h" @@ -30,7 +29,7 @@ class IdentifierInfo; /// A sequence of identifier/location pairs used to describe a particular /// module or submodule, e.g., std.vector. -using ModuleIdPath = ArrayRef; +using ModuleIdPath = ArrayRef>; /// Describes the result of attempting to load a module. class ModuleLoadResult { diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h index 313b730afbab8..46cc564086f1c 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -15,7 +15,6 @@ #define LLVM_CLANG_LEX_PPCALLBACKS_H #include "clang/Basic/DiagnosticIDs.h" -#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/ModuleLoader.h" diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index f8f2f567f9171..24bb524783e93 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -327,7 +327,7 @@ class Preprocessor { SourceLocation ModuleImportLoc; /// The import path for named module that we're currently processing. - SmallVector NamedModuleImportPath; + SmallVector, 2> NamedModuleImportPath; llvm::DenseMap> CheckPoints; unsigned CheckPointCounter = 0; @@ -622,7 +622,7 @@ class Preprocessor { /// The identifier and source location of the currently-active /// \#pragma clang arc_cf_code_audited begin. - IdentifierLoc PragmaARCCFCodeAuditedInfo; + std::pair PragmaARCCFCodeAuditedInfo; /// The source location of the currently-active /// \#pragma clang assume_nonnull begin. @@ -1998,7 +1998,8 @@ class Preprocessor { /// arc_cf_code_audited begin. /// /// Returns an invalid location if there is no such pragma active. - IdentifierLoc getPragmaARCCFCodeAuditedInfo() const { + std::pair + getPragmaARCCFCodeAuditedInfo() const { return PragmaARCCFCodeAuditedInfo; } @@ -2006,7 +2007,7 @@ class Preprocessor { /// arc_cf_code_audited begin. An invalid location ends the pragma. void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident, SourceLocation Loc) { - PragmaARCCFCodeAuditedInfo = IdentifierLoc(Loc, Ident); + PragmaARCCFCodeAuditedInfo = {Ident, Loc}; } /// The location of the currently-active \#pragma clang diff --git a/clang/include/clang/Parse/LoopHint.h b/clang/include/clang/Parse/LoopHint.h index 72be043d3c5a4..cec5605ea3615 100644 --- a/clang/include/clang/Parse/LoopHint.h +++ b/clang/include/clang/Parse/LoopHint.h @@ -9,12 +9,12 @@ #ifndef LLVM_CLANG_PARSE_LOOPHINT_H #define LLVM_CLANG_PARSE_LOOPHINT_H -#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceLocation.h" namespace clang { class Expr; +struct IdentifierLoc; /// Loop optimization hint for loop and unroll pragmas. struct LoopHint { diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 662f54d0e8d8a..9ebcf144ba59e 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -1725,8 +1725,8 @@ class Parser : public CodeCompletionHandler { ObjCTypeParamList *parseObjCTypeParamList(); ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs( ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc, - SmallVectorImpl &protocolIdents, SourceLocation &rAngleLoc, - bool mayBeProtocolList = true); + SmallVectorImpl &protocolIdents, + SourceLocation &rAngleLoc, bool mayBeProtocolList = true); void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl, SourceLocation atLoc, @@ -3818,7 +3818,8 @@ class Parser : public CodeCompletionHandler { SourceLocation Loc, llvm::SmallVectorImpl &IntExprs); /// Parses the 'device-type-list', which is a list of identifiers. - bool ParseOpenACCDeviceTypeList(llvm::SmallVector &Archs); + bool ParseOpenACCDeviceTypeList( + llvm::SmallVector> &Archs); /// Parses the 'async-argument', which is an integral value with two /// 'special' values that are likely negative (but come from Macros). OpenACCIntExprParseResult ParseOpenACCAsyncArgument(OpenACCDirectiveKind DK, @@ -3950,8 +3951,10 @@ class Parser : public CodeCompletionHandler { return false; } - bool ParseModuleName(SourceLocation UseLoc, - SmallVectorImpl &Path, bool IsImport); + bool ParseModuleName( + SourceLocation UseLoc, + SmallVectorImpl> &Path, + bool IsImport); //===--------------------------------------------------------------------===// // C++11/G++: Type Traits [Type-Traits.html in the GCC manual] diff --git a/clang/include/clang/Sema/ParsedAttr.h b/clang/include/clang/Sema/ParsedAttr.h index 428d3111de80d..b88b871dc8821 100644 --- a/clang/include/clang/Sema/ParsedAttr.h +++ b/clang/include/clang/Sema/ParsedAttr.h @@ -40,6 +40,7 @@ class LangOptions; class Sema; class Stmt; class TargetInfo; +struct IdentifierLoc; /// Represents information about a change in availability for /// an entity, which is part of the encoding of the 'availability' @@ -98,6 +99,15 @@ struct PropertyData { } // namespace detail +/// Wraps an identifier and optional source location for the identifier. +struct IdentifierLoc { + SourceLocation Loc; + IdentifierInfo *Ident; + + static IdentifierLoc *create(ASTContext &Ctx, SourceLocation Loc, + IdentifierInfo *Ident); +}; + /// A union of the various pointer types that can be passed to an /// ParsedAttr as an argument. using ArgsUnion = llvm::PointerUnion; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 1f23b754a69cb..fe37fd7701ce3 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -143,7 +143,7 @@ enum class LangAS : unsigned int; class LocalInstantiationScope; class LookupResult; class MangleNumberingContext; -typedef ArrayRef ModuleIdPath; +typedef ArrayRef> ModuleIdPath; class ModuleLoader; class MultiLevelTemplateArgumentList; struct NormalizedConstraint; diff --git a/clang/include/clang/Sema/SemaCodeCompletion.h b/clang/include/clang/Sema/SemaCodeCompletion.h index 3029e56e5cfe2..72159de3a6e72 100644 --- a/clang/include/clang/Sema/SemaCodeCompletion.h +++ b/clang/include/clang/Sema/SemaCodeCompletion.h @@ -193,7 +193,8 @@ class SemaCodeCompletion : public SemaBase { void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar); void CodeCompleteObjCSelector(Scope *S, ArrayRef SelIdents); - void CodeCompleteObjCProtocolReferences(ArrayRef Protocols); + void + CodeCompleteObjCProtocolReferences(ArrayRef Protocols); void CodeCompleteObjCProtocolDecl(Scope *S); void CodeCompleteObjCInterfaceDecl(Scope *S); void CodeCompleteObjCClassForwardDecl(Scope *S); diff --git a/clang/include/clang/Sema/SemaObjC.h b/clang/include/clang/Sema/SemaObjC.h index 4cda41a82b61f..791a7f45b832f 100644 --- a/clang/include/clang/Sema/SemaObjC.h +++ b/clang/include/clang/Sema/SemaObjC.h @@ -307,11 +307,11 @@ class SemaObjC : public SemaBase { DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, - ArrayRef IdentList, + ArrayRef IdentList, const ParsedAttributesView &attrList); void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, - ArrayRef ProtocolId, + ArrayRef ProtocolId, SmallVectorImpl &Protocols); void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId, diff --git a/clang/include/clang/Sema/SemaOpenACC.h b/clang/include/clang/Sema/SemaOpenACC.h index 8d31d46444c7e..4c3a13a3b044f 100644 --- a/clang/include/clang/Sema/SemaOpenACC.h +++ b/clang/include/clang/Sema/SemaOpenACC.h @@ -212,7 +212,7 @@ class SemaOpenACC : public SemaBase { } LoopWithoutSeqInfo; // Redeclaration of the version in OpenACCClause.h. - using DeviceTypeArgument = IdentifierLoc; + using DeviceTypeArgument = std::pair; /// A type to represent all the data for an OpenACC Clause that has been /// parsed, but not yet created/semantically analyzed. This is effectively a diff --git a/clang/lib/AST/OpenACCClause.cpp b/clang/lib/AST/OpenACCClause.cpp index 2820d7b288658..d7cbb51335359 100644 --- a/clang/lib/AST/OpenACCClause.cpp +++ b/clang/lib/AST/OpenACCClause.cpp @@ -891,10 +891,10 @@ void OpenACCClausePrinter::VisitDeviceTypeClause( OS << "("; llvm::interleaveComma(C.getArchitectures(), OS, [&](const DeviceTypeArgument &Arch) { - if (Arch.getIdentifierInfo() == nullptr) + if (Arch.first == nullptr) OS << "*"; else - OS << Arch.getIdentifierInfo()->getName(); + OS << Arch.first->getName(); }); OS << ")"; } diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp index 1bd94a3ac6431..c8b459ee78e6b 100644 --- a/clang/lib/AST/TextNodeDumper.cpp +++ b/clang/lib/AST/TextNodeDumper.cpp @@ -500,10 +500,10 @@ void TextNodeDumper::Visit(const OpenACCClause *C) { llvm::interleaveComma( cast(C)->getArchitectures(), OS, [&](const DeviceTypeArgument &Arch) { - if (Arch.getIdentifierInfo() == nullptr) + if (Arch.first == nullptr) OS << "*"; else - OS << Arch.getIdentifierInfo()->getName(); + OS << Arch.first->getName(); }); OS << ")"; break; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 93e4e31c2891d..243e0a3c15b05 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -35,7 +35,6 @@ #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Sema/CodeCompleteConsumer.h" -#include "clang/Sema/ParsedAttr.h" #include "clang/Sema/Sema.h" #include "clang/Serialization/ASTReader.h" #include "clang/Serialization/GlobalModuleIndex.h" @@ -2010,8 +2009,8 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, Module::NameVisibilityKind Visibility, bool IsInclusionDirective) { // Determine what file we're searching from. - StringRef ModuleName = Path[0].getIdentifierInfo()->getName(); - SourceLocation ModuleNameLoc = Path[0].getLoc(); + StringRef ModuleName = Path[0].first->getName(); + SourceLocation ModuleNameLoc = Path[0].second; // If we've already handled this import, just return the cached result. // This one-element cache is important to eliminate redundant diagnostics @@ -2027,7 +2026,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, // If we don't already have information on this module, load the module now. Module *Module = nullptr; ModuleMap &MM = getPreprocessor().getHeaderSearchInfo().getModuleMap(); - if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].getIdentifierInfo())) { + if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].first)) { // Use the cached result, which may be nullptr. Module = *MaybeModule; // Config macros are already checked before building a module, but they need @@ -2047,7 +2046,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, // * `Preprocessor::HandleHeaderIncludeOrImport` will never call this // function as the `#include` or `#import` is textual. - MM.cacheModuleLoad(*Path[0].getIdentifierInfo(), Module); + MM.cacheModuleLoad(*Path[0].first, Module); } else { ModuleLoadResult Result = findOrCompileModuleAndReadAST( ModuleName, ImportLoc, ModuleNameLoc, IsInclusionDirective); @@ -2056,7 +2055,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, if (!Result) DisableGeneratingGlobalModuleIndex = true; Module = Result; - MM.cacheModuleLoad(*Path[0].getIdentifierInfo(), Module); + MM.cacheModuleLoad(*Path[0].first, Module); } // If we never found the module, fail. Otherwise, verify the module and link @@ -2068,7 +2067,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, // a submodule. bool MapPrivateSubModToTopLevel = false; for (unsigned I = 1, N = Path.size(); I != N; ++I) { - StringRef Name = Path[I].getIdentifierInfo()->getName(); + StringRef Name = Path[I].first->getName(); clang::Module *Sub = Module->findSubmodule(Name); // If the user is requesting Foo.Private and it doesn't exist, try to @@ -2079,10 +2078,10 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, SmallString<128> PrivateModule(Module->Name); PrivateModule.append("_Private"); - SmallVector PrivPath; + SmallVector, 2> PrivPath; auto &II = PP->getIdentifierTable().get( PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID()); - PrivPath.emplace_back(Path[0].getLoc(), &II); + PrivPath.push_back(std::make_pair(&II, Path[0].second)); std::string FileName; // If there is a modulemap module or prebuilt module, load it. @@ -2096,12 +2095,11 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, PP->markClangModuleAsAffecting(Module); if (!getDiagnostics().isIgnored( diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) { - getDiagnostics().Report(Path[I].getLoc(), + getDiagnostics().Report(Path[I].second, diag::warn_no_priv_submodule_use_toplevel) - << Path[I].getIdentifierInfo() << Module->getFullModuleName() - << PrivateModule - << SourceRange(Path[0].getLoc(), Path[I].getLoc()) - << FixItHint::CreateReplacement(SourceRange(Path[0].getLoc()), + << Path[I].first << Module->getFullModuleName() << PrivateModule + << SourceRange(Path[0].second, Path[I].second) + << FixItHint::CreateReplacement(SourceRange(Path[0].second), PrivateModule); getDiagnostics().Report(Sub->DefinitionLoc, diag::note_private_top_level_defined); @@ -2130,11 +2128,10 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, // If there was a clear winner, user it. if (Best.size() == 1) { - getDiagnostics().Report(Path[I].getLoc(), - diag::err_no_submodule_suggest) - << Path[I].getIdentifierInfo() << Module->getFullModuleName() - << Best[0] << SourceRange(Path[0].getLoc(), Path[I - 1].getLoc()) - << FixItHint::CreateReplacement(SourceRange(Path[I].getLoc()), + getDiagnostics().Report(Path[I].second, diag::err_no_submodule_suggest) + << Path[I].first << Module->getFullModuleName() << Best[0] + << SourceRange(Path[0].second, Path[I - 1].second) + << FixItHint::CreateReplacement(SourceRange(Path[I].second), Best[0]); Sub = Module->findSubmodule(Best[0]); @@ -2144,9 +2141,9 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, if (!Sub) { // No submodule by this name. Complain, and don't look for further // submodules. - getDiagnostics().Report(Path[I].getLoc(), diag::err_no_submodule) - << Path[I].getIdentifierInfo() << Module->getFullModuleName() - << SourceRange(Path[0].getLoc(), Path[I - 1].getLoc()); + getDiagnostics().Report(Path[I].second, diag::err_no_submodule) + << Path[I].first << Module->getFullModuleName() + << SourceRange(Path[0].second, Path[I - 1].second); break; } @@ -2164,8 +2161,8 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, // FIXME: Should we detect this at module load time? It seems fairly // expensive (and rare). getDiagnostics().Report(ImportLoc, diag::warn_missing_submodule) - << Module->getFullModuleName() - << SourceRange(Path.front().getLoc(), Path.back().getLoc()); + << Module->getFullModuleName() + << SourceRange(Path.front().second, Path.back().second); return ModuleLoadResult(Module, ModuleLoadResult::MissingExpected); } @@ -2174,7 +2171,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, if (Preprocessor::checkModuleIsAvailable(getLangOpts(), getTarget(), *Module, getDiagnostics())) { getDiagnostics().Report(ImportLoc, diag::note_module_import_here) - << SourceRange(Path.front().getLoc(), Path.back().getLoc()); + << SourceRange(Path.front().second, Path.back().second); LastModuleImportLoc = ImportLoc; LastModuleImportResult = ModuleLoadResult(); return ModuleLoadResult(); @@ -2299,9 +2296,9 @@ GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex( Module *TheModule = I->second; OptionalFileEntryRef Entry = TheModule->getASTFile(); if (!Entry) { - SmallVector Path; - Path.emplace_back(TriggerLoc, - getPreprocessor().getIdentifierInfo(TheModule->Name)); + SmallVector, 2> Path; + Path.push_back(std::make_pair( + getPreprocessor().getIdentifierInfo(TheModule->Name), TriggerLoc)); std::reverse(Path.begin(), Path.end()); // Load a module as hidden. This also adds it to the global index. loadModule(TheModule->DefinitionLoc, Path, Module::Hidden, false); diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index e6c7b9f32c29b..c5aeb92c7af73 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -1216,9 +1216,9 @@ void GetDependenciesByModuleNameAction::ExecuteAction() { SourceManager &SM = PP.getSourceManager(); FileID MainFileID = SM.getMainFileID(); SourceLocation FileStart = SM.getLocForStartOfFile(MainFileID); - SmallVector Path; + SmallVector, 2> Path; IdentifierInfo *ModuleID = PP.getIdentifierInfo(ModuleName); - Path.emplace_back(FileStart, ModuleID); + Path.push_back(std::make_pair(ModuleID, FileStart)); auto ModResult = CI.loadModule(FileStart, Path, Module::Hidden, false); PPCallbacks *CB = PP.getPPCallbacks(); CB->moduleImport(SourceLocation(), Path, ModResult); diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 21ec83b437ef4..8411526019f3e 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1916,15 +1916,15 @@ void Preprocessor::EnterAnnotationToken(SourceRange Range, /// Produce a diagnostic informing the user that a #include or similar /// was implicitly treated as a module import. -static void diagnoseAutoModuleImport(Preprocessor &PP, SourceLocation HashLoc, - Token &IncludeTok, - ArrayRef Path, - SourceLocation PathEnd) { +static void diagnoseAutoModuleImport( + Preprocessor &PP, SourceLocation HashLoc, Token &IncludeTok, + ArrayRef> Path, + SourceLocation PathEnd) { SmallString<128> PathString; for (size_t I = 0, N = Path.size(); I != N; ++I) { if (I) PathString += '.'; - PathString += Path[I].getIdentifierInfo()->getName(); + PathString += Path[I].first->getName(); } int IncludeKind = 0; @@ -2273,12 +2273,12 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( SourceLocation StartLoc = IsImportDecl ? IncludeTok.getLocation() : HashLoc; // Complain about attempts to #include files in an audit pragma. - if (PragmaARCCFCodeAuditedInfo.getLoc().isValid()) { + if (PragmaARCCFCodeAuditedInfo.second.isValid()) { Diag(StartLoc, diag::err_pp_include_in_arc_cf_code_audited) << IsImportDecl; - Diag(PragmaARCCFCodeAuditedInfo.getLoc(), diag::note_pragma_entered_here); + Diag(PragmaARCCFCodeAuditedInfo.second, diag::note_pragma_entered_here); // Immediately leave the pragma. - PragmaARCCFCodeAuditedInfo = IdentifierLoc(); + PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()}; } // Complain about attempts to #include files in an assume-nonnull pragma. @@ -2403,10 +2403,10 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // Compute the module access path corresponding to this module. // FIXME: Should we have a second loadModule() overload to avoid this // extra lookup step? - SmallVector Path; + SmallVector, 2> Path; for (Module *Mod = ModuleToImport; Mod; Mod = Mod->Parent) - Path.emplace_back(FilenameTok.getLocation(), - getIdentifierInfo(Mod->Name)); + Path.push_back(std::make_pair(getIdentifierInfo(Mod->Name), + FilenameTok.getLocation())); std::reverse(Path.begin(), Path.end()); // Warn that we're replacing the include/import with a module import. diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index db6069e31fa46..a373a52506a24 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -409,13 +409,13 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) { // Complain about reaching a true EOF within arc_cf_code_audited. // We don't want to complain about reaching the end of a macro // instantiation or a _Pragma. - if (PragmaARCCFCodeAuditedInfo.getLoc().isValid() && !isEndOfMacro && + if (PragmaARCCFCodeAuditedInfo.second.isValid() && !isEndOfMacro && !(CurLexer && CurLexer->Is_PragmaLexer)) { - Diag(PragmaARCCFCodeAuditedInfo.getLoc(), + Diag(PragmaARCCFCodeAuditedInfo.second, diag::err_pp_eof_in_arc_cf_code_audited); // Recover by leaving immediately. - PragmaARCCFCodeAuditedInfo = IdentifierLoc(); + PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()}; } // Complain about reaching a true EOF within assume_nonnull. diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 5b6a29bdad910..91c1619e35623 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -763,19 +763,20 @@ void Preprocessor::HandlePragmaIncludeAlias(Token &Tok) { // Lex a component of a module name: either an identifier or a string literal; // for components that can be expressed both ways, the two forms are equivalent. -static bool LexModuleNameComponent(Preprocessor &PP, Token &Tok, - IdentifierLoc &ModuleNameComponent, - bool First) { +static bool LexModuleNameComponent( + Preprocessor &PP, Token &Tok, + std::pair &ModuleNameComponent, + bool First) { PP.LexUnexpandedToken(Tok); if (Tok.is(tok::string_literal) && !Tok.hasUDSuffix()) { StringLiteralParser Literal(Tok, PP); if (Literal.hadError) return true; - ModuleNameComponent = IdentifierLoc( - Tok.getLocation(), PP.getIdentifierInfo(Literal.GetString())); + ModuleNameComponent = std::make_pair( + PP.getIdentifierInfo(Literal.GetString()), Tok.getLocation()); } else if (!Tok.isAnnotation() && Tok.getIdentifierInfo()) { ModuleNameComponent = - IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo()); + std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation()); } else { PP.Diag(Tok.getLocation(), diag::err_pp_expected_module_name) << First; return true; @@ -783,10 +784,12 @@ static bool LexModuleNameComponent(Preprocessor &PP, Token &Tok, return false; } -static bool LexModuleName(Preprocessor &PP, Token &Tok, - llvm::SmallVectorImpl &ModuleName) { +static bool LexModuleName( + Preprocessor &PP, Token &Tok, + llvm::SmallVectorImpl> + &ModuleName) { while (true) { - IdentifierLoc NameComponent; + std::pair NameComponent; if (LexModuleNameComponent(PP, Tok, NameComponent, ModuleName.empty())) return true; ModuleName.push_back(NameComponent); @@ -800,10 +803,10 @@ static bool LexModuleName(Preprocessor &PP, Token &Tok, void Preprocessor::HandlePragmaModuleBuild(Token &Tok) { SourceLocation Loc = Tok.getLocation(); - IdentifierLoc ModuleNameLoc; + std::pair ModuleNameLoc; if (LexModuleNameComponent(*this, Tok, ModuleNameLoc, true)) return; - IdentifierInfo *ModuleName = ModuleNameLoc.getIdentifierInfo(); + IdentifierInfo *ModuleName = ModuleNameLoc.first; LexUnexpandedToken(Tok); if (Tok.isNot(tok::eod)) { @@ -1106,17 +1109,17 @@ struct PragmaDebugHandler : public PragmaHandler { PP.Diag(MacroName, diag::warn_pragma_debug_missing_argument) << II->getName(); } else if (II->isStr("module_map")) { - llvm::SmallVector ModuleName; + llvm::SmallVector, 8> + ModuleName; if (LexModuleName(PP, Tok, ModuleName)) return; ModuleMap &MM = PP.getHeaderSearchInfo().getModuleMap(); Module *M = nullptr; for (auto IIAndLoc : ModuleName) { - M = MM.lookupModuleQualified(IIAndLoc.getIdentifierInfo()->getName(), - M); + M = MM.lookupModuleQualified(IIAndLoc.first->getName(), M); if (!M) { - PP.Diag(IIAndLoc.getLoc(), diag::warn_pragma_debug_unknown_module) - << IIAndLoc.getIdentifierInfo()->getName(); + PP.Diag(IIAndLoc.second, diag::warn_pragma_debug_unknown_module) + << IIAndLoc.first->getName(); return; } } @@ -1704,7 +1707,8 @@ struct PragmaModuleImportHandler : public PragmaHandler { SourceLocation ImportLoc = Tok.getLocation(); // Read the module name. - llvm::SmallVector ModuleName; + llvm::SmallVector, 8> + ModuleName; if (LexModuleName(PP, Tok, ModuleName)) return; @@ -1719,7 +1723,7 @@ struct PragmaModuleImportHandler : public PragmaHandler { return; PP.makeModuleVisible(Imported, ImportLoc); - PP.EnterAnnotationToken(SourceRange(ImportLoc, ModuleName.back().getLoc()), + PP.EnterAnnotationToken(SourceRange(ImportLoc, ModuleName.back().second), tok::annot_module_include, Imported); if (auto *CB = PP.getPPCallbacks()) CB->moduleImport(ImportLoc, ModuleName, Imported); @@ -1740,7 +1744,8 @@ struct PragmaModuleBeginHandler : public PragmaHandler { SourceLocation BeginLoc = Tok.getLocation(); // Read the module name. - llvm::SmallVector ModuleName; + llvm::SmallVector, 8> + ModuleName; if (LexModuleName(PP, Tok, ModuleName)) return; @@ -1749,11 +1754,10 @@ struct PragmaModuleBeginHandler : public PragmaHandler { // We can only enter submodules of the current module. StringRef Current = PP.getLangOpts().CurrentModule; - if (ModuleName.front().getIdentifierInfo()->getName() != Current) { - PP.Diag(ModuleName.front().getLoc(), - diag::err_pp_module_begin_wrong_module) - << ModuleName.front().getIdentifierInfo() << (ModuleName.size() > 1) - << Current.empty() << Current; + if (ModuleName.front().first->getName() != Current) { + PP.Diag(ModuleName.front().second, diag::err_pp_module_begin_wrong_module) + << ModuleName.front().first << (ModuleName.size() > 1) + << Current.empty() << Current; return; } @@ -1761,19 +1765,17 @@ struct PragmaModuleBeginHandler : public PragmaHandler { // be loaded or implicitly loadable. auto &HSI = PP.getHeaderSearchInfo(); auto &MM = HSI.getModuleMap(); - Module *M = HSI.lookupModule(Current, ModuleName.front().getLoc()); + Module *M = HSI.lookupModule(Current, ModuleName.front().second); if (!M) { - PP.Diag(ModuleName.front().getLoc(), - diag::err_pp_module_begin_no_module_map) - << Current; + PP.Diag(ModuleName.front().second, + diag::err_pp_module_begin_no_module_map) << Current; return; } for (unsigned I = 1; I != ModuleName.size(); ++I) { - auto *NewM = MM.findOrInferSubmodule( - M, ModuleName[I].getIdentifierInfo()->getName()); + auto *NewM = MM.findOrInferSubmodule(M, ModuleName[I].first->getName()); if (!NewM) { - PP.Diag(ModuleName[I].getLoc(), diag::err_pp_module_begin_no_submodule) - << M->getFullModuleName() << ModuleName[I].getIdentifierInfo(); + PP.Diag(ModuleName[I].second, diag::err_pp_module_begin_no_submodule) + << M->getFullModuleName() << ModuleName[I].first; return; } M = NewM; @@ -1789,7 +1791,7 @@ struct PragmaModuleBeginHandler : public PragmaHandler { // Enter the scope of the submodule. PP.EnterSubmodule(M, BeginLoc, /*ForPragma*/true); - PP.EnterAnnotationToken(SourceRange(BeginLoc, ModuleName.back().getLoc()), + PP.EnterAnnotationToken(SourceRange(BeginLoc, ModuleName.back().second), tok::annot_module_begin, M); } }; @@ -1833,7 +1835,8 @@ struct PragmaModuleLoadHandler : public PragmaHandler { SourceLocation Loc = Tok.getLocation(); // Read the module name. - llvm::SmallVector ModuleName; + llvm::SmallVector, 8> + ModuleName; if (LexModuleName(PP, Tok, ModuleName)) return; @@ -1898,7 +1901,7 @@ struct PragmaARCCFCodeAuditedHandler : public PragmaHandler { PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma"; // The start location of the active audit. - SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedInfo().getLoc(); + SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedInfo().second; // The start location we want after processing this. SourceLocation NewLoc; diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 4c050bf1f5bb2..c25a3efd899e0 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -1159,8 +1159,8 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) { if (Result.is(tok::colon) && ModuleDeclState.isNamedModule()) { std::string Name = ModuleDeclState.getPrimaryName().str(); Name += ":"; - NamedModuleImportPath.emplace_back(Result.getLocation(), - getIdentifierInfo(Name)); + NamedModuleImportPath.push_back( + {getIdentifierInfo(Name), Result.getLocation()}); CurLexerCallback = CLK_LexAfterModuleImport; return true; } @@ -1258,8 +1258,8 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) { if (ModuleImportExpectsIdentifier && Result.getKind() == tok::identifier) { // We expected to see an identifier here, and we did; continue handling // identifiers. - NamedModuleImportPath.emplace_back(Result.getLocation(), - Result.getIdentifierInfo()); + NamedModuleImportPath.push_back( + std::make_pair(Result.getIdentifierInfo(), Result.getLocation())); ModuleImportExpectsIdentifier = false; CurLexerCallback = CLK_LexAfterModuleImport; return true; @@ -1302,12 +1302,12 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) { // If the FlatModuleName ends with colon, it implies it is a partition. if (!FlatModuleName.empty() && FlatModuleName.back() != ':') FlatModuleName += "."; - FlatModuleName += Piece.getIdentifierInfo()->getName(); + FlatModuleName += Piece.first->getName(); } - SourceLocation FirstPathLoc = NamedModuleImportPath[0].getLoc(); + SourceLocation FirstPathLoc = NamedModuleImportPath[0].second; NamedModuleImportPath.clear(); - NamedModuleImportPath.emplace_back(FirstPathLoc, - getIdentifierInfo(FlatModuleName)); + NamedModuleImportPath.push_back( + std::make_pair(getIdentifierInfo(FlatModuleName), FirstPathLoc)); } Module *Imported = nullptr; diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 8444ff3332e08..8fa74ecff19aa 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -432,8 +432,9 @@ static bool attributeParsedArgsUnevaluated(const IdentifierInfo &II, IdentifierLoc *Parser::ParseIdentifierLoc() { assert(Tok.is(tok::identifier) && "expected an identifier"); - IdentifierLoc *IL = new (Actions.Context) - IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo()); + IdentifierLoc *IL = IdentifierLoc::create(Actions.Context, + Tok.getLocation(), + Tok.getIdentifierInfo()); ConsumeToken(); return IL; } @@ -1352,21 +1353,20 @@ void Parser::ParseAvailabilityAttribute( return; } IdentifierLoc *Platform = ParseIdentifierLoc(); - if (const IdentifierInfo *const Ident = Platform->getIdentifierInfo()) { + if (const IdentifierInfo *const Ident = Platform->Ident) { // Disallow xrOS for availability attributes. if (Ident->getName().contains("xrOS") || Ident->getName().contains("xros")) - Diag(Platform->getLoc(), diag::warn_availability_unknown_platform) - << Ident; + Diag(Platform->Loc, diag::warn_availability_unknown_platform) << Ident; // Canonicalize platform name from "macosx" to "macos". else if (Ident->getName() == "macosx") - Platform->setIdentifierInfo(PP.getIdentifierInfo("macos")); + Platform->Ident = PP.getIdentifierInfo("macos"); // Canonicalize platform name from "macosx_app_extension" to // "macos_app_extension". else if (Ident->getName() == "macosx_app_extension") - Platform->setIdentifierInfo(PP.getIdentifierInfo("macos_app_extension")); + Platform->Ident = PP.getIdentifierInfo("macos_app_extension"); else - Platform->setIdentifierInfo(PP.getIdentifierInfo( - AvailabilityAttr::canonicalizePlatformName(Ident->getName()))); + Platform->Ident = PP.getIdentifierInfo( + AvailabilityAttr::canonicalizePlatformName(Ident->getName())); } // Parse the ',' following the platform name. @@ -1418,8 +1418,8 @@ void Parser::ParseAvailabilityAttribute( continue; } - if (Keyword == Ident_deprecated && Platform->getIdentifierInfo() && - Platform->getIdentifierInfo()->isStr("swift")) { + if (Keyword == Ident_deprecated && Platform->Ident && + Platform->Ident->isStr("swift")) { // For swift, we deprecate for all versions. if (Changes[Deprecated].KeywordLoc.isValid()) { Diag(KeywordLoc, diag::err_availability_redundant) @@ -1436,7 +1436,7 @@ void Parser::ParseAvailabilityAttribute( if (Keyword == Ident_environment) { if (EnvironmentLoc != nullptr) { Diag(KeywordLoc, diag::err_availability_redundant) - << Keyword << SourceRange(EnvironmentLoc->getLoc()); + << Keyword << SourceRange(EnvironmentLoc->Loc); } } @@ -1792,8 +1792,8 @@ void Parser::ParseSwiftNewTypeAttribute( return; } - auto *SwiftType = new (Actions.Context) - IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo()); + auto *SwiftType = IdentifierLoc::create(Actions.Context, Tok.getLocation(), + Tok.getIdentifierInfo()); ConsumeToken(); // Closing ')' diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 1416d52157dca..0a22f7372a9f9 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -4006,20 +4006,19 @@ std::optional Parser::ParseAvailabilitySpec() { if (Version.empty()) return std::nullopt; - StringRef GivenPlatform = - PlatformIdentifier->getIdentifierInfo()->getName(); + StringRef GivenPlatform = PlatformIdentifier->Ident->getName(); StringRef Platform = AvailabilityAttr::canonicalizePlatformName(GivenPlatform); if (AvailabilityAttr::getPrettyPlatformName(Platform).empty() || (GivenPlatform.contains("xros") || GivenPlatform.contains("xrOS"))) { - Diag(PlatformIdentifier->getLoc(), + Diag(PlatformIdentifier->Loc, diag::err_avail_query_unrecognized_platform_name) << GivenPlatform; return std::nullopt; } - return AvailabilitySpec(Version, Platform, PlatformIdentifier->getLoc(), + return AvailabilitySpec(Version, Platform, PlatformIdentifier->Loc, VersionRange.getEnd()); } } diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index 7ffacc4b79f79..f4c109f9a81a2 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -115,7 +115,7 @@ static void fixSeparateAttrArgAndNumber(StringRef ArgStr, SourceLocation ArgLoc, << FixedArg << FixItHint::CreateReplacement(SourceRange(ArgLoc, EndNumLoc), FixedArg); ArgsUnion &Slot = ArgExprs.back(); - Slot = new (Ctx) IdentifierLoc(ArgLoc, PP.getIdentifierInfo(FixedArg)); + Slot = IdentifierLoc::create(Ctx, ArgLoc, PP.getIdentifierInfo(FixedArg)); } void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index d872177b3d7aa..bcbf4dfbabafa 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -261,7 +261,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, // case, LAngleLoc will be valid and ProtocolIdents will capture the // protocol references (that have not yet been resolved). SourceLocation LAngleLoc, EndProtoLoc; - SmallVector ProtocolIdents; + SmallVector ProtocolIdents; ObjCTypeParamList *typeParameterList = nullptr; ObjCTypeParamListScope typeParamScope(Actions, getCurScope()); if (Tok.is(tok::less)) @@ -361,8 +361,8 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, if (!ProtocolIdents.empty()) { // We already parsed the protocols named when we thought we had a // type parameter list. Translate them into actual protocol references. - for (const auto &Loc : ProtocolIdents) { - protocolLocs.push_back(Loc.getLoc()); + for (const auto &pair : ProtocolIdents) { + protocolLocs.push_back(pair.second); } Actions.ObjC().FindProtocolDeclaration(/*WarnOnDeclarations=*/true, /*ForObjCContainer=*/true, @@ -459,8 +459,8 @@ static void addContextSensitiveTypeNullability(Parser &P, /// \param rAngleLoc The location of the ending '>'. ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs( ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc, - SmallVectorImpl &protocolIdents, SourceLocation &rAngleLoc, - bool mayBeProtocolList) { + SmallVectorImpl &protocolIdents, + SourceLocation &rAngleLoc, bool mayBeProtocolList) { assert(Tok.is(tok::less) && "Not at the beginning of a type parameter list"); // Within the type parameter list, don't treat '>' as an operator. @@ -474,8 +474,7 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs( for (const auto &pair : protocolIdents) { DeclResult typeParam = Actions.ObjC().actOnObjCTypeParam( getCurScope(), ObjCTypeParamVariance::Invariant, SourceLocation(), - index++, pair.getIdentifierInfo(), pair.getLoc(), SourceLocation(), - nullptr); + index++, pair.first, pair.second, SourceLocation(), nullptr); if (typeParam.isUsable()) typeParams.push_back(typeParam.get()); } @@ -547,7 +546,7 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs( } else if (mayBeProtocolList) { // If this could still be a protocol list, just capture the identifier. // We don't want to turn it into a parameter. - protocolIdents.emplace_back(paramLoc, paramName); + protocolIdents.push_back(std::make_pair(paramName, paramLoc)); continue; } @@ -607,7 +606,7 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs( /// Parse an objc-type-parameter-list. ObjCTypeParamList *Parser::parseObjCTypeParamList() { SourceLocation lAngleLoc; - SmallVector protocolIdents; + SmallVector protocolIdents; SourceLocation rAngleLoc; ObjCTypeParamListScope Scope(Actions, getCurScope()); @@ -1599,7 +1598,7 @@ ParseObjCProtocolReferences(SmallVectorImpl &Protocols, LAngleLoc = ConsumeToken(); // the "<" - SmallVector ProtocolIdents; + SmallVector ProtocolIdents; while (true) { if (Tok.is(tok::code_completion)) { @@ -1613,7 +1612,8 @@ ParseObjCProtocolReferences(SmallVectorImpl &Protocols, SkipUntil(tok::greater, StopAtSemi); return true; } - ProtocolIdents.emplace_back(Tok.getLocation(), Tok.getIdentifierInfo()); + ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), + Tok.getLocation())); ProtocolLocs.push_back(Tok.getLocation()); ConsumeToken(); @@ -1693,9 +1693,10 @@ void Parser::parseObjCTypeArgsOrProtocolQualifiers( if (Tok.is(tok::code_completion)) { // FIXME: Also include types here. - SmallVector identifierLocPairs; + SmallVector identifierLocPairs; for (unsigned i = 0, n = identifiers.size(); i != n; ++i) { - identifierLocPairs.emplace_back(identifierLocs[i], identifiers[i]); + identifierLocPairs.push_back(IdentifierLocPair(identifiers[i], + identifierLocs[i])); } QualType BaseT = Actions.GetTypeFromParser(baseType); @@ -2093,7 +2094,7 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, SourceLocation nameLoc = ConsumeToken(); if (TryConsumeToken(tok::semi)) { // forward declaration of one protocol. - IdentifierLoc ProtoInfo(nameLoc, protocolName); + IdentifierLocPair ProtoInfo(protocolName, nameLoc); return Actions.ObjC().ActOnForwardProtocolDeclaration(AtLoc, ProtoInfo, attrs); } @@ -2101,8 +2102,8 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, CheckNestedObjCContexts(AtLoc); if (Tok.is(tok::comma)) { // list of forward declarations. - SmallVector ProtocolRefs; - ProtocolRefs.emplace_back(nameLoc, protocolName); + SmallVector ProtocolRefs; + ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); // Parse the list of forward declarations. while (true) { @@ -2111,7 +2112,8 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, SkipUntil(tok::semi); return nullptr; } - ProtocolRefs.emplace_back(Tok.getLocation(), Tok.getIdentifierInfo()); + ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), + Tok.getLocation())); ConsumeToken(); // the identifier if (Tok.isNot(tok::comma)) @@ -2194,7 +2196,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc, // permitted here. Parse and diagnose them. if (Tok.is(tok::less)) { SourceLocation lAngleLoc, rAngleLoc; - SmallVector protocolIdents; + SmallVector protocolIdents; SourceLocation diagLoc = Tok.getLocation(); ObjCTypeParamListScope typeParamScope(Actions, getCurScope()); if (parseObjCTypeParamListOrProtocolRefs(typeParamScope, lAngleLoc, diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp index 337b3eca49764..64916995907c5 100644 --- a/clang/lib/Parse/ParseOpenACC.cpp +++ b/clang/lib/Parse/ParseOpenACC.cpp @@ -15,7 +15,6 @@ #include "clang/Basic/OpenACCKinds.h" #include "clang/Parse/Parser.h" #include "clang/Parse/RAIIObjectsForParser.h" -#include "clang/Sema/ParsedAttr.h" #include "clang/Sema/SemaOpenACC.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" @@ -815,7 +814,7 @@ bool Parser::ParseOpenACCIntExprList(OpenACCDirectiveKind DK, /// /// The device_type clause may be abbreviated to dtype. bool Parser::ParseOpenACCDeviceTypeList( - llvm::SmallVector &Archs) { + llvm::SmallVector> &Archs) { if (expectIdentifierOrKeyword(*this)) { SkipUntil(tok::r_paren, tok::annot_pragma_openacc_end, @@ -823,7 +822,7 @@ bool Parser::ParseOpenACCDeviceTypeList( return true; } IdentifierInfo *Ident = getCurToken().getIdentifierInfo(); - Archs.emplace_back(ConsumeToken(), Ident); + Archs.emplace_back(Ident, ConsumeToken()); while (!getCurToken().isOneOf(tok::r_paren, tok::annot_pragma_openacc_end)) { ExpectAndConsume(tok::comma); @@ -834,7 +833,7 @@ bool Parser::ParseOpenACCDeviceTypeList( return true; } Ident = getCurToken().getIdentifierInfo(); - Archs.emplace_back(ConsumeToken(), Ident); + Archs.emplace_back(Ident, ConsumeToken()); } return false; } @@ -1155,12 +1154,11 @@ Parser::OpenACCClauseParseResult Parser::ParseOpenACCClauseParams( } case OpenACCClauseKind::DType: case OpenACCClauseKind::DeviceType: { - llvm::SmallVector Archs; + llvm::SmallVector> Archs; if (getCurToken().is(tok::star)) { // FIXME: We want to mark that this is an 'everything else' type of // device_type in Sema. - ParsedClause.setDeviceTypeDetails( - {IdentifierLoc(ConsumeToken(), nullptr)}); + ParsedClause.setDeviceTypeDetails({{nullptr, ConsumeToken()}}); } else if (!ParseOpenACCDeviceTypeList(Archs)) { ParsedClause.setDeviceTypeDetails(std::move(Archs)); } else { diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp index 17b2b30942582..21ebff1e50559 100644 --- a/clang/lib/Parse/ParsePragma.cpp +++ b/clang/lib/Parse/ParsePragma.cpp @@ -1419,16 +1419,16 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) { static_cast(Tok.getAnnotationValue()); IdentifierInfo *PragmaNameInfo = Info->PragmaName.getIdentifierInfo(); - Hint.PragmaNameLoc = new (Actions.Context) - IdentifierLoc(Info->PragmaName.getLocation(), PragmaNameInfo); + Hint.PragmaNameLoc = IdentifierLoc::create( + Actions.Context, Info->PragmaName.getLocation(), PragmaNameInfo); // It is possible that the loop hint has no option identifier, such as // #pragma unroll(4). IdentifierInfo *OptionInfo = Info->Option.is(tok::identifier) ? Info->Option.getIdentifierInfo() : nullptr; - Hint.OptionLoc = new (Actions.Context) - IdentifierLoc(Info->Option.getLocation(), OptionInfo); + Hint.OptionLoc = IdentifierLoc::create( + Actions.Context, Info->Option.getLocation(), OptionInfo); llvm::ArrayRef Toks = Info->Toks; @@ -1508,7 +1508,7 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) { if (Toks.size() > 2) Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << PragmaLoopHintString(Info->PragmaName, Info->Option); - Hint.StateLoc = new (Actions.Context) IdentifierLoc(StateLoc, StateInfo); + Hint.StateLoc = IdentifierLoc::create(Actions.Context, StateLoc, StateInfo); } else if (OptionInfo && OptionInfo->getName() == "vectorize_width") { PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/false, /*IsReinject=*/false); @@ -1529,7 +1529,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) { ConsumeAnyToken(); } - Hint.StateLoc = new (Actions.Context) IdentifierLoc(StateLoc, StateInfo); + Hint.StateLoc = + IdentifierLoc::create(Actions.Context, StateLoc, StateInfo); ConsumeToken(); // Consume the constant expression eof terminator. } else { @@ -1553,7 +1554,7 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) { Arg2Error = true; } else Hint.StateLoc = - new (Actions.Context) IdentifierLoc(StateLoc, StateInfo); + IdentifierLoc::create(Actions.Context, StateLoc, StateInfo); PP.Lex(Tok); // Identifier } diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 4a82d57fe566b..e8ec140fbe3e5 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -2545,9 +2545,9 @@ StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts, ArgsUnion ArgHints[] = {Hint.PragmaNameLoc, Hint.OptionLoc, Hint.StateLoc, ArgsUnion(Hint.ValueExpr)}; - TempAttrs.addNew(Hint.PragmaNameLoc->getIdentifierInfo(), Hint.Range, - /*scopeName=*/nullptr, Hint.PragmaNameLoc->getLoc(), - ArgHints, /*numArgs=*/4, ParsedAttr::Form::Pragma()); + TempAttrs.addNew(Hint.PragmaNameLoc->Ident, Hint.Range, nullptr, + Hint.PragmaNameLoc->Loc, ArgHints, 4, + ParsedAttr::Form::Pragma()); } // Get the next statement. diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index d528664bca352..f3191762b1244 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -2541,17 +2541,17 @@ Parser::ParseModuleDecl(Sema::ModuleImportState &ImportState) { return Actions.ActOnPrivateModuleFragmentDecl(ModuleLoc, PrivateLoc); } - SmallVector Path; + SmallVector, 2> Path; if (ParseModuleName(ModuleLoc, Path, /*IsImport*/ false)) return nullptr; // Parse the optional module-partition. - SmallVector Partition; + SmallVector, 2> Partition; if (Tok.is(tok::colon)) { SourceLocation ColonLoc = ConsumeToken(); if (!getLangOpts().CPlusPlusModules) Diag(ColonLoc, diag::err_unsupported_module_partition) - << SourceRange(ColonLoc, Partition.back().getLoc()); + << SourceRange(ColonLoc, Partition.back().second); // Recover by ignoring the partition name. else if (ParseModuleName(ModuleLoc, Partition, /*IsImport*/ false)) return nullptr; @@ -2600,7 +2600,7 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc = ConsumeToken(); // For C++20 modules, we can have "name" or ":Partition name" as valid input. - SmallVector Path; + SmallVector, 2> Path; bool IsPartition = false; Module *HeaderUnit = nullptr; if (Tok.is(tok::header_name)) { @@ -2616,7 +2616,7 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc, SourceLocation ColonLoc = ConsumeToken(); if (!getLangOpts().CPlusPlusModules) Diag(ColonLoc, diag::err_unsupported_module_partition) - << SourceRange(ColonLoc, Path.back().getLoc()); + << SourceRange(ColonLoc, Path.back().second); // Recover by leaving partition empty. else if (ParseModuleName(ColonLoc, Path, /*IsImport*/ true)) return nullptr; @@ -2718,9 +2718,10 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc, /// module-name-qualifier[opt] identifier /// module-name-qualifier: /// module-name-qualifier[opt] identifier '.' -bool Parser::ParseModuleName(SourceLocation UseLoc, - SmallVectorImpl &Path, - bool IsImport) { +bool Parser::ParseModuleName( + SourceLocation UseLoc, + SmallVectorImpl> &Path, + bool IsImport) { // Parse the module path. while (true) { if (!Tok.is(tok::identifier)) { @@ -2736,7 +2737,7 @@ bool Parser::ParseModuleName(SourceLocation UseLoc, } // Record this part of the module path. - Path.emplace_back(Tok.getLocation(), Tok.getIdentifierInfo()); + Path.push_back(std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation())); ConsumeToken(); if (Tok.isNot(tok::period)) diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp index c149cef478539..b19a02b8c1a09 100644 --- a/clang/lib/Sema/ParsedAttr.cpp +++ b/clang/lib/Sema/ParsedAttr.cpp @@ -23,6 +23,14 @@ 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 5bcbe78e9d633..3f53fb200a93d 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)->getIdentifierInfo(); + IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident; unsigned BuiltinID = Ident->getBuiltinID(); StringRef AliasName = cast(D)->getIdentifier()->getName(); diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 1e4e6fdc78351..f6ec4cb0f069e 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 Protocols) { + ArrayRef 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 IdentifierLoc &Pair : Protocols) - if (ObjCProtocolDecl *Protocol = SemaRef.ObjC().LookupProtocol( - Pair.getIdentifierInfo(), Pair.getLoc())) + for (const IdentifierLocPair &Pair : Protocols) + if (ObjCProtocolDecl *Protocol = + SemaRef.ObjC().LookupProtocol(Pair.first, Pair.second)) Results.Ignore(Protocol); // Add all protocols. diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 7dd20a8795fc9..bc891fb009410 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->getLoc(), diag::err_attribute_argument_type) + Diag(Loc->Loc, diag::err_attribute_argument_type) << AL << AANT_ArgumentString - << FixItHint::CreateInsertion(Loc->getLoc(), "\"") - << FixItHint::CreateInsertion(getLocForEndOfToken(Loc->getLoc()), "\""); - Str = Loc->getIdentifierInfo()->getName(); + << FixItHint::CreateInsertion(Loc->Loc, "\"") + << FixItHint::CreateInsertion(getLocForEndOfToken(Loc->Loc), "\""); + Str = Loc->Ident->getName(); if (ArgLocation) - *ArgLocation = Loc->getLoc(); + *ArgLocation = Loc->Loc; return true; } @@ -768,7 +768,7 @@ static void handleDiagnoseAsBuiltinAttr(Sema &S, Decl *D, auto Union = AL.getArg(Index - 1); if (auto *E = dyn_cast(Union)) return E->getBeginLoc(); - return cast(Union)->getLoc(); + return cast(Union)->Loc; }(); 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->getIdentifierInfo()->getName(), DefaultState)) { - S.Diag(IL->getLoc(), diag::warn_attribute_type_not_supported) - << AL << IL->getIdentifierInfo(); + if (!ConsumableAttr::ConvertStrToConsumedState(IL->Ident->getName(), + DefaultState)) { + S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL + << IL->Ident; 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->getIdentifierInfo()->getName(); - Loc = Ident->getLoc(); + StateString = Ident->Ident->getName(); + Loc = Ident->Loc; } 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->getIdentifierInfo()->getName(); + StringRef StateString = Ident->Ident->getName(); if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString, ParamState)) { - S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported) + S.Diag(Ident->Loc, 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->getIdentifierInfo()->getName(), ReturnState)) { - S.Diag(IL->getLoc(), diag::warn_attribute_type_not_supported) - << AL << IL->getIdentifierInfo(); + if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->Ident->getName(), + ReturnState)) { + S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL + << IL->Ident; 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->getIdentifierInfo()->getName(); + StringRef Param = Ident->Ident->getName(); if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) { - S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported) - << AL << Param; + S.Diag(Ident->Loc, 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->getIdentifierInfo()->getName(); + StringRef Param = Ident->Ident->getName(); if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) { - S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported) - << AL << Param; + S.Diag(Ident->Loc, 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)->getIdentifierInfo(); + IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident; 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->getIdentifierInfo()->getName().trim(); + StringRef CPUName = CPUArg->Ident->getName().trim(); if (!S.Context.getTargetInfo().validateCPUSpecificCPUDispatch(CPUName)) { - S.Diag(CPUArg->getLoc(), diag::err_invalid_cpu_specific_dispatch_value) + S.Diag(CPUArg->Loc, 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->getIdentifierInfo()); + CPUs.push_back(CPUArg->Ident); } 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->getIdentifierInfo(); + IdentifierInfo *II = Platform->Ident; if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty()) - S.Diag(Platform->getLoc(), diag::warn_availability_unknown_platform) - << Platform->getIdentifierInfo(); + S.Diag(Platform->Loc, diag::warn_availability_unknown_platform) + << Platform->Ident; auto *ND = dyn_cast(D); if (!ND) // We warned about this already, so just return. @@ -2410,16 +2410,14 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { IdentifierInfo *IIEnvironment = nullptr; if (EnvironmentLoc) { if (S.getLangOpts().HLSL) { - IIEnvironment = EnvironmentLoc->getIdentifierInfo(); + IIEnvironment = EnvironmentLoc->Ident; if (AvailabilityAttr::getEnvironmentType( - EnvironmentLoc->getIdentifierInfo()->getName()) == + EnvironmentLoc->Ident->getName()) == llvm::Triple::EnvironmentType::UnknownEnvironment) - S.Diag(EnvironmentLoc->getLoc(), - diag::warn_availability_unknown_environment) - << EnvironmentLoc->getIdentifierInfo(); + S.Diag(EnvironmentLoc->Loc, diag::warn_availability_unknown_environment) + << EnvironmentLoc->Ident; } else { - S.Diag(EnvironmentLoc->getLoc(), - diag::err_availability_unexpected_parameter) + S.Diag(EnvironmentLoc->Loc, diag::err_availability_unexpected_parameter) << "environment" << /* C/C++ */ 1; } } @@ -3632,7 +3630,7 @@ static void handleEnumExtensibilityAttr(Sema &S, Decl *D, } EnumExtensibilityAttr::Kind ExtensibilityKind; - IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); + IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; if (!EnumExtensibilityAttr::ConvertStrToKind(II->getName(), ExtensibilityKind)) { S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; @@ -3855,7 +3853,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)->getIdentifierInfo(); + Info->Identifier = AL.getArgAsIdent(0)->Ident; StringRef Format = Info->Identifier->getName(); if (normalizeName(Format)) { @@ -4019,14 +4017,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->getIdentifierInfo()->getName()); + auto It = NameIdxMapping.find(IdLoc->Ident->getName()); if (It == UnknownName) { S.Diag(AL.getLoc(), diag::err_callback_attribute_argument_unknown) - << IdLoc->getIdentifierInfo() << IdLoc->getLoc(); + << IdLoc->Ident << IdLoc->Loc; return; } - SR = SourceRange(IdLoc->getLoc()); + SR = SourceRange(IdLoc->Loc); ArgIdx = It->second; } else if (AL.isArgExpr(I)) { Expr *IdxExpr = AL.getArgAsExpr(I); @@ -4144,14 +4142,13 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL, } assert(AL.isArgIdent(I)); IdentifierLoc *IdLoc = AL.getArgAsIdent(I); - if (IdLoc->getIdentifierInfo()->getName() == ParamName) { - Diag(IdLoc->getLoc(), diag::err_capture_by_references_itself) - << IdLoc->getLoc(); + if (IdLoc->Ident->getName() == ParamName) { + Diag(IdLoc->Loc, diag::err_capture_by_references_itself) << IdLoc->Loc; IsValid = false; continue; } - ParamIdents[I] = IdLoc->getIdentifierInfo(); - ParamLocs[I] = IdLoc->getLoc(); + ParamIdents[I] = IdLoc->Ident; + ParamLocs[I] = IdLoc->Loc; } if (!IsValid) return nullptr; @@ -4757,7 +4754,7 @@ static void handleModeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *Name = AL.getArgAsIdent(0)->getIdentifierInfo(); + IdentifierInfo *Name = AL.getArgAsIdent(0)->Ident; S.AddModeAttr(D, AL, Name); } @@ -5730,8 +5727,8 @@ static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D, } D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr( - S.Context, AL, AL.getArgAsIdent(0)->getIdentifierInfo(), ArgumentIdx, - TypeTagIdx, IsPointer)); + S.Context, AL, AL.getArgAsIdent(0)->Ident, ArgumentIdx, TypeTagIdx, + IsPointer)); } static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, @@ -5751,7 +5748,7 @@ static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, return; } - IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->getIdentifierInfo(); + IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->Ident; TypeSourceInfo *MatchingCTypeLoc = nullptr; S.GetTypeFromParser(AL.getMatchingCType(), &MatchingCTypeLoc); assert(MatchingCTypeLoc && "no type source info for attribute argument"); @@ -5822,7 +5819,7 @@ static void handleBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *Ident = AL.getArgAsIdent(0)->getIdentifierInfo(); + IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident; unsigned BuiltinID = Ident->getBuiltinID(); StringRef AliasName = cast(D)->getIdentifier()->getName(); @@ -6588,7 +6585,7 @@ static void handleCFGuardAttr(Sema &S, Decl *D, const ParsedAttr &AL) { } CFGuardAttr::GuardArg Arg; - IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); + IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; if (!CFGuardAttr::ConvertStrToGuardArg(II->getName(), Arg)) { S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; return; @@ -6690,9 +6687,8 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D, if (AL.isArgIdent(0)) { IdentifierLoc *IL = AL.getArgAsIdent(0); if (!VTablePointerAuthenticationAttr::ConvertStrToVPtrAuthKeyType( - IL->getIdentifierInfo()->getName(), KeyType)) { - S.Diag(IL->getLoc(), diag::err_invalid_authentication_key) - << IL->getIdentifierInfo(); + IL->Ident->getName(), KeyType)) { + S.Diag(IL->Loc, diag::err_invalid_authentication_key) << IL->Ident; AL.setInvalid(); } if (KeyType == VTablePointerAuthenticationAttr::DefaultKey && @@ -6712,16 +6708,15 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D, if (AL.isArgIdent(1)) { IdentifierLoc *IL = AL.getArgAsIdent(1); if (!VTablePointerAuthenticationAttr:: - ConvertStrToAddressDiscriminationMode( - IL->getIdentifierInfo()->getName(), AddressDiversityMode)) { - S.Diag(IL->getLoc(), diag::err_invalid_address_discrimination) - << IL->getIdentifierInfo(); + ConvertStrToAddressDiscriminationMode(IL->Ident->getName(), + AddressDiversityMode)) { + S.Diag(IL->Loc, diag::err_invalid_address_discrimination) << IL->Ident; AL.setInvalid(); } if (AddressDiversityMode == VTablePointerAuthenticationAttr::DefaultAddressDiscrimination && !S.getLangOpts().PointerAuthCalls) { - S.Diag(IL->getLoc(), diag::err_no_default_vtable_pointer_auth) << 1; + S.Diag(IL->Loc, diag::err_no_default_vtable_pointer_auth) << 1; AL.setInvalid(); } } else { @@ -6736,9 +6731,8 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D, if (AL.isArgIdent(2)) { IdentifierLoc *IL = AL.getArgAsIdent(2); if (!VTablePointerAuthenticationAttr::ConvertStrToExtraDiscrimination( - IL->getIdentifierInfo()->getName(), ED)) { - S.Diag(IL->getLoc(), diag::err_invalid_extra_discrimination) - << IL->getIdentifierInfo(); + IL->Ident->getName(), ED)) { + S.Diag(IL->Loc, diag::err_invalid_extra_discrimination) << IL->Ident; AL.setInvalid(); } if (ED == VTablePointerAuthenticationAttr::DefaultExtraDiscrimination && diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 0a14ce23a396e..ba9d3dcf19617 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -1310,26 +1310,24 @@ static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl, /// protocol declarations in its 'Protocols' argument. void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, - ArrayRef ProtocolId, + ArrayRef ProtocolId, SmallVectorImpl &Protocols) { - for (const IdentifierLoc &Pair : ProtocolId) { - ObjCProtocolDecl *PDecl = - LookupProtocol(Pair.getIdentifierInfo(), Pair.getLoc()); + for (const IdentifierLocPair &Pair : ProtocolId) { + ObjCProtocolDecl *PDecl = LookupProtocol(Pair.first, Pair.second); if (!PDecl) { DeclFilterCCC CCC{}; - TypoCorrection Corrected = SemaRef.CorrectTypo( - DeclarationNameInfo(Pair.getIdentifierInfo(), Pair.getLoc()), - Sema::LookupObjCProtocolName, SemaRef.TUScope, nullptr, CCC, - Sema::CTK_ErrorRecovery); + TypoCorrection Corrected = + SemaRef.CorrectTypo(DeclarationNameInfo(Pair.first, Pair.second), + Sema::LookupObjCProtocolName, SemaRef.TUScope, + nullptr, CCC, Sema::CTK_ErrorRecovery); if ((PDecl = Corrected.getCorrectionDeclAs())) SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_undeclared_protocol_suggest) - << Pair.getIdentifierInfo()); + << Pair.first); } if (!PDecl) { - Diag(Pair.getLoc(), diag::err_undeclared_protocol) - << Pair.getIdentifierInfo(); + Diag(Pair.second, diag::err_undeclared_protocol) << Pair.first; continue; } // If this is a forward protocol declaration, get its definition. @@ -1339,7 +1337,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.getLoc()); + (void)SemaRef.DiagnoseUseOfDecl(PDecl, Pair.second); } // If this is a forward declaration and we are supposed to warn in this @@ -1349,8 +1347,7 @@ void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations, if (WarnOnDeclarations && NestedProtocolHasNoDefinition(PDecl, UndefinedProtocol)) { - Diag(Pair.getLoc(), diag::warn_undef_protocolref) - << Pair.getIdentifierInfo(); + Diag(Pair.second, diag::warn_undef_protocolref) << Pair.first; Diag(UndefinedProtocol->getLocation(), diag::note_protocol_decl_undefined) << UndefinedProtocol; } @@ -1787,17 +1784,17 @@ void SemaObjC::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, /// ActOnForwardProtocolDeclaration - Handle \@protocol foo; SemaObjC::DeclGroupPtrTy SemaObjC::ActOnForwardProtocolDeclaration( - SourceLocation AtProtocolLoc, ArrayRef IdentList, + SourceLocation AtProtocolLoc, ArrayRef IdentList, const ParsedAttributesView &attrList) { ASTContext &Context = getASTContext(); SmallVector DeclsInGroup; - for (const IdentifierLoc &IdentPair : IdentList) { - IdentifierInfo *Ident = IdentPair.getIdentifierInfo(); + for (const IdentifierLocPair &IdentPair : IdentList) { + IdentifierInfo *Ident = IdentPair.first; ObjCProtocolDecl *PrevDecl = LookupProtocol( - Ident, IdentPair.getLoc(), SemaRef.forRedeclarationInCurContext()); + Ident, IdentPair.second, SemaRef.forRedeclarationInCurContext()); ObjCProtocolDecl *PDecl = ObjCProtocolDecl::Create(Context, SemaRef.CurContext, Ident, - IdentPair.getLoc(), AtProtocolLoc, PrevDecl); + IdentPair.second, AtProtocolLoc, PrevDecl); SemaRef.PushOnScopeChains(PDecl, SemaRef.TUScope); CheckObjCDeclScope(PDecl); diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 11f156ae09216..0b442b75d174d 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -1274,8 +1274,8 @@ bool SemaHLSL::handleResourceTypeAttr(QualType T, const ParsedAttr &AL) { } IdentifierLoc *Loc = AL.getArgAsIdent(0); - StringRef Identifier = Loc->getIdentifierInfo()->getName(); - SourceLocation ArgLoc = Loc->getLoc(); + StringRef Identifier = Loc->Ident->getName(); + SourceLocation ArgLoc = Loc->Loc; // Validate resource class value ResourceClass RC; @@ -1534,8 +1534,8 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) { } IdentifierLoc *Loc = AL.getArgAsIdent(0); - StringRef Str = Loc->getIdentifierInfo()->getName(); - SourceLocation ArgLoc = Loc->getLoc(); + StringRef Str = Loc->Ident->getName(); + SourceLocation ArgLoc = Loc->Loc; SourceLocation SpaceArgLoc; bool SpecifiedSpace = false; @@ -1549,8 +1549,8 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) { } IdentifierLoc *Loc = AL.getArgAsIdent(1); - Space = Loc->getIdentifierInfo()->getName(); - SpaceArgLoc = Loc->getLoc(); + Space = Loc->Ident->getName(); + SpaceArgLoc = Loc->Loc; } else { Slot = Str; } diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 4bba57193ded6..76589bff40be9 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -15,7 +15,6 @@ #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" @@ -69,7 +68,7 @@ static std::string stringFromPath(ModuleIdPath Path) { for (auto &Piece : Path) { if (!Name.empty()) Name += "."; - Name += Piece.getIdentifierInfo()->getName(); + Name += Piece.first->getName(); } return Name; } @@ -351,18 +350,17 @@ 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].getIdentifierInfo()->getName(); - if (!getSourceManager().isInSystemHeader(Path[0].getLoc()) && + StringRef FirstComponentName = Path[0].first->getName(); + if (!getSourceManager().isInSystemHeader(Path[0].second) && (FirstComponentName == "std" || (FirstComponentName.starts_with("std") && llvm::all_of(FirstComponentName.drop_front(3), &llvm::isDigit)))) - Diag(Path[0].getLoc(), diag::warn_reserved_module_name) - << Path[0].getIdentifierInfo(); + Diag(Path[0].second, diag::warn_reserved_module_name) << Path[0].first; // 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.getIdentifierInfo(), Part.getLoc())) + if (DiagReservedModuleName(*this, Part.first, Part.second)) return nullptr; } @@ -378,10 +376,10 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // correct. if (!getLangOpts().CurrentModule.empty() && getLangOpts().CurrentModule != ModuleName) { - Diag(Path.front().getLoc(), diag::err_current_module_name_mismatch) - << SourceRange(Path.front().getLoc(), IsPartition - ? Partition.back().getLoc() - : Path.back().getLoc()) + Diag(Path.front().second, diag::err_current_module_name_mismatch) + << SourceRange(Path.front().second, IsPartition + ? Partition.back().second + : Path.back().second) << getLangOpts().CurrentModule; return nullptr; } @@ -396,7 +394,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].getLoc(), diag::err_module_redefinition) << ModuleName; + Diag(Path[0].second, diag::err_module_redefinition) << ModuleName; if (M->DefinitionLoc.isValid()) Diag(M->DefinitionLoc, diag::note_prev_module_definition); else if (OptionalFileEntryRef FE = M->getASTFile()) @@ -419,8 +417,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. - IdentifierLoc ModuleNameLoc(Path[0].getLoc(), - PP.getIdentifierInfo(ModuleName)); + std::pair ModuleNameLoc( + PP.getIdentifierInfo(ModuleName), Path[0].second); // The module loader will assume we're trying to import the module that // we're building if `LangOpts.CurrentModule` equals to 'ModuleName'. @@ -492,7 +490,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].getLoc()); + Interface, Path[0].second); CurContext->addDecl(Import); // Sequence initialization of the imported module before that of the current @@ -581,7 +579,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. - IdentifierLoc ModuleNameLoc; + std::pair ModuleNameLoc; std::string ModuleName; if (IsPartition) { @@ -593,13 +591,11 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, ModuleName = NamedMod->getPrimaryModuleInterfaceName().str(); ModuleName += ":"; ModuleName += stringFromPath(Path); - ModuleNameLoc = - IdentifierLoc(Path[0].getLoc(), PP.getIdentifierInfo(ModuleName)); + ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second}; Path = ModuleIdPath(ModuleNameLoc); } else if (getLangOpts().CPlusPlusModules) { ModuleName = stringFromPath(Path); - ModuleNameLoc = - IdentifierLoc(Path[0].getLoc(), PP.getIdentifierInfo(ModuleName)); + ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second}; Path = ModuleIdPath(ModuleNameLoc); } @@ -684,7 +680,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].getLoc()); + IdentifierLocs.push_back(Path[0].second); } else { Module *ModCheck = Mod; for (unsigned I = 0, N = Path.size(); I != N; ++I) { @@ -694,7 +690,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, break; ModCheck = ModCheck->Parent; - IdentifierLocs.push_back(Path[I].getLoc()); + IdentifierLocs.push_back(Path[I].second); } } @@ -711,7 +707,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().getLoc()); + << SourceRange(ExportLoc, Path.back().second); } 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 9b24b5f052119..073d9791d037b 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -1446,8 +1446,10 @@ SemaObjC::ObjCSubscriptKind SemaObjC::CheckSubscriptingKind(Expr *FromE) { void SemaObjC::AddCFAuditedAttribute(Decl *D) { ASTContext &Context = getASTContext(); - auto IdLoc = SemaRef.PP.getPragmaARCCFCodeAuditedInfo(); - if (!IdLoc.getLoc().isValid()) + IdentifierInfo *Ident; + SourceLocation Loc; + std::tie(Ident, Loc) = SemaRef.PP.getPragmaARCCFCodeAuditedInfo(); + if (!Loc.isValid()) return; // Don't add a redundant or conflicting attribute. @@ -1455,8 +1457,7 @@ void SemaObjC::AddCFAuditedAttribute(Decl *D) { D->hasAttr()) return; - AttributeCommonInfo Info(IdLoc.getIdentifierInfo(), - SourceRange(IdLoc.getLoc()), + AttributeCommonInfo Info(Ident, SourceRange(Loc), AttributeCommonInfo::Form::Pragma()); D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info)); } @@ -1641,10 +1642,8 @@ void SemaObjC::handleMethodFamilyAttr(Decl *D, const ParsedAttr &AL) { IdentifierLoc *IL = AL.getArgAsIdent(0); ObjCMethodFamilyAttr::FamilyKind F; - if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind( - IL->getIdentifierInfo()->getName(), F)) { - Diag(IL->getLoc(), diag::warn_attribute_type_not_supported) - << AL << IL->getIdentifierInfo(); + if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->Ident->getName(), F)) { + Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL << IL->Ident; return; } @@ -1707,7 +1706,7 @@ void SemaObjC::handleBlocksAttr(Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); + IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; BlocksAttr::BlockType type; if (!BlocksAttr::ConvertStrToBlockType(II->getName(), type)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; @@ -1999,7 +1998,7 @@ void SemaObjC::handleNSErrorDomain(Decl *D, const ParsedAttr &Attr) { IdentifierLoc *IdentLoc = Attr.isArgIdent(0) ? Attr.getArgAsIdent(0) : nullptr; - if (!IdentLoc || !IdentLoc->getIdentifierInfo()) { + if (!IdentLoc || !IdentLoc->Ident) { // Try to locate the argument directly. SourceLocation Loc = Attr.getLoc(); if (Attr.isArgExpr(0) && Attr.getArgAsExpr(0)) @@ -2010,18 +2009,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->getIdentifierInfo()), + LookupResult Result(SemaRef, DeclarationName(IdentLoc->Ident), SourceLocation(), Sema::LookupNameKind::LookupOrdinaryName); if (!SemaRef.LookupName(Result, SemaRef.TUScope) || !Result.getAsSingle()) { - Diag(IdentLoc->getLoc(), diag::err_nserrordomain_invalid_decl) - << 1 << IdentLoc->getIdentifierInfo(); + Diag(IdentLoc->Loc, diag::err_nserrordomain_invalid_decl) + << 1 << IdentLoc->Ident; return; } - D->addAttr(::new (getASTContext()) NSErrorDomainAttr( - getASTContext(), Attr, IdentLoc->getIdentifierInfo())); + D->addAttr(::new (getASTContext()) + NSErrorDomainAttr(getASTContext(), Attr, IdentLoc->Ident)); } void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) { @@ -2034,7 +2033,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(D)) { - if (!Parm->getIdentifierInfo()->isStr("id")) { + if (!Parm->Ident->isStr("id")) { Diag(AL.getLoc(), diag::err_objc_attr_typedef_not_id) << AL; return; } @@ -2047,8 +2046,8 @@ void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) { } } - D->addAttr(::new (getASTContext()) ObjCBridgeAttr(getASTContext(), AL, - Parm->getIdentifierInfo())); + D->addAttr(::new (getASTContext()) + ObjCBridgeAttr(getASTContext(), AL, Parm->Ident)); } void SemaObjC::handleBridgeMutableAttr(Decl *D, const ParsedAttr &AL) { @@ -2059,21 +2058,21 @@ void SemaObjC::handleBridgeMutableAttr(Decl *D, const ParsedAttr &AL) { return; } - D->addAttr(::new (getASTContext()) ObjCBridgeMutableAttr( - getASTContext(), AL, Parm->getIdentifierInfo())); + D->addAttr(::new (getASTContext()) + ObjCBridgeMutableAttr(getASTContext(), AL, Parm->Ident)); } void SemaObjC::handleBridgeRelatedAttr(Decl *D, const ParsedAttr &AL) { IdentifierInfo *RelatedClass = - AL.isArgIdent(0) ? AL.getArgAsIdent(0)->getIdentifierInfo() : nullptr; + AL.isArgIdent(0) ? AL.getArgAsIdent(0)->Ident : nullptr; if (!RelatedClass) { Diag(D->getBeginLoc(), diag::err_objc_attr_not_id) << AL << 0; return; } IdentifierInfo *ClassMethod = - AL.getArgAsIdent(1) ? AL.getArgAsIdent(1)->getIdentifierInfo() : nullptr; + AL.getArgAsIdent(1) ? AL.getArgAsIdent(1)->Ident : nullptr; IdentifierInfo *InstanceMethod = - AL.getArgAsIdent(2) ? AL.getArgAsIdent(2)->getIdentifierInfo() : nullptr; + AL.getArgAsIdent(2) ? AL.getArgAsIdent(2)->Ident : 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 049baead031a1..ab25dcfd1a081 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].getLoc(), + SemaRef.Diag(Clause.getDeviceTypeArchitectures()[1].second, diag::err_acc_device_type_multiple_archs); return nullptr; } @@ -1369,17 +1369,16 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause( bool Diagnosed = false; auto FilterPred = [&](const DeviceTypeArgument &Arch) { // The '*' case. - if (!Arch.getIdentifierInfo()) + if (!Arch.first) return false; return llvm::find_if(ValidValues, [&](StringRef RHS) { - return Arch.getIdentifierInfo()->getName().equals_insensitive(RHS); + return Arch.first->getName().equals_insensitive(RHS); }) == ValidValues.end(); }; auto Diagnose = [&](const DeviceTypeArgument &Arch) { - Diagnosed = SemaRef.Diag(Arch.getLoc(), diag::err_acc_invalid_default_type) - << Arch.getIdentifierInfo() << Clause.getClauseKind() - << ValidValuesString; + Diagnosed = SemaRef.Diag(Arch.second, diag::err_acc_invalid_default_type) + << Arch.first << 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 a09626c3a9a8c..2f719c6d7a21e 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -79,10 +79,9 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, Expr *ValueExpr = A.getArgAsExpr(3); StringRef PragmaName = - llvm::StringSwitch( - PragmaNameLoc->getIdentifierInfo()->getName()) + llvm::StringSwitch(PragmaNameLoc->Ident->getName()) .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam", - PragmaNameLoc->getIdentifierInfo()->getName()) + PragmaNameLoc->Ident->getName()) .Default("clang loop"); // This could be handled automatically by adding a Subjects definition in @@ -128,10 +127,10 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Enable); } else { // #pragma clang loop ... - assert(OptionLoc && OptionLoc->getIdentifierInfo() && + assert(OptionLoc && OptionLoc->Ident && "Attribute must have valid option info."); Option = llvm::StringSwitch( - OptionLoc->getIdentifierInfo()->getName()) + OptionLoc->Ident->getName()) .Case("vectorize", LoopHintAttr::Vectorize) .Case("vectorize_width", LoopHintAttr::VectorizeWidth) .Case("interleave", LoopHintAttr::Interleave) @@ -145,13 +144,12 @@ 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->getIdentifierInfo())) && + assert((ValueExpr || (StateLoc && StateLoc->Ident)) && "Attribute must have a valid value expression or argument."); if (ValueExpr && S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc(), /*AllowZero=*/false)) return nullptr; - if (StateLoc && StateLoc->getIdentifierInfo() && - StateLoc->getIdentifierInfo()->isStr("scalable")) + if (StateLoc && StateLoc->Ident && StateLoc->Ident->isStr("scalable")) State = LoopHintAttr::ScalableWidth; else State = LoopHintAttr::FixedWidth; @@ -169,15 +167,14 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, Option == LoopHintAttr::Unroll || Option == LoopHintAttr::Distribute || Option == LoopHintAttr::PipelineDisabled) { - assert(StateLoc && StateLoc->getIdentifierInfo() && - "Loop hint must have an argument"); - if (StateLoc->getIdentifierInfo()->isStr("disable")) + assert(StateLoc && StateLoc->Ident && "Loop hint must have an argument"); + if (StateLoc->Ident->isStr("disable")) State = LoopHintAttr::Disable; - else if (StateLoc->getIdentifierInfo()->isStr("assume_safety")) + else if (StateLoc->Ident->isStr("assume_safety")) State = LoopHintAttr::AssumeSafety; - else if (StateLoc->getIdentifierInfo()->isStr("full")) + else if (StateLoc->Ident->isStr("full")) State = LoopHintAttr::Full; - else if (StateLoc->getIdentifierInfo()->isStr("enable")) + else if (StateLoc->Ident->isStr("enable")) State = LoopHintAttr::Enable; else llvm_unreachable("bad loop hint argument"); @@ -647,8 +644,8 @@ static Attr *handleAtomicAttr(Sema &S, Stmt *St, const ParsedAttr &AL, } IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex); - OptionString = Ident->getIdentifierInfo()->getName(); - Loc = Ident->getLoc(); + OptionString = Ident->Ident->getName(); + Loc = Ident->Loc; 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 4aae855a24b8f..fe72d6c85c37a 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)->getIdentifierInfo()->getName() - << isa(D) << /*pointer*/ 1; + << AL << AL.getArgAsIdent(0)->Ident->getName() << isa(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)->getIdentifierInfo()->getName() - << isa(D) << /*integral*/ 0; + << AL << AL.getArgAsIdent(0)->Ident->getName() << isa(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->getIdentifierInfo()->getName(), Convention)) { + if (!SwiftErrorAttr::ConvertStrToConventionKind(Loc->Ident->getName(), + Convention)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) - << AL << Loc->getIdentifierInfo(); + << AL << Loc->Ident; 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->getIdentifierInfo()->getName(), ConvKind)) { + if (!SwiftAsyncErrorAttr::ConvertStrToConventionKind(IDLoc->Ident->getName(), + ConvKind)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) - << AL << IDLoc->getIdentifierInfo(); + << AL << IDLoc->Ident; return; } @@ -643,7 +643,7 @@ void SemaSwift::handleNewType(Decl *D, const ParsedAttr &AL) { } SwiftNewTypeAttr::NewtypeKind Kind; - IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); + IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; 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)->getIdentifierInfo(); + IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; 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 87682233c5246..dc7e3a0bf8875 100644 --- a/clang/lib/Sema/SemaTemplateVariadic.cpp +++ b/clang/lib/Sema/SemaTemplateVariadic.cpp @@ -14,7 +14,6 @@ #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" @@ -756,7 +755,7 @@ bool Sema::CheckParameterPacksForExpansion( bool &RetainExpansion, UnsignedOrNone &NumExpansions) { ShouldExpand = true; RetainExpansion = false; - IdentifierLoc FirstPack; + std::pair FirstPack; bool HaveFirstPack = false; UnsignedOrNone NumPartialExpansions = std::nullopt; SourceLocation PartiallySubstitutedPackLoc; @@ -868,7 +867,8 @@ bool Sema::CheckParameterPacksForExpansion( // This is the first pack we've seen for which we have an argument. // Record it. NumExpansions = NewPackSize; - FirstPack = IdentifierLoc(ParmPack.second, Name); + FirstPack.first = Name; + FirstPack.second = ParmPack.second; 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.getIdentifierInfo() << Name << *NumExpansions + << FirstPack.first << Name << *NumExpansions << (LeastNewPackSize != NewPackSize) << LeastNewPackSize - << SourceRange(FirstPack.getLoc()) << SourceRange(ParmPack.second); + << SourceRange(FirstPack.second) << 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 6e7ee8b5506ff..eba7267904fb2 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)->getIdentifierInfo() : nullptr; + IdentifierInfo *II = attr.isArgIdent(0) ? attr.getArgAsIdent(0)->Ident + : nullptr; if (useExpansionLoc && loc.isMacroID() && II) { if (II->isStr("strong")) { if (S.findMacroSpelling(loc, "__strong")) name = "__strong"; @@ -5732,7 +5732,8 @@ static void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state, } IdentifierLoc *Arg = new (S.Context) IdentifierLoc; - Arg->setIdentifierInfo(&S.Context.Idents.get(attrStr)); + Arg->Ident = &S.Context.Idents.get(attrStr); + Arg->Loc = SourceLocation(); ArgsUnion Args(Arg); @@ -6632,7 +6633,7 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state, return true; } - IdentifierInfo *II = attr.getArgAsIdent(0)->getIdentifierInfo(); + IdentifierInfo *II = attr.getArgAsIdent(0)->Ident; Qualifiers::ObjCLifetime lifetime; if (II->isStr("none")) lifetime = Qualifiers::OCL_ExplicitNone; @@ -6810,7 +6811,7 @@ static bool handleObjCGCTypeAttr(TypeProcessingState &state, ParsedAttr &attr, return true; } - IdentifierInfo *II = attr.getArgAsIdent(0)->getIdentifierInfo(); + IdentifierInfo *II = attr.getArgAsIdent(0)->Ident; if (II->isStr("weak")) GCAttr = Qualifiers::Weak; else if (II->isStr("strong")) @@ -7540,7 +7541,7 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr) { if (Attr.isArgExpr(0)) Str = cast(Attr.getArgAsExpr(0))->getString(); else - Str = Attr.getArgAsIdent(0)->getIdentifierInfo()->getName(); + Str = Attr.getArgAsIdent(0)->Ident->getName(); PcsAttr::PCSType Type; if (!PcsAttr::ConvertStrToPCSType(Str, Type)) llvm_unreachable("already validated the attribute"); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index b404015867087..02c31dff620ec 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -12811,7 +12811,7 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() { for (unsigned I = 0; I < NumArchs; ++I) { IdentifierInfo *Ident = readBool() ? readIdentifier() : nullptr; SourceLocation Loc = readSourceLocation(); - Archs.emplace_back(Loc, Ident); + Archs.emplace_back(Ident, Loc); } return OpenACCDeviceTypeClause::Create(getContext(), ClauseKind, BeginLoc, diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 4dca0613cb9ae..95b5718f1d140 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -8774,10 +8774,10 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) { writeSourceLocation(DTC->getLParenLoc()); writeUInt32(DTC->getArchitectures().size()); for (const DeviceTypeArgument &Arg : DTC->getArchitectures()) { - writeBool(Arg.getIdentifierInfo()); - if (Arg.getIdentifierInfo()) - AddIdentifierRef(Arg.getIdentifierInfo()); - writeSourceLocation(Arg.getLoc()); + writeBool(Arg.first); + if (Arg.first) + AddIdentifierRef(Arg.first); + writeSourceLocation(Arg.second); } return; } diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 07856dbdba4b4..429bf823616da 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -664,7 +664,7 @@ void ModuleDepCollectorPP::moduleImport(SourceLocation ImportLoc, const Module *Imported) { if (MDC.ScanInstance.getPreprocessor().isInImportingCXXNamedModules()) { P1689ModuleInfo RequiredModule; - RequiredModule.ModuleName = Path[0].getIdentifierInfo()->getName().str(); + RequiredModule.ModuleName = Path[0].first->getName().str(); RequiredModule.Type = P1689ModuleInfo::ModuleType::NamedCXXModule; MDC.RequiredStdCXXModules.push_back(RequiredModule); return;