aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShilei Tian <i@tianshilei.me>2022-02-12 22:02:47 -0500
committerTom Stellard <tstellar@redhat.com>2022-02-15 03:02:27 -0800
commit01e3eb2bd438089ced550ab74de497f2bfa67038 (patch)
tree28d74832e9f98c773a203cad7841b26f731d36f2
parentf0b442c8ac58bbd40489defd2f3d65ff0b02b09c (diff)
downloadllvm-01e3eb2bd438089ced550ab74de497f2bfa67038.zip
llvm-01e3eb2bd438089ced550ab74de497f2bfa67038.tar.gz
llvm-01e3eb2bd438089ced550ab74de497f2bfa67038.tar.bz2
[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)
-rw-r--r--openmp/libomptarget/src/omptarget.cpp2
-rw-r--r--openmp/libomptarget/test/offloading/bug53727.cpp57
2 files changed, 59 insertions, 0 deletions
diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index c8504c8..304091e 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 0000000..4744024
--- /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;
+}