This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Where does the C standard describe overflow of signedintegers?
- From: Paul Schlie <schlie at comcast dot net>
- To: Paul Koning <pkoning at equallogic dot com>
- Cc: <dewar at adacore dot com>,<mattheww at chiark dot greenend dot org dot uk>,<gcc at gcc dot gnu dot org>
- Date: Thu, 14 Jul 2005 17:58:46 -0400
- Subject: Re: Where does the C standard describe overflow of signedintegers?
> From: Paul Koning <pkoning@equallogic.com>
>>>>>> "Paul" == Paul Schlie <schlie@comcast.net> writes:
>>> From: Robert Dewar <dewar@adacore.com>
>>>> Paul Schlie wrote:
>>>>> What about optimising x*2/2 to x?
>>>> Given that "C" requires the above be evaluated as (x*2)/2, as the
>>>> language specifies that the syntax defines the precedence of the
>>>> operations, and that no optimization should alter the behavior as
>>>> specified by the program; I'd say that unless it was known that
>>>> the value range of x was between 0 and INT_MAX, the optimization
>>>> is simply invalid.
>>> the optimization is indeed valid
>>>
>>> optimizations may most certainly alter behavior of undefined
>>> code. think about uninitialized local variables.
>
> Paul> I don't contest that it may, I simply don't believe it should.
>
> In that case you may want to stick with -O0. There are *lots* of
> things GCC does that alter undefined cases. How about the undefined
> behavior when aliasing rules are violated? Would you want to make
> -fno-strict-aliasing be the only supported setting?
- Isn't the purpose of "restrict" to explicitly enable the compiler to
more aggressively optimize references which it may be not have been
able to identify it as being strictly safe? (As opposed to it feeling
compelled presume potentially disastrously otherwise, without explicit
permission to do so?)