From fb42421ef060d7bc2e7f954ce12b0fdc83e57ee6 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Sat, 30 Jul 2016 16:19:14 +0000 Subject: [PATCH] re PR fortran/71730 (ICE when character length specification uses an undefined variable) 2016-07-30 Steven G. Kargl PR fortran/71730 * decl.c (char_len_param_value): Check return value of gfc_reduce_init_expr(). 2016-07-30 Steven G. Kargl PR fortran/71730 * gfortran.dg/pr71730.f90: New test. * gfortran.dg/bounds_check_strlen_2.f90: Fix invalid code. * gfortran.dg/array_constructor_27.f03: Update dg-error message. * gfortran.dg/array_constructor_26.f03: Ditto. From-SVN: r238904 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/decl.c | 11 ++++++++++- gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/gfortran.dg/array_constructor_26.f03 | 3 +-- gcc/testsuite/gfortran.dg/array_constructor_27.f03 | 3 +-- gcc/testsuite/gfortran.dg/bounds_check_strlen_2.f90 | 2 +- gcc/testsuite/gfortran.dg/pr71730.f90 | 5 +++++ 7 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr71730.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e8f8a81aeb9..775276bc5c2 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2016-07-30 Steven G. Kargl + + PR fortran/71730 + * decl.c (char_len_param_value): Check return value of + gfc_reduce_init_expr(). + 2016-07-29 Dominik Vogt * trans-array.c (gfc_conv_array_ref): Fix allocation of diagnostic diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index cf750391ef1..7ff2f0df297 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -906,6 +906,7 @@ char_len_param_value (gfc_expr **expr, bool *deferred) goto syntax; else if ((*expr)->expr_type == EXPR_VARIABLE) { + bool t; gfc_expr *e; e = gfc_copy_expr (*expr); @@ -917,7 +918,15 @@ char_len_param_value (gfc_expr **expr, bool *deferred) && e->ref->u.ar.dimen_type[0] == DIMEN_RANGE) goto syntax; - gfc_reduce_init_expr (e); + t = gfc_reduce_init_expr (e); + + if (!t && (e->ts.type == BT_UNKNOWN + && e->symtree->n.sym->attr.untyped == 1 + && e->symtree->n.sym->ns->seen_implicit_none == 1)) + { + gfc_free_expr (e); + goto syntax; + } if ((e->ref && e->ref->type == REF_ARRAY && e->ref->u.ar.type != AR_ELEMENT) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cf5ffcd7482..d41cfcaa6c3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2016-07-30 Steven G. Kargl + + PR fortran/71730 + * gfortran.dg/pr71730.f90: New test. + * gfortran.dg/bounds_check_strlen_2.f90: Fix invalid code. + * gfortran.dg/array_constructor_27.f03: Update dg-error message. + * gfortran.dg/array_constructor_26.f03: Ditto. + 2016-07-29 Bill Schmidt * g++.dg/pr70098.C: Remove XFAIL for powerpc64_no_dm. diff --git a/gcc/testsuite/gfortran.dg/array_constructor_26.f03 b/gcc/testsuite/gfortran.dg/array_constructor_26.f03 index 9993099af91..bb40d09d090 100644 --- a/gcc/testsuite/gfortran.dg/array_constructor_26.f03 +++ b/gcc/testsuite/gfortran.dg/array_constructor_26.f03 @@ -10,7 +10,6 @@ MODULE WinData INTEGER (1), PARAMETER :: MAXFLD = 25_1, MAXHED = 5_1, MAXCHR = 80_1 integer :: i TYPE TWindowData - CHARACTER (MAX_FLD_HED, 1) :: DWFdHd(MAXFLD) = [(" ", i = 1, MAXFLD)] - ! { dg-error "specification expression" "" { target *-*-* } 13 } + CHARACTER (MAX_FLD_HED, 1) :: DWFdHd(MAXFLD) = [(" ", i = 1, MAXFLD)] ! { dg-error "Scalar INTEGER expression" } END TYPE TWindowData END MODULE WinData diff --git a/gcc/testsuite/gfortran.dg/array_constructor_27.f03 b/gcc/testsuite/gfortran.dg/array_constructor_27.f03 index 21adac82ad4..de0217a7500 100644 --- a/gcc/testsuite/gfortran.dg/array_constructor_27.f03 +++ b/gcc/testsuite/gfortran.dg/array_constructor_27.f03 @@ -8,8 +8,7 @@ implicit none type t - character (a) :: arr (1) = [ "a" ] - ! { dg-error "specification expression" "" { target *-*-* } 11 } + character (a) :: arr (1) = [ "a" ] ! { dg-error "Scalar INTEGER expression" } end type t end diff --git a/gcc/testsuite/gfortran.dg/bounds_check_strlen_2.f90 b/gcc/testsuite/gfortran.dg/bounds_check_strlen_2.f90 index 241db66239c..73c2ea8282e 100644 --- a/gcc/testsuite/gfortran.dg/bounds_check_strlen_2.f90 +++ b/gcc/testsuite/gfortran.dg/bounds_check_strlen_2.f90 @@ -11,8 +11,8 @@ CONTAINS SUBROUTINE test (str, n) IMPLICIT NONE - CHARACTER(len=n) :: str INTEGER :: n + CHARACTER(len=n) :: str END SUBROUTINE test SUBROUTINE test2 (str) diff --git a/gcc/testsuite/gfortran.dg/pr71730.f90 b/gcc/testsuite/gfortran.dg/pr71730.f90 new file mode 100644 index 00000000000..f0d48c43e6f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr71730.f90 @@ -0,0 +1,5 @@ +! { dg-do compile } +subroutine foo + implicit none + character(len=bar) :: a ! { dg-error "Scalar INTEGER expression" } +end subroutine foo -- 2.30.2