| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-O -fdump-tree-ccp1" } */ |
| 3 |
|
| 4 |
struct A { |
| 5 |
struct B { |
| 6 |
int i; |
| 7 |
} b; |
| 8 |
} a; |
| 9 |
|
| 10 |
int foo (void) |
| 11 |
{ |
| 12 |
struct B *p = &a.b; |
| 13 |
struct A *q = (struct A *) p; |
| 14 |
return q->b.i; |
| 15 |
} |
| 16 |
|
| 17 |
int bar (void) |
| 18 |
{ |
| 19 |
struct A *p = &a; |
| 20 |
struct B *q = (struct B *) p; |
| 21 |
return q->i; |
| 22 |
} |
| 23 |
|
| 24 |
/* The first access is through struct A, so a.b.i is fine, |
| 25 |
the second access needs to preserve the original access type struct B. */ |
| 26 |
|
| 27 |
/* { dg-final { scan-tree-dump-times "a.b.i" 1 "ccp1" } } */ |
| 28 |
/* { dg-final { scan-tree-dump-times "MEM\\\[\\\(struct B \\\*\\\)&a\\\].i" 1 "ccp1" } } */ |