This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: 20040309-1.c vs overflow being undefined
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: falk at debian dot org (Falk Hueffner)
- Cc: pinskia at physics dot uc dot edu (Andrew Pinski), gcc at gcc dot gnu dot org
- Date: Sun, 27 Nov 2005 12:25:28 -0500 (EST)
- Subject: Re: 20040309-1.c vs overflow being undefined
>
> Andrew Pinski <pinskia@physics.uc.edu> 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 when we pass 65535 to foo (like in the testcase),
> > we get some large negative number for (signed int)x
>
> That shouldn't happen. Promoting from unsigned short to int shouldn't
> sign extend. If you see it happening, then that's a bug.
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).
-- Pinski