From cfe3bf89c2962d5f121450659669b9d469dc8b97 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 4 Oct 2019 18:57:01 +0000 Subject: [PATCH] Add missing null pointer check in -ftime-trace code createOutputFile diagnoses the error for the caller already, so recover by not writing the output. Fixes PR43555 No test, since I couldn't think of a good, portable, simple way to make the regular -o output file writable, but outputfile.json not writable. llvm-svn: 373771 --- clang/tools/driver/cc1_main.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index 8ab713f..acf6cd1 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -258,19 +258,20 @@ int cc1_main(ArrayRef Argv, const char *Argv0, void *MainAddr) { if (llvm::timeTraceProfilerEnabled()) { SmallString<128> Path(Clang->getFrontendOpts().OutputFile); llvm::sys::path::replace_extension(Path, "json"); - auto profilerOutput = - Clang->createOutputFile(Path.str(), - /*Binary=*/false, - /*RemoveFileOnSignal=*/false, "", - /*Extension=*/"json", - /*useTemporary=*/false); - - llvm::timeTraceProfilerWrite(*profilerOutput); - // FIXME(ibiryukov): make profilerOutput flush in destructor instead. - profilerOutput->flush(); - llvm::timeTraceProfilerCleanup(); - - llvm::errs() << "Time trace json-file dumped to " << Path.str() << "\n"; + if (auto profilerOutput = + Clang->createOutputFile(Path.str(), + /*Binary=*/false, + /*RemoveFileOnSignal=*/false, "", + /*Extension=*/"json", + /*useTemporary=*/false)) { + + llvm::timeTraceProfilerWrite(*profilerOutput); + // FIXME(ibiryukov): make profilerOutput flush in destructor instead. + profilerOutput->flush(); + llvm::timeTraceProfilerCleanup(); + + llvm::errs() << "Time trace json-file dumped to " << Path.str() << "\n"; + } } // Our error handler depends on the Diagnostics object, which we're -- 2.7.4