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