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