summaryrefslogtreecommitdiff
path: root/tools/opt
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-08-20 01:07:01 +0000
committerDan Gohman <gohman@apple.com>2010-08-20 01:07:01 +0000
commitd5826a33a5a7c298a8934541d11cda042028be3b (patch)
tree56249c802243407a71acb23ba3bcf59eb0d58b2b /tools/opt
parent52fdaeda759b2ef3b9048ab8651b024f864b3858 (diff)
downloadllvm-d5826a33a5a7c298a8934541d11cda042028be3b.tar.gz
llvm-d5826a33a5a7c298a8934541d11cda042028be3b.tar.bz2
llvm-d5826a33a5a7c298a8934541d11cda042028be3b.tar.xz
Use the new tool_output_file in several tools. This fixes a variety
of problems with output files being left behind or output streams being left unclosed. Fix llvm-mc to respect the -o option in all modes, rather than hardcoding outs() in some cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111603 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/opt')
-rw-r--r--tools/opt/opt.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index b8700685ca..f4ca38fb1a 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -385,7 +385,7 @@ int main(int argc, char **argv) {
}
// Figure out what stream we are supposed to write to...
- raw_ostream *Out = 0;
+ OwningPtr<tool_output_file> Out;
if (NoOutput) {
if (!OutputFilename.empty())
errs() << "WARNING: The -o (output filename) option is ignored when\n"
@@ -395,17 +395,11 @@ int main(int argc, char **argv) {
if (OutputFilename.empty())
OutputFilename = "-";
- // Make sure that the Output file gets unlinked from the disk if we get
- // a SIGINT.
- if (OutputFilename != "-")
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
-
std::string ErrorInfo;
- Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
- raw_fd_ostream::F_Binary);
+ Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
+ raw_fd_ostream::F_Binary));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
- delete Out;
return 1;
}
}
@@ -542,7 +536,7 @@ int main(int argc, char **argv) {
// Write bitcode or assembly to the output as the last step...
if (!NoOutput && !AnalyzeOnly) {
if (OutputAssembly)
- Passes.add(createPrintModulePass(Out));
+ Passes.add(createPrintModulePass(Out.get()));
else
Passes.add(createBitcodeWriterPass(*Out));
}
@@ -550,7 +544,9 @@ int main(int argc, char **argv) {
// Now that we have all of the passes ready, run them.
Passes.run(*M.get());
- // Delete the raw_fd_ostream.
- delete Out;
+ // Declare success.
+ if (!NoOutput)
+ Out->keep();
+
return 0;
}