public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/21459] New: Fortran runtime error: Unexpected end of format string
@ 2005-05-09  3:25 kamaraju at gmail dot com
  2005-05-09  3:39 ` [Bug libfortran/21459] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: kamaraju at gmail dot com @ 2005-05-09  3:25 UTC (permalink / raw)
  To: gcc-bugs

Consider the following test code

program format_string
  implicit none
  character(len=*), parameter :: rform='(F15.5)', &
  cform="(' (', F15.5, ',' F15.5, ') ')"

  call print_a_number(cform)
contains
subroutine print_a_number(style)
  character(len=*) :: style
  write(*, style) cmplx(0.0, 0.0)
end subroutine print_a_number
end program format_string

This program compiles fine. But gives a runtime error.

$gfortran-20050507-1 -v
Using built-in specs.
Target: i486-linux
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang
--prefix=/usr/lib/gcc-snapshot --enable-shared --with-system-zlib --disable-nls
--program-suffix=-20050507-1 --enable-__cxa_atexit
--enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug
--enable-java-gc=boehm --enable-java-awt=gtk --enable-mpfr --disable-werror
--disable-werror i486-linux
Thread model: posix
gcc version 4.1.0 20050507 (experimental)

$gfortran format_string.f90 -o format_string

$./a.out
At line 10 of file format_string.f90
Fortran runtime error: Unexpected end of format string
(' (',
      ^

I am using Debian Sid distribution, gcc-snapshot 20050507-1 package.

The above program compiles and runs fine with Absoft Fortran 90/95 compiler and
with intel fortran compiler 8.1 Build 20040921. The interaction with Absoft
compiler looks as follows

$f90 format_string.f90
rajulocal@kusumanchi:~/work/fortran/gfortran_bugs 28  527 11:21 PM
$./a.out
 (        0.00000,        0.00000)

-- 
           Summary: Fortran runtime error: Unexpected end of format string
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kamaraju at gmail dot com
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libfortran/21459] Fortran runtime error: Unexpected end of format string
  2005-05-09  3:25 [Bug fortran/21459] New: Fortran runtime error: Unexpected end of format string kamaraju at gmail dot com
@ 2005-05-09  3:39 ` pinskia at gcc dot gnu dot org
  2005-05-09 11:17 ` [Bug libfortran/21459] strings of different length in a single character(len=*) declaration fxcoudert at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-09  3:39 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|fortran                     |libfortran


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libfortran/21459] strings of different length in a single character(len=*) declaration
  2005-05-09  3:25 [Bug fortran/21459] New: Fortran runtime error: Unexpected end of format string kamaraju at gmail dot com
  2005-05-09  3:39 ` [Bug libfortran/21459] " pinskia at gcc dot gnu dot org
@ 2005-05-09 11:17 ` fxcoudert at gcc dot gnu dot org
  2005-05-11 20:24 ` tobi at gcc dot gnu dot org
  2005-05-11 20:45 ` tobi at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2005-05-09 11:17 UTC (permalink / raw)
  To: gcc-bugs


------- 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|0000-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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libfortran/21459] strings of different length in a single character(len=*) declaration
  2005-05-09  3:25 [Bug fortran/21459] New: Fortran runtime error: Unexpected end of format string kamaraju at gmail dot com
  2005-05-09  3:39 ` [Bug libfortran/21459] " pinskia at gcc dot gnu dot org
  2005-05-09 11:17 ` [Bug libfortran/21459] strings of different length in a single character(len=*) declaration fxcoudert at gcc dot gnu dot org
@ 2005-05-11 20:24 ` tobi at gcc dot gnu dot org
  2005-05-11 20:45 ` tobi at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: tobi at gcc dot gnu dot org @ 2005-05-11 20:24 UTC (permalink / raw)
  To: gcc-bugs


------- 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libfortran/21459] strings of different length in a single character(len=*) declaration
  2005-05-09  3:25 [Bug fortran/21459] New: Fortran runtime error: Unexpected end of format string kamaraju at gmail dot com
                   ` (2 preceding siblings ...)
  2005-05-11 20:24 ` tobi at gcc dot gnu dot org
@ 2005-05-11 20:45 ` tobi at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: tobi at gcc dot gnu dot org @ 2005-05-11 20:45 UTC (permalink / raw)
  To: gcc-bugs


------- 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 -0000      1.35
+++ decl.c      11 May 2005 20:39:13 -0000
@@ -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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-05-11 20:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-09  3:25 [Bug fortran/21459] New: Fortran runtime error: Unexpected end of format string kamaraju at gmail dot com
2005-05-09  3:39 ` [Bug libfortran/21459] " pinskia at gcc dot gnu dot org
2005-05-09 11:17 ` [Bug libfortran/21459] strings of different length in a single character(len=*) declaration fxcoudert at gcc dot gnu dot org
2005-05-11 20:24 ` tobi at gcc dot gnu dot org
2005-05-11 20:45 ` tobi at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).