diff --git a/openmp/libomptarget/src/api.cpp b/openmp/libomptarget/src/api.cpp --- a/openmp/libomptarget/src/api.cpp +++ b/openmp/libomptarget/src/api.cpp @@ -108,8 +108,12 @@ DeviceTy &Device = *PM->Devices[device_num]; bool IsLast; // not used bool IsHostPtr; + // omp_target_is_present tests whether a host pointer refers to storage that + // is mapped to a given device. However, due to the lack of the storage size, + // only check 1 byte. Cannot set size 0 which checks whether the pointer (zero + // lengh array) is mapped instead of the referred storage. TargetPointerResultTy TPR = - Device.getTgtPtrBegin(const_cast(ptr), 0, IsLast, + Device.getTgtPtrBegin(const_cast(ptr), 1, IsLast, /*UpdateRefCount=*/false, /*UseHoldRefCount=*/false, IsHostPtr); int rc = (TPR.TargetPointer != NULL); diff --git a/openmp/libomptarget/test/mapping/target_implicit_partial_map.c b/openmp/libomptarget/test/mapping/target_implicit_partial_map.c --- a/openmp/libomptarget/test/mapping/target_implicit_partial_map.c +++ b/openmp/libomptarget/test/mapping/target_implicit_partial_map.c @@ -13,6 +13,18 @@ #pragma omp target data map(alloc: arr[50:2]) // partially mapped { + // CHECK: arr[50] must present: 1 + fprintf(stderr, "arr[50] must present: %d\n", + omp_target_is_present(&arr[50], omp_get_default_device())); + + // CHECK: arr[0] should not present: 0 + fprintf(stderr, "arr[0] should not present: %d\n", + omp_target_is_present(&arr[0], omp_get_default_device())); + + // CHECK: arr[49] should not present: 0 + fprintf(stderr, "arr[49] should not present: %d\n", + omp_target_is_present(&arr[49], omp_get_default_device())); + #pragma omp target // would implicitly map with full size but already present { arr[50] = 5; @@ -20,8 +32,8 @@ } // must treat as present (dec ref count) even though full size not present } // wouldn't delete if previous ref count dec didn't happen - // CHECK: still present: 0 - fprintf(stderr, "still present: %d\n", + // CHECK: arr[50] still present: 0 + fprintf(stderr, "arr[50] still present: %d\n", omp_target_is_present(&arr[50], omp_get_default_device())); return 0;