Allow TextDiagnosticPrinter to have optional ownership of its output stream.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86823 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index e31f5a6..e0ca9cf 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -517,31 +517,27 @@
llvm::cl::value_desc("filename"),
llvm::cl::desc("output a dump of some build information to a file"));
-static llvm::raw_ostream *BuildLogFile = 0;
-
static void SetUpBuildDumpLog(const DiagnosticOptions &DiagOpts,
unsigned argc, char **argv,
llvm::OwningPtr<DiagnosticClient> &DiagClient) {
std::string ErrorInfo;
- BuildLogFile = new llvm::raw_fd_ostream(DumpBuildInformation.c_str(),
- ErrorInfo);
-
+ llvm::raw_ostream *OS = new llvm::raw_fd_ostream(DumpBuildInformation.c_str(),
+ ErrorInfo);
if (!ErrorInfo.empty()) {
llvm::errs() << "error opening -dump-build-information file '"
<< DumpBuildInformation << "', option ignored!\n";
- delete BuildLogFile;
- BuildLogFile = 0;
- DumpBuildInformation = "";
+ delete OS;
return;
}
- (*BuildLogFile) << "clang-cc command line arguments: ";
+ (*OS) << "clang-cc command line arguments: ";
for (unsigned i = 0; i != argc; ++i)
- (*BuildLogFile) << argv[i] << ' ';
- (*BuildLogFile) << '\n';
+ (*OS) << argv[i] << ' ';
+ (*OS) << '\n';
// Chain in a diagnostic client which will log the diagnostics.
- DiagnosticClient *Logger = new TextDiagnosticPrinter(*BuildLogFile, DiagOpts);
+ DiagnosticClient *Logger =
+ new TextDiagnosticPrinter(*OS, DiagOpts, /*OwnsOutputStream=*/true);
DiagClient.reset(new ChainedDiagnosticClient(DiagClient.take(), Logger));
}
@@ -1316,7 +1312,6 @@
}
delete ClangFrontendTimer;
- delete BuildLogFile;
// If verifying diagnostics and we reached here, all is well.
if (VerifyDiagnostics)