gcc/testsuite/gcc.dg/pr41935.c
raw| 1 | /* PR middle-end/41935 */ |
| 2 | /* { dg-do run } */ |
| 3 | /* { dg-options "-O2" } */ |
| 4 | |
| 5 | extern void abort (void); |
| 6 | struct A { int a; int b[10]; }; |
| 7 | |
| 8 | int |
| 9 | foo (struct A *p) |
| 10 | { |
| 11 | return __builtin_offsetof (struct A, b[p->a]); |
| 12 | } |
| 13 | |
| 14 | int |
| 15 | main () |
| 16 | { |
| 17 | struct A a; |
| 18 | a.a = 7; |
| 19 | if (foo (&a) != 7 * sizeof (int) + __builtin_offsetof (struct A, b)) |
| 20 | abort (); |
| 21 | a.a = 2; |
| 22 | if (foo (&a) != 2 * sizeof (int) + __builtin_offsetof (struct A, b)) |
| 23 | abort (); |
| 24 | return 0; |
| 25 | } |