From: Louis Krupp Date: Thu, 22 Sep 2016 07:07:53 +0000 (+0000) Subject: re PR fortran/66107 (ICE on missing parameter value for initialisation (segfault)) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=39abef62a17740d59f4bab506c07867cffa7da10;p=gcc.git re PR fortran/66107 (ICE on missing parameter value for initialisation (segfault)) 2016-09-21 Louis Krupp PR fortran/66107 * gfortran.dg/pr66107.f90: New test. 2016-09-21 Louis Krupp PR fortran/66107 * decl.c (add_init_expr_to_sym): Catch variable character length in parameter array. From-SVN: r240341 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 5d9a10df6b2..971c3483814 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2016-09-21 Louis Krupp + + PR fortran/66107 + * decl.c (add_init_expr_to_sym): Catch variable character length + in parameter array. + 2016-09-21 Paul Thomas PR fortran/77657 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index d9fae5753d0..2982e86bac0 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -1672,7 +1672,18 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) else if (init->expr_type == EXPR_ARRAY) { if (init->ts.u.cl) - clen = mpz_get_si (init->ts.u.cl->length->value.integer); + { + const gfc_expr *length = init->ts.u.cl->length; + if (length->expr_type != EXPR_CONSTANT) + { + gfc_error ("Cannot initialize parameter array " + "at %L " + "with variable length elements", + &sym->declared_at); + return false; + } + clen = mpz_get_si (length->value.integer); + } else if (init->value.constructor) { gfc_constructor *c; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6a1dae9cf3c..e6480d85374 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-21 Louis Krupp + + PR fortran/66107 + * gfortran.dg/pr66107.f90: New test. + 2016-09-21 Ian Lance Taylor * go.go-torture/execute/map-1.go: Replace old map deletion syntax diff --git a/gcc/testsuite/gfortran.dg/pr66107.f90 b/gcc/testsuite/gfortran.dg/pr66107.f90 new file mode 100644 index 00000000000..5127efaeed3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr66107.f90 @@ -0,0 +1,6 @@ +! { dg-do compile } +! PR fortran/66107 +subroutine p + integer n + character(*), parameter :: z(1) = [character(len=n) :: 'x'] ! { dg-error "Cannot initialize parameter array at .1. with variable length elements" } +end subroutine