From patchwork Thu Apr 25 18:16:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 89013 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2D133858414 for ; Thu, 25 Apr 2024 18:17:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0C7F63858D38 for ; Thu, 25 Apr 2024 18:16:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C7F63858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0C7F63858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714069020; cv=none; b=BrFWudG/L6ma7NmjPA6D6RWvkFUQBwuGxghVfBUEU3Ri83XOzwReYJ1KK5ppvgyFpdFOue8sxW4PgodpoxEb35d1sULEnT2tlNrhPH4g9kLXczxZoBCiTTn6jJvvLR1TBaMGMB41+eikacKtw1r3+QTzrRxaMKpBdZi6VypEGjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714069020; c=relaxed/simple; bh=GQodcQsn6qz02RfjFH/GkICa41sRNDWRdXqV7wABDDQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=xKgbQMslQNe2o8dyfcsWAJdb+c+i86KoL/vEt+hk/dv8HZ5QlOR8mINLucC6jwF9J9Py6O3I7SRC+IqWyToJM1sjYRNiJunGsjomZwmZGW7jkzLWxSnURHFOvAAHqNl8stHZzDnKNh1Ss3mTxmAMaufFo+qkC289jAFBi3zFw6E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714069018; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=FJyZMrV3lQXW686Wn4OPvAqOEexaCLaPYhKtxld4aSM=; b=NDu0pHK8lO6WC2jqSzTknFRzU6cOjD4oLc4VgNMJuNwT9VyDgi+yBjbAPCMf+rWKVN/Skd cm4xrpTLFBDnBLQeHFQgQQ7c4q4wMz+HKg6RuFQ2AaAL+oeOklaCJpuL41f2pC5DZr9CE+ ISOcM74lds6qvdfZ5Itt5rMY8C1ncT4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-329-YuYJIn0hPIaMRYEs1zF8dA-1; Thu, 25 Apr 2024 14:16:55 -0400 X-MC-Unique: YuYJIn0hPIaMRYEs1zF8dA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D5EC4800935; Thu, 25 Apr 2024 18:16:54 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6AAC11C0654E; Thu, 25 Apr 2024 18:16:54 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 43PIGqUk038045 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 25 Apr 2024 20:16:53 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 43PIGqYR038044; Thu, 25 Apr 2024 20:16:52 +0200 Date: Thu, 25 Apr 2024 20:16:51 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Tobias Burnus Subject: [committed] openmp: Copy DECL_LANG_SPECIFIC and DECL_LANG_FLAG_? to tree-nested decl copy [PR114825] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi! 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. Bootstrapped/regtested on x86_64-linux and i686-linux, committed so far to trunk. 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. Jakub --- gcc/tree-nested.cc.jj 2024-01-29 09:41:19.804391621 +0100 +++ gcc/tree-nested.cc 2024-04-24 18:02:55.103841888 +0200 @@ -1047,6 +1047,37 @@ get_frame_field (struct nesting_info *in 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_ 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_inf 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; --- gcc/testsuite/gfortran.dg/gomp/pr114825.f90.jj 2024-04-24 18:18:28.957461686 +0200 +++ gcc/testsuite/gfortran.dg/gomp/pr114825.f90 2024-04-24 18:18:08.757729477 +0200 @@ -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