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 4module m 5 type t 6 real x 7 end type t 8 contains 9 subroutine s1(a,b,c) 10 real :: a(*), b(:), c(..) 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 must be positive 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 must be positive 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 !CHECK: error: DIM=0 dimension must be positive 24 integer :: lb4(lbound(c,0)) 25 !CHECK: error: DIM=666 dimension is too large for any array (maximum rank 15) 26 integer :: lb4(lbound(c,666)) 27 end subroutine 28 subroutine s2 29 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array)) 30 integer :: x(2, 3) 31 !CHECK: error: Invalid 'dim=' argument (0) in CSHIFT 32 x = cshift(array, [1, 2], dim=0) 33 !CHECK: error: Invalid 'shift=' argument in CSHIFT: extent on dimension 1 is 2 but must be 3 34 x = cshift(array, [1, 2], dim=1) 35 end subroutine 36 subroutine s3 37 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array)) 38 integer :: x(2, 3) 39 !CHECK: error: Invalid 'dim=' argument (0) in EOSHIFT 40 x = eoshift(array, [1, 2], dim=0) 41 !CHECK: error: Invalid 'shift=' argument in EOSHIFT: extent on dimension 1 is 2 but must be 3 42 x = eoshift(array, [1, 2], dim=1) 43 !CHECK: error: Invalid 'boundary=' argument in EOSHIFT: extent on dimension 1 is 3 but must be 2 44 x = eoshift(array, 1, [0, 0, 0], 2) 45 end subroutine 46 subroutine s4 47 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array)) 48 logical, parameter :: mask(*,*) = reshape([(.true., j=1,3),(.false., j=1,3)], shape(array)) 49 integer :: x(3) 50 !CHECK: error: Invalid 'vector=' argument in PACK: the 'mask=' argument has 3 true elements, but the vector has only 2 elements 51 x = pack(array, mask, [0,0]) 52 x = pack(spread(array, x(1), x(2)), .true.) ! regression check, once crashed 53 end subroutine 54 subroutine s5 55 logical, parameter :: mask(2,3) = reshape([.false., .true., .true., .false., .false., .true.], shape(mask)) 56 integer, parameter :: field(3,2) = reshape([(-j,j=1,6)], shape(field)) 57 integer :: x(2,3) 58 !CHECK: error: Invalid 'vector=' argument in UNPACK: the 'mask=' argument has 3 true elements, but the vector has only 2 elements 59 x = unpack([1,2], mask, 0) 60 end subroutine 61 subroutine s6 62 !CHECK: error: POS=-1 out of range for BTEST 63 logical, parameter :: bad1 = btest(0, -1) 64 !CHECK: error: POS=32 out of range for BTEST 65 logical, parameter :: bad2 = btest(0, 32) 66 !CHECK-NOT: error: POS=33 out of range for BTEST 67 logical, parameter :: ok1 = btest(0_8, 33) 68 !CHECK: error: POS=64 out of range for BTEST 69 logical, parameter :: bad4 = btest(0_8, 64) 70 end subroutine 71 subroutine s7 72 !CHECK: error: SHIFT=-33 count for ishft is less than -32 73 integer, parameter :: bad1 = ishft(1, -33) 74 integer, parameter :: ok1 = ishft(1, -32) 75 integer, parameter :: ok2 = ishft(1, 32) 76 !CHECK: error: SHIFT=33 count for ishft is greater than 32 77 integer, parameter :: bad2 = ishft(1, 33) 78 !CHECK: error: SHIFT=-65 count for ishft is less than -64 79 integer(8), parameter :: bad3 = ishft(1_8, -65) 80 integer(8), parameter :: ok3 = ishft(1_8, -64) 81 integer(8), parameter :: ok4 = ishft(1_8, 64) 82 !CHECK: error: SHIFT=65 count for ishft is greater than 64 83 integer(8), parameter :: bad4 = ishft(1_8, 65) 84 end subroutine 85 subroutine s8 86 !CHECK: error: SHIFT=-33 count for shiftl is negative 87 integer, parameter :: bad1 = shiftl(1, -33) 88 !CHECK: error: SHIFT=-32 count for shiftl is negative 89 integer, parameter :: bad2 = shiftl(1, -32) 90 integer, parameter :: ok1 = shiftl(1, 32) 91 !CHECK: error: SHIFT=33 count for shiftl is greater than 32 92 integer, parameter :: bad3 = shiftl(1, 33) 93 !CHECK: error: SHIFT=-65 count for shiftl is negative 94 integer(8), parameter :: bad4 = shiftl(1_8, -65) 95 !CHECK: error: SHIFT=-64 count for shiftl is negative 96 integer(8), parameter :: bad5 = shiftl(1_8, -64) 97 integer(8), parameter :: ok2 = shiftl(1_8, 64) 98 !CHECK: error: SHIFT=65 count for shiftl is greater than 64 99 integer(8), parameter :: bad6 = shiftl(1_8, 65) 100 end subroutine 101 subroutine s9 102 integer, parameter :: rank15(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) = 1 103 !CHECK: error: SOURCE= argument to SPREAD has rank 15 but must have rank less than 15 104 integer, parameter :: bad1 = spread(rank15, 1, 1) 105 integer, parameter :: matrix(2, 2) = reshape([1, 2, 3, 4], [2, 2]) 106 !CHECK: error: DIM=0 argument to SPREAD must be between 1 and 3 107 integer, parameter :: bad2 = spread(matrix, 0, 1) 108 !CHECK: error: DIM=4 argument to SPREAD must be between 1 and 3 109 integer, parameter :: bad3 = spread(matrix, 4, 1) 110 end subroutine 111 subroutine s10 112 !CHECK: warning: CHAR(I=-1) is out of range for CHARACTER(KIND=1) 113 character(kind=1), parameter :: badc11 = char(-1,kind=1) 114 !CHECK: warning: ACHAR(I=-1) is out of range for CHARACTER(KIND=1) 115 character(kind=1), parameter :: bada11 = achar(-1,kind=1) 116 !CHECK: warning: CHAR(I=-1) is out of range for CHARACTER(KIND=2) 117 character(kind=2), parameter :: badc21 = char(-1,kind=2) 118 !CHECK: warning: ACHAR(I=-1) is out of range for CHARACTER(KIND=2) 119 character(kind=2), parameter :: bada21 = achar(-1,kind=2) 120 !CHECK: warning: CHAR(I=-1) is out of range for CHARACTER(KIND=4) 121 character(kind=4), parameter :: badc41 = char(-1,kind=4) 122 !CHECK: warning: ACHAR(I=-1) is out of range for CHARACTER(KIND=4) 123 character(kind=4), parameter :: bada41 = achar(-1,kind=4) 124 !CHECK: warning: CHAR(I=256) is out of range for CHARACTER(KIND=1) 125 character(kind=1), parameter :: badc12 = char(256,kind=1) 126 !CHECK: warning: ACHAR(I=256) is out of range for CHARACTER(KIND=1) 127 character(kind=1), parameter :: bada12 = achar(256,kind=1) 128 !CHECK: warning: CHAR(I=65536) is out of range for CHARACTER(KIND=2) 129 character(kind=2), parameter :: badc22 = char(65536,kind=2) 130 !CHECK: warning: ACHAR(I=65536) is out of range for CHARACTER(KIND=2) 131 character(kind=2), parameter :: bada22 = achar(65536,kind=2) 132 !CHECK: warning: CHAR(I=4294967296) is out of range for CHARACTER(KIND=4) 133 character(kind=4), parameter :: badc42 = char(4294967296_8,kind=4) 134 !CHECK: warning: ACHAR(I=4294967296) is out of range for CHARACTER(KIND=4) 135 character(kind=4), parameter :: bada42 = achar(4294967296_8,kind=4) 136 end subroutine 137 subroutine s11 138 character(:), allocatable :: x1 139 !CHECK: error: Invalid specification expression: non-constant inquiry function 'len' not allowed for local object 140 character(len(x1)) :: x2 141 real, allocatable :: x3(:) 142 !CHECK: error: Invalid specification expression: non-constant descriptor inquiry not allowed for local object 143 real :: x4(size(x3)) 144 end 145 subroutine s12(x,y) 146 class(t), intent(in) :: x 147 class(*), intent(in) :: y 148 !CHERK: error: Must be a constant value 149 integer, parameter :: bad1 = storage_size(x) 150 !CHERK: error: Must be a constant value 151 integer, parameter :: bad2 = storage_size(y) 152 end subroutine 153 subroutine s13 154 !CHECK: portability: Result of REPEAT() is too large to compute at compilation time (1.1259e+15 characters) 155 print *, repeat(repeat(' ', 2**20), 2**30) 156 !CHECK: error: NCOPIES= argument to REPEAT() should be nonnegative, but is -666 157 print *, repeat(' ', -666) 158 end subroutine 159 subroutine s14(n) 160 integer, intent(in) :: n 161 !CHECK: error: bit position for IBITS(POS=-1) is negative 162 print *, ibits(0, -1, n) 163 !CHECK: error: bit length for IBITS(LEN=-1) is negative 164 print *, ibits(0, n, -1) 165 !CHECK: error: IBITS() must have POS+LEN (>=33) no greater than 32 166 print *, ibits(0, n, 33) 167 !CHECK: error: IBITS() must have POS+LEN (>=33) no greater than 32 168 print *, ibits(0, 33, n) 169 end 170 subroutine warnings 171 use ieee_arithmetic, only: ieee_scalb 172 real, parameter :: ok1 = scale(0.0, 99999) ! 0.0 173 real, parameter :: ok2 = scale(1.0, -99999) ! 0.0 174 !CHECK: SCALE/IEEE_SCALB intrinsic folding overflow 175 real, parameter :: bad1 = scale(1.0, 99999) 176 !CHECK: SCALE/IEEE_SCALB intrinsic folding overflow 177 real, parameter :: bad1a = ieee_scalb(1.0, 99999) 178 !CHECK: complex ABS intrinsic folding overflow 179 real, parameter :: bad2 = abs(cmplx(huge(0.),huge(0.))) 180 !CHECK: warning: DIM intrinsic folding overflow 181 real, parameter :: bad3 = dim(huge(1.),-.5*huge(1.)) 182 !CHECK: warning: DIM intrinsic folding overflow 183 integer, parameter :: bad4 = dim(huge(1),-1) 184 !CHECK: warning: HYPOT intrinsic folding overflow 185 real, parameter :: bad5 = hypot(huge(0.), huge(0.)) 186 !CHECK: warning: SUM() of INTEGER(4) data overflowed 187 integer, parameter :: bad6 = sum([huge(1),huge(1)]) 188 !CHECK: warning: SUM() of REAL(4) data overflowed 189 real, parameter :: bad7 = sum([huge(1.),huge(1.)]) 190 !CHECK: warning: SUM() of COMPLEX(4) data overflowed 191 complex, parameter :: bad8 = sum([(huge(1.),0.),(huge(1.),0.)]) 192 !CHECK: warning: PRODUCT() of INTEGER(4) data overflowed 193 integer, parameter :: bad9 = product([huge(1),huge(1)]) 194 !CHECK: warning: PRODUCT() of REAL(4) data overflowed 195 real, parameter :: bad10 = product([huge(1.),huge(1.)]) 196 !CHECK: warning: PRODUCT() of COMPLEX(4) data overflowed 197 complex, parameter :: bad11 = product([(huge(1.),0.),(huge(1.),0.)]) 198 !CHECK: warning: conversion of 111111111111111111111_16 to INTEGER(8) overflowed; result is 430646668853801415 199 integer(8), parameter :: bad12 = int(111111111111111111111, 8) 200 !CHECK: warning: overflow on REAL(8) to REAL(4) conversion 201 x = 1.D40 202 !CHECK-NOT: warning: invalid argument 203 if (.not. isnan(real(z'ffffffffffffffff',8))) stop 204 end subroutine 205end module 206