Re: 20040309-1.c vs overflow being undefined

2005-11-27 Thread Neil Booth
Andreas Schwab wrote:- > Andrew Pinski <[EMAIL PROTECTED]> writes: > > > sorry wrong number, I had meant 32769. > > if (foo (32769) != 1) > > abort (); > > I think with 16 bit ints you should get 0 here, since (int)32769 == > -32767, which is less than 32767. int foo(unsigned short x) {

Re: 20040309-1.c vs overflow being undefined

2005-11-27 Thread Richard Henderson
On Sun, Nov 27, 2005 at 12:25:28PM -0500, Andrew Pinski wrote: > Actually I am not seeing that but instead I am seeing the subtraction done in > short and not in int (which is far as I can tell and remember reading the > promotion rules in C doing). You're wrong about the C promotion rules. r~

Re: 20040309-1.c vs overflow being undefined

2005-11-27 Thread Andreas Schwab
Andrew Pinski <[EMAIL PROTECTED]> writes: > sorry wrong number, I had meant 32769. > if (foo (32769) != 1) > abort (); I think with 16 bit ints you should get 0 here, since (int)32769 == -32767, which is less than 32767. Andreas. -- Andreas Schwab, SuSE Labs, [EMAIL PROTECTED] SuSE Linux

Re: 20040309-1.c vs overflow being undefined

2005-11-27 Thread Andrew Pinski
> > Andrew Pinski <[EMAIL PROTECTED]> writes: > > > If we look at this testcase, we have a function like: > > int foo(unsigned short x) > > { > > unsigned short y; > > y = x > 32767 ? x - 32768 : 0; > > return y; > > } > > > > > > x is promoted to a signed int by the front-end as the type >

Re: 20040309-1.c vs overflow being undefined

2005-11-27 Thread Andrew Pinski
> > Andrew Pinski <[EMAIL PROTECTED]> writes: > > > x is promoted to a signed int by the front-end as the type > > of 32768 is signed. So when we pass 65535 to foo (like in the testcase), > > we get some large negative number for (signed int)x > > I don't see how you can get a large negative nu

Re: 20040309-1.c vs overflow being undefined

2005-11-27 Thread Falk Hueffner
Andrew Pinski <[EMAIL PROTECTED]> writes: > If we look at this testcase, we have a function like: > int foo(unsigned short x) > { > unsigned short y; > y = x > 32767 ? x - 32768 : 0; > return y; > } > > > x is promoted to a signed int by the front-end as the type > of 32768 is signed. So wh

Re: 20040309-1.c vs overflow being undefined

2005-11-27 Thread Andreas Schwab
Andrew Pinski <[EMAIL PROTECTED]> writes: > x is promoted to a signed int by the front-end as the type > of 32768 is signed. So when we pass 65535 to foo (like in the testcase), > we get some large negative number for (signed int)x I don't see how you can get a large negative number for that. W

20040309-1.c vs overflow being undefined

2005-11-27 Thread Andrew Pinski
If we look at this testcase, we have a function like: int foo(unsigned short x) { unsigned short y; y = x > 32767 ? x - 32768 : 0; return y; } x is promoted to a signed int by the front-end as the type of 32768 is signed. So when we pass 65535 to foo (like in the testcase), we get some lar