re PR tree-optimization/53663 (inconsistent inline handling of bool within union)
authorRichard Guenther <rguenther@suse.de>
Tue, 25 Sep 2012 07:51:51 +0000 (07:51 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 25 Sep 2012 07:51:51 +0000 (07:51 +0000)
2012-09-25  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/53663
* tree-ssa-sccvn.c (vn_reference_lookup_3): Conditional
native encode/interpret translation on VN_WALKREWRITE.

* gcc.dg/torture/pr53663-1.c: New testcase.
* gcc.dg/torture/pr53663-2.c: Likewise.
* gcc.dg/torture/pr53663-3.c: Likewise.

From-SVN: r191694

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr53663-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr53663-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr53663-3.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index 36a9186..8bcade6 100644 (file)
@@ -1,3 +1,9 @@
+2012-09-25  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/53663
+       * tree-ssa-sccvn.c (vn_reference_lookup_3): Conditional
+       native encode/interpret translation on VN_WALKREWRITE.
+
 2012-09-24  Dehao Chen  <dehao@google.com>
 
        * tree-cfg.c (move_stmt_op): Reset the expr block only
index 9a9dc4b..d945459 100644 (file)
@@ -1,3 +1,10 @@
+2012-09-25  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/53663
+       * gcc.dg/torture/pr53663-1.c: New testcase.
+       * gcc.dg/torture/pr53663-2.c: Likewise.
+       * gcc.dg/torture/pr53663-3.c: Likewise.
+
 2012-09-25  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.target/i386/pr50725.c: Change 'long' to 'long long'.
diff --git a/gcc/testsuite/gcc.dg/torture/pr53663-1.c b/gcc/testsuite/gcc.dg/torture/pr53663-1.c
new file mode 100644 (file)
index 0000000..3392dde
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do run } */
+
+extern void abort (void);
+
+union u
+{
+  int i;
+  _Bool b;
+};
+
+void f(union u * vp, union u v)
+{
+  *vp = v;
+}
+
+int main()
+{
+  union u v;
+  union u v1;
+  union u v2;
+
+  v.i = 10;
+  f(&v1, v);
+
+  v.b = 0;
+  f(&v2, v);
+  if (v2.b != 0)
+    abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr53663-2.c b/gcc/testsuite/gcc.dg/torture/pr53663-2.c
new file mode 100644 (file)
index 0000000..9589a9e
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+
+extern void abort (void);
+
+union u
+{
+  int i;
+  short f;
+} v;
+
+short foo (short *f)
+{
+  *f = 1;
+  v.i = 0;
+  v.f = 0;
+  return *f;
+}
+
+int main()
+{
+  if (foo (&v.f) != 0)
+    abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr53663-3.c b/gcc/testsuite/gcc.dg/torture/pr53663-3.c
new file mode 100644 (file)
index 0000000..96af5db
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+
+extern void abort (void);
+
+union u
+{
+  int i;
+  float f;
+} v;
+
+float foo (float *f)
+{
+  *f = 1;
+  v.i = 0;
+  v.f = 0.;
+  return *f;
+}
+
+int main()
+{
+  if (foo (&v.f) != 0.)
+    abort ();
+  return 0;
+}
index 2e5ed74..9e62ebe 100644 (file)
@@ -1555,7 +1555,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_)
 
   /* 3) Assignment from a constant.  We can use folds native encode/interpret
      routines to extract the assigned bits.  */
-  else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
+  else if (vn_walk_kind == VN_WALKREWRITE
+          && CHAR_BIT == 8 && BITS_PER_UNIT == 8
           && ref->size == maxsize
           && maxsize % BITS_PER_UNIT == 0
           && offset % BITS_PER_UNIT == 0