Debian Codegraph @

libgomp/testsuite/libgomp.c-c++-common/array-of-struct-2.c

raw
1 /* { dg-do run } */
2
3 #include <stdlib.h>
4 #include <string.h>
5 #include <assert.h>
6
7 #define N 16
8
9 /* NOTE: This test is the same as array-of-struct-1.c, except the fields of
10 this struct are in a different order. */
11
12 struct Z {
13 int *ptr;
14 int arr[N];
15 int c;
16 };
17
18 void
19 foo (struct Z *zarr, int len)
20 {
21 #pragma omp target map(to:zarr, zarr[5].ptr) map(tofrom:zarr[5].ptr[0:len])
22 {
23 for (int i = 0; i < len; i++)
24 zarr[5].ptr[i]++;
25 }
26
27 #pragma omp target map(to:zarr) map(tofrom:zarr[4].arr[0:len])
28 {
29 for (int i = 0; i < len; i++)
30 zarr[4].arr[i]++;
31 }
32
33 #pragma omp target map (to:zarr[3].ptr) map(tofrom:zarr[3].ptr[0:len])
34 {
35 for (int i = 0; i < len; i++)
36 zarr[3].ptr[i]++;
37 }
38
39 #pragma omp target map(tofrom:zarr[2].arr[0:len])
40 {
41 for (int i = 0; i < len; i++)
42 zarr[2].arr[i]++;
43 }
44 }
45
46 int main (int argc, char *argv[])
47 {
48 struct Z zs[10];
49 memset (zs, 0, sizeof zs);
50
51 for (int i = 0; i < 10; i++)
52 zs[i].ptr = (int *) calloc (N, sizeof (int));
53
54 foo (zs, N);
55
56 for (int i = 0; i < N; i++)
57 {
58 assert (zs[2].arr[i] == 1);
59 assert (zs[4].arr[i] == 1);
60 assert (zs[3].ptr[i] == 1);
61 assert (zs[5].ptr[i] == 1);
62 }
63
64 return 0;
65 }