[llvm] r177573 - Make sure TableGen exits with an error code after printing errors.

Jakob Stoklund Olesen stoklund at 2pi.dk
Wed Mar 20 13:43:11 PDT 2013


Author: stoklund
Date: Wed Mar 20 15:43:11 2013
New Revision: 177573

URL: http://llvm.org/viewvc/llvm-project?rev=177573&view=rev
Log:
Make sure TableGen exits with an error code after printing errors.

This makes it possible to report multiple errors in one invocation.
There are already calls to PrintError in CodeGenDAGPatterns.cpp which
previously would not cause TableGen to fail.

<rdar://problem/13463339>

Modified:
    llvm/trunk/include/llvm/TableGen/Error.h
    llvm/trunk/lib/TableGen/Error.cpp
    llvm/trunk/lib/TableGen/Main.cpp

Modified: llvm/trunk/include/llvm/TableGen/Error.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Error.h?rev=177573&r1=177572&r2=177573&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Error.h (original)
+++ llvm/trunk/include/llvm/TableGen/Error.h Wed Mar 20 15:43:11 2013
@@ -32,6 +32,7 @@ LLVM_ATTRIBUTE_NORETURN void PrintFatalE
                                              const std::string &Msg);
 
 extern SourceMgr SrcMgr;
+extern unsigned ErrorsPrinted;
 
 
 } // end namespace "llvm"

Modified: llvm/trunk/lib/TableGen/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Error.cpp?rev=177573&r1=177572&r2=177573&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Error.cpp (original)
+++ llvm/trunk/lib/TableGen/Error.cpp Wed Mar 20 15:43:11 2013
@@ -20,9 +20,15 @@
 namespace llvm {
 
 SourceMgr SrcMgr;
+unsigned ErrorsPrinted = 0;
 
 static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
                          const Twine &Msg) {
+  // Count the total number of errors printed.
+  // This is used to exit with an error code if there were any errors.
+  if (Kind == SourceMgr::DK_Error)
+    ++ErrorsPrinted;
+
   SMLoc NullLoc;
   if (Loc.empty())
     Loc = NullLoc;

Modified: llvm/trunk/lib/TableGen/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Main.cpp?rev=177573&r1=177572&r2=177573&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Main.cpp (original)
+++ llvm/trunk/lib/TableGen/Main.cpp Wed Mar 20 15:43:11 2013
@@ -117,11 +117,14 @@ int TableGenMain(char *argv0, TableGenMa
   if (MainFn(Out.os(), Records))
     return 1;
 
+  if (ErrorsPrinted > 0) {
+    errs() << argv0 << ": " << ErrorsPrinted << " errors.\n";
+    return 1;
+  }
+
   // Declare success.
   Out.keep();
   return 0;
-
-  return 1;
 }
 
 }





More information about the llvm-commits mailing list