Debian Codegraph @

gcc/testsuite/gcc.dg/gnu23-tag-alias-3.c

raw
1 /* { dg-do run { target lto } }
2 * { dg-options "-std=gnu23 -flto -O2" }
3 */
4
5 /* These tests check that incompatible definitions of
6 tagged types can be assumed not to alias and that
7 this is exploited during optimization with LTO. */
8
9 struct foo { int x; };
10
11 [[gnu::noinline,gnu::noipa]]
12 int test_foo1(struct foo* a, void* b)
13 {
14 a->x = 1;
15
16 struct foo { int x; int y; }* p = b;
17 p->x = 2;
18
19 return a->x;
20 }
21
22 [[gnu::noinline,gnu::noipa]]
23 int test_foo2(struct foo* a, void* b)
24 {
25 a->x = 1;
26
27 struct fox { int x; }* p = b;
28 p->x = 2;
29
30 return a->x;
31 }
32
33
34 /* While these tests check that incompatible definitions
35 * of enums can alias. */
36
37 enum bar { A = 1, B = 3, C = 5, D = 9 };
38
39 [[gnu::noinline,gnu::noipa]]
40 int test_bar1(enum bar* a, void* b)
41 {
42 *a = A;
43
44 enum bar { A = 1, B = 3, C = 6, D = 9 }* p = b;
45 *p = B;
46
47 return *a;
48 }
49
50 [[gnu::noinline,gnu::noipa]]
51 int test_bar2(enum bar* a, void* b)
52 {
53 *a = A;
54
55 enum baX { A = 1, B = 3, C = 5, D = 9 }* p = b;
56 *p = B;
57
58 return *a;
59 }
60
61
62 int main()
63 {
64 struct foo y;
65
66 if (1 != test_foo1(&y, &y))
67 __builtin_abort();
68
69 if (1 != test_foo2(&y, &y))
70 __builtin_abort();
71
72 enum bar z;
73
74 if (B != test_bar1(&z, &z))
75 __builtin_abort();
76
77 if (B != test_bar2(&z, &z))
78 __builtin_abort();
79
80 return 0;
81 }
82
83