1! { dg-do run }
2!
3! Check that C_F_Pointer works with a noncontiguous SHAPE argument
4!
5use iso_c_binding
6type(c_ptr) :: x
7integer, target :: array(3)
8integer, pointer :: ptr(:,:)
9integer, pointer :: ptr2(:,:,:)
10integer :: myshape(5)
11
12array = [22,33,44]
13x = c_loc(array)
14myshape = [1,2,3,4,1]
15
16call c_f_pointer(x, ptr, shape=myshape(1:4:2))
17if (any (lbound(ptr) /= [ 1, 1])) STOP 1
18if (any (ubound(ptr) /= [ 1, 3])) STOP 2
19if (any (shape(ptr) /= [ 1, 3])) STOP 3
20if (any (ptr(1,:) /= array)) STOP 4
21
22call c_f_pointer(x, ptr2, shape=myshape([1,3,1]))
23if (any (lbound(ptr2) /= [ 1, 1, 1])) STOP 5
24if (any (ubound(ptr2) /= [ 1, 3, 1])) STOP 6
25if (any (shape(ptr2) /= [ 1, 3, 1])) STOP 7
26if (any (ptr2(1,:,1) /= array)) STOP 8
27end
28