re PR fortran/18082 (Infinite loop with automatic length character objects)
authorPaul Thomas <pault@gcc.gnu.org>
Wed, 12 Oct 2005 20:29:21 +0000 (20:29 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Wed, 12 Oct 2005 20:29:21 +0000 (20:29 +0000)
2005-10-12  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/18082
* decl.c (variable_decl): Make a new copy of the character
length for each variable, when the expression is not a
constant.

2005-10-12  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/18082
gfortran.dg/automatic_char_len_1.f90: New test.

From-SVN: r105329

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/automatic_char_len_1.f90 [new file with mode: 0755]

index 91acbf2e5a9549e1dcd7a640329c290123799d8d..94e2418acf6979dcd62ebd65ffe820993395c5ee 100644 (file)
@@ -1,3 +1,10 @@
+2005-10-12  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/18082
+       * decl.c (variable_decl): Make a new copy of the character
+       length for each variable, when the expression is not a
+       constant.
+
 2005-10-12  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
 
        * gfortran.h: Add bitmasks for different FPE traps. Add fpe
index 8c4ce585e43dfff02f6a4a568548c71e6862712d..20d1f8a2d20549c426b80d18e2c61b327de8add0 100644 (file)
@@ -900,7 +900,7 @@ gfc_match_null (gfc_expr ** result)
    symbol table or the current interface.  */
 
 static match
-variable_decl (void)
+variable_decl (int elem)
 {
   char name[GFC_MAX_SYMBOL_LEN + 1];
   gfc_expr *initializer, *char_len;
@@ -944,8 +944,20 @@ variable_decl (void)
          cl->length = char_len;
          break;
 
+       /* Non-constant lengths need to be copied after the first
+          element.  */
        case MATCH_NO:
-         cl = current_ts.cl;
+         if (elem > 1 && current_ts.cl->length
+               && current_ts.cl->length->expr_type != EXPR_CONSTANT)
+           {
+             cl = gfc_get_charlen ();
+             cl->next = gfc_current_ns->cl_list;
+             gfc_current_ns->cl_list = cl;
+             cl->length = gfc_copy_expr (current_ts.cl->length);
+           }
+         else
+           cl = current_ts.cl;
+
          break;
 
        case MATCH_ERROR:
@@ -1944,6 +1956,7 @@ gfc_match_data_decl (void)
 {
   gfc_symbol *sym;
   match m;
+  int elem;
 
   m = match_type_spec (&current_ts, 0);
   if (m != MATCH_YES)
@@ -1995,10 +2008,12 @@ ok:
   if (m == MATCH_NO && current_ts.type == BT_CHARACTER && old_char_selector)
     gfc_match_char (',');
 
-  /* Give the types/attributes to symbols that follow.  */
+  /* Give the types/attributes to symbols that follow. Give the element
+     a number so that repeat character length expressions can be copied.  */
+  elem = 1;
   for (;;)
     {
-      m = variable_decl ();
+      m = variable_decl (elem++);
       if (m == MATCH_ERROR)
        goto cleanup;
       if (m == MATCH_NO)
index 366ef0a073efc5cc0a873e939708efc6a581c055..7abf169d21743b9bc577a6eee48d902784e84da7 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-12  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/18082
+       gfortran.dg/automatic_char_len_1.f90: New test.
+
 2005-10-12  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/20847
diff --git a/gcc/testsuite/gfortran.dg/automatic_char_len_1.f90 b/gcc/testsuite/gfortran.dg/automatic_char_len_1.f90
new file mode 100755 (executable)
index 0000000..3ccfcb7
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR18082 - Compiler would get stuck in loop, whilst treating
+! the assignments.
+! Test is one of PR cases.
+subroutine snafu (i)
+character*(i) :: c1, c2
+c1 = ""
+c2 = ""
+end subroutine snafu
+
+