bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GCC optimizes integer overflow: bug or feature?


From: Joseph S. Myers
Subject: Re: GCC optimizes integer overflow: bug or feature?
Date: Tue, 19 Dec 2006 13:45:10 +0000 (UTC)

On Tue, 19 Dec 2006, Robert Dewar wrote:

> >     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.
> 
> That hardly seems sufficient documentation, when documenting undefined,
> you had better say what the semantics is. Saying it is not treated as
> undefined, and then failing to define it is a bit of a contradiction
> in terms :-)

That's documented in the previous paragraphs:

        @item
        @cite{The results of some bitwise operations on signed integers (C90
        6.3, C99 6.5).}

        Bitwise operators act on the representation of the value including
        both the sign and value bits, where the sign bit is considered
        immediately above the highest-value value bit.  Signed @samp{>>} acts
        on negative numbers by sign extension.

> What is (a*2)/2 optimized to? certainly it has the value a if you wrap, so you
> are not necessarily depending on undefined here.

It's optimized to a (and has been since at least 2.7.2.3, the earliest 
version I have around - though it wasn't until 3.0 that this optimization 
was fixed to apply only to signed types and not unsigned types as well).  
But if you wrap, (INT_MIN*2)/2 would be 0 not INT_MIN, for example.

-- 
Joseph S. Myers
address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]