xref: /llvm-project/offload/test/offloading/bug49779.cpp (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compilexx-generic && \
2 // RUN:   env LIBOMPTARGET_STACK_SIZE=2048 %libomptarget-run-generic
3 // RUN: %libomptarget-compileoptxx-generic && \
4 // RUN:   env LIBOMPTARGET_STACK_SIZE=2048 %libomptarget-run-generic
5 
6 // We need malloc/global_alloc support
7 // UNSUPPORTED: amdgcn-amd-amdhsa
8 
9 #include <cassert>
10 #include <iostream>
11 
work(int * C)12 void work(int *C) {
13 #pragma omp atomic
14   ++(*C);
15 }
16 
use(int * C)17 void use(int *C) {
18 #pragma omp parallel num_threads(2)
19   work(C);
20 }
21 
main()22 int main() {
23   int C = 0;
24 #pragma omp target map(C)
25   {
26     use(&C);
27 #pragma omp parallel num_threads(2)
28     use(&C);
29   }
30 
31   assert(C >= 2 && C <= 6);
32 
33   std::cout << "PASS\n";
34 
35   return 0;
36 }
37 
38 // CHECK: PASS
39