From: Ilya Biryukov Date: Mon, 9 Jul 2018 09:07:01 +0000 (+0000) Subject: [Preamble] Check system dependencies in preamble too X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d46ee151e6630cd8d1866f4f1619a0e10e7c1637;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336528 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/PrecompiledPreamble.cpp b/lib/Frontend/PrecompiledPreamble.cpp index 23371d1f42..30ae2db26d 100644 --- a/lib/Frontend/PrecompiledPreamble.cpp +++ b/lib/Frontend/PrecompiledPreamble.cpp @@ -63,6 +63,16 @@ createVFSOverlayForPreamblePCH(StringRef PCHFilename, return Overlay; } +class PreambleDependencyCollector : public DependencyCollector { +public: + // We want to collect all dependencies for correctness. Avoiding the real + // system dependencies (e.g. stl from /usr/lib) would probably be a good idea, + // but there is no way to distinguish between those and the ones that can be + // spuriously added by '-isystem' (e.g. to suppress warnings from those + // headers). + bool needSystemDependencies() override { return true; } +}; + /// Keeps a track of files to be deleted in destructor. class TemporaryFiles { public: @@ -311,7 +321,7 @@ llvm::ErrorOr PrecompiledPreamble::Build( Clang->setSourceManager( new SourceManager(Diagnostics, Clang->getFileManager())); - auto PreambleDepCollector = std::make_shared(); + auto PreambleDepCollector = std::make_shared(); Clang->addDependencyCollector(PreambleDepCollector); // Remap the main source file to the preamble buffer.