This is an archive of the discontinued LLVM Phabricator instance.

[PCH] Attach instance's dependency collectors to PCH external AST sources.
ClosedPublic

Authored by graydon on Mar 26 2017, 4:31 PM.

Details

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.

Diff Detail

Repository
rL LLVM

Event Timeline

graydon created this revision.Mar 26 2017, 4:31 PM
This revision is now accepted and ready to land.Mar 29 2017, 9:50 AM
bruno accepted this revision.Mar 29 2017, 10:06 AM

Thanks for working on this! LGTM too

This revision was automatically updated to reflect the committed changes.