1// PR libgomp/58482
2// { dg-do run }
3// { dg-options "-O2" }
4// { dg-additional-options "-msse2" { target sse2_runtime } }
5// { dg-additional-options "-mavx" { target avx_runtime } }
6
7extern "C" void abort ();
8int a[1024] __attribute__((aligned (32))) = { 1 };
9struct S
10{
11  int s;
12  S () : s (0) {}
13  ~S () {}
14};
15#pragma omp declare reduction (+:S:omp_out.s += omp_in.s)
16#pragma omp declare reduction (foo:S:omp_out.s += omp_in.s)
17#pragma omp declare reduction (foo:int:omp_out += omp_in)
18
19__attribute__((noinline, noclone)) int
20foo ()
21{
22  int i, u = 0;
23  S s, t;
24  #pragma omp parallel for simd aligned(a : 32) reduction(+:s) \
25				reduction(foo:t, u)
26  for (i = 0; i < 1024; i++)
27    {
28      int x = a[i];
29      s.s += x;
30      t.s += x;
31      u += x;
32    }
33  if (t.s != s.s || u != s.s)
34    abort ();
35  return s.s;
36}
37
38int
39main ()
40{
41  int i;
42  for (i = 0; i < 1024; i++)
43    a[i] = (i & 31) + (i / 128);
44  int s = foo ();
45  if (s != 19456)
46    abort ();
47}
48