Require target lto in several tests
[official-gcc.git] / gcc / testsuite / gcc.dg / gnu23-tag-alias-3.c
blob9d7e7e11c7fd08a7dc791352a261d765ea5107d2
1 /* { dg-do run { target lto } }
2 * { dg-options "-std=gnu23 -flto -O2" }
3 */
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. */
9 struct foo { int x; };
11 [[gnu::noinline,gnu::noipa]]
12 int test_foo1(struct foo* a, void* b)
14 a->x = 1;
16 struct foo { int x; int y; }* p = b;
17 p->x = 2;
19 return a->x;
22 [[gnu::noinline,gnu::noipa]]
23 int test_foo2(struct foo* a, void* b)
25 a->x = 1;
27 struct fox { int x; }* p = b;
28 p->x = 2;
30 return a->x;
34 /* While these tests check that incompatible definitions
35 * of enums can alias. */
37 enum bar { A = 1, B = 3, C = 5, D = 9 };
39 [[gnu::noinline,gnu::noipa]]
40 int test_bar1(enum bar* a, void* b)
42 *a = A;
44 enum bar { A = 1, B = 3, C = 6, D = 9 }* p = b;
45 *p = B;
47 return *a;
50 [[gnu::noinline,gnu::noipa]]
51 int test_bar2(enum bar* a, void* b)
53 *a = A;
55 enum baX { A = 1, B = 3, C = 5, D = 9 }* p = b;
56 *p = B;
58 return *a;
62 int main()
64 struct foo y;
66 if (1 != test_foo1(&y, &y))
67 __builtin_abort();
69 if (1 != test_foo2(&y, &y))
70 __builtin_abort();
72 enum bar z;
74 if (B != test_bar1(&z, &z))
75 __builtin_abort();
77 if (B != test_bar2(&z, &z))
78 __builtin_abort();
80 return 0;