[llvm] r185678 - Add a --crash option to not.

Rafael Espindola rafael.espindola at gmail.com
Thu Jul 4 19:50:04 PDT 2013


Author: rafael
Date: Thu Jul  4 21:50:03 2013
New Revision: 185678

URL: http://llvm.org/viewvc/llvm-project?rev=185678&view=rev
Log:
Add a --crash option to not.

Now the two possible uses of not are
* not cmd
  Will return true if cmd doesn't crash and returns false.
* not --crash cmd
  Will return true if cmd crashes.

It will be used/tested in a followup commit for the clang crash recovery
testing.

Modified:
    llvm/trunk/utils/not/not.cpp

Modified: llvm/trunk/utils/not/not.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/not/not.cpp?rev=185678&r1=185677&r2=185678&view=diff
==============================================================================
--- llvm/trunk/utils/not/not.cpp (original)
+++ llvm/trunk/utils/not/not.cpp Thu Jul  4 21:50:03 2013
@@ -13,14 +13,33 @@
 using namespace llvm;
 
 int main(int argc, const char **argv) {
-  std::string Program = sys::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::ExecuteAndWait(Program, argv + 1, 0, 0, 0, 0, &ErrMsg);
+  int Result = sys::ExecuteAndWait(Program, argv, 0, 0, 0, 0, &ErrMsg);
   if (Result < 0) {
     errs() << "Error: " << ErrMsg << "\n";
+    if (ExpectCrash)
+      return 0;
     return 1;
   }
 
+  if (ExpectCrash)
+    return 1;
+
   return Result == 0;
 }





More information about the llvm-commits mailing list