1 /* To test that the compiler can fill all the paddings to zeroes for the
2 structures when the auto variable is partially initialized, fully
3 initialized, or not initialized for -ftrivial-auto-var-init=pattern. */
5 /* { dg-options "-ftrivial-auto-var-init=pattern" } */
7 /* Structure with no padding. */
15 /* Simple structure with padding likely to be covered by compiler. */
16 struct test_small_hole
{
19 /* 3 byte padding hole here. */
24 /* Try to trigger unhandled padding in a structure. */
26 unsigned int internal1
;
27 unsigned long long internal2
;
28 } __attribute__((__aligned__(64)));
30 struct test_aligned a1
;
32 struct test_big_hole
{
36 /* 61 byte padding hole here. */
37 struct test_aligned four
;
38 } __attribute__((__aligned__(64)));
40 struct test_big_hole bh1
;
42 struct test_trailing_hole
{
47 /* "sizeof(unsigned long) - 1" byte padding hole here. */
50 __attribute__((noipa
)) void
51 foo (struct test_packed
*p
, struct test_small_hole
*sh
, struct test_aligned
*a
,
52 struct test_big_hole
*bh
, struct test_trailing_hole
*th
)
54 p
->one
= 1; p
->two
= 2; p
->three
= 3; p
->four
= 4;
55 sh
->one
= 11; sh
->two
= 12; sh
->three
= 13; sh
->four
= 14;
56 a
->internal1
= 21; a
->internal2
= 22;
57 bh
->one
= 31; bh
->two
= 32; bh
->three
= 33;
58 bh
->four
.internal1
= 34; bh
->four
.internal2
= 35;
59 th
->one
= 0; th
->two
= 0; th
->three
= 0; th
->four
= 44;
64 struct test_packed p2
;
65 struct test_small_hole sh2
;
66 struct test_aligned a2
;
67 struct test_big_hole bh2
;
68 struct test_trailing_hole th2
;
70 struct test_packed p3
= {.one
= 1};
71 struct test_small_hole sh3
= {.two
= 12};
72 struct test_aligned a3
= {.internal1
= 21};
73 struct test_big_hole bh3
= {.one
= 31};
74 struct test_trailing_hole th3
= {.three
= 0};
76 struct test_packed p4
= {.one
= 1, .two
= 2, .three
= 3, .four
= 4};
77 struct test_small_hole sh4
= {.one
= 11, .two
= 12, .three
= 13, .four
= 14};
78 struct test_aligned a4
= {.internal1
= 21, .internal2
= 22};
79 struct test_big_hole bh4
= {.one
= 31, .two
= 32, .three
= 33};
80 struct test_trailing_hole th4
= {.one
= 0, .two
= 0, .three
= 0, .four
= 44};
82 foo (&p1
, &sh1
, &a1
, &bh1
, &th1
);
83 foo (&p2
, &sh2
, &a2
, &bh2
, &th2
);
84 foo (&p3
, &sh3
, &a3
, &bh3
, &th3
);
85 bh4
.four
.internal1
= 34; bh4
.four
.internal2
= 35;
87 __builtin_clear_padding (&p1
);
88 __builtin_clear_padding (&sh1
);
89 __builtin_clear_padding (&a1
);
90 __builtin_clear_padding (&bh1
);
91 __builtin_clear_padding (&th1
);
93 if (__builtin_memcmp (&p1
, &p2
, sizeof (p1
))
94 || __builtin_memcmp (&sh1
, &sh2
, sizeof (sh1
))
95 || __builtin_memcmp (&a1
, &a2
, sizeof (a1
))
96 || __builtin_memcmp (&bh1
, &bh2
, sizeof (bh1
))
97 || __builtin_memcmp (&th1
, &th2
, sizeof (th1
)))
99 if (__builtin_memcmp (&p1
, &p3
, sizeof (p1
))
100 || __builtin_memcmp (&sh1
, &sh3
, sizeof (sh1
))
101 || __builtin_memcmp (&a1
, &a3
, sizeof (a1
))
102 || __builtin_memcmp (&bh1
, &bh3
, sizeof (bh1
))
103 || __builtin_memcmp (&th1
, &th3
, sizeof (th1
)))
105 if (__builtin_memcmp (&p1
, &p4
, sizeof (p1
))
106 || __builtin_memcmp (&sh1
, &sh4
, sizeof (sh1
))
107 || __builtin_memcmp (&a1
, &a4
, sizeof (a1
))
108 || __builtin_memcmp (&bh1
, &bh4
, sizeof (bh1
))
109 || __builtin_memcmp (&th1
, &th4
, sizeof (th1
)))