Daily bump.
[official-gcc.git] / libgomp / testsuite / libgomp.c / udr-1.c
blobea9da72526e5151941f199f5d0c51eb7036ba8f5
1 /* { dg-do run } */
3 extern
4 #ifdef __cplusplus
5 "C"
6 #endif
7 void abort ();
9 struct S { int s; struct S *t; };
11 void
12 foo (struct S *out, struct S *in)
14 out->s += in->s;
17 void
18 bar (struct S *x)
20 if (x->s != 6) abort ();
21 x->s = 15;
24 void
25 baz (struct S *x, struct S *y)
27 x->s = 6;
28 x->t = x;
29 (void) y;
32 #pragma omp declare reduction (foo: struct S: foo (&omp_out, &omp_in)) \
33 initializer (omp_priv = { 8, &omp_priv })
34 #pragma omp declare reduction (foo: char, int, short: omp_out += omp_in - 4) \
35 initializer (omp_priv = 4)
36 #pragma omp declare reduction (+: struct S: foo (&omp_out, &omp_in)) \
37 initializer (baz (&omp_priv, &omp_orig))
39 void
40 test (struct S s, struct S t)
42 int q = 0;
43 #pragma omp parallel num_threads (4) reduction (+: s, q) reduction (foo: t)
45 if (s.s != 6 || s.t != &s || t.s != 8 || t.t != &t)
46 abort ();
47 s.s = 2;
48 t.s = 3;
49 q = 1;
51 if (s.s != 12 + 2 * q || t.s != 14 + 3 * q)
52 abort ();
55 int
56 main ()
58 struct S s, t;
59 s.s = 9; t.s = 10;
60 int h = 30, v = 2, q = 0;
61 #pragma omp declare reduction (foo: struct S: omp_out.s *= omp_in.s) \
62 initializer (omp_priv = omp_orig)
64 #pragma omp declare reduction (foo: struct S: omp_out.s += omp_in.s) \
65 initializer (omp_priv = omp_orig)
66 #pragma omp parallel num_threads (4) reduction (+: t, q) \
67 reduction (min: h) reduction (foo: s, v)
69 if (s.s != 9 || t.s != 6 || v != 4 || h != __INT_MAX__) abort ();
70 asm volatile ("" : "+m" (s.s), "+m" (t.s));
71 asm volatile ("" : "+r" (h), "+r" (v));
72 h = t.s; s.s++; t.s++; v++; q++;
75 if (h != 6 || s.s != 9 + q * 10 || t.s != 10 + q * 7 || v != 2 + q)
76 abort ();
77 s.s = 12;
78 t.s = 14;
79 test (s, t);
80 return 0;