2015-11-30 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / target-7.C
blobe13c50f26dae14f2aa5463a44ae5c979b09c4ef5
1 extern "C" void abort ();
3 void
4 foo (int *x, int *&y, int (&z)[15])
6   int a[10], b[15], err, i;
7   for (i = 0; i < 10; i++)
8     a[i] = 7 * i;
9   for (i = 0; i < 15; i++)
10     b[i] = 8 * i;
11   #pragma omp target map(to:x[5:10], y[5:10], z[5:10], a[0:10], b[5:10]) map(from:err)
12   {
13     err = 0;
14     for (i = 0; i < 10; i++)
15       if (x[5 + i] != 20 + 4 * i
16           || y[5 + i] != 25 + 5 * i
17           || z[5 + i] != 30 + 6 * i
18           || a[i] != 7 * i
19           || b[5 + i] != 40 + 8 * i)
20         err = 1;
21   }
22   if (err)
23     abort ();
26 void
27 bar (int n, int v)
29   int a[n], b[n], c[n], d[n], e[n], err, i;
30   int (*x)[n] = &c;
31   int (*y2)[n] = &d;
32   int (*&y)[n] = y2;
33   int (&z)[n] = e;
34   for (i = 0; i < n; i++)
35     {
36       (*x)[i] = 4 * i;
37       (*y)[i] = 5 * i;
38       z[i] = 6 * i;
39       a[i] = 7 * i;
40       b[i] = 8 * i;
41     }
42   #pragma omp target map(to:x[0][5:10], y[0][5:10], z[5:10], a[0:10], b[5:10]) map(from:err)
43   {
44     err = 0;
45     for (i = 0; i < 10; i++)
46       if ((*x)[5 + i] != 20 + 4 * i
47           || (*y)[5 + i] != 25 + 5 * i
48           || z[5 + i] != 30 + 6 * i
49           || a[i] != 7 * i
50           || b[5 + i] != 40 + 8 * i)
51         err = 1;
52   }
53   if (err)
54     abort ();
55   for (i = 0; i < n; i++)
56     {
57       (*x)[i] = 9 * i;
58       (*y)[i] = 10 * i;
59       z[i] = 11 * i;
60       a[i] = 12 * i;
61       b[i] = 13 * i;
62     }
63   #pragma omp target map(to:x[0][v:v+5], y[0][v:v+5], z[v:v+5], a[v-5:v+5], b[v:v+5]) map(from:err)
64   {
65     err = 0;
66     for (i = 0; i < 10; i++)
67       if ((*x)[5 + i] != 45 + 9 * i
68           || (*y)[5 + i] != 50 + 10 * i
69           || z[5 + i] != 55 + 11 * i
70           || a[i] != 12 * i
71           || b[5 + i] != 65 + 13 * i)
72         err = 1;
73   }
74   if (err)
75     abort ();
78 int
79 main ()
81   int x[15], y2[15], z[15], *y = y2, i;
82   for (i = 0; i < 15; i++)
83     {
84       x[i] = 4 * i;
85       y[i] = 5 * i;
86       z[i] = 6 * i;
87     }
88   foo (x, y, z);
89   bar (15, 5);