Merged revisions 208012,208018-208019,208021,208023-208030,208033,208037,208040-20804...
[official-gcc.git] / main / gcc / testsuite / g++.dg / cilk-plus / CK / lambda_spawns.cc
blob9b3d2cc26e7a885e3e111b4c3c5028da60163af6
1 /* { dg-options "-fcilkplus" } */
2 /* { dg-do run { target i?86-*-* x86_64-*-* arm*-*-* } } */
3 // { dg-require-effective-target c++11 }
4 /* { dg-options "-fcilkplus -lcilkrts" { target { i?86-*-* x86_64-*-* arm*-*-* } } } */
5 #define FIRST_NUMBER 5
6 #define SECOND_NUMBER 3
7 #define HAVE_IO 0
8 #if HAVE_IO
9 #include <stdio.h>
10 #endif
12 #include <stdlib.h>
14 int global_var;
16 void foo1(int *array, int size)
18 #if HAVE_IO
19 for (int ii = 0; ii < size; ii++)
20 printf("%2d\t", array[ii]);
21 printf("\n");
22 fflush (stdout);
23 #else
24 if (size != 2)
25 __builtin_abort ();
26 if (array[0] != FIRST_NUMBER)
27 __builtin_abort ();
28 if (array[1] != SECOND_NUMBER)
29 __builtin_abort ();
30 #endif
31 global_var++;
33 void foo1_c(const int *array, int size)
35 #if HAVE_IO
36 for (int ii = 0; ii < size; ii++)
37 printf("%2d\t", array[ii]);
38 printf("\n");
39 fflush (stdout);
40 #else
41 if (size != 2)
42 __builtin_abort ();
43 if (array[0] != FIRST_NUMBER)
44 __builtin_abort ();
45 if (array[1] != SECOND_NUMBER)
46 __builtin_abort ();
47 #endif
48 global_var++;
52 int main2 (int argc) {
53 int A[2] = {FIRST_NUMBER, SECOND_NUMBER};
54 int B[2] = {FIRST_NUMBER, SECOND_NUMBER};
55 int main_size = argc+1; /* We know argc is 1, and so 1+1 = 2. */
56 int q = 0;
58 global_var = 0;
59 auto func0 = [=](){ foo1_c(A, 2); };
60 _Cilk_spawn func0();
61 foo1 (A, 2);
62 _Cilk_sync;
63 if (global_var != 2)
64 return (++q);
66 global_var = 0;
67 auto func1 = [=](int *Aa){ foo1(Aa, 2); };
68 _Cilk_spawn func1 (A);
69 foo1 (A, 2);
70 _Cilk_sync;
71 if (global_var != 2)
72 return (++q);
74 global_var = 0;
75 auto func2 = [=](int *Aa, int size){ foo1(Aa, size); };
76 _Cilk_spawn func2 (A, 2);
77 foo1 (A, 2);
78 _Cilk_sync;
79 if (global_var != 2)
80 return (++q);
82 global_var = 0;
83 auto func3 = [=](int *Aa, int size){ int new_size = (size % 2 + 2);
84 foo1(Aa, size); };
85 _Cilk_spawn func3 (A, 2);
86 foo1 (A, 2);
87 _Cilk_sync;
88 if (global_var != 2)
89 return (++q);
91 global_var = 0;
92 auto func4 = [](int *Aa){ foo1(Aa, 2); };
93 _Cilk_spawn func4 (A);
94 foo1 (A, 2);
95 _Cilk_sync;
96 if (global_var != 2)
97 return (++q);
99 global_var = 0;
100 auto func5 = [](int *Aa, int size){ foo1(Aa, size); };
101 _Cilk_spawn func5 (A, 2);
102 foo1 (A, 2);
103 _Cilk_sync;
104 if (global_var != 2)
105 return (++q);
107 global_var = 0;
108 auto func6 = [&](int *Aa){ foo1(Aa, 2); };
109 _Cilk_spawn func6 (A);
110 foo1 (A, 2);
111 _Cilk_sync;
112 if (global_var != 2)
113 return (++q);
115 global_var = 0;
116 auto func7 = [&](int *Aa, int size){ foo1(Aa, size); };
117 _Cilk_spawn func7 (A, 2);
118 foo1 (A, 2);
119 _Cilk_sync;
120 if (global_var != 2)
121 return (++q);
123 global_var = 0;
124 auto func8 = [&](){ foo1(A, 2); };
125 _Cilk_spawn func8 ();
126 foo1 (A, 2);
127 _Cilk_sync;
128 if (global_var != 2)
129 return (++q);
131 global_var = 0;
132 /* We ignore the first param here and pass in A from the outer fn. */
133 auto func9 = [&](int *Aa, int size){ foo1(A, size); };
134 _Cilk_spawn func9 (A, 2);
135 foo1 (A, 2);
136 _Cilk_sync;
137 if (global_var != 2)
138 return (++q);
140 global_var = 0;
141 auto func10 = [=](){ foo1_c(A, main_size); };
142 _Cilk_spawn func10 ();
143 foo1 (A, 2);
144 _Cilk_sync;
145 if (global_var != 2)
146 return (++q);
148 global_var = 0;
149 auto func11 = [&](){ foo1(A, main_size); };
150 _Cilk_spawn func11 ();
151 foo1 (A, 2);
152 _Cilk_sync;
153 if (global_var != 2)
154 return (++q);
156 global_var = 0;
157 /* We ignore the first & second param here and pass in A from the
158 outer fn. */
159 auto func12 = [&](int *Aa, int size){ foo1(A, main_size); };
160 _Cilk_spawn func12 (A, 2);
161 foo1 (A, 2);
162 _Cilk_sync;
163 if (global_var != 2)
164 return (++q);
166 global_var = 0;
167 _Cilk_spawn [&](int *Aa){ foo1(Aa, 2); }(A);
168 foo1 (A, 2);
169 _Cilk_sync;
170 if (global_var != 2)
171 return (++q);
173 global_var = 0;
174 _Cilk_spawn [&](int *Aa, int size){ foo1(Aa, size); }(A, 2);
175 foo1 (A, 2);
176 _Cilk_sync;
177 if (global_var != 2)
178 return (++q);
180 global_var = 0;
181 _Cilk_spawn [=](int *Aa){ foo1(Aa, 2); }(A);
182 foo1 (A, 2);
183 _Cilk_sync;
184 if (global_var != 2)
185 return (++q);
187 global_var = 0;
188 _Cilk_spawn [=](int *Aa, int size){ foo1(Aa, size); }(A, 2);
189 foo1 (A, 2);
190 _Cilk_sync;
191 if (global_var != 2)
192 return (++q);
194 global_var = 0;
195 /* We ignore the first param here. */
196 _Cilk_spawn [=](int *Aa, int size){ foo1_c(A, size); }(A, 2);
197 foo1 (A, 2);
198 _Cilk_sync;
199 if (global_var != 2)
200 return (++q);
202 global_var = 0;
203 /* We ignore the first and second param here. */
204 _Cilk_spawn [=](int *Aa, int size){ foo1_c(A, size); }(B, 2);
205 foo1 (A, 2);
206 _Cilk_sync;
207 if (global_var != 2)
208 return (++q);
210 global_var = 0;
211 _Cilk_spawn [&](){ foo1(A, 2); }();
212 [&](){ foo1(A, 2); }();
213 _Cilk_sync;
214 if (global_var != 2)
215 return (++q);
217 global_var = 0;
218 _Cilk_spawn [=](){ foo1_c (A, main_size); }();
219 foo1 (A, 2);
220 _Cilk_sync;
221 if (global_var != 2)
222 return (++q);
224 global_var = 0;
225 _Cilk_spawn [&](){ foo1(A, main_size); }();
226 [&](){ foo1(A, 2); }();
227 _Cilk_sync;
228 if (global_var != 2)
229 return (++q);
231 return q;
234 int main (void)
236 return main2 (1);