• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1! RUN: %S/test_errors.sh %s %t %f18
2subroutine forall1
3  real :: a(9)
4  !ERROR: 'i' is already declared in this scoping unit
5  !ERROR: Cannot redefine FORALL variable 'i'
6  forall (i=1:8, i=1:9)  a(i) = i
7  !ERROR: 'i' is already declared in this scoping unit
8  !ERROR: Cannot redefine FORALL variable 'i'
9  forall (i=1:8, i=1:9)
10    a(i) = i
11  end forall
12  forall (j=1:8)
13    !ERROR: 'j' is already declared in this scoping unit
14    !ERROR: Cannot redefine FORALL variable 'j'
15    forall (j=1:9)
16    end forall
17  end forall
18end
19
20subroutine forall2
21  integer, pointer :: a(:)
22  integer, target :: b(10,10)
23  forall (i=1:10)
24    !ERROR: Impure procedure 'f_impure' may not be referenced in a FORALL
25    a(f_impure(i):) => b(i,:)
26  end forall
27  !ERROR: FORALL mask expression may not reference impure procedure 'f_impure'
28  forall (j=1:10, f_impure(1)>2)
29  end forall
30contains
31  impure integer function f_impure(i)
32    f_impure = i
33  end
34end
35
36subroutine forall3
37  real :: x
38  forall(i=1:10)
39    !ERROR: Cannot redefine FORALL variable 'i'
40    i = 1
41  end forall
42  forall(i=1:10)
43    forall(j=1:10)
44      !ERROR: Cannot redefine FORALL variable 'i'
45      i = 1
46    end forall
47  end forall
48  !ERROR: Cannot redefine FORALL variable 'i'
49  forall(i=1:10) i = 1
50end
51
52subroutine forall4
53  integer, parameter :: zero = 0
54  integer :: a(10)
55
56  !ERROR: FORALL limit expression may not reference index variable 'i'
57  forall(i=1:i)
58    a(i) = i
59  end forall
60  !ERROR: FORALL step expression may not reference index variable 'i'
61  forall(i=1:10:i)
62    a(i) = i
63  end forall
64  !ERROR: FORALL step expression may not be zero
65  forall(i=1:10:zero)
66    a(i) = i
67  end forall
68
69  !ERROR: FORALL limit expression may not reference index variable 'i'
70  forall(i=1:i) a(i) = i
71  !ERROR: FORALL step expression may not reference index variable 'i'
72  forall(i=1:10:i) a(i) = i
73  !ERROR: FORALL step expression may not be zero
74  forall(i=1:10:zero) a(i) = i
75end
76
77! Note: this gets warnings but not errors
78subroutine forall5
79  real, target :: x(10), y(10)
80  forall(i=1:10)
81    x(i) = y(i)
82  end forall
83  forall(i=1:10)
84    x = y  ! warning: i not used on LHS
85    forall(j=1:10)
86      x(i) = y(i)  ! warning: j not used on LHS
87      x(j) = y(j)  ! warning: i not used on LHS
88    endforall
89  endforall
90  do concurrent(i=1:10)
91    x = y
92    forall(i=1:10) x = y
93  end do
94end
95
96subroutine forall6
97  type t
98    real, pointer :: p
99  end type
100  type(t) :: a(10)
101  real, target :: b(10)
102  forall(i=1:10)
103    a(i)%p => b(i)
104    a(1)%p => b(i)  ! warning: i not used on LHS
105  end forall
106end
107