From f44316fa94c208d45b37782734469d178d31b273 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Thu, 11 Sep 2008 14:15:01 +0000 Subject: [PATCH] * eval.c (evaluate_subexp_standard): Add calls to binop_promote and unop_promote before calling value_binop et. al. * ada-lang.c (ada_evaluate_subexp): Add calls to binop_promote and unop_promote before calling value_binop et. al. * valarith.c (value_binop): Do not call binop_promote or unop_promote. (value_pos): Do not call unop_promote. (value_neg, value_complement): Likewise. --- gdb/ChangeLog | 11 +++++++ gdb/ada-lang.c | 43 ++++++++++++++++++++++---- gdb/eval.c | 82 +++++++++++++++++++++++++++++++++++++++++++------- gdb/valarith.c | 14 --------- 4 files changed, 119 insertions(+), 31 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f6d18e13bd..bb72d9d2a2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2008-09-11 Ulrich Weigand + + * eval.c (evaluate_subexp_standard): Add calls to binop_promote + and unop_promote before calling value_binop et. al. + * ada-lang.c (ada_evaluate_subexp): Add calls to binop_promote + and unop_promote before calling value_binop et. al. + + * valarith.c (value_binop): Do not call binop_promote or unop_promote. + (value_pos): Do not call unop_promote. + (value_neg, value_complement): Likewise. + 2008-09-11 Ulrich Weigand * value.h (unop_promote, binop_promote): Add prototypes. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 2142b16420..840b5ed634 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -8463,6 +8463,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, type = value_type (arg1); while (TYPE_CODE (type) == TYPE_CODE_REF) type = TYPE_TARGET_TYPE (type); + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); return value_cast (type, value_binop (arg1, arg2, BINOP_ADD)); case BINOP_SUB: @@ -8484,6 +8485,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, type = value_type (arg1); while (TYPE_CODE (type) == TYPE_CODE_REF) type = TYPE_TARGET_TYPE (type); + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); return value_cast (type, value_binop (arg1, arg2, BINOP_SUB)); case BINOP_MUL: @@ -8501,6 +8503,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, arg1 = cast_from_fixed_to_double (arg1); if (ada_is_fixed_point_type (value_type (arg2))) arg2 = cast_from_fixed_to_double (arg2); + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); return ada_value_binop (arg1, arg2, op); } @@ -8514,7 +8517,10 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) return value_zero (value_type (arg1), not_lval); else - return ada_value_binop (arg1, arg2, op); + { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + return ada_value_binop (arg1, arg2, op); + } case BINOP_EQUAL: case BINOP_NOTEQUAL: @@ -8525,7 +8531,10 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, if (noside == EVAL_AVOID_SIDE_EFFECTS) tem = 0; else - tem = ada_value_equal (arg1, arg2); + { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + tem = ada_value_equal (arg1, arg2); + } if (op == BINOP_NOTEQUAL) tem = !tem; type = language_bool_type (exp->language_defn, exp->gdbarch); @@ -8538,7 +8547,10 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, else if (ada_is_fixed_point_type (value_type (arg1))) return value_cast (value_type (arg1), value_neg (arg1)); else - return value_neg (arg1); + { + unop_promote (exp->language_defn, exp->gdbarch, &arg1); + return value_neg (arg1); + } case BINOP_LOGICAL_AND: case BINOP_LOGICAL_OR: @@ -8823,6 +8835,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, case TYPE_CODE_RANGE: arg2 = value_from_longest (type, TYPE_LOW_BOUND (type)); arg3 = value_from_longest (type, TYPE_HIGH_BOUND (type)); + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3); type = language_bool_type (exp->language_defn, exp->gdbarch); return value_from_longest (type, @@ -8854,6 +8868,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, arg3 = ada_array_bound (arg2, tem, 1); arg2 = ada_array_bound (arg2, tem, 0); + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3); type = language_bool_type (exp->language_defn, exp->gdbarch); return value_from_longest (type, @@ -8870,6 +8886,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, if (noside == EVAL_SKIP) goto nosideret; + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3); type = language_bool_type (exp->language_defn, exp->gdbarch); return value_from_longest (type, @@ -9017,8 +9035,11 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, else if (noside == EVAL_AVOID_SIDE_EFFECTS) return value_zero (value_type (arg1), not_lval); else - return value_binop (arg1, arg2, - op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX); + { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + return value_binop (arg1, arg2, + op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX); + } case OP_ATR_MODULUS: { @@ -9076,7 +9097,16 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, else if (noside == EVAL_AVOID_SIDE_EFFECTS) return value_zero (value_type (arg1), not_lval); else - return value_binop (arg1, arg2, op); + { + /* For integer exponentiation operations, + only promote the first argument. */ + if (is_integral_type (value_type (arg2))) + unop_promote (exp->language_defn, exp->gdbarch, &arg1); + else + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + + return value_binop (arg1, arg2, op); + } case UNOP_PLUS: arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); @@ -9089,6 +9119,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); if (noside == EVAL_SKIP) goto nosideret; + unop_promote (exp->language_defn, exp->gdbarch, &arg1); if (value_less (arg1, value_zero (value_type (arg1), not_lval))) return value_neg (arg1); else diff --git a/gdb/eval.c b/gdb/eval.c index 02de6fed51..ab7d83f1bf 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1725,7 +1725,19 @@ evaluate_subexp_standard (struct type *expect_type, else if (op == BINOP_SUB && ptrmath_type_p (value_type (arg1))) arg2 = value_ptrsub (arg1, arg2); else - arg2 = value_binop (arg1, arg2, op); + { + struct value *tmp = arg1; + + /* For shift and integer exponentiation operations, + only promote the first argument. */ + if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP) + && is_integral_type (value_type (arg2))) + unop_promote (exp->language_defn, exp->gdbarch, &tmp); + else + binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2); + + arg2 = value_binop (tmp, arg2, op); + } return value_assign (arg1, arg2); case BINOP_ADD: @@ -1740,7 +1752,10 @@ evaluate_subexp_standard (struct type *expect_type, else if (ptrmath_type_p (value_type (arg2))) return value_ptradd (arg2, arg1); else - return value_binop (arg1, arg2, BINOP_ADD); + { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + return value_binop (arg1, arg2, BINOP_ADD); + } case BINOP_SUB: arg1 = evaluate_subexp_with_coercion (exp, pos, noside); @@ -1761,7 +1776,10 @@ evaluate_subexp_standard (struct type *expect_type, return value_ptrsub (arg1, arg2); } else - return value_binop (arg1, arg2, BINOP_SUB); + { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + return value_binop (arg1, arg2, BINOP_SUB); + } case BINOP_EXP: case BINOP_MUL: @@ -1798,11 +1816,22 @@ evaluate_subexp_standard (struct type *expect_type, struct value *v_one, *retval; v_one = value_one (value_type (arg2), not_lval); + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &v_one); retval = value_binop (arg1, v_one, op); return retval; } else - return value_binop (arg1, arg2, op); + { + /* For shift and integer exponentiation operations, + only promote the first argument. */ + if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP) + && is_integral_type (value_type (arg2))) + unop_promote (exp->language_defn, exp->gdbarch, &arg1); + else + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + + return value_binop (arg1, arg2, op); + } } case BINOP_RANGE: @@ -2073,6 +2102,7 @@ evaluate_subexp_standard (struct type *expect_type, } else { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); tem = value_equal (arg1, arg2); type = language_bool_type (exp->language_defn, exp->gdbarch); return value_from_longest (type, (LONGEST) tem); @@ -2089,6 +2119,7 @@ evaluate_subexp_standard (struct type *expect_type, } else { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); tem = value_equal (arg1, arg2); type = language_bool_type (exp->language_defn, exp->gdbarch); return value_from_longest (type, (LONGEST) ! tem); @@ -2105,6 +2136,7 @@ evaluate_subexp_standard (struct type *expect_type, } else { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); tem = value_less (arg1, arg2); type = language_bool_type (exp->language_defn, exp->gdbarch); return value_from_longest (type, (LONGEST) tem); @@ -2121,6 +2153,7 @@ evaluate_subexp_standard (struct type *expect_type, } else { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); tem = value_less (arg2, arg1); type = language_bool_type (exp->language_defn, exp->gdbarch); return value_from_longest (type, (LONGEST) tem); @@ -2137,6 +2170,7 @@ evaluate_subexp_standard (struct type *expect_type, } else { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); tem = value_less (arg2, arg1) || value_equal (arg1, arg2); type = language_bool_type (exp->language_defn, exp->gdbarch); return value_from_longest (type, (LONGEST) tem); @@ -2153,6 +2187,7 @@ evaluate_subexp_standard (struct type *expect_type, } else { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); tem = value_less (arg1, arg2) || value_equal (arg1, arg2); type = language_bool_type (exp->language_defn, exp->gdbarch); return value_from_longest (type, (LONGEST) tem); @@ -2185,7 +2220,10 @@ evaluate_subexp_standard (struct type *expect_type, if (unop_user_defined_p (op, arg1)) return value_x_unop (arg1, op, noside); else - return value_pos (arg1); + { + unop_promote (exp->language_defn, exp->gdbarch, &arg1); + return value_pos (arg1); + } case UNOP_NEG: arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); @@ -2194,7 +2232,10 @@ evaluate_subexp_standard (struct type *expect_type, if (unop_user_defined_p (op, arg1)) return value_x_unop (arg1, op, noside); else - return value_neg (arg1); + { + unop_promote (exp->language_defn, exp->gdbarch, &arg1); + return value_neg (arg1); + } case UNOP_COMPLEMENT: /* C++: check for and handle destructor names. */ @@ -2206,7 +2247,10 @@ evaluate_subexp_standard (struct type *expect_type, if (unop_user_defined_p (UNOP_COMPLEMENT, arg1)) return value_x_unop (arg1, UNOP_COMPLEMENT, noside); else - return value_complement (arg1); + { + unop_promote (exp->language_defn, exp->gdbarch, &arg1); + return value_complement (arg1); + } case UNOP_LOGICAL_NOT: arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); @@ -2324,7 +2368,11 @@ evaluate_subexp_standard (struct type *expect_type, if (ptrmath_type_p (value_type (arg1))) arg2 = value_ptradd (arg1, arg2); else - arg2 = value_binop (arg1, arg2, BINOP_ADD); + { + struct value *tmp = arg1; + binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2); + arg2 = value_binop (tmp, arg2, BINOP_ADD); + } return value_assign (arg1, arg2); } @@ -2343,7 +2391,11 @@ evaluate_subexp_standard (struct type *expect_type, if (ptrmath_type_p (value_type (arg1))) arg2 = value_ptrsub (arg1, arg2); else - arg2 = value_binop (arg1, arg2, BINOP_SUB); + { + struct value *tmp = arg1; + binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2); + arg2 = value_binop (tmp, arg2, BINOP_SUB); + } return value_assign (arg1, arg2); } @@ -2362,7 +2414,11 @@ evaluate_subexp_standard (struct type *expect_type, if (ptrmath_type_p (value_type (arg1))) arg2 = value_ptradd (arg1, arg2); else - arg2 = value_binop (arg1, arg2, BINOP_ADD); + { + struct value *tmp = arg1; + binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2); + arg2 = value_binop (tmp, arg2, BINOP_ADD); + } value_assign (arg1, arg2); return arg1; @@ -2382,7 +2438,11 @@ evaluate_subexp_standard (struct type *expect_type, if (ptrmath_type_p (value_type (arg1))) arg2 = value_ptrsub (arg1, arg2); else - arg2 = value_binop (arg1, arg2, BINOP_SUB); + { + struct value *tmp = arg1; + binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2); + arg2 = value_binop (tmp, arg2, BINOP_SUB); + } value_assign (arg1, arg2); return arg1; diff --git a/gdb/valarith.c b/gdb/valarith.c index 86accdd57d..b4bce73059 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -876,14 +876,6 @@ value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) struct value *val; struct type *type1, *type2, *result_type; - /* For shift and integer exponentiation operations, - only promote the first argument. */ - if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP) - && is_integral_type (value_type (arg2))) - unop_promote (current_language, current_gdbarch, &arg1); - else - binop_promote (current_language, current_gdbarch, &arg1, &arg2); - arg1 = coerce_ref (arg1); arg2 = coerce_ref (arg2); @@ -1489,8 +1481,6 @@ value_pos (struct value *arg1) { struct type *type; - unop_promote (current_language, current_gdbarch, &arg1); - arg1 = coerce_ref (arg1); type = check_typedef (value_type (arg1)); @@ -1514,8 +1504,6 @@ value_neg (struct value *arg1) { struct type *type; - unop_promote (current_language, current_gdbarch, &arg1); - arg1 = coerce_ref (arg1); type = check_typedef (value_type (arg1)); @@ -1553,8 +1541,6 @@ value_complement (struct value *arg1) { struct type *type; - unop_promote (current_language, current_gdbarch, &arg1); - arg1 = coerce_ref (arg1); type = check_typedef (value_type (arg1)); -- 2.34.1