From 54ba93231b4a4d8ca3007949c9d68b6a09440c26 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 19 Feb 2011 05:04:01 +0000 Subject: [PATCH] Don't crash on constant right shift. From-SVN: r170307 --- gcc/go/gofrontend/expressions.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index ebe4f282f8f..a073f9dfae9 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -5859,13 +5859,21 @@ Binary_expression::do_get_tree(Translate_context* context) tree eval_saved = NULL_TREE; if (is_shift_op) { - if (!DECL_P(left)) - left = save_expr(left); - if (!DECL_P(right)) - right = save_expr(right); // Make sure the values are evaluated. - eval_saved = fold_build2_loc(this->location(), COMPOUND_EXPR, - void_type_node, left, right); + if (!DECL_P(left) && TREE_SIDE_EFFECTS(left)) + { + left = save_expr(left); + eval_saved = left; + } + if (!DECL_P(right) && TREE_SIDE_EFFECTS(right)) + { + right = save_expr(right); + if (eval_saved == NULL_TREE) + eval_saved = right; + else + eval_saved = fold_build2_loc(this->location(), COMPOUND_EXPR, + void_type_node, eval_saved, right); + } } tree ret = fold_build2_loc(this->location(), @@ -5914,8 +5922,9 @@ Binary_expression::do_get_tree(Translate_context* context) ret = fold_build3_loc(this->location(), COND_EXPR, TREE_TYPE(left), compare, ret, overflow_result); - ret = fold_build2_loc(this->location(), COMPOUND_EXPR, - TREE_TYPE(ret), eval_saved, ret); + if (eval_saved != NULL_TREE) + ret = fold_build2_loc(this->location(), COMPOUND_EXPR, + TREE_TYPE(ret), eval_saved, ret); } return ret; -- 2.30.2