r200979 - Stat system dependencies when using -verify-pch
Ben Langmuir
blangmuir at apple.com
Fri Feb 7 09:31:11 PST 2014
Author: benlangmuir
Date: Fri Feb 7 11:31:11 2014
New Revision: 200979
URL: http://llvm.org/viewvc/llvm-project?rev=200979&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/FrontendAction.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/PCH/verify_pch.m
Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=200979&r1=200978&r2=200979&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Fri Feb 7 11:31:11 2014
@@ -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);
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=200979&r1=200978&r2=200979&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Fri Feb 7 11:31:11 2014
@@ -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();
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=200979&r1=200978&r2=200979&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Fri Feb 7 11:31:11 2014
@@ -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::createPCHExternalASTSo
const std::string &Sysroot,
bool DisablePCHValidation,
bool AllowPCHWithCompilerErrors,
- bool AllowConfigurationMismatch,
Preprocessor &PP,
ASTContext &Context,
void *DeserializationListener,
@@ -324,7 +321,8 @@ CompilerInstance::createPCHExternalASTSo
Sysroot.empty() ? "" : Sysroot.c_str(),
DisablePCHValidation,
AllowPCHWithCompilerErrors,
- AllowConfigurationMismatch,
+ /*AllowConfigurationMismatch*/false,
+ /*ValidateSystemInputs*/false,
UseGlobalModuleIndex));
Reader->setDeserializationListener(
@@ -333,9 +331,7 @@ CompilerInstance::createPCHExternalASTSo
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(SourceLocat
PPOpts.DisablePCHValidation,
/*AllowASTWithCompilerErrors=*/false,
/*AllowConfigurationMismatch=*/false,
+ /*ValidateSystemInputs=*/false,
getFrontendOpts().UseGlobalModuleIndex);
if (hasASTConsumer()) {
ModuleManager->setDeserializationListener(
Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=200979&r1=200978&r2=200979&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Fri Feb 7 11:31:11 2014
@@ -314,7 +314,6 @@ bool FrontendAction::BeginSourceFile(Com
CI.getPreprocessorOpts().ImplicitPCHInclude,
CI.getPreprocessorOpts().DisablePCHValidation,
CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
- /*AllowConfigurationMismatch*/false,
DeserialListener);
if (!CI.getASTContext().getExternalSource())
goto failure;
Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=200979&r1=200978&r2=200979&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Fri Feb 7 11:31:11 2014
@@ -326,11 +326,22 @@ ASTConsumer *VerifyPCHAction::CreateASTC
}
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 {
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=200979&r1=200978&r2=200979&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Feb 7 11:31:11 2014
@@ -1831,9 +1831,13 @@ ASTReader::ReadControlBlock(ModuleFile &
// 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, A
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, A
isysroot(isysroot), DisableValidation(DisableValidation),
AllowASTWithCompilerErrors(AllowASTWithCompilerErrors),
AllowConfigurationMismatch(AllowConfigurationMismatch),
+ ValidateSystemInputs(ValidateSystemInputs),
UseGlobalIndex(UseGlobalIndex), TriedLoadingGlobalIndex(false),
CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts),
NumSLocEntriesRead(0), TotalNumSLocEntries(0),
Modified: cfe/trunk/test/PCH/verify_pch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/verify_pch.m?rev=200979&r1=200978&r2=200979&view=diff
==============================================================================
--- cfe/trunk/test/PCH/verify_pch.m (original)
+++ cfe/trunk/test/PCH/verify_pch.m Fri Feb 7 11:31:11 2014
@@ -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>
More information about the cfe-commits
mailing list