]> granicus.if.org Git - clang/commitdiff
Stat system dependencies when using -verify-pch
authorBen Langmuir <blangmuir@apple.com>
Fri, 7 Feb 2014 17:31:11 +0000 (17:31 +0000)
committerBen Langmuir <blangmuir@apple.com>
Fri, 7 Feb 2014 17:31:11 +0000 (17:31 +0000)
We don't stat the system headers to check for stalenes during regular
PCH loading for performance reasons.  When explicitly saying
-verify-pch, we want to check all the dependencies - user or system.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200979 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/CompilerInstance.h
include/clang/Serialization/ASTReader.h
lib/Frontend/CompilerInstance.cpp
lib/Frontend/FrontendAction.cpp
lib/Frontend/FrontendActions.cpp
lib/Serialization/ASTReader.cpp
test/PCH/verify_pch.m

index 64de7a5b197170564f3fe7bd3a93188a1f4b0fec..fa20ae48e4f099fb282adcb7a700762428251642 100644 (file)
@@ -545,7 +545,6 @@ public:
   void createPCHExternalASTSource(StringRef Path,
                                   bool DisablePCHValidation,
                                   bool AllowPCHWithCompilerErrors,
-                                  bool AllowConfigurationMismatch,
                                   void *DeserializationListener);
 
   /// Create an external AST source to read a PCH file.
@@ -555,7 +554,6 @@ public:
   createPCHExternalASTSource(StringRef Path, const std::string &Sysroot,
                              bool DisablePCHValidation,
                              bool AllowPCHWithCompilerErrors,
-                             bool AllowConfigurationMismatch,
                              Preprocessor &PP, ASTContext &Context,
                              void *DeserializationListener, bool Preamble,
                              bool UseGlobalModuleIndex);
index 00ab7f04926359f007a98d5739b68231fa85e733..e4c2119e7f899510cb2e163ed58ec5ec330222e7 100644 (file)
@@ -737,6 +737,9 @@ private:
   /// from the current compiler instance.
   bool AllowConfigurationMismatch;
 
+  /// \brief Whether validate system input files.
+  bool ValidateSystemInputs;
+
   /// \brief Whether we are allowed to use the global module index.
   bool UseGlobalIndex;
 
@@ -1181,12 +1184,17 @@ public:
   /// \param AllowConfigurationMismatch If true, the AST reader will not check
   /// for configuration differences between the AST file and the invocation.
   ///
+  /// \param ValidateSystemInputs If true, the AST reader will validate
+  /// system input files in addition to user input files. This is only
+  /// meaningful if \p DisableValidation is false.
+  ///
   /// \param UseGlobalIndex If true, the AST reader will try to load and use
   /// the global module index.
   ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "",
             bool DisableValidation = false,
             bool AllowASTWithCompilerErrors = false,
             bool AllowConfigurationMismatch = false,
+            bool ValidateSystemInputs = false,
             bool UseGlobalIndex = true);
 
   ~ASTReader();
index d8381a824c7d11ace3352299db8bb3eaf6824912..d12118012539b84dea1a01c98fd200aa06ef9a52 100644 (file)
@@ -292,14 +292,12 @@ void CompilerInstance::createASTContext() {
 void CompilerInstance::createPCHExternalASTSource(StringRef Path,
                                                   bool DisablePCHValidation,
                                                 bool AllowPCHWithCompilerErrors,
-                                                bool AllowConfigurationMismatch,
                                                  void *DeserializationListener){
   OwningPtr<ExternalASTSource> Source;
   bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
   Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
                                           DisablePCHValidation,
                                           AllowPCHWithCompilerErrors,
-                                          AllowConfigurationMismatch,
                                           getPreprocessor(), getASTContext(),
                                           DeserializationListener,
                                           Preamble,
@@ -313,7 +311,6 @@ CompilerInstance::createPCHExternalASTSource(StringRef Path,
                                              const std::string &Sysroot,
                                              bool DisablePCHValidation,
                                              bool AllowPCHWithCompilerErrors,
-                                             bool AllowConfigurationMismatch,
                                              Preprocessor &PP,
                                              ASTContext &Context,
                                              void *DeserializationListener,
@@ -324,7 +321,8 @@ CompilerInstance::createPCHExternalASTSource(StringRef Path,
                              Sysroot.empty() ? "" : Sysroot.c_str(),
                              DisablePCHValidation,
                              AllowPCHWithCompilerErrors,
-                             AllowConfigurationMismatch,
+                             /*AllowConfigurationMismatch*/false,
+                             /*ValidateSystemInputs*/false,
                              UseGlobalModuleIndex));
 
   Reader->setDeserializationListener(
@@ -333,9 +331,7 @@ CompilerInstance::createPCHExternalASTSource(StringRef Path,
                           Preamble ? serialization::MK_Preamble
                                    : serialization::MK_PCH,
                           SourceLocation(),
-                          AllowConfigurationMismatch
-                            ? ASTReader::ARR_ConfigurationMismatch
-                            : ASTReader::ARR_None)) {
+                          ASTReader::ARR_None)) {
   case ASTReader::Success:
     // Set the predefines buffer as suggested by the PCH reader. Typically, the
     // predefines buffer will be empty.
@@ -1165,6 +1161,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
                                     PPOpts.DisablePCHValidation,
                                     /*AllowASTWithCompilerErrors=*/false,
                                     /*AllowConfigurationMismatch=*/false,
+                                    /*ValidateSystemInputs=*/false,
                                     getFrontendOpts().UseGlobalModuleIndex);
       if (hasASTConsumer()) {
         ModuleManager->setDeserializationListener(
index 13a0787e4270c547cc792075c3764afaead411e0..0baf3e5e1fb325e7d7518b0a9a11a7fa55c92d9c 100644 (file)
@@ -314,7 +314,6 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
                                 CI.getPreprocessorOpts().ImplicitPCHInclude,
                                 CI.getPreprocessorOpts().DisablePCHValidation,
                             CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
-                            /*AllowConfigurationMismatch*/false,
                                 DeserialListener);
       if (!CI.getASTContext().getExternalSource())
         goto failure;
index 8b174605ffd88b1512f335e63260ea4013a85fc7..27124ca84876bfe48c49c10f591f226d52edda39 100644 (file)
@@ -326,11 +326,22 @@ ASTConsumer *VerifyPCHAction::CreateASTConsumer(CompilerInstance &CI,
 }
 
 void VerifyPCHAction::ExecuteAction() {
-  getCompilerInstance().
-    createPCHExternalASTSource(getCurrentFile(), /*DisablePCHValidation*/false,
-                               /*AllowPCHWithCompilerErrors*/false,
-                               /*AllowConfigurationMismatch*/true,
-                               /*DeserializationListener*/0);
+  CompilerInstance &CI = getCompilerInstance();
+  bool Preamble = CI.getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
+  const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot;
+  OwningPtr<ASTReader> Reader(new ASTReader(
+    CI.getPreprocessor(), CI.getASTContext(),
+    Sysroot.empty() ? "" : Sysroot.c_str(),
+    /*DisableValidation*/false,
+    /*AllowPCHWithCompilerErrors*/false,
+    /*AllowConfigurationMismatch*/true,
+    /*ValidateSystemInputs*/true));
+
+  Reader->ReadAST(getCurrentFile(),
+                  Preamble ? serialization::MK_Preamble
+                           : serialization::MK_PCH,
+                  SourceLocation(),
+                  ASTReader::ARR_ConfigurationMismatch);
 }
 
 namespace {
index 4d2a400888809e3194fe9d338390b7e50cfae11b..96d404400969b66d25f0f9e61116c470ebdcfc07 100644 (file)
@@ -1831,9 +1831,13 @@ ASTReader::ReadControlBlock(ModuleFile &F,
       // Validate all of the non-system input files.
       if (!DisableValidation) {
         bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0;
-        // All user input files reside at the index range [0, Record[1]).
+        // All user input files reside at the index range [0, Record[1]), and
+        // system input files reside at [Record[1], Record[0]).
         // Record is the one from INPUT_FILE_OFFSETS.
-        for (unsigned I = 0, N = Record[1]; I < N; ++I) {
+        unsigned NumInputs = Record[0];
+        unsigned NumUserInputs = Record[1];
+        unsigned N = ValidateSystemInputs ? NumInputs : NumUserInputs;
+        for (unsigned I = 0; I < N; ++I) {
           InputFile IF = getInputFile(F, I+1, Complain);
           if (!IF.getFile() || IF.isOutOfDate())
             return OutOfDate;
@@ -7620,6 +7624,7 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context,
                      StringRef isysroot, bool DisableValidation,
                      bool AllowASTWithCompilerErrors,
                      bool AllowConfigurationMismatch,
+                     bool ValidateSystemInputs,
                      bool UseGlobalIndex)
   : Listener(new PCHValidator(PP, *this)), DeserializationListener(0),
     SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()),
@@ -7628,6 +7633,7 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context,
     isysroot(isysroot), DisableValidation(DisableValidation),
     AllowASTWithCompilerErrors(AllowASTWithCompilerErrors),
     AllowConfigurationMismatch(AllowConfigurationMismatch),
+    ValidateSystemInputs(ValidateSystemInputs),
     UseGlobalIndex(UseGlobalIndex), TriedLoadingGlobalIndex(false),
     CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts),
     NumSLocEntriesRead(0), TotalNumSLocEntries(0), 
index 9870231d7c8c895c8af74ac544b19fec8924618a..9c7bab8f0b368a030f73c87c0bbedb72e23d1335 100644 (file)
@@ -1,15 +1,30 @@
-// Precompile
+// Setup:
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/usr/include
+// RUN: echo '// empty' > %t/usr/include/sys_header.h
 // RUN: cp %s %t.h
-// RUN: %clang_cc1 -x objective-c-header -emit-pch -o %t.pch %t.h
+//
+// Precompile
+// RUN: %clang_cc1 -isysroot %t -x objective-c-header -emit-pch -o %t.pch %t.h
 
 // Verify successfully
-// RUN: %clang_cc1 -x objective-c -verify-pch %t.pch
+// RUN: %clang_cc1 -isysroot %t -verify-pch %t.pch
 
 // Incompatible lang options ignored
-// RUN: %clang_cc1 -x objective-c -fno-builtin -verify-pch %t.pch
+// RUN: %clang_cc1 -isysroot %t -x objective-c -fno-builtin -verify-pch %t.pch
 
 // Stale dependency
 // RUN: echo ' ' >> %t.h
-// RUN: not %clang_cc1 -x objective-c -verify-pch %t.pch 2> %t.log.2
+// RUN: not %clang_cc1 -isysroot %t -verify-pch %t.pch 2> %t.log.2
 // RUN: FileCheck -check-prefix=CHECK-STALE-DEP %s < %t.log.2
 // CHECK-STALE-DEP: file '{{.*}}.h' has been modified since the precompiled header '{{.*}}.pch' was built
+
+// Stale dependency in system header
+// RUN: %clang_cc1 -isysroot %t -x objective-c-header -emit-pch -o %t.pch %t.h
+// RUN: %clang_cc1 -isysroot %t -verify-pch %t.pch
+// RUN: echo ' ' >> %t/usr/include/sys_header.h
+// RUN: not %clang_cc1 -isysroot %t -verify-pch %t.pch 2> %t.log.3
+// RUN: FileCheck -check-prefix=CHECK-STALE-SYS-H %s < %t.log.3
+// CHECK-STALE-SYS-H: file '{{.*}}/usr/include/sys_header.h' has been modified since the precompiled header '{{.*}}.pch' was built
+
+#include <sys_header.h>