c: Fix up pointer types to may_alias structures [PR114493]
[official-gcc.git] / gcc / testsuite / gfortran.dg / coarray_alloc_comp_4.f08
blob6586ec651ddfa58860854e0a10f74bb4a7b83c19
1 ! { dg-do compile }
2 ! { dg-options "-fcoarray=lib -fdump-tree-original" }
3 ! { dg-additional-options "-latomic" { target libatomic_available } }
5 ! Contributed by Andre Vehreschild
6 ! Check that sub-components are caf_deregistered and not freed.
8 program coarray_alloc_comp_3
9   implicit none
11   type dt
12     integer, allocatable :: i
13   end type dt
15   type linktype
16     type(dt), allocatable :: link
17   end type linktype
19   type(linktype) :: obj[*]
21   allocate(obj%link)
23   if (.not. allocated(obj%link)) error stop "Test failed. 'obj%link' not allocated."
24   if (allocated(obj%link%i)) error stop "Test failed. 'obj%link%i' already allocated."
26   allocate(obj%link%i, source = 42)
28   if (.not. allocated(obj%link)) error stop "Test failed. 'obj%link' not allocated."
29   if (.not. allocated(obj%link%i)) error stop "Test failed. 'obj%link%i' not allocated."
30   if (obj%link%i /= 42) error stop "Test failed. obj%link%i /= 42."
32   deallocate(obj%link%i)
34   if (allocated(obj%link%i)) error stop "Test failed. 'obj%link%i' still allocated."
35   if (.not. allocated(obj%link)) error stop "Test failed. 'obj%link' no longer allocated."
37   ! Freeing this object, lead to crash with older gfortran...
38   deallocate(obj%link)
40   if (allocated(obj%link)) error stop "Test failed. 'obj%link' still allocated."
41 end program
42 ! Ensure, that three calls to deregister are present.
43 ! { dg-final { scan-tree-dump-times "_caf_deregister" 3 "original" } }
44 ! And ensure that no calls to builtin_free are made.
45 ! { dg-final { scan-tree-dump-not "_builtin_free" "original" } }