Discussion:
[9fans] arm compiler bug
(too old to reply)
c***@gmx.de
2013-01-02 09:05:49 UTC
Permalink
0 < -0x80000000 == 1 with 5c.

the problem is caused by this:

if(a == ACMP && f1->op == OCONST && p->from.offset < 0) {
p->as = ACMN;
p->from.offset = -p->from.offset;
}

because 0x80000000 == -0x80000000

adding the following check to that if expression fixes it:

&& p->from.offset != -p->from.offset

silly python code.

--
cinap
Richard Miller
2013-01-02 09:26:10 UTC
Permalink
Good catch.

2's complement integers are generally useful but it's easy to
forget that they don't quite obey normal algebraic rules.
The assumption that
(a < 0) => (-a > 0)
is the cause of many easily-missed bugs.
erik quanstrom
2013-01-02 15:07:00 UTC
Permalink
Post by c***@gmx.de
0 < -0x80000000 == 1 with 5c.
i get the same results for all compilers:
0 < -0x80000000......yes
1 == -0x80000000......no
0 < -0x80000000 == 1......yes

for [568]c. the last one is correct since the order of operations are
(0 < -0x80000000) == 1
which is clearly true.

- erik

#include <u.h>
#include <libc.h>

void
yesno(char *s, int bool)
{
print("%s...", s);
if(bool)
print("yes\n");
else
print("no\n");
}
void
main(void)
{
yesno("0 < -0x80000000...", 0 < -0x80000000);
yesno("1 == -0x80000000...", 1 == -0x80000000);
yesno("0 < -0x80000000 == 1...", 0 < -0x80000000 == 1);
exits("");
}
Charles Forsyth
2013-01-02 15:53:48 UTC
Permalink
those are being done at compile time.
Charles Forsyth
2013-01-02 15:55:45 UTC
Permalink
and 0x80000000 is thereby unsigned int, which changes the nature of
the comparison.
Post by Charles Forsyth
those are being done at compile time.
Matthew Veety
2013-01-02 18:32:05 UTC
Permalink
Is this related to the bug I found in python on arm?
Post by c***@gmx.de
0 < -0x80000000 == 1 with 5c.
if(a == ACMP && f1->op == OCONST && p->from.offset < 0) {
p->as = ACMN;
p->from.offset = -p->from.offset;
}
because 0x80000000 == -0x80000000
&& p->from.offset != -p->from.offset
silly python code.
--
cinap
erik quanstrom
2013-01-02 18:34:25 UTC
Permalink
Post by Matthew Veety
Is this related to the bug I found in python on arm?
it would be much more helpful if "the bug" and "python code"
were replaced with specific references.

- erik
c***@gmx.de
2013-01-02 20:16:34 UTC
Permalink
the offending line that triggered it is in Python/getargs.c
in the convertsimple() function (the ival < INT_MIN comparsion):

case 'i': {/* signed int */
int *p = va_arg(*p_va, int *);
long ival;
if (float_argument_error(arg))
return converterr("integer<i>", arg, msgbuf, bufsize);
ival = PyInt_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
return converterr("integer<i>", arg, msgbuf, bufsize);
else if (ival > INT_MAX) {
PyErr_SetString(PyExc_OverflowError,
"signed integer is greater than maximum");
return converterr("integer<i>", arg, msgbuf, bufsize);
}
else if (ival < INT_MIN) {
PyErr_SetString(PyExc_OverflowError,
"signed integer is less than minimum");
return converterr("integer<i>", arg, msgbuf, bufsize);
}
else
*p = ival;
break;
}

aijus 5e userspace arm emulator was a great help for reproducing
this as i dint have a raspi.

--
cinap

c***@gmx.de
2013-01-02 20:11:20 UTC
Permalink
yes.

--
cinap
Loading...