This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Document arithmetic overflow semantics
- From: Fergus Henderson <fjh at cs dot mu dot OZ dot AU>
- To: Robert Dewar <dewar at gnat dot com>
- Cc: jbuck at synopsys dot com, gcc-patches at gcc dot gnu dot org, gcc at gcc dot gnu dot org, kenner at vlsi1 dot ultra dot nyu dot edu, roger at www dot eyesopen dot com
- Date: Fri, 14 Feb 2003 18:20:41 +1100
- Subject: Re: [PATCH] Document arithmetic overflow semantics
- References: <20030213190720.E9620F2D5E@nile.gnat.com>
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.