diff options
author | Jakub Jelinek <jakub@redhat.com> | 2018-10-12 19:29:35 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2018-10-12 19:29:35 +0200 |
commit | 13d7c032ddb77ba0623d27dcedfb7d55751a83cb (patch) | |
tree | 627c251fd38f3f267c08343219ad54dc47194be9 | |
parent | 37bc00e7f05602ffbee267693a522b1fda7f5212 (diff) | |
download | gcc-13d7c032ddb77ba0623d27dcedfb7d55751a83cb.tar.gz |
backport: re PR middle-end/86539 (OpenMP wrong-code with taskloop and references)
Backported from mainline
2018-07-17 Jakub Jelinek <jakub@redhat.com>
PR middle-end/86539
* gimplify.c (gimplify_omp_for): Ensure taskloop firstprivatized init
and cond temporaries don't have reference type if iterator has
pointer type. For init use &for_pre_body instead of pre_p if
for_pre_body is non-empty.
* testsuite/libgomp.c++/pr86539.C: New test.
From-SVN: r265117
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/gimplify.c | 33 | ||||
-rw-r--r-- | libgomp/ChangeLog | 5 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c++/pr86539.C | 28 |
4 files changed, 73 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ebb7f2c19e1..5c5459ed8a0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,14 @@ 2018-10-12 Jakub Jelinek <jakub@redhat.com> Backported from mainline + 2018-07-17 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/86539 + * gimplify.c (gimplify_omp_for): Ensure taskloop firstprivatized init + and cond temporaries don't have reference type if iterator has + pointer type. For init use &for_pre_body instead of pre_p if + for_pre_body is non-empty. + 2018-07-26 Jakub Jelinek <jakub@redhat.com> PR middle-end/86660 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index e59fa5a6807..1181e8e06a2 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -8725,9 +8725,25 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i); if (!is_gimple_constant (TREE_OPERAND (t, 1))) { + tree type = TREE_TYPE (TREE_OPERAND (t, 0)); TREE_OPERAND (t, 1) = get_initialized_tmp_var (TREE_OPERAND (t, 1), - pre_p, NULL); + gimple_seq_empty_p (for_pre_body) + ? pre_p : &for_pre_body, NULL); + /* Reference to pointer conversion is considered useless, + but is significant for firstprivate clause. Force it + here. */ + if (TREE_CODE (type) == POINTER_TYPE + && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 1))) + == REFERENCE_TYPE)) + { + tree v = create_tmp_var (TYPE_MAIN_VARIANT (type)); + tree m = build2 (INIT_EXPR, TREE_TYPE (v), v, + TREE_OPERAND (t, 1)); + gimplify_and_add (m, gimple_seq_empty_p (for_pre_body) + ? pre_p : &for_pre_body); + TREE_OPERAND (t, 1) = v; + } tree c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); OMP_CLAUSE_DECL (c) = TREE_OPERAND (t, 1); @@ -8739,10 +8755,25 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i); if (!is_gimple_constant (TREE_OPERAND (t, 1))) { + tree type = TREE_TYPE (TREE_OPERAND (t, 0)); TREE_OPERAND (t, 1) = get_initialized_tmp_var (TREE_OPERAND (t, 1), gimple_seq_empty_p (for_pre_body) ? pre_p : &for_pre_body, NULL); + /* Reference to pointer conversion is considered useless, + but is significant for firstprivate clause. Force it + here. */ + if (TREE_CODE (type) == POINTER_TYPE + && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 1))) + == REFERENCE_TYPE)) + { + tree v = create_tmp_var (TYPE_MAIN_VARIANT (type)); + tree m = build2 (INIT_EXPR, TREE_TYPE (v), v, + TREE_OPERAND (t, 1)); + gimplify_and_add (m, gimple_seq_empty_p (for_pre_body) + ? pre_p : &for_pre_body); + TREE_OPERAND (t, 1) = v; + } tree c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); OMP_CLAUSE_DECL (c) = TREE_OPERAND (t, 1); diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index a9bbc5aaa56..45357816aec 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,6 +1,11 @@ 2018-10-12 Jakub Jelinek <jakub@redhat.com> Backported from mainline + 2018-07-17 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/86539 + * testsuite/libgomp.c++/pr86539.C: New test. + 2018-07-26 Jakub Jelinek <jakub@redhat.com> PR middle-end/86660 diff --git a/libgomp/testsuite/libgomp.c++/pr86539.C b/libgomp/testsuite/libgomp.c++/pr86539.C new file mode 100644 index 00000000000..ed0d63e4b76 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/pr86539.C @@ -0,0 +1,28 @@ +// PR middle-end/86539 + +int a[384]; + +__attribute__((noinline, noclone)) void +foo (int &b, int &c) +{ + #pragma omp taskloop shared (a) collapse(3) + for (int i = 0; i < 1; i++) + for (int *p = &b; p < &c; p++) + for (int j = 0; j < 1; j++) + if (p < &a[128] || p >= &a[256]) + __builtin_abort (); + else + p[0]++; +} + +int +main () +{ + #pragma omp parallel + #pragma omp single + foo (a[128], a[256]); + for (int i = 0; i < 384; i++) + if (a[i] != (i >= 128 && i < 256)) + __builtin_abort (); + return 0; +} |