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

fortran: Fix FINDLOC with DIM and MASK

Corrects the FINDLOC intrinsic function in Fortran when used with DIM and MASK arguments.

The Fortran runtime library had a bug in the FINDLOC intrinsic function where it did not correctly advance through the MASK array when both MASK and DIM arguments were provided. This led to incorrect results or potential issues during array traversal. This commit regenerates the runtime library templates for FINDLOC after fixing the logic in the ifindloc1.m4 macro to ensure proper handling of the MASK argument in all relevant cases.

In Details

The generated Fortran runtime library templates for FINDLOC (specifically the mfindloc1_* C files) failed to properly increment the array index for the MASK argument when both MASK and DIM were present. The m4/ifindloc1.m4 macro, responsible for generating these templates, has been corrected to ensure correct iteration through the MASK array under these conditions.

For Context
FINDLOC
A Fortran intrinsic function that returns the index (or indices) of the first occurrence of a specified value within an array, optionally considering a mask and dimension.
DIM
In Fortran, refers to the dimension argument of intrinsic functions like FINDLOC, MINLOC, MAXLOC, which specifies the dimension along which the operation should be performed.
MASK
In Fortran, an optional logical array argument for many intrinsic functions that specifies which elements of the input array are to be considered in the operation. Elements where MASK is false are ignored.
runtime library
A collection of pre-compiled functions and routines that are linked with a program at runtime to provide essential services, such as I/O, memory management, and intrinsic function implementations.
m4 macro processor
A general-purpose macro processor that can be used to preprocess source code. In this context, it's used to generate specialized versions of Fortran runtime library routines based on various data types and arguments.
Filed Under: fortranruntime libraryintrinsic functions