[Openmp-commits] [PATCH] D119471: [OpenMP][Offloading] Fix infinite loop in applyToShadowMapEntries

Shilei Tian via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Sat Feb 12 18:52:18 PST 2022


tianshilei1992 updated this revision to Diff 408228.
tianshilei1992 added a comment.

rebase and add test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119471/new/

https://reviews.llvm.org/D119471

Files:
  openmp/libomptarget/src/omptarget.cpp
  openmp/libomptarget/test/offloading/bug53727.cpp


Index: openmp/libomptarget/test/offloading/bug53727.cpp
===================================================================
--- /dev/null
+++ openmp/libomptarget/test/offloading/bug53727.cpp
@@ -0,0 +1,57 @@
+// RUN: %libomptarget-compilexx-and-run-generic
+
+#include <cassert>
+#include <iostream>
+
+constexpr const int N = 10;
+
+struct T {
+  int a;
+  int *p;
+};
+
+struct S {
+  int b;
+  T t;
+};
+
+int main(int argc, char *argv[]) {
+  S s;
+  s.t.p = new int[N];
+  for (int i = 0; i < N; ++i) {
+    s.t.p[i] = i;
+  }
+
+#pragma omp target enter data map(to : s, s.t.p[:N])
+
+#pragma omp target
+  {
+    for (int i = 0; i < N; ++i) {
+      s.t.p[i] += i;
+    }
+  }
+
+#pragma omp target update from(s.t.p[:N])
+
+  for (int i = 0; i < N; ++i) {
+    assert(s.t.p[i] == 2 * i);
+    s.t.p[i] += i;
+  }
+
+#pragma omp target update to(s.t.p[:N])
+
+#pragma omp target
+  {
+    for (int i = 0; i < N; ++i) {
+      s.t.p[i] += i;
+    }
+  }
+
+#pragma omp target exit data map(from : s, s.t.p[:N])
+
+  for (int i = 0; i < N; ++i) {
+    assert(s.t.p[i] == 4 * i);
+  }
+
+  return 0;
+}
Index: openmp/libomptarget/src/omptarget.cpp
===================================================================
--- openmp/libomptarget/src/omptarget.cpp
+++ openmp/libomptarget/src/omptarget.cpp
@@ -889,6 +889,7 @@
       DP("Restoring original host pointer value " DPxMOD
          " for host pointer " DPxMOD "\n",
          DPxPTR(Itr->second.HstPtrVal), DPxPTR(ShadowHstPtrAddr));
+      ++Itr;
       return OFFLOAD_SUCCESS;
     };
     applyToShadowMapEntries(Device, CB, HstPtrBegin, ArgSize, TPR);
@@ -911,6 +912,7 @@
                               sizeof(void *), AsyncInfo);
       if (Ret != OFFLOAD_SUCCESS)
         REPORT("Copying data to device failed.\n");
+      ++Itr;
       return Ret;
     };
     applyToShadowMapEntries(Device, CB, HstPtrBegin, ArgSize, TPR);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119471.408228.patch
Type: text/x-patch
Size: 1893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220213/b0d1b84f/attachment.bin>


More information about the Openmp-commits mailing list