This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

TRANSFER(source with allocatable components)+Assigning the source modifies the source


?? Dear gfortran developers,

?? I stumbled on what seems to be a bug during a test run with
TRANSFER() function. A small code that produces the behavior is
attached to the end.

?? It seems that using a derived type with allocatable components as
SOURCE in TRANSFER(SOURCE, MOLD) will cause some memory allocation
problems. ?The behavior manifests itself as a scrambling of SOURCE,
but only after SOURCE is used on the right-hand side of an assignment
statement subsequent to the call to TRANSFER. ?Also, I get the
following run-time error:

?? *** glibc detected *** ./ftest.x: double free or corruption
(fasttop): 0x000000000099f010 ***

?? Notice in the code below that var1, whose values are getting
scrambled, never appears on the left-hand side of an assignment. ?The
call to TRANSFER, and the subsequent use of var1 on the right-hand
side, both seem to be necessary to see the behavior. ?Also, if the
assigment is broken into component-by-component assignment, the
problem goes away.


?? COMPILER VERSION:
?? gcc version 4.7.0 20110418 (experimental) [trunk revision 172633] (GCC)
?? Platform:
?? Ubuntu Rel. 10.10 (maverick)
?? Kernel Linux 2.6.35-28-generic
?? GNOME 2.32.0

?? intel CORE i7 - 64bit (x86_64-unknown-linux-gnu)
?? Thank you for your support and help.
?? Alipasha Sadri
?? SAMPLE CODE:

?? ? ?PROGRAM Transfertest
!------------------------------------------------------------
?? ? ?TYPE node
?? ? ? ? INTEGER, ALLOCATABLE :: comp(:)
?? ? ?END TYPE node
!------------------------------------------------------------
?? ? ?INTEGER, PARAMETER ? :: N = 3
?? ? ?INTEGER ? ? ? ? ? ? ?:: tempvar(128)
?? ? ?TYPE(node) ? ? ? ? ? :: var1(N), var2(N), var3(N)
!------------------------------------------------------------
?? ? ?DO i = 1, N
?? ? ? ? ALLOCATE(var1(i)%comp(i))
?? ? ? ? FORALL (j=1:i) var1(i)%comp(j) = 2*i+1+j
?? ? ?END DO
?? ? ?tempvar = TRANSFER(var1, tempvar)
?? ? ?var2 ? ?= TRANSFER(tempvar, var2, N)
?? ? ?var3 = var1
?? ? ?var2 = var3
!------------------------------------------------------------
?? ? ?WRITE(*,*) 'var1:', ('{',var1(i)%comp,'}', i=1,N)
?? ? ?WRITE(*,*) 'var2:', ('{',var2(i)%comp,'}', i=1,N)
?? ? ?WRITE(*,*) 'var3:', ('{',var3(i)%comp,'}', i=1,N)
! ?<<<<<SHOULD SEE IDENTICAL VALUES BUT var1 IS WRONG.>>>>>
!------------------------------------------------------------
?? ? ?END PROGRAM Transfertest


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]