diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 185cc1368076..7ec894c86ccd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-09-09 Richard Guenther + + PR c++/23624 + * fold-const.c (fold_ternary): Check truth_value_p before + calling invert_truthvalue. + 2005-09-09 Nick Clifton * Makefile.in (LIBGCC_DEPS): Add libgcc2.h. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 2f024b42e02e..4b41adfc59f9 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10006,7 +10006,8 @@ fold_ternary (enum tree_code code, tree type, tree op0, tree op1, tree op2) /* If the second operand is simpler than the third, swap them since that produces better jump optimization results. */ - if (tree_swap_operands_p (op1, op2, false)) + if (truth_value_p (TREE_CODE (arg0)) + && tree_swap_operands_p (op1, op2, false)) { /* See if this can be inverted. If it can't, possibly because it was a floating-point inequality comparison, don't do diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8070a168bc55..db903b134c11 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-09-09 Richard Guenther + + PR c++/23624 + * g++.dg/tree-ssa/pr23624.C: New testcase. + 2005-09-09 Richard Sandiford PR fortran/19239 diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr23624.C b/gcc/testsuite/g++.dg/tree-ssa/pr23624.C new file mode 100644 index 000000000000..769d690ce8cb --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr23624.C @@ -0,0 +1,8 @@ +/* { dg-do compile } */ + +template +void f() +{ + int *t, i; + t[i ? 0 : i]; +}