218 lines · plain
1! RUN: not %flang_fc1 %s 2>&1 | FileCheck %s2! Check errors found in folding3! TODO: test others emitted from flang/lib/Evaluate4module m5 type t6 real x7 end type t8 contains9 subroutine s1(a,b,c,d)10 real :: a(*), b(:), c(..), d11 !CHECK: error: DIM=1 dimension is out of range for rank-1 assumed-size array12 integer :: ub1(ubound(a,1))13 !CHECK-NOT: error: DIM=1 dimension is out of range for rank-1 assumed-size array14 integer :: lb1(lbound(a,1))15 !CHECK: error: DIM=0 dimension must be positive16 integer :: ub2(ubound(a,0))17 !CHECK: error: DIM=2 dimension is out of range for rank-1 array18 integer :: ub3(ubound(a,2))19 !CHECK: error: DIM=0 dimension must be positive20 integer :: lb2(lbound(b,0))21 !CHECK: error: DIM=2 dimension is out of range for rank-1 array22 integer :: lb3(lbound(b,2))23 !CHECK: error: DIM=0 dimension must be positive24 integer :: lb4(lbound(c,0))25 !CHECK: error: DIM=666 dimension is too large for any array (maximum rank 15)26 integer :: lb5(lbound(c,666))27 !CHECK: error: 'array=' argument has unacceptable rank 028 integer :: lb6(lbound(d,1))29 !CHECK: error: 'array=' argument has unacceptable rank 030 integer :: ub4(ubound(d,1))31 end subroutine32 subroutine s233 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 CSHIFT36 x = cshift(array, [1, 2], dim=0)37 !CHECK: error: Invalid 'shift=' argument in CSHIFT: extent on dimension 1 is 2 but must be 338 x = cshift(array, [1, 2], dim=1)39 end subroutine40 subroutine s341 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array))42 integer :: x(2, 3)43 !CHECK: error: Invalid 'dim=' argument (0) in EOSHIFT44 x = eoshift(array, [1, 2], dim=0)45 !CHECK: error: Invalid 'shift=' argument in EOSHIFT: extent on dimension 1 is 2 but must be 346 x = eoshift(array, [1, 2], dim=1)47 !CHECK: error: Invalid 'boundary=' argument in EOSHIFT: extent on dimension 1 is 3 but must be 248 x = eoshift(array, 1, [0, 0, 0], 2)49 end subroutine50 subroutine s451 integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array))52 logical, parameter :: mask(*,*) = reshape([(.true., j=1,3),(.false., j=1,3)], shape(array))53 integer :: x(3)54 !CHECK: error: Invalid 'vector=' argument in PACK: the 'mask=' argument has 3 true elements, but the vector has only 2 elements55 x = pack(array, mask, [0,0])56 x = pack(spread(array, x(1), x(2)), .true.) ! regression check, once crashed57 end subroutine58 subroutine s559 logical, parameter :: mask(2,3) = reshape([.false., .true., .true., .false., .false., .true.], shape(mask))60 integer, parameter :: field(3,2) = reshape([(-j,j=1,6)], shape(field))61 integer :: x(2,3)62 !CHECK: error: Invalid 'vector=' argument in UNPACK: the 'mask=' argument has 3 true elements, but the vector has only 2 elements63 x = unpack([1,2], mask, 0)64 end subroutine65 subroutine s666 !CHECK: error: POS=-1 out of range for BTEST67 logical, parameter :: bad1 = btest(0, -1)68 !CHECK: error: POS=32 out of range for BTEST69 logical, parameter :: bad2 = btest(0, 32)70 !CHECK-NOT: error: POS=33 out of range for BTEST71 logical, parameter :: ok1 = btest(0_8, 33)72 !CHECK: error: POS=64 out of range for BTEST73 logical, parameter :: bad4 = btest(0_8, 64)74 end subroutine75 subroutine s776 !CHECK: error: SHIFT=-33 count for ishft is less than -3277 integer, parameter :: bad1 = ishft(1, -33)78 integer, parameter :: ok1 = ishft(1, -32)79 integer, parameter :: ok2 = ishft(1, 32)80 !CHECK: error: SHIFT=33 count for ishft is greater than 3281 integer, parameter :: bad2 = ishft(1, 33)82 !CHECK: error: SHIFT=-65 count for ishft is less than -6483 integer(8), parameter :: bad3 = ishft(1_8, -65)84 integer(8), parameter :: ok3 = ishft(1_8, -64)85 integer(8), parameter :: ok4 = ishft(1_8, 64)86 !CHECK: error: SHIFT=65 count for ishft is greater than 6487 integer(8), parameter :: bad4 = ishft(1_8, 65)88 end subroutine89 subroutine s890 !CHECK: error: SHIFT=-33 count for shiftl is negative91 integer, parameter :: bad1 = shiftl(1, -33)92 !CHECK: error: SHIFT=-32 count for shiftl is negative93 integer, parameter :: bad2 = shiftl(1, -32)94 integer, parameter :: ok1 = shiftl(1, 32)95 !CHECK: error: SHIFT=33 count for shiftl is greater than 3296 integer, parameter :: bad3 = shiftl(1, 33)97 !CHECK: error: SHIFT=-65 count for shiftl is negative98 integer(8), parameter :: bad4 = shiftl(1_8, -65)99 !CHECK: error: SHIFT=-64 count for shiftl is negative100 integer(8), parameter :: bad5 = shiftl(1_8, -64)101 integer(8), parameter :: ok2 = shiftl(1_8, 64)102 !CHECK: error: SHIFT=65 count for shiftl is greater than 64103 integer(8), parameter :: bad6 = shiftl(1_8, 65)104 end subroutine105 subroutine s9106 integer, parameter :: rank15(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) = 1107 !CHECK: error: SOURCE= argument to SPREAD has rank 15 but must have rank less than 15108 integer, parameter :: bad1 = spread(rank15, 1, 1)109 integer, parameter :: matrix(2, 2) = reshape([1, 2, 3, 4], [2, 2])110 !CHECK: error: DIM=0 argument to SPREAD must be between 1 and 3111 integer, parameter :: bad2 = spread(matrix, 0, 1)112 !CHECK: error: DIM=4 argument to SPREAD must be between 1 and 3113 integer, parameter :: bad3 = spread(matrix, 4, 1)114 end subroutine115 subroutine s10116 !CHECK: warning: CHAR(I=-1) is out of range for CHARACTER(KIND=1)117 character(kind=1), parameter :: badc11 = char(-1,kind=1)118 !CHECK: warning: ACHAR(I=-1) is out of range for CHARACTER(KIND=1)119 character(kind=1), parameter :: bada11 = achar(-1,kind=1)120 !CHECK: warning: CHAR(I=-1) is out of range for CHARACTER(KIND=2)121 character(kind=2), parameter :: badc21 = char(-1,kind=2)122 !CHECK: warning: ACHAR(I=-1) is out of range for CHARACTER(KIND=2)123 character(kind=2), parameter :: bada21 = achar(-1,kind=2)124 !CHECK: warning: CHAR(I=-1) is out of range for CHARACTER(KIND=4)125 character(kind=4), parameter :: badc41 = char(-1,kind=4)126 !CHECK: warning: ACHAR(I=-1) is out of range for CHARACTER(KIND=4)127 character(kind=4), parameter :: bada41 = achar(-1,kind=4)128 !CHECK: warning: CHAR(I=256) is out of range for CHARACTER(KIND=1)129 character(kind=1), parameter :: badc12 = char(256,kind=1)130 !CHECK: warning: ACHAR(I=256) is out of range for CHARACTER(KIND=1)131 character(kind=1), parameter :: bada12 = achar(256,kind=1)132 !CHECK: warning: CHAR(I=65536) is out of range for CHARACTER(KIND=2)133 character(kind=2), parameter :: badc22 = char(65536,kind=2)134 !CHECK: warning: ACHAR(I=65536) is out of range for CHARACTER(KIND=2)135 character(kind=2), parameter :: bada22 = achar(65536,kind=2)136 !CHECK: warning: CHAR(I=4294967296) is out of range for CHARACTER(KIND=4)137 character(kind=4), parameter :: badc42 = char(4294967296_8,kind=4)138 !CHECK: warning: ACHAR(I=4294967296) is out of range for CHARACTER(KIND=4)139 character(kind=4), parameter :: bada42 = achar(4294967296_8,kind=4)140 end subroutine141 subroutine s11142 character(:), allocatable :: x1143 !CHECK: error: Invalid specification expression: non-constant inquiry function 'len' not allowed for local object144 character(len(x1)) :: x2145 real, allocatable :: x3(:)146 !CHECK: error: Invalid specification expression: non-constant descriptor inquiry not allowed for local object147 real :: x4(size(x3))148 end149 subroutine s12(x,y)150 class(t), intent(in) :: x151 class(*), intent(in) :: y152 !CHECK: error: Must be a constant value153 integer, parameter :: bad1 = storage_size(x)154 !CHECK: error: Must be a constant value155 integer, parameter :: bad2 = storage_size(y)156 end subroutine157 subroutine s13158 !CHECK: portability: Result of REPEAT() is too large to compute at compilation time (1.1259e+15 characters)159 print *, repeat(repeat(' ', 2**20), 2**30)160 !CHECK: error: NCOPIES= argument to REPEAT() should be nonnegative, but is -666161 print *, repeat(' ', -666)162 end subroutine163 subroutine s14(n)164 integer, intent(in) :: n165 !CHECK: error: bit position for IBITS(POS=-1) is negative166 print *, ibits(0, -1, n)167 !CHECK: error: bit length for IBITS(LEN=-1) is negative168 print *, ibits(0, n, -1)169 !CHECK: error: IBITS() must have POS+LEN (>=33) no greater than 32170 print *, ibits(0, n, 33)171 !CHECK: error: IBITS() must have POS+LEN (>=33) no greater than 32172 print *, ibits(0, 33, n)173 end174 subroutine s15175 use ieee_arithmetic, only: ieee_flag_type, ieee_underflow, ieee_support_flag176 type(ieee_flag_type) :: f1 = ieee_underflow, f2177 !CHECK: portability: specification expression refers to local object 'f1' (initialized and saved)178 integer ok(merge(kind(1),-1,ieee_support_flag(f1, x)))179 !CHECK: error: Invalid specification expression: reference to local entity 'f2'180 integer bad(merge(kind(1),-1,ieee_support_flag(f2, x)))181 end182 subroutine warnings183 use ieee_arithmetic, only: ieee_scalb184 real, parameter :: ok1 = scale(0.0, 99999) ! 0.0185 real, parameter :: ok2 = scale(1.0, -99999) ! 0.0186 !CHECK: SCALE/IEEE_SCALB intrinsic folding overflow187 real, parameter :: bad1 = scale(1.0, 99999)188 !CHECK: SCALE/IEEE_SCALB intrinsic folding overflow189 real, parameter :: bad1a = ieee_scalb(1.0, 99999)190 !CHECK: complex ABS intrinsic folding overflow191 real, parameter :: bad2 = abs(cmplx(huge(0.),huge(0.)))192 !CHECK: warning: DIM intrinsic folding overflow193 real, parameter :: bad3 = dim(huge(1.),-.5*huge(1.))194 !CHECK: warning: DIM intrinsic folding overflow195 integer, parameter :: bad4 = dim(huge(1),-1)196 !CHECK: warning: HYPOT intrinsic folding overflow197 real, parameter :: bad5 = hypot(huge(0.), huge(0.))198 !CHECK: warning: SUM() of INTEGER(4) data overflowed199 integer, parameter :: bad6 = sum([huge(1),huge(1)])200 !CHECK: warning: SUM() of REAL(4) data overflowed201 real, parameter :: bad7 = sum([huge(1.),huge(1.)])202 !CHECK: warning: SUM() of COMPLEX(4) data overflowed203 complex, parameter :: bad8 = sum([(huge(1.),0.),(huge(1.),0.)])204 !CHECK: warning: PRODUCT() of INTEGER(4) data overflowed205 integer, parameter :: bad9 = product([huge(1),huge(1)])206 !CHECK: warning: PRODUCT() of REAL(4) data overflowed207 real, parameter :: bad10 = product([huge(1.),huge(1.)])208 !CHECK: warning: PRODUCT() of COMPLEX(4) data overflowed209 complex, parameter :: bad11 = product([(huge(1.),0.),(huge(1.),0.)])210 !CHECK: warning: conversion of 111111111111111111111_16 to INTEGER(8) overflowed; result is 430646668853801415211 integer(8), parameter :: bad12 = int(111111111111111111111, 8)212 !CHECK: warning: overflow on REAL(8) to REAL(4) conversion213 x = 1.D40214 !CHECK-NOT: warning: invalid argument215 if (.not. isnan(real(z'ffffffffffffffff',8))) stop216 end subroutine217end module218