diff options
author | Seyed Sajad Kahani <sska1377@gmail.com> | 2024-07-18 16:01:32 +0100 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2024-07-18 22:30:08 -0400 |
commit | 0f8261eae068850c8c48400159fc0a5b540d4d53 (patch) | |
tree | 4fb5e53a4fc7036eb03d6a63a45f8cd2759ddadd /gcc/cp/pt.cc | |
parent | 02cc8494745c4235890ad58e93b5acce5a89a775 (diff) | |
download | gcc-0f8261eae068850c8c48400159fc0a5b540d4d53.zip gcc-0f8261eae068850c8c48400159fc0a5b540d4d53.tar.gz gcc-0f8261eae068850c8c48400159fc0a5b540d4d53.tar.bz2 |
c++: Hash placeholder constraint in ctp_hasher
This patch addresses a difference between the hash function and the equality
function for canonical types of template parameters (ctp_hasher). The equality
function uses comptypes (typeck.cc) (with COMPARE_STRUCTURAL) and checks
constraint equality for two auto nodes (typeck.cc:1586), while the hash
function ignores it (pt.cc:4528). This leads to hash collisions that can be
avoided by using `hash_placeholder_constraint` (constraint.cc:1150).
Note that due to the proper handling of hash collisions (hash-table.h:1059),
there is no test case that can distinguish the current implementation from the
proposed one.
* constraint.cc (hash_placeholder_constraint): Rename to
iterative_hash_placeholder_constraint.
(iterative_hash_placeholder_constraint): Rename from
hash_placeholder_constraint and add the initial val argument.
* cp-tree.h (hash_placeholder_constraint): Rename to
iterative_hash_placeholder_constraint.
(iterative_hash_placeholder_constraint): Renamed from
hash_placeholder_constraint and add the initial val argument.
* pt.cc (struct ctp_hasher): Updated to use
iterative_hash_placeholder_constraint in the case of a valid placeholder
constraint.
(auto_hash::hash): Reflect the renaming of hash_placeholder_constraint to
iterative_hash_placeholder_constraint.
Diffstat (limited to 'gcc/cp/pt.cc')
-rw-r--r-- | gcc/cp/pt.cc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 057797f..108e929b 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -4500,7 +4500,12 @@ struct ctp_hasher : ggc_ptr_hash<tree_node> val = iterative_hash_object (TEMPLATE_TYPE_LEVEL (t), val); val = iterative_hash_object (TEMPLATE_TYPE_IDX (t), val); if (TREE_CODE (t) == TEMPLATE_TYPE_PARM) - val = iterative_hash_template_arg (CLASS_PLACEHOLDER_TEMPLATE (t), val); + { + val + = iterative_hash_template_arg (CLASS_PLACEHOLDER_TEMPLATE (t), val); + if (tree c = NON_ERROR (PLACEHOLDER_TYPE_CONSTRAINTS (t))) + val = iterative_hash_placeholder_constraint (c, val); + } if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM) val = iterative_hash_template_arg (TYPE_TI_ARGS (t), val); --comparing_specializations; @@ -29581,7 +29586,7 @@ auto_hash::hash (tree t) if (tree c = NON_ERROR (PLACEHOLDER_TYPE_CONSTRAINTS (t))) /* Matching constrained-type-specifiers denote the same template parameter, so hash the constraint. */ - return hash_placeholder_constraint (c); + return iterative_hash_placeholder_constraint (c, 0); else /* But unconstrained autos are all separate, so just hash the pointer. */ return iterative_hash_object (t, 0); |