Make IS_CONTIGUOUS true for assumed-rank scalars [PR126895]
The Fortran intrinsic IS_CONTIGUOUS now correctly returns true for assumed-rank scalars with a zero rank at runtime.
The Fortran intrinsic IS_CONTIGUOUS has been updated to correctly handle assumed-rank scalar arguments. If such an argument has a rank of zero at runtime, IS_CONTIGUOUS will now return true. This corrects a bug where the intrinsic incorrectly returned false due to a missing rank check in its span calculation.
In Details
In gfc_conv_is_contiguous_expr within trans-intrinsic.cc, the handling for assumed-rank variables passed to IS_CONTIGUOUS has been modified. A new condition ensures that if the runtime rank of an assumed-rank scalar is zero, the intrinsic returns true. This rectifies a situation where a previous check comparing the element span against the element size, which was not guarded by a rank check, could lead to a false negative.
- IS_CONTIGUOUS
- A Fortran intrinsic function that returns true if an array is contiguous in memory, and false otherwise. Contiguous arrays can be more efficiently processed by some operations.
- assumed-rank
- A Fortran feature where a procedure argument can accept arrays of any rank. The procedure itself does not know the rank at compile time, only at runtime.
- intrinsic
- A function or subroutine provided by the Fortran language itself, with a standard name and behavior, such as
IS_CONTIGUOUS,ALLOCATABLE,RANK, etc. - scalar
- A single data item, as opposed to an array of data items.