xref: /llvm-project/flang/test/Evaluate/folding09.f90 (revision 17daa84348f55aac7b0264a3e545a1cc4b16fe1a)
1! RUN: %python %S/test_folding.py %s %flang_fc1
2! Test folding of IS_CONTIGUOUS
3
4module 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, m
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, alch)
20    real, intent(in) :: arr1(:), arr2(10), mat(10, 10)
21    real, intent(in), contiguous :: arr3(:)
22    real, allocatable :: alloc(:)
23    real :: scalar
24    character(5) charr(5)
25    character(1) char1(5)
26    character(0) char0(5)
27    character(*) alch(5)
28    integer(kind=merge(1,-1,       is_contiguous(0)))               t01
29    integer(kind=merge(1,-1,       is_contiguous(scalar)))          t02
30    integer(kind=merge(1,-1,       is_contiguous(scalar + scalar))) t03
31    integer(kind=merge(1,-1,       is_contiguous([0, 1, 2])))       t04
32    integer(kind=merge(1,-1,       is_contiguous(arr1 + 1.0)))      t05
33    integer(kind=merge(1,-1,       is_contiguous(arr2)))            t06
34    integer(kind=merge(1,-1,       is_contiguous(mat)))             t07
35    integer(kind=merge(1,-1,       is_contiguous(mat(1:10,1))))     t08
36    integer(kind=merge(1,-1,       is_contiguous(arr2(1:10:1))))    t09
37    integer(kind=merge(1,-1, .not. is_contiguous(arr2(1:10:2))))    t10
38    integer(kind=merge(1,-1,       is_contiguous(arr3)))            t11
39    integer(kind=merge(1,-1, .not. is_contiguous(arr3(1:10:2))))    t12
40    integer(kind=merge(1,-1,       is_contiguous(f())))             t13
41    integer(kind=merge(1,-1,       is_contiguous(alloc)))           t14
42    integer(kind=merge(1,-1,       is_contiguous(charr(:)(:))))     t15
43    integer(kind=merge(1,-1,       is_contiguous(charr(1)(2:3))))   t16
44    integer(kind=merge(1,-1,       is_contiguous(charr(:)(1:))))    t17
45    integer(kind=merge(1,-1,       is_contiguous(charr(:)(3:2))))   t18
46    integer(kind=merge(1,-1,       is_contiguous(charr(:)(1:5))))   t19
47    integer(kind=merge(1,-1, .not. is_contiguous(charr(:)(1:4))))   t20
48    integer(kind=merge(1,-1,       is_contiguous(char1(:)(n:m))))   t21
49    integer(kind=merge(1,-1, .not. is_contiguous(char1(1:5:2)(n:m)))) t22
50    integer(kind=merge(1,-1,       is_contiguous(char0(:)(n:m))))   t23
51    integer(kind=merge(1,-1,       is_contiguous(char0(1:5:2)(n:m)))) t24
52    integer(kind=merge(1,-1,       is_contiguous(alch(:)(:))))      t25
53    associate (x => arr2)
54      block
55        integer(kind=merge(1,-1,is_contiguous(x))) n
56      end block
57    end associate
58    associate (x => arr2(1:10:2))
59      block
60        integer(kind=merge(1,-1,.not. is_contiguous(x))) n
61      end block
62    end associate
63    associate (x => arr3)
64      block
65        integer(kind=merge(1,-1,is_contiguous(x))) n
66      end block
67    end associate
68    associate (x => arr3(1:10:2))
69      block
70        integer(kind=merge(1,-1,.not. is_contiguous(x))) n
71      end block
72    end associate
73  end subroutine
74  subroutine test2(x, vec)
75    type t
76      integer :: i
77    end type
78    type(t) :: x(100)
79    integer(8) :: vec(10)
80    integer(kind=merge(1,-1, .not. is_contiguous(x(1:50:2)%i)))    t01
81    integer(kind=merge(1,-1, .not. is_contiguous(x(vec)%i)))       t02
82  end subroutine
83end module
84