ian@airs.com (Ian Lance Taylor)  wrote on 21.01.06 in <[EMAIL PROTECTED]>:

> "Dave Korn" <[EMAIL PROTECTED]> writes:
>
> >   I think he's saying that _this_ one might generate invalid code:
> >
> > void test(void)
> > {
> >         union { int i; double d; } u;
> >         int *ip;
> >         double *dp;
> >         int ii;
> >         double dd;
> >
> >         dp = &u.d;
> >         ip = &u.i;
> >         *ip = 15;
> >         ii = *ip;
> >         *dp = 1.5;
> >         dd = *dp;
> >         printf("ii=%d dd=%f\n", ii, dd);
> > }
>
> That function is valid too.
>
> Here is an example of an invalid function:
>
> void test(void)
> {
>         union { int i; double d; } u;
>         int *ip;
>         double *dp;
>         int ii;
>         double dd;
>
>         dp = &u.d;
>         ip = &u.i;
>         *ip = 15;
>         *dp = 1.5;
>         ii = *ip;
>         dd = *dp;
>         printf("ii=%d dd=%f\n", ii, dd);
> }

And of course(?), stack slot sharing is supposed to be like the first two  
examples, not the last.

Hmm. I think I begin to see what this is about. RTL AA (if I got this  
right) gets confused when two vars at the same address *can't* be  
distinguished by type, so that would be

void test(void)
{
        union { int i1; int i2; } u;
        int *ip1;
        int *ip2;
        int ii1;
        int ii2;
        ip1 = &u.i1;
        ip2 = &u.i2;
        *ip1 = 15;
        ii1 = *ip1;
        *ip2 = 17;
        ii2 = *ip2;
        printf("ii1=%d ii2=%d\n", ii1, ii2);
}

Hmm. I don't know if ISO allows *that* ... though I can see how it might  
arise naturally.

MfG Kai

Reply via email to