2018-01-22 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / udr-1.C
blobc3ddd859ea47fd717febaf803350f8e1e79db8d3
1 // { dg-do run }
3 extern "C" void abort ();
5 struct S
7   int s;
8   void foo (S &x) { s += x.s; }
9   void foo (S &x, bool y) { s += x.s; if (y) abort (); }
10   S (const S &x) { s = x.s + 1; }
11   S (const S &x, bool y) { s = x.s + 2; if (y) abort (); }
12   S () { s = 6; }
13   ~S ();
16 S::~S ()
18   if (s < 6) abort ();
19   s = -1;
20   /* Ensure the above store is not DSEd.  */
21   asm volatile ("" : : "r" (&s) : "memory");
24 void
25 bar (S &x)
27   if (x.s != 6) abort ();
28   x.s = 15;
31 #pragma omp declare reduction (foo: S: omp_out.foo (omp_in)) \
32         initializer (omp_priv (omp_orig, false))
33 #pragma omp declare reduction (foo: char, int, short: omp_out += omp_in - 4) \
34         initializer (omp_priv (4))
35 #pragma omp declare reduction (+: S: omp_out.foo (omp_in, false)) \
36         initializer (omp_priv (omp_orig))
38 namespace N
40   #pragma omp declare reduction (foo: S: omp_out.foo (omp_in)) \
41         initializer (::bar (omp_priv))
42   namespace M {}
45 int
46 main ()
48   S a, b, c, s, t, u;
49   if (a.s != 6 || b.s != 6 || c.s != 6
50       || s.s != 6 || t.s != 6 || u.s != 6) abort ();
51   s.s = 9; t.s = 10; u.s = 11;
52   int d = 0, e = 0, f = 0, g = 0, h = 30, v = 2, q = 0;
53   #pragma omp declare reduction (foo: S: omp_out.foo (omp_in, true)) \
54         initializer (omp_priv = omp_orig)
55   {
56     #pragma omp declare reduction (foo: S: omp_out.foo (omp_in, false)) \
57         initializer (omp_priv = omp_orig)
58     #pragma omp parallel num_threads (4) reduction (N::operator +: q) \
59         reduction (operator +: a, d) reduction (::operator +: b, e) \
60         reduction (+: c, f) reduction (::N::M::operator +: g) \
61         reduction (::N::min: h) reduction (foo: s) reduction (N::foo: t) \
62         reduction (::foo: u) reduction (::foo: v)
63     {
64       if (a.s != 7 || b.s != 7 || c.s != 7
65           || s.s != 10 || t.s != 15 || u.s != 13
66           || v != 4 || d || e || f || g || h != __INT_MAX__) abort ();
67       asm volatile ("" : "+m" (a.s), "+m" (b.s));
68       asm volatile ("" : "+m" (c.s), "+r" (d));
69       asm volatile ("" : "+r" (e), "+r" (f));
70       asm volatile ("" : "+r" (g), "+r" (h));
71       asm volatile ("" : "+m" (s.s), "+m" (t.s));
72       asm volatile ("" : "+m" (u.s), "+r" (v));
73       a.s++; b.s++; c.s++; d++; e++; f++; g++; h = t.s;
74       s.s++; t.s++; u.s++; v++; q++;
75     }
76   }
77   if (a.s != 6 + q * 8 || b.s != 6 + q * 8 || c.s != 6 + q * 8
78       || d != q || e != q || f != q || g != q || h != 15
79       || s.s != 9 + q * 11 || t.s != 10 + q * 16 || u.s != 11 + q * 14
80       || v != 2 + q)
81     abort ();