[Openmp-commits] [openmp] c27f530 - [OpenMP][Offloading] Fix infinite loop in applyToShadowMapEntries
Shilei Tian via Openmp-commits
openmp-commits at lists.llvm.org
Sat Feb 12 19:02:58 PST 2022
Author: Shilei Tian
Date: 2022-02-12T22:02:53-05:00
New Revision: c27f530d4c6306b2010306131f66e771d6a66594
URL: https://github.com/llvm/llvm-project/commit/c27f530d4c6306b2010306131f66e771d6a66594
DIFF: https://github.com/llvm/llvm-project/commit/c27f530d4c6306b2010306131f66e771d6a66594.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
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 Openmp-commits
mailing list