This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RTL alias analysis
On Jan 22, 2006, Richard Sandiford <richard@codesourcery.com> wrote:
> Ian Lance Taylor <ian@airs.com> writes:
>> kaih@khms.westfalen.de (Kai Henningsen) writes:
>>> void test(void) { union { int i; double d; } u;
>>> int *ip; double *dp; int ii; double dd;
>>> ip = &u.i; *ip = 15; ii = *ip; dp = &u.d; *dp = 1.5; dd = *dp;
>>> printf("ii=%d dd=%f\n", ii, dd); }
>>> So you're saying this function is not valid?
>>
>> That function is valid.
> I'm going to regret this, but... I don't follow. How is Kai's testcase
> different from:
> int ii; double dd; void foo (int *ip, double *dp) {
> *ip = 15; ii = *ip; *dp = 1.5; dd = *dp; }
> void test (void) { union { int i; double d; } u;
> foo (&u.i, &u.d); }
> ? foo() can write *dp before reading *ip.
I don't think it is any different. GCC's exception for unions only
applies if the object is accessed using the union type. So they are
indeed equivalent. The scary thing is that I don't think they
actually violate the ISO C strict aliasing rules, but they might still
be mis-optimized by GCC, assuming I understand correctly what GCC
does.
--
Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}