Strange (wrong?) aliasing outcome

Andrew Haley aph@redhat.com
Tue Oct 26 15:54:00 GMT 2004


Michael Veksler writes:
 > 
 > Here is another strange example:
 > 
 > struct A { int a; char x;};
 > struct B { int b; long x;};
 > void f(struct A* pa, struct B*pb)
 > {
 >    pa->a= pb->b+1;
 >    pa->a= pb->b+1;
 >    pa->a= pb->b+1;
 >    pa->a= pb->b+1;
 > }
 > int main()
 > {
 >    struct A a = {0};
 >    f(&a, (struct B*)&a);
 >    return a.a;
 > }
 > 
 > I would have thought that f() would be optimized to (like xlC does):
 > void f(struct A* pa, struct B*pb)
 > {
 >    pa->a= pb->b+1;
 > }
 > 
 > But it is not optimized

It's because the char member of struct A effectively makes its alias
set the same as alias set zero.  (Hint: have a look at the way
has_zero_child is used in alias.c.)

This implies that gcc's alias analysis is not complete, but we never
claimed that it was.

Andrew.



More information about the Gcc mailing list