Hi! I've committed following patch to fix ICE on taskloop construct where the IV is addressable. This doesn't ICE on for, simd or distribute because it is ORT_WORKSHARE or ORT_SIMD and thus omp_add_variable during create_tmp_var is called in outer context. While it doesn't hurt in that case, as we want to make the var just private or linear in the current context (the latter without copyin and copyout), it is better not to call omp_add_variable on it during create_tmp_var at all (we call it a few lines later with the right flags). Using create_tmp_var_raw would work too, but we'd have to manually do all the rest of gimple_add_tmp_var except for omp_add_variable.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk and 6.2. 2016-06-01 Jakub Jelinek <ja...@redhat.com> PR middle-end/71371 * gimplify.c (gimplify_omp_for): Temporarily clear gimplify_omp_ctxp around creation of the temporary. * c-c++-common/gomp/pr71371.c: New test. --- gcc/gimplify.c.jj 2016-05-26 10:38:02.000000000 +0200 +++ gcc/gimplify.c 2016-06-01 13:27:23.647789536 +0200 @@ -9007,7 +9007,12 @@ gimplify_omp_for (tree *expr_p, gimple_s || (ort == ORT_SIMD && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) > 1)) { + struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; + /* Make sure omp_add_variable is not called on it prematurely. + We call it ourselves a few lines later. */ + gimplify_omp_ctxp = NULL; var = create_tmp_var (TREE_TYPE (decl), get_name (decl)); + gimplify_omp_ctxp = ctx; TREE_OPERAND (t, 0) = var; gimplify_seq_add_stmt (&for_body, gimple_build_assign (decl, var)); --- gcc/testsuite/c-c++-common/gomp/pr71371.c.jj 2016-06-01 13:35:18.639633280 +0200 +++ gcc/testsuite/c-c++-common/gomp/pr71371.c 2016-06-01 13:35:37.366390567 +0200 @@ -0,0 +1,25 @@ +/* PR middle-end/71371 */ +/* { dg-do compile } */ + +void baz (int *); + +void +foo (void) +{ + int i; + #pragma omp taskloop + for (i = 0; i < 100; i++) + baz (&i); +} + +void +bar (void) +{ + int i; + #pragma omp parallel + { + #pragma omp for + for (i = 0; i < 100; i++) + baz (&i); + } +} Jakub