Avoid calling outs() and fouts() when the stream isn't really needed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104873 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 51b920f..a29555c 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -378,8 +378,12 @@
// Figure out what stream we are supposed to write to...
// FIXME: outs() is not binary!
- raw_ostream *Out = &outs(); // Default to printing to stdout...
- if (OutputFilename != "-") {
+ raw_ostream *Out = 0;
+ bool DeleteStream = true;
+ if (OutputFilename == "-") {
+ Out = &outs(); // Default to printing to stdout...
+ DeleteStream = false;
+ } else {
if (NoOutput || AnalyzeOnly) {
errs() << "WARNING: The -o (output filename) option is ignored when\n"
"the --disable-output or --analyze options are used.\n";
@@ -540,7 +544,7 @@
Passes.run(*M.get());
// Delete the raw_fd_ostream.
- if (Out != &outs())
+ if (DeleteStream)
delete Out;
return 0;
}