X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=utils%2Fnot%2Fnot.cpp;h=a5c7183bd2c9b019c07eadd4f5e5abfe80c31d85;hb=12af22e8cc217827cf4f118b0f5e4ebbda9925ae;hp=bb2d87bb44d4dcb59dad48dbe7ca250a8756d268;hpb=9f1d9fd1964d82f3e801efb71518144492cdf290;p=oota-llvm.git diff --git a/utils/not/not.cpp b/utils/not/not.cpp index bb2d87bb44d..a5c7183bd2c 100644 --- a/utils/not/not.cpp +++ b/utils/not/not.cpp @@ -13,14 +13,42 @@ using namespace llvm; int main(int argc, const char **argv) { - sys::Path 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, 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; }