[llvm] [OpenMP] Allocatable explicit member mapping fortran offloading tests (PR #96264)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 20 18:47:23 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-offload
Author: None (agozillon)
<details>
<summary>Changes</summary>
This PR is one in a series of 3 that aim to add support for explicit member mapping of
allocatable components in derived types within OpenMP+Fortran for Flang.
This PR provides all of the runtime tests that are currently upstreamable, unfortunately
some of the other tests would require linking of the fortran runtime for offload which
we currently do not do. But regardless, this is plenty to ensure that the mapping is
working in most cases.
---
Patch is 41.37 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96264.diff
25 Files Affected:
- (added) offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array-of-dtype.f90 (+42)
- (added) offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array.f90 (+35)
- (added) offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array-v2.f90 (+40)
- (added) offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array.f90 (+39)
- (added) offload/test/offloading/fortran/target-map-alloca-dtype-array-and-scalar.f90 (+46)
- (added) offload/test/offloading/fortran/target-map-alloca-dtype-array-of-dtype.f90 (+42)
- (added) offload/test/offloading/fortran/target-map-allocatable-dtype.f90 (+37)
- (modified) offload/test/offloading/fortran/target-map-double-nested-dtype-array-bounds.f90 (+1-1)
- (added) offload/test/offloading/fortran/target-map-dtype-3d-alloca-array-with-bounds.f90 (+47)
- (added) offload/test/offloading/fortran/target-map-dtype-alloca-and-non-alloca-array.f90 (+41)
- (added) offload/test/offloading/fortran/target-map-dtype-alloca-array-and-non-alloca-dtype.f90 (+50)
- (added) offload/test/offloading/fortran/target-map-dtype-alloca-array-of-dtype.f90 (+40)
- (added) offload/test/offloading/fortran/target-map-dtype-alloca-array-with-bounds.f90 (+35)
- (added) offload/test/offloading/fortran/target-map-dtype-allocatable-array.f90 (+33)
- (added) offload/test/offloading/fortran/target-map-dtype-allocatable-scalar-and-array.f90 (+39)
- (added) offload/test/offloading/fortran/target-map-multi-alloca-dtypes-with-multi-alloca-members.f90 (+96)
- (added) offload/test/offloading/fortran/target-map-multi-alloca-dtypes-with-multi-mixed-members.f90 (+88)
- (added) offload/test/offloading/fortran/target-map-nested-alloca-dtype-3d-alloca-array-bounds.f90 (+57)
- (added) offload/test/offloading/fortran/target-map-nested-alloca-dtype-alloca-array-bounds.f90 (+45)
- (added) offload/test/offloading/fortran/target-map-nested-dtype-3d-alloca-array-with-bounds.f90 (+55)
- (added) offload/test/offloading/fortran/target-map-nested-dtype-alloca-and-non-alloca-array.f90 (+52)
- (added) offload/test/offloading/fortran/target-map-nested-dtype-alloca-array-and-non-alloca-dtype.f90 (+56)
- (added) offload/test/offloading/fortran/target-map-nested-dtype-alloca-array-with-bounds.f90 (+44)
- (added) offload/test/offloading/fortran/target-map-nested-dtype-alloca-array.f90 (+43)
- (added) offload/test/offloading/fortran/target-map-pointer-to-dtype-allocatable-member.f90 (+52)
``````````diff
diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array-of-dtype.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array-of-dtype.f90
new file mode 100644
index 0000000000000..fd3a011850aec
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array-of-dtype.f90
@@ -0,0 +1,42 @@
+! Offloading test checking interaction of explicit
+! member mapping of an allocatable array of derived
+! types contained within an allocatable derived type
+! REQUIRES: flang, amdgcn-amd-amdhsa
+! UNSUPPORTED: nvptx64-nvidia-cuda
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: nested_dtype
+ real(4) :: i
+ real(4) :: j
+ integer(4) :: array_i(10)
+ integer(4) :: k
+ end type nested_dtype
+
+ type :: dtype
+ real(4) :: i
+ integer(4) :: array_i(10)
+ real(4) :: j
+ type(nested_dtype), allocatable :: array_dtype(:)
+ integer(4) :: k
+ end type dtype
+
+ type(dtype), allocatable :: dtyped
+ allocate(dtyped)
+ allocate(dtyped%array_dtype(10))
+
+!$omp target map(tofrom: dtyped%array_dtype)
+ do i = 1, 10
+ dtyped%array_dtype(i)%k = i
+ end do
+!$omp end target
+
+ print *, dtyped%array_dtype%k
+end program main
+
+!CHECK: 1 2 3 4 5 6 7 8 9 10
diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array.f90
new file mode 100644
index 0000000000000..6b8542a882f31
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-alloca-dtype-alloca-array.f90
@@ -0,0 +1,35 @@
+! Offload test that checks an allocatable array within an
+! allocatable derived type can be mapped explicitly using
+! member mapping.
+! REQUIRES: flang
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: dtype
+ real(4) :: i
+ integer(4) :: array_i(10)
+ real(4) :: j
+ integer, allocatable :: array_j(:)
+ integer(4) :: k
+ end type dtype
+
+ type(dtype), allocatable :: alloca_dtype
+ allocate(alloca_dtype)
+ allocate(alloca_dtype%array_j(10))
+
+!$omp target map(tofrom: alloca_dtype%array_j)
+ do i = 1, 10
+ alloca_dtype%array_j(i) = i
+ end do
+!$omp end target
+
+print *, alloca_dtype%array_j
+
+end program main
+
+!CHECK: 1 2 3 4 5 6 7 8 9 10
diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array-v2.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array-v2.f90
new file mode 100644
index 0000000000000..8188e24a1b992
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array-v2.f90
@@ -0,0 +1,40 @@
+! Offload test that checks an allocatable derived type can be
+! mapped alongside one of its own allocatable components
+! without disrupting either mapping, different from original
+! as the argument ordering is reversed (similar to C++ mapping
+! of a struct and a pointer, in concept at least).
+! REQUIRES: flang
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: dtype
+ real(4) :: i
+ integer, allocatable :: scalar
+ integer(4) :: array_i(10)
+ real(4) :: j
+ integer, allocatable :: array_j(:)
+ integer(4) :: k
+ end type dtype
+
+ type(dtype), allocatable :: alloca_dtype
+ allocate(alloca_dtype)
+ allocate(alloca_dtype%array_j(10))
+
+!$omp target map(tofrom: alloca_dtype%array_j, alloca_dtype)
+ do i = 1, 10
+ alloca_dtype%array_j(i) = i
+ end do
+ alloca_dtype%k = 50
+!$omp end target
+
+print *, alloca_dtype%array_j
+print *, alloca_dtype%k
+end program main
+
+!CHECK: 1 2 3 4 5 6 7 8 9 10
+!CHECK: 50
diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array.f90
new file mode 100644
index 0000000000000..c106732e4dc0c
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-alloca-dtype-and-alloca-array.f90
@@ -0,0 +1,39 @@
+! Offload test that checks an allocatable derived type can be
+! mapped alongside one of its own allocatable components
+! without disrupting either mapping (similar to C++ mapping
+! of a struct and a pointer, in concept at least).
+! REQUIRES: flang
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: dtype
+ real(4) :: i
+ integer, allocatable :: scalar
+ integer(4) :: array_i(10)
+ real(4) :: j
+ integer, allocatable :: array_j(:)
+ integer(4) :: k
+ end type dtype
+
+ type(dtype), allocatable :: alloca_dtype
+ allocate(alloca_dtype)
+ allocate(alloca_dtype%array_j(10))
+
+!$omp target map(tofrom: alloca_dtype, alloca_dtype%array_j)
+ do i = 1, 10
+ alloca_dtype%array_j(i) = i
+ end do
+ alloca_dtype%k = 50
+!$omp end target
+
+print *, alloca_dtype%array_j
+print *, alloca_dtype%k
+end program main
+
+!CHECK: 1 2 3 4 5 6 7 8 9 10
+!CHECK: 50
diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-array-and-scalar.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-array-and-scalar.f90
new file mode 100644
index 0000000000000..175cb2c5a8434
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-alloca-dtype-array-and-scalar.f90
@@ -0,0 +1,46 @@
+! Offloading test checking interaction of explicit
+! member mapping of non-allocatable members of an
+! allocatable derived type.
+! REQUIRES: flang, amdgcn-amd-amdhsa
+! UNSUPPORTED: nvptx64-nvidia-cuda
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: nested_dtype
+ real(4) :: i
+ real(4) :: j
+ integer(4) :: array_i(10)
+ integer(4) :: k
+ end type nested_dtype
+
+ type :: dtype
+ real(4) :: i
+ integer, allocatable :: scalar
+ integer(4) :: array_i(10)
+ type(nested_dtype) :: nested_dtype
+ real(4) :: j
+ integer, allocatable :: array_j(:)
+ integer(4) :: k
+ end type dtype
+
+ type(dtype), allocatable :: alloca_dtype
+ allocate(alloca_dtype)
+
+!$omp target map(tofrom: alloca_dtype%nested_dtype%array_i, alloca_dtype%k)
+ do i = 1, 10
+ alloca_dtype%nested_dtype%array_i(i) = i
+ end do
+ alloca_dtype%k = 50
+!$omp end target
+
+print *, alloca_dtype%k
+print *, alloca_dtype%nested_dtype%array_i
+end program main
+
+!CHECK: 50
+!CHECK: 1 2 3 4 5 6 7 8 9 10
diff --git a/offload/test/offloading/fortran/target-map-alloca-dtype-array-of-dtype.f90 b/offload/test/offloading/fortran/target-map-alloca-dtype-array-of-dtype.f90
new file mode 100644
index 0000000000000..7fc3be5c9c801
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-alloca-dtype-array-of-dtype.f90
@@ -0,0 +1,42 @@
+! Offloading test checking interaction of explicit
+! member mapping of an array of derived types
+! contained within an allocatable derived type
+! REQUIRES: flang, amdgcn-amd-amdhsa
+! UNSUPPORTED: nvptx64-nvidia-cuda
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: nested_dtype
+ real(4) :: i
+ real(4) :: j
+ integer(4) :: array_i(10)
+ integer(4) :: k
+ end type nested_dtype
+
+ type :: dtype
+ real(4) :: i
+ integer(4) :: array_i(10)
+ real(4) :: j
+ type(nested_dtype) :: array_dtype(10)
+ integer(4) :: k
+ end type dtype
+
+ type(dtype), allocatable :: dtyped
+ allocate(dtyped)
+
+!$omp target map(tofrom: dtyped%array_dtype)
+ do i = 1, 10
+ dtyped%array_dtype(i)%k = i
+ end do
+!$omp end target
+
+print *, dtyped%array_dtype%k
+
+end program main
+
+!CHECK: 1 2 3 4 5 6 7 8 9 10
diff --git a/offload/test/offloading/fortran/target-map-allocatable-dtype.f90 b/offload/test/offloading/fortran/target-map-allocatable-dtype.f90
new file mode 100644
index 0000000000000..56162e5a20212
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-allocatable-dtype.f90
@@ -0,0 +1,37 @@
+! Offload test that checks an allocatable derived type can be
+! mapped and at the least non-allocatable components can be
+! accessed.
+! REQUIRES: flang
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: dtype
+ real(4) :: i
+ integer, allocatable :: scalar
+ integer(4) :: array_i(10)
+ real(4) :: j
+ integer, allocatable :: array_j(:)
+ integer(4) :: k
+ end type dtype
+
+ type(dtype), allocatable :: alloca_dtype
+ allocate(alloca_dtype)
+
+!$omp target map(tofrom: alloca_dtype)
+ do i = 1, 10
+ alloca_dtype%array_i(i) = i
+ end do
+ alloca_dtype%k = 50
+!$omp end target
+
+print *, alloca_dtype%k
+print *, alloca_dtype%array_i
+end program main
+
+!CHECK: 50
+!CHECK: 1 2 3 4 5 6 7 8 9 10
diff --git a/offload/test/offloading/fortran/target-map-double-nested-dtype-array-bounds.f90 b/offload/test/offloading/fortran/target-map-double-nested-dtype-array-bounds.f90
index d327ebf8c1a92..250473e3768eb 100644
--- a/offload/test/offloading/fortran/target-map-double-nested-dtype-array-bounds.f90
+++ b/offload/test/offloading/fortran/target-map-double-nested-dtype-array-bounds.f90
@@ -1,5 +1,5 @@
! Offloading test checking interaction of two
-! explicit arrau member maps with bounds from
+! explicit array member maps with bounds from
! two nested derived types
! REQUIRES: flang, amdgcn-amd-amdhsa
! UNSUPPORTED: nvptx64-nvidia-cuda
diff --git a/offload/test/offloading/fortran/target-map-dtype-3d-alloca-array-with-bounds.f90 b/offload/test/offloading/fortran/target-map-dtype-3d-alloca-array-with-bounds.f90
new file mode 100644
index 0000000000000..5299d6a5064b2
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-dtype-3d-alloca-array-with-bounds.f90
@@ -0,0 +1,47 @@
+! Offload test that checks an allocatable array can be mapped with
+! a specified 3-D bounds when contained within a derived type and
+! mapped via member mapping.
+! REQUIRES: flang
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: top_layer
+ real(4) :: i
+ integer, allocatable :: scalar
+ integer(4) :: array_i(10)
+ real(4) :: j
+ integer, allocatable :: array_j(:,:,:)
+ integer(4) :: k
+ end type top_layer
+
+ type(top_layer) :: one_l
+ integer :: inArray(3,3,3)
+
+ allocate(one_l%array_j(3,3,3))
+
+ do i = 1, 3
+ do j = 1, 3
+ do k = 1, 3
+ inArray(i, j, k) = 42
+ one_l%array_j(i, j, k) = 0
+ end do
+ end do
+ end do
+
+!$omp target map(tofrom: one_l%array_j(1:3, 1:3, 2:2)) map(to: inArray(1:3, 1:3, 1:3))
+ do j = 1, 3
+ do k = 1, 3
+ one_l%array_j(k, j, 2) = inArray(k, j, 2)
+ end do
+ end do
+!$omp end target
+
+ print *, one_l%array_j
+end program main
+
+!CHECK: 0 0 0 0 0 0 0 0 0 42 42 42 42 42 42 42 42 42 0 0 0 0 0 0 0 0 0
diff --git a/offload/test/offloading/fortran/target-map-dtype-alloca-and-non-alloca-array.f90 b/offload/test/offloading/fortran/target-map-dtype-alloca-and-non-alloca-array.f90
new file mode 100644
index 0000000000000..d1e302477d302
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-dtype-alloca-and-non-alloca-array.f90
@@ -0,0 +1,41 @@
+! Offload test that checks an allocatable array can be mapped alongside
+! a non-allocatable array when both are contained within a derived type
+! can be mapped correctly via member mapping and then written to.
+! REQUIRES: flang
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: one_layer
+ real(4) :: i
+ integer, allocatable :: scalar
+ integer(4) :: array_i(10)
+ real(4) :: j
+ integer, allocatable :: array_j(:)
+ integer(4) :: k
+ end type one_layer
+
+ type(one_layer) :: one_l
+
+ allocate(one_l%array_j(10))
+
+ do i = 1, 10
+ one_l%array_i(i) = i
+ end do
+
+!$omp target map(tofrom: one_l%array_i, one_l%array_j)
+ do i = 1, 10
+ one_l%array_j(i) = one_l%array_i(i) + i
+ end do
+!$omp end target
+
+ print *, one_l%array_i
+ print *, one_l%array_j
+end program main
+
+!CHECK: 1 2 3 4 5 6 7 8 9 10
+!CHECK: 2 4 6 8 10 12 14 16 18 20
diff --git a/offload/test/offloading/fortran/target-map-dtype-alloca-array-and-non-alloca-dtype.f90 b/offload/test/offloading/fortran/target-map-dtype-alloca-array-and-non-alloca-dtype.f90
new file mode 100644
index 0000000000000..f3112ff21b8aa
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-dtype-alloca-array-and-non-alloca-dtype.f90
@@ -0,0 +1,50 @@
+! Offload test that checks an allocatable array can be mapped alongside
+! a non-allocatable derived type when both are contained within a
+! derived type can be mapped correctly via member mapping and then
+! written to.
+! REQUIRES: flang
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: bottom_layer
+ real(4) :: i
+ integer(4) :: array_i(10)
+ integer(4) :: k
+ end type bottom_layer
+
+ type :: top_layer
+ real(4) :: i
+ integer, allocatable :: scalar
+ integer(4) :: array_i(10)
+ real(4) :: j
+ integer, allocatable :: array_j(:)
+ integer(4) :: k
+ type(bottom_layer) :: nest
+ end type top_layer
+
+ type(top_layer) :: one_l
+
+ allocate(one_l%array_j(10))
+ allocate(one_l%scalar)
+
+ do i = 1, 10
+ one_l%nest%array_i(i) = i
+ end do
+
+!$omp target map(tofrom: one_l%nest, one_l%array_j)
+ do i = 1, 10
+ one_l%array_j(i) = one_l%nest%array_i(i) + i
+ end do
+!$omp end target
+
+ print *, one_l%nest%array_i
+ print *, one_l%array_j
+end program main
+
+!CHECK: 1 2 3 4 5 6 7 8 9 10
+!CHECK: 2 4 6 8 10 12 14 16 18 20
diff --git a/offload/test/offloading/fortran/target-map-dtype-alloca-array-of-dtype.f90 b/offload/test/offloading/fortran/target-map-dtype-alloca-array-of-dtype.f90
new file mode 100644
index 0000000000000..b286afb6125ab
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-dtype-alloca-array-of-dtype.f90
@@ -0,0 +1,40 @@
+! Offload test that checks it is possible to member map
+! an allocatable array of derived types nested within a
+! non-allocatable derived type.
+! REQUIRES: flang
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: nested_dtype
+ real(4) :: i
+ real(4) :: j
+ integer(4) :: array_i(10)
+ integer(4) :: k
+ end type nested_dtype
+
+ type :: dtype
+ real(4) :: i
+ integer(4) :: array_i(10)
+ real(4) :: j
+ type(nested_dtype), allocatable :: array_dtype(:)
+ integer(4) :: k
+ end type dtype
+
+ type(dtype) :: dtyped
+ allocate(dtyped%array_dtype(10))
+
+!$omp target map(tofrom: dtyped%array_dtype)
+ do i = 1, 10
+ dtyped%array_dtype(i)%k = i
+ end do
+!$omp end target
+
+print *, dtyped%array_dtype%k
+end program main
+
+!CHECK: 1 2 3 4 5 6 7 8 9 10
diff --git a/offload/test/offloading/fortran/target-map-dtype-alloca-array-with-bounds.f90 b/offload/test/offloading/fortran/target-map-dtype-alloca-array-with-bounds.f90
new file mode 100644
index 0000000000000..a25fb6dc30054
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-dtype-alloca-array-with-bounds.f90
@@ -0,0 +1,35 @@
+! Offload test that checks an allocatable array can be mapped with
+! a specified 1-D bounds when contained within a derived type and
+! mapped via member mapping.
+! REQUIRES: flang
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: top_layer
+ real(4) :: i
+ integer, allocatable :: scalar
+ integer(4) :: array_i(10)
+ real(4) :: j
+ integer, allocatable :: array_j(:)
+ integer(4) :: k
+ end type top_layer
+
+ type(top_layer) :: one_l
+
+ allocate(one_l%array_j(10))
+
+!$omp target map(tofrom: one_l%array_j(2:6))
+ do index = 1, 10
+ one_l%array_j(index) = index
+ end do
+!$omp end target
+
+ print *, one_l%array_j
+end program main
+
+!CHECK: 0 2 3 4 5 6 0 0 0 0
diff --git a/offload/test/offloading/fortran/target-map-dtype-allocatable-array.f90 b/offload/test/offloading/fortran/target-map-dtype-allocatable-array.f90
new file mode 100644
index 0000000000000..e20c102b41aa9
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-dtype-allocatable-array.f90
@@ -0,0 +1,33 @@
+! Offload test that checks an allocatable array contained within a derived type
+! can be mapped correctly via member mapping and then written to.
+! REQUIRES: flang
+! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
+! UNSUPPORTED: aarch64-unknown-linux-gnu
+! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
+! UNSUPPORTED: x86_64-pc-linux-gnu
+! UNSUPPORTED: x86_64-pc-linux-gnu-LTO
+
+! RUN: %libomptarget-compile-fortran-run-and-check-generic
+program main
+ type :: one_layer
+ real(4) :: i
+ integer, allocatable :: scalar
+ integer(4) :: array_i(10)
+ real(4) :: j
+ integer, allocatable :: array_j(:)
+ integer(4) :: k
+ end type one_layer
+
+ type(one_layer) :: one_l
+ allocate(one_l%array_j(10))
+
+ !$omp target map(tofrom: one_l%array_j)
+ do i = 1, 10
+ one_l%array_j(i) = i
+ end do
+ !$omp end target
+
+ print *, one_l%array_j
+end program main
+
+!CHECK: 1 2 3 4 5 6 7 8 9 10
diff --git a/offload/test/offloading/fortran/target-map-dtype-allocatable-scalar-and-array.f90 b/offload/test/offloading/fortran/target-map-dtype-allocatable-scalar-and-array.f90
new file mode 100644
index 0000000000000..836ba97e55c50
--- /dev/null
+++ b/offload/test/offloading/fortran/target-map-dtype-allocatable-scalar-and-array.f90
@@ -0,0 +1,39 @@
+! Offload test that checks an allocatable array alongside an allocatable
+! sclar contained within a derived type can be mapped correctly via
+! member mapping and then written to.
+! REQUIRES: flang
+! UNSUPPORT...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/96264
More information about the llvm-commits
mailing list