TableGen: Allow AddedComplexity values to be negative
[oota-llvm.git] / utils / not / not.cpp
index 908abe932d10591b38b05fd66f9f07c906b62e19..a5c7183bd2c9b019c07eadd4f5e5abfe80c31d85 100644 (file)
@@ -7,21 +7,48 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/System/Path.h"
-#include "llvm/System/Program.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
 int main(int argc, const char **argv) {
-  sys::Path Program = sys::Program::FindProgramByName(argv[1]);
+  bool ExpectCrash = false;
+
+  ++argv;
+  --argc;
+
+  if (argc > 0 && StringRef(argv[0]) == "--crash") {
+    ++argv;
+    --argc;
+    ExpectCrash = true;
+  }
+
+  if (argc == 0)
+    return 1;
+
+  std::string Program = sys::FindProgramByName(argv[0]);
 
   std::string ErrMsg;
-  int Result = sys::Program::ExecuteAndWait(Program, argv + 1, 0, 0, 0, 0,
-                                            &ErrMsg);
+  int Result = sys::ExecuteAndWait(Program, argv, nullptr, nullptr, 0, 0,
+                                   &ErrMsg);
+#ifdef _WIN32
+  // Handle abort() in msvcrt -- It has exit code as 3.  abort(), aka
+  // unreachable, should be recognized as a crash.  However, some binaries use
+  // exit code 3 on non-crash failure paths, so only do this if we expect a
+  // crash.
+  if (ExpectCrash && Result == 3)
+    Result = -3;
+#endif
   if (Result < 0) {
     errs() << "Error: " << ErrMsg << "\n";
+    if (ExpectCrash)
+      return 0;
     return 1;
   }
 
+  if (ExpectCrash)
+    return 1;
+
   return Result == 0;
 }