xref: /llvm-project/flang/test/Semantics/resolve123.f90 (revision 3717048496074929250e8d75c033e0b3409eb063)
1! RUN: %python %S/test_errors.py %s %flang_fc1
2! Tests for F'2023 C1131:
3! A variable-name that appears in a REDUCE locality-spec shall not have the
4! ASYNCHRONOUS, INTENT (IN), OPTIONAL, or VOLATILE attribute, shall not be
5! coindexed, and shall not be an assumed-size array. A variable-name that is not
6! permitted to appear in a variable definition context shall not appear in a
7! REDUCE locality-spec.
8
9subroutine s1()
10! Cannot have ASYNCHRONOUS variable in a REDUCE locality spec
11  integer, asynchronous :: k
12!ERROR: ASYNCHRONOUS variable 'k' not allowed in a REDUCE locality-spec
13  do concurrent(i=1:5) reduce(+:k)
14     k = k + i
15  end do
16end subroutine s1
17
18subroutine s2(arg)
19! Cannot have a dummy OPTIONAL in a REDUCE locality spec
20  integer, optional :: arg
21!ERROR: OPTIONAL argument 'arg' not allowed in a locality-spec
22  do concurrent(i=1:5) reduce(*:arg)
23     arg = arg * 1
24  end do
25end subroutine s2
26
27subroutine s3(arg)
28! This is OK
29  real :: arg
30  integer :: reduce, reduce2, reduce3
31  do concurrent(i=1:5) reduce(max:arg,reduce) reduce(iand:reduce2,reduce3)
32     arg = max(arg, i)
33     reduce = max(reduce, i)
34     reduce3 = iand(reduce3, i)
35  end do
36end subroutine s3
37
38subroutine s4(arg)
39! Cannot have a dummy INTENT(IN) in a REDUCE locality spec
40  real, intent(in) :: arg
41!ERROR: INTENT IN argument 'arg' not allowed in a locality-spec
42  do concurrent(i=1:5) reduce(min:arg)
43!ERROR: Left-hand side of assignment is not definable
44!ERROR: 'arg' is an INTENT(IN) dummy argument
45     arg = min(arg, i)
46  end do
47end subroutine s4
48
49module m
50contains
51  subroutine s5()
52    ! Cannot have VOLATILE variable in a REDUCE locality spec
53    integer, volatile :: var
54    !ERROR: VOLATILE variable 'var' not allowed in a REDUCE locality-spec
55    do concurrent(i=1:5) reduce(ieor:var)
56       var = ieor(var, i)
57    end do
58  end subroutine s5
59  subroutine f(x)
60    integer :: x
61  end subroutine f
62end module m
63
64subroutine s8(arg)
65! Cannot have an assumed size array
66  integer, dimension(*) :: arg
67!ERROR: Assumed size array 'arg' not allowed in a locality-spec
68  do concurrent(i=1:5) reduce(ior:arg)
69     arg(i) = ior(arg(i), i)
70  end do
71end subroutine s8
72
73subroutine s9()
74! Reduction variable should not appear in a variable definition context
75  integer :: i
76!ERROR: 'i' is already declared in this scoping unit
77  do concurrent(i=1:5) reduce(+:i)
78  end do
79end subroutine s9
80
81subroutine s10()
82! Cannot have variable inside of a NAMELIST in a REDUCE locality spec
83  integer :: k
84  namelist /nlist1/ k
85!ERROR: NAMELIST variable 'k' not allowed in a REDUCE locality-spec
86  do concurrent(i=1:5) reduce(+:k)
87     k = k + i
88  end do
89end subroutine s10
90