diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-12-18 21:43:20 +0100 |
---|---|---|
committer | Kwok Cheung Yeung <kcy@codesourcery.com> | 2021-01-22 08:19:13 -0800 |
commit | d4d00bc2f8fa2b130e50145db385fecf5858c845 (patch) | |
tree | 35ccd562f8af6b69e546b20fa2489ad4091ffb60 /libgomp | |
parent | f61fbb53ecf775cd491794f14847c2f1ebc88951 (diff) | |
download | gcc-d4d00bc2f8fa2b130e50145db385fecf5858c845.tar.gz |
openmp: Don't optimize shared to firstprivate on task with depend clause
The attached testcase is miscompiled, because we optimize shared clauses
to firstprivate when task body can't modify the variable even when the
task has depend clause. That is wrong, because firstprivate means the
variable will be copied immediately when the task is created, while with
depend clause some other task might change it later before the dependencies
are satisfied and the task should observe the value only after the change.
2020-12-18 Jakub Jelinek <jakub@redhat.com>
* gimplify.c (struct gimplify_omp_ctx): Add has_depend member.
(gimplify_scan_omp_clauses): Set it to true if OMP_CLAUSE_DEPEND
appears on OMP_TASK.
(gimplify_adjust_omp_clauses_1, gimplify_adjust_omp_clauses): Force
GOVD_WRITTEN on shared variables if task construct has depend clause.
* testsuite/libgomp.c/task-6.c: New test.
(cherry picked from commit 8b60459465252c7d47b58abf83fae2aa84915b03)
Diffstat (limited to 'libgomp')
-rw-r--r-- | libgomp/ChangeLog.omp | 7 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c/task-6.c | 47 |
2 files changed, 54 insertions, 0 deletions
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index bc500000af8..3518bc8eae5 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,6 +1,13 @@ 2021-01-22 Kwok Cheung Yeung <kcy@codesourcery.com> Backport from mainline + 2020-12-18 Jakub Jelinek <jakub@redhat.com> + + * testsuite/libgomp.c/task-6.c: New test. + +2021-01-22 Kwok Cheung Yeung <kcy@codesourcery.com> + + Backport from mainline 2021-01-18 Sebastian Huber <sebastian.huber@embedded-brains.de> * config/rtems/sem.h (gomp_sem_getcount): New function. diff --git a/libgomp/testsuite/libgomp.c/task-6.c b/libgomp/testsuite/libgomp.c/task-6.c new file mode 100644 index 00000000000..e5fc758d283 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/task-6.c @@ -0,0 +1,47 @@ +#include <stdlib.h> +#include <unistd.h> + +int +main () +{ + int x = 0, y = 0; + #pragma omp parallel shared(x, y) + #pragma omp master + { + #pragma omp task depend(out:y) shared(x, y) + { + sleep (1); + x = 1; + y = 1; + } + #pragma omp task depend(inout:y) shared(x, y) + { + if (x != 1 || y != 1) + abort (); + y++; + } + } + if (x != 1 || y != 2) + abort (); + x = 0; + y = 0; + #pragma omp parallel + #pragma omp master + { + #pragma omp task depend(out:y) + { + sleep (1); + x = 1; + y = 1; + } + #pragma omp task depend(inout:y) + { + if (x != 1 || y != 1) + abort (); + y++; + } + } + if (x != 1 || y != 2) + abort (); + return 0; +} |