diff options
author | Tyker <tyker1@outlook.com> | 2020-08-22 19:04:20 +0200 |
---|---|---|
committer | Tyker <tyker1@outlook.com> | 2020-08-22 19:16:43 +0200 |
commit | 7fef40d83cbb1be376f58b5763cf362e517b5e8d (patch) | |
tree | be598217c9b175fa99b18a42e3ea6f43cf201d35 /llvm/tools/llvm-reduce/llvm-reduce.cpp | |
parent | 2aaa5a546ea016b8e2092ced1bd7147db51d483a (diff) | |
download | llvm-7fef40d83cbb1be376f58b5763cf362e517b5e8d.zip llvm-7fef40d83cbb1be376f58b5763cf362e517b5e8d.tar.gz llvm-7fef40d83cbb1be376f58b5763cf362e517b5e8d.tar.bz2 |
[llvm-reduce] make llvm-reduce save the best reduction it has when it crashes
This helps with both debugging llvm-reduce and sometimes getting usefull result even if llvm-reduce crashes
Reviewed By: lebedev.ri
Differential Revision: https://reviews.llvm.org/D85996
Diffstat (limited to 'llvm/tools/llvm-reduce/llvm-reduce.cpp')
-rw-r--r-- | llvm/tools/llvm-reduce/llvm-reduce.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/llvm/tools/llvm-reduce/llvm-reduce.cpp b/llvm/tools/llvm-reduce/llvm-reduce.cpp index 9dd8aa4..376826b 100644 --- a/llvm/tools/llvm-reduce/llvm-reduce.cpp +++ b/llvm/tools/llvm-reduce/llvm-reduce.cpp @@ -80,6 +80,22 @@ static std::unique_ptr<Module> parseInputFile(StringRef Filename, return Result; } +void writeOutput(Module *M, StringRef Message) { + if (ReplaceInput) // In-place + OutputFilename = InputFilename.c_str(); + else if (OutputFilename.empty() || OutputFilename == "-") + OutputFilename = "reduced.ll"; + + std::error_code EC; + raw_fd_ostream Out(OutputFilename, EC); + if (EC) { + errs() << "Error opening output file: " << EC.message() << "!\n"; + exit(1); + } + M->print(Out, /*AnnotationWriter=*/nullptr); + errs() << Message << OutputFilename << "\n"; +} + int main(int argc, char **argv) { InitLLVM X(argc, argv); @@ -102,21 +118,8 @@ int main(int argc, char **argv) { // Print reduced file to STDOUT if (OutputFilename == "-") Tester.getProgram()->print(outs(), nullptr); - else { - if (ReplaceInput) // In-place - OutputFilename = InputFilename.c_str(); - else if (OutputFilename.empty()) - OutputFilename = "reduced.ll"; - - std::error_code EC; - raw_fd_ostream Out(OutputFilename, EC); - if (EC) { - errs() << "Error opening output file: " << EC.message() << "!\n"; - exit(1); - } - Tester.getProgram()->print(Out, /*AnnotationWriter=*/nullptr); - errs() << "\nDone reducing! Reduced testcase: " << OutputFilename << "\n"; - } + else + writeOutput(Tester.getProgram(), "\nDone reducing! Reduced testcase: "); } return 0; |