[PATCH] Document arithmetic overflow semantics

Richard Henderson rth@redhat.com
Thu Feb 13 17:58:00 GMT 2003


On Thu, Feb 13, 2003 at 07:22:42AM -0700, Roger Sayle wrote:
> Hi Richard,
> > I think that's backwards.  If program in C, C++, or Ada generates an
> > overflow, that program is undefined.  That means the optimizer can do
> > anything it wants to the program, which, in turn, means that the optimizer
> > can assume that overflow *does not* occur, and that allows a lot more
> > optimizations.
> 
> I completely disagree, and so do GCC's patch reviewers.

Huh?  I for one agree with Kenner.  Using the undefinedness of
something to infer that it doesn't happen is well-established.

> The behaviour of a program with optimization should always be the
> same as its behaviour without optimization.

For conformant code, yes.  For undefined code, no.

For a very popular example of this *not* happening for
non-conformant code is type-based aliasing.  This regularly
catches folks by "mis-scheduling" their code.



r~



More information about the Gcc mailing list