diff options
author | Reid Kleckner <rnk@google.com> | 2019-10-04 18:57:01 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2019-10-04 18:57:01 +0000 |
commit | cfe3bf89c2962d5f121450659669b9d469dc8b97 (patch) | |
tree | 104df98f8104099af8f8203242d8218507f6f74c | |
parent | ce452b1ca9fdb12604db3dc2059246e189e55d7b (diff) | |
download | bcm5719-llvm-cfe3bf89c2962d5f121450659669b9d469dc8b97.tar.gz bcm5719-llvm-cfe3bf89c2962d5f121450659669b9d469dc8b97.zip |
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
-rw-r--r-- | clang/tools/driver/cc1_main.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index 8ab713fd295..acf6cd1e537 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -258,19 +258,20 @@ int cc1_main(ArrayRef<const char *> 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 |