diff mbox

[PR,debug/45130] fix MEM_REF -fcompare-debug regression

Message ID orhbhzkio7.fsf@livre.localdomain
State New
Headers show

Commit Message

Alexandre Oliva Sept. 8, 2010, 9:51 p.m. UTC
On Sep  7, 2010, Richard Guenther <richard.guenther@gmail.com> wrote:

> +       /* The type of the second operand is irrelevant, except for
> +          its top-level qualifiers.  */
> +       val = iterative_hash_object (TYPE_HASH (type), val);

> I suppose this was to be "The type of the second operand is relevant, ..."

> Ok with that change.

Thanks.  I had to apply a similar fix to the code that dumps MEM_REFs
within COMPONENT_REFs, that I'm going ahead and checking in as obvious.

Here's the complete patch.

Comments

H.J. Lu Sept. 9, 2010, 12:33 a.m. UTC | #1
On Wed, Sep 8, 2010 at 2:51 PM, Alexandre Oliva <aoliva@redhat.com> wrote:
> On Sep  7, 2010, Richard Guenther <richard.guenther@gmail.com> wrote:
>
>> +       /* The type of the second operand is irrelevant, except for
>> +          its top-level qualifiers.  */
>> +       val = iterative_hash_object (TYPE_HASH (type), val);
>
>> I suppose this was to be "The type of the second operand is relevant, ..."
>
>> Ok with that change.
>
> Thanks.  I had to apply a similar fix to the code that dumps MEM_REFs
> within COMPONENT_REFs, that I'm going ahead and checking in as obvious.
>
> Here's the complete patch.
>
>

This may have caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45604
diff mbox

Patch

for gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR debug/45419
	PR debug/45408
	* tree-pretty-print.c (dump_generic_node): Disregard top-level
	qualifiers in otherwise equal MEM_REF pointer types.
	* fold-const.c (operand_equal_p): Compare pointer type of MEM_REFs.
	* tree.c (iterative_hash_expr): Hash the pointer type of MEM_REFs.

Index: gcc/tree-pretty-print.c
===================================================================
--- gcc/tree-pretty-print.c.orig	2010-09-06 14:50:54.291300126 -0300
+++ gcc/tree-pretty-print.c	2010-09-07 17:06:00.000000000 -0300
@@ -807,8 +807,8 @@  dump_generic_node (pretty_printer *buffe
 		== TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 1))))
 	    && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 0)))
 		== TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 1))))
-	    && (TYPE_QUALS (TREE_TYPE (TREE_OPERAND (node, 0)))
-		== TYPE_QUALS (TREE_TYPE (TREE_OPERAND (node, 1))))
+	    && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (node, 0)))
+		== TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (node, 1))))
 	    /* Same value types ignoring qualifiers.  */
 	    && (TYPE_MAIN_VARIANT (TREE_TYPE (node))
 		== TYPE_MAIN_VARIANT
@@ -827,9 +827,12 @@  dump_generic_node (pretty_printer *buffe
 	  }
 	else
 	  {
+	    tree ptype;
+
 	    pp_string (buffer, "MEM[");
 	    pp_string (buffer, "(");
-	    dump_generic_node (buffer, TREE_TYPE (TREE_OPERAND (node, 1)),
+	    ptype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (node, 1)));
+	    dump_generic_node (buffer, ptype,
 			       spc, flags | TDF_SLIM, false);
 	    pp_string (buffer, ")");
 	    dump_generic_node (buffer, TREE_OPERAND (node, 0),
@@ -1161,8 +1164,8 @@  dump_generic_node (pretty_printer *buffe
 		      == TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 1))))
 		  && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 0)))
 		      == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 1))))
-		  && (TYPE_QUALS (TREE_TYPE (TREE_OPERAND (op0, 0)))
-		      == TYPE_QUALS (TREE_TYPE (TREE_OPERAND (op0, 1))))
+		  && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (op0, 0)))
+		      == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (op0, 1))))
 		  /* Same value types ignoring qualifiers.  */
 		  && (TYPE_MAIN_VARIANT (TREE_TYPE (op0))
 		      == TYPE_MAIN_VARIANT
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c.orig	2010-09-06 14:50:54.313302817 -0300
+++ gcc/fold-const.c	2010-09-06 14:50:58.000000000 -0300
@@ -2593,14 +2593,17 @@  operand_equal_p (const_tree arg0, const_
 	  return OP_SAME (0);
 
 	case MEM_REF:
-	  /* Require equal access sizes.  We can have incomplete types
-	     for array references of variable-sized arrays from the
-	     Fortran frontent though.  */
+	  /* Require equal access sizes, and similar pointer types.
+	     We can have incomplete types for array references of
+	     variable-sized arrays from the Fortran frontent
+	     though.  */
 	  return ((TYPE_SIZE (TREE_TYPE (arg0)) == TYPE_SIZE (TREE_TYPE (arg1))
 		   || (TYPE_SIZE (TREE_TYPE (arg0))
 		       && TYPE_SIZE (TREE_TYPE (arg1))
 		       && operand_equal_p (TYPE_SIZE (TREE_TYPE (arg0)),
 					   TYPE_SIZE (TREE_TYPE (arg1)), flags)))
+		  && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg0, 1)))
+		      == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg1, 1))))
 		  && OP_SAME (0) && OP_SAME (1));
 
 	case ARRAY_REF:
Index: gcc/tree.c
===================================================================
--- gcc/tree.c.orig	2010-09-06 14:50:54.291300126 -0300
+++ gcc/tree.c	2010-09-07 17:08:24.000000000 -0300
@@ -6734,6 +6734,21 @@  iterative_hash_expr (const_tree t, hashv
 	  }
 	return val;
       }
+    case MEM_REF:
+      {
+	/* The type of the second operand is relevant, except for
+	   its top-level qualifiers.  */
+	tree type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (t, 1)));
+
+	val = iterative_hash_object (TYPE_HASH (type), val);
+
+	/* We could use the standard hash computation from this point
+	   on.  */
+	val = iterative_hash_object (code, val);
+	val = iterative_hash_expr (TREE_OPERAND (t, 1), val);
+	val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
+	return val;
+      }
     case FUNCTION_DECL:
       /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
 	 Otherwise nodes that compare equal according to operand_equal_p might