Menu

#19 zero minus bug

open
nobody
None
5
2004-05-25
2004-05-25
Anonymous
No

There seems to be a problem with subtracting a number
from zero.
Instead of just negating the number, it just ignored the
zero minus. For example:
x = 0 - y
seems to result in:
x = y

In the code in eval.c, I see:
case op_minus:
x = b - a;
break; /* !!!!! */
where all the other operators use a and b in the other
order. It seems someone else has flagged this as well.
This seems odd -- why is it that way?

Or maybe the optimizer gets rid of the zero minus in
optimize.c:
/* optimize trivial constant operators like +0, *1,
==true etc. */
if ((p->next != NULL)
&& (p->next->kind == node_ref)
&& node_is_some_constant(p->next->first)
) {

if ((p->op == op_plus)
|| (p->op == op_minus)
|| (p->op == op_shift_left)
|| (p->op == op_shift_right)
) {
if (node_is_constant(p->next, 0)) {

I am confused by the swapping of the operands - maybe
the optimizer is too :)

Hope this helps!!

- Kevin Wood
wood@kos.net

Discussion


Log in to post a comment.

MongoDB Logo MongoDB