[cfe-commits] r90442 - in /cfe/trunk: include/clang/Basic/DiagnosticFrontendKinds.td lib/Frontend/InitPreprocessor.cpp

Daniel Dunbar daniel at zuster.org
Thu Dec 3 01:14:12 PST 2009


Author: ddunbar
Date: Thu Dec  3 03:14:12 2009
New Revision: 90442

URL: http://llvm.org/viewvc/llvm-project?rev=90442&view=rev
Log:
Fix two more diagnostic-on-stderr instances that thought they could hide from me -- they thought wrong.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
    cfe/trunk/lib/Frontend/InitPreprocessor.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Thu Dec  3 03:14:12 2009
@@ -55,6 +55,10 @@
     "error at end of module block in PCH file: '%0'">;
 def err_fe_unable_to_open_output : Error<
     "unable to to open output file '%0': '%1'">;
+def err_fe_pth_file_has_no_source_header : Error<
+    "PTH file '%0' does not designate an original source header file for -include-pth">;
+def warn_fe_macro_contains_embedded_newline : Warning<
+    "macro '%0' contains embedded newline, text after the newline is ignored.">;
 
 def err_verify_bogus_characters : Error<
     "bogus characters before '{{' in expected string">;

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

==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu Dec  3 03:14:12 2009
@@ -28,7 +28,8 @@
 // Append a #define line to Buf for Macro.  Macro should be of the form XXX,
 // in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
 // "#define XXX Y z W".  To get a #define with no value, use "XXX=".
-static void DefineBuiltinMacro(std::vector<char> &Buf, const char *Macro) {
+static void DefineBuiltinMacro(std::vector<char> &Buf, const char *Macro,
+                               Diagnostic *Diags = 0) {
   const char *Command = "#define ";
   Buf.insert(Buf.end(), Command, Command+strlen(Command));
   if (const char *Equal = strchr(Macro, '=')) {
@@ -39,9 +40,9 @@
     // Per GCC -D semantics, the macro ends at \n if it exists.
     const char *End = strpbrk(Equal, "\n\r");
     if (End) {
-      fprintf(stderr, "warning: macro '%s' contains embedded newline, text "
-              "after the newline is ignored.\n",
-              std::string(Macro, Equal).c_str());
+      assert(Diags && "Unexpected macro with embedded newline!");
+      Diags->Report(diag::warn_fe_macro_contains_embedded_newline)
+        << std::string(Macro, Equal);
     } else {
       End = Equal+strlen(Equal);
     }
@@ -123,11 +124,9 @@
   const char *OriginalFile = P->getOriginalSourceFile();
 
   if (!OriginalFile) {
-    assert(!ImplicitIncludePTH.empty());
-    fprintf(stderr, "error: PTH file '%s' does not designate an original "
-            "source header file for -include-pth\n",
-            ImplicitIncludePTH.c_str());
-    exit (1);
+    PP.getDiagnostics().Report(diag::err_fe_pth_file_has_no_source_header)
+      << ImplicitIncludePTH;
+    return;
   }
 
   AddImplicitInclude(Buf, OriginalFile);
@@ -560,7 +559,8 @@
     if (InitOpts.Macros[i].second)  // isUndef
       UndefineBuiltinMacro(PredefineBuffer, InitOpts.Macros[i].first.c_str());
     else
-      DefineBuiltinMacro(PredefineBuffer, InitOpts.Macros[i].first.c_str());
+      DefineBuiltinMacro(PredefineBuffer, InitOpts.Macros[i].first.c_str(),
+                         &PP.getDiagnostics());
   }
 
   // If -imacros are specified, include them now.  These are processed before





More information about the cfe-commits mailing list