void createPCHExternalASTSource(StringRef Path,
bool DisablePCHValidation,
bool AllowPCHWithCompilerErrors,
- bool AllowConfigurationMismatch,
void *DeserializationListener);
/// Create an external AST source to read a PCH file.
createPCHExternalASTSource(StringRef Path, const std::string &Sysroot,
bool DisablePCHValidation,
bool AllowPCHWithCompilerErrors,
- bool AllowConfigurationMismatch,
Preprocessor &PP, ASTContext &Context,
void *DeserializationListener, bool Preamble,
bool UseGlobalModuleIndex);
/// 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;
/// \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();
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,
const std::string &Sysroot,
bool DisablePCHValidation,
bool AllowPCHWithCompilerErrors,
- bool AllowConfigurationMismatch,
Preprocessor &PP,
ASTContext &Context,
void *DeserializationListener,
Sysroot.empty() ? "" : Sysroot.c_str(),
DisablePCHValidation,
AllowPCHWithCompilerErrors,
- AllowConfigurationMismatch,
+ /*AllowConfigurationMismatch*/false,
+ /*ValidateSystemInputs*/false,
UseGlobalModuleIndex));
Reader->setDeserializationListener(
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.
PPOpts.DisablePCHValidation,
/*AllowASTWithCompilerErrors=*/false,
/*AllowConfigurationMismatch=*/false,
+ /*ValidateSystemInputs=*/false,
getFrontendOpts().UseGlobalModuleIndex);
if (hasASTConsumer()) {
ModuleManager->setDeserializationListener(
CI.getPreprocessorOpts().ImplicitPCHInclude,
CI.getPreprocessorOpts().DisablePCHValidation,
CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
- /*AllowConfigurationMismatch*/false,
DeserialListener);
if (!CI.getASTContext().getExternalSource())
goto failure;
}
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 {
// 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;
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()),
isysroot(isysroot), DisableValidation(DisableValidation),
AllowASTWithCompilerErrors(AllowASTWithCompilerErrors),
AllowConfigurationMismatch(AllowConfigurationMismatch),
+ ValidateSystemInputs(ValidateSystemInputs),
UseGlobalIndex(UseGlobalIndex), TriedLoadingGlobalIndex(false),
CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts),
NumSLocEntriesRead(0), TotalNumSLocEntries(0),
-// 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>