]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/38835 (field-insensitive PTA causes libstdc++ miscompiles)
authorRichard Guenther <rguenther@suse.de>
Fri, 16 Jan 2009 19:18:18 +0000 (19:18 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 16 Jan 2009 19:18:18 +0000 (19:18 +0000)
2009-01-16  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/38835
PR middle-end/36227
* fold-const.c (fold_binary): Remove PTR + INT -> (INT)(PTR p+ INT)
and INT + PTR -> (INT)(PTR p+ INT) folding.
* tree-ssa-address.c (create_mem_ref): Properly use POINTER_PLUS_EXPR.

java/
* builtins.c (build_addr_sum): Use POINTER_PLUS_EXPR.

* gcc.c-torture/execute/pr36227.c: New testcase.
* gcc.dg/tree-ssa/foldaddr-1.c: XFAIL.
* g++.dg/init/const7.C: Likewise.

From-SVN: r143442

gcc/ChangeLog
gcc/fold-const.c
gcc/java/ChangeLog
gcc/java/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/const7.C
gcc/testsuite/gcc.c-torture/execute/pr36227.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/foldaddr-1.c
gcc/tree-ssa-address.c

index 3c2457d84e611d405e45e570e517148b9bd016e6..f3c186ee1d7673ca55941dd9329346ecae8caf7f 100644 (file)
@@ -1,3 +1,11 @@
+2009-01-16  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/38835
+       PR middle-end/36227
+       * fold-const.c (fold_binary): Remove PTR + INT -> (INT)(PTR p+ INT)
+       and INT + PTR -> (INT)(PTR p+ INT) folding.
+       * tree-ssa-address.c (create_mem_ref): Properly use POINTER_PLUS_EXPR.
+
 2009-01-16  Adam Nemet  <anemet@caviumnetworks.com>
 
        PR target/38554
index 32863e6b4e80da8b02facd625c1e3f8af1ee641c..eb7d7c91210d643b9425f9956ac130d210213b7e 100644 (file)
@@ -9864,20 +9864,6 @@ 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))
-         && INTEGRAL_TYPE_P (TREE_TYPE (arg1)))
-       return fold_convert (type, fold_build2 (POINTER_PLUS_EXPR,
-                                               TREE_TYPE (arg0),
-                                               arg0,
-                                               fold_convert (sizetype, arg1)));
-      /* INT + PTR -> (INT)(PTR p+ INT) */
-      if (POINTER_TYPE_P (TREE_TYPE (arg1))
-         && INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
-       return fold_convert (type, fold_build2 (POINTER_PLUS_EXPR,
-                                               TREE_TYPE (arg1),
-                                               arg1,
-                                               fold_convert (sizetype, arg0)));
       /* A + (-B) -> A - B */
       if (TREE_CODE (arg1) == NEGATE_EXPR)
        return fold_build2 (MINUS_EXPR, type,
index a177380274887cfff2c53ab8ec508beda625b9f4..dd696e689da35068cb631d5eee7a9333cfd44039 100644 (file)
@@ -1,3 +1,9 @@
+2009-01-16  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/38835
+       PR middle-end/36227
+       * builtins.c (build_addr_sum): Use POINTER_PLUS_EXPR.
+
 2008-12-05  Sebastian Pop  <sebastian.pop@amd.com>
 
        PR bootstrap/38262
index a760def774896b494331e04ad777f5cd79a32649..c46241b7a81458b678cd14798982f7fa417a6205 100644 (file)
@@ -265,9 +265,10 @@ static tree
 build_addr_sum (tree type, tree addr, tree offset)
 {
   tree ptr_type = build_pointer_type (type);
-  return  fold_build2 (PLUS_EXPR, 
-                      ptr_type, 
-                      fold_convert (ptr_type, addr), offset);
+  return fold_build2 (POINTER_PLUS_EXPR,
+                     ptr_type,
+                     fold_convert (ptr_type, addr),
+                     fold_convert (sizetype, offset));
 }
 
 /* Make sure that this-arg is non-NULL.  This is a security check.  */
index 4a41a218ab172ec746f4fe5d6464ce31daa8a273..a7084b7e850717770f56d25da76509c720f83f19 100644 (file)
@@ -1,3 +1,11 @@
+2009-01-16  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/38835
+       PR middle-end/36227
+       * gcc.c-torture/execute/pr36227.c: New testcase.
+       * gcc.dg/tree-ssa/foldaddr-1.c: XFAIL.
+       * g++.dg/init/const7.C: Likewise.
+
 2009-01-16  Adam Nemet  <anemet@caviumnetworks.com>
 
        PR target/38554
index 18d04625db2da1178c806ee1f0a5cf287e65b66a..348bd58d6905d44e2adf3952974191ff39c044b4 100644 (file)
@@ -9,5 +9,5 @@ short offsets[1] = {
 // This ensures that we get a dump whether or not the bug is present.
 void fn() { }
 
-// { dg-final { scan-tree-dump-not "initialization"  "gimple" } }
+// { dg-final { scan-tree-dump-not "initialization"  "gimple" { xfail *-*-* } } }
 // { dg-final { cleanup-tree-dump "gimple" } }
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr36227.c b/gcc/testsuite/gcc.c-torture/execute/pr36227.c
new file mode 100644 (file)
index 0000000..355adf4
--- /dev/null
@@ -0,0 +1,15 @@
+#include <stdint.h>
+extern void abort (void);
+int main()
+{
+  int i = 1;
+  int *p = &i;
+  uintptr_t iptr;
+
+  iptr = (uintptr_t)p - (uintptr_t)&iptr;
+  p = (int *)((uintptr_t)&iptr + iptr);
+  if (*p != 1)
+    abort ();
+  return 0;
+}
+
index a92498eb1f66bad755b5e51f82c267ae05ff623c..2d8ccae2777fbdfe6e9693dd9bf946fc3287c881 100644 (file)
@@ -11,6 +11,6 @@ int foo(char *b)
 /* Folding should have determined that the two addresses were
    not identical and thus collapsed the function into a trivial
    "return 0".  */
-/* { dg-final { scan-tree-dump-times "return 0" 1 "original"} } */
+/* { dg-final { scan-tree-dump-times "return 0" 1 "original" { xfail *-*-* } } */
 /* { dg-final { cleanup-tree-dump "original" } } */
 
index df4f5c9296f38baf3ca2e698994959986337d4db..da236ffd5a9e720a2fab03151f3b950f7f02498c 100644 (file)
@@ -619,9 +619,9 @@ create_mem_ref (gimple_stmt_iterator *gsi, tree type, aff_tree *addr,
            {
              atype = TREE_TYPE (tmp);
              parts.base = force_gimple_operand_gsi (gsi,
-                       fold_build2 (PLUS_EXPR, atype,
-                                    fold_convert (atype, parts.base),
-                                    tmp),
+                       fold_build2 (POINTER_PLUS_EXPR, atype,
+                                    tmp,
+                                    fold_convert (sizetype, parts.base)),
                        true, NULL_TREE, true, GSI_SAME_STMT);
            }
          else