[llvm] [offload][openMP] Add omp_get_device_ptr_if_present api to offload (PR #153146)

Michael Klemm via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 14 01:22:50 PDT 2025


================
@@ -0,0 +1,86 @@
+// RUN: %libomptarget-compile-run-and-check-generic
+// REQUIRES: unified_shared_memory
+
+#include <assert.h>
+#include <omp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define N 1024
+#define OFFSET 16
+
+int main(int argc, char *argv[]) {
+  int *host_data = (int *)malloc(sizeof(int) * N);
+  int device_num = omp_get_default_device();
+
+  // Initialize data
+  for (int i = 0; i < N; i++) {
+    host_data[i] = i;
+  }
+
+  // Test 1: NULL pointer should return NULL
+  void *result = omp_get_device_ptr_if_present(NULL, device_num);
+  assert(result == NULL && "NULL input should return NULL");
----------------
mjklemm wrote:

Please do not use `assert`, but make this a hard failure with `exit(1)` or `return 1`. With the `assert` the test will depend on whether assertions have been enabled, and the test should correctly test for all possible build configurations. 

https://github.com/llvm/llvm-project/pull/153146


More information about the llvm-commits mailing list