From dc0f176a1c2142d6814b9b47ed516c9a0b2b9592 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Fri, 30 Oct 2015 16:26:59 +0000 Subject: [PATCH] re PR fortran/68154 (ICE on initializing character parameter array (explicit, implied)) 2015-10-30 Steven G. Kargl PR fortran/68154 * decl.c (add_init_expr_to_sym): if the char length in the typespec is NULL, check for and use a constructor. 2015-10-30 Steven G. Kargl PR fortran/68154 *gfortran.dg/pr68154.f90 From-SVN: r229588 --- gcc/fortran/ChangeLog | 7 ++++++- gcc/fortran/decl.c | 11 ++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr68154.f90 | 9 +++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr68154.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 587045d0579..74cae2f0d82 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,4 +1,9 @@ -2015-10-29 Steven G. Kargl +2015-10-30 Steven G. Kargl + + PR fortran/68154 + * decl.c (add_init_expr_to_sym): if the char length in the typespec + is NULL, check for and use a constructor. +2015-10-30 Steven G. Kargl PR fortran/68054 * decl.c (match_attr_spec): PROTECTED can only be a module. diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 6a7f3864ded..5a95fa4f193 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -1461,7 +1461,16 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) } else if (init->expr_type == EXPR_ARRAY) { - clen = mpz_get_si (init->ts.u.cl->length->value.integer); + if (init->ts.u.cl) + clen = mpz_get_si (init->ts.u.cl->length->value.integer); + else if (init->value.constructor) + { + gfc_constructor *c; + c = gfc_constructor_first (init->value.constructor); + clen = c->expr->value.character.length; + } + else + gcc_unreachable (); sym->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, clen); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ffefb43c1dd..5407db7f1be 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-10-30 Steven G. Kargl + + PR fortran/68154 + *gfortran.dg/pr68154.f90 + 2015-10-29 Nathan Sidwell * c-c++-common/goacc/acc_on_device-2-off.c: Delete. diff --git a/gcc/testsuite/gfortran.dg/pr68154.f90 b/gcc/testsuite/gfortran.dg/pr68154.f90 new file mode 100644 index 00000000000..6415eb0b804 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr68154.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/68154 +! Original code contributed by Gerhard Steinmetz +! gerhard dot steinmetz dot fortran at t-online dot de +program p + character(1), parameter :: x1(2) = 'a' + character(*), parameter :: x2(2) = x1 + character(*), parameter :: x3(*) = x1 +end -- 2.30.2