Hi all,

the attached patch checks that for F2008-style allocate(arr1, source=s)
the expression in s is array valued, when arr1 has no array spec and
emits an error message saying:

Array specification or array-valued SOURCE= expression required in ALLOCATE 
statement at (1)

This fixes the ICE.

Bootstrapped and regtests ok on x86_64-linux-gnu/F23. Ok for trunk?

Regards,
        Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

Attachment: pr67538_1.clog
Description: Binary data

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 55ab2ec..f5cd588 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -7217,7 +7217,15 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool *array_alloc_wo_spec)
 	  if (!gfc_notify_std (GFC_STD_F2008, "Array specification required "
 			       "in ALLOCATE statement at %L", &e->where))
 	    goto failure;
-	  *array_alloc_wo_spec = true;
+	  if (code->expr3->rank != 0)
+	    *array_alloc_wo_spec = true;
+	  else
+	    {
+	      gfc_error ("Array specification or array-valued SOURCE= "
+			 "expression required in ALLOCATE statement at %L",
+			 &e->where);
+	      goto failure;
+	    }
 	}
       else
 	{
diff --git a/gcc/testsuite/gfortran.dg/allocate_with_source_19.f08 b/gcc/testsuite/gfortran.dg/allocate_with_source_19.f08
new file mode 100644
index 0000000..ff84510
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/allocate_with_source_19.f08
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! { dg-options -std=f2008 }
+
+! Contributed by mreste...@gmail.com
+! Check that instead of an ICE the error message is emitted.
+
+module m
+ implicit none
+contains
+
+ subroutine s()
+  real, allocatable :: x(:)
+  real :: y
+
+   y = 5.0
+   ! x either needs an array spec, or y needs to be an array.
+   allocate( x , source=y ) ! { dg-error "Array specification or array-valued SOURCE= expression required in ALLOCATE statement" }
+
+ end subroutine s
+
+end module m
+

Reply via email to