Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

Building std.compat.cc was crashing for me because we would first get a
pointer into imported_temploid_friends, then insert a new entry, causing the
hash_map to expand, and then dereference the pointer into the former
location of the hash table.  Fixed by dereferencing the pointer before
inserting rather than after.

gcc/cp/ChangeLog:

        * module.cc (transfer_defining_module): Dereference
        pointer into hash_map before possible insertion.
---
 gcc/cp/module.cc | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 1578674614e..11b5242c55a 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -21811,17 +21811,18 @@ transfer_defining_module (tree olddecl, tree newdecl)
        DECL_MODULE_IMPORT_P (old_inner) = false;
     }
 
-  if (tree *orig = imported_temploid_friends->get (newdecl))
+  if (tree *p = imported_temploid_friends->get (newdecl))
     {
+      tree orig = *p;
       tree &slot = imported_temploid_friends->get_or_insert (olddecl);
       if (!slot)
-       slot = *orig;
-      else if (slot != *orig)
+       slot = orig;
+      else if (slot != orig)
        /* This can happen when multiple classes declare the same
           friend function (e.g. g++.dg/modules/tpl-friend-4);
           make sure we at least attach to the same module.  */
        gcc_checking_assert (get_originating_module (slot)
-                            == get_originating_module (*orig));
+                            == get_originating_module (orig));
     }
 }
 

base-commit: 2359344af53a5fc844d108fcf9f0e8bddd84a6b5
prerequisite-patch-id: 97ff08dddfd2b7dac54f2341eb0ef7f8009a8313
-- 
2.51.0

Reply via email to