]> 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 19:29:57 +0000 (21:29 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 19 Jul 2011 19:29:57 +0000 (21:29 +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: r176483

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

index 9b062d745c73be6930dae907b8b855cafe93dc49..060ce609d111093b201348d42e53ffa753d137d8 100644 (file)
@@ -1,6 +1,12 @@
 2011-07-19  Jakub Jelinek  <jakub@redhat.com>
 
        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.
+
        2011-05-23  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/48973
index 94bae9c83f2c1c991f44f6b22d1afb5ad87b1148..631f54a005218c4a7b716b3bf392c5b7d44786f4 100644 (file)
@@ -2570,13 +2570,18 @@ shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p)
                           false_label_p);
       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))))
     {
       /* As long as we're messing with gotos, turn if (a ? b : c) into
         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.  */
       expr = build3 (COND_EXPR, void_type_node, TREE_OPERAND (pred, 0),
                     shortcut_cond_r (TREE_OPERAND (pred, 1), true_label_p,
                                      false_label_p),
index 254103cd857ecb17ea5cf8a4b80a1bb5a67303ef..c2d84e09544414b6333440a021ad59bc490a5e65 100644 (file)
@@ -1,6 +1,11 @@
 2011-07-19  Jakub Jelinek  <jakub@redhat.com>
 
        Backport from mainline
+       2011-05-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/49165
+       * g++.dg/eh/cond5.C: New test.
+
        2011-05-23  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/48973
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 ();
+    }
+}