]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c/50565
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 12 Oct 2011 11:56:03 +0000 (11:56 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 12 Oct 2011 11:56:03 +0000 (11:56 +0000)
* convert.c (convert_to_integer): Do not narrow operands of
pointer subtraction.

testsuite:
* gcc.c-torture/compile/pr50565-1.c,
gcc.c-torture/compile/pr50565-2.c: New tests.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@179845 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/convert.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr50565-1.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/compile/pr50565-2.c [new file with mode: 0644]

index 474bbb4d64f890b2068e6579856f08f473824f99..d9fac6fefd145e7766d5df26f91b6b176ce26072 100644 (file)
@@ -1,3 +1,9 @@
+2011-10-12  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/50565
+       * convert.c (convert_to_integer): Do not narrow operands of
+       pointer subtraction.
+
 2011-10-12  Nick Clifton  <nickc@redhat.com>
 
        * config/arm/arm.h (EMIT_EABI_ATTRIBUTE): New macro.  Used to
index a647193ca949e8f425984eefe6e0b695ce79e1e9..f04b204819464a6962bc98e83d46bc14d5067f90 100644 (file)
@@ -745,6 +745,15 @@ convert_to_integer (tree type, tree expr)
            tree arg0 = get_unwidened (TREE_OPERAND (expr, 0), type);
            tree arg1 = get_unwidened (TREE_OPERAND (expr, 1), type);
 
+           /* Do not try to narrow operands of pointer subtraction;
+              that will interfere with other folding.  */
+           if (ex_form == MINUS_EXPR
+               && CONVERT_EXPR_P (arg0)
+               && CONVERT_EXPR_P (arg1)
+               && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (arg0, 0)))
+               && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0))))
+             break;
+
            if (outprec >= BITS_PER_WORD
                || TRULY_NOOP_TRUNCATION (outprec, inprec)
                || inprec > TYPE_PRECISION (TREE_TYPE (arg0))
index c0684924568c2260d9710e7f8737ffa66f939f25..70f89f9330cd27c3286b38fde585129e030fa5e0 100644 (file)
@@ -1,3 +1,9 @@
+2011-10-12  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/50565
+       * gcc.c-torture/compile/pr50565-1.c,
+       gcc.c-torture/compile/pr50565-2.c: New tests.
+
 2011-10-11  Jason Merrill  <jason@redhat.com>
 
        PR c++/49855
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr50565-1.c b/gcc/testsuite/gcc.c-torture/compile/pr50565-1.c
new file mode 100644 (file)
index 0000000..cdaad29
--- /dev/null
@@ -0,0 +1,4 @@
+struct s { char p[2]; };
+static struct s v;
+const int o0 = (int) ((void *) &v.p[0] - (void *) &v) + 0U;
+const int o1 = (int) ((void *) &v.p[0] - (void *) &v) + 1U;
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr50565-2.c b/gcc/testsuite/gcc.c-torture/compile/pr50565-2.c
new file mode 100644 (file)
index 0000000..2d30e88
--- /dev/null
@@ -0,0 +1,4 @@
+struct s { char p[2]; };
+static struct s v;
+const int o0 = (int) ((void *) &v.p[0] - (void *) &v) + 0;
+const int o1 = (int) ((void *) &v.p[0] - (void *) &v) + 1;