]> 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:31:01 +0000 (21:31 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 19 Jul 2011 19:31:01 +0000 (21:31 +0200)
Backport from mainline
2011-05-27  Jakub Jelinek  <jakub@redhat.com>

PR c++/49165
* c-common.c (c_common_truthvalue_conversion) <case COND_EXPR>: For
C++ don't call c_common_truthvalue_conversion on void type arms.

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

From-SVN: r176484

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/eh/cond6.C [new file with mode: 0644]

index 060ce609d111093b201348d42e53ffa753d137d8..ceede27601ca194b78cfb431ca44a721559c1bec 100644 (file)
@@ -1,6 +1,12 @@
 2011-07-19  Jakub Jelinek  <jakub@redhat.com>
 
        Backport from mainline
+       2011-05-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/49165
+       * c-common.c (c_common_truthvalue_conversion) <case COND_EXPR>: For
+       C++ don't call c_common_truthvalue_conversion on void type arms.
+
        2011-05-26  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/49165
index 5f4079054a6293c99c5cb5c7f3703d142ea961fd..2d62a1cc1bbfd261853492d1fbab198a8ef66edc 100644 (file)
@@ -3430,13 +3430,18 @@ c_common_truthvalue_conversion (location_t location, tree expr)
                                               TREE_OPERAND (expr, 0));
 
     case COND_EXPR:
-      /* Distribute the conversion into the arms of a COND_EXPR.  */
-      return fold_build3 (COND_EXPR, truthvalue_type_node,
-               TREE_OPERAND (expr, 0),
-               c_common_truthvalue_conversion (location,
-                                               TREE_OPERAND (expr, 1)),
-               c_common_truthvalue_conversion (location,
-                                               TREE_OPERAND (expr, 2)));
+      {
+       tree op1 = TREE_OPERAND (expr, 1);
+       tree op2 = TREE_OPERAND (expr, 2);
+        /* In C++ one of the arms might have void type if it is throw.  */
+       if (!VOID_TYPE_P (TREE_TYPE (op1)))
+         op1 = c_common_truthvalue_conversion (location, op1);
+       if (!VOID_TYPE_P (TREE_TYPE (op2)))
+         op2 = c_common_truthvalue_conversion (location, op2);
+       /* Distribute the conversion into the arms of a COND_EXPR.  */
+       return fold_build3 (COND_EXPR, truthvalue_type_node,
+                           TREE_OPERAND (expr, 0), op1, op2);
+      }
 
     CASE_CONVERT:
       /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
index c2d84e09544414b6333440a021ad59bc490a5e65..153a20c6d3e2bcabfa25e3a4319466eed619aea0 100644 (file)
@@ -1,6 +1,11 @@
 2011-07-19  Jakub Jelinek  <jakub@redhat.com>
 
        Backport from mainline
+       2011-05-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/49165
+       * g++.dg/eh/cond6.C: New test.
+
        2011-05-26  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/49165
diff --git a/gcc/testsuite/g++.dg/eh/cond6.C b/gcc/testsuite/g++.dg/eh/cond6.C
new file mode 100644 (file)
index 0000000..1eed63e
--- /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 ? 1 : throw 1))
+    y++;
+  if (y > 20 || (x ? 1 : 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 ();
+    }
+}