re PR fortran/67538 (ICE with invalid source allocation)
authorAndre Vehreschild <vehre@gcc.gnu.org>
Mon, 4 Apr 2016 10:32:32 +0000 (12:32 +0200)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Mon, 4 Apr 2016 10:32:32 +0000 (12:32 +0200)
gcc/fortran/ChangeLog:

2016-04-04  Andre Vehreschild  <vehre@gcc.gnu.org>

PR fortran/67538
* resolve.c (resolve_allocate_expr): Emit error message when no
array spec and no array valued source= expression is given in an
F2008 allocate() for an array to allocate.

gcc/testsuite/ChangeLog:

2016-04-04  Andre Vehreschild  <vehre@gcc.gnu.org>

PR fortran/67538
* gfortran.dg/allocate_with_source_19.f08: New test.

From-SVN: r234714

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/allocate_with_source_19.f08 [new file with mode: 0644]

index 88ac1cc352ee60900d0594da79ce51b0cc0bf673..4ad92c0fb2dc7139ac4ab55b7e5df886c4e2d002 100644 (file)
@@ -1,3 +1,10 @@
+2016-04-04  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/67538
+       * resolve.c (resolve_allocate_expr): Emit error message when no
+       array spec and no array valued source= expression is given in an
+       F2008 allocate() for an array to allocate.
+
 2016-04-04  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        PR fortran/65795
index 55ab2ecfcebec3ac8a1ce44b387df56cd1980047..f5cd588308a63cec2fc4e86fea984b1775d06833 100644 (file)
@@ -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
        {
index 47656a92652cf0d36588986236272c3e50ed106a..2de8ea55fd08be52f80f6d527b657f4110af206c 100644 (file)
@@ -1,3 +1,8 @@
+2016-04-04  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/67538
+       * gfortran.dg/allocate_with_source_19.f08: New test.
+
 2016-04-04  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        PR fortran/65795
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 (file)
index 0000000..ff84510
--- /dev/null
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! { dg-options -std=f2008 }
+
+! Contributed by mrestelli@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
+