aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/c2y-byte-alias-2.c
blob: 9bd2d18b3864479c2430ad8911dfe19d6ee89c92 (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
/* { dg-do run } */
/* { dg-options "-std=c2y -O2" } */

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

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

struct g2 {
	union g {
		_Alignas(int) char buf[sizeof(int)];
	} x[2];
	int i;
};

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

int main()
{
	struct f2 p2;
	if (0 != foo2(&p2, (void*)&p2.x[0].buf))
		__builtin_abort();

	struct g2 q2;
	if (0 != bar2(&q2, (void*)&q2.x[0].buf))
		__builtin_abort();
}