From: Ben Langmuir Date: Fri, 7 Feb 2014 17:31:11 +0000 (+0000) Subject: Stat system dependencies when using -verify-pch X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=499512d6f275dcdee59d87921c5dbad542d2b97a;p=clang Stat system dependencies when using -verify-pch 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 --- diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 64de7a5b19..fa20ae48e4 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -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); diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 00ab7f0492..e4c2119e7f 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -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(); diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index d8381a824c..d121180125 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -292,14 +292,12 @@ void CompilerInstance::createASTContext() { void CompilerInstance::createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors, - bool AllowConfigurationMismatch, void *DeserializationListener){ OwningPtr 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( diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index 13a0787e42..0baf3e5e1f 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -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; diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 8b174605ff..27124ca848 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -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 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 { diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 4d2a400888..96d4044009 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -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), diff --git a/test/PCH/verify_pch.m b/test/PCH/verify_pch.m index 9870231d7c..9c7bab8f0b 100644 --- a/test/PCH/verify_pch.m +++ b/test/PCH/verify_pch.m @@ -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