Debian Codegraph @

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

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