fortran: Fix copy from polymorphic pointer source in ALLOCATE [PR128033]
Fortran ALLOCATE statement now correctly handles polymorphic pointer sources.
A regression in the Fortran ALLOCATE statement that caused incorrect copying from polymorphic pointer sources has been fixed. The issue arose from a temporary fix for another bug, which inadvertently introduced a temporary array that lacked the necessary ‘class container’ information. This caused indexing errors when copying data. This commit reverts the problematic temporary fix and addresses the root cause by correctly identifying and using array references within the source expression, resolving the bug for users with polymorphic pointer arrays.
In Details
This commit resolves PR128033 by correcting the handling of polymorphic pointer array sources in Fortran's ALLOCATE statement. A previous change (r14-9160) introduced automatic parenthesized wrapping of the source expression to create a temporary, which inadvertently broke polymorphic array handling. The generated temporary's array reference missed the 'class container' parent, leading to incorrect array indexing via the non-polymorphic fallback. This patch reverts that temporary solution. It also fixes an assertion failure in gfc_find_array_ref that incorrectly expected single-element re…
- ALLOCATE statement
- A Fortran statement used to dynamically allocate memory for variables, such as pointers or allocatable arrays.
- polymorphic pointer
- In Fortran, a pointer that can point to objects of different, but related, dynamic types. These types are usually organized in an inheritance hierarchy.
- class container
- In Fortran, a derived type that holds polymorphic components. It represents an object whose dynamic type can change.
- array subreference
- A part of an array reference, potentially involving indexing or slicing, that itself refers to an array.