https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121743

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
2026-03-11  Jakub Jelinek  <[email protected]>

        PR fortran/121743
        * trans-decl.cc (generate_coarray_init): Use pushdecl_top_level
        instead of pushdecl.

        * gfortran.dg/coarray_51.f90: New test.

--- gcc/fortran/trans-decl.cc.jj        2026-03-10 08:14:28.095322712 +0100
+++ gcc/fortran/trans-decl.cc   2026-03-11 12:30:54.949351246 +0100
@@ -6185,7 +6185,7 @@ generate_coarray_init (gfc_namespace *ns
   DECL_CONTEXT (decl) = fndecl;
   DECL_RESULT (fndecl) = decl;

-  pushdecl (fndecl);
+  pushdecl_top_level (fndecl);
   current_function_decl = fndecl;
   announce_function (fndecl);

--- gcc/testsuite/gfortran.dg/coarray_51.f90.jj 2026-03-11 12:47:35.972433440
+0100
+++ gcc/testsuite/gfortran.dg/coarray_51.f90    2026-03-11 12:46:30.815534630
+0100
@@ -0,0 +1,11 @@
+! PR fortran/121743
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+
+program pr121743
+end program pr121743
+subroutine foo ()
+  integer, allocatable, dimension(:), codimension[:] :: s
+  integer :: i
+  i = s(1)[1]
+end

fixes this for me, but so far otherwise untested.

Reply via email to