| 1 | // RUN: %libomptarget-compile-generic && env LIBOMPTARGET_DEBUG=1 %libomptarget-run-generic 2>&1 | %fcheck-generic |
| 2 | // REQUIRES: libomptarget-debug |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | |
| 7 | int *allocate(size_t n) { |
| 8 | int *ptr = malloc(size: sizeof(int) * n); |
| 9 | #pragma omp target enter data map(to : ptr[ : n]) |
| 10 | return ptr; |
| 11 | } |
| 12 | |
| 13 | void deallocate(int *ptr, size_t n) { |
| 14 | #pragma omp target exit data map(delete : ptr[ : n]) |
| 15 | free(ptr: ptr); |
| 16 | } |
| 17 | |
| 18 | #pragma omp declare target |
| 19 | int *cnt; |
| 20 | void foo() { ++(*cnt); } |
| 21 | #pragma omp end declare target |
| 22 | |
| 23 | int main(void) { |
| 24 | int *A = allocate(n: 10); |
| 25 | int *V = allocate(n: 10); |
| 26 | deallocate(ptr: A, n: 10); |
| 27 | deallocate(ptr: V, n: 10); |
| 28 | // CHECK-NOT: RefCount=2 |
| 29 | cnt = malloc(size: sizeof(int)); |
| 30 | *cnt = 0; |
| 31 | #pragma omp target map(cnt[ : 1]) |
| 32 | foo(); |
| 33 | printf(format: "Cnt = %d.\n" , *cnt); |
| 34 | // CHECK: Cnt = 1. |
| 35 | *cnt = 0; |
| 36 | #pragma omp target data map(cnt[ : 1]) |
| 37 | #pragma omp target |
| 38 | foo(); |
| 39 | printf(format: "Cnt = %d.\n" , *cnt); |
| 40 | // CHECK: Cnt = 1. |
| 41 | free(ptr: cnt); |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |