diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp index 3bb30fd15b2e1..4c916fa30685b 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].first->getName() << ", " - << "Loc: " << getSourceLocationString(PP, Value[I].second) << "}"; + << "Name: " << Value[I].getIdentifierInfo()->getName() << ", " + << "Loc: " << getSourceLocationString(PP, Value[I].getLoc()) << "}"; } SS << "]"; appendArgument(Name, SS.str()); diff --git a/clang/include/clang/AST/OpenACCClause.h b/clang/include/clang/AST/OpenACCClause.h index 3687af76a559f..53026274aa118 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 = std::pair; +using DeviceTypeArgument = IdentifierLoc; /// 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.second.isInvalid(); + return Arg.getLoc().isInvalid(); }) && "Invalid SourceLocation for an argument"); - 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"); + 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"); std::uninitialized_copy(Archs.begin(), Archs.end(), getTrailingObjects()); @@ -302,7 +302,7 @@ class OpenACCDeviceTypeClause final } bool hasAsterisk() const { return getArchitectures().size() > 0 && - getArchitectures()[0].first == nullptr; + getArchitectures()[0].getIdentifierInfo() == nullptr; } ArrayRef getArchitectures() const { diff --git a/clang/include/clang/Basic/IdentifierTable.h b/clang/include/clang/Basic/IdentifierTable.h index 0347880244a40..1275b056227b5 100644 --- a/clang/include/clang/Basic/IdentifierTable.h +++ b/clang/include/clang/Basic/IdentifierTable.h @@ -18,6 +18,7 @@ #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" @@ -76,9 +77,6 @@ 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. @@ -1165,6 +1163,28 @@ 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 f880a9091a2ed..a58407200c41c 100644 --- a/clang/include/clang/Lex/ModuleLoader.h +++ b/clang/include/clang/Lex/ModuleLoader.h @@ -14,6 +14,7 @@ #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" @@ -29,7 +30,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 46cc564086f1c..313b730afbab8 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -15,6 +15,7 @@ #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 24bb524783e93..f8f2f567f9171 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, 2> NamedModuleImportPath; + SmallVector 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. - std::pair PragmaARCCFCodeAuditedInfo; + IdentifierLoc PragmaARCCFCodeAuditedInfo; /// The source location of the currently-active /// \#pragma clang assume_nonnull begin. @@ -1998,8 +1998,7 @@ class Preprocessor { /// arc_cf_code_audited begin. /// /// Returns an invalid location if there is no such pragma active. - std::pair - getPragmaARCCFCodeAuditedInfo() const { + IdentifierLoc getPragmaARCCFCodeAuditedInfo() const { return PragmaARCCFCodeAuditedInfo; } @@ -2007,7 +2006,7 @@ class Preprocessor { /// arc_cf_code_audited begin. An invalid location ends the pragma. void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident, SourceLocation Loc) { - PragmaARCCFCodeAuditedInfo = {Ident, Loc}; + PragmaARCCFCodeAuditedInfo = IdentifierLoc(Loc, Ident); } /// 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 cec5605ea3615..72be043d3c5a4 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 53da6269a3b11..fcc81b0c8f006 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, @@ -3816,8 +3816,7 @@ 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, @@ -3949,10 +3948,8 @@ 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 b88b871dc8821..428d3111de80d 100644 --- a/clang/include/clang/Sema/ParsedAttr.h +++ b/clang/include/clang/Sema/ParsedAttr.h @@ -40,7 +40,6 @@ 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' @@ -99,15 +98,6 @@ 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 5ab0af8234e26..8c68830001fd9 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 72159de3a6e72..3029e56e5cfe2 100644 --- a/clang/include/clang/Sema/SemaCodeCompletion.h +++ b/clang/include/clang/Sema/SemaCodeCompletion.h @@ -193,8 +193,7 @@ 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 791a7f45b832f..4cda41a82b61f 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 4c3a13a3b044f..8d31d46444c7e 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 = std::pair; + using DeviceTypeArgument = IdentifierLoc; /// 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 d7cbb51335359..2820d7b288658 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.first == nullptr) + if (Arch.getIdentifierInfo() == nullptr) OS << "*"; else - OS << Arch.first->getName(); + OS << Arch.getIdentifierInfo()->getName(); }); OS << ")"; } diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp index b90f32389c897..1fce87ce3c9ae 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.first == nullptr) + if (Arch.getIdentifierInfo() == nullptr) OS << "*"; else - OS << Arch.first->getName(); + OS << Arch.getIdentifierInfo()->getName(); }); OS << ")"; break; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index eb138de9d20cc..9fb89b96c2c77 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -35,6 +35,7 @@ #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" @@ -2028,8 +2029,8 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, Module::NameVisibilityKind Visibility, bool IsInclusionDirective) { // Determine what file we're searching from. - StringRef ModuleName = Path[0].first->getName(); - SourceLocation ModuleNameLoc = Path[0].second; + StringRef ModuleName = Path[0].getIdentifierInfo()->getName(); + SourceLocation ModuleNameLoc = Path[0].getLoc(); // If we've already handled this import, just return the cached result. // This one-element cache is important to eliminate redundant diagnostics @@ -2045,7 +2046,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].first)) { + if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].getIdentifierInfo())) { // Use the cached result, which may be nullptr. Module = *MaybeModule; // Config macros are already checked before building a module, but they need @@ -2065,7 +2066,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, // * `Preprocessor::HandleHeaderIncludeOrImport` will never call this // function as the `#include` or `#import` is textual. - MM.cacheModuleLoad(*Path[0].first, Module); + MM.cacheModuleLoad(*Path[0].getIdentifierInfo(), Module); } else { ModuleLoadResult Result = findOrCompileModuleAndReadAST( ModuleName, ImportLoc, ModuleNameLoc, IsInclusionDirective); @@ -2074,7 +2075,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, if (!Result) DisableGeneratingGlobalModuleIndex = true; Module = Result; - MM.cacheModuleLoad(*Path[0].first, Module); + MM.cacheModuleLoad(*Path[0].getIdentifierInfo(), Module); } // If we never found the module, fail. Otherwise, verify the module and link @@ -2086,7 +2087,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, // a submodule. bool MapPrivateSubModToTopLevel = false; for (unsigned I = 1, N = Path.size(); I != N; ++I) { - StringRef Name = Path[I].first->getName(); + StringRef Name = Path[I].getIdentifierInfo()->getName(); clang::Module *Sub = Module->findSubmodule(Name); // If the user is requesting Foo.Private and it doesn't exist, try to @@ -2097,10 +2098,10 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, SmallString<128> PrivateModule(Module->Name); PrivateModule.append("_Private"); - SmallVector, 2> PrivPath; + SmallVector PrivPath; auto &II = PP->getIdentifierTable().get( PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID()); - PrivPath.push_back(std::make_pair(&II, Path[0].second)); + PrivPath.emplace_back(Path[0].getLoc(), &II); std::string FileName; // If there is a modulemap module or prebuilt module, load it. @@ -2114,11 +2115,12 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, PP->markClangModuleAsAffecting(Module); if (!getDiagnostics().isIgnored( diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) { - getDiagnostics().Report(Path[I].second, + getDiagnostics().Report(Path[I].getLoc(), diag::warn_no_priv_submodule_use_toplevel) - << Path[I].first << Module->getFullModuleName() << PrivateModule - << SourceRange(Path[0].second, Path[I].second) - << FixItHint::CreateReplacement(SourceRange(Path[0].second), + << Path[I].getIdentifierInfo() << Module->getFullModuleName() + << PrivateModule + << SourceRange(Path[0].getLoc(), Path[I].getLoc()) + << FixItHint::CreateReplacement(SourceRange(Path[0].getLoc()), PrivateModule); getDiagnostics().Report(Sub->DefinitionLoc, diag::note_private_top_level_defined); @@ -2147,10 +2149,11 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, // If there was a clear winner, user it. if (Best.size() == 1) { - 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), + 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()), Best[0]); Sub = Module->findSubmodule(Best[0]); @@ -2160,9 +2163,9 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, if (!Sub) { // No submodule by this name. Complain, and don't look for further // submodules. - getDiagnostics().Report(Path[I].second, diag::err_no_submodule) - << Path[I].first << Module->getFullModuleName() - << SourceRange(Path[0].second, Path[I - 1].second); + getDiagnostics().Report(Path[I].getLoc(), diag::err_no_submodule) + << Path[I].getIdentifierInfo() << Module->getFullModuleName() + << SourceRange(Path[0].getLoc(), Path[I - 1].getLoc()); break; } @@ -2180,8 +2183,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().second, Path.back().second); + << Module->getFullModuleName() + << SourceRange(Path.front().getLoc(), Path.back().getLoc()); return ModuleLoadResult(Module, ModuleLoadResult::MissingExpected); } @@ -2190,7 +2193,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, if (Preprocessor::checkModuleIsAvailable(getLangOpts(), getTarget(), *Module, getDiagnostics())) { getDiagnostics().Report(ImportLoc, diag::note_module_import_here) - << SourceRange(Path.front().second, Path.back().second); + << SourceRange(Path.front().getLoc(), Path.back().getLoc()); LastModuleImportLoc = ImportLoc; LastModuleImportResult = ModuleLoadResult(); return ModuleLoadResult(); @@ -2316,9 +2319,9 @@ GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex( Module *TheModule = I->second; OptionalFileEntryRef Entry = TheModule->getASTFile(); if (!Entry) { - SmallVector, 2> Path; - Path.push_back(std::make_pair( - getPreprocessor().getIdentifierInfo(TheModule->Name), TriggerLoc)); + SmallVector Path; + Path.emplace_back(TriggerLoc, + getPreprocessor().getIdentifierInfo(TheModule->Name)); 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 c5aeb92c7af73..e6c7b9f32c29b 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, 2> Path; + SmallVector Path; IdentifierInfo *ModuleID = PP.getIdentifierInfo(ModuleName); - Path.push_back(std::make_pair(ModuleID, FileStart)); + Path.emplace_back(FileStart, ModuleID); 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 dfdba6bd09fd8..c11865c46997d 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].first->getName(); + PathString += Path[I].getIdentifierInfo()->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.second.isValid()) { + if (PragmaARCCFCodeAuditedInfo.getLoc().isValid()) { Diag(StartLoc, diag::err_pp_include_in_arc_cf_code_audited) << IsImportDecl; - Diag(PragmaARCCFCodeAuditedInfo.second, diag::note_pragma_entered_here); + Diag(PragmaARCCFCodeAuditedInfo.getLoc(), diag::note_pragma_entered_here); // Immediately leave the pragma. - PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()}; + PragmaARCCFCodeAuditedInfo = IdentifierLoc(); } // 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, 2> Path; + SmallVector Path; for (Module *Mod = ModuleToImport; Mod; Mod = Mod->Parent) - Path.push_back(std::make_pair(getIdentifierInfo(Mod->Name), - FilenameTok.getLocation())); + Path.emplace_back(FilenameTok.getLocation(), + getIdentifierInfo(Mod->Name)); 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 a373a52506a24..db6069e31fa46 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.second.isValid() && !isEndOfMacro && + if (PragmaARCCFCodeAuditedInfo.getLoc().isValid() && !isEndOfMacro && !(CurLexer && CurLexer->Is_PragmaLexer)) { - Diag(PragmaARCCFCodeAuditedInfo.second, + Diag(PragmaARCCFCodeAuditedInfo.getLoc(), diag::err_pp_eof_in_arc_cf_code_audited); // Recover by leaving immediately. - PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()}; + PragmaARCCFCodeAuditedInfo = IdentifierLoc(); } // Complain about reaching a true EOF within assume_nonnull. diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 91c1619e35623..5b6a29bdad910 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -763,20 +763,19 @@ 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, - std::pair &ModuleNameComponent, - bool First) { +static bool LexModuleNameComponent(Preprocessor &PP, Token &Tok, + IdentifierLoc &ModuleNameComponent, + bool First) { PP.LexUnexpandedToken(Tok); if (Tok.is(tok::string_literal) && !Tok.hasUDSuffix()) { StringLiteralParser Literal(Tok, PP); if (Literal.hadError) return true; - ModuleNameComponent = std::make_pair( - PP.getIdentifierInfo(Literal.GetString()), Tok.getLocation()); + ModuleNameComponent = IdentifierLoc( + Tok.getLocation(), PP.getIdentifierInfo(Literal.GetString())); } else if (!Tok.isAnnotation() && Tok.getIdentifierInfo()) { ModuleNameComponent = - std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation()); + IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo()); } else { PP.Diag(Tok.getLocation(), diag::err_pp_expected_module_name) << First; return true; @@ -784,12 +783,10 @@ static bool LexModuleNameComponent( return false; } -static bool LexModuleName( - Preprocessor &PP, Token &Tok, - llvm::SmallVectorImpl> - &ModuleName) { +static bool LexModuleName(Preprocessor &PP, Token &Tok, + llvm::SmallVectorImpl &ModuleName) { while (true) { - std::pair NameComponent; + IdentifierLoc NameComponent; if (LexModuleNameComponent(PP, Tok, NameComponent, ModuleName.empty())) return true; ModuleName.push_back(NameComponent); @@ -803,10 +800,10 @@ static bool LexModuleName( void Preprocessor::HandlePragmaModuleBuild(Token &Tok) { SourceLocation Loc = Tok.getLocation(); - std::pair ModuleNameLoc; + IdentifierLoc ModuleNameLoc; if (LexModuleNameComponent(*this, Tok, ModuleNameLoc, true)) return; - IdentifierInfo *ModuleName = ModuleNameLoc.first; + IdentifierInfo *ModuleName = ModuleNameLoc.getIdentifierInfo(); LexUnexpandedToken(Tok); if (Tok.isNot(tok::eod)) { @@ -1109,17 +1106,17 @@ struct PragmaDebugHandler : public PragmaHandler { PP.Diag(MacroName, diag::warn_pragma_debug_missing_argument) << II->getName(); } else if (II->isStr("module_map")) { - llvm::SmallVector, 8> - ModuleName; + llvm::SmallVector ModuleName; if (LexModuleName(PP, Tok, ModuleName)) return; ModuleMap &MM = PP.getHeaderSearchInfo().getModuleMap(); Module *M = nullptr; for (auto IIAndLoc : ModuleName) { - M = MM.lookupModuleQualified(IIAndLoc.first->getName(), M); + M = MM.lookupModuleQualified(IIAndLoc.getIdentifierInfo()->getName(), + M); if (!M) { - PP.Diag(IIAndLoc.second, diag::warn_pragma_debug_unknown_module) - << IIAndLoc.first->getName(); + PP.Diag(IIAndLoc.getLoc(), diag::warn_pragma_debug_unknown_module) + << IIAndLoc.getIdentifierInfo()->getName(); return; } } @@ -1707,8 +1704,7 @@ struct PragmaModuleImportHandler : public PragmaHandler { SourceLocation ImportLoc = Tok.getLocation(); // Read the module name. - llvm::SmallVector, 8> - ModuleName; + llvm::SmallVector ModuleName; if (LexModuleName(PP, Tok, ModuleName)) return; @@ -1723,7 +1719,7 @@ struct PragmaModuleImportHandler : public PragmaHandler { return; PP.makeModuleVisible(Imported, ImportLoc); - PP.EnterAnnotationToken(SourceRange(ImportLoc, ModuleName.back().second), + PP.EnterAnnotationToken(SourceRange(ImportLoc, ModuleName.back().getLoc()), tok::annot_module_include, Imported); if (auto *CB = PP.getPPCallbacks()) CB->moduleImport(ImportLoc, ModuleName, Imported); @@ -1744,8 +1740,7 @@ struct PragmaModuleBeginHandler : public PragmaHandler { SourceLocation BeginLoc = Tok.getLocation(); // Read the module name. - llvm::SmallVector, 8> - ModuleName; + llvm::SmallVector ModuleName; if (LexModuleName(PP, Tok, ModuleName)) return; @@ -1754,10 +1749,11 @@ struct PragmaModuleBeginHandler : public PragmaHandler { // We can only enter submodules of the current module. StringRef Current = PP.getLangOpts().CurrentModule; - 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; + 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; return; } @@ -1765,17 +1761,19 @@ struct PragmaModuleBeginHandler : public PragmaHandler { // be loaded or implicitly loadable. auto &HSI = PP.getHeaderSearchInfo(); auto &MM = HSI.getModuleMap(); - Module *M = HSI.lookupModule(Current, ModuleName.front().second); + Module *M = HSI.lookupModule(Current, ModuleName.front().getLoc()); if (!M) { - PP.Diag(ModuleName.front().second, - diag::err_pp_module_begin_no_module_map) << Current; + PP.Diag(ModuleName.front().getLoc(), + 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].first->getName()); + auto *NewM = MM.findOrInferSubmodule( + M, ModuleName[I].getIdentifierInfo()->getName()); if (!NewM) { - PP.Diag(ModuleName[I].second, diag::err_pp_module_begin_no_submodule) - << M->getFullModuleName() << ModuleName[I].first; + PP.Diag(ModuleName[I].getLoc(), diag::err_pp_module_begin_no_submodule) + << M->getFullModuleName() << ModuleName[I].getIdentifierInfo(); return; } M = NewM; @@ -1791,7 +1789,7 @@ struct PragmaModuleBeginHandler : public PragmaHandler { // Enter the scope of the submodule. PP.EnterSubmodule(M, BeginLoc, /*ForPragma*/true); - PP.EnterAnnotationToken(SourceRange(BeginLoc, ModuleName.back().second), + PP.EnterAnnotationToken(SourceRange(BeginLoc, ModuleName.back().getLoc()), tok::annot_module_begin, M); } }; @@ -1835,8 +1833,7 @@ struct PragmaModuleLoadHandler : public PragmaHandler { SourceLocation Loc = Tok.getLocation(); // Read the module name. - llvm::SmallVector, 8> - ModuleName; + llvm::SmallVector ModuleName; if (LexModuleName(PP, Tok, ModuleName)) return; @@ -1901,7 +1898,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().second; + SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedInfo().getLoc(); // 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 c25a3efd899e0..4c050bf1f5bb2 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.push_back( - {getIdentifierInfo(Name), Result.getLocation()}); + NamedModuleImportPath.emplace_back(Result.getLocation(), + getIdentifierInfo(Name)); 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.push_back( - std::make_pair(Result.getIdentifierInfo(), Result.getLocation())); + NamedModuleImportPath.emplace_back(Result.getLocation(), + Result.getIdentifierInfo()); 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.first->getName(); + FlatModuleName += Piece.getIdentifierInfo()->getName(); } - SourceLocation FirstPathLoc = NamedModuleImportPath[0].second; + SourceLocation FirstPathLoc = NamedModuleImportPath[0].getLoc(); NamedModuleImportPath.clear(); - NamedModuleImportPath.push_back( - std::make_pair(getIdentifierInfo(FlatModuleName), FirstPathLoc)); + NamedModuleImportPath.emplace_back(FirstPathLoc, + getIdentifierInfo(FlatModuleName)); } Module *Imported = nullptr; diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index d77400e0f8272..53da871580b18 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -432,9 +432,8 @@ static bool attributeParsedArgsUnevaluated(const IdentifierInfo &II, IdentifierLoc *Parser::ParseIdentifierLoc() { assert(Tok.is(tok::identifier) && "expected an identifier"); - IdentifierLoc *IL = IdentifierLoc::create(Actions.Context, - Tok.getLocation(), - Tok.getIdentifierInfo()); + IdentifierLoc *IL = new (Actions.Context) + IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo()); ConsumeToken(); return IL; } @@ -1353,20 +1352,21 @@ void Parser::ParseAvailabilityAttribute( return; } IdentifierLoc *Platform = ParseIdentifierLoc(); - if (const IdentifierInfo *const Ident = Platform->Ident) { + if (const IdentifierInfo *const Ident = Platform->getIdentifierInfo()) { // Disallow xrOS for availability attributes. if (Ident->getName().contains("xrOS") || Ident->getName().contains("xros")) - Diag(Platform->Loc, diag::warn_availability_unknown_platform) << Ident; + Diag(Platform->getLoc(), diag::warn_availability_unknown_platform) + << Ident; // Canonicalize platform name from "macosx" to "macos". else if (Ident->getName() == "macosx") - Platform->Ident = PP.getIdentifierInfo("macos"); + Platform->setIdentifierInfo(PP.getIdentifierInfo("macos")); // Canonicalize platform name from "macosx_app_extension" to // "macos_app_extension". else if (Ident->getName() == "macosx_app_extension") - Platform->Ident = PP.getIdentifierInfo("macos_app_extension"); + Platform->setIdentifierInfo(PP.getIdentifierInfo("macos_app_extension")); else - Platform->Ident = PP.getIdentifierInfo( - AvailabilityAttr::canonicalizePlatformName(Ident->getName())); + Platform->setIdentifierInfo(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->Ident && - Platform->Ident->isStr("swift")) { + if (Keyword == Ident_deprecated && Platform->getIdentifierInfo() && + Platform->getIdentifierInfo()->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->Loc); + << Keyword << SourceRange(EnvironmentLoc->getLoc()); } } @@ -1792,8 +1792,8 @@ void Parser::ParseSwiftNewTypeAttribute( return; } - auto *SwiftType = IdentifierLoc::create(Actions.Context, Tok.getLocation(), - Tok.getIdentifierInfo()); + auto *SwiftType = new (Actions.Context) + IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo()); ConsumeToken(); // Closing ')' diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 0a22f7372a9f9..1416d52157dca 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -4006,19 +4006,20 @@ std::optional Parser::ParseAvailabilitySpec() { if (Version.empty()) return std::nullopt; - StringRef GivenPlatform = PlatformIdentifier->Ident->getName(); + StringRef GivenPlatform = + PlatformIdentifier->getIdentifierInfo()->getName(); StringRef Platform = AvailabilityAttr::canonicalizePlatformName(GivenPlatform); if (AvailabilityAttr::getPrettyPlatformName(Platform).empty() || (GivenPlatform.contains("xros") || GivenPlatform.contains("xrOS"))) { - Diag(PlatformIdentifier->Loc, + Diag(PlatformIdentifier->getLoc(), diag::err_avail_query_unrecognized_platform_name) << GivenPlatform; return std::nullopt; } - return AvailabilitySpec(Version, Platform, PlatformIdentifier->Loc, + return AvailabilitySpec(Version, Platform, PlatformIdentifier->getLoc(), VersionRange.getEnd()); } } diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index f4c109f9a81a2..7ffacc4b79f79 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 = IdentifierLoc::create(Ctx, ArgLoc, PP.getIdentifierInfo(FixedArg)); + Slot = new (Ctx) IdentifierLoc(ArgLoc, PP.getIdentifierInfo(FixedArg)); } void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index bcbf4dfbabafa..d872177b3d7aa 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 &pair : ProtocolIdents) { - protocolLocs.push_back(pair.second); + for (const auto &Loc : ProtocolIdents) { + protocolLocs.push_back(Loc.getLoc()); } 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,7 +474,8 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs( for (const auto &pair : protocolIdents) { DeclResult typeParam = Actions.ObjC().actOnObjCTypeParam( getCurScope(), ObjCTypeParamVariance::Invariant, SourceLocation(), - index++, pair.first, pair.second, SourceLocation(), nullptr); + index++, pair.getIdentifierInfo(), pair.getLoc(), SourceLocation(), + nullptr); if (typeParam.isUsable()) typeParams.push_back(typeParam.get()); } @@ -546,7 +547,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.push_back(std::make_pair(paramName, paramLoc)); + protocolIdents.emplace_back(paramLoc, paramName); continue; } @@ -606,7 +607,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()); @@ -1598,7 +1599,7 @@ ParseObjCProtocolReferences(SmallVectorImpl &Protocols, LAngleLoc = ConsumeToken(); // the "<" - SmallVector ProtocolIdents; + SmallVector ProtocolIdents; while (true) { if (Tok.is(tok::code_completion)) { @@ -1612,8 +1613,7 @@ ParseObjCProtocolReferences(SmallVectorImpl &Protocols, SkipUntil(tok::greater, StopAtSemi); return true; } - ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), - Tok.getLocation())); + ProtocolIdents.emplace_back(Tok.getLocation(), Tok.getIdentifierInfo()); ProtocolLocs.push_back(Tok.getLocation()); ConsumeToken(); @@ -1693,10 +1693,9 @@ 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.push_back(IdentifierLocPair(identifiers[i], - identifierLocs[i])); + identifierLocPairs.emplace_back(identifierLocs[i], identifiers[i]); } QualType BaseT = Actions.GetTypeFromParser(baseType); @@ -2094,7 +2093,7 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, SourceLocation nameLoc = ConsumeToken(); if (TryConsumeToken(tok::semi)) { // forward declaration of one protocol. - IdentifierLocPair ProtoInfo(protocolName, nameLoc); + IdentifierLoc ProtoInfo(nameLoc, protocolName); return Actions.ObjC().ActOnForwardProtocolDeclaration(AtLoc, ProtoInfo, attrs); } @@ -2102,8 +2101,8 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, CheckNestedObjCContexts(AtLoc); if (Tok.is(tok::comma)) { // list of forward declarations. - SmallVector ProtocolRefs; - ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); + SmallVector ProtocolRefs; + ProtocolRefs.emplace_back(nameLoc, protocolName); // Parse the list of forward declarations. while (true) { @@ -2112,8 +2111,7 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, SkipUntil(tok::semi); return nullptr; } - ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), - Tok.getLocation())); + ProtocolRefs.emplace_back(Tok.getLocation(), Tok.getIdentifierInfo()); ConsumeToken(); // the identifier if (Tok.isNot(tok::comma)) @@ -2196,7 +2194,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 64916995907c5..337b3eca49764 100644 --- a/clang/lib/Parse/ParseOpenACC.cpp +++ b/clang/lib/Parse/ParseOpenACC.cpp @@ -15,6 +15,7 @@ #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" @@ -814,7 +815,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, @@ -822,7 +823,7 @@ bool Parser::ParseOpenACCDeviceTypeList( return true; } IdentifierInfo *Ident = getCurToken().getIdentifierInfo(); - Archs.emplace_back(Ident, ConsumeToken()); + Archs.emplace_back(ConsumeToken(), Ident); while (!getCurToken().isOneOf(tok::r_paren, tok::annot_pragma_openacc_end)) { ExpectAndConsume(tok::comma); @@ -833,7 +834,7 @@ bool Parser::ParseOpenACCDeviceTypeList( return true; } Ident = getCurToken().getIdentifierInfo(); - Archs.emplace_back(Ident, ConsumeToken()); + Archs.emplace_back(ConsumeToken(), Ident); } return false; } @@ -1154,11 +1155,12 @@ 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({{nullptr, ConsumeToken()}}); + ParsedClause.setDeviceTypeDetails( + {IdentifierLoc(ConsumeToken(), nullptr)}); } 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 21ebff1e50559..17b2b30942582 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 = IdentifierLoc::create( - Actions.Context, Info->PragmaName.getLocation(), PragmaNameInfo); + Hint.PragmaNameLoc = new (Actions.Context) + IdentifierLoc(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 = IdentifierLoc::create( - Actions.Context, Info->Option.getLocation(), OptionInfo); + Hint.OptionLoc = new (Actions.Context) + IdentifierLoc(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 = IdentifierLoc::create(Actions.Context, StateLoc, StateInfo); + Hint.StateLoc = new (Actions.Context) IdentifierLoc(StateLoc, StateInfo); } else if (OptionInfo && OptionInfo->getName() == "vectorize_width") { PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/false, /*IsReinject=*/false); @@ -1529,8 +1529,7 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) { ConsumeAnyToken(); } - Hint.StateLoc = - IdentifierLoc::create(Actions.Context, StateLoc, StateInfo); + Hint.StateLoc = new (Actions.Context) IdentifierLoc(StateLoc, StateInfo); ConsumeToken(); // Consume the constant expression eof terminator. } else { @@ -1554,7 +1553,7 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) { Arg2Error = true; } else Hint.StateLoc = - IdentifierLoc::create(Actions.Context, StateLoc, StateInfo); + new (Actions.Context) IdentifierLoc(StateLoc, StateInfo); PP.Lex(Tok); // Identifier } diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index e8ec140fbe3e5..4a82d57fe566b 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->Ident, Hint.Range, nullptr, - Hint.PragmaNameLoc->Loc, ArgHints, 4, - ParsedAttr::Form::Pragma()); + TempAttrs.addNew(Hint.PragmaNameLoc->getIdentifierInfo(), Hint.Range, + /*scopeName=*/nullptr, Hint.PragmaNameLoc->getLoc(), + ArgHints, /*numArgs=*/4, ParsedAttr::Form::Pragma()); } // Get the next statement. diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index f3191762b1244..d528664bca352 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, 2> Path; + SmallVector Path; if (ParseModuleName(ModuleLoc, Path, /*IsImport*/ false)) return nullptr; // Parse the optional module-partition. - SmallVector, 2> Partition; + SmallVector Partition; if (Tok.is(tok::colon)) { SourceLocation ColonLoc = ConsumeToken(); if (!getLangOpts().CPlusPlusModules) Diag(ColonLoc, diag::err_unsupported_module_partition) - << SourceRange(ColonLoc, Partition.back().second); + << SourceRange(ColonLoc, Partition.back().getLoc()); // 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, 2> Path; + SmallVector 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().second); + << SourceRange(ColonLoc, Path.back().getLoc()); // Recover by leaving partition empty. else if (ParseModuleName(ColonLoc, Path, /*IsImport*/ true)) return nullptr; @@ -2718,10 +2718,9 @@ 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)) { @@ -2737,7 +2736,7 @@ bool Parser::ParseModuleName( } // Record this part of the module path. - Path.push_back(std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation())); + Path.emplace_back(Tok.getLocation(), Tok.getIdentifierInfo()); ConsumeToken(); if (Tok.isNot(tok::period)) diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp index b19a02b8c1a09..c149cef478539 100644 --- a/clang/lib/Sema/ParsedAttr.cpp +++ b/clang/lib/Sema/ParsedAttr.cpp @@ -23,14 +23,6 @@ using namespace clang; -IdentifierLoc *IdentifierLoc::create(ASTContext &Ctx, SourceLocation Loc, - IdentifierInfo *Ident) { - IdentifierLoc *Result = new (Ctx) IdentifierLoc; - Result->Loc = Loc; - Result->Ident = Ident; - return Result; -} - size_t ParsedAttr::allocated_size() const { if (IsAvailability) return AttributeFactory::AvailabilityAllocSize; else if (IsTypeTagForDatatype) diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp index 3f53fb200a93d..5bcbe78e9d633 100644 --- a/clang/lib/Sema/SemaARM.cpp +++ b/clang/lib/Sema/SemaARM.cpp @@ -1178,7 +1178,7 @@ void SemaARM::handleBuiltinAliasAttr(Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *Ident = AL.getArgAsIdent(0)->getIdentifierInfo(); unsigned BuiltinID = Ident->getBuiltinID(); StringRef AliasName = cast(D)->getIdentifier()->getName(); diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 793ffb6a00b86..34395b9aa9135 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -8715,7 +8715,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); @@ -8726,9 +8726,9 @@ void SemaCodeCompletion::CodeCompleteObjCProtocolReferences( // Tell the result set to ignore all of the protocols we have // already seen. // FIXME: This doesn't work when caching code-completion results. - for (const IdentifierLocPair &Pair : Protocols) - if (ObjCProtocolDecl *Protocol = - SemaRef.ObjC().LookupProtocol(Pair.first, Pair.second)) + for (const IdentifierLoc &Pair : Protocols) + if (ObjCProtocolDecl *Protocol = SemaRef.ObjC().LookupProtocol( + Pair.getIdentifierInfo(), Pair.getLoc())) Results.Ignore(Protocol); // Add all protocols. diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 20ea38b7e05db..c6a0c007a824b 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -135,13 +135,13 @@ bool Sema::checkStringLiteralArgumentAttr(const ParsedAttr &AL, unsigned ArgNum, // Look for identifiers. If we have one emit a hint to fix it to a literal. if (AL.isArgIdent(ArgNum)) { IdentifierLoc *Loc = AL.getArgAsIdent(ArgNum); - Diag(Loc->Loc, diag::err_attribute_argument_type) + Diag(Loc->getLoc(), diag::err_attribute_argument_type) << AL << AANT_ArgumentString - << FixItHint::CreateInsertion(Loc->Loc, "\"") - << FixItHint::CreateInsertion(getLocForEndOfToken(Loc->Loc), "\""); - Str = Loc->Ident->getName(); + << FixItHint::CreateInsertion(Loc->getLoc(), "\"") + << FixItHint::CreateInsertion(getLocForEndOfToken(Loc->getLoc()), "\""); + Str = Loc->getIdentifierInfo()->getName(); if (ArgLocation) - *ArgLocation = Loc->Loc; + *ArgLocation = Loc->getLoc(); return true; } @@ -811,7 +811,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)->Loc; + return cast(Union)->getLoc(); }(); S.Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T; @@ -1003,10 +1003,10 @@ static void handleConsumableAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (AL.isArgIdent(0)) { IdentifierLoc *IL = AL.getArgAsIdent(0); - if (!ConsumableAttr::ConvertStrToConsumedState(IL->Ident->getName(), - DefaultState)) { - S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL - << IL->Ident; + if (!ConsumableAttr::ConvertStrToConsumedState( + IL->getIdentifierInfo()->getName(), DefaultState)) { + S.Diag(IL->getLoc(), diag::warn_attribute_type_not_supported) + << AL << IL->getIdentifierInfo(); return; } } else { @@ -1048,8 +1048,8 @@ static void handleCallableWhenAttr(Sema &S, Decl *D, const ParsedAttr &AL) { SourceLocation Loc; if (AL.isArgIdent(ArgIndex)) { IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex); - StateString = Ident->Ident->getName(); - Loc = Ident->Loc; + StateString = Ident->getIdentifierInfo()->getName(); + Loc = Ident->getLoc(); } else { if (!S.checkStringLiteralArgumentAttr(AL, ArgIndex, StateString, &Loc)) return; @@ -1073,11 +1073,11 @@ static void handleParamTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (AL.isArgIdent(0)) { IdentifierLoc *Ident = AL.getArgAsIdent(0); - StringRef StateString = Ident->Ident->getName(); + StringRef StateString = Ident->getIdentifierInfo()->getName(); if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString, ParamState)) { - S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) + S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported) << AL << StateString; return; } @@ -1107,10 +1107,10 @@ static void handleReturnTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (AL.isArgIdent(0)) { IdentifierLoc *IL = AL.getArgAsIdent(0); - if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->Ident->getName(), - ReturnState)) { - S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL - << IL->Ident; + if (!ReturnTypestateAttr::ConvertStrToConsumedState( + IL->getIdentifierInfo()->getName(), ReturnState)) { + S.Diag(IL->getLoc(), diag::warn_attribute_type_not_supported) + << AL << IL->getIdentifierInfo(); return; } } else { @@ -1154,10 +1154,10 @@ static void handleSetTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { SetTypestateAttr::ConsumedState NewState; if (AL.isArgIdent(0)) { IdentifierLoc *Ident = AL.getArgAsIdent(0); - StringRef Param = Ident->Ident->getName(); + StringRef Param = Ident->getIdentifierInfo()->getName(); if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) { - S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL - << Param; + S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported) + << AL << Param; return; } } else { @@ -1176,10 +1176,10 @@ static void handleTestTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { TestTypestateAttr::ConsumedState TestState; if (AL.isArgIdent(0)) { IdentifierLoc *Ident = AL.getArgAsIdent(0); - StringRef Param = Ident->Ident->getName(); + StringRef Param = Ident->getIdentifierInfo()->getName(); if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) { - S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL - << Param; + S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported) + << AL << Param; return; } } else { @@ -1540,7 +1540,7 @@ static void handleOwnershipAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *Module = AL.getArgAsIdent(0)->getIdentifierInfo(); StringRef ModuleName = Module->getName(); if (normalizeName(ModuleName)) { @@ -1907,10 +1907,10 @@ static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) { } IdentifierLoc *CPUArg = AL.getArgAsIdent(ArgNo); - StringRef CPUName = CPUArg->Ident->getName().trim(); + StringRef CPUName = CPUArg->getIdentifierInfo()->getName().trim(); if (!S.Context.getTargetInfo().validateCPUSpecificCPUDispatch(CPUName)) { - S.Diag(CPUArg->Loc, diag::err_invalid_cpu_specific_dispatch_value) + S.Diag(CPUArg->getLoc(), diag::err_invalid_cpu_specific_dispatch_value) << CPUName << (AL.getKind() == ParsedAttr::AT_CPUDispatch); return; } @@ -1923,7 +1923,7 @@ static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) { S.Diag(AL.getLoc(), diag::warn_multiversion_duplicate_entries); return; } - CPUs.push_back(CPUArg->Ident); + CPUs.push_back(CPUArg->getIdentifierInfo()); } FD->setIsMultiVersion(true); @@ -2401,10 +2401,10 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; IdentifierLoc *Platform = AL.getArgAsIdent(0); - IdentifierInfo *II = Platform->Ident; + IdentifierInfo *II = Platform->getIdentifierInfo(); if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty()) - S.Diag(Platform->Loc, diag::warn_availability_unknown_platform) - << Platform->Ident; + S.Diag(Platform->getLoc(), diag::warn_availability_unknown_platform) + << Platform->getIdentifierInfo(); auto *ND = dyn_cast(D); if (!ND) // We warned about this already, so just return. @@ -2453,14 +2453,16 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { IdentifierInfo *IIEnvironment = nullptr; if (EnvironmentLoc) { if (S.getLangOpts().HLSL) { - IIEnvironment = EnvironmentLoc->Ident; + IIEnvironment = EnvironmentLoc->getIdentifierInfo(); if (AvailabilityAttr::getEnvironmentType( - EnvironmentLoc->Ident->getName()) == + EnvironmentLoc->getIdentifierInfo()->getName()) == llvm::Triple::EnvironmentType::UnknownEnvironment) - S.Diag(EnvironmentLoc->Loc, diag::warn_availability_unknown_environment) - << EnvironmentLoc->Ident; + S.Diag(EnvironmentLoc->getLoc(), + diag::warn_availability_unknown_environment) + << EnvironmentLoc->getIdentifierInfo(); } else { - S.Diag(EnvironmentLoc->Loc, diag::err_availability_unexpected_parameter) + S.Diag(EnvironmentLoc->getLoc(), + diag::err_availability_unexpected_parameter) << "environment" << /* C/C++ */ 1; } } @@ -3673,7 +3675,7 @@ static void handleEnumExtensibilityAttr(Sema &S, Decl *D, } EnumExtensibilityAttr::Kind ExtensibilityKind; - IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); if (!EnumExtensibilityAttr::ConvertStrToKind(II->getName(), ExtensibilityKind)) { S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; @@ -3896,7 +3898,7 @@ static bool handleFormatAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, bool HasImplicitThisParam = isInstanceMethod(D); Info->NumArgs = getFunctionOrMethodNumParams(D) + HasImplicitThisParam; - Info->Identifier = AL.getArgAsIdent(0)->Ident; + Info->Identifier = AL.getArgAsIdent(0)->getIdentifierInfo(); StringRef Format = Info->Identifier->getName(); if (normalizeName(Format)) { @@ -4060,14 +4062,14 @@ static void handleCallbackAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (AL.isArgIdent(I)) { IdentifierLoc *IdLoc = AL.getArgAsIdent(I); - auto It = NameIdxMapping.find(IdLoc->Ident->getName()); + auto It = NameIdxMapping.find(IdLoc->getIdentifierInfo()->getName()); if (It == UnknownName) { S.Diag(AL.getLoc(), diag::err_callback_attribute_argument_unknown) - << IdLoc->Ident << IdLoc->Loc; + << IdLoc->getIdentifierInfo() << IdLoc->getLoc(); return; } - SR = SourceRange(IdLoc->Loc); + SR = SourceRange(IdLoc->getLoc()); ArgIdx = It->second; } else if (AL.isArgExpr(I)) { Expr *IdxExpr = AL.getArgAsExpr(I); @@ -4185,13 +4187,14 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL, } assert(AL.isArgIdent(I)); IdentifierLoc *IdLoc = AL.getArgAsIdent(I); - if (IdLoc->Ident->getName() == ParamName) { - Diag(IdLoc->Loc, diag::err_capture_by_references_itself) << IdLoc->Loc; + if (IdLoc->getIdentifierInfo()->getName() == ParamName) { + Diag(IdLoc->getLoc(), diag::err_capture_by_references_itself) + << IdLoc->getLoc(); IsValid = false; continue; } - ParamIdents[I] = IdLoc->Ident; - ParamLocs[I] = IdLoc->Loc; + ParamIdents[I] = IdLoc->getIdentifierInfo(); + ParamLocs[I] = IdLoc->getLoc(); } if (!IsValid) return nullptr; @@ -4797,7 +4800,7 @@ static void handleModeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *Name = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *Name = AL.getArgAsIdent(0)->getIdentifierInfo(); S.AddModeAttr(D, AL, Name); } @@ -5770,8 +5773,8 @@ static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D, } D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr( - S.Context, AL, AL.getArgAsIdent(0)->Ident, ArgumentIdx, TypeTagIdx, - IsPointer)); + S.Context, AL, AL.getArgAsIdent(0)->getIdentifierInfo(), ArgumentIdx, + TypeTagIdx, IsPointer)); } static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, @@ -5791,7 +5794,7 @@ static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, return; } - IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->getIdentifierInfo(); TypeSourceInfo *MatchingCTypeLoc = nullptr; S.GetTypeFromParser(AL.getMatchingCType(), &MatchingCTypeLoc); assert(MatchingCTypeLoc && "no type source info for attribute argument"); @@ -5862,7 +5865,7 @@ static void handleBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *Ident = AL.getArgAsIdent(0)->getIdentifierInfo(); unsigned BuiltinID = Ident->getBuiltinID(); StringRef AliasName = cast(D)->getIdentifier()->getName(); @@ -6628,7 +6631,7 @@ static void handleCFGuardAttr(Sema &S, Decl *D, const ParsedAttr &AL) { } CFGuardAttr::GuardArg Arg; - IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); if (!CFGuardAttr::ConvertStrToGuardArg(II->getName(), Arg)) { S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; return; @@ -6730,8 +6733,9 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D, if (AL.isArgIdent(0)) { IdentifierLoc *IL = AL.getArgAsIdent(0); if (!VTablePointerAuthenticationAttr::ConvertStrToVPtrAuthKeyType( - IL->Ident->getName(), KeyType)) { - S.Diag(IL->Loc, diag::err_invalid_authentication_key) << IL->Ident; + IL->getIdentifierInfo()->getName(), KeyType)) { + S.Diag(IL->getLoc(), diag::err_invalid_authentication_key) + << IL->getIdentifierInfo(); AL.setInvalid(); } if (KeyType == VTablePointerAuthenticationAttr::DefaultKey && @@ -6751,15 +6755,16 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D, if (AL.isArgIdent(1)) { IdentifierLoc *IL = AL.getArgAsIdent(1); if (!VTablePointerAuthenticationAttr:: - ConvertStrToAddressDiscriminationMode(IL->Ident->getName(), - AddressDiversityMode)) { - S.Diag(IL->Loc, diag::err_invalid_address_discrimination) << IL->Ident; + ConvertStrToAddressDiscriminationMode( + IL->getIdentifierInfo()->getName(), AddressDiversityMode)) { + S.Diag(IL->getLoc(), diag::err_invalid_address_discrimination) + << IL->getIdentifierInfo(); AL.setInvalid(); } if (AddressDiversityMode == VTablePointerAuthenticationAttr::DefaultAddressDiscrimination && !S.getLangOpts().PointerAuthCalls) { - S.Diag(IL->Loc, diag::err_no_default_vtable_pointer_auth) << 1; + S.Diag(IL->getLoc(), diag::err_no_default_vtable_pointer_auth) << 1; AL.setInvalid(); } } else { @@ -6774,8 +6779,9 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D, if (AL.isArgIdent(2)) { IdentifierLoc *IL = AL.getArgAsIdent(2); if (!VTablePointerAuthenticationAttr::ConvertStrToExtraDiscrimination( - IL->Ident->getName(), ED)) { - S.Diag(IL->Loc, diag::err_invalid_extra_discrimination) << IL->Ident; + IL->getIdentifierInfo()->getName(), ED)) { + S.Diag(IL->getLoc(), diag::err_invalid_extra_discrimination) + << IL->getIdentifierInfo(); AL.setInvalid(); } if (ED == VTablePointerAuthenticationAttr::DefaultExtraDiscrimination && diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index ba9d3dcf19617..0a14ce23a396e 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -1310,24 +1310,26 @@ static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl, /// protocol declarations in its 'Protocols' argument. void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, - ArrayRef ProtocolId, + ArrayRef ProtocolId, SmallVectorImpl &Protocols) { - for (const IdentifierLocPair &Pair : ProtocolId) { - ObjCProtocolDecl *PDecl = LookupProtocol(Pair.first, Pair.second); + for (const IdentifierLoc &Pair : ProtocolId) { + ObjCProtocolDecl *PDecl = + LookupProtocol(Pair.getIdentifierInfo(), Pair.getLoc()); if (!PDecl) { DeclFilterCCC CCC{}; - TypoCorrection Corrected = - SemaRef.CorrectTypo(DeclarationNameInfo(Pair.first, Pair.second), - Sema::LookupObjCProtocolName, SemaRef.TUScope, - nullptr, CCC, Sema::CTK_ErrorRecovery); + TypoCorrection Corrected = SemaRef.CorrectTypo( + DeclarationNameInfo(Pair.getIdentifierInfo(), Pair.getLoc()), + Sema::LookupObjCProtocolName, SemaRef.TUScope, nullptr, CCC, + Sema::CTK_ErrorRecovery); if ((PDecl = Corrected.getCorrectionDeclAs())) SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_undeclared_protocol_suggest) - << Pair.first); + << Pair.getIdentifierInfo()); } if (!PDecl) { - Diag(Pair.second, diag::err_undeclared_protocol) << Pair.first; + Diag(Pair.getLoc(), diag::err_undeclared_protocol) + << Pair.getIdentifierInfo(); continue; } // If this is a forward protocol declaration, get its definition. @@ -1337,7 +1339,7 @@ void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations, // For an objc container, delay protocol reference checking until after we // can set the objc decl as the availability context, otherwise check now. if (!ForObjCContainer) { - (void)SemaRef.DiagnoseUseOfDecl(PDecl, Pair.second); + (void)SemaRef.DiagnoseUseOfDecl(PDecl, Pair.getLoc()); } // If this is a forward declaration and we are supposed to warn in this @@ -1347,7 +1349,8 @@ void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations, if (WarnOnDeclarations && NestedProtocolHasNoDefinition(PDecl, UndefinedProtocol)) { - Diag(Pair.second, diag::warn_undef_protocolref) << Pair.first; + Diag(Pair.getLoc(), diag::warn_undef_protocolref) + << Pair.getIdentifierInfo(); Diag(UndefinedProtocol->getLocation(), diag::note_protocol_decl_undefined) << UndefinedProtocol; } @@ -1784,17 +1787,17 @@ void SemaObjC::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, /// ActOnForwardProtocolDeclaration - Handle \@protocol foo; SemaObjC::DeclGroupPtrTy SemaObjC::ActOnForwardProtocolDeclaration( - SourceLocation AtProtocolLoc, ArrayRef IdentList, + SourceLocation AtProtocolLoc, ArrayRef IdentList, const ParsedAttributesView &attrList) { ASTContext &Context = getASTContext(); SmallVector DeclsInGroup; - for (const IdentifierLocPair &IdentPair : IdentList) { - IdentifierInfo *Ident = IdentPair.first; + for (const IdentifierLoc &IdentPair : IdentList) { + IdentifierInfo *Ident = IdentPair.getIdentifierInfo(); ObjCProtocolDecl *PrevDecl = LookupProtocol( - Ident, IdentPair.second, SemaRef.forRedeclarationInCurContext()); + Ident, IdentPair.getLoc(), SemaRef.forRedeclarationInCurContext()); ObjCProtocolDecl *PDecl = ObjCProtocolDecl::Create(Context, SemaRef.CurContext, Ident, - IdentPair.second, AtProtocolLoc, PrevDecl); + IdentPair.getLoc(), AtProtocolLoc, PrevDecl); SemaRef.PushOnScopeChains(PDecl, SemaRef.TUScope); CheckObjCDeclScope(PDecl); diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 0b442b75d174d..11f156ae09216 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->Ident->getName(); - SourceLocation ArgLoc = Loc->Loc; + StringRef Identifier = Loc->getIdentifierInfo()->getName(); + SourceLocation ArgLoc = Loc->getLoc(); // 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->Ident->getName(); - SourceLocation ArgLoc = Loc->Loc; + StringRef Str = Loc->getIdentifierInfo()->getName(); + SourceLocation ArgLoc = Loc->getLoc(); SourceLocation SpaceArgLoc; bool SpecifiedSpace = false; @@ -1549,8 +1549,8 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) { } IdentifierLoc *Loc = AL.getArgAsIdent(1); - Space = Loc->Ident->getName(); - SpaceArgLoc = Loc->Loc; + Space = Loc->getIdentifierInfo()->getName(); + SpaceArgLoc = Loc->getLoc(); } else { Slot = Str; } diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 76589bff40be9..4bba57193ded6 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -15,6 +15,7 @@ #include "clang/AST/ASTMutationListener.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Sema/ParsedAttr.h" #include "clang/Sema/SemaInternal.h" #include "llvm/ADT/StringExtras.h" @@ -68,7 +69,7 @@ static std::string stringFromPath(ModuleIdPath Path) { for (auto &Piece : Path) { if (!Name.empty()) Name += "."; - Name += Piece.first->getName(); + Name += Piece.getIdentifierInfo()->getName(); } return Name; } @@ -350,17 +351,18 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // Test the first part of the path to see if it's std[0-9]+ but allow the // name in a system header. - StringRef FirstComponentName = Path[0].first->getName(); - if (!getSourceManager().isInSystemHeader(Path[0].second) && + StringRef FirstComponentName = Path[0].getIdentifierInfo()->getName(); + if (!getSourceManager().isInSystemHeader(Path[0].getLoc()) && (FirstComponentName == "std" || (FirstComponentName.starts_with("std") && llvm::all_of(FirstComponentName.drop_front(3), &llvm::isDigit)))) - Diag(Path[0].second, diag::warn_reserved_module_name) << Path[0].first; + Diag(Path[0].getLoc(), diag::warn_reserved_module_name) + << Path[0].getIdentifierInfo(); // Then test all of the components in the path to see if any of them are // using another kind of reserved or invalid identifier. for (auto Part : Path) { - if (DiagReservedModuleName(*this, Part.first, Part.second)) + if (DiagReservedModuleName(*this, Part.getIdentifierInfo(), Part.getLoc())) return nullptr; } @@ -376,10 +378,10 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // correct. if (!getLangOpts().CurrentModule.empty() && getLangOpts().CurrentModule != ModuleName) { - Diag(Path.front().second, diag::err_current_module_name_mismatch) - << SourceRange(Path.front().second, IsPartition - ? Partition.back().second - : Path.back().second) + Diag(Path.front().getLoc(), diag::err_current_module_name_mismatch) + << SourceRange(Path.front().getLoc(), IsPartition + ? Partition.back().getLoc() + : Path.back().getLoc()) << getLangOpts().CurrentModule; return nullptr; } @@ -394,7 +396,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // We can't have parsed or imported a definition of this module or parsed a // module map defining it already. if (auto *M = Map.findModule(ModuleName)) { - Diag(Path[0].second, diag::err_module_redefinition) << ModuleName; + Diag(Path[0].getLoc(), diag::err_module_redefinition) << ModuleName; if (M->DefinitionLoc.isValid()) Diag(M->DefinitionLoc, diag::note_prev_module_definition); else if (OptionalFileEntryRef FE = M->getASTFile()) @@ -417,8 +419,8 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // keyword nor a module-partition implicitly imports the primary // module interface unit of the module as if by a module-import- // declaration. - std::pair ModuleNameLoc( - PP.getIdentifierInfo(ModuleName), Path[0].second); + IdentifierLoc ModuleNameLoc(Path[0].getLoc(), + PP.getIdentifierInfo(ModuleName)); // The module loader will assume we're trying to import the module that // we're building if `LangOpts.CurrentModule` equals to 'ModuleName'. @@ -490,7 +492,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // Make the import decl for the interface in the impl module. ImportDecl *Import = ImportDecl::Create(Context, CurContext, ModuleLoc, - Interface, Path[0].second); + Interface, Path[0].getLoc()); CurContext->addDecl(Import); // Sequence initialization of the imported module before that of the current @@ -579,7 +581,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, // For a C++20 module name, flatten into a single identifier with the source // location of the first component. - std::pair ModuleNameLoc; + IdentifierLoc ModuleNameLoc; std::string ModuleName; if (IsPartition) { @@ -591,11 +593,13 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, ModuleName = NamedMod->getPrimaryModuleInterfaceName().str(); ModuleName += ":"; ModuleName += stringFromPath(Path); - ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second}; + ModuleNameLoc = + IdentifierLoc(Path[0].getLoc(), PP.getIdentifierInfo(ModuleName)); Path = ModuleIdPath(ModuleNameLoc); } else if (getLangOpts().CPlusPlusModules) { ModuleName = stringFromPath(Path); - ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second}; + ModuleNameLoc = + IdentifierLoc(Path[0].getLoc(), PP.getIdentifierInfo(ModuleName)); Path = ModuleIdPath(ModuleNameLoc); } @@ -680,7 +684,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, IdentifierLocs.push_back(SourceLocation()); } else if (getLangOpts().CPlusPlusModules && !Mod->Parent) { // A single identifier for the whole name. - IdentifierLocs.push_back(Path[0].second); + IdentifierLocs.push_back(Path[0].getLoc()); } else { Module *ModCheck = Mod; for (unsigned I = 0, N = Path.size(); I != N; ++I) { @@ -690,7 +694,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, break; ModCheck = ModCheck->Parent; - IdentifierLocs.push_back(Path[I].second); + IdentifierLocs.push_back(Path[I].getLoc()); } } @@ -707,7 +711,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, if (getLangOpts().CPlusPlusModules && ExportLoc.isValid() && Mod->Kind == Module::ModuleKind::ModulePartitionImplementation) { Diag(ExportLoc, diag::err_export_partition_impl) - << SourceRange(ExportLoc, Path.back().second); + << SourceRange(ExportLoc, Path.back().getLoc()); } else if (!ModuleScopes.empty() && !currentModuleIsImplementation()) { // Re-export the module if the imported module is exported. // Note that we don't need to add re-exported module to Imports field diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index 073d9791d037b..9b24b5f052119 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -1446,10 +1446,8 @@ SemaObjC::ObjCSubscriptKind SemaObjC::CheckSubscriptingKind(Expr *FromE) { void SemaObjC::AddCFAuditedAttribute(Decl *D) { ASTContext &Context = getASTContext(); - IdentifierInfo *Ident; - SourceLocation Loc; - std::tie(Ident, Loc) = SemaRef.PP.getPragmaARCCFCodeAuditedInfo(); - if (!Loc.isValid()) + auto IdLoc = SemaRef.PP.getPragmaARCCFCodeAuditedInfo(); + if (!IdLoc.getLoc().isValid()) return; // Don't add a redundant or conflicting attribute. @@ -1457,7 +1455,8 @@ void SemaObjC::AddCFAuditedAttribute(Decl *D) { D->hasAttr()) return; - AttributeCommonInfo Info(Ident, SourceRange(Loc), + AttributeCommonInfo Info(IdLoc.getIdentifierInfo(), + SourceRange(IdLoc.getLoc()), AttributeCommonInfo::Form::Pragma()); D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info)); } @@ -1642,8 +1641,10 @@ void SemaObjC::handleMethodFamilyAttr(Decl *D, const ParsedAttr &AL) { IdentifierLoc *IL = AL.getArgAsIdent(0); ObjCMethodFamilyAttr::FamilyKind F; - if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->Ident->getName(), F)) { - Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL << IL->Ident; + if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind( + IL->getIdentifierInfo()->getName(), F)) { + Diag(IL->getLoc(), diag::warn_attribute_type_not_supported) + << AL << IL->getIdentifierInfo(); return; } @@ -1706,7 +1707,7 @@ void SemaObjC::handleBlocksAttr(Decl *D, const ParsedAttr &AL) { return; } - IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); BlocksAttr::BlockType type; if (!BlocksAttr::ConvertStrToBlockType(II->getName(), type)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; @@ -1998,7 +1999,7 @@ void SemaObjC::handleNSErrorDomain(Decl *D, const ParsedAttr &Attr) { IdentifierLoc *IdentLoc = Attr.isArgIdent(0) ? Attr.getArgAsIdent(0) : nullptr; - if (!IdentLoc || !IdentLoc->Ident) { + if (!IdentLoc || !IdentLoc->getIdentifierInfo()) { // Try to locate the argument directly. SourceLocation Loc = Attr.getLoc(); if (Attr.isArgExpr(0) && Attr.getArgAsExpr(0)) @@ -2009,18 +2010,18 @@ void SemaObjC::handleNSErrorDomain(Decl *D, const ParsedAttr &Attr) { } // Verify that the identifier is a valid decl in the C decl namespace. - LookupResult Result(SemaRef, DeclarationName(IdentLoc->Ident), + LookupResult Result(SemaRef, DeclarationName(IdentLoc->getIdentifierInfo()), SourceLocation(), Sema::LookupNameKind::LookupOrdinaryName); if (!SemaRef.LookupName(Result, SemaRef.TUScope) || !Result.getAsSingle()) { - Diag(IdentLoc->Loc, diag::err_nserrordomain_invalid_decl) - << 1 << IdentLoc->Ident; + Diag(IdentLoc->getLoc(), diag::err_nserrordomain_invalid_decl) + << 1 << IdentLoc->getIdentifierInfo(); return; } - D->addAttr(::new (getASTContext()) - NSErrorDomainAttr(getASTContext(), Attr, IdentLoc->Ident)); + D->addAttr(::new (getASTContext()) NSErrorDomainAttr( + getASTContext(), Attr, IdentLoc->getIdentifierInfo())); } void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) { @@ -2033,7 +2034,7 @@ void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) { // Typedefs only allow objc_bridge(id) and have some additional checking. if (const auto *TD = dyn_cast(D)) { - if (!Parm->Ident->isStr("id")) { + if (!Parm->getIdentifierInfo()->isStr("id")) { Diag(AL.getLoc(), diag::err_objc_attr_typedef_not_id) << AL; return; } @@ -2046,8 +2047,8 @@ void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) { } } - D->addAttr(::new (getASTContext()) - ObjCBridgeAttr(getASTContext(), AL, Parm->Ident)); + D->addAttr(::new (getASTContext()) ObjCBridgeAttr(getASTContext(), AL, + Parm->getIdentifierInfo())); } void SemaObjC::handleBridgeMutableAttr(Decl *D, const ParsedAttr &AL) { @@ -2058,21 +2059,21 @@ void SemaObjC::handleBridgeMutableAttr(Decl *D, const ParsedAttr &AL) { return; } - D->addAttr(::new (getASTContext()) - ObjCBridgeMutableAttr(getASTContext(), AL, Parm->Ident)); + D->addAttr(::new (getASTContext()) ObjCBridgeMutableAttr( + getASTContext(), AL, Parm->getIdentifierInfo())); } void SemaObjC::handleBridgeRelatedAttr(Decl *D, const ParsedAttr &AL) { IdentifierInfo *RelatedClass = - AL.isArgIdent(0) ? AL.getArgAsIdent(0)->Ident : nullptr; + AL.isArgIdent(0) ? AL.getArgAsIdent(0)->getIdentifierInfo() : nullptr; if (!RelatedClass) { Diag(D->getBeginLoc(), diag::err_objc_attr_not_id) << AL << 0; return; } IdentifierInfo *ClassMethod = - AL.getArgAsIdent(1) ? AL.getArgAsIdent(1)->Ident : nullptr; + AL.getArgAsIdent(1) ? AL.getArgAsIdent(1)->getIdentifierInfo() : nullptr; IdentifierInfo *InstanceMethod = - AL.getArgAsIdent(2) ? AL.getArgAsIdent(2)->Ident : nullptr; + AL.getArgAsIdent(2) ? AL.getArgAsIdent(2)->getIdentifierInfo() : nullptr; D->addAttr(::new (getASTContext()) ObjCBridgeRelatedAttr( getASTContext(), AL, RelatedClass, ClassMethod, InstanceMethod)); } diff --git a/clang/lib/Sema/SemaOpenACCClause.cpp b/clang/lib/Sema/SemaOpenACCClause.cpp index ab25dcfd1a081..049baead031a1 100644 --- a/clang/lib/Sema/SemaOpenACCClause.cpp +++ b/clang/lib/Sema/SemaOpenACCClause.cpp @@ -1343,7 +1343,7 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause( // the limitation, since the Dialect requires this. if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Set && Clause.getDeviceTypeArchitectures().size() > 1) { - SemaRef.Diag(Clause.getDeviceTypeArchitectures()[1].second, + SemaRef.Diag(Clause.getDeviceTypeArchitectures()[1].getLoc(), diag::err_acc_device_type_multiple_archs); return nullptr; } @@ -1369,16 +1369,17 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause( bool Diagnosed = false; auto FilterPred = [&](const DeviceTypeArgument &Arch) { // The '*' case. - if (!Arch.first) + if (!Arch.getIdentifierInfo()) return false; return llvm::find_if(ValidValues, [&](StringRef RHS) { - return Arch.first->getName().equals_insensitive(RHS); + return Arch.getIdentifierInfo()->getName().equals_insensitive(RHS); }) == ValidValues.end(); }; auto Diagnose = [&](const DeviceTypeArgument &Arch) { - Diagnosed = SemaRef.Diag(Arch.second, diag::err_acc_invalid_default_type) - << Arch.first << Clause.getClauseKind() << ValidValuesString; + Diagnosed = SemaRef.Diag(Arch.getLoc(), diag::err_acc_invalid_default_type) + << Arch.getIdentifierInfo() << Clause.getClauseKind() + << ValidValuesString; }; // There aren't stable enumertor versions of 'for-each-then-erase', so do it diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index 2f719c6d7a21e..a09626c3a9a8c 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -79,9 +79,10 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, Expr *ValueExpr = A.getArgAsExpr(3); StringRef PragmaName = - llvm::StringSwitch(PragmaNameLoc->Ident->getName()) + llvm::StringSwitch( + PragmaNameLoc->getIdentifierInfo()->getName()) .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam", - PragmaNameLoc->Ident->getName()) + PragmaNameLoc->getIdentifierInfo()->getName()) .Default("clang loop"); // This could be handled automatically by adding a Subjects definition in @@ -127,10 +128,10 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Enable); } else { // #pragma clang loop ... - assert(OptionLoc && OptionLoc->Ident && + assert(OptionLoc && OptionLoc->getIdentifierInfo() && "Attribute must have valid option info."); Option = llvm::StringSwitch( - OptionLoc->Ident->getName()) + OptionLoc->getIdentifierInfo()->getName()) .Case("vectorize", LoopHintAttr::Vectorize) .Case("vectorize_width", LoopHintAttr::VectorizeWidth) .Case("interleave", LoopHintAttr::Interleave) @@ -144,12 +145,13 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, .Case("distribute", LoopHintAttr::Distribute) .Default(LoopHintAttr::Vectorize); if (Option == LoopHintAttr::VectorizeWidth) { - assert((ValueExpr || (StateLoc && StateLoc->Ident)) && + assert((ValueExpr || (StateLoc && StateLoc->getIdentifierInfo())) && "Attribute must have a valid value expression or argument."); if (ValueExpr && S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc(), /*AllowZero=*/false)) return nullptr; - if (StateLoc && StateLoc->Ident && StateLoc->Ident->isStr("scalable")) + if (StateLoc && StateLoc->getIdentifierInfo() && + StateLoc->getIdentifierInfo()->isStr("scalable")) State = LoopHintAttr::ScalableWidth; else State = LoopHintAttr::FixedWidth; @@ -167,14 +169,15 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, Option == LoopHintAttr::Unroll || Option == LoopHintAttr::Distribute || Option == LoopHintAttr::PipelineDisabled) { - assert(StateLoc && StateLoc->Ident && "Loop hint must have an argument"); - if (StateLoc->Ident->isStr("disable")) + assert(StateLoc && StateLoc->getIdentifierInfo() && + "Loop hint must have an argument"); + if (StateLoc->getIdentifierInfo()->isStr("disable")) State = LoopHintAttr::Disable; - else if (StateLoc->Ident->isStr("assume_safety")) + else if (StateLoc->getIdentifierInfo()->isStr("assume_safety")) State = LoopHintAttr::AssumeSafety; - else if (StateLoc->Ident->isStr("full")) + else if (StateLoc->getIdentifierInfo()->isStr("full")) State = LoopHintAttr::Full; - else if (StateLoc->Ident->isStr("enable")) + else if (StateLoc->getIdentifierInfo()->isStr("enable")) State = LoopHintAttr::Enable; else llvm_unreachable("bad loop hint argument"); @@ -644,8 +647,8 @@ static Attr *handleAtomicAttr(Sema &S, Stmt *St, const ParsedAttr &AL, } IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex); - OptionString = Ident->Ident->getName(); - Loc = Ident->Loc; + OptionString = Ident->getIdentifierInfo()->getName(); + Loc = Ident->getLoc(); if (!AtomicAttr::ConvertStrToConsumedOption(OptionString, Option)) { S.Diag(Loc, diag::err_attribute_invalid_atomic_argument) << OptionString; return nullptr; diff --git a/clang/lib/Sema/SemaSwift.cpp b/clang/lib/Sema/SemaSwift.cpp index fe72d6c85c37a..4aae855a24b8f 100644 --- a/clang/lib/Sema/SemaSwift.cpp +++ b/clang/lib/Sema/SemaSwift.cpp @@ -148,8 +148,8 @@ void SemaSwift::handleError(Decl *D, const ParsedAttr &AL) { return true; S.Diag(AL.getLoc(), diag::err_attr_swift_error_return_type) - << AL << AL.getArgAsIdent(0)->Ident->getName() << isa(D) - << /*pointer*/ 1; + << AL << AL.getArgAsIdent(0)->getIdentifierInfo()->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)->Ident->getName() << isa(D) - << /*integral*/ 0; + << AL << AL.getArgAsIdent(0)->getIdentifierInfo()->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->Ident->getName(), - Convention)) { + if (!SwiftErrorAttr::ConvertStrToConventionKind( + Loc->getIdentifierInfo()->getName(), Convention)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) - << AL << Loc->Ident; + << AL << Loc->getIdentifierInfo(); return; } @@ -287,10 +287,10 @@ static void checkSwiftAsyncErrorBlock(Sema &S, Decl *D, void SemaSwift::handleAsyncError(Decl *D, const ParsedAttr &AL) { IdentifierLoc *IDLoc = AL.getArgAsIdent(0); SwiftAsyncErrorAttr::ConventionKind ConvKind; - if (!SwiftAsyncErrorAttr::ConvertStrToConventionKind(IDLoc->Ident->getName(), - ConvKind)) { + if (!SwiftAsyncErrorAttr::ConvertStrToConventionKind( + IDLoc->getIdentifierInfo()->getName(), ConvKind)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) - << AL << IDLoc->Ident; + << AL << IDLoc->getIdentifierInfo(); return; } @@ -643,7 +643,7 @@ void SemaSwift::handleNewType(Decl *D, const ParsedAttr &AL) { } SwiftNewTypeAttr::NewtypeKind Kind; - IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); if (!SwiftNewTypeAttr::ConvertStrToNewtypeKind(II->getName(), Kind)) { Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; return; @@ -667,7 +667,7 @@ void SemaSwift::handleAsyncAttr(Decl *D, const ParsedAttr &AL) { } SwiftAsyncAttr::Kind Kind; - IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo(); if (!SwiftAsyncAttr::ConvertStrToKind(II->getName(), Kind)) { Diag(AL.getLoc(), diag::err_swift_async_no_access) << AL << II; return; diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp index dc7e3a0bf8875..87682233c5246 100644 --- a/clang/lib/Sema/SemaTemplateVariadic.cpp +++ b/clang/lib/Sema/SemaTemplateVariadic.cpp @@ -14,6 +14,7 @@ #include "clang/AST/ExprObjC.h" #include "clang/AST/TypeLoc.h" #include "clang/Sema/Lookup.h" +#include "clang/Sema/ParsedAttr.h" #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/ScopeInfo.h" #include "clang/Sema/Sema.h" @@ -755,7 +756,7 @@ bool Sema::CheckParameterPacksForExpansion( bool &RetainExpansion, UnsignedOrNone &NumExpansions) { ShouldExpand = true; RetainExpansion = false; - std::pair FirstPack; + IdentifierLoc FirstPack; bool HaveFirstPack = false; UnsignedOrNone NumPartialExpansions = std::nullopt; SourceLocation PartiallySubstitutedPackLoc; @@ -867,8 +868,7 @@ bool Sema::CheckParameterPacksForExpansion( // This is the first pack we've seen for which we have an argument. // Record it. NumExpansions = NewPackSize; - FirstPack.first = Name; - FirstPack.second = ParmPack.second; + FirstPack = IdentifierLoc(ParmPack.second, Name); HaveFirstPack = true; continue; } @@ -905,9 +905,9 @@ bool Sema::CheckParameterPacksForExpansion( // the same number of arguments specified. if (HaveFirstPack) Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict) - << FirstPack.first << Name << *NumExpansions + << FirstPack.getIdentifierInfo() << Name << *NumExpansions << (LeastNewPackSize != NewPackSize) << LeastNewPackSize - << SourceRange(FirstPack.second) << SourceRange(ParmPack.second); + << SourceRange(FirstPack.getLoc()) << SourceRange(ParmPack.second); else Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel) << Name << *NumExpansions << (LeastNewPackSize != NewPackSize) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 33b1d8ca4dfa0..da5249f0573bd 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -99,8 +99,8 @@ static void diagnoseBadTypeAttribute(Sema &S, const ParsedAttr &attr, StringRef name = attr.getAttrName()->getName(); // The GC attributes are usually written with macros; special-case them. - IdentifierInfo *II = attr.isArgIdent(0) ? attr.getArgAsIdent(0)->Ident - : nullptr; + IdentifierInfo *II = + attr.isArgIdent(0) ? attr.getArgAsIdent(0)->getIdentifierInfo() : nullptr; if (useExpansionLoc && loc.isMacroID() && II) { if (II->isStr("strong")) { if (S.findMacroSpelling(loc, "__strong")) name = "__strong"; @@ -5717,8 +5717,7 @@ static void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state, } IdentifierLoc *Arg = new (S.Context) IdentifierLoc; - Arg->Ident = &S.Context.Idents.get(attrStr); - Arg->Loc = SourceLocation(); + Arg->setIdentifierInfo(&S.Context.Idents.get(attrStr)); ArgsUnion Args(Arg); @@ -6618,7 +6617,7 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state, return true; } - IdentifierInfo *II = attr.getArgAsIdent(0)->Ident; + IdentifierInfo *II = attr.getArgAsIdent(0)->getIdentifierInfo(); Qualifiers::ObjCLifetime lifetime; if (II->isStr("none")) lifetime = Qualifiers::OCL_ExplicitNone; @@ -6796,7 +6795,7 @@ static bool handleObjCGCTypeAttr(TypeProcessingState &state, ParsedAttr &attr, return true; } - IdentifierInfo *II = attr.getArgAsIdent(0)->Ident; + IdentifierInfo *II = attr.getArgAsIdent(0)->getIdentifierInfo(); if (II->isStr("weak")) GCAttr = Qualifiers::Weak; else if (II->isStr("strong")) @@ -7526,7 +7525,7 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr) { if (Attr.isArgExpr(0)) Str = cast(Attr.getArgAsExpr(0))->getString(); else - Str = Attr.getArgAsIdent(0)->Ident->getName(); + Str = Attr.getArgAsIdent(0)->getIdentifierInfo()->getName(); PcsAttr::PCSType Type; if (!PcsAttr::ConvertStrToPCSType(Str, Type)) llvm_unreachable("already validated the attribute"); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 02c31dff620ec..b404015867087 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(Ident, Loc); + Archs.emplace_back(Loc, Ident); } return OpenACCDeviceTypeClause::Create(getContext(), ClauseKind, BeginLoc, diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 95b5718f1d140..4dca0613cb9ae 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.first); - if (Arg.first) - AddIdentifierRef(Arg.first); - writeSourceLocation(Arg.second); + writeBool(Arg.getIdentifierInfo()); + if (Arg.getIdentifierInfo()) + AddIdentifierRef(Arg.getIdentifierInfo()); + writeSourceLocation(Arg.getLoc()); } return; } diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index ebd392fbfa7d6..d41d24d4af3ac 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].first->getName().str(); + RequiredModule.ModuleName = Path[0].getIdentifierInfo()->getName().str(); RequiredModule.Type = P1689ModuleInfo::ModuleType::NamedCXXModule; MDC.RequiredStdCXXModules.push_back(RequiredModule); return;