This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] Detect most integer overflows.
- From: Andrew Haley <aph at redhat dot com>
- To: David Brown <david at westcontrol dot com>
- Cc: OndÅej BÃlka <neleai at seznam dot cz>, Trevor Saunders <tsaunders at mozilla dot com>, gcc at gcc dot gnu dot org
- Date: Thu, 31 Oct 2013 16:51:16 +0000
- Subject: Re: [RFC] Detect most integer overflows.
- Authentication-results: sourceware.org; auth=none
- References: <20131026192912 dot GA25428 at domone dot podge> <20131026235014 dot GF18009 at order dot stressinduktion dot org> <CAFiYyc0+wTbE1FwwLscquWvoEtM6JQw4p5qhnhBmGtVCMkx9fQ at mail dot gmail dot com> <20131030083413 dot GA12183 at domone dot podge> <5270C63C dot 6030406 at redhat dot com> <CAEwic4a9O7a2S34NEzZ5iq2oef=5Agmr863Thj5=MsENa_nxGg at mail dot gmail dot com> <20131030144909 dot GA4555 at tsaunders-iceball dot corp dot tor1 dot mozilla dot com> <20131030145959 dot GA15771 at domone dot podge> <52712468 dot 3060308 at westcontrol dot com> <52712C10 dot 6040403 at redhat dot com> <52720E9D dot 90506 at westcontrol dot com>
On 10/31/2013 08:02 AM, David Brown wrote:
> On 30/10/13 16:56, Andrew Haley wrote:
>> On 10/30/2013 03:23 PM, David Brown wrote:
>>> I believe that's only a minor reason for making signed overflows
>>> undefined behaviour. If it were a matter of implementation, I think it
>>> would have been made "implementation defined" rather than "undefined",
>>> so that two's complement machines could use wrapping while other systems
>>> (which are very rare now) could have other defined overflow behaviour.
>>>
>>> The main reason (again, this is my guess - I don't know what the C
>>> standards folk /actually/ thought) is that there is no obvious "correct"
>>> behaviour for signed overflow
>>
>> A more important reason that having signed overflow undefined allows
>> a lot of powerful loop optimization algorithms.
>
> Didn't I mention that? I certainly meant to!
>
> There was a recent discussion on comp.lang.c about this. I don't know
> how one could (or should) grade the relative importance of reasons, but
> certainly by having signed overflow as undefined you can enable many
> nice optimisations. These don't really turn up in "normal" code
They do:
for (int i = 0; i < 5; i ++)
a(p + i * 10);
->
for (int p1 = p; p1 < p + 50; p1 += 10)
a(p1);
Andrew.