From: Torbjörn SVENSSON <[email protected]>

gcc/cp/ChangeLog:

        PR c++/124806
        * module.cc (late_finish_module): Fix nullptr dereference.

Signed-off-by: Torbjörn SVENSSON <[email protected]>
---
 gcc/cp/module.cc | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index f7569e688a26..b97276bd09ec 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -24006,29 +24006,32 @@ late_finish_module (cpp_reader *reader,  
module_processing_cookie *cookie,
 
   cookie->config.active_init = init_fn_non_empty;
   if (cookie->began)
-    state->write_end (&cookie->out, reader, cookie->config, cookie->crc);
-
-  if (cookie->out.end () && cookie->cmi_name)
     {
-      /* Some OS's do not replace NEWNAME if it already exists.
-        This'll have a race condition in erroneous concurrent
-        builds.  */
-      unlink (cookie->cmi_name);
-      if (rename (cookie->tmp_name, cookie->cmi_name))
+      state->write_end (&cookie->out, reader, cookie->config, cookie->crc);
+
+      if (cookie->out.end () && cookie->cmi_name)
        {
-         dump () && dump ("Rename ('%s','%s') errno=%u",
-                          cookie->tmp_name, cookie->cmi_name, errno);
-         cookie->out.set_error (errno);
+         /* Some OS's do not replace NEWNAME if it already exists.
+            This'll have a race condition in erroneous concurrent
+            builds.  */
+         unlink (cookie->cmi_name);
+         if (rename (cookie->tmp_name, cookie->cmi_name))
+           {
+             dump () && dump ("Rename ('%s','%s') errno=%u",
+                              cookie->tmp_name, cookie->cmi_name, errno);
+             cookie->out.set_error (errno);
+           }
        }
-    }
 
-  if (cookie->out.get_error () && cookie->began)
-    {
-      error_at (state->loc, "failed to write compiled module: %s",
-               cookie->out.get_error (state->filename));
-      state->note_cmi_name ();
+       if (cookie->out.get_error ())
+         {
+           error_at (state->loc, "failed to write compiled module: %s",
+                     cookie->out.get_error (state->filename));
+           state->note_cmi_name ();
+         }
     }
 
+
   if (!errorcount)
     {
       auto *mapper = get_mapper (cpp_main_loc (reader), cpp_get_deps (reader));
-- 
2.54.0

Reply via email to