Fix xfail for 32-bit hppa*-*-* in gcc.dg/pr84877.c
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / taskloop-9.C
blob65abc31ff8d06be5576f4161b3fb266bd86c1eb3
1 // { dg-do run }
3 typedef __PTRDIFF_TYPE__ ptrdiff_t;
4 extern "C" void abort ();
6 template <typename T>
7 class I
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;
43 template <typename T> I<T>::I () : p (0) {}
44 template <typename T> I<T>::~I () { p = (T *) 0; }
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); }
75 template <typename T>
76 class J
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;
86 template <typename T> const I<T> &J<T>::begin () { return b; }
87 template <typename T> const I<T> &J<T>::end () { return e; }
89 int results[2000];
91 template <typename T>
92 void
93 baz (I<T> &i)
95   if (*i < 0 || *i >= 2000)
96     abort ();
97   results[*i]++;
100 I<int>
101 f1 (const I<int> &x, const I<int> &y)
103   I<int> i;
104 #pragma omp parallel shared (i)
105   {
106   #pragma omp single
107   #pragma omp taskloop lastprivate (i)
108     for (i = x; i < y - 1; ++i)
109       baz (i);
110   #pragma omp single
111     i += 3;
112   }
113   return I<int> (i);
116 I<int>
117 f2 (const I<int> &x, const I<int> &y)
119   I<int> i;
120 #pragma omp parallel
121 #pragma omp single
122 #pragma omp taskloop lastprivate (i)
123   for (i = x; i < y - 1; i = 1 - 6 + 7 + i)
124     baz (i);
125   return I<int> (i);
128 template <typename T>
129 I<int>
130 f3 (const I<int> &x, const I<int> &y)
132   I<int> i;
133 #pragma omp parallel
134 #pragma omp single
135 #pragma omp taskloop lastprivate (i)
136     for (i = x + 1000 - 64; i <= y - 10; i++)
137       baz (i);
138   return i;
141 template <typename T>
142 I<int>
143 f4 (const I<int> &x, const I<int> &y)
145   I<int> i;
146 #pragma omp parallel
147 #pragma omp single
148 #pragma omp taskloop lastprivate (i)
149   for (i = x + 2000 - 64; i > y + 10; --i)
150     baz (i);
151   return I<int> (i);
154 template <typename T>
155 I<int>
156 f5 (const I<int> &x, const I<int> &y)
158   I<int> i;
159 #pragma omp parallel
160 #pragma omp single
161 #pragma omp taskloop lastprivate (i)
162   for (i = x; i > y + T (6); i--)
163     baz (i);
164   return i;
167 template <typename T>
168 I<int>
169 f6 (const I<int> &x, const I<int> &y)
171   I<int> i;
172 #pragma omp parallel
173 #pragma omp single
174 #pragma omp taskloop lastprivate (i)
175   for (i = x - T (7); i > y; i -= T (2))
176     baz (i);
177   return I<int> (i);
180 template <int N>
181 I<int>
182 f7 (I<int> i, const I<int> &x, const I<int> &y)
184 #pragma omp parallel
185 #pragma omp single
186 #pragma omp taskloop lastprivate (i)
187   for (i = x - 10; i <= y + 10; i += N)
188     baz (i);
189   return I<int> (i);
192 template <int N>
193 I<int>
194 f8 (J<int> j)
196   I<int> i;
197 #pragma omp parallel shared (i)
198   #pragma omp single
199   #pragma omp taskloop lastprivate (i)
200     for (i = j.begin (); i <= j.end () + N; i += 2)
201       baz (i);
202   return i;
205 I<int> i9;
207 template <long N>
208 I<int> &
209 f9 (J<int> j)
211 #pragma omp parallel
212 #pragma omp single
213 #pragma omp taskloop lastprivate (i9)
214   for (i9 = j.begin () + N; i9 <= j.end () - N; i9 = i9 - N)
215     baz (i9);
216   return i9;
219 template <typename T, int N>
220 I<T>
221 f10 (const I<T> &x, const I<T> &y)
223   I<T> i;
224 #pragma omp parallel
225 #pragma omp single
226 #pragma omp taskloop lastprivate (i)
227   for (i = x; i > y; i = i + N)
228     baz (i);
229   return i;
232 template <typename T, typename U>
234 f11 (T i, const T &x, const T &y)
236 #pragma omp parallel
237   #pragma omp single
238   #pragma omp taskloop lastprivate (i)
239   for (i = x + U (2); i <= y + U (1); i = U (2) + U (3) + i)
240     baz (i);
241   return T (i);
244 template <typename T>
246 f12 (const T &x, const T &y)
248   T i;
249 #pragma omp parallel
250 #pragma omp single
251 #pragma omp taskloop lastprivate (i)
252   for (i = x; i > y; --i)
253     baz (i);
254   return i;
257 #define check(expr) \
258   for (int i = 0; i < 2000; i++)                        \
259     if (expr)                                           \
260       {                                                 \
261         if (results[i] != 1)                            \
262           abort ();                                     \
263         results[i] = 0;                                 \
264       }                                                 \
265     else if (results[i])                                \
266       abort ()
269 main ()
271   int a[2000];
272   long b[2000];
273   for (int i = 0; i < 2000; i++)
274     {
275       a[i] = i;
276       b[i] = i;
277     }
278   if (*f1 (&a[10], &a[1873]) != 1875)
279     abort ();
280   check (i >= 10 && i < 1872);
281   if (*f2 (&a[0], &a[1998]) != 1998)
282     abort ();
283   check (i < 1997 && (i & 1) == 0);
284   if (*f3<int> (&a[10], &a[1971]) != 1962)
285     abort ();
286   check (i >= 946 && i <= 1961);
287   if (*f4<int> (&a[0], &a[30]) != 40)
288     abort ();
289   check (i > 40 && i <= 2000 - 64);
290   if (*f5<short> (&a[1931], &a[17]) != 23)
291     abort ();
292   check (i > 23 && i <= 1931);
293   if (*f6<long> (&a[1931], &a[17]) != 16)
294     abort ();
295   check (i > 17 && i <= 1924 && (i & 1) == 0);
296   if (*f7<6> (I<int> (), &a[12], &a[1800]) != 1814)
297     abort ();
298   check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0);
299   if (*f8<121> (J<int> (&a[14], &a[1803])) != 1926)
300     abort ();
301   check (i >= 14 && i <= 1924 && (i & 1) == 0);
302   if (*f9<-3L> (J<int> (&a[27], &a[1761])) != 1767)
303     abort ();
304   check (i >= 24 && i <= 1764 && (i % 3) == 0);
305   if (*f10<int, -7> (&a[1939], &a[17]) != 14)
306     abort ();
307   check (i >= 21 && i <= 1939 && i % 7 == 0);
308   if (*f11<I<int>, short> (I<int> (), &a[71], &a[1941]) != 1943)
309     abort ();
310   check (i >= 73 && i <= 1938 && (i - 73) % 5 == 0);
311   if (*f12<I<int> > (&a[1761], &a[37]) != 37)
312     abort ();
313   check (i > 37 && i <= 1761);
314   if (*f10<long, -7> (&b[1939], &b[17]) != 14)
315     abort ();
316   check (i >= 21 && i <= 1939 && i % 7 == 0);
317   if (*f11<I<long>, short> (I<long> (), &b[71], &b[1941]) != 1943)
318     abort ();
319   check (i >= 73 && i <= 1938 && (i - 73) % 5 == 0);
320   if (*f12<I<long> > (&b[1761], &b[37]) != 37)
321     abort ();
322   check (i > 37 && i <= 1761);