GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

Fortran: Fixes ICE with LOC intrinsic on polymorphic argument

GCC's Fortran compiler fixes an internal compiler error when using the LOC intrinsic with polymorphic arguments, improving stability for advanced Fortran featu…

This commit resolves an Internal Compiler Error (ICE) in GCC’s Fortran front-end that occurred when the LOC() intrinsic function was used with a polymorphic argument, as reported in PR125606. The issue stemmed from a side effect of a previous fix (PR122977) that caused gfc_is_simply_contiguous to return false for SELECT TYPE temporaries. The correction now ensures that when the argument is not scalar or simply contiguous, the compiler gracefully falls back to taking the address of the argument array’s first element, preventing the ICE.

In Details

This fix targets an ICE in the Fortran front-end's trans-intrinsic.cc, specifically within gfc_conv_intrinsic_loc, related to PR125606. The problem arose because a previous patch for PR122977, which improved gfc_is_simply_contiguous for associate variables, inadvertently caused it to incorrectly return false for SELECT TYPE temporaries when used with the LOC() intrinsic. The resolution involves adding a fallback mechanism: when gfc_is_simply_contiguous indicates the argument is not scalar or simply contiguous, the compiler now directly takes the address of the array's first elem…

For Context

This update to GCC, the Fortran compiler, fixes a crash (Internal Compiler Error, or ICE) that users might have encountered when employing a specific Fortran feature. The LOC() intrinsic function in Fortran is used to get the memory address of a variable. The bug occurred when LOC() was called with a 'polymorphic' argument—a variable that can take on different data types during program execution, often used with SELECT TYPE constructs. Previously, the compiler would sometimes incorrectly determine that these polymorphic variables weren't stored in a simple, continuous block of memory, leading to a crash. The fix ensures that even when the compiler can't easily determine the memory layout of such a variable, it still correctly finds its starting address, making the compiler more robust for advanced Fortran programming.

Filed Under: fortranbugfixintrinsicspolymorphism