This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC optimizes integer overflow: bug or feature?


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
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]