[WebAssembly] Fix asan issue from https://reviews.llvm.org/D121349
[llvm-project.git] / flang / test / Evaluate / errors01.f90
blob50705be17a3902b820f148667e430a3ee721b872
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 contains
6 subroutine s1(a,b)
7 real :: a(*), b(:)
8 !CHECK: error: DIM=1 dimension is out of range for rank-1 assumed-size array
9 integer :: ub1(ubound(a,1))
10 !CHECK-NOT: error: DIM=1 dimension is out of range for rank-1 assumed-size array
11 integer :: lb1(lbound(a,1))
12 !CHECK: error: DIM=0 dimension is out of range for rank-1 array
13 integer :: ub2(ubound(a,0))
14 !CHECK: error: DIM=2 dimension is out of range for rank-1 array
15 integer :: ub3(ubound(a,2))
16 !CHECK: error: DIM=0 dimension is out of range for rank-1 array
17 integer :: lb2(lbound(b,0))
18 !CHECK: error: DIM=2 dimension is out of range for rank-1 array
19 integer :: lb3(lbound(b,2))
20 end subroutine
21 subroutine s2
22 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array))
23 integer :: x(2, 3)
24 !CHECK: error: Invalid 'dim=' argument (0) in CSHIFT
25 x = cshift(array, [1, 2], dim=0)
26 !CHECK: error: Invalid 'shift=' argument in CSHIFT: extent on dimension 1 is 2 but must be 3
27 x = cshift(array, [1, 2], dim=1)
28 end subroutine
29 subroutine s3
30 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array))
31 integer :: x(2, 3)
32 !CHECK: error: Invalid 'dim=' argument (0) in EOSHIFT
33 x = eoshift(array, [1, 2], dim=0)
34 !CHECK: error: Invalid 'shift=' argument in EOSHIFT: extent on dimension 1 is 2 but must be 3
35 x = eoshift(array, [1, 2], dim=1)
36 !CHECK: error: Invalid 'boundary=' argument in EOSHIFT: extent on dimension 1 is 3 but must be 2
37 x = eoshift(array, 1, [0, 0, 0], 2)
38 end subroutine
39 subroutine s4
40 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array))
41 logical, parameter :: mask(*,*) = reshape([(.true., j=1,3),(.false., j=1,3)], shape(array))
42 integer :: x(3)
43 !CHECK: error: Invalid 'vector=' argument in PACK: the 'mask=' argument has 3 true elements, but the vector has only 2 elements
44 x = pack(array, mask, [0,0])
45 end subroutine
46 subroutine s5
47 logical, parameter :: mask(2,3) = reshape([.false., .true., .true., .false., .false., .true.], shape(mask))
48 integer, parameter :: field(3,2) = reshape([(-j,j=1,6)], shape(field))
49 integer :: x(2,3)
50 !CHECK: error: Invalid 'vector=' argument in UNPACK: the 'mask=' argument has 3 true elements, but the vector has only 2 elements
51 x = unpack([1,2], mask, 0)
52 end subroutine
53 subroutine s6
54 !CHECK: error: POS=-1 out of range for BTEST
55 logical, parameter :: bad1 = btest(0, -1)
56 !CHECK: error: POS=32 out of range for BTEST
57 logical, parameter :: bad2 = btest(0, 32)
58 !CHECK-NOT: error: POS=33 out of range for BTEST
59 logical, parameter :: ok1 = btest(0_8, 33)
60 !CHECK: error: POS=64 out of range for BTEST
61 logical, parameter :: bad4 = btest(0_8, 64)
62 end subroutine
63 subroutine s7
64 !CHECK: error: SHIFT=-33 count for ishft is less than -32
65 integer, parameter :: bad1 = ishft(1, -33)
66 integer, parameter :: ok1 = ishft(1, -32)
67 integer, parameter :: ok2 = ishft(1, 32)
68 !CHECK: error: SHIFT=33 count for ishft is greater than 32
69 integer, parameter :: bad2 = ishft(1, 33)
70 !CHECK: error: SHIFT=-65 count for ishft is less than -64
71 integer(8), parameter :: bad3 = ishft(1_8, -65)
72 integer(8), parameter :: ok3 = ishft(1_8, -64)
73 integer(8), parameter :: ok4 = ishft(1_8, 64)
74 !CHECK: error: SHIFT=65 count for ishft is greater than 64
75 integer(8), parameter :: bad4 = ishft(1_8, 65)
76 end subroutine
77 subroutine s8
78 !CHECK: error: SHIFT=-33 count for shiftl is negative
79 integer, parameter :: bad1 = shiftl(1, -33)
80 !CHECK: error: SHIFT=-32 count for shiftl is negative
81 integer, parameter :: bad2 = shiftl(1, -32)
82 integer, parameter :: ok1 = shiftl(1, 32)
83 !CHECK: error: SHIFT=33 count for shiftl is greater than 32
84 integer, parameter :: bad3 = shiftl(1, 33)
85 !CHECK: error: SHIFT=-65 count for shiftl is negative
86 integer(8), parameter :: bad4 = shiftl(1_8, -65)
87 !CHECK: error: SHIFT=-64 count for shiftl is negative
88 integer(8), parameter :: bad5 = shiftl(1_8, -64)
89 integer(8), parameter :: ok2 = shiftl(1_8, 64)
90 !CHECK: error: SHIFT=65 count for shiftl is greater than 64
91 integer(8), parameter :: bad6 = shiftl(1_8, 65)
92 end subroutine
93 subroutine s9
94 integer, parameter :: rank15(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) = 1
95 !CHECK: error: SOURCE= argument to SPREAD has rank 15 but must have rank less than 15
96 integer, parameter :: bad1 = spread(rank15, 1, 1)
97 integer, parameter :: matrix(2, 2) = reshape([1, 2, 3, 4], [2, 2])
98 !CHECK: error: DIM=0 argument to SPREAD must be between 1 and 3
99 integer, parameter :: bad2 = spread(matrix, 0, 1)
100 !CHECK: error: DIM=4 argument to SPREAD must be between 1 and 3
101 integer, parameter :: bad3 = spread(matrix, 4, 1)
102 end subroutine
103 subroutine warnings
104 real, parameter :: ok1 = scale(0.0, 99999) ! 0.0
105 real, parameter :: ok2 = scale(1.0, -99999) ! 0.0
106 !CHECK: SCALE intrinsic folding overflow
107 real, parameter :: bad1 = scale(1.0, 99999)
108 end subroutine
109 end module