@@ -8,7 +8,7 @@ module caf_allocate_test
88 use veggies, only: result_t, test_item_t, assert_that, assert_equals, describe, it, succeed
99 use iso_c_binding, only: &
1010 c_ptr, c_int, c_int64_t, c_size_t, c_funptr, c_null_funptr, &
11- c_f_pointer, c_null_ptr, c_loc, c_sizeof, c_associated
11+ c_f_pointer, c_null_ptr, c_loc, c_sizeof, c_associated, c_intptr_t
1212
1313 implicit none
1414 private
@@ -97,9 +97,23 @@ function check_allocate_non_symmetric() result(result_)
9797 call prif_deallocate(c_loc(local_slice))
9898 end function
9999
100- function assert_aliased (h1 , h2 ) result(result_)
100+ ! returns (p + off)
101+ pure function c_ptr_add (p , off )
102+ type (c_ptr), intent (in ) :: p
103+ integer (c_size_t), intent (in ) :: off
104+ type (c_ptr) :: c_ptr_add
105+ integer (c_intptr_t) :: tmp
106+
107+ tmp = transfer (p, tmp)
108+ tmp = tmp + off
109+ c_ptr_add = transfer (tmp, c_ptr_add)
110+ end function
111+
112+ function assert_aliased (h1 , h2 , offset ) result(result_)
101113 type (result_t) :: result_
102114 type (prif_coarray_handle) :: h1, h2
115+ integer (c_size_t), optional :: offset
116+ integer (c_size_t) :: offset_
103117 type (c_ptr) :: p1, p2
104118 integer (c_size_t) :: s1, s2
105119 type (c_ptr) :: c1, c2, cx
@@ -108,11 +122,19 @@ function assert_aliased(h1, h2) result(result_)
108122
109123 result_ = succeed(" " )
110124
125+ if (present (offset)) then
126+ offset_ = offset
127+ else
128+ offset_ = 0
129+ endif
130+
111131 call prif_local_data_pointer(h1, p1)
112132 call prif_local_data_pointer(h2, p2)
113133 result_ = result_ .and. &
114- assert_that(c_associated(p1 , p2))
134+ assert_that(c_associated(c_ptr_add(p1, offset_) , p2))
115135
136+ ! As of PRIF 0.6. prif_size_bytes is unspecified for aliases,
137+ ! so this particular check is specific to the current Caffeine implementation
116138 call prif_size_bytes(h1, s1)
117139 call prif_size_bytes(h2, s2)
118140 result_ = result_ .and. &
@@ -190,6 +212,11 @@ function check_allocate_integer_array_coarray_with_corank2() result(result_)
190212 end block
191213
192214 block ! check aliasing creation
215+ # if FORCE_PRIF_0_5
216+ # define data_pointer_offset
217+ # else
218+ # define data_pointer_offset 0_c_size_t,
219+ # endif
193220 integer i, j
194221 integer , parameter :: lim = 10
195222 type (prif_coarray_handle) :: a(lim)
@@ -198,18 +225,30 @@ function check_allocate_integer_array_coarray_with_corank2() result(result_)
198225 do i= 2 , lim
199226 lco(1 ) = i
200227 uco(1 ) = i + num_imgs
201- call prif_alias_create(a(i-1 ), lco, uco, a(i))
228+ call prif_alias_create(a(i-1 ), lco, uco, data_pointer_offset a(i))
202229 result_ = result_ .and. &
203230 assert_aliased(a(i-1 ), a(i))
204231 do j = i+1 ,lim
205232 lco(1 ) = j
206233 uco(1 ) = j + num_imgs
207- call prif_alias_create(a(i), lco, uco, a(j))
234+ call prif_alias_create(a(i), lco, uco, data_pointer_offset a(j))
208235 result_ = result_ .and. &
209236 assert_aliased(a(i), a(j))
210237 result_ = result_ .and. &
211238 assert_aliased(a(j), coarray_handle)
212239 end do
240+ # if !FORCE_PRIF_0_5
241+ ! test PRIF 0.6 data_pointer_offset
242+ block
243+ type (prif_coarray_handle) :: b
244+ integer (c_size_t) :: off
245+ off = i
246+ call prif_alias_create(a(i), lco, uco, off, b)
247+ result_ = result_ .and. &
248+ assert_aliased(a(i), b, off)
249+ call prif_alias_destroy(b)
250+ end block
251+ # endif
213252 do j = i+1 ,lim
214253 call prif_alias_destroy(a(j))
215254 end do
0 commit comments