[PATCH] D85996: [llvm-reduce] make llvm-reduce save the best reduction it has when it crashes
Tyker via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 14 15:14:38 PDT 2020
Tyker updated this revision to Diff 285769.
Tyker added a comment.
In D85996#2219124 <https://reviews.llvm.org/D85996#2219124>, @lebedev.ri wrote:
> 1. I'm pretty sure it's not okay to allocate memory in crash handler.
> 2. We can't know that the internal state is still consistent.
i agree with both points but all i was trying to do i salvage what can be salvaged.
> We already store each IR to disk to run the interestingness test on it.
> Instead of `LastIntersting = ReducedProgram.get();`, let's just rewrite the `OutputFilename` each time.
yeah this is a better idea.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85996/new/
https://reviews.llvm.org/D85996
Files:
llvm/tools/llvm-reduce/deltas/Delta.cpp
llvm/tools/llvm-reduce/llvm-reduce.cpp
Index: llvm/tools/llvm-reduce/llvm-reduce.cpp
===================================================================
--- llvm/tools/llvm-reduce/llvm-reduce.cpp
+++ llvm/tools/llvm-reduce/llvm-reduce.cpp
@@ -80,6 +80,22 @@
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 @@
// 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;
Index: llvm/tools/llvm-reduce/deltas/Delta.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -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 @@
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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85996.285769.patch
Type: text/x-patch
Size: 2399 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200814/4e81051e/attachment.bin>
More information about the llvm-commits
mailing list