[Bug fortran/51634] [OOP] ICE with polymorphic operators
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51634 janus at gcc dot gnu.org changed: What|Removed |Added CC||janus at gcc dot gnu.org Target Milestone|--- |4.7.0
[Bug fortran/51634] [OOP] ICE with polymorphic operators
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51634 Tobias Burnus changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||FIXED --- Comment #4 from Tobias Burnus 2012-01-19 08:13:13 UTC --- FIXED on the trunk (4.7). Thanks for the patch, Paul!
[Bug fortran/51634] [OOP] ICE with polymorphic operators
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51634 --- Comment #3 from Paul Thomas 2012-01-18 20:52:51 UTC --- Author: pault Date: Wed Jan 18 20:52:48 2012 New Revision: 183287 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183287 Log: 2012-01-18 Paul Thomas PR fortran/51634 * trans-expr.c (gfc_conv_procedure_call): Deallocate allocatable components of temporary class arguments. 2012-01-18 Paul Thomas PR fortran/51634 * gfortran.dg/typebound_operator_12.f03: New. * gfortran.dg/typebound_operator_13.f03: New. Added: trunk/gcc/testsuite/gfortran.dg/typebound_operator_12.f03 trunk/gcc/testsuite/gfortran.dg/typebound_operator_13.f03 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-expr.c trunk/gcc/testsuite/ChangeLog
[Bug fortran/51634] [OOP] ICE with polymorphic operators
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51634 --- Comment #2 from Tobias Burnus 2012-01-13 22:17:53 UTC --- (In reply to comment #1) > Fixed on trunk as long as explicit allocations are inserted, as below. > I will raise a separate PR for the lack of automatic allocate on assign for > class objects with derived type components. The test case now works since the commit of PR 48351 (and thus I closed PR 51733). The following allocates of comment 1 are still needed, though - otherwise the code is invalid: function multiply(lhs,rhs) allocate(multiply) program main allocate (g%f(2), source = [1.0, 2.0]) * * * Unfortunately, the original program still fails. New test case; produces with ifort 12.1: 6.00 12.0 18.0 24.0 30.0 36.0 Fails with gfortran at: Invalid free() / delete / delete[] / realloc() at 0x4C28C3E: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x401BD0: MAIN__ (test.f90:34) The "free" issue only occurs for: fireworks = fireworks + fireworks * dt It works with fireworks = fireworks + fireworks or with fireworks = fireworks * dt I am not sure why it fails, but the following looks a bit odd: struct soop_stars D.1952; class.8._data = (struct soop_stars *) &D.1952; ... if (class.8.position.data != 0B) __builtin_free ((void *) class.8.position.data); Shouldn't that be: "class.8._data.position.data" (not the "_data")? module soop_stars_class implicit none type soop_stars real, dimension(:), allocatable :: position,velocity contains procedure :: total procedure :: product generic :: operator(+) => total generic :: operator(*) => product end type contains type(soop_stars) function product(lhs,rhs) class(soop_stars) ,intent(in) :: lhs real ,intent(in) :: rhs product%position = lhs%position*rhs product%velocity = lhs%velocity*rhs end function type(soop_stars) function total(lhs,rhs) class(soop_stars) ,intent(in) :: lhs,rhs total%position = lhs%position + rhs%position total%velocity = lhs%velocity + rhs%velocity end function end module program main use soop_stars_class ,only : soop_stars implicit none type(soop_stars) :: fireworks real :: dt fireworks%position = [1,2,3] fireworks%velocity = [4,5,6] dt = 5 fireworks = fireworks + fireworks*dt print *, fireworks%position print *, fireworks%velocity end program
[Bug fortran/51634] [OOP] ICE with polymorphic operators
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51634 Paul Thomas changed: What|Removed |Added CC||pault at gcc dot gnu.org --- Comment #1 from Paul Thomas 2012-01-02 13:28:13 UTC --- Fixed on trunk as long as explicit allocations are inserted, as below. I will raise a separate PR for the lack of automatic allocate on assign for class objects with derived type components. Thanks for the report. Paul module field_module implicit none private public :: field type :: field real, allocatable :: f(:) contains procedure :: multiply_real => multiply procedure :: copy => copy_field generic :: operator(*)=> multiply_real generic :: assignment(=) => copy end type contains subroutine copy_field (lhs, rhs) class(field), intent(inout) :: lhs class(field), intent(in) :: rhs if (allocated (lhs%f)) deallocate (lhs%f) allocate (lhs%f(size (rhs%f, 1))) lhs%f = rhs%f end subroutine function multiply(lhs,rhs) class(field) ,intent(in) :: lhs real ,intent(in) :: rhs class(field) ,allocatable :: multiply integer :: i allocate(multiply, source = field([(0.0, i = 1, size (lhs%f, 1))])) multiply%f = lhs%f * rhs end function end module field_module program main use field_module implicit none type(field) :: f, g real :: dt, half allocate (g%f(2), source = [1.0, 2.0]) dt = 7 half = 0.5 f = g * dt * half print *, f%f end program main