From df418f1d3cba53a4d3d20c2f640a250dd4c1bfa3 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 22 Nov 2019 22:38:44 +0100 Subject: [PATCH] re PR c++/92458 (Constraints do not work with precompiled headers) PR c++/92458 * tree-hash-traits.h (tree_decl_hash, tree_ssa_name_hash, tree_hash): Move to ... * tree.h (tree_decl_hash, tree_ssa_name_hash, tree_hash): ... here. (struct decl_tree_cache_traits, struct type_tree_cache_traits): New types. (decl_tree_cache_map, tree_tree_cache_map): New typedefs. * init.c (nsdmi_inst): Change type to decl_tree_cache_map * from tree_cache_map *. * constraint.cc (decl_constraints): Likewise. * decl.c (get_tuple_decomp_init): Likewise. * pt.c (defarg_inst, explicit_specifier_map): Likewise. (tsubst_default_argument, store_explicit_specifier): Use decl_tree_cache_map::create_ggc rather than tree_cache_map::create_ggc. * cp-objcp-common.c (debug_type_map): Change type to type_tree_cache_map * from tree_cache_map *. * g++.dg/pch/pr92458.C: New test. * g++.dg/pch/pr92458.Hs: New test. From-SVN: r278633 --- gcc/ChangeLog | 8 ++++ gcc/cp/ChangeLog | 14 +++++++ gcc/cp/constraint.cc | 2 +- gcc/cp/cp-objcp-common.c | 2 +- gcc/cp/decl.c | 2 +- gcc/cp/init.c | 2 +- gcc/cp/pt.c | 8 ++-- gcc/testsuite/ChangeLog | 6 +++ gcc/testsuite/g++.dg/pch/pr92458.C | 5 +++ gcc/testsuite/g++.dg/pch/pr92458.Hs | 7 ++++ gcc/tree-hash-traits.h | 40 ------------------ gcc/tree.h | 64 +++++++++++++++++++++++++++++ 12 files changed, 112 insertions(+), 48 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pch/pr92458.C create mode 100644 gcc/testsuite/g++.dg/pch/pr92458.Hs diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7f7dd0006f2..6ed7abaa343 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,13 @@ 2019-11-22 Jakub Jelinek + PR c++/92458 + * tree-hash-traits.h (tree_decl_hash, tree_ssa_name_hash, + tree_hash): Move to ... + * tree.h (tree_decl_hash, tree_ssa_name_hash, tree_hash): ... here. + (struct decl_tree_cache_traits, struct type_tree_cache_traits): New + types. + (decl_tree_cache_map, tree_tree_cache_map): New typedefs. + PR tree-optimization/92618 * tree-ssa-reassoc.c (v_info): Change from auto_vec to a struct containing the auto_vec and a tree. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cd1cd17ca4a..93cf9e95f71 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,17 @@ +2019-11-22 Jakub Jelinek + + PR c++/92458 + * init.c (nsdmi_inst): Change type to + decl_tree_cache_map * from tree_cache_map *. + * constraint.cc (decl_constraints): Likewise. + * decl.c (get_tuple_decomp_init): Likewise. + * pt.c (defarg_inst, explicit_specifier_map): Likewise. + (tsubst_default_argument, store_explicit_specifier): Use + decl_tree_cache_map::create_ggc rather than + tree_cache_map::create_ggc. + * cp-objcp-common.c (debug_type_map): Change type to + type_tree_cache_map * from tree_cache_map *. + 2019-11-21 Marek Polacek PR c++/92450 - ICE with invalid nested name specifier. diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 00b59a90868..171ca4e0ed4 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -1113,7 +1113,7 @@ build_constraints (tree tr, tree dr) /* A mapping from declarations to constraint information. */ -static GTY ((cache)) tree_cache_map *decl_constraints; +static GTY ((cache)) decl_tree_cache_map *decl_constraints; /* Returns the template constraints of declaration T. If T is not constrained, return NULL_TREE. Note that T must be non-null. */ diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index b9bc2c6592c..d168e2a802f 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -123,7 +123,7 @@ cxx_types_compatible_p (tree x, tree y) return same_type_ignoring_top_level_qualifiers_p (x, y); } -static GTY((cache)) tree_cache_map *debug_type_map; +static GTY((cache)) type_tree_cache_map *debug_type_map; /* Return a type to use in the debug info instead of TYPE, or NULL_TREE to keep TYPE. */ diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 86e38f4af69..26120720f07 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7998,7 +7998,7 @@ get_tuple_decomp_init (tree decl, unsigned i) /* It's impossible to recover the decltype of a tuple decomposition variable based on the actual type of the variable, so store it in a hash table. */ -static GTY((cache)) tree_cache_map *decomp_type_table; +static GTY((cache)) decl_tree_cache_map *decomp_type_table; tree lookup_decomp_type (tree v) diff --git a/gcc/cp/init.c b/gcc/cp/init.c index c620b05fe07..aa48f80e58d 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -548,7 +548,7 @@ perform_target_ctor (tree init) /* Return the non-static data initializer for FIELD_DECL MEMBER. */ -static GTY((cache)) tree_cache_map *nsdmi_inst; +static GTY((cache)) decl_tree_cache_map *nsdmi_inst; tree get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 064fe5be8b2..78b78bab74d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -13272,7 +13272,7 @@ tsubst_aggr_type (tree t, } } -static GTY((cache)) tree_cache_map *defarg_inst; +static GTY((cache)) decl_tree_cache_map *defarg_inst; /* Substitute into the default argument ARG (a default argument for FN), which has the indicated TYPE. */ @@ -13346,7 +13346,7 @@ tsubst_default_argument (tree fn, int parmnum, tree type, tree arg, if (arg != error_mark_node && !cp_unevaluated_operand) { if (!defarg_inst) - defarg_inst = tree_cache_map::create_ggc (37); + defarg_inst = decl_tree_cache_map::create_ggc (37); defarg_inst->put (parm, arg); } @@ -13383,7 +13383,7 @@ tsubst_default_arguments (tree fn, tsubst_flags_t complain) } /* Hash table mapping a FUNCTION_DECL to its dependent explicit-specifier. */ -static GTY((cache)) tree_cache_map *explicit_specifier_map; +static GTY((cache)) decl_tree_cache_map *explicit_specifier_map; /* Store a pair to EXPLICIT_SPECIFIER_MAP. */ @@ -13391,7 +13391,7 @@ void store_explicit_specifier (tree v, tree t) { if (!explicit_specifier_map) - explicit_specifier_map = tree_cache_map::create_ggc (37); + explicit_specifier_map = decl_tree_cache_map::create_ggc (37); DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (v) = true; explicit_specifier_map->put (v, t); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1f61bc3e72f..6f8c791d776 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-11-22 Jakub Jelinek + + PR c++/92458 + * g++.dg/pch/pr92458.C: New test. + * g++.dg/pch/pr92458.Hs: New test. + 2019-11-22 Iain Sandoe * gcc.target/i386/pr27971.c: Use mdynamic-no-pic for m32 on diff --git a/gcc/testsuite/g++.dg/pch/pr92458.C b/gcc/testsuite/g++.dg/pch/pr92458.C new file mode 100644 index 00000000000..a750599be1a --- /dev/null +++ b/gcc/testsuite/g++.dg/pch/pr92458.C @@ -0,0 +1,5 @@ +// PR c++/92458 +// { dg-options "-std=c++2a" } + +#include "pr92458.H" +S s; diff --git a/gcc/testsuite/g++.dg/pch/pr92458.Hs b/gcc/testsuite/g++.dg/pch/pr92458.Hs new file mode 100644 index 00000000000..b81ea634e23 --- /dev/null +++ b/gcc/testsuite/g++.dg/pch/pr92458.Hs @@ -0,0 +1,7 @@ +// PR c++/92458 +// { dg-options "-std=c++2a" } + +template concept C = sizeof(T) > 1; +template struct S { }; +template requires C struct S { }; +template requires (!C) struct S { }; diff --git a/gcc/tree-hash-traits.h b/gcc/tree-hash-traits.h index a3fc0249093..8c2a839c4fe 100644 --- a/gcc/tree-hash-traits.h +++ b/gcc/tree-hash-traits.h @@ -41,44 +41,4 @@ tree_operand_hash::equal (const value_type &t1, return operand_equal_p (t1, t2, 0); } -/* Hasher for tree decls. Pointer equality is enough here, but the DECL_UID - is a better hash than the pointer value and gives a predictable traversal - order. */ -struct tree_decl_hash : ggc_ptr_hash -{ - static inline hashval_t hash (tree); -}; - -inline hashval_t -tree_decl_hash::hash (tree t) -{ - return DECL_UID (t); -} - -/* Hash for SSA_NAMEs in the same function. Pointer equality is enough - here, but the SSA_NAME_VERSION is a better hash than the pointer - value and gives a predictable traversal order. */ -struct tree_ssa_name_hash : ggc_ptr_hash -{ - static inline hashval_t hash (tree); -}; - -inline hashval_t -tree_ssa_name_hash::hash (tree t) -{ - return SSA_NAME_VERSION (t); -} - -/* Hasher for general trees, based on their TREE_HASH. */ -struct tree_hash : ggc_ptr_hash -{ - static hashval_t hash (tree); -}; - -inline hashval_t -tree_hash::hash (tree t) -{ - return TREE_HASH (t); -} - #endif diff --git a/gcc/tree.h b/gcc/tree.h index 89114e227d8..60b6eae7b04 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -5351,6 +5351,58 @@ struct tree_decl_map_cache_hasher : ggc_cache_ptr_hash #define tree_vec_map_hash tree_decl_map_hash #define tree_vec_map_marked_p tree_map_base_marked_p +/* Hasher for tree decls. Pointer equality is enough here, but the DECL_UID + is a better hash than the pointer value and gives a predictable traversal + order. Additionally it can be used across PCH save/restore. */ +struct tree_decl_hash : ggc_ptr_hash +{ + static inline hashval_t hash (tree); +}; + +inline hashval_t +tree_decl_hash::hash (tree t) +{ + return DECL_UID (t); +} + +/* Similarly for types. Uses TYPE_UID as hash function. */ +struct tree_type_hash : ggc_ptr_hash +{ + static inline hashval_t hash (tree); +}; + +inline hashval_t +tree_type_hash::hash (tree t) +{ + return TYPE_UID (t); +} + +/* Hash for SSA_NAMEs in the same function. Pointer equality is enough + here, but the SSA_NAME_VERSION is a better hash than the pointer + value and gives a predictable traversal order. */ +struct tree_ssa_name_hash : ggc_ptr_hash +{ + static inline hashval_t hash (tree); +}; + +inline hashval_t +tree_ssa_name_hash::hash (tree t) +{ + return SSA_NAME_VERSION (t); +} + +/* Hasher for general trees, based on their TREE_HASH. */ +struct tree_hash : ggc_ptr_hash +{ + static hashval_t hash (tree); +}; + +inline hashval_t +tree_hash::hash (tree t) +{ + return TREE_HASH (t); +} + /* A hash_map of two trees for use with GTY((cache)). Garbage collection for such a map will not mark keys, and will mark values if the key is already marked. */ @@ -5358,6 +5410,18 @@ struct tree_cache_traits : simple_cache_map_traits, tree> { }; typedef hash_map tree_cache_map; +/* Similarly, but use DECL_UID as hash function rather than pointer hashing. + This is for hash_maps from decls to trees that need to work across PCH. */ +struct decl_tree_cache_traits + : simple_cache_map_traits { }; +typedef hash_map decl_tree_cache_map; + +/* Similarly, but use TYPE_UID as hash function rather than pointer hashing. + This is for hash_maps from types to trees that need to work across PCH. */ +struct type_tree_cache_traits + : simple_cache_map_traits { }; +typedef hash_map type_tree_cache_map; + /* Initialize the abstract argument list iterator object ITER with the arguments from CALL_EXPR node EXP. */ static inline void -- 2.30.2