From 835cde6462b3daf2cc24d56ee67d56d2c9c6a4d7 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 28 Sep 2021 11:58:47 +0200 Subject: [PATCH] openmp: Don't call omp_finish_clause on implicitly added private clauses on simd [PR102492] The gimplifier adds implicit private clauses on SIMD constructs for local variables in the SIMD body if they are addressable to make sure they use the magic arrays with "omp simd array" attribute (such that each SIMD lane has its own copy), but we actually don't need to default privatize etc. those, the construction for them is done in the SIMD body and so is destruction. omp_finish_clause for C++ now requires default constructor (and dtor) for private, so that OpenMP 5.1 default(private) works, but that will never be needed on SIMD. So, this patch just doesn't call omp_finish_clause for private on simd. The C and Fortran langhooks don't do anything for private. 2021-09-28 Jakub Jelinek PR middle-end/102492 * gimplify.c (gimplify_adjust_omp_clauses_1): Don't call the omp_finish_clause langhook on implicitly added OMP_CLAUSE_PRIVATE clauses on SIMD constructs. * g++.dg/gomp/simd-3.C: New test. (cherry picked from commit 4f07769057c45ec9e751ab1c23e0fe4750102840) --- gcc/ChangeLog.omp | 11 +++++++++++ gcc/gimplify.c | 8 ++++++-- gcc/testsuite/ChangeLog.omp | 8 ++++++++ gcc/testsuite/g++.dg/gomp/simd-3.C | 16 ++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/gomp/simd-3.C diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 467bf8139ef1..e519764cd73d 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,14 @@ +2021-09-28 Tobias Burnus + + Backported from master: + 2021-09-28 Jakub Jelinek + + PR middle-end/102492 + * gimplify.c (gimplify_adjust_omp_clauses_1): Don't call the + omp_finish_clause langhook on implicitly added OMP_CLAUSE_PRIVATE + clauses on SIMD constructs. + * g++.dg/gomp/simd-3.C: New test. + 2021-09-24 Marcel Vollweiler This patch removes the expectation that 'requires reverse_offload' is diff --git a/gcc/gimplify.c b/gcc/gimplify.c index c25387ab657f..8a324f6081b8 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -11626,8 +11626,12 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data) gimplify_omp_ctxp = ctx->outer_context; gomp_map_kind kind = (code == OMP_CLAUSE_MAP) ? OMP_CLAUSE_MAP_KIND (clause) : (gomp_map_kind) GOMP_MAP_LAST; - lang_hooks.decls.omp_finish_clause (clause, pre_p, - (ctx->region_type & ORT_ACC) != 0); + /* Don't call omp_finish_clause on implicitly added OMP_CLAUSE_PRIVATE + in simd. Those are only added for the local vars inside of simd body + and they don't need to be e.g. default constructible. */ + if (code != OMP_CLAUSE_PRIVATE || ctx->region_type != ORT_SIMD) + lang_hooks.decls.omp_finish_clause (clause, pre_p, + (ctx->region_type & ORT_ACC) != 0); /* Allow OpenACC to have implicit assumed-size arrays via FORCE_PRESENT, which should work as long as the array has previously been mapped explicitly on the target (e.g. by "enter data"). Raise an error for diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index c8518c6261ec..fa93577b0ed3 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,11 @@ +2021-09-28 Tobias Burnus + + Backported from master: + 2021-09-28 Jakub Jelinek + + PR middle-end/102492 + * g++.dg/gomp/simd-3.C: New test. + 2021-09-27 Tobias Burnus Backported from master: diff --git a/gcc/testsuite/g++.dg/gomp/simd-3.C b/gcc/testsuite/g++.dg/gomp/simd-3.C new file mode 100644 index 000000000000..db66c0801758 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/simd-3.C @@ -0,0 +1,16 @@ +// PR middle-end/102492 +// { dg-do compile } + +struct S { S (int); }; +void bar (S &); + +void +foo () +{ + #pragma omp simd + for (int i = 0; i < 64; i++) + { + S s = 26; + bar (s); + } +} -- 2.47.2