diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-07-27 00:27:13 +0000 | 
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-07-27 00:27:13 +0000 | 
| commit | ce3a8293a0473078fa29178a00f2dc7945438572 (patch) | |
| tree | 9210962cc780ebdb66a91e7ba93654bb8f5e2c48 /clang/lib | |
| parent | 66c5eef182dc5adab30d50a2e73de3b31109d305 (diff) | |
| download | bcm5719-llvm-ce3a8293a0473078fa29178a00f2dc7945438572.tar.gz bcm5719-llvm-ce3a8293a0473078fa29178a00f2dc7945438572.zip  | |
Implement -fno-validate-pch at the -cc1 level, which suppresses most
of the usual consistency checks used to determine when a precompiled
header is incompatible with the translation unit it's being loaded
into.
Enable this option when loading a precompiled preamble, because the
preamble loader will be performing all of this checking itself. Enable
the preamble-based test now that it's working.
This option is also useful for debugging Clang's PCH
(<rdar://problem/7532213>).
llvm-svn: 109475
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 9 | ||||
| -rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/Frontend/PCHReader.cpp | 28 | 
5 files changed, 33 insertions, 18 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 7ff3cdc5b9a..0463db18dc0 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -394,6 +394,7 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {      PreprocessorOpts.PrecompiledPreambleBytes.second                                                      = PreambleEndsAtStartOfLine;      PreprocessorOpts.ImplicitPCHInclude = PreambleFile.str(); +    PreprocessorOpts.DisablePCHValidation = true;    }    llvm::OwningPtr<TopLevelDeclTrackerAction> Act; @@ -415,9 +416,11 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {    Act->EndSourceFile();    // Remove the overridden buffer we used for the preamble. -  if (OverrideMainBuffer) +  if (OverrideMainBuffer) {      PreprocessorOpts.eraseRemappedFile(                                 PreprocessorOpts.remapped_file_buffer_end() - 1); +    PreprocessorOpts.DisablePCHValidation = true; +  }    Clang.takeDiagnosticClient(); @@ -426,9 +429,11 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {  error:    // Remove the overridden buffer we used for the preamble. -  if (OverrideMainBuffer) +  if (OverrideMainBuffer) {      PreprocessorOpts.eraseRemappedFile(                                 PreprocessorOpts.remapped_file_buffer_end() - 1); +    PreprocessorOpts.DisablePCHValidation = true; +  }    Clang.takeSourceManager();    Clang.takeFileManager(); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 0b1041f8412..ea295687aa0 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -250,9 +250,11 @@ void CompilerInstance::createASTContext() {  // ExternalASTSource -void CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path) { +void CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path, +                                                  bool DisablePCHValidation) {    llvm::OwningPtr<ExternalASTSource> Source;    Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot, +                                          DisablePCHValidation,                                            getPreprocessor(), getASTContext()));    // Remember the PCHReader, but in a non-owning way.    Reader = static_cast<PCHReader*>(Source.get()); @@ -262,11 +264,13 @@ void CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path) {  ExternalASTSource *  CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path,                                               const std::string &Sysroot, +                                             bool DisablePCHValidation,                                               Preprocessor &PP,                                               ASTContext &Context) {    llvm::OwningPtr<PCHReader> Reader;    Reader.reset(new PCHReader(PP, &Context, -                             Sysroot.empty() ? 0 : Sysroot.c_str())); +                             Sysroot.empty() ? 0 : Sysroot.c_str(), +                             DisablePCHValidation));    switch (Reader->ReadPCH(Path)) {    case PCHReader::Success: diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 68703c22fb4..0ae4739b410 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1353,7 +1353,8 @@ static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,      Opts.TokenCache = Opts.ImplicitPTHInclude;    Opts.UsePredefines = !Args.hasArg(OPT_undef);    Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record); -   +  Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch); +    if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) {      llvm::StringRef Value(A->getValue(Args));      size_t Comma = Value.find(','); diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index dbbf69c8b12..9efa8c61db8 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -118,7 +118,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,      if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {        assert(hasPCHSupport() && "This action does not have PCH support!");        CI.createPCHExternalASTSource( -        CI.getPreprocessorOpts().ImplicitPCHInclude); +                                CI.getPreprocessorOpts().ImplicitPCHInclude, +                                CI.getPreprocessorOpts().DisablePCHValidation);        if (!CI.getASTContext().getExternalSource())          goto failure;      } diff --git a/clang/lib/Frontend/PCHReader.cpp b/clang/lib/Frontend/PCHReader.cpp index f454477c50a..37e11249f88 100644 --- a/clang/lib/Frontend/PCHReader.cpp +++ b/clang/lib/Frontend/PCHReader.cpp @@ -414,13 +414,14 @@ void PCHValidator::ReadCounter(unsigned Value) {  //===----------------------------------------------------------------------===//  PCHReader::PCHReader(Preprocessor &PP, ASTContext *Context, -                     const char *isysroot) +                     const char *isysroot, bool DisableValidation)    : Listener(new PCHValidator(PP, *this)), DeserializationListener(0),      SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()),      Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context),      Consumer(0), MethodPoolLookupTable(0), MethodPoolLookupTableData(0),      TotalSelectorsInMethodPool(0), SelectorOffsets(0), -    TotalNumSelectors(0),  isysroot(isysroot), NumStatHits(0), NumStatMisses(0), +    TotalNumSelectors(0),  isysroot(isysroot),  +    DisableValidation(DisableValidation), NumStatHits(0), NumStatMisses(0),      NumSLocEntriesRead(0), TotalNumSLocEntries(0), NumStatementsRead(0),      TotalNumStatements(0), NumMacrosRead(0), NumMethodPoolSelectorsRead(0),      NumMethodPoolMisses(0), TotalNumMacros(0), NumLexicalDeclContextsRead(0), @@ -430,12 +431,14 @@ PCHReader::PCHReader(Preprocessor &PP, ASTContext *Context,  }  PCHReader::PCHReader(SourceManager &SourceMgr, FileManager &FileMgr, -                     Diagnostic &Diags, const char *isysroot) +                     Diagnostic &Diags, const char *isysroot, +                     bool DisableValidation)    : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr),      Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0),      MethodPoolLookupTable(0), MethodPoolLookupTableData(0),      TotalSelectorsInMethodPool(0), SelectorOffsets(0), -    TotalNumSelectors(0), isysroot(isysroot), NumStatHits(0), NumStatMisses(0), +    TotalNumSelectors(0), isysroot(isysroot),  +    DisableValidation(DisableValidation), NumStatHits(0), NumStatMisses(0),      NumSLocEntriesRead(0), TotalNumSLocEntries(0), NumStatementsRead(0),      TotalNumStatements(0), NumMacrosRead(0), NumMethodPoolSelectorsRead(0),      NumMethodPoolMisses(0), TotalNumMacros(0), NumLexicalDeclContextsRead(0), @@ -1019,14 +1022,15 @@ PCHReader::PCHReadResult PCHReader::ReadSLocEntryRecord(unsigned ID) {        return Failure;      } -    if ((off_t)Record[4] != File->getSize() +    if (!DisableValidation && +        ((off_t)Record[4] != File->getSize()  #if !defined(LLVM_ON_WIN32)          // In our regression testing, the Windows file system seems to          // have inconsistent modification times that sometimes          // erroneously trigger this error-handling path. -        || (time_t)Record[5] != File->getModificationTime() +         || (time_t)Record[5] != File->getModificationTime()  #endif -        ) { +        )) {        Diag(diag::err_fe_pch_file_modified)          << Filename;        return Failure; @@ -1481,7 +1485,7 @@ PCHReader::ReadPCHBlock(PerFileData &F) {        break;      case pch::METADATA: { -      if (Record[0] != pch::VERSION_MAJOR) { +      if (Record[0] != pch::VERSION_MAJOR && !DisableValidation) {          Diag(Record[0] < pch::VERSION_MAJOR? diag::warn_pch_version_too_old                                             : diag::warn_pch_version_too_new);          return IgnorePCH; @@ -1501,7 +1505,7 @@ PCHReader::ReadPCHBlock(PerFileData &F) {          Error("CHAINED_METADATA is not first record in block");          return Failure;        } -      if (Record[0] != pch::VERSION_MAJOR) { +      if (Record[0] != pch::VERSION_MAJOR && !DisableValidation) {          Diag(Record[0] < pch::VERSION_MAJOR? diag::warn_pch_version_too_old                                             : diag::warn_pch_version_too_new);          return IgnorePCH; @@ -1536,7 +1540,7 @@ PCHReader::ReadPCHBlock(PerFileData &F) {        break;      case pch::LANGUAGE_OPTIONS: -      if (ParseLanguageOptions(Record)) +      if (ParseLanguageOptions(Record) && !DisableValidation)          return IgnorePCH;        break; @@ -1704,7 +1708,7 @@ PCHReader::ReadPCHBlock(PerFileData &F) {      case pch::VERSION_CONTROL_BRANCH_REVISION: {        const std::string &CurBranch = getClangFullRepositoryVersion();        llvm::StringRef PCHBranch(BlobStart, BlobLen); -      if (llvm::StringRef(CurBranch) != PCHBranch) { +      if (llvm::StringRef(CurBranch) != PCHBranch && !DisableValidation) {          Diag(diag::warn_pch_different_branch) << PCHBranch << CurBranch;          return IgnorePCH;        } @@ -1759,7 +1763,7 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {    }    // Check the predefines buffers. -  if (CheckPredefinesBuffers()) +  if (!DisableValidation && CheckPredefinesBuffers())      return IgnorePCH;    if (PP) {  | 

