bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GCC optimizes integer overflow: bug or feature?


From: Joseph S. Myers
Subject: Re: GCC optimizes integer overflow: bug or feature?
Date: Tue, 19 Dec 2006 13:22:55 +0000 (UTC)

On Tue, 19 Dec 2006, Florian Weimer wrote:

> * Paolo Bonzini:
> 
> > Interesting read.  I agree with the proposed fix; however, note that
> > GCC does not make the result of overflowing signed left-shifts
> > undefined, exactly because in this case the overflow is relied upon by
> > too many existing programs
> 
> Is this documented somewhere?  Without documentation, it could also be
> an oversight (lack of optimization) from a programmer perspective.

Certainly, in implement-c.texi:

        GCC does not use the latitude given in C99 only to treat certain
        aspects of signed @samp{<<} as undefined, but this is subject to
        change.

This particular case has the special property that signed << was 
implementation-defined in C90 (DR#081) and became undefined in some cases 
in C99.

We've optimized expressions such as (a*2)/2 on the basis of overflow being 
undefined for a very long time, not just loops.

-- 
Joseph S. Myers
address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]