Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Doug Evans" <dje@google.com>
To: "GDB Patches" <gdb-patches@sourceware.org>
Cc: "Pierre Muller" <muller@ics.u-strasbg.fr>
Subject: Re: [BUG] BINOP_DIV and ptyp command
Date: Tue, 29 Jan 2008 05:26:00 -0000	[thread overview]
Message-ID: <e394668d0801282052g3c3b0510l3448f39a5a6d78f0@mail.gmail.com> (raw)
In-Reply-To: <002301c85c12$a73a4640$f5aed2c0$@u-strasbg.fr>

On Jan 21, 2008 1:47 AM, Pierre Muller <muller@ics.u-strasbg.fr> wrote:
> The ptyp command returns inconsistent types for the c '/'(BINOP_DIV)
> operator:
>
> (gdb) ptyp 3 / 2
> type = int
> (gdb) p 3 / 2
> $4 = 1
> (gdb) ptyp 3.0 / 2
> type = double
> (gdb) p 3.0 / 2
> $5 = 1.5
> (gdb) ptyp 3 / 2.0
> type = int
> (gdb) p 3 / 2.0
> $6 = 1.5
>
> I suspect that this bug is due to the fact that
> the type of this binary operator is inferred from the
> left node type, but this is wrong in the case '3 / 2.0'
>
>
> Pierre Muller

I may be missing something, but it seems like special casing
EVAL_AVOID_SIDE_EFFECTS for DIV/MOD/REM is no longer useful here (one
can imagine that it was added way back when to avoid division by zero,
but I'm just guessing).  I don't see any need to special case this
here, value_binop will catch integer division by zero and doesn't have
any special checks for floating point division by 0 (uses host fp
which can result in +/-inf, and isn't necessarily accurate for the
target at any rate, but that's an orthogonal issue).  If it were a
case of wanting to avoid tripping over the call to error("Division by
zero") then I'd expect to also see special casing of "1 >> 3.0" when
EVAL_AVOID_SIDE_EFFECTS.  Also note that for integer MOD, "division by
zero" isn't an issue.

So it seems like the following is the correct patch.

2008-01-28  Doug Evans  <dje@google.com>

        * eval.c (evaluate_subexp_standard): If DIV/REM/MOD and
        EVAL_AVOID_SIDE_EFFECTS, remove special case and process normally.

Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.77
diff -u -p -u -p -r1.77 eval.c
--- eval.c      18 Jan 2008 17:07:39 -0000      1.77
+++ eval.c      29 Jan 2008 04:37:52 -0000
@@ -1509,9 +1509,6 @@ evaluate_subexp_standard (struct type *e
        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))
-       return value_zero (value_type (arg1), not_lval);
       else
        return value_binop (arg1, arg2, op);


       reply	other threads:[~2008-01-29  4:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <002301c85c12$a73a4640$f5aed2c0$@u-strasbg.fr>
2008-01-29  5:26 ` Doug Evans [this message]
2008-01-29  6:32   ` Doug Evans
2008-01-29 14:42     ` Daniel Jacobowitz
2008-01-29 16:16       ` Doug Evans
2008-01-29 16:24         ` Doug Evans
2008-01-29 16:37           ` Daniel Jacobowitz
2008-01-29  7:35   ` Joel Brobecker
2008-01-29  7:51     ` Pierre Muller
2008-01-29 13:46       ` Daniel Jacobowitz
2008-01-29 15:17         ` Pierre Muller
2008-01-29 16:25           ` 'Daniel Jacobowitz'
2008-01-29 16:04       ` Doug Evans
2008-01-29 16:34         ` Pierre Muller
2008-01-29 15:51     ` Doug Evans
2008-01-29 16:49       ` Daniel Jacobowitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e394668d0801282052g3c3b0510l3448f39a5a6d78f0@mail.gmail.com \
    --to=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=muller@ics.u-strasbg.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox