[llvm-branch-commits] [openmp] 01e3eb2 - [OpenMP][Offloading] Fix infinite loop in applyToShadowMapEntries

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 15 03:03:08 PST 2022


Author: Shilei Tian
Date: 2022-02-15T03:02:27-08:00
New Revision: 01e3eb2bd438089ced550ab74de497f2bfa67038

URL: https://github.com/llvm/llvm-project/commit/01e3eb2bd438089ced550ab74de497f2bfa67038
DIFF: https://github.com/llvm/llvm-project/commit/01e3eb2bd438089ced550ab74de497f2bfa67038.diff

LOG: [OpenMP][Offloading] Fix infinite loop in applyToShadowMapEntries

This patch fixes the issue that the for loop in `applyToShadowMapEntries`
is infinite because `Itr` is not incremented in `CB`. Fixes #53727.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D119471

(cherry picked from commit c27f530d4c6306b2010306131f66e771d6a66594)

Added: 
    openmp/libomptarget/test/offloading/bug53727.cpp

Modified: 
    openmp/libomptarget/src/omptarget.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index c8504c8ea5ff9..304091e4f2f1d 100644
--- a/openmp/libomptarget/src/omptarget.cpp
+++ b/openmp/libomptarget/src/omptarget.cpp
@@ -889,6 +889,7 @@ static int targetDataContiguous(ident_t *loc, DeviceTy &Device, void *ArgsBase,
       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 @@ static int targetDataContiguous(ident_t *loc, DeviceTy &Device, void *ArgsBase,
                               sizeof(void *), AsyncInfo);
       if (Ret != OFFLOAD_SUCCESS)
         REPORT("Copying data to device failed.\n");
+      ++Itr;
       return Ret;
     };
     applyToShadowMapEntries(Device, CB, HstPtrBegin, ArgSize, TPR);

diff  --git a/openmp/libomptarget/test/offloading/bug53727.cpp b/openmp/libomptarget/test/offloading/bug53727.cpp
new file mode 100644
index 0000000000000..4744024dfec47
--- /dev/null
+++ b/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;
+}


        


More information about the llvm-branch-commits mailing list