Fix xfail for 32-bit hppa*-*-* in gcc.dg/pr84877.c
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / scan-5.C
blob5931a7fe14e856901b34de4557d429ed6af3a8b8
1 // { dg-require-effective-target size32plus }
3 extern "C" void abort ();
5 template <typename T>
6 struct S {
7   inline S ();
8   inline ~S ();
9   inline S (const S &);
10   inline S & operator= (const S &);
11   T s;
14 template <typename T>
15 S<T>::S () : s (0)
19 template <typename T>
20 S<T>::~S ()
24 template <typename T>
25 S<T>::S (const S &x)
27   s = x.s;
30 template <typename T>
31 S<T> &
32 S<T>::operator= (const S &x)
34   s = x.s;
35   return *this;
38 template <typename T>
39 static inline void
40 ini (S<T> &x)
42   x.s = 0;
45 S<int> r, a[1024], b[1024];
47 #pragma omp declare reduction (+: S<int>: omp_out.s += omp_in.s)
48 #pragma omp declare reduction (plus: S<int>: omp_out.s += omp_in.s) initializer (ini (omp_priv))
50 template <typename T>
51 __attribute__((noipa)) void
52 foo (S<T> *a, S<T> *b)
54   #pragma omp for reduction (inscan, +:r)
55   for (int i = 0; i < 1024; i++)
56     {
57       b[i] = r;
58       #pragma omp scan exclusive(r)
59       r.s += a[i].s;
60     }
63 template <typename T>
64 __attribute__((noipa)) S<T>
65 bar (void)
67   S<T> s;
68   #pragma omp parallel
69   #pragma omp for reduction (inscan, plus:s)
70   for (int i = 0; i < 1024; i++)
71     {
72       b[i] = s;
73       #pragma omp scan exclusive(s)
74       s.s += 2 * a[i].s;
75     }
76   return S<T> (s);
79 __attribute__((noipa)) void
80 baz (S<int> *a, S<int> *b)
82   #pragma omp parallel for reduction (inscan, +:r)
83   for (int i = 0; i < 1024; i++)
84     {
85       b[i] = r;
86       #pragma omp scan exclusive(r)
87       r.s += a[i].s;
88     }
91 __attribute__((noipa)) S<int>
92 qux (void)
94   S<int> s;
95   #pragma omp parallel for reduction (inscan, plus:s)
96   for (int i = 0; i < 1024; i++)
97     {
98       b[i] = s;
99       #pragma omp scan exclusive(s)
100       s.s += 2 * a[i].s;
101     }
102   return S<int> (s);
106 main ()
108   S<int> s;
109   for (int i = 0; i < 1024; ++i)
110     {
111       a[i].s = i;
112       b[i].s = -1;
113       asm ("" : "+g" (i));
114     }
115   #pragma omp parallel
116   foo (a, b);
117   if (r.s != 1024 * 1023 / 2)
118     abort ();
119   for (int i = 0; i < 1024; ++i)
120     {
121       if (b[i].s != s.s)
122         abort ();
123       else
124         b[i].s = 25;
125       s.s += i;
126     }
127   if (bar<int> ().s != 1024 * 1023)
128     abort ();
129   s.s = 0;
130   for (int i = 0; i < 1024; ++i)
131     {
132       if (b[i].s != s.s)
133         abort ();
134       s.s += 2 * i;
135     }
136   r.s = 0;
137   baz (a, b);
138   if (r.s != 1024 * 1023 / 2)
139     abort ();
140   s.s = 0;
141   for (int i = 0; i < 1024; ++i)
142     {
143       if (b[i].s != s.s)
144         abort ();
145       else
146         b[i].s = 25;
147       s.s += i;
148     }
149   if (qux ().s != 1024 * 1023)
150     abort ();
151   s.s = 0;
152   for (int i = 0; i < 1024; ++i)
153     {
154       if (b[i].s != s.s)
155         abort ();
156       s.s += 2 * i;
157     }