Line data Source code
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
4 : and during the instantiation of template functions.
5 :
6 : Copyright (C) 1998-2023 Free Software Foundation, Inc.
7 : Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 : formerly in parse.y and pt.cc.
9 :
10 : This file is part of GCC.
11 :
12 : GCC is free software; you can redistribute it and/or modify it
13 : under the terms of the GNU General Public License as published by
14 : the Free Software Foundation; either version 3, or (at your option)
15 : any later version.
16 :
17 : GCC is distributed in the hope that it will be useful, but
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.
21 :
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/>. */
25 :
26 : #include "config.h"
27 : #include "system.h"
28 : #include "coretypes.h"
29 : #include "target.h"
30 : #include "bitmap.h"
31 : #include "cp-tree.h"
32 : #include "stringpool.h"
33 : #include "cgraph.h"
34 : #include "stmt.h"
35 : #include "varasm.h"
36 : #include "stor-layout.h"
37 : #include "c-family/c-objc.h"
38 : #include "tree-inline.h"
39 : #include "intl.h"
40 : #include "tree-iterator.h"
41 : #include "omp-general.h"
42 : #include "convert.h"
43 : #include "stringpool.h"
44 : #include "attribs.h"
45 : #include "gomp-constants.h"
46 : #include "predict.h"
47 : #include "memmodel.h"
48 :
49 : /* There routines provide a modular interface to perform many parsing
50 : operations. They may therefore be used during actual parsing, or
51 : during template instantiation, which may be regarded as a
52 : degenerate form of parsing. */
53 :
54 : static tree maybe_convert_cond (tree);
55 : static tree finalize_nrv_r (tree *, int *, void *);
56 : static tree capture_decltype (tree);
57 :
58 : /* Used for OpenMP non-static data member privatization. */
59 :
60 : static hash_map<tree, tree> *omp_private_member_map;
61 : static vec<tree> omp_private_member_vec;
62 : static bool omp_private_member_ignore_next;
63 :
64 :
65 : /* Deferred Access Checking Overview
66 : ---------------------------------
67 :
68 : Most C++ expressions and declarations require access checking
69 : to be performed during parsing. However, in several cases,
70 : this has to be treated differently.
71 :
72 : For member declarations, access checking has to be deferred
73 : until more information about the declaration is known. For
74 : example:
75 :
76 : class A {
77 : typedef int X;
78 : public:
79 : X f();
80 : };
81 :
82 : A::X A::f();
83 : A::X g();
84 :
85 : When we are parsing the function return type `A::X', we don't
86 : really know if this is allowed until we parse the function name.
87 :
88 : Furthermore, some contexts require that access checking is
89 : never performed at all. These include class heads, and template
90 : instantiations.
91 :
92 : Typical use of access checking functions is described here:
93 :
94 : 1. When we enter a context that requires certain access checking
95 : mode, the function `push_deferring_access_checks' is called with
96 : DEFERRING argument specifying the desired mode. Access checking
97 : may be performed immediately (dk_no_deferred), deferred
98 : (dk_deferred), or not performed (dk_no_check).
99 :
100 : 2. When a declaration such as a type, or a variable, is encountered,
101 : the function `perform_or_defer_access_check' is called. It
102 : maintains a vector of all deferred checks.
103 :
104 : 3. The global `current_class_type' or `current_function_decl' is then
105 : setup by the parser. `enforce_access' relies on these information
106 : to check access.
107 :
108 : 4. Upon exiting the context mentioned in step 1,
109 : `perform_deferred_access_checks' is called to check all declaration
110 : stored in the vector. `pop_deferring_access_checks' is then
111 : called to restore the previous access checking mode.
112 :
113 : In case of parsing error, we simply call `pop_deferring_access_checks'
114 : without `perform_deferred_access_checks'. */
115 :
116 : struct GTY(()) deferred_access {
117 : /* A vector representing name-lookups for which we have deferred
118 : checking access controls. We cannot check the accessibility of
119 : names used in a decl-specifier-seq until we know what is being
120 : declared because code like:
121 :
122 : class A {
123 : class B {};
124 : B* f();
125 : }
126 :
127 : A::B* A::f() { return 0; }
128 :
129 : is valid, even though `A::B' is not generally accessible. */
130 : vec<deferred_access_check, va_gc> *deferred_access_checks;
131 :
132 : /* The current mode of access checks. */
133 : enum deferring_kind deferring_access_checks_kind;
134 : };
135 :
136 : /* Data for deferred access checking. */
137 : static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack;
138 : static GTY(()) unsigned deferred_access_no_check;
139 :
140 : /* Save the current deferred access states and start deferred
141 : access checking iff DEFER_P is true. */
142 :
143 : void
144 12457055698 : push_deferring_access_checks (deferring_kind deferring)
145 : {
146 : /* For context like template instantiation, access checking
147 : disabling applies to all nested context. */
148 12421809130 : if (deferred_access_no_check || deferring == dk_no_check)
149 147623956 : deferred_access_no_check++;
150 : else
151 : {
152 12274185174 : deferred_access e = {NULL, deferring};
153 12274185174 : vec_safe_push (deferred_access_stack, e);
154 : }
155 12421809130 : }
156 :
157 : /* Save the current deferred access states and start deferred access
158 : checking, continuing the set of deferred checks in CHECKS. */
159 :
160 : void
161 181758541 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
162 : {
163 181758541 : push_deferring_access_checks (dk_deferred);
164 181758541 : if (!deferred_access_no_check)
165 177090482 : deferred_access_stack->last().deferred_access_checks = checks;
166 181758541 : }
167 :
168 : /* Resume deferring access checks again after we stopped doing
169 : this previously. */
170 :
171 : void
172 109952646 : resume_deferring_access_checks (void)
173 : {
174 109952646 : if (!deferred_access_no_check)
175 109950369 : deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
176 109952646 : }
177 :
178 : /* Stop deferring access checks. */
179 :
180 : void
181 299470327 : stop_deferring_access_checks (void)
182 : {
183 299470327 : if (!deferred_access_no_check)
184 299463738 : deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
185 299470327 : }
186 :
187 : /* Discard the current deferred access checks and restore the
188 : previous states. */
189 :
190 : void
191 7440384947 : pop_deferring_access_checks (void)
192 : {
193 7440384947 : if (deferred_access_no_check)
194 133550354 : deferred_access_no_check--;
195 : else
196 7306834593 : deferred_access_stack->pop ();
197 7440384947 : }
198 :
199 : /* Returns a TREE_LIST representing the deferred checks.
200 : The TREE_PURPOSE of each node is the type through which the
201 : access occurred; the TREE_VALUE is the declaration named.
202 : */
203 :
204 : vec<deferred_access_check, va_gc> *
205 666777836 : get_deferred_access_checks (void)
206 : {
207 666777836 : if (deferred_access_no_check)
208 : return NULL;
209 : else
210 657566424 : return (deferred_access_stack->last().deferred_access_checks);
211 : }
212 :
213 : /* Take current deferred checks and combine with the
214 : previous states if we also defer checks previously.
215 : Otherwise perform checks now. */
216 :
217 : void
218 5016543237 : pop_to_parent_deferring_access_checks (void)
219 : {
220 5016543237 : if (deferred_access_no_check)
221 49320165 : deferred_access_no_check--;
222 : else
223 : {
224 4967223072 : vec<deferred_access_check, va_gc> *checks;
225 4967223072 : deferred_access *ptr;
226 :
227 4967223072 : checks = (deferred_access_stack->last ().deferred_access_checks);
228 :
229 4967223072 : deferred_access_stack->pop ();
230 4967223072 : ptr = &deferred_access_stack->last ();
231 4967223072 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
232 : {
233 : /* Check access. */
234 314018108 : perform_access_checks (checks, tf_warning_or_error);
235 : }
236 : else
237 : {
238 : /* Merge with parent. */
239 : int i, j;
240 : deferred_access_check *chk, *probe;
241 :
242 4758777012 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
243 : {
244 58519936 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
245 : {
246 6188254 : if (probe->binfo == chk->binfo &&
247 5045154 : probe->decl == chk->decl &&
248 454394 : probe->diag_decl == chk->diag_decl)
249 454342 : goto found;
250 : }
251 : /* Insert into parent's checks. */
252 52331682 : vec_safe_push (ptr->deferred_access_checks, *chk);
253 52786024 : found:;
254 : }
255 : }
256 : }
257 5016543237 : }
258 :
259 : /* Called from enforce_access. A class has attempted (but failed) to access
260 : DECL. It is already established that a baseclass of that class,
261 : PARENT_BINFO, has private access to DECL. Examine certain special cases
262 : to find a decl that accurately describes the source of the problem. If
263 : none of the special cases apply, simply return DECL as the source of the
264 : problem. */
265 :
266 : static tree
267 221 : get_class_access_diagnostic_decl (tree parent_binfo, tree decl)
268 : {
269 : /* When a class is denied access to a decl in a baseclass, most of the
270 : time it is because the decl itself was declared as private at the point
271 : of declaration.
272 :
273 : However, in C++, there are (at least) two situations in which a decl
274 : can be private even though it was not originally defined as such.
275 : These two situations only apply if a baseclass had private access to
276 : DECL (this function is only called if that is the case). */
277 :
278 : /* We should first check whether the reason the parent had private access
279 : to DECL was simply because DECL was created and declared as private in
280 : the parent. If it was, then DECL is definitively the source of the
281 : problem. */
282 221 : if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl),
283 : BINFO_TYPE (parent_binfo)))
284 : return decl;
285 :
286 : /* 1. If the "using" keyword is used to inherit DECL within the parent,
287 : this may cause DECL to be private, so we should return the using
288 : statement as the source of the problem.
289 :
290 : Scan the fields of PARENT_BINFO and see if there are any using decls. If
291 : there are, see if they inherit DECL. If they do, that's where DECL must
292 : have been declared private. */
293 :
294 76 : for (tree parent_field = TYPE_FIELDS (BINFO_TYPE (parent_binfo));
295 346 : parent_field;
296 270 : parent_field = DECL_CHAIN (parent_field))
297 : /* Not necessary, but also check TREE_PRIVATE for the sake of
298 : eliminating obviously non-relevant using decls. */
299 282 : if (TREE_CODE (parent_field) == USING_DECL
300 282 : && TREE_PRIVATE (parent_field))
301 : {
302 52 : tree decl_stripped = strip_using_decl (parent_field);
303 :
304 : /* The using statement might be overloaded. If so, we need to
305 : check all of the overloads. */
306 160 : for (ovl_iterator iter (decl_stripped); iter; ++iter)
307 : /* If equal, the using statement inherits DECL, and so is the
308 : source of the access failure, so return it. */
309 66 : if (*iter == decl)
310 12 : return parent_field;
311 : }
312 :
313 : /* 2. If DECL was privately inherited by the parent class, then DECL will
314 : be inaccessible, even though it may originally have been accessible to
315 : deriving classes. In that case, the fault lies with the parent, since it
316 : used a private inheritance, so we return the parent as the source of the
317 : problem.
318 :
319 : Since this is the last check, we just assume it's true. At worst, it
320 : will simply point to the class that failed to give access, which is
321 : technically true. */
322 64 : return TYPE_NAME (BINFO_TYPE (parent_binfo));
323 : }
324 :
325 : /* If the current scope isn't allowed to access DECL along
326 : BASETYPE_PATH, give an error, or if we're parsing a function or class
327 : template, defer the access check to be performed at instantiation time.
328 : The most derived class in BASETYPE_PATH is the one used to qualify DECL.
329 : DIAG_DECL is the declaration to use in the error diagnostic. */
330 :
331 : static bool
332 155343211 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
333 : tsubst_flags_t complain, access_failure_info *afi = NULL)
334 : {
335 155343211 : gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
336 :
337 155343211 : if (flag_new_inheriting_ctors
338 202590523 : && DECL_INHERITED_CTOR (decl))
339 : {
340 : /* 7.3.3/18: The additional constructors are accessible if they would be
341 : accessible when used to construct an object of the corresponding base
342 : class. */
343 30136 : decl = strip_inheriting_ctors (decl);
344 30136 : basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
345 : ba_any, NULL, complain);
346 : }
347 :
348 155343211 : tree cs = current_scope ();
349 155343211 : if (in_template_context
350 155343211 : && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
351 31700360 : if (tree template_info = get_template_info (cs))
352 : {
353 : /* When parsing a function or class template, we in general need to
354 : defer access checks until template instantiation time, since a friend
355 : declaration may grant access only to a particular specialization of
356 : the template. */
357 :
358 27526275 : if (accessible_p (basetype_path, decl, /*consider_local_p=*/true))
359 : /* But if the member is deemed accessible at parse time, then we can
360 : assume it'll be accessible at instantiation time. */
361 : return true;
362 :
363 : /* Access of a dependent decl should be rechecked after tsubst'ing
364 : into the user of the decl, rather than explicitly deferring the
365 : check here. */
366 166 : gcc_assert (!uses_template_parms (decl));
367 166 : if (TREE_CODE (decl) == FIELD_DECL)
368 8 : gcc_assert (!uses_template_parms (DECL_CONTEXT (decl)));
369 :
370 : /* Defer this access check until instantiation time. */
371 166 : deferred_access_check access_check;
372 166 : access_check.binfo = basetype_path;
373 166 : access_check.decl = decl;
374 166 : access_check.diag_decl = diag_decl;
375 166 : access_check.loc = input_location;
376 166 : vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info), access_check);
377 166 : return true;
378 : }
379 :
380 127816936 : if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
381 : {
382 16741 : if (flag_new_inheriting_ctors)
383 16711 : diag_decl = strip_inheriting_ctors (diag_decl);
384 16741 : if (complain & tf_error)
385 : {
386 1316 : access_kind access_failure_reason = ak_none;
387 :
388 : /* By default, using the decl as the source of the problem will
389 : usually give correct results. */
390 1316 : tree diag_location = diag_decl;
391 :
392 : /* However, if a parent of BASETYPE_PATH had private access to decl,
393 : then it actually might be the case that the source of the problem
394 : is not DECL. */
395 1316 : tree parent_binfo = get_parent_with_private_access (decl,
396 : basetype_path);
397 :
398 : /* So if a parent did have private access, then we need to do
399 : special checks to obtain the best diagnostic location decl. */
400 1316 : if (parent_binfo != NULL_TREE)
401 : {
402 221 : diag_location = get_class_access_diagnostic_decl (parent_binfo,
403 : diag_decl);
404 :
405 : /* We also at this point know that the reason access failed was
406 : because decl was private. */
407 221 : access_failure_reason = ak_private;
408 : }
409 :
410 : /* Finally, generate an error message. */
411 1316 : complain_about_access (decl, diag_decl, diag_location, true,
412 : access_failure_reason);
413 : }
414 16741 : if (afi)
415 425 : afi->record_access_failure (basetype_path, decl, diag_decl);
416 16741 : return false;
417 : }
418 :
419 : return true;
420 : }
421 :
422 : /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
423 : is the BINFO indicating the qualifying scope used to access the
424 : DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
425 : or we aren't in SFINAE context or all the checks succeed return TRUE,
426 : otherwise FALSE. */
427 :
428 : bool
429 593693183 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
430 : tsubst_flags_t complain)
431 : {
432 593693183 : int i;
433 593693183 : deferred_access_check *chk;
434 593693183 : location_t loc = input_location;
435 593693183 : bool ok = true;
436 :
437 593693183 : if (!checks)
438 : return true;
439 :
440 80652922 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
441 : {
442 44785744 : input_location = chk->loc;
443 44785744 : ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
444 : }
445 :
446 35867178 : input_location = loc;
447 35867178 : return (complain & tf_error) ? true : ok;
448 : }
449 :
450 : /* Perform the deferred access checks.
451 :
452 : After performing the checks, we still have to keep the list
453 : `deferred_access_stack->deferred_access_checks' since we may want
454 : to check access for them again later in a different context.
455 : For example:
456 :
457 : class A {
458 : typedef int X;
459 : static X a;
460 : };
461 : A::X A::a, x; // No error for `A::a', error for `x'
462 :
463 : We have to perform deferred access of `A::X', first with `A::a',
464 : next with `x'. Return value like perform_access_checks above. */
465 :
466 : bool
467 164162056 : perform_deferred_access_checks (tsubst_flags_t complain)
468 : {
469 164162056 : return perform_access_checks (get_deferred_access_checks (), complain);
470 : }
471 :
472 : /* Defer checking the accessibility of DECL, when looked up in
473 : BINFO. DIAG_DECL is the declaration to use to print diagnostics.
474 : Return value like perform_access_checks above.
475 : If non-NULL, report failures to AFI. */
476 :
477 : bool
478 252680903 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
479 : tsubst_flags_t complain,
480 : access_failure_info *afi)
481 : {
482 252680903 : int i;
483 252680903 : deferred_access *ptr;
484 252680903 : deferred_access_check *chk;
485 :
486 : /* Exit if we are in a context that no access checking is performed. */
487 252680903 : if (deferred_access_no_check)
488 : return true;
489 :
490 239583400 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
491 :
492 239583400 : ptr = &deferred_access_stack->last ();
493 :
494 : /* If we are not supposed to defer access checks, just check now. */
495 239583400 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
496 : {
497 110557467 : bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
498 199342244 : return (complain & tf_error) ? true : ok;
499 : }
500 :
501 : /* See if we are already going to perform this check. */
502 154770691 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
503 : {
504 34055361 : if (chk->decl == decl && chk->binfo == binfo &&
505 8310702 : chk->diag_decl == diag_decl)
506 : {
507 : return true;
508 : }
509 : }
510 : /* If not, record the check. */
511 120715330 : deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
512 120715330 : vec_safe_push (ptr->deferred_access_checks, new_access);
513 :
514 120715330 : return true;
515 : }
516 :
517 : /* Returns nonzero if the current statement is a full expression,
518 : i.e. temporaries created during that statement should be destroyed
519 : at the end of the statement. */
520 :
521 : int
522 684231176 : stmts_are_full_exprs_p (void)
523 : {
524 1368462352 : return current_stmt_tree ()->stmts_are_full_exprs_p;
525 : }
526 :
527 : /* T is a statement. Add it to the statement-tree. This is the C++
528 : version. The C/ObjC frontends have a slightly different version of
529 : this function. */
530 :
531 : tree
532 637677687 : add_stmt (tree t)
533 : {
534 637677687 : enum tree_code code = TREE_CODE (t);
535 :
536 637677687 : if (EXPR_P (t) && code != LABEL_EXPR)
537 : {
538 611118835 : if (!EXPR_HAS_LOCATION (t))
539 104134879 : SET_EXPR_LOCATION (t, input_location);
540 :
541 : /* When we expand a statement-tree, we must know whether or not the
542 : statements are full-expressions. We record that fact here. */
543 611118835 : if (STATEMENT_CODE_P (TREE_CODE (t)))
544 151041741 : STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
545 : }
546 :
547 637677687 : if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
548 1497539 : STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
549 :
550 : /* Add T to the statement-tree. Non-side-effect statements need to be
551 : recorded during statement expressions. */
552 637677687 : gcc_checking_assert (!stmt_list_stack->is_empty ());
553 637677687 : append_to_statement_list_force (t, &cur_stmt_list);
554 :
555 637677687 : return t;
556 : }
557 :
558 : /* Returns the stmt_tree to which statements are currently being added. */
559 :
560 : stmt_tree
561 3061444525 : current_stmt_tree (void)
562 : {
563 3061444525 : return (cfun
564 3053143824 : ? &cfun->language->base.x_stmt_tree
565 3061444525 : : &scope_chain->x_stmt_tree);
566 : }
567 :
568 : /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
569 :
570 : static tree
571 163453 : maybe_cleanup_point_expr (tree expr)
572 : {
573 326906 : if (!processing_template_decl && stmts_are_full_exprs_p ())
574 158896 : expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
575 163453 : return expr;
576 : }
577 :
578 : /* Like maybe_cleanup_point_expr except have the type of the new expression be
579 : void so we don't need to create a temporary variable to hold the inner
580 : expression. The reason why we do this is because the original type might be
581 : an aggregate and we cannot create a temporary variable for that type. */
582 :
583 : tree
584 160426224 : maybe_cleanup_point_expr_void (tree expr)
585 : {
586 218864638 : if (!processing_template_decl && stmts_are_full_exprs_p ())
587 56452292 : expr = fold_build_cleanup_point_expr (void_type_node, expr);
588 160426224 : return expr;
589 : }
590 :
591 :
592 :
593 : /* Create a declaration statement for the declaration given by the DECL. */
594 :
595 : void
596 52882336 : add_decl_expr (tree decl)
597 : {
598 52882336 : tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
599 52882336 : if (DECL_INITIAL (decl)
600 52882336 : || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
601 3960282 : r = maybe_cleanup_point_expr_void (r);
602 52882336 : add_stmt (r);
603 52882336 : }
604 :
605 : /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC. */
606 :
607 : static void
608 604044153 : set_cleanup_locs (tree stmts, location_t loc)
609 : {
610 607460370 : if (TREE_CODE (stmts) == CLEANUP_STMT)
611 : {
612 3416217 : tree t = CLEANUP_EXPR (stmts);
613 3416217 : if (t && TREE_CODE (t) != POSTCONDITION_STMT)
614 3416217 : protected_set_expr_location (t, loc);
615 : /* Avoid locus differences for C++ cdtor calls depending on whether
616 : cdtor_returns_this: a conversion to void is added to discard the return
617 : value, and this conversion ends up carrying the location, and when it
618 : gets discarded, the location is lost. So hold it in the call as
619 : well. */
620 3416217 : if (TREE_CODE (t) == NOP_EXPR
621 0 : && TREE_TYPE (t) == void_type_node
622 3416217 : && TREE_CODE (TREE_OPERAND (t, 0)) == CALL_EXPR)
623 0 : protected_set_expr_location (TREE_OPERAND (t, 0), loc);
624 3416217 : set_cleanup_locs (CLEANUP_BODY (stmts), loc);
625 : }
626 604044153 : else if (TREE_CODE (stmts) == STATEMENT_LIST)
627 545482821 : for (tree stmt : tsi_range (stmts))
628 419190415 : set_cleanup_locs (stmt, loc);
629 604044153 : }
630 :
631 : /* True iff the innermost block scope is a try block. */
632 :
633 : static bool
634 184853738 : at_try_scope ()
635 : {
636 184853738 : cp_binding_level *b = current_binding_level;
637 184853827 : while (b && b->kind == sk_cleanup)
638 89 : b = b->level_chain;
639 184853738 : return b && b->kind == sk_try;
640 : }
641 :
642 : /* Finish a scope. */
643 :
644 : tree
645 184853738 : do_poplevel (tree stmt_list)
646 : {
647 184853738 : tree block = NULL;
648 :
649 184853738 : bool was_try = at_try_scope ();
650 :
651 369707476 : if (stmts_are_full_exprs_p ())
652 184847106 : block = poplevel (kept_level_p (), 1, 0);
653 :
654 : /* This needs to come after poplevel merges sk_cleanup statement_lists. */
655 184853738 : maybe_splice_retval_cleanup (stmt_list, was_try);
656 :
657 184853738 : stmt_list = pop_stmt_list (stmt_list);
658 :
659 : /* input_location is the last token of the scope, usually a }. */
660 184853738 : set_cleanup_locs (stmt_list, input_location);
661 :
662 184853738 : if (!processing_template_decl)
663 : {
664 53602927 : stmt_list = c_build_bind_expr (input_location, block, stmt_list);
665 : /* ??? See c_end_compound_stmt re statement expressions. */
666 : }
667 :
668 184853738 : return stmt_list;
669 : }
670 :
671 : /* Begin a new scope. */
672 :
673 : static tree
674 184853500 : do_pushlevel (scope_kind sk)
675 : {
676 184853500 : tree ret = push_stmt_list ();
677 369707000 : if (stmts_are_full_exprs_p ())
678 184847150 : begin_scope (sk, NULL);
679 184853500 : return ret;
680 : }
681 :
682 : /* Queue a cleanup. CLEANUP is an expression/statement to be executed
683 : when the current scope is exited. EH_ONLY is true when this is not
684 : meant to apply to normal control flow transfer. DECL is the VAR_DECL
685 : being cleaned up, if any, or null for temporaries or subobjects. */
686 :
687 : void
688 3416056 : push_cleanup (tree decl, tree cleanup, bool eh_only)
689 : {
690 3416056 : tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
691 3416056 : CLEANUP_EH_ONLY (stmt) = eh_only;
692 3416056 : add_stmt (stmt);
693 3416056 : CLEANUP_BODY (stmt) = push_stmt_list ();
694 3416056 : }
695 :
696 : /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
697 : the current loops, represented by 'NULL_TREE' if we've seen a possible
698 : exit, and 'error_mark_node' if not. This is currently used only to
699 : suppress the warning about a function with no return statements, and
700 : therefore we don't bother noting returns as possible exits. We also
701 : don't bother with gotos. */
702 :
703 : static void
704 9700300 : begin_maybe_infinite_loop (tree cond)
705 : {
706 : /* Only track this while parsing a function, not during instantiation. */
707 9700300 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
708 1308333 : && !processing_template_decl))
709 : return;
710 8391501 : bool maybe_infinite = true;
711 8391501 : if (cond)
712 : {
713 8255385 : cond = fold_non_dependent_expr (cond);
714 8255385 : maybe_infinite = integer_nonzerop (cond);
715 : }
716 16646886 : vec_safe_push (cp_function_chain->infinite_loops,
717 8391501 : maybe_infinite ? error_mark_node : NULL_TREE);
718 :
719 : }
720 :
721 : /* A break is a possible exit for the current loop. */
722 :
723 : void
724 915382 : break_maybe_infinite_loop (void)
725 : {
726 915382 : if (!cfun)
727 : return;
728 915382 : cp_function_chain->infinite_loops->last() = NULL_TREE;
729 : }
730 :
731 : /* If we reach the end of the loop without seeing a possible exit, we have
732 : an infinite loop. */
733 :
734 : static void
735 9700300 : end_maybe_infinite_loop (tree cond)
736 : {
737 9700300 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
738 1308333 : && !processing_template_decl))
739 : return;
740 8391501 : tree current = cp_function_chain->infinite_loops->pop();
741 8391501 : if (current != NULL_TREE)
742 : {
743 2293002 : cond = fold_non_dependent_expr (cond);
744 2293002 : if (integer_nonzerop (cond))
745 127278 : current_function_infinite_loop = 1;
746 : }
747 : }
748 :
749 : /* Begin a conditional that might contain a declaration. When generating
750 : normal code, we want the declaration to appear before the statement
751 : containing the conditional. When generating template code, we want the
752 : conditional to be rendered as the raw DECL_EXPR. */
753 :
754 : static void
755 37542155 : begin_cond (tree *cond_p)
756 : {
757 37542155 : if (processing_template_decl)
758 27453897 : *cond_p = push_stmt_list ();
759 37542155 : }
760 :
761 : /* Finish such a conditional. */
762 :
763 : static void
764 37542155 : finish_cond (tree *cond_p, tree expr)
765 : {
766 37542155 : if (processing_template_decl)
767 : {
768 27453897 : tree cond = pop_stmt_list (*cond_p);
769 :
770 27453897 : if (expr == NULL_TREE)
771 : /* Empty condition in 'for'. */
772 133582 : gcc_assert (empty_expr_stmt_p (cond));
773 27320315 : else if (check_for_bare_parameter_packs (expr))
774 0 : expr = error_mark_node;
775 27320315 : else if (!empty_expr_stmt_p (cond))
776 304651 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
777 : }
778 37542155 : *cond_p = expr;
779 37542155 : }
780 :
781 : /* If *COND_P specifies a conditional with a declaration, transform the
782 : loop such that
783 : while (A x = 42) { }
784 : for (; A x = 42;) { }
785 : becomes
786 : while (true) { A x = 42; if (!x) break; }
787 : for (;;) { A x = 42; if (!x) break; }
788 : The statement list for BODY will be empty if the conditional did
789 : not declare anything. */
790 :
791 : static void
792 6987058 : simplify_loop_decl_cond (tree *cond_p, tree body)
793 : {
794 6987058 : tree cond, if_stmt;
795 :
796 6987058 : if (!TREE_SIDE_EFFECTS (body))
797 : return;
798 :
799 6956 : cond = *cond_p;
800 6956 : *cond_p = boolean_true_node;
801 :
802 6956 : if_stmt = begin_if_stmt ();
803 6956 : cond = cp_build_unary_op (TRUTH_NOT_EXPR, cond, false, tf_warning_or_error);
804 6956 : finish_if_stmt_cond (cond, if_stmt);
805 6956 : finish_break_stmt ();
806 6956 : finish_then_clause (if_stmt);
807 6956 : finish_if_stmt (if_stmt);
808 : }
809 :
810 : /* Finish a goto-statement. */
811 :
812 : tree
813 1553 : finish_goto_stmt (tree destination)
814 : {
815 1553 : if (identifier_p (destination))
816 1438 : destination = lookup_label (destination);
817 :
818 : /* We warn about unused labels with -Wunused. That means we have to
819 : mark the used labels as used. */
820 1553 : if (TREE_CODE (destination) == LABEL_DECL)
821 1438 : TREE_USED (destination) = 1;
822 : else
823 : {
824 115 : destination = mark_rvalue_use (destination);
825 115 : if (!processing_template_decl)
826 : {
827 91 : destination = cp_convert (ptr_type_node, destination,
828 : tf_warning_or_error);
829 91 : if (error_operand_p (destination))
830 : return NULL_TREE;
831 79 : destination
832 79 : = fold_build_cleanup_point_expr (TREE_TYPE (destination),
833 : destination);
834 : }
835 : }
836 :
837 1541 : check_goto (destination);
838 :
839 1541 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
840 1541 : return add_stmt (build_stmt (input_location, GOTO_EXPR, destination));
841 : }
842 :
843 : /* Returns true if CALL is a (possibly wrapped) CALL_EXPR or AGGR_INIT_EXPR
844 : to operator= () that is written as an operator expression. */
845 : static bool
846 22172741 : is_assignment_op_expr_p (tree call)
847 : {
848 22172741 : if (call == NULL_TREE)
849 : return false;
850 :
851 22172741 : call = extract_call_expr (call);
852 22172741 : if (call == NULL_TREE
853 1710834 : || call == error_mark_node
854 23883183 : || !CALL_EXPR_OPERATOR_SYNTAX (call))
855 : return false;
856 :
857 212107 : tree fndecl = cp_get_callee_fndecl_nofold (call);
858 212107 : return fndecl != NULL_TREE
859 198263 : && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
860 212139 : && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR);
861 : }
862 :
863 : /* COND is the condition-expression for an if, while, etc.,
864 : statement. Convert it to a boolean value, if appropriate.
865 : In addition, verify sequence points if -Wsequence-point is enabled. */
866 :
867 : static tree
868 39895412 : maybe_convert_cond (tree cond)
869 : {
870 : /* Empty conditions remain empty. */
871 39895412 : if (!cond)
872 : return NULL_TREE;
873 :
874 : /* Wait until we instantiate templates before doing conversion. */
875 39719205 : if (type_dependent_expression_p (cond))
876 : return cond;
877 :
878 22180046 : if (warn_sequence_point && !processing_template_decl)
879 250126 : verify_sequence_points (cond);
880 :
881 : /* Do the conversion. */
882 22180046 : cond = convert_from_reference (cond);
883 :
884 22172741 : if ((TREE_CODE (cond) == MODIFY_EXPR || is_assignment_op_expr_p (cond))
885 7333 : && warn_parentheses
886 468 : && !warning_suppressed_p (cond, OPT_Wparentheses)
887 22180242 : && warning_at (cp_expr_loc_or_input_loc (cond),
888 : OPT_Wparentheses, "suggest parentheses around "
889 : "assignment used as truth value"))
890 196 : suppress_warning (cond, OPT_Wparentheses);
891 :
892 22180046 : return condition_conversion (cond);
893 : }
894 :
895 : /* Finish an expression-statement, whose EXPRESSION is as indicated. */
896 :
897 : tree
898 87575147 : finish_expr_stmt (tree expr)
899 : {
900 87575147 : tree r = NULL_TREE;
901 87575147 : location_t loc = EXPR_LOCATION (expr);
902 :
903 87492901 : if (expr != NULL_TREE)
904 : {
905 : /* If we ran into a problem, make sure we complained. */
906 87574290 : gcc_assert (expr != error_mark_node || seen_error ());
907 :
908 87574290 : if (!processing_template_decl)
909 : {
910 32185626 : if (warn_sequence_point)
911 684419 : verify_sequence_points (expr);
912 32185626 : expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
913 : }
914 55388664 : else if (!type_dependent_expression_p (expr))
915 6791631 : convert_to_void (build_non_dependent_expr (expr), ICV_STATEMENT,
916 : tf_warning_or_error);
917 :
918 87574286 : if (check_for_bare_parameter_packs (expr))
919 24 : expr = error_mark_node;
920 :
921 : /* Simplification of inner statement expressions, compound exprs,
922 : etc can result in us already having an EXPR_STMT. */
923 87574286 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
924 : {
925 87573124 : if (TREE_CODE (expr) != EXPR_STMT)
926 86627955 : expr = build_stmt (loc, EXPR_STMT, expr);
927 87573124 : expr = maybe_cleanup_point_expr_void (expr);
928 : }
929 :
930 87574286 : r = add_stmt (expr);
931 : }
932 :
933 87575143 : return r;
934 : }
935 :
936 :
937 : /* Begin an if-statement. Returns a newly created IF_STMT if
938 : appropriate. */
939 :
940 : tree
941 30318529 : begin_if_stmt (void)
942 : {
943 30318529 : tree r, scope;
944 30318529 : scope = do_pushlevel (sk_cond);
945 30318529 : r = build_stmt (input_location, IF_STMT, NULL_TREE,
946 : NULL_TREE, NULL_TREE, scope);
947 30318529 : current_binding_level->this_entity = r;
948 30318529 : begin_cond (&IF_COND (r));
949 30318529 : return r;
950 : }
951 :
952 : /* Returns true if FN, a CALL_EXPR, is a call to
953 : std::is_constant_evaluated or __builtin_is_constant_evaluated. */
954 :
955 : static bool
956 169933 : is_std_constant_evaluated_p (tree fn)
957 : {
958 : /* std::is_constant_evaluated takes no arguments. */
959 169933 : if (call_expr_nargs (fn) != 0)
960 : return false;
961 :
962 57150 : tree fndecl = cp_get_callee_fndecl_nofold (fn);
963 57150 : if (fndecl == NULL_TREE)
964 : return false;
965 :
966 14793 : if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
967 : BUILT_IN_FRONTEND))
968 : return true;
969 :
970 14785 : if (!decl_in_std_namespace_p (fndecl))
971 : return false;
972 :
973 3662 : tree name = DECL_NAME (fndecl);
974 3662 : return name && id_equal (name, "is_constant_evaluated");
975 : }
976 :
977 : /* Callback function for maybe_warn_for_constant_evaluated that looks
978 : for calls to std::is_constant_evaluated in TP. */
979 :
980 : static tree
981 2963555 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
982 : {
983 2963555 : tree t = *tp;
984 :
985 2963555 : if (TYPE_P (t) || TREE_CONSTANT (t))
986 : {
987 523883 : *walk_subtrees = false;
988 523883 : return NULL_TREE;
989 : }
990 :
991 2439672 : switch (TREE_CODE (t))
992 : {
993 169933 : case CALL_EXPR:
994 169933 : if (is_std_constant_evaluated_p (t))
995 : return t;
996 : break;
997 8 : case EXPR_STMT:
998 : /* Don't warn in statement expressions. */
999 8 : *walk_subtrees = false;
1000 8 : return NULL_TREE;
1001 : default:
1002 : break;
1003 : }
1004 :
1005 : return NULL_TREE;
1006 : }
1007 :
1008 : /* In certain contexts, std::is_constant_evaluated() is always true (for
1009 : instance, in a consteval function or in a constexpr if), or always false
1010 : (e.g., in a non-constexpr non-consteval function) so give the user a clue. */
1011 :
1012 : static void
1013 30318529 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if)
1014 : {
1015 30318529 : if (!warn_tautological_compare)
1016 : return;
1017 :
1018 : /* Suppress warning for std::is_constant_evaluated if the conditional
1019 : comes from a macro. */
1020 905350 : if (from_macro_expansion_at (EXPR_LOCATION (cond)))
1021 : return;
1022 :
1023 353723 : cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
1024 : NULL);
1025 353723 : if (cond)
1026 : {
1027 355 : if (constexpr_if)
1028 10 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1029 : "%<std::is_constant_evaluated%> always evaluates to "
1030 : "true in %<if constexpr%>");
1031 345 : else if (!maybe_constexpr_fn (current_function_decl))
1032 2 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1033 : "%<std::is_constant_evaluated%> always evaluates to "
1034 : "false in a non-%<constexpr%> function");
1035 686 : else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1036 1 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1037 : "%<std::is_constant_evaluated%> always evaluates to "
1038 : "true in a %<consteval%> function");
1039 : }
1040 : }
1041 :
1042 : /* Process the COND of an if-statement, which may be given by
1043 : IF_STMT. */
1044 :
1045 : tree
1046 30318529 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
1047 : {
1048 30318529 : tree cond = maybe_convert_cond (orig_cond);
1049 30318529 : if (IF_STMT_CONSTEXPR_P (if_stmt)
1050 1986103 : && !type_dependent_expression_p (cond)
1051 1087931 : && require_constant_expression (cond)
1052 1087913 : && !instantiation_dependent_expression_p (cond)
1053 : /* Wait until instantiation time, since only then COND has been
1054 : converted to bool. */
1055 30802349 : && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
1056 : {
1057 483820 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/true);
1058 483820 : cond = instantiate_non_dependent_expr (cond);
1059 483820 : cond = cxx_constant_value (cond);
1060 : }
1061 : else
1062 : {
1063 29834709 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false);
1064 29834709 : if (processing_template_decl)
1065 21501718 : cond = orig_cond;
1066 : }
1067 30318529 : finish_cond (&IF_COND (if_stmt), cond);
1068 30318529 : add_stmt (if_stmt);
1069 30318529 : THEN_CLAUSE (if_stmt) = push_stmt_list ();
1070 30318529 : return cond;
1071 : }
1072 :
1073 : /* Finish the then-clause of an if-statement, which may be given by
1074 : IF_STMT. */
1075 :
1076 : tree
1077 30317875 : finish_then_clause (tree if_stmt)
1078 : {
1079 30317875 : THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
1080 30317875 : return if_stmt;
1081 : }
1082 :
1083 : /* Begin the else-clause of an if-statement. */
1084 :
1085 : void
1086 10617595 : begin_else_clause (tree if_stmt)
1087 : {
1088 10617595 : ELSE_CLAUSE (if_stmt) = push_stmt_list ();
1089 10617595 : }
1090 :
1091 : /* Finish the else-clause of an if-statement, which may be given by
1092 : IF_STMT. */
1093 :
1094 : void
1095 10617595 : finish_else_clause (tree if_stmt)
1096 : {
1097 10617595 : ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
1098 10617595 : }
1099 :
1100 : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1101 : read. */
1102 :
1103 : static tree
1104 101881892 : maybe_mark_exp_read_r (tree *tp, int *, void *)
1105 : {
1106 101881892 : tree t = *tp;
1107 101881892 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1108 7064511 : mark_exp_read (t);
1109 101881892 : return NULL_TREE;
1110 : }
1111 :
1112 : /* Finish an if-statement. */
1113 :
1114 : void
1115 30313699 : finish_if_stmt (tree if_stmt)
1116 : {
1117 30313699 : tree scope = IF_SCOPE (if_stmt);
1118 30313699 : IF_SCOPE (if_stmt) = NULL;
1119 30313699 : if (IF_STMT_CONSTEXPR_P (if_stmt))
1120 : {
1121 : /* Prevent various -Wunused warnings. We might not instantiate
1122 : either of these branches, so we would not mark the variables
1123 : used in that branch as read. */
1124 1985449 : cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
1125 : maybe_mark_exp_read_r, NULL);
1126 1985449 : cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
1127 : maybe_mark_exp_read_r, NULL);
1128 : }
1129 30313699 : add_stmt (do_poplevel (scope));
1130 30313699 : }
1131 :
1132 : /* Begin a while-statement. Returns a newly created WHILE_STMT if
1133 : appropriate. */
1134 :
1135 : tree
1136 2469639 : begin_while_stmt (void)
1137 : {
1138 2469639 : tree r;
1139 2469639 : r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE);
1140 2469639 : add_stmt (r);
1141 2469639 : WHILE_BODY (r) = do_pushlevel (sk_block);
1142 2469639 : begin_cond (&WHILE_COND (r));
1143 2469639 : return r;
1144 : }
1145 :
1146 : /* Process the COND of a while-statement, which may be given by
1147 : WHILE_STMT. */
1148 :
1149 : void
1150 2469639 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
1151 : unsigned short unroll)
1152 : {
1153 2469639 : cond = maybe_convert_cond (cond);
1154 2469639 : finish_cond (&WHILE_COND (while_stmt), cond);
1155 2469639 : begin_maybe_infinite_loop (cond);
1156 2469639 : if (ivdep && cond != error_mark_node)
1157 8 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1158 4 : TREE_TYPE (WHILE_COND (while_stmt)),
1159 4 : WHILE_COND (while_stmt),
1160 : build_int_cst (integer_type_node,
1161 4 : annot_expr_ivdep_kind),
1162 : integer_zero_node);
1163 2469639 : if (unroll && cond != error_mark_node)
1164 0 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1165 0 : TREE_TYPE (WHILE_COND (while_stmt)),
1166 0 : WHILE_COND (while_stmt),
1167 : build_int_cst (integer_type_node,
1168 0 : annot_expr_unroll_kind),
1169 : build_int_cst (integer_type_node,
1170 : unroll));
1171 2469639 : simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
1172 2469639 : }
1173 :
1174 : /* Finish a while-statement, which may be given by WHILE_STMT. */
1175 :
1176 : void
1177 2469639 : finish_while_stmt (tree while_stmt)
1178 : {
1179 2469639 : end_maybe_infinite_loop (boolean_true_node);
1180 2469639 : WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
1181 2469639 : }
1182 :
1183 : /* Begin a do-statement. Returns a newly created DO_STMT if
1184 : appropriate. */
1185 :
1186 : tree
1187 2587069 : begin_do_stmt (void)
1188 : {
1189 2587069 : tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE);
1190 2587069 : begin_maybe_infinite_loop (boolean_true_node);
1191 2587069 : add_stmt (r);
1192 2587069 : DO_BODY (r) = push_stmt_list ();
1193 2587069 : return r;
1194 : }
1195 :
1196 : /* Finish the body of a do-statement, which may be given by DO_STMT. */
1197 :
1198 : void
1199 2587069 : finish_do_body (tree do_stmt)
1200 : {
1201 2587069 : tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
1202 :
1203 2587069 : if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
1204 288724 : body = STATEMENT_LIST_TAIL (body)->stmt;
1205 :
1206 2587069 : if (IS_EMPTY_STMT (body))
1207 16 : warning (OPT_Wempty_body,
1208 : "suggest explicit braces around empty body in %<do%> statement");
1209 2587069 : }
1210 :
1211 : /* Finish a do-statement, which may be given by DO_STMT, and whose
1212 : COND is as indicated. */
1213 :
1214 : void
1215 2587069 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, unsigned short unroll)
1216 : {
1217 2587069 : cond = maybe_convert_cond (cond);
1218 2587069 : end_maybe_infinite_loop (cond);
1219 : /* Unlike other iteration statements, the condition may not contain
1220 : a declaration, so we don't call finish_cond which checks for
1221 : unexpanded parameter packs. */
1222 2587069 : if (check_for_bare_parameter_packs (cond))
1223 3 : cond = error_mark_node;
1224 2587069 : if (ivdep && cond != error_mark_node)
1225 4 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1226 4 : build_int_cst (integer_type_node, annot_expr_ivdep_kind),
1227 : integer_zero_node);
1228 2587069 : if (unroll && cond != error_mark_node)
1229 12 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1230 12 : build_int_cst (integer_type_node, annot_expr_unroll_kind),
1231 : build_int_cst (integer_type_node, unroll));
1232 2587069 : DO_COND (do_stmt) = cond;
1233 2587069 : }
1234 :
1235 : /* Finish a return-statement. The EXPRESSION returned, if any, is as
1236 : indicated. */
1237 :
1238 : tree
1239 64555636 : finish_return_stmt (tree expr)
1240 : {
1241 64555636 : tree r;
1242 64555636 : bool no_warning;
1243 :
1244 64555636 : expr = check_return_expr (expr, &no_warning);
1245 :
1246 64555636 : if (error_operand_p (expr)
1247 64555636 : || (flag_openmp && !check_omp_return ()))
1248 : {
1249 : /* Suppress -Wreturn-type for this function. */
1250 1153 : if (warn_return_type)
1251 1146 : suppress_warning (current_function_decl, OPT_Wreturn_type);
1252 1153 : return error_mark_node;
1253 : }
1254 :
1255 64554483 : if (!processing_template_decl)
1256 : {
1257 21697716 : if (warn_sequence_point)
1258 830163 : verify_sequence_points (expr);
1259 : }
1260 :
1261 64554483 : r = build_stmt (input_location, RETURN_EXPR, expr);
1262 64554483 : if (no_warning)
1263 34 : suppress_warning (r, OPT_Wreturn_type);
1264 64554483 : r = maybe_cleanup_point_expr_void (r);
1265 64554483 : r = add_stmt (r);
1266 :
1267 64554483 : return r;
1268 : }
1269 :
1270 : /* Begin the scope of a for-statement or a range-for-statement.
1271 : Both the returned trees are to be used in a call to
1272 : begin_for_stmt or begin_range_for_stmt. */
1273 :
1274 : tree
1275 4643592 : begin_for_scope (tree *init)
1276 : {
1277 4643592 : tree scope = do_pushlevel (sk_for);
1278 :
1279 4643592 : if (processing_template_decl)
1280 3790530 : *init = push_stmt_list ();
1281 : else
1282 853062 : *init = NULL_TREE;
1283 :
1284 4643592 : return scope;
1285 : }
1286 :
1287 : /* Begin a for-statement. Returns a new FOR_STMT.
1288 : SCOPE and INIT should be the return of begin_for_scope,
1289 : or both NULL_TREE */
1290 :
1291 : tree
1292 4517419 : begin_for_stmt (tree scope, tree init)
1293 : {
1294 4517419 : tree r;
1295 :
1296 4517419 : r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
1297 : NULL_TREE, NULL_TREE, NULL_TREE);
1298 :
1299 4517419 : if (scope == NULL_TREE)
1300 : {
1301 734538 : gcc_assert (!init);
1302 734538 : scope = begin_for_scope (&init);
1303 : }
1304 :
1305 4517419 : FOR_INIT_STMT (r) = init;
1306 4517419 : FOR_SCOPE (r) = scope;
1307 :
1308 4517419 : return r;
1309 : }
1310 :
1311 : /* Finish the init-statement of a for-statement, which may be
1312 : given by FOR_STMT. */
1313 :
1314 : void
1315 4517419 : finish_init_stmt (tree for_stmt)
1316 : {
1317 4517419 : if (processing_template_decl)
1318 3664357 : FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
1319 4517419 : add_stmt (for_stmt);
1320 4517419 : FOR_BODY (for_stmt) = do_pushlevel (sk_block);
1321 4517419 : begin_cond (&FOR_COND (for_stmt));
1322 4517419 : }
1323 :
1324 : /* Finish the COND of a for-statement, which may be given by
1325 : FOR_STMT. */
1326 :
1327 : void
1328 4517419 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, unsigned short unroll)
1329 : {
1330 4517419 : cond = maybe_convert_cond (cond);
1331 4517419 : finish_cond (&FOR_COND (for_stmt), cond);
1332 4517419 : begin_maybe_infinite_loop (cond);
1333 4517419 : if (ivdep && cond != error_mark_node)
1334 82 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1335 41 : TREE_TYPE (FOR_COND (for_stmt)),
1336 41 : FOR_COND (for_stmt),
1337 : build_int_cst (integer_type_node,
1338 41 : annot_expr_ivdep_kind),
1339 : integer_zero_node);
1340 4517419 : if (unroll && cond != error_mark_node)
1341 172 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1342 86 : TREE_TYPE (FOR_COND (for_stmt)),
1343 86 : FOR_COND (for_stmt),
1344 : build_int_cst (integer_type_node,
1345 86 : annot_expr_unroll_kind),
1346 : build_int_cst (integer_type_node,
1347 : unroll));
1348 4517419 : simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt));
1349 4517419 : }
1350 :
1351 : /* Finish the increment-EXPRESSION in a for-statement, which may be
1352 : given by FOR_STMT. */
1353 :
1354 : void
1355 4514244 : finish_for_expr (tree expr, tree for_stmt)
1356 : {
1357 4514244 : if (!expr)
1358 : return;
1359 : /* If EXPR is an overloaded function, issue an error; there is no
1360 : context available to use to perform overload resolution. */
1361 4271530 : if (type_unknown_p (expr))
1362 : {
1363 8 : cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1364 8 : expr = error_mark_node;
1365 : }
1366 4271530 : if (!processing_template_decl)
1367 : {
1368 807746 : if (warn_sequence_point)
1369 9312 : verify_sequence_points (expr);
1370 807746 : expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1371 : tf_warning_or_error);
1372 : }
1373 3463784 : else if (!type_dependent_expression_p (expr))
1374 1357793 : convert_to_void (build_non_dependent_expr (expr), ICV_THIRD_IN_FOR,
1375 : tf_warning_or_error);
1376 4271530 : expr = maybe_cleanup_point_expr_void (expr);
1377 4271530 : if (check_for_bare_parameter_packs (expr))
1378 0 : expr = error_mark_node;
1379 4271530 : FOR_EXPR (for_stmt) = expr;
1380 : }
1381 :
1382 : /* Finish the body of a for-statement, which may be given by
1383 : FOR_STMT. The increment-EXPR for the loop must be
1384 : provided.
1385 : It can also finish RANGE_FOR_STMT. */
1386 :
1387 : void
1388 4643592 : finish_for_stmt (tree for_stmt)
1389 : {
1390 4643592 : end_maybe_infinite_loop (boolean_true_node);
1391 :
1392 4643592 : if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1393 126173 : RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1394 : else
1395 4517419 : FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1396 :
1397 : /* Pop the scope for the body of the loop. */
1398 4643592 : tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1399 4643592 : ? &RANGE_FOR_SCOPE (for_stmt)
1400 4517419 : : &FOR_SCOPE (for_stmt));
1401 4643592 : tree scope = *scope_ptr;
1402 4643592 : *scope_ptr = NULL;
1403 :
1404 : /* During parsing of the body, range for uses "__for_{range,begin,end} "
1405 : decl names to make those unaccessible by code in the body.
1406 : Change it to ones with underscore instead of space, so that it can
1407 : be inspected in the debugger. */
1408 4643592 : tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1409 4643592 : gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 1
1410 : && CPTI_FOR_END__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 2
1411 : && CPTI_FOR_RANGE_IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 3
1412 : && CPTI_FOR_BEGIN_IDENTIFIER == CPTI_FOR_BEGIN__IDENTIFIER + 3
1413 : && CPTI_FOR_END_IDENTIFIER == CPTI_FOR_END__IDENTIFIER + 3);
1414 18574368 : for (int i = 0; i < 3; i++)
1415 : {
1416 13930776 : tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1417 13930776 : if (IDENTIFIER_BINDING (id)
1418 13930776 : && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1419 : {
1420 96547 : range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1421 96547 : gcc_assert (VAR_P (range_for_decl[i])
1422 : && DECL_ARTIFICIAL (range_for_decl[i]));
1423 : }
1424 : }
1425 :
1426 4643592 : add_stmt (do_poplevel (scope));
1427 :
1428 : /* If we're being called from build_vec_init, don't mess with the names of
1429 : the variables for an enclosing range-for. */
1430 9287184 : if (!stmts_are_full_exprs_p ())
1431 3175 : return;
1432 :
1433 18561668 : for (int i = 0; i < 3; i++)
1434 13921251 : if (range_for_decl[i])
1435 96544 : DECL_NAME (range_for_decl[i])
1436 96544 : = cp_global_trees[CPTI_FOR_RANGE_IDENTIFIER + i];
1437 : }
1438 :
1439 : /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1440 : SCOPE and INIT should be the return of begin_for_scope,
1441 : or both NULL_TREE .
1442 : To finish it call finish_for_stmt(). */
1443 :
1444 : tree
1445 126173 : begin_range_for_stmt (tree scope, tree init)
1446 : {
1447 126173 : begin_maybe_infinite_loop (boolean_false_node);
1448 :
1449 126173 : tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1450 : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1451 :
1452 126173 : if (scope == NULL_TREE)
1453 : {
1454 6 : gcc_assert (!init);
1455 6 : scope = begin_for_scope (&init);
1456 : }
1457 :
1458 : /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1459 126173 : RANGE_FOR_INIT_STMT (r) = init;
1460 126173 : RANGE_FOR_SCOPE (r) = scope;
1461 :
1462 126173 : return r;
1463 : }
1464 :
1465 : /* Finish the head of a range-based for statement, which may
1466 : be given by RANGE_FOR_STMT. DECL must be the declaration
1467 : and EXPR must be the loop expression. */
1468 :
1469 : void
1470 126173 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1471 : {
1472 126173 : if (processing_template_decl)
1473 252346 : RANGE_FOR_INIT_STMT (range_for_stmt)
1474 252346 : = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1475 126173 : RANGE_FOR_DECL (range_for_stmt) = decl;
1476 126173 : RANGE_FOR_EXPR (range_for_stmt) = expr;
1477 126173 : add_stmt (range_for_stmt);
1478 126173 : RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1479 126173 : }
1480 :
1481 : /* Finish a break-statement. */
1482 :
1483 : tree
1484 1973187 : finish_break_stmt (void)
1485 : {
1486 : /* In switch statements break is sometimes stylistically used after
1487 : a return statement. This can lead to spurious warnings about
1488 : control reaching the end of a non-void function when it is
1489 : inlined. Note that we are calling block_may_fallthru with
1490 : language specific tree nodes; this works because
1491 : block_may_fallthru returns true when given something it does not
1492 : understand. */
1493 3946374 : if (!block_may_fallthru (cur_stmt_list))
1494 1055 : return void_node;
1495 1972132 : note_break_stmt ();
1496 1972132 : return add_stmt (build_stmt (input_location, BREAK_STMT));
1497 : }
1498 :
1499 : /* Finish a continue-statement. */
1500 :
1501 : tree
1502 79570 : finish_continue_stmt (void)
1503 : {
1504 79570 : return add_stmt (build_stmt (input_location, CONTINUE_STMT));
1505 : }
1506 :
1507 : /* Begin a switch-statement. Returns a new SWITCH_STMT if
1508 : appropriate. */
1509 :
1510 : tree
1511 236568 : begin_switch_stmt (void)
1512 : {
1513 236568 : tree r, scope;
1514 :
1515 236568 : scope = do_pushlevel (sk_cond);
1516 236568 : r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE, scope);
1517 :
1518 236568 : begin_cond (&SWITCH_STMT_COND (r));
1519 :
1520 236568 : return r;
1521 : }
1522 :
1523 : /* Finish the cond of a switch-statement. */
1524 :
1525 : void
1526 236568 : finish_switch_cond (tree cond, tree switch_stmt)
1527 : {
1528 236568 : tree orig_type = NULL;
1529 :
1530 236568 : if (!processing_template_decl)
1531 : {
1532 : /* Convert the condition to an integer or enumeration type. */
1533 143163 : tree orig_cond = cond;
1534 143163 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1535 143163 : if (cond == NULL_TREE)
1536 : {
1537 15 : error_at (cp_expr_loc_or_input_loc (orig_cond),
1538 : "switch quantity not an integer");
1539 15 : cond = error_mark_node;
1540 : }
1541 : /* We want unlowered type here to handle enum bit-fields. */
1542 143163 : orig_type = unlowered_expr_type (cond);
1543 143163 : if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1544 105469 : orig_type = TREE_TYPE (cond);
1545 143163 : if (cond != error_mark_node)
1546 : {
1547 : /* [stmt.switch]
1548 :
1549 : Integral promotions are performed. */
1550 143140 : cond = perform_integral_promotions (cond);
1551 143140 : cond = maybe_cleanup_point_expr (cond);
1552 : }
1553 : }
1554 236568 : if (check_for_bare_parameter_packs (cond))
1555 0 : cond = error_mark_node;
1556 236568 : else if (!processing_template_decl && warn_sequence_point)
1557 1601 : verify_sequence_points (cond);
1558 :
1559 236568 : finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1560 236568 : SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1561 236568 : add_stmt (switch_stmt);
1562 236568 : push_switch (switch_stmt);
1563 236568 : SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1564 236568 : }
1565 :
1566 : /* Finish the body of a switch-statement, which may be given by
1567 : SWITCH_STMT. The COND to switch on is indicated. */
1568 :
1569 : void
1570 233358 : finish_switch_stmt (tree switch_stmt)
1571 : {
1572 233358 : tree scope;
1573 :
1574 466716 : SWITCH_STMT_BODY (switch_stmt) =
1575 233358 : pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1576 233358 : pop_switch ();
1577 :
1578 233358 : scope = SWITCH_STMT_SCOPE (switch_stmt);
1579 233358 : SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1580 233358 : add_stmt (do_poplevel (scope));
1581 233358 : }
1582 :
1583 : /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1584 : appropriate. */
1585 :
1586 : tree
1587 992485 : begin_try_block (void)
1588 : {
1589 992485 : tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1590 992485 : add_stmt (r);
1591 992485 : TRY_STMTS (r) = push_stmt_list ();
1592 992485 : return r;
1593 : }
1594 :
1595 : /* Likewise, for a function-try-block. The block returned in
1596 : *COMPOUND_STMT is an artificial outer scope, containing the
1597 : function-try-block. */
1598 :
1599 : tree
1600 269 : begin_function_try_block (tree *compound_stmt)
1601 : {
1602 269 : tree r;
1603 : /* This outer scope does not exist in the C++ standard, but we need
1604 : a place to put __FUNCTION__ and similar variables. */
1605 269 : *compound_stmt = begin_compound_stmt (0);
1606 269 : r = begin_try_block ();
1607 269 : FN_TRY_BLOCK_P (r) = 1;
1608 269 : return r;
1609 : }
1610 :
1611 : /* Finish a try-block, which may be given by TRY_BLOCK. */
1612 :
1613 : void
1614 992485 : finish_try_block (tree try_block)
1615 : {
1616 992485 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
1617 992485 : TRY_HANDLERS (try_block) = push_stmt_list ();
1618 992485 : }
1619 :
1620 : /* Finish the body of a cleanup try-block, which may be given by
1621 : TRY_BLOCK. */
1622 :
1623 : void
1624 0 : finish_cleanup_try_block (tree try_block)
1625 : {
1626 0 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
1627 0 : }
1628 :
1629 : /* Finish an implicitly generated try-block, with a cleanup is given
1630 : by CLEANUP. */
1631 :
1632 : void
1633 0 : finish_cleanup (tree cleanup, tree try_block)
1634 : {
1635 0 : TRY_HANDLERS (try_block) = cleanup;
1636 0 : CLEANUP_P (try_block) = 1;
1637 0 : }
1638 :
1639 : /* Likewise, for a function-try-block. */
1640 :
1641 : void
1642 269 : finish_function_try_block (tree try_block)
1643 : {
1644 269 : finish_try_block (try_block);
1645 : /* FIXME : something queer about CTOR_INITIALIZER somehow following
1646 : the try block, but moving it inside. */
1647 269 : in_function_try_handler = 1;
1648 269 : }
1649 :
1650 : /* Finish a handler-sequence for a try-block, which may be given by
1651 : TRY_BLOCK. */
1652 :
1653 : void
1654 992485 : finish_handler_sequence (tree try_block)
1655 : {
1656 992485 : TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
1657 992485 : check_handlers (TRY_HANDLERS (try_block));
1658 992485 : }
1659 :
1660 : /* Finish the handler-seq for a function-try-block, given by
1661 : TRY_BLOCK. COMPOUND_STMT is the outer block created by
1662 : begin_function_try_block. */
1663 :
1664 : void
1665 269 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
1666 : {
1667 269 : in_function_try_handler = 0;
1668 269 : finish_handler_sequence (try_block);
1669 269 : finish_compound_stmt (compound_stmt);
1670 269 : }
1671 :
1672 : /* Begin a handler. Returns a HANDLER if appropriate. */
1673 :
1674 : tree
1675 1328031 : begin_handler (void)
1676 : {
1677 1328031 : tree r;
1678 :
1679 1328031 : r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
1680 1328031 : add_stmt (r);
1681 :
1682 : /* Create a binding level for the eh_info and the exception object
1683 : cleanup. */
1684 1328031 : HANDLER_BODY (r) = do_pushlevel (sk_catch);
1685 :
1686 1328031 : return r;
1687 : }
1688 :
1689 : /* Finish the handler-parameters for a handler, which may be given by
1690 : HANDLER. DECL is the declaration for the catch parameter, or NULL
1691 : if this is a `catch (...)' clause. */
1692 :
1693 : void
1694 1328031 : finish_handler_parms (tree decl, tree handler)
1695 : {
1696 1328031 : tree type = NULL_TREE;
1697 1328031 : if (processing_template_decl)
1698 : {
1699 1226981 : if (decl)
1700 : {
1701 345310 : decl = pushdecl (decl);
1702 345310 : decl = push_template_decl (decl);
1703 345310 : HANDLER_PARMS (handler) = decl;
1704 345310 : type = TREE_TYPE (decl);
1705 : }
1706 : }
1707 : else
1708 : {
1709 101050 : type = expand_start_catch_block (decl);
1710 101050 : if (warn_catch_value
1711 2131 : && type != NULL_TREE
1712 834 : && type != error_mark_node
1713 101884 : && !TYPE_REF_P (TREE_TYPE (decl)))
1714 : {
1715 272 : tree orig_type = TREE_TYPE (decl);
1716 272 : if (CLASS_TYPE_P (orig_type))
1717 : {
1718 128 : if (TYPE_POLYMORPHIC_P (orig_type))
1719 64 : warning_at (DECL_SOURCE_LOCATION (decl),
1720 : OPT_Wcatch_value_,
1721 : "catching polymorphic type %q#T by value",
1722 : orig_type);
1723 64 : else if (warn_catch_value > 1)
1724 48 : warning_at (DECL_SOURCE_LOCATION (decl),
1725 : OPT_Wcatch_value_,
1726 : "catching type %q#T by value", orig_type);
1727 : }
1728 144 : else if (warn_catch_value > 2)
1729 72 : warning_at (DECL_SOURCE_LOCATION (decl),
1730 : OPT_Wcatch_value_,
1731 : "catching non-reference type %q#T", orig_type);
1732 : }
1733 : }
1734 1328031 : HANDLER_TYPE (handler) = type;
1735 1328031 : }
1736 :
1737 : /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1738 : the return value from the matching call to finish_handler_parms. */
1739 :
1740 : void
1741 1328031 : finish_handler (tree handler)
1742 : {
1743 1328031 : if (!processing_template_decl)
1744 101050 : expand_end_catch_block ();
1745 1328031 : HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
1746 1328031 : }
1747 :
1748 : /* Begin a compound statement. FLAGS contains some bits that control the
1749 : behavior and context. If BCS_NO_SCOPE is set, the compound statement
1750 : does not define a scope. If BCS_FN_BODY is set, this is the outermost
1751 : block of a function. If BCS_TRY_BLOCK is set, this is the block
1752 : created on behalf of a TRY statement. Returns a token to be passed to
1753 : finish_compound_stmt. */
1754 :
1755 : tree
1756 143093905 : begin_compound_stmt (unsigned int flags)
1757 : {
1758 143093905 : tree r;
1759 :
1760 143093905 : if (flags & BCS_NO_SCOPE)
1761 : {
1762 1945551 : r = push_stmt_list ();
1763 1945551 : STATEMENT_LIST_NO_SCOPE (r) = 1;
1764 :
1765 : /* Normally, we try hard to keep the BLOCK for a statement-expression.
1766 : But, if it's a statement-expression with a scopeless block, there's
1767 : nothing to keep, and we don't want to accidentally keep a block
1768 : *inside* the scopeless block. */
1769 1945551 : keep_next_level (false);
1770 : }
1771 : else
1772 : {
1773 141148354 : scope_kind sk = sk_block;
1774 141148354 : if (flags & BCS_TRY_BLOCK)
1775 : sk = sk_try;
1776 140155869 : else if (flags & BCS_TRANSACTION)
1777 : sk = sk_transaction;
1778 140155572 : else if (flags & BCS_STMT_EXPR)
1779 29877 : sk = sk_stmt_expr;
1780 141148354 : r = do_pushlevel (sk);
1781 : }
1782 :
1783 : /* When processing a template, we need to remember where the braces were,
1784 : so that we can set up identical scopes when instantiating the template
1785 : later. BIND_EXPR is a handy candidate for this.
1786 : Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1787 : result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1788 : processing templates. */
1789 143093905 : if (processing_template_decl)
1790 : {
1791 98648501 : r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
1792 98648501 : BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
1793 98648501 : BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
1794 98648501 : TREE_SIDE_EFFECTS (r) = 1;
1795 : }
1796 :
1797 143093905 : return r;
1798 : }
1799 :
1800 : /* Finish a compound-statement, which is given by STMT. */
1801 :
1802 : void
1803 143093865 : finish_compound_stmt (tree stmt)
1804 : {
1805 143093865 : if (TREE_CODE (stmt) == BIND_EXPR)
1806 : {
1807 98648501 : tree body = do_poplevel (BIND_EXPR_BODY (stmt));
1808 : /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1809 : discard the BIND_EXPR so it can be merged with the containing
1810 : STATEMENT_LIST. */
1811 98648501 : if (TREE_CODE (body) == STATEMENT_LIST
1812 89718920 : && STATEMENT_LIST_HEAD (body) == NULL
1813 7093567 : && !BIND_EXPR_BODY_BLOCK (stmt)
1814 105430981 : && !BIND_EXPR_TRY_BLOCK (stmt))
1815 : stmt = body;
1816 : else
1817 91866139 : BIND_EXPR_BODY (stmt) = body;
1818 : }
1819 44445364 : else if (STATEMENT_LIST_NO_SCOPE (stmt))
1820 1945269 : stmt = pop_stmt_list (stmt);
1821 : else
1822 : {
1823 : /* Destroy any ObjC "super" receivers that may have been
1824 : created. */
1825 42500095 : objc_clear_super_receiver ();
1826 :
1827 42500095 : stmt = do_poplevel (stmt);
1828 : }
1829 :
1830 : /* ??? See c_end_compound_stmt wrt statement expressions. */
1831 143093865 : add_stmt (stmt);
1832 143093865 : }
1833 :
1834 : /* Finish an asm-statement, whose components are a STRING, some
1835 : OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1836 : LABELS. Also note whether the asm-statement should be
1837 : considered volatile, and whether it is asm inline. */
1838 :
1839 : tree
1840 31553 : finish_asm_stmt (location_t loc, int volatile_p, tree string,
1841 : tree output_operands, tree input_operands, tree clobbers,
1842 : tree labels, bool inline_p)
1843 : {
1844 31553 : tree r;
1845 31553 : tree t;
1846 31553 : int ninputs = list_length (input_operands);
1847 31553 : int noutputs = list_length (output_operands);
1848 :
1849 31553 : if (!processing_template_decl)
1850 : {
1851 26741 : const char *constraint;
1852 26741 : const char **oconstraints;
1853 26741 : bool allows_mem, allows_reg, is_inout;
1854 26741 : tree operand;
1855 26741 : int i;
1856 :
1857 26741 : oconstraints = XALLOCAVEC (const char *, noutputs);
1858 :
1859 26741 : string = resolve_asm_operand_names (string, output_operands,
1860 : input_operands, labels);
1861 :
1862 45423 : for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
1863 : {
1864 18682 : operand = TREE_VALUE (t);
1865 :
1866 : /* ??? Really, this should not be here. Users should be using a
1867 : proper lvalue, dammit. But there's a long history of using
1868 : casts in the output operands. In cases like longlong.h, this
1869 : becomes a primitive form of typechecking -- if the cast can be
1870 : removed, then the output operand had a type of the proper width;
1871 : otherwise we'll get an error. Gross, but ... */
1872 18682 : STRIP_NOPS (operand);
1873 :
1874 18682 : operand = mark_lvalue_use (operand);
1875 :
1876 18682 : if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
1877 0 : operand = error_mark_node;
1878 :
1879 18682 : if (operand != error_mark_node
1880 18682 : && (TREE_READONLY (operand)
1881 18674 : || CP_TYPE_CONST_P (TREE_TYPE (operand))
1882 : /* Functions are not modifiable, even though they are
1883 : lvalues. */
1884 18674 : || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand))
1885 : /* If it's an aggregate and any field is const, then it is
1886 : effectively const. */
1887 18674 : || (CLASS_TYPE_P (TREE_TYPE (operand))
1888 27 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
1889 8 : cxx_readonly_error (loc, operand, lv_asm);
1890 :
1891 : tree *op = &operand;
1892 18689 : while (TREE_CODE (*op) == COMPOUND_EXPR)
1893 7 : op = &TREE_OPERAND (*op, 1);
1894 18682 : switch (TREE_CODE (*op))
1895 : {
1896 33 : case PREINCREMENT_EXPR:
1897 33 : case PREDECREMENT_EXPR:
1898 33 : case MODIFY_EXPR:
1899 33 : *op = genericize_compound_lvalue (*op);
1900 33 : op = &TREE_OPERAND (*op, 1);
1901 33 : break;
1902 : default:
1903 : break;
1904 : }
1905 :
1906 18682 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
1907 18682 : oconstraints[i] = constraint;
1908 :
1909 18682 : if (parse_output_constraint (&constraint, i, ninputs, noutputs,
1910 : &allows_mem, &allows_reg, &is_inout))
1911 : {
1912 : /* If the operand is going to end up in memory,
1913 : mark it addressable. */
1914 18678 : if (!allows_reg && !cxx_mark_addressable (*op))
1915 0 : operand = error_mark_node;
1916 : }
1917 : else
1918 4 : operand = error_mark_node;
1919 :
1920 18682 : TREE_VALUE (t) = operand;
1921 : }
1922 :
1923 43377 : for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
1924 : {
1925 16636 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
1926 16636 : bool constraint_parsed
1927 16636 : = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
1928 : oconstraints, &allows_mem, &allows_reg);
1929 : /* If the operand is going to end up in memory, don't call
1930 : decay_conversion. */
1931 16636 : if (constraint_parsed && !allows_reg && allows_mem)
1932 2861 : operand = mark_lvalue_use (TREE_VALUE (t));
1933 : else
1934 13775 : operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error);
1935 :
1936 : /* If the type of the operand hasn't been determined (e.g.,
1937 : because it involves an overloaded function), then issue
1938 : an error message. There's no context available to
1939 : resolve the overloading. */
1940 16636 : if (TREE_TYPE (operand) == unknown_type_node)
1941 : {
1942 4 : error_at (loc,
1943 : "type of %<asm%> operand %qE could not be determined",
1944 4 : TREE_VALUE (t));
1945 4 : operand = error_mark_node;
1946 : }
1947 :
1948 16636 : if (constraint_parsed)
1949 : {
1950 : /* If the operand is going to end up in memory,
1951 : mark it addressable. */
1952 16636 : if (!allows_reg && allows_mem)
1953 : {
1954 : /* Strip the nops as we allow this case. FIXME, this really
1955 : should be rejected or made deprecated. */
1956 2861 : STRIP_NOPS (operand);
1957 :
1958 2861 : tree *op = &operand;
1959 2868 : while (TREE_CODE (*op) == COMPOUND_EXPR)
1960 7 : op = &TREE_OPERAND (*op, 1);
1961 2861 : switch (TREE_CODE (*op))
1962 : {
1963 29 : case PREINCREMENT_EXPR:
1964 29 : case PREDECREMENT_EXPR:
1965 29 : case MODIFY_EXPR:
1966 29 : *op = genericize_compound_lvalue (*op);
1967 29 : op = &TREE_OPERAND (*op, 1);
1968 29 : break;
1969 : default:
1970 : break;
1971 : }
1972 :
1973 2861 : if (!cxx_mark_addressable (*op))
1974 0 : operand = error_mark_node;
1975 : }
1976 13775 : else if (!allows_reg && !allows_mem)
1977 : {
1978 : /* If constraint allows neither register nor memory,
1979 : try harder to get a constant. */
1980 148 : tree constop = maybe_constant_value (operand);
1981 148 : if (TREE_CONSTANT (constop))
1982 144 : operand = constop;
1983 : }
1984 : }
1985 : else
1986 0 : operand = error_mark_node;
1987 :
1988 16636 : TREE_VALUE (t) = operand;
1989 : }
1990 : }
1991 :
1992 31553 : r = build_stmt (loc, ASM_EXPR, string,
1993 : output_operands, input_operands,
1994 : clobbers, labels);
1995 31553 : ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
1996 31553 : ASM_INLINE_P (r) = inline_p;
1997 31553 : r = maybe_cleanup_point_expr_void (r);
1998 31553 : return add_stmt (r);
1999 : }
2000 :
2001 : /* Finish a label with the indicated NAME. Returns the new label. */
2002 :
2003 : tree
2004 1812 : finish_label_stmt (tree name)
2005 : {
2006 1812 : tree decl = define_label (input_location, name);
2007 :
2008 1812 : if (decl == error_mark_node)
2009 : return error_mark_node;
2010 :
2011 1804 : add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
2012 :
2013 1804 : return decl;
2014 : }
2015 :
2016 : /* Finish a series of declarations for local labels. G++ allows users
2017 : to declare "local" labels, i.e., labels with scope. This extension
2018 : is useful when writing code involving statement-expressions. */
2019 :
2020 : void
2021 104 : finish_label_decl (tree name)
2022 : {
2023 104 : if (!at_function_scope_p ())
2024 : {
2025 0 : error ("%<__label__%> declarations are only allowed in function scopes");
2026 0 : return;
2027 : }
2028 :
2029 104 : add_decl_expr (declare_local_label (name));
2030 : }
2031 :
2032 : /* When DECL goes out of scope, make sure that CLEANUP is executed. */
2033 :
2034 : void
2035 1948948 : finish_decl_cleanup (tree decl, tree cleanup)
2036 : {
2037 1948948 : push_cleanup (decl, cleanup, false);
2038 1948948 : }
2039 :
2040 : /* If the current scope exits with an exception, run CLEANUP. */
2041 :
2042 : void
2043 1466395 : finish_eh_cleanup (tree cleanup)
2044 : {
2045 1466395 : push_cleanup (NULL, cleanup, true);
2046 1466395 : }
2047 :
2048 : /* The MEM_INITS is a list of mem-initializers, in reverse of the
2049 : order they were written by the user. Each node is as for
2050 : emit_mem_initializers. */
2051 :
2052 : void
2053 11911215 : finish_mem_initializers (tree mem_inits)
2054 : {
2055 : /* Reorder the MEM_INITS so that they are in the order they appeared
2056 : in the source program. */
2057 11911215 : mem_inits = nreverse (mem_inits);
2058 :
2059 11911215 : if (processing_template_decl)
2060 : {
2061 : tree mem;
2062 :
2063 21039561 : for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
2064 : {
2065 : /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
2066 : check for bare parameter packs in the TREE_VALUE, because
2067 : any parameter packs in the TREE_VALUE have already been
2068 : bound as part of the TREE_PURPOSE. See
2069 : make_pack_expansion for more information. */
2070 12472495 : if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
2071 12472495 : && check_for_bare_parameter_packs (TREE_VALUE (mem)))
2072 3 : TREE_VALUE (mem) = error_mark_node;
2073 : }
2074 :
2075 8567066 : add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
2076 : CTOR_INITIALIZER, mem_inits));
2077 : }
2078 : else
2079 3344149 : emit_mem_initializers (mem_inits);
2080 11911215 : }
2081 :
2082 : /* Obfuscate EXPR if it looks like an id-expression or member access so
2083 : that the call to finish_decltype in do_auto_deduction will give the
2084 : right result. If EVEN_UNEVAL, do this even in unevaluated context. */
2085 :
2086 : tree
2087 19969786 : force_paren_expr (tree expr, bool even_uneval /* = false */)
2088 : {
2089 : /* This is only needed for decltype(auto) in C++14. */
2090 19969786 : if (cxx_dialect < cxx14)
2091 : return expr;
2092 :
2093 : /* If we're in unevaluated context, we can't be deducing a
2094 : return/initializer type, so we don't need to mess with this. */
2095 19413968 : if (cp_unevaluated_operand && !even_uneval)
2096 : return expr;
2097 :
2098 18577975 : if (TREE_CODE (expr) == COMPONENT_REF
2099 18577975 : || TREE_CODE (expr) == SCOPE_REF
2100 18577975 : || REFERENCE_REF_P (expr))
2101 76176 : REF_PARENTHESIZED_P (expr) = true;
2102 18501799 : else if (DECL_P (tree_strip_any_location_wrapper (expr)))
2103 : {
2104 1391865 : location_t loc = cp_expr_location (expr);
2105 1391865 : const tree_code code = processing_template_decl ? PAREN_EXPR
2106 : : VIEW_CONVERT_EXPR;
2107 1391865 : expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
2108 1391865 : REF_PARENTHESIZED_P (expr) = true;
2109 : }
2110 : return expr;
2111 : }
2112 :
2113 : /* If T is an id-expression obfuscated by force_paren_expr, undo the
2114 : obfuscation and return the underlying id-expression. Otherwise
2115 : return T. */
2116 :
2117 : tree
2118 338924958 : maybe_undo_parenthesized_ref (tree t)
2119 : {
2120 338924958 : if (cxx_dialect < cxx14)
2121 : return t;
2122 :
2123 331736415 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
2124 331736415 : && REF_PARENTHESIZED_P (t))
2125 166410 : t = TREE_OPERAND (t, 0);
2126 :
2127 : return t;
2128 : }
2129 :
2130 : /* Finish a parenthesized expression EXPR. */
2131 :
2132 : cp_expr
2133 19525530 : finish_parenthesized_expr (cp_expr expr)
2134 : {
2135 19525530 : if (EXPR_P (expr))
2136 : /* This inhibits warnings in c_common_truthvalue_conversion. */
2137 19454917 : suppress_warning (expr, OPT_Wparentheses);
2138 :
2139 19525530 : if (TREE_CODE (expr) == OFFSET_REF
2140 19525530 : || TREE_CODE (expr) == SCOPE_REF)
2141 : /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
2142 : enclosed in parentheses. */
2143 13893 : PTRMEM_OK_P (expr) = 0;
2144 :
2145 19525530 : tree stripped_expr = tree_strip_any_location_wrapper (expr);
2146 19525530 : if (TREE_CODE (stripped_expr) == STRING_CST)
2147 616690 : PAREN_STRING_LITERAL_P (stripped_expr) = 1;
2148 :
2149 19525530 : expr = cp_expr (force_paren_expr (expr), expr.get_location ());
2150 :
2151 19525530 : return expr;
2152 : }
2153 :
2154 : /* Finish a reference to a non-static data member (DECL) that is not
2155 : preceded by `.' or `->'. */
2156 :
2157 : tree
2158 37971260 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
2159 : tsubst_flags_t complain /* = tf_warning_or_error */)
2160 : {
2161 37971260 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
2162 37971260 : bool try_omp_private = !object && omp_private_member_map;
2163 35247587 : tree ret;
2164 :
2165 35247587 : if (!object)
2166 : {
2167 35247587 : tree scope = qualifying_scope;
2168 35247587 : if (scope == NULL_TREE)
2169 : {
2170 35227885 : scope = context_for_name_lookup (decl);
2171 35227885 : if (!TYPE_P (scope))
2172 : {
2173 : /* Can happen during error recovery (c++/85014). */
2174 3 : gcc_assert (seen_error ());
2175 3 : return error_mark_node;
2176 : }
2177 : }
2178 35247584 : object = maybe_dummy_object (scope, NULL);
2179 : }
2180 :
2181 37971257 : object = maybe_resolve_dummy (object, true);
2182 37971257 : if (object == error_mark_node)
2183 : return error_mark_node;
2184 :
2185 : /* DR 613/850: Can use non-static data members without an associated
2186 : object in sizeof/decltype/alignof. */
2187 37971254 : if (is_dummy_object (object)
2188 22458 : && !cp_unevaluated_operand
2189 37971379 : && (!processing_template_decl || !current_class_ref))
2190 : {
2191 105 : if (complain & tf_error)
2192 : {
2193 92 : if (current_function_decl
2194 92 : && DECL_STATIC_FUNCTION_P (current_function_decl))
2195 4 : error ("invalid use of member %qD in static member function", decl);
2196 88 : else if (current_function_decl
2197 81 : && processing_contract_condition
2198 92 : && DECL_CONSTRUCTOR_P (current_function_decl))
2199 1 : error ("invalid use of member %qD in constructor %<pre%> contract", decl);
2200 87 : else if (current_function_decl
2201 80 : && processing_contract_condition
2202 89 : && DECL_DESTRUCTOR_P (current_function_decl))
2203 1 : error ("invalid use of member %qD in destructor %<post%> contract", decl);
2204 : else
2205 86 : error ("invalid use of non-static data member %qD", decl);
2206 92 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
2207 : }
2208 :
2209 105 : return error_mark_node;
2210 : }
2211 :
2212 37971149 : if (current_class_ptr)
2213 37946855 : TREE_USED (current_class_ptr) = 1;
2214 37971149 : if (processing_template_decl)
2215 : {
2216 31716330 : tree type = TREE_TYPE (decl);
2217 :
2218 31716330 : if (TYPE_REF_P (type))
2219 : /* Quals on the object don't matter. */;
2220 30503604 : else if (PACK_EXPANSION_P (type))
2221 : /* Don't bother trying to represent this. */
2222 : type = NULL_TREE;
2223 : else
2224 : {
2225 : /* Set the cv qualifiers. */
2226 30503551 : int quals = cp_type_quals (TREE_TYPE (object));
2227 :
2228 30503551 : if (DECL_MUTABLE_P (decl))
2229 187245 : quals &= ~TYPE_QUAL_CONST;
2230 :
2231 30503551 : quals |= cp_type_quals (TREE_TYPE (decl));
2232 30503551 : type = cp_build_qualified_type (type, quals);
2233 : }
2234 :
2235 31716330 : if (qualifying_scope)
2236 : /* Wrap this in a SCOPE_REF for now. */
2237 8161 : ret = build_qualified_name (type, qualifying_scope, decl,
2238 : /*template_p=*/false);
2239 : else
2240 31708169 : ret = (convert_from_reference
2241 31708169 : (build_min (COMPONENT_REF, type, object, decl, NULL_TREE)));
2242 : }
2243 : /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
2244 : QUALIFYING_SCOPE is also non-null. */
2245 : else
2246 : {
2247 6254819 : tree access_type = TREE_TYPE (object);
2248 :
2249 6254819 : if (!perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
2250 : decl, complain))
2251 0 : return error_mark_node;
2252 :
2253 : /* If the data member was named `C::M', convert `*this' to `C'
2254 : first. */
2255 6254819 : if (qualifying_scope)
2256 : {
2257 11497 : tree binfo = NULL_TREE;
2258 11497 : object = build_scoped_ref (object, qualifying_scope,
2259 : &binfo);
2260 : }
2261 :
2262 6254819 : ret = build_class_member_access_expr (object, decl,
2263 : /*access_path=*/NULL_TREE,
2264 : /*preserve_reference=*/false,
2265 : complain);
2266 : }
2267 37971149 : if (try_omp_private)
2268 : {
2269 1614 : tree *v = omp_private_member_map->get (decl);
2270 1614 : if (v)
2271 1159 : ret = convert_from_reference (*v);
2272 : }
2273 : return ret;
2274 : }
2275 :
2276 : /* DECL was the declaration to which a qualified-id resolved. Issue
2277 : an error message if it is not accessible. If OBJECT_TYPE is
2278 : non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2279 : type of `*x', or `x', respectively. If the DECL was named as
2280 : `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like
2281 : perform_access_checks above. */
2282 :
2283 : bool
2284 2523420472 : check_accessibility_of_qualified_id (tree decl,
2285 : tree object_type,
2286 : tree nested_name_specifier,
2287 : tsubst_flags_t complain)
2288 : {
2289 : /* If we're not checking, return immediately. */
2290 2523420472 : if (deferred_access_no_check)
2291 : return true;
2292 :
2293 : /* Determine the SCOPE of DECL. */
2294 2517850311 : tree scope = context_for_name_lookup (decl);
2295 : /* If the SCOPE is not a type, then DECL is not a member. */
2296 2517850311 : if (!TYPE_P (scope)
2297 : /* If SCOPE is dependent then we can't perform this access check now,
2298 : and since we'll perform this access check again after substitution
2299 : there's no need to explicitly defer it. */
2300 2517850311 : || dependent_type_p (scope))
2301 2345957371 : return true;
2302 :
2303 171892940 : tree qualifying_type = NULL_TREE;
2304 : /* Compute the scope through which DECL is being accessed. */
2305 171892940 : if (object_type
2306 : /* OBJECT_TYPE might not be a class type; consider:
2307 :
2308 : class A { typedef int I; };
2309 : I *p;
2310 : p->A::I::~I();
2311 :
2312 : In this case, we will have "A::I" as the DECL, but "I" as the
2313 : OBJECT_TYPE. */
2314 52700 : && CLASS_TYPE_P (object_type)
2315 171945617 : && DERIVED_FROM_P (scope, object_type))
2316 : /* If we are processing a `->' or `.' expression, use the type of the
2317 : left-hand side. */
2318 : qualifying_type = object_type;
2319 171840275 : else if (nested_name_specifier)
2320 : {
2321 : /* If the reference is to a non-static member of the
2322 : current class, treat it as if it were referenced through
2323 : `this'. */
2324 193889540 : if (DECL_NONSTATIC_MEMBER_P (decl)
2325 96997666 : && current_class_ptr)
2326 39292 : if (tree current = current_nonlambda_class_type ())
2327 : {
2328 39269 : if (dependent_type_p (current))
2329 : /* In general we can't know whether this access goes through
2330 : `this' until instantiation time. Punt now, or else we might
2331 : create a deferred access check that's not relative to `this'
2332 : when it ought to be. We'll check this access again after
2333 : substitution, e.g. from tsubst_qualified_id. */
2334 : return true;
2335 :
2336 5629 : if (DERIVED_FROM_P (scope, current))
2337 : qualifying_type = current;
2338 : }
2339 : /* Otherwise, use the type indicated by the
2340 : nested-name-specifier. */
2341 : if (!qualifying_type)
2342 : qualifying_type = nested_name_specifier;
2343 : }
2344 : else
2345 : /* Otherwise, the name must be from the current class or one of
2346 : its bases. */
2347 74895503 : qualifying_type = currently_open_derived_class (scope);
2348 :
2349 171853845 : if (qualifying_type
2350 : /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2351 : or similar in a default argument value. */
2352 171859300 : && CLASS_TYPE_P (qualifying_type))
2353 167968971 : return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2354 167968971 : decl, complain);
2355 :
2356 : return true;
2357 : }
2358 :
2359 : /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2360 : class named to the left of the "::" operator. DONE is true if this
2361 : expression is a complete postfix-expression; it is false if this
2362 : expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2363 : iff this expression is the operand of '&'. TEMPLATE_P is true iff
2364 : the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2365 : is true iff this qualified name appears as a template argument. */
2366 :
2367 : tree
2368 42586546 : finish_qualified_id_expr (tree qualifying_class,
2369 : tree expr,
2370 : bool done,
2371 : bool address_p,
2372 : bool template_p,
2373 : bool template_arg_p,
2374 : tsubst_flags_t complain)
2375 : {
2376 42586546 : gcc_assert (TYPE_P (qualifying_class));
2377 :
2378 42586546 : if (error_operand_p (expr))
2379 10 : return error_mark_node;
2380 :
2381 42586536 : if (DECL_P (expr)
2382 : /* Functions are marked after overload resolution; avoid redundant
2383 : warnings. */
2384 34662326 : && TREE_CODE (expr) != FUNCTION_DECL
2385 77248835 : && !mark_used (expr, complain))
2386 0 : return error_mark_node;
2387 :
2388 42586536 : if (template_p)
2389 : {
2390 3812058 : if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE)
2391 : {
2392 : /* cp_parser_lookup_name thought we were looking for a type,
2393 : but we're actually looking for a declaration. */
2394 11 : qualifying_class = TYPE_CONTEXT (expr);
2395 11 : expr = TYPE_IDENTIFIER (expr);
2396 : }
2397 : else
2398 3812047 : check_template_keyword (expr);
2399 : }
2400 :
2401 : /* If EXPR occurs as the operand of '&', use special handling that
2402 : permits a pointer-to-member. */
2403 42586536 : if (address_p && done
2404 116178 : && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
2405 : {
2406 116175 : if (TREE_CODE (expr) == SCOPE_REF)
2407 0 : expr = TREE_OPERAND (expr, 1);
2408 116175 : expr = build_offset_ref (qualifying_class, expr,
2409 : /*address_p=*/true, complain);
2410 116175 : return expr;
2411 : }
2412 :
2413 : /* No need to check access within an enum. */
2414 42470361 : if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
2415 927944 : && TREE_CODE (expr) != IDENTIFIER_NODE)
2416 : return expr;
2417 :
2418 : /* Within the scope of a class, turn references to non-static
2419 : members into expression of the form "this->...". */
2420 41542420 : if (template_arg_p)
2421 : /* But, within a template argument, we do not want make the
2422 : transformation, as there is no "this" pointer. */
2423 : ;
2424 41538332 : else if (TREE_CODE (expr) == FIELD_DECL)
2425 : {
2426 19702 : push_deferring_access_checks (dk_no_check);
2427 19702 : expr = finish_non_static_data_member (expr, NULL_TREE,
2428 : qualifying_class, complain);
2429 19702 : pop_deferring_access_checks ();
2430 : }
2431 41518630 : else if (BASELINK_P (expr))
2432 : {
2433 : /* See if any of the functions are non-static members. */
2434 : /* If so, the expression may be relative to 'this'. */
2435 7608068 : if (!shared_member_p (expr)
2436 98814 : && current_class_ptr
2437 7706422 : && DERIVED_FROM_P (qualifying_class,
2438 : current_nonlambda_class_type ()))
2439 98217 : expr = (build_class_member_access_expr
2440 98217 : (maybe_dummy_object (qualifying_class, NULL),
2441 : expr,
2442 98217 : BASELINK_ACCESS_BINFO (expr),
2443 : /*preserve_reference=*/false,
2444 : complain));
2445 7509851 : else if (done)
2446 : /* The expression is a qualified name whose address is not
2447 : being taken. */
2448 355 : expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
2449 : complain);
2450 : }
2451 33910562 : else if (!template_p
2452 33703013 : && TREE_CODE (expr) == TEMPLATE_DECL
2453 33910617 : && !DECL_FUNCTION_TEMPLATE_P (expr))
2454 : {
2455 55 : if (complain & tf_error)
2456 3 : error ("%qE missing template arguments", expr);
2457 55 : return error_mark_node;
2458 : }
2459 : else
2460 : {
2461 : /* In a template, return a SCOPE_REF for most qualified-ids
2462 : so that we can check access at instantiation time. But if
2463 : we're looking at a member of the current instantiation, we
2464 : know we have access and building up the SCOPE_REF confuses
2465 : non-type template argument handling. */
2466 33910507 : if (processing_template_decl
2467 33910507 : && (!currently_open_class (qualifying_class)
2468 227 : || TREE_CODE (expr) == IDENTIFIER_NODE
2469 227 : || TREE_CODE (expr) == TEMPLATE_ID_EXPR
2470 90 : || TREE_CODE (expr) == BIT_NOT_EXPR))
2471 7162462 : expr = build_qualified_name (TREE_TYPE (expr),
2472 : qualifying_class, expr,
2473 : template_p);
2474 26748045 : else if (tree wrap = maybe_get_tls_wrapper_call (expr))
2475 51 : expr = wrap;
2476 :
2477 33910507 : expr = convert_from_reference (expr);
2478 : }
2479 :
2480 : return expr;
2481 : }
2482 :
2483 : /* Begin a statement-expression. The value returned must be passed to
2484 : finish_stmt_expr. */
2485 :
2486 : tree
2487 1969518 : begin_stmt_expr (void)
2488 : {
2489 1969518 : return push_stmt_list ();
2490 : }
2491 :
2492 : /* Process the final expression of a statement expression. EXPR can be
2493 : NULL, if the final expression is empty. Return a STATEMENT_LIST
2494 : containing all the statements in the statement-expression, or
2495 : ERROR_MARK_NODE if there was an error. */
2496 :
2497 : tree
2498 20556 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
2499 : {
2500 20556 : if (error_operand_p (expr))
2501 : {
2502 : /* The type of the statement-expression is the type of the last
2503 : expression. */
2504 4 : TREE_TYPE (stmt_expr) = error_mark_node;
2505 4 : return error_mark_node;
2506 : }
2507 :
2508 : /* If the last statement does not have "void" type, then the value
2509 : of the last statement is the value of the entire expression. */
2510 20552 : if (expr)
2511 : {
2512 20532 : tree type = TREE_TYPE (expr);
2513 :
2514 20532 : if (type && type_unknown_p (type))
2515 : {
2516 20 : error ("a statement expression is an insufficient context"
2517 : " for overload resolution");
2518 20 : TREE_TYPE (stmt_expr) = error_mark_node;
2519 20 : return error_mark_node;
2520 : }
2521 20512 : else if (processing_template_decl)
2522 : {
2523 167 : expr = build_stmt (input_location, EXPR_STMT, expr);
2524 167 : expr = add_stmt (expr);
2525 : /* Mark the last statement so that we can recognize it as such at
2526 : template-instantiation time. */
2527 167 : EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
2528 : }
2529 20345 : else if (VOID_TYPE_P (type))
2530 : {
2531 : /* Just treat this like an ordinary statement. */
2532 32 : expr = finish_expr_stmt (expr);
2533 : }
2534 : else
2535 : {
2536 : /* It actually has a value we need to deal with. First, force it
2537 : to be an rvalue so that we won't need to build up a copy
2538 : constructor call later when we try to assign it to something. */
2539 20313 : expr = force_rvalue (expr, tf_warning_or_error);
2540 20313 : if (error_operand_p (expr))
2541 0 : return error_mark_node;
2542 :
2543 : /* Update for array-to-pointer decay. */
2544 20313 : type = TREE_TYPE (expr);
2545 :
2546 : /* This TARGET_EXPR will initialize the outer one added by
2547 : finish_stmt_expr. */
2548 20313 : set_target_expr_eliding (expr);
2549 :
2550 : /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2551 : normal statement, but don't convert to void or actually add
2552 : the EXPR_STMT. */
2553 20313 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
2554 20313 : expr = maybe_cleanup_point_expr (expr);
2555 20313 : add_stmt (expr);
2556 : }
2557 :
2558 : /* The type of the statement-expression is the type of the last
2559 : expression. */
2560 20512 : TREE_TYPE (stmt_expr) = type;
2561 : }
2562 :
2563 : return stmt_expr;
2564 : }
2565 :
2566 : /* Finish a statement-expression. EXPR should be the value returned
2567 : by the previous begin_stmt_expr. Returns an expression
2568 : representing the statement-expression. */
2569 :
2570 : tree
2571 1969518 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
2572 : {
2573 1969518 : tree type;
2574 1969518 : tree result;
2575 :
2576 1969518 : if (error_operand_p (stmt_expr))
2577 : {
2578 24 : pop_stmt_list (stmt_expr);
2579 24 : return error_mark_node;
2580 : }
2581 :
2582 1969494 : gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
2583 :
2584 1969494 : type = TREE_TYPE (stmt_expr);
2585 1969494 : result = pop_stmt_list (stmt_expr);
2586 1969494 : TREE_TYPE (result) = type;
2587 :
2588 1969494 : if (processing_template_decl)
2589 : {
2590 478 : result = build_min (STMT_EXPR, type, result);
2591 478 : TREE_SIDE_EFFECTS (result) = 1;
2592 478 : STMT_EXPR_NO_SCOPE (result) = has_no_scope;
2593 : }
2594 1969016 : else if (CLASS_TYPE_P (type))
2595 : {
2596 : /* Wrap the statement-expression in a TARGET_EXPR so that the
2597 : temporary object created by the final expression is destroyed at
2598 : the end of the full-expression containing the
2599 : statement-expression. */
2600 86 : result = force_target_expr (type, result, tf_warning_or_error);
2601 : }
2602 :
2603 : return result;
2604 : }
2605 :
2606 : /* Returns the expression which provides the value of STMT_EXPR. */
2607 :
2608 : tree
2609 472 : stmt_expr_value_expr (tree stmt_expr)
2610 : {
2611 472 : tree t = STMT_EXPR_STMT (stmt_expr);
2612 :
2613 472 : if (TREE_CODE (t) == BIND_EXPR)
2614 472 : t = BIND_EXPR_BODY (t);
2615 :
2616 472 : if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
2617 380 : t = STATEMENT_LIST_TAIL (t)->stmt;
2618 :
2619 472 : if (TREE_CODE (t) == EXPR_STMT)
2620 423 : t = EXPR_STMT_EXPR (t);
2621 :
2622 472 : return t;
2623 : }
2624 :
2625 : /* Return TRUE iff EXPR_STMT is an empty list of
2626 : expression statements. */
2627 :
2628 : bool
2629 27454068 : empty_expr_stmt_p (tree expr_stmt)
2630 : {
2631 27454073 : tree body = NULL_TREE;
2632 :
2633 27454073 : if (expr_stmt == void_node)
2634 : return true;
2635 :
2636 27454069 : if (expr_stmt)
2637 : {
2638 27454069 : if (TREE_CODE (expr_stmt) == EXPR_STMT)
2639 5 : body = EXPR_STMT_EXPR (expr_stmt);
2640 27454064 : else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
2641 : body = expr_stmt;
2642 : }
2643 :
2644 5 : if (body)
2645 : {
2646 27149262 : if (TREE_CODE (body) == STATEMENT_LIST)
2647 27149257 : return tsi_end_p (tsi_start (body));
2648 : else
2649 : return empty_expr_stmt_p (body);
2650 : }
2651 : return false;
2652 : }
2653 :
2654 : /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
2655 : the function (or functions) to call; ARGS are the arguments to the
2656 : call. Returns the functions to be considered by overload resolution. */
2657 :
2658 : cp_expr
2659 10307663 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
2660 : tsubst_flags_t complain)
2661 : {
2662 10307663 : tree identifier = NULL_TREE;
2663 10307663 : tree functions = NULL_TREE;
2664 10307663 : tree tmpl_args = NULL_TREE;
2665 10307663 : bool template_id = false;
2666 10307663 : location_t loc = fn_expr.get_location ();
2667 10307663 : tree fn = fn_expr.get_value ();
2668 :
2669 10307663 : STRIP_ANY_LOCATION_WRAPPER (fn);
2670 :
2671 10307663 : if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
2672 : {
2673 : /* Use a separate flag to handle null args. */
2674 1035777 : template_id = true;
2675 1035777 : tmpl_args = TREE_OPERAND (fn, 1);
2676 1035777 : fn = TREE_OPERAND (fn, 0);
2677 : }
2678 :
2679 : /* Find the name of the overloaded function. */
2680 10307663 : if (identifier_p (fn))
2681 : identifier = fn;
2682 : else
2683 : {
2684 14211926 : functions = fn;
2685 10268677 : identifier = OVL_NAME (functions);
2686 : }
2687 :
2688 : /* A call to a namespace-scope function using an unqualified name.
2689 :
2690 : Do Koenig lookup -- unless any of the arguments are
2691 : type-dependent. */
2692 10307663 : if (!any_type_dependent_arguments_p (args)
2693 10307663 : && !any_dependent_template_arguments_p (tmpl_args))
2694 : {
2695 9734096 : fn = lookup_arg_dependent (identifier, functions, args);
2696 9734096 : if (!fn)
2697 : {
2698 : /* The unqualified name could not be resolved. */
2699 14901 : if (complain & tf_error)
2700 456 : fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
2701 : else
2702 : fn = identifier;
2703 : }
2704 : }
2705 :
2706 10307663 : if (fn && template_id && fn != error_mark_node)
2707 1035770 : fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
2708 :
2709 10307663 : return cp_expr (fn, loc);
2710 : }
2711 :
2712 : /* Generate an expression for `FN (ARGS)'. This may change the
2713 : contents of ARGS.
2714 :
2715 : If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2716 : as a virtual call, even if FN is virtual. (This flag is set when
2717 : encountering an expression where the function name is explicitly
2718 : qualified. For example a call to `X::f' never generates a virtual
2719 : call.)
2720 :
2721 : Returns code for the call. */
2722 :
2723 : tree
2724 105515625 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
2725 : bool koenig_p, tsubst_flags_t complain)
2726 : {
2727 105515625 : tree result;
2728 105515625 : tree orig_fn;
2729 105515625 : vec<tree, va_gc> *orig_args = *args;
2730 :
2731 105515625 : if (fn == error_mark_node)
2732 : return error_mark_node;
2733 :
2734 105514100 : gcc_assert (!TYPE_P (fn));
2735 :
2736 : /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2737 : it so that we can tell this is a call to a known function. */
2738 105514100 : fn = maybe_undo_parenthesized_ref (fn);
2739 :
2740 105514100 : STRIP_ANY_LOCATION_WRAPPER (fn);
2741 :
2742 105514100 : orig_fn = fn;
2743 :
2744 105514100 : if (processing_template_decl)
2745 : {
2746 : /* If FN is a local extern declaration (or set thereof) in a template,
2747 : look it up again at instantiation time. */
2748 68023798 : if (is_overloaded_fn (fn))
2749 : {
2750 52121013 : tree ifn = get_first_fn (fn);
2751 52121013 : if (TREE_CODE (ifn) == FUNCTION_DECL
2752 52121013 : && dependent_local_decl_p (ifn))
2753 8644 : orig_fn = DECL_NAME (ifn);
2754 : }
2755 :
2756 : /* If the call expression is dependent, build a CALL_EXPR node
2757 : with no type; type_dependent_expression_p recognizes
2758 : expressions with no type as being dependent. */
2759 68023798 : if (type_dependent_expression_p (fn)
2760 68023798 : || any_type_dependent_arguments_p (*args))
2761 : {
2762 57793043 : result = build_min_nt_call_vec (orig_fn, *args);
2763 95620387 : SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
2764 57793043 : KOENIG_LOOKUP_P (result) = koenig_p;
2765 : /* Disable the std::move warnings since this call was dependent
2766 : (c++/89780, c++/107363). This also suppresses the
2767 : -Wredundant-move warning. */
2768 57793043 : suppress_warning (result, OPT_Wpessimizing_move);
2769 57793043 : if (is_overloaded_fn (fn))
2770 41958662 : fn = get_fns (fn);
2771 :
2772 57793043 : if (cfun)
2773 : {
2774 43230105 : bool abnormal = true;
2775 129690627 : for (lkp_iterator iter (fn); abnormal && iter; ++iter)
2776 : {
2777 43230417 : tree fndecl = STRIP_TEMPLATE (*iter);
2778 43230417 : if (TREE_CODE (fndecl) != FUNCTION_DECL
2779 43230417 : || !TREE_THIS_VOLATILE (fndecl))
2780 43161005 : abnormal = false;
2781 : }
2782 : /* FIXME: Stop warning about falling off end of non-void
2783 : function. But this is wrong. Even if we only see
2784 : no-return fns at this point, we could select a
2785 : future-defined return fn during instantiation. Or
2786 : vice-versa. */
2787 43230105 : if (abnormal)
2788 69100 : current_function_returns_abnormally = 1;
2789 : }
2790 57793043 : return result;
2791 : }
2792 10230755 : orig_args = make_tree_vector_copy (*args);
2793 10230755 : if (!BASELINK_P (fn)
2794 10230755 : && TREE_CODE (fn) != PSEUDO_DTOR_EXPR
2795 10230755 : && TREE_TYPE (fn) != unknown_type_node)
2796 5475350 : fn = build_non_dependent_expr (fn);
2797 10230755 : make_args_non_dependent (*args);
2798 : }
2799 :
2800 47721057 : if (TREE_CODE (fn) == COMPONENT_REF)
2801 : {
2802 210963 : tree member = TREE_OPERAND (fn, 1);
2803 210963 : if (BASELINK_P (member))
2804 : {
2805 115741 : tree object = TREE_OPERAND (fn, 0);
2806 231482 : return build_new_method_call (object, member,
2807 : args, NULL_TREE,
2808 : (disallow_virtual
2809 : ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
2810 : : LOOKUP_NORMAL),
2811 : /*fn_p=*/NULL,
2812 115741 : complain);
2813 : }
2814 : }
2815 :
2816 : /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2817 47605316 : if (TREE_CODE (fn) == ADDR_EXPR
2818 47605316 : && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
2819 12 : fn = TREE_OPERAND (fn, 0);
2820 :
2821 47605316 : if (is_overloaded_fn (fn))
2822 46681885 : fn = baselink_for_fns (fn);
2823 :
2824 47605316 : result = NULL_TREE;
2825 47605316 : if (BASELINK_P (fn))
2826 : {
2827 11460636 : tree object;
2828 :
2829 : /* A call to a member function. From [over.call.func]:
2830 :
2831 : If the keyword this is in scope and refers to the class of
2832 : that member function, or a derived class thereof, then the
2833 : function call is transformed into a qualified function call
2834 : using (*this) as the postfix-expression to the left of the
2835 : . operator.... [Otherwise] a contrived object of type T
2836 : becomes the implied object argument.
2837 :
2838 : In this situation:
2839 :
2840 : struct A { void f(); };
2841 : struct B : public A {};
2842 : struct C : public A { void g() { B::f(); }};
2843 :
2844 : "the class of that member function" refers to `A'. But 11.2
2845 : [class.access.base] says that we need to convert 'this' to B* as
2846 : part of the access, so we pass 'B' to maybe_dummy_object. */
2847 :
2848 11460636 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
2849 : {
2850 : /* A constructor call always uses a dummy object. (This constructor
2851 : call which has the form A::A () is actually invalid and we are
2852 : going to reject it later in build_new_method_call.) */
2853 63 : object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
2854 : }
2855 : else
2856 11460573 : object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
2857 : NULL);
2858 :
2859 12387772 : result = build_new_method_call (object, fn, args, NULL_TREE,
2860 : (disallow_virtual
2861 : ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
2862 : : LOOKUP_NORMAL),
2863 : /*fn_p=*/NULL,
2864 : complain);
2865 : }
2866 36144680 : else if (concept_check_p (fn))
2867 : {
2868 : /* FN is actually a template-id referring to a concept definition. */
2869 110 : tree id = unpack_concept_check (fn);
2870 110 : tree tmpl = TREE_OPERAND (id, 0);
2871 110 : tree args = TREE_OPERAND (id, 1);
2872 :
2873 110 : if (!function_concept_p (tmpl))
2874 : {
2875 1 : error_at (EXPR_LOC_OR_LOC (fn, input_location),
2876 : "cannot call a concept as a function");
2877 1 : return error_mark_node;
2878 : }
2879 :
2880 : /* Ensure the result is wrapped as a call expression. */
2881 109 : result = build_concept_check (tmpl, args, tf_warning_or_error);
2882 : }
2883 36144570 : else if (is_overloaded_fn (fn))
2884 : {
2885 : /* If the function is an overloaded builtin, resolve it. */
2886 35221140 : if (TREE_CODE (fn) == FUNCTION_DECL
2887 35221140 : && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
2888 11375509 : || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
2889 7312678 : result = resolve_overloaded_builtin (input_location, fn, *args);
2890 :
2891 7312678 : if (!result)
2892 : {
2893 35078839 : if (warn_sizeof_pointer_memaccess
2894 1306783 : && (complain & tf_warning)
2895 1253347 : && !vec_safe_is_empty (*args)
2896 36068473 : && !processing_template_decl)
2897 : {
2898 : location_t sizeof_arg_loc[3];
2899 : tree sizeof_arg[3];
2900 : unsigned int i;
2901 3546876 : for (i = 0; i < 3; i++)
2902 : {
2903 2660157 : tree t;
2904 :
2905 2660157 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
2906 2660157 : sizeof_arg[i] = NULL_TREE;
2907 2660157 : if (i >= (*args)->length ())
2908 534413 : continue;
2909 2125744 : t = (**args)[i];
2910 2125744 : if (TREE_CODE (t) != SIZEOF_EXPR)
2911 2119430 : continue;
2912 6314 : if (SIZEOF_EXPR_TYPE_P (t))
2913 2228 : sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
2914 : else
2915 4086 : sizeof_arg[i] = TREE_OPERAND (t, 0);
2916 6314 : sizeof_arg_loc[i] = EXPR_LOCATION (t);
2917 : }
2918 886719 : sizeof_pointer_memaccess_warning
2919 886719 : (sizeof_arg_loc, fn, *args,
2920 : sizeof_arg, same_type_ignoring_top_level_qualifiers_p);
2921 : }
2922 :
2923 35078839 : if ((complain & tf_warning)
2924 27953694 : && TREE_CODE (fn) == FUNCTION_DECL
2925 15182988 : && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
2926 66613 : && vec_safe_length (*args) == 3
2927 35145452 : && !any_type_dependent_arguments_p (*args))
2928 : {
2929 66613 : tree arg0 = (*orig_args)[0];
2930 66613 : tree arg1 = (*orig_args)[1];
2931 66613 : tree arg2 = (*orig_args)[2];
2932 66613 : int literal_mask = ((literal_integer_zerop (arg1) << 1)
2933 66613 : | (literal_integer_zerop (arg2) << 2));
2934 66613 : warn_for_memset (input_location, arg0, arg2, literal_mask);
2935 : }
2936 :
2937 : /* A call to a namespace-scope function. */
2938 35078839 : result = build_new_function_call (fn, args, complain);
2939 : }
2940 : }
2941 923430 : else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
2942 : {
2943 10293 : if (!vec_safe_is_empty (*args))
2944 0 : error ("arguments to destructor are not allowed");
2945 : /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
2946 : which case the postfix-expression is a possibly-parenthesized class
2947 : member access), the function call destroys the object of scalar type
2948 : denoted by the object expression of the class member access. */
2949 10293 : tree ob = TREE_OPERAND (fn, 0);
2950 10293 : if (obvalue_p (ob))
2951 10273 : result = build_trivial_dtor_call (ob, true);
2952 : else
2953 : /* No location to clobber. */
2954 20 : result = convert_to_void (ob, ICV_STATEMENT, complain);
2955 : }
2956 913137 : else if (CLASS_TYPE_P (TREE_TYPE (fn)))
2957 : /* If the "function" is really an object of class type, it might
2958 : have an overloaded `operator ()'. */
2959 413281 : result = build_op_call (fn, args, complain);
2960 :
2961 46951441 : if (!result)
2962 : /* A call where the function is unknown. */
2963 499856 : result = cp_build_function_call_vec (fn, args, complain);
2964 :
2965 47593598 : if (processing_template_decl && result != error_mark_node)
2966 : {
2967 10172721 : if (INDIRECT_REF_P (result))
2968 701557 : result = TREE_OPERAND (result, 0);
2969 :
2970 : /* Prune all but the selected function from the original overload
2971 : set so that we can avoid some duplicate work at instantiation time. */
2972 10172721 : if (TREE_CODE (result) == CALL_EXPR
2973 10165130 : && really_overloaded_fn (orig_fn))
2974 : {
2975 3823583 : tree sel_fn = CALL_EXPR_FN (result);
2976 3823583 : if (TREE_CODE (sel_fn) == COMPONENT_REF)
2977 : {
2978 : /* The non-dependent result of build_new_method_call. */
2979 2083086 : sel_fn = TREE_OPERAND (sel_fn, 1);
2980 2083086 : gcc_assert (BASELINK_P (sel_fn));
2981 : }
2982 1740497 : else if (TREE_CODE (sel_fn) == ADDR_EXPR)
2983 : /* Our original callee wasn't wrapped in an ADDR_EXPR,
2984 : so strip this ADDR_EXPR added by build_over_call. */
2985 1740406 : sel_fn = TREE_OPERAND (sel_fn, 0);
2986 : orig_fn = sel_fn;
2987 : }
2988 :
2989 10172721 : result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
2990 10172721 : SET_EXPR_LOCATION (result, input_location);
2991 10172721 : KOENIG_LOOKUP_P (result) = koenig_p;
2992 10172721 : release_tree_vector (orig_args);
2993 10172721 : result = convert_from_reference (result);
2994 : }
2995 :
2996 : return result;
2997 : }
2998 :
2999 : /* Finish a call to a postfix increment or decrement or EXPR. (Which
3000 : is indicated by CODE, which should be POSTINCREMENT_EXPR or
3001 : POSTDECREMENT_EXPR.) */
3002 :
3003 : cp_expr
3004 1545515 : finish_increment_expr (cp_expr expr, enum tree_code code)
3005 : {
3006 : /* input_location holds the location of the trailing operator token.
3007 : Build a location of the form:
3008 : expr++
3009 : ~~~~^~
3010 : with the caret at the operator token, ranging from the start
3011 : of EXPR to the end of the operator token. */
3012 1545515 : location_t combined_loc = make_location (input_location,
3013 : expr.get_start (),
3014 : get_finish (input_location));
3015 1545515 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3016 1545515 : NULL_TREE, tf_warning_or_error);
3017 : /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3018 1545515 : result.set_location (combined_loc);
3019 1545515 : return result;
3020 : }
3021 :
3022 : /* Finish a use of `this'. Returns an expression for `this'. */
3023 :
3024 : tree
3025 20552287 : finish_this_expr (void)
3026 : {
3027 20552287 : tree result = NULL_TREE;
3028 :
3029 20552287 : if (current_class_ptr)
3030 : {
3031 20552256 : tree type = TREE_TYPE (current_class_ref);
3032 :
3033 : /* In a lambda expression, 'this' refers to the captured 'this'. */
3034 41104488 : if (LAMBDA_TYPE_P (type))
3035 125373 : result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type), true);
3036 : else
3037 20426883 : result = current_class_ptr;
3038 : }
3039 :
3040 20552256 : if (result)
3041 : /* The keyword 'this' is a prvalue expression. */
3042 20552253 : return rvalue (result);
3043 :
3044 34 : tree fn = current_nonlambda_function ();
3045 34 : if (fn && DECL_STATIC_FUNCTION_P (fn))
3046 4 : error ("%<this%> is unavailable for static member functions");
3047 30 : else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
3048 0 : error ("invalid use of %<this%> before it is valid");
3049 30 : else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
3050 0 : error ("invalid use of %<this%> after it is valid");
3051 30 : else if (fn)
3052 10 : error ("invalid use of %<this%> in non-member function");
3053 : else
3054 20 : error ("invalid use of %<this%> at top level");
3055 34 : return error_mark_node;
3056 : }
3057 :
3058 : /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3059 : expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3060 : the TYPE for the type given. If SCOPE is non-NULL, the expression
3061 : was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3062 :
3063 : tree
3064 10356 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
3065 : location_t loc)
3066 : {
3067 10356 : if (object == error_mark_node || destructor == error_mark_node)
3068 : return error_mark_node;
3069 :
3070 10345 : gcc_assert (TYPE_P (destructor));
3071 :
3072 10345 : if (!processing_template_decl)
3073 : {
3074 10317 : if (scope == error_mark_node)
3075 : {
3076 0 : error_at (loc, "invalid qualifying scope in pseudo-destructor name");
3077 0 : return error_mark_node;
3078 : }
3079 10317 : if (is_auto (destructor))
3080 3 : destructor = TREE_TYPE (object);
3081 10317 : if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
3082 : {
3083 4 : error_at (loc,
3084 : "qualified type %qT does not match destructor name ~%qT",
3085 : scope, destructor);
3086 4 : return error_mark_node;
3087 : }
3088 :
3089 :
3090 : /* [expr.pseudo] says both:
3091 :
3092 : The type designated by the pseudo-destructor-name shall be
3093 : the same as the object type.
3094 :
3095 : and:
3096 :
3097 : The cv-unqualified versions of the object type and of the
3098 : type designated by the pseudo-destructor-name shall be the
3099 : same type.
3100 :
3101 : We implement the more generous second sentence, since that is
3102 : what most other compilers do. */
3103 10313 : if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
3104 : destructor))
3105 : {
3106 12 : error_at (loc, "%qE is not of type %qT", object, destructor);
3107 12 : return error_mark_node;
3108 : }
3109 : }
3110 :
3111 10329 : tree type = (type_dependent_expression_p (object)
3112 10329 : ? NULL_TREE : void_type_node);
3113 :
3114 10329 : return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
3115 10329 : scope, destructor);
3116 : }
3117 :
3118 : /* Finish an expression of the form CODE EXPR. */
3119 :
3120 : cp_expr
3121 19828672 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
3122 : tsubst_flags_t complain)
3123 : {
3124 : /* Build a location of the form:
3125 : ++expr
3126 : ^~~~~~
3127 : with the caret at the operator token, ranging from the start
3128 : of the operator token to the end of EXPR. */
3129 19828672 : location_t combined_loc = make_location (op_loc,
3130 : op_loc, expr.get_finish ());
3131 19828672 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3132 19828672 : NULL_TREE, complain);
3133 : /* TODO: build_x_unary_op doesn't always honor the location. */
3134 19828672 : result.set_location (combined_loc);
3135 :
3136 19828672 : if (result == error_mark_node)
3137 262 : return result;
3138 :
3139 19828410 : if (!(complain & tf_warning))
3140 0 : return result;
3141 :
3142 19828410 : tree result_ovl = result;
3143 19828410 : tree expr_ovl = expr;
3144 :
3145 19828410 : if (!processing_template_decl)
3146 1804312 : expr_ovl = cp_fully_fold (expr_ovl);
3147 :
3148 19828410 : if (!CONSTANT_CLASS_P (expr_ovl)
3149 19828410 : || TREE_OVERFLOW_P (expr_ovl))
3150 19673720 : return result;
3151 :
3152 154690 : if (!processing_template_decl)
3153 147465 : result_ovl = cp_fully_fold (result_ovl);
3154 :
3155 154690 : if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
3156 10 : overflow_warning (combined_loc, result_ovl);
3157 :
3158 154690 : return result;
3159 : }
3160 :
3161 : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3162 : elements. */
3163 :
3164 : static bool
3165 12 : maybe_zero_constructor_nelts (tree expr)
3166 : {
3167 12 : if (CONSTRUCTOR_NELTS (expr) == 0)
3168 : return true;
3169 12 : if (!processing_template_decl)
3170 : return false;
3171 30 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
3172 21 : if (!PACK_EXPANSION_P (elt.value))
3173 : return false;
3174 : return true;
3175 : }
3176 :
3177 : /* Finish a compound-literal expression or C++11 functional cast with aggregate
3178 : initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3179 : is being cast. */
3180 :
3181 : tree
3182 3939711 : finish_compound_literal (tree type, tree compound_literal,
3183 : tsubst_flags_t complain,
3184 : fcl_t fcl_context)
3185 : {
3186 3939711 : if (type == error_mark_node)
3187 : return error_mark_node;
3188 :
3189 3939700 : if (TYPE_REF_P (type))
3190 : {
3191 9 : compound_literal
3192 9 : = finish_compound_literal (TREE_TYPE (type), compound_literal,
3193 : complain, fcl_context);
3194 : /* The prvalue is then used to direct-initialize the reference. */
3195 9 : tree r = (perform_implicit_conversion_flags
3196 9 : (type, compound_literal, complain, LOOKUP_NORMAL));
3197 9 : return convert_from_reference (r);
3198 : }
3199 :
3200 3939691 : if (!TYPE_OBJ_P (type))
3201 : {
3202 : /* DR2351 */
3203 61 : if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
3204 : {
3205 12 : if (!processing_template_decl)
3206 9 : return void_node;
3207 3 : TREE_TYPE (compound_literal) = type;
3208 3 : TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
3209 3 : CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
3210 3 : return compound_literal;
3211 : }
3212 22 : else if (VOID_TYPE_P (type)
3213 15 : && processing_template_decl
3214 34 : && maybe_zero_constructor_nelts (compound_literal))
3215 : /* If there are only packs in compound_literal, it could
3216 : be void{} after pack expansion. */;
3217 : else
3218 : {
3219 13 : if (complain & tf_error)
3220 10 : error ("compound literal of non-object type %qT", type);
3221 13 : return error_mark_node;
3222 : }
3223 : }
3224 :
3225 3939666 : if (template_placeholder_p (type))
3226 : {
3227 4819 : type = do_auto_deduction (type, compound_literal, type, complain,
3228 : adc_variable_type);
3229 4819 : if (type == error_mark_node)
3230 : return error_mark_node;
3231 : }
3232 : /* C++23 auto{x}. */
3233 3934847 : else if (is_auto (type)
3234 91 : && !AUTO_IS_DECLTYPE (type)
3235 3934936 : && CONSTRUCTOR_NELTS (compound_literal) == 1)
3236 : {
3237 85 : if (is_constrained_auto (type))
3238 : {
3239 2 : if (complain & tf_error)
3240 2 : error ("%<auto{x}%> cannot be constrained");
3241 2 : return error_mark_node;
3242 : }
3243 83 : else if (cxx_dialect < cxx23)
3244 1 : pedwarn (input_location, OPT_Wc__23_extensions,
3245 : "%<auto{x}%> only available with "
3246 : "%<-std=c++2b%> or %<-std=gnu++2b%>");
3247 83 : type = do_auto_deduction (type, compound_literal, type, complain,
3248 : adc_variable_type);
3249 83 : if (type == error_mark_node)
3250 : return error_mark_node;
3251 : }
3252 :
3253 : /* Used to hold a copy of the compound literal in a template. */
3254 3939613 : tree orig_cl = NULL_TREE;
3255 :
3256 3939613 : if (processing_template_decl)
3257 : {
3258 1872259 : const bool dependent_p
3259 1872259 : = (instantiation_dependent_expression_p (compound_literal)
3260 1872259 : || dependent_type_p (type));
3261 267356 : if (dependent_p)
3262 : /* We're about to return, no need to copy. */
3263 : orig_cl = compound_literal;
3264 : else
3265 : /* We're going to need a copy. */
3266 267356 : orig_cl = unshare_constructor (compound_literal);
3267 1872259 : TREE_TYPE (orig_cl) = type;
3268 : /* Mark the expression as a compound literal. */
3269 1872259 : TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
3270 : /* And as instantiation-dependent. */
3271 1872259 : CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
3272 1872259 : if (fcl_context == fcl_c99)
3273 48 : CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
3274 : /* If the compound literal is dependent, we're done for now. */
3275 1872259 : if (dependent_p)
3276 : return orig_cl;
3277 : /* Otherwise, do go on to e.g. check narrowing. */
3278 : }
3279 :
3280 2334710 : type = complete_type (type);
3281 :
3282 2334710 : if (TYPE_NON_AGGREGATE_CLASS (type))
3283 : {
3284 : /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3285 : everywhere that deals with function arguments would be a pain, so
3286 : just wrap it in a TREE_LIST. The parser set a flag so we know
3287 : that it came from T{} rather than T({}). */
3288 257015 : CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
3289 257015 : compound_literal = build_tree_list (NULL_TREE, compound_literal);
3290 257015 : return build_functional_cast (input_location, type,
3291 257015 : compound_literal, complain);
3292 : }
3293 :
3294 2077695 : if (TREE_CODE (type) == ARRAY_TYPE
3295 2077695 : && check_array_initializer (NULL_TREE, type, compound_literal))
3296 12 : return error_mark_node;
3297 2077683 : compound_literal = reshape_init (type, compound_literal, complain);
3298 1978795 : if (SCALAR_TYPE_P (type)
3299 189598 : && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
3300 2080469 : && !check_narrowing (type, compound_literal, complain))
3301 44 : return error_mark_node;
3302 2077639 : if (TREE_CODE (type) == ARRAY_TYPE
3303 2077639 : && TYPE_DOMAIN (type) == NULL_TREE)
3304 : {
3305 319 : cp_complete_array_type_or_error (&type, compound_literal,
3306 : false, complain);
3307 319 : if (type == error_mark_node)
3308 : return error_mark_node;
3309 : }
3310 2077636 : compound_literal = digest_init_flags (type, compound_literal,
3311 : LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
3312 : complain);
3313 2077636 : if (compound_literal == error_mark_node)
3314 : return error_mark_node;
3315 :
3316 : /* If we're in a template, return the original compound literal. */
3317 2077194 : if (orig_cl)
3318 : return orig_cl;
3319 :
3320 1839563 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3321 : {
3322 1675462 : TREE_HAS_CONSTRUCTOR (compound_literal) = true;
3323 1675462 : if (fcl_context == fcl_c99)
3324 30085 : CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
3325 : }
3326 :
3327 : /* Put static/constant array temporaries in static variables. */
3328 : /* FIXME all C99 compound literals should be variables rather than C++
3329 : temporaries, unless they are used as an aggregate initializer. */
3330 2264823 : if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
3331 1416673 : && fcl_context == fcl_c99
3332 98 : && TREE_CODE (type) == ARRAY_TYPE
3333 37 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
3334 1839600 : && initializer_constant_valid_p (compound_literal, type))
3335 : {
3336 37 : tree decl = create_temporary_var (type);
3337 37 : DECL_CONTEXT (decl) = NULL_TREE;
3338 37 : DECL_INITIAL (decl) = compound_literal;
3339 37 : TREE_STATIC (decl) = 1;
3340 37 : if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
3341 : {
3342 : /* 5.19 says that a constant expression can include an
3343 : lvalue-rvalue conversion applied to "a glvalue of literal type
3344 : that refers to a non-volatile temporary object initialized
3345 : with a constant expression". Rather than try to communicate
3346 : that this VAR_DECL is a temporary, just mark it constexpr. */
3347 32 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
3348 32 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
3349 32 : TREE_CONSTANT (decl) = true;
3350 : }
3351 37 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
3352 37 : decl = pushdecl_top_level (decl);
3353 37 : DECL_NAME (decl) = make_anon_name ();
3354 37 : SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
3355 : /* Make sure the destructor is callable. */
3356 37 : tree clean = cxx_maybe_build_cleanup (decl, complain);
3357 37 : if (clean == error_mark_node)
3358 : return error_mark_node;
3359 37 : return decl;
3360 : }
3361 :
3362 : /* Represent other compound literals with TARGET_EXPR so we produce
3363 : a prvalue, and can elide copies. */
3364 1839526 : if (!VECTOR_TYPE_P (type)
3365 1809819 : && (TREE_CODE (compound_literal) == CONSTRUCTOR
3366 164093 : || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
3367 : {
3368 : /* The CONSTRUCTOR is now an initializer, not a compound literal. */
3369 1645726 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3370 1645726 : TREE_HAS_CONSTRUCTOR (compound_literal) = false;
3371 1645726 : compound_literal = get_target_expr (compound_literal, complain);
3372 : }
3373 : else
3374 : /* For e.g. int{42} just make sure it's a prvalue. */
3375 193800 : compound_literal = rvalue (compound_literal);
3376 :
3377 : return compound_literal;
3378 : }
3379 :
3380 : /* Return the declaration for the function-name variable indicated by
3381 : ID. */
3382 :
3383 : tree
3384 98723 : finish_fname (tree id)
3385 : {
3386 98723 : tree decl;
3387 :
3388 98723 : decl = fname_decl (input_location, C_RID_CODE (id), id);
3389 98723 : if (processing_template_decl && current_function_decl
3390 53520 : && decl != error_mark_node)
3391 53520 : decl = DECL_NAME (decl);
3392 98723 : return decl;
3393 : }
3394 :
3395 : /* Finish a translation unit. */
3396 :
3397 : void
3398 88402 : finish_translation_unit (void)
3399 : {
3400 : /* In case there were missing closebraces,
3401 : get us back to the global binding level. */
3402 88402 : pop_everything ();
3403 176804 : while (current_namespace != global_namespace)
3404 0 : pop_namespace ();
3405 :
3406 : /* Do file scope __FUNCTION__ et al. */
3407 88402 : finish_fname_decls ();
3408 :
3409 88402 : if (vec_safe_length (scope_chain->omp_declare_target_attribute))
3410 : {
3411 16 : cp_omp_declare_target_attr
3412 16 : a = scope_chain->omp_declare_target_attribute->pop ();
3413 16 : if (!errorcount)
3414 12 : error ("%qs without corresponding %qs",
3415 : a.device_type >= 0 ? "#pragma omp begin declare target"
3416 : : "#pragma omp declare target",
3417 : "#pragma omp end declare target");
3418 32 : vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
3419 : }
3420 88402 : if (vec_safe_length (scope_chain->omp_begin_assumes))
3421 : {
3422 4 : if (!errorcount)
3423 4 : error ("%qs without corresponding %qs",
3424 : "#pragma omp begin assumes", "#pragma omp end assumes");
3425 4 : vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
3426 : }
3427 88402 : }
3428 :
3429 : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
3430 : Returns the parameter. */
3431 :
3432 : tree
3433 97156829 : finish_template_type_parm (tree aggr, tree identifier)
3434 : {
3435 97156829 : if (aggr != class_type_node)
3436 : {
3437 0 : permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
3438 0 : aggr = class_type_node;
3439 : }
3440 :
3441 97156829 : return build_tree_list (aggr, identifier);
3442 : }
3443 :
3444 : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
3445 : Returns the parameter. */
3446 :
3447 : tree
3448 219086 : finish_template_template_parm (tree aggr, tree identifier)
3449 : {
3450 219086 : tree decl = build_decl (input_location,
3451 : TYPE_DECL, identifier, NULL_TREE);
3452 :
3453 219086 : tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
3454 219086 : DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
3455 219086 : DECL_TEMPLATE_RESULT (tmpl) = decl;
3456 219086 : DECL_ARTIFICIAL (decl) = 1;
3457 :
3458 : /* Associate the constraints with the underlying declaration,
3459 : not the template. */
3460 219086 : tree constr = current_template_constraints ();
3461 219086 : set_constraints (decl, constr);
3462 :
3463 219086 : end_template_decl ();
3464 :
3465 219086 : gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
3466 :
3467 219086 : check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
3468 : /*is_primary=*/true, /*is_partial=*/false,
3469 : /*is_friend=*/0);
3470 :
3471 219086 : return finish_template_type_parm (aggr, tmpl);
3472 : }
3473 :
3474 : /* ARGUMENT is the default-argument value for a template template
3475 : parameter. If ARGUMENT is invalid, issue error messages and return
3476 : the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
3477 :
3478 : tree
3479 845 : check_template_template_default_arg (tree argument)
3480 : {
3481 845 : if (TREE_CODE (argument) != TEMPLATE_DECL
3482 845 : && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
3483 32 : && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
3484 : {
3485 24 : if (TREE_CODE (argument) == TYPE_DECL)
3486 : {
3487 24 : if (tree t = maybe_get_template_decl_from_type_decl (argument))
3488 24 : if (TREE_CODE (t) == TEMPLATE_DECL)
3489 : return t;
3490 20 : error ("invalid use of type %qT as a default value for a template "
3491 20 : "template-parameter", TREE_TYPE (argument));
3492 : }
3493 : else
3494 0 : error ("invalid default argument for a template template parameter");
3495 20 : return error_mark_node;
3496 : }
3497 :
3498 : return argument;
3499 : }
3500 :
3501 : /* Begin a class definition, as indicated by T. */
3502 :
3503 : tree
3504 17932266 : begin_class_definition (tree t)
3505 : {
3506 17932266 : if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
3507 46 : return error_mark_node;
3508 :
3509 17932248 : if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
3510 : {
3511 12 : error ("definition of %q#T inside template parameter list", t);
3512 12 : return error_mark_node;
3513 : }
3514 :
3515 : /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
3516 : are passed the same as decimal scalar types. */
3517 17932208 : if (TREE_CODE (t) == RECORD_TYPE
3518 17615168 : && !processing_template_decl)
3519 : {
3520 5684147 : tree ns = TYPE_CONTEXT (t);
3521 5684147 : if (ns && TREE_CODE (ns) == NAMESPACE_DECL
3522 4624696 : && DECL_CONTEXT (ns) == std_node
3523 335751 : && DECL_NAME (ns)
3524 6019879 : && id_equal (DECL_NAME (ns), "decimal"))
3525 : {
3526 166 : const char *n = TYPE_NAME_STRING (t);
3527 166 : if ((strcmp (n, "decimal32") == 0)
3528 112 : || (strcmp (n, "decimal64") == 0)
3529 50 : || (strcmp (n, "decimal128") == 0))
3530 162 : TYPE_TRANSPARENT_AGGR (t) = 1;
3531 : }
3532 : }
3533 :
3534 : /* A non-implicit typename comes from code like:
3535 :
3536 : template <typename T> struct A {
3537 : template <typename U> struct A<T>::B ...
3538 :
3539 : This is erroneous. */
3540 12248061 : else if (TREE_CODE (t) == TYPENAME_TYPE)
3541 : {
3542 0 : error ("invalid definition of qualified type %qT", t);
3543 0 : t = error_mark_node;
3544 : }
3545 :
3546 35864416 : if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
3547 : {
3548 0 : t = make_class_type (RECORD_TYPE);
3549 0 : pushtag (make_anon_name (), t);
3550 : }
3551 :
3552 17932208 : if (TYPE_BEING_DEFINED (t))
3553 : {
3554 0 : t = make_class_type (TREE_CODE (t));
3555 0 : pushtag (TYPE_IDENTIFIER (t), t);
3556 : }
3557 :
3558 17932208 : if (modules_p ())
3559 : {
3560 130576 : if (!module_may_redeclare (TYPE_NAME (t)))
3561 : {
3562 0 : error ("cannot declare %qD in a different module", TYPE_NAME (t));
3563 0 : inform (DECL_SOURCE_LOCATION (TYPE_NAME (t)), "declared here");
3564 0 : return error_mark_node;
3565 : }
3566 130576 : set_instantiating_module (TYPE_NAME (t));
3567 130576 : set_defining_module (TYPE_NAME (t));
3568 : }
3569 :
3570 17932208 : maybe_process_partial_specialization (t);
3571 17932208 : pushclass (t);
3572 17932208 : TYPE_BEING_DEFINED (t) = 1;
3573 17932208 : class_binding_level->defining_class_p = 1;
3574 :
3575 17932208 : if (flag_pack_struct)
3576 : {
3577 93 : tree v;
3578 93 : TYPE_PACKED (t) = 1;
3579 : /* Even though the type is being defined for the first time
3580 : here, there might have been a forward declaration, so there
3581 : might be cv-qualified variants of T. */
3582 93 : for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
3583 0 : TYPE_PACKED (v) = 1;
3584 : }
3585 : /* Reset the interface data, at the earliest possible
3586 : moment, as it might have been set via a class foo;
3587 : before. */
3588 36604914 : if (! TYPE_UNNAMED_P (t))
3589 : {
3590 17440107 : struct c_fileinfo *finfo = \
3591 17440107 : get_fileinfo (LOCATION_FILE (input_location));
3592 17440107 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
3593 17440107 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X
3594 : (t, finfo->interface_unknown);
3595 : }
3596 17932208 : reset_specialization ();
3597 :
3598 : /* Make a declaration for this class in its own scope. */
3599 17932208 : build_self_reference ();
3600 :
3601 17932208 : return t;
3602 : }
3603 :
3604 : /* Finish the member declaration given by DECL. */
3605 :
3606 : void
3607 224452558 : finish_member_declaration (tree decl)
3608 : {
3609 224452558 : if (decl == error_mark_node || decl == NULL_TREE)
3610 : return;
3611 :
3612 224451513 : if (decl == void_type_node)
3613 : /* The COMPONENT was a friend, not a member, and so there's
3614 : nothing for us to do. */
3615 : return;
3616 :
3617 : /* We should see only one DECL at a time. */
3618 224451513 : gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
3619 :
3620 : /* Don't add decls after definition. */
3621 224451528 : gcc_assert (TYPE_BEING_DEFINED (current_class_type)
3622 : /* We can add lambda types when late parsing default
3623 : arguments. */
3624 : || LAMBDA_TYPE_P (TREE_TYPE (decl)));
3625 :
3626 : /* Set up access control for DECL. */
3627 224451513 : TREE_PRIVATE (decl)
3628 224451513 : = (current_access_specifier == access_private_node);
3629 224451513 : TREE_PROTECTED (decl)
3630 224451513 : = (current_access_specifier == access_protected_node);
3631 224451513 : if (TREE_CODE (decl) == TEMPLATE_DECL)
3632 : {
3633 25607377 : TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
3634 25607377 : TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
3635 : }
3636 :
3637 : /* Mark the DECL as a member of the current class, unless it's
3638 : a member of an enumeration. */
3639 224451513 : if (TREE_CODE (decl) != CONST_DECL)
3640 223071814 : DECL_CONTEXT (decl) = current_class_type;
3641 :
3642 : /* Remember the single FIELD_DECL an anonymous aggregate type is used for. */
3643 224451513 : if (TREE_CODE (decl) == FIELD_DECL
3644 224451513 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
3645 : {
3646 93164 : gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
3647 93164 : ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))) = decl;
3648 : }
3649 :
3650 224451513 : if (TREE_CODE (decl) == USING_DECL)
3651 : /* Avoid debug info for class-scope USING_DECLS for now, we'll
3652 : call cp_emit_debug_info_for_using later. */
3653 1509232 : DECL_IGNORED_P (decl) = 1;
3654 :
3655 : /* Check for bare parameter packs in the non-static data member
3656 : declaration. */
3657 224451513 : if (TREE_CODE (decl) == FIELD_DECL)
3658 : {
3659 15250108 : if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
3660 9 : TREE_TYPE (decl) = error_mark_node;
3661 15250108 : if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
3662 0 : DECL_ATTRIBUTES (decl) = NULL_TREE;
3663 : }
3664 :
3665 : /* [dcl.link]
3666 :
3667 : A C language linkage is ignored for the names of class members
3668 : and the member function type of class member functions. */
3669 224451513 : if (DECL_LANG_SPECIFIC (decl))
3670 205659561 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
3671 :
3672 224451513 : bool add = false;
3673 :
3674 : /* Functions and non-functions are added differently. */
3675 224451513 : if (DECL_DECLARES_FUNCTION_P (decl))
3676 118275166 : add = add_method (current_class_type, decl, false);
3677 : /* Enter the DECL into the scope of the class, if the class
3678 : isn't a closure (whose fields are supposed to be unnamed). */
3679 106176347 : else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
3680 105584779 : || maybe_push_used_methods (decl)
3681 210813255 : || pushdecl_class_level (decl))
3682 : add = true;
3683 :
3684 118275166 : if (add)
3685 : {
3686 : /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3687 : go at the beginning. The reason is that
3688 : legacy_nonfn_member_lookup searches the list in order, and we
3689 : want a field name to override a type name so that the "struct
3690 : stat hack" will work. In particular:
3691 :
3692 : struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3693 :
3694 : is valid. */
3695 :
3696 224450317 : if (TREE_CODE (decl) == TYPE_DECL)
3697 76748877 : TYPE_FIELDS (current_class_type)
3698 153497754 : = chainon (TYPE_FIELDS (current_class_type), decl);
3699 : else
3700 : {
3701 147701440 : DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
3702 147701440 : TYPE_FIELDS (current_class_type) = decl;
3703 : }
3704 :
3705 224450317 : maybe_add_class_template_decl_list (current_class_type, decl,
3706 : /*friend_p=*/0);
3707 : }
3708 : }
3709 :
3710 : /* Finish processing a complete template declaration. The PARMS are
3711 : the template parameters. */
3712 :
3713 : void
3714 55000407 : finish_template_decl (tree parms)
3715 : {
3716 55000407 : if (parms)
3717 55000399 : end_template_decl ();
3718 : else
3719 8 : end_specialization ();
3720 55000407 : }
3721 :
3722 : // Returns the template type of the class scope being entered. If we're
3723 : // entering a constrained class scope. TYPE is the class template
3724 : // scope being entered and we may need to match the intended type with
3725 : // a constrained specialization. For example:
3726 : //
3727 : // template<Object T>
3728 : // struct S { void f(); }; #1
3729 : //
3730 : // template<Object T>
3731 : // void S<T>::f() { } #2
3732 : //
3733 : // We check, in #2, that S<T> refers precisely to the type declared by
3734 : // #1 (i.e., that the constraints match). Note that the following should
3735 : // be an error since there is no specialization of S<T> that is
3736 : // unconstrained, but this is not diagnosed here.
3737 : //
3738 : // template<typename T>
3739 : // void S<T>::f() { }
3740 : //
3741 : // We cannot diagnose this problem here since this function also matches
3742 : // qualified template names that are not part of a definition. For example:
3743 : //
3744 : // template<Integral T, Floating_point U>
3745 : // typename pair<T, U>::first_type void f(T, U);
3746 : //
3747 : // Here, it is unlikely that there is a partial specialization of
3748 : // pair constrained for for Integral and Floating_point arguments.
3749 : //
3750 : // The general rule is: if a constrained specialization with matching
3751 : // constraints is found return that type. Also note that if TYPE is not a
3752 : // class-type (e.g. a typename type), then no fixup is needed.
3753 :
3754 : static tree
3755 552140 : fixup_template_type (tree type)
3756 : {
3757 : // Find the template parameter list at the a depth appropriate to
3758 : // the scope we're trying to enter.
3759 552140 : tree parms = current_template_parms;
3760 552140 : int depth = template_class_depth (type);
3761 1173300 : for (int n = current_template_depth; n > depth && parms; --n)
3762 69020 : parms = TREE_CHAIN (parms);
3763 552140 : if (!parms)
3764 : return type;
3765 552137 : tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
3766 552137 : tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
3767 :
3768 : // Search for a specialization whose type and constraints match.
3769 552137 : tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
3770 552137 : tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
3771 837630 : while (specs)
3772 : {
3773 291729 : tree spec_constr = get_constraints (TREE_VALUE (specs));
3774 :
3775 : // If the type and constraints match a specialization, then we
3776 : // are entering that type.
3777 291729 : if (same_type_p (type, TREE_TYPE (specs))
3778 291729 : && equivalent_constraints (cur_constr, spec_constr))
3779 6236 : return TREE_TYPE (specs);
3780 285493 : specs = TREE_CHAIN (specs);
3781 : }
3782 :
3783 : // If no specialization matches, then must return the type
3784 : // previously found.
3785 : return type;
3786 : }
3787 :
3788 : /* Finish processing a template-id (which names a type) of the form
3789 : NAME < ARGS >. Return the TYPE_DECL for the type named by the
3790 : template-id. If ENTERING_SCOPE is nonzero we are about to enter
3791 : the scope of template-id indicated. */
3792 :
3793 : tree
3794 110911326 : finish_template_type (tree name, tree args, int entering_scope)
3795 : {
3796 110911326 : tree type;
3797 :
3798 110911326 : type = lookup_template_class (name, args,
3799 : NULL_TREE, NULL_TREE, entering_scope,
3800 : tf_warning_or_error | tf_user);
3801 :
3802 : /* If we might be entering the scope of a partial specialization,
3803 : find the one with the right constraints. */
3804 110911323 : if (flag_concepts
3805 5998211 : && entering_scope
3806 573257 : && CLASS_TYPE_P (type)
3807 564243 : && CLASSTYPE_TEMPLATE_INFO (type)
3808 564239 : && dependent_type_p (type)
3809 111463463 : && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
3810 552140 : type = fixup_template_type (type);
3811 :
3812 110911323 : if (type == error_mark_node)
3813 : return type;
3814 110910551 : else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
3815 97360596 : return TYPE_STUB_DECL (type);
3816 : else
3817 13549955 : return TYPE_NAME (type);
3818 : }
3819 :
3820 : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3821 : Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3822 : BASE_CLASS, or NULL_TREE if an error occurred. The
3823 : ACCESS_SPECIFIER is one of
3824 : access_{default,public,protected_private}_node. For a virtual base
3825 : we set TREE_TYPE. */
3826 :
3827 : tree
3828 8035880 : finish_base_specifier (tree base, tree access, bool virtual_p)
3829 : {
3830 8035880 : tree result;
3831 :
3832 8035880 : if (base == error_mark_node)
3833 : {
3834 0 : error ("invalid base-class specification");
3835 0 : result = NULL_TREE;
3836 : }
3837 15184424 : else if (! MAYBE_CLASS_TYPE_P (base))
3838 : {
3839 3 : error ("%qT is not a class type", base);
3840 3 : result = NULL_TREE;
3841 : }
3842 : else
3843 : {
3844 8035877 : if (cp_type_quals (base) != 0)
3845 : {
3846 : /* DR 484: Can a base-specifier name a cv-qualified
3847 : class type? */
3848 16 : base = TYPE_MAIN_VARIANT (base);
3849 : }
3850 8035877 : result = build_tree_list (access, base);
3851 8035877 : if (virtual_p)
3852 20602 : TREE_TYPE (result) = integer_type_node;
3853 : }
3854 :
3855 8035880 : return result;
3856 : }
3857 :
3858 : /* If FNS is a member function, a set of member functions, or a
3859 : template-id referring to one or more member functions, return a
3860 : BASELINK for FNS, incorporating the current access context.
3861 : Otherwise, return FNS unchanged. */
3862 :
3863 : tree
3864 73031083 : baselink_for_fns (tree fns)
3865 : {
3866 73031083 : tree scope;
3867 73031083 : tree cl;
3868 :
3869 73031083 : if (BASELINK_P (fns)
3870 73031083 : || error_operand_p (fns))
3871 : return fns;
3872 :
3873 61570491 : scope = ovl_scope (fns);
3874 61570491 : if (!CLASS_TYPE_P (scope))
3875 : return fns;
3876 :
3877 3791557 : cl = currently_open_derived_class (scope);
3878 3791557 : if (!cl)
3879 2562944 : cl = scope;
3880 3791557 : tree access_path = TYPE_BINFO (cl);
3881 3791557 : tree conv_path = (cl == scope ? access_path
3882 546396 : : lookup_base (cl, scope, ba_any, NULL, tf_none));
3883 3791557 : return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
3884 : }
3885 :
3886 : /* Returns true iff DECL is a variable from a function outside
3887 : the current one. */
3888 :
3889 : static bool
3890 1233372097 : outer_var_p (tree decl)
3891 : {
3892 1233372097 : return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
3893 1116513372 : && DECL_FUNCTION_SCOPE_P (decl)
3894 : /* Don't get confused by temporaries. */
3895 952694279 : && DECL_NAME (decl)
3896 2180029069 : && (DECL_CONTEXT (decl) != current_function_decl
3897 943505235 : || parsing_nsdmi ()));
3898 : }
3899 :
3900 : /* As above, but also checks that DECL is automatic. */
3901 :
3902 : bool
3903 1233372097 : outer_automatic_var_p (tree decl)
3904 : {
3905 1233372097 : return (outer_var_p (decl)
3906 1233372097 : && !TREE_STATIC (decl));
3907 : }
3908 :
3909 : /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3910 : rewrite it for lambda capture.
3911 :
3912 : If ODR_USE is true, we're being called from mark_use, and we complain about
3913 : use of constant variables. If ODR_USE is false, we're being called for the
3914 : id-expression, and we do lambda capture. */
3915 :
3916 : tree
3917 1355924 : process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
3918 : {
3919 1355924 : if (cp_unevaluated_operand)
3920 : {
3921 782309 : tree type = TREE_TYPE (decl);
3922 782309 : if (!dependent_type_p (type)
3923 782309 : && variably_modified_type_p (type, NULL_TREE))
3924 : /* VLAs are used even in unevaluated context. */;
3925 : else
3926 : /* It's not a use (3.2) if we're in an unevaluated context. */
3927 782303 : return decl;
3928 : }
3929 573621 : if (decl == error_mark_node)
3930 : return decl;
3931 :
3932 573604 : tree context = DECL_CONTEXT (decl);
3933 573604 : tree containing_function = current_function_decl;
3934 573604 : tree lambda_stack = NULL_TREE;
3935 573604 : tree lambda_expr = NULL_TREE;
3936 573604 : tree initializer = convert_from_reference (decl);
3937 :
3938 : /* Mark it as used now even if the use is ill-formed. */
3939 573604 : if (!mark_used (decl, complain))
3940 3 : return error_mark_node;
3941 :
3942 573601 : if (parsing_nsdmi ())
3943 : containing_function = NULL_TREE;
3944 :
3945 1146836 : if (containing_function && LAMBDA_FUNCTION_P (containing_function))
3946 : {
3947 : /* Check whether we've already built a proxy. */
3948 : tree var = decl;
3949 573731 : while (is_normal_capture_proxy (var))
3950 384 : var = DECL_CAPTURED_VARIABLE (var);
3951 573347 : tree d = retrieve_local_specialization (var);
3952 :
3953 573347 : if (d && d != decl && is_capture_proxy (d))
3954 : {
3955 463054 : if (DECL_CONTEXT (d) == containing_function)
3956 : /* We already have an inner proxy. */
3957 : return d;
3958 : else
3959 : /* We need to capture an outer proxy. */
3960 369 : return process_outer_var_ref (d, complain, odr_use);
3961 : }
3962 : }
3963 :
3964 : /* If we are in a lambda function, we can move out until we hit
3965 : 1. the context,
3966 : 2. a non-lambda function, or
3967 : 3. a non-default capturing lambda function. */
3968 220813 : while (context != containing_function
3969 : /* containing_function can be null with invalid generic lambdas. */
3970 220813 : && containing_function
3971 331361 : && LAMBDA_FUNCTION_P (containing_function))
3972 : {
3973 110548 : tree closure = DECL_CONTEXT (containing_function);
3974 110548 : lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
3975 :
3976 110548 : if (TYPE_CLASS_SCOPE_P (closure))
3977 : /* A lambda in an NSDMI (c++/64496). */
3978 : break;
3979 :
3980 110545 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
3981 : break;
3982 :
3983 110266 : lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
3984 :
3985 110266 : containing_function = decl_function_context (containing_function);
3986 : }
3987 :
3988 : /* In a lambda within a template, wait until instantiation time to implicitly
3989 : capture a parameter pack. We want to wait because we don't know if we're
3990 : capturing the whole pack or a single element, and it's OK to wait because
3991 : find_parameter_packs_r walks into the lambda body. */
3992 110547 : if (context == containing_function
3993 110547 : && DECL_PACK_P (decl))
3994 : return decl;
3995 :
3996 89853 : if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
3997 : {
3998 6 : if (complain & tf_error)
3999 6 : error ("cannot capture member %qD of anonymous union", decl);
4000 6 : return error_mark_node;
4001 : }
4002 : /* Do lambda capture when processing the id-expression, not when
4003 : odr-using a variable. */
4004 89847 : if (!odr_use && context == containing_function)
4005 178622 : decl = add_default_capture (lambda_stack,
4006 89311 : /*id=*/DECL_NAME (decl), initializer);
4007 : /* Only an odr-use of an outer automatic variable causes an
4008 : error, and a constant variable can decay to a prvalue
4009 : constant without odr-use. So don't complain yet. */
4010 536 : else if (!odr_use && decl_constant_var_p (decl))
4011 : return decl;
4012 256 : else if (lambda_expr)
4013 : {
4014 41 : if (complain & tf_error)
4015 : {
4016 41 : error ("%qD is not captured", decl);
4017 41 : tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
4018 41 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4019 38 : inform (location_of (closure),
4020 : "the lambda has no capture-default");
4021 3 : else if (TYPE_CLASS_SCOPE_P (closure))
4022 3 : inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
4023 : "capture variables from the enclosing context",
4024 3 : TYPE_CONTEXT (closure));
4025 41 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4026 : }
4027 41 : return error_mark_node;
4028 : }
4029 215 : else if (processing_contract_condition && (TREE_CODE (decl) == PARM_DECL))
4030 : /* Use of a parameter in a contract condition is fine. */
4031 : return decl;
4032 : else
4033 : {
4034 45 : if (complain & tf_error)
4035 : {
4036 58 : error (VAR_P (decl)
4037 : ? G_("use of local variable with automatic storage from "
4038 : "containing function")
4039 : : G_("use of parameter from containing function"));
4040 39 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4041 : }
4042 45 : return error_mark_node;
4043 : }
4044 89311 : return decl;
4045 : }
4046 :
4047 : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4048 : id-expression. (See cp_parser_id_expression for details.) SCOPE,
4049 : if non-NULL, is the type or namespace used to explicitly qualify
4050 : ID_EXPRESSION. DECL is the entity to which that name has been
4051 : resolved.
4052 :
4053 : *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4054 : constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4055 : be set to true if this expression isn't permitted in a
4056 : constant-expression, but it is otherwise not set by this function.
4057 : *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4058 : constant-expression, but a non-constant expression is also
4059 : permissible.
4060 :
4061 : DONE is true if this expression is a complete postfix-expression;
4062 : it is false if this expression is followed by '->', '[', '(', etc.
4063 : ADDRESS_P is true iff this expression is the operand of '&'.
4064 : TEMPLATE_P is true iff the qualified-id was of the form
4065 : "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4066 : appears as a template argument.
4067 :
4068 : If an error occurs, and it is the kind of error that might cause
4069 : the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4070 : is the caller's responsibility to issue the message. *ERROR_MSG
4071 : will be a string with static storage duration, so the caller need
4072 : not "free" it.
4073 :
4074 : Return an expression for the entity, after issuing appropriate
4075 : diagnostics. This function is also responsible for transforming a
4076 : reference to a non-static member into a COMPONENT_REF that makes
4077 : the use of "this" explicit.
4078 :
4079 : Upon return, *IDK will be filled in appropriately. */
4080 : static cp_expr
4081 397303434 : finish_id_expression_1 (tree id_expression,
4082 : tree decl,
4083 : tree scope,
4084 : cp_id_kind *idk,
4085 : bool integral_constant_expression_p,
4086 : bool allow_non_integral_constant_expression_p,
4087 : bool *non_integral_constant_expression_p,
4088 : bool template_p,
4089 : bool done,
4090 : bool address_p,
4091 : bool template_arg_p,
4092 : const char **error_msg,
4093 : location_t location)
4094 : {
4095 397303434 : decl = strip_using_decl (decl);
4096 :
4097 : /* Initialize the output parameters. */
4098 397303434 : *idk = CP_ID_KIND_NONE;
4099 397303434 : *error_msg = NULL;
4100 :
4101 397303434 : if (id_expression == error_mark_node)
4102 16 : return error_mark_node;
4103 : /* If we have a template-id, then no further lookup is
4104 : required. If the template-id was for a template-class, we
4105 : will sometimes have a TYPE_DECL at this point. */
4106 397303418 : else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4107 381622495 : || TREE_CODE (decl) == TYPE_DECL)
4108 : ;
4109 : /* Look up the name. */
4110 : else
4111 : {
4112 381621221 : if (decl == error_mark_node)
4113 : {
4114 : /* Name lookup failed. */
4115 99760 : if (scope
4116 99760 : && (!TYPE_P (scope)
4117 135 : || (!dependent_type_p (scope)
4118 125 : && !(identifier_p (id_expression)
4119 107 : && IDENTIFIER_CONV_OP_P (id_expression)
4120 4 : && dependent_type_p (TREE_TYPE (id_expression))))))
4121 : {
4122 : /* If the qualifying type is non-dependent (and the name
4123 : does not name a conversion operator to a dependent
4124 : type), issue an error. */
4125 383 : qualified_name_lookup_error (scope, id_expression, decl, location);
4126 383 : return error_mark_node;
4127 : }
4128 99377 : else if (!scope)
4129 : {
4130 : /* It may be resolved via Koenig lookup. */
4131 99359 : *idk = CP_ID_KIND_UNQUALIFIED;
4132 99359 : return id_expression;
4133 : }
4134 : else
4135 : decl = id_expression;
4136 : }
4137 :
4138 : /* Remember that the name was used in the definition of
4139 : the current class so that we can check later to see if
4140 : the meaning would have been different after the class
4141 : was entirely defined. */
4142 381521461 : if (!scope && decl != error_mark_node && identifier_p (id_expression))
4143 350850941 : maybe_note_name_used_in_class (id_expression, decl);
4144 :
4145 : /* A use in unevaluated operand might not be instantiated appropriately
4146 : if tsubst_copy builds a dummy parm, or if we never instantiate a
4147 : generic lambda, so mark it now. */
4148 381521479 : if (processing_template_decl && cp_unevaluated_operand)
4149 5248023 : mark_type_use (decl);
4150 :
4151 : /* Disallow uses of local variables from containing functions, except
4152 : within lambda-expressions. */
4153 381521479 : if (outer_automatic_var_p (decl))
4154 : {
4155 1204366 : decl = process_outer_var_ref (decl, tf_warning_or_error);
4156 1204366 : if (decl == error_mark_node)
4157 84 : return error_mark_node;
4158 : }
4159 :
4160 : /* Also disallow uses of function parameters outside the function
4161 : body, except inside an unevaluated context (i.e. decltype). */
4162 381521395 : if (TREE_CODE (decl) == PARM_DECL
4163 164296536 : && DECL_CONTEXT (decl) == NULL_TREE
4164 2562139 : && !cp_unevaluated_operand
4165 381521821 : && !processing_contract_condition)
4166 : {
4167 38 : *error_msg = G_("use of parameter outside function body");
4168 38 : return error_mark_node;
4169 : }
4170 : }
4171 :
4172 : /* If we didn't find anything, or what we found was a type,
4173 : then this wasn't really an id-expression. */
4174 397203554 : if (TREE_CODE (decl) == TEMPLATE_DECL
4175 397203554 : && !DECL_FUNCTION_TEMPLATE_P (decl))
4176 : {
4177 63 : *error_msg = G_("missing template arguments");
4178 63 : return error_mark_node;
4179 : }
4180 397203491 : else if (TREE_CODE (decl) == TYPE_DECL
4181 397202217 : || TREE_CODE (decl) == NAMESPACE_DECL)
4182 : {
4183 1290 : *error_msg = G_("expected primary-expression");
4184 1290 : return error_mark_node;
4185 : }
4186 :
4187 : /* If the name resolved to a template parameter, there is no
4188 : need to look it up again later. */
4189 18441449 : if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
4190 403576357 : || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4191 : {
4192 12067293 : tree r;
4193 :
4194 12067293 : *idk = CP_ID_KIND_NONE;
4195 12067293 : if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4196 0 : decl = TEMPLATE_PARM_DECL (decl);
4197 12067293 : r = DECL_INITIAL (decl);
4198 12067293 : if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
4199 : {
4200 : /* If the entity is a template parameter object for a template
4201 : parameter of type T, the type of the expression is const T. */
4202 35 : tree ctype = TREE_TYPE (r);
4203 35 : ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
4204 : | TYPE_QUAL_CONST));
4205 35 : r = build1 (VIEW_CONVERT_EXPR, ctype, r);
4206 : }
4207 12067293 : r = convert_from_reference (r);
4208 12067293 : if (integral_constant_expression_p
4209 2126267 : && !dependent_type_p (TREE_TYPE (decl))
4210 13828930 : && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
4211 : {
4212 51 : if (!allow_non_integral_constant_expression_p)
4213 8 : error ("template parameter %qD of type %qT is not allowed in "
4214 : "an integral constant expression because it is not of "
4215 8 : "integral or enumeration type", decl, TREE_TYPE (decl));
4216 51 : *non_integral_constant_expression_p = true;
4217 : }
4218 12067293 : return r;
4219 : }
4220 385134908 : else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
4221 : {
4222 11 : gcc_checking_assert (scope);
4223 11 : *idk = CP_ID_KIND_QUALIFIED;
4224 11 : cp_warn_deprecated_use_scopes (scope);
4225 11 : decl = finish_qualified_id_expr (scope, decl, done, address_p,
4226 : template_p, template_arg_p,
4227 : tf_warning_or_error);
4228 : }
4229 : else
4230 : {
4231 385134897 : if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4232 15680923 : && variable_template_p (TREE_OPERAND (decl, 0))
4233 387401770 : && !concept_check_p (decl))
4234 : /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
4235 : considered type-dependent) now, so that the dependence test that
4236 : follows gives us the right answer: if it represents a non-dependent
4237 : variable template-id then finish_template_variable will yield the
4238 : corresponding non-dependent VAR_DECL. */
4239 2266805 : decl = finish_template_variable (decl);
4240 :
4241 385134897 : bool dependent_p = type_dependent_expression_p (decl);
4242 :
4243 : /* If the declaration was explicitly qualified indicate
4244 : that. The semantics of `A::f(3)' are different than
4245 : `f(3)' if `f' is virtual. */
4246 770269794 : *idk = (scope
4247 385134897 : ? CP_ID_KIND_QUALIFIED
4248 344572445 : : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4249 344572445 : ? CP_ID_KIND_TEMPLATE_ID
4250 : : (dependent_p
4251 338816845 : ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
4252 : : CP_ID_KIND_UNQUALIFIED)));
4253 :
4254 385134897 : if (dependent_p
4255 385134897 : && !scope
4256 225840984 : && DECL_P (decl)
4257 597430155 : && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
4258 : /* Dependent type attributes on the decl mean that the TREE_TYPE is
4259 : wrong, so just return the identifier. */
4260 52 : return id_expression;
4261 :
4262 385134845 : if (DECL_CLASS_TEMPLATE_P (decl))
4263 : {
4264 0 : error ("use of class template %qT as expression", decl);
4265 0 : return error_mark_node;
4266 : }
4267 :
4268 385134845 : if (TREE_CODE (decl) == TREE_LIST)
4269 : {
4270 : /* Ambiguous reference to base members. */
4271 0 : error ("request for member %qD is ambiguous in "
4272 : "multiple inheritance lattice", id_expression);
4273 0 : print_candidates (decl);
4274 0 : return error_mark_node;
4275 : }
4276 :
4277 : /* Mark variable-like entities as used. Functions are similarly
4278 : marked either below or after overload resolution. */
4279 385134845 : if ((VAR_P (decl)
4280 385134845 : || TREE_CODE (decl) == PARM_DECL
4281 116274826 : || TREE_CODE (decl) == CONST_DECL
4282 109900670 : || TREE_CODE (decl) == RESULT_DECL)
4283 391509001 : && !mark_used (decl))
4284 11 : return error_mark_node;
4285 :
4286 : /* Only certain kinds of names are allowed in constant
4287 : expression. Template parameters have already
4288 : been handled above. */
4289 385134830 : if (! error_operand_p (decl)
4290 385134526 : && !dependent_p
4291 385134526 : && integral_constant_expression_p
4292 36931135 : && !decl_constant_var_p (decl)
4293 30996372 : && TREE_CODE (decl) != CONST_DECL
4294 27231829 : && !builtin_valid_in_constant_expr_p (decl)
4295 412343009 : && !concept_check_p (decl))
4296 : {
4297 27189872 : if (!allow_non_integral_constant_expression_p)
4298 : {
4299 30 : error ("%qD cannot appear in a constant-expression", decl);
4300 30 : return error_mark_node;
4301 : }
4302 27189842 : *non_integral_constant_expression_p = true;
4303 : }
4304 :
4305 385134800 : if (tree wrap = maybe_get_tls_wrapper_call (decl))
4306 : /* Replace an evaluated use of the thread_local variable with
4307 : a call to its wrapper. */
4308 : decl = wrap;
4309 385134461 : else if (concept_check_p (decl))
4310 : {
4311 : /* Nothing more to do. All of the analysis for concept checks
4312 : is done by build_conept_id, called from the parser. */
4313 : }
4314 384266613 : else if (scope)
4315 : {
4316 40487509 : if (TREE_CODE (decl) == SCOPE_REF)
4317 : {
4318 215 : gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
4319 215 : decl = TREE_OPERAND (decl, 1);
4320 : }
4321 :
4322 40487509 : decl = (adjust_result_of_qualified_name_lookup
4323 40487509 : (decl, scope, current_nonlambda_class_type()));
4324 :
4325 40487509 : cp_warn_deprecated_use_scopes (scope);
4326 :
4327 40487509 : if (TYPE_P (scope))
4328 6897969 : decl = finish_qualified_id_expr (scope,
4329 : decl,
4330 : done,
4331 : address_p,
4332 : template_p,
4333 : template_arg_p,
4334 : tf_warning_or_error);
4335 : else
4336 33589540 : decl = convert_from_reference (decl);
4337 : }
4338 343779104 : else if (TREE_CODE (decl) == FIELD_DECL)
4339 : {
4340 : /* Since SCOPE is NULL here, this is an unqualified name.
4341 : Access checking has been performed during name lookup
4342 : already. Turn off checking to avoid duplicate errors. */
4343 35226866 : push_deferring_access_checks (dk_no_check);
4344 35226866 : decl = finish_non_static_data_member (decl, NULL_TREE,
4345 : /*qualifying_scope=*/NULL_TREE);
4346 35226866 : pop_deferring_access_checks ();
4347 : }
4348 308552238 : else if (is_overloaded_fn (decl))
4349 : {
4350 : /* We only need to look at the first function,
4351 : because all the fns share the attribute we're
4352 : concerned with (all member fns or all non-members). */
4353 37235496 : tree first_fn = get_first_fn (decl);
4354 37235496 : first_fn = STRIP_TEMPLATE (first_fn);
4355 :
4356 37235496 : if (!template_arg_p
4357 37235496 : && (TREE_CODE (first_fn) == USING_DECL
4358 37232412 : || (TREE_CODE (first_fn) == FUNCTION_DECL
4359 37232412 : && DECL_FUNCTION_MEMBER_P (first_fn)
4360 20580490 : && !shared_member_p (decl))))
4361 : {
4362 : /* A set of member functions. */
4363 16790310 : decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
4364 16790310 : return finish_class_member_access_expr (decl, id_expression,
4365 : /*template_p=*/false,
4366 16790310 : tf_warning_or_error);
4367 : }
4368 :
4369 20445186 : decl = baselink_for_fns (decl);
4370 : }
4371 : else
4372 : {
4373 269200158 : if (DECL_P (decl) && DECL_NONLOCAL (decl)
4374 272261874 : && DECL_CLASS_SCOPE_P (decl))
4375 : {
4376 945132 : tree context = context_for_name_lookup (decl);
4377 945132 : if (context != current_class_type)
4378 : {
4379 566144 : tree path = currently_open_derived_class (context);
4380 566144 : if (!path)
4381 : /* PATH can be null for using an enum of an unrelated
4382 : class; we checked its access in lookup_using_decl.
4383 :
4384 : ??? Should this case make a clone instead, like
4385 : handle_using_decl? */
4386 4 : gcc_assert (TREE_CODE (decl) == CONST_DECL);
4387 : else
4388 566140 : perform_or_defer_access_check (TYPE_BINFO (path),
4389 : decl, decl,
4390 : tf_warning_or_error);
4391 : }
4392 : }
4393 :
4394 271316742 : decl = convert_from_reference (decl);
4395 : }
4396 : }
4397 :
4398 368344501 : return cp_expr (decl, location);
4399 : }
4400 :
4401 : /* As per finish_id_expression_1, but adding a wrapper node
4402 : around the result if needed to express LOCATION. */
4403 :
4404 : cp_expr
4405 397303434 : finish_id_expression (tree id_expression,
4406 : tree decl,
4407 : tree scope,
4408 : cp_id_kind *idk,
4409 : bool integral_constant_expression_p,
4410 : bool allow_non_integral_constant_expression_p,
4411 : bool *non_integral_constant_expression_p,
4412 : bool template_p,
4413 : bool done,
4414 : bool address_p,
4415 : bool template_arg_p,
4416 : const char **error_msg,
4417 : location_t location)
4418 : {
4419 397303434 : cp_expr result
4420 397303434 : = finish_id_expression_1 (id_expression, decl, scope, idk,
4421 : integral_constant_expression_p,
4422 : allow_non_integral_constant_expression_p,
4423 : non_integral_constant_expression_p,
4424 : template_p, done, address_p, template_arg_p,
4425 : error_msg, location);
4426 397303430 : return result.maybe_add_location_wrapper ();
4427 : }
4428 :
4429 : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
4430 : use as a type-specifier. */
4431 :
4432 : tree
4433 10411654 : finish_typeof (tree expr)
4434 : {
4435 10411654 : tree type;
4436 :
4437 10411654 : if (type_dependent_expression_p (expr))
4438 : {
4439 10330159 : type = cxx_make_type (TYPEOF_TYPE);
4440 10330159 : TYPEOF_TYPE_EXPR (type) = expr;
4441 10330159 : SET_TYPE_STRUCTURAL_EQUALITY (type);
4442 :
4443 10330159 : return type;
4444 : }
4445 :
4446 81495 : expr = mark_type_use (expr);
4447 :
4448 81495 : type = unlowered_expr_type (expr);
4449 :
4450 81495 : if (!type || type == unknown_type_node)
4451 : {
4452 4 : error ("type of %qE is unknown", expr);
4453 4 : return error_mark_node;
4454 : }
4455 :
4456 : return type;
4457 : }
4458 :
4459 : /* Implement the __underlying_type keyword: Return the underlying
4460 : type of TYPE, suitable for use as a type-specifier. */
4461 :
4462 : tree
4463 27800 : finish_underlying_type (tree type)
4464 : {
4465 27800 : if (!complete_type_or_else (type, NULL_TREE))
4466 3 : return error_mark_node;
4467 :
4468 27797 : if (TREE_CODE (type) != ENUMERAL_TYPE)
4469 : {
4470 32 : error ("%qT is not an enumeration type", type);
4471 32 : return error_mark_node;
4472 : }
4473 :
4474 27765 : tree underlying_type = ENUM_UNDERLYING_TYPE (type);
4475 :
4476 : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
4477 : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
4478 : See finish_enum_value_list for details. */
4479 27765 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
4480 57 : underlying_type
4481 57 : = c_common_type_for_mode (TYPE_MODE (underlying_type),
4482 57 : TYPE_UNSIGNED (underlying_type));
4483 :
4484 : return underlying_type;
4485 : }
4486 :
4487 : /* Implement the __type_pack_element keyword: Return the type
4488 : at index IDX within TYPES. */
4489 :
4490 : static tree
4491 57526 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
4492 : {
4493 57526 : idx = maybe_constant_value (idx);
4494 57526 : if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx)))
4495 : {
4496 6 : if (complain & tf_error)
4497 3 : error ("%<__type_pack_element%> index is not an integral constant");
4498 6 : return error_mark_node;
4499 : }
4500 57520 : HOST_WIDE_INT val = tree_to_shwi (idx);
4501 57520 : if (val < 0)
4502 : {
4503 3 : if (complain & tf_error)
4504 3 : error ("%<__type_pack_element%> index is negative");
4505 3 : return error_mark_node;
4506 : }
4507 57517 : if (val >= TREE_VEC_LENGTH (types))
4508 : {
4509 18 : if (complain & tf_error)
4510 15 : error ("%<__type_pack_element%> index is out of range");
4511 18 : return error_mark_node;
4512 : }
4513 57499 : return TREE_VEC_ELT (types, val);
4514 : }
4515 :
4516 : /* Implement the __direct_bases keyword: Return the direct base classes
4517 : of type. */
4518 :
4519 : tree
4520 15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
4521 : {
4522 15 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
4523 15 : || !NON_UNION_CLASS_TYPE_P (type))
4524 8 : return make_tree_vec (0);
4525 :
4526 7 : releasing_vec vector;
4527 7 : vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
4528 7 : tree binfo;
4529 7 : unsigned i;
4530 :
4531 : /* Virtual bases are initialized first */
4532 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
4533 13 : if (BINFO_VIRTUAL_P (binfo))
4534 13 : vec_safe_push (vector, binfo);
4535 :
4536 : /* Now non-virtuals */
4537 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
4538 13 : if (!BINFO_VIRTUAL_P (binfo))
4539 13 : vec_safe_push (vector, binfo);
4540 :
4541 7 : tree bases_vec = make_tree_vec (vector->length ());
4542 :
4543 27 : for (i = 0; i < vector->length (); ++i)
4544 13 : TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
4545 :
4546 7 : return bases_vec;
4547 15 : }
4548 :
4549 : /* Implement the __bases keyword: Return the base classes
4550 : of type */
4551 :
4552 : /* Find morally non-virtual base classes by walking binfo hierarchy */
4553 : /* Virtual base classes are handled separately in finish_bases */
4554 :
4555 : static tree
4556 73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
4557 : {
4558 : /* Don't walk bases of virtual bases */
4559 73 : return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
4560 : }
4561 :
4562 : static tree
4563 73 : dfs_calculate_bases_post (tree binfo, void *data_)
4564 : {
4565 73 : vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
4566 73 : if (!BINFO_VIRTUAL_P (binfo))
4567 48 : vec_safe_push (*data, BINFO_TYPE (binfo));
4568 73 : return NULL_TREE;
4569 : }
4570 :
4571 : /* Calculates the morally non-virtual base classes of a class */
4572 : static vec<tree, va_gc> *
4573 16 : calculate_bases_helper (tree type)
4574 : {
4575 16 : vec<tree, va_gc> *vector = make_tree_vector ();
4576 :
4577 : /* Now add non-virtual base classes in order of construction */
4578 16 : if (TYPE_BINFO (type))
4579 16 : dfs_walk_all (TYPE_BINFO (type),
4580 : dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
4581 16 : return vector;
4582 : }
4583 :
4584 : tree
4585 12 : calculate_bases (tree type, tsubst_flags_t complain)
4586 : {
4587 12 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
4588 12 : || !NON_UNION_CLASS_TYPE_P (type))
4589 5 : return make_tree_vec (0);
4590 :
4591 7 : releasing_vec vector;
4592 7 : tree bases_vec = NULL_TREE;
4593 7 : unsigned i;
4594 7 : vec<tree, va_gc> *vbases;
4595 7 : tree binfo;
4596 :
4597 : /* First go through virtual base classes */
4598 7 : for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
4599 16 : vec_safe_iterate (vbases, i, &binfo); i++)
4600 : {
4601 9 : releasing_vec vbase_bases
4602 9 : = calculate_bases_helper (BINFO_TYPE (binfo));
4603 9 : vec_safe_splice (vector, vbase_bases);
4604 9 : }
4605 :
4606 : /* Now for the non-virtual bases */
4607 7 : releasing_vec nonvbases = calculate_bases_helper (type);
4608 7 : vec_safe_splice (vector, nonvbases);
4609 :
4610 : /* Note that during error recovery vector->length can even be zero. */
4611 7 : if (vector->length () > 1)
4612 : {
4613 : /* Last element is entire class, so don't copy */
4614 6 : bases_vec = make_tree_vec (vector->length () - 1);
4615 :
4616 53 : for (i = 0; i < vector->length () - 1; ++i)
4617 41 : TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
4618 : }
4619 : else
4620 1 : bases_vec = make_tree_vec (0);
4621 :
4622 7 : return bases_vec;
4623 7 : }
4624 :
4625 : tree
4626 28 : finish_bases (tree type, bool direct)
4627 : {
4628 28 : tree bases = NULL_TREE;
4629 :
4630 28 : if (!processing_template_decl)
4631 : {
4632 : /* Parameter packs can only be used in templates */
4633 0 : error ("parameter pack %<__bases%> only valid in template declaration");
4634 0 : return error_mark_node;
4635 : }
4636 :
4637 28 : bases = cxx_make_type (BASES);
4638 28 : BASES_TYPE (bases) = type;
4639 28 : BASES_DIRECT (bases) = direct;
4640 28 : SET_TYPE_STRUCTURAL_EQUALITY (bases);
4641 :
4642 28 : return bases;
4643 : }
4644 :
4645 : /* Perform C++-specific checks for __builtin_offsetof before calling
4646 : fold_offsetof. */
4647 :
4648 : tree
4649 2577 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
4650 : {
4651 : /* If we're processing a template, we can't finish the semantics yet.
4652 : Otherwise we can fold the entire expression now. */
4653 2577 : if (processing_template_decl)
4654 : {
4655 78 : expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
4656 78 : SET_EXPR_LOCATION (expr, loc);
4657 78 : return expr;
4658 : }
4659 :
4660 2499 : if (expr == error_mark_node)
4661 : return error_mark_node;
4662 :
4663 2485 : if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
4664 : {
4665 8 : error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4666 8 : TREE_OPERAND (expr, 2));
4667 8 : return error_mark_node;
4668 : }
4669 4934 : if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
4670 4934 : || TREE_TYPE (expr) == unknown_type_node)
4671 : {
4672 40 : while (TREE_CODE (expr) == COMPONENT_REF
4673 40 : || TREE_CODE (expr) == COMPOUND_EXPR)
4674 16 : expr = TREE_OPERAND (expr, 1);
4675 :
4676 24 : if (DECL_P (expr))
4677 : {
4678 0 : error ("cannot apply %<offsetof%> to member function %qD", expr);
4679 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
4680 : }
4681 : else
4682 24 : error ("cannot apply %<offsetof%> to member function");
4683 24 : return error_mark_node;
4684 : }
4685 2453 : if (TREE_CODE (expr) == CONST_DECL)
4686 : {
4687 4 : error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
4688 4 : return error_mark_node;
4689 : }
4690 2449 : if (REFERENCE_REF_P (expr))
4691 12 : expr = TREE_OPERAND (expr, 0);
4692 2449 : if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
4693 4 : return error_mark_node;
4694 2445 : if (warn_invalid_offsetof
4695 2445 : && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
4696 2445 : && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
4697 2499 : && cp_unevaluated_operand == 0)
4698 54 : warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
4699 : "non-standard-layout type %qT is conditionally-supported",
4700 54 : TREE_TYPE (TREE_TYPE (object_ptr)));
4701 2445 : return fold_offsetof (expr);
4702 : }
4703 :
4704 : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4705 : function is broken out from the above for the benefit of the tree-ssa
4706 : project. */
4707 :
4708 : void
4709 208569 : simplify_aggr_init_expr (tree *tp)
4710 : {
4711 208569 : tree aggr_init_expr = *tp;
4712 :
4713 : /* Form an appropriate CALL_EXPR. */
4714 208569 : tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
4715 208569 : tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
4716 208569 : tree type = TREE_TYPE (slot);
4717 :
4718 208569 : tree call_expr;
4719 208569 : enum style_t { ctor, arg, pcc } style;
4720 :
4721 208569 : if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
4722 : style = ctor;
4723 : #ifdef PCC_STATIC_STRUCT_RETURN
4724 : else if (1)
4725 : style = pcc;
4726 : #endif
4727 : else
4728 : {
4729 47373 : gcc_assert (TREE_ADDRESSABLE (type));
4730 : style = arg;
4731 : }
4732 :
4733 208569 : call_expr = build_call_array_loc (input_location,
4734 208569 : TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
4735 : fn,
4736 208569 : aggr_init_expr_nargs (aggr_init_expr),
4737 208569 : AGGR_INIT_EXPR_ARGP (aggr_init_expr));
4738 208569 : TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
4739 208569 : CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
4740 208569 : CALL_EXPR_OPERATOR_SYNTAX (call_expr)
4741 208569 : = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
4742 208569 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
4743 208569 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
4744 :
4745 208569 : if (style == ctor)
4746 : {
4747 : /* Replace the first argument to the ctor with the address of the
4748 : slot. */
4749 161196 : cxx_mark_addressable (slot);
4750 161196 : CALL_EXPR_ARG (call_expr, 0) =
4751 161196 : build1 (ADDR_EXPR, build_pointer_type (type), slot);
4752 : }
4753 47373 : else if (style == arg)
4754 : {
4755 : /* Just mark it addressable here, and leave the rest to
4756 : expand_call{,_inline}. */
4757 47373 : cxx_mark_addressable (slot);
4758 47373 : CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
4759 47373 : call_expr = cp_build_init_expr (slot, call_expr);
4760 : }
4761 : else if (style == pcc)
4762 : {
4763 : /* If we're using the non-reentrant PCC calling convention, then we
4764 : need to copy the returned value out of the static buffer into the
4765 : SLOT. */
4766 : push_deferring_access_checks (dk_no_check);
4767 : call_expr = build_aggr_init (slot, call_expr,
4768 : DIRECT_BIND | LOOKUP_ONLYCONVERTING,
4769 : tf_warning_or_error);
4770 : pop_deferring_access_checks ();
4771 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
4772 : }
4773 :
4774 208569 : if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
4775 : {
4776 2729 : tree init = build_zero_init (type, NULL_TREE,
4777 : /*static_storage_p=*/false);
4778 2729 : init = cp_build_init_expr (slot, init);
4779 2729 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
4780 : init, call_expr);
4781 : }
4782 :
4783 208569 : *tp = call_expr;
4784 208569 : }
4785 :
4786 : /* Emit all thunks to FN that should be emitted when FN is emitted. */
4787 :
4788 : void
4789 30130259 : emit_associated_thunks (tree fn)
4790 : {
4791 : /* When we use vcall offsets, we emit thunks with the virtual
4792 : functions to which they thunk. The whole point of vcall offsets
4793 : is so that you can know statically the entire set of thunks that
4794 : will ever be needed for a given virtual function, thereby
4795 : enabling you to output all the thunks with the function itself. */
4796 30130259 : if (DECL_VIRTUAL_P (fn)
4797 : /* Do not emit thunks for extern template instantiations. */
4798 30130259 : && ! DECL_REALLY_EXTERN (fn))
4799 : {
4800 589852 : tree thunk;
4801 :
4802 1184732 : for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
4803 : {
4804 5028 : if (!THUNK_ALIAS (thunk))
4805 : {
4806 5028 : use_thunk (thunk, /*emit_p=*/1);
4807 5028 : if (DECL_RESULT_THUNK_P (thunk))
4808 : {
4809 222 : tree probe;
4810 :
4811 222 : for (probe = DECL_THUNKS (thunk);
4812 413 : probe; probe = DECL_CHAIN (probe))
4813 191 : use_thunk (probe, /*emit_p=*/1);
4814 : }
4815 : }
4816 : else
4817 0 : gcc_assert (!DECL_THUNKS (thunk));
4818 : }
4819 : }
4820 30130259 : }
4821 :
4822 : /* Generate RTL for FN. */
4823 :
4824 : bool
4825 90222819 : expand_or_defer_fn_1 (tree fn)
4826 : {
4827 : /* When the parser calls us after finishing the body of a template
4828 : function, we don't really want to expand the body. */
4829 90222819 : if (processing_template_decl)
4830 : {
4831 : /* Normally, collection only occurs in rest_of_compilation. So,
4832 : if we don't collect here, we never collect junk generated
4833 : during the processing of templates until we hit a
4834 : non-template function. It's not safe to do this inside a
4835 : nested class, though, as the parser may have local state that
4836 : is not a GC root. */
4837 55784288 : if (!function_depth)
4838 55570923 : ggc_collect ();
4839 55784288 : return false;
4840 : }
4841 :
4842 34438531 : gcc_assert (DECL_SAVED_TREE (fn));
4843 :
4844 : /* We make a decision about linkage for these functions at the end
4845 : of the compilation. Until that point, we do not want the back
4846 : end to output them -- but we do want it to see the bodies of
4847 : these functions so that it can inline them as appropriate. */
4848 34438531 : if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn))
4849 : {
4850 34202081 : if (DECL_INTERFACE_KNOWN (fn))
4851 : /* We've already made a decision as to how this function will
4852 : be handled. */;
4853 22253218 : else if (!at_eof
4854 8126567 : || DECL_IMMEDIATE_FUNCTION_P (fn)
4855 30379061 : || DECL_OMP_DECLARE_REDUCTION_P (fn))
4856 14127375 : tentative_decl_linkage (fn);
4857 : else
4858 8125843 : import_export_decl (fn);
4859 :
4860 : /* If the user wants us to keep all inline functions, then mark
4861 : this function as needed so that finish_file will make sure to
4862 : output it later. Similarly, all dllexport'd functions must
4863 : be emitted; there may be callers in other DLLs. */
4864 34202081 : if (DECL_DECLARED_INLINE_P (fn)
4865 32942436 : && !DECL_REALLY_EXTERN (fn)
4866 30410918 : && !DECL_IMMEDIATE_FUNCTION_P (fn)
4867 30409506 : && !DECL_OMP_DECLARE_REDUCTION_P (fn)
4868 64611587 : && (flag_keep_inline_functions
4869 30407267 : || (flag_keep_inline_dllexport
4870 30407267 : && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
4871 : {
4872 2239 : mark_needed (fn);
4873 2239 : DECL_EXTERNAL (fn) = 0;
4874 : }
4875 : }
4876 :
4877 : /* If this is a constructor or destructor body, we have to clone
4878 : it. */
4879 34438531 : if (maybe_clone_body (fn))
4880 : {
4881 : /* We don't want to process FN again, so pretend we've written
4882 : it out, even though we haven't. */
4883 4300771 : TREE_ASM_WRITTEN (fn) = 1;
4884 : /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4885 4300771 : if (!DECL_DECLARED_CONSTEXPR_P (fn)
4886 4309747 : && !(modules_p () && DECL_DECLARED_INLINE_P (fn)))
4887 3337233 : DECL_SAVED_TREE (fn) = NULL_TREE;
4888 4300771 : return false;
4889 : }
4890 :
4891 : /* There's no reason to do any of the work here if we're only doing
4892 : semantic analysis; this code just generates RTL. */
4893 30137760 : if (flag_syntax_only)
4894 : {
4895 : /* Pretend that this function has been written out so that we don't try
4896 : to expand it again. */
4897 7485 : TREE_ASM_WRITTEN (fn) = 1;
4898 7485 : return false;
4899 : }
4900 :
4901 30130275 : if (DECL_OMP_DECLARE_REDUCTION_P (fn))
4902 : return false;
4903 :
4904 : return true;
4905 : }
4906 :
4907 : void
4908 85976479 : expand_or_defer_fn (tree fn)
4909 : {
4910 85976479 : if (expand_or_defer_fn_1 (fn))
4911 : {
4912 25884709 : function_depth++;
4913 :
4914 : /* Expand or defer, at the whim of the compilation unit manager. */
4915 25884709 : cgraph_node::finalize_function (fn, function_depth > 1);
4916 25884709 : emit_associated_thunks (fn);
4917 :
4918 25884709 : function_depth--;
4919 :
4920 51769418 : if (DECL_IMMEDIATE_FUNCTION_P (fn))
4921 : {
4922 1206 : if (cgraph_node *node = cgraph_node::get (fn))
4923 : {
4924 1206 : node->body_removed = true;
4925 1206 : node->analyzed = false;
4926 1206 : node->definition = false;
4927 1206 : node->force_output = false;
4928 : }
4929 : }
4930 : }
4931 85976479 : }
4932 :
4933 113509 : class nrv_data
4934 : {
4935 : public:
4936 113509 : nrv_data () : visited (37) {}
4937 :
4938 : tree var;
4939 : tree result;
4940 : hash_table<nofree_ptr_hash <tree_node> > visited;
4941 : bool simple;
4942 : };
4943 :
4944 : /* Helper function for walk_tree, used by finalize_nrv below. */
4945 :
4946 : static tree
4947 14041493 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
4948 : {
4949 14041493 : class nrv_data *dp = (class nrv_data *)data;
4950 14041493 : tree_node **slot;
4951 :
4952 : /* No need to walk into types. There wouldn't be any need to walk into
4953 : non-statements, except that we have to consider STMT_EXPRs. */
4954 14041493 : if (TYPE_P (*tp))
4955 15 : *walk_subtrees = 0;
4956 : /* If there's a label, we might need to destroy the NRV on goto (92407). */
4957 14041478 : else if (TREE_CODE (*tp) == LABEL_EXPR)
4958 8 : dp->simple = false;
4959 : /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
4960 : but differs from using NULL_TREE in that it indicates that we care
4961 : about the value of the RESULT_DECL. But preserve anything appended
4962 : by check_return_expr. */
4963 14041470 : else if (TREE_CODE (*tp) == RETURN_EXPR)
4964 : {
4965 114123 : tree *p = &TREE_OPERAND (*tp, 0);
4966 317699 : while (TREE_CODE (*p) == COMPOUND_EXPR)
4967 89453 : p = &TREE_OPERAND (*p, 0);
4968 114123 : if (TREE_CODE (*p) == INIT_EXPR
4969 114123 : && INIT_EXPR_NRV_P (*p))
4970 114081 : *p = dp->result;
4971 : }
4972 : /* Change all cleanups for the NRV to only run when not returning. */
4973 13927347 : else if (TREE_CODE (*tp) == CLEANUP_STMT
4974 13927347 : && CLEANUP_DECL (*tp) == dp->var)
4975 : {
4976 88908 : if (dp->simple)
4977 88534 : CLEANUP_EH_ONLY (*tp) = true;
4978 : else
4979 : {
4980 1122 : tree cond = build3 (COND_EXPR, void_type_node,
4981 374 : current_retval_sentinel,
4982 374 : void_node, CLEANUP_EXPR (*tp));
4983 374 : CLEANUP_EXPR (*tp) = cond;
4984 : }
4985 : }
4986 : /* Replace the DECL_EXPR for the NRV with an initialization of the
4987 : RESULT_DECL, if needed. */
4988 13838439 : else if (TREE_CODE (*tp) == DECL_EXPR
4989 13838439 : && DECL_EXPR_DECL (*tp) == dp->var)
4990 : {
4991 113511 : tree init;
4992 113511 : if (DECL_INITIAL (dp->var)
4993 113511 : && DECL_INITIAL (dp->var) != error_mark_node)
4994 19039 : init = cp_build_init_expr (dp->result,
4995 19039 : DECL_INITIAL (dp->var));
4996 : else
4997 94472 : init = build_empty_stmt (EXPR_LOCATION (*tp));
4998 113511 : DECL_INITIAL (dp->var) = NULL_TREE;
4999 113511 : SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
5000 113511 : *tp = init;
5001 : }
5002 : /* And replace all uses of the NRV with the RESULT_DECL. */
5003 13724928 : else if (*tp == dp->var)
5004 443090 : *tp = dp->result;
5005 :
5006 : /* Avoid walking into the same tree more than once. Unfortunately, we
5007 : can't just use walk_tree_without duplicates because it would only call
5008 : us for the first occurrence of dp->var in the function body. */
5009 14041493 : slot = dp->visited.find_slot (*tp, INSERT);
5010 14041493 : if (*slot)
5011 3583775 : *walk_subtrees = 0;
5012 : else
5013 10457718 : *slot = *tp;
5014 :
5015 : /* Keep iterating. */
5016 14041493 : return NULL_TREE;
5017 : }
5018 :
5019 : /* Called from finish_function to implement the named return value
5020 : optimization by overriding all the RETURN_EXPRs and pertinent
5021 : CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5022 : RESULT_DECL for the function. */
5023 :
5024 : void
5025 113509 : finalize_nrv (tree fndecl, tree var)
5026 : {
5027 113509 : class nrv_data data;
5028 113509 : tree result = DECL_RESULT (fndecl);
5029 :
5030 : /* Copy name from VAR to RESULT. */
5031 113509 : DECL_NAME (result) = DECL_NAME (var);
5032 : /* Don't forget that we take its address. */
5033 113509 : TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
5034 : /* Finally set DECL_VALUE_EXPR to avoid assigning
5035 : a stack slot at -O0 for the original var and debug info
5036 : uses RESULT location for VAR. */
5037 113509 : SET_DECL_VALUE_EXPR (var, result);
5038 113509 : DECL_HAS_VALUE_EXPR_P (var) = 1;
5039 :
5040 113509 : data.var = var;
5041 113509 : data.result = result;
5042 :
5043 : /* This is simpler for variables declared in the outer scope of
5044 : the function so we know that their lifetime always ends with a
5045 : return; see g++.dg/opt/nrv6.C. */
5046 113509 : tree outer = outer_curly_brace_block (fndecl);
5047 113509 : data.simple = chain_member (var, BLOCK_VARS (outer));
5048 :
5049 113509 : cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
5050 113509 : }
5051 :
5052 : /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5053 :
5054 : bool
5055 2437 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
5056 : bool need_copy_ctor, bool need_copy_assignment,
5057 : bool need_dtor)
5058 : {
5059 2437 : int save_errorcount = errorcount;
5060 2437 : tree info, t;
5061 :
5062 : /* Always allocate 3 elements for simplicity. These are the
5063 : function decls for the ctor, dtor, and assignment op.
5064 : This layout is known to the three lang hooks,
5065 : cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
5066 : and cxx_omp_clause_assign_op. */
5067 2437 : info = make_tree_vec (3);
5068 2437 : CP_OMP_CLAUSE_INFO (c) = info;
5069 :
5070 2437 : if (need_default_ctor || need_copy_ctor)
5071 : {
5072 1849 : if (need_default_ctor)
5073 1442 : t = get_default_ctor (type);
5074 : else
5075 407 : t = get_copy_ctor (type, tf_warning_or_error);
5076 :
5077 1849 : if (t && !trivial_fn_p (t))
5078 1584 : TREE_VEC_ELT (info, 0) = t;
5079 : }
5080 :
5081 2437 : if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
5082 1775 : TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
5083 :
5084 2437 : if (need_copy_assignment)
5085 : {
5086 433 : t = get_copy_assign (type);
5087 :
5088 433 : if (t && !trivial_fn_p (t))
5089 372 : TREE_VEC_ELT (info, 2) = t;
5090 : }
5091 :
5092 2437 : return errorcount != save_errorcount;
5093 : }
5094 :
5095 : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
5096 : FIELD_DECL, otherwise return DECL itself. */
5097 :
5098 : static tree
5099 29086 : omp_clause_decl_field (tree decl)
5100 : {
5101 29086 : if (VAR_P (decl)
5102 19771 : && DECL_HAS_VALUE_EXPR_P (decl)
5103 343 : && DECL_ARTIFICIAL (decl)
5104 343 : && DECL_LANG_SPECIFIC (decl)
5105 29405 : && DECL_OMP_PRIVATIZED_MEMBER (decl))
5106 : {
5107 313 : tree f = DECL_VALUE_EXPR (decl);
5108 313 : if (INDIRECT_REF_P (f))
5109 0 : f = TREE_OPERAND (f, 0);
5110 313 : if (TREE_CODE (f) == COMPONENT_REF)
5111 : {
5112 313 : f = TREE_OPERAND (f, 1);
5113 313 : gcc_assert (TREE_CODE (f) == FIELD_DECL);
5114 : return f;
5115 : }
5116 : }
5117 : return NULL_TREE;
5118 : }
5119 :
5120 : /* Adjust DECL if needed for printing using %qE. */
5121 :
5122 : static tree
5123 248 : omp_clause_printable_decl (tree decl)
5124 : {
5125 0 : tree t = omp_clause_decl_field (decl);
5126 248 : if (t)
5127 60 : return t;
5128 : return decl;
5129 : }
5130 :
5131 : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
5132 : VAR_DECL T that doesn't need a DECL_EXPR added, record it for
5133 : privatization. */
5134 :
5135 : static void
5136 189 : omp_note_field_privatization (tree f, tree t)
5137 : {
5138 189 : if (!omp_private_member_map)
5139 67 : omp_private_member_map = new hash_map<tree, tree>;
5140 189 : tree &v = omp_private_member_map->get_or_insert (f);
5141 189 : if (v == NULL_TREE)
5142 : {
5143 147 : v = t;
5144 147 : omp_private_member_vec.safe_push (f);
5145 : /* Signal that we don't want to create DECL_EXPR for this dummy var. */
5146 147 : omp_private_member_vec.safe_push (integer_zero_node);
5147 : }
5148 189 : }
5149 :
5150 : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
5151 : dummy VAR_DECL. */
5152 :
5153 : tree
5154 928 : omp_privatize_field (tree t, bool shared)
5155 : {
5156 928 : tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
5157 928 : if (m == error_mark_node)
5158 : return error_mark_node;
5159 928 : if (!omp_private_member_map && !shared)
5160 408 : omp_private_member_map = new hash_map<tree, tree>;
5161 928 : if (TYPE_REF_P (TREE_TYPE (t)))
5162 : {
5163 139 : gcc_assert (INDIRECT_REF_P (m));
5164 139 : m = TREE_OPERAND (m, 0);
5165 : }
5166 928 : tree vb = NULL_TREE;
5167 928 : tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
5168 928 : if (v == NULL_TREE)
5169 : {
5170 851 : v = create_temporary_var (TREE_TYPE (m));
5171 851 : retrofit_lang_decl (v);
5172 851 : DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
5173 851 : SET_DECL_VALUE_EXPR (v, m);
5174 851 : DECL_HAS_VALUE_EXPR_P (v) = 1;
5175 851 : if (!shared)
5176 753 : omp_private_member_vec.safe_push (t);
5177 : }
5178 928 : return v;
5179 : }
5180 :
5181 : /* Helper function for handle_omp_array_sections. Called recursively
5182 : to handle multiple array-section-subscripts. C is the clause,
5183 : T current expression (initially OMP_CLAUSE_DECL), which is either
5184 : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
5185 : expression if specified, TREE_VALUE length expression if specified,
5186 : TREE_CHAIN is what it has been specified after, or some decl.
5187 : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
5188 : set to true if any of the array-section-subscript could have length
5189 : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
5190 : first array-section-subscript which is known not to have length
5191 : of one. Given say:
5192 : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
5193 : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
5194 : all are or may have length of 1, array-section-subscript [:2] is the
5195 : first one known not to have length 1. For array-section-subscript
5196 : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
5197 : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
5198 : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
5199 : case though, as some lengths could be zero. */
5200 :
5201 : static tree
5202 21721 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
5203 : bool &maybe_zero_len, unsigned int &first_non_one,
5204 : enum c_omp_region_type ort)
5205 : {
5206 21721 : tree ret, low_bound, length, type;
5207 21721 : if (TREE_CODE (t) != TREE_LIST)
5208 : {
5209 9613 : if (error_operand_p (t))
5210 0 : return error_mark_node;
5211 34 : if (REFERENCE_REF_P (t)
5212 9647 : && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF)
5213 34 : t = TREE_OPERAND (t, 0);
5214 9613 : ret = t;
5215 9613 : while (INDIRECT_REF_P (t))
5216 : {
5217 0 : t = TREE_OPERAND (t, 0);
5218 0 : STRIP_NOPS (t);
5219 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
5220 0 : t = TREE_OPERAND (t, 0);
5221 : }
5222 9613 : while (TREE_CODE (t) == COMPOUND_EXPR)
5223 : {
5224 0 : t = TREE_OPERAND (t, 1);
5225 0 : STRIP_NOPS (t);
5226 : }
5227 9613 : if (TREE_CODE (t) == COMPONENT_REF
5228 627 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
5229 62 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
5230 38 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
5231 10240 : && !type_dependent_expression_p (t))
5232 : {
5233 518 : if (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
5234 518 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
5235 : {
5236 0 : error_at (OMP_CLAUSE_LOCATION (c),
5237 : "bit-field %qE in %qs clause",
5238 0 : t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5239 0 : return error_mark_node;
5240 : }
5241 1192 : while (TREE_CODE (t) == COMPONENT_REF)
5242 : {
5243 674 : if (TREE_TYPE (TREE_OPERAND (t, 0))
5244 674 : && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == UNION_TYPE)
5245 : {
5246 0 : error_at (OMP_CLAUSE_LOCATION (c),
5247 : "%qE is a member of a union", t);
5248 0 : return error_mark_node;
5249 : }
5250 674 : t = TREE_OPERAND (t, 0);
5251 674 : while (TREE_CODE (t) == MEM_REF
5252 851 : || INDIRECT_REF_P (t)
5253 851 : || TREE_CODE (t) == ARRAY_REF)
5254 : {
5255 177 : t = TREE_OPERAND (t, 0);
5256 177 : STRIP_NOPS (t);
5257 177 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
5258 11 : t = TREE_OPERAND (t, 0);
5259 : }
5260 : }
5261 518 : if (REFERENCE_REF_P (t))
5262 0 : t = TREE_OPERAND (t, 0);
5263 : }
5264 9613 : if (TREE_CODE (t) == FIELD_DECL)
5265 49 : ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
5266 9564 : else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
5267 : {
5268 185 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
5269 : return NULL_TREE;
5270 48 : if (DECL_P (t))
5271 48 : error_at (OMP_CLAUSE_LOCATION (c),
5272 : "%qD is not a variable in %qs clause", t,
5273 48 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5274 : else
5275 0 : error_at (OMP_CLAUSE_LOCATION (c),
5276 : "%qE is not a variable in %qs clause", t,
5277 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5278 48 : return error_mark_node;
5279 : }
5280 9379 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
5281 8939 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
5282 17182 : && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
5283 : {
5284 24 : error_at (OMP_CLAUSE_LOCATION (c),
5285 : "%qD is threadprivate variable in %qs clause", t,
5286 24 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5287 24 : return error_mark_node;
5288 : }
5289 9404 : if (type_dependent_expression_p (ret))
5290 : return NULL_TREE;
5291 9089 : ret = convert_from_reference (ret);
5292 9089 : return ret;
5293 : }
5294 :
5295 12108 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
5296 7414 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
5297 5845 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
5298 4561 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
5299 15090 : && TREE_CODE (TREE_CHAIN (t)) == FIELD_DECL)
5300 43 : TREE_CHAIN (t) = omp_privatize_field (TREE_CHAIN (t), false);
5301 12108 : ret = handle_omp_array_sections_1 (c, TREE_CHAIN (t), types,
5302 : maybe_zero_len, first_non_one, ort);
5303 12108 : if (ret == error_mark_node || ret == NULL_TREE)
5304 : return ret;
5305 :
5306 11246 : type = TREE_TYPE (ret);
5307 11246 : low_bound = TREE_PURPOSE (t);
5308 11246 : length = TREE_VALUE (t);
5309 9083 : if ((low_bound && type_dependent_expression_p (low_bound))
5310 20235 : || (length && type_dependent_expression_p (length)))
5311 99 : return NULL_TREE;
5312 :
5313 11147 : if (low_bound == error_mark_node || length == error_mark_node)
5314 : return error_mark_node;
5315 :
5316 11147 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
5317 : {
5318 84 : error_at (OMP_CLAUSE_LOCATION (c),
5319 : "low bound %qE of array section does not have integral type",
5320 : low_bound);
5321 84 : return error_mark_node;
5322 : }
5323 11063 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
5324 : {
5325 84 : error_at (OMP_CLAUSE_LOCATION (c),
5326 : "length %qE of array section does not have integral type",
5327 : length);
5328 84 : return error_mark_node;
5329 : }
5330 10979 : if (low_bound)
5331 8896 : low_bound = mark_rvalue_use (low_bound);
5332 10979 : if (length)
5333 9713 : length = mark_rvalue_use (length);
5334 : /* We need to reduce to real constant-values for checks below. */
5335 9713 : if (length)
5336 9713 : length = fold_simple (length);
5337 10979 : if (low_bound)
5338 8896 : low_bound = fold_simple (low_bound);
5339 8896 : if (low_bound
5340 8896 : && TREE_CODE (low_bound) == INTEGER_CST
5341 16760 : && TYPE_PRECISION (TREE_TYPE (low_bound))
5342 7864 : > TYPE_PRECISION (sizetype))
5343 0 : low_bound = fold_convert (sizetype, low_bound);
5344 10979 : if (length
5345 9713 : && TREE_CODE (length) == INTEGER_CST
5346 18553 : && TYPE_PRECISION (TREE_TYPE (length))
5347 7574 : > TYPE_PRECISION (sizetype))
5348 0 : length = fold_convert (sizetype, length);
5349 10979 : if (low_bound == NULL_TREE)
5350 2083 : low_bound = integer_zero_node;
5351 :
5352 10979 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
5353 10979 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
5354 4803 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
5355 : {
5356 80 : if (length != integer_one_node)
5357 : {
5358 48 : error_at (OMP_CLAUSE_LOCATION (c),
5359 : "expected single pointer in %qs clause",
5360 : user_omp_clause_code_name (c, ort == C_ORT_ACC));
5361 48 : return error_mark_node;
5362 : }
5363 : }
5364 10931 : if (length != NULL_TREE)
5365 : {
5366 9697 : if (!integer_nonzerop (length))
5367 : {
5368 2199 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
5369 2167 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
5370 2127 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
5371 1960 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
5372 3937 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
5373 : {
5374 496 : if (integer_zerop (length))
5375 : {
5376 48 : error_at (OMP_CLAUSE_LOCATION (c),
5377 : "zero length array section in %qs clause",
5378 48 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5379 48 : return error_mark_node;
5380 : }
5381 : }
5382 : else
5383 1703 : maybe_zero_len = true;
5384 : }
5385 9649 : if (first_non_one == types.length ()
5386 9649 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
5387 4165 : first_non_one++;
5388 : }
5389 10883 : if (TREE_CODE (type) == ARRAY_TYPE)
5390 : {
5391 6392 : if (length == NULL_TREE
5392 6392 : && (TYPE_DOMAIN (type) == NULL_TREE
5393 1130 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
5394 : {
5395 44 : error_at (OMP_CLAUSE_LOCATION (c),
5396 : "for unknown bound array type length expression must "
5397 : "be specified");
5398 44 : return error_mark_node;
5399 : }
5400 6348 : if (TREE_CODE (low_bound) == INTEGER_CST
5401 6348 : && tree_int_cst_sgn (low_bound) == -1)
5402 : {
5403 232 : error_at (OMP_CLAUSE_LOCATION (c),
5404 : "negative low bound in array section in %qs clause",
5405 232 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5406 232 : return error_mark_node;
5407 : }
5408 6116 : if (length != NULL_TREE
5409 5058 : && TREE_CODE (length) == INTEGER_CST
5410 10233 : && tree_int_cst_sgn (length) == -1)
5411 : {
5412 232 : error_at (OMP_CLAUSE_LOCATION (c),
5413 : "negative length in array section in %qs clause",
5414 232 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5415 232 : return error_mark_node;
5416 : }
5417 5884 : if (TYPE_DOMAIN (type)
5418 5753 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
5419 11637 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
5420 : == INTEGER_CST)
5421 : {
5422 5329 : tree size
5423 5329 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
5424 5329 : size = size_binop (PLUS_EXPR, size, size_one_node);
5425 5329 : if (TREE_CODE (low_bound) == INTEGER_CST)
5426 : {
5427 4478 : if (tree_int_cst_lt (size, low_bound))
5428 : {
5429 80 : error_at (OMP_CLAUSE_LOCATION (c),
5430 : "low bound %qE above array section size "
5431 : "in %qs clause", low_bound,
5432 80 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5433 80 : return error_mark_node;
5434 : }
5435 4398 : if (tree_int_cst_equal (size, low_bound))
5436 : {
5437 28 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
5438 20 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
5439 8 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
5440 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
5441 28 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
5442 : {
5443 28 : error_at (OMP_CLAUSE_LOCATION (c),
5444 : "zero length array section in %qs clause",
5445 28 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5446 28 : return error_mark_node;
5447 : }
5448 0 : maybe_zero_len = true;
5449 : }
5450 4370 : else if (length == NULL_TREE
5451 1876 : && first_non_one == types.length ()
5452 4791 : && tree_int_cst_equal
5453 421 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
5454 : low_bound))
5455 273 : first_non_one++;
5456 : }
5457 851 : else if (length == NULL_TREE)
5458 : {
5459 11 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
5460 7 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
5461 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
5462 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
5463 11 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
5464 0 : maybe_zero_len = true;
5465 22 : if (first_non_one == types.length ())
5466 7 : first_non_one++;
5467 : }
5468 5221 : if (length && TREE_CODE (length) == INTEGER_CST)
5469 : {
5470 3733 : if (tree_int_cst_lt (size, length))
5471 : {
5472 84 : error_at (OMP_CLAUSE_LOCATION (c),
5473 : "length %qE above array section size "
5474 : "in %qs clause", length,
5475 84 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5476 84 : return error_mark_node;
5477 : }
5478 3649 : if (TREE_CODE (low_bound) == INTEGER_CST)
5479 : {
5480 3247 : tree lbpluslen
5481 3247 : = size_binop (PLUS_EXPR,
5482 : fold_convert (sizetype, low_bound),
5483 : fold_convert (sizetype, length));
5484 3247 : if (TREE_CODE (lbpluslen) == INTEGER_CST
5485 3247 : && tree_int_cst_lt (size, lbpluslen))
5486 : {
5487 80 : error_at (OMP_CLAUSE_LOCATION (c),
5488 : "high bound %qE above array section size "
5489 : "in %qs clause", lbpluslen,
5490 80 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5491 80 : return error_mark_node;
5492 : }
5493 : }
5494 : }
5495 : }
5496 555 : else if (length == NULL_TREE)
5497 : {
5498 1 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
5499 1 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
5500 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
5501 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
5502 1 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
5503 0 : maybe_zero_len = true;
5504 2 : if (first_non_one == types.length ())
5505 1 : first_non_one++;
5506 : }
5507 :
5508 : /* For [lb:] we will need to evaluate lb more than once. */
5509 4520 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
5510 : {
5511 842 : tree lb = cp_save_expr (low_bound);
5512 842 : if (lb != low_bound)
5513 : {
5514 6 : TREE_PURPOSE (t) = lb;
5515 6 : low_bound = lb;
5516 : }
5517 : }
5518 : }
5519 4491 : else if (TYPE_PTR_P (type))
5520 : {
5521 4447 : if (length == NULL_TREE)
5522 : {
5523 60 : if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
5524 52 : error_at (OMP_CLAUSE_LOCATION (c),
5525 : "for array function parameter length expression "
5526 : "must be specified");
5527 : else
5528 8 : error_at (OMP_CLAUSE_LOCATION (c),
5529 : "for pointer type length expression must be specified");
5530 60 : return error_mark_node;
5531 : }
5532 4387 : if (length != NULL_TREE
5533 4387 : && TREE_CODE (length) == INTEGER_CST
5534 3189 : && tree_int_cst_sgn (length) == -1)
5535 : {
5536 128 : error_at (OMP_CLAUSE_LOCATION (c),
5537 : "negative length in array section in %qs clause",
5538 128 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5539 128 : return error_mark_node;
5540 : }
5541 : /* If there is a pointer type anywhere but in the very first
5542 : array-section-subscript, the array section could be non-contiguous. */
5543 4259 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
5544 4123 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
5545 7816 : && TREE_CODE (TREE_CHAIN (t)) == TREE_LIST)
5546 : {
5547 : /* If any prior dimension has a non-one length, then deem this
5548 : array section as non-contiguous. */
5549 36 : for (tree d = TREE_CHAIN (t); TREE_CODE (d) == TREE_LIST;
5550 4 : d = TREE_CHAIN (d))
5551 : {
5552 32 : tree d_length = TREE_VALUE (d);
5553 32 : if (d_length == NULL_TREE || !integer_onep (d_length))
5554 : {
5555 28 : error_at (OMP_CLAUSE_LOCATION (c),
5556 : "array section is not contiguous in %qs clause",
5557 28 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5558 28 : return error_mark_node;
5559 : }
5560 : }
5561 : }
5562 : }
5563 : else
5564 : {
5565 44 : error_at (OMP_CLAUSE_LOCATION (c),
5566 : "%qE does not have pointer or array type", ret);
5567 44 : return error_mark_node;
5568 : }
5569 9843 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
5570 8739 : types.safe_push (TREE_TYPE (ret));
5571 : /* We will need to evaluate lb more than once. */
5572 9843 : tree lb = cp_save_expr (low_bound);
5573 9843 : if (lb != low_bound)
5574 : {
5575 811 : TREE_PURPOSE (t) = lb;
5576 811 : low_bound = lb;
5577 : }
5578 : /* Temporarily disable -fstrong-eval-order for array reductions.
5579 : The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
5580 : is something the middle-end can't cope with and more importantly,
5581 : it needs to be the actual base variable that is privatized, not some
5582 : temporary assigned previous value of it. That, together with OpenMP
5583 : saying how many times the side-effects are evaluated is unspecified,
5584 : makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
5585 9843 : warning_sentinel s (flag_strong_eval_order,
5586 9843 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
5587 8523 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
5588 19806 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
5589 9843 : ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
5590 : tf_warning_or_error);
5591 9843 : return ret;
5592 21721 : }
5593 :
5594 : /* Handle array sections for clause C. */
5595 :
5596 : static bool
5597 9613 : handle_omp_array_sections (tree c, enum c_omp_region_type ort)
5598 : {
5599 9613 : bool maybe_zero_len = false;
5600 9613 : unsigned int first_non_one = 0;
5601 9613 : auto_vec<tree, 10> types;
5602 9613 : tree *tp = &OMP_CLAUSE_DECL (c);
5603 9613 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
5604 8437 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
5605 1640 : && TREE_CODE (*tp) == TREE_LIST
5606 1640 : && TREE_PURPOSE (*tp)
5607 11009 : && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC)
5608 336 : tp = &TREE_VALUE (*tp);
5609 9613 : tree first = handle_omp_array_sections_1 (c, *tp, types,
5610 : maybe_zero_len, first_non_one,
5611 : ort);
5612 9613 : if (first == error_mark_node)
5613 : return true;
5614 8237 : if (first == NULL_TREE)
5615 : return false;
5616 7686 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
5617 7686 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
5618 : {
5619 1120 : tree t = *tp;
5620 1120 : tree tem = NULL_TREE;
5621 1120 : if (processing_template_decl)
5622 : return false;
5623 : /* Need to evaluate side effects in the length expressions
5624 : if any. */
5625 2168 : while (TREE_CODE (t) == TREE_LIST)
5626 : {
5627 1180 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
5628 : {
5629 24 : if (tem == NULL_TREE)
5630 : tem = TREE_VALUE (t);
5631 : else
5632 8 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
5633 8 : TREE_VALUE (t), tem);
5634 : }
5635 1180 : t = TREE_CHAIN (t);
5636 : }
5637 988 : if (tem)
5638 16 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
5639 988 : *tp = first;
5640 : }
5641 : else
5642 : {
5643 6566 : unsigned int num = types.length (), i;
5644 6566 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
5645 6566 : tree condition = NULL_TREE;
5646 :
5647 6566 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
5648 4 : maybe_zero_len = true;
5649 6566 : if (processing_template_decl && maybe_zero_len)
5650 : return false;
5651 :
5652 13939 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
5653 7444 : t = TREE_CHAIN (t))
5654 : {
5655 7544 : tree low_bound = TREE_PURPOSE (t);
5656 7544 : tree length = TREE_VALUE (t);
5657 :
5658 7544 : i--;
5659 7544 : if (low_bound
5660 6217 : && TREE_CODE (low_bound) == INTEGER_CST
5661 13126 : && TYPE_PRECISION (TREE_TYPE (low_bound))
5662 5582 : > TYPE_PRECISION (sizetype))
5663 0 : low_bound = fold_convert (sizetype, low_bound);
5664 7544 : if (length
5665 6918 : && TREE_CODE (length) == INTEGER_CST
5666 12442 : && TYPE_PRECISION (TREE_TYPE (length))
5667 4898 : > TYPE_PRECISION (sizetype))
5668 0 : length = fold_convert (sizetype, length);
5669 7544 : if (low_bound == NULL_TREE)
5670 1327 : low_bound = integer_zero_node;
5671 7544 : if (!maybe_zero_len && i > first_non_one)
5672 : {
5673 762 : if (integer_nonzerop (low_bound))
5674 48 : goto do_warn_noncontiguous;
5675 714 : if (length != NULL_TREE
5676 341 : && TREE_CODE (length) == INTEGER_CST
5677 341 : && TYPE_DOMAIN (types[i])
5678 341 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
5679 1055 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
5680 : == INTEGER_CST)
5681 : {
5682 341 : tree size;
5683 341 : size = size_binop (PLUS_EXPR,
5684 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
5685 : size_one_node);
5686 341 : if (!tree_int_cst_equal (length, size))
5687 : {
5688 52 : do_warn_noncontiguous:
5689 100 : error_at (OMP_CLAUSE_LOCATION (c),
5690 : "array section is not contiguous in %qs "
5691 : "clause",
5692 100 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5693 100 : return true;
5694 : }
5695 : }
5696 662 : if (!processing_template_decl
5697 459 : && length != NULL_TREE
5698 861 : && TREE_SIDE_EFFECTS (length))
5699 : {
5700 0 : if (side_effects == NULL_TREE)
5701 : side_effects = length;
5702 : else
5703 0 : side_effects = build2 (COMPOUND_EXPR,
5704 0 : TREE_TYPE (side_effects),
5705 : length, side_effects);
5706 : }
5707 : }
5708 6782 : else if (processing_template_decl)
5709 866 : continue;
5710 : else
5711 : {
5712 5916 : tree l;
5713 :
5714 5916 : if (i > first_non_one
5715 5916 : && ((length && integer_nonzerop (length))
5716 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
5717 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
5718 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
5719 0 : continue;
5720 5916 : if (length)
5721 5772 : l = fold_convert (sizetype, length);
5722 : else
5723 : {
5724 144 : l = size_binop (PLUS_EXPR,
5725 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
5726 : size_one_node);
5727 144 : l = size_binop (MINUS_EXPR, l,
5728 : fold_convert (sizetype, low_bound));
5729 : }
5730 5916 : if (i > first_non_one)
5731 : {
5732 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
5733 : size_zero_node);
5734 0 : if (condition == NULL_TREE)
5735 : condition = l;
5736 : else
5737 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
5738 : l, condition);
5739 : }
5740 5916 : else if (size == NULL_TREE)
5741 : {
5742 5637 : size = size_in_bytes (TREE_TYPE (types[i]));
5743 5637 : tree eltype = TREE_TYPE (types[num - 1]);
5744 5730 : while (TREE_CODE (eltype) == ARRAY_TYPE)
5745 93 : eltype = TREE_TYPE (eltype);
5746 5637 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
5747 4642 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
5748 9526 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
5749 1845 : size = size_binop (EXACT_DIV_EXPR, size,
5750 : size_in_bytes (eltype));
5751 5637 : size = size_binop (MULT_EXPR, size, l);
5752 5637 : if (condition)
5753 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
5754 : size, size_zero_node);
5755 : }
5756 : else
5757 279 : size = size_binop (MULT_EXPR, size, l);
5758 : }
5759 : }
5760 6395 : if (!processing_template_decl)
5761 : {
5762 5637 : if (side_effects)
5763 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
5764 5637 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
5765 4642 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
5766 9526 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
5767 : {
5768 1845 : size = size_binop (MINUS_EXPR, size, size_one_node);
5769 1845 : size = save_expr (size);
5770 1845 : tree index_type = build_index_type (size);
5771 1845 : tree eltype = TREE_TYPE (first);
5772 1882 : while (TREE_CODE (eltype) == ARRAY_TYPE)
5773 37 : eltype = TREE_TYPE (eltype);
5774 1845 : tree type = build_array_type (eltype, index_type);
5775 1845 : tree ptype = build_pointer_type (eltype);
5776 1845 : if (TYPE_REF_P (TREE_TYPE (t))
5777 1845 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
5778 188 : t = convert_from_reference (t);
5779 1657 : else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
5780 715 : t = build_fold_addr_expr (t);
5781 1845 : tree t2 = build_fold_addr_expr (first);
5782 1845 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
5783 : ptrdiff_type_node, t2);
5784 3690 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
5785 : ptrdiff_type_node, t2,
5786 1845 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
5787 : ptrdiff_type_node, t));
5788 1845 : if (tree_fits_shwi_p (t2))
5789 1500 : t = build2 (MEM_REF, type, t,
5790 1500 : build_int_cst (ptype, tree_to_shwi (t2)));
5791 : else
5792 : {
5793 345 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
5794 : sizetype, t2);
5795 345 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
5796 345 : TREE_TYPE (t), t, t2);
5797 345 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
5798 : }
5799 1845 : OMP_CLAUSE_DECL (c) = t;
5800 1845 : return false;
5801 : }
5802 3792 : OMP_CLAUSE_DECL (c) = first;
5803 3792 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
5804 : return false;
5805 3760 : OMP_CLAUSE_SIZE (c) = size;
5806 3760 : if (TREE_CODE (t) == FIELD_DECL)
5807 9 : t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
5808 3760 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
5809 3760 : || (TREE_CODE (t) == COMPONENT_REF
5810 453 : && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE))
5811 : return false;
5812 3017 : switch (OMP_CLAUSE_MAP_KIND (c))
5813 : {
5814 2985 : case GOMP_MAP_ALLOC:
5815 2985 : case GOMP_MAP_IF_PRESENT:
5816 2985 : case GOMP_MAP_TO:
5817 2985 : case GOMP_MAP_FROM:
5818 2985 : case GOMP_MAP_TOFROM:
5819 2985 : case GOMP_MAP_ALWAYS_TO:
5820 2985 : case GOMP_MAP_ALWAYS_FROM:
5821 2985 : case GOMP_MAP_ALWAYS_TOFROM:
5822 2985 : case GOMP_MAP_PRESENT_ALLOC:
5823 2985 : case GOMP_MAP_PRESENT_TO:
5824 2985 : case GOMP_MAP_PRESENT_FROM:
5825 2985 : case GOMP_MAP_PRESENT_TOFROM:
5826 2985 : case GOMP_MAP_ALWAYS_PRESENT_TO:
5827 2985 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
5828 2985 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
5829 2985 : case GOMP_MAP_RELEASE:
5830 2985 : case GOMP_MAP_DELETE:
5831 2985 : case GOMP_MAP_FORCE_TO:
5832 2985 : case GOMP_MAP_FORCE_FROM:
5833 2985 : case GOMP_MAP_FORCE_TOFROM:
5834 2985 : case GOMP_MAP_FORCE_PRESENT:
5835 2985 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
5836 2985 : break;
5837 : default:
5838 : break;
5839 : }
5840 3017 : bool reference_always_pointer = true;
5841 3017 : tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c),
5842 : OMP_CLAUSE_MAP);
5843 3017 : if (TREE_CODE (t) == COMPONENT_REF)
5844 : {
5845 316 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ATTACH_DETACH);
5846 :
5847 316 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
5848 316 : && TYPE_REF_P (TREE_TYPE (t)))
5849 : {
5850 40 : if (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == ARRAY_TYPE)
5851 20 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER);
5852 : else
5853 20 : t = convert_from_reference (t);
5854 :
5855 : reference_always_pointer = false;
5856 : }
5857 : }
5858 26 : else if (REFERENCE_REF_P (t)
5859 2727 : && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF)
5860 : {
5861 26 : gomp_map_kind k;
5862 26 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
5863 26 : && TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
5864 : k = GOMP_MAP_ATTACH_DETACH;
5865 : else
5866 : {
5867 15 : t = TREE_OPERAND (t, 0);
5868 15 : k = (ort == C_ORT_ACC
5869 15 : ? GOMP_MAP_ATTACH_DETACH : GOMP_MAP_ALWAYS_POINTER);
5870 : }
5871 26 : OMP_CLAUSE_SET_MAP_KIND (c2, k);
5872 : }
5873 : else
5874 2675 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
5875 3017 : OMP_CLAUSE_MAP_IMPLICIT (c2) = OMP_CLAUSE_MAP_IMPLICIT (c);
5876 3017 : if (OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER
5877 3017 : && !cxx_mark_addressable (t))
5878 : return false;
5879 3017 : OMP_CLAUSE_DECL (c2) = t;
5880 3017 : t = build_fold_addr_expr (first);
5881 3017 : t = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
5882 : ptrdiff_type_node, t);
5883 3017 : tree ptr = OMP_CLAUSE_DECL (c2);
5884 3017 : ptr = convert_from_reference (ptr);
5885 3017 : if (!INDIRECT_TYPE_P (TREE_TYPE (ptr)))
5886 892 : ptr = build_fold_addr_expr (ptr);
5887 6034 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
5888 : ptrdiff_type_node, t,
5889 3017 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
5890 : ptrdiff_type_node, ptr));
5891 3017 : OMP_CLAUSE_SIZE (c2) = t;
5892 3017 : OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c);
5893 3017 : OMP_CLAUSE_CHAIN (c) = c2;
5894 :
5895 3017 : ptr = OMP_CLAUSE_DECL (c2);
5896 3017 : if (reference_always_pointer
5897 2977 : && OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER
5898 302 : && TYPE_REF_P (TREE_TYPE (ptr))
5899 3032 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr))))
5900 : {
5901 0 : tree c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c),
5902 : OMP_CLAUSE_MAP);
5903 0 : OMP_CLAUSE_SET_MAP_KIND (c3, OMP_CLAUSE_MAP_KIND (c2));
5904 0 : OMP_CLAUSE_MAP_IMPLICIT (c2) = OMP_CLAUSE_MAP_IMPLICIT (c);
5905 0 : OMP_CLAUSE_DECL (c3) = ptr;
5906 0 : if (OMP_CLAUSE_MAP_KIND (c2) == GOMP_MAP_ALWAYS_POINTER
5907 0 : || OMP_CLAUSE_MAP_KIND (c2) == GOMP_MAP_ATTACH_DETACH)
5908 : {
5909 0 : OMP_CLAUSE_DECL (c2) = build_simple_mem_ref (ptr);
5910 0 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER);
5911 : }
5912 : else
5913 0 : OMP_CLAUSE_DECL (c2) = convert_from_reference (ptr);
5914 0 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
5915 0 : OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (c2);
5916 0 : OMP_CLAUSE_CHAIN (c2) = c3;
5917 : }
5918 : }
5919 : }
5920 : return false;
5921 9613 : }
5922 :
5923 : /* Return identifier to look up for omp declare reduction. */
5924 :
5925 : tree
5926 8307 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
5927 : {
5928 8307 : const char *p = NULL;
5929 8307 : const char *m = NULL;
5930 8307 : switch (reduction_code)
5931 : {
5932 5034 : case PLUS_EXPR:
5933 5034 : case MULT_EXPR:
5934 5034 : case MINUS_EXPR:
5935 5034 : case BIT_AND_EXPR:
5936 5034 : case BIT_XOR_EXPR:
5937 5034 : case BIT_IOR_EXPR:
5938 5034 : case TRUTH_ANDIF_EXPR:
5939 5034 : case TRUTH_ORIF_EXPR:
5940 5034 : reduction_id = ovl_op_identifier (false, reduction_code);
5941 5034 : break;
5942 : case MIN_EXPR:
5943 : p = "min";
5944 : break;
5945 : case MAX_EXPR:
5946 : p = "max";
5947 : break;
5948 : default:
5949 : break;
5950 : }
5951 :
5952 5034 : if (p == NULL)
5953 : {
5954 8151 : if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
5955 0 : return error_mark_node;
5956 8151 : p = IDENTIFIER_POINTER (reduction_id);
5957 : }
5958 :
5959 8307 : if (type != NULL_TREE)
5960 2285 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
5961 :
5962 8307 : const char prefix[] = "omp declare reduction ";
5963 8307 : size_t lenp = sizeof (prefix);
5964 8307 : if (strncmp (p, prefix, lenp - 1) == 0)
5965 2285 : lenp = 1;
5966 8307 : size_t len = strlen (p);
5967 8307 : size_t lenm = m ? strlen (m) + 1 : 0;
5968 8307 : char *name = XALLOCAVEC (char, lenp + len + lenm);
5969 8307 : if (lenp > 1)
5970 6022 : memcpy (name, prefix, lenp - 1);
5971 8307 : memcpy (name + lenp - 1, p, len + 1);
5972 8307 : if (m)
5973 : {
5974 2285 : name[lenp + len - 1] = '~';
5975 2285 : memcpy (name + lenp + len, m, lenm);
5976 : }
5977 8307 : return get_identifier (name);
5978 : }
5979 :
5980 : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5981 : FUNCTION_DECL or NULL_TREE if not found. */
5982 :
5983 : static tree
5984 1372 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
5985 : vec<tree> *ambiguousp)
5986 : {
5987 1372 : tree orig_id = id;
5988 1372 : tree baselink = NULL_TREE;
5989 1372 : if (identifier_p (id))
5990 : {
5991 1338 : cp_id_kind idk;
5992 1338 : bool nonint_cst_expression_p;
5993 1338 : const char *error_msg;
5994 1338 : id = omp_reduction_id (ERROR_MARK, id, type);
5995 1338 : tree decl = lookup_name (id);
5996 1338 : if (decl == NULL_TREE)
5997 100 : decl = error_mark_node;
5998 1338 : id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
5999 : &nonint_cst_expression_p, false, true, false,
6000 : false, &error_msg, loc);
6001 1338 : if (idk == CP_ID_KIND_UNQUALIFIED
6002 1438 : && identifier_p (id))
6003 : {
6004 100 : vec<tree, va_gc> *args = NULL;
6005 100 : vec_safe_push (args, build_reference_type (type));
6006 100 : id = perform_koenig_lookup (id, args, tf_none);
6007 : }
6008 : }
6009 34 : else if (TREE_CODE (id) == SCOPE_REF)
6010 34 : id = lookup_qualified_name (TREE_OPERAND (id, 0),
6011 : omp_reduction_id (ERROR_MARK,
6012 34 : TREE_OPERAND (id, 1),
6013 : type),
6014 : LOOK_want::NORMAL, false);
6015 1372 : tree fns = id;
6016 1372 : id = NULL_TREE;
6017 1372 : if (fns && is_overloaded_fn (fns))
6018 : {
6019 2556 : for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
6020 : {
6021 1278 : tree fndecl = *iter;
6022 1278 : if (TREE_CODE (fndecl) == FUNCTION_DECL)
6023 : {
6024 1278 : tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
6025 1278 : if (same_type_p (TREE_TYPE (argtype), type))
6026 : {
6027 1278 : id = fndecl;
6028 1278 : break;
6029 : }
6030 : }
6031 : }
6032 :
6033 1278 : if (id && BASELINK_P (fns))
6034 : {
6035 80 : if (baselinkp)
6036 0 : *baselinkp = fns;
6037 : else
6038 80 : baselink = fns;
6039 : }
6040 : }
6041 :
6042 1372 : if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
6043 : {
6044 42 : auto_vec<tree> ambiguous;
6045 42 : tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
6046 42 : unsigned int ix;
6047 42 : if (ambiguousp == NULL)
6048 24 : ambiguousp = &ambiguous;
6049 88 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
6050 : {
6051 62 : id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
6052 : baselinkp ? baselinkp : &baselink,
6053 : ambiguousp);
6054 46 : if (id == NULL_TREE)
6055 16 : continue;
6056 30 : if (!ambiguousp->is_empty ())
6057 4 : ambiguousp->safe_push (id);
6058 26 : else if (ret != NULL_TREE)
6059 : {
6060 8 : ambiguousp->safe_push (ret);
6061 8 : ambiguousp->safe_push (id);
6062 8 : ret = NULL_TREE;
6063 : }
6064 : else
6065 18 : ret = id;
6066 : }
6067 42 : if (ambiguousp != &ambiguous)
6068 18 : return ret;
6069 24 : if (!ambiguous.is_empty ())
6070 : {
6071 8 : const char *str = _("candidates are:");
6072 8 : unsigned int idx;
6073 8 : tree udr;
6074 8 : error_at (loc, "user defined reduction lookup is ambiguous");
6075 36 : FOR_EACH_VEC_ELT (ambiguous, idx, udr)
6076 : {
6077 20 : inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
6078 20 : if (idx == 0)
6079 8 : str = get_spaces (str);
6080 : }
6081 8 : ret = error_mark_node;
6082 8 : baselink = NULL_TREE;
6083 : }
6084 24 : id = ret;
6085 42 : }
6086 1354 : if (id && baselink)
6087 80 : perform_or_defer_access_check (BASELINK_BINFO (baselink),
6088 : id, id, tf_warning_or_error);
6089 : return id;
6090 : }
6091 :
6092 : /* Helper function for cp_parser_omp_declare_reduction_exprs
6093 : and tsubst_omp_udr.
6094 : Remove CLEANUP_STMT for data (omp_priv variable).
6095 : Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
6096 : DECL_EXPR. */
6097 :
6098 : tree
6099 4726 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
6100 : {
6101 4726 : if (TYPE_P (*tp))
6102 18 : *walk_subtrees = 0;
6103 4708 : else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
6104 54 : *tp = CLEANUP_BODY (*tp);
6105 4654 : else if (TREE_CODE (*tp) == DECL_EXPR)
6106 : {
6107 336 : tree decl = DECL_EXPR_DECL (*tp);
6108 336 : if (!processing_template_decl
6109 280 : && decl == (tree) data
6110 280 : && DECL_INITIAL (decl)
6111 437 : && DECL_INITIAL (decl) != error_mark_node)
6112 : {
6113 101 : tree list = NULL_TREE;
6114 101 : append_to_statement_list_force (*tp, &list);
6115 101 : tree init_expr = build2 (INIT_EXPR, void_type_node,
6116 101 : decl, DECL_INITIAL (decl));
6117 101 : DECL_INITIAL (decl) = NULL_TREE;
6118 101 : append_to_statement_list_force (init_expr, &list);
6119 101 : *tp = list;
6120 : }
6121 : }
6122 4726 : return NULL_TREE;
6123 : }
6124 :
6125 : /* Data passed from cp_check_omp_declare_reduction to
6126 : cp_check_omp_declare_reduction_r. */
6127 :
6128 : struct cp_check_omp_declare_reduction_data
6129 : {
6130 : location_t loc;
6131 : tree stmts[7];
6132 : bool combiner_p;
6133 : };
6134 :
6135 : /* Helper function for cp_check_omp_declare_reduction, called via
6136 : cp_walk_tree. */
6137 :
6138 : static tree
6139 17171 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
6140 : {
6141 17171 : struct cp_check_omp_declare_reduction_data *udr_data
6142 : = (struct cp_check_omp_declare_reduction_data *) data;
6143 13966 : if (SSA_VAR_P (*tp)
6144 3205 : && !DECL_ARTIFICIAL (*tp)
6145 300 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
6146 17471 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
6147 : {
6148 180 : location_t loc = udr_data->loc;
6149 180 : if (udr_data->combiner_p)
6150 60 : error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
6151 : "variable %qD which is not %<omp_out%> nor %<omp_in%>",
6152 : *tp);
6153 : else
6154 120 : error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
6155 : "to variable %qD which is not %<omp_priv%> nor "
6156 : "%<omp_orig%>",
6157 : *tp);
6158 180 : return *tp;
6159 : }
6160 : return NULL_TREE;
6161 : }
6162 :
6163 : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
6164 :
6165 : bool
6166 1357 : cp_check_omp_declare_reduction (tree udr)
6167 : {
6168 1357 : tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
6169 1357 : gcc_assert (TYPE_REF_P (type));
6170 1357 : type = TREE_TYPE (type);
6171 1357 : int i;
6172 1357 : location_t loc = DECL_SOURCE_LOCATION (udr);
6173 :
6174 1357 : if (type == error_mark_node)
6175 : return false;
6176 1357 : if (ARITHMETIC_TYPE_P (type))
6177 : {
6178 : static enum tree_code predef_codes[]
6179 : = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
6180 : BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
6181 4086 : for (i = 0; i < 8; i++)
6182 : {
6183 3640 : tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
6184 3640 : const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
6185 3640 : const char *n2 = IDENTIFIER_POINTER (id);
6186 3640 : if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
6187 3640 : && (n1[IDENTIFIER_LENGTH (id)] == '~'
6188 0 : || n1[IDENTIFIER_LENGTH (id)] == '\0'))
6189 : break;
6190 : }
6191 :
6192 470 : if (i == 8
6193 446 : && TREE_CODE (type) != COMPLEX_EXPR)
6194 : {
6195 446 : const char prefix_minmax[] = "omp declare reduction m";
6196 446 : size_t prefix_size = sizeof (prefix_minmax) - 1;
6197 446 : const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
6198 446 : if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
6199 : prefix_minmax, prefix_size) == 0
6200 12 : && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
6201 4 : || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
6202 458 : && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
6203 8 : i = 0;
6204 : }
6205 470 : if (i < 8)
6206 : {
6207 32 : error_at (loc, "predeclared arithmetic type %qT in "
6208 : "%<#pragma omp declare reduction%>", type);
6209 32 : return false;
6210 : }
6211 : }
6212 887 : else if (FUNC_OR_METHOD_TYPE_P (type)
6213 871 : || TREE_CODE (type) == ARRAY_TYPE)
6214 : {
6215 32 : error_at (loc, "function or array type %qT in "
6216 : "%<#pragma omp declare reduction%>", type);
6217 32 : return false;
6218 : }
6219 855 : else if (TYPE_REF_P (type))
6220 : {
6221 0 : error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
6222 : type);
6223 0 : return false;
6224 : }
6225 855 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
6226 : {
6227 32 : error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
6228 : "type %qT in %<#pragma omp declare reduction%>", type);
6229 32 : return false;
6230 : }
6231 :
6232 1261 : tree body = DECL_SAVED_TREE (udr);
6233 1261 : if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
6234 : return true;
6235 :
6236 1031 : tree_stmt_iterator tsi;
6237 1031 : struct cp_check_omp_declare_reduction_data data;
6238 1031 : memset (data.stmts, 0, sizeof data.stmts);
6239 1031 : for (i = 0, tsi = tsi_start (body);
6240 5384 : i < 7 && !tsi_end_p (tsi);
6241 5617 : i++, tsi_next (&tsi))
6242 4586 : data.stmts[i] = tsi_stmt (tsi);
6243 1031 : data.loc = loc;
6244 1031 : gcc_assert (tsi_end_p (tsi));
6245 1031 : if (i >= 3)
6246 : {
6247 1031 : gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
6248 : && TREE_CODE (data.stmts[1]) == DECL_EXPR);
6249 1031 : if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
6250 : return true;
6251 971 : data.combiner_p = true;
6252 971 : if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
6253 : &data, NULL))
6254 60 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
6255 : }
6256 971 : if (i >= 6)
6257 : {
6258 380 : gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
6259 : && TREE_CODE (data.stmts[4]) == DECL_EXPR);
6260 380 : data.combiner_p = false;
6261 380 : if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
6262 : &data, NULL)
6263 380 : || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
6264 : cp_check_omp_declare_reduction_r, &data, NULL))
6265 120 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */);
6266 380 : if (i == 7)
6267 213 : gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
6268 : }
6269 : return true;
6270 : }
6271 :
6272 : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
6273 : an inline call. But, remap
6274 : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
6275 : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
6276 :
6277 : static tree
6278 2280 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
6279 : tree decl, tree placeholder)
6280 : {
6281 2280 : copy_body_data id;
6282 2280 : hash_map<tree, tree> decl_map;
6283 :
6284 2280 : decl_map.put (omp_decl1, placeholder);
6285 2280 : decl_map.put (omp_decl2, decl);
6286 2280 : memset (&id, 0, sizeof (id));
6287 2280 : id.src_fn = DECL_CONTEXT (omp_decl1);
6288 2280 : id.dst_fn = current_function_decl;
6289 2280 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
6290 2280 : id.decl_map = &decl_map;
6291 :
6292 2280 : id.copy_decl = copy_decl_no_change;
6293 2280 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
6294 2280 : id.transform_new_cfg = true;
6295 2280 : id.transform_return_to_modify = false;
6296 2280 : id.eh_lp_nr = 0;
6297 2280 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
6298 2280 : return stmt;
6299 2280 : }
6300 :
6301 : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
6302 : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
6303 :
6304 : static tree
6305 15217 : find_omp_placeholder_r (tree *tp, int *, void *data)
6306 : {
6307 15217 : if (*tp == (tree) data)
6308 275 : return *tp;
6309 : return NULL_TREE;
6310 : }
6311 :
6312 : /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
6313 : Return true if there is some error and the clause should be removed. */
6314 :
6315 : static bool
6316 9399 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
6317 : {
6318 9399 : tree t = OMP_CLAUSE_DECL (c);
6319 9399 : bool predefined = false;
6320 9399 : if (TREE_CODE (t) == TREE_LIST)
6321 : {
6322 0 : gcc_assert (processing_template_decl);
6323 : return false;
6324 : }
6325 9399 : tree type = TREE_TYPE (t);
6326 9399 : if (TREE_CODE (t) == MEM_REF)
6327 1841 : type = TREE_TYPE (type);
6328 9399 : if (TYPE_REF_P (type))
6329 620 : type = TREE_TYPE (type);
6330 9399 : if (TREE_CODE (type) == ARRAY_TYPE)
6331 : {
6332 422 : tree oatype = type;
6333 422 : gcc_assert (TREE_CODE (t) != MEM_REF);
6334 848 : while (TREE_CODE (type) == ARRAY_TYPE)
6335 426 : type = TREE_TYPE (type);
6336 422 : if (!processing_template_decl)
6337 : {
6338 301 : t = require_complete_type (t);
6339 301 : if (t == error_mark_node
6340 301 : || !complete_type_or_else (oatype, NULL_TREE))
6341 12 : return true;
6342 289 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
6343 : TYPE_SIZE_UNIT (type));
6344 289 : if (integer_zerop (size))
6345 : {
6346 8 : error_at (OMP_CLAUSE_LOCATION (c),
6347 : "%qE in %<reduction%> clause is a zero size array",
6348 : omp_clause_printable_decl (t));
6349 4 : return true;
6350 : }
6351 285 : size = size_binop (MINUS_EXPR, size, size_one_node);
6352 285 : size = save_expr (size);
6353 285 : tree index_type = build_index_type (size);
6354 285 : tree atype = build_array_type (type, index_type);
6355 285 : tree ptype = build_pointer_type (type);
6356 285 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6357 170 : t = build_fold_addr_expr (t);
6358 285 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
6359 285 : OMP_CLAUSE_DECL (c) = t;
6360 : }
6361 : }
6362 9383 : if (type == error_mark_node)
6363 : return true;
6364 9379 : else if (ARITHMETIC_TYPE_P (type))
6365 8042 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
6366 : {
6367 : case PLUS_EXPR:
6368 : case MULT_EXPR:
6369 : case MINUS_EXPR:
6370 : case TRUTH_ANDIF_EXPR:
6371 : case TRUTH_ORIF_EXPR:
6372 : predefined = true;
6373 : break;
6374 238 : case MIN_EXPR:
6375 238 : case MAX_EXPR:
6376 238 : if (TREE_CODE (type) == COMPLEX_TYPE)
6377 : break;
6378 : predefined = true;
6379 : break;
6380 104 : case BIT_AND_EXPR:
6381 104 : case BIT_IOR_EXPR:
6382 104 : case BIT_XOR_EXPR:
6383 104 : if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
6384 : break;
6385 : predefined = true;
6386 : break;
6387 : default:
6388 : break;
6389 : }
6390 1337 : else if (TYPE_READONLY (type))
6391 : {
6392 24 : error_at (OMP_CLAUSE_LOCATION (c),
6393 : "%qE has const type for %<reduction%>",
6394 : omp_clause_printable_decl (t));
6395 12 : return true;
6396 : }
6397 1325 : else if (!processing_template_decl)
6398 : {
6399 1090 : t = require_complete_type (t);
6400 1090 : if (t == error_mark_node)
6401 : return true;
6402 1090 : OMP_CLAUSE_DECL (c) = t;
6403 : }
6404 :
6405 1090 : if (predefined)
6406 : {
6407 7796 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
6408 7796 : return false;
6409 : }
6410 1571 : else if (processing_template_decl)
6411 : {
6412 245 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
6413 : return true;
6414 : return false;
6415 : }
6416 :
6417 1326 : tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
6418 :
6419 1326 : type = TYPE_MAIN_VARIANT (type);
6420 1326 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
6421 1326 : if (id == NULL_TREE)
6422 970 : id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
6423 : NULL_TREE, NULL_TREE);
6424 1326 : id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
6425 1326 : if (id)
6426 : {
6427 1266 : if (id == error_mark_node)
6428 : return true;
6429 1258 : mark_used (id);
6430 1258 : tree body = DECL_SAVED_TREE (id);
6431 1258 : if (!body)
6432 : return true;
6433 1254 : if (TREE_CODE (body) == STATEMENT_LIST)
6434 : {
6435 1254 : tree_stmt_iterator tsi;
6436 1254 : tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
6437 1254 : int i;
6438 1254 : tree stmts[7];
6439 1254 : tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
6440 1254 : atype = TREE_TYPE (atype);
6441 1254 : bool need_static_cast = !same_type_p (type, atype);
6442 1254 : memset (stmts, 0, sizeof stmts);
6443 1254 : for (i = 0, tsi = tsi_start (body);
6444 8106 : i < 7 && !tsi_end_p (tsi);
6445 8835 : i++, tsi_next (&tsi))
6446 7581 : stmts[i] = tsi_stmt (tsi);
6447 1254 : gcc_assert (tsi_end_p (tsi));
6448 :
6449 1254 : if (i >= 3)
6450 : {
6451 1254 : gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
6452 : && TREE_CODE (stmts[1]) == DECL_EXPR);
6453 1254 : placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
6454 1254 : DECL_ARTIFICIAL (placeholder) = 1;
6455 1254 : DECL_IGNORED_P (placeholder) = 1;
6456 1254 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
6457 1254 : if (TREE_CODE (t) == MEM_REF)
6458 : {
6459 602 : decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
6460 : type);
6461 602 : DECL_ARTIFICIAL (decl_placeholder) = 1;
6462 602 : DECL_IGNORED_P (decl_placeholder) = 1;
6463 602 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
6464 : }
6465 1254 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
6466 285 : cxx_mark_addressable (placeholder);
6467 1254 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
6468 1254 : && (decl_placeholder
6469 149 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
6470 372 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
6471 118 : : OMP_CLAUSE_DECL (c));
6472 1254 : tree omp_out = placeholder;
6473 1254 : tree omp_in = decl_placeholder ? decl_placeholder
6474 652 : : convert_from_reference (OMP_CLAUSE_DECL (c));
6475 1254 : if (need_static_cast)
6476 : {
6477 8 : tree rtype = build_reference_type (atype);
6478 8 : omp_out = build_static_cast (input_location,
6479 : rtype, omp_out,
6480 : tf_warning_or_error);
6481 8 : omp_in = build_static_cast (input_location,
6482 : rtype, omp_in,
6483 : tf_warning_or_error);
6484 8 : if (omp_out == error_mark_node || omp_in == error_mark_node)
6485 4 : return true;
6486 8 : omp_out = convert_from_reference (omp_out);
6487 8 : omp_in = convert_from_reference (omp_in);
6488 : }
6489 1254 : OMP_CLAUSE_REDUCTION_MERGE (c)
6490 2508 : = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
6491 1254 : DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
6492 : }
6493 1254 : if (i >= 6)
6494 : {
6495 1030 : gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
6496 : && TREE_CODE (stmts[4]) == DECL_EXPR);
6497 1030 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
6498 1030 : && (decl_placeholder
6499 250 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
6500 880 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
6501 188 : : OMP_CLAUSE_DECL (c));
6502 1030 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
6503 217 : cxx_mark_addressable (placeholder);
6504 1030 : tree omp_priv = decl_placeholder ? decl_placeholder
6505 454 : : convert_from_reference (OMP_CLAUSE_DECL (c));
6506 1030 : tree omp_orig = placeholder;
6507 1030 : if (need_static_cast)
6508 : {
6509 6 : if (i == 7)
6510 : {
6511 4 : error_at (OMP_CLAUSE_LOCATION (c),
6512 : "user defined reduction with constructor "
6513 : "initializer for base class %qT", atype);
6514 4 : return true;
6515 : }
6516 2 : tree rtype = build_reference_type (atype);
6517 2 : omp_priv = build_static_cast (input_location,
6518 : rtype, omp_priv,
6519 : tf_warning_or_error);
6520 2 : omp_orig = build_static_cast (input_location,
6521 : rtype, omp_orig,
6522 : tf_warning_or_error);
6523 2 : if (omp_priv == error_mark_node
6524 2 : || omp_orig == error_mark_node)
6525 : return true;
6526 2 : omp_priv = convert_from_reference (omp_priv);
6527 2 : omp_orig = convert_from_reference (omp_orig);
6528 : }
6529 1026 : if (i == 6)
6530 301 : *need_default_ctor = true;
6531 1026 : OMP_CLAUSE_REDUCTION_INIT (c)
6532 1026 : = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
6533 1026 : DECL_EXPR_DECL (stmts[3]),
6534 : omp_priv, omp_orig);
6535 1026 : if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
6536 : find_omp_placeholder_r, placeholder, NULL))
6537 239 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
6538 : }
6539 224 : else if (i >= 3)
6540 : {
6541 224 : if (CLASS_TYPE_P (type) && !pod_type_p (type))
6542 206 : *need_default_ctor = true;
6543 : else
6544 : {
6545 18 : tree init;
6546 18 : tree v = decl_placeholder ? decl_placeholder
6547 18 : : convert_from_reference (t);
6548 18 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
6549 8 : init = build_constructor (TREE_TYPE (v), NULL);
6550 : else
6551 10 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
6552 36 : OMP_CLAUSE_REDUCTION_INIT (c)
6553 36 : = cp_build_init_expr (v, init);
6554 : }
6555 : }
6556 : }
6557 : }
6558 1310 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
6559 1250 : *need_dtor = true;
6560 : else
6561 : {
6562 120 : error_at (OMP_CLAUSE_LOCATION (c),
6563 : "user defined reduction not found for %qE",
6564 : omp_clause_printable_decl (t));
6565 60 : return true;
6566 : }
6567 1250 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
6568 602 : gcc_assert (TYPE_SIZE_UNIT (type)
6569 : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
6570 : return false;
6571 : }
6572 :
6573 : /* Called from finish_struct_1. linear(this) or linear(this:step)
6574 : clauses might not be finalized yet because the class has been incomplete
6575 : when parsing #pragma omp declare simd methods. Fix those up now. */
6576 :
6577 : void
6578 23141 : finish_omp_declare_simd_methods (tree t)
6579 : {
6580 23141 : if (processing_template_decl)
6581 : return;
6582 :
6583 166970 : for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
6584 : {
6585 236187 : if (TREE_CODE (x) == USING_DECL
6586 143829 : || !DECL_NONSTATIC_MEMBER_FUNCTION_P (x))
6587 92358 : continue;
6588 51471 : tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
6589 51605 : if (!ods || !TREE_VALUE (ods))
6590 51337 : continue;
6591 453 : for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
6592 319 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
6593 83 : && integer_zerop (OMP_CLAUSE_DECL (c))
6594 24 : && OMP_CLAUSE_LINEAR_STEP (c)
6595 343 : && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
6596 : {
6597 24 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
6598 24 : s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
6599 24 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
6600 24 : sizetype, s, TYPE_SIZE_UNIT (t));
6601 24 : OMP_CLAUSE_LINEAR_STEP (c) = s;
6602 : }
6603 : }
6604 : }
6605 :
6606 : /* Adjust sink depend/doacross clause to take into account pointer offsets.
6607 :
6608 : Return TRUE if there was a problem processing the offset, and the
6609 : whole clause should be removed. */
6610 :
6611 : static bool
6612 327 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
6613 : {
6614 327 : tree t = OMP_CLAUSE_DECL (sink_clause);
6615 327 : gcc_assert (TREE_CODE (t) == TREE_LIST);
6616 :
6617 : /* Make sure we don't adjust things twice for templates. */
6618 327 : if (processing_template_decl)
6619 : return false;
6620 :
6621 734 : for (; t; t = TREE_CHAIN (t))
6622 : {
6623 431 : tree decl = TREE_VALUE (t);
6624 431 : if (TYPE_PTR_P (TREE_TYPE (decl)))
6625 : {
6626 8 : tree offset = TREE_PURPOSE (t);
6627 8 : bool neg = wi::neg_p (wi::to_wide (offset));
6628 8 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
6629 8 : decl = mark_rvalue_use (decl);
6630 8 : decl = convert_from_reference (decl);
6631 16 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
6632 : neg ? MINUS_EXPR : PLUS_EXPR,
6633 : decl, offset);
6634 8 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
6635 : MINUS_EXPR, sizetype,
6636 : fold_convert (sizetype, t2),
6637 : fold_convert (sizetype, decl));
6638 8 : if (t2 == error_mark_node)
6639 : return true;
6640 8 : TREE_PURPOSE (t) = t2;
6641 : }
6642 : }
6643 : return false;
6644 : }
6645 :
6646 : /* Finish OpenMP iterators ITER. Return true if they are errorneous
6647 : and clauses containing them should be removed. */
6648 :
6649 : static bool
6650 680 : cp_omp_finish_iterators (tree iter)
6651 : {
6652 680 : bool ret = false;
6653 1503 : for (tree it = iter; it; it = TREE_CHAIN (it))
6654 : {
6655 823 : tree var = TREE_VEC_ELT (it, 0);
6656 823 : tree begin = TREE_VEC_ELT (it, 1);
6657 823 : tree end = TREE_VEC_ELT (it, 2);
6658 823 : tree step = TREE_VEC_ELT (it, 3);
6659 823 : tree orig_step;
6660 823 : tree type = TREE_TYPE (var);
6661 823 : location_t loc = DECL_SOURCE_LOCATION (var);
6662 823 : if (type == error_mark_node)
6663 : {
6664 0 : ret = true;
6665 0 : continue;
6666 : }
6667 823 : if (type_dependent_expression_p (var))
6668 76 : continue;
6669 747 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
6670 : {
6671 36 : error_at (loc, "iterator %qD has neither integral nor pointer type",
6672 : var);
6673 36 : ret = true;
6674 36 : continue;
6675 : }
6676 711 : else if (TYPE_READONLY (type))
6677 : {
6678 32 : error_at (loc, "iterator %qD has const qualified type", var);
6679 32 : ret = true;
6680 32 : continue;
6681 : }
6682 679 : if (type_dependent_expression_p (begin)
6683 667 : || type_dependent_expression_p (end)
6684 1346 : || type_dependent_expression_p (step))
6685 20 : continue;
6686 659 : else if (error_operand_p (step))
6687 : {
6688 0 : ret = true;
6689 0 : continue;
6690 : }
6691 659 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
6692 : {
6693 44 : error_at (EXPR_LOC_OR_LOC (step, loc),
6694 : "iterator step with non-integral type");
6695 28 : ret = true;
6696 28 : continue;
6697 : }
6698 :
6699 631 : begin = mark_rvalue_use (begin);
6700 631 : end = mark_rvalue_use (end);
6701 631 : step = mark_rvalue_use (step);
6702 631 : begin = cp_build_c_cast (input_location, type, begin,
6703 : tf_warning_or_error);
6704 631 : end = cp_build_c_cast (input_location, type, end,
6705 : tf_warning_or_error);
6706 631 : orig_step = step;
6707 631 : if (!processing_template_decl)
6708 531 : step = orig_step = save_expr (step);
6709 631 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
6710 631 : step = cp_build_c_cast (input_location, stype, step,
6711 : tf_warning_or_error);
6712 631 : if (POINTER_TYPE_P (type) && !processing_template_decl)
6713 : {
6714 87 : begin = save_expr (begin);
6715 87 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
6716 87 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
6717 : fold_convert (sizetype, step),
6718 : fold_convert (sizetype, begin));
6719 87 : step = fold_convert (ssizetype, step);
6720 : }
6721 631 : if (!processing_template_decl)
6722 : {
6723 531 : begin = maybe_constant_value (begin);
6724 531 : end = maybe_constant_value (end);
6725 531 : step = maybe_constant_value (step);
6726 531 : orig_step = maybe_constant_value (orig_step);
6727 : }
6728 631 : if (integer_zerop (step))
6729 : {
6730 36 : error_at (loc, "iterator %qD has zero step", var);
6731 36 : ret = true;
6732 36 : continue;
6733 : }
6734 :
6735 595 : if (begin == error_mark_node
6736 583 : || end == error_mark_node
6737 571 : || step == error_mark_node
6738 571 : || orig_step == error_mark_node)
6739 : {
6740 24 : ret = true;
6741 24 : continue;
6742 : }
6743 :
6744 571 : if (!processing_template_decl)
6745 : {
6746 471 : begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
6747 471 : end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
6748 471 : step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
6749 471 : orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
6750 : orig_step);
6751 : }
6752 571 : hash_set<tree> pset;
6753 571 : tree it2;
6754 679 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
6755 : {
6756 144 : tree var2 = TREE_VEC_ELT (it2, 0);
6757 144 : tree begin2 = TREE_VEC_ELT (it2, 1);
6758 144 : tree end2 = TREE_VEC_ELT (it2, 2);
6759 144 : tree step2 = TREE_VEC_ELT (it2, 3);
6760 144 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
6761 144 : if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
6762 : {
6763 12 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
6764 : "begin expression refers to outer iterator %qD", var);
6765 48 : break;
6766 : }
6767 132 : else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
6768 : {
6769 12 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
6770 : "end expression refers to outer iterator %qD", var);
6771 12 : break;
6772 : }
6773 120 : else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
6774 : {
6775 12 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
6776 : "step expression refers to outer iterator %qD", var);
6777 12 : break;
6778 : }
6779 : }
6780 571 : if (it2)
6781 : {
6782 36 : ret = true;
6783 36 : continue;
6784 : }
6785 535 : TREE_VEC_ELT (it, 1) = begin;
6786 535 : TREE_VEC_ELT (it, 2) = end;
6787 535 : if (processing_template_decl)
6788 92 : TREE_VEC_ELT (it, 3) = orig_step;
6789 : else
6790 : {
6791 443 : TREE_VEC_ELT (it, 3) = step;
6792 443 : TREE_VEC_ELT (it, 4) = orig_step;
6793 : }
6794 823 : }
6795 680 : return ret;
6796 : }
6797 :
6798 : /* Ensure that pointers are used in OpenACC attach and detach clauses.
6799 : Return true if an error has been detected. */
6800 :
6801 : static bool
6802 17767 : cp_oacc_check_attachments (tree c)
6803 : {
6804 17767 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6805 : return false;
6806 :
6807 : /* OpenACC attach / detach clauses must be pointers. */
6808 13524 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
6809 13524 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
6810 : {
6811 206 : tree t = OMP_CLAUSE_DECL (c);
6812 206 : tree type;
6813 :
6814 254 : while (TREE_CODE (t) == TREE_LIST)
6815 48 : t = TREE_CHAIN (t);
6816 :
6817 206 : type = TREE_TYPE (t);
6818 :
6819 206 : if (TREE_CODE (type) == REFERENCE_TYPE)
6820 48 : type = TREE_TYPE (type);
6821 :
6822 206 : if (TREE_CODE (type) != POINTER_TYPE)
6823 : {
6824 48 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
6825 : user_omp_clause_code_name (c, true));
6826 48 : return true;
6827 : }
6828 : }
6829 :
6830 : return false;
6831 : }
6832 :
6833 : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
6834 : Remove any elements from the list that are invalid. */
6835 :
6836 : tree
6837 64144 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
6838 : {
6839 64144 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
6840 64144 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
6841 64144 : bitmap_head oacc_reduction_head, is_on_device_head;
6842 64144 : tree c, t, *pc;
6843 64144 : tree safelen = NULL_TREE;
6844 64144 : bool branch_seen = false;
6845 64144 : bool copyprivate_seen = false;
6846 64144 : bool ordered_seen = false;
6847 64144 : bool order_seen = false;
6848 64144 : bool schedule_seen = false;
6849 64144 : bool oacc_async = false;
6850 64144 : bool indir_component_ref_p = false;
6851 64144 : tree last_iterators = NULL_TREE;
6852 64144 : bool last_iterators_remove = false;
6853 : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
6854 : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
6855 64144 : int reduction_seen = 0;
6856 64144 : bool allocate_seen = false;
6857 64144 : tree detach_seen = NULL_TREE;
6858 64144 : bool mergeable_seen = false;
6859 64144 : bool implicit_moved = false;
6860 64144 : bool target_in_reduction_seen = false;
6861 :
6862 64144 : bitmap_obstack_initialize (NULL);
6863 64144 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
6864 64144 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
6865 64144 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
6866 64144 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
6867 : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
6868 64144 : bitmap_initialize (&map_head, &bitmap_default_obstack);
6869 64144 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
6870 64144 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
6871 : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
6872 : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
6873 64144 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
6874 64144 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
6875 :
6876 64144 : if (ort & C_ORT_ACC)
6877 31110 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
6878 17545 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
6879 : {
6880 : oacc_async = true;
6881 : break;
6882 : }
6883 :
6884 64144 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
6885 :
6886 163608 : for (pc = &clauses, c = clauses; c ; c = *pc)
6887 : {
6888 99464 : bool remove = false;
6889 99464 : bool field_ok = false;
6890 :
6891 : /* We've reached the end of a list of expanded nodes. Reset the group
6892 : start pointer. */
6893 99464 : if (c == grp_sentinel)
6894 1958 : grp_start_p = NULL;
6895 :
6896 99464 : switch (OMP_CLAUSE_CODE (c))
6897 : {
6898 2286 : case OMP_CLAUSE_SHARED:
6899 2286 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
6900 2286 : goto check_dup_generic;
6901 2777 : case OMP_CLAUSE_PRIVATE:
6902 2777 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
6903 2777 : goto check_dup_generic;
6904 7949 : case OMP_CLAUSE_REDUCTION:
6905 7949 : if (reduction_seen == 0)
6906 6870 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
6907 1079 : else if (reduction_seen != -2
6908 2158 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
6909 1079 : ? -1 : 1))
6910 : {
6911 8 : error_at (OMP_CLAUSE_LOCATION (c),
6912 : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
6913 : "on the same construct");
6914 8 : reduction_seen = -2;
6915 : }
6916 : /* FALLTHRU */
6917 10143 : case OMP_CLAUSE_IN_REDUCTION:
6918 10143 : case OMP_CLAUSE_TASK_REDUCTION:
6919 10143 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
6920 10143 : t = OMP_CLAUSE_DECL (c);
6921 10143 : if (TREE_CODE (t) == TREE_LIST)
6922 : {
6923 2564 : if (handle_omp_array_sections (c, ort))
6924 : {
6925 : remove = true;
6926 : break;
6927 : }
6928 2508 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6929 2508 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
6930 : {
6931 4 : error_at (OMP_CLAUSE_LOCATION (c),
6932 : "%<inscan%> %<reduction%> clause with array "
6933 : "section");
6934 4 : remove = true;
6935 4 : break;
6936 : }
6937 2504 : if (TREE_CODE (t) == TREE_LIST)
6938 : {
6939 5358 : while (TREE_CODE (t) == TREE_LIST)
6940 2854 : t = TREE_CHAIN (t);
6941 : }
6942 : else
6943 : {
6944 0 : gcc_assert (TREE_CODE (t) == MEM_REF);
6945 0 : t = TREE_OPERAND (t, 0);
6946 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
6947 0 : t = TREE_OPERAND (t, 0);
6948 0 : if (TREE_CODE (t) == ADDR_EXPR
6949 0 : || INDIRECT_REF_P (t))
6950 0 : t = TREE_OPERAND (t, 0);
6951 : }
6952 2504 : tree n = omp_clause_decl_field (t);
6953 2504 : if (n)
6954 59 : t = n;
6955 2504 : goto check_dup_generic_t;
6956 : }
6957 7579 : if (oacc_async)
6958 7 : cxx_mark_addressable (t);
6959 7579 : goto check_dup_generic;
6960 116 : case OMP_CLAUSE_COPYPRIVATE:
6961 116 : copyprivate_seen = true;
6962 116 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
6963 116 : goto check_dup_generic;
6964 305 : case OMP_CLAUSE_COPYIN:
6965 305 : goto check_dup_generic;
6966 1945 : case OMP_CLAUSE_LINEAR:
6967 1945 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
6968 1945 : t = OMP_CLAUSE_DECL (c);
6969 1945 : if (ort != C_ORT_OMP_DECLARE_SIMD
6970 1945 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
6971 : {
6972 109 : if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
6973 : {
6974 56 : error_at (OMP_CLAUSE_LOCATION (c),
6975 : "modifier should not be specified in %<linear%> "
6976 : "clause on %<simd%> or %<for%> constructs when "
6977 : "not using OpenMP 5.2 modifiers");
6978 56 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
6979 : }
6980 53 : else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
6981 : {
6982 24 : error_at (OMP_CLAUSE_LOCATION (c),
6983 : "modifier other than %<val%> specified in "
6984 : "%<linear%> clause on %<simd%> or %<for%> "
6985 : "constructs when using OpenMP 5.2 modifiers");
6986 24 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
6987 : }
6988 : }
6989 1216 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
6990 3068 : && !type_dependent_expression_p (t))
6991 : {
6992 1812 : tree type = TREE_TYPE (t);
6993 1812 : if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
6994 1720 : || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
6995 1889 : && !TYPE_REF_P (type))
6996 : {
6997 64 : error_at (OMP_CLAUSE_LOCATION (c),
6998 : "linear clause with %qs modifier applied to "
6999 : "non-reference variable with %qT type",
7000 16 : OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7001 16 : ? "ref" : "uval", TREE_TYPE (t));
7002 16 : remove = true;
7003 16 : break;
7004 : }
7005 1796 : if (TYPE_REF_P (type))
7006 331 : type = TREE_TYPE (type);
7007 1796 : if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
7008 : {
7009 1712 : if (!INTEGRAL_TYPE_P (type)
7010 112 : && !TYPE_PTR_P (type))
7011 : {
7012 24 : error_at (OMP_CLAUSE_LOCATION (c),
7013 : "linear clause applied to non-integral "
7014 : "non-pointer variable with %qT type",
7015 24 : TREE_TYPE (t));
7016 24 : remove = true;
7017 24 : break;
7018 : }
7019 : }
7020 : }
7021 1905 : t = OMP_CLAUSE_LINEAR_STEP (c);
7022 1905 : if (t == NULL_TREE)
7023 6 : t = integer_one_node;
7024 1905 : if (t == error_mark_node)
7025 : {
7026 : remove = true;
7027 : break;
7028 : }
7029 1905 : else if (!type_dependent_expression_p (t)
7030 1903 : && !INTEGRAL_TYPE_P (TREE_TYPE (t))
7031 1921 : && (ort != C_ORT_OMP_DECLARE_SIMD
7032 12 : || TREE_CODE (t) != PARM_DECL
7033 8 : || !TYPE_REF_P (TREE_TYPE (t))
7034 8 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
7035 : {
7036 8 : error_at (OMP_CLAUSE_LOCATION (c),
7037 : "linear step expression must be integral");
7038 8 : remove = true;
7039 8 : break;
7040 : }
7041 : else
7042 : {
7043 1897 : t = mark_rvalue_use (t);
7044 1897 : if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
7045 : {
7046 54 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
7047 54 : goto check_dup_generic;
7048 : }
7049 1843 : if (!processing_template_decl
7050 3520 : && (VAR_P (OMP_CLAUSE_DECL (c))
7051 986 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
7052 : {
7053 1606 : if (ort == C_ORT_OMP_DECLARE_SIMD)
7054 : {
7055 676 : t = maybe_constant_value (t);
7056 676 : if (TREE_CODE (t) != INTEGER_CST)
7057 : {
7058 8 : error_at (OMP_CLAUSE_LOCATION (c),
7059 : "%<linear%> clause step %qE is neither "
7060 : "constant nor a parameter", t);
7061 8 : remove = true;
7062 8 : break;
7063 : }
7064 : }
7065 1598 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7066 1598 : tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
7067 1598 : if (TYPE_REF_P (type))
7068 301 : type = TREE_TYPE (type);
7069 1598 : if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
7070 : {
7071 74 : type = build_pointer_type (type);
7072 74 : tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
7073 74 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
7074 : d, t);
7075 74 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
7076 : MINUS_EXPR, sizetype,
7077 : fold_convert (sizetype, t),
7078 : fold_convert (sizetype, d));
7079 74 : if (t == error_mark_node)
7080 : {
7081 : remove = true;
7082 : break;
7083 : }
7084 : }
7085 1524 : else if (TYPE_PTR_P (type)
7086 : /* Can't multiply the step yet if *this
7087 : is still incomplete type. */
7088 1524 : && (ort != C_ORT_OMP_DECLARE_SIMD
7089 60 : || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
7090 60 : || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
7091 40 : || DECL_NAME (OMP_CLAUSE_DECL (c))
7092 40 : != this_identifier
7093 40 : || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
7094 : {
7095 48 : tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
7096 48 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
7097 : d, t);
7098 48 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
7099 : MINUS_EXPR, sizetype,
7100 : fold_convert (sizetype, t),
7101 : fold_convert (sizetype, d));
7102 48 : if (t == error_mark_node)
7103 : {
7104 : remove = true;
7105 : break;
7106 : }
7107 : }
7108 : else
7109 1476 : t = fold_convert (type, t);
7110 : }
7111 1835 : OMP_CLAUSE_LINEAR_STEP (c) = t;
7112 : }
7113 1835 : goto check_dup_generic;
7114 15971 : check_dup_generic:
7115 15971 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
7116 15971 : if (t)
7117 : {
7118 178 : if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
7119 89 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
7120 : }
7121 : else
7122 15882 : t = OMP_CLAUSE_DECL (c);
7123 18770 : check_dup_generic_t:
7124 18770 : if (t == current_class_ptr
7125 18770 : && ((ort != C_ORT_OMP_DECLARE_SIMD && ort != C_ORT_ACC)
7126 126 : || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
7127 86 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
7128 : {
7129 32 : error_at (OMP_CLAUSE_LOCATION (c),
7130 : "%<this%> allowed in OpenMP only in %<declare simd%>"
7131 : " clauses");
7132 32 : remove = true;
7133 32 : break;
7134 : }
7135 18738 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
7136 636 : && (!field_ok || TREE_CODE (t) != FIELD_DECL))
7137 : {
7138 76 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
7139 : break;
7140 52 : if (DECL_P (t))
7141 20 : error_at (OMP_CLAUSE_LOCATION (c),
7142 : "%qD is not a variable in clause %qs", t,
7143 20 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
7144 : else
7145 32 : error_at (OMP_CLAUSE_LOCATION (c),
7146 : "%qE is not a variable in clause %qs", t,
7147 32 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
7148 : remove = true;
7149 : }
7150 18662 : else if ((ort == C_ORT_ACC
7151 2533 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
7152 16413 : || (ort == C_ORT_OMP
7153 13832 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
7154 13799 : || (OMP_CLAUSE_CODE (c)
7155 : == OMP_CLAUSE_USE_DEVICE_ADDR)))
7156 34953 : || (ort == C_ORT_OMP_TARGET
7157 942 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
7158 : {
7159 2667 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
7160 2667 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
7161 292 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
7162 : {
7163 8 : error_at (OMP_CLAUSE_LOCATION (c),
7164 : "%qD appears more than once in data-sharing "
7165 : "clauses", t);
7166 8 : remove = true;
7167 8 : break;
7168 : }
7169 2659 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
7170 288 : target_in_reduction_seen = true;
7171 2659 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
7172 : {
7173 8 : error_at (OMP_CLAUSE_LOCATION (c),
7174 : ort == C_ORT_ACC
7175 : ? "%qD appears more than once in reduction clauses"
7176 : : "%qD appears more than once in data clauses",
7177 : t);
7178 8 : remove = true;
7179 : }
7180 : else
7181 2651 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
7182 : }
7183 15995 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
7184 15899 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
7185 15895 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
7186 31890 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
7187 : {
7188 100 : error_at (OMP_CLAUSE_LOCATION (c),
7189 : "%qD appears more than once in data clauses", t);
7190 100 : remove = true;
7191 : }
7192 15895 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
7193 13165 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
7194 12882 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
7195 16434 : && bitmap_bit_p (&map_head, DECL_UID (t)))
7196 : {
7197 12 : if (ort == C_ORT_ACC)
7198 0 : error_at (OMP_CLAUSE_LOCATION (c),
7199 : "%qD appears more than once in data clauses", t);
7200 : else
7201 12 : error_at (OMP_CLAUSE_LOCATION (c),
7202 : "%qD appears both in data and map clauses", t);
7203 : remove = true;
7204 : }
7205 : else
7206 15883 : bitmap_set_bit (&generic_head, DECL_UID (t));
7207 18706 : if (!field_ok)
7208 : break;
7209 14218 : handle_field_decl:
7210 24028 : if (!remove
7211 23774 : && TREE_CODE (t) == FIELD_DECL
7212 25138 : && t == OMP_CLAUSE_DECL (c))
7213 : {
7214 862 : OMP_CLAUSE_DECL (c)
7215 862 : = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
7216 : == OMP_CLAUSE_SHARED));
7217 862 : if (OMP_CLAUSE_DECL (c) == error_mark_node)
7218 0 : remove = true;
7219 : }
7220 : break;
7221 :
7222 3863 : case OMP_CLAUSE_FIRSTPRIVATE:
7223 3863 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
7224 : {
7225 516 : move_implicit:
7226 516 : implicit_moved = true;
7227 : /* Move firstprivate and map clauses with
7228 : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
7229 : clauses chain. */
7230 516 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
7231 516 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
7232 3157 : while (*pc1)
7233 2641 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
7234 2641 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
7235 : {
7236 316 : *pc3 = *pc1;
7237 316 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
7238 316 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
7239 : }
7240 2325 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
7241 2325 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
7242 : {
7243 460 : *pc2 = *pc1;
7244 460 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
7245 460 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
7246 : }
7247 : else
7248 1865 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
7249 516 : *pc3 = NULL;
7250 516 : *pc2 = cl2;
7251 516 : *pc1 = cl1;
7252 516 : continue;
7253 516 : }
7254 3565 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
7255 3565 : if (t)
7256 58 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
7257 : else
7258 3507 : t = OMP_CLAUSE_DECL (c);
7259 3565 : if (ort != C_ORT_ACC && t == current_class_ptr)
7260 : {
7261 8 : error_at (OMP_CLAUSE_LOCATION (c),
7262 : "%<this%> allowed in OpenMP only in %<declare simd%>"
7263 : " clauses");
7264 8 : remove = true;
7265 8 : break;
7266 : }
7267 3557 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
7268 339 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
7269 339 : || TREE_CODE (t) != FIELD_DECL))
7270 : {
7271 53 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
7272 : break;
7273 24 : if (DECL_P (t))
7274 16 : error_at (OMP_CLAUSE_LOCATION (c),
7275 : "%qD is not a variable in clause %<firstprivate%>",
7276 : t);
7277 : else
7278 8 : error_at (OMP_CLAUSE_LOCATION (c),
7279 : "%qE is not a variable in clause %<firstprivate%>",
7280 : t);
7281 : remove = true;
7282 : }
7283 3504 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
7284 316 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
7285 3795 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
7286 : remove = true;
7287 3504 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
7288 3492 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
7289 6992 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
7290 : {
7291 20 : error_at (OMP_CLAUSE_LOCATION (c),
7292 : "%qD appears more than once in data clauses", t);
7293 20 : remove = true;
7294 : }
7295 3484 : else if (bitmap_bit_p (&map_head, DECL_UID (t)))
7296 : {
7297 28 : if (ort == C_ORT_ACC)
7298 0 : error_at (OMP_CLAUSE_LOCATION (c),
7299 : "%qD appears more than once in data clauses", t);
7300 28 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
7301 28 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
7302 : /* Silently drop the clause. */;
7303 : else
7304 24 : error_at (OMP_CLAUSE_LOCATION (c),
7305 : "%qD appears both in data and map clauses", t);
7306 : remove = true;
7307 : }
7308 : else
7309 3456 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
7310 3528 : goto handle_field_decl;
7311 :
7312 3218 : case OMP_CLAUSE_LASTPRIVATE:
7313 3218 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
7314 3218 : if (t)
7315 40 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
7316 : else
7317 3178 : t = OMP_CLAUSE_DECL (c);
7318 3218 : if (ort != C_ORT_ACC && t == current_class_ptr)
7319 : {
7320 8 : error_at (OMP_CLAUSE_LOCATION (c),
7321 : "%<this%> allowed in OpenMP only in %<declare simd%>"
7322 : " clauses");
7323 8 : remove = true;
7324 8 : break;
7325 : }
7326 3210 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
7327 319 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
7328 319 : || TREE_CODE (t) != FIELD_DECL))
7329 : {
7330 45 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
7331 : break;
7332 12 : if (DECL_P (t))
7333 4 : error_at (OMP_CLAUSE_LOCATION (c),
7334 : "%qD is not a variable in clause %<lastprivate%>",
7335 : t);
7336 : else
7337 8 : error_at (OMP_CLAUSE_LOCATION (c),
7338 : "%qE is not a variable in clause %<lastprivate%>",
7339 : t);
7340 : remove = true;
7341 : }
7342 3165 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
7343 3165 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
7344 : {
7345 16 : error_at (OMP_CLAUSE_LOCATION (c),
7346 : "%qD appears more than once in data clauses", t);
7347 16 : remove = true;
7348 : }
7349 : else
7350 3149 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
7351 3177 : goto handle_field_decl;
7352 :
7353 2363 : case OMP_CLAUSE_IF:
7354 2363 : t = OMP_CLAUSE_IF_EXPR (c);
7355 2363 : t = maybe_convert_cond (t);
7356 2363 : if (t == error_mark_node)
7357 : remove = true;
7358 2359 : else if (!processing_template_decl)
7359 2300 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7360 2363 : OMP_CLAUSE_IF_EXPR (c) = t;
7361 2363 : break;
7362 :
7363 317 : case OMP_CLAUSE_FINAL:
7364 317 : t = OMP_CLAUSE_FINAL_EXPR (c);
7365 317 : t = maybe_convert_cond (t);
7366 317 : if (t == error_mark_node)
7367 : remove = true;
7368 317 : else if (!processing_template_decl)
7369 309 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7370 317 : OMP_CLAUSE_FINAL_EXPR (c) = t;
7371 317 : break;
7372 :
7373 1442 : case OMP_CLAUSE_GANG:
7374 : /* Operand 1 is the gang static: argument. */
7375 1442 : t = OMP_CLAUSE_OPERAND (c, 1);
7376 1442 : if (t != NULL_TREE)
7377 : {
7378 136 : if (t == error_mark_node)
7379 : remove = true;
7380 136 : else if (!type_dependent_expression_p (t)
7381 136 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7382 : {
7383 8 : error_at (OMP_CLAUSE_LOCATION (c),
7384 : "%<gang%> static expression must be integral");
7385 8 : remove = true;
7386 : }
7387 : else
7388 : {
7389 128 : t = mark_rvalue_use (t);
7390 128 : if (!processing_template_decl)
7391 : {
7392 128 : t = maybe_constant_value (t);
7393 128 : if (TREE_CODE (t) == INTEGER_CST
7394 110 : && tree_int_cst_sgn (t) != 1
7395 181 : && t != integer_minus_one_node)
7396 : {
7397 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
7398 : "%<gang%> static value must be "
7399 : "positive");
7400 0 : t = integer_one_node;
7401 : }
7402 128 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7403 : }
7404 : }
7405 136 : OMP_CLAUSE_OPERAND (c, 1) = t;
7406 : }
7407 : /* Check operand 0, the num argument. */
7408 : /* FALLTHRU */
7409 :
7410 4070 : case OMP_CLAUSE_WORKER:
7411 4070 : case OMP_CLAUSE_VECTOR:
7412 4070 : if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
7413 : break;
7414 : /* FALLTHRU */
7415 :
7416 3348 : case OMP_CLAUSE_NUM_TASKS:
7417 3348 : case OMP_CLAUSE_NUM_TEAMS:
7418 3348 : case OMP_CLAUSE_NUM_THREADS:
7419 3348 : case OMP_CLAUSE_NUM_GANGS:
7420 3348 : case OMP_CLAUSE_NUM_WORKERS:
7421 3348 : case OMP_CLAUSE_VECTOR_LENGTH:
7422 3348 : t = OMP_CLAUSE_OPERAND (c, 0);
7423 3348 : if (t == error_mark_node)
7424 : remove = true;
7425 3348 : else if (!type_dependent_expression_p (t)
7426 3348 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7427 : {
7428 124 : switch (OMP_CLAUSE_CODE (c))
7429 : {
7430 16 : case OMP_CLAUSE_GANG:
7431 16 : error_at (OMP_CLAUSE_LOCATION (c),
7432 16 : "%<gang%> num expression must be integral"); break;
7433 16 : case OMP_CLAUSE_VECTOR:
7434 16 : error_at (OMP_CLAUSE_LOCATION (c),
7435 : "%<vector%> length expression must be integral");
7436 16 : break;
7437 16 : case OMP_CLAUSE_WORKER:
7438 16 : error_at (OMP_CLAUSE_LOCATION (c),
7439 : "%<worker%> num expression must be integral");
7440 16 : break;
7441 76 : default:
7442 76 : error_at (OMP_CLAUSE_LOCATION (c),
7443 : "%qs expression must be integral",
7444 76 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
7445 : }
7446 : remove = true;
7447 : }
7448 : else
7449 : {
7450 3224 : t = mark_rvalue_use (t);
7451 3224 : if (!processing_template_decl)
7452 : {
7453 2945 : t = maybe_constant_value (t);
7454 2945 : if (TREE_CODE (t) == INTEGER_CST
7455 2945 : && tree_int_cst_sgn (t) != 1)
7456 : {
7457 112 : switch (OMP_CLAUSE_CODE (c))
7458 : {
7459 4 : case OMP_CLAUSE_GANG:
7460 4 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
7461 : "%<gang%> num value must be positive");
7462 4 : break;
7463 0 : case OMP_CLAUSE_VECTOR:
7464 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
7465 : "%<vector%> length value must be "
7466 : "positive");
7467 0 : break;
7468 0 : case OMP_CLAUSE_WORKER:
7469 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
7470 : "%<worker%> num value must be "
7471 : "positive");
7472 0 : break;
7473 108 : default:
7474 108 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
7475 : "%qs value must be positive",
7476 : omp_clause_code_name
7477 108 : [OMP_CLAUSE_CODE (c)]);
7478 : }
7479 112 : t = integer_one_node;
7480 : }
7481 2945 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7482 : }
7483 3224 : OMP_CLAUSE_OPERAND (c, 0) = t;
7484 : }
7485 3348 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
7486 928 : && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
7487 3691 : && !remove)
7488 : {
7489 343 : t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
7490 343 : if (t == error_mark_node)
7491 : remove = true;
7492 343 : else if (!type_dependent_expression_p (t)
7493 343 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7494 : {
7495 0 : error_at (OMP_CLAUSE_LOCATION (c),
7496 : "%qs expression must be integral",
7497 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
7498 0 : remove = true;
7499 : }
7500 : else
7501 : {
7502 343 : t = mark_rvalue_use (t);
7503 343 : if (!processing_template_decl)
7504 : {
7505 255 : t = maybe_constant_value (t);
7506 255 : if (TREE_CODE (t) == INTEGER_CST
7507 255 : && tree_int_cst_sgn (t) != 1)
7508 : {
7509 24 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
7510 : "%qs value must be positive",
7511 : omp_clause_code_name
7512 24 : [OMP_CLAUSE_CODE (c)]);
7513 24 : t = NULL_TREE;
7514 : }
7515 : else
7516 231 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7517 255 : tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
7518 255 : if (t
7519 231 : && TREE_CODE (t) == INTEGER_CST
7520 53 : && TREE_CODE (upper) == INTEGER_CST
7521 304 : && tree_int_cst_lt (upper, t))
7522 : {
7523 24 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
7524 : "%<num_teams%> lower bound %qE bigger "
7525 : "than upper bound %qE", t, upper);
7526 24 : t = NULL_TREE;
7527 : }
7528 : }
7529 343 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
7530 : }
7531 : }
7532 : break;
7533 :
7534 4002 : case OMP_CLAUSE_SCHEDULE:
7535 4002 : t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
7536 4002 : if (t == NULL)
7537 : ;
7538 2165 : else if (t == error_mark_node)
7539 : remove = true;
7540 2165 : else if (!type_dependent_expression_p (t)
7541 2165 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7542 : {
7543 12 : error_at (OMP_CLAUSE_LOCATION (c),
7544 : "schedule chunk size expression must be integral");
7545 12 : remove = true;
7546 : }
7547 : else
7548 : {
7549 2153 : t = mark_rvalue_use (t);
7550 2153 : if (!processing_template_decl)
7551 : {
7552 2108 : t = maybe_constant_value (t);
7553 2108 : if (TREE_CODE (t) == INTEGER_CST
7554 2108 : && tree_int_cst_sgn (t) != 1)
7555 : {
7556 8 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
7557 : "chunk size value must be positive");
7558 8 : t = integer_one_node;
7559 : }
7560 2108 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7561 : }
7562 2153 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
7563 : }
7564 2165 : if (!remove)
7565 : schedule_seen = true;
7566 : break;
7567 :
7568 1399 : case OMP_CLAUSE_SIMDLEN:
7569 1399 : case OMP_CLAUSE_SAFELEN:
7570 1399 : t = OMP_CLAUSE_OPERAND (c, 0);
7571 1399 : if (t == error_mark_node)
7572 : remove = true;
7573 1399 : else if (!type_dependent_expression_p (t)
7574 1399 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7575 : {
7576 0 : error_at (OMP_CLAUSE_LOCATION (c),
7577 : "%qs length expression must be integral",
7578 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
7579 0 : remove = true;
7580 : }
7581 : else
7582 : {
7583 1399 : t = mark_rvalue_use (t);
7584 1399 : if (!processing_template_decl)
7585 : {
7586 1334 : t = maybe_constant_value (t);
7587 1334 : if (TREE_CODE (t) != INTEGER_CST
7588 1334 : || tree_int_cst_sgn (t) != 1)
7589 : {
7590 0 : error_at (OMP_CLAUSE_LOCATION (c),
7591 : "%qs length expression must be positive "
7592 : "constant integer expression",
7593 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
7594 0 : remove = true;
7595 : }
7596 : }
7597 1399 : OMP_CLAUSE_OPERAND (c, 0) = t;
7598 1399 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
7599 532 : safelen = c;
7600 : }
7601 : break;
7602 :
7603 426 : case OMP_CLAUSE_ASYNC:
7604 426 : t = OMP_CLAUSE_ASYNC_EXPR (c);
7605 426 : if (t == error_mark_node)
7606 : remove = true;
7607 406 : else if (!type_dependent_expression_p (t)
7608 406 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7609 : {
7610 16 : error_at (OMP_CLAUSE_LOCATION (c),
7611 : "%<async%> expression must be integral");
7612 16 : remove = true;
7613 : }
7614 : else
7615 : {
7616 390 : t = mark_rvalue_use (t);
7617 390 : if (!processing_template_decl)
7618 379 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7619 390 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
7620 : }
7621 : break;
7622 :
7623 240 : case OMP_CLAUSE_WAIT:
7624 240 : t = OMP_CLAUSE_WAIT_EXPR (c);
7625 240 : if (t == error_mark_node)
7626 : remove = true;
7627 240 : else if (!processing_template_decl)
7628 230 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7629 240 : OMP_CLAUSE_WAIT_EXPR (c) = t;
7630 240 : break;
7631 :
7632 768 : case OMP_CLAUSE_THREAD_LIMIT:
7633 768 : t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
7634 768 : if (t == error_mark_node)
7635 : remove = true;
7636 768 : else if (!type_dependent_expression_p (t)
7637 768 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7638 : {
7639 0 : error_at (OMP_CLAUSE_LOCATION (c),
7640 : "%<thread_limit%> expression must be integral");
7641 0 : remove = true;
7642 : }
7643 : else
7644 : {
7645 768 : t = mark_rvalue_use (t);
7646 768 : if (!processing_template_decl)
7647 : {
7648 696 : t = maybe_constant_value (t);
7649 696 : if (TREE_CODE (t) == INTEGER_CST
7650 696 : && tree_int_cst_sgn (t) != 1)
7651 : {
7652 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
7653 : "%<thread_limit%> value must be positive");
7654 0 : t = integer_one_node;
7655 : }
7656 696 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7657 : }
7658 768 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
7659 : }
7660 : break;
7661 :
7662 617 : case OMP_CLAUSE_DEVICE:
7663 617 : t = OMP_CLAUSE_DEVICE_ID (c);
7664 617 : if (t == error_mark_node)
7665 : remove = true;
7666 617 : else if (!type_dependent_expression_p (t)
7667 617 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7668 : {
7669 0 : error_at (OMP_CLAUSE_LOCATION (c),
7670 : "%<device%> id must be integral");
7671 0 : remove = true;
7672 : }
7673 617 : else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
7674 87 : && TREE_CODE (t) == INTEGER_CST
7675 696 : && !integer_onep (t))
7676 : {
7677 4 : error_at (OMP_CLAUSE_LOCATION (c),
7678 : "the %<device%> clause expression must evaluate to "
7679 : "%<1%>");
7680 4 : remove = true;
7681 : }
7682 : else
7683 : {
7684 613 : t = mark_rvalue_use (t);
7685 613 : if (!processing_template_decl)
7686 613 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7687 613 : OMP_CLAUSE_DEVICE_ID (c) = t;
7688 : }
7689 : break;
7690 :
7691 1901 : case OMP_CLAUSE_DIST_SCHEDULE:
7692 1901 : t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
7693 1901 : if (t == NULL)
7694 : ;
7695 1873 : else if (t == error_mark_node)
7696 : remove = true;
7697 1873 : else if (!type_dependent_expression_p (t)
7698 1873 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7699 : {
7700 0 : error_at (OMP_CLAUSE_LOCATION (c),
7701 : "%<dist_schedule%> chunk size expression must be "
7702 : "integral");
7703 0 : remove = true;
7704 : }
7705 : else
7706 : {
7707 1873 : t = mark_rvalue_use (t);
7708 1873 : if (!processing_template_decl)
7709 1873 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7710 1873 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
7711 : }
7712 : break;
7713 :
7714 942 : case OMP_CLAUSE_ALIGNED:
7715 942 : t = OMP_CLAUSE_DECL (c);
7716 942 : if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
7717 : {
7718 0 : error_at (OMP_CLAUSE_LOCATION (c),
7719 : "%<this%> allowed in OpenMP only in %<declare simd%>"
7720 : " clauses");
7721 0 : remove = true;
7722 0 : break;
7723 : }
7724 942 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
7725 : {
7726 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
7727 : break;
7728 0 : if (DECL_P (t))
7729 0 : error_at (OMP_CLAUSE_LOCATION (c),
7730 : "%qD is not a variable in %<aligned%> clause", t);
7731 : else
7732 0 : error_at (OMP_CLAUSE_LOCATION (c),
7733 : "%qE is not a variable in %<aligned%> clause", t);
7734 : remove = true;
7735 : }
7736 942 : else if (!type_dependent_expression_p (t)
7737 918 : && !TYPE_PTR_P (TREE_TYPE (t))
7738 136 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
7739 1012 : && (!TYPE_REF_P (TREE_TYPE (t))
7740 46 : || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
7741 34 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
7742 : != ARRAY_TYPE))))
7743 : {
7744 44 : error_at (OMP_CLAUSE_LOCATION (c),
7745 : "%qE in %<aligned%> clause is neither a pointer nor "
7746 : "an array nor a reference to pointer or array", t);
7747 44 : remove = true;
7748 : }
7749 898 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
7750 : {
7751 0 : error_at (OMP_CLAUSE_LOCATION (c),
7752 : "%qD appears more than once in %<aligned%> clauses",
7753 : t);
7754 0 : remove = true;
7755 : }
7756 : else
7757 898 : bitmap_set_bit (&aligned_head, DECL_UID (t));
7758 942 : t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
7759 942 : if (t == error_mark_node)
7760 : remove = true;
7761 942 : else if (t == NULL_TREE)
7762 : break;
7763 858 : else if (!type_dependent_expression_p (t)
7764 858 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7765 : {
7766 0 : error_at (OMP_CLAUSE_LOCATION (c),
7767 : "%<aligned%> clause alignment expression must "
7768 : "be integral");
7769 0 : remove = true;
7770 : }
7771 : else
7772 : {
7773 858 : t = mark_rvalue_use (t);
7774 858 : if (!processing_template_decl)
7775 : {
7776 786 : t = maybe_constant_value (t);
7777 786 : if (TREE_CODE (t) != INTEGER_CST
7778 786 : || tree_int_cst_sgn (t) != 1)
7779 : {
7780 0 : error_at (OMP_CLAUSE_LOCATION (c),
7781 : "%<aligned%> clause alignment expression must "
7782 : "be positive constant integer expression");
7783 0 : remove = true;
7784 : }
7785 : else
7786 786 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7787 : }
7788 858 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
7789 : }
7790 : break;
7791 :
7792 405 : case OMP_CLAUSE_NONTEMPORAL:
7793 405 : t = OMP_CLAUSE_DECL (c);
7794 405 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
7795 : {
7796 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
7797 : break;
7798 0 : if (DECL_P (t))
7799 0 : error_at (OMP_CLAUSE_LOCATION (c),
7800 : "%qD is not a variable in %<nontemporal%> clause",
7801 : t);
7802 : else
7803 0 : error_at (OMP_CLAUSE_LOCATION (c),
7804 : "%qE is not a variable in %<nontemporal%> clause",
7805 : t);
7806 : remove = true;
7807 : }
7808 405 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
7809 : {
7810 8 : error_at (OMP_CLAUSE_LOCATION (c),
7811 : "%qD appears more than once in %<nontemporal%> "
7812 : "clauses", t);
7813 8 : remove = true;
7814 : }
7815 : else
7816 397 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
7817 : break;
7818 :
7819 3125 : case OMP_CLAUSE_ALLOCATE:
7820 3125 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
7821 3125 : if (t)
7822 2 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
7823 : else
7824 3123 : t = OMP_CLAUSE_DECL (c);
7825 3125 : if (t == current_class_ptr)
7826 : {
7827 0 : error_at (OMP_CLAUSE_LOCATION (c),
7828 : "%<this%> not allowed in %<allocate%> clause");
7829 0 : remove = true;
7830 0 : break;
7831 : }
7832 3125 : if (!VAR_P (t)
7833 826 : && TREE_CODE (t) != PARM_DECL
7834 10 : && TREE_CODE (t) != FIELD_DECL)
7835 : {
7836 4 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
7837 : break;
7838 4 : if (DECL_P (t))
7839 4 : error_at (OMP_CLAUSE_LOCATION (c),
7840 : "%qD is not a variable in %<allocate%> clause", t);
7841 : else
7842 0 : error_at (OMP_CLAUSE_LOCATION (c),
7843 : "%qE is not a variable in %<allocate%> clause", t);
7844 : remove = true;
7845 : }
7846 3121 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
7847 : {
7848 16 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
7849 : "%qD appears more than once in %<allocate%> clauses",
7850 : t);
7851 16 : remove = true;
7852 : }
7853 : else
7854 : {
7855 3105 : bitmap_set_bit (&aligned_head, DECL_UID (t));
7856 3105 : allocate_seen = true;
7857 : }
7858 3125 : tree allocator, align;
7859 3125 : align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
7860 3125 : if (error_operand_p (align))
7861 : {
7862 : remove = true;
7863 : break;
7864 : }
7865 3125 : if (align)
7866 : {
7867 165 : if (!type_dependent_expression_p (align)
7868 165 : && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
7869 : {
7870 5 : error_at (OMP_CLAUSE_LOCATION (c),
7871 : "%<allocate%> clause %<align%> modifier "
7872 : "argument needs to be positive constant "
7873 : "power of two integer expression");
7874 5 : remove = true;
7875 : }
7876 : else
7877 : {
7878 160 : align = mark_rvalue_use (align);
7879 160 : if (!processing_template_decl)
7880 : {
7881 157 : align = maybe_constant_value (align);
7882 157 : if (TREE_CODE (align) != INTEGER_CST
7883 153 : || !tree_fits_uhwi_p (align)
7884 310 : || !integer_pow2p (align))
7885 : {
7886 13 : error_at (OMP_CLAUSE_LOCATION (c),
7887 : "%<allocate%> clause %<align%> modifier "
7888 : "argument needs to be positive constant "
7889 : "power of two integer expression");
7890 13 : remove = true;
7891 : }
7892 : }
7893 : }
7894 165 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
7895 : }
7896 3125 : allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
7897 3125 : if (error_operand_p (allocator))
7898 : {
7899 : remove = true;
7900 : break;
7901 : }
7902 3125 : if (allocator == NULL_TREE)
7903 2067 : goto handle_field_decl;
7904 1058 : tree allocatort;
7905 1058 : allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
7906 1058 : if (!type_dependent_expression_p (allocator)
7907 1058 : && (TREE_CODE (allocatort) != ENUMERAL_TYPE
7908 1035 : || TYPE_NAME (allocatort) == NULL_TREE
7909 1035 : || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
7910 2070 : || (DECL_NAME (TYPE_NAME (allocatort))
7911 1035 : != get_identifier ("omp_allocator_handle_t"))
7912 1035 : || (TYPE_CONTEXT (allocatort)
7913 1035 : != DECL_CONTEXT (global_namespace))))
7914 : {
7915 20 : error_at (OMP_CLAUSE_LOCATION (c),
7916 : "%<allocate%> clause allocator expression has "
7917 : "type %qT rather than %<omp_allocator_handle_t%>",
7918 20 : TREE_TYPE (allocator));
7919 20 : remove = true;
7920 20 : break;
7921 : }
7922 : else
7923 : {
7924 1038 : allocator = mark_rvalue_use (allocator);
7925 1038 : if (!processing_template_decl)
7926 1031 : allocator = maybe_constant_value (allocator);
7927 1038 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
7928 : }
7929 1038 : goto handle_field_decl;
7930 :
7931 732 : case OMP_CLAUSE_DOACROSS:
7932 732 : t = OMP_CLAUSE_DECL (c);
7933 732 : if (t == NULL_TREE)
7934 : break;
7935 327 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
7936 : {
7937 327 : if (cp_finish_omp_clause_doacross_sink (c))
7938 12 : remove = true;
7939 : break;
7940 : }
7941 0 : gcc_unreachable ();
7942 2860 : case OMP_CLAUSE_DEPEND:
7943 2860 : case OMP_CLAUSE_AFFINITY:
7944 2860 : t = OMP_CLAUSE_DECL (c);
7945 2860 : if (TREE_CODE (t) == TREE_LIST
7946 2113 : && TREE_PURPOSE (t)
7947 4729 : && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
7948 : {
7949 809 : if (TREE_PURPOSE (t) != last_iterators)
7950 680 : last_iterators_remove
7951 680 : = cp_omp_finish_iterators (TREE_PURPOSE (t));
7952 809 : last_iterators = TREE_PURPOSE (t);
7953 809 : t = TREE_VALUE (t);
7954 809 : if (last_iterators_remove)
7955 192 : t = error_mark_node;
7956 : }
7957 : else
7958 : last_iterators = NULL_TREE;
7959 :
7960 2860 : if (TREE_CODE (t) == TREE_LIST)
7961 : {
7962 1640 : if (handle_omp_array_sections (c, ort))
7963 : remove = true;
7964 1204 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
7965 1204 : && (OMP_CLAUSE_DEPEND_KIND (c)
7966 : == OMP_CLAUSE_DEPEND_DEPOBJ))
7967 : {
7968 8 : error_at (OMP_CLAUSE_LOCATION (c),
7969 : "%<depend%> clause with %<depobj%> dependence "
7970 : "type on array section");
7971 8 : remove = true;
7972 : }
7973 : break;
7974 : }
7975 1220 : if (t == error_mark_node)
7976 : remove = true;
7977 1004 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
7978 1004 : && t == ridpointers[RID_OMP_ALL_MEMORY])
7979 : {
7980 42 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
7981 42 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
7982 : {
7983 12 : error_at (OMP_CLAUSE_LOCATION (c),
7984 : "%<omp_all_memory%> used with %<depend%> kind "
7985 : "other than %<out%> or %<inout%>");
7986 12 : remove = true;
7987 : }
7988 42 : if (processing_template_decl)
7989 : break;
7990 : }
7991 962 : else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
7992 : break;
7993 718 : else if (!lvalue_p (t))
7994 : {
7995 24 : if (DECL_P (t))
7996 16 : error_at (OMP_CLAUSE_LOCATION (c),
7997 : "%qD is not lvalue expression nor array section "
7998 : "in %qs clause", t,
7999 16 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8000 : else
8001 8 : error_at (OMP_CLAUSE_LOCATION (c),
8002 : "%qE is not lvalue expression nor array section "
8003 : "in %qs clause", t,
8004 8 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8005 : remove = true;
8006 : }
8007 694 : else if (TREE_CODE (t) == COMPONENT_REF
8008 48 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
8009 742 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
8010 : {
8011 8 : error_at (OMP_CLAUSE_LOCATION (c),
8012 : "bit-field %qE in %qs clause", t,
8013 8 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8014 8 : remove = true;
8015 : }
8016 686 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
8017 686 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
8018 : {
8019 152 : if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
8020 10 : ? TREE_TYPE (TREE_TYPE (t))
8021 66 : : TREE_TYPE (t)))
8022 : {
8023 16 : error_at (OMP_CLAUSE_LOCATION (c),
8024 : "%qE does not have %<omp_depend_t%> type in "
8025 : "%<depend%> clause with %<depobj%> dependence "
8026 : "type", t);
8027 16 : remove = true;
8028 : }
8029 : }
8030 610 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
8031 1060 : && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
8032 5 : ? TREE_TYPE (TREE_TYPE (t))
8033 445 : : TREE_TYPE (t)))
8034 : {
8035 20 : error_at (OMP_CLAUSE_LOCATION (c),
8036 : "%qE should not have %<omp_depend_t%> type in "
8037 : "%<depend%> clause with dependence type other than "
8038 : "%<depobj%>", t);
8039 20 : remove = true;
8040 : }
8041 86 : if (!remove)
8042 : {
8043 680 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
8044 30 : t = null_pointer_node;
8045 : else
8046 : {
8047 650 : tree addr = cp_build_addr_expr (t, tf_warning_or_error);
8048 650 : if (addr == error_mark_node)
8049 : {
8050 : remove = true;
8051 : break;
8052 : }
8053 650 : t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
8054 : addr, RO_UNARY_STAR,
8055 : tf_warning_or_error);
8056 650 : if (t == error_mark_node)
8057 : {
8058 : remove = true;
8059 : break;
8060 : }
8061 : }
8062 680 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
8063 173 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
8064 853 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
8065 : == TREE_VEC))
8066 173 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
8067 : else
8068 507 : OMP_CLAUSE_DECL (c) = t;
8069 : }
8070 : break;
8071 85 : case OMP_CLAUSE_DETACH:
8072 85 : t = OMP_CLAUSE_DECL (c);
8073 85 : if (detach_seen)
8074 : {
8075 4 : error_at (OMP_CLAUSE_LOCATION (c),
8076 : "too many %qs clauses on a task construct",
8077 : "detach");
8078 4 : remove = true;
8079 4 : break;
8080 : }
8081 81 : else if (error_operand_p (t))
8082 : {
8083 : remove = true;
8084 : break;
8085 : }
8086 : else
8087 : {
8088 77 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
8089 77 : if (!type_dependent_expression_p (t)
8090 77 : && (!INTEGRAL_TYPE_P (type)
8091 : || TREE_CODE (type) != ENUMERAL_TYPE
8092 61 : || TYPE_NAME (type) == NULL_TREE
8093 122 : || (DECL_NAME (TYPE_NAME (type))
8094 61 : != get_identifier ("omp_event_handle_t"))))
8095 : {
8096 8 : error_at (OMP_CLAUSE_LOCATION (c),
8097 : "%<detach%> clause event handle "
8098 : "has type %qT rather than "
8099 : "%<omp_event_handle_t%>",
8100 : type);
8101 8 : remove = true;
8102 : }
8103 77 : detach_seen = c;
8104 77 : cxx_mark_addressable (t);
8105 : }
8106 77 : break;
8107 :
8108 13784 : case OMP_CLAUSE_MAP:
8109 13784 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
8110 218 : goto move_implicit;
8111 : /* FALLTHRU */
8112 17839 : case OMP_CLAUSE_TO:
8113 17839 : case OMP_CLAUSE_FROM:
8114 17839 : case OMP_CLAUSE__CACHE_:
8115 17839 : t = OMP_CLAUSE_DECL (c);
8116 17839 : if (TREE_CODE (t) == TREE_LIST)
8117 : {
8118 5375 : grp_start_p = pc;
8119 5375 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
8120 :
8121 5375 : if (handle_omp_array_sections (c, ort))
8122 : remove = true;
8123 : else
8124 : {
8125 4391 : t = OMP_CLAUSE_DECL (c);
8126 4391 : if (TREE_CODE (t) != TREE_LIST
8127 3760 : && !type_dependent_expression_p (t)
8128 8151 : && !omp_mappable_type (TREE_TYPE (t)))
8129 : {
8130 4 : error_at (OMP_CLAUSE_LOCATION (c),
8131 : "array section does not have mappable type "
8132 : "in %qs clause",
8133 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8134 4 : if (TREE_TYPE (t) != error_mark_node
8135 4 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
8136 4 : cxx_incomplete_type_inform (TREE_TYPE (t));
8137 4391 : remove = true;
8138 : }
8139 6333 : while (TREE_CODE (t) == ARRAY_REF)
8140 1942 : t = TREE_OPERAND (t, 0);
8141 4391 : if (TREE_CODE (t) == COMPONENT_REF
8142 4391 : && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
8143 : {
8144 158 : do
8145 : {
8146 158 : t = TREE_OPERAND (t, 0);
8147 158 : if (REFERENCE_REF_P (t))
8148 3 : t = TREE_OPERAND (t, 0);
8149 158 : if (TREE_CODE (t) == MEM_REF
8150 158 : || INDIRECT_REF_P (t))
8151 : {
8152 0 : t = TREE_OPERAND (t, 0);
8153 0 : STRIP_NOPS (t);
8154 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
8155 0 : t = TREE_OPERAND (t, 0);
8156 : }
8157 : }
8158 158 : while (TREE_CODE (t) == COMPONENT_REF
8159 158 : || TREE_CODE (t) == ARRAY_REF);
8160 :
8161 149 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8162 137 : && OMP_CLAUSE_MAP_IMPLICIT (c)
8163 149 : && (bitmap_bit_p (&map_head, DECL_UID (t))
8164 0 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
8165 0 : || bitmap_bit_p (&map_firstprivate_head,
8166 0 : DECL_UID (t))))
8167 : {
8168 : remove = true;
8169 : break;
8170 : }
8171 149 : if (bitmap_bit_p (&map_field_head, DECL_UID (t)))
8172 : break;
8173 101 : if (bitmap_bit_p (&map_head, DECL_UID (t)))
8174 : {
8175 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
8176 0 : error_at (OMP_CLAUSE_LOCATION (c),
8177 : "%qD appears more than once in motion"
8178 : " clauses", t);
8179 0 : else if (ort == C_ORT_ACC)
8180 0 : error_at (OMP_CLAUSE_LOCATION (c),
8181 : "%qD appears more than once in data"
8182 : " clauses", t);
8183 : else
8184 0 : error_at (OMP_CLAUSE_LOCATION (c),
8185 : "%qD appears more than once in map"
8186 : " clauses", t);
8187 : remove = true;
8188 : }
8189 : else
8190 : {
8191 101 : bitmap_set_bit (&map_head, DECL_UID (t));
8192 101 : bitmap_set_bit (&map_field_head, DECL_UID (t));
8193 : }
8194 : }
8195 : }
8196 5327 : if (cp_oacc_check_attachments (c))
8197 16 : remove = true;
8198 5327 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8199 5327 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
8200 4079 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
8201 : /* In this case, we have a single array element which is a
8202 : pointer, and we already set OMP_CLAUSE_SIZE in
8203 : handle_omp_array_sections above. For attach/detach clauses,
8204 : reset the OMP_CLAUSE_SIZE (representing a bias) to zero
8205 : here. */
8206 80 : OMP_CLAUSE_SIZE (c) = size_zero_node;
8207 : break;
8208 : }
8209 12464 : if (t == error_mark_node)
8210 : {
8211 : remove = true;
8212 : break;
8213 : }
8214 : /* OpenACC attach / detach clauses must be pointers. */
8215 12440 : if (cp_oacc_check_attachments (c))
8216 : {
8217 : remove = true;
8218 : break;
8219 : }
8220 12408 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8221 12408 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
8222 9315 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
8223 : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
8224 : bias) to zero here, so it is not set erroneously to the pointer
8225 : size later on in gimplify.cc. */
8226 94 : OMP_CLAUSE_SIZE (c) = size_zero_node;
8227 69 : if (REFERENCE_REF_P (t)
8228 12477 : && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF)
8229 : {
8230 69 : t = TREE_OPERAND (t, 0);
8231 69 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8232 69 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
8233 32 : OMP_CLAUSE_DECL (c) = t;
8234 : }
8235 12408 : while (INDIRECT_REF_P (t)
8236 12408 : || TREE_CODE (t) == ARRAY_REF)
8237 : {
8238 0 : t = TREE_OPERAND (t, 0);
8239 0 : STRIP_NOPS (t);
8240 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
8241 0 : t = TREE_OPERAND (t, 0);
8242 : }
8243 12408 : while (TREE_CODE (t) == COMPOUND_EXPR)
8244 : {
8245 0 : t = TREE_OPERAND (t, 1);
8246 0 : STRIP_NOPS (t);
8247 : }
8248 12408 : if (TREE_CODE (t) == COMPONENT_REF
8249 12408 : && invalid_nonstatic_memfn_p (EXPR_LOCATION (t), t,
8250 : tf_warning_or_error))
8251 : remove = true;
8252 12408 : indir_component_ref_p = false;
8253 12408 : if (TREE_CODE (t) == COMPONENT_REF
8254 12408 : && (INDIRECT_REF_P (TREE_OPERAND (t, 0))
8255 854 : || TREE_CODE (TREE_OPERAND (t, 0)) == ARRAY_REF))
8256 : {
8257 216 : t = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
8258 216 : indir_component_ref_p = true;
8259 216 : STRIP_NOPS (t);
8260 216 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
8261 11 : t = TREE_OPERAND (t, 0);
8262 : }
8263 12408 : if (TREE_CODE (t) == COMPONENT_REF
8264 13317 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE__CACHE_)
8265 : {
8266 909 : if (type_dependent_expression_p (t))
8267 : break;
8268 755 : if (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
8269 755 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
8270 : {
8271 24 : error_at (OMP_CLAUSE_LOCATION (c),
8272 : "bit-field %qE in %qs clause",
8273 24 : t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8274 24 : remove = true;
8275 : }
8276 731 : else if (!omp_mappable_type (TREE_TYPE (t)))
8277 : {
8278 0 : error_at (OMP_CLAUSE_LOCATION (c),
8279 : "%qE does not have a mappable type in %qs clause",
8280 0 : t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8281 0 : if (TREE_TYPE (t) != error_mark_node
8282 0 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
8283 0 : cxx_incomplete_type_inform (TREE_TYPE (t));
8284 755 : remove = true;
8285 : }
8286 1630 : while (TREE_CODE (t) == COMPONENT_REF)
8287 : {
8288 875 : if (TREE_TYPE (TREE_OPERAND (t, 0))
8289 875 : && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
8290 : == UNION_TYPE))
8291 : {
8292 0 : error_at (OMP_CLAUSE_LOCATION (c),
8293 : "%qE is a member of a union", t);
8294 0 : remove = true;
8295 0 : break;
8296 : }
8297 875 : t = TREE_OPERAND (t, 0);
8298 875 : if (TREE_CODE (t) == MEM_REF)
8299 : {
8300 0 : if (maybe_ne (mem_ref_offset (t), 0))
8301 0 : error_at (OMP_CLAUSE_LOCATION (c),
8302 : "cannot dereference %qE in %qs clause", t,
8303 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8304 : else
8305 0 : t = TREE_OPERAND (t, 0);
8306 : }
8307 933 : while (TREE_CODE (t) == MEM_REF
8308 933 : || INDIRECT_REF_P (t)
8309 1808 : || TREE_CODE (t) == ARRAY_REF)
8310 : {
8311 58 : t = TREE_OPERAND (t, 0);
8312 58 : STRIP_NOPS (t);
8313 58 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
8314 0 : t = TREE_OPERAND (t, 0);
8315 : }
8316 : }
8317 755 : if (remove)
8318 : break;
8319 731 : if (REFERENCE_REF_P (t))
8320 0 : t = TREE_OPERAND (t, 0);
8321 731 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
8322 : {
8323 731 : if (bitmap_bit_p (&map_field_head, DECL_UID (t))
8324 731 : || (ort != C_ORT_ACC
8325 185 : && bitmap_bit_p (&map_head, DECL_UID (t))))
8326 430 : goto handle_map_references;
8327 : }
8328 : }
8329 11800 : if (!processing_template_decl
8330 11462 : && TREE_CODE (t) == FIELD_DECL)
8331 : {
8332 33 : OMP_CLAUSE_DECL (c) = finish_non_static_data_member (t, NULL_TREE,
8333 : NULL_TREE);
8334 33 : break;
8335 : }
8336 11767 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8337 : {
8338 21 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8339 : break;
8340 5 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8341 5 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
8342 5 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
8343 5 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH))
8344 : break;
8345 0 : if (DECL_P (t))
8346 0 : error_at (OMP_CLAUSE_LOCATION (c),
8347 : "%qD is not a variable in %qs clause", t,
8348 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8349 : else
8350 0 : error_at (OMP_CLAUSE_LOCATION (c),
8351 : "%qE is not a variable in %qs clause", t,
8352 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8353 : remove = true;
8354 : }
8355 11746 : else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
8356 : {
8357 0 : error_at (OMP_CLAUSE_LOCATION (c),
8358 : "%qD is threadprivate variable in %qs clause", t,
8359 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8360 0 : remove = true;
8361 : }
8362 11746 : else if (!processing_template_decl
8363 11424 : && !TYPE_REF_P (TREE_TYPE (t))
8364 11149 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
8365 8202 : || (OMP_CLAUSE_MAP_KIND (c)
8366 : != GOMP_MAP_FIRSTPRIVATE_POINTER))
8367 8587 : && !indir_component_ref_p
8368 20238 : && !cxx_mark_addressable (t))
8369 : remove = true;
8370 11746 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8371 8769 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
8372 8769 : || (OMP_CLAUSE_MAP_KIND (c)
8373 : == GOMP_MAP_FIRSTPRIVATE_POINTER)))
8374 9091 : && t == OMP_CLAUSE_DECL (c)
8375 8634 : && !type_dependent_expression_p (t)
8376 28682 : && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
8377 111 : ? TREE_TYPE (TREE_TYPE (t))
8378 8357 : : TREE_TYPE (t)))
8379 : {
8380 56 : error_at (OMP_CLAUSE_LOCATION (c),
8381 : "%qD does not have a mappable type in %qs clause", t,
8382 56 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8383 56 : if (TREE_TYPE (t) != error_mark_node
8384 56 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
8385 52 : cxx_incomplete_type_inform (TREE_TYPE (t));
8386 : remove = true;
8387 : }
8388 11690 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8389 8721 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
8390 120 : && !type_dependent_expression_p (t)
8391 11802 : && !INDIRECT_TYPE_P (TREE_TYPE (t)))
8392 : {
8393 8 : error_at (OMP_CLAUSE_LOCATION (c),
8394 : "%qD is not a pointer variable", t);
8395 8 : remove = true;
8396 : }
8397 11682 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8398 8713 : && OMP_CLAUSE_MAP_IMPLICIT (c)
8399 12142 : && (bitmap_bit_p (&map_head, DECL_UID (t))
8400 424 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
8401 424 : || bitmap_bit_p (&map_firstprivate_head,
8402 424 : DECL_UID (t))))
8403 : remove = true;
8404 11642 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8405 11642 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER)
8406 : {
8407 2647 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
8408 2647 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8409 5290 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8410 : {
8411 16 : error_at (OMP_CLAUSE_LOCATION (c),
8412 : "%qD appears more than once in data clauses", t);
8413 16 : remove = true;
8414 : }
8415 2631 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8416 2631 : && !bitmap_bit_p (&map_field_head, DECL_UID (t)))
8417 : {
8418 8 : if (ort == C_ORT_ACC)
8419 4 : error_at (OMP_CLAUSE_LOCATION (c),
8420 : "%qD appears more than once in data clauses", t);
8421 : else
8422 4 : error_at (OMP_CLAUSE_LOCATION (c),
8423 : "%qD appears both in data and map clauses", t);
8424 : remove = true;
8425 : }
8426 : else
8427 2623 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
8428 : }
8429 8995 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8430 8995 : && !bitmap_bit_p (&map_field_head, DECL_UID (t)))
8431 : {
8432 24 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
8433 0 : error_at (OMP_CLAUSE_LOCATION (c),
8434 : "%qD appears more than once in motion clauses", t);
8435 24 : else if (ort == C_ORT_ACC)
8436 12 : error_at (OMP_CLAUSE_LOCATION (c),
8437 : "%qD appears more than once in data clauses", t);
8438 : else
8439 12 : error_at (OMP_CLAUSE_LOCATION (c),
8440 : "%qD appears more than once in map clauses", t);
8441 : remove = true;
8442 : }
8443 8971 : else if (ort == C_ORT_ACC
8444 8971 : && bitmap_bit_p (&generic_head, DECL_UID (t)))
8445 : {
8446 0 : error_at (OMP_CLAUSE_LOCATION (c),
8447 : "%qD appears more than once in data clauses", t);
8448 0 : remove = true;
8449 : }
8450 8971 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8451 8971 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
8452 : {
8453 36 : if (ort == C_ORT_ACC)
8454 0 : error_at (OMP_CLAUSE_LOCATION (c),
8455 : "%qD appears more than once in data clauses", t);
8456 : else
8457 36 : error_at (OMP_CLAUSE_LOCATION (c),
8458 : "%qD appears both in data and map clauses", t);
8459 : remove = true;
8460 : }
8461 : else
8462 : {
8463 8935 : bitmap_set_bit (&map_head, DECL_UID (t));
8464 :
8465 8935 : tree decl = OMP_CLAUSE_DECL (c);
8466 8935 : if (t != decl
8467 8935 : && (TREE_CODE (decl) == COMPONENT_REF
8468 31 : || (INDIRECT_REF_P (decl)
8469 31 : && TREE_CODE (TREE_OPERAND (decl, 0)) == COMPONENT_REF
8470 31 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl, 0))))))
8471 441 : bitmap_set_bit (&map_field_head, DECL_UID (t));
8472 : }
8473 12012 : handle_map_references:
8474 24 : if (!remove
8475 11984 : && !processing_template_decl
8476 11681 : && ort != C_ORT_DECLARE_SIMD
8477 23669 : && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))
8478 : {
8479 340 : t = OMP_CLAUSE_DECL (c);
8480 340 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
8481 : {
8482 18 : OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t);
8483 18 : if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
8484 18 : OMP_CLAUSE_SIZE (c)
8485 36 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t)));
8486 : }
8487 322 : else if (OMP_CLAUSE_MAP_KIND (c)
8488 : != GOMP_MAP_FIRSTPRIVATE_POINTER
8489 229 : && (OMP_CLAUSE_MAP_KIND (c)
8490 : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
8491 229 : && (OMP_CLAUSE_MAP_KIND (c)
8492 : != GOMP_MAP_ALWAYS_POINTER)
8493 516 : && (OMP_CLAUSE_MAP_KIND (c)
8494 : != GOMP_MAP_ATTACH_DETACH))
8495 : {
8496 194 : grp_start_p = pc;
8497 194 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
8498 :
8499 194 : tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c),
8500 : OMP_CLAUSE_MAP);
8501 194 : if (TREE_CODE (t) == COMPONENT_REF)
8502 90 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER);
8503 : else
8504 104 : OMP_CLAUSE_SET_MAP_KIND (c2,
8505 : GOMP_MAP_FIRSTPRIVATE_REFERENCE);
8506 194 : OMP_CLAUSE_DECL (c2) = t;
8507 194 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
8508 194 : OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c);
8509 194 : OMP_CLAUSE_CHAIN (c) = c2;
8510 194 : OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t);
8511 194 : if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
8512 186 : OMP_CLAUSE_SIZE (c)
8513 372 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t)));
8514 : c = c2;
8515 : }
8516 : }
8517 : break;
8518 :
8519 566 : case OMP_CLAUSE_ENTER:
8520 566 : case OMP_CLAUSE_LINK:
8521 566 : t = OMP_CLAUSE_DECL (c);
8522 566 : const char *cname;
8523 566 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
8524 566 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
8525 566 : && OMP_CLAUSE_ENTER_TO (c))
8526 : cname = "to";
8527 566 : if (TREE_CODE (t) == FUNCTION_DECL
8528 566 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
8529 : ;
8530 366 : else if (!VAR_P (t))
8531 : {
8532 16 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
8533 : {
8534 12 : if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
8535 8 : error_at (OMP_CLAUSE_LOCATION (c),
8536 : "template %qE in clause %qs", t, cname);
8537 4 : else if (really_overloaded_fn (t))
8538 4 : error_at (OMP_CLAUSE_LOCATION (c),
8539 : "overloaded function name %qE in clause %qs", t,
8540 : cname);
8541 : else
8542 0 : error_at (OMP_CLAUSE_LOCATION (c),
8543 : "%qE is neither a variable nor a function name "
8544 : "in clause %qs", t, cname);
8545 : }
8546 : else
8547 4 : error_at (OMP_CLAUSE_LOCATION (c),
8548 : "%qE is not a variable in clause %qs", t, cname);
8549 : remove = true;
8550 : }
8551 350 : else if (DECL_THREAD_LOCAL_P (t))
8552 : {
8553 8 : error_at (OMP_CLAUSE_LOCATION (c),
8554 : "%qD is threadprivate variable in %qs clause", t,
8555 : cname);
8556 8 : remove = true;
8557 : }
8558 342 : else if (!omp_mappable_type (TREE_TYPE (t)))
8559 : {
8560 24 : error_at (OMP_CLAUSE_LOCATION (c),
8561 : "%qD does not have a mappable type in %qs clause", t,
8562 : cname);
8563 24 : if (TREE_TYPE (t) != error_mark_node
8564 24 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
8565 24 : cxx_incomplete_type_inform (TREE_TYPE (t));
8566 : remove = true;
8567 : }
8568 8 : if (remove)
8569 : break;
8570 518 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
8571 : {
8572 32 : error_at (OMP_CLAUSE_LOCATION (c),
8573 : "%qE appears more than once on the same "
8574 : "%<declare target%> directive", t);
8575 32 : remove = true;
8576 : }
8577 : else
8578 486 : bitmap_set_bit (&generic_head, DECL_UID (t));
8579 : break;
8580 :
8581 533 : case OMP_CLAUSE_UNIFORM:
8582 533 : t = OMP_CLAUSE_DECL (c);
8583 533 : if (TREE_CODE (t) != PARM_DECL)
8584 : {
8585 0 : if (processing_template_decl)
8586 : break;
8587 0 : if (DECL_P (t))
8588 0 : error_at (OMP_CLAUSE_LOCATION (c),
8589 : "%qD is not an argument in %<uniform%> clause", t);
8590 : else
8591 0 : error_at (OMP_CLAUSE_LOCATION (c),
8592 : "%qE is not an argument in %<uniform%> clause", t);
8593 : remove = true;
8594 : break;
8595 : }
8596 : /* map_head bitmap is used as uniform_head if declare_simd. */
8597 533 : bitmap_set_bit (&map_head, DECL_UID (t));
8598 533 : goto check_dup_generic;
8599 :
8600 183 : case OMP_CLAUSE_GRAINSIZE:
8601 183 : t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
8602 183 : if (t == error_mark_node)
8603 : remove = true;
8604 183 : else if (!type_dependent_expression_p (t)
8605 183 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8606 : {
8607 0 : error_at (OMP_CLAUSE_LOCATION (c),
8608 : "%<grainsize%> expression must be integral");
8609 0 : remove = true;
8610 : }
8611 : else
8612 : {
8613 183 : t = mark_rvalue_use (t);
8614 183 : if (!processing_template_decl)
8615 : {
8616 182 : t = maybe_constant_value (t);
8617 182 : if (TREE_CODE (t) == INTEGER_CST
8618 182 : && tree_int_cst_sgn (t) != 1)
8619 : {
8620 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8621 : "%<grainsize%> value must be positive");
8622 0 : t = integer_one_node;
8623 : }
8624 182 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8625 : }
8626 183 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
8627 : }
8628 : break;
8629 :
8630 301 : case OMP_CLAUSE_PRIORITY:
8631 301 : t = OMP_CLAUSE_PRIORITY_EXPR (c);
8632 301 : if (t == error_mark_node)
8633 : remove = true;
8634 301 : else if (!type_dependent_expression_p (t)
8635 301 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8636 : {
8637 0 : error_at (OMP_CLAUSE_LOCATION (c),
8638 : "%<priority%> expression must be integral");
8639 0 : remove = true;
8640 : }
8641 : else
8642 : {
8643 301 : t = mark_rvalue_use (t);
8644 301 : if (!processing_template_decl)
8645 : {
8646 301 : t = maybe_constant_value (t);
8647 301 : if (TREE_CODE (t) == INTEGER_CST
8648 301 : && tree_int_cst_sgn (t) == -1)
8649 : {
8650 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8651 : "%<priority%> value must be non-negative");
8652 0 : t = integer_one_node;
8653 : }
8654 301 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8655 : }
8656 301 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
8657 : }
8658 : break;
8659 :
8660 285 : case OMP_CLAUSE_HINT:
8661 285 : t = OMP_CLAUSE_HINT_EXPR (c);
8662 285 : if (t == error_mark_node)
8663 : remove = true;
8664 285 : else if (!type_dependent_expression_p (t)
8665 285 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8666 : {
8667 12 : error_at (OMP_CLAUSE_LOCATION (c),
8668 : "%<hint%> expression must be integral");
8669 12 : remove = true;
8670 : }
8671 : else
8672 : {
8673 273 : t = mark_rvalue_use (t);
8674 273 : if (!processing_template_decl)
8675 : {
8676 209 : t = maybe_constant_value (t);
8677 209 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8678 209 : if (TREE_CODE (t) != INTEGER_CST)
8679 : {
8680 21 : error_at (OMP_CLAUSE_LOCATION (c),
8681 : "%<hint%> expression must be constant integer "
8682 : "expression");
8683 21 : remove = true;
8684 : }
8685 : }
8686 273 : OMP_CLAUSE_HINT_EXPR (c) = t;
8687 : }
8688 : break;
8689 :
8690 212 : case OMP_CLAUSE_FILTER:
8691 212 : t = OMP_CLAUSE_FILTER_EXPR (c);
8692 212 : if (t == error_mark_node)
8693 : remove = true;
8694 212 : else if (!type_dependent_expression_p (t)
8695 212 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8696 : {
8697 8 : error_at (OMP_CLAUSE_LOCATION (c),
8698 : "%<filter%> expression must be integral");
8699 8 : remove = true;
8700 : }
8701 : else
8702 : {
8703 204 : t = mark_rvalue_use (t);
8704 204 : if (!processing_template_decl)
8705 : {
8706 200 : t = maybe_constant_value (t);
8707 200 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8708 : }
8709 204 : OMP_CLAUSE_FILTER_EXPR (c) = t;
8710 : }
8711 : break;
8712 :
8713 397 : case OMP_CLAUSE_IS_DEVICE_PTR:
8714 397 : case OMP_CLAUSE_USE_DEVICE_PTR:
8715 397 : field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
8716 397 : t = OMP_CLAUSE_DECL (c);
8717 397 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
8718 268 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
8719 397 : if (!type_dependent_expression_p (t))
8720 : {
8721 397 : tree type = TREE_TYPE (t);
8722 397 : if (!TYPE_PTR_P (type)
8723 397 : && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
8724 : {
8725 58 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
8726 58 : && ort == C_ORT_OMP)
8727 : {
8728 4 : error_at (OMP_CLAUSE_LOCATION (c),
8729 : "%qs variable is neither a pointer "
8730 : "nor reference to pointer",
8731 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8732 4 : remove = true;
8733 : }
8734 54 : else if (TREE_CODE (type) != ARRAY_TYPE
8735 54 : && (!TYPE_REF_P (type)
8736 2 : || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
8737 : {
8738 12 : error_at (OMP_CLAUSE_LOCATION (c),
8739 : "%qs variable is neither a pointer, nor an "
8740 : "array nor reference to pointer or array",
8741 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8742 12 : remove = true;
8743 : }
8744 : }
8745 : }
8746 397 : goto check_dup_generic;
8747 :
8748 295 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
8749 295 : t = OMP_CLAUSE_DECL (c);
8750 295 : if (TREE_CODE (t) == TREE_LIST)
8751 : {
8752 34 : if (handle_omp_array_sections (c, ort))
8753 : remove = true;
8754 : else
8755 : {
8756 34 : t = OMP_CLAUSE_DECL (c);
8757 36 : while (TREE_CODE (t) == TREE_LIST)
8758 2 : t = TREE_CHAIN (t);
8759 78 : while (INDIRECT_REF_P (t)
8760 78 : || TREE_CODE (t) == ARRAY_REF)
8761 44 : t = TREE_OPERAND (t, 0);
8762 : }
8763 : }
8764 295 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
8765 : {
8766 295 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
8767 295 : if (!processing_template_decl
8768 295 : && !cxx_mark_addressable (t))
8769 : remove = true;
8770 : }
8771 295 : goto check_dup_generic_t;
8772 :
8773 89 : case OMP_CLAUSE_USE_DEVICE_ADDR:
8774 89 : field_ok = true;
8775 89 : t = OMP_CLAUSE_DECL (c);
8776 89 : if (!processing_template_decl
8777 87 : && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
8778 87 : && !TYPE_REF_P (TREE_TYPE (t))
8779 169 : && !cxx_mark_addressable (t))
8780 : remove = true;
8781 89 : goto check_dup_generic;
8782 :
8783 : case OMP_CLAUSE_NOWAIT:
8784 : case OMP_CLAUSE_DEFAULT:
8785 : case OMP_CLAUSE_UNTIED:
8786 : case OMP_CLAUSE_COLLAPSE:
8787 : case OMP_CLAUSE_PARALLEL:
8788 : case OMP_CLAUSE_FOR:
8789 : case OMP_CLAUSE_SECTIONS:
8790 : case OMP_CLAUSE_TASKGROUP:
8791 : case OMP_CLAUSE_PROC_BIND:
8792 : case OMP_CLAUSE_DEVICE_TYPE:
8793 : case OMP_CLAUSE_NOGROUP:
8794 : case OMP_CLAUSE_THREADS:
8795 : case OMP_CLAUSE_SIMD:
8796 : case OMP_CLAUSE_DEFAULTMAP:
8797 : case OMP_CLAUSE_BIND:
8798 : case OMP_CLAUSE_AUTO:
8799 : case OMP_CLAUSE_INDEPENDENT:
8800 : case OMP_CLAUSE_SEQ:
8801 : case OMP_CLAUSE_IF_PRESENT:
8802 : case OMP_CLAUSE_FINALIZE:
8803 : case OMP_CLAUSE_NOHOST:
8804 : break;
8805 :
8806 244 : case OMP_CLAUSE_MERGEABLE:
8807 244 : mergeable_seen = true;
8808 244 : break;
8809 :
8810 413 : case OMP_CLAUSE_TILE:
8811 957 : for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
8812 544 : list = TREE_CHAIN (list))
8813 : {
8814 544 : t = TREE_VALUE (list);
8815 :
8816 544 : if (t == error_mark_node)
8817 : remove = true;
8818 508 : else if (!type_dependent_expression_p (t)
8819 508 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8820 : {
8821 4 : error_at (OMP_CLAUSE_LOCATION (c),
8822 : "%<tile%> argument needs integral type");
8823 4 : remove = true;
8824 : }
8825 : else
8826 : {
8827 504 : t = mark_rvalue_use (t);
8828 504 : if (!processing_template_decl)
8829 : {
8830 : /* Zero is used to indicate '*', we permit you
8831 : to get there via an ICE of value zero. */
8832 492 : t = maybe_constant_value (t);
8833 492 : if (!tree_fits_shwi_p (t)
8834 468 : || tree_to_shwi (t) < 0)
8835 : {
8836 56 : error_at (OMP_CLAUSE_LOCATION (c),
8837 : "%<tile%> argument needs positive "
8838 : "integral constant");
8839 56 : remove = true;
8840 : }
8841 492 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8842 : }
8843 : }
8844 :
8845 : /* Update list item. */
8846 544 : TREE_VALUE (list) = t;
8847 : }
8848 : break;
8849 :
8850 652 : case OMP_CLAUSE_ORDERED:
8851 652 : ordered_seen = true;
8852 652 : break;
8853 :
8854 1850 : case OMP_CLAUSE_ORDER:
8855 1850 : if (order_seen)
8856 : remove = true;
8857 : else
8858 : order_seen = true;
8859 : break;
8860 :
8861 724 : case OMP_CLAUSE_INBRANCH:
8862 724 : case OMP_CLAUSE_NOTINBRANCH:
8863 724 : if (branch_seen)
8864 : {
8865 4 : error_at (OMP_CLAUSE_LOCATION (c),
8866 : "%<inbranch%> clause is incompatible with "
8867 : "%<notinbranch%>");
8868 4 : remove = true;
8869 : }
8870 : branch_seen = true;
8871 : break;
8872 :
8873 336 : case OMP_CLAUSE_INCLUSIVE:
8874 336 : case OMP_CLAUSE_EXCLUSIVE:
8875 336 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8876 336 : if (!t)
8877 336 : t = OMP_CLAUSE_DECL (c);
8878 336 : if (t == current_class_ptr)
8879 : {
8880 0 : error_at (OMP_CLAUSE_LOCATION (c),
8881 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8882 : " clauses");
8883 0 : remove = true;
8884 0 : break;
8885 : }
8886 336 : if (!VAR_P (t)
8887 122 : && TREE_CODE (t) != PARM_DECL
8888 0 : && TREE_CODE (t) != FIELD_DECL)
8889 : {
8890 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8891 : break;
8892 0 : if (DECL_P (t))
8893 0 : error_at (OMP_CLAUSE_LOCATION (c),
8894 : "%qD is not a variable in clause %qs", t,
8895 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8896 : else
8897 0 : error_at (OMP_CLAUSE_LOCATION (c),
8898 : "%qE is not a variable in clause %qs", t,
8899 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8900 : remove = true;
8901 : }
8902 : break;
8903 :
8904 0 : default:
8905 0 : gcc_unreachable ();
8906 : }
8907 :
8908 98948 : if (remove)
8909 : {
8910 3043 : if (grp_start_p)
8911 : {
8912 : /* If we found a clause to remove, we want to remove the whole
8913 : expanded group, otherwise gimplify can get confused. */
8914 1044 : *grp_start_p = grp_sentinel;
8915 1044 : pc = grp_start_p;
8916 1044 : grp_start_p = NULL;
8917 : }
8918 : else
8919 1999 : *pc = OMP_CLAUSE_CHAIN (c);
8920 : }
8921 : else
8922 95905 : pc = &OMP_CLAUSE_CHAIN (c);
8923 : }
8924 :
8925 64144 : if (reduction_seen < 0 && (ordered_seen || schedule_seen))
8926 64144 : reduction_seen = -2;
8927 :
8928 160203 : for (pc = &clauses, c = clauses; c ; c = *pc)
8929 : {
8930 96059 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
8931 96059 : bool remove = false;
8932 96059 : bool need_complete_type = false;
8933 96059 : bool need_default_ctor = false;
8934 96059 : bool need_copy_ctor = false;
8935 96059 : bool need_copy_assignment = false;
8936 96059 : bool need_implicitly_determined = false;
8937 96059 : bool need_dtor = false;
8938 96059 : tree type, inner_type;
8939 :
8940 96059 : switch (c_kind)
8941 : {
8942 : case OMP_CLAUSE_SHARED:
8943 : need_implicitly_determined = true;
8944 : break;
8945 2733 : case OMP_CLAUSE_PRIVATE:
8946 2733 : need_complete_type = true;
8947 2733 : need_default_ctor = true;
8948 2733 : need_dtor = true;
8949 2733 : need_implicitly_determined = true;
8950 2733 : break;
8951 3485 : case OMP_CLAUSE_FIRSTPRIVATE:
8952 3485 : need_complete_type = true;
8953 3485 : need_copy_ctor = true;
8954 3485 : need_dtor = true;
8955 3485 : need_implicitly_determined = true;
8956 3485 : break;
8957 3182 : case OMP_CLAUSE_LASTPRIVATE:
8958 3182 : need_complete_type = true;
8959 3182 : need_copy_assignment = true;
8960 3182 : need_implicitly_determined = true;
8961 3182 : break;
8962 7881 : case OMP_CLAUSE_REDUCTION:
8963 7881 : if (reduction_seen == -2)
8964 36 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
8965 7881 : if (OMP_CLAUSE_REDUCTION_INSCAN (c))
8966 450 : need_copy_assignment = true;
8967 : need_implicitly_determined = true;
8968 : break;
8969 : case OMP_CLAUSE_IN_REDUCTION:
8970 : case OMP_CLAUSE_TASK_REDUCTION:
8971 : case OMP_CLAUSE_INCLUSIVE:
8972 : case OMP_CLAUSE_EXCLUSIVE:
8973 : need_implicitly_determined = true;
8974 : break;
8975 1837 : case OMP_CLAUSE_LINEAR:
8976 1837 : if (ort != C_ORT_OMP_DECLARE_SIMD)
8977 : need_implicitly_determined = true;
8978 794 : else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
8979 848 : && !bitmap_bit_p (&map_head,
8980 54 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
8981 : {
8982 8 : error_at (OMP_CLAUSE_LOCATION (c),
8983 : "%<linear%> clause step is a parameter %qD not "
8984 : "specified in %<uniform%> clause",
8985 8 : OMP_CLAUSE_LINEAR_STEP (c));
8986 8 : *pc = OMP_CLAUSE_CHAIN (c);
8987 72521 : continue;
8988 : }
8989 : break;
8990 : case OMP_CLAUSE_COPYPRIVATE:
8991 409 : need_copy_assignment = true;
8992 : break;
8993 : case OMP_CLAUSE_COPYIN:
8994 409 : need_copy_assignment = true;
8995 : break;
8996 867 : case OMP_CLAUSE_SIMDLEN:
8997 867 : if (safelen
8998 373 : && !processing_template_decl
8999 1240 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
9000 373 : OMP_CLAUSE_SIMDLEN_EXPR (c)))
9001 : {
9002 0 : error_at (OMP_CLAUSE_LOCATION (c),
9003 : "%<simdlen%> clause value is bigger than "
9004 : "%<safelen%> clause value");
9005 0 : OMP_CLAUSE_SIMDLEN_EXPR (c)
9006 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
9007 : }
9008 867 : pc = &OMP_CLAUSE_CHAIN (c);
9009 867 : continue;
9010 3990 : case OMP_CLAUSE_SCHEDULE:
9011 3990 : if (ordered_seen
9012 3990 : && (OMP_CLAUSE_SCHEDULE_KIND (c)
9013 : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
9014 : {
9015 28 : error_at (OMP_CLAUSE_LOCATION (c),
9016 : "%<nonmonotonic%> schedule modifier specified "
9017 : "together with %<ordered%> clause");
9018 56 : OMP_CLAUSE_SCHEDULE_KIND (c)
9019 28 : = (enum omp_clause_schedule_kind)
9020 28 : (OMP_CLAUSE_SCHEDULE_KIND (c)
9021 : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
9022 : }
9023 3990 : if (reduction_seen == -2)
9024 12 : error_at (OMP_CLAUSE_LOCATION (c),
9025 : "%qs clause specified together with %<inscan%> "
9026 : "%<reduction%> clause", "schedule");
9027 3990 : pc = &OMP_CLAUSE_CHAIN (c);
9028 3990 : continue;
9029 56 : case OMP_CLAUSE_NOGROUP:
9030 56 : if (reduction_seen)
9031 : {
9032 4 : error_at (OMP_CLAUSE_LOCATION (c),
9033 : "%<nogroup%> clause must not be used together with "
9034 : "%<reduction%> clause");
9035 4 : *pc = OMP_CLAUSE_CHAIN (c);
9036 4 : continue;
9037 : }
9038 52 : pc = &OMP_CLAUSE_CHAIN (c);
9039 52 : continue;
9040 652 : case OMP_CLAUSE_ORDERED:
9041 652 : if (reduction_seen == -2)
9042 8 : error_at (OMP_CLAUSE_LOCATION (c),
9043 : "%qs clause specified together with %<inscan%> "
9044 : "%<reduction%> clause", "ordered");
9045 652 : pc = &OMP_CLAUSE_CHAIN (c);
9046 652 : continue;
9047 1818 : case OMP_CLAUSE_ORDER:
9048 1818 : if (ordered_seen)
9049 : {
9050 16 : error_at (OMP_CLAUSE_LOCATION (c),
9051 : "%<order%> clause must not be used together "
9052 : "with %<ordered%>");
9053 16 : *pc = OMP_CLAUSE_CHAIN (c);
9054 16 : continue;
9055 : }
9056 1802 : pc = &OMP_CLAUSE_CHAIN (c);
9057 1802 : continue;
9058 69 : case OMP_CLAUSE_DETACH:
9059 69 : if (mergeable_seen)
9060 : {
9061 8 : error_at (OMP_CLAUSE_LOCATION (c),
9062 : "%<detach%> clause must not be used together with "
9063 : "%<mergeable%> clause");
9064 8 : *pc = OMP_CLAUSE_CHAIN (c);
9065 8 : continue;
9066 : }
9067 61 : pc = &OMP_CLAUSE_CHAIN (c);
9068 61 : continue;
9069 12784 : case OMP_CLAUSE_MAP:
9070 12784 : if (target_in_reduction_seen && !processing_template_decl)
9071 : {
9072 727 : t = OMP_CLAUSE_DECL (c);
9073 1526 : while (handled_component_p (t)
9074 : || INDIRECT_REF_P (t)
9075 : || TREE_CODE (t) == ADDR_EXPR
9076 : || TREE_CODE (t) == MEM_REF
9077 839 : || TREE_CODE (t) == NON_LVALUE_EXPR)
9078 112 : t = TREE_OPERAND (t, 0);
9079 727 : if (DECL_P (t)
9080 727 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
9081 358 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
9082 : }
9083 12784 : pc = &OMP_CLAUSE_CHAIN (c);
9084 12784 : continue;
9085 6961 : case OMP_CLAUSE_NOWAIT:
9086 6961 : if (copyprivate_seen)
9087 : {
9088 8 : error_at (OMP_CLAUSE_LOCATION (c),
9089 : "%<nowait%> clause must not be used together "
9090 : "with %<copyprivate%>");
9091 8 : *pc = OMP_CLAUSE_CHAIN (c);
9092 8 : continue;
9093 : }
9094 : /* FALLTHRU */
9095 51516 : default:
9096 51516 : pc = &OMP_CLAUSE_CHAIN (c);
9097 51516 : continue;
9098 : }
9099 :
9100 24291 : t = OMP_CLAUSE_DECL (c);
9101 24291 : switch (c_kind)
9102 : {
9103 3182 : case OMP_CLAUSE_LASTPRIVATE:
9104 3182 : if (DECL_P (t)
9105 3182 : && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
9106 : {
9107 3059 : need_default_ctor = true;
9108 3059 : need_dtor = true;
9109 : }
9110 : break;
9111 :
9112 10067 : case OMP_CLAUSE_REDUCTION:
9113 10067 : case OMP_CLAUSE_IN_REDUCTION:
9114 10067 : case OMP_CLAUSE_TASK_REDUCTION:
9115 10067 : if (allocate_seen)
9116 : {
9117 1973 : if (TREE_CODE (t) == MEM_REF)
9118 : {
9119 294 : t = TREE_OPERAND (t, 0);
9120 294 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
9121 0 : t = TREE_OPERAND (t, 0);
9122 294 : if (TREE_CODE (t) == ADDR_EXPR
9123 222 : || INDIRECT_REF_P (t))
9124 146 : t = TREE_OPERAND (t, 0);
9125 294 : if (DECL_P (t))
9126 294 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
9127 : }
9128 1679 : else if (TREE_CODE (t) == TREE_LIST)
9129 : {
9130 384 : while (TREE_CODE (t) == TREE_LIST)
9131 192 : t = TREE_CHAIN (t);
9132 192 : if (DECL_P (t))
9133 192 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
9134 192 : t = OMP_CLAUSE_DECL (c);
9135 : }
9136 1487 : else if (DECL_P (t))
9137 1487 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
9138 1973 : t = OMP_CLAUSE_DECL (c);
9139 : }
9140 10067 : if (processing_template_decl
9141 1011 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9142 : break;
9143 9399 : if (finish_omp_reduction_clause (c, &need_default_ctor,
9144 : &need_dtor))
9145 : remove = true;
9146 : else
9147 9287 : t = OMP_CLAUSE_DECL (c);
9148 : break;
9149 :
9150 301 : case OMP_CLAUSE_COPYIN:
9151 301 : if (processing_template_decl
9152 0 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9153 : break;
9154 301 : if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
9155 : {
9156 20 : error_at (OMP_CLAUSE_LOCATION (c),
9157 : "%qE must be %<threadprivate%> for %<copyin%>", t);
9158 20 : remove = true;
9159 : }
9160 : break;
9161 :
9162 : default:
9163 : break;
9164 : }
9165 :
9166 24291 : if (processing_template_decl
9167 1744 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9168 : {
9169 745 : pc = &OMP_CLAUSE_CHAIN (c);
9170 745 : continue;
9171 : }
9172 :
9173 23546 : if (need_complete_type || need_copy_assignment)
9174 : {
9175 10189 : t = require_complete_type (t);
9176 10189 : if (t == error_mark_node)
9177 : remove = true;
9178 10157 : else if (!processing_template_decl
9179 9767 : && TYPE_REF_P (TREE_TYPE (t))
9180 10776 : && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
9181 : remove = true;
9182 : }
9183 23546 : if (need_implicitly_determined)
9184 : {
9185 22352 : const char *share_name = NULL;
9186 :
9187 22352 : if (allocate_seen
9188 5488 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
9189 26893 : && DECL_P (t))
9190 4164 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
9191 :
9192 22352 : if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
9193 : share_name = "threadprivate";
9194 22296 : else switch (cxx_omp_predetermined_sharing_1 (t))
9195 : {
9196 : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
9197 : break;
9198 56 : case OMP_CLAUSE_DEFAULT_SHARED:
9199 56 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
9200 36 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
9201 76 : && c_omp_predefined_variable (t))
9202 : /* The __func__ variable and similar function-local predefined
9203 : variables may be listed in a shared or firstprivate
9204 : clause. */
9205 : break;
9206 40 : if (VAR_P (t)
9207 40 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
9208 12 : && TREE_STATIC (t)
9209 52 : && cxx_omp_const_qual_no_mutable (t))
9210 : {
9211 8 : tree ctx = CP_DECL_CONTEXT (t);
9212 : /* const qualified static data members without mutable
9213 : member may be specified in firstprivate clause. */
9214 8 : if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
9215 : break;
9216 : }
9217 : share_name = "shared";
9218 : break;
9219 : case OMP_CLAUSE_DEFAULT_PRIVATE:
9220 : share_name = "private";
9221 : break;
9222 0 : default:
9223 0 : gcc_unreachable ();
9224 : }
9225 : if (share_name)
9226 : {
9227 176 : error_at (OMP_CLAUSE_LOCATION (c),
9228 : "%qE is predetermined %qs for %qs",
9229 : omp_clause_printable_decl (t), share_name,
9230 88 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9231 88 : remove = true;
9232 : }
9233 22264 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
9234 20032 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
9235 38848 : && cxx_omp_const_qual_no_mutable (t))
9236 : {
9237 168 : error_at (OMP_CLAUSE_LOCATION (c),
9238 : "%<const%> qualified %qE without %<mutable%> member "
9239 : "may appear only in %<shared%> or %<firstprivate%> "
9240 : "clauses", omp_clause_printable_decl (t));
9241 84 : remove = true;
9242 : }
9243 : }
9244 :
9245 23546 : if (detach_seen
9246 21 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
9247 13 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
9248 13 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
9249 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
9250 23567 : && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
9251 : {
9252 8 : error_at (OMP_CLAUSE_LOCATION (c),
9253 : "the event handle of a %<detach%> clause "
9254 : "should not be in a data-sharing clause");
9255 8 : remove = true;
9256 : }
9257 :
9258 : /* We're interested in the base element, not arrays. */
9259 23546 : inner_type = type = TREE_TYPE (t);
9260 23546 : if ((need_complete_type
9261 : || need_copy_assignment
9262 13357 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
9263 6255 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
9264 4752 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
9265 32495 : && TYPE_REF_P (inner_type))
9266 995 : inner_type = TREE_TYPE (inner_type);
9267 26375 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
9268 2829 : inner_type = TREE_TYPE (inner_type);
9269 :
9270 : /* Check for special function availability by building a call to one.
9271 : Save the results, because later we won't be in the right context
9272 : for making these queries. */
9273 2656 : if (CLASS_TYPE_P (inner_type)
9274 2656 : && COMPLETE_TYPE_P (inner_type)
9275 2585 : && (need_default_ctor || need_copy_ctor
9276 1161 : || need_copy_assignment || need_dtor)
9277 2212 : && !type_dependent_expression_p (t)
9278 25758 : && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
9279 : need_copy_ctor, need_copy_assignment,
9280 : need_dtor))
9281 : remove = true;
9282 :
9283 23546 : if (!remove
9284 23546 : && c_kind == OMP_CLAUSE_SHARED
9285 2228 : && processing_template_decl)
9286 : {
9287 119 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
9288 119 : if (t)
9289 5 : OMP_CLAUSE_DECL (c) = t;
9290 : }
9291 :
9292 23546 : if (remove)
9293 387 : *pc = OMP_CLAUSE_CHAIN (c);
9294 : else
9295 23159 : pc = &OMP_CLAUSE_CHAIN (c);
9296 : }
9297 :
9298 64144 : if (allocate_seen)
9299 18976 : for (pc = &clauses, c = clauses; c ; c = *pc)
9300 : {
9301 16159 : bool remove = false;
9302 16159 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
9303 3067 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
9304 2528 : && DECL_P (OMP_CLAUSE_DECL (c))
9305 18687 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
9306 : {
9307 40 : error_at (OMP_CLAUSE_LOCATION (c),
9308 : "%qD specified in %<allocate%> clause but not in "
9309 20 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
9310 20 : remove = true;
9311 : }
9312 16159 : if (remove)
9313 20 : *pc = OMP_CLAUSE_CHAIN (c);
9314 : else
9315 16139 : pc = &OMP_CLAUSE_CHAIN (c);
9316 : }
9317 :
9318 64144 : bitmap_obstack_release (NULL);
9319 64144 : return clauses;
9320 : }
9321 :
9322 : /* Start processing OpenMP clauses that can include any
9323 : privatization clauses for non-static data members. */
9324 :
9325 : tree
9326 49599 : push_omp_privatization_clauses (bool ignore_next)
9327 : {
9328 49599 : if (omp_private_member_ignore_next)
9329 : {
9330 839 : omp_private_member_ignore_next = ignore_next;
9331 839 : return NULL_TREE;
9332 : }
9333 48760 : omp_private_member_ignore_next = ignore_next;
9334 48760 : if (omp_private_member_map)
9335 20 : omp_private_member_vec.safe_push (error_mark_node);
9336 48760 : return push_stmt_list ();
9337 : }
9338 :
9339 : /* Revert remapping of any non-static data members since
9340 : the last push_omp_privatization_clauses () call. */
9341 :
9342 : void
9343 49591 : pop_omp_privatization_clauses (tree stmt)
9344 : {
9345 49591 : if (stmt == NULL_TREE)
9346 : return;
9347 48752 : stmt = pop_stmt_list (stmt);
9348 48752 : if (omp_private_member_map)
9349 : {
9350 1395 : while (!omp_private_member_vec.is_empty ())
9351 : {
9352 920 : tree t = omp_private_member_vec.pop ();
9353 920 : if (t == error_mark_node)
9354 : {
9355 20 : add_stmt (stmt);
9356 20 : return;
9357 : }
9358 900 : bool no_decl_expr = t == integer_zero_node;
9359 900 : if (no_decl_expr)
9360 147 : t = omp_private_member_vec.pop ();
9361 900 : tree *v = omp_private_member_map->get (t);
9362 900 : gcc_assert (v);
9363 900 : if (!no_decl_expr)
9364 753 : add_decl_expr (*v);
9365 900 : omp_private_member_map->remove (t);
9366 : }
9367 950 : delete omp_private_member_map;
9368 475 : omp_private_member_map = NULL;
9369 : }
9370 48732 : add_stmt (stmt);
9371 : }
9372 :
9373 : /* Remember OpenMP privatization clauses mapping and clear it.
9374 : Used for lambdas. */
9375 :
9376 : void
9377 1783012 : save_omp_privatization_clauses (vec<tree> &save)
9378 : {
9379 1783012 : save = vNULL;
9380 1783012 : if (omp_private_member_ignore_next)
9381 2 : save.safe_push (integer_one_node);
9382 1783012 : omp_private_member_ignore_next = false;
9383 1783012 : if (!omp_private_member_map)
9384 : return;
9385 :
9386 0 : while (!omp_private_member_vec.is_empty ())
9387 : {
9388 0 : tree t = omp_private_member_vec.pop ();
9389 0 : if (t == error_mark_node)
9390 : {
9391 0 : save.safe_push (t);
9392 0 : continue;
9393 : }
9394 0 : tree n = t;
9395 0 : if (t == integer_zero_node)
9396 0 : t = omp_private_member_vec.pop ();
9397 0 : tree *v = omp_private_member_map->get (t);
9398 0 : gcc_assert (v);
9399 0 : save.safe_push (*v);
9400 0 : save.safe_push (t);
9401 0 : if (n != t)
9402 0 : save.safe_push (n);
9403 : }
9404 0 : delete omp_private_member_map;
9405 0 : omp_private_member_map = NULL;
9406 : }
9407 :
9408 : /* Restore OpenMP privatization clauses mapping saved by the
9409 : above function. */
9410 :
9411 : void
9412 1783012 : restore_omp_privatization_clauses (vec<tree> &save)
9413 : {
9414 1783012 : gcc_assert (omp_private_member_vec.is_empty ());
9415 1783012 : omp_private_member_ignore_next = false;
9416 1783012 : if (save.is_empty ())
9417 : return;
9418 4 : if (save.length () == 1 && save[0] == integer_one_node)
9419 : {
9420 2 : omp_private_member_ignore_next = true;
9421 2 : save.release ();
9422 2 : return;
9423 : }
9424 :
9425 0 : omp_private_member_map = new hash_map <tree, tree>;
9426 0 : while (!save.is_empty ())
9427 : {
9428 0 : tree t = save.pop ();
9429 0 : tree n = t;
9430 0 : if (t != error_mark_node)
9431 : {
9432 0 : if (t == integer_one_node)
9433 : {
9434 0 : omp_private_member_ignore_next = true;
9435 0 : gcc_assert (save.is_empty ());
9436 0 : break;
9437 : }
9438 0 : if (t == integer_zero_node)
9439 0 : t = save.pop ();
9440 0 : tree &v = omp_private_member_map->get_or_insert (t);
9441 0 : v = save.pop ();
9442 : }
9443 0 : omp_private_member_vec.safe_push (t);
9444 0 : if (n != t)
9445 0 : omp_private_member_vec.safe_push (n);
9446 : }
9447 0 : save.release ();
9448 : }
9449 :
9450 : /* For all variables in the tree_list VARS, mark them as thread local. */
9451 :
9452 : void
9453 230 : finish_omp_threadprivate (tree vars)
9454 : {
9455 230 : tree t;
9456 :
9457 : /* Mark every variable in VARS to be assigned thread local storage. */
9458 499 : for (t = vars; t; t = TREE_CHAIN (t))
9459 : {
9460 269 : tree v = TREE_PURPOSE (t);
9461 :
9462 269 : if (error_operand_p (v))
9463 : ;
9464 269 : else if (!VAR_P (v))
9465 8 : error ("%<threadprivate%> %qD is not file, namespace "
9466 : "or block scope variable", v);
9467 : /* If V had already been marked threadprivate, it doesn't matter
9468 : whether it had been used prior to this point. */
9469 261 : else if (TREE_USED (v)
9470 261 : && (DECL_LANG_SPECIFIC (v) == NULL
9471 0 : || !CP_DECL_THREADPRIVATE_P (v)))
9472 4 : error ("%qE declared %<threadprivate%> after first use", v);
9473 257 : else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
9474 4 : error ("automatic variable %qE cannot be %<threadprivate%>", v);
9475 253 : else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
9476 4 : error ("%<threadprivate%> %qE has incomplete type", v);
9477 198 : else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
9478 266 : && CP_DECL_CONTEXT (v) != current_class_type)
9479 8 : error ("%<threadprivate%> %qE directive not "
9480 8 : "in %qT definition", v, CP_DECL_CONTEXT (v));
9481 : else
9482 : {
9483 : /* Allocate a LANG_SPECIFIC structure for V, if needed. */
9484 241 : if (DECL_LANG_SPECIFIC (v) == NULL)
9485 200 : retrofit_lang_decl (v);
9486 :
9487 241 : if (! CP_DECL_THREAD_LOCAL_P (v))
9488 : {
9489 241 : CP_DECL_THREAD_LOCAL_P (v) = true;
9490 241 : set_decl_tls_model (v, decl_default_tls_model (v));
9491 : /* If rtl has been already set for this var, call
9492 : make_decl_rtl once again, so that encode_section_info
9493 : has a chance to look at the new decl flags. */
9494 241 : if (DECL_RTL_SET_P (v))
9495 0 : make_decl_rtl (v);
9496 : }
9497 241 : CP_DECL_THREADPRIVATE_P (v) = 1;
9498 : }
9499 : }
9500 230 : }
9501 :
9502 : /* Build an OpenMP structured block. */
9503 :
9504 : tree
9505 65195 : begin_omp_structured_block (void)
9506 : {
9507 46640 : return do_pushlevel (sk_omp);
9508 : }
9509 :
9510 : tree
9511 65191 : finish_omp_structured_block (tree block)
9512 : {
9513 46636 : return do_poplevel (block);
9514 : }
9515 :
9516 : /* Similarly, except force the retention of the BLOCK. */
9517 :
9518 : tree
9519 15629 : begin_omp_parallel (void)
9520 : {
9521 15629 : keep_next_level (true);
9522 15629 : return begin_omp_structured_block ();
9523 : }
9524 :
9525 : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
9526 : statement. */
9527 :
9528 : tree
9529 683 : finish_oacc_data (tree clauses, tree block)
9530 : {
9531 683 : tree stmt;
9532 :
9533 683 : block = finish_omp_structured_block (block);
9534 :
9535 683 : stmt = make_node (OACC_DATA);
9536 683 : TREE_TYPE (stmt) = void_type_node;
9537 683 : OACC_DATA_CLAUSES (stmt) = clauses;
9538 683 : OACC_DATA_BODY (stmt) = block;
9539 :
9540 683 : return add_stmt (stmt);
9541 : }
9542 :
9543 : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
9544 : statement. */
9545 :
9546 : tree
9547 76 : finish_oacc_host_data (tree clauses, tree block)
9548 : {
9549 76 : tree stmt;
9550 :
9551 76 : block = finish_omp_structured_block (block);
9552 :
9553 76 : stmt = make_node (OACC_HOST_DATA);
9554 76 : TREE_TYPE (stmt) = void_type_node;
9555 76 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
9556 76 : OACC_HOST_DATA_BODY (stmt) = block;
9557 :
9558 76 : return add_stmt (stmt);
9559 : }
9560 :
9561 : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
9562 : statement. */
9563 :
9564 : tree
9565 5003 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
9566 : {
9567 5003 : body = finish_omp_structured_block (body);
9568 :
9569 5003 : tree stmt = make_node (code);
9570 5003 : TREE_TYPE (stmt) = void_type_node;
9571 5003 : OMP_BODY (stmt) = body;
9572 5003 : OMP_CLAUSES (stmt) = clauses;
9573 :
9574 5003 : return add_stmt (stmt);
9575 : }
9576 :
9577 : /* Used to walk OpenMP target directive body. */
9578 :
9579 : struct omp_target_walk_data
9580 : {
9581 : /* Holds the 'this' expression found in current function. */
9582 : tree current_object;
9583 :
9584 : /* True if the 'this' expression was accessed in the target body. */
9585 : bool this_expr_accessed;
9586 :
9587 : /* For non-static functions, record which pointer-typed members were
9588 : accessed, and the whole expression. */
9589 : hash_map<tree, tree> ptr_members_accessed;
9590 :
9591 : /* Record which lambda objects were accessed in target body. */
9592 : hash_set<tree> lambda_objects_accessed;
9593 :
9594 : /* For lambda functions, the __closure object expression of the current
9595 : function, and the set of captured variables accessed in target body. */
9596 : tree current_closure;
9597 : hash_set<tree> closure_vars_accessed;
9598 :
9599 : /* Local variables declared inside a BIND_EXPR, used to filter out such
9600 : variables when recording lambda_objects_accessed. */
9601 : hash_set<tree> local_decls;
9602 : };
9603 :
9604 : /* Helper function of finish_omp_target_clauses, called via
9605 : cp_walk_tree_without_duplicates. Traverse body of OpenMP target
9606 : directive *TP, and fill out omp_target_walk_data passed in *PTR. */
9607 :
9608 : static tree
9609 198116 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
9610 : {
9611 198116 : tree t = *tp;
9612 198116 : struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
9613 198116 : tree current_object = data->current_object;
9614 198116 : tree current_closure = data->current_closure;
9615 :
9616 : /* References inside of these expression codes shouldn't incur any
9617 : form of mapping, so return early. */
9618 198116 : if (TREE_CODE (t) == SIZEOF_EXPR
9619 198108 : || TREE_CODE (t) == ALIGNOF_EXPR)
9620 : {
9621 8 : *walk_subtrees = 0;
9622 8 : return NULL_TREE;
9623 : }
9624 :
9625 198108 : if (TREE_CODE (t) == OMP_CLAUSE)
9626 : return NULL_TREE;
9627 :
9628 184519 : if (current_object)
9629 : {
9630 1094 : tree this_expr = TREE_OPERAND (current_object, 0);
9631 :
9632 1094 : if (operand_equal_p (t, this_expr))
9633 : {
9634 28 : data->this_expr_accessed = true;
9635 28 : *walk_subtrees = 0;
9636 28 : return NULL_TREE;
9637 : }
9638 :
9639 1066 : if (TREE_CODE (t) == COMPONENT_REF
9640 104 : && POINTER_TYPE_P (TREE_TYPE (t))
9641 33 : && operand_equal_p (TREE_OPERAND (t, 0), current_object)
9642 1099 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
9643 : {
9644 33 : data->this_expr_accessed = true;
9645 33 : tree fld = TREE_OPERAND (t, 1);
9646 33 : if (data->ptr_members_accessed.get (fld) == NULL)
9647 : {
9648 12 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
9649 5 : t = convert_from_reference (t);
9650 12 : data->ptr_members_accessed.put (fld, t);
9651 : }
9652 33 : *walk_subtrees = 0;
9653 33 : return NULL_TREE;
9654 : }
9655 : }
9656 :
9657 : /* When the current_function_decl is a lambda function, the closure object
9658 : argument's type seems to not yet have fields layed out, so a recording
9659 : of DECL_VALUE_EXPRs during the target body walk seems the only way to
9660 : find them. */
9661 184458 : if (current_closure
9662 208 : && (VAR_P (t)
9663 208 : || TREE_CODE (t) == PARM_DECL
9664 192 : || TREE_CODE (t) == RESULT_DECL)
9665 16 : && DECL_HAS_VALUE_EXPR_P (t)
9666 6 : && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
9667 184464 : && operand_equal_p (current_closure,
9668 6 : TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
9669 : {
9670 6 : if (!data->closure_vars_accessed.contains (t))
9671 6 : data->closure_vars_accessed.add (t);
9672 6 : *walk_subtrees = 0;
9673 6 : return NULL_TREE;
9674 : }
9675 :
9676 184452 : if (TREE_CODE (t) == BIND_EXPR)
9677 : {
9678 17444 : tree block = BIND_EXPR_BLOCK (t);
9679 19071 : for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
9680 1627 : if (!data->local_decls.contains (var))
9681 1627 : data->local_decls.add (var);
9682 17444 : return NULL_TREE;
9683 : }
9684 :
9685 168374 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
9686 : {
9687 15 : tree lt = TREE_TYPE (t);
9688 15 : gcc_assert (CLASS_TYPE_P (lt));
9689 :
9690 15 : if (!data->lambda_objects_accessed.contains (t)
9691 : /* Do not prepare to create target maps for locally declared
9692 : lambdas or anonymous ones. */
9693 15 : && !data->local_decls.contains (t)
9694 28 : && TREE_CODE (t) != TARGET_EXPR)
9695 2 : data->lambda_objects_accessed.add (t);
9696 15 : *walk_subtrees = 0;
9697 15 : return NULL_TREE;
9698 : }
9699 :
9700 : return NULL_TREE;
9701 : }
9702 :
9703 : /* Helper function for finish_omp_target, and also from tsubst_expr.
9704 : Create additional clauses for mapping of non-static members, lambda objects,
9705 : etc. */
9706 :
9707 : void
9708 5940 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
9709 : {
9710 5940 : omp_target_walk_data data;
9711 5940 : data.this_expr_accessed = false;
9712 5940 : data.current_object = NULL_TREE;
9713 :
9714 5940 : if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
9715 57 : if (tree ct = current_nonlambda_class_type ())
9716 : {
9717 57 : tree object = maybe_dummy_object (ct, NULL);
9718 57 : object = maybe_resolve_dummy (object, true);
9719 57 : data.current_object = object;
9720 : }
9721 :
9722 5940 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
9723 : {
9724 5 : tree closure = DECL_ARGUMENTS (current_function_decl);
9725 5 : data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
9726 : }
9727 : else
9728 5935 : data.current_closure = NULL_TREE;
9729 :
9730 5940 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r, &data);
9731 :
9732 5940 : auto_vec<tree, 16> new_clauses;
9733 :
9734 5940 : tree omp_target_this_expr = NULL_TREE;
9735 5940 : tree *explicit_this_deref_map = NULL;
9736 5940 : if (data.this_expr_accessed)
9737 : {
9738 25 : omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
9739 :
9740 : /* See if explicit user-specified map(this[:]) clause already exists.
9741 : If not, we create an implicit map(tofrom:this[:1]) clause. */
9742 54 : for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
9743 30 : if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
9744 29 : && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
9745 27 : || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
9746 32 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
9747 : omp_target_this_expr))
9748 : {
9749 : explicit_this_deref_map = cp;
9750 : break;
9751 : }
9752 : }
9753 :
9754 5940 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
9755 5940 : && (data.this_expr_accessed
9756 0 : || !data.closure_vars_accessed.is_empty ()))
9757 : {
9758 : /* For lambda functions, we need to first create a copy of the
9759 : __closure object. */
9760 5 : tree closure = DECL_ARGUMENTS (current_function_decl);
9761 5 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
9762 5 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
9763 5 : OMP_CLAUSE_DECL (c)
9764 5 : = build_indirect_ref (loc, closure, RO_UNARY_STAR);
9765 5 : OMP_CLAUSE_SIZE (c)
9766 5 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
9767 5 : new_clauses.safe_push (c);
9768 :
9769 5 : tree closure_obj = OMP_CLAUSE_DECL (c);
9770 5 : tree closure_type = TREE_TYPE (closure_obj);
9771 :
9772 10 : gcc_assert (LAMBDA_TYPE_P (closure_type)
9773 : && CLASS_TYPE_P (closure_type));
9774 :
9775 5 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
9776 5 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
9777 5 : OMP_CLAUSE_DECL (c2) = closure;
9778 5 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
9779 5 : new_clauses.safe_push (c2);
9780 : }
9781 :
9782 5940 : if (data.this_expr_accessed)
9783 : {
9784 : /* If the this-expr was accessed, create a map(*this) clause. */
9785 25 : enum gomp_map_kind kind = GOMP_MAP_TOFROM;
9786 25 : if (explicit_this_deref_map)
9787 : {
9788 1 : tree this_map = *explicit_this_deref_map;
9789 1 : tree nc = OMP_CLAUSE_CHAIN (this_map);
9790 2 : gcc_assert (nc != NULL_TREE
9791 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
9792 : && (OMP_CLAUSE_MAP_KIND (nc)
9793 : == GOMP_MAP_FIRSTPRIVATE_POINTER));
9794 1 : kind = OMP_CLAUSE_MAP_KIND (this_map);
9795 : /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
9796 : two-map sequence away from the chain. */
9797 1 : *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
9798 : }
9799 25 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
9800 25 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
9801 25 : OMP_CLAUSE_DECL (c)
9802 25 : = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
9803 25 : OMP_CLAUSE_SIZE (c)
9804 25 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
9805 25 : new_clauses.safe_push (c);
9806 :
9807 : /* If we're in a lambda function, the this-pointer will actually be
9808 : '__closure->this', a mapped member of __closure, hence always_pointer.
9809 : Otherwise it's a firstprivate pointer. */
9810 25 : enum gomp_map_kind ptr_kind
9811 25 : = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
9812 25 : ? GOMP_MAP_ALWAYS_POINTER
9813 25 : : GOMP_MAP_FIRSTPRIVATE_POINTER);
9814 25 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
9815 25 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
9816 25 : OMP_CLAUSE_DECL (c) = omp_target_this_expr;
9817 25 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9818 25 : new_clauses.safe_push (c);
9819 : }
9820 :
9821 5940 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
9822 : {
9823 5 : if (omp_target_this_expr)
9824 : {
9825 5 : STRIP_NOPS (omp_target_this_expr);
9826 5 : gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
9827 5 : omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
9828 : }
9829 :
9830 11 : for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
9831 16 : i != data.closure_vars_accessed.end (); ++i)
9832 : {
9833 6 : tree orig_decl = *i;
9834 6 : tree closure_expr = DECL_VALUE_EXPR (orig_decl);
9835 :
9836 6 : if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
9837 6 : || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
9838 : {
9839 : /* this-pointer is processed above, outside this loop. */
9840 1 : if (omp_target_this_expr
9841 1 : && operand_equal_p (closure_expr, omp_target_this_expr))
9842 0 : continue;
9843 :
9844 1 : bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
9845 1 : enum gomp_map_kind kind, ptr_kind, nc_kind;
9846 1 : tree size;
9847 :
9848 1 : if (ptr_p)
9849 : {
9850 : /* For pointers, default mapped as zero-length array
9851 : section. */
9852 1 : kind = GOMP_MAP_ALLOC;
9853 1 : nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
9854 1 : ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
9855 1 : size = size_zero_node;
9856 : }
9857 : else
9858 : {
9859 : /* For references, default mapped as appearing on map
9860 : clause. */
9861 0 : kind = GOMP_MAP_TOFROM;
9862 0 : nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
9863 0 : ptr_kind = GOMP_MAP_ALWAYS_POINTER;
9864 0 : size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
9865 : }
9866 :
9867 2 : for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
9868 1 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
9869 1 : && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
9870 1 : || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
9871 1 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
9872 : orig_decl))
9873 : {
9874 : /* If this was already specified by user as a map,
9875 : save the user specified map kind, delete the
9876 : "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
9877 : and insert our own sequence:
9878 : "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
9879 : */
9880 0 : tree nc = OMP_CLAUSE_CHAIN (*p);
9881 0 : gcc_assert (nc != NULL_TREE
9882 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
9883 : && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
9884 : /* Update with user specified kind and size. */
9885 0 : kind = OMP_CLAUSE_MAP_KIND (*p);
9886 0 : size = OMP_CLAUSE_SIZE (*p);
9887 0 : *p = OMP_CLAUSE_CHAIN (nc);
9888 0 : break;
9889 : }
9890 :
9891 1 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
9892 1 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
9893 1 : OMP_CLAUSE_DECL (c)
9894 1 : = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
9895 1 : OMP_CLAUSE_SIZE (c) = size;
9896 1 : if (ptr_p)
9897 1 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
9898 1 : new_clauses.safe_push (c);
9899 :
9900 1 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
9901 1 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
9902 1 : OMP_CLAUSE_DECL (c) = closure_expr;
9903 1 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9904 1 : new_clauses.safe_push (c);
9905 : }
9906 : }
9907 : }
9908 :
9909 5940 : if (!data.ptr_members_accessed.is_empty ())
9910 12 : for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
9911 36 : i != data.ptr_members_accessed.end (); ++i)
9912 : {
9913 : /* For each referenced member that is of pointer or reference-to-pointer
9914 : type, create the equivalent of map(alloc:this->ptr[:0]). */
9915 12 : tree field_decl = (*i).first;
9916 12 : tree ptr_member = (*i).second;
9917 :
9918 25 : for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
9919 : {
9920 14 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9921 1 : continue;
9922 : /* If map(this->ptr[:N]) already exists, avoid creating another
9923 : such map. */
9924 13 : tree decl = OMP_CLAUSE_DECL (c);
9925 13 : if ((TREE_CODE (decl) == INDIRECT_REF
9926 13 : || TREE_CODE (decl) == MEM_REF)
9927 13 : && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
9928 1 : goto next_ptr_member;
9929 : }
9930 :
9931 11 : if (!cxx_mark_addressable (ptr_member))
9932 0 : gcc_unreachable ();
9933 :
9934 11 : if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
9935 : {
9936 : /* For reference to pointers, we need to map the referenced
9937 : pointer first for things to be correct. */
9938 5 : tree ptr_member_type = TREE_TYPE (ptr_member);
9939 :
9940 : /* Map pointer target as zero-length array section. */
9941 5 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
9942 5 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
9943 5 : OMP_CLAUSE_DECL (c)
9944 5 : = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
9945 5 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9946 5 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
9947 :
9948 : /* Map pointer to zero-length array section. */
9949 5 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
9950 5 : OMP_CLAUSE_SET_MAP_KIND
9951 : (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
9952 5 : OMP_CLAUSE_DECL (c2) = ptr_member;
9953 5 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
9954 :
9955 : /* Attach reference-to-pointer field to pointer. */
9956 5 : tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
9957 5 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
9958 5 : OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
9959 5 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
9960 :
9961 5 : new_clauses.safe_push (c);
9962 5 : new_clauses.safe_push (c2);
9963 5 : new_clauses.safe_push (c3);
9964 : }
9965 6 : else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
9966 : {
9967 : /* Map pointer target as zero-length array section. */
9968 6 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
9969 6 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
9970 6 : OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
9971 : RO_UNARY_STAR);
9972 6 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9973 6 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
9974 :
9975 : /* Attach zero-length array section to pointer. */
9976 6 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
9977 6 : OMP_CLAUSE_SET_MAP_KIND
9978 : (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
9979 6 : OMP_CLAUSE_DECL (c2) = ptr_member;
9980 6 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
9981 :
9982 6 : new_clauses.safe_push (c);
9983 6 : new_clauses.safe_push (c2);
9984 : }
9985 : else
9986 0 : gcc_unreachable ();
9987 :
9988 12 : next_ptr_member:
9989 12 : ;
9990 : }
9991 :
9992 5942 : for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
9993 5942 : i != data.lambda_objects_accessed.end (); ++i)
9994 : {
9995 2 : tree lobj = *i;
9996 2 : if (TREE_CODE (lobj) == TARGET_EXPR)
9997 0 : lobj = TREE_OPERAND (lobj, 0);
9998 :
9999 2 : tree lt = TREE_TYPE (lobj);
10000 4 : gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
10001 :
10002 2 : tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
10003 2 : OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
10004 2 : OMP_CLAUSE_DECL (lc) = lobj;
10005 2 : OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
10006 2 : new_clauses.safe_push (lc);
10007 :
10008 34 : for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
10009 : {
10010 32 : if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
10011 : {
10012 2 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
10013 : lobj, fld, NULL_TREE);
10014 2 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10015 2 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
10016 2 : OMP_CLAUSE_DECL (c)
10017 2 : = build_indirect_ref (loc, exp, RO_UNARY_STAR);
10018 2 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10019 2 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
10020 2 : new_clauses.safe_push (c);
10021 :
10022 2 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10023 2 : OMP_CLAUSE_SET_MAP_KIND
10024 : (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
10025 2 : OMP_CLAUSE_DECL (c) = exp;
10026 2 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10027 2 : new_clauses.safe_push (c);
10028 : }
10029 30 : else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
10030 : {
10031 0 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
10032 : lobj, fld, NULL_TREE);
10033 0 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10034 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
10035 0 : OMP_CLAUSE_DECL (c)
10036 0 : = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
10037 0 : OMP_CLAUSE_SIZE (c)
10038 0 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
10039 0 : new_clauses.safe_push (c);
10040 :
10041 0 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10042 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
10043 0 : OMP_CLAUSE_DECL (c) = exp;
10044 0 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10045 0 : new_clauses.safe_push (c);
10046 : }
10047 : }
10048 : }
10049 :
10050 5940 : tree c = *clauses_ptr;
10051 11975 : for (int i = new_clauses.length () - 1; i >= 0; i--)
10052 : {
10053 95 : OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
10054 95 : c = new_clauses[i];
10055 : }
10056 5940 : *clauses_ptr = c;
10057 5940 : }
10058 :
10059 : /* Called from cp_parser_omp_target. Create additional implicit clauses for
10060 : OpenMP target directives, and do sanity checks. */
10061 :
10062 : tree
10063 5931 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
10064 : {
10065 5931 : if (!processing_template_decl)
10066 5432 : finish_omp_target_clauses (loc, body, &clauses);
10067 :
10068 5931 : tree stmt = make_node (OMP_TARGET);
10069 5931 : TREE_TYPE (stmt) = void_type_node;
10070 5931 : OMP_TARGET_CLAUSES (stmt) = clauses;
10071 5931 : OMP_TARGET_BODY (stmt) = body;
10072 5931 : OMP_TARGET_COMBINED (stmt) = combined_p;
10073 5931 : SET_EXPR_LOCATION (stmt, loc);
10074 :
10075 5931 : tree c = clauses;
10076 13381 : while (c)
10077 : {
10078 7450 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
10079 3328 : switch (OMP_CLAUSE_MAP_KIND (c))
10080 : {
10081 : case GOMP_MAP_TO:
10082 : case GOMP_MAP_ALWAYS_TO:
10083 : case GOMP_MAP_PRESENT_TO:
10084 : case GOMP_MAP_ALWAYS_PRESENT_TO:
10085 : case GOMP_MAP_FROM:
10086 : case GOMP_MAP_ALWAYS_FROM:
10087 : case GOMP_MAP_PRESENT_FROM:
10088 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
10089 : case GOMP_MAP_TOFROM:
10090 : case GOMP_MAP_ALWAYS_TOFROM:
10091 : case GOMP_MAP_PRESENT_TOFROM:
10092 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
10093 : case GOMP_MAP_ALLOC:
10094 : case GOMP_MAP_PRESENT_ALLOC:
10095 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
10096 : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
10097 : case GOMP_MAP_ALWAYS_POINTER:
10098 : case GOMP_MAP_ATTACH_DETACH:
10099 : case GOMP_MAP_ATTACH:
10100 : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
10101 : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
10102 : break;
10103 4 : default:
10104 4 : error_at (OMP_CLAUSE_LOCATION (c),
10105 : "%<#pragma omp target%> with map-type other "
10106 : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
10107 : "on %<map%> clause");
10108 4 : break;
10109 : }
10110 7450 : c = OMP_CLAUSE_CHAIN (c);
10111 : }
10112 5931 : return add_stmt (stmt);
10113 : }
10114 :
10115 : tree
10116 9867 : finish_omp_parallel (tree clauses, tree body)
10117 : {
10118 9867 : tree stmt;
10119 :
10120 9867 : body = finish_omp_structured_block (body);
10121 :
10122 9867 : stmt = make_node (OMP_PARALLEL);
10123 9867 : TREE_TYPE (stmt) = void_type_node;
10124 9867 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
10125 9867 : OMP_PARALLEL_BODY (stmt) = body;
10126 :
10127 9867 : return add_stmt (stmt);
10128 : }
10129 :
10130 : tree
10131 2926 : begin_omp_task (void)
10132 : {
10133 2926 : keep_next_level (true);
10134 2926 : return begin_omp_structured_block ();
10135 : }
10136 :
10137 : tree
10138 2926 : finish_omp_task (tree clauses, tree body)
10139 : {
10140 2926 : tree stmt;
10141 :
10142 2926 : body = finish_omp_structured_block (body);
10143 :
10144 2926 : stmt = make_node (OMP_TASK);
10145 2926 : TREE_TYPE (stmt) = void_type_node;
10146 2926 : OMP_TASK_CLAUSES (stmt) = clauses;
10147 2926 : OMP_TASK_BODY (stmt) = body;
10148 :
10149 2926 : return add_stmt (stmt);
10150 : }
10151 :
10152 : /* Helper function for finish_omp_for. Convert Ith random access iterator
10153 : into integral iterator. Return FALSE if successful. */
10154 :
10155 : static bool
10156 859 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
10157 : tree declv, tree orig_declv, tree initv,
10158 : tree condv, tree incrv, tree *body,
10159 : tree *pre_body, tree &clauses,
10160 : int collapse, int ordered)
10161 : {
10162 859 : tree diff, iter_init, iter_incr = NULL, last;
10163 859 : tree incr_var = NULL, orig_pre_body, orig_body, c;
10164 859 : tree decl = TREE_VEC_ELT (declv, i);
10165 859 : tree init = TREE_VEC_ELT (initv, i);
10166 859 : tree cond = TREE_VEC_ELT (condv, i);
10167 859 : tree incr = TREE_VEC_ELT (incrv, i);
10168 859 : tree iter = decl;
10169 859 : location_t elocus = locus;
10170 :
10171 859 : if (init && EXPR_HAS_LOCATION (init))
10172 4 : elocus = EXPR_LOCATION (init);
10173 :
10174 859 : switch (TREE_CODE (cond))
10175 : {
10176 855 : case GT_EXPR:
10177 855 : case GE_EXPR:
10178 855 : case LT_EXPR:
10179 855 : case LE_EXPR:
10180 855 : case NE_EXPR:
10181 855 : if (TREE_OPERAND (cond, 1) == iter)
10182 50 : cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
10183 50 : TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
10184 855 : if (TREE_OPERAND (cond, 0) != iter)
10185 0 : cond = error_mark_node;
10186 : else
10187 : {
10188 855 : tree tem = build_x_binary_op (EXPR_LOCATION (cond),
10189 855 : TREE_CODE (cond),
10190 : iter, ERROR_MARK,
10191 855 : TREE_OPERAND (cond, 1), ERROR_MARK,
10192 : NULL_TREE, NULL, tf_warning_or_error);
10193 855 : if (error_operand_p (tem))
10194 : return true;
10195 : }
10196 : break;
10197 4 : default:
10198 4 : cond = error_mark_node;
10199 4 : break;
10200 : }
10201 856 : if (cond == error_mark_node)
10202 : {
10203 4 : error_at (elocus, "invalid controlling predicate");
10204 4 : return true;
10205 : }
10206 852 : diff = build_x_binary_op (elocus, MINUS_EXPR,
10207 852 : TREE_OPERAND (cond, 1), ERROR_MARK,
10208 : iter, ERROR_MARK,
10209 : NULL_TREE, NULL, tf_warning_or_error);
10210 852 : diff = cp_fully_fold (diff);
10211 852 : if (error_operand_p (diff))
10212 : return true;
10213 852 : if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
10214 : {
10215 0 : error_at (elocus, "difference between %qE and %qD does not have integer type",
10216 0 : TREE_OPERAND (cond, 1), iter);
10217 0 : return true;
10218 : }
10219 852 : if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
10220 852 : TREE_VEC_ELT (declv, i), NULL_TREE,
10221 : cond, cp_walk_subtrees))
10222 : return true;
10223 :
10224 792 : switch (TREE_CODE (incr))
10225 : {
10226 338 : case PREINCREMENT_EXPR:
10227 338 : case PREDECREMENT_EXPR:
10228 338 : case POSTINCREMENT_EXPR:
10229 338 : case POSTDECREMENT_EXPR:
10230 338 : if (TREE_OPERAND (incr, 0) != iter)
10231 : {
10232 0 : incr = error_mark_node;
10233 0 : break;
10234 : }
10235 338 : iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
10236 : TREE_CODE (incr), iter,
10237 : NULL_TREE, tf_warning_or_error);
10238 338 : if (error_operand_p (iter_incr))
10239 : return true;
10240 338 : else if (TREE_CODE (incr) == PREINCREMENT_EXPR
10241 248 : || TREE_CODE (incr) == POSTINCREMENT_EXPR)
10242 263 : incr = integer_one_node;
10243 : else
10244 75 : incr = integer_minus_one_node;
10245 : break;
10246 454 : case MODIFY_EXPR:
10247 454 : if (TREE_OPERAND (incr, 0) != iter)
10248 0 : incr = error_mark_node;
10249 454 : else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
10250 454 : || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
10251 : {
10252 454 : tree rhs = TREE_OPERAND (incr, 1);
10253 454 : if (TREE_OPERAND (rhs, 0) == iter)
10254 : {
10255 338 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
10256 : != INTEGER_TYPE)
10257 0 : incr = error_mark_node;
10258 : else
10259 : {
10260 338 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
10261 338 : iter, TREE_CODE (rhs),
10262 338 : TREE_OPERAND (rhs, 1),
10263 : NULL_TREE,
10264 : tf_warning_or_error);
10265 338 : if (error_operand_p (iter_incr))
10266 : return true;
10267 338 : incr = TREE_OPERAND (rhs, 1);
10268 338 : incr = cp_convert (TREE_TYPE (diff), incr,
10269 : tf_warning_or_error);
10270 338 : if (TREE_CODE (rhs) == MINUS_EXPR)
10271 : {
10272 16 : incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
10273 16 : incr = fold_simple (incr);
10274 : }
10275 338 : if (TREE_CODE (incr) != INTEGER_CST
10276 338 : && (TREE_CODE (incr) != NOP_EXPR
10277 76 : || (TREE_CODE (TREE_OPERAND (incr, 0))
10278 : != INTEGER_CST)))
10279 : iter_incr = NULL;
10280 : }
10281 : }
10282 116 : else if (TREE_OPERAND (rhs, 1) == iter)
10283 : {
10284 116 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
10285 116 : || TREE_CODE (rhs) != PLUS_EXPR)
10286 0 : incr = error_mark_node;
10287 : else
10288 : {
10289 116 : iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
10290 : PLUS_EXPR,
10291 116 : TREE_OPERAND (rhs, 0),
10292 : ERROR_MARK, iter,
10293 : ERROR_MARK, NULL_TREE, NULL,
10294 : tf_warning_or_error);
10295 116 : if (error_operand_p (iter_incr))
10296 : return true;
10297 116 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
10298 : iter, NOP_EXPR,
10299 : iter_incr, NULL_TREE,
10300 : tf_warning_or_error);
10301 116 : if (error_operand_p (iter_incr))
10302 : return true;
10303 116 : incr = TREE_OPERAND (rhs, 0);
10304 116 : iter_incr = NULL;
10305 : }
10306 : }
10307 : else
10308 0 : incr = error_mark_node;
10309 : }
10310 : else
10311 0 : incr = error_mark_node;
10312 : break;
10313 0 : default:
10314 0 : incr = error_mark_node;
10315 0 : break;
10316 : }
10317 :
10318 792 : if (incr == error_mark_node)
10319 : {
10320 0 : error_at (elocus, "invalid increment expression");
10321 0 : return true;
10322 : }
10323 :
10324 792 : incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
10325 792 : incr = cp_fully_fold (incr);
10326 792 : tree loop_iv_seen = NULL_TREE;
10327 1828 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
10328 1156 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
10329 1156 : && OMP_CLAUSE_DECL (c) == iter)
10330 : {
10331 120 : if (code == OMP_TASKLOOP || code == OMP_LOOP)
10332 : {
10333 60 : loop_iv_seen = c;
10334 60 : OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
10335 : }
10336 : break;
10337 : }
10338 1036 : else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
10339 113 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
10340 1070 : && OMP_CLAUSE_DECL (c) == iter)
10341 : {
10342 30 : loop_iv_seen = c;
10343 30 : if (code == OMP_TASKLOOP)
10344 25 : OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
10345 : }
10346 :
10347 792 : decl = create_temporary_var (TREE_TYPE (diff));
10348 792 : pushdecl (decl);
10349 792 : add_decl_expr (decl);
10350 792 : last = create_temporary_var (TREE_TYPE (diff));
10351 792 : pushdecl (last);
10352 792 : add_decl_expr (last);
10353 792 : if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
10354 10 : && (!ordered || (i < collapse && collapse > 1)))
10355 : {
10356 10 : incr_var = create_temporary_var (TREE_TYPE (diff));
10357 10 : pushdecl (incr_var);
10358 10 : add_decl_expr (incr_var);
10359 : }
10360 1584 : gcc_assert (stmts_are_full_exprs_p ());
10361 792 : tree diffvar = NULL_TREE;
10362 792 : if (code == OMP_TASKLOOP)
10363 : {
10364 101 : if (!loop_iv_seen)
10365 : {
10366 38 : tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
10367 38 : OMP_CLAUSE_DECL (ivc) = iter;
10368 38 : cxx_omp_finish_clause (ivc, NULL, false);
10369 38 : OMP_CLAUSE_CHAIN (ivc) = clauses;
10370 38 : clauses = ivc;
10371 : }
10372 101 : tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
10373 101 : OMP_CLAUSE_DECL (lvc) = last;
10374 101 : OMP_CLAUSE_CHAIN (lvc) = clauses;
10375 101 : clauses = lvc;
10376 101 : diffvar = create_temporary_var (TREE_TYPE (diff));
10377 101 : pushdecl (diffvar);
10378 101 : add_decl_expr (diffvar);
10379 : }
10380 691 : else if (code == OMP_LOOP)
10381 : {
10382 43 : if (!loop_iv_seen)
10383 : {
10384 : /* While iterators on the loop construct are predetermined
10385 : lastprivate, if the decl is not declared inside of the
10386 : loop, OMP_CLAUSE_LASTPRIVATE should have been added
10387 : already. */
10388 16 : loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
10389 16 : OMP_CLAUSE_DECL (loop_iv_seen) = iter;
10390 16 : OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
10391 16 : clauses = loop_iv_seen;
10392 : }
10393 27 : else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
10394 : {
10395 5 : OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
10396 5 : OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
10397 5 : OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
10398 : }
10399 43 : if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
10400 21 : cxx_omp_finish_clause (loop_iv_seen, NULL, false);
10401 : }
10402 :
10403 792 : orig_pre_body = *pre_body;
10404 792 : *pre_body = push_stmt_list ();
10405 792 : if (orig_pre_body)
10406 636 : add_stmt (orig_pre_body);
10407 792 : if (init != NULL)
10408 62 : finish_expr_stmt (build_x_modify_expr (elocus,
10409 : iter, NOP_EXPR, init,
10410 : NULL_TREE, tf_warning_or_error));
10411 792 : init = build_int_cst (TREE_TYPE (diff), 0);
10412 792 : if (c && iter_incr == NULL
10413 28 : && (!ordered || (i < collapse && collapse > 1)))
10414 : {
10415 28 : if (incr_var)
10416 : {
10417 10 : finish_expr_stmt (build_x_modify_expr (elocus,
10418 : incr_var, NOP_EXPR,
10419 : incr, NULL_TREE,
10420 : tf_warning_or_error));
10421 10 : incr = incr_var;
10422 : }
10423 28 : iter_incr = build_x_modify_expr (elocus,
10424 : iter, PLUS_EXPR, incr,
10425 : NULL_TREE, tf_warning_or_error);
10426 : }
10427 792 : if (c && ordered && i < collapse && collapse > 1)
10428 792 : iter_incr = incr;
10429 792 : finish_expr_stmt (build_x_modify_expr (elocus,
10430 : last, NOP_EXPR, init,
10431 : NULL_TREE, tf_warning_or_error));
10432 792 : if (diffvar)
10433 : {
10434 101 : finish_expr_stmt (build_x_modify_expr (elocus,
10435 : diffvar, NOP_EXPR,
10436 : diff, NULL_TREE, tf_warning_or_error));
10437 101 : diff = diffvar;
10438 : }
10439 792 : *pre_body = pop_stmt_list (*pre_body);
10440 :
10441 1584 : cond = cp_build_binary_op (elocus,
10442 792 : TREE_CODE (cond), decl, diff,
10443 : tf_warning_or_error);
10444 792 : incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
10445 : elocus, incr, NULL_TREE);
10446 :
10447 792 : orig_body = *body;
10448 792 : *body = push_stmt_list ();
10449 792 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
10450 792 : iter_init = build_x_modify_expr (elocus,
10451 : iter, PLUS_EXPR, iter_init,
10452 : NULL_TREE, tf_warning_or_error);
10453 792 : if (iter_init != error_mark_node)
10454 788 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
10455 792 : finish_expr_stmt (iter_init);
10456 792 : finish_expr_stmt (build_x_modify_expr (elocus,
10457 : last, NOP_EXPR, decl,
10458 : NULL_TREE, tf_warning_or_error));
10459 792 : add_stmt (orig_body);
10460 792 : *body = pop_stmt_list (*body);
10461 :
10462 792 : if (c)
10463 : {
10464 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
10465 120 : if (!ordered)
10466 114 : finish_expr_stmt (iter_incr);
10467 : else
10468 : {
10469 6 : iter_init = decl;
10470 6 : if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
10471 2 : iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
10472 : iter_init, iter_incr);
10473 6 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
10474 6 : iter_init = build_x_modify_expr (elocus,
10475 : iter, PLUS_EXPR, iter_init,
10476 : NULL_TREE, tf_warning_or_error);
10477 6 : if (iter_init != error_mark_node)
10478 6 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
10479 6 : finish_expr_stmt (iter_init);
10480 : }
10481 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c)
10482 240 : = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
10483 : }
10484 :
10485 792 : if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
10486 : {
10487 50 : tree t = TREE_VEC_ELT (orig_declv, i);
10488 50 : gcc_assert (TREE_PURPOSE (t) == NULL_TREE
10489 : && TREE_VALUE (t) == NULL_TREE
10490 : && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
10491 50 : TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
10492 50 : TREE_VALUE (t) = last;
10493 : }
10494 : else
10495 742 : TREE_VEC_ELT (orig_declv, i)
10496 1484 : = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
10497 792 : TREE_VEC_ELT (declv, i) = decl;
10498 792 : TREE_VEC_ELT (initv, i) = init;
10499 792 : TREE_VEC_ELT (condv, i) = cond;
10500 792 : TREE_VEC_ELT (incrv, i) = incr;
10501 :
10502 792 : return false;
10503 : }
10504 :
10505 : /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
10506 : are directly for their associated operands in the statement. DECL
10507 : and INIT are a combo; if DECL is NULL then INIT ought to be a
10508 : MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
10509 : optional statements that need to go before the loop into its
10510 : sk_omp scope. */
10511 :
10512 : tree
10513 20937 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
10514 : tree orig_declv, tree initv, tree condv, tree incrv,
10515 : tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
10516 : {
10517 20937 : tree omp_for = NULL, orig_incr = NULL;
10518 20937 : tree decl = NULL, init, cond, incr;
10519 20937 : location_t elocus;
10520 20937 : int i;
10521 20937 : int collapse = 1;
10522 20937 : int ordered = 0;
10523 :
10524 20937 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
10525 20937 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
10526 20937 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
10527 20937 : if (TREE_VEC_LENGTH (declv) > 1)
10528 : {
10529 3591 : tree c;
10530 :
10531 3591 : c = omp_find_clause (clauses, OMP_CLAUSE_TILE);
10532 3591 : if (c)
10533 95 : collapse = list_length (OMP_CLAUSE_TILE_LIST (c));
10534 : else
10535 : {
10536 3496 : c = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE);
10537 3496 : if (c)
10538 3432 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c));
10539 3496 : if (collapse != TREE_VEC_LENGTH (declv))
10540 95 : ordered = TREE_VEC_LENGTH (declv);
10541 : }
10542 : }
10543 47593 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
10544 : {
10545 26704 : decl = TREE_VEC_ELT (declv, i);
10546 26704 : init = TREE_VEC_ELT (initv, i);
10547 26704 : cond = TREE_VEC_ELT (condv, i);
10548 26704 : incr = TREE_VEC_ELT (incrv, i);
10549 26704 : elocus = locus;
10550 :
10551 26704 : if (decl == NULL)
10552 : {
10553 17798 : if (init != NULL)
10554 17794 : switch (TREE_CODE (init))
10555 : {
10556 17281 : case MODIFY_EXPR:
10557 17281 : decl = TREE_OPERAND (init, 0);
10558 17281 : init = TREE_OPERAND (init, 1);
10559 17281 : break;
10560 489 : case MODOP_EXPR:
10561 489 : if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
10562 : {
10563 489 : decl = TREE_OPERAND (init, 0);
10564 489 : init = TREE_OPERAND (init, 2);
10565 : }
10566 : break;
10567 : default:
10568 : break;
10569 : }
10570 :
10571 17798 : if (decl == NULL)
10572 : {
10573 28 : error_at (locus,
10574 : "expected iteration declaration or initialization");
10575 28 : return NULL;
10576 : }
10577 : }
10578 :
10579 26676 : if (init && EXPR_HAS_LOCATION (init))
10580 2451 : elocus = EXPR_LOCATION (init);
10581 :
10582 26676 : if (cond == global_namespace)
10583 78 : continue;
10584 :
10585 26598 : if (cond == NULL)
10586 : {
10587 12 : error_at (elocus, "missing controlling predicate");
10588 12 : return NULL;
10589 : }
10590 :
10591 26586 : if (incr == NULL)
10592 : {
10593 8 : error_at (elocus, "missing increment expression");
10594 8 : return NULL;
10595 : }
10596 :
10597 26578 : TREE_VEC_ELT (declv, i) = decl;
10598 26578 : TREE_VEC_ELT (initv, i) = init;
10599 : }
10600 :
10601 20889 : if (orig_inits)
10602 : {
10603 : bool fail = false;
10604 : tree orig_init;
10605 20976 : FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
10606 1128 : if (orig_init
10607 3287 : && !c_omp_check_loop_iv_exprs (locus, code,
10608 : orig_declv ? orig_declv : declv, i,
10609 1113 : TREE_VEC_ELT (declv, i), orig_init,
10610 : NULL_TREE, cp_walk_subtrees))
10611 : fail = true;
10612 19848 : if (fail)
10613 1119 : return NULL;
10614 : }
10615 :
10616 20820 : if (dependent_omp_for_p (declv, initv, condv, incrv))
10617 : {
10618 353 : tree stmt;
10619 :
10620 353 : stmt = make_node (code);
10621 :
10622 1140 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
10623 : {
10624 : /* This is really just a place-holder. We'll be decomposing this
10625 : again and going through the cp_build_modify_expr path below when
10626 : we instantiate the thing. */
10627 434 : TREE_VEC_ELT (initv, i)
10628 868 : = build2 (MODIFY_EXPR, void_type_node, TREE_VEC_ELT (declv, i),
10629 434 : TREE_VEC_ELT (initv, i));
10630 : }
10631 :
10632 353 : TREE_TYPE (stmt) = void_type_node;
10633 353 : OMP_FOR_INIT (stmt) = initv;
10634 353 : OMP_FOR_COND (stmt) = condv;
10635 353 : OMP_FOR_INCR (stmt) = incrv;
10636 353 : OMP_FOR_BODY (stmt) = body;
10637 353 : OMP_FOR_PRE_BODY (stmt) = pre_body;
10638 353 : OMP_FOR_CLAUSES (stmt) = clauses;
10639 :
10640 353 : SET_EXPR_LOCATION (stmt, locus);
10641 353 : return add_stmt (stmt);
10642 : }
10643 :
10644 20467 : if (!orig_declv)
10645 19745 : orig_declv = copy_node (declv);
10646 :
10647 20467 : if (processing_template_decl)
10648 777 : orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
10649 :
10650 47236 : for (i = 0; i < TREE_VEC_LENGTH (declv); )
10651 : {
10652 26891 : decl = TREE_VEC_ELT (declv, i);
10653 26891 : init = TREE_VEC_ELT (initv, i);
10654 26891 : cond = TREE_VEC_ELT (condv, i);
10655 26891 : incr = TREE_VEC_ELT (incrv, i);
10656 26891 : if (orig_incr)
10657 1054 : TREE_VEC_ELT (orig_incr, i) = incr;
10658 26891 : elocus = locus;
10659 :
10660 26891 : if (init && EXPR_HAS_LOCATION (init))
10661 2217 : elocus = EXPR_LOCATION (init);
10662 :
10663 26891 : if (!DECL_P (decl))
10664 : {
10665 12 : error_at (elocus, "expected iteration declaration or initialization");
10666 12 : return NULL;
10667 : }
10668 :
10669 26879 : if (incr && TREE_CODE (incr) == MODOP_EXPR)
10670 : {
10671 1 : if (orig_incr)
10672 1 : TREE_VEC_ELT (orig_incr, i) = incr;
10673 1 : incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
10674 1 : TREE_CODE (TREE_OPERAND (incr, 1)),
10675 1 : TREE_OPERAND (incr, 2),
10676 : tf_warning_or_error);
10677 : }
10678 :
10679 26879 : if (CLASS_TYPE_P (TREE_TYPE (decl)))
10680 : {
10681 875 : if (code == OMP_SIMD)
10682 : {
10683 16 : error_at (elocus, "%<#pragma omp simd%> used with class "
10684 : "iteration variable %qE", decl);
10685 16 : return NULL;
10686 : }
10687 859 : if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
10688 : initv, condv, incrv, &body,
10689 : &pre_body, clauses,
10690 : collapse, ordered))
10691 : return NULL;
10692 792 : continue;
10693 : }
10694 :
10695 52008 : if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
10696 27528 : && !TYPE_PTR_P (TREE_TYPE (decl)))
10697 : {
10698 15 : error_at (elocus, "invalid type for iteration variable %qE", decl);
10699 15 : return NULL;
10700 : }
10701 :
10702 25989 : if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
10703 25019 : init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
10704 : tf_warning_or_error);
10705 : else
10706 970 : init = build2 (MODIFY_EXPR, void_type_node, decl, init);
10707 25989 : if (decl == error_mark_node || init == error_mark_node)
10708 : return NULL;
10709 :
10710 25977 : TREE_VEC_ELT (declv, i) = decl;
10711 25977 : TREE_VEC_ELT (initv, i) = init;
10712 25977 : TREE_VEC_ELT (condv, i) = cond;
10713 25977 : TREE_VEC_ELT (incrv, i) = incr;
10714 25977 : i++;
10715 : }
10716 :
10717 20345 : if (pre_body && IS_EMPTY_STMT (pre_body))
10718 0 : pre_body = NULL;
10719 :
10720 40690 : omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
10721 : incrv, body, pre_body,
10722 20345 : !processing_template_decl);
10723 :
10724 : /* Check for iterators appearing in lb, b or incr expressions. */
10725 20345 : if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
10726 : omp_for = NULL_TREE;
10727 :
10728 19753 : if (omp_for == NULL)
10729 880 : return NULL;
10730 :
10731 19465 : add_stmt (omp_for);
10732 :
10733 44230 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
10734 : {
10735 24765 : init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
10736 24765 : decl = TREE_OPERAND (init, 0);
10737 24765 : cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
10738 24765 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
10739 :
10740 24765 : if (!processing_template_decl)
10741 : {
10742 24115 : if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
10743 : {
10744 110 : tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
10745 110 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
10746 110 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10747 110 : t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
10748 110 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
10749 220 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10750 : }
10751 : else
10752 : {
10753 24005 : tree t = TREE_OPERAND (init, 1);
10754 24005 : TREE_OPERAND (init, 1)
10755 48010 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10756 : }
10757 24115 : if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
10758 : {
10759 130 : tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
10760 130 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
10761 130 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10762 130 : t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
10763 130 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
10764 260 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10765 : }
10766 : else
10767 : {
10768 23985 : tree t = TREE_OPERAND (cond, 1);
10769 23985 : TREE_OPERAND (cond, 1)
10770 47970 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10771 : }
10772 : }
10773 :
10774 24765 : if (TREE_CODE (incr) != MODIFY_EXPR)
10775 18545 : continue;
10776 :
10777 6220 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
10778 77 : && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
10779 6297 : && !processing_template_decl)
10780 : {
10781 69 : tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
10782 69 : if (TREE_SIDE_EFFECTS (t)
10783 10 : && t != decl
10784 77 : && (TREE_CODE (t) != NOP_EXPR
10785 0 : || TREE_OPERAND (t, 0) != decl))
10786 8 : TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
10787 16 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10788 :
10789 69 : t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
10790 69 : if (TREE_SIDE_EFFECTS (t)
10791 59 : && t != decl
10792 128 : && (TREE_CODE (t) != NOP_EXPR
10793 7 : || TREE_OPERAND (t, 0) != decl))
10794 59 : TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
10795 118 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10796 : }
10797 :
10798 6220 : if (orig_incr)
10799 207 : TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
10800 : }
10801 19465 : OMP_FOR_CLAUSES (omp_for) = clauses;
10802 :
10803 : /* For simd loops with non-static data member iterators, we could have added
10804 : OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
10805 : step at this point, fill it in. */
10806 5356 : if (code == OMP_SIMD && !processing_template_decl
10807 24765 : && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
10808 5404 : for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
10809 670 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
10810 670 : if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
10811 : {
10812 4 : decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
10813 4 : gcc_assert (decl == OMP_CLAUSE_DECL (c));
10814 4 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
10815 4 : tree step, stept;
10816 4 : switch (TREE_CODE (incr))
10817 : {
10818 0 : case PREINCREMENT_EXPR:
10819 0 : case POSTINCREMENT_EXPR:
10820 : /* c_omp_for_incr_canonicalize_ptr() should have been
10821 : called to massage things appropriately. */
10822 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
10823 0 : OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
10824 0 : break;
10825 0 : case PREDECREMENT_EXPR:
10826 0 : case POSTDECREMENT_EXPR:
10827 : /* c_omp_for_incr_canonicalize_ptr() should have been
10828 : called to massage things appropriately. */
10829 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
10830 0 : OMP_CLAUSE_LINEAR_STEP (c)
10831 0 : = build_int_cst (TREE_TYPE (decl), -1);
10832 0 : break;
10833 4 : case MODIFY_EXPR:
10834 4 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
10835 4 : incr = TREE_OPERAND (incr, 1);
10836 4 : switch (TREE_CODE (incr))
10837 : {
10838 4 : case PLUS_EXPR:
10839 4 : if (TREE_OPERAND (incr, 1) == decl)
10840 0 : step = TREE_OPERAND (incr, 0);
10841 : else
10842 4 : step = TREE_OPERAND (incr, 1);
10843 : break;
10844 0 : case MINUS_EXPR:
10845 0 : case POINTER_PLUS_EXPR:
10846 0 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
10847 0 : step = TREE_OPERAND (incr, 1);
10848 0 : break;
10849 0 : default:
10850 0 : gcc_unreachable ();
10851 : }
10852 4 : stept = TREE_TYPE (decl);
10853 4 : if (INDIRECT_TYPE_P (stept))
10854 0 : stept = sizetype;
10855 4 : step = fold_convert (stept, step);
10856 4 : if (TREE_CODE (incr) == MINUS_EXPR)
10857 0 : step = fold_build1 (NEGATE_EXPR, stept, step);
10858 4 : OMP_CLAUSE_LINEAR_STEP (c) = step;
10859 4 : break;
10860 0 : default:
10861 0 : gcc_unreachable ();
10862 : }
10863 : }
10864 : /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
10865 : clauses, we need copy ctor for those rather than default ctor,
10866 : plus as for other lastprivates assignment op and dtor. */
10867 19465 : if (code == OMP_LOOP && !processing_template_decl)
10868 2350 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
10869 1474 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
10870 230 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
10871 1496 : && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
10872 : false, true, true, true))
10873 0 : CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
10874 :
10875 : return omp_for;
10876 : }
10877 :
10878 : /* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS
10879 : and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */
10880 :
10881 : tree
10882 15734 : finish_omp_for_block (tree bind, tree omp_for)
10883 : {
10884 15734 : if (omp_for == NULL_TREE
10885 14636 : || !OMP_FOR_ORIG_DECLS (omp_for)
10886 14077 : || bind == NULL_TREE
10887 29811 : || TREE_CODE (bind) != BIND_EXPR)
10888 : return bind;
10889 : tree b = NULL_TREE;
10890 32099 : for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
10891 18549 : if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)) == TREE_LIST
10892 18549 : && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
10893 : {
10894 110 : tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
10895 110 : gcc_assert (BIND_EXPR_BLOCK (bind)
10896 : && (BIND_EXPR_VARS (bind)
10897 : == BLOCK_VARS (BIND_EXPR_BLOCK (bind))));
10898 346 : for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
10899 1672 : for (tree *p = &BIND_EXPR_VARS (bind); *p; p = &DECL_CHAIN (*p))
10900 : {
10901 1436 : if (*p == TREE_VEC_ELT (v, j))
10902 : {
10903 236 : tree var = *p;
10904 236 : *p = DECL_CHAIN (*p);
10905 236 : if (b == NULL_TREE)
10906 : {
10907 100 : b = make_node (BLOCK);
10908 100 : b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
10909 100 : OMP_FOR_BODY (omp_for), b);
10910 100 : TREE_SIDE_EFFECTS (b) = 1;
10911 100 : OMP_FOR_BODY (omp_for) = b;
10912 : }
10913 236 : DECL_CHAIN (var) = BIND_EXPR_VARS (b);
10914 236 : BIND_EXPR_VARS (b) = var;
10915 236 : BLOCK_VARS (BIND_EXPR_BLOCK (b)) = var;
10916 : }
10917 : }
10918 110 : BLOCK_VARS (BIND_EXPR_BLOCK (bind)) = BIND_EXPR_VARS (bind);
10919 : }
10920 : return bind;
10921 : }
10922 :
10923 : void
10924 3944 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
10925 : tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
10926 : tree clauses, enum omp_memory_order mo, bool weak)
10927 : {
10928 3944 : tree orig_lhs;
10929 3944 : tree orig_rhs;
10930 3944 : tree orig_v;
10931 3944 : tree orig_lhs1;
10932 3944 : tree orig_rhs1;
10933 3944 : tree orig_r;
10934 3944 : bool dependent_p;
10935 3944 : tree stmt;
10936 :
10937 3944 : orig_lhs = lhs;
10938 3944 : orig_rhs = rhs;
10939 3944 : orig_v = v;
10940 3944 : orig_lhs1 = lhs1;
10941 3944 : orig_rhs1 = rhs1;
10942 3944 : orig_r = r;
10943 3944 : dependent_p = false;
10944 3944 : stmt = NULL_TREE;
10945 :
10946 : /* Even in a template, we can detect invalid uses of the atomic
10947 : pragma if neither LHS nor RHS is type-dependent. */
10948 3944 : if (processing_template_decl)
10949 : {
10950 660 : dependent_p = (type_dependent_expression_p (lhs)
10951 278 : || (rhs && type_dependent_expression_p (rhs))
10952 274 : || (v && type_dependent_expression_p (v))
10953 274 : || (lhs1 && type_dependent_expression_p (lhs1))
10954 274 : || (rhs1 && type_dependent_expression_p (rhs1))
10955 934 : || (r
10956 28 : && r != void_list_node
10957 18 : && type_dependent_expression_p (r)));
10958 660 : if (clauses)
10959 : {
10960 40 : gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
10961 : && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
10962 : && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
10963 40 : if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
10964 40 : || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
10965 : dependent_p = true;
10966 : }
10967 628 : if (!dependent_p)
10968 : {
10969 250 : lhs = build_non_dependent_expr (lhs);
10970 250 : if (rhs)
10971 187 : rhs = build_non_dependent_expr (rhs);
10972 250 : if (v)
10973 149 : v = build_non_dependent_expr (v);
10974 250 : if (lhs1)
10975 46 : lhs1 = build_non_dependent_expr (lhs1);
10976 250 : if (rhs1)
10977 154 : rhs1 = build_non_dependent_expr (rhs1);
10978 250 : if (r && r != void_list_node)
10979 18 : r = build_non_dependent_expr (r);
10980 : }
10981 : }
10982 3944 : if (!dependent_p)
10983 : {
10984 3534 : bool swapped = false;
10985 3534 : if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
10986 : {
10987 143 : std::swap (rhs, rhs1);
10988 143 : swapped = !commutative_tree_code (opcode);
10989 : }
10990 3534 : if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
10991 : {
10992 0 : if (code == OMP_ATOMIC)
10993 0 : error ("%<#pragma omp atomic update%> uses two different "
10994 : "expressions for memory");
10995 : else
10996 0 : error ("%<#pragma omp atomic capture%> uses two different "
10997 : "expressions for memory");
10998 0 : return;
10999 : }
11000 3534 : if (lhs1 && !cp_tree_equal (lhs, lhs1))
11001 : {
11002 0 : if (code == OMP_ATOMIC)
11003 0 : error ("%<#pragma omp atomic update%> uses two different "
11004 : "expressions for memory");
11005 : else
11006 0 : error ("%<#pragma omp atomic capture%> uses two different "
11007 : "expressions for memory");
11008 0 : return;
11009 : }
11010 7068 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
11011 : v, lhs1, rhs1, r, swapped, mo, weak,
11012 3534 : processing_template_decl != 0);
11013 3534 : if (stmt == error_mark_node)
11014 : return;
11015 : }
11016 3904 : if (processing_template_decl)
11017 : {
11018 648 : if (code == OMP_ATOMIC_READ)
11019 : {
11020 167 : stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
11021 167 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
11022 167 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
11023 : }
11024 : else
11025 : {
11026 481 : if (opcode == NOP_EXPR)
11027 34 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
11028 447 : else if (opcode == COND_EXPR)
11029 : {
11030 144 : stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
11031 144 : if (orig_r)
11032 56 : stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
11033 : stmt);
11034 144 : stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
11035 : orig_lhs);
11036 144 : orig_rhs1 = NULL_TREE;
11037 : }
11038 : else
11039 303 : stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
11040 481 : if (orig_rhs1)
11041 214 : stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
11042 : COMPOUND_EXPR, orig_rhs1, stmt);
11043 481 : if (code != OMP_ATOMIC)
11044 : {
11045 255 : stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
11046 255 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
11047 255 : OMP_ATOMIC_WEAK (stmt) = weak;
11048 255 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
11049 : }
11050 : }
11051 648 : stmt = build2 (OMP_ATOMIC, void_type_node,
11052 : clauses ? clauses : integer_zero_node, stmt);
11053 648 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
11054 648 : OMP_ATOMIC_WEAK (stmt) = weak;
11055 648 : SET_EXPR_LOCATION (stmt, loc);
11056 : }
11057 :
11058 : /* Avoid -Wunused-value warnings here, the whole construct has side-effects
11059 : and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
11060 : in some tree that appears to be unused, the value is not unused. */
11061 3904 : warning_sentinel w (warn_unused_value);
11062 3904 : finish_expr_stmt (stmt);
11063 3904 : }
11064 :
11065 : void
11066 556 : finish_omp_barrier (void)
11067 : {
11068 556 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
11069 556 : releasing_vec vec;
11070 556 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
11071 556 : finish_expr_stmt (stmt);
11072 556 : }
11073 :
11074 : void
11075 467 : finish_omp_depobj (location_t loc, tree depobj,
11076 : enum omp_clause_depend_kind kind, tree clause)
11077 : {
11078 467 : if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
11079 : {
11080 402 : if (!lvalue_p (depobj))
11081 : {
11082 8 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
11083 : "%<depobj%> expression is not lvalue expression");
11084 8 : depobj = error_mark_node;
11085 : }
11086 : }
11087 :
11088 467 : if (processing_template_decl)
11089 : {
11090 149 : if (clause == NULL_TREE)
11091 61 : clause = build_int_cst (integer_type_node, kind);
11092 149 : add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
11093 149 : return;
11094 : }
11095 :
11096 318 : if (!error_operand_p (depobj))
11097 : {
11098 310 : tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
11099 310 : if (addr == error_mark_node)
11100 : depobj = error_mark_node;
11101 : else
11102 310 : depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
11103 : tf_warning_or_error);
11104 : }
11105 :
11106 318 : c_finish_omp_depobj (loc, depobj, kind, clause);
11107 : }
11108 :
11109 : void
11110 182 : finish_omp_flush (int mo)
11111 : {
11112 182 : tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
11113 182 : releasing_vec vec;
11114 182 : if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
11115 : {
11116 63 : fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
11117 63 : vec->quick_push (build_int_cst (integer_type_node, mo));
11118 : }
11119 182 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
11120 182 : finish_expr_stmt (stmt);
11121 182 : }
11122 :
11123 : void
11124 117 : finish_omp_taskwait (void)
11125 : {
11126 117 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
11127 117 : releasing_vec vec;
11128 117 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
11129 117 : finish_expr_stmt (stmt);
11130 117 : }
11131 :
11132 : void
11133 16 : finish_omp_taskyield (void)
11134 : {
11135 16 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
11136 16 : releasing_vec vec;
11137 16 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
11138 16 : finish_expr_stmt (stmt);
11139 16 : }
11140 :
11141 : void
11142 778 : finish_omp_cancel (tree clauses)
11143 : {
11144 778 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
11145 778 : int mask = 0;
11146 778 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
11147 : mask = 1;
11148 545 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
11149 : mask = 2;
11150 376 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
11151 : mask = 4;
11152 216 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
11153 : mask = 8;
11154 : else
11155 : {
11156 0 : error ("%<#pragma omp cancel%> must specify one of "
11157 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
11158 0 : return;
11159 : }
11160 778 : releasing_vec vec;
11161 778 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
11162 778 : if (ifc != NULL_TREE)
11163 : {
11164 88 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
11165 88 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
11166 8 : error_at (OMP_CLAUSE_LOCATION (ifc),
11167 : "expected %<cancel%> %<if%> clause modifier");
11168 : else
11169 : {
11170 80 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
11171 80 : if (ifc2 != NULL_TREE)
11172 : {
11173 4 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
11174 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
11175 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
11176 4 : error_at (OMP_CLAUSE_LOCATION (ifc2),
11177 : "expected %<cancel%> %<if%> clause modifier");
11178 : }
11179 : }
11180 :
11181 88 : if (!processing_template_decl)
11182 76 : ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
11183 : else
11184 12 : ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
11185 12 : OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
11186 : integer_zero_node, ERROR_MARK,
11187 : NULL_TREE, NULL, tf_warning_or_error);
11188 : }
11189 : else
11190 690 : ifc = boolean_true_node;
11191 778 : vec->quick_push (build_int_cst (integer_type_node, mask));
11192 778 : vec->quick_push (ifc);
11193 778 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
11194 778 : finish_expr_stmt (stmt);
11195 778 : }
11196 :
11197 : void
11198 651 : finish_omp_cancellation_point (tree clauses)
11199 : {
11200 651 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
11201 651 : int mask = 0;
11202 651 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
11203 : mask = 1;
11204 487 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
11205 : mask = 2;
11206 347 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
11207 : mask = 4;
11208 207 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
11209 : mask = 8;
11210 : else
11211 : {
11212 4 : error ("%<#pragma omp cancellation point%> must specify one of "
11213 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
11214 4 : return;
11215 : }
11216 647 : releasing_vec vec
11217 647 : = make_tree_vector_single (build_int_cst (integer_type_node, mask));
11218 647 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
11219 647 : finish_expr_stmt (stmt);
11220 647 : }
11221 :
11222 : /* Begin a __transaction_atomic or __transaction_relaxed statement.
11223 : If PCOMPOUND is non-null, this is for a function-transaction-block, and we
11224 : should create an extra compound stmt. */
11225 :
11226 : tree
11227 371 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
11228 : {
11229 371 : tree r;
11230 :
11231 371 : if (pcompound)
11232 24 : *pcompound = begin_compound_stmt (0);
11233 :
11234 371 : r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
11235 :
11236 : /* Only add the statement to the function if support enabled. */
11237 371 : if (flag_tm)
11238 363 : add_stmt (r);
11239 : else
11240 16 : error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
11241 : ? G_("%<__transaction_relaxed%> without "
11242 : "transactional memory support enabled")
11243 : : G_("%<__transaction_atomic%> without "
11244 : "transactional memory support enabled")));
11245 :
11246 371 : TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
11247 371 : TREE_SIDE_EFFECTS (r) = 1;
11248 371 : return r;
11249 : }
11250 :
11251 : /* End a __transaction_atomic or __transaction_relaxed statement.
11252 : If COMPOUND_STMT is non-null, this is for a function-transaction-block,
11253 : and we should end the compound. If NOEX is non-NULL, we wrap the body in
11254 : a MUST_NOT_THROW_EXPR with NOEX as condition. */
11255 :
11256 : void
11257 371 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
11258 : {
11259 371 : TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
11260 371 : TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
11261 371 : TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
11262 371 : TRANSACTION_EXPR_IS_STMT (stmt) = 1;
11263 :
11264 : /* noexcept specifications are not allowed for function transactions. */
11265 371 : gcc_assert (!(noex && compound_stmt));
11266 371 : if (noex)
11267 : {
11268 52 : tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
11269 : noex);
11270 52 : protected_set_expr_location
11271 52 : (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
11272 52 : TREE_SIDE_EFFECTS (body) = 1;
11273 52 : TRANSACTION_EXPR_BODY (stmt) = body;
11274 : }
11275 :
11276 371 : if (compound_stmt)
11277 24 : finish_compound_stmt (compound_stmt);
11278 371 : }
11279 :
11280 : /* Build a __transaction_atomic or __transaction_relaxed expression. If
11281 : NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
11282 : condition. */
11283 :
11284 : tree
11285 123 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
11286 : {
11287 123 : tree ret;
11288 123 : if (noex)
11289 : {
11290 57 : expr = build_must_not_throw_expr (expr, noex);
11291 57 : protected_set_expr_location (expr, loc);
11292 57 : TREE_SIDE_EFFECTS (expr) = 1;
11293 : }
11294 123 : ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
11295 123 : if (flags & TM_STMT_ATTR_RELAXED)
11296 5 : TRANSACTION_EXPR_RELAXED (ret) = 1;
11297 123 : TREE_SIDE_EFFECTS (ret) = 1;
11298 123 : SET_EXPR_LOCATION (ret, loc);
11299 123 : return ret;
11300 : }
11301 :
11302 : void
11303 89260 : init_cp_semantics (void)
11304 : {
11305 89260 : }
11306 :
11307 :
11308 : /* Build a STATIC_ASSERT for a static assertion with the condition
11309 : CONDITION and the message text MESSAGE. LOCATION is the location
11310 : of the static assertion in the source code. When MEMBER_P, this
11311 : static assertion is a member of a class. If SHOW_EXPR_P is true,
11312 : print the condition (because it was instantiation-dependent). */
11313 :
11314 : void
11315 5405256 : finish_static_assert (tree condition, tree message, location_t location,
11316 : bool member_p, bool show_expr_p)
11317 : {
11318 5405256 : tsubst_flags_t complain = tf_warning_or_error;
11319 :
11320 5405256 : if (message == NULL_TREE
11321 5405256 : || message == error_mark_node
11322 5405250 : || condition == NULL_TREE
11323 5405250 : || condition == error_mark_node)
11324 : return;
11325 :
11326 5405175 : if (check_for_bare_parameter_packs (condition))
11327 3 : condition = error_mark_node;
11328 :
11329 : /* Save the condition in case it was a concept check. */
11330 5405175 : tree orig_condition = condition;
11331 :
11332 5405175 : if (instantiation_dependent_expression_p (condition))
11333 : {
11334 : /* We're in a template; build a STATIC_ASSERT and put it in
11335 : the right place. */
11336 2518850 : defer:
11337 2518853 : tree assertion = make_node (STATIC_ASSERT);
11338 2518853 : STATIC_ASSERT_CONDITION (assertion) = orig_condition;
11339 2518853 : STATIC_ASSERT_MESSAGE (assertion) = message;
11340 2518853 : STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
11341 :
11342 2518853 : if (member_p)
11343 1466059 : maybe_add_class_template_decl_list (current_class_type,
11344 : assertion,
11345 : /*friend_p=*/0);
11346 : else
11347 1052794 : add_stmt (assertion);
11348 :
11349 2518853 : return;
11350 : }
11351 :
11352 : /* Fold the expression and convert it to a boolean value. */
11353 2886325 : condition = contextual_conv_bool (condition, complain);
11354 2886325 : condition = fold_non_dependent_expr (condition, complain,
11355 : /*manifestly_const_eval=*/true);
11356 :
11357 2886325 : if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
11358 : /* Do nothing; the condition is satisfied. */
11359 : ;
11360 : else
11361 : {
11362 784 : iloc_sentinel ils (location);
11363 :
11364 784 : if (integer_zerop (condition))
11365 : {
11366 : /* CWG2518: static_assert failure in a template is not IFNDR. */
11367 640 : if (processing_template_decl)
11368 3 : goto defer;
11369 :
11370 637 : int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT
11371 : (TREE_TYPE (TREE_TYPE (message))));
11372 637 : int len = TREE_STRING_LENGTH (message) / sz - 1;
11373 :
11374 : /* See if we can find which clause was failing (for logical AND). */
11375 637 : tree bad = find_failing_clause (NULL, orig_condition);
11376 : /* If not, or its location is unusable, fall back to the previous
11377 : location. */
11378 637 : location_t cloc = cp_expr_loc_or_loc (bad, location);
11379 :
11380 637 : auto_diagnostic_group d;
11381 :
11382 : /* Report the error. */
11383 637 : if (len == 0)
11384 305 : error_at (cloc, "static assertion failed");
11385 : else
11386 332 : error_at (cloc, "static assertion failed: %s",
11387 332 : TREE_STRING_POINTER (message));
11388 :
11389 637 : diagnose_failing_condition (bad, cloc, show_expr_p);
11390 637 : }
11391 144 : else if (condition && condition != error_mark_node)
11392 : {
11393 138 : error ("non-constant condition for static assertion");
11394 138 : if (require_rvalue_constant_expression (condition))
11395 102 : cxx_constant_value (condition);
11396 : }
11397 784 : }
11398 : }
11399 :
11400 : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
11401 : suitable for use as a type-specifier.
11402 :
11403 : ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
11404 : id-expression or a class member access, FALSE when it was parsed as
11405 : a full expression. */
11406 :
11407 : tree
11408 6743771 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
11409 : tsubst_flags_t complain)
11410 : {
11411 6743771 : tree type = NULL_TREE;
11412 :
11413 6743771 : if (!expr || error_operand_p (expr))
11414 34188 : return error_mark_node;
11415 :
11416 6709583 : if (TYPE_P (expr)
11417 6709583 : || TREE_CODE (expr) == TYPE_DECL
11418 13419147 : || (TREE_CODE (expr) == BIT_NOT_EXPR
11419 9690 : && TYPE_P (TREE_OPERAND (expr, 0))))
11420 : {
11421 31 : if (complain & tf_error)
11422 31 : error ("argument to %<decltype%> must be an expression");
11423 31 : return error_mark_node;
11424 : }
11425 :
11426 : /* decltype is an unevaluated context. */
11427 6709552 : cp_unevaluated u;
11428 :
11429 6709552 : processing_template_decl_sentinel ptds (/*reset=*/false);
11430 :
11431 : /* Depending on the resolution of DR 1172, we may later need to distinguish
11432 : instantiation-dependent but not type-dependent expressions so that, say,
11433 : A<decltype(sizeof(T))>::U doesn't require 'typename'. */
11434 6709552 : if (instantiation_dependent_uneval_expression_p (expr))
11435 : {
11436 2522138 : type = cxx_make_type (DECLTYPE_TYPE);
11437 2522138 : DECLTYPE_TYPE_EXPR (type) = expr;
11438 5044276 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
11439 2522138 : = id_expression_or_member_access_p;
11440 2522138 : SET_TYPE_STRUCTURAL_EQUALITY (type);
11441 :
11442 2522138 : return type;
11443 : }
11444 4187414 : else if (processing_template_decl)
11445 : {
11446 661 : expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
11447 661 : if (expr == error_mark_node)
11448 : return error_mark_node;
11449 : /* Keep processing_template_decl cleared for the rest of the function
11450 : (for sake of the call to lvalue_kind below, which handles templated
11451 : and non-templated COND_EXPR differently). */
11452 614 : processing_template_decl = 0;
11453 : }
11454 :
11455 : /* The type denoted by decltype(e) is defined as follows: */
11456 :
11457 4187367 : expr = resolve_nondeduced_context (expr, complain);
11458 4187367 : if (!mark_single_function (expr, complain))
11459 0 : return error_mark_node;
11460 :
11461 4187367 : if (invalid_nonstatic_memfn_p (input_location, expr, complain))
11462 18 : return error_mark_node;
11463 :
11464 4187349 : if (type_unknown_p (expr))
11465 : {
11466 17 : if (complain & tf_error)
11467 6 : error ("%<decltype%> cannot resolve address of overloaded function");
11468 17 : return error_mark_node;
11469 : }
11470 :
11471 : /* To get the size of a static data member declared as an array of
11472 : unknown bound, we need to instantiate it. */
11473 4187332 : if (VAR_P (expr)
11474 2472 : && VAR_HAD_UNKNOWN_BOUND (expr)
11475 4187332 : && DECL_TEMPLATE_INSTANTIATION (expr))
11476 0 : instantiate_decl (expr, /*defer_ok*/true, /*expl_inst_mem*/false);
11477 :
11478 4187332 : if (id_expression_or_member_access_p)
11479 : {
11480 : /* If e is an id-expression or a class member access (5.2.5
11481 : [expr.ref]), decltype(e) is defined as the type of the entity
11482 : named by e. If there is no such entity, or e names a set of
11483 : overloaded functions, the program is ill-formed. */
11484 26720 : if (identifier_p (expr))
11485 0 : expr = lookup_name (expr);
11486 :
11487 26720 : if (INDIRECT_REF_P (expr)
11488 26720 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
11489 : /* This can happen when the expression is, e.g., "a.b". Just
11490 : look at the underlying operand. */
11491 21326 : expr = TREE_OPERAND (expr, 0);
11492 :
11493 26720 : if (TREE_CODE (expr) == OFFSET_REF
11494 26720 : || TREE_CODE (expr) == MEMBER_REF
11495 26720 : || TREE_CODE (expr) == SCOPE_REF)
11496 : /* We're only interested in the field itself. If it is a
11497 : BASELINK, we will need to see through it in the next
11498 : step. */
11499 0 : expr = TREE_OPERAND (expr, 1);
11500 :
11501 26720 : if (BASELINK_P (expr))
11502 : /* See through BASELINK nodes to the underlying function. */
11503 1 : expr = BASELINK_FUNCTIONS (expr);
11504 :
11505 : /* decltype of a decomposition name drops references in the tuple case
11506 : (unlike decltype of a normal variable) and keeps cv-qualifiers from
11507 : the containing object in the other cases (unlike decltype of a member
11508 : access expression). */
11509 26720 : if (DECL_DECOMPOSITION_P (expr))
11510 : {
11511 86 : if (DECL_HAS_VALUE_EXPR_P (expr))
11512 : /* Expr is an array or struct subobject proxy, handle
11513 : bit-fields properly. */
11514 54 : return unlowered_expr_type (expr);
11515 : else
11516 : /* Expr is a reference variable for the tuple case. */
11517 32 : return lookup_decomp_type (expr);
11518 : }
11519 :
11520 26634 : switch (TREE_CODE (expr))
11521 : {
11522 0 : case FIELD_DECL:
11523 0 : if (DECL_BIT_FIELD_TYPE (expr))
11524 : {
11525 : type = DECL_BIT_FIELD_TYPE (expr);
11526 : break;
11527 : }
11528 : /* Fall through for fields that aren't bitfields. */
11529 25855 : gcc_fallthrough ();
11530 :
11531 25855 : case FUNCTION_DECL:
11532 25855 : case VAR_DECL:
11533 25855 : case CONST_DECL:
11534 25855 : case PARM_DECL:
11535 25855 : case RESULT_DECL:
11536 25855 : case TEMPLATE_PARM_INDEX:
11537 25855 : expr = mark_type_use (expr);
11538 25855 : type = TREE_TYPE (expr);
11539 25855 : break;
11540 :
11541 0 : case ERROR_MARK:
11542 0 : type = error_mark_node;
11543 0 : break;
11544 :
11545 686 : case COMPONENT_REF:
11546 686 : case COMPOUND_EXPR:
11547 686 : mark_type_use (expr);
11548 686 : type = is_bitfield_expr_with_lowered_type (expr);
11549 686 : if (!type)
11550 663 : type = TREE_TYPE (TREE_OPERAND (expr, 1));
11551 : break;
11552 :
11553 0 : case BIT_FIELD_REF:
11554 0 : gcc_unreachable ();
11555 :
11556 60 : case INTEGER_CST:
11557 60 : case PTRMEM_CST:
11558 : /* We can get here when the id-expression refers to an
11559 : enumerator or non-type template parameter. */
11560 60 : type = TREE_TYPE (expr);
11561 60 : break;
11562 :
11563 33 : default:
11564 : /* Handle instantiated template non-type arguments. */
11565 33 : type = TREE_TYPE (expr);
11566 33 : break;
11567 : }
11568 : }
11569 : else
11570 : {
11571 : /* Within a lambda-expression:
11572 :
11573 : Every occurrence of decltype((x)) where x is a possibly
11574 : parenthesized id-expression that names an entity of
11575 : automatic storage duration is treated as if x were
11576 : transformed into an access to a corresponding data member
11577 : of the closure type that would have been declared if x
11578 : were a use of the denoted entity. */
11579 4160612 : if (outer_automatic_var_p (expr)
11580 36 : && current_function_decl
11581 4160684 : && LAMBDA_FUNCTION_P (current_function_decl))
11582 36 : type = capture_decltype (expr);
11583 4160576 : else if (error_operand_p (expr))
11584 0 : type = error_mark_node;
11585 4160576 : else if (expr == current_class_ptr)
11586 : /* If the expression is just "this", we want the
11587 : cv-unqualified pointer for the "this" type. */
11588 0 : type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
11589 : else
11590 : {
11591 : /* Otherwise, where T is the type of e, if e is an lvalue,
11592 : decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
11593 4160576 : cp_lvalue_kind clk = lvalue_kind (expr);
11594 4160576 : type = unlowered_expr_type (expr);
11595 4160576 : gcc_assert (!TYPE_REF_P (type));
11596 :
11597 : /* For vector types, pick a non-opaque variant. */
11598 4160576 : if (VECTOR_TYPE_P (type))
11599 74 : type = strip_typedefs (type);
11600 :
11601 4160576 : if (clk != clk_none && !(clk & clk_class))
11602 518413 : type = cp_build_reference_type (type, (clk & clk_rvalueref));
11603 : }
11604 : }
11605 :
11606 : return type;
11607 6709552 : }
11608 :
11609 : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
11610 : __has_nothrow_copy, depending on assign_p. Returns true iff all
11611 : the copy {ctor,assign} fns are nothrow. */
11612 :
11613 : static bool
11614 370 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
11615 : {
11616 370 : tree fns = NULL_TREE;
11617 :
11618 370 : if (assign_p || TYPE_HAS_COPY_CTOR (type))
11619 366 : fns = get_class_binding (type, assign_p ? assign_op_identifier
11620 : : ctor_identifier);
11621 :
11622 370 : bool saw_copy = false;
11623 1028 : for (ovl_iterator iter (fns); iter; ++iter)
11624 : {
11625 585 : tree fn = *iter;
11626 :
11627 585 : if (copy_fn_p (fn) > 0)
11628 : {
11629 562 : saw_copy = true;
11630 562 : if (!maybe_instantiate_noexcept (fn)
11631 562 : || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
11632 256 : return false;
11633 : }
11634 : }
11635 :
11636 114 : return saw_copy;
11637 : }
11638 :
11639 : /* Return true if DERIVED is pointer interconvertible base of BASE. */
11640 :
11641 : static bool
11642 37 : pointer_interconvertible_base_of_p (tree base, tree derived)
11643 : {
11644 37 : if (base == error_mark_node || derived == error_mark_node)
11645 : return false;
11646 37 : base = TYPE_MAIN_VARIANT (base);
11647 37 : derived = TYPE_MAIN_VARIANT (derived);
11648 32 : if (!NON_UNION_CLASS_TYPE_P (base)
11649 69 : || !NON_UNION_CLASS_TYPE_P (derived))
11650 : return false;
11651 :
11652 32 : if (same_type_p (base, derived))
11653 : return true;
11654 :
11655 19 : if (!std_layout_type_p (derived))
11656 : return false;
11657 :
11658 17 : return uniquely_derived_from_p (base, derived);
11659 : }
11660 :
11661 : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
11662 : return true if MEMBERTYPE is the type of the first non-static data member
11663 : of TYPE or for unions of any members. */
11664 : static bool
11665 236 : first_nonstatic_data_member_p (tree type, tree membertype)
11666 : {
11667 476 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
11668 : {
11669 447 : if (TREE_CODE (field) != FIELD_DECL)
11670 53 : continue;
11671 394 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
11672 20 : continue;
11673 374 : if (DECL_FIELD_IS_BASE (field))
11674 15 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
11675 359 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
11676 : {
11677 79 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
11678 52 : || std_layout_type_p (TREE_TYPE (field)))
11679 108 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
11680 : return true;
11681 : }
11682 280 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
11683 : membertype))
11684 : return true;
11685 200 : if (TREE_CODE (type) != UNION_TYPE)
11686 : return false;
11687 : }
11688 : return false;
11689 : }
11690 :
11691 : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
11692 :
11693 : tree
11694 209 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
11695 : tree *args)
11696 : {
11697 : /* Unless users call the builtin directly, the following 3 checks should be
11698 : ensured from std::is_pointer_interconvertible_with_class function
11699 : template. */
11700 209 : if (nargs != 1)
11701 : {
11702 2 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
11703 : "needs a single argument");
11704 2 : return boolean_false_node;
11705 : }
11706 207 : tree arg = args[0];
11707 207 : if (error_operand_p (arg))
11708 0 : return boolean_false_node;
11709 207 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
11710 : {
11711 2 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
11712 : "argument is not pointer to member");
11713 2 : return boolean_false_node;
11714 : }
11715 :
11716 205 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
11717 10 : return boolean_false_node;
11718 :
11719 195 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
11720 195 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
11721 195 : if (!complete_type_or_else (basetype, NULL_TREE))
11722 1 : return boolean_false_node;
11723 :
11724 194 : if (TREE_CODE (basetype) != UNION_TYPE
11725 194 : && !std_layout_type_p (basetype))
11726 14 : return boolean_false_node;
11727 :
11728 180 : if (!first_nonstatic_data_member_p (basetype, membertype))
11729 55 : return boolean_false_node;
11730 :
11731 125 : if (TREE_CODE (arg) == PTRMEM_CST)
11732 26 : arg = cplus_expand_constant (arg);
11733 :
11734 125 : if (integer_nonzerop (arg))
11735 8 : return boolean_false_node;
11736 117 : if (integer_zerop (arg))
11737 25 : return boolean_true_node;
11738 :
11739 92 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
11740 : build_zero_cst (TREE_TYPE (arg)));
11741 : }
11742 :
11743 : /* Helper function for is_corresponding_member_aggr. Return true if
11744 : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
11745 : union or structure BASETYPE. */
11746 :
11747 : static bool
11748 32 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
11749 : {
11750 77 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
11751 67 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
11752 12 : continue;
11753 55 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
11754 : membertype))
11755 : {
11756 18 : if (TREE_CODE (arg) != INTEGER_CST
11757 18 : || tree_int_cst_equal (arg, byte_position (field)))
11758 18 : return true;
11759 : }
11760 37 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
11761 : {
11762 6 : tree narg = arg;
11763 6 : if (TREE_CODE (basetype) != UNION_TYPE
11764 0 : && TREE_CODE (narg) == INTEGER_CST)
11765 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
11766 6 : if (is_corresponding_member_union (TREE_TYPE (field),
11767 : membertype, narg))
11768 : return true;
11769 : }
11770 : return false;
11771 : }
11772 :
11773 : /* Helper function for fold_builtin_is_corresponding_member call.
11774 : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
11775 : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
11776 : boolean_true_node if they are corresponding members, or for
11777 : non-constant ARG2 the highest member offset for corresponding
11778 : members. */
11779 :
11780 : static tree
11781 201 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
11782 : tree arg1, tree basetype2, tree membertype2,
11783 : tree arg2)
11784 : {
11785 201 : tree field1 = TYPE_FIELDS (basetype1);
11786 201 : tree field2 = TYPE_FIELDS (basetype2);
11787 201 : tree ret = boolean_false_node;
11788 849 : while (1)
11789 : {
11790 525 : bool r = next_common_initial_sequence (field1, field2);
11791 525 : if (field1 == NULL_TREE || field2 == NULL_TREE)
11792 : break;
11793 477 : if (r
11794 369 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
11795 : membertype1)
11796 662 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
11797 : membertype2))
11798 : {
11799 183 : tree pos = byte_position (field1);
11800 183 : if (TREE_CODE (arg1) == INTEGER_CST
11801 183 : && tree_int_cst_equal (arg1, pos))
11802 : {
11803 33 : if (TREE_CODE (arg2) == INTEGER_CST)
11804 33 : return boolean_true_node;
11805 : return pos;
11806 : }
11807 150 : else if (TREE_CODE (arg1) != INTEGER_CST)
11808 426 : ret = pos;
11809 : }
11810 588 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
11811 336 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
11812 : {
11813 42 : if ((!lookup_attribute ("no_unique_address",
11814 42 : DECL_ATTRIBUTES (field1)))
11815 42 : != !lookup_attribute ("no_unique_address",
11816 42 : DECL_ATTRIBUTES (field2)))
11817 : break;
11818 42 : if (!tree_int_cst_equal (bit_position (field1),
11819 42 : bit_position (field2)))
11820 : break;
11821 36 : bool overlap = true;
11822 36 : tree pos = byte_position (field1);
11823 36 : if (TREE_CODE (arg1) == INTEGER_CST)
11824 : {
11825 12 : tree off1 = fold_convert (sizetype, arg1);
11826 12 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
11827 12 : if (tree_int_cst_lt (off1, pos)
11828 12 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
11829 : overlap = false;
11830 : }
11831 36 : if (TREE_CODE (arg2) == INTEGER_CST)
11832 : {
11833 12 : tree off2 = fold_convert (sizetype, arg2);
11834 12 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
11835 12 : if (tree_int_cst_lt (off2, pos)
11836 12 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
11837 : overlap = false;
11838 : }
11839 30 : if (overlap
11840 30 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
11841 43 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
11842 : {
11843 13 : tree narg1 = arg1;
11844 13 : if (TREE_CODE (arg1) == INTEGER_CST)
11845 3 : narg1 = size_binop (MINUS_EXPR,
11846 : fold_convert (sizetype, arg1), pos);
11847 13 : tree narg2 = arg2;
11848 13 : if (TREE_CODE (arg2) == INTEGER_CST)
11849 3 : narg2 = size_binop (MINUS_EXPR,
11850 : fold_convert (sizetype, arg2), pos);
11851 13 : tree t1 = TREE_TYPE (field1);
11852 13 : tree t2 = TREE_TYPE (field2);
11853 13 : tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
11854 : narg1, t2, membertype2,
11855 : narg2);
11856 13 : if (nret != boolean_false_node)
11857 : {
11858 13 : if (nret == boolean_true_node)
11859 3 : return nret;
11860 10 : if (TREE_CODE (arg1) == INTEGER_CST)
11861 0 : return size_binop (PLUS_EXPR, nret, pos);
11862 10 : ret = size_binop (PLUS_EXPR, nret, pos);
11863 : }
11864 : }
11865 23 : else if (overlap
11866 17 : && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
11867 40 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
11868 : {
11869 17 : tree narg1 = arg1;
11870 17 : if (TREE_CODE (arg1) == INTEGER_CST)
11871 3 : narg1 = size_binop (MINUS_EXPR,
11872 : fold_convert (sizetype, arg1), pos);
11873 17 : tree narg2 = arg2;
11874 17 : if (TREE_CODE (arg2) == INTEGER_CST)
11875 3 : narg2 = size_binop (MINUS_EXPR,
11876 : fold_convert (sizetype, arg2), pos);
11877 17 : if (is_corresponding_member_union (TREE_TYPE (field1),
11878 : membertype1, narg1)
11879 17 : && is_corresponding_member_union (TREE_TYPE (field2),
11880 : membertype2, narg2))
11881 : {
11882 9 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
11883 : "not well defined for anonymous unions");
11884 9 : return boolean_false_node;
11885 : }
11886 : }
11887 : }
11888 426 : if (!r)
11889 : break;
11890 324 : field1 = DECL_CHAIN (field1);
11891 324 : field2 = DECL_CHAIN (field2);
11892 324 : }
11893 : return ret;
11894 : }
11895 :
11896 : /* Fold __builtin_is_corresponding_member call. */
11897 :
11898 : tree
11899 286 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
11900 : tree *args)
11901 : {
11902 : /* Unless users call the builtin directly, the following 3 checks should be
11903 : ensured from std::is_corresponding_member function template. */
11904 286 : if (nargs != 2)
11905 : {
11906 3 : error_at (loc, "%<__builtin_is_corresponding_member%> "
11907 : "needs two arguments");
11908 3 : return boolean_false_node;
11909 : }
11910 283 : tree arg1 = args[0];
11911 283 : tree arg2 = args[1];
11912 283 : if (error_operand_p (arg1) || error_operand_p (arg2))
11913 0 : return boolean_false_node;
11914 291 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
11915 289 : || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
11916 : {
11917 3 : error_at (loc, "%<__builtin_is_corresponding_member%> "
11918 : "argument is not pointer to member");
11919 3 : return boolean_false_node;
11920 : }
11921 :
11922 280 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
11923 280 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
11924 6 : return boolean_false_node;
11925 :
11926 274 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
11927 274 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
11928 274 : if (!complete_type_or_else (basetype1, NULL_TREE))
11929 4 : return boolean_false_node;
11930 :
11931 270 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
11932 270 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
11933 270 : if (!complete_type_or_else (basetype2, NULL_TREE))
11934 4 : return boolean_false_node;
11935 :
11936 260 : if (!NON_UNION_CLASS_TYPE_P (basetype1)
11937 260 : || !NON_UNION_CLASS_TYPE_P (basetype2)
11938 260 : || !std_layout_type_p (basetype1)
11939 508 : || !std_layout_type_p (basetype2))
11940 24 : return boolean_false_node;
11941 :
11942 : /* If the member types aren't layout compatible, then they
11943 : can't be corresponding members. */
11944 242 : if (!layout_compatible_type_p (membertype1, membertype2))
11945 12 : return boolean_false_node;
11946 :
11947 230 : if (TREE_CODE (arg1) == PTRMEM_CST)
11948 91 : arg1 = cplus_expand_constant (arg1);
11949 230 : if (TREE_CODE (arg2) == PTRMEM_CST)
11950 93 : arg2 = cplus_expand_constant (arg2);
11951 :
11952 230 : if (null_member_pointer_value_p (arg1)
11953 230 : || null_member_pointer_value_p (arg2))
11954 6 : return boolean_false_node;
11955 :
11956 224 : if (TREE_CODE (arg1) == INTEGER_CST
11957 92 : && TREE_CODE (arg2) == INTEGER_CST
11958 316 : && !tree_int_cst_equal (arg1, arg2))
11959 36 : return boolean_false_node;
11960 :
11961 188 : if (TREE_CODE (arg2) == INTEGER_CST
11962 56 : && TREE_CODE (arg1) != INTEGER_CST)
11963 : {
11964 : std::swap (arg1, arg2);
11965 : std::swap (membertype1, membertype2);
11966 : std::swap (basetype1, basetype2);
11967 : }
11968 :
11969 188 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
11970 : basetype2, membertype2, arg2);
11971 188 : if (TREE_TYPE (ret) == boolean_type_node)
11972 : return ret;
11973 : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
11974 : already returns boolean_{true,false}_node whether those particular
11975 : members are corresponding members or not. Otherwise, if only
11976 : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
11977 : above), it returns boolean_false_node if it is certainly not a
11978 : corresponding member and otherwise we need to do a runtime check that
11979 : those two OFFSET_TYPE offsets are equal.
11980 : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
11981 : returns the largest offset at which the members would be corresponding
11982 : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
11983 106 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
11984 106 : if (TREE_CODE (arg1) == INTEGER_CST)
11985 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
11986 : fold_convert (TREE_TYPE (arg1), arg2));
11987 106 : ret = fold_build2 (LE_EXPR, boolean_type_node,
11988 : fold_convert (pointer_sized_int_node, arg1),
11989 : fold_convert (pointer_sized_int_node, ret));
11990 106 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
11991 : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
11992 : fold_convert (TREE_TYPE (arg1), arg2)));
11993 : }
11994 :
11995 : /* Actually evaluates the trait. */
11996 :
11997 : static bool
11998 3675736 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
11999 : {
12000 3675736 : enum tree_code type_code1;
12001 3675736 : tree t;
12002 :
12003 3675736 : type_code1 = TREE_CODE (type1);
12004 :
12005 3675736 : switch (kind)
12006 : {
12007 418 : case CPTK_HAS_NOTHROW_ASSIGN:
12008 418 : type1 = strip_array_types (type1);
12009 792 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
12010 792 : && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
12011 224 : || (CLASS_TYPE_P (type1)
12012 172 : && classtype_has_nothrow_assign_or_copy_p (type1,
12013 : true))));
12014 :
12015 680 : case CPTK_HAS_TRIVIAL_ASSIGN:
12016 : /* ??? The standard seems to be missing the "or array of such a class
12017 : type" wording for this trait. */
12018 680 : type1 = strip_array_types (type1);
12019 1336 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
12020 1316 : && (trivial_type_p (type1)
12021 396 : || (CLASS_TYPE_P (type1)
12022 296 : && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
12023 :
12024 281 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
12025 281 : type1 = strip_array_types (type1);
12026 281 : return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
12027 281 : || (CLASS_TYPE_P (type1)
12028 122 : && (t = locate_ctor (type1))
12029 78 : && maybe_instantiate_noexcept (t)
12030 75 : && TYPE_NOTHROW_P (TREE_TYPE (t))));
12031 :
12032 595 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
12033 595 : type1 = strip_array_types (type1);
12034 595 : return (trivial_type_p (type1)
12035 595 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
12036 :
12037 401 : case CPTK_HAS_NOTHROW_COPY:
12038 401 : type1 = strip_array_types (type1);
12039 401 : return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
12040 401 : || (CLASS_TYPE_P (type1)
12041 198 : && classtype_has_nothrow_assign_or_copy_p (type1, false)));
12042 :
12043 690 : case CPTK_HAS_TRIVIAL_COPY:
12044 : /* ??? The standard seems to be missing the "or array of such a class
12045 : type" wording for this trait. */
12046 690 : type1 = strip_array_types (type1);
12047 1143 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
12048 1123 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
12049 :
12050 18328 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
12051 18328 : type1 = strip_array_types (type1);
12052 20854 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
12053 20848 : || (CLASS_TYPE_P (type1)
12054 2466 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
12055 :
12056 317 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
12057 317 : return type_has_virtual_destructor (type1);
12058 :
12059 349 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
12060 349 : return type_has_unique_obj_representations (type1);
12061 :
12062 41204 : case CPTK_IS_ABSTRACT:
12063 41204 : return ABSTRACT_CLASS_TYPE_P (type1);
12064 :
12065 816 : case CPTK_IS_AGGREGATE:
12066 816 : return CP_AGGREGATE_TYPE_P (type1);
12067 :
12068 34622 : case CPTK_IS_BASE_OF:
12069 34513 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
12070 55280 : && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
12071 19224 : || DERIVED_FROM_P (type1, type2)));
12072 :
12073 41467 : case CPTK_IS_CLASS:
12074 41467 : return NON_UNION_CLASS_TYPE_P (type1);
12075 :
12076 208084 : case CPTK_IS_EMPTY:
12077 208084 : return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
12078 :
12079 227738 : case CPTK_IS_ENUM:
12080 227738 : return type_code1 == ENUMERAL_TYPE;
12081 :
12082 325295 : case CPTK_IS_FINAL:
12083 325295 : return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
12084 :
12085 75 : case CPTK_IS_LAYOUT_COMPATIBLE:
12086 75 : return layout_compatible_type_p (type1, type2);
12087 :
12088 193 : case CPTK_IS_LITERAL_TYPE:
12089 193 : return literal_type_p (type1);
12090 :
12091 37 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
12092 37 : return pointer_interconvertible_base_of_p (type1, type2);
12093 :
12094 8452 : case CPTK_IS_POD:
12095 8452 : return pod_type_p (type1);
12096 :
12097 309 : case CPTK_IS_POLYMORPHIC:
12098 309 : return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
12099 :
12100 969786 : case CPTK_IS_SAME:
12101 969786 : return same_type_p (type1, type2);
12102 :
12103 33806 : case CPTK_IS_STD_LAYOUT:
12104 33806 : return std_layout_type_p (type1);
12105 :
12106 55749 : case CPTK_IS_TRIVIAL:
12107 55749 : return trivial_type_p (type1);
12108 :
12109 1928 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
12110 1928 : return is_trivially_xible (MODIFY_EXPR, type1, type2);
12111 :
12112 2276 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
12113 2276 : return is_trivially_xible (INIT_EXPR, type1, type2);
12114 :
12115 4880 : case CPTK_IS_TRIVIALLY_COPYABLE:
12116 4880 : return trivially_copyable_p (type1);
12117 :
12118 3266 : case CPTK_IS_UNION:
12119 3266 : return type_code1 == UNION_TYPE;
12120 :
12121 343001 : case CPTK_IS_ASSIGNABLE:
12122 343001 : return is_xible (MODIFY_EXPR, type1, type2);
12123 :
12124 473198 : case CPTK_IS_CONSTRUCTIBLE:
12125 473198 : return is_xible (INIT_EXPR, type1, type2);
12126 :
12127 134914 : case CPTK_IS_NOTHROW_ASSIGNABLE:
12128 134914 : return is_nothrow_xible (MODIFY_EXPR, type1, type2);
12129 :
12130 289485 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
12131 289485 : return is_nothrow_xible (INIT_EXPR, type1, type2);
12132 :
12133 414457 : case CPTK_IS_CONVERTIBLE:
12134 414457 : return is_convertible (type1, type2);
12135 :
12136 2478 : case CPTK_IS_NOTHROW_CONVERTIBLE:
12137 2478 : return is_nothrow_convertible (type1, type2);
12138 :
12139 3521 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
12140 3521 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
12141 :
12142 32622 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
12143 32622 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
12144 :
12145 18 : case CPTK_IS_DEDUCIBLE:
12146 18 : return type_targs_deducible_from (type1, type2);
12147 :
12148 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
12149 : case CPTK_##CODE:
12150 : #include "cp-trait.def"
12151 : #undef DEFTRAIT_TYPE
12152 : /* Type-yielding traits are handled in finish_trait_type. */
12153 : break;
12154 : }
12155 :
12156 0 : gcc_unreachable ();
12157 : }
12158 :
12159 : /* Returns true if TYPE meets the requirements for the specified KIND,
12160 : false otherwise.
12161 :
12162 : When KIND == 1, TYPE must be an array of unknown bound,
12163 : or (possibly cv-qualified) void, or a complete type.
12164 :
12165 : When KIND == 2, TYPE must be a complete type, or array of complete type,
12166 : or (possibly cv-qualified) void.
12167 :
12168 : When KIND == 3:
12169 : If TYPE is a non-union class type, it must be complete.
12170 :
12171 : When KIND == 4:
12172 : If TYPE is a class type, it must be complete. */
12173 :
12174 : static bool
12175 3477732 : check_trait_type (tree type, int kind = 1)
12176 : {
12177 3477732 : if (type == NULL_TREE)
12178 : return true;
12179 :
12180 3477732 : if (TREE_CODE (type) == TREE_VEC)
12181 : {
12182 490027 : for (tree arg : tree_vec_range (type))
12183 198266 : if (!check_trait_type (arg, kind))
12184 0 : return false;
12185 291761 : return true;
12186 : }
12187 :
12188 3185971 : if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
12189 : return true; // Array of unknown bound. Don't care about completeness.
12190 :
12191 3185492 : if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
12192 : return true; // Not a non-union class type. Don't care about completeness.
12193 :
12194 3115240 : if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
12195 : return true; // Not a class type. Don't care about completeness.
12196 :
12197 3114807 : if (VOID_TYPE_P (type))
12198 : return true;
12199 :
12200 3114081 : type = complete_type (strip_array_types (type));
12201 3114081 : if (!COMPLETE_TYPE_P (type)
12202 117 : && cxx_incomplete_type_diagnostic (NULL_TREE, type, DK_PERMERROR)
12203 3114198 : && !flag_permissive)
12204 : return false;
12205 : return true;
12206 : }
12207 :
12208 : /* Process a trait expression. */
12209 :
12210 : tree
12211 5457200 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
12212 : {
12213 5457200 : if (type1 == error_mark_node
12214 5457200 : || type2 == error_mark_node)
12215 : return error_mark_node;
12216 :
12217 5457200 : if (processing_template_decl)
12218 : {
12219 1782371 : tree trait_expr = make_node (TRAIT_EXPR);
12220 1782371 : TREE_TYPE (trait_expr) = boolean_type_node;
12221 1782371 : TRAIT_EXPR_TYPE1 (trait_expr) = type1;
12222 1782371 : TRAIT_EXPR_TYPE2 (trait_expr) = type2;
12223 1782371 : TRAIT_EXPR_KIND (trait_expr) = kind;
12224 1782371 : TRAIT_EXPR_LOCATION (trait_expr) = loc;
12225 1782371 : return trait_expr;
12226 : }
12227 :
12228 3674829 : switch (kind)
12229 : {
12230 20718 : case CPTK_HAS_NOTHROW_ASSIGN:
12231 20718 : case CPTK_HAS_TRIVIAL_ASSIGN:
12232 20718 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
12233 20718 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
12234 20718 : case CPTK_HAS_NOTHROW_COPY:
12235 20718 : case CPTK_HAS_TRIVIAL_COPY:
12236 20718 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
12237 20718 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
12238 20718 : if (!check_trait_type (type1))
12239 32 : return error_mark_node;
12240 : break;
12241 :
12242 103104 : case CPTK_IS_LITERAL_TYPE:
12243 103104 : case CPTK_IS_POD:
12244 103104 : case CPTK_IS_STD_LAYOUT:
12245 103104 : case CPTK_IS_TRIVIAL:
12246 103104 : case CPTK_IS_TRIVIALLY_COPYABLE:
12247 103104 : if (!check_trait_type (type1, /* kind = */ 2))
12248 24 : return error_mark_node;
12249 : break;
12250 :
12251 249933 : case CPTK_IS_EMPTY:
12252 249933 : case CPTK_IS_POLYMORPHIC:
12253 249933 : case CPTK_IS_ABSTRACT:
12254 249933 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
12255 249933 : if (!check_trait_type (type1, /* kind = */ 3))
12256 19 : return error_mark_node;
12257 : break;
12258 :
12259 : /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
12260 : type to know whether an array is an aggregate, so use kind=4 here. */
12261 326129 : case CPTK_IS_AGGREGATE:
12262 326129 : case CPTK_IS_FINAL:
12263 326129 : if (!check_trait_type (type1, /* kind = */ 4))
12264 18 : return error_mark_node;
12265 : break;
12266 :
12267 816220 : case CPTK_IS_ASSIGNABLE:
12268 816220 : case CPTK_IS_CONSTRUCTIBLE:
12269 816220 : if (!check_trait_type (type1))
12270 21 : return error_mark_node;
12271 : break;
12272 :
12273 881681 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
12274 881681 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
12275 881681 : case CPTK_IS_NOTHROW_ASSIGNABLE:
12276 881681 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
12277 881681 : case CPTK_IS_CONVERTIBLE:
12278 881681 : case CPTK_IS_NOTHROW_CONVERTIBLE:
12279 881681 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
12280 881681 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
12281 881681 : if (!check_trait_type (type1)
12282 881681 : || !check_trait_type (type2))
12283 0 : return error_mark_node;
12284 : break;
12285 :
12286 34691 : case CPTK_IS_BASE_OF:
12287 34691 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
12288 34577 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
12289 20722 : && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
12290 53966 : && !complete_type_or_else (type2, NULL_TREE))
12291 : /* We already issued an error. */
12292 32 : return error_mark_node;
12293 : break;
12294 :
12295 : case CPTK_IS_CLASS:
12296 : case CPTK_IS_ENUM:
12297 : case CPTK_IS_UNION:
12298 : case CPTK_IS_SAME:
12299 : break;
12300 :
12301 78 : case CPTK_IS_LAYOUT_COMPATIBLE:
12302 78 : if (!array_of_unknown_bound_p (type1)
12303 71 : && TREE_CODE (type1) != VOID_TYPE
12304 146 : && !complete_type_or_else (type1, NULL_TREE))
12305 : /* We already issued an error. */
12306 2 : return error_mark_node;
12307 76 : if (!array_of_unknown_bound_p (type2)
12308 65 : && TREE_CODE (type2) != VOID_TYPE
12309 138 : && !complete_type_or_else (type2, NULL_TREE))
12310 : /* We already issued an error. */
12311 1 : return error_mark_node;
12312 : break;
12313 :
12314 18 : case CPTK_IS_DEDUCIBLE:
12315 18 : if (!DECL_TYPE_TEMPLATE_P (type1))
12316 : {
12317 0 : error ("%qD is not a class or alias template", type1);
12318 0 : return error_mark_node;
12319 : }
12320 : break;
12321 :
12322 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
12323 : case CPTK_##CODE:
12324 : #include "cp-trait.def"
12325 : #undef DEFTRAIT_TYPE
12326 : /* Type-yielding traits are handled in finish_trait_type. */
12327 0 : gcc_unreachable ();
12328 : }
12329 :
12330 3674680 : tree val = (trait_expr_value (kind, type1, type2)
12331 3674680 : ? boolean_true_node : boolean_false_node);
12332 3674680 : return maybe_wrap_with_location (val, loc);
12333 : }
12334 :
12335 : /* Process a trait type. */
12336 :
12337 : tree
12338 1106696 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
12339 : tsubst_flags_t complain)
12340 : {
12341 1106696 : if (type1 == error_mark_node
12342 1106692 : || type2 == error_mark_node)
12343 : return error_mark_node;
12344 :
12345 1106692 : if (processing_template_decl)
12346 : {
12347 45885 : tree type = cxx_make_type (TRAIT_TYPE);
12348 45885 : TRAIT_TYPE_TYPE1 (type) = type1;
12349 45885 : TRAIT_TYPE_TYPE2 (type) = type2;
12350 45885 : TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
12351 : /* These traits are intended to be used in the definition of the ::type
12352 : member of the corresponding standard library type trait and aren't
12353 : mangleable (and thus won't appear directly in template signatures),
12354 : so structural equality should suffice. */
12355 45885 : SET_TYPE_STRUCTURAL_EQUALITY (type);
12356 45885 : return type;
12357 : }
12358 :
12359 1060807 : switch (kind)
12360 : {
12361 27774 : case CPTK_UNDERLYING_TYPE:
12362 27774 : return finish_underlying_type (type1);
12363 :
12364 425232 : case CPTK_REMOVE_CV:
12365 425232 : return cv_unqualified (type1);
12366 :
12367 540093 : case CPTK_REMOVE_REFERENCE:
12368 540093 : if (TYPE_REF_P (type1))
12369 313408 : type1 = TREE_TYPE (type1);
12370 : return type1;
12371 :
12372 10182 : case CPTK_REMOVE_CVREF:
12373 10182 : if (TYPE_REF_P (type1))
12374 4136 : type1 = TREE_TYPE (type1);
12375 10182 : return cv_unqualified (type1);
12376 :
12377 57526 : case CPTK_TYPE_PACK_ELEMENT:
12378 57526 : return finish_type_pack_element (type1, type2, complain);
12379 :
12380 : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
12381 : case CPTK_##CODE:
12382 : #include "cp-trait.def"
12383 : #undef DEFTRAIT_EXPR
12384 : /* Expression-yielding traits are handled in finish_trait_expr. */
12385 : case CPTK_BASES:
12386 : case CPTK_DIRECT_BASES:
12387 : /* BASES and DIRECT_BASES are handled in finish_bases. */
12388 : break;
12389 : }
12390 :
12391 0 : gcc_unreachable ();
12392 : }
12393 :
12394 : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
12395 : which is ignored for C++. */
12396 :
12397 : void
12398 0 : set_float_const_decimal64 (void)
12399 : {
12400 0 : }
12401 :
12402 : void
12403 0 : clear_float_const_decimal64 (void)
12404 : {
12405 0 : }
12406 :
12407 : bool
12408 1458212 : float_const_decimal64_p (void)
12409 : {
12410 1458212 : return 0;
12411 : }
12412 :
12413 :
12414 : /* Return true if T designates the implied `this' parameter. */
12415 :
12416 : bool
12417 81391175 : is_this_parameter (tree t)
12418 : {
12419 81391175 : if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
12420 : return false;
12421 38457627 : gcc_assert (TREE_CODE (t) == PARM_DECL
12422 : || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
12423 : || (cp_binding_oracle && VAR_P (t)));
12424 : return true;
12425 : }
12426 :
12427 : /* Insert the deduced return type for an auto function. */
12428 :
12429 : void
12430 83040 : apply_deduced_return_type (tree fco, tree return_type)
12431 : {
12432 83040 : tree result;
12433 :
12434 83040 : if (return_type == error_mark_node)
12435 : return;
12436 :
12437 83039 : if (DECL_CONV_FN_P (fco))
12438 24 : DECL_NAME (fco) = make_conv_op_name (return_type);
12439 :
12440 83039 : TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
12441 :
12442 83039 : maybe_update_postconditions (fco);
12443 :
12444 : /* Apply the type to the result object. */
12445 :
12446 83039 : result = DECL_RESULT (fco);
12447 83039 : if (result == NULL_TREE)
12448 : return;
12449 82977 : if (TREE_TYPE (result) == return_type)
12450 : return;
12451 :
12452 82976 : if (!processing_template_decl && !VOID_TYPE_P (return_type)
12453 126658 : && !complete_type_or_else (return_type, NULL_TREE))
12454 : return;
12455 :
12456 : /* We already have a DECL_RESULT from start_preparsed_function.
12457 : Now we need to redo the work it and allocate_struct_function
12458 : did to reflect the new type. */
12459 82976 : result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
12460 82976 : TYPE_MAIN_VARIANT (return_type));
12461 82976 : DECL_ARTIFICIAL (result) = 1;
12462 82976 : DECL_IGNORED_P (result) = 1;
12463 82976 : cp_apply_type_quals_to_decl (cp_type_quals (return_type),
12464 : result);
12465 82976 : DECL_RESULT (fco) = result;
12466 :
12467 82976 : if (!processing_template_decl)
12468 82976 : if (function *fun = DECL_STRUCT_FUNCTION (fco))
12469 : {
12470 82950 : bool aggr = aggregate_value_p (result, fco);
12471 : #ifdef PCC_STATIC_STRUCT_RETURN
12472 : fun->returns_pcc_struct = aggr;
12473 : #endif
12474 82950 : fun->returns_struct = aggr;
12475 : }
12476 : }
12477 :
12478 : /* DECL is a local variable or parameter from the surrounding scope of a
12479 : lambda-expression. Returns the decltype for a use of the capture field
12480 : for DECL even if it hasn't been captured yet. */
12481 :
12482 : static tree
12483 36 : capture_decltype (tree decl)
12484 : {
12485 36 : tree lam = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl));
12486 36 : tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
12487 : LOOK_want::HIDDEN_LAMBDA);
12488 36 : tree type;
12489 :
12490 36 : if (cap && is_capture_proxy (cap))
12491 21 : type = TREE_TYPE (cap);
12492 : else
12493 15 : switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam))
12494 : {
12495 3 : case CPLD_NONE:
12496 3 : error ("%qD is not captured", decl);
12497 3 : return error_mark_node;
12498 :
12499 9 : case CPLD_COPY:
12500 9 : type = TREE_TYPE (decl);
12501 9 : if (TYPE_REF_P (type)
12502 9 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
12503 0 : type = TREE_TYPE (type);
12504 : break;
12505 :
12506 3 : case CPLD_REFERENCE:
12507 3 : type = TREE_TYPE (decl);
12508 3 : if (!TYPE_REF_P (type))
12509 3 : type = build_reference_type (TREE_TYPE (decl));
12510 : break;
12511 :
12512 0 : default:
12513 0 : gcc_unreachable ();
12514 : }
12515 :
12516 33 : if (!TYPE_REF_P (type))
12517 : {
12518 24 : if (!LAMBDA_EXPR_MUTABLE_P (lam))
12519 15 : type = cp_build_qualified_type (type, (cp_type_quals (type)
12520 : |TYPE_QUAL_CONST));
12521 24 : type = build_reference_type (type);
12522 : }
12523 : return type;
12524 : }
12525 :
12526 : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
12527 : this is a right unary fold. Otherwise it is a left unary fold. */
12528 :
12529 : static tree
12530 291703 : finish_unary_fold_expr (tree expr, int op, tree_code dir)
12531 : {
12532 : /* Build a pack expansion (assuming expr has pack type). */
12533 291703 : if (!uses_parameter_packs (expr))
12534 : {
12535 3 : error_at (location_of (expr), "operand of fold expression has no "
12536 : "unexpanded parameter packs");
12537 3 : return error_mark_node;
12538 : }
12539 291700 : tree pack = make_pack_expansion (expr);
12540 :
12541 : /* Build the fold expression. */
12542 291700 : tree code = build_int_cstu (integer_type_node, abs (op));
12543 291700 : tree fold = build_min_nt_loc (input_location, dir, code, pack);
12544 291700 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
12545 291700 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
12546 291700 : FOLD_EXPR_OP (fold),
12547 291700 : FOLD_EXPR_MODIFY_P (fold));
12548 291700 : return fold;
12549 : }
12550 :
12551 : tree
12552 739 : finish_left_unary_fold_expr (tree expr, int op)
12553 : {
12554 739 : return finish_unary_fold_expr (expr, op, UNARY_LEFT_FOLD_EXPR);
12555 : }
12556 :
12557 : tree
12558 290964 : finish_right_unary_fold_expr (tree expr, int op)
12559 : {
12560 290964 : return finish_unary_fold_expr (expr, op, UNARY_RIGHT_FOLD_EXPR);
12561 : }
12562 :
12563 : /* Build a binary fold expression over EXPR1 and EXPR2. The
12564 : associativity of the fold is determined by EXPR1 and EXPR2 (whichever
12565 : has an unexpanded parameter pack). */
12566 :
12567 : tree
12568 606 : finish_binary_fold_expr (tree pack, tree init, int op, tree_code dir)
12569 : {
12570 606 : pack = make_pack_expansion (pack);
12571 606 : tree code = build_int_cstu (integer_type_node, abs (op));
12572 606 : tree fold = build_min_nt_loc (input_location, dir, code, pack, init);
12573 606 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
12574 606 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
12575 606 : FOLD_EXPR_OP (fold),
12576 606 : FOLD_EXPR_MODIFY_P (fold));
12577 606 : return fold;
12578 : }
12579 :
12580 : tree
12581 606 : finish_binary_fold_expr (tree expr1, tree expr2, int op)
12582 : {
12583 : // Determine which expr has an unexpanded parameter pack and
12584 : // set the pack and initial term.
12585 606 : bool pack1 = uses_parameter_packs (expr1);
12586 606 : bool pack2 = uses_parameter_packs (expr2);
12587 606 : if (pack1 && !pack2)
12588 189 : return finish_binary_fold_expr (expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
12589 417 : else if (pack2 && !pack1)
12590 417 : return finish_binary_fold_expr (expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
12591 : else
12592 : {
12593 0 : if (pack1)
12594 0 : error ("both arguments in binary fold have unexpanded parameter packs");
12595 : else
12596 0 : error ("no unexpanded parameter packs in binary fold");
12597 : }
12598 0 : return error_mark_node;
12599 : }
12600 :
12601 : /* Finish __builtin_launder (arg). */
12602 :
12603 : tree
12604 9523 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
12605 : {
12606 9523 : tree orig_arg = arg;
12607 9523 : if (!type_dependent_expression_p (arg))
12608 69 : arg = decay_conversion (arg, complain);
12609 9523 : if (error_operand_p (arg))
12610 0 : return error_mark_node;
12611 9523 : if (!type_dependent_expression_p (arg)
12612 9523 : && !TYPE_PTR_P (TREE_TYPE (arg)))
12613 : {
12614 9 : error_at (loc, "non-pointer argument to %<__builtin_launder%>");
12615 9 : return error_mark_node;
12616 : }
12617 9514 : if (processing_template_decl)
12618 9454 : arg = orig_arg;
12619 9514 : return build_call_expr_internal_loc (loc, IFN_LAUNDER,
12620 19028 : TREE_TYPE (arg), 1, arg);
12621 : }
12622 :
12623 : /* Finish __builtin_convertvector (arg, type). */
12624 :
12625 : tree
12626 221 : cp_build_vec_convert (tree arg, location_t loc, tree type,
12627 : tsubst_flags_t complain)
12628 : {
12629 221 : if (error_operand_p (type))
12630 12 : return error_mark_node;
12631 209 : if (error_operand_p (arg))
12632 0 : return error_mark_node;
12633 :
12634 209 : tree ret = NULL_TREE;
12635 209 : if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
12636 232 : ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
12637 : decay_conversion (arg, complain),
12638 : loc, type, (complain & tf_error) != 0);
12639 :
12640 209 : if (!processing_template_decl)
12641 : return ret;
12642 :
12643 32 : return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
12644 : }
12645 :
12646 : /* Finish __builtin_bit_cast (type, arg). */
12647 :
12648 : tree
12649 13841 : cp_build_bit_cast (location_t loc, tree type, tree arg,
12650 : tsubst_flags_t complain)
12651 : {
12652 13841 : if (error_operand_p (type))
12653 0 : return error_mark_node;
12654 13841 : if (!dependent_type_p (type))
12655 : {
12656 9570 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
12657 12 : return error_mark_node;
12658 9558 : if (TREE_CODE (type) == ARRAY_TYPE)
12659 : {
12660 : /* std::bit_cast for destination ARRAY_TYPE is not possible,
12661 : as functions may not return an array, so don't bother trying
12662 : to support this (and then deal with VLAs etc.). */
12663 12 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
12664 : "is an array type", type);
12665 12 : return error_mark_node;
12666 : }
12667 9546 : if (!trivially_copyable_p (type))
12668 : {
12669 24 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
12670 : "is not trivially copyable", type);
12671 24 : return error_mark_node;
12672 : }
12673 : }
12674 :
12675 13793 : if (error_operand_p (arg))
12676 0 : return error_mark_node;
12677 :
12678 13793 : if (!type_dependent_expression_p (arg))
12679 : {
12680 406 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
12681 : {
12682 : /* Don't perform array-to-pointer conversion. */
12683 23 : arg = mark_rvalue_use (arg, loc, true);
12684 23 : if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
12685 0 : return error_mark_node;
12686 : }
12687 : else
12688 383 : arg = decay_conversion (arg, complain);
12689 :
12690 406 : if (error_operand_p (arg))
12691 16 : return error_mark_node;
12692 :
12693 390 : if (!trivially_copyable_p (TREE_TYPE (arg)))
12694 : {
12695 12 : error_at (cp_expr_loc_or_loc (arg, loc),
12696 : "%<__builtin_bit_cast%> source type %qT "
12697 12 : "is not trivially copyable", TREE_TYPE (arg));
12698 12 : return error_mark_node;
12699 : }
12700 378 : if (!dependent_type_p (type)
12701 740 : && !cp_tree_equal (TYPE_SIZE_UNIT (type),
12702 362 : TYPE_SIZE_UNIT (TREE_TYPE (arg))))
12703 : {
12704 24 : error_at (loc, "%<__builtin_bit_cast%> source size %qE "
12705 : "not equal to destination type size %qE",
12706 24 : TYPE_SIZE_UNIT (TREE_TYPE (arg)),
12707 24 : TYPE_SIZE_UNIT (type));
12708 24 : return error_mark_node;
12709 : }
12710 : }
12711 :
12712 13741 : tree ret = build_min (BIT_CAST_EXPR, type, arg);
12713 13741 : SET_EXPR_LOCATION (ret, loc);
12714 :
12715 13741 : if (!processing_template_decl && CLASS_TYPE_P (type))
12716 170 : ret = get_target_expr (ret, complain);
12717 :
12718 : return ret;
12719 : }
12720 :
12721 : #include "gt-cp-semantics.h"
|