public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/47523] New: Wrong length in I/O deferred allocatable scalar character
@ 2011-01-28 20:59 tkoenig at gcc dot gnu.org
  2011-01-28 21:15 ` [Bug fortran/47523] Concatenation with deferred length character with lhs variable tkoenig at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-01-28 20:59 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Wrong length in I/O deferred allocatable scalar
                    character
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tkoenig@gcc.gnu.org
                CC: pault@gcc.gnu.org


Hi Paul,

sorry to be the first one to find a bug in your really cool
deferred length allocatable scalars.

Test case:

ig25@linux-fd1f:~/Krempel/Char-alloc> cat foo.f90
program main
  implicit none
  character(:), allocatable :: a, b
  a = 'a'
  print '(A)', a
  a = a // 'x'
  print '(A,A)',a
  print *,len(a)
end program main
ig25@linux-fd1f:~/Krempel/Char-alloc> gfortran foo.f90
ig25@linux-fd1f:~/Krempel/Char-alloc> ./a.out
a
a
           2

Output should be

a
ax
           2

The last line shows the length is correct, maybe it's just the
interaction with the library.  I will investigate a bit more.


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

* [Bug fortran/47523] Concatenation with deferred length character with lhs variable
  2011-01-28 20:59 [Bug fortran/47523] New: Wrong length in I/O deferred allocatable scalar character tkoenig at gcc dot gnu.org
@ 2011-01-28 21:15 ` tkoenig at gcc dot gnu.org
  2011-01-28 22:05 ` burnus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-01-28 21:15 UTC (permalink / raw)
  To: gcc-bugs

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

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Wrong length in I/O         |Concatenation with deferred
                   |deferred allocatable scalar |length character with lhs
                   |character                   |variable

--- Comment #1 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-01-28 20:58:49 UTC ---
Actually, it isn't a wrong length, the problem was an
invisible nul character in the output.

Look at this:

program main
  implicit none
  integer :: i
  character(:), allocatable :: a, b, c
  a = 'a'
  a = a // 'x'
  b = 'b'
  c = b // 'x'
  write (*,*) 'a is:'
  do i=1,len(a)
    write (*,*) ichar(a(i:i))
  end do

  write (*,*) 'c is:'
  do i=1,len(c)
     write (*,*) ichar(c(i:i))
  end do
end program main
ig25@linux-fd1f:~/Krempel/Char-alloc> gfortran bar.f90
ig25@linux-fd1f:~/Krempel/Char-alloc> ./a.out
 a is:
          97
           0
 c is:
          98
         120

The expression a = a // 'x' gets the wrong value for x.


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

* [Bug fortran/47523] Concatenation with deferred length character with lhs variable
  2011-01-28 20:59 [Bug fortran/47523] New: Wrong length in I/O deferred allocatable scalar character tkoenig at gcc dot gnu.org
  2011-01-28 21:15 ` [Bug fortran/47523] Concatenation with deferred length character with lhs variable tkoenig at gcc dot gnu.org
@ 2011-01-28 22:05 ` burnus at gcc dot gnu.org
  2011-01-29 16:30 ` pault at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-01-28 22:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-01-28 21:04:40 UTC ---
I think I/O is OK - the issue is probably the same as PR 47519: Mishandling of
intrinsic operations. Though, this case looks a bit different than the other
PR.

void
concat_string (gfc_charlen_type destlen, CHARTYPE * dest,
               gfc_charlen_type len1, const CHARTYPE * s1,
               gfc_charlen_type len2, const CHARTYPE * s2)

But for   a = a // 'x'


        if (a != 0B) goto L.3;
        L.3:;
        a = (character(kind=1)[1:.a] *) __builtin_realloc ((void *) a,
(<unnamed-unsigned:64>) (.a + 1));
        L.4:;
        .a = .a + 1;
        D.1536 = (.a + 1) * 64;
        D.1537 = (void * restrict) __builtin_malloc (MAX_EXPR
<(<unnamed-unsigned:64>) D.1536, 1>);
        pstr.0 = (character(kind=1)[1:] *) D.1537;
        _gfortran_concat_string (.a + 1, pstr.0, .a, a, 1, &"x"[1]{lb: 1 sz:
1});

Thus, one first allocates "a", increments the length and then uses as "s1"
argument to the intrinsic. That cannot work ...


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

* [Bug fortran/47523] Concatenation with deferred length character with lhs variable
  2011-01-28 20:59 [Bug fortran/47523] New: Wrong length in I/O deferred allocatable scalar character tkoenig at gcc dot gnu.org
  2011-01-28 21:15 ` [Bug fortran/47523] Concatenation with deferred length character with lhs variable tkoenig at gcc dot gnu.org
  2011-01-28 22:05 ` burnus at gcc dot gnu.org
@ 2011-01-29 16:30 ` pault at gcc dot gnu.org
  2011-01-30 18:10 ` pault at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2011-01-29 16:30 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.01.29 14:58:37
         AssignedTo|unassigned at gcc dot       |pault at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #3 from Paul Thomas <pault at gcc dot gnu.org> 2011-01-29 14:58:37 UTC ---
I have a patch cooking - thanks for the report Thomas!

Paul


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

* [Bug fortran/47523] Concatenation with deferred length character with lhs variable
  2011-01-28 20:59 [Bug fortran/47523] New: Wrong length in I/O deferred allocatable scalar character tkoenig at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-01-29 16:30 ` pault at gcc dot gnu.org
@ 2011-01-30 18:10 ` pault at gcc dot gnu.org
  2011-01-30 18:19 ` pault at gcc dot gnu.org
  2011-02-02 18:16 ` dnovillo at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2011-01-30 18:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paul Thomas <pault at gcc dot gnu.org> 2011-01-30 17:50:07 UTC ---
Author: pault
Date: Sun Jan 30 17:50:01 2011
New Revision: 169413

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169413
Log:
2011-01-30  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/47523
    * trans-expr.c (gfc_trans_assignment_1): If the rhs is an op
    expr and is assigned to a deferred character length scalar,
    make sure that the function is called before reallocation,
    so that the length is available. Include procedure pointer
    and procedure pointer component rhs as well.

2011-01-30  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/47523
    * trans-expr.c (gfc_trans_assignment_1): If the rhs is an op
    expr and is assigned to a deferred character length scalar,
    make sure that the function is called before reallocation,
    so that the length is available. Include procedure pointer
    and procedure pointer component rhs as well.

    PR fortran/45170
    PR fortran/35810
    PR fortran/47350
    * gfortran.dg/allocatable_function_5.f90: New test not added by
    mistake on 2011-01-28.



Added:
    trunk/gcc/testsuite/gfortran.dg/allocatable_function_5.f90
    trunk/gcc/testsuite/gfortran.dg/realloc_on_assign_5.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug fortran/47523] Concatenation with deferred length character with lhs variable
  2011-01-28 20:59 [Bug fortran/47523] New: Wrong length in I/O deferred allocatable scalar character tkoenig at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-01-30 18:10 ` pault at gcc dot gnu.org
@ 2011-01-30 18:19 ` pault at gcc dot gnu.org
  2011-02-02 18:16 ` dnovillo at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2011-01-30 18:19 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #5 from Paul Thomas <pault at gcc dot gnu.org> 2011-01-30 17:56:22 UTC ---
Fixed on trunk.

Thanks, Thomas :-)

Cheers

Paul


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

* [Bug fortran/47523] Concatenation with deferred length character with lhs variable
  2011-01-28 20:59 [Bug fortran/47523] New: Wrong length in I/O deferred allocatable scalar character tkoenig at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2011-01-30 18:19 ` pault at gcc dot gnu.org
@ 2011-02-02 18:16 ` dnovillo at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: dnovillo at gcc dot gnu.org @ 2011-02-02 18:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Diego Novillo <dnovillo at gcc dot gnu.org> 2011-02-02 18:04:31 UTC ---
Author: dnovillo
Date: Wed Feb  2 18:04:21 2011
New Revision: 169697

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169697
Log:
2011-01-30  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/47523
    * trans-expr.c (gfc_trans_assignment_1): If the rhs is an op
    expr and is assigned to a deferred character length scalar,
    make sure that the function is called before reallocation,
    so that the length is available. Include procedure pointer
    and procedure pointer component rhs as well.

2011-01-30  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/47523
    * trans-expr.c (gfc_trans_assignment_1): If the rhs is an op
    expr and is assigned to a deferred character length scalar,
    make sure that the function is called before reallocation,
    so that the length is available. Include procedure pointer
    and procedure pointer component rhs as well.

    PR fortran/45170
    PR fortran/35810
    PR fortran/47350
    * gfortran.dg/allocatable_function_5.f90: New test not added by
    mistake on 2011-01-28.

Added:
   
branches/google/integration/gcc/testsuite/gfortran.dg/allocatable_function_5.f90
   
branches/google/integration/gcc/testsuite/gfortran.dg/realloc_on_assign_5.f03
Modified:
    branches/google/integration/gcc/fortran/ChangeLog
    branches/google/integration/gcc/fortran/trans-expr.c
    branches/google/integration/gcc/testsuite/ChangeLog


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

end of thread, other threads:[~2011-02-02 18:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-28 20:59 [Bug fortran/47523] New: Wrong length in I/O deferred allocatable scalar character tkoenig at gcc dot gnu.org
2011-01-28 21:15 ` [Bug fortran/47523] Concatenation with deferred length character with lhs variable tkoenig at gcc dot gnu.org
2011-01-28 22:05 ` burnus at gcc dot gnu.org
2011-01-29 16:30 ` pault at gcc dot gnu.org
2011-01-30 18:10 ` pault at gcc dot gnu.org
2011-01-30 18:19 ` pault at gcc dot gnu.org
2011-02-02 18:16 ` dnovillo at gcc dot gnu.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).