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