AVR: Assert minimal required bit width of section_common::flags.
[gcc.git] / libgomp / testsuite / libgomp.c / target-19.c
blobdac7c56cbde59ec454c92e4acb95e0992113999f
1 extern void abort (void);
3 __attribute__((noinline, noclone)) void
4 foo (int *p, int *q, int *r, int n, int m)
6 int i, err, *s = r;
7 int sep = 1;
8 #pragma omp target map(to:sep)
9 sep = 0;
10 #pragma omp target data map(to:p[0:8])
12 /* For zero length array sections, p points to the start of
13 already mapped range, q to the end of it (with nothing mapped
14 after it), and r does not point to an mapped range. */
15 #pragma omp target map(alloc:p[:0]) map(to:q[:0]) map(from:r[:0]) private(i) map(from:err) firstprivate (s)
17 err = 0;
18 for (i = 0; i < 8; i++)
19 if (p[i] != i + 1)
20 err = 1;
21 if (sep)
23 /* Since OpenMP 5.2, 'q'/'r' are no longer set to NULL if pointing to
24 unmapped storage. */
25 if (q == (int *) 0 || r == (int *) 0)
26 err = 1;
28 else if (p + 8 != q || r != s)
29 err = 1;
31 if (err)
32 abort ();
33 /* Implicit mapping of pointers behaves the same way. */
34 #pragma omp target private(i) map(from:err) firstprivate (s)
36 err = 0;
37 for (i = 0; i < 8; i++)
38 if (p[i] != i + 1)
39 err = 1;
40 if (sep)
42 /* Since OpenMP 5.2, 'q'/'r' are no longer set to NULL if pointing to
43 unmapped storage. */
44 if (q == (int *) 0 || r == (int *) 0)
45 err = 1;
47 else if (p + 8 != q || r != s)
48 err = 1;
50 if (err)
51 abort ();
52 /* And zero-length array sections, though not known at compile
53 time, behave the same. */
54 #pragma omp target map(p[:n]) map(tofrom:q[:n]) map(alloc:r[:n]) private(i) map(from:err) firstprivate (s)
56 err = 0;
57 for (i = 0; i < 8; i++)
58 if (p[i] != i + 1)
59 err = 1;
60 if (sep)
62 /* Since OpenMP 5.2, 'q'/'r' are no longer set to NULL if pointing to
63 unmapped storage. */
64 if (q == (int *) 0 || r == (int *) 0)
65 err = 1;
67 else if (p + 8 != q || r != s)
68 err = 1;
70 if (err)
71 abort ();
72 /* Non-zero length array sections, though not known at compile,
73 behave differently. */
74 #pragma omp target map(p[:m]) map(tofrom:q[:m]) map(to:r[:m]) private(i) map(from:err)
76 err = 0;
77 for (i = 0; i < 8; i++)
78 if (p[i] != i + 1)
79 err = 1;
80 if (q[0] != 9 || r[0] != 10)
81 err = 1;
83 if (err)
84 abort ();
85 #pragma omp target data map(to:q[0:1])
87 /* For zero length array sections, p points to the start of
88 already mapped range, q points to the start of another one,
89 and r to the end of the second one. */
90 #pragma omp target map(to:p[:0]) map(from:q[:0]) map(tofrom:r[:0]) private(i) map(from:err)
92 err = 0;
93 for (i = 0; i < 8; i++)
94 if (p[i] != i + 1)
95 err = 1;
96 if (q[0] != 9)
97 err = 1;
98 else if (sep)
100 /* Since OpenMP 5.2, 'r' is no longer set to NULL if *r is unmapped.*/
101 if (r == (int *) 0)
102 err = 1;
104 else if (r != q + 1)
105 err = 1;
107 if (err)
108 abort ();
109 /* Implicit mapping of pointers behaves the same way. */
110 #pragma omp target private(i) map(from:err)
112 err = 0;
113 for (i = 0; i < 8; i++)
114 if (p[i] != i + 1)
115 err = 1;
116 if (q[0] != 9)
117 err = 1;
118 else if (sep)
120 /* Since OpenMP 5.2, 'r' is no longer set to NULL if *r is unmapped.*/
121 if (r == (int *) 0)
122 err = 1;
124 else if (r != q + 1)
125 err = 1;
127 if (err)
128 abort ();
129 /* And zero-length array sections, though not known at compile
130 time, behave the same. */
131 #pragma omp target map(p[:n]) map(alloc:q[:n]) map(from:r[:n]) private(i) map(from:err)
133 err = 0;
134 for (i = 0; i < 8; i++)
135 if (p[i] != i + 1)
136 err = 1;
137 if (q[0] != 9)
138 err = 1;
139 else if (sep)
141 /* Since OpenMP 5.2, 'r' is no longer set to NULL if *r is unmapped.*/
142 if (r == (int *) 0)
143 err = 1;
145 else if (r != q + 1)
146 err = 1;
148 if (err)
149 abort ();
150 /* Non-zero length array sections, though not known at compile,
151 behave differently. */
152 #pragma omp target map(p[:m]) map(alloc:q[:m]) map(tofrom:r[:m]) private(i) map(from:err)
154 err = 0;
155 for (i = 0; i < 8; i++)
156 if (p[i] != i + 1)
157 err = 1;
158 if (q[0] != 9 || r[0] != 10)
159 err = 1;
161 if (err)
162 abort ();
168 main ()
170 int a[32], i;
171 for (i = 0; i < 32; i++)
172 a[i] = i;
173 foo (a + 1, a + 9, a + 10, 0, 1);
174 return 0;