Fortran uses span indexing for polymorphic target dummies
Fortran's compiler now correctly uses span indexing for polymorphic target dummy arguments, improving array handling.
This change enables span indexing for polymorphic target dummy arguments in Fortran by modifying how array descriptors are handled. Previously, span indexing was limited to non-polymorphic arguments. The compiler now correctly extracts array span information from class containers for polymorphic entities, ensuring consistent array handling. This fixes a bug where span indexing was not correctly applied to polymorphic dummy arrays, enhancing the compiler’s robustness for complex array declarations.
In Details
This change affects the GCC Fortran frontend, specifically the handling of polymorphic dummy arguments with the TARGET attribute. It extends the infrastructure for span indexing, previously added for non-polymorphic arguments, to support polymorphic entities. The core modifications are in gfc_dummy_requires_direct_arg and gfc_get_array_span in symbol.cc and trans-array.cc, respectively. The challenge lies in the differing attribute storage and array specification for polymorphic entities compared to non-polymorphic ones, requiring a more complex update to correctly access the array de…
- span indexing
- A compiler optimization technique in Fortran that allows efficient access to array elements by using information about the array's extents (its 'span'). This can improve performance by enabling more direct memory access and reducing overhead.
- polymorphic
- In Fortran, an entity that can assume different types at runtime. This is typically achieved through class types and derived types that can hold values of different underlying types.
- target dummy argument
- A dummy argument (parameter) in a Fortran procedure that is declared with the TARGET attribute. This attribute indicates that the argument may be the target of a pointer.
- array descriptor
- A data structure that holds metadata about an array, such as its bounds, type, and memory address. The compiler uses array descriptors to manage and access array elements efficiently.
- class container
- In Fortran, a type that can hold values of different derived types, enabling polymorphism. When an object of a class type is passed as an argument, its actual type may vary at runtime.