diff --git a/openmp/libomptarget/test/offloading/bug50022.cpp b/openmp/libomptarget/test/offloading/bug50022.cpp new file mode 100644 --- /dev/null +++ b/openmp/libomptarget/test/offloading/bug50022.cpp @@ -0,0 +1,39 @@ +// RUN: %libomptarget-compilexx-and-run-generic + +#include +#include +#include + +int main(int argc, char *argv[]) { + int a = 0; + std::cout << "outside a = " << a << " addr " << &a << std::endl; +#pragma omp target map(tofrom : a) depend(out : a) nowait + { + int sum = 0; + for (int i = 0; i < 100000; i++) + sum++; + a = 1; + } + +#pragma omp task depend(inout : a) shared(a) + { + std::cout << "a = " << a << " addr " << &a << std::endl; + if (a != 1) + throw std::runtime_error("wrong result!"); + a = 2; + } + +#pragma omp task depend(inout : a) shared(a) + { + std::cout << "a = " << a << " addr " << &a << std::endl; + if (a != 2) + throw std::runtime_error("wrong result!"); + a = 3; + } + +#pragma omp taskwait + + assert(a == 3 && "wrong result!"); + + return 0; +} diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp --- a/openmp/runtime/src/kmp_tasking.cpp +++ b/openmp/runtime/src/kmp_tasking.cpp @@ -940,16 +940,17 @@ if (!(taskdata->td_flags.team_serial || taskdata->td_flags.tasking_ser) || taskdata->td_flags.detachable == TASK_DETACHABLE || taskdata->td_flags.hidden_helper) { + __kmp_release_deps(gtid, taskdata); // Predecrement simulated by "- 1" calculation children = KMP_ATOMIC_DEC(&taskdata->td_parent->td_incomplete_child_tasks) - 1; KMP_DEBUG_ASSERT(children >= 0); if (taskdata->td_taskgroup) KMP_ATOMIC_DEC(&taskdata->td_taskgroup->count); - __kmp_release_deps(gtid, taskdata); - } else if (task_team && task_team->tt.tt_found_proxy_tasks) { - // if we found proxy tasks there could exist a dependency chain - // with the proxy task as origin + } else if (task_team && (task_team->tt.tt_found_proxy_tasks || + task_team->tt.tt_hidden_helper_task_encountered)) { + // if we found proxy or hidden helper tasks there could exist a dependency + // chain with the proxy task as origin __kmp_release_deps(gtid, taskdata); } // td_flags.executing must be marked as 0 after __kmp_release_deps has been