GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

fortran: Fix simplification of TRANSFER of derived types

Compiler now correctly initializes all elements of an array component when simplifying TRANSFER of derived types.

A bug in the Fortran compiler’s simplification of the TRANSFER intrinsic for derived types with array components has been fixed. Previously, if an array component was initialized by a scalar constant, only the first element of the array was being set to that value. This change ensures that all elements of the array component are correctly initialized with the scalar constant, as intended.

In Details

The encode_derived function in GCC's Fortran front-end was responsible for simplifying the TRANSFER intrinsic when applied to derived types. When a derived type contained an array component that was initialized by a scalar constant, encode_derived incorrectly handled the initialization of that array component. It only populated the first element of the array, leaving subsequent elements uninitialized or with stale values. This commit modifies encode_derived to correctly set all elements of the array component to the scalar constant value when such a simplification occurs.

For Context
TRANSFER
A Fortran intrinsic procedure that transfers values between objects of different types and kinds, often used for data conversion or manipulation at the byte level.
derived type
A user-defined composite data type in Fortran, similar to a struct in C, which can contain components of various data types, including arrays.
simplification
A compiler optimization technique that reduces complex expressions or operations into simpler, equivalent forms to improve performance or reduce code size.
Filed Under: fortranoptimizationbugfix