xref: /llvm-project/flang/test/Semantics/allocated.f90 (revision d34f5dd07a2197ec91ecc33307eed6435ceda73f)
1! RUN: %python %S/test_errors.py %s %flang_fc1
2! Tests for the ALLOCATED() intrinsic
3subroutine alloc(coarray_alloc, coarray_not_alloc, t2_not_alloc, &
4                 assumedRank)
5
6  interface
7    function return_allocatable()
8      integer, allocatable :: return_allocatable(:)
9    end function
10  end interface
11
12  type :: t1
13    integer, allocatable :: alloc(:)
14    integer :: not_alloc
15  end type
16
17  type :: t2
18    real, allocatable :: coarray_alloc[:]
19    real, allocatable :: coarray_alloc_array(:)[:]
20  end type
21
22
23  integer :: not_alloc(100)
24  real, allocatable :: x_alloc
25  character(:), allocatable :: char_alloc(:)
26  type(t1) :: dt_not_alloc(100)
27  type(t1), allocatable :: dt_alloc(:)
28
29  real, allocatable :: coarray_alloc[:, :]
30  real, allocatable :: coarray_alloc_array(:)[:, :]
31  real :: coarray_not_alloc(:)[*]
32
33  type(t2) :: t2_not_alloc
34  real, allocatable :: assumedRank(..)
35
36
37  ! OK
38  print *, allocated(x_alloc)
39  print *, allocated(char_alloc)
40  print *, allocated(dt_alloc)
41  print *, allocated(dt_not_alloc(3)%alloc)
42  print *, allocated(dt_alloc(3)%alloc)
43  print *, allocated(coarray_alloc)
44  print *, allocated(coarray_alloc[2,3])
45  print *, allocated(t2_not_alloc%coarray_alloc)
46  print *, allocated(t2_not_alloc%coarray_alloc[2])
47  print *, allocated(assumedRank)
48  select rank (assumedRank)
49  rank (0)
50    print *, allocated(scalar=assumedRank)
51  rank default
52    print *, allocated(array=assumedRank)
53  end select
54
55  !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
56  print *, allocated(not_alloc)
57  !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
58  print *, allocated(dt_not_alloc)
59  !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
60  print *, allocated(dt_alloc%not_alloc)
61  !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
62  print *, allocated(char_alloc(:))
63  !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
64  print *, allocated(char_alloc(1)(1:10))
65  !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
66  print *, allocated(coarray_alloc_array(1:10))
67  !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
68  print *, allocated(coarray_alloc_array(1:10)[2,2])
69  !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
70  print *, allocated(t2_not_alloc%coarray_alloc_array(1))
71  !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
72  print *, allocated(t2_not_alloc%coarray_alloc_array(1)[2])
73  !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
74  print *, allocated(return_allocatable())
75end subroutine
76