diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index bc548e4e8b84..fba2df13a37a 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -1154,7 +1154,7 @@ public: // Use PTH? if (!TokenCache.empty()) - PTHMgr.reset(PTHManager::Create(TokenCache)); + PTHMgr.reset(PTHManager::Create(TokenCache, &Diags)); // Create the Preprocessor. llvm::OwningPtr PP(new Preprocessor(Diags, LangInfo, Target, diff --git a/clang/include/clang/Lex/PTHManager.h b/clang/include/clang/Lex/PTHManager.h index b77cda1f0b7d..22343e208c27 100644 --- a/clang/include/clang/Lex/PTHManager.h +++ b/clang/include/clang/Lex/PTHManager.h @@ -29,6 +29,7 @@ namespace clang { class FileEntry; class PTHLexer; +class Diagnostic; class PTHManager : public IdentifierInfoLookup { friend class PTHLexer; @@ -107,7 +108,7 @@ public: /// Create - This method creates PTHManager objects. The 'file' argument /// is the name of the PTH file. This method returns NULL upon failure. - static PTHManager *Create(const std::string& file); + static PTHManager *Create(const std::string& file, Diagnostic* Diags = 0); void setPreprocessor(Preprocessor *pp) { PP = pp; } diff --git a/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp index f9f2b2106120..36f509cba648 100644 --- a/clang/lib/Lex/PTHLexer.cpp +++ b/clang/lib/Lex/PTHLexer.cpp @@ -390,13 +390,20 @@ PTHManager::~PTHManager() { free(PerIDCache); } -PTHManager* PTHManager::Create(const std::string& file) { +PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags) { // Memory map the PTH file. llvm::OwningPtr File(llvm::MemoryBuffer::getFile(file.c_str())); - if (!File) + if (!File) { + if (Diags) { + unsigned DiagID = Diags->getCustomDiagID(Diagnostic::Note, + "PTH file %0 could not be read"); + Diags->Report(FullSourceLoc(), DiagID) << file; + } + return 0; + } // Get the buffer ranges and check if there are at least three 32-bit // words at the end of the file.