https://gcc.gnu.org/g:0768ec0d32f570b1db13ca41b0a1506275c44053

commit r16-1090-g0768ec0d32f570b1db13ca41b0a1506275c44053
Author: Harald Anlauf <anl...@gmx.de>
Date:   Tue Jun 3 20:48:31 2025 +0200

    Fortran: ICE due to missing locus with data statement for coarray [PR99838]
    
            PR fortran/99838
    
    gcc/fortran/ChangeLog:
    
            * data.cc (gfc_assign_data_value): For a new initializer use the
            location from the constructor as fallback.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/coarray_data_2.f90: New test.

Diff:
---
 gcc/fortran/data.cc                          |  8 +++++++-
 gcc/testsuite/gfortran.dg/coarray_data_2.f90 | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/data.cc b/gcc/fortran/data.cc
index 5c83f6948b8a..a438c268cdae 100644
--- a/gcc/fortran/data.cc
+++ b/gcc/fortran/data.cc
@@ -593,7 +593,13 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, 
mpz_t index,
        {
          /* Point the container at the new expression.  */
          if (last_con == NULL)
-           symbol->value = expr;
+           {
+             symbol->value = expr;
+             /* For a new initializer use the location from the
+                constructor as fallback.  */
+             if (!GFC_LOCUS_IS_SET(expr->where) && con != NULL)
+               symbol->value->where = con->where;
+           }
          else
            last_con->expr = expr;
        }
diff --git a/gcc/testsuite/gfortran.dg/coarray_data_2.f90 
b/gcc/testsuite/gfortran.dg/coarray_data_2.f90
new file mode 100644
index 000000000000..bda57f3df890
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_data_2.f90
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! { dg-additional-options "-fcoarray=lib -Warray-temporaries" }
+!
+! PR fortran/99838 - ICE due to missing locus with data statement for coarray
+!
+! Contributed by Gerhard Steinmetz
+
+program p
+  type t
+     integer :: a
+  end type
+  type(t) :: x(3)[*]
+  data x%a /1, 2, 3/ ! { dg-warning "Creating array temporary" }
+end

Reply via email to