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-2026 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 : #include "gimplify.h"
49 : #include "contracts.h"
50 : #include "c-family/c-pragma.h"
51 :
52 : /* There routines provide a modular interface to perform many parsing
53 : operations. They may therefore be used during actual parsing, or
54 : during template instantiation, which may be regarded as a
55 : degenerate form of parsing. */
56 :
57 : static tree finalize_nrv_r (tree *, int *, void *);
58 :
59 : /* Used for OpenMP non-static data member privatization. */
60 :
61 : static hash_map<tree, tree> *omp_private_member_map;
62 : static vec<tree> omp_private_member_vec;
63 : static bool omp_private_member_ignore_next;
64 :
65 :
66 : /* Deferred Access Checking Overview
67 : ---------------------------------
68 :
69 : Most C++ expressions and declarations require access checking
70 : to be performed during parsing. However, in several cases,
71 : this has to be treated differently.
72 :
73 : For member declarations, access checking has to be deferred
74 : until more information about the declaration is known. For
75 : example:
76 :
77 : class A {
78 : typedef int X;
79 : public:
80 : X f();
81 : };
82 :
83 : A::X A::f();
84 : A::X g();
85 :
86 : When we are parsing the function return type `A::X', we don't
87 : really know if this is allowed until we parse the function name.
88 :
89 : Furthermore, some contexts require that access checking is
90 : never performed at all. These include class heads, and template
91 : instantiations.
92 :
93 : Typical use of access checking functions is described here:
94 :
95 : 1. When we enter a context that requires certain access checking
96 : mode, the function `push_deferring_access_checks' is called with
97 : DEFERRING argument specifying the desired mode. Access checking
98 : may be performed immediately (dk_no_deferred), deferred
99 : (dk_deferred), or not performed (dk_no_check).
100 :
101 : 2. When a declaration such as a type, or a variable, is encountered,
102 : the function `perform_or_defer_access_check' is called. It
103 : maintains a vector of all deferred checks.
104 :
105 : 3. The global `current_class_type' or `current_function_decl' is then
106 : setup by the parser. `enforce_access' relies on these information
107 : to check access.
108 :
109 : 4. Upon exiting the context mentioned in step 1,
110 : `perform_deferred_access_checks' is called to check all declaration
111 : stored in the vector. `pop_deferring_access_checks' is then
112 : called to restore the previous access checking mode.
113 :
114 : In case of parsing error, we simply call `pop_deferring_access_checks'
115 : without `perform_deferred_access_checks'. */
116 :
117 : struct GTY(()) deferred_access {
118 : /* A vector representing name-lookups for which we have deferred
119 : checking access controls. We cannot check the accessibility of
120 : names used in a decl-specifier-seq until we know what is being
121 : declared because code like:
122 :
123 : class A {
124 : class B {};
125 : B* f();
126 : }
127 :
128 : A::B* A::f() { return 0; }
129 :
130 : is valid, even though `A::B' is not generally accessible. */
131 : vec<deferred_access_check, va_gc> *deferred_access_checks;
132 :
133 : /* The current mode of access checks. */
134 : enum deferring_kind deferring_access_checks_kind;
135 : };
136 :
137 : /* Data for deferred access checking. */
138 : static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack;
139 : static GTY(()) unsigned deferred_access_no_check;
140 :
141 : /* Save the current deferred access states and start deferred
142 : access checking iff DEFER_P is true. */
143 :
144 : void
145 24445406165 : push_deferring_access_checks (deferring_kind deferring)
146 : {
147 : /* For context like template instantiation, access checking
148 : disabling applies to all nested context. */
149 24445406165 : if (deferred_access_no_check || deferring == dk_no_check)
150 314826969 : deferred_access_no_check++;
151 : else
152 : {
153 24130579196 : deferred_access e = {NULL, deferring};
154 24130579196 : vec_safe_push (deferred_access_stack, e);
155 : }
156 24445406165 : }
157 :
158 : /* Save the current deferred access states and start deferred access
159 : checking, continuing the set of deferred checks in CHECKS. */
160 :
161 : void
162 392368998 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
163 : {
164 392368998 : push_deferring_access_checks (dk_deferred);
165 392368998 : if (!deferred_access_no_check)
166 384506947 : deferred_access_stack->last().deferred_access_checks = checks;
167 392368998 : }
168 :
169 : /* Resume deferring access checks again after we stopped doing
170 : this previously. */
171 :
172 : void
173 186561063 : resume_deferring_access_checks (void)
174 : {
175 186561063 : if (!deferred_access_no_check)
176 186540735 : deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
177 186561063 : }
178 :
179 : /* Stop deferring access checks. */
180 :
181 : void
182 523095797 : stop_deferring_access_checks (void)
183 : {
184 523095797 : if (!deferred_access_no_check)
185 523035692 : deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
186 523095797 : }
187 :
188 : /* Discard the current deferred access checks and restore the
189 : previous states. */
190 :
191 : void
192 15153735080 : pop_deferring_access_checks (void)
193 : {
194 15153735080 : if (deferred_access_no_check)
195 241095556 : deferred_access_no_check--;
196 : else
197 14912639524 : deferred_access_stack->pop ();
198 15153735080 : }
199 :
200 : /* Returns a TREE_LIST representing the deferred checks.
201 : The TREE_PURPOSE of each node is the type through which the
202 : access occurred; the TREE_VALUE is the declaration named.
203 : */
204 :
205 : vec<deferred_access_check, va_gc> *
206 1308069383 : get_deferred_access_checks (void)
207 : {
208 1308069383 : if (deferred_access_no_check)
209 : return NULL;
210 : else
211 1291887225 : return (deferred_access_stack->last().deferred_access_checks);
212 : }
213 :
214 : /* Take current deferred checks and combine with the
215 : previous states if we also defer checks previously.
216 : Otherwise perform checks now. */
217 :
218 : void
219 9291533760 : pop_to_parent_deferring_access_checks (void)
220 : {
221 9291533760 : if (deferred_access_no_check)
222 73731407 : deferred_access_no_check--;
223 : else
224 : {
225 9217802353 : vec<deferred_access_check, va_gc> *checks;
226 9217802353 : deferred_access *ptr;
227 :
228 9217802353 : checks = (deferred_access_stack->last ().deferred_access_checks);
229 :
230 9217802353 : deferred_access_stack->pop ();
231 9217802353 : ptr = &deferred_access_stack->last ();
232 9217802353 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
233 : {
234 : /* Check access. */
235 581261479 : perform_access_checks (checks, tf_warning_or_error);
236 : }
237 : else
238 : {
239 : /* Merge with parent. */
240 : int i, j;
241 : deferred_access_check *chk, *probe;
242 :
243 8843529440 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
244 : {
245 112486473 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
246 : {
247 9981928 : if (probe->binfo == chk->binfo &&
248 7893054 : probe->decl == chk->decl &&
249 990678 : probe->diag_decl == chk->diag_decl)
250 989738 : goto found;
251 : }
252 : /* Insert into parent's checks. */
253 102504545 : vec_safe_push (ptr->deferred_access_checks, *chk);
254 103494283 : found:;
255 : }
256 : }
257 : }
258 9291533760 : }
259 :
260 : /* Called from enforce_access. A class has attempted (but failed) to access
261 : DECL. It is already established that a baseclass of that class,
262 : PARENT_BINFO, has private access to DECL. Examine certain special cases
263 : to find a decl that accurately describes the source of the problem. If
264 : none of the special cases apply, simply return DECL as the source of the
265 : problem. */
266 :
267 : static tree
268 182 : get_class_access_diagnostic_decl (tree parent_binfo, tree decl)
269 : {
270 : /* When a class is denied access to a decl in a baseclass, most of the
271 : time it is because the decl itself was declared as private at the point
272 : of declaration.
273 :
274 : However, in C++, there are (at least) two situations in which a decl
275 : can be private even though it was not originally defined as such.
276 : These two situations only apply if a baseclass had private access to
277 : DECL (this function is only called if that is the case). */
278 :
279 : /* We should first check whether the reason the parent had private access
280 : to DECL was simply because DECL was created and declared as private in
281 : the parent. If it was, then DECL is definitively the source of the
282 : problem. */
283 182 : if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl),
284 : BINFO_TYPE (parent_binfo)))
285 : return decl;
286 :
287 : /* 1. If the "using" keyword is used to inherit DECL within the parent,
288 : this may cause DECL to be private, so we should return the using
289 : statement as the source of the problem.
290 :
291 : Scan the fields of PARENT_BINFO and see if there are any using decls. If
292 : there are, see if they inherit DECL. If they do, that's where DECL must
293 : have been declared private. */
294 :
295 66 : for (tree parent_field = TYPE_FIELDS (BINFO_TYPE (parent_binfo));
296 326 : parent_field;
297 260 : parent_field = DECL_CHAIN (parent_field))
298 : /* Not necessary, but also check TREE_PRIVATE for the sake of
299 : eliminating obviously non-relevant using decls. */
300 278 : if (TREE_CODE (parent_field) == USING_DECL
301 81 : && TREE_PRIVATE (parent_field))
302 : {
303 78 : tree decl_stripped = strip_using_decl (parent_field);
304 :
305 : /* The using statement might be overloaded. If so, we need to
306 : check all of the overloads. */
307 180 : for (ovl_iterator iter (decl_stripped); iter; ++iter)
308 : /* If equal, the using statement inherits DECL, and so is the
309 : source of the access failure, so return it. */
310 99 : if (*iter == decl)
311 18 : return parent_field;
312 : }
313 :
314 : /* 2. If DECL was privately inherited by the parent class, then DECL will
315 : be inaccessible, even though it may originally have been accessible to
316 : deriving classes. In that case, the fault lies with the parent, since it
317 : used a private inheritance, so we return the parent as the source of the
318 : problem.
319 :
320 : Since this is the last check, we just assume it's true. At worst, it
321 : will simply point to the class that failed to give access, which is
322 : technically true. */
323 48 : return TYPE_NAME (BINFO_TYPE (parent_binfo));
324 : }
325 :
326 : /* If the current scope isn't allowed to access DECL along
327 : BASETYPE_PATH, give an error, or if we're parsing a function or class
328 : template, defer the access check to be performed at instantiation time.
329 : The most derived class in BASETYPE_PATH is the one used to qualify DECL.
330 : DIAG_DECL is the declaration to use in the error diagnostic. */
331 :
332 : static bool
333 425553665 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
334 : tsubst_flags_t complain, access_failure_info *afi = NULL)
335 : {
336 425553665 : gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
337 :
338 425553665 : if (flag_new_inheriting_ctors
339 537815300 : && DECL_INHERITED_CTOR (decl))
340 : {
341 : /* 7.3.3/18: The additional constructors are accessible if they would be
342 : accessible when used to construct an object of the corresponding base
343 : class. */
344 63237 : decl = strip_inheriting_ctors (decl);
345 63237 : basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
346 : ba_any, NULL, complain);
347 : }
348 :
349 425553665 : tree cs = current_scope ();
350 425553665 : if (in_template_context
351 425553665 : && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
352 42484845 : if (tree template_info = get_template_info (cs))
353 : {
354 : /* When parsing a function or class template, we in general need to
355 : defer access checks until template instantiation time, since a friend
356 : declaration may grant access only to a particular specialization of
357 : the template. */
358 :
359 42237062 : if (accessible_p (basetype_path, decl, /*consider_local_p=*/true))
360 : /* But if the member is deemed accessible at parse time, then we can
361 : assume it'll be accessible at instantiation time. */
362 : return true;
363 :
364 : /* Access of a dependent decl should be rechecked after tsubst'ing
365 : into the user of the decl, rather than explicitly deferring the
366 : check here. */
367 135 : gcc_assert (!uses_template_parms (decl));
368 135 : if (TREE_CODE (decl) == FIELD_DECL)
369 6 : gcc_assert (!uses_template_parms (DECL_CONTEXT (decl)));
370 :
371 : /* Defer this access check until instantiation time. */
372 135 : deferred_access_check access_check;
373 135 : access_check.binfo = basetype_path;
374 135 : access_check.decl = decl;
375 135 : access_check.diag_decl = diag_decl;
376 135 : access_check.loc = input_location;
377 135 : vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info), access_check);
378 135 : return true;
379 : }
380 :
381 383316603 : if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
382 : {
383 22451 : if (flag_new_inheriting_ctors)
384 22421 : diag_decl = strip_inheriting_ctors (diag_decl);
385 22451 : if (complain & tf_error)
386 : {
387 1159 : access_kind access_failure_reason = ak_none;
388 :
389 : /* By default, using the decl as the source of the problem will
390 : usually give correct results. */
391 1159 : tree diag_location = diag_decl;
392 :
393 : /* However, if a parent of BASETYPE_PATH had private access to decl,
394 : then it actually might be the case that the source of the problem
395 : is not DECL. */
396 1159 : tree parent_binfo = get_parent_with_private_access (decl,
397 : basetype_path);
398 :
399 : /* So if a parent did have private access, then we need to do
400 : special checks to obtain the best diagnostic location decl. */
401 1159 : if (parent_binfo != NULL_TREE)
402 : {
403 182 : diag_location = get_class_access_diagnostic_decl (parent_binfo,
404 : diag_decl);
405 :
406 : /* We also at this point know that the reason access failed was
407 : because decl was private. */
408 182 : access_failure_reason = ak_private;
409 : }
410 :
411 : /* Finally, generate an error message. */
412 1159 : complain_about_access (decl, diag_decl, diag_location, true,
413 : access_failure_reason);
414 : }
415 22451 : if (afi)
416 412 : afi->record_access_failure (basetype_path, decl, diag_decl);
417 : return false;
418 : }
419 :
420 : return true;
421 : }
422 :
423 : /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
424 : is the BINFO indicating the qualifying scope used to access the
425 : DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
426 : or we aren't in SFINAE context or all the checks succeed return TRUE,
427 : otherwise FALSE. */
428 :
429 : bool
430 1114089390 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
431 : tsubst_flags_t complain)
432 : {
433 1114089390 : int i;
434 1114089390 : deferred_access_check *chk;
435 1114089390 : location_t loc = input_location;
436 1114089390 : bool ok = true;
437 :
438 1114089390 : if (!checks)
439 : return true;
440 :
441 129648660 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
442 : {
443 72155928 : input_location = chk->loc;
444 72155928 : ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
445 : }
446 :
447 57492732 : input_location = loc;
448 57492732 : return (complain & tf_error) ? true : ok;
449 : }
450 :
451 : /* Perform the deferred access checks.
452 :
453 : After performing the checks, we still have to keep the list
454 : `deferred_access_stack->deferred_access_checks' since we may want
455 : to check access for them again later in a different context.
456 : For example:
457 :
458 : class A {
459 : typedef int X;
460 : static X a;
461 : };
462 : A::X A::a, x; // No error for `A::a', error for `x'
463 :
464 : We have to perform deferred access of `A::X', first with `A::a',
465 : next with `x'. Return value like perform_access_checks above. */
466 :
467 : bool
468 291131877 : perform_deferred_access_checks (tsubst_flags_t complain)
469 : {
470 291131877 : return perform_access_checks (get_deferred_access_checks (), complain);
471 : }
472 :
473 : /* Defer checking the accessibility of DECL, when looked up in
474 : BINFO. DIAG_DECL is the declaration to use to print diagnostics.
475 : Return value like perform_access_checks above.
476 : If non-NULL, report failures to AFI. */
477 :
478 : bool
479 639086319 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
480 : tsubst_flags_t complain,
481 : access_failure_info *afi)
482 : {
483 639086319 : int i;
484 639086319 : deferred_access *ptr;
485 639086319 : deferred_access_check *chk;
486 :
487 : /* Exit if we are in a context that no access checking is performed. */
488 639086319 : if (deferred_access_no_check)
489 : return true;
490 :
491 608260901 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
492 :
493 608260901 : ptr = &deferred_access_stack->last ();
494 :
495 : /* If we are not supposed to defer access checks, just check now. */
496 608260901 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
497 : {
498 353397737 : bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
499 353397737 : return (complain & tf_error) ? true : ok;
500 : }
501 :
502 : /* See if we are already going to perform this check. */
503 310053897 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
504 : {
505 72445331 : if (chk->decl == decl && chk->binfo == binfo &&
506 17255677 : chk->diag_decl == diag_decl)
507 : {
508 : return true;
509 : }
510 : }
511 : /* If not, record the check. */
512 237608566 : deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
513 237608566 : vec_safe_push (ptr->deferred_access_checks, new_access);
514 :
515 237608566 : return true;
516 : }
517 :
518 : /* Returns nonzero if the current statement is a full expression,
519 : i.e. temporaries created during that statement should be destroyed
520 : at the end of the statement. */
521 :
522 : int
523 1532432300 : stmts_are_full_exprs_p (void)
524 : {
525 1532432300 : return current_stmt_tree ()->stmts_are_full_exprs_p;
526 : }
527 :
528 : /* T is a statement. Add it to the statement-tree. This is the C++
529 : version. The C/ObjC frontends have a slightly different version of
530 : this function. */
531 :
532 : tree
533 1322140693 : add_stmt (tree t)
534 : {
535 1322140693 : enum tree_code code = TREE_CODE (t);
536 :
537 1322140693 : if (EXPR_P (t) && code != LABEL_EXPR)
538 : {
539 1271130558 : if (!EXPR_HAS_LOCATION (t))
540 203088764 : SET_EXPR_LOCATION (t, input_location);
541 :
542 : /* When we expand a statement-tree, we must know whether or not the
543 : statements are full-expressions. We record that fact here. */
544 1271130558 : if (STATEMENT_CODE_P (TREE_CODE (t)))
545 331002508 : STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
546 : }
547 :
548 1322140693 : if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
549 5910313 : STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
550 :
551 : /* Add T to the statement-tree. Non-side-effect statements need to be
552 : recorded during statement expressions. */
553 1322140693 : gcc_checking_assert (!stmt_list_stack->is_empty ());
554 1322140693 : append_to_statement_list_force (t, &cur_stmt_list);
555 :
556 1322140693 : return t;
557 : }
558 :
559 : /* Returns the stmt_tree to which statements are currently being added. */
560 :
561 : stmt_tree
562 7833935523 : current_stmt_tree (void)
563 : {
564 7833935523 : return (cfun
565 7794875645 : ? &cfun->language->base.x_stmt_tree
566 7833935523 : : &scope_chain->x_stmt_tree);
567 : }
568 :
569 : /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
570 :
571 : static tree
572 330167 : maybe_cleanup_point_expr (tree expr)
573 : {
574 330167 : if (!processing_template_decl && stmts_are_full_exprs_p ())
575 316799 : expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
576 330167 : return expr;
577 : }
578 :
579 : /* Like maybe_cleanup_point_expr except have the type of the new expression be
580 : void so we don't need to create a temporary variable to hold the inner
581 : expression. The reason why we do this is because the original type might be
582 : an aggregate and we cannot create a temporary variable for that type. */
583 :
584 : tree
585 327734617 : maybe_cleanup_point_expr_void (tree expr)
586 : {
587 327734617 : if (!processing_template_decl && stmts_are_full_exprs_p ())
588 110126354 : expr = fold_build_cleanup_point_expr (void_type_node, expr);
589 327734617 : return expr;
590 : }
591 :
592 :
593 :
594 : /* Create a declaration statement for the declaration given by the DECL. */
595 :
596 : void
597 110815512 : add_decl_expr (tree decl)
598 : {
599 110815512 : tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
600 110815512 : if (DECL_INITIAL (decl)
601 110815512 : || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
602 19705488 : r = maybe_cleanup_point_expr_void (r);
603 110815512 : add_stmt (r);
604 110815512 : }
605 :
606 : /* Set EXPR_LOCATION on one cleanup T to LOC. */
607 :
608 : static void
609 5914504 : set_one_cleanup_loc (tree t, location_t loc)
610 : {
611 5914504 : if (!t)
612 : return;
613 :
614 5914504 : if (TREE_CODE (t) != POSTCONDITION_STMT)
615 5914504 : protected_set_expr_location (t, loc);
616 :
617 : /* Avoid locus differences for C++ cdtor calls depending on whether
618 : cdtor_returns_this: a conversion to void is added to discard the return
619 : value, and this conversion ends up carrying the location, and when it
620 : gets discarded, the location is lost. So hold it in the call as well. */
621 5914504 : if (TREE_CODE (t) == NOP_EXPR
622 0 : && TREE_TYPE (t) == void_type_node
623 5914504 : && TREE_CODE (TREE_OPERAND (t, 0)) == CALL_EXPR)
624 0 : protected_set_expr_location (TREE_OPERAND (t, 0), loc);
625 : }
626 :
627 : /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC. */
628 :
629 : static void
630 1247876468 : set_cleanup_locs (tree stmts, location_t loc)
631 : {
632 1253790972 : if (TREE_CODE (stmts) == CLEANUP_STMT)
633 : {
634 5914504 : set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
635 5914504 : set_cleanup_locs (CLEANUP_BODY (stmts), loc);
636 : }
637 1247876468 : else if (TREE_CODE (stmts) == STATEMENT_LIST)
638 1109378755 : for (tree stmt : tsi_range (stmts))
639 859073581 : set_cleanup_locs (stmt, loc);
640 1247876468 : }
641 :
642 : /* True iff the innermost block scope is a try block. */
643 :
644 : static bool
645 388802887 : at_try_scope ()
646 : {
647 388802887 : cp_binding_level *b = current_binding_level;
648 388803343 : while (b && b->kind == sk_cleanup)
649 456 : b = b->level_chain;
650 388802887 : return b && b->kind == sk_try;
651 : }
652 :
653 : /* Finish a scope. */
654 :
655 : tree
656 388802887 : do_poplevel (tree stmt_list)
657 : {
658 388802887 : tree block = NULL;
659 :
660 388802887 : bool was_try = at_try_scope ();
661 :
662 388802887 : if (stmts_are_full_exprs_p ())
663 388740088 : block = poplevel (kept_level_p (), 1, 0);
664 :
665 : /* This needs to come after poplevel merges sk_cleanup statement_lists. */
666 388802887 : maybe_splice_retval_cleanup (stmt_list, was_try);
667 :
668 388802887 : stmt_list = pop_stmt_list (stmt_list);
669 :
670 : /* input_location is the last token of the scope, usually a }. */
671 388802887 : set_cleanup_locs (stmt_list, input_location);
672 :
673 388802887 : if (!processing_template_decl)
674 : {
675 119787381 : stmt_list = c_build_bind_expr (input_location, block, stmt_list);
676 : /* ??? See c_end_compound_stmt re statement expressions. */
677 : }
678 :
679 388802887 : return stmt_list;
680 : }
681 :
682 : /* Begin a new scope. */
683 :
684 : tree
685 388765038 : do_pushlevel (scope_kind sk)
686 : {
687 388765038 : tree ret = push_stmt_list ();
688 388765038 : if (stmts_are_full_exprs_p ())
689 388740142 : begin_scope (sk, NULL);
690 388765038 : return ret;
691 : }
692 :
693 : /* Queue a cleanup. CLEANUP is an expression/statement to be executed
694 : when the current scope is exited. EH_ONLY is true when this is not
695 : meant to apply to normal control flow transfer. DECL is the VAR_DECL
696 : being cleaned up, if any, or null for temporaries or subobjects. */
697 :
698 : void
699 5914442 : push_cleanup (tree decl, tree cleanup, bool eh_only)
700 : {
701 5914442 : tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
702 5914442 : CLEANUP_EH_ONLY (stmt) = eh_only;
703 5914442 : add_stmt (stmt);
704 5914442 : CLEANUP_BODY (stmt) = push_stmt_list ();
705 5914442 : }
706 :
707 : /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
708 : the current loops, represented by 'NULL_TREE' if we've seen a possible
709 : exit, and 'error_mark_node' if not. This is currently used only to
710 : suppress the warning about a function with no return statements, and
711 : therefore we don't bother noting returns as possible exits. We also
712 : don't bother with gotos. */
713 :
714 : static void
715 18611758 : begin_maybe_infinite_loop (tree cond)
716 : {
717 : /* Only track this while parsing a function, not during instantiation. */
718 18611758 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
719 2728866 : && !processing_template_decl))
720 : return;
721 15882394 : bool maybe_infinite = true;
722 15882394 : if (cond)
723 : {
724 15570018 : cond = fold_non_dependent_expr (cond);
725 15570018 : maybe_infinite = integer_nonzerop (cond);
726 : }
727 31452412 : vec_safe_push (cp_function_chain->infinite_loops,
728 15882394 : maybe_infinite ? error_mark_node : NULL_TREE);
729 :
730 : }
731 :
732 : /* A break is a possible exit for the current loop. */
733 :
734 : void
735 1551819 : break_maybe_infinite_loop (void)
736 : {
737 1551819 : if (!cfun)
738 : return;
739 1551819 : cp_function_chain->infinite_loops->last() = NULL_TREE;
740 : }
741 :
742 : /* If we reach the end of the loop without seeing a possible exit, we have
743 : an infinite loop. */
744 :
745 : static void
746 18611758 : end_maybe_infinite_loop (tree cond)
747 : {
748 18611758 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
749 2728866 : && !processing_template_decl))
750 : return;
751 15882394 : tree current = cp_function_chain->infinite_loops->pop();
752 15882394 : if (current != NULL_TREE)
753 : {
754 5131418 : cond = fold_non_dependent_expr (cond);
755 5131418 : if (integer_nonzerop (cond))
756 335838 : current_function_infinite_loop = 1;
757 : }
758 : }
759 :
760 : /* Begin a conditional that might contain a declaration. When generating
761 : normal code, we want the declaration to appear before the statement
762 : containing the conditional. When generating template code, we want the
763 : conditional to be rendered as the raw DECL_EXPR. */
764 :
765 : static void
766 89848240 : begin_cond (tree *cond_p)
767 : {
768 89848240 : if (processing_template_decl)
769 63605498 : *cond_p = push_stmt_list ();
770 89848240 : }
771 :
772 : /* Finish such a conditional. */
773 :
774 : static void
775 89848240 : finish_cond (tree *cond_p, tree expr)
776 : {
777 89848240 : if (processing_template_decl)
778 : {
779 63605498 : tree cond = pop_stmt_list (*cond_p);
780 :
781 63605498 : if (expr == NULL_TREE)
782 : /* Empty condition in 'for'. */
783 291568 : gcc_assert (empty_expr_stmt_p (cond));
784 63313930 : else if (check_for_bare_parameter_packs (expr))
785 0 : expr = error_mark_node;
786 63313930 : else if (!empty_expr_stmt_p (cond))
787 939647 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
788 : }
789 89848240 : *cond_p = expr;
790 89848240 : }
791 :
792 : /* If loop condition specifies a conditional with a declaration,
793 : such as
794 : while (A x = 42) { }
795 : for (; A x = 42;) { }
796 : move the *BODY_P statements as a BIND_EXPR into {FOR,WHILE}_COND_PREP
797 : and if there are any CLEANUP_STMT at the end, remember their count in
798 : {FOR,WHILE}_COND_CLEANUP.
799 : genericize_c_loop will then handle it appropriately. In particular,
800 : the {FOR,WHILE}_COND, {FOR,WHILE}_BODY, if used continue label and
801 : FOR_EXPR will be appended into the {FOR,WHILE}_COND_PREP BIND_EXPR,
802 : but it can't be done too early because only the actual body should
803 : bind BREAK_STMT and CONTINUE_STMT to the inner loop.
804 : The statement list for *BODY will be empty if the conditional did
805 : not declare anything. */
806 :
807 : static void
808 12554966 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
809 : {
810 12554966 : if (!TREE_SIDE_EFFECTS (*body_p))
811 12545193 : return;
812 :
813 9773 : gcc_assert (!processing_template_decl);
814 9773 : *prep_p = *body_p;
815 9773 : if (*prep_p != cur_stmt_list)
816 : {
817 : /* There can be just one CLEANUP_STMT, or there could be multiple
818 : nested CLEANUP_STMTs, e.g. for structured bindings used as
819 : condition. */
820 97 : gcc_assert (stmt_list_stack->length () > 1);
821 97 : for (unsigned i = stmt_list_stack->length () - 2; ; --i)
822 : {
823 109 : tree t = (*stmt_list_stack)[i];
824 109 : tree_stmt_iterator last = tsi_last (t);
825 218 : gcc_assert (tsi_one_before_end_p (last)
826 : && TREE_CODE (tsi_stmt (last)) == CLEANUP_STMT
827 : && (CLEANUP_BODY (tsi_stmt (last))
828 : == (*stmt_list_stack)[i + 1])
829 : && !CLEANUP_EH_ONLY (tsi_stmt (last)));
830 109 : if (t == *prep_p)
831 : {
832 97 : *cleanup_p = build_int_cst (long_unsigned_type_node,
833 97 : stmt_list_stack->length () - 1 - i);
834 97 : break;
835 : }
836 12 : gcc_assert (i >= 1);
837 12 : }
838 : }
839 9773 : current_binding_level->keep = true;
840 9773 : tree_stmt_iterator iter = tsi_last (cur_stmt_list);
841 : /* Temporarily store in {FOR,WHILE}_BODY the last statement of
842 : the innnermost statement list or NULL if it has no statement.
843 : This is used in finish_loop_cond_prep to find out the splitting
844 : point and then {FOR,WHILE}_BODY will be changed to the actual
845 : body. */
846 9773 : if (tsi_end_p (iter))
847 : *body_p = NULL_TREE;
848 : else
849 9682 : *body_p = tsi_stmt (iter);
850 : }
851 :
852 : /* Finalize {FOR,WHILE}_{BODY,COND_PREP} after the loop body.
853 : The above function initialized *BODY_P to the last statement
854 : in *PREP_P at that point.
855 : Call do_poplevel on *PREP_P and move everything after that
856 : former last statement into *BODY_P. genericize_c_loop
857 : will later put those parts back together.
858 : CLEANUP is {FOR,WHILE}_COND_CLEANUP. */
859 :
860 : static void
861 9773 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
862 : {
863 9773 : *prep_p = do_poplevel (*prep_p);
864 9773 : gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
865 9773 : if (BIND_EXPR_BODY (*prep_p) == *body_p)
866 : {
867 18 : gcc_assert (cleanup == NULL_TREE);
868 18 : *body_p = build_empty_stmt (input_location);
869 109 : return;
870 : }
871 9755 : tree stmt_list = BIND_EXPR_BODY (*prep_p);
872 9755 : gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
873 9755 : if (cleanup)
874 : {
875 97 : tree_stmt_iterator iter = tsi_last (stmt_list);
876 97 : gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
877 109 : for (unsigned depth = tree_to_uhwi (cleanup); depth > 1; --depth)
878 : {
879 12 : gcc_assert (TREE_CODE (CLEANUP_BODY (tsi_stmt (iter)))
880 : == STATEMENT_LIST);
881 12 : iter = tsi_last (CLEANUP_BODY (tsi_stmt (iter)));
882 12 : gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
883 : }
884 97 : if (*body_p == NULL_TREE)
885 : {
886 91 : *body_p = CLEANUP_BODY (tsi_stmt (iter));
887 91 : CLEANUP_BODY (tsi_stmt (iter)) = build_empty_stmt (input_location);
888 91 : return;
889 : }
890 6 : stmt_list = CLEANUP_BODY (tsi_stmt (iter));
891 : }
892 9664 : tree_stmt_iterator iter = tsi_start (stmt_list);
893 9896 : while (tsi_stmt (iter) != *body_p)
894 232 : tsi_next (&iter);
895 9664 : *body_p = tsi_split_stmt_list (input_location, iter);
896 : }
897 :
898 : /* Finish a goto-statement. */
899 :
900 : tree
901 2764 : finish_goto_stmt (tree destination)
902 : {
903 2764 : if (identifier_p (destination))
904 2618 : destination = lookup_label (destination);
905 :
906 : /* We warn about unused labels with -Wunused. That means we have to
907 : mark the used labels as used. */
908 2764 : if (TREE_CODE (destination) == LABEL_DECL)
909 2618 : TREE_USED (destination) = 1;
910 : else
911 : {
912 146 : destination = mark_rvalue_use (destination);
913 146 : if (!processing_template_decl)
914 : {
915 126 : destination = cp_convert (ptr_type_node, destination,
916 : tf_warning_or_error);
917 126 : if (error_operand_p (destination))
918 : return NULL_TREE;
919 117 : destination
920 117 : = fold_build_cleanup_point_expr (TREE_TYPE (destination),
921 : destination);
922 : }
923 : }
924 :
925 2755 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
926 :
927 2755 : tree stmt = build_stmt (input_location, GOTO_EXPR, destination);
928 2755 : check_goto (&TREE_OPERAND (stmt, 0));
929 :
930 2755 : return add_stmt (stmt);
931 : }
932 :
933 : /* Returns true if T corresponds to an assignment operator expression. */
934 :
935 : static bool
936 879632 : is_assignment_op_expr_p (tree t)
937 : {
938 879632 : if (t == NULL_TREE)
939 : return false;
940 :
941 879632 : if (TREE_CODE (t) == MODIFY_EXPR
942 879632 : || (TREE_CODE (t) == MODOP_EXPR
943 336 : && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
944 : return true;
945 :
946 878945 : tree call = extract_call_expr (t);
947 878945 : if (call == NULL_TREE
948 129830 : || call == error_mark_node
949 1008775 : || !CALL_EXPR_OPERATOR_SYNTAX (call))
950 : return false;
951 :
952 4664 : tree fndecl = cp_get_callee_fndecl_nofold (call);
953 4664 : return fndecl != NULL_TREE
954 4566 : && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
955 4715 : && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR);
956 : }
957 :
958 : /* Return true if TYPE is a class type that is convertible to
959 : and assignable from bool. */
960 :
961 : static GTY((deletable)) hash_map<tree, bool> *boolish_class_type_p_cache;
962 :
963 : static bool
964 60 : boolish_class_type_p (tree type)
965 : {
966 60 : type = TYPE_MAIN_VARIANT (type);
967 60 : if (!CLASS_TYPE_P (type) || !COMPLETE_TYPE_P (type))
968 : return false;
969 :
970 77 : if (bool *r = hash_map_safe_get (boolish_class_type_p_cache, type))
971 26 : return *r;
972 :
973 19 : tree ops;
974 19 : bool has_bool_assignment = false;
975 19 : bool has_bool_conversion = false;
976 :
977 19 : ops = lookup_fnfields (type, assign_op_identifier, /*protect=*/0, tf_none);
978 58 : for (tree op : ovl_range (BASELINK_FUNCTIONS (ops)))
979 : {
980 31 : op = STRIP_TEMPLATE (op);
981 31 : if (TREE_CODE (op) != FUNCTION_DECL)
982 0 : continue;
983 31 : tree parm = DECL_CHAIN (DECL_ARGUMENTS (op));
984 31 : tree parm_type = non_reference (TREE_TYPE (parm));
985 31 : if (TREE_CODE (parm_type) == BOOLEAN_TYPE)
986 : {
987 : has_bool_assignment = true;
988 : break;
989 : }
990 : }
991 :
992 19 : if (has_bool_assignment)
993 : {
994 4 : ops = lookup_conversions (type);
995 8 : for (; ops; ops = TREE_CHAIN (ops))
996 : {
997 4 : tree op = TREE_VALUE (ops);
998 4 : if (!DECL_NONCONVERTING_P (op)
999 4 : && TREE_CODE (DECL_CONV_FN_TYPE (op)) == BOOLEAN_TYPE)
1000 : {
1001 : has_bool_conversion = true;
1002 : break;
1003 : }
1004 : }
1005 : }
1006 :
1007 19 : bool boolish = has_bool_assignment && has_bool_conversion;
1008 19 : hash_map_safe_put<true> (boolish_class_type_p_cache, type, boolish);
1009 19 : return boolish;
1010 : }
1011 :
1012 :
1013 : /* Maybe warn about an unparenthesized 'a = b' (appearing in a
1014 : boolean context where 'a == b' might have been intended).
1015 : NESTED_P is true if T is the RHS of another assignment. */
1016 :
1017 : void
1018 92763517 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
1019 : tsubst_flags_t complain)
1020 : {
1021 92763517 : tree type = TREE_TYPE (t);
1022 92763517 : t = STRIP_REFERENCE_REF (t);
1023 :
1024 92763517 : if ((complain & tf_warning)
1025 92701807 : && warn_parentheses
1026 879632 : && is_assignment_op_expr_p (t)
1027 : /* A parenthesized expression would've had this warning
1028 : suppressed by finish_parenthesized_expr. */
1029 738 : && !warning_suppressed_p (t, OPT_Wparentheses)
1030 : /* In c = a = b, don't warn if a has type bool or bool-like class. */
1031 92763864 : && (!nested_p
1032 176 : || (TREE_CODE (type) != BOOLEAN_TYPE
1033 60 : && !boolish_class_type_p (type))))
1034 : {
1035 219 : warning_at (cp_expr_loc_or_input_loc (t), OPT_Wparentheses,
1036 : "suggest parentheses around assignment used as truth value");
1037 219 : suppress_warning (t, OPT_Wparentheses);
1038 : }
1039 92763517 : }
1040 :
1041 : /* Helper class for saving/restoring ANNOTATE_EXPRs. For a tree node t, users
1042 : can construct one of these like so:
1043 :
1044 : annotate_saver s (&t);
1045 :
1046 : and t will be updated to have any annotations removed. The user can then
1047 : transform t, and later restore the ANNOTATE_EXPRs with:
1048 :
1049 : t = s.restore (t).
1050 :
1051 : The intent is to ensure that any ANNOTATE_EXPRs remain the outermost
1052 : expressions following any operations on t. */
1053 :
1054 : class annotate_saver {
1055 : /* The chain of saved annotations, if there were any. Otherwise null. */
1056 : tree m_annotations;
1057 :
1058 : /* If M_ANNOTATIONS is non-null, then M_INNER points to TREE_OPERAND (A, 0)
1059 : for the innermost annotation A. */
1060 : tree *m_inner;
1061 :
1062 : public:
1063 : annotate_saver (tree *);
1064 : tree restore (tree);
1065 : };
1066 :
1067 : /* If *COND is an ANNOTATE_EXPR, walk through the chain of annotations, and set
1068 : *COND equal to the first non-ANNOTATE_EXPR (saving a pointer to the
1069 : original chain of annotations for later use in restore). */
1070 :
1071 54762995 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
1072 : {
1073 54762995 : tree *t = cond;
1074 54773394 : while (TREE_CODE (*t) == ANNOTATE_EXPR)
1075 10399 : t = &TREE_OPERAND (*t, 0);
1076 :
1077 54762995 : if (t != cond)
1078 : {
1079 10396 : m_annotations = *cond;
1080 10396 : *cond = *t;
1081 10396 : m_inner = t;
1082 : }
1083 54762995 : }
1084 :
1085 : /* If we didn't strip any annotations on construction, return NEW_INNER
1086 : unmodified. Otherwise, wrap the saved annotations around NEW_INNER (updating
1087 : the types and flags of the annotations if needed) and return the resulting
1088 : expression. */
1089 :
1090 : tree
1091 54762995 : annotate_saver::restore (tree new_inner)
1092 : {
1093 54762995 : if (!m_annotations)
1094 : return new_inner;
1095 :
1096 : /* If the type of the inner expression changed, we need to update the types
1097 : of all the ANNOTATE_EXPRs. We may need to update the flags too, but we
1098 : assume they only change if the type of the inner expression changes.
1099 : The flag update logic assumes that the other operands to the
1100 : ANNOTATE_EXPRs are always INTEGER_CSTs. */
1101 10396 : if (TREE_TYPE (new_inner) != TREE_TYPE (*m_inner))
1102 : {
1103 6 : const bool new_readonly
1104 6 : = TREE_READONLY (new_inner) || CONSTANT_CLASS_P (new_inner);
1105 :
1106 12 : for (tree c = m_annotations; c != *m_inner; c = TREE_OPERAND (c, 0))
1107 : {
1108 6 : gcc_checking_assert (TREE_CODE (c) == ANNOTATE_EXPR
1109 : && TREE_CODE (TREE_OPERAND (c, 1)) == INTEGER_CST
1110 : && TREE_CODE (TREE_OPERAND (c, 2)) == INTEGER_CST);
1111 6 : TREE_TYPE (c) = TREE_TYPE (new_inner);
1112 6 : TREE_SIDE_EFFECTS (c) = TREE_SIDE_EFFECTS (new_inner);
1113 6 : TREE_READONLY (c) = new_readonly;
1114 : }
1115 : }
1116 :
1117 10396 : *m_inner = new_inner;
1118 10396 : return m_annotations;
1119 : }
1120 :
1121 : /* COND is the condition-expression for an if, while, etc.,
1122 : statement. Convert it to a boolean value, if appropriate.
1123 : In addition, verify sequence points if -Wsequence-point is enabled. */
1124 :
1125 : tree
1126 94899705 : maybe_convert_cond (tree cond)
1127 : {
1128 : /* Empty conditions remain empty. */
1129 94899705 : if (!cond)
1130 : return NULL_TREE;
1131 :
1132 : /* Wait until we instantiate templates before doing conversion. */
1133 94527214 : if (type_dependent_expression_p (cond))
1134 39764219 : return cond;
1135 :
1136 : /* Strip any ANNOTATE_EXPRs from COND. */
1137 54762995 : annotate_saver annotations (&cond);
1138 :
1139 : /* For structured binding used in condition, the conversion needs to be
1140 : evaluated before the individual variables are initialized in the
1141 : std::tuple_{size,element} case. cp_finish_decomp saved the conversion
1142 : result in a TARGET_EXPR, pick it up from there. */
1143 383373 : if (DECL_DECOMPOSITION_P (cond)
1144 225 : && DECL_DECOMP_IS_BASE (cond)
1145 225 : && DECL_DECOMP_BASE (cond)
1146 54763217 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1147 56 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1148 :
1149 54762995 : if (warn_sequence_point && !processing_template_decl)
1150 328972 : verify_sequence_points (cond);
1151 :
1152 54762995 : maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
1153 : tf_warning_or_error);
1154 :
1155 : /* Do the conversion. */
1156 54762995 : cond = convert_from_reference (cond);
1157 54762995 : cond = condition_conversion (cond);
1158 :
1159 : /* Restore any ANNOTATE_EXPRs around COND. */
1160 54762995 : return annotations.restore (cond);
1161 : }
1162 :
1163 : /* Finish an expression-statement, whose EXPRESSION is as indicated. */
1164 :
1165 : tree
1166 168431005 : finish_expr_stmt (tree expr)
1167 : {
1168 168431005 : tree r = NULL_TREE;
1169 168431005 : location_t loc = EXPR_LOCATION (expr);
1170 :
1171 168234943 : if (expr != NULL_TREE)
1172 : {
1173 : /* If we ran into a problem, make sure we complained. */
1174 168430844 : gcc_assert (expr != error_mark_node || seen_error ());
1175 :
1176 168430844 : if (!processing_template_decl)
1177 : {
1178 61429022 : if (warn_sequence_point)
1179 818151 : verify_sequence_points (expr);
1180 61429022 : expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1181 : }
1182 107001822 : else if (!type_dependent_expression_p (expr))
1183 23294219 : convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1184 :
1185 168430841 : if (check_for_bare_parameter_packs (expr))
1186 24 : expr = error_mark_node;
1187 :
1188 : /* Simplification of inner statement expressions, compound exprs,
1189 : etc can result in us already having an EXPR_STMT or other statement
1190 : tree. Don't wrap them in EXPR_STMT. */
1191 168430841 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
1192 : {
1193 168430662 : if (TREE_CODE (expr) != EXPR_STMT
1194 165905258 : && !STATEMENT_CLASS_P (expr)
1195 165901107 : && TREE_CODE (expr) != STATEMENT_LIST)
1196 165745329 : expr = build_stmt (loc, EXPR_STMT, expr);
1197 168430662 : expr = maybe_cleanup_point_expr_void (expr);
1198 : }
1199 :
1200 168430841 : r = add_stmt (expr);
1201 : }
1202 :
1203 168431002 : return r;
1204 : }
1205 :
1206 :
1207 : /* Begin an if-statement. Returns a newly created IF_STMT if
1208 : appropriate. */
1209 :
1210 : tree
1211 76563884 : begin_if_stmt (void)
1212 : {
1213 76563884 : tree r, scope;
1214 76563884 : scope = do_pushlevel (sk_cond);
1215 76563884 : r = build_stmt (input_location, IF_STMT, NULL_TREE,
1216 : NULL_TREE, NULL_TREE, scope);
1217 76563884 : current_binding_level->this_entity = r;
1218 76563884 : begin_cond (&IF_COND (r));
1219 76563884 : return r;
1220 : }
1221 :
1222 : /* Returns true if FN, a CALL_EXPR, is a call to
1223 : std::is_constant_evaluated or __builtin_is_constant_evaluated. */
1224 :
1225 : static bool
1226 253585 : is_std_constant_evaluated_p (tree fn)
1227 : {
1228 : /* std::is_constant_evaluated takes no arguments. */
1229 253585 : if (call_expr_nargs (fn) != 0)
1230 : return false;
1231 :
1232 90281 : tree fndecl = cp_get_callee_fndecl_nofold (fn);
1233 90281 : if (fndecl == NULL_TREE)
1234 : return false;
1235 :
1236 28346 : if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
1237 : BUILT_IN_FRONTEND))
1238 : return true;
1239 :
1240 28317 : if (!decl_in_std_namespace_p (fndecl))
1241 : return false;
1242 :
1243 12978 : tree name = DECL_NAME (fndecl);
1244 12978 : return name && id_equal (name, "is_constant_evaluated");
1245 : }
1246 :
1247 : /* Callback function for maybe_warn_for_constant_evaluated that looks
1248 : for calls to std::is_constant_evaluated in TP. */
1249 :
1250 : static tree
1251 4701759 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
1252 : {
1253 4701759 : tree t = *tp;
1254 :
1255 4701759 : if (TYPE_P (t) || TREE_CONSTANT (t))
1256 : {
1257 833980 : *walk_subtrees = false;
1258 833980 : return NULL_TREE;
1259 : }
1260 :
1261 3867779 : switch (TREE_CODE (t))
1262 : {
1263 253585 : case CALL_EXPR:
1264 253585 : if (is_std_constant_evaluated_p (t))
1265 2390 : return t;
1266 : break;
1267 6 : case EXPR_STMT:
1268 : /* Don't warn in statement expressions. */
1269 6 : *walk_subtrees = false;
1270 6 : return NULL_TREE;
1271 : default:
1272 : break;
1273 : }
1274 :
1275 : return NULL_TREE;
1276 : }
1277 :
1278 : /* In certain contexts, std::is_constant_evaluated() is always true (for
1279 : instance, in a consteval function or in a constexpr if), or always false
1280 : (e.g., in a non-constexpr non-consteval function) so give the user a clue. */
1281 :
1282 : static void
1283 76649645 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
1284 : bool trivial_infinite)
1285 : {
1286 76649645 : if (!warn_tautological_compare)
1287 : return;
1288 :
1289 : /* Suppress warning for std::is_constant_evaluated if the conditional
1290 : comes from a macro. */
1291 1435716 : if (from_macro_expansion_at (EXPR_LOCATION (cond)))
1292 : return;
1293 :
1294 606321 : cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
1295 : NULL);
1296 606321 : if (cond)
1297 : {
1298 2390 : if (constexpr_if)
1299 34 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1300 : "%<std::is_constant_evaluated%> always evaluates to "
1301 : "true in %<if constexpr%>");
1302 2356 : else if (trivial_infinite)
1303 : {
1304 8 : auto_diagnostic_group d;
1305 8 : if (warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1306 : "%<std::is_constant_evaluated%> evaluates to "
1307 : "true when checking if trivially empty iteration "
1308 : "statement is trivial infinite loop")
1309 8 : && !maybe_constexpr_fn (current_function_decl))
1310 8 : inform (EXPR_LOCATION (cond),
1311 : "and evaluates to false when actually evaluating "
1312 : "the condition in non-%<constexpr%> function");
1313 8 : }
1314 2348 : else if (!maybe_constexpr_fn (current_function_decl))
1315 38 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1316 : "%<std::is_constant_evaluated%> always evaluates to "
1317 : "false in a non-%<constexpr%> function");
1318 4620 : else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1319 3 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1320 : "%<std::is_constant_evaluated%> always evaluates to "
1321 : "true in a %<consteval%> function");
1322 : }
1323 : }
1324 :
1325 : /* Process the COND of an if-statement, which may be given by
1326 : IF_STMT. */
1327 :
1328 : tree
1329 76563884 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
1330 : {
1331 76563884 : tree cond = maybe_convert_cond (orig_cond);
1332 76563884 : maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
1333 : /*trivial_infinite=*/false);
1334 76563884 : if (IF_STMT_CONSTEXPR_P (if_stmt)
1335 16161675 : && !type_dependent_expression_p (cond)
1336 11070210 : && require_constant_expression (cond)
1337 11070179 : && !instantiation_dependent_expression_p (cond)
1338 : /* Wait until instantiation time, since only then COND has been
1339 : converted to bool. */
1340 82634422 : && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
1341 : {
1342 6070538 : cond = instantiate_non_dependent_expr (cond);
1343 6070538 : cond = cxx_constant_value (cond);
1344 : }
1345 70493346 : else if (processing_template_decl)
1346 52806156 : cond = orig_cond;
1347 76563884 : finish_cond (&IF_COND (if_stmt), cond);
1348 76563884 : add_stmt (if_stmt);
1349 76563884 : THEN_CLAUSE (if_stmt) = push_stmt_list ();
1350 76563884 : return cond;
1351 : }
1352 :
1353 : /* Finish the then-clause of an if-statement, which may be given by
1354 : IF_STMT. */
1355 :
1356 : tree
1357 76556088 : finish_then_clause (tree if_stmt)
1358 : {
1359 76556088 : THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
1360 76556088 : return if_stmt;
1361 : }
1362 :
1363 : /* Begin the else-clause of an if-statement. */
1364 :
1365 : void
1366 28622136 : begin_else_clause (tree if_stmt)
1367 : {
1368 28622136 : ELSE_CLAUSE (if_stmt) = push_stmt_list ();
1369 28622136 : }
1370 :
1371 : /* Finish the else-clause of an if-statement, which may be given by
1372 : IF_STMT. */
1373 :
1374 : void
1375 28622098 : finish_else_clause (tree if_stmt)
1376 : {
1377 28622098 : ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
1378 28622098 : }
1379 :
1380 : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1381 : read. */
1382 :
1383 : static tree
1384 877928539 : maybe_mark_exp_read_r (tree *tp, int *, void *)
1385 : {
1386 877928539 : tree t = *tp;
1387 877928539 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1388 51202909 : mark_exp_read (t);
1389 877928539 : return NULL_TREE;
1390 : }
1391 :
1392 : /* Finish an if-statement. */
1393 :
1394 : void
1395 76556088 : finish_if_stmt (tree if_stmt)
1396 : {
1397 76556088 : tree scope = IF_SCOPE (if_stmt);
1398 76556088 : IF_SCOPE (if_stmt) = NULL;
1399 76556088 : if (IF_STMT_CONSTEXPR_P (if_stmt))
1400 : {
1401 : /* Prevent various -Wunused warnings. We might not instantiate
1402 : either of these branches, so we would not mark the variables
1403 : used in that branch as read. */
1404 16153879 : cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
1405 : maybe_mark_exp_read_r, NULL);
1406 16153879 : cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
1407 : maybe_mark_exp_read_r, NULL);
1408 : }
1409 76556088 : add_stmt (do_poplevel (scope));
1410 76556088 : }
1411 :
1412 : /* Determine if iteration statement with *CONDP condition and
1413 : loop BODY is trivially empty iteration statement or even
1414 : trivial infinite loop. In the latter case for -ffinite-loops
1415 : add ANNOTATE_EXPR to mark the loop as maybe validly infinite.
1416 : Also, emit -Wtautological-compare warning for std::is_constant_evaluated ()
1417 : calls in the condition when needed. */
1418 :
1419 : static void
1420 17960039 : finish_loop_cond (tree *condp, tree body)
1421 : {
1422 17960039 : if (TREE_CODE (*condp) == INTEGER_CST)
1423 : return;
1424 12900344 : bool trivially_empty = expr_first (body) == NULL_TREE;
1425 12900344 : bool trivial_infinite = false;
1426 12900344 : if (trivially_empty)
1427 : {
1428 99855 : tree c = fold_non_dependent_expr (*condp, tf_none,
1429 : /*manifestly_const_eval=*/true);
1430 99855 : trivial_infinite = c && integer_nonzerop (c);
1431 : }
1432 12900344 : if (warn_tautological_compare)
1433 : {
1434 85963 : tree cond = *condp;
1435 86330 : while (TREE_CODE (cond) == ANNOTATE_EXPR)
1436 367 : cond = TREE_OPERAND (cond, 0);
1437 85963 : if (trivial_infinite
1438 86027 : && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1439 64 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1440 : /*trivial_infinite=*/true);
1441 85899 : else if (!trivially_empty
1442 375 : || !processing_template_decl
1443 86303 : || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1444 85697 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1445 : /*trivial_infinite=*/false);
1446 : }
1447 12900344 : if (trivial_infinite && flag_finite_loops && !processing_template_decl)
1448 64 : *condp = build3 (ANNOTATE_EXPR, TREE_TYPE (*condp), *condp,
1449 : build_int_cst (integer_type_node,
1450 : annot_expr_maybe_infinite_kind),
1451 : integer_zero_node);
1452 : }
1453 :
1454 : /* Begin a while-statement. Returns a newly created WHILE_STMT if
1455 : appropriate. */
1456 :
1457 : tree
1458 4915695 : begin_while_stmt (void)
1459 : {
1460 4915695 : tree r;
1461 4915695 : r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1462 : NULL_TREE, NULL_TREE);
1463 4915695 : add_stmt (r);
1464 4915695 : WHILE_BODY (r) = do_pushlevel (sk_block);
1465 4915695 : begin_cond (&WHILE_COND (r));
1466 4915695 : return r;
1467 : }
1468 :
1469 : /* Process the COND of a while-statement, which may be given by
1470 : WHILE_STMT. */
1471 :
1472 : void
1473 4915695 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
1474 : tree unroll, bool novector)
1475 : {
1476 4915695 : cond = maybe_convert_cond (cond);
1477 4915695 : finish_cond (&WHILE_COND (while_stmt), cond);
1478 4915695 : begin_maybe_infinite_loop (cond);
1479 4915695 : if (ivdep && cond != error_mark_node)
1480 24 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1481 12 : TREE_TYPE (WHILE_COND (while_stmt)),
1482 12 : WHILE_COND (while_stmt),
1483 : build_int_cst (integer_type_node,
1484 : annot_expr_ivdep_kind),
1485 : integer_zero_node);
1486 4915695 : if (unroll && cond != error_mark_node)
1487 27958 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1488 13979 : TREE_TYPE (WHILE_COND (while_stmt)),
1489 13979 : WHILE_COND (while_stmt),
1490 : build_int_cst (integer_type_node,
1491 : annot_expr_unroll_kind),
1492 : unroll);
1493 4915695 : if (novector && cond != error_mark_node)
1494 42 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1495 21 : TREE_TYPE (WHILE_COND (while_stmt)),
1496 21 : WHILE_COND (while_stmt),
1497 : build_int_cst (integer_type_node,
1498 : annot_expr_no_vector_kind),
1499 : integer_zero_node);
1500 4915695 : adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
1501 : &WHILE_COND_PREP (while_stmt),
1502 : &WHILE_COND_CLEANUP (while_stmt));
1503 4915695 : }
1504 :
1505 : /* Finish a while-statement, which may be given by WHILE_STMT. */
1506 :
1507 : void
1508 4915695 : finish_while_stmt (tree while_stmt)
1509 : {
1510 4915695 : end_maybe_infinite_loop (boolean_true_node);
1511 4915695 : if (WHILE_COND_PREP (while_stmt))
1512 9599 : finish_loop_cond_prep (&WHILE_BODY (while_stmt),
1513 : &WHILE_COND_PREP (while_stmt),
1514 9599 : WHILE_COND_CLEANUP (while_stmt));
1515 : else
1516 4906096 : WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
1517 4915695 : finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
1518 4915695 : }
1519 :
1520 : /* Begin a do-statement. Returns a newly created DO_STMT if
1521 : appropriate. */
1522 :
1523 : tree
1524 5777564 : begin_do_stmt (void)
1525 : {
1526 5777564 : tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
1527 : NULL_TREE);
1528 5777564 : begin_maybe_infinite_loop (boolean_true_node);
1529 5777564 : add_stmt (r);
1530 5777564 : DO_BODY (r) = push_stmt_list ();
1531 5777564 : return r;
1532 : }
1533 :
1534 : /* Finish the body of a do-statement, which may be given by DO_STMT. */
1535 :
1536 : void
1537 5777564 : finish_do_body (tree do_stmt)
1538 : {
1539 5777564 : tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
1540 :
1541 5777564 : if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
1542 545064 : body = STATEMENT_LIST_TAIL (body)->stmt;
1543 :
1544 5777564 : if (IS_EMPTY_STMT (body))
1545 30 : warning (OPT_Wempty_body,
1546 : "suggest explicit braces around empty body in %<do%> statement");
1547 5777564 : }
1548 :
1549 : /* Finish a do-statement, which may be given by DO_STMT, and whose
1550 : COND is as indicated. */
1551 :
1552 : void
1553 5777564 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
1554 : bool novector)
1555 : {
1556 5777564 : cond = maybe_convert_cond (cond);
1557 5777564 : end_maybe_infinite_loop (cond);
1558 : /* Unlike other iteration statements, the condition may not contain
1559 : a declaration, so we don't call finish_cond which checks for
1560 : unexpanded parameter packs. */
1561 5777564 : if (check_for_bare_parameter_packs (cond))
1562 3 : cond = error_mark_node;
1563 5777564 : if (ivdep && cond != error_mark_node)
1564 3 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1565 : build_int_cst (integer_type_node, annot_expr_ivdep_kind),
1566 : integer_zero_node);
1567 5777564 : if (unroll && cond != error_mark_node)
1568 9 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1569 : build_int_cst (integer_type_node, annot_expr_unroll_kind),
1570 : unroll);
1571 5777564 : if (novector && cond != error_mark_node)
1572 0 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1573 : build_int_cst (integer_type_node, annot_expr_no_vector_kind),
1574 : integer_zero_node);
1575 5777564 : DO_COND (do_stmt) = cond;
1576 5777564 : tree do_body = DO_BODY (do_stmt);
1577 5777534 : if (CONVERT_EXPR_P (do_body)
1578 30 : && integer_zerop (TREE_OPERAND (do_body, 0))
1579 5777594 : && VOID_TYPE_P (TREE_TYPE (do_body)))
1580 : do_body = NULL_TREE;
1581 5777564 : finish_loop_cond (&DO_COND (do_stmt), do_body);
1582 5777564 : }
1583 :
1584 : /* Finish a return-statement. The EXPRESSION returned, if any, is as
1585 : indicated. */
1586 :
1587 : tree
1588 132364709 : finish_return_stmt (tree expr)
1589 : {
1590 132364709 : tree r;
1591 132364709 : bool no_warning;
1592 132364709 : bool dangling;
1593 :
1594 132364709 : expr = check_return_expr (expr, &no_warning, &dangling);
1595 :
1596 132364709 : if (error_operand_p (expr)
1597 132364709 : || (flag_openmp && !check_omp_return ()))
1598 : {
1599 : /* Suppress -Wreturn-type for this function. */
1600 1347 : if (warn_return_type)
1601 1341 : suppress_warning (current_function_decl, OPT_Wreturn_type);
1602 1347 : return error_mark_node;
1603 : }
1604 :
1605 132363362 : if (!processing_template_decl)
1606 : {
1607 46459598 : if (warn_sequence_point)
1608 1038605 : verify_sequence_points (expr);
1609 : }
1610 :
1611 132363362 : r = build_stmt (input_location, RETURN_EXPR, expr);
1612 132363362 : RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
1613 132363362 : if (no_warning)
1614 33 : suppress_warning (r, OPT_Wreturn_type);
1615 132363362 : r = maybe_cleanup_point_expr_void (r);
1616 132363362 : r = add_stmt (r);
1617 :
1618 132363362 : return r;
1619 : }
1620 :
1621 : /* Begin the scope of a for-statement or a range-for-statement.
1622 : Both the returned trees are to be used in a call to
1623 : begin_for_stmt or begin_range_for_stmt. */
1624 :
1625 : tree
1626 7918499 : begin_for_scope (tree *init)
1627 : {
1628 7918499 : tree scope = do_pushlevel (sk_for);
1629 :
1630 7918499 : if (processing_template_decl)
1631 6288867 : *init = push_stmt_list ();
1632 : else
1633 1629632 : *init = NULL_TREE;
1634 :
1635 7918499 : return scope;
1636 : }
1637 :
1638 : /* Begin a for-statement. Returns a new FOR_STMT.
1639 : SCOPE and INIT should be the return of begin_for_scope,
1640 : or both NULL_TREE */
1641 :
1642 : tree
1643 7639271 : begin_for_stmt (tree scope, tree init)
1644 : {
1645 7639271 : tree r;
1646 :
1647 7639271 : r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
1648 : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
1649 : NULL_TREE, NULL_TREE);
1650 :
1651 7639271 : if (scope == NULL_TREE)
1652 : {
1653 1379936 : gcc_assert (!init);
1654 1379936 : scope = begin_for_scope (&init);
1655 : }
1656 :
1657 7639271 : FOR_INIT_STMT (r) = init;
1658 7639271 : FOR_SCOPE (r) = scope;
1659 :
1660 7639271 : return r;
1661 : }
1662 :
1663 : /* Finish the init-statement of a for-statement, which may be
1664 : given by FOR_STMT. */
1665 :
1666 : void
1667 7639271 : finish_init_stmt (tree for_stmt)
1668 : {
1669 7639271 : if (processing_template_decl)
1670 6009639 : FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
1671 7639271 : add_stmt (for_stmt);
1672 7639271 : FOR_BODY (for_stmt) = do_pushlevel (sk_block);
1673 7639271 : begin_cond (&FOR_COND (for_stmt));
1674 7639271 : }
1675 :
1676 : /* Finish the COND of a for-statement, which may be given by
1677 : FOR_STMT. */
1678 :
1679 : void
1680 7639271 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
1681 : bool novector)
1682 : {
1683 7639271 : cond = maybe_convert_cond (cond);
1684 7639271 : finish_cond (&FOR_COND (for_stmt), cond);
1685 7639271 : begin_maybe_infinite_loop (cond);
1686 7639271 : if (ivdep && cond != error_mark_node)
1687 68 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1688 34 : TREE_TYPE (FOR_COND (for_stmt)),
1689 34 : FOR_COND (for_stmt),
1690 : build_int_cst (integer_type_node,
1691 : annot_expr_ivdep_kind),
1692 : integer_zero_node);
1693 7639271 : if (unroll && cond != error_mark_node)
1694 408 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1695 204 : TREE_TYPE (FOR_COND (for_stmt)),
1696 204 : FOR_COND (for_stmt),
1697 : build_int_cst (integer_type_node,
1698 : annot_expr_unroll_kind),
1699 : unroll);
1700 7639271 : if (novector && cond && cond != error_mark_node)
1701 268 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1702 134 : TREE_TYPE (FOR_COND (for_stmt)),
1703 134 : FOR_COND (for_stmt),
1704 : build_int_cst (integer_type_node,
1705 : annot_expr_no_vector_kind),
1706 : integer_zero_node);
1707 7639271 : adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
1708 : &FOR_COND_CLEANUP (for_stmt));
1709 7639271 : }
1710 :
1711 : /* Finish the increment-EXPRESSION in a for-statement, which may be
1712 : given by FOR_STMT. */
1713 :
1714 : void
1715 7626877 : finish_for_expr (tree expr, tree for_stmt)
1716 : {
1717 7626877 : if (!expr)
1718 : return;
1719 : /* If EXPR is an overloaded function, issue an error; there is no
1720 : context available to use to perform overload resolution. */
1721 7163849 : if (type_unknown_p (expr))
1722 : {
1723 6 : cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1724 6 : expr = error_mark_node;
1725 : }
1726 7163849 : if (!processing_template_decl)
1727 : {
1728 1555194 : if (warn_sequence_point)
1729 15015 : verify_sequence_points (expr);
1730 1555194 : expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1731 : tf_warning_or_error);
1732 : }
1733 5608655 : else if (!type_dependent_expression_p (expr))
1734 2016209 : convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
1735 7163849 : expr = maybe_cleanup_point_expr_void (expr);
1736 7163849 : if (check_for_bare_parameter_packs (expr))
1737 0 : expr = error_mark_node;
1738 7163849 : FOR_EXPR (for_stmt) = expr;
1739 : }
1740 :
1741 : /* During parsing of the body, range for uses "__for_{range,begin,end} "
1742 : decl names to make those unaccessible by code in the body.
1743 : Find those decls and store into RANGE_FOR_DECL array, so that they
1744 : can be changed later to ones with underscore instead of space, so that
1745 : it can be inspected in the debugger. */
1746 :
1747 : void
1748 7918612 : find_range_for_decls (tree range_for_decl[3])
1749 : {
1750 7918612 : gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 1
1751 : && CPTI_FOR_END__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 2
1752 : && CPTI_FOR_RANGE_IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 3
1753 : && CPTI_FOR_BEGIN_IDENTIFIER == CPTI_FOR_BEGIN__IDENTIFIER + 3
1754 : && CPTI_FOR_END_IDENTIFIER == CPTI_FOR_END__IDENTIFIER + 3);
1755 31674448 : for (int i = 0; i < 3; i++)
1756 : {
1757 23755836 : tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1758 23755836 : if (IDENTIFIER_BINDING (id)
1759 23755836 : && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1760 : {
1761 276985 : range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1762 276985 : gcc_assert (VAR_P (range_for_decl[i])
1763 : && DECL_ARTIFICIAL (range_for_decl[i]));
1764 : }
1765 : }
1766 7918612 : }
1767 :
1768 : /* Finish the body of a for-statement, which may be given by
1769 : FOR_STMT. The increment-EXPR for the loop must be
1770 : provided.
1771 : It can also finish RANGE_FOR_STMT. */
1772 :
1773 : void
1774 7918499 : finish_for_stmt (tree for_stmt)
1775 : {
1776 7918499 : end_maybe_infinite_loop (boolean_true_node);
1777 :
1778 7918499 : if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1779 279228 : RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1780 : else
1781 : {
1782 7639271 : if (FOR_COND_PREP (for_stmt))
1783 174 : finish_loop_cond_prep (&FOR_BODY (for_stmt),
1784 : &FOR_COND_PREP (for_stmt),
1785 174 : FOR_COND_CLEANUP (for_stmt));
1786 : else
1787 7639097 : FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1788 7639271 : if (FOR_COND (for_stmt))
1789 7266780 : finish_loop_cond (&FOR_COND (for_stmt),
1790 7266780 : FOR_EXPR (for_stmt) ? integer_one_node
1791 143937 : : FOR_BODY (for_stmt));
1792 : }
1793 :
1794 : /* Pop the scope for the body of the loop. */
1795 7918499 : tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1796 7918499 : ? &RANGE_FOR_SCOPE (for_stmt)
1797 7639271 : : &FOR_SCOPE (for_stmt));
1798 7918499 : tree scope = *scope_ptr;
1799 7918499 : *scope_ptr = NULL;
1800 :
1801 : /* During parsing of the body, range for uses "__for_{range,begin,end} "
1802 : decl names to make those unaccessible by code in the body.
1803 : Change it to ones with underscore instead of space, so that it can
1804 : be inspected in the debugger. */
1805 7918499 : tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1806 7918499 : find_range_for_decls (range_for_decl);
1807 :
1808 7918499 : add_stmt (do_poplevel (scope));
1809 :
1810 : /* If we're being called from build_vec_init, don't mess with the names of
1811 : the variables for an enclosing range-for. */
1812 7918499 : if (!stmts_are_full_exprs_p ())
1813 12394 : return;
1814 :
1815 31624420 : for (int i = 0; i < 3; i++)
1816 23718315 : if (range_for_decl[i])
1817 276869 : DECL_NAME (range_for_decl[i])
1818 276869 : = cp_global_trees[CPTI_FOR_RANGE_IDENTIFIER + i];
1819 : }
1820 :
1821 : /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1822 : SCOPE and INIT should be the return of begin_for_scope,
1823 : or both NULL_TREE .
1824 : To finish it call finish_for_stmt(). */
1825 :
1826 : tree
1827 279228 : begin_range_for_stmt (tree scope, tree init)
1828 : {
1829 279228 : begin_maybe_infinite_loop (boolean_false_node);
1830 :
1831 279228 : tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1832 : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1833 :
1834 279228 : if (scope == NULL_TREE)
1835 : {
1836 506 : gcc_assert (!init);
1837 506 : scope = begin_for_scope (&init);
1838 : }
1839 :
1840 : /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1841 279228 : RANGE_FOR_INIT_STMT (r) = init;
1842 279228 : RANGE_FOR_SCOPE (r) = scope;
1843 :
1844 279228 : return r;
1845 : }
1846 :
1847 : /* Finish the head of a range-based for statement, which may
1848 : be given by RANGE_FOR_STMT. DECL must be the declaration
1849 : and EXPR must be the loop expression. */
1850 :
1851 : void
1852 279228 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1853 : {
1854 279228 : if (processing_template_decl)
1855 558456 : RANGE_FOR_INIT_STMT (range_for_stmt)
1856 558456 : = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1857 279228 : RANGE_FOR_DECL (range_for_stmt) = decl;
1858 279228 : RANGE_FOR_EXPR (range_for_stmt) = expr;
1859 279228 : add_stmt (range_for_stmt);
1860 279228 : RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1861 279228 : }
1862 :
1863 : /* Begin the scope of an expansion-statement. */
1864 :
1865 : tree
1866 2324 : begin_template_for_scope (tree *init)
1867 : {
1868 2324 : tree scope = do_pushlevel (sk_template_for);
1869 :
1870 2324 : if (processing_template_decl)
1871 547 : *init = push_stmt_list ();
1872 : else
1873 1777 : *init = NULL_TREE;
1874 :
1875 2324 : return scope;
1876 : }
1877 :
1878 : /* Finish a break-statement. */
1879 :
1880 : tree
1881 4919447 : finish_break_stmt (void)
1882 : {
1883 : /* In switch statements break is sometimes stylistically used after
1884 : a return statement. This can lead to spurious warnings about
1885 : control reaching the end of a non-void function when it is
1886 : inlined. Note that we are calling block_may_fallthru with
1887 : language specific tree nodes; this works because
1888 : block_may_fallthru returns true when given something it does not
1889 : understand. */
1890 4919447 : if (!block_may_fallthru (cur_stmt_list))
1891 714 : return void_node;
1892 4918733 : note_break_stmt ();
1893 4918733 : return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
1894 : }
1895 :
1896 : /* Finish a continue-statement. */
1897 :
1898 : tree
1899 253473 : finish_continue_stmt (void)
1900 : {
1901 253473 : return add_stmt (build_stmt (input_location, CONTINUE_STMT, NULL_TREE));
1902 : }
1903 :
1904 : /* Begin a switch-statement. Returns a new SWITCH_STMT if
1905 : appropriate. */
1906 :
1907 : tree
1908 729390 : begin_switch_stmt (void)
1909 : {
1910 729390 : tree r, scope;
1911 :
1912 729390 : scope = do_pushlevel (sk_cond);
1913 729390 : r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1914 : scope, NULL_TREE);
1915 :
1916 729390 : begin_cond (&SWITCH_STMT_COND (r));
1917 :
1918 729390 : return r;
1919 : }
1920 :
1921 : /* Finish the cond of a switch-statement. */
1922 :
1923 : void
1924 729390 : finish_switch_cond (tree cond, tree switch_stmt)
1925 : {
1926 729390 : tree orig_type = NULL;
1927 :
1928 729390 : if (!processing_template_decl)
1929 : {
1930 : /* Convert the condition to an integer or enumeration type. */
1931 301429 : tree orig_cond = cond;
1932 : /* For structured binding used in condition, the conversion needs to be
1933 : evaluated before the individual variables are initialized in the
1934 : std::tuple_{size,element} case. cp_finish_decomp saved the
1935 : conversion result in a TARGET_EXPR, pick it up from there. */
1936 122 : if (DECL_DECOMPOSITION_P (cond)
1937 57 : && DECL_DECOMP_IS_BASE (cond)
1938 57 : && DECL_DECOMP_BASE (cond)
1939 301483 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1940 18 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1941 301429 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1942 301429 : if (cond == NULL_TREE)
1943 : {
1944 42 : error_at (cp_expr_loc_or_input_loc (orig_cond),
1945 : "switch quantity not an integer");
1946 27 : cond = error_mark_node;
1947 : }
1948 : /* We want unlowered type here to handle enum bit-fields. */
1949 301429 : orig_type = unlowered_expr_type (cond);
1950 301429 : if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1951 207485 : orig_type = TREE_TYPE (cond);
1952 301429 : if (cond != error_mark_node)
1953 : {
1954 : /* [stmt.switch]
1955 :
1956 : Integral promotions are performed. */
1957 301396 : cond = perform_integral_promotions (cond);
1958 301396 : cond = maybe_cleanup_point_expr (cond);
1959 : }
1960 : }
1961 729390 : if (check_for_bare_parameter_packs (cond))
1962 0 : cond = error_mark_node;
1963 729390 : else if (!processing_template_decl && warn_sequence_point)
1964 2853 : verify_sequence_points (cond);
1965 :
1966 729390 : finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1967 729390 : SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1968 729390 : add_stmt (switch_stmt);
1969 729390 : push_switch (switch_stmt);
1970 729390 : SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1971 729390 : }
1972 :
1973 : /* Finish the body of a switch-statement, which may be given by
1974 : SWITCH_STMT. The COND to switch on is indicated. */
1975 :
1976 : void
1977 729390 : finish_switch_stmt (tree switch_stmt)
1978 : {
1979 729390 : tree scope;
1980 :
1981 1458780 : SWITCH_STMT_BODY (switch_stmt) =
1982 729390 : pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1983 729390 : pop_switch ();
1984 :
1985 729390 : scope = SWITCH_STMT_SCOPE (switch_stmt);
1986 729390 : SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1987 729390 : add_stmt (do_poplevel (scope));
1988 729390 : }
1989 :
1990 : /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1991 : appropriate. */
1992 :
1993 : tree
1994 1192849 : begin_try_block (void)
1995 : {
1996 1192849 : tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1997 1192849 : add_stmt (r);
1998 1192849 : TRY_STMTS (r) = push_stmt_list ();
1999 1192849 : return r;
2000 : }
2001 :
2002 : /* Likewise, for a function-try-block. The block returned in
2003 : *COMPOUND_STMT is an artificial outer scope, containing the
2004 : function-try-block. */
2005 :
2006 : tree
2007 2212 : begin_function_try_block (tree *compound_stmt)
2008 : {
2009 2212 : tree r;
2010 : /* This outer scope does not exist in the C++ standard, but we need
2011 : a place to put __FUNCTION__ and similar variables. */
2012 2212 : *compound_stmt = begin_compound_stmt (0);
2013 2212 : current_binding_level->artificial = 1;
2014 2212 : r = begin_try_block ();
2015 2212 : FN_TRY_BLOCK_P (r) = 1;
2016 2212 : return r;
2017 : }
2018 :
2019 : /* Finish a try-block, which may be given by TRY_BLOCK. */
2020 :
2021 : void
2022 1192849 : finish_try_block (tree try_block)
2023 : {
2024 1192849 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2025 1192849 : TRY_HANDLERS (try_block) = push_stmt_list ();
2026 1192849 : }
2027 :
2028 : /* Finish the body of a cleanup try-block, which may be given by
2029 : TRY_BLOCK. */
2030 :
2031 : void
2032 0 : finish_cleanup_try_block (tree try_block)
2033 : {
2034 0 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2035 0 : }
2036 :
2037 : /* Finish an implicitly generated try-block, with a cleanup is given
2038 : by CLEANUP. */
2039 :
2040 : void
2041 0 : finish_cleanup (tree cleanup, tree try_block)
2042 : {
2043 0 : TRY_HANDLERS (try_block) = cleanup;
2044 0 : CLEANUP_P (try_block) = 1;
2045 0 : }
2046 :
2047 : /* Likewise, for a function-try-block. */
2048 :
2049 : void
2050 2212 : finish_function_try_block (tree try_block)
2051 : {
2052 2212 : finish_try_block (try_block);
2053 : /* FIXME : something queer about CTOR_INITIALIZER somehow following
2054 : the try block, but moving it inside. */
2055 2212 : in_function_try_handler = 1;
2056 2212 : }
2057 :
2058 : /* Finish a handler-sequence for a try-block, which may be given by
2059 : TRY_BLOCK. */
2060 :
2061 : void
2062 1192849 : finish_handler_sequence (tree try_block)
2063 : {
2064 1192849 : TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
2065 1192849 : check_handlers (TRY_HANDLERS (try_block));
2066 1192849 : }
2067 :
2068 : /* Finish the handler-seq for a function-try-block, given by
2069 : TRY_BLOCK. COMPOUND_STMT is the outer block created by
2070 : begin_function_try_block. */
2071 :
2072 : void
2073 2212 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
2074 : {
2075 2212 : in_function_try_handler = 0;
2076 2212 : finish_handler_sequence (try_block);
2077 2212 : finish_compound_stmt (compound_stmt);
2078 2212 : }
2079 :
2080 : /* Begin a handler. Returns a HANDLER if appropriate. */
2081 :
2082 : tree
2083 1662347 : begin_handler (void)
2084 : {
2085 1662347 : tree r;
2086 :
2087 1662347 : r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
2088 1662347 : add_stmt (r);
2089 :
2090 : /* Create a binding level for the eh_info and the exception object
2091 : cleanup. */
2092 1662347 : HANDLER_BODY (r) = do_pushlevel (sk_catch);
2093 :
2094 1662347 : return r;
2095 : }
2096 :
2097 : /* Finish the handler-parameters for a handler, which may be given by
2098 : HANDLER. DECL is the declaration for the catch parameter, or NULL
2099 : if this is a `catch (...)' clause. */
2100 :
2101 : void
2102 1662347 : finish_handler_parms (tree decl, tree handler)
2103 : {
2104 1662347 : tree type = NULL_TREE;
2105 1662347 : if (processing_template_decl)
2106 : {
2107 1516422 : if (decl)
2108 : {
2109 493125 : decl = pushdecl (decl);
2110 493125 : decl = push_template_decl (decl);
2111 493125 : HANDLER_PARMS (handler) = decl;
2112 493125 : type = TREE_TYPE (decl);
2113 : }
2114 : }
2115 : else
2116 : {
2117 145925 : type = expand_start_catch_block (decl);
2118 145925 : if (warn_catch_value
2119 2116 : && type != NULL_TREE
2120 711 : && type != error_mark_node
2121 146636 : && !TYPE_REF_P (TREE_TYPE (decl)))
2122 : {
2123 210 : tree orig_type = TREE_TYPE (decl);
2124 210 : if (CLASS_TYPE_P (orig_type))
2125 : {
2126 96 : if (TYPE_POLYMORPHIC_P (orig_type))
2127 48 : warning_at (DECL_SOURCE_LOCATION (decl),
2128 48 : OPT_Wcatch_value_,
2129 : "catching polymorphic type %q#T by value",
2130 : orig_type);
2131 48 : else if (warn_catch_value > 1)
2132 36 : warning_at (DECL_SOURCE_LOCATION (decl),
2133 36 : OPT_Wcatch_value_,
2134 : "catching type %q#T by value", orig_type);
2135 : }
2136 114 : else if (warn_catch_value > 2)
2137 54 : warning_at (DECL_SOURCE_LOCATION (decl),
2138 54 : OPT_Wcatch_value_,
2139 : "catching non-reference type %q#T", orig_type);
2140 : }
2141 : }
2142 1662347 : HANDLER_TYPE (handler) = type;
2143 1662347 : }
2144 :
2145 : /* Finish a handler, which may be given by HANDLER. The BLOCKs are
2146 : the return value from the matching call to finish_handler_parms. */
2147 :
2148 : void
2149 1662347 : finish_handler (tree handler)
2150 : {
2151 1662347 : if (!processing_template_decl)
2152 145925 : expand_end_catch_block ();
2153 1662347 : HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
2154 1662347 : }
2155 :
2156 : /* Begin a compound statement. FLAGS contains some bits that control the
2157 : behavior and context. If BCS_NO_SCOPE is set, the compound statement
2158 : does not define a scope. If BCS_FN_BODY is set, this is the outermost
2159 : block of a function. If BCS_TRY_BLOCK is set, this is the block
2160 : created on behalf of a TRY statement. Returns a token to be passed to
2161 : finish_compound_stmt. */
2162 :
2163 : tree
2164 294622330 : begin_compound_stmt (unsigned int flags)
2165 : {
2166 294622330 : tree r;
2167 :
2168 294622330 : if (flags & BCS_NO_SCOPE)
2169 : {
2170 5637050 : r = push_stmt_list ();
2171 5637050 : STATEMENT_LIST_NO_SCOPE (r) = 1;
2172 :
2173 : /* Normally, we try hard to keep the BLOCK for a statement-expression.
2174 : But, if it's a statement-expression with a scopeless block, there's
2175 : nothing to keep, and we don't want to accidentally keep a block
2176 : *inside* the scopeless block. */
2177 5637050 : keep_next_level (false);
2178 : }
2179 : else
2180 : {
2181 288985280 : scope_kind sk = sk_block;
2182 288985280 : if (flags & BCS_TRY_BLOCK)
2183 : sk = sk_try;
2184 287792622 : else if (flags & BCS_TRANSACTION)
2185 : sk = sk_transaction;
2186 287792387 : else if (flags & BCS_STMT_EXPR)
2187 29088 : sk = sk_stmt_expr;
2188 288985280 : r = do_pushlevel (sk);
2189 : }
2190 :
2191 : /* When processing a template, we need to remember where the braces were,
2192 : so that we can set up identical scopes when instantiating the template
2193 : later. BIND_EXPR is a handy candidate for this.
2194 : Note that do_poplevel won't create a BIND_EXPR itself here (and thus
2195 : result in nested BIND_EXPRs), since we don't build BLOCK nodes when
2196 : processing templates. */
2197 294622330 : if (processing_template_decl)
2198 : {
2199 197319385 : r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
2200 197319385 : BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
2201 197319385 : BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
2202 197319385 : TREE_SIDE_EFFECTS (r) = 1;
2203 : }
2204 :
2205 294622330 : return r;
2206 : }
2207 :
2208 : /* Finish a compound-statement, which is given by STMT. */
2209 :
2210 : void
2211 294622291 : finish_compound_stmt (tree stmt)
2212 : {
2213 294622291 : if (TREE_CODE (stmt) == BIND_EXPR)
2214 : {
2215 197319385 : tree body = do_poplevel (BIND_EXPR_BODY (stmt));
2216 : /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
2217 : discard the BIND_EXPR so it can be merged with the containing
2218 : STATEMENT_LIST. */
2219 197319385 : if (TREE_CODE (body) == STATEMENT_LIST
2220 179494572 : && STATEMENT_LIST_HEAD (body) == NULL
2221 11985640 : && !BIND_EXPR_BODY_BLOCK (stmt)
2222 208781196 : && !BIND_EXPR_TRY_BLOCK (stmt))
2223 : stmt = body;
2224 : else
2225 185857671 : BIND_EXPR_BODY (stmt) = body;
2226 : }
2227 97302906 : else if (STATEMENT_LIST_NO_SCOPE (stmt))
2228 5599147 : stmt = pop_stmt_list (stmt);
2229 : else
2230 : {
2231 : /* Destroy any ObjC "super" receivers that may have been
2232 : created. */
2233 91703759 : objc_clear_super_receiver ();
2234 :
2235 91703759 : stmt = do_poplevel (stmt);
2236 : }
2237 :
2238 : /* ??? See c_end_compound_stmt wrt statement expressions. */
2239 294622291 : add_stmt (stmt);
2240 294622291 : }
2241 :
2242 : /* Finish an asm string literal, which can be a string literal
2243 : or parenthesized constant expression. Extract the string literal
2244 : from the latter. */
2245 :
2246 : tree
2247 55450 : finish_asm_string_expression (location_t loc, tree string)
2248 : {
2249 55450 : if (string == error_mark_node
2250 55437 : || TREE_CODE (string) == STRING_CST
2251 883 : || processing_template_decl)
2252 : return string;
2253 576 : string = cxx_constant_value (string, tf_error);
2254 576 : if (TREE_CODE (string) == STRING_CST)
2255 10 : string = build1_loc (loc, PAREN_EXPR, TREE_TYPE (string),
2256 : string);
2257 576 : cexpr_str cstr (string);
2258 576 : if (!cstr.type_check (loc))
2259 171 : return error_mark_node;
2260 405 : if (!cstr.extract (loc, string))
2261 62 : string = error_mark_node;
2262 405 : return string;
2263 576 : }
2264 :
2265 : /* Finish an asm-statement, whose components are a STRING, some
2266 : OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
2267 : LABELS. Also note whether the asm-statement should be
2268 : considered volatile, and whether it is asm inline. TOPLEV_P
2269 : is true if finishing namespace scope extended asm. */
2270 :
2271 : tree
2272 32310 : finish_asm_stmt (location_t loc, int volatile_p, tree string,
2273 : tree output_operands, tree input_operands, tree clobbers,
2274 : tree labels, bool inline_p, bool toplev_p)
2275 : {
2276 32310 : tree r;
2277 32310 : tree t;
2278 32310 : int ninputs = list_length (input_operands);
2279 32310 : int noutputs = list_length (output_operands);
2280 :
2281 32310 : if (!processing_template_decl)
2282 : {
2283 12724 : const char *constraint;
2284 12724 : const char **oconstraints;
2285 12724 : bool allows_mem, allows_reg, is_inout;
2286 12724 : tree operand;
2287 12724 : int i;
2288 :
2289 12724 : oconstraints = XALLOCAVEC (const char *, noutputs);
2290 :
2291 25346 : string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
2292 : string);
2293 12724 : if (string == error_mark_node)
2294 109 : return error_mark_node;
2295 37890 : for (int i = 0; i < 2; ++i)
2296 61954 : for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
2297 : {
2298 36709 : tree s = TREE_VALUE (TREE_PURPOSE (t));
2299 73400 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2300 36709 : if (s == error_mark_node)
2301 : return error_mark_node;
2302 36679 : TREE_VALUE (TREE_PURPOSE (t)) = s;
2303 : }
2304 18032 : for (t = clobbers; t; t = TREE_CHAIN (t))
2305 : {
2306 5417 : tree s = TREE_VALUE (t);
2307 10828 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2308 5417 : TREE_VALUE (t) = s;
2309 : }
2310 :
2311 12615 : string = resolve_asm_operand_names (string, output_operands,
2312 : input_operands, labels);
2313 :
2314 44415 : for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
2315 : {
2316 19185 : operand = TREE_VALUE (t);
2317 :
2318 : /* ??? Really, this should not be here. Users should be using a
2319 : proper lvalue, dammit. But there's a long history of using
2320 : casts in the output operands. In cases like longlong.h, this
2321 : becomes a primitive form of typechecking -- if the cast can be
2322 : removed, then the output operand had a type of the proper width;
2323 : otherwise we'll get an error. Gross, but ... */
2324 19185 : STRIP_NOPS (operand);
2325 :
2326 19185 : operand = mark_lvalue_use (operand);
2327 :
2328 19185 : if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
2329 9 : operand = error_mark_node;
2330 :
2331 19185 : if (operand != error_mark_node
2332 19185 : && (TREE_READONLY (operand)
2333 19170 : || CP_TYPE_CONST_P (TREE_TYPE (operand))
2334 : /* Functions are not modifiable, even though they are
2335 : lvalues. */
2336 19170 : || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand))
2337 : /* If it's an aggregate and any field is const, then it is
2338 : effectively const. */
2339 19170 : || (CLASS_TYPE_P (TREE_TYPE (operand))
2340 426 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
2341 6 : cxx_readonly_error (loc, operand, lv_asm);
2342 :
2343 19185 : tree *op = &operand;
2344 19192 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2345 7 : op = &TREE_OPERAND (*op, 1);
2346 19185 : switch (TREE_CODE (*op))
2347 : {
2348 30 : case PREINCREMENT_EXPR:
2349 30 : case PREDECREMENT_EXPR:
2350 30 : case MODIFY_EXPR:
2351 30 : *op = genericize_compound_lvalue (*op);
2352 30 : op = &TREE_OPERAND (*op, 1);
2353 30 : break;
2354 : default:
2355 : break;
2356 : }
2357 :
2358 19185 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2359 19185 : oconstraints[i] = constraint;
2360 :
2361 19185 : if (parse_output_constraint (&constraint, i, ninputs, noutputs,
2362 : &allows_mem, &allows_reg, &is_inout,
2363 : nullptr))
2364 : {
2365 : /* If the operand is going to end up in memory,
2366 : mark it addressable. */
2367 19176 : if (!allows_reg && !cxx_mark_addressable (*op))
2368 0 : operand = error_mark_node;
2369 19176 : if (allows_reg && toplev_p)
2370 : {
2371 3 : error_at (loc, "constraint allows registers outside of "
2372 : "a function");
2373 3 : operand = error_mark_node;
2374 : }
2375 : }
2376 : else
2377 9 : operand = error_mark_node;
2378 :
2379 812 : if (toplev_p && operand != error_mark_node)
2380 : {
2381 21 : if (TREE_SIDE_EFFECTS (operand))
2382 : {
2383 0 : error_at (loc, "side-effects in output operand outside "
2384 : "of a function");
2385 0 : operand = error_mark_node;
2386 : }
2387 : else
2388 : {
2389 21 : tree addr
2390 21 : = cp_build_addr_expr (operand, tf_warning_or_error);
2391 21 : if (addr == error_mark_node)
2392 0 : operand = error_mark_node;
2393 : else
2394 : {
2395 21 : addr = maybe_constant_value (addr);
2396 21 : if (!initializer_constant_valid_p (addr,
2397 21 : TREE_TYPE (addr)))
2398 : {
2399 3 : error_at (loc, "output operand outside of a "
2400 : "function is not constant");
2401 3 : operand = error_mark_node;
2402 : }
2403 : else
2404 18 : operand = build_fold_indirect_ref (addr);
2405 : }
2406 : }
2407 : }
2408 19164 : else if (operand != error_mark_node && strstr (constraint, "-"))
2409 : {
2410 3 : error_at (loc, "%<-%> modifier used inside of a function");
2411 3 : operand = error_mark_node;
2412 : }
2413 :
2414 19185 : TREE_VALUE (t) = operand;
2415 : }
2416 :
2417 30104 : for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
2418 : {
2419 17489 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2420 17489 : bool constraint_parsed
2421 17489 : = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
2422 : oconstraints, &allows_mem, &allows_reg,
2423 : nullptr);
2424 : /* If the operand is going to end up in memory, don't call
2425 : decay_conversion. */
2426 17489 : if (constraint_parsed && !allows_reg && allows_mem)
2427 669 : operand = mark_lvalue_use (TREE_VALUE (t));
2428 : else
2429 16820 : operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error);
2430 :
2431 : /* If the type of the operand hasn't been determined (e.g.,
2432 : because it involves an overloaded function), then issue
2433 : an error message. There's no context available to
2434 : resolve the overloading. */
2435 17489 : if (TREE_TYPE (operand) == unknown_type_node)
2436 : {
2437 3 : error_at (loc,
2438 : "type of %<asm%> operand %qE could not be determined",
2439 3 : TREE_VALUE (t));
2440 3 : operand = error_mark_node;
2441 : }
2442 :
2443 17489 : if (constraint_parsed)
2444 : {
2445 : /* If the operand is going to end up in memory,
2446 : mark it addressable. */
2447 17468 : if (!allows_reg && allows_mem)
2448 : {
2449 : /* Strip the nops as we allow this case. FIXME, this really
2450 : should be rejected or made deprecated. */
2451 669 : STRIP_NOPS (operand);
2452 :
2453 669 : tree *op = &operand;
2454 676 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2455 7 : op = &TREE_OPERAND (*op, 1);
2456 669 : switch (TREE_CODE (*op))
2457 : {
2458 27 : case PREINCREMENT_EXPR:
2459 27 : case PREDECREMENT_EXPR:
2460 27 : case MODIFY_EXPR:
2461 27 : *op = genericize_compound_lvalue (*op);
2462 27 : op = &TREE_OPERAND (*op, 1);
2463 27 : break;
2464 : default:
2465 : break;
2466 : }
2467 :
2468 669 : if (!cxx_mark_addressable (*op))
2469 0 : operand = error_mark_node;
2470 : }
2471 16799 : else if (!allows_reg && !allows_mem)
2472 : {
2473 : /* If constraint allows neither register nor memory,
2474 : try harder to get a constant. */
2475 465 : tree constop = maybe_constant_value (operand);
2476 465 : if (TREE_CONSTANT (constop))
2477 438 : operand = constop;
2478 : }
2479 17468 : if (allows_reg && toplev_p)
2480 : {
2481 3 : error_at (loc, "constraint allows registers outside of "
2482 : "a function");
2483 3 : operand = error_mark_node;
2484 : }
2485 17468 : if (constraint[0] == ':' && operand != error_mark_node)
2486 : {
2487 48 : tree t = operand;
2488 48 : STRIP_NOPS (t);
2489 48 : if (TREE_CODE (t) != ADDR_EXPR
2490 48 : || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
2491 30 : || (VAR_P (TREE_OPERAND (t, 0))
2492 24 : && is_global_var (TREE_OPERAND (t, 0)))))
2493 : {
2494 15 : error_at (loc, "%<:%> constraint operand is not address "
2495 : "of a function or non-automatic variable");
2496 15 : operand = error_mark_node;
2497 : }
2498 33 : else if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
2499 12 : suppress_warning (TREE_OPERAND (t, 0), OPT_Wunused);
2500 : }
2501 : }
2502 : else
2503 21 : operand = error_mark_node;
2504 :
2505 17489 : if (toplev_p && operand != error_mark_node)
2506 : {
2507 117 : if (TREE_SIDE_EFFECTS (operand))
2508 : {
2509 6 : error_at (loc, "side-effects in input operand outside "
2510 : "of a function");
2511 6 : operand = error_mark_node;
2512 : }
2513 111 : else if (allows_mem && lvalue_or_else (operand, lv_asm, tf_none))
2514 : {
2515 21 : tree addr = cp_build_addr_expr (operand, tf_warning_or_error);
2516 21 : if (addr == error_mark_node)
2517 0 : operand = error_mark_node;
2518 : else
2519 : {
2520 21 : addr = maybe_constant_value (addr);
2521 21 : if (!initializer_constant_valid_p (addr,
2522 21 : TREE_TYPE (addr)))
2523 : {
2524 3 : error_at (loc, "input operand outside of a "
2525 : "function is not constant");
2526 3 : operand = error_mark_node;
2527 : }
2528 : else
2529 18 : operand = build_fold_indirect_ref (addr);
2530 : }
2531 : }
2532 : else
2533 : {
2534 90 : operand = maybe_constant_value (operand);
2535 90 : if (!initializer_constant_valid_p (operand,
2536 90 : TREE_TYPE (operand)))
2537 : {
2538 3 : error_at (loc, "input operand outside of a "
2539 : "function is not constant");
2540 3 : operand = error_mark_node;
2541 : }
2542 : }
2543 : }
2544 17372 : else if (operand != error_mark_node && strstr (constraint, "-"))
2545 : {
2546 9 : error_at (loc, "%<-%> modifier used inside of a function");
2547 9 : operand = error_mark_node;
2548 : }
2549 :
2550 17489 : TREE_VALUE (t) = operand;
2551 : }
2552 : }
2553 :
2554 32201 : r = build_stmt (loc, ASM_EXPR, string,
2555 : output_operands, input_operands,
2556 : clobbers, labels);
2557 32201 : ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
2558 32201 : ASM_INLINE_P (r) = inline_p;
2559 32201 : if (toplev_p)
2560 : {
2561 99 : symtab->finalize_toplevel_asm (r);
2562 99 : return r;
2563 : }
2564 32102 : r = maybe_cleanup_point_expr_void (r);
2565 32102 : return add_stmt (r);
2566 : }
2567 :
2568 : /* Finish a label with the indicated NAME. Returns the new label. */
2569 :
2570 : tree
2571 2539 : finish_label_stmt (tree name)
2572 : {
2573 2539 : tree decl = define_label (input_location, name);
2574 :
2575 2539 : if (decl == error_mark_node)
2576 : return error_mark_node;
2577 :
2578 2533 : add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
2579 :
2580 2533 : return decl;
2581 : }
2582 :
2583 : /* Finish a series of declarations for local labels. G++ allows users
2584 : to declare "local" labels, i.e., labels with scope. This extension
2585 : is useful when writing code involving statement-expressions. */
2586 :
2587 : void
2588 219 : finish_label_decl (tree name)
2589 : {
2590 219 : if (!at_function_scope_p ())
2591 : {
2592 0 : error ("%<__label__%> declarations are only allowed in function scopes");
2593 0 : return;
2594 : }
2595 :
2596 219 : add_decl_expr (declare_local_label (name));
2597 : }
2598 :
2599 : /* When DECL goes out of scope, make sure that CLEANUP is executed. */
2600 :
2601 : void
2602 3623290 : finish_decl_cleanup (tree decl, tree cleanup)
2603 : {
2604 3623290 : push_cleanup (decl, cleanup, false);
2605 3623290 : }
2606 :
2607 : /* If the current scope exits with an exception, run CLEANUP. */
2608 :
2609 : void
2610 2281349 : finish_eh_cleanup (tree cleanup)
2611 : {
2612 2281349 : push_cleanup (NULL, cleanup, true);
2613 2281349 : }
2614 :
2615 : /* The MEM_INITS is a list of mem-initializers, in reverse of the
2616 : order they were written by the user. Each node is as for
2617 : emit_mem_initializers. */
2618 :
2619 : void
2620 20996590 : finish_mem_initializers (tree mem_inits)
2621 : {
2622 : /* Reorder the MEM_INITS so that they are in the order they appeared
2623 : in the source program. */
2624 20996590 : mem_inits = nreverse (mem_inits);
2625 :
2626 20996590 : if (processing_template_decl)
2627 : {
2628 : tree mem;
2629 :
2630 35490154 : for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
2631 : {
2632 : /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
2633 : check for bare parameter packs in the TREE_VALUE, because
2634 : any parameter packs in the TREE_VALUE have already been
2635 : bound as part of the TREE_PURPOSE. See
2636 : make_pack_expansion for more information. */
2637 20995333 : if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
2638 20995333 : && check_for_bare_parameter_packs (TREE_VALUE (mem)))
2639 3 : TREE_VALUE (mem) = error_mark_node;
2640 : }
2641 :
2642 14494821 : add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
2643 : CTOR_INITIALIZER, mem_inits));
2644 : }
2645 : else
2646 6501769 : emit_mem_initializers (mem_inits);
2647 20996590 : }
2648 :
2649 : /* Obfuscate EXPR if it looks like an id-expression or member access so
2650 : that the call to finish_decltype in do_auto_deduction will give the
2651 : right result. If EVEN_UNEVAL, do this even in unevaluated context. */
2652 :
2653 : tree
2654 46342166 : force_paren_expr (tree expr, bool even_uneval /* = false */)
2655 : {
2656 : /* This is only needed for decltype(auto) in C++14. */
2657 46342166 : if (cxx_dialect < cxx14)
2658 : return expr;
2659 :
2660 : /* If we're in unevaluated context, we can't be deducing a
2661 : return/initializer type, so we don't need to mess with this. */
2662 45695564 : if (cp_unevaluated_operand && !even_uneval)
2663 : return expr;
2664 :
2665 37981669 : if (TREE_CODE (expr) == COMPONENT_REF
2666 37923392 : || TREE_CODE (expr) == SCOPE_REF
2667 75898305 : || REFERENCE_REF_P (expr))
2668 609724 : REF_PARENTHESIZED_P (expr) = true;
2669 37371945 : else if (DECL_P (tree_strip_any_location_wrapper (expr)))
2670 : {
2671 1793800 : location_t loc = cp_expr_location (expr);
2672 1793800 : const tree_code code = processing_template_decl ? PAREN_EXPR
2673 : : VIEW_CONVERT_EXPR;
2674 1793800 : expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
2675 1793800 : REF_PARENTHESIZED_P (expr) = true;
2676 : }
2677 : return expr;
2678 : }
2679 :
2680 : /* If T is an id-expression obfuscated by force_paren_expr, undo the
2681 : obfuscation and return the underlying id-expression. Otherwise
2682 : return T. */
2683 :
2684 : tree
2685 1023488481 : maybe_undo_parenthesized_ref (tree t)
2686 : {
2687 1023488481 : if (cxx_dialect < cxx14)
2688 : return t;
2689 :
2690 1013296525 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
2691 1123492674 : && REF_PARENTHESIZED_P (t))
2692 205563 : t = TREE_OPERAND (t, 0);
2693 :
2694 : return t;
2695 : }
2696 :
2697 : /* Finish a parenthesized expression EXPR. */
2698 :
2699 : cp_expr
2700 34536792 : finish_parenthesized_expr (cp_expr expr)
2701 : {
2702 34536792 : if (EXPR_P (expr))
2703 : {
2704 : /* This inhibits warnings in maybe_warn_unparenthesized_assignment
2705 : and c_common_truthvalue_conversion. */
2706 68660970 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
2707 : /* And maybe_warn_sizeof_array_div. */
2708 68660970 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
2709 : }
2710 :
2711 34536792 : if (TREE_CODE (expr) == OFFSET_REF
2712 34536792 : || TREE_CODE (expr) == SCOPE_REF)
2713 : /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
2714 : enclosed in parentheses. */
2715 31678 : PTRMEM_OK_P (expr) = 0;
2716 :
2717 34536792 : tree stripped_expr = tree_strip_any_location_wrapper (expr);
2718 34536792 : if (TREE_CODE (stripped_expr) == STRING_CST)
2719 888237 : PAREN_STRING_LITERAL_P (stripped_expr) = 1;
2720 33648555 : else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
2721 1464 : PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
2722 :
2723 34536792 : expr = cp_expr (force_paren_expr (expr), expr.get_location ());
2724 :
2725 34536792 : return expr;
2726 : }
2727 :
2728 : /* Finish a reference to a non-static data member (DECL) that is not
2729 : preceded by `.' or `->'. */
2730 :
2731 : tree
2732 79466279 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
2733 : tsubst_flags_t complain /* = tf_warning_or_error */)
2734 : {
2735 79466279 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
2736 79466279 : bool try_omp_private = !object && omp_private_member_map;
2737 69024526 : tree ret;
2738 :
2739 69024526 : if (!object)
2740 : {
2741 69024526 : tree scope = qualifying_scope;
2742 69024526 : if (scope == NULL_TREE)
2743 : {
2744 69012927 : scope = context_for_name_lookup (decl);
2745 69012927 : if (!TYPE_P (scope))
2746 : {
2747 : /* Can happen during error recovery (c++/85014). */
2748 3 : gcc_assert (seen_error ());
2749 3 : return error_mark_node;
2750 : }
2751 : }
2752 69024523 : object = maybe_dummy_object (scope, NULL);
2753 : }
2754 :
2755 79466276 : object = maybe_resolve_dummy (object, true);
2756 79466276 : if (object == error_mark_node)
2757 : return error_mark_node;
2758 :
2759 : /* DR 613/850: Can use non-static data members without an associated
2760 : object in sizeof/decltype/alignof. */
2761 79466273 : if (is_dummy_object (object)
2762 36101 : && !cp_unevaluated_operand
2763 79466379 : && (!processing_template_decl || !current_class_ref))
2764 : {
2765 91 : if (complain & tf_error)
2766 : {
2767 74 : auto_diagnostic_group d;
2768 74 : if (current_function_decl
2769 74 : && DECL_STATIC_FUNCTION_P (current_function_decl))
2770 3 : error ("invalid use of member %qD in static member function", decl);
2771 71 : else if (current_function_decl
2772 63 : && processing_contract_condition
2773 71 : && DECL_CONSTRUCTOR_P (current_function_decl))
2774 0 : error ("invalid use of member %qD in constructor %<pre%> contract", decl);
2775 71 : else if (current_function_decl
2776 63 : && processing_contract_condition
2777 71 : && DECL_DESTRUCTOR_P (current_function_decl))
2778 0 : error ("invalid use of member %qD in destructor %<post%> contract", decl);
2779 : else
2780 71 : error ("invalid use of non-static data member %qD", decl);
2781 74 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
2782 74 : }
2783 :
2784 91 : return error_mark_node;
2785 : }
2786 :
2787 79466182 : if (current_class_ptr)
2788 79135193 : TREE_USED (current_class_ptr) = 1;
2789 79466182 : if (processing_template_decl)
2790 : {
2791 63172166 : tree type = TREE_TYPE (decl);
2792 :
2793 63172166 : if (TYPE_REF_P (type))
2794 : /* Quals on the object don't matter. */;
2795 60801572 : else if (PACK_EXPANSION_P (type))
2796 : /* Don't bother trying to represent this. */
2797 : type = NULL_TREE;
2798 60798564 : else if (!TREE_TYPE (object) || WILDCARD_TYPE_P (TREE_TYPE (object)))
2799 : /* We don't know what the eventual quals will be, so punt until
2800 : instantiation time.
2801 :
2802 : This can happen when called from build_capture_proxy for an explicit
2803 : object lambda. It's a bit marginal to call this function in that
2804 : case, since this function is for references to members of 'this',
2805 : but the deduced type is required to be derived from the closure
2806 : type, so it works. */
2807 : type = NULL_TREE;
2808 : else
2809 : {
2810 : /* Set the cv qualifiers. */
2811 60794046 : int quals = cp_type_quals (TREE_TYPE (object));
2812 :
2813 60794046 : if (DECL_MUTABLE_P (decl))
2814 244042 : quals &= ~TYPE_QUAL_CONST;
2815 :
2816 60794046 : quals |= cp_type_quals (TREE_TYPE (decl));
2817 60794046 : type = cp_build_qualified_type (type, quals);
2818 : }
2819 :
2820 63172166 : if (qualifying_scope)
2821 : /* Wrap this in a SCOPE_REF for now. */
2822 9528 : ret = build_qualified_name (type, qualifying_scope, decl,
2823 : /*template_p=*/false);
2824 : else
2825 63162638 : ret = (convert_from_reference
2826 63162638 : (build_min (COMPONENT_REF, type, object, decl, NULL_TREE)));
2827 : }
2828 : /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
2829 : QUALIFYING_SCOPE is also non-null. */
2830 : else
2831 : {
2832 16294016 : tree access_type = TREE_TYPE (object);
2833 :
2834 16294016 : if (!perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
2835 : decl, complain))
2836 0 : return error_mark_node;
2837 :
2838 : /* If the data member was named `C::M', convert `*this' to `C'
2839 : first. */
2840 16294016 : if (qualifying_scope)
2841 : {
2842 2024 : tree binfo = NULL_TREE;
2843 2024 : object = build_scoped_ref (object, qualifying_scope,
2844 : &binfo);
2845 : }
2846 :
2847 16294016 : ret = build_class_member_access_expr (object, decl,
2848 : /*access_path=*/NULL_TREE,
2849 : /*preserve_reference=*/false,
2850 : complain);
2851 : }
2852 79466182 : if (try_omp_private)
2853 : {
2854 1671 : tree *v = omp_private_member_map->get (decl);
2855 1671 : if (v)
2856 1243 : ret = convert_from_reference (*v);
2857 : }
2858 : return ret;
2859 : }
2860 :
2861 : /* DECL was the declaration to which a qualified-id resolved. Issue
2862 : an error message if it is not accessible. If OBJECT_TYPE is
2863 : non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2864 : type of `*x', or `x', respectively. If the DECL was named as
2865 : `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like
2866 : perform_access_checks above. */
2867 :
2868 : bool
2869 4987213470 : check_accessibility_of_qualified_id (tree decl,
2870 : tree object_type,
2871 : tree nested_name_specifier,
2872 : tsubst_flags_t complain)
2873 : {
2874 : /* If we're not checking, return immediately. */
2875 4987213470 : if (deferred_access_no_check)
2876 : return true;
2877 :
2878 : /* Determine the SCOPE of DECL. */
2879 4975959301 : tree scope = context_for_name_lookup (decl);
2880 : /* If the SCOPE is not a type, then DECL is not a member. */
2881 4975959301 : if (!TYPE_P (scope)
2882 : /* If SCOPE is dependent then we can't perform this access check now,
2883 : and since we'll perform this access check again after substitution
2884 : there's no need to explicitly defer it. */
2885 4975959301 : || dependent_type_p (scope))
2886 : return true;
2887 :
2888 476180423 : tree qualifying_type = NULL_TREE;
2889 : /* Compute the scope through which DECL is being accessed. */
2890 476180423 : if (object_type
2891 : /* OBJECT_TYPE might not be a class type; consider:
2892 :
2893 : class A { typedef int I; };
2894 : I *p;
2895 : p->A::I::~I();
2896 :
2897 : In this case, we will have "A::I" as the DECL, but "I" as the
2898 : OBJECT_TYPE. */
2899 101724 : && CLASS_TYPE_P (object_type)
2900 476282130 : && DERIVED_FROM_P (scope, object_type))
2901 : {
2902 : /* If we are processing a `->' or `.' expression, use the type of the
2903 : left-hand side. */
2904 101698 : if (tree open = currently_open_class (object_type))
2905 : qualifying_type = open;
2906 : else
2907 : qualifying_type = object_type;
2908 : }
2909 476078725 : else if (nested_name_specifier)
2910 : {
2911 : /* If the reference is to a non-static member of the
2912 : current class, treat it as if it were referenced through
2913 : `this'. */
2914 632805113 : if (DECL_NONSTATIC_MEMBER_P (decl)
2915 316454727 : && current_class_ptr)
2916 41401 : if (tree current = current_nonlambda_class_type ())
2917 : {
2918 41378 : if (dependent_type_p (current))
2919 : /* In general we can't know whether this access goes through
2920 : `this' until instantiation time. Punt now, or else we might
2921 : create a deferred access check that's not relative to `this'
2922 : when it ought to be. We'll check this access again after
2923 : substitution, e.g. from tsubst_qualified_id. */
2924 : return true;
2925 :
2926 3595 : if (DERIVED_FROM_P (scope, current))
2927 : qualifying_type = current;
2928 : }
2929 : /* Otherwise, use the type indicated by the
2930 : nested-name-specifier. */
2931 : if (!qualifying_type)
2932 : qualifying_type = nested_name_specifier;
2933 : }
2934 : else
2935 : /* Otherwise, the name must be from the current class or one of
2936 : its bases. */
2937 159676167 : qualifying_type = currently_open_derived_class (scope);
2938 :
2939 476079428 : if (qualifying_type
2940 : /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2941 : or similar in a default argument value. */
2942 476142640 : && CLASS_TYPE_P (qualifying_type))
2943 448674614 : return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2944 448674614 : decl, complain);
2945 :
2946 : return true;
2947 : }
2948 :
2949 : /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2950 : class named to the left of the "::" operator. DONE is true if this
2951 : expression is a complete postfix-expression; it is false if this
2952 : expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2953 : iff this expression is the operand of '&'. TEMPLATE_P is true iff
2954 : the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2955 : is true iff this qualified name appears as a template argument. */
2956 :
2957 : tree
2958 85377829 : finish_qualified_id_expr (tree qualifying_class,
2959 : tree expr,
2960 : bool done,
2961 : bool address_p,
2962 : bool template_p,
2963 : bool template_arg_p,
2964 : tsubst_flags_t complain)
2965 : {
2966 85377829 : gcc_assert (TYPE_P (qualifying_class));
2967 :
2968 85377829 : if (error_operand_p (expr))
2969 21 : return error_mark_node;
2970 :
2971 85377808 : if (DECL_P (expr)
2972 : /* Functions are marked after overload resolution; avoid redundant
2973 : warnings. */
2974 78078968 : && TREE_CODE (expr) != FUNCTION_DECL
2975 163456752 : && !mark_used (expr, complain))
2976 0 : return error_mark_node;
2977 :
2978 85377808 : if (template_p)
2979 : {
2980 270510 : if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE)
2981 : {
2982 : /* cp_parser_lookup_name thought we were looking for a type,
2983 : but we're actually looking for a declaration. */
2984 9 : qualifying_class = TYPE_CONTEXT (expr);
2985 9 : expr = TYPE_IDENTIFIER (expr);
2986 : }
2987 : else
2988 270501 : check_template_keyword (expr);
2989 : }
2990 :
2991 : /* If EXPR occurs as the operand of '&', use special handling that
2992 : permits a pointer-to-member. */
2993 85377808 : if (address_p && done
2994 163741 : && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
2995 : {
2996 163739 : if (TREE_CODE (expr) == SCOPE_REF)
2997 0 : expr = TREE_OPERAND (expr, 1);
2998 163739 : expr = build_offset_ref (qualifying_class, expr,
2999 : /*address_p=*/true, complain);
3000 163739 : return expr;
3001 : }
3002 :
3003 : /* No need to check access within an enum. */
3004 85214069 : if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
3005 3622476 : && TREE_CODE (expr) != IDENTIFIER_NODE)
3006 : return expr;
3007 :
3008 : /* Within the scope of a class, turn references to non-static
3009 : members into expression of the form "this->...". */
3010 81591596 : if (template_arg_p)
3011 : /* But, within a template argument, we do not want make the
3012 : transformation, as there is no "this" pointer. */
3013 : ;
3014 81588932 : else if (TREE_CODE (expr) == FIELD_DECL)
3015 : {
3016 11599 : push_deferring_access_checks (dk_no_check);
3017 11599 : expr = finish_non_static_data_member (expr, NULL_TREE,
3018 : qualifying_class, complain);
3019 11599 : pop_deferring_access_checks ();
3020 : }
3021 81577333 : else if (BASELINK_P (expr))
3022 : {
3023 : /* See if any of the functions are non-static members. */
3024 : /* If so, the expression may be relative to 'this'. */
3025 6810626 : if (!shared_member_p (expr)
3026 452372 : && current_class_ptr
3027 7262311 : && DERIVED_FROM_P (qualifying_class,
3028 : current_nonlambda_class_type ()))
3029 451371 : expr = (build_class_member_access_expr
3030 451371 : (maybe_dummy_object (qualifying_class, NULL),
3031 : expr,
3032 451371 : BASELINK_ACCESS_BINFO (expr),
3033 : /*preserve_reference=*/false,
3034 : complain));
3035 6359255 : else if (done)
3036 : /* The expression is a qualified name whose address is not
3037 : being taken. */
3038 3567 : expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
3039 : complain);
3040 : }
3041 74766707 : else if (!template_p
3042 74553310 : && TREE_CODE (expr) == TEMPLATE_DECL
3043 74766790 : && !DECL_FUNCTION_TEMPLATE_P (expr))
3044 : {
3045 83 : if (complain & tf_error)
3046 5 : error ("%qE missing template arguments", expr);
3047 83 : return error_mark_node;
3048 : }
3049 : else
3050 : {
3051 : /* In a template, return a SCOPE_REF for most qualified-ids
3052 : so that we can check access at instantiation time. But if
3053 : we're looking at a member of the current instantiation, we
3054 : know we have access and building up the SCOPE_REF confuses
3055 : non-type template argument handling. */
3056 74766624 : if (processing_template_decl
3057 74766624 : && (!currently_open_class (qualifying_class)
3058 10643 : || TREE_CODE (expr) == IDENTIFIER_NODE
3059 10643 : || TREE_CODE (expr) == TEMPLATE_ID_EXPR
3060 82 : || TREE_CODE (expr) == BIT_NOT_EXPR))
3061 11132963 : expr = build_qualified_name (TREE_TYPE (expr),
3062 : qualifying_class, expr,
3063 : template_p);
3064 63633661 : else if (tree wrap = maybe_get_tls_wrapper_call (expr))
3065 9 : expr = wrap;
3066 :
3067 74766624 : expr = convert_from_reference (expr);
3068 : }
3069 :
3070 : return expr;
3071 : }
3072 :
3073 : /* Begin a statement-expression. The value returned must be passed to
3074 : finish_stmt_expr. */
3075 :
3076 : tree
3077 5658484 : begin_stmt_expr (void)
3078 : {
3079 5658484 : return push_stmt_list ();
3080 : }
3081 :
3082 : /* Process the final expression of a statement expression. EXPR can be
3083 : NULL, if the final expression is empty. Return a STATEMENT_LIST
3084 : containing all the statements in the statement-expression, or
3085 : ERROR_MARK_NODE if there was an error. */
3086 :
3087 : tree
3088 29004 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
3089 : {
3090 29004 : if (error_operand_p (expr))
3091 : {
3092 : /* The type of the statement-expression is the type of the last
3093 : expression. */
3094 3 : TREE_TYPE (stmt_expr) = error_mark_node;
3095 3 : return error_mark_node;
3096 : }
3097 :
3098 : /* If the last statement does not have "void" type, then the value
3099 : of the last statement is the value of the entire expression. */
3100 29001 : if (expr)
3101 : {
3102 28986 : tree type = TREE_TYPE (expr);
3103 :
3104 28986 : if (type && type_unknown_p (type))
3105 : {
3106 15 : error ("a statement expression is an insufficient context"
3107 : " for overload resolution");
3108 15 : TREE_TYPE (stmt_expr) = error_mark_node;
3109 15 : return error_mark_node;
3110 : }
3111 28971 : else if (processing_template_decl)
3112 : {
3113 : /* Not finish_expr_stmt because we don't want convert_to_void. */
3114 169 : expr = build_stmt (input_location, EXPR_STMT, expr);
3115 169 : expr = add_stmt (expr);
3116 : /* Mark the last statement so that we can recognize it as such at
3117 : template-instantiation time. */
3118 169 : EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
3119 : }
3120 28802 : else if (VOID_TYPE_P (type))
3121 : {
3122 : /* Just treat this like an ordinary statement. */
3123 31 : expr = finish_expr_stmt (expr);
3124 : }
3125 : else
3126 : {
3127 : /* It actually has a value we need to deal with. First, force it
3128 : to be an rvalue so that we won't need to build up a copy
3129 : constructor call later when we try to assign it to something. */
3130 28771 : expr = force_rvalue (expr, tf_warning_or_error);
3131 28771 : if (error_operand_p (expr))
3132 0 : return error_mark_node;
3133 :
3134 : /* Update for array-to-pointer decay. */
3135 28771 : type = TREE_TYPE (expr);
3136 :
3137 : /* This TARGET_EXPR will initialize the outer one added by
3138 : finish_stmt_expr. */
3139 28771 : set_target_expr_eliding (expr);
3140 :
3141 : /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
3142 : normal statement, but don't convert to void or actually add
3143 : the EXPR_STMT. */
3144 28771 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
3145 28771 : expr = maybe_cleanup_point_expr (expr);
3146 28771 : add_stmt (expr);
3147 : }
3148 :
3149 : /* The type of the statement-expression is the type of the last
3150 : expression. */
3151 28971 : TREE_TYPE (stmt_expr) = type;
3152 : }
3153 :
3154 : return stmt_expr;
3155 : }
3156 :
3157 : /* Finish a statement-expression. EXPR should be the value returned
3158 : by the previous begin_stmt_expr. Returns an expression
3159 : representing the statement-expression. */
3160 :
3161 : tree
3162 5658484 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
3163 : {
3164 5658484 : tree type;
3165 5658484 : tree result;
3166 :
3167 5658484 : if (error_operand_p (stmt_expr))
3168 : {
3169 18 : pop_stmt_list (stmt_expr);
3170 18 : return error_mark_node;
3171 : }
3172 :
3173 5658466 : gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
3174 :
3175 5658466 : type = TREE_TYPE (stmt_expr);
3176 5658466 : result = pop_stmt_list (stmt_expr);
3177 5658466 : TREE_TYPE (result) = type;
3178 :
3179 5658466 : if (processing_template_decl)
3180 : {
3181 38096 : result = build_min (STMT_EXPR, type, result);
3182 38096 : TREE_SIDE_EFFECTS (result) = 1;
3183 38096 : STMT_EXPR_NO_SCOPE (result) = has_no_scope;
3184 : }
3185 5620370 : else if (CLASS_TYPE_P (type))
3186 : {
3187 : /* Wrap the statement-expression in a TARGET_EXPR so that the
3188 : temporary object created by the final expression is destroyed at
3189 : the end of the full-expression containing the
3190 : statement-expression. */
3191 118 : result = force_target_expr (type, result, tf_warning_or_error);
3192 : }
3193 :
3194 : return result;
3195 : }
3196 :
3197 : /* Returns the expression which provides the value of STMT_EXPR. */
3198 :
3199 : tree
3200 191 : stmt_expr_value_expr (tree stmt_expr)
3201 : {
3202 191 : tree t = STMT_EXPR_STMT (stmt_expr);
3203 :
3204 191 : if (TREE_CODE (t) == BIND_EXPR)
3205 191 : t = BIND_EXPR_BODY (t);
3206 :
3207 191 : if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
3208 158 : t = STATEMENT_LIST_TAIL (t)->stmt;
3209 :
3210 191 : if (TREE_CODE (t) == EXPR_STMT)
3211 173 : t = EXPR_STMT_EXPR (t);
3212 :
3213 191 : return t;
3214 : }
3215 :
3216 : /* Return TRUE iff EXPR_STMT is an empty list of
3217 : expression statements. */
3218 :
3219 : bool
3220 63605670 : empty_expr_stmt_p (tree expr_stmt)
3221 : {
3222 63605675 : tree body = NULL_TREE;
3223 :
3224 63605675 : if (expr_stmt == void_node)
3225 : return true;
3226 :
3227 63605672 : if (expr_stmt)
3228 : {
3229 63605672 : if (TREE_CODE (expr_stmt) == EXPR_STMT)
3230 5 : body = EXPR_STMT_EXPR (expr_stmt);
3231 63605667 : else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
3232 : body = expr_stmt;
3233 : }
3234 :
3235 5 : if (body)
3236 : {
3237 62665889 : if (TREE_CODE (body) == STATEMENT_LIST)
3238 62665884 : return tsi_end_p (tsi_start (body));
3239 : else
3240 : return empty_expr_stmt_p (body);
3241 : }
3242 : return false;
3243 : }
3244 :
3245 : /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
3246 : the function (or functions) to call; ARGS are the arguments to the
3247 : call. Returns the functions to be considered by overload resolution. */
3248 :
3249 : cp_expr
3250 19311133 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
3251 : tsubst_flags_t complain)
3252 : {
3253 19311133 : tree identifier = NULL_TREE;
3254 19311133 : tree functions = NULL_TREE;
3255 19311133 : tree tmpl_args = NULL_TREE;
3256 19311133 : bool template_id = false;
3257 19311133 : location_t loc = fn_expr.get_location ();
3258 19311133 : tree fn = fn_expr.get_value ();
3259 :
3260 19311133 : STRIP_ANY_LOCATION_WRAPPER (fn);
3261 :
3262 19311133 : if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
3263 : {
3264 : /* Use a separate flag to handle null args. */
3265 3703481 : template_id = true;
3266 3703481 : tmpl_args = TREE_OPERAND (fn, 1);
3267 3703481 : fn = TREE_OPERAND (fn, 0);
3268 : }
3269 :
3270 : /* Find the name of the overloaded function. */
3271 19311133 : if (identifier_p (fn))
3272 : identifier = fn;
3273 : else
3274 : {
3275 27272533 : functions = fn;
3276 19111003 : identifier = OVL_NAME (functions);
3277 : }
3278 :
3279 : /* A call to a namespace-scope function using an unqualified name.
3280 :
3281 : Do Koenig lookup -- unless any of the arguments are
3282 : type-dependent. */
3283 19311133 : if (!any_type_dependent_arguments_p (args)
3284 19311133 : && !any_dependent_template_arguments_p (tmpl_args))
3285 : {
3286 18434694 : fn = lookup_arg_dependent (identifier, functions, args);
3287 18434694 : if (!fn)
3288 : {
3289 : /* The unqualified name could not be resolved. */
3290 59387 : if (complain & tf_error)
3291 391 : fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
3292 : else
3293 : fn = identifier;
3294 : }
3295 : }
3296 :
3297 19311133 : if (fn && template_id && fn != error_mark_node)
3298 3703468 : fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
3299 :
3300 19311133 : return cp_expr (fn, loc);
3301 : }
3302 :
3303 : /* Generate an expression for `FN (ARGS)'. This may change the
3304 : contents of ARGS.
3305 :
3306 : If DISALLOW_VIRTUAL is true, the call to FN will be not generated
3307 : as a virtual call, even if FN is virtual. (This flag is set when
3308 : encountering an expression where the function name is explicitly
3309 : qualified. For example a call to `X::f' never generates a virtual
3310 : call.)
3311 :
3312 : Returns code for the call. */
3313 :
3314 : tree
3315 375174946 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
3316 : bool koenig_p, tsubst_flags_t complain)
3317 : {
3318 375174946 : tree result;
3319 375174946 : tree orig_fn;
3320 375174946 : vec<tree, va_gc> *orig_args = *args;
3321 375174946 : tsubst_flags_t orig_complain = complain;
3322 :
3323 375174946 : if (fn == error_mark_node)
3324 : return error_mark_node;
3325 :
3326 375173878 : complain &= ~tf_any_viable;
3327 375173878 : gcc_assert (!TYPE_P (fn));
3328 :
3329 : /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
3330 : it so that we can tell this is a call to a known function. */
3331 375173878 : fn = maybe_undo_parenthesized_ref (fn);
3332 :
3333 375173878 : STRIP_ANY_LOCATION_WRAPPER (fn);
3334 :
3335 375173878 : orig_fn = fn;
3336 :
3337 375173878 : if (concept_check_p (fn))
3338 : {
3339 6 : error_at (EXPR_LOC_OR_LOC (fn, input_location),
3340 : "cannot call a concept as a function");
3341 6 : return error_mark_node;
3342 : }
3343 :
3344 375173872 : if (processing_template_decl)
3345 : {
3346 : /* If FN is a local extern declaration (or set thereof) in a template,
3347 : look it up again at instantiation time. */
3348 241855042 : if (is_overloaded_fn (fn))
3349 : {
3350 148238960 : tree ifn = get_first_fn (fn);
3351 148238960 : if (TREE_CODE (ifn) == FUNCTION_DECL
3352 148238960 : && dependent_local_decl_p (ifn))
3353 41117 : orig_fn = DECL_NAME (ifn);
3354 : }
3355 :
3356 : /* If the call expression is dependent, build a CALL_EXPR node
3357 : with no type; type_dependent_expression_p recognizes
3358 : expressions with no type as being dependent. */
3359 241855042 : if (type_dependent_expression_p (fn)
3360 241855042 : || any_type_dependent_arguments_p (*args))
3361 : {
3362 219907718 : if (koenig_p
3363 10735259 : && TREE_CODE (orig_fn) == FUNCTION_DECL
3364 223274201 : && !fndecl_built_in_p (orig_fn))
3365 : /* For an ADL-enabled call where unqualified lookup found a
3366 : single non-template function, wrap it in an OVERLOAD so that
3367 : later substitution doesn't overeagerly mark the function as
3368 : used. */
3369 879344 : orig_fn = ovl_make (orig_fn, NULL_TREE);
3370 219907718 : result = build_min_nt_call_vec (orig_fn, *args);
3371 298991740 : SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
3372 219907718 : KOENIG_LOOKUP_P (result) = koenig_p;
3373 : /* Disable the std::move warnings since this call was dependent
3374 : (c++/89780, c++/107363). This also suppresses the
3375 : -Wredundant-move warning. */
3376 219907718 : suppress_warning (result, OPT_Wpessimizing_move);
3377 :
3378 219907718 : if (cfun && cp_function_chain && !cp_unevaluated_operand)
3379 : {
3380 191466626 : bool abnormal = true;
3381 191745011 : for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
3382 : {
3383 106274855 : tree fndecl = STRIP_TEMPLATE (*iter);
3384 106274855 : if (TREE_CODE (fndecl) != FUNCTION_DECL
3385 106274777 : || !TREE_THIS_VOLATILE (fndecl))
3386 : {
3387 : abnormal = false;
3388 : break;
3389 : }
3390 : }
3391 : /* FIXME: Stop warning about falling off end of non-void
3392 : function. But this is wrong. Even if we only see
3393 : no-return fns at this point, we could select a
3394 : future-defined return fn during instantiation. Or
3395 : vice-versa. */
3396 191466626 : if (abnormal)
3397 85470156 : current_function_returns_abnormally = 1;
3398 : }
3399 219907718 : if (TREE_CODE (fn) == COMPONENT_REF)
3400 101624881 : maybe_generic_this_capture (TREE_OPERAND (fn, 0),
3401 101624881 : TREE_OPERAND (fn, 1));
3402 : return result;
3403 : }
3404 21947324 : orig_args = make_tree_vector_copy (*args);
3405 : }
3406 :
3407 155266154 : if (TREE_CODE (fn) == COMPONENT_REF)
3408 : {
3409 29657875 : tree member = TREE_OPERAND (fn, 1);
3410 29657875 : if (BASELINK_P (member))
3411 : {
3412 29467857 : tree object = TREE_OPERAND (fn, 0);
3413 58522969 : return build_new_method_call (object, member,
3414 : args, NULL_TREE,
3415 : (disallow_virtual
3416 : ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
3417 : : LOOKUP_NORMAL),
3418 : /*fn_p=*/NULL,
3419 29467857 : complain);
3420 : }
3421 : }
3422 :
3423 : /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
3424 125798297 : if (TREE_CODE (fn) == ADDR_EXPR
3425 125798297 : && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
3426 9 : fn = TREE_OPERAND (fn, 0);
3427 :
3428 125798297 : if (is_overloaded_fn (fn))
3429 116927078 : fn = baselink_for_fns (fn);
3430 :
3431 125798297 : result = NULL_TREE;
3432 125798297 : if (BASELINK_P (fn))
3433 : {
3434 14331612 : tree object;
3435 :
3436 : /* A call to a member function. From [over.call.func]:
3437 :
3438 : If the keyword this is in scope and refers to the class of
3439 : that member function, or a derived class thereof, then the
3440 : function call is transformed into a qualified function call
3441 : using (*this) as the postfix-expression to the left of the
3442 : . operator.... [Otherwise] a contrived object of type T
3443 : becomes the implied object argument.
3444 :
3445 : In this situation:
3446 :
3447 : struct A { void f(); };
3448 : struct B : public A {};
3449 : struct C : public A { void g() { B::f(); }};
3450 :
3451 : "the class of that member function" refers to `A'. But 11.2
3452 : [class.access.base] says that we need to convert 'this' to B* as
3453 : part of the access, so we pass 'B' to maybe_dummy_object. */
3454 :
3455 14331612 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
3456 : {
3457 : /* A constructor call always uses a dummy object. (This constructor
3458 : call which has the form A::A () is actually invalid and we are
3459 : going to reject it later in build_new_method_call.) */
3460 39 : object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
3461 : }
3462 : else
3463 14331573 : object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
3464 : NULL);
3465 :
3466 16368114 : result = build_new_method_call (object, fn, args, NULL_TREE,
3467 : (disallow_virtual
3468 : ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
3469 : : LOOKUP_NORMAL),
3470 : /*fn_p=*/NULL,
3471 : complain);
3472 : }
3473 111466685 : else if (is_overloaded_fn (fn))
3474 : {
3475 : /* If the function is an overloaded builtin, resolve it. */
3476 102595466 : if (TREE_CODE (fn) == FUNCTION_DECL
3477 102595466 : && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
3478 19113816 : || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
3479 9667273 : result = resolve_overloaded_builtin (input_location, fn, *args,
3480 : complain & tf_error);
3481 :
3482 9667273 : if (!result)
3483 : {
3484 102248488 : tree alloc_size_attr = NULL_TREE;
3485 102248488 : if (warn_calloc_transposed_args
3486 715649 : && TREE_CODE (fn) == FUNCTION_DECL
3487 102248488 : && (alloc_size_attr
3488 432246 : = lookup_attribute ("alloc_size",
3489 432246 : TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
3490 3401 : if (TREE_VALUE (alloc_size_attr) == NULL_TREE
3491 3401 : || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
3492 : alloc_size_attr = NULL_TREE;
3493 100506818 : if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
3494 1741730 : && (complain & tf_warning)
3495 1519241 : && !vec_safe_is_empty (*args)
3496 103414708 : && !processing_template_decl)
3497 : {
3498 : location_t sizeof_arg_loc[6];
3499 : tree sizeof_arg[6];
3500 : unsigned int i;
3501 8381196 : for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
3502 : {
3503 3143151 : tree t;
3504 :
3505 3143151 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
3506 3143151 : sizeof_arg[i] = NULL_TREE;
3507 3143151 : if (i >= (*args)->length ())
3508 656536 : continue;
3509 2486615 : t = (**args)[i];
3510 2486615 : if (TREE_CODE (t) != SIZEOF_EXPR)
3511 2479958 : continue;
3512 6657 : if (SIZEOF_EXPR_TYPE_P (t))
3513 2663 : sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
3514 : else
3515 3994 : sizeof_arg[i] = TREE_OPERAND (t, 0);
3516 6657 : sizeof_arg_loc[i] = EXPR_LOCATION (t);
3517 : }
3518 1047657 : if (warn_sizeof_pointer_memaccess)
3519 : {
3520 1047597 : auto same_p = same_type_ignoring_top_level_qualifiers_p;
3521 1047597 : sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
3522 : sizeof_arg, same_p);
3523 : }
3524 1047657 : if (alloc_size_attr)
3525 60 : warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
3526 : alloc_size_attr);
3527 : }
3528 :
3529 102248488 : if ((complain & tf_warning)
3530 56486261 : && TREE_CODE (fn) == FUNCTION_DECL
3531 27033188 : && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
3532 147572 : && vec_safe_length (*args) == 3
3533 102396060 : && !any_type_dependent_arguments_p (*args))
3534 : {
3535 147572 : tree arg0 = (*orig_args)[0];
3536 147572 : tree arg1 = (*orig_args)[1];
3537 147572 : tree arg2 = (*orig_args)[2];
3538 147572 : int literal_mask = ((literal_integer_zerop (arg1) << 1)
3539 147572 : | (literal_integer_zerop (arg2) << 2));
3540 147572 : warn_for_memset (input_location, arg0, arg2, literal_mask);
3541 : }
3542 :
3543 : /* A call to a namespace-scope function. */
3544 102248488 : result = build_new_function_call (fn, args, orig_complain);
3545 : }
3546 : }
3547 8871219 : else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
3548 : {
3549 161880 : if (!vec_safe_is_empty (*args))
3550 0 : error ("arguments to destructor are not allowed");
3551 : /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
3552 : which case the postfix-expression is a possibly-parenthesized class
3553 : member access), the function call destroys the object of scalar type
3554 : denoted by the object expression of the class member access. */
3555 161880 : tree ob = TREE_OPERAND (fn, 0);
3556 161880 : if (obvalue_p (ob))
3557 161862 : result = build_trivial_dtor_call (ob, true);
3558 : else
3559 : /* No location to clobber. */
3560 18 : result = convert_to_void (ob, ICV_STATEMENT, complain);
3561 : }
3562 8709339 : else if (CLASS_TYPE_P (TREE_TYPE (fn)))
3563 : /* If the "function" is really an object of class type, it might
3564 : have an overloaded `operator ()'. */
3565 2632603 : result = build_op_call (fn, args, complain);
3566 :
3567 119361065 : if (!result)
3568 : /* A call where the function is unknown. */
3569 6076736 : result = cp_build_function_call_vec (fn, args, complain);
3570 :
3571 125784779 : if (processing_template_decl && result != error_mark_node)
3572 : {
3573 16799614 : if (INDIRECT_REF_P (result))
3574 1146635 : result = TREE_OPERAND (result, 0);
3575 :
3576 : /* Prune all but the selected function from the original overload
3577 : set so that we can avoid some duplicate work at instantiation time. */
3578 16799614 : if (TREE_CODE (result) == CALL_EXPR
3579 16789847 : && really_overloaded_fn (orig_fn))
3580 : {
3581 6191659 : tree sel_fn = CALL_EXPR_FN (result);
3582 6191659 : if (TREE_CODE (sel_fn) == COMPONENT_REF)
3583 : {
3584 : /* The non-dependent result of build_new_method_call. */
3585 262163 : sel_fn = TREE_OPERAND (sel_fn, 1);
3586 262163 : gcc_assert (BASELINK_P (sel_fn));
3587 : }
3588 5929496 : else if (TREE_CODE (sel_fn) == ADDR_EXPR)
3589 : /* Our original callee wasn't wrapped in an ADDR_EXPR,
3590 : so strip this ADDR_EXPR added by build_over_call. */
3591 5929496 : sel_fn = TREE_OPERAND (sel_fn, 0);
3592 : orig_fn = sel_fn;
3593 : }
3594 :
3595 16799614 : tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
3596 16799614 : SET_EXPR_LOCATION (r, input_location);
3597 16799614 : KOENIG_LOOKUP_P (r) = koenig_p;
3598 16799614 : TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
3599 16799614 : release_tree_vector (orig_args);
3600 16799614 : result = convert_from_reference (r);
3601 : }
3602 :
3603 : return result;
3604 : }
3605 :
3606 : /* Finish a call to a postfix increment or decrement or EXPR. (Which
3607 : is indicated by CODE, which should be POSTINCREMENT_EXPR or
3608 : POSTDECREMENT_EXPR.) */
3609 :
3610 : cp_expr
3611 2700176 : finish_increment_expr (cp_expr expr, enum tree_code code)
3612 : {
3613 : /* input_location holds the location of the trailing operator token.
3614 : Build a location of the form:
3615 : expr++
3616 : ~~~~^~
3617 : with the caret at the operator token, ranging from the start
3618 : of EXPR to the end of the operator token. */
3619 2700176 : location_t combined_loc = make_location (input_location,
3620 : expr.get_start (),
3621 : get_finish (input_location));
3622 2700176 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3623 2700176 : NULL_TREE, tf_warning_or_error);
3624 : /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3625 2700176 : result.set_location (combined_loc);
3626 2700176 : return result;
3627 : }
3628 :
3629 : /* Finish a use of `this'. Returns an expression for `this'. */
3630 :
3631 : tree
3632 36944853 : finish_this_expr (void)
3633 : {
3634 36944853 : tree result = NULL_TREE;
3635 :
3636 73889582 : if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
3637 36643518 : result = current_class_ptr;
3638 602654 : else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
3639 301259 : result = (lambda_expr_this_capture
3640 301259 : (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
3641 : else
3642 76 : gcc_checking_assert (!current_class_ptr);
3643 :
3644 36944777 : if (result)
3645 : /* The keyword 'this' is a prvalue expression. */
3646 36944774 : return rvalue (result);
3647 :
3648 79 : tree fn = current_nonlambda_function ();
3649 79 : if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
3650 : {
3651 6 : auto_diagnostic_group d;
3652 6 : error ("%<this%> is unavailable for explicit object member "
3653 : "functions");
3654 6 : tree xobj_parm = DECL_ARGUMENTS (fn);
3655 6 : gcc_assert (xobj_parm);
3656 6 : tree parm_name = DECL_NAME (xobj_parm);
3657 :
3658 6 : static tree remembered_fn = NULL_TREE;
3659 : /* Only output this diagnostic once per function. */
3660 6 : if (remembered_fn == fn)
3661 : /* Early escape. */;
3662 6 : else if (parm_name)
3663 6 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3664 : "use explicit object parameter %qs instead",
3665 3 : IDENTIFIER_POINTER (parm_name));
3666 : else
3667 3 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3668 : "name the explicit object parameter");
3669 :
3670 6 : remembered_fn = fn;
3671 6 : }
3672 73 : else if (fn && DECL_STATIC_FUNCTION_P (fn))
3673 3 : error ("%<this%> is unavailable for static member functions");
3674 70 : else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
3675 0 : error ("invalid use of %<this%> in a constructor %<pre%> condition");
3676 70 : else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
3677 0 : error ("invalid use of %<this%> in a destructor %<post%> condition");
3678 70 : else if (fn)
3679 22 : error ("invalid use of %<this%> in non-member function");
3680 : else
3681 48 : error ("invalid use of %<this%> at top level");
3682 79 : return error_mark_node;
3683 : }
3684 :
3685 : /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3686 : expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3687 : the TYPE for the type given. If SCOPE is non-NULL, the expression
3688 : was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3689 :
3690 : tree
3691 161931 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
3692 : location_t loc, tsubst_flags_t complain)
3693 : {
3694 161931 : if (object == error_mark_node || destructor == error_mark_node)
3695 : return error_mark_node;
3696 :
3697 161922 : gcc_assert (TYPE_P (destructor));
3698 :
3699 161922 : if (!processing_template_decl)
3700 : {
3701 161901 : if (scope == error_mark_node)
3702 : {
3703 0 : if (complain & tf_error)
3704 0 : error_at (loc, "invalid qualifying scope in pseudo-destructor name");
3705 0 : return error_mark_node;
3706 : }
3707 161901 : if (is_auto (destructor))
3708 3 : destructor = TREE_TYPE (object);
3709 161901 : if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
3710 : {
3711 3 : if (complain & tf_error)
3712 3 : error_at (loc,
3713 : "qualified type %qT does not match destructor name ~%qT",
3714 : scope, destructor);
3715 3 : return error_mark_node;
3716 : }
3717 :
3718 :
3719 : /* [expr.pseudo] says both:
3720 :
3721 : The type designated by the pseudo-destructor-name shall be
3722 : the same as the object type.
3723 :
3724 : and:
3725 :
3726 : The cv-unqualified versions of the object type and of the
3727 : type designated by the pseudo-destructor-name shall be the
3728 : same type.
3729 :
3730 : We implement the more generous second sentence, since that is
3731 : what most other compilers do. */
3732 161898 : if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
3733 : destructor))
3734 : {
3735 12 : if (complain & tf_error)
3736 9 : error_at (loc, "%qE is not of type %qT", object, destructor);
3737 12 : return error_mark_node;
3738 : }
3739 : }
3740 :
3741 161907 : tree type = (type_dependent_expression_p (object)
3742 161907 : ? NULL_TREE : void_type_node);
3743 :
3744 161907 : return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
3745 161907 : scope, destructor);
3746 : }
3747 :
3748 : /* Finish an expression of the form CODE EXPR. */
3749 :
3750 : cp_expr
3751 39392572 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
3752 : tsubst_flags_t complain)
3753 : {
3754 : /* Build a location of the form:
3755 : ++expr
3756 : ^~~~~~
3757 : with the caret at the operator token, ranging from the start
3758 : of the operator token to the end of EXPR. */
3759 39392572 : location_t combined_loc = make_location (op_loc,
3760 : op_loc, expr.get_finish ());
3761 39392572 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3762 39392572 : NULL_TREE, complain);
3763 : /* TODO: build_x_unary_op doesn't always honor the location. */
3764 39392572 : result.set_location (combined_loc);
3765 :
3766 39392572 : if (result == error_mark_node)
3767 : return result;
3768 :
3769 39392069 : if (!(complain & tf_warning))
3770 : return result;
3771 :
3772 : /* These will never fold into a constant, so no need to check for
3773 : overflow for them. */
3774 39392069 : if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
3775 : return result;
3776 :
3777 21261121 : tree result_ovl = result;
3778 21261121 : tree expr_ovl = expr;
3779 :
3780 21261121 : if (!processing_template_decl)
3781 1866726 : expr_ovl = cp_fully_fold (expr_ovl);
3782 :
3783 21261121 : if (!CONSTANT_CLASS_P (expr_ovl)
3784 21261121 : || TREE_OVERFLOW_P (expr_ovl))
3785 : return result;
3786 :
3787 260270 : if (!processing_template_decl)
3788 250808 : result_ovl = cp_fully_fold (result_ovl);
3789 :
3790 260270 : if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
3791 9 : overflow_warning (combined_loc, result_ovl);
3792 :
3793 : return result;
3794 : }
3795 :
3796 : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3797 : elements. */
3798 :
3799 : static bool
3800 12 : maybe_zero_constructor_nelts (tree expr)
3801 : {
3802 12 : if (CONSTRUCTOR_NELTS (expr) == 0)
3803 : return true;
3804 12 : if (!processing_template_decl)
3805 : return false;
3806 30 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
3807 21 : if (!PACK_EXPANSION_P (elt.value))
3808 : return false;
3809 : return true;
3810 : }
3811 :
3812 : /* Finish a compound-literal expression or C++11 functional cast with aggregate
3813 : initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3814 : is being cast. */
3815 :
3816 : tree
3817 10040151 : finish_compound_literal (tree type, tree compound_literal,
3818 : tsubst_flags_t complain,
3819 : fcl_t fcl_context)
3820 : {
3821 10040151 : if (type == error_mark_node)
3822 : return error_mark_node;
3823 :
3824 10040099 : if (TYPE_REF_P (type))
3825 : {
3826 12 : compound_literal
3827 12 : = finish_compound_literal (TREE_TYPE (type), compound_literal,
3828 : complain, fcl_context);
3829 : /* The prvalue is then used to direct-initialize the reference. */
3830 12 : tree r = (perform_implicit_conversion_flags
3831 12 : (type, compound_literal, complain, LOOKUP_NORMAL));
3832 12 : return convert_from_reference (r);
3833 : }
3834 :
3835 10040087 : if (!TYPE_OBJ_P (type))
3836 : {
3837 : /* DR2351 */
3838 60 : if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
3839 : {
3840 12 : if (!processing_template_decl)
3841 9 : return void_node;
3842 3 : TREE_TYPE (compound_literal) = type;
3843 3 : TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
3844 3 : CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
3845 3 : return compound_literal;
3846 : }
3847 21 : else if (VOID_TYPE_P (type)
3848 15 : && processing_template_decl
3849 33 : && maybe_zero_constructor_nelts (compound_literal))
3850 : /* If there are only packs in compound_literal, it could
3851 : be void{} after pack expansion. */;
3852 : else
3853 : {
3854 12 : if (complain & tf_error)
3855 9 : error ("compound literal of non-object type %qT", type);
3856 12 : return error_mark_node;
3857 : }
3858 : }
3859 :
3860 10040063 : if (template_placeholder_p (type))
3861 : {
3862 194423 : type = do_auto_deduction (type, compound_literal, type, complain,
3863 : adc_variable_type);
3864 194423 : if (type == error_mark_node)
3865 : return error_mark_node;
3866 : }
3867 : /* C++23 auto{x}. */
3868 9845640 : else if (is_auto (type)
3869 162 : && !AUTO_IS_DECLTYPE (type)
3870 9845799 : && CONSTRUCTOR_NELTS (compound_literal) == 1)
3871 : {
3872 150 : if (is_constrained_auto (type))
3873 : {
3874 3 : if (complain & tf_error)
3875 3 : error ("%<auto{x}%> cannot be constrained");
3876 3 : return error_mark_node;
3877 : }
3878 147 : else if (cxx_dialect < cxx23)
3879 : {
3880 1 : if ((complain & tf_warning_or_error) == 0)
3881 0 : return error_mark_node;
3882 1 : pedwarn (input_location, OPT_Wc__23_extensions,
3883 : "%<auto{x}%> only available with "
3884 : "%<-std=c++23%> or %<-std=gnu++23%>");
3885 : }
3886 147 : type = do_auto_deduction (type, compound_literal, type, complain,
3887 : adc_variable_type);
3888 147 : if (type == error_mark_node)
3889 : return error_mark_node;
3890 : }
3891 :
3892 : /* Used to hold a copy of the compound literal in a template. */
3893 10039918 : tree orig_cl = NULL_TREE;
3894 :
3895 10039918 : if (processing_template_decl)
3896 : {
3897 5247791 : const bool dependent_p
3898 5247791 : = (instantiation_dependent_expression_p (compound_literal)
3899 5247791 : || dependent_type_p (type));
3900 1740162 : if (dependent_p)
3901 : /* We're about to return, no need to copy. */
3902 : orig_cl = compound_literal;
3903 : else
3904 : /* We're going to need a copy. */
3905 1740162 : orig_cl = unshare_constructor (compound_literal);
3906 5247791 : TREE_TYPE (orig_cl) = type;
3907 : /* Mark the expression as a compound literal. */
3908 5247791 : TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
3909 : /* And as instantiation-dependent. */
3910 5247791 : CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
3911 5247791 : if (fcl_context == fcl_c99)
3912 130 : CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
3913 : /* If the compound literal is dependent, we're done for now. */
3914 5247791 : if (dependent_p)
3915 : return orig_cl;
3916 : /* Otherwise, do go on to e.g. check narrowing. */
3917 : }
3918 :
3919 6532289 : type = complete_type (type);
3920 :
3921 6532289 : if (TYPE_NON_AGGREGATE_CLASS (type))
3922 : {
3923 : /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3924 : everywhere that deals with function arguments would be a pain, so
3925 : just wrap it in a TREE_LIST. The parser set a flag so we know
3926 : that it came from T{} rather than T({}). */
3927 1086434 : CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
3928 1086434 : compound_literal = build_tree_list (NULL_TREE, compound_literal);
3929 1086434 : return build_functional_cast (input_location, type,
3930 1086434 : compound_literal, complain);
3931 : }
3932 :
3933 5445855 : if (TREE_CODE (type) == ARRAY_TYPE
3934 5445855 : && check_array_initializer (NULL_TREE, type, compound_literal))
3935 9 : return error_mark_node;
3936 5445846 : compound_literal = reshape_init (type, compound_literal, complain);
3937 5445846 : if (SCALAR_TYPE_P (type)
3938 754105 : && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
3939 218200 : && !check_narrowing (type, compound_literal, complain))
3940 131 : return error_mark_node;
3941 5445715 : if (TREE_CODE (type) == ARRAY_TYPE
3942 5445715 : && TYPE_DOMAIN (type) == NULL_TREE)
3943 : {
3944 1253 : cp_complete_array_type_or_error (&type, compound_literal,
3945 : false, complain);
3946 1253 : if (type == error_mark_node)
3947 : return error_mark_node;
3948 : }
3949 5445712 : if (abstract_virtuals_error (ACU_UNKNOWN, type, complain))
3950 7 : return error_mark_node;
3951 5445705 : compound_literal = digest_init_flags (type, compound_literal,
3952 : LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
3953 : complain);
3954 5445705 : if (compound_literal == error_mark_node)
3955 : return error_mark_node;
3956 :
3957 : /* If we're in a template, return the original compound literal. */
3958 5445041 : if (orig_cl)
3959 : return orig_cl;
3960 :
3961 3793467 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3962 : {
3963 3096145 : TREE_HAS_CONSTRUCTOR (compound_literal) = true;
3964 3096145 : if (fcl_context == fcl_c99)
3965 37961 : CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
3966 : }
3967 :
3968 : /* Put static/constant array temporaries in static variables. */
3969 : /* FIXME all C99 compound literals should be variables rather than C++
3970 : temporaries, unless they are used as an aggregate initializer. */
3971 5002263 : if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
3972 2594198 : && fcl_context == fcl_c99
3973 83 : && TREE_CODE (type) == ARRAY_TYPE
3974 31 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
3975 3793498 : && initializer_constant_valid_p (compound_literal, type))
3976 : {
3977 31 : tree decl = create_temporary_var (type);
3978 31 : DECL_CONTEXT (decl) = NULL_TREE;
3979 31 : DECL_INITIAL (decl) = compound_literal;
3980 31 : TREE_STATIC (decl) = 1;
3981 31 : if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
3982 : {
3983 : /* 5.19 says that a constant expression can include an
3984 : lvalue-rvalue conversion applied to "a glvalue of literal type
3985 : that refers to a non-volatile temporary object initialized
3986 : with a constant expression". Rather than try to communicate
3987 : that this VAR_DECL is a temporary, just mark it constexpr. */
3988 24 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
3989 24 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
3990 24 : TREE_CONSTANT (decl) = true;
3991 : }
3992 31 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
3993 31 : decl = pushdecl_top_level (decl);
3994 31 : DECL_NAME (decl) = make_anon_name ();
3995 31 : SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
3996 : /* Make sure the destructor is callable. */
3997 31 : tree clean = cxx_maybe_build_cleanup (decl, complain);
3998 31 : if (clean == error_mark_node)
3999 : return error_mark_node;
4000 31 : return decl;
4001 : }
4002 :
4003 : /* Represent other compound literals with TARGET_EXPR so we produce
4004 : a prvalue, and can elide copies. */
4005 3793436 : if (!VECTOR_TYPE_P (type)
4006 3752869 : && (TREE_CODE (compound_literal) == CONSTRUCTOR
4007 697316 : || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
4008 : {
4009 : /* The CONSTRUCTOR is now an initializer, not a compound literal. */
4010 3055553 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
4011 3055553 : TREE_HAS_CONSTRUCTOR (compound_literal) = false;
4012 3055553 : compound_literal = get_target_expr (compound_literal, complain);
4013 : }
4014 : else
4015 : /* For e.g. int{42} just make sure it's a prvalue. */
4016 737883 : compound_literal = rvalue (compound_literal);
4017 :
4018 : return compound_literal;
4019 : }
4020 :
4021 : /* Return the declaration for the function-name variable indicated by
4022 : ID. */
4023 :
4024 : tree
4025 297827 : finish_fname (tree id)
4026 : {
4027 297827 : tree decl = fname_decl (input_location, C_RID_CODE (id), id);
4028 : /* [expr.prim.lambda.closure]/16 "Unless the compound-statement is that
4029 : of a consteval-block-declaration, a variable __func__ is implicitly
4030 : defined...". We could be in a consteval block in a function, though,
4031 : and then we shouldn't warn. */
4032 297827 : if (current_function_decl
4033 297827 : && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
4034 8 : pedwarn (input_location, 0, "%qD is not defined outside of function scope",
4035 : decl);
4036 297827 : if (processing_template_decl && current_function_decl
4037 219548 : && decl != error_mark_node)
4038 219548 : decl = DECL_NAME (decl);
4039 297827 : return decl;
4040 : }
4041 :
4042 : /* Finish a translation unit. */
4043 :
4044 : void
4045 99119 : finish_translation_unit (void)
4046 : {
4047 : /* In case there were missing closebraces,
4048 : get us back to the global binding level. */
4049 99119 : pop_everything ();
4050 198238 : while (current_namespace != global_namespace)
4051 0 : pop_namespace ();
4052 :
4053 : /* Do file scope __FUNCTION__ et al. */
4054 99119 : finish_fname_decls ();
4055 :
4056 99119 : if (vec_safe_length (scope_chain->omp_declare_target_attribute))
4057 : {
4058 12 : cp_omp_declare_target_attr
4059 12 : a = scope_chain->omp_declare_target_attribute->pop ();
4060 12 : if (!errorcount)
4061 9 : error ("%qs without corresponding %qs",
4062 : a.device_type >= 0 ? "#pragma omp begin declare target"
4063 : : "#pragma omp declare target",
4064 : "#pragma omp end declare target");
4065 24 : vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
4066 : }
4067 99119 : if (vec_safe_length (scope_chain->omp_declare_variant_attribute))
4068 : {
4069 0 : if (!errorcount)
4070 0 : error ("%<omp begin declare variant%> without corresponding "
4071 : "%<omp end declare variant%>");
4072 0 : vec_safe_truncate (scope_chain->omp_declare_variant_attribute, 0);
4073 : }
4074 99119 : if (vec_safe_length (scope_chain->omp_begin_assumes))
4075 : {
4076 3 : if (!errorcount)
4077 3 : error ("%qs without corresponding %qs",
4078 : "#pragma omp begin assumes", "#pragma omp end assumes");
4079 3 : vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
4080 : }
4081 99119 : }
4082 :
4083 : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
4084 : Returns the parameter. */
4085 :
4086 : tree
4087 165161434 : finish_template_type_parm (tree aggr, tree identifier)
4088 : {
4089 165161434 : if (aggr != class_type_node)
4090 : {
4091 0 : permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
4092 0 : aggr = class_type_node;
4093 : }
4094 :
4095 165161434 : return build_tree_list (aggr, identifier);
4096 : }
4097 :
4098 : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
4099 : Returns the parameter. */
4100 :
4101 : tree
4102 420587 : finish_template_template_parm (tree aggr, tree identifier)
4103 : {
4104 420587 : tree decl = build_decl (input_location,
4105 : TYPE_DECL, identifier, NULL_TREE);
4106 :
4107 420587 : tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
4108 420587 : DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
4109 420587 : DECL_TEMPLATE_RESULT (tmpl) = decl;
4110 420587 : DECL_ARTIFICIAL (decl) = 1;
4111 :
4112 : /* Associate the constraints with the underlying declaration,
4113 : not the template. */
4114 420587 : tree constr = current_template_constraints ();
4115 420587 : set_constraints (decl, constr);
4116 :
4117 420587 : end_template_decl ();
4118 :
4119 420587 : gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
4120 :
4121 420587 : check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
4122 : /*is_primary=*/true, /*is_partial=*/false,
4123 : /*is_friend=*/0);
4124 :
4125 420587 : return finish_template_type_parm (aggr, tmpl);
4126 : }
4127 :
4128 : /* ARGUMENT is the default-argument value for a template template
4129 : parameter. If ARGUMENT is invalid, issue error messages and return
4130 : the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
4131 :
4132 : tree
4133 950 : check_template_template_default_arg (tree argument)
4134 : {
4135 950 : if (TREE_CODE (argument) != TEMPLATE_DECL
4136 : && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
4137 : && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
4138 : {
4139 : if (TREE_CODE (argument) == TYPE_DECL)
4140 : {
4141 18 : if (tree t = maybe_get_template_decl_from_type_decl (argument))
4142 18 : if (TREE_CODE (t) == TEMPLATE_DECL)
4143 : return t;
4144 15 : error ("invalid use of type %qT as a default value for a template "
4145 15 : "template-parameter", TREE_TYPE (argument));
4146 : }
4147 : else
4148 0 : error ("invalid default argument for a template template parameter");
4149 15 : return error_mark_node;
4150 : }
4151 :
4152 : return argument;
4153 : }
4154 :
4155 : /* Begin a class definition, as indicated by T. */
4156 :
4157 : tree
4158 31777798 : begin_class_definition (tree t)
4159 : {
4160 31777798 : if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
4161 33 : return error_mark_node;
4162 :
4163 31777903 : if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
4164 : {
4165 9 : error ("definition of %q#T inside template parameter list", t);
4166 9 : return error_mark_node;
4167 : }
4168 :
4169 : /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
4170 : are passed the same as decimal scalar types. */
4171 31777756 : if (TREE_CODE (t) == RECORD_TYPE
4172 31247665 : && !processing_template_decl)
4173 : {
4174 11231868 : tree ns = TYPE_CONTEXT (t);
4175 11231865 : if (ns && TREE_CODE (ns) == NAMESPACE_DECL
4176 9224260 : && DECL_CONTEXT (ns) == std_node
4177 2235183 : && DECL_NAME (ns)
4178 13467031 : && id_equal (DECL_NAME (ns), "decimal"))
4179 : {
4180 150 : const char *n = TYPE_NAME_STRING (t);
4181 150 : if ((strcmp (n, "decimal32") == 0)
4182 101 : || (strcmp (n, "decimal64") == 0)
4183 46 : || (strcmp (n, "decimal128") == 0))
4184 147 : TYPE_TRANSPARENT_AGGR (t) = 1;
4185 : }
4186 : }
4187 :
4188 : /* A non-implicit typename comes from code like:
4189 :
4190 : template <typename T> struct A {
4191 : template <typename U> struct A<T>::B ...
4192 :
4193 : This is erroneous. */
4194 20545888 : else if (TREE_CODE (t) == TYPENAME_TYPE)
4195 : {
4196 0 : error ("invalid definition of qualified type %qT", t);
4197 0 : t = error_mark_node;
4198 : }
4199 :
4200 31777756 : if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
4201 : {
4202 0 : t = make_class_type (RECORD_TYPE);
4203 0 : pushtag (make_anon_name (), t);
4204 : }
4205 :
4206 31777756 : if (TYPE_BEING_DEFINED (t))
4207 : {
4208 0 : t = make_class_type (TREE_CODE (t));
4209 0 : pushtag (TYPE_IDENTIFIER (t), t);
4210 : }
4211 :
4212 31777756 : maybe_process_partial_specialization (t);
4213 31777756 : pushclass (t);
4214 31777756 : TYPE_BEING_DEFINED (t) = 1;
4215 31777756 : class_binding_level->defining_class_p = 1;
4216 :
4217 31777756 : if (flag_pack_struct)
4218 : {
4219 99 : tree v;
4220 99 : TYPE_PACKED (t) = 1;
4221 : /* Even though the type is being defined for the first time
4222 : here, there might have been a forward declaration, so there
4223 : might be cv-qualified variants of T. */
4224 99 : for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
4225 0 : TYPE_PACKED (v) = 1;
4226 : }
4227 : /* Reset the interface data, at the earliest possible
4228 : moment, as it might have been set via a class foo;
4229 : before. */
4230 65983560 : if (! TYPE_UNNAMED_P (t))
4231 : {
4232 31015565 : struct c_fileinfo *finfo = \
4233 31015565 : get_fileinfo (LOCATION_FILE (input_location));
4234 31015565 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
4235 31015565 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X
4236 : (t, finfo->interface_unknown);
4237 : }
4238 31777756 : reset_specialization ();
4239 :
4240 : /* Make a declaration for this class in its own scope. */
4241 31777756 : build_self_reference ();
4242 :
4243 31777756 : return t;
4244 : }
4245 :
4246 : /* Finish the member declaration given by DECL. */
4247 :
4248 : void
4249 429094971 : finish_member_declaration (tree decl)
4250 : {
4251 429094971 : if (decl == error_mark_node || decl == NULL_TREE)
4252 : return;
4253 :
4254 429093922 : if (decl == void_type_node)
4255 : /* The COMPONENT was a friend, not a member, and so there's
4256 : nothing for us to do. */
4257 : return;
4258 :
4259 : /* We should see only one DECL at a time. */
4260 429093922 : gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
4261 :
4262 : /* Don't add decls after definition. */
4263 429093943 : gcc_assert (TYPE_BEING_DEFINED (current_class_type)
4264 : /* We can add lambda types when late parsing default
4265 : arguments. */
4266 : || LAMBDA_TYPE_P (TREE_TYPE (decl)));
4267 :
4268 : /* Set up access control for DECL. */
4269 429093922 : TREE_PRIVATE (decl)
4270 429093922 : = (current_access_specifier == access_private_node);
4271 429093922 : TREE_PROTECTED (decl)
4272 429093922 : = (current_access_specifier == access_protected_node);
4273 429093922 : if (TREE_CODE (decl) == TEMPLATE_DECL)
4274 : {
4275 48993292 : TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
4276 48993292 : TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
4277 : }
4278 :
4279 : /* Mark the DECL as a member of the current class, unless it's
4280 : a member of an enumeration. */
4281 429093922 : if (TREE_CODE (decl) != CONST_DECL)
4282 426674351 : DECL_CONTEXT (decl) = current_class_type;
4283 :
4284 429093922 : if (TREE_TYPE (decl)
4285 425502278 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl))
4286 429490004 : && TREE_CODE (decl) != TYPE_DECL)
4287 : {
4288 : /* Remember the single FIELD_DECL an anonymous aggregate type is used
4289 : for. */
4290 288389 : if (TREE_CODE (decl) == FIELD_DECL && DECL_NAME (decl) == NULL_TREE)
4291 : {
4292 288373 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
4293 288373 : gcc_assert (!ANON_AGGR_TYPE_FIELD (type));
4294 288373 : SET_ANON_AGGR_TYPE_FIELD (type, decl);
4295 : }
4296 : /* [class.union.anon]/1: Each object of such an unnamed type shall
4297 : be such an unnamed object. */
4298 16 : else if (ANON_UNION_TYPE_P (TREE_TYPE (decl)))
4299 : {
4300 10 : tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
4301 10 : auto_diagnostic_group d;
4302 10 : error_at (location_of (decl),
4303 : "declaration of member %qD with anonymous union type %qT",
4304 10 : decl, TREE_TYPE (decl));
4305 10 : inform (DECL_SOURCE_LOCATION (adecl),
4306 : "anonymous union declared here");
4307 10 : }
4308 : else
4309 : {
4310 6 : tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
4311 6 : auto_diagnostic_group d;
4312 6 : error_at (location_of (decl),
4313 : "declaration of member %qD with anonymous struct type %qT",
4314 6 : decl, TREE_TYPE (decl));
4315 6 : inform (DECL_SOURCE_LOCATION (adecl),
4316 : "anonymous struct declared here");
4317 6 : }
4318 : }
4319 428805533 : else if (TREE_TYPE (decl)
4320 425213889 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
4321 430398446 : && TREE_CODE (decl) != TYPE_DECL)
4322 : {
4323 1529111 : tree type = strip_array_types (TREE_TYPE (decl));
4324 1529111 : if (ANON_AGGR_TYPE_P (type))
4325 : {
4326 : /* [class.union.anon]/1: Each object of such an unnamed type shall
4327 : be such an unnamed object. */
4328 12 : tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (type));
4329 12 : auto_diagnostic_group d;
4330 12 : if (ANON_UNION_TYPE_P (type))
4331 : {
4332 8 : error_at (location_of (decl),
4333 : "declaration of member %qD with array of anonymous "
4334 8 : "union type %qT", decl, TREE_TYPE (decl));
4335 8 : inform (DECL_SOURCE_LOCATION (adecl),
4336 : "anonymous union declared here");
4337 : }
4338 : else
4339 : {
4340 4 : error_at (location_of (decl),
4341 : "declaration of member %qD with array of anonymous "
4342 4 : "struct type %qT", decl, TREE_TYPE (decl));
4343 4 : inform (DECL_SOURCE_LOCATION (adecl),
4344 : "anonymous struct declared here");
4345 : }
4346 12 : }
4347 : }
4348 :
4349 429093922 : if (TREE_CODE (decl) == USING_DECL)
4350 : /* Avoid debug info for class-scope USING_DECLS for now, we'll
4351 : call cp_emit_debug_info_for_using later. */
4352 3499135 : DECL_IGNORED_P (decl) = 1;
4353 :
4354 : /* Check for bare parameter packs in the non-static data member
4355 : declaration. */
4356 429093922 : if (TREE_CODE (decl) == FIELD_DECL)
4357 : {
4358 31475041 : if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
4359 9 : TREE_TYPE (decl) = error_mark_node;
4360 31475041 : if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
4361 0 : DECL_ATTRIBUTES (decl) = NULL_TREE;
4362 : }
4363 :
4364 : /* [dcl.link]
4365 :
4366 : A C language linkage is ignored for the names of class members
4367 : and the member function type of class member functions. */
4368 429093922 : if (DECL_LANG_SPECIFIC (decl))
4369 391627936 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
4370 :
4371 429093922 : bool add = false;
4372 :
4373 : /* Functions and non-functions are added differently. */
4374 429093922 : if (DECL_DECLARES_FUNCTION_P (decl))
4375 221768055 : add = add_method (current_class_type, decl, false);
4376 : /* Enter the DECL into the scope of the class, if the class
4377 : isn't a closure (whose fields are supposed to be unnamed). */
4378 207325867 : else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
4379 203432287 : || maybe_push_used_methods (decl)
4380 408827285 : || pushdecl_class_level (decl))
4381 : add = true;
4382 :
4383 221768055 : if (add)
4384 : {
4385 : /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
4386 : go at the beginning. The reason is that
4387 : legacy_nonfn_member_lookup searches the list in order, and we
4388 : want a field name to override a type name so that the "struct
4389 : stat hack" will work. In particular:
4390 :
4391 : struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
4392 :
4393 : is valid. */
4394 :
4395 429080601 : if (TREE_CODE (decl) == TYPE_DECL)
4396 147085376 : TYPE_FIELDS (current_class_type)
4397 294170752 : = chainon (TYPE_FIELDS (current_class_type), decl);
4398 : else
4399 : {
4400 281995225 : DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
4401 281995225 : TYPE_FIELDS (current_class_type) = decl;
4402 : }
4403 :
4404 429080601 : maybe_add_class_template_decl_list (current_class_type, decl,
4405 : /*friend_p=*/0);
4406 : }
4407 : }
4408 :
4409 : /* Finish processing a complete template declaration. The PARMS are
4410 : the template parameters. */
4411 :
4412 : void
4413 94643765 : finish_template_decl (tree parms)
4414 : {
4415 94643765 : if (parms)
4416 94643756 : end_template_decl ();
4417 : else
4418 9 : end_specialization ();
4419 94643765 : }
4420 :
4421 : // Returns the template type of the class scope being entered. If we're
4422 : // entering a constrained class scope. TYPE is the class template
4423 : // scope being entered and we may need to match the intended type with
4424 : // a constrained specialization. For example:
4425 : //
4426 : // template<Object T>
4427 : // struct S { void f(); }; #1
4428 : //
4429 : // template<Object T>
4430 : // void S<T>::f() { } #2
4431 : //
4432 : // We check, in #2, that S<T> refers precisely to the type declared by
4433 : // #1 (i.e., that the constraints match). Note that the following should
4434 : // be an error since there is no specialization of S<T> that is
4435 : // unconstrained, but this is not diagnosed here.
4436 : //
4437 : // template<typename T>
4438 : // void S<T>::f() { }
4439 : //
4440 : // We cannot diagnose this problem here since this function also matches
4441 : // qualified template names that are not part of a definition. For example:
4442 : //
4443 : // template<Integral T, Floating_point U>
4444 : // typename pair<T, U>::first_type void f(T, U);
4445 : //
4446 : // Here, it is unlikely that there is a partial specialization of
4447 : // pair constrained for Integral and Floating_point arguments.
4448 : //
4449 : // The general rule is: if a constrained specialization with matching
4450 : // constraints is found return that type. Also note that if TYPE is not a
4451 : // class-type (e.g. a typename type), then no fixup is needed.
4452 :
4453 : static tree
4454 18583514 : fixup_template_type (tree type)
4455 : {
4456 : // Find the template parameter list at the a depth appropriate to
4457 : // the scope we're trying to enter.
4458 18583514 : tree parms = current_template_parms;
4459 18583514 : int depth = template_class_depth (type);
4460 22833247 : for (int n = current_template_depth; n > depth && parms; --n)
4461 4249733 : parms = TREE_CHAIN (parms);
4462 18583514 : if (!parms)
4463 : return type;
4464 18583504 : tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
4465 18583504 : tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
4466 :
4467 : // Search for a specialization whose type and constraints match.
4468 18583504 : tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
4469 18583504 : tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
4470 35970921 : while (specs)
4471 : {
4472 17833605 : tree spec_constr = get_constraints (TREE_VALUE (specs));
4473 :
4474 : // If the type and constraints match a specialization, then we
4475 : // are entering that type.
4476 17833605 : if (same_type_p (type, TREE_TYPE (specs))
4477 17833605 : && equivalent_constraints (cur_constr, spec_constr))
4478 446188 : return TREE_TYPE (specs);
4479 17387417 : specs = TREE_CHAIN (specs);
4480 : }
4481 :
4482 : // If no specialization matches, then must return the type
4483 : // previously found.
4484 : return type;
4485 : }
4486 :
4487 : /* Finish processing a template-id (which names a type) of the form
4488 : NAME < ARGS >. Return the TYPE_DECL for the type named by the
4489 : template-id. If ENTERING_SCOPE is nonzero we are about to enter
4490 : the scope of template-id indicated. */
4491 :
4492 : tree
4493 191996180 : finish_template_type (tree name, tree args, int entering_scope)
4494 : {
4495 191996180 : tree type;
4496 :
4497 191996180 : type = lookup_template_class (name, args,
4498 : NULL_TREE, NULL_TREE,
4499 : tf_warning_or_error | tf_user);
4500 191996177 : if (entering_scope)
4501 19641088 : type = adjust_type_for_entering_scope (type);
4502 :
4503 : /* If we might be entering the scope of a partial specialization,
4504 : find the one with the right constraints. */
4505 191996177 : if (flag_concepts
4506 189231527 : && entering_scope
4507 19266846 : && CLASS_TYPE_P (type)
4508 19094617 : && CLASSTYPE_TEMPLATE_INFO (type)
4509 19094608 : && dependent_type_p (type)
4510 210579691 : && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
4511 18583514 : type = fixup_template_type (type);
4512 :
4513 191996177 : if (type == error_mark_node)
4514 : return type;
4515 191993887 : else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
4516 150718599 : return TYPE_STUB_DECL (type);
4517 : else
4518 41275288 : return TYPE_NAME (type);
4519 : }
4520 :
4521 : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER
4522 : and ANNOTATIONS.
4523 : Return a TREE_LIST containing the ACCESS_SPECIFIER (or if there are
4524 : ANNOTATIONS, TREE_LIST containing the ACCESS_SPECIFIER and ANNOTATIONS)
4525 : and the BASE_CLASS, or NULL_TREE if an error occurred. The
4526 : ACCESS_SPECIFIER is one of
4527 : access_{default,public,protected,private}_node. For a virtual base
4528 : we set TREE_TYPE. */
4529 :
4530 : tree
4531 11696311 : finish_base_specifier (tree base, tree access, bool virtual_p,
4532 : tree annotations)
4533 : {
4534 11696311 : tree result;
4535 :
4536 11696311 : if (base == error_mark_node)
4537 : {
4538 0 : error ("invalid base-class specification");
4539 0 : result = NULL_TREE;
4540 : }
4541 11696311 : else if (! MAYBE_CLASS_TYPE_P (base))
4542 : {
4543 3 : error ("%qT is not a class type", base);
4544 3 : result = NULL_TREE;
4545 : }
4546 : else
4547 : {
4548 11696308 : if (cp_type_quals (base) != 0)
4549 : {
4550 : /* DR 484: Can a base-specifier name a cv-qualified
4551 : class type? */
4552 12 : base = TYPE_MAIN_VARIANT (base);
4553 : }
4554 11696308 : if (annotations)
4555 18 : access = build_tree_list (access, nreverse (annotations));
4556 11696308 : result = build_tree_list (access, base);
4557 11696308 : if (virtual_p)
4558 26742 : TREE_TYPE (result) = integer_type_node;
4559 : }
4560 :
4561 11696311 : return result;
4562 : }
4563 :
4564 : /* If FNS is a member function, a set of member functions, or a
4565 : template-id referring to one or more member functions, return a
4566 : BASELINK for FNS, incorporating the current access context.
4567 : Otherwise, return FNS unchanged. If IGNORE_CURRENT_CLASS_P is
4568 : true, we do not consider the currently open derived class. */
4569 :
4570 : tree
4571 188004867 : baselink_for_fns (tree fns, bool ignore_current_class_p/*=false*/)
4572 : {
4573 188004867 : if (BASELINK_P (fns) || error_operand_p (fns))
4574 : return fns;
4575 :
4576 173794192 : tree scope = ovl_scope (fns);
4577 173794192 : if (!CLASS_TYPE_P (scope))
4578 : return fns;
4579 :
4580 9099984 : tree cl = (ignore_current_class_p
4581 9099984 : ? NULL_TREE
4582 9098244 : : currently_open_derived_class (scope));
4583 9098244 : if (!cl)
4584 : cl = scope;
4585 9099984 : tree access_path = TYPE_BINFO (cl);
4586 9099984 : tree conv_path = (cl == scope ? access_path
4587 729830 : : lookup_base (cl, scope, ba_any, NULL, tf_none));
4588 9099984 : return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
4589 : }
4590 :
4591 : /* Returns true iff we are currently parsing a lambda-declarator. */
4592 :
4593 : bool
4594 2022789715 : parsing_lambda_declarator ()
4595 : {
4596 2022789715 : cp_binding_level *b = current_binding_level;
4597 2024848034 : while (b->kind == sk_template_parms || b->kind == sk_function_parms)
4598 2058319 : b = b->level_chain;
4599 2022789715 : return b->kind == sk_lambda;
4600 : }
4601 :
4602 : /* Returns true iff DECL is a variable from a function outside
4603 : the current one. */
4604 :
4605 : static bool
4606 2699001910 : outer_var_p (tree decl)
4607 : {
4608 : /* These should have been stripped or otherwise handled by the caller. */
4609 2699001910 : gcc_checking_assert (!REFERENCE_REF_P (decl));
4610 :
4611 1773833431 : return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
4612 2479234891 : && DECL_FUNCTION_SCOPE_P (decl)
4613 : /* Don't get confused by temporaries. */
4614 2055340176 : && DECL_NAME (decl)
4615 4730030111 : && (DECL_CONTEXT (decl) != current_function_decl
4616 2020592430 : || parsing_nsdmi ()
4617 : /* Also consider captures as outer vars if we are in
4618 : decltype in a lambda declarator as in:
4619 : auto l = [j=0]() -> decltype((j)) { ... }
4620 : for the sake of finish_decltype_type.
4621 :
4622 : (Similar issue also affects non-lambdas, but vexing parse
4623 : makes it more difficult to handle than lambdas.) */
4624 2020591083 : || parsing_lambda_declarator ()));
4625 : }
4626 :
4627 : /* As above, but also checks that DECL is automatic. */
4628 :
4629 : bool
4630 2699001910 : outer_automatic_var_p (tree decl)
4631 : {
4632 2699001910 : return (outer_var_p (decl)
4633 2699001910 : && !TREE_STATIC (decl));
4634 : }
4635 :
4636 : /* Note whether capture proxy D is only used in a contract condition. */
4637 :
4638 : static void
4639 178506 : set_contract_capture_flag (tree d, bool val)
4640 : {
4641 178506 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (d));
4642 178506 : tree proxy = DECL_VALUE_EXPR (d);
4643 178506 : gcc_checking_assert (TREE_CODE (proxy) == COMPONENT_REF
4644 : && TREE_CODE (TREE_OPERAND (proxy, 1)) == FIELD_DECL);
4645 178506 : DECL_CONTRACT_CAPTURE_P (TREE_OPERAND (proxy, 1)) = val;
4646 178506 : }
4647 :
4648 : /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
4649 : rewrite it for lambda capture.
4650 :
4651 : If ODR_USE is true, we're being called from mark_use, and we complain about
4652 : use of constant variables. If ODR_USE is false, we're being called for the
4653 : id-expression, and we do lambda capture. */
4654 :
4655 : tree
4656 5383502 : process_outer_var_ref (tree decl, tsubst_flags_t complain,
4657 : bool odr_use/*=false*/)
4658 : {
4659 5389921 : if (cp_unevaluated_operand)
4660 : {
4661 3191052 : tree type = TREE_TYPE (decl);
4662 3191052 : if (!dependent_type_p (type)
4663 3191052 : && variably_modified_type_p (type, NULL_TREE))
4664 : /* VLAs are used even in unevaluated context. */;
4665 : else
4666 : /* It's not a use (3.2) if we're in an unevaluated context. */
4667 : return decl;
4668 : }
4669 2198875 : if (decl == error_mark_node)
4670 : return decl;
4671 :
4672 2198869 : tree context = DECL_CONTEXT (decl);
4673 2198869 : tree containing_function = current_function_decl;
4674 2198869 : tree lambda_stack = NULL_TREE;
4675 2198869 : tree lambda_expr = NULL_TREE;
4676 2198869 : tree initializer = convert_from_reference (decl);
4677 2198869 : tree var = strip_normal_capture_proxy (decl);
4678 :
4679 : /* Mark it as used now even if the use is ill-formed. */
4680 2198869 : if (!mark_used (decl, complain))
4681 3 : return error_mark_node;
4682 :
4683 2198866 : if (parsing_nsdmi () || parsing_lambda_declarator ())
4684 : containing_function = NULL_TREE;
4685 :
4686 4396824 : if (containing_function && LAMBDA_FUNCTION_P (containing_function))
4687 : {
4688 : /* Check whether we've already built a proxy. */
4689 2198297 : tree d = retrieve_local_specialization (var);
4690 :
4691 2198297 : if (d && d != decl && is_capture_proxy (d))
4692 : {
4693 1138195 : if (flag_contracts && !processing_contract_condition)
4694 : /* We might have created a capture for a contract_assert ref. to
4695 : some var, if that is now captured 'normally' then this is OK.
4696 : Otherwise we leave the capture marked as incorrect. */
4697 178500 : set_contract_capture_flag (d, false);
4698 1138195 : if (DECL_CONTEXT (d) == containing_function)
4699 : /* We already have an inner proxy. */
4700 : return d;
4701 : else
4702 : /* We need to capture an outer proxy. */
4703 : return process_outer_var_ref (d, complain, odr_use);
4704 : }
4705 : }
4706 :
4707 : /* If we are in a lambda function, we can move out until we hit
4708 : 1. the context,
4709 : 2. a non-lambda function, or
4710 : 3. a non-default capturing lambda function. */
4711 2127507 : while (context != containing_function
4712 : /* containing_function can be null with invalid generic lambdas. */
4713 2127507 : && containing_function
4714 3195755 : && LAMBDA_FUNCTION_P (containing_function))
4715 : {
4716 1068248 : tree closure = DECL_CONTEXT (containing_function);
4717 1068248 : lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
4718 :
4719 1068248 : if (TYPE_CLASS_SCOPE_P (closure))
4720 : /* A lambda in an NSDMI (c++/64496). */
4721 : break;
4722 :
4723 1068245 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4724 : break;
4725 :
4726 1066836 : lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
4727 :
4728 1066836 : containing_function = decl_function_context (containing_function);
4729 : }
4730 :
4731 : /* In a lambda within a template, wait until instantiation time to implicitly
4732 : capture a parameter pack. We want to wait because we don't know if we're
4733 : capturing the whole pack or a single element, and it's OK to wait because
4734 : find_parameter_packs_r walks into the lambda body. */
4735 1060671 : if (context == containing_function
4736 1060671 : && DECL_PACK_P (decl))
4737 : return decl;
4738 :
4739 1016219 : if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
4740 : {
4741 6 : if (complain & tf_error)
4742 6 : error ("cannot capture member %qD of anonymous union", decl);
4743 6 : return error_mark_node;
4744 : }
4745 : /* Do lambda capture when processing the id-expression, not when
4746 : odr-using a variable, but uses in a contract must not cause a capture. */
4747 1016213 : if (!odr_use && context == containing_function)
4748 : {
4749 1014232 : decl = add_default_capture (lambda_stack,
4750 1014232 : /*id=*/DECL_NAME (decl), initializer);
4751 1014232 : if (flag_contracts && processing_contract_condition)
4752 6 : set_contract_capture_flag (decl, true);
4753 : }
4754 : /* Only an odr-use of an outer automatic variable causes an
4755 : error, and a constant variable can decay to a prvalue
4756 : constant without odr-use. So don't complain yet. */
4757 1981 : else if (!odr_use && decl_constant_var_p (var))
4758 : return var;
4759 : /* Don't complain when DECL is dependent, because it can turn out to
4760 : be constant (and therefore needing no capture) when instantiating. */
4761 452 : else if (VAR_P (var) && instantiation_dependent_expression_p (var))
4762 : return var;
4763 434 : else if (lambda_expr)
4764 : {
4765 60 : if (complain & tf_error)
4766 : {
4767 56 : auto_diagnostic_group d;
4768 56 : error ("%qD is not captured", decl);
4769 56 : tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
4770 56 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4771 53 : inform (location_of (closure),
4772 : "the lambda has no capture-default");
4773 3 : else if (TYPE_CLASS_SCOPE_P (closure))
4774 3 : inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
4775 : "capture variables from the enclosing context",
4776 3 : TYPE_CONTEXT (closure));
4777 56 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4778 56 : }
4779 60 : return error_mark_node;
4780 : }
4781 374 : else if (processing_contract_condition && TREE_CODE (decl) == PARM_DECL)
4782 : /* Use of a parameter in a contract condition is fine. */
4783 : return decl;
4784 : else
4785 : {
4786 53 : if (complain & tf_error)
4787 : {
4788 39 : auto_diagnostic_group d;
4789 57 : error (VAR_P (decl)
4790 : ? G_("use of local variable with automatic storage from "
4791 : "containing function")
4792 : : G_("use of parameter from containing function"));
4793 39 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4794 39 : }
4795 53 : return error_mark_node;
4796 : }
4797 : return decl;
4798 : }
4799 :
4800 : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4801 : id-expression. (See cp_parser_id_expression for details.) SCOPE,
4802 : if non-NULL, is the type or namespace used to explicitly qualify
4803 : ID_EXPRESSION. DECL is the entity to which that name has been
4804 : resolved.
4805 :
4806 : *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4807 : constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4808 : be set to true if this expression isn't permitted in a
4809 : constant-expression, but it is otherwise not set by this function.
4810 : *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4811 : constant-expression, but a non-constant expression is also
4812 : permissible.
4813 :
4814 : DONE is true if this expression is a complete postfix-expression;
4815 : it is false if this expression is followed by '->', '[', '(', etc.
4816 : ADDRESS_P is true iff this expression is the operand of '&'.
4817 : TEMPLATE_P is true iff the qualified-id was of the form
4818 : "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4819 : appears as a template argument.
4820 :
4821 : If an error occurs, and it is the kind of error that might cause
4822 : the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4823 : is the caller's responsibility to issue the message. *ERROR_MSG
4824 : will be a string with static storage duration, so the caller need
4825 : not "free" it.
4826 :
4827 : Return an expression for the entity, after issuing appropriate
4828 : diagnostics. This function is also responsible for transforming a
4829 : reference to a non-static member into a COMPONENT_REF that makes
4830 : the use of "this" explicit.
4831 :
4832 : Upon return, *IDK will be filled in appropriately. */
4833 : static cp_expr
4834 800873426 : finish_id_expression_1 (tree id_expression,
4835 : tree decl,
4836 : tree scope,
4837 : cp_id_kind *idk,
4838 : bool integral_constant_expression_p,
4839 : bool allow_non_integral_constant_expression_p,
4840 : bool *non_integral_constant_expression_p,
4841 : bool template_p,
4842 : bool done,
4843 : bool address_p,
4844 : bool template_arg_p,
4845 : const char **error_msg,
4846 : location_t location)
4847 : {
4848 800873426 : decl = strip_using_decl (decl);
4849 :
4850 : /* Initialize the output parameters. */
4851 800873426 : *idk = CP_ID_KIND_NONE;
4852 800873426 : *error_msg = NULL;
4853 :
4854 800873426 : if (id_expression == error_mark_node)
4855 12 : return error_mark_node;
4856 : /* If we have a template-id, then no further lookup is
4857 : required. If the template-id was for a template-class, we
4858 : will sometimes have a TYPE_DECL at this point. */
4859 800873414 : else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4860 745059891 : || TREE_CODE (decl) == TYPE_DECL)
4861 : ;
4862 : /* Look up the name. */
4863 : else
4864 : {
4865 745058968 : if (decl == error_mark_node)
4866 : {
4867 : /* Name lookup failed. */
4868 132922 : if (scope
4869 374 : && !dependent_namespace_p (scope)
4870 133296 : && (!TYPE_P (scope)
4871 119 : || (!dependentish_scope_p (scope)
4872 115 : && !(identifier_p (id_expression)
4873 100 : && IDENTIFIER_CONV_OP_P (id_expression)
4874 3 : && dependent_type_p (TREE_TYPE (id_expression))))))
4875 : {
4876 : /* If the qualifying type is non-dependent (and the name
4877 : does not name a conversion operator to a dependent
4878 : type), issue an error. */
4879 364 : qualified_name_lookup_error (scope, id_expression, decl, location);
4880 364 : return error_mark_node;
4881 : }
4882 132558 : else if (!scope)
4883 : {
4884 : /* It may be resolved via Koenig lookup. */
4885 132548 : *idk = CP_ID_KIND_UNQUALIFIED;
4886 132548 : return id_expression;
4887 : }
4888 : else
4889 : decl = id_expression;
4890 : }
4891 :
4892 : /* Remember that the name was used in the definition of
4893 : the current class so that we can check later to see if
4894 : the meaning would have been different after the class
4895 : was entirely defined. */
4896 744926046 : if (!scope && decl != error_mark_node && identifier_p (id_expression))
4897 666116306 : maybe_note_name_used_in_class (id_expression, decl);
4898 :
4899 : /* A use in unevaluated operand might not be instantiated appropriately
4900 : if tsubst_copy builds a dummy parm, or if we never instantiate a
4901 : generic lambda, so mark it now. */
4902 744926056 : if (processing_template_decl
4903 744926056 : && (cp_unevaluated_operand
4904 644199832 : || generic_lambda_fn_p (current_function_decl)))
4905 20830097 : mark_type_use (decl);
4906 :
4907 : /* Disallow uses of local variables from containing functions, except
4908 : within lambda-expressions. */
4909 744926056 : if (outer_automatic_var_p (decl))
4910 : {
4911 3850488 : decl = process_outer_var_ref (decl, tf_warning_or_error);
4912 3850488 : if (decl == error_mark_node)
4913 92 : return error_mark_node;
4914 : }
4915 :
4916 : /* Also disallow uses of function parameters outside the function
4917 : body, except inside an unevaluated context (i.e. decltype). */
4918 744925964 : if (TREE_CODE (decl) == PARM_DECL
4919 311034556 : && DECL_CONTEXT (decl) == NULL_TREE
4920 8447858 : && !CONSTRAINT_VAR_P (decl)
4921 4532205 : && !cp_unevaluated_operand
4922 563 : && !processing_contract_condition
4923 744926020 : && !processing_omp_trait_property_expr)
4924 : {
4925 38 : *error_msg = G_("use of parameter outside function body");
4926 38 : return error_mark_node;
4927 : }
4928 : }
4929 :
4930 : /* If we didn't find anything, or what we found was a type,
4931 : then this wasn't really an id-expression. */
4932 800740372 : if (TREE_CODE (decl) == TEMPLATE_DECL
4933 800740372 : && !DECL_FUNCTION_TEMPLATE_P (decl))
4934 : {
4935 51 : *error_msg = G_("missing template arguments");
4936 51 : return error_mark_node;
4937 : }
4938 800740321 : else if (TREE_CODE (decl) == TYPE_DECL
4939 800739398 : || TREE_CODE (decl) == NAMESPACE_DECL)
4940 : {
4941 938 : *error_msg = G_("expected primary-expression");
4942 938 : return error_mark_node;
4943 : }
4944 :
4945 : /* If the name resolved to a template parameter, there is no
4946 : need to look it up again later. */
4947 33921416 : if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
4948 814876220 : || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4949 : {
4950 19784579 : tree r;
4951 :
4952 19784579 : *idk = CP_ID_KIND_NONE;
4953 19784579 : if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4954 0 : decl = TEMPLATE_PARM_DECL (decl);
4955 19784579 : r = DECL_INITIAL (decl);
4956 19784579 : if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
4957 : {
4958 : /* If the entity is a template parameter object for a template
4959 : parameter of type T, the type of the expression is const T. */
4960 2969 : tree ctype = TREE_TYPE (r);
4961 2969 : ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
4962 : | TYPE_QUAL_CONST));
4963 2969 : r = build1 (VIEW_CONVERT_EXPR, ctype, r);
4964 : }
4965 19784579 : r = convert_from_reference (r);
4966 19784579 : if (integral_constant_expression_p
4967 3451059 : && !dependent_type_p (TREE_TYPE (decl))
4968 22730915 : && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
4969 : {
4970 1023 : if (!allow_non_integral_constant_expression_p)
4971 6 : error ("template parameter %qD of type %qT is not allowed in "
4972 : "an integral constant expression because it is not of "
4973 6 : "integral or enumeration type", decl, TREE_TYPE (decl));
4974 1023 : *non_integral_constant_expression_p = true;
4975 : }
4976 :
4977 19784579 : if (flag_contracts && processing_contract_condition)
4978 15 : r = constify_contract_access (r);
4979 :
4980 19784579 : return r;
4981 : }
4982 780954804 : else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
4983 : {
4984 9 : gcc_checking_assert (scope);
4985 9 : *idk = CP_ID_KIND_QUALIFIED;
4986 9 : cp_warn_deprecated_use_scopes (scope);
4987 9 : decl = finish_qualified_id_expr (scope, decl, done, address_p,
4988 : template_p, template_arg_p,
4989 : tf_warning_or_error);
4990 : }
4991 : else
4992 : {
4993 780954795 : if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4994 55813523 : && variable_template_p (TREE_OPERAND (decl, 0))
4995 793600613 : && !concept_check_p (decl))
4996 : /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
4997 : considered type-dependent) now, so that the dependence test that
4998 : follows gives us the right answer: if it represents a non-dependent
4999 : variable template-id then finish_template_variable will yield the
5000 : corresponding non-dependent VAR_DECL. */
5001 12645818 : decl = finish_template_variable (decl);
5002 :
5003 780954795 : bool dependent_p = type_dependent_expression_p (decl);
5004 :
5005 : /* If the declaration was explicitly qualified indicate
5006 : that. The semantics of `A::f(3)' are different than
5007 : `f(3)' if `f' is virtual. */
5008 1561909590 : *idk = (scope
5009 780954795 : ? CP_ID_KIND_QUALIFIED
5010 679349836 : : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
5011 679349836 : ? CP_ID_KIND_TEMPLATE_ID
5012 : : (dependent_p
5013 646625247 : ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
5014 : : CP_ID_KIND_UNQUALIFIED)));
5015 :
5016 780954795 : if (dependent_p
5017 780954795 : && !scope
5018 447994597 : && DECL_P (decl)
5019 1197319092 : && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
5020 : /* Dependent type attributes on the decl mean that the TREE_TYPE is
5021 : wrong, so just return the identifier. */
5022 39 : return id_expression;
5023 :
5024 780954756 : if (DECL_CLASS_TEMPLATE_P (decl))
5025 : {
5026 0 : error ("use of class template %qT as expression", decl);
5027 0 : return error_mark_node;
5028 : }
5029 :
5030 780954756 : if (TREE_CODE (decl) == TREE_LIST)
5031 : {
5032 : /* Ambiguous reference to base members. */
5033 0 : auto_diagnostic_group d;
5034 0 : error ("request for member %qD is ambiguous in "
5035 : "multiple inheritance lattice", id_expression);
5036 0 : print_candidates (input_location, decl);
5037 0 : return error_mark_node;
5038 0 : }
5039 :
5040 : /* Mark variable-like entities as used. Functions are similarly
5041 : marked either below or after overload resolution. */
5042 780954756 : if ((VAR_P (decl)
5043 566447406 : || TREE_CODE (decl) == PARM_DECL
5044 255412894 : || TREE_CODE (decl) == CONST_DECL
5045 241276057 : || TREE_CODE (decl) == RESULT_DECL)
5046 1106126105 : && !mark_used (decl))
5047 12 : return error_mark_node;
5048 :
5049 : /* Only certain kinds of names are allowed in constant
5050 : expression. Template parameters have already
5051 : been handled above. */
5052 780954741 : if (! error_operand_p (decl)
5053 780954415 : && !dependent_p
5054 780954415 : && integral_constant_expression_p
5055 78613648 : && !decl_constant_var_p (decl)
5056 63911208 : && TREE_CODE (decl) != CONST_DECL
5057 55220853 : && !builtin_valid_in_constant_expr_p (decl)
5058 836125432 : && !concept_check_p (decl))
5059 : {
5060 54594720 : if (!allow_non_integral_constant_expression_p)
5061 : {
5062 30 : error ("%qD cannot appear in a constant-expression", decl);
5063 30 : return error_mark_node;
5064 : }
5065 54594690 : *non_integral_constant_expression_p = true;
5066 : }
5067 :
5068 780954711 : if (tree wrap = maybe_get_tls_wrapper_call (decl))
5069 : /* Replace an evaluated use of the thread_local variable with
5070 : a call to its wrapper. */
5071 : decl = wrap;
5072 780954199 : else if (concept_check_p (decl))
5073 : {
5074 : /* Nothing more to do. All of the analysis for concept checks
5075 : is done by build_conept_id, called from the parser. */
5076 : }
5077 763752335 : else if (scope)
5078 : {
5079 99634529 : if (TREE_CODE (decl) == SCOPE_REF)
5080 : {
5081 91135 : gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
5082 91135 : decl = TREE_OPERAND (decl, 1);
5083 : }
5084 :
5085 99634529 : decl = (adjust_result_of_qualified_name_lookup
5086 99634529 : (decl, scope, current_nonlambda_class_type()));
5087 :
5088 99634529 : cp_warn_deprecated_use_scopes (scope);
5089 :
5090 99634529 : if (TYPE_P (scope))
5091 14124167 : decl = finish_qualified_id_expr (scope,
5092 : decl,
5093 : done,
5094 : address_p,
5095 : template_p,
5096 : template_arg_p,
5097 : tf_warning_or_error);
5098 : else
5099 85510362 : decl = convert_from_reference (decl);
5100 : }
5101 664117806 : else if (TREE_CODE (decl) == FIELD_DECL)
5102 : {
5103 69012036 : if (flag_contracts && processing_contract_condition
5104 37 : && contract_class_ptr == current_class_ptr)
5105 : {
5106 6 : error ("%qD 'this' required when accessing a member within a "
5107 : "constructor precondition or destructor postcondition "
5108 : "contract check", decl);
5109 6 : return error_mark_node;
5110 : }
5111 : /* Since SCOPE is NULL here, this is an unqualified name.
5112 : Access checking has been performed during name lookup
5113 : already. Turn off checking to avoid duplicate errors. */
5114 69012030 : push_deferring_access_checks (dk_no_check);
5115 69012030 : decl = finish_non_static_data_member (decl, NULL_TREE,
5116 : /*qualifying_scope=*/NULL_TREE);
5117 69012030 : pop_deferring_access_checks ();
5118 : }
5119 595105770 : else if (is_overloaded_fn (decl))
5120 : {
5121 : /* We only need to look at the first function,
5122 : because all the fns share the attribute we're
5123 : concerned with (all member fns or all non-members). */
5124 63825455 : tree first_fn = get_first_fn (decl);
5125 63825455 : first_fn = STRIP_TEMPLATE (first_fn);
5126 :
5127 63825455 : if (!template_arg_p
5128 63825455 : && (TREE_CODE (first_fn) == USING_DECL
5129 63823567 : || (TREE_CODE (first_fn) == FUNCTION_DECL
5130 63823567 : && DECL_FUNCTION_MEMBER_P (first_fn)
5131 39002757 : && !shared_member_p (decl))))
5132 : {
5133 : /* A set of member functions. */
5134 30027159 : if (flag_contracts && processing_contract_condition
5135 24 : && contract_class_ptr == current_class_ptr)
5136 : {
5137 3 : error ("%qD 'this' required when accessing a member within a "
5138 : "constructor precondition or destructor postcondition "
5139 : "contract check", decl);
5140 3 : return error_mark_node;
5141 : }
5142 30027156 : decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
5143 30027156 : return finish_class_member_access_expr (decl, id_expression,
5144 : /*template_p=*/false,
5145 30027156 : tf_warning_or_error);
5146 : }
5147 :
5148 33798296 : decl = baselink_for_fns (decl);
5149 : }
5150 : else
5151 : {
5152 519594079 : if (DECL_P (decl) && DECL_NONLOCAL (decl)
5153 532812391 : && DECL_CLASS_SCOPE_P (decl))
5154 : {
5155 1532076 : tree context = context_for_name_lookup (decl);
5156 1532076 : if (context != current_class_type)
5157 : {
5158 801037 : tree path = currently_open_derived_class (context);
5159 801037 : if (!path)
5160 : /* PATH can be null for using an enum of an unrelated
5161 : class; we checked its access in lookup_using_decl.
5162 :
5163 : ??? Should this case make a clone instead, like
5164 : handle_using_decl? */
5165 43 : gcc_assert (TREE_CODE (decl) == CONST_DECL
5166 : /* This is for:
5167 : constexpr auto r = ^^S::i;
5168 : auto a = [:r:]; */
5169 : || flag_reflection);
5170 : else
5171 800994 : perform_or_defer_access_check (TYPE_BINFO (path),
5172 : decl, decl,
5173 : tf_warning_or_error);
5174 : }
5175 : }
5176 :
5177 531280315 : decl = convert_from_reference (decl);
5178 : }
5179 : }
5180 :
5181 750927555 : check_param_in_postcondition (decl, location);
5182 750927555 : if (flag_contracts && processing_contract_condition)
5183 2033 : decl = constify_contract_access (decl);
5184 :
5185 750927555 : return cp_expr (decl, location);
5186 : }
5187 :
5188 : /* As per finish_id_expression_1, but adding a wrapper node
5189 : around the result if needed to express LOCATION. */
5190 :
5191 : cp_expr
5192 800873426 : finish_id_expression (tree id_expression,
5193 : tree decl,
5194 : tree scope,
5195 : cp_id_kind *idk,
5196 : bool integral_constant_expression_p,
5197 : bool allow_non_integral_constant_expression_p,
5198 : bool *non_integral_constant_expression_p,
5199 : bool template_p,
5200 : bool done,
5201 : bool address_p,
5202 : bool template_arg_p,
5203 : const char **error_msg,
5204 : location_t location)
5205 : {
5206 800873426 : cp_expr result
5207 800873426 : = finish_id_expression_1 (id_expression, decl, scope, idk,
5208 : integral_constant_expression_p,
5209 : allow_non_integral_constant_expression_p,
5210 : non_integral_constant_expression_p,
5211 : template_p, done, address_p, template_arg_p,
5212 : error_msg, location);
5213 800873423 : return result.maybe_add_location_wrapper ();
5214 : }
5215 :
5216 : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
5217 : use as a type-specifier. */
5218 :
5219 : tree
5220 22044398 : finish_typeof (tree expr)
5221 : {
5222 22044398 : tree type;
5223 :
5224 22044398 : if (type_dependent_expression_p (expr))
5225 : {
5226 21951265 : type = cxx_make_type (TYPEOF_TYPE);
5227 21951265 : TYPEOF_TYPE_EXPR (type) = expr;
5228 21951265 : SET_TYPE_STRUCTURAL_EQUALITY (type);
5229 :
5230 21951265 : return type;
5231 : }
5232 :
5233 93133 : expr = mark_type_use (expr);
5234 :
5235 93133 : type = unlowered_expr_type (expr);
5236 :
5237 93133 : if (!type || type == unknown_type_node)
5238 : {
5239 3 : error ("type of %qE is unknown", expr);
5240 3 : return error_mark_node;
5241 : }
5242 :
5243 : return type;
5244 : }
5245 :
5246 : /* Implement the __underlying_type keyword: Return the underlying
5247 : type of TYPE, suitable for use as a type-specifier. */
5248 :
5249 : tree
5250 48876 : finish_underlying_type (tree type)
5251 : {
5252 48876 : if (!complete_type_or_else (type, NULL_TREE))
5253 3 : return error_mark_node;
5254 :
5255 48873 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5256 : {
5257 24 : error ("%qT is not an enumeration type", type);
5258 24 : return error_mark_node;
5259 : }
5260 :
5261 48849 : tree underlying_type = ENUM_UNDERLYING_TYPE (type);
5262 :
5263 : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5264 : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5265 : See finish_enum_value_list for details. */
5266 48849 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5267 56 : underlying_type
5268 56 : = c_common_type_for_mode (TYPE_MODE (underlying_type),
5269 56 : TYPE_UNSIGNED (underlying_type));
5270 :
5271 : return underlying_type;
5272 : }
5273 :
5274 : /* Implement the __type_pack_element keyword: Return the type
5275 : at index IDX within TYPES. */
5276 :
5277 : static tree
5278 135687 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
5279 : {
5280 135687 : idx = maybe_constant_value (idx, NULL_TREE, mce_true);
5281 135687 : if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
5282 : {
5283 6 : if (complain & tf_error)
5284 3 : error ("pack index has non-integral type %qT", TREE_TYPE (idx));
5285 6 : return error_mark_node;
5286 : }
5287 135681 : if (TREE_CODE (idx) != INTEGER_CST)
5288 : {
5289 2 : if (complain & tf_error)
5290 : {
5291 2 : error ("pack index is not an integral constant");
5292 2 : cxx_constant_value (idx);
5293 : }
5294 2 : return error_mark_node;
5295 : }
5296 135679 : if (tree_int_cst_sgn (idx) < 0)
5297 : {
5298 3 : if (complain & tf_error)
5299 3 : error ("pack index %qE is negative", idx);
5300 3 : return error_mark_node;
5301 : }
5302 135676 : if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
5303 : {
5304 35 : if (complain & tf_error)
5305 29 : error ("pack index %qE is out of range for pack of length %qd",
5306 29 : idx, TREE_VEC_LENGTH (types));
5307 35 : return error_mark_node;
5308 : }
5309 135641 : return TREE_VEC_ELT (types, tree_to_shwi (idx));
5310 : }
5311 :
5312 : /* In a pack-index T...[N], return the element at index IDX within TYPES.
5313 : PARENTHESIZED_P is true iff the pack index was wrapped in (). */
5314 :
5315 : tree
5316 22552 : pack_index_element (tree idx, tree types, bool parenthesized_p,
5317 : tsubst_flags_t complain)
5318 : {
5319 22552 : tree r = finish_type_pack_element (idx, types, complain);
5320 22552 : if (parenthesized_p)
5321 : /* For the benefit of decltype(auto). */
5322 35 : r = force_paren_expr (r);
5323 22552 : return r;
5324 : }
5325 :
5326 : /* Implement the __direct_bases keyword: Return the direct base classes
5327 : of type. */
5328 :
5329 : tree
5330 15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
5331 : {
5332 15 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5333 15 : || !NON_UNION_CLASS_TYPE_P (type))
5334 8 : return make_tree_vec (0);
5335 :
5336 7 : releasing_vec vector;
5337 7 : vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
5338 7 : tree binfo;
5339 7 : unsigned i;
5340 :
5341 : /* Virtual bases are initialized first */
5342 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5343 13 : if (BINFO_VIRTUAL_P (binfo))
5344 2 : vec_safe_push (vector, binfo);
5345 :
5346 : /* Now non-virtuals */
5347 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5348 13 : if (!BINFO_VIRTUAL_P (binfo))
5349 11 : vec_safe_push (vector, binfo);
5350 :
5351 7 : tree bases_vec = make_tree_vec (vector->length ());
5352 :
5353 27 : for (i = 0; i < vector->length (); ++i)
5354 13 : TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
5355 :
5356 7 : return bases_vec;
5357 7 : }
5358 :
5359 : /* Implement the __bases keyword: Return the base classes
5360 : of type */
5361 :
5362 : /* Find morally non-virtual base classes by walking binfo hierarchy */
5363 : /* Virtual base classes are handled separately in finish_bases */
5364 :
5365 : static tree
5366 73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
5367 : {
5368 : /* Don't walk bases of virtual bases */
5369 73 : return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
5370 : }
5371 :
5372 : static tree
5373 73 : dfs_calculate_bases_post (tree binfo, void *data_)
5374 : {
5375 73 : vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
5376 73 : if (!BINFO_VIRTUAL_P (binfo))
5377 48 : vec_safe_push (*data, BINFO_TYPE (binfo));
5378 73 : return NULL_TREE;
5379 : }
5380 :
5381 : /* Calculates the morally non-virtual base classes of a class */
5382 : static vec<tree, va_gc> *
5383 16 : calculate_bases_helper (tree type)
5384 : {
5385 16 : vec<tree, va_gc> *vector = make_tree_vector ();
5386 :
5387 : /* Now add non-virtual base classes in order of construction */
5388 16 : if (TYPE_BINFO (type))
5389 16 : dfs_walk_all (TYPE_BINFO (type),
5390 : dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
5391 16 : return vector;
5392 : }
5393 :
5394 : tree
5395 12 : calculate_bases (tree type, tsubst_flags_t complain)
5396 : {
5397 12 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5398 12 : || !NON_UNION_CLASS_TYPE_P (type))
5399 5 : return make_tree_vec (0);
5400 :
5401 7 : releasing_vec vector;
5402 7 : tree bases_vec = NULL_TREE;
5403 7 : unsigned i;
5404 7 : vec<tree, va_gc> *vbases;
5405 7 : tree binfo;
5406 :
5407 : /* First go through virtual base classes */
5408 7 : for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
5409 16 : vec_safe_iterate (vbases, i, &binfo); i++)
5410 : {
5411 9 : releasing_vec vbase_bases
5412 9 : = calculate_bases_helper (BINFO_TYPE (binfo));
5413 9 : vec_safe_splice (vector, vbase_bases);
5414 9 : }
5415 :
5416 : /* Now for the non-virtual bases */
5417 7 : releasing_vec nonvbases = calculate_bases_helper (type);
5418 7 : vec_safe_splice (vector, nonvbases);
5419 :
5420 : /* Note that during error recovery vector->length can even be zero. */
5421 7 : if (vector->length () > 1)
5422 : {
5423 : /* Last element is entire class, so don't copy */
5424 6 : bases_vec = make_tree_vec (vector->length () - 1);
5425 :
5426 53 : for (i = 0; i < vector->length () - 1; ++i)
5427 41 : TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
5428 : }
5429 : else
5430 1 : bases_vec = make_tree_vec (0);
5431 :
5432 7 : return bases_vec;
5433 7 : }
5434 :
5435 : tree
5436 28 : finish_bases (tree type, bool direct)
5437 : {
5438 28 : tree bases = NULL_TREE;
5439 :
5440 28 : if (!processing_template_decl)
5441 : {
5442 : /* Parameter packs can only be used in templates */
5443 0 : error ("parameter pack %<__bases%> only valid in template declaration");
5444 0 : return error_mark_node;
5445 : }
5446 :
5447 28 : bases = cxx_make_type (BASES);
5448 28 : BASES_TYPE (bases) = type;
5449 28 : BASES_DIRECT (bases) = direct;
5450 28 : SET_TYPE_STRUCTURAL_EQUALITY (bases);
5451 :
5452 28 : return bases;
5453 : }
5454 :
5455 : /* Perform C++-specific checks for __builtin_offsetof before calling
5456 : fold_offsetof. */
5457 :
5458 : tree
5459 2419 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
5460 : {
5461 : /* If we're processing a template, we can't finish the semantics yet.
5462 : Otherwise we can fold the entire expression now. */
5463 2419 : if (processing_template_decl)
5464 : {
5465 60 : expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
5466 60 : SET_EXPR_LOCATION (expr, loc);
5467 60 : return expr;
5468 : }
5469 :
5470 2359 : if (expr == error_mark_node)
5471 : return error_mark_node;
5472 :
5473 2342 : if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
5474 : {
5475 6 : error ("cannot apply %<offsetof%> to destructor %<~%T%>",
5476 6 : TREE_OPERAND (expr, 2));
5477 6 : return error_mark_node;
5478 : }
5479 4657 : if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
5480 4657 : || TREE_TYPE (expr) == unknown_type_node)
5481 : {
5482 30 : while (TREE_CODE (expr) == COMPONENT_REF
5483 30 : || TREE_CODE (expr) == COMPOUND_EXPR)
5484 12 : expr = TREE_OPERAND (expr, 1);
5485 :
5486 18 : if (DECL_P (expr))
5487 : {
5488 0 : auto_diagnostic_group d;
5489 0 : error ("cannot apply %<offsetof%> to member function %qD", expr);
5490 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
5491 0 : }
5492 : else
5493 18 : error ("cannot apply %<offsetof%> to member function");
5494 18 : return error_mark_node;
5495 : }
5496 2318 : if (TREE_CODE (expr) == CONST_DECL)
5497 : {
5498 3 : error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
5499 3 : return error_mark_node;
5500 : }
5501 2315 : if (REFERENCE_REF_P (expr))
5502 9 : expr = TREE_OPERAND (expr, 0);
5503 2315 : if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
5504 3 : return error_mark_node;
5505 2312 : if (warn_invalid_offsetof
5506 2312 : && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
5507 2312 : && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
5508 2357 : && cp_unevaluated_operand == 0)
5509 45 : warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
5510 : "non-standard-layout type %qT is conditionally-supported",
5511 45 : TREE_TYPE (TREE_TYPE (object_ptr)));
5512 2312 : return fold_offsetof (expr);
5513 : }
5514 :
5515 : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
5516 : function is broken out from the above for the benefit of the tree-ssa
5517 : project. */
5518 :
5519 : void
5520 365496 : simplify_aggr_init_expr (tree *tp)
5521 : {
5522 365496 : tree aggr_init_expr = *tp;
5523 :
5524 : /* Form an appropriate CALL_EXPR. */
5525 365496 : tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
5526 365496 : tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
5527 365496 : tree type = TREE_TYPE (slot);
5528 :
5529 365496 : tree call_expr;
5530 365496 : enum style_t { ctor, arg, pcc } style;
5531 :
5532 365496 : if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
5533 : style = ctor;
5534 : #ifdef PCC_STATIC_STRUCT_RETURN
5535 : else if (1)
5536 : style = pcc;
5537 : #endif
5538 : else
5539 : {
5540 97157 : gcc_assert (TREE_ADDRESSABLE (type));
5541 : style = arg;
5542 : }
5543 :
5544 365496 : call_expr = build_call_array_loc (input_location,
5545 365496 : TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
5546 : fn,
5547 365496 : aggr_init_expr_nargs (aggr_init_expr),
5548 365496 : AGGR_INIT_EXPR_ARGP (aggr_init_expr));
5549 365496 : TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
5550 365496 : CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
5551 365496 : CALL_EXPR_OPERATOR_SYNTAX (call_expr)
5552 365496 : = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
5553 365496 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
5554 365496 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
5555 365496 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
5556 :
5557 365496 : if (style == ctor)
5558 : {
5559 : /* Replace the first argument to the ctor with the address of the
5560 : slot. */
5561 268339 : cxx_mark_addressable (slot);
5562 268339 : CALL_EXPR_ARG (call_expr, 0) =
5563 268339 : build1 (ADDR_EXPR, build_pointer_type (type), slot);
5564 : }
5565 97157 : else if (style == arg)
5566 : {
5567 : /* Just mark it addressable here, and leave the rest to
5568 : expand_call{,_inline}. */
5569 97157 : cxx_mark_addressable (slot);
5570 97157 : CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
5571 97157 : call_expr = cp_build_init_expr (slot, call_expr);
5572 : }
5573 : else if (style == pcc)
5574 : {
5575 : /* If we're using the non-reentrant PCC calling convention, then we
5576 : need to copy the returned value out of the static buffer into the
5577 : SLOT. */
5578 : push_deferring_access_checks (dk_no_check);
5579 : call_expr = build_aggr_init (slot, call_expr,
5580 : DIRECT_BIND | LOOKUP_ONLYCONVERTING,
5581 : tf_warning_or_error);
5582 : pop_deferring_access_checks ();
5583 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
5584 : }
5585 :
5586 365496 : if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
5587 : {
5588 4117 : tree init = build_zero_init (type, NULL_TREE,
5589 : /*static_storage_p=*/false);
5590 4117 : init = cp_build_init_expr (slot, init);
5591 4117 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
5592 : init, call_expr);
5593 : }
5594 :
5595 365496 : *tp = call_expr;
5596 365496 : }
5597 :
5598 : /* Emit all thunks to FN that should be emitted when FN is emitted. */
5599 :
5600 : void
5601 61539657 : emit_associated_thunks (tree fn)
5602 : {
5603 : /* When we use vcall offsets, we emit thunks with the virtual
5604 : functions to which they thunk. The whole point of vcall offsets
5605 : is so that you can know statically the entire set of thunks that
5606 : will ever be needed for a given virtual function, thereby
5607 : enabling you to output all the thunks with the function itself. */
5608 61539657 : if (DECL_VIRTUAL_P (fn)
5609 : /* Do not emit thunks for extern template instantiations. */
5610 1170495 : && ! DECL_REALLY_EXTERN (fn)
5611 : /* Do not emit thunks for tentative decls, those will be processed
5612 : again at_eof if really needed. */
5613 62593633 : && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
5614 : {
5615 1052881 : tree thunk;
5616 :
5617 1057303 : for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
5618 : {
5619 4422 : if (!THUNK_ALIAS (thunk))
5620 : {
5621 4422 : use_thunk (thunk, /*emit_p=*/1);
5622 4422 : if (DECL_RESULT_THUNK_P (thunk))
5623 : {
5624 181 : tree probe;
5625 :
5626 181 : for (probe = DECL_THUNKS (thunk);
5627 333 : probe; probe = DECL_CHAIN (probe))
5628 152 : use_thunk (probe, /*emit_p=*/1);
5629 : }
5630 : }
5631 : else
5632 0 : gcc_assert (!DECL_THUNKS (thunk));
5633 : }
5634 : }
5635 61539657 : }
5636 :
5637 : /* Generate RTL for FN. */
5638 :
5639 : bool
5640 167217516 : expand_or_defer_fn_1 (tree fn)
5641 : {
5642 : /* When the parser calls us after finishing the body of a template
5643 : function, we don't really want to expand the body. */
5644 167217516 : if (processing_template_decl)
5645 : {
5646 : /* Normally, collection only occurs in rest_of_compilation. So,
5647 : if we don't collect here, we never collect junk generated
5648 : during the processing of templates until we hit a
5649 : non-template function. It's not safe to do this inside a
5650 : nested class, though, as the parser may have local state that
5651 : is not a GC root. */
5652 97453533 : if (!function_depth)
5653 96989554 : ggc_collect ();
5654 : return false;
5655 : }
5656 :
5657 69763983 : gcc_assert (DECL_SAVED_TREE (fn));
5658 :
5659 : /* We make a decision about linkage for these functions at the end
5660 : of the compilation. Until that point, we do not want the back
5661 : end to output them -- but we do want it to see the bodies of
5662 : these functions so that it can inline them as appropriate. */
5663 69763983 : if (DECL_DECLARED_INLINE_P (fn)
5664 1958069 : || DECL_IMPLICIT_INSTANTIATION (fn)
5665 70027709 : || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (fn))
5666 : {
5667 69500284 : if (DECL_INTERFACE_KNOWN (fn))
5668 : /* We've already made a decision as to how this function will
5669 : be handled. */;
5670 49167769 : else if (!at_eof
5671 17726895 : || DECL_IMMEDIATE_FUNCTION_P (fn)
5672 66424249 : || DECL_OMP_DECLARE_REDUCTION_P (fn))
5673 31911289 : tentative_decl_linkage (fn);
5674 : else
5675 17256480 : import_export_decl (fn);
5676 :
5677 : /* If the user wants us to keep all inline functions, then mark
5678 : this function as needed so that finish_file will make sure to
5679 : output it later. Similarly, all dllexport'd functions must
5680 : be emitted; there may be callers in other DLLs. */
5681 69500284 : if (DECL_DECLARED_INLINE_P (fn)
5682 67805914 : && !DECL_REALLY_EXTERN (fn)
5683 64053983 : && !DECL_IMMEDIATE_FUNCTION_P (fn)
5684 62919383 : && !DECL_OMP_DECLARE_REDUCTION_P (fn)
5685 132419667 : && (flag_keep_inline_functions
5686 62916593 : || (flag_keep_inline_dllexport
5687 62916593 : && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
5688 : {
5689 2790 : mark_needed (fn);
5690 2790 : DECL_EXTERNAL (fn) = 0;
5691 : }
5692 : }
5693 :
5694 : /* If this is a constructor or destructor body, we have to clone
5695 : it. */
5696 69763983 : if (maybe_clone_body (fn))
5697 : {
5698 : /* We don't want to process FN again, so pretend we've written
5699 : it out, even though we haven't. */
5700 8196126 : TREE_ASM_WRITTEN (fn) = 1;
5701 : /* If this is a constexpr function we still need the body to be
5702 : able to evaluate it. Similarly, with modules we only stream
5703 : the maybe-in-charge cdtor and regenerate the clones from it on
5704 : demand, so we also need to keep the body. Otherwise we don't
5705 : need it anymore. */
5706 8196126 : if (!maybe_constexpr_fn (fn)
5707 8196126 : && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
5708 3836602 : DECL_SAVED_TREE (fn) = void_node;
5709 : return false;
5710 : }
5711 :
5712 : /* There's no reason to do any of the work here if we're only doing
5713 : semantic analysis; this code just generates RTL. */
5714 61567857 : if (flag_syntax_only)
5715 : {
5716 : /* Pretend that this function has been written out so that we don't try
5717 : to expand it again. */
5718 28184 : TREE_ASM_WRITTEN (fn) = 1;
5719 28184 : return false;
5720 : }
5721 :
5722 61539673 : if (DECL_OMP_DECLARE_REDUCTION_P (fn))
5723 16 : return false;
5724 :
5725 : return true;
5726 : }
5727 :
5728 : void
5729 159047430 : expand_or_defer_fn (tree fn)
5730 : {
5731 159047430 : if (expand_or_defer_fn_1 (fn))
5732 : {
5733 53372062 : function_depth++;
5734 :
5735 : /* Expand or defer, at the whim of the compilation unit manager. */
5736 53372062 : cgraph_node::finalize_function (fn, function_depth > 1);
5737 53372062 : emit_associated_thunks (fn);
5738 :
5739 53372062 : function_depth--;
5740 :
5741 106744124 : if (DECL_IMMEDIATE_FUNCTION_P (fn))
5742 : {
5743 1073244 : if (cgraph_node *node = cgraph_node::get (fn))
5744 : {
5745 1073244 : node->body_removed = true;
5746 1073244 : node->analyzed = false;
5747 1073244 : node->definition = false;
5748 1073244 : node->force_output = false;
5749 : }
5750 : }
5751 : }
5752 159047430 : }
5753 :
5754 467626 : class nrv_data
5755 : {
5756 : public:
5757 233813 : nrv_data () : visited (37) {}
5758 :
5759 : tree var;
5760 : tree result;
5761 : hash_set<tree> visited;
5762 : bool simple;
5763 : bool in_nrv_cleanup;
5764 : };
5765 :
5766 : /* Helper function for walk_tree, used by finalize_nrv below. */
5767 :
5768 : static tree
5769 21201570 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
5770 : {
5771 21201570 : class nrv_data *dp = (class nrv_data *)data;
5772 :
5773 : /* No need to walk into types. There wouldn't be any need to walk into
5774 : non-statements, except that we have to consider STMT_EXPRs. */
5775 21201570 : if (TYPE_P (*tp))
5776 193090 : *walk_subtrees = 0;
5777 :
5778 : /* Replace all uses of the NRV with the RESULT_DECL. */
5779 21008480 : else if (*tp == dp->var)
5780 508115 : *tp = dp->result;
5781 :
5782 : /* Avoid walking into the same tree more than once. Unfortunately, we
5783 : can't just use walk_tree_without duplicates because it would only call
5784 : us for the first occurrence of dp->var in the function body. */
5785 20500365 : else if (dp->visited.add (*tp))
5786 4485506 : *walk_subtrees = 0;
5787 :
5788 : /* If there's a label, we might need to destroy the NRV on goto (92407). */
5789 16014859 : else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
5790 3 : dp->simple = false;
5791 : /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
5792 : but differs from using NULL_TREE in that it indicates that we care
5793 : about the value of the RESULT_DECL. But preserve anything appended
5794 : by check_return_expr. */
5795 16014856 : else if (TREE_CODE (*tp) == RETURN_EXPR)
5796 : {
5797 239993 : tree *p = &TREE_OPERAND (*tp, 0);
5798 615372 : while (TREE_CODE (*p) == COMPOUND_EXPR)
5799 135386 : p = &TREE_OPERAND (*p, 0);
5800 239993 : if (TREE_CODE (*p) == INIT_EXPR
5801 239993 : && INIT_EXPR_NRV_P (*p))
5802 239583 : *p = dp->result;
5803 : }
5804 : /* Change all cleanups for the NRV to only run when not returning. */
5805 15774863 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5806 15774863 : && CLEANUP_DECL (*tp) == dp->var)
5807 : {
5808 130270 : dp->in_nrv_cleanup = true;
5809 130270 : cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
5810 130270 : dp->in_nrv_cleanup = false;
5811 130270 : cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
5812 130270 : *walk_subtrees = 0;
5813 :
5814 130270 : if (dp->simple)
5815 : /* For a simple NRV, just run it on the EH path. */
5816 129607 : CLEANUP_EH_ONLY (*tp) = true;
5817 : else
5818 : {
5819 : /* Not simple, we need to check current_retval_sentinel to decide
5820 : whether to run it. If it's set, we're returning normally and
5821 : don't want to destroy the NRV. If the sentinel is not set, we're
5822 : leaving scope some other way, either by flowing off the end of its
5823 : scope or throwing an exception. */
5824 1989 : tree cond = build3 (COND_EXPR, void_type_node,
5825 663 : current_retval_sentinel,
5826 663 : void_node, CLEANUP_EXPR (*tp));
5827 663 : CLEANUP_EXPR (*tp) = cond;
5828 : }
5829 :
5830 : /* If a cleanup might throw, we need to clear current_retval_sentinel on
5831 : the exception path, both so the check above succeeds and so an outer
5832 : cleanup added by maybe_splice_retval_cleanup doesn't run. */
5833 130270 : if (cp_function_chain->throwing_cleanup)
5834 : {
5835 216 : tree clear = build2 (MODIFY_EXPR, boolean_type_node,
5836 : current_retval_sentinel,
5837 : boolean_false_node);
5838 216 : if (dp->simple)
5839 : {
5840 : /* We're already only on the EH path, just prepend it. */
5841 206 : tree &exp = CLEANUP_EXPR (*tp);
5842 206 : exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
5843 : }
5844 : else
5845 : {
5846 : /* The cleanup runs on both normal and EH paths, we need another
5847 : CLEANUP_STMT to clear the flag only on the EH path. */
5848 10 : tree &bod = CLEANUP_BODY (*tp);
5849 10 : bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
5850 10 : bod, clear, current_retval_sentinel);
5851 10 : CLEANUP_EH_ONLY (bod) = true;
5852 : }
5853 : }
5854 : }
5855 : /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
5856 : want to destroy the retval before the variable goes out of scope. */
5857 15644593 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5858 5169 : && dp->in_nrv_cleanup
5859 15648327 : && CLEANUP_DECL (*tp) == dp->result)
5860 6 : CLEANUP_EXPR (*tp) = void_node;
5861 : /* Replace the DECL_EXPR for the NRV with an initialization of the
5862 : RESULT_DECL, if needed. */
5863 15644587 : else if (TREE_CODE (*tp) == DECL_EXPR
5864 15644587 : && DECL_EXPR_DECL (*tp) == dp->var)
5865 : {
5866 233815 : tree init;
5867 233815 : if (DECL_INITIAL (dp->var)
5868 233815 : && DECL_INITIAL (dp->var) != error_mark_node)
5869 95728 : init = cp_build_init_expr (dp->result,
5870 95728 : DECL_INITIAL (dp->var));
5871 : else
5872 138087 : init = build_empty_stmt (EXPR_LOCATION (*tp));
5873 233815 : DECL_INITIAL (dp->var) = NULL_TREE;
5874 233815 : SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
5875 233815 : *tp = init;
5876 : }
5877 :
5878 : /* Keep iterating. */
5879 21201570 : return NULL_TREE;
5880 : }
5881 :
5882 : /* Called from finish_function to implement the named return value
5883 : optimization by overriding all the RETURN_EXPRs and pertinent
5884 : CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5885 : RESULT_DECL for the function. */
5886 :
5887 : void
5888 233813 : finalize_nrv (tree fndecl, tree var)
5889 : {
5890 233813 : class nrv_data data;
5891 233813 : tree result = DECL_RESULT (fndecl);
5892 :
5893 : /* Copy name from VAR to RESULT. */
5894 233813 : DECL_NAME (result) = DECL_NAME (var);
5895 : /* Don't forget that we take its address. */
5896 233813 : TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
5897 : /* Finally set DECL_VALUE_EXPR to avoid assigning
5898 : a stack slot at -O0 for the original var and debug info
5899 : uses RESULT location for VAR. */
5900 233813 : SET_DECL_VALUE_EXPR (var, result);
5901 233813 : DECL_HAS_VALUE_EXPR_P (var) = 1;
5902 :
5903 233813 : data.var = var;
5904 233813 : data.result = result;
5905 233813 : data.in_nrv_cleanup = false;
5906 :
5907 : /* This is simpler for variables declared in the outer scope of
5908 : the function so we know that their lifetime always ends with a
5909 : return; see g++.dg/opt/nrv6.C. */
5910 233813 : tree outer = outer_curly_brace_block (fndecl);
5911 233813 : data.simple = chain_member (var, BLOCK_VARS (outer));
5912 :
5913 233813 : cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
5914 233813 : }
5915 :
5916 : /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5917 :
5918 : bool
5919 2249 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
5920 : bool need_copy_ctor, bool need_copy_assignment,
5921 : bool need_dtor)
5922 : {
5923 2249 : int save_errorcount = errorcount;
5924 2249 : tree info, t;
5925 :
5926 : /* Always allocate 3 elements for simplicity. These are the
5927 : function decls for the ctor, dtor, and assignment op.
5928 : This layout is known to the three lang hooks,
5929 : cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
5930 : and cxx_omp_clause_assign_op. */
5931 2249 : info = make_tree_vec (3);
5932 2249 : CP_OMP_CLAUSE_INFO (c) = info;
5933 :
5934 2249 : if (need_default_ctor || need_copy_ctor)
5935 : {
5936 1654 : if (need_default_ctor)
5937 1255 : t = get_default_ctor (type);
5938 : else
5939 399 : t = get_copy_ctor (type, tf_warning_or_error);
5940 :
5941 1654 : if (t && !trivial_fn_p (t))
5942 1400 : TREE_VEC_ELT (info, 0) = t;
5943 : }
5944 :
5945 2249 : if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
5946 1632 : TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
5947 :
5948 2249 : if (need_copy_assignment)
5949 : {
5950 397 : t = get_copy_assign (type);
5951 :
5952 397 : if (t && !trivial_fn_p (t))
5953 344 : TREE_VEC_ELT (info, 2) = t;
5954 : }
5955 :
5956 2249 : return errorcount != save_errorcount;
5957 : }
5958 :
5959 : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
5960 : FIELD_DECL, otherwise return DECL itself. */
5961 :
5962 : static tree
5963 26714 : omp_clause_decl_field (tree decl)
5964 : {
5965 26714 : if (VAR_P (decl)
5966 18651 : && DECL_HAS_VALUE_EXPR_P (decl)
5967 359 : && DECL_ARTIFICIAL (decl)
5968 359 : && DECL_LANG_SPECIFIC (decl)
5969 27049 : && DECL_OMP_PRIVATIZED_MEMBER (decl))
5970 : {
5971 328 : tree f = DECL_VALUE_EXPR (decl);
5972 328 : if (INDIRECT_REF_P (f))
5973 0 : f = TREE_OPERAND (f, 0);
5974 328 : if (TREE_CODE (f) == COMPONENT_REF)
5975 : {
5976 328 : f = TREE_OPERAND (f, 1);
5977 328 : gcc_assert (TREE_CODE (f) == FIELD_DECL);
5978 : return f;
5979 : }
5980 : }
5981 : return NULL_TREE;
5982 : }
5983 :
5984 : /* Adjust DECL if needed for printing using %qE. */
5985 :
5986 : static tree
5987 187 : omp_clause_printable_decl (tree decl)
5988 : {
5989 0 : tree t = omp_clause_decl_field (decl);
5990 187 : if (t)
5991 45 : return t;
5992 : return decl;
5993 : }
5994 :
5995 : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
5996 : VAR_DECL T that doesn't need a DECL_EXPR added, record it for
5997 : privatization. */
5998 :
5999 : static void
6000 219 : omp_note_field_privatization (tree f, tree t)
6001 : {
6002 219 : if (!omp_private_member_map)
6003 71 : omp_private_member_map = new hash_map<tree, tree>;
6004 219 : tree &v = omp_private_member_map->get_or_insert (f);
6005 219 : if (v == NULL_TREE)
6006 : {
6007 146 : v = t;
6008 146 : omp_private_member_vec.safe_push (f);
6009 : /* Signal that we don't want to create DECL_EXPR for this dummy var. */
6010 146 : omp_private_member_vec.safe_push (integer_zero_node);
6011 : }
6012 219 : }
6013 :
6014 : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
6015 : dummy VAR_DECL. */
6016 :
6017 : tree
6018 861 : omp_privatize_field (tree t, bool shared)
6019 : {
6020 861 : tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6021 861 : if (m == error_mark_node)
6022 : return error_mark_node;
6023 861 : if (!omp_private_member_map && !shared)
6024 365 : omp_private_member_map = new hash_map<tree, tree>;
6025 861 : if (TYPE_REF_P (TREE_TYPE (t)))
6026 : {
6027 123 : gcc_assert (INDIRECT_REF_P (m));
6028 123 : m = TREE_OPERAND (m, 0);
6029 : }
6030 861 : tree vb = NULL_TREE;
6031 861 : tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
6032 861 : if (v == NULL_TREE)
6033 : {
6034 770 : v = create_temporary_var (TREE_TYPE (m));
6035 770 : retrofit_lang_decl (v);
6036 770 : DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
6037 770 : SET_DECL_VALUE_EXPR (v, m);
6038 770 : DECL_HAS_VALUE_EXPR_P (v) = 1;
6039 770 : if (!shared)
6040 690 : omp_private_member_vec.safe_push (t);
6041 : }
6042 861 : return v;
6043 : }
6044 :
6045 : /* C++ specialisation of the c_omp_address_inspector class. */
6046 :
6047 : class cp_omp_address_inspector : public c_omp_address_inspector
6048 : {
6049 : public:
6050 31536 : cp_omp_address_inspector (location_t loc, tree t)
6051 31536 : : c_omp_address_inspector (loc, t)
6052 : {
6053 : }
6054 :
6055 31536 : ~cp_omp_address_inspector ()
6056 : {
6057 23100 : }
6058 :
6059 134667 : bool processing_template_decl_p ()
6060 : {
6061 134667 : return processing_template_decl;
6062 : }
6063 :
6064 0 : void emit_unmappable_type_notes (tree t)
6065 : {
6066 0 : if (TREE_TYPE (t) != error_mark_node
6067 0 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
6068 0 : cxx_incomplete_type_inform (TREE_TYPE (t));
6069 0 : }
6070 :
6071 1062 : tree convert_from_reference (tree x)
6072 : {
6073 1062 : return ::convert_from_reference (x);
6074 : }
6075 :
6076 147 : tree build_array_ref (location_t loc, tree arr, tree idx)
6077 : {
6078 147 : return ::build_array_ref (loc, arr, idx);
6079 : }
6080 :
6081 23042 : bool check_clause (tree clause)
6082 : {
6083 23042 : if (TREE_CODE (orig) == COMPONENT_REF
6084 23042 : && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
6085 : tf_warning_or_error))
6086 : return false;
6087 23039 : if (!c_omp_address_inspector::check_clause (clause))
6088 : return false;
6089 : return true;
6090 : }
6091 : };
6092 :
6093 : /* Helper function for handle_omp_array_sections. Called recursively
6094 : to handle multiple array-section-subscripts. C is the clause,
6095 : T current expression (initially OMP_CLAUSE_DECL), which is either
6096 : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
6097 : expression if specified, TREE_VALUE length expression if specified,
6098 : TREE_CHAIN is what it has been specified after, or some decl.
6099 : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
6100 : set to true if any of the array-section-subscript could have length
6101 : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
6102 : first array-section-subscript which is known not to have length
6103 : of one. Given say:
6104 : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
6105 : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
6106 : all are or may have length of 1, array-section-subscript [:2] is the
6107 : first one known not to have length 1. For array-section-subscript
6108 : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
6109 : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
6110 : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
6111 : case though, as some lengths could be zero. */
6112 :
6113 : static tree
6114 21494 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
6115 : bool &maybe_zero_len, unsigned int &first_non_one,
6116 : enum c_omp_region_type ort)
6117 : {
6118 21494 : tree ret, low_bound, length, type;
6119 21494 : bool openacc = (ort & C_ORT_ACC) != 0;
6120 21494 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
6121 : {
6122 9708 : if (error_operand_p (t))
6123 6 : return error_mark_node;
6124 :
6125 9702 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6126 9702 : tree t_refto = ai.maybe_unconvert_ref (t);
6127 :
6128 9702 : if (!ai.check_clause (c))
6129 0 : return error_mark_node;
6130 9702 : else if (ai.component_access_p ()
6131 11090 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6132 64 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
6133 40 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
6134 1388 : t = ai.get_root_term (true);
6135 : else
6136 8314 : t = ai.unconverted_ref_origin ();
6137 9702 : if (t == error_mark_node)
6138 : return error_mark_node;
6139 9702 : ret = t_refto;
6140 9702 : if (TREE_CODE (t) == FIELD_DECL)
6141 33 : ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6142 9669 : else if (!VAR_P (t)
6143 2861 : && (openacc || !EXPR_P (t))
6144 2666 : && TREE_CODE (t) != PARM_DECL)
6145 : {
6146 51 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6147 : return NULL_TREE;
6148 33 : if (DECL_P (t))
6149 33 : error_at (OMP_CLAUSE_LOCATION (c),
6150 : "%qD is not a variable in %qs clause", t,
6151 33 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6152 : else
6153 0 : error_at (OMP_CLAUSE_LOCATION (c),
6154 : "%qE is not a variable in %qs clause", t,
6155 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6156 33 : return error_mark_node;
6157 : }
6158 9618 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6159 9227 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6160 17916 : && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
6161 : {
6162 18 : error_at (OMP_CLAUSE_LOCATION (c),
6163 : "%qD is threadprivate variable in %qs clause", t,
6164 18 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6165 18 : return error_mark_node;
6166 : }
6167 9633 : if (type_dependent_expression_p (ret))
6168 : return NULL_TREE;
6169 8922 : ret = convert_from_reference (ret);
6170 8922 : return ret;
6171 9702 : }
6172 :
6173 11786 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
6174 7859 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6175 6557 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6176 5273 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6177 14500 : && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
6178 43 : TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
6179 11786 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
6180 : maybe_zero_len, first_non_one, ort);
6181 11786 : if (ret == error_mark_node || ret == NULL_TREE)
6182 : return ret;
6183 :
6184 10716 : type = TREE_TYPE (ret);
6185 10716 : low_bound = TREE_OPERAND (t, 1);
6186 10716 : length = TREE_OPERAND (t, 2);
6187 8597 : if ((low_bound && type_dependent_expression_p (low_bound))
6188 19230 : || (length && type_dependent_expression_p (length)))
6189 : return NULL_TREE;
6190 :
6191 10628 : if (low_bound == error_mark_node || length == error_mark_node)
6192 : return error_mark_node;
6193 :
6194 10616 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
6195 : {
6196 75 : error_at (OMP_CLAUSE_LOCATION (c),
6197 : "low bound %qE of array section does not have integral type",
6198 : low_bound);
6199 75 : return error_mark_node;
6200 : }
6201 10541 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
6202 : {
6203 75 : error_at (OMP_CLAUSE_LOCATION (c),
6204 : "length %qE of array section does not have integral type",
6205 : length);
6206 75 : return error_mark_node;
6207 : }
6208 10466 : if (low_bound)
6209 8413 : low_bound = mark_rvalue_use (low_bound);
6210 10466 : if (length)
6211 9403 : length = mark_rvalue_use (length);
6212 : /* We need to reduce to real constant-values for checks below. */
6213 9403 : if (length)
6214 9403 : length = fold_simple (length);
6215 10466 : if (low_bound)
6216 8413 : low_bound = fold_simple (low_bound);
6217 8413 : if (low_bound
6218 8413 : && TREE_CODE (low_bound) == INTEGER_CST
6219 15889 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6220 7476 : > TYPE_PRECISION (sizetype))
6221 0 : low_bound = fold_convert (sizetype, low_bound);
6222 10466 : if (length
6223 9403 : && TREE_CODE (length) == INTEGER_CST
6224 17846 : && TYPE_PRECISION (TREE_TYPE (length))
6225 7380 : > TYPE_PRECISION (sizetype))
6226 0 : length = fold_convert (sizetype, length);
6227 10466 : if (low_bound == NULL_TREE)
6228 2053 : low_bound = integer_zero_node;
6229 :
6230 10466 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6231 10466 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
6232 5167 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
6233 : {
6234 60 : if (length != integer_one_node)
6235 : {
6236 36 : error_at (OMP_CLAUSE_LOCATION (c),
6237 : "expected single pointer in %qs clause",
6238 : user_omp_clause_code_name (c, openacc));
6239 36 : return error_mark_node;
6240 : }
6241 : }
6242 10430 : if (length != NULL_TREE)
6243 : {
6244 9391 : if (!integer_nonzerop (length))
6245 : {
6246 2078 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6247 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6248 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6249 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6250 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6251 : {
6252 479 : if (integer_zerop (length))
6253 : {
6254 36 : error_at (OMP_CLAUSE_LOCATION (c),
6255 : "zero length array section in %qs clause",
6256 36 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6257 36 : return error_mark_node;
6258 : }
6259 : }
6260 : else
6261 1599 : maybe_zero_len = true;
6262 : }
6263 9355 : if (first_non_one == types.length ()
6264 9355 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
6265 3989 : first_non_one++;
6266 : }
6267 10394 : if (TREE_CODE (type) == ARRAY_TYPE)
6268 : {
6269 5796 : if (length == NULL_TREE
6270 5796 : && (TYPE_DOMAIN (type) == NULL_TREE
6271 955 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
6272 : {
6273 33 : error_at (OMP_CLAUSE_LOCATION (c),
6274 : "for unknown bound array type length expression must "
6275 : "be specified");
6276 33 : return error_mark_node;
6277 : }
6278 5763 : if (TREE_CODE (low_bound) == INTEGER_CST
6279 5763 : && tree_int_cst_sgn (low_bound) == -1)
6280 : {
6281 177 : error_at (OMP_CLAUSE_LOCATION (c),
6282 : "negative low bound in array section in %qs clause",
6283 177 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6284 177 : return error_mark_node;
6285 : }
6286 5586 : if (length != NULL_TREE
6287 4688 : && TREE_CODE (length) == INTEGER_CST
6288 9348 : && tree_int_cst_sgn (length) == -1)
6289 : {
6290 177 : error_at (OMP_CLAUSE_LOCATION (c),
6291 : "negative length in array section in %qs clause",
6292 177 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6293 177 : return error_mark_node;
6294 : }
6295 5409 : if (TYPE_DOMAIN (type)
6296 5310 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6297 10719 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
6298 : == INTEGER_CST)
6299 : {
6300 4914 : tree size
6301 4914 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6302 4914 : size = size_binop (PLUS_EXPR, size, size_one_node);
6303 4914 : if (TREE_CODE (low_bound) == INTEGER_CST)
6304 : {
6305 4137 : if (tree_int_cst_lt (size, low_bound))
6306 : {
6307 63 : error_at (OMP_CLAUSE_LOCATION (c),
6308 : "low bound %qE above array section size "
6309 : "in %qs clause", low_bound,
6310 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6311 63 : return error_mark_node;
6312 : }
6313 4074 : if (tree_int_cst_equal (size, low_bound))
6314 : {
6315 21 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6316 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6317 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6318 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6319 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6320 : {
6321 21 : error_at (OMP_CLAUSE_LOCATION (c),
6322 : "zero length array section in %qs clause",
6323 21 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6324 21 : return error_mark_node;
6325 : }
6326 0 : maybe_zero_len = true;
6327 : }
6328 4053 : else if (length == NULL_TREE
6329 1578 : && first_non_one == types.length ()
6330 4406 : && tree_int_cst_equal
6331 353 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6332 : low_bound))
6333 207 : first_non_one++;
6334 : }
6335 777 : else if (length == NULL_TREE)
6336 : {
6337 24 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6338 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6339 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6340 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6341 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6342 13 : maybe_zero_len = true;
6343 48 : if (first_non_one == types.length ())
6344 21 : first_non_one++;
6345 : }
6346 4830 : if (length && TREE_CODE (length) == INTEGER_CST)
6347 : {
6348 3465 : if (tree_int_cst_lt (size, length))
6349 : {
6350 63 : error_at (OMP_CLAUSE_LOCATION (c),
6351 : "length %qE above array section size "
6352 : "in %qs clause", length,
6353 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6354 63 : return error_mark_node;
6355 : }
6356 3402 : if (TREE_CODE (low_bound) == INTEGER_CST)
6357 : {
6358 3064 : tree lbpluslen
6359 3064 : = size_binop (PLUS_EXPR,
6360 : fold_convert (sizetype, low_bound),
6361 : fold_convert (sizetype, length));
6362 3064 : if (TREE_CODE (lbpluslen) == INTEGER_CST
6363 3064 : && tree_int_cst_lt (size, lbpluslen))
6364 : {
6365 60 : error_at (OMP_CLAUSE_LOCATION (c),
6366 : "high bound %qE above array section size "
6367 : "in %qs clause", lbpluslen,
6368 60 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6369 60 : return error_mark_node;
6370 : }
6371 : }
6372 : }
6373 : }
6374 495 : else if (length == NULL_TREE)
6375 : {
6376 1 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6377 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6378 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6379 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6380 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6381 0 : maybe_zero_len = true;
6382 2 : if (first_non_one == types.length ())
6383 1 : first_non_one++;
6384 : }
6385 :
6386 : /* For [lb:] we will need to evaluate lb more than once. */
6387 4157 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6388 : {
6389 733 : tree lb = cp_save_expr (low_bound);
6390 733 : if (lb != low_bound)
6391 : {
6392 11 : TREE_OPERAND (t, 1) = lb;
6393 11 : low_bound = lb;
6394 : }
6395 : }
6396 : }
6397 4598 : else if (TYPE_PTR_P (type))
6398 : {
6399 4538 : if (length == NULL_TREE)
6400 : {
6401 51 : if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
6402 45 : error_at (OMP_CLAUSE_LOCATION (c),
6403 : "for array function parameter length expression "
6404 : "must be specified");
6405 : else
6406 6 : error_at (OMP_CLAUSE_LOCATION (c),
6407 : "for pointer type length expression must be specified");
6408 51 : return error_mark_node;
6409 : }
6410 4487 : if (length != NULL_TREE
6411 4487 : && TREE_CODE (length) == INTEGER_CST
6412 3390 : && tree_int_cst_sgn (length) == -1)
6413 : {
6414 96 : error_at (OMP_CLAUSE_LOCATION (c),
6415 : "negative length in array section in %qs clause",
6416 96 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6417 96 : return error_mark_node;
6418 : }
6419 : /* If there is a pointer type anywhere but in the very first
6420 : array-section-subscript, the array section could be non-contiguous. */
6421 4391 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6422 4289 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6423 8195 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
6424 : {
6425 : /* If any prior dimension has a non-one length, then deem this
6426 : array section as non-contiguous. */
6427 159 : for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
6428 69 : d = TREE_OPERAND (d, 0))
6429 : {
6430 90 : tree d_length = TREE_OPERAND (d, 2);
6431 90 : if (d_length == NULL_TREE || !integer_onep (d_length))
6432 : {
6433 21 : error_at (OMP_CLAUSE_LOCATION (c),
6434 : "array section is not contiguous in %qs clause",
6435 21 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6436 21 : return error_mark_node;
6437 : }
6438 : }
6439 : }
6440 : }
6441 : else
6442 : {
6443 60 : error_at (OMP_CLAUSE_LOCATION (c),
6444 : "%qE does not have pointer or array type", ret);
6445 60 : return error_mark_node;
6446 : }
6447 9572 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6448 8667 : types.safe_push (TREE_TYPE (ret));
6449 : /* We will need to evaluate lb more than once. */
6450 9572 : tree lb = cp_save_expr (low_bound);
6451 9572 : if (lb != low_bound)
6452 : {
6453 720 : TREE_OPERAND (t, 1) = lb;
6454 720 : low_bound = lb;
6455 : }
6456 : /* Temporarily disable -fstrong-eval-order for array reductions.
6457 : The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
6458 : is something the middle-end can't cope with and more importantly,
6459 : it needs to be the actual base variable that is privatized, not some
6460 : temporary assigned previous value of it. That, together with OpenMP
6461 : saying how many times the side-effects are evaluated is unspecified,
6462 : makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
6463 9572 : warning_sentinel s (flag_strong_eval_order,
6464 9572 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6465 8475 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6466 16913 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
6467 9572 : ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
6468 : tf_warning_or_error);
6469 9572 : return ret;
6470 9572 : }
6471 :
6472 : /* Handle array sections for clause C. */
6473 :
6474 : static bool
6475 9708 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
6476 : {
6477 9708 : bool maybe_zero_len = false;
6478 9708 : unsigned int first_non_one = 0;
6479 9708 : auto_vec<tree, 10> types;
6480 9708 : tree *tp = &OMP_CLAUSE_DECL (c);
6481 9708 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6482 8749 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6483 10117 : && OMP_ITERATOR_DECL_P (*tp))
6484 258 : tp = &TREE_VALUE (*tp);
6485 9708 : tree first = handle_omp_array_sections_1 (c, *tp, types,
6486 : maybe_zero_len, first_non_one,
6487 : ort);
6488 9708 : if (first == error_mark_node)
6489 : return true;
6490 8595 : if (first == NULL_TREE)
6491 : return false;
6492 7778 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6493 7778 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6494 : {
6495 951 : tree t = *tp;
6496 951 : tree tem = NULL_TREE;
6497 951 : if (processing_template_decl)
6498 : return false;
6499 : /* Need to evaluate side effects in the length expressions
6500 : if any. */
6501 852 : while (TREE_CODE (t) == TREE_LIST)
6502 : {
6503 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
6504 : {
6505 0 : if (tem == NULL_TREE)
6506 : tem = TREE_VALUE (t);
6507 : else
6508 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
6509 0 : TREE_VALUE (t), tem);
6510 : }
6511 0 : t = TREE_CHAIN (t);
6512 : }
6513 852 : if (tem)
6514 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
6515 852 : *tp = first;
6516 : }
6517 : else
6518 : {
6519 6827 : unsigned int num = types.length (), i;
6520 6827 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
6521 6827 : tree condition = NULL_TREE;
6522 :
6523 6827 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
6524 3 : maybe_zero_len = true;
6525 6827 : if (processing_template_decl && maybe_zero_len)
6526 : return false;
6527 :
6528 14362 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
6529 7613 : t = TREE_OPERAND (t, 0))
6530 : {
6531 7688 : gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
6532 :
6533 7688 : tree low_bound = TREE_OPERAND (t, 1);
6534 7688 : tree length = TREE_OPERAND (t, 2);
6535 :
6536 7688 : i--;
6537 7688 : if (low_bound
6538 6242 : && TREE_CODE (low_bound) == INTEGER_CST
6539 13319 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6540 5631 : > TYPE_PRECISION (sizetype))
6541 0 : low_bound = fold_convert (sizetype, low_bound);
6542 7688 : if (length
6543 7139 : && TREE_CODE (length) == INTEGER_CST
6544 12935 : && TYPE_PRECISION (TREE_TYPE (length))
6545 5247 : > TYPE_PRECISION (sizetype))
6546 0 : length = fold_convert (sizetype, length);
6547 7688 : if (low_bound == NULL_TREE)
6548 1446 : low_bound = integer_zero_node;
6549 7688 : if (!maybe_zero_len && i > first_non_one)
6550 : {
6551 646 : if (integer_nonzerop (low_bound))
6552 36 : goto do_warn_noncontiguous;
6553 610 : if (length != NULL_TREE
6554 282 : && TREE_CODE (length) == INTEGER_CST
6555 282 : && TYPE_DOMAIN (types[i])
6556 282 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
6557 892 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
6558 : == INTEGER_CST)
6559 : {
6560 282 : tree size;
6561 282 : size = size_binop (PLUS_EXPR,
6562 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6563 : size_one_node);
6564 282 : if (!tree_int_cst_equal (length, size))
6565 : {
6566 39 : do_warn_noncontiguous:
6567 150 : error_at (OMP_CLAUSE_LOCATION (c),
6568 : "array section is not contiguous in %qs "
6569 : "clause",
6570 75 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6571 75 : return true;
6572 : }
6573 : }
6574 571 : if (!processing_template_decl
6575 401 : && length != NULL_TREE
6576 742 : && TREE_SIDE_EFFECTS (length))
6577 : {
6578 0 : if (side_effects == NULL_TREE)
6579 : side_effects = length;
6580 : else
6581 0 : side_effects = build2 (COMPOUND_EXPR,
6582 0 : TREE_TYPE (side_effects),
6583 : length, side_effects);
6584 : }
6585 : }
6586 7042 : else if (processing_template_decl)
6587 726 : continue;
6588 : else
6589 : {
6590 6316 : tree l;
6591 :
6592 6316 : if (i > first_non_one
6593 6316 : && ((length && integer_nonzerop (length))
6594 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6595 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6596 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
6597 0 : continue;
6598 6316 : if (length)
6599 6177 : l = fold_convert (sizetype, length);
6600 : else
6601 : {
6602 139 : l = size_binop (PLUS_EXPR,
6603 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6604 : size_one_node);
6605 139 : l = size_binop (MINUS_EXPR, l,
6606 : fold_convert (sizetype, low_bound));
6607 : }
6608 6316 : if (i > first_non_one)
6609 : {
6610 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
6611 : size_zero_node);
6612 0 : if (condition == NULL_TREE)
6613 : condition = l;
6614 : else
6615 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
6616 : l, condition);
6617 : }
6618 6316 : else if (size == NULL_TREE)
6619 : {
6620 6029 : size = size_in_bytes (TREE_TYPE (types[i]));
6621 6029 : tree eltype = TREE_TYPE (types[num - 1]);
6622 6100 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6623 71 : eltype = TREE_TYPE (eltype);
6624 6029 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6625 5219 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6626 10495 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6627 1659 : size = size_binop (EXACT_DIV_EXPR, size,
6628 : size_in_bytes (eltype));
6629 6029 : size = size_binop (MULT_EXPR, size, l);
6630 6029 : if (condition)
6631 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
6632 : size, size_zero_node);
6633 : }
6634 : else
6635 287 : size = size_binop (MULT_EXPR, size, l);
6636 : }
6637 : }
6638 6674 : if (!processing_template_decl)
6639 : {
6640 6029 : if (side_effects)
6641 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
6642 6029 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6643 5219 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6644 10495 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6645 : {
6646 1659 : size = size_binop (MINUS_EXPR, size, size_one_node);
6647 1659 : size = save_expr (size);
6648 1659 : tree index_type = build_index_type (size);
6649 1659 : tree eltype = TREE_TYPE (first);
6650 1688 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6651 29 : eltype = TREE_TYPE (eltype);
6652 1659 : tree type = build_array_type (eltype, index_type);
6653 1659 : tree ptype = build_pointer_type (eltype);
6654 1659 : if (TYPE_REF_P (TREE_TYPE (t))
6655 1659 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
6656 170 : t = convert_from_reference (t);
6657 1489 : else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6658 641 : t = build_fold_addr_expr (t);
6659 1659 : tree t2 = build_fold_addr_expr (first);
6660 1659 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6661 : ptrdiff_type_node, t2);
6662 1659 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
6663 : ptrdiff_type_node, t2,
6664 1659 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6665 : ptrdiff_type_node, t));
6666 1659 : if (tree_fits_shwi_p (t2))
6667 1321 : t = build2 (MEM_REF, type, t,
6668 1321 : build_int_cst (ptype, tree_to_shwi (t2)));
6669 : else
6670 : {
6671 338 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6672 : sizetype, t2);
6673 338 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
6674 338 : TREE_TYPE (t), t, t2);
6675 338 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
6676 : }
6677 1659 : OMP_CLAUSE_DECL (c) = t;
6678 6029 : return false;
6679 : }
6680 4370 : OMP_CLAUSE_DECL (c) = first;
6681 4370 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
6682 : return false;
6683 4344 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
6684 4344 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
6685 3787 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
6686 3775 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
6687 4320 : OMP_CLAUSE_SIZE (c) = size;
6688 4344 : if (TREE_CODE (t) == FIELD_DECL)
6689 3 : t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6690 :
6691 4344 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6692 : return false;
6693 :
6694 3799 : if (TREE_CODE (first) == INDIRECT_REF)
6695 : {
6696 : /* Detect and skip adding extra nodes for pointer-to-member
6697 : mappings. These are unsupported for now. */
6698 2413 : tree tmp = TREE_OPERAND (first, 0);
6699 :
6700 2413 : if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
6701 1915 : tmp = TREE_OPERAND (tmp, 0);
6702 :
6703 2413 : if (TREE_CODE (tmp) == INDIRECT_REF)
6704 158 : tmp = TREE_OPERAND (tmp, 0);
6705 :
6706 2413 : if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
6707 : {
6708 468 : tree offset = TREE_OPERAND (tmp, 1);
6709 468 : STRIP_NOPS (offset);
6710 468 : if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
6711 : {
6712 36 : sorry_at (OMP_CLAUSE_LOCATION (c),
6713 : "pointer-to-member mapping %qE not supported",
6714 18 : OMP_CLAUSE_DECL (c));
6715 18 : return true;
6716 : }
6717 : }
6718 : }
6719 :
6720 : /* FIRST represents the first item of data that we are mapping.
6721 : E.g. if we're mapping an array, FIRST might resemble
6722 : "foo.bar.myarray[0]". */
6723 :
6724 3781 : auto_vec<omp_addr_token *, 10> addr_tokens;
6725 :
6726 3781 : if (!omp_parse_expr (addr_tokens, first))
6727 : return true;
6728 :
6729 3781 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6730 :
6731 3781 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
6732 3781 : if (nc != error_mark_node)
6733 : {
6734 3781 : using namespace omp_addr_tokenizer;
6735 :
6736 3781 : if (ai.maybe_zero_length_array_section (c))
6737 3757 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
6738 :
6739 : /* !!! If we're accessing a base decl via chained access
6740 : methods (e.g. multiple indirections), duplicate clause
6741 : detection won't work properly. Skip it in that case. */
6742 3781 : if ((addr_tokens[0]->type == STRUCTURE_BASE
6743 2764 : || addr_tokens[0]->type == ARRAY_BASE)
6744 3781 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
6745 3770 : && addr_tokens[1]->type == ACCESS_METHOD
6746 7551 : && omp_access_chain_p (addr_tokens, 1))
6747 218 : c = nc;
6748 :
6749 3781 : return false;
6750 : }
6751 7562 : }
6752 : }
6753 : return false;
6754 9708 : }
6755 :
6756 : /* Return identifier to look up for omp declare reduction. */
6757 :
6758 : tree
6759 7113 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
6760 : {
6761 7113 : const char *p = NULL;
6762 7113 : const char *m = NULL;
6763 7113 : switch (reduction_code)
6764 : {
6765 4200 : case PLUS_EXPR:
6766 4200 : case MULT_EXPR:
6767 4200 : case MINUS_EXPR:
6768 4200 : case BIT_AND_EXPR:
6769 4200 : case BIT_XOR_EXPR:
6770 4200 : case BIT_IOR_EXPR:
6771 4200 : case TRUTH_ANDIF_EXPR:
6772 4200 : case TRUTH_ORIF_EXPR:
6773 4200 : reduction_id = ovl_op_identifier (false, reduction_code);
6774 4200 : break;
6775 : case MIN_EXPR:
6776 : p = "min";
6777 : break;
6778 : case MAX_EXPR:
6779 : p = "max";
6780 : break;
6781 : default:
6782 : break;
6783 : }
6784 :
6785 4200 : if (p == NULL)
6786 : {
6787 6949 : if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
6788 0 : return error_mark_node;
6789 6949 : p = IDENTIFIER_POINTER (reduction_id);
6790 : }
6791 :
6792 7113 : if (type != NULL_TREE)
6793 2047 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6794 :
6795 7113 : const char prefix[] = "omp declare reduction ";
6796 7113 : size_t lenp = sizeof (prefix);
6797 7113 : if (strncmp (p, prefix, lenp - 1) == 0)
6798 2047 : lenp = 1;
6799 7113 : size_t len = strlen (p);
6800 7113 : size_t lenm = m ? strlen (m) + 1 : 0;
6801 7113 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6802 7113 : if (lenp > 1)
6803 5066 : memcpy (name, prefix, lenp - 1);
6804 7113 : memcpy (name + lenp - 1, p, len + 1);
6805 7113 : if (m)
6806 : {
6807 2047 : name[lenp + len - 1] = '~';
6808 2047 : memcpy (name + lenp + len, m, lenm);
6809 : }
6810 7113 : return get_identifier (name);
6811 : }
6812 :
6813 : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
6814 : FUNCTION_DECL or NULL_TREE if not found. */
6815 :
6816 : static tree
6817 1298 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
6818 : vec<tree> *ambiguousp)
6819 : {
6820 1298 : tree orig_id = id;
6821 1298 : tree baselink = NULL_TREE;
6822 1298 : if (identifier_p (id))
6823 : {
6824 1270 : cp_id_kind idk;
6825 1270 : bool nonint_cst_expression_p;
6826 1270 : const char *error_msg;
6827 1270 : id = omp_reduction_id (ERROR_MARK, id, type);
6828 1270 : tree decl = lookup_name (id);
6829 1270 : if (decl == NULL_TREE)
6830 80 : decl = error_mark_node;
6831 1270 : id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
6832 : &nonint_cst_expression_p, false, true, false,
6833 : false, &error_msg, loc);
6834 1270 : if (idk == CP_ID_KIND_UNQUALIFIED
6835 1350 : && identifier_p (id))
6836 : {
6837 80 : vec<tree, va_gc> *args = NULL;
6838 80 : vec_safe_push (args, build_reference_type (type));
6839 80 : id = perform_koenig_lookup (id, args, tf_none);
6840 : }
6841 : }
6842 28 : else if (TREE_CODE (id) == SCOPE_REF)
6843 28 : id = lookup_qualified_name (TREE_OPERAND (id, 0),
6844 : omp_reduction_id (ERROR_MARK,
6845 28 : TREE_OPERAND (id, 1),
6846 : type),
6847 : LOOK_want::NORMAL, false);
6848 1298 : tree fns = id;
6849 1298 : id = NULL_TREE;
6850 1298 : if (fns && is_overloaded_fn (fns))
6851 : {
6852 1224 : for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
6853 : {
6854 1224 : tree fndecl = *iter;
6855 1224 : if (TREE_CODE (fndecl) == FUNCTION_DECL)
6856 : {
6857 1224 : tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
6858 1224 : if (same_type_p (TREE_TYPE (argtype), type))
6859 : {
6860 1224 : id = fndecl;
6861 1224 : break;
6862 : }
6863 : }
6864 : }
6865 :
6866 1224 : if (id && BASELINK_P (fns))
6867 : {
6868 74 : if (baselinkp)
6869 0 : *baselinkp = fns;
6870 : else
6871 74 : baselink = fns;
6872 : }
6873 : }
6874 :
6875 1298 : if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
6876 : {
6877 35 : auto_vec<tree> ambiguous;
6878 35 : tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
6879 35 : unsigned int ix;
6880 35 : if (ambiguousp == NULL)
6881 19 : ambiguousp = &ambiguous;
6882 73 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
6883 : {
6884 62 : id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
6885 : baselinkp ? baselinkp : &baselink,
6886 : ambiguousp);
6887 38 : if (id == NULL_TREE)
6888 14 : continue;
6889 24 : if (!ambiguousp->is_empty ())
6890 3 : ambiguousp->safe_push (id);
6891 21 : else if (ret != NULL_TREE)
6892 : {
6893 6 : ambiguousp->safe_push (ret);
6894 6 : ambiguousp->safe_push (id);
6895 6 : ret = NULL_TREE;
6896 : }
6897 : else
6898 15 : ret = id;
6899 : }
6900 35 : if (ambiguousp != &ambiguous)
6901 16 : return ret;
6902 19 : if (!ambiguous.is_empty ())
6903 : {
6904 6 : auto_diagnostic_group d;
6905 6 : const char *str = _("candidates are:");
6906 6 : unsigned int idx;
6907 6 : tree udr;
6908 6 : error_at (loc, "user defined reduction lookup is ambiguous");
6909 27 : FOR_EACH_VEC_ELT (ambiguous, idx, udr)
6910 : {
6911 15 : inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
6912 15 : if (idx == 0)
6913 6 : str = get_spaces (str);
6914 : }
6915 6 : ret = error_mark_node;
6916 6 : baselink = NULL_TREE;
6917 6 : }
6918 19 : id = ret;
6919 35 : }
6920 1282 : if (id && baselink)
6921 74 : perform_or_defer_access_check (BASELINK_BINFO (baselink),
6922 : id, id, tf_warning_or_error);
6923 : return id;
6924 : }
6925 :
6926 : /* Return identifier to look up for omp declare mapper. */
6927 :
6928 : tree
6929 4067 : omp_mapper_id (tree mapper_id, tree type)
6930 : {
6931 4067 : const char *p = NULL;
6932 4067 : const char *m = NULL;
6933 :
6934 4067 : if (mapper_id == NULL_TREE)
6935 : p = "";
6936 91 : else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
6937 91 : p = IDENTIFIER_POINTER (mapper_id);
6938 : else
6939 0 : return error_mark_node;
6940 :
6941 4067 : if (type != NULL_TREE)
6942 4059 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6943 :
6944 4067 : const char prefix[] = "omp declare mapper ";
6945 4067 : size_t lenp = sizeof (prefix);
6946 4067 : if (strncmp (p, prefix, lenp - 1) == 0)
6947 8 : lenp = 1;
6948 4067 : size_t len = strlen (p);
6949 4067 : size_t lenm = m ? strlen (m) + 1 : 0;
6950 4067 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6951 4067 : memcpy (name, prefix, lenp - 1);
6952 4067 : memcpy (name + lenp - 1, p, len + 1);
6953 4067 : if (m)
6954 : {
6955 4059 : name[lenp + len - 1] = '~';
6956 4059 : memcpy (name + lenp + len, m, lenm);
6957 : }
6958 4067 : return get_identifier (name);
6959 : }
6960 :
6961 : tree
6962 12046 : cxx_omp_mapper_lookup (tree id, tree type)
6963 : {
6964 12046 : if (!RECORD_OR_UNION_TYPE_P (type))
6965 : return NULL_TREE;
6966 3826 : id = omp_mapper_id (id, type);
6967 3826 : return lookup_name (id);
6968 : }
6969 :
6970 : tree
6971 375 : cxx_omp_extract_mapper_directive (tree vardecl)
6972 : {
6973 375 : gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
6974 :
6975 : /* Instantiate the decl if we haven't already. */
6976 375 : mark_used (vardecl);
6977 375 : tree body = DECL_INITIAL (vardecl);
6978 :
6979 375 : if (TREE_CODE (body) == STATEMENT_LIST)
6980 : {
6981 0 : tree_stmt_iterator tsi = tsi_start (body);
6982 0 : gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
6983 0 : tsi_next (&tsi);
6984 0 : body = tsi_stmt (tsi);
6985 : }
6986 :
6987 375 : gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
6988 :
6989 375 : return body;
6990 : }
6991 :
6992 : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
6993 : nothing more complicated. */
6994 :
6995 : tree
6996 1959 : cxx_omp_map_array_section (location_t loc, tree t)
6997 : {
6998 1959 : tree low = TREE_OPERAND (t, 1);
6999 1959 : tree len = TREE_OPERAND (t, 2);
7000 :
7001 1959 : if (len && integer_onep (len))
7002 : {
7003 317 : t = TREE_OPERAND (t, 0);
7004 :
7005 317 : if (!low)
7006 26 : low = integer_zero_node;
7007 :
7008 317 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
7009 6 : t = convert_from_reference (t);
7010 :
7011 317 : if (TYPE_PTR_P (TREE_TYPE (t))
7012 317 : || TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7013 317 : t = build_array_ref (loc, t, low);
7014 : else
7015 : /* handle_omp_array_sections_1 has already diagnosed the error. */
7016 0 : t = error_mark_node;
7017 : }
7018 :
7019 1959 : return t;
7020 : }
7021 :
7022 : /* Helper function for cp_parser_omp_declare_reduction_exprs
7023 : and tsubst_omp_udr.
7024 : Remove CLEANUP_STMT for data (omp_priv variable).
7025 : Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
7026 : DECL_EXPR. */
7027 :
7028 : tree
7029 4449 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
7030 : {
7031 4449 : if (TYPE_P (*tp))
7032 230 : *walk_subtrees = 0;
7033 4219 : else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
7034 52 : *tp = CLEANUP_BODY (*tp);
7035 4167 : else if (TREE_CODE (*tp) == DECL_EXPR)
7036 : {
7037 310 : tree decl = DECL_EXPR_DECL (*tp);
7038 310 : if (!processing_template_decl
7039 261 : && decl == (tree) data
7040 261 : && DECL_INITIAL (decl)
7041 402 : && DECL_INITIAL (decl) != error_mark_node)
7042 : {
7043 92 : tree list = NULL_TREE;
7044 92 : append_to_statement_list_force (*tp, &list);
7045 92 : tree init_expr = build2 (INIT_EXPR, void_type_node,
7046 92 : decl, DECL_INITIAL (decl));
7047 92 : DECL_INITIAL (decl) = NULL_TREE;
7048 92 : append_to_statement_list_force (init_expr, &list);
7049 92 : *tp = list;
7050 : }
7051 : }
7052 4449 : return NULL_TREE;
7053 : }
7054 :
7055 : /* Data passed from cp_check_omp_declare_reduction to
7056 : cp_check_omp_declare_reduction_r. */
7057 :
7058 : struct cp_check_omp_declare_reduction_data
7059 : {
7060 : location_t loc;
7061 : tree stmts[7];
7062 : bool combiner_p;
7063 : };
7064 :
7065 : /* Helper function for cp_check_omp_declare_reduction, called via
7066 : cp_walk_tree. */
7067 :
7068 : static tree
7069 15042 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
7070 : {
7071 15042 : struct cp_check_omp_declare_reduction_data *udr_data
7072 : = (struct cp_check_omp_declare_reduction_data *) data;
7073 15042 : if (SSA_VAR_P (*tp)
7074 2702 : && !DECL_ARTIFICIAL (*tp)
7075 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
7076 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
7077 : {
7078 135 : location_t loc = udr_data->loc;
7079 135 : if (udr_data->combiner_p)
7080 45 : error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
7081 : "variable %qD which is not %<omp_out%> nor %<omp_in%>",
7082 : *tp);
7083 : else
7084 90 : error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
7085 : "to variable %qD which is not %<omp_priv%> nor "
7086 : "%<omp_orig%>",
7087 : *tp);
7088 135 : return *tp;
7089 : }
7090 : return NULL_TREE;
7091 : }
7092 :
7093 : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
7094 :
7095 : bool
7096 1104 : cp_check_omp_declare_reduction (tree udr)
7097 : {
7098 1104 : tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
7099 1104 : gcc_assert (TYPE_REF_P (type));
7100 1104 : type = TREE_TYPE (type);
7101 1104 : int i;
7102 1104 : location_t loc = DECL_SOURCE_LOCATION (udr);
7103 :
7104 1104 : if (type == error_mark_node)
7105 : return false;
7106 1104 : if (ARITHMETIC_TYPE_P (type))
7107 : {
7108 : static enum tree_code predef_codes[]
7109 : = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
7110 : BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
7111 3276 : for (i = 0; i < 8; i++)
7112 : {
7113 2918 : tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
7114 2918 : const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
7115 2918 : const char *n2 = IDENTIFIER_POINTER (id);
7116 2918 : if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
7117 2918 : && (n1[IDENTIFIER_LENGTH (id)] == '~'
7118 0 : || n1[IDENTIFIER_LENGTH (id)] == '\0'))
7119 : break;
7120 : }
7121 :
7122 376 : if (i == 8
7123 358 : && TREE_CODE (type) != COMPLEX_EXPR)
7124 : {
7125 358 : const char prefix_minmax[] = "omp declare reduction m";
7126 358 : size_t prefix_size = sizeof (prefix_minmax) - 1;
7127 358 : const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
7128 358 : if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
7129 : prefix_minmax, prefix_size) == 0
7130 10 : && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
7131 4 : || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
7132 368 : && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
7133 6 : i = 0;
7134 : }
7135 376 : if (i < 8)
7136 : {
7137 24 : error_at (loc, "predeclared arithmetic type %qT in "
7138 : "%<#pragma omp declare reduction%>", type);
7139 24 : return false;
7140 : }
7141 : }
7142 : else if (FUNC_OR_METHOD_TYPE_P (type)
7143 : || TREE_CODE (type) == ARRAY_TYPE)
7144 : {
7145 24 : error_at (loc, "function or array type %qT in "
7146 : "%<#pragma omp declare reduction%>", type);
7147 24 : return false;
7148 : }
7149 : else if (TYPE_REF_P (type))
7150 : {
7151 0 : error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
7152 : type);
7153 0 : return false;
7154 : }
7155 704 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
7156 : {
7157 24 : error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
7158 : "type %qT in %<#pragma omp declare reduction%>", type);
7159 24 : return false;
7160 : }
7161 :
7162 1032 : tree body = DECL_SAVED_TREE (udr);
7163 1032 : if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
7164 : return true;
7165 :
7166 846 : tree_stmt_iterator tsi;
7167 846 : struct cp_check_omp_declare_reduction_data data;
7168 846 : memset (data.stmts, 0, sizeof data.stmts);
7169 846 : for (i = 0, tsi = tsi_start (body);
7170 4707 : i < 7 && !tsi_end_p (tsi);
7171 3861 : i++, tsi_next (&tsi))
7172 3861 : data.stmts[i] = tsi_stmt (tsi);
7173 846 : data.loc = loc;
7174 846 : gcc_assert (tsi_end_p (tsi));
7175 846 : if (i >= 3)
7176 : {
7177 846 : gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
7178 : && TREE_CODE (data.stmts[1]) == DECL_EXPR);
7179 846 : if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
7180 : return true;
7181 801 : data.combiner_p = true;
7182 801 : if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
7183 : &data, NULL))
7184 45 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
7185 : }
7186 801 : if (i >= 6)
7187 : {
7188 339 : gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
7189 : && TREE_CODE (data.stmts[4]) == DECL_EXPR);
7190 339 : data.combiner_p = false;
7191 339 : if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
7192 : &data, NULL)
7193 339 : || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
7194 : cp_check_omp_declare_reduction_r, &data, NULL))
7195 90 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */);
7196 339 : if (i == 7)
7197 201 : gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
7198 : }
7199 : return true;
7200 : }
7201 :
7202 : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
7203 : an inline call. But, remap
7204 : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
7205 : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
7206 :
7207 : static tree
7208 2217 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
7209 : tree decl, tree placeholder)
7210 : {
7211 2217 : copy_body_data id;
7212 2217 : hash_map<tree, tree> decl_map;
7213 :
7214 2217 : decl_map.put (omp_decl1, placeholder);
7215 2217 : decl_map.put (omp_decl2, decl);
7216 2217 : memset (&id, 0, sizeof (id));
7217 2217 : id.src_fn = DECL_CONTEXT (omp_decl1);
7218 2217 : id.dst_fn = current_function_decl;
7219 2217 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
7220 2217 : id.decl_map = &decl_map;
7221 :
7222 2217 : id.copy_decl = copy_decl_no_change;
7223 2217 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
7224 2217 : id.transform_new_cfg = true;
7225 2217 : id.transform_return_to_modify = false;
7226 2217 : id.eh_lp_nr = 0;
7227 2217 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
7228 2217 : return stmt;
7229 2217 : }
7230 :
7231 : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
7232 : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
7233 :
7234 : static tree
7235 15573 : find_omp_placeholder_r (tree *tp, int *, void *data)
7236 : {
7237 15573 : if (*tp == (tree) data)
7238 274 : return *tp;
7239 : return NULL_TREE;
7240 : }
7241 :
7242 : /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
7243 : Return true if there is some error and the clause should be removed. */
7244 :
7245 : static bool
7246 9018 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
7247 : {
7248 9018 : tree t = OMP_CLAUSE_DECL (c);
7249 9018 : bool predefined = false;
7250 9018 : if (TREE_CODE (t) == TREE_LIST)
7251 : {
7252 0 : gcc_assert (processing_template_decl);
7253 : return false;
7254 : }
7255 9018 : tree type = TREE_TYPE (t);
7256 9018 : if (TREE_CODE (t) == MEM_REF)
7257 1656 : type = TREE_TYPE (type);
7258 9018 : if (TYPE_REF_P (type))
7259 557 : type = TREE_TYPE (type);
7260 9018 : if (TREE_CODE (type) == ARRAY_TYPE)
7261 : {
7262 377 : tree oatype = type;
7263 377 : gcc_assert (TREE_CODE (t) != MEM_REF);
7264 757 : while (TREE_CODE (type) == ARRAY_TYPE)
7265 380 : type = TREE_TYPE (type);
7266 377 : if (!processing_template_decl)
7267 : {
7268 270 : t = require_complete_type (t);
7269 270 : if (t == error_mark_node
7270 270 : || !complete_type_or_else (oatype, NULL_TREE))
7271 : return true;
7272 261 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
7273 : TYPE_SIZE_UNIT (type));
7274 261 : if (integer_zerop (size))
7275 : {
7276 6 : error_at (OMP_CLAUSE_LOCATION (c),
7277 : "%qE in %<reduction%> clause is a zero size array",
7278 : omp_clause_printable_decl (t));
7279 3 : return true;
7280 : }
7281 258 : size = size_binop (MINUS_EXPR, size, size_one_node);
7282 258 : size = save_expr (size);
7283 258 : tree index_type = build_index_type (size);
7284 258 : tree atype = build_array_type (type, index_type);
7285 258 : tree ptype = build_pointer_type (type);
7286 258 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7287 152 : t = build_fold_addr_expr (t);
7288 258 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
7289 258 : OMP_CLAUSE_DECL (c) = t;
7290 : }
7291 : }
7292 9006 : if (type == error_mark_node)
7293 : return true;
7294 9003 : else if (ARITHMETIC_TYPE_P (type))
7295 7734 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
7296 : {
7297 : case PLUS_EXPR:
7298 : case MULT_EXPR:
7299 : case MINUS_EXPR:
7300 : case TRUTH_ANDIF_EXPR:
7301 : case TRUTH_ORIF_EXPR:
7302 : predefined = true;
7303 : break;
7304 246 : case MIN_EXPR:
7305 246 : case MAX_EXPR:
7306 246 : if (TREE_CODE (type) == COMPLEX_TYPE)
7307 : break;
7308 : predefined = true;
7309 : break;
7310 111 : case BIT_AND_EXPR:
7311 111 : case BIT_IOR_EXPR:
7312 111 : case BIT_XOR_EXPR:
7313 111 : if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
7314 : break;
7315 : predefined = true;
7316 : break;
7317 : default:
7318 : break;
7319 : }
7320 1269 : else if (TYPE_READONLY (type))
7321 : {
7322 18 : error_at (OMP_CLAUSE_LOCATION (c),
7323 : "%qE has const type for %<reduction%>",
7324 : omp_clause_printable_decl (t));
7325 9 : return true;
7326 : }
7327 1260 : else if (!processing_template_decl)
7328 : {
7329 1047 : t = require_complete_type (t);
7330 1047 : if (t == error_mark_node)
7331 : return true;
7332 1047 : OMP_CLAUSE_DECL (c) = t;
7333 : }
7334 :
7335 1047 : if (predefined)
7336 : {
7337 7512 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7338 7512 : return false;
7339 : }
7340 1482 : else if (processing_template_decl)
7341 : {
7342 222 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
7343 : return true;
7344 219 : return false;
7345 : }
7346 :
7347 1260 : tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7348 :
7349 1260 : type = TYPE_MAIN_VARIANT (type);
7350 1260 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7351 1260 : if (id == NULL_TREE)
7352 933 : id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
7353 : NULL_TREE, NULL_TREE);
7354 1260 : id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
7355 1260 : if (id)
7356 : {
7357 1215 : if (id == error_mark_node)
7358 : return true;
7359 1209 : mark_used (id);
7360 1209 : tree body = DECL_SAVED_TREE (id);
7361 1209 : if (!body)
7362 : return true;
7363 1206 : if (TREE_CODE (body) == STATEMENT_LIST)
7364 : {
7365 1206 : tree_stmt_iterator tsi;
7366 1206 : tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
7367 1206 : int i;
7368 1206 : tree stmts[7];
7369 1206 : tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
7370 1206 : atype = TREE_TYPE (atype);
7371 1206 : bool need_static_cast = !same_type_p (type, atype);
7372 1206 : memset (stmts, 0, sizeof stmts);
7373 1206 : for (i = 0, tsi = tsi_start (body);
7374 8594 : i < 7 && !tsi_end_p (tsi);
7375 7388 : i++, tsi_next (&tsi))
7376 7388 : stmts[i] = tsi_stmt (tsi);
7377 1206 : gcc_assert (tsi_end_p (tsi));
7378 :
7379 1206 : if (i >= 3)
7380 : {
7381 1206 : gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
7382 : && TREE_CODE (stmts[1]) == DECL_EXPR);
7383 1206 : placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
7384 1206 : DECL_ARTIFICIAL (placeholder) = 1;
7385 1206 : DECL_IGNORED_P (placeholder) = 1;
7386 1206 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
7387 1206 : if (TREE_CODE (t) == MEM_REF)
7388 : {
7389 600 : decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
7390 : type);
7391 600 : DECL_ARTIFICIAL (decl_placeholder) = 1;
7392 600 : DECL_IGNORED_P (decl_placeholder) = 1;
7393 600 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
7394 : }
7395 1206 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
7396 294 : cxx_mark_addressable (placeholder);
7397 1206 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
7398 1206 : && (decl_placeholder
7399 158 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7400 390 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7401 127 : : OMP_CLAUSE_DECL (c));
7402 1206 : tree omp_out = placeholder;
7403 1206 : tree omp_in = decl_placeholder ? decl_placeholder
7404 606 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7405 1206 : if (need_static_cast)
7406 : {
7407 7 : tree rtype = build_reference_type (atype);
7408 7 : omp_out = build_static_cast (input_location,
7409 : rtype, omp_out,
7410 : tf_warning_or_error);
7411 7 : omp_in = build_static_cast (input_location,
7412 : rtype, omp_in,
7413 : tf_warning_or_error);
7414 7 : if (omp_out == error_mark_node || omp_in == error_mark_node)
7415 3 : return true;
7416 7 : omp_out = convert_from_reference (omp_out);
7417 7 : omp_in = convert_from_reference (omp_in);
7418 : }
7419 1206 : OMP_CLAUSE_REDUCTION_MERGE (c)
7420 1206 : = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
7421 1206 : DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
7422 : }
7423 1206 : if (i >= 6)
7424 : {
7425 1014 : gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
7426 : && TREE_CODE (stmts[4]) == DECL_EXPR);
7427 1014 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
7428 1014 : && (decl_placeholder
7429 232 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7430 844 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7431 170 : : OMP_CLAUSE_DECL (c));
7432 1014 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
7433 225 : cxx_mark_addressable (placeholder);
7434 1014 : tree omp_priv = decl_placeholder ? decl_placeholder
7435 438 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7436 1014 : tree omp_orig = placeholder;
7437 1014 : if (need_static_cast)
7438 : {
7439 5 : if (i == 7)
7440 : {
7441 3 : error_at (OMP_CLAUSE_LOCATION (c),
7442 : "user defined reduction with constructor "
7443 : "initializer for base class %qT", atype);
7444 3 : return true;
7445 : }
7446 2 : tree rtype = build_reference_type (atype);
7447 2 : omp_priv = build_static_cast (input_location,
7448 : rtype, omp_priv,
7449 : tf_warning_or_error);
7450 2 : omp_orig = build_static_cast (input_location,
7451 : rtype, omp_orig,
7452 : tf_warning_or_error);
7453 2 : if (omp_priv == error_mark_node
7454 2 : || omp_orig == error_mark_node)
7455 : return true;
7456 2 : omp_priv = convert_from_reference (omp_priv);
7457 2 : omp_orig = convert_from_reference (omp_orig);
7458 : }
7459 1011 : if (i == 6)
7460 286 : *need_default_ctor = true;
7461 1011 : OMP_CLAUSE_REDUCTION_INIT (c)
7462 1011 : = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
7463 1011 : DECL_EXPR_DECL (stmts[3]),
7464 : omp_priv, omp_orig);
7465 1011 : if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
7466 : find_omp_placeholder_r, placeholder, NULL))
7467 247 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
7468 : }
7469 192 : else if (i >= 3)
7470 : {
7471 192 : if (CLASS_TYPE_P (type) && !pod_type_p (type))
7472 175 : *need_default_ctor = true;
7473 : else
7474 : {
7475 17 : tree init;
7476 17 : tree v = decl_placeholder ? decl_placeholder
7477 17 : : convert_from_reference (t);
7478 17 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
7479 8 : init = build_constructor (TREE_TYPE (v), NULL);
7480 : else
7481 9 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
7482 34 : OMP_CLAUSE_REDUCTION_INIT (c)
7483 34 : = cp_build_init_expr (v, init);
7484 : }
7485 : }
7486 : }
7487 : }
7488 1248 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7489 1203 : *need_dtor = true;
7490 : else
7491 : {
7492 90 : error_at (OMP_CLAUSE_LOCATION (c),
7493 : "user defined reduction not found for %qE",
7494 : omp_clause_printable_decl (t));
7495 45 : return true;
7496 : }
7497 1203 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7498 600 : gcc_assert (TYPE_SIZE_UNIT (type)
7499 : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
7500 : return false;
7501 : }
7502 :
7503 : /* Check an instance of an "omp declare mapper" function. */
7504 :
7505 : bool
7506 208 : cp_check_omp_declare_mapper (tree udm)
7507 : {
7508 208 : tree var = OMP_DECLARE_MAPPER_DECL (udm);
7509 208 : tree type = TREE_TYPE (var);
7510 208 : location_t loc = DECL_SOURCE_LOCATION (var);
7511 :
7512 208 : if (type == error_mark_node)
7513 : return false;
7514 :
7515 208 : if (processing_template_decl)
7516 : return true;
7517 :
7518 197 : if (!RECORD_OR_UNION_TYPE_P (type))
7519 : {
7520 17 : error_at (loc, "%qT is not a struct, union or class type in "
7521 : "%<#pragma omp declare mapper%>", type);
7522 17 : return false;
7523 : }
7524 180 : if (CLASSTYPE_VBASECLASSES (type))
7525 : {
7526 3 : error_at (loc, "%qT must not be a virtual base class in "
7527 : "%<#pragma omp declare mapper%>", type);
7528 3 : return false;
7529 : }
7530 :
7531 177 : tree c = OMP_DECLARE_MAPPER_CLAUSES (udm);
7532 215 : for ( ; c; c = OMP_CLAUSE_CHAIN (c))
7533 : {
7534 187 : tree dvar = OMP_CLAUSE_DECL (c);
7535 400 : while (!DECL_P (dvar) && TREE_OPERAND_LENGTH (dvar))
7536 213 : dvar = TREE_OPERAND (dvar, 0);
7537 187 : if (dvar == var)
7538 : break;
7539 : }
7540 177 : if (!c)
7541 : {
7542 : // After template handling, the var is mangled, demangle it
7543 28 : const char *name = IDENTIFIER_POINTER (DECL_NAME (var));
7544 28 : char *n = NULL;
7545 28 : if (startswith (name, "omp declare mapper "))
7546 : {
7547 3 : name += strlen ("omp declare mapper ");
7548 3 : n = xstrdup (name);
7549 3 : n[strchr (n, '~')-n] = '\0';
7550 3 : name = n;
7551 : }
7552 28 : error_at (loc, "at least one %<map%> clause must map %qs or an "
7553 : "element of it", name);
7554 28 : if (n)
7555 3 : free (n);
7556 : return false;
7557 : }
7558 :
7559 : /* FIXME: The vardecl created for the mapper_id uses DECL_DECLARED_CONSTEXPR_P
7560 : = 1, which is set to false in finalize_literal_type_property for C++ < 11,
7561 : leading to an error in ensure_literal_type_for_constexpr_object.
7562 : Examples (compile with -std=c++98): gcc.dg/gomp/declare-mapper-13.c and
7563 : libgomp.c++/declare-mapper-{5,6,8}.C. */
7564 149 : if (cxx_dialect < cxx11)
7565 : {
7566 0 : sorry_at (loc, "%<#pragma omp declare mapper%> with %<-std=%> set to "
7567 : "before C++11");
7568 0 : return false;
7569 : }
7570 :
7571 : return true;
7572 : }
7573 :
7574 : /* Called from finish_struct_1. linear(this) or linear(this:step)
7575 : clauses might not be finalized yet because the class has been incomplete
7576 : when parsing #pragma omp declare simd methods. Fix those up now. */
7577 :
7578 : void
7579 118365 : finish_omp_declare_simd_methods (tree t)
7580 : {
7581 118365 : if (processing_template_decl)
7582 : return;
7583 :
7584 808644 : for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
7585 : {
7586 1142470 : if (TREE_CODE (x) == USING_DECL
7587 690279 : || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
7588 452191 : continue;
7589 238088 : tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
7590 238196 : if (!ods || !TREE_VALUE (ods))
7591 237980 : continue;
7592 366 : for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
7593 258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7594 66 : && integer_zerop (OMP_CLAUSE_DECL (c))
7595 18 : && OMP_CLAUSE_LINEAR_STEP (c)
7596 276 : && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
7597 : {
7598 18 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
7599 18 : s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
7600 18 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
7601 18 : sizetype, s, TYPE_SIZE_UNIT (t));
7602 18 : OMP_CLAUSE_LINEAR_STEP (c) = s;
7603 : }
7604 : }
7605 : }
7606 :
7607 : /* Adjust sink depend/doacross clause to take into account pointer offsets.
7608 :
7609 : Return TRUE if there was a problem processing the offset, and the
7610 : whole clause should be removed. */
7611 :
7612 : static bool
7613 298 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
7614 : {
7615 298 : tree t = OMP_CLAUSE_DECL (sink_clause);
7616 298 : gcc_assert (TREE_CODE (t) == TREE_LIST);
7617 :
7618 : /* Make sure we don't adjust things twice for templates. */
7619 298 : if (processing_template_decl)
7620 : return false;
7621 :
7622 671 : for (; t; t = TREE_CHAIN (t))
7623 : {
7624 391 : tree decl = TREE_VALUE (t);
7625 391 : if (TYPE_PTR_P (TREE_TYPE (decl)))
7626 : {
7627 6 : tree offset = TREE_PURPOSE (t);
7628 6 : bool neg = wi::neg_p (wi::to_wide (offset));
7629 6 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
7630 6 : decl = mark_rvalue_use (decl);
7631 6 : decl = convert_from_reference (decl);
7632 12 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
7633 : neg ? MINUS_EXPR : PLUS_EXPR,
7634 : decl, offset);
7635 6 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
7636 : MINUS_EXPR, sizetype,
7637 : fold_convert (sizetype, t2),
7638 : fold_convert (sizetype, decl));
7639 6 : if (t2 == error_mark_node)
7640 : return true;
7641 6 : TREE_PURPOSE (t) = t2;
7642 : }
7643 : }
7644 : return false;
7645 : }
7646 :
7647 : /* Finish OpenMP iterators ITER. Return true if they are erroneous
7648 : and clauses containing them should be removed. */
7649 :
7650 : static bool
7651 615 : cp_omp_finish_iterators (tree iter)
7652 : {
7653 615 : bool ret = false;
7654 1395 : for (tree it = iter; it; it = TREE_CHAIN (it))
7655 : {
7656 780 : tree var = OMP_ITERATOR_VAR (it);
7657 780 : tree begin = OMP_ITERATOR_BEGIN (it);
7658 780 : tree end = OMP_ITERATOR_END (it);
7659 780 : tree step = OMP_ITERATOR_STEP (it);
7660 780 : tree orig_step;
7661 780 : tree type = TREE_TYPE (var);
7662 780 : location_t loc = DECL_SOURCE_LOCATION (var);
7663 780 : if (type == error_mark_node)
7664 : {
7665 0 : ret = true;
7666 218 : continue;
7667 : }
7668 780 : if (type_dependent_expression_p (var))
7669 59 : continue;
7670 721 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
7671 : {
7672 27 : error_at (loc, "iterator %qD has neither integral nor pointer type",
7673 : var);
7674 27 : ret = true;
7675 27 : continue;
7676 : }
7677 694 : else if (TYPE_READONLY (type))
7678 : {
7679 24 : error_at (loc, "iterator %qD has const qualified type", var);
7680 24 : ret = true;
7681 24 : continue;
7682 : }
7683 670 : if (type_dependent_expression_p (begin)
7684 661 : || type_dependent_expression_p (end)
7685 1331 : || type_dependent_expression_p (step))
7686 15 : continue;
7687 655 : else if (error_operand_p (step))
7688 : {
7689 0 : ret = true;
7690 0 : continue;
7691 : }
7692 655 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
7693 : {
7694 21 : error_at (EXPR_LOC_OR_LOC (step, loc),
7695 : "iterator step with non-integral type");
7696 21 : ret = true;
7697 21 : continue;
7698 : }
7699 :
7700 634 : begin = mark_rvalue_use (begin);
7701 634 : end = mark_rvalue_use (end);
7702 634 : step = mark_rvalue_use (step);
7703 634 : begin = cp_build_c_cast (input_location, type, begin,
7704 : tf_warning_or_error);
7705 634 : end = cp_build_c_cast (input_location, type, end,
7706 : tf_warning_or_error);
7707 634 : orig_step = step;
7708 634 : if (!processing_template_decl)
7709 557 : step = orig_step = save_expr (step);
7710 634 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
7711 634 : step = cp_build_c_cast (input_location, stype, step,
7712 : tf_warning_or_error);
7713 634 : if (POINTER_TYPE_P (type) && !processing_template_decl)
7714 : {
7715 66 : begin = save_expr (begin);
7716 66 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
7717 66 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
7718 : fold_convert (sizetype, step),
7719 : fold_convert (sizetype, begin));
7720 66 : step = fold_convert (ssizetype, step);
7721 : }
7722 634 : if (!processing_template_decl)
7723 : {
7724 557 : begin = maybe_constant_value (begin);
7725 557 : end = maybe_constant_value (end);
7726 557 : step = maybe_constant_value (step);
7727 557 : orig_step = maybe_constant_value (orig_step);
7728 : }
7729 634 : if (integer_zerop (step))
7730 : {
7731 27 : error_at (loc, "iterator %qD has zero step", var);
7732 27 : ret = true;
7733 27 : continue;
7734 : }
7735 :
7736 607 : if (begin == error_mark_node
7737 598 : || end == error_mark_node
7738 589 : || step == error_mark_node
7739 589 : || orig_step == error_mark_node)
7740 : {
7741 18 : ret = true;
7742 18 : continue;
7743 : }
7744 :
7745 589 : if (!processing_template_decl)
7746 : {
7747 512 : begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
7748 512 : end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
7749 512 : step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
7750 512 : orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
7751 : orig_step);
7752 : }
7753 589 : hash_set<tree> pset;
7754 589 : tree it2;
7755 745 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
7756 : {
7757 183 : tree var2 = OMP_ITERATOR_VAR (it2);
7758 183 : tree begin2 = OMP_ITERATOR_BEGIN (it2);
7759 183 : tree end2 = OMP_ITERATOR_END (it2);
7760 183 : tree step2 = OMP_ITERATOR_STEP (it2);
7761 183 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
7762 183 : if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
7763 : {
7764 9 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
7765 : "begin expression refers to outer iterator %qD", var);
7766 36 : break;
7767 : }
7768 174 : else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
7769 : {
7770 9 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
7771 : "end expression refers to outer iterator %qD", var);
7772 9 : break;
7773 : }
7774 165 : else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
7775 : {
7776 9 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
7777 : "step expression refers to outer iterator %qD", var);
7778 9 : break;
7779 : }
7780 : }
7781 589 : if (it2)
7782 : {
7783 27 : ret = true;
7784 27 : continue;
7785 : }
7786 562 : OMP_ITERATOR_BEGIN (it) = begin;
7787 562 : OMP_ITERATOR_END (it) = end;
7788 562 : if (processing_template_decl)
7789 71 : OMP_ITERATOR_STEP (it) = orig_step;
7790 : else
7791 : {
7792 491 : OMP_ITERATOR_STEP (it) = step;
7793 491 : OMP_ITERATOR_ORIG_STEP (it) = orig_step;
7794 : }
7795 589 : }
7796 615 : return ret;
7797 : }
7798 :
7799 : /* Ensure that pointers are used in OpenACC attach and detach clauses.
7800 : Return true if an error has been detected. */
7801 :
7802 : static bool
7803 18829 : cp_oacc_check_attachments (tree c)
7804 : {
7805 18829 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
7806 : return false;
7807 :
7808 : /* OpenACC attach / detach clauses must be pointers. */
7809 14803 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
7810 14803 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
7811 : {
7812 196 : tree t = OMP_CLAUSE_DECL (c);
7813 196 : tree type;
7814 :
7815 232 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7816 36 : t = TREE_OPERAND (t, 0);
7817 :
7818 196 : type = TREE_TYPE (t);
7819 :
7820 196 : if (TREE_CODE (type) == REFERENCE_TYPE)
7821 36 : type = TREE_TYPE (type);
7822 :
7823 196 : if (TREE_CODE (type) != POINTER_TYPE)
7824 : {
7825 36 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
7826 : user_omp_clause_code_name (c, true));
7827 36 : return true;
7828 : }
7829 : }
7830 :
7831 : return false;
7832 : }
7833 :
7834 : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
7835 : happened. */
7836 :
7837 : tree
7838 813 : cp_finish_omp_init_prefer_type (tree pref_type)
7839 : {
7840 813 : if (processing_template_decl
7841 741 : || pref_type == NULL_TREE
7842 356 : || TREE_CODE (pref_type) != TREE_LIST)
7843 : return pref_type;
7844 :
7845 81 : tree t = TREE_PURPOSE (pref_type);
7846 81 : char *str = const_cast<char *> (TREE_STRING_POINTER (t));
7847 81 : tree fr_list = TREE_VALUE (pref_type);
7848 81 : int len = TREE_VEC_LENGTH (fr_list);
7849 81 : int cnt = 0;
7850 :
7851 270 : while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
7852 : {
7853 270 : str++;
7854 270 : if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
7855 : {
7856 : /* Assume a no or a single 'fr'. */
7857 150 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7858 150 : location_t loc = UNKNOWN_LOCATION;
7859 150 : tree value = TREE_VEC_ELT (fr_list, cnt);
7860 150 : if (value != NULL_TREE && value != error_mark_node)
7861 : {
7862 126 : loc = EXPR_LOCATION (value);
7863 126 : if (value && TREE_CODE (value) == NOP_EXPR)
7864 39 : value = TREE_OPERAND (value, 0);
7865 126 : value = cp_fully_fold (value);
7866 : }
7867 126 : if (value != NULL_TREE && value != error_mark_node)
7868 : {
7869 126 : if (TREE_CODE (value) != INTEGER_CST
7870 126 : || !tree_fits_shwi_p (value))
7871 0 : error_at (loc,
7872 : "expected string literal or "
7873 : "constant integer expression instead of %qE", value);
7874 : else
7875 : {
7876 126 : HOST_WIDE_INT n = tree_to_shwi (value);
7877 126 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
7878 : {
7879 48 : warning_at (loc, OPT_Wopenmp,
7880 : "unknown foreign runtime identifier %qwd", n);
7881 48 : n = GOMP_INTEROP_IFR_UNKNOWN;
7882 : }
7883 126 : str[0] = (char) n;
7884 : }
7885 : }
7886 150 : str++;
7887 : }
7888 120 : else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
7889 : {
7890 : /* Assume a no or a single 'fr'. */
7891 120 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7892 120 : str++;
7893 : }
7894 270 : str++;
7895 294 : while (str[0] != '\0')
7896 24 : str += strlen (str) + 1;
7897 270 : str++;
7898 270 : cnt++;
7899 270 : if (cnt >= len)
7900 : break;
7901 : }
7902 : return t;
7903 : }
7904 :
7905 : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
7906 : Remove any elements from the list that are invalid. */
7907 :
7908 : tree
7909 63463 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
7910 : {
7911 63463 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
7912 63463 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
7913 63463 : bitmap_head oacc_reduction_head, is_on_device_head;
7914 63463 : tree c, t, *pc;
7915 63463 : tree safelen = NULL_TREE;
7916 63463 : bool openacc = (ort & C_ORT_ACC) != 0;
7917 63463 : bool branch_seen = false;
7918 63463 : bool copyprivate_seen = false;
7919 63463 : bool ordered_seen = false;
7920 63463 : bool order_seen = false;
7921 63463 : bool schedule_seen = false;
7922 63463 : bool oacc_async = false;
7923 63463 : bool indir_component_ref_p = false;
7924 63463 : tree last_iterators = NULL_TREE;
7925 63463 : bool last_iterators_remove = false;
7926 : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
7927 : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
7928 63463 : int reduction_seen = 0;
7929 63463 : bool allocate_seen = false;
7930 63463 : tree detach_seen = NULL_TREE;
7931 63463 : bool mergeable_seen = false;
7932 63463 : bool implicit_moved = false;
7933 63463 : bool target_in_reduction_seen = false;
7934 63463 : bool num_tasks_seen = false;
7935 63463 : bool partial_seen = false;
7936 63463 : bool init_seen = false;
7937 63463 : bool init_use_destroy_seen = false;
7938 63463 : tree init_no_targetsync_clause = NULL_TREE;
7939 63463 : tree depend_clause = NULL_TREE;
7940 :
7941 63463 : if (!openacc)
7942 50642 : clauses = omp_remove_duplicate_maps (clauses, true);
7943 :
7944 63463 : bitmap_obstack_initialize (NULL);
7945 63463 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
7946 63463 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
7947 63463 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
7948 63463 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
7949 : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
7950 63463 : bitmap_initialize (&map_head, &bitmap_default_obstack);
7951 63463 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
7952 63463 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
7953 : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
7954 : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
7955 63463 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
7956 63463 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
7957 :
7958 63463 : if (openacc)
7959 28440 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
7960 16007 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
7961 : {
7962 : oacc_async = true;
7963 : break;
7964 : }
7965 :
7966 63463 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
7967 :
7968 162385 : for (pc = &clauses, c = clauses; c ; c = *pc)
7969 : {
7970 98922 : bool remove = false;
7971 98922 : bool field_ok = false;
7972 :
7973 : /* We've reached the end of a list of expanded nodes. Reset the group
7974 : start pointer. */
7975 98922 : if (c == grp_sentinel)
7976 : {
7977 5707 : if (grp_start_p
7978 5707 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
7979 96 : for (tree gc = *grp_start_p; gc != grp_sentinel;
7980 66 : gc = OMP_CLAUSE_CHAIN (gc))
7981 66 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
7982 : grp_start_p = NULL;
7983 : }
7984 :
7985 98922 : switch (OMP_CLAUSE_CODE (c))
7986 : {
7987 2100 : case OMP_CLAUSE_SHARED:
7988 2100 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7989 2100 : goto check_dup_generic;
7990 2584 : case OMP_CLAUSE_PRIVATE:
7991 2584 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7992 2584 : goto check_dup_generic;
7993 7548 : case OMP_CLAUSE_REDUCTION:
7994 7548 : if (reduction_seen == 0)
7995 6429 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
7996 1119 : else if (reduction_seen != -2
7997 2238 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
7998 1119 : ? -1 : 1))
7999 : {
8000 6 : error_at (OMP_CLAUSE_LOCATION (c),
8001 : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
8002 : "on the same construct");
8003 6 : reduction_seen = -2;
8004 : }
8005 : /* FALLTHRU */
8006 9693 : case OMP_CLAUSE_IN_REDUCTION:
8007 9693 : case OMP_CLAUSE_TASK_REDUCTION:
8008 9693 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8009 9693 : t = OMP_CLAUSE_DECL (c);
8010 9693 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
8011 : {
8012 2315 : if (handle_omp_array_sections (c, ort))
8013 : {
8014 : remove = true;
8015 : break;
8016 : }
8017 2273 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
8018 2273 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
8019 : {
8020 3 : error_at (OMP_CLAUSE_LOCATION (c),
8021 : "%<inscan%> %<reduction%> clause with array "
8022 : "section");
8023 3 : remove = true;
8024 3 : break;
8025 : }
8026 2270 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
8027 : {
8028 4888 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
8029 2618 : t = TREE_OPERAND (t, 0);
8030 : }
8031 : else
8032 : {
8033 0 : gcc_assert (TREE_CODE (t) == MEM_REF);
8034 0 : t = TREE_OPERAND (t, 0);
8035 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
8036 0 : t = TREE_OPERAND (t, 0);
8037 0 : if (TREE_CODE (t) == ADDR_EXPR
8038 0 : || INDIRECT_REF_P (t))
8039 0 : t = TREE_OPERAND (t, 0);
8040 : }
8041 2270 : tree n = omp_clause_decl_field (t);
8042 2270 : if (n)
8043 59 : t = n;
8044 2270 : goto check_dup_generic_t;
8045 : }
8046 7378 : if (oacc_async)
8047 7 : cxx_mark_addressable (t);
8048 7378 : goto check_dup_generic;
8049 98 : case OMP_CLAUSE_COPYPRIVATE:
8050 98 : copyprivate_seen = true;
8051 98 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8052 98 : goto check_dup_generic;
8053 280 : case OMP_CLAUSE_COPYIN:
8054 280 : goto check_dup_generic;
8055 1631 : case OMP_CLAUSE_LINEAR:
8056 1631 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8057 1631 : t = OMP_CLAUSE_DECL (c);
8058 1631 : if (ort != C_ORT_OMP_DECLARE_SIMD
8059 1631 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
8060 : {
8061 84 : if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
8062 : {
8063 42 : error_at (OMP_CLAUSE_LOCATION (c),
8064 : "modifier should not be specified in %<linear%> "
8065 : "clause on %<simd%> or %<for%> constructs when "
8066 : "not using OpenMP 5.2 modifiers");
8067 42 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
8068 : }
8069 42 : else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
8070 : {
8071 18 : error_at (OMP_CLAUSE_LOCATION (c),
8072 : "modifier other than %<val%> specified in "
8073 : "%<linear%> clause on %<simd%> or %<for%> "
8074 : "constructs when using OpenMP 5.2 modifiers");
8075 18 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
8076 : }
8077 : }
8078 1011 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
8079 2571 : && !type_dependent_expression_p (t))
8080 : {
8081 1529 : tree type = TREE_TYPE (t);
8082 1529 : if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
8083 1448 : || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
8084 1598 : && !TYPE_REF_P (type))
8085 : {
8086 12 : error_at (OMP_CLAUSE_LOCATION (c),
8087 : "linear clause with %qs modifier applied to "
8088 : "non-reference variable with %qT type",
8089 12 : OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
8090 12 : ? "ref" : "uval", TREE_TYPE (t));
8091 12 : remove = true;
8092 12 : break;
8093 : }
8094 1517 : if (TYPE_REF_P (type))
8095 281 : type = TREE_TYPE (type);
8096 1517 : if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
8097 : {
8098 1442 : if (!INTEGRAL_TYPE_P (type)
8099 85 : && !TYPE_PTR_P (type))
8100 : {
8101 18 : error_at (OMP_CLAUSE_LOCATION (c),
8102 : "linear clause applied to non-integral "
8103 : "non-pointer variable with %qT type",
8104 18 : TREE_TYPE (t));
8105 18 : remove = true;
8106 18 : break;
8107 : }
8108 : }
8109 : }
8110 1601 : t = OMP_CLAUSE_LINEAR_STEP (c);
8111 1601 : if (t == NULL_TREE)
8112 6 : t = integer_one_node;
8113 1601 : if (t == error_mark_node)
8114 : {
8115 : remove = true;
8116 : break;
8117 : }
8118 1601 : else if (!type_dependent_expression_p (t)
8119 1599 : && !INTEGRAL_TYPE_P (TREE_TYPE (t))
8120 1613 : && (ort != C_ORT_OMP_DECLARE_SIMD
8121 9 : || TREE_CODE (t) != PARM_DECL
8122 6 : || !TYPE_REF_P (TREE_TYPE (t))
8123 6 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
8124 : {
8125 6 : error_at (OMP_CLAUSE_LOCATION (c),
8126 : "linear step expression must be integral");
8127 6 : remove = true;
8128 6 : break;
8129 : }
8130 : else
8131 : {
8132 1595 : t = mark_rvalue_use (t);
8133 1595 : if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
8134 : {
8135 42 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
8136 42 : goto check_dup_generic;
8137 : }
8138 1553 : if (!processing_template_decl
8139 1553 : && (VAR_P (OMP_CLAUSE_DECL (c))
8140 835 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
8141 : {
8142 1372 : if (ort == C_ORT_OMP_DECLARE_SIMD)
8143 : {
8144 589 : t = maybe_constant_value (t);
8145 589 : if (TREE_CODE (t) != INTEGER_CST)
8146 : {
8147 6 : error_at (OMP_CLAUSE_LOCATION (c),
8148 : "%<linear%> clause step %qE is neither "
8149 : "constant nor a parameter", t);
8150 6 : remove = true;
8151 6 : break;
8152 : }
8153 : }
8154 1366 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8155 1366 : tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
8156 1366 : if (TYPE_REF_P (type))
8157 257 : type = TREE_TYPE (type);
8158 1366 : if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
8159 : {
8160 66 : type = build_pointer_type (type);
8161 66 : tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
8162 66 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8163 : d, t);
8164 66 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8165 : MINUS_EXPR, sizetype,
8166 : fold_convert (sizetype, t),
8167 : fold_convert (sizetype, d));
8168 66 : if (t == error_mark_node)
8169 : {
8170 : remove = true;
8171 : break;
8172 : }
8173 : }
8174 1300 : else if (TYPE_PTR_P (type)
8175 : /* Can't multiply the step yet if *this
8176 : is still incomplete type. */
8177 1300 : && (ort != C_ORT_OMP_DECLARE_SIMD
8178 45 : || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
8179 45 : || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
8180 30 : || DECL_NAME (OMP_CLAUSE_DECL (c))
8181 30 : != this_identifier
8182 30 : || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
8183 : {
8184 37 : tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
8185 37 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8186 : d, t);
8187 37 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8188 : MINUS_EXPR, sizetype,
8189 : fold_convert (sizetype, t),
8190 : fold_convert (sizetype, d));
8191 37 : if (t == error_mark_node)
8192 : {
8193 : remove = true;
8194 : break;
8195 : }
8196 : }
8197 : else
8198 1263 : t = fold_convert (type, t);
8199 : }
8200 1547 : OMP_CLAUSE_LINEAR_STEP (c) = t;
8201 : }
8202 1547 : goto check_dup_generic;
8203 14995 : check_dup_generic:
8204 14995 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8205 14995 : if (t)
8206 : {
8207 101 : if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
8208 101 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8209 : }
8210 : else
8211 14894 : t = OMP_CLAUSE_DECL (c);
8212 17532 : check_dup_generic_t:
8213 17532 : if (t == current_class_ptr
8214 17532 : && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
8215 102 : || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
8216 72 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
8217 : {
8218 24 : error_at (OMP_CLAUSE_LOCATION (c),
8219 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8220 : " clauses");
8221 24 : remove = true;
8222 24 : break;
8223 : }
8224 17508 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8225 586 : && (!field_ok || TREE_CODE (t) != FIELD_DECL))
8226 : {
8227 59 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8228 : break;
8229 39 : if (DECL_P (t))
8230 30 : error_at (OMP_CLAUSE_LOCATION (c),
8231 : "%qD is not a variable in clause %qs", t,
8232 15 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8233 : else
8234 48 : error_at (OMP_CLAUSE_LOCATION (c),
8235 : "%qE is not a variable in clause %qs", t,
8236 24 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8237 : remove = true;
8238 : }
8239 17449 : else if ((openacc
8240 2707 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
8241 14980 : || (ort == C_ORT_OMP
8242 12647 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
8243 12616 : || (OMP_CLAUSE_CODE (c)
8244 : == OMP_CLAUSE_USE_DEVICE_ADDR)))
8245 32322 : || (ort == C_ORT_OMP_TARGET
8246 938 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
8247 : {
8248 2854 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
8249 2854 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8250 275 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
8251 : {
8252 6 : error_at (OMP_CLAUSE_LOCATION (c),
8253 : "%qD appears more than once in data-sharing "
8254 : "clauses", t);
8255 6 : remove = true;
8256 6 : break;
8257 : }
8258 2848 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
8259 272 : target_in_reduction_seen = true;
8260 2848 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8261 : {
8262 12 : error_at (OMP_CLAUSE_LOCATION (c),
8263 : openacc
8264 : ? "%qD appears more than once in reduction clauses"
8265 : : "%qD appears more than once in data clauses",
8266 : t);
8267 6 : remove = true;
8268 : }
8269 : else
8270 2842 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8271 : }
8272 14595 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8273 14522 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8274 14519 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
8275 29114 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8276 : {
8277 76 : error_at (OMP_CLAUSE_LOCATION (c),
8278 : "%qD appears more than once in data clauses", t);
8279 76 : remove = true;
8280 : }
8281 14519 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
8282 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
8283 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
8284 3125 : && bitmap_bit_p (&map_head, DECL_UID (t)))
8285 : {
8286 9 : if (openacc)
8287 0 : error_at (OMP_CLAUSE_LOCATION (c),
8288 : "%qD appears more than once in data clauses", t);
8289 : else
8290 9 : error_at (OMP_CLAUSE_LOCATION (c),
8291 : "%qD appears both in data and map clauses", t);
8292 : remove = true;
8293 : }
8294 : else
8295 14510 : bitmap_set_bit (&generic_head, DECL_UID (t));
8296 17482 : if (!field_ok)
8297 : break;
8298 13071 : handle_field_decl:
8299 21825 : if (!remove
8300 21630 : && TREE_CODE (t) == FIELD_DECL
8301 16940 : && t == OMP_CLAUSE_DECL (c))
8302 : {
8303 795 : OMP_CLAUSE_DECL (c)
8304 795 : = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
8305 : == OMP_CLAUSE_SHARED));
8306 795 : if (OMP_CLAUSE_DECL (c) == error_mark_node)
8307 98453 : remove = true;
8308 : }
8309 : break;
8310 :
8311 3486 : case OMP_CLAUSE_FIRSTPRIVATE:
8312 3486 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
8313 : {
8314 414 : move_implicit:
8315 414 : implicit_moved = true;
8316 : /* Move firstprivate and map clauses with
8317 : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
8318 : clauses chain. */
8319 414 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
8320 414 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
8321 2704 : while (*pc1)
8322 2290 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
8323 2290 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
8324 : {
8325 275 : *pc3 = *pc1;
8326 275 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
8327 275 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8328 : }
8329 2015 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
8330 2015 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
8331 : {
8332 370 : *pc2 = *pc1;
8333 370 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
8334 370 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8335 : }
8336 : else
8337 1645 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
8338 414 : *pc3 = NULL;
8339 414 : *pc2 = cl2;
8340 414 : *pc1 = cl1;
8341 414 : continue;
8342 414 : }
8343 3229 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8344 3229 : if (t)
8345 69 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8346 : else
8347 3160 : t = OMP_CLAUSE_DECL (c);
8348 3229 : if (!openacc && t == current_class_ptr)
8349 : {
8350 6 : error_at (OMP_CLAUSE_LOCATION (c),
8351 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8352 : " clauses");
8353 6 : remove = true;
8354 6 : break;
8355 : }
8356 3223 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8357 333 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8358 333 : || TREE_CODE (t) != FIELD_DECL))
8359 : {
8360 41 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8361 : break;
8362 18 : if (DECL_P (t))
8363 12 : error_at (OMP_CLAUSE_LOCATION (c),
8364 : "%qD is not a variable in clause %<firstprivate%>",
8365 : t);
8366 : else
8367 6 : error_at (OMP_CLAUSE_LOCATION (c),
8368 : "%qE is not a variable in clause %<firstprivate%>",
8369 : t);
8370 : remove = true;
8371 : }
8372 3182 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8373 275 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
8374 3436 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8375 : remove = true;
8376 3182 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8377 3173 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8378 6352 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8379 : {
8380 15 : error_at (OMP_CLAUSE_LOCATION (c),
8381 : "%qD appears more than once in data clauses", t);
8382 15 : remove = true;
8383 : }
8384 3167 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8385 3167 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
8386 : {
8387 21 : if (openacc)
8388 0 : error_at (OMP_CLAUSE_LOCATION (c),
8389 : "%qD appears more than once in data clauses", t);
8390 21 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8391 21 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
8392 : /* Silently drop the clause. */;
8393 : else
8394 18 : error_at (OMP_CLAUSE_LOCATION (c),
8395 : "%qD appears both in data and map clauses", t);
8396 : remove = true;
8397 : }
8398 : else
8399 3146 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
8400 3200 : goto handle_field_decl;
8401 :
8402 2793 : case OMP_CLAUSE_LASTPRIVATE:
8403 2793 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8404 2793 : if (t)
8405 35 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8406 : else
8407 2758 : t = OMP_CLAUSE_DECL (c);
8408 2793 : if (!openacc && t == current_class_ptr)
8409 : {
8410 6 : error_at (OMP_CLAUSE_LOCATION (c),
8411 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8412 : " clauses");
8413 6 : remove = true;
8414 6 : break;
8415 : }
8416 2787 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8417 259 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8418 259 : || TREE_CODE (t) != FIELD_DECL))
8419 : {
8420 35 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8421 : break;
8422 9 : if (DECL_P (t))
8423 3 : error_at (OMP_CLAUSE_LOCATION (c),
8424 : "%qD is not a variable in clause %<lastprivate%>",
8425 : t);
8426 : else
8427 6 : error_at (OMP_CLAUSE_LOCATION (c),
8428 : "%qE is not a variable in clause %<lastprivate%>",
8429 : t);
8430 : remove = true;
8431 : }
8432 2752 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8433 2752 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8434 : {
8435 12 : error_at (OMP_CLAUSE_LOCATION (c),
8436 : "%qD appears more than once in data clauses", t);
8437 12 : remove = true;
8438 : }
8439 : else
8440 2740 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
8441 2761 : goto handle_field_decl;
8442 :
8443 2221 : case OMP_CLAUSE_IF:
8444 2221 : case OMP_CLAUSE_SELF:
8445 2221 : t = OMP_CLAUSE_OPERAND (c, 0);
8446 2221 : t = maybe_convert_cond (t);
8447 2221 : if (t == error_mark_node)
8448 : remove = true;
8449 2206 : else if (!processing_template_decl)
8450 2145 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8451 2221 : OMP_CLAUSE_OPERAND (c, 0) = t;
8452 2221 : break;
8453 :
8454 289 : case OMP_CLAUSE_FINAL:
8455 289 : t = OMP_CLAUSE_FINAL_EXPR (c);
8456 289 : t = maybe_convert_cond (t);
8457 289 : if (t == error_mark_node)
8458 : remove = true;
8459 289 : else if (!processing_template_decl)
8460 283 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8461 289 : OMP_CLAUSE_FINAL_EXPR (c) = t;
8462 289 : break;
8463 :
8464 92 : case OMP_CLAUSE_NOCONTEXT:
8465 92 : t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
8466 92 : t = maybe_convert_cond (t);
8467 92 : if (t == error_mark_node)
8468 : remove = true;
8469 89 : else if (!processing_template_decl)
8470 83 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8471 92 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
8472 92 : break;
8473 :
8474 80 : case OMP_CLAUSE_NOVARIANTS:
8475 80 : t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
8476 80 : t = maybe_convert_cond (t);
8477 80 : if (t == error_mark_node)
8478 : remove = true;
8479 77 : else if (!processing_template_decl)
8480 71 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8481 80 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
8482 80 : break;
8483 :
8484 1249 : case OMP_CLAUSE_GANG:
8485 : /* Operand 1 is the gang static: argument. */
8486 1249 : t = OMP_CLAUSE_OPERAND (c, 1);
8487 1249 : if (t != NULL_TREE)
8488 : {
8489 129 : if (t == error_mark_node)
8490 : remove = true;
8491 129 : else if (!type_dependent_expression_p (t)
8492 129 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8493 : {
8494 6 : error_at (OMP_CLAUSE_LOCATION (c),
8495 : "%<gang%> static expression must be integral");
8496 6 : remove = true;
8497 : }
8498 : else
8499 : {
8500 123 : t = mark_rvalue_use (t);
8501 123 : if (!processing_template_decl)
8502 : {
8503 123 : t = maybe_constant_value (t);
8504 123 : if (TREE_CODE (t) == INTEGER_CST
8505 109 : && tree_int_cst_sgn (t) != 1
8506 176 : && t != integer_minus_one_node)
8507 : {
8508 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8509 : "%<gang%> static value must be "
8510 : "positive");
8511 0 : t = integer_one_node;
8512 : }
8513 123 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8514 : }
8515 : }
8516 129 : OMP_CLAUSE_OPERAND (c, 1) = t;
8517 : }
8518 : /* Check operand 0, the num argument. */
8519 : /* FALLTHRU */
8520 :
8521 3480 : case OMP_CLAUSE_WORKER:
8522 3480 : case OMP_CLAUSE_VECTOR:
8523 3480 : if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
8524 : break;
8525 : /* FALLTHRU */
8526 :
8527 484 : case OMP_CLAUSE_NUM_TASKS:
8528 484 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
8529 136 : num_tasks_seen = true;
8530 : /* FALLTHRU */
8531 :
8532 3034 : case OMP_CLAUSE_NUM_TEAMS:
8533 3034 : case OMP_CLAUSE_NUM_THREADS:
8534 3034 : case OMP_CLAUSE_NUM_GANGS:
8535 3034 : case OMP_CLAUSE_NUM_WORKERS:
8536 3034 : case OMP_CLAUSE_DYN_GROUPPRIVATE:
8537 3034 : case OMP_CLAUSE_VECTOR_LENGTH:
8538 3034 : t = OMP_CLAUSE_OPERAND (c, 0);
8539 3034 : if (t == error_mark_node)
8540 : remove = true;
8541 3034 : else if (!type_dependent_expression_p (t)
8542 3034 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8543 : {
8544 99 : switch (OMP_CLAUSE_CODE (c))
8545 : {
8546 12 : case OMP_CLAUSE_GANG:
8547 12 : error_at (OMP_CLAUSE_LOCATION (c),
8548 12 : "%<gang%> num expression must be integral"); break;
8549 12 : case OMP_CLAUSE_VECTOR:
8550 12 : error_at (OMP_CLAUSE_LOCATION (c),
8551 : "%<vector%> length expression must be integral");
8552 12 : break;
8553 12 : case OMP_CLAUSE_WORKER:
8554 12 : error_at (OMP_CLAUSE_LOCATION (c),
8555 : "%<worker%> num expression must be integral");
8556 12 : break;
8557 63 : default:
8558 63 : error_at (OMP_CLAUSE_LOCATION (c),
8559 : "%qs expression must be integral",
8560 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8561 : }
8562 : remove = true;
8563 : }
8564 : else
8565 : {
8566 2935 : t = mark_rvalue_use (t);
8567 2935 : if (!processing_template_decl)
8568 : {
8569 2687 : t = maybe_constant_value (t);
8570 2687 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
8571 2652 : && TREE_CODE (t) == INTEGER_CST
8572 4142 : && tree_int_cst_sgn (t) != 1)
8573 : {
8574 85 : switch (OMP_CLAUSE_CODE (c))
8575 : {
8576 3 : case OMP_CLAUSE_GANG:
8577 3 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8578 : "%<gang%> num value must be positive");
8579 3 : break;
8580 0 : case OMP_CLAUSE_VECTOR:
8581 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8582 : "%<vector%> length value must be "
8583 : "positive");
8584 0 : break;
8585 0 : case OMP_CLAUSE_WORKER:
8586 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8587 : "%<worker%> num value must be "
8588 : "positive");
8589 0 : break;
8590 82 : default:
8591 82 : warning_at (OMP_CLAUSE_LOCATION (c),
8592 46 : (flag_openmp || flag_openmp_simd)
8593 82 : ? OPT_Wopenmp : 0,
8594 : "%qs value must be positive",
8595 : omp_clause_code_name
8596 82 : [OMP_CLAUSE_CODE (c)]);
8597 : }
8598 85 : t = integer_one_node;
8599 : }
8600 2602 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
8601 35 : && TREE_CODE (t) == INTEGER_CST
8602 2625 : && tree_int_cst_sgn (t) < 0)
8603 : {
8604 8 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8605 : "%<dyn_groupprivate%> value must be "
8606 : "non-negative");
8607 8 : t = integer_zero_node;
8608 : }
8609 2687 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8610 : }
8611 2935 : OMP_CLAUSE_OPERAND (c, 0) = t;
8612 : }
8613 3034 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
8614 752 : && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
8615 3313 : && !remove)
8616 : {
8617 279 : t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
8618 279 : if (t == error_mark_node)
8619 : remove = true;
8620 279 : else if (!type_dependent_expression_p (t)
8621 279 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8622 : {
8623 0 : error_at (OMP_CLAUSE_LOCATION (c),
8624 : "%qs expression must be integral",
8625 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8626 0 : remove = true;
8627 : }
8628 : else
8629 : {
8630 279 : t = mark_rvalue_use (t);
8631 279 : if (!processing_template_decl)
8632 : {
8633 213 : t = maybe_constant_value (t);
8634 213 : if (TREE_CODE (t) == INTEGER_CST
8635 213 : && tree_int_cst_sgn (t) != 1)
8636 : {
8637 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8638 : "%qs value must be positive",
8639 : omp_clause_code_name
8640 18 : [OMP_CLAUSE_CODE (c)]);
8641 18 : t = NULL_TREE;
8642 : }
8643 : else
8644 195 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8645 213 : tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
8646 213 : if (t
8647 195 : && TREE_CODE (t) == INTEGER_CST
8648 43 : && TREE_CODE (upper) == INTEGER_CST
8649 250 : && tree_int_cst_lt (upper, t))
8650 : {
8651 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8652 : "%<num_teams%> lower bound %qE bigger "
8653 : "than upper bound %qE", t, upper);
8654 18 : t = NULL_TREE;
8655 : }
8656 : }
8657 279 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
8658 : }
8659 : }
8660 : break;
8661 :
8662 3892 : case OMP_CLAUSE_SCHEDULE:
8663 3892 : t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
8664 3892 : if (t == NULL)
8665 : ;
8666 2093 : else if (t == error_mark_node)
8667 : remove = true;
8668 2093 : else if (!type_dependent_expression_p (t)
8669 2093 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8670 : {
8671 9 : error_at (OMP_CLAUSE_LOCATION (c),
8672 : "schedule chunk size expression must be integral");
8673 9 : remove = true;
8674 : }
8675 : else
8676 : {
8677 2084 : t = mark_rvalue_use (t);
8678 2084 : if (!processing_template_decl)
8679 : {
8680 2044 : t = maybe_constant_value (t);
8681 2044 : if (TREE_CODE (t) == INTEGER_CST
8682 2044 : && tree_int_cst_sgn (t) != 1)
8683 : {
8684 6 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8685 : "chunk size value must be positive");
8686 6 : t = integer_one_node;
8687 : }
8688 2044 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8689 : }
8690 2084 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8691 : }
8692 2093 : if (!remove)
8693 : schedule_seen = true;
8694 : break;
8695 :
8696 1268 : case OMP_CLAUSE_SIMDLEN:
8697 1268 : case OMP_CLAUSE_SAFELEN:
8698 1268 : t = OMP_CLAUSE_OPERAND (c, 0);
8699 1268 : if (t == error_mark_node)
8700 : remove = true;
8701 1268 : else if (!type_dependent_expression_p (t)
8702 1268 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8703 : {
8704 0 : error_at (OMP_CLAUSE_LOCATION (c),
8705 : "%qs length expression must be integral",
8706 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8707 0 : remove = true;
8708 : }
8709 : else
8710 : {
8711 1268 : t = mark_rvalue_use (t);
8712 1268 : if (!processing_template_decl)
8713 : {
8714 1219 : t = maybe_constant_value (t);
8715 1219 : if (TREE_CODE (t) != INTEGER_CST
8716 1219 : || tree_int_cst_sgn (t) != 1)
8717 : {
8718 0 : error_at (OMP_CLAUSE_LOCATION (c),
8719 : "%qs length expression must be positive "
8720 : "constant integer expression",
8721 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8722 0 : remove = true;
8723 : }
8724 : }
8725 1268 : OMP_CLAUSE_OPERAND (c, 0) = t;
8726 1268 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
8727 470 : safelen = c;
8728 : }
8729 : break;
8730 :
8731 388 : case OMP_CLAUSE_ASYNC:
8732 388 : t = OMP_CLAUSE_ASYNC_EXPR (c);
8733 388 : if (t == error_mark_node)
8734 : remove = true;
8735 373 : else if (!type_dependent_expression_p (t)
8736 373 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8737 : {
8738 12 : error_at (OMP_CLAUSE_LOCATION (c),
8739 : "%<async%> expression must be integral");
8740 12 : remove = true;
8741 : }
8742 : else
8743 : {
8744 361 : t = mark_rvalue_use (t);
8745 361 : if (!processing_template_decl)
8746 352 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8747 361 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
8748 : }
8749 : break;
8750 :
8751 204 : case OMP_CLAUSE_WAIT:
8752 204 : t = OMP_CLAUSE_WAIT_EXPR (c);
8753 204 : if (t == error_mark_node)
8754 : remove = true;
8755 204 : else if (!processing_template_decl)
8756 196 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8757 204 : OMP_CLAUSE_WAIT_EXPR (c) = t;
8758 204 : break;
8759 :
8760 637 : case OMP_CLAUSE_THREAD_LIMIT:
8761 637 : t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
8762 637 : if (t == error_mark_node)
8763 : remove = true;
8764 637 : else if (!type_dependent_expression_p (t)
8765 637 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8766 : {
8767 0 : error_at (OMP_CLAUSE_LOCATION (c),
8768 : "%<thread_limit%> expression must be integral");
8769 0 : remove = true;
8770 : }
8771 : else
8772 : {
8773 637 : t = mark_rvalue_use (t);
8774 637 : if (!processing_template_decl)
8775 : {
8776 583 : t = maybe_constant_value (t);
8777 583 : if (TREE_CODE (t) == INTEGER_CST
8778 583 : && tree_int_cst_sgn (t) != 1)
8779 : {
8780 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8781 : "%<thread_limit%> value must be positive");
8782 0 : t = integer_one_node;
8783 : }
8784 583 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8785 : }
8786 637 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
8787 : }
8788 : break;
8789 :
8790 770 : case OMP_CLAUSE_DEVICE:
8791 770 : t = OMP_CLAUSE_DEVICE_ID (c);
8792 770 : if (t == error_mark_node)
8793 : remove = true;
8794 770 : else if (!type_dependent_expression_p (t)
8795 770 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8796 : {
8797 6 : error_at (OMP_CLAUSE_LOCATION (c),
8798 : "%<device%> id must be integral");
8799 6 : remove = true;
8800 : }
8801 764 : else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
8802 66 : && TREE_CODE (t) == INTEGER_CST
8803 824 : && !integer_onep (t))
8804 : {
8805 3 : error_at (OMP_CLAUSE_LOCATION (c),
8806 : "the %<device%> clause expression must evaluate to "
8807 : "%<1%>");
8808 3 : remove = true;
8809 : }
8810 : else
8811 : {
8812 761 : t = mark_rvalue_use (t);
8813 761 : if (!processing_template_decl)
8814 750 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8815 761 : OMP_CLAUSE_DEVICE_ID (c) = t;
8816 : }
8817 : break;
8818 :
8819 1848 : case OMP_CLAUSE_DIST_SCHEDULE:
8820 1848 : t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
8821 1848 : if (t == NULL)
8822 : ;
8823 1827 : else if (t == error_mark_node)
8824 : remove = true;
8825 1827 : else if (!type_dependent_expression_p (t)
8826 1827 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8827 : {
8828 0 : error_at (OMP_CLAUSE_LOCATION (c),
8829 : "%<dist_schedule%> chunk size expression must be "
8830 : "integral");
8831 0 : remove = true;
8832 : }
8833 : else
8834 : {
8835 1827 : t = mark_rvalue_use (t);
8836 1827 : if (!processing_template_decl)
8837 1827 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8838 1827 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
8839 : }
8840 : break;
8841 :
8842 807 : case OMP_CLAUSE_ALIGNED:
8843 807 : t = OMP_CLAUSE_DECL (c);
8844 807 : if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
8845 : {
8846 0 : error_at (OMP_CLAUSE_LOCATION (c),
8847 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8848 : " clauses");
8849 0 : remove = true;
8850 0 : break;
8851 : }
8852 807 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8853 : {
8854 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8855 : break;
8856 0 : if (DECL_P (t))
8857 0 : error_at (OMP_CLAUSE_LOCATION (c),
8858 : "%qD is not a variable in %<aligned%> clause", t);
8859 : else
8860 0 : error_at (OMP_CLAUSE_LOCATION (c),
8861 : "%qE is not a variable in %<aligned%> clause", t);
8862 : remove = true;
8863 : }
8864 807 : else if (!type_dependent_expression_p (t)
8865 789 : && !TYPE_PTR_P (TREE_TYPE (t))
8866 111 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
8867 864 : && (!TYPE_REF_P (TREE_TYPE (t))
8868 39 : || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
8869 30 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
8870 : != ARRAY_TYPE))))
8871 : {
8872 33 : error_at (OMP_CLAUSE_LOCATION (c),
8873 : "%qE in %<aligned%> clause is neither a pointer nor "
8874 : "an array nor a reference to pointer or array", t);
8875 33 : remove = true;
8876 : }
8877 774 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8878 : {
8879 0 : error_at (OMP_CLAUSE_LOCATION (c),
8880 : "%qD appears more than once in %<aligned%> clauses",
8881 : t);
8882 0 : remove = true;
8883 : }
8884 : else
8885 774 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8886 807 : t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
8887 807 : if (t == error_mark_node)
8888 : remove = true;
8889 807 : else if (t == NULL_TREE)
8890 : break;
8891 744 : else if (!type_dependent_expression_p (t)
8892 744 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8893 : {
8894 0 : error_at (OMP_CLAUSE_LOCATION (c),
8895 : "%<aligned%> clause alignment expression must "
8896 : "be integral");
8897 0 : remove = true;
8898 : }
8899 : else
8900 : {
8901 744 : t = mark_rvalue_use (t);
8902 744 : if (!processing_template_decl)
8903 : {
8904 690 : t = maybe_constant_value (t);
8905 690 : if (TREE_CODE (t) != INTEGER_CST
8906 690 : || tree_int_cst_sgn (t) != 1)
8907 : {
8908 0 : error_at (OMP_CLAUSE_LOCATION (c),
8909 : "%<aligned%> clause alignment expression must "
8910 : "be positive constant integer expression");
8911 0 : remove = true;
8912 : }
8913 : }
8914 744 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
8915 : }
8916 : break;
8917 :
8918 369 : case OMP_CLAUSE_NONTEMPORAL:
8919 369 : t = OMP_CLAUSE_DECL (c);
8920 369 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8921 : {
8922 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8923 : break;
8924 0 : if (DECL_P (t))
8925 0 : error_at (OMP_CLAUSE_LOCATION (c),
8926 : "%qD is not a variable in %<nontemporal%> clause",
8927 : t);
8928 : else
8929 0 : error_at (OMP_CLAUSE_LOCATION (c),
8930 : "%qE is not a variable in %<nontemporal%> clause",
8931 : t);
8932 : remove = true;
8933 : }
8934 369 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8935 : {
8936 6 : error_at (OMP_CLAUSE_LOCATION (c),
8937 : "%qD appears more than once in %<nontemporal%> "
8938 : "clauses", t);
8939 6 : remove = true;
8940 : }
8941 : else
8942 363 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8943 : break;
8944 :
8945 2809 : case OMP_CLAUSE_ALLOCATE:
8946 2809 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8947 2809 : if (t)
8948 14 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8949 : else
8950 2795 : t = OMP_CLAUSE_DECL (c);
8951 2809 : if (t == current_class_ptr)
8952 : {
8953 0 : error_at (OMP_CLAUSE_LOCATION (c),
8954 : "%<this%> not allowed in %<allocate%> clause");
8955 0 : remove = true;
8956 0 : break;
8957 : }
8958 2809 : if (!VAR_P (t)
8959 678 : && TREE_CODE (t) != PARM_DECL
8960 45 : && TREE_CODE (t) != FIELD_DECL)
8961 : {
8962 3 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8963 : break;
8964 3 : if (DECL_P (t))
8965 3 : error_at (OMP_CLAUSE_LOCATION (c),
8966 : "%qD is not a variable in %<allocate%> clause", t);
8967 : else
8968 0 : error_at (OMP_CLAUSE_LOCATION (c),
8969 : "%qE is not a variable in %<allocate%> clause", t);
8970 : remove = true;
8971 : }
8972 2806 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8973 : {
8974 12 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8975 : "%qD appears more than once in %<allocate%> clauses",
8976 : t);
8977 12 : remove = true;
8978 : }
8979 : else
8980 : {
8981 2794 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8982 2794 : allocate_seen = true;
8983 : }
8984 2809 : tree allocator, align;
8985 2809 : align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
8986 2809 : if (error_operand_p (align))
8987 : {
8988 : remove = true;
8989 : break;
8990 : }
8991 2809 : if (align)
8992 : {
8993 211 : if (!type_dependent_expression_p (align)
8994 211 : && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
8995 : {
8996 4 : error_at (OMP_CLAUSE_LOCATION (c),
8997 : "%<allocate%> clause %<align%> modifier "
8998 : "argument needs to be positive constant "
8999 : "power of two integer expression");
9000 4 : remove = true;
9001 : }
9002 : else
9003 : {
9004 207 : align = mark_rvalue_use (align);
9005 207 : if (!processing_template_decl)
9006 : {
9007 192 : align = maybe_constant_value (align);
9008 192 : if (TREE_CODE (align) != INTEGER_CST
9009 189 : || !tree_fits_uhwi_p (align)
9010 381 : || !integer_pow2p (align))
9011 : {
9012 10 : error_at (OMP_CLAUSE_LOCATION (c),
9013 : "%<allocate%> clause %<align%> modifier "
9014 : "argument needs to be positive constant "
9015 : "power of two integer expression");
9016 10 : remove = true;
9017 : }
9018 : }
9019 : }
9020 211 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
9021 : }
9022 2809 : allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
9023 2809 : if (error_operand_p (allocator))
9024 : {
9025 : remove = true;
9026 : break;
9027 : }
9028 2809 : if (allocator == NULL_TREE)
9029 1751 : goto handle_field_decl;
9030 1058 : tree allocatort;
9031 1058 : allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
9032 1058 : if (!type_dependent_expression_p (allocator)
9033 1058 : && (TREE_CODE (allocatort) != ENUMERAL_TYPE
9034 1039 : || TYPE_NAME (allocatort) == NULL_TREE
9035 1039 : || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
9036 2078 : || (DECL_NAME (TYPE_NAME (allocatort))
9037 1039 : != get_identifier ("omp_allocator_handle_t"))
9038 1039 : || (TYPE_CONTEXT (allocatort)
9039 1039 : != DECL_CONTEXT (global_namespace))))
9040 : {
9041 16 : error_at (OMP_CLAUSE_LOCATION (c),
9042 : "%<allocate%> clause allocator expression has "
9043 : "type %qT rather than %<omp_allocator_handle_t%>",
9044 16 : TREE_TYPE (allocator));
9045 16 : remove = true;
9046 16 : break;
9047 : }
9048 : else
9049 : {
9050 1042 : allocator = mark_rvalue_use (allocator);
9051 1042 : if (!processing_template_decl)
9052 1023 : allocator = maybe_constant_value (allocator);
9053 1042 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
9054 : }
9055 1042 : goto handle_field_decl;
9056 :
9057 654 : case OMP_CLAUSE_DOACROSS:
9058 654 : t = OMP_CLAUSE_DECL (c);
9059 654 : if (t == NULL_TREE)
9060 : break;
9061 298 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
9062 : {
9063 298 : if (cp_finish_omp_clause_doacross_sink (c))
9064 98453 : remove = true;
9065 : break;
9066 : }
9067 0 : gcc_unreachable ();
9068 89 : case OMP_CLAUSE_USES_ALLOCATORS:
9069 89 : t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
9070 89 : t = convert_from_reference (t);
9071 89 : if (t == error_mark_node)
9072 : {
9073 : remove = true;
9074 : break;
9075 : }
9076 82 : if (DECL_P (t)
9077 82 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
9078 79 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9079 78 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
9080 : {
9081 1 : error_at (OMP_CLAUSE_LOCATION (c),
9082 : "%qE appears more than once in data clauses", t);
9083 1 : remove = true;
9084 : }
9085 81 : else if (DECL_P (t))
9086 78 : bitmap_set_bit (&generic_head, DECL_UID (t));
9087 82 : if (type_dependent_expression_p (t))
9088 : break;
9089 77 : if (TREE_CODE (t) == FIELD_DECL)
9090 : {
9091 0 : sorry_at (OMP_CLAUSE_LOCATION (c), "class member %qE not yet "
9092 : "supported in %<uses_allocators%> clause", t);
9093 0 : remove = true;
9094 0 : break;
9095 : }
9096 77 : if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9097 151 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9098 : "omp_allocator_handle_t") != 0)
9099 : {
9100 3 : error_at (OMP_CLAUSE_LOCATION (c),
9101 : "allocator %qE must be of %<omp_allocator_handle_t%> "
9102 : "type", t);
9103 3 : remove = true;
9104 3 : break;
9105 : }
9106 74 : tree init;
9107 74 : if (TREE_CODE (t) == CONST_DECL)
9108 7 : init = DECL_INITIAL(t);
9109 : else
9110 : init = t;
9111 74 : if (!DECL_P (t)
9112 74 : && (init == NULL_TREE
9113 3 : || TREE_CODE (init) != INTEGER_CST
9114 3 : || ((wi::to_widest (init) < 0
9115 3 : || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
9116 1 : && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
9117 1 : || (wi::to_widest (init)
9118 2 : > GOMP_OMPX_PREDEF_ALLOC_MAX)))))
9119 : {
9120 1 : remove = true;
9121 1 : error_at (OMP_CLAUSE_LOCATION (c),
9122 : "allocator %qE must be either a variable or a "
9123 : "predefined allocator", t);
9124 1 : break;
9125 : }
9126 73 : else if (TREE_CODE (t) == CONST_DECL)
9127 : {
9128 : /* omp_null_allocator is ignored and for predefined allocators,
9129 : not special handling is required; thus, remove them removed. */
9130 7 : remove = true;
9131 :
9132 7 : if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
9133 7 : || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
9134 : {
9135 0 : error_at (OMP_CLAUSE_LOCATION (c),
9136 : "modifiers cannot be used with predefined "
9137 : "allocators");
9138 0 : break;
9139 : }
9140 : }
9141 73 : t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
9142 73 : if (t == error_mark_node)
9143 : {
9144 : remove = true;
9145 : break;
9146 : }
9147 72 : if (t != NULL_TREE
9148 16 : && !type_dependent_expression_p (t)
9149 88 : && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
9150 15 : || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9151 28 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9152 : "omp_memspace_handle_t") != 0))
9153 : {
9154 2 : error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
9155 : " constant enum of %<omp_memspace_handle_t%> type", t);
9156 2 : remove = true;
9157 2 : break;
9158 : }
9159 70 : t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
9160 70 : if (t == error_mark_node)
9161 : {
9162 : remove = true;
9163 : break;
9164 : }
9165 69 : if (type_dependent_expression_p (t))
9166 : break;
9167 69 : if (t != NULL_TREE
9168 41 : && t != error_mark_node
9169 41 : && !type_dependent_expression_p (t)
9170 110 : && (!DECL_P (t)
9171 41 : || DECL_EXTERNAL (t)
9172 39 : || TREE_CODE (t) == PARM_DECL))
9173 : {
9174 4 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
9175 : "defined in same scope as the construct on which the "
9176 : "clause appears", t);
9177 4 : remove = true;
9178 : }
9179 69 : if (t != NULL_TREE)
9180 : {
9181 41 : bool type_err = false;
9182 :
9183 41 : if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
9184 39 : || DECL_SIZE (t) == NULL_TREE
9185 79 : || !COMPLETE_TYPE_P (TREE_TYPE (t)))
9186 : type_err = true;
9187 : else
9188 : {
9189 38 : tree elem_t = TREE_TYPE (TREE_TYPE (t));
9190 38 : if (TREE_CODE (elem_t) != RECORD_TYPE
9191 76 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
9192 : "omp_alloctrait_t") != 0
9193 76 : || !TYPE_READONLY (elem_t))
9194 : type_err = true;
9195 : }
9196 37 : if (type_err)
9197 : {
9198 4 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
9199 : "be of %<const omp_alloctrait_t []%> type", t);
9200 4 : remove = true;
9201 : }
9202 37 : else if (TREE_CODE (array_type_nelts_top (TREE_TYPE (t)))
9203 : != INTEGER_CST)
9204 : {
9205 1 : error_at (OMP_CLAUSE_LOCATION (c), "variable length traits "
9206 : "arrays are not supported");
9207 1 : remove = true;
9208 : }
9209 : else
9210 : {
9211 36 : tree cst_val = decl_constant_value (t);
9212 36 : if (cst_val == t)
9213 : {
9214 1 : error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
9215 : "initialized with constants");
9216 1 : remove = true;
9217 : }
9218 : }
9219 : }
9220 69 : if (remove)
9221 : break;
9222 55 : pc = &OMP_CLAUSE_CHAIN (c);
9223 55 : continue;
9224 1807 : case OMP_CLAUSE_DEPEND:
9225 1807 : depend_clause = c;
9226 : /* FALLTHRU */
9227 2416 : case OMP_CLAUSE_AFFINITY:
9228 2416 : t = OMP_CLAUSE_DECL (c);
9229 2416 : if (OMP_ITERATOR_DECL_P (t))
9230 : {
9231 623 : if (TREE_PURPOSE (t) != last_iterators)
9232 525 : last_iterators_remove
9233 525 : = cp_omp_finish_iterators (TREE_PURPOSE (t));
9234 623 : last_iterators = TREE_PURPOSE (t);
9235 623 : t = TREE_VALUE (t);
9236 623 : if (last_iterators_remove)
9237 144 : t = error_mark_node;
9238 : }
9239 : else
9240 : last_iterators = NULL_TREE;
9241 :
9242 2416 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9243 : {
9244 1368 : if (handle_omp_array_sections (c, ort))
9245 : remove = true;
9246 1014 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9247 1014 : && (OMP_CLAUSE_DEPEND_KIND (c)
9248 : == OMP_CLAUSE_DEPEND_DEPOBJ))
9249 : {
9250 6 : error_at (OMP_CLAUSE_LOCATION (c),
9251 : "%<depend%> clause with %<depobj%> dependence "
9252 : "type on array section");
9253 6 : remove = true;
9254 : }
9255 : break;
9256 : }
9257 1048 : if (t == error_mark_node)
9258 : remove = true;
9259 886 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9260 886 : && t == ridpointers[RID_OMP_ALL_MEMORY])
9261 : {
9262 33 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
9263 33 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
9264 : {
9265 9 : error_at (OMP_CLAUSE_LOCATION (c),
9266 : "%<omp_all_memory%> used with %<depend%> kind "
9267 : "other than %<out%> or %<inout%>");
9268 9 : remove = true;
9269 : }
9270 33 : if (processing_template_decl)
9271 : break;
9272 : }
9273 853 : else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9274 : break;
9275 661 : else if (!lvalue_p (t))
9276 : {
9277 21 : if (DECL_P (t))
9278 24 : error_at (OMP_CLAUSE_LOCATION (c),
9279 : "%qD is not lvalue expression nor array section "
9280 : "in %qs clause", t,
9281 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9282 : else
9283 18 : error_at (OMP_CLAUSE_LOCATION (c),
9284 : "%qE is not lvalue expression nor array section "
9285 : "in %qs clause", t,
9286 9 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9287 : remove = true;
9288 : }
9289 640 : else if (TREE_CODE (t) == COMPONENT_REF
9290 36 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
9291 676 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
9292 : {
9293 12 : error_at (OMP_CLAUSE_LOCATION (c),
9294 : "bit-field %qE in %qs clause", t,
9295 6 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9296 6 : remove = true;
9297 : }
9298 634 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9299 634 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
9300 : {
9301 130 : if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9302 8 : ? TREE_TYPE (TREE_TYPE (t))
9303 57 : : TREE_TYPE (t)))
9304 : {
9305 12 : error_at (OMP_CLAUSE_LOCATION (c),
9306 : "%qE does not have %<omp_depend_t%> type in "
9307 : "%<depend%> clause with %<depobj%> dependence "
9308 : "type", t);
9309 12 : remove = true;
9310 : }
9311 : }
9312 569 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9313 1010 : && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9314 4 : ? TREE_TYPE (TREE_TYPE (t))
9315 437 : : TREE_TYPE (t)))
9316 : {
9317 15 : error_at (OMP_CLAUSE_LOCATION (c),
9318 : "%qE should not have %<omp_depend_t%> type in "
9319 : "%<depend%> clause with dependence type other than "
9320 : "%<depobj%>", t);
9321 15 : remove = true;
9322 : }
9323 87 : if (!remove)
9324 : {
9325 631 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
9326 24 : t = null_pointer_node;
9327 : else
9328 : {
9329 607 : tree addr = cp_build_addr_expr (t, tf_warning_or_error);
9330 607 : if (addr == error_mark_node)
9331 : {
9332 : remove = true;
9333 : break;
9334 : }
9335 607 : t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
9336 : addr, RO_UNARY_STAR,
9337 : tf_warning_or_error);
9338 607 : if (t == error_mark_node)
9339 : {
9340 : remove = true;
9341 : break;
9342 : }
9343 : }
9344 631 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
9345 137 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
9346 768 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
9347 : == TREE_VEC))
9348 137 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
9349 : else
9350 494 : OMP_CLAUSE_DECL (c) = t;
9351 : }
9352 : break;
9353 69 : case OMP_CLAUSE_DETACH:
9354 69 : t = OMP_CLAUSE_DECL (c);
9355 69 : if (detach_seen)
9356 : {
9357 3 : error_at (OMP_CLAUSE_LOCATION (c),
9358 : "too many %qs clauses on a task construct",
9359 : "detach");
9360 3 : remove = true;
9361 3 : break;
9362 : }
9363 66 : else if (error_operand_p (t))
9364 : {
9365 : remove = true;
9366 : break;
9367 : }
9368 : else
9369 : {
9370 63 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
9371 63 : if (!type_dependent_expression_p (t)
9372 63 : && (!INTEGRAL_TYPE_P (type)
9373 : || TREE_CODE (type) != ENUMERAL_TYPE
9374 51 : || TYPE_NAME (type) == NULL_TREE
9375 102 : || (DECL_NAME (TYPE_NAME (type))
9376 51 : != get_identifier ("omp_event_handle_t"))))
9377 : {
9378 6 : error_at (OMP_CLAUSE_LOCATION (c),
9379 : "%<detach%> clause event handle "
9380 : "has type %qT rather than "
9381 : "%<omp_event_handle_t%>",
9382 : type);
9383 6 : remove = true;
9384 : }
9385 63 : detach_seen = c;
9386 63 : cxx_mark_addressable (t);
9387 : }
9388 63 : break;
9389 :
9390 16349 : case OMP_CLAUSE_MAP:
9391 16349 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
9392 157 : goto move_implicit;
9393 16192 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
9394 16192 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
9395 : {
9396 : remove = true;
9397 : break;
9398 : }
9399 : /* FALLTHRU */
9400 19370 : case OMP_CLAUSE_TO:
9401 19370 : case OMP_CLAUSE_FROM:
9402 19370 : if (OMP_CLAUSE_ITERATORS (c)
9403 19370 : && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
9404 : {
9405 98453 : t = error_mark_node;
9406 : break;
9407 : }
9408 : /* FALLTHRU */
9409 20258 : case OMP_CLAUSE__CACHE_:
9410 20258 : {
9411 20258 : using namespace omp_addr_tokenizer;
9412 20258 : auto_vec<omp_addr_token *, 10> addr_tokens;
9413 :
9414 20258 : t = OMP_CLAUSE_DECL (c);
9415 20258 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9416 : {
9417 5997 : grp_start_p = pc;
9418 5997 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9419 :
9420 5997 : if (handle_omp_array_sections (c, ort))
9421 : remove = true;
9422 : else
9423 : {
9424 5187 : t = OMP_CLAUSE_DECL (c);
9425 5187 : if (TREE_CODE (t) != OMP_ARRAY_SECTION
9426 4326 : && !type_dependent_expression_p (t)
9427 9513 : && !omp_mappable_type (TREE_TYPE (t)))
9428 : {
9429 3 : auto_diagnostic_group d;
9430 6 : error_at (OMP_CLAUSE_LOCATION (c),
9431 : "array section does not have mappable type "
9432 : "in %qs clause",
9433 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9434 3 : if (TREE_TYPE (t) != error_mark_node
9435 3 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9436 3 : cxx_incomplete_type_inform (TREE_TYPE (t));
9437 3 : remove = true;
9438 3 : }
9439 7112 : while (TREE_CODE (t) == ARRAY_REF)
9440 1925 : t = TREE_OPERAND (t, 0);
9441 :
9442 5187 : if (type_dependent_expression_p (t))
9443 : break;
9444 :
9445 4713 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9446 :
9447 4713 : if (!ai.map_supported_p ()
9448 4713 : || !omp_parse_expr (addr_tokens, t))
9449 : {
9450 18 : sorry_at (OMP_CLAUSE_LOCATION (c),
9451 : "unsupported map expression %qE",
9452 9 : OMP_CLAUSE_DECL (c));
9453 9 : remove = true;
9454 9 : break;
9455 : }
9456 :
9457 : /* This check is to determine if this will be the only map
9458 : node created for this clause. Otherwise, we'll check
9459 : the following FIRSTPRIVATE_POINTER,
9460 : FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
9461 : iteration(s) of the loop. */
9462 9359 : if (addr_tokens.length () >= 4
9463 1063 : && addr_tokens[0]->type == STRUCTURE_BASE
9464 1057 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
9465 1057 : && addr_tokens[1]->type == ACCESS_METHOD
9466 1057 : && addr_tokens[2]->type == COMPONENT_SELECTOR
9467 977 : && addr_tokens[3]->type == ACCESS_METHOD
9468 5418 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
9469 551 : || (addr_tokens[3]->u.access_kind
9470 : == ACCESS_INDEXED_ARRAY)))
9471 : {
9472 165 : tree rt = addr_tokens[1]->expr;
9473 :
9474 165 : gcc_assert (DECL_P (rt));
9475 :
9476 165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9477 154 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9478 165 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
9479 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
9480 0 : || bitmap_bit_p (&map_firstprivate_head,
9481 0 : DECL_UID (rt))))
9482 : {
9483 : remove = true;
9484 : break;
9485 : }
9486 165 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
9487 : break;
9488 116 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
9489 : {
9490 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9491 0 : error_at (OMP_CLAUSE_LOCATION (c),
9492 : "%qD appears more than once in motion"
9493 : " clauses", rt);
9494 0 : else if (openacc)
9495 0 : error_at (OMP_CLAUSE_LOCATION (c),
9496 : "%qD appears more than once in data"
9497 : " clauses", rt);
9498 : else
9499 0 : error_at (OMP_CLAUSE_LOCATION (c),
9500 : "%qD appears more than once in map"
9501 : " clauses", rt);
9502 : remove = true;
9503 : }
9504 : else
9505 : {
9506 116 : bitmap_set_bit (&map_head, DECL_UID (rt));
9507 116 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
9508 : }
9509 : }
9510 4713 : }
9511 5465 : if (cp_oacc_check_attachments (c))
9512 12 : remove = true;
9513 5465 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9514 4484 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9515 4420 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9516 5563 : && !OMP_CLAUSE_SIZE (c))
9517 : /* In this case, we have a single array element which is a
9518 : pointer, and we already set OMP_CLAUSE_SIZE in
9519 : handle_omp_array_sections above. For attach/detach
9520 : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
9521 : to zero here. */
9522 60 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9523 : break;
9524 : }
9525 14261 : else if (type_dependent_expression_p (t))
9526 : break;
9527 13478 : else if (!omp_parse_expr (addr_tokens, t))
9528 : {
9529 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
9530 : "unsupported map expression %qE",
9531 0 : OMP_CLAUSE_DECL (c));
9532 0 : remove = true;
9533 0 : break;
9534 : }
9535 13478 : if (t == error_mark_node)
9536 : {
9537 : remove = true;
9538 : break;
9539 : }
9540 : /* OpenACC attach / detach clauses must be pointers. */
9541 13364 : if (cp_oacc_check_attachments (c))
9542 : {
9543 : remove = true;
9544 : break;
9545 : }
9546 13340 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9547 10295 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9548 10246 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9549 13414 : && !OMP_CLAUSE_SIZE (c))
9550 : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
9551 : bias) to zero here, so it is not set erroneously to the
9552 : pointer size later on in gimplify.cc. */
9553 66 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9554 :
9555 13340 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9556 :
9557 13340 : if (!ai.check_clause (c))
9558 : {
9559 : remove = true;
9560 : break;
9561 : }
9562 :
9563 13319 : if (!ai.map_supported_p ())
9564 : {
9565 88 : sorry_at (OMP_CLAUSE_LOCATION (c),
9566 : "unsupported map expression %qE",
9567 44 : OMP_CLAUSE_DECL (c));
9568 44 : remove = true;
9569 44 : break;
9570 : }
9571 :
9572 26550 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
9573 : || addr_tokens[0]->type == STRUCTURE_BASE)
9574 : && addr_tokens[1]->type == ACCESS_METHOD);
9575 :
9576 13275 : t = addr_tokens[1]->expr;
9577 :
9578 : /* This is used to prevent cxx_mark_addressable from being called
9579 : on 'this' for expressions like 'this->a', i.e. typical member
9580 : accesses. */
9581 13275 : indir_component_ref_p
9582 26550 : = (addr_tokens[0]->type == STRUCTURE_BASE
9583 13275 : && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
9584 :
9585 13275 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
9586 1 : goto skip_decl_checks;
9587 :
9588 : /* For OpenMP, we can access a struct "t" and "t.d" on the same
9589 : mapping. OpenACC allows multiple fields of the same structure
9590 : to be written. */
9591 13274 : if (addr_tokens[0]->type == STRUCTURE_BASE
9592 13274 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
9593 1263 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
9594 1351 : goto skip_decl_checks;
9595 :
9596 11923 : if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
9597 : {
9598 0 : OMP_CLAUSE_DECL (c)
9599 0 : = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
9600 0 : break;
9601 : }
9602 11923 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9603 : {
9604 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9605 : break;
9606 0 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9607 0 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9608 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
9609 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
9610 0 : || (!openacc && EXPR_P (t))))
9611 : break;
9612 0 : if (DECL_P (t))
9613 0 : error_at (OMP_CLAUSE_LOCATION (c),
9614 : "%qD is not a variable in %qs clause", t,
9615 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9616 : else
9617 0 : error_at (OMP_CLAUSE_LOCATION (c),
9618 : "%qE is not a variable in %qs clause", t,
9619 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9620 : remove = true;
9621 : }
9622 11923 : else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
9623 : {
9624 0 : error_at (OMP_CLAUSE_LOCATION (c),
9625 : "%qD is threadprivate variable in %qs clause", t,
9626 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9627 0 : remove = true;
9628 : }
9629 11923 : else if (!processing_template_decl
9630 11744 : && !TYPE_REF_P (TREE_TYPE (t))
9631 11067 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9632 8132 : || (OMP_CLAUSE_MAP_KIND (c)
9633 : != GOMP_MAP_FIRSTPRIVATE_POINTER))
9634 9084 : && !indir_component_ref_p
9635 8720 : && (t != current_class_ptr
9636 18 : || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9637 6 : || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
9638 20643 : && !cxx_mark_addressable (t))
9639 : remove = true;
9640 11923 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9641 8970 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9642 8970 : || (OMP_CLAUSE_MAP_KIND (c)
9643 : == GOMP_MAP_FIRSTPRIVATE_POINTER)
9644 6987 : || (OMP_CLAUSE_MAP_KIND (c)
9645 : == GOMP_MAP_ATTACH_DETACH)))
9646 9280 : && t == OMP_CLAUSE_DECL (c)
9647 8582 : && !type_dependent_expression_p (t)
9648 29087 : && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
9649 278 : ? TREE_TYPE (TREE_TYPE (t))
9650 8304 : : TREE_TYPE (t)))
9651 : {
9652 42 : auto_diagnostic_group d;
9653 84 : error_at (OMP_CLAUSE_LOCATION (c),
9654 : "%qD does not have a mappable type in %qs clause", t,
9655 42 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9656 42 : if (TREE_TYPE (t) != error_mark_node
9657 42 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9658 39 : cxx_incomplete_type_inform (TREE_TYPE (t));
9659 42 : remove = true;
9660 42 : }
9661 11881 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9662 8934 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
9663 93 : && !type_dependent_expression_p (t)
9664 11974 : && !INDIRECT_TYPE_P (TREE_TYPE (t)))
9665 : {
9666 6 : error_at (OMP_CLAUSE_LOCATION (c),
9667 : "%qD is not a pointer variable", t);
9668 6 : remove = true;
9669 : }
9670 11875 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9671 8928 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9672 12245 : && (bitmap_bit_p (&map_head, DECL_UID (t))
9673 367 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
9674 367 : || bitmap_bit_p (&map_firstprivate_head,
9675 367 : DECL_UID (t))))
9676 : remove = true;
9677 11869 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9678 11869 : && (OMP_CLAUSE_MAP_KIND (c)
9679 : == GOMP_MAP_FIRSTPRIVATE_POINTER))
9680 : {
9681 1977 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
9682 1977 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9683 3951 : || (openacc
9684 1364 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
9685 : {
9686 12 : error_at (OMP_CLAUSE_LOCATION (c),
9687 : "%qD appears more than once in data clauses", t);
9688 12 : remove = true;
9689 : }
9690 1965 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9691 12 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9692 1973 : && openacc)
9693 : {
9694 3 : error_at (OMP_CLAUSE_LOCATION (c),
9695 : "%qD appears more than once in data clauses", t);
9696 3 : remove = true;
9697 : }
9698 : else
9699 1962 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9700 : }
9701 9892 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9702 9892 : && (OMP_CLAUSE_MAP_KIND (c)
9703 : == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
9704 115 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9705 9777 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9706 181 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9707 38 : && ort != C_ORT_OMP
9708 38 : && ort != C_ORT_OMP_TARGET
9709 9793 : && ort != C_ORT_OMP_EXIT_DATA)
9710 : {
9711 9 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9712 0 : error_at (OMP_CLAUSE_LOCATION (c),
9713 : "%qD appears more than once in motion clauses", t);
9714 9 : else if (openacc)
9715 9 : error_at (OMP_CLAUSE_LOCATION (c),
9716 : "%qD appears more than once in data clauses", t);
9717 : else
9718 0 : error_at (OMP_CLAUSE_LOCATION (c),
9719 : "%qD appears more than once in map clauses", t);
9720 : remove = true;
9721 : }
9722 9768 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
9723 : {
9724 0 : error_at (OMP_CLAUSE_LOCATION (c),
9725 : "%qD appears more than once in data clauses", t);
9726 0 : remove = true;
9727 : }
9728 9768 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9729 9768 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
9730 : {
9731 27 : if (openacc)
9732 0 : error_at (OMP_CLAUSE_LOCATION (c),
9733 : "%qD appears more than once in data clauses", t);
9734 : else
9735 27 : error_at (OMP_CLAUSE_LOCATION (c),
9736 : "%qD appears both in data and map clauses", t);
9737 : remove = true;
9738 : }
9739 9741 : else if (!omp_access_chain_p (addr_tokens, 1))
9740 : {
9741 9661 : bitmap_set_bit (&map_head, DECL_UID (t));
9742 :
9743 9661 : tree decl = OMP_CLAUSE_DECL (c);
9744 9661 : if (t != decl
9745 9661 : && (TREE_CODE (decl) == COMPONENT_REF
9746 162 : || (INDIRECT_REF_P (decl)
9747 162 : && (TREE_CODE (TREE_OPERAND (decl, 0))
9748 : == COMPONENT_REF)
9749 150 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
9750 : 0))))))
9751 1165 : bitmap_set_bit (&map_field_head, DECL_UID (t));
9752 : }
9753 :
9754 4693 : skip_decl_checks:
9755 : /* If we call ai.expand_map_clause in handle_omp_array_sections,
9756 : the containing loop (here) iterates through the new nodes
9757 : created by that expansion. Avoid expanding those again (just
9758 : by checking the node type). */
9759 4693 : if (!remove
9760 13170 : && !processing_template_decl
9761 12994 : && ort != C_ORT_DECLARE_SIMD
9762 12994 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9763 9967 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
9764 8005 : && (OMP_CLAUSE_MAP_KIND (c)
9765 : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
9766 7890 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
9767 7890 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
9768 6891 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
9769 6842 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
9770 : {
9771 9844 : grp_start_p = pc;
9772 9844 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9773 9844 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
9774 : addr_tokens, ort);
9775 9844 : if (nc != error_mark_node)
9776 9844 : c = nc;
9777 : }
9778 20323 : }
9779 13275 : break;
9780 :
9781 596 : case OMP_CLAUSE_ENTER:
9782 596 : case OMP_CLAUSE_LINK:
9783 596 : t = OMP_CLAUSE_DECL (c);
9784 596 : const char *cname;
9785 596 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
9786 596 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
9787 596 : && OMP_CLAUSE_ENTER_TO (c))
9788 : cname = "to";
9789 596 : if (TREE_CODE (t) == FUNCTION_DECL
9790 596 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9791 : ;
9792 379 : else if (!VAR_P (t))
9793 : {
9794 12 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9795 : {
9796 9 : if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
9797 6 : error_at (OMP_CLAUSE_LOCATION (c),
9798 : "template %qE in clause %qs", t, cname);
9799 3 : else if (really_overloaded_fn (t))
9800 3 : error_at (OMP_CLAUSE_LOCATION (c),
9801 : "overloaded function name %qE in clause %qs", t,
9802 : cname);
9803 : else
9804 0 : error_at (OMP_CLAUSE_LOCATION (c),
9805 : "%qE is neither a variable nor a function name "
9806 : "in clause %qs", t, cname);
9807 : }
9808 : else
9809 3 : error_at (OMP_CLAUSE_LOCATION (c),
9810 : "%qE is not a variable in clause %qs", t, cname);
9811 : remove = true;
9812 : }
9813 367 : else if (DECL_THREAD_LOCAL_P (t))
9814 : {
9815 6 : error_at (OMP_CLAUSE_LOCATION (c),
9816 : "%qD is threadprivate variable in %qs clause", t,
9817 : cname);
9818 6 : remove = true;
9819 : }
9820 361 : else if (!omp_mappable_type (TREE_TYPE (t)))
9821 : {
9822 18 : auto_diagnostic_group d;
9823 18 : error_at (OMP_CLAUSE_LOCATION (c),
9824 : "%qD does not have a mappable type in %qs clause", t,
9825 : cname);
9826 18 : if (TREE_TYPE (t) != error_mark_node
9827 18 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9828 18 : cxx_incomplete_type_inform (TREE_TYPE (t));
9829 18 : remove = true;
9830 18 : }
9831 36 : if (remove)
9832 : break;
9833 560 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9834 : {
9835 24 : error_at (OMP_CLAUSE_LOCATION (c),
9836 : "%qE appears more than once on the same "
9837 : "%<declare target%> directive", t);
9838 24 : remove = true;
9839 : }
9840 : else
9841 536 : bitmap_set_bit (&generic_head, DECL_UID (t));
9842 : break;
9843 :
9844 457 : case OMP_CLAUSE_UNIFORM:
9845 457 : t = OMP_CLAUSE_DECL (c);
9846 457 : if (TREE_CODE (t) != PARM_DECL)
9847 : {
9848 0 : if (processing_template_decl)
9849 : break;
9850 0 : if (DECL_P (t))
9851 0 : error_at (OMP_CLAUSE_LOCATION (c),
9852 : "%qD is not an argument in %<uniform%> clause", t);
9853 : else
9854 0 : error_at (OMP_CLAUSE_LOCATION (c),
9855 : "%qE is not an argument in %<uniform%> clause", t);
9856 : remove = true;
9857 : break;
9858 : }
9859 : /* map_head bitmap is used as uniform_head if declare_simd. */
9860 457 : bitmap_set_bit (&map_head, DECL_UID (t));
9861 457 : goto check_dup_generic;
9862 :
9863 165 : case OMP_CLAUSE_GRAINSIZE:
9864 165 : t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
9865 165 : if (t == error_mark_node)
9866 : remove = true;
9867 165 : else if (!type_dependent_expression_p (t)
9868 165 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9869 : {
9870 0 : error_at (OMP_CLAUSE_LOCATION (c),
9871 : "%<grainsize%> expression must be integral");
9872 0 : remove = true;
9873 : }
9874 : else
9875 : {
9876 165 : t = mark_rvalue_use (t);
9877 165 : if (!processing_template_decl)
9878 : {
9879 164 : t = maybe_constant_value (t);
9880 164 : if (TREE_CODE (t) == INTEGER_CST
9881 164 : && tree_int_cst_sgn (t) != 1)
9882 : {
9883 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9884 : "%<grainsize%> value must be positive");
9885 0 : t = integer_one_node;
9886 : }
9887 164 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9888 : }
9889 165 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
9890 : }
9891 : break;
9892 :
9893 276 : case OMP_CLAUSE_PRIORITY:
9894 276 : t = OMP_CLAUSE_PRIORITY_EXPR (c);
9895 276 : if (t == error_mark_node)
9896 : remove = true;
9897 276 : else if (!type_dependent_expression_p (t)
9898 276 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9899 : {
9900 0 : error_at (OMP_CLAUSE_LOCATION (c),
9901 : "%<priority%> expression must be integral");
9902 0 : remove = true;
9903 : }
9904 : else
9905 : {
9906 276 : t = mark_rvalue_use (t);
9907 276 : if (!processing_template_decl)
9908 : {
9909 276 : t = maybe_constant_value (t);
9910 276 : if (TREE_CODE (t) == INTEGER_CST
9911 276 : && tree_int_cst_sgn (t) == -1)
9912 : {
9913 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9914 : "%<priority%> value must be non-negative");
9915 0 : t = integer_one_node;
9916 : }
9917 276 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9918 : }
9919 276 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
9920 : }
9921 : break;
9922 :
9923 228 : case OMP_CLAUSE_HINT:
9924 228 : t = OMP_CLAUSE_HINT_EXPR (c);
9925 228 : if (t == error_mark_node)
9926 : remove = true;
9927 228 : else if (!type_dependent_expression_p (t)
9928 228 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9929 : {
9930 9 : error_at (OMP_CLAUSE_LOCATION (c),
9931 : "%<hint%> expression must be integral");
9932 9 : remove = true;
9933 : }
9934 : else
9935 : {
9936 219 : t = mark_rvalue_use (t);
9937 219 : if (!processing_template_decl)
9938 : {
9939 171 : t = maybe_constant_value (t);
9940 171 : if (TREE_CODE (t) != INTEGER_CST)
9941 : {
9942 16 : error_at (OMP_CLAUSE_LOCATION (c),
9943 : "%<hint%> expression must be constant integer "
9944 : "expression");
9945 16 : remove = true;
9946 : }
9947 : }
9948 219 : OMP_CLAUSE_HINT_EXPR (c) = t;
9949 : }
9950 : break;
9951 :
9952 186 : case OMP_CLAUSE_FILTER:
9953 186 : t = OMP_CLAUSE_FILTER_EXPR (c);
9954 186 : if (t == error_mark_node)
9955 : remove = true;
9956 186 : else if (!type_dependent_expression_p (t)
9957 186 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9958 : {
9959 6 : error_at (OMP_CLAUSE_LOCATION (c),
9960 : "%<filter%> expression must be integral");
9961 6 : remove = true;
9962 : }
9963 : else
9964 : {
9965 180 : t = mark_rvalue_use (t);
9966 180 : if (!processing_template_decl)
9967 : {
9968 177 : t = maybe_constant_value (t);
9969 177 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9970 : }
9971 180 : OMP_CLAUSE_FILTER_EXPR (c) = t;
9972 : }
9973 : break;
9974 :
9975 433 : case OMP_CLAUSE_IS_DEVICE_PTR:
9976 433 : case OMP_CLAUSE_USE_DEVICE_PTR:
9977 433 : field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
9978 433 : t = OMP_CLAUSE_DECL (c);
9979 433 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
9980 329 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9981 433 : if (!type_dependent_expression_p (t))
9982 : {
9983 431 : tree type = TREE_TYPE (t);
9984 431 : if (!TYPE_PTR_P (type)
9985 431 : && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
9986 : {
9987 57 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
9988 57 : && ort == C_ORT_OMP)
9989 : {
9990 3 : error_at (OMP_CLAUSE_LOCATION (c),
9991 : "%qs variable is neither a pointer "
9992 : "nor reference to pointer",
9993 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9994 3 : remove = true;
9995 : }
9996 54 : else if (TREE_CODE (type) != ARRAY_TYPE
9997 54 : && (!TYPE_REF_P (type)
9998 2 : || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
9999 : {
10000 12 : error_at (OMP_CLAUSE_LOCATION (c),
10001 : "%qs variable is neither a pointer, nor an "
10002 : "array nor reference to pointer or array",
10003 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10004 12 : remove = true;
10005 : }
10006 : }
10007 : }
10008 433 : goto check_dup_generic;
10009 :
10010 267 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
10011 267 : t = OMP_CLAUSE_DECL (c);
10012 267 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10013 : {
10014 28 : if (handle_omp_array_sections (c, ort))
10015 : remove = true;
10016 : else
10017 : {
10018 28 : t = OMP_CLAUSE_DECL (c);
10019 30 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10020 2 : t = TREE_OPERAND (t, 0);
10021 64 : while (INDIRECT_REF_P (t)
10022 64 : || TREE_CODE (t) == ARRAY_REF)
10023 36 : t = TREE_OPERAND (t, 0);
10024 : }
10025 : }
10026 267 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
10027 : {
10028 267 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
10029 267 : if (!processing_template_decl
10030 267 : && !cxx_mark_addressable (t))
10031 : remove = true;
10032 : }
10033 267 : goto check_dup_generic_t;
10034 :
10035 76 : case OMP_CLAUSE_USE_DEVICE_ADDR:
10036 76 : field_ok = true;
10037 76 : t = OMP_CLAUSE_DECL (c);
10038 76 : if (!processing_template_decl
10039 74 : && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
10040 74 : && !TYPE_REF_P (TREE_TYPE (t))
10041 143 : && !cxx_mark_addressable (t))
10042 : remove = true;
10043 76 : goto check_dup_generic;
10044 :
10045 : case OMP_CLAUSE_NOWAIT:
10046 : case OMP_CLAUSE_DEFAULT:
10047 : case OMP_CLAUSE_UNTIED:
10048 : case OMP_CLAUSE_COLLAPSE:
10049 : case OMP_CLAUSE_PARALLEL:
10050 : case OMP_CLAUSE_FOR:
10051 : case OMP_CLAUSE_SECTIONS:
10052 : case OMP_CLAUSE_TASKGROUP:
10053 : case OMP_CLAUSE_PROC_BIND:
10054 : case OMP_CLAUSE_DEVICE_TYPE:
10055 : case OMP_CLAUSE_NOGROUP:
10056 : case OMP_CLAUSE_THREADS:
10057 : case OMP_CLAUSE_SIMD:
10058 : case OMP_CLAUSE_DEFAULTMAP:
10059 : case OMP_CLAUSE_BIND:
10060 : case OMP_CLAUSE_AUTO:
10061 : case OMP_CLAUSE_INDEPENDENT:
10062 : case OMP_CLAUSE_SEQ:
10063 : case OMP_CLAUSE_IF_PRESENT:
10064 : case OMP_CLAUSE_FINALIZE:
10065 : case OMP_CLAUSE_NOHOST:
10066 : case OMP_CLAUSE_INDIRECT:
10067 : break;
10068 :
10069 231 : case OMP_CLAUSE_MERGEABLE:
10070 231 : mergeable_seen = true;
10071 231 : break;
10072 :
10073 322 : case OMP_CLAUSE_TILE:
10074 754 : for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
10075 432 : list = TREE_CHAIN (list))
10076 : {
10077 432 : t = TREE_VALUE (list);
10078 :
10079 432 : if (t == error_mark_node)
10080 : remove = true;
10081 403 : else if (!type_dependent_expression_p (t)
10082 403 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10083 : {
10084 3 : error_at (OMP_CLAUSE_LOCATION (c),
10085 : "%<tile%> argument needs integral type");
10086 3 : remove = true;
10087 : }
10088 : else
10089 : {
10090 400 : t = mark_rvalue_use (t);
10091 400 : if (!processing_template_decl)
10092 : {
10093 : /* Zero is used to indicate '*', we permit you
10094 : to get there via an ICE of value zero. */
10095 385 : t = maybe_constant_value (t);
10096 385 : if (!tree_fits_shwi_p (t)
10097 369 : || tree_to_shwi (t) < 0)
10098 : {
10099 40 : error_at (OMP_CLAUSE_LOCATION (c),
10100 : "%<tile%> argument needs positive "
10101 : "integral constant");
10102 40 : remove = true;
10103 : }
10104 : }
10105 : }
10106 :
10107 : /* Update list item. */
10108 432 : TREE_VALUE (list) = t;
10109 : }
10110 : break;
10111 :
10112 1027 : case OMP_CLAUSE_SIZES:
10113 1027 : for (tree list = OMP_CLAUSE_SIZES_LIST (c);
10114 2688 : !remove && list; list = TREE_CHAIN (list))
10115 : {
10116 1661 : t = TREE_VALUE (list);
10117 :
10118 1661 : if (t == error_mark_node)
10119 0 : t = integer_one_node;
10120 1661 : else if (!type_dependent_expression_p (t)
10121 1661 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10122 : {
10123 8 : error_at (OMP_CLAUSE_LOCATION (c),
10124 : "%<sizes%> argument needs positive integral "
10125 : "constant");
10126 8 : t = integer_one_node;
10127 : }
10128 : else
10129 : {
10130 1653 : t = mark_rvalue_use (t);
10131 1653 : if (!processing_template_decl)
10132 : {
10133 1636 : t = maybe_constant_value (t);
10134 1636 : HOST_WIDE_INT n;
10135 1636 : if (!tree_fits_shwi_p (t)
10136 1632 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
10137 1632 : || (n = tree_to_shwi (t)) <= 0
10138 3240 : || (int)n != n)
10139 : {
10140 32 : error_at (OMP_CLAUSE_LOCATION (c),
10141 : "%<sizes%> argument needs positive "
10142 : "integral constant");
10143 32 : t = integer_one_node;
10144 : }
10145 : }
10146 : }
10147 :
10148 : /* Update list item. */
10149 1661 : TREE_VALUE (list) = t;
10150 : }
10151 : break;
10152 :
10153 630 : case OMP_CLAUSE_ORDERED:
10154 630 : ordered_seen = true;
10155 630 : break;
10156 :
10157 1549 : case OMP_CLAUSE_ORDER:
10158 1549 : if (order_seen)
10159 : remove = true;
10160 : else
10161 : order_seen = true;
10162 : break;
10163 :
10164 638 : case OMP_CLAUSE_INBRANCH:
10165 638 : case OMP_CLAUSE_NOTINBRANCH:
10166 638 : if (branch_seen)
10167 : {
10168 3 : error_at (OMP_CLAUSE_LOCATION (c),
10169 : "%<inbranch%> clause is incompatible with "
10170 : "%<notinbranch%>");
10171 3 : remove = true;
10172 : }
10173 : branch_seen = true;
10174 : break;
10175 :
10176 306 : case OMP_CLAUSE_INCLUSIVE:
10177 306 : case OMP_CLAUSE_EXCLUSIVE:
10178 306 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10179 306 : if (!t)
10180 306 : t = OMP_CLAUSE_DECL (c);
10181 306 : if (t == current_class_ptr)
10182 : {
10183 0 : error_at (OMP_CLAUSE_LOCATION (c),
10184 : "%<this%> allowed in OpenMP only in %<declare simd%>"
10185 : " clauses");
10186 0 : remove = true;
10187 0 : break;
10188 : }
10189 306 : if (!VAR_P (t)
10190 : && TREE_CODE (t) != PARM_DECL
10191 : && TREE_CODE (t) != FIELD_DECL)
10192 : {
10193 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
10194 : break;
10195 0 : if (DECL_P (t))
10196 0 : error_at (OMP_CLAUSE_LOCATION (c),
10197 : "%qD is not a variable in clause %qs", t,
10198 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10199 : else
10200 0 : error_at (OMP_CLAUSE_LOCATION (c),
10201 : "%qE is not a variable in clause %qs", t,
10202 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10203 : remove = true;
10204 : }
10205 : break;
10206 :
10207 : case OMP_CLAUSE_FULL:
10208 : break;
10209 :
10210 470 : case OMP_CLAUSE_PARTIAL:
10211 470 : partial_seen = true;
10212 470 : t = OMP_CLAUSE_PARTIAL_EXPR (c);
10213 470 : if (!t)
10214 : break;
10215 :
10216 313 : if (t == error_mark_node)
10217 : t = NULL_TREE;
10218 313 : else if (!type_dependent_expression_p (t)
10219 313 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10220 : {
10221 3 : error_at (OMP_CLAUSE_LOCATION (c),
10222 : "%<partial%> argument needs positive constant "
10223 : "integer expression");
10224 3 : t = NULL_TREE;
10225 : }
10226 : else
10227 : {
10228 310 : t = mark_rvalue_use (t);
10229 310 : if (!processing_template_decl)
10230 : {
10231 292 : t = maybe_constant_value (t);
10232 :
10233 292 : HOST_WIDE_INT n;
10234 584 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
10235 292 : || !tree_fits_shwi_p (t)
10236 286 : || (n = tree_to_shwi (t)) <= 0
10237 560 : || (int)n != n)
10238 : {
10239 24 : error_at (OMP_CLAUSE_LOCATION (c),
10240 : "%<partial%> argument needs positive "
10241 : "constant integer expression");
10242 24 : t = NULL_TREE;
10243 : }
10244 : }
10245 : }
10246 :
10247 313 : OMP_CLAUSE_PARTIAL_EXPR (c) = t;
10248 313 : break;
10249 549 : case OMP_CLAUSE_INIT:
10250 549 : init_seen = true;
10251 549 : OMP_CLAUSE_INIT_PREFER_TYPE (c)
10252 549 : = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
10253 549 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
10254 271 : init_no_targetsync_clause = c;
10255 : /* FALLTHRU */
10256 844 : case OMP_CLAUSE_DESTROY:
10257 844 : case OMP_CLAUSE_USE:
10258 844 : init_use_destroy_seen = true;
10259 844 : t = OMP_CLAUSE_DECL (c);
10260 844 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
10261 : {
10262 9 : error_at (OMP_CLAUSE_LOCATION (c),
10263 : "%qD appears more than once in action clauses", t);
10264 9 : remove = true;
10265 9 : break;
10266 : }
10267 835 : bitmap_set_bit (&generic_head, DECL_UID (t));
10268 : /* FALLTHRU */
10269 1099 : case OMP_CLAUSE_INTEROP:
10270 1099 : if (!processing_template_decl)
10271 : {
10272 1003 : if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
10273 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) && */
10274 1003 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
10275 : {
10276 126 : error_at (OMP_CLAUSE_LOCATION (c),
10277 : "%qD must be of %<omp_interop_t%>",
10278 63 : OMP_CLAUSE_DECL (c));
10279 63 : remove = true;
10280 : }
10281 940 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
10282 481 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
10283 1058 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
10284 : {
10285 36 : error_at (OMP_CLAUSE_LOCATION (c),
10286 18 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
10287 18 : remove = true;
10288 : }
10289 : }
10290 1099 : pc = &OMP_CLAUSE_CHAIN (c);
10291 1099 : break;
10292 0 : default:
10293 0 : gcc_unreachable ();
10294 55 : }
10295 :
10296 98453 : if (remove)
10297 : {
10298 2706 : if (grp_start_p)
10299 : {
10300 : /* If we found a clause to remove, we want to remove the whole
10301 : expanded group, otherwise gimplify
10302 : (omp_resolve_clause_dependencies) can get confused. */
10303 861 : *grp_start_p = grp_sentinel;
10304 861 : pc = grp_start_p;
10305 861 : grp_start_p = NULL;
10306 : }
10307 : else
10308 1845 : *pc = OMP_CLAUSE_CHAIN (c);
10309 : }
10310 : else
10311 95747 : pc = &OMP_CLAUSE_CHAIN (c);
10312 : }
10313 :
10314 63463 : if (grp_start_p
10315 63463 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
10316 140 : for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
10317 86 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
10318 :
10319 63463 : if (reduction_seen < 0 && (ordered_seen || schedule_seen))
10320 63463 : reduction_seen = -2;
10321 :
10322 160177 : for (pc = &clauses, c = clauses; c ; c = *pc)
10323 : {
10324 96714 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
10325 96714 : bool remove = false;
10326 96714 : bool need_complete_type = false;
10327 96714 : bool need_default_ctor = false;
10328 96714 : bool need_copy_ctor = false;
10329 96714 : bool need_copy_assignment = false;
10330 96714 : bool need_implicitly_determined = false;
10331 96714 : bool need_dtor = false;
10332 96714 : tree type, inner_type;
10333 :
10334 96714 : switch (c_kind)
10335 : {
10336 : case OMP_CLAUSE_SHARED:
10337 : need_implicitly_determined = true;
10338 : break;
10339 2550 : case OMP_CLAUSE_PRIVATE:
10340 2550 : need_complete_type = true;
10341 2550 : need_default_ctor = true;
10342 2550 : need_dtor = true;
10343 2550 : need_implicitly_determined = true;
10344 2550 : break;
10345 3169 : case OMP_CLAUSE_FIRSTPRIVATE:
10346 3169 : need_complete_type = true;
10347 3169 : need_copy_ctor = true;
10348 3169 : need_dtor = true;
10349 3169 : need_implicitly_determined = true;
10350 3169 : break;
10351 2766 : case OMP_CLAUSE_LASTPRIVATE:
10352 2766 : need_complete_type = true;
10353 2766 : need_copy_assignment = true;
10354 2766 : need_implicitly_determined = true;
10355 2766 : break;
10356 7497 : case OMP_CLAUSE_REDUCTION:
10357 7497 : if (reduction_seen == -2)
10358 27 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
10359 7497 : if (OMP_CLAUSE_REDUCTION_INSCAN (c))
10360 436 : need_copy_assignment = true;
10361 : need_implicitly_determined = true;
10362 : break;
10363 : case OMP_CLAUSE_IN_REDUCTION:
10364 : case OMP_CLAUSE_TASK_REDUCTION:
10365 : case OMP_CLAUSE_INCLUSIVE:
10366 : case OMP_CLAUSE_EXCLUSIVE:
10367 : need_implicitly_determined = true;
10368 : break;
10369 1550 : case OMP_CLAUSE_LINEAR:
10370 1550 : if (ort != C_ORT_OMP_DECLARE_SIMD)
10371 : need_implicitly_determined = true;
10372 679 : else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
10373 721 : && !bitmap_bit_p (&map_head,
10374 42 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
10375 : {
10376 6 : error_at (OMP_CLAUSE_LOCATION (c),
10377 : "%<linear%> clause step is a parameter %qD not "
10378 : "specified in %<uniform%> clause",
10379 6 : OMP_CLAUSE_LINEAR_STEP (c));
10380 6 : *pc = OMP_CLAUSE_CHAIN (c);
10381 74981 : continue;
10382 : }
10383 : break;
10384 : case OMP_CLAUSE_COPYPRIVATE:
10385 369 : need_copy_assignment = true;
10386 : break;
10387 : case OMP_CLAUSE_COPYIN:
10388 369 : need_copy_assignment = true;
10389 : break;
10390 798 : case OMP_CLAUSE_SIMDLEN:
10391 798 : if (safelen
10392 345 : && !processing_template_decl
10393 1143 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
10394 345 : OMP_CLAUSE_SIMDLEN_EXPR (c)))
10395 : {
10396 0 : error_at (OMP_CLAUSE_LOCATION (c),
10397 : "%<simdlen%> clause value is bigger than "
10398 : "%<safelen%> clause value");
10399 0 : OMP_CLAUSE_SIMDLEN_EXPR (c)
10400 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
10401 : }
10402 798 : pc = &OMP_CLAUSE_CHAIN (c);
10403 798 : continue;
10404 3883 : case OMP_CLAUSE_SCHEDULE:
10405 3883 : if (ordered_seen
10406 3883 : && (OMP_CLAUSE_SCHEDULE_KIND (c)
10407 : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
10408 : {
10409 21 : error_at (OMP_CLAUSE_LOCATION (c),
10410 : "%<nonmonotonic%> schedule modifier specified "
10411 : "together with %<ordered%> clause");
10412 42 : OMP_CLAUSE_SCHEDULE_KIND (c)
10413 21 : = (enum omp_clause_schedule_kind)
10414 21 : (OMP_CLAUSE_SCHEDULE_KIND (c)
10415 : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
10416 : }
10417 3883 : if (reduction_seen == -2)
10418 9 : error_at (OMP_CLAUSE_LOCATION (c),
10419 : "%qs clause specified together with %<inscan%> "
10420 : "%<reduction%> clause", "schedule");
10421 3883 : pc = &OMP_CLAUSE_CHAIN (c);
10422 3883 : continue;
10423 51 : case OMP_CLAUSE_NOGROUP:
10424 51 : if (reduction_seen)
10425 : {
10426 3 : error_at (OMP_CLAUSE_LOCATION (c),
10427 : "%<nogroup%> clause must not be used together with "
10428 : "%<reduction%> clause");
10429 3 : *pc = OMP_CLAUSE_CHAIN (c);
10430 3 : continue;
10431 : }
10432 48 : pc = &OMP_CLAUSE_CHAIN (c);
10433 48 : continue;
10434 165 : case OMP_CLAUSE_GRAINSIZE:
10435 165 : if (num_tasks_seen)
10436 : {
10437 6 : error_at (OMP_CLAUSE_LOCATION (c),
10438 : "%<grainsize%> clause must not be used together with "
10439 : "%<num_tasks%> clause");
10440 6 : *pc = OMP_CLAUSE_CHAIN (c);
10441 6 : continue;
10442 : }
10443 159 : pc = &OMP_CLAUSE_CHAIN (c);
10444 159 : continue;
10445 630 : case OMP_CLAUSE_ORDERED:
10446 630 : if (reduction_seen == -2)
10447 6 : error_at (OMP_CLAUSE_LOCATION (c),
10448 : "%qs clause specified together with %<inscan%> "
10449 : "%<reduction%> clause", "ordered");
10450 630 : pc = &OMP_CLAUSE_CHAIN (c);
10451 630 : continue;
10452 1525 : case OMP_CLAUSE_ORDER:
10453 1525 : if (ordered_seen)
10454 : {
10455 12 : error_at (OMP_CLAUSE_LOCATION (c),
10456 : "%<order%> clause must not be used together "
10457 : "with %<ordered%> clause");
10458 12 : *pc = OMP_CLAUSE_CHAIN (c);
10459 12 : continue;
10460 : }
10461 1513 : pc = &OMP_CLAUSE_CHAIN (c);
10462 1513 : continue;
10463 57 : case OMP_CLAUSE_DETACH:
10464 57 : if (mergeable_seen)
10465 : {
10466 6 : error_at (OMP_CLAUSE_LOCATION (c),
10467 : "%<detach%> clause must not be used together with "
10468 : "%<mergeable%> clause");
10469 6 : *pc = OMP_CLAUSE_CHAIN (c);
10470 6 : continue;
10471 : }
10472 51 : pc = &OMP_CLAUSE_CHAIN (c);
10473 51 : continue;
10474 16091 : case OMP_CLAUSE_MAP:
10475 16091 : if (target_in_reduction_seen && !processing_template_decl)
10476 : {
10477 684 : t = OMP_CLAUSE_DECL (c);
10478 684 : while (handled_component_p (t)
10479 : || INDIRECT_REF_P (t)
10480 : || TREE_CODE (t) == ADDR_EXPR
10481 : || TREE_CODE (t) == MEM_REF
10482 804 : || TREE_CODE (t) == NON_LVALUE_EXPR)
10483 120 : t = TREE_OPERAND (t, 0);
10484 684 : if (DECL_P (t)
10485 684 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
10486 342 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
10487 : }
10488 16091 : pc = &OMP_CLAUSE_CHAIN (c);
10489 16091 : continue;
10490 225 : case OMP_CLAUSE_FULL:
10491 225 : if (partial_seen)
10492 : {
10493 12 : error_at (OMP_CLAUSE_LOCATION (c),
10494 : "%<full%> clause must not be used together "
10495 : "with %<partial%> clause");
10496 12 : *pc = OMP_CLAUSE_CHAIN (c);
10497 12 : continue;
10498 : }
10499 213 : pc = &OMP_CLAUSE_CHAIN (c);
10500 213 : continue;
10501 6952 : case OMP_CLAUSE_NOWAIT:
10502 6952 : if (copyprivate_seen)
10503 : {
10504 6 : error_at (OMP_CLAUSE_LOCATION (c),
10505 : "%<nowait%> clause must not be used together "
10506 : "with %<copyprivate%> clause");
10507 6 : *pc = OMP_CLAUSE_CHAIN (c);
10508 6 : continue;
10509 : }
10510 : /* FALLTHRU */
10511 50864 : default:
10512 50864 : pc = &OMP_CLAUSE_CHAIN (c);
10513 50864 : continue;
10514 : }
10515 :
10516 22413 : t = OMP_CLAUSE_DECL (c);
10517 22413 : switch (c_kind)
10518 : {
10519 2766 : case OMP_CLAUSE_LASTPRIVATE:
10520 2766 : if (DECL_P (t)
10521 2766 : && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
10522 : {
10523 2666 : need_default_ctor = true;
10524 2666 : need_dtor = true;
10525 : }
10526 : break;
10527 :
10528 9636 : case OMP_CLAUSE_REDUCTION:
10529 9636 : case OMP_CLAUSE_IN_REDUCTION:
10530 9636 : case OMP_CLAUSE_TASK_REDUCTION:
10531 9636 : if (allocate_seen)
10532 : {
10533 1711 : if (TREE_CODE (t) == MEM_REF)
10534 : {
10535 222 : t = TREE_OPERAND (t, 0);
10536 222 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
10537 0 : t = TREE_OPERAND (t, 0);
10538 222 : if (TREE_CODE (t) == ADDR_EXPR
10539 168 : || INDIRECT_REF_P (t))
10540 110 : t = TREE_OPERAND (t, 0);
10541 222 : if (DECL_P (t))
10542 222 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10543 : }
10544 1489 : else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10545 : {
10546 288 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10547 144 : t = TREE_OPERAND (t, 0);
10548 144 : if (DECL_P (t))
10549 144 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10550 144 : t = OMP_CLAUSE_DECL (c);
10551 : }
10552 1345 : else if (DECL_P (t))
10553 1345 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10554 1711 : t = OMP_CLAUSE_DECL (c);
10555 : }
10556 9636 : if (processing_template_decl
10557 929 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10558 : break;
10559 9018 : if (finish_omp_reduction_clause (c, &need_default_ctor,
10560 : &need_dtor))
10561 : remove = true;
10562 : else
10563 8934 : t = OMP_CLAUSE_DECL (c);
10564 : break;
10565 :
10566 277 : case OMP_CLAUSE_COPYIN:
10567 277 : if (processing_template_decl
10568 0 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10569 : break;
10570 277 : if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
10571 : {
10572 15 : error_at (OMP_CLAUSE_LOCATION (c),
10573 : "%qE must be %<threadprivate%> for %<copyin%>", t);
10574 15 : remove = true;
10575 : }
10576 : break;
10577 :
10578 : default:
10579 : break;
10580 : }
10581 :
10582 22413 : if (processing_template_decl
10583 1610 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10584 : {
10585 680 : pc = &OMP_CLAUSE_CHAIN (c);
10586 680 : continue;
10587 : }
10588 :
10589 21733 : if (need_complete_type || need_copy_assignment)
10590 : {
10591 9234 : t = require_complete_type (t);
10592 9234 : if (t == error_mark_node)
10593 : remove = true;
10594 9210 : else if (!processing_template_decl
10595 8827 : && TYPE_REF_P (TREE_TYPE (t))
10596 9766 : && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
10597 : remove = true;
10598 : }
10599 21733 : if (need_implicitly_determined)
10600 : {
10601 20692 : const char *share_name = NULL;
10602 :
10603 20692 : if (allocate_seen
10604 5114 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10605 24927 : && DECL_P (t))
10606 3950 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10607 :
10608 20692 : if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
10609 : share_name = "threadprivate";
10610 20650 : else switch (cxx_omp_predetermined_sharing_1 (t))
10611 : {
10612 : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
10613 : break;
10614 47 : case OMP_CLAUSE_DEFAULT_SHARED:
10615 47 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10616 30 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
10617 64 : && c_omp_predefined_variable (t))
10618 : /* The __func__ variable and similar function-local predefined
10619 : variables may be listed in a shared or firstprivate
10620 : clause. */
10621 : break;
10622 31 : if (VAR_P (t)
10623 31 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10624 9 : && TREE_STATIC (t)
10625 40 : && cxx_omp_const_qual_no_mutable (t))
10626 : {
10627 6 : tree ctx = CP_DECL_CONTEXT (t);
10628 : /* const qualified static data members without mutable
10629 : member may be specified in firstprivate clause. */
10630 6 : if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
10631 : break;
10632 : }
10633 : share_name = "shared";
10634 : break;
10635 : case OMP_CLAUSE_DEFAULT_PRIVATE:
10636 : share_name = "private";
10637 : break;
10638 0 : default:
10639 0 : gcc_unreachable ();
10640 : }
10641 : if (share_name)
10642 : {
10643 67 : error_at (OMP_CLAUSE_LOCATION (c),
10644 : "%qE is predetermined %qs for %qs",
10645 : omp_clause_printable_decl (t), share_name,
10646 67 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10647 67 : remove = true;
10648 : }
10649 20625 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10650 18566 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
10651 36051 : && cxx_omp_const_qual_no_mutable (t))
10652 : {
10653 126 : error_at (OMP_CLAUSE_LOCATION (c),
10654 : "%<const%> qualified %qE without %<mutable%> member "
10655 : "may appear only in %<shared%> or %<firstprivate%> "
10656 : "clauses", omp_clause_printable_decl (t));
10657 63 : remove = true;
10658 : }
10659 : }
10660 :
10661 21733 : if (detach_seen
10662 16 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10663 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
10664 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10665 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
10666 21749 : && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
10667 : {
10668 6 : error_at (OMP_CLAUSE_LOCATION (c),
10669 : "the event handle of a %<detach%> clause "
10670 : "should not be in a data-sharing clause");
10671 6 : remove = true;
10672 : }
10673 :
10674 : /* We're interested in the base element, not arrays. */
10675 21733 : inner_type = type = TREE_TYPE (t);
10676 21733 : if ((need_complete_type
10677 : || need_copy_assignment
10678 12499 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
10679 5717 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
10680 4244 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
10681 30315 : && TYPE_REF_P (inner_type))
10682 899 : inner_type = TREE_TYPE (inner_type);
10683 24411 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
10684 2678 : inner_type = TREE_TYPE (inner_type);
10685 :
10686 : /* Check for special function availability by building a call to one.
10687 : Save the results, because later we won't be in the right context
10688 : for making these queries. */
10689 2397 : if (CLASS_TYPE_P (inner_type)
10690 2397 : && COMPLETE_TYPE_P (inner_type)
10691 2328 : && (need_default_ctor || need_copy_ctor
10692 1091 : || need_copy_assignment || need_dtor)
10693 2004 : && !type_dependent_expression_p (t)
10694 23737 : && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
10695 : need_copy_ctor, need_copy_assignment,
10696 : need_dtor))
10697 : remove = true;
10698 :
10699 21733 : if (!remove
10700 21733 : && c_kind == OMP_CLAUSE_SHARED
10701 2056 : && processing_template_decl)
10702 : {
10703 125 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10704 125 : if (t)
10705 5 : OMP_CLAUSE_DECL (c) = t;
10706 : }
10707 :
10708 21733 : if (remove)
10709 292 : *pc = OMP_CLAUSE_CHAIN (c);
10710 : else
10711 21441 : pc = &OMP_CLAUSE_CHAIN (c);
10712 : }
10713 :
10714 63463 : if (allocate_seen)
10715 17449 : for (pc = &clauses, c = clauses; c ; c = *pc)
10716 : {
10717 14948 : bool remove = false;
10718 14948 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
10719 2764 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
10720 2312 : && DECL_P (OMP_CLAUSE_DECL (c))
10721 17260 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
10722 : {
10723 15 : error_at (OMP_CLAUSE_LOCATION (c),
10724 : "%qD specified in %<allocate%> clause but not in "
10725 15 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
10726 15 : remove = true;
10727 : }
10728 14948 : if (remove)
10729 15 : *pc = OMP_CLAUSE_CHAIN (c);
10730 : else
10731 14933 : pc = &OMP_CLAUSE_CHAIN (c);
10732 : }
10733 :
10734 63463 : if (ort == C_ORT_OMP_INTEROP
10735 63463 : && depend_clause
10736 60 : && (!init_use_destroy_seen
10737 57 : || (init_seen && init_no_targetsync_clause)))
10738 : {
10739 9 : auto_diagnostic_group d;
10740 9 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
10741 : "%<depend%> clause requires action clauses with "
10742 : "%<targetsync%> interop-type");
10743 9 : if (init_no_targetsync_clause)
10744 6 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
10745 : "%<init%> clause lacks the %<targetsync%> modifier");
10746 9 : }
10747 :
10748 63463 : bitmap_obstack_release (NULL);
10749 63463 : return clauses;
10750 : }
10751 :
10752 : /* Start processing OpenMP clauses that can include any
10753 : privatization clauses for non-static data members. */
10754 :
10755 : tree
10756 49194 : push_omp_privatization_clauses (bool ignore_next)
10757 : {
10758 49194 : if (omp_private_member_ignore_next)
10759 : {
10760 722 : omp_private_member_ignore_next = ignore_next;
10761 722 : return NULL_TREE;
10762 : }
10763 48472 : omp_private_member_ignore_next = ignore_next;
10764 48472 : if (omp_private_member_map)
10765 24 : omp_private_member_vec.safe_push (error_mark_node);
10766 48472 : return push_stmt_list ();
10767 : }
10768 :
10769 : /* Revert remapping of any non-static data members since
10770 : the last push_omp_privatization_clauses () call. */
10771 :
10772 : void
10773 49188 : pop_omp_privatization_clauses (tree stmt)
10774 : {
10775 49188 : if (stmt == NULL_TREE)
10776 : return;
10777 48466 : stmt = pop_stmt_list (stmt);
10778 48466 : if (omp_private_member_map)
10779 : {
10780 1280 : while (!omp_private_member_vec.is_empty ())
10781 : {
10782 850 : tree t = omp_private_member_vec.pop ();
10783 850 : if (t == error_mark_node)
10784 : {
10785 24 : add_stmt (stmt);
10786 24 : return;
10787 : }
10788 826 : bool no_decl_expr = t == integer_zero_node;
10789 826 : if (no_decl_expr)
10790 136 : t = omp_private_member_vec.pop ();
10791 826 : tree *v = omp_private_member_map->get (t);
10792 826 : gcc_assert (v);
10793 826 : if (!no_decl_expr)
10794 690 : add_decl_expr (*v);
10795 826 : omp_private_member_map->remove (t);
10796 : }
10797 860 : delete omp_private_member_map;
10798 430 : omp_private_member_map = NULL;
10799 : }
10800 48442 : add_stmt (stmt);
10801 : }
10802 :
10803 : /* Remember OpenMP privatization clauses mapping and clear it.
10804 : Used for lambdas. */
10805 :
10806 : void
10807 16436116 : save_omp_privatization_clauses (vec<tree> &save)
10808 : {
10809 16436116 : save = vNULL;
10810 16436116 : if (omp_private_member_ignore_next)
10811 2 : save.safe_push (integer_one_node);
10812 16436116 : omp_private_member_ignore_next = false;
10813 16436116 : if (!omp_private_member_map)
10814 : return;
10815 :
10816 0 : while (!omp_private_member_vec.is_empty ())
10817 : {
10818 0 : tree t = omp_private_member_vec.pop ();
10819 0 : if (t == error_mark_node)
10820 : {
10821 0 : save.safe_push (t);
10822 0 : continue;
10823 : }
10824 0 : tree n = t;
10825 0 : if (t == integer_zero_node)
10826 0 : t = omp_private_member_vec.pop ();
10827 0 : tree *v = omp_private_member_map->get (t);
10828 0 : gcc_assert (v);
10829 0 : save.safe_push (*v);
10830 0 : save.safe_push (t);
10831 0 : if (n != t)
10832 0 : save.safe_push (n);
10833 : }
10834 0 : delete omp_private_member_map;
10835 0 : omp_private_member_map = NULL;
10836 : }
10837 :
10838 : /* Restore OpenMP privatization clauses mapping saved by the
10839 : above function. */
10840 :
10841 : void
10842 16436116 : restore_omp_privatization_clauses (vec<tree> &save)
10843 : {
10844 16436116 : gcc_assert (omp_private_member_vec.is_empty ());
10845 16436116 : omp_private_member_ignore_next = false;
10846 16436116 : if (save.is_empty ())
10847 : return;
10848 4 : if (save.length () == 1 && save[0] == integer_one_node)
10849 : {
10850 2 : omp_private_member_ignore_next = true;
10851 2 : save.release ();
10852 2 : return;
10853 : }
10854 :
10855 0 : omp_private_member_map = new hash_map <tree, tree>;
10856 0 : while (!save.is_empty ())
10857 : {
10858 0 : tree t = save.pop ();
10859 0 : tree n = t;
10860 0 : if (t != error_mark_node)
10861 : {
10862 0 : if (t == integer_one_node)
10863 : {
10864 0 : omp_private_member_ignore_next = true;
10865 0 : gcc_assert (save.is_empty ());
10866 0 : break;
10867 : }
10868 0 : if (t == integer_zero_node)
10869 0 : t = save.pop ();
10870 0 : tree &v = omp_private_member_map->get_or_insert (t);
10871 0 : v = save.pop ();
10872 : }
10873 0 : omp_private_member_vec.safe_push (t);
10874 0 : if (n != t)
10875 0 : omp_private_member_vec.safe_push (n);
10876 : }
10877 0 : save.release ();
10878 : }
10879 :
10880 : /* For all variables in the tree_list VARS, mark them as thread local. */
10881 :
10882 : void
10883 244 : finish_omp_threadprivate (tree vars)
10884 : {
10885 244 : tree t;
10886 :
10887 : /* Mark every variable in VARS to be assigned thread local storage. */
10888 521 : for (t = vars; t; t = TREE_CHAIN (t))
10889 : {
10890 277 : tree v = TREE_PURPOSE (t);
10891 277 : location_t loc = EXPR_LOCATION (TREE_VALUE (t));
10892 :
10893 277 : if (error_operand_p (v))
10894 : ;
10895 277 : else if (!VAR_P (v))
10896 6 : error_at (loc, "%<threadprivate%> %qD is not file, namespace "
10897 : "or block scope variable", v);
10898 : /* If V had already been marked threadprivate, it doesn't matter
10899 : whether it had been used prior to this point. */
10900 271 : else if (TREE_USED (v)
10901 271 : && (DECL_LANG_SPECIFIC (v) == NULL
10902 3 : || !CP_DECL_THREADPRIVATE_P (v)))
10903 6 : error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10904 265 : else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10905 6 : error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10906 259 : else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
10907 3 : error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10908 207 : else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
10909 279 : && CP_DECL_CONTEXT (v) != current_class_type)
10910 6 : error_at (loc, "%<threadprivate%> %qE directive not "
10911 6 : "in %qT definition", v, CP_DECL_CONTEXT (v));
10912 : else
10913 : {
10914 : /* Allocate a LANG_SPECIFIC structure for V, if needed. */
10915 250 : if (DECL_LANG_SPECIFIC (v) == NULL)
10916 206 : retrofit_lang_decl (v);
10917 :
10918 250 : if (! CP_DECL_THREAD_LOCAL_P (v))
10919 : {
10920 250 : CP_DECL_THREAD_LOCAL_P (v) = true;
10921 250 : set_decl_tls_model (v, decl_default_tls_model (v));
10922 : /* If rtl has been already set for this var, call
10923 : make_decl_rtl once again, so that encode_section_info
10924 : has a chance to look at the new decl flags. */
10925 250 : if (DECL_RTL_SET_P (v))
10926 0 : make_decl_rtl (v);
10927 : }
10928 250 : CP_DECL_THREADPRIVATE_P (v) = 1;
10929 : }
10930 : }
10931 244 : }
10932 :
10933 : /* Build an OpenMP structured block. */
10934 :
10935 : tree
10936 64717 : begin_omp_structured_block (void)
10937 : {
10938 64717 : return do_pushlevel (sk_omp);
10939 : }
10940 :
10941 : tree
10942 64702 : finish_omp_structured_block (tree block)
10943 : {
10944 64702 : return do_poplevel (block);
10945 : }
10946 :
10947 : /* Similarly, except force the retention of the BLOCK. */
10948 :
10949 : tree
10950 14970 : begin_omp_parallel (void)
10951 : {
10952 14970 : keep_next_level (true);
10953 14970 : return begin_omp_structured_block ();
10954 : }
10955 :
10956 : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
10957 : statement. */
10958 :
10959 : tree
10960 768 : finish_oacc_data (tree clauses, tree block)
10961 : {
10962 768 : tree stmt;
10963 :
10964 768 : block = finish_omp_structured_block (block);
10965 :
10966 768 : stmt = make_node (OACC_DATA);
10967 768 : TREE_TYPE (stmt) = void_type_node;
10968 768 : OACC_DATA_CLAUSES (stmt) = clauses;
10969 768 : OACC_DATA_BODY (stmt) = block;
10970 :
10971 768 : return add_stmt (stmt);
10972 : }
10973 :
10974 : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
10975 : statement. */
10976 :
10977 : tree
10978 55 : finish_oacc_host_data (tree clauses, tree block)
10979 : {
10980 55 : tree stmt;
10981 :
10982 55 : block = finish_omp_structured_block (block);
10983 :
10984 55 : stmt = make_node (OACC_HOST_DATA);
10985 55 : TREE_TYPE (stmt) = void_type_node;
10986 55 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
10987 55 : OACC_HOST_DATA_BODY (stmt) = block;
10988 :
10989 55 : return add_stmt (stmt);
10990 : }
10991 :
10992 : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
10993 : statement. */
10994 :
10995 : tree
10996 4689 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
10997 : {
10998 4689 : body = finish_omp_structured_block (body);
10999 :
11000 4689 : tree stmt = make_node (code);
11001 4689 : TREE_TYPE (stmt) = void_type_node;
11002 4689 : OMP_BODY (stmt) = body;
11003 4689 : OMP_CLAUSES (stmt) = clauses;
11004 :
11005 4689 : return add_stmt (stmt);
11006 : }
11007 :
11008 : /* Used to walk OpenMP target directive body. */
11009 :
11010 : struct omp_target_walk_data
11011 : {
11012 : /* Holds the 'this' expression found in current function. */
11013 : tree current_object;
11014 :
11015 : /* True if the 'this' expression was accessed in the target body. */
11016 : bool this_expr_accessed;
11017 :
11018 : /* For non-static functions, record which pointer-typed members were
11019 : accessed, and the whole expression. */
11020 : hash_map<tree, tree> ptr_members_accessed;
11021 :
11022 : /* Record which lambda objects were accessed in target body. */
11023 : hash_set<tree> lambda_objects_accessed;
11024 :
11025 : /* For lambda functions, the __closure object expression of the current
11026 : function, and the set of captured variables accessed in target body. */
11027 : tree current_closure;
11028 : hash_set<tree> closure_vars_accessed;
11029 :
11030 : /* Local variables declared inside a BIND_EXPR, used to filter out such
11031 : variables when recording lambda_objects_accessed. */
11032 : hash_set<tree> local_decls;
11033 :
11034 : omp_mapper_list<tree> *mappers;
11035 : };
11036 :
11037 : /* Helper function of finish_omp_target_clauses, called via
11038 : cp_walk_tree_without_duplicates. Traverse body of OpenMP target
11039 : directive *TP, and fill out omp_target_walk_data passed in *PTR. */
11040 :
11041 : static tree
11042 228836 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
11043 : {
11044 228836 : tree t = *tp;
11045 228836 : struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
11046 228836 : tree current_object = data->current_object;
11047 228836 : tree current_closure = data->current_closure;
11048 228836 : omp_mapper_list<tree> *mlist = data->mappers;
11049 :
11050 : /* References inside of these expression codes shouldn't incur any
11051 : form of mapping, so return early. */
11052 228836 : if (TREE_CODE (t) == SIZEOF_EXPR
11053 228828 : || TREE_CODE (t) == ALIGNOF_EXPR)
11054 : {
11055 8 : *walk_subtrees = 0;
11056 8 : return NULL_TREE;
11057 : }
11058 :
11059 228828 : if (TREE_CODE (t) == OMP_CLAUSE)
11060 : return NULL_TREE;
11061 :
11062 216230 : if (!processing_template_decl)
11063 : {
11064 216230 : tree aggr_type = NULL_TREE;
11065 :
11066 216230 : if (TREE_CODE (t) == COMPONENT_REF
11067 216230 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
11068 2257 : aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
11069 213973 : else if ((TREE_CODE (t) == VAR_DECL
11070 : || TREE_CODE (t) == PARM_DECL
11071 : || TREE_CODE (t) == RESULT_DECL)
11072 16988 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
11073 1216 : aggr_type = TREE_TYPE (t);
11074 :
11075 3473 : if (aggr_type)
11076 : {
11077 3473 : tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
11078 3473 : if (mapper_fn)
11079 199 : mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
11080 : }
11081 : }
11082 :
11083 216230 : if (current_object)
11084 : {
11085 2565 : tree this_expr = TREE_OPERAND (current_object, 0);
11086 :
11087 2565 : if (operand_equal_p (t, this_expr))
11088 : {
11089 35 : data->this_expr_accessed = true;
11090 35 : *walk_subtrees = 0;
11091 35 : return NULL_TREE;
11092 : }
11093 :
11094 2530 : if (TREE_CODE (t) == COMPONENT_REF
11095 115 : && POINTER_TYPE_P (TREE_TYPE (t))
11096 36 : && operand_equal_p (TREE_OPERAND (t, 0), current_object)
11097 2564 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
11098 : {
11099 34 : data->this_expr_accessed = true;
11100 34 : tree fld = TREE_OPERAND (t, 1);
11101 34 : if (data->ptr_members_accessed.get (fld) == NULL)
11102 : {
11103 14 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
11104 4 : t = convert_from_reference (t);
11105 14 : data->ptr_members_accessed.put (fld, t);
11106 : }
11107 34 : *walk_subtrees = 0;
11108 34 : return NULL_TREE;
11109 : }
11110 : }
11111 :
11112 : /* When the current_function_decl is a lambda function, the closure object
11113 : argument's type seems to not yet have fields laid out, so a recording
11114 : of DECL_VALUE_EXPRs during the target body walk seems the only way to
11115 : find them. */
11116 216161 : if (current_closure
11117 301 : && (VAR_P (t)
11118 : || TREE_CODE (t) == PARM_DECL
11119 : || TREE_CODE (t) == RESULT_DECL)
11120 24 : && DECL_HAS_VALUE_EXPR_P (t)
11121 10 : && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
11122 216171 : && operand_equal_p (current_closure,
11123 10 : TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
11124 : {
11125 9 : if (!data->closure_vars_accessed.contains (t))
11126 9 : data->closure_vars_accessed.add (t);
11127 9 : *walk_subtrees = 0;
11128 9 : return NULL_TREE;
11129 : }
11130 :
11131 216152 : if (TREE_CODE (t) == BIND_EXPR)
11132 : {
11133 20014 : if (tree block = BIND_EXPR_BLOCK (t))
11134 22470 : for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
11135 2460 : if (!data->local_decls.contains (var))
11136 2460 : data->local_decls.add (var);
11137 : return NULL_TREE;
11138 : }
11139 :
11140 200741 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
11141 : {
11142 39 : tree lt = TREE_TYPE (t);
11143 39 : gcc_assert (CLASS_TYPE_P (lt));
11144 :
11145 39 : if (!data->lambda_objects_accessed.contains (t)
11146 : /* Do not prepare to create target maps for locally declared
11147 : lambdas or anonymous ones. */
11148 39 : && !data->local_decls.contains (t)
11149 72 : && TREE_CODE (t) != TARGET_EXPR)
11150 13 : data->lambda_objects_accessed.add (t);
11151 39 : *walk_subtrees = 0;
11152 39 : return NULL_TREE;
11153 : }
11154 :
11155 : return NULL_TREE;
11156 : }
11157 :
11158 : /* Helper function for finish_omp_target, and also from tsubst_expr.
11159 : Create additional clauses for mapping of non-static members, lambda objects,
11160 : etc. */
11161 :
11162 : void
11163 6961 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
11164 : {
11165 6961 : omp_target_walk_data data;
11166 6961 : data.this_expr_accessed = false;
11167 6961 : data.current_object = NULL_TREE;
11168 :
11169 6961 : if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
11170 96 : if (tree ct = current_nonlambda_class_type ())
11171 : {
11172 95 : tree object = maybe_dummy_object (ct, NULL);
11173 95 : object = maybe_resolve_dummy (object, true);
11174 95 : data.current_object = object;
11175 : }
11176 :
11177 6961 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11178 : {
11179 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11180 8 : data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11181 : }
11182 : else
11183 : data.current_closure = NULL_TREE;
11184 :
11185 6961 : auto_vec<tree, 16> new_clauses;
11186 :
11187 6961 : if (!processing_template_decl)
11188 : {
11189 6961 : hash_set<omp_name_type<tree> > seen_types;
11190 6961 : auto_vec<tree> mapper_fns;
11191 6961 : omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
11192 6961 : data.mappers = &mlist;
11193 :
11194 6961 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11195 : &data);
11196 :
11197 6961 : unsigned int i;
11198 6961 : tree mapper_fn;
11199 14015 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11200 93 : c_omp_find_nested_mappers (&mlist, mapper_fn);
11201 :
11202 7124 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11203 : {
11204 93 : tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
11205 93 : if (mapper == error_mark_node)
11206 0 : continue;
11207 93 : tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
11208 93 : tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
11209 93 : if (BASELINK_P (mapper_fn))
11210 0 : mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
11211 :
11212 93 : tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
11213 93 : OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
11214 93 : OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
11215 93 : OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
11216 :
11217 93 : new_clauses.safe_push (c);
11218 : }
11219 6961 : }
11220 : else
11221 : {
11222 0 : data.mappers = NULL;
11223 0 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11224 : &data);
11225 : }
11226 :
11227 6961 : tree omp_target_this_expr = NULL_TREE;
11228 6961 : tree *explicit_this_deref_map = NULL;
11229 6961 : if (data.this_expr_accessed)
11230 : {
11231 31 : omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
11232 :
11233 : /* See if explicit user-specified map(this[:]) clause already exists.
11234 : If not, we create an implicit map(tofrom:this[:1]) clause. */
11235 80 : for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
11236 50 : if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
11237 47 : && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
11238 40 : || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
11239 57 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
11240 : omp_target_this_expr))
11241 : {
11242 : explicit_this_deref_map = cp;
11243 : break;
11244 : }
11245 : }
11246 :
11247 6961 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11248 6961 : && (data.this_expr_accessed
11249 1 : || !data.closure_vars_accessed.is_empty ()))
11250 : {
11251 : /* For lambda functions, we need to first create a copy of the
11252 : __closure object. */
11253 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11254 8 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11255 8 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
11256 8 : OMP_CLAUSE_DECL (c)
11257 8 : = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11258 8 : OMP_CLAUSE_SIZE (c)
11259 8 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
11260 8 : new_clauses.safe_push (c);
11261 :
11262 8 : tree closure_obj = OMP_CLAUSE_DECL (c);
11263 8 : tree closure_type = TREE_TYPE (closure_obj);
11264 :
11265 16 : gcc_assert (LAMBDA_TYPE_P (closure_type)
11266 : && CLASS_TYPE_P (closure_type));
11267 :
11268 8 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11269 8 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
11270 8 : OMP_CLAUSE_DECL (c2) = closure;
11271 8 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11272 8 : new_clauses.safe_push (c2);
11273 : }
11274 :
11275 6961 : if (data.this_expr_accessed)
11276 : {
11277 : /* If the this-expr was accessed, create a map(*this) clause. */
11278 31 : enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11279 31 : if (explicit_this_deref_map)
11280 : {
11281 1 : tree this_map = *explicit_this_deref_map;
11282 1 : tree nc = OMP_CLAUSE_CHAIN (this_map);
11283 2 : gcc_assert (nc != NULL_TREE
11284 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11285 : && (OMP_CLAUSE_MAP_KIND (nc)
11286 : == GOMP_MAP_FIRSTPRIVATE_POINTER));
11287 1 : kind = OMP_CLAUSE_MAP_KIND (this_map);
11288 : /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
11289 : two-map sequence away from the chain. */
11290 1 : *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
11291 : }
11292 31 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11293 31 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11294 31 : OMP_CLAUSE_DECL (c)
11295 31 : = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
11296 31 : OMP_CLAUSE_SIZE (c)
11297 31 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
11298 31 : new_clauses.safe_push (c);
11299 :
11300 : /* If we're in a lambda function, the this-pointer will actually be
11301 : '__closure->this', a mapped member of __closure, hence always_pointer.
11302 : Otherwise it's a firstprivate pointer. */
11303 31 : enum gomp_map_kind ptr_kind
11304 31 : = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11305 31 : ? GOMP_MAP_ALWAYS_POINTER
11306 24 : : GOMP_MAP_FIRSTPRIVATE_POINTER);
11307 31 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11308 31 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11309 31 : OMP_CLAUSE_DECL (c) = omp_target_this_expr;
11310 31 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11311 31 : new_clauses.safe_push (c);
11312 : }
11313 :
11314 6961 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11315 : {
11316 8 : if (omp_target_this_expr)
11317 : {
11318 7 : STRIP_NOPS (omp_target_this_expr);
11319 7 : gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
11320 7 : omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
11321 : }
11322 :
11323 17 : for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
11324 25 : i != data.closure_vars_accessed.end (); ++i)
11325 : {
11326 9 : tree orig_decl = *i;
11327 9 : tree closure_expr = DECL_VALUE_EXPR (orig_decl);
11328 :
11329 9 : if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
11330 9 : || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
11331 : {
11332 : /* this-pointer is processed above, outside this loop. */
11333 3 : if (omp_target_this_expr
11334 3 : && operand_equal_p (closure_expr, omp_target_this_expr))
11335 0 : continue;
11336 :
11337 3 : bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
11338 3 : enum gomp_map_kind kind, ptr_kind, nc_kind;
11339 3 : tree size;
11340 :
11341 3 : if (ptr_p)
11342 : {
11343 : /* For pointers, default mapped as zero-length array
11344 : section. */
11345 2 : kind = GOMP_MAP_ALLOC;
11346 2 : nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
11347 2 : ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
11348 2 : size = size_zero_node;
11349 : }
11350 : else
11351 : {
11352 : /* For references, default mapped as appearing on map
11353 : clause. */
11354 1 : kind = GOMP_MAP_TOFROM;
11355 1 : nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
11356 1 : ptr_kind = GOMP_MAP_ALWAYS_POINTER;
11357 1 : size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
11358 : }
11359 :
11360 6 : for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
11361 3 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
11362 1 : && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
11363 1 : || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
11364 3 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
11365 : orig_decl))
11366 : {
11367 : /* If this was already specified by user as a map,
11368 : save the user specified map kind, delete the
11369 : "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
11370 : and insert our own sequence:
11371 : "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
11372 : */
11373 0 : tree nc = OMP_CLAUSE_CHAIN (*p);
11374 0 : gcc_assert (nc != NULL_TREE
11375 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11376 : && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
11377 : /* Update with user specified kind and size. */
11378 0 : kind = OMP_CLAUSE_MAP_KIND (*p);
11379 0 : size = OMP_CLAUSE_SIZE (*p);
11380 0 : *p = OMP_CLAUSE_CHAIN (nc);
11381 0 : break;
11382 : }
11383 :
11384 3 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11385 3 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11386 3 : OMP_CLAUSE_DECL (c)
11387 3 : = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
11388 3 : OMP_CLAUSE_SIZE (c) = size;
11389 3 : if (ptr_p)
11390 2 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11391 3 : new_clauses.safe_push (c);
11392 :
11393 3 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11394 3 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11395 3 : OMP_CLAUSE_DECL (c) = closure_expr;
11396 3 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11397 3 : new_clauses.safe_push (c);
11398 : }
11399 : }
11400 : }
11401 :
11402 6961 : if (!data.ptr_members_accessed.is_empty ())
11403 14 : for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
11404 42 : i != data.ptr_members_accessed.end (); ++i)
11405 : {
11406 : /* For each referenced member that is of pointer or reference-to-pointer
11407 : type, create the equivalent of map(alloc:this->ptr[:0]). */
11408 14 : tree field_decl = (*i).first;
11409 14 : tree ptr_member = (*i).second;
11410 :
11411 26 : for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
11412 : {
11413 16 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
11414 2 : continue;
11415 : /* If map(this->ptr[:N]) already exists, avoid creating another
11416 : such map. */
11417 14 : tree decl = OMP_CLAUSE_DECL (c);
11418 14 : if ((TREE_CODE (decl) == INDIRECT_REF
11419 10 : || TREE_CODE (decl) == MEM_REF)
11420 14 : && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
11421 4 : goto next_ptr_member;
11422 : }
11423 :
11424 10 : if (!cxx_mark_addressable (ptr_member))
11425 0 : gcc_unreachable ();
11426 :
11427 10 : if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
11428 : {
11429 : /* For reference to pointers, we need to map the referenced
11430 : pointer first for things to be correct. */
11431 4 : tree ptr_member_type = TREE_TYPE (ptr_member);
11432 :
11433 : /* Map pointer target as zero-length array section. */
11434 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11435 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11436 4 : OMP_CLAUSE_DECL (c)
11437 4 : = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
11438 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11439 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11440 :
11441 : /* Map pointer to zero-length array section. */
11442 4 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11443 4 : OMP_CLAUSE_SET_MAP_KIND
11444 : (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
11445 4 : OMP_CLAUSE_DECL (c2) = ptr_member;
11446 4 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11447 :
11448 : /* Attach reference-to-pointer field to pointer. */
11449 4 : tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11450 4 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
11451 4 : OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
11452 4 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
11453 :
11454 4 : new_clauses.safe_push (c);
11455 4 : new_clauses.safe_push (c2);
11456 4 : new_clauses.safe_push (c3);
11457 : }
11458 6 : else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
11459 : {
11460 : /* Map pointer target as zero-length array section. */
11461 6 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11462 6 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11463 6 : OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
11464 : RO_UNARY_STAR);
11465 6 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11466 6 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11467 :
11468 : /* Attach zero-length array section to pointer. */
11469 6 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11470 6 : OMP_CLAUSE_SET_MAP_KIND
11471 : (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11472 6 : OMP_CLAUSE_DECL (c2) = ptr_member;
11473 6 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11474 :
11475 6 : new_clauses.safe_push (c);
11476 6 : new_clauses.safe_push (c2);
11477 : }
11478 : else
11479 0 : gcc_unreachable ();
11480 :
11481 14 : next_ptr_member:
11482 14 : ;
11483 : }
11484 :
11485 6974 : for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
11486 6974 : i != data.lambda_objects_accessed.end (); ++i)
11487 : {
11488 13 : tree lobj = *i;
11489 13 : if (TREE_CODE (lobj) == TARGET_EXPR)
11490 0 : lobj = TARGET_EXPR_SLOT (lobj);
11491 :
11492 13 : tree lt = TREE_TYPE (lobj);
11493 26 : gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
11494 :
11495 13 : tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
11496 13 : OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
11497 13 : OMP_CLAUSE_DECL (lc) = lobj;
11498 13 : OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
11499 13 : new_clauses.safe_push (lc);
11500 :
11501 180 : for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
11502 : {
11503 167 : if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
11504 : {
11505 4 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11506 : lobj, fld, NULL_TREE);
11507 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11508 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11509 4 : OMP_CLAUSE_DECL (c)
11510 4 : = build_indirect_ref (loc, exp, RO_UNARY_STAR);
11511 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11512 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11513 4 : new_clauses.safe_push (c);
11514 :
11515 4 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11516 4 : OMP_CLAUSE_SET_MAP_KIND
11517 : (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11518 4 : OMP_CLAUSE_DECL (c) = exp;
11519 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11520 4 : new_clauses.safe_push (c);
11521 : }
11522 163 : else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
11523 : {
11524 0 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11525 : lobj, fld, NULL_TREE);
11526 0 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11527 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
11528 0 : OMP_CLAUSE_DECL (c)
11529 0 : = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
11530 0 : OMP_CLAUSE_SIZE (c)
11531 0 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
11532 0 : new_clauses.safe_push (c);
11533 :
11534 0 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11535 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
11536 0 : OMP_CLAUSE_DECL (c) = exp;
11537 0 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11538 0 : new_clauses.safe_push (c);
11539 : }
11540 : }
11541 : }
11542 :
11543 6961 : tree c = *clauses_ptr;
11544 14144 : for (int i = new_clauses.length () - 1; i >= 0; i--)
11545 : {
11546 222 : OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
11547 222 : c = new_clauses[i];
11548 : }
11549 6961 : *clauses_ptr = c;
11550 6961 : }
11551 :
11552 : /* Called from cp_parser_omp_target. Create additional implicit clauses for
11553 : OpenMP target directives, and do sanity checks. */
11554 :
11555 : tree
11556 6951 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
11557 : {
11558 6951 : if (!processing_template_decl)
11559 6145 : finish_omp_target_clauses (loc, body, &clauses);
11560 :
11561 6951 : tree stmt = make_node (OMP_TARGET);
11562 6951 : TREE_TYPE (stmt) = void_type_node;
11563 6951 : OMP_TARGET_CLAUSES (stmt) = clauses;
11564 6951 : OMP_TARGET_BODY (stmt) = body;
11565 6951 : OMP_TARGET_COMBINED (stmt) = combined_p;
11566 6951 : SET_EXPR_LOCATION (stmt, loc);
11567 :
11568 6951 : tree c = clauses;
11569 16720 : while (c)
11570 : {
11571 9769 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
11572 5673 : switch (OMP_CLAUSE_MAP_KIND (c))
11573 : {
11574 : case GOMP_MAP_TO:
11575 : case GOMP_MAP_ALWAYS_TO:
11576 : case GOMP_MAP_PRESENT_TO:
11577 : case GOMP_MAP_ALWAYS_PRESENT_TO:
11578 : case GOMP_MAP_FROM:
11579 : case GOMP_MAP_ALWAYS_FROM:
11580 : case GOMP_MAP_PRESENT_FROM:
11581 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
11582 : case GOMP_MAP_TOFROM:
11583 : case GOMP_MAP_ALWAYS_TOFROM:
11584 : case GOMP_MAP_PRESENT_TOFROM:
11585 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
11586 : case GOMP_MAP_ALLOC:
11587 : case GOMP_MAP_PRESENT_ALLOC:
11588 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
11589 : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
11590 : case GOMP_MAP_ALWAYS_POINTER:
11591 : case GOMP_MAP_ATTACH_DETACH:
11592 : case GOMP_MAP_ATTACH:
11593 : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
11594 : case GOMP_MAP_POINTER:
11595 : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
11596 : break;
11597 3 : default:
11598 3 : error_at (OMP_CLAUSE_LOCATION (c),
11599 : "%<#pragma omp target%> with map-type other "
11600 : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
11601 : "on %<map%> clause");
11602 3 : break;
11603 : }
11604 9769 : c = OMP_CLAUSE_CHAIN (c);
11605 : }
11606 6951 : return add_stmt (stmt);
11607 : }
11608 :
11609 : tree
11610 9458 : finish_omp_parallel (tree clauses, tree body)
11611 : {
11612 9458 : tree stmt;
11613 :
11614 9458 : body = finish_omp_structured_block (body);
11615 :
11616 9458 : stmt = make_node (OMP_PARALLEL);
11617 9458 : TREE_TYPE (stmt) = void_type_node;
11618 9458 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
11619 9458 : OMP_PARALLEL_BODY (stmt) = body;
11620 :
11621 9458 : return add_stmt (stmt);
11622 : }
11623 :
11624 : tree
11625 2411 : begin_omp_task (void)
11626 : {
11627 2411 : keep_next_level (true);
11628 2411 : return begin_omp_structured_block ();
11629 : }
11630 :
11631 : tree
11632 2411 : finish_omp_task (tree clauses, tree body)
11633 : {
11634 2411 : tree stmt;
11635 :
11636 2411 : body = finish_omp_structured_block (body);
11637 :
11638 2411 : stmt = make_node (OMP_TASK);
11639 2411 : TREE_TYPE (stmt) = void_type_node;
11640 2411 : OMP_TASK_CLAUSES (stmt) = clauses;
11641 2411 : OMP_TASK_BODY (stmt) = body;
11642 :
11643 2411 : return add_stmt (stmt);
11644 : }
11645 :
11646 : /* Helper function for finish_omp_for. Convert Ith random access iterator
11647 : into integral iterator. Return FALSE if successful. */
11648 :
11649 : static bool
11650 813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
11651 : tree declv, tree orig_declv, tree initv,
11652 : tree condv, tree incrv, tree *body,
11653 : tree *pre_body, tree &clauses,
11654 : int collapse, int ordered)
11655 : {
11656 813 : tree diff, iter_init, iter_incr = NULL, last;
11657 813 : tree incr_var = NULL, orig_pre_body, orig_body, c;
11658 813 : tree decl = TREE_VEC_ELT (declv, i);
11659 813 : tree init = TREE_VEC_ELT (initv, i);
11660 813 : tree cond = TREE_VEC_ELT (condv, i);
11661 813 : tree incr = TREE_VEC_ELT (incrv, i);
11662 813 : tree iter = decl;
11663 813 : location_t elocus = locus;
11664 :
11665 813 : if (init && EXPR_HAS_LOCATION (init))
11666 12 : elocus = EXPR_LOCATION (init);
11667 :
11668 813 : switch (TREE_CODE (cond))
11669 : {
11670 810 : case GT_EXPR:
11671 810 : case GE_EXPR:
11672 810 : case LT_EXPR:
11673 810 : case LE_EXPR:
11674 810 : case NE_EXPR:
11675 810 : if (TREE_OPERAND (cond, 1) == iter)
11676 42 : cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
11677 42 : TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
11678 810 : if (TREE_OPERAND (cond, 0) != iter)
11679 0 : cond = error_mark_node;
11680 : else
11681 : {
11682 810 : tree tem = build_x_binary_op (EXPR_LOCATION (cond),
11683 810 : TREE_CODE (cond),
11684 : iter, ERROR_MARK,
11685 810 : TREE_OPERAND (cond, 1), ERROR_MARK,
11686 : NULL_TREE, NULL, tf_warning_or_error);
11687 810 : if (error_operand_p (tem))
11688 : return true;
11689 : }
11690 : break;
11691 3 : default:
11692 3 : cond = error_mark_node;
11693 3 : break;
11694 : }
11695 810 : if (cond == error_mark_node)
11696 : {
11697 3 : error_at (elocus, "invalid controlling predicate");
11698 3 : return true;
11699 : }
11700 807 : diff = build_x_binary_op (elocus, MINUS_EXPR,
11701 807 : TREE_OPERAND (cond, 1), ERROR_MARK,
11702 : iter, ERROR_MARK,
11703 : NULL_TREE, NULL, tf_warning_or_error);
11704 807 : diff = cp_fully_fold (diff);
11705 807 : if (error_operand_p (diff))
11706 : return true;
11707 807 : if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
11708 : {
11709 0 : error_at (elocus, "difference between %qE and %qD does not have integer type",
11710 0 : TREE_OPERAND (cond, 1), iter);
11711 0 : return true;
11712 : }
11713 807 : if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
11714 807 : TREE_VEC_ELT (declv, i), NULL_TREE,
11715 : cond, cp_walk_subtrees))
11716 : return true;
11717 :
11718 762 : switch (TREE_CODE (incr))
11719 : {
11720 370 : case PREINCREMENT_EXPR:
11721 370 : case PREDECREMENT_EXPR:
11722 370 : case POSTINCREMENT_EXPR:
11723 370 : case POSTDECREMENT_EXPR:
11724 370 : if (TREE_OPERAND (incr, 0) != iter)
11725 : {
11726 0 : incr = error_mark_node;
11727 0 : break;
11728 : }
11729 370 : iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
11730 370 : TREE_CODE (incr), iter,
11731 : NULL_TREE, tf_warning_or_error);
11732 370 : if (error_operand_p (iter_incr))
11733 : return true;
11734 370 : else if (TREE_CODE (incr) == PREINCREMENT_EXPR
11735 219 : || TREE_CODE (incr) == POSTINCREMENT_EXPR)
11736 299 : incr = integer_one_node;
11737 : else
11738 71 : incr = integer_minus_one_node;
11739 : break;
11740 392 : case MODIFY_EXPR:
11741 392 : if (TREE_OPERAND (incr, 0) != iter)
11742 0 : incr = error_mark_node;
11743 392 : else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
11744 392 : || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
11745 : {
11746 392 : tree rhs = TREE_OPERAND (incr, 1);
11747 392 : if (TREE_OPERAND (rhs, 0) == iter)
11748 : {
11749 299 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
11750 : != INTEGER_TYPE)
11751 0 : incr = error_mark_node;
11752 : else
11753 : {
11754 299 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11755 299 : iter, TREE_CODE (rhs),
11756 299 : TREE_OPERAND (rhs, 1),
11757 : NULL_TREE,
11758 : tf_warning_or_error);
11759 299 : if (error_operand_p (iter_incr))
11760 : return true;
11761 299 : incr = TREE_OPERAND (rhs, 1);
11762 299 : incr = cp_convert (TREE_TYPE (diff), incr,
11763 : tf_warning_or_error);
11764 299 : if (TREE_CODE (rhs) == MINUS_EXPR)
11765 : {
11766 16 : incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
11767 16 : incr = fold_simple (incr);
11768 : }
11769 299 : if (TREE_CODE (incr) != INTEGER_CST
11770 299 : && (TREE_CODE (incr) != NOP_EXPR
11771 66 : || (TREE_CODE (TREE_OPERAND (incr, 0))
11772 : != INTEGER_CST)))
11773 : iter_incr = NULL;
11774 : }
11775 : }
11776 93 : else if (TREE_OPERAND (rhs, 1) == iter)
11777 : {
11778 93 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
11779 93 : || TREE_CODE (rhs) != PLUS_EXPR)
11780 0 : incr = error_mark_node;
11781 : else
11782 : {
11783 93 : iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
11784 : PLUS_EXPR,
11785 93 : TREE_OPERAND (rhs, 0),
11786 : ERROR_MARK, iter,
11787 : ERROR_MARK, NULL_TREE, NULL,
11788 : tf_warning_or_error);
11789 93 : if (error_operand_p (iter_incr))
11790 : return true;
11791 93 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11792 : iter, NOP_EXPR,
11793 : iter_incr, NULL_TREE,
11794 : tf_warning_or_error);
11795 93 : if (error_operand_p (iter_incr))
11796 : return true;
11797 93 : incr = TREE_OPERAND (rhs, 0);
11798 93 : iter_incr = NULL;
11799 : }
11800 : }
11801 : else
11802 0 : incr = error_mark_node;
11803 : }
11804 : else
11805 0 : incr = error_mark_node;
11806 : break;
11807 0 : default:
11808 0 : incr = error_mark_node;
11809 0 : break;
11810 : }
11811 :
11812 762 : if (incr == error_mark_node)
11813 : {
11814 0 : error_at (elocus, "invalid increment expression");
11815 0 : return true;
11816 : }
11817 :
11818 762 : incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
11819 762 : incr = cp_fully_fold (incr);
11820 762 : tree loop_iv_seen = NULL_TREE;
11821 1735 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11822 1093 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
11823 1093 : && OMP_CLAUSE_DECL (c) == iter)
11824 : {
11825 120 : if (code == OMP_TASKLOOP || code == OMP_LOOP)
11826 : {
11827 60 : loop_iv_seen = c;
11828 60 : OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
11829 : }
11830 : break;
11831 : }
11832 973 : else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
11833 113 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
11834 1007 : && OMP_CLAUSE_DECL (c) == iter)
11835 : {
11836 30 : loop_iv_seen = c;
11837 30 : if (code == OMP_TASKLOOP)
11838 25 : OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
11839 : }
11840 :
11841 762 : decl = create_temporary_var (TREE_TYPE (diff));
11842 762 : pushdecl (decl);
11843 762 : add_decl_expr (decl);
11844 762 : last = create_temporary_var (TREE_TYPE (diff));
11845 762 : pushdecl (last);
11846 762 : add_decl_expr (last);
11847 762 : if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
11848 10 : && (!ordered || (i < collapse && collapse > 1)))
11849 : {
11850 10 : incr_var = create_temporary_var (TREE_TYPE (diff));
11851 10 : pushdecl (incr_var);
11852 10 : add_decl_expr (incr_var);
11853 : }
11854 762 : gcc_assert (stmts_are_full_exprs_p ());
11855 762 : tree diffvar = NULL_TREE;
11856 762 : if (code == OMP_TASKLOOP)
11857 : {
11858 101 : if (!loop_iv_seen)
11859 : {
11860 38 : tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11861 38 : OMP_CLAUSE_DECL (ivc) = iter;
11862 38 : cxx_omp_finish_clause (ivc, NULL, false);
11863 38 : OMP_CLAUSE_CHAIN (ivc) = clauses;
11864 38 : clauses = ivc;
11865 : }
11866 101 : tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11867 101 : OMP_CLAUSE_DECL (lvc) = last;
11868 101 : OMP_CLAUSE_CHAIN (lvc) = clauses;
11869 101 : clauses = lvc;
11870 101 : diffvar = create_temporary_var (TREE_TYPE (diff));
11871 101 : pushdecl (diffvar);
11872 101 : add_decl_expr (diffvar);
11873 : }
11874 661 : else if (code == OMP_LOOP)
11875 : {
11876 43 : if (!loop_iv_seen)
11877 : {
11878 : /* While iterators on the loop construct are predetermined
11879 : lastprivate, if the decl is not declared inside of the
11880 : loop, OMP_CLAUSE_LASTPRIVATE should have been added
11881 : already. */
11882 16 : loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11883 16 : OMP_CLAUSE_DECL (loop_iv_seen) = iter;
11884 16 : OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
11885 16 : clauses = loop_iv_seen;
11886 : }
11887 27 : else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
11888 : {
11889 5 : OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
11890 5 : OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
11891 5 : OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
11892 : }
11893 43 : if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
11894 21 : cxx_omp_finish_clause (loop_iv_seen, NULL, false);
11895 : }
11896 :
11897 762 : orig_pre_body = *pre_body;
11898 762 : *pre_body = push_stmt_list ();
11899 762 : if (orig_pre_body)
11900 610 : add_stmt (orig_pre_body);
11901 762 : if (init != NULL)
11902 61 : finish_expr_stmt (build_x_modify_expr (elocus,
11903 : iter, NOP_EXPR, init,
11904 : NULL_TREE, tf_warning_or_error));
11905 762 : init = build_int_cst (TREE_TYPE (diff), 0);
11906 762 : if (c && iter_incr == NULL
11907 28 : && (!ordered || (i < collapse && collapse > 1)))
11908 : {
11909 28 : if (incr_var)
11910 : {
11911 10 : finish_expr_stmt (build_x_modify_expr (elocus,
11912 : incr_var, NOP_EXPR,
11913 : incr, NULL_TREE,
11914 : tf_warning_or_error));
11915 10 : incr = incr_var;
11916 : }
11917 28 : iter_incr = build_x_modify_expr (elocus,
11918 : iter, PLUS_EXPR, incr,
11919 : NULL_TREE, tf_warning_or_error);
11920 : }
11921 762 : if (c && ordered && i < collapse && collapse > 1)
11922 762 : iter_incr = incr;
11923 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11924 : last, NOP_EXPR, init,
11925 : NULL_TREE, tf_warning_or_error));
11926 762 : if (diffvar)
11927 : {
11928 101 : finish_expr_stmt (build_x_modify_expr (elocus,
11929 : diffvar, NOP_EXPR,
11930 : diff, NULL_TREE, tf_warning_or_error));
11931 101 : diff = diffvar;
11932 : }
11933 762 : *pre_body = pop_stmt_list (*pre_body);
11934 :
11935 1524 : cond = cp_build_binary_op (elocus,
11936 762 : TREE_CODE (cond), decl, diff,
11937 : tf_warning_or_error);
11938 762 : incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
11939 : elocus, incr, NULL_TREE);
11940 :
11941 762 : orig_body = *body;
11942 762 : *body = push_stmt_list ();
11943 762 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
11944 762 : iter_init = build_x_modify_expr (elocus,
11945 : iter, PLUS_EXPR, iter_init,
11946 : NULL_TREE, tf_warning_or_error);
11947 762 : if (iter_init != error_mark_node)
11948 759 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11949 762 : finish_expr_stmt (iter_init);
11950 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11951 : last, NOP_EXPR, decl,
11952 : NULL_TREE, tf_warning_or_error));
11953 762 : add_stmt (orig_body);
11954 762 : *body = pop_stmt_list (*body);
11955 :
11956 762 : if (c)
11957 : {
11958 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
11959 120 : if (!ordered)
11960 114 : finish_expr_stmt (iter_incr);
11961 : else
11962 : {
11963 6 : iter_init = decl;
11964 6 : if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
11965 2 : iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
11966 : iter_init, iter_incr);
11967 6 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
11968 6 : iter_init = build_x_modify_expr (elocus,
11969 : iter, PLUS_EXPR, iter_init,
11970 : NULL_TREE, tf_warning_or_error);
11971 6 : if (iter_init != error_mark_node)
11972 6 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11973 6 : finish_expr_stmt (iter_init);
11974 : }
11975 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c)
11976 240 : = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
11977 : }
11978 :
11979 762 : if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
11980 : {
11981 116 : tree t = TREE_VEC_ELT (orig_declv, i);
11982 116 : gcc_assert (TREE_PURPOSE (t) == NULL_TREE
11983 : && TREE_VALUE (t) == NULL_TREE
11984 : && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
11985 116 : TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
11986 116 : TREE_VALUE (t) = last;
11987 : }
11988 : else
11989 646 : TREE_VEC_ELT (orig_declv, i)
11990 1292 : = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
11991 762 : TREE_VEC_ELT (declv, i) = decl;
11992 762 : TREE_VEC_ELT (initv, i) = init;
11993 762 : TREE_VEC_ELT (condv, i) = cond;
11994 762 : TREE_VEC_ELT (incrv, i) = incr;
11995 :
11996 762 : return false;
11997 : }
11998 :
11999 : /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
12000 : are directly for their associated operands in the statement. DECL
12001 : and INIT are a combo; if DECL is NULL then INIT ought to be a
12002 : MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
12003 : optional statements that need to go before the loop into its
12004 : sk_omp scope. */
12005 :
12006 : tree
12007 21246 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
12008 : tree orig_declv, tree initv, tree condv, tree incrv,
12009 : tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
12010 : {
12011 21246 : tree omp_for = NULL, orig_incr = NULL;
12012 21246 : tree decl = NULL, init, cond, incr;
12013 21246 : location_t elocus;
12014 21246 : int i;
12015 21246 : int collapse = 1;
12016 21246 : int ordered = 0;
12017 21246 : auto_vec<location_t> init_locv;
12018 :
12019 21246 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
12020 21246 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
12021 21246 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
12022 21246 : if (TREE_VEC_LENGTH (declv) > 1)
12023 : {
12024 4054 : if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
12025 83 : collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
12026 : else
12027 : {
12028 3971 : if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
12029 3501 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
12030 470 : else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
12031 394 : collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
12032 3971 : if (collapse != TREE_VEC_LENGTH (declv))
12033 100 : ordered = TREE_VEC_LENGTH (declv);
12034 : }
12035 : }
12036 48837 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
12037 : {
12038 27627 : decl = TREE_VEC_ELT (declv, i);
12039 27627 : init = TREE_VEC_ELT (initv, i);
12040 27627 : cond = TREE_VEC_ELT (condv, i);
12041 27627 : incr = TREE_VEC_ELT (incrv, i);
12042 27627 : elocus = locus;
12043 :
12044 27627 : if (decl == global_namespace)
12045 : {
12046 1101 : gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
12047 1101 : TREE_VEC_ELT (declv, i) = NULL_TREE;
12048 1101 : init_locv.safe_push (UNKNOWN_LOCATION);
12049 1101 : continue;
12050 : }
12051 : /* We are going to throw out the init's original MODIFY_EXPR or
12052 : MODOP_EXPR below. Save its location so we can use it when
12053 : reconstructing the expression farther down. Alternatively, if the
12054 : initializer is a binding of the iteration variable, save
12055 : that location. Any of these locations in the initialization clause
12056 : for the current nested loop are better than using the argument locus,
12057 : that points to the "for" of the outermost loop in the nest. */
12058 26526 : if (init && EXPR_HAS_LOCATION (init))
12059 17962 : elocus = EXPR_LOCATION (init);
12060 8564 : else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
12061 : /* This can happen for class iterators. */
12062 0 : elocus = EXPR_LOCATION (decl);
12063 8564 : else if (decl && DECL_P (decl))
12064 : {
12065 8537 : if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
12066 8537 : elocus = DECL_SOURCE_LOCATION (decl);
12067 0 : else if (DECL_INITIAL (decl)
12068 0 : && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
12069 0 : elocus = EXPR_LOCATION (DECL_INITIAL (decl));
12070 : }
12071 26526 : init_locv.safe_push (elocus);
12072 :
12073 26526 : if (decl == NULL)
12074 : {
12075 16654 : if (init != NULL)
12076 16651 : switch (TREE_CODE (init))
12077 : {
12078 16244 : case MODIFY_EXPR:
12079 16244 : decl = TREE_OPERAND (init, 0);
12080 16244 : init = TREE_OPERAND (init, 1);
12081 16244 : break;
12082 389 : case MODOP_EXPR:
12083 389 : if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
12084 : {
12085 389 : decl = TREE_OPERAND (init, 0);
12086 389 : init = TREE_OPERAND (init, 2);
12087 : }
12088 : break;
12089 : default:
12090 : break;
12091 : }
12092 :
12093 16654 : if (decl == NULL)
12094 : {
12095 21 : error_at (locus,
12096 : "expected iteration declaration or initialization");
12097 21 : return NULL;
12098 : }
12099 : }
12100 :
12101 26505 : if (cond == global_namespace)
12102 170 : continue;
12103 :
12104 26335 : if (cond == NULL)
12105 : {
12106 9 : error_at (elocus, "missing controlling predicate");
12107 9 : return NULL;
12108 : }
12109 :
12110 26326 : if (incr == NULL)
12111 : {
12112 6 : error_at (elocus, "missing increment expression");
12113 6 : return NULL;
12114 : }
12115 :
12116 26320 : TREE_VEC_ELT (declv, i) = decl;
12117 26320 : TREE_VEC_ELT (initv, i) = init;
12118 : }
12119 :
12120 21210 : if (orig_inits)
12121 : {
12122 : bool fail = false;
12123 : tree orig_init;
12124 21310 : FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
12125 1181 : if (orig_init
12126 3396 : && !c_omp_check_loop_iv_exprs (locus, code,
12127 : orig_declv ? orig_declv : declv, i,
12128 1164 : TREE_VEC_ELT (declv, i), orig_init,
12129 : NULL_TREE, cp_walk_subtrees))
12130 : fail = true;
12131 20129 : if (fail)
12132 21246 : return NULL;
12133 : }
12134 :
12135 21153 : if (dependent_omp_for_p (declv, initv, condv, incrv, body))
12136 : {
12137 453 : tree stmt;
12138 :
12139 453 : stmt = make_node (code);
12140 :
12141 1499 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
12142 : {
12143 593 : if (TREE_VEC_ELT (declv, i) == NULL_TREE)
12144 9 : continue;
12145 : /* This is really just a place-holder. We'll be decomposing this
12146 : again and going through the cp_build_modify_expr path below when
12147 : we instantiate the thing. */
12148 584 : TREE_VEC_ELT (initv, i)
12149 1168 : = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
12150 584 : TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
12151 : }
12152 :
12153 453 : TREE_TYPE (stmt) = void_type_node;
12154 453 : OMP_FOR_INIT (stmt) = initv;
12155 453 : OMP_FOR_COND (stmt) = condv;
12156 453 : OMP_FOR_INCR (stmt) = incrv;
12157 453 : OMP_FOR_BODY (stmt) = body;
12158 453 : OMP_FOR_PRE_BODY (stmt) = pre_body;
12159 453 : OMP_FOR_CLAUSES (stmt) = clauses;
12160 :
12161 453 : SET_EXPR_LOCATION (stmt, locus);
12162 453 : return add_stmt (stmt);
12163 : }
12164 :
12165 20700 : if (!orig_declv)
12166 19891 : orig_declv = copy_node (declv);
12167 :
12168 20700 : if (processing_template_decl)
12169 634 : orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
12170 :
12171 48266 : for (i = 0; i < TREE_VEC_LENGTH (declv); )
12172 : {
12173 27658 : decl = TREE_VEC_ELT (declv, i);
12174 27658 : init = TREE_VEC_ELT (initv, i);
12175 27658 : cond = TREE_VEC_ELT (condv, i);
12176 27658 : incr = TREE_VEC_ELT (incrv, i);
12177 27658 : if (orig_incr)
12178 866 : TREE_VEC_ELT (orig_incr, i) = incr;
12179 27658 : elocus = init_locv[i];
12180 :
12181 27658 : if (decl == NULL_TREE)
12182 : {
12183 1092 : i++;
12184 1092 : continue;
12185 : }
12186 :
12187 26566 : if (!DECL_P (decl))
12188 : {
12189 6 : error_at (elocus, "expected iteration declaration or initialization");
12190 6 : return NULL;
12191 : }
12192 :
12193 26560 : if (incr && TREE_CODE (incr) == MODOP_EXPR)
12194 : {
12195 1 : if (orig_incr)
12196 1 : TREE_VEC_ELT (orig_incr, i) = incr;
12197 1 : incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
12198 1 : TREE_CODE (TREE_OPERAND (incr, 1)),
12199 1 : TREE_OPERAND (incr, 2),
12200 : tf_warning_or_error);
12201 : }
12202 :
12203 26560 : if (CLASS_TYPE_P (TREE_TYPE (decl)))
12204 : {
12205 825 : if (code == OMP_SIMD)
12206 : {
12207 12 : error_at (elocus, "%<#pragma omp simd%> used with class "
12208 : "iteration variable %qE", decl);
12209 12 : return NULL;
12210 : }
12211 813 : if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
12212 : initv, condv, incrv, &body,
12213 : &pre_body, clauses,
12214 : collapse, ordered))
12215 : return NULL;
12216 762 : continue;
12217 : }
12218 :
12219 51470 : if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
12220 27321 : && !TYPE_PTR_P (TREE_TYPE (decl)))
12221 : {
12222 14 : error_at (elocus, "invalid type for iteration variable %qE", decl);
12223 14 : return NULL;
12224 : }
12225 :
12226 25721 : if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
12227 24938 : init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
12228 : tf_warning_or_error);
12229 : else
12230 783 : init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
12231 25721 : if (decl == error_mark_node || init == error_mark_node)
12232 : return NULL;
12233 :
12234 25712 : TREE_VEC_ELT (declv, i) = decl;
12235 25712 : TREE_VEC_ELT (initv, i) = init;
12236 25712 : TREE_VEC_ELT (condv, i) = cond;
12237 25712 : TREE_VEC_ELT (incrv, i) = incr;
12238 25712 : i++;
12239 : }
12240 :
12241 20608 : if (pre_body && IS_EMPTY_STMT (pre_body))
12242 0 : pre_body = NULL;
12243 :
12244 41216 : omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
12245 : incrv, body, pre_body,
12246 20608 : !processing_template_decl);
12247 :
12248 : /* Check for iterators appearing in lb, b or incr expressions. */
12249 20608 : if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
12250 : omp_for = NULL_TREE;
12251 :
12252 20122 : if (omp_for == NULL)
12253 : return NULL;
12254 :
12255 19906 : add_stmt (omp_for);
12256 :
12257 65590 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
12258 : {
12259 25778 : init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
12260 25778 : if (init == NULL_TREE)
12261 1032 : continue;
12262 24746 : decl = TREE_OPERAND (init, 0);
12263 24746 : cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
12264 24746 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
12265 :
12266 24746 : if (!processing_template_decl)
12267 : {
12268 24203 : if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
12269 : {
12270 106 : tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
12271 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
12272 106 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12273 106 : t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
12274 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
12275 212 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12276 : }
12277 : else
12278 : {
12279 24097 : tree t = TREE_OPERAND (init, 1);
12280 24097 : TREE_OPERAND (init, 1)
12281 48194 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12282 : }
12283 24203 : if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
12284 : {
12285 121 : tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
12286 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
12287 121 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12288 121 : t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
12289 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
12290 242 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12291 : }
12292 : else
12293 : {
12294 24082 : tree t = TREE_OPERAND (cond, 1);
12295 24082 : TREE_OPERAND (cond, 1)
12296 48164 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12297 : }
12298 : }
12299 :
12300 24746 : if (TREE_CODE (incr) != MODIFY_EXPR)
12301 18541 : continue;
12302 :
12303 6205 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
12304 70 : && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
12305 6275 : && !processing_template_decl)
12306 : {
12307 64 : tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
12308 64 : if (TREE_SIDE_EFFECTS (t)
12309 8 : && t != decl
12310 70 : && (TREE_CODE (t) != NOP_EXPR
12311 0 : || TREE_OPERAND (t, 0) != decl))
12312 6 : TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
12313 12 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12314 :
12315 64 : t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
12316 64 : if (TREE_SIDE_EFFECTS (t)
12317 56 : && t != decl
12318 120 : && (TREE_CODE (t) != NOP_EXPR
12319 5 : || TREE_OPERAND (t, 0) != decl))
12320 56 : TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
12321 112 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12322 : }
12323 :
12324 6205 : if (orig_incr)
12325 177 : TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
12326 : }
12327 19906 : OMP_FOR_CLAUSES (omp_for) = clauses;
12328 :
12329 : /* For simd loops with non-static data member iterators, we could have added
12330 : OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
12331 : step at this point, fill it in. */
12332 4741 : if (code == OMP_SIMD && !processing_template_decl
12333 24603 : && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
12334 4625 : for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
12335 561 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
12336 561 : if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
12337 : {
12338 4 : decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
12339 4 : gcc_assert (decl == OMP_CLAUSE_DECL (c));
12340 4 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
12341 4 : tree step, stept;
12342 4 : switch (TREE_CODE (incr))
12343 : {
12344 0 : case PREINCREMENT_EXPR:
12345 0 : case POSTINCREMENT_EXPR:
12346 : /* c_omp_for_incr_canonicalize_ptr() should have been
12347 : called to massage things appropriately. */
12348 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12349 0 : OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
12350 0 : break;
12351 0 : case PREDECREMENT_EXPR:
12352 0 : case POSTDECREMENT_EXPR:
12353 : /* c_omp_for_incr_canonicalize_ptr() should have been
12354 : called to massage things appropriately. */
12355 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12356 0 : OMP_CLAUSE_LINEAR_STEP (c)
12357 0 : = build_int_cst (TREE_TYPE (decl), -1);
12358 0 : break;
12359 4 : case MODIFY_EXPR:
12360 4 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12361 4 : incr = TREE_OPERAND (incr, 1);
12362 4 : switch (TREE_CODE (incr))
12363 : {
12364 4 : case PLUS_EXPR:
12365 4 : if (TREE_OPERAND (incr, 1) == decl)
12366 0 : step = TREE_OPERAND (incr, 0);
12367 : else
12368 4 : step = TREE_OPERAND (incr, 1);
12369 : break;
12370 0 : case MINUS_EXPR:
12371 0 : case POINTER_PLUS_EXPR:
12372 0 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12373 0 : step = TREE_OPERAND (incr, 1);
12374 0 : break;
12375 0 : default:
12376 0 : gcc_unreachable ();
12377 : }
12378 4 : stept = TREE_TYPE (decl);
12379 4 : if (INDIRECT_TYPE_P (stept))
12380 0 : stept = sizetype;
12381 4 : step = fold_convert (stept, step);
12382 4 : if (TREE_CODE (incr) == MINUS_EXPR)
12383 0 : step = fold_build1 (NEGATE_EXPR, stept, step);
12384 4 : OMP_CLAUSE_LINEAR_STEP (c) = step;
12385 4 : break;
12386 0 : default:
12387 0 : gcc_unreachable ();
12388 : }
12389 : }
12390 : /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
12391 : clauses, we need copy ctor for those rather than default ctor,
12392 : plus as for other lastprivates assignment op and dtor. */
12393 19906 : if (code == OMP_LOOP && !processing_template_decl)
12394 1993 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12395 1285 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
12396 204 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
12397 1307 : && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
12398 : false, true, true, true))
12399 0 : CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
12400 :
12401 : return omp_for;
12402 21246 : }
12403 :
12404 : /* Code walker for finish_omp_for_block: extract binding of DP->var
12405 : from its current block and move it to a new BIND_EXPR DP->b
12406 : surrounding the body of DP->omp_for. */
12407 :
12408 : struct fofb_data {
12409 : tree var;
12410 : tree b;
12411 : tree omp_for;
12412 : };
12413 :
12414 : static tree
12415 389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
12416 : {
12417 389 : struct fofb_data *fofb = (struct fofb_data *)dp;
12418 389 : if (TREE_CODE (*tp) == BIND_EXPR)
12419 578 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
12420 : {
12421 576 : if (*p == fofb->var)
12422 : {
12423 363 : *p = DECL_CHAIN (*p);
12424 363 : if (fofb->b == NULL_TREE)
12425 : {
12426 214 : fofb->b = make_node (BLOCK);
12427 214 : fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
12428 214 : OMP_FOR_BODY (fofb->omp_for), fofb->b);
12429 214 : TREE_SIDE_EFFECTS (fofb->b) = 1;
12430 214 : OMP_FOR_BODY (fofb->omp_for) = fofb->b;
12431 : }
12432 363 : DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
12433 363 : BIND_EXPR_VARS (fofb->b) = fofb->var;
12434 363 : BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
12435 363 : BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
12436 363 : return *tp;
12437 : }
12438 : }
12439 26 : if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
12440 22 : *walk_subtrees = false;
12441 : return NULL_TREE;
12442 : }
12443 :
12444 : /* Fix up range for decls. Those decls were pushed into BIND's
12445 : BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
12446 : and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
12447 : so that processing of combined loop directives can find them. */
12448 : tree
12449 14665 : finish_omp_for_block (tree bind, tree omp_for)
12450 : {
12451 14665 : if (omp_for == NULL_TREE
12452 14618 : || !OMP_FOR_ORIG_DECLS (omp_for)
12453 28693 : || bind == NULL_TREE)
12454 637 : return bind;
12455 14028 : struct fofb_data fofb;
12456 14028 : fofb.b = NULL_TREE;
12457 14028 : fofb.omp_for = omp_for;
12458 33583 : for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
12459 19555 : if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
12460 19333 : && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
12461 : == TREE_LIST)
12462 20386 : && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
12463 : {
12464 237 : tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
12465 602 : for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
12466 : {
12467 365 : fofb.var = TREE_VEC_ELT (v, j);
12468 365 : cp_walk_tree (&bind, finish_omp_for_block_walker,
12469 : (void *)&fofb, NULL);
12470 : }
12471 : }
12472 14028 : return bind;
12473 : }
12474 :
12475 : void
12476 3345 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
12477 : tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
12478 : tree clauses, enum omp_memory_order mo, bool weak)
12479 : {
12480 3345 : tree orig_lhs;
12481 3345 : tree orig_rhs;
12482 3345 : tree orig_v;
12483 3345 : tree orig_lhs1;
12484 3345 : tree orig_rhs1;
12485 3345 : tree orig_r;
12486 3345 : bool dependent_p;
12487 3345 : tree stmt;
12488 :
12489 3345 : orig_lhs = lhs;
12490 3345 : orig_rhs = rhs;
12491 3345 : orig_v = v;
12492 3345 : orig_lhs1 = lhs1;
12493 3345 : orig_rhs1 = rhs1;
12494 3345 : orig_r = r;
12495 3345 : dependent_p = false;
12496 3345 : stmt = NULL_TREE;
12497 :
12498 : /* Even in a template, we can detect invalid uses of the atomic
12499 : pragma if neither LHS nor RHS is type-dependent. */
12500 3345 : if (processing_template_decl)
12501 : {
12502 600 : dependent_p = (type_dependent_expression_p (lhs)
12503 237 : || (rhs && type_dependent_expression_p (rhs))
12504 234 : || (v && type_dependent_expression_p (v))
12505 234 : || (lhs1 && type_dependent_expression_p (lhs1))
12506 234 : || (rhs1 && type_dependent_expression_p (rhs1))
12507 834 : || (r
12508 25 : && r != void_list_node
12509 16 : && type_dependent_expression_p (r)));
12510 600 : if (clauses)
12511 : {
12512 30 : gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
12513 : && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
12514 : && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
12515 30 : if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
12516 30 : || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
12517 : dependent_p = true;
12518 : }
12519 : }
12520 576 : if (!dependent_p)
12521 : {
12522 2961 : bool swapped = false;
12523 2961 : if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
12524 : {
12525 143 : std::swap (rhs, rhs1);
12526 143 : swapped = !commutative_tree_code (opcode);
12527 : }
12528 2961 : if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
12529 : {
12530 0 : if (code == OMP_ATOMIC)
12531 0 : error ("%<#pragma omp atomic update%> uses two different "
12532 : "expressions for memory");
12533 : else
12534 0 : error ("%<#pragma omp atomic capture%> uses two different "
12535 : "expressions for memory");
12536 : return;
12537 : }
12538 2961 : if (lhs1 && !cp_tree_equal (lhs, lhs1))
12539 : {
12540 0 : if (code == OMP_ATOMIC)
12541 0 : error ("%<#pragma omp atomic update%> uses two different "
12542 : "expressions for memory");
12543 : else
12544 0 : error ("%<#pragma omp atomic capture%> uses two different "
12545 : "expressions for memory");
12546 : return;
12547 : }
12548 5922 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
12549 : v, lhs1, rhs1, r, swapped, mo, weak,
12550 2961 : processing_template_decl != 0);
12551 2961 : if (stmt == error_mark_node)
12552 : return;
12553 : }
12554 3315 : if (processing_template_decl)
12555 : {
12556 591 : if (code == OMP_ATOMIC_READ)
12557 : {
12558 167 : stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
12559 167 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12560 167 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12561 : }
12562 : else
12563 : {
12564 424 : if (opcode == NOP_EXPR)
12565 35 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
12566 389 : else if (opcode == COND_EXPR)
12567 : {
12568 124 : stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
12569 124 : if (orig_r)
12570 50 : stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
12571 : stmt);
12572 124 : stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
12573 : orig_lhs);
12574 124 : orig_rhs1 = NULL_TREE;
12575 : }
12576 : else
12577 265 : stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
12578 424 : if (orig_rhs1)
12579 182 : stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
12580 : COMPOUND_EXPR, orig_rhs1, stmt);
12581 424 : if (code != OMP_ATOMIC)
12582 : {
12583 233 : stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
12584 233 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12585 233 : OMP_ATOMIC_WEAK (stmt) = weak;
12586 233 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12587 : }
12588 : }
12589 591 : stmt = build2 (OMP_ATOMIC, void_type_node,
12590 : clauses ? clauses : integer_zero_node, stmt);
12591 591 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12592 591 : OMP_ATOMIC_WEAK (stmt) = weak;
12593 591 : SET_EXPR_LOCATION (stmt, loc);
12594 : }
12595 :
12596 : /* Avoid -Wunused-value warnings here, the whole construct has side-effects
12597 : and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
12598 : in some tree that appears to be unused, the value is not unused. */
12599 3315 : warning_sentinel w (warn_unused_value);
12600 3315 : finish_expr_stmt (stmt);
12601 3315 : }
12602 :
12603 : void
12604 359 : finish_omp_barrier (void)
12605 : {
12606 359 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
12607 359 : releasing_vec vec;
12608 359 : vec->quick_push (build_int_cst (integer_type_node, GOMP_BARRIER_EXPLICIT));
12609 359 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12610 359 : finish_expr_stmt (stmt);
12611 359 : }
12612 :
12613 : void
12614 397 : finish_omp_depobj (location_t loc, tree depobj,
12615 : enum omp_clause_depend_kind kind, tree clause)
12616 : {
12617 397 : if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
12618 : {
12619 343 : if (!lvalue_p (depobj))
12620 : {
12621 6 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
12622 : "%<depobj%> expression is not lvalue expression");
12623 6 : depobj = error_mark_node;
12624 : }
12625 : }
12626 :
12627 397 : if (processing_template_decl)
12628 : {
12629 114 : if (clause == NULL_TREE)
12630 47 : clause = build_int_cst (integer_type_node, kind);
12631 114 : add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
12632 114 : return;
12633 : }
12634 :
12635 283 : if (!error_operand_p (depobj))
12636 : {
12637 274 : tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
12638 274 : if (addr == error_mark_node)
12639 : depobj = error_mark_node;
12640 : else
12641 274 : depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
12642 : tf_warning_or_error);
12643 : }
12644 :
12645 283 : c_finish_omp_depobj (loc, depobj, kind, clause);
12646 : }
12647 :
12648 : void
12649 162 : finish_omp_flush (int mo)
12650 : {
12651 162 : tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
12652 162 : releasing_vec vec;
12653 162 : if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
12654 : {
12655 54 : fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
12656 54 : vec->quick_push (build_int_cst (integer_type_node, mo));
12657 : }
12658 162 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12659 162 : finish_expr_stmt (stmt);
12660 162 : }
12661 :
12662 : void
12663 111 : finish_omp_taskwait (void)
12664 : {
12665 111 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
12666 111 : releasing_vec vec;
12667 111 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12668 111 : finish_expr_stmt (stmt);
12669 111 : }
12670 :
12671 : void
12672 16 : finish_omp_taskyield (void)
12673 : {
12674 16 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
12675 16 : releasing_vec vec;
12676 16 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12677 16 : finish_expr_stmt (stmt);
12678 16 : }
12679 :
12680 : void
12681 596 : finish_omp_cancel (tree clauses)
12682 : {
12683 596 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
12684 596 : int mask = 0;
12685 596 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12686 : mask = 1;
12687 414 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12688 : mask = 2;
12689 285 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12690 : mask = 4;
12691 164 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12692 : mask = 8;
12693 : else
12694 : {
12695 0 : error ("%<#pragma omp cancel%> must specify one of "
12696 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12697 0 : return;
12698 : }
12699 596 : releasing_vec vec;
12700 596 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
12701 596 : if (ifc != NULL_TREE)
12702 : {
12703 70 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
12704 70 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
12705 6 : error_at (OMP_CLAUSE_LOCATION (ifc),
12706 : "expected %<cancel%> %<if%> clause modifier");
12707 : else
12708 : {
12709 64 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
12710 64 : if (ifc2 != NULL_TREE)
12711 : {
12712 3 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
12713 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
12714 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
12715 3 : error_at (OMP_CLAUSE_LOCATION (ifc2),
12716 : "expected %<cancel%> %<if%> clause modifier");
12717 : }
12718 : }
12719 :
12720 70 : if (!processing_template_decl)
12721 61 : ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
12722 : else
12723 9 : ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
12724 9 : OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
12725 : integer_zero_node, ERROR_MARK,
12726 : NULL_TREE, NULL, tf_warning_or_error);
12727 : }
12728 : else
12729 526 : ifc = boolean_true_node;
12730 596 : vec->quick_push (build_int_cst (integer_type_node, mask));
12731 596 : vec->quick_push (ifc);
12732 596 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12733 596 : finish_expr_stmt (stmt);
12734 596 : }
12735 :
12736 : void
12737 494 : finish_omp_cancellation_point (tree clauses)
12738 : {
12739 494 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
12740 494 : int mask = 0;
12741 494 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12742 : mask = 1;
12743 366 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12744 : mask = 2;
12745 261 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12746 : mask = 4;
12747 156 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12748 : mask = 8;
12749 : else
12750 : {
12751 3 : error ("%<#pragma omp cancellation point%> must specify one of "
12752 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12753 3 : return;
12754 : }
12755 491 : releasing_vec vec
12756 491 : = make_tree_vector_single (build_int_cst (integer_type_node, mask));
12757 491 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12758 491 : finish_expr_stmt (stmt);
12759 491 : }
12760 :
12761 : /* Begin a __transaction_atomic or __transaction_relaxed statement.
12762 : If PCOMPOUND is non-null, this is for a function-transaction-block, and we
12763 : should create an extra compound stmt. */
12764 :
12765 : tree
12766 303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
12767 : {
12768 303 : tree r;
12769 :
12770 303 : if (pcompound)
12771 21 : *pcompound = begin_compound_stmt (0);
12772 :
12773 303 : r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
12774 :
12775 : /* Only add the statement to the function if support enabled. */
12776 303 : if (flag_tm)
12777 297 : add_stmt (r);
12778 : else
12779 12 : error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
12780 : ? G_("%<__transaction_relaxed%> without "
12781 : "transactional memory support enabled")
12782 : : G_("%<__transaction_atomic%> without "
12783 : "transactional memory support enabled")));
12784 :
12785 303 : TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
12786 303 : TREE_SIDE_EFFECTS (r) = 1;
12787 303 : return r;
12788 : }
12789 :
12790 : /* End a __transaction_atomic or __transaction_relaxed statement.
12791 : If COMPOUND_STMT is non-null, this is for a function-transaction-block,
12792 : and we should end the compound. If NOEX is non-NULL, we wrap the body in
12793 : a MUST_NOT_THROW_EXPR with NOEX as condition. */
12794 :
12795 : void
12796 303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
12797 : {
12798 303 : TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
12799 303 : TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
12800 303 : TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
12801 303 : TRANSACTION_EXPR_IS_STMT (stmt) = 1;
12802 :
12803 : /* noexcept specifications are not allowed for function transactions. */
12804 303 : gcc_assert (!(noex && compound_stmt));
12805 303 : if (noex)
12806 : {
12807 51 : tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
12808 : noex);
12809 51 : protected_set_expr_location
12810 51 : (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
12811 51 : TREE_SIDE_EFFECTS (body) = 1;
12812 51 : TRANSACTION_EXPR_BODY (stmt) = body;
12813 : }
12814 :
12815 303 : if (compound_stmt)
12816 21 : finish_compound_stmt (compound_stmt);
12817 303 : }
12818 :
12819 : /* Build a __transaction_atomic or __transaction_relaxed expression. If
12820 : NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
12821 : condition. */
12822 :
12823 : tree
12824 116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
12825 : {
12826 116 : tree ret;
12827 116 : if (noex)
12828 : {
12829 57 : expr = build_must_not_throw_expr (expr, noex);
12830 57 : protected_set_expr_location (expr, loc);
12831 57 : TREE_SIDE_EFFECTS (expr) = 1;
12832 : }
12833 116 : ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
12834 116 : if (flags & TM_STMT_ATTR_RELAXED)
12835 4 : TRANSACTION_EXPR_RELAXED (ret) = 1;
12836 116 : TREE_SIDE_EFFECTS (ret) = 1;
12837 116 : SET_EXPR_LOCATION (ret, loc);
12838 116 : return ret;
12839 : }
12840 :
12841 : void
12842 100712 : init_cp_semantics (void)
12843 : {
12844 100712 : }
12845 :
12846 :
12847 : /* Get constant string at LOCATION. Returns true if successful,
12848 : otherwise false. */
12849 :
12850 : bool
12851 11421864 : cexpr_str::type_check (location_t location, bool allow_char8_t /*=false*/)
12852 : {
12853 11421864 : tsubst_flags_t complain = tf_warning_or_error;
12854 :
12855 11421864 : if (message == NULL_TREE
12856 11421864 : || message == error_mark_node
12857 22843725 : || check_for_bare_parameter_packs (message))
12858 : return false;
12859 :
12860 11421861 : if (TREE_CODE (message) != STRING_CST
12861 11421861 : && !type_dependent_expression_p (message))
12862 : {
12863 1053 : message_sz
12864 1053 : = finish_class_member_access_expr (message,
12865 : get_identifier ("size"),
12866 : false, complain);
12867 1053 : if (message_sz != error_mark_node)
12868 952 : message_data
12869 952 : = finish_class_member_access_expr (message,
12870 : get_identifier ("data"),
12871 : false, complain);
12872 1053 : if (message_sz == error_mark_node || message_data == error_mark_node)
12873 : {
12874 139 : error_at (location, "constexpr string must be a string "
12875 : "literal or object with %<size%> and "
12876 : "%<data%> members");
12877 322 : return false;
12878 : }
12879 914 : releasing_vec size_args, data_args;
12880 914 : message_sz = finish_call_expr (message_sz, &size_args, false, false,
12881 : complain);
12882 914 : message_data = finish_call_expr (message_data, &data_args, false, false,
12883 : complain);
12884 914 : if (message_sz == error_mark_node || message_data == error_mark_node)
12885 : return false;
12886 800 : message_sz = build_converted_constant_expr (size_type_node, message_sz,
12887 : complain);
12888 800 : if (message_sz == error_mark_node)
12889 : {
12890 15 : error_at (location, "constexpr string %<size()%> "
12891 : "must be implicitly convertible to "
12892 : "%<std::size_t%>");
12893 15 : return false;
12894 : }
12895 :
12896 785 : if (allow_char8_t
12897 74 : && POINTER_TYPE_P (TREE_TYPE (message_data))
12898 74 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
12899 74 : == char8_type_node)
12900 805 : && (TYPE_QUALS (TREE_TYPE (TREE_TYPE (message_data)))
12901 : == TYPE_QUAL_CONST))
12902 : return true;
12903 :
12904 765 : message_data = build_converted_constant_expr (const_string_type_node,
12905 : message_data, complain);
12906 765 : if (message_data == error_mark_node)
12907 : {
12908 34 : error_at (location, "constexpr string %<data()%> "
12909 : "must be implicitly convertible to "
12910 : "%<const char*%>");
12911 34 : return false;
12912 : }
12913 914 : }
12914 : return true;
12915 : }
12916 :
12917 : /* Extract constant string at LOCATON into output string STR.
12918 : Returns true if successful, otherwise false. */
12919 :
12920 : bool
12921 405 : cexpr_str::extract (location_t location, tree &str)
12922 : {
12923 405 : const char *msg;
12924 405 : int len;
12925 405 : if (!extract (location, msg, len))
12926 : return false;
12927 343 : str = build_string (len, msg);
12928 343 : return true;
12929 : }
12930 :
12931 : /* Extract constant string at LOCATION into output string MSG with LEN.
12932 : Returns true if successful, otherwise false. */
12933 :
12934 : bool
12935 2687 : cexpr_str::extract (location_t location, const char * &msg, int &len,
12936 : const constexpr_ctx *ctx /* = NULL */,
12937 : bool *non_constant_p /* = NULL */,
12938 : bool *overflow_p /* = NULL */,
12939 : tree *jump_target /* = NULL */)
12940 : {
12941 2687 : tsubst_flags_t complain = tf_warning_or_error;
12942 :
12943 2687 : msg = NULL;
12944 2687 : if (message_sz && message_data)
12945 : {
12946 677 : tree msz;
12947 677 : if (ctx)
12948 : {
12949 110 : msz = cxx_eval_constant_expression (ctx, message_sz, vc_prvalue,
12950 : non_constant_p, overflow_p,
12951 : jump_target);
12952 110 : if (*jump_target || *non_constant_p)
12953 : return false;
12954 : }
12955 : else
12956 567 : msz = cxx_constant_value (message_sz, NULL_TREE, complain);
12957 669 : if (!tree_fits_uhwi_p (msz))
12958 : {
12959 35 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
12960 35 : error_at (location,
12961 : "constexpr string %<size()%> "
12962 : "must be a constant expression");
12963 : return false;
12964 : }
12965 634 : else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
12966 : != tree_to_uhwi (msz))
12967 : {
12968 0 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
12969 0 : error_at (location,
12970 : "constexpr string message %<size()%> "
12971 : "%qE too large", msz);
12972 : return false;
12973 : }
12974 634 : len = tree_to_uhwi (msz);
12975 634 : tree data;
12976 634 : if (ctx)
12977 : {
12978 102 : data = cxx_eval_constant_expression (ctx, message_data, vc_prvalue,
12979 : non_constant_p, overflow_p,
12980 : jump_target);
12981 102 : if (*jump_target || *non_constant_p)
12982 : return false;
12983 94 : STRIP_NOPS (data);
12984 94 : if (TREE_CODE (data) != ADDR_EXPR)
12985 : {
12986 0 : unhandled:
12987 0 : if (!cxx_constexpr_quiet_p (ctx))
12988 0 : error_at (location, "unhandled return from %<data()%>");
12989 : return false;
12990 : }
12991 94 : tree str = TREE_OPERAND (data, 0);
12992 94 : unsigned HOST_WIDE_INT off = 0;
12993 94 : if (TREE_CODE (str) == ARRAY_REF
12994 94 : && tree_fits_uhwi_p (TREE_OPERAND (str, 1)))
12995 : {
12996 12 : off = tree_to_uhwi (TREE_OPERAND (str, 1));
12997 12 : str = TREE_OPERAND (str, 0);
12998 : }
12999 94 : str = cxx_eval_constant_expression (ctx, str, vc_prvalue,
13000 : non_constant_p, overflow_p,
13001 : jump_target);
13002 94 : if (*jump_target || *non_constant_p)
13003 : return false;
13004 94 : if (TREE_CODE (str) == STRING_CST)
13005 : {
13006 84 : if (TREE_STRING_LENGTH (str) < len
13007 84 : || (unsigned) TREE_STRING_LENGTH (str) < off
13008 168 : || (unsigned) TREE_STRING_LENGTH (str) < off + len)
13009 0 : goto unhandled;
13010 84 : msg = TREE_STRING_POINTER (str) + off;
13011 84 : goto translate;
13012 : }
13013 10 : if (TREE_CODE (str) != CONSTRUCTOR
13014 10 : || TREE_CODE (TREE_TYPE (str)) != ARRAY_TYPE)
13015 0 : goto unhandled;
13016 10 : char *b;
13017 10 : if (len < 64)
13018 10 : b = XALLOCAVEC (char, len + 1);
13019 : else
13020 : {
13021 0 : buf = XNEWVEC (char, len + 1);
13022 0 : b = buf;
13023 : }
13024 10 : msg = b;
13025 10 : memset (b, 0, len + 1);
13026 10 : tree field, value;
13027 10 : unsigned k;
13028 10 : unsigned HOST_WIDE_INT l = 0;
13029 158 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (str), k, field, value)
13030 158 : if (!tree_fits_shwi_p (value))
13031 0 : goto unhandled;
13032 158 : else if (field == NULL_TREE)
13033 : {
13034 0 : if (integer_zerop (value))
13035 : break;
13036 0 : if (l >= off && l < off + len)
13037 0 : b[l - off] = tree_to_shwi (value);
13038 0 : ++l;
13039 : }
13040 158 : else if (TREE_CODE (field) == RANGE_EXPR)
13041 : {
13042 0 : tree lo = TREE_OPERAND (field, 0);
13043 0 : tree hi = TREE_OPERAND (field, 1);
13044 0 : if (!tree_fits_uhwi_p (lo) || !tree_fits_uhwi_p (hi))
13045 0 : goto unhandled;
13046 0 : if (integer_zerop (value))
13047 : break;
13048 0 : unsigned HOST_WIDE_INT m = tree_to_uhwi (hi);
13049 0 : for (l = tree_to_uhwi (lo); l <= m; ++l)
13050 0 : if (l >= off && l < off + len)
13051 0 : b[l - off] = tree_to_shwi (value);
13052 : }
13053 158 : else if (tree_fits_uhwi_p (field))
13054 : {
13055 158 : l = tree_to_uhwi (field);
13056 158 : if (integer_zerop (value))
13057 : break;
13058 148 : if (l >= off && l < off + len)
13059 148 : b[l - off] = tree_to_shwi (value);
13060 148 : l++;
13061 : }
13062 10 : b[len] = '\0';
13063 : }
13064 : else
13065 : {
13066 532 : data = maybe_constant_value (message_data, NULL_TREE, mce_true);
13067 532 : if (!reduced_constant_expression_p (data))
13068 96 : data = NULL_TREE;
13069 532 : if (len)
13070 : {
13071 455 : if (data)
13072 381 : msg = c_getstr (data);
13073 455 : if (msg == NULL)
13074 119 : buf = XNEWVEC (char, len);
13075 1458 : for (int i = 0; i < len; ++i)
13076 : {
13077 1033 : tree t = message_data;
13078 1033 : if (i)
13079 1156 : t = build2 (POINTER_PLUS_EXPR,
13080 578 : TREE_TYPE (message_data), message_data,
13081 578 : size_int (i));
13082 1033 : t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
13083 1033 : tree t2 = cxx_constant_value (t, NULL_TREE, complain);
13084 1033 : if (!tree_fits_shwi_p (t2))
13085 : {
13086 30 : error_at (location,
13087 : "constexpr string %<data()[%d]%> "
13088 : "must be a constant expression", i);
13089 30 : return false;
13090 : }
13091 1003 : if (msg == NULL)
13092 362 : buf[i] = tree_to_shwi (t2);
13093 : /* If c_getstr worked, just verify the first and
13094 : last characters using constant evaluation. */
13095 641 : else if (len > 2 && i == 0)
13096 268 : i = len - 2;
13097 : }
13098 425 : if (msg == NULL)
13099 104 : msg = buf;
13100 : }
13101 77 : else if (!data)
13102 : {
13103 : /* We don't have any function to test whether some
13104 : expression is a core constant expression. So, instead
13105 : test whether (message.data (), 0) is a constant
13106 : expression. */
13107 22 : data = build2 (COMPOUND_EXPR, integer_type_node,
13108 : message_data, integer_zero_node);
13109 22 : tree t = cxx_constant_value (data, NULL_TREE, complain);
13110 22 : if (!integer_zerop (t))
13111 : {
13112 22 : error_at (location,
13113 : "constexpr string %<data()%> "
13114 : "must be a core constant expression");
13115 22 : return false;
13116 : }
13117 : }
13118 : }
13119 : }
13120 : else
13121 : {
13122 2010 : tree eltype = TREE_TYPE (TREE_TYPE (message));
13123 2010 : int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
13124 2010 : msg = TREE_STRING_POINTER (message);
13125 2010 : len = TREE_STRING_LENGTH (message) / sz - 1;
13126 : }
13127 2584 : translate:
13128 2584 : if ((message_sz && message_data) || ctx)
13129 : {
13130 : /* Convert the string from execution charset to SOURCE_CHARSET. */
13131 768 : cpp_string istr, ostr;
13132 768 : istr.len = len;
13133 768 : istr.text = (const unsigned char *) msg;
13134 768 : enum cpp_ttype type = CPP_STRING;
13135 768 : if (message_sz && message_data)
13136 : {
13137 574 : if (POINTER_TYPE_P (TREE_TYPE (message_data))
13138 574 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
13139 574 : == char8_type_node))
13140 : type = CPP_UTF8STRING;
13141 : }
13142 194 : else if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message)))
13143 194 : == char8_type_node)
13144 768 : type = CPP_UTF8STRING;
13145 768 : if (len == 0)
13146 : ;
13147 643 : else if (!cpp_translate_string (parse_in, &istr, &ostr, type,
13148 : true))
13149 : {
13150 0 : if (type == CPP_UTF8STRING)
13151 0 : error_at (location, "could not convert constexpr string from "
13152 : "UTF-8 encoding to source character "
13153 : "set");
13154 : else
13155 0 : error_at (location, "could not convert constexpr string from "
13156 : "ordinary literal encoding to source character "
13157 : "set");
13158 0 : return false;
13159 : }
13160 : else
13161 : {
13162 643 : if (buf)
13163 104 : XDELETEVEC (buf);
13164 643 : msg = buf = const_cast <char *> ((const char *) ostr.text);
13165 643 : len = ostr.len;
13166 : }
13167 : }
13168 :
13169 : return true;
13170 : }
13171 :
13172 : /* Build a STATIC_ASSERT for a static assertion with the condition
13173 : CONDITION and the message text MESSAGE. LOCATION is the location
13174 : of the static assertion in the source code. When MEMBER_P, this
13175 : static assertion is a member of a class. If SHOW_EXPR_P is true,
13176 : print the condition (because it was instantiation-dependent).
13177 : If CONSTEVAL_BLOCK_P is true, this static assertion represents
13178 : a consteval block. */
13179 :
13180 : void
13181 11421173 : finish_static_assert (tree condition, tree message, location_t location,
13182 : bool member_p, bool show_expr_p,
13183 : bool consteval_block_p/*=false*/)
13184 : {
13185 11421173 : tsubst_flags_t complain = tf_warning_or_error;
13186 :
13187 11421173 : if (condition == NULL_TREE
13188 11421173 : || condition == error_mark_node)
13189 4843191 : return;
13190 :
13191 11420947 : if (check_for_bare_parameter_packs (condition))
13192 : return;
13193 :
13194 11420944 : cexpr_str cstr(message);
13195 11420944 : if (!cstr.type_check (location))
13196 : return;
13197 :
13198 : /* Save the condition in case it was a concept check. */
13199 11420850 : tree orig_condition = condition;
13200 :
13201 11420850 : if (instantiation_dependent_expression_p (condition)
13202 11420850 : || instantiation_dependent_expression_p (message))
13203 : {
13204 : /* We're in a template; build a STATIC_ASSERT and put it in
13205 : the right place. */
13206 4842347 : defer:
13207 4842347 : tree assertion = make_node (STATIC_ASSERT);
13208 4842347 : STATIC_ASSERT_CONDITION (assertion) = orig_condition;
13209 4842347 : STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
13210 4842347 : STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
13211 4842347 : CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
13212 :
13213 4842347 : if (member_p)
13214 2479935 : maybe_add_class_template_decl_list (current_class_type,
13215 : assertion,
13216 : /*friend_p=*/0);
13217 : else
13218 2362412 : add_stmt (assertion);
13219 :
13220 : return;
13221 : }
13222 :
13223 : /* Evaluate the consteval { }. This must be done only once. */
13224 6584489 : if (consteval_block_p)
13225 : {
13226 496 : cxx_constant_value (condition);
13227 496 : return;
13228 : }
13229 :
13230 : /* Fold the expression and convert it to a boolean value. */
13231 6583993 : condition = contextual_conv_bool (condition, complain);
13232 6583993 : condition = fold_non_dependent_expr (condition, complain,
13233 : /*manifestly_const_eval=*/true);
13234 :
13235 6583991 : if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
13236 : /* Do nothing; the condition is satisfied. */
13237 : ;
13238 : else
13239 : {
13240 8830 : iloc_sentinel ils (location);
13241 :
13242 8830 : if (integer_zerop (condition))
13243 : {
13244 : /* CWG2518: static_assert failure in a template is not IFNDR. */
13245 7964 : if (processing_template_decl)
13246 5986 : goto defer;
13247 :
13248 1978 : int len;
13249 1978 : const char *msg = NULL;
13250 1978 : if (!cstr.extract (location, msg, len))
13251 25 : return;
13252 :
13253 : /* See if we can find which clause was failing (for logical AND). */
13254 1953 : tree bad = find_failing_clause (NULL, orig_condition);
13255 : /* If not, or its location is unusable, fall back to the previous
13256 : location. */
13257 1953 : location_t cloc = cp_expr_loc_or_loc (bad, location);
13258 :
13259 1953 : auto_diagnostic_group d;
13260 :
13261 : /* Report the error. */
13262 1953 : if (len == 0)
13263 1241 : error_at (cloc, "static assertion failed");
13264 : else
13265 712 : error_at (cloc, "static assertion failed: %.*s", len, msg);
13266 :
13267 1953 : diagnose_failing_condition (bad, cloc, show_expr_p);
13268 :
13269 : /* Suppress -Wreturn-type for functions with failed static_asserts.
13270 : Otherwise templates like:
13271 : if constexpr (whatever)
13272 : return something (args);
13273 : else
13274 : static_assert (false, "explanation");
13275 : get a useless extra -Wreturn-type warning. */
13276 1953 : if (current_function_decl)
13277 756 : suppress_warning (current_function_decl, OPT_Wreturn_type);
13278 1953 : }
13279 866 : else if (condition && condition != error_mark_node)
13280 : {
13281 860 : error ("non-constant condition for static assertion");
13282 860 : if (require_rvalue_constant_expression (condition))
13283 798 : cxx_constant_value (condition);
13284 : }
13285 8830 : }
13286 11420942 : }
13287 :
13288 : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
13289 : suitable for use as a type-specifier.
13290 :
13291 : ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
13292 : id-expression or a class member access, FALSE when it was parsed as
13293 : a full expression. */
13294 :
13295 : tree
13296 43892051 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
13297 : tsubst_flags_t complain)
13298 : {
13299 43892051 : tree type = NULL_TREE;
13300 :
13301 43892051 : if (!expr || error_operand_p (expr))
13302 241886 : return error_mark_node;
13303 :
13304 43650165 : if (TYPE_P (expr)
13305 43650165 : || TREE_CODE (expr) == TYPE_DECL
13306 87300310 : || (TREE_CODE (expr) == BIT_NOT_EXPR
13307 16450 : && TYPE_P (TREE_OPERAND (expr, 0))))
13308 : {
13309 29 : if (complain & tf_error)
13310 29 : error ("argument to %<decltype%> must be an expression");
13311 29 : return error_mark_node;
13312 : }
13313 :
13314 : /* decltype is an unevaluated context. */
13315 43650136 : cp_unevaluated u;
13316 :
13317 43650136 : processing_template_decl_sentinel ptds (/*reset=*/false);
13318 :
13319 : /* Depending on the resolution of DR 1172, we may later need to distinguish
13320 : instantiation-dependent but not type-dependent expressions so that, say,
13321 : A<decltype(sizeof(T))>::U doesn't require 'typename'. */
13322 43650136 : if (instantiation_dependent_uneval_expression_p (expr))
13323 : {
13324 7398866 : dependent:
13325 7399442 : type = cxx_make_type (DECLTYPE_TYPE);
13326 7399442 : DECLTYPE_TYPE_EXPR (type) = expr;
13327 14798884 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
13328 7399442 : = id_expression_or_member_access_p;
13329 7399442 : SET_TYPE_STRUCTURAL_EQUALITY (type);
13330 :
13331 7399442 : return type;
13332 : }
13333 36251270 : else if (processing_template_decl)
13334 : {
13335 7408 : expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
13336 7408 : if (expr == error_mark_node)
13337 : return error_mark_node;
13338 : /* Keep processing_template_decl cleared for the rest of the function
13339 : (for sake of the call to lvalue_kind below, which handles templated
13340 : and non-templated COND_EXPR differently). */
13341 7371 : processing_template_decl = 0;
13342 : }
13343 :
13344 : /* The type denoted by decltype(e) is defined as follows: */
13345 :
13346 36251233 : expr = resolve_nondeduced_context (expr, complain);
13347 36251233 : if (!mark_single_function (expr, complain))
13348 0 : return error_mark_node;
13349 :
13350 36251233 : if (invalid_nonstatic_memfn_p (input_location, expr, complain))
13351 18 : return error_mark_node;
13352 :
13353 36251215 : if (type_unknown_p (expr))
13354 : {
13355 18 : if (complain & tf_error)
13356 6 : error ("%<decltype%> cannot resolve address of overloaded function");
13357 18 : return error_mark_node;
13358 : }
13359 :
13360 36251197 : if (id_expression_or_member_access_p)
13361 : {
13362 : /* If e is an id-expression or a class member access (5.2.5
13363 : [expr.ref]), decltype(e) is defined as the type of the entity
13364 : named by e. If there is no such entity, or e names a set of
13365 : overloaded functions, the program is ill-formed. */
13366 547274 : if (identifier_p (expr))
13367 0 : expr = lookup_name (expr);
13368 :
13369 : /* If e is a constified expression inside a contract assertion,
13370 : strip the const wrapper. Per P2900R14, "For a function f with the
13371 : return type T , the result name is an lvalue of type const T , decltype(r)
13372 : is T , and decltype((r)) is const T&." */
13373 547274 : expr = strip_contract_const_wrapper (expr);
13374 :
13375 372684 : if (REFERENCE_REF_P (expr)
13376 547279 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
13377 : /* This can happen when the expression is, e.g., "a.b". Just
13378 : look at the underlying operand. */
13379 375955 : expr = TREE_OPERAND (expr, 0);
13380 :
13381 547274 : if (TREE_CODE (expr) == OFFSET_REF
13382 547274 : || TREE_CODE (expr) == MEMBER_REF
13383 547274 : || TREE_CODE (expr) == SCOPE_REF)
13384 : /* We're only interested in the field itself. If it is a
13385 : BASELINK, we will need to see through it in the next
13386 : step. */
13387 0 : expr = TREE_OPERAND (expr, 1);
13388 :
13389 547274 : if (BASELINK_P (expr))
13390 : /* See through BASELINK nodes to the underlying function. */
13391 7 : expr = BASELINK_FUNCTIONS (expr);
13392 :
13393 : /* decltype of a decomposition name drops references in the tuple case
13394 : (unlike decltype of a normal variable) and keeps cv-qualifiers from
13395 : the containing object in the other cases (unlike decltype of a member
13396 : access expression). */
13397 547274 : if (DECL_DECOMPOSITION_P (expr))
13398 : {
13399 1449 : if (ptds.saved)
13400 : {
13401 275 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr)
13402 : || (DECL_CONTEXT (expr)
13403 : != current_function_decl));
13404 : /* DECL_HAS_VALUE_EXPR_P is always set if
13405 : processing_template_decl at least for structured bindings
13406 : within the template. If lookup_decomp_type
13407 : returns non-NULL, it is the tuple case. */
13408 275 : if (tree ret = lookup_decomp_type (expr))
13409 : return ret;
13410 191 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
13411 : }
13412 1365 : if (DECL_HAS_VALUE_EXPR_P (expr))
13413 : /* Expr is an array or struct subobject proxy, handle
13414 : bit-fields properly. */
13415 1021 : return unlowered_expr_type (expr);
13416 : else
13417 : /* Expr is a reference variable for the tuple case. */
13418 344 : return lookup_decomp_type (expr);
13419 : }
13420 :
13421 545825 : switch (TREE_CODE (expr))
13422 : {
13423 650 : case FIELD_DECL:
13424 650 : if (DECL_BIT_FIELD_TYPE (expr))
13425 : {
13426 : type = DECL_BIT_FIELD_TYPE (expr);
13427 : break;
13428 : }
13429 : /* Fall through for fields that aren't bitfields. */
13430 147355 : gcc_fallthrough ();
13431 :
13432 147355 : case VAR_DECL:
13433 147355 : if (is_capture_proxy (expr))
13434 : {
13435 99 : if (is_normal_capture_proxy (expr))
13436 : {
13437 21 : expr = DECL_CAPTURED_VARIABLE (expr);
13438 21 : type = TREE_TYPE (expr);
13439 : }
13440 : else
13441 : {
13442 78 : expr = DECL_VALUE_EXPR (expr);
13443 78 : gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
13444 78 : expr = TREE_OPERAND (expr, 1);
13445 78 : type = TREE_TYPE (expr);
13446 : }
13447 : break;
13448 : }
13449 : /* Fall through for variables that aren't capture proxies. */
13450 534778 : gcc_fallthrough ();
13451 :
13452 534778 : case FUNCTION_DECL:
13453 534778 : case CONST_DECL:
13454 534778 : case PARM_DECL:
13455 534778 : case RESULT_DECL:
13456 534778 : case TEMPLATE_PARM_INDEX:
13457 534778 : expr = mark_type_use (expr);
13458 534778 : type = TREE_TYPE (expr);
13459 534778 : if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
13460 : {
13461 : /* decltype of an NTTP object is the type of the template
13462 : parameter, which is the object type modulo cv-quals. */
13463 2643 : int quals = cp_type_quals (type);
13464 2643 : gcc_checking_assert (quals & TYPE_QUAL_CONST);
13465 2643 : type = cv_unqualified (type);
13466 : }
13467 : break;
13468 :
13469 0 : case ERROR_MARK:
13470 0 : type = error_mark_node;
13471 0 : break;
13472 :
13473 3506 : case COMPONENT_REF:
13474 3506 : case COMPOUND_EXPR:
13475 3506 : mark_type_use (expr);
13476 3506 : type = is_bitfield_expr_with_lowered_type (expr);
13477 3506 : if (!type)
13478 3469 : type = TREE_TYPE (TREE_OPERAND (expr, 1));
13479 : break;
13480 :
13481 0 : case BIT_FIELD_REF:
13482 0 : gcc_unreachable ();
13483 :
13484 3497 : case INTEGER_CST:
13485 3497 : case PTRMEM_CST:
13486 : /* We can get here when the id-expression refers to an
13487 : enumerator or non-type template parameter. */
13488 3497 : type = TREE_TYPE (expr);
13489 3497 : break;
13490 :
13491 3945 : default:
13492 : /* Handle instantiated template non-type arguments. */
13493 3945 : type = TREE_TYPE (expr);
13494 3945 : break;
13495 : }
13496 : }
13497 : else
13498 : {
13499 35703923 : tree decl = STRIP_REFERENCE_REF (expr);
13500 35703923 : tree lam = current_lambda_expr ();
13501 35703923 : if (lam && outer_automatic_var_p (decl))
13502 : {
13503 : /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
13504 : unevaluated operand within S would refer to an entity captured by
13505 : copy in some intervening lambda-expression, then let E be the
13506 : innermost such lambda-expression.
13507 :
13508 : If there is such a lambda-expression and if P is in E's function
13509 : parameter scope but not its parameter-declaration-clause, then the
13510 : type of the expression is the type of a class member access
13511 : expression naming the non-static data member that would be declared
13512 : for such a capture in the object parameter of the function call
13513 : operator of E." */
13514 : /* FIXME: This transformation needs to happen for all uses of an outer
13515 : local variable inside decltype, not just decltype((x)) (PR83167).
13516 : And we don't handle nested lambdas properly, where we need to
13517 : consider the outer lambdas as well (PR112926). */
13518 1379 : tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
13519 : LOOK_want::HIDDEN_LAMBDA);
13520 :
13521 1379 : if (cap && is_capture_proxy (cap))
13522 467 : type = TREE_TYPE (cap);
13523 912 : else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
13524 : {
13525 738 : type = TREE_TYPE (decl);
13526 738 : if (TYPE_REF_P (type)
13527 738 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
13528 36 : type = TREE_TYPE (type);
13529 : }
13530 :
13531 1205 : if (type && !TYPE_REF_P (type))
13532 : {
13533 1121 : int quals;
13534 1121 : if (current_function_decl
13535 2104 : && LAMBDA_FUNCTION_P (current_function_decl)
13536 2104 : && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
13537 : {
13538 900 : tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
13539 900 : if (WILDCARD_TYPE_P (non_reference (obtype)))
13540 : /* We don't know what the eventual obtype quals will be. */
13541 576 : goto dependent;
13542 648 : auto direct_type = [](tree t){
13543 324 : if (INDIRECT_TYPE_P (t))
13544 162 : return TREE_TYPE (t);
13545 : return t;
13546 : };
13547 648 : quals = (cp_type_quals (type)
13548 324 : | cp_type_quals (direct_type (obtype)));
13549 : }
13550 : else
13551 : /* We are in the parameter clause, trailing return type, or
13552 : the requires clause and have no relevant c_f_decl yet. */
13553 349 : quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
13554 221 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
13555 545 : type = cp_build_qualified_type (type, quals);
13556 545 : type = build_reference_type (type);
13557 : }
13558 : }
13559 35702544 : else if (error_operand_p (expr))
13560 0 : type = error_mark_node;
13561 35702544 : else if (expr == current_class_ptr)
13562 : /* If the expression is just "this", we want the
13563 : cv-unqualified pointer for the "this" type. */
13564 0 : type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
13565 :
13566 545 : if (!type)
13567 : {
13568 : /* Otherwise, where T is the type of e, if e is an lvalue,
13569 : decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
13570 35702718 : cp_lvalue_kind clk = lvalue_kind (expr);
13571 35702718 : type = unlowered_expr_type (expr);
13572 35702718 : gcc_assert (!TYPE_REF_P (type));
13573 :
13574 : /* For vector types, pick a non-opaque variant. */
13575 35702718 : if (VECTOR_TYPE_P (type))
13576 4421 : type = strip_typedefs (type);
13577 :
13578 35702718 : if (clk != clk_none && !(clk & clk_class))
13579 9052445 : type = cp_build_reference_type (type, (clk & clk_rvalueref));
13580 : }
13581 : }
13582 :
13583 : return type;
13584 43650136 : }
13585 :
13586 : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
13587 : __has_nothrow_copy, depending on assign_p. Returns true iff all
13588 : the copy {ctor,assign} fns are nothrow. */
13589 :
13590 : static bool
13591 279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
13592 : {
13593 279 : tree fns = NULL_TREE;
13594 :
13595 279 : if (assign_p || TYPE_HAS_COPY_CTOR (type))
13596 276 : fns = get_class_binding (type, assign_p ? assign_op_identifier
13597 : : ctor_identifier);
13598 :
13599 279 : bool saw_copy = false;
13600 696 : for (ovl_iterator iter (fns); iter; ++iter)
13601 : {
13602 441 : tree fn = *iter;
13603 :
13604 441 : if (copy_fn_p (fn) > 0)
13605 : {
13606 423 : saw_copy = true;
13607 423 : if (!maybe_instantiate_noexcept (fn)
13608 423 : || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
13609 192 : return false;
13610 : }
13611 : }
13612 :
13613 87 : return saw_copy;
13614 : }
13615 :
13616 : /* Return true if BASE is a pointer-interconvertible base of DERIVED. */
13617 :
13618 : bool
13619 183 : pointer_interconvertible_base_of_p (tree base, tree derived,
13620 : bool explain/*=false*/)
13621 : {
13622 183 : if (base == error_mark_node || derived == error_mark_node)
13623 : return false;
13624 :
13625 183 : base = TYPE_MAIN_VARIANT (base);
13626 183 : derived = TYPE_MAIN_VARIANT (derived);
13627 183 : if (!NON_UNION_CLASS_TYPE_P (base))
13628 : {
13629 17 : if (explain)
13630 3 : inform (location_of (base),
13631 : "%qT is not a non-union class type", base);
13632 : return false;
13633 : }
13634 166 : if (!NON_UNION_CLASS_TYPE_P (derived))
13635 : {
13636 8 : if (explain)
13637 3 : inform (location_of (derived),
13638 : "%qT is not a non-union class type", derived);
13639 : return false;
13640 : }
13641 :
13642 158 : if (same_type_p (base, derived))
13643 : return true;
13644 :
13645 117 : if (!std_layout_type_p (derived))
13646 : {
13647 18 : if (explain)
13648 6 : inform (location_of (derived),
13649 : "%qT is not a standard-layout type", derived);
13650 : return false;
13651 : }
13652 :
13653 99 : if (!uniquely_derived_from_p (base, derived))
13654 : {
13655 18 : if (explain)
13656 : {
13657 : /* An ambiguous base should already be impossible due to
13658 : the std_layout_type_p check. */
13659 3 : gcc_checking_assert (!DERIVED_FROM_P (base, derived));
13660 3 : inform (location_of (derived),
13661 : "%qT is not a base of %qT", base, derived);
13662 : }
13663 : return false;
13664 : }
13665 :
13666 : return true;
13667 : }
13668 :
13669 : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
13670 : return true if MEMBERTYPE is the type of the first non-static data member
13671 : of TYPE or for unions of any members. */
13672 : static bool
13673 637 : first_nonstatic_data_member_p (tree type, tree membertype)
13674 : {
13675 1297 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
13676 : {
13677 1222 : if (TREE_CODE (field) != FIELD_DECL)
13678 135 : continue;
13679 1087 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
13680 60 : continue;
13681 1027 : if (DECL_FIELD_IS_BASE (field))
13682 45 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
13683 982 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13684 : {
13685 216 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
13686 138 : || std_layout_type_p (TREE_TYPE (field)))
13687 294 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
13688 : return true;
13689 : }
13690 766 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13691 : membertype))
13692 : return true;
13693 537 : if (TREE_CODE (type) != UNION_TYPE)
13694 : return false;
13695 : }
13696 : return false;
13697 : }
13698 :
13699 : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
13700 :
13701 : tree
13702 536 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
13703 : tree *args)
13704 : {
13705 : /* Unless users call the builtin directly, the following 3 checks should be
13706 : ensured from std::is_pointer_interconvertible_with_class function
13707 : template. */
13708 536 : if (nargs != 1)
13709 : {
13710 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13711 : "needs a single argument");
13712 6 : return boolean_false_node;
13713 : }
13714 530 : tree arg = args[0];
13715 530 : if (error_operand_p (arg))
13716 0 : return boolean_false_node;
13717 530 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
13718 : {
13719 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13720 : "argument is not pointer to member");
13721 6 : return boolean_false_node;
13722 : }
13723 :
13724 524 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
13725 18 : return boolean_false_node;
13726 :
13727 506 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
13728 506 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
13729 506 : if (!complete_type_or_else (basetype, NULL_TREE))
13730 3 : return boolean_false_node;
13731 :
13732 503 : if (TREE_CODE (basetype) != UNION_TYPE
13733 503 : && !std_layout_type_p (basetype))
13734 22 : return boolean_false_node;
13735 :
13736 481 : if (!first_nonstatic_data_member_p (basetype, membertype))
13737 132 : return boolean_false_node;
13738 :
13739 349 : if (TREE_CODE (arg) == PTRMEM_CST)
13740 68 : arg = cplus_expand_constant (arg);
13741 :
13742 349 : if (integer_nonzerop (arg))
13743 10 : return boolean_false_node;
13744 339 : if (integer_zerop (arg))
13745 71 : return boolean_true_node;
13746 :
13747 268 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
13748 : build_zero_cst (TREE_TYPE (arg)));
13749 : }
13750 :
13751 : /* Helper function for is_corresponding_member_aggr. Return true if
13752 : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
13753 : union or structure BASETYPE. */
13754 :
13755 : static bool
13756 90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
13757 : {
13758 222 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
13759 192 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
13760 36 : continue;
13761 156 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13762 : membertype))
13763 : {
13764 48 : if (TREE_CODE (arg) != INTEGER_CST
13765 48 : || tree_int_cst_equal (arg, byte_position (field)))
13766 : return true;
13767 : }
13768 108 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13769 : {
13770 18 : tree narg = arg;
13771 18 : if (TREE_CODE (basetype) != UNION_TYPE
13772 0 : && TREE_CODE (narg) == INTEGER_CST)
13773 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
13774 18 : if (is_corresponding_member_union (TREE_TYPE (field),
13775 : membertype, narg))
13776 : return true;
13777 : }
13778 : return false;
13779 : }
13780 :
13781 : /* Helper function for fold_builtin_is_corresponding_member call.
13782 : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
13783 : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
13784 : boolean_true_node if they are corresponding members, or for
13785 : non-constant ARG2 the highest member offset for corresponding
13786 : members. */
13787 :
13788 : static tree
13789 550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
13790 : tree arg1, tree basetype2, tree membertype2,
13791 : tree arg2)
13792 : {
13793 550 : tree field1 = TYPE_FIELDS (basetype1);
13794 550 : tree field2 = TYPE_FIELDS (basetype2);
13795 550 : tree ret = boolean_false_node;
13796 2376 : while (1)
13797 : {
13798 1463 : bool r = next_common_initial_sequence (field1, field2);
13799 1463 : if (field1 == NULL_TREE || field2 == NULL_TREE)
13800 : break;
13801 1331 : if (r
13802 1038 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
13803 : membertype1)
13804 1841 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
13805 : membertype2))
13806 : {
13807 504 : tree pos = byte_position (field1);
13808 504 : if (TREE_CODE (arg1) == INTEGER_CST
13809 504 : && tree_int_cst_equal (arg1, pos))
13810 : {
13811 92 : if (TREE_CODE (arg2) == INTEGER_CST)
13812 92 : return boolean_true_node;
13813 : return pos;
13814 : }
13815 412 : else if (TREE_CODE (arg1) != INTEGER_CST)
13816 1188 : ret = pos;
13817 : }
13818 1654 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
13819 944 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
13820 : {
13821 117 : if ((!lookup_attribute ("no_unique_address",
13822 117 : DECL_ATTRIBUTES (field1)))
13823 117 : != !lookup_attribute ("no_unique_address",
13824 117 : DECL_ATTRIBUTES (field2)))
13825 : break;
13826 117 : if (!tree_int_cst_equal (bit_position (field1),
13827 117 : bit_position (field2)))
13828 : break;
13829 99 : bool overlap = true;
13830 99 : tree pos = byte_position (field1);
13831 99 : if (TREE_CODE (arg1) == INTEGER_CST)
13832 : {
13833 27 : tree off1 = fold_convert (sizetype, arg1);
13834 27 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
13835 27 : if (tree_int_cst_lt (off1, pos)
13836 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
13837 : overlap = false;
13838 : }
13839 99 : if (TREE_CODE (arg2) == INTEGER_CST)
13840 : {
13841 27 : tree off2 = fold_convert (sizetype, arg2);
13842 27 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
13843 27 : if (tree_int_cst_lt (off2, pos)
13844 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
13845 : overlap = false;
13846 : }
13847 87 : if (overlap
13848 87 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
13849 126 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
13850 : {
13851 39 : tree narg1 = arg1;
13852 39 : if (TREE_CODE (arg1) == INTEGER_CST)
13853 9 : narg1 = size_binop (MINUS_EXPR,
13854 : fold_convert (sizetype, arg1), pos);
13855 39 : tree narg2 = arg2;
13856 39 : if (TREE_CODE (arg2) == INTEGER_CST)
13857 9 : narg2 = size_binop (MINUS_EXPR,
13858 : fold_convert (sizetype, arg2), pos);
13859 39 : tree t1 = TREE_TYPE (field1);
13860 39 : tree t2 = TREE_TYPE (field2);
13861 39 : tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
13862 : narg1, t2, membertype2,
13863 : narg2);
13864 39 : if (nret != boolean_false_node)
13865 : {
13866 39 : if (nret == boolean_true_node)
13867 : return nret;
13868 30 : if (TREE_CODE (arg1) == INTEGER_CST)
13869 0 : return size_binop (PLUS_EXPR, nret, pos);
13870 30 : ret = size_binop (PLUS_EXPR, nret, pos);
13871 : }
13872 : }
13873 60 : else if (overlap
13874 48 : && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
13875 108 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
13876 : {
13877 48 : tree narg1 = arg1;
13878 48 : if (TREE_CODE (arg1) == INTEGER_CST)
13879 6 : narg1 = size_binop (MINUS_EXPR,
13880 : fold_convert (sizetype, arg1), pos);
13881 48 : tree narg2 = arg2;
13882 48 : if (TREE_CODE (arg2) == INTEGER_CST)
13883 6 : narg2 = size_binop (MINUS_EXPR,
13884 : fold_convert (sizetype, arg2), pos);
13885 48 : if (is_corresponding_member_union (TREE_TYPE (field1),
13886 : membertype1, narg1)
13887 48 : && is_corresponding_member_union (TREE_TYPE (field2),
13888 : membertype2, narg2))
13889 : {
13890 24 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
13891 : "not well defined for anonymous unions");
13892 24 : return boolean_false_node;
13893 : }
13894 : }
13895 : }
13896 1188 : if (!r)
13897 : break;
13898 913 : field1 = DECL_CHAIN (field1);
13899 913 : field2 = DECL_CHAIN (field2);
13900 913 : }
13901 : return ret;
13902 : }
13903 :
13904 : /* Fold __builtin_is_corresponding_member call. */
13905 :
13906 : tree
13907 699 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
13908 : tree *args)
13909 : {
13910 : /* Unless users call the builtin directly, the following 3 checks should be
13911 : ensured from std::is_corresponding_member function template. */
13912 699 : if (nargs != 2)
13913 : {
13914 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13915 : "needs two arguments");
13916 9 : return boolean_false_node;
13917 : }
13918 690 : tree arg1 = args[0];
13919 690 : tree arg2 = args[1];
13920 690 : if (error_operand_p (arg1) || error_operand_p (arg2))
13921 0 : return boolean_false_node;
13922 711 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
13923 705 : || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
13924 : {
13925 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13926 : "argument is not pointer to member");
13927 9 : return boolean_false_node;
13928 : }
13929 :
13930 681 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
13931 681 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
13932 15 : return boolean_false_node;
13933 :
13934 666 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
13935 666 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
13936 666 : if (!complete_type_or_else (basetype1, NULL_TREE))
13937 12 : return boolean_false_node;
13938 :
13939 654 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
13940 654 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
13941 654 : if (!complete_type_or_else (basetype2, NULL_TREE))
13942 12 : return boolean_false_node;
13943 :
13944 627 : if (!NON_UNION_CLASS_TYPE_P (basetype1)
13945 627 : || !NON_UNION_CLASS_TYPE_P (basetype2)
13946 627 : || !std_layout_type_p (basetype1)
13947 1233 : || !std_layout_type_p (basetype2))
13948 51 : return boolean_false_node;
13949 :
13950 : /* If the member types aren't layout compatible, then they
13951 : can't be corresponding members. */
13952 591 : if (!layout_compatible_type_p (membertype1, membertype2))
13953 18 : return boolean_false_node;
13954 :
13955 573 : if (TREE_CODE (arg1) == PTRMEM_CST)
13956 176 : arg1 = cplus_expand_constant (arg1);
13957 573 : if (TREE_CODE (arg2) == PTRMEM_CST)
13958 182 : arg2 = cplus_expand_constant (arg2);
13959 :
13960 573 : if (null_member_pointer_value_p (arg1)
13961 573 : || null_member_pointer_value_p (arg2))
13962 9 : return boolean_false_node;
13963 :
13964 564 : if (TREE_CODE (arg1) == INTEGER_CST
13965 182 : && TREE_CODE (arg2) == INTEGER_CST
13966 746 : && !tree_int_cst_equal (arg1, arg2))
13967 53 : return boolean_false_node;
13968 :
13969 511 : if (TREE_CODE (arg2) == INTEGER_CST
13970 129 : && TREE_CODE (arg1) != INTEGER_CST)
13971 : {
13972 : std::swap (arg1, arg2);
13973 : std::swap (membertype1, membertype2);
13974 : std::swap (basetype1, basetype2);
13975 : }
13976 :
13977 511 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
13978 : basetype2, membertype2, arg2);
13979 511 : if (TREE_TYPE (ret) == boolean_type_node)
13980 : return ret;
13981 : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
13982 : already returns boolean_{true,false}_node whether those particular
13983 : members are corresponding members or not. Otherwise, if only
13984 : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
13985 : above), it returns boolean_false_node if it is certainly not a
13986 : corresponding member and otherwise we need to do a runtime check that
13987 : those two OFFSET_TYPE offsets are equal.
13988 : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
13989 : returns the largest offset at which the members would be corresponding
13990 : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
13991 304 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
13992 304 : if (TREE_CODE (arg1) == INTEGER_CST)
13993 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13994 : fold_convert (TREE_TYPE (arg1), arg2));
13995 304 : ret = fold_build2 (LE_EXPR, boolean_type_node,
13996 : fold_convert (pointer_sized_int_node, arg1),
13997 : fold_convert (pointer_sized_int_node, ret));
13998 304 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
13999 : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
14000 : fold_convert (TREE_TYPE (arg1), arg2)));
14001 : }
14002 :
14003 : /* Fold __builtin_is_string_literal call. */
14004 :
14005 : tree
14006 4246 : fold_builtin_is_string_literal (location_t loc, int nargs, tree *args)
14007 : {
14008 : /* Unless users call the builtin directly, the following 3 checks should be
14009 : ensured from std::is_string_literal overloads. */
14010 4246 : if (nargs != 1)
14011 : {
14012 0 : error_at (loc, "%<__builtin_is_string_literal%> needs a single "
14013 : "argument");
14014 0 : return boolean_false_node;
14015 : }
14016 4246 : tree arg = args[0];
14017 4246 : if (error_operand_p (arg))
14018 0 : return boolean_false_node;
14019 4246 : if (!TYPE_PTR_P (TREE_TYPE (arg))
14020 4246 : || !TYPE_READONLY (TREE_TYPE (TREE_TYPE (arg)))
14021 8492 : || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (arg))))
14022 : {
14023 0 : arg_invalid:
14024 0 : error_at (loc, "%<__builtin_is_string_literal%> "
14025 : "argument is not %<const char*%>, %<const wchar_t*%>, "
14026 : "%<const char8_t*%>, %<const char16_t*%> or "
14027 : "%<const char32_t*%>");
14028 0 : return boolean_false_node;
14029 : }
14030 4246 : tree chart = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg)));
14031 4246 : if (chart != char_type_node
14032 3392 : && chart != wchar_type_node
14033 2544 : && chart != char8_type_node
14034 1696 : && chart != char16_type_node
14035 848 : && chart != char32_type_node)
14036 0 : goto arg_invalid;
14037 :
14038 4246 : STRIP_NOPS (arg);
14039 8504 : while (TREE_CODE (arg) == POINTER_PLUS_EXPR)
14040 : {
14041 12 : arg = TREE_OPERAND (arg, 0);
14042 12 : STRIP_NOPS (arg);
14043 : }
14044 4246 : if (TREE_CODE (arg) != ADDR_EXPR)
14045 4190 : return boolean_false_node;
14046 56 : arg = TREE_OPERAND (arg, 0);
14047 56 : if (TREE_CODE (arg) == ARRAY_REF)
14048 24 : arg = TREE_OPERAND (arg, 0);
14049 56 : if (TREE_CODE (arg) != STRING_CST)
14050 16 : return boolean_false_node;
14051 40 : return boolean_true_node;
14052 : }
14053 :
14054 : /* [basic.types] 8. True iff TYPE is an object type. */
14055 :
14056 : static bool
14057 2944971 : object_type_p (const_tree type)
14058 : {
14059 2944971 : return (TREE_CODE (type) != FUNCTION_TYPE
14060 0 : && !TYPE_REF_P (type)
14061 2944971 : && !VOID_TYPE_P (type));
14062 : }
14063 :
14064 : /* [defns.referenceable] True iff TYPE is a referenceable type. */
14065 :
14066 : static bool
14067 3594131 : referenceable_type_p (const_tree type)
14068 : {
14069 3594131 : return (TYPE_REF_P (type)
14070 3594587 : || object_type_p (type)
14071 3594587 : || (FUNC_OR_METHOD_TYPE_P (type)
14072 385 : && type_memfn_quals (type) == TYPE_UNQUALIFIED
14073 319 : && type_memfn_rqual (type) == REF_QUAL_NONE));
14074 : }
14075 :
14076 : /* Actually evaluates the trait. */
14077 :
14078 : static bool
14079 18258442 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
14080 : {
14081 18258442 : enum tree_code type_code1;
14082 18258442 : tree t;
14083 :
14084 18258442 : type_code1 = TREE_CODE (type1);
14085 :
14086 18258442 : switch (kind)
14087 : {
14088 317 : case CPTK_HAS_NOTHROW_ASSIGN:
14089 317 : type1 = strip_array_types (type1);
14090 601 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
14091 601 : && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
14092 173 : || (CLASS_TYPE_P (type1)
14093 129 : && classtype_has_nothrow_assign_or_copy_p (type1,
14094 : true))));
14095 :
14096 215 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
14097 215 : type1 = strip_array_types (type1);
14098 215 : return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
14099 215 : || (CLASS_TYPE_P (type1)
14100 93 : && (t = locate_ctor (type1))
14101 60 : && maybe_instantiate_noexcept (t)
14102 58 : && TYPE_NOTHROW_P (TREE_TYPE (t))));
14103 :
14104 305 : case CPTK_HAS_NOTHROW_COPY:
14105 305 : type1 = strip_array_types (type1);
14106 305 : return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
14107 305 : || (CLASS_TYPE_P (type1)
14108 150 : && classtype_has_nothrow_assign_or_copy_p (type1, false)));
14109 :
14110 517 : case CPTK_HAS_TRIVIAL_ASSIGN:
14111 : /* ??? The standard seems to be missing the "or array of such a class
14112 : type" wording for this trait. */
14113 517 : type1 = strip_array_types (type1);
14114 1016 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
14115 1001 : && (trivial_type_p (type1)
14116 307 : || (CLASS_TYPE_P (type1)
14117 222 : && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
14118 :
14119 545 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14120 545 : type1 = strip_array_types (type1);
14121 545 : return (trivial_type_p (type1)
14122 545 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
14123 :
14124 526 : case CPTK_HAS_TRIVIAL_COPY:
14125 : /* ??? The standard seems to be missing the "or array of such a class
14126 : type" wording for this trait. */
14127 526 : type1 = strip_array_types (type1);
14128 878 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14129 863 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
14130 :
14131 781 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14132 781 : type1 = strip_array_types (type1);
14133 781 : if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
14134 : {
14135 123 : deferring_access_check_sentinel dacs (dk_no_check);
14136 123 : cp_unevaluated un;
14137 123 : tree fn = get_dtor (type1, tf_none);
14138 123 : if (!fn && !seen_error ())
14139 3 : warning (0, "checking %qs for type %qT with a destructor that "
14140 : "cannot be called", "__has_trivial_destructor", type1);
14141 123 : }
14142 1121 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14143 1118 : || (CLASS_TYPE_P (type1)
14144 293 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
14145 :
14146 61491 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14147 61491 : return type_has_unique_obj_representations (type1);
14148 :
14149 311 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14150 311 : return type_has_virtual_destructor (type1);
14151 :
14152 56754 : case CPTK_IS_ABSTRACT:
14153 56754 : return ABSTRACT_CLASS_TYPE_P (type1);
14154 :
14155 871 : case CPTK_IS_AGGREGATE:
14156 871 : return CP_AGGREGATE_TYPE_P (type1);
14157 :
14158 373119 : case CPTK_IS_ARRAY:
14159 373119 : return (type_code1 == ARRAY_TYPE
14160 : /* We don't want to report T[0] as being an array type.
14161 : This is for compatibility with an implementation of
14162 : std::is_array by template argument deduction, because
14163 : compute_array_index_type_loc rejects a zero-size array
14164 : in SFINAE context. */
14165 373119 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14166 :
14167 1033916 : case CPTK_IS_ASSIGNABLE:
14168 1033916 : return is_xible (MODIFY_EXPR, type1, type2);
14169 :
14170 520744 : case CPTK_IS_BASE_OF:
14171 520653 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14172 1022512 : && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
14173 473258 : || DERIVED_FROM_P (type1, type2)));
14174 :
14175 58460 : case CPTK_IS_BOUNDED_ARRAY:
14176 58460 : return (type_code1 == ARRAY_TYPE
14177 1668 : && TYPE_DOMAIN (type1)
14178 : /* We don't want to report T[0] as being a bounded array type.
14179 : This is for compatibility with an implementation of
14180 : std::is_bounded_array by template argument deduction, because
14181 : compute_array_index_type_loc rejects a zero-size array
14182 : in SFINAE context. */
14183 60000 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14184 :
14185 542270 : case CPTK_IS_CLASS:
14186 542270 : return NON_UNION_CLASS_TYPE_P (type1);
14187 :
14188 595371 : case CPTK_IS_CONST:
14189 595371 : return CP_TYPE_CONST_P (type1);
14190 :
14191 2413113 : case CPTK_IS_CONSTRUCTIBLE:
14192 2413113 : return is_xible (INIT_EXPR, type1, type2);
14193 :
14194 3201421 : case CPTK_IS_CONVERTIBLE:
14195 3201421 : return is_convertible (type1, type2);
14196 :
14197 3327 : case CPTK_IS_DESTRUCTIBLE:
14198 3327 : return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14199 :
14200 219322 : case CPTK_IS_EMPTY:
14201 219322 : return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
14202 :
14203 681617 : case CPTK_IS_ENUM:
14204 681617 : return type_code1 == ENUMERAL_TYPE;
14205 :
14206 435923 : case CPTK_IS_FINAL:
14207 435923 : return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
14208 :
14209 48392 : case CPTK_IS_FUNCTION:
14210 48392 : return type_code1 == FUNCTION_TYPE;
14211 :
14212 1247 : case CPTK_IS_IMPLICIT_LIFETIME:
14213 1247 : return implicit_lifetime_type_p (type1);
14214 :
14215 49331 : case CPTK_IS_INVOCABLE:
14216 49331 : return !error_operand_p (build_invoke (type1, type2, tf_none));
14217 :
14218 221 : case CPTK_IS_LAYOUT_COMPATIBLE:
14219 221 : return layout_compatible_type_p (type1, type2);
14220 :
14221 197 : case CPTK_IS_LITERAL_TYPE:
14222 197 : return literal_type_p (type1);
14223 :
14224 49072 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14225 49072 : return TYPE_PTRMEMFUNC_P (type1);
14226 :
14227 49059 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14228 49059 : return TYPE_PTRDATAMEM_P (type1);
14229 :
14230 11075 : case CPTK_IS_MEMBER_POINTER:
14231 11075 : return TYPE_PTRMEM_P (type1);
14232 :
14233 465830 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14234 465830 : return is_nothrow_xible (MODIFY_EXPR, type1, type2);
14235 :
14236 939221 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14237 939221 : return is_nothrow_xible (INIT_EXPR, type1, type2);
14238 :
14239 683 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14240 683 : return is_nothrow_convertible (type1, type2);
14241 :
14242 24404 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14243 24404 : return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14244 :
14245 44230 : case CPTK_IS_NOTHROW_INVOCABLE:
14246 44230 : return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
14247 :
14248 1140537 : case CPTK_IS_OBJECT:
14249 1140537 : return object_type_p (type1);
14250 :
14251 168 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14252 168 : return pointer_interconvertible_base_of_p (type1, type2);
14253 :
14254 11595 : case CPTK_IS_POD:
14255 11595 : return pod_type_p (type1);
14256 :
14257 153344 : case CPTK_IS_POINTER:
14258 153344 : return TYPE_PTR_P (type1);
14259 :
14260 289 : case CPTK_IS_POLYMORPHIC:
14261 289 : return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
14262 :
14263 724263 : case CPTK_IS_REFERENCE:
14264 724263 : return type_code1 == REFERENCE_TYPE;
14265 :
14266 2706760 : case CPTK_IS_SAME:
14267 2706760 : return same_type_p (type1, type2);
14268 :
14269 373 : case CPTK_IS_SCOPED_ENUM:
14270 373 : return SCOPED_ENUM_P (type1);
14271 :
14272 64575 : case CPTK_IS_STD_LAYOUT:
14273 64575 : return std_layout_type_p (type1);
14274 :
14275 59808 : case CPTK_IS_TRIVIAL:
14276 59808 : return trivial_type_p (type1);
14277 :
14278 12856 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14279 12856 : return is_trivially_xible (MODIFY_EXPR, type1, type2);
14280 :
14281 76687 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14282 76687 : return is_trivially_xible (INIT_EXPR, type1, type2);
14283 :
14284 120650 : case CPTK_IS_TRIVIALLY_COPYABLE:
14285 120650 : return trivially_copyable_p (type1);
14286 :
14287 27510 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14288 27510 : return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14289 :
14290 99943 : case CPTK_IS_UNBOUNDED_ARRAY:
14291 99943 : return array_of_unknown_bound_p (type1);
14292 :
14293 277102 : case CPTK_IS_UNION:
14294 277102 : return type_code1 == UNION_TYPE;
14295 :
14296 751 : case CPTK_IS_VIRTUAL_BASE_OF:
14297 683 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14298 1415 : && lookup_base (type2, type1, ba_require_virtual,
14299 : NULL, tf_none) != NULL_TREE);
14300 :
14301 619777 : case CPTK_IS_VOLATILE:
14302 619777 : return CP_TYPE_VOLATILE_P (type1);
14303 :
14304 222347 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14305 222347 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
14306 :
14307 54560 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14308 54560 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
14309 :
14310 85 : case CPTK_IS_DEDUCIBLE:
14311 85 : return type_targs_deducible_from (type1, type2);
14312 :
14313 264 : case CPTK_IS_STRUCTURAL:
14314 264 : return structural_type_p (type1);
14315 :
14316 : /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
14317 : are handled in finish_trait_expr. */
14318 0 : case CPTK_RANK:
14319 0 : case CPTK_TYPE_ORDER:
14320 0 : case CPTK_STRUCTURED_BINDING_SIZE:
14321 0 : gcc_unreachable ();
14322 :
14323 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14324 : case CPTK_##CODE:
14325 : #include "cp-trait.def"
14326 : #undef DEFTRAIT_TYPE
14327 : /* Type-yielding traits are handled in finish_trait_type. */
14328 : break;
14329 : }
14330 :
14331 0 : gcc_unreachable ();
14332 : }
14333 :
14334 : /* Returns true if TYPE meets the requirements for the specified KIND,
14335 : false otherwise.
14336 :
14337 : When KIND == 1, TYPE must be an array of unknown bound,
14338 : or (possibly cv-qualified) void, or a complete type.
14339 :
14340 : When KIND == 2, TYPE must be a complete type, or array of complete type,
14341 : or (possibly cv-qualified) void.
14342 :
14343 : When KIND == 3:
14344 : If TYPE is a non-union class type, it must be complete.
14345 :
14346 : When KIND == 4:
14347 : If TYPE is a class type, it must be complete.
14348 :
14349 : If COMPLAIN is not tf_none, we permerror and return false if that doesn't
14350 : produce a hard error. */
14351 :
14352 : static bool
14353 19170860 : check_trait_type (tree type, int kind, tsubst_flags_t complain)
14354 : {
14355 19170860 : if (type == NULL_TREE)
14356 : return true;
14357 :
14358 19170860 : if (TREE_CODE (type) == TREE_VEC)
14359 : {
14360 6258834 : for (tree arg : tree_vec_range (type))
14361 2740965 : if (!check_trait_type (arg, kind, complain))
14362 123 : return false;
14363 3517869 : return true;
14364 : }
14365 :
14366 15652868 : if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
14367 : return true; // Array of unknown bound. Don't care about completeness.
14368 :
14369 15652010 : if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
14370 : return true; // Not a non-union class type. Don't care about completeness.
14371 :
14372 15536220 : if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
14373 : return true; // Not a class type. Don't care about completeness.
14374 :
14375 15535689 : if (VOID_TYPE_P (type))
14376 : return true;
14377 :
14378 15534048 : type = complete_type (strip_array_types (type));
14379 15534048 : if (!COMPLETE_TYPE_P (type)
14380 : /* If we're not emitting error messages, always return false for
14381 : incomplete types. */
14382 15534048 : && (complain == tf_none
14383 181 : || (cxx_incomplete_type_diagnostic (NULL_TREE, type,
14384 : diagnostics::kind::permerror)
14385 181 : && !flag_permissive)))
14386 886 : return false;
14387 : return true;
14388 : }
14389 :
14390 : /* True iff the conversion (if any) would be a direct reference
14391 : binding, not requiring complete types. This is LWG2939. */
14392 :
14393 : static bool
14394 6725204 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
14395 : {
14396 6725204 : tree from, to;
14397 6725204 : switch (kind)
14398 : {
14399 : /* These put the target type first. */
14400 : case CPTK_IS_CONSTRUCTIBLE:
14401 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14402 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14403 : case CPTK_IS_INVOCABLE:
14404 : case CPTK_IS_NOTHROW_INVOCABLE:
14405 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14406 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14407 : to = type1;
14408 : from = type2;
14409 : break;
14410 :
14411 : /* These put it second. */
14412 3202176 : case CPTK_IS_CONVERTIBLE:
14413 3202176 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14414 3202176 : to = type2;
14415 3202176 : from = type1;
14416 3202176 : break;
14417 :
14418 0 : default:
14419 0 : gcc_unreachable ();
14420 : }
14421 :
14422 6725204 : if (TREE_CODE (to) != REFERENCE_TYPE || !from)
14423 : return false;
14424 914684 : if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
14425 62978 : from = TREE_VEC_ELT (from, 0);
14426 914684 : return (TYPE_P (from)
14427 1819154 : && (same_type_ignoring_top_level_qualifiers_p
14428 904470 : (non_reference (to), non_reference (from))));
14429 : }
14430 :
14431 : /* Helper for finish_trait_expr and tsubst_expr. Handle
14432 : CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
14433 : way. */
14434 :
14435 : tree
14436 273 : finish_structured_binding_size (location_t loc, tree type,
14437 : tsubst_flags_t complain)
14438 : {
14439 273 : if (TYPE_REF_P (type))
14440 : {
14441 105 : if (complain & tf_error)
14442 99 : error_at (loc, "%qs argument %qT is a reference",
14443 : "__builtin_structured_binding_size", type);
14444 105 : return error_mark_node;
14445 : }
14446 168 : HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
14447 168 : if (ret == -1)
14448 63 : return error_mark_node;
14449 105 : return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
14450 : }
14451 :
14452 : /* Process a trait expression. */
14453 :
14454 : tree
14455 21691886 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2,
14456 : tsubst_flags_t complain/*=tf_warning_or_error*/)
14457 : {
14458 21691886 : if (type1 == error_mark_node
14459 21691883 : || type2 == error_mark_node)
14460 : return error_mark_node;
14461 :
14462 21691883 : if (processing_template_decl)
14463 : {
14464 3432638 : tree trait_expr = make_node (TRAIT_EXPR);
14465 3432638 : if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
14466 32253 : TREE_TYPE (trait_expr) = size_type_node;
14467 3400385 : else if (kind == CPTK_TYPE_ORDER)
14468 : {
14469 4530 : tree val = type_order_value (type1, type1);
14470 4530 : if (val != error_mark_node)
14471 4530 : TREE_TYPE (trait_expr) = TREE_TYPE (val);
14472 : }
14473 : else
14474 3395855 : TREE_TYPE (trait_expr) = boolean_type_node;
14475 3432638 : TRAIT_EXPR_TYPE1 (trait_expr) = type1;
14476 3432638 : TRAIT_EXPR_TYPE2 (trait_expr) = type2;
14477 3432638 : TRAIT_EXPR_KIND (trait_expr) = kind;
14478 3432638 : TRAIT_EXPR_LOCATION (trait_expr) = loc;
14479 3432638 : return trait_expr;
14480 : }
14481 :
14482 18259245 : switch (kind)
14483 : {
14484 57700 : case CPTK_HAS_NOTHROW_ASSIGN:
14485 57700 : case CPTK_HAS_TRIVIAL_ASSIGN:
14486 57700 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
14487 57700 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14488 57700 : case CPTK_HAS_NOTHROW_COPY:
14489 57700 : case CPTK_HAS_TRIVIAL_COPY:
14490 57700 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14491 57700 : case CPTK_IS_DESTRUCTIBLE:
14492 57700 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14493 57700 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14494 57700 : if (!check_trait_type (type1, /*kind=*/1, complain))
14495 57 : return error_mark_node;
14496 : break;
14497 :
14498 318713 : case CPTK_IS_LITERAL_TYPE:
14499 318713 : case CPTK_IS_POD:
14500 318713 : case CPTK_IS_STD_LAYOUT:
14501 318713 : case CPTK_IS_TRIVIAL:
14502 318713 : case CPTK_IS_TRIVIALLY_COPYABLE:
14503 318713 : case CPTK_IS_STRUCTURAL:
14504 318713 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14505 318713 : if (!check_trait_type (type1, /* kind = */ 2, complain))
14506 133 : return error_mark_node;
14507 : break;
14508 :
14509 276715 : case CPTK_IS_ABSTRACT:
14510 276715 : case CPTK_IS_EMPTY:
14511 276715 : case CPTK_IS_POLYMORPHIC:
14512 276715 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14513 276715 : if (!check_trait_type (type1, /* kind = */ 3, complain))
14514 39 : return error_mark_node;
14515 : break;
14516 :
14517 : /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
14518 : type to know whether an array is an aggregate, so use kind=4 here. */
14519 438096 : case CPTK_IS_AGGREGATE:
14520 438096 : case CPTK_IS_FINAL:
14521 438096 : case CPTK_IS_IMPLICIT_LIFETIME:
14522 438096 : if (!check_trait_type (type1, /* kind = */ 4, complain))
14523 55 : return error_mark_node;
14524 : break;
14525 :
14526 6725204 : case CPTK_IS_CONSTRUCTIBLE:
14527 6725204 : case CPTK_IS_CONVERTIBLE:
14528 6725204 : case CPTK_IS_INVOCABLE:
14529 6725204 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14530 6725204 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14531 6725204 : case CPTK_IS_NOTHROW_INVOCABLE:
14532 6725204 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14533 6725204 : /* Don't check completeness for direct reference binding. */;
14534 6725204 : if (same_type_ref_bind_p (kind, type1, type2))
14535 : break;
14536 7669530 : gcc_fallthrough ();
14537 :
14538 7669530 : case CPTK_IS_ASSIGNABLE:
14539 7669530 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14540 7669530 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14541 7669530 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14542 7669530 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14543 7669530 : if (!check_trait_type (type1, /*kind=*/1, complain)
14544 7669530 : || !check_trait_type (type2, /*kind=*/1, complain))
14545 602 : return error_mark_node;
14546 : break;
14547 :
14548 520939 : case CPTK_IS_BASE_OF:
14549 520939 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14550 520834 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14551 501944 : && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
14552 994332 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
14553 : /* We already issued an error. */
14554 27 : return error_mark_node;
14555 : break;
14556 :
14557 778 : case CPTK_IS_VIRTUAL_BASE_OF:
14558 710 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14559 1469 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
14560 : /* We already issued an error. */
14561 27 : return error_mark_node;
14562 : break;
14563 :
14564 : case CPTK_IS_ARRAY:
14565 : case CPTK_IS_BOUNDED_ARRAY:
14566 : case CPTK_IS_CLASS:
14567 : case CPTK_IS_CONST:
14568 : case CPTK_IS_ENUM:
14569 : case CPTK_IS_FUNCTION:
14570 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14571 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14572 : case CPTK_IS_MEMBER_POINTER:
14573 : case CPTK_IS_OBJECT:
14574 : case CPTK_IS_POINTER:
14575 : case CPTK_IS_REFERENCE:
14576 : case CPTK_IS_SAME:
14577 : case CPTK_IS_SCOPED_ENUM:
14578 : case CPTK_IS_UNBOUNDED_ARRAY:
14579 : case CPTK_IS_UNION:
14580 : case CPTK_IS_VOLATILE:
14581 : break;
14582 :
14583 : case CPTK_RANK:
14584 : {
14585 : size_t rank = 0;
14586 122 : for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
14587 80 : ++rank;
14588 42 : return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
14589 : loc);
14590 : }
14591 :
14592 460 : case CPTK_TYPE_ORDER:
14593 460 : return maybe_wrap_with_location (type_order_value (type1, type2), loc);
14594 :
14595 144 : case CPTK_STRUCTURED_BINDING_SIZE:
14596 144 : return finish_structured_binding_size (loc, type1, complain);
14597 :
14598 242 : case CPTK_IS_LAYOUT_COMPATIBLE:
14599 242 : if (!array_of_unknown_bound_p (type1)
14600 223 : && TREE_CODE (type1) != VOID_TYPE
14601 456 : && !complete_type_or_maybe_complain (type1, NULL_TREE, complain))
14602 : /* We already issued an error. */
14603 12 : return error_mark_node;
14604 230 : if (!array_of_unknown_bound_p (type2)
14605 203 : && TREE_CODE (type2) != VOID_TYPE
14606 424 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
14607 : /* We already issued an error. */
14608 9 : return error_mark_node;
14609 : break;
14610 :
14611 85 : case CPTK_IS_DEDUCIBLE:
14612 85 : if (!DECL_TYPE_TEMPLATE_P (type1))
14613 : {
14614 0 : error ("%qD is not a class or alias template", type1);
14615 0 : return error_mark_node;
14616 : }
14617 : break;
14618 :
14619 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14620 : case CPTK_##CODE:
14621 : #include "cp-trait.def"
14622 : #undef DEFTRAIT_TYPE
14623 : /* Type-yielding traits are handled in finish_trait_type. */
14624 0 : gcc_unreachable ();
14625 : }
14626 :
14627 18257638 : tree val = (trait_expr_value (kind, type1, type2)
14628 18257638 : ? boolean_true_node : boolean_false_node);
14629 18257638 : return maybe_wrap_with_location (val, loc);
14630 : }
14631 :
14632 : /* Process a trait type. */
14633 :
14634 : tree
14635 8050056 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
14636 : tsubst_flags_t complain)
14637 : {
14638 8050993 : if (type1 == error_mark_node
14639 8050990 : || type2 == error_mark_node)
14640 : return error_mark_node;
14641 :
14642 8050990 : if (processing_template_decl)
14643 : {
14644 236739 : tree type = cxx_make_type (TRAIT_TYPE);
14645 236739 : TRAIT_TYPE_TYPE1 (type) = type1;
14646 236739 : TRAIT_TYPE_TYPE2 (type) = type2;
14647 236739 : TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
14648 : /* These traits are intended to be used in the definition of the ::type
14649 : member of the corresponding standard library type trait and aren't
14650 : mangleable (and thus won't appear directly in template signatures),
14651 : so structural equality should suffice. */
14652 236739 : SET_TYPE_STRUCTURAL_EQUALITY (type);
14653 236739 : return type;
14654 : }
14655 :
14656 7814251 : switch (kind)
14657 : {
14658 1254356 : case CPTK_ADD_LVALUE_REFERENCE:
14659 : /* [meta.trans.ref]. */
14660 1254356 : if (referenceable_type_p (type1))
14661 1254269 : return cp_build_reference_type (type1, /*rval=*/false);
14662 : return type1;
14663 :
14664 648800 : case CPTK_ADD_POINTER:
14665 : /* [meta.trans.ptr]. */
14666 648800 : if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
14667 : {
14668 648768 : if (TYPE_REF_P (type1))
14669 647574 : type1 = TREE_TYPE (type1);
14670 648768 : return build_pointer_type (type1);
14671 : }
14672 : return type1;
14673 :
14674 1690999 : case CPTK_ADD_RVALUE_REFERENCE:
14675 : /* [meta.trans.ref]. */
14676 1690999 : if (referenceable_type_p (type1))
14677 1690941 : return cp_build_reference_type (type1, /*rval=*/true);
14678 : return type1;
14679 :
14680 240008 : case CPTK_DECAY:
14681 240008 : if (TYPE_REF_P (type1))
14682 43498 : type1 = TREE_TYPE (type1);
14683 :
14684 240008 : if (TREE_CODE (type1) == ARRAY_TYPE)
14685 728 : return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
14686 728 : complain);
14687 239280 : else if (TREE_CODE (type1) == FUNCTION_TYPE)
14688 : return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
14689 : else
14690 239071 : return cv_unqualified (type1);
14691 :
14692 223 : case CPTK_REMOVE_ALL_EXTENTS:
14693 223 : return strip_array_types (type1);
14694 :
14695 1007231 : case CPTK_REMOVE_CV:
14696 1007231 : return cv_unqualified (type1);
14697 :
14698 478877 : case CPTK_REMOVE_CVREF:
14699 478877 : if (TYPE_REF_P (type1))
14700 182626 : type1 = TREE_TYPE (type1);
14701 478877 : return cv_unqualified (type1);
14702 :
14703 66876 : case CPTK_REMOVE_EXTENT:
14704 66876 : if (TREE_CODE (type1) == ARRAY_TYPE)
14705 9506 : type1 = TREE_TYPE (type1);
14706 : return type1;
14707 :
14708 45062 : case CPTK_REMOVE_POINTER:
14709 45062 : if (TYPE_PTR_P (type1))
14710 42174 : type1 = TREE_TYPE (type1);
14711 : return type1;
14712 :
14713 2219900 : case CPTK_REMOVE_REFERENCE:
14714 2219900 : if (TYPE_REF_P (type1))
14715 1348201 : type1 = TREE_TYPE (type1);
14716 : return type1;
14717 :
14718 113135 : case CPTK_TYPE_PACK_ELEMENT:
14719 113135 : return finish_type_pack_element (type1, type2, complain);
14720 :
14721 48784 : case CPTK_UNDERLYING_TYPE:
14722 48784 : return finish_underlying_type (type1);
14723 :
14724 : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
14725 : case CPTK_##CODE:
14726 : #include "cp-trait.def"
14727 : #undef DEFTRAIT_EXPR
14728 : /* Expression-yielding traits are handled in finish_trait_expr. */
14729 : case CPTK_BASES:
14730 : case CPTK_DIRECT_BASES:
14731 : /* BASES and DIRECT_BASES are handled in finish_bases. */
14732 : break;
14733 : }
14734 :
14735 0 : gcc_unreachable ();
14736 : }
14737 :
14738 : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
14739 : which is ignored for C++. */
14740 :
14741 : void
14742 0 : set_float_const_decimal64 (void)
14743 : {
14744 0 : }
14745 :
14746 : void
14747 0 : clear_float_const_decimal64 (void)
14748 : {
14749 0 : }
14750 :
14751 : bool
14752 1889877 : float_const_decimal64_p (void)
14753 : {
14754 1889877 : return 0;
14755 : }
14756 :
14757 :
14758 : /* Return true if T designates the implied `this' parameter. */
14759 :
14760 : bool
14761 6684461 : is_this_parameter (tree t)
14762 : {
14763 6684461 : if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
14764 : return false;
14765 3915411 : gcc_assert (TREE_CODE (t) == PARM_DECL
14766 : || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
14767 : || (cp_binding_oracle && VAR_P (t)));
14768 : return true;
14769 : }
14770 :
14771 : /* As above, or a C++23 explicit object parameter. */
14772 :
14773 : bool
14774 456 : is_object_parameter (tree t)
14775 : {
14776 456 : if (is_this_parameter (t))
14777 : return true;
14778 91 : if (TREE_CODE (t) != PARM_DECL)
14779 : return false;
14780 34 : tree ctx = DECL_CONTEXT (t);
14781 34 : return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
14782 62 : && t == DECL_ARGUMENTS (ctx));
14783 : }
14784 :
14785 : /* Insert the deduced return type for an auto function. */
14786 :
14787 : void
14788 1081665 : apply_deduced_return_type (tree fco, tree return_type)
14789 : {
14790 1081665 : tree result;
14791 :
14792 1081665 : if (return_type == error_mark_node)
14793 : return;
14794 :
14795 1081662 : if (DECL_CONV_FN_P (fco))
14796 42 : DECL_NAME (fco) = make_conv_op_name (return_type);
14797 :
14798 1081662 : TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
14799 :
14800 1081662 : maybe_update_postconditions (fco);
14801 :
14802 : /* Apply the type to the result object. */
14803 :
14804 1081662 : result = DECL_RESULT (fco);
14805 1081662 : if (result == NULL_TREE)
14806 : return;
14807 1069174 : if (TREE_TYPE (result) == return_type)
14808 : return;
14809 :
14810 1069171 : if (!processing_template_decl && !VOID_TYPE_P (return_type)
14811 1979552 : && !complete_type_or_else (return_type, NULL_TREE))
14812 : return;
14813 :
14814 : /* We already have a DECL_RESULT from start_preparsed_function.
14815 : Now we need to redo the work it and allocate_struct_function
14816 : did to reflect the new type. */
14817 1069171 : result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
14818 1069171 : TYPE_MAIN_VARIANT (return_type));
14819 1069171 : DECL_ARTIFICIAL (result) = 1;
14820 1069171 : DECL_IGNORED_P (result) = 1;
14821 1069171 : cp_apply_type_quals_to_decl (cp_type_quals (return_type),
14822 : result);
14823 1069171 : DECL_RESULT (fco) = result;
14824 :
14825 1069171 : if (!uses_template_parms (fco))
14826 1069171 : if (function *fun = DECL_STRUCT_FUNCTION (fco))
14827 : {
14828 1068182 : bool aggr = aggregate_value_p (result, fco);
14829 : #ifdef PCC_STATIC_STRUCT_RETURN
14830 : fun->returns_pcc_struct = aggr;
14831 : #endif
14832 1068182 : fun->returns_struct = aggr;
14833 : }
14834 : }
14835 :
14836 : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
14837 : this is a right unary fold. Otherwise it is a left unary fold. */
14838 :
14839 : static tree
14840 851519 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
14841 : {
14842 : /* Build a pack expansion (assuming expr has pack type). */
14843 851519 : if (!uses_parameter_packs (expr))
14844 : {
14845 3 : error_at (location_of (expr), "operand of fold expression has no "
14846 : "unexpanded parameter packs");
14847 3 : return error_mark_node;
14848 : }
14849 851516 : tree pack = make_pack_expansion (expr);
14850 :
14851 : /* Build the fold expression. */
14852 851516 : tree code = build_int_cstu (integer_type_node, abs (op));
14853 851516 : tree fold = build_min_nt_loc (loc, dir, code, pack);
14854 851516 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14855 851516 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14856 851516 : FOLD_EXPR_OP (fold),
14857 851516 : FOLD_EXPR_MODIFY_P (fold));
14858 851516 : return fold;
14859 : }
14860 :
14861 : tree
14862 25974 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
14863 : {
14864 25974 : return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
14865 : }
14866 :
14867 : tree
14868 825545 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
14869 : {
14870 825545 : return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
14871 : }
14872 :
14873 : /* Build a binary fold expression over EXPR1 and EXPR2. The
14874 : associativity of the fold is determined by EXPR1 and EXPR2 (whichever
14875 : has an unexpanded parameter pack). */
14876 :
14877 : static tree
14878 197562 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
14879 : int op, tree_code dir)
14880 : {
14881 197562 : pack = make_pack_expansion (pack);
14882 197562 : tree code = build_int_cstu (integer_type_node, abs (op));
14883 197562 : tree fold = build_min_nt_loc (loc, dir, code, pack, init);
14884 197562 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14885 197562 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14886 197562 : FOLD_EXPR_OP (fold),
14887 197562 : FOLD_EXPR_MODIFY_P (fold));
14888 197562 : return fold;
14889 : }
14890 :
14891 : tree
14892 197562 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
14893 : {
14894 : // Determine which expr has an unexpanded parameter pack and
14895 : // set the pack and initial term.
14896 197562 : bool pack1 = uses_parameter_packs (expr1);
14897 197562 : bool pack2 = uses_parameter_packs (expr2);
14898 197562 : if (pack1 && !pack2)
14899 1087 : return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
14900 196475 : else if (pack2 && !pack1)
14901 196475 : return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
14902 : else
14903 : {
14904 0 : if (pack1)
14905 0 : error ("both arguments in binary fold have unexpanded parameter packs");
14906 : else
14907 0 : error ("no unexpanded parameter packs in binary fold");
14908 : }
14909 0 : return error_mark_node;
14910 : }
14911 :
14912 : /* Finish __builtin_launder (arg). */
14913 :
14914 : tree
14915 14293 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
14916 : {
14917 14293 : tree orig_arg = arg;
14918 14293 : if (!type_dependent_expression_p (arg))
14919 84 : arg = decay_conversion (arg, complain);
14920 14293 : if (error_operand_p (arg))
14921 0 : return error_mark_node;
14922 14293 : if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
14923 : {
14924 24 : error_at (loc, "type %qT of argument to %<__builtin_launder%> "
14925 24 : "is not a pointer to object type", TREE_TYPE (arg));
14926 24 : return error_mark_node;
14927 : }
14928 14269 : if (processing_template_decl)
14929 14209 : arg = orig_arg;
14930 14269 : return build_call_expr_internal_loc (loc, IFN_LAUNDER,
14931 28538 : TREE_TYPE (arg), 1, arg);
14932 : }
14933 :
14934 : /* Finish __builtin_convertvector (arg, type). */
14935 :
14936 : tree
14937 486 : cp_build_vec_convert (tree arg, location_t loc, tree type,
14938 : tsubst_flags_t complain)
14939 : {
14940 486 : if (error_operand_p (type))
14941 9 : return error_mark_node;
14942 477 : if (error_operand_p (arg))
14943 0 : return error_mark_node;
14944 :
14945 477 : tree ret = NULL_TREE;
14946 477 : if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
14947 439 : ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
14948 : decay_conversion (arg, complain),
14949 : loc, type, (complain & tf_error) != 0);
14950 :
14951 477 : if (!processing_template_decl)
14952 : return ret;
14953 :
14954 80 : return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
14955 : }
14956 :
14957 : /* Finish __builtin_bit_cast (type, arg). */
14958 :
14959 : tree
14960 295842 : cp_build_bit_cast (location_t loc, tree type, tree arg,
14961 : tsubst_flags_t complain)
14962 : {
14963 295842 : if (error_operand_p (type))
14964 0 : return error_mark_node;
14965 295842 : if (!dependent_type_p (type))
14966 : {
14967 214427 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
14968 9 : return error_mark_node;
14969 214418 : if (TREE_CODE (type) == ARRAY_TYPE)
14970 : {
14971 : /* std::bit_cast for destination ARRAY_TYPE is not possible,
14972 : as functions may not return an array, so don't bother trying
14973 : to support this (and then deal with VLAs etc.). */
14974 9 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14975 : "is an array type", type);
14976 9 : return error_mark_node;
14977 : }
14978 214409 : if (!trivially_copyable_p (type))
14979 : {
14980 18 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14981 : "is not trivially copyable", type);
14982 18 : return error_mark_node;
14983 : }
14984 214391 : if (consteval_only_p (type) || consteval_only_p (arg))
14985 : {
14986 8 : error_at (loc, "%<__builtin_bit_cast%> cannot be used with "
14987 : "consteval-only types");
14988 8 : return error_mark_node;
14989 : }
14990 : }
14991 :
14992 295798 : if (error_operand_p (arg))
14993 0 : return error_mark_node;
14994 :
14995 295798 : if (!type_dependent_expression_p (arg))
14996 : {
14997 115280 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
14998 : {
14999 : /* Don't perform array-to-pointer conversion. */
15000 375 : arg = mark_rvalue_use (arg, loc, true);
15001 375 : if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
15002 0 : return error_mark_node;
15003 : }
15004 : else
15005 114905 : arg = decay_conversion (arg, complain);
15006 :
15007 115280 : if (error_operand_p (arg))
15008 12 : return error_mark_node;
15009 :
15010 115268 : if (!trivially_copyable_p (TREE_TYPE (arg)))
15011 : {
15012 9 : error_at (cp_expr_loc_or_loc (arg, loc),
15013 : "%<__builtin_bit_cast%> source type %qT "
15014 9 : "is not trivially copyable", TREE_TYPE (arg));
15015 9 : return error_mark_node;
15016 : }
15017 115259 : if (!dependent_type_p (type)
15018 192162 : && !cp_tree_equal (TYPE_SIZE_UNIT (type),
15019 76903 : TYPE_SIZE_UNIT (TREE_TYPE (arg))))
15020 : {
15021 18 : error_at (loc, "%<__builtin_bit_cast%> source size %qE "
15022 : "not equal to destination type size %qE",
15023 18 : TYPE_SIZE_UNIT (TREE_TYPE (arg)),
15024 18 : TYPE_SIZE_UNIT (type));
15025 18 : return error_mark_node;
15026 : }
15027 : }
15028 :
15029 295759 : tree ret = build_min (BIT_CAST_EXPR, type, arg);
15030 295759 : SET_EXPR_LOCATION (ret, loc);
15031 :
15032 295759 : if (!processing_template_decl && CLASS_TYPE_P (type))
15033 872 : ret = get_target_expr (ret, complain);
15034 :
15035 : return ret;
15036 : }
15037 :
15038 : /* Diagnose invalid #pragma GCC unroll argument and adjust
15039 : it if needed. */
15040 :
15041 : tree
15042 24633 : cp_check_pragma_unroll (location_t loc, tree unroll)
15043 : {
15044 24633 : HOST_WIDE_INT lunroll = 0;
15045 24633 : if (type_dependent_expression_p (unroll))
15046 : ;
15047 49194 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
15048 49148 : || (!value_dependent_expression_p (unroll)
15049 24521 : && (!tree_fits_shwi_p (unroll)
15050 24495 : || (lunroll = tree_to_shwi (unroll)) < 0
15051 24480 : || lunroll >= USHRT_MAX)))
15052 : {
15053 90 : error_at (loc, "%<#pragma GCC unroll%> requires an"
15054 : " assignment-expression that evaluates to a non-negative"
15055 : " integral constant less than %u", USHRT_MAX);
15056 90 : unroll = integer_one_node;
15057 : }
15058 24507 : else if (TREE_CODE (unroll) == INTEGER_CST)
15059 : {
15060 24477 : unroll = fold_convert (integer_type_node, unroll);
15061 24477 : if (integer_zerop (unroll))
15062 12 : unroll = integer_one_node;
15063 : }
15064 24633 : return unroll;
15065 : }
15066 :
15067 : #include "gt-cp-semantics.h"
|