diff options
author | Michael Buch <michaelbuch12@gmail.com> | 2025-04-16 17:05:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-16 17:05:53 +0200 |
commit | 99c08ff1cb96fc4f471aca0dd253060b3f32e8bc (patch) | |
tree | ad0c002d6ec23b6f4a24dfc95bbd870f2fb1f016 /clang/lib/Sema/SemaModule.cpp | |
parent | ef1abbe32e66c16118ded6dd9f7b1a55dea8c2b6 (diff) | |
download | llvm-99c08ff1cb96fc4f471aca0dd253060b3f32e8bc.zip llvm-99c08ff1cb96fc4f471aca0dd253060b3f32e8bc.tar.gz llvm-99c08ff1cb96fc4f471aca0dd253060b3f32e8bc.tar.bz2 |
Revert "[clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc`" (#135974)
Reverts llvm/llvm-project#135808
Example from the LLDB macOS CI:
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/24084/execution/node/54/log/?consoleFull
```
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp:360:49: error: no viable conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'clang::ModuleIdPath' (aka 'ArrayRef<IdentifierLoc>')
clang::Module *top_level_module = DoGetModule(clang_path.front(), false);
^~~~~~~~~~~~~~~~~~
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:41:40: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'const llvm::ArrayRef<clang::IdentifierLoc> &' for 1st argument
class LLVM_GSL_POINTER [[nodiscard]] ArrayRef {
^
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:41:40: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'llvm::ArrayRef<clang::IdentifierLoc> &&' for 1st argument
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:70:18: note: candidate constructor not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'std::nullopt_t' for 1st argument
/*implicit*/ ArrayRef(std::nullopt_t) {}
```
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r-- | clang/lib/Sema/SemaModule.cpp | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 4bba571..76589bf 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -15,7 +15,6 @@ #include "clang/AST/ASTMutationListener.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" -#include "clang/Sema/ParsedAttr.h" #include "clang/Sema/SemaInternal.h" #include "llvm/ADT/StringExtras.h" @@ -69,7 +68,7 @@ static std::string stringFromPath(ModuleIdPath Path) { for (auto &Piece : Path) { if (!Name.empty()) Name += "."; - Name += Piece.getIdentifierInfo()->getName(); + Name += Piece.first->getName(); } return Name; } @@ -351,18 +350,17 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // Test the first part of the path to see if it's std[0-9]+ but allow the // name in a system header. - StringRef FirstComponentName = Path[0].getIdentifierInfo()->getName(); - if (!getSourceManager().isInSystemHeader(Path[0].getLoc()) && + StringRef FirstComponentName = Path[0].first->getName(); + if (!getSourceManager().isInSystemHeader(Path[0].second) && (FirstComponentName == "std" || (FirstComponentName.starts_with("std") && llvm::all_of(FirstComponentName.drop_front(3), &llvm::isDigit)))) - Diag(Path[0].getLoc(), diag::warn_reserved_module_name) - << Path[0].getIdentifierInfo(); + Diag(Path[0].second, diag::warn_reserved_module_name) << Path[0].first; // Then test all of the components in the path to see if any of them are // using another kind of reserved or invalid identifier. for (auto Part : Path) { - if (DiagReservedModuleName(*this, Part.getIdentifierInfo(), Part.getLoc())) + if (DiagReservedModuleName(*this, Part.first, Part.second)) return nullptr; } @@ -378,10 +376,10 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // correct. if (!getLangOpts().CurrentModule.empty() && getLangOpts().CurrentModule != ModuleName) { - Diag(Path.front().getLoc(), diag::err_current_module_name_mismatch) - << SourceRange(Path.front().getLoc(), IsPartition - ? Partition.back().getLoc() - : Path.back().getLoc()) + Diag(Path.front().second, diag::err_current_module_name_mismatch) + << SourceRange(Path.front().second, IsPartition + ? Partition.back().second + : Path.back().second) << getLangOpts().CurrentModule; return nullptr; } @@ -396,7 +394,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // We can't have parsed or imported a definition of this module or parsed a // module map defining it already. if (auto *M = Map.findModule(ModuleName)) { - Diag(Path[0].getLoc(), diag::err_module_redefinition) << ModuleName; + Diag(Path[0].second, diag::err_module_redefinition) << ModuleName; if (M->DefinitionLoc.isValid()) Diag(M->DefinitionLoc, diag::note_prev_module_definition); else if (OptionalFileEntryRef FE = M->getASTFile()) @@ -419,8 +417,8 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // keyword nor a module-partition implicitly imports the primary // module interface unit of the module as if by a module-import- // declaration. - IdentifierLoc ModuleNameLoc(Path[0].getLoc(), - PP.getIdentifierInfo(ModuleName)); + std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc( + PP.getIdentifierInfo(ModuleName), Path[0].second); // The module loader will assume we're trying to import the module that // we're building if `LangOpts.CurrentModule` equals to 'ModuleName'. @@ -492,7 +490,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // Make the import decl for the interface in the impl module. ImportDecl *Import = ImportDecl::Create(Context, CurContext, ModuleLoc, - Interface, Path[0].getLoc()); + Interface, Path[0].second); CurContext->addDecl(Import); // Sequence initialization of the imported module before that of the current @@ -581,7 +579,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, // For a C++20 module name, flatten into a single identifier with the source // location of the first component. - IdentifierLoc ModuleNameLoc; + std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc; std::string ModuleName; if (IsPartition) { @@ -593,13 +591,11 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, ModuleName = NamedMod->getPrimaryModuleInterfaceName().str(); ModuleName += ":"; ModuleName += stringFromPath(Path); - ModuleNameLoc = - IdentifierLoc(Path[0].getLoc(), PP.getIdentifierInfo(ModuleName)); + ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second}; Path = ModuleIdPath(ModuleNameLoc); } else if (getLangOpts().CPlusPlusModules) { ModuleName = stringFromPath(Path); - ModuleNameLoc = - IdentifierLoc(Path[0].getLoc(), PP.getIdentifierInfo(ModuleName)); + ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second}; Path = ModuleIdPath(ModuleNameLoc); } @@ -684,7 +680,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, IdentifierLocs.push_back(SourceLocation()); } else if (getLangOpts().CPlusPlusModules && !Mod->Parent) { // A single identifier for the whole name. - IdentifierLocs.push_back(Path[0].getLoc()); + IdentifierLocs.push_back(Path[0].second); } else { Module *ModCheck = Mod; for (unsigned I = 0, N = Path.size(); I != N; ++I) { @@ -694,7 +690,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, break; ModCheck = ModCheck->Parent; - IdentifierLocs.push_back(Path[I].getLoc()); + IdentifierLocs.push_back(Path[I].second); } } @@ -711,7 +707,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, if (getLangOpts().CPlusPlusModules && ExportLoc.isValid() && Mod->Kind == Module::ModuleKind::ModulePartitionImplementation) { Diag(ExportLoc, diag::err_export_partition_impl) - << SourceRange(ExportLoc, Path.back().getLoc()); + << SourceRange(ExportLoc, Path.back().second); } else if (!ModuleScopes.empty() && !currentModuleIsImplementation()) { // Re-export the module if the imported module is exported. // Note that we don't need to add re-exported module to Imports field |