[Bug fortran/56596] New: Invalid read of size 4 gfortran.dg/class_array_7.f03
dominiq at lps dot ens.fr
gcc-bugzilla@gcc.gnu.org
Mon Mar 11 13:54:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56596
Bug #: 56596
Summary: Invalid read of size 4 gfortran.dg/class_array_7.f03
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: dominiq@lps.ens.fr
Running gfortran.dg/class_array_7.f03 under valgrind gives
==54979== Invalid read of size 4
==54979== at 0x100001731: __realloc_MOD_assign (class_array_7.f03:25)
==54979== by 0x100001629: __realloc_MOD_reallocate (class_array_7.f03:33)
==54979== by 0x1000019D8: MAIN__ (class_array_7.f03:55)
==54979== by 0x100001B7D: main (class_array_7.f03:49)
==54979== Address 0x10044a408 is 0 bytes after a block of size 40 alloc'd
==54979== at 0x100013679: malloc (vg_replace_malloc.c:266)
==54979== by 0x1000017E0: MAIN__ (class_array_7.f03:53)
==54979== by 0x100001B7D: main (class_array_7.f03:49)
==54979==
==54979==
==54979== HEAP SUMMARY:
==54979== in use at exit: 88 bytes in 1 blocks
==54979== total heap usage: 25 allocs, 24 frees, 7,061 bytes allocated
==54979==
==54979== LEAK SUMMARY:
==54979== definitely lost: 0 bytes in 0 blocks
==54979== indirectly lost: 0 bytes in 0 blocks
==54979== possibly lost: 0 bytes in 0 blocks
==54979== still reachable: 0 bytes in 0 blocks
==54979== suppressed: 88 bytes in 1 blocks
==54979==
==54979== For counts of detected and suppressed errors, rerun with: -v
==54979== ERROR SUMMARY: 5 errors from 1 contexts (suppressed: 0 from 0)
The test also aborts if it is compiled with -fsanitize=address.
Reduced test
module realloc
implicit none
type :: base_type
integer :: i
contains
procedure :: assign
generic :: assignment(=) => assign ! define generic assignment
end type base_type
type, extends(base_type) :: extended_type
integer :: j
end type extended_type
contains
elemental subroutine assign (a, b)
class(base_type), intent(out) :: a
class(base_type), intent(in) :: b
a%i = b%i
end subroutine assign
subroutine reallocate (a)
class(extended_type), dimension(:), allocatable :: tmp
class(base_type), dimension(:), allocatable, intent(inout) :: a
allocate (extended_type :: tmp (size (a))) ! how to alloc b with same type
as a ?
tmp = a ! polymorphic l.h.s.
call move_alloc (from=tmp, to=a)
end subroutine reallocate
end module realloc
program main
use realloc
implicit none
class(base_type), dimension(:), allocatable :: a
allocate (extended_type :: a(10))
call reallocate (a)
end program main
More information about the Gcc-bugs
mailing list