https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125051
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Paul Thomas <[email protected]>: https://gcc.gnu.org/g:3e281ae5d6a814585b884d693ef354e75bf12be7 commit r17-427-g3e281ae5d6a814585b884d693ef354e75bf12be7 Author: Paul Thomas <[email protected]> Date: Fri May 8 06:34:21 2026 +0100 Fortran: Allow access to coarray elements within modules. [PR125051] The parts of this patch is fix the problem are chunks 2 and 3. Chunk3 prevents gfc_conv_intrinsic_caf_get from working in the module namespace, when the array symbol is in a module. Equally, though, gfc_current_ns is not necessarily in the referencing procedure namespace. The second chunk makes sure that this is the case. As an aside, it seems to us that it makes considerably more sense that gfc_current_ns be that of the current procedure. The first chunk makes sure that result symbol initialization does not occur outside the function. Passes regtesting with FC44/x86_64. 2026-05-10 Andre Vehreschild <[email protected]> Paul Thomas <[email protected]> gcc/fortran PR fortran/125051 * trans-decl.cc (gfc_get_symbol_decl): gfc_defer_symbol_init must not be called for PDT types, classes or types with PDT (gfc_generate_function_code): If gfc_current_ns is not the same as the function namespace, stash it,change it to the function namespace and restore after translation of the code. * trans-intrinsic.cc (gfc_conv_intrinsic_caf_get): If the array is in a module, use the symbol namespace. * trans-openmp.cc (gfc_trans_omp_array_reduction_or_udr): If the current namespace is not that of the procedure, change to the procedure namspace and revert on leaving this function. gcc/testsuite/ PR fortran/125051 * gfortran.dg/coarray/pr125051.f90: New test.
