[clang] 19131c7 - [clang][modules][lldb] Fix build after #113391

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 28 12:51:00 PDT 2024


Author: Jan Svoboda
Date: 2024-10-28T12:50:53-07:00
New Revision: 19131c7f36e047898ea954ee5a187ac62f2ab09b

URL: https://github.com/llvm/llvm-project/commit/19131c7f36e047898ea954ee5a187ac62f2ab09b
DIFF: https://github.com/llvm/llvm-project/commit/19131c7f36e047898ea954ee5a187ac62f2ab09b.diff

LOG: [clang][modules][lldb] Fix build after #113391

Instead of changing the return type of `ModuleMap::findOrCreateModule`, this patch adds a counterpart that only returns `Module *` and thus has the same signature as `createModule()`, which is important in `ASTReader`.

Added: 
    

Modified: 
    clang/include/clang/Lex/ModuleMap.h
    clang/lib/Lex/ModuleMap.cpp
    clang/lib/Serialization/ASTReader.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h
index 5ee152e4213abf..53e9e0ec83ddb1 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -541,9 +541,17 @@ class ModuleMap {
   ///
   /// \param IsExplicit Whether this is an explicit submodule.
   ///
-  /// \returns The found or newly-created module.
-  Module *findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
-                             bool IsExplicit);
+  /// \returns The found or newly-created module, along with a boolean value
+  /// that will be true if the module is newly-created.
+  std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent,
+                                               bool IsFramework,
+                                               bool IsExplicit);
+  /// Call \c ModuleMap::findOrCreateModule and throw away the information
+  /// whether the module was found or created.
+  Module *findOrCreateModuleFirst(StringRef Name, Module *Parent,
+                                  bool IsFramework, bool IsExplicit) {
+    return findOrCreateModule(Name, Parent, IsFramework, IsExplicit).first;
+  }
   /// Create new submodule, assuming it does not exist. This function can only
   /// be called when it is guaranteed that this submodule does not exist yet.
   /// The parameters have same semantics as \c ModuleMap::findOrCreateModule.

diff  --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 10774429a2177b..dc9d2bfd5629c9 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -655,8 +655,8 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) {
         SmallString<32> NameBuf;
         StringRef Name = sanitizeFilenameAsIdentifier(
             llvm::sys::path::stem(SkippedDir.getName()), NameBuf);
-        Result =
-            findOrCreateModule(Name, Result, /*IsFramework=*/false, Explicit);
+        Result = findOrCreateModuleFirst(Name, Result, /*IsFramework=*/false,
+                                         Explicit);
         setInferredModuleAllowedBy(Result, UmbrellaModuleMap);
 
         // Associate the module and the directory.
@@ -672,8 +672,8 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File) {
       SmallString<32> NameBuf;
       StringRef Name = sanitizeFilenameAsIdentifier(
                          llvm::sys::path::stem(File.getName()), NameBuf);
-      Result =
-          findOrCreateModule(Name, Result, /*IsFramework=*/false, Explicit);
+      Result = findOrCreateModuleFirst(Name, Result, /*IsFramework=*/false,
+                                       Explicit);
       setInferredModuleAllowedBy(Result, UmbrellaModuleMap);
       Result->addTopHeader(File);
 
@@ -857,14 +857,17 @@ Module *ModuleMap::lookupModuleQualified(StringRef Name, Module *Context) const{
   return Context->findSubmodule(Name);
 }
 
-Module *ModuleMap::findOrCreateModule(StringRef Name, Module *Parent,
-                                      bool IsFramework, bool IsExplicit) {
+std::pair<Module *, bool> ModuleMap::findOrCreateModule(StringRef Name,
+                                                        Module *Parent,
+                                                        bool IsFramework,
+                                                        bool IsExplicit) {
   // Try to find an existing module with this name.
   if (Module *Sub = lookupModuleQualified(Name, Parent))
-    return Sub;
+    return std::make_pair(Sub, false);
 
   // Create a new module with this name.
-  return createModule(Name, Parent, IsFramework, IsExplicit);
+  Module *M = createModule(Name, Parent, IsFramework, IsExplicit);
+  return std::make_pair(M, true);
 }
 
 Module *ModuleMap::createModule(StringRef Name, Module *Parent,
@@ -2129,8 +2132,8 @@ void ModuleMapParser::parseModuleDecl() {
     ActiveModule =
         Map.createShadowedModule(ModuleName, Framework, ShadowingModule);
   } else {
-    ActiveModule =
-        Map.findOrCreateModule(ModuleName, ActiveModule, Framework, Explicit);
+    ActiveModule = Map.findOrCreateModuleFirst(ModuleName, ActiveModule,
+                                               Framework, Explicit);
   }
 
   ActiveModule->DefinitionLoc = ModuleNameLoc;

diff  --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 74a79ac54bb4eb..8d8f9378cfeabe 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -5760,8 +5760,9 @@ llvm::Error ASTReader::ReadSubmoduleBlock(ModuleFile &F,
   // If we don't know the top-level module, there's no point in doing qualified
   // lookup of its submodules; it won't find anything anywhere within this tree.
   // Let's skip that and avoid some string lookups.
-  auto CreateModule = !KnowsTopLevelModule ? &ModuleMap::createModule
-                                           : &ModuleMap::findOrCreateModule;
+  auto CreateModule = !KnowsTopLevelModule
+                          ? &ModuleMap::createModule
+                          : &ModuleMap::findOrCreateModuleFirst;
 
   bool First = true;
   Module *CurrentModule = nullptr;


        


More information about the cfe-commits mailing list