| 1 |
// { dg-do run } |
| 2 |
|
| 3 |
typedef __PTRDIFF_TYPE__ ptrdiff_t; |
| 4 |
extern "C" void abort (); |
| 5 |
|
| 6 |
template <typename T> |
| 7 |
class I |
| 8 |
{ |
| 9 |
public: |
| 10 |
typedef ptrdiff_t difference_type; |
| 11 |
I (); |
| 12 |
~I (); |
| 13 |
I (T *); |
| 14 |
I (const I &); |
| 15 |
T &operator * (); |
| 16 |
T *operator -> (); |
| 17 |
T &operator [] (const difference_type &) const; |
| 18 |
I &operator = (const I &); |
| 19 |
I &operator ++ (); |
| 20 |
I operator ++ (int); |
| 21 |
I &operator -- (); |
| 22 |
I operator -- (int); |
| 23 |
I &operator += (const difference_type &); |
| 24 |
I &operator -= (const difference_type &); |
| 25 |
I operator + (const difference_type &) const; |
| 26 |
I operator - (const difference_type &) const; |
| 27 |
template <typename S> friend bool operator == (I<S> &, I<S> &); |
| 28 |
template <typename S> friend bool operator == (const I<S> &, const I<S> &); |
| 29 |
template <typename S> friend bool operator < (I<S> &, I<S> &); |
| 30 |
template <typename S> friend bool operator < (const I<S> &, const I<S> &); |
| 31 |
template <typename S> friend bool operator <= (I<S> &, I<S> &); |
| 32 |
template <typename S> friend bool operator <= (const I<S> &, const I<S> &); |
| 33 |
template <typename S> friend bool operator > (I<S> &, I<S> &); |
| 34 |
template <typename S> friend bool operator > (const I<S> &, const I<S> &); |
| 35 |
template <typename S> friend bool operator >= (I<S> &, I<S> &); |
| 36 |
template <typename S> friend bool operator >= (const I<S> &, const I<S> &); |
| 37 |
template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &); |
| 38 |
template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &); |
| 39 |
template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &); |
| 40 |
private: |
| 41 |
T *p; |
| 42 |
}; |
| 43 |
template <typename T> I<T>::I () : p (0) {} |
| 44 |
template <typename T> I<T>::~I () {} |
| 45 |
template <typename T> I<T>::I (T *x) : p (x) {} |
| 46 |
template <typename T> I<T>::I (const I &x) : p (x.p) {} |
| 47 |
template <typename T> T &I<T>::operator * () { return *p; } |
| 48 |
template <typename T> T *I<T>::operator -> () { return p; } |
| 49 |
template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; } |
| 50 |
template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; } |
| 51 |
template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; } |
| 52 |
template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); } |
| 53 |
template <typename T> I<T> &I<T>::operator -- () { --p; return *this; } |
| 54 |
template <typename T> I<T> I<T>::operator -- (int) { return I (p--); } |
| 55 |
template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; } |
| 56 |
template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; } |
| 57 |
template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); } |
| 58 |
template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); } |
| 59 |
template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; } |
| 60 |
template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; } |
| 61 |
template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); } |
| 62 |
template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); } |
| 63 |
template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; } |
| 64 |
template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; } |
| 65 |
template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; } |
| 66 |
template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; } |
| 67 |
template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; } |
| 68 |
template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; } |
| 69 |
template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; } |
| 70 |
template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; } |
| 71 |
template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; } |
| 72 |
template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; } |
| 73 |
template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); } |
| 74 |
|
| 75 |
template <typename T> |
| 76 |
class J |
| 77 |
{ |
| 78 |
public: |
| 79 |
J(const I<T> &x, const I<T> &y) : b (x), e (y) {} |
| 80 |
const I<T> &begin (); |
| 81 |
const I<T> &end (); |
| 82 |
private: |
| 83 |
I<T> b, e; |
| 84 |
}; |
| 85 |
|
| 86 |
template <typename T> const I<T> &J<T>::begin () { return b; } |
| 87 |
template <typename T> const I<T> &J<T>::end () { return e; } |
| 88 |
|
| 89 |
int results[2000]; |
| 90 |
|
| 91 |
template <typename T> |
| 92 |
void |
| 93 |
baz (I<T> &i) |
| 94 |
{ |
| 95 |
if (*i < 0 || *i >= 2000) |
| 96 |
abort (); |
| 97 |
results[*i]++; |
| 98 |
} |
| 99 |
|
| 100 |
void |
| 101 |
f1 (const I<int> &x, const I<int> &y) |
| 102 |
{ |
| 103 |
#pragma omp parallel |
| 104 |
#pragma omp single |
| 105 |
#pragma omp taskloop num_tasks(22) |
| 106 |
for (I<int> i = x; i <= y; i += 6) |
| 107 |
baz (i); |
| 108 |
} |
| 109 |
|
| 110 |
void |
| 111 |
f2 (const I<int> &x, const I<int> &y) |
| 112 |
{ |
| 113 |
I<int> i; |
| 114 |
#pragma omp parallel |
| 115 |
#pragma omp single |
| 116 |
#pragma omp taskloop grainsize(384) private(i) |
| 117 |
for (i = x; i < y - 1; i = 1 - 6 + 7 + i) |
| 118 |
baz (i); |
| 119 |
} |
| 120 |
|
| 121 |
template <typename T> |
| 122 |
void |
| 123 |
f3 (const I<int> &x, const I<int> &y) |
| 124 |
{ |
| 125 |
#pragma omp parallel |
| 126 |
#pragma omp single |
| 127 |
#pragma omp taskloop default(none) firstprivate (x, y) |
| 128 |
for (I<int> i = x; i <= y; i = i + 9 - 8) |
| 129 |
baz (i); |
| 130 |
} |
| 131 |
|
| 132 |
template <typename T> |
| 133 |
void |
| 134 |
f4 (const I<int> &x, const I<int> &y) |
| 135 |
{ |
| 136 |
I<int> i; |
| 137 |
#pragma omp parallel |
| 138 |
#pragma omp single |
| 139 |
#pragma omp taskloop lastprivate(i) |
| 140 |
for (i = x + 2000 - 64; i > y + 10; --i) |
| 141 |
baz (i); |
| 142 |
} |
| 143 |
|
| 144 |
void |
| 145 |
f5 (const I<int> &x, const I<int> &y) |
| 146 |
{ |
| 147 |
#pragma omp parallel |
| 148 |
#pragma omp single |
| 149 |
#pragma omp taskloop |
| 150 |
for (I<int> i = x + 2000 - 64; i > y + 10; i -= 10) |
| 151 |
baz (i); |
| 152 |
} |
| 153 |
|
| 154 |
template <int N> |
| 155 |
void |
| 156 |
f6 (const I<int> &x, const I<int> &y) |
| 157 |
{ |
| 158 |
#pragma omp parallel |
| 159 |
#pragma omp single |
| 160 |
#pragma omp taskloop |
| 161 |
for (I<int> i = x + 2000 - 64; i > y + 10; i = i - 12 + 2) |
| 162 |
{ |
| 163 |
I<int> j = i + N; |
| 164 |
baz (j); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
template <int N> |
| 169 |
void |
| 170 |
f7 (I<int> i, const I<int> &x, const I<int> &y) |
| 171 |
{ |
| 172 |
#pragma omp parallel |
| 173 |
#pragma omp single |
| 174 |
#pragma omp taskloop default(none) firstprivate (x, y) |
| 175 |
for (i = x - 10; i <= y + 10; i += N) |
| 176 |
baz (i); |
| 177 |
} |
| 178 |
|
| 179 |
template <int N> |
| 180 |
void |
| 181 |
f8 (J<int> j) |
| 182 |
{ |
| 183 |
I<int> i; |
| 184 |
#pragma omp parallel |
| 185 |
#pragma omp single |
| 186 |
#pragma omp taskloop default(none) num_tasks(*I<int> (j.begin ())) firstprivate (j) |
| 187 |
for (i = j.begin (); i <= j.end () + N; i += 2) |
| 188 |
baz (i); |
| 189 |
} |
| 190 |
|
| 191 |
template <typename T, int N> |
| 192 |
void |
| 193 |
f9 (const I<T> &x, const I<T> &y) |
| 194 |
{ |
| 195 |
#pragma omp parallel |
| 196 |
#pragma omp single |
| 197 |
#pragma omp taskloop grainsize(163) |
| 198 |
for (I<T> i = x; i <= y; i = i + N) |
| 199 |
baz (i); |
| 200 |
} |
| 201 |
|
| 202 |
template <typename T, int N> |
| 203 |
void |
| 204 |
f10 (const I<T> &x, const I<T> &y) |
| 205 |
{ |
| 206 |
I<T> i; |
| 207 |
#pragma omp parallel |
| 208 |
#pragma omp single |
| 209 |
#pragma omp taskloop |
| 210 |
for (i = x; i > y; i = i + N) |
| 211 |
baz (i); |
| 212 |
} |
| 213 |
|
| 214 |
template <typename T> |
| 215 |
void |
| 216 |
f11 (const T &x, const T &y) |
| 217 |
{ |
| 218 |
#pragma omp parallel |
| 219 |
{ |
| 220 |
#pragma omp single nowait |
| 221 |
#pragma omp taskloop nogroup |
| 222 |
for (T i = x; i <= y; i += 3) |
| 223 |
baz (i); |
| 224 |
#pragma omp single nowait |
| 225 |
{ |
| 226 |
T j = y + 3; |
| 227 |
baz (j); |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
template <typename T> |
| 233 |
void |
| 234 |
f12 (const T &x, const T &y) |
| 235 |
{ |
| 236 |
T i; |
| 237 |
#pragma omp parallel |
| 238 |
#pragma omp single |
| 239 |
#pragma omp taskloop |
| 240 |
for (i = x; i > y; --i) |
| 241 |
baz (i); |
| 242 |
} |
| 243 |
|
| 244 |
template <int N> |
| 245 |
struct K |
| 246 |
{ |
| 247 |
template <typename T> |
| 248 |
static void |
| 249 |
f13 (const T &x, const T &y) |
| 250 |
{ |
| 251 |
#pragma omp parallel |
| 252 |
#pragma omp single |
| 253 |
#pragma omp taskloop |
| 254 |
for (T i = x; i <= y + N; i += N) |
| 255 |
baz (i); |
| 256 |
} |
| 257 |
}; |
| 258 |
|
| 259 |
I<int> |
| 260 |
f14 (const I<int> &x, const I<int> &y) |
| 261 |
{ |
| 262 |
I<int> i; |
| 263 |
#pragma omp parallel |
| 264 |
#pragma omp single |
| 265 |
#pragma omp taskloop lastprivate(i) |
| 266 |
for (i = x; i < y - 1; i = 1 - 6 + 7 + i) |
| 267 |
baz (i); |
| 268 |
return i; |
| 269 |
} |
| 270 |
|
| 271 |
template <typename T> |
| 272 |
I<int> |
| 273 |
f15 (const I<int> &x, const I<int> &y) |
| 274 |
{ |
| 275 |
I<int> i; |
| 276 |
#pragma omp parallel |
| 277 |
#pragma omp single |
| 278 |
#pragma omp taskloop lastprivate(i) |
| 279 |
for (i = x + 2000 - 64; i > y + 10; --i) |
| 280 |
baz (i); |
| 281 |
return i; |
| 282 |
} |
| 283 |
|
| 284 |
template <int N> |
| 285 |
I<int> |
| 286 |
f16 (I<int> i, const I<int> &x, const I<int> &y) |
| 287 |
{ |
| 288 |
#pragma omp parallel |
| 289 |
#pragma omp single |
| 290 |
#pragma omp taskloop lastprivate(i) |
| 291 |
for (i = x - 10; i <= y + 10; i += N) |
| 292 |
baz (i); |
| 293 |
return i; |
| 294 |
} |
| 295 |
|
| 296 |
template <int N> |
| 297 |
I<int> |
| 298 |
f17 (J<int> j) |
| 299 |
{ |
| 300 |
static I<int> i; |
| 301 |
#pragma omp parallel |
| 302 |
#pragma omp single |
| 303 |
#pragma omp taskloop lastprivate(i) |
| 304 |
for (i = j.begin (); i <= j.end () + N; i += 2) |
| 305 |
baz (i); |
| 306 |
return i; |
| 307 |
} |
| 308 |
|
| 309 |
template <typename T, int N> |
| 310 |
I<T> |
| 311 |
f18 (const I<T> &x, const I<T> &y) |
| 312 |
{ |
| 313 |
static I<T> i; |
| 314 |
#pragma omp parallel |
| 315 |
#pragma omp single |
| 316 |
#pragma omp taskloop lastprivate(i) |
| 317 |
for (i = x; i > y; i = i + N) |
| 318 |
baz (i); |
| 319 |
return i; |
| 320 |
} |
| 321 |
|
| 322 |
template <typename T> |
| 323 |
T |
| 324 |
f19 (const T &x, const T &y) |
| 325 |
{ |
| 326 |
T i; |
| 327 |
#pragma omp parallel |
| 328 |
{ |
| 329 |
#pragma omp single nowait |
| 330 |
#pragma omp taskloop nogroup lastprivate(i) |
| 331 |
for (i = x; i <= y; i += 3) |
| 332 |
baz (i); |
| 333 |
#pragma omp single nowait |
| 334 |
{ |
| 335 |
T j = y + 3; |
| 336 |
baz (j); |
| 337 |
} |
| 338 |
} |
| 339 |
return i; |
| 340 |
} |
| 341 |
|
| 342 |
template <typename T> |
| 343 |
T |
| 344 |
f20 (const T &x, const T &y) |
| 345 |
{ |
| 346 |
T i; |
| 347 |
#pragma omp parallel |
| 348 |
#pragma omp single |
| 349 |
#pragma omp taskloop lastprivate(i) |
| 350 |
for (i = x; i > y; --i) |
| 351 |
baz (i); |
| 352 |
return i; |
| 353 |
} |
| 354 |
|
| 355 |
#define check(expr) \ |
| 356 |
for (int i = 0; i < 2000; i++) \ |
| 357 |
if (expr) \ |
| 358 |
{ \ |
| 359 |
if (results[i] != 1) \ |
| 360 |
abort (); \ |
| 361 |
results[i] = 0; \ |
| 362 |
} \ |
| 363 |
else if (results[i]) \ |
| 364 |
abort () |
| 365 |
|
| 366 |
int |
| 367 |
main () |
| 368 |
{ |
| 369 |
int a[2000]; |
| 370 |
long b[2000]; |
| 371 |
for (int i = 0; i < 2000; i++) |
| 372 |
{ |
| 373 |
a[i] = i; |
| 374 |
b[i] = i; |
| 375 |
} |
| 376 |
f1 (&a[10], &a[1990]); |
| 377 |
check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0); |
| 378 |
f2 (&a[0], &a[1999]); |
| 379 |
check (i < 1998 && (i & 1) == 0); |
| 380 |
f3<char> (&a[20], &a[1837]); |
| 381 |
check (i >= 20 && i <= 1837); |
| 382 |
f4<int> (&a[0], &a[30]); |
| 383 |
check (i > 40 && i <= 2000 - 64); |
| 384 |
f5 (&a[0], &a[100]); |
| 385 |
check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); |
| 386 |
f6<-10> (&a[10], &a[110]); |
| 387 |
check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); |
| 388 |
f7<6> (I<int> (), &a[12], &a[1800]); |
| 389 |
check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); |
| 390 |
f8<121> (J<int> (&a[14], &a[1803])); |
| 391 |
check (i >= 14 && i <= 1924 && (i & 1) == 0); |
| 392 |
f9<int, 7> (&a[33], &a[1967]); |
| 393 |
check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); |
| 394 |
f10<int, -7> (&a[1939], &a[17]); |
| 395 |
check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); |
| 396 |
f11<I<int> > (&a[16], &a[1981]); |
| 397 |
check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); |
| 398 |
f12<I<int> > (&a[1761], &a[37]); |
| 399 |
check (i > 37 && i <= 1761); |
| 400 |
K<5>::f13<I<int> > (&a[1], &a[1935]); |
| 401 |
check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); |
| 402 |
if (f14 (&a[0], &a[1999]) != I<int>(&a[1998])) |
| 403 |
abort (); |
| 404 |
check (i < 1998 && (i & 1) == 0); |
| 405 |
if (f15<int> (&a[0], &a[30]) != I<int>(&a[40])) |
| 406 |
abort (); |
| 407 |
check (i > 40 && i <= 2000 - 64); |
| 408 |
if (f16<6> (I<int> (), &a[12], &a[1800]) != I<int>(&a[1814])) |
| 409 |
abort (); |
| 410 |
check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); |
| 411 |
if (f17<121> (J<int> (&a[14], &a[1803])) != I<int>(&a[1926])) |
| 412 |
abort (); |
| 413 |
check (i >= 14 && i <= 1924 && (i & 1) == 0); |
| 414 |
if (f18<int, -7> (&a[1939], &a[17]) != I<int>(&a[14])) |
| 415 |
abort (); |
| 416 |
check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); |
| 417 |
if (f19<I<int> > (&a[16], &a[1981]) != I<int>(&a[1984])) |
| 418 |
abort (); |
| 419 |
check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); |
| 420 |
if (f20<I<int> > (&a[1761], &a[37]) != I<int>(&a[37])) |
| 421 |
abort (); |
| 422 |
check (i > 37 && i <= 1761); |
| 423 |
f9<long, 7> (&b[33], &b[1967]); |
| 424 |
check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); |
| 425 |
f10<long, -7> (&b[1939], &b[17]); |
| 426 |
check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); |
| 427 |
f11<I<long> > (&b[16], &b[1981]); |
| 428 |
check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); |
| 429 |
f12<I<long> > (&b[1761], &b[37]); |
| 430 |
check (i > 37 && i <= 1761); |
| 431 |
K<5>::f13<I<long> > (&b[1], &b[1935]); |
| 432 |
check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); |
| 433 |
if (f18<long, -7> (&b[1939], &b[17]) != I<long>(&b[14])) |
| 434 |
abort (); |
| 435 |
check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); |
| 436 |
if (f19<I<long> > (&b[16], &b[1981]) != I<long>(&b[1984])) |
| 437 |
abort (); |
| 438 |
check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); |
| 439 |
if (f20<I<long> > (&b[1761], &b[37]) != I<long>(&b[37])) |
| 440 |
abort (); |
| 441 |
check (i > 37 && i <= 1761); |
| 442 |
} |