From fd7423e13e3e374957f612526fadf007f17ebac1 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 19 Jul 2011 14:56:48 +0200 Subject: [PATCH] backport: re PR c++/49165 (ICE on for-loop/throw combination) Backport from mainline 2011-05-27 Jakub Jelinek PR c++/49165 * c-common.c (c_common_truthvalue_conversion) : For C++ don't call c_common_truthvalue_conversion on void type arms. * g++.dg/eh/cond6.C: New test. From-SVN: r176453 --- gcc/ChangeLog | 6 +++++ gcc/c-common.c | 15 ++++++------ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/eh/cond6.C | 43 +++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/eh/cond6.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 06ebb56485cb..10977031214d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,12 @@ 2011-07-19 Jakub Jelinek Backport from mainline + 2011-05-27 Jakub Jelinek + + PR c++/49165 + * c-common.c (c_common_truthvalue_conversion) : For + C++ don't call c_common_truthvalue_conversion on void type arms. + 2011-05-26 Jakub Jelinek PR c++/49165 diff --git a/gcc/c-common.c b/gcc/c-common.c index 72ea40427fe9..0eac72727d60 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -4031,14 +4031,15 @@ c_common_truthvalue_conversion (location_t location, tree expr) /* Distribute the conversion into the arms of a COND_EXPR. */ if (c_dialect_cxx ()) { + 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); expr = fold_build3_loc (location, 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_OPERAND (expr, 0), op1, op2); goto ret; } else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c14c8eaa2749..d259fd59d2b6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2011-07-19 Jakub Jelinek Backport from mainline + 2011-05-27 Jakub Jelinek + + PR c++/49165 + * g++.dg/eh/cond6.C: New test. + 2011-05-26 Jakub Jelinek 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 index 000000000000..1eed63ec84f5 --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/cond6.C @@ -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 (); + } +} -- 2.47.2