]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/50565 (initializer element is not computable at load time)
authorJoseph Myers <joseph@codesourcery.com>
Wed, 12 Oct 2011 11:58:47 +0000 (12:58 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Wed, 12 Oct 2011 11:58:47 +0000 (12:58 +0100)
PR c/50565
* 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.

From-SVN: r179847

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 54f4e0319c84c431df5661891c94071b943d407b..de0cd9604d92356ea5c0bb02dbc8a918024eb4d9 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-11  Eric Botcazou  <ebotcazou@adacore.com>
 
        PR target/49965
index 055f294d1d7a355f283f9f36847643de8da12e9e..175ecb89323ed2737d4e3582cc0e8f8652e8737d 100644 (file)
@@ -728,6 +728,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 964651820a4a2ea31000e4b159bd8840679a6cca..6e4e386c83b66c8a3d30514c0f9a27bbb46c3a6f 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  Janis Johnson  <janisjo@codesourcery.com>
 
        PR c++/44473
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;