llvm-project/clang/lib/Frontend
Graydon Hoare ce539b54e3 [PCH] Attach instance's dependency collectors to PCH external AST sources.
Summary:
When a PCH is included via -include-pch, clang should treat the
current TU as dependent on the sourcefile that the PCH was generated from.

This is currently _partly_ accomplished by InitializePreprocessor calling
AddImplicitIncludePCH to synthesize an implicit #include of the sourcefile,
into the preprocessor's Predefines buffer.

For FrontendActions such as PreprocessOnlyAction (which is, curiously, what the
driver winds up running one of in response to a plain clang -M) this is
sufficient: the preprocessor cranks over its Predefines and emits a dependency
reference to the initial sourcefile.

For other FrontendActions (for example -emit-obj or -fsyntax-only) the
Predefines buffer is reset to the suggested predefines buffer from the PCH, so
the dependency edge is lost. The result is that clang emits a .d file in those
cases that lacks a reference to the .h file responsible for the input (and in
Swift's case, our .swiftdeps file winds up not including a reference to the
source file for a PCH bridging header.)

This patch fixes the problem by taking a different tack: ignoring the
Predefines buffer (which seems a bit like a hack anyways) and directly
attaching the CompilerInstance's DependencyCollectors (and legacy
DependencyFileGenerator) to the ASTReader for the external AST.

This approach is similar to the one chosen in earlier consultation with Bruno
and Ben, and I think it's the least-bad solution, given several options.

Reviewers: bruno, benlangmuir, doug.gregor

Reviewed By: bruno, doug.gregor

Subscribers: cfe-commits

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

llvm-svn: 299009
2017-03-29 17:33:09 +00:00
..
Rewrite Encapsulate FPOptions and use it consistently 2017-03-27 19:17:25 +00:00
ASTConsumers.cpp Add -cc1 flag -ast-dump-all to perform an AST dump including entities that haven't yet been deserialized. 2017-03-09 22:00:01 +00:00
ASTMerge.cpp [Frontend] Make the memory management of FrontendAction pointers explicit by using unique_ptr. 2016-02-07 19:28:36 +00:00
ASTUnit.cpp Add a function to MD5 a file's contents. 2017-03-20 23:33:18 +00:00
CMakeLists.txt clangFrontend: Make intrinsics_gen optional for standalone build. 2016-06-02 20:24:07 +00:00
CacheTokens.cpp Fix the build with MSVC 2013 after r283856 2016-10-11 17:24:09 +00:00
ChainedDiagnosticConsumer.cpp
ChainedIncludesSource.cpp Reapply "IntrusiveRefCntPtr -> std::shared_ptr for CompilerInvocationBase and CodeCompleteConsumer" 2017-01-06 19:49:01 +00:00
CodeGenOptions.cpp revert SVN r265702, r265640 2016-04-08 16:52:00 +00:00
CompilerInstance.cpp [PCH] Attach instance's dependency collectors to PCH external AST sources. 2017-03-29 17:33:09 +00:00
CompilerInvocation.cpp [OpenCL] Extended mapping of parcing CodeGen arguments 2017-03-27 10:38:01 +00:00
CreateInvocationFromCommandLine.cpp Reapply "IntrusiveRefCntPtr -> std::shared_ptr for CompilerInvocationBase and CodeCompleteConsumer" 2017-01-06 19:49:01 +00:00
DependencyFile.cpp Fix PR31644 introduced by r287138 and add a regression test. 2017-01-14 21:12:08 +00:00
DependencyGraph.cpp Revert r240270 ("Fixed/added namespace ending comments using clang-tidy"). 2015-06-22 23:07:51 +00:00
DiagnosticRenderer.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
FrontendAction.cpp Use filename in linemarker when compiling preprocessed source (Revised) 2017-03-07 20:20:23 +00:00
FrontendActions.cpp Add -cc1 flag -ast-dump-all to perform an AST dump including entities that haven't yet been deserialized. 2017-03-09 22:00:01 +00:00
FrontendOptions.cpp C++ Modules TS: add frontend support for building pcm files from module 2016-08-26 00:14:38 +00:00
HeaderIncludeGen.cpp [Frontend] StringRefize and fix bad indentation. 2016-05-27 12:52:19 +00:00
InitHeaderSearch.cpp [Frontend] Fix an issue where a quoted search path is incorrectly 2016-12-02 09:51:51 +00:00
InitPreprocessor.cpp Bump __cplusplus for C++17 to 201703L per the C++17 DIS. 2017-03-20 20:12:48 +00:00
LangStandards.cpp
LayoutOverrideSource.cpp Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith r259192 post commit comment. 2016-01-29 19:38:18 +00:00
LogDiagnosticPrinter.cpp Replace double negation of !FileID.isInvalid() with FileID.isValid(). 2015-10-03 10:46:20 +00:00
ModuleDependencyCollector.cpp [CrashReproducer] Add support for merging -ivfsoverlay 2016-12-22 07:06:03 +00:00
MultiplexConsumer.cpp PR29097: add an update record when we instantiate the default member 2016-08-24 21:25:37 +00:00
PCHContainerOperations.cpp Bitcode: Decouple block info block state from reader. 2016-11-08 04:17:11 +00:00
PrintPreprocessedOutput.cpp [Preprocessor] Support for '-dI' flag 2016-11-17 22:45:31 +00:00
SerializedDiagnosticPrinter.cpp Move SerializedDiagnosticPrinter's SharedState to std::shared_ptr rather than IntrusiveRefCntPtr 2017-01-05 19:48:10 +00:00
SerializedDiagnosticReader.cpp Bitcode: Decouple block info block state from reader. 2016-11-08 04:17:11 +00:00
TestModuleFileExtension.cpp Fix for LLVM Bitcode API change (to use std::shared_ptr) 2017-01-04 22:36:43 +00:00
TestModuleFileExtension.h Module file extensions: pass a Sema through to the extension writer. 2015-12-08 22:43:32 +00:00
TextDiagnostic.cpp Move UTF functions into namespace llvm. 2016-09-30 00:38:45 +00:00
TextDiagnosticBuffer.cpp Replace push_back(Constructor(foo)) with emplace_back(foo) for non-trivial types 2015-05-29 19:42:19 +00:00
TextDiagnosticPrinter.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
VerifyDiagnosticConsumer.cpp Instead of resetting the pointer, or releasing it which was the previous 2016-11-03 18:03:14 +00:00