]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: fix hash_map issue
authorJason Merrill <jason@redhat.com>
Fri, 14 Nov 2025 12:22:57 +0000 (17:52 +0530)
committerJason Merrill <jason@redhat.com>
Sat, 15 Nov 2025 06:12:21 +0000 (11:42 +0530)
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

index 1578674614e78da7828bfb91cd7f9d3b42e39bb3..11b5242c55a8aae5f3387fbeec023b3d893c776f 100644 (file)
@@ -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));
     }
 }