summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2025-11-14 17:52:57 +0530
committerJason Merrill <jason@redhat.com>2025-11-15 11:42:21 +0530
commit4b84e561856599f82ce8f12a876ade388d5db330 (patch)
tree43fb25cc5d3eacb74a90befbca7196b6ab508f6d
parentfeccb9c9cd6ccab3fa75e2ca3f533e02de15750f (diff)
c++/modules: fix hash_map issue
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.
-rw-r--r--gcc/cp/module.cc9
1 files 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));
}
}