From patchwork Fri Mar 18 16:27:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1607162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KKqLd03hqz9s0B for ; Sat, 19 Mar 2022 03:32:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DE7A639484BC for ; Fri, 18 Mar 2022 16:32:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 7805D3899434; Fri, 18 Mar 2022 16:27:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7805D3899434 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.90,192,1643702400"; d="diff'?scan'208";a="73169588" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 18 Mar 2022 08:27:18 -0800 IronPort-SDR: mYHhkq4OmokRrauMvq+DT28vrVW0JfyntvtycLq6v6iVABqqgK1pK0KdT6TeMQjI9EN6Xqrq5l sqCjQU9rzMRyXgFodAGE7sTWe5yXhCl32YhE2Ein1xTdvX0D0s4LB527df2WOCzy9c4LVFx7Bc SKq1LnzsQuVJVavQ+7792TiQzQ5t8zNF40PW9PiFtV+pTgQEHJ+Wgyu9bj/I37fFLAK+KW1XcD Mq9m5JZ90Da+ZQpiMyUR7bGWYEbxiKzb7McKRwZ7X+ajVlz6SNRJ3NShzUScHtJIW46Fv0rxJ3 kPs= Message-ID: <6e5a585d-9876-cc66-413d-3cad381ddbdf@codesourcery.com> Date: Fri, 18 Mar 2022 17:27:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: gcc-patches , fortran , Jakub Jelinek From: Tobias Burnus Subject: [Patch] Fortran/OpenMP: Improve associate-name diagnostic [PR103039] X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" SELECT TYPE, SELECT RANK and ASSOCIATE have associate-name => selector and create a pointer to the selector. GCC was fixed to handle CLASS properly in class(t) :: var !$omp ... firstprivate(var) As a side effect, firstprivate(assoc_name) now also gets handled that way, effectively trying to firstprivate(selector) which should be shared... While firstprivate(var) does not appear explicitly, it gets added via gfc_omp_predetermined_sharing. I went for the simple solution and handle it only in gfortran's ctor/dtor. An alternative would be to set OMP_CLAUSE_FIRSTPRIVATE_NO_REFERENCE, which is currently only set for C++'s __for_end / __for_range and then later process it in ctor/dtor. I am not sure whether that's really best and what's the best way to propagate it. One way would be to create and use OMP_CLAUSE_DEFAULT_FIRSTPRIVATE_NO_REFERENCE. OK as is (simple version) – or is a fuller version better. If so, suggestion how to do this best? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 Fortran/OpenMP: Fix privatization of associated names gfc_omp_predetermined_sharing cases the associate-name pointer variable to be OMP_CLAUSE_DEFAULT_FIRSTPRIVATE, which is fine. However, the associated selector is shared. Thus, the target of associate-name pointer should not get copied. (It was before but because of gfc_omp_privatize_by_reference returning false, the selector was not only wrongly copied but this was also not done properly.) gcc/fortran/ChangeLog: PR fortran/103039 * trans-openmp.cc (gfc_omp_clause_copy_ctor, gfc_omp_clause_dtor): Only privatize pointer for associate names. libgomp/ChangeLog: PR fortran/103039 * testsuite/libgomp.fortran/associate4.f90: New test. gcc/fortran/trans-openmp.cc | 10 +++ libgomp/testsuite/libgomp.fortran/associate4.f90 | 92 ++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index fad76a4791f..101924f5e76 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -808,6 +808,11 @@ gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src) gcc_assert (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_FIRSTPRIVATE || OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR); + /* Privatize pointer, only; cf. gfc_omp_predetermined_sharing. */ + if (DECL_P (OMP_CLAUSE_DECL (clause)) + && GFC_DECL_ASSOCIATE_VAR_P (OMP_CLAUSE_DECL (clause))) + return build2 (MODIFY_EXPR, TREE_TYPE (dest), dest, src); + if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause)) && DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause)) && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause))) @@ -1321,6 +1326,11 @@ gfc_omp_clause_dtor (tree clause, tree decl) tree type = TREE_TYPE (decl), tem; tree decl_type = TREE_TYPE (OMP_CLAUSE_DECL (clause)); + /* Only pointer was privatized; cf. gfc_omp_clause_copy_ctor. */ + if (DECL_P (OMP_CLAUSE_DECL (clause)) + && GFC_DECL_ASSOCIATE_VAR_P (OMP_CLAUSE_DECL (clause))) + return NULL_TREE; + if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause)) && DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause)) && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause))) diff --git a/libgomp/testsuite/libgomp.fortran/associate4.f90 b/libgomp/testsuite/libgomp.fortran/associate4.f90 new file mode 100644 index 00000000000..f0949b5530d --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/associate4.f90 @@ -0,0 +1,92 @@ +! PR fortran/51722 + +module m +implicit none + +contains + +subroutine seltype + +type :: a + integer :: p = 2 +end type a + +type, extends(a) :: b + integer :: cnt = 0 +end type b + +integer :: k, s +class(a), pointer :: x + +allocate(a :: x) +s = 0 +select type (y => x) +class is (a) +!$omp parallel do default(shared) private(k) reduction(+:s) + do k = 1,10 + s = s + k*y%p + end do +!$omp end parallel do +end select + +if (s /= 110) error stop +deallocate(x) +allocate(b :: x) + +s = 0 +select type (y => x) +class is (b) +!$omp parallel do default(shared) private(k) reduction(+:s) + do k = 1,10 + s = s + k*y%p +!$omp atomic update + y%cnt = y%cnt + 2 + end do +!$omp end parallel do +if (s /= 110) error stop +if (y%p /= 2) error stop +if (y%cnt /= 10*2) error stop +end select + +deallocate(x) + +end subroutine seltype + +subroutine assoc + +type :: b + integer :: r = 3 +end type b + +type :: a + integer :: p = 2 + class(b), pointer :: u => null() +end type a + +integer :: k, s +class(a), pointer :: x + +s = 0 +allocate(a :: x) +allocate(b :: x%u) + +associate(f => x%u) +!$omp parallel do default(shared) private(k) reduction(+:s) + do k = 1,10 + s = s + k*f%r + end do +!$omp end parallel do +end associate + +deallocate(x%u) +deallocate(x) + +if (s /= 165) error stop +end subroutine assoc +end module m + +use m +implicit none (type, external) +call seltype +call assoc +end