Hi! This patch fixes a problem with UDRs, where if we copy reduction clauses to multiple constructs (on combined constructs), we weren't copying OMP_CLAUSE_REDUCTION_PLACEHOLDER (which holds IDENTIFIER_NODE, TREE_VEC or some similar magic used by {,c_}finish_omp_clauses later on to properly finalize the clause.
Will commit tomorrow. 2013-09-25 Jakub Jelinek <ja...@redhat.com> PR libgomp/58482 * c-omp.c (c_omp_split_clauses) <case OMP_CLAUSE_REDUCTION>: Copy also OMP_CLAUSE_REDUCTION_PLACEHOLDER. * testsuite/libgomp.c/simd-6.c: New test. * testsuite/libgomp.c++/simd-8.C: New test. --- gcc/c-family/c-omp.c.jj 2013-09-25 09:51:45.000000000 +0200 +++ gcc/c-family/c-omp.c 2013-09-25 19:08:05.776289461 +0200 @@ -832,6 +832,8 @@ c_omp_split_clauses (location_t loc, enu OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); OMP_CLAUSE_REDUCTION_CODE (c) = OMP_CLAUSE_REDUCTION_CODE (clauses); + OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) + = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses); OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_SIMD]; cclauses[C_OMP_CLAUSE_SPLIT_SIMD] = c; } @@ -844,6 +846,8 @@ c_omp_split_clauses (location_t loc, enu OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); OMP_CLAUSE_REDUCTION_CODE (c) = OMP_CLAUSE_REDUCTION_CODE (clauses); + OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) + = OMP_CLAUSE_REDUCTION_PLACEHOLDER (clauses); OMP_CLAUSE_CHAIN (c) = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] = c; s = C_OMP_CLAUSE_SPLIT_TEAMS; --- libgomp/testsuite/libgomp.c/simd-6.c.jj 2013-09-25 19:15:09.572135004 +0200 +++ libgomp/testsuite/libgomp.c/simd-6.c 2013-09-25 19:15:05.748158078 +0200 @@ -0,0 +1,44 @@ +/* PR libgomp/58482 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ +/* { dg-additional-options "-msse2" { target sse2_runtime } } */ +/* { dg-additional-options "-mavx" { target avx_runtime } } */ + +extern void abort (); +int a[1024] __attribute__((aligned (32))) = { 1 }; +struct S { int s; }; +#pragma omp declare reduction (+:struct S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:struct S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:int:omp_out += omp_in) + +__attribute__((noinline, noclone)) int +foo (void) +{ + int i, u = 0; + struct S s, t; + s.s = 0; t.s = 0; + #pragma omp parallel for simd aligned(a : 32) reduction(+:s) \ + reduction(foo:t, u) + for (i = 0; i < 1024; i++) + { + int x = a[i]; + s.s += x; + t.s += x; + u += x; + } + if (t.s != s.s || u != s.s) + abort (); + return s.s; +} + +int +main () +{ + int i; + for (i = 0; i < 1024; i++) + a[i] = (i & 31) + (i / 128); + int s = foo (); + if (s != 19456) + abort (); + return 0; +} --- libgomp/testsuite/libgomp.c++/simd-8.C.jj 2013-09-25 19:15:42.069968629 +0200 +++ libgomp/testsuite/libgomp.c++/simd-8.C 2013-09-25 19:16:03.615860022 +0200 @@ -0,0 +1,47 @@ +// PR libgomp/58482 +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +extern "C" void abort (); +int a[1024] __attribute__((aligned (32))) = { 1 }; +struct S +{ + int s; + S () : s (0) {} + ~S () {} +}; +#pragma omp declare reduction (+:S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:int:omp_out += omp_in) + +__attribute__((noinline, noclone)) int +foo () +{ + int i, u = 0; + S s, t; + #pragma omp parallel for simd aligned(a : 32) reduction(+:s) \ + reduction(foo:t, u) + for (i = 0; i < 1024; i++) + { + int x = a[i]; + s.s += x; + t.s += x; + u += x; + } + if (t.s != s.s || u != s.s) + abort (); + return s.s; +} + +int +main () +{ + int i; + for (i = 0; i < 1024; i++) + a[i] = (i & 31) + (i / 128); + int s = foo (); + if (s != 19456) + abort (); +} Jakub