From: Nathan Sidwell Date: Fri, 11 Dec 2020 16:22:57 +0000 (-0800) Subject: c++: cp_tree_equal tweaks X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=059da609fa8b3a08d1d6618f9d90dc3cfbcd05bc;p=gcc.git c++: cp_tree_equal tweaks When comparing streamed trees we can encounter NON_LVALUE_EXPR and VIEW_CONVERT_EXPRs with null types. Also, when checking a potential duplicate we don't want to reject PARM_DECLs with different contexts, if those two contexts are the two decls of interest. gcc/cp/ * cp-tree.h (map_context_from, map_context_to): Declare. * module.cc (map_context_from, map_context_to): Define. * tree.c (cp_tree_equal): Check map_context_{from,to} for parm context difference. Allow NON_LVALUE_EXPR and VIEW_CONVERT_EXPR with null types. --- diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 63170fc013d..f2a01d25d0c 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5454,6 +5454,10 @@ extern int function_depth; in structrual_comptypes. */ extern int comparing_specializations; +/* When comparing specializations permit context _FROM to match _TO. */ +extern tree map_context_from; +extern tree map_context_to; + /* In parser.c. */ /* Nonzero if we are parsing an unevaluated operand: an operand to diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 02b5af81189..2417d67ee41 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -65,6 +65,11 @@ along with GCC; see the file COPYING3. If not see #include "intl.h" #include "langhooks.h" +/* During duplicate detection we need to tell some comparators that + these are equivalent. */ +tree map_context_from; +tree map_context_to; + /* Id for dumping module information. */ int module_dump_id; diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index d9fa505041f..0584a7b725e 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3837,7 +3837,12 @@ cp_tree_equal (tree t1, tree t2) template. */ if (comparing_specializations - && DECL_CONTEXT (t1) != DECL_CONTEXT (t2)) + && DECL_CONTEXT (t1) != DECL_CONTEXT (t2) + /* Module duplicate checking can have t1 = new, t2 = + existing, and they should be considered matching at this + point. */ + && (DECL_CONTEXT (t1) != map_context_from + && DECL_CONTEXT (t2) != map_context_to)) /* When comparing hash table entries, only an exact match is good enough; we don't want to replace 'this' with the version from another function. But be more flexible @@ -3974,6 +3979,17 @@ cp_tree_equal (tree t1, tree t2) return same_type_p (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2)) && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2)); + case NON_LVALUE_EXPR: + case VIEW_CONVERT_EXPR: + /* Used for location wrappers with possibly NULL types. */ + if (!TREE_TYPE (t1) || !TREE_TYPE (t2)) + { + if (TREE_TYPE (t1) || TREE_TYPE (t2)) + return false; + break; + } + /* FALLTHROUGH */ + case CAST_EXPR: case STATIC_CAST_EXPR: case REINTERPRET_CAST_EXPR: @@ -3981,10 +3997,8 @@ cp_tree_equal (tree t1, tree t2) case DYNAMIC_CAST_EXPR: case IMPLICIT_CONV_EXPR: case NEW_EXPR: - CASE_CONVERT: - case NON_LVALUE_EXPR: - case VIEW_CONVERT_EXPR: case BIT_CAST_EXPR: + CASE_CONVERT: if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))) return false; /* Now compare operands as usual. */