aboutsummaryrefslogtreecommitdiff
path: root/gdb/eval.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2008-02-04 00:23:05 +0000
committerDoug Evans <dje@google.com>2008-02-04 00:23:05 +0000
commit301f0ecf99facbe3fd62ccefbc69a3dd3acc7235 (patch)
tree412062f600c084e692c054aed6b904527f6eac46 /gdb/eval.c
parente44a2c9c3dd1e12fd2707c6407d3763fa8acae17 (diff)
downloadgdb-301f0ecf99facbe3fd62ccefbc69a3dd3acc7235.zip
gdb-301f0ecf99facbe3fd62ccefbc69a3dd3acc7235.tar.gz
gdb-301f0ecf99facbe3fd62ccefbc69a3dd3acc7235.tar.bz2
* eval.c (evaluate_subexp_standard): Fix type of result of mixed
integer/float division operations when EVAL_AVOID_SIDE_EFFECTS. * valops.c (value_one): New function. * value.h (value_one): Declare. Fix argument promotion for binary arithmetic ops for C. * valarith.c (unop_result_type): New fn. (binop_result_type): New fn. (value_binop): Move result type computation to binop_result_type. (value_pos, value_neg, value_complement): Move result type computation to unop_result_type. * gdb.base/whatis-exp.exp: Fix expected result of whatis x+y, x-y, x*y.
Diffstat (limited to 'gdb/eval.c')
-rw-r--r--gdb/eval.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/gdb/eval.c b/gdb/eval.c
index 6e5be65..efe1dc2 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1518,12 +1518,30 @@ evaluate_subexp_standard (struct type *expect_type,
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
- else if (noside == EVAL_AVOID_SIDE_EFFECTS
- && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD
- || op == BINOP_INTDIV))
- return value_zero (value_type (arg1), not_lval);
else
- return value_binop (arg1, arg2, op);
+ {
+ /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
+ fudge arg2 to avoid division-by-zero, the caller is
+ (theoretically) only looking for the type of the result. */
+ if (noside == EVAL_AVOID_SIDE_EFFECTS
+ /* ??? Do we really want to test for BINOP_MOD here?
+ The implementation of value_binop gives it a well-defined
+ value. */
+ && (op == BINOP_DIV
+ || op == BINOP_INTDIV
+ || op == BINOP_REM
+ || op == BINOP_MOD)
+ && value_logical_not (arg2))
+ {
+ struct value *v_one, *retval;
+
+ v_one = value_one (value_type (arg2), not_lval);
+ retval = value_binop (arg1, v_one, op);
+ return retval;
+ }
+ else
+ return value_binop (arg1, arg2, op);
+ }
case BINOP_RANGE:
arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);