RISC-V: Refactor Dynamic LMUL codes
[official-gcc.git] / gcc / testsuite / gfortran.dg / string_length_1.f90
blob42deb08dffea45ab912bf2f3c3914bba8044a02d
1 ! { dg-do run }
2 ! Testcase for PR 31203
3 ! We used to create strings with negative length
4 subroutine foo(i)
5 integer :: i
6 character(len=i) :: s(2)
7 if (len(s) < 0) STOP 1
8 if (len(s) /= max(i,0)) STOP 2
9 end
11 function gee(i)
12 integer, intent(in) :: i
13 character(len=i) :: gee
15 gee = ""
16 end function gee
18 subroutine s1(i,j)
19 character(len=i-j) :: a
20 if (len(a) < 0) STOP 1
21 end subroutine
23 program test
24 interface
25 function gee(i)
26 integer, intent(in) :: i
27 character(len=i) :: gee
28 end function gee
29 end interface
31 call foo(2)
32 call foo(-1)
33 call s1(1,2)
34 call s1(-1,-8)
35 call s1(-8,-1)
37 if (len(gee(2)) /= 2) STOP 3
38 if (len(gee(-5)) /= 0) STOP 4
39 if (len(gee(intfunc(3))) /= max(intfunc(3),0)) STOP 5
40 if (len(gee(intfunc(2))) /= max(intfunc(2),0)) STOP 6
42 if (len(bar(2)) /= 2) STOP 7
43 if (len(bar(-5)) /= 0) STOP 8
44 if (len(bar(intfunc(3))) /= max(intfunc(3),0)) STOP 9
45 if (len(bar(intfunc(2))) /= max(intfunc(2),0)) STOP 10
47 if (cow(bar(2)) /= 2) STOP 11
48 if (cow(bar(-5)) /= 0) STOP 12
49 if (cow(bar(intfunc(3))) /= max(intfunc(3),0)) STOP 13
50 if (cow(bar(intfunc(2))) /= max(intfunc(2),0)) STOP 14
52 contains
54 function bar(i)
55 integer, intent(in) :: i
56 character(len=i) :: bar
58 bar = ""
59 end function bar
61 function cow(c)
62 character(len=*), intent(in) :: c
63 integer :: cow
64 cow = len(c)
65 end function cow
67 pure function intfunc(i)
68 integer, intent(in) :: i
69 integer :: intfunc
71 intfunc = 2*i-5
72 end function intfunc
74 end program test