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.

llvm-svn: 200979
This commit is contained in:
Ben Langmuir
2014-02-07 17:31:11 +00:00
parent 4c80bdae72
commit 3d4417c7fd
7 changed files with 56 additions and 22 deletions

View 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);

View 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();

View 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(

View 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;

View 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 {

View 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),

View 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>