xref: /llvm-project/flang/test/Semantics/collectives01.f90 (revision e3b6b9299c9691c7dcde0f80b8af679a50540979)
1! RUN: %python %S/test_errors.py %s %flang_fc1
2! This test checks for semantic errors in co_sum subroutine calls based on
3! the co_reduce interface defined in section 16.9.50 of the Fortran 2018 standard.
4
5program test_co_sum
6  implicit none
7
8  integer i, status, integer_array(1), coindexed_integer[*], coindexed_result_image[*], repeated_status
9  complex c, complex_array(1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1)
10  double precision d, double_precision_array(1)
11  real r, real_array(1), coindexed_real[*]
12
13  character(len=1) message, coindexed_character[*], character_array(1), repeated_message
14  logical bool
15
16  !___ standard-conforming calls with no keyword arguments ___
17  call co_sum(i)
18  call co_sum(c)
19  call co_sum(d)
20  call co_sum(r)
21  call co_sum(i, 1)
22  call co_sum(c, 1, status)
23  call co_sum(d, 1, status, message)
24  call co_sum(r, 1, status, message)
25  call co_sum(integer_array)
26  call co_sum(complex_array, 1)
27  call co_sum(double_precision_array, 1, status)
28  call co_sum(real_array, 1, status, message)
29
30  !___ standard-conforming calls with keyword arguments ___
31
32  ! all arguments present
33  call co_sum(a=i, result_image=1, stat=status, errmsg=message)
34  call co_sum(a = i, result_image = 1, stat = status, errmsg = message)
35  call co_sum(result_image=1, a=i, errmsg=message, stat=status)
36
37  ! one optional argument not present
38  call co_sum(a=i,                 stat=status, errmsg=message)
39  call co_sum(a=i, result_image=1,              errmsg=message)
40  call co_sum(a=i, result_image=1, stat=status                )
41
42  ! two optional arguments not present
43  call co_sum(a=i, result_image=1                             )
44  call co_sum(a=i,                 stat=status                )
45  call co_sum(a=i,                              errmsg=message)
46  call co_sum(a=i, result_image=coindexed_result_image[1])
47
48  ! no optional arguments present
49  call co_sum(a=i                                             )
50
51  !___ non-standard-conforming calls ___
52
53  !ERROR: missing mandatory 'a=' argument
54  call co_sum()
55
56  !ERROR: missing mandatory 'a=' argument
57  call co_sum(result_image=1, stat=status, errmsg=message)
58
59  !ERROR: repeated keyword argument to intrinsic 'co_sum'
60  call co_sum(a=i, a=c)
61
62  !ERROR: repeated keyword argument to intrinsic 'co_sum'
63  call co_sum(a=i, result_image=1, result_image=2, stat=status, errmsg=message)
64
65  !ERROR: repeated keyword argument to intrinsic 'co_sum'
66  call co_sum(a=i, result_image=1, stat=status, stat=repeated_status, errmsg=message)
67
68  !ERROR: repeated keyword argument to intrinsic 'co_sum'
69  call co_sum(a=i, result_image=1, stat=status, errmsg=message, errmsg=repeated_message)
70
71  !ERROR: keyword argument to intrinsic 'co_sum' was supplied positionally by an earlier actual argument
72  call co_sum(i, 1, a=c)
73
74  !ERROR: keyword argument to intrinsic 'co_sum' was supplied positionally by an earlier actual argument
75  call co_sum(i, 1, result_image=2)
76
77  !ERROR: keyword argument to intrinsic 'co_sum' was supplied positionally by an earlier actual argument
78  call co_sum(i, 1, status, stat=repeated_status)
79
80  !ERROR: keyword argument to intrinsic 'co_sum' was supplied positionally by an earlier actual argument
81  call co_sum(i, 1, status, message, errmsg=repeated_message)
82
83  ! argument 'a' shall be of numeric type
84  !ERROR: Actual argument for 'a=' has bad type 'LOGICAL(4)'
85  call co_sum(bool)
86
87  ! argument 'a' is intent(inout)
88  !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'a=' is not definable
89  !BECAUSE: '2_4' is not a variable or pointer
90  call co_sum(a=1+1)
91
92  !ERROR: 'a' argument to 'co_sum' may not be a coindexed object
93  call co_sum(a=coindexed_real[1])
94
95  ! 'result_image' argument shall be a integer
96  !ERROR: Actual argument for 'result_image=' has bad type 'LOGICAL(4)'
97  call co_sum(i, result_image=bool)
98
99  ! 'result_image' argument shall be an integer scalar
100  !ERROR: 'result_image=' argument has unacceptable rank 1
101  call co_sum(c, result_image=integer_array)
102
103  ! argument 'stat' shall be intent(out)
104  !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'stat=' is not definable
105  !BECAUSE: '2_4' is not a variable or pointer
106  call co_sum(a=i, result_image=1, stat=1+1, errmsg=message)
107
108  !ERROR: 'stat' argument to 'co_sum' may not be a coindexed object
109  call co_sum(d, stat=coindexed_integer[1])
110
111  !ERROR: 'stat' argument to 'co_sum' may not be a coindexed object
112  call co_sum(stat=coindexed_integer[1], a=d)
113
114  ! 'stat' argument shall be an integer
115  !ERROR: Actual argument for 'stat=' has bad type 'CHARACTER(KIND=1,LEN=1_8)'
116  call co_sum(r, stat=message)
117
118  ! 'stat' argument shall be an integer scalar
119  !ERROR: 'stat=' argument has unacceptable rank 1
120  call co_sum(i, stat=integer_array)
121
122  ! 'errmsg' argument shall be intent(inout)
123  !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'errmsg=' is not definable
124  !BECAUSE: '"c"' is not a variable or pointer
125  call co_sum(a=i, result_image=1, stat=status, errmsg='c')
126
127  !ERROR: 'errmsg' argument to 'co_sum' may not be a coindexed object
128  call co_sum(c, errmsg=coindexed_character[1])
129
130  ! 'errmsg' argument shall be a character
131  !ERROR: Actual argument for 'errmsg=' has bad type 'INTEGER(4)'
132  call co_sum(c, errmsg=i)
133
134  ! 'errmsg' argument shall be character scalar
135  !ERROR: 'errmsg=' argument has unacceptable rank 1
136  call co_sum(d, errmsg=character_array)
137
138  !ERROR: actual argument #5 without a keyword may not follow an actual argument with a keyword
139  call co_sum(r, result_image=1, stat=status, errmsg=message, 3.4)
140
141  ! keyword argument with incorrect name
142  !ERROR: unknown keyword argument to intrinsic 'co_sum'
143  call co_sum(fake=3.4)
144
145  !ERROR: 'a' argument to 'co_sum' may not be a coindexed object
146  !ERROR: 'errmsg' argument to 'co_sum' may not be a coindexed object
147  !ERROR: 'stat' argument to 'co_sum' may not be a coindexed object
148  call co_sum(result_image=coindexed_result_image[1], a=coindexed_real[1], errmsg=coindexed_character[1], stat=coindexed_integer[1])
149
150end program test_co_sum
151