From: Jakub Jelinek Date: Tue, 30 May 2017 07:44:51 +0000 (+0200) Subject: backport: re PR middle-end/69183 (ICE when using OpenMP PRIVATE keyword in OMP DO... X-Git-Tag: releases/gcc-5.5.0~283 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2c405ac37fdfb7a7c0709c94082173743cc06eb;p=thirdparty%2Fgcc.git backport: re PR middle-end/69183 (ICE when using OpenMP PRIVATE keyword in OMP DO loop not explicitly encapsulated in OMP PARALLEL region) Backported from mainline 2016-11-23 Jakub Jelinek PR middle-end/69183 * omp-low.c (build_outer_var_ref): Change lastprivate argument to code, pass it recursively, adjust uses. For OMP_CLAUSE_PRIVATE on worksharing constructs, treat it like clauses on simd construct. Formatting fix. (lower_rec_input_clauses): For OMP_CLAUSE_PRIVATE_OUTER_REF pass OMP_CLAUSE_PRIVATE as last argument to build_outer_var_ref. (lower_lastprivate_clauses): Pass OMP_CLAUSE_LASTPRIVATE instead of true as last argument to build_outer_var_ref. * gfortran.dg/gomp/pr69183.f90: New test. From-SVN: r248628 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 75427f88bf88..256514d686f8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,18 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2016-11-23 Jakub Jelinek + + PR middle-end/69183 + * omp-low.c (build_outer_var_ref): Change lastprivate argument + to code, pass it recursively, adjust uses. For OMP_CLAUSE_PRIVATE + on worksharing constructs, treat it like clauses on simd construct. + Formatting fix. + (lower_rec_input_clauses): For OMP_CLAUSE_PRIVATE_OUTER_REF pass + OMP_CLAUSE_PRIVATE as last argument to build_outer_var_ref. + (lower_lastprivate_clauses): Pass OMP_CLAUSE_LASTPRIVATE instead + of true as last argument to build_outer_var_ref. + 2016-11-22 Jakub Jelinek PR middle-end/78416 diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 308e13506073..945b9c733d6a 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -1166,7 +1166,8 @@ build_receiver_ref (tree var, bool by_ref, omp_context *ctx) this is some variable. */ static tree -build_outer_var_ref (tree var, omp_context *ctx) +build_outer_var_ref (tree var, omp_context *ctx, + enum omp_clause_code code = OMP_CLAUSE_ERROR) { tree x; @@ -1175,7 +1176,7 @@ build_outer_var_ref (tree var, omp_context *ctx) else if (is_variable_sized (var)) { x = TREE_OPERAND (DECL_VALUE_EXPR (var), 0); - x = build_outer_var_ref (x, ctx); + x = build_outer_var_ref (x, ctx, code); x = build_simple_mem_ref (x); } else if (is_taskreg_ctx (ctx)) @@ -1183,11 +1184,17 @@ build_outer_var_ref (tree var, omp_context *ctx) bool by_ref = use_pointer_for_field (var, NULL); x = build_receiver_ref (var, by_ref, ctx); } - else if (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR - && gimple_omp_for_kind (ctx->stmt) & GF_OMP_FOR_SIMD) - { - /* #pragma omp simd isn't a worksharing construct, and can reference even - private vars in its linear etc. clauses. */ + else if ((gimple_code (ctx->stmt) == GIMPLE_OMP_FOR + && gimple_omp_for_kind (ctx->stmt) & GF_OMP_FOR_SIMD) + || (code == OMP_CLAUSE_PRIVATE + && (gimple_code (ctx->stmt) == GIMPLE_OMP_FOR + || gimple_code (ctx->stmt) == GIMPLE_OMP_SECTIONS + || gimple_code (ctx->stmt) == GIMPLE_OMP_SINGLE))) + { + /* #pragma omp simd isn't a worksharing construct, and can reference + even private vars in its linear etc. clauses. + Similarly for OMP_CLAUSE_PRIVATE with outer ref, that can refer + to private vars in all worksharing constructs. */ x = NULL_TREE; if (ctx->outer && is_taskreg_ctx (ctx)) x = lookup_decl (var, ctx->outer); @@ -3886,7 +3893,7 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, if (is_task_ctx (ctx)) x = build_receiver_ref (var, false, ctx); else - x = build_outer_var_ref (var, ctx); + x = build_outer_var_ref (var, ctx, OMP_CLAUSE_PRIVATE); } else x = NULL; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 968c228b150a..ee5334cfe5ee 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,9 @@ Backported from mainline 2016-11-23 Jakub Jelinek + PR middle-end/69183 + * gfortran.dg/gomp/pr69183.f90: New test. + PR c++/77739 * g++.dg/cpp1y/pr77739.C: New test. diff --git a/gcc/testsuite/gfortran.dg/gomp/pr69183.f90 b/gcc/testsuite/gfortran.dg/gomp/pr69183.f90 new file mode 100644 index 000000000000..5dc985a8eb48 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/pr69183.f90 @@ -0,0 +1,11 @@ +! PR middle-end/69183 +! { dg-do compile } + +program pr69183 + integer, allocatable :: z + integer :: i + !$omp do private(z) + do i = 1, 2 + z = i + end do +end