User account creation filtered due to spam.

Bug 38915 - wrong results for structure assignment of character components when left and right sides overlap
Summary: wrong results for structure assignment of character components when left and ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: wrong-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2009-01-19 17:52 UTC by Dick Hendrickson
Modified: 2009-04-06 10:53 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-01-22 15:00:32


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dick Hendrickson 2009-01-19 17:52:16 UTC
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        !
Comment 1 Tobias Burnus 2009-01-19 18:49:03 UTC
Confirm. ICE with 4.1.x and 4.2.x and wrong code with 4.3.x and 4.4.

Thanks for the report.
Comment 2 Paul Thomas 2009-01-22 15:00:32 UTC
(In reply to comment #1)
> Confirm. ICE with 4.1.x and 4.2.x and wrong code with 4.3.x and 4.4.
> 
> Thanks for the report.
> 
The character length is being incorrectly set to 1 for the failing assignments; ie. the last argument of the memmove is 1.

I'm on to it.

Paul
Comment 3 Paul Thomas 2009-01-28 06:21:51 UTC
See http://gcc.gnu.org/ml/fortran/2009-01/msg00331.html
Comment 4 Dominique d'Humieres 2009-03-21 16:56:52 UTC
Copy of http://gcc.gnu.org/ml/fortran/2009-01/msg00333.html:

> Bootstrapped and regtested on FC9/x86_64 - OK for 4.5?

Works as advertised on i686-apple-darwin9 (32 and 64 bit modes) without
regression. Since the patch fixes a wrong code, should not it be commited
in 4.4 (still 2 P1)?

Thanks for the patch.

Dominique

AFAICT this patch has not been reviewed.
Comment 5 Paul Thomas 2009-03-31 20:03:48 UTC
Subject: Bug 38915

Author: pault
Date: Tue Mar 31 20:03:23 2009
New Revision: 145370

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145370
Log:
2009-03-31  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/38915
	* trans-expr.c (gfc_trans_assignment_1): Ensure temporaries
	have a string_length.

2009-03-31  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/38915
	* gfortran.dg/char_length_15.f90: New test.

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

Comment 6 Dominique d'Humieres 2009-04-04 09:14:50 UTC
Could the patch be back-ported to 4.4 (4.3?)? TIA.
Comment 7 Paul Thomas 2009-04-06 10:53:42 UTC
Fixed on trunk.  I am prepared to backport but the mood appears to be against it.

Thanks for the report.

Paul