Introduce FileEntryRef and use it when handling includes to report correct dependencies
authorAlex Lorenz <arphaman@gmail.com>
Thu, 22 Aug 2019 18:15:50 +0000 (18:15 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Thu, 22 Aug 2019 18:15:50 +0000 (18:15 +0000)
commit4dc5573acc0d2e7c59d8bac2543eb25cb4b32984
tree79d7d47df40888fc8802d0f98f1dee747a10ff25
parent15ee5ba6e75759f5ca3d58f941fb6f8023741491
Introduce FileEntryRef and use it when handling includes to report correct dependencies
when the FileManager is reused across invocations

This commit introduces a parallel API to FileManager's getFile: getFileEntryRef, which returns
a reference to the FileEntry, and the name that was used to access the file. In the case of
a VFS with 'use-external-names', the FileEntyRef contains the external name of the file,
not the filename that was used to access it.

The new API is adopted only in the HeaderSearch and Preprocessor for include file lookup, so that the
accessed path can be propagated to SourceManager's FileInfo. SourceManager's FileInfo now can report this accessed path, using
the new getName method. This API is then adopted in the dependency collector, which now correctly reports dependencies when a file
is included both using a symlink and a real path in the case when the FileManager is reused across multiple Preprocessor invocations.

Note that this patch does not fix all dependency collector issues, as the same problem is still present in other cases when dependencies
are obtained using FileSkipped, InclusionDirective, and HasInclude. This will be fixed in follow-up commits.

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

llvm-svn: 369680
24 files changed:
clang/include/clang/Basic/FileManager.h
clang/include/clang/Basic/SourceManager.h
clang/include/clang/Lex/DirectoryLookup.h
clang/include/clang/Lex/HeaderMap.h
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/Preprocessor.h
clang/lib/Basic/FileManager.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/DependencyFile.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
clang/lib/Lex/HeaderMap.cpp
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Lex/Pragma.cpp
clang/lib/Lex/Preprocessor.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/VFS/external-names.c
clang/unittests/Tooling/CMakeLists.txt
clang/unittests/Tooling/DependencyScannerTest.cpp [new file with mode: 0644]