Fortran: Fix pointer function result span indexing for function results
GFortran now correctly handles the span of pointer function results, ensuring correct temporary indexing and subreferencing for derived-type components and com…
This commit addresses an issue in GFortran where pointer function results with spans larger than element sizes were incorrectly handled. Callers often ignored this span, leading to incorrect indexing of temporary results. The patch ensures that temporary results are marked with GFC_DECL_PTR_ARRAY_P, associate names and pointers are flagged as subreference arrays, and actual arguments are passed correctly, including making packed copies when the span differs from the element size. This resolves PR127731.
In Details
This patch for GFortran's Fortran front-end (in expr.cc, resolve.cc, trans-expr.cc) correctly indexes pointer function results by their span, addressing PR127731. Previously, temporaries created for such results, which could have a span larger than the element size (e.g., pointing to a derived-type component or complex part), were indexed by element size. The fix introduces pointer_array_result_p and pointer_result_var helper functions, marks result temporaries with GFC_DECL_PTR_ARRAY_P, sets subref_array_pointer on associated names and pointer objects, and uses `gfc_conv_subref…
- Pointer array function
- A function in Fortran that returns a pointer to an array or an array of pointers. The span of the returned array can be larger than the element size.
- Span
- In the context of Fortran pointers, the span refers to the memory range occupied by the data being pointed to, which can be larger than the size of a single element if pointing to a component or a slice.
- Subreference array pointer
- A pointer that refers to a part of another array or data structure, where the pointer itself carries information about its offset and extent within the larger structure.
- Derived-type
- A user-defined data type in Fortran that can aggregate components of various data types.
- GFC_DECL_PTR_ARRAY_P
- A flag or marker used internally by the GFortran compiler to indicate that a declared variable or temporary is a pointer to an array, with its span information being relevant.