Skip to content

Commit

Permalink
Merge pull request #6005 from apple/jan_svoboda/stable-20221013-vfs-d…
Browse files Browse the repository at this point in the history
…ep-cherry-pick

[clang] Report the on-disk paths for inputs to module compiles
  • Loading branch information
jansvoboda11 authored Jan 17, 2023
2 parents 74beffe + 2216ee8 commit 727d88c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
12 changes: 10 additions & 2 deletions clang/lib/Frontend/DependencyFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ struct DFGMMCallback : public ModuleMapCallbacks {

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();
Expand All @@ -156,6 +158,11 @@ struct DepCollectorASTListener : public ASTReaderListener {
if (IsOverridden || IsExplicitModule)
return true;

// Run this through the FileManager in order to respect 'use-external-name'
// in case we have a VFS overlay.
if (auto FE = FileMgr.getOptionalFileRef(Filename))
Filename = FE->getName();

DepCollector.maybeAddDependency(Filename, /*FromModule*/true, IsSystem,
/*IsModuleFile*/false, /*IsMissing*/false);
return true;
Expand Down Expand Up @@ -211,7 +218,8 @@ void DependencyCollector::attachToPreprocessor(Preprocessor &PP) {
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(
Expand Down
13 changes: 10 additions & 3 deletions clang/lib/Frontend/ModuleDependencyCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ namespace {
/// 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 {
// Run this through the FileManager in order to respect 'use-external-name'
// in case we have a VFS overlay.
if (auto FE = FileMgr.getOptionalFileRef(Filename))
Filename = FE->getName();
Collector.addFile(Filename);
return true;
}
Expand Down Expand Up @@ -99,7 +105,8 @@ struct ModuleDependencyMMCallbacks : public ModuleMapCallbacks {
}

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) {
Expand Down
32 changes: 32 additions & 0 deletions clang/test/Modules/dependency-gen-vfs.c
Original file line number Diff line number Diff line change
@@ -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: FileCheck %s --input-file=%t/tu.d
// CHECK: {{.*}}tu.o: \
// CHECK-NEXT: {{.*}}tu.c \
// CHECK-NEXT: {{.*}}module.modulemap \
// CHECK-NEXT: {{.*}}m-real.h

0 comments on commit 727d88c

Please sign in to comment.