Debian Codegraph @

gcc/testsuite/gcc.target/sh/pr54760-3.c

raw
1 /* Check that these thread relative memory accesses play along with
2 surrounding code.
3 These should be moved to C torture tests once there are target
4 independent thread_pointer built-in functions available. */
5 /* { dg-do compile } */
6 /* { dg-options "-O1" } */
7
8 int
9 test00 (void* p, int x)
10 {
11 int* tcb = (int*)__builtin_thread_pointer ();
12 int r = tcb[4];
13
14 __builtin_set_thread_pointer (p);
15
16 tcb = (int*)__builtin_thread_pointer ();
17 return tcb[255] + r;
18 }
19
20 int
21 test01 (void)
22 {
23 unsigned short* tcb = (unsigned short*)__builtin_thread_pointer ();
24 return tcb[500];
25 }
26
27 void
28 test02 (int* x, int a, int b)
29 {
30 int* tcb = (int*)__builtin_thread_pointer ();
31 tcb[50] = a;
32
33 __builtin_set_thread_pointer (x);
34
35 tcb = (int*)__builtin_thread_pointer ();
36 tcb[40] = b;
37 }
38
39 int
40 test03 (const int* x, int c)
41 {
42 volatile int* tcb = (volatile int*)__builtin_thread_pointer ();
43
44 int s = 0;
45 int i;
46 for (i = 0; i < c; ++i)
47 s ^= x[i] + tcb[40];
48
49 return s;
50 }
51
52 int
53 test04 (const int* x, int c, int** xx, int d)
54 {
55 int s = 0;
56 int i;
57 for (i = 0; i < c; ++i)
58 {
59 volatile int* tcb = (volatile int*)__builtin_thread_pointer ();
60 tcb[20] = s;
61
62 __builtin_set_thread_pointer (xx[i]);
63
64 tcb = (volatile int*)__builtin_thread_pointer ();
65 s ^= x[i] + tcb[40] + d;
66 }
67 return s;
68 }