1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[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
This commit is contained in:
Tyker 2020-08-22 19:04:20 +02:00
parent 4175888640
commit d75baa4613
2 changed files with 21 additions and 15 deletions

View File

@ -21,6 +21,8 @@
using namespace llvm;
void writeOutput(llvm::Module *M, llvm::StringRef Message);
bool IsReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) {
// Write Module to tmp file
int FD;
@ -149,6 +151,7 @@ void llvm::runDeltaPass(
UninterestingChunks.insert(ChunkToCheckForUninterestingness);
ReducedProgram = std::move(Clone);
errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n";
writeOutput(ReducedProgram.get(), "Saved new best reduction to ");
}
// Delete uninteresting chunks
erase_if(ChunksStillConsideredInteresting,

View File

@ -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;