Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29276 Discussions

Compiler 8.0, bounds checking and lazy if evaluation

driemer
Beginner
449 Views
I have found a problem in the 8.0 version of the compiler when bounds checking is turned on (-CB). Using the following code:
program lazyif
real(8), allocatable :: dumArray(:)
integer nSize
nSize = 0
if(nSize .gt. 0) then
allocate (dumArray(nSize))
dumArray = 1
endif
if(nSize.gt.0 .and. dumArray(1) .ne. 0) then
write(*, '(A)') 'dumArray first element is not zero'
else
write(*, '(A)') 'lazy if succeeded'
endif
end
If this code is compiled without -CB it works correctly and prints out 'lazy if succeeded'. If it is compiled with -CB (ifort -CB lazyif.for), a runtime error occurs
forrtl: severe (408): fort: (2): Subscript #1 of the array DUMARRAY has value 1 which is greater than the upper bound of -1
Now, on the other hand, if the code is compiled with CVF 6.6B using
df -check:bounds lazyif.for
it works correctly and prints 'lazy if succeeded'. I do not believe we had this problem with version 7.1
0 Kudos
1 Reply
Steven_L_Intel1
Employee
449 Views
You are relying on an optimization choice, and not a feature. Your code is incorrect - Fortran does not have "lazy if evaluation". Fix the code by using nested IF.
0 Kudos
Reply