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: [PATCH] Document arithmetic overflow semantics


On Thu, Feb 13, 2003 at 08:08:30AM -0500, Richard Kenner wrote:
>     + For integral types, negation is the same as subtraction from zero.
>     + Because the range of two's-complement values in not symmetric, the
>     + negation of the maximum negative integer results in the same maximum
>     + negative number.
> 
> I *really* don't like defining the tree operations as having this overflow
> behavior.    I have three major problems with it:
> 
> (1) It removes the potential of optimizations that assume such overflow cannot
>     occur in languages where it is undefined (C, C++, and Ada).

In C, it is frequently the case that defining the overflow behavior of
signed integer in this way makes more optimizations possible.  For one
thing, it makes addition and multiplication associative.  Without such
an assumption, you can't turn (a+b)+c into a+(b+c), because the overflows
might be different.

> (2) It represents an implementation difficulty and perhaps cost on machines
>     where this behavior is not present (for example, where it traps).

I'd hate to implement C on a machine that forces a trap on integer
overflows.

> (3) It does not allow representing trapping arithmetic in the three.
> 
> My suggestion is to use a bit in either the type (my preference) or the
> operation to say whether overflow is defined or not.  There can be a bit in
> the operation to require that it trap if it overflow.

If this were done, then it would be a very good idea to mark the C int
type as having defined overflow behavior, with the possibility of changing
this if someone wants to port to a strange machine.


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