From 444655b6f02605ae936426a14ba527795795587b Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 3 Nov 2020 05:11:42 -0800 Subject: [PATCH] c++: cp_tree_equal cleanups A couple of small fixes. I noticed bind_template_template_parms was not marking the parm a template parm (this broke some module handling). Debugging CALL_EXPR comparisons led me to refactor cp_tree_equal's CALL_EXPR code (and my recent fix to debug printing of same). Finally TREE_VECS are best compared by comp_template_args. I recall that last piece being a left over from fixes during gcc-10. I've been using it on the modules branch since then. gcc/cp/ * tree.c (bind_template_template_parm): Mark the parm as a template parm. (cp_tree_equal): Refactor CALL_EXPR. Use comp_template_args for TREE_VECs. --- gcc/cp/tree.c | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 9bc37aca95b..3087c4ab52c 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2700,6 +2700,7 @@ bind_template_template_parm (tree t, tree newargs) t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM); decl = build_decl (input_location, TYPE_DECL, DECL_NAME (decl), NULL_TREE); + SET_DECL_TEMPLATE_PARM_P (decl); /* These nodes have to be created to reflect new TYPE_DECL and template arguments. */ @@ -3671,20 +3672,28 @@ cp_tree_equal (tree t1, tree t2) case CALL_EXPR: { - tree arg1, arg2; - call_expr_arg_iterator iter1, iter2; - if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2) - || !called_fns_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2))) + if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2)) return false; - for (arg1 = first_call_expr_arg (t1, &iter1), - arg2 = first_call_expr_arg (t2, &iter2); - arg1 && arg2; - arg1 = next_call_expr_arg (&iter1), - arg2 = next_call_expr_arg (&iter2)) - if (!cp_tree_equal (arg1, arg2)) - return false; - if (arg1 || arg2) + + if (!called_fns_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2))) + return false; + + call_expr_arg_iterator iter1, iter2; + init_call_expr_arg_iterator (t1, &iter1); + init_call_expr_arg_iterator (t2, &iter2); + if (iter1.n != iter2.n) return false; + + while (more_call_expr_args_p (&iter1)) + { + tree arg1 = next_call_expr_arg (&iter1); + tree arg2 = next_call_expr_arg (&iter2); + + gcc_checking_assert (arg1 && arg2); + if (!cp_tree_equal (arg1, arg2)) + return false; + } + return true; } @@ -3779,16 +3788,11 @@ cp_tree_equal (tree t1, tree t2) CHECK_CONSTR_ARGS (t2))); case TREE_VEC: - { - unsigned ix; - if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2)) - return false; - for (ix = TREE_VEC_LENGTH (t1); ix--;) - if (!cp_tree_equal (TREE_VEC_ELT (t1, ix), - TREE_VEC_ELT (t2, ix))) - return false; - return true; - } + /* These are template args. Really we should be getting the + caller to do this as it knows it to be true. */ + if (!comp_template_args (t1, t2, NULL, NULL, false)) + return false; + return true; case SIZEOF_EXPR: case ALIGNOF_EXPR: -- 2.30.2