diff options
author | Graydon Hoare <ghoare@apple.com> | 2017-03-29 17:33:09 +0000 |
---|---|---|
committer | Graydon Hoare <ghoare@apple.com> | 2017-03-29 17:33:09 +0000 |
commit | f2760ac904beaab3c5d05b5c1af7e9a3bc50f1f4 (patch) | |
tree | 2bd2a6975af6efce9c2c4674637aa1210f0c14db /test/PCH | |
parent | b18f3efe980fabecca8feac4bd1512e4e9c33d57 (diff) | |
download | clang-f2760ac904beaab3c5d05b5c1af7e9a3bc50f1f4.tar.gz |
[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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299009 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/PCH')
-rw-r--r-- | test/PCH/emit-dependencies.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/PCH/emit-dependencies.c b/test/PCH/emit-dependencies.c new file mode 100644 index 0000000000..c719b9ebdd --- /dev/null +++ b/test/PCH/emit-dependencies.c @@ -0,0 +1,9 @@ +// RUN: rm -f %t.pch +// RUN: %clang_cc1 -emit-pch -o %t.pch %S/Inputs/chain-decls1.h +// RUN: %clang_cc1 -include-pch %t.pch -fsyntax-only -MT %s.o -dependency-file - %s | FileCheck %s +// CHECK: Inputs/chain-decls1.h + +int main() { + f(); + return 0; +} |