Debian Codegraph @

gcc/testsuite/gcc.dg/c2y-byte-alias-1.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-std=c2y -O2" } */
3
4 struct f { _Alignas(int) char buf[sizeof(int)]; };
5 struct f2 { struct f x; };
6 union g { _Alignas(int) char buf[sizeof(int)]; };
7
8 [[gnu::noinline]]
9 int foo(struct f *p, int *q)
10 {
11 *q = 1;
12 *p = (struct f){ };
13 return *q;
14 }
15
16 [[gnu::noinline]]
17 int foo2(struct f2 *p, int *q)
18 {
19 *q = 1;
20 *p = (struct f2){ };
21 return *q;
22 }
23
24 [[gnu::noinline]]
25 int bar(union g *p, int *q)
26 {
27 *q = 1;
28 *p = (union g){ };
29 return *q;
30 }
31
32
33 int main()
34 {
35 struct f p;
36 if (0 != foo(&p, (void*)&p.buf))
37 __builtin_abort();
38
39 struct f2 p2;
40 if (0 != foo2(&p2, (void*)&p2.x.buf))
41 __builtin_abort();
42
43 union g q;
44 if (0 != bar(&q, (void*)&q.buf))
45 __builtin_abort();
46 }