From 3cf89a7b992d483e80b3b5960f6f4012fae95045 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Sat, 9 Jun 2018 15:47:40 +0000 Subject: re PR fortran/85138 (ICE with generic function) 2018-06-09 Steven G. Kargl PR fortran/85138 PR fortran/85996 PR fortran/86051 * decl.c (gfc_match_char_spec): Use private namespace in attempt to reduce a charlen to a constant. 2018-06-09 Steven G. Kargl PR fortran/85138 PR fortran/85996 PR fortran/86051 * gfortran.dg/pr85138_1.f90: New test. * gfortran.dg/pr85138_2.f90: Ditto. * gfortran.dg/pr85996.f90: Ditto. From-SVN: r261362 --- gcc/fortran/ChangeLog | 8 ++++++++ gcc/fortran/decl.c | 22 ++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) (limited to 'gcc/fortran') diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 52fdc46a..1868780 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,5 +1,13 @@ 2018-06-09 Steven G. Kargl + PR fortran/85138 + PR fortran/85996 + PR fortran/86051 + * decl.c (gfc_match_char_spec): Use private namespace in attempt to + reduce a charlen to a constant. + +2018-06-09 Steven G. Kargl + PR fortran/78278 * data.c (gfc_assign_data_value): Re-arrange code to allow for an error for double initialization of CHARACTER entities. diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index df21ce0..c36a16b 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -3238,12 +3238,20 @@ done: cl->length = gfc_get_int_expr (gfc_charlen_int_kind, NULL, 1); else { - /* If gfortran ends up here, then the len may be reducible to a - constant. Try to do that here. If it does not reduce, simply - assign len to the charlen. */ + /* If gfortran ends up here, then len may be reducible to a constant. + Try to do that here. If it does not reduce, simply assign len to + charlen. A complication occurs with user-defined generic functions, + which are not resolved. Use a private namespace to deal with + generic functions. */ + if (len && len->expr_type != EXPR_CONSTANT) { + gfc_namespace *old_ns; gfc_expr *e; + + old_ns = gfc_current_ns; + gfc_current_ns = gfc_get_namespace (NULL, 0); + e = gfc_copy_expr (len); gfc_reduce_init_expr (e); if (e->expr_type == EXPR_CONSTANT) @@ -3254,10 +3262,12 @@ done: } else gfc_free_expr (e); - cl->length = len; + + gfc_free_namespace (gfc_current_ns); + gfc_current_ns = old_ns; } - else - cl->length = len; + + cl->length = len; } ts->u.cl = cl; -- cgit v1.1