This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: bad optimization
- From: Andrew Haley <aph at redhat dot com>
- To: "Andy Falanga (afalanga)" <afalanga at micron dot com>
- Cc: Brian Budge <brian dot budge at gmail dot com>, GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Wed, 21 Aug 2013 16:21:22 +0100
- Subject: Re: bad optimization
- References: <CANjXV6_=hQQPtk78VkumtHXhK+rE-UkT=-ibBx83BqYsS+sp5w at mail dot gmail dot com> <5213BE12 dot 6050207 at redhat dot com> <60F6FAE47D1BCE4380CC06D18F49789B4FB1CF4D at NTXBOIMBX02 dot micron dot com>
On 08/21/2013 03:49 PM, Andy Falanga (afalanga) wrote:
>> -----Original Message-----
>> From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
>> Behalf Of Andrew Haley
>> Sent: Tuesday, August 20, 2013 1:06 PM
>> To: Brian Budge
>> Cc: GCC-help
>> Subject: Re: bad optimization
>>
>> On 08/20/2013 07:34 PM, Brian Budge wrote:
>>> Is this an example of undefined behavior, or should I file a bug?
>>
>> It's an example of undefined behavior. No bug.
>
> For the ignorant (me), can you explain why it's undefined?
Signed integer overflow is always undefined in C++:
(5/5 C++03, 5/4 C++11) If during the evaluation of an
expression, the result is not mathematically defined or not in the
range of representable values for its type, the behavior is
undefined.
(3.9.1/4) Unsigned integers, declared unsigned, shall obey the
laws of arithmetic modulo 2^n where n is the number of bits in the
value representation of that particular size of integer. This
implies that unsigned arithmetic does not overflow because a
result that cannot be represented by the resulting unsigned
integer type is reduced modulo the number that is one greater than
the largest value that can be represented by the resulting
unsigned integer type.
Andrew.