From patchwork Tue Feb 28 16:18:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1749513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PR2c95N11z1yX2 for ; Wed, 1 Mar 2023 03:18:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95DDC3858421 for ; Tue, 28 Feb 2023 16:18:47 +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 068EF3858D33; Tue, 28 Feb 2023 16:18:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 068EF3858D33 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.98,222,1673942400"; d="diff'?scan'208";a="98330928" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 28 Feb 2023 08:18:32 -0800 IronPort-SDR: iGOY6kPwKibzJbxFIKo1Uu774grHa2GeEKY0gZRTDtA75DDf0d3bT9XFi/QMoiJcomYdO3gsvk MaIe1rwG2IBigE/GIzh9EX6sPW2ZrMFjFjEUemHy57MXeB7+YX0XwBuKumru6MiU4Cmt5FugoA /TPkO/fYAqofKOSXcPX3bMmGNmUt/aztD0aXO92CuDvIwSjBVup8BHan54iCm/Q/xITmH+AFhA MnUJlmxrmnvISHYz/oBSINyfbYGJe24sSCPMSS3JhtkgWuZPypPhixM+TlPVRzucOg6dr3tEw0 pA4= Message-ID: <452ab67b-34f5-d816-436d-33f8f9ac44d4@codesourcery.com> Date: Tue, 28 Feb 2023 17:18:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Content-Language: en-US From: Tobias Burnus To: gcc-patches , Jakub Jelinek CC: fortran Subject: [Patch] OpenMP/Fortran: Fix handling of optional is_device_ptr + bind(C) [PR108546] X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-15.mgc.mentorg.com (139.181.222.15) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, 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.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" (That's a[11/12/13 Regression] P2 regression) The problem is that an is-present check on the receiver side (inside the target region) does not make much sense; the != NULL check needs to be done before the GOMP_target_ext but it *is* already there. (Having the check inside the target region failed with an ICE.) Additionally, I encountered an issue for 'void *' alias 'type(c_ptr)'. That's on the Fortran-language side represented as derived type with private component(s), but then mapped to 'void*'. In any case, it lead to 'map(to: p) map(pset: p)' and the former will be at some point get TYPE_UNIT_SIZE(TREE_TYPE(*p)) but '*p' is void, giving an ICE in omp-lower ... OK for mainline – and later backport to 12 + 11? 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 OpenMP/Fortran: Fix handling of optional is_device_ptr + bind(C) [PR108546] For is_device_ptr, optional checks should only be done before calling libgomp, afterwards they are NULL either because of absent or, by chance, because it is unallocated or unassociated (for pointers/allocatables). Additionally, it fixes an issue with explicit mapping for 'type(c_ptr)'. PR middle-end/108546 gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_trans_omp_clauses): Fix mapping of type(C_ptr) variables. gcc/ChangeLog: * omp-low.cc (lower_omp_target): Remove optional handling on the receiver side, i.e. inside target (data), for use_device_ptr. libgomp/ChangeLog: * testsuite/libgomp.fortran/is_device_ptr-3.f90: New test. * testsuite/libgomp.fortran/use_device_ptr-optional-4.f90: New test. gcc/fortran/trans-openmp.cc | 4 +- gcc/omp-low.cc | 3 +- .../testsuite/libgomp.fortran/is_device_ptr-3.f90 | 46 +++++++++++++++++++ .../libgomp.fortran/use_device_ptr-optional-4.f90 | 53 ++++++++++++++++++++++ 4 files changed, 104 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 2d16f3be8ea..84c0184f48e 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -3152,7 +3152,9 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, || GFC_DECL_CRAY_POINTEE (decl) || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (decl))) - || n->sym->ts.type == BT_DERIVED)) + || (n->sym->ts.type == BT_DERIVED + && (n->sym->ts.u.derived->ts.f90_type + != BT_VOID)))) { tree orig_decl = decl; diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index fef41a013ec..9757592c635 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -13942,7 +13942,8 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) } tree present; present = ((do_optional_check - && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_HAS_DEVICE_ADDR) + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_HAS_DEVICE_ADDR + && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IS_DEVICE_PTR) ? omp_check_optional_argument (OMP_CLAUSE_DECL (c), true) : NULL_TREE); if (present) diff --git a/libgomp/testsuite/libgomp.fortran/is_device_ptr-3.f90 b/libgomp/testsuite/libgomp.fortran/is_device_ptr-3.f90 new file mode 100644 index 00000000000..ab9f00ebecb --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/is_device_ptr-3.f90 @@ -0,0 +1,46 @@ +module m + use iso_c_binding + implicit none +contains + subroutine s(x,y,z) + type(c_ptr), optional :: x + integer, pointer, optional :: y + integer, allocatable, optional :: z + logical is_present, is_null + is_present = present(x) + if (is_present) & + is_null = .not. c_associated(x) + + !$omp target is_device_ptr(x) has_device_addr(y) has_device_addr(z) + if (is_present) then + if (is_null) then + if (c_associated(x)) stop 1 + if (associated(y)) stop 2 + if (allocated(z)) stop 3 + else + if (.not. c_associated(x, c_loc(y))) stop 4 + if (y /= 7) stop 5 + if (z /= 9) stop 6 + end if + end if + !$omp end target + end +end + +use m +implicit none +integer, pointer :: p +integer, allocatable :: a +p => null() +call s() +!$omp target data map(p,a) use_device_addr(p,a) + call s(c_null_ptr, p, a) +!$omp end target data +allocate(p,a) +p = 7 +a = 9 +!$omp target data map(p,a) use_device_addr(p,a) + call s(c_loc(p), p, a) +!$omp end target data +deallocate(p,a) +end diff --git a/libgomp/testsuite/libgomp.fortran/use_device_ptr-optional-4.f90 b/libgomp/testsuite/libgomp.fortran/use_device_ptr-optional-4.f90 new file mode 100644 index 00000000000..b2a5c314685 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/use_device_ptr-optional-4.f90 @@ -0,0 +1,53 @@ +! PR middle-end/108546 +! +module m + use iso_c_binding + implicit none + type(c_ptr) :: p2, p3 +contains + subroutine s(x,y,z) + type(c_ptr), optional :: x + integer, pointer, optional :: y + integer, allocatable, optional, target :: z + logical is_present, is_null + is_present = present(x) + if (is_present) & + is_null = .not. c_associated(x) + + !$omp target data use_device_ptr(x) use_device_addr(y) use_device_addr(z) + if (is_present) then + if (is_null) then + if (c_associated(x)) stop 1 + if (associated(y)) stop 2 + if (allocated(z)) stop 3 + else + if (.not. c_associated(x, p2)) stop 4 + if (.not. c_associated(c_loc(y), p2)) stop 5 + if (.not. c_associated(c_loc(z), p3)) stop 6 + end if + end if + !$omp end target data + end +end + +use m +implicit none +type(c_ptr) :: cp +integer, pointer :: p +integer, allocatable, target :: a +call s() +p => null() +call s(c_null_ptr, p, a) +allocate(p,a) +p = 7 +a = 9 +cp = c_loc(p) +!$omp target enter data map(to: cp, p, a) +!$omp target map(from: p2, p3) + p2 = c_loc(p) + p3 = c_loc(a) +!$omp end target +call s(cp, p, a) +!$omp target exit data map(delete: cp, p, a) +deallocate(p,a) +end