Fortran passes arrays with descriptors for non-contiguous TARGET dummies
Fortran now uses descriptors for non-contiguous array actual arguments passed to TARGET or POINTER dummies.
A fix for Fortran addresses issues with array actual arguments that have non-contiguous elements when passed to TARGET or POINTER dummy arguments. Previously, these were incorrectly copied, leading to stale pointers. The compiler now passes a descriptor for such arrays, ensuring correct pointer association and only copying data if necessary.
In Details
When an actual array argument has elements spaced by more than their size (e.g., a CLASS array or derived-type component), passing it to a TARGET or POINTER dummy previously caused incorrect copy-in/out, invalidating dummy pointers. This change ensures such arguments are passed with a descriptor that correctly represents their span and element type, addressing PR53800.
- TARGET dummy
- In Fortran, a dummy argument that is declared with the
TARGETattribute, indicating it can be the target of aPOINTER. - POINTER dummy
- In Fortran, a dummy argument declared as a
POINTER. It can be associated with aTARGETor anotherPOINTER. - descriptor
- A data structure that describes an array, typically containing its base address, element type, size, and shape (e.g., bounds and strides). Fortran uses descriptors to handle arrays with complex layouts.
- stale pointers
- Pointers that reference memory locations that are no longer valid or have been reallocated for different data, leading to undefined behavior.
- host association
- A Fortran mechanism where contained procedures can access variables from their containing procedures (hosts).