SUNDAY, AUGUST 9, 2026
fortran
Fix missing vptrs for Fortran class allocations.
Correctly initializes virtual pointers for Fortran class allocations, resolving a bug and adding a test case.
This commit addresses a bug in Fortran’s handling of class allocations where virtual pointers (vptrs) were not being correctly initialized. Changes in trans-array.cc and trans-stmt.cc ensure proper array descriptor usage and assignment for class sources. A new test case, allocate_class_5.f90, is added to verify the fix.
In Details
PR98573 is fixed by ensuring that gfc_array_init_size in trans-array.cc uses the expr3_desc for the type when it's an array descriptor. Additionally, gfc_trans_allocate in trans-stmt.cc now uses trans_assignment for class source assignments, which appears to resolve issues with missing vptrs.
For Context
- vptr
- Virtual Pointer. A pointer used in object-oriented programming to locate virtual functions at runtime. Its presence is essential for dynamic dispatch in derived classes.
- class allocation
- In Fortran, this refers to the allocation of memory for objects of derived types that may have virtual procedures, requiring proper initialization of their vptrs.
- array descriptor
- A data structure containing information about an array, such as its base address, element size, and dimension extents. It's used by the runtime to manage array operations.