sched1: debug/model: dump predecessor list and BB num [NFC]
[gcc.git] / libgomp / testsuite / libgomp.c / allocate-6.c
blob6d7278ce5718df6d8fcf701b60b9e917d6e31593
1 /* TODO: move to ../libgomp.c-c++-common once C++ is implemented. */
2 /* NOTE: { target c } is unsupported with with the C compiler. */
4 /* { dg-do run } */
5 /* { dg-additional-options "-fdump-tree-omplower" } */
7 /* For the 4 vars in omp_parallel, 4 in omp_target and 1 of 2 in no_alloc2_func. */
8 /* { dg-final { scan-tree-dump-times "__builtin_GOMP_alloc \\(" 9 "omplower" } } */
9 /* { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(" 9 "omplower" } } */
11 #include <omp.h>
13 void
14 check_int (int *x, int y)
16 if (*x != y)
17 __builtin_abort ();
20 void
21 check_ptr (int **x, int *y)
23 if (*x != y)
24 __builtin_abort ();
28 int
29 no_alloc_func ()
31 /* There is no __builtin_GOMP_alloc / __builtin_GOMP_free as
32 allocator == omp_default_mem_alloc (known at compile time. */
33 int no_alloc;
34 #pragma omp allocate(no_alloc) allocator(omp_default_mem_alloc)
35 no_alloc = 7;
36 return no_alloc;
39 int
40 no_alloc2_func()
42 /* There is no __builtin_GOMP_alloc / __builtin_GOMP_free as
43 no_alloc2 is TREE_UNUSED. But there is for is_alloc2. */
44 int no_alloc2, is_alloc2;
45 #pragma omp allocate(no_alloc2, is_alloc2)
46 is_alloc2 = 7;
47 return is_alloc2;
51 void
52 omp_parallel ()
54 int n = 6;
55 int iii = 5, jjj[5], kkk[n];
56 int *ptr = (int *) 0x1234;
57 #pragma omp allocate(iii, jjj, kkk, ptr)
59 for (int i = 0; i < 5; i++)
60 jjj[i] = 3*i;
61 for (int i = 0; i < 6; i++)
62 kkk[i] = 7*i;
64 #pragma omp parallel default(none) firstprivate(iii, jjj, kkk, ptr) if(0)
66 if (iii != 5)
67 __builtin_abort();
68 iii = 7;
69 check_int (&iii, 7);
70 for (int i = 0; i < 5; i++)
71 if (jjj[i] != 3*i)
72 __builtin_abort ();
73 for (int i = 0; i < 6; i++)
74 if (kkk[i] != 7*i)
75 __builtin_abort ();
76 for (int i = 0; i < 5; i++)
77 jjj[i] = 4*i;
78 for (int i = 0; i < 6; i++)
79 kkk[i] = 8*i;
80 for (int i = 0; i < 5; i++)
81 check_int (&jjj[i], 4*i);
82 for (int i = 0; i < 6; i++)
83 check_int (&kkk[i], 8*i);
84 if (ptr != (int *) 0x1234)
85 __builtin_abort ();
86 ptr = (int *) 0xabcd;
87 if (ptr != (int *) 0xabcd)
88 __builtin_abort ();
89 check_ptr (&ptr, (int *) 0xabcd);
91 if (iii != 5)
92 __builtin_abort ();
93 check_int (&iii, 5);
94 for (int i = 0; i < 5; i++)
96 if (jjj[i] != 3*i)
97 __builtin_abort ();
98 check_int (&jjj[i], 3*i);
100 for (int i = 0; i < 6; i++)
102 if (kkk[i] != 7*i)
103 __builtin_abort ();
104 check_int (&kkk[i], 7*i);
106 if (ptr != (int *) 0x1234)
107 __builtin_abort ();
108 check_ptr (&ptr, (int *) 0x1234);
110 #pragma omp parallel default(firstprivate) if(0)
112 if (iii != 5)
113 __builtin_abort();
114 iii = 7;
115 check_int (&iii, 7);
116 for (int i = 0; i < 5; i++)
117 if (jjj[i] != 3*i)
118 __builtin_abort ();
119 for (int i = 0; i < 6; i++)
120 if (kkk[i] != 7*i)
121 __builtin_abort ();
122 for (int i = 0; i < 5; i++)
123 jjj[i] = 4*i;
124 for (int i = 0; i < 6; i++)
125 kkk[i] = 8*i;
126 for (int i = 0; i < 5; i++)
127 check_int (&jjj[i], 4*i);
128 for (int i = 0; i < 6; i++)
129 check_int (&kkk[i], 8*i);
130 if (ptr != (int *) 0x1234)
131 __builtin_abort ();
132 ptr = (int *) 0xabcd;
133 if (ptr != (int *) 0xabcd)
134 __builtin_abort ();
135 check_ptr (&ptr, (int *) 0xabcd);
137 if (iii != 5)
138 __builtin_abort ();
139 check_int (&iii, 5);
140 for (int i = 0; i < 5; i++)
142 if (jjj[i] != 3*i)
143 __builtin_abort ();
144 check_int (&jjj[i], 3*i);
146 for (int i = 0; i < 6; i++)
148 if (kkk[i] != 7*i)
149 __builtin_abort ();
150 check_int (&kkk[i], 7*i);
152 if (ptr != (int *) 0x1234)
153 __builtin_abort ();
154 check_ptr (&ptr, (int *) 0x1234);
159 void
160 omp_target ()
162 int n = 6;
163 int iii = 5, jjj[5], kkk[n];
164 int *ptr = (int *) 0x1234;
165 #pragma omp allocate(iii, jjj, kkk, ptr)
167 for (int i = 0; i < 5; i++)
168 jjj[i] = 3*i;
169 for (int i = 0; i < 6; i++)
170 kkk[i] = 7*i;
172 #pragma omp target defaultmap(none) firstprivate(iii, jjj, kkk, ptr)
174 if (iii != 5)
175 __builtin_abort();
176 iii = 7;
177 check_int (&iii, 7);
178 for (int i = 0; i < 5; i++)
179 if (jjj[i] != 3*i)
180 __builtin_abort ();
181 for (int i = 0; i < 6; i++)
182 if (kkk[i] != 7*i)
183 __builtin_abort ();
184 for (int i = 0; i < 5; i++)
185 jjj[i] = 4*i;
186 for (int i = 0; i < 6; i++)
187 kkk[i] = 8*i;
188 for (int i = 0; i < 5; i++)
189 check_int (&jjj[i], 4*i);
190 for (int i = 0; i < 6; i++)
191 check_int (&kkk[i], 8*i);
192 if (ptr != (int *) 0x1234)
193 __builtin_abort ();
194 ptr = (int *) 0xabcd;
195 if (ptr != (int *) 0xabcd)
196 __builtin_abort ();
197 check_ptr (&ptr, (int *) 0xabcd);
199 if (iii != 5)
200 __builtin_abort ();
201 check_int (&iii, 5);
202 for (int i = 0; i < 5; i++)
204 if (jjj[i] != 3*i)
205 __builtin_abort ();
206 check_int (&jjj[i], 3*i);
208 for (int i = 0; i < 6; i++)
210 if (kkk[i] != 7*i)
211 __builtin_abort ();
212 check_int (&kkk[i], 7*i);
214 if (ptr != (int *) 0x1234)
215 __builtin_abort ();
216 check_ptr (&ptr, (int *) 0x1234);
218 #pragma omp target defaultmap(firstprivate)
220 if (iii != 5)
221 __builtin_abort();
222 iii = 7;
223 check_int (&iii, 7);
224 for (int i = 0; i < 5; i++)
225 if (jjj[i] != 3*i)
226 __builtin_abort ();
227 for (int i = 0; i < 6; i++)
228 if (kkk[i] != 7*i)
229 __builtin_abort ();
230 for (int i = 0; i < 5; i++)
231 jjj[i] = 4*i;
232 for (int i = 0; i < 6; i++)
233 kkk[i] = 8*i;
234 for (int i = 0; i < 5; i++)
235 check_int (&jjj[i], 4*i);
236 for (int i = 0; i < 6; i++)
237 check_int (&kkk[i], 8*i);
238 if (ptr != (int *) 0x1234)
239 __builtin_abort ();
240 ptr = (int *) 0xabcd;
241 if (ptr != (int *) 0xabcd)
242 __builtin_abort ();
243 check_ptr (&ptr, (int *) 0xabcd);
245 if (iii != 5)
246 __builtin_abort ();
247 check_int (&iii, 5);
248 for (int i = 0; i < 5; i++)
250 if (jjj[i] != 3*i)
251 __builtin_abort ();
252 check_int (&jjj[i], 3*i);
254 for (int i = 0; i < 6; i++)
256 if (kkk[i] != 7*i)
257 __builtin_abort ();
258 check_int (&kkk[i], 7*i);
260 if (ptr != (int *) 0x1234)
261 __builtin_abort ();
262 check_ptr (&ptr, (int *) 0x1234);
264 #pragma omp target defaultmap(tofrom)
266 if (iii != 5)
267 __builtin_abort();
268 iii = 7;
269 check_int (&iii, 7);
270 for (int i = 0; i < 5; i++)
271 if (jjj[i] != 3*i)
272 __builtin_abort ();
273 for (int i = 0; i < 6; i++)
274 if (kkk[i] != 7*i)
275 __builtin_abort ();
276 for (int i = 0; i < 5; i++)
277 jjj[i] = 4*i;
278 for (int i = 0; i < 6; i++)
279 kkk[i] = 8*i;
280 for (int i = 0; i < 5; i++)
281 check_int (&jjj[i], 4*i);
282 for (int i = 0; i < 6; i++)
283 check_int (&kkk[i], 8*i);
284 if (ptr != (int *) 0x1234)
285 __builtin_abort ();
286 ptr = (int *) 0xabcd;
287 if (ptr != (int *) 0xabcd)
288 __builtin_abort ();
289 check_ptr (&ptr, (int *) 0xabcd);
292 if (iii != 7)
293 __builtin_abort ();
294 check_int (&iii, 7);
295 for (int i = 0; i < 5; i++)
297 if (jjj[i] != 4*i)
298 __builtin_abort ();
299 check_int (&jjj[i], 4*i);
301 for (int i = 0; i < 6; i++)
303 if (kkk[i] != 8*i)
304 __builtin_abort ();
305 check_int (&kkk[i], 8*i);
307 if (ptr != (int *) 0xabcd)
308 __builtin_abort ();
309 check_ptr (&ptr, (int *) 0xabcd);
314 main ()
316 omp_parallel ();
317 omp_target ();
318 return 0;