]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/34459 (incorrect code when compiled with optimization (-O1))
authorJakub Jelinek <jakub@redhat.com>
Thu, 20 Dec 2007 14:40:33 +0000 (15:40 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 20 Dec 2007 14:40:33 +0000 (15:40 +0100)
PR c++/34459
* tree-ssa-dse.c (dse_optimize_stmt): Don't eliminate store if
USE_STMT not only stores into the same object as STMT, but might
read it too.

* gcc.c-torture/execute/20071219-1.c: New test.

From-SVN: r131101

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20071219-1.c [new file with mode: 0644]
gcc/tree-ssa-dse.c

index 070123da93c04b097c63eb9f4e428048965bc714..33922e02906785e6743022faefcb9970aba74aa3 100644 (file)
@@ -1,3 +1,10 @@
+2007-12-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/34459
+       * tree-ssa-dse.c (dse_optimize_stmt): Don't eliminate store if
+       USE_STMT not only stores into the same object as STMT, but might
+       read it too.
+
 2007-12-19  Sebastian Pop  <sebastian.pop@amd.com>
 
        PR tree-optimization/34413
index 3c67c45c256df7e0de4004d16dba03def16e29d7..e9364ec22b2c845e603fed1922fa06a29244b4c4 100644 (file)
@@ -1,3 +1,8 @@
+2007-12-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/34459
+       * gcc.c-torture/execute/20071219-1.c: New test.
+
 2007-12-20  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/34530
diff --git a/gcc/testsuite/gcc.c-torture/execute/20071219-1.c b/gcc/testsuite/gcc.c-torture/execute/20071219-1.c
new file mode 100644 (file)
index 0000000..4152711
--- /dev/null
@@ -0,0 +1,71 @@
+/* PR c++/34459 */
+
+extern void abort (void);
+extern void *memset (void *s, int c, __SIZE_TYPE__ n);
+
+struct S
+{
+  char s[25];
+};
+
+struct S *p;
+
+void __attribute__((noinline))
+foo (struct S *x, int set)
+{
+  int i;
+  for (i = 0; i < sizeof (x->s); ++i)
+    if (x->s[i] != 0)
+      abort ();
+    else if (set)
+      x->s[i] = set;
+  p = x;
+}
+
+void __attribute__((noinline))
+test1 (void)
+{
+  struct S a;
+  memset (&a.s, '\0', sizeof (a.s));
+  foo (&a, 0);
+  struct S b = a;
+  foo (&b, 1);
+  b = a;
+  b = b;
+  foo (&b, 0);
+}
+
+void __attribute__((noinline))
+test2 (void)
+{
+  struct S a;
+  memset (&a.s, '\0', sizeof (a.s));
+  foo (&a, 0);
+  struct S b = a;
+  foo (&b, 1);
+  b = a;
+  b = *p;
+  foo (&b, 0);
+}
+
+void __attribute__((noinline))
+test3 (void)
+{
+  struct S a;
+  memset (&a.s, '\0', sizeof (a.s));
+  foo (&a, 0);
+  struct S b = a;
+  foo (&b, 1);
+  *p = a;
+  *p = b;
+  foo (&b, 0);
+}
+
+int
+main (void)
+{
+  test1 ();
+  test2 ();
+  test3 ();
+  return 0;
+}
index 3435fa3038215055b9c0f654b486c77728cec4be..3e0f04be1245dba638db06918192ea5e7b0f8a4f 100644 (file)
@@ -470,6 +470,26 @@ dse_optimize_stmt (struct dom_walk_data *walk_data,
          vuse_vec_p vv;
          tree stmt_lhs;
 
+         if (LOADED_SYMS (use_stmt))
+           {
+             tree use_base
+               = get_base_address (GIMPLE_STMT_OPERAND (use_stmt, 0));
+             /* If use_stmt is or might be a nop assignment, e.g. for
+                struct { ... } S a, b, *p; ...
+                b = a; b = b;
+                or
+                b = a; b = *p; where p might be &b, then USE_STMT
+                acts as a use as well as definition, so store in STMT
+                is not dead.  */
+             if (TREE_CODE (use_base) == VAR_DECL
+                 && bitmap_bit_p (LOADED_SYMS (use_stmt),
+                                  DECL_UID (use_base)))
+               {
+                 record_voperand_set (dse_gd->stores, &bd->stores, ann->uid);
+                 return;
+               }
+           }
+
          if (dump_file && (dump_flags & TDF_DETAILS))
             {
               fprintf (dump_file, "  Deleted dead store '");