------- Comment #2 from dominiq at lps dot ens dot fr  2007-11-13 15:08 -------
Reduced test case:

module TransferBug

   type ByteType
      character(len=1)                                  :: singleByte
   end type

contains

   subroutine BytesToString(bytes, string)
      type (ByteType), intent(in)                       :: bytes(:)
      character(len=*), intent(out)                     :: string
      string = 'Hi! '
!      print *, len(trim(string))  !  <-- works
      print *, len(transfer(bytes, string)) ! <-- gives garbage (crash with
g95)
   end subroutine

end module

program main
   use TransferBug
   character(len=100) :: str
   type (ByteType)                                   :: bytes(4)
   bytes = (/ByteType('t'), ByteType('e'), ByteType('s'), ByteType('t')/)
   call BytesToString( bytes, str )
   print *, trim(str)   ! This should print 'Hi!'
end program

[karma] f90/bug% gfc -fbounds-check pr34080_red.f90
[karma] f90/bug% a.out 
           0
 0låŨ0l0 ]Q(Ô¿ÿà`á
d
[karma] f90/bug% pgfc -fbounds-check pr34080_red.f90
[karma] f90/bug% a.out
         100
 Hi!

If I exchange the commented print lines, the code works. So the bug is related
to transfer, but apparently through some memory leak and not due to its result.


-- 


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

Reply via email to