[clang] NFCI: Use `FileEntryRef` in `ModuleMapCallbacks`
authorJan Svoboda <jan_svoboda@apple.com>
Wed, 31 May 2023 17:35:59 +0000 (10:35 -0700)
committerJan Svoboda <jan_svoboda@apple.com>
Thu, 1 Jun 2023 17:10:00 +0000 (10:10 -0700)
This patch removes path hackery from `ModuleMapCallbacks` by adopting `FileEntryRef`. No functional change intended.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D151852

clang/include/clang/Lex/ModuleMap.h
clang/lib/Frontend/ModuleDependencyCollector.cpp
clang/lib/Lex/ModuleMap.cpp

index e28147c..6f584ca 100644 (file)
@@ -67,10 +67,8 @@ public:
 
   /// Called when an umbrella header is added during module map parsing.
   ///
-  /// \param FileMgr FileManager instance
   /// \param Header The umbrella header to collect.
-  virtual void moduleMapAddUmbrellaHeader(FileManager *FileMgr,
-                                          const FileEntry *Header) {}
+  virtual void moduleMapAddUmbrellaHeader(FileEntryRef Header) {}
 };
 
 class ModuleMap {
index b4b312b..939e611 100644 (file)
@@ -72,37 +72,12 @@ struct ModuleDependencyMMCallbacks : public ModuleMapCallbacks {
     if (llvm::sys::path::is_absolute(HeaderPath))
       Collector.addFile(HeaderPath);
   }
-  void moduleMapAddUmbrellaHeader(FileManager *FileMgr,
-                                  const FileEntry *Header) override {
-    StringRef HeaderFilename = Header->getName();
-    moduleMapAddHeader(HeaderFilename);
-    // The FileManager can find and cache the symbolic link for a framework
-    // header before its real path, this means a module can have some of its
-    // headers to use other paths. Although this is usually not a problem, it's
-    // inconsistent, and not collecting the original path header leads to
-    // umbrella clashes while rebuilding modules in the crash reproducer. For
-    // example:
-    //    ApplicationServices.framework/Frameworks/ImageIO.framework/ImageIO.h
-    // instead of:
-    //    ImageIO.framework/ImageIO.h
-    //
-    // FIXME: this shouldn't be necessary once we have FileName instances
-    // around instead of FileEntry ones. For now, make sure we collect all
-    // that we need for the reproducer to work correctly.
-    StringRef UmbreallDirFromHeader =
-        llvm::sys::path::parent_path(HeaderFilename);
-    StringRef UmbrellaDir = Header->getDir()->getName();
-    if (!UmbrellaDir.equals(UmbreallDirFromHeader)) {
-      SmallString<128> AltHeaderFilename;
-      llvm::sys::path::append(AltHeaderFilename, UmbrellaDir,
-                              llvm::sys::path::filename(HeaderFilename));
-      if (FileMgr->getFile(AltHeaderFilename))
-        moduleMapAddHeader(AltHeaderFilename);
-    }
+  void moduleMapAddUmbrellaHeader(FileEntryRef Header) override {
+    moduleMapAddHeader(Header.getNameAsRequested());
   }
 };
 
-}
+} // namespace
 
 void ModuleDependencyCollector::attachToASTReader(ASTReader &R) {
   R.addListener(
index bfd4890..93f770f 100644 (file)
@@ -1180,7 +1180,7 @@ void ModuleMap::setUmbrellaHeaderAsWritten(
 
   // Notify callbacks that we just added a new header.
   for (const auto &Cb : Callbacks)
-    Cb->moduleMapAddUmbrellaHeader(&SourceMgr.getFileManager(), UmbrellaHeader);
+    Cb->moduleMapAddUmbrellaHeader(UmbrellaHeader);
 }
 
 void ModuleMap::setUmbrellaDirAsWritten(