[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 14:08:40 PDT 2020
Tyker created this revision.
Tyker added a reviewer: lebedev.ri.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Tyker requested review of this revision.
This helps with both debugging llvm-reduce and sometimes getting usefull result even if llvm-reduce crashes
Repository:
rG LLVM Github Monorepo
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
@@ -21,6 +21,7 @@
#include "llvm/IRReader/IRReader.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include <system_error>
@@ -80,6 +81,22 @@
return Result;
}
+/// This variable is mark volatile because it is accessed by a signal handler.
+Module *volatile LastIntersting = nullptr;
+
+static void onCrashHandler(void *) {
+ StringRef Path = "last-interssting.ll";
+
+ std::error_code EC;
+ raw_fd_ostream Out(Path, EC);
+ if (EC) {
+ errs() << "Error opening output file: " << EC.message() << "!\n";
+ exit(1);
+ }
+ LastIntersting->print(Out, /*AnnotationWriter=*/nullptr);
+ errs() << "\n Saved last intersting Module to " << Path << "\n";
+}
+
int main(int argc, char **argv) {
InitLLVM X(argc, argv);
@@ -88,6 +105,8 @@
LLVMContext Context;
std::unique_ptr<Module> OriginalProgram =
parseInputFile(InputFilename, Context);
+ LastIntersting = OriginalProgram.get();
+ sys::AddSignalHandler(onCrashHandler, nullptr);
// Initialize test environment
TestRunner Tester(TestFilename, TestArguments);
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;
+extern Module *volatile LastIntersting;
+
bool IsReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) {
// Write Module to tmp file
int FD;
@@ -148,6 +150,7 @@
FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = true;
UninterestingChunks.insert(ChunkToCheckForUninterestingness);
ReducedProgram = std::move(Clone);
+ LastIntersting = ReducedProgram.get();
errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n";
}
// Delete uninteresting chunks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85996.285756.patch
Type: text/x-patch
Size: 2180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200814/e7e75ab5/attachment.bin>
More information about the llvm-commits
mailing list