GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

Fortran: Fix data corruption with allocation from ctr source

Corrects data corruption in Fortran derived type assignments involving allocatable components.

This commit addresses data corruption issues in the Fortran compiler (gfortran) that occurred when assigning derived type expressions to class components or derived type components. It ensures that allocatable components are properly copied during such assignments. Additionally, it handles the case of assigning a class expression to a scalar class component by correctly allocating the component and using vptr copy, thus preventing data corruption.

In Details

In gfc_trans_subcomponent_assign within trans-expr.cc, assignments involving derived types with allocatable components were not correctly handling the allocation and copying of these components. This patch introduces logic to copy allocatable components when a derived type expression is assigned to a class or derived type component. It also correctly allocates and uses vptr copy for scalar class component assignments.

For Context
derived type
A user-defined composite data type in Fortran, similar to a struct in C or a class in C++. It can contain components of various data types, including other derived types.
allocatable component
A component within a derived type that is declared as allocatable. This means its memory can be dynamically allocated and deallocated during runtime, allowing for variable-sized data structures.
vptr copy
Virtual pointer copy. In the context of object-oriented programming and compiler implementations, this likely refers to copying the virtual function table pointer or similar mechanism to ensure correct polymorphic behavior after an assignment.
gfortran
The GNU Fortran compiler, part of the GCC suite. It translates Fortran source code into executable programs.
trans-expr.cc
A source file in the gfortran compiler that likely handles the translation of Fortran expressions into an intermediate representation for optimization and code generation.
Filed Under: fortrandata corruptionassignment