From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 3BA313858D20; Thu, 25 Apr 2024 18:15:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BA313858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714068922; bh=gEDLuHkdPMIoFN6edDJolDqrZzzs0wmBNdRAYJB8RlY=; h=From:To:Subject:Date:From; b=ZtL8dpqEdoZhmnU9uNU4GiuUtHySJ6LC0+XppyPV9oP4lM/EfBK51nhbCOT3D94CX Bwa7PV1qozc3LOnm9CHQsvw4IpX/YTtYKc6ehcN/6XimdearSCPgqqeI7l3D0a+bBQ /YfJmIx4s3tr9Qrz5fVKhwF2bb8A8iHhBN5rp6B0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-10130] openmp: Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_? to tree-nested decl copy [PR114825] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 8d80e3c5a641556e32fdf3637f08a0648f5aaab3 X-Git-Newrev: 14d48516e588ad2b35e2007b3970bdcb1b3f145c Message-Id: <20240425181522.3BA313858D20@sourceware.org> Date: Thu, 25 Apr 2024 18:15:22 +0000 (GMT) List-Id: https://gcc.gnu.org/g:14d48516e588ad2b35e2007b3970bdcb1b3f145c commit r14-10130-g14d48516e588ad2b35e2007b3970bdcb1b3f145c Author: Jakub Jelinek Date: Thu Apr 25 20:09:35 2024 +0200 openmp: Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_? to tree-nested decl copy [PR114825] tree-nested.cc creates in 2 spots artificial VAR_DECLs, one of them is used both for debug info and OpenMP/OpenACC lowering purposes, the other solely for OpenMP/OpenACC lowering purposes. When the decls are used in OpenMP/OpenACC lowering, the OMP langhooks (mostly Fortran, C just a little and C++ doesn't have nested functions) then inspect the flags on the vars and based on that decide how to lower the corresponding clauses. Unfortunately we weren't copying DECL_LANG_SPECIFIC and DECL_LANG_FLAG_?, so the langhooks made decisions on the default flags on those instead. As the original decl isn't necessarily a VAR_DECL, could be e.g. PARM_DECL, using copy_node wouldn't work properly, so this patch just copies those flags in addition to other flags it was copying already. And I've removed code duplication by introducing a helper function which does copying common to both uses. 2024-04-25 Jakub Jelinek PR fortran/114825 * tree-nested.cc (get_debug_decl): New function. (get_nonlocal_debug_decl): Use it. (get_local_debug_decl): Likewise. * gfortran.dg/gomp/pr114825.f90: New test. Diff: --- gcc/testsuite/gfortran.dg/gomp/pr114825.f90 | 16 ++++++++ gcc/tree-nested.cc | 61 ++++++++++++++++------------- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/gcc/testsuite/gfortran.dg/gomp/pr114825.f90 b/gcc/testsuite/gfortran.dg/gomp/pr114825.f90 new file mode 100644 index 00000000000..b635476af61 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/pr114825.f90 @@ -0,0 +1,16 @@ +! PR fortran/114825 + +subroutine pr114825(b) + type t + real, allocatable :: m(:) + end type t + type(t), allocatable, target :: b(:) + type(t), pointer :: d + !$omp parallel private(d) + d => b(1) + !$omp end parallel +contains + subroutine sub + d => b(1) + end subroutine sub +end subroutine pr114825 diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc index c8f07f78185..4e5f3be7676 100644 --- a/gcc/tree-nested.cc +++ b/gcc/tree-nested.cc @@ -1047,6 +1047,37 @@ get_frame_field (struct nesting_info *info, tree target_context, static void note_nonlocal_vla_type (struct nesting_info *info, tree type); +/* Helper for get_nonlocal_debug_decl and get_local_debug_decl. */ + +static tree +get_debug_decl (tree decl) +{ + tree new_decl + = build_decl (DECL_SOURCE_LOCATION (decl), + VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl)); + DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl); + DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl); + TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl); + TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl); + TREE_READONLY (new_decl) = TREE_READONLY (decl); + TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl); + DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1; + if ((TREE_CODE (decl) == PARM_DECL + || TREE_CODE (decl) == RESULT_DECL + || VAR_P (decl)) + && DECL_BY_REFERENCE (decl)) + DECL_BY_REFERENCE (new_decl) = 1; + /* Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_* for OpenMP langhook + purposes. */ + DECL_LANG_SPECIFIC (new_decl) = DECL_LANG_SPECIFIC (decl); +#define COPY_DLF(n) DECL_LANG_FLAG_##n (new_decl) = DECL_LANG_FLAG_##n (decl) + COPY_DLF (0); COPY_DLF (1); COPY_DLF (2); COPY_DLF (3); + COPY_DLF (4); COPY_DLF (5); COPY_DLF (6); COPY_DLF (7); + COPY_DLF (8); +#undef COPY_DLF + return new_decl; +} + /* A subroutine of convert_nonlocal_reference_op. Create a local variable in the nested function with DECL_VALUE_EXPR set to reference the true variable in the parent function. This is used both for debug info @@ -1094,21 +1125,8 @@ get_nonlocal_debug_decl (struct nesting_info *info, tree decl) x = build_simple_mem_ref_notrap (x); /* ??? We should be remapping types as well, surely. */ - new_decl = build_decl (DECL_SOURCE_LOCATION (decl), - VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl)); + new_decl = get_debug_decl (decl); DECL_CONTEXT (new_decl) = info->context; - DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl); - DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl); - TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl); - TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl); - TREE_READONLY (new_decl) = TREE_READONLY (decl); - TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl); - DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1; - if ((TREE_CODE (decl) == PARM_DECL - || TREE_CODE (decl) == RESULT_DECL - || VAR_P (decl)) - && DECL_BY_REFERENCE (decl)) - DECL_BY_REFERENCE (new_decl) = 1; SET_DECL_VALUE_EXPR (new_decl, x); DECL_HAS_VALUE_EXPR_P (new_decl) = 1; @@ -1892,21 +1910,8 @@ get_local_debug_decl (struct nesting_info *info, tree decl, tree field) x = info->frame_decl; x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE); - new_decl = build_decl (DECL_SOURCE_LOCATION (decl), - VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl)); + new_decl = get_debug_decl (decl); DECL_CONTEXT (new_decl) = info->context; - DECL_ARTIFICIAL (new_decl) = DECL_ARTIFICIAL (decl); - DECL_IGNORED_P (new_decl) = DECL_IGNORED_P (decl); - TREE_THIS_VOLATILE (new_decl) = TREE_THIS_VOLATILE (decl); - TREE_SIDE_EFFECTS (new_decl) = TREE_SIDE_EFFECTS (decl); - TREE_READONLY (new_decl) = TREE_READONLY (decl); - TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl); - DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1; - if ((TREE_CODE (decl) == PARM_DECL - || TREE_CODE (decl) == RESULT_DECL - || VAR_P (decl)) - && DECL_BY_REFERENCE (decl)) - DECL_BY_REFERENCE (new_decl) = 1; SET_DECL_VALUE_EXPR (new_decl, x); DECL_HAS_VALUE_EXPR_P (new_decl) = 1;