[llvm] 4cf5e22 - llvm-reduce: Report file opening errors

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 31 20:08:29 PDT 2022


Author: Matt Arsenault
Date: 2022-10-31T18:37:33-07:00
New Revision: 4cf5e22d20dfb725e92b57c7ac4bba65d7cd62be

URL: https://github.com/llvm/llvm-project/commit/4cf5e22d20dfb725e92b57c7ac4bba65d7cd62be
DIFF: https://github.com/llvm/llvm-project/commit/4cf5e22d20dfb725e92b57c7ac4bba65d7cd62be.diff

LOG: llvm-reduce: Report file opening errors

This was also trying to write the bitcode to the failed file
on failure, which asserts. Also, consistently use
ToolOutputFile, instead of one path manually removing
the temp file.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp
index c29c8af3e25d8..26feca6b99248 100644
--- a/llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -79,24 +79,17 @@ bool isReduced(ReducerWorkItem &M, TestRunner &Test) {
     exit(1);
   }
 
-  if (TmpFilesAsBitcode) {
-    llvm::raw_fd_ostream OutStream(FD, true);
-    writeBitcode(M, OutStream);
-    OutStream.close();
-    if (OutStream.has_error()) {
-      errs() << "Error emitting bitcode to file '" << CurrentFilepath << "'!\n";
-      sys::fs::remove(CurrentFilepath);
-      exit(1);
-    }
-    bool Res = Test.run(CurrentFilepath);
-    sys::fs::remove(CurrentFilepath);
-    return Res;
-  }
   ToolOutputFile Out(CurrentFilepath, FD);
-  M.print(Out.os(), /*AnnotationWriter=*/nullptr);
+
+  if (TmpFilesAsBitcode)
+    writeBitcode(M, Out.os());
+  else
+    M.print(Out.os(), /*AnnotationWriter=*/nullptr);
+
   Out.os().close();
   if (Out.os().has_error()) {
-    errs() << "Error emitting bitcode to file '" << CurrentFilepath << "'!\n";
+    errs() << "Error emitting bitcode to file '" << CurrentFilepath
+           << "': " << Out.os().error().message();
     exit(1);
   }
 


        


More information about the llvm-commits mailing list