diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-09-07 20:18:45 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-09-07 20:18:45 +0000 |
commit | cda45e54690704301689e9d2b33ca378698538d3 (patch) | |
tree | c9402e4154bca00f2baa0227e10f6c5a507ab885 | |
parent | cb70da2a2c124e5aa8192e5a77cdec9bd4f0bdd0 (diff) |
Backported from mainline
2017-07-27 Jakub Jelinek <jakub@redhat.com>
PR c/45784
* c-omp.c (c_finish_omp_for): If the condition is wrapped in
rhs of COMPOUND_EXPR(s), skip them and readd their lhs into
new COMPOUND_EXPRs around the rhs of the comparison.
* testsuite/libgomp.c/pr45784.c: New test.
* testsuite/libgomp.c++/pr45784.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@251848 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/c-family/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/c-family/c-omp.c | 21 | ||||
-rw-r--r-- | libgomp/ChangeLog | 9 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c++/pr45784.C | 5 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c/pr45784.c | 41 |
5 files changed, 86 insertions, 0 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 264200b050ee..26b0073b79d9 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,13 @@ +2017-09-07 Jakub Jelinek <jakub@redhat.com> + + Backported from mainline + 2017-07-27 Jakub Jelinek <jakub@redhat.com> + + PR c/45784 + * c-omp.c (c_finish_omp_for): If the condition is wrapped in + rhs of COMPOUND_EXPR(s), skip them and readd their lhs into + new COMPOUND_EXPRs around the rhs of the comparison. + 2017-08-14 Release Manager * GCC 7.2.0 released. diff --git a/gcc/c-family/c-omp.c b/gcc/c-family/c-omp.c index 519c4e4ce669..977cb0ea1530 100644 --- a/gcc/c-family/c-omp.c +++ b/gcc/c-family/c-omp.c @@ -531,6 +531,12 @@ c_finish_omp_for (location_t locus, enum tree_code code, tree declv, { bool cond_ok = false; + /* E.g. C sizeof (vla) could add COMPOUND_EXPRs with + evaluation of the vla VAR_DECL. We need to readd + them to the non-decl operand. See PR45784. */ + while (TREE_CODE (cond) == COMPOUND_EXPR) + cond = TREE_OPERAND (cond, 1); + if (EXPR_HAS_LOCATION (cond)) elocus = EXPR_LOCATION (cond); @@ -605,6 +611,21 @@ c_finish_omp_for (location_t locus, enum tree_code code, tree declv, else if (code != CILK_SIMD && code != CILK_FOR) cond_ok = false; } + + if (cond_ok && TREE_VEC_ELT (condv, i) != cond) + { + tree ce = NULL_TREE, *pce = &ce; + tree type = TREE_TYPE (TREE_OPERAND (cond, 1)); + for (tree c = TREE_VEC_ELT (condv, i); c != cond; + c = TREE_OPERAND (c, 1)) + { + *pce = build2 (COMPOUND_EXPR, type, TREE_OPERAND (c, 0), + TREE_OPERAND (cond, 1)); + pce = &TREE_OPERAND (*pce, 1); + } + TREE_OPERAND (cond, 1) = ce; + TREE_VEC_ELT (condv, i) = cond; + } } if (!cond_ok) diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 7532a96d26d1..6cc292798875 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,12 @@ +2017-09-07 Jakub Jelinek <jakub@redhat.com> + + Backported from mainline + 2017-07-27 Jakub Jelinek <jakub@redhat.com> + + PR c/45784 + * testsuite/libgomp.c/pr45784.c: New test. + * testsuite/libgomp.c++/pr45784.C: New test. + 2017-08-14 Release Manager * GCC 7.2.0 released. diff --git a/libgomp/testsuite/libgomp.c++/pr45784.C b/libgomp/testsuite/libgomp.c++/pr45784.C new file mode 100644 index 000000000000..306246c754af --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/pr45784.C @@ -0,0 +1,5 @@ +// PR c/45784 +// { dg-do run } + +#include "../libgomp.c/pr45784.c" + diff --git a/libgomp/testsuite/libgomp.c/pr45784.c b/libgomp/testsuite/libgomp.c/pr45784.c new file mode 100644 index 000000000000..78612108bf63 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/pr45784.c @@ -0,0 +1,41 @@ +/* PR c/45784 */ +/* { dg-do run } */ + +void +foo (int n) +{ + char *p, vla[2 * n]; + int i; + #pragma omp parallel for + for (p = vla; p < vla + (sizeof (vla) / sizeof (vla[0])); p++) + *p = ' '; + #pragma omp parallel for + for (i = 0; i < 2 * n; i++) + if (vla[i] != ' ') + __builtin_abort (); +} + +void +bar (int n) +{ + char *p, vla1[n], vla2[n * 2], vla3[n * 3], vla4[n * 4]; + int i; + __builtin_memset (vla4, ' ', n * 4); + #pragma omp parallel for + for (p = vla4 + sizeof (vla1); p < vla4 + sizeof (vla3) - sizeof (vla2) + sizeof (vla1); p += sizeof (vla4) / sizeof (vla4)) + p[0] = '!'; + #pragma omp parallel for + for (i = 0; i < n * 4; i++) + if (vla4[i] != ((i >= n && i < 2 * n) ? '!' : ' ')) + __builtin_abort (); +} + +int +main () +{ + volatile int n; + n = 128; + foo (n); + bar (n); + return 0; +} |