2017-02-20 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gfortran.dg / c_f_pointer_shape_tests_5.f90
blobf3e17892bf929977c1c6bb379e3694530ff41e79
1 ! { dg-do run }
3 ! Check that C_F_Pointer works with a noncontiguous SHAPE argument
5 use iso_c_binding
6 type(c_ptr) :: x
7 integer, target :: array(3)
8 integer, pointer :: ptr(:,:)
9 integer, pointer :: ptr2(:,:,:)
10 integer :: myshape(5)
12 array = [22,33,44]
13 x = c_loc(array)
14 myshape = [1,2,3,4,1]
16 call c_f_pointer(x, ptr, shape=myshape(1:4:2))
17 if (any (lbound(ptr) /= [ 1, 1])) call abort ()
18 if (any (ubound(ptr) /= [ 1, 3])) call abort ()
19 if (any (shape(ptr) /= [ 1, 3])) call abort ()
20 if (any (ptr(1,:) /= array)) call abort()
22 call c_f_pointer(x, ptr2, shape=myshape([1,3,1]))
23 if (any (lbound(ptr2) /= [ 1, 1, 1])) call abort ()
24 if (any (ubound(ptr2) /= [ 1, 3, 1])) call abort ()
25 if (any (shape(ptr2) /= [ 1, 3, 1])) call abort ()
26 if (any (ptr2(1,:,1) /= array)) call abort()
27 end