libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / c2y-byte-alias-1.c
blob30bc2c09c2f812e86026cc80e594573bb5d7ecc6
1 /* { dg-do run } */
2 /* { dg-options "-std=c2y -O2" } */
4 struct f { _Alignas(int) char buf[sizeof(int)]; };
5 struct f2 { struct f x; };
6 union g { _Alignas(int) char buf[sizeof(int)]; };
8 [[gnu::noinline]]
9 int foo(struct f *p, int *q)
11 *q = 1;
12 *p = (struct f){ };
13 return *q;
16 [[gnu::noinline]]
17 int foo2(struct f2 *p, int *q)
19 *q = 1;
20 *p = (struct f2){ };
21 return *q;
24 [[gnu::noinline]]
25 int bar(union g *p, int *q)
27 *q = 1;
28 *p = (union g){ };
29 return *q;
33 int main()
35 struct f p;
36 if (0 != foo(&p, (void*)&p.buf))
37 __builtin_abort();
39 struct f2 p2;
40 if (0 != foo2(&p2, (void*)&p2.x.buf))
41 __builtin_abort();
43 union g q;
44 if (0 != bar(&q, (void*)&q.buf))
45 __builtin_abort();