9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] arm compiler bug
@ 2013-01-02  9:05 cinap_lenrek
  2013-01-02  9:26 ` Richard Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: cinap_lenrek @ 2013-01-02  9:05 UTC (permalink / raw)
  To: 9fans

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] arm compiler bug
  2013-01-02  9:05 [9fans] arm compiler bug cinap_lenrek
@ 2013-01-02  9:26 ` Richard Miller
  2013-01-02 15:07 ` erik quanstrom
  2013-01-02 18:32 ` Matthew Veety
  2 siblings, 0 replies; 9+ messages in thread
From: Richard Miller @ 2013-01-02  9:26 UTC (permalink / raw)
  To: 9fans

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.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] arm compiler bug
  2013-01-02  9:05 [9fans] arm compiler bug cinap_lenrek
  2013-01-02  9:26 ` Richard Miller
@ 2013-01-02 15:07 ` erik quanstrom
  2013-01-02 15:53   ` Charles Forsyth
  2013-01-02 18:32 ` Matthew Veety
  2 siblings, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2013-01-02 15:07 UTC (permalink / raw)
  To: cinap_lenrek, 9fans

On Wed Jan  2 04:07:28 EST 2013, cinap_lenrek@gmx.de wrote:
> 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("");
}



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] arm compiler bug
  2013-01-02 15:07 ` erik quanstrom
@ 2013-01-02 15:53   ` Charles Forsyth
  2013-01-02 15:55     ` Charles Forsyth
  0 siblings, 1 reply; 9+ messages in thread
From: Charles Forsyth @ 2013-01-02 15:53 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

those are being done at compile time.

On 2 January 2013 15:07, erik quanstrom <quanstro@quanstro.net> wrote:
> i get the same results for all compilers:



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] arm compiler bug
  2013-01-02 15:53   ` Charles Forsyth
@ 2013-01-02 15:55     ` Charles Forsyth
  0 siblings, 0 replies; 9+ messages in thread
From: Charles Forsyth @ 2013-01-02 15:55 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

and 0x80000000 is thereby unsigned int, which changes the nature of
the comparison.

On 2 January 2013 15:53, Charles Forsyth <charles.forsyth@gmail.com> wrote:
> those are being done at compile time.
>
> On 2 January 2013 15:07, erik quanstrom <quanstro@quanstro.net> wrote:
>> i get the same results for all compilers:



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] arm compiler bug
  2013-01-02  9:05 [9fans] arm compiler bug cinap_lenrek
  2013-01-02  9:26 ` Richard Miller
  2013-01-02 15:07 ` erik quanstrom
@ 2013-01-02 18:32 ` Matthew Veety
  2013-01-02 18:34   ` erik quanstrom
  2013-01-02 20:11   ` cinap_lenrek
  2 siblings, 2 replies; 9+ messages in thread
From: Matthew Veety @ 2013-01-02 18:32 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Is this related to the bug I found in python on arm?

On Jan 2, 2013, at 4:05, cinap_lenrek@gmx.de wrote:

> 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
>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] arm compiler bug
  2013-01-02 18:32 ` Matthew Veety
@ 2013-01-02 18:34   ` erik quanstrom
  2013-01-02 20:16     ` cinap_lenrek
  2013-01-02 20:11   ` cinap_lenrek
  1 sibling, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2013-01-02 18:34 UTC (permalink / raw)
  To: 9fans

On Wed Jan  2 13:32:30 EST 2013, mveety@gmail.com wrote:
> 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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] arm compiler bug
  2013-01-02 18:32 ` Matthew Veety
  2013-01-02 18:34   ` erik quanstrom
@ 2013-01-02 20:11   ` cinap_lenrek
  1 sibling, 0 replies; 9+ messages in thread
From: cinap_lenrek @ 2013-01-02 20:11 UTC (permalink / raw)
  To: 9fans

yes.

--
cinap



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] arm compiler bug
  2013-01-02 18:34   ` erik quanstrom
@ 2013-01-02 20:16     ` cinap_lenrek
  0 siblings, 0 replies; 9+ messages in thread
From: cinap_lenrek @ 2013-01-02 20:16 UTC (permalink / raw)
  To: 9fans

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-01-02 20:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-02  9:05 [9fans] arm compiler bug cinap_lenrek
2013-01-02  9:26 ` Richard Miller
2013-01-02 15:07 ` erik quanstrom
2013-01-02 15:53   ` Charles Forsyth
2013-01-02 15:55     ` Charles Forsyth
2013-01-02 18:32 ` Matthew Veety
2013-01-02 18:34   ` erik quanstrom
2013-01-02 20:16     ` cinap_lenrek
2013-01-02 20:11   ` cinap_lenrek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).