Debian Codegraph @

gcc/testsuite/gfortran.dg/finalize_57.f90

raw
1 ! { dg-do compile }
2 ! { dg-additional-options "-fdump-tree-original" }
3 !
4 ! PR fortran/90068
5 !
6 ! Contributed by Brad Richardson <[email protected]>
7 !
8
9 program array_memory_leak
10 implicit none
11
12 type, abstract :: base
13 end type base
14
15 type, extends(base) :: extended
16 end type extended
17
18 type :: container
19 class(base), allocatable :: thing
20 end type
21
22 type, extends(base) :: collection
23 type(container), allocatable :: stuff(:)
24 end type collection
25
26 call run()
27 call bad()
28 contains
29 subroutine run()
30 type(collection) :: my_thing
31 type(container) :: a_container
32
33 a_container = newContainer(newExtended()) ! This is fine
34 my_thing = newCollection([a_container])
35 end subroutine run
36
37 subroutine bad()
38 type(collection) :: my_thing
39
40 my_thing = newCollection([newContainer(newExtended())]) ! This is a memory leak
41 end subroutine bad
42
43 function newExtended()
44 type(extended) :: newExtended
45 end function newExtended
46
47 function newContainer(thing)
48 class(base), intent(in) :: thing
49 type(container) :: newContainer
50
51 allocate(newContainer%thing, source = thing)
52 end function newContainer
53
54 function newCollection(things)
55 type(container), intent(in) :: things(:)
56 type(collection) :: newCollection
57
58 newCollection%stuff = things
59 end function newCollection
60 end program array_memory_leak
61
62 ! { dg-final { scan-tree-dump-times "__builtin_free" 15 "original" } }
63