1 /* { dg-do run } */
2 
3 extern
4 #ifdef __cplusplus
5 "C"
6 #endif
7 void abort ();
8 
9 struct S { int s; struct S *t; };
10 
11 void
foo(struct S * out,struct S * in)12 foo (struct S *out, struct S *in)
13 {
14   out->s += in->s;
15 }
16 
17 void
bar(struct S * x)18 bar (struct S *x)
19 {
20   if (x->s != 6) abort ();
21   x->s = 15;
22 }
23 
24 void
baz(struct S * x,struct S * y)25 baz (struct S *x, struct S *y)
26 {
27   x->s = 6;
28   x->t = x;
29   (void) y;
30 }
31 
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))
38 
39 void
test(struct S s,struct S t)40 test (struct S s, struct S t)
41 {
42   int q = 0;
43   #pragma omp parallel num_threads (4) reduction (+: s, q) reduction (foo: t)
44   {
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;
50   }
51   if (s.s != 12 + 2 * q || t.s != 14 + 3 * q)
52     abort ();
53 }
54 
55 int
main()56 main ()
57 {
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)
63   {
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)
68     {
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++;
73     }
74   }
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;
81 }
82