[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Evaluate / errors01.f90
blob0b86ccb199ccd545ba200c5e816cd1d5766f490a
1 ! RUN: not %flang_fc1 %s 2>&1 | FileCheck %s
2 ! Check errors found in folding
3 ! TODO: test others emitted from flang/lib/Evaluate
4 module m
5 type t
6 real x
7 end type t
8 contains
9 subroutine s1(a,b)
10 real :: a(*), b(:)
11 !CHECK: error: DIM=1 dimension is out of range for rank-1 assumed-size array
12 integer :: ub1(ubound(a,1))
13 !CHECK-NOT: error: DIM=1 dimension is out of range for rank-1 assumed-size array
14 integer :: lb1(lbound(a,1))
15 !CHECK: error: DIM=0 dimension is out of range for rank-1 array
16 integer :: ub2(ubound(a,0))
17 !CHECK: error: DIM=2 dimension is out of range for rank-1 array
18 integer :: ub3(ubound(a,2))
19 !CHECK: error: DIM=0 dimension is out of range for rank-1 array
20 integer :: lb2(lbound(b,0))
21 !CHECK: error: DIM=2 dimension is out of range for rank-1 array
22 integer :: lb3(lbound(b,2))
23 end subroutine
24 subroutine s2
25 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array))
26 integer :: x(2, 3)
27 !CHECK: error: Invalid 'dim=' argument (0) in CSHIFT
28 x = cshift(array, [1, 2], dim=0)
29 !CHECK: error: Invalid 'shift=' argument in CSHIFT: extent on dimension 1 is 2 but must be 3
30 x = cshift(array, [1, 2], dim=1)
31 end subroutine
32 subroutine s3
33 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array))
34 integer :: x(2, 3)
35 !CHECK: error: Invalid 'dim=' argument (0) in EOSHIFT
36 x = eoshift(array, [1, 2], dim=0)
37 !CHECK: error: Invalid 'shift=' argument in EOSHIFT: extent on dimension 1 is 2 but must be 3
38 x = eoshift(array, [1, 2], dim=1)
39 !CHECK: error: Invalid 'boundary=' argument in EOSHIFT: extent on dimension 1 is 3 but must be 2
40 x = eoshift(array, 1, [0, 0, 0], 2)
41 end subroutine
42 subroutine s4
43 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array))
44 logical, parameter :: mask(*,*) = reshape([(.true., j=1,3),(.false., j=1,3)], shape(array))
45 integer :: x(3)
46 !CHECK: error: Invalid 'vector=' argument in PACK: the 'mask=' argument has 3 true elements, but the vector has only 2 elements
47 x = pack(array, mask, [0,0])
48 end subroutine
49 subroutine s5
50 logical, parameter :: mask(2,3) = reshape([.false., .true., .true., .false., .false., .true.], shape(mask))
51 integer, parameter :: field(3,2) = reshape([(-j,j=1,6)], shape(field))
52 integer :: x(2,3)
53 !CHECK: error: Invalid 'vector=' argument in UNPACK: the 'mask=' argument has 3 true elements, but the vector has only 2 elements
54 x = unpack([1,2], mask, 0)
55 end subroutine
56 subroutine s6
57 !CHECK: error: POS=-1 out of range for BTEST
58 logical, parameter :: bad1 = btest(0, -1)
59 !CHECK: error: POS=32 out of range for BTEST
60 logical, parameter :: bad2 = btest(0, 32)
61 !CHECK-NOT: error: POS=33 out of range for BTEST
62 logical, parameter :: ok1 = btest(0_8, 33)
63 !CHECK: error: POS=64 out of range for BTEST
64 logical, parameter :: bad4 = btest(0_8, 64)
65 end subroutine
66 subroutine s7
67 !CHECK: error: SHIFT=-33 count for ishft is less than -32
68 integer, parameter :: bad1 = ishft(1, -33)
69 integer, parameter :: ok1 = ishft(1, -32)
70 integer, parameter :: ok2 = ishft(1, 32)
71 !CHECK: error: SHIFT=33 count for ishft is greater than 32
72 integer, parameter :: bad2 = ishft(1, 33)
73 !CHECK: error: SHIFT=-65 count for ishft is less than -64
74 integer(8), parameter :: bad3 = ishft(1_8, -65)
75 integer(8), parameter :: ok3 = ishft(1_8, -64)
76 integer(8), parameter :: ok4 = ishft(1_8, 64)
77 !CHECK: error: SHIFT=65 count for ishft is greater than 64
78 integer(8), parameter :: bad4 = ishft(1_8, 65)
79 end subroutine
80 subroutine s8
81 !CHECK: error: SHIFT=-33 count for shiftl is negative
82 integer, parameter :: bad1 = shiftl(1, -33)
83 !CHECK: error: SHIFT=-32 count for shiftl is negative
84 integer, parameter :: bad2 = shiftl(1, -32)
85 integer, parameter :: ok1 = shiftl(1, 32)
86 !CHECK: error: SHIFT=33 count for shiftl is greater than 32
87 integer, parameter :: bad3 = shiftl(1, 33)
88 !CHECK: error: SHIFT=-65 count for shiftl is negative
89 integer(8), parameter :: bad4 = shiftl(1_8, -65)
90 !CHECK: error: SHIFT=-64 count for shiftl is negative
91 integer(8), parameter :: bad5 = shiftl(1_8, -64)
92 integer(8), parameter :: ok2 = shiftl(1_8, 64)
93 !CHECK: error: SHIFT=65 count for shiftl is greater than 64
94 integer(8), parameter :: bad6 = shiftl(1_8, 65)
95 end subroutine
96 subroutine s9
97 integer, parameter :: rank15(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) = 1
98 !CHECK: error: SOURCE= argument to SPREAD has rank 15 but must have rank less than 15
99 integer, parameter :: bad1 = spread(rank15, 1, 1)
100 integer, parameter :: matrix(2, 2) = reshape([1, 2, 3, 4], [2, 2])
101 !CHECK: error: DIM=0 argument to SPREAD must be between 1 and 3
102 integer, parameter :: bad2 = spread(matrix, 0, 1)
103 !CHECK: error: DIM=4 argument to SPREAD must be between 1 and 3
104 integer, parameter :: bad3 = spread(matrix, 4, 1)
105 end subroutine
106 subroutine s10
107 !CHECK: warning: CHAR(I=-1) is out of range for CHARACTER(KIND=1)
108 character(kind=1), parameter :: badc11 = char(-1,kind=1)
109 !CHECK: warning: ACHAR(I=-1) is out of range for CHARACTER(KIND=1)
110 character(kind=1), parameter :: bada11 = achar(-1,kind=1)
111 !CHECK: warning: CHAR(I=-1) is out of range for CHARACTER(KIND=2)
112 character(kind=2), parameter :: badc21 = char(-1,kind=2)
113 !CHECK: warning: ACHAR(I=-1) is out of range for CHARACTER(KIND=2)
114 character(kind=2), parameter :: bada21 = achar(-1,kind=2)
115 !CHECK: warning: CHAR(I=-1) is out of range for CHARACTER(KIND=4)
116 character(kind=4), parameter :: badc41 = char(-1,kind=4)
117 !CHECK: warning: ACHAR(I=-1) is out of range for CHARACTER(KIND=4)
118 character(kind=4), parameter :: bada41 = achar(-1,kind=4)
119 !CHECK: warning: CHAR(I=256) is out of range for CHARACTER(KIND=1)
120 character(kind=1), parameter :: badc12 = char(256,kind=1)
121 !CHECK: warning: ACHAR(I=256) is out of range for CHARACTER(KIND=1)
122 character(kind=1), parameter :: bada12 = achar(256,kind=1)
123 !CHECK: warning: CHAR(I=65536) is out of range for CHARACTER(KIND=2)
124 character(kind=2), parameter :: badc22 = char(65536,kind=2)
125 !CHECK: warning: ACHAR(I=65536) is out of range for CHARACTER(KIND=2)
126 character(kind=2), parameter :: bada22 = achar(65536,kind=2)
127 !CHECK: warning: CHAR(I=4294967296) is out of range for CHARACTER(KIND=4)
128 character(kind=4), parameter :: badc42 = char(4294967296_8,kind=4)
129 !CHECK: warning: ACHAR(I=4294967296) is out of range for CHARACTER(KIND=4)
130 character(kind=4), parameter :: bada42 = achar(4294967296_8,kind=4)
131 end subroutine
132 subroutine s11
133 character(:), allocatable :: x1
134 !CHECK: error: Invalid specification expression: non-constant inquiry function 'len' not allowed for local object
135 character(len(x1)) :: x2
136 real, allocatable :: x3(:)
137 !CHECK: error: Invalid specification expression: non-constant descriptor inquiry not allowed for local object
138 real :: x4(size(x3))
140 subroutine s12(x,y)
141 class(t), intent(in) :: x
142 class(*), intent(in) :: y
143 !CHERK: error: Must be a constant value
144 integer, parameter :: bad1 = storage_size(x)
145 !CHERK: error: Must be a constant value
146 integer, parameter :: bad2 = storage_size(y)
147 end subroutine
148 subroutine s13
149 !CHECK: portability: Result of REPEAT() is too large to compute at compilation time (1.1259e+15 characters)
150 print *, repeat(repeat(' ', 2**20), 2**30)
151 !CHECK: error: NCOPIES= argument to REPEAT() should be nonnegative, but is -666
152 print *, repeat(' ', -666)
153 end subroutine
154 subroutine warnings
155 real, parameter :: ok1 = scale(0.0, 99999) ! 0.0
156 real, parameter :: ok2 = scale(1.0, -99999) ! 0.0
157 !CHECK: SCALE intrinsic folding overflow
158 real, parameter :: bad1 = scale(1.0, 99999)
159 !CHECK: complex ABS intrinsic folding overflow
160 real, parameter :: bad2 = abs(cmplx(huge(0.),huge(0.)))
161 !CHECK: warning: DIM intrinsic folding overflow
162 real, parameter :: bad3 = dim(huge(1.),-.5*huge(1.))
163 !CHECK: warning: DIM intrinsic folding overflow
164 integer, parameter :: bad4 = dim(huge(1),-1)
165 !CHECK: warning: overflow on REAL(8) to REAL(4) conversion
166 x = 1.D40
167 end subroutine
168 end module