re PR middle-end/33122 (Mistaken type mismatch error prevents bootstrap)
authorRichard Guenther <rguenther@suse.de>
Tue, 21 Aug 2007 08:23:50 +0000 (08:23 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 21 Aug 2007 08:23:50 +0000 (08:23 +0000)
2007-08-21  Richard Guenther  <rguenther@suse.de>

PR middle-end/33122
* fold-const.c (fold_binary): Remove index +p PTR folding.
Fix types of POINTER_PLUS_EXPR generated by folding of
(PTR +p B) +p A.

        * gcc.c-torture/compile/pr33122.c: New testcase.

From-SVN: r127659

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr33122.c [new file with mode: 0644]

index 39535283140cb37c6c9d4583b7e563ad66d7cfb3..8223bdd37976677b20bf5d5eeecfc13672b88c56 100644 (file)
@@ -1,3 +1,10 @@
+2007-08-21  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/33122
+       * fold-const.c (fold_binary): Remove index +p PTR folding.
+       Fix types of POINTER_PLUS_EXPR generated by folding of
+       (PTR +p B) +p A.
+
 2007-08-20  Chao-ying Fu  <fu@mips.com>
 
        * c-common.h (enum rid): Add new enumeration values of RID_SAT,
index d5d0f1e3c111ecb5acb079b03e26619e6f286d55..8faf77d87519a033505d1ba2d1eb8fbb4931cd69 100644 (file)
@@ -9528,20 +9528,17 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
                                                fold_convert (sizetype, arg1),
                                                fold_convert (sizetype, arg0)));
 
-      /* index +p PTR -> PTR +p index */
-      if (POINTER_TYPE_P (TREE_TYPE (arg1))
-         && INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
-        return fold_build2 (POINTER_PLUS_EXPR, type,
-                           fold_convert (type, arg1), fold_convert (sizetype, arg0));
-
       /* (PTR +p B) +p A -> PTR +p (B + A) */
       if (TREE_CODE (arg0) == POINTER_PLUS_EXPR)
        {
          tree inner;
          tree arg01 = fold_convert (sizetype, TREE_OPERAND (arg0, 1));
          tree arg00 = TREE_OPERAND (arg0, 0);
-         inner = fold_build2 (PLUS_EXPR, sizetype, arg01, fold_convert (sizetype, arg1));
-         return fold_build2 (POINTER_PLUS_EXPR, type, arg00, inner);
+         inner = fold_build2 (PLUS_EXPR, sizetype,
+                              arg01, fold_convert (sizetype, arg1));
+         return fold_convert (type,
+                              fold_build2 (POINTER_PLUS_EXPR,
+                                           TREE_TYPE (arg00), arg00, inner));
        }
 
       /* PTR_CST +p CST -> CST1 */
@@ -9559,6 +9556,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
        }
 
       return NULL_TREE;
+
     case PLUS_EXPR:
       /* PTR + INT -> (INT)(PTR p+ INT) */
       if (POINTER_TYPE_P (TREE_TYPE (arg0))
index c94e48ba28318fbdd3be73bf4e4f41d19b4e178f..29500ed8fdf8073f3acdbbc6c9fddaef15c52e88 100644 (file)
@@ -1,3 +1,8 @@
+2007-08-21  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/33122
+       * gcc.c-torture/compile/pr33122.c: New testcase.
+
 2007-03-20  Pawel Sikora  <pluto@pld-linux.org>
 
         * g++.dg/warn/Wnvdtor-2.C: New testcase.
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr33122.c b/gcc/testsuite/gcc.c-torture/compile/pr33122.c
new file mode 100644 (file)
index 0000000..e862540
--- /dev/null
@@ -0,0 +1,14 @@
+struct dis386 {
+  const char *x;
+};
+
+static const struct dis386 float_reg[][2] = {
+  { { "fadd" }, { "fadd" } },
+};
+
+void foo(int i, int j)
+{
+  const struct dis386 *dp;
+
+  dp = &float_reg[i - 1][j];
+}