aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2007-06-30 13:08:19 +0000
committerPaul Thomas <pault@gcc.gnu.org>2007-06-30 13:08:19 +0000
commit64f4bedf7ec92fe4afc7b666aa90363274713c3b (patch)
treeb41c5295a35ac928f337c34969abfcfe8e43472d /gcc
parent1760a1a86bf459482fff422ef2e3fed4f28ac910 (diff)
downloadgcc-64f4bedf7ec92fe4afc7b666aa90363274713c3b.zip
gcc-64f4bedf7ec92fe4afc7b666aa90363274713c3b.tar.gz
gcc-64f4bedf7ec92fe4afc7b666aa90363274713c3b.tar.bz2
re PR fortran/32472 (ICE in trans-const.c:106 for REPEAT initialization expression of non-parameter)
2007-06-30 Paul Thomas <pault@gcc.gnu.org> PR fortran/32472 * simplify.c (gfc_simplify_repeat): Add handling of character literal for first argument. 2007-06-30 Paul Thomas <pault@gcc.gnu.org> PR fortran/30284 * gfortran.dg/repeat_f90: New test. From-SVN: r126147
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/simplify.c37
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/repeat_5.f909
3 files changed, 43 insertions, 8 deletions
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 87fe6f1..9dd3084 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 f97e1e0..5a76345 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-06-30 Paul Thomas <pault@gcc.gnu.org>
+
+ PR fortran/30284
+ * gfortran.dg/repeat_f90: New test.
+
2007-06-30 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
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 0000000..48acea5
--- /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 <burnus@gcc.gnu.org>
+!
+ CHARACTER(len=1025) :: string2 = repeat('?',1025)
+ print *, string2
+end