[Bug fortran/38915] New: wrong results for structure assignment of character components when left and right sides overlap

dick dot hendrickson at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Jan 19 17:52:00 GMT 2009


The following program gives the wrong results for the character assignments to
a structure component.  The problem appears to occur when there is an overlap
between the left and right hand sides of the assignment.  It is "as if" the
character length of the right hand side is treated as 1, rather than 9, and
then the left is blank padded to 9.  While experimenting with this, I tried
some simple things like L(1:2)%c = R(2:3)%c and they all worked.

Dick Hendrickson

       program cg0033_41

! fails on Windows XP
! gcc version 4.4.0 20081219 (experimental) [trunk revision 142842] (GCC)

       type t
         sequence
         integer i
         character(len=9) c
       end type t

       type (t)  L(3),R(3), LL(4), RR(4)
       EQUIVALENCE (L,LL)

       integer nfv1(3), nfv2(3)

       R(1)%c = '123456789'
       R(2)%c = 'abcdefghi'
       R(3)%c = '!@#$%^&*('

       L%c = R%c
       print *, 'simple assignment'
       print *,  R%c
       print *,  L%c

       LL(1:3)%c = R%c
       LL(4)%c = 'QWERTYUIO'
       RR%c = LL%c

       L%c = LL(2:4)%c

       print *
       print *, 'overlapping assignment'
       print *,  RR(2:4)%c
       print *,  L%c

       nfv1 = (/1,2,3/)
       nfv2 = nfv1
       L%c = R%c
       L(nfv1)%c = L(nfv2)%c
       print *
       print *, ' vvs assignment'
       print *,  R%c
       print *,  L%c

       end


C:\gfortran>gfortran try_cg0033_41.f

C:\gfortran>a
 simple assignment
 123456789abcdefghi!@#$%^&*(
 123456789abcdefghi!@#$%^&*(

 overlapping assignment
 abcdefghi!@#$%^&*(QWERTYUIO
 a        !        Q

  vvs assignment
 123456789abcdefghi!@#$%^&*(
 1        a        !


-- 
           Summary: wrong results for structure assignment of character
                    components when left and right sides overlap
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dick dot hendrickson at gmail dot com


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



More information about the Gcc-bugs mailing list