diff mbox series

c++: cp_tree_equal tweaks

Message ID 4ec87f90-9343-3ddf-c2da-a566c13d2755@acm.org
State New
Headers show
Series c++: cp_tree_equal tweaks | expand

Commit Message

Nathan Sidwell Dec. 11, 2020, 4:27 p.m. UTC
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.

pushing to trunk
diff mbox series

Patch

diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h
index 63170fc013d..f2a01d25d0c 100644
--- i/gcc/cp/cp-tree.h
+++ w/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 i/gcc/cp/module.cc w/gcc/cp/module.cc
index 02b5af81189..2417d67ee41 100644
--- i/gcc/cp/module.cc
+++ w/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 i/gcc/cp/tree.c w/gcc/cp/tree.c
index d9fa505041f..0584a7b725e 100644
--- i/gcc/cp/tree.c
+++ w/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.  */