jansvoboda11 updated this revision to Diff 379424.
jansvoboda11 added a comment.

Use clearer wording in member name & documentation, use `std::string` instead 
of `StringRef` for storing module name to solve lifetime issues (surfaced in 
CI).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111543/new/

https://reviews.llvm.org/D111543

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/test/Modules/Inputs/module-name-used-by-objc-bridge/Interface.h
  clang/test/Modules/Inputs/module-name-used-by-objc-bridge/InterfaceBridge.h
  clang/test/Modules/Inputs/module-name-used-by-objc-bridge/module.modulemap
  clang/test/Modules/module-name-used-by-objc-bridge.m

Index: clang/test/Modules/module-name-used-by-objc-bridge.m
===================================================================
--- /dev/null
+++ clang/test/Modules/module-name-used-by-objc-bridge.m
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t && mkdir %t
+
+// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-name=InterfaceBridge \
+// RUN:   %S/Inputs/module-name-used-by-objc-bridge/module.modulemap -o %t/InterfaceBridge.pcm
+
+// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-name=Interface \
+// RUN:   %S/Inputs/module-name-used-by-objc-bridge/module.modulemap -o %t/Interface.pcm
+
+// Check that the `-fmodule-file=<name>=<path>` form succeeds:
+// RUN: %clang_cc1 -fmodules -fsyntax-only %s -I %S/Inputs/module-name-used-by-objc-bridge \
+// RUN:   -fmodule-file=InterfaceBridge=%t/InterfaceBridge.pcm -fmodule-file=Interface=%t/Interface.pcm \
+// RUN:   -fmodule-map-file=%S/Inputs/module-name-used-by-objc-bridge/module.modulemap -verify
+
+// Check that the `-fmodule-file=<path>` form succeeds:
+// RUN: %clang_cc1 -fmodules -fsyntax-only %s -I %S/Inputs/module-name-used-by-objc-bridge \
+// RUN:   -fmodule-file=%t/InterfaceBridge.pcm -fmodule-file=%t/Interface.pcm \
+// RUN:   -fmodule-map-file=%S/Inputs/module-name-used-by-objc-bridge/module.modulemap -verify
+
+#import "InterfaceBridge.h"
+#import "Interface.h"
+
+@interface Interface (User)
+@end
+
+// expected-no-diagnostics
Index: clang/test/Modules/Inputs/module-name-used-by-objc-bridge/module.modulemap
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/module-name-used-by-objc-bridge/module.modulemap
@@ -0,0 +1,7 @@
+module InterfaceBridge {
+  header "InterfaceBridge.h"
+}
+
+module Interface {
+  header "Interface.h"
+}
Index: clang/test/Modules/Inputs/module-name-used-by-objc-bridge/InterfaceBridge.h
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/module-name-used-by-objc-bridge/InterfaceBridge.h
@@ -0,0 +1 @@
+typedef struct __attribute__((objc_bridge(Interface))) Foo *Bar;
Index: clang/test/Modules/Inputs/module-name-used-by-objc-bridge/Interface.h
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/module-name-used-by-objc-bridge/Interface.h
@@ -0,0 +1,2 @@
+@interface Interface
+@end
Index: clang/lib/Frontend/CompilerInstance.cpp
===================================================================
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -1639,28 +1639,27 @@
   // the files we were handed.
   struct ReadModuleNames : ASTReaderListener {
     CompilerInstance &CI;
-    llvm::SmallVector<IdentifierInfo*, 8> LoadedModules;
+    llvm::SmallVector<std::string, 8> LoadedModules;
 
     ReadModuleNames(CompilerInstance &CI) : CI(CI) {}
 
     void ReadModuleName(StringRef ModuleName) override {
-      LoadedModules.push_back(
-          CI.getPreprocessor().getIdentifierInfo(ModuleName));
+      LoadedModules.push_back(ModuleName.str());
     }
 
     void registerAll() {
       ModuleMap &MM = CI.getPreprocessor().getHeaderSearchInfo().getModuleMap();
-      for (auto *II : LoadedModules)
-        MM.cacheModuleLoad(*II, MM.findModule(II->getName()));
+      for (const std::string &LoadedModule : LoadedModules)
+        MM.cacheExplicitModuleLoad(LoadedModule, MM.findModule(LoadedModule));
       LoadedModules.clear();
     }
 
     void markAllUnavailable() {
-      for (auto *II : LoadedModules) {
+      for (const std::string &LoadedModule : LoadedModules) {
         if (Module *M = CI.getPreprocessor()
                             .getHeaderSearchInfo()
                             .getModuleMap()
-                            .findModule(II->getName())) {
+                            .findModule(LoadedModule)) {
           M->HasIncompatibleModuleFile = true;
 
           // Mark module as available if the only reason it was unavailable
Index: clang/include/clang/Lex/ModuleMap.h
===================================================================
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -105,6 +105,10 @@
   /// nullptr is stored for modules that are known to fail to load.
   llvm::DenseMap<const IdentifierInfo *, Module *> CachedModuleLoads;
 
+  /// Module loading cache indexed by module name. Used by explicit modules,
+  /// where IdentifierInfo is not available.
+  llvm::StringMap<Module *, llvm::BumpPtrAllocator> CachedExplicitModuleLoads;
+
   /// Shadow modules created while building this module map.
   llvm::SmallVector<Module*, 2> ShadowModules;
 
@@ -707,12 +711,22 @@
     CachedModuleLoads[&II] = M;
   }
 
+  /// Cache an explicit module load.
+  void cacheExplicitModuleLoad(StringRef ModuleName, Module *M) {
+    CachedExplicitModuleLoads[ModuleName] = M;
+  }
+
   /// Return a cached module load.
   llvm::Optional<Module *> getCachedModuleLoad(const IdentifierInfo &II) {
-    auto I = CachedModuleLoads.find(&II);
-    if (I == CachedModuleLoads.end())
-      return None;
-    return I->second;
+    auto It1 = CachedModuleLoads.find(&II);
+    if (It1 != CachedModuleLoads.end())
+      return It1->second;
+
+    auto It2 = CachedExplicitModuleLoads.find(II.getName());
+    if (It2 != CachedExplicitModuleLoads.end())
+      return CachedModuleLoads[&II] = It2->second;
+
+    return None;
   }
 };
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D111543: ... Jan Svoboda via Phabricator via cfe-commits

Reply via email to