]>
Commit | Line | Data |
---|---|---|
ad321293 MM |
1 | /* Perform the semantic phase of parsing, i.e., the process of |
2 | building tree structure, checking semantic consistency, and | |
3 | building RTL. These routines are used both during actual parsing | |
c8094d83 | 4 | and during the instantiation of template functions. |
ad321293 | 5 | |
5624e564 | 6 | Copyright (C) 1998-2015 Free Software Foundation, Inc. |
ad321293 | 7 | Written by Mark Mitchell (mmitchell@usa.net) based on code found |
c8094d83 | 8 | formerly in parse.y and pt.c. |
ad321293 | 9 | |
f5adbb8d | 10 | This file is part of GCC. |
ad321293 | 11 | |
f5adbb8d | 12 | GCC is free software; you can redistribute it and/or modify it |
ad321293 | 13 | under the terms of the GNU General Public License as published by |
e77f031d | 14 | the Free Software Foundation; either version 3, or (at your option) |
ad321293 | 15 | any later version. |
c8094d83 | 16 | |
f5adbb8d | 17 | GCC is distributed in the hope that it will be useful, but |
ad321293 MM |
18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | General Public License for more details. | |
c8094d83 | 21 | |
e77f031d NC |
22 | You should have received a copy of the GNU General Public License |
23 | along with GCC; see the file COPYING3. If not see | |
24 | <http://www.gnu.org/licenses/>. */ | |
ad321293 MM |
25 | |
26 | #include "config.h" | |
8d052bc7 | 27 | #include "system.h" |
4977bab6 | 28 | #include "coretypes.h" |
2adfab87 AM |
29 | #include "target.h" |
30 | #include "bitmap.h" | |
2adfab87 | 31 | #include "cp-tree.h" |
2adfab87 AM |
32 | #include "stringpool.h" |
33 | #include "cgraph.h" | |
d8a2d370 DN |
34 | #include "stmt.h" |
35 | #include "varasm.h" | |
36 | #include "stor-layout.h" | |
61d3ce20 | 37 | #include "c-family/c-objc.h" |
25af8512 | 38 | #include "tree-inline.h" |
9b6ab3c0 | 39 | #include "intl.h" |
325c3691 | 40 | #include "tree-iterator.h" |
0645c1a2 | 41 | #include "omp-low.h" |
9a771876 | 42 | #include "convert.h" |
41dbbb37 | 43 | #include "gomp-constants.h" |
ad321293 MM |
44 | |
45 | /* There routines provide a modular interface to perform many parsing | |
46 | operations. They may therefore be used during actual parsing, or | |
47 | during template instantiation, which may be regarded as a | |
0b4d5576 | 48 | degenerate form of parsing. */ |
ad321293 | 49 | |
3a978d72 | 50 | static tree maybe_convert_cond (tree); |
6de9cd9a | 51 | static tree finalize_nrv_r (tree *, int *, void *); |
d5f4eddd | 52 | static tree capture_decltype (tree); |
4985cde3 | 53 | |
d9a6bd32 JJ |
54 | /* Used for OpenMP non-static data member privatization. */ |
55 | ||
56 | static hash_map<tree, tree> *omp_private_member_map; | |
57 | static vec<tree> omp_private_member_vec; | |
58 | static bool omp_private_member_ignore_next; | |
59 | ||
558475f0 | 60 | |
8d241e0b KL |
61 | /* Deferred Access Checking Overview |
62 | --------------------------------- | |
63 | ||
64 | Most C++ expressions and declarations require access checking | |
65 | to be performed during parsing. However, in several cases, | |
66 | this has to be treated differently. | |
67 | ||
68 | For member declarations, access checking has to be deferred | |
69 | until more information about the declaration is known. For | |
70 | example: | |
71 | ||
72 | class A { | |
0cbd7506 | 73 | typedef int X; |
8d241e0b | 74 | public: |
0cbd7506 | 75 | X f(); |
8d241e0b KL |
76 | }; |
77 | ||
78 | A::X A::f(); | |
79 | A::X g(); | |
80 | ||
81 | When we are parsing the function return type `A::X', we don't | |
82 | really know if this is allowed until we parse the function name. | |
83 | ||
84 | Furthermore, some contexts require that access checking is | |
85 | never performed at all. These include class heads, and template | |
86 | instantiations. | |
87 | ||
88 | Typical use of access checking functions is described here: | |
c8094d83 | 89 | |
8d241e0b KL |
90 | 1. When we enter a context that requires certain access checking |
91 | mode, the function `push_deferring_access_checks' is called with | |
92 | DEFERRING argument specifying the desired mode. Access checking | |
93 | may be performed immediately (dk_no_deferred), deferred | |
94 | (dk_deferred), or not performed (dk_no_check). | |
95 | ||
96 | 2. When a declaration such as a type, or a variable, is encountered, | |
97 | the function `perform_or_defer_access_check' is called. It | |
9771b263 | 98 | maintains a vector of all deferred checks. |
8d241e0b KL |
99 | |
100 | 3. The global `current_class_type' or `current_function_decl' is then | |
101 | setup by the parser. `enforce_access' relies on these information | |
102 | to check access. | |
103 | ||
104 | 4. Upon exiting the context mentioned in step 1, | |
105 | `perform_deferred_access_checks' is called to check all declaration | |
9771b263 | 106 | stored in the vector. `pop_deferring_access_checks' is then |
8d241e0b KL |
107 | called to restore the previous access checking mode. |
108 | ||
109 | In case of parsing error, we simply call `pop_deferring_access_checks' | |
110 | without `perform_deferred_access_checks'. */ | |
111 | ||
a79683d5 | 112 | struct GTY(()) deferred_access { |
9771b263 | 113 | /* A vector representing name-lookups for which we have deferred |
3e1f1ba5 NS |
114 | checking access controls. We cannot check the accessibility of |
115 | names used in a decl-specifier-seq until we know what is being | |
116 | declared because code like: | |
117 | ||
c8094d83 | 118 | class A { |
0cbd7506 MS |
119 | class B {}; |
120 | B* f(); | |
3e1f1ba5 NS |
121 | } |
122 | ||
123 | A::B* A::f() { return 0; } | |
124 | ||
d6b418fa | 125 | is valid, even though `A::B' is not generally accessible. */ |
9771b263 | 126 | vec<deferred_access_check, va_gc> * GTY(()) deferred_access_checks; |
c8094d83 | 127 | |
3e1f1ba5 NS |
128 | /* The current mode of access checks. */ |
129 | enum deferring_kind deferring_access_checks_kind; | |
c8094d83 | 130 | |
a79683d5 | 131 | }; |
3e1f1ba5 | 132 | |
cf22909c | 133 | /* Data for deferred access checking. */ |
9771b263 | 134 | static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack; |
3e1f1ba5 | 135 | static GTY(()) unsigned deferred_access_no_check; |
cf22909c KL |
136 | |
137 | /* Save the current deferred access states and start deferred | |
138 | access checking iff DEFER_P is true. */ | |
139 | ||
572c2b17 AP |
140 | void |
141 | push_deferring_access_checks (deferring_kind deferring) | |
cf22909c | 142 | { |
78757caa KL |
143 | /* For context like template instantiation, access checking |
144 | disabling applies to all nested context. */ | |
3e1f1ba5 NS |
145 | if (deferred_access_no_check || deferring == dk_no_check) |
146 | deferred_access_no_check++; | |
cf22909c | 147 | else |
3e1f1ba5 | 148 | { |
f32682ca | 149 | deferred_access e = {NULL, deferring}; |
9771b263 | 150 | vec_safe_push (deferred_access_stack, e); |
3e1f1ba5 | 151 | } |
cf22909c KL |
152 | } |
153 | ||
0ef08a81 JM |
154 | /* Save the current deferred access states and start deferred access |
155 | checking, continuing the set of deferred checks in CHECKS. */ | |
156 | ||
157 | void | |
158 | reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks) | |
159 | { | |
160 | push_deferring_access_checks (dk_deferred); | |
161 | if (!deferred_access_no_check) | |
162 | deferred_access_stack->last().deferred_access_checks = checks; | |
163 | } | |
164 | ||
cf22909c KL |
165 | /* Resume deferring access checks again after we stopped doing |
166 | this previously. */ | |
167 | ||
572c2b17 AP |
168 | void |
169 | resume_deferring_access_checks (void) | |
cf22909c | 170 | { |
3e1f1ba5 | 171 | if (!deferred_access_no_check) |
9771b263 | 172 | deferred_access_stack->last().deferring_access_checks_kind = dk_deferred; |
cf22909c KL |
173 | } |
174 | ||
175 | /* Stop deferring access checks. */ | |
176 | ||
572c2b17 AP |
177 | void |
178 | stop_deferring_access_checks (void) | |
cf22909c | 179 | { |
3e1f1ba5 | 180 | if (!deferred_access_no_check) |
9771b263 | 181 | deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred; |
cf22909c KL |
182 | } |
183 | ||
184 | /* Discard the current deferred access checks and restore the | |
185 | previous states. */ | |
186 | ||
572c2b17 AP |
187 | void |
188 | pop_deferring_access_checks (void) | |
cf22909c | 189 | { |
3e1f1ba5 NS |
190 | if (deferred_access_no_check) |
191 | deferred_access_no_check--; | |
192 | else | |
9771b263 | 193 | deferred_access_stack->pop (); |
cf22909c KL |
194 | } |
195 | ||
c8094d83 MS |
196 | /* Returns a TREE_LIST representing the deferred checks. |
197 | The TREE_PURPOSE of each node is the type through which the | |
cf22909c KL |
198 | access occurred; the TREE_VALUE is the declaration named. |
199 | */ | |
200 | ||
9771b263 | 201 | vec<deferred_access_check, va_gc> * |
572c2b17 | 202 | get_deferred_access_checks (void) |
cf22909c | 203 | { |
3e1f1ba5 NS |
204 | if (deferred_access_no_check) |
205 | return NULL; | |
206 | else | |
9771b263 | 207 | return (deferred_access_stack->last().deferred_access_checks); |
cf22909c KL |
208 | } |
209 | ||
210 | /* Take current deferred checks and combine with the | |
211 | previous states if we also defer checks previously. | |
212 | Otherwise perform checks now. */ | |
213 | ||
572c2b17 AP |
214 | void |
215 | pop_to_parent_deferring_access_checks (void) | |
cf22909c | 216 | { |
3e1f1ba5 NS |
217 | if (deferred_access_no_check) |
218 | deferred_access_no_check--; | |
219 | else | |
220 | { | |
9771b263 | 221 | vec<deferred_access_check, va_gc> *checks; |
3e1f1ba5 NS |
222 | deferred_access *ptr; |
223 | ||
9771b263 | 224 | checks = (deferred_access_stack->last ().deferred_access_checks); |
3e1f1ba5 | 225 | |
9771b263 DN |
226 | deferred_access_stack->pop (); |
227 | ptr = &deferred_access_stack->last (); | |
3e1f1ba5 NS |
228 | if (ptr->deferring_access_checks_kind == dk_no_deferred) |
229 | { | |
230 | /* Check access. */ | |
0e69fdf0 | 231 | perform_access_checks (checks, tf_warning_or_error); |
3e1f1ba5 NS |
232 | } |
233 | else | |
234 | { | |
235 | /* Merge with parent. */ | |
d6b418fa SM |
236 | int i, j; |
237 | deferred_access_check *chk, *probe; | |
c8094d83 | 238 | |
9771b263 | 239 | FOR_EACH_VEC_SAFE_ELT (checks, i, chk) |
3e1f1ba5 | 240 | { |
9771b263 | 241 | FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe) |
d6b418fa SM |
242 | { |
243 | if (probe->binfo == chk->binfo && | |
244 | probe->decl == chk->decl && | |
245 | probe->diag_decl == chk->diag_decl) | |
246 | goto found; | |
247 | } | |
3e1f1ba5 | 248 | /* Insert into parent's checks. */ |
9771b263 | 249 | vec_safe_push (ptr->deferred_access_checks, *chk); |
3e1f1ba5 NS |
250 | found:; |
251 | } | |
252 | } | |
253 | } | |
cf22909c KL |
254 | } |
255 | ||
6b648482 MM |
256 | /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node |
257 | is the BINFO indicating the qualifying scope used to access the | |
0e69fdf0 PC |
258 | DECL node stored in the TREE_VALUE of the node. If CHECKS is empty |
259 | or we aren't in SFINAE context or all the checks succeed return TRUE, | |
260 | otherwise FALSE. */ | |
6b648482 | 261 | |
0e69fdf0 | 262 | bool |
9771b263 | 263 | perform_access_checks (vec<deferred_access_check, va_gc> *checks, |
0e69fdf0 | 264 | tsubst_flags_t complain) |
6b648482 | 265 | { |
d6b418fa SM |
266 | int i; |
267 | deferred_access_check *chk; | |
b3ff651a | 268 | location_t loc = input_location; |
0e69fdf0 | 269 | bool ok = true; |
d6b418fa SM |
270 | |
271 | if (!checks) | |
0e69fdf0 | 272 | return true; |
d6b418fa | 273 | |
9771b263 | 274 | FOR_EACH_VEC_SAFE_ELT (checks, i, chk) |
b3ff651a JM |
275 | { |
276 | input_location = chk->loc; | |
0e69fdf0 | 277 | ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain); |
b3ff651a JM |
278 | } |
279 | ||
280 | input_location = loc; | |
0e69fdf0 | 281 | return (complain & tf_error) ? true : ok; |
6b648482 MM |
282 | } |
283 | ||
25903d03 KL |
284 | /* Perform the deferred access checks. |
285 | ||
286 | After performing the checks, we still have to keep the list | |
287 | `deferred_access_stack->deferred_access_checks' since we may want | |
288 | to check access for them again later in a different context. | |
289 | For example: | |
290 | ||
291 | class A { | |
292 | typedef int X; | |
293 | static X a; | |
294 | }; | |
295 | A::X A::a, x; // No error for `A::a', error for `x' | |
296 | ||
297 | We have to perform deferred access of `A::X', first with `A::a', | |
0e69fdf0 | 298 | next with `x'. Return value like perform_access_checks above. */ |
cf22909c | 299 | |
0e69fdf0 PC |
300 | bool |
301 | perform_deferred_access_checks (tsubst_flags_t complain) | |
cf22909c | 302 | { |
0e69fdf0 | 303 | return perform_access_checks (get_deferred_access_checks (), complain); |
cf22909c KL |
304 | } |
305 | ||
306 | /* Defer checking the accessibility of DECL, when looked up in | |
0e69fdf0 PC |
307 | BINFO. DIAG_DECL is the declaration to use to print diagnostics. |
308 | Return value like perform_access_checks above. */ | |
cf22909c | 309 | |
0e69fdf0 PC |
310 | bool |
311 | perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl, | |
312 | tsubst_flags_t complain) | |
cf22909c | 313 | { |
d6b418fa | 314 | int i; |
3e1f1ba5 | 315 | deferred_access *ptr; |
d6b418fa | 316 | deferred_access_check *chk; |
d6b418fa | 317 | |
cf22909c | 318 | |
3e1f1ba5 NS |
319 | /* Exit if we are in a context that no access checking is performed. |
320 | */ | |
321 | if (deferred_access_no_check) | |
0e69fdf0 | 322 | return true; |
c8094d83 | 323 | |
50bc768d | 324 | gcc_assert (TREE_CODE (binfo) == TREE_BINFO); |
0f2a66c9 | 325 | |
9771b263 | 326 | ptr = &deferred_access_stack->last (); |
c8094d83 | 327 | |
cf22909c | 328 | /* If we are not supposed to defer access checks, just check now. */ |
3e1f1ba5 | 329 | if (ptr->deferring_access_checks_kind == dk_no_deferred) |
cf22909c | 330 | { |
0e69fdf0 PC |
331 | bool ok = enforce_access (binfo, decl, diag_decl, complain); |
332 | return (complain & tf_error) ? true : ok; | |
cf22909c | 333 | } |
c8094d83 | 334 | |
cf22909c | 335 | /* See if we are already going to perform this check. */ |
9771b263 | 336 | FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk) |
d6b418fa SM |
337 | { |
338 | if (chk->decl == decl && chk->binfo == binfo && | |
339 | chk->diag_decl == diag_decl) | |
340 | { | |
0e69fdf0 | 341 | return true; |
d6b418fa SM |
342 | } |
343 | } | |
cf22909c | 344 | /* If not, record the check. */ |
f32682ca | 345 | deferred_access_check new_access = {binfo, decl, diag_decl, input_location}; |
9771b263 | 346 | vec_safe_push (ptr->deferred_access_checks, new_access); |
f7d042e2 JM |
347 | |
348 | return true; | |
349 | } | |
350 | ||
838dfd8a | 351 | /* Returns nonzero if the current statement is a full expression, |
f2c5f623 BC |
352 | i.e. temporaries created during that statement should be destroyed |
353 | at the end of the statement. */ | |
35b1567d | 354 | |
f2c5f623 | 355 | int |
3a978d72 | 356 | stmts_are_full_exprs_p (void) |
f2c5f623 | 357 | { |
ae499cce MM |
358 | return current_stmt_tree ()->stmts_are_full_exprs_p; |
359 | } | |
360 | ||
ed3d0b14 ILT |
361 | /* T is a statement. Add it to the statement-tree. This is the C++ |
362 | version. The C/ObjC frontends have a slightly different version of | |
363 | this function. */ | |
364 | ||
365 | tree | |
366 | add_stmt (tree t) | |
367 | { | |
368 | enum tree_code code = TREE_CODE (t); | |
369 | ||
370 | if (EXPR_P (t) && code != LABEL_EXPR) | |
371 | { | |
372 | if (!EXPR_HAS_LOCATION (t)) | |
373 | SET_EXPR_LOCATION (t, input_location); | |
374 | ||
375 | /* When we expand a statement-tree, we must know whether or not the | |
376 | statements are full-expressions. We record that fact here. */ | |
377 | STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p (); | |
378 | } | |
379 | ||
0450fc0b PP |
380 | if (code == LABEL_EXPR || code == CASE_LABEL_EXPR) |
381 | STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1; | |
382 | ||
ed3d0b14 ILT |
383 | /* Add T to the statement-tree. Non-side-effect statements need to be |
384 | recorded during statement expressions. */ | |
9771b263 | 385 | gcc_checking_assert (!stmt_list_stack->is_empty ()); |
ed3d0b14 ILT |
386 | append_to_statement_list_force (t, &cur_stmt_list); |
387 | ||
388 | return t; | |
389 | } | |
390 | ||
e8924938 | 391 | /* Returns the stmt_tree to which statements are currently being added. */ |
ae499cce MM |
392 | |
393 | stmt_tree | |
3a978d72 | 394 | current_stmt_tree (void) |
ae499cce | 395 | { |
c8094d83 MS |
396 | return (cfun |
397 | ? &cfun->language->base.x_stmt_tree | |
ae499cce | 398 | : &scope_chain->x_stmt_tree); |
f2c5f623 | 399 | } |
35b1567d | 400 | |
543a0daa RH |
401 | /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */ |
402 | ||
403 | static tree | |
404 | maybe_cleanup_point_expr (tree expr) | |
405 | { | |
406 | if (!processing_template_decl && stmts_are_full_exprs_p ()) | |
0ad28dde | 407 | expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr); |
543a0daa RH |
408 | return expr; |
409 | } | |
410 | ||
0ad28dde | 411 | /* Like maybe_cleanup_point_expr except have the type of the new expression be |
22423a1f KH |
412 | void so we don't need to create a temporary variable to hold the inner |
413 | expression. The reason why we do this is because the original type might be | |
414 | an aggregate and we cannot create a temporary variable for that type. */ | |
0ad28dde | 415 | |
14a3430e | 416 | tree |
0ad28dde AP |
417 | maybe_cleanup_point_expr_void (tree expr) |
418 | { | |
419 | if (!processing_template_decl && stmts_are_full_exprs_p ()) | |
420 | expr = fold_build_cleanup_point_expr (void_type_node, expr); | |
421 | return expr; | |
422 | } | |
423 | ||
424 | ||
425 | ||
543a0daa RH |
426 | /* Create a declaration statement for the declaration given by the DECL. */ |
427 | ||
428 | void | |
350fae66 | 429 | add_decl_expr (tree decl) |
543a0daa | 430 | { |
c2255bc4 | 431 | tree r = build_stmt (input_location, DECL_EXPR, decl); |
b187901e AP |
432 | if (DECL_INITIAL (decl) |
433 | || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl)))) | |
0ad28dde | 434 | r = maybe_cleanup_point_expr_void (r); |
543a0daa RH |
435 | add_stmt (r); |
436 | } | |
437 | ||
f2c5f623 | 438 | /* Finish a scope. */ |
35b1567d | 439 | |
20aff0b3 | 440 | tree |
325c3691 | 441 | do_poplevel (tree stmt_list) |
35b1567d | 442 | { |
325c3691 | 443 | tree block = NULL; |
35b1567d | 444 | |
f2c5f623 | 445 | if (stmts_are_full_exprs_p ()) |
325c3691 | 446 | block = poplevel (kept_level_p (), 1, 0); |
f2c5f623 | 447 | |
325c3691 | 448 | stmt_list = pop_stmt_list (stmt_list); |
c8094d83 | 449 | |
325c3691 RH |
450 | if (!processing_template_decl) |
451 | { | |
c2255bc4 | 452 | stmt_list = c_build_bind_expr (input_location, block, stmt_list); |
325c3691 | 453 | /* ??? See c_end_compound_stmt re statement expressions. */ |
35b1567d BC |
454 | } |
455 | ||
325c3691 | 456 | return stmt_list; |
35b1567d BC |
457 | } |
458 | ||
c8094d83 | 459 | /* Begin a new scope. */ |
35b1567d | 460 | |
325c3691 | 461 | static tree |
92bc1323 | 462 | do_pushlevel (scope_kind sk) |
35b1567d | 463 | { |
325c3691 | 464 | tree ret = push_stmt_list (); |
f2c5f623 | 465 | if (stmts_are_full_exprs_p ()) |
325c3691 RH |
466 | begin_scope (sk, NULL); |
467 | return ret; | |
468 | } | |
5a508662 RH |
469 | |
470 | /* Queue a cleanup. CLEANUP is an expression/statement to be executed | |
471 | when the current scope is exited. EH_ONLY is true when this is not | |
472 | meant to apply to normal control flow transfer. */ | |
473 | ||
474 | void | |
475 | push_cleanup (tree decl, tree cleanup, bool eh_only) | |
476 | { | |
c2255bc4 | 477 | tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl); |
5a508662 RH |
478 | CLEANUP_EH_ONLY (stmt) = eh_only; |
479 | add_stmt (stmt); | |
480 | CLEANUP_BODY (stmt) = push_stmt_list (); | |
481 | } | |
325c3691 | 482 | |
20f18c3c JM |
483 | /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all |
484 | the current loops, represented by 'NULL_TREE' if we've seen a possible | |
485 | exit, and 'error_mark_node' if not. This is currently used only to | |
486 | suppress the warning about a function with no return statements, and | |
487 | therefore we don't bother noting returns as possible exits. We also | |
488 | don't bother with gotos. */ | |
489 | ||
490 | static void | |
491 | begin_maybe_infinite_loop (tree cond) | |
492 | { | |
493 | /* Only track this while parsing a function, not during instantiation. */ | |
494 | if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl) | |
495 | && !processing_template_decl)) | |
496 | return; | |
497 | bool maybe_infinite = true; | |
498 | if (cond) | |
499 | { | |
234bef96 | 500 | cond = fold_non_dependent_expr (cond); |
20f18c3c JM |
501 | maybe_infinite = integer_nonzerop (cond); |
502 | } | |
503 | vec_safe_push (cp_function_chain->infinite_loops, | |
504 | maybe_infinite ? error_mark_node : NULL_TREE); | |
505 | ||
506 | } | |
507 | ||
508 | /* A break is a possible exit for the current loop. */ | |
509 | ||
510 | void | |
511 | break_maybe_infinite_loop (void) | |
512 | { | |
513 | if (!cfun) | |
514 | return; | |
515 | cp_function_chain->infinite_loops->last() = NULL_TREE; | |
516 | } | |
517 | ||
518 | /* If we reach the end of the loop without seeing a possible exit, we have | |
519 | an infinite loop. */ | |
520 | ||
521 | static void | |
522 | end_maybe_infinite_loop (tree cond) | |
523 | { | |
524 | if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl) | |
525 | && !processing_template_decl)) | |
526 | return; | |
527 | tree current = cp_function_chain->infinite_loops->pop(); | |
528 | if (current != NULL_TREE) | |
529 | { | |
530 | cond = fold_non_dependent_expr (cond); | |
20f18c3c JM |
531 | if (integer_nonzerop (cond)) |
532 | current_function_infinite_loop = 1; | |
533 | } | |
534 | } | |
535 | ||
536 | ||
caf2523d RH |
537 | /* Begin a conditional that might contain a declaration. When generating |
538 | normal code, we want the declaration to appear before the statement | |
539 | containing the conditional. When generating template code, we want the | |
350fae66 | 540 | conditional to be rendered as the raw DECL_EXPR. */ |
325c3691 RH |
541 | |
542 | static void | |
caf2523d | 543 | begin_cond (tree *cond_p) |
325c3691 | 544 | { |
caf2523d RH |
545 | if (processing_template_decl) |
546 | *cond_p = push_stmt_list (); | |
547 | } | |
548 | ||
549 | /* Finish such a conditional. */ | |
550 | ||
551 | static void | |
552 | finish_cond (tree *cond_p, tree expr) | |
553 | { | |
554 | if (processing_template_decl) | |
35b1567d | 555 | { |
caf2523d | 556 | tree cond = pop_stmt_list (*cond_p); |
5d80a306 | 557 | |
fdaf2f48 JM |
558 | if (expr == NULL_TREE) |
559 | /* Empty condition in 'for'. */ | |
560 | gcc_assert (empty_expr_stmt_p (cond)); | |
561 | else if (check_for_bare_parameter_packs (expr)) | |
562 | expr = error_mark_node; | |
563 | else if (!empty_expr_stmt_p (cond)) | |
564 | expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr); | |
35b1567d | 565 | } |
caf2523d | 566 | *cond_p = expr; |
35b1567d BC |
567 | } |
568 | ||
325c3691 RH |
569 | /* If *COND_P specifies a conditional with a declaration, transform the |
570 | loop such that | |
0cbd7506 MS |
571 | while (A x = 42) { } |
572 | for (; A x = 42;) { } | |
325c3691 | 573 | becomes |
0cbd7506 MS |
574 | while (true) { A x = 42; if (!x) break; } |
575 | for (;;) { A x = 42; if (!x) break; } | |
caf2523d RH |
576 | The statement list for BODY will be empty if the conditional did |
577 | not declare anything. */ | |
c8094d83 | 578 | |
325c3691 | 579 | static void |
caf2523d | 580 | simplify_loop_decl_cond (tree *cond_p, tree body) |
325c3691 | 581 | { |
caf2523d | 582 | tree cond, if_stmt; |
325c3691 | 583 | |
caf2523d RH |
584 | if (!TREE_SIDE_EFFECTS (body)) |
585 | return; | |
325c3691 | 586 | |
caf2523d RH |
587 | cond = *cond_p; |
588 | *cond_p = boolean_true_node; | |
c8094d83 | 589 | |
caf2523d | 590 | if_stmt = begin_if_stmt (); |
5ade1ed2 | 591 | cond = cp_build_unary_op (TRUTH_NOT_EXPR, cond, 0, tf_warning_or_error); |
caf2523d RH |
592 | finish_if_stmt_cond (cond, if_stmt); |
593 | finish_break_stmt (); | |
594 | finish_then_clause (if_stmt); | |
595 | finish_if_stmt (if_stmt); | |
596 | } | |
325c3691 | 597 | |
35b1567d BC |
598 | /* Finish a goto-statement. */ |
599 | ||
3e4d04a1 | 600 | tree |
3a978d72 | 601 | finish_goto_stmt (tree destination) |
35b1567d | 602 | { |
9dc6f476 | 603 | if (identifier_p (destination)) |
35b1567d BC |
604 | destination = lookup_label (destination); |
605 | ||
606 | /* We warn about unused labels with -Wunused. That means we have to | |
607 | mark the used labels as used. */ | |
608 | if (TREE_CODE (destination) == LABEL_DECL) | |
609 | TREE_USED (destination) = 1; | |
fc2b8477 MM |
610 | else |
611 | { | |
14f68c39 AK |
612 | if (check_no_cilk (destination, |
613 | "Cilk array notation cannot be used as a computed goto expression", | |
614 | "%<_Cilk_spawn%> statement cannot be used as a computed goto expression")) | |
615 | destination = error_mark_node; | |
84628aa8 | 616 | destination = mark_rvalue_use (destination); |
fc2b8477 | 617 | if (!processing_template_decl) |
f5651df1 | 618 | { |
4b978f96 PC |
619 | destination = cp_convert (ptr_type_node, destination, |
620 | tf_warning_or_error); | |
f5651df1 JJ |
621 | if (error_operand_p (destination)) |
622 | return NULL_TREE; | |
53406315 JJ |
623 | destination |
624 | = fold_build_cleanup_point_expr (TREE_TYPE (destination), | |
625 | destination); | |
f5651df1 | 626 | } |
fc2b8477 | 627 | } |
c8094d83 | 628 | |
35b1567d BC |
629 | check_goto (destination); |
630 | ||
c2255bc4 | 631 | return add_stmt (build_stmt (input_location, GOTO_EXPR, destination)); |
35b1567d BC |
632 | } |
633 | ||
ed5511d9 | 634 | /* COND is the condition-expression for an if, while, etc., |
d4033c81 MLI |
635 | statement. Convert it to a boolean value, if appropriate. |
636 | In addition, verify sequence points if -Wsequence-point is enabled. */ | |
ed5511d9 | 637 | |
8ce33230 | 638 | static tree |
3a978d72 | 639 | maybe_convert_cond (tree cond) |
ed5511d9 MM |
640 | { |
641 | /* Empty conditions remain empty. */ | |
642 | if (!cond) | |
643 | return NULL_TREE; | |
644 | ||
645 | /* Wait until we instantiate templates before doing conversion. */ | |
646 | if (processing_template_decl) | |
647 | return cond; | |
648 | ||
d4033c81 MLI |
649 | if (warn_sequence_point) |
650 | verify_sequence_points (cond); | |
651 | ||
ed5511d9 MM |
652 | /* Do the conversion. */ |
653 | cond = convert_from_reference (cond); | |
fbc8d2d3 ILT |
654 | |
655 | if (TREE_CODE (cond) == MODIFY_EXPR | |
656 | && !TREE_NO_WARNING (cond) | |
657 | && warn_parentheses) | |
658 | { | |
659 | warning (OPT_Wparentheses, | |
660 | "suggest parentheses around assignment used as truth value"); | |
661 | TREE_NO_WARNING (cond) = 1; | |
662 | } | |
663 | ||
ed5511d9 MM |
664 | return condition_conversion (cond); |
665 | } | |
666 | ||
9bfadf57 | 667 | /* Finish an expression-statement, whose EXPRESSION is as indicated. */ |
a7e4cfa0 | 668 | |
3e4d04a1 | 669 | tree |
3a978d72 | 670 | finish_expr_stmt (tree expr) |
ad321293 | 671 | { |
3e4d04a1 RH |
672 | tree r = NULL_TREE; |
673 | ||
ce4a0391 | 674 | if (expr != NULL_TREE) |
ad321293 | 675 | { |
a5bcc582 | 676 | if (!processing_template_decl) |
3a5b9284 RH |
677 | { |
678 | if (warn_sequence_point) | |
679 | verify_sequence_points (expr); | |
ebeb2c24 | 680 | expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error); |
3a5b9284 | 681 | } |
47d4c811 | 682 | else if (!type_dependent_expression_p (expr)) |
ebeb2c24 | 683 | convert_to_void (build_non_dependent_expr (expr), ICV_STATEMENT, |
5ade1ed2 | 684 | tf_warning_or_error); |
325c3691 | 685 | |
7b3e2d46 | 686 | if (check_for_bare_parameter_packs (expr)) |
4439d02f | 687 | expr = error_mark_node; |
5d80a306 | 688 | |
325c3691 | 689 | /* Simplification of inner statement expressions, compound exprs, |
ca5b80f3 | 690 | etc can result in us already having an EXPR_STMT. */ |
543a0daa RH |
691 | if (TREE_CODE (expr) != CLEANUP_POINT_EXPR) |
692 | { | |
693 | if (TREE_CODE (expr) != EXPR_STMT) | |
c2255bc4 | 694 | expr = build_stmt (input_location, EXPR_STMT, expr); |
0ad28dde | 695 | expr = maybe_cleanup_point_expr_void (expr); |
543a0daa RH |
696 | } |
697 | ||
325c3691 | 698 | r = add_stmt (expr); |
35b1567d | 699 | } |
364460b6 | 700 | |
3e4d04a1 | 701 | return r; |
35b1567d BC |
702 | } |
703 | ||
35b1567d | 704 | |
ad321293 MM |
705 | /* Begin an if-statement. Returns a newly created IF_STMT if |
706 | appropriate. */ | |
707 | ||
708 | tree | |
3a978d72 | 709 | begin_if_stmt (void) |
ad321293 | 710 | { |
325c3691 | 711 | tree r, scope; |
1eb2a14d | 712 | scope = do_pushlevel (sk_cond); |
545f261b NF |
713 | r = build_stmt (input_location, IF_STMT, NULL_TREE, |
714 | NULL_TREE, NULL_TREE, scope); | |
caf2523d | 715 | begin_cond (&IF_COND (r)); |
ad321293 MM |
716 | return r; |
717 | } | |
718 | ||
719 | /* Process the COND of an if-statement, which may be given by | |
720 | IF_STMT. */ | |
721 | ||
c8094d83 | 722 | void |
3a978d72 | 723 | finish_if_stmt_cond (tree cond, tree if_stmt) |
ad321293 | 724 | { |
caf2523d RH |
725 | finish_cond (&IF_COND (if_stmt), maybe_convert_cond (cond)); |
726 | add_stmt (if_stmt); | |
325c3691 | 727 | THEN_CLAUSE (if_stmt) = push_stmt_list (); |
ad321293 MM |
728 | } |
729 | ||
730 | /* Finish the then-clause of an if-statement, which may be given by | |
731 | IF_STMT. */ | |
732 | ||
733 | tree | |
3a978d72 | 734 | finish_then_clause (tree if_stmt) |
ad321293 | 735 | { |
325c3691 | 736 | THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt)); |
35b1567d | 737 | return if_stmt; |
ad321293 MM |
738 | } |
739 | ||
740 | /* Begin the else-clause of an if-statement. */ | |
741 | ||
325c3691 RH |
742 | void |
743 | begin_else_clause (tree if_stmt) | |
ad321293 | 744 | { |
325c3691 | 745 | ELSE_CLAUSE (if_stmt) = push_stmt_list (); |
ad321293 MM |
746 | } |
747 | ||
748 | /* Finish the else-clause of an if-statement, which may be given by | |
749 | IF_STMT. */ | |
750 | ||
751 | void | |
3a978d72 | 752 | finish_else_clause (tree if_stmt) |
ad321293 | 753 | { |
325c3691 | 754 | ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt)); |
ad321293 MM |
755 | } |
756 | ||
dfbb4f34 | 757 | /* Finish an if-statement. */ |
ad321293 | 758 | |
c8094d83 | 759 | void |
325c3691 | 760 | finish_if_stmt (tree if_stmt) |
ad321293 | 761 | { |
545f261b NF |
762 | tree scope = IF_SCOPE (if_stmt); |
763 | IF_SCOPE (if_stmt) = NULL; | |
325c3691 | 764 | add_stmt (do_poplevel (scope)); |
35b1567d BC |
765 | } |
766 | ||
ad321293 MM |
767 | /* Begin a while-statement. Returns a newly created WHILE_STMT if |
768 | appropriate. */ | |
769 | ||
770 | tree | |
3a978d72 | 771 | begin_while_stmt (void) |
ad321293 MM |
772 | { |
773 | tree r; | |
c2255bc4 | 774 | r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE); |
ae499cce | 775 | add_stmt (r); |
325c3691 | 776 | WHILE_BODY (r) = do_pushlevel (sk_block); |
caf2523d | 777 | begin_cond (&WHILE_COND (r)); |
ad321293 MM |
778 | return r; |
779 | } | |
780 | ||
27d26ee7 | 781 | /* Process the COND of a while-statement, which may be given by |
ad321293 MM |
782 | WHILE_STMT. */ |
783 | ||
c8094d83 | 784 | void |
c5028d80 | 785 | finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep) |
ad321293 | 786 | { |
14f68c39 AK |
787 | if (check_no_cilk (cond, |
788 | "Cilk array notation cannot be used as a condition for while statement", | |
789 | "%<_Cilk_spawn%> statement cannot be used as a condition for while statement")) | |
790 | cond = error_mark_node; | |
20f18c3c JM |
791 | cond = maybe_convert_cond (cond); |
792 | finish_cond (&WHILE_COND (while_stmt), cond); | |
793 | begin_maybe_infinite_loop (cond); | |
c5028d80 TB |
794 | if (ivdep && cond != error_mark_node) |
795 | WHILE_COND (while_stmt) = build2 (ANNOTATE_EXPR, | |
796 | TREE_TYPE (WHILE_COND (while_stmt)), | |
797 | WHILE_COND (while_stmt), | |
798 | build_int_cst (integer_type_node, | |
799 | annot_expr_ivdep_kind)); | |
caf2523d | 800 | simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt)); |
ad321293 MM |
801 | } |
802 | ||
803 | /* Finish a while-statement, which may be given by WHILE_STMT. */ | |
804 | ||
c8094d83 | 805 | void |
3a978d72 | 806 | finish_while_stmt (tree while_stmt) |
ad321293 | 807 | { |
20f18c3c | 808 | end_maybe_infinite_loop (boolean_true_node); |
325c3691 | 809 | WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt)); |
ad321293 MM |
810 | } |
811 | ||
812 | /* Begin a do-statement. Returns a newly created DO_STMT if | |
813 | appropriate. */ | |
814 | ||
815 | tree | |
3a978d72 | 816 | begin_do_stmt (void) |
ad321293 | 817 | { |
c2255bc4 | 818 | tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE); |
20f18c3c | 819 | begin_maybe_infinite_loop (boolean_true_node); |
ae499cce | 820 | add_stmt (r); |
325c3691 | 821 | DO_BODY (r) = push_stmt_list (); |
35b1567d | 822 | return r; |
ad321293 MM |
823 | } |
824 | ||
825 | /* Finish the body of a do-statement, which may be given by DO_STMT. */ | |
826 | ||
827 | void | |
3a978d72 | 828 | finish_do_body (tree do_stmt) |
ad321293 | 829 | { |
62e00e94 DM |
830 | tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt)); |
831 | ||
832 | if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body)) | |
833 | body = STATEMENT_LIST_TAIL (body)->stmt; | |
834 | ||
835 | if (IS_EMPTY_STMT (body)) | |
836 | warning (OPT_Wempty_body, | |
837 | "suggest explicit braces around empty body in %<do%> statement"); | |
ad321293 MM |
838 | } |
839 | ||
840 | /* Finish a do-statement, which may be given by DO_STMT, and whose | |
841 | COND is as indicated. */ | |
842 | ||
843 | void | |
c5028d80 | 844 | finish_do_stmt (tree cond, tree do_stmt, bool ivdep) |
ad321293 | 845 | { |
14f68c39 AK |
846 | if (check_no_cilk (cond, |
847 | "Cilk array notation cannot be used as a condition for a do-while statement", | |
848 | "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement")) | |
849 | cond = error_mark_node; | |
ed5511d9 | 850 | cond = maybe_convert_cond (cond); |
20f18c3c | 851 | end_maybe_infinite_loop (cond); |
c5028d80 TB |
852 | if (ivdep && cond != error_mark_node) |
853 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, | |
854 | build_int_cst (integer_type_node, annot_expr_ivdep_kind)); | |
35b1567d | 855 | DO_COND (do_stmt) = cond; |
35b1567d | 856 | } |
ed5511d9 | 857 | |
ad321293 MM |
858 | /* Finish a return-statement. The EXPRESSION returned, if any, is as |
859 | indicated. */ | |
860 | ||
3e4d04a1 | 861 | tree |
3a978d72 | 862 | finish_return_stmt (tree expr) |
ad321293 | 863 | { |
3e4d04a1 | 864 | tree r; |
0c9b182b | 865 | bool no_warning; |
3e4d04a1 | 866 | |
0c9b182b | 867 | expr = check_return_expr (expr, &no_warning); |
1799e5d5 | 868 | |
830ce0a2 MP |
869 | if (error_operand_p (expr) |
870 | || (flag_openmp && !check_omp_return ())) | |
3dbb8427 JM |
871 | { |
872 | /* Suppress -Wreturn-type for this function. */ | |
873 | if (warn_return_type) | |
874 | TREE_NO_WARNING (current_function_decl) = true; | |
875 | return error_mark_node; | |
876 | } | |
877 | ||
35b1567d | 878 | if (!processing_template_decl) |
efee38a9 | 879 | { |
d4033c81 MLI |
880 | if (warn_sequence_point) |
881 | verify_sequence_points (expr); | |
882 | ||
44d10c10 | 883 | if (DECL_DESTRUCTOR_P (current_function_decl) |
c8094d83 | 884 | || (DECL_CONSTRUCTOR_P (current_function_decl) |
44d10c10 | 885 | && targetm.cxx.cdtor_returns_this ())) |
efee38a9 MM |
886 | { |
887 | /* Similarly, all destructors must run destructors for | |
888 | base-classes before returning. So, all returns in a | |
dfbb4f34 | 889 | destructor get sent to the DTOR_LABEL; finish_function emits |
efee38a9 | 890 | code to return a value there. */ |
44d10c10 | 891 | return finish_goto_stmt (cdtor_label); |
efee38a9 MM |
892 | } |
893 | } | |
543a0daa | 894 | |
c2255bc4 | 895 | r = build_stmt (input_location, RETURN_EXPR, expr); |
0c9b182b | 896 | TREE_NO_WARNING (r) |= no_warning; |
0ad28dde | 897 | r = maybe_cleanup_point_expr_void (r); |
543a0daa | 898 | r = add_stmt (r); |
3e4d04a1 RH |
899 | |
900 | return r; | |
35b1567d | 901 | } |
efee38a9 | 902 | |
3f43ac31 RRC |
903 | /* Begin the scope of a for-statement or a range-for-statement. |
904 | Both the returned trees are to be used in a call to | |
905 | begin_for_stmt or begin_range_for_stmt. */ | |
ad321293 MM |
906 | |
907 | tree | |
3f43ac31 RRC |
908 | begin_for_scope (tree *init) |
909 | { | |
910 | tree scope = NULL_TREE; | |
911 | if (flag_new_for_scope > 0) | |
912 | scope = do_pushlevel (sk_for); | |
913 | ||
914 | if (processing_template_decl) | |
915 | *init = push_stmt_list (); | |
916 | else | |
917 | *init = NULL_TREE; | |
918 | ||
919 | return scope; | |
920 | } | |
921 | ||
922 | /* Begin a for-statement. Returns a new FOR_STMT. | |
923 | SCOPE and INIT should be the return of begin_for_scope, | |
924 | or both NULL_TREE */ | |
925 | ||
926 | tree | |
927 | begin_for_stmt (tree scope, tree init) | |
ad321293 MM |
928 | { |
929 | tree r; | |
930 | ||
c2255bc4 | 931 | r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE, |
40e71fc7 | 932 | NULL_TREE, NULL_TREE, NULL_TREE); |
325c3691 | 933 | |
3f43ac31 RRC |
934 | if (scope == NULL_TREE) |
935 | { | |
95cc031f JJ |
936 | gcc_assert (!init || !(flag_new_for_scope > 0)); |
937 | if (!init) | |
938 | scope = begin_for_scope (&init); | |
3f43ac31 RRC |
939 | } |
940 | FOR_INIT_STMT (r) = init; | |
40e71fc7 | 941 | FOR_SCOPE (r) = scope; |
894ca2c9 | 942 | |
ad321293 MM |
943 | return r; |
944 | } | |
945 | ||
946 | /* Finish the for-init-statement of a for-statement, which may be | |
947 | given by FOR_STMT. */ | |
948 | ||
949 | void | |
3a978d72 | 950 | finish_for_init_stmt (tree for_stmt) |
ad321293 | 951 | { |
894ca2c9 RH |
952 | if (processing_template_decl) |
953 | FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt)); | |
325c3691 RH |
954 | add_stmt (for_stmt); |
955 | FOR_BODY (for_stmt) = do_pushlevel (sk_block); | |
caf2523d | 956 | begin_cond (&FOR_COND (for_stmt)); |
ad321293 MM |
957 | } |
958 | ||
959 | /* Finish the COND of a for-statement, which may be given by | |
960 | FOR_STMT. */ | |
961 | ||
962 | void | |
c5028d80 | 963 | finish_for_cond (tree cond, tree for_stmt, bool ivdep) |
ad321293 | 964 | { |
14f68c39 AK |
965 | if (check_no_cilk (cond, |
966 | "Cilk array notation cannot be used in a condition for a for-loop", | |
967 | "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop")) | |
968 | cond = error_mark_node; | |
20f18c3c JM |
969 | cond = maybe_convert_cond (cond); |
970 | finish_cond (&FOR_COND (for_stmt), cond); | |
971 | begin_maybe_infinite_loop (cond); | |
c5028d80 TB |
972 | if (ivdep && cond != error_mark_node) |
973 | FOR_COND (for_stmt) = build2 (ANNOTATE_EXPR, | |
974 | TREE_TYPE (FOR_COND (for_stmt)), | |
975 | FOR_COND (for_stmt), | |
976 | build_int_cst (integer_type_node, | |
977 | annot_expr_ivdep_kind)); | |
caf2523d | 978 | simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt)); |
ad321293 MM |
979 | } |
980 | ||
981 | /* Finish the increment-EXPRESSION in a for-statement, which may be | |
982 | given by FOR_STMT. */ | |
983 | ||
984 | void | |
3a978d72 | 985 | finish_for_expr (tree expr, tree for_stmt) |
ad321293 | 986 | { |
543a0daa RH |
987 | if (!expr) |
988 | return; | |
6f69173e MM |
989 | /* If EXPR is an overloaded function, issue an error; there is no |
990 | context available to use to perform overload resolution. */ | |
543a0daa | 991 | if (type_unknown_p (expr)) |
6f69173e MM |
992 | { |
993 | cxx_incomplete_type_error (expr, TREE_TYPE (expr)); | |
994 | expr = error_mark_node; | |
995 | } | |
bcd46a7c AP |
996 | if (!processing_template_decl) |
997 | { | |
998 | if (warn_sequence_point) | |
0cbd7506 | 999 | verify_sequence_points (expr); |
ebeb2c24 | 1000 | expr = convert_to_void (expr, ICV_THIRD_IN_FOR, |
5ade1ed2 | 1001 | tf_warning_or_error); |
bcd46a7c AP |
1002 | } |
1003 | else if (!type_dependent_expression_p (expr)) | |
ebeb2c24 | 1004 | convert_to_void (build_non_dependent_expr (expr), ICV_THIRD_IN_FOR, |
5ade1ed2 | 1005 | tf_warning_or_error); |
0ad28dde | 1006 | expr = maybe_cleanup_point_expr_void (expr); |
7b3e2d46 | 1007 | if (check_for_bare_parameter_packs (expr)) |
4439d02f | 1008 | expr = error_mark_node; |
35b1567d | 1009 | FOR_EXPR (for_stmt) = expr; |
ad321293 MM |
1010 | } |
1011 | ||
1012 | /* Finish the body of a for-statement, which may be given by | |
1013 | FOR_STMT. The increment-EXPR for the loop must be | |
f9132eb7 RRC |
1014 | provided. |
1015 | It can also finish RANGE_FOR_STMT. */ | |
ad321293 MM |
1016 | |
1017 | void | |
3a978d72 | 1018 | finish_for_stmt (tree for_stmt) |
ad321293 | 1019 | { |
20f18c3c JM |
1020 | end_maybe_infinite_loop (boolean_true_node); |
1021 | ||
f9132eb7 | 1022 | if (TREE_CODE (for_stmt) == RANGE_FOR_STMT) |
a8733ebf | 1023 | RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt)); |
f9132eb7 | 1024 | else |
a8733ebf | 1025 | FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt)); |
325c3691 | 1026 | |
ad321293 | 1027 | /* Pop the scope for the body of the loop. */ |
a8733ebf | 1028 | if (flag_new_for_scope > 0) |
325c3691 | 1029 | { |
40e71fc7 NF |
1030 | tree scope; |
1031 | tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT | |
1032 | ? &RANGE_FOR_SCOPE (for_stmt) | |
1033 | : &FOR_SCOPE (for_stmt)); | |
1034 | scope = *scope_ptr; | |
1035 | *scope_ptr = NULL; | |
325c3691 RH |
1036 | add_stmt (do_poplevel (scope)); |
1037 | } | |
ad321293 MM |
1038 | } |
1039 | ||
f9132eb7 | 1040 | /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT. |
3f43ac31 RRC |
1041 | SCOPE and INIT should be the return of begin_for_scope, |
1042 | or both NULL_TREE . | |
f9132eb7 RRC |
1043 | To finish it call finish_for_stmt(). */ |
1044 | ||
1045 | tree | |
3f43ac31 | 1046 | begin_range_for_stmt (tree scope, tree init) |
f9132eb7 RRC |
1047 | { |
1048 | tree r; | |
a8733ebf | 1049 | |
20f18c3c JM |
1050 | begin_maybe_infinite_loop (boolean_false_node); |
1051 | ||
f9132eb7 | 1052 | r = build_stmt (input_location, RANGE_FOR_STMT, |
40e71fc7 | 1053 | NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE); |
a8733ebf | 1054 | |
3f43ac31 RRC |
1055 | if (scope == NULL_TREE) |
1056 | { | |
95cc031f JJ |
1057 | gcc_assert (!init || !(flag_new_for_scope > 0)); |
1058 | if (!init) | |
1059 | scope = begin_for_scope (&init); | |
3f43ac31 RRC |
1060 | } |
1061 | ||
1062 | /* RANGE_FOR_STMTs do not use nor save the init tree, so we | |
1063 | pop it now. */ | |
1064 | if (init) | |
1065 | pop_stmt_list (init); | |
40e71fc7 | 1066 | RANGE_FOR_SCOPE (r) = scope; |
f9132eb7 RRC |
1067 | |
1068 | return r; | |
1069 | } | |
1070 | ||
1071 | /* Finish the head of a range-based for statement, which may | |
1072 | be given by RANGE_FOR_STMT. DECL must be the declaration | |
1073 | and EXPR must be the loop expression. */ | |
1074 | ||
1075 | void | |
1076 | finish_range_for_decl (tree range_for_stmt, tree decl, tree expr) | |
1077 | { | |
1078 | RANGE_FOR_DECL (range_for_stmt) = decl; | |
1079 | RANGE_FOR_EXPR (range_for_stmt) = expr; | |
1080 | add_stmt (range_for_stmt); | |
1081 | RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block); | |
1082 | } | |
1083 | ||
ad321293 MM |
1084 | /* Finish a break-statement. */ |
1085 | ||
3e4d04a1 | 1086 | tree |
3a978d72 | 1087 | finish_break_stmt (void) |
ad321293 | 1088 | { |
04771457 JM |
1089 | /* In switch statements break is sometimes stylistically used after |
1090 | a return statement. This can lead to spurious warnings about | |
1091 | control reaching the end of a non-void function when it is | |
1092 | inlined. Note that we are calling block_may_fallthru with | |
1093 | language specific tree nodes; this works because | |
1094 | block_may_fallthru returns true when given something it does not | |
1095 | understand. */ | |
1096 | if (!block_may_fallthru (cur_stmt_list)) | |
632f2871 | 1097 | return void_node; |
c2255bc4 | 1098 | return add_stmt (build_stmt (input_location, BREAK_STMT)); |
35b1567d BC |
1099 | } |
1100 | ||
ad321293 MM |
1101 | /* Finish a continue-statement. */ |
1102 | ||
3e4d04a1 | 1103 | tree |
3a978d72 | 1104 | finish_continue_stmt (void) |
ad321293 | 1105 | { |
c2255bc4 | 1106 | return add_stmt (build_stmt (input_location, CONTINUE_STMT)); |
ad321293 MM |
1107 | } |
1108 | ||
35b1567d BC |
1109 | /* Begin a switch-statement. Returns a new SWITCH_STMT if |
1110 | appropriate. */ | |
1111 | ||
1112 | tree | |
3a978d72 | 1113 | begin_switch_stmt (void) |
35b1567d | 1114 | { |
325c3691 RH |
1115 | tree r, scope; |
1116 | ||
1eb2a14d | 1117 | scope = do_pushlevel (sk_cond); |
1f18dbc6 NF |
1118 | r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE, scope); |
1119 | ||
ebaae582 | 1120 | begin_cond (&SWITCH_STMT_COND (r)); |
325c3691 | 1121 | |
527f0080 | 1122 | return r; |
ad321293 MM |
1123 | } |
1124 | ||
527f0080 | 1125 | /* Finish the cond of a switch-statement. */ |
ad321293 | 1126 | |
527f0080 | 1127 | void |
3a978d72 | 1128 | finish_switch_cond (tree cond, tree switch_stmt) |
ad321293 | 1129 | { |
6f9fdf4d | 1130 | tree orig_type = NULL; |
14f68c39 AK |
1131 | |
1132 | if (check_no_cilk (cond, | |
1133 | "Cilk array notation cannot be used as a condition for switch statement", | |
1134 | "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement")) | |
1135 | cond = error_mark_node; | |
1136 | ||
35b1567d | 1137 | if (!processing_template_decl) |
373eb3b3 | 1138 | { |
35b1567d | 1139 | /* Convert the condition to an integer or enumeration type. */ |
b746c5dc | 1140 | cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true); |
35b1567d | 1141 | if (cond == NULL_TREE) |
373eb3b3 | 1142 | { |
35b1567d BC |
1143 | error ("switch quantity not an integer"); |
1144 | cond = error_mark_node; | |
1145 | } | |
083e891e MP |
1146 | /* We want unlowered type here to handle enum bit-fields. */ |
1147 | orig_type = unlowered_expr_type (cond); | |
5964a3a6 MP |
1148 | if (TREE_CODE (orig_type) != ENUMERAL_TYPE) |
1149 | orig_type = TREE_TYPE (cond); | |
35b1567d BC |
1150 | if (cond != error_mark_node) |
1151 | { | |
0a72704b MM |
1152 | /* [stmt.switch] |
1153 | ||
1154 | Integral promotions are performed. */ | |
1155 | cond = perform_integral_promotions (cond); | |
543a0daa | 1156 | cond = maybe_cleanup_point_expr (cond); |
373eb3b3 | 1157 | } |
ad321293 | 1158 | } |
7b3e2d46 | 1159 | if (check_for_bare_parameter_packs (cond)) |
4439d02f | 1160 | cond = error_mark_node; |
d4033c81 MLI |
1161 | else if (!processing_template_decl && warn_sequence_point) |
1162 | verify_sequence_points (cond); | |
1163 | ||
ebaae582 SB |
1164 | finish_cond (&SWITCH_STMT_COND (switch_stmt), cond); |
1165 | SWITCH_STMT_TYPE (switch_stmt) = orig_type; | |
caf2523d | 1166 | add_stmt (switch_stmt); |
56cb9733 | 1167 | push_switch (switch_stmt); |
ebaae582 | 1168 | SWITCH_STMT_BODY (switch_stmt) = push_stmt_list (); |
ad321293 MM |
1169 | } |
1170 | ||
1171 | /* Finish the body of a switch-statement, which may be given by | |
1172 | SWITCH_STMT. The COND to switch on is indicated. */ | |
1173 | ||
1174 | void | |
3a978d72 | 1175 | finish_switch_stmt (tree switch_stmt) |
ad321293 | 1176 | { |
325c3691 RH |
1177 | tree scope; |
1178 | ||
ebaae582 SB |
1179 | SWITCH_STMT_BODY (switch_stmt) = |
1180 | pop_stmt_list (SWITCH_STMT_BODY (switch_stmt)); | |
c8094d83 | 1181 | pop_switch (); |
325c3691 | 1182 | |
1f18dbc6 NF |
1183 | scope = SWITCH_STMT_SCOPE (switch_stmt); |
1184 | SWITCH_STMT_SCOPE (switch_stmt) = NULL; | |
325c3691 | 1185 | add_stmt (do_poplevel (scope)); |
ad321293 MM |
1186 | } |
1187 | ||
ad321293 MM |
1188 | /* Begin a try-block. Returns a newly-created TRY_BLOCK if |
1189 | appropriate. */ | |
1190 | ||
1191 | tree | |
3a978d72 | 1192 | begin_try_block (void) |
ad321293 | 1193 | { |
c2255bc4 | 1194 | tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE); |
ae499cce | 1195 | add_stmt (r); |
325c3691 | 1196 | TRY_STMTS (r) = push_stmt_list (); |
35b1567d | 1197 | return r; |
ad321293 MM |
1198 | } |
1199 | ||
eaf6fb90 MM |
1200 | /* Likewise, for a function-try-block. The block returned in |
1201 | *COMPOUND_STMT is an artificial outer scope, containing the | |
1202 | function-try-block. */ | |
0dde4175 JM |
1203 | |
1204 | tree | |
eaf6fb90 | 1205 | begin_function_try_block (tree *compound_stmt) |
0dde4175 | 1206 | { |
eaf6fb90 MM |
1207 | tree r; |
1208 | /* This outer scope does not exist in the C++ standard, but we need | |
1209 | a place to put __FUNCTION__ and similar variables. */ | |
1210 | *compound_stmt = begin_compound_stmt (0); | |
1211 | r = begin_try_block (); | |
35b1567d | 1212 | FN_TRY_BLOCK_P (r) = 1; |
35b1567d | 1213 | return r; |
0dde4175 JM |
1214 | } |
1215 | ||
ad321293 MM |
1216 | /* Finish a try-block, which may be given by TRY_BLOCK. */ |
1217 | ||
1218 | void | |
3a978d72 | 1219 | finish_try_block (tree try_block) |
ad321293 | 1220 | { |
325c3691 RH |
1221 | TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block)); |
1222 | TRY_HANDLERS (try_block) = push_stmt_list (); | |
ad321293 MM |
1223 | } |
1224 | ||
efa8eda3 MM |
1225 | /* Finish the body of a cleanup try-block, which may be given by |
1226 | TRY_BLOCK. */ | |
1227 | ||
62409b39 | 1228 | void |
3a978d72 | 1229 | finish_cleanup_try_block (tree try_block) |
62409b39 | 1230 | { |
325c3691 | 1231 | TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block)); |
62409b39 MM |
1232 | } |
1233 | ||
f1dedc31 MM |
1234 | /* Finish an implicitly generated try-block, with a cleanup is given |
1235 | by CLEANUP. */ | |
1236 | ||
1237 | void | |
3a978d72 | 1238 | finish_cleanup (tree cleanup, tree try_block) |
f1dedc31 | 1239 | { |
35b1567d BC |
1240 | TRY_HANDLERS (try_block) = cleanup; |
1241 | CLEANUP_P (try_block) = 1; | |
f1dedc31 MM |
1242 | } |
1243 | ||
0dde4175 JM |
1244 | /* Likewise, for a function-try-block. */ |
1245 | ||
1246 | void | |
3a978d72 | 1247 | finish_function_try_block (tree try_block) |
0dde4175 | 1248 | { |
325c3691 RH |
1249 | finish_try_block (try_block); |
1250 | /* FIXME : something queer about CTOR_INITIALIZER somehow following | |
1251 | the try block, but moving it inside. */ | |
b35d4555 | 1252 | in_function_try_handler = 1; |
0dde4175 JM |
1253 | } |
1254 | ||
ad321293 MM |
1255 | /* Finish a handler-sequence for a try-block, which may be given by |
1256 | TRY_BLOCK. */ | |
1257 | ||
1258 | void | |
3a978d72 | 1259 | finish_handler_sequence (tree try_block) |
ad321293 | 1260 | { |
325c3691 | 1261 | TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block)); |
35b1567d | 1262 | check_handlers (TRY_HANDLERS (try_block)); |
ad321293 MM |
1263 | } |
1264 | ||
eaf6fb90 MM |
1265 | /* Finish the handler-seq for a function-try-block, given by |
1266 | TRY_BLOCK. COMPOUND_STMT is the outer block created by | |
1267 | begin_function_try_block. */ | |
0dde4175 JM |
1268 | |
1269 | void | |
eaf6fb90 | 1270 | finish_function_handler_sequence (tree try_block, tree compound_stmt) |
0dde4175 | 1271 | { |
b35d4555 | 1272 | in_function_try_handler = 0; |
325c3691 | 1273 | finish_handler_sequence (try_block); |
eaf6fb90 | 1274 | finish_compound_stmt (compound_stmt); |
35b1567d BC |
1275 | } |
1276 | ||
ad321293 MM |
1277 | /* Begin a handler. Returns a HANDLER if appropriate. */ |
1278 | ||
1279 | tree | |
3a978d72 | 1280 | begin_handler (void) |
ad321293 MM |
1281 | { |
1282 | tree r; | |
325c3691 | 1283 | |
c2255bc4 | 1284 | r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE); |
ae499cce | 1285 | add_stmt (r); |
325c3691 | 1286 | |
1a6025b4 JM |
1287 | /* Create a binding level for the eh_info and the exception object |
1288 | cleanup. */ | |
325c3691 RH |
1289 | HANDLER_BODY (r) = do_pushlevel (sk_catch); |
1290 | ||
ad321293 MM |
1291 | return r; |
1292 | } | |
1293 | ||
1294 | /* Finish the handler-parameters for a handler, which may be given by | |
b35d4555 MM |
1295 | HANDLER. DECL is the declaration for the catch parameter, or NULL |
1296 | if this is a `catch (...)' clause. */ | |
ad321293 | 1297 | |
1a6025b4 | 1298 | void |
3a978d72 | 1299 | finish_handler_parms (tree decl, tree handler) |
b35d4555 | 1300 | { |
1a6025b4 | 1301 | tree type = NULL_TREE; |
b35d4555 MM |
1302 | if (processing_template_decl) |
1303 | { | |
1304 | if (decl) | |
1305 | { | |
1306 | decl = pushdecl (decl); | |
1307 | decl = push_template_decl (decl); | |
325c3691 | 1308 | HANDLER_PARMS (handler) = decl; |
1a6025b4 | 1309 | type = TREE_TYPE (decl); |
b35d4555 MM |
1310 | } |
1311 | } | |
35b1567d | 1312 | else |
1a6025b4 | 1313 | type = expand_start_catch_block (decl); |
1a6025b4 | 1314 | HANDLER_TYPE (handler) = type; |
35b1567d BC |
1315 | } |
1316 | ||
1317 | /* Finish a handler, which may be given by HANDLER. The BLOCKs are | |
1318 | the return value from the matching call to finish_handler_parms. */ | |
1319 | ||
1320 | void | |
3a978d72 | 1321 | finish_handler (tree handler) |
35b1567d BC |
1322 | { |
1323 | if (!processing_template_decl) | |
1a6025b4 | 1324 | expand_end_catch_block (); |
325c3691 | 1325 | HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler)); |
35b1567d BC |
1326 | } |
1327 | ||
5882f0f3 | 1328 | /* Begin a compound statement. FLAGS contains some bits that control the |
5995ebfb | 1329 | behavior and context. If BCS_NO_SCOPE is set, the compound statement |
5882f0f3 | 1330 | does not define a scope. If BCS_FN_BODY is set, this is the outermost |
c8094d83 | 1331 | block of a function. If BCS_TRY_BLOCK is set, this is the block |
5882f0f3 RH |
1332 | created on behalf of a TRY statement. Returns a token to be passed to |
1333 | finish_compound_stmt. */ | |
ad321293 MM |
1334 | |
1335 | tree | |
325c3691 | 1336 | begin_compound_stmt (unsigned int flags) |
ad321293 | 1337 | { |
325c3691 | 1338 | tree r; |
558475f0 | 1339 | |
325c3691 RH |
1340 | if (flags & BCS_NO_SCOPE) |
1341 | { | |
1342 | r = push_stmt_list (); | |
1343 | STATEMENT_LIST_NO_SCOPE (r) = 1; | |
1344 | ||
1345 | /* Normally, we try hard to keep the BLOCK for a statement-expression. | |
1346 | But, if it's a statement-expression with a scopeless block, there's | |
1347 | nothing to keep, and we don't want to accidentally keep a block | |
c8094d83 | 1348 | *inside* the scopeless block. */ |
325c3691 RH |
1349 | keep_next_level (false); |
1350 | } | |
f1dedc31 | 1351 | else |
b8fd7909 JM |
1352 | { |
1353 | scope_kind sk = sk_block; | |
1354 | if (flags & BCS_TRY_BLOCK) | |
1355 | sk = sk_try; | |
1356 | else if (flags & BCS_TRANSACTION) | |
1357 | sk = sk_transaction; | |
1358 | r = do_pushlevel (sk); | |
1359 | } | |
325c3691 | 1360 | |
5882f0f3 RH |
1361 | /* When processing a template, we need to remember where the braces were, |
1362 | so that we can set up identical scopes when instantiating the template | |
1363 | later. BIND_EXPR is a handy candidate for this. | |
1364 | Note that do_poplevel won't create a BIND_EXPR itself here (and thus | |
1365 | result in nested BIND_EXPRs), since we don't build BLOCK nodes when | |
1366 | processing templates. */ | |
1367 | if (processing_template_decl) | |
325c3691 | 1368 | { |
f293ce4b | 1369 | r = build3 (BIND_EXPR, NULL, NULL, r, NULL); |
5882f0f3 RH |
1370 | BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0; |
1371 | BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0; | |
325c3691 RH |
1372 | TREE_SIDE_EFFECTS (r) = 1; |
1373 | } | |
ad321293 MM |
1374 | |
1375 | return r; | |
1376 | } | |
1377 | ||
5882f0f3 | 1378 | /* Finish a compound-statement, which is given by STMT. */ |
ad321293 | 1379 | |
325c3691 RH |
1380 | void |
1381 | finish_compound_stmt (tree stmt) | |
ad321293 | 1382 | { |
5882f0f3 | 1383 | if (TREE_CODE (stmt) == BIND_EXPR) |
e02927a1 JM |
1384 | { |
1385 | tree body = do_poplevel (BIND_EXPR_BODY (stmt)); | |
1386 | /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special, | |
1387 | discard the BIND_EXPR so it can be merged with the containing | |
1388 | STATEMENT_LIST. */ | |
1389 | if (TREE_CODE (body) == STATEMENT_LIST | |
1390 | && STATEMENT_LIST_HEAD (body) == NULL | |
1391 | && !BIND_EXPR_BODY_BLOCK (stmt) | |
1392 | && !BIND_EXPR_TRY_BLOCK (stmt)) | |
1393 | stmt = body; | |
1394 | else | |
1395 | BIND_EXPR_BODY (stmt) = body; | |
1396 | } | |
325c3691 RH |
1397 | else if (STATEMENT_LIST_NO_SCOPE (stmt)) |
1398 | stmt = pop_stmt_list (stmt); | |
7a3397c7 | 1399 | else |
5f070bc7 ZL |
1400 | { |
1401 | /* Destroy any ObjC "super" receivers that may have been | |
1402 | created. */ | |
1403 | objc_clear_super_receiver (); | |
1404 | ||
1405 | stmt = do_poplevel (stmt); | |
1406 | } | |
ad321293 | 1407 | |
325c3691 RH |
1408 | /* ??? See c_end_compound_stmt wrt statement expressions. */ |
1409 | add_stmt (stmt); | |
ad321293 MM |
1410 | } |
1411 | ||
6de9cd9a | 1412 | /* Finish an asm-statement, whose components are a STRING, some |
1c384bf1 RH |
1413 | OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some |
1414 | LABELS. Also note whether the asm-statement should be | |
1415 | considered volatile. */ | |
7dc5bd62 | 1416 | |
3e4d04a1 | 1417 | tree |
6de9cd9a | 1418 | finish_asm_stmt (int volatile_p, tree string, tree output_operands, |
1c384bf1 | 1419 | tree input_operands, tree clobbers, tree labels) |
35b1567d BC |
1420 | { |
1421 | tree r; | |
abfc8a36 | 1422 | tree t; |
5544530a PB |
1423 | int ninputs = list_length (input_operands); |
1424 | int noutputs = list_length (output_operands); | |
abfc8a36 | 1425 | |
abfc8a36 | 1426 | if (!processing_template_decl) |
40b18c0a | 1427 | { |
74f0c611 RH |
1428 | const char *constraint; |
1429 | const char **oconstraints; | |
1430 | bool allows_mem, allows_reg, is_inout; | |
1431 | tree operand; | |
40b18c0a | 1432 | int i; |
40b18c0a | 1433 | |
86b8fed1 | 1434 | oconstraints = XALLOCAVEC (const char *, noutputs); |
74f0c611 RH |
1435 | |
1436 | string = resolve_asm_operand_names (string, output_operands, | |
1c384bf1 | 1437 | input_operands, labels); |
74f0c611 RH |
1438 | |
1439 | for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i) | |
40b18c0a | 1440 | { |
74f0c611 RH |
1441 | operand = TREE_VALUE (t); |
1442 | ||
1443 | /* ??? Really, this should not be here. Users should be using a | |
1444 | proper lvalue, dammit. But there's a long history of using | |
1445 | casts in the output operands. In cases like longlong.h, this | |
1446 | becomes a primitive form of typechecking -- if the cast can be | |
1447 | removed, then the output operand had a type of the proper width; | |
1448 | otherwise we'll get an error. Gross, but ... */ | |
1449 | STRIP_NOPS (operand); | |
1450 | ||
03a904b5 JJ |
1451 | operand = mark_lvalue_use (operand); |
1452 | ||
5ade1ed2 | 1453 | if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error)) |
74f0c611 RH |
1454 | operand = error_mark_node; |
1455 | ||
3db45ab5 | 1456 | if (operand != error_mark_node |
5544530a PB |
1457 | && (TREE_READONLY (operand) |
1458 | || CP_TYPE_CONST_P (TREE_TYPE (operand)) | |
3db45ab5 MS |
1459 | /* Functions are not modifiable, even though they are |
1460 | lvalues. */ | |
1461 | || TREE_CODE (TREE_TYPE (operand)) == FUNCTION_TYPE | |
1462 | || TREE_CODE (TREE_TYPE (operand)) == METHOD_TYPE | |
1463 | /* If it's an aggregate and any field is const, then it is | |
1464 | effectively const. */ | |
1465 | || (CLASS_TYPE_P (TREE_TYPE (operand)) | |
1466 | && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand))))) | |
4816c593 | 1467 | cxx_readonly_error (operand, lv_asm); |
5544530a | 1468 | |
74f0c611 RH |
1469 | constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); |
1470 | oconstraints[i] = constraint; | |
1471 | ||
1472 | if (parse_output_constraint (&constraint, i, ninputs, noutputs, | |
1473 | &allows_mem, &allows_reg, &is_inout)) | |
1474 | { | |
1475 | /* If the operand is going to end up in memory, | |
1476 | mark it addressable. */ | |
1477 | if (!allows_reg && !cxx_mark_addressable (operand)) | |
1478 | operand = error_mark_node; | |
1479 | } | |
1480 | else | |
1481 | operand = error_mark_node; | |
1482 | ||
1483 | TREE_VALUE (t) = operand; | |
1484 | } | |
1485 | ||
1486 | for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t)) | |
1487 | { | |
1488 | constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))); | |
0ab19cbc JJ |
1489 | bool constraint_parsed |
1490 | = parse_input_constraint (&constraint, i, ninputs, noutputs, 0, | |
1491 | oconstraints, &allows_mem, &allows_reg); | |
1492 | /* If the operand is going to end up in memory, don't call | |
1493 | decay_conversion. */ | |
1494 | if (constraint_parsed && !allows_reg && allows_mem) | |
1495 | operand = mark_lvalue_use (TREE_VALUE (t)); | |
1496 | else | |
1497 | operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error); | |
74f0c611 | 1498 | |
40b18c0a MM |
1499 | /* If the type of the operand hasn't been determined (e.g., |
1500 | because it involves an overloaded function), then issue | |
1501 | an error message. There's no context available to | |
1502 | resolve the overloading. */ | |
74f0c611 | 1503 | if (TREE_TYPE (operand) == unknown_type_node) |
40b18c0a | 1504 | { |
c8094d83 | 1505 | error ("type of asm operand %qE could not be determined", |
0cbd7506 | 1506 | TREE_VALUE (t)); |
74f0c611 | 1507 | operand = error_mark_node; |
40b18c0a | 1508 | } |
40b18c0a | 1509 | |
0ab19cbc | 1510 | if (constraint_parsed) |
40b18c0a | 1511 | { |
74f0c611 RH |
1512 | /* If the operand is going to end up in memory, |
1513 | mark it addressable. */ | |
b4c33883 AP |
1514 | if (!allows_reg && allows_mem) |
1515 | { | |
1516 | /* Strip the nops as we allow this case. FIXME, this really | |
1517 | should be rejected or made deprecated. */ | |
1518 | STRIP_NOPS (operand); | |
1519 | if (!cxx_mark_addressable (operand)) | |
1520 | operand = error_mark_node; | |
1521 | } | |
6760071f JJ |
1522 | else if (!allows_reg && !allows_mem) |
1523 | { | |
1524 | /* If constraint allows neither register nor memory, | |
1525 | try harder to get a constant. */ | |
1526 | tree constop = maybe_constant_value (operand); | |
1527 | if (TREE_CONSTANT (constop)) | |
1528 | operand = constop; | |
1529 | } | |
40b18c0a | 1530 | } |
74f0c611 RH |
1531 | else |
1532 | operand = error_mark_node; | |
40b18c0a | 1533 | |
74f0c611 | 1534 | TREE_VALUE (t) = operand; |
40b18c0a MM |
1535 | } |
1536 | } | |
abfc8a36 | 1537 | |
c2255bc4 | 1538 | r = build_stmt (input_location, ASM_EXPR, string, |
0dfdeca6 | 1539 | output_operands, input_operands, |
1c384bf1 | 1540 | clobbers, labels); |
5544530a | 1541 | ASM_VOLATILE_P (r) = volatile_p || noutputs == 0; |
0ad28dde | 1542 | r = maybe_cleanup_point_expr_void (r); |
3e4d04a1 | 1543 | return add_stmt (r); |
ad321293 | 1544 | } |
b4c4a9ec | 1545 | |
5bca4e80 | 1546 | /* Finish a label with the indicated NAME. Returns the new label. */ |
f01b0acb | 1547 | |
a723baf1 | 1548 | tree |
3a978d72 | 1549 | finish_label_stmt (tree name) |
f01b0acb | 1550 | { |
5b030314 | 1551 | tree decl = define_label (input_location, name); |
417fa55b | 1552 | |
5bca4e80 | 1553 | if (decl == error_mark_node) |
417fa55b LM |
1554 | return error_mark_node; |
1555 | ||
c2255bc4 | 1556 | add_stmt (build_stmt (input_location, LABEL_EXPR, decl)); |
5bca4e80 ILT |
1557 | |
1558 | return decl; | |
f01b0acb MM |
1559 | } |
1560 | ||
acef433b MM |
1561 | /* Finish a series of declarations for local labels. G++ allows users |
1562 | to declare "local" labels, i.e., labels with scope. This extension | |
1563 | is useful when writing code involving statement-expressions. */ | |
1564 | ||
1565 | void | |
3a978d72 | 1566 | finish_label_decl (tree name) |
acef433b | 1567 | { |
a6d76a95 PC |
1568 | if (!at_function_scope_p ()) |
1569 | { | |
1570 | error ("__label__ declarations are only allowed in function scopes"); | |
1571 | return; | |
1572 | } | |
1573 | ||
1574 | add_decl_expr (declare_local_label (name)); | |
acef433b MM |
1575 | } |
1576 | ||
659e5a7a | 1577 | /* When DECL goes out of scope, make sure that CLEANUP is executed. */ |
f1dedc31 | 1578 | |
c8094d83 | 1579 | void |
3a978d72 | 1580 | finish_decl_cleanup (tree decl, tree cleanup) |
f1dedc31 | 1581 | { |
325c3691 | 1582 | push_cleanup (decl, cleanup, false); |
35b1567d BC |
1583 | } |
1584 | ||
659e5a7a | 1585 | /* If the current scope exits with an exception, run CLEANUP. */ |
24bef158 | 1586 | |
659e5a7a | 1587 | void |
3a978d72 | 1588 | finish_eh_cleanup (tree cleanup) |
24bef158 | 1589 | { |
325c3691 | 1590 | push_cleanup (NULL, cleanup, true); |
35b1567d BC |
1591 | } |
1592 | ||
2282d28d MM |
1593 | /* The MEM_INITS is a list of mem-initializers, in reverse of the |
1594 | order they were written by the user. Each node is as for | |
1595 | emit_mem_initializers. */ | |
bf3428d0 MM |
1596 | |
1597 | void | |
2282d28d | 1598 | finish_mem_initializers (tree mem_inits) |
bf3428d0 | 1599 | { |
2282d28d MM |
1600 | /* Reorder the MEM_INITS so that they are in the order they appeared |
1601 | in the source program. */ | |
1602 | mem_inits = nreverse (mem_inits); | |
bf3428d0 | 1603 | |
a0de9d20 | 1604 | if (processing_template_decl) |
5d80a306 DG |
1605 | { |
1606 | tree mem; | |
1607 | ||
1608 | for (mem = mem_inits; mem; mem = TREE_CHAIN (mem)) | |
1609 | { | |
1610 | /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the | |
1611 | check for bare parameter packs in the TREE_VALUE, because | |
1612 | any parameter packs in the TREE_VALUE have already been | |
1613 | bound as part of the TREE_PURPOSE. See | |
1614 | make_pack_expansion for more information. */ | |
4439d02f | 1615 | if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION |
7b3e2d46 | 1616 | && check_for_bare_parameter_packs (TREE_VALUE (mem))) |
4439d02f | 1617 | TREE_VALUE (mem) = error_mark_node; |
5d80a306 DG |
1618 | } |
1619 | ||
f330f599 PC |
1620 | add_stmt (build_min_nt_loc (UNKNOWN_LOCATION, |
1621 | CTOR_INITIALIZER, mem_inits)); | |
5d80a306 | 1622 | } |
cdd2559c | 1623 | else |
2282d28d | 1624 | emit_mem_initializers (mem_inits); |
558475f0 MM |
1625 | } |
1626 | ||
10c6dc8e JM |
1627 | /* Obfuscate EXPR if it looks like an id-expression or member access so |
1628 | that the call to finish_decltype in do_auto_deduction will give the | |
1629 | right result. */ | |
1630 | ||
1631 | tree | |
1632 | force_paren_expr (tree expr) | |
1633 | { | |
1634 | /* This is only needed for decltype(auto) in C++14. */ | |
e4276ba5 | 1635 | if (cxx_dialect < cxx14) |
10c6dc8e JM |
1636 | return expr; |
1637 | ||
0e4cf887 JM |
1638 | /* If we're in unevaluated context, we can't be deducing a |
1639 | return/initializer type, so we don't need to mess with this. */ | |
1640 | if (cp_unevaluated_operand) | |
1641 | return expr; | |
1642 | ||
10c6dc8e JM |
1643 | if (!DECL_P (expr) && TREE_CODE (expr) != COMPONENT_REF |
1644 | && TREE_CODE (expr) != SCOPE_REF) | |
1645 | return expr; | |
1646 | ||
0e4cf887 JM |
1647 | if (TREE_CODE (expr) == COMPONENT_REF) |
1648 | REF_PARENTHESIZED_P (expr) = true; | |
1649 | else if (type_dependent_expression_p (expr)) | |
10c6dc8e | 1650 | expr = build1 (PAREN_EXPR, TREE_TYPE (expr), expr); |
0d8ab59c JM |
1651 | else if (VAR_P (expr) && DECL_HARD_REGISTER (expr)) |
1652 | /* We can't bind a hard register variable to a reference. */; | |
10c6dc8e JM |
1653 | else |
1654 | { | |
1655 | cp_lvalue_kind kind = lvalue_kind (expr); | |
1656 | if ((kind & ~clk_class) != clk_none) | |
1657 | { | |
1658 | tree type = unlowered_expr_type (expr); | |
1659 | bool rval = !!(kind & clk_rvalueref); | |
1660 | type = cp_build_reference_type (type, rval); | |
6e4992ca PC |
1661 | /* This inhibits warnings in, eg, cxx_mark_addressable |
1662 | (c++/60955). */ | |
1663 | warning_sentinel s (extra_warnings); | |
0e4cf887 | 1664 | expr = build_static_cast (type, expr, tf_error); |
96e780c0 JM |
1665 | if (expr != error_mark_node) |
1666 | REF_PARENTHESIZED_P (expr) = true; | |
10c6dc8e JM |
1667 | } |
1668 | } | |
1669 | ||
1670 | return expr; | |
1671 | } | |
1672 | ||
b4c4a9ec MM |
1673 | /* Finish a parenthesized expression EXPR. */ |
1674 | ||
e87eed2a DM |
1675 | cp_expr |
1676 | finish_parenthesized_expr (cp_expr expr) | |
b4c4a9ec | 1677 | { |
6615c446 | 1678 | if (EXPR_P (expr)) |
78ef5b89 | 1679 | /* This inhibits warnings in c_common_truthvalue_conversion. */ |
31ec7d2f | 1680 | TREE_NO_WARNING (expr) = 1; |
b4c4a9ec | 1681 | |
d816a3ba JM |
1682 | if (TREE_CODE (expr) == OFFSET_REF |
1683 | || TREE_CODE (expr) == SCOPE_REF) | |
19420d00 NS |
1684 | /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be |
1685 | enclosed in parentheses. */ | |
1686 | PTRMEM_OK_P (expr) = 0; | |
c8094d83 | 1687 | |
7a8380ae NS |
1688 | if (TREE_CODE (expr) == STRING_CST) |
1689 | PAREN_STRING_LITERAL_P (expr) = 1; | |
c8094d83 | 1690 | |
e87eed2a | 1691 | expr = cp_expr (force_paren_expr (expr), expr.get_location ()); |
10c6dc8e | 1692 | |
b4c4a9ec MM |
1693 | return expr; |
1694 | } | |
1695 | ||
a723baf1 MM |
1696 | /* Finish a reference to a non-static data member (DECL) that is not |
1697 | preceded by `.' or `->'. */ | |
1698 | ||
1699 | tree | |
a3f10e50 | 1700 | finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) |
a723baf1 | 1701 | { |
50bc768d | 1702 | gcc_assert (TREE_CODE (decl) == FIELD_DECL); |
d9a6bd32 JJ |
1703 | bool try_omp_private = !object && omp_private_member_map; |
1704 | tree ret; | |
a723baf1 | 1705 | |
2defb926 | 1706 | if (!object) |
51fc2d02 | 1707 | { |
51fc2d02 JM |
1708 | tree scope = qualifying_scope; |
1709 | if (scope == NULL_TREE) | |
1710 | scope = context_for_name_lookup (decl); | |
1711 | object = maybe_dummy_object (scope, NULL); | |
1712 | } | |
1713 | ||
0b360a07 | 1714 | object = maybe_resolve_dummy (object, true); |
1496e7d6 PC |
1715 | if (object == error_mark_node) |
1716 | return error_mark_node; | |
1717 | ||
e2254932 | 1718 | /* DR 613/850: Can use non-static data members without an associated |
2defb926 JM |
1719 | object in sizeof/decltype/alignof. */ |
1720 | if (is_dummy_object (object) && cp_unevaluated_operand == 0 | |
1721 | && (!processing_template_decl || !current_class_ref)) | |
a723baf1 | 1722 | { |
c8094d83 | 1723 | if (current_function_decl |
a723baf1 | 1724 | && DECL_STATIC_FUNCTION_P (current_function_decl)) |
6863c41a | 1725 | error ("invalid use of member %qD in static member function", decl); |
a723baf1 | 1726 | else |
6863c41a JM |
1727 | error ("invalid use of non-static data member %qD", decl); |
1728 | inform (DECL_SOURCE_LOCATION (decl), "declared here"); | |
a723baf1 MM |
1729 | |
1730 | return error_mark_node; | |
1731 | } | |
d5f4eddd | 1732 | |
51fc2d02 JM |
1733 | if (current_class_ptr) |
1734 | TREE_USED (current_class_ptr) = 1; | |
58e1d54c | 1735 | if (processing_template_decl && !qualifying_scope) |
a723baf1 | 1736 | { |
a3f10e50 | 1737 | tree type = TREE_TYPE (decl); |
a723baf1 | 1738 | |
a3f10e50 | 1739 | if (TREE_CODE (type) == REFERENCE_TYPE) |
2516ccfe | 1740 | /* Quals on the object don't matter. */; |
2993d08a JM |
1741 | else if (PACK_EXPANSION_P (type)) |
1742 | /* Don't bother trying to represent this. */ | |
1743 | type = NULL_TREE; | |
a3f10e50 NS |
1744 | else |
1745 | { | |
f4f206f4 | 1746 | /* Set the cv qualifiers. */ |
bab5167f | 1747 | int quals = cp_type_quals (TREE_TYPE (object)); |
c8094d83 | 1748 | |
a3f10e50 NS |
1749 | if (DECL_MUTABLE_P (decl)) |
1750 | quals &= ~TYPE_QUAL_CONST; | |
9e95d15f | 1751 | |
a3f10e50 NS |
1752 | quals |= cp_type_quals (TREE_TYPE (decl)); |
1753 | type = cp_build_qualified_type (type, quals); | |
1754 | } | |
c8094d83 | 1755 | |
d9a6bd32 | 1756 | ret = (convert_from_reference |
2516ccfe | 1757 | (build_min (COMPONENT_REF, type, object, decl, NULL_TREE))); |
a3f10e50 | 1758 | } |
ab11c13f JM |
1759 | /* If PROCESSING_TEMPLATE_DECL is nonzero here, then |
1760 | QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF | |
1761 | for now. */ | |
1762 | else if (processing_template_decl) | |
d9a6bd32 JJ |
1763 | ret = build_qualified_name (TREE_TYPE (decl), |
1764 | qualifying_scope, | |
1765 | decl, | |
1766 | /*template_p=*/false); | |
a3f10e50 NS |
1767 | else |
1768 | { | |
1769 | tree access_type = TREE_TYPE (object); | |
9f01ded6 | 1770 | |
02022f3a | 1771 | perform_or_defer_access_check (TYPE_BINFO (access_type), decl, |
0e69fdf0 | 1772 | decl, tf_warning_or_error); |
a723baf1 MM |
1773 | |
1774 | /* If the data member was named `C::M', convert `*this' to `C' | |
1775 | first. */ | |
1776 | if (qualifying_scope) | |
1777 | { | |
1778 | tree binfo = NULL_TREE; | |
1779 | object = build_scoped_ref (object, qualifying_scope, | |
1780 | &binfo); | |
1781 | } | |
1782 | ||
d9a6bd32 JJ |
1783 | ret = build_class_member_access_expr (object, decl, |
1784 | /*access_path=*/NULL_TREE, | |
1785 | /*preserve_reference=*/false, | |
1786 | tf_warning_or_error); | |
1787 | } | |
1788 | if (try_omp_private) | |
1789 | { | |
1790 | tree *v = omp_private_member_map->get (decl); | |
1791 | if (v) | |
1792 | ret = convert_from_reference (*v); | |
a723baf1 | 1793 | } |
d9a6bd32 | 1794 | return ret; |
a723baf1 MM |
1795 | } |
1796 | ||
aa373032 DS |
1797 | /* If we are currently parsing a template and we encountered a typedef |
1798 | TYPEDEF_DECL that is being accessed though CONTEXT, this function | |
1799 | adds the typedef to a list tied to the current template. | |
b52259e1 | 1800 | At template instantiation time, that list is walked and access check |
aa373032 DS |
1801 | performed for each typedef. |
1802 | LOCATION is the location of the usage point of TYPEDEF_DECL. */ | |
1803 | ||
1804 | void | |
1805 | add_typedef_to_current_template_for_access_check (tree typedef_decl, | |
1806 | tree context, | |
1807 | location_t location) | |
1808 | { | |
1809 | tree template_info = NULL; | |
1810 | tree cs = current_scope (); | |
1811 | ||
1812 | if (!is_typedef_decl (typedef_decl) | |
1813 | || !context | |
1814 | || !CLASS_TYPE_P (context) | |
1815 | || !cs) | |
1816 | return; | |
1817 | ||
1818 | if (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL) | |
1819 | template_info = get_template_info (cs); | |
1820 | ||
1821 | if (template_info | |
1822 | && TI_TEMPLATE (template_info) | |
1823 | && !currently_open_class (context)) | |
1824 | append_type_to_template_for_access_check (cs, typedef_decl, | |
1825 | context, location); | |
1826 | } | |
1827 | ||
ee76b931 MM |
1828 | /* DECL was the declaration to which a qualified-id resolved. Issue |
1829 | an error message if it is not accessible. If OBJECT_TYPE is | |
1830 | non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the | |
1831 | type of `*x', or `x', respectively. If the DECL was named as | |
1832 | `A::B' then NESTED_NAME_SPECIFIER is `A'. */ | |
1833 | ||
1834 | void | |
c8094d83 MS |
1835 | check_accessibility_of_qualified_id (tree decl, |
1836 | tree object_type, | |
ee76b931 MM |
1837 | tree nested_name_specifier) |
1838 | { | |
1839 | tree scope; | |
1840 | tree qualifying_type = NULL_TREE; | |
95b4aca6 | 1841 | |
d0940d56 DS |
1842 | /* If we are parsing a template declaration and if decl is a typedef, |
1843 | add it to a list tied to the template. | |
1844 | At template instantiation time, that list will be walked and | |
1845 | access check performed. */ | |
aa373032 DS |
1846 | add_typedef_to_current_template_for_access_check (decl, |
1847 | nested_name_specifier | |
1848 | ? nested_name_specifier | |
1849 | : DECL_CONTEXT (decl), | |
1850 | input_location); | |
d0940d56 | 1851 | |
77880ae4 | 1852 | /* If we're not checking, return immediately. */ |
95b4aca6 NS |
1853 | if (deferred_access_no_check) |
1854 | return; | |
c8094d83 | 1855 | |
ee76b931 MM |
1856 | /* Determine the SCOPE of DECL. */ |
1857 | scope = context_for_name_lookup (decl); | |
1858 | /* If the SCOPE is not a type, then DECL is not a member. */ | |
1859 | if (!TYPE_P (scope)) | |
1860 | return; | |
1861 | /* Compute the scope through which DECL is being accessed. */ | |
c8094d83 | 1862 | if (object_type |
ee76b931 MM |
1863 | /* OBJECT_TYPE might not be a class type; consider: |
1864 | ||
1865 | class A { typedef int I; }; | |
1866 | I *p; | |
1867 | p->A::I::~I(); | |
1868 | ||
0cbd7506 | 1869 | In this case, we will have "A::I" as the DECL, but "I" as the |
ee76b931 MM |
1870 | OBJECT_TYPE. */ |
1871 | && CLASS_TYPE_P (object_type) | |
1872 | && DERIVED_FROM_P (scope, object_type)) | |
1873 | /* If we are processing a `->' or `.' expression, use the type of the | |
1874 | left-hand side. */ | |
1875 | qualifying_type = object_type; | |
1876 | else if (nested_name_specifier) | |
1877 | { | |
1878 | /* If the reference is to a non-static member of the | |
1879 | current class, treat it as if it were referenced through | |
1880 | `this'. */ | |
adb50dfb | 1881 | tree ct; |
ee76b931 MM |
1882 | if (DECL_NONSTATIC_MEMBER_P (decl) |
1883 | && current_class_ptr | |
adb50dfb VV |
1884 | && DERIVED_FROM_P (scope, ct = current_nonlambda_class_type ())) |
1885 | qualifying_type = ct; | |
ee76b931 MM |
1886 | /* Otherwise, use the type indicated by the |
1887 | nested-name-specifier. */ | |
1888 | else | |
1889 | qualifying_type = nested_name_specifier; | |
1890 | } | |
1891 | else | |
1892 | /* Otherwise, the name must be from the current class or one of | |
1893 | its bases. */ | |
1894 | qualifying_type = currently_open_derived_class (scope); | |
1895 | ||
fc429748 MM |
1896 | if (qualifying_type |
1897 | /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM | |
1898 | or similar in a default argument value. */ | |
1899 | && CLASS_TYPE_P (qualifying_type) | |
1900 | && !dependent_type_p (qualifying_type)) | |
02022f3a | 1901 | perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl, |
0e69fdf0 | 1902 | decl, tf_warning_or_error); |
ee76b931 MM |
1903 | } |
1904 | ||
1905 | /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the | |
1906 | class named to the left of the "::" operator. DONE is true if this | |
1907 | expression is a complete postfix-expression; it is false if this | |
1908 | expression is followed by '->', '[', '(', etc. ADDRESS_P is true | |
02ed62dd MM |
1909 | iff this expression is the operand of '&'. TEMPLATE_P is true iff |
1910 | the qualified-id was of the form "A::template B". TEMPLATE_ARG_P | |
1911 | is true iff this qualified name appears as a template argument. */ | |
ee76b931 MM |
1912 | |
1913 | tree | |
3db45ab5 MS |
1914 | finish_qualified_id_expr (tree qualifying_class, |
1915 | tree expr, | |
02ed62dd | 1916 | bool done, |
3db45ab5 | 1917 | bool address_p, |
02ed62dd | 1918 | bool template_p, |
a378996b PC |
1919 | bool template_arg_p, |
1920 | tsubst_flags_t complain) | |
ee76b931 | 1921 | { |
d4f0f205 MM |
1922 | gcc_assert (TYPE_P (qualifying_class)); |
1923 | ||
5e08432e MM |
1924 | if (error_operand_p (expr)) |
1925 | return error_mark_node; | |
1926 | ||
2e649151 PC |
1927 | if ((DECL_P (expr) || BASELINK_P (expr)) |
1928 | && !mark_used (expr, complain)) | |
1929 | return error_mark_node; | |
d4f0f205 | 1930 | |
02ed62dd MM |
1931 | if (template_p) |
1932 | check_template_keyword (expr); | |
1933 | ||
ee76b931 MM |
1934 | /* If EXPR occurs as the operand of '&', use special handling that |
1935 | permits a pointer-to-member. */ | |
1936 | if (address_p && done) | |
1937 | { | |
1938 | if (TREE_CODE (expr) == SCOPE_REF) | |
1939 | expr = TREE_OPERAND (expr, 1); | |
c8094d83 | 1940 | expr = build_offset_ref (qualifying_class, expr, |
a378996b | 1941 | /*address_p=*/true, complain); |
ee76b931 MM |
1942 | return expr; |
1943 | } | |
1944 | ||
d348f172 JM |
1945 | /* No need to check access within an enum. */ |
1946 | if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE) | |
1947 | return expr; | |
1948 | ||
02ed62dd MM |
1949 | /* Within the scope of a class, turn references to non-static |
1950 | members into expression of the form "this->...". */ | |
1951 | if (template_arg_p) | |
1952 | /* But, within a template argument, we do not want make the | |
1953 | transformation, as there is no "this" pointer. */ | |
1954 | ; | |
1955 | else if (TREE_CODE (expr) == FIELD_DECL) | |
43854f72 SB |
1956 | { |
1957 | push_deferring_access_checks (dk_no_check); | |
2defb926 | 1958 | expr = finish_non_static_data_member (expr, NULL_TREE, |
43854f72 SB |
1959 | qualifying_class); |
1960 | pop_deferring_access_checks (); | |
1961 | } | |
ee76b931 MM |
1962 | else if (BASELINK_P (expr) && !processing_template_decl) |
1963 | { | |
ee76b931 | 1964 | /* See if any of the functions are non-static members. */ |
7e361ae6 | 1965 | /* If so, the expression may be relative to 'this'. */ |
294e855f | 1966 | if (!shared_member_p (expr) |
0ef811d7 JM |
1967 | && current_class_ptr |
1968 | && DERIVED_FROM_P (qualifying_class, | |
1969 | current_nonlambda_class_type ())) | |
c8094d83 | 1970 | expr = (build_class_member_access_expr |
0ef811d7 | 1971 | (maybe_dummy_object (qualifying_class, NULL), |
ee76b931 MM |
1972 | expr, |
1973 | BASELINK_ACCESS_BINFO (expr), | |
5ade1ed2 | 1974 | /*preserve_reference=*/false, |
a378996b | 1975 | complain)); |
ee76b931 | 1976 | else if (done) |
a5ac359a MM |
1977 | /* The expression is a qualified name whose address is not |
1978 | being taken. */ | |
a378996b PC |
1979 | expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false, |
1980 | complain); | |
ee76b931 | 1981 | } |
e467c9d2 JM |
1982 | else if (BASELINK_P (expr)) |
1983 | ; | |
1984 | else | |
1985 | { | |
e467c9d2 JM |
1986 | /* In a template, return a SCOPE_REF for most qualified-ids |
1987 | so that we can check access at instantiation time. But if | |
1988 | we're looking at a member of the current instantiation, we | |
1989 | know we have access and building up the SCOPE_REF confuses | |
1990 | non-type template argument handling. */ | |
1991 | if (processing_template_decl | |
1992 | && !currently_open_class (qualifying_class)) | |
1993 | expr = build_qualified_name (TREE_TYPE (expr), | |
1994 | qualifying_class, expr, | |
1995 | template_p); | |
1e8671f7 JM |
1996 | |
1997 | expr = convert_from_reference (expr); | |
e467c9d2 | 1998 | } |
ee76b931 MM |
1999 | |
2000 | return expr; | |
2001 | } | |
2002 | ||
b69b1501 MM |
2003 | /* Begin a statement-expression. The value returned must be passed to |
2004 | finish_stmt_expr. */ | |
b4c4a9ec | 2005 | |
c8094d83 | 2006 | tree |
3a978d72 | 2007 | begin_stmt_expr (void) |
b4c4a9ec | 2008 | { |
325c3691 | 2009 | return push_stmt_list (); |
35b1567d BC |
2010 | } |
2011 | ||
a5bcc582 | 2012 | /* Process the final expression of a statement expression. EXPR can be |
85a56c9d MM |
2013 | NULL, if the final expression is empty. Return a STATEMENT_LIST |
2014 | containing all the statements in the statement-expression, or | |
2015 | ERROR_MARK_NODE if there was an error. */ | |
a5bcc582 NS |
2016 | |
2017 | tree | |
325c3691 | 2018 | finish_stmt_expr_expr (tree expr, tree stmt_expr) |
a5bcc582 | 2019 | { |
72e4661a | 2020 | if (error_operand_p (expr)) |
76b9a2a1 AP |
2021 | { |
2022 | /* The type of the statement-expression is the type of the last | |
2023 | expression. */ | |
2024 | TREE_TYPE (stmt_expr) = error_mark_node; | |
2025 | return error_mark_node; | |
2026 | } | |
c8094d83 | 2027 | |
85a56c9d | 2028 | /* If the last statement does not have "void" type, then the value |
3db45ab5 | 2029 | of the last statement is the value of the entire expression. */ |
a5bcc582 NS |
2030 | if (expr) |
2031 | { | |
c6c7698d JM |
2032 | tree type = TREE_TYPE (expr); |
2033 | ||
2034 | if (processing_template_decl) | |
2035 | { | |
c2255bc4 | 2036 | expr = build_stmt (input_location, EXPR_STMT, expr); |
c6c7698d JM |
2037 | expr = add_stmt (expr); |
2038 | /* Mark the last statement so that we can recognize it as such at | |
2039 | template-instantiation time. */ | |
2040 | EXPR_STMT_STMT_EXPR_RESULT (expr) = 1; | |
2041 | } | |
2042 | else if (VOID_TYPE_P (type)) | |
a5bcc582 | 2043 | { |
c6c7698d JM |
2044 | /* Just treat this like an ordinary statement. */ |
2045 | expr = finish_expr_stmt (expr); | |
2046 | } | |
2047 | else | |
2048 | { | |
2049 | /* It actually has a value we need to deal with. First, force it | |
2050 | to be an rvalue so that we won't need to build up a copy | |
2051 | constructor call later when we try to assign it to something. */ | |
574cfaa4 | 2052 | expr = force_rvalue (expr, tf_warning_or_error); |
85a56c9d MM |
2053 | if (error_operand_p (expr)) |
2054 | return error_mark_node; | |
c6c7698d JM |
2055 | |
2056 | /* Update for array-to-pointer decay. */ | |
2692eb7d | 2057 | type = TREE_TYPE (expr); |
c6c7698d JM |
2058 | |
2059 | /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a | |
2060 | normal statement, but don't convert to void or actually add | |
2061 | the EXPR_STMT. */ | |
2062 | if (TREE_CODE (expr) != CLEANUP_POINT_EXPR) | |
2063 | expr = maybe_cleanup_point_expr (expr); | |
2064 | add_stmt (expr); | |
85a56c9d | 2065 | } |
c6c7698d | 2066 | |
85a56c9d MM |
2067 | /* The type of the statement-expression is the type of the last |
2068 | expression. */ | |
2069 | TREE_TYPE (stmt_expr) = type; | |
a5bcc582 | 2070 | } |
c8094d83 | 2071 | |
85a56c9d | 2072 | return stmt_expr; |
a5bcc582 NS |
2073 | } |
2074 | ||
303b7406 NS |
2075 | /* Finish a statement-expression. EXPR should be the value returned |
2076 | by the previous begin_stmt_expr. Returns an expression | |
2077 | representing the statement-expression. */ | |
b4c4a9ec | 2078 | |
c8094d83 | 2079 | tree |
325c3691 | 2080 | finish_stmt_expr (tree stmt_expr, bool has_no_scope) |
b4c4a9ec | 2081 | { |
85a56c9d MM |
2082 | tree type; |
2083 | tree result; | |
325c3691 | 2084 | |
85a56c9d | 2085 | if (error_operand_p (stmt_expr)) |
d7b5fa31 JJ |
2086 | { |
2087 | pop_stmt_list (stmt_expr); | |
2088 | return error_mark_node; | |
2089 | } | |
325c3691 | 2090 | |
85a56c9d | 2091 | gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST); |
325c3691 | 2092 | |
85a56c9d MM |
2093 | type = TREE_TYPE (stmt_expr); |
2094 | result = pop_stmt_list (stmt_expr); | |
c6c7698d | 2095 | TREE_TYPE (result) = type; |
6f80451c | 2096 | |
a5bcc582 | 2097 | if (processing_template_decl) |
325c3691 RH |
2098 | { |
2099 | result = build_min (STMT_EXPR, type, result); | |
2100 | TREE_SIDE_EFFECTS (result) = 1; | |
2101 | STMT_EXPR_NO_SCOPE (result) = has_no_scope; | |
2102 | } | |
c6c7698d | 2103 | else if (CLASS_TYPE_P (type)) |
a5bcc582 | 2104 | { |
c6c7698d JM |
2105 | /* Wrap the statement-expression in a TARGET_EXPR so that the |
2106 | temporary object created by the final expression is destroyed at | |
2107 | the end of the full-expression containing the | |
2108 | statement-expression. */ | |
574cfaa4 | 2109 | result = force_target_expr (type, result, tf_warning_or_error); |
a5bcc582 | 2110 | } |
325c3691 | 2111 | |
b4c4a9ec MM |
2112 | return result; |
2113 | } | |
2114 | ||
c2acde1e JM |
2115 | /* Returns the expression which provides the value of STMT_EXPR. */ |
2116 | ||
2117 | tree | |
2118 | stmt_expr_value_expr (tree stmt_expr) | |
2119 | { | |
2120 | tree t = STMT_EXPR_STMT (stmt_expr); | |
2121 | ||
2122 | if (TREE_CODE (t) == BIND_EXPR) | |
2123 | t = BIND_EXPR_BODY (t); | |
2124 | ||
9de0e916 | 2125 | if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t)) |
c2acde1e JM |
2126 | t = STATEMENT_LIST_TAIL (t)->stmt; |
2127 | ||
2128 | if (TREE_CODE (t) == EXPR_STMT) | |
2129 | t = EXPR_STMT_EXPR (t); | |
2130 | ||
2131 | return t; | |
2132 | } | |
2133 | ||
9af66ed1 DS |
2134 | /* Return TRUE iff EXPR_STMT is an empty list of |
2135 | expression statements. */ | |
2136 | ||
2137 | bool | |
2138 | empty_expr_stmt_p (tree expr_stmt) | |
2139 | { | |
2140 | tree body = NULL_TREE; | |
2141 | ||
632f2871 | 2142 | if (expr_stmt == void_node) |
489df541 DS |
2143 | return true; |
2144 | ||
9af66ed1 DS |
2145 | if (expr_stmt) |
2146 | { | |
2147 | if (TREE_CODE (expr_stmt) == EXPR_STMT) | |
2148 | body = EXPR_STMT_EXPR (expr_stmt); | |
2149 | else if (TREE_CODE (expr_stmt) == STATEMENT_LIST) | |
2150 | body = expr_stmt; | |
2151 | } | |
2152 | ||
489df541 DS |
2153 | if (body) |
2154 | { | |
2155 | if (TREE_CODE (body) == STATEMENT_LIST) | |
2156 | return tsi_end_p (tsi_start (body)); | |
2157 | else | |
2158 | return empty_expr_stmt_p (body); | |
2159 | } | |
9af66ed1 DS |
2160 | return false; |
2161 | } | |
2162 | ||
b3445994 | 2163 | /* Perform Koenig lookup. FN is the postfix-expression representing |
fa531100 | 2164 | the function (or functions) to call; ARGS are the arguments to the |
cdc23b1b | 2165 | call. Returns the functions to be considered by overload resolution. */ |
b3445994 | 2166 | |
e87eed2a DM |
2167 | cp_expr |
2168 | perform_koenig_lookup (cp_expr fn, vec<tree, va_gc> *args, | |
94df301f | 2169 | tsubst_flags_t complain) |
b3445994 MM |
2170 | { |
2171 | tree identifier = NULL_TREE; | |
2172 | tree functions = NULL_TREE; | |
d095e03c | 2173 | tree tmpl_args = NULL_TREE; |
4e6a9725 | 2174 | bool template_id = false; |
d095e03c JM |
2175 | |
2176 | if (TREE_CODE (fn) == TEMPLATE_ID_EXPR) | |
2177 | { | |
4e6a9725 JM |
2178 | /* Use a separate flag to handle null args. */ |
2179 | template_id = true; | |
d095e03c JM |
2180 | tmpl_args = TREE_OPERAND (fn, 1); |
2181 | fn = TREE_OPERAND (fn, 0); | |
2182 | } | |
b3445994 MM |
2183 | |
2184 | /* Find the name of the overloaded function. */ | |
9dc6f476 | 2185 | if (identifier_p (fn)) |
b3445994 MM |
2186 | identifier = fn; |
2187 | else if (is_overloaded_fn (fn)) | |
2188 | { | |
2189 | functions = fn; | |
2190 | identifier = DECL_NAME (get_first_fn (functions)); | |
2191 | } | |
2192 | else if (DECL_P (fn)) | |
2193 | { | |
2194 | functions = fn; | |
2195 | identifier = DECL_NAME (fn); | |
2196 | } | |
2197 | ||
2198 | /* A call to a namespace-scope function using an unqualified name. | |
2199 | ||
2200 | Do Koenig lookup -- unless any of the arguments are | |
2201 | type-dependent. */ | |
d095e03c JM |
2202 | if (!any_type_dependent_arguments_p (args) |
2203 | && !any_dependent_template_arguments_p (tmpl_args)) | |
b3445994 | 2204 | { |
cdc23b1b | 2205 | fn = lookup_arg_dependent (identifier, functions, args); |
b3445994 | 2206 | if (!fn) |
94df301f JM |
2207 | { |
2208 | /* The unqualified name could not be resolved. */ | |
2209 | if (complain) | |
2210 | fn = unqualified_fn_lookup_error (identifier); | |
2211 | else | |
2212 | fn = identifier; | |
2213 | } | |
b3445994 | 2214 | } |
b3445994 | 2215 | |
4e6a9725 JM |
2216 | if (fn && template_id) |
2217 | fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args); | |
d095e03c | 2218 | |
b3445994 MM |
2219 | return fn; |
2220 | } | |
2221 | ||
c166b898 ILT |
2222 | /* Generate an expression for `FN (ARGS)'. This may change the |
2223 | contents of ARGS. | |
4ba126e4 MM |
2224 | |
2225 | If DISALLOW_VIRTUAL is true, the call to FN will be not generated | |
2226 | as a virtual call, even if FN is virtual. (This flag is set when | |
2227 | encountering an expression where the function name is explicitly | |
2228 | qualified. For example a call to `X::f' never generates a virtual | |
2229 | call.) | |
2230 | ||
2231 | Returns code for the call. */ | |
b4c4a9ec | 2232 | |
c8094d83 | 2233 | tree |
9771b263 | 2234 | finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual, |
c166b898 | 2235 | bool koenig_p, tsubst_flags_t complain) |
b4c4a9ec | 2236 | { |
d17811fd MM |
2237 | tree result; |
2238 | tree orig_fn; | |
9771b263 | 2239 | vec<tree, va_gc> *orig_args = NULL; |
d17811fd | 2240 | |
c166b898 | 2241 | if (fn == error_mark_node) |
4ba126e4 MM |
2242 | return error_mark_node; |
2243 | ||
4860b874 | 2244 | gcc_assert (!TYPE_P (fn)); |
a759e627 | 2245 | |
d17811fd | 2246 | orig_fn = fn; |
d17811fd MM |
2247 | |
2248 | if (processing_template_decl) | |
2249 | { | |
1770aeed DS |
2250 | /* If the call expression is dependent, build a CALL_EXPR node |
2251 | with no type; type_dependent_expression_p recognizes | |
2252 | expressions with no type as being dependent. */ | |
d17811fd | 2253 | if (type_dependent_expression_p (fn) |
1770aeed | 2254 | || any_type_dependent_arguments_p (*args) |
712c948a JM |
2255 | /* For a non-static member function that doesn't have an |
2256 | explicit object argument, we need to specifically | |
1770aeed DS |
2257 | test the type dependency of the "this" pointer because it |
2258 | is not included in *ARGS even though it is considered to | |
2259 | be part of the list of arguments. Note that this is | |
2260 | related to CWG issues 515 and 1005. */ | |
712c948a JM |
2261 | || (TREE_CODE (fn) != COMPONENT_REF |
2262 | && non_static_member_function_p (fn) | |
1770aeed DS |
2263 | && current_class_ref |
2264 | && type_dependent_expression_p (current_class_ref))) | |
6d80c4b9 | 2265 | { |
c166b898 | 2266 | result = build_nt_call_vec (fn, *args); |
8400e75e | 2267 | SET_EXPR_LOCATION (result, EXPR_LOC_OR_LOC (fn, input_location)); |
5094a795 | 2268 | KOENIG_LOOKUP_P (result) = koenig_p; |
be461b8f JJ |
2269 | if (cfun) |
2270 | { | |
2271 | do | |
2272 | { | |
2273 | tree fndecl = OVL_CURRENT (fn); | |
2274 | if (TREE_CODE (fndecl) != FUNCTION_DECL | |
2275 | || !TREE_THIS_VOLATILE (fndecl)) | |
2276 | break; | |
2277 | fn = OVL_NEXT (fn); | |
2278 | } | |
2279 | while (fn); | |
2280 | if (!fn) | |
2281 | current_function_returns_abnormally = 1; | |
2282 | } | |
6d80c4b9 MM |
2283 | return result; |
2284 | } | |
c166b898 | 2285 | orig_args = make_tree_vector_copy (*args); |
d17811fd MM |
2286 | if (!BASELINK_P (fn) |
2287 | && TREE_CODE (fn) != PSEUDO_DTOR_EXPR | |
2288 | && TREE_TYPE (fn) != unknown_type_node) | |
2289 | fn = build_non_dependent_expr (fn); | |
c166b898 | 2290 | make_args_non_dependent (*args); |
d17811fd MM |
2291 | } |
2292 | ||
deb9642d JM |
2293 | if (TREE_CODE (fn) == COMPONENT_REF) |
2294 | { | |
2295 | tree member = TREE_OPERAND (fn, 1); | |
2296 | if (BASELINK_P (member)) | |
2297 | { | |
2298 | tree object = TREE_OPERAND (fn, 0); | |
2299 | return build_new_method_call (object, member, | |
2300 | args, NULL_TREE, | |
2301 | (disallow_virtual | |
2302 | ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | |
2303 | : LOOKUP_NORMAL), | |
2304 | /*fn_p=*/NULL, | |
2305 | complain); | |
2306 | } | |
2307 | } | |
2308 | ||
53677b17 PC |
2309 | /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */ |
2310 | if (TREE_CODE (fn) == ADDR_EXPR | |
2311 | && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD) | |
2312 | fn = TREE_OPERAND (fn, 0); | |
2313 | ||
eff3a276 MM |
2314 | if (is_overloaded_fn (fn)) |
2315 | fn = baselink_for_fns (fn); | |
a723baf1 | 2316 | |
d17811fd | 2317 | result = NULL_TREE; |
4ba126e4 | 2318 | if (BASELINK_P (fn)) |
03d82991 | 2319 | { |
4ba126e4 MM |
2320 | tree object; |
2321 | ||
2322 | /* A call to a member function. From [over.call.func]: | |
2323 | ||
2324 | If the keyword this is in scope and refers to the class of | |
2325 | that member function, or a derived class thereof, then the | |
2326 | function call is transformed into a qualified function call | |
2327 | using (*this) as the postfix-expression to the left of the | |
2328 | . operator.... [Otherwise] a contrived object of type T | |
c8094d83 | 2329 | becomes the implied object argument. |
4ba126e4 | 2330 | |
38f1276b | 2331 | In this situation: |
4ba126e4 MM |
2332 | |
2333 | struct A { void f(); }; | |
2334 | struct B : public A {}; | |
2335 | struct C : public A { void g() { B::f(); }}; | |
2336 | ||
38f1276b JM |
2337 | "the class of that member function" refers to `A'. But 11.2 |
2338 | [class.access.base] says that we need to convert 'this' to B* as | |
2339 | part of the access, so we pass 'B' to maybe_dummy_object. */ | |
b4c4a9ec | 2340 | |
38f1276b JM |
2341 | object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)), |
2342 | NULL); | |
b4c4a9ec | 2343 | |
d17811fd MM |
2344 | if (processing_template_decl) |
2345 | { | |
2346 | if (type_dependent_expression_p (object)) | |
c166b898 ILT |
2347 | { |
2348 | tree ret = build_nt_call_vec (orig_fn, orig_args); | |
2349 | release_tree_vector (orig_args); | |
2350 | return ret; | |
2351 | } | |
d17811fd MM |
2352 | object = build_non_dependent_expr (object); |
2353 | } | |
2354 | ||
2355 | result = build_new_method_call (object, fn, args, NULL_TREE, | |
c8094d83 | 2356 | (disallow_virtual |
c2aa8dc9 JM |
2357 | ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL |
2358 | : LOOKUP_NORMAL), | |
5ade1ed2 DG |
2359 | /*fn_p=*/NULL, |
2360 | complain); | |
4ba126e4 MM |
2361 | } |
2362 | else if (is_overloaded_fn (fn)) | |
16c35a1f RH |
2363 | { |
2364 | /* If the function is an overloaded builtin, resolve it. */ | |
2365 | if (TREE_CODE (fn) == FUNCTION_DECL | |
58646b77 PB |
2366 | && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL |
2367 | || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD)) | |
c2255bc4 | 2368 | result = resolve_overloaded_builtin (input_location, fn, *args); |
16c35a1f RH |
2369 | |
2370 | if (!result) | |
0d23cf7a JJ |
2371 | { |
2372 | if (warn_sizeof_pointer_memaccess | |
32ad49af | 2373 | && (complain & tf_warning) |
9771b263 | 2374 | && !vec_safe_is_empty (*args) |
0d23cf7a JJ |
2375 | && !processing_template_decl) |
2376 | { | |
3a785c97 JJ |
2377 | location_t sizeof_arg_loc[3]; |
2378 | tree sizeof_arg[3]; | |
2379 | unsigned int i; | |
2380 | for (i = 0; i < 3; i++) | |
2381 | { | |
2382 | tree t; | |
2383 | ||
2384 | sizeof_arg_loc[i] = UNKNOWN_LOCATION; | |
2385 | sizeof_arg[i] = NULL_TREE; | |
9771b263 | 2386 | if (i >= (*args)->length ()) |
3a785c97 | 2387 | continue; |
9771b263 | 2388 | t = (**args)[i]; |
3a785c97 JJ |
2389 | if (TREE_CODE (t) != SIZEOF_EXPR) |
2390 | continue; | |
2391 | if (SIZEOF_EXPR_TYPE_P (t)) | |
2392 | sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0)); | |
2393 | else | |
2394 | sizeof_arg[i] = TREE_OPERAND (t, 0); | |
2395 | sizeof_arg_loc[i] = EXPR_LOCATION (t); | |
2396 | } | |
0d23cf7a | 2397 | sizeof_pointer_memaccess_warning |
3a785c97 | 2398 | (sizeof_arg_loc, fn, *args, |
0d23cf7a JJ |
2399 | sizeof_arg, same_type_ignoring_top_level_qualifiers_p); |
2400 | } | |
2401 | ||
2402 | /* A call to a namespace-scope function. */ | |
2403 | result = build_new_function_call (fn, args, koenig_p, complain); | |
2404 | } | |
16c35a1f | 2405 | } |
a723baf1 MM |
2406 | else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR) |
2407 | { | |
9771b263 | 2408 | if (!vec_safe_is_empty (*args)) |
a723baf1 MM |
2409 | error ("arguments to destructor are not allowed"); |
2410 | /* Mark the pseudo-destructor call as having side-effects so | |
2411 | that we do not issue warnings about its use. */ | |
2412 | result = build1 (NOP_EXPR, | |
2413 | void_type_node, | |
2414 | TREE_OPERAND (fn, 0)); | |
2415 | TREE_SIDE_EFFECTS (result) = 1; | |
a723baf1 | 2416 | } |
4ba126e4 | 2417 | else if (CLASS_TYPE_P (TREE_TYPE (fn))) |
d17811fd MM |
2418 | /* If the "function" is really an object of class type, it might |
2419 | have an overloaded `operator ()'. */ | |
c166b898 | 2420 | result = build_op_call (fn, args, complain); |
16c35a1f | 2421 | |
d17811fd MM |
2422 | if (!result) |
2423 | /* A call where the function is unknown. */ | |
c166b898 | 2424 | result = cp_build_function_call_vec (fn, args, complain); |
4ba126e4 | 2425 | |
bb4586d3 | 2426 | if (processing_template_decl && result != error_mark_node) |
6d80c4b9 | 2427 | { |
591cb3cf | 2428 | if (INDIRECT_REF_P (result)) |
bb4586d3 | 2429 | result = TREE_OPERAND (result, 0); |
c166b898 | 2430 | result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args); |
6e04dcd5 | 2431 | SET_EXPR_LOCATION (result, input_location); |
5094a795 | 2432 | KOENIG_LOOKUP_P (result) = koenig_p; |
c166b898 | 2433 | release_tree_vector (orig_args); |
bb4586d3 | 2434 | result = convert_from_reference (result); |
6d80c4b9 | 2435 | } |
c166b898 | 2436 | |
3a2cb4d0 JM |
2437 | if (koenig_p) |
2438 | { | |
2439 | /* Free garbage OVERLOADs from arg-dependent lookup. */ | |
2440 | tree next = NULL_TREE; | |
2441 | for (fn = orig_fn; | |
2442 | fn && TREE_CODE (fn) == OVERLOAD && OVL_ARG_DEPENDENT (fn); | |
2443 | fn = next) | |
2444 | { | |
2445 | if (processing_template_decl) | |
2446 | /* In a template, we'll re-use them at instantiation time. */ | |
2447 | OVL_ARG_DEPENDENT (fn) = false; | |
2448 | else | |
2449 | { | |
2450 | next = OVL_CHAIN (fn); | |
2451 | ggc_free (fn); | |
2452 | } | |
2453 | } | |
2454 | } | |
2455 | ||
d17811fd | 2456 | return result; |
b4c4a9ec MM |
2457 | } |
2458 | ||
2459 | /* Finish a call to a postfix increment or decrement or EXPR. (Which | |
2460 | is indicated by CODE, which should be POSTINCREMENT_EXPR or | |
2461 | POSTDECREMENT_EXPR.) */ | |
2462 | ||
e87eed2a DM |
2463 | cp_expr |
2464 | finish_increment_expr (cp_expr expr, enum tree_code code) | |
2465 | { | |
2466 | /* input_location holds the location of the trailing operator token. | |
2467 | Build a location of the form: | |
2468 | expr++ | |
2469 | ~~~~^~ | |
2470 | with the caret at the operator token, ranging from the start | |
2471 | of EXPR to the end of the operator token. */ | |
2472 | location_t combined_loc = make_location (input_location, | |
2473 | expr.get_start (), | |
2474 | get_finish (input_location)); | |
2475 | cp_expr result = build_x_unary_op (combined_loc, code, expr, | |
2476 | tf_warning_or_error); | |
2477 | /* TODO: build_x_unary_op doesn't honor the location, so set it here. */ | |
2478 | result.set_location (combined_loc); | |
2479 | return result; | |
b4c4a9ec MM |
2480 | } |
2481 | ||
2482 | /* Finish a use of `this'. Returns an expression for `this'. */ | |
2483 | ||
c8094d83 | 2484 | tree |
3a978d72 | 2485 | finish_this_expr (void) |
b4c4a9ec | 2486 | { |
2bf492a1 | 2487 | tree result = NULL_TREE; |
b4c4a9ec | 2488 | |
c6be04ad JM |
2489 | if (current_class_ptr) |
2490 | { | |
2491 | tree type = TREE_TYPE (current_class_ref); | |
2492 | ||
2493 | /* In a lambda expression, 'this' refers to the captured 'this'. */ | |
2494 | if (LAMBDA_TYPE_P (type)) | |
0b360a07 | 2495 | result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type), true); |
c6be04ad JM |
2496 | else |
2497 | result = current_class_ptr; | |
c6be04ad | 2498 | } |
b4c4a9ec | 2499 | |
2bf492a1 JM |
2500 | if (result) |
2501 | /* The keyword 'this' is a prvalue expression. */ | |
2502 | return rvalue (result); | |
374b2837 | 2503 | |
2bf492a1 JM |
2504 | tree fn = current_nonlambda_function (); |
2505 | if (fn && DECL_STATIC_FUNCTION_P (fn)) | |
2506 | error ("%<this%> is unavailable for static member functions"); | |
2507 | else if (fn) | |
2508 | error ("invalid use of %<this%> in non-member function"); | |
2509 | else | |
2510 | error ("invalid use of %<this%> at top level"); | |
2511 | return error_mark_node; | |
b4c4a9ec MM |
2512 | } |
2513 | ||
a723baf1 MM |
2514 | /* Finish a pseudo-destructor expression. If SCOPE is NULL, the |
2515 | expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is | |
2516 | the TYPE for the type given. If SCOPE is non-NULL, the expression | |
2517 | was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */ | |
b4c4a9ec | 2518 | |
c8094d83 | 2519 | tree |
2dc6ed87 PC |
2520 | finish_pseudo_destructor_expr (tree object, tree scope, tree destructor, |
2521 | location_t loc) | |
b4c4a9ec | 2522 | { |
09b1ccd6 | 2523 | if (object == error_mark_node || destructor == error_mark_node) |
a723baf1 | 2524 | return error_mark_node; |
40242ccf | 2525 | |
50bc768d | 2526 | gcc_assert (TYPE_P (destructor)); |
b4c4a9ec | 2527 | |
a723baf1 MM |
2528 | if (!processing_template_decl) |
2529 | { | |
2530 | if (scope == error_mark_node) | |
2531 | { | |
2dc6ed87 | 2532 | error_at (loc, "invalid qualifying scope in pseudo-destructor name"); |
a723baf1 MM |
2533 | return error_mark_node; |
2534 | } | |
3df70c62 JM |
2535 | if (is_auto (destructor)) |
2536 | destructor = TREE_TYPE (object); | |
5cf10afb AP |
2537 | if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor)) |
2538 | { | |
2dc6ed87 PC |
2539 | error_at (loc, |
2540 | "qualified type %qT does not match destructor name ~%qT", | |
2541 | scope, destructor); | |
5cf10afb AP |
2542 | return error_mark_node; |
2543 | } | |
2544 | ||
c8094d83 | 2545 | |
26bcf8fc MM |
2546 | /* [expr.pseudo] says both: |
2547 | ||
0cbd7506 | 2548 | The type designated by the pseudo-destructor-name shall be |
26bcf8fc MM |
2549 | the same as the object type. |
2550 | ||
0cbd7506 | 2551 | and: |
26bcf8fc | 2552 | |
0cbd7506 | 2553 | The cv-unqualified versions of the object type and of the |
26bcf8fc MM |
2554 | type designated by the pseudo-destructor-name shall be the |
2555 | same type. | |
2556 | ||
0cbd7506 MS |
2557 | We implement the more generous second sentence, since that is |
2558 | what most other compilers do. */ | |
c8094d83 | 2559 | if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object), |
26bcf8fc | 2560 | destructor)) |
a723baf1 | 2561 | { |
2dc6ed87 | 2562 | error_at (loc, "%qE is not of type %qT", object, destructor); |
a723baf1 MM |
2563 | return error_mark_node; |
2564 | } | |
2565 | } | |
b4c4a9ec | 2566 | |
2dc6ed87 PC |
2567 | return build3_loc (loc, PSEUDO_DTOR_EXPR, void_type_node, object, |
2568 | scope, destructor); | |
b4c4a9ec MM |
2569 | } |
2570 | ||
ce4a0391 MM |
2571 | /* Finish an expression of the form CODE EXPR. */ |
2572 | ||
e87eed2a DM |
2573 | cp_expr |
2574 | finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr, | |
e59baf05 | 2575 | tsubst_flags_t complain) |
ce4a0391 | 2576 | { |
e87eed2a DM |
2577 | /* Build a location of the form: |
2578 | ++expr | |
2579 | ^~~~~~ | |
2580 | with the caret at the operator token, ranging from the start | |
2581 | of the operator token to the end of EXPR. */ | |
2582 | location_t combined_loc = make_location (op_loc, | |
2583 | op_loc, expr.get_finish ()); | |
2584 | cp_expr result = build_x_unary_op (combined_loc, code, expr, complain); | |
2585 | /* TODO: build_x_unary_op doesn't always honor the location. */ | |
2586 | result.set_location (combined_loc); | |
2587 | ||
cda0a029 JM |
2588 | tree result_ovl, expr_ovl; |
2589 | ||
2590 | if (!(complain & tf_warning)) | |
2591 | return result; | |
2592 | ||
2593 | result_ovl = result; | |
2594 | expr_ovl = expr; | |
2595 | ||
2596 | if (!processing_template_decl) | |
2597 | expr_ovl = cp_fully_fold (expr_ovl); | |
2598 | ||
2599 | if (!CONSTANT_CLASS_P (expr_ovl) | |
2600 | || TREE_OVERFLOW_P (expr_ovl)) | |
2601 | return result; | |
2602 | ||
2603 | if (!processing_template_decl) | |
2604 | result_ovl = cp_fully_fold (result_ovl); | |
2605 | ||
2606 | if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl)) | |
e87eed2a | 2607 | overflow_warning (combined_loc, result_ovl); |
59c0753d | 2608 | |
ce4a0391 MM |
2609 | return result; |
2610 | } | |
2611 | ||
a723baf1 | 2612 | /* Finish a compound-literal expression. TYPE is the type to which |
09357846 | 2613 | the CONSTRUCTOR in COMPOUND_LITERAL is being cast. */ |
a723baf1 MM |
2614 | |
2615 | tree | |
834aa426 JM |
2616 | finish_compound_literal (tree type, tree compound_literal, |
2617 | tsubst_flags_t complain) | |
a723baf1 | 2618 | { |
326a4d4e JJ |
2619 | if (type == error_mark_node) |
2620 | return error_mark_node; | |
2621 | ||
76186d20 JM |
2622 | if (TREE_CODE (type) == REFERENCE_TYPE) |
2623 | { | |
2624 | compound_literal | |
2625 | = finish_compound_literal (TREE_TYPE (type), compound_literal, | |
2626 | complain); | |
2627 | return cp_build_c_cast (type, compound_literal, complain); | |
2628 | } | |
2629 | ||
2b643eda MM |
2630 | if (!TYPE_OBJ_P (type)) |
2631 | { | |
834aa426 JM |
2632 | if (complain & tf_error) |
2633 | error ("compound literal of non-object type %qT", type); | |
2b643eda MM |
2634 | return error_mark_node; |
2635 | } | |
2636 | ||
a723baf1 | 2637 | if (processing_template_decl) |
a723baf1 | 2638 | { |
e92fb501 MM |
2639 | TREE_TYPE (compound_literal) = type; |
2640 | /* Mark the expression as a compound literal. */ | |
2641 | TREE_HAS_CONSTRUCTOR (compound_literal) = 1; | |
2642 | return compound_literal; | |
a723baf1 MM |
2643 | } |
2644 | ||
df794884 | 2645 | type = complete_type (type); |
09357846 JM |
2646 | |
2647 | if (TYPE_NON_AGGREGATE_CLASS (type)) | |
2648 | { | |
2649 | /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST | |
2650 | everywhere that deals with function arguments would be a pain, so | |
2651 | just wrap it in a TREE_LIST. The parser set a flag so we know | |
2652 | that it came from T{} rather than T({}). */ | |
2653 | CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1; | |
2654 | compound_literal = build_tree_list (NULL_TREE, compound_literal); | |
834aa426 | 2655 | return build_functional_cast (type, compound_literal, complain); |
09357846 JM |
2656 | } |
2657 | ||
23bee8f4 JJ |
2658 | if (TREE_CODE (type) == ARRAY_TYPE |
2659 | && check_array_initializer (NULL_TREE, type, compound_literal)) | |
2660 | return error_mark_node; | |
754af126 | 2661 | compound_literal = reshape_init (type, compound_literal, complain); |
25339f10 | 2662 | if (SCALAR_TYPE_P (type) |
c428869b | 2663 | && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal) |
6a6bdc3d PC |
2664 | && !check_narrowing (type, compound_literal, complain)) |
2665 | return error_mark_node; | |
80c6dcf5 JM |
2666 | if (TREE_CODE (type) == ARRAY_TYPE |
2667 | && TYPE_DOMAIN (type) == NULL_TREE) | |
2668 | { | |
2669 | cp_complete_array_type_or_error (&type, compound_literal, | |
2670 | false, complain); | |
2671 | if (type == error_mark_node) | |
2672 | return error_mark_node; | |
2673 | } | |
754af126 | 2674 | compound_literal = digest_init (type, compound_literal, complain); |
8c53f5e2 JM |
2675 | if (TREE_CODE (compound_literal) == CONSTRUCTOR) |
2676 | TREE_HAS_CONSTRUCTOR (compound_literal) = true; | |
a63940ba JM |
2677 | /* Put static/constant array temporaries in static variables, but always |
2678 | represent class temporaries with TARGET_EXPR so we elide copies. */ | |
2679 | if ((!at_function_scope_p () || CP_TYPE_CONST_P (type)) | |
2680 | && TREE_CODE (type) == ARRAY_TYPE | |
fa9ef321 | 2681 | && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type) |
a63940ba JM |
2682 | && initializer_constant_valid_p (compound_literal, type)) |
2683 | { | |
2684 | tree decl = create_temporary_var (type); | |
2685 | DECL_INITIAL (decl) = compound_literal; | |
2686 | TREE_STATIC (decl) = 1; | |
2687 | if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type)) | |
2688 | { | |
2689 | /* 5.19 says that a constant expression can include an | |
2690 | lvalue-rvalue conversion applied to "a glvalue of literal type | |
2691 | that refers to a non-volatile temporary object initialized | |
2692 | with a constant expression". Rather than try to communicate | |
2693 | that this VAR_DECL is a temporary, just mark it constexpr. */ | |
2694 | DECL_DECLARED_CONSTEXPR_P (decl) = true; | |
2695 | DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true; | |
2696 | TREE_CONSTANT (decl) = true; | |
2697 | } | |
2698 | cp_apply_type_quals_to_decl (cp_type_quals (type), decl); | |
2699 | decl = pushdecl_top_level (decl); | |
2700 | DECL_NAME (decl) = make_anon_name (); | |
2701 | SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl)); | |
eca7fc57 JM |
2702 | /* Make sure the destructor is callable. */ |
2703 | tree clean = cxx_maybe_build_cleanup (decl, complain); | |
2704 | if (clean == error_mark_node) | |
2705 | return error_mark_node; | |
a63940ba JM |
2706 | return decl; |
2707 | } | |
2708 | else | |
574cfaa4 | 2709 | return get_target_expr_sfinae (compound_literal, complain); |
a723baf1 MM |
2710 | } |
2711 | ||
5f261ba9 MM |
2712 | /* Return the declaration for the function-name variable indicated by |
2713 | ID. */ | |
2714 | ||
2715 | tree | |
2716 | finish_fname (tree id) | |
2717 | { | |
2718 | tree decl; | |
c8094d83 | 2719 | |
3ba09659 | 2720 | decl = fname_decl (input_location, C_RID_CODE (id), id); |
f2381074 KT |
2721 | if (processing_template_decl && current_function_decl |
2722 | && decl != error_mark_node) | |
10b1d5e7 | 2723 | decl = DECL_NAME (decl); |
5f261ba9 MM |
2724 | return decl; |
2725 | } | |
2726 | ||
8014a339 | 2727 | /* Finish a translation unit. */ |
ce4a0391 | 2728 | |
c8094d83 | 2729 | void |
3a978d72 | 2730 | finish_translation_unit (void) |
ce4a0391 MM |
2731 | { |
2732 | /* In case there were missing closebraces, | |
2733 | get us back to the global binding level. */ | |
273a708f | 2734 | pop_everything (); |
ce4a0391 MM |
2735 | while (current_namespace != global_namespace) |
2736 | pop_namespace (); | |
0ba8a114 | 2737 | |
c6002625 | 2738 | /* Do file scope __FUNCTION__ et al. */ |
0ba8a114 | 2739 | finish_fname_decls (); |
ce4a0391 MM |
2740 | } |
2741 | ||
b4c4a9ec MM |
2742 | /* Finish a template type parameter, specified as AGGR IDENTIFIER. |
2743 | Returns the parameter. */ | |
2744 | ||
c8094d83 | 2745 | tree |
3a978d72 | 2746 | finish_template_type_parm (tree aggr, tree identifier) |
b4c4a9ec | 2747 | { |
6eabb241 | 2748 | if (aggr != class_type_node) |
b4c4a9ec | 2749 | { |
cbe5f3b3 | 2750 | permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>"); |
b4c4a9ec MM |
2751 | aggr = class_type_node; |
2752 | } | |
2753 | ||
2754 | return build_tree_list (aggr, identifier); | |
2755 | } | |
2756 | ||
2757 | /* Finish a template template parameter, specified as AGGR IDENTIFIER. | |
2758 | Returns the parameter. */ | |
2759 | ||
c8094d83 | 2760 | tree |
3a978d72 | 2761 | finish_template_template_parm (tree aggr, tree identifier) |
b4c4a9ec | 2762 | { |
c2255bc4 AH |
2763 | tree decl = build_decl (input_location, |
2764 | TYPE_DECL, identifier, NULL_TREE); | |
971e17ff | 2765 | |
b4c4a9ec MM |
2766 | tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE); |
2767 | DECL_TEMPLATE_PARMS (tmpl) = current_template_parms; | |
2768 | DECL_TEMPLATE_RESULT (tmpl) = decl; | |
c727aa5e | 2769 | DECL_ARTIFICIAL (decl) = 1; |
971e17ff AS |
2770 | |
2771 | // Associate the constraints with the underlying declaration, | |
2772 | // not the template. | |
2773 | tree reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms); | |
2774 | tree constr = build_constraints (reqs, NULL_TREE); | |
2775 | set_constraints (decl, constr); | |
2776 | ||
b4c4a9ec MM |
2777 | end_template_decl (); |
2778 | ||
50bc768d | 2779 | gcc_assert (DECL_TEMPLATE_PARMS (tmpl)); |
b37bf5bd | 2780 | |
85d85234 DG |
2781 | check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl), |
2782 | /*is_primary=*/true, /*is_partial=*/false, | |
2783 | /*is_friend=*/0); | |
2784 | ||
b4c4a9ec MM |
2785 | return finish_template_type_parm (aggr, tmpl); |
2786 | } | |
ce4a0391 | 2787 | |
8ba658ee MM |
2788 | /* ARGUMENT is the default-argument value for a template template |
2789 | parameter. If ARGUMENT is invalid, issue error messages and return | |
2790 | the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */ | |
2791 | ||
2792 | tree | |
2793 | check_template_template_default_arg (tree argument) | |
2794 | { | |
2795 | if (TREE_CODE (argument) != TEMPLATE_DECL | |
2796 | && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM | |
8ba658ee MM |
2797 | && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE) |
2798 | { | |
a3a503a5 | 2799 | if (TREE_CODE (argument) == TYPE_DECL) |
e488a090 VR |
2800 | error ("invalid use of type %qT as a default value for a template " |
2801 | "template-parameter", TREE_TYPE (argument)); | |
a3a503a5 GB |
2802 | else |
2803 | error ("invalid default argument for a template template parameter"); | |
8ba658ee MM |
2804 | return error_mark_node; |
2805 | } | |
2806 | ||
2807 | return argument; | |
2808 | } | |
2809 | ||
ce4a0391 MM |
2810 | /* Begin a class definition, as indicated by T. */ |
2811 | ||
2812 | tree | |
e3c888eb | 2813 | begin_class_definition (tree t) |
ce4a0391 | 2814 | { |
7d2f0ecd | 2815 | if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t))) |
7437519c ZW |
2816 | return error_mark_node; |
2817 | ||
522d6614 NS |
2818 | if (processing_template_parmlist) |
2819 | { | |
a82e1a7d | 2820 | error ("definition of %q#T inside template parameter list", t); |
522d6614 NS |
2821 | return error_mark_node; |
2822 | } | |
ebf0bf7f JJ |
2823 | |
2824 | /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733 | |
2825 | are passed the same as decimal scalar types. */ | |
cd924144 JM |
2826 | if (TREE_CODE (t) == RECORD_TYPE |
2827 | && !processing_template_decl) | |
ebf0bf7f | 2828 | { |
cd924144 JM |
2829 | tree ns = TYPE_CONTEXT (t); |
2830 | if (ns && TREE_CODE (ns) == NAMESPACE_DECL | |
2831 | && DECL_CONTEXT (ns) == std_node | |
935c0a5d | 2832 | && DECL_NAME (ns) |
cd924144 JM |
2833 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (ns)), "decimal")) |
2834 | { | |
2835 | const char *n = TYPE_NAME_STRING (t); | |
2836 | if ((strcmp (n, "decimal32") == 0) | |
2837 | || (strcmp (n, "decimal64") == 0) | |
2838 | || (strcmp (n, "decimal128") == 0)) | |
2839 | TYPE_TRANSPARENT_AGGR (t) = 1; | |
2840 | } | |
ebf0bf7f JJ |
2841 | } |
2842 | ||
47ee8904 MM |
2843 | /* A non-implicit typename comes from code like: |
2844 | ||
2845 | template <typename T> struct A { | |
0cbd7506 | 2846 | template <typename U> struct A<T>::B ... |
47ee8904 MM |
2847 | |
2848 | This is erroneous. */ | |
2849 | else if (TREE_CODE (t) == TYPENAME_TYPE) | |
2850 | { | |
a82e1a7d | 2851 | error ("invalid definition of qualified type %qT", t); |
47ee8904 MM |
2852 | t = error_mark_node; |
2853 | } | |
2854 | ||
9e1e64ec | 2855 | if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t)) |
ce4a0391 | 2856 | { |
9e1e64ec | 2857 | t = make_class_type (RECORD_TYPE); |
bd3d082e | 2858 | pushtag (make_anon_name (), t, /*tag_scope=*/ts_current); |
ce4a0391 | 2859 | } |
830fcda8 | 2860 | |
4c571114 | 2861 | if (TYPE_BEING_DEFINED (t)) |
ce4a0391 | 2862 | { |
9e1e64ec | 2863 | t = make_class_type (TREE_CODE (t)); |
bd3d082e | 2864 | pushtag (TYPE_IDENTIFIER (t), t, /*tag_scope=*/ts_current); |
ce4a0391 | 2865 | } |
ff350acd | 2866 | maybe_process_partial_specialization (t); |
29370796 | 2867 | pushclass (t); |
ce4a0391 | 2868 | TYPE_BEING_DEFINED (t) = 1; |
5294e4c3 | 2869 | class_binding_level->defining_class_p = 1; |
b9e75696 | 2870 | |
c0694c4b MM |
2871 | if (flag_pack_struct) |
2872 | { | |
2873 | tree v; | |
2874 | TYPE_PACKED (t) = 1; | |
2875 | /* Even though the type is being defined for the first time | |
2876 | here, there might have been a forward declaration, so there | |
2877 | might be cv-qualified variants of T. */ | |
2878 | for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v)) | |
2879 | TYPE_PACKED (v) = 1; | |
2880 | } | |
ce4a0391 MM |
2881 | /* Reset the interface data, at the earliest possible |
2882 | moment, as it might have been set via a class foo; | |
2883 | before. */ | |
1951a1b6 JM |
2884 | if (! TYPE_ANONYMOUS_P (t)) |
2885 | { | |
8400e75e DM |
2886 | struct c_fileinfo *finfo = \ |
2887 | get_fileinfo (LOCATION_FILE (input_location)); | |
5d709b00 | 2888 | CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only; |
1951a1b6 | 2889 | SET_CLASSTYPE_INTERFACE_UNKNOWN_X |
5d709b00 | 2890 | (t, finfo->interface_unknown); |
1951a1b6 | 2891 | } |
ce4a0391 | 2892 | reset_specialization(); |
c8094d83 | 2893 | |
b7975aed MM |
2894 | /* Make a declaration for this class in its own scope. */ |
2895 | build_self_reference (); | |
2896 | ||
830fcda8 | 2897 | return t; |
ce4a0391 MM |
2898 | } |
2899 | ||
61a127b3 MM |
2900 | /* Finish the member declaration given by DECL. */ |
2901 | ||
2902 | void | |
3a978d72 | 2903 | finish_member_declaration (tree decl) |
61a127b3 MM |
2904 | { |
2905 | if (decl == error_mark_node || decl == NULL_TREE) | |
2906 | return; | |
2907 | ||
2908 | if (decl == void_type_node) | |
2909 | /* The COMPONENT was a friend, not a member, and so there's | |
2910 | nothing for us to do. */ | |
2911 | return; | |
2912 | ||
2913 | /* We should see only one DECL at a time. */ | |
910ad8de | 2914 | gcc_assert (DECL_CHAIN (decl) == NULL_TREE); |
61a127b3 MM |
2915 | |
2916 | /* Set up access control for DECL. */ | |
c8094d83 | 2917 | TREE_PRIVATE (decl) |
61a127b3 | 2918 | = (current_access_specifier == access_private_node); |
c8094d83 | 2919 | TREE_PROTECTED (decl) |
61a127b3 MM |
2920 | = (current_access_specifier == access_protected_node); |
2921 | if (TREE_CODE (decl) == TEMPLATE_DECL) | |
2922 | { | |
17aec3eb RK |
2923 | TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl); |
2924 | TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl); | |
61a127b3 MM |
2925 | } |
2926 | ||
8d0d1915 JM |
2927 | /* Mark the DECL as a member of the current class, unless it's |
2928 | a member of an enumeration. */ | |
2929 | if (TREE_CODE (decl) != CONST_DECL) | |
2930 | DECL_CONTEXT (decl) = current_class_type; | |
61a127b3 | 2931 | |
b1d7b1c0 | 2932 | /* Check for bare parameter packs in the member variable declaration. */ |
1ad8aeeb | 2933 | if (TREE_CODE (decl) == FIELD_DECL) |
4439d02f | 2934 | { |
7b3e2d46 | 2935 | if (check_for_bare_parameter_packs (TREE_TYPE (decl))) |
4439d02f | 2936 | TREE_TYPE (decl) = error_mark_node; |
7b3e2d46 | 2937 | if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl))) |
4439d02f DG |
2938 | DECL_ATTRIBUTES (decl) = NULL_TREE; |
2939 | } | |
b1d7b1c0 | 2940 | |
421844e7 MM |
2941 | /* [dcl.link] |
2942 | ||
2943 | A C language linkage is ignored for the names of class members | |
2944 | and the member function type of class member functions. */ | |
2945 | if (DECL_LANG_SPECIFIC (decl) && DECL_LANGUAGE (decl) == lang_c) | |
5d2ed28c | 2946 | SET_DECL_LANGUAGE (decl, lang_cplusplus); |
421844e7 | 2947 | |
61a127b3 MM |
2948 | /* Put functions on the TYPE_METHODS list and everything else on the |
2949 | TYPE_FIELDS list. Note that these are built up in reverse order. | |
2950 | We reverse them (to obtain declaration order) in finish_struct. */ | |
9ededfc5 | 2951 | if (DECL_DECLARES_FUNCTION_P (decl)) |
61a127b3 MM |
2952 | { |
2953 | /* We also need to add this function to the | |
2954 | CLASSTYPE_METHOD_VEC. */ | |
b77fe7b4 NS |
2955 | if (add_method (current_class_type, decl, NULL_TREE)) |
2956 | { | |
5ce039df | 2957 | gcc_assert (TYPE_MAIN_VARIANT (current_class_type) == current_class_type); |
910ad8de | 2958 | DECL_CHAIN (decl) = TYPE_METHODS (current_class_type); |
b77fe7b4 | 2959 | TYPE_METHODS (current_class_type) = decl; |
f139561c | 2960 | |
b77fe7b4 NS |
2961 | maybe_add_class_template_decl_list (current_class_type, decl, |
2962 | /*friend_p=*/0); | |
2963 | } | |
61a127b3 | 2964 | } |
fad882c6 JM |
2965 | /* Enter the DECL into the scope of the class, if the class |
2966 | isn't a closure (whose fields are supposed to be unnamed). */ | |
2967 | else if (CLASSTYPE_LAMBDA_EXPR (current_class_type) | |
2968 | || pushdecl_class_level (decl)) | |
61a127b3 | 2969 | { |
557831a9 FC |
2970 | if (TREE_CODE (decl) == USING_DECL) |
2971 | { | |
557831a9 FC |
2972 | /* For now, ignore class-scope USING_DECLS, so that |
2973 | debugging backends do not see them. */ | |
2974 | DECL_IGNORED_P (decl) = 1; | |
2975 | } | |
2976 | ||
61a127b3 MM |
2977 | /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields |
2978 | go at the beginning. The reason is that lookup_field_1 | |
2979 | searches the list in order, and we want a field name to | |
2980 | override a type name so that the "struct stat hack" will | |
2981 | work. In particular: | |
2982 | ||
2983 | struct S { enum E { }; int E } s; | |
2984 | s.E = 3; | |
2985 | ||
0e339752 | 2986 | is valid. In addition, the FIELD_DECLs must be maintained in |
61a127b3 MM |
2987 | declaration order so that class layout works as expected. |
2988 | However, we don't need that order until class layout, so we | |
2989 | save a little time by putting FIELD_DECLs on in reverse order | |
2990 | here, and then reversing them in finish_struct_1. (We could | |
2991 | also keep a pointer to the correct insertion points in the | |
2992 | list.) */ | |
2993 | ||
2994 | if (TREE_CODE (decl) == TYPE_DECL) | |
c8094d83 | 2995 | TYPE_FIELDS (current_class_type) |
61a127b3 MM |
2996 | = chainon (TYPE_FIELDS (current_class_type), decl); |
2997 | else | |
2998 | { | |
910ad8de | 2999 | DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type); |
61a127b3 MM |
3000 | TYPE_FIELDS (current_class_type) = decl; |
3001 | } | |
8f032717 | 3002 | |
c8094d83 | 3003 | maybe_add_class_template_decl_list (current_class_type, decl, |
f139561c | 3004 | /*friend_p=*/0); |
61a127b3 MM |
3005 | } |
3006 | } | |
3007 | ||
306ef644 | 3008 | /* Finish processing a complete template declaration. The PARMS are |
36a117a5 MM |
3009 | the template parameters. */ |
3010 | ||
3011 | void | |
3a978d72 | 3012 | finish_template_decl (tree parms) |
36a117a5 MM |
3013 | { |
3014 | if (parms) | |
3015 | end_template_decl (); | |
3016 | else | |
3017 | end_specialization (); | |
3018 | } | |
3019 | ||
971e17ff AS |
3020 | // Returns the template type of the class scope being entered. If we're |
3021 | // entering a constrained class scope. TYPE is the class template | |
3022 | // scope being entered and we may need to match the intended type with | |
3023 | // a constrained specialization. For example: | |
3024 | // | |
3025 | // template<Object T> | |
3026 | // struct S { void f(); }; #1 | |
3027 | // | |
3028 | // template<Object T> | |
3029 | // void S<T>::f() { } #2 | |
3030 | // | |
3031 | // We check, in #2, that S<T> refers precisely to the type declared by | |
3032 | // #1 (i.e., that the constraints match). Note that the following should | |
3033 | // be an error since there is no specialization of S<T> that is | |
3034 | // unconstrained, but this is not diagnosed here. | |
3035 | // | |
3036 | // template<typename T> | |
3037 | // void S<T>::f() { } | |
3038 | // | |
3039 | // We cannot diagnose this problem here since this function also matches | |
3040 | // qualified template names that are not part of a definition. For example: | |
3041 | // | |
3042 | // template<Integral T, Floating_point U> | |
3043 | // typename pair<T, U>::first_type void f(T, U); | |
3044 | // | |
3045 | // Here, it is unlikely that there is a partial specialization of | |
3046 | // pair constrained for for Integral and Floating_point arguments. | |
3047 | // | |
3048 | // The general rule is: if a constrained specialization with matching | |
3049 | // constraints is found return that type. Also note that if TYPE is not a | |
3050 | // class-type (e.g. a typename type), then no fixup is needed. | |
3051 | ||
3052 | static tree | |
3053 | fixup_template_type (tree type) | |
3054 | { | |
3055 | // Find the template parameter list at the a depth appropriate to | |
3056 | // the scope we're trying to enter. | |
3057 | tree parms = current_template_parms; | |
3058 | int depth = template_class_depth (type); | |
3059 | for (int n = processing_template_decl; n > depth && parms; --n) | |
3060 | parms = TREE_CHAIN (parms); | |
3061 | if (!parms) | |
3062 | return type; | |
3063 | tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms); | |
3064 | tree cur_constr = build_constraints (cur_reqs, NULL_TREE); | |
3065 | ||
3066 | // Search for a specialization whose type and constraints match. | |
3067 | tree tmpl = CLASSTYPE_TI_TEMPLATE (type); | |
3068 | tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl); | |
3069 | while (specs) | |
3070 | { | |
3071 | tree spec_constr = get_constraints (TREE_VALUE (specs)); | |
3072 | ||
3073 | // If the type and constraints match a specialization, then we | |
3074 | // are entering that type. | |
3075 | if (same_type_p (type, TREE_TYPE (specs)) | |
3076 | && equivalent_constraints (cur_constr, spec_constr)) | |
3077 | return TREE_TYPE (specs); | |
3078 | specs = TREE_CHAIN (specs); | |
3079 | } | |
3080 | ||
3081 | // If no specialization matches, then must return the type | |
3082 | // previously found. | |
3083 | return type; | |
3084 | } | |
3085 | ||
509fc277 | 3086 | /* Finish processing a template-id (which names a type) of the form |
36a117a5 | 3087 | NAME < ARGS >. Return the TYPE_DECL for the type named by the |
838dfd8a | 3088 | template-id. If ENTERING_SCOPE is nonzero we are about to enter |
36a117a5 MM |
3089 | the scope of template-id indicated. */ |
3090 | ||
3091 | tree | |
3a978d72 | 3092 | finish_template_type (tree name, tree args, int entering_scope) |
36a117a5 | 3093 | { |
28704289 | 3094 | tree type; |
36a117a5 | 3095 | |
28704289 | 3096 | type = lookup_template_class (name, args, |
42eaed49 | 3097 | NULL_TREE, NULL_TREE, entering_scope, |
23fca1f5 | 3098 | tf_warning_or_error | tf_user); |
971e17ff AS |
3099 | |
3100 | /* If we might be entering the scope of a partial specialization, | |
3101 | find the one with the right constraints. */ | |
3102 | if (flag_concepts | |
3103 | && entering_scope | |
3104 | && CLASS_TYPE_P (type) | |
3105 | && dependent_type_p (type) | |
3106 | && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type))) | |
3107 | type = fixup_template_type (type); | |
3108 | ||
28704289 DS |
3109 | if (type == error_mark_node) |
3110 | return type; | |
3111 | else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type)) | |
3112 | return TYPE_STUB_DECL (type); | |
3113 | else | |
3114 | return TYPE_NAME (type); | |
36a117a5 | 3115 | } |
648f19f6 | 3116 | |
ea6021e8 MM |
3117 | /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER. |
3118 | Return a TREE_LIST containing the ACCESS_SPECIFIER and the | |
3119 | BASE_CLASS, or NULL_TREE if an error occurred. The | |
aba649ba | 3120 | ACCESS_SPECIFIER is one of |
809e3e7f NS |
3121 | access_{default,public,protected_private}_node. For a virtual base |
3122 | we set TREE_TYPE. */ | |
ea6021e8 | 3123 | |
c8094d83 | 3124 | tree |
dbbf88d1 | 3125 | finish_base_specifier (tree base, tree access, bool virtual_p) |
ea6021e8 | 3126 | { |
ea6021e8 MM |
3127 | tree result; |
3128 | ||
dbbf88d1 | 3129 | if (base == error_mark_node) |
acb044ee GDR |
3130 | { |
3131 | error ("invalid base-class specification"); | |
3132 | result = NULL_TREE; | |
3133 | } | |
9e1e64ec PC |
3134 | else if (! MAYBE_CLASS_TYPE_P (base)) |
3135 | { | |
3136 | error ("%qT is not a class type", base); | |
3137 | result = NULL_TREE; | |
3138 | } | |
ea6021e8 | 3139 | else |
bb92901d | 3140 | { |
dbbf88d1 | 3141 | if (cp_type_quals (base) != 0) |
0cbd7506 | 3142 | { |
546a4197 PC |
3143 | /* DR 484: Can a base-specifier name a cv-qualified |
3144 | class type? */ | |
0cbd7506 MS |
3145 | base = TYPE_MAIN_VARIANT (base); |
3146 | } | |
dbbf88d1 | 3147 | result = build_tree_list (access, base); |
809e3e7f NS |
3148 | if (virtual_p) |
3149 | TREE_TYPE (result) = integer_type_node; | |
bb92901d | 3150 | } |
ea6021e8 MM |
3151 | |
3152 | return result; | |
3153 | } | |
61a127b3 | 3154 | |
eff3a276 MM |
3155 | /* If FNS is a member function, a set of member functions, or a |
3156 | template-id referring to one or more member functions, return a | |
3157 | BASELINK for FNS, incorporating the current access context. | |
3158 | Otherwise, return FNS unchanged. */ | |
3159 | ||
3160 | tree | |
3161 | baselink_for_fns (tree fns) | |
3162 | { | |
aef3a6b2 | 3163 | tree scope; |
eff3a276 MM |
3164 | tree cl; |
3165 | ||
3166 | if (BASELINK_P (fns) | |
eff3a276 MM |
3167 | || error_operand_p (fns)) |
3168 | return fns; | |
aef3a6b2 JM |
3169 | |
3170 | scope = ovl_scope (fns); | |
3171 | if (!CLASS_TYPE_P (scope)) | |
eff3a276 MM |
3172 | return fns; |
3173 | ||
aef3a6b2 | 3174 | cl = currently_open_derived_class (scope); |
eff3a276 | 3175 | if (!cl) |
aef3a6b2 | 3176 | cl = scope; |
eff3a276 | 3177 | cl = TYPE_BINFO (cl); |
5a40306b | 3178 | return build_baselink (cl, cl, fns, /*optype=*/NULL_TREE); |
eff3a276 MM |
3179 | } |
3180 | ||
9fd30fec | 3181 | /* Returns true iff DECL is a variable from a function outside |
d5f4eddd JM |
3182 | the current one. */ |
3183 | ||
3184 | static bool | |
9fd30fec | 3185 | outer_var_p (tree decl) |
d5f4eddd | 3186 | { |
5a6ccc94 | 3187 | return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL) |
d5f4eddd | 3188 | && DECL_FUNCTION_SCOPE_P (decl) |
cdf47df0 JM |
3189 | && (DECL_CONTEXT (decl) != current_function_decl |
3190 | || parsing_nsdmi ())); | |
d5f4eddd JM |
3191 | } |
3192 | ||
9fd30fec JM |
3193 | /* As above, but also checks that DECL is automatic. */ |
3194 | ||
548cb3d7 | 3195 | bool |
9fd30fec JM |
3196 | outer_automatic_var_p (tree decl) |
3197 | { | |
3198 | return (outer_var_p (decl) | |
3199 | && !TREE_STATIC (decl)); | |
3200 | } | |
3201 | ||
548cb3d7 JM |
3202 | /* DECL satisfies outer_automatic_var_p. Possibly complain about it or |
3203 | rewrite it for lambda capture. */ | |
3204 | ||
3205 | tree | |
3206 | process_outer_var_ref (tree decl, tsubst_flags_t complain) | |
3207 | { | |
3208 | if (cp_unevaluated_operand) | |
3209 | /* It's not a use (3.2) if we're in an unevaluated context. */ | |
3210 | return decl; | |
63d02f05 JM |
3211 | if (decl == error_mark_node) |
3212 | return decl; | |
548cb3d7 JM |
3213 | |
3214 | tree context = DECL_CONTEXT (decl); | |
3215 | tree containing_function = current_function_decl; | |
3216 | tree lambda_stack = NULL_TREE; | |
3217 | tree lambda_expr = NULL_TREE; | |
3218 | tree initializer = convert_from_reference (decl); | |
3219 | ||
3220 | /* Mark it as used now even if the use is ill-formed. */ | |
9f635aba PC |
3221 | if (!mark_used (decl, complain) && !(complain & tf_error)) |
3222 | return error_mark_node; | |
548cb3d7 JM |
3223 | |
3224 | /* Core issue 696: "[At the July 2009 meeting] the CWG expressed | |
3225 | support for an approach in which a reference to a local | |
3226 | [constant] automatic variable in a nested class or lambda body | |
3227 | would enter the expression as an rvalue, which would reduce | |
3228 | the complexity of the problem" | |
3229 | ||
3230 | FIXME update for final resolution of core issue 696. */ | |
3231 | if (decl_maybe_constant_var_p (decl)) | |
3232 | { | |
3233 | if (processing_template_decl) | |
3234 | /* In a template, the constant value may not be in a usable | |
3235 | form, so wait until instantiation time. */ | |
3236 | return decl; | |
3237 | else if (decl_constant_var_p (decl)) | |
5af874fb JM |
3238 | { |
3239 | tree t = maybe_constant_value (convert_from_reference (decl)); | |
3240 | if (TREE_CONSTANT (t)) | |
3241 | return t; | |
3242 | } | |
548cb3d7 JM |
3243 | } |
3244 | ||
3245 | if (parsing_nsdmi ()) | |
3246 | containing_function = NULL_TREE; | |
3247 | else | |
3248 | /* If we are in a lambda function, we can move out until we hit | |
3249 | 1. the context, | |
3250 | 2. a non-lambda function, or | |
3251 | 3. a non-default capturing lambda function. */ | |
3252 | while (context != containing_function | |
3253 | && LAMBDA_FUNCTION_P (containing_function)) | |
3254 | { | |
47867b4f JM |
3255 | tree closure = DECL_CONTEXT (containing_function); |
3256 | lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure); | |
3257 | ||
3258 | if (TYPE_CLASS_SCOPE_P (closure)) | |
3259 | /* A lambda in an NSDMI (c++/64496). */ | |
3260 | break; | |
548cb3d7 JM |
3261 | |
3262 | if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) | |
3263 | == CPLD_NONE) | |
3264 | break; | |
3265 | ||
3266 | lambda_stack = tree_cons (NULL_TREE, | |
3267 | lambda_expr, | |
3268 | lambda_stack); | |
3269 | ||
3270 | containing_function | |
3271 | = decl_function_context (containing_function); | |
3272 | } | |
3273 | ||
56a6f1d3 | 3274 | if (lambda_expr && VAR_P (decl) |
548cb3d7 JM |
3275 | && DECL_ANON_UNION_VAR_P (decl)) |
3276 | { | |
3277 | if (complain & tf_error) | |
3278 | error ("cannot capture member %qD of anonymous union", decl); | |
3279 | return error_mark_node; | |
3280 | } | |
3281 | if (context == containing_function) | |
3282 | { | |
3283 | decl = add_default_capture (lambda_stack, | |
3284 | /*id=*/DECL_NAME (decl), | |
3285 | initializer); | |
3286 | } | |
3287 | else if (lambda_expr) | |
3288 | { | |
3289 | if (complain & tf_error) | |
47867b4f JM |
3290 | { |
3291 | error ("%qD is not captured", decl); | |
3292 | tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr); | |
3293 | if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) | |
3294 | == CPLD_NONE) | |
3295 | inform (location_of (closure), | |
3296 | "the lambda has no capture-default"); | |
3297 | else if (TYPE_CLASS_SCOPE_P (closure)) | |
3298 | inform (0, "lambda in local class %q+T cannot " | |
3299 | "capture variables from the enclosing context", | |
3300 | TYPE_CONTEXT (closure)); | |
4b1cbcee | 3301 | inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl); |
47867b4f | 3302 | } |
548cb3d7 JM |
3303 | return error_mark_node; |
3304 | } | |
3305 | else | |
3306 | { | |
3307 | if (complain & tf_error) | |
3308 | error (VAR_P (decl) | |
3309 | ? G_("use of local variable with automatic storage from containing function") | |
3310 | : G_("use of parameter from containing function")); | |
4b1cbcee | 3311 | inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl); |
548cb3d7 JM |
3312 | return error_mark_node; |
3313 | } | |
3314 | return decl; | |
3315 | } | |
3316 | ||
b3445994 MM |
3317 | /* ID_EXPRESSION is a representation of parsed, but unprocessed, |
3318 | id-expression. (See cp_parser_id_expression for details.) SCOPE, | |
3319 | if non-NULL, is the type or namespace used to explicitly qualify | |
3320 | ID_EXPRESSION. DECL is the entity to which that name has been | |
c8094d83 | 3321 | resolved. |
b3445994 MM |
3322 | |
3323 | *CONSTANT_EXPRESSION_P is true if we are presently parsing a | |
3324 | constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will | |
3325 | be set to true if this expression isn't permitted in a | |
3326 | constant-expression, but it is otherwise not set by this function. | |
3327 | *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a | |
3328 | constant-expression, but a non-constant expression is also | |
3329 | permissible. | |
3330 | ||
02ed62dd MM |
3331 | DONE is true if this expression is a complete postfix-expression; |
3332 | it is false if this expression is followed by '->', '[', '(', etc. | |
3333 | ADDRESS_P is true iff this expression is the operand of '&'. | |
3334 | TEMPLATE_P is true iff the qualified-id was of the form | |
3335 | "A::template B". TEMPLATE_ARG_P is true iff this qualified name | |
3336 | appears as a template argument. | |
3337 | ||
b3445994 MM |
3338 | If an error occurs, and it is the kind of error that might cause |
3339 | the parser to abort a tentative parse, *ERROR_MSG is filled in. It | |
3340 | is the caller's responsibility to issue the message. *ERROR_MSG | |
3341 | will be a string with static storage duration, so the caller need | |
3342 | not "free" it. | |
3343 | ||
3344 | Return an expression for the entity, after issuing appropriate | |
3345 | diagnostics. This function is also responsible for transforming a | |
3346 | reference to a non-static member into a COMPONENT_REF that makes | |
c8094d83 | 3347 | the use of "this" explicit. |
b3445994 MM |
3348 | |
3349 | Upon return, *IDK will be filled in appropriately. */ | |
e87eed2a | 3350 | cp_expr |
c8094d83 | 3351 | finish_id_expression (tree id_expression, |
b3445994 MM |
3352 | tree decl, |
3353 | tree scope, | |
3354 | cp_id_kind *idk, | |
67c03833 JM |
3355 | bool integral_constant_expression_p, |
3356 | bool allow_non_integral_constant_expression_p, | |
3357 | bool *non_integral_constant_expression_p, | |
02ed62dd MM |
3358 | bool template_p, |
3359 | bool done, | |
3360 | bool address_p, | |
3361 | bool template_arg_p, | |
2b7a3abf DS |
3362 | const char **error_msg, |
3363 | location_t location) | |
b3445994 | 3364 | { |
a9727434 FC |
3365 | decl = strip_using_decl (decl); |
3366 | ||
b3445994 MM |
3367 | /* Initialize the output parameters. */ |
3368 | *idk = CP_ID_KIND_NONE; | |
3369 | *error_msg = NULL; | |
3370 | ||
3371 | if (id_expression == error_mark_node) | |
3372 | return error_mark_node; | |
3373 | /* If we have a template-id, then no further lookup is | |
3374 | required. If the template-id was for a template-class, we | |
3375 | will sometimes have a TYPE_DECL at this point. */ | |
3376 | else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
ee935db4 | 3377 | || TREE_CODE (decl) == TYPE_DECL) |
b3445994 MM |
3378 | ; |
3379 | /* Look up the name. */ | |
c8094d83 | 3380 | else |
b3445994 MM |
3381 | { |
3382 | if (decl == error_mark_node) | |
3383 | { | |
3384 | /* Name lookup failed. */ | |
c8094d83 MS |
3385 | if (scope |
3386 | && (!TYPE_P (scope) | |
4546865e | 3387 | || (!dependent_type_p (scope) |
9dc6f476 | 3388 | && !(identifier_p (id_expression) |
4546865e MM |
3389 | && IDENTIFIER_TYPENAME_P (id_expression) |
3390 | && dependent_type_p (TREE_TYPE (id_expression)))))) | |
b3445994 | 3391 | { |
4546865e MM |
3392 | /* If the qualifying type is non-dependent (and the name |
3393 | does not name a conversion operator to a dependent | |
3394 | type), issue an error. */ | |
2b7a3abf | 3395 | qualified_name_lookup_error (scope, id_expression, decl, location); |
b3445994 MM |
3396 | return error_mark_node; |
3397 | } | |
3398 | else if (!scope) | |
3399 | { | |
3400 | /* It may be resolved via Koenig lookup. */ | |
3401 | *idk = CP_ID_KIND_UNQUALIFIED; | |
3402 | return id_expression; | |
3403 | } | |
4546865e MM |
3404 | else |
3405 | decl = id_expression; | |
b3445994 MM |
3406 | } |
3407 | /* If DECL is a variable that would be out of scope under | |
3408 | ANSI/ISO rules, but in scope in the ARM, name lookup | |
3409 | will succeed. Issue a diagnostic here. */ | |
3410 | else | |
3411 | decl = check_for_out_of_scope_variable (decl); | |
3412 | ||
3413 | /* Remember that the name was used in the definition of | |
3414 | the current class so that we can check later to see if | |
3415 | the meaning would have been different after the class | |
3416 | was entirely defined. */ | |
9dc6f476 | 3417 | if (!scope && decl != error_mark_node && identifier_p (id_expression)) |
b3445994 | 3418 | maybe_note_name_used_in_class (id_expression, decl); |
8ca4bf25 | 3419 | |
d5f4eddd JM |
3420 | /* Disallow uses of local variables from containing functions, except |
3421 | within lambda-expressions. */ | |
548cb3d7 | 3422 | if (outer_automatic_var_p (decl)) |
cfb71cad JM |
3423 | { |
3424 | decl = process_outer_var_ref (decl, tf_warning_or_error); | |
3425 | if (decl == error_mark_node) | |
3426 | return error_mark_node; | |
3427 | } | |
da9bc840 JM |
3428 | |
3429 | /* Also disallow uses of function parameters outside the function | |
3430 | body, except inside an unevaluated context (i.e. decltype). */ | |
3431 | if (TREE_CODE (decl) == PARM_DECL | |
3432 | && DECL_CONTEXT (decl) == NULL_TREE | |
3433 | && !cp_unevaluated_operand) | |
3434 | { | |
5d264d62 | 3435 | *error_msg = "use of parameter outside function body"; |
da9bc840 JM |
3436 | return error_mark_node; |
3437 | } | |
b3445994 MM |
3438 | } |
3439 | ||
3440 | /* If we didn't find anything, or what we found was a type, | |
3441 | then this wasn't really an id-expression. */ | |
3442 | if (TREE_CODE (decl) == TEMPLATE_DECL | |
3443 | && !DECL_FUNCTION_TEMPLATE_P (decl)) | |
3444 | { | |
3445 | *error_msg = "missing template arguments"; | |
3446 | return error_mark_node; | |
3447 | } | |
3448 | else if (TREE_CODE (decl) == TYPE_DECL | |
3449 | || TREE_CODE (decl) == NAMESPACE_DECL) | |
3450 | { | |
3451 | *error_msg = "expected primary-expression"; | |
3452 | return error_mark_node; | |
3453 | } | |
3454 | ||
3455 | /* If the name resolved to a template parameter, there is no | |
931a9c05 GB |
3456 | need to look it up again later. */ |
3457 | if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl)) | |
3458 | || TREE_CODE (decl) == TEMPLATE_PARM_INDEX) | |
b3445994 | 3459 | { |
db24eb1f | 3460 | tree r; |
c8094d83 | 3461 | |
b3445994 | 3462 | *idk = CP_ID_KIND_NONE; |
931a9c05 GB |
3463 | if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX) |
3464 | decl = TEMPLATE_PARM_DECL (decl); | |
db24eb1f | 3465 | r = convert_from_reference (DECL_INITIAL (decl)); |
c8094d83 MS |
3466 | |
3467 | if (integral_constant_expression_p | |
68deab91 | 3468 | && !dependent_type_p (TREE_TYPE (decl)) |
db24eb1f | 3469 | && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r)))) |
931a9c05 | 3470 | { |
67c03833 | 3471 | if (!allow_non_integral_constant_expression_p) |
a82e1a7d | 3472 | error ("template parameter %qD of type %qT is not allowed in " |
931a9c05 GB |
3473 | "an integral constant expression because it is not of " |
3474 | "integral or enumeration type", decl, TREE_TYPE (decl)); | |
67c03833 | 3475 | *non_integral_constant_expression_p = true; |
931a9c05 | 3476 | } |
db24eb1f | 3477 | return r; |
931a9c05 | 3478 | } |
b3445994 MM |
3479 | else |
3480 | { | |
a2b4cfaa | 3481 | bool dependent_p = type_dependent_expression_p (decl); |
b3445994 MM |
3482 | |
3483 | /* If the declaration was explicitly qualified indicate | |
3484 | that. The semantics of `A::f(3)' are different than | |
3485 | `f(3)' if `f' is virtual. */ | |
c8094d83 | 3486 | *idk = (scope |
b3445994 MM |
3487 | ? CP_ID_KIND_QUALIFIED |
3488 | : (TREE_CODE (decl) == TEMPLATE_ID_EXPR | |
3489 | ? CP_ID_KIND_TEMPLATE_ID | |
a2b4cfaa JM |
3490 | : (dependent_p |
3491 | ? CP_ID_KIND_UNQUALIFIED_DEPENDENT | |
3492 | : CP_ID_KIND_UNQUALIFIED))); | |
b3445994 MM |
3493 | |
3494 | /* If the name was dependent on a template parameter, we will | |
3495 | resolve the name at instantiation time. */ | |
3496 | if (dependent_p) | |
3497 | { | |
a2b4cfaa JM |
3498 | /* If we found a variable, then name lookup during the |
3499 | instantiation will always resolve to the same VAR_DECL | |
3500 | (or an instantiation thereof). */ | |
3501 | if (VAR_P (decl) | |
3502 | || TREE_CODE (decl) == CONST_DECL | |
3503 | || TREE_CODE (decl) == PARM_DECL) | |
3504 | { | |
3505 | mark_used (decl); | |
3506 | return convert_from_reference (decl); | |
3507 | } | |
3508 | ||
b3445994 MM |
3509 | /* Create a SCOPE_REF for qualified names, if the scope is |
3510 | dependent. */ | |
3511 | if (scope) | |
3512 | { | |
02ed62dd MM |
3513 | if (TYPE_P (scope)) |
3514 | { | |
3515 | if (address_p && done) | |
3516 | decl = finish_qualified_id_expr (scope, decl, | |
3517 | done, address_p, | |
3518 | template_p, | |
a378996b PC |
3519 | template_arg_p, |
3520 | tf_warning_or_error); | |
7e361ae6 JM |
3521 | else |
3522 | { | |
3523 | tree type = NULL_TREE; | |
3524 | if (DECL_P (decl) && !dependent_scope_p (scope)) | |
3525 | type = TREE_TYPE (decl); | |
3526 | decl = build_qualified_name (type, | |
3527 | scope, | |
3528 | id_expression, | |
3529 | template_p); | |
3530 | } | |
02ed62dd MM |
3531 | } |
3532 | if (TREE_TYPE (decl)) | |
3533 | decl = convert_from_reference (decl); | |
3534 | return decl; | |
b3445994 MM |
3535 | } |
3536 | /* A TEMPLATE_ID already contains all the information we | |
3537 | need. */ | |
3538 | if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR) | |
3539 | return id_expression; | |
bad1f462 KL |
3540 | /* The same is true for FIELD_DECL, but we also need to |
3541 | make sure that the syntax is correct. */ | |
3542 | else if (TREE_CODE (decl) == FIELD_DECL) | |
a26ddf11 KL |
3543 | { |
3544 | /* Since SCOPE is NULL here, this is an unqualified name. | |
3545 | Access checking has been performed during name lookup | |
3546 | already. Turn off checking to avoid duplicate errors. */ | |
3547 | push_deferring_access_checks (dk_no_check); | |
3548 | decl = finish_non_static_data_member | |
2defb926 | 3549 | (decl, NULL_TREE, |
a26ddf11 KL |
3550 | /*qualifying_scope=*/NULL_TREE); |
3551 | pop_deferring_access_checks (); | |
3552 | return decl; | |
3553 | } | |
10b1d5e7 | 3554 | return id_expression; |
b3445994 MM |
3555 | } |
3556 | ||
415d4636 | 3557 | if (TREE_CODE (decl) == NAMESPACE_DECL) |
9e95d15f | 3558 | { |
a82e1a7d | 3559 | error ("use of namespace %qD as expression", decl); |
9e95d15f NS |
3560 | return error_mark_node; |
3561 | } | |
3562 | else if (DECL_CLASS_TEMPLATE_P (decl)) | |
3563 | { | |
a82e1a7d | 3564 | error ("use of class template %qT as expression", decl); |
9e95d15f NS |
3565 | return error_mark_node; |
3566 | } | |
3567 | else if (TREE_CODE (decl) == TREE_LIST) | |
3568 | { | |
3569 | /* Ambiguous reference to base members. */ | |
a82e1a7d | 3570 | error ("request for member %qD is ambiguous in " |
9e95d15f NS |
3571 | "multiple inheritance lattice", id_expression); |
3572 | print_candidates (decl); | |
3573 | return error_mark_node; | |
3574 | } | |
415d4636 MM |
3575 | |
3576 | /* Mark variable-like entities as used. Functions are similarly | |
3577 | marked either below or after overload resolution. */ | |
5a6ccc94 | 3578 | if ((VAR_P (decl) |
f27a59cf PC |
3579 | || TREE_CODE (decl) == PARM_DECL |
3580 | || TREE_CODE (decl) == CONST_DECL | |
3581 | || TREE_CODE (decl) == RESULT_DECL) | |
3582 | && !mark_used (decl)) | |
3583 | return error_mark_node; | |
415d4636 | 3584 | |
aef4a215 | 3585 | /* Only certain kinds of names are allowed in constant |
8d0d1915 | 3586 | expression. Template parameters have already |
aef4a215 | 3587 | been handled above. */ |
7f7d4b12 DS |
3588 | if (! error_operand_p (decl) |
3589 | && integral_constant_expression_p | |
aef4a215 | 3590 | && ! decl_constant_var_p (decl) |
8d0d1915 | 3591 | && TREE_CODE (decl) != CONST_DECL |
aef4a215 JM |
3592 | && ! builtin_valid_in_constant_expr_p (decl)) |
3593 | { | |
3594 | if (!allow_non_integral_constant_expression_p) | |
3595 | { | |
3596 | error ("%qD cannot appear in a constant-expression", decl); | |
3597 | return error_mark_node; | |
3598 | } | |
3599 | *non_integral_constant_expression_p = true; | |
3600 | } | |
3601 | ||
7c424acd | 3602 | tree wrap; |
5a6ccc94 | 3603 | if (VAR_P (decl) |
7c424acd | 3604 | && !cp_unevaluated_operand |
71d64cd4 | 3605 | && !processing_template_decl |
56363ffd | 3606 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)) |
3048c0c7 | 3607 | && CP_DECL_THREAD_LOCAL_P (decl) |
7c424acd JM |
3608 | && (wrap = get_tls_wrapper_fn (decl))) |
3609 | { | |
3610 | /* Replace an evaluated use of the thread_local variable with | |
3611 | a call to its wrapper. */ | |
3612 | decl = build_cxx_call (wrap, 0, NULL, tf_warning_or_error); | |
3613 | } | |
4a4f287d BO |
3614 | else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR |
3615 | && variable_template_p (TREE_OPERAND (decl, 0))) | |
3616 | { | |
3617 | decl = finish_template_variable (decl); | |
5e0231c2 | 3618 | mark_used (decl); |
85171e78 | 3619 | decl = convert_from_reference (decl); |
4a4f287d | 3620 | } |
7c424acd | 3621 | else if (scope) |
415d4636 | 3622 | { |
c8094d83 | 3623 | decl = (adjust_result_of_qualified_name_lookup |
90677b8d | 3624 | (decl, scope, current_nonlambda_class_type())); |
e20bcc5e JH |
3625 | |
3626 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
3627 | mark_used (decl); | |
3628 | ||
e467c9d2 | 3629 | if (TYPE_P (scope)) |
02ed62dd MM |
3630 | decl = finish_qualified_id_expr (scope, |
3631 | decl, | |
3632 | done, | |
3633 | address_p, | |
3634 | template_p, | |
a378996b PC |
3635 | template_arg_p, |
3636 | tf_warning_or_error); | |
db24eb1f | 3637 | else |
e467c9d2 | 3638 | decl = convert_from_reference (decl); |
415d4636 | 3639 | } |
9e95d15f | 3640 | else if (TREE_CODE (decl) == FIELD_DECL) |
a26ddf11 KL |
3641 | { |
3642 | /* Since SCOPE is NULL here, this is an unqualified name. | |
3643 | Access checking has been performed during name lookup | |
3644 | already. Turn off checking to avoid duplicate errors. */ | |
3645 | push_deferring_access_checks (dk_no_check); | |
2defb926 | 3646 | decl = finish_non_static_data_member (decl, NULL_TREE, |
a26ddf11 KL |
3647 | /*qualifying_scope=*/NULL_TREE); |
3648 | pop_deferring_access_checks (); | |
3649 | } | |
9e95d15f NS |
3650 | else if (is_overloaded_fn (decl)) |
3651 | { | |
eff3a276 | 3652 | tree first_fn; |
b3445994 | 3653 | |
294e855f | 3654 | first_fn = get_first_fn (decl); |
9e95d15f NS |
3655 | if (TREE_CODE (first_fn) == TEMPLATE_DECL) |
3656 | first_fn = DECL_TEMPLATE_RESULT (first_fn); | |
415d4636 | 3657 | |
9965f21f PC |
3658 | if (!really_overloaded_fn (decl) |
3659 | && !mark_used (first_fn)) | |
3660 | return error_mark_node; | |
415d4636 | 3661 | |
02ed62dd MM |
3662 | if (!template_arg_p |
3663 | && TREE_CODE (first_fn) == FUNCTION_DECL | |
821eaf2a MM |
3664 | && DECL_FUNCTION_MEMBER_P (first_fn) |
3665 | && !shared_member_p (decl)) | |
9e95d15f NS |
3666 | { |
3667 | /* A set of member functions. */ | |
3668 | decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0); | |
02ed62dd | 3669 | return finish_class_member_access_expr (decl, id_expression, |
5ade1ed2 DG |
3670 | /*template_p=*/false, |
3671 | tf_warning_or_error); | |
9e95d15f | 3672 | } |
eff3a276 MM |
3673 | |
3674 | decl = baselink_for_fns (decl); | |
9e95d15f NS |
3675 | } |
3676 | else | |
3677 | { | |
9e95d15f | 3678 | if (DECL_P (decl) && DECL_NONLOCAL (decl) |
24f58e74 | 3679 | && DECL_CLASS_SCOPE_P (decl)) |
9e95d15f | 3680 | { |
24f58e74 PC |
3681 | tree context = context_for_name_lookup (decl); |
3682 | if (context != current_class_type) | |
3683 | { | |
3684 | tree path = currently_open_derived_class (context); | |
3685 | perform_or_defer_access_check (TYPE_BINFO (path), | |
0e69fdf0 PC |
3686 | decl, decl, |
3687 | tf_warning_or_error); | |
24f58e74 | 3688 | } |
9e95d15f | 3689 | } |
c8094d83 | 3690 | |
db24eb1f | 3691 | decl = convert_from_reference (decl); |
9e95d15f | 3692 | } |
b3445994 MM |
3693 | } |
3694 | ||
e87eed2a | 3695 | return cp_expr (decl, location); |
b3445994 MM |
3696 | } |
3697 | ||
0213a355 JM |
3698 | /* Implement the __typeof keyword: Return the type of EXPR, suitable for |
3699 | use as a type-specifier. */ | |
3700 | ||
b894fc05 | 3701 | tree |
3a978d72 | 3702 | finish_typeof (tree expr) |
b894fc05 | 3703 | { |
65a5559b MM |
3704 | tree type; |
3705 | ||
dffbbe80 | 3706 | if (type_dependent_expression_p (expr)) |
b894fc05 | 3707 | { |
9e1e64ec | 3708 | type = cxx_make_type (TYPEOF_TYPE); |
eb34af89 | 3709 | TYPEOF_TYPE_EXPR (type) = expr; |
3ad6a8e1 | 3710 | SET_TYPE_STRUCTURAL_EQUALITY (type); |
b894fc05 | 3711 | |
65a5559b | 3712 | return type; |
b894fc05 JM |
3713 | } |
3714 | ||
03a904b5 JJ |
3715 | expr = mark_type_use (expr); |
3716 | ||
3c38f0ff | 3717 | type = unlowered_expr_type (expr); |
65a5559b MM |
3718 | |
3719 | if (!type || type == unknown_type_node) | |
3720 | { | |
a82e1a7d | 3721 | error ("type of %qE is unknown", expr); |
65a5559b MM |
3722 | return error_mark_node; |
3723 | } | |
3724 | ||
3725 | return type; | |
b894fc05 | 3726 | } |
558475f0 | 3727 | |
a0d260fc PC |
3728 | /* Implement the __underlying_type keyword: Return the underlying |
3729 | type of TYPE, suitable for use as a type-specifier. */ | |
3730 | ||
3731 | tree | |
3732 | finish_underlying_type (tree type) | |
3733 | { | |
3734 | tree underlying_type; | |
3735 | ||
3736 | if (processing_template_decl) | |
3737 | { | |
3738 | underlying_type = cxx_make_type (UNDERLYING_TYPE); | |
3739 | UNDERLYING_TYPE_TYPE (underlying_type) = type; | |
3740 | SET_TYPE_STRUCTURAL_EQUALITY (underlying_type); | |
3741 | ||
3742 | return underlying_type; | |
3743 | } | |
3744 | ||
3745 | complete_type (type); | |
3746 | ||
3747 | if (TREE_CODE (type) != ENUMERAL_TYPE) | |
3748 | { | |
ca2507dc | 3749 | error ("%qT is not an enumeration type", type); |
a0d260fc PC |
3750 | return error_mark_node; |
3751 | } | |
3752 | ||
3753 | underlying_type = ENUM_UNDERLYING_TYPE (type); | |
3754 | ||
3755 | /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE | |
3756 | includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information. | |
3757 | See finish_enum_value_list for details. */ | |
3758 | if (!ENUM_FIXED_UNDERLYING_TYPE_P (type)) | |
3759 | underlying_type | |
3760 | = c_common_type_for_mode (TYPE_MODE (underlying_type), | |
3761 | TYPE_UNSIGNED (underlying_type)); | |
3762 | ||
3763 | return underlying_type; | |
3764 | } | |
3765 | ||
4daba884 BK |
3766 | /* Implement the __direct_bases keyword: Return the direct base classes |
3767 | of type */ | |
3768 | ||
3769 | tree | |
3770 | calculate_direct_bases (tree type) | |
3771 | { | |
9771b263 | 3772 | vec<tree, va_gc> *vector = make_tree_vector(); |
4daba884 | 3773 | tree bases_vec = NULL_TREE; |
9771b263 | 3774 | vec<tree, va_gc> *base_binfos; |
4daba884 BK |
3775 | tree binfo; |
3776 | unsigned i; | |
3777 | ||
3778 | complete_type (type); | |
3779 | ||
3780 | if (!NON_UNION_CLASS_TYPE_P (type)) | |
3781 | return make_tree_vec (0); | |
3782 | ||
3783 | base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type)); | |
3784 | ||
3785 | /* Virtual bases are initialized first */ | |
9771b263 | 3786 | for (i = 0; base_binfos->iterate (i, &binfo); i++) |
4daba884 BK |
3787 | { |
3788 | if (BINFO_VIRTUAL_P (binfo)) | |
3789 | { | |
9771b263 | 3790 | vec_safe_push (vector, binfo); |
4daba884 BK |
3791 | } |
3792 | } | |
3793 | ||
3794 | /* Now non-virtuals */ | |
9771b263 | 3795 | for (i = 0; base_binfos->iterate (i, &binfo); i++) |
4daba884 BK |
3796 | { |
3797 | if (!BINFO_VIRTUAL_P (binfo)) | |
3798 | { | |
9771b263 | 3799 | vec_safe_push (vector, binfo); |
4daba884 BK |
3800 | } |
3801 | } | |
3802 | ||
3803 | ||
9771b263 | 3804 | bases_vec = make_tree_vec (vector->length ()); |
4daba884 | 3805 | |
9771b263 | 3806 | for (i = 0; i < vector->length (); ++i) |
4daba884 | 3807 | { |
9771b263 | 3808 | TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]); |
4daba884 BK |
3809 | } |
3810 | return bases_vec; | |
3811 | } | |
3812 | ||
3813 | /* Implement the __bases keyword: Return the base classes | |
3814 | of type */ | |
3815 | ||
3816 | /* Find morally non-virtual base classes by walking binfo hierarchy */ | |
3817 | /* Virtual base classes are handled separately in finish_bases */ | |
3818 | ||
3819 | static tree | |
12308bc6 | 3820 | dfs_calculate_bases_pre (tree binfo, void * /*data_*/) |
4daba884 BK |
3821 | { |
3822 | /* Don't walk bases of virtual bases */ | |
3823 | return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE; | |
3824 | } | |
3825 | ||
3826 | static tree | |
3827 | dfs_calculate_bases_post (tree binfo, void *data_) | |
3828 | { | |
9771b263 | 3829 | vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_); |
4daba884 BK |
3830 | if (!BINFO_VIRTUAL_P (binfo)) |
3831 | { | |
9771b263 | 3832 | vec_safe_push (*data, BINFO_TYPE (binfo)); |
4daba884 BK |
3833 | } |
3834 | return NULL_TREE; | |
3835 | } | |
3836 | ||
3837 | /* Calculates the morally non-virtual base classes of a class */ | |
9771b263 | 3838 | static vec<tree, va_gc> * |
4daba884 BK |
3839 | calculate_bases_helper (tree type) |
3840 | { | |
9771b263 | 3841 | vec<tree, va_gc> *vector = make_tree_vector(); |
4daba884 BK |
3842 | |
3843 | /* Now add non-virtual base classes in order of construction */ | |
3844 | dfs_walk_all (TYPE_BINFO (type), | |
3845 | dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector); | |
3846 | return vector; | |
3847 | } | |
3848 | ||
3849 | tree | |
3850 | calculate_bases (tree type) | |
3851 | { | |
9771b263 | 3852 | vec<tree, va_gc> *vector = make_tree_vector(); |
4daba884 BK |
3853 | tree bases_vec = NULL_TREE; |
3854 | unsigned i; | |
9771b263 DN |
3855 | vec<tree, va_gc> *vbases; |
3856 | vec<tree, va_gc> *nonvbases; | |
4daba884 BK |
3857 | tree binfo; |
3858 | ||
3859 | complete_type (type); | |
3860 | ||
3861 | if (!NON_UNION_CLASS_TYPE_P (type)) | |
3862 | return make_tree_vec (0); | |
3863 | ||
3864 | /* First go through virtual base classes */ | |
3865 | for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0; | |
9771b263 | 3866 | vec_safe_iterate (vbases, i, &binfo); i++) |
4daba884 | 3867 | { |
9771b263 DN |
3868 | vec<tree, va_gc> *vbase_bases; |
3869 | vbase_bases = calculate_bases_helper (BINFO_TYPE (binfo)); | |
3870 | vec_safe_splice (vector, vbase_bases); | |
4daba884 BK |
3871 | release_tree_vector (vbase_bases); |
3872 | } | |
3873 | ||
3874 | /* Now for the non-virtual bases */ | |
3875 | nonvbases = calculate_bases_helper (type); | |
9771b263 | 3876 | vec_safe_splice (vector, nonvbases); |
4daba884 BK |
3877 | release_tree_vector (nonvbases); |
3878 | ||
3879 | /* Last element is entire class, so don't copy */ | |
9771b263 | 3880 | bases_vec = make_tree_vec (vector->length () - 1); |
4daba884 | 3881 | |
9771b263 | 3882 | for (i = 0; i < vector->length () - 1; ++i) |
4daba884 | 3883 | { |
9771b263 | 3884 | TREE_VEC_ELT (bases_vec, i) = (*vector)[i]; |
4daba884 BK |
3885 | } |
3886 | release_tree_vector (vector); | |
3887 | return bases_vec; | |
3888 | } | |
3889 | ||
3890 | tree | |
3891 | finish_bases (tree type, bool direct) | |
3892 | { | |
3893 | tree bases = NULL_TREE; | |
3894 | ||
3895 | if (!processing_template_decl) | |
3896 | { | |
3897 | /* Parameter packs can only be used in templates */ | |
3898 | error ("Parameter pack __bases only valid in template declaration"); | |
3899 | return error_mark_node; | |
3900 | } | |
3901 | ||
3902 | bases = cxx_make_type (BASES); | |
3903 | BASES_TYPE (bases) = type; | |
3904 | BASES_DIRECT (bases) = direct; | |
3905 | SET_TYPE_STRUCTURAL_EQUALITY (bases); | |
3906 | ||
3907 | return bases; | |
3908 | } | |
3909 | ||
c291f8b1 VR |
3910 | /* Perform C++-specific checks for __builtin_offsetof before calling |
3911 | fold_offsetof. */ | |
3912 | ||
3913 | tree | |
8591575f | 3914 | finish_offsetof (tree expr, location_t loc) |
c291f8b1 | 3915 | { |
b433d944 JM |
3916 | /* If we're processing a template, we can't finish the semantics yet. |
3917 | Otherwise we can fold the entire expression now. */ | |
3918 | if (processing_template_decl) | |
3919 | { | |
3920 | expr = build1 (OFFSETOF_EXPR, size_type_node, expr); | |
3921 | SET_EXPR_LOCATION (expr, loc); | |
3922 | return expr; | |
3923 | } | |
3924 | ||
4c65a534 VR |
3925 | if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR) |
3926 | { | |
3927 | error ("cannot apply %<offsetof%> to destructor %<~%T%>", | |
3928 | TREE_OPERAND (expr, 2)); | |
3929 | return error_mark_node; | |
3930 | } | |
c291f8b1 VR |
3931 | if (TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE |
3932 | || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE | |
fbfc8363 | 3933 | || TREE_TYPE (expr) == unknown_type_node) |
c291f8b1 | 3934 | { |
98cf9ac9 | 3935 | if (INDIRECT_REF_P (expr)) |
929f647a PC |
3936 | error ("second operand of %<offsetof%> is neither a single " |
3937 | "identifier nor a sequence of member accesses and " | |
3938 | "array references"); | |
3939 | else | |
3940 | { | |
3941 | if (TREE_CODE (expr) == COMPONENT_REF | |
3942 | || TREE_CODE (expr) == COMPOUND_EXPR) | |
3943 | expr = TREE_OPERAND (expr, 1); | |
3944 | error ("cannot apply %<offsetof%> to member function %qD", expr); | |
3945 | } | |
c291f8b1 VR |
3946 | return error_mark_node; |
3947 | } | |
31e292c7 | 3948 | if (REFERENCE_REF_P (expr)) |
60c4d135 | 3949 | expr = TREE_OPERAND (expr, 0); |
a174e38c JM |
3950 | if (TREE_CODE (expr) == COMPONENT_REF) |
3951 | { | |
3952 | tree object = TREE_OPERAND (expr, 0); | |
3953 | if (!complete_type_or_else (TREE_TYPE (object), object)) | |
3954 | return error_mark_node; | |
8591575f JM |
3955 | if (warn_invalid_offsetof |
3956 | && CLASS_TYPE_P (TREE_TYPE (object)) | |
3957 | && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (object)) | |
3958 | && cp_unevaluated_operand == 0) | |
3959 | pedwarn (loc, OPT_Winvalid_offsetof, | |
3960 | "offsetof within non-standard-layout type %qT is undefined", | |
3961 | TREE_TYPE (object)); | |
a174e38c | 3962 | } |
cf9e9959 | 3963 | return fold_offsetof (expr); |
c291f8b1 VR |
3964 | } |
3965 | ||
9eeb200f JM |
3966 | /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This |
3967 | function is broken out from the above for the benefit of the tree-ssa | |
3968 | project. */ | |
3969 | ||
3970 | void | |
3971 | simplify_aggr_init_expr (tree *tp) | |
3972 | { | |
3973 | tree aggr_init_expr = *tp; | |
3974 | ||
3eb24f73 | 3975 | /* Form an appropriate CALL_EXPR. */ |
5039610b SL |
3976 | tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr); |
3977 | tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr); | |
2692eb7d | 3978 | tree type = TREE_TYPE (slot); |
9eeb200f JM |
3979 | |
3980 | tree call_expr; | |
3981 | enum style_t { ctor, arg, pcc } style; | |
4977bab6 | 3982 | |
3eb24f73 | 3983 | if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr)) |
4977bab6 ZW |
3984 | style = ctor; |
3985 | #ifdef PCC_STATIC_STRUCT_RETURN | |
3986 | else if (1) | |
3987 | style = pcc; | |
3988 | #endif | |
4977bab6 | 3989 | else |
315fb5db NS |
3990 | { |
3991 | gcc_assert (TREE_ADDRESSABLE (type)); | |
3992 | style = arg; | |
3993 | } | |
4977bab6 | 3994 | |
db3927fb AH |
3995 | call_expr = build_call_array_loc (input_location, |
3996 | TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))), | |
3997 | fn, | |
3998 | aggr_init_expr_nargs (aggr_init_expr), | |
3999 | AGGR_INIT_EXPR_ARGP (aggr_init_expr)); | |
d8a0d13e | 4000 | TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr); |
fe6ebcf1 | 4001 | CALL_EXPR_LIST_INIT_P (call_expr) = CALL_EXPR_LIST_INIT_P (aggr_init_expr); |
5039610b | 4002 | |
fa47911c | 4003 | if (style == ctor) |
3eb24f73 | 4004 | { |
fa47911c JM |
4005 | /* Replace the first argument to the ctor with the address of the |
4006 | slot. */ | |
dffd7eb6 | 4007 | cxx_mark_addressable (slot); |
5039610b SL |
4008 | CALL_EXPR_ARG (call_expr, 0) = |
4009 | build1 (ADDR_EXPR, build_pointer_type (type), slot); | |
3eb24f73 | 4010 | } |
5039610b | 4011 | else if (style == arg) |
fa47911c JM |
4012 | { |
4013 | /* Just mark it addressable here, and leave the rest to | |
4014 | expand_call{,_inline}. */ | |
4015 | cxx_mark_addressable (slot); | |
4016 | CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true; | |
71d1add3 | 4017 | call_expr = build2 (INIT_EXPR, TREE_TYPE (call_expr), slot, call_expr); |
fa47911c | 4018 | } |
4977bab6 | 4019 | else if (style == pcc) |
3eb24f73 | 4020 | { |
4977bab6 ZW |
4021 | /* If we're using the non-reentrant PCC calling convention, then we |
4022 | need to copy the returned value out of the static buffer into the | |
4023 | SLOT. */ | |
78757caa | 4024 | push_deferring_access_checks (dk_no_check); |
71d1add3 JM |
4025 | call_expr = build_aggr_init (slot, call_expr, |
4026 | DIRECT_BIND | LOOKUP_ONLYCONVERTING, | |
4027 | tf_warning_or_error); | |
78757caa | 4028 | pop_deferring_access_checks (); |
71d1add3 | 4029 | call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot); |
4561285b JM |
4030 | } |
4031 | ||
450a927a JM |
4032 | if (AGGR_INIT_ZERO_FIRST (aggr_init_expr)) |
4033 | { | |
4034 | tree init = build_zero_init (type, NULL_TREE, | |
4035 | /*static_storage_p=*/false); | |
4036 | init = build2 (INIT_EXPR, void_type_node, slot, init); | |
71d1add3 JM |
4037 | call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr), |
4038 | init, call_expr); | |
450a927a JM |
4039 | } |
4040 | ||
71d1add3 | 4041 | *tp = call_expr; |
3eb24f73 MM |
4042 | } |
4043 | ||
31f8e4f3 MM |
4044 | /* Emit all thunks to FN that should be emitted when FN is emitted. */ |
4045 | ||
e89d6010 | 4046 | void |
3a978d72 | 4047 | emit_associated_thunks (tree fn) |
31f8e4f3 MM |
4048 | { |
4049 | /* When we use vcall offsets, we emit thunks with the virtual | |
4050 | functions to which they thunk. The whole point of vcall offsets | |
4051 | is so that you can know statically the entire set of thunks that | |
4052 | will ever be needed for a given virtual function, thereby | |
4053 | enabling you to output all the thunks with the function itself. */ | |
4537ec0c DN |
4054 | if (DECL_VIRTUAL_P (fn) |
4055 | /* Do not emit thunks for extern template instantiations. */ | |
4056 | && ! DECL_REALLY_EXTERN (fn)) | |
31f8e4f3 | 4057 | { |
bb5e8a7f | 4058 | tree thunk; |
c8094d83 | 4059 | |
910ad8de | 4060 | for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk)) |
4977bab6 | 4061 | { |
e00853fd | 4062 | if (!THUNK_ALIAS (thunk)) |
4977bab6 | 4063 | { |
bb885938 NS |
4064 | use_thunk (thunk, /*emit_p=*/1); |
4065 | if (DECL_RESULT_THUNK_P (thunk)) | |
4066 | { | |
4067 | tree probe; | |
c8094d83 | 4068 | |
bb885938 | 4069 | for (probe = DECL_THUNKS (thunk); |
910ad8de | 4070 | probe; probe = DECL_CHAIN (probe)) |
bb885938 NS |
4071 | use_thunk (probe, /*emit_p=*/1); |
4072 | } | |
4977bab6 | 4073 | } |
bb885938 | 4074 | else |
50bc768d | 4075 | gcc_assert (!DECL_THUNKS (thunk)); |
4977bab6 | 4076 | } |
31f8e4f3 MM |
4077 | } |
4078 | } | |
4079 | ||
558475f0 MM |
4080 | /* Generate RTL for FN. */ |
4081 | ||
b2583345 JJ |
4082 | bool |
4083 | expand_or_defer_fn_1 (tree fn) | |
8cd2462c JH |
4084 | { |
4085 | /* When the parser calls us after finishing the body of a template | |
c353b8e3 MM |
4086 | function, we don't really want to expand the body. */ |
4087 | if (processing_template_decl) | |
8cd2462c JH |
4088 | { |
4089 | /* Normally, collection only occurs in rest_of_compilation. So, | |
4090 | if we don't collect here, we never collect junk generated | |
4091 | during the processing of templates until we hit a | |
27250734 MM |
4092 | non-template function. It's not safe to do this inside a |
4093 | nested class, though, as the parser may have local state that | |
4094 | is not a GC root. */ | |
4095 | if (!function_depth) | |
4096 | ggc_collect (); | |
b2583345 | 4097 | return false; |
8cd2462c JH |
4098 | } |
4099 | ||
a406865a | 4100 | gcc_assert (DECL_SAVED_TREE (fn)); |
726a989a | 4101 | |
4684cd27 MM |
4102 | /* We make a decision about linkage for these functions at the end |
4103 | of the compilation. Until that point, we do not want the back | |
4104 | end to output them -- but we do want it to see the bodies of | |
1a10290c | 4105 | these functions so that it can inline them as appropriate. */ |
4684cd27 MM |
4106 | if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn)) |
4107 | { | |
1ef0df47 MM |
4108 | if (DECL_INTERFACE_KNOWN (fn)) |
4109 | /* We've already made a decision as to how this function will | |
4110 | be handled. */; | |
4111 | else if (!at_eof) | |
944b63db | 4112 | tentative_decl_linkage (fn); |
4684cd27 MM |
4113 | else |
4114 | import_export_decl (fn); | |
1a10290c MM |
4115 | |
4116 | /* If the user wants us to keep all inline functions, then mark | |
4117 | this function as needed so that finish_file will make sure to | |
fe2978fb MM |
4118 | output it later. Similarly, all dllexport'd functions must |
4119 | be emitted; there may be callers in other DLLs. */ | |
322d490e KT |
4120 | if (DECL_DECLARED_INLINE_P (fn) |
4121 | && !DECL_REALLY_EXTERN (fn) | |
4122 | && (flag_keep_inline_functions | |
4123 | || (flag_keep_inline_dllexport | |
4124 | && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn))))) | |
ffca9d53 JM |
4125 | { |
4126 | mark_needed (fn); | |
4127 | DECL_EXTERNAL (fn) = 0; | |
4128 | } | |
4684cd27 MM |
4129 | } |
4130 | ||
1f26ac87 JM |
4131 | /* If this is a constructor or destructor body, we have to clone |
4132 | it. */ | |
4133 | if (maybe_clone_body (fn)) | |
4134 | { | |
4135 | /* We don't want to process FN again, so pretend we've written | |
4136 | it out, even though we haven't. */ | |
4137 | TREE_ASM_WRITTEN (fn) = 1; | |
4138 | /* If this is an instantiation of a constexpr function, keep | |
4139 | DECL_SAVED_TREE for explain_invalid_constexpr_fn. */ | |
4140 | if (!is_instantiation_of_constexpr (fn)) | |
4141 | DECL_SAVED_TREE (fn) = NULL_TREE; | |
4142 | return false; | |
4143 | } | |
4144 | ||
8cd2462c JH |
4145 | /* There's no reason to do any of the work here if we're only doing |
4146 | semantic analysis; this code just generates RTL. */ | |
4147 | if (flag_syntax_only) | |
b2583345 JJ |
4148 | return false; |
4149 | ||
4150 | return true; | |
4151 | } | |
8cd2462c | 4152 | |
b2583345 JJ |
4153 | void |
4154 | expand_or_defer_fn (tree fn) | |
4155 | { | |
4156 | if (expand_or_defer_fn_1 (fn)) | |
4157 | { | |
4158 | function_depth++; | |
99edd65d | 4159 | |
b2583345 | 4160 | /* Expand or defer, at the whim of the compilation unit manager. */ |
3dafb85c | 4161 | cgraph_node::finalize_function (fn, function_depth > 1); |
6744a6ab | 4162 | emit_associated_thunks (fn); |
99edd65d | 4163 | |
b2583345 JJ |
4164 | function_depth--; |
4165 | } | |
8cd2462c JH |
4166 | } |
4167 | ||
6de9cd9a DN |
4168 | struct nrv_data |
4169 | { | |
c203e8a7 TS |
4170 | nrv_data () : visited (37) {} |
4171 | ||
6de9cd9a DN |
4172 | tree var; |
4173 | tree result; | |
8d67ee55 | 4174 | hash_table<nofree_ptr_hash <tree_node> > visited; |
6de9cd9a | 4175 | }; |
0d97bf4c | 4176 | |
6de9cd9a DN |
4177 | /* Helper function for walk_tree, used by finalize_nrv below. */ |
4178 | ||
4179 | static tree | |
4180 | finalize_nrv_r (tree* tp, int* walk_subtrees, void* data) | |
0d97bf4c | 4181 | { |
6de9cd9a | 4182 | struct nrv_data *dp = (struct nrv_data *)data; |
703c8606 | 4183 | tree_node **slot; |
07b2f2fd JM |
4184 | |
4185 | /* No need to walk into types. There wouldn't be any need to walk into | |
4186 | non-statements, except that we have to consider STMT_EXPRs. */ | |
0d97bf4c JM |
4187 | if (TYPE_P (*tp)) |
4188 | *walk_subtrees = 0; | |
6de9cd9a DN |
4189 | /* Change all returns to just refer to the RESULT_DECL; this is a nop, |
4190 | but differs from using NULL_TREE in that it indicates that we care | |
4191 | about the value of the RESULT_DECL. */ | |
5088b058 RH |
4192 | else if (TREE_CODE (*tp) == RETURN_EXPR) |
4193 | TREE_OPERAND (*tp, 0) = dp->result; | |
6de9cd9a DN |
4194 | /* Change all cleanups for the NRV to only run when an exception is |
4195 | thrown. */ | |
07b2f2fd | 4196 | else if (TREE_CODE (*tp) == CLEANUP_STMT |
6de9cd9a | 4197 | && CLEANUP_DECL (*tp) == dp->var) |
659e5a7a | 4198 | CLEANUP_EH_ONLY (*tp) = 1; |
350fae66 | 4199 | /* Replace the DECL_EXPR for the NRV with an initialization of the |
6de9cd9a | 4200 | RESULT_DECL, if needed. */ |
350fae66 RK |
4201 | else if (TREE_CODE (*tp) == DECL_EXPR |
4202 | && DECL_EXPR_DECL (*tp) == dp->var) | |
6de9cd9a DN |
4203 | { |
4204 | tree init; | |
4205 | if (DECL_INITIAL (dp->var) | |
4206 | && DECL_INITIAL (dp->var) != error_mark_node) | |
2d188530 JJ |
4207 | init = build2 (INIT_EXPR, void_type_node, dp->result, |
4208 | DECL_INITIAL (dp->var)); | |
6de9cd9a | 4209 | else |
c2255bc4 | 4210 | init = build_empty_stmt (EXPR_LOCATION (*tp)); |
2d188530 | 4211 | DECL_INITIAL (dp->var) = NULL_TREE; |
5e278028 | 4212 | SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp)); |
6de9cd9a DN |
4213 | *tp = init; |
4214 | } | |
4215 | /* And replace all uses of the NRV with the RESULT_DECL. */ | |
4216 | else if (*tp == dp->var) | |
4217 | *tp = dp->result; | |
4218 | ||
4219 | /* Avoid walking into the same tree more than once. Unfortunately, we | |
4220 | can't just use walk_tree_without duplicates because it would only call | |
4221 | us for the first occurrence of dp->var in the function body. */ | |
703c8606 | 4222 | slot = dp->visited.find_slot (*tp, INSERT); |
6de9cd9a DN |
4223 | if (*slot) |
4224 | *walk_subtrees = 0; | |
4225 | else | |
4226 | *slot = *tp; | |
0d97bf4c JM |
4227 | |
4228 | /* Keep iterating. */ | |
4229 | return NULL_TREE; | |
4230 | } | |
4231 | ||
6de9cd9a | 4232 | /* Called from finish_function to implement the named return value |
5088b058 | 4233 | optimization by overriding all the RETURN_EXPRs and pertinent |
6de9cd9a DN |
4234 | CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the |
4235 | RESULT_DECL for the function. */ | |
f444e36b | 4236 | |
4985cde3 | 4237 | void |
6de9cd9a | 4238 | finalize_nrv (tree *tp, tree var, tree result) |
f444e36b | 4239 | { |
6de9cd9a DN |
4240 | struct nrv_data data; |
4241 | ||
add86e09 | 4242 | /* Copy name from VAR to RESULT. */ |
6de9cd9a | 4243 | DECL_NAME (result) = DECL_NAME (var); |
6de9cd9a DN |
4244 | /* Don't forget that we take its address. */ |
4245 | TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var); | |
add86e09 JJ |
4246 | /* Finally set DECL_VALUE_EXPR to avoid assigning |
4247 | a stack slot at -O0 for the original var and debug info | |
4248 | uses RESULT location for VAR. */ | |
4249 | SET_DECL_VALUE_EXPR (var, result); | |
4250 | DECL_HAS_VALUE_EXPR_P (var) = 1; | |
6de9cd9a DN |
4251 | |
4252 | data.var = var; | |
4253 | data.result = result; | |
14588106 | 4254 | cp_walk_tree (tp, finalize_nrv_r, &data, 0); |
b850de4f | 4255 | } |
1799e5d5 | 4256 | \f |
a68ab351 JJ |
4257 | /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */ |
4258 | ||
4259 | bool | |
4260 | cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor, | |
acf0174b JJ |
4261 | bool need_copy_ctor, bool need_copy_assignment, |
4262 | bool need_dtor) | |
a68ab351 JJ |
4263 | { |
4264 | int save_errorcount = errorcount; | |
4265 | tree info, t; | |
4266 | ||
4267 | /* Always allocate 3 elements for simplicity. These are the | |
4268 | function decls for the ctor, dtor, and assignment op. | |
4269 | This layout is known to the three lang hooks, | |
4270 | cxx_omp_clause_default_init, cxx_omp_clause_copy_init, | |
4271 | and cxx_omp_clause_assign_op. */ | |
4272 | info = make_tree_vec (3); | |
4273 | CP_OMP_CLAUSE_INFO (c) = info; | |
4274 | ||
ac177431 | 4275 | if (need_default_ctor || need_copy_ctor) |
a68ab351 JJ |
4276 | { |
4277 | if (need_default_ctor) | |
ac177431 | 4278 | t = get_default_ctor (type); |
a68ab351 | 4279 | else |
4577f730 | 4280 | t = get_copy_ctor (type, tf_warning_or_error); |
ac177431 JM |
4281 | |
4282 | if (t && !trivial_fn_p (t)) | |
4283 | TREE_VEC_ELT (info, 0) = t; | |
a68ab351 JJ |
4284 | } |
4285 | ||
acf0174b | 4286 | if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) |
4577f730 | 4287 | TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error); |
a68ab351 | 4288 | |
ac177431 | 4289 | if (need_copy_assignment) |
a68ab351 | 4290 | { |
ac177431 JM |
4291 | t = get_copy_assign (type); |
4292 | ||
4293 | if (t && !trivial_fn_p (t)) | |
4294 | TREE_VEC_ELT (info, 2) = t; | |
a68ab351 JJ |
4295 | } |
4296 | ||
4297 | return errorcount != save_errorcount; | |
4298 | } | |
4299 | ||
d9a6bd32 JJ |
4300 | /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding |
4301 | FIELD_DECL, otherwise return DECL itself. */ | |
4302 | ||
4303 | static tree | |
4304 | omp_clause_decl_field (tree decl) | |
4305 | { | |
4306 | if (VAR_P (decl) | |
4307 | && DECL_HAS_VALUE_EXPR_P (decl) | |
4308 | && DECL_ARTIFICIAL (decl) | |
4309 | && DECL_LANG_SPECIFIC (decl) | |
4310 | && DECL_OMP_PRIVATIZED_MEMBER (decl)) | |
4311 | { | |
4312 | tree f = DECL_VALUE_EXPR (decl); | |
4313 | if (TREE_CODE (f) == INDIRECT_REF) | |
4314 | f = TREE_OPERAND (f, 0); | |
4315 | if (TREE_CODE (f) == COMPONENT_REF) | |
4316 | { | |
4317 | f = TREE_OPERAND (f, 1); | |
4318 | gcc_assert (TREE_CODE (f) == FIELD_DECL); | |
4319 | return f; | |
4320 | } | |
4321 | } | |
4322 | return NULL_TREE; | |
4323 | } | |
4324 | ||
4325 | /* Adjust DECL if needed for printing using %qE. */ | |
4326 | ||
4327 | static tree | |
4328 | omp_clause_printable_decl (tree decl) | |
4329 | { | |
4330 | tree t = omp_clause_decl_field (decl); | |
4331 | if (t) | |
4332 | return t; | |
4333 | return decl; | |
4334 | } | |
4335 | ||
4336 | /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER | |
4337 | VAR_DECL T that doesn't need a DECL_EXPR added, record it for | |
4338 | privatization. */ | |
4339 | ||
4340 | static void | |
4341 | omp_note_field_privatization (tree f, tree t) | |
4342 | { | |
4343 | if (!omp_private_member_map) | |
4344 | omp_private_member_map = new hash_map<tree, tree>; | |
4345 | tree &v = omp_private_member_map->get_or_insert (f); | |
4346 | if (v == NULL_TREE) | |
4347 | { | |
4348 | v = t; | |
4349 | omp_private_member_vec.safe_push (f); | |
4350 | /* Signal that we don't want to create DECL_EXPR for this dummy var. */ | |
4351 | omp_private_member_vec.safe_push (integer_zero_node); | |
4352 | } | |
4353 | } | |
4354 | ||
4355 | /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER | |
4356 | dummy VAR_DECL. */ | |
4357 | ||
4358 | tree | |
e01d41e5 | 4359 | omp_privatize_field (tree t, bool shared) |
d9a6bd32 JJ |
4360 | { |
4361 | tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE); | |
4362 | if (m == error_mark_node) | |
4363 | return error_mark_node; | |
e01d41e5 | 4364 | if (!omp_private_member_map && !shared) |
d9a6bd32 JJ |
4365 | omp_private_member_map = new hash_map<tree, tree>; |
4366 | if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE) | |
4367 | { | |
4368 | gcc_assert (TREE_CODE (m) == INDIRECT_REF); | |
4369 | m = TREE_OPERAND (m, 0); | |
4370 | } | |
e01d41e5 JJ |
4371 | tree vb = NULL_TREE; |
4372 | tree &v = shared ? vb : omp_private_member_map->get_or_insert (t); | |
d9a6bd32 JJ |
4373 | if (v == NULL_TREE) |
4374 | { | |
4375 | v = create_temporary_var (TREE_TYPE (m)); | |
4376 | if (!DECL_LANG_SPECIFIC (v)) | |
4377 | retrofit_lang_decl (v); | |
4378 | DECL_OMP_PRIVATIZED_MEMBER (v) = 1; | |
4379 | SET_DECL_VALUE_EXPR (v, m); | |
4380 | DECL_HAS_VALUE_EXPR_P (v) = 1; | |
e01d41e5 JJ |
4381 | if (!shared) |
4382 | omp_private_member_vec.safe_push (t); | |
d9a6bd32 JJ |
4383 | } |
4384 | return v; | |
4385 | } | |
4386 | ||
acf0174b JJ |
4387 | /* Helper function for handle_omp_array_sections. Called recursively |
4388 | to handle multiple array-section-subscripts. C is the clause, | |
4389 | T current expression (initially OMP_CLAUSE_DECL), which is either | |
4390 | a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound | |
4391 | expression if specified, TREE_VALUE length expression if specified, | |
4392 | TREE_CHAIN is what it has been specified after, or some decl. | |
4393 | TYPES vector is populated with array section types, MAYBE_ZERO_LEN | |
4394 | set to true if any of the array-section-subscript could have length | |
4395 | of zero (explicit or implicit), FIRST_NON_ONE is the index of the | |
4396 | first array-section-subscript which is known not to have length | |
4397 | of one. Given say: | |
4398 | map(a[:b][2:1][:c][:2][:d][e:f][2:5]) | |
4399 | FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c] | |
4400 | all are or may have length of 1, array-section-subscript [:2] is the | |
d9a6bd32 | 4401 | first one known not to have length 1. For array-section-subscript |
acf0174b JJ |
4402 | <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't |
4403 | 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we | |
4404 | can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above | |
4405 | case though, as some lengths could be zero. */ | |
4406 | ||
4407 | static tree | |
4408 | handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types, | |
d9a6bd32 JJ |
4409 | bool &maybe_zero_len, unsigned int &first_non_one, |
4410 | bool is_omp) | |
acf0174b JJ |
4411 | { |
4412 | tree ret, low_bound, length, type; | |
4413 | if (TREE_CODE (t) != TREE_LIST) | |
4414 | { | |
4415 | if (error_operand_p (t)) | |
4416 | return error_mark_node; | |
d9a6bd32 JJ |
4417 | if (REFERENCE_REF_P (t) |
4418 | && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF) | |
4419 | t = TREE_OPERAND (t, 0); | |
4420 | ret = t; | |
4421 | if (TREE_CODE (t) == COMPONENT_REF | |
4422 | && is_omp | |
4423 | && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP | |
4424 | || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO | |
4425 | || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM) | |
4426 | && !type_dependent_expression_p (t)) | |
4427 | { | |
4428 | if (DECL_BIT_FIELD (TREE_OPERAND (t, 1))) | |
4429 | { | |
4430 | error_at (OMP_CLAUSE_LOCATION (c), | |
4431 | "bit-field %qE in %qs clause", | |
4432 | t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4433 | return error_mark_node; | |
4434 | } | |
4435 | while (TREE_CODE (t) == COMPONENT_REF) | |
4436 | { | |
4437 | if (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == UNION_TYPE) | |
4438 | { | |
4439 | error_at (OMP_CLAUSE_LOCATION (c), | |
4440 | "%qE is a member of a union", t); | |
4441 | return error_mark_node; | |
4442 | } | |
4443 | t = TREE_OPERAND (t, 0); | |
4444 | } | |
4445 | } | |
56a6f1d3 | 4446 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
acf0174b JJ |
4447 | { |
4448 | if (processing_template_decl) | |
4449 | return NULL_TREE; | |
4450 | if (DECL_P (t)) | |
4451 | error_at (OMP_CLAUSE_LOCATION (c), | |
4452 | "%qD is not a variable in %qs clause", t, | |
4453 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4454 | else | |
4455 | error_at (OMP_CLAUSE_LOCATION (c), | |
4456 | "%qE is not a variable in %qs clause", t, | |
4457 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4458 | return error_mark_node; | |
4459 | } | |
d9a6bd32 JJ |
4460 | else if (TREE_CODE (t) == PARM_DECL |
4461 | && DECL_ARTIFICIAL (t) | |
4462 | && DECL_NAME (t) == this_identifier) | |
4463 | { | |
4464 | error_at (OMP_CLAUSE_LOCATION (c), | |
4465 | "%<this%> allowed in OpenMP only in %<declare simd%>" | |
4466 | " clauses"); | |
4467 | return error_mark_node; | |
4468 | } | |
acf0174b | 4469 | else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND |
3048c0c7 | 4470 | && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) |
acf0174b JJ |
4471 | { |
4472 | error_at (OMP_CLAUSE_LOCATION (c), | |
4473 | "%qD is threadprivate variable in %qs clause", t, | |
4474 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4475 | return error_mark_node; | |
4476 | } | |
d9a6bd32 | 4477 | if (type_dependent_expression_p (ret)) |
7da8534d | 4478 | return NULL_TREE; |
d9a6bd32 JJ |
4479 | ret = convert_from_reference (ret); |
4480 | return ret; | |
acf0174b JJ |
4481 | } |
4482 | ||
d9a6bd32 JJ |
4483 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION |
4484 | && TREE_CODE (TREE_CHAIN (t)) == FIELD_DECL) | |
e01d41e5 | 4485 | TREE_CHAIN (t) = omp_privatize_field (TREE_CHAIN (t), false); |
acf0174b | 4486 | ret = handle_omp_array_sections_1 (c, TREE_CHAIN (t), types, |
d9a6bd32 | 4487 | maybe_zero_len, first_non_one, is_omp); |
acf0174b JJ |
4488 | if (ret == error_mark_node || ret == NULL_TREE) |
4489 | return ret; | |
4490 | ||
4491 | type = TREE_TYPE (ret); | |
4492 | low_bound = TREE_PURPOSE (t); | |
4493 | length = TREE_VALUE (t); | |
4494 | if ((low_bound && type_dependent_expression_p (low_bound)) | |
4495 | || (length && type_dependent_expression_p (length))) | |
4496 | return NULL_TREE; | |
4497 | ||
4498 | if (low_bound == error_mark_node || length == error_mark_node) | |
4499 | return error_mark_node; | |
4500 | ||
4501 | if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound))) | |
4502 | { | |
4503 | error_at (OMP_CLAUSE_LOCATION (c), | |
4504 | "low bound %qE of array section does not have integral type", | |
4505 | low_bound); | |
4506 | return error_mark_node; | |
4507 | } | |
4508 | if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length))) | |
4509 | { | |
4510 | error_at (OMP_CLAUSE_LOCATION (c), | |
4511 | "length %qE of array section does not have integral type", | |
4512 | length); | |
4513 | return error_mark_node; | |
4514 | } | |
d90c0a59 JJ |
4515 | if (low_bound) |
4516 | low_bound = mark_rvalue_use (low_bound); | |
4517 | if (length) | |
4518 | length = mark_rvalue_use (length); | |
cda0a029 JM |
4519 | /* We need to reduce to real constant-values for checks below. */ |
4520 | if (length) | |
4521 | length = fold_simple (length); | |
4522 | if (low_bound) | |
4523 | low_bound = fold_simple (low_bound); | |
acf0174b JJ |
4524 | if (low_bound |
4525 | && TREE_CODE (low_bound) == INTEGER_CST | |
4526 | && TYPE_PRECISION (TREE_TYPE (low_bound)) | |
4527 | > TYPE_PRECISION (sizetype)) | |
4528 | low_bound = fold_convert (sizetype, low_bound); | |
4529 | if (length | |
4530 | && TREE_CODE (length) == INTEGER_CST | |
4531 | && TYPE_PRECISION (TREE_TYPE (length)) | |
4532 | > TYPE_PRECISION (sizetype)) | |
4533 | length = fold_convert (sizetype, length); | |
4534 | if (low_bound == NULL_TREE) | |
4535 | low_bound = integer_zero_node; | |
4536 | ||
4537 | if (length != NULL_TREE) | |
4538 | { | |
4539 | if (!integer_nonzerop (length)) | |
d9a6bd32 JJ |
4540 | { |
4541 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND | |
4542 | || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) | |
4543 | { | |
4544 | if (integer_zerop (length)) | |
4545 | { | |
4546 | error_at (OMP_CLAUSE_LOCATION (c), | |
4547 | "zero length array section in %qs clause", | |
4548 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4549 | return error_mark_node; | |
4550 | } | |
4551 | } | |
4552 | else | |
4553 | maybe_zero_len = true; | |
4554 | } | |
acf0174b JJ |
4555 | if (first_non_one == types.length () |
4556 | && (TREE_CODE (length) != INTEGER_CST || integer_onep (length))) | |
4557 | first_non_one++; | |
4558 | } | |
4559 | if (TREE_CODE (type) == ARRAY_TYPE) | |
4560 | { | |
4561 | if (length == NULL_TREE | |
4562 | && (TYPE_DOMAIN (type) == NULL_TREE | |
4563 | || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)) | |
4564 | { | |
4565 | error_at (OMP_CLAUSE_LOCATION (c), | |
4566 | "for unknown bound array type length expression must " | |
4567 | "be specified"); | |
4568 | return error_mark_node; | |
4569 | } | |
4570 | if (TREE_CODE (low_bound) == INTEGER_CST | |
4571 | && tree_int_cst_sgn (low_bound) == -1) | |
4572 | { | |
4573 | error_at (OMP_CLAUSE_LOCATION (c), | |
4574 | "negative low bound in array section in %qs clause", | |
4575 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4576 | return error_mark_node; | |
4577 | } | |
4578 | if (length != NULL_TREE | |
4579 | && TREE_CODE (length) == INTEGER_CST | |
4580 | && tree_int_cst_sgn (length) == -1) | |
4581 | { | |
4582 | error_at (OMP_CLAUSE_LOCATION (c), | |
4583 | "negative length in array section in %qs clause", | |
4584 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4585 | return error_mark_node; | |
4586 | } | |
4587 | if (TYPE_DOMAIN (type) | |
4588 | && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) | |
4589 | && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) | |
4590 | == INTEGER_CST) | |
4591 | { | |
4592 | tree size = size_binop (PLUS_EXPR, | |
4593 | TYPE_MAX_VALUE (TYPE_DOMAIN (type)), | |
4594 | size_one_node); | |
4595 | if (TREE_CODE (low_bound) == INTEGER_CST) | |
4596 | { | |
4597 | if (tree_int_cst_lt (size, low_bound)) | |
4598 | { | |
4599 | error_at (OMP_CLAUSE_LOCATION (c), | |
4600 | "low bound %qE above array section size " | |
4601 | "in %qs clause", low_bound, | |
4602 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4603 | return error_mark_node; | |
4604 | } | |
4605 | if (tree_int_cst_equal (size, low_bound)) | |
d9a6bd32 JJ |
4606 | { |
4607 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND | |
4608 | || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) | |
4609 | { | |
4610 | error_at (OMP_CLAUSE_LOCATION (c), | |
4611 | "zero length array section in %qs clause", | |
4612 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4613 | return error_mark_node; | |
4614 | } | |
4615 | maybe_zero_len = true; | |
4616 | } | |
acf0174b JJ |
4617 | else if (length == NULL_TREE |
4618 | && first_non_one == types.length () | |
4619 | && tree_int_cst_equal | |
4620 | (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), | |
4621 | low_bound)) | |
4622 | first_non_one++; | |
4623 | } | |
4624 | else if (length == NULL_TREE) | |
4625 | { | |
d9a6bd32 JJ |
4626 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND |
4627 | && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) | |
4628 | maybe_zero_len = true; | |
acf0174b JJ |
4629 | if (first_non_one == types.length ()) |
4630 | first_non_one++; | |
4631 | } | |
4632 | if (length && TREE_CODE (length) == INTEGER_CST) | |
4633 | { | |
4634 | if (tree_int_cst_lt (size, length)) | |
4635 | { | |
4636 | error_at (OMP_CLAUSE_LOCATION (c), | |
4637 | "length %qE above array section size " | |
4638 | "in %qs clause", length, | |
4639 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4640 | return error_mark_node; | |
4641 | } | |
4642 | if (TREE_CODE (low_bound) == INTEGER_CST) | |
4643 | { | |
4644 | tree lbpluslen | |
4645 | = size_binop (PLUS_EXPR, | |
4646 | fold_convert (sizetype, low_bound), | |
4647 | fold_convert (sizetype, length)); | |
4648 | if (TREE_CODE (lbpluslen) == INTEGER_CST | |
4649 | && tree_int_cst_lt (size, lbpluslen)) | |
4650 | { | |
4651 | error_at (OMP_CLAUSE_LOCATION (c), | |
4652 | "high bound %qE above array section size " | |
4653 | "in %qs clause", lbpluslen, | |
4654 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4655 | return error_mark_node; | |
4656 | } | |
4657 | } | |
4658 | } | |
4659 | } | |
4660 | else if (length == NULL_TREE) | |
4661 | { | |
d9a6bd32 JJ |
4662 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND |
4663 | && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) | |
4664 | maybe_zero_len = true; | |
acf0174b JJ |
4665 | if (first_non_one == types.length ()) |
4666 | first_non_one++; | |
4667 | } | |
4668 | ||
4669 | /* For [lb:] we will need to evaluate lb more than once. */ | |
4670 | if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) | |
4671 | { | |
4672 | tree lb = cp_save_expr (low_bound); | |
4673 | if (lb != low_bound) | |
4674 | { | |
4675 | TREE_PURPOSE (t) = lb; | |
4676 | low_bound = lb; | |
4677 | } | |
4678 | } | |
4679 | } | |
4680 | else if (TREE_CODE (type) == POINTER_TYPE) | |
4681 | { | |
4682 | if (length == NULL_TREE) | |
4683 | { | |
4684 | error_at (OMP_CLAUSE_LOCATION (c), | |
4685 | "for pointer type length expression must be specified"); | |
4686 | return error_mark_node; | |
4687 | } | |
d9a6bd32 JJ |
4688 | if (length != NULL_TREE |
4689 | && TREE_CODE (length) == INTEGER_CST | |
4690 | && tree_int_cst_sgn (length) == -1) | |
4691 | { | |
4692 | error_at (OMP_CLAUSE_LOCATION (c), | |
4693 | "negative length in array section in %qs clause", | |
4694 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4695 | return error_mark_node; | |
4696 | } | |
acf0174b JJ |
4697 | /* If there is a pointer type anywhere but in the very first |
4698 | array-section-subscript, the array section can't be contiguous. */ | |
4699 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND | |
4700 | && TREE_CODE (TREE_CHAIN (t)) == TREE_LIST) | |
4701 | { | |
4702 | error_at (OMP_CLAUSE_LOCATION (c), | |
4703 | "array section is not contiguous in %qs clause", | |
4704 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
4705 | return error_mark_node; | |
4706 | } | |
4707 | } | |
4708 | else | |
4709 | { | |
4710 | error_at (OMP_CLAUSE_LOCATION (c), | |
4711 | "%qE does not have pointer or array type", ret); | |
4712 | return error_mark_node; | |
4713 | } | |
4714 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) | |
4715 | types.safe_push (TREE_TYPE (ret)); | |
4716 | /* We will need to evaluate lb more than once. */ | |
4717 | tree lb = cp_save_expr (low_bound); | |
4718 | if (lb != low_bound) | |
4719 | { | |
4720 | TREE_PURPOSE (t) = lb; | |
4721 | low_bound = lb; | |
4722 | } | |
4723 | ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, false); | |
4724 | return ret; | |
4725 | } | |
4726 | ||
4727 | /* Handle array sections for clause C. */ | |
4728 | ||
4729 | static bool | |
d9a6bd32 | 4730 | handle_omp_array_sections (tree c, bool is_omp) |
acf0174b JJ |
4731 | { |
4732 | bool maybe_zero_len = false; | |
4733 | unsigned int first_non_one = 0; | |
d9a6bd32 | 4734 | auto_vec<tree, 10> types; |
acf0174b | 4735 | tree first = handle_omp_array_sections_1 (c, OMP_CLAUSE_DECL (c), types, |
d9a6bd32 JJ |
4736 | maybe_zero_len, first_non_one, |
4737 | is_omp); | |
acf0174b | 4738 | if (first == error_mark_node) |
ef062b13 | 4739 | return true; |
acf0174b | 4740 | if (first == NULL_TREE) |
ef062b13 | 4741 | return false; |
acf0174b JJ |
4742 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND) |
4743 | { | |
4744 | tree t = OMP_CLAUSE_DECL (c); | |
4745 | tree tem = NULL_TREE; | |
acf0174b JJ |
4746 | if (processing_template_decl) |
4747 | return false; | |
4748 | /* Need to evaluate side effects in the length expressions | |
4749 | if any. */ | |
4750 | while (TREE_CODE (t) == TREE_LIST) | |
4751 | { | |
4752 | if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t))) | |
4753 | { | |
4754 | if (tem == NULL_TREE) | |
4755 | tem = TREE_VALUE (t); | |
4756 | else | |
4757 | tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem), | |
4758 | TREE_VALUE (t), tem); | |
4759 | } | |
4760 | t = TREE_CHAIN (t); | |
4761 | } | |
4762 | if (tem) | |
4763 | first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first); | |
4764 | OMP_CLAUSE_DECL (c) = first; | |
4765 | } | |
4766 | else | |
4767 | { | |
4768 | unsigned int num = types.length (), i; | |
4769 | tree t, side_effects = NULL_TREE, size = NULL_TREE; | |
4770 | tree condition = NULL_TREE; | |
4771 | ||
4772 | if (int_size_in_bytes (TREE_TYPE (first)) <= 0) | |
4773 | maybe_zero_len = true; | |
4774 | if (processing_template_decl && maybe_zero_len) | |
ef062b13 | 4775 | return false; |
acf0174b JJ |
4776 | |
4777 | for (i = num, t = OMP_CLAUSE_DECL (c); i > 0; | |
4778 | t = TREE_CHAIN (t)) | |
4779 | { | |
4780 | tree low_bound = TREE_PURPOSE (t); | |
4781 | tree length = TREE_VALUE (t); | |
4782 | ||
4783 | i--; | |
4784 | if (low_bound | |
4785 | && TREE_CODE (low_bound) == INTEGER_CST | |
4786 | && TYPE_PRECISION (TREE_TYPE (low_bound)) | |
4787 | > TYPE_PRECISION (sizetype)) | |
4788 | low_bound = fold_convert (sizetype, low_bound); | |
4789 | if (length | |
4790 | && TREE_CODE (length) == INTEGER_CST | |
4791 | && TYPE_PRECISION (TREE_TYPE (length)) | |
4792 | > TYPE_PRECISION (sizetype)) | |
4793 | length = fold_convert (sizetype, length); | |
4794 | if (low_bound == NULL_TREE) | |
4795 | low_bound = integer_zero_node; | |
4796 | if (!maybe_zero_len && i > first_non_one) | |
4797 | { | |
4798 | if (integer_nonzerop (low_bound)) | |
4799 | goto do_warn_noncontiguous; | |
4800 | if (length != NULL_TREE | |
4801 | && TREE_CODE (length) == INTEGER_CST | |
4802 | && TYPE_DOMAIN (types[i]) | |
4803 | && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])) | |
4804 | && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))) | |
4805 | == INTEGER_CST) | |
4806 | { | |
4807 | tree size; | |
4808 | size = size_binop (PLUS_EXPR, | |
4809 | TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])), | |
4810 | size_one_node); | |
4811 | if (!tree_int_cst_equal (length, size)) | |
4812 | { | |
4813 | do_warn_noncontiguous: | |
4814 | error_at (OMP_CLAUSE_LOCATION (c), | |
4815 | "array section is not contiguous in %qs " | |
4816 | "clause", | |
4817 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
acf0174b JJ |
4818 | return true; |
4819 | } | |
4820 | } | |
4821 | if (!processing_template_decl | |
4822 | && length != NULL_TREE | |
4823 | && TREE_SIDE_EFFECTS (length)) | |
4824 | { | |
4825 | if (side_effects == NULL_TREE) | |
4826 | side_effects = length; | |
4827 | else | |
4828 | side_effects = build2 (COMPOUND_EXPR, | |
4829 | TREE_TYPE (side_effects), | |
4830 | length, side_effects); | |
4831 | } | |
4832 | } | |
4833 | else if (processing_template_decl) | |
4834 | continue; | |
4835 | else | |
4836 | { | |
4837 | tree l; | |
4838 | ||
d9a6bd32 JJ |
4839 | if (i > first_non_one |
4840 | && ((length && integer_nonzerop (length)) | |
4841 | || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)) | |
acf0174b JJ |
4842 | continue; |
4843 | if (length) | |
4844 | l = fold_convert (sizetype, length); | |
4845 | else | |
4846 | { | |
4847 | l = size_binop (PLUS_EXPR, | |
4848 | TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])), | |
4849 | size_one_node); | |
4850 | l = size_binop (MINUS_EXPR, l, | |
4851 | fold_convert (sizetype, low_bound)); | |
4852 | } | |
4853 | if (i > first_non_one) | |
4854 | { | |
4855 | l = fold_build2 (NE_EXPR, boolean_type_node, l, | |
4856 | size_zero_node); | |
4857 | if (condition == NULL_TREE) | |
4858 | condition = l; | |
4859 | else | |
4860 | condition = fold_build2 (BIT_AND_EXPR, boolean_type_node, | |
4861 | l, condition); | |
4862 | } | |
4863 | else if (size == NULL_TREE) | |
4864 | { | |
4865 | size = size_in_bytes (TREE_TYPE (types[i])); | |
d9a6bd32 JJ |
4866 | tree eltype = TREE_TYPE (types[num - 1]); |
4867 | while (TREE_CODE (eltype) == ARRAY_TYPE) | |
4868 | eltype = TREE_TYPE (eltype); | |
4869 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) | |
4870 | size = size_binop (EXACT_DIV_EXPR, size, | |
4871 | size_in_bytes (eltype)); | |
acf0174b JJ |
4872 | size = size_binop (MULT_EXPR, size, l); |
4873 | if (condition) | |
4874 | size = fold_build3 (COND_EXPR, sizetype, condition, | |
4875 | size, size_zero_node); | |
4876 | } | |
4877 | else | |
4878 | size = size_binop (MULT_EXPR, size, l); | |
4879 | } | |
4880 | } | |
acf0174b JJ |
4881 | if (!processing_template_decl) |
4882 | { | |
4883 | if (side_effects) | |
4884 | size = build2 (COMPOUND_EXPR, sizetype, side_effects, size); | |
d9a6bd32 JJ |
4885 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) |
4886 | { | |
4887 | size = size_binop (MINUS_EXPR, size, size_one_node); | |
4888 | tree index_type = build_index_type (size); | |
4889 | tree eltype = TREE_TYPE (first); | |
4890 | while (TREE_CODE (eltype) == ARRAY_TYPE) | |
4891 | eltype = TREE_TYPE (eltype); | |
4892 | tree type = build_array_type (eltype, index_type); | |
4893 | tree ptype = build_pointer_type (eltype); | |
4894 | if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE | |
4895 | && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t)))) | |
4896 | t = convert_from_reference (t); | |
4897 | else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) | |
4898 | t = build_fold_addr_expr (t); | |
e01d41e5 JJ |
4899 | tree t2 = build_fold_addr_expr (first); |
4900 | t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), | |
4901 | ptrdiff_type_node, t2); | |
4902 | t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR, | |
4903 | ptrdiff_type_node, t2, | |
4904 | fold_convert_loc (OMP_CLAUSE_LOCATION (c), | |
4905 | ptrdiff_type_node, t)); | |
4906 | if (tree_fits_shwi_p (t2)) | |
4907 | t = build2 (MEM_REF, type, t, | |
4908 | build_int_cst (ptype, tree_to_shwi (t2))); | |
4909 | else | |
4910 | { | |
4911 | t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), | |
4912 | sizetype, t2); | |
4913 | t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR, | |
4914 | TREE_TYPE (t), t, t2); | |
4915 | t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0)); | |
4916 | } | |
d9a6bd32 JJ |
4917 | OMP_CLAUSE_DECL (c) = t; |
4918 | return false; | |
4919 | } | |
acf0174b JJ |
4920 | OMP_CLAUSE_DECL (c) = first; |
4921 | OMP_CLAUSE_SIZE (c) = size; | |
d9a6bd32 JJ |
4922 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP |
4923 | || (TREE_CODE (t) == COMPONENT_REF | |
4924 | && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)) | |
acf0174b | 4925 | return false; |
d9a6bd32 JJ |
4926 | if (is_omp) |
4927 | switch (OMP_CLAUSE_MAP_KIND (c)) | |
4928 | { | |
4929 | case GOMP_MAP_ALLOC: | |
4930 | case GOMP_MAP_TO: | |
4931 | case GOMP_MAP_FROM: | |
4932 | case GOMP_MAP_TOFROM: | |
4933 | case GOMP_MAP_ALWAYS_TO: | |
4934 | case GOMP_MAP_ALWAYS_FROM: | |
4935 | case GOMP_MAP_ALWAYS_TOFROM: | |
4936 | case GOMP_MAP_RELEASE: | |
4937 | case GOMP_MAP_DELETE: | |
4938 | OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1; | |
4939 | break; | |
4940 | default: | |
4941 | break; | |
4942 | } | |
acf0174b JJ |
4943 | tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c), |
4944 | OMP_CLAUSE_MAP); | |
e01d41e5 JJ |
4945 | if (!is_omp) |
4946 | OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_POINTER); | |
4947 | else if (TREE_CODE (t) == COMPONENT_REF) | |
4948 | OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER); | |
4949 | else if (REFERENCE_REF_P (t) | |
4950 | && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF) | |
4951 | { | |
4952 | t = TREE_OPERAND (t, 0); | |
4953 | OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER); | |
4954 | } | |
4955 | else | |
4956 | OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER); | |
4957 | if (OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER | |
4958 | && !cxx_mark_addressable (t)) | |
acf0174b JJ |
4959 | return false; |
4960 | OMP_CLAUSE_DECL (c2) = t; | |
4961 | t = build_fold_addr_expr (first); | |
4962 | t = fold_convert_loc (OMP_CLAUSE_LOCATION (c), | |
4963 | ptrdiff_type_node, t); | |
4964 | tree ptr = OMP_CLAUSE_DECL (c2); | |
4965 | ptr = convert_from_reference (ptr); | |
4966 | if (!POINTER_TYPE_P (TREE_TYPE (ptr))) | |
4967 | ptr = build_fold_addr_expr (ptr); | |
4968 | t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR, | |
4969 | ptrdiff_type_node, t, | |
4970 | fold_convert_loc (OMP_CLAUSE_LOCATION (c), | |
4971 | ptrdiff_type_node, ptr)); | |
4972 | OMP_CLAUSE_SIZE (c2) = t; | |
4973 | OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c); | |
4974 | OMP_CLAUSE_CHAIN (c) = c2; | |
4975 | ptr = OMP_CLAUSE_DECL (c2); | |
e01d41e5 | 4976 | if (OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER |
d9a6bd32 | 4977 | && TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE |
acf0174b JJ |
4978 | && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (ptr)))) |
4979 | { | |
4980 | tree c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), | |
4981 | OMP_CLAUSE_MAP); | |
e01d41e5 | 4982 | OMP_CLAUSE_SET_MAP_KIND (c3, OMP_CLAUSE_MAP_KIND (c2)); |
acf0174b | 4983 | OMP_CLAUSE_DECL (c3) = ptr; |
e01d41e5 JJ |
4984 | if (OMP_CLAUSE_MAP_KIND (c2) == GOMP_MAP_ALWAYS_POINTER) |
4985 | OMP_CLAUSE_DECL (c2) = build_simple_mem_ref (ptr); | |
4986 | else | |
4987 | OMP_CLAUSE_DECL (c2) = convert_from_reference (ptr); | |
acf0174b JJ |
4988 | OMP_CLAUSE_SIZE (c3) = size_zero_node; |
4989 | OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (c2); | |
4990 | OMP_CLAUSE_CHAIN (c2) = c3; | |
4991 | } | |
4992 | } | |
4993 | } | |
4994 | return false; | |
4995 | } | |
4996 | ||
4997 | /* Return identifier to look up for omp declare reduction. */ | |
4998 | ||
4999 | tree | |
5000 | omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type) | |
5001 | { | |
5002 | const char *p = NULL; | |
5003 | const char *m = NULL; | |
5004 | switch (reduction_code) | |
5005 | { | |
5006 | case PLUS_EXPR: | |
5007 | case MULT_EXPR: | |
5008 | case MINUS_EXPR: | |
5009 | case BIT_AND_EXPR: | |
5010 | case BIT_XOR_EXPR: | |
5011 | case BIT_IOR_EXPR: | |
5012 | case TRUTH_ANDIF_EXPR: | |
5013 | case TRUTH_ORIF_EXPR: | |
5014 | reduction_id = ansi_opname (reduction_code); | |
5015 | break; | |
5016 | case MIN_EXPR: | |
5017 | p = "min"; | |
5018 | break; | |
5019 | case MAX_EXPR: | |
5020 | p = "max"; | |
5021 | break; | |
5022 | default: | |
5023 | break; | |
5024 | } | |
5025 | ||
5026 | if (p == NULL) | |
5027 | { | |
5028 | if (TREE_CODE (reduction_id) != IDENTIFIER_NODE) | |
5029 | return error_mark_node; | |
5030 | p = IDENTIFIER_POINTER (reduction_id); | |
5031 | } | |
5032 | ||
5033 | if (type != NULL_TREE) | |
5034 | m = mangle_type_string (TYPE_MAIN_VARIANT (type)); | |
5035 | ||
5036 | const char prefix[] = "omp declare reduction "; | |
5037 | size_t lenp = sizeof (prefix); | |
5038 | if (strncmp (p, prefix, lenp - 1) == 0) | |
5039 | lenp = 1; | |
5040 | size_t len = strlen (p); | |
5041 | size_t lenm = m ? strlen (m) + 1 : 0; | |
5042 | char *name = XALLOCAVEC (char, lenp + len + lenm); | |
5043 | if (lenp > 1) | |
5044 | memcpy (name, prefix, lenp - 1); | |
5045 | memcpy (name + lenp - 1, p, len + 1); | |
5046 | if (m) | |
5047 | { | |
5048 | name[lenp + len - 1] = '~'; | |
5049 | memcpy (name + lenp + len, m, lenm); | |
5050 | } | |
5051 | return get_identifier (name); | |
5052 | } | |
5053 | ||
5054 | /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial | |
5055 | FUNCTION_DECL or NULL_TREE if not found. */ | |
5056 | ||
5057 | static tree | |
5058 | omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp, | |
5059 | vec<tree> *ambiguousp) | |
5060 | { | |
5061 | tree orig_id = id; | |
5062 | tree baselink = NULL_TREE; | |
5063 | if (identifier_p (id)) | |
5064 | { | |
5065 | cp_id_kind idk; | |
5066 | bool nonint_cst_expression_p; | |
5067 | const char *error_msg; | |
5068 | id = omp_reduction_id (ERROR_MARK, id, type); | |
5069 | tree decl = lookup_name (id); | |
5070 | if (decl == NULL_TREE) | |
5071 | decl = error_mark_node; | |
5072 | id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true, | |
5073 | &nonint_cst_expression_p, false, true, false, | |
5074 | false, &error_msg, loc); | |
5075 | if (idk == CP_ID_KIND_UNQUALIFIED | |
5076 | && identifier_p (id)) | |
5077 | { | |
5078 | vec<tree, va_gc> *args = NULL; | |
5079 | vec_safe_push (args, build_reference_type (type)); | |
cdc23b1b | 5080 | id = perform_koenig_lookup (id, args, tf_none); |
acf0174b JJ |
5081 | } |
5082 | } | |
5083 | else if (TREE_CODE (id) == SCOPE_REF) | |
5084 | id = lookup_qualified_name (TREE_OPERAND (id, 0), | |
5085 | omp_reduction_id (ERROR_MARK, | |
5086 | TREE_OPERAND (id, 1), | |
5087 | type), | |
5088 | false, false); | |
5089 | tree fns = id; | |
5090 | if (id && is_overloaded_fn (id)) | |
5091 | id = get_fns (id); | |
5092 | for (; id; id = OVL_NEXT (id)) | |
5093 | { | |
5094 | tree fndecl = OVL_CURRENT (id); | |
5095 | if (TREE_CODE (fndecl) == FUNCTION_DECL) | |
5096 | { | |
5097 | tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl))); | |
5098 | if (same_type_p (TREE_TYPE (argtype), type)) | |
5099 | break; | |
5100 | } | |
5101 | } | |
5102 | if (id && BASELINK_P (fns)) | |
5103 | { | |
5104 | if (baselinkp) | |
5105 | *baselinkp = fns; | |
5106 | else | |
5107 | baselink = fns; | |
5108 | } | |
5109 | if (id == NULL_TREE && CLASS_TYPE_P (type) && TYPE_BINFO (type)) | |
5110 | { | |
5111 | vec<tree> ambiguous = vNULL; | |
5112 | tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE; | |
5113 | unsigned int ix; | |
5114 | if (ambiguousp == NULL) | |
5115 | ambiguousp = &ambiguous; | |
5116 | for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++) | |
5117 | { | |
5118 | id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo), | |
5119 | baselinkp ? baselinkp : &baselink, | |
5120 | ambiguousp); | |
5121 | if (id == NULL_TREE) | |
5122 | continue; | |
5123 | if (!ambiguousp->is_empty ()) | |
5124 | ambiguousp->safe_push (id); | |
5125 | else if (ret != NULL_TREE) | |
5126 | { | |
5127 | ambiguousp->safe_push (ret); | |
5128 | ambiguousp->safe_push (id); | |
5129 | ret = NULL_TREE; | |
5130 | } | |
5131 | else | |
5132 | ret = id; | |
5133 | } | |
5134 | if (ambiguousp != &ambiguous) | |
5135 | return ret; | |
5136 | if (!ambiguous.is_empty ()) | |
5137 | { | |
5138 | const char *str = _("candidates are:"); | |
5139 | unsigned int idx; | |
5140 | tree udr; | |
5141 | error_at (loc, "user defined reduction lookup is ambiguous"); | |
5142 | FOR_EACH_VEC_ELT (ambiguous, idx, udr) | |
5143 | { | |
5144 | inform (DECL_SOURCE_LOCATION (udr), "%s %#D", str, udr); | |
5145 | if (idx == 0) | |
5146 | str = get_spaces (str); | |
5147 | } | |
5148 | ambiguous.release (); | |
5149 | ret = error_mark_node; | |
5150 | baselink = NULL_TREE; | |
5151 | } | |
5152 | id = ret; | |
5153 | } | |
5154 | if (id && baselink) | |
5155 | perform_or_defer_access_check (BASELINK_BINFO (baselink), | |
5156 | id, id, tf_warning_or_error); | |
5157 | return id; | |
5158 | } | |
5159 | ||
5160 | /* Helper function for cp_parser_omp_declare_reduction_exprs | |
5161 | and tsubst_omp_udr. | |
5162 | Remove CLEANUP_STMT for data (omp_priv variable). | |
5163 | Also append INIT_EXPR for DECL_INITIAL of omp_priv after its | |
5164 | DECL_EXPR. */ | |
5165 | ||
5166 | tree | |
5167 | cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data) | |
5168 | { | |
5169 | if (TYPE_P (*tp)) | |
5170 | *walk_subtrees = 0; | |
5171 | else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data) | |
5172 | *tp = CLEANUP_BODY (*tp); | |
5173 | else if (TREE_CODE (*tp) == DECL_EXPR) | |
5174 | { | |
5175 | tree decl = DECL_EXPR_DECL (*tp); | |
5176 | if (!processing_template_decl | |
5177 | && decl == (tree) data | |
5178 | && DECL_INITIAL (decl) | |
5179 | && DECL_INITIAL (decl) != error_mark_node) | |
5180 | { | |
5181 | tree list = NULL_TREE; | |
5182 | append_to_statement_list_force (*tp, &list); | |
5183 | tree init_expr = build2 (INIT_EXPR, void_type_node, | |
5184 | decl, DECL_INITIAL (decl)); | |
5185 | DECL_INITIAL (decl) = NULL_TREE; | |
5186 | append_to_statement_list_force (init_expr, &list); | |
5187 | *tp = list; | |
5188 | } | |
5189 | } | |
5190 | return NULL_TREE; | |
5191 | } | |
5192 | ||
5193 | /* Data passed from cp_check_omp_declare_reduction to | |
5194 | cp_check_omp_declare_reduction_r. */ | |
5195 | ||
5196 | struct cp_check_omp_declare_reduction_data | |
5197 | { | |
5198 | location_t loc; | |
5199 | tree stmts[7]; | |
5200 | bool combiner_p; | |
5201 | }; | |
5202 | ||
5203 | /* Helper function for cp_check_omp_declare_reduction, called via | |
5204 | cp_walk_tree. */ | |
5205 | ||
5206 | static tree | |
5207 | cp_check_omp_declare_reduction_r (tree *tp, int *, void *data) | |
5208 | { | |
5209 | struct cp_check_omp_declare_reduction_data *udr_data | |
5210 | = (struct cp_check_omp_declare_reduction_data *) data; | |
5211 | if (SSA_VAR_P (*tp) | |
5212 | && !DECL_ARTIFICIAL (*tp) | |
5213 | && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3]) | |
5214 | && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4])) | |
5215 | { | |
5216 | location_t loc = udr_data->loc; | |
5217 | if (udr_data->combiner_p) | |
5218 | error_at (loc, "%<#pragma omp declare reduction%> combiner refers to " | |
5219 | "variable %qD which is not %<omp_out%> nor %<omp_in%>", | |
5220 | *tp); | |
5221 | else | |
5222 | error_at (loc, "%<#pragma omp declare reduction%> initializer refers " | |
5223 | "to variable %qD which is not %<omp_priv%> nor " | |
5224 | "%<omp_orig%>", | |
5225 | *tp); | |
5226 | return *tp; | |
5227 | } | |
5228 | return NULL_TREE; | |
5229 | } | |
5230 | ||
5231 | /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */ | |
5232 | ||
5233 | void | |
5234 | cp_check_omp_declare_reduction (tree udr) | |
5235 | { | |
5236 | tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr))); | |
5237 | gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); | |
5238 | type = TREE_TYPE (type); | |
5239 | int i; | |
5240 | location_t loc = DECL_SOURCE_LOCATION (udr); | |
5241 | ||
5242 | if (type == error_mark_node) | |
5243 | return; | |
5244 | if (ARITHMETIC_TYPE_P (type)) | |
5245 | { | |
5246 | static enum tree_code predef_codes[] | |
5247 | = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR, | |
5248 | BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR }; | |
5249 | for (i = 0; i < 8; i++) | |
5250 | { | |
5251 | tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE); | |
5252 | const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr)); | |
5253 | const char *n2 = IDENTIFIER_POINTER (id); | |
5254 | if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0 | |
5255 | && (n1[IDENTIFIER_LENGTH (id)] == '~' | |
5256 | || n1[IDENTIFIER_LENGTH (id)] == '\0')) | |
5257 | break; | |
5258 | } | |
5259 | ||
5260 | if (i == 8 | |
5261 | && TREE_CODE (type) != COMPLEX_EXPR) | |
5262 | { | |
5263 | const char prefix_minmax[] = "omp declare reduction m"; | |
5264 | size_t prefix_size = sizeof (prefix_minmax) - 1; | |
5265 | const char *n = IDENTIFIER_POINTER (DECL_NAME (udr)); | |
5266 | if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)), | |
5267 | prefix_minmax, prefix_size) == 0 | |
5268 | && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n') | |
5269 | || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x')) | |
5270 | && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0')) | |
5271 | i = 0; | |
5272 | } | |
5273 | if (i < 8) | |
5274 | { | |
5275 | error_at (loc, "predeclared arithmetic type %qT in " | |
5276 | "%<#pragma omp declare reduction%>", type); | |
5277 | return; | |
5278 | } | |
5279 | } | |
5280 | else if (TREE_CODE (type) == FUNCTION_TYPE | |
5281 | || TREE_CODE (type) == METHOD_TYPE | |
5282 | || TREE_CODE (type) == ARRAY_TYPE) | |
5283 | { | |
5284 | error_at (loc, "function or array type %qT in " | |
5285 | "%<#pragma omp declare reduction%>", type); | |
5286 | return; | |
5287 | } | |
5288 | else if (TREE_CODE (type) == REFERENCE_TYPE) | |
5289 | { | |
5290 | error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>", | |
5291 | type); | |
5292 | return; | |
5293 | } | |
5294 | else if (TYPE_QUALS_NO_ADDR_SPACE (type)) | |
5295 | { | |
5296 | error_at (loc, "const, volatile or __restrict qualified type %qT in " | |
5297 | "%<#pragma omp declare reduction%>", type); | |
5298 | return; | |
5299 | } | |
5300 | ||
5301 | tree body = DECL_SAVED_TREE (udr); | |
5302 | if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST) | |
5303 | return; | |
5304 | ||
5305 | tree_stmt_iterator tsi; | |
5306 | struct cp_check_omp_declare_reduction_data data; | |
5307 | memset (data.stmts, 0, sizeof data.stmts); | |
5308 | for (i = 0, tsi = tsi_start (body); | |
5309 | i < 7 && !tsi_end_p (tsi); | |
5310 | i++, tsi_next (&tsi)) | |
5311 | data.stmts[i] = tsi_stmt (tsi); | |
5312 | data.loc = loc; | |
5313 | gcc_assert (tsi_end_p (tsi)); | |
5314 | if (i >= 3) | |
5315 | { | |
5316 | gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR | |
5317 | && TREE_CODE (data.stmts[1]) == DECL_EXPR); | |
5318 | if (TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0]))) | |
5319 | return; | |
5320 | data.combiner_p = true; | |
5321 | if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r, | |
5322 | &data, NULL)) | |
5323 | TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])) = 1; | |
5324 | } | |
5325 | if (i >= 6) | |
5326 | { | |
5327 | gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR | |
5328 | && TREE_CODE (data.stmts[4]) == DECL_EXPR); | |
5329 | data.combiner_p = false; | |
5330 | if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r, | |
5331 | &data, NULL) | |
5332 | || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])), | |
5333 | cp_check_omp_declare_reduction_r, &data, NULL)) | |
5334 | TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])) = 1; | |
5335 | if (i == 7) | |
5336 | gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR); | |
5337 | } | |
5338 | } | |
5339 | ||
5340 | /* Helper function of finish_omp_clauses. Clone STMT as if we were making | |
5341 | an inline call. But, remap | |
5342 | the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER | |
5343 | and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */ | |
5344 | ||
5345 | static tree | |
5346 | clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2, | |
5347 | tree decl, tree placeholder) | |
5348 | { | |
5349 | copy_body_data id; | |
b787e7a2 | 5350 | hash_map<tree, tree> decl_map; |
acf0174b | 5351 | |
b787e7a2 TS |
5352 | decl_map.put (omp_decl1, placeholder); |
5353 | decl_map.put (omp_decl2, decl); | |
acf0174b JJ |
5354 | memset (&id, 0, sizeof (id)); |
5355 | id.src_fn = DECL_CONTEXT (omp_decl1); | |
5356 | id.dst_fn = current_function_decl; | |
5357 | id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn); | |
b787e7a2 | 5358 | id.decl_map = &decl_map; |
acf0174b JJ |
5359 | |
5360 | id.copy_decl = copy_decl_no_change; | |
5361 | id.transform_call_graph_edges = CB_CGE_DUPLICATE; | |
5362 | id.transform_new_cfg = true; | |
5363 | id.transform_return_to_modify = false; | |
5364 | id.transform_lang_insert_block = NULL; | |
5365 | id.eh_lp_nr = 0; | |
5366 | walk_tree (&stmt, copy_tree_body_r, &id, NULL); | |
acf0174b JJ |
5367 | return stmt; |
5368 | } | |
5369 | ||
5370 | /* Helper function of finish_omp_clauses, called via cp_walk_tree. | |
5371 | Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */ | |
5372 | ||
5373 | static tree | |
5374 | find_omp_placeholder_r (tree *tp, int *, void *data) | |
5375 | { | |
5376 | if (*tp == (tree) data) | |
5377 | return *tp; | |
5378 | return NULL_TREE; | |
5379 | } | |
5380 | ||
5381 | /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C. | |
5382 | Return true if there is some error and the clause should be removed. */ | |
5383 | ||
5384 | static bool | |
5385 | finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) | |
5386 | { | |
5387 | tree t = OMP_CLAUSE_DECL (c); | |
5388 | bool predefined = false; | |
d9a6bd32 JJ |
5389 | if (TREE_CODE (t) == TREE_LIST) |
5390 | { | |
5391 | gcc_assert (processing_template_decl); | |
5392 | return false; | |
5393 | } | |
acf0174b | 5394 | tree type = TREE_TYPE (t); |
d9a6bd32 JJ |
5395 | if (TREE_CODE (t) == MEM_REF) |
5396 | type = TREE_TYPE (type); | |
acf0174b JJ |
5397 | if (TREE_CODE (type) == REFERENCE_TYPE) |
5398 | type = TREE_TYPE (type); | |
d9a6bd32 JJ |
5399 | if (TREE_CODE (type) == ARRAY_TYPE) |
5400 | { | |
5401 | tree oatype = type; | |
5402 | gcc_assert (TREE_CODE (t) != MEM_REF); | |
5403 | while (TREE_CODE (type) == ARRAY_TYPE) | |
5404 | type = TREE_TYPE (type); | |
5405 | if (!processing_template_decl) | |
5406 | { | |
5407 | t = require_complete_type (t); | |
5408 | if (t == error_mark_node) | |
5409 | return true; | |
5410 | tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype), | |
5411 | TYPE_SIZE_UNIT (type)); | |
5412 | if (integer_zerop (size)) | |
5413 | { | |
5414 | error ("%qE in %<reduction%> clause is a zero size array", | |
5415 | omp_clause_printable_decl (t)); | |
5416 | return true; | |
5417 | } | |
5418 | size = size_binop (MINUS_EXPR, size, size_one_node); | |
5419 | tree index_type = build_index_type (size); | |
5420 | tree atype = build_array_type (type, index_type); | |
5421 | tree ptype = build_pointer_type (type); | |
5422 | if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) | |
5423 | t = build_fold_addr_expr (t); | |
5424 | t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0)); | |
5425 | OMP_CLAUSE_DECL (c) = t; | |
5426 | } | |
5427 | } | |
4ca56230 PC |
5428 | if (type == error_mark_node) |
5429 | return true; | |
5430 | else if (ARITHMETIC_TYPE_P (type)) | |
acf0174b JJ |
5431 | switch (OMP_CLAUSE_REDUCTION_CODE (c)) |
5432 | { | |
5433 | case PLUS_EXPR: | |
5434 | case MULT_EXPR: | |
5435 | case MINUS_EXPR: | |
5436 | predefined = true; | |
5437 | break; | |
5438 | case MIN_EXPR: | |
5439 | case MAX_EXPR: | |
5440 | if (TREE_CODE (type) == COMPLEX_TYPE) | |
5441 | break; | |
5442 | predefined = true; | |
5443 | break; | |
5444 | case BIT_AND_EXPR: | |
5445 | case BIT_IOR_EXPR: | |
5446 | case BIT_XOR_EXPR: | |
652fea39 JJ |
5447 | if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE) |
5448 | break; | |
5449 | predefined = true; | |
5450 | break; | |
acf0174b JJ |
5451 | case TRUTH_ANDIF_EXPR: |
5452 | case TRUTH_ORIF_EXPR: | |
5453 | if (FLOAT_TYPE_P (type)) | |
5454 | break; | |
5455 | predefined = true; | |
5456 | break; | |
5457 | default: | |
5458 | break; | |
5459 | } | |
d9a6bd32 | 5460 | else if (TYPE_READONLY (type)) |
acf0174b | 5461 | { |
d9a6bd32 JJ |
5462 | error ("%qE has const type for %<reduction%>", |
5463 | omp_clause_printable_decl (t)); | |
acf0174b JJ |
5464 | return true; |
5465 | } | |
5466 | else if (!processing_template_decl) | |
5467 | { | |
5468 | t = require_complete_type (t); | |
5469 | if (t == error_mark_node) | |
5470 | return true; | |
5471 | OMP_CLAUSE_DECL (c) = t; | |
5472 | } | |
5473 | ||
5474 | if (predefined) | |
5475 | { | |
5476 | OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE; | |
5477 | return false; | |
5478 | } | |
5479 | else if (processing_template_decl) | |
5480 | return false; | |
5481 | ||
5482 | tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c); | |
5483 | ||
d9a6bd32 | 5484 | type = TYPE_MAIN_VARIANT (type); |
acf0174b JJ |
5485 | OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE; |
5486 | if (id == NULL_TREE) | |
5487 | id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c), | |
5488 | NULL_TREE, NULL_TREE); | |
5489 | id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL); | |
5490 | if (id) | |
5491 | { | |
5492 | if (id == error_mark_node) | |
5493 | return true; | |
5494 | id = OVL_CURRENT (id); | |
5495 | mark_used (id); | |
5496 | tree body = DECL_SAVED_TREE (id); | |
88957d5e PC |
5497 | if (!body) |
5498 | return true; | |
acf0174b JJ |
5499 | if (TREE_CODE (body) == STATEMENT_LIST) |
5500 | { | |
5501 | tree_stmt_iterator tsi; | |
d9a6bd32 | 5502 | tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE; |
acf0174b JJ |
5503 | int i; |
5504 | tree stmts[7]; | |
5505 | tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id))); | |
5506 | atype = TREE_TYPE (atype); | |
5507 | bool need_static_cast = !same_type_p (type, atype); | |
5508 | memset (stmts, 0, sizeof stmts); | |
5509 | for (i = 0, tsi = tsi_start (body); | |
5510 | i < 7 && !tsi_end_p (tsi); | |
5511 | i++, tsi_next (&tsi)) | |
5512 | stmts[i] = tsi_stmt (tsi); | |
5513 | gcc_assert (tsi_end_p (tsi)); | |
5514 | ||
5515 | if (i >= 3) | |
5516 | { | |
5517 | gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR | |
5518 | && TREE_CODE (stmts[1]) == DECL_EXPR); | |
5519 | placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type); | |
5520 | DECL_ARTIFICIAL (placeholder) = 1; | |
5521 | DECL_IGNORED_P (placeholder) = 1; | |
5522 | OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder; | |
d9a6bd32 JJ |
5523 | if (TREE_CODE (t) == MEM_REF) |
5524 | { | |
5525 | decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE, | |
5526 | type); | |
5527 | DECL_ARTIFICIAL (decl_placeholder) = 1; | |
5528 | DECL_IGNORED_P (decl_placeholder) = 1; | |
5529 | OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder; | |
5530 | } | |
acf0174b JJ |
5531 | if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0]))) |
5532 | cxx_mark_addressable (placeholder); | |
5533 | if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1])) | |
5534 | && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) | |
5535 | != REFERENCE_TYPE) | |
d9a6bd32 JJ |
5536 | cxx_mark_addressable (decl_placeholder ? decl_placeholder |
5537 | : OMP_CLAUSE_DECL (c)); | |
acf0174b | 5538 | tree omp_out = placeholder; |
d9a6bd32 JJ |
5539 | tree omp_in = decl_placeholder ? decl_placeholder |
5540 | : convert_from_reference (OMP_CLAUSE_DECL (c)); | |
acf0174b JJ |
5541 | if (need_static_cast) |
5542 | { | |
5543 | tree rtype = build_reference_type (atype); | |
5544 | omp_out = build_static_cast (rtype, omp_out, | |
5545 | tf_warning_or_error); | |
5546 | omp_in = build_static_cast (rtype, omp_in, | |
5547 | tf_warning_or_error); | |
5548 | if (omp_out == error_mark_node || omp_in == error_mark_node) | |
5549 | return true; | |
5550 | omp_out = convert_from_reference (omp_out); | |
5551 | omp_in = convert_from_reference (omp_in); | |
5552 | } | |
5553 | OMP_CLAUSE_REDUCTION_MERGE (c) | |
5554 | = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]), | |
5555 | DECL_EXPR_DECL (stmts[1]), omp_in, omp_out); | |
5556 | } | |
5557 | if (i >= 6) | |
5558 | { | |
5559 | gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR | |
5560 | && TREE_CODE (stmts[4]) == DECL_EXPR); | |
5561 | if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))) | |
d9a6bd32 JJ |
5562 | cxx_mark_addressable (decl_placeholder ? decl_placeholder |
5563 | : OMP_CLAUSE_DECL (c)); | |
acf0174b JJ |
5564 | if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4]))) |
5565 | cxx_mark_addressable (placeholder); | |
d9a6bd32 JJ |
5566 | tree omp_priv = decl_placeholder ? decl_placeholder |
5567 | : convert_from_reference (OMP_CLAUSE_DECL (c)); | |
acf0174b JJ |
5568 | tree omp_orig = placeholder; |
5569 | if (need_static_cast) | |
5570 | { | |
5571 | if (i == 7) | |
5572 | { | |
5573 | error_at (OMP_CLAUSE_LOCATION (c), | |
5574 | "user defined reduction with constructor " | |
5575 | "initializer for base class %qT", atype); | |
5576 | return true; | |
5577 | } | |
5578 | tree rtype = build_reference_type (atype); | |
5579 | omp_priv = build_static_cast (rtype, omp_priv, | |
5580 | tf_warning_or_error); | |
5581 | omp_orig = build_static_cast (rtype, omp_orig, | |
5582 | tf_warning_or_error); | |
5583 | if (omp_priv == error_mark_node | |
5584 | || omp_orig == error_mark_node) | |
5585 | return true; | |
5586 | omp_priv = convert_from_reference (omp_priv); | |
5587 | omp_orig = convert_from_reference (omp_orig); | |
5588 | } | |
5589 | if (i == 6) | |
5590 | *need_default_ctor = true; | |
5591 | OMP_CLAUSE_REDUCTION_INIT (c) | |
5592 | = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]), | |
5593 | DECL_EXPR_DECL (stmts[3]), | |
5594 | omp_priv, omp_orig); | |
5595 | if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c), | |
5596 | find_omp_placeholder_r, placeholder, NULL)) | |
5597 | OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1; | |
5598 | } | |
5599 | else if (i >= 3) | |
5600 | { | |
5601 | if (CLASS_TYPE_P (type) && !pod_type_p (type)) | |
5602 | *need_default_ctor = true; | |
5603 | else | |
5604 | { | |
5605 | tree init; | |
d9a6bd32 JJ |
5606 | tree v = decl_placeholder ? decl_placeholder |
5607 | : convert_from_reference (t); | |
acf0174b JJ |
5608 | if (AGGREGATE_TYPE_P (TREE_TYPE (v))) |
5609 | init = build_constructor (TREE_TYPE (v), NULL); | |
5610 | else | |
5611 | init = fold_convert (TREE_TYPE (v), integer_zero_node); | |
5612 | OMP_CLAUSE_REDUCTION_INIT (c) | |
5613 | = build2 (INIT_EXPR, TREE_TYPE (v), v, init); | |
5614 | } | |
5615 | } | |
5616 | } | |
5617 | } | |
5618 | if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c)) | |
5619 | *need_dtor = true; | |
5620 | else | |
5621 | { | |
d9a6bd32 JJ |
5622 | error ("user defined reduction not found for %qE", |
5623 | omp_clause_printable_decl (t)); | |
acf0174b JJ |
5624 | return true; |
5625 | } | |
d9a6bd32 JJ |
5626 | if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF) |
5627 | gcc_assert (TYPE_SIZE_UNIT (type) | |
5628 | && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST); | |
5629 | return false; | |
5630 | } | |
5631 | ||
5632 | /* Called from finish_struct_1. linear(this) or linear(this:step) | |
5633 | clauses might not be finalized yet because the class has been incomplete | |
5634 | when parsing #pragma omp declare simd methods. Fix those up now. */ | |
5635 | ||
5636 | void | |
5637 | finish_omp_declare_simd_methods (tree t) | |
5638 | { | |
5639 | if (processing_template_decl) | |
5640 | return; | |
5641 | ||
5642 | for (tree x = TYPE_METHODS (t); x; x = DECL_CHAIN (x)) | |
5643 | { | |
5644 | if (TREE_CODE (TREE_TYPE (x)) != METHOD_TYPE) | |
5645 | continue; | |
5646 | tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x)); | |
5647 | if (!ods || !TREE_VALUE (ods)) | |
5648 | continue; | |
5649 | for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c)) | |
5650 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR | |
5651 | && integer_zerop (OMP_CLAUSE_DECL (c)) | |
5652 | && OMP_CLAUSE_LINEAR_STEP (c) | |
5653 | && TREE_CODE (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))) | |
5654 | == POINTER_TYPE) | |
5655 | { | |
5656 | tree s = OMP_CLAUSE_LINEAR_STEP (c); | |
5657 | s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s); | |
5658 | s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR, | |
5659 | sizetype, s, TYPE_SIZE_UNIT (t)); | |
5660 | OMP_CLAUSE_LINEAR_STEP (c) = s; | |
5661 | } | |
5662 | } | |
5663 | } | |
5664 | ||
5665 | /* Adjust sink depend clause to take into account pointer offsets. | |
5666 | ||
5667 | Return TRUE if there was a problem processing the offset, and the | |
5668 | whole clause should be removed. */ | |
5669 | ||
5670 | static bool | |
5671 | cp_finish_omp_clause_depend_sink (tree sink_clause) | |
5672 | { | |
5673 | tree t = OMP_CLAUSE_DECL (sink_clause); | |
5674 | gcc_assert (TREE_CODE (t) == TREE_LIST); | |
5675 | ||
5676 | /* Make sure we don't adjust things twice for templates. */ | |
5677 | if (processing_template_decl) | |
5678 | return false; | |
5679 | ||
5680 | for (; t; t = TREE_CHAIN (t)) | |
5681 | { | |
5682 | tree decl = TREE_VALUE (t); | |
5683 | if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE) | |
5684 | { | |
5685 | tree offset = TREE_PURPOSE (t); | |
5686 | bool neg = wi::neg_p ((wide_int) offset); | |
5687 | offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset); | |
5688 | decl = mark_rvalue_use (decl); | |
5689 | decl = convert_from_reference (decl); | |
5690 | tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause), | |
5691 | neg ? MINUS_EXPR : PLUS_EXPR, | |
5692 | decl, offset); | |
5693 | t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause), | |
a8fc2579 RB |
5694 | MINUS_EXPR, sizetype, |
5695 | fold_convert (sizetype, t2), | |
5696 | fold_convert (sizetype, decl)); | |
d9a6bd32 JJ |
5697 | if (t2 == error_mark_node) |
5698 | return true; | |
5699 | TREE_PURPOSE (t) = t2; | |
5700 | } | |
5701 | } | |
acf0174b JJ |
5702 | return false; |
5703 | } | |
5704 | ||
1799e5d5 RH |
5705 | /* For all elements of CLAUSES, validate them vs OpenMP constraints. |
5706 | Remove any elements from the list that are invalid. */ | |
5707 | ||
5708 | tree | |
d9a6bd32 | 5709 | finish_omp_clauses (tree clauses, bool allow_fields, bool declare_simd) |
1799e5d5 RH |
5710 | { |
5711 | bitmap_head generic_head, firstprivate_head, lastprivate_head; | |
e01d41e5 | 5712 | bitmap_head aligned_head, map_head, map_field_head; |
f3316c6d | 5713 | tree c, t, *pc; |
d9a6bd32 | 5714 | tree safelen = NULL_TREE; |
acf0174b JJ |
5715 | bool branch_seen = false; |
5716 | bool copyprivate_seen = false; | |
e01d41e5 | 5717 | bool ordered_seen = false; |
1799e5d5 RH |
5718 | |
5719 | bitmap_obstack_initialize (NULL); | |
5720 | bitmap_initialize (&generic_head, &bitmap_default_obstack); | |
5721 | bitmap_initialize (&firstprivate_head, &bitmap_default_obstack); | |
5722 | bitmap_initialize (&lastprivate_head, &bitmap_default_obstack); | |
acf0174b | 5723 | bitmap_initialize (&aligned_head, &bitmap_default_obstack); |
d9a6bd32 JJ |
5724 | bitmap_initialize (&map_head, &bitmap_default_obstack); |
5725 | bitmap_initialize (&map_field_head, &bitmap_default_obstack); | |
1799e5d5 RH |
5726 | |
5727 | for (pc = &clauses, c = clauses; c ; c = *pc) | |
5728 | { | |
5729 | bool remove = false; | |
d9a6bd32 | 5730 | bool field_ok = false; |
1799e5d5 RH |
5731 | |
5732 | switch (OMP_CLAUSE_CODE (c)) | |
5733 | { | |
5734 | case OMP_CLAUSE_SHARED: | |
e01d41e5 | 5735 | field_ok = allow_fields; |
1799e5d5 RH |
5736 | goto check_dup_generic; |
5737 | case OMP_CLAUSE_PRIVATE: | |
d9a6bd32 | 5738 | field_ok = allow_fields; |
1799e5d5 RH |
5739 | goto check_dup_generic; |
5740 | case OMP_CLAUSE_REDUCTION: | |
d9a6bd32 JJ |
5741 | field_ok = allow_fields; |
5742 | t = OMP_CLAUSE_DECL (c); | |
5743 | if (TREE_CODE (t) == TREE_LIST) | |
5744 | { | |
5745 | if (handle_omp_array_sections (c, allow_fields)) | |
5746 | { | |
5747 | remove = true; | |
5748 | break; | |
5749 | } | |
5750 | if (TREE_CODE (t) == TREE_LIST) | |
5751 | { | |
5752 | while (TREE_CODE (t) == TREE_LIST) | |
5753 | t = TREE_CHAIN (t); | |
5754 | } | |
5755 | else | |
5756 | { | |
5757 | gcc_assert (TREE_CODE (t) == MEM_REF); | |
5758 | t = TREE_OPERAND (t, 0); | |
e01d41e5 JJ |
5759 | if (TREE_CODE (t) == POINTER_PLUS_EXPR) |
5760 | t = TREE_OPERAND (t, 0); | |
d9a6bd32 JJ |
5761 | if (TREE_CODE (t) == ADDR_EXPR |
5762 | || TREE_CODE (t) == INDIRECT_REF) | |
5763 | t = TREE_OPERAND (t, 0); | |
5764 | } | |
5765 | tree n = omp_clause_decl_field (t); | |
5766 | if (n) | |
5767 | t = n; | |
5768 | goto check_dup_generic_t; | |
5769 | } | |
1799e5d5 RH |
5770 | goto check_dup_generic; |
5771 | case OMP_CLAUSE_COPYPRIVATE: | |
acf0174b | 5772 | copyprivate_seen = true; |
d9a6bd32 | 5773 | field_ok = allow_fields; |
1799e5d5 RH |
5774 | goto check_dup_generic; |
5775 | case OMP_CLAUSE_COPYIN: | |
acf0174b JJ |
5776 | goto check_dup_generic; |
5777 | case OMP_CLAUSE_LINEAR: | |
d9a6bd32 | 5778 | field_ok = allow_fields; |
acf0174b | 5779 | t = OMP_CLAUSE_DECL (c); |
d9a6bd32 JJ |
5780 | if (!declare_simd |
5781 | && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT) | |
5782 | { | |
5783 | error_at (OMP_CLAUSE_LOCATION (c), | |
5784 | "modifier should not be specified in %<linear%> " | |
5785 | "clause on %<simd%> or %<for%> constructs"); | |
5786 | OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT; | |
5787 | } | |
7da8534d | 5788 | if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL) |
d9a6bd32 | 5789 | && !type_dependent_expression_p (t)) |
acf0174b | 5790 | { |
d9a6bd32 JJ |
5791 | tree type = TREE_TYPE (t); |
5792 | if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF | |
5793 | || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL) | |
5794 | && TREE_CODE (type) != REFERENCE_TYPE) | |
5795 | { | |
5796 | error ("linear clause with %qs modifier applied to " | |
5797 | "non-reference variable with %qT type", | |
5798 | OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF | |
5799 | ? "ref" : "uval", TREE_TYPE (t)); | |
5800 | remove = true; | |
5801 | break; | |
5802 | } | |
5803 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
5804 | type = TREE_TYPE (type); | |
5805 | if (!INTEGRAL_TYPE_P (type) | |
5806 | && TREE_CODE (type) != POINTER_TYPE) | |
5807 | { | |
5808 | error ("linear clause applied to non-integral non-pointer " | |
5809 | "variable with %qT type", TREE_TYPE (t)); | |
5810 | remove = true; | |
5811 | break; | |
5812 | } | |
acf0174b JJ |
5813 | } |
5814 | t = OMP_CLAUSE_LINEAR_STEP (c); | |
5815 | if (t == NULL_TREE) | |
5816 | t = integer_one_node; | |
5817 | if (t == error_mark_node) | |
ee1d5a02 JJ |
5818 | { |
5819 | remove = true; | |
5820 | break; | |
5821 | } | |
acf0174b | 5822 | else if (!type_dependent_expression_p (t) |
e01d41e5 JJ |
5823 | && !INTEGRAL_TYPE_P (TREE_TYPE (t)) |
5824 | && (!declare_simd | |
5825 | || TREE_CODE (t) != PARM_DECL | |
5826 | || TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE | |
5827 | || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t))))) | |
acf0174b JJ |
5828 | { |
5829 | error ("linear step expression must be integral"); | |
5830 | remove = true; | |
ee1d5a02 | 5831 | break; |
acf0174b JJ |
5832 | } |
5833 | else | |
5834 | { | |
5835 | t = mark_rvalue_use (t); | |
e01d41e5 JJ |
5836 | if (declare_simd && TREE_CODE (t) == PARM_DECL) |
5837 | { | |
5838 | OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1; | |
5839 | goto check_dup_generic; | |
5840 | } | |
7da8534d JJ |
5841 | if (!processing_template_decl |
5842 | && (VAR_P (OMP_CLAUSE_DECL (c)) | |
5843 | || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL)) | |
acf0174b | 5844 | { |
e01d41e5 JJ |
5845 | if (declare_simd) |
5846 | { | |
5847 | t = maybe_constant_value (t); | |
5848 | if (TREE_CODE (t) != INTEGER_CST) | |
5849 | { | |
5850 | error_at (OMP_CLAUSE_LOCATION (c), | |
5851 | "%<linear%> clause step %qE is neither " | |
5852 | "constant nor a parameter", t); | |
5853 | remove = true; | |
5854 | break; | |
5855 | } | |
5856 | } | |
acf0174b | 5857 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); |
d9a6bd32 JJ |
5858 | tree type = TREE_TYPE (OMP_CLAUSE_DECL (c)); |
5859 | if (TREE_CODE (type) == REFERENCE_TYPE) | |
5860 | type = TREE_TYPE (type); | |
5861 | if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF) | |
5862 | { | |
5863 | type = build_pointer_type (type); | |
5864 | tree d = fold_convert (type, OMP_CLAUSE_DECL (c)); | |
5865 | t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR, | |
5866 | d, t); | |
5867 | t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), | |
a8fc2579 RB |
5868 | MINUS_EXPR, sizetype, |
5869 | fold_convert (sizetype, t), | |
5870 | fold_convert (sizetype, d)); | |
d9a6bd32 JJ |
5871 | if (t == error_mark_node) |
5872 | { | |
5873 | remove = true; | |
5874 | break; | |
5875 | } | |
5876 | } | |
5877 | else if (TREE_CODE (type) == POINTER_TYPE | |
5878 | /* Can't multiply the step yet if *this | |
5879 | is still incomplete type. */ | |
5880 | && (!declare_simd | |
5881 | || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL | |
5882 | || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c)) | |
5883 | || DECL_NAME (OMP_CLAUSE_DECL (c)) | |
5884 | != this_identifier | |
5885 | || !TYPE_BEING_DEFINED (TREE_TYPE (type)))) | |
acf0174b | 5886 | { |
d9a6bd32 | 5887 | tree d = convert_from_reference (OMP_CLAUSE_DECL (c)); |
acf0174b | 5888 | t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR, |
d9a6bd32 | 5889 | d, t); |
acf0174b | 5890 | t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), |
a8fc2579 RB |
5891 | MINUS_EXPR, sizetype, |
5892 | fold_convert (sizetype, t), | |
5893 | fold_convert (sizetype, d)); | |
acf0174b | 5894 | if (t == error_mark_node) |
ee1d5a02 JJ |
5895 | { |
5896 | remove = true; | |
5897 | break; | |
5898 | } | |
acf0174b | 5899 | } |
da6f124d | 5900 | else |
d9a6bd32 | 5901 | t = fold_convert (type, t); |
acf0174b JJ |
5902 | } |
5903 | OMP_CLAUSE_LINEAR_STEP (c) = t; | |
5904 | } | |
1799e5d5 RH |
5905 | goto check_dup_generic; |
5906 | check_dup_generic: | |
d9a6bd32 JJ |
5907 | t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); |
5908 | if (t) | |
5909 | { | |
e01d41e5 | 5910 | if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED) |
d9a6bd32 JJ |
5911 | omp_note_field_privatization (t, OMP_CLAUSE_DECL (c)); |
5912 | } | |
5913 | else | |
5914 | t = OMP_CLAUSE_DECL (c); | |
5915 | check_dup_generic_t: | |
5916 | if (t == current_class_ptr | |
5917 | && (!declare_simd | |
5918 | || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR | |
5919 | && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM))) | |
5920 | { | |
5921 | error ("%<this%> allowed in OpenMP only in %<declare simd%>" | |
5922 | " clauses"); | |
5923 | remove = true; | |
5924 | break; | |
5925 | } | |
5926 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL | |
5927 | && (!field_ok || TREE_CODE (t) != FIELD_DECL)) | |
1799e5d5 RH |
5928 | { |
5929 | if (processing_template_decl) | |
5930 | break; | |
76dc15d4 | 5931 | if (DECL_P (t)) |
acf0174b JJ |
5932 | error ("%qD is not a variable in clause %qs", t, |
5933 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
76dc15d4 | 5934 | else |
acf0174b JJ |
5935 | error ("%qE is not a variable in clause %qs", t, |
5936 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
1799e5d5 RH |
5937 | remove = true; |
5938 | } | |
5939 | else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
5940 | || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) | |
5941 | || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) | |
5942 | { | |
76dc15d4 | 5943 | error ("%qD appears more than once in data clauses", t); |
1799e5d5 RH |
5944 | remove = true; |
5945 | } | |
e01d41e5 JJ |
5946 | else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE |
5947 | && bitmap_bit_p (&map_head, DECL_UID (t))) | |
5948 | { | |
5949 | error ("%qD appears both in data and map clauses", t); | |
5950 | remove = true; | |
5951 | } | |
1799e5d5 RH |
5952 | else |
5953 | bitmap_set_bit (&generic_head, DECL_UID (t)); | |
d9a6bd32 JJ |
5954 | if (!field_ok) |
5955 | break; | |
5956 | handle_field_decl: | |
5957 | if (!remove | |
5958 | && TREE_CODE (t) == FIELD_DECL | |
5959 | && t == OMP_CLAUSE_DECL (c)) | |
5960 | { | |
e01d41e5 JJ |
5961 | OMP_CLAUSE_DECL (c) |
5962 | = omp_privatize_field (t, (OMP_CLAUSE_CODE (c) | |
5963 | == OMP_CLAUSE_SHARED)); | |
d9a6bd32 JJ |
5964 | if (OMP_CLAUSE_DECL (c) == error_mark_node) |
5965 | remove = true; | |
5966 | } | |
1799e5d5 RH |
5967 | break; |
5968 | ||
5969 | case OMP_CLAUSE_FIRSTPRIVATE: | |
d9a6bd32 JJ |
5970 | t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); |
5971 | if (t) | |
5972 | omp_note_field_privatization (t, OMP_CLAUSE_DECL (c)); | |
5973 | else | |
5974 | t = OMP_CLAUSE_DECL (c); | |
5975 | if (t == current_class_ptr) | |
5976 | { | |
5977 | error ("%<this%> allowed in OpenMP only in %<declare simd%>" | |
5978 | " clauses"); | |
5979 | remove = true; | |
5980 | break; | |
5981 | } | |
5982 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL | |
5983 | && (!allow_fields || TREE_CODE (t) != FIELD_DECL)) | |
1799e5d5 RH |
5984 | { |
5985 | if (processing_template_decl) | |
5986 | break; | |
85b20612 JJ |
5987 | if (DECL_P (t)) |
5988 | error ("%qD is not a variable in clause %<firstprivate%>", t); | |
5989 | else | |
5990 | error ("%qE is not a variable in clause %<firstprivate%>", t); | |
1799e5d5 RH |
5991 | remove = true; |
5992 | } | |
5993 | else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
5994 | || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) | |
5995 | { | |
85b20612 | 5996 | error ("%qD appears more than once in data clauses", t); |
1799e5d5 RH |
5997 | remove = true; |
5998 | } | |
e01d41e5 JJ |
5999 | else if (bitmap_bit_p (&map_head, DECL_UID (t))) |
6000 | { | |
6001 | error ("%qD appears both in data and map clauses", t); | |
6002 | remove = true; | |
6003 | } | |
1799e5d5 RH |
6004 | else |
6005 | bitmap_set_bit (&firstprivate_head, DECL_UID (t)); | |
d9a6bd32 | 6006 | goto handle_field_decl; |
1799e5d5 RH |
6007 | |
6008 | case OMP_CLAUSE_LASTPRIVATE: | |
d9a6bd32 JJ |
6009 | t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); |
6010 | if (t) | |
6011 | omp_note_field_privatization (t, OMP_CLAUSE_DECL (c)); | |
6012 | else | |
6013 | t = OMP_CLAUSE_DECL (c); | |
6014 | if (t == current_class_ptr) | |
6015 | { | |
6016 | error ("%<this%> allowed in OpenMP only in %<declare simd%>" | |
6017 | " clauses"); | |
6018 | remove = true; | |
6019 | break; | |
6020 | } | |
6021 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL | |
6022 | && (!allow_fields || TREE_CODE (t) != FIELD_DECL)) | |
1799e5d5 RH |
6023 | { |
6024 | if (processing_template_decl) | |
6025 | break; | |
85b20612 JJ |
6026 | if (DECL_P (t)) |
6027 | error ("%qD is not a variable in clause %<lastprivate%>", t); | |
6028 | else | |
6029 | error ("%qE is not a variable in clause %<lastprivate%>", t); | |
1799e5d5 RH |
6030 | remove = true; |
6031 | } | |
6032 | else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
6033 | || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) | |
6034 | { | |
85b20612 | 6035 | error ("%qD appears more than once in data clauses", t); |
1799e5d5 RH |
6036 | remove = true; |
6037 | } | |
6038 | else | |
6039 | bitmap_set_bit (&lastprivate_head, DECL_UID (t)); | |
d9a6bd32 | 6040 | goto handle_field_decl; |
1799e5d5 RH |
6041 | |
6042 | case OMP_CLAUSE_IF: | |
6043 | t = OMP_CLAUSE_IF_EXPR (c); | |
6044 | t = maybe_convert_cond (t); | |
6045 | if (t == error_mark_node) | |
6046 | remove = true; | |
b848354b JJ |
6047 | else if (!processing_template_decl) |
6048 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
1799e5d5 RH |
6049 | OMP_CLAUSE_IF_EXPR (c) = t; |
6050 | break; | |
6051 | ||
20906c66 JJ |
6052 | case OMP_CLAUSE_FINAL: |
6053 | t = OMP_CLAUSE_FINAL_EXPR (c); | |
6054 | t = maybe_convert_cond (t); | |
6055 | if (t == error_mark_node) | |
6056 | remove = true; | |
b848354b JJ |
6057 | else if (!processing_template_decl) |
6058 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
20906c66 JJ |
6059 | OMP_CLAUSE_FINAL_EXPR (c) = t; |
6060 | break; | |
6061 | ||
0d077441 NS |
6062 | case OMP_CLAUSE_GANG: |
6063 | /* Operand 1 is the gang static: argument. */ | |
6064 | t = OMP_CLAUSE_OPERAND (c, 1); | |
6065 | if (t != NULL_TREE) | |
6066 | { | |
6067 | if (t == error_mark_node) | |
6068 | remove = true; | |
6069 | else if (!type_dependent_expression_p (t) | |
6070 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6071 | { | |
6072 | error ("%<gang%> static expression must be integral"); | |
6073 | remove = true; | |
6074 | } | |
6075 | else | |
6076 | { | |
6077 | t = mark_rvalue_use (t); | |
6078 | if (!processing_template_decl) | |
6079 | { | |
6080 | t = maybe_constant_value (t); | |
6081 | if (TREE_CODE (t) == INTEGER_CST | |
6082 | && tree_int_cst_sgn (t) != 1 | |
6083 | && t != integer_minus_one_node) | |
6084 | { | |
6085 | warning_at (OMP_CLAUSE_LOCATION (c), 0, | |
6086 | "%<gang%> static value must be" | |
6087 | "positive"); | |
6088 | t = integer_one_node; | |
6089 | } | |
6090 | } | |
6091 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6092 | } | |
6093 | OMP_CLAUSE_OPERAND (c, 1) = t; | |
6094 | } | |
6095 | /* Check operand 0, the num argument. */ | |
6096 | ||
6097 | case OMP_CLAUSE_WORKER: | |
6098 | case OMP_CLAUSE_VECTOR: | |
6099 | if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE) | |
6100 | break; | |
6101 | ||
6102 | case OMP_CLAUSE_NUM_TASKS: | |
6103 | case OMP_CLAUSE_NUM_TEAMS: | |
1799e5d5 | 6104 | case OMP_CLAUSE_NUM_THREADS: |
0d077441 NS |
6105 | case OMP_CLAUSE_NUM_GANGS: |
6106 | case OMP_CLAUSE_NUM_WORKERS: | |
6107 | case OMP_CLAUSE_VECTOR_LENGTH: | |
6108 | t = OMP_CLAUSE_OPERAND (c, 0); | |
1799e5d5 RH |
6109 | if (t == error_mark_node) |
6110 | remove = true; | |
6e684eee JJ |
6111 | else if (!type_dependent_expression_p (t) |
6112 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
1799e5d5 | 6113 | { |
0d077441 NS |
6114 | switch (OMP_CLAUSE_CODE (c)) |
6115 | { | |
6116 | case OMP_CLAUSE_GANG: | |
6117 | error_at (OMP_CLAUSE_LOCATION (c), | |
6118 | "%<gang%> num expression must be integral"); break; | |
6119 | case OMP_CLAUSE_VECTOR: | |
6120 | error_at (OMP_CLAUSE_LOCATION (c), | |
6121 | "%<vector%> length expression must be integral"); | |
6122 | break; | |
6123 | case OMP_CLAUSE_WORKER: | |
6124 | error_at (OMP_CLAUSE_LOCATION (c), | |
6125 | "%<worker%> num expression must be integral"); | |
6126 | break; | |
6127 | default: | |
6128 | error_at (OMP_CLAUSE_LOCATION (c), | |
6129 | "%qs expression must be integral", | |
6130 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6131 | } | |
1799e5d5 RH |
6132 | remove = true; |
6133 | } | |
7d1362bc | 6134 | else |
b848354b JJ |
6135 | { |
6136 | t = mark_rvalue_use (t); | |
6137 | if (!processing_template_decl) | |
d9a6bd32 JJ |
6138 | { |
6139 | t = maybe_constant_value (t); | |
6140 | if (TREE_CODE (t) == INTEGER_CST | |
6141 | && tree_int_cst_sgn (t) != 1) | |
6142 | { | |
0d077441 NS |
6143 | switch (OMP_CLAUSE_CODE (c)) |
6144 | { | |
6145 | case OMP_CLAUSE_GANG: | |
6146 | warning_at (OMP_CLAUSE_LOCATION (c), 0, | |
6147 | "%<gang%> num value must be positive"); | |
6148 | break; | |
6149 | case OMP_CLAUSE_VECTOR: | |
6150 | warning_at (OMP_CLAUSE_LOCATION (c), 0, | |
6151 | "%<vector%> length value must be" | |
6152 | "positive"); | |
6153 | break; | |
6154 | case OMP_CLAUSE_WORKER: | |
6155 | warning_at (OMP_CLAUSE_LOCATION (c), 0, | |
6156 | "%<worker%> num value must be" | |
6157 | "positive"); | |
6158 | break; | |
6159 | default: | |
6160 | warning_at (OMP_CLAUSE_LOCATION (c), 0, | |
6161 | "%qs value must be positive", | |
6162 | omp_clause_code_name | |
6163 | [OMP_CLAUSE_CODE (c)]); | |
6164 | } | |
d9a6bd32 JJ |
6165 | t = integer_one_node; |
6166 | } | |
6167 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6168 | } | |
0d077441 | 6169 | OMP_CLAUSE_OPERAND (c, 0) = t; |
b848354b | 6170 | } |
1799e5d5 RH |
6171 | break; |
6172 | ||
6173 | case OMP_CLAUSE_SCHEDULE: | |
e01d41e5 JJ |
6174 | if (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC) |
6175 | { | |
6176 | const char *p = NULL; | |
6177 | switch (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_MASK) | |
6178 | { | |
6179 | case OMP_CLAUSE_SCHEDULE_STATIC: p = "static"; break; | |
6180 | case OMP_CLAUSE_SCHEDULE_DYNAMIC: break; | |
6181 | case OMP_CLAUSE_SCHEDULE_GUIDED: break; | |
6182 | case OMP_CLAUSE_SCHEDULE_AUTO: p = "auto"; break; | |
6183 | case OMP_CLAUSE_SCHEDULE_RUNTIME: p = "runtime"; break; | |
6184 | default: gcc_unreachable (); | |
6185 | } | |
6186 | if (p) | |
6187 | { | |
6188 | error_at (OMP_CLAUSE_LOCATION (c), | |
6189 | "%<nonmonotonic%> modifier specified for %qs " | |
6190 | "schedule kind", p); | |
6191 | OMP_CLAUSE_SCHEDULE_KIND (c) | |
6192 | = (enum omp_clause_schedule_kind) | |
6193 | (OMP_CLAUSE_SCHEDULE_KIND (c) | |
6194 | & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC); | |
6195 | } | |
6196 | } | |
6197 | ||
1799e5d5 RH |
6198 | t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c); |
6199 | if (t == NULL) | |
6200 | ; | |
6201 | else if (t == error_mark_node) | |
6202 | remove = true; | |
6e684eee | 6203 | else if (!type_dependent_expression_p (t) |
9a771876 JJ |
6204 | && (OMP_CLAUSE_SCHEDULE_KIND (c) |
6205 | != OMP_CLAUSE_SCHEDULE_CILKFOR) | |
6e684eee | 6206 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) |
1799e5d5 RH |
6207 | { |
6208 | error ("schedule chunk size expression must be integral"); | |
6209 | remove = true; | |
6210 | } | |
7d1362bc | 6211 | else |
b848354b JJ |
6212 | { |
6213 | t = mark_rvalue_use (t); | |
6214 | if (!processing_template_decl) | |
9a771876 JJ |
6215 | { |
6216 | if (OMP_CLAUSE_SCHEDULE_KIND (c) | |
6217 | == OMP_CLAUSE_SCHEDULE_CILKFOR) | |
6218 | { | |
6219 | t = convert_to_integer (long_integer_type_node, t); | |
6220 | if (t == error_mark_node) | |
6221 | { | |
6222 | remove = true; | |
6223 | break; | |
6224 | } | |
6225 | } | |
6226 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6227 | } | |
b848354b JJ |
6228 | OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; |
6229 | } | |
1799e5d5 RH |
6230 | break; |
6231 | ||
acf0174b JJ |
6232 | case OMP_CLAUSE_SIMDLEN: |
6233 | case OMP_CLAUSE_SAFELEN: | |
6234 | t = OMP_CLAUSE_OPERAND (c, 0); | |
6235 | if (t == error_mark_node) | |
6236 | remove = true; | |
6237 | else if (!type_dependent_expression_p (t) | |
6238 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6239 | { | |
6240 | error ("%qs length expression must be integral", | |
6241 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6242 | remove = true; | |
6243 | } | |
6244 | else | |
6245 | { | |
6246 | t = mark_rvalue_use (t); | |
6247 | t = maybe_constant_value (t); | |
6248 | if (!processing_template_decl) | |
6249 | { | |
6250 | if (TREE_CODE (t) != INTEGER_CST | |
6251 | || tree_int_cst_sgn (t) != 1) | |
6252 | { | |
6253 | error ("%qs length expression must be positive constant" | |
6254 | " integer expression", | |
6255 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6256 | remove = true; | |
6257 | } | |
6258 | } | |
6259 | OMP_CLAUSE_OPERAND (c, 0) = t; | |
d9a6bd32 JJ |
6260 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN) |
6261 | safelen = c; | |
acf0174b JJ |
6262 | } |
6263 | break; | |
6264 | ||
41dbbb37 TS |
6265 | case OMP_CLAUSE_ASYNC: |
6266 | t = OMP_CLAUSE_ASYNC_EXPR (c); | |
6267 | if (t == error_mark_node) | |
6268 | remove = true; | |
6269 | else if (!type_dependent_expression_p (t) | |
6270 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6271 | { | |
6272 | error ("%<async%> expression must be integral"); | |
6273 | remove = true; | |
6274 | } | |
6275 | else | |
6276 | { | |
6277 | t = mark_rvalue_use (t); | |
6278 | if (!processing_template_decl) | |
6279 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6280 | OMP_CLAUSE_ASYNC_EXPR (c) = t; | |
6281 | } | |
6282 | break; | |
6283 | ||
41dbbb37 TS |
6284 | case OMP_CLAUSE_WAIT: |
6285 | t = OMP_CLAUSE_WAIT_EXPR (c); | |
6286 | if (t == error_mark_node) | |
6287 | remove = true; | |
6288 | else if (!processing_template_decl) | |
6289 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6290 | OMP_CLAUSE_WAIT_EXPR (c) = t; | |
6291 | break; | |
6292 | ||
acf0174b JJ |
6293 | case OMP_CLAUSE_THREAD_LIMIT: |
6294 | t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c); | |
6295 | if (t == error_mark_node) | |
6296 | remove = true; | |
6297 | else if (!type_dependent_expression_p (t) | |
6298 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6299 | { | |
6300 | error ("%<thread_limit%> expression must be integral"); | |
6301 | remove = true; | |
6302 | } | |
6303 | else | |
6304 | { | |
6305 | t = mark_rvalue_use (t); | |
6306 | if (!processing_template_decl) | |
d9a6bd32 JJ |
6307 | { |
6308 | t = maybe_constant_value (t); | |
6309 | if (TREE_CODE (t) == INTEGER_CST | |
6310 | && tree_int_cst_sgn (t) != 1) | |
6311 | { | |
6312 | warning_at (OMP_CLAUSE_LOCATION (c), 0, | |
6313 | "%<thread_limit%> value must be positive"); | |
6314 | t = integer_one_node; | |
6315 | } | |
6316 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6317 | } | |
acf0174b JJ |
6318 | OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t; |
6319 | } | |
6320 | break; | |
6321 | ||
6322 | case OMP_CLAUSE_DEVICE: | |
6323 | t = OMP_CLAUSE_DEVICE_ID (c); | |
6324 | if (t == error_mark_node) | |
6325 | remove = true; | |
6326 | else if (!type_dependent_expression_p (t) | |
6327 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6328 | { | |
6329 | error ("%<device%> id must be integral"); | |
6330 | remove = true; | |
6331 | } | |
6332 | else | |
6333 | { | |
6334 | t = mark_rvalue_use (t); | |
6335 | if (!processing_template_decl) | |
6336 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6337 | OMP_CLAUSE_DEVICE_ID (c) = t; | |
6338 | } | |
6339 | break; | |
6340 | ||
6341 | case OMP_CLAUSE_DIST_SCHEDULE: | |
6342 | t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c); | |
6343 | if (t == NULL) | |
6344 | ; | |
6345 | else if (t == error_mark_node) | |
6346 | remove = true; | |
6347 | else if (!type_dependent_expression_p (t) | |
6348 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6349 | { | |
6350 | error ("%<dist_schedule%> chunk size expression must be " | |
6351 | "integral"); | |
6352 | remove = true; | |
6353 | } | |
6354 | else | |
6355 | { | |
6356 | t = mark_rvalue_use (t); | |
6357 | if (!processing_template_decl) | |
6358 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6359 | OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; | |
6360 | } | |
6361 | break; | |
6362 | ||
6363 | case OMP_CLAUSE_ALIGNED: | |
6364 | t = OMP_CLAUSE_DECL (c); | |
d9a6bd32 JJ |
6365 | if (t == current_class_ptr && !declare_simd) |
6366 | { | |
6367 | error ("%<this%> allowed in OpenMP only in %<declare simd%>" | |
6368 | " clauses"); | |
6369 | remove = true; | |
6370 | break; | |
6371 | } | |
56a6f1d3 | 6372 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
acf0174b JJ |
6373 | { |
6374 | if (processing_template_decl) | |
6375 | break; | |
6376 | if (DECL_P (t)) | |
6377 | error ("%qD is not a variable in %<aligned%> clause", t); | |
6378 | else | |
6379 | error ("%qE is not a variable in %<aligned%> clause", t); | |
6380 | remove = true; | |
6381 | } | |
5a9785fb JJ |
6382 | else if (!type_dependent_expression_p (t) |
6383 | && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE | |
6384 | && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE | |
6385 | && (TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE | |
6386 | || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t))) | |
6387 | && (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) | |
6388 | != ARRAY_TYPE)))) | |
6389 | { | |
6390 | error_at (OMP_CLAUSE_LOCATION (c), | |
6391 | "%qE in %<aligned%> clause is neither a pointer nor " | |
6392 | "an array nor a reference to pointer or array", t); | |
6393 | remove = true; | |
6394 | } | |
acf0174b JJ |
6395 | else if (bitmap_bit_p (&aligned_head, DECL_UID (t))) |
6396 | { | |
6397 | error ("%qD appears more than once in %<aligned%> clauses", t); | |
6398 | remove = true; | |
6399 | } | |
6400 | else | |
6401 | bitmap_set_bit (&aligned_head, DECL_UID (t)); | |
6402 | t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c); | |
6403 | if (t == error_mark_node) | |
6404 | remove = true; | |
6405 | else if (t == NULL_TREE) | |
6406 | break; | |
6407 | else if (!type_dependent_expression_p (t) | |
6408 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6409 | { | |
6410 | error ("%<aligned%> clause alignment expression must " | |
6411 | "be integral"); | |
6412 | remove = true; | |
6413 | } | |
6414 | else | |
6415 | { | |
6416 | t = mark_rvalue_use (t); | |
6417 | t = maybe_constant_value (t); | |
6418 | if (!processing_template_decl) | |
6419 | { | |
6420 | if (TREE_CODE (t) != INTEGER_CST | |
6421 | || tree_int_cst_sgn (t) != 1) | |
6422 | { | |
6423 | error ("%<aligned%> clause alignment expression must be " | |
6424 | "positive constant integer expression"); | |
6425 | remove = true; | |
6426 | } | |
6427 | } | |
6428 | OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t; | |
6429 | } | |
6430 | break; | |
6431 | ||
6432 | case OMP_CLAUSE_DEPEND: | |
6433 | t = OMP_CLAUSE_DECL (c); | |
d9a6bd32 JJ |
6434 | if (t == NULL_TREE) |
6435 | { | |
6436 | gcc_assert (OMP_CLAUSE_DEPEND_KIND (c) | |
6437 | == OMP_CLAUSE_DEPEND_SOURCE); | |
6438 | break; | |
6439 | } | |
6440 | if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK) | |
6441 | { | |
6442 | if (cp_finish_omp_clause_depend_sink (c)) | |
6443 | remove = true; | |
6444 | break; | |
6445 | } | |
acf0174b JJ |
6446 | if (TREE_CODE (t) == TREE_LIST) |
6447 | { | |
d9a6bd32 | 6448 | if (handle_omp_array_sections (c, allow_fields)) |
acf0174b JJ |
6449 | remove = true; |
6450 | break; | |
6451 | } | |
6452 | if (t == error_mark_node) | |
6453 | remove = true; | |
56a6f1d3 | 6454 | else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
acf0174b JJ |
6455 | { |
6456 | if (processing_template_decl) | |
6457 | break; | |
6458 | if (DECL_P (t)) | |
6459 | error ("%qD is not a variable in %<depend%> clause", t); | |
6460 | else | |
6461 | error ("%qE is not a variable in %<depend%> clause", t); | |
6462 | remove = true; | |
6463 | } | |
d9a6bd32 JJ |
6464 | else if (t == current_class_ptr) |
6465 | { | |
6466 | error ("%<this%> allowed in OpenMP only in %<declare simd%>" | |
6467 | " clauses"); | |
6468 | remove = true; | |
6469 | } | |
acf0174b JJ |
6470 | else if (!processing_template_decl |
6471 | && !cxx_mark_addressable (t)) | |
6472 | remove = true; | |
6473 | break; | |
6474 | ||
6475 | case OMP_CLAUSE_MAP: | |
6476 | case OMP_CLAUSE_TO: | |
6477 | case OMP_CLAUSE_FROM: | |
41dbbb37 | 6478 | case OMP_CLAUSE__CACHE_: |
acf0174b JJ |
6479 | t = OMP_CLAUSE_DECL (c); |
6480 | if (TREE_CODE (t) == TREE_LIST) | |
6481 | { | |
d9a6bd32 | 6482 | if (handle_omp_array_sections (c, allow_fields)) |
acf0174b JJ |
6483 | remove = true; |
6484 | else | |
6485 | { | |
6486 | t = OMP_CLAUSE_DECL (c); | |
bce16b88 JJ |
6487 | if (TREE_CODE (t) != TREE_LIST |
6488 | && !type_dependent_expression_p (t) | |
6489 | && !cp_omp_mappable_type (TREE_TYPE (t))) | |
acf0174b JJ |
6490 | { |
6491 | error_at (OMP_CLAUSE_LOCATION (c), | |
6492 | "array section does not have mappable type " | |
6493 | "in %qs clause", | |
6494 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6495 | remove = true; | |
6496 | } | |
d9a6bd32 JJ |
6497 | while (TREE_CODE (t) == ARRAY_REF) |
6498 | t = TREE_OPERAND (t, 0); | |
6499 | if (TREE_CODE (t) == COMPONENT_REF | |
6500 | && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) | |
6501 | { | |
6502 | while (TREE_CODE (t) == COMPONENT_REF) | |
6503 | t = TREE_OPERAND (t, 0); | |
6504 | if (bitmap_bit_p (&map_field_head, DECL_UID (t))) | |
6505 | break; | |
6506 | if (bitmap_bit_p (&map_head, DECL_UID (t))) | |
6507 | { | |
6508 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) | |
6509 | error ("%qD appears more than once in motion" | |
6510 | " clauses", t); | |
6511 | else | |
6512 | error ("%qD appears more than once in map" | |
6513 | " clauses", t); | |
6514 | remove = true; | |
6515 | } | |
6516 | else | |
6517 | { | |
6518 | bitmap_set_bit (&map_head, DECL_UID (t)); | |
6519 | bitmap_set_bit (&map_field_head, DECL_UID (t)); | |
6520 | } | |
6521 | } | |
acf0174b JJ |
6522 | } |
6523 | break; | |
6524 | } | |
6525 | if (t == error_mark_node) | |
d9a6bd32 JJ |
6526 | { |
6527 | remove = true; | |
6528 | break; | |
6529 | } | |
6530 | if (REFERENCE_REF_P (t) | |
6531 | && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF) | |
e01d41e5 JJ |
6532 | { |
6533 | t = TREE_OPERAND (t, 0); | |
6534 | OMP_CLAUSE_DECL (c) = t; | |
6535 | } | |
d9a6bd32 JJ |
6536 | if (TREE_CODE (t) == COMPONENT_REF |
6537 | && allow_fields | |
6538 | && OMP_CLAUSE_CODE (c) != OMP_CLAUSE__CACHE_) | |
6539 | { | |
6540 | if (type_dependent_expression_p (t)) | |
6541 | break; | |
6542 | if (DECL_BIT_FIELD (TREE_OPERAND (t, 1))) | |
6543 | { | |
6544 | error_at (OMP_CLAUSE_LOCATION (c), | |
6545 | "bit-field %qE in %qs clause", | |
6546 | t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6547 | remove = true; | |
6548 | } | |
6549 | else if (!cp_omp_mappable_type (TREE_TYPE (t))) | |
6550 | { | |
6551 | error_at (OMP_CLAUSE_LOCATION (c), | |
6552 | "%qE does not have a mappable type in %qs clause", | |
6553 | t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6554 | remove = true; | |
6555 | } | |
6556 | while (TREE_CODE (t) == COMPONENT_REF) | |
6557 | { | |
6558 | if (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) | |
6559 | == UNION_TYPE) | |
6560 | { | |
6561 | error_at (OMP_CLAUSE_LOCATION (c), | |
6562 | "%qE is a member of a union", t); | |
6563 | remove = true; | |
6564 | break; | |
6565 | } | |
6566 | t = TREE_OPERAND (t, 0); | |
6567 | } | |
6568 | if (remove) | |
6569 | break; | |
6570 | if (VAR_P (t) || TREE_CODE (t) == PARM_DECL) | |
6571 | { | |
e01d41e5 JJ |
6572 | if (bitmap_bit_p (&map_field_head, DECL_UID (t))) |
6573 | goto handle_map_references; | |
d9a6bd32 JJ |
6574 | } |
6575 | } | |
6576 | if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) | |
acf0174b JJ |
6577 | { |
6578 | if (processing_template_decl) | |
6579 | break; | |
6580 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP | |
e01d41e5 JJ |
6581 | && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER |
6582 | || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER)) | |
acf0174b JJ |
6583 | break; |
6584 | if (DECL_P (t)) | |
6585 | error ("%qD is not a variable in %qs clause", t, | |
6586 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6587 | else | |
6588 | error ("%qE is not a variable in %qs clause", t, | |
6589 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6590 | remove = true; | |
6591 | } | |
3048c0c7 | 6592 | else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) |
acf0174b JJ |
6593 | { |
6594 | error ("%qD is threadprivate variable in %qs clause", t, | |
6595 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6596 | remove = true; | |
6597 | } | |
d9a6bd32 JJ |
6598 | else if (t == current_class_ptr) |
6599 | { | |
6600 | error ("%<this%> allowed in OpenMP only in %<declare simd%>" | |
6601 | " clauses"); | |
6602 | remove = true; | |
6603 | break; | |
6604 | } | |
acf0174b JJ |
6605 | else if (!processing_template_decl |
6606 | && TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE | |
e4606348 JJ |
6607 | && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP |
6608 | || (OMP_CLAUSE_MAP_KIND (c) | |
6609 | != GOMP_MAP_FIRSTPRIVATE_POINTER)) | |
acf0174b JJ |
6610 | && !cxx_mark_addressable (t)) |
6611 | remove = true; | |
6612 | else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP | |
d9a6bd32 JJ |
6613 | && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER |
6614 | || (OMP_CLAUSE_MAP_KIND (c) | |
6615 | == GOMP_MAP_FIRSTPRIVATE_POINTER))) | |
6616 | && t == OMP_CLAUSE_DECL (c) | |
bce16b88 | 6617 | && !type_dependent_expression_p (t) |
acf0174b JJ |
6618 | && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t)) |
6619 | == REFERENCE_TYPE) | |
6620 | ? TREE_TYPE (TREE_TYPE (t)) | |
6621 | : TREE_TYPE (t))) | |
6622 | { | |
6623 | error_at (OMP_CLAUSE_LOCATION (c), | |
6624 | "%qD does not have a mappable type in %qs clause", t, | |
6625 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6626 | remove = true; | |
6627 | } | |
d9a6bd32 JJ |
6628 | else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP |
6629 | && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER) | |
6630 | { | |
6631 | if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
6632 | || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) | |
6633 | { | |
6634 | error ("%qD appears more than once in data clauses", t); | |
6635 | remove = true; | |
6636 | } | |
e01d41e5 | 6637 | else if (bitmap_bit_p (&map_head, DECL_UID (t))) |
d9a6bd32 | 6638 | { |
e01d41e5 JJ |
6639 | error ("%qD appears both in data and map clauses", t); |
6640 | remove = true; | |
d9a6bd32 | 6641 | } |
e01d41e5 JJ |
6642 | else |
6643 | bitmap_set_bit (&generic_head, DECL_UID (t)); | |
d9a6bd32 JJ |
6644 | } |
6645 | else if (bitmap_bit_p (&map_head, DECL_UID (t))) | |
acf0174b JJ |
6646 | { |
6647 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) | |
6648 | error ("%qD appears more than once in motion clauses", t); | |
6649 | else | |
6650 | error ("%qD appears more than once in map clauses", t); | |
6651 | remove = true; | |
6652 | } | |
e01d41e5 JJ |
6653 | else if (bitmap_bit_p (&generic_head, DECL_UID (t)) |
6654 | || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) | |
6655 | { | |
6656 | error ("%qD appears both in data and map clauses", t); | |
6657 | remove = true; | |
6658 | } | |
acf0174b | 6659 | else |
d9a6bd32 JJ |
6660 | { |
6661 | bitmap_set_bit (&map_head, DECL_UID (t)); | |
6662 | if (t != OMP_CLAUSE_DECL (c) | |
6663 | && TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF) | |
6664 | bitmap_set_bit (&map_field_head, DECL_UID (t)); | |
6665 | } | |
e01d41e5 JJ |
6666 | handle_map_references: |
6667 | if (!remove | |
6668 | && !processing_template_decl | |
6669 | && allow_fields | |
6670 | && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) == REFERENCE_TYPE) | |
6671 | { | |
6672 | t = OMP_CLAUSE_DECL (c); | |
6673 | if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) | |
6674 | { | |
6675 | OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t); | |
6676 | if (OMP_CLAUSE_SIZE (c) == NULL_TREE) | |
6677 | OMP_CLAUSE_SIZE (c) | |
6678 | = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))); | |
6679 | } | |
6680 | else if (OMP_CLAUSE_MAP_KIND (c) | |
6681 | != GOMP_MAP_FIRSTPRIVATE_POINTER | |
6682 | && (OMP_CLAUSE_MAP_KIND (c) | |
6683 | != GOMP_MAP_FIRSTPRIVATE_REFERENCE) | |
6684 | && (OMP_CLAUSE_MAP_KIND (c) | |
6685 | != GOMP_MAP_ALWAYS_POINTER)) | |
6686 | { | |
6687 | tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c), | |
6688 | OMP_CLAUSE_MAP); | |
6689 | if (TREE_CODE (t) == COMPONENT_REF) | |
6690 | OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER); | |
6691 | else | |
6692 | OMP_CLAUSE_SET_MAP_KIND (c2, | |
6693 | GOMP_MAP_FIRSTPRIVATE_REFERENCE); | |
6694 | OMP_CLAUSE_DECL (c2) = t; | |
6695 | OMP_CLAUSE_SIZE (c2) = size_zero_node; | |
6696 | OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c); | |
6697 | OMP_CLAUSE_CHAIN (c) = c2; | |
6698 | OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t); | |
6699 | if (OMP_CLAUSE_SIZE (c) == NULL_TREE) | |
6700 | OMP_CLAUSE_SIZE (c) | |
6701 | = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))); | |
6702 | c = c2; | |
6703 | } | |
6704 | } | |
d9a6bd32 JJ |
6705 | break; |
6706 | ||
6707 | case OMP_CLAUSE_TO_DECLARE: | |
d9a6bd32 JJ |
6708 | case OMP_CLAUSE_LINK: |
6709 | t = OMP_CLAUSE_DECL (c); | |
e01d41e5 JJ |
6710 | if (TREE_CODE (t) == FUNCTION_DECL |
6711 | && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE) | |
6712 | ; | |
6713 | else if (!VAR_P (t)) | |
d9a6bd32 | 6714 | { |
e01d41e5 JJ |
6715 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE) |
6716 | { | |
6717 | if (TREE_CODE (t) == OVERLOAD && OVL_CHAIN (t)) | |
6718 | error_at (OMP_CLAUSE_LOCATION (c), | |
6719 | "overloaded function name %qE in clause %qs", t, | |
6720 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6721 | else if (TREE_CODE (t) == TEMPLATE_ID_EXPR) | |
6722 | error_at (OMP_CLAUSE_LOCATION (c), | |
6723 | "template %qE in clause %qs", t, | |
6724 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6725 | else | |
6726 | error_at (OMP_CLAUSE_LOCATION (c), | |
6727 | "%qE is neither a variable nor a function name " | |
6728 | "in clause %qs", t, | |
6729 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6730 | } | |
6731 | else | |
6732 | error_at (OMP_CLAUSE_LOCATION (c), | |
6733 | "%qE is not a variable in clause %qs", t, | |
6734 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
d9a6bd32 JJ |
6735 | remove = true; |
6736 | } | |
6737 | else if (DECL_THREAD_LOCAL_P (t)) | |
6738 | { | |
6739 | error_at (OMP_CLAUSE_LOCATION (c), | |
6740 | "%qD is threadprivate variable in %qs clause", t, | |
6741 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6742 | remove = true; | |
6743 | } | |
6744 | else if (!cp_omp_mappable_type (TREE_TYPE (t))) | |
6745 | { | |
6746 | error_at (OMP_CLAUSE_LOCATION (c), | |
6747 | "%qD does not have a mappable type in %qs clause", t, | |
6748 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6749 | remove = true; | |
6750 | } | |
e01d41e5 JJ |
6751 | if (remove) |
6752 | break; | |
6753 | if (bitmap_bit_p (&generic_head, DECL_UID (t))) | |
6754 | { | |
6755 | error_at (OMP_CLAUSE_LOCATION (c), | |
6756 | "%qE appears more than once on the same " | |
6757 | "%<declare target%> directive", t); | |
6758 | remove = true; | |
6759 | } | |
6760 | else | |
6761 | bitmap_set_bit (&generic_head, DECL_UID (t)); | |
acf0174b JJ |
6762 | break; |
6763 | ||
6764 | case OMP_CLAUSE_UNIFORM: | |
6765 | t = OMP_CLAUSE_DECL (c); | |
6766 | if (TREE_CODE (t) != PARM_DECL) | |
6767 | { | |
6768 | if (processing_template_decl) | |
6769 | break; | |
6770 | if (DECL_P (t)) | |
6771 | error ("%qD is not an argument in %<uniform%> clause", t); | |
6772 | else | |
6773 | error ("%qE is not an argument in %<uniform%> clause", t); | |
6774 | remove = true; | |
ee1d5a02 | 6775 | break; |
acf0174b | 6776 | } |
e01d41e5 JJ |
6777 | /* map_head bitmap is used as uniform_head if declare_simd. */ |
6778 | bitmap_set_bit (&map_head, DECL_UID (t)); | |
ee1d5a02 | 6779 | goto check_dup_generic; |
acf0174b | 6780 | |
d9a6bd32 JJ |
6781 | case OMP_CLAUSE_GRAINSIZE: |
6782 | t = OMP_CLAUSE_GRAINSIZE_EXPR (c); | |
6783 | if (t == error_mark_node) | |
6784 | remove = true; | |
6785 | else if (!type_dependent_expression_p (t) | |
6786 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6787 | { | |
6788 | error ("%<grainsize%> expression must be integral"); | |
6789 | remove = true; | |
6790 | } | |
6791 | else | |
6792 | { | |
6793 | t = mark_rvalue_use (t); | |
6794 | if (!processing_template_decl) | |
6795 | { | |
6796 | t = maybe_constant_value (t); | |
6797 | if (TREE_CODE (t) == INTEGER_CST | |
6798 | && tree_int_cst_sgn (t) != 1) | |
6799 | { | |
6800 | warning_at (OMP_CLAUSE_LOCATION (c), 0, | |
6801 | "%<grainsize%> value must be positive"); | |
6802 | t = integer_one_node; | |
6803 | } | |
6804 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6805 | } | |
6806 | OMP_CLAUSE_GRAINSIZE_EXPR (c) = t; | |
6807 | } | |
6808 | break; | |
6809 | ||
6810 | case OMP_CLAUSE_PRIORITY: | |
6811 | t = OMP_CLAUSE_PRIORITY_EXPR (c); | |
6812 | if (t == error_mark_node) | |
6813 | remove = true; | |
6814 | else if (!type_dependent_expression_p (t) | |
6815 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6816 | { | |
6817 | error ("%<priority%> expression must be integral"); | |
6818 | remove = true; | |
6819 | } | |
6820 | else | |
6821 | { | |
6822 | t = mark_rvalue_use (t); | |
6823 | if (!processing_template_decl) | |
6824 | { | |
6825 | t = maybe_constant_value (t); | |
6826 | if (TREE_CODE (t) == INTEGER_CST | |
6827 | && tree_int_cst_sgn (t) == -1) | |
6828 | { | |
6829 | warning_at (OMP_CLAUSE_LOCATION (c), 0, | |
6830 | "%<priority%> value must be non-negative"); | |
6831 | t = integer_one_node; | |
6832 | } | |
6833 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6834 | } | |
6835 | OMP_CLAUSE_PRIORITY_EXPR (c) = t; | |
6836 | } | |
6837 | break; | |
6838 | ||
6839 | case OMP_CLAUSE_HINT: | |
6840 | t = OMP_CLAUSE_HINT_EXPR (c); | |
6841 | if (t == error_mark_node) | |
6842 | remove = true; | |
6843 | else if (!type_dependent_expression_p (t) | |
6844 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6845 | { | |
6846 | error ("%<num_tasks%> expression must be integral"); | |
6847 | remove = true; | |
6848 | } | |
6849 | else | |
6850 | { | |
6851 | t = mark_rvalue_use (t); | |
6852 | if (!processing_template_decl) | |
6853 | { | |
6854 | t = maybe_constant_value (t); | |
6855 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6856 | } | |
6857 | OMP_CLAUSE_HINT_EXPR (c) = t; | |
6858 | } | |
6859 | break; | |
6860 | ||
37d5ad46 | 6861 | case OMP_CLAUSE_USE_DEVICE: |
d9a6bd32 JJ |
6862 | case OMP_CLAUSE_IS_DEVICE_PTR: |
6863 | case OMP_CLAUSE_USE_DEVICE_PTR: | |
6864 | field_ok = allow_fields; | |
6865 | t = OMP_CLAUSE_DECL (c); | |
6866 | if (!type_dependent_expression_p (t)) | |
6867 | { | |
6868 | tree type = TREE_TYPE (t); | |
6869 | if (TREE_CODE (type) != POINTER_TYPE | |
6870 | && TREE_CODE (type) != ARRAY_TYPE | |
6871 | && (TREE_CODE (type) != REFERENCE_TYPE | |
6872 | || (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE | |
6873 | && TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))) | |
6874 | { | |
6875 | error_at (OMP_CLAUSE_LOCATION (c), | |
6876 | "%qs variable is neither a pointer, nor an array" | |
6877 | "nor reference to pointer or array", | |
6878 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
6879 | remove = true; | |
6880 | } | |
6881 | } | |
6882 | goto check_dup_generic; | |
6883 | ||
1799e5d5 | 6884 | case OMP_CLAUSE_NOWAIT: |
1799e5d5 | 6885 | case OMP_CLAUSE_DEFAULT: |
a68ab351 JJ |
6886 | case OMP_CLAUSE_UNTIED: |
6887 | case OMP_CLAUSE_COLLAPSE: | |
20906c66 | 6888 | case OMP_CLAUSE_MERGEABLE: |
acf0174b JJ |
6889 | case OMP_CLAUSE_PARALLEL: |
6890 | case OMP_CLAUSE_FOR: | |
6891 | case OMP_CLAUSE_SECTIONS: | |
6892 | case OMP_CLAUSE_TASKGROUP: | |
6893 | case OMP_CLAUSE_PROC_BIND: | |
d9a6bd32 JJ |
6894 | case OMP_CLAUSE_NOGROUP: |
6895 | case OMP_CLAUSE_THREADS: | |
6896 | case OMP_CLAUSE_SIMD: | |
6897 | case OMP_CLAUSE_DEFAULTMAP: | |
9a771876 | 6898 | case OMP_CLAUSE__CILK_FOR_COUNT_: |
0d077441 | 6899 | case OMP_CLAUSE_AUTO: |
7a5e4956 | 6900 | case OMP_CLAUSE_INDEPENDENT: |
0d077441 | 6901 | case OMP_CLAUSE_SEQ: |
acf0174b JJ |
6902 | break; |
6903 | ||
7a5e4956 CP |
6904 | case OMP_CLAUSE_TILE: |
6905 | for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list; | |
6906 | list = TREE_CHAIN (list)) | |
6907 | { | |
6908 | t = TREE_VALUE (list); | |
6909 | ||
6910 | if (t == error_mark_node) | |
6911 | remove = true; | |
6912 | else if (!type_dependent_expression_p (t) | |
6913 | && !INTEGRAL_TYPE_P (TREE_TYPE (t))) | |
6914 | { | |
6915 | error ("%<tile%> value must be integral"); | |
6916 | remove = true; | |
6917 | } | |
6918 | else | |
6919 | { | |
6920 | t = mark_rvalue_use (t); | |
6921 | if (!processing_template_decl) | |
6922 | { | |
6923 | t = maybe_constant_value (t); | |
6924 | if (TREE_CODE (t) == INTEGER_CST | |
6925 | && tree_int_cst_sgn (t) != 1 | |
6926 | && t != integer_minus_one_node) | |
6927 | { | |
6928 | warning_at (OMP_CLAUSE_LOCATION (c), 0, | |
6929 | "%<tile%> value must be positive"); | |
6930 | t = integer_one_node; | |
6931 | } | |
6932 | } | |
6933 | t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
6934 | } | |
6935 | ||
6936 | /* Update list item. */ | |
6937 | TREE_VALUE (list) = t; | |
6938 | } | |
6939 | break; | |
6940 | ||
e01d41e5 JJ |
6941 | case OMP_CLAUSE_ORDERED: |
6942 | ordered_seen = true; | |
6943 | break; | |
6944 | ||
acf0174b JJ |
6945 | case OMP_CLAUSE_INBRANCH: |
6946 | case OMP_CLAUSE_NOTINBRANCH: | |
6947 | if (branch_seen) | |
6948 | { | |
6949 | error ("%<inbranch%> clause is incompatible with " | |
6950 | "%<notinbranch%>"); | |
6951 | remove = true; | |
6952 | } | |
6953 | branch_seen = true; | |
1799e5d5 RH |
6954 | break; |
6955 | ||
6956 | default: | |
6957 | gcc_unreachable (); | |
6958 | } | |
6959 | ||
6960 | if (remove) | |
6961 | *pc = OMP_CLAUSE_CHAIN (c); | |
6962 | else | |
6963 | pc = &OMP_CLAUSE_CHAIN (c); | |
6964 | } | |
6965 | ||
6966 | for (pc = &clauses, c = clauses; c ; c = *pc) | |
6967 | { | |
81f40b79 | 6968 | enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c); |
1799e5d5 | 6969 | bool remove = false; |
d9a6bd32 | 6970 | bool need_complete_type = false; |
1799e5d5 RH |
6971 | bool need_default_ctor = false; |
6972 | bool need_copy_ctor = false; | |
6973 | bool need_copy_assignment = false; | |
6974 | bool need_implicitly_determined = false; | |
acf0174b | 6975 | bool need_dtor = false; |
1799e5d5 RH |
6976 | tree type, inner_type; |
6977 | ||
6978 | switch (c_kind) | |
6979 | { | |
6980 | case OMP_CLAUSE_SHARED: | |
1799e5d5 RH |
6981 | need_implicitly_determined = true; |
6982 | break; | |
6983 | case OMP_CLAUSE_PRIVATE: | |
d9a6bd32 | 6984 | need_complete_type = true; |
1799e5d5 | 6985 | need_default_ctor = true; |
acf0174b | 6986 | need_dtor = true; |
1799e5d5 RH |
6987 | need_implicitly_determined = true; |
6988 | break; | |
6989 | case OMP_CLAUSE_FIRSTPRIVATE: | |
d9a6bd32 | 6990 | need_complete_type = true; |
1799e5d5 | 6991 | need_copy_ctor = true; |
acf0174b | 6992 | need_dtor = true; |
1799e5d5 RH |
6993 | need_implicitly_determined = true; |
6994 | break; | |
6995 | case OMP_CLAUSE_LASTPRIVATE: | |
d9a6bd32 | 6996 | need_complete_type = true; |
1799e5d5 RH |
6997 | need_copy_assignment = true; |
6998 | need_implicitly_determined = true; | |
6999 | break; | |
7000 | case OMP_CLAUSE_REDUCTION: | |
1799e5d5 RH |
7001 | need_implicitly_determined = true; |
7002 | break; | |
d9a6bd32 JJ |
7003 | case OMP_CLAUSE_LINEAR: |
7004 | if (!declare_simd) | |
7005 | need_implicitly_determined = true; | |
e01d41e5 JJ |
7006 | else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) |
7007 | && !bitmap_bit_p (&map_head, | |
7008 | DECL_UID (OMP_CLAUSE_LINEAR_STEP (c)))) | |
7009 | { | |
7010 | error_at (OMP_CLAUSE_LOCATION (c), | |
7011 | "%<linear%> clause step is a parameter %qD not " | |
7012 | "specified in %<uniform%> clause", | |
7013 | OMP_CLAUSE_LINEAR_STEP (c)); | |
7014 | *pc = OMP_CLAUSE_CHAIN (c); | |
7015 | continue; | |
7016 | } | |
d9a6bd32 | 7017 | break; |
1799e5d5 | 7018 | case OMP_CLAUSE_COPYPRIVATE: |
1799e5d5 RH |
7019 | need_copy_assignment = true; |
7020 | break; | |
7021 | case OMP_CLAUSE_COPYIN: | |
1799e5d5 RH |
7022 | need_copy_assignment = true; |
7023 | break; | |
d9a6bd32 JJ |
7024 | case OMP_CLAUSE_SIMDLEN: |
7025 | if (safelen | |
7026 | && !processing_template_decl | |
7027 | && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen), | |
7028 | OMP_CLAUSE_SIMDLEN_EXPR (c))) | |
7029 | { | |
7030 | error_at (OMP_CLAUSE_LOCATION (c), | |
7031 | "%<simdlen%> clause value is bigger than " | |
7032 | "%<safelen%> clause value"); | |
7033 | OMP_CLAUSE_SIMDLEN_EXPR (c) | |
7034 | = OMP_CLAUSE_SAFELEN_EXPR (safelen); | |
7035 | } | |
7036 | pc = &OMP_CLAUSE_CHAIN (c); | |
7037 | continue; | |
e01d41e5 JJ |
7038 | case OMP_CLAUSE_SCHEDULE: |
7039 | if (ordered_seen | |
7040 | && (OMP_CLAUSE_SCHEDULE_KIND (c) | |
7041 | & OMP_CLAUSE_SCHEDULE_NONMONOTONIC)) | |
7042 | { | |
7043 | error_at (OMP_CLAUSE_LOCATION (c), | |
7044 | "%<nonmonotonic%> schedule modifier specified " | |
7045 | "together with %<ordered%> clause"); | |
7046 | OMP_CLAUSE_SCHEDULE_KIND (c) | |
7047 | = (enum omp_clause_schedule_kind) | |
7048 | (OMP_CLAUSE_SCHEDULE_KIND (c) | |
7049 | & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC); | |
7050 | } | |
7051 | pc = &OMP_CLAUSE_CHAIN (c); | |
7052 | continue; | |
acf0174b JJ |
7053 | case OMP_CLAUSE_NOWAIT: |
7054 | if (copyprivate_seen) | |
7055 | { | |
7056 | error_at (OMP_CLAUSE_LOCATION (c), | |
7057 | "%<nowait%> clause must not be used together " | |
7058 | "with %<copyprivate%>"); | |
7059 | *pc = OMP_CLAUSE_CHAIN (c); | |
7060 | continue; | |
7061 | } | |
7062 | /* FALLTHRU */ | |
1799e5d5 RH |
7063 | default: |
7064 | pc = &OMP_CLAUSE_CHAIN (c); | |
7065 | continue; | |
7066 | } | |
7067 | ||
7068 | t = OMP_CLAUSE_DECL (c); | |
7069 | if (processing_template_decl | |
5a6ccc94 | 7070 | && !VAR_P (t) && TREE_CODE (t) != PARM_DECL) |
1799e5d5 RH |
7071 | { |
7072 | pc = &OMP_CLAUSE_CHAIN (c); | |
7073 | continue; | |
7074 | } | |
7075 | ||
7076 | switch (c_kind) | |
7077 | { | |
7078 | case OMP_CLAUSE_LASTPRIVATE: | |
7079 | if (!bitmap_bit_p (&firstprivate_head, DECL_UID (t))) | |
acf0174b JJ |
7080 | { |
7081 | need_default_ctor = true; | |
7082 | need_dtor = true; | |
7083 | } | |
1799e5d5 RH |
7084 | break; |
7085 | ||
7086 | case OMP_CLAUSE_REDUCTION: | |
acf0174b JJ |
7087 | if (finish_omp_reduction_clause (c, &need_default_ctor, |
7088 | &need_dtor)) | |
7089 | remove = true; | |
7090 | else | |
7091 | t = OMP_CLAUSE_DECL (c); | |
1799e5d5 RH |
7092 | break; |
7093 | ||
7094 | case OMP_CLAUSE_COPYIN: | |
3048c0c7 | 7095 | if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t)) |
1799e5d5 RH |
7096 | { |
7097 | error ("%qE must be %<threadprivate%> for %<copyin%>", t); | |
7098 | remove = true; | |
7099 | } | |
7100 | break; | |
7101 | ||
7102 | default: | |
7103 | break; | |
7104 | } | |
7105 | ||
d9a6bd32 | 7106 | if (need_complete_type || need_copy_assignment) |
1799e5d5 RH |
7107 | { |
7108 | t = require_complete_type (t); | |
7109 | if (t == error_mark_node) | |
7110 | remove = true; | |
8a8c12a3 | 7111 | else if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE |
d9a6bd32 JJ |
7112 | && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t)) |
7113 | remove = true; | |
1799e5d5 RH |
7114 | } |
7115 | if (need_implicitly_determined) | |
7116 | { | |
7117 | const char *share_name = NULL; | |
7118 | ||
3048c0c7 | 7119 | if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) |
1799e5d5 RH |
7120 | share_name = "threadprivate"; |
7121 | else switch (cxx_omp_predetermined_sharing (t)) | |
7122 | { | |
7123 | case OMP_CLAUSE_DEFAULT_UNSPECIFIED: | |
7124 | break; | |
7125 | case OMP_CLAUSE_DEFAULT_SHARED: | |
20906c66 JJ |
7126 | /* const vars may be specified in firstprivate clause. */ |
7127 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE | |
7128 | && cxx_omp_const_qual_no_mutable (t)) | |
7129 | break; | |
1799e5d5 RH |
7130 | share_name = "shared"; |
7131 | break; | |
7132 | case OMP_CLAUSE_DEFAULT_PRIVATE: | |
7133 | share_name = "private"; | |
7134 | break; | |
7135 | default: | |
7136 | gcc_unreachable (); | |
7137 | } | |
7138 | if (share_name) | |
7139 | { | |
7140 | error ("%qE is predetermined %qs for %qs", | |
d9a6bd32 JJ |
7141 | omp_clause_printable_decl (t), share_name, |
7142 | omp_clause_code_name[OMP_CLAUSE_CODE (c)]); | |
1799e5d5 RH |
7143 | remove = true; |
7144 | } | |
7145 | } | |
7146 | ||
7147 | /* We're interested in the base element, not arrays. */ | |
7148 | inner_type = type = TREE_TYPE (t); | |
d9a6bd32 JJ |
7149 | if ((need_complete_type |
7150 | || need_copy_assignment | |
7151 | || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) | |
acf0174b JJ |
7152 | && TREE_CODE (inner_type) == REFERENCE_TYPE) |
7153 | inner_type = TREE_TYPE (inner_type); | |
d9a6bd32 JJ |
7154 | while (TREE_CODE (inner_type) == ARRAY_TYPE) |
7155 | inner_type = TREE_TYPE (inner_type); | |
acf0174b | 7156 | |
84dc00e8 | 7157 | /* Check for special function availability by building a call to one. |
1799e5d5 RH |
7158 | Save the results, because later we won't be in the right context |
7159 | for making these queries. */ | |
7160 | if (CLASS_TYPE_P (inner_type) | |
8a8c12a3 | 7161 | && COMPLETE_TYPE_P (inner_type) |
acf0174b JJ |
7162 | && (need_default_ctor || need_copy_ctor |
7163 | || need_copy_assignment || need_dtor) | |
a68ab351 JJ |
7164 | && !type_dependent_expression_p (t) |
7165 | && cxx_omp_create_clause_info (c, inner_type, need_default_ctor, | |
acf0174b JJ |
7166 | need_copy_ctor, need_copy_assignment, |
7167 | need_dtor)) | |
a68ab351 | 7168 | remove = true; |
1799e5d5 | 7169 | |
e01d41e5 JJ |
7170 | if (!remove |
7171 | && c_kind == OMP_CLAUSE_SHARED | |
7172 | && processing_template_decl) | |
7173 | { | |
7174 | t = omp_clause_decl_field (OMP_CLAUSE_DECL (c)); | |
7175 | if (t) | |
7176 | OMP_CLAUSE_DECL (c) = t; | |
7177 | } | |
7178 | ||
1799e5d5 RH |
7179 | if (remove) |
7180 | *pc = OMP_CLAUSE_CHAIN (c); | |
7181 | else | |
7182 | pc = &OMP_CLAUSE_CHAIN (c); | |
7183 | } | |
7184 | ||
7185 | bitmap_obstack_release (NULL); | |
7186 | return clauses; | |
7187 | } | |
7188 | ||
d9a6bd32 JJ |
7189 | /* Start processing OpenMP clauses that can include any |
7190 | privatization clauses for non-static data members. */ | |
7191 | ||
7192 | tree | |
7193 | push_omp_privatization_clauses (bool ignore_next) | |
7194 | { | |
7195 | if (omp_private_member_ignore_next) | |
7196 | { | |
7197 | omp_private_member_ignore_next = ignore_next; | |
7198 | return NULL_TREE; | |
7199 | } | |
7200 | omp_private_member_ignore_next = ignore_next; | |
7201 | if (omp_private_member_map) | |
7202 | omp_private_member_vec.safe_push (error_mark_node); | |
7203 | return push_stmt_list (); | |
7204 | } | |
7205 | ||
7206 | /* Revert remapping of any non-static data members since | |
7207 | the last push_omp_privatization_clauses () call. */ | |
7208 | ||
7209 | void | |
7210 | pop_omp_privatization_clauses (tree stmt) | |
7211 | { | |
7212 | if (stmt == NULL_TREE) | |
7213 | return; | |
7214 | stmt = pop_stmt_list (stmt); | |
7215 | if (omp_private_member_map) | |
7216 | { | |
7217 | while (!omp_private_member_vec.is_empty ()) | |
7218 | { | |
7219 | tree t = omp_private_member_vec.pop (); | |
7220 | if (t == error_mark_node) | |
7221 | { | |
7222 | add_stmt (stmt); | |
7223 | return; | |
7224 | } | |
7225 | bool no_decl_expr = t == integer_zero_node; | |
7226 | if (no_decl_expr) | |
7227 | t = omp_private_member_vec.pop (); | |
7228 | tree *v = omp_private_member_map->get (t); | |
7229 | gcc_assert (v); | |
7230 | if (!no_decl_expr) | |
7231 | add_decl_expr (*v); | |
7232 | omp_private_member_map->remove (t); | |
7233 | } | |
7234 | delete omp_private_member_map; | |
7235 | omp_private_member_map = NULL; | |
7236 | } | |
7237 | add_stmt (stmt); | |
7238 | } | |
7239 | ||
7240 | /* Remember OpenMP privatization clauses mapping and clear it. | |
7241 | Used for lambdas. */ | |
7242 | ||
7243 | void | |
7244 | save_omp_privatization_clauses (vec<tree> &save) | |
7245 | { | |
7246 | save = vNULL; | |
7247 | if (omp_private_member_ignore_next) | |
7248 | save.safe_push (integer_one_node); | |
7249 | omp_private_member_ignore_next = false; | |
7250 | if (!omp_private_member_map) | |
7251 | return; | |
7252 | ||
7253 | while (!omp_private_member_vec.is_empty ()) | |
7254 | { | |
7255 | tree t = omp_private_member_vec.pop (); | |
7256 | if (t == error_mark_node) | |
7257 | { | |
7258 | save.safe_push (t); | |
7259 | continue; | |
7260 | } | |
7261 | tree n = t; | |
7262 | if (t == integer_zero_node) | |
7263 | t = omp_private_member_vec.pop (); | |
7264 | tree *v = omp_private_member_map->get (t); | |
7265 | gcc_assert (v); | |
7266 | save.safe_push (*v); | |
7267 | save.safe_push (t); | |
7268 | if (n != t) | |
7269 | save.safe_push (n); | |
7270 | } | |
7271 | delete omp_private_member_map; | |
7272 | omp_private_member_map = NULL; | |
7273 | } | |
7274 | ||
7275 | /* Restore OpenMP privatization clauses mapping saved by the | |
7276 | above function. */ | |
7277 | ||
7278 | void | |
7279 | restore_omp_privatization_clauses (vec<tree> &save) | |
7280 | { | |
7281 | gcc_assert (omp_private_member_vec.is_empty ()); | |
7282 | omp_private_member_ignore_next = false; | |
7283 | if (save.is_empty ()) | |
7284 | return; | |
7285 | if (save.length () == 1 && save[0] == integer_one_node) | |
7286 | { | |
7287 | omp_private_member_ignore_next = true; | |
7288 | save.release (); | |
7289 | return; | |
7290 | } | |
7291 | ||
7292 | omp_private_member_map = new hash_map <tree, tree>; | |
7293 | while (!save.is_empty ()) | |
7294 | { | |
7295 | tree t = save.pop (); | |
7296 | tree n = t; | |
7297 | if (t != error_mark_node) | |
7298 | { | |
7299 | if (t == integer_one_node) | |
7300 | { | |
7301 | omp_private_member_ignore_next = true; | |
7302 | gcc_assert (save.is_empty ()); | |
7303 | break; | |
7304 | } | |
7305 | if (t == integer_zero_node) | |
7306 | t = save.pop (); | |
7307 | tree &v = omp_private_member_map->get_or_insert (t); | |
7308 | v = save.pop (); | |
7309 | } | |
7310 | omp_private_member_vec.safe_push (t); | |
7311 | if (n != t) | |
7312 | omp_private_member_vec.safe_push (n); | |
7313 | } | |
7314 | save.release (); | |
7315 | } | |
7316 | ||
1799e5d5 RH |
7317 | /* For all variables in the tree_list VARS, mark them as thread local. */ |
7318 | ||
7319 | void | |
7320 | finish_omp_threadprivate (tree vars) | |
7321 | { | |
7322 | tree t; | |
7323 | ||
7324 | /* Mark every variable in VARS to be assigned thread local storage. */ | |
7325 | for (t = vars; t; t = TREE_CHAIN (t)) | |
7326 | { | |
7327 | tree v = TREE_PURPOSE (t); | |
7328 | ||
edb6000e JJ |
7329 | if (error_operand_p (v)) |
7330 | ; | |
5a6ccc94 | 7331 | else if (!VAR_P (v)) |
edb6000e JJ |
7332 | error ("%<threadprivate%> %qD is not file, namespace " |
7333 | "or block scope variable", v); | |
1799e5d5 RH |
7334 | /* If V had already been marked threadprivate, it doesn't matter |
7335 | whether it had been used prior to this point. */ | |
edb6000e | 7336 | else if (TREE_USED (v) |
1799e5d5 RH |
7337 | && (DECL_LANG_SPECIFIC (v) == NULL |
7338 | || !CP_DECL_THREADPRIVATE_P (v))) | |
7339 | error ("%qE declared %<threadprivate%> after first use", v); | |
7340 | else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v)) | |
7341 | error ("automatic variable %qE cannot be %<threadprivate%>", v); | |
57c3feb4 | 7342 | else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v)))) |
1799e5d5 | 7343 | error ("%<threadprivate%> %qE has incomplete type", v); |
a68ab351 JJ |
7344 | else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v)) |
7345 | && CP_DECL_CONTEXT (v) != current_class_type) | |
7346 | error ("%<threadprivate%> %qE directive not " | |
7347 | "in %qT definition", v, CP_DECL_CONTEXT (v)); | |
1799e5d5 RH |
7348 | else |
7349 | { | |
7350 | /* Allocate a LANG_SPECIFIC structure for V, if needed. */ | |
7351 | if (DECL_LANG_SPECIFIC (v) == NULL) | |
7352 | { | |
7353 | retrofit_lang_decl (v); | |
7354 | ||
7355 | /* Make sure that DECL_DISCRIMINATOR_P continues to be true | |
7356 | after the allocation of the lang_decl structure. */ | |
7357 | if (DECL_DISCRIMINATOR_P (v)) | |
b97e8a14 | 7358 | DECL_LANG_SPECIFIC (v)->u.base.u2sel = 1; |
1799e5d5 RH |
7359 | } |
7360 | ||
3048c0c7 | 7361 | if (! CP_DECL_THREAD_LOCAL_P (v)) |
1799e5d5 | 7362 | { |
3048c0c7 | 7363 | CP_DECL_THREAD_LOCAL_P (v) = true; |
56363ffd | 7364 | set_decl_tls_model (v, decl_default_tls_model (v)); |
1799e5d5 RH |
7365 | /* If rtl has been already set for this var, call |
7366 | make_decl_rtl once again, so that encode_section_info | |
7367 | has a chance to look at the new decl flags. */ | |
7368 | if (DECL_RTL_SET_P (v)) | |
7369 | make_decl_rtl (v); | |
7370 | } | |
7371 | CP_DECL_THREADPRIVATE_P (v) = 1; | |
7372 | } | |
7373 | } | |
7374 | } | |
7375 | ||
7376 | /* Build an OpenMP structured block. */ | |
7377 | ||
7378 | tree | |
7379 | begin_omp_structured_block (void) | |
7380 | { | |
7381 | return do_pushlevel (sk_omp); | |
7382 | } | |
7383 | ||
7384 | tree | |
7385 | finish_omp_structured_block (tree block) | |
7386 | { | |
7387 | return do_poplevel (block); | |
7388 | } | |
7389 | ||
88bae6f4 | 7390 | /* Similarly, except force the retention of the BLOCK. */ |
41dbbb37 TS |
7391 | |
7392 | tree | |
88bae6f4 | 7393 | begin_omp_parallel (void) |
41dbbb37 | 7394 | { |
88bae6f4 TS |
7395 | keep_next_level (true); |
7396 | return begin_omp_structured_block (); | |
41dbbb37 TS |
7397 | } |
7398 | ||
88bae6f4 TS |
7399 | /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound |
7400 | statement. */ | |
41dbbb37 TS |
7401 | |
7402 | tree | |
88bae6f4 | 7403 | finish_oacc_data (tree clauses, tree block) |
41dbbb37 TS |
7404 | { |
7405 | tree stmt; | |
7406 | ||
7407 | block = finish_omp_structured_block (block); | |
7408 | ||
88bae6f4 | 7409 | stmt = make_node (OACC_DATA); |
41dbbb37 | 7410 | TREE_TYPE (stmt) = void_type_node; |
88bae6f4 TS |
7411 | OACC_DATA_CLAUSES (stmt) = clauses; |
7412 | OACC_DATA_BODY (stmt) = block; | |
41dbbb37 TS |
7413 | |
7414 | return add_stmt (stmt); | |
7415 | } | |
7416 | ||
37d5ad46 JB |
7417 | /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound |
7418 | statement. */ | |
7419 | ||
7420 | tree | |
7421 | finish_oacc_host_data (tree clauses, tree block) | |
7422 | { | |
7423 | tree stmt; | |
7424 | ||
7425 | block = finish_omp_structured_block (block); | |
7426 | ||
7427 | stmt = make_node (OACC_HOST_DATA); | |
7428 | TREE_TYPE (stmt) = void_type_node; | |
7429 | OACC_HOST_DATA_CLAUSES (stmt) = clauses; | |
7430 | OACC_HOST_DATA_BODY (stmt) = block; | |
7431 | ||
7432 | return add_stmt (stmt); | |
7433 | } | |
7434 | ||
88bae6f4 TS |
7435 | /* Generate OMP construct CODE, with BODY and CLAUSES as its compound |
7436 | statement. */ | |
41dbbb37 TS |
7437 | |
7438 | tree | |
88bae6f4 | 7439 | finish_omp_construct (enum tree_code code, tree body, tree clauses) |
41dbbb37 | 7440 | { |
88bae6f4 | 7441 | body = finish_omp_structured_block (body); |
41dbbb37 | 7442 | |
88bae6f4 | 7443 | tree stmt = make_node (code); |
41dbbb37 | 7444 | TREE_TYPE (stmt) = void_type_node; |
88bae6f4 TS |
7445 | OMP_BODY (stmt) = body; |
7446 | OMP_CLAUSES (stmt) = clauses; | |
41dbbb37 TS |
7447 | |
7448 | return add_stmt (stmt); | |
7449 | } | |
7450 | ||
1799e5d5 RH |
7451 | tree |
7452 | finish_omp_parallel (tree clauses, tree body) | |
7453 | { | |
7454 | tree stmt; | |
7455 | ||
7456 | body = finish_omp_structured_block (body); | |
b850de4f | 7457 | |
1799e5d5 RH |
7458 | stmt = make_node (OMP_PARALLEL); |
7459 | TREE_TYPE (stmt) = void_type_node; | |
7460 | OMP_PARALLEL_CLAUSES (stmt) = clauses; | |
7461 | OMP_PARALLEL_BODY (stmt) = body; | |
54f7877c | 7462 | |
1799e5d5 RH |
7463 | return add_stmt (stmt); |
7464 | } | |
7465 | ||
a68ab351 JJ |
7466 | tree |
7467 | begin_omp_task (void) | |
7468 | { | |
7469 | keep_next_level (true); | |
7470 | return begin_omp_structured_block (); | |
7471 | } | |
7472 | ||
7473 | tree | |
7474 | finish_omp_task (tree clauses, tree body) | |
7475 | { | |
7476 | tree stmt; | |
7477 | ||
7478 | body = finish_omp_structured_block (body); | |
7479 | ||
7480 | stmt = make_node (OMP_TASK); | |
7481 | TREE_TYPE (stmt) = void_type_node; | |
7482 | OMP_TASK_CLAUSES (stmt) = clauses; | |
7483 | OMP_TASK_BODY (stmt) = body; | |
7484 | ||
7485 | return add_stmt (stmt); | |
7486 | } | |
7487 | ||
7488 | /* Helper function for finish_omp_for. Convert Ith random access iterator | |
7489 | into integral iterator. Return FALSE if successful. */ | |
7490 | ||
7491 | static bool | |
d9a6bd32 | 7492 | handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code, |
e01d41e5 JJ |
7493 | tree declv, tree orig_declv, tree initv, |
7494 | tree condv, tree incrv, tree *body, | |
7495 | tree *pre_body, tree &clauses, tree *lastp, | |
7496 | int collapse, int ordered) | |
a68ab351 JJ |
7497 | { |
7498 | tree diff, iter_init, iter_incr = NULL, last; | |
7499 | tree incr_var = NULL, orig_pre_body, orig_body, c; | |
7500 | tree decl = TREE_VEC_ELT (declv, i); | |
7501 | tree init = TREE_VEC_ELT (initv, i); | |
7502 | tree cond = TREE_VEC_ELT (condv, i); | |
7503 | tree incr = TREE_VEC_ELT (incrv, i); | |
7504 | tree iter = decl; | |
7505 | location_t elocus = locus; | |
7506 | ||
7507 | if (init && EXPR_HAS_LOCATION (init)) | |
7508 | elocus = EXPR_LOCATION (init); | |
7509 | ||
cda0a029 | 7510 | cond = cp_fully_fold (cond); |
a68ab351 JJ |
7511 | switch (TREE_CODE (cond)) |
7512 | { | |
7513 | case GT_EXPR: | |
7514 | case GE_EXPR: | |
7515 | case LT_EXPR: | |
7516 | case LE_EXPR: | |
9a771876 | 7517 | case NE_EXPR: |
c5cdb03f JJ |
7518 | if (TREE_OPERAND (cond, 1) == iter) |
7519 | cond = build2 (swap_tree_comparison (TREE_CODE (cond)), | |
7520 | TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0)); | |
a68ab351 JJ |
7521 | if (TREE_OPERAND (cond, 0) != iter) |
7522 | cond = error_mark_node; | |
7523 | else | |
7524 | { | |
f330f599 PC |
7525 | tree tem = build_x_binary_op (EXPR_LOCATION (cond), |
7526 | TREE_CODE (cond), | |
4fe977f2 | 7527 | iter, ERROR_MARK, |
a68ab351 JJ |
7528 | TREE_OPERAND (cond, 1), ERROR_MARK, |
7529 | NULL, tf_warning_or_error); | |
7530 | if (error_operand_p (tem)) | |
7531 | return true; | |
7532 | } | |
7533 | break; | |
7534 | default: | |
7535 | cond = error_mark_node; | |
7536 | break; | |
7537 | } | |
7538 | if (cond == error_mark_node) | |
7539 | { | |
69bc6bff | 7540 | error_at (elocus, "invalid controlling predicate"); |
a68ab351 JJ |
7541 | return true; |
7542 | } | |
f330f599 | 7543 | diff = build_x_binary_op (elocus, MINUS_EXPR, TREE_OPERAND (cond, 1), |
a68ab351 JJ |
7544 | ERROR_MARK, iter, ERROR_MARK, NULL, |
7545 | tf_warning_or_error); | |
cda0a029 | 7546 | diff = cp_fully_fold (diff); |
a68ab351 JJ |
7547 | if (error_operand_p (diff)) |
7548 | return true; | |
7549 | if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE) | |
7550 | { | |
69bc6bff MLI |
7551 | error_at (elocus, "difference between %qE and %qD does not have integer type", |
7552 | TREE_OPERAND (cond, 1), iter); | |
a68ab351 JJ |
7553 | return true; |
7554 | } | |
e01d41e5 JJ |
7555 | if (!c_omp_check_loop_iv_exprs (locus, orig_declv, |
7556 | TREE_VEC_ELT (declv, i), NULL_TREE, | |
7557 | cond, cp_walk_subtrees)) | |
7558 | return true; | |
a68ab351 JJ |
7559 | |
7560 | switch (TREE_CODE (incr)) | |
7561 | { | |
7562 | case PREINCREMENT_EXPR: | |
7563 | case PREDECREMENT_EXPR: | |
7564 | case POSTINCREMENT_EXPR: | |
7565 | case POSTDECREMENT_EXPR: | |
7566 | if (TREE_OPERAND (incr, 0) != iter) | |
7567 | { | |
7568 | incr = error_mark_node; | |
7569 | break; | |
7570 | } | |
f330f599 PC |
7571 | iter_incr = build_x_unary_op (EXPR_LOCATION (incr), |
7572 | TREE_CODE (incr), iter, | |
a68ab351 JJ |
7573 | tf_warning_or_error); |
7574 | if (error_operand_p (iter_incr)) | |
7575 | return true; | |
7576 | else if (TREE_CODE (incr) == PREINCREMENT_EXPR | |
7577 | || TREE_CODE (incr) == POSTINCREMENT_EXPR) | |
7578 | incr = integer_one_node; | |
7579 | else | |
7580 | incr = integer_minus_one_node; | |
7581 | break; | |
7582 | case MODIFY_EXPR: | |
7583 | if (TREE_OPERAND (incr, 0) != iter) | |
7584 | incr = error_mark_node; | |
7585 | else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR | |
7586 | || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR) | |
7587 | { | |
7588 | tree rhs = TREE_OPERAND (incr, 1); | |
7589 | if (TREE_OPERAND (rhs, 0) == iter) | |
7590 | { | |
7591 | if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1))) | |
7592 | != INTEGER_TYPE) | |
7593 | incr = error_mark_node; | |
7594 | else | |
7595 | { | |
f330f599 PC |
7596 | iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs), |
7597 | iter, TREE_CODE (rhs), | |
a68ab351 JJ |
7598 | TREE_OPERAND (rhs, 1), |
7599 | tf_warning_or_error); | |
7600 | if (error_operand_p (iter_incr)) | |
7601 | return true; | |
7602 | incr = TREE_OPERAND (rhs, 1); | |
4b978f96 PC |
7603 | incr = cp_convert (TREE_TYPE (diff), incr, |
7604 | tf_warning_or_error); | |
a68ab351 JJ |
7605 | if (TREE_CODE (rhs) == MINUS_EXPR) |
7606 | { | |
7607 | incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr); | |
cda0a029 | 7608 | incr = fold_simple (incr); |
a68ab351 JJ |
7609 | } |
7610 | if (TREE_CODE (incr) != INTEGER_CST | |
7611 | && (TREE_CODE (incr) != NOP_EXPR | |
7612 | || (TREE_CODE (TREE_OPERAND (incr, 0)) | |
7613 | != INTEGER_CST))) | |
7614 | iter_incr = NULL; | |
7615 | } | |
7616 | } | |
7617 | else if (TREE_OPERAND (rhs, 1) == iter) | |
7618 | { | |
7619 | if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE | |
7620 | || TREE_CODE (rhs) != PLUS_EXPR) | |
7621 | incr = error_mark_node; | |
7622 | else | |
7623 | { | |
f330f599 PC |
7624 | iter_incr = build_x_binary_op (EXPR_LOCATION (rhs), |
7625 | PLUS_EXPR, | |
a68ab351 JJ |
7626 | TREE_OPERAND (rhs, 0), |
7627 | ERROR_MARK, iter, | |
7628 | ERROR_MARK, NULL, | |
7629 | tf_warning_or_error); | |
7630 | if (error_operand_p (iter_incr)) | |
7631 | return true; | |
f330f599 PC |
7632 | iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs), |
7633 | iter, NOP_EXPR, | |
a68ab351 JJ |
7634 | iter_incr, |
7635 | tf_warning_or_error); | |
7636 | if (error_operand_p (iter_incr)) | |
7637 | return true; | |
7638 | incr = TREE_OPERAND (rhs, 0); | |
7639 | iter_incr = NULL; | |
7640 | } | |
7641 | } | |
7642 | else | |
7643 | incr = error_mark_node; | |
7644 | } | |
7645 | else | |
7646 | incr = error_mark_node; | |
7647 | break; | |
7648 | default: | |
7649 | incr = error_mark_node; | |
7650 | break; | |
7651 | } | |
7652 | ||
7653 | if (incr == error_mark_node) | |
7654 | { | |
69bc6bff | 7655 | error_at (elocus, "invalid increment expression"); |
a68ab351 JJ |
7656 | return true; |
7657 | } | |
7658 | ||
4b978f96 | 7659 | incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error); |
d9a6bd32 | 7660 | bool taskloop_iv_seen = false; |
a68ab351 JJ |
7661 | for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) |
7662 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE | |
7663 | && OMP_CLAUSE_DECL (c) == iter) | |
d9a6bd32 JJ |
7664 | { |
7665 | if (code == OMP_TASKLOOP) | |
7666 | { | |
7667 | taskloop_iv_seen = true; | |
7668 | OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c) = 1; | |
7669 | } | |
7670 | break; | |
7671 | } | |
7672 | else if (code == OMP_TASKLOOP | |
7673 | && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE | |
7674 | && OMP_CLAUSE_DECL (c) == iter) | |
7675 | { | |
7676 | taskloop_iv_seen = true; | |
7677 | OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1; | |
7678 | } | |
a68ab351 JJ |
7679 | |
7680 | decl = create_temporary_var (TREE_TYPE (diff)); | |
7681 | pushdecl (decl); | |
7682 | add_decl_expr (decl); | |
7683 | last = create_temporary_var (TREE_TYPE (diff)); | |
7684 | pushdecl (last); | |
7685 | add_decl_expr (last); | |
d9a6bd32 JJ |
7686 | if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST |
7687 | && (!ordered || (i < collapse && collapse > 1))) | |
a68ab351 JJ |
7688 | { |
7689 | incr_var = create_temporary_var (TREE_TYPE (diff)); | |
7690 | pushdecl (incr_var); | |
7691 | add_decl_expr (incr_var); | |
7692 | } | |
7693 | gcc_assert (stmts_are_full_exprs_p ()); | |
d9a6bd32 JJ |
7694 | tree diffvar = NULL_TREE; |
7695 | if (code == OMP_TASKLOOP) | |
7696 | { | |
7697 | if (!taskloop_iv_seen) | |
7698 | { | |
7699 | tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE); | |
7700 | OMP_CLAUSE_DECL (ivc) = iter; | |
7701 | cxx_omp_finish_clause (ivc, NULL); | |
7702 | OMP_CLAUSE_CHAIN (ivc) = clauses; | |
7703 | clauses = ivc; | |
7704 | } | |
7705 | tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE); | |
7706 | OMP_CLAUSE_DECL (lvc) = last; | |
7707 | OMP_CLAUSE_CHAIN (lvc) = clauses; | |
7708 | clauses = lvc; | |
7709 | diffvar = create_temporary_var (TREE_TYPE (diff)); | |
7710 | pushdecl (diffvar); | |
7711 | add_decl_expr (diffvar); | |
7712 | } | |
a68ab351 JJ |
7713 | |
7714 | orig_pre_body = *pre_body; | |
7715 | *pre_body = push_stmt_list (); | |
7716 | if (orig_pre_body) | |
7717 | add_stmt (orig_pre_body); | |
7718 | if (init != NULL) | |
f330f599 PC |
7719 | finish_expr_stmt (build_x_modify_expr (elocus, |
7720 | iter, NOP_EXPR, init, | |
a68ab351 JJ |
7721 | tf_warning_or_error)); |
7722 | init = build_int_cst (TREE_TYPE (diff), 0); | |
d9a6bd32 JJ |
7723 | if (c && iter_incr == NULL |
7724 | && (!ordered || (i < collapse && collapse > 1))) | |
a68ab351 | 7725 | { |
d9a6bd32 JJ |
7726 | if (incr_var) |
7727 | { | |
7728 | finish_expr_stmt (build_x_modify_expr (elocus, | |
7729 | incr_var, NOP_EXPR, | |
7730 | incr, tf_warning_or_error)); | |
7731 | incr = incr_var; | |
7732 | } | |
f330f599 PC |
7733 | iter_incr = build_x_modify_expr (elocus, |
7734 | iter, PLUS_EXPR, incr, | |
a68ab351 JJ |
7735 | tf_warning_or_error); |
7736 | } | |
d9a6bd32 JJ |
7737 | if (c && ordered && i < collapse && collapse > 1) |
7738 | iter_incr = incr; | |
f330f599 PC |
7739 | finish_expr_stmt (build_x_modify_expr (elocus, |
7740 | last, NOP_EXPR, init, | |
a68ab351 | 7741 | tf_warning_or_error)); |
d9a6bd32 JJ |
7742 | if (diffvar) |
7743 | { | |
7744 | finish_expr_stmt (build_x_modify_expr (elocus, | |
7745 | diffvar, NOP_EXPR, | |
7746 | diff, tf_warning_or_error)); | |
7747 | diff = diffvar; | |
7748 | } | |
a68ab351 JJ |
7749 | *pre_body = pop_stmt_list (*pre_body); |
7750 | ||
ba47d38d AH |
7751 | cond = cp_build_binary_op (elocus, |
7752 | TREE_CODE (cond), decl, diff, | |
a68ab351 | 7753 | tf_warning_or_error); |
32e8bb8e | 7754 | incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR, |
c2255bc4 | 7755 | elocus, incr, NULL_TREE); |
a68ab351 JJ |
7756 | |
7757 | orig_body = *body; | |
7758 | *body = push_stmt_list (); | |
7759 | iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last); | |
f330f599 PC |
7760 | iter_init = build_x_modify_expr (elocus, |
7761 | iter, PLUS_EXPR, iter_init, | |
a68ab351 | 7762 | tf_warning_or_error); |
4e4d2c41 JJ |
7763 | if (iter_init != error_mark_node) |
7764 | iter_init = build1 (NOP_EXPR, void_type_node, iter_init); | |
a68ab351 | 7765 | finish_expr_stmt (iter_init); |
f330f599 PC |
7766 | finish_expr_stmt (build_x_modify_expr (elocus, |
7767 | last, NOP_EXPR, decl, | |
a68ab351 JJ |
7768 | tf_warning_or_error)); |
7769 | add_stmt (orig_body); | |
7770 | *body = pop_stmt_list (*body); | |
7771 | ||
7772 | if (c) | |
7773 | { | |
7774 | OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list (); | |
d9a6bd32 JJ |
7775 | if (!ordered) |
7776 | finish_expr_stmt (iter_incr); | |
7777 | else | |
7778 | { | |
7779 | iter_init = decl; | |
7780 | if (i < collapse && collapse > 1 && !error_operand_p (iter_incr)) | |
7781 | iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff), | |
7782 | iter_init, iter_incr); | |
7783 | iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last); | |
7784 | iter_init = build_x_modify_expr (elocus, | |
7785 | iter, PLUS_EXPR, iter_init, | |
7786 | tf_warning_or_error); | |
7787 | if (iter_init != error_mark_node) | |
7788 | iter_init = build1 (NOP_EXPR, void_type_node, iter_init); | |
7789 | finish_expr_stmt (iter_init); | |
7790 | } | |
a68ab351 JJ |
7791 | OMP_CLAUSE_LASTPRIVATE_STMT (c) |
7792 | = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c)); | |
7793 | } | |
7794 | ||
7795 | TREE_VEC_ELT (declv, i) = decl; | |
7796 | TREE_VEC_ELT (initv, i) = init; | |
7797 | TREE_VEC_ELT (condv, i) = cond; | |
7798 | TREE_VEC_ELT (incrv, i) = incr; | |
9a771876 | 7799 | *lastp = last; |
a68ab351 JJ |
7800 | |
7801 | return false; | |
7802 | } | |
7803 | ||
1799e5d5 RH |
7804 | /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR |
7805 | are directly for their associated operands in the statement. DECL | |
7806 | and INIT are a combo; if DECL is NULL then INIT ought to be a | |
7807 | MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are | |
7808 | optional statements that need to go before the loop into its | |
7809 | sk_omp scope. */ | |
7810 | ||
7811 | tree | |
d9a6bd32 JJ |
7812 | finish_omp_for (location_t locus, enum tree_code code, tree declv, |
7813 | tree orig_declv, tree initv, tree condv, tree incrv, | |
e01d41e5 | 7814 | tree body, tree pre_body, vec<tree> *orig_inits, tree clauses) |
a68ab351 JJ |
7815 | { |
7816 | tree omp_for = NULL, orig_incr = NULL; | |
9a771876 JJ |
7817 | tree decl = NULL, init, cond, incr, orig_decl = NULL_TREE, block = NULL_TREE; |
7818 | tree last = NULL_TREE; | |
a68ab351 JJ |
7819 | location_t elocus; |
7820 | int i; | |
d9a6bd32 JJ |
7821 | int collapse = 1; |
7822 | int ordered = 0; | |
a68ab351 JJ |
7823 | |
7824 | gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv)); | |
7825 | gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv)); | |
7826 | gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv)); | |
d9a6bd32 JJ |
7827 | if (TREE_VEC_LENGTH (declv) > 1) |
7828 | { | |
7829 | tree c = find_omp_clause (clauses, OMP_CLAUSE_COLLAPSE); | |
7830 | if (c) | |
7831 | collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c)); | |
7832 | if (collapse != TREE_VEC_LENGTH (declv)) | |
7833 | ordered = TREE_VEC_LENGTH (declv); | |
7834 | } | |
a68ab351 JJ |
7835 | for (i = 0; i < TREE_VEC_LENGTH (declv); i++) |
7836 | { | |
7837 | decl = TREE_VEC_ELT (declv, i); | |
7838 | init = TREE_VEC_ELT (initv, i); | |
7839 | cond = TREE_VEC_ELT (condv, i); | |
7840 | incr = TREE_VEC_ELT (incrv, i); | |
7841 | elocus = locus; | |
7842 | ||
7843 | if (decl == NULL) | |
7844 | { | |
7845 | if (init != NULL) | |
7846 | switch (TREE_CODE (init)) | |
1799e5d5 | 7847 | { |
a68ab351 | 7848 | case MODIFY_EXPR: |
1799e5d5 | 7849 | decl = TREE_OPERAND (init, 0); |
a68ab351 JJ |
7850 | init = TREE_OPERAND (init, 1); |
7851 | break; | |
7852 | case MODOP_EXPR: | |
7853 | if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR) | |
7854 | { | |
7855 | decl = TREE_OPERAND (init, 0); | |
7856 | init = TREE_OPERAND (init, 2); | |
7857 | } | |
7858 | break; | |
7859 | default: | |
7860 | break; | |
1799e5d5 | 7861 | } |
1799e5d5 | 7862 | |
a68ab351 JJ |
7863 | if (decl == NULL) |
7864 | { | |
69bc6bff MLI |
7865 | error_at (locus, |
7866 | "expected iteration declaration or initialization"); | |
a68ab351 JJ |
7867 | return NULL; |
7868 | } | |
1799e5d5 | 7869 | } |
1799e5d5 | 7870 | |
a68ab351 JJ |
7871 | if (init && EXPR_HAS_LOCATION (init)) |
7872 | elocus = EXPR_LOCATION (init); | |
1799e5d5 RH |
7873 | |
7874 | if (cond == NULL) | |
7875 | { | |
69bc6bff | 7876 | error_at (elocus, "missing controlling predicate"); |
1799e5d5 RH |
7877 | return NULL; |
7878 | } | |
7879 | ||
7880 | if (incr == NULL) | |
7881 | { | |
69bc6bff | 7882 | error_at (elocus, "missing increment expression"); |
1799e5d5 RH |
7883 | return NULL; |
7884 | } | |
7885 | ||
a68ab351 JJ |
7886 | TREE_VEC_ELT (declv, i) = decl; |
7887 | TREE_VEC_ELT (initv, i) = init; | |
7888 | } | |
7889 | ||
e01d41e5 JJ |
7890 | if (orig_inits) |
7891 | { | |
7892 | bool fail = false; | |
7893 | tree orig_init; | |
7894 | FOR_EACH_VEC_ELT (*orig_inits, i, orig_init) | |
7895 | if (orig_init | |
7896 | && !c_omp_check_loop_iv_exprs (locus, declv, | |
7897 | TREE_VEC_ELT (declv, i), orig_init, | |
7898 | NULL_TREE, cp_walk_subtrees)) | |
7899 | fail = true; | |
7900 | if (fail) | |
7901 | return NULL; | |
7902 | } | |
7903 | ||
a68ab351 JJ |
7904 | if (dependent_omp_for_p (declv, initv, condv, incrv)) |
7905 | { | |
7906 | tree stmt; | |
7907 | ||
acf0174b | 7908 | stmt = make_node (code); |
1799e5d5 | 7909 | |
a68ab351 JJ |
7910 | for (i = 0; i < TREE_VEC_LENGTH (declv); i++) |
7911 | { | |
7912 | /* This is really just a place-holder. We'll be decomposing this | |
7913 | again and going through the cp_build_modify_expr path below when | |
7914 | we instantiate the thing. */ | |
7915 | TREE_VEC_ELT (initv, i) | |
7916 | = build2 (MODIFY_EXPR, void_type_node, TREE_VEC_ELT (declv, i), | |
7917 | TREE_VEC_ELT (initv, i)); | |
7918 | } | |
1799e5d5 RH |
7919 | |
7920 | TREE_TYPE (stmt) = void_type_node; | |
a68ab351 JJ |
7921 | OMP_FOR_INIT (stmt) = initv; |
7922 | OMP_FOR_COND (stmt) = condv; | |
7923 | OMP_FOR_INCR (stmt) = incrv; | |
1799e5d5 RH |
7924 | OMP_FOR_BODY (stmt) = body; |
7925 | OMP_FOR_PRE_BODY (stmt) = pre_body; | |
a68ab351 | 7926 | OMP_FOR_CLAUSES (stmt) = clauses; |
1799e5d5 RH |
7927 | |
7928 | SET_EXPR_LOCATION (stmt, locus); | |
7929 | return add_stmt (stmt); | |
7930 | } | |
7931 | ||
d9a6bd32 JJ |
7932 | if (!orig_declv) |
7933 | orig_declv = copy_node (declv); | |
7934 | ||
a68ab351 JJ |
7935 | if (processing_template_decl) |
7936 | orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv)); | |
1799e5d5 | 7937 | |
a68ab351 | 7938 | for (i = 0; i < TREE_VEC_LENGTH (declv); ) |
dadb19e0 | 7939 | { |
a68ab351 JJ |
7940 | decl = TREE_VEC_ELT (declv, i); |
7941 | init = TREE_VEC_ELT (initv, i); | |
7942 | cond = TREE_VEC_ELT (condv, i); | |
7943 | incr = TREE_VEC_ELT (incrv, i); | |
7944 | if (orig_incr) | |
7945 | TREE_VEC_ELT (orig_incr, i) = incr; | |
7946 | elocus = locus; | |
7947 | ||
7948 | if (init && EXPR_HAS_LOCATION (init)) | |
dadb19e0 | 7949 | elocus = EXPR_LOCATION (init); |
dadb19e0 | 7950 | |
a68ab351 JJ |
7951 | if (!DECL_P (decl)) |
7952 | { | |
69bc6bff | 7953 | error_at (elocus, "expected iteration declaration or initialization"); |
a68ab351 JJ |
7954 | return NULL; |
7955 | } | |
969c111d | 7956 | |
a68ab351 JJ |
7957 | if (incr && TREE_CODE (incr) == MODOP_EXPR) |
7958 | { | |
7959 | if (orig_incr) | |
7960 | TREE_VEC_ELT (orig_incr, i) = incr; | |
7961 | incr = cp_build_modify_expr (TREE_OPERAND (incr, 0), | |
7962 | TREE_CODE (TREE_OPERAND (incr, 1)), | |
7963 | TREE_OPERAND (incr, 2), | |
7964 | tf_warning_or_error); | |
7965 | } | |
7966 | ||
7967 | if (CLASS_TYPE_P (TREE_TYPE (decl))) | |
7968 | { | |
acf0174b JJ |
7969 | if (code == OMP_SIMD) |
7970 | { | |
7971 | error_at (elocus, "%<#pragma omp simd%> used with class " | |
7972 | "iteration variable %qE", decl); | |
7973 | return NULL; | |
7974 | } | |
9a771876 JJ |
7975 | if (code == CILK_FOR && i == 0) |
7976 | orig_decl = decl; | |
e01d41e5 JJ |
7977 | if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv, |
7978 | initv, condv, incrv, &body, | |
7979 | &pre_body, clauses, &last, | |
7980 | collapse, ordered)) | |
a68ab351 JJ |
7981 | return NULL; |
7982 | continue; | |
7983 | } | |
7984 | ||
7985 | if (!INTEGRAL_TYPE_P (TREE_TYPE (decl)) | |
50e10fa8 | 7986 | && !TYPE_PTR_P (TREE_TYPE (decl))) |
a68ab351 | 7987 | { |
69bc6bff | 7988 | error_at (elocus, "invalid type for iteration variable %qE", decl); |
a68ab351 JJ |
7989 | return NULL; |
7990 | } | |
969c111d | 7991 | |
b2ebd268 | 7992 | if (!processing_template_decl) |
8569b2d0 JJ |
7993 | { |
7994 | init = fold_build_cleanup_point_expr (TREE_TYPE (init), init); | |
7995 | init = cp_build_modify_expr (decl, NOP_EXPR, init, tf_warning_or_error); | |
7996 | } | |
7997 | else | |
7998 | init = build2 (MODIFY_EXPR, void_type_node, decl, init); | |
e4ebaef3 JJ |
7999 | if (cond |
8000 | && TREE_SIDE_EFFECTS (cond) | |
8001 | && COMPARISON_CLASS_P (cond) | |
8002 | && !processing_template_decl) | |
a68ab351 | 8003 | { |
e4ebaef3 JJ |
8004 | tree t = TREE_OPERAND (cond, 0); |
8005 | if (TREE_SIDE_EFFECTS (t) | |
8006 | && t != decl | |
8007 | && (TREE_CODE (t) != NOP_EXPR | |
8008 | || TREE_OPERAND (t, 0) != decl)) | |
8009 | TREE_OPERAND (cond, 0) | |
8010 | = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
a68ab351 | 8011 | |
e4ebaef3 JJ |
8012 | t = TREE_OPERAND (cond, 1); |
8013 | if (TREE_SIDE_EFFECTS (t) | |
8014 | && t != decl | |
8015 | && (TREE_CODE (t) != NOP_EXPR | |
8016 | || TREE_OPERAND (t, 0) != decl)) | |
8017 | TREE_OPERAND (cond, 1) | |
a68ab351 JJ |
8018 | = fold_build_cleanup_point_expr (TREE_TYPE (t), t); |
8019 | } | |
8020 | if (decl == error_mark_node || init == error_mark_node) | |
8021 | return NULL; | |
8022 | ||
8023 | TREE_VEC_ELT (declv, i) = decl; | |
8024 | TREE_VEC_ELT (initv, i) = init; | |
8025 | TREE_VEC_ELT (condv, i) = cond; | |
8026 | TREE_VEC_ELT (incrv, i) = incr; | |
8027 | i++; | |
969c111d | 8028 | } |
a68ab351 JJ |
8029 | |
8030 | if (IS_EMPTY_STMT (pre_body)) | |
8031 | pre_body = NULL; | |
8032 | ||
9a771876 JJ |
8033 | if (code == CILK_FOR && !processing_template_decl) |
8034 | block = push_stmt_list (); | |
8035 | ||
d9a6bd32 JJ |
8036 | omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv, |
8037 | incrv, body, pre_body); | |
a68ab351 | 8038 | |
e01d41e5 JJ |
8039 | /* Check for iterators appearing in lb, b or incr expressions. */ |
8040 | if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees)) | |
8041 | omp_for = NULL_TREE; | |
8042 | ||
a68ab351 | 8043 | if (omp_for == NULL) |
9a771876 JJ |
8044 | { |
8045 | if (block) | |
8046 | pop_stmt_list (block); | |
8047 | return NULL; | |
8048 | } | |
a68ab351 | 8049 | |
e01d41e5 JJ |
8050 | add_stmt (omp_for); |
8051 | ||
a68ab351 | 8052 | for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++) |
969c111d | 8053 | { |
e4ebaef3 JJ |
8054 | decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i), 0); |
8055 | incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i); | |
969c111d | 8056 | |
a68ab351 JJ |
8057 | if (TREE_CODE (incr) != MODIFY_EXPR) |
8058 | continue; | |
8059 | ||
8060 | if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1)) | |
e4ebaef3 JJ |
8061 | && BINARY_CLASS_P (TREE_OPERAND (incr, 1)) |
8062 | && !processing_template_decl) | |
a68ab351 | 8063 | { |
e4ebaef3 JJ |
8064 | tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0); |
8065 | if (TREE_SIDE_EFFECTS (t) | |
8066 | && t != decl | |
8067 | && (TREE_CODE (t) != NOP_EXPR | |
8068 | || TREE_OPERAND (t, 0) != decl)) | |
8069 | TREE_OPERAND (TREE_OPERAND (incr, 1), 0) | |
8070 | = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
a68ab351 | 8071 | |
e4ebaef3 JJ |
8072 | t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); |
8073 | if (TREE_SIDE_EFFECTS (t) | |
8074 | && t != decl | |
8075 | && (TREE_CODE (t) != NOP_EXPR | |
8076 | || TREE_OPERAND (t, 0) != decl)) | |
8077 | TREE_OPERAND (TREE_OPERAND (incr, 1), 1) | |
8078 | = fold_build_cleanup_point_expr (TREE_TYPE (t), t); | |
a68ab351 JJ |
8079 | } |
8080 | ||
8081 | if (orig_incr) | |
8082 | TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i); | |
969c111d | 8083 | } |
9a771876 JJ |
8084 | OMP_FOR_CLAUSES (omp_for) = clauses; |
8085 | ||
d9a6bd32 JJ |
8086 | /* For simd loops with non-static data member iterators, we could have added |
8087 | OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the | |
8088 | step at this point, fill it in. */ | |
8089 | if (code == OMP_SIMD && !processing_template_decl | |
8090 | && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1) | |
8091 | for (tree c = find_omp_clause (clauses, OMP_CLAUSE_LINEAR); c; | |
8092 | c = find_omp_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR)) | |
8093 | if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE) | |
8094 | { | |
8095 | decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0); | |
8096 | gcc_assert (decl == OMP_CLAUSE_DECL (c)); | |
8097 | incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0); | |
8098 | tree step, stept; | |
8099 | switch (TREE_CODE (incr)) | |
8100 | { | |
8101 | case PREINCREMENT_EXPR: | |
8102 | case POSTINCREMENT_EXPR: | |
8103 | /* c_omp_for_incr_canonicalize_ptr() should have been | |
8104 | called to massage things appropriately. */ | |
8105 | gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl))); | |
8106 | OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1); | |
8107 | break; | |
8108 | case PREDECREMENT_EXPR: | |
8109 | case POSTDECREMENT_EXPR: | |
8110 | /* c_omp_for_incr_canonicalize_ptr() should have been | |
8111 | called to massage things appropriately. */ | |
8112 | gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl))); | |
8113 | OMP_CLAUSE_LINEAR_STEP (c) | |
8114 | = build_int_cst (TREE_TYPE (decl), -1); | |
8115 | break; | |
8116 | case MODIFY_EXPR: | |
8117 | gcc_assert (TREE_OPERAND (incr, 0) == decl); | |
8118 | incr = TREE_OPERAND (incr, 1); | |
8119 | switch (TREE_CODE (incr)) | |
8120 | { | |
8121 | case PLUS_EXPR: | |
8122 | if (TREE_OPERAND (incr, 1) == decl) | |
8123 | step = TREE_OPERAND (incr, 0); | |
8124 | else | |
8125 | step = TREE_OPERAND (incr, 1); | |
8126 | break; | |
8127 | case MINUS_EXPR: | |
8128 | case POINTER_PLUS_EXPR: | |
8129 | gcc_assert (TREE_OPERAND (incr, 0) == decl); | |
8130 | step = TREE_OPERAND (incr, 1); | |
8131 | break; | |
8132 | default: | |
8133 | gcc_unreachable (); | |
8134 | } | |
8135 | stept = TREE_TYPE (decl); | |
8136 | if (POINTER_TYPE_P (stept)) | |
8137 | stept = sizetype; | |
8138 | step = fold_convert (stept, step); | |
8139 | if (TREE_CODE (incr) == MINUS_EXPR) | |
8140 | step = fold_build1 (NEGATE_EXPR, stept, step); | |
8141 | OMP_CLAUSE_LINEAR_STEP (c) = step; | |
8142 | break; | |
8143 | default: | |
8144 | gcc_unreachable (); | |
8145 | } | |
8146 | } | |
8147 | ||
9a771876 JJ |
8148 | if (block) |
8149 | { | |
8150 | tree omp_par = make_node (OMP_PARALLEL); | |
8151 | TREE_TYPE (omp_par) = void_type_node; | |
8152 | OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE; | |
8153 | tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); | |
8154 | TREE_SIDE_EFFECTS (bind) = 1; | |
8155 | BIND_EXPR_BODY (bind) = pop_stmt_list (block); | |
8156 | OMP_PARALLEL_BODY (omp_par) = bind; | |
8157 | if (OMP_FOR_PRE_BODY (omp_for)) | |
8158 | { | |
8159 | add_stmt (OMP_FOR_PRE_BODY (omp_for)); | |
8160 | OMP_FOR_PRE_BODY (omp_for) = NULL_TREE; | |
8161 | } | |
8162 | init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0); | |
8163 | decl = TREE_OPERAND (init, 0); | |
8164 | cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0); | |
8165 | incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0); | |
8166 | tree t = TREE_OPERAND (cond, 1), c, clauses, *pc; | |
8167 | clauses = OMP_FOR_CLAUSES (omp_for); | |
8168 | OMP_FOR_CLAUSES (omp_for) = NULL_TREE; | |
8169 | for (pc = &clauses; *pc; ) | |
8170 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_SCHEDULE) | |
8171 | { | |
8172 | gcc_assert (OMP_FOR_CLAUSES (omp_for) == NULL_TREE); | |
8173 | OMP_FOR_CLAUSES (omp_for) = *pc; | |
8174 | *pc = OMP_CLAUSE_CHAIN (*pc); | |
8175 | OMP_CLAUSE_CHAIN (OMP_FOR_CLAUSES (omp_for)) = NULL_TREE; | |
8176 | } | |
8177 | else | |
8178 | { | |
8179 | gcc_assert (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_FIRSTPRIVATE); | |
8180 | pc = &OMP_CLAUSE_CHAIN (*pc); | |
8181 | } | |
8182 | if (TREE_CODE (t) != INTEGER_CST) | |
8183 | { | |
8184 | TREE_OPERAND (cond, 1) = get_temp_regvar (TREE_TYPE (t), t); | |
8185 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
8186 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1); | |
8187 | OMP_CLAUSE_CHAIN (c) = clauses; | |
8188 | clauses = c; | |
8189 | } | |
8190 | if (TREE_CODE (incr) == MODIFY_EXPR) | |
8191 | { | |
8192 | t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); | |
8193 | if (TREE_CODE (t) != INTEGER_CST) | |
8194 | { | |
8195 | TREE_OPERAND (TREE_OPERAND (incr, 1), 1) | |
8196 | = get_temp_regvar (TREE_TYPE (t), t); | |
8197 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
8198 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); | |
8199 | OMP_CLAUSE_CHAIN (c) = clauses; | |
8200 | clauses = c; | |
8201 | } | |
8202 | } | |
8203 | t = TREE_OPERAND (init, 1); | |
8204 | if (TREE_CODE (t) != INTEGER_CST) | |
8205 | { | |
8206 | TREE_OPERAND (init, 1) = get_temp_regvar (TREE_TYPE (t), t); | |
8207 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
8208 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1); | |
8209 | OMP_CLAUSE_CHAIN (c) = clauses; | |
8210 | clauses = c; | |
8211 | } | |
8212 | if (orig_decl && orig_decl != decl) | |
8213 | { | |
8214 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
8215 | OMP_CLAUSE_DECL (c) = orig_decl; | |
8216 | OMP_CLAUSE_CHAIN (c) = clauses; | |
8217 | clauses = c; | |
8218 | } | |
8219 | if (last) | |
8220 | { | |
8221 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
8222 | OMP_CLAUSE_DECL (c) = last; | |
8223 | OMP_CLAUSE_CHAIN (c) = clauses; | |
8224 | clauses = c; | |
8225 | } | |
8226 | c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE); | |
8227 | OMP_CLAUSE_DECL (c) = decl; | |
8228 | OMP_CLAUSE_CHAIN (c) = clauses; | |
8229 | clauses = c; | |
8230 | c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_); | |
8231 | OMP_CLAUSE_OPERAND (c, 0) | |
8232 | = cilk_for_number_of_iterations (omp_for); | |
8233 | OMP_CLAUSE_CHAIN (c) = clauses; | |
d9a6bd32 | 8234 | OMP_PARALLEL_CLAUSES (omp_par) = finish_omp_clauses (c, false); |
9a771876 JJ |
8235 | add_stmt (omp_par); |
8236 | return omp_par; | |
8237 | } | |
8238 | else if (code == CILK_FOR && processing_template_decl) | |
8239 | { | |
8240 | tree c, clauses = OMP_FOR_CLAUSES (omp_for); | |
8241 | if (orig_decl && orig_decl != decl) | |
8242 | { | |
8243 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
8244 | OMP_CLAUSE_DECL (c) = orig_decl; | |
8245 | OMP_CLAUSE_CHAIN (c) = clauses; | |
8246 | clauses = c; | |
8247 | } | |
8248 | if (last) | |
8249 | { | |
8250 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); | |
8251 | OMP_CLAUSE_DECL (c) = last; | |
8252 | OMP_CLAUSE_CHAIN (c) = clauses; | |
8253 | clauses = c; | |
8254 | } | |
8255 | OMP_FOR_CLAUSES (omp_for) = clauses; | |
8256 | } | |
969c111d | 8257 | return omp_for; |
1799e5d5 RH |
8258 | } |
8259 | ||
8260 | void | |
20906c66 | 8261 | finish_omp_atomic (enum tree_code code, enum tree_code opcode, tree lhs, |
acf0174b | 8262 | tree rhs, tree v, tree lhs1, tree rhs1, bool seq_cst) |
1799e5d5 | 8263 | { |
239371f9 JJ |
8264 | tree orig_lhs; |
8265 | tree orig_rhs; | |
20906c66 JJ |
8266 | tree orig_v; |
8267 | tree orig_lhs1; | |
8268 | tree orig_rhs1; | |
239371f9 | 8269 | bool dependent_p; |
e6bd5565 MM |
8270 | tree stmt; |
8271 | ||
239371f9 JJ |
8272 | orig_lhs = lhs; |
8273 | orig_rhs = rhs; | |
20906c66 JJ |
8274 | orig_v = v; |
8275 | orig_lhs1 = lhs1; | |
8276 | orig_rhs1 = rhs1; | |
239371f9 JJ |
8277 | dependent_p = false; |
8278 | stmt = NULL_TREE; | |
8279 | ||
8280 | /* Even in a template, we can detect invalid uses of the atomic | |
8281 | pragma if neither LHS nor RHS is type-dependent. */ | |
8282 | if (processing_template_decl) | |
e6bd5565 | 8283 | { |
239371f9 | 8284 | dependent_p = (type_dependent_expression_p (lhs) |
20906c66 JJ |
8285 | || (rhs && type_dependent_expression_p (rhs)) |
8286 | || (v && type_dependent_expression_p (v)) | |
8287 | || (lhs1 && type_dependent_expression_p (lhs1)) | |
8288 | || (rhs1 && type_dependent_expression_p (rhs1))); | |
239371f9 | 8289 | if (!dependent_p) |
e6bd5565 MM |
8290 | { |
8291 | lhs = build_non_dependent_expr (lhs); | |
20906c66 JJ |
8292 | if (rhs) |
8293 | rhs = build_non_dependent_expr (rhs); | |
8294 | if (v) | |
8295 | v = build_non_dependent_expr (v); | |
8296 | if (lhs1) | |
8297 | lhs1 = build_non_dependent_expr (lhs1); | |
8298 | if (rhs1) | |
8299 | rhs1 = build_non_dependent_expr (rhs1); | |
e6bd5565 | 8300 | } |
239371f9 JJ |
8301 | } |
8302 | if (!dependent_p) | |
8303 | { | |
acf0174b JJ |
8304 | bool swapped = false; |
8305 | if (rhs1 && cp_tree_equal (lhs, rhs)) | |
8306 | { | |
6b4db501 | 8307 | std::swap (rhs, rhs1); |
acf0174b JJ |
8308 | swapped = !commutative_tree_code (opcode); |
8309 | } | |
8310 | if (rhs1 && !cp_tree_equal (lhs, rhs1)) | |
8311 | { | |
8312 | if (code == OMP_ATOMIC) | |
8313 | error ("%<#pragma omp atomic update%> uses two different " | |
8314 | "expressions for memory"); | |
8315 | else | |
8316 | error ("%<#pragma omp atomic capture%> uses two different " | |
8317 | "expressions for memory"); | |
8318 | return; | |
8319 | } | |
8320 | if (lhs1 && !cp_tree_equal (lhs, lhs1)) | |
8321 | { | |
8322 | if (code == OMP_ATOMIC) | |
8323 | error ("%<#pragma omp atomic update%> uses two different " | |
8324 | "expressions for memory"); | |
8325 | else | |
8326 | error ("%<#pragma omp atomic capture%> uses two different " | |
8327 | "expressions for memory"); | |
8328 | return; | |
8329 | } | |
20906c66 | 8330 | stmt = c_finish_omp_atomic (input_location, code, opcode, lhs, rhs, |
e01d41e5 JJ |
8331 | v, lhs1, rhs1, swapped, seq_cst, |
8332 | processing_template_decl != 0); | |
239371f9 JJ |
8333 | if (stmt == error_mark_node) |
8334 | return; | |
e6bd5565 | 8335 | } |
239371f9 | 8336 | if (processing_template_decl) |
20906c66 JJ |
8337 | { |
8338 | if (code == OMP_ATOMIC_READ) | |
8339 | { | |
f330f599 PC |
8340 | stmt = build_min_nt_loc (EXPR_LOCATION (orig_lhs), |
8341 | OMP_ATOMIC_READ, orig_lhs); | |
acf0174b | 8342 | OMP_ATOMIC_SEQ_CST (stmt) = seq_cst; |
20906c66 JJ |
8343 | stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt); |
8344 | } | |
8345 | else | |
8346 | { | |
8347 | if (opcode == NOP_EXPR) | |
8348 | stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs); | |
8349 | else | |
8350 | stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs); | |
8351 | if (orig_rhs1) | |
f330f599 PC |
8352 | stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1), |
8353 | COMPOUND_EXPR, orig_rhs1, stmt); | |
20906c66 JJ |
8354 | if (code != OMP_ATOMIC) |
8355 | { | |
f330f599 PC |
8356 | stmt = build_min_nt_loc (EXPR_LOCATION (orig_lhs1), |
8357 | code, orig_lhs1, stmt); | |
acf0174b | 8358 | OMP_ATOMIC_SEQ_CST (stmt) = seq_cst; |
20906c66 JJ |
8359 | stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt); |
8360 | } | |
8361 | } | |
8362 | stmt = build2 (OMP_ATOMIC, void_type_node, integer_zero_node, stmt); | |
acf0174b | 8363 | OMP_ATOMIC_SEQ_CST (stmt) = seq_cst; |
20906c66 | 8364 | } |
e3f505d8 | 8365 | finish_expr_stmt (stmt); |
1799e5d5 RH |
8366 | } |
8367 | ||
8368 | void | |
8369 | finish_omp_barrier (void) | |
8370 | { | |
e79983f4 | 8371 | tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER); |
9771b263 | 8372 | vec<tree, va_gc> *vec = make_tree_vector (); |
c166b898 ILT |
8373 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); |
8374 | release_tree_vector (vec); | |
1799e5d5 RH |
8375 | finish_expr_stmt (stmt); |
8376 | } | |
8377 | ||
8378 | void | |
8379 | finish_omp_flush (void) | |
8380 | { | |
e79983f4 | 8381 | tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE); |
9771b263 | 8382 | vec<tree, va_gc> *vec = make_tree_vector (); |
c166b898 ILT |
8383 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); |
8384 | release_tree_vector (vec); | |
1799e5d5 RH |
8385 | finish_expr_stmt (stmt); |
8386 | } | |
8387 | ||
a68ab351 JJ |
8388 | void |
8389 | finish_omp_taskwait (void) | |
1799e5d5 | 8390 | { |
e79983f4 | 8391 | tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT); |
9771b263 | 8392 | vec<tree, va_gc> *vec = make_tree_vector (); |
c166b898 ILT |
8393 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); |
8394 | release_tree_vector (vec); | |
a68ab351 | 8395 | finish_expr_stmt (stmt); |
1799e5d5 | 8396 | } |
20906c66 JJ |
8397 | |
8398 | void | |
8399 | finish_omp_taskyield (void) | |
8400 | { | |
e79983f4 | 8401 | tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD); |
9771b263 | 8402 | vec<tree, va_gc> *vec = make_tree_vector (); |
20906c66 JJ |
8403 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); |
8404 | release_tree_vector (vec); | |
8405 | finish_expr_stmt (stmt); | |
8406 | } | |
acf0174b JJ |
8407 | |
8408 | void | |
8409 | finish_omp_cancel (tree clauses) | |
8410 | { | |
8411 | tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL); | |
8412 | int mask = 0; | |
8413 | if (find_omp_clause (clauses, OMP_CLAUSE_PARALLEL)) | |
8414 | mask = 1; | |
8415 | else if (find_omp_clause (clauses, OMP_CLAUSE_FOR)) | |
8416 | mask = 2; | |
8417 | else if (find_omp_clause (clauses, OMP_CLAUSE_SECTIONS)) | |
8418 | mask = 4; | |
8419 | else if (find_omp_clause (clauses, OMP_CLAUSE_TASKGROUP)) | |
8420 | mask = 8; | |
8421 | else | |
8422 | { | |
8423 | error ("%<#pragma omp cancel must specify one of " | |
8424 | "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses"); | |
8425 | return; | |
8426 | } | |
8427 | vec<tree, va_gc> *vec = make_tree_vector (); | |
8428 | tree ifc = find_omp_clause (clauses, OMP_CLAUSE_IF); | |
8429 | if (ifc != NULL_TREE) | |
8430 | { | |
8431 | tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc)); | |
8432 | ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR, | |
8433 | boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc), | |
8434 | build_zero_cst (type)); | |
8435 | } | |
8436 | else | |
8437 | ifc = boolean_true_node; | |
8438 | vec->quick_push (build_int_cst (integer_type_node, mask)); | |
8439 | vec->quick_push (ifc); | |
8440 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); | |
8441 | release_tree_vector (vec); | |
8442 | finish_expr_stmt (stmt); | |
8443 | } | |
8444 | ||
8445 | void | |
8446 | finish_omp_cancellation_point (tree clauses) | |
8447 | { | |
8448 | tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT); | |
8449 | int mask = 0; | |
8450 | if (find_omp_clause (clauses, OMP_CLAUSE_PARALLEL)) | |
8451 | mask = 1; | |
8452 | else if (find_omp_clause (clauses, OMP_CLAUSE_FOR)) | |
8453 | mask = 2; | |
8454 | else if (find_omp_clause (clauses, OMP_CLAUSE_SECTIONS)) | |
8455 | mask = 4; | |
8456 | else if (find_omp_clause (clauses, OMP_CLAUSE_TASKGROUP)) | |
8457 | mask = 8; | |
8458 | else | |
8459 | { | |
8460 | error ("%<#pragma omp cancellation point must specify one of " | |
8461 | "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses"); | |
8462 | return; | |
8463 | } | |
8464 | vec<tree, va_gc> *vec | |
8465 | = make_tree_vector_single (build_int_cst (integer_type_node, mask)); | |
8466 | tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error); | |
8467 | release_tree_vector (vec); | |
8468 | finish_expr_stmt (stmt); | |
8469 | } | |
1799e5d5 | 8470 | \f |
0a35513e AH |
8471 | /* Begin a __transaction_atomic or __transaction_relaxed statement. |
8472 | If PCOMPOUND is non-null, this is for a function-transaction-block, and we | |
8473 | should create an extra compound stmt. */ | |
8474 | ||
8475 | tree | |
8476 | begin_transaction_stmt (location_t loc, tree *pcompound, int flags) | |
8477 | { | |
8478 | tree r; | |
8479 | ||
8480 | if (pcompound) | |
8481 | *pcompound = begin_compound_stmt (0); | |
8482 | ||
8483 | r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE); | |
8484 | ||
8485 | /* Only add the statement to the function if support enabled. */ | |
8486 | if (flag_tm) | |
8487 | add_stmt (r); | |
8488 | else | |
8489 | error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0 | |
8490 | ? G_("%<__transaction_relaxed%> without " | |
8491 | "transactional memory support enabled") | |
8492 | : G_("%<__transaction_atomic%> without " | |
8493 | "transactional memory support enabled"))); | |
8494 | ||
8495 | TRANSACTION_EXPR_BODY (r) = push_stmt_list (); | |
6f2d959b | 8496 | TREE_SIDE_EFFECTS (r) = 1; |
0a35513e AH |
8497 | return r; |
8498 | } | |
8499 | ||
8500 | /* End a __transaction_atomic or __transaction_relaxed statement. | |
8501 | If COMPOUND_STMT is non-null, this is for a function-transaction-block, | |
f0f3286a TR |
8502 | and we should end the compound. If NOEX is non-NULL, we wrap the body in |
8503 | a MUST_NOT_THROW_EXPR with NOEX as condition. */ | |
0a35513e AH |
8504 | |
8505 | void | |
f0f3286a | 8506 | finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex) |
0a35513e AH |
8507 | { |
8508 | TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt)); | |
8509 | TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0; | |
8510 | TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0; | |
8511 | TRANSACTION_EXPR_IS_STMT (stmt) = 1; | |
8512 | ||
f0f3286a TR |
8513 | /* noexcept specifications are not allowed for function transactions. */ |
8514 | gcc_assert (!(noex && compound_stmt)); | |
8515 | if (noex) | |
8516 | { | |
8517 | tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt), | |
8518 | noex); | |
5b5dce39 MP |
8519 | protected_set_expr_location |
8520 | (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt))); | |
f0f3286a TR |
8521 | TREE_SIDE_EFFECTS (body) = 1; |
8522 | TRANSACTION_EXPR_BODY (stmt) = body; | |
8523 | } | |
8524 | ||
0a35513e AH |
8525 | if (compound_stmt) |
8526 | finish_compound_stmt (compound_stmt); | |
0a35513e AH |
8527 | } |
8528 | ||
f0f3286a TR |
8529 | /* Build a __transaction_atomic or __transaction_relaxed expression. If |
8530 | NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as | |
8531 | condition. */ | |
0a35513e AH |
8532 | |
8533 | tree | |
f0f3286a | 8534 | build_transaction_expr (location_t loc, tree expr, int flags, tree noex) |
0a35513e AH |
8535 | { |
8536 | tree ret; | |
f0f3286a TR |
8537 | if (noex) |
8538 | { | |
8539 | expr = build_must_not_throw_expr (expr, noex); | |
5b5dce39 | 8540 | protected_set_expr_location (expr, loc); |
f0f3286a TR |
8541 | TREE_SIDE_EFFECTS (expr) = 1; |
8542 | } | |
0a35513e AH |
8543 | ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr); |
8544 | if (flags & TM_STMT_ATTR_RELAXED) | |
8545 | TRANSACTION_EXPR_RELAXED (ret) = 1; | |
6f2d959b | 8546 | TREE_SIDE_EFFECTS (ret) = 1; |
0a35513e AH |
8547 | SET_EXPR_LOCATION (ret, loc); |
8548 | return ret; | |
8549 | } | |
8550 | \f | |
54f7877c | 8551 | void |
3a978d72 | 8552 | init_cp_semantics (void) |
54f7877c | 8553 | { |
54f7877c | 8554 | } |
55a3debe DG |
8555 | \f |
8556 | /* Build a STATIC_ASSERT for a static assertion with the condition | |
8557 | CONDITION and the message text MESSAGE. LOCATION is the location | |
8558 | of the static assertion in the source code. When MEMBER_P, this | |
8559 | static assertion is a member of a class. */ | |
8560 | void | |
8561 | finish_static_assert (tree condition, tree message, location_t location, | |
8562 | bool member_p) | |
8563 | { | |
61b6d4cd DS |
8564 | if (message == NULL_TREE |
8565 | || message == error_mark_node | |
8566 | || condition == NULL_TREE | |
8567 | || condition == error_mark_node) | |
8568 | return; | |
8569 | ||
7b3e2d46 DG |
8570 | if (check_for_bare_parameter_packs (condition)) |
8571 | condition = error_mark_node; | |
8572 | ||
55a3debe DG |
8573 | if (type_dependent_expression_p (condition) |
8574 | || value_dependent_expression_p (condition)) | |
8575 | { | |
8576 | /* We're in a template; build a STATIC_ASSERT and put it in | |
8577 | the right place. */ | |
8578 | tree assertion; | |
8579 | ||
8580 | assertion = make_node (STATIC_ASSERT); | |
8581 | STATIC_ASSERT_CONDITION (assertion) = condition; | |
8582 | STATIC_ASSERT_MESSAGE (assertion) = message; | |
8583 | STATIC_ASSERT_SOURCE_LOCATION (assertion) = location; | |
8584 | ||
8585 | if (member_p) | |
8586 | maybe_add_class_template_decl_list (current_class_type, | |
8587 | assertion, | |
8588 | /*friend_p=*/0); | |
8589 | else | |
8590 | add_stmt (assertion); | |
8591 | ||
8592 | return; | |
8593 | } | |
8594 | ||
8595 | /* Fold the expression and convert it to a boolean value. */ | |
234bef96 | 8596 | condition = instantiate_non_dependent_expr (condition); |
4b978f96 | 8597 | condition = cp_convert (boolean_type_node, condition, tf_warning_or_error); |
fa2200cb | 8598 | condition = maybe_constant_value (condition); |
55a3debe DG |
8599 | |
8600 | if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition)) | |
8601 | /* Do nothing; the condition is satisfied. */ | |
8602 | ; | |
8603 | else | |
8604 | { | |
8605 | location_t saved_loc = input_location; | |
8606 | ||
8607 | input_location = location; | |
8608 | if (TREE_CODE (condition) == INTEGER_CST | |
8609 | && integer_zerop (condition)) | |
e79fc3d4 ESR |
8610 | { |
8611 | int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT | |
8612 | (TREE_TYPE (TREE_TYPE (message)))); | |
8613 | int len = TREE_STRING_LENGTH (message) / sz - 1; | |
8614 | /* Report the error. */ | |
8615 | if (len == 0) | |
8616 | error ("static assertion failed"); | |
8617 | else | |
8618 | error ("static assertion failed: %s", | |
8619 | TREE_STRING_POINTER (message)); | |
8620 | } | |
55a3debe | 8621 | else if (condition && condition != error_mark_node) |
fa2200cb JM |
8622 | { |
8623 | error ("non-constant condition for static assertion"); | |
9299bde0 PC |
8624 | if (require_potential_rvalue_constant_expression (condition)) |
8625 | cxx_constant_value (condition); | |
fa2200cb | 8626 | } |
55a3debe DG |
8627 | input_location = saved_loc; |
8628 | } | |
8629 | } | |
3ad6a8e1 DG |
8630 | \f |
8631 | /* Implements the C++0x decltype keyword. Returns the type of EXPR, | |
8632 | suitable for use as a type-specifier. | |
8633 | ||
8634 | ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an | |
8635 | id-expression or a class member access, FALSE when it was parsed as | |
8636 | a full expression. */ | |
a77f94e2 | 8637 | |
3ad6a8e1 | 8638 | tree |
5b97c77f JM |
8639 | finish_decltype_type (tree expr, bool id_expression_or_member_access_p, |
8640 | tsubst_flags_t complain) | |
3ad6a8e1 | 8641 | { |
056dd1af | 8642 | tree type = NULL_TREE; |
3ad6a8e1 | 8643 | |
e4fd5b87 DG |
8644 | if (!expr || error_operand_p (expr)) |
8645 | return error_mark_node; | |
8646 | ||
7a547b93 JJ |
8647 | if (TYPE_P (expr) |
8648 | || TREE_CODE (expr) == TYPE_DECL | |
8649 | || (TREE_CODE (expr) == BIT_NOT_EXPR | |
8650 | && TYPE_P (TREE_OPERAND (expr, 0)))) | |
8651 | { | |
5b97c77f JM |
8652 | if (complain & tf_error) |
8653 | error ("argument to decltype must be an expression"); | |
7a547b93 JJ |
8654 | return error_mark_node; |
8655 | } | |
8656 | ||
2c905502 JM |
8657 | /* Depending on the resolution of DR 1172, we may later need to distinguish |
8658 | instantiation-dependent but not type-dependent expressions so that, say, | |
8659 | A<decltype(sizeof(T))>::U doesn't require 'typename'. */ | |
8660 | if (instantiation_dependent_expression_p (expr)) | |
3ad6a8e1 | 8661 | { |
9e1e64ec | 8662 | type = cxx_make_type (DECLTYPE_TYPE); |
3ad6a8e1 DG |
8663 | DECLTYPE_TYPE_EXPR (type) = expr; |
8664 | DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type) | |
8665 | = id_expression_or_member_access_p; | |
8666 | SET_TYPE_STRUCTURAL_EQUALITY (type); | |
8667 | ||
8668 | return type; | |
8669 | } | |
8670 | ||
8671 | /* The type denoted by decltype(e) is defined as follows: */ | |
8672 | ||
ccb05613 | 8673 | expr = resolve_nondeduced_context (expr); |
48326487 | 8674 | |
d3ea4c06 | 8675 | if (invalid_nonstatic_memfn_p (input_location, expr, complain)) |
6c74ff23 JM |
8676 | return error_mark_node; |
8677 | ||
6cdb1428 JM |
8678 | if (type_unknown_p (expr)) |
8679 | { | |
8680 | if (complain & tf_error) | |
8681 | error ("decltype cannot resolve address of overloaded function"); | |
8682 | return error_mark_node; | |
8683 | } | |
8684 | ||
48326487 JM |
8685 | /* To get the size of a static data member declared as an array of |
8686 | unknown bound, we need to instantiate it. */ | |
5a6ccc94 | 8687 | if (VAR_P (expr) |
48326487 JM |
8688 | && VAR_HAD_UNKNOWN_BOUND (expr) |
8689 | && DECL_TEMPLATE_INSTANTIATION (expr)) | |
8690 | instantiate_decl (expr, /*defer_ok*/true, /*expl_inst_mem*/false); | |
8691 | ||
3ad6a8e1 DG |
8692 | if (id_expression_or_member_access_p) |
8693 | { | |
8694 | /* If e is an id-expression or a class member access (5.2.5 | |
8695 | [expr.ref]), decltype(e) is defined as the type of the entity | |
8696 | named by e. If there is no such entity, or e names a set of | |
8697 | overloaded functions, the program is ill-formed. */ | |
9dc6f476 | 8698 | if (identifier_p (expr)) |
3ad6a8e1 DG |
8699 | expr = lookup_name (expr); |
8700 | ||
591cb3cf | 8701 | if (INDIRECT_REF_P (expr)) |
3ad6a8e1 DG |
8702 | /* This can happen when the expression is, e.g., "a.b". Just |
8703 | look at the underlying operand. */ | |
8704 | expr = TREE_OPERAND (expr, 0); | |
8705 | ||
8706 | if (TREE_CODE (expr) == OFFSET_REF | |
cf3c30d3 JM |
8707 | || TREE_CODE (expr) == MEMBER_REF |
8708 | || TREE_CODE (expr) == SCOPE_REF) | |
3ad6a8e1 DG |
8709 | /* We're only interested in the field itself. If it is a |
8710 | BASELINK, we will need to see through it in the next | |
8711 | step. */ | |
8712 | expr = TREE_OPERAND (expr, 1); | |
8713 | ||
c5ce25ce | 8714 | if (BASELINK_P (expr)) |
6cdb1428 | 8715 | /* See through BASELINK nodes to the underlying function. */ |
3ad6a8e1 DG |
8716 | expr = BASELINK_FUNCTIONS (expr); |
8717 | ||
3ad6a8e1 DG |
8718 | switch (TREE_CODE (expr)) |
8719 | { | |
8720 | case FIELD_DECL: | |
e76d7cc7 | 8721 | if (DECL_BIT_FIELD_TYPE (expr)) |
3ad6a8e1 DG |
8722 | { |
8723 | type = DECL_BIT_FIELD_TYPE (expr); | |
8724 | break; | |
8725 | } | |
8726 | /* Fall through for fields that aren't bitfields. */ | |
8727 | ||
8728 | case FUNCTION_DECL: | |
8729 | case VAR_DECL: | |
8730 | case CONST_DECL: | |
8731 | case PARM_DECL: | |
8732 | case RESULT_DECL: | |
088d4f95 | 8733 | case TEMPLATE_PARM_INDEX: |
03a904b5 | 8734 | expr = mark_type_use (expr); |
3ad6a8e1 DG |
8735 | type = TREE_TYPE (expr); |
8736 | break; | |
8737 | ||
8738 | case ERROR_MARK: | |
8739 | type = error_mark_node; | |
8740 | break; | |
8741 | ||
8742 | case COMPONENT_REF: | |
4882d82a | 8743 | case COMPOUND_EXPR: |
03a904b5 | 8744 | mark_type_use (expr); |
3ad6a8e1 DG |
8745 | type = is_bitfield_expr_with_lowered_type (expr); |
8746 | if (!type) | |
8747 | type = TREE_TYPE (TREE_OPERAND (expr, 1)); | |
8748 | break; | |
8749 | ||
8750 | case BIT_FIELD_REF: | |
8751 | gcc_unreachable (); | |
8752 | ||
8753 | case INTEGER_CST: | |
8733916b | 8754 | case PTRMEM_CST: |
3ad6a8e1 | 8755 | /* We can get here when the id-expression refers to an |
8733916b | 8756 | enumerator or non-type template parameter. */ |
3ad6a8e1 DG |
8757 | type = TREE_TYPE (expr); |
8758 | break; | |
8759 | ||
8760 | default: | |
57c16a5e PC |
8761 | /* Handle instantiated template non-type arguments. */ |
8762 | type = TREE_TYPE (expr); | |
8763 | break; | |
3ad6a8e1 DG |
8764 | } |
8765 | } | |
8766 | else | |
8767 | { | |
c1e41527 JM |
8768 | /* Within a lambda-expression: |
8769 | ||
8770 | Every occurrence of decltype((x)) where x is a possibly | |
8771 | parenthesized id-expression that names an entity of | |
8772 | automatic storage duration is treated as if x were | |
8773 | transformed into an access to a corresponding data member | |
8774 | of the closure type that would have been declared if x | |
8775 | were a use of the denoted entity. */ | |
8776 | if (outer_automatic_var_p (expr) | |
8777 | && current_function_decl | |
8778 | && LAMBDA_FUNCTION_P (current_function_decl)) | |
8779 | type = capture_decltype (expr); | |
8780 | else if (error_operand_p (expr)) | |
8781 | type = error_mark_node; | |
8782 | else if (expr == current_class_ptr) | |
8783 | /* If the expression is just "this", we want the | |
8784 | cv-unqualified pointer for the "this" type. */ | |
8785 | type = TYPE_MAIN_VARIANT (TREE_TYPE (expr)); | |
8786 | else | |
8787 | { | |
8788 | /* Otherwise, where T is the type of e, if e is an lvalue, | |
8789 | decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */ | |
8790 | cp_lvalue_kind clk = lvalue_kind (expr); | |
8791 | type = unlowered_expr_type (expr); | |
8792 | gcc_assert (TREE_CODE (type) != REFERENCE_TYPE); | |
7cea661c MG |
8793 | |
8794 | /* For vector types, pick a non-opaque variant. */ | |
b55b02ea | 8795 | if (VECTOR_TYPE_P (type)) |
7cea661c MG |
8796 | type = strip_typedefs (type); |
8797 | ||
c1e41527 JM |
8798 | if (clk != clk_none && !(clk & clk_class)) |
8799 | type = cp_build_reference_type (type, (clk & clk_rvalueref)); | |
8800 | } | |
3ad6a8e1 DG |
8801 | } |
8802 | ||
3ad6a8e1 DG |
8803 | return type; |
8804 | } | |
cf22909c | 8805 | |
b29441ec PC |
8806 | /* Called from trait_expr_value to evaluate either __has_nothrow_assign or |
8807 | __has_nothrow_copy, depending on assign_p. */ | |
cb68ec50 PC |
8808 | |
8809 | static bool | |
b29441ec | 8810 | classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p) |
cb68ec50 | 8811 | { |
b29441ec | 8812 | tree fns; |
cb68ec50 | 8813 | |
b29441ec PC |
8814 | if (assign_p) |
8815 | { | |
8816 | int ix; | |
8817 | ix = lookup_fnfields_1 (type, ansi_assopname (NOP_EXPR)); | |
8818 | if (ix < 0) | |
cb68ec50 | 8819 | return false; |
9771b263 | 8820 | fns = (*CLASSTYPE_METHOD_VEC (type))[ix]; |
b29441ec | 8821 | } |
066ec0a4 | 8822 | else if (TYPE_HAS_COPY_CTOR (type)) |
b29441ec PC |
8823 | { |
8824 | /* If construction of the copy constructor was postponed, create | |
8825 | it now. */ | |
8826 | if (CLASSTYPE_LAZY_COPY_CTOR (type)) | |
8827 | lazily_declare_fn (sfk_copy_constructor, type); | |
d5f4eddd JM |
8828 | if (CLASSTYPE_LAZY_MOVE_CTOR (type)) |
8829 | lazily_declare_fn (sfk_move_constructor, type); | |
b29441ec | 8830 | fns = CLASSTYPE_CONSTRUCTORS (type); |
cb68ec50 PC |
8831 | } |
8832 | else | |
8833 | return false; | |
8834 | ||
b29441ec | 8835 | for (; fns; fns = OVL_NEXT (fns)) |
279086c3 PC |
8836 | { |
8837 | tree fn = OVL_CURRENT (fns); | |
8838 | ||
8839 | if (assign_p) | |
8840 | { | |
8841 | if (copy_fn_p (fn) == 0) | |
8842 | continue; | |
8843 | } | |
8844 | else if (copy_fn_p (fn) <= 0) | |
8845 | continue; | |
8846 | ||
ba9146c1 | 8847 | maybe_instantiate_noexcept (fn); |
279086c3 PC |
8848 | if (!TYPE_NOTHROW_P (TREE_TYPE (fn))) |
8849 | return false; | |
8850 | } | |
b29441ec | 8851 | |
cb68ec50 PC |
8852 | return true; |
8853 | } | |
8854 | ||
8855 | /* Actually evaluates the trait. */ | |
8856 | ||
8857 | static bool | |
8858 | trait_expr_value (cp_trait_kind kind, tree type1, tree type2) | |
8859 | { | |
8860 | enum tree_code type_code1; | |
8861 | tree t; | |
8862 | ||
8863 | type_code1 = TREE_CODE (type1); | |
8864 | ||
8865 | switch (kind) | |
8866 | { | |
8867 | case CPTK_HAS_NOTHROW_ASSIGN: | |
c32097d8 | 8868 | type1 = strip_array_types (type1); |
b29441ec PC |
8869 | return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE |
8870 | && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2) | |
8871 | || (CLASS_TYPE_P (type1) | |
8872 | && classtype_has_nothrow_assign_or_copy_p (type1, | |
8873 | true)))); | |
cb68ec50 PC |
8874 | |
8875 | case CPTK_HAS_TRIVIAL_ASSIGN: | |
c32097d8 JM |
8876 | /* ??? The standard seems to be missing the "or array of such a class |
8877 | type" wording for this trait. */ | |
8878 | type1 = strip_array_types (type1); | |
cb68ec50 | 8879 | return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE |
c32097d8 | 8880 | && (trivial_type_p (type1) |
cb68ec50 | 8881 | || (CLASS_TYPE_P (type1) |
066ec0a4 | 8882 | && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); |
cb68ec50 PC |
8883 | |
8884 | case CPTK_HAS_NOTHROW_CONSTRUCTOR: | |
8885 | type1 = strip_array_types (type1); | |
8886 | return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2) | |
8887 | || (CLASS_TYPE_P (type1) | |
ac177431 | 8888 | && (t = locate_ctor (type1)) |
ffabb761 JM |
8889 | && (maybe_instantiate_noexcept (t), |
8890 | TYPE_NOTHROW_P (TREE_TYPE (t))))); | |
cb68ec50 PC |
8891 | |
8892 | case CPTK_HAS_TRIVIAL_CONSTRUCTOR: | |
8893 | type1 = strip_array_types (type1); | |
c32097d8 | 8894 | return (trivial_type_p (type1) |
cb68ec50 PC |
8895 | || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); |
8896 | ||
8897 | case CPTK_HAS_NOTHROW_COPY: | |
c32097d8 | 8898 | type1 = strip_array_types (type1); |
cb68ec50 PC |
8899 | return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2) |
8900 | || (CLASS_TYPE_P (type1) | |
b29441ec | 8901 | && classtype_has_nothrow_assign_or_copy_p (type1, false))); |
cb68ec50 PC |
8902 | |
8903 | case CPTK_HAS_TRIVIAL_COPY: | |
c32097d8 JM |
8904 | /* ??? The standard seems to be missing the "or array of such a class |
8905 | type" wording for this trait. */ | |
8906 | type1 = strip_array_types (type1); | |
8907 | return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE | |
066ec0a4 | 8908 | || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1))); |
cb68ec50 PC |
8909 | |
8910 | case CPTK_HAS_TRIVIAL_DESTRUCTOR: | |
8911 | type1 = strip_array_types (type1); | |
c32097d8 | 8912 | return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE |
cb68ec50 PC |
8913 | || (CLASS_TYPE_P (type1) |
8914 | && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1))); | |
8915 | ||
8916 | case CPTK_HAS_VIRTUAL_DESTRUCTOR: | |
46408846 | 8917 | return type_has_virtual_destructor (type1); |
cb68ec50 PC |
8918 | |
8919 | case CPTK_IS_ABSTRACT: | |
94ccc95d | 8920 | return (ABSTRACT_CLASS_TYPE_P (type1)); |
cb68ec50 PC |
8921 | |
8922 | case CPTK_IS_BASE_OF: | |
8923 | return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) | |
1f872df7 PC |
8924 | && (same_type_ignoring_top_level_qualifiers_p (type1, type2) |
8925 | || DERIVED_FROM_P (type1, type2))); | |
cb68ec50 PC |
8926 | |
8927 | case CPTK_IS_CLASS: | |
8928 | return (NON_UNION_CLASS_TYPE_P (type1)); | |
8929 | ||
cb68ec50 PC |
8930 | case CPTK_IS_EMPTY: |
8931 | return (NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1)); | |
8932 | ||
8933 | case CPTK_IS_ENUM: | |
8934 | return (type_code1 == ENUMERAL_TYPE); | |
8935 | ||
b3908fcc JW |
8936 | case CPTK_IS_FINAL: |
8937 | return (CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1)); | |
8938 | ||
3c0d13bf PC |
8939 | case CPTK_IS_LITERAL_TYPE: |
8940 | return (literal_type_p (type1)); | |
8941 | ||
cb68ec50 PC |
8942 | case CPTK_IS_POD: |
8943 | return (pod_type_p (type1)); | |
8944 | ||
8945 | case CPTK_IS_POLYMORPHIC: | |
8946 | return (CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1)); | |
8947 | ||
971e17ff AS |
8948 | case CPTK_IS_SAME_AS: |
8949 | return same_type_p (type1, type2); | |
8950 | ||
c32097d8 JM |
8951 | case CPTK_IS_STD_LAYOUT: |
8952 | return (std_layout_type_p (type1)); | |
8953 | ||
8954 | case CPTK_IS_TRIVIAL: | |
8955 | return (trivial_type_p (type1)); | |
8956 | ||
dd5d5481 JM |
8957 | case CPTK_IS_TRIVIALLY_ASSIGNABLE: |
8958 | return is_trivially_xible (MODIFY_EXPR, type1, type2); | |
8959 | ||
8960 | case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: | |
8961 | return is_trivially_xible (INIT_EXPR, type1, type2); | |
8962 | ||
b752325e JM |
8963 | case CPTK_IS_TRIVIALLY_COPYABLE: |
8964 | return (trivially_copyable_p (type1)); | |
8965 | ||
cb68ec50 PC |
8966 | case CPTK_IS_UNION: |
8967 | return (type_code1 == UNION_TYPE); | |
8968 | ||
8969 | default: | |
8970 | gcc_unreachable (); | |
8971 | return false; | |
8972 | } | |
8973 | } | |
8974 | ||
4f75413f | 8975 | /* If TYPE is an array of unknown bound, or (possibly cv-qualified) |
dd5d5481 | 8976 | void, or a complete type, returns true, otherwise false. */ |
ff284b4b | 8977 | |
dd5d5481 | 8978 | static bool |
ff284b4b PC |
8979 | check_trait_type (tree type) |
8980 | { | |
dd5d5481 JM |
8981 | if (type == NULL_TREE) |
8982 | return true; | |
8983 | ||
8984 | if (TREE_CODE (type) == TREE_LIST) | |
8985 | return (check_trait_type (TREE_VALUE (type)) | |
8986 | && check_trait_type (TREE_CHAIN (type))); | |
8987 | ||
f94ae987 JM |
8988 | if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type) |
8989 | && COMPLETE_TYPE_P (TREE_TYPE (type))) | |
dd5d5481 | 8990 | return true; |
ff284b4b PC |
8991 | |
8992 | if (VOID_TYPE_P (type)) | |
dd5d5481 | 8993 | return true; |
ff284b4b | 8994 | |
dd5d5481 | 8995 | return !!complete_type_or_else (strip_array_types (type), NULL_TREE); |
ff284b4b PC |
8996 | } |
8997 | ||
cb68ec50 PC |
8998 | /* Process a trait expression. */ |
8999 | ||
9000 | tree | |
9001 | finish_trait_expr (cp_trait_kind kind, tree type1, tree type2) | |
9002 | { | |
cb68ec50 | 9003 | if (type1 == error_mark_node |
dd5d5481 | 9004 | || type2 == error_mark_node) |
cb68ec50 PC |
9005 | return error_mark_node; |
9006 | ||
9007 | if (processing_template_decl) | |
9008 | { | |
9009 | tree trait_expr = make_node (TRAIT_EXPR); | |
9010 | TREE_TYPE (trait_expr) = boolean_type_node; | |
9011 | TRAIT_EXPR_TYPE1 (trait_expr) = type1; | |
9012 | TRAIT_EXPR_TYPE2 (trait_expr) = type2; | |
9013 | TRAIT_EXPR_KIND (trait_expr) = kind; | |
9014 | return trait_expr; | |
9015 | } | |
9016 | ||
ff284b4b | 9017 | switch (kind) |
cb68ec50 | 9018 | { |
ff284b4b PC |
9019 | case CPTK_HAS_NOTHROW_ASSIGN: |
9020 | case CPTK_HAS_TRIVIAL_ASSIGN: | |
9021 | case CPTK_HAS_NOTHROW_CONSTRUCTOR: | |
9022 | case CPTK_HAS_TRIVIAL_CONSTRUCTOR: | |
9023 | case CPTK_HAS_NOTHROW_COPY: | |
9024 | case CPTK_HAS_TRIVIAL_COPY: | |
9025 | case CPTK_HAS_TRIVIAL_DESTRUCTOR: | |
9026 | case CPTK_HAS_VIRTUAL_DESTRUCTOR: | |
9027 | case CPTK_IS_ABSTRACT: | |
9028 | case CPTK_IS_EMPTY: | |
b3908fcc | 9029 | case CPTK_IS_FINAL: |
3c0d13bf | 9030 | case CPTK_IS_LITERAL_TYPE: |
ff284b4b PC |
9031 | case CPTK_IS_POD: |
9032 | case CPTK_IS_POLYMORPHIC: | |
c32097d8 JM |
9033 | case CPTK_IS_STD_LAYOUT: |
9034 | case CPTK_IS_TRIVIAL: | |
b752325e | 9035 | case CPTK_IS_TRIVIALLY_COPYABLE: |
ff284b4b | 9036 | if (!check_trait_type (type1)) |
4f75413f | 9037 | return error_mark_node; |
ff284b4b | 9038 | break; |
dd5d5481 JM |
9039 | |
9040 | case CPTK_IS_TRIVIALLY_ASSIGNABLE: | |
9041 | case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: | |
9042 | if (!check_trait_type (type1) | |
9043 | || !check_trait_type (type2)) | |
9044 | return error_mark_node; | |
9045 | break; | |
ff284b4b PC |
9046 | |
9047 | case CPTK_IS_BASE_OF: | |
9048 | if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) | |
9049 | && !same_type_ignoring_top_level_qualifiers_p (type1, type2) | |
4f75413f PC |
9050 | && !complete_type_or_else (type2, NULL_TREE)) |
9051 | /* We already issued an error. */ | |
9052 | return error_mark_node; | |
ff284b4b PC |
9053 | break; |
9054 | ||
9055 | case CPTK_IS_CLASS: | |
9056 | case CPTK_IS_ENUM: | |
9057 | case CPTK_IS_UNION: | |
971e17ff | 9058 | case CPTK_IS_SAME_AS: |
ff284b4b | 9059 | break; |
971e17ff | 9060 | |
ff284b4b PC |
9061 | default: |
9062 | gcc_unreachable (); | |
cb68ec50 PC |
9063 | } |
9064 | ||
9065 | return (trait_expr_value (kind, type1, type2) | |
9066 | ? boolean_true_node : boolean_false_node); | |
9067 | } | |
9068 | ||
6ec637a4 JJ |
9069 | /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64, |
9070 | which is ignored for C++. */ | |
9071 | ||
9072 | void | |
9073 | set_float_const_decimal64 (void) | |
9074 | { | |
9075 | } | |
9076 | ||
9077 | void | |
9078 | clear_float_const_decimal64 (void) | |
9079 | { | |
9080 | } | |
9081 | ||
9082 | bool | |
9083 | float_const_decimal64_p (void) | |
9084 | { | |
9085 | return 0; | |
9086 | } | |
9087 | ||
3b49d762 | 9088 | \f |
2d76680f | 9089 | /* Return true if T designates the implied `this' parameter. */ |
7ecbca9d GDR |
9090 | |
9091 | bool | |
2d76680f | 9092 | is_this_parameter (tree t) |
66e61a34 | 9093 | { |
2d76680f | 9094 | if (!DECL_P (t) || DECL_NAME (t) != this_identifier) |
66e61a34 | 9095 | return false; |
2d76680f | 9096 | gcc_assert (TREE_CODE (t) == PARM_DECL || is_capture_proxy (t)); |
fbf833b7 PC |
9097 | return true; |
9098 | } | |
9099 | ||
852497a3 | 9100 | /* Insert the deduced return type for an auto function. */ |
d5f4eddd JM |
9101 | |
9102 | void | |
852497a3 | 9103 | apply_deduced_return_type (tree fco, tree return_type) |
d5f4eddd | 9104 | { |
d5f4eddd JM |
9105 | tree result; |
9106 | ||
d5f4eddd JM |
9107 | if (return_type == error_mark_node) |
9108 | return; | |
9109 | ||
852497a3 JM |
9110 | if (LAMBDA_FUNCTION_P (fco)) |
9111 | { | |
9112 | tree lambda = CLASSTYPE_LAMBDA_EXPR (current_class_type); | |
9113 | LAMBDA_EXPR_RETURN_TYPE (lambda) = return_type; | |
9114 | } | |
9115 | ||
9116 | if (DECL_CONV_FN_P (fco)) | |
9117 | DECL_NAME (fco) = mangle_conv_op_name_for_type (return_type); | |
9118 | ||
643d4cd6 | 9119 | TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco)); |
d5f4eddd JM |
9120 | |
9121 | result = DECL_RESULT (fco); | |
9122 | if (result == NULL_TREE) | |
9123 | return; | |
852497a3 JM |
9124 | if (TREE_TYPE (result) == return_type) |
9125 | return; | |
d5f4eddd JM |
9126 | |
9127 | /* We already have a DECL_RESULT from start_preparsed_function. | |
9128 | Now we need to redo the work it and allocate_struct_function | |
9129 | did to reflect the new type. */ | |
9b8662c2 | 9130 | gcc_assert (current_function_decl == fco); |
d5f4eddd JM |
9131 | result = build_decl (input_location, RESULT_DECL, NULL_TREE, |
9132 | TYPE_MAIN_VARIANT (return_type)); | |
9133 | DECL_ARTIFICIAL (result) = 1; | |
9134 | DECL_IGNORED_P (result) = 1; | |
9135 | cp_apply_type_quals_to_decl (cp_type_quals (return_type), | |
9136 | result); | |
9137 | ||
9138 | DECL_RESULT (fco) = result; | |
9139 | ||
852497a3 | 9140 | if (!processing_template_decl) |
d5f4eddd | 9141 | { |
3734964f DT |
9142 | if (!VOID_TYPE_P (TREE_TYPE (result))) |
9143 | complete_type_or_else (TREE_TYPE (result), NULL_TREE); | |
852497a3 | 9144 | bool aggr = aggregate_value_p (result, fco); |
d5f4eddd | 9145 | #ifdef PCC_STATIC_STRUCT_RETURN |
852497a3 | 9146 | cfun->returns_pcc_struct = aggr; |
d5f4eddd | 9147 | #endif |
852497a3 | 9148 | cfun->returns_struct = aggr; |
d5f4eddd JM |
9149 | } |
9150 | ||
9151 | } | |
9152 | ||
9153 | /* DECL is a local variable or parameter from the surrounding scope of a | |
9154 | lambda-expression. Returns the decltype for a use of the capture field | |
9155 | for DECL even if it hasn't been captured yet. */ | |
9156 | ||
9157 | static tree | |
9158 | capture_decltype (tree decl) | |
9159 | { | |
9160 | tree lam = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl)); | |
9161 | /* FIXME do lookup instead of list walk? */ | |
9162 | tree cap = value_member (decl, LAMBDA_EXPR_CAPTURE_LIST (lam)); | |
9163 | tree type; | |
9164 | ||
9165 | if (cap) | |
9166 | type = TREE_TYPE (TREE_PURPOSE (cap)); | |
9167 | else | |
9168 | switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam)) | |
9169 | { | |
9170 | case CPLD_NONE: | |
9171 | error ("%qD is not captured", decl); | |
9172 | return error_mark_node; | |
9173 | ||
9174 | case CPLD_COPY: | |
9175 | type = TREE_TYPE (decl); | |
9176 | if (TREE_CODE (type) == REFERENCE_TYPE | |
9177 | && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE) | |
9178 | type = TREE_TYPE (type); | |
9179 | break; | |
9180 | ||
9181 | case CPLD_REFERENCE: | |
9182 | type = TREE_TYPE (decl); | |
9183 | if (TREE_CODE (type) != REFERENCE_TYPE) | |
9184 | type = build_reference_type (TREE_TYPE (decl)); | |
9185 | break; | |
9186 | ||
9187 | default: | |
9188 | gcc_unreachable (); | |
9189 | } | |
9190 | ||
9191 | if (TREE_CODE (type) != REFERENCE_TYPE) | |
9192 | { | |
9193 | if (!LAMBDA_EXPR_MUTABLE_P (lam)) | |
a3360e77 | 9194 | type = cp_build_qualified_type (type, (cp_type_quals (type) |
d5f4eddd JM |
9195 | |TYPE_QUAL_CONST)); |
9196 | type = build_reference_type (type); | |
9197 | } | |
9198 | return type; | |
9199 | } | |
9200 | ||
378b307d AS |
9201 | /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true, |
9202 | this is a right unary fold. Otherwise it is a left unary fold. */ | |
9203 | ||
9204 | static tree | |
9205 | finish_unary_fold_expr (tree expr, int op, tree_code dir) | |
9206 | { | |
9207 | // Build a pack expansion (assuming expr has pack type). | |
9208 | if (!uses_parameter_packs (expr)) | |
9209 | { | |
9210 | error_at (location_of (expr), "operand of fold expression has no " | |
9211 | "unexpanded parameter packs"); | |
9212 | return error_mark_node; | |
9213 | } | |
9214 | tree pack = make_pack_expansion (expr); | |
9215 | ||
9216 | // Build the fold expression. | |
9217 | tree code = build_int_cstu (integer_type_node, abs (op)); | |
9218 | tree fold = build_min (dir, unknown_type_node, code, pack); | |
9219 | FOLD_EXPR_MODIFY_P (fold) = (op < 0); | |
9220 | return fold; | |
9221 | } | |
9222 | ||
9223 | tree | |
9224 | finish_left_unary_fold_expr (tree expr, int op) | |
9225 | { | |
9226 | return finish_unary_fold_expr (expr, op, UNARY_LEFT_FOLD_EXPR); | |
9227 | } | |
9228 | ||
9229 | tree | |
9230 | finish_right_unary_fold_expr (tree expr, int op) | |
9231 | { | |
9232 | return finish_unary_fold_expr (expr, op, UNARY_RIGHT_FOLD_EXPR); | |
9233 | } | |
9234 | ||
9235 | /* Build a binary fold expression over EXPR1 and EXPR2. The | |
9236 | associativity of the fold is determined by EXPR1 and EXPR2 (whichever | |
9237 | has an unexpanded parameter pack). */ | |
9238 | ||
9239 | tree | |
9240 | finish_binary_fold_expr (tree pack, tree init, int op, tree_code dir) | |
9241 | { | |
9242 | pack = make_pack_expansion (pack); | |
9243 | tree code = build_int_cstu (integer_type_node, abs (op)); | |
9244 | tree fold = build_min (dir, unknown_type_node, code, pack, init); | |
9245 | FOLD_EXPR_MODIFY_P (fold) = (op < 0); | |
9246 | return fold; | |
9247 | } | |
9248 | ||
9249 | tree | |
9250 | finish_binary_fold_expr (tree expr1, tree expr2, int op) | |
9251 | { | |
9252 | // Determine which expr has an unexpanded parameter pack and | |
9253 | // set the pack and initial term. | |
9254 | bool pack1 = uses_parameter_packs (expr1); | |
9255 | bool pack2 = uses_parameter_packs (expr2); | |
9256 | if (pack1 && !pack2) | |
9257 | return finish_binary_fold_expr (expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR); | |
9258 | else if (pack2 && !pack1) | |
9259 | return finish_binary_fold_expr (expr2, expr1, op, BINARY_LEFT_FOLD_EXPR); | |
9260 | else | |
9261 | { | |
9262 | if (pack1) | |
9263 | error ("both arguments in binary fold have unexpanded parameter packs"); | |
9264 | else | |
9265 | error ("no unexpanded parameter packs in binary fold"); | |
9266 | } | |
9267 | return error_mark_node; | |
9268 | } | |
9269 | ||
cf22909c | 9270 | #include "gt-cp-semantics.h" |