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: Florian Weimer
Subject: Re: GCC optimizes integer overflow: bug or feature?
Date: Tue, 19 Dec 2006 14:37:32 +0100

* Joseph S. Myers:

> On Tue, 19 Dec 2006, Florian Weimer wrote:
>
>> * Paolo Bonzini:
>> 
>> > Interesting read.  I agree with the proposed fix; however, note that
>> > GCC does not make the result of overflowing signed left-shifts
>> > undefined, exactly because in this case the overflow is relied upon by
>> > too many existing programs
>> 
>> Is this documented somewhere?  Without documentation, it could also be
>> an oversight (lack of optimization) from a programmer perspective.
>
> Certainly, in implement-c.texi:
>
>       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.

Thanks, I missed that paragraph.  But I fail to see how this is
helpful in any way to a programmer.  To me, it reads like "we've got
some predictable semantics in some cases, but we don't tell you what
they are, and if you rely on them by chance, your code may break with
the next compiler release, without notice".

Something like:

        GCC does not use the latitude given in C99 only to treat
        certain aspects of signed @samp{<<} as undefined: If the right
        operand @var{n} is non-negative and less than the width of the
        left operand @var{val}, the resulting value @address@hidden <<
        @var{n}} is guaranteed to be equal to @var{val} times 2 to the
        @var{n}th power under 2-complement arithmetic.

would probably settle the issue, but it's unwieldy.




reply via email to

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