re PR fortran/32472 (ICE in trans-const.c:106 for REPEAT initialization expression...
authorPaul Thomas <pault@gcc.gnu.org>
Sat, 30 Jun 2007 13:08:19 +0000 (13:08 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sat, 30 Jun 2007 13:08:19 +0000 (13:08 +0000)
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

gcc/fortran/simplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/repeat_5.f90 [new file with mode: 0644]

index 87fe6f1..9dd3084 100644 (file)
@@ -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);
index f97e1e0..5a76345 100644 (file)
@@ -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 (file)
index 0000000..48acea5
--- /dev/null
@@ -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