jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, bnbarham.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since D135636 <https://reviews.llvm.org/D135636>, PCM files contain the "as 
requested" path of input files. The machinery for generating dependency files 
reports those paths as they appeared in the PCM file, which may confuse 
consumers that are not aware of VFS overlays that might've been in place at 
compile-time.

This patch makes sure the "use-external-name" setting is being respected when 
generating dependency files in modular builds by piping the paths serialized in 
PCMs through `FileEntryRef::getName()` before putting them into dependency 
files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141644

Files:
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Frontend/ModuleDependencyCollector.cpp
  clang/test/Modules/dependency-gen-vfs.c

Index: clang/test/Modules/dependency-gen-vfs.c
===================================================================
--- /dev/null
+++ clang/test/Modules/dependency-gen-vfs.c
@@ -0,0 +1,32 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- module.modulemap
+module M { header "m.h" }
+
+//--- m-real.h
+
+//--- overlay.json.template
+{
+  "version": 0,
+  "case-sensitive": "false",
+  "roots": [
+    {
+      "external-contents": "DIR/m-real.h",
+      "name": "DIR/m.h",
+      "type": "file"
+    }
+  ]
+}
+
+//--- tu.c
+#include "m.h"
+
+// RUN: sed -e "s|DIR|%/t|g" %t/overlay.json.template > %t/overlay.json
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \
+// RUN:   -ivfsoverlay %t/overlay.json -dependency-file %t/tu.d -MT %t/tu.o -fsyntax-only %t/tu.c
+// RUN: cat %t/tu.d | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t
+// CHECK:      [[PREFIX]]/tu.o: \
+// CHECK-NEXT: [[PREFIX]]/tu.c \
+// CHECK-NEXT: [[PREFIX]]/module.modulemap \
+// CHECK-NEXT: [[PREFIX]]/m-real.h
Index: clang/lib/Frontend/ModuleDependencyCollector.cpp
===================================================================
--- clang/lib/Frontend/ModuleDependencyCollector.cpp
+++ clang/lib/Frontend/ModuleDependencyCollector.cpp
@@ -26,13 +26,17 @@
 /// Private implementations for ModuleDependencyCollector
 class ModuleDependencyListener : public ASTReaderListener {
   ModuleDependencyCollector &Collector;
+  FileManager &FileMgr;
 public:
-  ModuleDependencyListener(ModuleDependencyCollector &Collector)
-      : Collector(Collector) {}
+  ModuleDependencyListener(ModuleDependencyCollector &Collector,
+                           FileManager &FileMgr)
+      : Collector(Collector), FileMgr(FileMgr) {}
   bool needsInputFileVisitation() override { return true; }
   bool needsSystemInputFileVisitation() override { return true; }
   bool visitInputFile(StringRef Filename, bool IsSystem, bool IsOverridden,
                       bool IsExplicitModule) override {
+    if (auto FE = FileMgr.getOptionalFileRef(Filename))
+      Filename = FE->getName();
     Collector.addFile(Filename);
     return true;
   }
@@ -99,7 +103,8 @@
 }
 
 void ModuleDependencyCollector::attachToASTReader(ASTReader &R) {
-  R.addListener(std::make_unique<ModuleDependencyListener>(*this));
+  R.addListener(
+      std::make_unique<ModuleDependencyListener>(*this, R.getFileManager()));
 }
 
 void ModuleDependencyCollector::attachToPreprocessor(Preprocessor &PP) {
Index: clang/lib/Frontend/DependencyFile.cpp
===================================================================
--- clang/lib/Frontend/DependencyFile.cpp
+++ clang/lib/Frontend/DependencyFile.cpp
@@ -108,7 +108,9 @@
 
 struct DepCollectorASTListener : public ASTReaderListener {
   DependencyCollector &DepCollector;
-  DepCollectorASTListener(DependencyCollector &L) : DepCollector(L) { }
+  FileManager &FileMgr;
+  DepCollectorASTListener(DependencyCollector &L, FileManager &FileMgr)
+      : DepCollector(L), FileMgr(FileMgr) {}
   bool needsInputFileVisitation() override { return true; }
   bool needsSystemInputFileVisitation() override {
     return DepCollector.needSystemDependencies();
@@ -124,6 +126,9 @@
     if (IsOverridden || IsExplicitModule)
       return true;
 
+    if (auto FE = FileMgr.getOptionalFileRef(Filename))
+      Filename = FE->getName();
+
     DepCollector.maybeAddDependency(Filename, /*FromModule*/true, IsSystem,
                                    /*IsModuleFile*/false, /*IsMissing*/false);
     return true;
@@ -176,7 +181,8 @@
       std::make_unique<DepCollectorMMCallbacks>(*this));
 }
 void DependencyCollector::attachToASTReader(ASTReader &R) {
-  R.addListener(std::make_unique<DepCollectorASTListener>(*this));
+  R.addListener(
+      std::make_unique<DepCollectorASTListener>(*this, R.getFileManager()));
 }
 
 DependencyFileGenerator::DependencyFileGenerator(
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to