]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/63551 (wrong code (segfaults) at -Os on x86_64-linux-gnu)
authorMarek Polacek <polacek@redhat.com>
Thu, 30 Apr 2015 18:41:33 +0000 (18:41 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 30 Apr 2015 18:41:33 +0000 (18:41 +0000)
        * g++.dg/ipa/pr63551.C: New test.

        Backported from mainline
        2014-12-15  Jakub Jelinek  <jakub@redhat.com>

        PR tree-optimization/63551
        * gcc.dg/ipa/pr63551.c (fn2): Use 4294967286U instead of
        4294967286 to avoid warnings.

        2014-12-03  Martin Jambor  <mjambor@suse.cz>

        PR ipa/64153
        * ipa-inline-analysis.c (evaluate_conditions_for_known_args): Check
        type sizes before view_converting.

        2014-12-01  Martin Jambor  <mjambor@suse.cz>

        PR ipa/63551
        * ipa-inline-analysis.c (evaluate_conditions_for_known_args): Convert
        value of the argument to the type of the value in the condition.

        * gcc.dg/ipa/pr63551.c: New test.
        * gcc.dg/ipa/pr64041.c: Likewise.

From-SVN: r222653

gcc/ChangeLog
gcc/ipa-inline-analysis.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ipa/pr63551.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/pr63551.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/pr64041.c [new file with mode: 0644]

index fa72ba183bb6e9b8b266fbdf9e4d72b8b1e887ca..287013afc87544c10097be4ce8a923e306187331 100644 (file)
@@ -1,3 +1,18 @@
+2015-04-30  Marek Polacek  <polacek@redhat.com>
+
+       Backported from mainline
+       2014-12-03  Martin Jambor  <mjambor@suse.cz>
+
+       PR ipa/64153
+       * ipa-inline-analysis.c (evaluate_conditions_for_known_args): Check
+       type sizes before view_converting.
+
+       2014-12-01  Martin Jambor  <mjambor@suse.cz>
+
+       PR ipa/63551
+       * ipa-inline-analysis.c (evaluate_conditions_for_known_args): Convert
+       value of the argument to the type of the value in the condition.
+
 2015-04-24  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        Backport from mainline r222385
index 53439333c90fb24045878adde88fc55bfdff5adf..1a27df2e14cb0bc323c9c3101e15e07127809567 100644 (file)
@@ -831,9 +831,19 @@ evaluate_conditions_for_known_args (struct cgraph_node *node,
        }
       if (c->code == IS_NOT_CONSTANT || c->code == CHANGED)
        continue;
-      res = fold_binary_to_constant (c->code, boolean_type_node, val, c->val);
-      if (res && integer_zerop (res))
-       continue;
+
+      if (operand_equal_p (TYPE_SIZE (TREE_TYPE (c->val)),
+                          TYPE_SIZE (TREE_TYPE (val)), 0))
+       {
+         val = fold_unary (VIEW_CONVERT_EXPR, TREE_TYPE (c->val), val);
+
+         res = val
+           ? fold_binary_to_constant (c->code, boolean_type_node, val, c->val)
+           : NULL;
+
+         if (res && integer_zerop (res))
+           continue;
+       }
       clause |= 1 << (i + predicate_first_dynamic_condition);
     }
   return clause;
index 75f7bc3beede9b9315fc700c419a37b7bb5ecf9b..ffa7a529aa3915c417db78a7263fdb8845b117d7 100644 (file)
@@ -1,3 +1,20 @@
+2015-04-30  Marek Polacek  <polacek@redhat.com>
+
+       * g++.dg/ipa/pr63551.C: New test.
+
+       Backported from mainline
+       2014-12-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/63551
+       * gcc.dg/ipa/pr63551.c (fn2): Use 4294967286U instead of
+       4294967286 to avoid warnings.
+
+       2014-12-01  Martin Jambor  <mjambor@suse.cz>
+
+       PR ipa/63551
+       * gcc.dg/ipa/pr63551.c: New test.
+       * gcc.dg/ipa/pr64041.c: Likewise.
+
 2015-04-24  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        Backport from mainline r222362
diff --git a/gcc/testsuite/g++.dg/ipa/pr63551.C b/gcc/testsuite/g++.dg/ipa/pr63551.C
new file mode 100644 (file)
index 0000000..03e0339
--- /dev/null
@@ -0,0 +1,23 @@
+// { dg-options "-O -Wno-psabi" }
+// { dg-do compile }
+
+struct A { int a; };
+template <typename T, typename V> struct B { V operator[] (T); };
+union U { long double ld; void *v; };
+A a;
+
+void
+bar (U &x)
+{
+  if (x.v) *reinterpret_cast <A *>(x.v) = a;
+}
+
+struct C { C (A) { c.ld = 0; bar (c); } U c; };
+struct D { A d, e; void foo () { f[0][d] = e; } B <int, B <A, C> > f; };
+
+void
+baz ()
+{
+  D d;
+  d.foo ();
+}
diff --git a/gcc/testsuite/gcc.dg/ipa/pr63551.c b/gcc/testsuite/gcc.dg/ipa/pr63551.c
new file mode 100644 (file)
index 0000000..48b020a
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do run } */
+/* { dg-options "-Os" } */
+
+union U
+{
+  unsigned int f0;
+  int f1;
+};
+
+int a, d;
+
+void
+fn1 (union U p)
+{
+  if (p.f1 <= 0)
+    if (a)
+      d = 0;
+}
+
+void
+fn2 ()
+{
+  d = 0;
+  union U b = { 4294967286U };
+  fn1 (b);
+}
+
+int
+main ()
+{
+  fn2 ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/ipa/pr64041.c b/gcc/testsuite/gcc.dg/ipa/pr64041.c
new file mode 100644 (file)
index 0000000..4877b4b
--- /dev/null
@@ -0,0 +1,64 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+int printf (const char *, ...);
+
+int a, b = 1, d;
+
+union U1
+{
+  unsigned int f0;
+  int f1;
+};
+
+union U2
+{
+  int f2;
+  int f3;
+} c;
+
+int
+fn1 (int p)
+{
+  int t = p && a || p && a && p; 
+  return t ? t : a;
+}
+
+unsigned
+fn2 (union U1 p1, union U2 p2)
+{
+  if (p1.f1 <= 0)
+    {
+      for (; p2.f2;)
+       c.f2 = 0;
+      p2.f2 = fn1 (d);
+    }
+  return p2.f3;
+}
+
+int g = 0;
+
+int
+foo ()
+{
+  if (b)
+    {
+      union U1 f = { 0xFFFFFFFFU }; 
+
+      fn2 (f, c);
+    }
+  g = 1;
+  return 0; 
+}
+
+
+int
+main ()
+{
+  foo ();
+
+  if (g == 0)
+    __builtin_abort ();
+
+  return 0;
+}