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 !
Confirm. ICE with 4.1.x and 4.2.x and wrong code with 4.3.x and 4.4. Thanks for the report.
(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
See http://gcc.gnu.org/ml/fortran/2009-01/msg00331.html
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.
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
Could the patch be back-ported to 4.4 (4.3?)? TIA.
Fixed on trunk. I am prepared to backport but the mood appears to be against it. Thanks for the report. Paul