[llvm] [OpenMP] Add tests for mapping of chained 'containing' structs (PR #156703)
Abhinav Gaba via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 5 10:33:18 PDT 2025
================
@@ -0,0 +1,217 @@
+// RUN: %libomptarget-compilexx-run-and-check-generic
+
+// XFAIL: *
+
+#include <cstdlib>
+#include <cstdio>
+#include <cassert>
+#include <cstring>
+
+#include <omp.h>
+
+struct R {
+ int d;
+ int e;
+ int f;
+};
+
+struct S {
+ int a;
+ int b;
+ struct {
+ int c;
+ R r;
+ R *rp;
+ } sub;
+ int g;
+};
+
+struct T {
+ int a;
+ int *ptr;
+ int b;
+};
+
+int main() {
+ R r;
+ R *rp = new R;
+ S s;
+ S *sp = new S;
+ T t;
+ T *tp = new T;
+
+ memset(&r, 0, sizeof(R));
+ memset(rp, 0, sizeof(R));
+ memset(&s, 0, sizeof(S));
+ memset(sp, 0, sizeof(S));
+ memset(&t, 0, sizeof(T));
+ memset(tp, 0, sizeof(T));
+
+ s.sub.rp = new R;
+ sp->sub.rp = new R;
+
+ memset(s.sub.rp, 0, sizeof(R));
+ memset(sp->sub.rp, 0, sizeof(R));
+
+ t.ptr = new int[10];
+ tp->ptr = new int[10];
+
+ memset(t.ptr, 0, sizeof(int)*10);
+ memset(tp->ptr, 0, sizeof(int)*10);
+
+#pragma omp target map(tofrom: r) map(tofrom: r.e)
+{
+ r.d++;
+ r.e += 2;
+ r.f += 3;
+}
+ printf ("%d\n", r.d); // CHECK: 1
+ printf ("%d\n", r.e); // CHECK-NEXT: 2
+ printf ("%d\n", r.f); // CHECK-NEXT: 3
+
+#pragma omp target map(tofrom: rp[:1]) map(tofrom: rp->e)
+{
+ rp->d++;
+ rp->e += 2;
+ rp->f += 3;
+}
+
+ printf ("%d\n", rp->d); // CHECK-NEXT: 1
+ printf ("%d\n", rp->e); // CHECK-NEXT: 2
+ printf ("%d\n", rp->f); // CHECK-NEXT: 3
+
+ int v;
+ int *orig_addr_v = &v;
+ bool separate_memory_space;
+
+#pragma omp target data map(v)
+ {
+ void *mapped_ptr_v =
+ omp_get_mapped_ptr(orig_addr_v, omp_get_default_device());
+ separate_memory_space = mapped_ptr_v != (void*) orig_addr_v;
----------------
abhinavgaba wrote:
Sounds good. If we needed the distinction, we could also check that the default device is different from host device, but we don't need to do that in this case.
https://github.com/llvm/llvm-project/pull/156703
More information about the llvm-commits
mailing list