X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=utils%2Fnot%2Fnot.cpp;h=a5c7183bd2c9b019c07eadd4f5e5abfe80c31d85;hb=12af22e8cc217827cf4f118b0f5e4ebbda9925ae;hp=dd89b8f11c0e4a93d6fcddc3fae4939ea9fa5edc;hpb=48f7ce88a6040c12d4c7d0a5bd208cf1e0bda9d1;p=oota-llvm.git diff --git a/utils/not/not.cpp b/utils/not/not.cpp index dd89b8f11c0..a5c7183bd2c 100644 --- a/utils/not/not.cpp +++ b/utils/not/not.cpp @@ -7,11 +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]); - return !sys::Program::ExecuteAndWait(Program, 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, 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; }