Skip to content

Commit e5801b0

Browse files
committedJul 9, 2018
[Preamble] Check system dependencies in preamble too
Summary: PrecompiledPreamble hasn't checked if the system dependencies changed before. This resulted in invalid preamble not being rebuilt if headers that changed were found in -isystem include paths. This pattern is sometimes used to avoid showing warnings in third party code, so we want to correctly handle those cases. Tested in clangd, see the follow-up patch. Reviewers: sammccall, ioeric Reviewed By: sammccall Subscribers: omtcyfz, cfe-commits Differential Revision: https://reviews.llvm.org/D48946 llvm-svn: 336528
1 parent 078c879 commit e5801b0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed
 

‎clang/lib/Frontend/PrecompiledPreamble.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ createVFSOverlayForPreamblePCH(StringRef PCHFilename,
6363
return Overlay;
6464
}
6565

66+
class PreambleDependencyCollector : public DependencyCollector {
67+
public:
68+
// We want to collect all dependencies for correctness. Avoiding the real
69+
// system dependencies (e.g. stl from /usr/lib) would probably be a good idea,
70+
// but there is no way to distinguish between those and the ones that can be
71+
// spuriously added by '-isystem' (e.g. to suppress warnings from those
72+
// headers).
73+
bool needSystemDependencies() override { return true; }
74+
};
75+
6676
/// Keeps a track of files to be deleted in destructor.
6777
class TemporaryFiles {
6878
public:
@@ -311,7 +321,7 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
311321
Clang->setSourceManager(
312322
new SourceManager(Diagnostics, Clang->getFileManager()));
313323

314-
auto PreambleDepCollector = std::make_shared<DependencyCollector>();
324+
auto PreambleDepCollector = std::make_shared<PreambleDependencyCollector>();
315325
Clang->addDependencyCollector(PreambleDepCollector);
316326

317327
// Remap the main source file to the preamble buffer.

0 commit comments

Comments
 (0)
Please sign in to comment.