Author: rnk
Date: Fri Oct  4 11:57:01 2019
New Revision: 373771

URL: http://llvm.org/viewvc/llvm-project?rev=373771&view=rev
Log:
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.

Modified:
    cfe/trunk/tools/driver/cc1_main.cpp

Modified: cfe/trunk/tools/driver/cc1_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=373771&r1=373770&r2=373771&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Fri Oct  4 11:57:01 2019
@@ -258,19 +258,20 @@ int cc1_main(ArrayRef<const char *> Argv
   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);
+    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::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";
+      llvm::errs() << "Time trace json-file dumped to " << Path.str() << "\n";
+    }
   }
 
   // Our error handler depends on the Diagnostics object, which we're


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to