Make sure TableGen exits with an error code after printing errors.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 20 Mar 2013 20:43:11 +0000 (20:43 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 20 Mar 2013 20:43:11 +0000 (20:43 +0000)
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>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177573 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/TableGen/Error.h
lib/TableGen/Error.cpp
lib/TableGen/Main.cpp

index 2f6b7e625c3dd4b0598caf26f4ccb8598fdcffbc..2d0a2b45a96a0c5ea830bb434c6038f6cdb8f917 100644 (file)
@@ -32,6 +32,7 @@ LLVM_ATTRIBUTE_NORETURN void PrintFatalError(ArrayRef<SMLoc> ErrorLoc,
                                              const std::string &Msg);
 
 extern SourceMgr SrcMgr;
+extern unsigned ErrorsPrinted;
 
 
 } // end namespace "llvm"
index ec84a72454f65a90a23e74ceea79b920c76d87f6..928b1203cd8f108ca0b4b180f56bf1f2fdebc7b9 100644 (file)
 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;
index e1cd6237832c5ace7ca554db988d4ca1fc00307b..dc4167b305cae65dce354b3129d5dad44f60c84d 100644 (file)
@@ -117,11 +117,14 @@ int TableGenMain(char *argv0, TableGenMainFn *MainFn) {
   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;
 }
 
 }