From: Nathan Sidwell Date: Tue, 22 Oct 2002 09:06:19 +0000 (+0000) Subject: re PR c++/7209 (Faulty array dereferencing) X-Git-Tag: releases/gcc-3.2.1~123 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0badb078c1b0b7ee0de83c36ae64aa5285199e03;p=thirdparty%2Fgcc.git re PR c++/7209 (Faulty array dereferencing) PR c++/7209 * fold_const.c (fold_binary_op_with_conditional_arg): Always build compound_expr if we used save_expr. testsuite: * g++.dg/expr: New directory. * g++.dg/expr/cond1.C: New test. From-SVN: r58406 --- diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f44c482379a0..926581c2ab47 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4869,6 +4869,7 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p) /* And these are the types of the expressions. */ tree lhs_type = type; tree rhs_type = type; + int save = 0; if (cond_first_p) { @@ -4927,11 +4928,12 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p) if an arm is a COND_EXPR since we get exponential behavior in that case. */ - if (TREE_CODE (arg) != SAVE_EXPR && ! TREE_CONSTANT (arg) - && global_bindings_p () == 0 - && ((TREE_CODE (arg) != VAR_DECL - && TREE_CODE (arg) != PARM_DECL) - || TREE_SIDE_EFFECTS (arg))) + if (TREE_CODE (arg) == SAVE_EXPR) + save = 1; + else if (! TREE_CONSTANT (arg) + && global_bindings_p () == 0 + && ((TREE_CODE (arg) != VAR_DECL && TREE_CODE (arg) != PARM_DECL) + || TREE_SIDE_EFFECTS (arg))) { if (TREE_CODE (true_value) != COND_EXPR) lhs = fold (build (lhs_code, lhs_type, *true_lhs, *true_rhs)); @@ -4941,7 +4943,11 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p) if ((lhs == 0 || ! TREE_CONSTANT (lhs)) && (rhs == 0 || !TREE_CONSTANT (rhs))) - arg = save_expr (arg), lhs = rhs = 0; + { + arg = save_expr (arg); + lhs = rhs = 0; + save = 1; + } } if (lhs == 0) @@ -4951,7 +4957,7 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p) test = fold (build (COND_EXPR, type, test, lhs, rhs)); - if (TREE_CODE (arg) == SAVE_EXPR) + if (save) return build (COMPOUND_EXPR, type, convert (void_type_node, arg), strip_compound_expr (test, arg)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ac6fb869f508..eacd9c3c2c0b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2002-10-22 Nathan Sidwell + + PR c++/7209 + * g++.dg/expr: New directory. + * g++.dg/expr/cond1.C: New test. + 2002-10-21 Zack Weinberg * gcc.dg/noncompile/920923-1.c: Prevent spurious regressions with