diff options
-rw-r--r-- | clang/lib/Frontend/ModuleDependencyCollector.cpp | 20 | ||||
-rw-r--r-- | clang/test/Modules/crash-vfs-headermaps.m | 7 |
2 files changed, 27 insertions, 0 deletions
diff --git a/clang/lib/Frontend/ModuleDependencyCollector.cpp b/clang/lib/Frontend/ModuleDependencyCollector.cpp index cc655f6eb00..578910a7771 100644 --- a/clang/lib/Frontend/ModuleDependencyCollector.cpp +++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp @@ -38,6 +38,24 @@ public: } }; +struct ModuleDependencyPPCallbacks : public PPCallbacks { + ModuleDependencyCollector &Collector; + SourceManager &SM; + ModuleDependencyPPCallbacks(ModuleDependencyCollector &Collector, + SourceManager &SM) + : Collector(Collector), SM(SM) {} + + void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, + StringRef FileName, bool IsAngled, + CharSourceRange FilenameRange, const FileEntry *File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported) override { + if (!File) + return; + Collector.addFile(File->getName()); + } +}; + struct ModuleDependencyMMCallbacks : public ModuleMapCallbacks { ModuleDependencyCollector &Collector; ModuleDependencyMMCallbacks(ModuleDependencyCollector &Collector) @@ -102,6 +120,8 @@ void ModuleDependencyCollector::attachToASTReader(ASTReader &R) { } void ModuleDependencyCollector::attachToPreprocessor(Preprocessor &PP) { + PP.addPPCallbacks(llvm::make_unique<ModuleDependencyPPCallbacks>( + *this, PP.getSourceManager())); PP.getHeaderSearchInfo().getModuleMap().addModuleMapCallbacks( llvm::make_unique<ModuleDependencyMMCallbacks>(*this)); } diff --git a/clang/test/Modules/crash-vfs-headermaps.m b/clang/test/Modules/crash-vfs-headermaps.m index 208d9678b1e..4f88f3ba119 100644 --- a/clang/test/Modules/crash-vfs-headermaps.m +++ b/clang/test/Modules/crash-vfs-headermaps.m @@ -40,6 +40,13 @@ // CHECKYAML-NEXT: 'overlay-relative': 'true', // CHECKYAML-NEXT: 'ignore-non-existent-contents': 'false' // CHECKYAML: 'type': 'directory' +// CHECKYAML: 'name': "/[[PATH:.*]]/Foo.framework/Headers", +// CHECKYAML-NEXT: 'contents': [ +// CHECKYAML-NEXT: { +// CHECKYAML-NEXT: 'type': 'file', +// CHECKYAML-NEXT: 'name': "Foo.h", +// CHECKYAML-NEXT: 'external-contents': "/[[PATH]]/Foo.framework/Headers/Foo.h" +// CHECKYAML: 'type': 'directory' // CHECKYAML: 'name': "/[[PATH:.*]]/i", // CHECKYAML-NEXT: 'contents': [ // CHECKYAML-NEXT: { |