Skip to content

Commit

Permalink
llvm-reduce: Report file opening errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arsenm committed Nov 1, 2022
1 parent 07f1217 commit 4cf5e22
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions llvm/tools/llvm-reduce/deltas/Delta.cpp
Expand Up @@ -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);
}

Expand Down

0 comments on commit 4cf5e22

Please sign in to comment.