From: Steven G. Kargl Date: Thu, 8 Mar 2018 00:42:41 +0000 (+0000) Subject: re PR fortran/64124 ([F95] Valid constant expr rejected) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=00df7c36f5c0d082f3ac4f240546d3c4d4812fdd;p=gcc.git re PR fortran/64124 ([F95] Valid constant expr rejected) 2018-03-07 Steven G. Kargl PR fortran/64124 PR fortran/70409 * decl.c (gfc_match_char_spec): Try to reduce a charlen to a constant. 2018-03-07 Steven G. Kargl PR fortran/64124 PR fortran/70409 * gfortran.dg/pr64124.f90: New tests. * gfortran.dg/pr70409.f90: New tests. From-SVN: r258347 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f87cce8c084..796b58dd6f3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-03-07 Steven G. Kargl + + PR fortran/64124 + PR fortran/70409 + * decl.c (gfc_match_char_spec): Try to reduce a charlen to a constant. + 2017-03-06 Thomas Koenig PR fortran/84697 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index dcfda27a3c6..160964399fc 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -3147,7 +3147,24 @@ done: if (seen_length == 0) cl->length = gfc_get_int_expr (gfc_charlen_int_kind, NULL, 1); else - cl->length = len; + { + /* 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 (len && len->expr_type != EXPR_CONSTANT) + { + gfc_expr *e; + e = gfc_copy_expr (len); + gfc_reduce_init_expr (e); + if (e->expr_type == EXPR_CONSTANT) + gfc_replace_expr (len, e); + else + gfc_free_expr (e); + cl->length = len; + } + else + cl->length = len; + } ts->u.cl = cl; ts->kind = kind == 0 ? gfc_default_character_kind : kind; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 080164d421a..d795f0d9a71 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-03-07 Steven G. Kargl + + PR fortran/64124 + PR fortran/70409 + * gfortran.dg/pr64124.f90: New tests. + * gfortran.dg/pr70409.f90: New tests. + 2018-03-07 Segher Boessenkool PR target/82411 diff --git a/gcc/testsuite/gfortran.dg/pr64124.f90 b/gcc/testsuite/gfortran.dg/pr64124.f90 new file mode 100644 index 00000000000..349c20de204 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr64124.f90 @@ -0,0 +1,5 @@ +! { dg-do compile } +! PR fortran/64124.f90 + character(len=kind(1)) x + integer(len(x)) y + end diff --git a/gcc/testsuite/gfortran.dg/pr70409.f90 b/gcc/testsuite/gfortran.dg/pr70409.f90 new file mode 100644 index 00000000000..0372f6e9632 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr70409.f90 @@ -0,0 +1,23 @@ +! { dg-do run } +! PR fortran/70409 +! Contriubted by Harald Anlauf +program foo + integer, parameter :: huge_1 = huge(0_1) + character( huge_1 ), parameter :: x = 'abc' + character( huge(0_1) ), parameter :: y = 'abc' + character( huge(0_1)+0 ), parameter :: z = 'abcdef' + character( huge(0_1) ) :: a = 'abc' + integer, parameter :: huge_2 = huge(0_2) + character( huge_2 ), parameter :: u = 'abc' + character( huge(0_2) ), parameter :: v = 'abc' + character(int(huge(0_2),4)), parameter :: w = 'abcdef' + character( huge(0_2) ) :: b = 'abc' + if (len(x) /= huge_1) stop 1 + if (len(y) /= huge_1) stop 2 + if (len(z) /= huge_1) stop 3 + if (len(a) /= huge_1) stop 4 + if (len(u) /= huge_2) stop 5 + if (len(v) /= huge_2) stop 6 + if (len(w) /= huge_2) stop 7 + if (len(b) /= huge_2) stop 8 +end program foo