[Bug libfortran/21459] strings of different length in a single character(len=*) declaration

2005-05-11 Thread tobi at gcc dot gnu dot org

--- Additional Comments From tobi at gcc dot gnu dot org  2005-05-11 20:24 
---
The problem is that all characters declared on the same line share the same
gfc_charlen structure.  This should be fixed during resolution, I'll have a look
at this.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21459


[Bug libfortran/21459] strings of different length in a single character(len=*) declaration

2005-05-11 Thread tobi at gcc dot gnu dot org

--- Additional Comments From tobi at gcc dot gnu dot org  2005-05-11 20:45 
---
This patch passes the testsuite and fixes the bug, but creates a memory leak:

   * decl.c (add_init_expr_to_sym): Create new gfc_charlen for each
   item with length = (*)

Index: decl.c
===
RCS file: /cvs/gcc/gcc/gcc/fortran/decl.c,v
retrieving revision 1.35
diff -u -p -r1.35 decl.c
--- decl.c  29 Apr 2005 15:31:37 -  1.35
+++ decl.c  11 May 2005 20:39:13 -
@@ -740,6 +740,11 @@ add_init_expr_to_sym (const char *name,
  /* Update symbol character length according initializer.  */
  if (sym-ts.cl-length == NULL)
{
+ /* If there are multiple CHARACTER variables declared on
+the same line, we don't want them to share the same
+length.  */
+ sym-ts.cl = gfc_get_charlen ();
+
  if (init-expr_type == EXPR_CONSTANT)
sym-ts.cl-length =
gfc_int_expr (init-value.character.length);

In order to evade the memory leak, we should instead of setting
sym-ts.cl-length = NULL, set sym-ts.cl = gfc_unknown_charlen, where the
latter is a new global placeholder variable, and then fill in sym-ts.cl as I
did in the patch.  I've seen something like this in g95, but I don't remember if
this was what it was used for there.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21459


[Bug libfortran/21459] strings of different length in a single character(len=*) declaration

2005-05-09 Thread fxcoudert at gcc dot gnu dot org

--- Additional Comments From fxcoudert at gcc dot gnu dot org  2005-05-09 
11:15 ---
Reduced testcase is following. The root of the problem is that when we declare
strings of different length in the same character(len=*) declaration, all
strings are truncated to the length of the first one. Example:

$ cat pr21459.f90
  character(len=*) :: c1='12345', c2='123456789'
  print *, c1
  print *, c2
  end
$ gfortran pr21459.f90  ./a.out
 12345
 12345

-- 
   What|Removed |Added

 CC||fxcoudert at gcc dot gnu dot
   ||org
OtherBugsDependingO||19276
  nThis||
 Status|UNCONFIRMED |NEW
 Ever Confirmed||1
   Last reconfirmed|-00-00 00:00:00 |2005-05-09 11:15:34
   date||
Summary|Fortran runtime error:  |strings of different length
   |Unexpected end of format|in a single character(len=*)
   |string  |declaration


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21459