From: Jordan Rupprecht Date: Tue, 12 Feb 2019 20:00:51 +0000 (+0000) Subject: [llvm-dwp] Avoid writing the output dwp file when there is an error X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02f8fc49ff4ad5f37a0bd7ad4264e7fb98745b99;p=llvm [llvm-dwp] Avoid writing the output dwp file when there is an error Summary: Use ToolOutputFile to clean up the output file unless dwp actually finishes successfully. Reviewers: dblaikie Reviewed By: dblaikie Subscribers: jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58130 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353873 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/tools/llvm-dwp/X86/missing_dwo_id.test b/test/tools/llvm-dwp/X86/missing_dwo_id.test index a07bcb8fb9b..bb5eddccd22 100644 --- a/test/tools/llvm-dwp/X86/missing_dwo_id.test +++ b/test/tools/llvm-dwp/X86/missing_dwo_id.test @@ -1,3 +1,7 @@ +RUN: rm -f %t RUN: not llvm-dwp %p/../Inputs/missing_dwo_id.dwo -o %t 2>&1 | FileCheck %s +Make sure we did not leave behind a temporary file: +RUN: not ls %t + CHECK: error: {{.*}}missing_dwo_id.dwo': compile unit missing dwo_id diff --git a/tools/llvm-dwp/llvm-dwp.cpp b/tools/llvm-dwp/llvm-dwp.cpp index 87831a8f81f..f2fb3ba1479 100644 --- a/tools/llvm-dwp/llvm-dwp.cpp +++ b/tools/llvm-dwp/llvm-dwp.cpp @@ -39,6 +39,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -700,23 +701,23 @@ int main(int argc, char **argv) { // Create the output file. std::error_code EC; - raw_fd_ostream OutFile(OutputFilename, EC, sys::fs::F_None); + ToolOutputFile OutFile(OutputFilename, EC, sys::fs::F_None); Optional BOS; raw_pwrite_stream *OS; if (EC) return error(Twine(OutputFilename) + ": " + EC.message(), Context); - if (OutFile.supportsSeeking()) { - OS = &OutFile; + if (OutFile.os().supportsSeeking()) { + OS = &OutFile.os(); } else { - BOS.emplace(OutFile); + BOS.emplace(OutFile.os()); OS = BOS.getPointer(); } MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); std::unique_ptr MS(TheTarget->createMCObjectStreamer( TheTriple, MC, std::unique_ptr(MAB), - MAB->createObjectWriter(*OS), std::unique_ptr(MCE), - *MSTI, MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible, + MAB->createObjectWriter(*OS), std::unique_ptr(MCE), *MSTI, + MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ false)); if (!MS) return error("no object streamer for target " + TripleName, Context); @@ -739,4 +740,6 @@ int main(int argc, char **argv) { } MS->Finish(); + OutFile.keep(); + return 0; }