1 /* PR middle-end/22141 */ 2 /* { dg-do compile } */ 3 /* { dg-options "-Os" } */ 4 5 extern void abort (void); 6 7 struct S 8 { 9 struct T 10 { 11 char a; 12 char b; 13 char c; 14 char d; 15 } t; 16 } u; 17 18 struct U 19 { 20 struct S s[4]; 21 }; 22 23 void __attribute__((noinline)) c1(struct T * p)24c1 (struct T *p) 25 { 26 if (p->a != 1 || p->b != 2 || p->c != 3 || p->d != 4) 27 abort (); 28 __builtin_memset (p, 0xaa, sizeof (*p)); 29 } 30 31 void __attribute__((noinline)) c2(struct S * p)32c2 (struct S *p) 33 { 34 c1 (&p->t); 35 } 36 37 void __attribute__((noinline)) c3(struct U * p)38c3 (struct U *p) 39 { 40 c2 (&p->s[2]); 41 } 42 43 void __attribute__((noinline)) f1(void)44f1 (void) 45 { 46 u = (struct S) { { 1, 2, 3, 4 } }; 47 } 48 49 void __attribute__((noinline)) f2(void)50f2 (void) 51 { 52 u.t.a = 1; 53 u.t.b = 2; 54 u.t.c = 3; 55 u.t.d = 4; 56 } 57 58 void __attribute__((noinline)) f3(void)59f3 (void) 60 { 61 u.t.d = 4; 62 u.t.b = 2; 63 u.t.a = 1; 64 u.t.c = 3; 65 } 66 67 void __attribute__((noinline)) f4(void)68f4 (void) 69 { 70 struct S v; 71 v.t.a = 1; 72 v.t.b = 2; 73 v.t.c = 3; 74 v.t.d = 4; 75 c2 (&v); 76 } 77 78 void __attribute__((noinline)) f5(struct S * p)79f5 (struct S *p) 80 { 81 p->t.a = 1; 82 p->t.c = 3; 83 p->t.d = 4; 84 p->t.b = 2; 85 } 86 87 void __attribute__((noinline)) f6(void)88f6 (void) 89 { 90 struct U v; 91 v.s[2].t.a = 1; 92 v.s[2].t.b = 2; 93 v.s[2].t.c = 3; 94 v.s[2].t.d = 4; 95 c3 (&v); 96 } 97 98 void __attribute__((noinline)) f7(struct U * p)99f7 (struct U *p) 100 { 101 p->s[2].t.a = 1; 102 p->s[2].t.c = 3; 103 p->s[2].t.d = 4; 104 p->s[2].t.b = 2; 105 } 106 107 int main(void)108main (void) 109 { 110 struct U w; 111 f1 (); 112 c2 (&u); 113 f2 (); 114 c1 (&u.t); 115 f3 (); 116 c2 (&u); 117 f4 (); 118 f5 (&u); 119 c2 (&u); 120 f6 (); 121 f7 (&w); 122 c3 (&w); 123 return 0; 124 } 125 126 /* { dg-final { scan-assembler-times "67305985\|4030201" 7 } } */ 127