[PATCH] Document arithmetic overflow semantics
Fergus Henderson
fjh@cs.mu.OZ.AU
Fri Feb 14 08:00:00 GMT 2003
On 13-Feb-2003, Robert Dewar <dewar@gnat.com> wrote:
> > Suppose we denote the three variants of "+" as follows:
> >
> > +undef undefined behaviour on overflow
> > +wrap wraps on overflow
> > +trap traps on overflow
>
> I still don't see how +wrap differs from an unsigned addition, so it seems
> simply confusing to have it around explicitly.
You are right that +wrap has the same semantics as an unsigned addition.
But I don't think it would be confusing to have it around explicitly,
and I do think that doing this would make things a lot easier.
In GCC trees the signedness of additions is determined by the signedness
of the types of the operands. Representing +wrap additions as unsigned
operations would require that the operations be converted to unsigned
types. This will require more tree nodes, which may have a compilation
time impact, and the additional conversions would complicate the intermediate
representation in ways that may inhibit some optimizations.
I think it would be much better to adopt a consistent approach which will
work for all arithmetic operations, not just plus and minus.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
More information about the Gcc
mailing list