1! RUN: %S/test_folding.sh %s %t %f18
2! Test folding of LBOUND and UBOUND
3
4module m
5 contains
6  function foo()
7    real :: foo(2:3,4:6)
8  end function
9  subroutine test(n1,a1,a2)
10    integer, intent(in) :: n1
11    real, intent(in) :: a1(0:n1), a2(0:*)
12    type :: t
13      real :: a
14    end type
15    type(t) :: ta(0:2)
16    character(len=2) :: ca(-1:1)
17    integer, parameter :: lba1(*) = lbound(a1)
18    logical, parameter :: test_lba1 = all(lba1 == [0])
19    integer, parameter :: lba2(*) = lbound(a2)
20    logical, parameter :: test_lba2 = all(lba2 == [0])
21    integer, parameter :: lbtadim = lbound(ta,1)
22    logical, parameter :: test_lbtadim = lbtadim == 0
23    integer, parameter :: ubtadim = ubound(ta,1)
24    logical, parameter :: test_ubtadim = ubtadim == 2
25    integer, parameter :: lbta1(*) = lbound(ta)
26    logical, parameter :: test_lbta1 = all(lbta1 == [0])
27    integer, parameter :: ubta1(*) = ubound(ta)
28    logical, parameter :: test_ubta1 = all(ubta1 == [2])
29    integer, parameter :: lbta2(*) = lbound(ta(:))
30    logical, parameter :: test_lbta2 = all(lbta2 == [1])
31    integer, parameter :: ubta2(*) = ubound(ta(:))
32    logical, parameter :: test_ubta2 = all(ubta2 == [3])
33    integer, parameter :: lbta3(*) = lbound(ta%a)
34    logical, parameter :: test_lbta3 = all(lbta3 == [1])
35    integer, parameter :: ubta3(*) = ubound(ta%a)
36    logical, parameter :: test_ubta3 = all(ubta3 == [3])
37    integer, parameter :: lbca1(*) = lbound(ca)
38    logical, parameter :: test_lbca1 = all(lbca1 == [-1])
39    integer, parameter :: ubca1(*) = ubound(ca)
40    logical, parameter :: test_ubca1 = all(ubca1 == [1])
41    integer, parameter :: lbca2(*) = lbound(ca(:)(1:1))
42    logical, parameter :: test_lbca2 = all(lbca2 == [1])
43    integer, parameter :: ubca2(*) = ubound(ca(:)(1:1))
44    logical, parameter :: test_ubca2 = all(ubca2 == [3])
45    integer, parameter :: lbfoo(*) = lbound(foo())
46    logical, parameter :: test_lbfoo = all(lbfoo == [1,1])
47    integer, parameter :: ubfoo(*) = ubound(foo())
48    logical, parameter :: test_ubfoo = all(ubfoo == [2,3])
49  end subroutine
50  subroutine test2
51    real :: a(2:3,4:6)
52    associate (b => a)
53      block
54        integer, parameter :: lbb(*) = lbound(b)
55        logical, parameter :: test_lbb = all(lbb == [2,4])
56        integer, parameter :: ubb(*) = ubound(b)
57        logical, parameter :: test_ubb = all(ubb == [3,6])
58      end block
59    end associate
60    associate (b => a + 0)
61      block
62        integer, parameter :: lbb(*) = lbound(b)
63        logical, parameter :: test_lbb = all(lbb == [1,1])
64        integer, parameter :: ubb(*) = ubound(b)
65        logical, parameter :: test_ubb = all(ubb == [2,3])
66      end block
67    end associate
68  end subroutine
69end
70