Debian Codegraph @

gcc/testsuite/gfortran.dg/coarray/alloc_comp_8.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-latomic" { target libatomic_available } }
3 !
4 ! Contributed by Andre Vehreschild
5 ! Check that manually freeing components does not lead to a runtime crash,
6 ! when the auto-deallocation is taking care.
7
8 program alloc_comp_6
9 implicit none
10
11 type dt
12 integer, allocatable :: i
13 end type dt
14
15 type linktype
16 type(dt), allocatable :: link
17 end type linktype
18
19 type(linktype), allocatable :: obj[:]
20
21 allocate(obj[*])
22 allocate(obj%link)
23
24 if (.not. allocated(obj)) error stop "Test failed. 'obj' not allocated."
25 if (.not. allocated(obj%link)) error stop "Test failed. 'obj%link' not allocated."
26 if (allocated(obj%link%i)) error stop "Test failed. 'obj%link%i' already allocated."
27
28 allocate(obj%link%i, source = 42)
29
30 if (.not. allocated(obj)) error stop "Test failed. 'obj' not allocated."
31 if (.not. allocated(obj%link)) error stop "Test failed. 'obj%link' not allocated."
32 if (.not. allocated(obj%link%i)) error stop "Test failed. 'obj%link%i' not allocated."
33 if (obj%link%i /= 42) error stop "Test failed. obj%link%i /= 42."
34
35 deallocate(obj%link%i)
36
37 if (allocated(obj%link%i)) error stop "Test failed. 'obj%link%i' still allocated."
38 if (.not. allocated(obj%link)) error stop "Test failed. 'obj%link' no longer allocated."
39 if (.not. allocated(obj)) error stop "Test failed. 'obj' no longer allocated."
40
41 ! Freeing this object, lead to crash with older gfortran...
42 deallocate(obj%link)
43
44 if (allocated(obj%link)) error stop "Test failed. 'obj%link' still allocated."
45 if (.not. allocated(obj)) error stop "Test failed. 'obj' no longer allocated."
46
47 ! ... when auto-deallocating the allocated components.
48 deallocate(obj)
49
50 if (allocated(obj)) error stop "Test failed. 'obj' still allocated."
51 end program