libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / pr55940.c
blob85761f6c31f76941f33af87af8a1b942a5eced3c
1 /* PR target/55940 */
2 /* { dg-do run } */
3 /* { dg-skip-if "pointer arithmetic can wrap" { msp430-*-* } { "*" } { "-mlarge" } } */
4 /* { dg-options "-Os" } */
5 /* { dg-additional-options "-mpreferred-stack-boundary=2" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
7 struct S { int s; unsigned long t; };
9 __attribute__ ((noinline, noclone)) unsigned long long
10 bar (struct S *x, unsigned long y)
12 asm volatile ("" : : "r" (x), "r" (y) : "memory");
13 return x->s + y;
16 __attribute__ ((noinline, noclone)) unsigned long long
17 foo (struct S *x, unsigned long y)
19 unsigned long a;
20 if (__builtin_expect (((__UINTPTR_TYPE__) (x) + 0x1000U < 0x2000U), 0))
21 return ~0ULL;
22 if (__builtin_expect (x->s <= 0 || x->s > 9, 0))
23 return ~0ULL;
24 a = x->t >> 12;
25 if (y == a)
26 return ~0ULL;
27 if (x->s == 3)
28 return x->t + y * 4096;
29 return bar (x, y);
32 int va, vb, vc, vd;
34 int
35 main ()
37 struct S s;
38 asm volatile ("" : : : "memory");
39 int a = va, b = vb, c = vc, d = vd;
40 asm volatile ("" : : : "memory");
41 int i;
42 for (i = 0; i < 64; i++)
43 if (foo ((struct S *) 0, 0) != ~0ULL)
44 __builtin_abort ();
45 s.s = 3;
46 s.t = 2 << 12;
47 if (foo (&s, 2) != ~0ULL)
48 __builtin_abort ();
49 if (foo (&s, 3) != (2 << 12) + 3 * 4096)
50 __builtin_abort ();
51 asm volatile ("" : : : "memory");
52 va = a; vb = b; vc = c; vd = d;
53 asm volatile ("" : : : "memory");
54 return 0;