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 24477665580 : push_deferring_access_checks (deferring_kind deferring)
146 : {
147 : /* For context like template instantiation, access checking
148 : disabling applies to all nested context. */
149 24477665580 : if (deferred_access_no_check || deferring == dk_no_check)
150 315015858 : deferred_access_no_check++;
151 : else
152 : {
153 24162649722 : deferred_access e = {NULL, deferring};
154 24162649722 : vec_safe_push (deferred_access_stack, e);
155 : }
156 24477665580 : }
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 393137807 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
163 : {
164 393137807 : push_deferring_access_checks (dk_deferred);
165 393137807 : if (!deferred_access_no_check)
166 385269088 : deferred_access_stack->last().deferred_access_checks = checks;
167 393137807 : }
168 :
169 : /* Resume deferring access checks again after we stopped doing
170 : this previously. */
171 :
172 : void
173 186790288 : resume_deferring_access_checks (void)
174 : {
175 186790288 : if (!deferred_access_no_check)
176 186769952 : deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
177 186790288 : }
178 :
179 : /* Stop deferring access checks. */
180 :
181 : void
182 523731957 : stop_deferring_access_checks (void)
183 : {
184 523731957 : if (!deferred_access_no_check)
185 523671826 : deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
186 523731957 : }
187 :
188 : /* Discard the current deferred access checks and restore the
189 : previous states. */
190 :
191 : void
192 15173959038 : pop_deferring_access_checks (void)
193 : {
194 15173959038 : if (deferred_access_no_check)
195 241271172 : deferred_access_no_check--;
196 : else
197 14932687866 : deferred_access_stack->pop ();
198 15173959038 : }
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 1310437679 : get_deferred_access_checks (void)
207 : {
208 1310437679 : if (deferred_access_no_check)
209 : return NULL;
210 : else
211 1294242478 : 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 9303568500 : pop_to_parent_deferring_access_checks (void)
220 : {
221 9303568500 : if (deferred_access_no_check)
222 73744680 : deferred_access_no_check--;
223 : else
224 : {
225 9229823820 : vec<deferred_access_check, va_gc> *checks;
226 9229823820 : deferred_access *ptr;
227 :
228 9229823820 : checks = (deferred_access_stack->last ().deferred_access_checks);
229 :
230 9229823820 : deferred_access_stack->pop ();
231 9229823820 : ptr = &deferred_access_stack->last ();
232 9229823820 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
233 : {
234 : /* Check access. */
235 581994332 : 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 8854970170 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
244 : {
245 112567957 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
246 : {
247 9988271 : if (probe->binfo == chk->binfo &&
248 7897441 : probe->decl == chk->decl &&
249 991595 : probe->diag_decl == chk->diag_decl)
250 990655 : goto found;
251 : }
252 : /* Insert into parent's checks. */
253 102579686 : vec_safe_push (ptr->deferred_access_checks, *chk);
254 103570341 : found:;
255 : }
256 : }
257 : }
258 9303568500 : }
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 426804712 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
334 : tsubst_flags_t complain, access_failure_info *afi = NULL)
335 : {
336 426804712 : gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
337 :
338 426804712 : if (flag_new_inheriting_ctors
339 539300107 : && 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 63277 : decl = strip_inheriting_ctors (decl);
345 63277 : basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
346 : ba_any, NULL, complain);
347 : }
348 :
349 426804712 : tree cs = current_scope ();
350 426804712 : if (in_template_context
351 426804712 : && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
352 42512570 : 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 42264612 : 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 384540100 : if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
382 : {
383 22469 : if (flag_new_inheriting_ctors)
384 22439 : diag_decl = strip_inheriting_ctors (diag_decl);
385 22469 : 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 22469 : 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 1115899639 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
431 : tsubst_flags_t complain)
432 : {
433 1115899639 : int i;
434 1115899639 : deferred_access_check *chk;
435 1115899639 : location_t loc = input_location;
436 1115899639 : bool ok = true;
437 :
438 1115899639 : if (!checks)
439 : return true;
440 :
441 129929507 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
442 : {
443 72320032 : input_location = chk->loc;
444 72320032 : ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
445 : }
446 :
447 57609475 : input_location = loc;
448 57609475 : 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 291761828 : perform_deferred_access_checks (tsubst_flags_t complain)
469 : {
470 291761828 : 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 640587913 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
480 : tsubst_flags_t complain,
481 : access_failure_info *afi)
482 : {
483 640587913 : int i;
484 640587913 : deferred_access *ptr;
485 640587913 : deferred_access_check *chk;
486 :
487 : /* Exit if we are in a context that no access checking is performed. */
488 640587913 : if (deferred_access_no_check)
489 : return true;
490 :
491 609733703 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
492 :
493 609733703 : ptr = &deferred_access_stack->last ();
494 :
495 : /* If we are not supposed to defer access checks, just check now. */
496 609733703 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
497 : {
498 354484680 : bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
499 354484680 : return (complain & tf_error) ? true : ok;
500 : }
501 :
502 : /* See if we are already going to perform this check. */
503 310627912 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
504 : {
505 72701390 : if (chk->decl == decl && chk->binfo == binfo &&
506 17323580 : chk->diag_decl == diag_decl)
507 : {
508 : return true;
509 : }
510 : }
511 : /* If not, record the check. */
512 237926522 : deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
513 237926522 : vec_safe_push (ptr->deferred_access_checks, new_access);
514 :
515 237926522 : 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 1533831042 : stmts_are_full_exprs_p (void)
524 : {
525 1533831042 : 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 1323439381 : add_stmt (tree t)
534 : {
535 1323439381 : enum tree_code code = TREE_CODE (t);
536 :
537 1323439381 : if (EXPR_P (t) && code != LABEL_EXPR)
538 : {
539 1272383805 : if (!EXPR_HAS_LOCATION (t))
540 203354858 : 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 1272383805 : if (STATEMENT_CODE_P (TREE_CODE (t)))
545 331194117 : STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
546 : }
547 :
548 1323439381 : if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
549 5916114 : 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 1323439381 : gcc_checking_assert (!stmt_list_stack->is_empty ());
554 1323439381 : append_to_statement_list_force (t, &cur_stmt_list);
555 :
556 1323439381 : return t;
557 : }
558 :
559 : /* Returns the stmt_tree to which statements are currently being added. */
560 :
561 : stmt_tree
562 7841134188 : current_stmt_tree (void)
563 : {
564 7841134188 : return (cfun
565 7801917558 : ? &cfun->language->base.x_stmt_tree
566 7841134188 : : &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 330664 : maybe_cleanup_point_expr (tree expr)
573 : {
574 330664 : if (!processing_template_decl && stmts_are_full_exprs_p ())
575 317277 : expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
576 330664 : 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 328154626 : maybe_cleanup_point_expr_void (tree expr)
586 : {
587 328154626 : if (!processing_template_decl && stmts_are_full_exprs_p ())
588 110238979 : expr = fold_build_cleanup_point_expr (void_type_node, expr);
589 328154626 : return expr;
590 : }
591 :
592 :
593 :
594 : /* Create a declaration statement for the declaration given by the DECL. */
595 :
596 : void
597 110982042 : add_decl_expr (tree decl)
598 : {
599 110982042 : tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
600 110982042 : if (DECL_INITIAL (decl)
601 110982042 : || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
602 19761407 : r = maybe_cleanup_point_expr_void (r);
603 110982042 : add_stmt (r);
604 110982042 : }
605 :
606 : /* Set EXPR_LOCATION on one cleanup T to LOC. */
607 :
608 : static void
609 5921867 : set_one_cleanup_loc (tree t, location_t loc)
610 : {
611 5921867 : if (!t)
612 : return;
613 :
614 5921867 : if (TREE_CODE (t) != POSTCONDITION_STMT)
615 5921867 : 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 5921867 : if (TREE_CODE (t) == NOP_EXPR
622 0 : && TREE_TYPE (t) == void_type_node
623 5921867 : && 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 1249116028 : set_cleanup_locs (tree stmts, location_t loc)
631 : {
632 1255037895 : if (TREE_CODE (stmts) == CLEANUP_STMT)
633 : {
634 5921867 : set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
635 5921867 : set_cleanup_locs (CLEANUP_BODY (stmts), loc);
636 : }
637 1249116028 : else if (TREE_CODE (stmts) == STATEMENT_LIST)
638 1110563638 : for (tree stmt : tsi_range (stmts))
639 860004159 : set_cleanup_locs (stmt, loc);
640 1249116028 : }
641 :
642 : /* True iff the innermost block scope is a try block. */
643 :
644 : static bool
645 389111869 : at_try_scope ()
646 : {
647 389111869 : cp_binding_level *b = current_binding_level;
648 389112325 : while (b && b->kind == sk_cleanup)
649 456 : b = b->level_chain;
650 389111869 : return b && b->kind == sk_try;
651 : }
652 :
653 : /* Finish a scope. */
654 :
655 : tree
656 389111869 : do_poplevel (tree stmt_list)
657 : {
658 389111869 : tree block = NULL;
659 :
660 389111869 : bool was_try = at_try_scope ();
661 :
662 389111869 : if (stmts_are_full_exprs_p ())
663 389049008 : block = poplevel (kept_level_p (), 1, 0);
664 :
665 : /* This needs to come after poplevel merges sk_cleanup statement_lists. */
666 389111869 : maybe_splice_retval_cleanup (stmt_list, was_try);
667 :
668 389111869 : stmt_list = pop_stmt_list (stmt_list);
669 :
670 : /* input_location is the last token of the scope, usually a }. */
671 389111869 : set_cleanup_locs (stmt_list, input_location);
672 :
673 389111869 : if (!processing_template_decl)
674 : {
675 119733204 : stmt_list = c_build_bind_expr (input_location, block, stmt_list);
676 : /* ??? See c_end_compound_stmt re statement expressions. */
677 : }
678 :
679 389111869 : return stmt_list;
680 : }
681 :
682 : /* Begin a new scope. */
683 :
684 : tree
685 389073996 : do_pushlevel (scope_kind sk)
686 : {
687 389073996 : tree ret = push_stmt_list ();
688 389073996 : if (stmts_are_full_exprs_p ())
689 389049062 : begin_scope (sk, NULL);
690 389073996 : 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 5921805 : push_cleanup (tree decl, tree cleanup, bool eh_only)
700 : {
701 5921805 : tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
702 5921805 : CLEANUP_EH_ONLY (stmt) = eh_only;
703 5921805 : add_stmt (stmt);
704 5921805 : CLEANUP_BODY (stmt) = push_stmt_list ();
705 5921805 : }
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 18628684 : begin_maybe_infinite_loop (tree cond)
716 : {
717 : /* Only track this while parsing a function, not during instantiation. */
718 18628684 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
719 2731418 : && !processing_template_decl))
720 : return;
721 15896768 : bool maybe_infinite = true;
722 15896768 : if (cond)
723 : {
724 15584043 : cond = fold_non_dependent_expr (cond);
725 15584043 : maybe_infinite = integer_nonzerop (cond);
726 : }
727 31480811 : vec_safe_push (cp_function_chain->infinite_loops,
728 15896768 : 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 1563107 : break_maybe_infinite_loop (void)
736 : {
737 1563107 : if (!cfun)
738 : return;
739 1563107 : 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 18628684 : end_maybe_infinite_loop (tree cond)
747 : {
748 18628684 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
749 2731418 : && !processing_template_decl))
750 : return;
751 15896768 : tree current = cp_function_chain->infinite_loops->pop();
752 15896768 : if (current != NULL_TREE)
753 : {
754 5136649 : cond = fold_non_dependent_expr (cond);
755 5136649 : if (integer_nonzerop (cond))
756 336259 : 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 89889259 : begin_cond (tree *cond_p)
767 : {
768 89889259 : if (processing_template_decl)
769 63704064 : *cond_p = push_stmt_list ();
770 89889259 : }
771 :
772 : /* Finish such a conditional. */
773 :
774 : static void
775 89889259 : finish_cond (tree *cond_p, tree expr)
776 : {
777 89889259 : if (processing_template_decl)
778 : {
779 63704064 : tree cond = pop_stmt_list (*cond_p);
780 :
781 63704064 : if (expr == NULL_TREE)
782 : /* Empty condition in 'for'. */
783 291905 : gcc_assert (empty_expr_stmt_p (cond));
784 63412159 : else if (check_for_bare_parameter_packs (expr))
785 0 : expr = error_mark_node;
786 63412159 : else if (!empty_expr_stmt_p (cond))
787 941448 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
788 : }
789 89889259 : *cond_p = expr;
790 89889259 : }
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 12565963 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
809 : {
810 12565963 : if (!TREE_SIDE_EFFECTS (*body_p))
811 12556184 : return;
812 :
813 9779 : gcc_assert (!processing_template_decl);
814 9779 : *prep_p = *body_p;
815 9779 : 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 9779 : current_binding_level->keep = true;
840 9779 : 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 9779 : if (tsi_end_p (iter))
847 : *body_p = NULL_TREE;
848 : else
849 9688 : *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 9779 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
862 : {
863 9779 : *prep_p = do_poplevel (*prep_p);
864 9779 : gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
865 9779 : 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 9761 : tree stmt_list = BIND_EXPR_BODY (*prep_p);
872 9761 : gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
873 9761 : 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 9670 : tree_stmt_iterator iter = tsi_start (stmt_list);
893 9902 : while (tsi_stmt (iter) != *body_p)
894 232 : tsi_next (&iter);
895 9670 : *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 880576 : is_assignment_op_expr_p (tree t)
937 : {
938 880576 : if (t == NULL_TREE)
939 : return false;
940 :
941 880576 : if (TREE_CODE (t) == MODIFY_EXPR
942 880576 : || (TREE_CODE (t) == MODOP_EXPR
943 336 : && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
944 : return true;
945 :
946 879889 : tree call = extract_call_expr (t);
947 879889 : if (call == NULL_TREE
948 129861 : || call == error_mark_node
949 1009750 : || !CALL_EXPR_OPERATOR_SYNTAX (call))
950 : return false;
951 :
952 4678 : tree fndecl = cp_get_callee_fndecl_nofold (call);
953 4678 : return fndecl != NULL_TREE
954 4580 : && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
955 4729 : && 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 92832701 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
1019 : tsubst_flags_t complain)
1020 : {
1021 92832701 : tree type = TREE_TYPE (t);
1022 92832701 : t = STRIP_REFERENCE_REF (t);
1023 :
1024 92832701 : if ((complain & tf_warning)
1025 92770940 : && warn_parentheses
1026 880576 : && 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 92833048 : && (!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 92832701 : }
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 54740479 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
1072 : {
1073 54740479 : tree *t = cond;
1074 54750887 : while (TREE_CODE (*t) == ANNOTATE_EXPR)
1075 10408 : t = &TREE_OPERAND (*t, 0);
1076 :
1077 54740479 : if (t != cond)
1078 : {
1079 10405 : m_annotations = *cond;
1080 10405 : *cond = *t;
1081 10405 : m_inner = t;
1082 : }
1083 54740479 : }
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 54740479 : annotate_saver::restore (tree new_inner)
1092 : {
1093 54740479 : 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 10405 : 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 10405 : *m_inner = new_inner;
1118 10405 : 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 94945620 : maybe_convert_cond (tree cond)
1127 : {
1128 : /* Empty conditions remain empty. */
1129 94945620 : if (!cond)
1130 : return NULL_TREE;
1131 :
1132 : /* Wait until we instantiate templates before doing conversion. */
1133 94572741 : if (type_dependent_expression_p (cond))
1134 39832262 : return cond;
1135 :
1136 : /* Strip any ANNOTATE_EXPRs from COND. */
1137 54740479 : 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 NON_LVALUE_EXPR, pick it up from there. */
1143 385694 : if (DECL_DECOMPOSITION_P (cond)
1144 228 : && DECL_DECOMP_IS_BASE (cond)
1145 228 : && DECL_DECOMP_BASE (cond)
1146 54740704 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == NON_LVALUE_EXPR)
1147 59 : cond = TREE_OPERAND (DECL_DECOMP_BASE (cond), 0);
1148 :
1149 54740479 : if (warn_sequence_point && !processing_template_decl)
1150 328155 : verify_sequence_points (cond);
1151 :
1152 54740479 : maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
1153 : tf_warning_or_error);
1154 :
1155 : /* Do the conversion. */
1156 54740479 : cond = convert_from_reference (cond);
1157 54740479 : cond = condition_conversion (cond);
1158 :
1159 : /* Restore any ANNOTATE_EXPRs around COND. */
1160 54740479 : return annotations.restore (cond);
1161 : }
1162 :
1163 : /* Finish an expression-statement, whose EXPRESSION is as indicated. */
1164 :
1165 : tree
1166 168634631 : finish_expr_stmt (tree expr)
1167 : {
1168 168634631 : tree r = NULL_TREE;
1169 168634631 : location_t loc = EXPR_LOCATION (expr);
1170 :
1171 168438262 : if (expr != NULL_TREE)
1172 : {
1173 : /* If we ran into a problem, make sure we complained. */
1174 168634470 : gcc_assert (expr != error_mark_node || seen_error ());
1175 :
1176 168634470 : if (!processing_template_decl)
1177 : {
1178 61510243 : if (warn_sequence_point)
1179 819382 : verify_sequence_points (expr);
1180 61510243 : expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1181 : }
1182 107124227 : else if (!type_dependent_expression_p (expr))
1183 23318966 : convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1184 :
1185 168634467 : 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 168634467 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
1192 : {
1193 168634288 : if (TREE_CODE (expr) != EXPR_STMT
1194 166103541 : && !STATEMENT_CLASS_P (expr)
1195 166099390 : && TREE_CODE (expr) != STATEMENT_LIST)
1196 165943355 : expr = build_stmt (loc, EXPR_STMT, expr);
1197 168634288 : expr = maybe_cleanup_point_expr_void (expr);
1198 : }
1199 :
1200 168634467 : r = add_stmt (expr);
1201 : }
1202 :
1203 168634628 : return r;
1204 : }
1205 :
1206 :
1207 : /* Begin an if-statement. Returns a newly created IF_STMT if
1208 : appropriate. */
1209 :
1210 : tree
1211 76593129 : begin_if_stmt (void)
1212 : {
1213 76593129 : tree r, scope;
1214 76593129 : scope = do_pushlevel (sk_cond);
1215 76593129 : r = build_stmt (input_location, IF_STMT, NULL_TREE,
1216 : NULL_TREE, NULL_TREE, scope);
1217 76593129 : current_binding_level->this_entity = r;
1218 76593129 : begin_cond (&IF_COND (r));
1219 76593129 : 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 253783 : is_std_constant_evaluated_p (tree fn)
1227 : {
1228 : /* std::is_constant_evaluated takes no arguments. */
1229 253783 : if (call_expr_nargs (fn) != 0)
1230 : return false;
1231 :
1232 90427 : tree fndecl = cp_get_callee_fndecl_nofold (fn);
1233 90427 : if (fndecl == NULL_TREE)
1234 : return false;
1235 :
1236 28360 : if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
1237 : BUILT_IN_FRONTEND))
1238 : return true;
1239 :
1240 28331 : if (!decl_in_std_namespace_p (fndecl))
1241 : return false;
1242 :
1243 12992 : tree name = DECL_NAME (fndecl);
1244 12992 : 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 4705062 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
1252 : {
1253 4705062 : tree t = *tp;
1254 :
1255 4705062 : if (TYPE_P (t) || TREE_CONSTANT (t))
1256 : {
1257 834049 : *walk_subtrees = false;
1258 834049 : return NULL_TREE;
1259 : }
1260 :
1261 3871013 : switch (TREE_CODE (t))
1262 : {
1263 253783 : case CALL_EXPR:
1264 253783 : if (is_std_constant_evaluated_p (t))
1265 2396 : 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 76678928 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
1284 : bool trivial_infinite)
1285 : {
1286 76678928 : if (!warn_tautological_compare)
1287 : return;
1288 :
1289 : /* Suppress warning for std::is_constant_evaluated if the conditional
1290 : comes from a macro. */
1291 1435504 : if (from_macro_expansion_at (EXPR_LOCATION (cond)))
1292 : return;
1293 :
1294 606157 : cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
1295 : NULL);
1296 606157 : if (cond)
1297 : {
1298 2396 : 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 2362 : 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 2354 : 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 4632 : 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 76593129 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
1330 : {
1331 76593129 : tree cond = maybe_convert_cond (orig_cond);
1332 76593129 : maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
1333 : /*trivial_infinite=*/false);
1334 76593129 : if (IF_STMT_CONSTEXPR_P (if_stmt)
1335 16112600 : && !type_dependent_expression_p (cond)
1336 10997912 : && require_constant_expression (cond)
1337 10997881 : && !instantiation_dependent_expression_p (cond)
1338 : /* Wait until instantiation time, since only then COND has been
1339 : converted to bool. */
1340 82584860 : && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
1341 : {
1342 5991731 : cond = instantiate_non_dependent_expr (cond);
1343 5991731 : cond = cxx_constant_value (cond);
1344 : }
1345 70601398 : else if (processing_template_decl)
1346 52895465 : cond = orig_cond;
1347 76593129 : finish_cond (&IF_COND (if_stmt), cond);
1348 76593129 : add_stmt (if_stmt);
1349 76593129 : THEN_CLAUSE (if_stmt) = push_stmt_list ();
1350 76593129 : 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 76585321 : finish_then_clause (tree if_stmt)
1358 : {
1359 76585321 : THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
1360 76585321 : return if_stmt;
1361 : }
1362 :
1363 : /* Begin the else-clause of an if-statement. */
1364 :
1365 : void
1366 28601177 : begin_else_clause (tree if_stmt)
1367 : {
1368 28601177 : ELSE_CLAUSE (if_stmt) = push_stmt_list ();
1369 28601177 : }
1370 :
1371 : /* Finish the else-clause of an if-statement, which may be given by
1372 : IF_STMT. */
1373 :
1374 : void
1375 28601139 : finish_else_clause (tree if_stmt)
1376 : {
1377 28601139 : ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
1378 28601139 : }
1379 :
1380 : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1381 : read. */
1382 :
1383 : static tree
1384 878294964 : maybe_mark_exp_read_r (tree *tp, int *, void *)
1385 : {
1386 878294964 : tree t = *tp;
1387 878294964 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1388 51271789 : mark_exp_read (t);
1389 878294964 : return NULL_TREE;
1390 : }
1391 :
1392 : /* Finish an if-statement. */
1393 :
1394 : void
1395 76585321 : finish_if_stmt (tree if_stmt)
1396 : {
1397 76585321 : tree scope = IF_SCOPE (if_stmt);
1398 76585321 : IF_SCOPE (if_stmt) = NULL;
1399 76585321 : 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 16104792 : cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
1405 : maybe_mark_exp_read_r, NULL);
1406 16104792 : cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
1407 : maybe_mark_exp_read_r, NULL);
1408 : }
1409 76585321 : add_stmt (do_poplevel (scope));
1410 76585321 : }
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 17976321 : finish_loop_cond (tree *condp, tree body)
1421 : {
1422 17976321 : if (TREE_CODE (*condp) == INTEGER_CST)
1423 : return;
1424 12911367 : bool trivially_empty = expr_first (body) == NULL_TREE;
1425 12911367 : bool trivial_infinite = false;
1426 12911367 : if (trivially_empty)
1427 : {
1428 99973 : tree c = fold_non_dependent_expr (*condp, tf_none,
1429 : /*manifestly_const_eval=*/true);
1430 99973 : trivial_infinite = c && integer_nonzerop (c);
1431 : }
1432 12911367 : if (warn_tautological_compare)
1433 : {
1434 86001 : tree cond = *condp;
1435 86368 : while (TREE_CODE (cond) == ANNOTATE_EXPR)
1436 367 : cond = TREE_OPERAND (cond, 0);
1437 86001 : if (trivial_infinite
1438 86065 : && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1439 64 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1440 : /*trivial_infinite=*/true);
1441 85937 : else if (!trivially_empty
1442 375 : || !processing_template_decl
1443 86341 : || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1444 85735 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1445 : /*trivial_infinite=*/false);
1446 : }
1447 12911367 : 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 4920409 : begin_while_stmt (void)
1459 : {
1460 4920409 : tree r;
1461 4920409 : r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1462 : NULL_TREE, NULL_TREE);
1463 4920409 : add_stmt (r);
1464 4920409 : WHILE_BODY (r) = do_pushlevel (sk_block);
1465 4920409 : begin_cond (&WHILE_COND (r));
1466 4920409 : return r;
1467 : }
1468 :
1469 : /* Process the COND of a while-statement, which may be given by
1470 : WHILE_STMT. */
1471 :
1472 : void
1473 4920409 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
1474 : tree unroll, bool novector)
1475 : {
1476 4920409 : cond = maybe_convert_cond (cond);
1477 4920409 : finish_cond (&WHILE_COND (while_stmt), cond);
1478 4920409 : begin_maybe_infinite_loop (cond);
1479 4920409 : 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 4920409 : if (unroll && cond != error_mark_node)
1487 27990 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1488 13995 : TREE_TYPE (WHILE_COND (while_stmt)),
1489 13995 : WHILE_COND (while_stmt),
1490 : build_int_cst (integer_type_node,
1491 : annot_expr_unroll_kind),
1492 : unroll);
1493 4920409 : 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 4920409 : adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
1501 : &WHILE_COND_PREP (while_stmt),
1502 : &WHILE_COND_CLEANUP (while_stmt));
1503 4920409 : }
1504 :
1505 : /* Finish a while-statement, which may be given by WHILE_STMT. */
1506 :
1507 : void
1508 4920409 : finish_while_stmt (tree while_stmt)
1509 : {
1510 4920409 : end_maybe_infinite_loop (boolean_true_node);
1511 4920409 : if (WHILE_COND_PREP (while_stmt))
1512 9605 : finish_loop_cond_prep (&WHILE_BODY (while_stmt),
1513 : &WHILE_COND_PREP (while_stmt),
1514 9605 : WHILE_COND_CLEANUP (while_stmt));
1515 : else
1516 4910804 : WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
1517 4920409 : finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
1518 4920409 : }
1519 :
1520 : /* Begin a do-statement. Returns a newly created DO_STMT if
1521 : appropriate. */
1522 :
1523 : tree
1524 5783237 : begin_do_stmt (void)
1525 : {
1526 5783237 : tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
1527 : NULL_TREE);
1528 5783237 : begin_maybe_infinite_loop (boolean_true_node);
1529 5783237 : add_stmt (r);
1530 5783237 : DO_BODY (r) = push_stmt_list ();
1531 5783237 : return r;
1532 : }
1533 :
1534 : /* Finish the body of a do-statement, which may be given by DO_STMT. */
1535 :
1536 : void
1537 5783237 : finish_do_body (tree do_stmt)
1538 : {
1539 5783237 : tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
1540 :
1541 5783237 : if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
1542 545367 : body = STATEMENT_LIST_TAIL (body)->stmt;
1543 :
1544 5783237 : if (IS_EMPTY_STMT (body))
1545 30 : warning (OPT_Wempty_body,
1546 : "suggest explicit braces around empty body in %<do%> statement");
1547 5783237 : }
1548 :
1549 : /* Finish a do-statement, which may be given by DO_STMT, and whose
1550 : COND is as indicated. */
1551 :
1552 : void
1553 5783237 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
1554 : bool novector)
1555 : {
1556 5783237 : cond = maybe_convert_cond (cond);
1557 5783237 : 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 5783237 : if (check_for_bare_parameter_packs (cond))
1562 3 : cond = error_mark_node;
1563 5783237 : 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 5783237 : 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 5783237 : 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 5783237 : DO_COND (do_stmt) = cond;
1576 5783237 : tree do_body = DO_BODY (do_stmt);
1577 5783207 : if (CONVERT_EXPR_P (do_body)
1578 30 : && integer_zerop (TREE_OPERAND (do_body, 0))
1579 5783267 : && VOID_TYPE_P (TREE_TYPE (do_body)))
1580 : do_body = NULL_TREE;
1581 5783237 : finish_loop_cond (&DO_COND (do_stmt), do_body);
1582 5783237 : }
1583 :
1584 : /* Finish a return-statement. The EXPRESSION returned, if any, is as
1585 : indicated. */
1586 :
1587 : tree
1588 132519035 : finish_return_stmt (tree expr)
1589 : {
1590 132519035 : tree r;
1591 132519035 : bool no_warning;
1592 132519035 : bool dangling;
1593 :
1594 132519035 : expr = check_return_expr (expr, &no_warning, &dangling);
1595 :
1596 132519035 : if (error_operand_p (expr)
1597 132519035 : || (flag_openmp && !check_omp_return ()))
1598 : {
1599 : /* Suppress -Wreturn-type for this function. */
1600 1351 : if (warn_return_type)
1601 1345 : suppress_warning (current_function_decl, OPT_Wreturn_type);
1602 1351 : return error_mark_node;
1603 : }
1604 :
1605 132517684 : if (!processing_template_decl)
1606 : {
1607 46495945 : if (warn_sequence_point)
1608 1039438 : verify_sequence_points (expr);
1609 : }
1610 :
1611 132517684 : r = build_stmt (input_location, RETURN_EXPR, expr);
1612 132517684 : RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
1613 132517684 : if (no_warning)
1614 33 : suppress_warning (r, OPT_Wreturn_type);
1615 132517684 : r = maybe_cleanup_point_expr_void (r);
1616 132517684 : r = add_stmt (r);
1617 :
1618 132517684 : 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 7925038 : begin_for_scope (tree *init)
1627 : {
1628 7925038 : tree scope = do_pushlevel (sk_for);
1629 :
1630 7925038 : if (processing_template_decl)
1631 6294018 : *init = push_stmt_list ();
1632 : else
1633 1631020 : *init = NULL_TREE;
1634 :
1635 7925038 : 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 7645554 : begin_for_stmt (tree scope, tree init)
1644 : {
1645 7645554 : tree r;
1646 :
1647 7645554 : 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 7645554 : if (scope == NULL_TREE)
1652 : {
1653 1381109 : gcc_assert (!init);
1654 1381109 : scope = begin_for_scope (&init);
1655 : }
1656 :
1657 7645554 : FOR_INIT_STMT (r) = init;
1658 7645554 : FOR_SCOPE (r) = scope;
1659 :
1660 7645554 : 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 7645554 : finish_init_stmt (tree for_stmt)
1668 : {
1669 7645554 : if (processing_template_decl)
1670 6014534 : FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
1671 7645554 : add_stmt (for_stmt);
1672 7645554 : FOR_BODY (for_stmt) = do_pushlevel (sk_block);
1673 7645554 : begin_cond (&FOR_COND (for_stmt));
1674 7645554 : }
1675 :
1676 : /* Finish the COND of a for-statement, which may be given by
1677 : FOR_STMT. */
1678 :
1679 : void
1680 7645554 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
1681 : bool novector)
1682 : {
1683 7645554 : cond = maybe_convert_cond (cond);
1684 7645554 : finish_cond (&FOR_COND (for_stmt), cond);
1685 7645554 : begin_maybe_infinite_loop (cond);
1686 7645554 : 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 7645554 : 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 7645554 : 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 7645554 : adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
1708 : &FOR_COND_CLEANUP (for_stmt));
1709 7645554 : }
1710 :
1711 : /* Finish the increment-EXPRESSION in a for-statement, which may be
1712 : given by FOR_STMT. */
1713 :
1714 : void
1715 7633141 : finish_for_expr (tree expr, tree for_stmt)
1716 : {
1717 7633141 : 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 7169692 : if (type_unknown_p (expr))
1722 : {
1723 6 : cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1724 6 : expr = error_mark_node;
1725 : }
1726 7169692 : if (!processing_template_decl)
1727 : {
1728 1556524 : if (warn_sequence_point)
1729 15015 : verify_sequence_points (expr);
1730 1556524 : expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1731 : tf_warning_or_error);
1732 : }
1733 5613168 : else if (!type_dependent_expression_p (expr))
1734 2017019 : convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
1735 7169692 : expr = maybe_cleanup_point_expr_void (expr);
1736 7169692 : if (check_for_bare_parameter_packs (expr))
1737 0 : expr = error_mark_node;
1738 7169692 : 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 7925151 : find_range_for_decls (tree range_for_decl[3])
1749 : {
1750 7925151 : 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 31700604 : for (int i = 0; i < 3; i++)
1756 : {
1757 23775453 : tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1758 23775453 : if (IDENTIFIER_BINDING (id)
1759 23775453 : && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1760 : {
1761 277357 : range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1762 277357 : gcc_assert (VAR_P (range_for_decl[i])
1763 : && DECL_ARTIFICIAL (range_for_decl[i]));
1764 : }
1765 : }
1766 7925151 : }
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 7925038 : finish_for_stmt (tree for_stmt)
1775 : {
1776 7925038 : end_maybe_infinite_loop (boolean_true_node);
1777 :
1778 7925038 : if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1779 279484 : RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1780 : else
1781 : {
1782 7645554 : 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 7645380 : FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1788 7645554 : if (FOR_COND (for_stmt))
1789 7272675 : finish_loop_cond (&FOR_COND (for_stmt),
1790 7272675 : FOR_EXPR (for_stmt) ? integer_one_node
1791 144013 : : FOR_BODY (for_stmt));
1792 : }
1793 :
1794 : /* Pop the scope for the body of the loop. */
1795 7925038 : tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1796 7925038 : ? &RANGE_FOR_SCOPE (for_stmt)
1797 7645554 : : &FOR_SCOPE (for_stmt));
1798 7925038 : tree scope = *scope_ptr;
1799 7925038 : *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 7925038 : tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1806 7925038 : find_range_for_decls (range_for_decl);
1807 :
1808 7925038 : 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 7925038 : if (!stmts_are_full_exprs_p ())
1813 12413 : return;
1814 :
1815 31650500 : for (int i = 0; i < 3; i++)
1816 23737875 : if (range_for_decl[i])
1817 277241 : DECL_NAME (range_for_decl[i])
1818 277241 : = 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 279484 : begin_range_for_stmt (tree scope, tree init)
1828 : {
1829 279484 : begin_maybe_infinite_loop (boolean_false_node);
1830 :
1831 279484 : tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1832 : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1833 :
1834 279484 : 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 279484 : RANGE_FOR_INIT_STMT (r) = init;
1842 279484 : RANGE_FOR_SCOPE (r) = scope;
1843 :
1844 279484 : 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 279484 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1853 : {
1854 279484 : if (processing_template_decl)
1855 558968 : RANGE_FOR_INIT_STMT (range_for_stmt)
1856 558968 : = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1857 279484 : RANGE_FOR_DECL (range_for_stmt) = decl;
1858 279484 : RANGE_FOR_EXPR (range_for_stmt) = expr;
1859 279484 : add_stmt (range_for_stmt);
1860 279484 : RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1861 279484 : }
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 4933316 : 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 4933316 : if (!block_may_fallthru (cur_stmt_list))
1891 714 : return void_node;
1892 4932602 : note_break_stmt ();
1893 4932602 : return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
1894 : }
1895 :
1896 : /* Finish a continue-statement. */
1897 :
1898 : tree
1899 253640 : finish_continue_stmt (void)
1900 : {
1901 253640 : 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 730167 : begin_switch_stmt (void)
1909 : {
1910 730167 : tree r, scope;
1911 :
1912 730167 : scope = do_pushlevel (sk_cond);
1913 730167 : r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1914 : scope, NULL_TREE);
1915 :
1916 730167 : begin_cond (&SWITCH_STMT_COND (r));
1917 :
1918 730167 : return r;
1919 : }
1920 :
1921 : /* Finish the cond of a switch-statement. */
1922 :
1923 : void
1924 730167 : finish_switch_cond (tree cond, tree switch_stmt)
1925 : {
1926 730167 : tree orig_type = NULL;
1927 :
1928 730167 : if (!processing_template_decl)
1929 : {
1930 : /* Convert the condition to an integer or enumeration type. */
1931 301907 : 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 NON_LVALUE_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 301961 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == NON_LVALUE_EXPR)
1940 18 : cond = TREE_OPERAND (DECL_DECOMP_BASE (cond), 0);
1941 301907 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1942 301907 : 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 301907 : orig_type = unlowered_expr_type (cond);
1950 301907 : if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1951 207775 : orig_type = TREE_TYPE (cond);
1952 301907 : if (cond != error_mark_node)
1953 : {
1954 : /* [stmt.switch]
1955 :
1956 : Integral promotions are performed. */
1957 301874 : cond = perform_integral_promotions (cond);
1958 301874 : cond = maybe_cleanup_point_expr (cond);
1959 : }
1960 : }
1961 730167 : if (check_for_bare_parameter_packs (cond))
1962 0 : cond = error_mark_node;
1963 730167 : else if (!processing_template_decl && warn_sequence_point)
1964 2853 : verify_sequence_points (cond);
1965 :
1966 730167 : finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1967 730167 : SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1968 730167 : add_stmt (switch_stmt);
1969 730167 : push_switch (switch_stmt);
1970 730167 : SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1971 730167 : }
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 730167 : finish_switch_stmt (tree switch_stmt)
1978 : {
1979 730167 : tree scope;
1980 :
1981 1460334 : SWITCH_STMT_BODY (switch_stmt) =
1982 730167 : pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1983 730167 : pop_switch ();
1984 :
1985 730167 : scope = SWITCH_STMT_SCOPE (switch_stmt);
1986 730167 : SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1987 730167 : add_stmt (do_poplevel (scope));
1988 730167 : }
1989 :
1990 : /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1991 : appropriate. */
1992 :
1993 : tree
1994 1193671 : begin_try_block (void)
1995 : {
1996 1193671 : tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1997 1193671 : add_stmt (r);
1998 1193671 : TRY_STMTS (r) = push_stmt_list ();
1999 1193671 : 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 2220 : begin_function_try_block (tree *compound_stmt)
2008 : {
2009 2220 : 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 2220 : *compound_stmt = begin_compound_stmt (0);
2013 2220 : current_binding_level->artificial = 1;
2014 2220 : r = begin_try_block ();
2015 2220 : FN_TRY_BLOCK_P (r) = 1;
2016 2220 : return r;
2017 : }
2018 :
2019 : /* Finish a try-block, which may be given by TRY_BLOCK. */
2020 :
2021 : void
2022 1193671 : finish_try_block (tree try_block)
2023 : {
2024 1193671 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2025 1193671 : TRY_HANDLERS (try_block) = push_stmt_list ();
2026 1193671 : }
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 2220 : finish_function_try_block (tree try_block)
2051 : {
2052 2220 : finish_try_block (try_block);
2053 : /* FIXME : something queer about CTOR_INITIALIZER somehow following
2054 : the try block, but moving it inside. */
2055 2220 : in_function_try_handler = 1;
2056 2220 : }
2057 :
2058 : /* Finish a handler-sequence for a try-block, which may be given by
2059 : TRY_BLOCK. */
2060 :
2061 : void
2062 1193671 : finish_handler_sequence (tree try_block)
2063 : {
2064 1193671 : TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
2065 1193671 : check_handlers (TRY_HANDLERS (try_block));
2066 1193671 : }
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 2220 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
2074 : {
2075 2220 : in_function_try_handler = 0;
2076 2220 : finish_handler_sequence (try_block);
2077 2220 : finish_compound_stmt (compound_stmt);
2078 2220 : }
2079 :
2080 : /* Begin a handler. Returns a HANDLER if appropriate. */
2081 :
2082 : tree
2083 1663444 : begin_handler (void)
2084 : {
2085 1663444 : tree r;
2086 :
2087 1663444 : r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
2088 1663444 : add_stmt (r);
2089 :
2090 : /* Create a binding level for the eh_info and the exception object
2091 : cleanup. */
2092 1663444 : HANDLER_BODY (r) = do_pushlevel (sk_catch);
2093 :
2094 1663444 : 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 1663444 : finish_handler_parms (tree decl, tree handler)
2103 : {
2104 1663444 : tree type = NULL_TREE;
2105 1663444 : if (processing_template_decl)
2106 : {
2107 1517427 : if (decl)
2108 : {
2109 493414 : decl = pushdecl (decl);
2110 493414 : decl = push_template_decl (decl);
2111 493414 : HANDLER_PARMS (handler) = decl;
2112 493414 : type = TREE_TYPE (decl);
2113 : }
2114 : }
2115 : else
2116 : {
2117 146017 : type = expand_start_catch_block (decl);
2118 146017 : if (warn_catch_value
2119 2116 : && type != NULL_TREE
2120 711 : && type != error_mark_node
2121 146728 : && !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 1663444 : HANDLER_TYPE (handler) = type;
2143 1663444 : }
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 1663444 : finish_handler (tree handler)
2150 : {
2151 1663444 : if (!processing_template_decl)
2152 146017 : expand_end_catch_block ();
2153 1663444 : HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
2154 1663444 : }
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 294895209 : begin_compound_stmt (unsigned int flags)
2165 : {
2166 294895209 : tree r;
2167 :
2168 294895209 : if (flags & BCS_NO_SCOPE)
2169 : {
2170 5649884 : r = push_stmt_list ();
2171 5649884 : 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 5649884 : keep_next_level (false);
2178 : }
2179 : else
2180 : {
2181 289245325 : scope_kind sk = sk_block;
2182 289245325 : if (flags & BCS_TRY_BLOCK)
2183 : sk = sk_try;
2184 288051847 : else if (flags & BCS_TRANSACTION)
2185 : sk = sk_transaction;
2186 288051612 : else if (flags & BCS_STMT_EXPR)
2187 29088 : sk = sk_stmt_expr;
2188 289245325 : 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 294895209 : if (processing_template_decl)
2198 : {
2199 197577566 : r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
2200 197577566 : BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
2201 197577566 : BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
2202 197577566 : TREE_SIDE_EFFECTS (r) = 1;
2203 : }
2204 :
2205 294895209 : return r;
2206 : }
2207 :
2208 : /* Finish a compound-statement, which is given by STMT. */
2209 :
2210 : void
2211 294895170 : finish_compound_stmt (tree stmt)
2212 : {
2213 294895170 : if (TREE_CODE (stmt) == BIND_EXPR)
2214 : {
2215 197577566 : 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 197577566 : if (TREE_CODE (body) == STATEMENT_LIST
2220 179692124 : && STATEMENT_LIST_HEAD (body) == NULL
2221 11996417 : && !BIND_EXPR_BODY_BLOCK (stmt)
2222 209049874 : && !BIND_EXPR_TRY_BLOCK (stmt))
2223 : stmt = body;
2224 : else
2225 186105355 : BIND_EXPR_BODY (stmt) = body;
2226 : }
2227 97317604 : else if (STATEMENT_LIST_NO_SCOPE (stmt))
2228 5611957 : stmt = pop_stmt_list (stmt);
2229 : else
2230 : {
2231 : /* Destroy any ObjC "super" receivers that may have been
2232 : created. */
2233 91705647 : objc_clear_super_receiver ();
2234 :
2235 91705647 : stmt = do_poplevel (stmt);
2236 : }
2237 :
2238 : /* ??? See c_end_compound_stmt wrt statement expressions. */
2239 294895170 : add_stmt (stmt);
2240 294895170 : }
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 55333 : finish_asm_string_expression (location_t loc, tree string)
2248 : {
2249 55333 : if (string == error_mark_node
2250 55320 : || 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 32566 : 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 32566 : tree r;
2277 32566 : tree t;
2278 32566 : int ninputs = list_length (input_operands);
2279 32566 : int noutputs = list_length (output_operands);
2280 :
2281 32566 : if (!processing_template_decl)
2282 : {
2283 12804 : const char *constraint;
2284 12804 : const char **oconstraints;
2285 12804 : bool allows_mem, allows_reg, is_inout;
2286 12804 : tree operand;
2287 12804 : int i;
2288 :
2289 12804 : oconstraints = XALLOCAVEC (const char *, noutputs);
2290 :
2291 25506 : string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
2292 : string);
2293 12804 : if (string == error_mark_node)
2294 109 : return error_mark_node;
2295 38130 : for (int i = 0; i < 2; ++i)
2296 61917 : for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
2297 : {
2298 36512 : tree s = TREE_VALUE (TREE_PURPOSE (t));
2299 73006 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2300 36512 : if (s == error_mark_node)
2301 : return error_mark_node;
2302 36482 : TREE_VALUE (TREE_PURPOSE (t)) = s;
2303 : }
2304 18112 : 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 12695 : string = resolve_asm_operand_names (string, output_operands,
2312 : input_operands, labels);
2313 :
2314 44491 : for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
2315 : {
2316 19101 : 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 19101 : STRIP_NOPS (operand);
2325 :
2326 19101 : operand = mark_lvalue_use (operand);
2327 :
2328 19101 : if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
2329 9 : operand = error_mark_node;
2330 :
2331 19101 : if (operand != error_mark_node
2332 19101 : && (TREE_READONLY (operand)
2333 19086 : || CP_TYPE_CONST_P (TREE_TYPE (operand))
2334 : /* Functions are not modifiable, even though they are
2335 : lvalues. */
2336 19086 : || 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 19086 : || (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 19101 : tree *op = &operand;
2344 19108 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2345 7 : op = &TREE_OPERAND (*op, 1);
2346 19101 : 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 19101 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2359 19101 : oconstraints[i] = constraint;
2360 :
2361 19101 : 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 19092 : if (!allows_reg && !cxx_mark_addressable (*op))
2368 0 : operand = error_mark_node;
2369 19092 : 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 712 : 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 19080 : 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 19101 : TREE_VALUE (t) = operand;
2415 : }
2416 :
2417 30071 : for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
2418 : {
2419 17376 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2420 17376 : bool constraint_parsed
2421 17376 : = 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 17376 : if (constraint_parsed && !allows_reg && allows_mem)
2427 580 : operand = mark_lvalue_use (TREE_VALUE (t));
2428 : else
2429 16796 : 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 17376 : 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 17376 : if (constraint_parsed)
2444 : {
2445 : /* If the operand is going to end up in memory,
2446 : mark it addressable. */
2447 17355 : 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 580 : STRIP_NOPS (operand);
2452 :
2453 580 : tree *op = &operand;
2454 587 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2455 7 : op = &TREE_OPERAND (*op, 1);
2456 580 : 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 580 : if (!cxx_mark_addressable (*op))
2469 0 : operand = error_mark_node;
2470 : }
2471 16775 : 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 17355 : 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 17355 : 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 17376 : 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 17259 : 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 17376 : TREE_VALUE (t) = operand;
2551 : }
2552 : }
2553 :
2554 32457 : r = build_stmt (loc, ASM_EXPR, string,
2555 : output_operands, input_operands,
2556 : clobbers, labels);
2557 32457 : ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
2558 32457 : ASM_INLINE_P (r) = inline_p;
2559 32457 : if (toplev_p)
2560 : {
2561 99 : symtab->finalize_toplevel_asm (r);
2562 99 : return r;
2563 : }
2564 32358 : r = maybe_cleanup_point_expr_void (r);
2565 32358 : 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 3626614 : finish_decl_cleanup (tree decl, tree cleanup)
2603 : {
2604 3626614 : push_cleanup (decl, cleanup, false);
2605 3626614 : }
2606 :
2607 : /* If the current scope exits with an exception, run CLEANUP. */
2608 :
2609 : void
2610 2285380 : finish_eh_cleanup (tree cleanup)
2611 : {
2612 2285380 : push_cleanup (NULL, cleanup, true);
2613 2285380 : }
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 21018398 : 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 21018398 : mem_inits = nreverse (mem_inits);
2625 :
2626 21018398 : if (processing_template_decl)
2627 : {
2628 : tree mem;
2629 :
2630 35520942 : 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 21012696 : if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
2638 21012696 : && check_for_bare_parameter_packs (TREE_VALUE (mem)))
2639 3 : TREE_VALUE (mem) = error_mark_node;
2640 : }
2641 :
2642 14508246 : add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
2643 : CTOR_INITIALIZER, mem_inits));
2644 : }
2645 : else
2646 6510152 : emit_mem_initializers (mem_inits);
2647 21018398 : }
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 46474767 : force_paren_expr (tree expr, bool even_uneval /* = false */)
2655 : {
2656 : /* This is only needed for decltype(auto) in C++14. */
2657 46474767 : 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 45828164 : if (cp_unevaluated_operand && !even_uneval)
2663 : return expr;
2664 :
2665 38081732 : if (TREE_CODE (expr) == COMPONENT_REF
2666 38023417 : || TREE_CODE (expr) == SCOPE_REF
2667 76098380 : || REFERENCE_REF_P (expr))
2668 622375 : REF_PARENTHESIZED_P (expr) = true;
2669 37459357 : else if (DECL_P (tree_strip_any_location_wrapper (expr)))
2670 : {
2671 1794290 : location_t loc = cp_expr_location (expr);
2672 1794290 : const tree_code code = processing_template_decl ? PAREN_EXPR
2673 : : VIEW_CONVERT_EXPR;
2674 1794290 : expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
2675 1794290 : 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 1025493844 : maybe_undo_parenthesized_ref (tree t)
2686 : {
2687 1025493844 : if (cxx_dialect < cxx14)
2688 : return t;
2689 :
2690 1015294145 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
2691 1125672730 : && REF_PARENTHESIZED_P (t))
2692 205721 : t = TREE_OPERAND (t, 0);
2693 :
2694 : return t;
2695 : }
2696 :
2697 : /* Finish a parenthesized expression EXPR. */
2698 :
2699 : cp_expr
2700 34568868 : finish_parenthesized_expr (cp_expr expr)
2701 : {
2702 34568868 : if (EXPR_P (expr))
2703 : {
2704 : /* This inhibits warnings in maybe_warn_unparenthesized_assignment
2705 : and c_common_truthvalue_conversion. */
2706 68724708 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
2707 : /* And maybe_warn_sizeof_array_div. */
2708 68724708 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
2709 : }
2710 :
2711 34568868 : if (TREE_CODE (expr) == OFFSET_REF
2712 34568868 : || 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 31727 : PTRMEM_OK_P (expr) = 0;
2716 :
2717 34568868 : tree stripped_expr = tree_strip_any_location_wrapper (expr);
2718 34568868 : if (TREE_CODE (stripped_expr) == STRING_CST)
2719 889011 : PAREN_STRING_LITERAL_P (stripped_expr) = 1;
2720 33679857 : else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
2721 1470 : PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
2722 :
2723 34568868 : expr = cp_expr (force_paren_expr (expr), expr.get_location ());
2724 :
2725 34568868 : 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 79547909 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
2733 : tsubst_flags_t complain /* = tf_warning_or_error */)
2734 : {
2735 79547909 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
2736 79547909 : bool try_omp_private = !object && omp_private_member_map;
2737 69090333 : tree ret;
2738 :
2739 69090333 : if (!object)
2740 : {
2741 69090333 : tree scope = qualifying_scope;
2742 69090333 : if (scope == NULL_TREE)
2743 : {
2744 69078722 : scope = context_for_name_lookup (decl);
2745 69078722 : 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 69090330 : object = maybe_dummy_object (scope, NULL);
2753 : }
2754 :
2755 79547906 : object = maybe_resolve_dummy (object, true);
2756 79547906 : 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 79547903 : if (is_dummy_object (object)
2762 36171 : && !cp_unevaluated_operand
2763 79548009 : && (!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 79547812 : if (current_class_ptr)
2788 79216251 : TREE_USED (current_class_ptr) = 1;
2789 79547812 : if (processing_template_decl)
2790 : {
2791 63233700 : tree type = TREE_TYPE (decl);
2792 :
2793 63233700 : if (TYPE_REF_P (type))
2794 : /* Quals on the object don't matter. */;
2795 60860995 : else if (PACK_EXPANSION_P (type))
2796 : /* Don't bother trying to represent this. */
2797 : type = NULL_TREE;
2798 60857979 : 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 60853446 : int quals = cp_type_quals (TREE_TYPE (object));
2812 :
2813 60853446 : if (DECL_MUTABLE_P (decl))
2814 244249 : quals &= ~TYPE_QUAL_CONST;
2815 :
2816 60853446 : quals |= cp_type_quals (TREE_TYPE (decl));
2817 60853446 : type = cp_build_qualified_type (type, quals);
2818 : }
2819 :
2820 63233700 : if (qualifying_scope)
2821 : /* Wrap this in a SCOPE_REF for now. */
2822 9537 : ret = build_qualified_name (type, qualifying_scope, decl,
2823 : /*template_p=*/false);
2824 : else
2825 63224163 : ret = (convert_from_reference
2826 63224163 : (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 16314112 : tree access_type = TREE_TYPE (object);
2833 :
2834 16314112 : 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 16314112 : if (qualifying_scope)
2841 : {
2842 2027 : tree binfo = NULL_TREE;
2843 2027 : object = build_scoped_ref (object, qualifying_scope,
2844 : &binfo);
2845 : }
2846 :
2847 16314112 : ret = build_class_member_access_expr (object, decl,
2848 : /*access_path=*/NULL_TREE,
2849 : /*preserve_reference=*/false,
2850 : complain);
2851 : }
2852 79547812 : 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 4994224150 : 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 4994224150 : if (deferred_access_no_check)
2876 : return true;
2877 :
2878 : /* Determine the SCOPE of DECL. */
2879 4982962665 : tree scope = context_for_name_lookup (decl);
2880 : /* If the SCOPE is not a type, then DECL is not a member. */
2881 4982962665 : 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 4982962665 : || dependent_type_p (scope))
2886 : return true;
2887 :
2888 477409417 : tree qualifying_type = NULL_TREE;
2889 : /* Compute the scope through which DECL is being accessed. */
2890 477409417 : 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 101832 : && CLASS_TYPE_P (object_type)
2900 477511232 : && 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 101806 : if (tree open = currently_open_class (object_type))
2905 : qualifying_type = open;
2906 : else
2907 : qualifying_type = object_type;
2908 : }
2909 477307611 : 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 634986691 : if (DECL_NONSTATIC_MEMBER_P (decl)
2915 317545562 : && current_class_ptr)
2916 41447 : if (tree current = current_nonlambda_class_type ())
2917 : {
2918 41402 : 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 159814264 : qualifying_type = currently_open_derived_class (scope);
2938 :
2939 477308314 : 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 477371610 : && CLASS_TYPE_P (qualifying_type))
2943 449859354 : return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2944 449859354 : 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 85582051 : 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 85582051 : gcc_assert (TYPE_P (qualifying_class));
2967 :
2968 85582051 : if (error_operand_p (expr))
2969 21 : return error_mark_node;
2970 :
2971 85582030 : if (DECL_P (expr)
2972 : /* Functions are marked after overload resolution; avoid redundant
2973 : warnings. */
2974 78284244 : && TREE_CODE (expr) != FUNCTION_DECL
2975 163866250 : && !mark_used (expr, complain))
2976 0 : return error_mark_node;
2977 :
2978 85582030 : if (template_p)
2979 : {
2980 263616 : 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 263607 : 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 85582030 : if (address_p && done
2994 163837 : && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
2995 : {
2996 163835 : if (TREE_CODE (expr) == SCOPE_REF)
2997 0 : expr = TREE_OPERAND (expr, 1);
2998 163835 : expr = build_offset_ref (qualifying_class, expr,
2999 : /*address_p=*/true, complain);
3000 163835 : return expr;
3001 : }
3002 :
3003 : /* No need to check access within an enum. */
3004 85418195 : if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
3005 3625644 : && 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 81792554 : 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 81789890 : else if (TREE_CODE (expr) == FIELD_DECL)
3015 : {
3016 11611 : push_deferring_access_checks (dk_no_check);
3017 11611 : expr = finish_non_static_data_member (expr, NULL_TREE,
3018 : qualifying_class, complain);
3019 11611 : pop_deferring_access_checks ();
3020 : }
3021 81778279 : 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 6809040 : if (!shared_member_p (expr)
3026 452988 : && current_class_ptr
3027 7261341 : && DERIVED_FROM_P (qualifying_class,
3028 : current_nonlambda_class_type ()))
3029 451987 : expr = (build_class_member_access_expr
3030 451987 : (maybe_dummy_object (qualifying_class, NULL),
3031 : expr,
3032 451987 : BASELINK_ACCESS_BINFO (expr),
3033 : /*preserve_reference=*/false,
3034 : complain));
3035 6357053 : else if (done)
3036 : /* The expression is a qualified name whose address is not
3037 : being taken. */
3038 3579 : expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
3039 : complain);
3040 : }
3041 74969239 : else if (!template_p
3042 74755596 : && TREE_CODE (expr) == TEMPLATE_DECL
3043 74969322 : && !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 74969156 : if (processing_template_decl
3057 74969156 : && (!currently_open_class (qualifying_class)
3058 10653 : || TREE_CODE (expr) == IDENTIFIER_NODE
3059 10653 : || TREE_CODE (expr) == TEMPLATE_ID_EXPR
3060 82 : || TREE_CODE (expr) == BIT_NOT_EXPR))
3061 11139219 : expr = build_qualified_name (TREE_TYPE (expr),
3062 : qualifying_class, expr,
3063 : template_p);
3064 63829937 : else if (tree wrap = maybe_get_tls_wrapper_call (expr))
3065 9 : expr = wrap;
3066 :
3067 74969156 : 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 5671312 : begin_stmt_expr (void)
3078 : {
3079 5671312 : 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 29023 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
3089 : {
3090 29023 : 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 29020 : if (expr)
3101 : {
3102 29005 : tree type = TREE_TYPE (expr);
3103 :
3104 29005 : 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 28990 : 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 28821 : 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 28790 : expr = force_rvalue (expr, tf_warning_or_error);
3131 28790 : if (error_operand_p (expr))
3132 0 : return error_mark_node;
3133 :
3134 : /* Update for array-to-pointer decay. */
3135 28790 : type = TREE_TYPE (expr);
3136 :
3137 : /* This TARGET_EXPR will initialize the outer one added by
3138 : finish_stmt_expr. */
3139 28790 : 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 28790 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
3145 28790 : expr = maybe_cleanup_point_expr (expr);
3146 28790 : add_stmt (expr);
3147 : }
3148 :
3149 : /* The type of the statement-expression is the type of the last
3150 : expression. */
3151 28990 : 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 5671312 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
3163 : {
3164 5671312 : tree type;
3165 5671312 : tree result;
3166 :
3167 5671312 : if (error_operand_p (stmt_expr))
3168 : {
3169 18 : pop_stmt_list (stmt_expr);
3170 18 : return error_mark_node;
3171 : }
3172 :
3173 5671294 : gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
3174 :
3175 5671294 : type = TREE_TYPE (stmt_expr);
3176 5671294 : result = pop_stmt_list (stmt_expr);
3177 5671294 : TREE_TYPE (result) = type;
3178 :
3179 5671294 : if (processing_template_decl)
3180 : {
3181 38120 : result = build_min (STMT_EXPR, type, result);
3182 38120 : TREE_SIDE_EFFECTS (result) = 1;
3183 38120 : STMT_EXPR_NO_SCOPE (result) = has_no_scope;
3184 : }
3185 5633174 : 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 63704236 : empty_expr_stmt_p (tree expr_stmt)
3221 : {
3222 63704241 : tree body = NULL_TREE;
3223 :
3224 63704241 : if (expr_stmt == void_node)
3225 : return true;
3226 :
3227 63704238 : if (expr_stmt)
3228 : {
3229 63704238 : if (TREE_CODE (expr_stmt) == EXPR_STMT)
3230 5 : body = EXPR_STMT_EXPR (expr_stmt);
3231 63704233 : else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
3232 : body = expr_stmt;
3233 : }
3234 :
3235 5 : if (body)
3236 : {
3237 62762654 : if (TREE_CODE (body) == STATEMENT_LIST)
3238 62762649 : 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 19357434 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
3251 : tsubst_flags_t complain)
3252 : {
3253 19357434 : tree identifier = NULL_TREE;
3254 19357434 : tree functions = NULL_TREE;
3255 19357434 : tree tmpl_args = NULL_TREE;
3256 19357434 : bool template_id = false;
3257 19357434 : location_t loc = fn_expr.get_location ();
3258 19357434 : tree fn = fn_expr.get_value ();
3259 :
3260 19357434 : STRIP_ANY_LOCATION_WRAPPER (fn);
3261 :
3262 19357434 : if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
3263 : {
3264 : /* Use a separate flag to handle null args. */
3265 3722525 : template_id = true;
3266 3722525 : tmpl_args = TREE_OPERAND (fn, 1);
3267 3722525 : fn = TREE_OPERAND (fn, 0);
3268 : }
3269 :
3270 : /* Find the name of the overloaded function. */
3271 19357434 : if (identifier_p (fn))
3272 : identifier = fn;
3273 : else
3274 : {
3275 27351885 : functions = fn;
3276 19157141 : 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 19357434 : if (!any_type_dependent_arguments_p (args)
3284 19357434 : && !any_dependent_template_arguments_p (tmpl_args))
3285 : {
3286 18480662 : fn = lookup_arg_dependent (identifier, functions, args);
3287 18480662 : if (!fn)
3288 : {
3289 : /* The unqualified name could not be resolved. */
3290 59429 : if (complain & tf_error)
3291 391 : fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
3292 : else
3293 : fn = identifier;
3294 : }
3295 : }
3296 :
3297 19357434 : if (fn && template_id && fn != error_mark_node)
3298 3722512 : fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
3299 :
3300 19357434 : return cp_expr (fn, loc);
3301 : }
3302 :
3303 : /* Analyze call to a front-end builtin FN with arguments *ARGS. Return true
3304 : if the call is correct, false if erroneous. */
3305 :
3306 : static bool
3307 128632 : check_frontend_builtin (tree fn, vec<tree, va_gc> **args,
3308 : tsubst_flags_t complain)
3309 : {
3310 128632 : tree arg, ptype, type;
3311 128632 : switch (DECL_UNCHECKED_FUNCTION_CODE (fn))
3312 : {
3313 693 : case CP_BUILT_IN_IS_WITHIN_LIFETIME:
3314 693 : case CP_BUILT_IN_START_LIFETIME:
3315 : /* Unless users call the builtin directly, the following 2 checks
3316 : should be ensured from std::is_within_lifetime or
3317 : std::start_lifetime template. */
3318 693 : if (vec_safe_length (*args) != 1)
3319 : {
3320 14 : if (complain & tf_error)
3321 14 : error ("%qE needs a single argument", DECL_NAME (fn));
3322 : return false;
3323 : }
3324 679 : arg = (**args)[0];
3325 679 : if (error_operand_p (arg))
3326 : return false;
3327 679 : ptype = TREE_TYPE (arg);
3328 679 : if (!POINTER_TYPE_P (ptype))
3329 : {
3330 13 : if (complain & tf_error)
3331 13 : error ("%qE argument type %qT is not pointer type",
3332 13 : DECL_NAME (fn), ptype);
3333 : return false;
3334 : }
3335 666 : if (DECL_UNCHECKED_FUNCTION_CODE (fn) == CP_BUILT_IN_IS_WITHIN_LIFETIME)
3336 : return true;
3337 328 : type = TREE_TYPE (ptype);
3338 328 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
3339 : return false;
3340 328 : if (!CP_AGGREGATE_TYPE_P (type))
3341 : {
3342 10 : if (complain & tf_error)
3343 10 : error ("%qE argument type %qT is not a pointer to aggregate type",
3344 10 : DECL_NAME (fn), ptype);
3345 : return false;
3346 : }
3347 318 : if (!implicit_lifetime_type_p (type))
3348 : {
3349 4 : if (complain & tf_error)
3350 4 : error ("%qE argument type %qT is not a pointer to "
3351 4 : "implicit-lifetime type", DECL_NAME (fn), ptype);
3352 : return false;
3353 : }
3354 : return true;
3355 : default:
3356 : return true;
3357 : }
3358 : }
3359 :
3360 : /* Generate an expression for `FN (ARGS)'. This may change the
3361 : contents of ARGS.
3362 :
3363 : If DISALLOW_VIRTUAL is true, the call to FN will be not generated
3364 : as a virtual call, even if FN is virtual. (This flag is set when
3365 : encountering an expression where the function name is explicitly
3366 : qualified. For example a call to `X::f' never generates a virtual
3367 : call.)
3368 :
3369 : Returns code for the call. */
3370 :
3371 : tree
3372 375730842 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
3373 : bool koenig_p, tsubst_flags_t complain)
3374 : {
3375 375730842 : tree result;
3376 375730842 : tree orig_fn;
3377 375730842 : vec<tree, va_gc> *orig_args = *args;
3378 375730842 : tsubst_flags_t orig_complain = complain;
3379 :
3380 375730842 : if (fn == error_mark_node)
3381 : return error_mark_node;
3382 :
3383 375729774 : complain &= ~tf_any_viable;
3384 375729774 : gcc_assert (!TYPE_P (fn));
3385 :
3386 : /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
3387 : it so that we can tell this is a call to a known function. */
3388 375729774 : fn = maybe_undo_parenthesized_ref (fn);
3389 :
3390 375729774 : STRIP_ANY_LOCATION_WRAPPER (fn);
3391 :
3392 375729774 : orig_fn = fn;
3393 :
3394 375729774 : if (concept_check_p (fn))
3395 : {
3396 6 : error_at (EXPR_LOC_OR_LOC (fn, input_location),
3397 : "cannot call a concept as a function");
3398 6 : return error_mark_node;
3399 : }
3400 :
3401 375729768 : if (processing_template_decl)
3402 : {
3403 : /* If FN is a local extern declaration (or set thereof) in a template,
3404 : look it up again at instantiation time. */
3405 242104208 : if (is_overloaded_fn (fn))
3406 : {
3407 148438764 : tree ifn = get_first_fn (fn);
3408 148438764 : if (TREE_CODE (ifn) == FUNCTION_DECL
3409 148438764 : && dependent_local_decl_p (ifn))
3410 41149 : orig_fn = DECL_NAME (ifn);
3411 : }
3412 :
3413 : /* If the call expression is dependent, build a CALL_EXPR node
3414 : with no type; type_dependent_expression_p recognizes
3415 : expressions with no type as being dependent. */
3416 242104208 : if (type_dependent_expression_p (fn)
3417 242104208 : || any_type_dependent_arguments_p (*args))
3418 : {
3419 220125999 : if (koenig_p
3420 10767196 : && TREE_CODE (orig_fn) == FUNCTION_DECL
3421 223499863 : && !fndecl_built_in_p (orig_fn))
3422 : /* For an ADL-enabled call where unqualified lookup found a
3423 : single non-template function, wrap it in an OVERLOAD so that
3424 : later substitution doesn't overeagerly mark the function as
3425 : used. */
3426 879874 : orig_fn = ovl_make (orig_fn, NULL_TREE);
3427 220125999 : result = build_min_nt_call_vec (orig_fn, *args);
3428 299313888 : SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
3429 220125999 : KOENIG_LOOKUP_P (result) = koenig_p;
3430 : /* Disable the std::move warnings since this call was dependent
3431 : (c++/89780, c++/107363). This also suppresses the
3432 : -Wredundant-move warning. */
3433 220125999 : suppress_warning (result, OPT_Wpessimizing_move);
3434 :
3435 220125999 : if (cfun && cp_function_chain && !cp_unevaluated_operand)
3436 : {
3437 191647150 : bool abnormal = true;
3438 191926710 : for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
3439 : {
3440 106416683 : tree fndecl = STRIP_TEMPLATE (*iter);
3441 106416683 : if (TREE_CODE (fndecl) != FUNCTION_DECL
3442 106416605 : || !TREE_THIS_VOLATILE (fndecl))
3443 : {
3444 : abnormal = false;
3445 : break;
3446 : }
3447 : }
3448 : /* FIXME: Stop warning about falling off end of non-void
3449 : function. But this is wrong. Even if we only see
3450 : no-return fns at this point, we could select a
3451 : future-defined return fn during instantiation. Or
3452 : vice-versa. */
3453 191647150 : if (abnormal)
3454 85510027 : current_function_returns_abnormally = 1;
3455 : }
3456 220125999 : if (TREE_CODE (fn) == COMPONENT_REF)
3457 101650692 : maybe_generic_this_capture (TREE_OPERAND (fn, 0),
3458 101650692 : TREE_OPERAND (fn, 1));
3459 : return result;
3460 : }
3461 21978209 : orig_args = make_tree_vector_copy (*args);
3462 : }
3463 :
3464 155603769 : if (TREE_CODE (fn) == COMPONENT_REF)
3465 : {
3466 29710459 : tree member = TREE_OPERAND (fn, 1);
3467 29710459 : if (BASELINK_P (member))
3468 : {
3469 29520281 : tree object = TREE_OPERAND (fn, 0);
3470 58627265 : return build_new_method_call (object, member,
3471 : args, NULL_TREE,
3472 : (disallow_virtual
3473 : ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
3474 : : LOOKUP_NORMAL),
3475 : /*fn_p=*/NULL,
3476 29520281 : complain);
3477 : }
3478 : }
3479 :
3480 : /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
3481 126083488 : if (TREE_CODE (fn) == ADDR_EXPR
3482 126083488 : && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
3483 9 : fn = TREE_OPERAND (fn, 0);
3484 :
3485 126083488 : if (is_overloaded_fn (fn))
3486 117152860 : fn = baselink_for_fns (fn);
3487 :
3488 126083488 : result = NULL_TREE;
3489 126083488 : if (BASELINK_P (fn))
3490 : {
3491 14332073 : tree object;
3492 :
3493 : /* A call to a member function. From [over.call.func]:
3494 :
3495 : If the keyword this is in scope and refers to the class of
3496 : that member function, or a derived class thereof, then the
3497 : function call is transformed into a qualified function call
3498 : using (*this) as the postfix-expression to the left of the
3499 : . operator.... [Otherwise] a contrived object of type T
3500 : becomes the implied object argument.
3501 :
3502 : In this situation:
3503 :
3504 : struct A { void f(); };
3505 : struct B : public A {};
3506 : struct C : public A { void g() { B::f(); }};
3507 :
3508 : "the class of that member function" refers to `A'. But 11.2
3509 : [class.access.base] says that we need to convert 'this' to B* as
3510 : part of the access, so we pass 'B' to maybe_dummy_object. */
3511 :
3512 14332073 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
3513 : {
3514 : /* A constructor call always uses a dummy object. (This constructor
3515 : call which has the form A::A () is actually invalid and we are
3516 : going to reject it later in build_new_method_call.) */
3517 39 : object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
3518 : }
3519 : else
3520 14332034 : object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
3521 : NULL);
3522 :
3523 16370297 : result = build_new_method_call (object, fn, args, NULL_TREE,
3524 : (disallow_virtual
3525 : ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
3526 : : LOOKUP_NORMAL),
3527 : /*fn_p=*/NULL,
3528 : complain);
3529 : }
3530 111751415 : else if (is_overloaded_fn (fn))
3531 : {
3532 : /* If the function is an overloaded builtin, resolve it. */
3533 102820787 : if (TREE_CODE (fn) == FUNCTION_DECL
3534 102820787 : && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
3535 19131647 : || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
3536 9690178 : result = resolve_overloaded_builtin (input_location, fn, *args,
3537 : complain & tf_error);
3538 :
3539 9690178 : if (!result)
3540 : {
3541 102473590 : tree alloc_size_attr = NULL_TREE;
3542 102473590 : if (warn_calloc_transposed_args
3543 716603 : && TREE_CODE (fn) == FUNCTION_DECL
3544 102473590 : && (alloc_size_attr
3545 432526 : = lookup_attribute ("alloc_size",
3546 432526 : TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
3547 3401 : if (TREE_VALUE (alloc_size_attr) == NULL_TREE
3548 3401 : || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
3549 : alloc_size_attr = NULL_TREE;
3550 100730371 : if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
3551 1743279 : && (complain & tf_warning)
3552 1520989 : && !vec_safe_is_empty (*args)
3553 103641002 : && !processing_template_decl)
3554 : {
3555 : location_t sizeof_arg_loc[6];
3556 : tree sizeof_arg[6];
3557 : unsigned int i;
3558 8390604 : for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
3559 : {
3560 3146679 : tree t;
3561 :
3562 3146679 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
3563 3146679 : sizeof_arg[i] = NULL_TREE;
3564 3146679 : if (i >= (*args)->length ())
3565 657445 : continue;
3566 2489234 : t = (**args)[i];
3567 2489234 : if (TREE_CODE (t) != SIZEOF_EXPR)
3568 2482577 : continue;
3569 6657 : if (SIZEOF_EXPR_TYPE_P (t))
3570 2663 : sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
3571 : else
3572 3994 : sizeof_arg[i] = TREE_OPERAND (t, 0);
3573 6657 : sizeof_arg_loc[i] = EXPR_LOCATION (t);
3574 : }
3575 1048833 : if (warn_sizeof_pointer_memaccess)
3576 : {
3577 1048773 : auto same_p = same_type_ignoring_top_level_qualifiers_p;
3578 1048773 : sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
3579 : sizeof_arg, same_p);
3580 : }
3581 1048833 : if (alloc_size_attr)
3582 60 : warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
3583 : alloc_size_attr);
3584 : }
3585 :
3586 102473590 : if ((complain & tf_warning)
3587 56582144 : && TREE_CODE (fn) == FUNCTION_DECL
3588 27070746 : && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
3589 147699 : && vec_safe_length (*args) == 3
3590 102621289 : && !any_type_dependent_arguments_p (*args))
3591 : {
3592 147699 : tree arg0 = (*orig_args)[0];
3593 147699 : tree arg1 = (*orig_args)[1];
3594 147699 : tree arg2 = (*orig_args)[2];
3595 147699 : int literal_mask = ((literal_integer_zerop (arg1) << 1)
3596 147699 : | (literal_integer_zerop (arg2) << 2));
3597 147699 : warn_for_memset (input_location, arg0, arg2, literal_mask);
3598 : }
3599 :
3600 102473590 : if (TREE_CODE (fn) == FUNCTION_DECL
3601 27197618 : && fndecl_built_in_p (fn, BUILT_IN_FRONTEND)
3602 102602222 : && !check_frontend_builtin (fn, args, complain))
3603 41 : return error_mark_node;
3604 :
3605 : /* A call to a namespace-scope function. */
3606 102473549 : result = build_new_function_call (fn, args, orig_complain);
3607 : }
3608 : }
3609 8930628 : else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
3610 : {
3611 162017 : if (!vec_safe_is_empty (*args))
3612 0 : error ("arguments to destructor are not allowed");
3613 : /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
3614 : which case the postfix-expression is a possibly-parenthesized class
3615 : member access), the function call destroys the object of scalar type
3616 : denoted by the object expression of the class member access. */
3617 162017 : tree ob = TREE_OPERAND (fn, 0);
3618 162017 : if (obvalue_p (ob))
3619 161999 : result = build_trivial_dtor_call (ob, true);
3620 : else
3621 : /* No location to clobber. */
3622 18 : result = convert_to_void (ob, ICV_STATEMENT, complain);
3623 : }
3624 8768611 : else if (CLASS_TYPE_P (TREE_TYPE (fn)))
3625 : /* If the "function" is really an object of class type, it might
3626 : have an overloaded `operator ()'. */
3627 2641674 : result = build_op_call (fn, args, complain);
3628 :
3629 119595795 : if (!result)
3630 : /* A call where the function is unknown. */
3631 6126937 : result = cp_build_function_call_vec (fn, args, complain);
3632 :
3633 126069929 : if (processing_template_decl && result != error_mark_node)
3634 : {
3635 16824755 : if (INDIRECT_REF_P (result))
3636 1148267 : result = TREE_OPERAND (result, 0);
3637 :
3638 : /* Prune all but the selected function from the original overload
3639 : set so that we can avoid some duplicate work at instantiation time. */
3640 16824755 : if (TREE_CODE (result) == CALL_EXPR
3641 16814979 : && really_overloaded_fn (orig_fn))
3642 : {
3643 6197497 : tree sel_fn = CALL_EXPR_FN (result);
3644 6197497 : if (TREE_CODE (sel_fn) == COMPONENT_REF)
3645 : {
3646 : /* The non-dependent result of build_new_method_call. */
3647 262378 : sel_fn = TREE_OPERAND (sel_fn, 1);
3648 262378 : gcc_assert (BASELINK_P (sel_fn));
3649 : }
3650 5935119 : else if (TREE_CODE (sel_fn) == ADDR_EXPR)
3651 : /* Our original callee wasn't wrapped in an ADDR_EXPR,
3652 : so strip this ADDR_EXPR added by build_over_call. */
3653 5935119 : sel_fn = TREE_OPERAND (sel_fn, 0);
3654 : orig_fn = sel_fn;
3655 : }
3656 :
3657 16824755 : tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
3658 16824755 : SET_EXPR_LOCATION (r, input_location);
3659 16824755 : KOENIG_LOOKUP_P (r) = koenig_p;
3660 16824755 : TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
3661 16824755 : release_tree_vector (orig_args);
3662 16824755 : result = convert_from_reference (r);
3663 : }
3664 :
3665 : return result;
3666 : }
3667 :
3668 : /* Finish a call to a postfix increment or decrement or EXPR. (Which
3669 : is indicated by CODE, which should be POSTINCREMENT_EXPR or
3670 : POSTDECREMENT_EXPR.) */
3671 :
3672 : cp_expr
3673 2702234 : finish_increment_expr (cp_expr expr, enum tree_code code)
3674 : {
3675 : /* input_location holds the location of the trailing operator token.
3676 : Build a location of the form:
3677 : expr++
3678 : ~~~~^~
3679 : with the caret at the operator token, ranging from the start
3680 : of EXPR to the end of the operator token. */
3681 2702234 : location_t combined_loc = make_location (input_location,
3682 : expr.get_start (),
3683 : get_finish (input_location));
3684 2702234 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3685 2702234 : NULL_TREE, tf_warning_or_error);
3686 : /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3687 2702234 : result.set_location (combined_loc);
3688 2702234 : return result;
3689 : }
3690 :
3691 : /* Finish a use of `this'. Returns an expression for `this'. */
3692 :
3693 : tree
3694 36978246 : finish_this_expr (void)
3695 : {
3696 36978246 : tree result = NULL_TREE;
3697 :
3698 73956368 : if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
3699 36676698 : result = current_class_ptr;
3700 603080 : else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
3701 301472 : result = (lambda_expr_this_capture
3702 301472 : (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
3703 : else
3704 76 : gcc_checking_assert (!current_class_ptr);
3705 :
3706 36978170 : if (result)
3707 : /* The keyword 'this' is a prvalue expression. */
3708 36978167 : return rvalue (result);
3709 :
3710 79 : tree fn = current_nonlambda_function ();
3711 79 : if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
3712 : {
3713 6 : auto_diagnostic_group d;
3714 6 : error ("%<this%> is unavailable for explicit object member "
3715 : "functions");
3716 6 : tree xobj_parm = DECL_ARGUMENTS (fn);
3717 6 : gcc_assert (xobj_parm);
3718 6 : tree parm_name = DECL_NAME (xobj_parm);
3719 :
3720 6 : static tree remembered_fn = NULL_TREE;
3721 : /* Only output this diagnostic once per function. */
3722 6 : if (remembered_fn == fn)
3723 : /* Early escape. */;
3724 6 : else if (parm_name)
3725 6 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3726 : "use explicit object parameter %qs instead",
3727 3 : IDENTIFIER_POINTER (parm_name));
3728 : else
3729 3 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3730 : "name the explicit object parameter");
3731 :
3732 6 : remembered_fn = fn;
3733 6 : }
3734 73 : else if (fn && DECL_STATIC_FUNCTION_P (fn))
3735 3 : error ("%<this%> is unavailable for static member functions");
3736 70 : else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
3737 0 : error ("invalid use of %<this%> in a constructor %<pre%> condition");
3738 70 : else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
3739 0 : error ("invalid use of %<this%> in a destructor %<post%> condition");
3740 70 : else if (fn)
3741 22 : error ("invalid use of %<this%> in non-member function");
3742 : else
3743 48 : error ("invalid use of %<this%> at top level");
3744 79 : return error_mark_node;
3745 : }
3746 :
3747 : /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3748 : expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3749 : the TYPE for the type given. If SCOPE is non-NULL, the expression
3750 : was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3751 :
3752 : tree
3753 162068 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
3754 : location_t loc, tsubst_flags_t complain)
3755 : {
3756 162068 : if (object == error_mark_node || destructor == error_mark_node)
3757 : return error_mark_node;
3758 :
3759 162059 : gcc_assert (TYPE_P (destructor));
3760 :
3761 162059 : if (!processing_template_decl)
3762 : {
3763 162038 : if (scope == error_mark_node)
3764 : {
3765 0 : if (complain & tf_error)
3766 0 : error_at (loc, "invalid qualifying scope in pseudo-destructor name");
3767 0 : return error_mark_node;
3768 : }
3769 162038 : if (is_auto (destructor))
3770 3 : destructor = TREE_TYPE (object);
3771 162038 : if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
3772 : {
3773 3 : if (complain & tf_error)
3774 3 : error_at (loc,
3775 : "qualified type %qT does not match destructor name ~%qT",
3776 : scope, destructor);
3777 3 : return error_mark_node;
3778 : }
3779 :
3780 :
3781 : /* [expr.pseudo] says both:
3782 :
3783 : The type designated by the pseudo-destructor-name shall be
3784 : the same as the object type.
3785 :
3786 : and:
3787 :
3788 : The cv-unqualified versions of the object type and of the
3789 : type designated by the pseudo-destructor-name shall be the
3790 : same type.
3791 :
3792 : We implement the more generous second sentence, since that is
3793 : what most other compilers do. */
3794 162035 : if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
3795 : destructor))
3796 : {
3797 12 : if (complain & tf_error)
3798 9 : error_at (loc, "%qE is not of type %qT", object, destructor);
3799 12 : return error_mark_node;
3800 : }
3801 : }
3802 :
3803 162044 : tree type = (type_dependent_expression_p (object)
3804 162044 : ? NULL_TREE : void_type_node);
3805 :
3806 162044 : return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
3807 162044 : scope, destructor);
3808 : }
3809 :
3810 : /* Finish an expression of the form CODE EXPR. */
3811 :
3812 : cp_expr
3813 39455037 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
3814 : tsubst_flags_t complain)
3815 : {
3816 : /* Build a location of the form:
3817 : ++expr
3818 : ^~~~~~
3819 : with the caret at the operator token, ranging from the start
3820 : of the operator token to the end of EXPR. */
3821 39455037 : location_t combined_loc = make_location (op_loc,
3822 : op_loc, expr.get_finish ());
3823 39455037 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3824 39455037 : NULL_TREE, complain);
3825 : /* TODO: build_x_unary_op doesn't always honor the location. */
3826 39455037 : result.set_location (combined_loc);
3827 :
3828 39455037 : if (result == error_mark_node)
3829 : return result;
3830 :
3831 39454534 : if (!(complain & tf_warning))
3832 : return result;
3833 :
3834 : /* These will never fold into a constant, so no need to check for
3835 : overflow for them. */
3836 39454534 : if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
3837 : return result;
3838 :
3839 21306534 : tree result_ovl = result;
3840 21306534 : tree expr_ovl = expr;
3841 :
3842 21306534 : if (!processing_template_decl)
3843 1869181 : expr_ovl = cp_fully_fold (expr_ovl);
3844 :
3845 21306534 : if (!CONSTANT_CLASS_P (expr_ovl)
3846 21306534 : || TREE_OVERFLOW_P (expr_ovl))
3847 : return result;
3848 :
3849 260670 : if (!processing_template_decl)
3850 251202 : result_ovl = cp_fully_fold (result_ovl);
3851 :
3852 260670 : if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
3853 9 : overflow_warning (combined_loc, result_ovl);
3854 :
3855 : return result;
3856 : }
3857 :
3858 : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3859 : elements. */
3860 :
3861 : static bool
3862 12 : maybe_zero_constructor_nelts (tree expr)
3863 : {
3864 12 : if (CONSTRUCTOR_NELTS (expr) == 0)
3865 : return true;
3866 12 : if (!processing_template_decl)
3867 : return false;
3868 30 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
3869 21 : if (!PACK_EXPANSION_P (elt.value))
3870 : return false;
3871 : return true;
3872 : }
3873 :
3874 : /* Finish a compound-literal expression or C++11 functional cast with aggregate
3875 : initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3876 : is being cast. */
3877 :
3878 : tree
3879 10059091 : finish_compound_literal (tree type, tree compound_literal,
3880 : tsubst_flags_t complain,
3881 : fcl_t fcl_context)
3882 : {
3883 10059091 : if (type == error_mark_node)
3884 : return error_mark_node;
3885 :
3886 10059039 : if (TYPE_REF_P (type))
3887 : {
3888 12 : compound_literal
3889 12 : = finish_compound_literal (TREE_TYPE (type), compound_literal,
3890 : complain, fcl_context);
3891 : /* The prvalue is then used to direct-initialize the reference. */
3892 12 : tree r = (perform_implicit_conversion_flags
3893 12 : (type, compound_literal, complain, LOOKUP_NORMAL));
3894 12 : return convert_from_reference (r);
3895 : }
3896 :
3897 10059027 : if (!TYPE_OBJ_P (type))
3898 : {
3899 : /* DR2351 */
3900 60 : if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
3901 : {
3902 12 : if (!processing_template_decl)
3903 9 : return void_node;
3904 3 : TREE_TYPE (compound_literal) = type;
3905 3 : TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
3906 3 : CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
3907 3 : return compound_literal;
3908 : }
3909 21 : else if (VOID_TYPE_P (type)
3910 15 : && processing_template_decl
3911 33 : && maybe_zero_constructor_nelts (compound_literal))
3912 : /* If there are only packs in compound_literal, it could
3913 : be void{} after pack expansion. */;
3914 : else
3915 : {
3916 12 : if (complain & tf_error)
3917 9 : error ("compound literal of non-object type %qT", type);
3918 12 : return error_mark_node;
3919 : }
3920 : }
3921 :
3922 10059003 : if (template_placeholder_p (type))
3923 : {
3924 194669 : type = do_auto_deduction (type, compound_literal, type, complain,
3925 : adc_variable_type);
3926 194669 : if (type == error_mark_node)
3927 : return error_mark_node;
3928 : }
3929 : /* C++23 auto{x}. */
3930 9864334 : else if (is_auto (type)
3931 162 : && !AUTO_IS_DECLTYPE (type)
3932 9864493 : && CONSTRUCTOR_NELTS (compound_literal) == 1)
3933 : {
3934 150 : if (is_constrained_auto (type))
3935 : {
3936 3 : if (complain & tf_error)
3937 3 : error ("%<auto{x}%> cannot be constrained");
3938 3 : return error_mark_node;
3939 : }
3940 147 : else if (cxx_dialect < cxx23)
3941 : {
3942 1 : if ((complain & tf_warning_or_error) == 0)
3943 0 : return error_mark_node;
3944 1 : pedwarn (input_location, OPT_Wc__23_extensions,
3945 : "%<auto{x}%> only available with "
3946 : "%<-std=c++23%> or %<-std=gnu++23%>");
3947 : }
3948 147 : type = do_auto_deduction (type, compound_literal, type, complain,
3949 : adc_variable_type);
3950 147 : if (type == error_mark_node)
3951 : return error_mark_node;
3952 : }
3953 :
3954 : /* Used to hold a copy of the compound literal in a template. */
3955 10058858 : tree orig_cl = NULL_TREE;
3956 :
3957 10058858 : if (processing_template_decl)
3958 : {
3959 5253918 : const bool dependent_p
3960 5253918 : = (instantiation_dependent_expression_p (compound_literal)
3961 5253918 : || dependent_type_p (type));
3962 1742042 : if (dependent_p)
3963 : /* We're about to return, no need to copy. */
3964 : orig_cl = compound_literal;
3965 : else
3966 : /* We're going to need a copy. */
3967 1742042 : orig_cl = unshare_constructor (compound_literal);
3968 5253918 : TREE_TYPE (orig_cl) = type;
3969 : /* Mark the expression as a compound literal. */
3970 5253918 : TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
3971 : /* And as instantiation-dependent. */
3972 5253918 : CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
3973 5253918 : if (fcl_context == fcl_c99)
3974 130 : CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
3975 : /* If the compound literal is dependent, we're done for now. */
3976 5253918 : if (dependent_p)
3977 : return orig_cl;
3978 : /* Otherwise, do go on to e.g. check narrowing. */
3979 : }
3980 :
3981 6546982 : type = complete_type (type);
3982 :
3983 6546982 : if (TYPE_NON_AGGREGATE_CLASS (type))
3984 : {
3985 : /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3986 : everywhere that deals with function arguments would be a pain, so
3987 : just wrap it in a TREE_LIST. The parser set a flag so we know
3988 : that it came from T{} rather than T({}). */
3989 1088325 : CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
3990 1088325 : compound_literal = build_tree_list (NULL_TREE, compound_literal);
3991 1088325 : return build_functional_cast (input_location, type,
3992 1088325 : compound_literal, complain);
3993 : }
3994 :
3995 5458657 : if (TREE_CODE (type) == ARRAY_TYPE
3996 5458657 : && check_array_initializer (NULL_TREE, type, compound_literal))
3997 9 : return error_mark_node;
3998 5458648 : compound_literal = reshape_init (type, compound_literal, complain);
3999 5458648 : if (SCALAR_TYPE_P (type)
4000 754875 : && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
4001 218338 : && !check_narrowing (type, compound_literal, complain))
4002 131 : return error_mark_node;
4003 5458517 : if (TREE_CODE (type) == ARRAY_TYPE
4004 5458517 : && TYPE_DOMAIN (type) == NULL_TREE)
4005 : {
4006 1253 : cp_complete_array_type_or_error (&type, compound_literal,
4007 : false, complain);
4008 1253 : if (type == error_mark_node)
4009 : return error_mark_node;
4010 : }
4011 5458514 : if (abstract_virtuals_error (ACU_UNKNOWN, type, complain))
4012 7 : return error_mark_node;
4013 5458507 : compound_literal = digest_init_flags (type, compound_literal,
4014 : LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
4015 : complain);
4016 5458507 : if (compound_literal == error_mark_node)
4017 : return error_mark_node;
4018 :
4019 : /* If we're in a template, return the original compound literal. */
4020 5457843 : if (orig_cl)
4021 : return orig_cl;
4022 :
4023 3804529 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
4024 : {
4025 3106492 : TREE_HAS_CONSTRUCTOR (compound_literal) = true;
4026 3106492 : if (fcl_context == fcl_c99)
4027 37961 : CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
4028 : }
4029 :
4030 : /* Put static/constant array temporaries in static variables. */
4031 : /* FIXME all C99 compound literals should be variables rather than C++
4032 : temporaries, unless they are used as an aggregate initializer. */
4033 5014649 : if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
4034 2603958 : && fcl_context == fcl_c99
4035 83 : && TREE_CODE (type) == ARRAY_TYPE
4036 31 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
4037 3804560 : && initializer_constant_valid_p (compound_literal, type))
4038 : {
4039 31 : tree decl = create_temporary_var (type);
4040 31 : DECL_CONTEXT (decl) = NULL_TREE;
4041 31 : DECL_INITIAL (decl) = compound_literal;
4042 31 : TREE_STATIC (decl) = 1;
4043 31 : if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
4044 : {
4045 : /* 5.19 says that a constant expression can include an
4046 : lvalue-rvalue conversion applied to "a glvalue of literal type
4047 : that refers to a non-volatile temporary object initialized
4048 : with a constant expression". Rather than try to communicate
4049 : that this VAR_DECL is a temporary, just mark it constexpr. */
4050 24 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
4051 24 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
4052 24 : TREE_CONSTANT (decl) = true;
4053 : }
4054 31 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
4055 31 : decl = pushdecl_top_level (decl);
4056 31 : DECL_NAME (decl) = make_anon_name ();
4057 31 : SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
4058 : /* Make sure the destructor is callable. */
4059 31 : tree clean = cxx_maybe_build_cleanup (decl, complain);
4060 31 : if (clean == error_mark_node)
4061 : return error_mark_node;
4062 31 : return decl;
4063 : }
4064 :
4065 : /* Represent other compound literals with TARGET_EXPR so we produce
4066 : a prvalue, and can elide copies. */
4067 3804498 : if (!VECTOR_TYPE_P (type)
4068 3763931 : && (TREE_CODE (compound_literal) == CONSTRUCTOR
4069 698031 : || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
4070 : {
4071 : /* The CONSTRUCTOR is now an initializer, not a compound literal. */
4072 3065900 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
4073 3065900 : TREE_HAS_CONSTRUCTOR (compound_literal) = false;
4074 3065900 : compound_literal = get_target_expr (compound_literal, complain);
4075 : }
4076 : else
4077 : /* For e.g. int{42} just make sure it's a prvalue. */
4078 738598 : compound_literal = rvalue (compound_literal);
4079 :
4080 : return compound_literal;
4081 : }
4082 :
4083 : /* Return the declaration for the function-name variable indicated by
4084 : ID. */
4085 :
4086 : tree
4087 299136 : finish_fname (tree id)
4088 : {
4089 299136 : tree decl = fname_decl (input_location, C_RID_CODE (id), id);
4090 : /* [expr.prim.lambda.closure]/16 "Unless the compound-statement is that
4091 : of a consteval-block-declaration, a variable __func__ is implicitly
4092 : defined...". We could be in a consteval block in a function, though,
4093 : and then we shouldn't warn. */
4094 299136 : if (current_function_decl
4095 299136 : && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
4096 8 : pedwarn (input_location, 0, "%qD is not defined outside of function scope",
4097 : decl);
4098 299136 : if (processing_template_decl && current_function_decl
4099 220598 : && decl != error_mark_node)
4100 220598 : decl = DECL_NAME (decl);
4101 299136 : return decl;
4102 : }
4103 :
4104 : /* Finish a translation unit. */
4105 :
4106 : void
4107 99836 : finish_translation_unit (void)
4108 : {
4109 : /* In case there were missing closebraces,
4110 : get us back to the global binding level. */
4111 99836 : pop_everything ();
4112 199672 : while (current_namespace != global_namespace)
4113 0 : pop_namespace ();
4114 :
4115 : /* Do file scope __FUNCTION__ et al. */
4116 99836 : finish_fname_decls ();
4117 :
4118 99836 : if (vec_safe_length (scope_chain->omp_declare_target_attribute))
4119 : {
4120 12 : cp_omp_declare_target_attr
4121 12 : a = scope_chain->omp_declare_target_attribute->pop ();
4122 12 : if (!errorcount)
4123 9 : error ("%qs without corresponding %qs",
4124 : a.device_type >= 0 ? "#pragma omp begin declare target"
4125 : : "#pragma omp declare target",
4126 : "#pragma omp end declare target");
4127 24 : vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
4128 : }
4129 99836 : if (vec_safe_length (scope_chain->omp_declare_variant_attribute))
4130 : {
4131 0 : if (!errorcount)
4132 0 : error ("%<omp begin declare variant%> without corresponding "
4133 : "%<omp end declare variant%>");
4134 0 : vec_safe_truncate (scope_chain->omp_declare_variant_attribute, 0);
4135 : }
4136 99836 : if (vec_safe_length (scope_chain->omp_begin_assumes))
4137 : {
4138 3 : if (!errorcount)
4139 3 : error ("%qs without corresponding %qs",
4140 : "#pragma omp begin assumes", "#pragma omp end assumes");
4141 3 : vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
4142 : }
4143 99836 : }
4144 :
4145 : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
4146 : Returns the parameter. */
4147 :
4148 : tree
4149 165408905 : finish_template_type_parm (tree aggr, tree identifier)
4150 : {
4151 165408905 : if (aggr != class_type_node)
4152 : {
4153 0 : permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
4154 0 : aggr = class_type_node;
4155 : }
4156 :
4157 165408905 : return build_tree_list (aggr, identifier);
4158 : }
4159 :
4160 : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
4161 : Returns the parameter. */
4162 :
4163 : tree
4164 421170 : finish_template_template_parm (tree aggr, tree identifier)
4165 : {
4166 421170 : tree decl = build_decl (input_location,
4167 : TYPE_DECL, identifier, NULL_TREE);
4168 :
4169 421170 : tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
4170 421170 : DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
4171 421170 : DECL_TEMPLATE_RESULT (tmpl) = decl;
4172 421170 : DECL_ARTIFICIAL (decl) = 1;
4173 :
4174 : /* Associate the constraints with the underlying declaration,
4175 : not the template. */
4176 421170 : tree constr = current_template_constraints ();
4177 421170 : set_constraints (decl, constr);
4178 :
4179 421170 : end_template_decl ();
4180 :
4181 421170 : gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
4182 :
4183 421170 : check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
4184 : /*is_primary=*/true, /*is_partial=*/false,
4185 : /*is_friend=*/0);
4186 :
4187 421170 : return finish_template_type_parm (aggr, tmpl);
4188 : }
4189 :
4190 : /* ARGUMENT is the default-argument value for a template template
4191 : parameter. If ARGUMENT is invalid, issue error messages and return
4192 : the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
4193 :
4194 : tree
4195 950 : check_template_template_default_arg (tree argument)
4196 : {
4197 950 : if (TREE_CODE (argument) != TEMPLATE_DECL
4198 : && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
4199 : && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
4200 : {
4201 : if (TREE_CODE (argument) == TYPE_DECL)
4202 : {
4203 18 : if (tree t = maybe_get_template_decl_from_type_decl (argument))
4204 18 : if (TREE_CODE (t) == TEMPLATE_DECL)
4205 : return t;
4206 15 : error ("invalid use of type %qT as a default value for a template "
4207 15 : "template-parameter", TREE_TYPE (argument));
4208 : }
4209 : else
4210 0 : error ("invalid default argument for a template template parameter");
4211 15 : return error_mark_node;
4212 : }
4213 :
4214 : return argument;
4215 : }
4216 :
4217 : /* Begin a class definition, as indicated by T. */
4218 :
4219 : tree
4220 31812241 : begin_class_definition (tree t)
4221 : {
4222 31812241 : if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
4223 33 : return error_mark_node;
4224 :
4225 31812358 : if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
4226 : {
4227 24 : error ("definition of %q#T inside template parameter list", t);
4228 24 : return error_mark_node;
4229 : }
4230 :
4231 : /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
4232 : are passed the same as decimal scalar types. */
4233 31812184 : if (TREE_CODE (t) == RECORD_TYPE
4234 31281251 : && !processing_template_decl)
4235 : {
4236 11244729 : tree ns = TYPE_CONTEXT (t);
4237 11244726 : if (ns && TREE_CODE (ns) == NAMESPACE_DECL
4238 9234417 : && DECL_CONTEXT (ns) == std_node
4239 2237826 : && DECL_NAME (ns)
4240 13482535 : && id_equal (DECL_NAME (ns), "decimal"))
4241 : {
4242 150 : const char *n = TYPE_NAME_STRING (t);
4243 150 : if ((strcmp (n, "decimal32") == 0)
4244 101 : || (strcmp (n, "decimal64") == 0)
4245 46 : || (strcmp (n, "decimal128") == 0))
4246 147 : TYPE_TRANSPARENT_AGGR (t) = 1;
4247 : }
4248 : }
4249 :
4250 : /* A non-implicit typename comes from code like:
4251 :
4252 : template <typename T> struct A {
4253 : template <typename U> struct A<T>::B ...
4254 :
4255 : This is erroneous. */
4256 20567455 : else if (TREE_CODE (t) == TYPENAME_TYPE)
4257 : {
4258 0 : error ("invalid definition of qualified type %qT", t);
4259 0 : t = error_mark_node;
4260 : }
4261 :
4262 31812184 : if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
4263 : {
4264 0 : t = make_class_type (RECORD_TYPE);
4265 0 : pushtag (make_anon_name (), t);
4266 : }
4267 :
4268 31812184 : if (TYPE_BEING_DEFINED (t))
4269 : {
4270 0 : t = make_class_type (TREE_CODE (t));
4271 0 : pushtag (TYPE_IDENTIFIER (t), t);
4272 : }
4273 :
4274 31812184 : maybe_process_partial_specialization (t);
4275 31812184 : pushclass (t);
4276 31812184 : TYPE_BEING_DEFINED (t) = 1;
4277 31812184 : class_binding_level->defining_class_p = 1;
4278 :
4279 31812184 : if (flag_pack_struct)
4280 : {
4281 99 : tree v;
4282 99 : TYPE_PACKED (t) = 1;
4283 : /* Even though the type is being defined for the first time
4284 : here, there might have been a forward declaration, so there
4285 : might be cv-qualified variants of T. */
4286 99 : for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
4287 0 : TYPE_PACKED (v) = 1;
4288 : }
4289 : /* Reset the interface data, at the earliest possible
4290 : moment, as it might have been set via a class foo;
4291 : before. */
4292 66055643 : if (! TYPE_UNNAMED_P (t))
4293 : {
4294 31048805 : struct c_fileinfo *finfo = \
4295 31048805 : get_fileinfo (LOCATION_FILE (input_location));
4296 31048805 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
4297 31048805 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X
4298 : (t, finfo->interface_unknown);
4299 : }
4300 31812184 : reset_specialization ();
4301 :
4302 : /* Make a declaration for this class in its own scope. */
4303 31812184 : build_self_reference ();
4304 :
4305 31812184 : return t;
4306 : }
4307 :
4308 : /* Finish the member declaration given by DECL. */
4309 :
4310 : void
4311 429799991 : finish_member_declaration (tree decl)
4312 : {
4313 429799991 : if (decl == error_mark_node || decl == NULL_TREE)
4314 : return;
4315 :
4316 429798942 : if (decl == void_type_node)
4317 : /* The COMPONENT was a friend, not a member, and so there's
4318 : nothing for us to do. */
4319 : return;
4320 :
4321 : /* We should see only one DECL at a time. */
4322 429798942 : gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
4323 :
4324 : /* Don't add decls after definition. */
4325 429798963 : gcc_assert (TYPE_BEING_DEFINED (current_class_type)
4326 : /* We can add lambda types when late parsing default
4327 : arguments. */
4328 : || LAMBDA_TYPE_P (TREE_TYPE (decl)));
4329 :
4330 : /* Set up access control for DECL. */
4331 429798942 : TREE_PRIVATE (decl)
4332 429798942 : = (current_access_specifier == access_private_node);
4333 429798942 : TREE_PROTECTED (decl)
4334 429798942 : = (current_access_specifier == access_protected_node);
4335 429798942 : if (TREE_CODE (decl) == TEMPLATE_DECL)
4336 : {
4337 49058396 : TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
4338 49058396 : TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
4339 : }
4340 :
4341 : /* Mark the DECL as a member of the current class, unless it's
4342 : a member of an enumeration. */
4343 429798942 : if (TREE_CODE (decl) != CONST_DECL)
4344 427376031 : DECL_CONTEXT (decl) = current_class_type;
4345 :
4346 429798942 : if (TREE_TYPE (decl)
4347 426202146 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl))
4348 430195303 : && TREE_CODE (decl) != TYPE_DECL)
4349 : {
4350 : /* Remember the single FIELD_DECL an anonymous aggregate type is used
4351 : for. */
4352 288602 : if (TREE_CODE (decl) == FIELD_DECL && DECL_NAME (decl) == NULL_TREE)
4353 : {
4354 288586 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
4355 288586 : gcc_assert (!ANON_AGGR_TYPE_FIELD (type));
4356 288586 : SET_ANON_AGGR_TYPE_FIELD (type, decl);
4357 : }
4358 : /* [class.union.anon]/1: Each object of such an unnamed type shall
4359 : be such an unnamed object. */
4360 16 : else if (ANON_UNION_TYPE_P (TREE_TYPE (decl)))
4361 : {
4362 10 : tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
4363 10 : auto_diagnostic_group d;
4364 10 : error_at (location_of (decl),
4365 : "declaration of member %qD with anonymous union type %qT",
4366 10 : decl, TREE_TYPE (decl));
4367 10 : inform (DECL_SOURCE_LOCATION (adecl),
4368 : "anonymous union declared here");
4369 10 : }
4370 : else
4371 : {
4372 6 : tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
4373 6 : auto_diagnostic_group d;
4374 6 : error_at (location_of (decl),
4375 : "declaration of member %qD with anonymous struct type %qT",
4376 6 : decl, TREE_TYPE (decl));
4377 6 : inform (DECL_SOURCE_LOCATION (adecl),
4378 : "anonymous struct declared here");
4379 6 : }
4380 : }
4381 429510340 : else if (TREE_TYPE (decl)
4382 425913544 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
4383 431106049 : && TREE_CODE (decl) != TYPE_DECL)
4384 : {
4385 1530764 : tree type = strip_array_types (TREE_TYPE (decl));
4386 1530764 : if (ANON_AGGR_TYPE_P (type))
4387 : {
4388 : /* [class.union.anon]/1: Each object of such an unnamed type shall
4389 : be such an unnamed object. */
4390 12 : tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (type));
4391 12 : auto_diagnostic_group d;
4392 12 : if (ANON_UNION_TYPE_P (type))
4393 : {
4394 8 : error_at (location_of (decl),
4395 : "declaration of member %qD with array of anonymous "
4396 8 : "union type %qT", decl, TREE_TYPE (decl));
4397 8 : inform (DECL_SOURCE_LOCATION (adecl),
4398 : "anonymous union declared here");
4399 : }
4400 : else
4401 : {
4402 4 : error_at (location_of (decl),
4403 : "declaration of member %qD with array of anonymous "
4404 4 : "struct type %qT", decl, TREE_TYPE (decl));
4405 4 : inform (DECL_SOURCE_LOCATION (adecl),
4406 : "anonymous struct declared here");
4407 : }
4408 12 : }
4409 : }
4410 :
4411 429798942 : if (TREE_CODE (decl) == USING_DECL)
4412 : /* Avoid debug info for class-scope USING_DECLS for now, we'll
4413 : call cp_emit_debug_info_for_using later. */
4414 3504200 : DECL_IGNORED_P (decl) = 1;
4415 :
4416 : /* Check for bare parameter packs in the non-static data member
4417 : declaration. */
4418 429798942 : if (TREE_CODE (decl) == FIELD_DECL)
4419 : {
4420 31505907 : if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
4421 9 : TREE_TYPE (decl) = error_mark_node;
4422 31505907 : if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
4423 0 : DECL_ATTRIBUTES (decl) = NULL_TREE;
4424 : }
4425 :
4426 : /* [dcl.link]
4427 :
4428 : A C language linkage is ignored for the names of class members
4429 : and the member function type of class member functions. */
4430 429798942 : if (DECL_LANG_SPECIFIC (decl))
4431 392277477 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
4432 :
4433 429798942 : bool add = false;
4434 :
4435 : /* Functions and non-functions are added differently. */
4436 429798942 : if (DECL_DECLARES_FUNCTION_P (decl))
4437 222013876 : add = add_method (current_class_type, decl, false);
4438 : /* Enter the DECL into the scope of the class, if the class
4439 : isn't a closure (whose fields are supposed to be unnamed). */
4440 207785066 : else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
4441 203886692 : || maybe_push_used_methods (decl)
4442 409739255 : || pushdecl_class_level (decl))
4443 : add = true;
4444 :
4445 222013876 : if (add)
4446 : {
4447 : /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
4448 : go at the beginning. The reason is that
4449 : legacy_nonfn_member_lookup searches the list in order, and we
4450 : want a field name to override a type name so that the "struct
4451 : stat hack" will work. In particular:
4452 :
4453 : struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
4454 :
4455 : is valid. */
4456 :
4457 429785589 : if (TREE_CODE (decl) == TYPE_DECL)
4458 147475287 : TYPE_FIELDS (current_class_type)
4459 294950574 : = chainon (TYPE_FIELDS (current_class_type), decl);
4460 : else
4461 : {
4462 282310302 : DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
4463 282310302 : TYPE_FIELDS (current_class_type) = decl;
4464 : }
4465 :
4466 429785589 : maybe_add_class_template_decl_list (current_class_type, decl,
4467 : /*friend_p=*/0);
4468 : }
4469 : }
4470 :
4471 : /* Finish processing a complete template declaration. The PARMS are
4472 : the template parameters. */
4473 :
4474 : void
4475 94787755 : finish_template_decl (tree parms)
4476 : {
4477 94787755 : if (parms)
4478 94787746 : end_template_decl ();
4479 : else
4480 9 : end_specialization ();
4481 94787755 : }
4482 :
4483 : // Returns the template type of the class scope being entered. If we're
4484 : // entering a constrained class scope. TYPE is the class template
4485 : // scope being entered and we may need to match the intended type with
4486 : // a constrained specialization. For example:
4487 : //
4488 : // template<Object T>
4489 : // struct S { void f(); }; #1
4490 : //
4491 : // template<Object T>
4492 : // void S<T>::f() { } #2
4493 : //
4494 : // We check, in #2, that S<T> refers precisely to the type declared by
4495 : // #1 (i.e., that the constraints match). Note that the following should
4496 : // be an error since there is no specialization of S<T> that is
4497 : // unconstrained, but this is not diagnosed here.
4498 : //
4499 : // template<typename T>
4500 : // void S<T>::f() { }
4501 : //
4502 : // We cannot diagnose this problem here since this function also matches
4503 : // qualified template names that are not part of a definition. For example:
4504 : //
4505 : // template<Integral T, Floating_point U>
4506 : // typename pair<T, U>::first_type void f(T, U);
4507 : //
4508 : // Here, it is unlikely that there is a partial specialization of
4509 : // pair constrained for Integral and Floating_point arguments.
4510 : //
4511 : // The general rule is: if a constrained specialization with matching
4512 : // constraints is found return that type. Also note that if TYPE is not a
4513 : // class-type (e.g. a typename type), then no fixup is needed.
4514 :
4515 : static tree
4516 18620063 : fixup_template_type (tree type)
4517 : {
4518 : // Find the template parameter list at the a depth appropriate to
4519 : // the scope we're trying to enter.
4520 18620063 : tree parms = current_template_parms;
4521 18620063 : int depth = template_class_depth (type);
4522 22872194 : for (int n = current_template_depth; n > depth && parms; --n)
4523 4252131 : parms = TREE_CHAIN (parms);
4524 18620063 : if (!parms)
4525 : return type;
4526 18620053 : tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
4527 18620053 : tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
4528 :
4529 : // Search for a specialization whose type and constraints match.
4530 18620053 : tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
4531 18620053 : tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
4532 36021338 : while (specs)
4533 : {
4534 17847967 : tree spec_constr = get_constraints (TREE_VALUE (specs));
4535 :
4536 : // If the type and constraints match a specialization, then we
4537 : // are entering that type.
4538 17847967 : if (same_type_p (type, TREE_TYPE (specs))
4539 17847967 : && equivalent_constraints (cur_constr, spec_constr))
4540 446682 : return TREE_TYPE (specs);
4541 17401285 : specs = TREE_CHAIN (specs);
4542 : }
4543 :
4544 : // If no specialization matches, then must return the type
4545 : // previously found.
4546 : return type;
4547 : }
4548 :
4549 : /* Finish processing a template-id (which names a type) of the form
4550 : NAME < ARGS >. Return the TYPE_DECL for the type named by the
4551 : template-id. If ENTERING_SCOPE is nonzero we are about to enter
4552 : the scope of template-id indicated. */
4553 :
4554 : tree
4555 192264064 : finish_template_type (tree name, tree args, int entering_scope)
4556 : {
4557 192264064 : tree type;
4558 :
4559 192264064 : type = lookup_template_class (name, args,
4560 : NULL_TREE, NULL_TREE,
4561 : tf_warning_or_error | tf_user);
4562 192264061 : if (entering_scope)
4563 19678012 : type = adjust_type_for_entering_scope (type);
4564 :
4565 : /* If we might be entering the scope of a partial specialization,
4566 : find the one with the right constraints. */
4567 192264061 : if (flag_concepts
4568 189498303 : && entering_scope
4569 19303679 : && CLASS_TYPE_P (type)
4570 19131256 : && CLASSTYPE_TEMPLATE_INFO (type)
4571 19131247 : && dependent_type_p (type)
4572 210884124 : && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
4573 18620063 : type = fixup_template_type (type);
4574 :
4575 192264061 : if (type == error_mark_node)
4576 : return type;
4577 192261771 : else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
4578 150919185 : return TYPE_STUB_DECL (type);
4579 : else
4580 41342586 : return TYPE_NAME (type);
4581 : }
4582 :
4583 : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER
4584 : and ANNOTATIONS.
4585 : Return a TREE_LIST containing the ACCESS_SPECIFIER (or if there are
4586 : ANNOTATIONS, TREE_LIST containing the ACCESS_SPECIFIER and ANNOTATIONS)
4587 : and the BASE_CLASS, or NULL_TREE if an error occurred. The
4588 : ACCESS_SPECIFIER is one of
4589 : access_{default,public,protected,private}_node. For a virtual base
4590 : we set TREE_TYPE. */
4591 :
4592 : tree
4593 11707812 : finish_base_specifier (tree base, tree access, bool virtual_p,
4594 : tree annotations)
4595 : {
4596 11707812 : tree result;
4597 :
4598 11707812 : if (base == error_mark_node)
4599 : {
4600 0 : error ("invalid base-class specification");
4601 0 : result = NULL_TREE;
4602 : }
4603 11707812 : else if (! MAYBE_CLASS_TYPE_P (base))
4604 : {
4605 3 : error ("%qT is not a class type", base);
4606 3 : result = NULL_TREE;
4607 : }
4608 : else
4609 : {
4610 11707809 : if (cp_type_quals (base) != 0)
4611 : {
4612 : /* DR 484: Can a base-specifier name a cv-qualified
4613 : class type? */
4614 12 : base = TYPE_MAIN_VARIANT (base);
4615 : }
4616 11707809 : if (annotations)
4617 18 : access = build_tree_list (access, nreverse (annotations));
4618 11707809 : result = build_tree_list (access, base);
4619 11707809 : if (virtual_p)
4620 26757 : TREE_TYPE (result) = integer_type_node;
4621 : }
4622 :
4623 11707812 : return result;
4624 : }
4625 :
4626 : /* If FNS is a member function, a set of member functions, or a
4627 : template-id referring to one or more member functions, return a
4628 : BASELINK for FNS, incorporating the current access context.
4629 : Otherwise, return FNS unchanged. If IGNORE_CURRENT_CLASS_P is
4630 : true, we do not consider the currently open derived class. */
4631 :
4632 : tree
4633 188431041 : baselink_for_fns (tree fns, bool ignore_current_class_p/*=false*/)
4634 : {
4635 188431041 : if (BASELINK_P (fns) || error_operand_p (fns))
4636 : return fns;
4637 :
4638 174219983 : tree scope = ovl_scope (fns);
4639 174219983 : if (!CLASS_TYPE_P (scope))
4640 : return fns;
4641 :
4642 9112308 : tree cl = (ignore_current_class_p
4643 9112308 : ? NULL_TREE
4644 9110568 : : currently_open_derived_class (scope));
4645 9110568 : if (!cl)
4646 : cl = scope;
4647 9112308 : tree access_path = TYPE_BINFO (cl);
4648 9112308 : tree conv_path = (cl == scope ? access_path
4649 730432 : : lookup_base (cl, scope, ba_any, NULL, tf_none));
4650 9112308 : return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
4651 : }
4652 :
4653 : /* Returns true iff we are currently parsing a lambda-declarator. */
4654 :
4655 : bool
4656 2024961655 : parsing_lambda_declarator ()
4657 : {
4658 2024961655 : cp_binding_level *b = current_binding_level;
4659 2027022585 : while (b->kind == sk_template_parms || b->kind == sk_function_parms)
4660 2060930 : b = b->level_chain;
4661 2024961655 : return b->kind == sk_lambda;
4662 : }
4663 :
4664 : /* Returns true iff DECL is a variable from a function outside
4665 : the current one. */
4666 :
4667 : static bool
4668 2702647826 : outer_var_p (tree decl)
4669 : {
4670 : /* These should have been stripped or otherwise handled by the caller. */
4671 2702647826 : gcc_checking_assert (!REFERENCE_REF_P (decl));
4672 :
4673 1776166755 : return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
4674 2482620018 : && DECL_FUNCTION_SCOPE_P (decl)
4675 : /* Don't get confused by temporaries. */
4676 2057600219 : && DECL_NAME (decl)
4677 4735908554 : && (DECL_CONTEXT (decl) != current_function_decl
4678 2022762128 : || parsing_nsdmi ()
4679 : /* Also consider captures as outer vars if we are in
4680 : decltype in a lambda declarator as in:
4681 : auto l = [j=0]() -> decltype((j)) { ... }
4682 : for the sake of finish_decltype_type.
4683 :
4684 : (Similar issue also affects non-lambdas, but vexing parse
4685 : makes it more difficult to handle than lambdas.) */
4686 2022760769 : || parsing_lambda_declarator ()));
4687 : }
4688 :
4689 : /* As above, but also checks that DECL is automatic. */
4690 :
4691 : bool
4692 2702647826 : outer_automatic_var_p (tree decl)
4693 : {
4694 2702647826 : return (outer_var_p (decl)
4695 2702647826 : && !TREE_STATIC (decl));
4696 : }
4697 :
4698 : /* Note whether capture proxy D is only used in a contract condition. */
4699 :
4700 : static void
4701 179256 : set_contract_capture_flag (tree d, bool val)
4702 : {
4703 179256 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (d));
4704 179256 : tree proxy = DECL_VALUE_EXPR (d);
4705 179256 : gcc_checking_assert (TREE_CODE (proxy) == COMPONENT_REF
4706 : && TREE_CODE (TREE_OPERAND (proxy, 1)) == FIELD_DECL);
4707 179256 : DECL_CONTRACT_CAPTURE_P (TREE_OPERAND (proxy, 1)) = val;
4708 179256 : }
4709 :
4710 : /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
4711 : rewrite it for lambda capture.
4712 :
4713 : If ODR_USE is true, we're being called from mark_use, and we complain about
4714 : use of constant variables. If ODR_USE is false, we're being called for the
4715 : id-expression, and we do lambda capture. */
4716 :
4717 : tree
4718 5407369 : process_outer_var_ref (tree decl, tsubst_flags_t complain,
4719 : bool odr_use/*=false*/)
4720 : {
4721 5413806 : bool in_typeid_probe = false;
4722 5413806 : if (cp_unevaluated_operand)
4723 : {
4724 3212742 : tree type = TREE_TYPE (decl);
4725 3212742 : if (!dependent_type_p (type)
4726 3212742 : && variably_modified_type_p (type, NULL_TREE))
4727 : /* VLAs are used even in unevaluated context. */;
4728 3212736 : else if (cp_unevaluated_operand > cp_unevaluated_typeid_cutoff)
4729 : /* It's not a use (3.2) if we're in an unevaluated context. */
4730 : return decl;
4731 : else
4732 : /* Inside a typeid operand's own probe: capture is still
4733 : attempted below ([expr.prim.lambda.capture]/7), but a missing
4734 : capture-default must not be diagnosed yet - see below. */
4735 : in_typeid_probe = true;
4736 : }
4737 2201133 : if (decl == error_mark_node)
4738 : return decl;
4739 :
4740 2201127 : tree context = DECL_CONTEXT (decl);
4741 2201127 : tree containing_function = current_function_decl;
4742 2201127 : tree lambda_stack = NULL_TREE;
4743 2201127 : tree lambda_expr = NULL_TREE;
4744 2201127 : tree initializer = convert_from_reference (decl);
4745 2201127 : tree var = strip_normal_capture_proxy (decl);
4746 :
4747 : /* Mark it as used now even if the use is ill-formed. */
4748 2201127 : if (!mark_used (decl, complain))
4749 3 : return error_mark_node;
4750 :
4751 2201124 : if (parsing_nsdmi () || parsing_lambda_declarator ())
4752 : containing_function = NULL_TREE;
4753 :
4754 4401353 : if (containing_function && LAMBDA_FUNCTION_P (containing_function))
4755 : {
4756 : /* Check whether we've already built a proxy. */
4757 2200572 : tree d = retrieve_local_specialization (var);
4758 :
4759 2200572 : if (d && d != decl && is_capture_proxy (d))
4760 : {
4761 1139290 : if (flag_contracts && !processing_contract_condition)
4762 : /* We might have created a capture for a contract_assert ref. to
4763 : some var, if that is now captured 'normally' then this is OK.
4764 : Otherwise we leave the capture marked as incorrect. */
4765 179250 : set_contract_capture_flag (d, false);
4766 1139290 : if (DECL_CONTEXT (d) == containing_function)
4767 : /* We already have an inner proxy. */
4768 : return d;
4769 : else
4770 : /* We need to capture an outer proxy. */
4771 : return process_outer_var_ref (d, complain, odr_use);
4772 : }
4773 : }
4774 :
4775 : /* If we are in a lambda function, we can move out until we hit
4776 : 1. the context,
4777 : 2. a non-lambda function, or
4778 : 3. a non-default capturing lambda function. */
4779 2129874 : while (context != containing_function
4780 : /* containing_function can be null with invalid generic lambdas. */
4781 2129874 : && containing_function
4782 3199332 : && LAMBDA_FUNCTION_P (containing_function))
4783 : {
4784 1069458 : tree closure = DECL_CONTEXT (containing_function);
4785 1069458 : lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
4786 :
4787 1069458 : if (TYPE_CLASS_SCOPE_P (closure))
4788 : /* A lambda in an NSDMI (c++/64496). */
4789 : break;
4790 :
4791 1069455 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4792 : break;
4793 :
4794 1068040 : lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
4795 :
4796 1068040 : containing_function = decl_function_context (containing_function);
4797 : }
4798 :
4799 : /* In a lambda within a template, wait until instantiation time to implicitly
4800 : capture a parameter pack. We want to wait because we don't know if we're
4801 : capturing the whole pack or a single element, and it's OK to wait because
4802 : find_parameter_packs_r walks into the lambda body. */
4803 1061834 : if (context == containing_function
4804 1061834 : && DECL_PACK_P (decl))
4805 : return decl;
4806 :
4807 1017332 : if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
4808 : {
4809 6 : if (complain & tf_error)
4810 6 : error ("cannot capture member %qD of anonymous union", decl);
4811 6 : return error_mark_node;
4812 : }
4813 : /* Do lambda capture when processing the id-expression, not when
4814 : odr-using a variable, but uses in a contract must not cause a capture. */
4815 1017326 : if (!odr_use && context == containing_function)
4816 : {
4817 1015356 : decl = add_default_capture (lambda_stack,
4818 1015356 : /*id=*/DECL_NAME (decl), initializer);
4819 1015356 : if (flag_contracts && processing_contract_condition)
4820 6 : set_contract_capture_flag (decl, true);
4821 : }
4822 : /* Capture was attempted above; whether it's really needed depends on
4823 : an evaluated-ness we don't know yet. Defer instead of diagnosing:
4824 : a later, non-probe pass will complain if the operand turns out
4825 : evaluated, and there's nothing to complain about if it doesn't. */
4826 1970 : else if (in_typeid_probe)
4827 : return var;
4828 : /* Only an odr-use of an outer automatic variable causes an
4829 : error, and a constant variable can decay to a prvalue
4830 : constant without odr-use. So don't complain yet. */
4831 1961 : else if (!odr_use && decl_constant_var_p (var))
4832 : return var;
4833 : /* Don't complain when DECL is dependent, because it can turn out to
4834 : be constant (and therefore needing no capture) when instantiating. */
4835 432 : else if (VAR_P (var) && instantiation_dependent_expression_p (var))
4836 : return var;
4837 414 : else if (lambda_expr)
4838 : {
4839 60 : if (complain & tf_error)
4840 : {
4841 56 : auto_diagnostic_group d;
4842 56 : error ("%qD is not captured", decl);
4843 56 : tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
4844 56 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4845 53 : inform (location_of (closure),
4846 : "the lambda has no capture-default");
4847 3 : else if (TYPE_CLASS_SCOPE_P (closure))
4848 3 : inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
4849 : "capture variables from the enclosing context",
4850 3 : TYPE_CONTEXT (closure));
4851 56 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4852 56 : }
4853 60 : return error_mark_node;
4854 : }
4855 354 : else if (processing_contract_condition && TREE_CODE (decl) == PARM_DECL)
4856 : /* Use of a parameter in a contract condition is fine. */
4857 : return decl;
4858 : else
4859 : {
4860 53 : if (complain & tf_error)
4861 : {
4862 39 : auto_diagnostic_group d;
4863 57 : error (VAR_P (decl)
4864 : ? G_("use of local variable with automatic storage from "
4865 : "containing function")
4866 : : G_("use of parameter from containing function"));
4867 39 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4868 39 : }
4869 53 : return error_mark_node;
4870 : }
4871 : return decl;
4872 : }
4873 :
4874 : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4875 : id-expression. (See cp_parser_id_expression for details.) SCOPE,
4876 : if non-NULL, is the type or namespace used to explicitly qualify
4877 : ID_EXPRESSION. DECL is the entity to which that name has been
4878 : resolved.
4879 :
4880 : *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4881 : constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4882 : be set to true if this expression isn't permitted in a
4883 : constant-expression, but it is otherwise not set by this function.
4884 : *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4885 : constant-expression, but a non-constant expression is also
4886 : permissible.
4887 :
4888 : DONE is true if this expression is a complete postfix-expression;
4889 : it is false if this expression is followed by '->', '[', '(', etc.
4890 : ADDRESS_P is true iff this expression is the operand of '&'.
4891 : TEMPLATE_P is true iff the qualified-id was of the form
4892 : "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4893 : appears as a template argument.
4894 :
4895 : If an error occurs, and it is the kind of error that might cause
4896 : the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4897 : is the caller's responsibility to issue the message. *ERROR_MSG
4898 : will be a string with static storage duration, so the caller need
4899 : not "free" it.
4900 :
4901 : Return an expression for the entity, after issuing appropriate
4902 : diagnostics. This function is also responsible for transforming a
4903 : reference to a non-static member into a COMPONENT_REF that makes
4904 : the use of "this" explicit.
4905 :
4906 : Upon return, *IDK will be filled in appropriately. */
4907 : static cp_expr
4908 801874433 : finish_id_expression_1 (tree id_expression,
4909 : tree decl,
4910 : tree scope,
4911 : cp_id_kind *idk,
4912 : bool integral_constant_expression_p,
4913 : bool allow_non_integral_constant_expression_p,
4914 : bool *non_integral_constant_expression_p,
4915 : bool template_p,
4916 : bool done,
4917 : bool address_p,
4918 : bool template_arg_p,
4919 : const char **error_msg,
4920 : location_t location)
4921 : {
4922 801874433 : decl = strip_using_decl (decl);
4923 :
4924 : /* Initialize the output parameters. */
4925 801874433 : *idk = CP_ID_KIND_NONE;
4926 801874433 : *error_msg = NULL;
4927 :
4928 801874433 : if (id_expression == error_mark_node)
4929 12 : return error_mark_node;
4930 : /* If we have a template-id, then no further lookup is
4931 : required. If the template-id was for a template-class, we
4932 : will sometimes have a TYPE_DECL at this point. */
4933 801874421 : else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4934 745936750 : || TREE_CODE (decl) == TYPE_DECL)
4935 : ;
4936 : /* Look up the name. */
4937 : else
4938 : {
4939 745935827 : if (decl == error_mark_node)
4940 : {
4941 : /* Name lookup failed. */
4942 133079 : if (scope
4943 374 : && !dependent_namespace_p (scope)
4944 133453 : && (!TYPE_P (scope)
4945 119 : || (!dependentish_scope_p (scope)
4946 115 : && !(identifier_p (id_expression)
4947 100 : && IDENTIFIER_CONV_OP_P (id_expression)
4948 3 : && dependent_type_p (TREE_TYPE (id_expression))))))
4949 : {
4950 : /* If the qualifying type is non-dependent (and the name
4951 : does not name a conversion operator to a dependent
4952 : type), issue an error. */
4953 364 : qualified_name_lookup_error (scope, id_expression, decl, location);
4954 364 : return error_mark_node;
4955 : }
4956 132715 : else if (!scope)
4957 : {
4958 : /* It may be resolved via Koenig lookup. */
4959 132705 : *idk = CP_ID_KIND_UNQUALIFIED;
4960 132705 : return id_expression;
4961 : }
4962 : else
4963 : decl = id_expression;
4964 : }
4965 :
4966 : /* Remember that the name was used in the definition of
4967 : the current class so that we can check later to see if
4968 : the meaning would have been different after the class
4969 : was entirely defined. */
4970 745802748 : if (!scope && decl != error_mark_node && identifier_p (id_expression))
4971 666906065 : maybe_note_name_used_in_class (id_expression, decl);
4972 :
4973 : /* A use in unevaluated operand might not be instantiated appropriately
4974 : if tsubst_copy builds a dummy parm, or if we never instantiate a
4975 : generic lambda, so mark it now. */
4976 745802758 : if (processing_template_decl
4977 745802758 : && (cp_unevaluated_operand
4978 644978645 : || generic_lambda_fn_p (current_function_decl)))
4979 20855942 : mark_type_use (decl);
4980 :
4981 : /* Disallow uses of local variables from containing functions, except
4982 : within lambda-expressions. */
4983 745802758 : if (outer_automatic_var_p (decl))
4984 : {
4985 3855279 : decl = process_outer_var_ref (decl, tf_warning_or_error);
4986 3855279 : if (decl == error_mark_node)
4987 92 : return error_mark_node;
4988 : }
4989 :
4990 : /* Also disallow uses of function parameters outside the function
4991 : body, except inside an unevaluated context (i.e. decltype). */
4992 745802666 : if (TREE_CODE (decl) == PARM_DECL
4993 311377598 : && DECL_CONTEXT (decl) == NULL_TREE
4994 8456985 : && !CONSTRAINT_VAR_P (decl)
4995 4536979 : && !cp_unevaluated_operand
4996 595 : && !processing_contract_condition
4997 745802722 : && !processing_omp_trait_property_expr)
4998 : {
4999 38 : *error_msg = G_("use of parameter outside function body");
5000 38 : return error_mark_node;
5001 : }
5002 : }
5003 :
5004 : /* If we didn't find anything, or what we found was a type,
5005 : then this wasn't really an id-expression. */
5006 801741222 : if (TREE_CODE (decl) == TEMPLATE_DECL
5007 801741222 : && !DECL_FUNCTION_TEMPLATE_P (decl))
5008 : {
5009 51 : *error_msg = G_("missing template arguments");
5010 51 : return error_mark_node;
5011 : }
5012 801741171 : else if (TREE_CODE (decl) == TYPE_DECL
5013 801740248 : || TREE_CODE (decl) == NAMESPACE_DECL)
5014 : {
5015 938 : *error_msg = G_("expected primary-expression");
5016 938 : return error_mark_node;
5017 : }
5018 :
5019 : /* If the name resolved to a template parameter, there is no
5020 : need to look it up again later. */
5021 33975887 : if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
5022 815892490 : || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
5023 : {
5024 19823630 : tree r;
5025 :
5026 19823630 : *idk = CP_ID_KIND_NONE;
5027 19823630 : if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
5028 0 : decl = TEMPLATE_PARM_DECL (decl);
5029 19823630 : r = DECL_INITIAL (decl);
5030 19823630 : if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
5031 : {
5032 : /* If the entity is a template parameter object for a template
5033 : parameter of type T, the type of the expression is const T. */
5034 2969 : tree ctype = TREE_TYPE (r);
5035 2969 : ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
5036 : | TYPE_QUAL_CONST));
5037 2969 : r = build1 (VIEW_CONVERT_EXPR, ctype, r);
5038 : }
5039 19823630 : r = convert_from_reference (r);
5040 19823630 : if (integral_constant_expression_p
5041 3454632 : && !dependent_type_p (TREE_TYPE (decl))
5042 22773114 : && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
5043 : {
5044 1023 : if (!allow_non_integral_constant_expression_p)
5045 6 : error ("template parameter %qD of type %qT is not allowed in "
5046 : "an integral constant expression because it is not of "
5047 6 : "integral or enumeration type", decl, TREE_TYPE (decl));
5048 1023 : *non_integral_constant_expression_p = true;
5049 : }
5050 :
5051 19823630 : if (flag_contracts && processing_contract_condition)
5052 27 : r = constify_contract_access (r);
5053 :
5054 19823630 : return r;
5055 : }
5056 781916603 : else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
5057 : {
5058 9 : gcc_checking_assert (scope);
5059 9 : *idk = CP_ID_KIND_QUALIFIED;
5060 9 : cp_warn_deprecated_use_scopes (scope);
5061 9 : decl = finish_qualified_id_expr (scope, decl, done, address_p,
5062 : template_p, template_arg_p,
5063 : tf_warning_or_error);
5064 : }
5065 : else
5066 : {
5067 781916594 : if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
5068 55937671 : && variable_template_p (TREE_OPERAND (decl, 0))
5069 794605787 : && !concept_check_p (decl))
5070 : /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
5071 : considered type-dependent) now, so that the dependence test that
5072 : follows gives us the right answer: if it represents a non-dependent
5073 : variable template-id then finish_template_variable will yield the
5074 : corresponding non-dependent VAR_DECL. */
5075 12689193 : decl = finish_template_variable (decl);
5076 :
5077 781916594 : bool dependent_p = type_dependent_expression_p (decl);
5078 :
5079 : /* If the declaration was explicitly qualified indicate
5080 : that. The semantics of `A::f(3)' are different than
5081 : `f(3)' if `f' is virtual. */
5082 1563833188 : *idk = (scope
5083 781916594 : ? CP_ID_KIND_QUALIFIED
5084 680184157 : : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
5085 680184157 : ? CP_ID_KIND_TEMPLATE_ID
5086 : : (dependent_p
5087 647376285 : ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
5088 : : CP_ID_KIND_UNQUALIFIED)));
5089 :
5090 781916594 : if (dependent_p
5091 781916594 : && !scope
5092 448608239 : && DECL_P (decl)
5093 1198809351 : && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
5094 : /* Dependent type attributes on the decl mean that the TREE_TYPE is
5095 : wrong, so just return the identifier. */
5096 39 : return id_expression;
5097 :
5098 781916555 : if (DECL_CLASS_TEMPLATE_P (decl))
5099 : {
5100 0 : error ("use of class template %qT as expression", decl);
5101 0 : return error_mark_node;
5102 : }
5103 :
5104 781916555 : if (TREE_CODE (decl) == TREE_LIST)
5105 : {
5106 : /* Ambiguous reference to base members. */
5107 0 : auto_diagnostic_group d;
5108 0 : error ("request for member %qD is ambiguous in "
5109 : "multiple inheritance lattice", id_expression);
5110 0 : print_candidates (input_location, decl);
5111 0 : return error_mark_node;
5112 0 : }
5113 :
5114 : /* Mark variable-like entities as used. Functions are similarly
5115 : marked either below or after overload resolution. */
5116 781916555 : if ((VAR_P (decl)
5117 567135802 : || TREE_CODE (decl) == PARM_DECL
5118 255758248 : || TREE_CODE (decl) == CONST_DECL
5119 241605991 : || TREE_CODE (decl) == RESULT_DECL)
5120 1107446366 : && !mark_used (decl))
5121 12 : return error_mark_node;
5122 :
5123 : /* Only certain kinds of names are allowed in constant
5124 : expression. Template parameters have already
5125 : been handled above. */
5126 781916540 : if (! error_operand_p (decl)
5127 781916214 : && !dependent_p
5128 781916214 : && integral_constant_expression_p
5129 78682017 : && !decl_constant_var_p (decl)
5130 63965592 : && TREE_CODE (decl) != CONST_DECL
5131 55263703 : && !builtin_valid_in_constant_expr_p (decl)
5132 837130021 : && !concept_check_p (decl))
5133 : {
5134 54636604 : if (!allow_non_integral_constant_expression_p)
5135 : {
5136 30 : error ("%qD cannot appear in a constant-expression", decl);
5137 30 : return error_mark_node;
5138 : }
5139 54636574 : *non_integral_constant_expression_p = true;
5140 : }
5141 :
5142 781916510 : if (tree wrap = maybe_get_tls_wrapper_call (decl))
5143 : /* Replace an evaluated use of the thread_local variable with
5144 : a call to its wrapper. */
5145 : decl = wrap;
5146 781915998 : else if (concept_check_p (decl))
5147 : {
5148 : /* Nothing more to do. All of the analysis for concept checks
5149 : is done by build_conept_id, called from the parser. */
5150 : }
5151 764689809 : else if (scope)
5152 : {
5153 99758852 : if (TREE_CODE (decl) == SCOPE_REF)
5154 : {
5155 91299 : gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
5156 91299 : decl = TREE_OPERAND (decl, 1);
5157 : }
5158 :
5159 99758852 : decl = (adjust_result_of_qualified_name_lookup
5160 99758852 : (decl, scope, current_nonlambda_class_type()));
5161 :
5162 99758852 : cp_warn_deprecated_use_scopes (scope);
5163 :
5164 99758852 : if (TYPE_P (scope))
5165 14132840 : decl = finish_qualified_id_expr (scope,
5166 : decl,
5167 : done,
5168 : address_p,
5169 : template_p,
5170 : template_arg_p,
5171 : tf_warning_or_error);
5172 : else
5173 85626012 : decl = convert_from_reference (decl);
5174 : }
5175 664930957 : else if (TREE_CODE (decl) == FIELD_DECL)
5176 : {
5177 69077831 : if (flag_contracts && processing_contract_condition
5178 37 : && contract_class_ptr == current_class_ptr)
5179 : {
5180 6 : error ("%qD 'this' required when accessing a member within a "
5181 : "constructor precondition or destructor postcondition "
5182 : "contract check", decl);
5183 6 : return error_mark_node;
5184 : }
5185 : /* Since SCOPE is NULL here, this is an unqualified name.
5186 : Access checking has been performed during name lookup
5187 : already. Turn off checking to avoid duplicate errors. */
5188 69077825 : push_deferring_access_checks (dk_no_check);
5189 69077825 : decl = finish_non_static_data_member (decl, NULL_TREE,
5190 : /*qualifying_scope=*/NULL_TREE);
5191 69077825 : pop_deferring_access_checks ();
5192 : }
5193 595853126 : else if (is_overloaded_fn (decl))
5194 : {
5195 : /* We only need to look at the first function,
5196 : because all the fns share the attribute we're
5197 : concerned with (all member fns or all non-members). */
5198 63921652 : tree first_fn = get_first_fn (decl);
5199 63921652 : first_fn = STRIP_TEMPLATE (first_fn);
5200 :
5201 63921652 : if (!template_arg_p
5202 63921652 : && (TREE_CODE (first_fn) == USING_DECL
5203 63919764 : || (TREE_CODE (first_fn) == FUNCTION_DECL
5204 63919764 : && DECL_FUNCTION_MEMBER_P (first_fn)
5205 39041334 : && !shared_member_p (decl))))
5206 : {
5207 : /* A set of member functions. */
5208 30053490 : if (flag_contracts && processing_contract_condition
5209 24 : && contract_class_ptr == current_class_ptr)
5210 : {
5211 3 : error ("%qD 'this' required when accessing a member within a "
5212 : "constructor precondition or destructor postcondition "
5213 : "contract check", decl);
5214 3 : return error_mark_node;
5215 : }
5216 30053487 : decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
5217 30053487 : return finish_class_member_access_expr (decl, id_expression,
5218 : /*template_p=*/false,
5219 30053487 : tf_warning_or_error);
5220 : }
5221 :
5222 33868162 : decl = baselink_for_fns (decl);
5223 : }
5224 : else
5225 : {
5226 520207019 : if (DECL_P (decl) && DECL_NONLOCAL (decl)
5227 533464637 : && DECL_CLASS_SCOPE_P (decl))
5228 : {
5229 1533163 : tree context = context_for_name_lookup (decl);
5230 1533163 : if (context != current_class_type)
5231 : {
5232 801583 : tree path = currently_open_derived_class (context);
5233 801583 : if (!path)
5234 : /* PATH can be null for using an enum of an unrelated
5235 : class; we checked its access in lookup_using_decl.
5236 :
5237 : ??? Should this case make a clone instead, like
5238 : handle_using_decl? */
5239 43 : gcc_assert (TREE_CODE (decl) == CONST_DECL
5240 : /* This is for:
5241 : constexpr auto r = ^^S::i;
5242 : auto a = [:r:]; */
5243 : || flag_reflection);
5244 : else
5245 801540 : perform_or_defer_access_check (TYPE_BINFO (path),
5246 : decl, decl,
5247 : tf_warning_or_error);
5248 : }
5249 : }
5250 :
5251 531931474 : decl = convert_from_reference (decl);
5252 : }
5253 : }
5254 :
5255 751863023 : check_param_in_postcondition (decl, location);
5256 751863023 : if (flag_contracts && processing_contract_condition)
5257 2109 : decl = constify_contract_access (decl);
5258 :
5259 751863023 : return cp_expr (decl, location);
5260 : }
5261 :
5262 : /* As per finish_id_expression_1, but adding a wrapper node
5263 : around the result if needed to express LOCATION. */
5264 :
5265 : cp_expr
5266 801874433 : finish_id_expression (tree id_expression,
5267 : tree decl,
5268 : tree scope,
5269 : cp_id_kind *idk,
5270 : bool integral_constant_expression_p,
5271 : bool allow_non_integral_constant_expression_p,
5272 : bool *non_integral_constant_expression_p,
5273 : bool template_p,
5274 : bool done,
5275 : bool address_p,
5276 : bool template_arg_p,
5277 : const char **error_msg,
5278 : location_t location)
5279 : {
5280 801874433 : cp_expr result
5281 801874433 : = finish_id_expression_1 (id_expression, decl, scope, idk,
5282 : integral_constant_expression_p,
5283 : allow_non_integral_constant_expression_p,
5284 : non_integral_constant_expression_p,
5285 : template_p, done, address_p, template_arg_p,
5286 : error_msg, location);
5287 801874430 : return result.maybe_add_location_wrapper ();
5288 : }
5289 :
5290 : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
5291 : use as a type-specifier. */
5292 :
5293 : tree
5294 22064047 : finish_typeof (tree expr)
5295 : {
5296 22064047 : tree type;
5297 :
5298 22064047 : if (type_dependent_expression_p (expr))
5299 : {
5300 21970884 : type = cxx_make_type (TYPEOF_TYPE);
5301 21970884 : TYPEOF_TYPE_EXPR (type) = expr;
5302 21970884 : SET_TYPE_STRUCTURAL_EQUALITY (type);
5303 :
5304 21970884 : return type;
5305 : }
5306 :
5307 93163 : expr = mark_type_use (expr);
5308 :
5309 93163 : type = unlowered_expr_type (expr);
5310 :
5311 93163 : if (!type || type == unknown_type_node)
5312 : {
5313 3 : error ("type of %qE is unknown", expr);
5314 3 : return error_mark_node;
5315 : }
5316 :
5317 : return type;
5318 : }
5319 :
5320 : /* Implement the __underlying_type keyword: Return the underlying
5321 : type of TYPE, suitable for use as a type-specifier. */
5322 :
5323 : tree
5324 48915 : finish_underlying_type (tree type)
5325 : {
5326 48915 : if (!complete_type_or_else (type, NULL_TREE))
5327 3 : return error_mark_node;
5328 :
5329 48912 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5330 : {
5331 24 : error ("%qT is not an enumeration type", type);
5332 24 : return error_mark_node;
5333 : }
5334 :
5335 48888 : tree underlying_type = ENUM_UNDERLYING_TYPE (type);
5336 :
5337 : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5338 : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5339 : See finish_enum_value_list for details. */
5340 48888 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5341 56 : underlying_type
5342 56 : = c_common_type_for_mode (TYPE_MODE (underlying_type),
5343 56 : TYPE_UNSIGNED (underlying_type));
5344 :
5345 : return underlying_type;
5346 : }
5347 :
5348 : /* Implement the __type_pack_element keyword: Return the type
5349 : at index IDX within TYPES. */
5350 :
5351 : static tree
5352 135759 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
5353 : {
5354 135759 : idx = maybe_constant_value (idx, NULL_TREE, mce_true);
5355 135759 : if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
5356 : {
5357 6 : if (complain & tf_error)
5358 3 : error ("pack index has non-integral type %qT", TREE_TYPE (idx));
5359 6 : return error_mark_node;
5360 : }
5361 135753 : if (TREE_CODE (idx) != INTEGER_CST)
5362 : {
5363 2 : if (complain & tf_error)
5364 : {
5365 2 : error ("pack index is not an integral constant");
5366 2 : cxx_constant_value (idx);
5367 : }
5368 2 : return error_mark_node;
5369 : }
5370 135751 : if (tree_int_cst_sgn (idx) < 0)
5371 : {
5372 3 : if (complain & tf_error)
5373 3 : error ("pack index %qE is negative", idx);
5374 3 : return error_mark_node;
5375 : }
5376 135748 : if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
5377 : {
5378 35 : if (complain & tf_error)
5379 29 : error ("pack index %qE is out of range for pack of length %qd",
5380 29 : idx, TREE_VEC_LENGTH (types));
5381 35 : return error_mark_node;
5382 : }
5383 135713 : return TREE_VEC_ELT (types, tree_to_shwi (idx));
5384 : }
5385 :
5386 : /* In a pack-index T...[N], return the element at index IDX within TYPES.
5387 : PARENTHESIZED_P is true iff the pack index was wrapped in (). */
5388 :
5389 : tree
5390 22552 : pack_index_element (tree idx, tree types, bool parenthesized_p,
5391 : tsubst_flags_t complain)
5392 : {
5393 22552 : tree r = finish_type_pack_element (idx, types, complain);
5394 22552 : if (parenthesized_p)
5395 : /* For the benefit of decltype(auto). */
5396 35 : r = force_paren_expr (r);
5397 22552 : return r;
5398 : }
5399 :
5400 : /* Implement the __direct_bases keyword: Return the direct base classes
5401 : of type. */
5402 :
5403 : tree
5404 15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
5405 : {
5406 15 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5407 15 : || !NON_UNION_CLASS_TYPE_P (type))
5408 8 : return make_tree_vec (0);
5409 :
5410 7 : releasing_vec vector;
5411 7 : vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
5412 7 : tree binfo;
5413 7 : unsigned i;
5414 :
5415 : /* Virtual bases are initialized first */
5416 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5417 13 : if (BINFO_VIRTUAL_P (binfo))
5418 2 : vec_safe_push (vector, binfo);
5419 :
5420 : /* Now non-virtuals */
5421 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5422 13 : if (!BINFO_VIRTUAL_P (binfo))
5423 11 : vec_safe_push (vector, binfo);
5424 :
5425 7 : tree bases_vec = make_tree_vec (vector->length ());
5426 :
5427 27 : for (i = 0; i < vector->length (); ++i)
5428 13 : TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
5429 :
5430 7 : return bases_vec;
5431 7 : }
5432 :
5433 : /* Implement the __bases keyword: Return the base classes
5434 : of type */
5435 :
5436 : /* Find morally non-virtual base classes by walking binfo hierarchy */
5437 : /* Virtual base classes are handled separately in finish_bases */
5438 :
5439 : static tree
5440 73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
5441 : {
5442 : /* Don't walk bases of virtual bases */
5443 73 : return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
5444 : }
5445 :
5446 : static tree
5447 73 : dfs_calculate_bases_post (tree binfo, void *data_)
5448 : {
5449 73 : vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
5450 73 : if (!BINFO_VIRTUAL_P (binfo))
5451 48 : vec_safe_push (*data, BINFO_TYPE (binfo));
5452 73 : return NULL_TREE;
5453 : }
5454 :
5455 : /* Calculates the morally non-virtual base classes of a class */
5456 : static vec<tree, va_gc> *
5457 16 : calculate_bases_helper (tree type)
5458 : {
5459 16 : vec<tree, va_gc> *vector = make_tree_vector ();
5460 :
5461 : /* Now add non-virtual base classes in order of construction */
5462 16 : if (TYPE_BINFO (type))
5463 16 : dfs_walk_all (TYPE_BINFO (type),
5464 : dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
5465 16 : return vector;
5466 : }
5467 :
5468 : tree
5469 12 : calculate_bases (tree type, tsubst_flags_t complain)
5470 : {
5471 12 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5472 12 : || !NON_UNION_CLASS_TYPE_P (type))
5473 5 : return make_tree_vec (0);
5474 :
5475 7 : releasing_vec vector;
5476 7 : tree bases_vec = NULL_TREE;
5477 7 : unsigned i;
5478 7 : vec<tree, va_gc> *vbases;
5479 7 : tree binfo;
5480 :
5481 : /* First go through virtual base classes */
5482 7 : for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
5483 16 : vec_safe_iterate (vbases, i, &binfo); i++)
5484 : {
5485 9 : releasing_vec vbase_bases
5486 9 : = calculate_bases_helper (BINFO_TYPE (binfo));
5487 9 : vec_safe_splice (vector, vbase_bases);
5488 9 : }
5489 :
5490 : /* Now for the non-virtual bases */
5491 7 : releasing_vec nonvbases = calculate_bases_helper (type);
5492 7 : vec_safe_splice (vector, nonvbases);
5493 :
5494 : /* Note that during error recovery vector->length can even be zero. */
5495 7 : if (vector->length () > 1)
5496 : {
5497 : /* Last element is entire class, so don't copy */
5498 6 : bases_vec = make_tree_vec (vector->length () - 1);
5499 :
5500 53 : for (i = 0; i < vector->length () - 1; ++i)
5501 41 : TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
5502 : }
5503 : else
5504 1 : bases_vec = make_tree_vec (0);
5505 :
5506 7 : return bases_vec;
5507 7 : }
5508 :
5509 : tree
5510 28 : finish_bases (tree type, bool direct)
5511 : {
5512 28 : tree bases = NULL_TREE;
5513 :
5514 28 : if (!processing_template_decl)
5515 : {
5516 : /* Parameter packs can only be used in templates */
5517 0 : error ("parameter pack %<__bases%> only valid in template declaration");
5518 0 : return error_mark_node;
5519 : }
5520 :
5521 28 : bases = cxx_make_type (BASES);
5522 28 : BASES_TYPE (bases) = type;
5523 28 : BASES_DIRECT (bases) = direct;
5524 28 : SET_TYPE_STRUCTURAL_EQUALITY (bases);
5525 :
5526 28 : return bases;
5527 : }
5528 :
5529 : /* Perform C++-specific checks for __builtin_offsetof before calling
5530 : fold_offsetof. */
5531 :
5532 : tree
5533 2419 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
5534 : {
5535 : /* If we're processing a template, we can't finish the semantics yet.
5536 : Otherwise we can fold the entire expression now. */
5537 2419 : if (processing_template_decl)
5538 : {
5539 60 : expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
5540 60 : SET_EXPR_LOCATION (expr, loc);
5541 60 : return expr;
5542 : }
5543 :
5544 2359 : if (expr == error_mark_node)
5545 : return error_mark_node;
5546 :
5547 2342 : if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
5548 : {
5549 6 : error ("cannot apply %<offsetof%> to destructor %<~%T%>",
5550 6 : TREE_OPERAND (expr, 2));
5551 6 : return error_mark_node;
5552 : }
5553 4657 : if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
5554 4657 : || TREE_TYPE (expr) == unknown_type_node)
5555 : {
5556 30 : while (TREE_CODE (expr) == COMPONENT_REF
5557 30 : || TREE_CODE (expr) == COMPOUND_EXPR)
5558 12 : expr = TREE_OPERAND (expr, 1);
5559 :
5560 18 : if (DECL_P (expr))
5561 : {
5562 0 : auto_diagnostic_group d;
5563 0 : error ("cannot apply %<offsetof%> to member function %qD", expr);
5564 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
5565 0 : }
5566 : else
5567 18 : error ("cannot apply %<offsetof%> to member function");
5568 18 : return error_mark_node;
5569 : }
5570 2318 : if (TREE_CODE (expr) == CONST_DECL)
5571 : {
5572 3 : error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
5573 3 : return error_mark_node;
5574 : }
5575 2315 : if (REFERENCE_REF_P (expr))
5576 9 : expr = TREE_OPERAND (expr, 0);
5577 2315 : if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
5578 3 : return error_mark_node;
5579 2312 : if (warn_invalid_offsetof
5580 2312 : && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
5581 2312 : && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
5582 2357 : && cp_unevaluated_operand == 0)
5583 45 : warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
5584 : "non-standard-layout type %qT is conditionally-supported",
5585 45 : TREE_TYPE (TREE_TYPE (object_ptr)));
5586 2312 : return fold_offsetof (expr);
5587 : }
5588 :
5589 : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
5590 : function is broken out from the above for the benefit of the tree-ssa
5591 : project. */
5592 :
5593 : void
5594 365452 : simplify_aggr_init_expr (tree *tp)
5595 : {
5596 365452 : tree aggr_init_expr = *tp;
5597 :
5598 : /* Form an appropriate CALL_EXPR. */
5599 365452 : tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
5600 365452 : tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
5601 365452 : tree type = TREE_TYPE (slot);
5602 :
5603 365452 : tree call_expr;
5604 365452 : enum style_t { ctor, arg, pcc } style;
5605 :
5606 365452 : if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
5607 : style = ctor;
5608 : #ifdef PCC_STATIC_STRUCT_RETURN
5609 : else if (1)
5610 : style = pcc;
5611 : #endif
5612 : else
5613 : {
5614 97040 : gcc_assert (TREE_ADDRESSABLE (type));
5615 : style = arg;
5616 : }
5617 :
5618 365452 : call_expr = build_call_array_loc (input_location,
5619 365452 : TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
5620 : fn,
5621 365452 : aggr_init_expr_nargs (aggr_init_expr),
5622 365452 : AGGR_INIT_EXPR_ARGP (aggr_init_expr));
5623 365452 : TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
5624 365452 : CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
5625 365452 : CALL_EXPR_OPERATOR_SYNTAX (call_expr)
5626 365452 : = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
5627 365452 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
5628 365452 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
5629 365452 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
5630 :
5631 365452 : if (style == ctor)
5632 : {
5633 : /* Replace the first argument to the ctor with the address of the
5634 : slot. */
5635 268412 : cxx_mark_addressable (slot);
5636 268412 : CALL_EXPR_ARG (call_expr, 0) =
5637 268412 : build1 (ADDR_EXPR, build_pointer_type (type), slot);
5638 : }
5639 97040 : else if (style == arg)
5640 : {
5641 : /* Just mark it addressable here, and leave the rest to
5642 : expand_call{,_inline}. */
5643 97040 : cxx_mark_addressable (slot);
5644 97040 : CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
5645 97040 : call_expr = cp_build_init_expr (slot, call_expr);
5646 : }
5647 : else if (style == pcc)
5648 : {
5649 : /* If we're using the non-reentrant PCC calling convention, then we
5650 : need to copy the returned value out of the static buffer into the
5651 : SLOT. */
5652 : push_deferring_access_checks (dk_no_check);
5653 : call_expr = build_aggr_init (slot, call_expr,
5654 : DIRECT_BIND | LOOKUP_ONLYCONVERTING,
5655 : tf_warning_or_error);
5656 : pop_deferring_access_checks ();
5657 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
5658 : }
5659 :
5660 365452 : if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
5661 : {
5662 4152 : tree init = build_zero_init (type, NULL_TREE,
5663 : /*static_storage_p=*/false);
5664 4152 : init = cp_build_init_expr (slot, init);
5665 4152 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
5666 : init, call_expr);
5667 : }
5668 :
5669 365452 : *tp = call_expr;
5670 365452 : }
5671 :
5672 : /* Emit all thunks to FN that should be emitted when FN is emitted. */
5673 :
5674 : void
5675 61597179 : emit_associated_thunks (tree fn)
5676 : {
5677 : /* When we use vcall offsets, we emit thunks with the virtual
5678 : functions to which they thunk. The whole point of vcall offsets
5679 : is so that you can know statically the entire set of thunks that
5680 : will ever be needed for a given virtual function, thereby
5681 : enabling you to output all the thunks with the function itself. */
5682 61597179 : if (DECL_VIRTUAL_P (fn)
5683 : /* Do not emit thunks for extern template instantiations. */
5684 1171757 : && ! DECL_REALLY_EXTERN (fn)
5685 : /* Do not emit thunks for tentative decls, those will be processed
5686 : again at_eof if really needed. */
5687 62651847 : && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
5688 : {
5689 1053568 : tree thunk;
5690 :
5691 1057998 : for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
5692 : {
5693 4430 : if (!THUNK_ALIAS (thunk))
5694 : {
5695 4430 : use_thunk (thunk, /*emit_p=*/1);
5696 4430 : if (DECL_RESULT_THUNK_P (thunk))
5697 : {
5698 181 : tree probe;
5699 :
5700 181 : for (probe = DECL_THUNKS (thunk);
5701 333 : probe; probe = DECL_CHAIN (probe))
5702 152 : use_thunk (probe, /*emit_p=*/1);
5703 : }
5704 : }
5705 : else
5706 0 : gcc_assert (!DECL_THUNKS (thunk));
5707 : }
5708 : }
5709 61597179 : }
5710 :
5711 : /* Generate RTL for FN. */
5712 :
5713 : bool
5714 167392030 : expand_or_defer_fn_1 (tree fn)
5715 : {
5716 : /* When the parser calls us after finishing the body of a template
5717 : function, we don't really want to expand the body. */
5718 167392030 : if (processing_template_decl)
5719 : {
5720 : /* Normally, collection only occurs in rest_of_compilation. So,
5721 : if we don't collect here, we never collect junk generated
5722 : during the processing of templates until we hit a
5723 : non-template function. It's not safe to do this inside a
5724 : nested class, though, as the parser may have local state that
5725 : is not a GC root. */
5726 97560589 : if (!function_depth)
5727 97096214 : ggc_collect ();
5728 : return false;
5729 : }
5730 :
5731 69831441 : gcc_assert (DECL_SAVED_TREE (fn));
5732 :
5733 : /* We make a decision about linkage for these functions at the end
5734 : of the compilation. Until that point, we do not want the back
5735 : end to output them -- but we do want it to see the bodies of
5736 : these functions so that it can inline them as appropriate. */
5737 69831441 : if (DECL_DECLARED_INLINE_P (fn)
5738 1959946 : || DECL_IMPLICIT_INSTANTIATION (fn)
5739 70095747 : || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (fn))
5740 : {
5741 69567162 : if (DECL_INTERFACE_KNOWN (fn))
5742 : /* We've already made a decision as to how this function will
5743 : be handled. */;
5744 49210392 : else if (!at_eof
5745 17730000 : || DECL_IMMEDIATE_FUNCTION_P (fn)
5746 66490871 : || DECL_OMP_DECLARE_REDUCTION_P (fn))
5747 31929913 : tentative_decl_linkage (fn);
5748 : else
5749 17280479 : import_export_decl (fn);
5750 :
5751 : /* If the user wants us to keep all inline functions, then mark
5752 : this function as needed so that finish_file will make sure to
5753 : output it later. Similarly, all dllexport'd functions must
5754 : be emitted; there may be callers in other DLLs. */
5755 69567162 : if (DECL_DECLARED_INLINE_P (fn)
5756 67871495 : && !DECL_REALLY_EXTERN (fn)
5757 64114943 : && !DECL_IMMEDIATE_FUNCTION_P (fn)
5758 62997177 : && !DECL_OMP_DECLARE_REDUCTION_P (fn)
5759 132564339 : && (flag_keep_inline_functions
5760 62994387 : || (flag_keep_inline_dllexport
5761 62994387 : && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
5762 : {
5763 2790 : mark_needed (fn);
5764 2790 : DECL_EXTERNAL (fn) = 0;
5765 : }
5766 : }
5767 :
5768 : /* If this is a constructor or destructor body, we have to clone
5769 : it. */
5770 69831441 : if (maybe_clone_body (fn))
5771 : {
5772 : /* We don't want to process FN again, so pretend we've written
5773 : it out, even though we haven't. */
5774 8206062 : TREE_ASM_WRITTEN (fn) = 1;
5775 : /* If this is a constexpr function we still need the body to be
5776 : able to evaluate it. Similarly, with modules we only stream
5777 : the maybe-in-charge cdtor and regenerate the clones from it on
5778 : demand, so we also need to keep the body. Otherwise we don't
5779 : need it anymore. */
5780 8206062 : if (!maybe_constexpr_fn (fn)
5781 8206062 : && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
5782 3838664 : DECL_SAVED_TREE (fn) = void_node;
5783 : return false;
5784 : }
5785 :
5786 : /* There's no reason to do any of the work here if we're only doing
5787 : semantic analysis; this code just generates RTL. */
5788 61625379 : if (flag_syntax_only)
5789 : {
5790 : /* Pretend that this function has been written out so that we don't try
5791 : to expand it again. */
5792 28184 : TREE_ASM_WRITTEN (fn) = 1;
5793 28184 : return false;
5794 : }
5795 :
5796 61597195 : if (DECL_OMP_DECLARE_REDUCTION_P (fn))
5797 16 : return false;
5798 :
5799 : return true;
5800 : }
5801 :
5802 : void
5803 159212060 : expand_or_defer_fn (tree fn)
5804 : {
5805 159212060 : if (expand_or_defer_fn_1 (fn))
5806 : {
5807 53419700 : function_depth++;
5808 :
5809 : /* Expand or defer, at the whim of the compilation unit manager. */
5810 53419700 : cgraph_node::finalize_function (fn, function_depth > 1);
5811 53419700 : emit_associated_thunks (fn);
5812 :
5813 53419700 : function_depth--;
5814 :
5815 106839400 : if (DECL_IMMEDIATE_FUNCTION_P (fn))
5816 : {
5817 1056218 : if (cgraph_node *node = cgraph_node::get (fn))
5818 : {
5819 1056218 : node->body_removed = true;
5820 1056218 : node->analyzed = false;
5821 1056218 : node->definition = false;
5822 1056218 : node->force_output = false;
5823 : }
5824 : }
5825 : }
5826 159212060 : }
5827 :
5828 468062 : class nrv_data
5829 : {
5830 : public:
5831 234031 : nrv_data () : visited (37) {}
5832 :
5833 : tree var;
5834 : tree result;
5835 : hash_set<tree> visited;
5836 : bool simple;
5837 : bool in_nrv_cleanup;
5838 : };
5839 :
5840 : /* Helper function for walk_tree, used by finalize_nrv below. */
5841 :
5842 : static tree
5843 21217742 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
5844 : {
5845 21217742 : class nrv_data *dp = (class nrv_data *)data;
5846 :
5847 : /* No need to walk into types. There wouldn't be any need to walk into
5848 : non-statements, except that we have to consider STMT_EXPRs. */
5849 21217742 : if (TYPE_P (*tp))
5850 193255 : *walk_subtrees = 0;
5851 :
5852 : /* Replace all uses of the NRV with the RESULT_DECL. */
5853 21024487 : else if (*tp == dp->var)
5854 508579 : *tp = dp->result;
5855 :
5856 : /* Avoid walking into the same tree more than once. Unfortunately, we
5857 : can't just use walk_tree_without duplicates because it would only call
5858 : us for the first occurrence of dp->var in the function body. */
5859 20515908 : else if (dp->visited.add (*tp))
5860 4488426 : *walk_subtrees = 0;
5861 :
5862 : /* If there's a label, we might need to destroy the NRV on goto (92407). */
5863 16027482 : else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
5864 3 : dp->simple = false;
5865 : /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
5866 : but differs from using NULL_TREE in that it indicates that we care
5867 : about the value of the RESULT_DECL. But preserve anything appended
5868 : by check_return_expr. */
5869 16027479 : else if (TREE_CODE (*tp) == RETURN_EXPR)
5870 : {
5871 240229 : tree *p = &TREE_OPERAND (*tp, 0);
5872 615976 : while (TREE_CODE (*p) == COMPOUND_EXPR)
5873 135518 : p = &TREE_OPERAND (*p, 0);
5874 240229 : if (TREE_CODE (*p) == INIT_EXPR
5875 240229 : && INIT_EXPR_NRV_P (*p))
5876 239819 : *p = dp->result;
5877 : }
5878 : /* Change all cleanups for the NRV to only run when not returning. */
5879 15787250 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5880 15787250 : && CLEANUP_DECL (*tp) == dp->var)
5881 : {
5882 130386 : dp->in_nrv_cleanup = true;
5883 130386 : cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
5884 130386 : dp->in_nrv_cleanup = false;
5885 130386 : cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
5886 130386 : *walk_subtrees = 0;
5887 :
5888 130386 : if (dp->simple)
5889 : /* For a simple NRV, just run it on the EH path. */
5890 129723 : CLEANUP_EH_ONLY (*tp) = true;
5891 : else
5892 : {
5893 : /* Not simple, we need to check current_retval_sentinel to decide
5894 : whether to run it. If it's set, we're returning normally and
5895 : don't want to destroy the NRV. If the sentinel is not set, we're
5896 : leaving scope some other way, either by flowing off the end of its
5897 : scope or throwing an exception. */
5898 1989 : tree cond = build3 (COND_EXPR, void_type_node,
5899 663 : current_retval_sentinel,
5900 663 : void_node, CLEANUP_EXPR (*tp));
5901 663 : CLEANUP_EXPR (*tp) = cond;
5902 : }
5903 :
5904 : /* If a cleanup might throw, we need to clear current_retval_sentinel on
5905 : the exception path, both so the check above succeeds and so an outer
5906 : cleanup added by maybe_splice_retval_cleanup doesn't run. */
5907 130386 : if (cp_function_chain->throwing_cleanup)
5908 : {
5909 216 : tree clear = build2 (MODIFY_EXPR, boolean_type_node,
5910 : current_retval_sentinel,
5911 : boolean_false_node);
5912 216 : if (dp->simple)
5913 : {
5914 : /* We're already only on the EH path, just prepend it. */
5915 206 : tree &exp = CLEANUP_EXPR (*tp);
5916 206 : exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
5917 : }
5918 : else
5919 : {
5920 : /* The cleanup runs on both normal and EH paths, we need another
5921 : CLEANUP_STMT to clear the flag only on the EH path. */
5922 10 : tree &bod = CLEANUP_BODY (*tp);
5923 10 : bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
5924 10 : bod, clear, current_retval_sentinel);
5925 10 : CLEANUP_EH_ONLY (bod) = true;
5926 : }
5927 : }
5928 : }
5929 : /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
5930 : want to destroy the retval before the variable goes out of scope. */
5931 15656864 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5932 5177 : && dp->in_nrv_cleanup
5933 15660606 : && CLEANUP_DECL (*tp) == dp->result)
5934 6 : CLEANUP_EXPR (*tp) = void_node;
5935 : /* Replace the DECL_EXPR for the NRV with an initialization of the
5936 : RESULT_DECL, if needed. */
5937 15656858 : else if (TREE_CODE (*tp) == DECL_EXPR
5938 15656858 : && DECL_EXPR_DECL (*tp) == dp->var)
5939 : {
5940 234033 : tree init;
5941 234033 : if (DECL_INITIAL (dp->var)
5942 234033 : && DECL_INITIAL (dp->var) != error_mark_node)
5943 95836 : init = cp_build_init_expr (dp->result,
5944 95836 : DECL_INITIAL (dp->var));
5945 : else
5946 138197 : init = build_empty_stmt (EXPR_LOCATION (*tp));
5947 234033 : DECL_INITIAL (dp->var) = NULL_TREE;
5948 234033 : SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
5949 234033 : *tp = init;
5950 : }
5951 :
5952 : /* Keep iterating. */
5953 21217742 : return NULL_TREE;
5954 : }
5955 :
5956 : /* Called from finish_function to implement the named return value
5957 : optimization by overriding all the RETURN_EXPRs and pertinent
5958 : CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5959 : RESULT_DECL for the function. */
5960 :
5961 : void
5962 234031 : finalize_nrv (tree fndecl, tree var)
5963 : {
5964 234031 : class nrv_data data;
5965 234031 : tree result = DECL_RESULT (fndecl);
5966 :
5967 : /* Copy name from VAR to RESULT. */
5968 234031 : DECL_NAME (result) = DECL_NAME (var);
5969 : /* Don't forget that we take its address. */
5970 234031 : TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
5971 : /* Finally set DECL_VALUE_EXPR to avoid assigning
5972 : a stack slot at -O0 for the original var and debug info
5973 : uses RESULT location for VAR. */
5974 234031 : SET_DECL_VALUE_EXPR (var, result);
5975 234031 : DECL_HAS_VALUE_EXPR_P (var) = 1;
5976 :
5977 234031 : data.var = var;
5978 234031 : data.result = result;
5979 234031 : data.in_nrv_cleanup = false;
5980 :
5981 : /* This is simpler for variables declared in the outer scope of
5982 : the function so we know that their lifetime always ends with a
5983 : return; see g++.dg/opt/nrv6.C. */
5984 234031 : tree outer = outer_curly_brace_block (fndecl);
5985 234031 : data.simple = chain_member (var, BLOCK_VARS (outer));
5986 :
5987 234031 : cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
5988 234031 : }
5989 :
5990 : /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5991 :
5992 : bool
5993 2249 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
5994 : bool need_copy_ctor, bool need_copy_assignment,
5995 : bool need_dtor)
5996 : {
5997 2249 : int save_errorcount = errorcount;
5998 2249 : tree info, t;
5999 :
6000 : /* Always allocate 3 elements for simplicity. These are the
6001 : function decls for the ctor, dtor, and assignment op.
6002 : This layout is known to the three lang hooks,
6003 : cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
6004 : and cxx_omp_clause_assign_op. */
6005 2249 : info = make_tree_vec (3);
6006 2249 : CP_OMP_CLAUSE_INFO (c) = info;
6007 :
6008 2249 : if (need_default_ctor || need_copy_ctor)
6009 : {
6010 1654 : if (need_default_ctor)
6011 1255 : t = get_default_ctor (type);
6012 : else
6013 399 : t = get_copy_ctor (type, tf_warning_or_error);
6014 :
6015 1654 : if (t && !trivial_fn_p (t))
6016 1400 : TREE_VEC_ELT (info, 0) = t;
6017 : }
6018 :
6019 2249 : if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
6020 1632 : TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
6021 :
6022 2249 : if (need_copy_assignment)
6023 : {
6024 397 : t = get_copy_assign (type);
6025 :
6026 397 : if (t && !trivial_fn_p (t))
6027 344 : TREE_VEC_ELT (info, 2) = t;
6028 : }
6029 :
6030 2249 : return errorcount != save_errorcount;
6031 : }
6032 :
6033 : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
6034 : FIELD_DECL, otherwise return DECL itself. */
6035 :
6036 : static tree
6037 26714 : omp_clause_decl_field (tree decl)
6038 : {
6039 26714 : if (VAR_P (decl)
6040 18651 : && DECL_HAS_VALUE_EXPR_P (decl)
6041 359 : && DECL_ARTIFICIAL (decl)
6042 359 : && DECL_LANG_SPECIFIC (decl)
6043 27049 : && DECL_OMP_PRIVATIZED_MEMBER (decl))
6044 : {
6045 328 : tree f = DECL_VALUE_EXPR (decl);
6046 328 : if (INDIRECT_REF_P (f))
6047 0 : f = TREE_OPERAND (f, 0);
6048 328 : if (TREE_CODE (f) == COMPONENT_REF)
6049 : {
6050 328 : f = TREE_OPERAND (f, 1);
6051 328 : gcc_assert (TREE_CODE (f) == FIELD_DECL);
6052 : return f;
6053 : }
6054 : }
6055 : return NULL_TREE;
6056 : }
6057 :
6058 : /* Adjust DECL if needed for printing using %qE. */
6059 :
6060 : static tree
6061 187 : omp_clause_printable_decl (tree decl)
6062 : {
6063 0 : tree t = omp_clause_decl_field (decl);
6064 187 : if (t)
6065 45 : return t;
6066 : return decl;
6067 : }
6068 :
6069 : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
6070 : VAR_DECL T that doesn't need a DECL_EXPR added, record it for
6071 : privatization. */
6072 :
6073 : static void
6074 219 : omp_note_field_privatization (tree f, tree t)
6075 : {
6076 219 : if (!omp_private_member_map)
6077 71 : omp_private_member_map = new hash_map<tree, tree>;
6078 219 : tree &v = omp_private_member_map->get_or_insert (f);
6079 219 : if (v == NULL_TREE)
6080 : {
6081 146 : v = t;
6082 146 : omp_private_member_vec.safe_push (f);
6083 : /* Signal that we don't want to create DECL_EXPR for this dummy var. */
6084 146 : omp_private_member_vec.safe_push (integer_zero_node);
6085 : }
6086 219 : }
6087 :
6088 : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
6089 : dummy VAR_DECL. */
6090 :
6091 : tree
6092 861 : omp_privatize_field (tree t, bool shared)
6093 : {
6094 861 : tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6095 861 : if (m == error_mark_node)
6096 : return error_mark_node;
6097 861 : if (!omp_private_member_map && !shared)
6098 365 : omp_private_member_map = new hash_map<tree, tree>;
6099 861 : if (TYPE_REF_P (TREE_TYPE (t)))
6100 : {
6101 123 : gcc_assert (INDIRECT_REF_P (m));
6102 123 : m = TREE_OPERAND (m, 0);
6103 : }
6104 861 : tree vb = NULL_TREE;
6105 861 : tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
6106 861 : if (v == NULL_TREE)
6107 : {
6108 770 : v = create_temporary_var (TREE_TYPE (m));
6109 770 : retrofit_lang_decl (v);
6110 770 : DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
6111 770 : SET_DECL_VALUE_EXPR (v, m);
6112 770 : DECL_HAS_VALUE_EXPR_P (v) = 1;
6113 770 : if (!shared)
6114 690 : omp_private_member_vec.safe_push (t);
6115 : }
6116 861 : return v;
6117 : }
6118 :
6119 : /* C++ specialisation of the c_omp_address_inspector class. */
6120 :
6121 : class cp_omp_address_inspector : public c_omp_address_inspector
6122 : {
6123 : public:
6124 31538 : cp_omp_address_inspector (location_t loc, tree t)
6125 31538 : : c_omp_address_inspector (loc, t)
6126 : {
6127 : }
6128 :
6129 31538 : ~cp_omp_address_inspector ()
6130 : {
6131 23102 : }
6132 :
6133 134675 : bool processing_template_decl_p ()
6134 : {
6135 134675 : return processing_template_decl;
6136 : }
6137 :
6138 0 : void emit_unmappable_type_notes (tree t)
6139 : {
6140 0 : if (TREE_TYPE (t) != error_mark_node
6141 0 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
6142 0 : cxx_incomplete_type_inform (TREE_TYPE (t));
6143 0 : }
6144 :
6145 1062 : tree convert_from_reference (tree x)
6146 : {
6147 1062 : return ::convert_from_reference (x);
6148 : }
6149 :
6150 147 : tree build_array_ref (location_t loc, tree arr, tree idx)
6151 : {
6152 147 : return ::build_array_ref (loc, arr, idx);
6153 : }
6154 :
6155 23044 : bool check_clause (tree clause)
6156 : {
6157 23044 : if (TREE_CODE (orig) == COMPONENT_REF
6158 23044 : && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
6159 : tf_warning_or_error))
6160 : return false;
6161 23041 : if (!c_omp_address_inspector::check_clause (clause))
6162 : return false;
6163 : return true;
6164 : }
6165 : };
6166 :
6167 : /* Helper function for handle_omp_array_sections. Called recursively
6168 : to handle multiple array-section-subscripts. C is the clause,
6169 : T current expression (initially OMP_CLAUSE_DECL), which is either
6170 : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
6171 : expression if specified, TREE_VALUE length expression if specified,
6172 : TREE_CHAIN is what it has been specified after, or some decl.
6173 : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
6174 : set to true if any of the array-section-subscript could have length
6175 : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
6176 : first array-section-subscript which is known not to have length
6177 : of one. Given say:
6178 : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
6179 : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
6180 : all are or may have length of 1, array-section-subscript [:2] is the
6181 : first one known not to have length 1. For array-section-subscript
6182 : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
6183 : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
6184 : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
6185 : case though, as some lengths could be zero. */
6186 :
6187 : static tree
6188 21494 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
6189 : bool &maybe_zero_len, unsigned int &first_non_one,
6190 : enum c_omp_region_type ort)
6191 : {
6192 21494 : tree ret, low_bound, length, type;
6193 21494 : bool openacc = (ort & C_ORT_ACC) != 0;
6194 21494 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
6195 : {
6196 9708 : if (error_operand_p (t))
6197 6 : return error_mark_node;
6198 :
6199 9702 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6200 9702 : tree t_refto = ai.maybe_unconvert_ref (t);
6201 :
6202 9702 : if (!ai.check_clause (c))
6203 0 : return error_mark_node;
6204 9702 : else if (ai.component_access_p ()
6205 11090 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6206 64 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
6207 40 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
6208 1388 : t = ai.get_root_term (true);
6209 : else
6210 8314 : t = ai.unconverted_ref_origin ();
6211 9702 : if (t == error_mark_node)
6212 : return error_mark_node;
6213 9702 : ret = t_refto;
6214 9702 : if (TREE_CODE (t) == FIELD_DECL)
6215 33 : ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6216 9669 : else if (!VAR_P (t)
6217 2861 : && (openacc || !EXPR_P (t))
6218 2666 : && TREE_CODE (t) != PARM_DECL)
6219 : {
6220 51 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6221 : return NULL_TREE;
6222 33 : if (DECL_P (t))
6223 33 : error_at (OMP_CLAUSE_LOCATION (c),
6224 : "%qD is not a variable in %qs clause", t,
6225 33 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6226 : else
6227 0 : error_at (OMP_CLAUSE_LOCATION (c),
6228 : "%qE is not a variable in %qs clause", t,
6229 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6230 33 : return error_mark_node;
6231 : }
6232 9618 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6233 9227 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6234 17916 : && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
6235 : {
6236 18 : error_at (OMP_CLAUSE_LOCATION (c),
6237 : "%qD is threadprivate variable in %qs clause", t,
6238 18 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6239 18 : return error_mark_node;
6240 : }
6241 9633 : if (type_dependent_expression_p (ret))
6242 : return NULL_TREE;
6243 8922 : ret = convert_from_reference (ret);
6244 8922 : return ret;
6245 9702 : }
6246 :
6247 11786 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
6248 7859 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6249 6557 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6250 5273 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6251 14500 : && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
6252 43 : TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
6253 11786 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
6254 : maybe_zero_len, first_non_one, ort);
6255 11786 : if (ret == error_mark_node || ret == NULL_TREE)
6256 : return ret;
6257 :
6258 10716 : type = TREE_TYPE (ret);
6259 10716 : low_bound = TREE_OPERAND (t, 1);
6260 10716 : length = TREE_OPERAND (t, 2);
6261 8597 : if ((low_bound && type_dependent_expression_p (low_bound))
6262 19230 : || (length && type_dependent_expression_p (length)))
6263 : return NULL_TREE;
6264 :
6265 10628 : if (low_bound == error_mark_node || length == error_mark_node)
6266 : return error_mark_node;
6267 :
6268 10616 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
6269 : {
6270 75 : error_at (OMP_CLAUSE_LOCATION (c),
6271 : "low bound %qE of array section does not have integral type",
6272 : low_bound);
6273 75 : return error_mark_node;
6274 : }
6275 10541 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
6276 : {
6277 75 : error_at (OMP_CLAUSE_LOCATION (c),
6278 : "length %qE of array section does not have integral type",
6279 : length);
6280 75 : return error_mark_node;
6281 : }
6282 10466 : if (low_bound)
6283 8413 : low_bound = mark_rvalue_use (low_bound);
6284 10466 : if (length)
6285 9403 : length = mark_rvalue_use (length);
6286 : /* We need to reduce to real constant-values for checks below. */
6287 9403 : if (length)
6288 9403 : length = fold_simple (length);
6289 10466 : if (low_bound)
6290 8413 : low_bound = fold_simple (low_bound);
6291 8413 : if (low_bound
6292 8413 : && TREE_CODE (low_bound) == INTEGER_CST
6293 15889 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6294 7476 : > TYPE_PRECISION (sizetype))
6295 0 : low_bound = fold_convert (sizetype, low_bound);
6296 10466 : if (length
6297 9403 : && TREE_CODE (length) == INTEGER_CST
6298 17846 : && TYPE_PRECISION (TREE_TYPE (length))
6299 7380 : > TYPE_PRECISION (sizetype))
6300 0 : length = fold_convert (sizetype, length);
6301 10466 : if (low_bound == NULL_TREE)
6302 2053 : low_bound = integer_zero_node;
6303 :
6304 10466 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6305 10466 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
6306 5167 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
6307 : {
6308 60 : if (length != integer_one_node)
6309 : {
6310 36 : error_at (OMP_CLAUSE_LOCATION (c),
6311 : "expected single pointer in %qs clause",
6312 : user_omp_clause_code_name (c, openacc));
6313 36 : return error_mark_node;
6314 : }
6315 : }
6316 10430 : if (length != NULL_TREE)
6317 : {
6318 9391 : if (!integer_nonzerop (length))
6319 : {
6320 2078 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6321 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6322 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6323 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6324 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6325 : {
6326 479 : if (integer_zerop (length))
6327 : {
6328 36 : error_at (OMP_CLAUSE_LOCATION (c),
6329 : "zero length array section in %qs clause",
6330 36 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6331 36 : return error_mark_node;
6332 : }
6333 : }
6334 : else
6335 1599 : maybe_zero_len = true;
6336 : }
6337 9355 : if (first_non_one == types.length ()
6338 9355 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
6339 3989 : first_non_one++;
6340 : }
6341 10394 : if (TREE_CODE (type) == ARRAY_TYPE)
6342 : {
6343 5796 : if (length == NULL_TREE
6344 5796 : && (TYPE_DOMAIN (type) == NULL_TREE
6345 955 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
6346 : {
6347 33 : error_at (OMP_CLAUSE_LOCATION (c),
6348 : "for unknown bound array type length expression must "
6349 : "be specified");
6350 33 : return error_mark_node;
6351 : }
6352 5763 : if (TREE_CODE (low_bound) == INTEGER_CST
6353 5763 : && tree_int_cst_sgn (low_bound) == -1)
6354 : {
6355 177 : error_at (OMP_CLAUSE_LOCATION (c),
6356 : "negative low bound in array section in %qs clause",
6357 177 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6358 177 : return error_mark_node;
6359 : }
6360 5586 : if (length != NULL_TREE
6361 4688 : && TREE_CODE (length) == INTEGER_CST
6362 9348 : && tree_int_cst_sgn (length) == -1)
6363 : {
6364 177 : error_at (OMP_CLAUSE_LOCATION (c),
6365 : "negative length in array section in %qs clause",
6366 177 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6367 177 : return error_mark_node;
6368 : }
6369 5409 : if (TYPE_DOMAIN (type)
6370 5310 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6371 10719 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
6372 : == INTEGER_CST)
6373 : {
6374 4914 : tree size
6375 4914 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6376 4914 : size = size_binop (PLUS_EXPR, size, size_one_node);
6377 4914 : if (TREE_CODE (low_bound) == INTEGER_CST)
6378 : {
6379 4137 : if (tree_int_cst_lt (size, low_bound))
6380 : {
6381 63 : error_at (OMP_CLAUSE_LOCATION (c),
6382 : "low bound %qE above array section size "
6383 : "in %qs clause", low_bound,
6384 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6385 63 : return error_mark_node;
6386 : }
6387 4074 : if (tree_int_cst_equal (size, low_bound))
6388 : {
6389 21 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6390 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6391 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6392 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6393 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6394 : {
6395 21 : error_at (OMP_CLAUSE_LOCATION (c),
6396 : "zero length array section in %qs clause",
6397 21 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6398 21 : return error_mark_node;
6399 : }
6400 0 : maybe_zero_len = true;
6401 : }
6402 4053 : else if (length == NULL_TREE
6403 1578 : && first_non_one == types.length ()
6404 4406 : && tree_int_cst_equal
6405 353 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6406 : low_bound))
6407 207 : first_non_one++;
6408 : }
6409 777 : else if (length == NULL_TREE)
6410 : {
6411 24 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6412 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6413 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6414 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6415 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6416 13 : maybe_zero_len = true;
6417 48 : if (first_non_one == types.length ())
6418 21 : first_non_one++;
6419 : }
6420 4830 : if (length && TREE_CODE (length) == INTEGER_CST)
6421 : {
6422 3465 : if (tree_int_cst_lt (size, length))
6423 : {
6424 63 : error_at (OMP_CLAUSE_LOCATION (c),
6425 : "length %qE above array section size "
6426 : "in %qs clause", length,
6427 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6428 63 : return error_mark_node;
6429 : }
6430 3402 : if (TREE_CODE (low_bound) == INTEGER_CST)
6431 : {
6432 3064 : tree lbpluslen
6433 3064 : = size_binop (PLUS_EXPR,
6434 : fold_convert (sizetype, low_bound),
6435 : fold_convert (sizetype, length));
6436 3064 : if (TREE_CODE (lbpluslen) == INTEGER_CST
6437 3064 : && tree_int_cst_lt (size, lbpluslen))
6438 : {
6439 60 : error_at (OMP_CLAUSE_LOCATION (c),
6440 : "high bound %qE above array section size "
6441 : "in %qs clause", lbpluslen,
6442 60 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6443 60 : return error_mark_node;
6444 : }
6445 : }
6446 : }
6447 : }
6448 495 : else if (length == NULL_TREE)
6449 : {
6450 1 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6451 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6452 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6453 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6454 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6455 0 : maybe_zero_len = true;
6456 2 : if (first_non_one == types.length ())
6457 1 : first_non_one++;
6458 : }
6459 :
6460 : /* For [lb:] we will need to evaluate lb more than once. */
6461 4157 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6462 : {
6463 733 : tree lb = cp_save_expr (low_bound);
6464 733 : if (lb != low_bound)
6465 : {
6466 11 : TREE_OPERAND (t, 1) = lb;
6467 11 : low_bound = lb;
6468 : }
6469 : }
6470 : }
6471 4598 : else if (TYPE_PTR_P (type))
6472 : {
6473 4538 : if (length == NULL_TREE)
6474 : {
6475 51 : if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
6476 45 : error_at (OMP_CLAUSE_LOCATION (c),
6477 : "for array function parameter length expression "
6478 : "must be specified");
6479 : else
6480 6 : error_at (OMP_CLAUSE_LOCATION (c),
6481 : "for pointer type length expression must be specified");
6482 51 : return error_mark_node;
6483 : }
6484 4487 : if (length != NULL_TREE
6485 4487 : && TREE_CODE (length) == INTEGER_CST
6486 3390 : && tree_int_cst_sgn (length) == -1)
6487 : {
6488 96 : error_at (OMP_CLAUSE_LOCATION (c),
6489 : "negative length in array section in %qs clause",
6490 96 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6491 96 : return error_mark_node;
6492 : }
6493 : /* If there is a pointer type anywhere but in the very first
6494 : array-section-subscript, the array section could be non-contiguous. */
6495 4391 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6496 4289 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6497 8195 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
6498 : {
6499 : /* If any prior dimension has a non-one length, then deem this
6500 : array section as non-contiguous. */
6501 159 : for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
6502 69 : d = TREE_OPERAND (d, 0))
6503 : {
6504 90 : tree d_length = TREE_OPERAND (d, 2);
6505 90 : if (d_length == NULL_TREE || !integer_onep (d_length))
6506 : {
6507 21 : error_at (OMP_CLAUSE_LOCATION (c),
6508 : "array section is not contiguous in %qs clause",
6509 21 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6510 21 : return error_mark_node;
6511 : }
6512 : }
6513 : }
6514 : }
6515 : else
6516 : {
6517 60 : error_at (OMP_CLAUSE_LOCATION (c),
6518 : "%qE does not have pointer or array type", ret);
6519 60 : return error_mark_node;
6520 : }
6521 9572 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6522 8667 : types.safe_push (TREE_TYPE (ret));
6523 : /* We will need to evaluate lb more than once. */
6524 9572 : tree lb = cp_save_expr (low_bound);
6525 9572 : if (lb != low_bound)
6526 : {
6527 720 : TREE_OPERAND (t, 1) = lb;
6528 720 : low_bound = lb;
6529 : }
6530 : /* Temporarily disable -fstrong-eval-order for array reductions.
6531 : The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
6532 : is something the middle-end can't cope with and more importantly,
6533 : it needs to be the actual base variable that is privatized, not some
6534 : temporary assigned previous value of it. That, together with OpenMP
6535 : saying how many times the side-effects are evaluated is unspecified,
6536 : makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
6537 9572 : warning_sentinel s (flag_strong_eval_order,
6538 9572 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6539 8475 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6540 16913 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
6541 9572 : ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
6542 : tf_warning_or_error);
6543 9572 : return ret;
6544 9572 : }
6545 :
6546 : /* Handle array sections for clause C. */
6547 :
6548 : static bool
6549 9708 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
6550 : {
6551 9708 : bool maybe_zero_len = false;
6552 9708 : unsigned int first_non_one = 0;
6553 9708 : auto_vec<tree, 10> types;
6554 9708 : tree *tp = &OMP_CLAUSE_DECL (c);
6555 9708 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6556 8749 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6557 10117 : && OMP_ITERATOR_DECL_P (*tp))
6558 258 : tp = &TREE_VALUE (*tp);
6559 9708 : tree first = handle_omp_array_sections_1 (c, *tp, types,
6560 : maybe_zero_len, first_non_one,
6561 : ort);
6562 9708 : if (first == error_mark_node)
6563 : return true;
6564 8595 : if (first == NULL_TREE)
6565 : return false;
6566 7778 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6567 7778 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6568 : {
6569 951 : tree t = *tp;
6570 951 : tree tem = NULL_TREE;
6571 951 : if (processing_template_decl)
6572 : return false;
6573 : /* Need to evaluate side effects in the length expressions
6574 : if any. */
6575 852 : while (TREE_CODE (t) == TREE_LIST)
6576 : {
6577 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
6578 : {
6579 0 : if (tem == NULL_TREE)
6580 : tem = TREE_VALUE (t);
6581 : else
6582 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
6583 0 : TREE_VALUE (t), tem);
6584 : }
6585 0 : t = TREE_CHAIN (t);
6586 : }
6587 852 : if (tem)
6588 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
6589 852 : *tp = first;
6590 : }
6591 : else
6592 : {
6593 6827 : unsigned int num = types.length (), i;
6594 6827 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
6595 6827 : tree condition = NULL_TREE;
6596 :
6597 6827 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
6598 3 : maybe_zero_len = true;
6599 6827 : if (processing_template_decl && maybe_zero_len)
6600 : return false;
6601 :
6602 14362 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
6603 7613 : t = TREE_OPERAND (t, 0))
6604 : {
6605 7688 : gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
6606 :
6607 7688 : tree low_bound = TREE_OPERAND (t, 1);
6608 7688 : tree length = TREE_OPERAND (t, 2);
6609 :
6610 7688 : i--;
6611 7688 : if (low_bound
6612 6242 : && TREE_CODE (low_bound) == INTEGER_CST
6613 13319 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6614 5631 : > TYPE_PRECISION (sizetype))
6615 0 : low_bound = fold_convert (sizetype, low_bound);
6616 7688 : if (length
6617 7139 : && TREE_CODE (length) == INTEGER_CST
6618 12935 : && TYPE_PRECISION (TREE_TYPE (length))
6619 5247 : > TYPE_PRECISION (sizetype))
6620 0 : length = fold_convert (sizetype, length);
6621 7688 : if (low_bound == NULL_TREE)
6622 1446 : low_bound = integer_zero_node;
6623 7688 : if (!maybe_zero_len && i > first_non_one)
6624 : {
6625 646 : if (integer_nonzerop (low_bound))
6626 36 : goto do_warn_noncontiguous;
6627 610 : if (length != NULL_TREE
6628 282 : && TREE_CODE (length) == INTEGER_CST
6629 282 : && TYPE_DOMAIN (types[i])
6630 282 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
6631 892 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
6632 : == INTEGER_CST)
6633 : {
6634 282 : tree size;
6635 282 : size = size_binop (PLUS_EXPR,
6636 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6637 : size_one_node);
6638 282 : if (!tree_int_cst_equal (length, size))
6639 : {
6640 39 : do_warn_noncontiguous:
6641 150 : error_at (OMP_CLAUSE_LOCATION (c),
6642 : "array section is not contiguous in %qs "
6643 : "clause",
6644 75 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6645 75 : return true;
6646 : }
6647 : }
6648 571 : if (!processing_template_decl
6649 401 : && length != NULL_TREE
6650 742 : && TREE_SIDE_EFFECTS (length))
6651 : {
6652 0 : if (side_effects == NULL_TREE)
6653 : side_effects = length;
6654 : else
6655 0 : side_effects = build2 (COMPOUND_EXPR,
6656 0 : TREE_TYPE (side_effects),
6657 : length, side_effects);
6658 : }
6659 : }
6660 7042 : else if (processing_template_decl)
6661 726 : continue;
6662 : else
6663 : {
6664 6316 : tree l;
6665 :
6666 6316 : if (i > first_non_one
6667 6316 : && ((length && integer_nonzerop (length))
6668 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6669 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6670 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
6671 0 : continue;
6672 6316 : if (length)
6673 6177 : l = fold_convert (sizetype, length);
6674 : else
6675 : {
6676 139 : l = size_binop (PLUS_EXPR,
6677 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6678 : size_one_node);
6679 139 : l = size_binop (MINUS_EXPR, l,
6680 : fold_convert (sizetype, low_bound));
6681 : }
6682 6316 : if (i > first_non_one)
6683 : {
6684 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
6685 : size_zero_node);
6686 0 : if (condition == NULL_TREE)
6687 : condition = l;
6688 : else
6689 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
6690 : l, condition);
6691 : }
6692 6316 : else if (size == NULL_TREE)
6693 : {
6694 6029 : size = size_in_bytes (TREE_TYPE (types[i]));
6695 6029 : tree eltype = TREE_TYPE (types[num - 1]);
6696 6100 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6697 71 : eltype = TREE_TYPE (eltype);
6698 6029 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6699 5219 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6700 10495 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6701 1659 : size = size_binop (EXACT_DIV_EXPR, size,
6702 : size_in_bytes (eltype));
6703 6029 : size = size_binop (MULT_EXPR, size, l);
6704 6029 : if (condition)
6705 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
6706 : size, size_zero_node);
6707 : }
6708 : else
6709 287 : size = size_binop (MULT_EXPR, size, l);
6710 : }
6711 : }
6712 6674 : if (!processing_template_decl)
6713 : {
6714 6029 : if (side_effects)
6715 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
6716 6029 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6717 5219 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6718 10495 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6719 : {
6720 1659 : size = size_binop (MINUS_EXPR, size, size_one_node);
6721 1659 : size = save_expr (size);
6722 1659 : tree index_type = build_index_type (size);
6723 1659 : tree eltype = TREE_TYPE (first);
6724 1688 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6725 29 : eltype = TREE_TYPE (eltype);
6726 1659 : tree type = build_array_type (eltype, index_type);
6727 1659 : tree ptype = build_pointer_type (eltype);
6728 1659 : if (TYPE_REF_P (TREE_TYPE (t))
6729 1659 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
6730 170 : t = convert_from_reference (t);
6731 1489 : else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6732 641 : t = build_fold_addr_expr (t);
6733 1659 : tree t2 = build_fold_addr_expr (first);
6734 1659 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6735 : ptrdiff_type_node, t2);
6736 1659 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
6737 : ptrdiff_type_node, t2,
6738 1659 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6739 : ptrdiff_type_node, t));
6740 1659 : if (tree_fits_shwi_p (t2))
6741 1321 : t = build2 (MEM_REF, type, t,
6742 1321 : build_int_cst (ptype, tree_to_shwi (t2)));
6743 : else
6744 : {
6745 338 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6746 : sizetype, t2);
6747 338 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
6748 338 : TREE_TYPE (t), t, t2);
6749 338 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
6750 : }
6751 1659 : OMP_CLAUSE_DECL (c) = t;
6752 6029 : return false;
6753 : }
6754 4370 : OMP_CLAUSE_DECL (c) = first;
6755 4370 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
6756 : return false;
6757 4344 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
6758 4344 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
6759 3787 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
6760 3775 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
6761 4320 : OMP_CLAUSE_SIZE (c) = size;
6762 4344 : if (TREE_CODE (t) == FIELD_DECL)
6763 3 : t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6764 :
6765 4344 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6766 : return false;
6767 :
6768 3799 : if (TREE_CODE (first) == INDIRECT_REF)
6769 : {
6770 : /* Detect and skip adding extra nodes for pointer-to-member
6771 : mappings. These are unsupported for now. */
6772 2413 : tree tmp = TREE_OPERAND (first, 0);
6773 :
6774 2413 : if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
6775 1915 : tmp = TREE_OPERAND (tmp, 0);
6776 :
6777 2413 : if (TREE_CODE (tmp) == INDIRECT_REF)
6778 158 : tmp = TREE_OPERAND (tmp, 0);
6779 :
6780 2413 : if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
6781 : {
6782 468 : tree offset = TREE_OPERAND (tmp, 1);
6783 468 : STRIP_NOPS (offset);
6784 468 : if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
6785 : {
6786 36 : sorry_at (OMP_CLAUSE_LOCATION (c),
6787 : "pointer-to-member mapping %qE not supported",
6788 18 : OMP_CLAUSE_DECL (c));
6789 18 : return true;
6790 : }
6791 : }
6792 : }
6793 :
6794 : /* FIRST represents the first item of data that we are mapping.
6795 : E.g. if we're mapping an array, FIRST might resemble
6796 : "foo.bar.myarray[0]". */
6797 :
6798 3781 : auto_vec<omp_addr_token *, 10> addr_tokens;
6799 :
6800 3781 : if (!omp_parse_expr (addr_tokens, first))
6801 : return true;
6802 :
6803 3781 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6804 :
6805 3781 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
6806 3781 : if (nc != error_mark_node)
6807 : {
6808 3781 : using namespace omp_addr_tokenizer;
6809 :
6810 3781 : if (ai.maybe_zero_length_array_section (c))
6811 3757 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
6812 :
6813 : /* !!! If we're accessing a base decl via chained access
6814 : methods (e.g. multiple indirections), duplicate clause
6815 : detection won't work properly. Skip it in that case. */
6816 3781 : if ((addr_tokens[0]->type == STRUCTURE_BASE
6817 2764 : || addr_tokens[0]->type == ARRAY_BASE)
6818 3781 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
6819 3770 : && addr_tokens[1]->type == ACCESS_METHOD
6820 7551 : && omp_access_chain_p (addr_tokens, 1))
6821 218 : c = nc;
6822 :
6823 3781 : return false;
6824 : }
6825 7562 : }
6826 : }
6827 : return false;
6828 9708 : }
6829 :
6830 : /* Return identifier to look up for omp declare reduction. */
6831 :
6832 : tree
6833 7113 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
6834 : {
6835 7113 : const char *p = NULL;
6836 7113 : const char *m = NULL;
6837 7113 : switch (reduction_code)
6838 : {
6839 4200 : case PLUS_EXPR:
6840 4200 : case MULT_EXPR:
6841 4200 : case MINUS_EXPR:
6842 4200 : case BIT_AND_EXPR:
6843 4200 : case BIT_XOR_EXPR:
6844 4200 : case BIT_IOR_EXPR:
6845 4200 : case TRUTH_ANDIF_EXPR:
6846 4200 : case TRUTH_ORIF_EXPR:
6847 4200 : reduction_id = ovl_op_identifier (false, reduction_code);
6848 4200 : break;
6849 : case MIN_EXPR:
6850 : p = "min";
6851 : break;
6852 : case MAX_EXPR:
6853 : p = "max";
6854 : break;
6855 : default:
6856 : break;
6857 : }
6858 :
6859 4200 : if (p == NULL)
6860 : {
6861 6949 : if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
6862 0 : return error_mark_node;
6863 6949 : p = IDENTIFIER_POINTER (reduction_id);
6864 : }
6865 :
6866 7113 : if (type != NULL_TREE)
6867 2047 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6868 :
6869 7113 : const char prefix[] = "omp declare reduction ";
6870 7113 : size_t lenp = sizeof (prefix);
6871 7113 : if (strncmp (p, prefix, lenp - 1) == 0)
6872 2047 : lenp = 1;
6873 7113 : size_t len = strlen (p);
6874 7113 : size_t lenm = m ? strlen (m) + 1 : 0;
6875 7113 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6876 7113 : if (lenp > 1)
6877 5066 : memcpy (name, prefix, lenp - 1);
6878 7113 : memcpy (name + lenp - 1, p, len + 1);
6879 7113 : if (m)
6880 : {
6881 2047 : name[lenp + len - 1] = '~';
6882 2047 : memcpy (name + lenp + len, m, lenm);
6883 : }
6884 7113 : return get_identifier (name);
6885 : }
6886 :
6887 : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
6888 : FUNCTION_DECL or NULL_TREE if not found. */
6889 :
6890 : static tree
6891 1298 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
6892 : vec<tree> *ambiguousp)
6893 : {
6894 1298 : tree orig_id = id;
6895 1298 : tree baselink = NULL_TREE;
6896 1298 : if (identifier_p (id))
6897 : {
6898 1270 : cp_id_kind idk;
6899 1270 : bool nonint_cst_expression_p;
6900 1270 : const char *error_msg;
6901 1270 : id = omp_reduction_id (ERROR_MARK, id, type);
6902 1270 : tree decl = lookup_name (id);
6903 1270 : if (decl == NULL_TREE)
6904 80 : decl = error_mark_node;
6905 1270 : id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
6906 : &nonint_cst_expression_p, false, true, false,
6907 : false, &error_msg, loc);
6908 1270 : if (idk == CP_ID_KIND_UNQUALIFIED
6909 1350 : && identifier_p (id))
6910 : {
6911 80 : vec<tree, va_gc> *args = NULL;
6912 80 : vec_safe_push (args, build_reference_type (type));
6913 80 : id = perform_koenig_lookup (id, args, tf_none);
6914 : }
6915 : }
6916 28 : else if (TREE_CODE (id) == SCOPE_REF)
6917 28 : id = lookup_qualified_name (TREE_OPERAND (id, 0),
6918 : omp_reduction_id (ERROR_MARK,
6919 28 : TREE_OPERAND (id, 1),
6920 : type),
6921 : LOOK_want::NORMAL, false);
6922 1298 : tree fns = id;
6923 1298 : id = NULL_TREE;
6924 1298 : if (fns && is_overloaded_fn (fns))
6925 : {
6926 1224 : for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
6927 : {
6928 1224 : tree fndecl = *iter;
6929 1224 : if (TREE_CODE (fndecl) == FUNCTION_DECL)
6930 : {
6931 1224 : tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
6932 1224 : if (same_type_p (TREE_TYPE (argtype), type))
6933 : {
6934 1224 : id = fndecl;
6935 1224 : break;
6936 : }
6937 : }
6938 : }
6939 :
6940 1224 : if (id && BASELINK_P (fns))
6941 : {
6942 74 : if (baselinkp)
6943 0 : *baselinkp = fns;
6944 : else
6945 74 : baselink = fns;
6946 : }
6947 : }
6948 :
6949 1298 : if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
6950 : {
6951 35 : auto_vec<tree> ambiguous;
6952 35 : tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
6953 35 : unsigned int ix;
6954 35 : if (ambiguousp == NULL)
6955 19 : ambiguousp = &ambiguous;
6956 73 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
6957 : {
6958 62 : id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
6959 : baselinkp ? baselinkp : &baselink,
6960 : ambiguousp);
6961 38 : if (id == NULL_TREE)
6962 14 : continue;
6963 24 : if (!ambiguousp->is_empty ())
6964 3 : ambiguousp->safe_push (id);
6965 21 : else if (ret != NULL_TREE)
6966 : {
6967 6 : ambiguousp->safe_push (ret);
6968 6 : ambiguousp->safe_push (id);
6969 6 : ret = NULL_TREE;
6970 : }
6971 : else
6972 15 : ret = id;
6973 : }
6974 35 : if (ambiguousp != &ambiguous)
6975 16 : return ret;
6976 19 : if (!ambiguous.is_empty ())
6977 : {
6978 6 : auto_diagnostic_group d;
6979 6 : const char *str = _("candidates are:");
6980 6 : unsigned int idx;
6981 6 : tree udr;
6982 6 : error_at (loc, "user defined reduction lookup is ambiguous");
6983 27 : FOR_EACH_VEC_ELT (ambiguous, idx, udr)
6984 : {
6985 15 : inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
6986 15 : if (idx == 0)
6987 6 : str = get_spaces (str);
6988 : }
6989 6 : ret = error_mark_node;
6990 6 : baselink = NULL_TREE;
6991 6 : }
6992 19 : id = ret;
6993 35 : }
6994 1282 : if (id && baselink)
6995 74 : perform_or_defer_access_check (BASELINK_BINFO (baselink),
6996 : id, id, tf_warning_or_error);
6997 : return id;
6998 : }
6999 :
7000 : /* Return identifier to look up for omp declare mapper. */
7001 :
7002 : tree
7003 4067 : omp_mapper_id (tree mapper_id, tree type)
7004 : {
7005 4067 : const char *p = NULL;
7006 4067 : const char *m = NULL;
7007 :
7008 4067 : if (mapper_id == NULL_TREE)
7009 : p = "";
7010 91 : else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
7011 91 : p = IDENTIFIER_POINTER (mapper_id);
7012 : else
7013 0 : return error_mark_node;
7014 :
7015 4067 : if (type != NULL_TREE)
7016 4059 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
7017 :
7018 4067 : const char prefix[] = "omp declare mapper ";
7019 4067 : size_t lenp = sizeof (prefix);
7020 4067 : if (strncmp (p, prefix, lenp - 1) == 0)
7021 8 : lenp = 1;
7022 4067 : size_t len = strlen (p);
7023 4067 : size_t lenm = m ? strlen (m) + 1 : 0;
7024 4067 : char *name = XALLOCAVEC (char, lenp + len + lenm);
7025 4067 : memcpy (name, prefix, lenp - 1);
7026 4067 : memcpy (name + lenp - 1, p, len + 1);
7027 4067 : if (m)
7028 : {
7029 4059 : name[lenp + len - 1] = '~';
7030 4059 : memcpy (name + lenp + len, m, lenm);
7031 : }
7032 4067 : return get_identifier (name);
7033 : }
7034 :
7035 : tree
7036 12048 : cxx_omp_mapper_lookup (tree id, tree type)
7037 : {
7038 12048 : if (!RECORD_OR_UNION_TYPE_P (type))
7039 : return NULL_TREE;
7040 3826 : id = omp_mapper_id (id, type);
7041 3826 : return lookup_name (id);
7042 : }
7043 :
7044 : tree
7045 375 : cxx_omp_extract_mapper_directive (tree vardecl)
7046 : {
7047 375 : gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
7048 :
7049 : /* Instantiate the decl if we haven't already. */
7050 375 : mark_used (vardecl);
7051 375 : tree body = DECL_INITIAL (vardecl);
7052 :
7053 375 : if (TREE_CODE (body) == STATEMENT_LIST)
7054 : {
7055 0 : tree_stmt_iterator tsi = tsi_start (body);
7056 0 : gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
7057 0 : tsi_next (&tsi);
7058 0 : body = tsi_stmt (tsi);
7059 : }
7060 :
7061 375 : gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
7062 :
7063 375 : return body;
7064 : }
7065 :
7066 : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
7067 : nothing more complicated. */
7068 :
7069 : tree
7070 1959 : cxx_omp_map_array_section (location_t loc, tree t)
7071 : {
7072 1959 : tree low = TREE_OPERAND (t, 1);
7073 1959 : tree len = TREE_OPERAND (t, 2);
7074 :
7075 1959 : if (len && integer_onep (len))
7076 : {
7077 317 : t = TREE_OPERAND (t, 0);
7078 :
7079 317 : if (!low)
7080 26 : low = integer_zero_node;
7081 :
7082 317 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
7083 6 : t = convert_from_reference (t);
7084 :
7085 317 : if (TYPE_PTR_P (TREE_TYPE (t))
7086 317 : || TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7087 317 : t = build_array_ref (loc, t, low);
7088 : else
7089 : /* handle_omp_array_sections_1 has already diagnosed the error. */
7090 0 : t = error_mark_node;
7091 : }
7092 :
7093 1959 : return t;
7094 : }
7095 :
7096 : /* Helper function for cp_parser_omp_declare_reduction_exprs
7097 : and tsubst_omp_udr.
7098 : Remove CLEANUP_STMT for data (omp_priv variable).
7099 : Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
7100 : DECL_EXPR. */
7101 :
7102 : tree
7103 4449 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
7104 : {
7105 4449 : if (TYPE_P (*tp))
7106 230 : *walk_subtrees = 0;
7107 4219 : else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
7108 52 : *tp = CLEANUP_BODY (*tp);
7109 4167 : else if (TREE_CODE (*tp) == DECL_EXPR)
7110 : {
7111 310 : tree decl = DECL_EXPR_DECL (*tp);
7112 310 : if (!processing_template_decl
7113 261 : && decl == (tree) data
7114 261 : && DECL_INITIAL (decl)
7115 402 : && DECL_INITIAL (decl) != error_mark_node)
7116 : {
7117 92 : tree list = NULL_TREE;
7118 92 : append_to_statement_list_force (*tp, &list);
7119 92 : tree init_expr = build2 (INIT_EXPR, void_type_node,
7120 92 : decl, DECL_INITIAL (decl));
7121 92 : DECL_INITIAL (decl) = NULL_TREE;
7122 92 : append_to_statement_list_force (init_expr, &list);
7123 92 : *tp = list;
7124 : }
7125 : }
7126 4449 : return NULL_TREE;
7127 : }
7128 :
7129 : /* Data passed from cp_check_omp_declare_reduction to
7130 : cp_check_omp_declare_reduction_r. */
7131 :
7132 : struct cp_check_omp_declare_reduction_data
7133 : {
7134 : location_t loc;
7135 : tree stmts[7];
7136 : bool combiner_p;
7137 : };
7138 :
7139 : /* Helper function for cp_check_omp_declare_reduction, called via
7140 : cp_walk_tree. */
7141 :
7142 : static tree
7143 15042 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
7144 : {
7145 15042 : struct cp_check_omp_declare_reduction_data *udr_data
7146 : = (struct cp_check_omp_declare_reduction_data *) data;
7147 15042 : if (SSA_VAR_P (*tp)
7148 2702 : && !DECL_ARTIFICIAL (*tp)
7149 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
7150 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
7151 : {
7152 135 : location_t loc = udr_data->loc;
7153 135 : if (udr_data->combiner_p)
7154 45 : error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
7155 : "variable %qD which is not %<omp_out%> nor %<omp_in%>",
7156 : *tp);
7157 : else
7158 90 : error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
7159 : "to variable %qD which is not %<omp_priv%> nor "
7160 : "%<omp_orig%>",
7161 : *tp);
7162 135 : return *tp;
7163 : }
7164 : return NULL_TREE;
7165 : }
7166 :
7167 : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
7168 :
7169 : bool
7170 1104 : cp_check_omp_declare_reduction (tree udr)
7171 : {
7172 1104 : tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
7173 1104 : gcc_assert (TYPE_REF_P (type));
7174 1104 : type = TREE_TYPE (type);
7175 1104 : int i;
7176 1104 : location_t loc = DECL_SOURCE_LOCATION (udr);
7177 :
7178 1104 : if (type == error_mark_node)
7179 : return false;
7180 1104 : if (ARITHMETIC_TYPE_P (type))
7181 : {
7182 : static enum tree_code predef_codes[]
7183 : = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
7184 : BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
7185 3276 : for (i = 0; i < 8; i++)
7186 : {
7187 2918 : tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
7188 2918 : const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
7189 2918 : const char *n2 = IDENTIFIER_POINTER (id);
7190 2918 : if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
7191 2918 : && (n1[IDENTIFIER_LENGTH (id)] == '~'
7192 0 : || n1[IDENTIFIER_LENGTH (id)] == '\0'))
7193 : break;
7194 : }
7195 :
7196 376 : if (i == 8
7197 358 : && TREE_CODE (type) != COMPLEX_EXPR)
7198 : {
7199 358 : const char prefix_minmax[] = "omp declare reduction m";
7200 358 : size_t prefix_size = sizeof (prefix_minmax) - 1;
7201 358 : const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
7202 358 : if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
7203 : prefix_minmax, prefix_size) == 0
7204 10 : && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
7205 4 : || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
7206 368 : && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
7207 6 : i = 0;
7208 : }
7209 376 : if (i < 8)
7210 : {
7211 24 : error_at (loc, "predeclared arithmetic type %qT in "
7212 : "%<#pragma omp declare reduction%>", type);
7213 24 : return false;
7214 : }
7215 : }
7216 : else if (FUNC_OR_METHOD_TYPE_P (type)
7217 : || TREE_CODE (type) == ARRAY_TYPE)
7218 : {
7219 24 : error_at (loc, "function or array type %qT in "
7220 : "%<#pragma omp declare reduction%>", type);
7221 24 : return false;
7222 : }
7223 : else if (TYPE_REF_P (type))
7224 : {
7225 0 : error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
7226 : type);
7227 0 : return false;
7228 : }
7229 704 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
7230 : {
7231 24 : error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
7232 : "type %qT in %<#pragma omp declare reduction%>", type);
7233 24 : return false;
7234 : }
7235 :
7236 1032 : tree body = DECL_SAVED_TREE (udr);
7237 1032 : if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
7238 : return true;
7239 :
7240 846 : tree_stmt_iterator tsi;
7241 846 : struct cp_check_omp_declare_reduction_data data;
7242 846 : memset (data.stmts, 0, sizeof data.stmts);
7243 846 : for (i = 0, tsi = tsi_start (body);
7244 4707 : i < 7 && !tsi_end_p (tsi);
7245 3861 : i++, tsi_next (&tsi))
7246 3861 : data.stmts[i] = tsi_stmt (tsi);
7247 846 : data.loc = loc;
7248 846 : gcc_assert (tsi_end_p (tsi));
7249 846 : if (i >= 3)
7250 : {
7251 846 : gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
7252 : && TREE_CODE (data.stmts[1]) == DECL_EXPR);
7253 846 : if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
7254 : return true;
7255 801 : data.combiner_p = true;
7256 801 : if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
7257 : &data, NULL))
7258 45 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
7259 : }
7260 801 : if (i >= 6)
7261 : {
7262 339 : gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
7263 : && TREE_CODE (data.stmts[4]) == DECL_EXPR);
7264 339 : data.combiner_p = false;
7265 339 : if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
7266 : &data, NULL)
7267 339 : || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
7268 : cp_check_omp_declare_reduction_r, &data, NULL))
7269 90 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */);
7270 339 : if (i == 7)
7271 201 : gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
7272 : }
7273 : return true;
7274 : }
7275 :
7276 : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
7277 : an inline call. But, remap
7278 : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
7279 : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
7280 :
7281 : static tree
7282 2217 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
7283 : tree decl, tree placeholder)
7284 : {
7285 2217 : copy_body_data id;
7286 2217 : hash_map<tree, tree> decl_map;
7287 :
7288 2217 : decl_map.put (omp_decl1, placeholder);
7289 2217 : decl_map.put (omp_decl2, decl);
7290 2217 : memset (&id, 0, sizeof (id));
7291 2217 : id.src_fn = DECL_CONTEXT (omp_decl1);
7292 2217 : id.dst_fn = current_function_decl;
7293 2217 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
7294 2217 : id.decl_map = &decl_map;
7295 :
7296 2217 : id.copy_decl = copy_decl_no_change;
7297 2217 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
7298 2217 : id.transform_new_cfg = true;
7299 2217 : id.transform_return_to_modify = false;
7300 2217 : id.eh_lp_nr = 0;
7301 2217 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
7302 2217 : return stmt;
7303 2217 : }
7304 :
7305 : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
7306 : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
7307 :
7308 : static tree
7309 15573 : find_omp_placeholder_r (tree *tp, int *, void *data)
7310 : {
7311 15573 : if (*tp == (tree) data)
7312 274 : return *tp;
7313 : return NULL_TREE;
7314 : }
7315 :
7316 : /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
7317 : Return true if there is some error and the clause should be removed. */
7318 :
7319 : static bool
7320 9018 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
7321 : {
7322 9018 : tree t = OMP_CLAUSE_DECL (c);
7323 9018 : bool predefined = false;
7324 9018 : if (TREE_CODE (t) == TREE_LIST)
7325 : {
7326 0 : gcc_assert (processing_template_decl);
7327 : return false;
7328 : }
7329 9018 : tree type = TREE_TYPE (t);
7330 9018 : if (TREE_CODE (t) == MEM_REF)
7331 1656 : type = TREE_TYPE (type);
7332 9018 : if (TYPE_REF_P (type))
7333 557 : type = TREE_TYPE (type);
7334 9018 : if (TREE_CODE (type) == ARRAY_TYPE)
7335 : {
7336 377 : tree oatype = type;
7337 377 : gcc_assert (TREE_CODE (t) != MEM_REF);
7338 757 : while (TREE_CODE (type) == ARRAY_TYPE)
7339 380 : type = TREE_TYPE (type);
7340 377 : if (!processing_template_decl)
7341 : {
7342 270 : t = require_complete_type (t);
7343 270 : if (t == error_mark_node
7344 270 : || !complete_type_or_else (oatype, NULL_TREE))
7345 : return true;
7346 261 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
7347 : TYPE_SIZE_UNIT (type));
7348 261 : if (integer_zerop (size))
7349 : {
7350 6 : error_at (OMP_CLAUSE_LOCATION (c),
7351 : "%qE in %<reduction%> clause is a zero size array",
7352 : omp_clause_printable_decl (t));
7353 3 : return true;
7354 : }
7355 258 : size = size_binop (MINUS_EXPR, size, size_one_node);
7356 258 : size = save_expr (size);
7357 258 : tree index_type = build_index_type (size);
7358 258 : tree atype = build_array_type (type, index_type);
7359 258 : tree ptype = build_pointer_type (type);
7360 258 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7361 152 : t = build_fold_addr_expr (t);
7362 258 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
7363 258 : OMP_CLAUSE_DECL (c) = t;
7364 : }
7365 : }
7366 9006 : if (type == error_mark_node)
7367 : return true;
7368 9003 : else if (ARITHMETIC_TYPE_P (type))
7369 7734 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
7370 : {
7371 : case PLUS_EXPR:
7372 : case MULT_EXPR:
7373 : case MINUS_EXPR:
7374 : case TRUTH_ANDIF_EXPR:
7375 : case TRUTH_ORIF_EXPR:
7376 : predefined = true;
7377 : break;
7378 246 : case MIN_EXPR:
7379 246 : case MAX_EXPR:
7380 246 : if (TREE_CODE (type) == COMPLEX_TYPE)
7381 : break;
7382 : predefined = true;
7383 : break;
7384 111 : case BIT_AND_EXPR:
7385 111 : case BIT_IOR_EXPR:
7386 111 : case BIT_XOR_EXPR:
7387 111 : if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
7388 : break;
7389 : predefined = true;
7390 : break;
7391 : default:
7392 : break;
7393 : }
7394 1269 : else if (TYPE_READONLY (type))
7395 : {
7396 18 : error_at (OMP_CLAUSE_LOCATION (c),
7397 : "%qE has const type for %<reduction%>",
7398 : omp_clause_printable_decl (t));
7399 9 : return true;
7400 : }
7401 1260 : else if (!processing_template_decl)
7402 : {
7403 1047 : t = require_complete_type (t);
7404 1047 : if (t == error_mark_node)
7405 : return true;
7406 1047 : OMP_CLAUSE_DECL (c) = t;
7407 : }
7408 :
7409 1047 : if (predefined)
7410 : {
7411 7512 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7412 7512 : return false;
7413 : }
7414 1482 : else if (processing_template_decl)
7415 : {
7416 222 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
7417 : return true;
7418 219 : return false;
7419 : }
7420 :
7421 1260 : tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7422 :
7423 1260 : type = TYPE_MAIN_VARIANT (type);
7424 1260 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7425 1260 : if (id == NULL_TREE)
7426 933 : id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
7427 : NULL_TREE, NULL_TREE);
7428 1260 : id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
7429 1260 : if (id)
7430 : {
7431 1215 : if (id == error_mark_node)
7432 : return true;
7433 1209 : mark_used (id);
7434 1209 : tree body = DECL_SAVED_TREE (id);
7435 1209 : if (!body)
7436 : return true;
7437 1206 : if (TREE_CODE (body) == STATEMENT_LIST)
7438 : {
7439 1206 : tree_stmt_iterator tsi;
7440 1206 : tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
7441 1206 : int i;
7442 1206 : tree stmts[7];
7443 1206 : tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
7444 1206 : atype = TREE_TYPE (atype);
7445 1206 : bool need_static_cast = !same_type_p (type, atype);
7446 1206 : memset (stmts, 0, sizeof stmts);
7447 1206 : for (i = 0, tsi = tsi_start (body);
7448 8594 : i < 7 && !tsi_end_p (tsi);
7449 7388 : i++, tsi_next (&tsi))
7450 7388 : stmts[i] = tsi_stmt (tsi);
7451 1206 : gcc_assert (tsi_end_p (tsi));
7452 :
7453 1206 : if (i >= 3)
7454 : {
7455 1206 : gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
7456 : && TREE_CODE (stmts[1]) == DECL_EXPR);
7457 1206 : placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
7458 1206 : DECL_ARTIFICIAL (placeholder) = 1;
7459 1206 : DECL_IGNORED_P (placeholder) = 1;
7460 1206 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
7461 1206 : if (TREE_CODE (t) == MEM_REF)
7462 : {
7463 600 : decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
7464 : type);
7465 600 : DECL_ARTIFICIAL (decl_placeholder) = 1;
7466 600 : DECL_IGNORED_P (decl_placeholder) = 1;
7467 600 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
7468 : }
7469 1206 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
7470 294 : cxx_mark_addressable (placeholder);
7471 1206 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
7472 1206 : && (decl_placeholder
7473 158 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7474 390 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7475 127 : : OMP_CLAUSE_DECL (c));
7476 1206 : tree omp_out = placeholder;
7477 1206 : tree omp_in = decl_placeholder ? decl_placeholder
7478 606 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7479 1206 : if (need_static_cast)
7480 : {
7481 7 : tree rtype = build_reference_type (atype);
7482 7 : omp_out = build_static_cast (input_location,
7483 : rtype, omp_out,
7484 : tf_warning_or_error);
7485 7 : omp_in = build_static_cast (input_location,
7486 : rtype, omp_in,
7487 : tf_warning_or_error);
7488 7 : if (omp_out == error_mark_node || omp_in == error_mark_node)
7489 3 : return true;
7490 7 : omp_out = convert_from_reference (omp_out);
7491 7 : omp_in = convert_from_reference (omp_in);
7492 : }
7493 1206 : OMP_CLAUSE_REDUCTION_MERGE (c)
7494 1206 : = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
7495 1206 : DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
7496 : }
7497 1206 : if (i >= 6)
7498 : {
7499 1014 : gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
7500 : && TREE_CODE (stmts[4]) == DECL_EXPR);
7501 1014 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
7502 1014 : && (decl_placeholder
7503 232 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7504 844 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7505 170 : : OMP_CLAUSE_DECL (c));
7506 1014 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
7507 225 : cxx_mark_addressable (placeholder);
7508 1014 : tree omp_priv = decl_placeholder ? decl_placeholder
7509 438 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7510 1014 : tree omp_orig = placeholder;
7511 1014 : if (need_static_cast)
7512 : {
7513 5 : if (i == 7)
7514 : {
7515 3 : error_at (OMP_CLAUSE_LOCATION (c),
7516 : "user defined reduction with constructor "
7517 : "initializer for base class %qT", atype);
7518 3 : return true;
7519 : }
7520 2 : tree rtype = build_reference_type (atype);
7521 2 : omp_priv = build_static_cast (input_location,
7522 : rtype, omp_priv,
7523 : tf_warning_or_error);
7524 2 : omp_orig = build_static_cast (input_location,
7525 : rtype, omp_orig,
7526 : tf_warning_or_error);
7527 2 : if (omp_priv == error_mark_node
7528 2 : || omp_orig == error_mark_node)
7529 : return true;
7530 2 : omp_priv = convert_from_reference (omp_priv);
7531 2 : omp_orig = convert_from_reference (omp_orig);
7532 : }
7533 1011 : if (i == 6)
7534 286 : *need_default_ctor = true;
7535 1011 : OMP_CLAUSE_REDUCTION_INIT (c)
7536 1011 : = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
7537 1011 : DECL_EXPR_DECL (stmts[3]),
7538 : omp_priv, omp_orig);
7539 1011 : if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
7540 : find_omp_placeholder_r, placeholder, NULL))
7541 247 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
7542 : }
7543 192 : else if (i >= 3)
7544 : {
7545 192 : if (CLASS_TYPE_P (type) && !pod_type_p (type))
7546 175 : *need_default_ctor = true;
7547 : else
7548 : {
7549 17 : tree init;
7550 17 : tree v = decl_placeholder ? decl_placeholder
7551 17 : : convert_from_reference (t);
7552 17 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
7553 8 : init = build_constructor (TREE_TYPE (v), NULL);
7554 : else
7555 9 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
7556 34 : OMP_CLAUSE_REDUCTION_INIT (c)
7557 34 : = cp_build_init_expr (v, init);
7558 : }
7559 : }
7560 : }
7561 : }
7562 1248 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7563 1203 : *need_dtor = true;
7564 : else
7565 : {
7566 90 : error_at (OMP_CLAUSE_LOCATION (c),
7567 : "user defined reduction not found for %qE",
7568 : omp_clause_printable_decl (t));
7569 45 : return true;
7570 : }
7571 1203 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7572 600 : gcc_assert (TYPE_SIZE_UNIT (type)
7573 : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
7574 : return false;
7575 : }
7576 :
7577 : /* Check an instance of an "omp declare mapper" function. */
7578 :
7579 : bool
7580 208 : cp_check_omp_declare_mapper (tree udm)
7581 : {
7582 208 : tree var = OMP_DECLARE_MAPPER_DECL (udm);
7583 208 : tree type = TREE_TYPE (var);
7584 208 : location_t loc = DECL_SOURCE_LOCATION (var);
7585 :
7586 208 : if (type == error_mark_node)
7587 : return false;
7588 :
7589 208 : if (processing_template_decl)
7590 : return true;
7591 :
7592 197 : if (!RECORD_OR_UNION_TYPE_P (type))
7593 : {
7594 17 : error_at (loc, "%qT is not a struct, union or class type in "
7595 : "%<#pragma omp declare mapper%>", type);
7596 17 : return false;
7597 : }
7598 180 : if (CLASSTYPE_VBASECLASSES (type))
7599 : {
7600 3 : error_at (loc, "%qT must not be a virtual base class in "
7601 : "%<#pragma omp declare mapper%>", type);
7602 3 : return false;
7603 : }
7604 :
7605 177 : tree c = OMP_DECLARE_MAPPER_CLAUSES (udm);
7606 215 : for ( ; c; c = OMP_CLAUSE_CHAIN (c))
7607 : {
7608 187 : tree dvar = OMP_CLAUSE_DECL (c);
7609 400 : while (!DECL_P (dvar) && TREE_OPERAND_LENGTH (dvar))
7610 213 : dvar = TREE_OPERAND (dvar, 0);
7611 187 : if (dvar == var)
7612 : break;
7613 : }
7614 177 : if (!c)
7615 : {
7616 : // After template handling, the var is mangled, demangle it
7617 28 : const char *name = IDENTIFIER_POINTER (DECL_NAME (var));
7618 28 : char *n = NULL;
7619 28 : if (startswith (name, "omp declare mapper "))
7620 : {
7621 3 : name += strlen ("omp declare mapper ");
7622 3 : n = xstrdup (name);
7623 3 : n[strchr (n, '~')-n] = '\0';
7624 3 : name = n;
7625 : }
7626 28 : error_at (loc, "at least one %<map%> clause must map %qs or an "
7627 : "element of it", name);
7628 28 : if (n)
7629 3 : free (n);
7630 : return false;
7631 : }
7632 :
7633 : /* FIXME: The vardecl created for the mapper_id uses DECL_DECLARED_CONSTEXPR_P
7634 : = 1, which is set to false in finalize_literal_type_property for C++ < 11,
7635 : leading to an error in ensure_literal_type_for_constexpr_object.
7636 : Examples (compile with -std=c++98): gcc.dg/gomp/declare-mapper-13.c and
7637 : libgomp.c++/declare-mapper-{5,6,8}.C. */
7638 149 : if (cxx_dialect < cxx11)
7639 : {
7640 0 : sorry_at (loc, "%<#pragma omp declare mapper%> with %<-std=%> set to "
7641 : "before C++11");
7642 0 : return false;
7643 : }
7644 :
7645 : return true;
7646 : }
7647 :
7648 : /* Called from finish_struct_1. linear(this) or linear(this:step)
7649 : clauses might not be finalized yet because the class has been incomplete
7650 : when parsing #pragma omp declare simd methods. Fix those up now. */
7651 :
7652 : void
7653 118627 : finish_omp_declare_simd_methods (tree t)
7654 : {
7655 118627 : if (processing_template_decl)
7656 : return;
7657 :
7658 809768 : for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
7659 : {
7660 1143994 : if (TREE_CODE (x) == USING_DECL
7661 691141 : || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
7662 452853 : continue;
7663 238288 : tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
7664 238396 : if (!ods || !TREE_VALUE (ods))
7665 238180 : continue;
7666 366 : for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
7667 258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7668 66 : && integer_zerop (OMP_CLAUSE_DECL (c))
7669 18 : && OMP_CLAUSE_LINEAR_STEP (c)
7670 276 : && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
7671 : {
7672 18 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
7673 18 : s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
7674 18 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
7675 18 : sizetype, s, TYPE_SIZE_UNIT (t));
7676 18 : OMP_CLAUSE_LINEAR_STEP (c) = s;
7677 : }
7678 : }
7679 : }
7680 :
7681 : /* Adjust sink depend/doacross clause to take into account pointer offsets.
7682 :
7683 : Return TRUE if there was a problem processing the offset, and the
7684 : whole clause should be removed. */
7685 :
7686 : static bool
7687 298 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
7688 : {
7689 298 : tree t = OMP_CLAUSE_DECL (sink_clause);
7690 298 : gcc_assert (TREE_CODE (t) == TREE_LIST);
7691 :
7692 : /* Make sure we don't adjust things twice for templates. */
7693 298 : if (processing_template_decl)
7694 : return false;
7695 :
7696 671 : for (; t; t = TREE_CHAIN (t))
7697 : {
7698 391 : tree decl = TREE_VALUE (t);
7699 391 : if (TYPE_PTR_P (TREE_TYPE (decl)))
7700 : {
7701 6 : tree offset = TREE_PURPOSE (t);
7702 6 : bool neg = wi::neg_p (wi::to_wide (offset));
7703 6 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
7704 6 : decl = mark_rvalue_use (decl);
7705 6 : decl = convert_from_reference (decl);
7706 12 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
7707 : neg ? MINUS_EXPR : PLUS_EXPR,
7708 : decl, offset);
7709 6 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
7710 : MINUS_EXPR, sizetype,
7711 : fold_convert (sizetype, t2),
7712 : fold_convert (sizetype, decl));
7713 6 : if (t2 == error_mark_node)
7714 : return true;
7715 6 : TREE_PURPOSE (t) = t2;
7716 : }
7717 : }
7718 : return false;
7719 : }
7720 :
7721 : /* Finish OpenMP iterators ITER. Return true if they are erroneous
7722 : and clauses containing them should be removed. */
7723 :
7724 : static bool
7725 615 : cp_omp_finish_iterators (tree iter)
7726 : {
7727 615 : bool ret = false;
7728 1395 : for (tree it = iter; it; it = TREE_CHAIN (it))
7729 : {
7730 780 : tree var = OMP_ITERATOR_VAR (it);
7731 780 : tree begin = OMP_ITERATOR_BEGIN (it);
7732 780 : tree end = OMP_ITERATOR_END (it);
7733 780 : tree step = OMP_ITERATOR_STEP (it);
7734 780 : tree orig_step;
7735 780 : tree type = TREE_TYPE (var);
7736 780 : location_t loc = DECL_SOURCE_LOCATION (var);
7737 780 : if (type == error_mark_node)
7738 : {
7739 0 : ret = true;
7740 218 : continue;
7741 : }
7742 780 : if (type_dependent_expression_p (var))
7743 59 : continue;
7744 721 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
7745 : {
7746 27 : error_at (loc, "iterator %qD has neither integral nor pointer type",
7747 : var);
7748 27 : ret = true;
7749 27 : continue;
7750 : }
7751 694 : else if (TYPE_READONLY (type))
7752 : {
7753 24 : error_at (loc, "iterator %qD has const qualified type", var);
7754 24 : ret = true;
7755 24 : continue;
7756 : }
7757 670 : if (type_dependent_expression_p (begin)
7758 661 : || type_dependent_expression_p (end)
7759 1331 : || type_dependent_expression_p (step))
7760 15 : continue;
7761 655 : else if (error_operand_p (step))
7762 : {
7763 0 : ret = true;
7764 0 : continue;
7765 : }
7766 655 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
7767 : {
7768 21 : error_at (EXPR_LOC_OR_LOC (step, loc),
7769 : "iterator step with non-integral type");
7770 21 : ret = true;
7771 21 : continue;
7772 : }
7773 :
7774 634 : begin = mark_rvalue_use (begin);
7775 634 : end = mark_rvalue_use (end);
7776 634 : step = mark_rvalue_use (step);
7777 634 : begin = cp_build_c_cast (input_location, type, begin,
7778 : tf_warning_or_error);
7779 634 : end = cp_build_c_cast (input_location, type, end,
7780 : tf_warning_or_error);
7781 634 : orig_step = step;
7782 634 : if (!processing_template_decl)
7783 557 : step = orig_step = save_expr (step);
7784 634 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
7785 634 : step = cp_build_c_cast (input_location, stype, step,
7786 : tf_warning_or_error);
7787 634 : if (POINTER_TYPE_P (type) && !processing_template_decl)
7788 : {
7789 66 : begin = save_expr (begin);
7790 66 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
7791 66 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
7792 : fold_convert (sizetype, step),
7793 : fold_convert (sizetype, begin));
7794 66 : step = fold_convert (ssizetype, step);
7795 : }
7796 634 : if (!processing_template_decl)
7797 : {
7798 557 : begin = maybe_constant_value (begin);
7799 557 : end = maybe_constant_value (end);
7800 557 : step = maybe_constant_value (step);
7801 557 : orig_step = maybe_constant_value (orig_step);
7802 : }
7803 634 : if (integer_zerop (step))
7804 : {
7805 27 : error_at (loc, "iterator %qD has zero step", var);
7806 27 : ret = true;
7807 27 : continue;
7808 : }
7809 :
7810 607 : if (begin == error_mark_node
7811 598 : || end == error_mark_node
7812 589 : || step == error_mark_node
7813 589 : || orig_step == error_mark_node)
7814 : {
7815 18 : ret = true;
7816 18 : continue;
7817 : }
7818 :
7819 589 : if (!processing_template_decl)
7820 : {
7821 512 : begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
7822 512 : end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
7823 512 : step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
7824 512 : orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
7825 : orig_step);
7826 : }
7827 589 : hash_set<tree> pset;
7828 589 : tree it2;
7829 745 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
7830 : {
7831 183 : tree var2 = OMP_ITERATOR_VAR (it2);
7832 183 : tree begin2 = OMP_ITERATOR_BEGIN (it2);
7833 183 : tree end2 = OMP_ITERATOR_END (it2);
7834 183 : tree step2 = OMP_ITERATOR_STEP (it2);
7835 183 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
7836 183 : if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
7837 : {
7838 9 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
7839 : "begin expression refers to outer iterator %qD", var);
7840 36 : break;
7841 : }
7842 174 : else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
7843 : {
7844 9 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
7845 : "end expression refers to outer iterator %qD", var);
7846 9 : break;
7847 : }
7848 165 : else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
7849 : {
7850 9 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
7851 : "step expression refers to outer iterator %qD", var);
7852 9 : break;
7853 : }
7854 : }
7855 589 : if (it2)
7856 : {
7857 27 : ret = true;
7858 27 : continue;
7859 : }
7860 562 : OMP_ITERATOR_BEGIN (it) = begin;
7861 562 : OMP_ITERATOR_END (it) = end;
7862 562 : if (processing_template_decl)
7863 71 : OMP_ITERATOR_STEP (it) = orig_step;
7864 : else
7865 : {
7866 491 : OMP_ITERATOR_STEP (it) = step;
7867 491 : OMP_ITERATOR_ORIG_STEP (it) = orig_step;
7868 : }
7869 589 : }
7870 615 : return ret;
7871 : }
7872 :
7873 : /* Ensure that pointers are used in OpenACC attach and detach clauses.
7874 : Return true if an error has been detected. */
7875 :
7876 : static bool
7877 18831 : cp_oacc_check_attachments (tree c)
7878 : {
7879 18831 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
7880 : return false;
7881 :
7882 : /* OpenACC attach / detach clauses must be pointers. */
7883 14805 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
7884 14805 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
7885 : {
7886 196 : tree t = OMP_CLAUSE_DECL (c);
7887 196 : tree type;
7888 :
7889 232 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7890 36 : t = TREE_OPERAND (t, 0);
7891 :
7892 196 : type = TREE_TYPE (t);
7893 :
7894 196 : if (TREE_CODE (type) == REFERENCE_TYPE)
7895 36 : type = TREE_TYPE (type);
7896 :
7897 196 : if (TREE_CODE (type) != POINTER_TYPE)
7898 : {
7899 36 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
7900 : user_omp_clause_code_name (c, true));
7901 36 : return true;
7902 : }
7903 : }
7904 :
7905 : return false;
7906 : }
7907 :
7908 : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
7909 : happened. */
7910 :
7911 : tree
7912 813 : cp_finish_omp_init_prefer_type (tree pref_type)
7913 : {
7914 813 : if (processing_template_decl
7915 741 : || pref_type == NULL_TREE
7916 356 : || TREE_CODE (pref_type) != TREE_LIST)
7917 : return pref_type;
7918 :
7919 81 : tree t = TREE_PURPOSE (pref_type);
7920 81 : char *str = const_cast<char *> (TREE_STRING_POINTER (t));
7921 81 : tree fr_list = TREE_VALUE (pref_type);
7922 81 : int len = TREE_VEC_LENGTH (fr_list);
7923 81 : int cnt = 0;
7924 :
7925 270 : while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
7926 : {
7927 270 : str++;
7928 270 : if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
7929 : {
7930 : /* Assume a no or a single 'fr'. */
7931 150 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7932 150 : location_t loc = UNKNOWN_LOCATION;
7933 150 : tree value = TREE_VEC_ELT (fr_list, cnt);
7934 150 : if (value != NULL_TREE && value != error_mark_node)
7935 : {
7936 126 : loc = EXPR_LOCATION (value);
7937 126 : if (value && TREE_CODE (value) == NOP_EXPR)
7938 39 : value = TREE_OPERAND (value, 0);
7939 126 : value = cp_fully_fold (value);
7940 : }
7941 126 : if (value != NULL_TREE && value != error_mark_node)
7942 : {
7943 126 : if (TREE_CODE (value) != INTEGER_CST
7944 126 : || !tree_fits_shwi_p (value))
7945 0 : error_at (loc,
7946 : "expected string literal or "
7947 : "constant integer expression instead of %qE", value);
7948 : else
7949 : {
7950 126 : HOST_WIDE_INT n = tree_to_shwi (value);
7951 126 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
7952 : {
7953 48 : warning_at (loc, OPT_Wopenmp,
7954 : "unknown foreign runtime identifier %qwd", n);
7955 48 : n = GOMP_INTEROP_IFR_UNKNOWN;
7956 : }
7957 126 : str[0] = (char) n;
7958 : }
7959 : }
7960 150 : str++;
7961 : }
7962 120 : else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
7963 : {
7964 : /* Assume a no or a single 'fr'. */
7965 120 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7966 120 : str++;
7967 : }
7968 270 : str++;
7969 294 : while (str[0] != '\0')
7970 24 : str += strlen (str) + 1;
7971 270 : str++;
7972 270 : cnt++;
7973 270 : if (cnt >= len)
7974 : break;
7975 : }
7976 : return t;
7977 : }
7978 :
7979 : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
7980 : Remove any elements from the list that are invalid. */
7981 :
7982 : tree
7983 63466 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
7984 : {
7985 63466 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
7986 63466 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
7987 63466 : bitmap_head oacc_reduction_head, is_on_device_head;
7988 63466 : tree c, t, *pc;
7989 63466 : tree safelen = NULL_TREE;
7990 63466 : bool openacc = (ort & C_ORT_ACC) != 0;
7991 63466 : bool branch_seen = false;
7992 63466 : bool copyprivate_seen = false;
7993 63466 : bool ordered_seen = false;
7994 63466 : bool order_seen = false;
7995 63466 : bool schedule_seen = false;
7996 63466 : bool oacc_async = false;
7997 63466 : bool indir_component_ref_p = false;
7998 63466 : tree last_iterators = NULL_TREE;
7999 63466 : bool last_iterators_remove = false;
8000 : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
8001 : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
8002 63466 : int reduction_seen = 0;
8003 63466 : bool allocate_seen = false;
8004 63466 : tree detach_seen = NULL_TREE;
8005 63466 : bool mergeable_seen = false;
8006 63466 : bool implicit_moved = false;
8007 63466 : bool target_in_reduction_seen = false;
8008 63466 : bool num_tasks_seen = false;
8009 63466 : bool partial_seen = false;
8010 63466 : bool init_seen = false;
8011 63466 : bool init_use_destroy_seen = false;
8012 63466 : tree init_no_targetsync_clause = NULL_TREE;
8013 63466 : tree depend_clause = NULL_TREE;
8014 :
8015 63466 : if (!openacc)
8016 50645 : clauses = omp_remove_duplicate_maps (clauses, true);
8017 :
8018 63466 : bitmap_obstack_initialize (NULL);
8019 63466 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
8020 63466 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
8021 63466 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
8022 63466 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
8023 : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
8024 63466 : bitmap_initialize (&map_head, &bitmap_default_obstack);
8025 63466 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
8026 63466 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
8027 : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
8028 : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
8029 63466 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
8030 63466 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
8031 :
8032 63466 : if (openacc)
8033 28440 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
8034 16007 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
8035 : {
8036 : oacc_async = true;
8037 : break;
8038 : }
8039 :
8040 63466 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
8041 :
8042 162391 : for (pc = &clauses, c = clauses; c ; c = *pc)
8043 : {
8044 98925 : bool remove = false;
8045 98925 : bool field_ok = false;
8046 :
8047 : /* We've reached the end of a list of expanded nodes. Reset the group
8048 : start pointer. */
8049 98925 : if (c == grp_sentinel)
8050 : {
8051 5707 : if (grp_start_p
8052 5707 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
8053 96 : for (tree gc = *grp_start_p; gc != grp_sentinel;
8054 66 : gc = OMP_CLAUSE_CHAIN (gc))
8055 66 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
8056 : grp_start_p = NULL;
8057 : }
8058 :
8059 98925 : switch (OMP_CLAUSE_CODE (c))
8060 : {
8061 2100 : case OMP_CLAUSE_SHARED:
8062 2100 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8063 2100 : goto check_dup_generic;
8064 2584 : case OMP_CLAUSE_PRIVATE:
8065 2584 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8066 2584 : goto check_dup_generic;
8067 7548 : case OMP_CLAUSE_REDUCTION:
8068 7548 : if (reduction_seen == 0)
8069 6429 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
8070 1119 : else if (reduction_seen != -2
8071 2238 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
8072 1119 : ? -1 : 1))
8073 : {
8074 6 : error_at (OMP_CLAUSE_LOCATION (c),
8075 : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
8076 : "on the same construct");
8077 6 : reduction_seen = -2;
8078 : }
8079 : /* FALLTHRU */
8080 9693 : case OMP_CLAUSE_IN_REDUCTION:
8081 9693 : case OMP_CLAUSE_TASK_REDUCTION:
8082 9693 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8083 9693 : t = OMP_CLAUSE_DECL (c);
8084 9693 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
8085 : {
8086 2315 : if (handle_omp_array_sections (c, ort))
8087 : {
8088 : remove = true;
8089 : break;
8090 : }
8091 2273 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
8092 2273 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
8093 : {
8094 3 : error_at (OMP_CLAUSE_LOCATION (c),
8095 : "%<inscan%> %<reduction%> clause with array "
8096 : "section");
8097 3 : remove = true;
8098 3 : break;
8099 : }
8100 2270 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
8101 : {
8102 4888 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
8103 2618 : t = TREE_OPERAND (t, 0);
8104 : }
8105 : else
8106 : {
8107 0 : gcc_assert (TREE_CODE (t) == MEM_REF);
8108 0 : t = TREE_OPERAND (t, 0);
8109 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
8110 0 : t = TREE_OPERAND (t, 0);
8111 0 : if (TREE_CODE (t) == ADDR_EXPR
8112 0 : || INDIRECT_REF_P (t))
8113 0 : t = TREE_OPERAND (t, 0);
8114 : }
8115 2270 : tree n = omp_clause_decl_field (t);
8116 2270 : if (n)
8117 59 : t = n;
8118 2270 : goto check_dup_generic_t;
8119 : }
8120 7378 : if (oacc_async)
8121 7 : cxx_mark_addressable (t);
8122 7378 : goto check_dup_generic;
8123 98 : case OMP_CLAUSE_COPYPRIVATE:
8124 98 : copyprivate_seen = true;
8125 98 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8126 98 : goto check_dup_generic;
8127 280 : case OMP_CLAUSE_COPYIN:
8128 280 : goto check_dup_generic;
8129 1631 : case OMP_CLAUSE_LINEAR:
8130 1631 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8131 1631 : t = OMP_CLAUSE_DECL (c);
8132 1631 : if (ort != C_ORT_OMP_DECLARE_SIMD
8133 1631 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
8134 : {
8135 84 : if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
8136 : {
8137 42 : error_at (OMP_CLAUSE_LOCATION (c),
8138 : "modifier should not be specified in %<linear%> "
8139 : "clause on %<simd%> or %<for%> constructs when "
8140 : "not using OpenMP 5.2 modifiers");
8141 42 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
8142 : }
8143 42 : else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
8144 : {
8145 18 : error_at (OMP_CLAUSE_LOCATION (c),
8146 : "modifier other than %<val%> specified in "
8147 : "%<linear%> clause on %<simd%> or %<for%> "
8148 : "constructs when using OpenMP 5.2 modifiers");
8149 18 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
8150 : }
8151 : }
8152 1011 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
8153 2571 : && !type_dependent_expression_p (t))
8154 : {
8155 1529 : tree type = TREE_TYPE (t);
8156 1529 : if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
8157 1448 : || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
8158 1598 : && !TYPE_REF_P (type))
8159 : {
8160 12 : error_at (OMP_CLAUSE_LOCATION (c),
8161 : "linear clause with %qs modifier applied to "
8162 : "non-reference variable with %qT type",
8163 12 : OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
8164 12 : ? "ref" : "uval", TREE_TYPE (t));
8165 12 : remove = true;
8166 12 : break;
8167 : }
8168 1517 : if (TYPE_REF_P (type))
8169 281 : type = TREE_TYPE (type);
8170 1517 : if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
8171 : {
8172 1442 : if (!INTEGRAL_TYPE_P (type)
8173 85 : && !TYPE_PTR_P (type))
8174 : {
8175 18 : error_at (OMP_CLAUSE_LOCATION (c),
8176 : "linear clause applied to non-integral "
8177 : "non-pointer variable with %qT type",
8178 18 : TREE_TYPE (t));
8179 18 : remove = true;
8180 18 : break;
8181 : }
8182 : }
8183 : }
8184 1601 : t = OMP_CLAUSE_LINEAR_STEP (c);
8185 1601 : if (t == NULL_TREE)
8186 6 : t = integer_one_node;
8187 1601 : if (t == error_mark_node)
8188 : {
8189 : remove = true;
8190 : break;
8191 : }
8192 1601 : else if (!type_dependent_expression_p (t)
8193 1599 : && !INTEGRAL_TYPE_P (TREE_TYPE (t))
8194 1613 : && (ort != C_ORT_OMP_DECLARE_SIMD
8195 9 : || TREE_CODE (t) != PARM_DECL
8196 6 : || !TYPE_REF_P (TREE_TYPE (t))
8197 6 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
8198 : {
8199 6 : error_at (OMP_CLAUSE_LOCATION (c),
8200 : "linear step expression must be integral");
8201 6 : remove = true;
8202 6 : break;
8203 : }
8204 : else
8205 : {
8206 1595 : t = mark_rvalue_use (t);
8207 1595 : if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
8208 : {
8209 42 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
8210 42 : goto check_dup_generic;
8211 : }
8212 1553 : if (!processing_template_decl
8213 1553 : && (VAR_P (OMP_CLAUSE_DECL (c))
8214 835 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
8215 : {
8216 1372 : if (ort == C_ORT_OMP_DECLARE_SIMD)
8217 : {
8218 589 : t = maybe_constant_value (t);
8219 589 : if (TREE_CODE (t) != INTEGER_CST)
8220 : {
8221 6 : error_at (OMP_CLAUSE_LOCATION (c),
8222 : "%<linear%> clause step %qE is neither "
8223 : "constant nor a parameter", t);
8224 6 : remove = true;
8225 6 : break;
8226 : }
8227 : }
8228 1366 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8229 1366 : tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
8230 1366 : if (TYPE_REF_P (type))
8231 257 : type = TREE_TYPE (type);
8232 1366 : if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
8233 : {
8234 66 : type = build_pointer_type (type);
8235 66 : tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
8236 66 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8237 : d, t);
8238 66 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8239 : MINUS_EXPR, sizetype,
8240 : fold_convert (sizetype, t),
8241 : fold_convert (sizetype, d));
8242 66 : if (t == error_mark_node)
8243 : {
8244 : remove = true;
8245 : break;
8246 : }
8247 : }
8248 1300 : else if (TYPE_PTR_P (type)
8249 : /* Can't multiply the step yet if *this
8250 : is still incomplete type. */
8251 1300 : && (ort != C_ORT_OMP_DECLARE_SIMD
8252 45 : || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
8253 45 : || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
8254 30 : || DECL_NAME (OMP_CLAUSE_DECL (c))
8255 30 : != this_identifier
8256 30 : || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
8257 : {
8258 37 : tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
8259 37 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8260 : d, t);
8261 37 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8262 : MINUS_EXPR, sizetype,
8263 : fold_convert (sizetype, t),
8264 : fold_convert (sizetype, d));
8265 37 : if (t == error_mark_node)
8266 : {
8267 : remove = true;
8268 : break;
8269 : }
8270 : }
8271 : else
8272 1263 : t = fold_convert (type, t);
8273 : }
8274 1547 : OMP_CLAUSE_LINEAR_STEP (c) = t;
8275 : }
8276 1547 : goto check_dup_generic;
8277 14995 : check_dup_generic:
8278 14995 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8279 14995 : if (t)
8280 : {
8281 101 : if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
8282 101 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8283 : }
8284 : else
8285 14894 : t = OMP_CLAUSE_DECL (c);
8286 17532 : check_dup_generic_t:
8287 17532 : if (t == current_class_ptr
8288 17532 : && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
8289 102 : || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
8290 72 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
8291 : {
8292 24 : error_at (OMP_CLAUSE_LOCATION (c),
8293 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8294 : " clauses");
8295 24 : remove = true;
8296 24 : break;
8297 : }
8298 17508 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8299 586 : && (!field_ok || TREE_CODE (t) != FIELD_DECL))
8300 : {
8301 59 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8302 : break;
8303 39 : if (DECL_P (t))
8304 30 : error_at (OMP_CLAUSE_LOCATION (c),
8305 : "%qD is not a variable in clause %qs", t,
8306 15 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8307 : else
8308 48 : error_at (OMP_CLAUSE_LOCATION (c),
8309 : "%qE is not a variable in clause %qs", t,
8310 24 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8311 : remove = true;
8312 : }
8313 17449 : else if ((openacc
8314 2707 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
8315 14980 : || (ort == C_ORT_OMP
8316 12647 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
8317 12616 : || (OMP_CLAUSE_CODE (c)
8318 : == OMP_CLAUSE_USE_DEVICE_ADDR)))
8319 32322 : || (ort == C_ORT_OMP_TARGET
8320 938 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
8321 : {
8322 2854 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
8323 2854 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8324 275 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
8325 : {
8326 6 : error_at (OMP_CLAUSE_LOCATION (c),
8327 : "%qD appears more than once in data-sharing "
8328 : "clauses", t);
8329 6 : remove = true;
8330 6 : break;
8331 : }
8332 2848 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
8333 272 : target_in_reduction_seen = true;
8334 2848 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8335 : {
8336 12 : error_at (OMP_CLAUSE_LOCATION (c),
8337 : openacc
8338 : ? "%qD appears more than once in reduction clauses"
8339 : : "%qD appears more than once in data clauses",
8340 : t);
8341 6 : remove = true;
8342 : }
8343 : else
8344 2842 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8345 : }
8346 14595 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8347 14522 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8348 14519 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
8349 29114 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8350 : {
8351 76 : error_at (OMP_CLAUSE_LOCATION (c),
8352 : "%qD appears more than once in data clauses", t);
8353 76 : remove = true;
8354 : }
8355 14519 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
8356 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
8357 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
8358 3125 : && bitmap_bit_p (&map_head, DECL_UID (t)))
8359 : {
8360 9 : if (openacc)
8361 0 : error_at (OMP_CLAUSE_LOCATION (c),
8362 : "%qD appears more than once in data clauses", t);
8363 : else
8364 9 : error_at (OMP_CLAUSE_LOCATION (c),
8365 : "%qD appears both in data and map clauses", t);
8366 : remove = true;
8367 : }
8368 : else
8369 14510 : bitmap_set_bit (&generic_head, DECL_UID (t));
8370 17482 : if (!field_ok)
8371 : break;
8372 13071 : handle_field_decl:
8373 21825 : if (!remove
8374 21630 : && TREE_CODE (t) == FIELD_DECL
8375 16940 : && t == OMP_CLAUSE_DECL (c))
8376 : {
8377 795 : OMP_CLAUSE_DECL (c)
8378 795 : = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
8379 : == OMP_CLAUSE_SHARED));
8380 795 : if (OMP_CLAUSE_DECL (c) == error_mark_node)
8381 98456 : remove = true;
8382 : }
8383 : break;
8384 :
8385 3486 : case OMP_CLAUSE_FIRSTPRIVATE:
8386 3486 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
8387 : {
8388 414 : move_implicit:
8389 414 : implicit_moved = true;
8390 : /* Move firstprivate and map clauses with
8391 : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
8392 : clauses chain. */
8393 414 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
8394 414 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
8395 2704 : while (*pc1)
8396 2290 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
8397 2290 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
8398 : {
8399 275 : *pc3 = *pc1;
8400 275 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
8401 275 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8402 : }
8403 2015 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
8404 2015 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
8405 : {
8406 370 : *pc2 = *pc1;
8407 370 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
8408 370 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8409 : }
8410 : else
8411 1645 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
8412 414 : *pc3 = NULL;
8413 414 : *pc2 = cl2;
8414 414 : *pc1 = cl1;
8415 414 : continue;
8416 414 : }
8417 3229 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8418 3229 : if (t)
8419 69 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8420 : else
8421 3160 : t = OMP_CLAUSE_DECL (c);
8422 3229 : if (!openacc && t == current_class_ptr)
8423 : {
8424 6 : error_at (OMP_CLAUSE_LOCATION (c),
8425 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8426 : " clauses");
8427 6 : remove = true;
8428 6 : break;
8429 : }
8430 3223 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8431 333 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8432 333 : || TREE_CODE (t) != FIELD_DECL))
8433 : {
8434 41 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8435 : break;
8436 18 : if (DECL_P (t))
8437 12 : error_at (OMP_CLAUSE_LOCATION (c),
8438 : "%qD is not a variable in clause %<firstprivate%>",
8439 : t);
8440 : else
8441 6 : error_at (OMP_CLAUSE_LOCATION (c),
8442 : "%qE is not a variable in clause %<firstprivate%>",
8443 : t);
8444 : remove = true;
8445 : }
8446 3182 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8447 275 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
8448 3436 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8449 : remove = true;
8450 3182 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8451 3173 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8452 6352 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8453 : {
8454 15 : error_at (OMP_CLAUSE_LOCATION (c),
8455 : "%qD appears more than once in data clauses", t);
8456 15 : remove = true;
8457 : }
8458 3167 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8459 3167 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
8460 : {
8461 21 : if (openacc)
8462 0 : error_at (OMP_CLAUSE_LOCATION (c),
8463 : "%qD appears more than once in data clauses", t);
8464 21 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8465 21 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
8466 : /* Silently drop the clause. */;
8467 : else
8468 18 : error_at (OMP_CLAUSE_LOCATION (c),
8469 : "%qD appears both in data and map clauses", t);
8470 : remove = true;
8471 : }
8472 : else
8473 3146 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
8474 3200 : goto handle_field_decl;
8475 :
8476 2793 : case OMP_CLAUSE_LASTPRIVATE:
8477 2793 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8478 2793 : if (t)
8479 35 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8480 : else
8481 2758 : t = OMP_CLAUSE_DECL (c);
8482 2793 : if (!openacc && t == current_class_ptr)
8483 : {
8484 6 : error_at (OMP_CLAUSE_LOCATION (c),
8485 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8486 : " clauses");
8487 6 : remove = true;
8488 6 : break;
8489 : }
8490 2787 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8491 259 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8492 259 : || TREE_CODE (t) != FIELD_DECL))
8493 : {
8494 35 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8495 : break;
8496 9 : if (DECL_P (t))
8497 3 : error_at (OMP_CLAUSE_LOCATION (c),
8498 : "%qD is not a variable in clause %<lastprivate%>",
8499 : t);
8500 : else
8501 6 : error_at (OMP_CLAUSE_LOCATION (c),
8502 : "%qE is not a variable in clause %<lastprivate%>",
8503 : t);
8504 : remove = true;
8505 : }
8506 2752 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8507 2752 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8508 : {
8509 12 : error_at (OMP_CLAUSE_LOCATION (c),
8510 : "%qD appears more than once in data clauses", t);
8511 12 : remove = true;
8512 : }
8513 : else
8514 2740 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
8515 2761 : goto handle_field_decl;
8516 :
8517 2221 : case OMP_CLAUSE_IF:
8518 2221 : case OMP_CLAUSE_SELF:
8519 2221 : t = OMP_CLAUSE_OPERAND (c, 0);
8520 2221 : t = maybe_convert_cond (t);
8521 2221 : if (t == error_mark_node)
8522 : remove = true;
8523 2206 : else if (!processing_template_decl)
8524 2145 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8525 2221 : OMP_CLAUSE_OPERAND (c, 0) = t;
8526 2221 : break;
8527 :
8528 289 : case OMP_CLAUSE_FINAL:
8529 289 : t = OMP_CLAUSE_FINAL_EXPR (c);
8530 289 : t = maybe_convert_cond (t);
8531 289 : if (t == error_mark_node)
8532 : remove = true;
8533 289 : else if (!processing_template_decl)
8534 283 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8535 289 : OMP_CLAUSE_FINAL_EXPR (c) = t;
8536 289 : break;
8537 :
8538 92 : case OMP_CLAUSE_NOCONTEXT:
8539 92 : t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
8540 92 : t = maybe_convert_cond (t);
8541 92 : if (t == error_mark_node)
8542 : remove = true;
8543 89 : else if (!processing_template_decl)
8544 83 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8545 92 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
8546 92 : break;
8547 :
8548 80 : case OMP_CLAUSE_NOVARIANTS:
8549 80 : t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
8550 80 : t = maybe_convert_cond (t);
8551 80 : if (t == error_mark_node)
8552 : remove = true;
8553 77 : else if (!processing_template_decl)
8554 71 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8555 80 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
8556 80 : break;
8557 :
8558 1249 : case OMP_CLAUSE_GANG:
8559 : /* Operand 1 is the gang static: argument. */
8560 1249 : t = OMP_CLAUSE_OPERAND (c, 1);
8561 1249 : if (t != NULL_TREE)
8562 : {
8563 129 : if (t == error_mark_node)
8564 : remove = true;
8565 129 : else if (!type_dependent_expression_p (t)
8566 129 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8567 : {
8568 6 : error_at (OMP_CLAUSE_LOCATION (c),
8569 : "%<gang%> static expression must be integral");
8570 6 : remove = true;
8571 : }
8572 : else
8573 : {
8574 123 : t = mark_rvalue_use (t);
8575 123 : if (!processing_template_decl)
8576 : {
8577 123 : t = maybe_constant_value (t);
8578 123 : if (TREE_CODE (t) == INTEGER_CST
8579 109 : && tree_int_cst_sgn (t) != 1
8580 176 : && t != integer_minus_one_node)
8581 : {
8582 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8583 : "%<gang%> static value must be "
8584 : "positive");
8585 0 : t = integer_one_node;
8586 : }
8587 123 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8588 : }
8589 : }
8590 129 : OMP_CLAUSE_OPERAND (c, 1) = t;
8591 : }
8592 : /* Check operand 0, the num argument. */
8593 : /* FALLTHRU */
8594 :
8595 3480 : case OMP_CLAUSE_WORKER:
8596 3480 : case OMP_CLAUSE_VECTOR:
8597 3480 : if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
8598 : break;
8599 : /* FALLTHRU */
8600 :
8601 484 : case OMP_CLAUSE_NUM_TASKS:
8602 484 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
8603 136 : num_tasks_seen = true;
8604 : /* FALLTHRU */
8605 :
8606 3034 : case OMP_CLAUSE_NUM_TEAMS:
8607 3034 : case OMP_CLAUSE_NUM_THREADS:
8608 3034 : case OMP_CLAUSE_NUM_GANGS:
8609 3034 : case OMP_CLAUSE_NUM_WORKERS:
8610 3034 : case OMP_CLAUSE_DYN_GROUPPRIVATE:
8611 3034 : case OMP_CLAUSE_VECTOR_LENGTH:
8612 3034 : t = OMP_CLAUSE_OPERAND (c, 0);
8613 3034 : if (t == error_mark_node)
8614 : remove = true;
8615 3034 : else if (!type_dependent_expression_p (t)
8616 3034 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8617 : {
8618 99 : switch (OMP_CLAUSE_CODE (c))
8619 : {
8620 12 : case OMP_CLAUSE_GANG:
8621 12 : error_at (OMP_CLAUSE_LOCATION (c),
8622 12 : "%<gang%> num expression must be integral"); break;
8623 12 : case OMP_CLAUSE_VECTOR:
8624 12 : error_at (OMP_CLAUSE_LOCATION (c),
8625 : "%<vector%> length expression must be integral");
8626 12 : break;
8627 12 : case OMP_CLAUSE_WORKER:
8628 12 : error_at (OMP_CLAUSE_LOCATION (c),
8629 : "%<worker%> num expression must be integral");
8630 12 : break;
8631 63 : default:
8632 63 : error_at (OMP_CLAUSE_LOCATION (c),
8633 : "%qs expression must be integral",
8634 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8635 : }
8636 : remove = true;
8637 : }
8638 : else
8639 : {
8640 2935 : t = mark_rvalue_use (t);
8641 2935 : if (!processing_template_decl)
8642 : {
8643 2687 : t = maybe_constant_value (t);
8644 2687 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
8645 2652 : && TREE_CODE (t) == INTEGER_CST
8646 4142 : && tree_int_cst_sgn (t) != 1)
8647 : {
8648 85 : switch (OMP_CLAUSE_CODE (c))
8649 : {
8650 3 : case OMP_CLAUSE_GANG:
8651 3 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8652 : "%<gang%> num value must be positive");
8653 3 : break;
8654 0 : case OMP_CLAUSE_VECTOR:
8655 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8656 : "%<vector%> length value must be "
8657 : "positive");
8658 0 : break;
8659 0 : case OMP_CLAUSE_WORKER:
8660 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8661 : "%<worker%> num value must be "
8662 : "positive");
8663 0 : break;
8664 82 : default:
8665 82 : warning_at (OMP_CLAUSE_LOCATION (c),
8666 46 : (flag_openmp || flag_openmp_simd)
8667 82 : ? OPT_Wopenmp : 0,
8668 : "%qs value must be positive",
8669 : omp_clause_code_name
8670 82 : [OMP_CLAUSE_CODE (c)]);
8671 : }
8672 85 : t = integer_one_node;
8673 : }
8674 2602 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
8675 35 : && TREE_CODE (t) == INTEGER_CST
8676 2625 : && tree_int_cst_sgn (t) < 0)
8677 : {
8678 8 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8679 : "%<dyn_groupprivate%> value must be "
8680 : "non-negative");
8681 8 : t = integer_zero_node;
8682 : }
8683 2687 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8684 : }
8685 2935 : OMP_CLAUSE_OPERAND (c, 0) = t;
8686 : }
8687 3034 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
8688 752 : && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
8689 3313 : && !remove)
8690 : {
8691 279 : t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
8692 279 : if (t == error_mark_node)
8693 : remove = true;
8694 279 : else if (!type_dependent_expression_p (t)
8695 279 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8696 : {
8697 0 : error_at (OMP_CLAUSE_LOCATION (c),
8698 : "%qs expression must be integral",
8699 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8700 0 : remove = true;
8701 : }
8702 : else
8703 : {
8704 279 : t = mark_rvalue_use (t);
8705 279 : if (!processing_template_decl)
8706 : {
8707 213 : t = maybe_constant_value (t);
8708 213 : if (TREE_CODE (t) == INTEGER_CST
8709 213 : && tree_int_cst_sgn (t) != 1)
8710 : {
8711 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8712 : "%qs value must be positive",
8713 : omp_clause_code_name
8714 18 : [OMP_CLAUSE_CODE (c)]);
8715 18 : t = NULL_TREE;
8716 : }
8717 : else
8718 195 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8719 213 : tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
8720 213 : if (t
8721 195 : && TREE_CODE (t) == INTEGER_CST
8722 43 : && TREE_CODE (upper) == INTEGER_CST
8723 250 : && tree_int_cst_lt (upper, t))
8724 : {
8725 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8726 : "%<num_teams%> lower bound %qE bigger "
8727 : "than upper bound %qE", t, upper);
8728 18 : t = NULL_TREE;
8729 : }
8730 : }
8731 279 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
8732 : }
8733 : }
8734 : break;
8735 :
8736 3892 : case OMP_CLAUSE_SCHEDULE:
8737 3892 : t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
8738 3892 : if (t == NULL)
8739 : ;
8740 2093 : else if (t == error_mark_node)
8741 : remove = true;
8742 2093 : else if (!type_dependent_expression_p (t)
8743 2093 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8744 : {
8745 9 : error_at (OMP_CLAUSE_LOCATION (c),
8746 : "schedule chunk size expression must be integral");
8747 9 : remove = true;
8748 : }
8749 : else
8750 : {
8751 2084 : t = mark_rvalue_use (t);
8752 2084 : if (!processing_template_decl)
8753 : {
8754 2044 : t = maybe_constant_value (t);
8755 2044 : if (TREE_CODE (t) == INTEGER_CST
8756 2044 : && tree_int_cst_sgn (t) != 1)
8757 : {
8758 6 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8759 : "chunk size value must be positive");
8760 6 : t = integer_one_node;
8761 : }
8762 2044 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8763 : }
8764 2084 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8765 : }
8766 2093 : if (!remove)
8767 : schedule_seen = true;
8768 : break;
8769 :
8770 1268 : case OMP_CLAUSE_SIMDLEN:
8771 1268 : case OMP_CLAUSE_SAFELEN:
8772 1268 : t = OMP_CLAUSE_OPERAND (c, 0);
8773 1268 : if (t == error_mark_node)
8774 : remove = true;
8775 1268 : else if (!type_dependent_expression_p (t)
8776 1268 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8777 : {
8778 0 : error_at (OMP_CLAUSE_LOCATION (c),
8779 : "%qs length expression must be integral",
8780 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8781 0 : remove = true;
8782 : }
8783 : else
8784 : {
8785 1268 : t = mark_rvalue_use (t);
8786 1268 : if (!processing_template_decl)
8787 : {
8788 1219 : t = maybe_constant_value (t);
8789 1219 : if (TREE_CODE (t) != INTEGER_CST
8790 1219 : || tree_int_cst_sgn (t) != 1)
8791 : {
8792 0 : error_at (OMP_CLAUSE_LOCATION (c),
8793 : "%qs length expression must be positive "
8794 : "constant integer expression",
8795 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8796 0 : remove = true;
8797 : }
8798 : }
8799 1268 : OMP_CLAUSE_OPERAND (c, 0) = t;
8800 1268 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
8801 470 : safelen = c;
8802 : }
8803 : break;
8804 :
8805 388 : case OMP_CLAUSE_ASYNC:
8806 388 : t = OMP_CLAUSE_ASYNC_EXPR (c);
8807 388 : if (t == error_mark_node)
8808 : remove = true;
8809 373 : else if (!type_dependent_expression_p (t)
8810 373 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8811 : {
8812 12 : error_at (OMP_CLAUSE_LOCATION (c),
8813 : "%<async%> expression must be integral");
8814 12 : remove = true;
8815 : }
8816 : else
8817 : {
8818 361 : t = mark_rvalue_use (t);
8819 361 : if (!processing_template_decl)
8820 352 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8821 361 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
8822 : }
8823 : break;
8824 :
8825 204 : case OMP_CLAUSE_WAIT:
8826 204 : t = OMP_CLAUSE_WAIT_EXPR (c);
8827 204 : if (t == error_mark_node)
8828 : remove = true;
8829 204 : else if (!processing_template_decl)
8830 196 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8831 204 : OMP_CLAUSE_WAIT_EXPR (c) = t;
8832 204 : break;
8833 :
8834 637 : case OMP_CLAUSE_THREAD_LIMIT:
8835 637 : t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
8836 637 : if (t == error_mark_node)
8837 : remove = true;
8838 637 : else if (!type_dependent_expression_p (t)
8839 637 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8840 : {
8841 0 : error_at (OMP_CLAUSE_LOCATION (c),
8842 : "%<thread_limit%> expression must be integral");
8843 0 : remove = true;
8844 : }
8845 : else
8846 : {
8847 637 : t = mark_rvalue_use (t);
8848 637 : if (!processing_template_decl)
8849 : {
8850 583 : t = maybe_constant_value (t);
8851 583 : if (TREE_CODE (t) == INTEGER_CST
8852 583 : && tree_int_cst_sgn (t) != 1)
8853 : {
8854 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8855 : "%<thread_limit%> value must be positive");
8856 0 : t = integer_one_node;
8857 : }
8858 583 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8859 : }
8860 637 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
8861 : }
8862 : break;
8863 :
8864 770 : case OMP_CLAUSE_DEVICE:
8865 770 : t = OMP_CLAUSE_DEVICE_ID (c);
8866 770 : if (t == error_mark_node)
8867 : remove = true;
8868 770 : else if (!type_dependent_expression_p (t)
8869 770 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8870 : {
8871 6 : error_at (OMP_CLAUSE_LOCATION (c),
8872 : "%<device%> id must be integral");
8873 6 : remove = true;
8874 : }
8875 764 : else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
8876 66 : && TREE_CODE (t) == INTEGER_CST
8877 824 : && !integer_onep (t))
8878 : {
8879 3 : error_at (OMP_CLAUSE_LOCATION (c),
8880 : "the %<device%> clause expression must evaluate to "
8881 : "%<1%>");
8882 3 : remove = true;
8883 : }
8884 : else
8885 : {
8886 761 : t = mark_rvalue_use (t);
8887 761 : if (!processing_template_decl)
8888 750 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8889 761 : OMP_CLAUSE_DEVICE_ID (c) = t;
8890 : }
8891 : break;
8892 :
8893 1848 : case OMP_CLAUSE_DIST_SCHEDULE:
8894 1848 : t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
8895 1848 : if (t == NULL)
8896 : ;
8897 1827 : else if (t == error_mark_node)
8898 : remove = true;
8899 1827 : else if (!type_dependent_expression_p (t)
8900 1827 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8901 : {
8902 0 : error_at (OMP_CLAUSE_LOCATION (c),
8903 : "%<dist_schedule%> chunk size expression must be "
8904 : "integral");
8905 0 : remove = true;
8906 : }
8907 : else
8908 : {
8909 1827 : t = mark_rvalue_use (t);
8910 1827 : if (!processing_template_decl)
8911 1827 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8912 1827 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
8913 : }
8914 : break;
8915 :
8916 807 : case OMP_CLAUSE_ALIGNED:
8917 807 : t = OMP_CLAUSE_DECL (c);
8918 807 : if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
8919 : {
8920 0 : error_at (OMP_CLAUSE_LOCATION (c),
8921 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8922 : " clauses");
8923 0 : remove = true;
8924 0 : break;
8925 : }
8926 807 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8927 : {
8928 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8929 : break;
8930 0 : if (DECL_P (t))
8931 0 : error_at (OMP_CLAUSE_LOCATION (c),
8932 : "%qD is not a variable in %<aligned%> clause", t);
8933 : else
8934 0 : error_at (OMP_CLAUSE_LOCATION (c),
8935 : "%qE is not a variable in %<aligned%> clause", t);
8936 : remove = true;
8937 : }
8938 807 : else if (!type_dependent_expression_p (t)
8939 789 : && !TYPE_PTR_P (TREE_TYPE (t))
8940 111 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
8941 864 : && (!TYPE_REF_P (TREE_TYPE (t))
8942 39 : || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
8943 30 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
8944 : != ARRAY_TYPE))))
8945 : {
8946 33 : error_at (OMP_CLAUSE_LOCATION (c),
8947 : "%qE in %<aligned%> clause is neither a pointer nor "
8948 : "an array nor a reference to pointer or array", t);
8949 33 : remove = true;
8950 : }
8951 774 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8952 : {
8953 0 : error_at (OMP_CLAUSE_LOCATION (c),
8954 : "%qD appears more than once in %<aligned%> clauses",
8955 : t);
8956 0 : remove = true;
8957 : }
8958 : else
8959 774 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8960 807 : t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
8961 807 : if (t == error_mark_node)
8962 : remove = true;
8963 807 : else if (t == NULL_TREE)
8964 : break;
8965 744 : else if (!type_dependent_expression_p (t)
8966 744 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8967 : {
8968 0 : error_at (OMP_CLAUSE_LOCATION (c),
8969 : "%<aligned%> clause alignment expression must "
8970 : "be integral");
8971 0 : remove = true;
8972 : }
8973 : else
8974 : {
8975 744 : t = mark_rvalue_use (t);
8976 744 : if (!processing_template_decl)
8977 : {
8978 690 : t = maybe_constant_value (t);
8979 690 : if (TREE_CODE (t) != INTEGER_CST
8980 690 : || tree_int_cst_sgn (t) != 1)
8981 : {
8982 0 : error_at (OMP_CLAUSE_LOCATION (c),
8983 : "%<aligned%> clause alignment expression must "
8984 : "be positive constant integer expression");
8985 0 : remove = true;
8986 : }
8987 : }
8988 744 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
8989 : }
8990 : break;
8991 :
8992 369 : case OMP_CLAUSE_NONTEMPORAL:
8993 369 : t = OMP_CLAUSE_DECL (c);
8994 369 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8995 : {
8996 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8997 : break;
8998 0 : if (DECL_P (t))
8999 0 : error_at (OMP_CLAUSE_LOCATION (c),
9000 : "%qD is not a variable in %<nontemporal%> clause",
9001 : t);
9002 : else
9003 0 : error_at (OMP_CLAUSE_LOCATION (c),
9004 : "%qE is not a variable in %<nontemporal%> clause",
9005 : t);
9006 : remove = true;
9007 : }
9008 369 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
9009 : {
9010 6 : error_at (OMP_CLAUSE_LOCATION (c),
9011 : "%qD appears more than once in %<nontemporal%> "
9012 : "clauses", t);
9013 6 : remove = true;
9014 : }
9015 : else
9016 363 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
9017 : break;
9018 :
9019 2809 : case OMP_CLAUSE_ALLOCATE:
9020 2809 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
9021 2809 : if (t)
9022 14 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
9023 : else
9024 2795 : t = OMP_CLAUSE_DECL (c);
9025 2809 : if (t == current_class_ptr)
9026 : {
9027 0 : error_at (OMP_CLAUSE_LOCATION (c),
9028 : "%<this%> not allowed in %<allocate%> clause");
9029 0 : remove = true;
9030 0 : break;
9031 : }
9032 2809 : if (!VAR_P (t)
9033 678 : && TREE_CODE (t) != PARM_DECL
9034 45 : && TREE_CODE (t) != FIELD_DECL)
9035 : {
9036 3 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9037 : break;
9038 3 : if (DECL_P (t))
9039 3 : error_at (OMP_CLAUSE_LOCATION (c),
9040 : "%qD is not a variable in %<allocate%> clause", t);
9041 : else
9042 0 : error_at (OMP_CLAUSE_LOCATION (c),
9043 : "%qE is not a variable in %<allocate%> clause", t);
9044 : remove = true;
9045 : }
9046 2806 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
9047 : {
9048 12 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9049 : "%qD appears more than once in %<allocate%> clauses",
9050 : t);
9051 12 : remove = true;
9052 : }
9053 : else
9054 : {
9055 2794 : bitmap_set_bit (&aligned_head, DECL_UID (t));
9056 2794 : allocate_seen = true;
9057 : }
9058 2809 : tree allocator, align;
9059 2809 : align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
9060 2809 : if (error_operand_p (align))
9061 : {
9062 : remove = true;
9063 : break;
9064 : }
9065 2809 : if (align)
9066 : {
9067 211 : if (!type_dependent_expression_p (align)
9068 211 : && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
9069 : {
9070 4 : error_at (OMP_CLAUSE_LOCATION (c),
9071 : "%<allocate%> clause %<align%> modifier "
9072 : "argument needs to be positive constant "
9073 : "power of two integer expression");
9074 4 : remove = true;
9075 : }
9076 : else
9077 : {
9078 207 : align = mark_rvalue_use (align);
9079 207 : if (!processing_template_decl)
9080 : {
9081 192 : align = maybe_constant_value (align);
9082 192 : if (TREE_CODE (align) != INTEGER_CST
9083 189 : || !tree_fits_uhwi_p (align)
9084 381 : || !integer_pow2p (align))
9085 : {
9086 10 : error_at (OMP_CLAUSE_LOCATION (c),
9087 : "%<allocate%> clause %<align%> modifier "
9088 : "argument needs to be positive constant "
9089 : "power of two integer expression");
9090 10 : remove = true;
9091 : }
9092 : }
9093 : }
9094 211 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
9095 : }
9096 2809 : allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
9097 2809 : if (error_operand_p (allocator))
9098 : {
9099 : remove = true;
9100 : break;
9101 : }
9102 2809 : if (allocator == NULL_TREE)
9103 1751 : goto handle_field_decl;
9104 1058 : tree allocatort;
9105 1058 : allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
9106 1058 : if (!type_dependent_expression_p (allocator)
9107 1058 : && (TREE_CODE (allocatort) != ENUMERAL_TYPE
9108 1039 : || TYPE_NAME (allocatort) == NULL_TREE
9109 1039 : || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
9110 2078 : || (DECL_NAME (TYPE_NAME (allocatort))
9111 1039 : != get_identifier ("omp_allocator_handle_t"))
9112 1039 : || (TYPE_CONTEXT (allocatort)
9113 1039 : != DECL_CONTEXT (global_namespace))))
9114 : {
9115 16 : error_at (OMP_CLAUSE_LOCATION (c),
9116 : "%<allocate%> clause allocator expression has "
9117 : "type %qT rather than %<omp_allocator_handle_t%>",
9118 16 : TREE_TYPE (allocator));
9119 16 : remove = true;
9120 16 : break;
9121 : }
9122 : else
9123 : {
9124 1042 : allocator = mark_rvalue_use (allocator);
9125 1042 : if (!processing_template_decl)
9126 1023 : allocator = maybe_constant_value (allocator);
9127 1042 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
9128 : }
9129 1042 : goto handle_field_decl;
9130 :
9131 654 : case OMP_CLAUSE_DOACROSS:
9132 654 : t = OMP_CLAUSE_DECL (c);
9133 654 : if (t == NULL_TREE)
9134 : break;
9135 298 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
9136 : {
9137 298 : if (cp_finish_omp_clause_doacross_sink (c))
9138 98456 : remove = true;
9139 : break;
9140 : }
9141 0 : gcc_unreachable ();
9142 89 : case OMP_CLAUSE_USES_ALLOCATORS:
9143 89 : t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
9144 89 : t = convert_from_reference (t);
9145 89 : if (t == error_mark_node)
9146 : {
9147 : remove = true;
9148 : break;
9149 : }
9150 82 : if (DECL_P (t)
9151 82 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
9152 79 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9153 78 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
9154 : {
9155 1 : error_at (OMP_CLAUSE_LOCATION (c),
9156 : "%qE appears more than once in data clauses", t);
9157 1 : remove = true;
9158 : }
9159 81 : else if (DECL_P (t))
9160 78 : bitmap_set_bit (&generic_head, DECL_UID (t));
9161 82 : if (type_dependent_expression_p (t))
9162 : break;
9163 77 : if (TREE_CODE (t) == FIELD_DECL)
9164 : {
9165 0 : sorry_at (OMP_CLAUSE_LOCATION (c), "class member %qE not yet "
9166 : "supported in %<uses_allocators%> clause", t);
9167 0 : remove = true;
9168 0 : break;
9169 : }
9170 77 : if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9171 151 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9172 : "omp_allocator_handle_t") != 0)
9173 : {
9174 3 : error_at (OMP_CLAUSE_LOCATION (c),
9175 : "allocator %qE must be of %<omp_allocator_handle_t%> "
9176 : "type", t);
9177 3 : remove = true;
9178 3 : break;
9179 : }
9180 74 : tree init;
9181 74 : if (TREE_CODE (t) == CONST_DECL)
9182 7 : init = DECL_INITIAL(t);
9183 : else
9184 : init = t;
9185 74 : if (!DECL_P (t)
9186 74 : && (init == NULL_TREE
9187 3 : || TREE_CODE (init) != INTEGER_CST
9188 3 : || ((wi::to_widest (init) < 0
9189 3 : || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
9190 1 : && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
9191 1 : || (wi::to_widest (init)
9192 2 : > GOMP_OMPX_PREDEF_ALLOC_MAX)))))
9193 : {
9194 1 : remove = true;
9195 1 : error_at (OMP_CLAUSE_LOCATION (c),
9196 : "allocator %qE must be either a variable or a "
9197 : "predefined allocator", t);
9198 1 : break;
9199 : }
9200 73 : else if (TREE_CODE (t) == CONST_DECL)
9201 : {
9202 : /* omp_null_allocator is ignored and for predefined allocators,
9203 : not special handling is required; thus, remove them removed. */
9204 7 : remove = true;
9205 :
9206 7 : if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
9207 7 : || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
9208 : {
9209 0 : error_at (OMP_CLAUSE_LOCATION (c),
9210 : "modifiers cannot be used with predefined "
9211 : "allocators");
9212 0 : break;
9213 : }
9214 : }
9215 73 : t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
9216 73 : if (t == error_mark_node)
9217 : {
9218 : remove = true;
9219 : break;
9220 : }
9221 72 : if (t != NULL_TREE
9222 16 : && !type_dependent_expression_p (t)
9223 88 : && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
9224 15 : || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9225 28 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9226 : "omp_memspace_handle_t") != 0))
9227 : {
9228 2 : error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
9229 : " constant enum of %<omp_memspace_handle_t%> type", t);
9230 2 : remove = true;
9231 2 : break;
9232 : }
9233 70 : t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
9234 70 : if (t == error_mark_node)
9235 : {
9236 : remove = true;
9237 : break;
9238 : }
9239 69 : if (type_dependent_expression_p (t))
9240 : break;
9241 69 : if (t != NULL_TREE
9242 41 : && t != error_mark_node
9243 41 : && !type_dependent_expression_p (t)
9244 110 : && (!DECL_P (t)
9245 41 : || DECL_EXTERNAL (t)
9246 39 : || TREE_CODE (t) == PARM_DECL))
9247 : {
9248 4 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
9249 : "defined in same scope as the construct on which the "
9250 : "clause appears", t);
9251 4 : remove = true;
9252 : }
9253 69 : if (t != NULL_TREE)
9254 : {
9255 41 : bool type_err = false;
9256 :
9257 41 : if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
9258 39 : || DECL_SIZE (t) == NULL_TREE
9259 79 : || !COMPLETE_TYPE_P (TREE_TYPE (t)))
9260 : type_err = true;
9261 : else
9262 : {
9263 38 : tree elem_t = TREE_TYPE (TREE_TYPE (t));
9264 38 : if (TREE_CODE (elem_t) != RECORD_TYPE
9265 76 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
9266 : "omp_alloctrait_t") != 0
9267 76 : || !TYPE_READONLY (elem_t))
9268 : type_err = true;
9269 : }
9270 37 : if (type_err)
9271 : {
9272 4 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
9273 : "be of %<const omp_alloctrait_t []%> type", t);
9274 4 : remove = true;
9275 : }
9276 37 : else if (TREE_CODE (array_type_nelts_top (TREE_TYPE (t)))
9277 : != INTEGER_CST)
9278 : {
9279 1 : error_at (OMP_CLAUSE_LOCATION (c), "variable length traits "
9280 : "arrays are not supported");
9281 1 : remove = true;
9282 : }
9283 : else
9284 : {
9285 36 : tree cst_val = decl_constant_value (t);
9286 36 : if (cst_val == t)
9287 : {
9288 1 : error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
9289 : "initialized with constants");
9290 1 : remove = true;
9291 : }
9292 : }
9293 : }
9294 69 : if (remove)
9295 : break;
9296 55 : pc = &OMP_CLAUSE_CHAIN (c);
9297 55 : continue;
9298 1807 : case OMP_CLAUSE_DEPEND:
9299 1807 : depend_clause = c;
9300 : /* FALLTHRU */
9301 2416 : case OMP_CLAUSE_AFFINITY:
9302 2416 : t = OMP_CLAUSE_DECL (c);
9303 2416 : if (OMP_ITERATOR_DECL_P (t))
9304 : {
9305 623 : if (TREE_PURPOSE (t) != last_iterators)
9306 525 : last_iterators_remove
9307 525 : = cp_omp_finish_iterators (TREE_PURPOSE (t));
9308 623 : last_iterators = TREE_PURPOSE (t);
9309 623 : t = TREE_VALUE (t);
9310 623 : if (last_iterators_remove)
9311 144 : t = error_mark_node;
9312 : }
9313 : else
9314 : last_iterators = NULL_TREE;
9315 :
9316 2416 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9317 : {
9318 1368 : if (handle_omp_array_sections (c, ort))
9319 : remove = true;
9320 1014 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9321 1014 : && (OMP_CLAUSE_DEPEND_KIND (c)
9322 : == OMP_CLAUSE_DEPEND_DEPOBJ))
9323 : {
9324 6 : error_at (OMP_CLAUSE_LOCATION (c),
9325 : "%<depend%> clause with %<depobj%> dependence "
9326 : "type on array section");
9327 6 : remove = true;
9328 : }
9329 : break;
9330 : }
9331 1048 : if (t == error_mark_node)
9332 : remove = true;
9333 886 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9334 886 : && t == ridpointers[RID_OMP_ALL_MEMORY])
9335 : {
9336 33 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
9337 33 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
9338 : {
9339 9 : error_at (OMP_CLAUSE_LOCATION (c),
9340 : "%<omp_all_memory%> used with %<depend%> kind "
9341 : "other than %<out%> or %<inout%>");
9342 9 : remove = true;
9343 : }
9344 33 : if (processing_template_decl)
9345 : break;
9346 : }
9347 853 : else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9348 : break;
9349 661 : else if (!lvalue_p (t))
9350 : {
9351 21 : if (DECL_P (t))
9352 24 : error_at (OMP_CLAUSE_LOCATION (c),
9353 : "%qD is not lvalue expression nor array section "
9354 : "in %qs clause", t,
9355 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9356 : else
9357 18 : error_at (OMP_CLAUSE_LOCATION (c),
9358 : "%qE is not lvalue expression nor array section "
9359 : "in %qs clause", t,
9360 9 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9361 : remove = true;
9362 : }
9363 640 : else if (TREE_CODE (t) == COMPONENT_REF
9364 36 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
9365 676 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
9366 : {
9367 12 : error_at (OMP_CLAUSE_LOCATION (c),
9368 : "bit-field %qE in %qs clause", t,
9369 6 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9370 6 : remove = true;
9371 : }
9372 634 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9373 634 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
9374 : {
9375 130 : if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9376 8 : ? TREE_TYPE (TREE_TYPE (t))
9377 57 : : TREE_TYPE (t)))
9378 : {
9379 12 : error_at (OMP_CLAUSE_LOCATION (c),
9380 : "%qE does not have %<omp_depend_t%> type in "
9381 : "%<depend%> clause with %<depobj%> dependence "
9382 : "type", t);
9383 12 : remove = true;
9384 : }
9385 : }
9386 569 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9387 1010 : && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9388 4 : ? TREE_TYPE (TREE_TYPE (t))
9389 437 : : TREE_TYPE (t)))
9390 : {
9391 15 : error_at (OMP_CLAUSE_LOCATION (c),
9392 : "%qE should not have %<omp_depend_t%> type in "
9393 : "%<depend%> clause with dependence type other than "
9394 : "%<depobj%>", t);
9395 15 : remove = true;
9396 : }
9397 87 : if (!remove)
9398 : {
9399 631 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
9400 24 : t = null_pointer_node;
9401 : else
9402 : {
9403 607 : tree addr = cp_build_addr_expr (t, tf_warning_or_error);
9404 607 : if (addr == error_mark_node)
9405 : {
9406 : remove = true;
9407 : break;
9408 : }
9409 607 : t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
9410 : addr, RO_UNARY_STAR,
9411 : tf_warning_or_error);
9412 607 : if (t == error_mark_node)
9413 : {
9414 : remove = true;
9415 : break;
9416 : }
9417 : }
9418 631 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
9419 137 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
9420 768 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
9421 : == TREE_VEC))
9422 137 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
9423 : else
9424 494 : OMP_CLAUSE_DECL (c) = t;
9425 : }
9426 : break;
9427 69 : case OMP_CLAUSE_DETACH:
9428 69 : t = OMP_CLAUSE_DECL (c);
9429 69 : if (detach_seen)
9430 : {
9431 3 : error_at (OMP_CLAUSE_LOCATION (c),
9432 : "too many %qs clauses on a task construct",
9433 : "detach");
9434 3 : remove = true;
9435 3 : break;
9436 : }
9437 66 : else if (error_operand_p (t))
9438 : {
9439 : remove = true;
9440 : break;
9441 : }
9442 : else
9443 : {
9444 63 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
9445 63 : if (!type_dependent_expression_p (t)
9446 63 : && (!INTEGRAL_TYPE_P (type)
9447 : || TREE_CODE (type) != ENUMERAL_TYPE
9448 51 : || TYPE_NAME (type) == NULL_TREE
9449 102 : || (DECL_NAME (TYPE_NAME (type))
9450 51 : != get_identifier ("omp_event_handle_t"))))
9451 : {
9452 6 : error_at (OMP_CLAUSE_LOCATION (c),
9453 : "%<detach%> clause event handle "
9454 : "has type %qT rather than "
9455 : "%<omp_event_handle_t%>",
9456 : type);
9457 6 : remove = true;
9458 : }
9459 63 : detach_seen = c;
9460 63 : cxx_mark_addressable (t);
9461 : }
9462 63 : break;
9463 :
9464 16351 : case OMP_CLAUSE_MAP:
9465 16351 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
9466 157 : goto move_implicit;
9467 16194 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
9468 16194 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
9469 : {
9470 : remove = true;
9471 : break;
9472 : }
9473 : /* FALLTHRU */
9474 19372 : case OMP_CLAUSE_TO:
9475 19372 : case OMP_CLAUSE_FROM:
9476 19372 : if (OMP_CLAUSE_ITERATORS (c)
9477 19372 : && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
9478 : {
9479 98456 : t = error_mark_node;
9480 : break;
9481 : }
9482 : /* FALLTHRU */
9483 20260 : case OMP_CLAUSE__CACHE_:
9484 20260 : {
9485 20260 : using namespace omp_addr_tokenizer;
9486 20260 : auto_vec<omp_addr_token *, 10> addr_tokens;
9487 :
9488 20260 : t = OMP_CLAUSE_DECL (c);
9489 20260 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9490 : {
9491 5997 : grp_start_p = pc;
9492 5997 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9493 :
9494 5997 : if (handle_omp_array_sections (c, ort))
9495 : remove = true;
9496 : else
9497 : {
9498 5187 : t = OMP_CLAUSE_DECL (c);
9499 5187 : if (TREE_CODE (t) != OMP_ARRAY_SECTION
9500 4326 : && !type_dependent_expression_p (t)
9501 9513 : && !omp_mappable_type (TREE_TYPE (t)))
9502 : {
9503 3 : auto_diagnostic_group d;
9504 6 : error_at (OMP_CLAUSE_LOCATION (c),
9505 : "array section does not have mappable type "
9506 : "in %qs clause",
9507 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9508 3 : if (TREE_TYPE (t) != error_mark_node
9509 3 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9510 3 : cxx_incomplete_type_inform (TREE_TYPE (t));
9511 3 : remove = true;
9512 3 : }
9513 7112 : while (TREE_CODE (t) == ARRAY_REF)
9514 1925 : t = TREE_OPERAND (t, 0);
9515 :
9516 5187 : if (type_dependent_expression_p (t))
9517 : break;
9518 :
9519 4713 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9520 :
9521 4713 : if (!ai.map_supported_p ()
9522 4713 : || !omp_parse_expr (addr_tokens, t))
9523 : {
9524 18 : sorry_at (OMP_CLAUSE_LOCATION (c),
9525 : "unsupported map expression %qE",
9526 9 : OMP_CLAUSE_DECL (c));
9527 9 : remove = true;
9528 9 : break;
9529 : }
9530 :
9531 : /* This check is to determine if this will be the only map
9532 : node created for this clause. Otherwise, we'll check
9533 : the following FIRSTPRIVATE_POINTER,
9534 : FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
9535 : iteration(s) of the loop. */
9536 9359 : if (addr_tokens.length () >= 4
9537 1063 : && addr_tokens[0]->type == STRUCTURE_BASE
9538 1057 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
9539 1057 : && addr_tokens[1]->type == ACCESS_METHOD
9540 1057 : && addr_tokens[2]->type == COMPONENT_SELECTOR
9541 977 : && addr_tokens[3]->type == ACCESS_METHOD
9542 5418 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
9543 551 : || (addr_tokens[3]->u.access_kind
9544 : == ACCESS_INDEXED_ARRAY)))
9545 : {
9546 165 : tree rt = addr_tokens[1]->expr;
9547 :
9548 165 : gcc_assert (DECL_P (rt));
9549 :
9550 165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9551 154 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9552 165 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
9553 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
9554 0 : || bitmap_bit_p (&map_firstprivate_head,
9555 0 : DECL_UID (rt))))
9556 : {
9557 : remove = true;
9558 : break;
9559 : }
9560 165 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
9561 : break;
9562 116 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
9563 : {
9564 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9565 0 : error_at (OMP_CLAUSE_LOCATION (c),
9566 : "%qD appears more than once in motion"
9567 : " clauses", rt);
9568 0 : else if (openacc)
9569 0 : error_at (OMP_CLAUSE_LOCATION (c),
9570 : "%qD appears more than once in data"
9571 : " clauses", rt);
9572 : else
9573 0 : error_at (OMP_CLAUSE_LOCATION (c),
9574 : "%qD appears more than once in map"
9575 : " clauses", rt);
9576 : remove = true;
9577 : }
9578 : else
9579 : {
9580 116 : bitmap_set_bit (&map_head, DECL_UID (rt));
9581 116 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
9582 : }
9583 : }
9584 4713 : }
9585 5465 : if (cp_oacc_check_attachments (c))
9586 12 : remove = true;
9587 5465 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9588 4484 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9589 4420 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9590 5563 : && !OMP_CLAUSE_SIZE (c))
9591 : /* In this case, we have a single array element which is a
9592 : pointer, and we already set OMP_CLAUSE_SIZE in
9593 : handle_omp_array_sections above. For attach/detach
9594 : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
9595 : to zero here. */
9596 60 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9597 : break;
9598 : }
9599 14263 : else if (type_dependent_expression_p (t))
9600 : break;
9601 13480 : else if (!omp_parse_expr (addr_tokens, t))
9602 : {
9603 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
9604 : "unsupported map expression %qE",
9605 0 : OMP_CLAUSE_DECL (c));
9606 0 : remove = true;
9607 0 : break;
9608 : }
9609 13480 : if (t == error_mark_node)
9610 : {
9611 : remove = true;
9612 : break;
9613 : }
9614 : /* OpenACC attach / detach clauses must be pointers. */
9615 13366 : if (cp_oacc_check_attachments (c))
9616 : {
9617 : remove = true;
9618 : break;
9619 : }
9620 13342 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9621 10297 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9622 10248 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9623 13416 : && !OMP_CLAUSE_SIZE (c))
9624 : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
9625 : bias) to zero here, so it is not set erroneously to the
9626 : pointer size later on in gimplify.cc. */
9627 66 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9628 :
9629 13342 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9630 :
9631 13342 : if (!ai.check_clause (c))
9632 : {
9633 : remove = true;
9634 : break;
9635 : }
9636 :
9637 13321 : if (!ai.map_supported_p ())
9638 : {
9639 88 : sorry_at (OMP_CLAUSE_LOCATION (c),
9640 : "unsupported map expression %qE",
9641 44 : OMP_CLAUSE_DECL (c));
9642 44 : remove = true;
9643 44 : break;
9644 : }
9645 :
9646 26554 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
9647 : || addr_tokens[0]->type == STRUCTURE_BASE)
9648 : && addr_tokens[1]->type == ACCESS_METHOD);
9649 :
9650 13277 : t = addr_tokens[1]->expr;
9651 :
9652 : /* This is used to prevent cxx_mark_addressable from being called
9653 : on 'this' for expressions like 'this->a', i.e. typical member
9654 : accesses. */
9655 13277 : indir_component_ref_p
9656 26554 : = (addr_tokens[0]->type == STRUCTURE_BASE
9657 13277 : && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
9658 :
9659 13277 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
9660 1 : goto skip_decl_checks;
9661 :
9662 : /* For OpenMP, we can access a struct "t" and "t.d" on the same
9663 : mapping. OpenACC allows multiple fields of the same structure
9664 : to be written. */
9665 13276 : if (addr_tokens[0]->type == STRUCTURE_BASE
9666 13276 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
9667 1263 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
9668 1351 : goto skip_decl_checks;
9669 :
9670 11925 : if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
9671 : {
9672 0 : OMP_CLAUSE_DECL (c)
9673 0 : = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
9674 0 : break;
9675 : }
9676 11925 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9677 : {
9678 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9679 : break;
9680 0 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9681 0 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9682 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
9683 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
9684 0 : || (!openacc && EXPR_P (t))))
9685 : break;
9686 0 : if (DECL_P (t))
9687 0 : error_at (OMP_CLAUSE_LOCATION (c),
9688 : "%qD is not a variable in %qs clause", t,
9689 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9690 : else
9691 0 : error_at (OMP_CLAUSE_LOCATION (c),
9692 : "%qE is not a variable in %qs clause", t,
9693 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9694 : remove = true;
9695 : }
9696 11925 : else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
9697 : {
9698 0 : error_at (OMP_CLAUSE_LOCATION (c),
9699 : "%qD is threadprivate variable in %qs clause", t,
9700 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9701 0 : remove = true;
9702 : }
9703 11925 : else if (!processing_template_decl
9704 11746 : && !TYPE_REF_P (TREE_TYPE (t))
9705 11069 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9706 8134 : || (OMP_CLAUSE_MAP_KIND (c)
9707 : != GOMP_MAP_FIRSTPRIVATE_POINTER))
9708 9086 : && !indir_component_ref_p
9709 8722 : && (t != current_class_ptr
9710 18 : || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9711 6 : || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
9712 20647 : && !cxx_mark_addressable (t))
9713 : remove = true;
9714 11925 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9715 8972 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9716 8972 : || (OMP_CLAUSE_MAP_KIND (c)
9717 : == GOMP_MAP_FIRSTPRIVATE_POINTER)
9718 6989 : || (OMP_CLAUSE_MAP_KIND (c)
9719 : == GOMP_MAP_ATTACH_DETACH)))
9720 9282 : && t == OMP_CLAUSE_DECL (c)
9721 8584 : && !type_dependent_expression_p (t)
9722 29093 : && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
9723 278 : ? TREE_TYPE (TREE_TYPE (t))
9724 8306 : : TREE_TYPE (t)))
9725 : {
9726 42 : auto_diagnostic_group d;
9727 84 : error_at (OMP_CLAUSE_LOCATION (c),
9728 : "%qD does not have a mappable type in %qs clause", t,
9729 42 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9730 42 : if (TREE_TYPE (t) != error_mark_node
9731 42 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9732 39 : cxx_incomplete_type_inform (TREE_TYPE (t));
9733 42 : remove = true;
9734 42 : }
9735 11883 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9736 8936 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
9737 93 : && !type_dependent_expression_p (t)
9738 11976 : && !INDIRECT_TYPE_P (TREE_TYPE (t)))
9739 : {
9740 6 : error_at (OMP_CLAUSE_LOCATION (c),
9741 : "%qD is not a pointer variable", t);
9742 6 : remove = true;
9743 : }
9744 11877 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9745 8930 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9746 12247 : && (bitmap_bit_p (&map_head, DECL_UID (t))
9747 367 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
9748 367 : || bitmap_bit_p (&map_firstprivate_head,
9749 367 : DECL_UID (t))))
9750 : remove = true;
9751 11871 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9752 11871 : && (OMP_CLAUSE_MAP_KIND (c)
9753 : == GOMP_MAP_FIRSTPRIVATE_POINTER))
9754 : {
9755 1977 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
9756 1977 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9757 3951 : || (openacc
9758 1364 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
9759 : {
9760 12 : error_at (OMP_CLAUSE_LOCATION (c),
9761 : "%qD appears more than once in data clauses", t);
9762 12 : remove = true;
9763 : }
9764 1965 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9765 12 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9766 1973 : && openacc)
9767 : {
9768 3 : error_at (OMP_CLAUSE_LOCATION (c),
9769 : "%qD appears more than once in data clauses", t);
9770 3 : remove = true;
9771 : }
9772 : else
9773 1962 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9774 : }
9775 9894 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9776 9894 : && (OMP_CLAUSE_MAP_KIND (c)
9777 : == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
9778 115 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9779 9779 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9780 181 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9781 38 : && ort != C_ORT_OMP
9782 38 : && ort != C_ORT_OMP_TARGET
9783 9795 : && ort != C_ORT_OMP_EXIT_DATA)
9784 : {
9785 9 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9786 0 : error_at (OMP_CLAUSE_LOCATION (c),
9787 : "%qD appears more than once in motion clauses", t);
9788 9 : else if (openacc)
9789 9 : error_at (OMP_CLAUSE_LOCATION (c),
9790 : "%qD appears more than once in data clauses", t);
9791 : else
9792 0 : error_at (OMP_CLAUSE_LOCATION (c),
9793 : "%qD appears more than once in map clauses", t);
9794 : remove = true;
9795 : }
9796 9770 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
9797 : {
9798 0 : error_at (OMP_CLAUSE_LOCATION (c),
9799 : "%qD appears more than once in data clauses", t);
9800 0 : remove = true;
9801 : }
9802 9770 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9803 9770 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
9804 : {
9805 27 : if (openacc)
9806 0 : error_at (OMP_CLAUSE_LOCATION (c),
9807 : "%qD appears more than once in data clauses", t);
9808 : else
9809 27 : error_at (OMP_CLAUSE_LOCATION (c),
9810 : "%qD appears both in data and map clauses", t);
9811 : remove = true;
9812 : }
9813 9743 : else if (!omp_access_chain_p (addr_tokens, 1))
9814 : {
9815 9663 : bitmap_set_bit (&map_head, DECL_UID (t));
9816 :
9817 9663 : tree decl = OMP_CLAUSE_DECL (c);
9818 9663 : if (t != decl
9819 9663 : && (TREE_CODE (decl) == COMPONENT_REF
9820 162 : || (INDIRECT_REF_P (decl)
9821 162 : && (TREE_CODE (TREE_OPERAND (decl, 0))
9822 : == COMPONENT_REF)
9823 150 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
9824 : 0))))))
9825 1165 : bitmap_set_bit (&map_field_head, DECL_UID (t));
9826 : }
9827 :
9828 4693 : skip_decl_checks:
9829 : /* If we call ai.expand_map_clause in handle_omp_array_sections,
9830 : the containing loop (here) iterates through the new nodes
9831 : created by that expansion. Avoid expanding those again (just
9832 : by checking the node type). */
9833 4693 : if (!remove
9834 13172 : && !processing_template_decl
9835 12996 : && ort != C_ORT_DECLARE_SIMD
9836 12996 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9837 9969 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
9838 8007 : && (OMP_CLAUSE_MAP_KIND (c)
9839 : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
9840 7892 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
9841 7892 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
9842 6893 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
9843 6844 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
9844 : {
9845 9846 : grp_start_p = pc;
9846 9846 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9847 9846 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
9848 : addr_tokens, ort);
9849 9846 : if (nc != error_mark_node)
9850 9846 : c = nc;
9851 : }
9852 20325 : }
9853 13277 : break;
9854 :
9855 597 : case OMP_CLAUSE_ENTER:
9856 597 : case OMP_CLAUSE_LINK:
9857 597 : t = OMP_CLAUSE_DECL (c);
9858 597 : const char *cname;
9859 597 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
9860 597 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
9861 597 : && OMP_CLAUSE_ENTER_TO (c))
9862 : cname = "to";
9863 597 : if (TREE_CODE (t) == FUNCTION_DECL
9864 597 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9865 : ;
9866 380 : else if (!VAR_P (t))
9867 : {
9868 12 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9869 : {
9870 9 : if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
9871 6 : error_at (OMP_CLAUSE_LOCATION (c),
9872 : "template %qE in clause %qs", t, cname);
9873 3 : else if (really_overloaded_fn (t))
9874 3 : error_at (OMP_CLAUSE_LOCATION (c),
9875 : "overloaded function name %qE in clause %qs", t,
9876 : cname);
9877 : else
9878 0 : error_at (OMP_CLAUSE_LOCATION (c),
9879 : "%qE is neither a variable nor a function name "
9880 : "in clause %qs", t, cname);
9881 : }
9882 : else
9883 3 : error_at (OMP_CLAUSE_LOCATION (c),
9884 : "%qE is not a variable in clause %qs", t, cname);
9885 : remove = true;
9886 : }
9887 368 : else if (DECL_THREAD_LOCAL_P (t))
9888 : {
9889 6 : error_at (OMP_CLAUSE_LOCATION (c),
9890 : "%qD is threadprivate variable in %qs clause", t,
9891 : cname);
9892 6 : remove = true;
9893 : }
9894 362 : else if (!omp_mappable_type (TREE_TYPE (t)))
9895 : {
9896 18 : auto_diagnostic_group d;
9897 18 : error_at (OMP_CLAUSE_LOCATION (c),
9898 : "%qD does not have a mappable type in %qs clause", t,
9899 : cname);
9900 18 : if (TREE_TYPE (t) != error_mark_node
9901 18 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9902 18 : cxx_incomplete_type_inform (TREE_TYPE (t));
9903 18 : remove = true;
9904 18 : }
9905 36 : if (remove)
9906 : break;
9907 561 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9908 : {
9909 24 : error_at (OMP_CLAUSE_LOCATION (c),
9910 : "%qE appears more than once on the same "
9911 : "%<declare target%> directive", t);
9912 24 : remove = true;
9913 : }
9914 : else
9915 537 : bitmap_set_bit (&generic_head, DECL_UID (t));
9916 : break;
9917 :
9918 457 : case OMP_CLAUSE_UNIFORM:
9919 457 : t = OMP_CLAUSE_DECL (c);
9920 457 : if (TREE_CODE (t) != PARM_DECL)
9921 : {
9922 0 : if (processing_template_decl)
9923 : break;
9924 0 : if (DECL_P (t))
9925 0 : error_at (OMP_CLAUSE_LOCATION (c),
9926 : "%qD is not an argument in %<uniform%> clause", t);
9927 : else
9928 0 : error_at (OMP_CLAUSE_LOCATION (c),
9929 : "%qE is not an argument in %<uniform%> clause", t);
9930 : remove = true;
9931 : break;
9932 : }
9933 : /* map_head bitmap is used as uniform_head if declare_simd. */
9934 457 : bitmap_set_bit (&map_head, DECL_UID (t));
9935 457 : goto check_dup_generic;
9936 :
9937 165 : case OMP_CLAUSE_GRAINSIZE:
9938 165 : t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
9939 165 : if (t == error_mark_node)
9940 : remove = true;
9941 165 : else if (!type_dependent_expression_p (t)
9942 165 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9943 : {
9944 0 : error_at (OMP_CLAUSE_LOCATION (c),
9945 : "%<grainsize%> expression must be integral");
9946 0 : remove = true;
9947 : }
9948 : else
9949 : {
9950 165 : t = mark_rvalue_use (t);
9951 165 : if (!processing_template_decl)
9952 : {
9953 164 : t = maybe_constant_value (t);
9954 164 : if (TREE_CODE (t) == INTEGER_CST
9955 164 : && tree_int_cst_sgn (t) != 1)
9956 : {
9957 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9958 : "%<grainsize%> value must be positive");
9959 0 : t = integer_one_node;
9960 : }
9961 164 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9962 : }
9963 165 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
9964 : }
9965 : break;
9966 :
9967 276 : case OMP_CLAUSE_PRIORITY:
9968 276 : t = OMP_CLAUSE_PRIORITY_EXPR (c);
9969 276 : if (t == error_mark_node)
9970 : remove = true;
9971 276 : else if (!type_dependent_expression_p (t)
9972 276 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9973 : {
9974 0 : error_at (OMP_CLAUSE_LOCATION (c),
9975 : "%<priority%> expression must be integral");
9976 0 : remove = true;
9977 : }
9978 : else
9979 : {
9980 276 : t = mark_rvalue_use (t);
9981 276 : if (!processing_template_decl)
9982 : {
9983 276 : t = maybe_constant_value (t);
9984 276 : if (TREE_CODE (t) == INTEGER_CST
9985 276 : && tree_int_cst_sgn (t) == -1)
9986 : {
9987 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9988 : "%<priority%> value must be non-negative");
9989 0 : t = integer_one_node;
9990 : }
9991 276 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9992 : }
9993 276 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
9994 : }
9995 : break;
9996 :
9997 228 : case OMP_CLAUSE_HINT:
9998 228 : t = OMP_CLAUSE_HINT_EXPR (c);
9999 228 : if (t == error_mark_node)
10000 : remove = true;
10001 228 : else if (!type_dependent_expression_p (t)
10002 228 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10003 : {
10004 9 : error_at (OMP_CLAUSE_LOCATION (c),
10005 : "%<hint%> expression must be integral");
10006 9 : remove = true;
10007 : }
10008 : else
10009 : {
10010 219 : t = mark_rvalue_use (t);
10011 219 : if (!processing_template_decl)
10012 : {
10013 171 : t = maybe_constant_value (t);
10014 171 : if (TREE_CODE (t) != INTEGER_CST)
10015 : {
10016 16 : error_at (OMP_CLAUSE_LOCATION (c),
10017 : "%<hint%> expression must be constant integer "
10018 : "expression");
10019 16 : remove = true;
10020 : }
10021 : }
10022 219 : OMP_CLAUSE_HINT_EXPR (c) = t;
10023 : }
10024 : break;
10025 :
10026 186 : case OMP_CLAUSE_FILTER:
10027 186 : t = OMP_CLAUSE_FILTER_EXPR (c);
10028 186 : if (t == error_mark_node)
10029 : remove = true;
10030 186 : else if (!type_dependent_expression_p (t)
10031 186 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10032 : {
10033 6 : error_at (OMP_CLAUSE_LOCATION (c),
10034 : "%<filter%> expression must be integral");
10035 6 : remove = true;
10036 : }
10037 : else
10038 : {
10039 180 : t = mark_rvalue_use (t);
10040 180 : if (!processing_template_decl)
10041 : {
10042 177 : t = maybe_constant_value (t);
10043 177 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10044 : }
10045 180 : OMP_CLAUSE_FILTER_EXPR (c) = t;
10046 : }
10047 : break;
10048 :
10049 433 : case OMP_CLAUSE_IS_DEVICE_PTR:
10050 433 : case OMP_CLAUSE_USE_DEVICE_PTR:
10051 433 : field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
10052 433 : t = OMP_CLAUSE_DECL (c);
10053 433 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
10054 329 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
10055 433 : if (!type_dependent_expression_p (t))
10056 : {
10057 431 : tree type = TREE_TYPE (t);
10058 431 : if (!TYPE_PTR_P (type)
10059 431 : && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
10060 : {
10061 57 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
10062 57 : && ort == C_ORT_OMP)
10063 : {
10064 3 : error_at (OMP_CLAUSE_LOCATION (c),
10065 : "%qs variable is neither a pointer "
10066 : "nor reference to pointer",
10067 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10068 3 : remove = true;
10069 : }
10070 54 : else if (TREE_CODE (type) != ARRAY_TYPE
10071 54 : && (!TYPE_REF_P (type)
10072 2 : || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
10073 : {
10074 12 : error_at (OMP_CLAUSE_LOCATION (c),
10075 : "%qs variable is neither a pointer, nor an "
10076 : "array nor reference to pointer or array",
10077 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10078 12 : remove = true;
10079 : }
10080 : }
10081 : }
10082 433 : goto check_dup_generic;
10083 :
10084 267 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
10085 267 : t = OMP_CLAUSE_DECL (c);
10086 267 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10087 : {
10088 28 : if (handle_omp_array_sections (c, ort))
10089 : remove = true;
10090 : else
10091 : {
10092 28 : t = OMP_CLAUSE_DECL (c);
10093 30 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10094 2 : t = TREE_OPERAND (t, 0);
10095 64 : while (INDIRECT_REF_P (t)
10096 64 : || TREE_CODE (t) == ARRAY_REF)
10097 36 : t = TREE_OPERAND (t, 0);
10098 : }
10099 : }
10100 267 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
10101 : {
10102 267 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
10103 267 : if (!processing_template_decl
10104 267 : && !cxx_mark_addressable (t))
10105 : remove = true;
10106 : }
10107 267 : goto check_dup_generic_t;
10108 :
10109 76 : case OMP_CLAUSE_USE_DEVICE_ADDR:
10110 76 : field_ok = true;
10111 76 : t = OMP_CLAUSE_DECL (c);
10112 76 : if (!processing_template_decl
10113 74 : && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
10114 74 : && !TYPE_REF_P (TREE_TYPE (t))
10115 143 : && !cxx_mark_addressable (t))
10116 : remove = true;
10117 76 : goto check_dup_generic;
10118 :
10119 : case OMP_CLAUSE_NOWAIT:
10120 : case OMP_CLAUSE_DEFAULT:
10121 : case OMP_CLAUSE_UNTIED:
10122 : case OMP_CLAUSE_COLLAPSE:
10123 : case OMP_CLAUSE_PARALLEL:
10124 : case OMP_CLAUSE_FOR:
10125 : case OMP_CLAUSE_SECTIONS:
10126 : case OMP_CLAUSE_TASKGROUP:
10127 : case OMP_CLAUSE_PROC_BIND:
10128 : case OMP_CLAUSE_DEVICE_TYPE:
10129 : case OMP_CLAUSE_NOGROUP:
10130 : case OMP_CLAUSE_THREADS:
10131 : case OMP_CLAUSE_SIMD:
10132 : case OMP_CLAUSE_DEFAULTMAP:
10133 : case OMP_CLAUSE_BIND:
10134 : case OMP_CLAUSE_AUTO:
10135 : case OMP_CLAUSE_INDEPENDENT:
10136 : case OMP_CLAUSE_SEQ:
10137 : case OMP_CLAUSE_IF_PRESENT:
10138 : case OMP_CLAUSE_FINALIZE:
10139 : case OMP_CLAUSE_NOHOST:
10140 : case OMP_CLAUSE_INDIRECT:
10141 : break;
10142 :
10143 231 : case OMP_CLAUSE_MERGEABLE:
10144 231 : mergeable_seen = true;
10145 231 : break;
10146 :
10147 322 : case OMP_CLAUSE_TILE:
10148 754 : for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
10149 432 : list = TREE_CHAIN (list))
10150 : {
10151 432 : t = TREE_VALUE (list);
10152 :
10153 432 : if (t == error_mark_node)
10154 : remove = true;
10155 403 : else if (!type_dependent_expression_p (t)
10156 403 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10157 : {
10158 3 : error_at (OMP_CLAUSE_LOCATION (c),
10159 : "%<tile%> argument needs integral type");
10160 3 : remove = true;
10161 : }
10162 : else
10163 : {
10164 400 : t = mark_rvalue_use (t);
10165 400 : if (!processing_template_decl)
10166 : {
10167 : /* Zero is used to indicate '*', we permit you
10168 : to get there via an ICE of value zero. */
10169 385 : t = maybe_constant_value (t);
10170 385 : if (!tree_fits_shwi_p (t)
10171 369 : || tree_to_shwi (t) < 0)
10172 : {
10173 40 : error_at (OMP_CLAUSE_LOCATION (c),
10174 : "%<tile%> argument needs positive "
10175 : "integral constant");
10176 40 : remove = true;
10177 : }
10178 : }
10179 : }
10180 :
10181 : /* Update list item. */
10182 432 : TREE_VALUE (list) = t;
10183 : }
10184 : break;
10185 :
10186 1027 : case OMP_CLAUSE_SIZES:
10187 1027 : for (tree list = OMP_CLAUSE_SIZES_LIST (c);
10188 2688 : !remove && list; list = TREE_CHAIN (list))
10189 : {
10190 1661 : t = TREE_VALUE (list);
10191 :
10192 1661 : if (t == error_mark_node)
10193 0 : t = integer_one_node;
10194 1661 : else if (!type_dependent_expression_p (t)
10195 1661 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10196 : {
10197 8 : error_at (OMP_CLAUSE_LOCATION (c),
10198 : "%<sizes%> argument needs positive integral "
10199 : "constant");
10200 8 : t = integer_one_node;
10201 : }
10202 : else
10203 : {
10204 1653 : t = mark_rvalue_use (t);
10205 1653 : if (!processing_template_decl)
10206 : {
10207 1636 : t = maybe_constant_value (t);
10208 1636 : HOST_WIDE_INT n;
10209 1636 : if (!tree_fits_shwi_p (t)
10210 1632 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
10211 1632 : || (n = tree_to_shwi (t)) <= 0
10212 3240 : || (int)n != n)
10213 : {
10214 32 : error_at (OMP_CLAUSE_LOCATION (c),
10215 : "%<sizes%> argument needs positive "
10216 : "integral constant");
10217 32 : t = integer_one_node;
10218 : }
10219 : }
10220 : }
10221 :
10222 : /* Update list item. */
10223 1661 : TREE_VALUE (list) = t;
10224 : }
10225 : break;
10226 :
10227 630 : case OMP_CLAUSE_ORDERED:
10228 630 : ordered_seen = true;
10229 630 : break;
10230 :
10231 1549 : case OMP_CLAUSE_ORDER:
10232 1549 : if (order_seen)
10233 : remove = true;
10234 : else
10235 : order_seen = true;
10236 : break;
10237 :
10238 638 : case OMP_CLAUSE_INBRANCH:
10239 638 : case OMP_CLAUSE_NOTINBRANCH:
10240 638 : if (branch_seen)
10241 : {
10242 3 : error_at (OMP_CLAUSE_LOCATION (c),
10243 : "%<inbranch%> clause is incompatible with "
10244 : "%<notinbranch%>");
10245 3 : remove = true;
10246 : }
10247 : branch_seen = true;
10248 : break;
10249 :
10250 306 : case OMP_CLAUSE_INCLUSIVE:
10251 306 : case OMP_CLAUSE_EXCLUSIVE:
10252 306 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10253 306 : if (!t)
10254 306 : t = OMP_CLAUSE_DECL (c);
10255 306 : if (t == current_class_ptr)
10256 : {
10257 0 : error_at (OMP_CLAUSE_LOCATION (c),
10258 : "%<this%> allowed in OpenMP only in %<declare simd%>"
10259 : " clauses");
10260 0 : remove = true;
10261 0 : break;
10262 : }
10263 306 : if (!VAR_P (t)
10264 : && TREE_CODE (t) != PARM_DECL
10265 : && TREE_CODE (t) != FIELD_DECL)
10266 : {
10267 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
10268 : break;
10269 0 : if (DECL_P (t))
10270 0 : error_at (OMP_CLAUSE_LOCATION (c),
10271 : "%qD is not a variable in clause %qs", t,
10272 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10273 : else
10274 0 : error_at (OMP_CLAUSE_LOCATION (c),
10275 : "%qE is not a variable in clause %qs", t,
10276 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10277 : remove = true;
10278 : }
10279 : break;
10280 :
10281 : case OMP_CLAUSE_FULL:
10282 : break;
10283 :
10284 470 : case OMP_CLAUSE_PARTIAL:
10285 470 : partial_seen = true;
10286 470 : t = OMP_CLAUSE_PARTIAL_EXPR (c);
10287 470 : if (!t)
10288 : break;
10289 :
10290 313 : if (t == error_mark_node)
10291 : t = NULL_TREE;
10292 313 : else if (!type_dependent_expression_p (t)
10293 313 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10294 : {
10295 3 : error_at (OMP_CLAUSE_LOCATION (c),
10296 : "%<partial%> argument needs positive constant "
10297 : "integer expression");
10298 3 : t = NULL_TREE;
10299 : }
10300 : else
10301 : {
10302 310 : t = mark_rvalue_use (t);
10303 310 : if (!processing_template_decl)
10304 : {
10305 292 : t = maybe_constant_value (t);
10306 :
10307 292 : HOST_WIDE_INT n;
10308 584 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
10309 292 : || !tree_fits_shwi_p (t)
10310 286 : || (n = tree_to_shwi (t)) <= 0
10311 560 : || (int)n != n)
10312 : {
10313 24 : error_at (OMP_CLAUSE_LOCATION (c),
10314 : "%<partial%> argument needs positive "
10315 : "constant integer expression");
10316 24 : t = NULL_TREE;
10317 : }
10318 : }
10319 : }
10320 :
10321 313 : OMP_CLAUSE_PARTIAL_EXPR (c) = t;
10322 313 : break;
10323 549 : case OMP_CLAUSE_INIT:
10324 549 : init_seen = true;
10325 549 : OMP_CLAUSE_INIT_PREFER_TYPE (c)
10326 549 : = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
10327 549 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
10328 271 : init_no_targetsync_clause = c;
10329 : /* FALLTHRU */
10330 844 : case OMP_CLAUSE_DESTROY:
10331 844 : case OMP_CLAUSE_USE:
10332 844 : init_use_destroy_seen = true;
10333 844 : t = OMP_CLAUSE_DECL (c);
10334 844 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
10335 : {
10336 9 : error_at (OMP_CLAUSE_LOCATION (c),
10337 : "%qD appears more than once in action clauses", t);
10338 9 : remove = true;
10339 9 : break;
10340 : }
10341 835 : bitmap_set_bit (&generic_head, DECL_UID (t));
10342 : /* FALLTHRU */
10343 1099 : case OMP_CLAUSE_INTEROP:
10344 1099 : if (!processing_template_decl)
10345 : {
10346 1003 : if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
10347 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) && */
10348 1003 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
10349 : {
10350 126 : error_at (OMP_CLAUSE_LOCATION (c),
10351 : "%qD must be of %<omp_interop_t%>",
10352 63 : OMP_CLAUSE_DECL (c));
10353 63 : remove = true;
10354 : }
10355 940 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
10356 481 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
10357 1058 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
10358 : {
10359 36 : error_at (OMP_CLAUSE_LOCATION (c),
10360 18 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
10361 18 : remove = true;
10362 : }
10363 : }
10364 1099 : pc = &OMP_CLAUSE_CHAIN (c);
10365 1099 : break;
10366 0 : default:
10367 0 : gcc_unreachable ();
10368 55 : }
10369 :
10370 98456 : if (remove)
10371 : {
10372 2706 : if (grp_start_p)
10373 : {
10374 : /* If we found a clause to remove, we want to remove the whole
10375 : expanded group, otherwise gimplify
10376 : (omp_resolve_clause_dependencies) can get confused. */
10377 861 : *grp_start_p = grp_sentinel;
10378 861 : pc = grp_start_p;
10379 861 : grp_start_p = NULL;
10380 : }
10381 : else
10382 1845 : *pc = OMP_CLAUSE_CHAIN (c);
10383 : }
10384 : else
10385 95750 : pc = &OMP_CLAUSE_CHAIN (c);
10386 : }
10387 :
10388 63466 : if (grp_start_p
10389 63466 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
10390 140 : for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
10391 86 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
10392 :
10393 63466 : if (reduction_seen < 0 && (ordered_seen || schedule_seen))
10394 63466 : reduction_seen = -2;
10395 :
10396 160183 : for (pc = &clauses, c = clauses; c ; c = *pc)
10397 : {
10398 96717 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
10399 96717 : bool remove = false;
10400 96717 : bool need_complete_type = false;
10401 96717 : bool need_default_ctor = false;
10402 96717 : bool need_copy_ctor = false;
10403 96717 : bool need_copy_assignment = false;
10404 96717 : bool need_implicitly_determined = false;
10405 96717 : bool need_dtor = false;
10406 96717 : tree type, inner_type;
10407 :
10408 96717 : switch (c_kind)
10409 : {
10410 : case OMP_CLAUSE_SHARED:
10411 : need_implicitly_determined = true;
10412 : break;
10413 2550 : case OMP_CLAUSE_PRIVATE:
10414 2550 : need_complete_type = true;
10415 2550 : need_default_ctor = true;
10416 2550 : need_dtor = true;
10417 2550 : need_implicitly_determined = true;
10418 2550 : break;
10419 3169 : case OMP_CLAUSE_FIRSTPRIVATE:
10420 3169 : need_complete_type = true;
10421 3169 : need_copy_ctor = true;
10422 3169 : need_dtor = true;
10423 3169 : need_implicitly_determined = true;
10424 3169 : break;
10425 2766 : case OMP_CLAUSE_LASTPRIVATE:
10426 2766 : need_complete_type = true;
10427 2766 : need_copy_assignment = true;
10428 2766 : need_implicitly_determined = true;
10429 2766 : break;
10430 7497 : case OMP_CLAUSE_REDUCTION:
10431 7497 : if (reduction_seen == -2)
10432 27 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
10433 7497 : if (OMP_CLAUSE_REDUCTION_INSCAN (c))
10434 436 : need_copy_assignment = true;
10435 : need_implicitly_determined = true;
10436 : break;
10437 : case OMP_CLAUSE_IN_REDUCTION:
10438 : case OMP_CLAUSE_TASK_REDUCTION:
10439 : case OMP_CLAUSE_INCLUSIVE:
10440 : case OMP_CLAUSE_EXCLUSIVE:
10441 : need_implicitly_determined = true;
10442 : break;
10443 1550 : case OMP_CLAUSE_LINEAR:
10444 1550 : if (ort != C_ORT_OMP_DECLARE_SIMD)
10445 : need_implicitly_determined = true;
10446 679 : else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
10447 721 : && !bitmap_bit_p (&map_head,
10448 42 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
10449 : {
10450 6 : error_at (OMP_CLAUSE_LOCATION (c),
10451 : "%<linear%> clause step is a parameter %qD not "
10452 : "specified in %<uniform%> clause",
10453 6 : OMP_CLAUSE_LINEAR_STEP (c));
10454 6 : *pc = OMP_CLAUSE_CHAIN (c);
10455 74984 : continue;
10456 : }
10457 : break;
10458 : case OMP_CLAUSE_COPYPRIVATE:
10459 369 : need_copy_assignment = true;
10460 : break;
10461 : case OMP_CLAUSE_COPYIN:
10462 369 : need_copy_assignment = true;
10463 : break;
10464 798 : case OMP_CLAUSE_SIMDLEN:
10465 798 : if (safelen
10466 345 : && !processing_template_decl
10467 1143 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
10468 345 : OMP_CLAUSE_SIMDLEN_EXPR (c)))
10469 : {
10470 0 : error_at (OMP_CLAUSE_LOCATION (c),
10471 : "%<simdlen%> clause value is bigger than "
10472 : "%<safelen%> clause value");
10473 0 : OMP_CLAUSE_SIMDLEN_EXPR (c)
10474 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
10475 : }
10476 798 : pc = &OMP_CLAUSE_CHAIN (c);
10477 798 : continue;
10478 3883 : case OMP_CLAUSE_SCHEDULE:
10479 3883 : if (ordered_seen
10480 3883 : && (OMP_CLAUSE_SCHEDULE_KIND (c)
10481 : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
10482 : {
10483 21 : error_at (OMP_CLAUSE_LOCATION (c),
10484 : "%<nonmonotonic%> schedule modifier specified "
10485 : "together with %<ordered%> clause");
10486 42 : OMP_CLAUSE_SCHEDULE_KIND (c)
10487 21 : = (enum omp_clause_schedule_kind)
10488 21 : (OMP_CLAUSE_SCHEDULE_KIND (c)
10489 : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
10490 : }
10491 3883 : if (reduction_seen == -2)
10492 9 : error_at (OMP_CLAUSE_LOCATION (c),
10493 : "%qs clause specified together with %<inscan%> "
10494 : "%<reduction%> clause", "schedule");
10495 3883 : pc = &OMP_CLAUSE_CHAIN (c);
10496 3883 : continue;
10497 51 : case OMP_CLAUSE_NOGROUP:
10498 51 : if (reduction_seen)
10499 : {
10500 3 : error_at (OMP_CLAUSE_LOCATION (c),
10501 : "%<nogroup%> clause must not be used together with "
10502 : "%<reduction%> clause");
10503 3 : *pc = OMP_CLAUSE_CHAIN (c);
10504 3 : continue;
10505 : }
10506 48 : pc = &OMP_CLAUSE_CHAIN (c);
10507 48 : continue;
10508 165 : case OMP_CLAUSE_GRAINSIZE:
10509 165 : if (num_tasks_seen)
10510 : {
10511 6 : error_at (OMP_CLAUSE_LOCATION (c),
10512 : "%<grainsize%> clause must not be used together with "
10513 : "%<num_tasks%> clause");
10514 6 : *pc = OMP_CLAUSE_CHAIN (c);
10515 6 : continue;
10516 : }
10517 159 : pc = &OMP_CLAUSE_CHAIN (c);
10518 159 : continue;
10519 630 : case OMP_CLAUSE_ORDERED:
10520 630 : if (reduction_seen == -2)
10521 6 : error_at (OMP_CLAUSE_LOCATION (c),
10522 : "%qs clause specified together with %<inscan%> "
10523 : "%<reduction%> clause", "ordered");
10524 630 : pc = &OMP_CLAUSE_CHAIN (c);
10525 630 : continue;
10526 1525 : case OMP_CLAUSE_ORDER:
10527 1525 : if (ordered_seen)
10528 : {
10529 12 : error_at (OMP_CLAUSE_LOCATION (c),
10530 : "%<order%> clause must not be used together "
10531 : "with %<ordered%> clause");
10532 12 : *pc = OMP_CLAUSE_CHAIN (c);
10533 12 : continue;
10534 : }
10535 1513 : pc = &OMP_CLAUSE_CHAIN (c);
10536 1513 : continue;
10537 57 : case OMP_CLAUSE_DETACH:
10538 57 : if (mergeable_seen)
10539 : {
10540 6 : error_at (OMP_CLAUSE_LOCATION (c),
10541 : "%<detach%> clause must not be used together with "
10542 : "%<mergeable%> clause");
10543 6 : *pc = OMP_CLAUSE_CHAIN (c);
10544 6 : continue;
10545 : }
10546 51 : pc = &OMP_CLAUSE_CHAIN (c);
10547 51 : continue;
10548 16093 : case OMP_CLAUSE_MAP:
10549 16093 : if (target_in_reduction_seen && !processing_template_decl)
10550 : {
10551 684 : t = OMP_CLAUSE_DECL (c);
10552 684 : while (handled_component_p (t)
10553 : || INDIRECT_REF_P (t)
10554 : || TREE_CODE (t) == ADDR_EXPR
10555 : || TREE_CODE (t) == MEM_REF
10556 804 : || TREE_CODE (t) == NON_LVALUE_EXPR)
10557 120 : t = TREE_OPERAND (t, 0);
10558 684 : if (DECL_P (t)
10559 684 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
10560 342 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
10561 : }
10562 16093 : pc = &OMP_CLAUSE_CHAIN (c);
10563 16093 : continue;
10564 225 : case OMP_CLAUSE_FULL:
10565 225 : if (partial_seen)
10566 : {
10567 12 : error_at (OMP_CLAUSE_LOCATION (c),
10568 : "%<full%> clause must not be used together "
10569 : "with %<partial%> clause");
10570 12 : *pc = OMP_CLAUSE_CHAIN (c);
10571 12 : continue;
10572 : }
10573 213 : pc = &OMP_CLAUSE_CHAIN (c);
10574 213 : continue;
10575 6952 : case OMP_CLAUSE_NOWAIT:
10576 6952 : if (copyprivate_seen)
10577 : {
10578 6 : error_at (OMP_CLAUSE_LOCATION (c),
10579 : "%<nowait%> clause must not be used together "
10580 : "with %<copyprivate%> clause");
10581 6 : *pc = OMP_CLAUSE_CHAIN (c);
10582 6 : continue;
10583 : }
10584 : /* FALLTHRU */
10585 50865 : default:
10586 50865 : pc = &OMP_CLAUSE_CHAIN (c);
10587 50865 : continue;
10588 : }
10589 :
10590 22413 : t = OMP_CLAUSE_DECL (c);
10591 22413 : switch (c_kind)
10592 : {
10593 2766 : case OMP_CLAUSE_LASTPRIVATE:
10594 2766 : if (DECL_P (t)
10595 2766 : && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
10596 : {
10597 2666 : need_default_ctor = true;
10598 2666 : need_dtor = true;
10599 : }
10600 : break;
10601 :
10602 9636 : case OMP_CLAUSE_REDUCTION:
10603 9636 : case OMP_CLAUSE_IN_REDUCTION:
10604 9636 : case OMP_CLAUSE_TASK_REDUCTION:
10605 9636 : if (allocate_seen)
10606 : {
10607 1711 : if (TREE_CODE (t) == MEM_REF)
10608 : {
10609 222 : t = TREE_OPERAND (t, 0);
10610 222 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
10611 0 : t = TREE_OPERAND (t, 0);
10612 222 : if (TREE_CODE (t) == ADDR_EXPR
10613 168 : || INDIRECT_REF_P (t))
10614 110 : t = TREE_OPERAND (t, 0);
10615 222 : if (DECL_P (t))
10616 222 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10617 : }
10618 1489 : else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10619 : {
10620 288 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10621 144 : t = TREE_OPERAND (t, 0);
10622 144 : if (DECL_P (t))
10623 144 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10624 144 : t = OMP_CLAUSE_DECL (c);
10625 : }
10626 1345 : else if (DECL_P (t))
10627 1345 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10628 1711 : t = OMP_CLAUSE_DECL (c);
10629 : }
10630 9636 : if (processing_template_decl
10631 929 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10632 : break;
10633 9018 : if (finish_omp_reduction_clause (c, &need_default_ctor,
10634 : &need_dtor))
10635 : remove = true;
10636 : else
10637 8934 : t = OMP_CLAUSE_DECL (c);
10638 : break;
10639 :
10640 277 : case OMP_CLAUSE_COPYIN:
10641 277 : if (processing_template_decl
10642 0 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10643 : break;
10644 277 : if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
10645 : {
10646 15 : error_at (OMP_CLAUSE_LOCATION (c),
10647 : "%qE must be %<threadprivate%> for %<copyin%>", t);
10648 15 : remove = true;
10649 : }
10650 : break;
10651 :
10652 : default:
10653 : break;
10654 : }
10655 :
10656 22413 : if (processing_template_decl
10657 1610 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10658 : {
10659 680 : pc = &OMP_CLAUSE_CHAIN (c);
10660 680 : continue;
10661 : }
10662 :
10663 21733 : if (need_complete_type || need_copy_assignment)
10664 : {
10665 9234 : t = require_complete_type (t);
10666 9234 : if (t == error_mark_node)
10667 : remove = true;
10668 9210 : else if (!processing_template_decl
10669 8827 : && TYPE_REF_P (TREE_TYPE (t))
10670 9766 : && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
10671 : remove = true;
10672 : }
10673 21733 : if (need_implicitly_determined)
10674 : {
10675 20692 : const char *share_name = NULL;
10676 :
10677 20692 : if (allocate_seen
10678 5114 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10679 24927 : && DECL_P (t))
10680 3950 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10681 :
10682 20692 : if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
10683 : share_name = "threadprivate";
10684 20650 : else switch (cxx_omp_predetermined_sharing_1 (t))
10685 : {
10686 : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
10687 : break;
10688 47 : case OMP_CLAUSE_DEFAULT_SHARED:
10689 47 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10690 30 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
10691 64 : && c_omp_predefined_variable (t))
10692 : /* The __func__ variable and similar function-local predefined
10693 : variables may be listed in a shared or firstprivate
10694 : clause. */
10695 : break;
10696 31 : if (VAR_P (t)
10697 31 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10698 9 : && TREE_STATIC (t)
10699 40 : && cxx_omp_const_qual_no_mutable (t))
10700 : {
10701 6 : tree ctx = CP_DECL_CONTEXT (t);
10702 : /* const qualified static data members without mutable
10703 : member may be specified in firstprivate clause. */
10704 6 : if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
10705 : break;
10706 : }
10707 : share_name = "shared";
10708 : break;
10709 : case OMP_CLAUSE_DEFAULT_PRIVATE:
10710 : share_name = "private";
10711 : break;
10712 0 : default:
10713 0 : gcc_unreachable ();
10714 : }
10715 : if (share_name)
10716 : {
10717 67 : error_at (OMP_CLAUSE_LOCATION (c),
10718 : "%qE is predetermined %qs for %qs",
10719 : omp_clause_printable_decl (t), share_name,
10720 67 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10721 67 : remove = true;
10722 : }
10723 20625 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10724 18566 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
10725 36051 : && cxx_omp_const_qual_no_mutable (t))
10726 : {
10727 126 : error_at (OMP_CLAUSE_LOCATION (c),
10728 : "%<const%> qualified %qE without %<mutable%> member "
10729 : "may appear only in %<shared%> or %<firstprivate%> "
10730 : "clauses", omp_clause_printable_decl (t));
10731 63 : remove = true;
10732 : }
10733 : }
10734 :
10735 21733 : if (detach_seen
10736 16 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10737 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
10738 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10739 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
10740 21749 : && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
10741 : {
10742 6 : error_at (OMP_CLAUSE_LOCATION (c),
10743 : "the event handle of a %<detach%> clause "
10744 : "should not be in a data-sharing clause");
10745 6 : remove = true;
10746 : }
10747 :
10748 : /* We're interested in the base element, not arrays. */
10749 21733 : inner_type = type = TREE_TYPE (t);
10750 21733 : if ((need_complete_type
10751 : || need_copy_assignment
10752 12499 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
10753 5717 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
10754 4244 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
10755 30315 : && TYPE_REF_P (inner_type))
10756 899 : inner_type = TREE_TYPE (inner_type);
10757 24411 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
10758 2678 : inner_type = TREE_TYPE (inner_type);
10759 :
10760 : /* Check for special function availability by building a call to one.
10761 : Save the results, because later we won't be in the right context
10762 : for making these queries. */
10763 2397 : if (CLASS_TYPE_P (inner_type)
10764 2397 : && COMPLETE_TYPE_P (inner_type)
10765 2328 : && (need_default_ctor || need_copy_ctor
10766 1091 : || need_copy_assignment || need_dtor)
10767 2004 : && !type_dependent_expression_p (t)
10768 23737 : && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
10769 : need_copy_ctor, need_copy_assignment,
10770 : need_dtor))
10771 : remove = true;
10772 :
10773 21733 : if (!remove
10774 21733 : && c_kind == OMP_CLAUSE_SHARED
10775 2056 : && processing_template_decl)
10776 : {
10777 125 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10778 125 : if (t)
10779 5 : OMP_CLAUSE_DECL (c) = t;
10780 : }
10781 :
10782 21733 : if (remove)
10783 292 : *pc = OMP_CLAUSE_CHAIN (c);
10784 : else
10785 21441 : pc = &OMP_CLAUSE_CHAIN (c);
10786 : }
10787 :
10788 63466 : if (allocate_seen)
10789 17449 : for (pc = &clauses, c = clauses; c ; c = *pc)
10790 : {
10791 14948 : bool remove = false;
10792 14948 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
10793 2764 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
10794 2312 : && DECL_P (OMP_CLAUSE_DECL (c))
10795 17260 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
10796 : {
10797 15 : error_at (OMP_CLAUSE_LOCATION (c),
10798 : "%qD specified in %<allocate%> clause but not in "
10799 15 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
10800 15 : remove = true;
10801 : }
10802 14948 : if (remove)
10803 15 : *pc = OMP_CLAUSE_CHAIN (c);
10804 : else
10805 14933 : pc = &OMP_CLAUSE_CHAIN (c);
10806 : }
10807 :
10808 63466 : if (ort == C_ORT_OMP_INTEROP
10809 63466 : && depend_clause
10810 60 : && (!init_use_destroy_seen
10811 57 : || (init_seen && init_no_targetsync_clause)))
10812 : {
10813 9 : auto_diagnostic_group d;
10814 9 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
10815 : "%<depend%> clause requires action clauses with "
10816 : "%<targetsync%> interop-type");
10817 9 : if (init_no_targetsync_clause)
10818 6 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
10819 : "%<init%> clause lacks the %<targetsync%> modifier");
10820 9 : }
10821 :
10822 63466 : bitmap_obstack_release (NULL);
10823 63466 : return clauses;
10824 : }
10825 :
10826 : /* Start processing OpenMP clauses that can include any
10827 : privatization clauses for non-static data members. */
10828 :
10829 : tree
10830 49196 : push_omp_privatization_clauses (bool ignore_next)
10831 : {
10832 49196 : if (omp_private_member_ignore_next)
10833 : {
10834 722 : omp_private_member_ignore_next = ignore_next;
10835 722 : return NULL_TREE;
10836 : }
10837 48474 : omp_private_member_ignore_next = ignore_next;
10838 48474 : if (omp_private_member_map)
10839 24 : omp_private_member_vec.safe_push (error_mark_node);
10840 48474 : return push_stmt_list ();
10841 : }
10842 :
10843 : /* Revert remapping of any non-static data members since
10844 : the last push_omp_privatization_clauses () call. */
10845 :
10846 : void
10847 49190 : pop_omp_privatization_clauses (tree stmt)
10848 : {
10849 49190 : if (stmt == NULL_TREE)
10850 : return;
10851 48468 : stmt = pop_stmt_list (stmt);
10852 48468 : if (omp_private_member_map)
10853 : {
10854 1280 : while (!omp_private_member_vec.is_empty ())
10855 : {
10856 850 : tree t = omp_private_member_vec.pop ();
10857 850 : if (t == error_mark_node)
10858 : {
10859 24 : add_stmt (stmt);
10860 24 : return;
10861 : }
10862 826 : bool no_decl_expr = t == integer_zero_node;
10863 826 : if (no_decl_expr)
10864 136 : t = omp_private_member_vec.pop ();
10865 826 : tree *v = omp_private_member_map->get (t);
10866 826 : gcc_assert (v);
10867 826 : if (!no_decl_expr)
10868 690 : add_decl_expr (*v);
10869 826 : omp_private_member_map->remove (t);
10870 : }
10871 860 : delete omp_private_member_map;
10872 430 : omp_private_member_map = NULL;
10873 : }
10874 48444 : add_stmt (stmt);
10875 : }
10876 :
10877 : /* Remember OpenMP privatization clauses mapping and clear it.
10878 : Used for lambdas. */
10879 :
10880 : void
10881 16445926 : save_omp_privatization_clauses (vec<tree> &save)
10882 : {
10883 16445926 : save = vNULL;
10884 16445926 : if (omp_private_member_ignore_next)
10885 2 : save.safe_push (integer_one_node);
10886 16445926 : omp_private_member_ignore_next = false;
10887 16445926 : if (!omp_private_member_map)
10888 : return;
10889 :
10890 0 : while (!omp_private_member_vec.is_empty ())
10891 : {
10892 0 : tree t = omp_private_member_vec.pop ();
10893 0 : if (t == error_mark_node)
10894 : {
10895 0 : save.safe_push (t);
10896 0 : continue;
10897 : }
10898 0 : tree n = t;
10899 0 : if (t == integer_zero_node)
10900 0 : t = omp_private_member_vec.pop ();
10901 0 : tree *v = omp_private_member_map->get (t);
10902 0 : gcc_assert (v);
10903 0 : save.safe_push (*v);
10904 0 : save.safe_push (t);
10905 0 : if (n != t)
10906 0 : save.safe_push (n);
10907 : }
10908 0 : delete omp_private_member_map;
10909 0 : omp_private_member_map = NULL;
10910 : }
10911 :
10912 : /* Restore OpenMP privatization clauses mapping saved by the
10913 : above function. */
10914 :
10915 : void
10916 16445926 : restore_omp_privatization_clauses (vec<tree> &save)
10917 : {
10918 16445926 : gcc_assert (omp_private_member_vec.is_empty ());
10919 16445926 : omp_private_member_ignore_next = false;
10920 16445926 : if (save.is_empty ())
10921 : return;
10922 4 : if (save.length () == 1 && save[0] == integer_one_node)
10923 : {
10924 2 : omp_private_member_ignore_next = true;
10925 2 : save.release ();
10926 2 : return;
10927 : }
10928 :
10929 0 : omp_private_member_map = new hash_map <tree, tree>;
10930 0 : while (!save.is_empty ())
10931 : {
10932 0 : tree t = save.pop ();
10933 0 : tree n = t;
10934 0 : if (t != error_mark_node)
10935 : {
10936 0 : if (t == integer_one_node)
10937 : {
10938 0 : omp_private_member_ignore_next = true;
10939 0 : gcc_assert (save.is_empty ());
10940 0 : break;
10941 : }
10942 0 : if (t == integer_zero_node)
10943 0 : t = save.pop ();
10944 0 : tree &v = omp_private_member_map->get_or_insert (t);
10945 0 : v = save.pop ();
10946 : }
10947 0 : omp_private_member_vec.safe_push (t);
10948 0 : if (n != t)
10949 0 : omp_private_member_vec.safe_push (n);
10950 : }
10951 0 : save.release ();
10952 : }
10953 :
10954 : /* For all variables in the tree_list VARS, mark them as thread local. */
10955 :
10956 : void
10957 244 : finish_omp_threadprivate (tree vars)
10958 : {
10959 244 : tree t;
10960 :
10961 : /* Mark every variable in VARS to be assigned thread local storage. */
10962 521 : for (t = vars; t; t = TREE_CHAIN (t))
10963 : {
10964 277 : tree v = TREE_PURPOSE (t);
10965 277 : location_t loc = EXPR_LOCATION (TREE_VALUE (t));
10966 :
10967 277 : if (error_operand_p (v))
10968 : ;
10969 277 : else if (!VAR_P (v))
10970 6 : error_at (loc, "%<threadprivate%> %qD is not file, namespace "
10971 : "or block scope variable", v);
10972 : /* If V had already been marked threadprivate, it doesn't matter
10973 : whether it had been used prior to this point. */
10974 271 : else if (TREE_USED (v)
10975 271 : && (DECL_LANG_SPECIFIC (v) == NULL
10976 3 : || !CP_DECL_THREADPRIVATE_P (v)))
10977 6 : error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10978 265 : else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10979 6 : error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10980 259 : else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
10981 3 : error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10982 207 : else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
10983 279 : && CP_DECL_CONTEXT (v) != current_class_type)
10984 6 : error_at (loc, "%<threadprivate%> %qE directive not "
10985 6 : "in %qT definition", v, CP_DECL_CONTEXT (v));
10986 : else
10987 : {
10988 : /* Allocate a LANG_SPECIFIC structure for V, if needed. */
10989 250 : if (DECL_LANG_SPECIFIC (v) == NULL)
10990 206 : retrofit_lang_decl (v);
10991 :
10992 250 : if (! CP_DECL_THREAD_LOCAL_P (v))
10993 : {
10994 250 : CP_DECL_THREAD_LOCAL_P (v) = true;
10995 250 : set_decl_tls_model (v, decl_default_tls_model (v));
10996 : /* If rtl has been already set for this var, call
10997 : make_decl_rtl once again, so that encode_section_info
10998 : has a chance to look at the new decl flags. */
10999 250 : if (DECL_RTL_SET_P (v))
11000 0 : make_decl_rtl (v);
11001 : }
11002 250 : CP_DECL_THREADPRIVATE_P (v) = 1;
11003 : }
11004 : }
11005 244 : }
11006 :
11007 : /* Build an OpenMP structured block. */
11008 :
11009 : tree
11010 64719 : begin_omp_structured_block (void)
11011 : {
11012 64719 : return do_pushlevel (sk_omp);
11013 : }
11014 :
11015 : tree
11016 64704 : finish_omp_structured_block (tree block)
11017 : {
11018 64704 : return do_poplevel (block);
11019 : }
11020 :
11021 : /* Similarly, except force the retention of the BLOCK. */
11022 :
11023 : tree
11024 14970 : begin_omp_parallel (void)
11025 : {
11026 14970 : keep_next_level (true);
11027 14970 : return begin_omp_structured_block ();
11028 : }
11029 :
11030 : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
11031 : statement. */
11032 :
11033 : tree
11034 768 : finish_oacc_data (tree clauses, tree block)
11035 : {
11036 768 : tree stmt;
11037 :
11038 768 : block = finish_omp_structured_block (block);
11039 :
11040 768 : stmt = make_node (OACC_DATA);
11041 768 : TREE_TYPE (stmt) = void_type_node;
11042 768 : OACC_DATA_CLAUSES (stmt) = clauses;
11043 768 : OACC_DATA_BODY (stmt) = block;
11044 :
11045 768 : return add_stmt (stmt);
11046 : }
11047 :
11048 : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
11049 : statement. */
11050 :
11051 : tree
11052 55 : finish_oacc_host_data (tree clauses, tree block)
11053 : {
11054 55 : tree stmt;
11055 :
11056 55 : block = finish_omp_structured_block (block);
11057 :
11058 55 : stmt = make_node (OACC_HOST_DATA);
11059 55 : TREE_TYPE (stmt) = void_type_node;
11060 55 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
11061 55 : OACC_HOST_DATA_BODY (stmt) = block;
11062 :
11063 55 : return add_stmt (stmt);
11064 : }
11065 :
11066 : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
11067 : statement. */
11068 :
11069 : tree
11070 4689 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
11071 : {
11072 4689 : body = finish_omp_structured_block (body);
11073 :
11074 4689 : tree stmt = make_node (code);
11075 4689 : TREE_TYPE (stmt) = void_type_node;
11076 4689 : OMP_BODY (stmt) = body;
11077 4689 : OMP_CLAUSES (stmt) = clauses;
11078 :
11079 4689 : return add_stmt (stmt);
11080 : }
11081 :
11082 : /* Used to walk OpenMP target directive body. */
11083 :
11084 : struct omp_target_walk_data
11085 : {
11086 : /* Holds the 'this' expression found in current function. */
11087 : tree current_object;
11088 :
11089 : /* True if the 'this' expression was accessed in the target body. */
11090 : bool this_expr_accessed;
11091 :
11092 : /* For non-static functions, record which pointer-typed members were
11093 : accessed, and the whole expression. */
11094 : hash_map<tree, tree> ptr_members_accessed;
11095 :
11096 : /* Record which lambda objects were accessed in target body. */
11097 : hash_set<tree> lambda_objects_accessed;
11098 :
11099 : /* For lambda functions, the __closure object expression of the current
11100 : function, and the set of captured variables accessed in target body. */
11101 : tree current_closure;
11102 : hash_set<tree> closure_vars_accessed;
11103 :
11104 : /* Local variables declared inside a BIND_EXPR, used to filter out such
11105 : variables when recording lambda_objects_accessed. */
11106 : hash_set<tree> local_decls;
11107 :
11108 : omp_mapper_list<tree> *mappers;
11109 : };
11110 :
11111 : /* Helper function of finish_omp_target_clauses, called via
11112 : cp_walk_tree_without_duplicates. Traverse body of OpenMP target
11113 : directive *TP, and fill out omp_target_walk_data passed in *PTR. */
11114 :
11115 : static tree
11116 228858 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
11117 : {
11118 228858 : tree t = *tp;
11119 228858 : struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
11120 228858 : tree current_object = data->current_object;
11121 228858 : tree current_closure = data->current_closure;
11122 228858 : omp_mapper_list<tree> *mlist = data->mappers;
11123 :
11124 : /* References inside of these expression codes shouldn't incur any
11125 : form of mapping, so return early. */
11126 228858 : if (TREE_CODE (t) == SIZEOF_EXPR
11127 228850 : || TREE_CODE (t) == ALIGNOF_EXPR)
11128 : {
11129 8 : *walk_subtrees = 0;
11130 8 : return NULL_TREE;
11131 : }
11132 :
11133 228850 : if (TREE_CODE (t) == OMP_CLAUSE)
11134 : return NULL_TREE;
11135 :
11136 216252 : if (!processing_template_decl)
11137 : {
11138 216252 : tree aggr_type = NULL_TREE;
11139 :
11140 216252 : if (TREE_CODE (t) == COMPONENT_REF
11141 216252 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
11142 2257 : aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
11143 213995 : else if ((TREE_CODE (t) == VAR_DECL
11144 : || TREE_CODE (t) == PARM_DECL
11145 : || TREE_CODE (t) == RESULT_DECL)
11146 16991 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
11147 1216 : aggr_type = TREE_TYPE (t);
11148 :
11149 3473 : if (aggr_type)
11150 : {
11151 3473 : tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
11152 3473 : if (mapper_fn)
11153 199 : mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
11154 : }
11155 : }
11156 :
11157 216252 : if (current_object)
11158 : {
11159 2565 : tree this_expr = TREE_OPERAND (current_object, 0);
11160 :
11161 2565 : if (operand_equal_p (t, this_expr))
11162 : {
11163 35 : data->this_expr_accessed = true;
11164 35 : *walk_subtrees = 0;
11165 35 : return NULL_TREE;
11166 : }
11167 :
11168 2530 : if (TREE_CODE (t) == COMPONENT_REF
11169 115 : && POINTER_TYPE_P (TREE_TYPE (t))
11170 36 : && operand_equal_p (TREE_OPERAND (t, 0), current_object)
11171 2564 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
11172 : {
11173 34 : data->this_expr_accessed = true;
11174 34 : tree fld = TREE_OPERAND (t, 1);
11175 34 : if (data->ptr_members_accessed.get (fld) == NULL)
11176 : {
11177 14 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
11178 4 : t = convert_from_reference (t);
11179 14 : data->ptr_members_accessed.put (fld, t);
11180 : }
11181 34 : *walk_subtrees = 0;
11182 34 : return NULL_TREE;
11183 : }
11184 : }
11185 :
11186 : /* When the current_function_decl is a lambda function, the closure object
11187 : argument's type seems to not yet have fields laid out, so a recording
11188 : of DECL_VALUE_EXPRs during the target body walk seems the only way to
11189 : find them. */
11190 216183 : if (current_closure
11191 301 : && (VAR_P (t)
11192 : || TREE_CODE (t) == PARM_DECL
11193 : || TREE_CODE (t) == RESULT_DECL)
11194 24 : && DECL_HAS_VALUE_EXPR_P (t)
11195 10 : && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
11196 216193 : && operand_equal_p (current_closure,
11197 10 : TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
11198 : {
11199 9 : if (!data->closure_vars_accessed.contains (t))
11200 9 : data->closure_vars_accessed.add (t);
11201 9 : *walk_subtrees = 0;
11202 9 : return NULL_TREE;
11203 : }
11204 :
11205 216174 : if (TREE_CODE (t) == BIND_EXPR)
11206 : {
11207 20016 : if (tree block = BIND_EXPR_BLOCK (t))
11208 22472 : for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
11209 2460 : if (!data->local_decls.contains (var))
11210 2460 : data->local_decls.add (var);
11211 : return NULL_TREE;
11212 : }
11213 :
11214 200761 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
11215 : {
11216 39 : tree lt = TREE_TYPE (t);
11217 39 : gcc_assert (CLASS_TYPE_P (lt));
11218 :
11219 39 : if (!data->lambda_objects_accessed.contains (t)
11220 : /* Do not prepare to create target maps for locally declared
11221 : lambdas or anonymous ones. */
11222 39 : && !data->local_decls.contains (t)
11223 72 : && TREE_CODE (t) != TARGET_EXPR)
11224 13 : data->lambda_objects_accessed.add (t);
11225 39 : *walk_subtrees = 0;
11226 39 : return NULL_TREE;
11227 : }
11228 :
11229 : return NULL_TREE;
11230 : }
11231 :
11232 : /* Helper function for finish_omp_target, and also from tsubst_expr.
11233 : Create additional clauses for mapping of non-static members, lambda objects,
11234 : etc. */
11235 :
11236 : void
11237 6963 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
11238 : {
11239 6963 : omp_target_walk_data data;
11240 6963 : data.this_expr_accessed = false;
11241 6963 : data.current_object = NULL_TREE;
11242 :
11243 6963 : if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
11244 96 : if (tree ct = current_nonlambda_class_type ())
11245 : {
11246 95 : tree object = maybe_dummy_object (ct, NULL);
11247 95 : object = maybe_resolve_dummy (object, true);
11248 95 : data.current_object = object;
11249 : }
11250 :
11251 6963 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11252 : {
11253 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11254 8 : data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11255 : }
11256 : else
11257 : data.current_closure = NULL_TREE;
11258 :
11259 6963 : auto_vec<tree, 16> new_clauses;
11260 :
11261 6963 : if (!processing_template_decl)
11262 : {
11263 6963 : hash_set<omp_name_type<tree> > seen_types;
11264 6963 : auto_vec<tree> mapper_fns;
11265 6963 : omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
11266 6963 : data.mappers = &mlist;
11267 :
11268 6963 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11269 : &data);
11270 :
11271 6963 : unsigned int i;
11272 6963 : tree mapper_fn;
11273 14019 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11274 93 : c_omp_find_nested_mappers (&mlist, mapper_fn);
11275 :
11276 7126 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11277 : {
11278 93 : tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
11279 93 : if (mapper == error_mark_node)
11280 0 : continue;
11281 93 : tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
11282 93 : tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
11283 93 : if (BASELINK_P (mapper_fn))
11284 0 : mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
11285 :
11286 93 : tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
11287 93 : OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
11288 93 : OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
11289 93 : OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
11290 :
11291 93 : new_clauses.safe_push (c);
11292 : }
11293 6963 : }
11294 : else
11295 : {
11296 0 : data.mappers = NULL;
11297 0 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11298 : &data);
11299 : }
11300 :
11301 6963 : tree omp_target_this_expr = NULL_TREE;
11302 6963 : tree *explicit_this_deref_map = NULL;
11303 6963 : if (data.this_expr_accessed)
11304 : {
11305 31 : omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
11306 :
11307 : /* See if explicit user-specified map(this[:]) clause already exists.
11308 : If not, we create an implicit map(tofrom:this[:1]) clause. */
11309 80 : for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
11310 50 : if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
11311 47 : && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
11312 40 : || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
11313 57 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
11314 : omp_target_this_expr))
11315 : {
11316 : explicit_this_deref_map = cp;
11317 : break;
11318 : }
11319 : }
11320 :
11321 6963 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11322 6963 : && (data.this_expr_accessed
11323 1 : || !data.closure_vars_accessed.is_empty ()))
11324 : {
11325 : /* For lambda functions, we need to first create a copy of the
11326 : __closure object. */
11327 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11328 8 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11329 8 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
11330 8 : OMP_CLAUSE_DECL (c)
11331 8 : = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11332 8 : OMP_CLAUSE_SIZE (c)
11333 8 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
11334 8 : new_clauses.safe_push (c);
11335 :
11336 8 : tree closure_obj = OMP_CLAUSE_DECL (c);
11337 8 : tree closure_type = TREE_TYPE (closure_obj);
11338 :
11339 16 : gcc_assert (LAMBDA_TYPE_P (closure_type)
11340 : && CLASS_TYPE_P (closure_type));
11341 :
11342 8 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11343 8 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
11344 8 : OMP_CLAUSE_DECL (c2) = closure;
11345 8 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11346 8 : new_clauses.safe_push (c2);
11347 : }
11348 :
11349 6963 : if (data.this_expr_accessed)
11350 : {
11351 : /* If the this-expr was accessed, create a map(*this) clause. */
11352 31 : enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11353 31 : if (explicit_this_deref_map)
11354 : {
11355 1 : tree this_map = *explicit_this_deref_map;
11356 1 : tree nc = OMP_CLAUSE_CHAIN (this_map);
11357 2 : gcc_assert (nc != NULL_TREE
11358 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11359 : && (OMP_CLAUSE_MAP_KIND (nc)
11360 : == GOMP_MAP_FIRSTPRIVATE_POINTER));
11361 1 : kind = OMP_CLAUSE_MAP_KIND (this_map);
11362 : /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
11363 : two-map sequence away from the chain. */
11364 1 : *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
11365 : }
11366 31 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11367 31 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11368 31 : OMP_CLAUSE_DECL (c)
11369 31 : = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
11370 31 : OMP_CLAUSE_SIZE (c)
11371 31 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
11372 31 : new_clauses.safe_push (c);
11373 :
11374 : /* If we're in a lambda function, the this-pointer will actually be
11375 : '__closure->this', a mapped member of __closure, hence always_pointer.
11376 : Otherwise it's a firstprivate pointer. */
11377 31 : enum gomp_map_kind ptr_kind
11378 31 : = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11379 31 : ? GOMP_MAP_ALWAYS_POINTER
11380 24 : : GOMP_MAP_FIRSTPRIVATE_POINTER);
11381 31 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11382 31 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11383 31 : OMP_CLAUSE_DECL (c) = omp_target_this_expr;
11384 31 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11385 31 : new_clauses.safe_push (c);
11386 : }
11387 :
11388 6963 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11389 : {
11390 8 : if (omp_target_this_expr)
11391 : {
11392 7 : STRIP_NOPS (omp_target_this_expr);
11393 7 : gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
11394 7 : omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
11395 : }
11396 :
11397 17 : for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
11398 25 : i != data.closure_vars_accessed.end (); ++i)
11399 : {
11400 9 : tree orig_decl = *i;
11401 9 : tree closure_expr = DECL_VALUE_EXPR (orig_decl);
11402 :
11403 9 : if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
11404 9 : || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
11405 : {
11406 : /* this-pointer is processed above, outside this loop. */
11407 3 : if (omp_target_this_expr
11408 3 : && operand_equal_p (closure_expr, omp_target_this_expr))
11409 0 : continue;
11410 :
11411 3 : bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
11412 3 : enum gomp_map_kind kind, ptr_kind, nc_kind;
11413 3 : tree size;
11414 :
11415 3 : if (ptr_p)
11416 : {
11417 : /* For pointers, default mapped as zero-length array
11418 : section. */
11419 2 : kind = GOMP_MAP_ALLOC;
11420 2 : nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
11421 2 : ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
11422 2 : size = size_zero_node;
11423 : }
11424 : else
11425 : {
11426 : /* For references, default mapped as appearing on map
11427 : clause. */
11428 1 : kind = GOMP_MAP_TOFROM;
11429 1 : nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
11430 1 : ptr_kind = GOMP_MAP_ALWAYS_POINTER;
11431 1 : size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
11432 : }
11433 :
11434 6 : for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
11435 3 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
11436 1 : && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
11437 1 : || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
11438 3 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
11439 : orig_decl))
11440 : {
11441 : /* If this was already specified by user as a map,
11442 : save the user specified map kind, delete the
11443 : "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
11444 : and insert our own sequence:
11445 : "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
11446 : */
11447 0 : tree nc = OMP_CLAUSE_CHAIN (*p);
11448 0 : gcc_assert (nc != NULL_TREE
11449 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11450 : && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
11451 : /* Update with user specified kind and size. */
11452 0 : kind = OMP_CLAUSE_MAP_KIND (*p);
11453 0 : size = OMP_CLAUSE_SIZE (*p);
11454 0 : *p = OMP_CLAUSE_CHAIN (nc);
11455 0 : break;
11456 : }
11457 :
11458 3 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11459 3 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11460 3 : OMP_CLAUSE_DECL (c)
11461 3 : = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
11462 3 : OMP_CLAUSE_SIZE (c) = size;
11463 3 : if (ptr_p)
11464 2 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11465 3 : new_clauses.safe_push (c);
11466 :
11467 3 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11468 3 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11469 3 : OMP_CLAUSE_DECL (c) = closure_expr;
11470 3 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11471 3 : new_clauses.safe_push (c);
11472 : }
11473 : }
11474 : }
11475 :
11476 6963 : if (!data.ptr_members_accessed.is_empty ())
11477 14 : for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
11478 42 : i != data.ptr_members_accessed.end (); ++i)
11479 : {
11480 : /* For each referenced member that is of pointer or reference-to-pointer
11481 : type, create the equivalent of map(alloc:this->ptr[:0]). */
11482 14 : tree field_decl = (*i).first;
11483 14 : tree ptr_member = (*i).second;
11484 :
11485 26 : for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
11486 : {
11487 16 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
11488 2 : continue;
11489 : /* If map(this->ptr[:N]) already exists, avoid creating another
11490 : such map. */
11491 14 : tree decl = OMP_CLAUSE_DECL (c);
11492 14 : if ((TREE_CODE (decl) == INDIRECT_REF
11493 10 : || TREE_CODE (decl) == MEM_REF)
11494 14 : && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
11495 4 : goto next_ptr_member;
11496 : }
11497 :
11498 10 : if (!cxx_mark_addressable (ptr_member))
11499 0 : gcc_unreachable ();
11500 :
11501 10 : if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
11502 : {
11503 : /* For reference to pointers, we need to map the referenced
11504 : pointer first for things to be correct. */
11505 4 : tree ptr_member_type = TREE_TYPE (ptr_member);
11506 :
11507 : /* Map pointer target as zero-length array section. */
11508 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11509 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11510 4 : OMP_CLAUSE_DECL (c)
11511 4 : = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
11512 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11513 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11514 :
11515 : /* Map pointer to zero-length array section. */
11516 4 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11517 4 : OMP_CLAUSE_SET_MAP_KIND
11518 : (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
11519 4 : OMP_CLAUSE_DECL (c2) = ptr_member;
11520 4 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11521 :
11522 : /* Attach reference-to-pointer field to pointer. */
11523 4 : tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11524 4 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
11525 4 : OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
11526 4 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
11527 :
11528 4 : new_clauses.safe_push (c);
11529 4 : new_clauses.safe_push (c2);
11530 4 : new_clauses.safe_push (c3);
11531 : }
11532 6 : else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
11533 : {
11534 : /* Map pointer target as zero-length array section. */
11535 6 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11536 6 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11537 6 : OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
11538 : RO_UNARY_STAR);
11539 6 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11540 6 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11541 :
11542 : /* Attach zero-length array section to pointer. */
11543 6 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11544 6 : OMP_CLAUSE_SET_MAP_KIND
11545 : (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11546 6 : OMP_CLAUSE_DECL (c2) = ptr_member;
11547 6 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11548 :
11549 6 : new_clauses.safe_push (c);
11550 6 : new_clauses.safe_push (c2);
11551 : }
11552 : else
11553 0 : gcc_unreachable ();
11554 :
11555 14 : next_ptr_member:
11556 14 : ;
11557 : }
11558 :
11559 6976 : for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
11560 6976 : i != data.lambda_objects_accessed.end (); ++i)
11561 : {
11562 13 : tree lobj = *i;
11563 13 : if (TREE_CODE (lobj) == TARGET_EXPR)
11564 0 : lobj = TARGET_EXPR_SLOT (lobj);
11565 :
11566 13 : tree lt = TREE_TYPE (lobj);
11567 26 : gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
11568 :
11569 13 : tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
11570 13 : OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
11571 13 : OMP_CLAUSE_DECL (lc) = lobj;
11572 13 : OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
11573 13 : new_clauses.safe_push (lc);
11574 :
11575 180 : for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
11576 : {
11577 167 : if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
11578 : {
11579 4 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11580 : lobj, fld, NULL_TREE);
11581 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11582 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11583 4 : OMP_CLAUSE_DECL (c)
11584 4 : = build_indirect_ref (loc, exp, RO_UNARY_STAR);
11585 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11586 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11587 4 : new_clauses.safe_push (c);
11588 :
11589 4 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11590 4 : OMP_CLAUSE_SET_MAP_KIND
11591 : (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11592 4 : OMP_CLAUSE_DECL (c) = exp;
11593 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11594 4 : new_clauses.safe_push (c);
11595 : }
11596 163 : else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
11597 : {
11598 0 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11599 : lobj, fld, NULL_TREE);
11600 0 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11601 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
11602 0 : OMP_CLAUSE_DECL (c)
11603 0 : = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
11604 0 : OMP_CLAUSE_SIZE (c)
11605 0 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
11606 0 : new_clauses.safe_push (c);
11607 :
11608 0 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11609 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
11610 0 : OMP_CLAUSE_DECL (c) = exp;
11611 0 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11612 0 : new_clauses.safe_push (c);
11613 : }
11614 : }
11615 : }
11616 :
11617 6963 : tree c = *clauses_ptr;
11618 14148 : for (int i = new_clauses.length () - 1; i >= 0; i--)
11619 : {
11620 222 : OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
11621 222 : c = new_clauses[i];
11622 : }
11623 6963 : *clauses_ptr = c;
11624 6963 : }
11625 :
11626 : /* Called from cp_parser_omp_target. Create additional implicit clauses for
11627 : OpenMP target directives, and do sanity checks. */
11628 :
11629 : tree
11630 6953 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
11631 : {
11632 6953 : if (!processing_template_decl)
11633 6147 : finish_omp_target_clauses (loc, body, &clauses);
11634 :
11635 6953 : tree stmt = make_node (OMP_TARGET);
11636 6953 : TREE_TYPE (stmt) = void_type_node;
11637 6953 : OMP_TARGET_CLAUSES (stmt) = clauses;
11638 6953 : OMP_TARGET_BODY (stmt) = body;
11639 6953 : OMP_TARGET_COMBINED (stmt) = combined_p;
11640 6953 : SET_EXPR_LOCATION (stmt, loc);
11641 :
11642 6953 : tree c = clauses;
11643 16724 : while (c)
11644 : {
11645 9771 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
11646 5675 : switch (OMP_CLAUSE_MAP_KIND (c))
11647 : {
11648 : case GOMP_MAP_TO:
11649 : case GOMP_MAP_ALWAYS_TO:
11650 : case GOMP_MAP_PRESENT_TO:
11651 : case GOMP_MAP_ALWAYS_PRESENT_TO:
11652 : case GOMP_MAP_FROM:
11653 : case GOMP_MAP_ALWAYS_FROM:
11654 : case GOMP_MAP_PRESENT_FROM:
11655 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
11656 : case GOMP_MAP_TOFROM:
11657 : case GOMP_MAP_ALWAYS_TOFROM:
11658 : case GOMP_MAP_PRESENT_TOFROM:
11659 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
11660 : case GOMP_MAP_ALLOC:
11661 : case GOMP_MAP_PRESENT_ALLOC:
11662 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
11663 : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
11664 : case GOMP_MAP_ALWAYS_POINTER:
11665 : case GOMP_MAP_ATTACH_DETACH:
11666 : case GOMP_MAP_ATTACH:
11667 : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
11668 : case GOMP_MAP_POINTER:
11669 : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
11670 : break;
11671 3 : default:
11672 3 : error_at (OMP_CLAUSE_LOCATION (c),
11673 : "%<#pragma omp target%> with map-type other "
11674 : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
11675 : "on %<map%> clause");
11676 3 : break;
11677 : }
11678 9771 : c = OMP_CLAUSE_CHAIN (c);
11679 : }
11680 6953 : return add_stmt (stmt);
11681 : }
11682 :
11683 : tree
11684 9458 : finish_omp_parallel (tree clauses, tree body)
11685 : {
11686 9458 : tree stmt;
11687 :
11688 9458 : body = finish_omp_structured_block (body);
11689 :
11690 9458 : stmt = make_node (OMP_PARALLEL);
11691 9458 : TREE_TYPE (stmt) = void_type_node;
11692 9458 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
11693 9458 : OMP_PARALLEL_BODY (stmt) = body;
11694 :
11695 9458 : return add_stmt (stmt);
11696 : }
11697 :
11698 : tree
11699 2411 : begin_omp_task (void)
11700 : {
11701 2411 : keep_next_level (true);
11702 2411 : return begin_omp_structured_block ();
11703 : }
11704 :
11705 : tree
11706 2411 : finish_omp_task (tree clauses, tree body)
11707 : {
11708 2411 : tree stmt;
11709 :
11710 2411 : body = finish_omp_structured_block (body);
11711 :
11712 2411 : stmt = make_node (OMP_TASK);
11713 2411 : TREE_TYPE (stmt) = void_type_node;
11714 2411 : OMP_TASK_CLAUSES (stmt) = clauses;
11715 2411 : OMP_TASK_BODY (stmt) = body;
11716 :
11717 2411 : return add_stmt (stmt);
11718 : }
11719 :
11720 : /* Helper function for finish_omp_for. Convert Ith random access iterator
11721 : into integral iterator. Return FALSE if successful. */
11722 :
11723 : static bool
11724 813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
11725 : tree declv, tree orig_declv, tree initv,
11726 : tree condv, tree incrv, tree *body,
11727 : tree *pre_body, tree &clauses,
11728 : int collapse, int ordered)
11729 : {
11730 813 : tree diff, iter_init, iter_incr = NULL, last;
11731 813 : tree incr_var = NULL, orig_pre_body, orig_body, c;
11732 813 : tree decl = TREE_VEC_ELT (declv, i);
11733 813 : tree init = TREE_VEC_ELT (initv, i);
11734 813 : tree cond = TREE_VEC_ELT (condv, i);
11735 813 : tree incr = TREE_VEC_ELT (incrv, i);
11736 813 : tree iter = decl;
11737 813 : location_t elocus = locus;
11738 :
11739 813 : if (init && EXPR_HAS_LOCATION (init))
11740 12 : elocus = EXPR_LOCATION (init);
11741 :
11742 813 : switch (TREE_CODE (cond))
11743 : {
11744 810 : case GT_EXPR:
11745 810 : case GE_EXPR:
11746 810 : case LT_EXPR:
11747 810 : case LE_EXPR:
11748 810 : case NE_EXPR:
11749 810 : if (TREE_OPERAND (cond, 1) == iter)
11750 42 : cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
11751 42 : TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
11752 810 : if (TREE_OPERAND (cond, 0) != iter)
11753 0 : cond = error_mark_node;
11754 : else
11755 : {
11756 810 : tree tem = build_x_binary_op (EXPR_LOCATION (cond),
11757 810 : TREE_CODE (cond),
11758 : iter, ERROR_MARK,
11759 810 : TREE_OPERAND (cond, 1), ERROR_MARK,
11760 : NULL_TREE, NULL, tf_warning_or_error);
11761 810 : if (error_operand_p (tem))
11762 : return true;
11763 : }
11764 : break;
11765 3 : default:
11766 3 : cond = error_mark_node;
11767 3 : break;
11768 : }
11769 810 : if (cond == error_mark_node)
11770 : {
11771 3 : error_at (elocus, "invalid controlling predicate");
11772 3 : return true;
11773 : }
11774 807 : diff = build_x_binary_op (elocus, MINUS_EXPR,
11775 807 : TREE_OPERAND (cond, 1), ERROR_MARK,
11776 : iter, ERROR_MARK,
11777 : NULL_TREE, NULL, tf_warning_or_error);
11778 807 : diff = cp_fully_fold (diff);
11779 807 : if (error_operand_p (diff))
11780 : return true;
11781 807 : if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
11782 : {
11783 0 : error_at (elocus, "difference between %qE and %qD does not have integer type",
11784 0 : TREE_OPERAND (cond, 1), iter);
11785 0 : return true;
11786 : }
11787 807 : if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
11788 807 : TREE_VEC_ELT (declv, i), NULL_TREE,
11789 : cond, cp_walk_subtrees))
11790 : return true;
11791 :
11792 762 : switch (TREE_CODE (incr))
11793 : {
11794 370 : case PREINCREMENT_EXPR:
11795 370 : case PREDECREMENT_EXPR:
11796 370 : case POSTINCREMENT_EXPR:
11797 370 : case POSTDECREMENT_EXPR:
11798 370 : if (TREE_OPERAND (incr, 0) != iter)
11799 : {
11800 0 : incr = error_mark_node;
11801 0 : break;
11802 : }
11803 370 : iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
11804 370 : TREE_CODE (incr), iter,
11805 : NULL_TREE, tf_warning_or_error);
11806 370 : if (error_operand_p (iter_incr))
11807 : return true;
11808 370 : else if (TREE_CODE (incr) == PREINCREMENT_EXPR
11809 219 : || TREE_CODE (incr) == POSTINCREMENT_EXPR)
11810 299 : incr = integer_one_node;
11811 : else
11812 71 : incr = integer_minus_one_node;
11813 : break;
11814 392 : case MODIFY_EXPR:
11815 392 : if (TREE_OPERAND (incr, 0) != iter)
11816 0 : incr = error_mark_node;
11817 392 : else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
11818 392 : || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
11819 : {
11820 392 : tree rhs = TREE_OPERAND (incr, 1);
11821 392 : if (TREE_OPERAND (rhs, 0) == iter)
11822 : {
11823 299 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
11824 : != INTEGER_TYPE)
11825 0 : incr = error_mark_node;
11826 : else
11827 : {
11828 299 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11829 299 : iter, TREE_CODE (rhs),
11830 299 : TREE_OPERAND (rhs, 1),
11831 : NULL_TREE,
11832 : tf_warning_or_error);
11833 299 : if (error_operand_p (iter_incr))
11834 : return true;
11835 299 : incr = TREE_OPERAND (rhs, 1);
11836 299 : incr = cp_convert (TREE_TYPE (diff), incr,
11837 : tf_warning_or_error);
11838 299 : if (TREE_CODE (rhs) == MINUS_EXPR)
11839 : {
11840 16 : incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
11841 16 : incr = fold_simple (incr);
11842 : }
11843 299 : if (TREE_CODE (incr) != INTEGER_CST
11844 299 : && (TREE_CODE (incr) != NOP_EXPR
11845 66 : || (TREE_CODE (TREE_OPERAND (incr, 0))
11846 : != INTEGER_CST)))
11847 : iter_incr = NULL;
11848 : }
11849 : }
11850 93 : else if (TREE_OPERAND (rhs, 1) == iter)
11851 : {
11852 93 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
11853 93 : || TREE_CODE (rhs) != PLUS_EXPR)
11854 0 : incr = error_mark_node;
11855 : else
11856 : {
11857 93 : iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
11858 : PLUS_EXPR,
11859 93 : TREE_OPERAND (rhs, 0),
11860 : ERROR_MARK, iter,
11861 : ERROR_MARK, NULL_TREE, NULL,
11862 : tf_warning_or_error);
11863 93 : if (error_operand_p (iter_incr))
11864 : return true;
11865 93 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11866 : iter, NOP_EXPR,
11867 : iter_incr, NULL_TREE,
11868 : tf_warning_or_error);
11869 93 : if (error_operand_p (iter_incr))
11870 : return true;
11871 93 : incr = TREE_OPERAND (rhs, 0);
11872 93 : iter_incr = NULL;
11873 : }
11874 : }
11875 : else
11876 0 : incr = error_mark_node;
11877 : }
11878 : else
11879 0 : incr = error_mark_node;
11880 : break;
11881 0 : default:
11882 0 : incr = error_mark_node;
11883 0 : break;
11884 : }
11885 :
11886 762 : if (incr == error_mark_node)
11887 : {
11888 0 : error_at (elocus, "invalid increment expression");
11889 0 : return true;
11890 : }
11891 :
11892 762 : incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
11893 762 : incr = cp_fully_fold (incr);
11894 762 : tree loop_iv_seen = NULL_TREE;
11895 1735 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11896 1093 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
11897 1093 : && OMP_CLAUSE_DECL (c) == iter)
11898 : {
11899 120 : if (code == OMP_TASKLOOP || code == OMP_LOOP)
11900 : {
11901 60 : loop_iv_seen = c;
11902 60 : OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
11903 : }
11904 : break;
11905 : }
11906 973 : else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
11907 113 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
11908 1007 : && OMP_CLAUSE_DECL (c) == iter)
11909 : {
11910 30 : loop_iv_seen = c;
11911 30 : if (code == OMP_TASKLOOP)
11912 25 : OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
11913 : }
11914 :
11915 762 : decl = create_temporary_var (TREE_TYPE (diff));
11916 762 : pushdecl (decl);
11917 762 : add_decl_expr (decl);
11918 762 : last = create_temporary_var (TREE_TYPE (diff));
11919 762 : pushdecl (last);
11920 762 : add_decl_expr (last);
11921 762 : if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
11922 10 : && (!ordered || (i < collapse && collapse > 1)))
11923 : {
11924 10 : incr_var = create_temporary_var (TREE_TYPE (diff));
11925 10 : pushdecl (incr_var);
11926 10 : add_decl_expr (incr_var);
11927 : }
11928 762 : gcc_assert (stmts_are_full_exprs_p ());
11929 762 : tree diffvar = NULL_TREE;
11930 762 : if (code == OMP_TASKLOOP)
11931 : {
11932 101 : if (!loop_iv_seen)
11933 : {
11934 38 : tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11935 38 : OMP_CLAUSE_DECL (ivc) = iter;
11936 38 : cxx_omp_finish_clause (ivc, NULL, false);
11937 38 : OMP_CLAUSE_CHAIN (ivc) = clauses;
11938 38 : clauses = ivc;
11939 : }
11940 101 : tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11941 101 : OMP_CLAUSE_DECL (lvc) = last;
11942 101 : OMP_CLAUSE_CHAIN (lvc) = clauses;
11943 101 : clauses = lvc;
11944 101 : diffvar = create_temporary_var (TREE_TYPE (diff));
11945 101 : pushdecl (diffvar);
11946 101 : add_decl_expr (diffvar);
11947 : }
11948 661 : else if (code == OMP_LOOP)
11949 : {
11950 43 : if (!loop_iv_seen)
11951 : {
11952 : /* While iterators on the loop construct are predetermined
11953 : lastprivate, if the decl is not declared inside of the
11954 : loop, OMP_CLAUSE_LASTPRIVATE should have been added
11955 : already. */
11956 16 : loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11957 16 : OMP_CLAUSE_DECL (loop_iv_seen) = iter;
11958 16 : OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
11959 16 : clauses = loop_iv_seen;
11960 : }
11961 27 : else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
11962 : {
11963 5 : OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
11964 5 : OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
11965 5 : OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
11966 : }
11967 43 : if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
11968 21 : cxx_omp_finish_clause (loop_iv_seen, NULL, false);
11969 : }
11970 :
11971 762 : orig_pre_body = *pre_body;
11972 762 : *pre_body = push_stmt_list ();
11973 762 : if (orig_pre_body)
11974 610 : add_stmt (orig_pre_body);
11975 762 : if (init != NULL)
11976 61 : finish_expr_stmt (build_x_modify_expr (elocus,
11977 : iter, NOP_EXPR, init,
11978 : NULL_TREE, tf_warning_or_error));
11979 762 : init = build_int_cst (TREE_TYPE (diff), 0);
11980 762 : if (c && iter_incr == NULL
11981 28 : && (!ordered || (i < collapse && collapse > 1)))
11982 : {
11983 28 : if (incr_var)
11984 : {
11985 10 : finish_expr_stmt (build_x_modify_expr (elocus,
11986 : incr_var, NOP_EXPR,
11987 : incr, NULL_TREE,
11988 : tf_warning_or_error));
11989 10 : incr = incr_var;
11990 : }
11991 28 : iter_incr = build_x_modify_expr (elocus,
11992 : iter, PLUS_EXPR, incr,
11993 : NULL_TREE, tf_warning_or_error);
11994 : }
11995 762 : if (c && ordered && i < collapse && collapse > 1)
11996 762 : iter_incr = incr;
11997 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11998 : last, NOP_EXPR, init,
11999 : NULL_TREE, tf_warning_or_error));
12000 762 : if (diffvar)
12001 : {
12002 101 : finish_expr_stmt (build_x_modify_expr (elocus,
12003 : diffvar, NOP_EXPR,
12004 : diff, NULL_TREE, tf_warning_or_error));
12005 101 : diff = diffvar;
12006 : }
12007 762 : *pre_body = pop_stmt_list (*pre_body);
12008 :
12009 1524 : cond = cp_build_binary_op (elocus,
12010 762 : TREE_CODE (cond), decl, diff,
12011 : tf_warning_or_error);
12012 762 : incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
12013 : elocus, incr, NULL_TREE);
12014 :
12015 762 : orig_body = *body;
12016 762 : *body = push_stmt_list ();
12017 762 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
12018 762 : iter_init = build_x_modify_expr (elocus,
12019 : iter, PLUS_EXPR, iter_init,
12020 : NULL_TREE, tf_warning_or_error);
12021 762 : if (iter_init != error_mark_node)
12022 759 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
12023 762 : finish_expr_stmt (iter_init);
12024 762 : finish_expr_stmt (build_x_modify_expr (elocus,
12025 : last, NOP_EXPR, decl,
12026 : NULL_TREE, tf_warning_or_error));
12027 762 : add_stmt (orig_body);
12028 762 : *body = pop_stmt_list (*body);
12029 :
12030 762 : if (c)
12031 : {
12032 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
12033 120 : if (!ordered)
12034 114 : finish_expr_stmt (iter_incr);
12035 : else
12036 : {
12037 6 : iter_init = decl;
12038 6 : if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
12039 2 : iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
12040 : iter_init, iter_incr);
12041 6 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
12042 6 : iter_init = build_x_modify_expr (elocus,
12043 : iter, PLUS_EXPR, iter_init,
12044 : NULL_TREE, tf_warning_or_error);
12045 6 : if (iter_init != error_mark_node)
12046 6 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
12047 6 : finish_expr_stmt (iter_init);
12048 : }
12049 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c)
12050 240 : = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
12051 : }
12052 :
12053 762 : if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
12054 : {
12055 116 : tree t = TREE_VEC_ELT (orig_declv, i);
12056 116 : gcc_assert (TREE_PURPOSE (t) == NULL_TREE
12057 : && TREE_VALUE (t) == NULL_TREE
12058 : && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
12059 116 : TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
12060 116 : TREE_VALUE (t) = last;
12061 : }
12062 : else
12063 646 : TREE_VEC_ELT (orig_declv, i)
12064 1292 : = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
12065 762 : TREE_VEC_ELT (declv, i) = decl;
12066 762 : TREE_VEC_ELT (initv, i) = init;
12067 762 : TREE_VEC_ELT (condv, i) = cond;
12068 762 : TREE_VEC_ELT (incrv, i) = incr;
12069 :
12070 762 : return false;
12071 : }
12072 :
12073 : /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
12074 : are directly for their associated operands in the statement. DECL
12075 : and INIT are a combo; if DECL is NULL then INIT ought to be a
12076 : MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
12077 : optional statements that need to go before the loop into its
12078 : sk_omp scope. */
12079 :
12080 : tree
12081 21246 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
12082 : tree orig_declv, tree initv, tree condv, tree incrv,
12083 : tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
12084 : {
12085 21246 : tree omp_for = NULL, orig_incr = NULL;
12086 21246 : tree decl = NULL, init, cond, incr;
12087 21246 : location_t elocus;
12088 21246 : int i;
12089 21246 : int collapse = 1;
12090 21246 : int ordered = 0;
12091 21246 : auto_vec<location_t> init_locv;
12092 :
12093 21246 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
12094 21246 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
12095 21246 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
12096 21246 : if (TREE_VEC_LENGTH (declv) > 1)
12097 : {
12098 4054 : if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
12099 83 : collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
12100 : else
12101 : {
12102 3971 : if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
12103 3501 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
12104 470 : else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
12105 394 : collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
12106 3971 : if (collapse != TREE_VEC_LENGTH (declv))
12107 100 : ordered = TREE_VEC_LENGTH (declv);
12108 : }
12109 : }
12110 48837 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
12111 : {
12112 27627 : decl = TREE_VEC_ELT (declv, i);
12113 27627 : init = TREE_VEC_ELT (initv, i);
12114 27627 : cond = TREE_VEC_ELT (condv, i);
12115 27627 : incr = TREE_VEC_ELT (incrv, i);
12116 27627 : elocus = locus;
12117 :
12118 27627 : if (decl == global_namespace)
12119 : {
12120 1101 : gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
12121 1101 : TREE_VEC_ELT (declv, i) = NULL_TREE;
12122 1101 : init_locv.safe_push (UNKNOWN_LOCATION);
12123 1101 : continue;
12124 : }
12125 : /* We are going to throw out the init's original MODIFY_EXPR or
12126 : MODOP_EXPR below. Save its location so we can use it when
12127 : reconstructing the expression farther down. Alternatively, if the
12128 : initializer is a binding of the iteration variable, save
12129 : that location. Any of these locations in the initialization clause
12130 : for the current nested loop are better than using the argument locus,
12131 : that points to the "for" of the outermost loop in the nest. */
12132 26526 : if (init && EXPR_HAS_LOCATION (init))
12133 17962 : elocus = EXPR_LOCATION (init);
12134 8564 : else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
12135 : /* This can happen for class iterators. */
12136 0 : elocus = EXPR_LOCATION (decl);
12137 8564 : else if (decl && DECL_P (decl))
12138 : {
12139 8537 : if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
12140 8537 : elocus = DECL_SOURCE_LOCATION (decl);
12141 0 : else if (DECL_INITIAL (decl)
12142 0 : && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
12143 0 : elocus = EXPR_LOCATION (DECL_INITIAL (decl));
12144 : }
12145 26526 : init_locv.safe_push (elocus);
12146 :
12147 26526 : if (decl == NULL)
12148 : {
12149 16654 : if (init != NULL)
12150 16651 : switch (TREE_CODE (init))
12151 : {
12152 16244 : case MODIFY_EXPR:
12153 16244 : decl = TREE_OPERAND (init, 0);
12154 16244 : init = TREE_OPERAND (init, 1);
12155 16244 : break;
12156 389 : case MODOP_EXPR:
12157 389 : if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
12158 : {
12159 389 : decl = TREE_OPERAND (init, 0);
12160 389 : init = TREE_OPERAND (init, 2);
12161 : }
12162 : break;
12163 : default:
12164 : break;
12165 : }
12166 :
12167 16654 : if (decl == NULL)
12168 : {
12169 21 : error_at (locus,
12170 : "expected iteration declaration or initialization");
12171 21 : return NULL;
12172 : }
12173 : }
12174 :
12175 26505 : if (cond == global_namespace)
12176 170 : continue;
12177 :
12178 26335 : if (cond == NULL)
12179 : {
12180 9 : error_at (elocus, "missing controlling predicate");
12181 9 : return NULL;
12182 : }
12183 :
12184 26326 : if (incr == NULL)
12185 : {
12186 6 : error_at (elocus, "missing increment expression");
12187 6 : return NULL;
12188 : }
12189 :
12190 26320 : TREE_VEC_ELT (declv, i) = decl;
12191 26320 : TREE_VEC_ELT (initv, i) = init;
12192 : }
12193 :
12194 21210 : if (orig_inits)
12195 : {
12196 : bool fail = false;
12197 : tree orig_init;
12198 21310 : FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
12199 1181 : if (orig_init
12200 3396 : && !c_omp_check_loop_iv_exprs (locus, code,
12201 : orig_declv ? orig_declv : declv, i,
12202 1164 : TREE_VEC_ELT (declv, i), orig_init,
12203 : NULL_TREE, cp_walk_subtrees))
12204 : fail = true;
12205 20129 : if (fail)
12206 21246 : return NULL;
12207 : }
12208 :
12209 21153 : if (dependent_omp_for_p (declv, initv, condv, incrv, body))
12210 : {
12211 453 : tree stmt;
12212 :
12213 453 : stmt = make_node (code);
12214 :
12215 1499 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
12216 : {
12217 593 : if (TREE_VEC_ELT (declv, i) == NULL_TREE)
12218 9 : continue;
12219 : /* This is really just a place-holder. We'll be decomposing this
12220 : again and going through the cp_build_modify_expr path below when
12221 : we instantiate the thing. */
12222 584 : TREE_VEC_ELT (initv, i)
12223 1168 : = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
12224 584 : TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
12225 : }
12226 :
12227 453 : TREE_TYPE (stmt) = void_type_node;
12228 453 : OMP_FOR_INIT (stmt) = initv;
12229 453 : OMP_FOR_COND (stmt) = condv;
12230 453 : OMP_FOR_INCR (stmt) = incrv;
12231 453 : OMP_FOR_BODY (stmt) = body;
12232 453 : OMP_FOR_PRE_BODY (stmt) = pre_body;
12233 453 : OMP_FOR_CLAUSES (stmt) = clauses;
12234 :
12235 453 : SET_EXPR_LOCATION (stmt, locus);
12236 453 : return add_stmt (stmt);
12237 : }
12238 :
12239 20700 : if (!orig_declv)
12240 19891 : orig_declv = copy_node (declv);
12241 :
12242 20700 : if (processing_template_decl)
12243 634 : orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
12244 :
12245 48266 : for (i = 0; i < TREE_VEC_LENGTH (declv); )
12246 : {
12247 27658 : decl = TREE_VEC_ELT (declv, i);
12248 27658 : init = TREE_VEC_ELT (initv, i);
12249 27658 : cond = TREE_VEC_ELT (condv, i);
12250 27658 : incr = TREE_VEC_ELT (incrv, i);
12251 27658 : if (orig_incr)
12252 866 : TREE_VEC_ELT (orig_incr, i) = incr;
12253 27658 : elocus = init_locv[i];
12254 :
12255 27658 : if (decl == NULL_TREE)
12256 : {
12257 1092 : i++;
12258 1092 : continue;
12259 : }
12260 :
12261 26566 : if (!DECL_P (decl))
12262 : {
12263 6 : error_at (elocus, "expected iteration declaration or initialization");
12264 6 : return NULL;
12265 : }
12266 :
12267 26560 : if (incr && TREE_CODE (incr) == MODOP_EXPR)
12268 : {
12269 1 : if (orig_incr)
12270 1 : TREE_VEC_ELT (orig_incr, i) = incr;
12271 1 : incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
12272 1 : TREE_CODE (TREE_OPERAND (incr, 1)),
12273 1 : TREE_OPERAND (incr, 2),
12274 : tf_warning_or_error);
12275 : }
12276 :
12277 26560 : if (CLASS_TYPE_P (TREE_TYPE (decl)))
12278 : {
12279 825 : if (code == OMP_SIMD)
12280 : {
12281 12 : error_at (elocus, "%<#pragma omp simd%> used with class "
12282 : "iteration variable %qE", decl);
12283 12 : return NULL;
12284 : }
12285 813 : if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
12286 : initv, condv, incrv, &body,
12287 : &pre_body, clauses,
12288 : collapse, ordered))
12289 : return NULL;
12290 762 : continue;
12291 : }
12292 :
12293 51470 : if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
12294 27321 : && !TYPE_PTR_P (TREE_TYPE (decl)))
12295 : {
12296 14 : error_at (elocus, "invalid type for iteration variable %qE", decl);
12297 14 : return NULL;
12298 : }
12299 :
12300 25721 : if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
12301 24938 : init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
12302 : tf_warning_or_error);
12303 : else
12304 783 : init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
12305 25721 : if (decl == error_mark_node || init == error_mark_node)
12306 : return NULL;
12307 :
12308 25712 : TREE_VEC_ELT (declv, i) = decl;
12309 25712 : TREE_VEC_ELT (initv, i) = init;
12310 25712 : TREE_VEC_ELT (condv, i) = cond;
12311 25712 : TREE_VEC_ELT (incrv, i) = incr;
12312 25712 : i++;
12313 : }
12314 :
12315 20608 : if (pre_body && IS_EMPTY_STMT (pre_body))
12316 0 : pre_body = NULL;
12317 :
12318 41216 : omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
12319 : incrv, body, pre_body,
12320 20608 : !processing_template_decl);
12321 :
12322 : /* Check for iterators appearing in lb, b or incr expressions. */
12323 20608 : if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
12324 : omp_for = NULL_TREE;
12325 :
12326 20122 : if (omp_for == NULL)
12327 : return NULL;
12328 :
12329 19906 : add_stmt (omp_for);
12330 :
12331 65590 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
12332 : {
12333 25778 : init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
12334 25778 : if (init == NULL_TREE)
12335 1032 : continue;
12336 24746 : decl = TREE_OPERAND (init, 0);
12337 24746 : cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
12338 24746 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
12339 :
12340 24746 : if (!processing_template_decl)
12341 : {
12342 24203 : if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
12343 : {
12344 106 : tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
12345 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
12346 106 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12347 106 : t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
12348 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
12349 212 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12350 : }
12351 : else
12352 : {
12353 24097 : tree t = TREE_OPERAND (init, 1);
12354 24097 : TREE_OPERAND (init, 1)
12355 48194 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12356 : }
12357 24203 : if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
12358 : {
12359 121 : tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
12360 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
12361 121 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12362 121 : t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
12363 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
12364 242 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12365 : }
12366 : else
12367 : {
12368 24082 : tree t = TREE_OPERAND (cond, 1);
12369 24082 : TREE_OPERAND (cond, 1)
12370 48164 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12371 : }
12372 : }
12373 :
12374 24746 : if (TREE_CODE (incr) != MODIFY_EXPR)
12375 18541 : continue;
12376 :
12377 6205 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
12378 70 : && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
12379 6275 : && !processing_template_decl)
12380 : {
12381 64 : tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
12382 64 : if (TREE_SIDE_EFFECTS (t)
12383 8 : && t != decl
12384 70 : && (TREE_CODE (t) != NOP_EXPR
12385 0 : || TREE_OPERAND (t, 0) != decl))
12386 6 : TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
12387 12 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12388 :
12389 64 : t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
12390 64 : if (TREE_SIDE_EFFECTS (t)
12391 56 : && t != decl
12392 120 : && (TREE_CODE (t) != NOP_EXPR
12393 5 : || TREE_OPERAND (t, 0) != decl))
12394 56 : TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
12395 112 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12396 : }
12397 :
12398 6205 : if (orig_incr)
12399 177 : TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
12400 : }
12401 19906 : OMP_FOR_CLAUSES (omp_for) = clauses;
12402 :
12403 : /* For simd loops with non-static data member iterators, we could have added
12404 : OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
12405 : step at this point, fill it in. */
12406 4741 : if (code == OMP_SIMD && !processing_template_decl
12407 24603 : && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
12408 4625 : for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
12409 561 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
12410 561 : if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
12411 : {
12412 4 : decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
12413 4 : gcc_assert (decl == OMP_CLAUSE_DECL (c));
12414 4 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
12415 4 : tree step, stept;
12416 4 : switch (TREE_CODE (incr))
12417 : {
12418 0 : case PREINCREMENT_EXPR:
12419 0 : case POSTINCREMENT_EXPR:
12420 : /* c_omp_for_incr_canonicalize_ptr() should have been
12421 : called to massage things appropriately. */
12422 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12423 0 : OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
12424 0 : break;
12425 0 : case PREDECREMENT_EXPR:
12426 0 : case POSTDECREMENT_EXPR:
12427 : /* c_omp_for_incr_canonicalize_ptr() should have been
12428 : called to massage things appropriately. */
12429 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12430 0 : OMP_CLAUSE_LINEAR_STEP (c)
12431 0 : = build_int_cst (TREE_TYPE (decl), -1);
12432 0 : break;
12433 4 : case MODIFY_EXPR:
12434 4 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12435 4 : incr = TREE_OPERAND (incr, 1);
12436 4 : switch (TREE_CODE (incr))
12437 : {
12438 4 : case PLUS_EXPR:
12439 4 : if (TREE_OPERAND (incr, 1) == decl)
12440 0 : step = TREE_OPERAND (incr, 0);
12441 : else
12442 4 : step = TREE_OPERAND (incr, 1);
12443 : break;
12444 0 : case MINUS_EXPR:
12445 0 : case POINTER_PLUS_EXPR:
12446 0 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12447 0 : step = TREE_OPERAND (incr, 1);
12448 0 : break;
12449 0 : default:
12450 0 : gcc_unreachable ();
12451 : }
12452 4 : stept = TREE_TYPE (decl);
12453 4 : if (INDIRECT_TYPE_P (stept))
12454 0 : stept = sizetype;
12455 4 : step = fold_convert (stept, step);
12456 4 : if (TREE_CODE (incr) == MINUS_EXPR)
12457 0 : step = fold_build1 (NEGATE_EXPR, stept, step);
12458 4 : OMP_CLAUSE_LINEAR_STEP (c) = step;
12459 4 : break;
12460 0 : default:
12461 0 : gcc_unreachable ();
12462 : }
12463 : }
12464 : /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
12465 : clauses, we need copy ctor for those rather than default ctor,
12466 : plus as for other lastprivates assignment op and dtor. */
12467 19906 : if (code == OMP_LOOP && !processing_template_decl)
12468 1993 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12469 1285 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
12470 204 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
12471 1307 : && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
12472 : false, true, true, true))
12473 0 : CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
12474 :
12475 : return omp_for;
12476 21246 : }
12477 :
12478 : /* Code walker for finish_omp_for_block: extract binding of DP->var
12479 : from its current block and move it to a new BIND_EXPR DP->b
12480 : surrounding the body of DP->omp_for. */
12481 :
12482 : struct fofb_data {
12483 : tree var;
12484 : tree b;
12485 : tree omp_for;
12486 : };
12487 :
12488 : static tree
12489 389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
12490 : {
12491 389 : struct fofb_data *fofb = (struct fofb_data *)dp;
12492 389 : if (TREE_CODE (*tp) == BIND_EXPR)
12493 578 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
12494 : {
12495 576 : if (*p == fofb->var)
12496 : {
12497 363 : *p = DECL_CHAIN (*p);
12498 363 : if (fofb->b == NULL_TREE)
12499 : {
12500 214 : fofb->b = make_node (BLOCK);
12501 214 : fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
12502 214 : OMP_FOR_BODY (fofb->omp_for), fofb->b);
12503 214 : TREE_SIDE_EFFECTS (fofb->b) = 1;
12504 214 : OMP_FOR_BODY (fofb->omp_for) = fofb->b;
12505 : }
12506 363 : DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
12507 363 : BIND_EXPR_VARS (fofb->b) = fofb->var;
12508 363 : BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
12509 363 : BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
12510 363 : return *tp;
12511 : }
12512 : }
12513 26 : if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
12514 22 : *walk_subtrees = false;
12515 : return NULL_TREE;
12516 : }
12517 :
12518 : /* Fix up range for decls. Those decls were pushed into BIND's
12519 : BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
12520 : and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
12521 : so that processing of combined loop directives can find them. */
12522 : tree
12523 14665 : finish_omp_for_block (tree bind, tree omp_for)
12524 : {
12525 14665 : if (omp_for == NULL_TREE
12526 14618 : || !OMP_FOR_ORIG_DECLS (omp_for)
12527 28693 : || bind == NULL_TREE)
12528 637 : return bind;
12529 14028 : struct fofb_data fofb;
12530 14028 : fofb.b = NULL_TREE;
12531 14028 : fofb.omp_for = omp_for;
12532 33583 : for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
12533 19555 : if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
12534 19333 : && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
12535 : == TREE_LIST)
12536 20386 : && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
12537 : {
12538 237 : tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
12539 602 : for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
12540 : {
12541 365 : fofb.var = TREE_VEC_ELT (v, j);
12542 365 : cp_walk_tree (&bind, finish_omp_for_block_walker,
12543 : (void *)&fofb, NULL);
12544 : }
12545 : }
12546 14028 : return bind;
12547 : }
12548 :
12549 : void
12550 3345 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
12551 : tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
12552 : tree clauses, enum omp_memory_order mo, bool weak)
12553 : {
12554 3345 : tree orig_lhs;
12555 3345 : tree orig_rhs;
12556 3345 : tree orig_v;
12557 3345 : tree orig_lhs1;
12558 3345 : tree orig_rhs1;
12559 3345 : tree orig_r;
12560 3345 : bool dependent_p;
12561 3345 : tree stmt;
12562 :
12563 3345 : orig_lhs = lhs;
12564 3345 : orig_rhs = rhs;
12565 3345 : orig_v = v;
12566 3345 : orig_lhs1 = lhs1;
12567 3345 : orig_rhs1 = rhs1;
12568 3345 : orig_r = r;
12569 3345 : dependent_p = false;
12570 3345 : stmt = NULL_TREE;
12571 :
12572 : /* Even in a template, we can detect invalid uses of the atomic
12573 : pragma if neither LHS nor RHS is type-dependent. */
12574 3345 : if (processing_template_decl)
12575 : {
12576 600 : dependent_p = (type_dependent_expression_p (lhs)
12577 237 : || (rhs && type_dependent_expression_p (rhs))
12578 234 : || (v && type_dependent_expression_p (v))
12579 234 : || (lhs1 && type_dependent_expression_p (lhs1))
12580 234 : || (rhs1 && type_dependent_expression_p (rhs1))
12581 834 : || (r
12582 25 : && r != void_list_node
12583 16 : && type_dependent_expression_p (r)));
12584 600 : if (clauses)
12585 : {
12586 30 : gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
12587 : && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
12588 : && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
12589 30 : if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
12590 30 : || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
12591 : dependent_p = true;
12592 : }
12593 : }
12594 576 : if (!dependent_p)
12595 : {
12596 2961 : bool swapped = false;
12597 2961 : if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
12598 : {
12599 143 : std::swap (rhs, rhs1);
12600 143 : swapped = !commutative_tree_code (opcode);
12601 : }
12602 2961 : if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
12603 : {
12604 0 : if (code == OMP_ATOMIC)
12605 0 : error ("%<#pragma omp atomic update%> uses two different "
12606 : "expressions for memory");
12607 : else
12608 0 : error ("%<#pragma omp atomic capture%> uses two different "
12609 : "expressions for memory");
12610 : return;
12611 : }
12612 2961 : if (lhs1 && !cp_tree_equal (lhs, lhs1))
12613 : {
12614 0 : if (code == OMP_ATOMIC)
12615 0 : error ("%<#pragma omp atomic update%> uses two different "
12616 : "expressions for memory");
12617 : else
12618 0 : error ("%<#pragma omp atomic capture%> uses two different "
12619 : "expressions for memory");
12620 : return;
12621 : }
12622 5922 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
12623 : v, lhs1, rhs1, r, swapped, mo, weak,
12624 2961 : processing_template_decl != 0);
12625 2961 : if (stmt == error_mark_node)
12626 : return;
12627 : }
12628 3315 : if (processing_template_decl)
12629 : {
12630 591 : if (code == OMP_ATOMIC_READ)
12631 : {
12632 167 : stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
12633 167 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12634 167 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12635 : }
12636 : else
12637 : {
12638 424 : if (opcode == NOP_EXPR)
12639 35 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
12640 389 : else if (opcode == COND_EXPR)
12641 : {
12642 124 : stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
12643 124 : if (orig_r)
12644 50 : stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
12645 : stmt);
12646 124 : stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
12647 : orig_lhs);
12648 124 : orig_rhs1 = NULL_TREE;
12649 : }
12650 : else
12651 265 : stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
12652 424 : if (orig_rhs1)
12653 182 : stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
12654 : COMPOUND_EXPR, orig_rhs1, stmt);
12655 424 : if (code != OMP_ATOMIC)
12656 : {
12657 233 : stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
12658 233 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12659 233 : OMP_ATOMIC_WEAK (stmt) = weak;
12660 233 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12661 : }
12662 : }
12663 591 : stmt = build2 (OMP_ATOMIC, void_type_node,
12664 : clauses ? clauses : integer_zero_node, stmt);
12665 591 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12666 591 : OMP_ATOMIC_WEAK (stmt) = weak;
12667 591 : SET_EXPR_LOCATION (stmt, loc);
12668 : }
12669 :
12670 : /* Avoid -Wunused-value warnings here, the whole construct has side-effects
12671 : and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
12672 : in some tree that appears to be unused, the value is not unused. */
12673 3315 : warning_sentinel w (warn_unused_value);
12674 3315 : finish_expr_stmt (stmt);
12675 3315 : }
12676 :
12677 : void
12678 359 : finish_omp_barrier (void)
12679 : {
12680 359 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
12681 359 : releasing_vec vec;
12682 359 : vec->quick_push (build_int_cst (integer_type_node, GOMP_BARRIER_EXPLICIT));
12683 359 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12684 359 : finish_expr_stmt (stmt);
12685 359 : }
12686 :
12687 : void
12688 397 : finish_omp_depobj (location_t loc, tree depobj,
12689 : enum omp_clause_depend_kind kind, tree clause)
12690 : {
12691 397 : if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
12692 : {
12693 343 : if (!lvalue_p (depobj))
12694 : {
12695 6 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
12696 : "%<depobj%> expression is not lvalue expression");
12697 6 : depobj = error_mark_node;
12698 : }
12699 : }
12700 :
12701 397 : if (processing_template_decl)
12702 : {
12703 114 : if (clause == NULL_TREE)
12704 47 : clause = build_int_cst (integer_type_node, kind);
12705 114 : add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
12706 114 : return;
12707 : }
12708 :
12709 283 : if (!error_operand_p (depobj))
12710 : {
12711 274 : tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
12712 274 : if (addr == error_mark_node)
12713 : depobj = error_mark_node;
12714 : else
12715 274 : depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
12716 : tf_warning_or_error);
12717 : }
12718 :
12719 283 : c_finish_omp_depobj (loc, depobj, kind, clause);
12720 : }
12721 :
12722 : void
12723 162 : finish_omp_flush (int mo)
12724 : {
12725 162 : tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
12726 162 : releasing_vec vec;
12727 162 : if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
12728 : {
12729 54 : fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
12730 54 : vec->quick_push (build_int_cst (integer_type_node, mo));
12731 : }
12732 162 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12733 162 : finish_expr_stmt (stmt);
12734 162 : }
12735 :
12736 : void
12737 111 : finish_omp_taskwait (void)
12738 : {
12739 111 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
12740 111 : releasing_vec vec;
12741 111 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12742 111 : finish_expr_stmt (stmt);
12743 111 : }
12744 :
12745 : void
12746 16 : finish_omp_taskyield (void)
12747 : {
12748 16 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
12749 16 : releasing_vec vec;
12750 16 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12751 16 : finish_expr_stmt (stmt);
12752 16 : }
12753 :
12754 : void
12755 596 : finish_omp_cancel (tree clauses)
12756 : {
12757 596 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
12758 596 : int mask = 0;
12759 596 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12760 : mask = 1;
12761 414 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12762 : mask = 2;
12763 285 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12764 : mask = 4;
12765 164 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12766 : mask = 8;
12767 : else
12768 : {
12769 0 : error ("%<#pragma omp cancel%> must specify one of "
12770 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12771 0 : return;
12772 : }
12773 596 : releasing_vec vec;
12774 596 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
12775 596 : if (ifc != NULL_TREE)
12776 : {
12777 70 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
12778 70 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
12779 6 : error_at (OMP_CLAUSE_LOCATION (ifc),
12780 : "expected %<cancel%> %<if%> clause modifier");
12781 : else
12782 : {
12783 64 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
12784 64 : if (ifc2 != NULL_TREE)
12785 : {
12786 3 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
12787 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
12788 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
12789 3 : error_at (OMP_CLAUSE_LOCATION (ifc2),
12790 : "expected %<cancel%> %<if%> clause modifier");
12791 : }
12792 : }
12793 :
12794 70 : if (!processing_template_decl)
12795 61 : ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
12796 : else
12797 9 : ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
12798 9 : OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
12799 : integer_zero_node, ERROR_MARK,
12800 : NULL_TREE, NULL, tf_warning_or_error);
12801 : }
12802 : else
12803 526 : ifc = boolean_true_node;
12804 596 : vec->quick_push (build_int_cst (integer_type_node, mask));
12805 596 : vec->quick_push (ifc);
12806 596 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12807 596 : finish_expr_stmt (stmt);
12808 596 : }
12809 :
12810 : void
12811 494 : finish_omp_cancellation_point (tree clauses)
12812 : {
12813 494 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
12814 494 : int mask = 0;
12815 494 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12816 : mask = 1;
12817 366 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12818 : mask = 2;
12819 261 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12820 : mask = 4;
12821 156 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12822 : mask = 8;
12823 : else
12824 : {
12825 3 : error ("%<#pragma omp cancellation point%> must specify one of "
12826 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12827 3 : return;
12828 : }
12829 491 : releasing_vec vec
12830 491 : = make_tree_vector_single (build_int_cst (integer_type_node, mask));
12831 491 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12832 491 : finish_expr_stmt (stmt);
12833 491 : }
12834 :
12835 : /* Begin a __transaction_atomic or __transaction_relaxed statement.
12836 : If PCOMPOUND is non-null, this is for a function-transaction-block, and we
12837 : should create an extra compound stmt. */
12838 :
12839 : tree
12840 303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
12841 : {
12842 303 : tree r;
12843 :
12844 303 : if (pcompound)
12845 21 : *pcompound = begin_compound_stmt (0);
12846 :
12847 303 : r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
12848 :
12849 : /* Only add the statement to the function if support enabled. */
12850 303 : if (flag_tm)
12851 297 : add_stmt (r);
12852 : else
12853 12 : error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
12854 : ? G_("%<__transaction_relaxed%> without "
12855 : "transactional memory support enabled")
12856 : : G_("%<__transaction_atomic%> without "
12857 : "transactional memory support enabled")));
12858 :
12859 303 : TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
12860 303 : TREE_SIDE_EFFECTS (r) = 1;
12861 303 : return r;
12862 : }
12863 :
12864 : /* End a __transaction_atomic or __transaction_relaxed statement.
12865 : If COMPOUND_STMT is non-null, this is for a function-transaction-block,
12866 : and we should end the compound. If NOEX is non-NULL, we wrap the body in
12867 : a MUST_NOT_THROW_EXPR with NOEX as condition. */
12868 :
12869 : void
12870 303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
12871 : {
12872 303 : TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
12873 303 : TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
12874 303 : TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
12875 303 : TRANSACTION_EXPR_IS_STMT (stmt) = 1;
12876 :
12877 : /* noexcept specifications are not allowed for function transactions. */
12878 303 : gcc_assert (!(noex && compound_stmt));
12879 303 : if (noex)
12880 : {
12881 51 : tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
12882 : noex);
12883 51 : protected_set_expr_location
12884 51 : (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
12885 51 : TREE_SIDE_EFFECTS (body) = 1;
12886 51 : TRANSACTION_EXPR_BODY (stmt) = body;
12887 : }
12888 :
12889 303 : if (compound_stmt)
12890 21 : finish_compound_stmt (compound_stmt);
12891 303 : }
12892 :
12893 : /* Build a __transaction_atomic or __transaction_relaxed expression. If
12894 : NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
12895 : condition. */
12896 :
12897 : tree
12898 116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
12899 : {
12900 116 : tree ret;
12901 116 : if (noex)
12902 : {
12903 57 : expr = build_must_not_throw_expr (expr, noex);
12904 57 : protected_set_expr_location (expr, loc);
12905 57 : TREE_SIDE_EFFECTS (expr) = 1;
12906 : }
12907 116 : ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
12908 116 : if (flags & TM_STMT_ATTR_RELAXED)
12909 4 : TRANSACTION_EXPR_RELAXED (ret) = 1;
12910 116 : TREE_SIDE_EFFECTS (ret) = 1;
12911 116 : SET_EXPR_LOCATION (ret, loc);
12912 116 : return ret;
12913 : }
12914 :
12915 : void
12916 101479 : init_cp_semantics (void)
12917 : {
12918 101479 : }
12919 :
12920 :
12921 : /* Get constant string at LOCATION. Returns true if successful,
12922 : otherwise false. */
12923 :
12924 : bool
12925 11446865 : cexpr_str::type_check (location_t location, bool allow_char8_t /*=false*/)
12926 : {
12927 11446865 : tsubst_flags_t complain = tf_warning_or_error;
12928 :
12929 11446865 : if (message == NULL_TREE
12930 11446865 : || message == error_mark_node
12931 22893727 : || check_for_bare_parameter_packs (message))
12932 : return false;
12933 :
12934 11446862 : if (TREE_CODE (message) != STRING_CST
12935 11446862 : && !type_dependent_expression_p (message))
12936 : {
12937 1053 : message_sz
12938 1053 : = finish_class_member_access_expr (message,
12939 : get_identifier ("size"),
12940 : false, complain);
12941 1053 : if (message_sz != error_mark_node)
12942 952 : message_data
12943 952 : = finish_class_member_access_expr (message,
12944 : get_identifier ("data"),
12945 : false, complain);
12946 1053 : if (message_sz == error_mark_node || message_data == error_mark_node)
12947 : {
12948 139 : error_at (location, "constexpr string must be a string "
12949 : "literal or object with %<size%> and "
12950 : "%<data%> members");
12951 322 : return false;
12952 : }
12953 914 : releasing_vec size_args, data_args;
12954 914 : message_sz = finish_call_expr (message_sz, &size_args, false, false,
12955 : complain);
12956 914 : message_data = finish_call_expr (message_data, &data_args, false, false,
12957 : complain);
12958 914 : if (message_sz == error_mark_node || message_data == error_mark_node)
12959 : return false;
12960 800 : message_sz = build_converted_constant_expr (size_type_node, message_sz,
12961 : complain);
12962 800 : if (message_sz == error_mark_node)
12963 : {
12964 15 : error_at (location, "constexpr string %<size()%> "
12965 : "must be implicitly convertible to "
12966 : "%<std::size_t%>");
12967 15 : return false;
12968 : }
12969 :
12970 785 : if (allow_char8_t
12971 74 : && POINTER_TYPE_P (TREE_TYPE (message_data))
12972 74 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
12973 74 : == char8_type_node)
12974 805 : && (TYPE_QUALS (TREE_TYPE (TREE_TYPE (message_data)))
12975 : == TYPE_QUAL_CONST))
12976 : return true;
12977 :
12978 765 : message_data = build_converted_constant_expr (const_string_type_node,
12979 : message_data, complain);
12980 765 : if (message_data == error_mark_node)
12981 : {
12982 34 : error_at (location, "constexpr string %<data()%> "
12983 : "must be implicitly convertible to "
12984 : "%<const char*%>");
12985 34 : return false;
12986 : }
12987 914 : }
12988 : return true;
12989 : }
12990 :
12991 : /* Extract constant string at LOCATON into output string STR.
12992 : Returns true if successful, otherwise false. */
12993 :
12994 : bool
12995 405 : cexpr_str::extract (location_t location, tree &str)
12996 : {
12997 405 : const char *msg;
12998 405 : int len;
12999 405 : if (!extract (location, msg, len))
13000 : return false;
13001 343 : str = build_string (len, msg);
13002 343 : return true;
13003 : }
13004 :
13005 : /* Extract constant string at LOCATION into output string MSG with LEN.
13006 : Returns true if successful, otherwise false. */
13007 :
13008 : bool
13009 2705 : cexpr_str::extract (location_t location, const char * &msg, int &len,
13010 : const constexpr_ctx *ctx /* = NULL */,
13011 : bool *non_constant_p /* = NULL */,
13012 : bool *overflow_p /* = NULL */,
13013 : tree *jump_target /* = NULL */)
13014 : {
13015 2705 : tsubst_flags_t complain = tf_warning_or_error;
13016 :
13017 2705 : msg = NULL;
13018 2705 : if (message_sz && message_data)
13019 : {
13020 677 : tree msz;
13021 677 : if (ctx)
13022 : {
13023 110 : msz = cxx_eval_constant_expression (ctx, message_sz, vc_prvalue,
13024 : non_constant_p, overflow_p,
13025 : jump_target);
13026 110 : if (*jump_target || *non_constant_p)
13027 : return false;
13028 : }
13029 : else
13030 567 : msz = cxx_constant_value (message_sz, NULL_TREE, complain);
13031 669 : if (!tree_fits_uhwi_p (msz))
13032 : {
13033 35 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
13034 35 : error_at (location,
13035 : "constexpr string %<size()%> "
13036 : "must be a constant expression");
13037 : return false;
13038 : }
13039 634 : else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
13040 : != tree_to_uhwi (msz))
13041 : {
13042 0 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
13043 0 : error_at (location,
13044 : "constexpr string message %<size()%> "
13045 : "%qE too large", msz);
13046 : return false;
13047 : }
13048 634 : len = tree_to_uhwi (msz);
13049 634 : tree data;
13050 634 : if (ctx)
13051 : {
13052 102 : data = cxx_eval_constant_expression (ctx, message_data, vc_prvalue,
13053 : non_constant_p, overflow_p,
13054 : jump_target);
13055 102 : if (*jump_target || *non_constant_p)
13056 : return false;
13057 94 : STRIP_NOPS (data);
13058 94 : if (TREE_CODE (data) != ADDR_EXPR)
13059 : {
13060 0 : unhandled:
13061 0 : if (!cxx_constexpr_quiet_p (ctx))
13062 0 : error_at (location, "unhandled return from %<data()%>");
13063 : return false;
13064 : }
13065 94 : tree str = TREE_OPERAND (data, 0);
13066 94 : unsigned HOST_WIDE_INT off = 0;
13067 94 : if (TREE_CODE (str) == ARRAY_REF
13068 94 : && tree_fits_uhwi_p (TREE_OPERAND (str, 1)))
13069 : {
13070 12 : off = tree_to_uhwi (TREE_OPERAND (str, 1));
13071 12 : str = TREE_OPERAND (str, 0);
13072 : }
13073 94 : str = cxx_eval_constant_expression (ctx, str, vc_prvalue,
13074 : non_constant_p, overflow_p,
13075 : jump_target);
13076 94 : if (*jump_target || *non_constant_p)
13077 : return false;
13078 94 : if (TREE_CODE (str) == STRING_CST)
13079 : {
13080 84 : if (TREE_STRING_LENGTH (str) < len
13081 84 : || (unsigned) TREE_STRING_LENGTH (str) < off
13082 168 : || (unsigned) TREE_STRING_LENGTH (str) < off + len)
13083 0 : goto unhandled;
13084 84 : msg = TREE_STRING_POINTER (str) + off;
13085 84 : goto translate;
13086 : }
13087 10 : if (TREE_CODE (str) != CONSTRUCTOR
13088 10 : || TREE_CODE (TREE_TYPE (str)) != ARRAY_TYPE)
13089 0 : goto unhandled;
13090 10 : char *b;
13091 10 : if (len < 64)
13092 10 : b = XALLOCAVEC (char, len + 1);
13093 : else
13094 : {
13095 0 : buf = XNEWVEC (char, len + 1);
13096 0 : b = buf;
13097 : }
13098 10 : msg = b;
13099 10 : memset (b, 0, len + 1);
13100 10 : tree field, value;
13101 10 : unsigned k;
13102 10 : unsigned HOST_WIDE_INT l = 0;
13103 158 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (str), k, field, value)
13104 158 : if (!tree_fits_shwi_p (value))
13105 0 : goto unhandled;
13106 158 : else if (field == NULL_TREE)
13107 : {
13108 0 : if (integer_zerop (value))
13109 : break;
13110 0 : if (l >= off && l < off + len)
13111 0 : b[l - off] = tree_to_shwi (value);
13112 0 : ++l;
13113 : }
13114 158 : else if (TREE_CODE (field) == RANGE_EXPR)
13115 : {
13116 0 : tree lo = TREE_OPERAND (field, 0);
13117 0 : tree hi = TREE_OPERAND (field, 1);
13118 0 : if (!tree_fits_uhwi_p (lo) || !tree_fits_uhwi_p (hi))
13119 0 : goto unhandled;
13120 0 : if (integer_zerop (value))
13121 : break;
13122 0 : unsigned HOST_WIDE_INT m = tree_to_uhwi (hi);
13123 0 : for (l = tree_to_uhwi (lo); l <= m; ++l)
13124 0 : if (l >= off && l < off + len)
13125 0 : b[l - off] = tree_to_shwi (value);
13126 : }
13127 158 : else if (tree_fits_uhwi_p (field))
13128 : {
13129 158 : l = tree_to_uhwi (field);
13130 158 : if (integer_zerop (value))
13131 : break;
13132 148 : if (l >= off && l < off + len)
13133 148 : b[l - off] = tree_to_shwi (value);
13134 148 : l++;
13135 : }
13136 10 : b[len] = '\0';
13137 : }
13138 : else
13139 : {
13140 532 : data = maybe_constant_value (message_data, NULL_TREE, mce_true);
13141 532 : if (!reduced_constant_expression_p (data))
13142 96 : data = NULL_TREE;
13143 532 : if (len)
13144 : {
13145 455 : if (data)
13146 381 : msg = c_getstr (data);
13147 455 : if (msg == NULL)
13148 119 : buf = XNEWVEC (char, len);
13149 1458 : for (int i = 0; i < len; ++i)
13150 : {
13151 1033 : tree t = message_data;
13152 1033 : if (i)
13153 1156 : t = build2 (POINTER_PLUS_EXPR,
13154 578 : TREE_TYPE (message_data), message_data,
13155 578 : size_int (i));
13156 1033 : t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
13157 1033 : tree t2 = cxx_constant_value (t, NULL_TREE, complain);
13158 1033 : if (!tree_fits_shwi_p (t2))
13159 : {
13160 30 : error_at (location,
13161 : "constexpr string %<data()[%d]%> "
13162 : "must be a constant expression", i);
13163 30 : return false;
13164 : }
13165 1003 : if (msg == NULL)
13166 362 : buf[i] = tree_to_shwi (t2);
13167 : /* If c_getstr worked, just verify the first and
13168 : last characters using constant evaluation. */
13169 641 : else if (len > 2 && i == 0)
13170 268 : i = len - 2;
13171 : }
13172 425 : if (msg == NULL)
13173 104 : msg = buf;
13174 : }
13175 77 : else if (!data)
13176 : {
13177 : /* We don't have any function to test whether some
13178 : expression is a core constant expression. So, instead
13179 : test whether (message.data (), 0) is a constant
13180 : expression. */
13181 22 : data = build2 (COMPOUND_EXPR, integer_type_node,
13182 : message_data, integer_zero_node);
13183 22 : tree t = cxx_constant_value (data, NULL_TREE, complain);
13184 22 : if (!integer_zerop (t))
13185 : {
13186 22 : error_at (location,
13187 : "constexpr string %<data()%> "
13188 : "must be a core constant expression");
13189 22 : return false;
13190 : }
13191 : }
13192 : }
13193 : }
13194 : else
13195 : {
13196 2028 : tree eltype = TREE_TYPE (TREE_TYPE (message));
13197 2028 : int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
13198 2028 : msg = TREE_STRING_POINTER (message);
13199 2028 : len = TREE_STRING_LENGTH (message) / sz - 1;
13200 : }
13201 2602 : translate:
13202 2602 : if ((message_sz && message_data) || ctx)
13203 : {
13204 : /* Convert the string from execution charset to SOURCE_CHARSET. */
13205 768 : cpp_string istr, ostr;
13206 768 : istr.len = len;
13207 768 : istr.text = (const unsigned char *) msg;
13208 768 : enum cpp_ttype type = CPP_STRING;
13209 768 : if (message_sz && message_data)
13210 : {
13211 574 : if (POINTER_TYPE_P (TREE_TYPE (message_data))
13212 574 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
13213 574 : == char8_type_node))
13214 : type = CPP_UTF8STRING;
13215 : }
13216 194 : else if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message)))
13217 194 : == char8_type_node)
13218 768 : type = CPP_UTF8STRING;
13219 768 : if (len == 0)
13220 : ;
13221 643 : else if (!cpp_translate_string (parse_in, &istr, &ostr, type,
13222 : true))
13223 : {
13224 0 : if (type == CPP_UTF8STRING)
13225 0 : error_at (location, "could not convert constexpr string from "
13226 : "UTF-8 encoding to source character "
13227 : "set");
13228 : else
13229 0 : error_at (location, "could not convert constexpr string from "
13230 : "ordinary literal encoding to source character "
13231 : "set");
13232 0 : return false;
13233 : }
13234 : else
13235 : {
13236 643 : if (buf)
13237 104 : XDELETEVEC (buf);
13238 643 : msg = buf = const_cast <char *> ((const char *) ostr.text);
13239 643 : len = ostr.len;
13240 : }
13241 : }
13242 :
13243 : return true;
13244 : }
13245 :
13246 : /* Build a STATIC_ASSERT for a static assertion with the condition
13247 : CONDITION and the message text MESSAGE. LOCATION is the location
13248 : of the static assertion in the source code. When MEMBER_P, this
13249 : static assertion is a member of a class. If SHOW_EXPR_P is true,
13250 : print the condition (because it was instantiation-dependent).
13251 : If CONSTEVAL_BLOCK_P is true, this static assertion represents
13252 : a consteval block. */
13253 :
13254 : void
13255 11446174 : finish_static_assert (tree condition, tree message, location_t location,
13256 : bool member_p, bool show_expr_p,
13257 : bool consteval_block_p/*=false*/)
13258 : {
13259 11446174 : tsubst_flags_t complain = tf_warning_or_error;
13260 :
13261 11446174 : if (condition == NULL_TREE
13262 11446174 : || condition == error_mark_node)
13263 4853165 : return;
13264 :
13265 11445948 : if (check_for_bare_parameter_packs (condition))
13266 : return;
13267 :
13268 11445945 : cexpr_str cstr(message);
13269 11445945 : if (!cstr.type_check (location))
13270 : return;
13271 :
13272 : /* Save the condition in case it was a concept check. */
13273 11445851 : tree orig_condition = condition;
13274 :
13275 11445851 : if (instantiation_dependent_expression_p (condition)
13276 11445851 : || instantiation_dependent_expression_p (message))
13277 : {
13278 : /* We're in a template; build a STATIC_ASSERT and put it in
13279 : the right place. */
13280 4852301 : defer:
13281 4852301 : tree assertion = make_node (STATIC_ASSERT);
13282 4852301 : STATIC_ASSERT_CONDITION (assertion) = orig_condition;
13283 4852301 : STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
13284 4852301 : STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
13285 4852301 : CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
13286 :
13287 4852301 : if (member_p)
13288 2482527 : maybe_add_class_template_decl_list (current_class_type,
13289 : assertion,
13290 : /*friend_p=*/0);
13291 : else
13292 2369774 : add_stmt (assertion);
13293 :
13294 : return;
13295 : }
13296 :
13297 : /* Evaluate the consteval { }. This must be done only once. */
13298 6599562 : if (consteval_block_p)
13299 : {
13300 516 : cxx_constant_value (condition);
13301 516 : return;
13302 : }
13303 :
13304 : /* Fold the expression and convert it to a boolean value. */
13305 6599046 : condition = contextual_conv_bool (condition, complain);
13306 6599046 : condition = fold_non_dependent_expr (condition, complain,
13307 : /*manifestly_const_eval=*/true);
13308 :
13309 6599044 : if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
13310 : /* Do nothing; the condition is satisfied. */
13311 : ;
13312 : else
13313 : {
13314 8874 : iloc_sentinel ils (location);
13315 :
13316 8874 : if (integer_zerop (condition))
13317 : {
13318 : /* CWG2518: static_assert failure in a template is not IFNDR. */
13319 8008 : if (processing_template_decl)
13320 6012 : goto defer;
13321 :
13322 1996 : int len;
13323 1996 : const char *msg = NULL;
13324 1996 : if (!cstr.extract (location, msg, len))
13325 25 : return;
13326 :
13327 : /* See if we can find which clause was failing (for logical AND). */
13328 1971 : tree bad = find_failing_clause (NULL, orig_condition);
13329 : /* If not, or its location is unusable, fall back to the previous
13330 : location. */
13331 1971 : location_t cloc = cp_expr_loc_or_loc (bad, location);
13332 :
13333 1971 : auto_diagnostic_group d;
13334 :
13335 : /* Report the error. */
13336 1971 : if (len == 0)
13337 1259 : error_at (cloc, "static assertion failed");
13338 : else
13339 712 : error_at (cloc, "static assertion failed: %.*s", len, msg);
13340 :
13341 1971 : diagnose_failing_condition (bad, cloc, show_expr_p);
13342 :
13343 : /* Suppress -Wreturn-type for functions with failed static_asserts.
13344 : Otherwise templates like:
13345 : if constexpr (whatever)
13346 : return something (args);
13347 : else
13348 : static_assert (false, "explanation");
13349 : get a useless extra -Wreturn-type warning. */
13350 1971 : if (current_function_decl)
13351 756 : suppress_warning (current_function_decl, OPT_Wreturn_type);
13352 1971 : }
13353 866 : else if (condition && condition != error_mark_node)
13354 : {
13355 860 : error ("non-constant condition for static assertion");
13356 860 : if (require_rvalue_constant_expression (condition))
13357 798 : cxx_constant_value (condition);
13358 : }
13359 8874 : }
13360 11445943 : }
13361 :
13362 : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
13363 : suitable for use as a type-specifier.
13364 :
13365 : ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
13366 : id-expression or a class member access, FALSE when it was parsed as
13367 : a full expression. */
13368 :
13369 : tree
13370 44058748 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
13371 : tsubst_flags_t complain)
13372 : {
13373 44058748 : tree type = NULL_TREE;
13374 :
13375 44058748 : if (!expr || error_operand_p (expr))
13376 242108 : return error_mark_node;
13377 :
13378 43816640 : if (TYPE_P (expr)
13379 43816640 : || TREE_CODE (expr) == TYPE_DECL
13380 87633260 : || (TREE_CODE (expr) == BIT_NOT_EXPR
13381 16479 : && TYPE_P (TREE_OPERAND (expr, 0))))
13382 : {
13383 29 : if (complain & tf_error)
13384 29 : error ("argument to %<decltype%> must be an expression");
13385 29 : return error_mark_node;
13386 : }
13387 :
13388 : /* decltype is an unevaluated context. */
13389 43816611 : cp_unevaluated u;
13390 :
13391 43816611 : processing_template_decl_sentinel ptds (/*reset=*/false);
13392 :
13393 : /* Depending on the resolution of DR 1172, we may later need to distinguish
13394 : instantiation-dependent but not type-dependent expressions so that, say,
13395 : A<decltype(sizeof(T))>::U doesn't require 'typename'. */
13396 43816611 : if (instantiation_dependent_uneval_expression_p (expr))
13397 : {
13398 7409661 : dependent:
13399 7410237 : type = cxx_make_type (DECLTYPE_TYPE);
13400 7410237 : DECLTYPE_TYPE_EXPR (type) = expr;
13401 14820474 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
13402 7410237 : = id_expression_or_member_access_p;
13403 7410237 : SET_TYPE_STRUCTURAL_EQUALITY (type);
13404 :
13405 7410237 : return type;
13406 : }
13407 36406950 : else if (processing_template_decl)
13408 : {
13409 7440 : expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
13410 7440 : if (expr == error_mark_node)
13411 : return error_mark_node;
13412 : /* Keep processing_template_decl cleared for the rest of the function
13413 : (for sake of the call to lvalue_kind below, which handles templated
13414 : and non-templated COND_EXPR differently). */
13415 7403 : processing_template_decl = 0;
13416 : }
13417 :
13418 : /* The type denoted by decltype(e) is defined as follows: */
13419 :
13420 36406913 : expr = resolve_nondeduced_context (expr, complain);
13421 36406913 : if (!mark_single_function (expr, complain))
13422 0 : return error_mark_node;
13423 :
13424 36406913 : if (invalid_nonstatic_memfn_p (input_location, expr, complain))
13425 18 : return error_mark_node;
13426 :
13427 36406895 : if (type_unknown_p (expr))
13428 : {
13429 18 : if (complain & tf_error)
13430 6 : error ("%<decltype%> cannot resolve address of overloaded function");
13431 18 : return error_mark_node;
13432 : }
13433 :
13434 36406877 : if (id_expression_or_member_access_p)
13435 : {
13436 : /* If e is an id-expression or a class member access (5.2.5
13437 : [expr.ref]), decltype(e) is defined as the type of the entity
13438 : named by e. If there is no such entity, or e names a set of
13439 : overloaded functions, the program is ill-formed. */
13440 548682 : if (identifier_p (expr))
13441 0 : expr = lookup_name (expr);
13442 :
13443 : /* If e is a constified expression inside a contract assertion,
13444 : strip the const wrapper. Per P2900R14, "For a function f with the
13445 : return type T , the result name is an lvalue of type const T , decltype(r)
13446 : is T , and decltype((r)) is const T&." */
13447 548682 : expr = strip_contract_const_wrapper (expr);
13448 :
13449 373925 : if (REFERENCE_REF_P (expr)
13450 548687 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
13451 : /* This can happen when the expression is, e.g., "a.b". Just
13452 : look at the underlying operand. */
13453 377196 : expr = TREE_OPERAND (expr, 0);
13454 :
13455 548682 : if (TREE_CODE (expr) == OFFSET_REF
13456 548682 : || TREE_CODE (expr) == MEMBER_REF
13457 548682 : || TREE_CODE (expr) == SCOPE_REF)
13458 : /* We're only interested in the field itself. If it is a
13459 : BASELINK, we will need to see through it in the next
13460 : step. */
13461 0 : expr = TREE_OPERAND (expr, 1);
13462 :
13463 548682 : if (BASELINK_P (expr))
13464 : /* See through BASELINK nodes to the underlying function. */
13465 7 : expr = BASELINK_FUNCTIONS (expr);
13466 :
13467 : /* decltype of a decomposition name drops references in the tuple case
13468 : (unlike decltype of a normal variable) and keeps cv-qualifiers from
13469 : the containing object in the other cases (unlike decltype of a member
13470 : access expression). */
13471 548682 : if (DECL_DECOMPOSITION_P (expr))
13472 : {
13473 1449 : if (ptds.saved)
13474 : {
13475 275 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr)
13476 : || (DECL_CONTEXT (expr)
13477 : != current_function_decl));
13478 : /* DECL_HAS_VALUE_EXPR_P is always set if
13479 : processing_template_decl at least for structured bindings
13480 : within the template. If lookup_decomp_type
13481 : returns non-NULL, it is the tuple case. */
13482 275 : if (tree ret = lookup_decomp_type (expr))
13483 : return ret;
13484 191 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
13485 : }
13486 1365 : if (DECL_HAS_VALUE_EXPR_P (expr))
13487 : /* Expr is an array or struct subobject proxy, handle
13488 : bit-fields properly. */
13489 1021 : return unlowered_expr_type (expr);
13490 : else
13491 : /* Expr is a reference variable for the tuple case. */
13492 344 : return lookup_decomp_type (expr);
13493 : }
13494 :
13495 547233 : switch (TREE_CODE (expr))
13496 : {
13497 650 : case FIELD_DECL:
13498 650 : if (DECL_BIT_FIELD_TYPE (expr))
13499 : {
13500 : type = DECL_BIT_FIELD_TYPE (expr);
13501 : break;
13502 : }
13503 : /* Fall through for fields that aren't bitfields. */
13504 147499 : gcc_fallthrough ();
13505 :
13506 147499 : case VAR_DECL:
13507 147499 : if (is_capture_proxy (expr))
13508 : {
13509 99 : if (is_normal_capture_proxy (expr))
13510 : {
13511 21 : expr = DECL_CAPTURED_VARIABLE (expr);
13512 21 : type = TREE_TYPE (expr);
13513 : }
13514 : else
13515 : {
13516 78 : expr = DECL_VALUE_EXPR (expr);
13517 78 : gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
13518 78 : expr = TREE_OPERAND (expr, 1);
13519 78 : type = TREE_TYPE (expr);
13520 : }
13521 : break;
13522 : }
13523 : /* Fall through for variables that aren't capture proxies. */
13524 536183 : gcc_fallthrough ();
13525 :
13526 536183 : case FUNCTION_DECL:
13527 536183 : case CONST_DECL:
13528 536183 : case PARM_DECL:
13529 536183 : case RESULT_DECL:
13530 536183 : case TEMPLATE_PARM_INDEX:
13531 536183 : expr = mark_type_use (expr);
13532 536183 : type = TREE_TYPE (expr);
13533 536183 : if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
13534 : {
13535 : /* decltype of an NTTP object is the type of the template
13536 : parameter, which is the object type modulo cv-quals. */
13537 2643 : int quals = cp_type_quals (type);
13538 2643 : gcc_checking_assert (quals & TYPE_QUAL_CONST);
13539 2643 : type = cv_unqualified (type);
13540 : }
13541 : break;
13542 :
13543 0 : case ERROR_MARK:
13544 0 : type = error_mark_node;
13545 0 : break;
13546 :
13547 3506 : case COMPONENT_REF:
13548 3506 : case COMPOUND_EXPR:
13549 3506 : mark_type_use (expr);
13550 3506 : type = is_bitfield_expr_with_lowered_type (expr);
13551 3506 : if (!type)
13552 3469 : type = TREE_TYPE (TREE_OPERAND (expr, 1));
13553 : break;
13554 :
13555 0 : case BIT_FIELD_REF:
13556 0 : gcc_unreachable ();
13557 :
13558 3500 : case INTEGER_CST:
13559 3500 : case PTRMEM_CST:
13560 : /* We can get here when the id-expression refers to an
13561 : enumerator or non-type template parameter. */
13562 3500 : type = TREE_TYPE (expr);
13563 3500 : break;
13564 :
13565 3945 : default:
13566 : /* Handle instantiated template non-type arguments. */
13567 3945 : type = TREE_TYPE (expr);
13568 3945 : break;
13569 : }
13570 : }
13571 : else
13572 : {
13573 35858195 : tree decl = STRIP_REFERENCE_REF (expr);
13574 35858195 : tree lam = current_lambda_expr ();
13575 35858195 : if (lam && outer_automatic_var_p (decl))
13576 : {
13577 : /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
13578 : unevaluated operand within S would refer to an entity captured by
13579 : copy in some intervening lambda-expression, then let E be the
13580 : innermost such lambda-expression.
13581 :
13582 : If there is such a lambda-expression and if P is in E's function
13583 : parameter scope but not its parameter-declaration-clause, then the
13584 : type of the expression is the type of a class member access
13585 : expression naming the non-static data member that would be declared
13586 : for such a capture in the object parameter of the function call
13587 : operator of E." */
13588 : /* FIXME: This transformation needs to happen for all uses of an outer
13589 : local variable inside decltype, not just decltype((x)) (PR83167).
13590 : And we don't handle nested lambdas properly, where we need to
13591 : consider the outer lambdas as well (PR112926). */
13592 1379 : tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
13593 : LOOK_want::HIDDEN_LAMBDA);
13594 :
13595 1379 : if (cap && is_capture_proxy (cap))
13596 467 : type = TREE_TYPE (cap);
13597 912 : else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
13598 : {
13599 738 : type = TREE_TYPE (decl);
13600 738 : if (TYPE_REF_P (type)
13601 738 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
13602 36 : type = TREE_TYPE (type);
13603 : }
13604 :
13605 1205 : if (type && !TYPE_REF_P (type))
13606 : {
13607 1121 : int quals;
13608 1121 : if (current_function_decl
13609 2104 : && LAMBDA_FUNCTION_P (current_function_decl)
13610 2104 : && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
13611 : {
13612 900 : tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
13613 900 : if (WILDCARD_TYPE_P (non_reference (obtype)))
13614 : /* We don't know what the eventual obtype quals will be. */
13615 576 : goto dependent;
13616 648 : auto direct_type = [](tree t){
13617 324 : if (INDIRECT_TYPE_P (t))
13618 162 : return TREE_TYPE (t);
13619 : return t;
13620 : };
13621 648 : quals = (cp_type_quals (type)
13622 324 : | cp_type_quals (direct_type (obtype)));
13623 : }
13624 : else
13625 : /* We are in the parameter clause, trailing return type, or
13626 : the requires clause and have no relevant c_f_decl yet. */
13627 349 : quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
13628 221 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
13629 545 : type = cp_build_qualified_type (type, quals);
13630 545 : type = build_reference_type (type);
13631 : }
13632 : }
13633 35856816 : else if (error_operand_p (expr))
13634 0 : type = error_mark_node;
13635 35856816 : else if (expr == current_class_ptr)
13636 : /* If the expression is just "this", we want the
13637 : cv-unqualified pointer for the "this" type. */
13638 0 : type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
13639 :
13640 545 : if (!type)
13641 : {
13642 : /* Otherwise, where T is the type of e, if e is an lvalue,
13643 : decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
13644 35856990 : cp_lvalue_kind clk = lvalue_kind (expr);
13645 35856990 : type = unlowered_expr_type (expr);
13646 35856990 : gcc_assert (!TYPE_REF_P (type));
13647 :
13648 : /* For vector types, pick a non-opaque variant. */
13649 35856990 : if (VECTOR_TYPE_P (type))
13650 4421 : type = strip_typedefs (type);
13651 :
13652 35856990 : if (clk != clk_none && !(clk & clk_class))
13653 9127886 : type = cp_build_reference_type (type, (clk & clk_rvalueref));
13654 : }
13655 : }
13656 :
13657 : return type;
13658 43816611 : }
13659 :
13660 : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
13661 : __has_nothrow_copy, depending on assign_p. Returns true iff all
13662 : the copy {ctor,assign} fns are nothrow. */
13663 :
13664 : static bool
13665 279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
13666 : {
13667 279 : tree fns = NULL_TREE;
13668 :
13669 279 : if (assign_p || TYPE_HAS_COPY_CTOR (type))
13670 276 : fns = get_class_binding (type, assign_p ? assign_op_identifier
13671 : : ctor_identifier);
13672 :
13673 279 : bool saw_copy = false;
13674 696 : for (ovl_iterator iter (fns); iter; ++iter)
13675 : {
13676 441 : tree fn = *iter;
13677 :
13678 441 : if (copy_fn_p (fn) > 0)
13679 : {
13680 423 : saw_copy = true;
13681 423 : if (!maybe_instantiate_noexcept (fn)
13682 423 : || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
13683 192 : return false;
13684 : }
13685 : }
13686 :
13687 87 : return saw_copy;
13688 : }
13689 :
13690 : /* Return true if BASE is a pointer-interconvertible base of DERIVED. */
13691 :
13692 : bool
13693 183 : pointer_interconvertible_base_of_p (tree base, tree derived,
13694 : bool explain/*=false*/)
13695 : {
13696 183 : if (base == error_mark_node || derived == error_mark_node)
13697 : return false;
13698 :
13699 183 : base = TYPE_MAIN_VARIANT (base);
13700 183 : derived = TYPE_MAIN_VARIANT (derived);
13701 183 : if (!NON_UNION_CLASS_TYPE_P (base))
13702 : {
13703 17 : if (explain)
13704 3 : inform (location_of (base),
13705 : "%qT is not a non-union class type", base);
13706 : return false;
13707 : }
13708 166 : if (!NON_UNION_CLASS_TYPE_P (derived))
13709 : {
13710 8 : if (explain)
13711 3 : inform (location_of (derived),
13712 : "%qT is not a non-union class type", derived);
13713 : return false;
13714 : }
13715 :
13716 158 : if (same_type_p (base, derived))
13717 : return true;
13718 :
13719 117 : if (!std_layout_type_p (derived))
13720 : {
13721 18 : if (explain)
13722 6 : inform (location_of (derived),
13723 : "%qT is not a standard-layout type", derived);
13724 : return false;
13725 : }
13726 :
13727 99 : if (!uniquely_derived_from_p (base, derived))
13728 : {
13729 18 : if (explain)
13730 : {
13731 : /* An ambiguous base should already be impossible due to
13732 : the std_layout_type_p check. */
13733 3 : gcc_checking_assert (!DERIVED_FROM_P (base, derived));
13734 3 : inform (location_of (derived),
13735 : "%qT is not a base of %qT", base, derived);
13736 : }
13737 : return false;
13738 : }
13739 :
13740 : return true;
13741 : }
13742 :
13743 : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
13744 : return true if MEMBERTYPE is the type of the first non-static data member
13745 : of TYPE or for unions of any members. */
13746 : static bool
13747 637 : first_nonstatic_data_member_p (tree type, tree membertype)
13748 : {
13749 1297 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
13750 : {
13751 1222 : if (TREE_CODE (field) != FIELD_DECL)
13752 135 : continue;
13753 1087 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
13754 60 : continue;
13755 1027 : if (DECL_FIELD_IS_BASE (field))
13756 45 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
13757 982 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13758 : {
13759 216 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
13760 138 : || std_layout_type_p (TREE_TYPE (field)))
13761 294 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
13762 : return true;
13763 : }
13764 766 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13765 : membertype))
13766 : return true;
13767 537 : if (TREE_CODE (type) != UNION_TYPE)
13768 : return false;
13769 : }
13770 : return false;
13771 : }
13772 :
13773 : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
13774 :
13775 : tree
13776 536 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
13777 : tree *args)
13778 : {
13779 : /* Unless users call the builtin directly, the following 3 checks should be
13780 : ensured from std::is_pointer_interconvertible_with_class function
13781 : template. */
13782 536 : if (nargs != 1)
13783 : {
13784 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13785 : "needs a single argument");
13786 6 : return boolean_false_node;
13787 : }
13788 530 : tree arg = args[0];
13789 530 : if (error_operand_p (arg))
13790 0 : return boolean_false_node;
13791 530 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
13792 : {
13793 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13794 : "argument is not pointer to member");
13795 6 : return boolean_false_node;
13796 : }
13797 :
13798 524 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
13799 18 : return boolean_false_node;
13800 :
13801 506 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
13802 506 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
13803 506 : if (!complete_type_or_else (basetype, NULL_TREE))
13804 3 : return boolean_false_node;
13805 :
13806 503 : if (TREE_CODE (basetype) != UNION_TYPE
13807 503 : && !std_layout_type_p (basetype))
13808 22 : return boolean_false_node;
13809 :
13810 481 : if (!first_nonstatic_data_member_p (basetype, membertype))
13811 132 : return boolean_false_node;
13812 :
13813 349 : if (TREE_CODE (arg) == PTRMEM_CST)
13814 68 : arg = cplus_expand_constant (arg);
13815 :
13816 349 : if (integer_nonzerop (arg))
13817 10 : return boolean_false_node;
13818 339 : if (integer_zerop (arg))
13819 71 : return boolean_true_node;
13820 :
13821 268 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
13822 : build_zero_cst (TREE_TYPE (arg)));
13823 : }
13824 :
13825 : /* Helper function for is_corresponding_member_aggr. Return true if
13826 : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
13827 : union or structure BASETYPE. */
13828 :
13829 : static bool
13830 90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
13831 : {
13832 222 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
13833 192 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
13834 36 : continue;
13835 156 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13836 : membertype))
13837 : {
13838 48 : if (TREE_CODE (arg) != INTEGER_CST
13839 48 : || tree_int_cst_equal (arg, byte_position (field)))
13840 : return true;
13841 : }
13842 108 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13843 : {
13844 18 : tree narg = arg;
13845 18 : if (TREE_CODE (basetype) != UNION_TYPE
13846 0 : && TREE_CODE (narg) == INTEGER_CST)
13847 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
13848 18 : if (is_corresponding_member_union (TREE_TYPE (field),
13849 : membertype, narg))
13850 : return true;
13851 : }
13852 : return false;
13853 : }
13854 :
13855 : /* Helper function for fold_builtin_is_corresponding_member call.
13856 : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
13857 : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
13858 : boolean_true_node if they are corresponding members, or for
13859 : non-constant ARG2 the highest member offset for corresponding
13860 : members. */
13861 :
13862 : static tree
13863 550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
13864 : tree arg1, tree basetype2, tree membertype2,
13865 : tree arg2)
13866 : {
13867 550 : tree field1 = TYPE_FIELDS (basetype1);
13868 550 : tree field2 = TYPE_FIELDS (basetype2);
13869 550 : tree ret = boolean_false_node;
13870 2376 : while (1)
13871 : {
13872 1463 : bool r = next_common_initial_sequence (field1, field2);
13873 1463 : if (field1 == NULL_TREE || field2 == NULL_TREE)
13874 : break;
13875 1331 : if (r
13876 1038 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
13877 : membertype1)
13878 1841 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
13879 : membertype2))
13880 : {
13881 504 : tree pos = byte_position (field1);
13882 504 : if (TREE_CODE (arg1) == INTEGER_CST
13883 504 : && tree_int_cst_equal (arg1, pos))
13884 : {
13885 92 : if (TREE_CODE (arg2) == INTEGER_CST)
13886 92 : return boolean_true_node;
13887 : return pos;
13888 : }
13889 412 : else if (TREE_CODE (arg1) != INTEGER_CST)
13890 1188 : ret = pos;
13891 : }
13892 1654 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
13893 944 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
13894 : {
13895 117 : if ((!lookup_attribute ("no_unique_address",
13896 117 : DECL_ATTRIBUTES (field1)))
13897 117 : != !lookup_attribute ("no_unique_address",
13898 117 : DECL_ATTRIBUTES (field2)))
13899 : break;
13900 117 : if (!tree_int_cst_equal (bit_position (field1),
13901 117 : bit_position (field2)))
13902 : break;
13903 99 : bool overlap = true;
13904 99 : tree pos = byte_position (field1);
13905 99 : if (TREE_CODE (arg1) == INTEGER_CST)
13906 : {
13907 27 : tree off1 = fold_convert (sizetype, arg1);
13908 27 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
13909 27 : if (tree_int_cst_lt (off1, pos)
13910 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
13911 : overlap = false;
13912 : }
13913 99 : if (TREE_CODE (arg2) == INTEGER_CST)
13914 : {
13915 27 : tree off2 = fold_convert (sizetype, arg2);
13916 27 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
13917 27 : if (tree_int_cst_lt (off2, pos)
13918 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
13919 : overlap = false;
13920 : }
13921 87 : if (overlap
13922 87 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
13923 126 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
13924 : {
13925 39 : tree narg1 = arg1;
13926 39 : if (TREE_CODE (arg1) == INTEGER_CST)
13927 9 : narg1 = size_binop (MINUS_EXPR,
13928 : fold_convert (sizetype, arg1), pos);
13929 39 : tree narg2 = arg2;
13930 39 : if (TREE_CODE (arg2) == INTEGER_CST)
13931 9 : narg2 = size_binop (MINUS_EXPR,
13932 : fold_convert (sizetype, arg2), pos);
13933 39 : tree t1 = TREE_TYPE (field1);
13934 39 : tree t2 = TREE_TYPE (field2);
13935 39 : tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
13936 : narg1, t2, membertype2,
13937 : narg2);
13938 39 : if (nret != boolean_false_node)
13939 : {
13940 39 : if (nret == boolean_true_node)
13941 : return nret;
13942 30 : if (TREE_CODE (arg1) == INTEGER_CST)
13943 0 : return size_binop (PLUS_EXPR, nret, pos);
13944 30 : ret = size_binop (PLUS_EXPR, nret, pos);
13945 : }
13946 : }
13947 60 : else if (overlap
13948 48 : && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
13949 108 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
13950 : {
13951 48 : tree narg1 = arg1;
13952 48 : if (TREE_CODE (arg1) == INTEGER_CST)
13953 6 : narg1 = size_binop (MINUS_EXPR,
13954 : fold_convert (sizetype, arg1), pos);
13955 48 : tree narg2 = arg2;
13956 48 : if (TREE_CODE (arg2) == INTEGER_CST)
13957 6 : narg2 = size_binop (MINUS_EXPR,
13958 : fold_convert (sizetype, arg2), pos);
13959 48 : if (is_corresponding_member_union (TREE_TYPE (field1),
13960 : membertype1, narg1)
13961 48 : && is_corresponding_member_union (TREE_TYPE (field2),
13962 : membertype2, narg2))
13963 : {
13964 24 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
13965 : "not well defined for anonymous unions");
13966 24 : return boolean_false_node;
13967 : }
13968 : }
13969 : }
13970 1188 : if (!r)
13971 : break;
13972 913 : field1 = DECL_CHAIN (field1);
13973 913 : field2 = DECL_CHAIN (field2);
13974 913 : }
13975 : return ret;
13976 : }
13977 :
13978 : /* Fold __builtin_is_corresponding_member call. */
13979 :
13980 : tree
13981 699 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
13982 : tree *args)
13983 : {
13984 : /* Unless users call the builtin directly, the following 3 checks should be
13985 : ensured from std::is_corresponding_member function template. */
13986 699 : if (nargs != 2)
13987 : {
13988 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13989 : "needs two arguments");
13990 9 : return boolean_false_node;
13991 : }
13992 690 : tree arg1 = args[0];
13993 690 : tree arg2 = args[1];
13994 690 : if (error_operand_p (arg1) || error_operand_p (arg2))
13995 0 : return boolean_false_node;
13996 711 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
13997 705 : || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
13998 : {
13999 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
14000 : "argument is not pointer to member");
14001 9 : return boolean_false_node;
14002 : }
14003 :
14004 681 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
14005 681 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
14006 15 : return boolean_false_node;
14007 :
14008 666 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
14009 666 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
14010 666 : if (!complete_type_or_else (basetype1, NULL_TREE))
14011 12 : return boolean_false_node;
14012 :
14013 654 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
14014 654 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
14015 654 : if (!complete_type_or_else (basetype2, NULL_TREE))
14016 12 : return boolean_false_node;
14017 :
14018 627 : if (!NON_UNION_CLASS_TYPE_P (basetype1)
14019 627 : || !NON_UNION_CLASS_TYPE_P (basetype2)
14020 627 : || !std_layout_type_p (basetype1)
14021 1233 : || !std_layout_type_p (basetype2))
14022 51 : return boolean_false_node;
14023 :
14024 : /* If the member types aren't layout compatible, then they
14025 : can't be corresponding members. */
14026 591 : if (!layout_compatible_type_p (membertype1, membertype2))
14027 18 : return boolean_false_node;
14028 :
14029 573 : if (TREE_CODE (arg1) == PTRMEM_CST)
14030 176 : arg1 = cplus_expand_constant (arg1);
14031 573 : if (TREE_CODE (arg2) == PTRMEM_CST)
14032 182 : arg2 = cplus_expand_constant (arg2);
14033 :
14034 573 : if (null_member_pointer_value_p (arg1)
14035 573 : || null_member_pointer_value_p (arg2))
14036 9 : return boolean_false_node;
14037 :
14038 564 : if (TREE_CODE (arg1) == INTEGER_CST
14039 182 : && TREE_CODE (arg2) == INTEGER_CST
14040 746 : && !tree_int_cst_equal (arg1, arg2))
14041 53 : return boolean_false_node;
14042 :
14043 511 : if (TREE_CODE (arg2) == INTEGER_CST
14044 129 : && TREE_CODE (arg1) != INTEGER_CST)
14045 : {
14046 : std::swap (arg1, arg2);
14047 : std::swap (membertype1, membertype2);
14048 : std::swap (basetype1, basetype2);
14049 : }
14050 :
14051 511 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
14052 : basetype2, membertype2, arg2);
14053 511 : if (TREE_TYPE (ret) == boolean_type_node)
14054 : return ret;
14055 : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
14056 : already returns boolean_{true,false}_node whether those particular
14057 : members are corresponding members or not. Otherwise, if only
14058 : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
14059 : above), it returns boolean_false_node if it is certainly not a
14060 : corresponding member and otherwise we need to do a runtime check that
14061 : those two OFFSET_TYPE offsets are equal.
14062 : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
14063 : returns the largest offset at which the members would be corresponding
14064 : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
14065 304 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
14066 304 : if (TREE_CODE (arg1) == INTEGER_CST)
14067 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
14068 : fold_convert (TREE_TYPE (arg1), arg2));
14069 304 : ret = fold_build2 (LE_EXPR, boolean_type_node,
14070 : fold_convert (pointer_sized_int_node, arg1),
14071 : fold_convert (pointer_sized_int_node, ret));
14072 304 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
14073 : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
14074 : fold_convert (TREE_TYPE (arg1), arg2)));
14075 : }
14076 :
14077 : /* Fold __builtin_is_string_literal call. */
14078 :
14079 : tree
14080 4276 : fold_builtin_is_string_literal (location_t loc, int nargs, tree *args)
14081 : {
14082 : /* Unless users call the builtin directly, the following 3 checks should be
14083 : ensured from std::is_string_literal overloads. */
14084 4276 : if (nargs != 1)
14085 : {
14086 0 : error_at (loc, "%<__builtin_is_string_literal%> needs a single "
14087 : "argument");
14088 0 : return boolean_false_node;
14089 : }
14090 4276 : tree arg = args[0];
14091 4276 : if (error_operand_p (arg))
14092 0 : return boolean_false_node;
14093 4276 : if (!TYPE_PTR_P (TREE_TYPE (arg))
14094 4276 : || !TYPE_READONLY (TREE_TYPE (TREE_TYPE (arg)))
14095 8552 : || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (arg))))
14096 : {
14097 0 : arg_invalid:
14098 0 : error_at (loc, "%<__builtin_is_string_literal%> "
14099 : "argument is not %<const char*%>, %<const wchar_t*%>, "
14100 : "%<const char8_t*%>, %<const char16_t*%> or "
14101 : "%<const char32_t*%>");
14102 0 : return boolean_false_node;
14103 : }
14104 4276 : tree chart = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg)));
14105 4276 : if (chart != char_type_node
14106 3416 : && chart != wchar_type_node
14107 2562 : && chart != char8_type_node
14108 1708 : && chart != char16_type_node
14109 854 : && chart != char32_type_node)
14110 0 : goto arg_invalid;
14111 :
14112 4276 : STRIP_NOPS (arg);
14113 8564 : while (TREE_CODE (arg) == POINTER_PLUS_EXPR)
14114 : {
14115 12 : arg = TREE_OPERAND (arg, 0);
14116 12 : STRIP_NOPS (arg);
14117 : }
14118 4276 : if (TREE_CODE (arg) != ADDR_EXPR)
14119 4220 : return boolean_false_node;
14120 56 : arg = TREE_OPERAND (arg, 0);
14121 56 : if (TREE_CODE (arg) == ARRAY_REF)
14122 24 : arg = TREE_OPERAND (arg, 0);
14123 56 : if (TREE_CODE (arg) != STRING_CST)
14124 16 : return boolean_false_node;
14125 40 : return boolean_true_node;
14126 : }
14127 :
14128 : /* [basic.types] 8. True iff TYPE is an object type. */
14129 :
14130 : static bool
14131 2964247 : object_type_p (const_tree type)
14132 : {
14133 2964247 : return (TREE_CODE (type) != FUNCTION_TYPE
14134 0 : && !TYPE_REF_P (type)
14135 2964247 : && !VOID_TYPE_P (type));
14136 : }
14137 :
14138 : /* [defns.referenceable] True iff TYPE is a referenceable type. */
14139 :
14140 : static bool
14141 3619609 : referenceable_type_p (const_tree type)
14142 : {
14143 3619609 : return (TYPE_REF_P (type)
14144 3620065 : || object_type_p (type)
14145 3620065 : || (FUNC_OR_METHOD_TYPE_P (type)
14146 385 : && type_memfn_quals (type) == TYPE_UNQUALIFIED
14147 319 : && type_memfn_rqual (type) == REF_QUAL_NONE));
14148 : }
14149 :
14150 : /* Actually evaluates the trait. */
14151 :
14152 : static bool
14153 18344438 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
14154 : {
14155 18344438 : enum tree_code type_code1;
14156 18344438 : tree t;
14157 :
14158 18344438 : type_code1 = TREE_CODE (type1);
14159 :
14160 18344438 : switch (kind)
14161 : {
14162 317 : case CPTK_HAS_NOTHROW_ASSIGN:
14163 317 : type1 = strip_array_types (type1);
14164 601 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
14165 601 : && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
14166 173 : || (CLASS_TYPE_P (type1)
14167 129 : && classtype_has_nothrow_assign_or_copy_p (type1,
14168 : true))));
14169 :
14170 215 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
14171 215 : type1 = strip_array_types (type1);
14172 215 : return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
14173 215 : || (CLASS_TYPE_P (type1)
14174 93 : && (t = locate_ctor (type1))
14175 60 : && maybe_instantiate_noexcept (t)
14176 58 : && TYPE_NOTHROW_P (TREE_TYPE (t))));
14177 :
14178 305 : case CPTK_HAS_NOTHROW_COPY:
14179 305 : type1 = strip_array_types (type1);
14180 305 : return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
14181 305 : || (CLASS_TYPE_P (type1)
14182 150 : && classtype_has_nothrow_assign_or_copy_p (type1, false)));
14183 :
14184 517 : case CPTK_HAS_TRIVIAL_ASSIGN:
14185 : /* ??? The standard seems to be missing the "or array of such a class
14186 : type" wording for this trait. */
14187 517 : type1 = strip_array_types (type1);
14188 1016 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
14189 1001 : && (trivial_type_p (type1)
14190 307 : || (CLASS_TYPE_P (type1)
14191 222 : && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
14192 :
14193 545 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14194 545 : type1 = strip_array_types (type1);
14195 545 : return (trivial_type_p (type1)
14196 545 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
14197 :
14198 526 : case CPTK_HAS_TRIVIAL_COPY:
14199 : /* ??? The standard seems to be missing the "or array of such a class
14200 : type" wording for this trait. */
14201 526 : type1 = strip_array_types (type1);
14202 878 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14203 863 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
14204 :
14205 781 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14206 781 : type1 = strip_array_types (type1);
14207 781 : if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
14208 : {
14209 123 : deferring_access_check_sentinel dacs (dk_no_check);
14210 123 : cp_unevaluated un;
14211 123 : tree fn = get_dtor (type1, tf_none);
14212 123 : if (!fn && !seen_error ())
14213 3 : warning (0, "checking %qs for type %qT with a destructor that "
14214 : "cannot be called", "__has_trivial_destructor", type1);
14215 123 : }
14216 1121 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14217 1118 : || (CLASS_TYPE_P (type1)
14218 293 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
14219 :
14220 61547 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14221 61547 : return type_has_unique_obj_representations (type1);
14222 :
14223 311 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14224 311 : return type_has_virtual_destructor (type1);
14225 :
14226 56790 : case CPTK_IS_ABSTRACT:
14227 56790 : return ABSTRACT_CLASS_TYPE_P (type1);
14228 :
14229 1021 : case CPTK_IS_AGGREGATE:
14230 1021 : return CP_AGGREGATE_TYPE_P (type1);
14231 :
14232 376450 : case CPTK_IS_ARRAY:
14233 376450 : return (type_code1 == ARRAY_TYPE
14234 : /* We don't want to report T[0] as being an array type.
14235 : This is for compatibility with an implementation of
14236 : std::is_array by template argument deduction, because
14237 : compute_array_index_type_loc rejects a zero-size array
14238 : in SFINAE context. */
14239 376450 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14240 :
14241 1038753 : case CPTK_IS_ASSIGNABLE:
14242 1038753 : return is_xible (MODIFY_EXPR, type1, type2);
14243 :
14244 524992 : case CPTK_IS_BASE_OF:
14245 524901 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14246 1030996 : && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
14247 477438 : || DERIVED_FROM_P (type1, type2)));
14248 :
14249 58555 : case CPTK_IS_BOUNDED_ARRAY:
14250 58555 : return (type_code1 == ARRAY_TYPE
14251 1668 : && TYPE_DOMAIN (type1)
14252 : /* We don't want to report T[0] as being a bounded array type.
14253 : This is for compatibility with an implementation of
14254 : std::is_bounded_array by template argument deduction, because
14255 : compute_array_index_type_loc rejects a zero-size array
14256 : in SFINAE context. */
14257 60095 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14258 :
14259 546745 : case CPTK_IS_CLASS:
14260 546745 : return NON_UNION_CLASS_TYPE_P (type1);
14261 :
14262 600689 : case CPTK_IS_CONST:
14263 600689 : return CP_TYPE_CONST_P (type1);
14264 :
14265 2425178 : case CPTK_IS_CONSTRUCTIBLE:
14266 2425178 : return is_xible (INIT_EXPR, type1, type2);
14267 :
14268 3220484 : case CPTK_IS_CONVERTIBLE:
14269 3220484 : return is_convertible (type1, type2);
14270 :
14271 3342 : case CPTK_IS_DESTRUCTIBLE:
14272 3342 : return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14273 :
14274 223202 : case CPTK_IS_EMPTY:
14275 223202 : return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
14276 :
14277 682369 : case CPTK_IS_ENUM:
14278 682369 : return type_code1 == ENUMERAL_TYPE;
14279 :
14280 439926 : case CPTK_IS_FINAL:
14281 439926 : return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
14282 :
14283 48462 : case CPTK_IS_FUNCTION:
14284 48462 : return type_code1 == FUNCTION_TYPE;
14285 :
14286 1397 : case CPTK_IS_IMPLICIT_LIFETIME:
14287 1397 : return implicit_lifetime_type_p (type1);
14288 :
14289 49356 : case CPTK_IS_INVOCABLE:
14290 49356 : return !error_operand_p (build_invoke (type1, type2, tf_none));
14291 :
14292 221 : case CPTK_IS_LAYOUT_COMPATIBLE:
14293 221 : return layout_compatible_type_p (type1, type2);
14294 :
14295 197 : case CPTK_IS_LITERAL_TYPE:
14296 197 : return literal_type_p (type1);
14297 :
14298 49096 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14299 49096 : return TYPE_PTRMEMFUNC_P (type1);
14300 :
14301 49083 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14302 49083 : return TYPE_PTRDATAMEM_P (type1);
14303 :
14304 11081 : case CPTK_IS_MEMBER_POINTER:
14305 11081 : return TYPE_PTRMEM_P (type1);
14306 :
14307 468171 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14308 468171 : return is_nothrow_xible (MODIFY_EXPR, type1, type2);
14309 :
14310 942813 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14311 942813 : return is_nothrow_xible (INIT_EXPR, type1, type2);
14312 :
14313 683 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14314 683 : return is_nothrow_convertible (type1, type2);
14315 :
14316 24416 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14317 24416 : return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14318 :
14319 44252 : case CPTK_IS_NOTHROW_INVOCABLE:
14320 44252 : return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
14321 :
14322 1147233 : case CPTK_IS_OBJECT:
14323 1147233 : return object_type_p (type1);
14324 :
14325 168 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14326 168 : return pointer_interconvertible_base_of_p (type1, type2);
14327 :
14328 11603 : case CPTK_IS_POD:
14329 11603 : return pod_type_p (type1);
14330 :
14331 153481 : case CPTK_IS_POINTER:
14332 153481 : return TYPE_PTR_P (type1);
14333 :
14334 289 : case CPTK_IS_POLYMORPHIC:
14335 289 : return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
14336 :
14337 730548 : case CPTK_IS_REFERENCE:
14338 730548 : return type_code1 == REFERENCE_TYPE;
14339 :
14340 2704927 : case CPTK_IS_SAME:
14341 2704927 : return same_type_p (type1, type2);
14342 :
14343 373 : case CPTK_IS_SCOPED_ENUM:
14344 373 : return SCOPED_ENUM_P (type1);
14345 :
14346 64605 : case CPTK_IS_STD_LAYOUT:
14347 64605 : return std_layout_type_p (type1);
14348 :
14349 59770 : case CPTK_IS_TRIVIAL:
14350 59770 : return trivial_type_p (type1);
14351 :
14352 12926 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14353 12926 : return is_trivially_xible (MODIFY_EXPR, type1, type2);
14354 :
14355 76781 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14356 76781 : return is_trivially_xible (INIT_EXPR, type1, type2);
14357 :
14358 120729 : case CPTK_IS_TRIVIALLY_COPYABLE:
14359 120729 : return trivially_copyable_p (type1);
14360 :
14361 27577 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14362 27577 : return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14363 :
14364 100024 : case CPTK_IS_UNBOUNDED_ARRAY:
14365 100024 : return array_of_unknown_bound_p (type1);
14366 :
14367 277334 : case CPTK_IS_UNION:
14368 277334 : return type_code1 == UNION_TYPE;
14369 :
14370 751 : case CPTK_IS_VIRTUAL_BASE_OF:
14371 683 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14372 1415 : && lookup_base (type2, type1, ba_require_virtual,
14373 : NULL, tf_none) != NULL_TREE);
14374 :
14375 625113 : case CPTK_IS_VOLATILE:
14376 625113 : return CP_TYPE_VOLATILE_P (type1);
14377 :
14378 222479 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14379 222479 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
14380 :
14381 54590 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14382 54590 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
14383 :
14384 85 : case CPTK_IS_DEDUCIBLE:
14385 85 : return type_targs_deducible_from (type1, type2);
14386 :
14387 264 : case CPTK_IS_STRUCTURAL:
14388 264 : return structural_type_p (type1);
14389 :
14390 : /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
14391 : are handled in finish_trait_expr. */
14392 0 : case CPTK_RANK:
14393 0 : case CPTK_TYPE_ORDER:
14394 0 : case CPTK_STRUCTURED_BINDING_SIZE:
14395 0 : gcc_unreachable ();
14396 :
14397 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14398 : case CPTK_##CODE:
14399 : #include "cp-trait.def"
14400 : #undef DEFTRAIT_TYPE
14401 : /* Type-yielding traits are handled in finish_trait_type. */
14402 : break;
14403 : }
14404 :
14405 0 : gcc_unreachable ();
14406 : }
14407 :
14408 : /* Returns true if TYPE meets the requirements for the specified KIND,
14409 : false otherwise.
14410 :
14411 : When KIND == 1, TYPE must be an array of unknown bound,
14412 : or (possibly cv-qualified) void, or a complete type.
14413 :
14414 : When KIND == 2, TYPE must be a complete type, or array of complete type,
14415 : or (possibly cv-qualified) void.
14416 :
14417 : When KIND == 3:
14418 : If TYPE is a non-union class type, it must be complete.
14419 :
14420 : When KIND == 4:
14421 : If TYPE is a class type, it must be complete.
14422 :
14423 : If COMPLAIN is not tf_none, we permerror and return false if that doesn't
14424 : produce a hard error. */
14425 :
14426 : static bool
14427 19263341 : check_trait_type (tree type, int kind, tsubst_flags_t complain)
14428 : {
14429 19263341 : if (type == NULL_TREE)
14430 : return true;
14431 :
14432 19263341 : if (TREE_CODE (type) == TREE_VEC)
14433 : {
14434 6288735 : for (tree arg : tree_vec_range (type))
14435 2755068 : if (!check_trait_type (arg, kind, complain))
14436 123 : return false;
14437 3533667 : return true;
14438 : }
14439 :
14440 15729551 : if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
14441 : return true; // Array of unknown bound. Don't care about completeness.
14442 :
14443 15728693 : if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
14444 : return true; // Not a non-union class type. Don't care about completeness.
14445 :
14446 15612830 : if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
14447 : return true; // Not a class type. Don't care about completeness.
14448 :
14449 15611999 : if (VOID_TYPE_P (type))
14450 : return true;
14451 :
14452 15610358 : type = complete_type (strip_array_types (type));
14453 15610358 : if (!COMPLETE_TYPE_P (type)
14454 : /* If we're not emitting error messages, always return false for
14455 : incomplete types. */
14456 15610358 : && (complain == tf_none
14457 181 : || (cxx_incomplete_type_diagnostic (NULL_TREE, type,
14458 : diagnostics::kind::permerror)
14459 181 : && !flag_permissive)))
14460 886 : return false;
14461 : return true;
14462 : }
14463 :
14464 : /* True iff the conversion (if any) would be a direct reference
14465 : binding, not requiring complete types. This is LWG2939. */
14466 :
14467 : static bool
14468 6760065 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
14469 : {
14470 6760065 : tree from, to;
14471 6760065 : switch (kind)
14472 : {
14473 : /* These put the target type first. */
14474 : case CPTK_IS_CONSTRUCTIBLE:
14475 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14476 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14477 : case CPTK_IS_INVOCABLE:
14478 : case CPTK_IS_NOTHROW_INVOCABLE:
14479 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14480 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14481 : to = type1;
14482 : from = type2;
14483 : break;
14484 :
14485 : /* These put it second. */
14486 3221239 : case CPTK_IS_CONVERTIBLE:
14487 3221239 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14488 3221239 : to = type2;
14489 3221239 : from = type1;
14490 3221239 : break;
14491 :
14492 0 : default:
14493 0 : gcc_unreachable ();
14494 : }
14495 :
14496 6760065 : if (TREE_CODE (to) != REFERENCE_TYPE || !from)
14497 : return false;
14498 922025 : if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
14499 63013 : from = TREE_VEC_ELT (from, 0);
14500 922025 : return (TYPE_P (from)
14501 1833836 : && (same_type_ignoring_top_level_qualifiers_p
14502 911811 : (non_reference (to), non_reference (from))));
14503 : }
14504 :
14505 : /* Helper for finish_trait_expr and tsubst_expr. Handle
14506 : CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
14507 : way. */
14508 :
14509 : tree
14510 273 : finish_structured_binding_size (location_t loc, tree type,
14511 : tsubst_flags_t complain)
14512 : {
14513 273 : if (TYPE_REF_P (type))
14514 : {
14515 105 : if (complain & tf_error)
14516 99 : error_at (loc, "%qs argument %qT is a reference",
14517 : "__builtin_structured_binding_size", type);
14518 105 : return error_mark_node;
14519 : }
14520 168 : HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
14521 168 : if (ret == -1)
14522 63 : return error_mark_node;
14523 105 : return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
14524 : }
14525 :
14526 : /* Process a trait expression. */
14527 :
14528 : tree
14529 21840926 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2,
14530 : tsubst_flags_t complain/*=tf_warning_or_error*/)
14531 : {
14532 21840926 : if (type1 == error_mark_node
14533 21840923 : || type2 == error_mark_node)
14534 : return error_mark_node;
14535 :
14536 21840923 : if (processing_template_decl)
14537 : {
14538 3495682 : tree trait_expr = make_node (TRAIT_EXPR);
14539 3495682 : if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
14540 32295 : TREE_TYPE (trait_expr) = size_type_node;
14541 3463387 : else if (kind == CPTK_TYPE_ORDER)
14542 : {
14543 4556 : tree val = type_order_value (type1, type1);
14544 4556 : if (val != error_mark_node)
14545 4556 : TREE_TYPE (trait_expr) = TREE_TYPE (val);
14546 : }
14547 : else
14548 3458831 : TREE_TYPE (trait_expr) = boolean_type_node;
14549 3495682 : TRAIT_EXPR_TYPE1 (trait_expr) = type1;
14550 3495682 : TRAIT_EXPR_TYPE2 (trait_expr) = type2;
14551 3495682 : TRAIT_EXPR_KIND (trait_expr) = kind;
14552 3495682 : TRAIT_EXPR_LOCATION (trait_expr) = loc;
14553 3495682 : return trait_expr;
14554 : }
14555 :
14556 18345241 : switch (kind)
14557 : {
14558 57794 : case CPTK_HAS_NOTHROW_ASSIGN:
14559 57794 : case CPTK_HAS_TRIVIAL_ASSIGN:
14560 57794 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
14561 57794 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14562 57794 : case CPTK_HAS_NOTHROW_COPY:
14563 57794 : case CPTK_HAS_TRIVIAL_COPY:
14564 57794 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14565 57794 : case CPTK_IS_DESTRUCTIBLE:
14566 57794 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14567 57794 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14568 57794 : if (!check_trait_type (type1, /*kind=*/1, complain))
14569 57 : return error_mark_node;
14570 : break;
14571 :
14572 318848 : case CPTK_IS_LITERAL_TYPE:
14573 318848 : case CPTK_IS_POD:
14574 318848 : case CPTK_IS_STD_LAYOUT:
14575 318848 : case CPTK_IS_TRIVIAL:
14576 318848 : case CPTK_IS_TRIVIALLY_COPYABLE:
14577 318848 : case CPTK_IS_STRUCTURAL:
14578 318848 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14579 318848 : if (!check_trait_type (type1, /* kind = */ 2, complain))
14580 133 : return error_mark_node;
14581 : break;
14582 :
14583 280631 : case CPTK_IS_ABSTRACT:
14584 280631 : case CPTK_IS_EMPTY:
14585 280631 : case CPTK_IS_POLYMORPHIC:
14586 280631 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14587 280631 : if (!check_trait_type (type1, /* kind = */ 3, complain))
14588 39 : return error_mark_node;
14589 : break;
14590 :
14591 : /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
14592 : type to know whether an array is an aggregate, so use kind=4 here. */
14593 442399 : case CPTK_IS_AGGREGATE:
14594 442399 : case CPTK_IS_FINAL:
14595 442399 : case CPTK_IS_IMPLICIT_LIFETIME:
14596 442399 : if (!check_trait_type (type1, /* kind = */ 4, complain))
14597 55 : return error_mark_node;
14598 : break;
14599 :
14600 6760065 : case CPTK_IS_CONSTRUCTIBLE:
14601 6760065 : case CPTK_IS_CONVERTIBLE:
14602 6760065 : case CPTK_IS_INVOCABLE:
14603 6760065 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14604 6760065 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14605 6760065 : case CPTK_IS_NOTHROW_INVOCABLE:
14606 6760065 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14607 6760065 : /* Don't check completeness for direct reference binding. */;
14608 6760065 : if (same_type_ref_bind_p (kind, type1, type2))
14609 : break;
14610 7704495 : gcc_fallthrough ();
14611 :
14612 7704495 : case CPTK_IS_ASSIGNABLE:
14613 7704495 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14614 7704495 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14615 7704495 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14616 7704495 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14617 7704495 : if (!check_trait_type (type1, /*kind=*/1, complain)
14618 7704495 : || !check_trait_type (type2, /*kind=*/1, complain))
14619 602 : return error_mark_node;
14620 : break;
14621 :
14622 525187 : case CPTK_IS_BASE_OF:
14623 525187 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14624 525082 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14625 506180 : && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
14626 1002760 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
14627 : /* We already issued an error. */
14628 27 : return error_mark_node;
14629 : break;
14630 :
14631 778 : case CPTK_IS_VIRTUAL_BASE_OF:
14632 710 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14633 1469 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
14634 : /* We already issued an error. */
14635 27 : return error_mark_node;
14636 : break;
14637 :
14638 : case CPTK_IS_ARRAY:
14639 : case CPTK_IS_BOUNDED_ARRAY:
14640 : case CPTK_IS_CLASS:
14641 : case CPTK_IS_CONST:
14642 : case CPTK_IS_ENUM:
14643 : case CPTK_IS_FUNCTION:
14644 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14645 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14646 : case CPTK_IS_MEMBER_POINTER:
14647 : case CPTK_IS_OBJECT:
14648 : case CPTK_IS_POINTER:
14649 : case CPTK_IS_REFERENCE:
14650 : case CPTK_IS_SAME:
14651 : case CPTK_IS_SCOPED_ENUM:
14652 : case CPTK_IS_UNBOUNDED_ARRAY:
14653 : case CPTK_IS_UNION:
14654 : case CPTK_IS_VOLATILE:
14655 : break;
14656 :
14657 : case CPTK_RANK:
14658 : {
14659 : size_t rank = 0;
14660 122 : for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
14661 80 : ++rank;
14662 42 : return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
14663 : loc);
14664 : }
14665 :
14666 460 : case CPTK_TYPE_ORDER:
14667 460 : return maybe_wrap_with_location (type_order_value (type1, type2), loc);
14668 :
14669 144 : case CPTK_STRUCTURED_BINDING_SIZE:
14670 144 : return finish_structured_binding_size (loc, type1, complain);
14671 :
14672 242 : case CPTK_IS_LAYOUT_COMPATIBLE:
14673 242 : if (!array_of_unknown_bound_p (type1)
14674 223 : && TREE_CODE (type1) != VOID_TYPE
14675 456 : && !complete_type_or_maybe_complain (type1, NULL_TREE, complain))
14676 : /* We already issued an error. */
14677 12 : return error_mark_node;
14678 230 : if (!array_of_unknown_bound_p (type2)
14679 203 : && TREE_CODE (type2) != VOID_TYPE
14680 424 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
14681 : /* We already issued an error. */
14682 9 : return error_mark_node;
14683 : break;
14684 :
14685 85 : case CPTK_IS_DEDUCIBLE:
14686 85 : if (!DECL_TYPE_TEMPLATE_P (type1))
14687 : {
14688 0 : error ("%qD is not a class or alias template", type1);
14689 0 : return error_mark_node;
14690 : }
14691 : break;
14692 :
14693 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14694 : case CPTK_##CODE:
14695 : #include "cp-trait.def"
14696 : #undef DEFTRAIT_TYPE
14697 : /* Type-yielding traits are handled in finish_trait_type. */
14698 0 : gcc_unreachable ();
14699 : }
14700 :
14701 18343634 : tree val = (trait_expr_value (kind, type1, type2)
14702 18343634 : ? boolean_true_node : boolean_false_node);
14703 18343634 : return maybe_wrap_with_location (val, loc);
14704 : }
14705 :
14706 : /* Process a trait type. */
14707 :
14708 : tree
14709 8097121 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
14710 : tsubst_flags_t complain)
14711 : {
14712 8098058 : if (type1 == error_mark_node
14713 8098055 : || type2 == error_mark_node)
14714 : return error_mark_node;
14715 :
14716 8098055 : if (processing_template_decl)
14717 : {
14718 237055 : tree type = cxx_make_type (TRAIT_TYPE);
14719 237055 : TRAIT_TYPE_TYPE1 (type) = type1;
14720 237055 : TRAIT_TYPE_TYPE2 (type) = type2;
14721 237055 : TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
14722 : /* These traits are intended to be used in the definition of the ::type
14723 : member of the corresponding standard library type trait and aren't
14724 : mangleable (and thus won't appear directly in template signatures),
14725 : so structural equality should suffice. */
14726 237055 : SET_TYPE_STRUCTURAL_EQUALITY (type);
14727 237055 : return type;
14728 : }
14729 :
14730 7861000 : switch (kind)
14731 : {
14732 1262354 : case CPTK_ADD_LVALUE_REFERENCE:
14733 : /* [meta.trans.ref]. */
14734 1262354 : if (referenceable_type_p (type1))
14735 1262267 : return cp_build_reference_type (type1, /*rval=*/false);
14736 : return type1;
14737 :
14738 655002 : case CPTK_ADD_POINTER:
14739 : /* [meta.trans.ptr]. */
14740 655002 : if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
14741 : {
14742 654970 : if (TYPE_REF_P (type1))
14743 653776 : type1 = TREE_TYPE (type1);
14744 654970 : return build_pointer_type (type1);
14745 : }
14746 : return type1;
14747 :
14748 1702277 : case CPTK_ADD_RVALUE_REFERENCE:
14749 : /* [meta.trans.ref]. */
14750 1702277 : if (referenceable_type_p (type1))
14751 1702219 : return cp_build_reference_type (type1, /*rval=*/true);
14752 : return type1;
14753 :
14754 240160 : case CPTK_DECAY:
14755 240160 : if (TYPE_REF_P (type1))
14756 43525 : type1 = TREE_TYPE (type1);
14757 :
14758 240160 : if (TREE_CODE (type1) == ARRAY_TYPE)
14759 728 : return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
14760 728 : complain);
14761 239432 : else if (TREE_CODE (type1) == FUNCTION_TYPE)
14762 : return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
14763 : else
14764 239223 : return cv_unqualified (type1);
14765 :
14766 223 : case CPTK_REMOVE_ALL_EXTENTS:
14767 223 : return strip_array_types (type1);
14768 :
14769 1012139 : case CPTK_REMOVE_CV:
14770 1012139 : return cv_unqualified (type1);
14771 :
14772 483345 : case CPTK_REMOVE_CVREF:
14773 483345 : if (TYPE_REF_P (type1))
14774 183858 : type1 = TREE_TYPE (type1);
14775 483345 : return cv_unqualified (type1);
14776 :
14777 66918 : case CPTK_REMOVE_EXTENT:
14778 66918 : if (TREE_CODE (type1) == ARRAY_TYPE)
14779 9512 : type1 = TREE_TYPE (type1);
14780 : return type1;
14781 :
14782 45137 : case CPTK_REMOVE_POINTER:
14783 45137 : if (TYPE_PTR_P (type1))
14784 42239 : type1 = TREE_TYPE (type1);
14785 : return type1;
14786 :
14787 2231415 : case CPTK_REMOVE_REFERENCE:
14788 2231415 : if (TYPE_REF_P (type1))
14789 1355129 : type1 = TREE_TYPE (type1);
14790 : return type1;
14791 :
14792 113207 : case CPTK_TYPE_PACK_ELEMENT:
14793 113207 : return finish_type_pack_element (type1, type2, complain);
14794 :
14795 48823 : case CPTK_UNDERLYING_TYPE:
14796 48823 : return finish_underlying_type (type1);
14797 :
14798 : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
14799 : case CPTK_##CODE:
14800 : #include "cp-trait.def"
14801 : #undef DEFTRAIT_EXPR
14802 : /* Expression-yielding traits are handled in finish_trait_expr. */
14803 : case CPTK_BASES:
14804 : case CPTK_DIRECT_BASES:
14805 : /* BASES and DIRECT_BASES are handled in finish_bases. */
14806 : break;
14807 : }
14808 :
14809 0 : gcc_unreachable ();
14810 : }
14811 :
14812 : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
14813 : which is ignored for C++. */
14814 :
14815 : void
14816 0 : set_float_const_decimal64 (void)
14817 : {
14818 0 : }
14819 :
14820 : void
14821 0 : clear_float_const_decimal64 (void)
14822 : {
14823 0 : }
14824 :
14825 : bool
14826 1891056 : float_const_decimal64_p (void)
14827 : {
14828 1891056 : return 0;
14829 : }
14830 :
14831 :
14832 : /* Return true if T designates the implied `this' parameter. */
14833 :
14834 : bool
14835 6693451 : is_this_parameter (tree t)
14836 : {
14837 6693451 : if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
14838 : return false;
14839 3920654 : gcc_assert (TREE_CODE (t) == PARM_DECL
14840 : || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
14841 : || (cp_binding_oracle && VAR_P (t)));
14842 : return true;
14843 : }
14844 :
14845 : /* As above, or a C++23 explicit object parameter. */
14846 :
14847 : bool
14848 456 : is_object_parameter (tree t)
14849 : {
14850 456 : if (is_this_parameter (t))
14851 : return true;
14852 91 : if (TREE_CODE (t) != PARM_DECL)
14853 : return false;
14854 34 : tree ctx = DECL_CONTEXT (t);
14855 34 : return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
14856 62 : && t == DECL_ARGUMENTS (ctx));
14857 : }
14858 :
14859 : /* Insert the deduced return type for an auto function. */
14860 :
14861 : void
14862 1077064 : apply_deduced_return_type (tree fco, tree return_type)
14863 : {
14864 1077064 : tree result;
14865 :
14866 1077064 : if (return_type == error_mark_node)
14867 : return;
14868 :
14869 1077061 : if (DECL_CONV_FN_P (fco))
14870 42 : DECL_NAME (fco) = make_conv_op_name (return_type);
14871 :
14872 1077061 : TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
14873 :
14874 1077061 : maybe_update_postconditions (fco);
14875 :
14876 : /* Apply the type to the result object. */
14877 :
14878 1077061 : result = DECL_RESULT (fco);
14879 1077061 : if (result == NULL_TREE)
14880 : return;
14881 1064548 : if (TREE_TYPE (result) == return_type)
14882 : return;
14883 :
14884 1064545 : if (!processing_template_decl && !VOID_TYPE_P (return_type)
14885 1969909 : && !complete_type_or_else (return_type, NULL_TREE))
14886 : return;
14887 :
14888 : /* We already have a DECL_RESULT from start_preparsed_function.
14889 : Now we need to redo the work it and allocate_struct_function
14890 : did to reflect the new type. */
14891 1064545 : result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
14892 1064545 : TYPE_MAIN_VARIANT (return_type));
14893 1064545 : DECL_ARTIFICIAL (result) = 1;
14894 1064545 : DECL_IGNORED_P (result) = 1;
14895 1064545 : cp_apply_type_quals_to_decl (cp_type_quals (return_type),
14896 : result);
14897 1064545 : DECL_RESULT (fco) = result;
14898 :
14899 1064545 : if (!uses_template_parms (fco))
14900 1064545 : if (function *fun = DECL_STRUCT_FUNCTION (fco))
14901 : {
14902 1063550 : bool aggr = aggregate_value_p (result, fco);
14903 : #ifdef PCC_STATIC_STRUCT_RETURN
14904 : fun->returns_pcc_struct = aggr;
14905 : #endif
14906 1063550 : fun->returns_struct = aggr;
14907 : }
14908 : }
14909 :
14910 : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
14911 : this is a right unary fold. Otherwise it is a left unary fold. */
14912 :
14913 : static tree
14914 852751 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
14915 : {
14916 : /* Build a pack expansion (assuming expr has pack type). */
14917 852751 : if (!uses_parameter_packs (expr))
14918 : {
14919 3 : error_at (location_of (expr), "operand of fold expression has no "
14920 : "unexpanded parameter packs");
14921 3 : return error_mark_node;
14922 : }
14923 852748 : tree pack = make_pack_expansion (expr);
14924 :
14925 : /* Build the fold expression. */
14926 852748 : tree code = build_int_cstu (integer_type_node, abs (op));
14927 852748 : tree fold = build_min_nt_loc (loc, dir, code, pack);
14928 852748 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14929 852748 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14930 852748 : FOLD_EXPR_OP (fold),
14931 852748 : FOLD_EXPR_MODIFY_P (fold));
14932 852748 : return fold;
14933 : }
14934 :
14935 : tree
14936 26084 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
14937 : {
14938 26084 : return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
14939 : }
14940 :
14941 : tree
14942 826667 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
14943 : {
14944 826667 : return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
14945 : }
14946 :
14947 : /* Build a binary fold expression over EXPR1 and EXPR2. The
14948 : associativity of the fold is determined by EXPR1 and EXPR2 (whichever
14949 : has an unexpanded parameter pack). */
14950 :
14951 : static tree
14952 197729 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
14953 : int op, tree_code dir)
14954 : {
14955 197729 : pack = make_pack_expansion (pack);
14956 197729 : tree code = build_int_cstu (integer_type_node, abs (op));
14957 197729 : tree fold = build_min_nt_loc (loc, dir, code, pack, init);
14958 197729 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14959 197729 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14960 197729 : FOLD_EXPR_OP (fold),
14961 197729 : FOLD_EXPR_MODIFY_P (fold));
14962 197729 : return fold;
14963 : }
14964 :
14965 : tree
14966 197729 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
14967 : {
14968 : // Determine which expr has an unexpanded parameter pack and
14969 : // set the pack and initial term.
14970 197729 : bool pack1 = uses_parameter_packs (expr1);
14971 197729 : bool pack2 = uses_parameter_packs (expr2);
14972 197729 : if (pack1 && !pack2)
14973 1090 : return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
14974 196639 : else if (pack2 && !pack1)
14975 196639 : return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
14976 : else
14977 : {
14978 0 : if (pack1)
14979 0 : error ("both arguments in binary fold have unexpanded parameter packs");
14980 : else
14981 0 : error ("no unexpanded parameter packs in binary fold");
14982 : }
14983 0 : return error_mark_node;
14984 : }
14985 :
14986 : /* Finish __builtin_launder (arg). */
14987 :
14988 : tree
14989 14312 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
14990 : {
14991 14312 : tree orig_arg = arg;
14992 14312 : if (!type_dependent_expression_p (arg))
14993 84 : arg = decay_conversion (arg, complain);
14994 14312 : if (error_operand_p (arg))
14995 0 : return error_mark_node;
14996 14312 : if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
14997 : {
14998 24 : error_at (loc, "type %qT of argument to %<__builtin_launder%> "
14999 24 : "is not a pointer to object type", TREE_TYPE (arg));
15000 24 : return error_mark_node;
15001 : }
15002 14288 : if (processing_template_decl)
15003 14228 : arg = orig_arg;
15004 14288 : return build_call_expr_internal_loc (loc, IFN_LAUNDER,
15005 28576 : TREE_TYPE (arg), 1, arg);
15006 : }
15007 :
15008 : /* Finish __builtin_convertvector (arg, type). */
15009 :
15010 : tree
15011 486 : cp_build_vec_convert (tree arg, location_t loc, tree type,
15012 : tsubst_flags_t complain)
15013 : {
15014 486 : if (error_operand_p (type))
15015 9 : return error_mark_node;
15016 477 : if (error_operand_p (arg))
15017 0 : return error_mark_node;
15018 :
15019 477 : tree ret = NULL_TREE;
15020 477 : if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
15021 439 : ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
15022 : decay_conversion (arg, complain),
15023 : loc, type, (complain & tf_error) != 0);
15024 :
15025 477 : if (!processing_template_decl)
15026 : return ret;
15027 :
15028 80 : return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
15029 : }
15030 :
15031 : /* Finish __builtin_bit_cast (type, arg). */
15032 :
15033 : tree
15034 296156 : cp_build_bit_cast (location_t loc, tree type, tree arg,
15035 : tsubst_flags_t complain)
15036 : {
15037 296156 : if (error_operand_p (type))
15038 0 : return error_mark_node;
15039 296156 : if (!dependent_type_p (type))
15040 : {
15041 214649 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
15042 9 : return error_mark_node;
15043 214640 : if (TREE_CODE (type) == ARRAY_TYPE)
15044 : {
15045 : /* std::bit_cast for destination ARRAY_TYPE is not possible,
15046 : as functions may not return an array, so don't bother trying
15047 : to support this (and then deal with VLAs etc.). */
15048 9 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
15049 : "is an array type", type);
15050 9 : return error_mark_node;
15051 : }
15052 214631 : if (!trivially_copyable_p (type))
15053 : {
15054 18 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
15055 : "is not trivially copyable", type);
15056 18 : return error_mark_node;
15057 : }
15058 214613 : if (consteval_only_p (type) || consteval_only_p (arg))
15059 : {
15060 8 : error_at (loc, "%<__builtin_bit_cast%> cannot be used with "
15061 : "consteval-only types");
15062 8 : return error_mark_node;
15063 : }
15064 : }
15065 :
15066 296112 : if (error_operand_p (arg))
15067 0 : return error_mark_node;
15068 :
15069 296112 : if (!type_dependent_expression_p (arg))
15070 : {
15071 115376 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
15072 : {
15073 : /* Don't perform array-to-pointer conversion. */
15074 375 : arg = mark_rvalue_use (arg, loc, true);
15075 375 : if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
15076 0 : return error_mark_node;
15077 : }
15078 : else
15079 115001 : arg = decay_conversion (arg, complain);
15080 :
15081 115376 : if (error_operand_p (arg))
15082 12 : return error_mark_node;
15083 :
15084 115364 : if (!trivially_copyable_p (TREE_TYPE (arg)))
15085 : {
15086 9 : error_at (cp_expr_loc_or_loc (arg, loc),
15087 : "%<__builtin_bit_cast%> source type %qT "
15088 9 : "is not trivially copyable", TREE_TYPE (arg));
15089 9 : return error_mark_node;
15090 : }
15091 115355 : if (!dependent_type_p (type)
15092 192318 : && !cp_tree_equal (TYPE_SIZE_UNIT (type),
15093 76963 : TYPE_SIZE_UNIT (TREE_TYPE (arg))))
15094 : {
15095 18 : error_at (loc, "%<__builtin_bit_cast%> source size %qE "
15096 : "not equal to destination type size %qE",
15097 18 : TYPE_SIZE_UNIT (TREE_TYPE (arg)),
15098 18 : TYPE_SIZE_UNIT (type));
15099 18 : return error_mark_node;
15100 : }
15101 : }
15102 :
15103 296073 : tree ret = build_min (BIT_CAST_EXPR, type, arg);
15104 296073 : SET_EXPR_LOCATION (ret, loc);
15105 :
15106 296073 : if (!processing_template_decl && CLASS_TYPE_P (type))
15107 872 : ret = get_target_expr (ret, complain);
15108 :
15109 : return ret;
15110 : }
15111 :
15112 : /* Diagnose invalid #pragma GCC unroll argument and adjust
15113 : it if needed. */
15114 :
15115 : tree
15116 24658 : cp_check_pragma_unroll (location_t loc, tree unroll)
15117 : {
15118 24658 : HOST_WIDE_INT lunroll = 0;
15119 24658 : if (type_dependent_expression_p (unroll))
15120 : ;
15121 49244 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
15122 49198 : || (!value_dependent_expression_p (unroll)
15123 24546 : && (!tree_fits_shwi_p (unroll)
15124 24520 : || (lunroll = tree_to_shwi (unroll)) < 0
15125 24505 : || lunroll >= USHRT_MAX)))
15126 : {
15127 90 : error_at (loc, "%<#pragma GCC unroll%> requires an"
15128 : " assignment-expression that evaluates to a non-negative"
15129 : " integral constant less than %u", USHRT_MAX);
15130 90 : unroll = integer_one_node;
15131 : }
15132 24532 : else if (TREE_CODE (unroll) == INTEGER_CST)
15133 : {
15134 24502 : unroll = fold_convert (integer_type_node, unroll);
15135 24502 : if (integer_zerop (unroll))
15136 12 : unroll = integer_one_node;
15137 : }
15138 24658 : return unroll;
15139 : }
15140 :
15141 : #include "gt-cp-semantics.h"
|