aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/c2y-byte-alias-1.c
blob: 30bc2c09c2f812e86026cc80e594573bb5d7ecc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* { dg-do run } */
/* { dg-options "-std=c2y -O2" } */

struct f { _Alignas(int) char buf[sizeof(int)]; };
struct f2 { struct f x; };
union g { _Alignas(int) char buf[sizeof(int)]; };

[[gnu::noinline]]
int foo(struct f *p, int *q)
{
	*q = 1;
	*p = (struct f){ };
	return *q;
}

[[gnu::noinline]]
int foo2(struct f2 *p, int *q)
{
	*q = 1;
	*p = (struct f2){ };
	return *q;
}

[[gnu::noinline]]
int bar(union g *p, int *q)
{
	*q = 1;
	*p = (union g){ };
	return *q;
}


int main()
{
	struct f p;
	if (0 != foo(&p, (void*)&p.buf))
		__builtin_abort();

	struct f2 p2;
	if (0 != foo2(&p2, (void*)&p2.x.buf))
		__builtin_abort();

	union g q;
	if (0 != bar(&q, (void*)&q.buf))
		__builtin_abort();
}