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.

(cherry picked from commit 0768ec0d32f570b1db13ca41b0a1506275c44053)
diff --git a/gcc/fortran/data.cc b/gcc/fortran/data.cc
index 5c83f69..a438c26 100644
--- a/gcc/fortran/data.cc
+++ b/gcc/fortran/data.cc
@@ -593,7 +593,13 @@
 	{
 	  /* 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 0000000..bda57f3
--- /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