https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102431
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-10 branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:18e0162ecb5de800f1609bfda657183bf95c7901 commit r10-10657-g18e0162ecb5de800f1609bfda657183bf95c7901 Author: Jakub Jelinek <ja...@redhat.com> Date: Tue Nov 23 10:30:02 2021 +0100 openmp: Fix up handling of reduction clauses on the loop construct [PR102431] We were using unshare_expr and walk_tree_without_duplicate replacement of the placeholder vars. The OMP_CLAUSE_REDUCTION_{INIT,MERGE} can contain other trees that need to be duplicated though, e.g. BLOCKs referenced in BIND_EXPR(s), or local VAR_DECLs. This patch uses the inliner code to copy all of that. There is a slight complication that those local VAR_DECLs or placeholders don't have DECL_CONTEXT set, they will get that only when they are gimplified later on, so this patch sets DECL_CONTEXT for those temporarily and resets it afterwards. 2021-11-23 Jakub Jelinek <ja...@redhat.com> PR middle-end/102431 * gimplify.c (replace_reduction_placeholders): Remove. (note_no_context_vars): New function. (gimplify_omp_loop): For OMP_PARALLEL's BIND_EXPR create a new BLOCK. Use copy_tree_body_r with walk_tree instead of unshare_expr and replace_reduction_placeholders for duplication of OMP_CLAUSE_REDUCTION_{INIT,MERGE} expressions. Ensure all mentioned automatic vars have DECL_CONTEXT set to non-NULL before doing so and reset it afterwards for those vars and their corresponding vars. * c-c++-common/gomp/pr102431.c: New test. * g++.dg/gomp/pr102431.C: New test. (cherry picked from commit 5e9b973bd60185f221222022f56db7df3d92250e)