This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Ada front-end depends on signed overflow
- From: Paul Schlie <schlie at comcast dot net>
- To: Michael Veksler <VEKSLER at il dot ibm dot com>
- Cc: <bosch at gnat dot com>,Robert Dewar <dewar at adacore dot com>,Florian Weimer <fw at deneb dot enyo dot de>,GCC List <gcc at gcc dot gnu dot org>,Andrew Pinski <pinskia at physics dot uc dot edu>
- Date: Wed, 08 Jun 2005 14:16:46 -0400
- Subject: Re: Ada front-end depends on signed overflow
> From: Michael Veksler <VEKSLER@il.ibm.com>
>> Paul Schlie wrote on 08/06/2005 17:53:04:
>> - I would have if someone could provide a concrete example of an
>> undefined behavior which produces a reliably useful/predictable result.
>>
> Well this is a simple hackery quiz, which is irrelevant to GCC.
>
> 1: int a, b;
> 2: int f() { return b++; }
> 3: int main(int argc)
> 4: {
> 5: b= argc;
> 6: a= b + f(); /* a==b*2 or a==b*2+1 */
> 7: a= a/2; /* a=b */
> 8: return a;
> 9: }
>
> If one would claim that a is totally unconstrained at line 6, then this
> example will be invalid. In that case, I can give a more restricted
> example, where 'a' is computed speculatively and is discarded
> in exactly the same cases when it is undefined.
- unless I misunderstand, it actually is undefined if the value of argc
may be as large as the largest representable positive int value, if
both signed int overflows and evaluation order are undefined/unspecified.
(although confess to missing your point, as it's not clear how an
undefined behavior is productively contributing to the observation that
a == argc if agc++ doesn't overflow or evaluated l-r; as opposed to
observing that if the evaluation order were fixed l-r and not undefined,
then the optimization may be derived?)
> Oh, well here it is.
> 1: int a, b, c;
> 2: int f() { return a ? b++ : b; }
> 3: int main()
> 4: {
> 5: scanf("%d %d", &a, &b);
> 6: c= b + f(); /* C is undefined if a != 0*/
> 7: if (a) c = b;
> 8: return c;
> 9: }
>
> This example is predictable. I argue that it may be also
> useful performance-wise to do speculative computations.
- I believe it's subject to the same problem?