r336528 - [Preamble] Check system dependencies in preamble too

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 02:07:01 PDT 2018

Author: ibiryukov
Date: Mon Jul  9 02:07:01 2018
New Revision: 336528

URL: http://llvm.org/viewvc/llvm-project?rev=336528&view=rev
[Preamble] Check system dependencies in preamble too

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


Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=336528&r1=336527&r2=336528&view=diff
--- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original)
+++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Mon Jul  9 02:07:01 2018
@@ -63,6 +63,16 @@ createVFSOverlayForPreamblePCH(StringRef
   return Overlay;
+class PreambleDependencyCollector : public DependencyCollector {
+  // 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 {
@@ -311,7 +321,7 @@ llvm::ErrorOr<PrecompiledPreamble> Preco
       new SourceManager(Diagnostics, Clang->getFileManager()));
-  auto PreambleDepCollector = std::make_shared<DependencyCollector>();
+  auto PreambleDepCollector = std::make_shared<PreambleDependencyCollector>();
   // Remap the main source file to the preamble buffer.

More information about the cfe-commits mailing list