This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Re: [Patch, Fortran, pr60322] was: [Patch 1/2, Fortran, pr60322] [OOP] Incorrect bounds on polymorphic dummy array


Dear Andre,

Everything works as expected with your new patch. 

I have changed the test for pr57305 to

use iso_c_binding
implicit none
integer :: i
real, target :: e
class(*), allocatable, target :: a(:)
do i = 1, 3
  e = i 
  call add_element_poly(a,e)
  select type (a)
    type is (real)
      print *, a
  end select
end do
contains
    subroutine add_element_poly(a,e)
      use iso_c_binding
      class(*),allocatable,intent(inout),target :: a(:)
      class(*),intent(in),target :: e
      class(*),allocatable,target :: tmp(:)
      type(c_ptr) :: dummy
      
      interface
        function memcpy(dest,src,n) bind(C,name="memcpy") result(res)
          import
          type(c_ptr) :: res
          integer(c_intptr_t),value :: dest
          integer(c_intptr_t),value :: src
          integer(c_size_t),value :: n
        end function
      end interface

      if (.not.allocated(a)) then
        allocate(a(1), source=e)
      else
        allocate(tmp(size(a)),source=a)
        deallocate(a)
        allocate(a(size(tmp)+1),mold=e)
        dummy = memcpy(loc(a(1)),loc(tmp),sizeof(tmp))
        dummy = memcpy(loc(a(size(tmp)+1)),loc(e),sizeof(e))
      end if
    end subroutine
end

and get the expected outputs at run time (it works also if I replace MOLD with SOURCE and remove the second âdummy = ââ line).

Thanks for your patience,

Dominique

> Le 25 mars 2015 Ã 17:56, Andre Vehreschild <vehre@gmx.de> a Ãcrit :
> 
> Hi Dominique, hi all,
> 
> you are absolutely right, Dominique: I missed the part of pr60322_base_*. 
> 
> But this time it is there and furthermore does solve the allocate( mold=e) and
> the loc(e) issue. 
> 
> Paul: I have simplified your patch by only checking whether the
> arg_expr.ts.type == BT_CLASS. All tests showed, that this enough to produce the
> correct code.
> 
> Bootstraps and regtests ok on x86_64-linux-gnu/F20. 
> 
> Comments, please!
> 
> Regards,
> 	Andre
> 
> On Wed, 25 Mar 2015 10:43:34 +0100
> Dominique d'HumiÃres <dominiq@lps.ens.fr> wrote:


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