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

            Bug ID: 59252
           Summary: wrong code generation for allocatable dummy arguments
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arnaud02 at users dot sourceforge.net

module branch_plot_results_mod
  implicit none

  type branch_plot_results_ppv_type
     sequence
     real(8)       , allocatable  :: v(:)
     integer                     :: handle = 0
     character(256), allocatable :: label
  end type branch_plot_results_ppv_type

  type branch_plot_results_type
     sequence
     type(branch_plot_results_ppv_type), allocatable :: appv(:)
     integer                                         :: end_appv = 0
  end type branch_plot_results_type

contains
  subroutine construct_branch_plot_results(res)
    type (branch_plot_results_type), allocatable, intent(inout) :: res
    if(.not.allocated(res)) allocate(res)
  end subroutine construct_branch_plot_results

  subroutine construct_branch_plot_results_appv(appv,asize)
    type(branch_plot_results_ppv_type), allocatable, intent(inout) :: appv(:) 
    integer                                        , intent(in   ) :: asize

    if(allocated(appv)) then
       if(asize.ne.size(appv)) then
          deallocate(appv)
       endif
    endif
    if(.not.allocated(appv)) then
       allocate(appv(asize)) 
    endif
  end subroutine construct_branch_plot_results_appv

end module branch_plot_results_mod
program testy
  use branch_plot_results_mod

  type(branch_plot_results_type), allocatable :: res

  call construct_branch_plot_results(res)
  call construct_branch_plot_results_appv(res%appv, 20)
end program testy

While compiling the program above, gfortran 4.8.2 on Linux x86_64 produces an
executable that results in the run-time error below:
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Valgrind points to the following error:
==24773== Use of uninitialised value of size 8
==24773==    at 0x401F37:
__branch_plot_results_mod_MOD_construct_branch_plot_results_appv (b2.f90:33)
==24773==    by 0x402222: MAIN__ (b2.f90:44)
==24773==    by 0x402393: main (b2.f90:39)
==24773==

I suspect that gfortran does not support allocatable dummy arguments properly
in this case.

Reply via email to