This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Strange (wrong?) aliasing outcome


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]