Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / api / omp_get_mapped_ptr.c
bloba8e11f912d668e75f7332dbc6794864348a3950d
1 // RUN: %libomptarget-compile-and-run-generic
3 #include <assert.h>
4 #include <omp.h>
5 #include <stdlib.h>
7 #define N 1024
8 #define OFFSET 16
10 int main(int argc, char *argv[]) {
11 int *host_data = (int *)malloc(sizeof(int) * N);
12 void *device_ptr = omp_get_mapped_ptr(host_data, 0);
14 assert(device_ptr == NULL && "the pointer should not be mapped right now");
16 #pragma omp target enter data map(to: host_data[:N])
18 device_ptr = omp_get_mapped_ptr(host_data, 0);
20 assert(device_ptr && "the pointer should be mapped now");
22 void *ptr = NULL;
24 #pragma omp target map(from: ptr)
25 { ptr = host_data; }
27 assert(ptr == device_ptr && "wrong pointer mapping");
29 device_ptr = omp_get_mapped_ptr(host_data + OFFSET, 0);
31 assert(device_ptr && "the pointer with offset should be mapped");
33 #pragma omp target map(from: ptr)
34 { ptr = host_data + OFFSET; }
36 assert(ptr == device_ptr && "wrong pointer mapping");
38 return 0;