]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/49165 (ICE on for-loop/throw combination)
authorJakub Jelinek <jakub@redhat.com>
Tue, 19 Jul 2011 12:54:34 +0000 (14:54 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 19 Jul 2011 12:54:34 +0000 (14:54 +0200)
Backport from mainline
2011-05-26  Jakub Jelinek  <jakub@redhat.com>

PR c++/49165
* gimplify.c (shortcut_cond_r): Don't special case
COND_EXPRs if they have void type on one of their arms.

* g++.dg/eh/cond5.C: New test.

From-SVN: r176452

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/eh/cond5.C [new file with mode: 0644]

index 1da0eb374f21916a02e260e1e0e0a4619f8e9c9d..06ebb56485cbb28af7811d2b693785c247ac24a7 100644 (file)
@@ -3,6 +3,10 @@
        Backport from mainline
        2011-05-26  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/49165
+       * gimplify.c (shortcut_cond_r): Don't special case
+       COND_EXPRs if they have void type on one of their arms.
+
        PR tree-optimization/49161
        * tree-vrp.c (struct case_info): New type.
        (compare_case_labels): Sort case_info structs instead of
index 7578418d33ca59c322b904805ee40ac48b49aad5..4db3bc44634831f48ba23b7e48e55ff0fd573f51 100644 (file)
@@ -2496,7 +2496,9 @@ shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p,
                           new_locus);
       append_to_statement_list (t, &expr);
     }
-  else if (TREE_CODE (pred) == COND_EXPR)
+  else if (TREE_CODE (pred) == COND_EXPR
+          && !VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (pred, 1)))
+          && !VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (pred, 2))))
     {
       location_t new_locus;
 
@@ -2504,7 +2506,10 @@ shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p,
         if (a)
           if (b) goto yes; else goto no;
         else
-          if (c) goto yes; else goto no;  */
+          if (c) goto yes; else goto no;
+
+        Don't do this if one of the arms has void type, which can happen
+        in C++ when the arm is throw.  */
 
       /* Keep the original source location on the first 'if'.  Set the source
         location of the ? on the second 'if'.  */
index 127eda200d3d2bffb615085f9a4d64b005367f07..c14c8eaa2749d9985b93b4131c424e738cf79819 100644 (file)
@@ -3,6 +3,9 @@
        Backport from mainline
        2011-05-26  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/49165
+       * g++.dg/eh/cond5.C: New test.
+
        PR tree-optimization/49161
        * gcc.c-torture/execute/pr49161.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/eh/cond5.C b/gcc/testsuite/g++.dg/eh/cond5.C
new file mode 100644 (file)
index 0000000..3f0c599
--- /dev/null
@@ -0,0 +1,43 @@
+// PR c++/49165
+// { dg-do run }
+
+extern "C" void abort ();
+
+int
+foo (bool x, int y)
+{
+  if (y < 10 && (x ? true : throw 1))
+    y++;
+  if (y > 20 || (x ? true : throw 2))
+    y++;
+  return y;
+}
+
+int
+main ()
+{
+  if (foo (true, 0) != 2
+      || foo (true, 10) != 11
+      || foo (false, 30) != 31)
+    abort ();
+  try
+    {
+      foo (false, 0);
+      abort ();
+    }
+  catch (int i)
+    {
+      if (i != 1)
+       abort ();
+    }
+  try
+    {
+      foo (false, 10);
+      abort ();
+    }
+  catch (int i)
+    {
+      if (i != 2)
+       abort ();
+    }
+}