From c3ac76aa4078e84d8ca0daf6dab7bc9738f3aa33 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 31 Jul 2019 09:49:56 +0200 Subject: [PATCH] re PR middle-end/91301 (ICE in omp_add_variable on random access iterator distribute parallel for private (iterator)) PR middle-end/91301 * gimplify.c (gimplify_omp_for): If for class iterator on distribute parallel for there is no data sharing clause on inner_for_stmt, look for private clause on combined parallel too and if found, move it to inner_for_stmt. * testsuite/libgomp.c++/for-27.C: New test. From-SVN: r273922 --- gcc/ChangeLog | 8 ++ gcc/gimplify.c | 16 +++ libgomp/ChangeLog | 5 + libgomp/testsuite/libgomp.c++/for-27.C | 169 +++++++++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 libgomp/testsuite/libgomp.c++/for-27.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c946bbad68e..29325388de1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-07-31 Jakub Jelinek + + PR middle-end/91301 + * gimplify.c (gimplify_omp_for): If for class iterator on + distribute parallel for there is no data sharing clause + on inner_for_stmt, look for private clause on combined + parallel too and if found, move it to inner_for_stmt. + 2019-07-31 Richard Sandiford * lra-int.h (lra_operand_data): Remove early_clobber field. diff --git a/gcc/gimplify.c b/gcc/gimplify.c index a40c7ce6663..6a1a7f0b1ac 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -10662,6 +10662,22 @@ gimplify_omp_for (tree *expr_p, gimple_seq *pre_p) || OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_LASTPRIVATE) && OMP_CLAUSE_DECL (*pc) == orig_decl) break; + if (*pc == NULL_TREE) + { + tree *spc; + for (spc = &OMP_PARALLEL_CLAUSES (*data[1]); + *spc; spc = &OMP_CLAUSE_CHAIN (*spc)) + if (OMP_CLAUSE_CODE (*spc) == OMP_CLAUSE_PRIVATE + && OMP_CLAUSE_DECL (*spc) == orig_decl) + break; + if (*spc) + { + tree c = *spc; + *spc = OMP_CLAUSE_CHAIN (c); + OMP_CLAUSE_CHAIN (c) = NULL_TREE; + *pc = c; + } + } if (*pc == NULL_TREE) ; else if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_PRIVATE) diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 85900470792..5adcd74a4ec 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,8 @@ +2019-07-31 Jakub Jelinek + + PR middle-end/91301 + * testsuite/libgomp.c++/for-27.C: New test. + 2019-07-23 Steven G. Kargl * testsuite/libgomp.fortran/reduction4.f90: Update BOZ usage diff --git a/libgomp/testsuite/libgomp.c++/for-27.C b/libgomp/testsuite/libgomp.c++/for-27.C new file mode 100644 index 00000000000..7dca4305f85 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/for-27.C @@ -0,0 +1,169 @@ +// { dg-do run } + +typedef __PTRDIFF_TYPE__ ptrdiff_t; +extern "C" void abort (); + +int a[2000]; + +template +class I +{ +public: + typedef ptrdiff_t difference_type; + I (); + ~I (); + I (T *); + I (const I &); + T &operator * (); + T *operator -> (); + T &operator [] (const difference_type &) const; + I &operator = (const I &); + I &operator ++ (); + I operator ++ (int); + I &operator -- (); + I operator -- (int); + I &operator += (const difference_type &); + I &operator -= (const difference_type &); + I operator + (const difference_type &) const; + I operator - (const difference_type &) const; + template friend bool operator == (I &, I &); + template friend bool operator == (const I &, const I &); + template friend bool operator < (I &, I &); + template friend bool operator < (const I &, const I &); + template friend bool operator <= (I &, I &); + template friend bool operator <= (const I &, const I &); + template friend bool operator > (I &, I &); + template friend bool operator > (const I &, const I &); + template friend bool operator >= (I &, I &); + template friend bool operator >= (const I &, const I &); + template friend typename I::difference_type operator - (I &, I &); + template friend typename I::difference_type operator - (const I &, const I &); + template friend I operator + (typename I::difference_type , const I &); +private: + T *p; +}; +template I::I () : p (0) {} +template I::~I () {} +template I::I (T *x) : p (x) {} +template I::I (const I &x) : p (x.p) {} +template T &I::operator * () { return *p; } +template T *I::operator -> () { return p; } +template T &I::operator [] (const difference_type &x) const { return p[x]; } +template I &I::operator = (const I &x) { p = x.p; return *this; } +template I &I::operator ++ () { ++p; return *this; } +template I I::operator ++ (int) { return I (p++); } +template I &I::operator -- () { --p; return *this; } +template I I::operator -- (int) { return I (p--); } +template I &I::operator += (const difference_type &x) { p += x; return *this; } +template I &I::operator -= (const difference_type &x) { p -= x; return *this; } +template I I::operator + (const difference_type &x) const { return I (p + x); } +template I I::operator - (const difference_type &x) const { return I (p - x); } +template bool operator == (I &x, I &y) { return x.p == y.p; } +template bool operator == (const I &x, const I &y) { return x.p == y.p; } +template bool operator != (I &x, I &y) { return !(x == y); } +template bool operator != (const I &x, const I &y) { return !(x == y); } +template bool operator < (I &x, I &y) { return x.p < y.p; } +template bool operator < (const I &x, const I &y) { return x.p < y.p; } +template bool operator <= (I &x, I &y) { return x.p <= y.p; } +template bool operator <= (const I &x, const I &y) { return x.p <= y.p; } +template bool operator > (I &x, I &y) { return x.p > y.p; } +template bool operator > (const I &x, const I &y) { return x.p > y.p; } +template bool operator >= (I &x, I &y) { return x.p >= y.p; } +template bool operator >= (const I &x, const I &y) { return x.p >= y.p; } +template typename I::difference_type operator - (I &x, I &y) { return x.p - y.p; } +template typename I::difference_type operator - (const I &x, const I &y) { return x.p - y.p; } +template I operator + (typename I::difference_type x, const I &y) { return I (x + y.p); } + +template +class J +{ +public: + J(const I &x, const I &y) : b (x), e (y) {} + const I &begin (); + const I &end (); +private: + I b, e; +}; + +template const I &J::begin () { return b; } +template const I &J::end () { return e; } + +int results[2000]; + +template +void +baz (I &i) +{ + if (*i < 0 || *i >= 2000) + abort (); + results[*i]++; +} + +static inline void +baz (int i) +{ + results[i]++; +} + +void +f1 () +{ +#pragma omp simd + for (auto i : a) + baz (i); +} + +void +f2 (const I &x, const I &y) +{ + I i; +#pragma omp distribute parallel for + for (i = x; i <= y; i += 6) + baz (*i); +} + +void +f3 (const I &x, const I &y) +{ + I i; +#pragma omp distribute parallel for private (i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (*i); +} + +void +f4 (const I &x, const I &y) +{ + I i; +#pragma omp teams distribute parallel for lastprivate (i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (*i); +} + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (results[i] != 1) \ + abort (); \ + results[i] = 0; \ + } \ + else if (results[i]) \ + abort () + +int +main () +{ + for (int i = 0; i < 2000; i++) + a[i] = i; + f1 (); + check (1); + #pragma omp teams + f2 (&a[10], &a[1990]); + check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0); + #pragma omp teams + f3 (&a[0], &a[1999]); + check (i < 1998 && (i & 1) == 0); + f4 (&a[0], &a[30]); + check (i > 40 && i <= 2000 - 64); +} -- 2.30.2