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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.06.08 22:12:30
                 CC|                            |pault at gcc dot gnu.org
     Ever Confirmed|0                           |1
      Known to fail|                            |4.3.4, 4.4.0, 4.5.1, 4.6.0,
                   |                            |4.7.0
           Severity|normal                      |major

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-06-08 
22:12:30 UTC ---
First: The module http://www.fortran.com/iso_varying_string.f95 is invalid, cf.
PR 49331. (That shouldn't affect this PR.)

Secondly, there seems to be a serious bug in gfortran - and several other
compilers - in the handling of constructors of derived types with allocatable
components. With gfortran, I see three bugs for the following program:

- There is no reallocate on assignment
- The memory is multiple times freed for a normal constructor
- With reshape, the result is wrong (+ one has an invalid free)

Expected: With and without the explicit allocate of z and z2, the program
should print:
 11 11 22 22 22
 11 11 22 22 22

Actual result (w/ explicit allocate)
          11          11          22          22          22
           0           0           0           0  -202116348
  (Plus segfault)


implicit none
type t
  integer, allocatable :: A(:)
end type t

type(t) :: x, y
type(t), allocatable :: z(:), z2(:)

allocate (x%A(2))
allocate (y%A(3))
x%A = 11
y%A = 22

! BUG 1: Realloc LHS does not work,
! hence the following lines are required:
allocate (z(2))
allocate (z2(2))

z = [ x, y ]
print *, z(1)%a, z(2)%a  ! OK, if allocated

! BUG 2: Crash with invalid FREE at the the program

! BUG 3: The following produces garbage
z2 = reshape ([ x, y ], [ 2 ])
print *, z2(1)%a, z2(2)%a
end

Reply via email to