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: Michael Veksler <VEKSLER at il dot ibm dot com>
- To: Paul Schlie <schlie at comcast dot net>
- 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, 8 Jun 2005 19:07:00 +0300
- Subject: Re: Ada front-end depends on signed overflow
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.
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.