-check does not check

-check does not check

The following program should create a run-time error, but it does not.
Instead, it behaves as if 1:n = 1:m

program bug
implicit none
real(8) :: a(20)=1,b(20)=2
integer :: n=10,m=20
b(1:m)=b(1:m)+a(1:n)
print *,b
end program bug

The final result is:
3.00000000000000 3.00000000000000 3.00000000000000
3.00000000000000 3.00000000000000 3.00000000000000
3.00000000000000 3.00000000000000 3.00000000000000
3.00000000000000 3.00000000000000 3.00000000000000
3.00000000000000 3.00000000000000 3.00000000000000
3.00000000000000 3.00000000000000 3.00000000000000
3.00000000000000 3.00000000000000

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You're looking for a type of checking we don't yet do - shape checking.

Steve - Intel Developer Support

Steve,
Your answer is extremely unsatisfying, and contrary to what your manual says

The manual states that "check bounds", which is part of "check all":

"Generates code to perform run-time checks on array subscript and character
substring expressions. An error is reported if the expression is outside
the dimension of the array or the length of the string.
For array bounds, each individual dimension is checked. Array bounds checking
is not performed for arrays that are dummy arguments in which the last
dimension bound is specified as * or when both upper and lower dimensions
are 1.
Once the program is debugged, omit this option to reduce executable program
size and slightly improve run-time performance."

I was lucky: In my actual program I was stopped in the correct place dividing by zero.
Had there been another nonzero value, I could have believed that the program ran correctly.
Fortran is mainly used for numerical computations, which in many cases are very difficult to debug. This is a typical, hard to debug, error.

The least Intel can do is add a clarifying statement to the manual.

Best Reply

Hello,

you're absolutely right. Specifying "-check bounds" should detect the case you provided.
I've created a defect ticket ([edit: combined feature request with other existing ticket] DPD200178659 DPD200022151) for this case and coming back to you once we know when this is going to be fixed.

Best regards,

Georg Zitzlsberger

Although I agree in a broad sense with your complaint, may I point out that, strictly speaking, there is no array bound violation here. Both arrays have upper bound equal to 20. Nowhere is this bound exceeded. Therefore, the section of the manual that you quoted is not illuminating.

The error in the program is different from a subscript overrun. It is that you have an expression with two parts, which are not in shape conformance; nor does the special case of Array Op Scalar, in which the scalar is broadcast to an array of the same shape as the first operand and the operation then performed, apply.

You are right, if the "array" mentioned in the documentation is the full array.
However, people, like myself, may also think that the "array" is the
array segment in the statement, i.e. a(1:n), because this is what really matters to us.
Therefore, for us the documentation is misleading.
Yossi.

Yossi,

I'm sorry that you did not like my answer, and to be honest, I don't either, as I have requested that shape checking be added to the compiler. But the answer is correct. Bounds checking looks at places where your code indexes into arrays. None of the array references you have contain bounds errors. But the compiler then is being asked to add a 10-element array to a 20-element array. The Fortran standard says this is not allowed, but it is because the shapes of the arrays don't match. The compiler assumes they do and picks one or the other array size for its computations, leading to incorrect results.

I will add your example and request to the existing request to add this feature.

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today