Hi! When gimplifying lastprivate or linear clause with non-NULL OMP_CLAUSE_*_STMT, we wrap it into a BIND_EXPR and push temporaries there, but I haven't done that when we are adding that only during gimplification for the loop's IV. For worksharing loop or distribute or simd it isn't that big deal, because either there is no outlining of the corresponding code, or it is through outer parallel, teams etc. so the temporaries end up there. But, in the case of taskloop, there is always outlining and so we need to make sure the temporaries are in the right spot.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk (so far). 2019-01-28 Jakub Jelinek <ja...@redhat.com> PR middle-end/89002 * gimplify.c (gimplify_omp_for): When adding OMP_CLAUSE_*_GIMPLE_SEQ for lastprivate/linear IV, push gimplify context around gimplify_assign and, if it needed any temporaries, pop it into a gimple bind around the sequence. * testsuite/libgomp.c/pr89002.c: New test. --- gcc/gimplify.c.jj 2019-01-22 23:27:56.000000000 +0100 +++ gcc/gimplify.c 2019-01-28 17:32:58.149683211 +0100 @@ -11167,8 +11167,17 @@ gimplify_omp_for (tree *expr_p, gimple_s seq = &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (c); else seq = &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c); + push_gimplify_context (); gimplify_assign (decl, t, seq); - } + gimple *bind = NULL; + if (gimplify_ctxp->temps) + { + bind = gimple_build_bind (NULL_TREE, *seq, NULL_TREE); + *seq = NULL; + gimplify_seq_add_stmt (seq, bind); + } + pop_gimplify_context (bind); + } } } --- libgomp/testsuite/libgomp.c/pr89002.c.jj 2019-01-28 17:49:47.791086171 +0100 +++ libgomp/testsuite/libgomp.c/pr89002.c 2019-01-28 17:49:17.836600273 +0100 @@ -0,0 +1,43 @@ +/* PR middle-end/89002 */ + +extern void abort (void); + +int +foo (int x) +{ + int a; + int *p = &a; + +#pragma omp taskloop lastprivate (a) + for (a = 0; a < x; ++a) + ; + return *p; +} + +int +bar (int x) +{ + int a; + int *p = &a; + +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate (a) + for (a = 0; a < x; ++a) + ; + return *p; +} + +int +main () +{ +#pragma omp parallel +#pragma omp single + { + if (foo (4) != 4) + abort (); + } + if (bar (6) != 6) + abort (); + return 0; +} Jakub