1! { dg-do run }
2! { dg-options "-fdec-structure" }
3!
4! Test whether union backend declarations are corrently _not_ copied when they
5! are not in fact equal. The structure defined in sub() is seen later, but
6! where siz has a different value.
7!
8
9subroutine aborts (s)
10  character(*), intent(in) :: s
11  print *, s
12  STOP 1
13end subroutine
14
15subroutine sub ()
16  integer, parameter :: siz = 1024
17  structure /s6/
18    union ! U0
19      map ! M0
20        integer ibuf(siz)
21      end map
22      map ! M1
23        character(8) cbuf(siz)
24      end map
25      map ! M2
26        real rbuf(siz)
27      end map
28    end union
29  end structure
30  record /s6/ r6
31  r6.ibuf(1) = z'badbeef'
32  r6.ibuf(2) = z'badbeef'
33end subroutine
34
35! Repeat definition from subroutine sub with different size parameter.
36! If the structure definition is copied here the stack may get messed up.
37integer, parameter :: siz = 65536
38structure /s6/
39  union ! U12
40    map
41      integer ibuf(siz)
42    end map
43    map
44      character(8) cbuf(siz)
45    end map
46    map
47      real rbuf(siz)
48    end map
49  end union
50end structure
51
52record /s6/ r6
53integer :: r6_canary = 0
54
55! Copied type declaration - this should not cause problems
56i = 1
57do while (i < siz)
58  r6.ibuf(i) = z'badbeef'
59  i = i + 1
60end do
61
62if ( r6_canary .ne. 0 ) then
63  call aborts ('copied decls: overflow')
64endif
65
66end
67