From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 3CC9A385842C; Thu, 2 Mar 2023 15:32:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CC9A385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677771179; bh=lQAVg0NXF7n8pCepJS+TNpZWyikLU2YC8z0Z4rQuJgQ=; h=From:To:Subject:Date:From; b=HKYtzUXT4KXZgLuZ000Qk+NJ1qwbva8PnhP2pMODq4+2qDZzlQX0wcxOw8iGxdKm6 Eb6D+55fZCzDR0M3UP/326U6Dk7wuCG8h392R+Y3WSiz06TNgvNWTgnRazcCn/X5tk O+3TybzCVT0TKaVNzM5i6PpVLngWlquIWzt0cWJg= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] OpenMP/Fortran: Fix handling of optional is_device_ptr + bind(C) [PR108546] X-Act-Checkin: gcc X-Git-Author: Tobias Burnus X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: baa7f7adf756899974f132bbacbb29f45aa3cd21 X-Git-Newrev: 15b6140ed5d5f006063835319fdd6486d1abceb9 Message-Id: <20230302153259.3CC9A385842C@sourceware.org> Date: Thu, 2 Mar 2023 15:32:59 +0000 (GMT) List-Id: https://gcc.gnu.org/g:15b6140ed5d5f006063835319fdd6486d1abceb9 commit 15b6140ed5d5f006063835319fdd6486d1abceb9 Author: Tobias Burnus Date: Wed Mar 1 15:18:40 2023 +0100 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. (cherry picked from commit 96ff97ff6574666a5509ae9fa596e7f2b6ad4f88) Diff: --- gcc/ChangeLog.omp | 10 ++++ gcc/fortran/ChangeLog.omp | 9 ++++ gcc/fortran/trans-openmp.cc | 4 +- gcc/omp-low.cc | 3 +- libgomp/ChangeLog.omp | 9 ++++ .../testsuite/libgomp.fortran/is_device_ptr-3.f90 | 46 +++++++++++++++++++ .../libgomp.fortran/use_device_ptr-optional-4.f90 | 53 ++++++++++++++++++++++ 7 files changed, 132 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index c1da700805c..be8dfa8f1b9 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,13 @@ +2023-03-01 Tobias Burnus + + Backported from master: + 2023-03-01 Tobias Burnus + + PR middle-end/108546 + * omp-low.cc (lower_omp_target): Remove optional handling + on the receiver side, i.e. inside target (data), for + use_device_ptr. + 2023-02-23 Andrew Stubbs Backport from mainline: diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp index 75fb3a63c40..38e69db65b3 100644 --- a/gcc/fortran/ChangeLog.omp +++ b/gcc/fortran/ChangeLog.omp @@ -1,3 +1,12 @@ +2023-03-01 Tobias Burnus + + Backported from master: + 2023-03-01 Tobias Burnus + + PR middle-end/108546 + * trans-openmp.cc (gfc_trans_omp_clauses): Fix mapping of + type(C_ptr) variables. + 2023-02-22 Tobias Burnus * trans-decl.cc (gfc_get_symbol_decl): Add attributes diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 8784dc0f77f..acd8ce645bb 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -4640,7 +4640,9 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl) || GFC_DECL_CRAY_POINTEE (decl) || GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (type)) - || 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; enum gomp_map_kind gmk = GOMP_MAP_POINTER; diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index d5b102e7fb6..c18ec6a60a1 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -15101,7 +15101,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/ChangeLog.omp b/libgomp/ChangeLog.omp index 51c15697e72..3ed90bb38f2 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,12 @@ +2023-03-01 Tobias Burnus + + Backported from master: + 2023-03-01 Tobias Burnus + + PR middle-end/108546 + * testsuite/libgomp.fortran/is_device_ptr-3.f90: New test. + * testsuite/libgomp.fortran/use_device_ptr-optional-4.f90: New test. + 2023-02-23 Andrew Stubbs * target.c (gomp_attach_pointer): Check for USM. 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