diff mbox series

[committed] Tweak POINTER_DIFF_EXPR verification (PR middle-end/83164)

Message ID 20171207171059.GP2353@tucnak
State New
Headers show
Series [committed] Tweak POINTER_DIFF_EXPR verification (PR middle-end/83164) | expand

Commit Message

Jakub Jelinek Dec. 7, 2017, 5:10 p.m. UTC
Hi!

As mentioned in the PR, we need to treat POINTER_DIFF_EXPR similarly
how we treat comparisons with pointer operands (i.e. that either
there is useless conversion from one type to the other, or from the
other to the one, or the pointer type modes are the same), because
we have exceptions for pointers to void and can propagate there
various pointer types.
But, if we accept all cases where TYPE_MODE is the same, then we don't
need to call useless_type_conversion_p at all, as for different TYPE_MODEs
it will always return false.

Bootstrapped/regtested on x86_64-linux and i686-linux, preapproved by
Richard in the PR, committed to trunk.

2017-12-07  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/83164
	* tree-cfg.c (verify_gimple_assign_binary): Don't require
	types_compatible_p, just that TYPE_MODE is the same.

	* gcc.c-torture/compile/pr83164.c: New test.


	Jakub
diff mbox series

Patch

--- gcc/tree-cfg.c.jj	2017-12-06 09:16:12.000000000 +0100
+++ gcc/tree-cfg.c	2017-12-07 13:00:33.641456189 +0100
@@ -4007,7 +4007,9 @@  verify_gimple_assign_binary (gassign *st
       {
 	if (!POINTER_TYPE_P (rhs1_type)
 	    || !POINTER_TYPE_P (rhs2_type)
-	    || !types_compatible_p (rhs1_type, rhs2_type)
+	    /* Because we special-case pointers to void we allow difference
+	       of arbitrary pointers with the same mode.  */
+	    || TYPE_MODE (rhs1_type) != TYPE_MODE (rhs2_type)
 	    || TREE_CODE (lhs_type) != INTEGER_TYPE
 	    || TYPE_UNSIGNED (lhs_type)
 	    || TYPE_PRECISION (lhs_type) != TYPE_PRECISION (rhs1_type))
--- gcc/testsuite/gcc.c-torture/compile/pr83164.c.jj	2017-12-07 12:54:01.911306184 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr83164.c	2017-12-07 12:53:41.000000000 +0100
@@ -0,0 +1,7 @@ 
+/* PR middle-end/83164 */
+
+__PTRDIFF_TYPE__
+foo (void)
+{
+  return (char *) foo - (char *) 0x1230;
+}