Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
19 Views

CFI_address strange behaviour

Hi all!

CFI_address IMHO correctly returns the address for the element designated by the subscript array with the index running between dim[0].lower_bound and dim[0].extent + dim[0].lower_bound - 1 (inclusive).

But if the index is outside the range 0 to dim[0].extent the address returned will be NULL.

If it is inside that range it will always return a correctly calculated, but sometimes outside of bounds, address.

This is a clear bug or am I missing something?

Thank you very much.

Best regards,

José Rui

0 Kudos
2 Replies
Highlighted
Black Belt Retired Employee
19 Views

The standard says: "The value of subscripts shall be within the bounds of dimension i specified by the dim member of the C descriptor except for the last dimension of a C descriptor for an assumed-size array." In the case where the value is outside the bounds, the standard does not specify the behavior and thus anything is possible.

I wasn't able to compile your C code as MSVC didn't like the line:

void addr_c(const CFI_cdesc_t *restrict auxp){

This includes C syntax I am unfamiliar with so I'm not sure what the issue is.

I wrote the implementation of CFI_address but it was long enough ago that I don't remember the details there. I note that the standard also says, "For the C descriptor of an assumed-size array, the value of the subscript for the last dimension shall not be less than the lower bound, and the subscript order value specified by the subscripts shall not exceed the size of the array.", so I might have added an extent check and just returned NULL if the extent was exceeded. I agree that it would be better if it returned NULL for an out-of-bounds request, but if it is properly returning the address of elements within the bounds, even when the Fortran bounds are -3:3, I can't get too worked up about it. 

There may still be a bug, though, if it is relying on extent too much. For example, a Fortran array 10:11) should should allow a C index of 10, even though the extent is 2. I'll run some tests.

0 Kudos
Highlighted
Black Belt Retired Employee
19 Views

Ok, I figured out how to run your code and see I misunderstood your explanation. I agree there is a bug - CFI_address is not properly interpreting the subscript argument based on the array bounds. I'm reasonably certain this worked in 2015, but it might be that the tests were too simplistic. Please report this to Intel.

0 Kudos