2016-05-07 Fritz Reese <fritzoreese@gmail.com>
[official-gcc.git] / gcc / testsuite / gfortran.dg / dec_union_6.f90
blob31059c468802308da683864d44119b7ec6a6ee69
1 ! { dg-do run }
2 ! { dg-options "-fdec-structure" }
4 ! sub0 and sub1 test a regression where calling gfc_use_derived from
5 ! gfc_find_component on the structure type symbol being parsed caused the
6 ! symbol to be freed and swapped for the previously seen type symbol, leaving
7 ! dangling pointers and causing all sorts of mayhem.
10 subroutine sub0 (u)
11 structure /s/
12 union ! U0
13 map ! M0
14 integer i
15 end map
16 end union
17 end structure
18 record /s/ u
19 u.i = 0
20 end subroutine sub0
22 subroutine sub1 ()
23 structure /s/
24 union ! U1
25 map ! M1
26 integer i
27 end map
28 end union
29 end structure
30 record /s/ u
31 interface ! matches the declaration of sub0 above
32 subroutine sub0 (u)
33 structure /s/
34 union ! U2
35 map ! M2
36 integer i ! gfc_find_component should not call gfc_use_derived
37 end map ! here, otherwise this structure's type symbol is freed
38 end union ! out from under it
39 end structure
40 record /s/ u
41 end subroutine sub0
42 end interface
43 call sub0(u)
44 end subroutine
46 ! If sub0 and sub1 aren't used they may be omitted
47 structure /s/
48 union ! U1
49 map ! M3
50 integer i
51 end map
52 end union
53 end structure
54 record /s/ u
56 call sub0(u)
57 call sub1()
59 end