| 1 |
! RUN: %python %S/test_folding.py %s %flang_fc1 |
| 2 |
! Test folding of IS_CONTIGUOUS |
| 3 |
|
| 4 |
module m |
| 5 |
real, target :: hosted(2) |
| 6 |
integer, parameter :: cst(2,2) = reshape([1, 2, 3, 4], shape(cst)) |
| 7 |
integer, parameter :: empty_cst(2,0) = reshape([1], shape(empty_cst)) |
| 8 |
integer :: n |
| 9 |
logical, parameter :: test_param1 = is_contiguous(cst(:,1)) |
| 10 |
logical, parameter :: test_param2 = is_contiguous(cst(1,:)) |
| 11 |
logical, parameter :: test_param3 = is_contiguous(cst(:,n)) |
| 12 |
logical, parameter :: test_param4 = .not. is_contiguous(cst(n,:)) |
| 13 |
logical, parameter :: test_param5 = is_contiguous(empty_cst(n,-1:n:2)) |
| 14 |
contains |
| 15 |
function f() |
| 16 |
real, pointer, contiguous :: f(:) |
| 17 |
f => hosted |
| 18 |
end function |
| 19 |
subroutine test(arr1, arr2, arr3, mat, alloc) |
| 20 |
real, intent(in) :: arr1(:), arr2(10), mat(10, 10) |
| 21 |
real, intent(in), contiguous :: arr3(:) |
| 22 |
real, allocatable :: alloc(:) |
| 23 |
real :: scalar |
| 24 |
integer(kind=merge(1,-1, is_contiguous(0))) t01 |
| 25 |
integer(kind=merge(1,-1, is_contiguous(scalar))) t02 |
| 26 |
integer(kind=merge(1,-1, is_contiguous(scalar + scalar))) t03 |
| 27 |
integer(kind=merge(1,-1, is_contiguous([0, 1, 2]))) t04 |
| 28 |
integer(kind=merge(1,-1, is_contiguous(arr1 + 1.0))) t05 |
| 29 |
integer(kind=merge(1,-1, is_contiguous(arr2))) t06 |
| 30 |
integer(kind=merge(1,-1, is_contiguous(mat))) t07 |
| 31 |
integer(kind=merge(1,-1, is_contiguous(mat(1:10,1)))) t08 |
| 32 |
integer(kind=merge(1,-1, is_contiguous(arr2(1:10:1)))) t09 |
| 33 |
integer(kind=merge(1,-1, .not. is_contiguous(arr2(1:10:2)))) t10 |
| 34 |
integer(kind=merge(1,-1, is_contiguous(arr3))) t11 |
| 35 |
integer(kind=merge(1,-1, .not. is_contiguous(arr3(1:10:2)))) t12 |
| 36 |
integer(kind=merge(1,-1, is_contiguous(f()))) t13 |
| 37 |
integer(kind=merge(1,-1, is_contiguous(alloc))) t14 |
| 38 |
associate (x => arr2) |
| 39 |
block |
| 40 |
integer(kind=merge(1,-1,is_contiguous(x))) n |
| 41 |
end block |
| 42 |
end associate |
| 43 |
associate (x => arr2(1:10:2)) |
| 44 |
block |
| 45 |
integer(kind=merge(1,-1,.not. is_contiguous(x))) n |
| 46 |
end block |
| 47 |
end associate |
| 48 |
associate (x => arr3) |
| 49 |
block |
| 50 |
integer(kind=merge(1,-1,is_contiguous(x))) n |
| 51 |
end block |
| 52 |
end associate |
| 53 |
associate (x => arr3(1:10:2)) |
| 54 |
block |
| 55 |
integer(kind=merge(1,-1,.not. is_contiguous(x))) n |
| 56 |
end block |
| 57 |
end associate |
| 58 |
end subroutine |
| 59 |
subroutine test2(x, vec) |
| 60 |
type t |
| 61 |
integer :: i |
| 62 |
end type |
| 63 |
type(t) :: x(100) |
| 64 |
integer(8) :: vec(10) |
| 65 |
integer(kind=merge(1,-1, .not. is_contiguous(x(1:50:2)%i))) t01 |
| 66 |
integer(kind=merge(1,-1, .not. is_contiguous(x(vec)%i))) t02 |
| 67 |
end subroutine |
| 68 |
end module |