// PR c++/86443 // { dg-do run } // { dg-additional-options "-std=c++17" } typedef __PTRDIFF_TYPE__ ptrdiff_t; extern "C" void abort (); #pragma omp declare target 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]++; } void baz (int i) { if (i < 0 || i >= 2000) abort (); results[i]++; } void f1 (J j) { #pragma omp distribute parallel for default(none) for (I i = j.begin (); i < j.end (); i += 3) baz (*i); } void f2 (J j) { I i; #pragma omp distribute parallel for default(none) for (i = j.begin (); i < j.end (); ++i) baz (*i); } template void f3 (J j) { #pragma omp distribute parallel for default(none) for (I i = j.begin (); i < j.end (); i += 6) baz (*i); } template void f4 (J j) { I i; #pragma omp distribute parallel for default(none) for (i = j.begin (); i < j.end (); i += 9) baz (*i); } template void f5 (J j) { #pragma omp distribute parallel for default(none) for (I i = j.begin (); i < j.end (); i += 4) baz (*i); } template void f6 (J j) { I i; #pragma omp distribute parallel for default(none) for (i = j.begin (); i < j.end (); i += 7) baz (*i); } #pragma omp end declare target #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 () { int a[2000]; for (int i = 0; i < 2000; i++) a[i] = i; #pragma omp target data map (to: a) { #pragma omp target teams map (always, tofrom: results) { J j (&a[75], &a[1945]); f1 (j); } check (i >= 75 && i < 1945 && (i - 75) % 3 == 0); #pragma omp target teams map (always, tofrom: results) { J j (&a[63], &a[1949]); f2 (j); } check (i >= 63 && i < 1949); #pragma omp target teams map (always, tofrom: results) { J j (&a[58], &a[1979]); f3 <2> (j); } check (i >= 58 && i < 1979 && (i - 58) % 6 == 0); #pragma omp target teams map (always, tofrom: results) { J j (&a[59], &a[1981]); f4 <9> (j); } check (i >= 59 && i < 1981 && (i - 59) % 9 == 0); #pragma omp target teams map (always, tofrom: results) { J j (&a[52], &a[1972]); f5 (j); } check (i >= 52 && i < 1972 && (i - 52) % 4 == 0); #pragma omp target teams map (always, tofrom: results) { J j (&a[31], &a[1827]); f6 (j); } check (i >= 31 && i < 1827 && (i - 31) % 7 == 0); } }