]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: ICE due to missing locus with data statement for coarray [PR99838]
authorHarald Anlauf <anlauf@gmx.de>
Tue, 3 Jun 2025 18:48:31 +0000 (20:48 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 3 Jun 2025 19:14:37 +0000 (21:14 +0200)
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.

gcc/fortran/data.cc
gcc/testsuite/gfortran.dg/coarray_data_2.f90 [new file with mode: 0644]

index 5c83f6948b8a33c3a52182952b9296f06d7721ef..a438c268cdaeea6836d1cacd78d10df027b581cf 100644 (file)
@@ -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 (file)
index 0000000..bda57f3
--- /dev/null
@@ -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