From 64f4bedf7ec92fe4afc7b666aa90363274713c3b Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Sat, 30 Jun 2007 13:08:19 +0000 Subject: [PATCH] re PR fortran/32472 (ICE in trans-const.c:106 for REPEAT initialization expression of non-parameter) 2007-06-30 Paul Thomas PR fortran/32472 * simplify.c (gfc_simplify_repeat): Add handling of character literal for first argument. 2007-06-30 Paul Thomas PR fortran/30284 * gfortran.dg/repeat_f90: New test. From-SVN: r126147 --- gcc/fortran/simplify.c | 37 ++++++++++++++++++++------ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/repeat_5.f90 | 9 +++++++ 3 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/repeat_5.f90 diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 87fe6f14708..9dd308425c2 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -2858,6 +2858,7 @@ gfc_simplify_repeat (gfc_expr *e, gfc_expr *n) gfc_expr *result; int i, j, len, ncop, nlen; mpz_t ncopies; + bool have_length = false; /* If NCOPIES isn't a constant, there's nothing we can do. */ if (n->expr_type != EXPR_CONSTANT) @@ -2872,29 +2873,49 @@ gfc_simplify_repeat (gfc_expr *e, gfc_expr *n) } /* If we don't know the character length, we can do no more. */ - if (e->ts.cl == NULL || e->ts.cl->length == NULL - || e->ts.cl->length->expr_type != EXPR_CONSTANT) + if (e->ts.cl && e->ts.cl->length + && e->ts.cl->length->expr_type == EXPR_CONSTANT) + { + len = mpz_get_si (e->ts.cl->length->value.integer); + have_length = true; + } + else if (e->expr_type == EXPR_CONSTANT + && (e->ts.cl == NULL || e->ts.cl->length == NULL)) + { + len = e->value.character.length; + } + else return NULL; /* If the source length is 0, any value of NCOPIES is valid and everything behaves as if NCOPIES == 0. */ mpz_init (ncopies); - if (mpz_sgn (e->ts.cl->length->value.integer) == 0) + if (len == 0) mpz_set_ui (ncopies, 0); else mpz_set (ncopies, n->value.integer); /* Check that NCOPIES isn't too large. */ - if (mpz_sgn (e->ts.cl->length->value.integer) != 0) + if (len) { - mpz_t max; + mpz_t max, mlen; int i; /* Compute the maximum value allowed for NCOPIES: huge(cl) / len. */ mpz_init (max); i = gfc_validate_kind (BT_INTEGER, gfc_charlen_int_kind, false); - mpz_tdiv_q (max, gfc_integer_kinds[i].huge, - e->ts.cl->length->value.integer); + + if (have_length) + { + mpz_tdiv_q (max, gfc_integer_kinds[i].huge, + e->ts.cl->length->value.integer); + } + else + { + mpz_init_set_si (mlen, len); + mpz_tdiv_q (max, gfc_integer_kinds[i].huge, mlen); + mpz_clear (mlen); + } /* The check itself. */ if (mpz_cmp (ncopies, max) > 0) @@ -2915,7 +2936,7 @@ gfc_simplify_repeat (gfc_expr *e, gfc_expr *n) if (e->expr_type != EXPR_CONSTANT) return NULL; - if (mpz_sgn (e->ts.cl->length->value.integer) != 0) + if (len || mpz_sgn (e->ts.cl->length->value.integer) != 0) { const char *res = gfc_extract_int (n, &ncop); gcc_assert (res == NULL); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f97e1e06d8e..5a763456aea 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-06-30 Paul Thomas + + PR fortran/30284 + * gfortran.dg/repeat_f90: New test. + 2007-06-30 Manuel Lopez-Ibanez PR testsuite/25241 diff --git a/gcc/testsuite/gfortran.dg/repeat_5.f90 b/gcc/testsuite/gfortran.dg/repeat_5.f90 new file mode 100644 index 00000000000..48acea53f1c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/repeat_5.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! +! PR32472 -- character literals were not implemented in REPEAT. +! +! Contributed by Tobias Burnus +! + CHARACTER(len=1025) :: string2 = repeat('?',1025) + print *, string2 +end -- 2.30.2