]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/83633 (gfortran internal compiler error for explicit-shape array with...
authorSteven G. Kargl <kargl@gcc.gnu.org>
Sun, 25 Feb 2018 17:32:36 +0000 (17:32 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Sun, 25 Feb 2018 17:32:36 +0000 (17:32 +0000)
2018-02-25  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/83633
* decl.c (variable_decl): Check that an explicit-shape-array with
nonconstant bounds is allowed.

2018-02-25  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/83633
* gfortran.dg/explicit_shape_1.f90: New test.
* gfortran.dg/automatic_module_variable.f90: Update regex.
* gfortran.dg/bad_automatic_objects_1.f90: Ditto.

From-SVN: r257974

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/automatic_module_variable.f90
gcc/testsuite/gfortran.dg/bad_automatic_objects_1.f90
gcc/testsuite/gfortran.dg/explicit_shape_1.f90 [new file with mode: 0644]

index bb1743d71b017692fecab835c63cf85a03e57d1b..9eec89572449e4a7733c14671e1154c1974f9eca 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-25  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/83633
+       * decl.c (variable_decl): Check that an explicit-shape-array with
+       nonconstant bounds is allowed.
+
 2018-02-24  Steven G. Kargl <kargl@gcc.gnu.org>
 
        PR fortran/30792
index a3ac70933f034b0fe7e6887e0708df956ae9fe80..64e0fee5c297f17a14d01a384ef41b806a53317a 100644 (file)
@@ -2220,7 +2220,10 @@ variable_decl (int elem)
   /* At this point, we know for sure if the symbol is PARAMETER and can thus
      determine (and check) whether it can be implied-shape.  If it
      was parsed as assumed-size, change it because PARAMETERs can not
-     be assumed-size.  */
+     be assumed-size.
+
+     An explicit-shape-array cannot appear under several conditions.
+     That check is done here as well.  */
   if (as)
     {
       if (as->type == AS_IMPLIED_SHAPE && current_attr.flavor != FL_PARAMETER)
@@ -2242,6 +2245,50 @@ variable_decl (int elem)
          m = MATCH_ERROR;
          goto cleanup;
        }
+
+      /* F2018:C830 (R816) An explicit-shape-spec whose bounds are not
+        constant expressions shall appear only in a subprogram, derived
+        type definition, BLOCK construct, or interface body.  */
+      if (as->type == AS_EXPLICIT
+         && gfc_current_state () != COMP_BLOCK
+         && gfc_current_state () != COMP_DERIVED
+         && gfc_current_state () != COMP_FUNCTION
+         && gfc_current_state () != COMP_INTERFACE
+         && gfc_current_state () != COMP_SUBROUTINE)
+       {
+         gfc_expr *e;
+         bool not_constant = false;
+
+         for (int i = 0; i < as->rank; i++)
+           {
+             e = gfc_copy_expr (as->lower[i]);
+             gfc_resolve_expr (e);
+             gfc_simplify_expr (e, 0);
+             if (e && (e->expr_type != EXPR_CONSTANT))
+               {
+                 not_constant = true;
+                 break;
+               }
+             gfc_free_expr (e);
+
+             e = gfc_copy_expr (as->upper[i]);
+             gfc_resolve_expr (e);
+             gfc_simplify_expr (e, 0);
+             if (e && (e->expr_type != EXPR_CONSTANT))
+               {
+                 not_constant = true;
+                 break;
+               }
+             gfc_free_expr (e);
+           }
+
+         if (not_constant)
+           { 
+             gfc_error ("Explicit shaped array with nonconstant bounds at %C");
+             m = MATCH_ERROR;
+             goto cleanup;
+           }
+       }
     }
 
   char_len = NULL;
index 8305efe3201c0399bd9f62269f3e35d85f241219..92a58e5a49bdda6f0ab1fdd6b305c5b773dbfa83 100644 (file)
@@ -1,3 +1,10 @@
+2018-02-25  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/83633
+       * gfortran.dg/explicit_shape_1.f90: New test.
+       * gfortran.dg/automatic_module_variable.f90: Update regex.
+       * gfortran.dg/bad_automatic_objects_1.f90: Ditto.
+
 2018-02-24  Steven G. Kargl <kargl@gcc.gnu.org>
 
        PR fortran/30792
index 201dcf4e1d3cb360d5864a205bcd3df7932283a8..ab041fcf4f5ac40cce2e8545be134b20f761a520 100644 (file)
@@ -1,10 +1,12 @@
 ! { dg-do compile }
 ! Tests fix for PR15976
 !
+! Error message update with patch for PR fortran/83633
+!
 module sd
   integer, parameter :: n = 20
   integer :: i(n)
-  integer :: j(m) ! { dg-error "must have constant shape" }
+  integer :: j(m) ! { dg-error "array with nonconstant bounds" }
   integer, pointer :: p(:)
   integer, allocatable :: q(:)
 contains
index 2734418619478f0eb0e0b88a9dac4da5c6a3c956..61db2174e5b9cca84428efde8d8d3cccd1983ddd 100644 (file)
@@ -5,16 +5,18 @@
 !
 ! Contributed by Joost VandeVondele  <jv244@cam.ac.uk>
 !
+! Error message update with patch for PR fortran/83633
+!
 module foo
   integer    ::  i
 end module foo
 module bar
   use foo
-  integer, dimension (i) :: j ! { dg-error "must have constant shape" }
+  integer, dimension (i) :: j ! { dg-error "array with nonconstant bounds" }
   character (len = i) :: c1   ! { dg-error "must have constant character length" }
 end module bar
 program foobar
   use foo
-  integer, dimension (i) :: k ! { dg-error "must have constant shape" }
+  integer, dimension (i) :: k ! { dg-error "array with nonconstant bounds" }
   character (len = i) :: c2   ! { dg-error "must have constant character length" }
 end program foobar
diff --git a/gcc/testsuite/gfortran.dg/explicit_shape_1.f90 b/gcc/testsuite/gfortran.dg/explicit_shape_1.f90
new file mode 100644 (file)
index 0000000..ca3cd00
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR fortran/83633
+! Original testcase by Nathan T. Weeks  <weeks at iastate dot edu>
+!
+integer :: A(command_argument_count()) = 1 ! { dg-error "nonconstant bounds" }
+write (*,*) A
+end