From 7f28d732d2a851c097aeb544dc8010bd78d721b5 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Sat, 2 Sep 2017 23:43:04 +0000 Subject: Move some CLI utils out of llvm-isel-fuzzer and into the library FuzzMutate might not be the best place for these, but it makes more sense than an entirely new library for now. This will make setting up fuzz targets with consistent CLI handling easier. llvm-svn: 312425 --- llvm/tools/llvm-isel-fuzzer/DummyISelFuzzer.cpp | 38 ++----------------------- 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'llvm/tools/llvm-isel-fuzzer/DummyISelFuzzer.cpp') diff --git a/llvm/tools/llvm-isel-fuzzer/DummyISelFuzzer.cpp b/llvm/tools/llvm-isel-fuzzer/DummyISelFuzzer.cpp index 89c1c81cdbe..ec9c74e3040 100644 --- a/llvm/tools/llvm-isel-fuzzer/DummyISelFuzzer.cpp +++ b/llvm/tools/llvm-isel-fuzzer/DummyISelFuzzer.cpp @@ -11,43 +11,11 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/Compiler.h" -#include "llvm/Support/Error.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/raw_ostream.h" - -using namespace llvm; +#include "llvm/FuzzMutate/FuzzerCLI.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size); extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv); - int main(int argc, char *argv[]) { - errs() << "*** This tool was not linked to libFuzzer.\n" - << "*** No fuzzing will be performed.\n"; - if (int RC = LLVMFuzzerInitialize(&argc, &argv)) { - errs() << "Initialization failed\n"; - return RC; - } - - for (int I = 1; I < argc; ++I) { - StringRef Arg(argv[I]); - if (Arg.startswith("-")) { - if (Arg.equals("-ignore_remaining_args=1")) - break; - continue; - } - - auto BufOrErr = MemoryBuffer::getFile(Arg, /*FileSize-*/ -1, - /*RequiresNullTerminator=*/false); - if (std::error_code EC = BufOrErr.getError()) { - errs() << "Error reading file: " << Arg << ": " << EC.message() << "\n"; - return 1; - } - std::unique_ptr Buf = std::move(BufOrErr.get()); - errs() << "Running: " << Arg << " (" << Buf->getBufferSize() << " bytes)\n"; - LLVMFuzzerTestOneInput( - reinterpret_cast(Buf->getBufferStart()), - Buf->getBufferSize()); - } + return llvm::runFuzzerOnInputs(argc, argv, LLVMFuzzerTestOneInput, + LLVMFuzzerInitialize); } -- cgit v1.2.3