Index: cp/cp-objcp-common.c =================================================================== --- cp/cp-objcp-common.c (revision 251538) +++ cp/cp-objcp-common.c (working copy) @@ -131,6 +131,20 @@ cxx_types_compatible_p (tree x, tree y) return same_type_ignoring_top_level_qualifiers_p (x, y); } +struct offset_type_hasher : ggc_cache_ptr_hash +{ + static hashval_t hash (tree_map *m) { return tree_map_hash (m); } + static bool equal (tree_map *a, tree_map *b) { return tree_map_eq (a, b); } + + static int + keep_cache_entry (tree_map *&e) + { + return ggc_marked_p (e->base.from); + } +}; + +static GTY((cache)) hash_table *offset_type_hash; + /* Return a type to use in the debug info instead of TYPE, or NULL_TREE to keep TYPE. */ @@ -138,8 +152,35 @@ tree cp_get_debug_type (const_tree type) { if (TYPE_PTRMEMFUNC_P (type) && !typedef_variant_p (type)) - return build_offset_type (TYPE_PTRMEMFUNC_OBJECT_TYPE (type), - TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))); + { + if (offset_type_hash == NULL) + offset_type_hash = hash_table::create_ggc (512); + + /* We cannot simply use build_offset_type here because the function uses + the type canonicalization hashtable, which is GC-ed, so its behavior + depends on the actual collection points. Since we are building these + types on the fly for the debug info only, they would not be attached + to any GC root and always be swept, so we would make the contents of + the debug info depend on the collection points. */ + struct tree_map in, *h; + + in.base.from = CONST_CAST_TREE (type); + in.hash = htab_hash_pointer (type); + h = offset_type_hash->find_with_hash (&in, in.hash); + if (h) + return h->to; + + tree t = build_offset_type (TYPE_PTRMEMFUNC_OBJECT_TYPE (type), + TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))); + + h = ggc_alloc (); + h->base.from = CONST_CAST_TREE (type); + h->hash = htab_hash_pointer (type); + h->to = t; + *offset_type_hash->find_slot_with_hash (h, h->hash, INSERT) = h; + + return t; + } return NULL_TREE; }