File: allocate12.f90

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (122 lines) | stat: -rw-r--r-- 4,662 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
! RUN: %python %S/test_errors.py %s %flang_fc1
! Check for semantic errors in ALLOCATE statements

subroutine C941_C942b_C950(xsrc, x1, a2, b2, cx1, ca2, cb1, cb2, c1, c2)
! C941: An allocate-coarray-spec shall appear if and only if the allocate-object
! is a coarray.
  type type0
    real, allocatable :: array(:)
  end type
  type type1
    class(type0), pointer :: t0
  end type

  type type2
    type(type1), pointer :: t1(:)
  end type

  type A
    real x(10)
  end type

  type B
    real, allocatable :: x(:)
  end type

  type C
    class(type2), allocatable :: ct2(:, :)[:, :, :]
    class(A), allocatable :: cx(:, :)[:, :, :]
    class(A), allocatable :: x(:, :)
  end type

  real :: xsrc(10)
  real, allocatable :: x1, x2(:)
  class(A), pointer :: a1, a2(:)

  real, allocatable :: cx1[:], cx2(:)[:, :]
  class(A), allocatable :: ca1[:, :], ca2(:)[:]

  type(B) :: b1, b2(*)
  type(B) :: cb1[5:*], cb2(*)[2, -1:*]

  type(C) :: c1
  pointer :: c2(:, :)
  pointer :: varLocal(:)

  class(*), allocatable :: var(:), cvar(:)[:]

  ! Valid constructs
  allocate(x1, x2(10), cx1[*], cx2(10)[2, -1:*])
  allocate(a1, a2(10), ca1[2, -1:*], ca2(10)[*])
  allocate(b1%x, b2(1)%x, cb1%x, cb2(1)%x, SOURCE=xsrc)
  allocate(c1%x(-1:10, 1:5), c1%cx(-1:10, 1:5)[-1:5, 1:2, 2:*])
  allocate(c2(9, 27))
  allocate(varLocal(64))
  allocate(A:: var(5), cvar(10)[*])


  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
  allocate(x1[*])
  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
  allocate(x2(10)[*])
  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
  allocate(cx1)
  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
  allocate(cx2(10))

  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
  allocate(cx1[*], a1[*])
  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
  allocate(cx1[*], a2(10)[*])
  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
  allocate(x1, ca1)
  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
  allocate(ca1[2, -1:*], ca2(10))

  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
  allocate(b1%x[5:*] , SOURCE=xsrc)
  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
  allocate(b2(1)%x[2, -1:*], SOURCE=xsrc)
  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
  allocate(cb1%x[5:*] , SOURCE=xsrc)
  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
  allocate(cb2(1)%x[2, -1:*], SOURCE=xsrc)

  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
  allocate(c1%x(-1:10, 1:5)[-1:5, 1:2, 2:*])
  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
  allocate(c1%cx(-1:10, 1:5))

  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
  allocate(A:: var(5)[*], cvar(10)[*])
  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
  allocate(A:: var(5), cvar(10))

! C942b: [... (shape related stuff not tested here) ...]. The number of
! allocate-coshape-specs in an allocate-coarray-spec shall be one less
! than the corank of the allocate-object.

  ! Valid constructs already tested above

  !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
  allocate(cx1[2,-1:*], cx2(10)[2, -1:*])
  !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
  allocate(ca1[*], ca2(10)[*])
  !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
  allocate(c1%cx(-1:10, 1:5)[-1:5, 1:*])
  !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
  allocate(A:: cvar(10)[2,2,*])

! C950: An allocate-object shall not be a coindexed object.

  ! Valid construct
  allocate(c1%ct2(2,5)%t1(2)%t0%array(10))

  !ERROR: Allocatable object must not be coindexed in ALLOCATE
  allocate(b1%x, b2(1)%x, cb1[2]%x, SOURCE=xsrc)
  !ERROR: Allocatable object must not be coindexed in ALLOCATE
  allocate(b1%x, b2(1)%x, cb2(1)[2,-1]%x, MOLD=xsrc)
  !ERROR: Allocatable object must not be coindexed in ALLOCATE
  allocate(c1%ct2(2,5)[1,1,1]%t1(2)%t0%array(10))

end subroutine