[cfe-commits] r90434 - in /cfe/trunk: include/clang/Basic/DiagnosticFrontendKinds.td include/clang/Frontend/PCHReader.h lib/Frontend/CompilerInvocation.cpp lib/Frontend/PCHReader.cpp

Daniel Dunbar daniel at zuster.org
Thu Dec 3 01:13:06 PST 2009


Author: ddunbar
Date: Thu Dec  3 03:13:06 2009
New Revision: 90434

URL: http://llvm.org/viewvc/llvm-project?rev=90434&view=rev
Log:
Switch PCHReader::getOriginalSourceFile to use proper diagnostics.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
    cfe/trunk/include/clang/Frontend/PCHReader.h
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/PCHReader.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=90434&r1=90433&r2=90434&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Thu Dec  3 03:13:06 2009
@@ -45,6 +45,14 @@
     "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">;

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=90434&r1=90433&r2=90434&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Thu Dec  3 03:13:06 2009
@@ -530,7 +530,8 @@
   /// \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

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=90434&r1=90433&r2=90434&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Dec  3 03:13:06 2009
@@ -1205,11 +1205,9 @@
     // 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

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=90434&r1=90433&r2=90434&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Thu Dec  3 03:13:06 2009
@@ -1569,13 +1569,14 @@
 /// \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 @@
       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 @@
       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 @@
 
     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;





More information about the cfe-commits mailing list