[llvm] [Clang][OpenMP] Handled `NonContig` Descriptor `DimCount` (PR #181987)

Abhinav Gaba via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 18 14:56:09 PST 2026


================
@@ -0,0 +1,97 @@
+// RUN: %libomptarget-compile-run-and-check-generic
+// Tests non-contiguous array sections with expression-based count on struct
+// member arrays with both FROM and TO directives.
+
+#include <omp.h>
+#include <stdio.h>
+
+struct S {
+  int len;
+  double data[20];
+};
+
+int main() {
+  struct S s;
+  s.len = 10;
+
+  // Initialize on device
+#pragma omp target map(tofrom : s)
+  {
+    for (int i = 0; i < s.len; i++) {
+      s.data[i] = i;
+    }
+  }
+
+  // Test FROM: Modify on device, then update from device
+#pragma omp target data map(to : s)
+  {
+#pragma omp target
+    {
+      for (int i = 0; i < s.len; i++) {
+        s.data[i] += i * 10;
+      }
+    }
+
+    // Update from device with expression-based count: len/2 elements
+#pragma omp target update from(s.data[0 : s.len / 2 : 2])
+  }
+
+  printf("struct count expression (from):\n");
+  for (int i = 0; i < s.len; i++)
+    printf("%f\n", s.data[i]);
+
+  // Test TO: Reset, modify host, update to device
+#pragma omp target map(tofrom : s)
+  {
+    for (int i = 0; i < s.len; i++) {
+      s.data[i] = i * 2;
+    }
+  }
+
+  // Modify host data
+  for (int i = 0; i < s.len / 2; i++) {
+    s.data[i * 2] = i + 100;
+  }
+
+  // Update to device with expression-based count
+#pragma omp target data map(to : s)
+  {
+#pragma omp target update to(s.data[0 : s.len / 2 : 2])
----------------
abhinavgaba wrote:

The `target data map(to: s)` would already have copied the full `s` to device in line 57. You'd probably want to convert the map into `from` or `alloc`.

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


More information about the llvm-commits mailing list