From fc386590ad78ebd512c865cf01e286bb6f93b80a Mon Sep 17 00:00:00 2001 From: kargl Date: Sun, 25 Feb 2018 16:50:50 +0000 Subject: [PATCH] 2018-02-25 Steven G. Kargl PR fortran/83633 * decl.c (variable_decl): Check that an explicit-shape-array with nonconstant bounds is allowed. 2018-02-25 Steven G. Kargl 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. * gfortran.dg/constant_shape.f90: Ditto. * gfortran.dg/dec_structure_23.f90: Ditto. * gfortran.dg/pr78240.f90: Ditto. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257971 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 6 +++ gcc/fortran/decl.c | 49 +++++++++++++++++++++- gcc/testsuite/ChangeLog | 10 +++++ .../gfortran.dg/automatic_module_variable.f90 | 4 +- .../gfortran.dg/bad_automatic_objects_1.f90 | 6 ++- gcc/testsuite/gfortran.dg/constant_shape.f90 | 7 ++-- gcc/testsuite/gfortran.dg/dec_structure_23.f90 | 9 ++-- gcc/testsuite/gfortran.dg/explicit_shape_1.f90 | 7 ++++ gcc/testsuite/gfortran.dg/pr78240.f90 | 5 ++- 9 files changed, 90 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/explicit_shape_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 2c2aa2b8d90..76ac274674a 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-02-25 Steven G. Kargl + + PR fortran/83633 + * decl.c (variable_decl): Check that an explicit-shape-array with + nonconstant bounds is allowed. + 2018-02-25 Paul Thomas PR fortran/84523 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index e377a213db4..dcfda27a3c6 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -2304,7 +2304,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) @@ -2326,6 +2329,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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0a015c8ca59..86fce26c083 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2018-02-25 Steven G. Kargl + + 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. + * gfortran.dg/constant_shape.f90: Ditto. + * gfortran.dg/dec_structure_23.f90: Ditto. + * gfortran.dg/pr78240.f90: Ditto. + 2018-02-25 Paul Thomas PR fortran/84523 diff --git a/gcc/testsuite/gfortran.dg/automatic_module_variable.f90 b/gcc/testsuite/gfortran.dg/automatic_module_variable.f90 index 201dcf4e1d3..ab041fcf4f5 100644 --- a/gcc/testsuite/gfortran.dg/automatic_module_variable.f90 +++ b/gcc/testsuite/gfortran.dg/automatic_module_variable.f90 @@ -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 diff --git a/gcc/testsuite/gfortran.dg/bad_automatic_objects_1.f90 b/gcc/testsuite/gfortran.dg/bad_automatic_objects_1.f90 index 27344186194..61db2174e5b 100644 --- a/gcc/testsuite/gfortran.dg/bad_automatic_objects_1.f90 +++ b/gcc/testsuite/gfortran.dg/bad_automatic_objects_1.f90 @@ -5,16 +5,18 @@ ! ! Contributed by Joost VandeVondele ! +! 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/constant_shape.f90 b/gcc/testsuite/gfortran.dg/constant_shape.f90 index c2eaf82f5ec..5ee927b20e2 100644 --- a/gcc/testsuite/gfortran.dg/constant_shape.f90 +++ b/gcc/testsuite/gfortran.dg/constant_shape.f90 @@ -3,7 +3,8 @@ ! PR 78392: ICE in gfc_trans_auto_array_allocation, at fortran/trans-array.c:5979 ! ! Contributed by Janus Weil - +! Error message update with patch for PR fortran/83633 +! module mytypes implicit none contains @@ -15,6 +16,6 @@ end module program test use mytypes implicit none - integer, dimension(get_i()) :: x ! { dg-error "must have constant shape" } - print *, size (x) + integer, dimension(get_i()) :: x ! { dg-error "array with nonconstant bounds" } + print *, size (x) ! { dg-error "has no IMPLICIT type" } end diff --git a/gcc/testsuite/gfortran.dg/dec_structure_23.f90 b/gcc/testsuite/gfortran.dg/dec_structure_23.f90 index 3c68489c4bd..78db344e0fc 100644 --- a/gcc/testsuite/gfortran.dg/dec_structure_23.f90 +++ b/gcc/testsuite/gfortran.dg/dec_structure_23.f90 @@ -6,14 +6,15 @@ ! Test a regression where an ICE occurred attempting to create array variables ! with non-constant array-specs in legacy clist initializers. ! - +! Error message update with patch for PR fortran/83633 +! program p implicit none integer :: nn real :: rr structure /s/ - integer x(n) /1/ ! { dg-error "xpected constant" } - integer xx(nn) /1/ ! { dg-error "xpected constant" } - integer xxx(rr) /1.0/ ! { dg-error "xpected constant" } + integer x(n) /1/ ! { dg-error "array with nonconstant bounds" } + integer xx(nn) /1/ ! { dg-error "array with nonconstant bounds" } + integer xxx(rr) /1.0/ ! { dg-error "array with nonconstant bounds" } end structure end diff --git a/gcc/testsuite/gfortran.dg/explicit_shape_1.f90 b/gcc/testsuite/gfortran.dg/explicit_shape_1.f90 new file mode 100644 index 00000000000..ca3cd00d855 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/explicit_shape_1.f90 @@ -0,0 +1,7 @@ +! { dg-do compile } +! PR fortran/83633 +! Original testcase by Nathan T. Weeks +! +integer :: A(command_argument_count()) = 1 ! { dg-error "nonconstant bounds" } +write (*,*) A +end diff --git a/gcc/testsuite/gfortran.dg/pr78240.f90 b/gcc/testsuite/gfortran.dg/pr78240.f90 index 5373b555a50..45d3f86360b 100644 --- a/gcc/testsuite/gfortran.dg/pr78240.f90 +++ b/gcc/testsuite/gfortran.dg/pr78240.f90 @@ -7,9 +7,10 @@ ! to the error handling routine for non-constant array-specs in DATA list ! initializers. ! - +! Error message update with patch for PR fortran/83633 +! program p - integer x(n) /1/ ! { dg-error "cannot appear in the expression" } + integer x(n) /1/ ! { dg-error "array with nonconstant bounds" } end ! { dg-prune-output "module or main program" } ! { dg-prune-output "Nonconstant array" } -- 2.11.4.GIT