[llvm] 7fef40d - [llvm-reduce] make llvm-reduce save the best reduction it has when it crashes

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 22 10:17:05 PDT 2020


Author: Tyker
Date: 2020-08-22T19:16:43+02:00
New Revision: 7fef40d83cbb1be376f58b5763cf362e517b5e8d

URL: https://github.com/llvm/llvm-project/commit/7fef40d83cbb1be376f58b5763cf362e517b5e8d
DIFF: https://github.com/llvm/llvm-project/commit/7fef40d83cbb1be376f58b5763cf362e517b5e8d.diff

LOG: [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

Added: 
    

Modified: 
    llvm/tools/llvm-reduce/deltas/Delta.cpp
    llvm/tools/llvm-reduce/llvm-reduce.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp
index c23d70145b69..02ff46dbe2d1 100644
--- a/llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ b/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 @@ 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,

diff  --git a/llvm/tools/llvm-reduce/llvm-reduce.cpp b/llvm/tools/llvm-reduce/llvm-reduce.cpp
index 9dd8aa4a938e..376826b8b9e7 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;


        


More information about the llvm-commits mailing list