diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-12-03 09:13:06 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-12-03 09:13:06 +0000 |
commit | 3b95148ce1c73b1bda0b1180af3e91f0623ce2da (patch) | |
tree | 20b30400c5cf928791cece126b5c72908b56d504 /clang | |
parent | acadc55d4e7fb58a51f03108dc9e9a2d44aaa1f2 (diff) | |
download | bcm5719-llvm-3b95148ce1c73b1bda0b1180af3e91f0623ce2da.tar.gz bcm5719-llvm-3b95148ce1c73b1bda0b1180af3e91f0623ce2da.zip |
Switch PCHReader::getOriginalSourceFile to use proper diagnostics.
llvm-svn: 90434
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Basic/DiagnosticFrontendKinds.td | 8 | ||||
-rw-r--r-- | clang/include/clang/Frontend/PCHReader.h | 3 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Frontend/PCHReader.cpp | 15 |
4 files changed, 19 insertions, 13 deletions
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 9ddb87f3b73..835f57b13be 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -45,6 +45,14 @@ def err_fe_unable_to_create_target : Error< "unable to create target: '%0'">; def err_fe_unable_to_interface_with_target : Error< "unable to interface with target machine">; +def err_fe_unable_to_read_pch_file : Error< + "unable to read PCH file: '%0'">; +def err_fe_not_a_pch_file : Error< + "input is not a PCH file: '%0'">; +def err_fe_pch_malformed_block : Error< + "malformed block record in PCH file: '%0'">; +def err_fe_pch_error_at_end_block : Error< + "error at end of module block in PCH file: '%0'">; def err_verify_bogus_characters : Error< "bogus characters before '{{' in expected string">; diff --git a/clang/include/clang/Frontend/PCHReader.h b/clang/include/clang/Frontend/PCHReader.h index ae7cb14422d..ff92cee7f55 100644 --- a/clang/include/clang/Frontend/PCHReader.h +++ b/clang/include/clang/Frontend/PCHReader.h @@ -530,7 +530,8 @@ public: /// \brief Retrieve the name of the original source file name /// directly from the PCH file, without actually loading the PCH /// file. - static std::string getOriginalSourceFile(const std::string &PCHFileName); + static std::string getOriginalSourceFile(const std::string &PCHFileName, + Diagnostic &Diags); /// \brief Returns the suggested contents of the predefines buffer, /// which contains a (typically-empty) subset of the predefines diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index ccf60fb9e38..2ecbcfe862e 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1205,11 +1205,9 @@ static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, // PCH is handled specially, we need to extra the original include path. if (it->getOption().matches(OPT_include_pch)) { std::string OriginalFile = - PCHReader::getOriginalSourceFile(it->getValue(Args)); - - // FIXME: Don't fail like this. + PCHReader::getOriginalSourceFile(it->getValue(Args), Diags); if (OriginalFile.empty()) - exit(1); + continue; Opts.Includes.push_back(OriginalFile); } else diff --git a/clang/lib/Frontend/PCHReader.cpp b/clang/lib/Frontend/PCHReader.cpp index cb96bcb48ae..40eb9ca536d 100644 --- a/clang/lib/Frontend/PCHReader.cpp +++ b/clang/lib/Frontend/PCHReader.cpp @@ -1569,13 +1569,14 @@ void PCHReader::InitializeContext(ASTContext &Ctx) { /// \brief Retrieve the name of the original source file name /// directly from the PCH file, without actually loading the PCH /// file. -std::string PCHReader::getOriginalSourceFile(const std::string &PCHFileName) { +std::string PCHReader::getOriginalSourceFile(const std::string &PCHFileName, + Diagnostic &Diags) { // Open the PCH file. std::string ErrStr; llvm::OwningPtr<llvm::MemoryBuffer> Buffer; Buffer.reset(llvm::MemoryBuffer::getFile(PCHFileName.c_str(), &ErrStr)); if (!Buffer) { - fprintf(stderr, "error: %s\n", ErrStr.c_str()); + Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; return std::string(); } @@ -1591,9 +1592,7 @@ std::string PCHReader::getOriginalSourceFile(const std::string &PCHFileName) { Stream.Read(8) != 'P' || Stream.Read(8) != 'C' || Stream.Read(8) != 'H') { - fprintf(stderr, - "error: '%s' does not appear to be a precompiled header file\n", - PCHFileName.c_str()); + Diags.Report(diag::err_fe_not_a_pch_file) << PCHFileName; return std::string(); } @@ -1608,14 +1607,14 @@ std::string PCHReader::getOriginalSourceFile(const std::string &PCHFileName) { switch (BlockID) { case pch::PCH_BLOCK_ID: if (Stream.EnterSubBlock(pch::PCH_BLOCK_ID)) { - fprintf(stderr, "error: malformed block record in PCH file\n"); + Diags.Report(diag::err_fe_pch_malformed_block) << PCHFileName; return std::string(); } break; default: if (Stream.SkipBlock()) { - fprintf(stderr, "error: malformed block record in PCH file\n"); + Diags.Report(diag::err_fe_pch_malformed_block) << PCHFileName; return std::string(); } break; @@ -1625,7 +1624,7 @@ std::string PCHReader::getOriginalSourceFile(const std::string &PCHFileName) { if (Code == llvm::bitc::END_BLOCK) { if (Stream.ReadBlockEnd()) { - fprintf(stderr, "error: error at end of module block in PCH file\n"); + Diags.Report(diag::err_fe_pch_error_at_end_block) << PCHFileName; return std::string(); } continue; |