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

Fortran OpenMP correctly handles POINTER array privatization.

Fortran `POINTER` attribute arrays with OpenMP `firstprivate` clauses now correctly maintain their association status instead of being deep-copied.

This commit corrects an issue where Fortran arrays with the POINTER attribute were deep-copied when used with an OpenMP firstprivate clause, instead of having their association status preserved. A new language hook, omp_array_data_privatize, differentiates these cases during OpenMP lowering. This ensures compliance with the OpenMP specification for POINTER variables, where new list items should receive the same association status as the original.

In Details

This patch introduces gfc_omp_array_data_privatize, a new Fortran-specific language hook for LANG_HOOKS_OMP_ARRAY_DATA_PRIVATIZE, and integrates it into omp-low.cc. The core issue stems from incorrect privatization of POINTER arrays during OpenMP's firstprivate handling. According to the OpenMP specification, POINTER items should undergo pointer assignment to preserve association status, not deep copying. The new hook enables scan_sharing_clauses and lower_omp_target to correctly differentiate and apply the specified privatization behavior for Fortran POINTER arrays, avoidin…

For Context

When you write parallel programs using OpenMP in Fortran, there's a feature called firstprivate that creates a private copy of a variable for each part of your parallel code. For regular variables, this means making a separate copy of its value. However, Fortran has a special type of variable called a POINTER, which stores a memory address rather than a direct value. According to the OpenMP rules, when a POINTER array is declared firstprivate, the new private copies should point to the same memory location as the original, not create entirely new copies of the array data. This commit fixes a bug where the compiler was incorrectly making deep copies of the array data for POINTER arrays, which could lead to unexpected behavior or performance issues. The fix introduces a new mechanism (a 'langhook') to ensure that the compiler correctly handles POINTER arrays in parallel sections, making sure they behave as the OpenMP standard intends.

Filed Under: fortranopenmpbugfixparallelism