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 22960706427 : push_deferring_access_checks (deferring_kind deferring)
146 : {
147 : /* For context like template instantiation, access checking
148 : disabling applies to all nested context. */
149 22960706427 : if (deferred_access_no_check || deferring == dk_no_check)
150 293961190 : deferred_access_no_check++;
151 : else
152 : {
153 22666745237 : deferred_access e = {NULL, deferring};
154 22666745237 : vec_safe_push (deferred_access_stack, e);
155 : }
156 22960706427 : }
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 362702535 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
163 : {
164 362702535 : push_deferring_access_checks (dk_deferred);
165 362702535 : if (!deferred_access_no_check)
166 355964387 : deferred_access_stack->last().deferred_access_checks = checks;
167 362702535 : }
168 :
169 : /* Resume deferring access checks again after we stopped doing
170 : this previously. */
171 :
172 : void
173 175565790 : resume_deferring_access_checks (void)
174 : {
175 175565790 : if (!deferred_access_no_check)
176 175545505 : deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
177 175565790 : }
178 :
179 : /* Stop deferring access checks. */
180 :
181 : void
182 492762921 : stop_deferring_access_checks (void)
183 : {
184 492762921 : if (!deferred_access_no_check)
185 492702738 : deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
186 492762921 : }
187 :
188 : /* Discard the current deferred access checks and restore the
189 : previous states. */
190 :
191 : void
192 14232096684 : pop_deferring_access_checks (void)
193 : {
194 14232096684 : if (deferred_access_no_check)
195 224846379 : deferred_access_no_check--;
196 : else
197 14007250305 : deferred_access_stack->pop ();
198 14232096684 : }
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 1221575949 : get_deferred_access_checks (void)
207 : {
208 1221575949 : if (deferred_access_no_check)
209 : return NULL;
210 : else
211 1208234483 : 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 8728474675 : pop_to_parent_deferring_access_checks (void)
220 : {
221 8728474675 : if (deferred_access_no_check)
222 69114805 : deferred_access_no_check--;
223 : else
224 : {
225 8659359870 : vec<deferred_access_check, va_gc> *checks;
226 8659359870 : deferred_access *ptr;
227 :
228 8659359870 : checks = (deferred_access_stack->last ().deferred_access_checks);
229 :
230 8659359870 : deferred_access_stack->pop ();
231 8659359870 : ptr = &deferred_access_stack->last ();
232 8659359870 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
233 : {
234 : /* Check access. */
235 546285520 : 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 8308772744 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
244 : {
245 106497535 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
246 : {
247 9582183 : if (probe->binfo == chk->binfo &&
248 7608408 : probe->decl == chk->decl &&
249 934609 : probe->diag_decl == chk->diag_decl)
250 933845 : goto found;
251 : }
252 : /* Insert into parent's checks. */
253 96915352 : vec_safe_push (ptr->deferred_access_checks, *chk);
254 97849197 : found:;
255 : }
256 : }
257 : }
258 8728474675 : }
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 394692931 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
334 : tsubst_flags_t complain, access_failure_info *afi = NULL)
335 : {
336 394692931 : gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
337 :
338 394692931 : if (flag_new_inheriting_ctors
339 500033767 : && 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 59360 : decl = strip_inheriting_ctors (decl);
345 59360 : basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
346 : ba_any, NULL, complain);
347 : }
348 :
349 394692931 : tree cs = current_scope ();
350 394692931 : if (in_template_context
351 394692931 : && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
352 40509094 : 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 40274120 : 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 354418811 : if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
382 : {
383 21572 : if (flag_new_inheriting_ctors)
384 21542 : diag_decl = strip_inheriting_ctors (diag_decl);
385 21572 : if (complain & tf_error)
386 : {
387 1151 : 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 1151 : 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 1151 : 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 1151 : 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 1151 : complain_about_access (decl, diag_decl, diag_location, true,
413 : access_failure_reason);
414 : }
415 21572 : if (afi)
416 412 : afi->record_access_failure (basetype_path, decl, diag_decl);
417 21572 : 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 1040647784 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
431 : tsubst_flags_t complain)
432 : {
433 1040647784 : int i;
434 1040647784 : deferred_access_check *chk;
435 1040647784 : location_t loc = input_location;
436 1040647784 : bool ok = true;
437 :
438 1040647784 : if (!checks)
439 : return true;
440 :
441 123450305 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
442 : {
443 68784625 : input_location = chk->loc;
444 68784625 : ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
445 : }
446 :
447 54665680 : input_location = loc;
448 54665680 : 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 273449210 : perform_deferred_access_checks (tsubst_flags_t complain)
469 : {
470 273449210 : 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 593020124 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
480 : tsubst_flags_t complain,
481 : access_failure_info *afi)
482 : {
483 593020124 : int i;
484 593020124 : deferred_access *ptr;
485 593020124 : deferred_access_check *chk;
486 :
487 : /* Exit if we are in a context that no access checking is performed. */
488 593020124 : if (deferred_access_no_check)
489 : return true;
490 :
491 569222395 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
492 :
493 569222395 : ptr = &deferred_access_stack->last ();
494 :
495 : /* If we are not supposed to defer access checks, just check now. */
496 569222395 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
497 : {
498 325908306 : bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
499 497113589 : return (complain & tf_error) ? true : ok;
500 : }
501 :
502 : /* See if we are already going to perform this check. */
503 297114416 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
504 : {
505 71017627 : if (chk->decl == decl && chk->binfo == binfo &&
506 17218035 : chk->diag_decl == diag_decl)
507 : {
508 : return true;
509 : }
510 : }
511 : /* If not, record the check. */
512 226096789 : deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
513 226096789 : vec_safe_push (ptr->deferred_access_checks, new_access);
514 :
515 226096789 : 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 1431146732 : stmts_are_full_exprs_p (void)
524 : {
525 1431146732 : 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 1240640642 : add_stmt (tree t)
534 : {
535 1240640642 : enum tree_code code = TREE_CODE (t);
536 :
537 1240640642 : if (EXPR_P (t) && code != LABEL_EXPR)
538 : {
539 1192561944 : if (!EXPR_HAS_LOCATION (t))
540 190497880 : 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 1192561944 : if (STATEMENT_CODE_P (TREE_CODE (t)))
545 309443101 : STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
546 : }
547 :
548 1240640642 : if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
549 5341939 : 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 1240640642 : gcc_checking_assert (!stmt_list_stack->is_empty ());
554 1240640642 : append_to_statement_list_force (t, &cur_stmt_list);
555 :
556 1240640642 : return t;
557 : }
558 :
559 : /* Returns the stmt_tree to which statements are currently being added. */
560 :
561 : stmt_tree
562 7324916694 : current_stmt_tree (void)
563 : {
564 7324916694 : return (cfun
565 7287244598 : ? &cfun->language->base.x_stmt_tree
566 7324916694 : : &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 288755 : maybe_cleanup_point_expr (tree expr)
573 : {
574 288755 : if (!processing_template_decl && stmts_are_full_exprs_p ())
575 274722 : expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
576 288755 : 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 307105563 : maybe_cleanup_point_expr_void (tree expr)
586 : {
587 307105563 : if (!processing_template_decl && stmts_are_full_exprs_p ())
588 102229861 : expr = fold_build_cleanup_point_expr (void_type_node, expr);
589 307105563 : return expr;
590 : }
591 :
592 :
593 :
594 : /* Create a declaration statement for the declaration given by the DECL. */
595 :
596 : void
597 104106089 : add_decl_expr (tree decl)
598 : {
599 104106089 : tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
600 104106089 : if (DECL_INITIAL (decl)
601 104106089 : || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
602 18614873 : r = maybe_cleanup_point_expr_void (r);
603 104106089 : add_stmt (r);
604 104106089 : }
605 :
606 : /* Set EXPR_LOCATION on one cleanup T to LOC. */
607 :
608 : static void
609 5506315 : set_one_cleanup_loc (tree t, location_t loc)
610 : {
611 5506315 : if (!t)
612 : return;
613 :
614 5506315 : if (TREE_CODE (t) != POSTCONDITION_STMT)
615 5506315 : 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 5506315 : if (TREE_CODE (t) == NOP_EXPR
622 0 : && TREE_TYPE (t) == void_type_node
623 5506315 : && 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 1173054537 : set_cleanup_locs (tree stmts, location_t loc)
631 : {
632 1178560852 : if (TREE_CODE (stmts) == CLEANUP_STMT)
633 : {
634 5506315 : set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
635 5506315 : set_cleanup_locs (CLEANUP_BODY (stmts), loc);
636 : }
637 1173054537 : else if (TREE_CODE (stmts) == STATEMENT_LIST)
638 1046022774 : for (tree stmt : tsi_range (stmts))
639 810097069 : set_cleanup_locs (stmt, loc);
640 1173054537 : }
641 :
642 : /* True iff the innermost block scope is a try block. */
643 :
644 : static bool
645 362957468 : at_try_scope ()
646 : {
647 362957468 : cp_binding_level *b = current_binding_level;
648 362957846 : while (b && b->kind == sk_cleanup)
649 378 : b = b->level_chain;
650 362957468 : return b && b->kind == sk_try;
651 : }
652 :
653 : /* Finish a scope. */
654 :
655 : tree
656 362957468 : do_poplevel (tree stmt_list)
657 : {
658 362957468 : tree block = NULL;
659 :
660 362957468 : bool was_try = at_try_scope ();
661 :
662 362957468 : if (stmts_are_full_exprs_p ())
663 362896653 : block = poplevel (kept_level_p (), 1, 0);
664 :
665 : /* This needs to come after poplevel merges sk_cleanup statement_lists. */
666 362957468 : maybe_splice_retval_cleanup (stmt_list, was_try);
667 :
668 362957468 : stmt_list = pop_stmt_list (stmt_list);
669 :
670 : /* input_location is the last token of the scope, usually a }. */
671 362957468 : set_cleanup_locs (stmt_list, input_location);
672 :
673 362957468 : if (!processing_template_decl)
674 : {
675 110631679 : stmt_list = c_build_bind_expr (input_location, block, stmt_list);
676 : /* ??? See c_end_compound_stmt re statement expressions. */
677 : }
678 :
679 362957468 : return stmt_list;
680 : }
681 :
682 : /* Begin a new scope. */
683 :
684 : tree
685 362921240 : do_pushlevel (scope_kind sk)
686 : {
687 362921240 : tree ret = push_stmt_list ();
688 362921240 : if (stmts_are_full_exprs_p ())
689 362896713 : begin_scope (sk, NULL);
690 362921240 : 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 5506224 : push_cleanup (tree decl, tree cleanup, bool eh_only)
700 : {
701 5506224 : tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
702 5506224 : CLEANUP_EH_ONLY (stmt) = eh_only;
703 5506224 : add_stmt (stmt);
704 5506224 : CLEANUP_BODY (stmt) = push_stmt_list ();
705 5506224 : }
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 17493630 : begin_maybe_infinite_loop (tree cond)
716 : {
717 : /* Only track this while parsing a function, not during instantiation. */
718 17493630 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
719 2551403 : && !processing_template_decl))
720 : return;
721 14941682 : bool maybe_infinite = true;
722 14941682 : if (cond)
723 : {
724 14637225 : cond = fold_non_dependent_expr (cond);
725 14637225 : maybe_infinite = integer_nonzerop (cond);
726 : }
727 29578907 : vec_safe_push (cp_function_chain->infinite_loops,
728 14941682 : 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 1478885 : break_maybe_infinite_loop (void)
736 : {
737 1478885 : if (!cfun)
738 : return;
739 1478885 : 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 17493630 : end_maybe_infinite_loop (tree cond)
747 : {
748 17493630 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
749 2551403 : && !processing_template_decl))
750 : return;
751 14941682 : tree current = cp_function_chain->infinite_loops->pop();
752 14941682 : if (current != NULL_TREE)
753 : {
754 4800881 : cond = fold_non_dependent_expr (cond);
755 4800881 : if (integer_nonzerop (cond))
756 300735 : 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 83562556 : begin_cond (tree *cond_p)
767 : {
768 83562556 : if (processing_template_decl)
769 59648009 : *cond_p = push_stmt_list ();
770 83562556 : }
771 :
772 : /* Finish such a conditional. */
773 :
774 : static void
775 83562556 : finish_cond (tree *cond_p, tree expr)
776 : {
777 83562556 : if (processing_template_decl)
778 : {
779 59648009 : tree cond = pop_stmt_list (*cond_p);
780 :
781 59648009 : if (expr == NULL_TREE)
782 : /* Empty condition in 'for'. */
783 284406 : gcc_assert (empty_expr_stmt_p (cond));
784 59363603 : else if (check_for_bare_parameter_packs (expr))
785 0 : expr = error_mark_node;
786 59363603 : else if (!empty_expr_stmt_p (cond))
787 898365 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
788 : }
789 83562556 : *cond_p = expr;
790 83562556 : }
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 11866447 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
809 : {
810 11866447 : if (!TREE_SIDE_EFFECTS (*body_p))
811 11857042 : return;
812 :
813 9405 : gcc_assert (!processing_template_decl);
814 9405 : *prep_p = *body_p;
815 9405 : 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 9405 : current_binding_level->keep = true;
840 9405 : 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 9405 : if (tsi_end_p (iter))
847 91 : *body_p = NULL_TREE;
848 : else
849 9314 : *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 9405 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
862 : {
863 9405 : *prep_p = do_poplevel (*prep_p);
864 9405 : gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
865 9405 : 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 9387 : tree stmt_list = BIND_EXPR_BODY (*prep_p);
872 9387 : gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
873 9387 : 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 9296 : tree_stmt_iterator iter = tsi_start (stmt_list);
893 9492 : while (tsi_stmt (iter) != *body_p)
894 196 : tsi_next (&iter);
895 9296 : *body_p = tsi_split_stmt_list (input_location, iter);
896 : }
897 :
898 : /* Finish a goto-statement. */
899 :
900 : tree
901 2710 : finish_goto_stmt (tree destination)
902 : {
903 2710 : if (identifier_p (destination))
904 2573 : 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 2710 : if (TREE_CODE (destination) == LABEL_DECL)
909 2573 : TREE_USED (destination) = 1;
910 : else
911 : {
912 137 : destination = mark_rvalue_use (destination);
913 137 : if (!processing_template_decl)
914 : {
915 117 : destination = cp_convert (ptr_type_node, destination,
916 : tf_warning_or_error);
917 117 : if (error_operand_p (destination))
918 : return NULL_TREE;
919 108 : destination
920 108 : = fold_build_cleanup_point_expr (TREE_TYPE (destination),
921 : destination);
922 : }
923 : }
924 :
925 2701 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
926 :
927 2701 : tree stmt = build_stmt (input_location, GOTO_EXPR, destination);
928 2701 : check_goto (&TREE_OPERAND (stmt, 0));
929 :
930 2701 : return add_stmt (stmt);
931 : }
932 :
933 : /* Returns true if T corresponds to an assignment operator expression. */
934 :
935 : static bool
936 871968 : is_assignment_op_expr_p (tree t)
937 : {
938 871968 : if (t == NULL_TREE)
939 : return false;
940 :
941 871968 : if (TREE_CODE (t) == MODIFY_EXPR
942 871968 : || (TREE_CODE (t) == MODOP_EXPR
943 336 : && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
944 : return true;
945 :
946 871281 : tree call = extract_call_expr (t);
947 871281 : if (call == NULL_TREE
948 128554 : || call == error_mark_node
949 999835 : || !CALL_EXPR_OPERATOR_SYNTAX (call))
950 : return false;
951 :
952 4667 : tree fndecl = cp_get_callee_fndecl_nofold (call);
953 4667 : return fndecl != NULL_TREE
954 4569 : && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
955 4718 : && 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 4 : 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 85930477 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
1019 : tsubst_flags_t complain)
1020 : {
1021 85930477 : tree type = TREE_TYPE (t);
1022 85930477 : t = STRIP_REFERENCE_REF (t);
1023 :
1024 85930477 : if ((complain & tf_warning)
1025 85871521 : && warn_parentheses
1026 871968 : && 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 85930824 : && (!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 85930477 : }
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 50599623 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
1072 : {
1073 50599623 : tree *t = cond;
1074 50609512 : while (TREE_CODE (*t) == ANNOTATE_EXPR)
1075 9889 : t = &TREE_OPERAND (*t, 0);
1076 :
1077 50599623 : if (t != cond)
1078 : {
1079 9886 : m_annotations = *cond;
1080 9886 : *cond = *t;
1081 9886 : m_inner = t;
1082 : }
1083 50599623 : }
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 50599623 : annotate_saver::restore (tree new_inner)
1092 : {
1093 50599623 : 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 9886 : 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 9886 : *m_inner = new_inner;
1118 9886 : 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 88317856 : maybe_convert_cond (tree cond)
1127 : {
1128 : /* Empty conditions remain empty. */
1129 88317856 : if (!cond)
1130 : return NULL_TREE;
1131 :
1132 : /* Wait until we instantiate templates before doing conversion. */
1133 87957838 : if (type_dependent_expression_p (cond))
1134 37358215 : return cond;
1135 :
1136 : /* Strip any ANNOTATE_EXPRs from COND. */
1137 50599623 : 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,elemenet} case. cp_finish_decomp saved the conversion
1142 : result in a TARGET_EXPR, pick it up from there. */
1143 349284 : if (DECL_DECOMPOSITION_P (cond)
1144 224 : && DECL_DECOMP_IS_BASE (cond)
1145 224 : && DECL_DECOMP_BASE (cond)
1146 50599844 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1147 56 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1148 :
1149 50599623 : if (warn_sequence_point && !processing_template_decl)
1150 323901 : verify_sequence_points (cond);
1151 :
1152 50599623 : maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
1153 : tf_warning_or_error);
1154 :
1155 : /* Do the conversion. */
1156 50599623 : cond = convert_from_reference (cond);
1157 50599623 : cond = condition_conversion (cond);
1158 :
1159 : /* Restore any ANNOTATE_EXPRs around COND. */
1160 50599623 : return annotations.restore (cond);
1161 : }
1162 :
1163 : /* Finish an expression-statement, whose EXPRESSION is as indicated. */
1164 :
1165 : tree
1166 158058567 : finish_expr_stmt (tree expr)
1167 : {
1168 158058567 : tree r = NULL_TREE;
1169 158058567 : location_t loc = EXPR_LOCATION (expr);
1170 :
1171 157901627 : if (expr != NULL_TREE)
1172 : {
1173 : /* If we ran into a problem, make sure we complained. */
1174 158058406 : gcc_assert (expr != error_mark_node || seen_error ());
1175 :
1176 158058406 : if (!processing_template_decl)
1177 : {
1178 56680868 : if (warn_sequence_point)
1179 806565 : verify_sequence_points (expr);
1180 56680868 : expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1181 : }
1182 101377538 : else if (!type_dependent_expression_p (expr))
1183 22022689 : convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1184 :
1185 158058403 : 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 158058403 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
1192 : {
1193 158058224 : if (TREE_CODE (expr) != EXPR_STMT
1194 155695640 : && !STATEMENT_CLASS_P (expr)
1195 155691489 : && TREE_CODE (expr) != STATEMENT_LIST)
1196 155572598 : expr = build_stmt (loc, EXPR_STMT, expr);
1197 158058224 : expr = maybe_cleanup_point_expr_void (expr);
1198 : }
1199 :
1200 158058403 : r = add_stmt (expr);
1201 : }
1202 :
1203 158058564 : return r;
1204 : }
1205 :
1206 :
1207 : /* Begin an if-statement. Returns a newly created IF_STMT if
1208 : appropriate. */
1209 :
1210 : tree
1211 71028920 : begin_if_stmt (void)
1212 : {
1213 71028920 : tree r, scope;
1214 71028920 : scope = do_pushlevel (sk_cond);
1215 71028920 : r = build_stmt (input_location, IF_STMT, NULL_TREE,
1216 : NULL_TREE, NULL_TREE, scope);
1217 71028920 : current_binding_level->this_entity = r;
1218 71028920 : begin_cond (&IF_COND (r));
1219 71028920 : 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 252075 : is_std_constant_evaluated_p (tree fn)
1227 : {
1228 : /* std::is_constant_evaluated takes no arguments. */
1229 252075 : if (call_expr_nargs (fn) != 0)
1230 : return false;
1231 :
1232 89738 : tree fndecl = cp_get_callee_fndecl_nofold (fn);
1233 89738 : if (fndecl == NULL_TREE)
1234 : return false;
1235 :
1236 27596 : if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
1237 : BUILT_IN_FRONTEND))
1238 : return true;
1239 :
1240 27567 : if (!decl_in_std_namespace_p (fndecl))
1241 : return false;
1242 :
1243 12230 : tree name = DECL_NAME (fndecl);
1244 12230 : 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 4670193 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
1252 : {
1253 4670193 : tree t = *tp;
1254 :
1255 4670193 : if (TYPE_P (t) || TREE_CONSTANT (t))
1256 : {
1257 823746 : *walk_subtrees = false;
1258 823746 : return NULL_TREE;
1259 : }
1260 :
1261 3846447 : switch (TREE_CODE (t))
1262 : {
1263 252075 : case CALL_EXPR:
1264 252075 : if (is_std_constant_evaluated_p (t))
1265 : 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 71114468 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
1284 : bool trivial_infinite)
1285 : {
1286 71114468 : if (!warn_tautological_compare)
1287 : return;
1288 :
1289 : /* Suppress warning for std::is_constant_evaluated if the conditional
1290 : comes from a macro. */
1291 1423874 : if (from_macro_expansion_at (EXPR_LOCATION (cond)))
1292 : return;
1293 :
1294 600498 : cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
1295 : NULL);
1296 600498 : if (cond)
1297 : {
1298 2392 : 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 2358 : 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 2350 : 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 4624 : 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 71028920 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
1330 : {
1331 71028920 : tree cond = maybe_convert_cond (orig_cond);
1332 71028920 : maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
1333 : /*trivial_infinite=*/false);
1334 71028920 : if (IF_STMT_CONSTEXPR_P (if_stmt)
1335 14649764 : && !type_dependent_expression_p (cond)
1336 9850802 : && require_constant_expression (cond)
1337 9850773 : && !instantiation_dependent_expression_p (cond)
1338 : /* Wait until instantiation time, since only then COND has been
1339 : converted to bool. */
1340 76359191 : && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
1341 : {
1342 5330271 : cond = instantiate_non_dependent_expr (cond);
1343 5330271 : cond = cxx_constant_value (cond);
1344 : }
1345 65698649 : else if (processing_template_decl)
1346 49425165 : cond = orig_cond;
1347 71028920 : finish_cond (&IF_COND (if_stmt), cond);
1348 71028920 : add_stmt (if_stmt);
1349 71028920 : THEN_CLAUSE (if_stmt) = push_stmt_list ();
1350 71028920 : 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 71024037 : finish_then_clause (tree if_stmt)
1358 : {
1359 71024037 : THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
1360 71024037 : return if_stmt;
1361 : }
1362 :
1363 : /* Begin the else-clause of an if-statement. */
1364 :
1365 : void
1366 26568327 : begin_else_clause (tree if_stmt)
1367 : {
1368 26568327 : ELSE_CLAUSE (if_stmt) = push_stmt_list ();
1369 26568327 : }
1370 :
1371 : /* Finish the else-clause of an if-statement, which may be given by
1372 : IF_STMT. */
1373 :
1374 : void
1375 26568289 : finish_else_clause (tree if_stmt)
1376 : {
1377 26568289 : ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
1378 26568289 : }
1379 :
1380 : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1381 : read. */
1382 :
1383 : static tree
1384 788566595 : maybe_mark_exp_read_r (tree *tp, int *, void *)
1385 : {
1386 788566595 : tree t = *tp;
1387 788566595 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1388 45515590 : mark_exp_read (t);
1389 788566595 : return NULL_TREE;
1390 : }
1391 :
1392 : /* Finish an if-statement. */
1393 :
1394 : void
1395 71024037 : finish_if_stmt (tree if_stmt)
1396 : {
1397 71024037 : tree scope = IF_SCOPE (if_stmt);
1398 71024037 : IF_SCOPE (if_stmt) = NULL;
1399 71024037 : 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 14644881 : cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
1405 : maybe_mark_exp_read_r, NULL);
1406 14644881 : cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
1407 : maybe_mark_exp_read_r, NULL);
1408 : }
1409 71024037 : add_stmt (do_poplevel (scope));
1410 71024037 : }
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 16925630 : finish_loop_cond (tree *condp, tree body)
1421 : {
1422 16925630 : if (TREE_CODE (*condp) == INTEGER_CST)
1423 : return;
1424 12195096 : bool trivially_empty = expr_first (body) == NULL_TREE;
1425 12195096 : bool trivial_infinite = false;
1426 12195096 : if (trivially_empty)
1427 : {
1428 95305 : tree c = fold_non_dependent_expr (*condp, tf_none,
1429 : /*manifestly_const_eval=*/true);
1430 95305 : trivial_infinite = c && integer_nonzerop (c);
1431 : }
1432 12195096 : if (warn_tautological_compare)
1433 : {
1434 85750 : tree cond = *condp;
1435 86117 : while (TREE_CODE (cond) == ANNOTATE_EXPR)
1436 367 : cond = TREE_OPERAND (cond, 0);
1437 85750 : if (trivial_infinite
1438 85814 : && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1439 64 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1440 : /*trivial_infinite=*/true);
1441 85686 : else if (!trivially_empty
1442 375 : || !processing_template_decl
1443 86090 : || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1444 85484 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1445 : /*trivial_infinite=*/false);
1446 : }
1447 12195096 : 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 4636144 : begin_while_stmt (void)
1459 : {
1460 4636144 : tree r;
1461 4636144 : r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1462 : NULL_TREE, NULL_TREE);
1463 4636144 : add_stmt (r);
1464 4636144 : WHILE_BODY (r) = do_pushlevel (sk_block);
1465 4636144 : begin_cond (&WHILE_COND (r));
1466 4636144 : return r;
1467 : }
1468 :
1469 : /* Process the COND of a while-statement, which may be given by
1470 : WHILE_STMT. */
1471 :
1472 : void
1473 4636144 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
1474 : tree unroll, bool novector)
1475 : {
1476 4636144 : cond = maybe_convert_cond (cond);
1477 4636144 : finish_cond (&WHILE_COND (while_stmt), cond);
1478 4636144 : begin_maybe_infinite_loop (cond);
1479 4636144 : 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 4636144 : if (unroll && cond != error_mark_node)
1487 25764 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1488 12882 : TREE_TYPE (WHILE_COND (while_stmt)),
1489 12882 : WHILE_COND (while_stmt),
1490 : build_int_cst (integer_type_node,
1491 : annot_expr_unroll_kind),
1492 : unroll);
1493 4636144 : 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 4636144 : adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
1501 : &WHILE_COND_PREP (while_stmt),
1502 : &WHILE_COND_CLEANUP (while_stmt));
1503 4636144 : }
1504 :
1505 : /* Finish a while-statement, which may be given by WHILE_STMT. */
1506 :
1507 : void
1508 4636144 : finish_while_stmt (tree while_stmt)
1509 : {
1510 4636144 : end_maybe_infinite_loop (boolean_true_node);
1511 4636144 : if (WHILE_COND_PREP (while_stmt))
1512 9231 : finish_loop_cond_prep (&WHILE_BODY (while_stmt),
1513 : &WHILE_COND_PREP (while_stmt),
1514 9231 : WHILE_COND_CLEANUP (while_stmt));
1515 : else
1516 4626913 : WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
1517 4636144 : finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
1518 4636144 : }
1519 :
1520 : /* Begin a do-statement. Returns a newly created DO_STMT if
1521 : appropriate. */
1522 :
1523 : tree
1524 5419201 : begin_do_stmt (void)
1525 : {
1526 5419201 : tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
1527 : NULL_TREE);
1528 5419201 : begin_maybe_infinite_loop (boolean_true_node);
1529 5419201 : add_stmt (r);
1530 5419201 : DO_BODY (r) = push_stmt_list ();
1531 5419201 : return r;
1532 : }
1533 :
1534 : /* Finish the body of a do-statement, which may be given by DO_STMT. */
1535 :
1536 : void
1537 5419201 : finish_do_body (tree do_stmt)
1538 : {
1539 5419201 : tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
1540 :
1541 5419201 : if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
1542 518192 : body = STATEMENT_LIST_TAIL (body)->stmt;
1543 :
1544 5419201 : if (IS_EMPTY_STMT (body))
1545 30 : warning (OPT_Wempty_body,
1546 : "suggest explicit braces around empty body in %<do%> statement");
1547 5419201 : }
1548 :
1549 : /* Finish a do-statement, which may be given by DO_STMT, and whose
1550 : COND is as indicated. */
1551 :
1552 : void
1553 5419201 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
1554 : bool novector)
1555 : {
1556 5419201 : cond = maybe_convert_cond (cond);
1557 5419201 : 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 5419201 : if (check_for_bare_parameter_packs (cond))
1562 3 : cond = error_mark_node;
1563 5419201 : 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 5419201 : 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 5419201 : 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 5419201 : DO_COND (do_stmt) = cond;
1576 5419201 : tree do_body = DO_BODY (do_stmt);
1577 5419171 : if (CONVERT_EXPR_P (do_body)
1578 30 : && integer_zerop (TREE_OPERAND (do_body, 0))
1579 5419231 : && VOID_TYPE_P (TREE_TYPE (do_body)))
1580 : do_body = NULL_TREE;
1581 5419201 : finish_loop_cond (&DO_COND (do_stmt), do_body);
1582 5419201 : }
1583 :
1584 : /* Finish a return-statement. The EXPRESSION returned, if any, is as
1585 : indicated. */
1586 :
1587 : tree
1588 123598731 : finish_return_stmt (tree expr)
1589 : {
1590 123598731 : tree r;
1591 123598731 : bool no_warning;
1592 123598731 : bool dangling;
1593 :
1594 123598731 : expr = check_return_expr (expr, &no_warning, &dangling);
1595 :
1596 123598731 : if (error_operand_p (expr)
1597 123598731 : || (flag_openmp && !check_omp_return ()))
1598 : {
1599 : /* Suppress -Wreturn-type for this function. */
1600 1246 : if (warn_return_type)
1601 1240 : suppress_warning (current_function_decl, OPT_Wreturn_type);
1602 1246 : return error_mark_node;
1603 : }
1604 :
1605 123597485 : if (!processing_template_decl)
1606 : {
1607 43289668 : if (warn_sequence_point)
1608 1021423 : verify_sequence_points (expr);
1609 : }
1610 :
1611 123597485 : r = build_stmt (input_location, RETURN_EXPR, expr);
1612 123597485 : RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
1613 123597485 : if (no_warning)
1614 33 : suppress_warning (r, OPT_Wreturn_type);
1615 123597485 : r = maybe_cleanup_point_expr_void (r);
1616 123597485 : r = add_stmt (r);
1617 :
1618 123597485 : 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 7438285 : begin_for_scope (tree *init)
1627 : {
1628 7438285 : tree scope = do_pushlevel (sk_for);
1629 :
1630 7438285 : if (processing_template_decl)
1631 5907620 : *init = push_stmt_list ();
1632 : else
1633 1530665 : *init = NULL_TREE;
1634 :
1635 7438285 : 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 7230303 : begin_for_stmt (tree scope, tree init)
1644 : {
1645 7230303 : tree r;
1646 :
1647 7230303 : 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 7230303 : if (scope == NULL_TREE)
1652 : {
1653 1288579 : gcc_assert (!init);
1654 1288579 : scope = begin_for_scope (&init);
1655 : }
1656 :
1657 7230303 : FOR_INIT_STMT (r) = init;
1658 7230303 : FOR_SCOPE (r) = scope;
1659 :
1660 7230303 : 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 7230303 : finish_init_stmt (tree for_stmt)
1668 : {
1669 7230303 : if (processing_template_decl)
1670 5699638 : FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
1671 7230303 : add_stmt (for_stmt);
1672 7230303 : FOR_BODY (for_stmt) = do_pushlevel (sk_block);
1673 7230303 : begin_cond (&FOR_COND (for_stmt));
1674 7230303 : }
1675 :
1676 : /* Finish the COND of a for-statement, which may be given by
1677 : FOR_STMT. */
1678 :
1679 : void
1680 7230303 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
1681 : bool novector)
1682 : {
1683 7230303 : cond = maybe_convert_cond (cond);
1684 7230303 : finish_cond (&FOR_COND (for_stmt), cond);
1685 7230303 : begin_maybe_infinite_loop (cond);
1686 7230303 : 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 7230303 : 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 7230303 : 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 7230303 : adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
1708 : &FOR_COND_CLEANUP (for_stmt));
1709 7230303 : }
1710 :
1711 : /* Finish the increment-EXPRESSION in a for-statement, which may be
1712 : given by FOR_STMT. */
1713 :
1714 : void
1715 7218092 : finish_for_expr (tree expr, tree for_stmt)
1716 : {
1717 7218092 : 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 6773072 : if (type_unknown_p (expr))
1722 : {
1723 6 : cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1724 6 : expr = error_mark_node;
1725 : }
1726 6773072 : if (!processing_template_decl)
1727 : {
1728 1460957 : if (warn_sequence_point)
1729 14876 : verify_sequence_points (expr);
1730 1460957 : expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1731 : tf_warning_or_error);
1732 : }
1733 5312115 : else if (!type_dependent_expression_p (expr))
1734 1906066 : convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
1735 6773072 : expr = maybe_cleanup_point_expr_void (expr);
1736 6773072 : if (check_for_bare_parameter_packs (expr))
1737 0 : expr = error_mark_node;
1738 6773072 : 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 7438398 : find_range_for_decls (tree range_for_decl[3])
1749 : {
1750 7438398 : 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 29753592 : for (int i = 0; i < 3; i++)
1756 : {
1757 22315194 : tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1758 22315194 : if (IDENTIFIER_BINDING (id)
1759 22315194 : && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1760 : {
1761 258358 : range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1762 258358 : gcc_assert (VAR_P (range_for_decl[i])
1763 : && DECL_ARTIFICIAL (range_for_decl[i]));
1764 : }
1765 : }
1766 7438398 : }
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 7438285 : finish_for_stmt (tree for_stmt)
1775 : {
1776 7438285 : end_maybe_infinite_loop (boolean_true_node);
1777 :
1778 7438285 : if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1779 207982 : RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1780 : else
1781 : {
1782 7230303 : 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 7230129 : FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1788 7230303 : if (FOR_COND (for_stmt))
1789 6870285 : finish_loop_cond (&FOR_COND (for_stmt),
1790 6870285 : FOR_EXPR (for_stmt) ? integer_one_node
1791 136528 : : FOR_BODY (for_stmt));
1792 : }
1793 :
1794 : /* Pop the scope for the body of the loop. */
1795 7438285 : tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1796 7438285 : ? &RANGE_FOR_SCOPE (for_stmt)
1797 7230303 : : &FOR_SCOPE (for_stmt));
1798 7438285 : tree scope = *scope_ptr;
1799 7438285 : *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 7438285 : tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1806 7438285 : find_range_for_decls (range_for_decl);
1807 :
1808 7438285 : 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 7438285 : if (!stmts_are_full_exprs_p ())
1813 12211 : return;
1814 :
1815 29704296 : for (int i = 0; i < 3; i++)
1816 22278222 : if (range_for_decl[i])
1817 258242 : DECL_NAME (range_for_decl[i])
1818 258242 : = 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 207982 : begin_range_for_stmt (tree scope, tree init)
1828 : {
1829 207982 : begin_maybe_infinite_loop (boolean_false_node);
1830 :
1831 207982 : tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1832 : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1833 :
1834 207982 : if (scope == NULL_TREE)
1835 : {
1836 254 : gcc_assert (!init);
1837 254 : scope = begin_for_scope (&init);
1838 : }
1839 :
1840 : /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1841 207982 : RANGE_FOR_INIT_STMT (r) = init;
1842 207982 : RANGE_FOR_SCOPE (r) = scope;
1843 :
1844 207982 : 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 207982 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1853 : {
1854 207982 : if (processing_template_decl)
1855 415964 : RANGE_FOR_INIT_STMT (range_for_stmt)
1856 415964 : = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1857 207982 : RANGE_FOR_DECL (range_for_stmt) = decl;
1858 207982 : RANGE_FOR_EXPR (range_for_stmt) = expr;
1859 207982 : add_stmt (range_for_stmt);
1860 207982 : RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1861 207982 : }
1862 :
1863 : /* Begin the scope of an expansion-statement. */
1864 :
1865 : tree
1866 1445 : begin_template_for_scope (tree *init)
1867 : {
1868 1445 : tree scope = do_pushlevel (sk_template_for);
1869 :
1870 1445 : if (processing_template_decl)
1871 419 : *init = push_stmt_list ();
1872 : else
1873 1026 : *init = NULL_TREE;
1874 :
1875 1445 : return scope;
1876 : }
1877 :
1878 : /* Finish a break-statement. */
1879 :
1880 : tree
1881 4634716 : 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 4634716 : if (!block_may_fallthru (cur_stmt_list))
1891 711 : return void_node;
1892 4634005 : note_break_stmt ();
1893 4634005 : return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
1894 : }
1895 :
1896 : /* Finish a continue-statement. */
1897 :
1898 : tree
1899 224305 : finish_continue_stmt (void)
1900 : {
1901 224305 : 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 667189 : begin_switch_stmt (void)
1909 : {
1910 667189 : tree r, scope;
1911 :
1912 667189 : scope = do_pushlevel (sk_cond);
1913 667189 : r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1914 : scope, NULL_TREE);
1915 :
1916 667189 : begin_cond (&SWITCH_STMT_COND (r));
1917 :
1918 667189 : return r;
1919 : }
1920 :
1921 : /* Finish the cond of a switch-statement. */
1922 :
1923 : void
1924 667189 : finish_switch_cond (tree cond, tree switch_stmt)
1925 : {
1926 667189 : tree orig_type = NULL;
1927 :
1928 667189 : if (!processing_template_decl)
1929 : {
1930 : /* Convert the condition to an integer or enumeration type. */
1931 259358 : 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,elemenet} case. cp_finish_decomp saved the
1935 : conversion result in a TARGET_EXPR, pick it up from there. */
1936 122 : if (DECL_DECOMPOSITION_P (cond)
1937 57 : && DECL_DECOMP_IS_BASE (cond)
1938 57 : && DECL_DECOMP_BASE (cond)
1939 259412 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1940 18 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1941 259358 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1942 259358 : 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 259358 : orig_type = unlowered_expr_type (cond);
1950 259358 : if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1951 182474 : orig_type = TREE_TYPE (cond);
1952 259358 : if (cond != error_mark_node)
1953 : {
1954 : /* [stmt.switch]
1955 :
1956 : Integral promotions are performed. */
1957 259325 : cond = perform_integral_promotions (cond);
1958 259325 : cond = maybe_cleanup_point_expr (cond);
1959 : }
1960 : }
1961 667189 : if (check_for_bare_parameter_packs (cond))
1962 0 : cond = error_mark_node;
1963 667189 : else if (!processing_template_decl && warn_sequence_point)
1964 2776 : verify_sequence_points (cond);
1965 :
1966 667189 : finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1967 667189 : SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1968 667189 : add_stmt (switch_stmt);
1969 667189 : push_switch (switch_stmt);
1970 667189 : SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1971 667189 : }
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 667189 : finish_switch_stmt (tree switch_stmt)
1978 : {
1979 667189 : tree scope;
1980 :
1981 1334378 : SWITCH_STMT_BODY (switch_stmt) =
1982 667189 : pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1983 667189 : pop_switch ();
1984 :
1985 667189 : scope = SWITCH_STMT_SCOPE (switch_stmt);
1986 667189 : SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1987 667189 : add_stmt (do_poplevel (scope));
1988 667189 : }
1989 :
1990 : /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1991 : appropriate. */
1992 :
1993 : tree
1994 1130656 : begin_try_block (void)
1995 : {
1996 1130656 : tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1997 1130656 : add_stmt (r);
1998 1130656 : TRY_STMTS (r) = push_stmt_list ();
1999 1130656 : 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 330 : begin_function_try_block (tree *compound_stmt)
2008 : {
2009 330 : 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 330 : *compound_stmt = begin_compound_stmt (0);
2013 330 : current_binding_level->artificial = 1;
2014 330 : r = begin_try_block ();
2015 330 : FN_TRY_BLOCK_P (r) = 1;
2016 330 : return r;
2017 : }
2018 :
2019 : /* Finish a try-block, which may be given by TRY_BLOCK. */
2020 :
2021 : void
2022 1130656 : finish_try_block (tree try_block)
2023 : {
2024 1130656 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2025 1130656 : TRY_HANDLERS (try_block) = push_stmt_list ();
2026 1130656 : }
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 330 : finish_function_try_block (tree try_block)
2051 : {
2052 330 : finish_try_block (try_block);
2053 : /* FIXME : something queer about CTOR_INITIALIZER somehow following
2054 : the try block, but moving it inside. */
2055 330 : in_function_try_handler = 1;
2056 330 : }
2057 :
2058 : /* Finish a handler-sequence for a try-block, which may be given by
2059 : TRY_BLOCK. */
2060 :
2061 : void
2062 1130656 : finish_handler_sequence (tree try_block)
2063 : {
2064 1130656 : TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
2065 1130656 : check_handlers (TRY_HANDLERS (try_block));
2066 1130656 : }
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 330 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
2074 : {
2075 330 : in_function_try_handler = 0;
2076 330 : finish_handler_sequence (try_block);
2077 330 : finish_compound_stmt (compound_stmt);
2078 330 : }
2079 :
2080 : /* Begin a handler. Returns a HANDLER if appropriate. */
2081 :
2082 : tree
2083 1575921 : begin_handler (void)
2084 : {
2085 1575921 : tree r;
2086 :
2087 1575921 : r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
2088 1575921 : add_stmt (r);
2089 :
2090 : /* Create a binding level for the eh_info and the exception object
2091 : cleanup. */
2092 1575921 : HANDLER_BODY (r) = do_pushlevel (sk_catch);
2093 :
2094 1575921 : 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 1575921 : finish_handler_parms (tree decl, tree handler)
2103 : {
2104 1575921 : tree type = NULL_TREE;
2105 1575921 : if (processing_template_decl)
2106 : {
2107 1437947 : if (decl)
2108 : {
2109 468325 : decl = pushdecl (decl);
2110 468325 : decl = push_template_decl (decl);
2111 468325 : HANDLER_PARMS (handler) = decl;
2112 468325 : type = TREE_TYPE (decl);
2113 : }
2114 : }
2115 : else
2116 : {
2117 137974 : type = expand_start_catch_block (decl);
2118 137974 : if (warn_catch_value
2119 2118 : && type != NULL_TREE
2120 711 : && type != error_mark_node
2121 138685 : && !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 1575921 : HANDLER_TYPE (handler) = type;
2143 1575921 : }
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 1575921 : finish_handler (tree handler)
2150 : {
2151 1575921 : if (!processing_template_decl)
2152 137974 : expand_end_catch_block ();
2153 1575921 : HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
2154 1575921 : }
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 275172854 : begin_compound_stmt (unsigned int flags)
2165 : {
2166 275172854 : tree r;
2167 :
2168 275172854 : if (flags & BCS_NO_SCOPE)
2169 : {
2170 5104794 : r = push_stmt_list ();
2171 5104794 : 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 5104794 : keep_next_level (false);
2178 : }
2179 : else
2180 : {
2181 270068060 : scope_kind sk = sk_block;
2182 270068060 : if (flags & BCS_TRY_BLOCK)
2183 : sk = sk_try;
2184 268937524 : else if (flags & BCS_TRANSACTION)
2185 : sk = sk_transaction;
2186 268937289 : else if (flags & BCS_STMT_EXPR)
2187 29082 : sk = sk_stmt_expr;
2188 270068060 : 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 275172854 : if (processing_template_decl)
2198 : {
2199 185118565 : r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
2200 185118565 : BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
2201 185118565 : BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
2202 185118565 : TREE_SIDE_EFFECTS (r) = 1;
2203 : }
2204 :
2205 275172854 : return r;
2206 : }
2207 :
2208 : /* Finish a compound-statement, which is given by STMT. */
2209 :
2210 : void
2211 275172815 : finish_compound_stmt (tree stmt)
2212 : {
2213 275172815 : if (TREE_CODE (stmt) == BIND_EXPR)
2214 : {
2215 185118565 : 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 185118565 : if (TREE_CODE (body) == STATEMENT_LIST
2220 169347632 : && STATEMENT_LIST_HEAD (body) == NULL
2221 11304198 : && !BIND_EXPR_BODY_BLOCK (stmt)
2222 195924401 : && !BIND_EXPR_TRY_BLOCK (stmt))
2223 : stmt = body;
2224 : else
2225 174312826 : BIND_EXPR_BODY (stmt) = body;
2226 : }
2227 90054250 : else if (STATEMENT_LIST_NO_SCOPE (stmt))
2228 5068506 : stmt = pop_stmt_list (stmt);
2229 : else
2230 : {
2231 : /* Destroy any ObjC "super" receivers that may have been
2232 : created. */
2233 84985744 : objc_clear_super_receiver ();
2234 :
2235 84985744 : stmt = do_poplevel (stmt);
2236 : }
2237 :
2238 : /* ??? See c_end_compound_stmt wrt statement expressions. */
2239 275172815 : add_stmt (stmt);
2240 275172815 : }
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 53790 : finish_asm_string_expression (location_t loc, tree string)
2248 : {
2249 53790 : if (string == error_mark_node
2250 53777 : || 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 25883 : 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 25883 : tree r;
2277 25883 : tree t;
2278 25883 : int ninputs = list_length (input_operands);
2279 25883 : int noutputs = list_length (output_operands);
2280 :
2281 25883 : if (!processing_template_decl)
2282 : {
2283 12366 : const char *constraint;
2284 12366 : const char **oconstraints;
2285 12366 : bool allows_mem, allows_reg, is_inout;
2286 12366 : tree operand;
2287 12366 : int i;
2288 :
2289 12366 : oconstraints = XALLOCAVEC (const char *, noutputs);
2290 :
2291 24630 : string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
2292 : string);
2293 12366 : if (string == error_mark_node)
2294 109 : return error_mark_node;
2295 36816 : for (int i = 0; i < 2; ++i)
2296 84459 : for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
2297 : {
2298 35371 : tree s = TREE_VALUE (TREE_PURPOSE (t));
2299 70724 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2300 35371 : if (s == error_mark_node)
2301 : return error_mark_node;
2302 35341 : TREE_VALUE (TREE_PURPOSE (t)) = s;
2303 : }
2304 17710 : for (t = clobbers; t; t = TREE_CHAIN (t))
2305 : {
2306 5453 : tree s = TREE_VALUE (t);
2307 10900 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2308 5453 : TREE_VALUE (t) = s;
2309 : }
2310 :
2311 12257 : string = resolve_asm_operand_names (string, output_operands,
2312 : input_operands, labels);
2313 :
2314 30706 : for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
2315 : {
2316 18449 : 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 18449 : STRIP_NOPS (operand);
2325 :
2326 18449 : operand = mark_lvalue_use (operand);
2327 :
2328 18449 : if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
2329 9 : operand = error_mark_node;
2330 :
2331 18449 : if (operand != error_mark_node
2332 18449 : && (TREE_READONLY (operand)
2333 18434 : || CP_TYPE_CONST_P (TREE_TYPE (operand))
2334 : /* Functions are not modifiable, even though they are
2335 : lvalues. */
2336 18434 : || 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 18434 : || (CLASS_TYPE_P (TREE_TYPE (operand))
2340 150 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
2341 6 : cxx_readonly_error (loc, operand, lv_asm);
2342 :
2343 : tree *op = &operand;
2344 18456 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2345 7 : op = &TREE_OPERAND (*op, 1);
2346 18449 : 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 18449 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2359 18449 : oconstraints[i] = constraint;
2360 :
2361 18449 : 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 18440 : if (!allows_reg && !cxx_mark_addressable (*op))
2368 0 : operand = error_mark_node;
2369 18440 : 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 439 : 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 18428 : 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 18449 : TREE_VALUE (t) = operand;
2415 : }
2416 :
2417 29144 : for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
2418 : {
2419 16887 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2420 16887 : bool constraint_parsed
2421 16887 : = 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 16887 : if (constraint_parsed && !allows_reg && allows_mem)
2427 306 : operand = mark_lvalue_use (TREE_VALUE (t));
2428 : else
2429 16581 : 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 16887 : 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 16887 : if (constraint_parsed)
2444 : {
2445 : /* If the operand is going to end up in memory,
2446 : mark it addressable. */
2447 16866 : 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 306 : STRIP_NOPS (operand);
2452 :
2453 306 : tree *op = &operand;
2454 313 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2455 7 : op = &TREE_OPERAND (*op, 1);
2456 306 : 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 306 : if (!cxx_mark_addressable (*op))
2469 0 : operand = error_mark_node;
2470 : }
2471 16560 : else if (!allows_reg && !allows_mem)
2472 : {
2473 : /* If constraint allows neither register nor memory,
2474 : try harder to get a constant. */
2475 474 : tree constop = maybe_constant_value (operand);
2476 474 : if (TREE_CONSTANT (constop))
2477 447 : operand = constop;
2478 : }
2479 16866 : 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 16866 : 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 16887 : 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 16770 : 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 16887 : TREE_VALUE (t) = operand;
2551 : }
2552 : }
2553 :
2554 25774 : r = build_stmt (loc, ASM_EXPR, string,
2555 : output_operands, input_operands,
2556 : clobbers, labels);
2557 25774 : ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
2558 25774 : ASM_INLINE_P (r) = inline_p;
2559 25774 : if (toplev_p)
2560 : {
2561 99 : symtab->finalize_toplevel_asm (r);
2562 99 : return r;
2563 : }
2564 25675 : r = maybe_cleanup_point_expr_void (r);
2565 25675 : return add_stmt (r);
2566 : }
2567 :
2568 : /* Finish a label with the indicated NAME. Returns the new label. */
2569 :
2570 : tree
2571 2478 : finish_label_stmt (tree name)
2572 : {
2573 2478 : tree decl = define_label (input_location, name);
2574 :
2575 2478 : if (decl == error_mark_node)
2576 : return error_mark_node;
2577 :
2578 2472 : add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
2579 :
2580 2472 : 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 3350989 : finish_decl_cleanup (tree decl, tree cleanup)
2603 : {
2604 3350989 : push_cleanup (decl, cleanup, false);
2605 3350989 : }
2606 :
2607 : /* If the current scope exits with an exception, run CLEANUP. */
2608 :
2609 : void
2610 2146227 : finish_eh_cleanup (tree cleanup)
2611 : {
2612 2146227 : push_cleanup (NULL, cleanup, true);
2613 2146227 : }
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 19759524 : 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 19759524 : mem_inits = nreverse (mem_inits);
2625 :
2626 19759524 : if (processing_template_decl)
2627 : {
2628 : tree mem;
2629 :
2630 33487352 : 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 19838703 : if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
2638 19838703 : && check_for_bare_parameter_packs (TREE_VALUE (mem)))
2639 3 : TREE_VALUE (mem) = error_mark_node;
2640 : }
2641 :
2642 13648649 : add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
2643 : CTOR_INITIALIZER, mem_inits));
2644 : }
2645 : else
2646 6110875 : emit_mem_initializers (mem_inits);
2647 19759524 : }
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 44115712 : force_paren_expr (tree expr, bool even_uneval /* = false */)
2655 : {
2656 : /* This is only needed for decltype(auto) in C++14. */
2657 44115712 : 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 43483414 : if (cp_unevaluated_operand && !even_uneval)
2663 : return expr;
2664 :
2665 36292792 : if (TREE_CODE (expr) == COMPONENT_REF
2666 36235700 : || TREE_CODE (expr) == SCOPE_REF
2667 72522492 : || REFERENCE_REF_P (expr))
2668 649202 : REF_PARENTHESIZED_P (expr) = true;
2669 35643590 : else if (DECL_P (tree_strip_any_location_wrapper (expr)))
2670 : {
2671 1703226 : location_t loc = cp_expr_location (expr);
2672 1703226 : const tree_code code = processing_template_decl ? PAREN_EXPR
2673 : : VIEW_CONVERT_EXPR;
2674 1703226 : expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
2675 1703226 : 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 939879089 : maybe_undo_parenthesized_ref (tree t)
2686 : {
2687 939879089 : if (cxx_dialect < cxx14)
2688 : return t;
2689 :
2690 929972730 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
2691 1032399779 : && REF_PARENTHESIZED_P (t))
2692 191564 : t = TREE_OPERAND (t, 0);
2693 :
2694 : return t;
2695 : }
2696 :
2697 : /* Finish a parenthesized expression EXPR. */
2698 :
2699 : cp_expr
2700 32371246 : finish_parenthesized_expr (cp_expr expr)
2701 : {
2702 32371246 : if (EXPR_P (expr))
2703 : {
2704 : /* This inhibits warnings in maybe_warn_unparenthesized_assignment
2705 : and c_common_truthvalue_conversion. */
2706 64455790 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
2707 : /* And maybe_warn_sizeof_array_div. */
2708 64455790 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
2709 : }
2710 :
2711 32371246 : if (TREE_CODE (expr) == OFFSET_REF
2712 32371246 : || 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 28952 : PTRMEM_OK_P (expr) = 0;
2716 :
2717 32371246 : tree stripped_expr = tree_strip_any_location_wrapper (expr);
2718 32371246 : if (TREE_CODE (stripped_expr) == STRING_CST)
2719 842984 : PAREN_STRING_LITERAL_P (stripped_expr) = 1;
2720 31528262 : else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
2721 914 : PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
2722 :
2723 32371246 : expr = cp_expr (force_paren_expr (expr), expr.get_location ());
2724 :
2725 32371246 : 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 74663422 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
2733 : tsubst_flags_t complain /* = tf_warning_or_error */)
2734 : {
2735 74663422 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
2736 74663422 : bool try_omp_private = !object && omp_private_member_map;
2737 65386627 : tree ret;
2738 :
2739 65386627 : if (!object)
2740 : {
2741 65386627 : tree scope = qualifying_scope;
2742 65386627 : if (scope == NULL_TREE)
2743 : {
2744 65375498 : scope = context_for_name_lookup (decl);
2745 65375498 : 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 65386624 : object = maybe_dummy_object (scope, NULL);
2753 : }
2754 :
2755 74663419 : object = maybe_resolve_dummy (object, true);
2756 74663419 : 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 74663416 : if (is_dummy_object (object)
2762 30841 : && !cp_unevaluated_operand
2763 74663514 : && (!processing_template_decl || !current_class_ref))
2764 : {
2765 83 : if (complain & tf_error)
2766 : {
2767 73 : auto_diagnostic_group d;
2768 73 : if (current_function_decl
2769 73 : && DECL_STATIC_FUNCTION_P (current_function_decl))
2770 3 : error ("invalid use of member %qD in static member function", decl);
2771 70 : else if (current_function_decl
2772 63 : && processing_contract_condition
2773 70 : && DECL_CONSTRUCTOR_P (current_function_decl))
2774 0 : error ("invalid use of member %qD in constructor %<pre%> contract", decl);
2775 70 : else if (current_function_decl
2776 63 : && processing_contract_condition
2777 70 : && DECL_DESTRUCTOR_P (current_function_decl))
2778 0 : error ("invalid use of member %qD in destructor %<post%> contract", decl);
2779 : else
2780 70 : error ("invalid use of non-static data member %qD", decl);
2781 73 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
2782 73 : }
2783 :
2784 83 : return error_mark_node;
2785 : }
2786 :
2787 74663333 : if (current_class_ptr)
2788 74397347 : TREE_USED (current_class_ptr) = 1;
2789 74663333 : if (processing_template_decl)
2790 : {
2791 59645314 : tree type = TREE_TYPE (decl);
2792 :
2793 59645314 : if (TYPE_REF_P (type))
2794 : /* Quals on the object don't matter. */;
2795 57430026 : else if (PACK_EXPANSION_P (type))
2796 : /* Don't bother trying to represent this. */
2797 : type = NULL_TREE;
2798 57427622 : 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 57425319 : int quals = cp_type_quals (TREE_TYPE (object));
2812 :
2813 57425319 : if (DECL_MUTABLE_P (decl))
2814 233925 : quals &= ~TYPE_QUAL_CONST;
2815 :
2816 57425319 : quals |= cp_type_quals (TREE_TYPE (decl));
2817 57425319 : type = cp_build_qualified_type (type, quals);
2818 : }
2819 :
2820 59645314 : if (qualifying_scope)
2821 : /* Wrap this in a SCOPE_REF for now. */
2822 9159 : ret = build_qualified_name (type, qualifying_scope, decl,
2823 : /*template_p=*/false);
2824 : else
2825 59636155 : ret = (convert_from_reference
2826 59636155 : (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 15018019 : tree access_type = TREE_TYPE (object);
2833 :
2834 15018019 : 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 15018019 : if (qualifying_scope)
2841 : {
2842 1930 : tree binfo = NULL_TREE;
2843 1930 : object = build_scoped_ref (object, qualifying_scope,
2844 : &binfo);
2845 : }
2846 :
2847 15018019 : ret = build_class_member_access_expr (object, decl,
2848 : /*access_path=*/NULL_TREE,
2849 : /*preserve_reference=*/false,
2850 : complain);
2851 : }
2852 74663333 : 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 4685399434 : 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 4685399434 : if (deferred_access_no_check)
2876 : return true;
2877 :
2878 : /* Determine the SCOPE of DECL. */
2879 4677557414 : tree scope = context_for_name_lookup (decl);
2880 : /* If the SCOPE is not a type, then DECL is not a member. */
2881 4677557414 : 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 4677557414 : || dependent_type_p (scope))
2886 4231245532 : return true;
2887 :
2888 446311882 : tree qualifying_type = NULL_TREE;
2889 : /* Compute the scope through which DECL is being accessed. */
2890 446311882 : 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 94386 : && CLASS_TYPE_P (object_type)
2900 446406251 : && 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 94360 : if (tree open = currently_open_class (object_type))
2905 : qualifying_type = open;
2906 : else
2907 : qualifying_type = object_type;
2908 : }
2909 446217522 : 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 590007759 : if (DECL_NONSTATIC_MEMBER_P (decl)
2915 295053685 : && current_class_ptr)
2916 39888 : if (tree current = current_nonlambda_class_type ())
2917 : {
2918 39865 : 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 3565 : 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 151213641 : qualifying_type = currently_open_derived_class (scope);
2938 :
2939 446218024 : 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 446275582 : && CLASS_TYPE_P (qualifying_type))
2943 420133949 : return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2944 420133949 : 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 82545607 : 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 82545607 : gcc_assert (TYPE_P (qualifying_class));
2967 :
2968 82545607 : if (error_operand_p (expr))
2969 21 : return error_mark_node;
2970 :
2971 82545586 : if (DECL_P (expr)
2972 : /* Functions are marked after overload resolution; avoid redundant
2973 : warnings. */
2974 75723120 : && TREE_CODE (expr) != FUNCTION_DECL
2975 158268682 : && !mark_used (expr, complain))
2976 0 : return error_mark_node;
2977 :
2978 82545586 : if (template_p)
2979 : {
2980 242035 : 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 242026 : 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 82545586 : if (address_p && done
2994 155441 : && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
2995 : {
2996 155439 : if (TREE_CODE (expr) == SCOPE_REF)
2997 0 : expr = TREE_OPERAND (expr, 1);
2998 155439 : expr = build_offset_ref (qualifying_class, expr,
2999 : /*address_p=*/true, complain);
3000 155439 : return expr;
3001 : }
3002 :
3003 : /* No need to check access within an enum. */
3004 82390147 : if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
3005 3414424 : && 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 78975726 : 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 78973086 : else if (TREE_CODE (expr) == FIELD_DECL)
3015 : {
3016 11129 : push_deferring_access_checks (dk_no_check);
3017 11129 : expr = finish_non_static_data_member (expr, NULL_TREE,
3018 : qualifying_class, complain);
3019 11129 : pop_deferring_access_checks ();
3020 : }
3021 78961957 : 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 6372362 : if (!shared_member_p (expr)
3026 395270 : && current_class_ptr
3027 6766992 : && DERIVED_FROM_P (qualifying_class,
3028 : current_nonlambda_class_type ()))
3029 394410 : expr = (build_class_member_access_expr
3030 394410 : (maybe_dummy_object (qualifying_class, NULL),
3031 : expr,
3032 394410 : BASELINK_ACCESS_BINFO (expr),
3033 : /*preserve_reference=*/false,
3034 : complain));
3035 5977952 : else if (done)
3036 : /* The expression is a qualified name whose address is not
3037 : being taken. */
3038 2470 : expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
3039 : complain);
3040 : }
3041 72589595 : else if (!template_p
3042 72395036 : && TREE_CODE (expr) == TEMPLATE_DECL
3043 72589675 : && !DECL_FUNCTION_TEMPLATE_P (expr))
3044 : {
3045 80 : if (complain & tf_error)
3046 4 : error ("%qE missing template arguments", expr);
3047 80 : 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 72589515 : if (processing_template_decl
3057 72589515 : && (!currently_open_class (qualifying_class)
3058 9912 : || TREE_CODE (expr) == IDENTIFIER_NODE
3059 9912 : || TREE_CODE (expr) == TEMPLATE_ID_EXPR
3060 82 : || TREE_CODE (expr) == BIT_NOT_EXPR))
3061 10588357 : expr = build_qualified_name (TREE_TYPE (expr),
3062 : qualifying_class, expr,
3063 : template_p);
3064 62001158 : else if (tree wrap = maybe_get_tls_wrapper_call (expr))
3065 9 : expr = wrap;
3066 :
3067 72589515 : 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 5126494 : begin_stmt_expr (void)
3078 : {
3079 5126494 : 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 29663 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
3089 : {
3090 29663 : 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 29660 : if (expr)
3101 : {
3102 29645 : tree type = TREE_TYPE (expr);
3103 :
3104 29645 : 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 29630 : 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 29461 : 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 29430 : expr = force_rvalue (expr, tf_warning_or_error);
3131 29430 : if (error_operand_p (expr))
3132 0 : return error_mark_node;
3133 :
3134 : /* Update for array-to-pointer decay. */
3135 29430 : type = TREE_TYPE (expr);
3136 :
3137 : /* This TARGET_EXPR will initialize the outer one added by
3138 : finish_stmt_expr. */
3139 29430 : 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 29430 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
3145 29430 : expr = maybe_cleanup_point_expr (expr);
3146 29430 : add_stmt (expr);
3147 : }
3148 :
3149 : /* The type of the statement-expression is the type of the last
3150 : expression. */
3151 29630 : 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 5126494 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
3163 : {
3164 5126494 : tree type;
3165 5126494 : tree result;
3166 :
3167 5126494 : if (error_operand_p (stmt_expr))
3168 : {
3169 18 : pop_stmt_list (stmt_expr);
3170 18 : return error_mark_node;
3171 : }
3172 :
3173 5126476 : gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
3174 :
3175 5126476 : type = TREE_TYPE (stmt_expr);
3176 5126476 : result = pop_stmt_list (stmt_expr);
3177 5126476 : TREE_TYPE (result) = type;
3178 :
3179 5126476 : if (processing_template_decl)
3180 : {
3181 36481 : result = build_min (STMT_EXPR, type, result);
3182 36481 : TREE_SIDE_EFFECTS (result) = 1;
3183 36481 : STMT_EXPR_NO_SCOPE (result) = has_no_scope;
3184 : }
3185 5089995 : 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 59648181 : empty_expr_stmt_p (tree expr_stmt)
3221 : {
3222 59648185 : tree body = NULL_TREE;
3223 :
3224 59648185 : if (expr_stmt == void_node)
3225 : return true;
3226 :
3227 59648182 : if (expr_stmt)
3228 : {
3229 59648182 : if (TREE_CODE (expr_stmt) == EXPR_STMT)
3230 4 : body = EXPR_STMT_EXPR (expr_stmt);
3231 59648178 : else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
3232 : body = expr_stmt;
3233 : }
3234 :
3235 4 : if (body)
3236 : {
3237 58749681 : if (TREE_CODE (body) == STATEMENT_LIST)
3238 58749677 : 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 18216942 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
3251 : tsubst_flags_t complain)
3252 : {
3253 18216942 : tree identifier = NULL_TREE;
3254 18216942 : tree functions = NULL_TREE;
3255 18216942 : tree tmpl_args = NULL_TREE;
3256 18216942 : bool template_id = false;
3257 18216942 : location_t loc = fn_expr.get_location ();
3258 18216942 : tree fn = fn_expr.get_value ();
3259 :
3260 18216942 : STRIP_ANY_LOCATION_WRAPPER (fn);
3261 :
3262 18216942 : if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
3263 : {
3264 : /* Use a separate flag to handle null args. */
3265 3577258 : template_id = true;
3266 3577258 : tmpl_args = TREE_OPERAND (fn, 1);
3267 3577258 : fn = TREE_OPERAND (fn, 0);
3268 : }
3269 :
3270 : /* Find the name of the overloaded function. */
3271 18216942 : if (identifier_p (fn))
3272 : identifier = fn;
3273 : else
3274 : {
3275 25841779 : functions = fn;
3276 18032605 : 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 18216942 : if (!any_type_dependent_arguments_p (args)
3284 18216942 : && !any_dependent_template_arguments_p (tmpl_args))
3285 : {
3286 17323079 : fn = lookup_arg_dependent (identifier, functions, args);
3287 17323079 : if (!fn)
3288 : {
3289 : /* The unqualified name could not be resolved. */
3290 56963 : if (complain & tf_error)
3291 390 : fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
3292 : else
3293 : fn = identifier;
3294 : }
3295 : }
3296 :
3297 18216942 : if (fn && template_id && fn != error_mark_node)
3298 3577245 : fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
3299 :
3300 18216942 : return cp_expr (fn, loc);
3301 : }
3302 :
3303 : /* Generate an expression for `FN (ARGS)'. This may change the
3304 : contents of ARGS.
3305 :
3306 : If DISALLOW_VIRTUAL is true, the call to FN will be not generated
3307 : as a virtual call, even if FN is virtual. (This flag is set when
3308 : encountering an expression where the function name is explicitly
3309 : qualified. For example a call to `X::f' never generates a virtual
3310 : call.)
3311 :
3312 : Returns code for the call. */
3313 :
3314 : tree
3315 344527323 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
3316 : bool koenig_p, tsubst_flags_t complain)
3317 : {
3318 344527323 : tree result;
3319 344527323 : tree orig_fn;
3320 344527323 : vec<tree, va_gc> *orig_args = *args;
3321 344527323 : tsubst_flags_t orig_complain = complain;
3322 :
3323 344527323 : if (fn == error_mark_node)
3324 : return error_mark_node;
3325 :
3326 344526308 : complain &= ~tf_any_viable;
3327 344526308 : gcc_assert (!TYPE_P (fn));
3328 :
3329 : /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
3330 : it so that we can tell this is a call to a known function. */
3331 344526308 : fn = maybe_undo_parenthesized_ref (fn);
3332 :
3333 344526308 : STRIP_ANY_LOCATION_WRAPPER (fn);
3334 :
3335 344526308 : orig_fn = fn;
3336 :
3337 344526308 : if (concept_check_p (fn))
3338 : {
3339 6 : error_at (EXPR_LOC_OR_LOC (fn, input_location),
3340 : "cannot call a concept as a function");
3341 6 : return error_mark_node;
3342 : }
3343 :
3344 344526302 : if (processing_template_decl)
3345 : {
3346 : /* If FN is a local extern declaration (or set thereof) in a template,
3347 : look it up again at instantiation time. */
3348 227183978 : if (is_overloaded_fn (fn))
3349 : {
3350 139321438 : tree ifn = get_first_fn (fn);
3351 139321438 : if (TREE_CODE (ifn) == FUNCTION_DECL
3352 139321438 : && dependent_local_decl_p (ifn))
3353 38951 : orig_fn = DECL_NAME (ifn);
3354 : }
3355 :
3356 : /* If the call expression is dependent, build a CALL_EXPR node
3357 : with no type; type_dependent_expression_p recognizes
3358 : expressions with no type as being dependent. */
3359 227183978 : if (type_dependent_expression_p (fn)
3360 227183978 : || any_type_dependent_arguments_p (*args))
3361 : {
3362 205813600 : if (koenig_p
3363 10204884 : && TREE_CODE (orig_fn) == FUNCTION_DECL
3364 208968843 : && !fndecl_built_in_p (orig_fn))
3365 : /* For an ADL-enabled call where unqualified lookup found a
3366 : single non-template function, wrap it in an OVERLOAD so that
3367 : later substitution doesn't overeagerly mark the function as
3368 : used. */
3369 826322 : orig_fn = ovl_make (orig_fn, NULL_TREE);
3370 205813600 : result = build_min_nt_call_vec (orig_fn, *args);
3371 279634970 : SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
3372 205813600 : KOENIG_LOOKUP_P (result) = koenig_p;
3373 : /* Disable the std::move warnings since this call was dependent
3374 : (c++/89780, c++/107363). This also suppresses the
3375 : -Wredundant-move warning. */
3376 205813600 : suppress_warning (result, OPT_Wpessimizing_move);
3377 :
3378 205813600 : if (cfun && cp_function_chain && !cp_unevaluated_operand)
3379 : {
3380 179548895 : bool abnormal = true;
3381 179768534 : for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
3382 : {
3383 99503235 : tree fndecl = STRIP_TEMPLATE (*iter);
3384 99503235 : if (TREE_CODE (fndecl) != FUNCTION_DECL
3385 99503157 : || !TREE_THIS_VOLATILE (fndecl))
3386 : {
3387 : abnormal = false;
3388 : break;
3389 : }
3390 : }
3391 : /* FIXME: Stop warning about falling off end of non-void
3392 : function. But this is wrong. Even if we only see
3393 : no-return fns at this point, we could select a
3394 : future-defined return fn during instantiation. Or
3395 : vice-versa. */
3396 179548895 : if (abnormal)
3397 80265299 : current_function_returns_abnormally = 1;
3398 : }
3399 205813600 : if (TREE_CODE (fn) == COMPONENT_REF)
3400 95564335 : maybe_generic_this_capture (TREE_OPERAND (fn, 0),
3401 95564335 : TREE_OPERAND (fn, 1));
3402 205813600 : return result;
3403 : }
3404 21370378 : orig_args = make_tree_vector_copy (*args);
3405 : }
3406 :
3407 138712702 : if (TREE_CODE (fn) == COMPONENT_REF)
3408 : {
3409 28291053 : tree member = TREE_OPERAND (fn, 1);
3410 28291053 : if (BASELINK_P (member))
3411 : {
3412 28110889 : tree object = TREE_OPERAND (fn, 0);
3413 55861443 : return build_new_method_call (object, member,
3414 : args, NULL_TREE,
3415 : (disallow_virtual
3416 : ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
3417 : : LOOKUP_NORMAL),
3418 : /*fn_p=*/NULL,
3419 28110889 : complain);
3420 : }
3421 : }
3422 :
3423 : /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
3424 110601813 : if (TREE_CODE (fn) == ADDR_EXPR
3425 110601813 : && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
3426 9 : fn = TREE_OPERAND (fn, 0);
3427 :
3428 110601813 : if (is_overloaded_fn (fn))
3429 102338933 : fn = baselink_for_fns (fn);
3430 :
3431 110601813 : result = NULL_TREE;
3432 110601813 : if (BASELINK_P (fn))
3433 : {
3434 13343009 : tree object;
3435 :
3436 : /* A call to a member function. From [over.call.func]:
3437 :
3438 : If the keyword this is in scope and refers to the class of
3439 : that member function, or a derived class thereof, then the
3440 : function call is transformed into a qualified function call
3441 : using (*this) as the postfix-expression to the left of the
3442 : . operator.... [Otherwise] a contrived object of type T
3443 : becomes the implied object argument.
3444 :
3445 : In this situation:
3446 :
3447 : struct A { void f(); };
3448 : struct B : public A {};
3449 : struct C : public A { void g() { B::f(); }};
3450 :
3451 : "the class of that member function" refers to `A'. But 11.2
3452 : [class.access.base] says that we need to convert 'this' to B* as
3453 : part of the access, so we pass 'B' to maybe_dummy_object. */
3454 :
3455 13343009 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
3456 : {
3457 : /* A constructor call always uses a dummy object. (This constructor
3458 : call which has the form A::A () is actually invalid and we are
3459 : going to reject it later in build_new_method_call.) */
3460 39 : object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
3461 : }
3462 : else
3463 13342970 : object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
3464 : NULL);
3465 :
3466 15207783 : result = build_new_method_call (object, fn, args, NULL_TREE,
3467 : (disallow_virtual
3468 : ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
3469 : : LOOKUP_NORMAL),
3470 : /*fn_p=*/NULL,
3471 : complain);
3472 : }
3473 97258804 : else if (is_overloaded_fn (fn))
3474 : {
3475 : /* If the function is an overloaded builtin, resolve it. */
3476 88995924 : if (TREE_CODE (fn) == FUNCTION_DECL
3477 88995924 : && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
3478 17959002 : || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
3479 8921890 : result = resolve_overloaded_builtin (input_location, fn, *args,
3480 : complain & tf_error);
3481 :
3482 8921890 : if (!result)
3483 : {
3484 88662363 : tree alloc_size_attr = NULL_TREE;
3485 88662363 : if (warn_calloc_transposed_args
3486 685982 : && TREE_CODE (fn) == FUNCTION_DECL
3487 88662363 : && (alloc_size_attr
3488 430694 : = lookup_attribute ("alloc_size",
3489 430694 : TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
3490 3353 : if (TREE_VALUE (alloc_size_attr) == NULL_TREE
3491 3353 : || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
3492 : alloc_size_attr = NULL_TREE;
3493 86976064 : if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
3494 1686359 : && (complain & tf_warning)
3495 1492632 : && !vec_safe_is_empty (*args)
3496 89810507 : && !processing_template_decl)
3497 : {
3498 : location_t sizeof_arg_loc[6];
3499 : tree sizeof_arg[6];
3500 : unsigned int i;
3501 8239228 : for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
3502 : {
3503 3089913 : tree t;
3504 :
3505 3089913 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
3506 3089913 : sizeof_arg[i] = NULL_TREE;
3507 3089913 : if (i >= (*args)->length ())
3508 649451 : continue;
3509 2440462 : t = (**args)[i];
3510 2440462 : if (TREE_CODE (t) != SIZEOF_EXPR)
3511 2433813 : continue;
3512 6649 : if (SIZEOF_EXPR_TYPE_P (t))
3513 2653 : sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
3514 : else
3515 3996 : sizeof_arg[i] = TREE_OPERAND (t, 0);
3516 6649 : sizeof_arg_loc[i] = EXPR_LOCATION (t);
3517 : }
3518 1029911 : if (warn_sizeof_pointer_memaccess)
3519 : {
3520 1029851 : auto same_p = same_type_ignoring_top_level_qualifiers_p;
3521 1029851 : sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
3522 : sizeof_arg, same_p);
3523 : }
3524 1029911 : if (alloc_size_attr)
3525 60 : warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
3526 : alloc_size_attr);
3527 : }
3528 :
3529 88662363 : if ((complain & tf_warning)
3530 52935110 : && TREE_CODE (fn) == FUNCTION_DECL
3531 25180392 : && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
3532 133048 : && vec_safe_length (*args) == 3
3533 88795411 : && !any_type_dependent_arguments_p (*args))
3534 : {
3535 133048 : tree arg0 = (*orig_args)[0];
3536 133048 : tree arg1 = (*orig_args)[1];
3537 133048 : tree arg2 = (*orig_args)[2];
3538 133048 : int literal_mask = ((literal_integer_zerop (arg1) << 1)
3539 133048 : | (literal_integer_zerop (arg2) << 2));
3540 133048 : warn_for_memset (input_location, arg0, arg2, literal_mask);
3541 : }
3542 :
3543 : /* A call to a namespace-scope function. */
3544 88662363 : result = build_new_function_call (fn, args, orig_complain);
3545 : }
3546 : }
3547 8262880 : else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
3548 : {
3549 150330 : if (!vec_safe_is_empty (*args))
3550 0 : error ("arguments to destructor are not allowed");
3551 : /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
3552 : which case the postfix-expression is a possibly-parenthesized class
3553 : member access), the function call destroys the object of scalar type
3554 : denoted by the object expression of the class member access. */
3555 150330 : tree ob = TREE_OPERAND (fn, 0);
3556 150330 : if (obvalue_p (ob))
3557 150312 : result = build_trivial_dtor_call (ob, true);
3558 : else
3559 : /* No location to clobber. */
3560 18 : result = convert_to_void (ob, ICV_STATEMENT, complain);
3561 : }
3562 8112550 : else if (CLASS_TYPE_P (TREE_TYPE (fn)))
3563 : /* If the "function" is really an object of class type, it might
3564 : have an overloaded `operator ()'. */
3565 2174872 : result = build_op_call (fn, args, complain);
3566 :
3567 104317056 : if (!result)
3568 : /* A call where the function is unknown. */
3569 5937678 : result = cp_build_function_call_vec (fn, args, complain);
3570 :
3571 110588295 : if (processing_template_decl && result != error_mark_node)
3572 : {
3573 15884403 : if (INDIRECT_REF_P (result))
3574 1135645 : result = TREE_OPERAND (result, 0);
3575 :
3576 : /* Prune all but the selected function from the original overload
3577 : set so that we can avoid some duplicate work at instantiation time. */
3578 15884403 : if (TREE_CODE (result) == CALL_EXPR
3579 15875012 : && really_overloaded_fn (orig_fn))
3580 : {
3581 5975266 : tree sel_fn = CALL_EXPR_FN (result);
3582 5975266 : if (TREE_CODE (sel_fn) == COMPONENT_REF)
3583 : {
3584 : /* The non-dependent result of build_new_method_call. */
3585 248630 : sel_fn = TREE_OPERAND (sel_fn, 1);
3586 248630 : gcc_assert (BASELINK_P (sel_fn));
3587 : }
3588 5726636 : else if (TREE_CODE (sel_fn) == ADDR_EXPR)
3589 : /* Our original callee wasn't wrapped in an ADDR_EXPR,
3590 : so strip this ADDR_EXPR added by build_over_call. */
3591 5726636 : sel_fn = TREE_OPERAND (sel_fn, 0);
3592 : orig_fn = sel_fn;
3593 : }
3594 :
3595 15884403 : tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
3596 15884403 : SET_EXPR_LOCATION (r, input_location);
3597 15884403 : KOENIG_LOOKUP_P (r) = koenig_p;
3598 15884403 : TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
3599 15884403 : release_tree_vector (orig_args);
3600 15884403 : result = convert_from_reference (r);
3601 : }
3602 :
3603 : return result;
3604 : }
3605 :
3606 : /* Finish a call to a postfix increment or decrement or EXPR. (Which
3607 : is indicated by CODE, which should be POSTINCREMENT_EXPR or
3608 : POSTDECREMENT_EXPR.) */
3609 :
3610 : cp_expr
3611 2560442 : finish_increment_expr (cp_expr expr, enum tree_code code)
3612 : {
3613 : /* input_location holds the location of the trailing operator token.
3614 : Build a location of the form:
3615 : expr++
3616 : ~~~~^~
3617 : with the caret at the operator token, ranging from the start
3618 : of EXPR to the end of the operator token. */
3619 2560442 : location_t combined_loc = make_location (input_location,
3620 : expr.get_start (),
3621 : get_finish (input_location));
3622 2560442 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3623 2560442 : NULL_TREE, tf_warning_or_error);
3624 : /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3625 2560442 : result.set_location (combined_loc);
3626 2560442 : return result;
3627 : }
3628 :
3629 : /* Finish a use of `this'. Returns an expression for `this'. */
3630 :
3631 : tree
3632 35079583 : finish_this_expr (void)
3633 : {
3634 35079583 : tree result = NULL_TREE;
3635 :
3636 70159052 : if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
3637 34803348 : result = current_class_ptr;
3638 552454 : else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
3639 276161 : result = (lambda_expr_this_capture
3640 276161 : (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
3641 : else
3642 74 : gcc_checking_assert (!current_class_ptr);
3643 :
3644 35079509 : if (result)
3645 : /* The keyword 'this' is a prvalue expression. */
3646 35079506 : return rvalue (result);
3647 :
3648 77 : tree fn = current_nonlambda_function ();
3649 77 : if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
3650 : {
3651 4 : auto_diagnostic_group d;
3652 4 : error ("%<this%> is unavailable for explicit object member "
3653 : "functions");
3654 4 : tree xobj_parm = DECL_ARGUMENTS (fn);
3655 4 : gcc_assert (xobj_parm);
3656 4 : tree parm_name = DECL_NAME (xobj_parm);
3657 :
3658 4 : static tree remembered_fn = NULL_TREE;
3659 : /* Only output this diagnostic once per function. */
3660 4 : if (remembered_fn == fn)
3661 : /* Early escape. */;
3662 4 : else if (parm_name)
3663 4 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3664 : "use explicit object parameter %qs instead",
3665 2 : IDENTIFIER_POINTER (parm_name));
3666 : else
3667 2 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3668 : "name the explicit object parameter");
3669 :
3670 4 : remembered_fn = fn;
3671 4 : }
3672 73 : else if (fn && DECL_STATIC_FUNCTION_P (fn))
3673 3 : error ("%<this%> is unavailable for static member functions");
3674 70 : else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
3675 0 : error ("invalid use of %<this%> in a constructor %<pre%> condition");
3676 70 : else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
3677 0 : error ("invalid use of %<this%> in a destructor %<post%> condition");
3678 70 : else if (fn)
3679 22 : error ("invalid use of %<this%> in non-member function");
3680 : else
3681 48 : error ("invalid use of %<this%> at top level");
3682 77 : return error_mark_node;
3683 : }
3684 :
3685 : /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3686 : expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3687 : the TYPE for the type given. If SCOPE is non-NULL, the expression
3688 : was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3689 :
3690 : tree
3691 150381 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
3692 : location_t loc, tsubst_flags_t complain)
3693 : {
3694 150381 : if (object == error_mark_node || destructor == error_mark_node)
3695 : return error_mark_node;
3696 :
3697 150372 : gcc_assert (TYPE_P (destructor));
3698 :
3699 150372 : if (!processing_template_decl)
3700 : {
3701 150351 : if (scope == error_mark_node)
3702 : {
3703 0 : if (complain & tf_error)
3704 0 : error_at (loc, "invalid qualifying scope in pseudo-destructor name");
3705 0 : return error_mark_node;
3706 : }
3707 150351 : if (is_auto (destructor))
3708 3 : destructor = TREE_TYPE (object);
3709 150351 : if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
3710 : {
3711 3 : if (complain & tf_error)
3712 3 : error_at (loc,
3713 : "qualified type %qT does not match destructor name ~%qT",
3714 : scope, destructor);
3715 3 : return error_mark_node;
3716 : }
3717 :
3718 :
3719 : /* [expr.pseudo] says both:
3720 :
3721 : The type designated by the pseudo-destructor-name shall be
3722 : the same as the object type.
3723 :
3724 : and:
3725 :
3726 : The cv-unqualified versions of the object type and of the
3727 : type designated by the pseudo-destructor-name shall be the
3728 : same type.
3729 :
3730 : We implement the more generous second sentence, since that is
3731 : what most other compilers do. */
3732 150348 : if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
3733 : destructor))
3734 : {
3735 12 : if (complain & tf_error)
3736 9 : error_at (loc, "%qE is not of type %qT", object, destructor);
3737 12 : return error_mark_node;
3738 : }
3739 : }
3740 :
3741 150357 : tree type = (type_dependent_expression_p (object)
3742 150357 : ? NULL_TREE : void_type_node);
3743 :
3744 150357 : return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
3745 150357 : scope, destructor);
3746 : }
3747 :
3748 : /* Finish an expression of the form CODE EXPR. */
3749 :
3750 : cp_expr
3751 37100571 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
3752 : tsubst_flags_t complain)
3753 : {
3754 : /* Build a location of the form:
3755 : ++expr
3756 : ^~~~~~
3757 : with the caret at the operator token, ranging from the start
3758 : of the operator token to the end of EXPR. */
3759 37100571 : location_t combined_loc = make_location (op_loc,
3760 : op_loc, expr.get_finish ());
3761 37100571 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3762 37100571 : NULL_TREE, complain);
3763 : /* TODO: build_x_unary_op doesn't always honor the location. */
3764 37100571 : result.set_location (combined_loc);
3765 :
3766 37100571 : if (result == error_mark_node)
3767 : return result;
3768 :
3769 37100104 : if (!(complain & tf_warning))
3770 : return result;
3771 :
3772 : /* These will never fold into a constant, so no need to check for
3773 : overflow for them. */
3774 37100104 : if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
3775 : return result;
3776 :
3777 19943484 : tree result_ovl = result;
3778 19943484 : tree expr_ovl = expr;
3779 :
3780 19943484 : if (!processing_template_decl)
3781 1760081 : expr_ovl = cp_fully_fold (expr_ovl);
3782 :
3783 19943484 : if (!CONSTANT_CLASS_P (expr_ovl)
3784 19943484 : || TREE_OVERFLOW_P (expr_ovl))
3785 : return result;
3786 :
3787 242791 : if (!processing_template_decl)
3788 233697 : result_ovl = cp_fully_fold (result_ovl);
3789 :
3790 242791 : if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
3791 9 : overflow_warning (combined_loc, result_ovl);
3792 :
3793 : return result;
3794 : }
3795 :
3796 : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3797 : elements. */
3798 :
3799 : static bool
3800 12 : maybe_zero_constructor_nelts (tree expr)
3801 : {
3802 12 : if (CONSTRUCTOR_NELTS (expr) == 0)
3803 : return true;
3804 12 : if (!processing_template_decl)
3805 : return false;
3806 30 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
3807 21 : if (!PACK_EXPANSION_P (elt.value))
3808 : return false;
3809 : return true;
3810 : }
3811 :
3812 : /* Finish a compound-literal expression or C++11 functional cast with aggregate
3813 : initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3814 : is being cast. */
3815 :
3816 : tree
3817 9327414 : finish_compound_literal (tree type, tree compound_literal,
3818 : tsubst_flags_t complain,
3819 : fcl_t fcl_context)
3820 : {
3821 9327414 : if (type == error_mark_node)
3822 : return error_mark_node;
3823 :
3824 9327362 : if (TYPE_REF_P (type))
3825 : {
3826 12 : compound_literal
3827 12 : = finish_compound_literal (TREE_TYPE (type), compound_literal,
3828 : complain, fcl_context);
3829 : /* The prvalue is then used to direct-initialize the reference. */
3830 12 : tree r = (perform_implicit_conversion_flags
3831 12 : (type, compound_literal, complain, LOOKUP_NORMAL));
3832 12 : return convert_from_reference (r);
3833 : }
3834 :
3835 9327350 : if (!TYPE_OBJ_P (type))
3836 : {
3837 : /* DR2351 */
3838 60 : if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
3839 : {
3840 12 : if (!processing_template_decl)
3841 9 : return void_node;
3842 3 : TREE_TYPE (compound_literal) = type;
3843 3 : TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
3844 3 : CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
3845 3 : return compound_literal;
3846 : }
3847 21 : else if (VOID_TYPE_P (type)
3848 15 : && processing_template_decl
3849 33 : && maybe_zero_constructor_nelts (compound_literal))
3850 : /* If there are only packs in compound_literal, it could
3851 : be void{} after pack expansion. */;
3852 : else
3853 : {
3854 12 : if (complain & tf_error)
3855 9 : error ("compound literal of non-object type %qT", type);
3856 12 : return error_mark_node;
3857 : }
3858 : }
3859 :
3860 9327326 : if (template_placeholder_p (type))
3861 : {
3862 176194 : type = do_auto_deduction (type, compound_literal, type, complain,
3863 : adc_variable_type);
3864 176194 : if (type == error_mark_node)
3865 : return error_mark_node;
3866 : }
3867 : /* C++23 auto{x}. */
3868 9151132 : else if (is_auto (type)
3869 109 : && !AUTO_IS_DECLTYPE (type)
3870 9151239 : && CONSTRUCTOR_NELTS (compound_literal) == 1)
3871 : {
3872 101 : if (is_constrained_auto (type))
3873 : {
3874 2 : if (complain & tf_error)
3875 2 : error ("%<auto{x}%> cannot be constrained");
3876 2 : return error_mark_node;
3877 : }
3878 99 : else if (cxx_dialect < cxx23)
3879 : {
3880 1 : if ((complain & tf_warning_or_error) == 0)
3881 0 : return error_mark_node;
3882 1 : pedwarn (input_location, OPT_Wc__23_extensions,
3883 : "%<auto{x}%> only available with "
3884 : "%<-std=c++23%> or %<-std=gnu++23%>");
3885 : }
3886 99 : type = do_auto_deduction (type, compound_literal, type, complain,
3887 : adc_variable_type);
3888 99 : if (type == error_mark_node)
3889 : return error_mark_node;
3890 : }
3891 :
3892 : /* Used to hold a copy of the compound literal in a template. */
3893 9327207 : tree orig_cl = NULL_TREE;
3894 :
3895 9327207 : if (processing_template_decl)
3896 : {
3897 4878304 : const bool dependent_p
3898 4878304 : = (instantiation_dependent_expression_p (compound_literal)
3899 4878304 : || dependent_type_p (type));
3900 1614337 : if (dependent_p)
3901 : /* We're about to return, no need to copy. */
3902 : orig_cl = compound_literal;
3903 : else
3904 : /* We're going to need a copy. */
3905 1614337 : orig_cl = unshare_constructor (compound_literal);
3906 4878304 : TREE_TYPE (orig_cl) = type;
3907 : /* Mark the expression as a compound literal. */
3908 4878304 : TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
3909 : /* And as instantiation-dependent. */
3910 4878304 : CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
3911 4878304 : if (fcl_context == fcl_c99)
3912 130 : CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
3913 : /* If the compound literal is dependent, we're done for now. */
3914 4878304 : if (dependent_p)
3915 : return orig_cl;
3916 : /* Otherwise, do go on to e.g. check narrowing. */
3917 : }
3918 :
3919 6063240 : type = complete_type (type);
3920 :
3921 6063240 : if (TYPE_NON_AGGREGATE_CLASS (type))
3922 : {
3923 : /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3924 : everywhere that deals with function arguments would be a pain, so
3925 : just wrap it in a TREE_LIST. The parser set a flag so we know
3926 : that it came from T{} rather than T({}). */
3927 1033228 : CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
3928 1033228 : compound_literal = build_tree_list (NULL_TREE, compound_literal);
3929 1033228 : return build_functional_cast (input_location, type,
3930 1033228 : compound_literal, complain);
3931 : }
3932 :
3933 5030012 : if (TREE_CODE (type) == ARRAY_TYPE
3934 5030012 : && check_array_initializer (NULL_TREE, type, compound_literal))
3935 9 : return error_mark_node;
3936 5030003 : compound_literal = reshape_init (type, compound_literal, complain);
3937 4844201 : if (SCALAR_TYPE_P (type)
3938 680527 : && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
3939 5239006 : && !check_narrowing (type, compound_literal, complain))
3940 102 : return error_mark_node;
3941 5029901 : if (TREE_CODE (type) == ARRAY_TYPE
3942 5029901 : && TYPE_DOMAIN (type) == NULL_TREE)
3943 : {
3944 1197 : cp_complete_array_type_or_error (&type, compound_literal,
3945 : false, complain);
3946 1197 : if (type == error_mark_node)
3947 : return error_mark_node;
3948 : }
3949 5029898 : compound_literal = digest_init_flags (type, compound_literal,
3950 : LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
3951 : complain);
3952 5029898 : if (compound_literal == error_mark_node)
3953 : return error_mark_node;
3954 :
3955 : /* If we're in a template, return the original compound literal. */
3956 5029300 : if (orig_cl)
3957 : return orig_cl;
3958 :
3959 3505624 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3960 : {
3961 2878012 : TREE_HAS_CONSTRUCTOR (compound_literal) = true;
3962 2878012 : if (fcl_context == fcl_c99)
3963 38209 : CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
3964 : }
3965 :
3966 : /* Put static/constant array temporaries in static variables. */
3967 : /* FIXME all C99 compound literals should be variables rather than C++
3968 : temporaries, unless they are used as an aggregate initializer. */
3969 4573739 : if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
3970 2443228 : && fcl_context == fcl_c99
3971 83 : && TREE_CODE (type) == ARRAY_TYPE
3972 31 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
3973 3505655 : && initializer_constant_valid_p (compound_literal, type))
3974 : {
3975 31 : tree decl = create_temporary_var (type);
3976 31 : DECL_CONTEXT (decl) = NULL_TREE;
3977 31 : DECL_INITIAL (decl) = compound_literal;
3978 31 : TREE_STATIC (decl) = 1;
3979 31 : if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
3980 : {
3981 : /* 5.19 says that a constant expression can include an
3982 : lvalue-rvalue conversion applied to "a glvalue of literal type
3983 : that refers to a non-volatile temporary object initialized
3984 : with a constant expression". Rather than try to communicate
3985 : that this VAR_DECL is a temporary, just mark it constexpr. */
3986 24 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
3987 24 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
3988 24 : TREE_CONSTANT (decl) = true;
3989 : }
3990 31 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
3991 31 : decl = pushdecl_top_level (decl);
3992 31 : DECL_NAME (decl) = make_anon_name ();
3993 31 : SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
3994 : /* Make sure the destructor is callable. */
3995 31 : tree clean = cxx_maybe_build_cleanup (decl, complain);
3996 31 : if (clean == error_mark_node)
3997 : return error_mark_node;
3998 31 : return decl;
3999 : }
4000 :
4001 : /* Represent other compound literals with TARGET_EXPR so we produce
4002 : a prvalue, and can elide copies. */
4003 3505593 : if (!VECTOR_TYPE_P (type)
4004 3466888 : && (TREE_CODE (compound_literal) == CONSTRUCTOR
4005 627606 : || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
4006 : {
4007 : /* The CONSTRUCTOR is now an initializer, not a compound literal. */
4008 2839282 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
4009 2839282 : TREE_HAS_CONSTRUCTOR (compound_literal) = false;
4010 2839282 : compound_literal = get_target_expr (compound_literal, complain);
4011 : }
4012 : else
4013 : /* For e.g. int{42} just make sure it's a prvalue. */
4014 666311 : compound_literal = rvalue (compound_literal);
4015 :
4016 : return compound_literal;
4017 : }
4018 :
4019 : /* Return the declaration for the function-name variable indicated by
4020 : ID. */
4021 :
4022 : tree
4023 237091 : finish_fname (tree id)
4024 : {
4025 237091 : tree decl = fname_decl (input_location, C_RID_CODE (id), id);
4026 : /* [expr.prim.lambda.closure]/16 "Unless the compound-statement is that
4027 : of a consteval-block-declaration, a variable __func__ is implicitly
4028 : defined...". We could be in a consteval block in a function, though,
4029 : and then we shouldn't warn. */
4030 237091 : if (current_function_decl
4031 237091 : && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
4032 4 : pedwarn (input_location, 0, "%qD is not defined outside of function scope",
4033 : decl);
4034 237091 : if (processing_template_decl && current_function_decl
4035 165569 : && decl != error_mark_node)
4036 165569 : decl = DECL_NAME (decl);
4037 237091 : return decl;
4038 : }
4039 :
4040 : /* Finish a translation unit. */
4041 :
4042 : void
4043 96888 : finish_translation_unit (void)
4044 : {
4045 : /* In case there were missing closebraces,
4046 : get us back to the global binding level. */
4047 96888 : pop_everything ();
4048 193776 : while (current_namespace != global_namespace)
4049 0 : pop_namespace ();
4050 :
4051 : /* Do file scope __FUNCTION__ et al. */
4052 96888 : finish_fname_decls ();
4053 :
4054 96888 : if (vec_safe_length (scope_chain->omp_declare_target_attribute))
4055 : {
4056 12 : cp_omp_declare_target_attr
4057 12 : a = scope_chain->omp_declare_target_attribute->pop ();
4058 12 : if (!errorcount)
4059 9 : error ("%qs without corresponding %qs",
4060 : a.device_type >= 0 ? "#pragma omp begin declare target"
4061 : : "#pragma omp declare target",
4062 : "#pragma omp end declare target");
4063 24 : vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
4064 : }
4065 96888 : if (vec_safe_length (scope_chain->omp_declare_variant_attribute))
4066 : {
4067 0 : if (!errorcount)
4068 0 : error ("%<omp begin declare variant%> without corresponding "
4069 : "%<omp end declare variant%>");
4070 0 : vec_safe_truncate (scope_chain->omp_declare_variant_attribute, 0);
4071 : }
4072 96888 : if (vec_safe_length (scope_chain->omp_begin_assumes))
4073 : {
4074 3 : if (!errorcount)
4075 3 : error ("%qs without corresponding %qs",
4076 : "#pragma omp begin assumes", "#pragma omp end assumes");
4077 3 : vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
4078 : }
4079 96888 : }
4080 :
4081 : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
4082 : Returns the parameter. */
4083 :
4084 : tree
4085 155000753 : finish_template_type_parm (tree aggr, tree identifier)
4086 : {
4087 155000753 : if (aggr != class_type_node)
4088 : {
4089 0 : permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
4090 0 : aggr = class_type_node;
4091 : }
4092 :
4093 155000753 : return build_tree_list (aggr, identifier);
4094 : }
4095 :
4096 : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
4097 : Returns the parameter. */
4098 :
4099 : tree
4100 386457 : finish_template_template_parm (tree aggr, tree identifier)
4101 : {
4102 386457 : tree decl = build_decl (input_location,
4103 : TYPE_DECL, identifier, NULL_TREE);
4104 :
4105 386457 : tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
4106 386457 : DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
4107 386457 : DECL_TEMPLATE_RESULT (tmpl) = decl;
4108 386457 : DECL_ARTIFICIAL (decl) = 1;
4109 :
4110 : /* Associate the constraints with the underlying declaration,
4111 : not the template. */
4112 386457 : tree constr = current_template_constraints ();
4113 386457 : set_constraints (decl, constr);
4114 :
4115 386457 : end_template_decl ();
4116 :
4117 386457 : gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
4118 :
4119 386457 : check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
4120 : /*is_primary=*/true, /*is_partial=*/false,
4121 : /*is_friend=*/0);
4122 :
4123 386457 : return finish_template_type_parm (aggr, tmpl);
4124 : }
4125 :
4126 : /* ARGUMENT is the default-argument value for a template template
4127 : parameter. If ARGUMENT is invalid, issue error messages and return
4128 : the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
4129 :
4130 : tree
4131 897 : check_template_template_default_arg (tree argument)
4132 : {
4133 897 : if (TREE_CODE (argument) != TEMPLATE_DECL
4134 : && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
4135 : && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
4136 : {
4137 : if (TREE_CODE (argument) == TYPE_DECL)
4138 : {
4139 18 : if (tree t = maybe_get_template_decl_from_type_decl (argument))
4140 18 : if (TREE_CODE (t) == TEMPLATE_DECL)
4141 : return t;
4142 15 : error ("invalid use of type %qT as a default value for a template "
4143 15 : "template-parameter", TREE_TYPE (argument));
4144 : }
4145 : else
4146 0 : error ("invalid default argument for a template template parameter");
4147 15 : return error_mark_node;
4148 : }
4149 :
4150 : return argument;
4151 : }
4152 :
4153 : /* Begin a class definition, as indicated by T. */
4154 :
4155 : tree
4156 29531286 : begin_class_definition (tree t)
4157 : {
4158 29531286 : if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
4159 33 : return error_mark_node;
4160 :
4161 29531384 : if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
4162 : {
4163 9 : error ("definition of %q#T inside template parameter list", t);
4164 9 : return error_mark_node;
4165 : }
4166 :
4167 : /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
4168 : are passed the same as decimal scalar types. */
4169 29531244 : if (TREE_CODE (t) == RECORD_TYPE
4170 29031139 : && !processing_template_decl)
4171 : {
4172 10368656 : tree ns = TYPE_CONTEXT (t);
4173 10368654 : if (ns && TREE_CODE (ns) == NAMESPACE_DECL
4174 8584069 : && DECL_CONTEXT (ns) == std_node
4175 2092721 : && DECL_NAME (ns)
4176 12461357 : && id_equal (DECL_NAME (ns), "decimal"))
4177 : {
4178 150 : const char *n = TYPE_NAME_STRING (t);
4179 150 : if ((strcmp (n, "decimal32") == 0)
4180 101 : || (strcmp (n, "decimal64") == 0)
4181 46 : || (strcmp (n, "decimal128") == 0))
4182 147 : TYPE_TRANSPARENT_AGGR (t) = 1;
4183 : }
4184 : }
4185 :
4186 : /* A non-implicit typename comes from code like:
4187 :
4188 : template <typename T> struct A {
4189 : template <typename U> struct A<T>::B ...
4190 :
4191 : This is erroneous. */
4192 19162588 : else if (TREE_CODE (t) == TYPENAME_TYPE)
4193 : {
4194 0 : error ("invalid definition of qualified type %qT", t);
4195 0 : t = error_mark_node;
4196 : }
4197 :
4198 29531244 : if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
4199 : {
4200 0 : t = make_class_type (RECORD_TYPE);
4201 0 : pushtag (make_anon_name (), t);
4202 : }
4203 :
4204 29531244 : if (TYPE_BEING_DEFINED (t))
4205 : {
4206 0 : t = make_class_type (TREE_CODE (t));
4207 0 : pushtag (TYPE_IDENTIFIER (t), t);
4208 : }
4209 :
4210 29531244 : maybe_process_partial_specialization (t);
4211 29531244 : pushclass (t);
4212 29531244 : TYPE_BEING_DEFINED (t) = 1;
4213 29531244 : class_binding_level->defining_class_p = 1;
4214 :
4215 29531244 : if (flag_pack_struct)
4216 : {
4217 99 : tree v;
4218 99 : TYPE_PACKED (t) = 1;
4219 : /* Even though the type is being defined for the first time
4220 : here, there might have been a forward declaration, so there
4221 : might be cv-qualified variants of T. */
4222 99 : for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
4223 0 : TYPE_PACKED (v) = 1;
4224 : }
4225 : /* Reset the interface data, at the earliest possible
4226 : moment, as it might have been set via a class foo;
4227 : before. */
4228 61232181 : if (! TYPE_UNNAMED_P (t))
4229 : {
4230 28811250 : struct c_fileinfo *finfo = \
4231 28811250 : get_fileinfo (LOCATION_FILE (input_location));
4232 28811250 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
4233 28811250 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X
4234 : (t, finfo->interface_unknown);
4235 : }
4236 29531244 : reset_specialization ();
4237 :
4238 : /* Make a declaration for this class in its own scope. */
4239 29531244 : build_self_reference ();
4240 :
4241 29531244 : return t;
4242 : }
4243 :
4244 : /* Finish the member declaration given by DECL. */
4245 :
4246 : void
4247 401098496 : finish_member_declaration (tree decl)
4248 : {
4249 401098496 : if (decl == error_mark_node || decl == NULL_TREE)
4250 : return;
4251 :
4252 401097495 : if (decl == void_type_node)
4253 : /* The COMPONENT was a friend, not a member, and so there's
4254 : nothing for us to do. */
4255 : return;
4256 :
4257 : /* We should see only one DECL at a time. */
4258 401097495 : gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
4259 :
4260 : /* Don't add decls after definition. */
4261 401097516 : gcc_assert (TYPE_BEING_DEFINED (current_class_type)
4262 : /* We can add lambda types when late parsing default
4263 : arguments. */
4264 : || LAMBDA_TYPE_P (TREE_TYPE (decl)));
4265 :
4266 : /* Set up access control for DECL. */
4267 401097495 : TREE_PRIVATE (decl)
4268 401097495 : = (current_access_specifier == access_private_node);
4269 401097495 : TREE_PROTECTED (decl)
4270 401097495 : = (current_access_specifier == access_protected_node);
4271 401097495 : if (TREE_CODE (decl) == TEMPLATE_DECL)
4272 : {
4273 45481445 : TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
4274 45481445 : TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
4275 : }
4276 :
4277 : /* Mark the DECL as a member of the current class, unless it's
4278 : a member of an enumeration. */
4279 401097495 : if (TREE_CODE (decl) != CONST_DECL)
4280 398905396 : DECL_CONTEXT (decl) = current_class_type;
4281 :
4282 : /* Remember the single FIELD_DECL an anonymous aggregate type is used for. */
4283 401097495 : if (TREE_CODE (decl) == FIELD_DECL
4284 401097495 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
4285 : {
4286 253956 : gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
4287 253956 : SET_ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl)), decl);
4288 : }
4289 :
4290 401097495 : if (TREE_CODE (decl) == USING_DECL)
4291 : /* Avoid debug info for class-scope USING_DECLS for now, we'll
4292 : call cp_emit_debug_info_for_using later. */
4293 3103933 : DECL_IGNORED_P (decl) = 1;
4294 :
4295 : /* Check for bare parameter packs in the non-static data member
4296 : declaration. */
4297 401097495 : if (TREE_CODE (decl) == FIELD_DECL)
4298 : {
4299 28880467 : if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
4300 9 : TREE_TYPE (decl) = error_mark_node;
4301 28880467 : if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
4302 0 : DECL_ATTRIBUTES (decl) = NULL_TREE;
4303 : }
4304 :
4305 : /* [dcl.link]
4306 :
4307 : A C language linkage is ignored for the names of class members
4308 : and the member function type of class member functions. */
4309 401097495 : if (DECL_LANG_SPECIFIC (decl))
4310 366869260 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
4311 :
4312 401097495 : bool add = false;
4313 :
4314 : /* Functions and non-functions are added differently. */
4315 401097495 : if (DECL_DECLARES_FUNCTION_P (decl))
4316 207328652 : add = add_method (current_class_type, decl, false);
4317 : /* Enter the DECL into the scope of the class, if the class
4318 : isn't a closure (whose fields are supposed to be unnamed). */
4319 193768843 : else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
4320 190427647 : || maybe_push_used_methods (decl)
4321 382442791 : || pushdecl_class_level (decl))
4322 : add = true;
4323 :
4324 207328652 : if (add)
4325 : {
4326 : /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
4327 : go at the beginning. The reason is that
4328 : legacy_nonfn_member_lookup searches the list in order, and we
4329 : want a field name to override a type name so that the "struct
4330 : stat hack" will work. In particular:
4331 :
4332 : struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
4333 :
4334 : is valid. */
4335 :
4336 401087986 : if (TREE_CODE (decl) == TYPE_DECL)
4337 138347166 : TYPE_FIELDS (current_class_type)
4338 276694332 : = chainon (TYPE_FIELDS (current_class_type), decl);
4339 : else
4340 : {
4341 262740820 : DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
4342 262740820 : TYPE_FIELDS (current_class_type) = decl;
4343 : }
4344 :
4345 401087986 : maybe_add_class_template_decl_list (current_class_type, decl,
4346 : /*friend_p=*/0);
4347 : }
4348 : }
4349 :
4350 : /* Finish processing a complete template declaration. The PARMS are
4351 : the template parameters. */
4352 :
4353 : void
4354 88601534 : finish_template_decl (tree parms)
4355 : {
4356 88601534 : if (parms)
4357 88601525 : end_template_decl ();
4358 : else
4359 9 : end_specialization ();
4360 88601534 : }
4361 :
4362 : // Returns the template type of the class scope being entered. If we're
4363 : // entering a constrained class scope. TYPE is the class template
4364 : // scope being entered and we may need to match the intended type with
4365 : // a constrained specialization. For example:
4366 : //
4367 : // template<Object T>
4368 : // struct S { void f(); }; #1
4369 : //
4370 : // template<Object T>
4371 : // void S<T>::f() { } #2
4372 : //
4373 : // We check, in #2, that S<T> refers precisely to the type declared by
4374 : // #1 (i.e., that the constraints match). Note that the following should
4375 : // be an error since there is no specialization of S<T> that is
4376 : // unconstrained, but this is not diagnosed here.
4377 : //
4378 : // template<typename T>
4379 : // void S<T>::f() { }
4380 : //
4381 : // We cannot diagnose this problem here since this function also matches
4382 : // qualified template names that are not part of a definition. For example:
4383 : //
4384 : // template<Integral T, Floating_point U>
4385 : // typename pair<T, U>::first_type void f(T, U);
4386 : //
4387 : // Here, it is unlikely that there is a partial specialization of
4388 : // pair constrained for Integral and Floating_point arguments.
4389 : //
4390 : // The general rule is: if a constrained specialization with matching
4391 : // constraints is found return that type. Also note that if TYPE is not a
4392 : // class-type (e.g. a typename type), then no fixup is needed.
4393 :
4394 : static tree
4395 17504754 : fixup_template_type (tree type)
4396 : {
4397 : // Find the template parameter list at the a depth appropriate to
4398 : // the scope we're trying to enter.
4399 17504754 : tree parms = current_template_parms;
4400 17504754 : int depth = template_class_depth (type);
4401 39013935 : for (int n = current_template_depth; n > depth && parms; --n)
4402 4004427 : parms = TREE_CHAIN (parms);
4403 17504754 : if (!parms)
4404 : return type;
4405 17504744 : tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
4406 17504744 : tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
4407 :
4408 : // Search for a specialization whose type and constraints match.
4409 17504744 : tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
4410 17504744 : tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
4411 34056685 : while (specs)
4412 : {
4413 16961631 : tree spec_constr = get_constraints (TREE_VALUE (specs));
4414 :
4415 : // If the type and constraints match a specialization, then we
4416 : // are entering that type.
4417 16961631 : if (same_type_p (type, TREE_TYPE (specs))
4418 16961631 : && equivalent_constraints (cur_constr, spec_constr))
4419 409690 : return TREE_TYPE (specs);
4420 16551941 : specs = TREE_CHAIN (specs);
4421 : }
4422 :
4423 : // If no specialization matches, then must return the type
4424 : // previously found.
4425 : return type;
4426 : }
4427 :
4428 : /* Finish processing a template-id (which names a type) of the form
4429 : NAME < ARGS >. Return the TYPE_DECL for the type named by the
4430 : template-id. If ENTERING_SCOPE is nonzero we are about to enter
4431 : the scope of template-id indicated. */
4432 :
4433 : tree
4434 180861409 : finish_template_type (tree name, tree args, int entering_scope)
4435 : {
4436 180861409 : tree type;
4437 :
4438 180861409 : type = lookup_template_class (name, args,
4439 : NULL_TREE, NULL_TREE,
4440 : tf_warning_or_error | tf_user);
4441 180861406 : if (entering_scope)
4442 18512553 : type = adjust_type_for_entering_scope (type);
4443 :
4444 : /* If we might be entering the scope of a partial specialization,
4445 : find the one with the right constraints. */
4446 180861406 : if (flag_concepts
4447 178156983 : && entering_scope
4448 18150633 : && CLASS_TYPE_P (type)
4449 17992304 : && CLASSTYPE_TEMPLATE_INFO (type)
4450 17992295 : && dependent_type_p (type)
4451 198366160 : && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
4452 17504754 : type = fixup_template_type (type);
4453 :
4454 180861406 : if (type == error_mark_node)
4455 : return type;
4456 180859133 : else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
4457 143195065 : return TYPE_STUB_DECL (type);
4458 : else
4459 37664068 : return TYPE_NAME (type);
4460 : }
4461 :
4462 : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER
4463 : and ANNOTATIONS.
4464 : Return a TREE_LIST containing the ACCESS_SPECIFIER (or if there are
4465 : ANNOTATIONS, TREE_LIST containing the ACCESS_SPECIFIER and ANNOTATIONS)
4466 : and the BASE_CLASS, or NULL_TREE if an error occurred. The
4467 : ACCESS_SPECIFIER is one of
4468 : access_{default,public,protected,private}_node. For a virtual base
4469 : we set TREE_TYPE. */
4470 :
4471 : tree
4472 10954180 : finish_base_specifier (tree base, tree access, bool virtual_p,
4473 : tree annotations)
4474 : {
4475 10954180 : tree result;
4476 :
4477 10954180 : if (base == error_mark_node)
4478 : {
4479 0 : error ("invalid base-class specification");
4480 0 : result = NULL_TREE;
4481 : }
4482 10954180 : else if (! MAYBE_CLASS_TYPE_P (base))
4483 : {
4484 3 : error ("%qT is not a class type", base);
4485 3 : result = NULL_TREE;
4486 : }
4487 : else
4488 : {
4489 10954177 : if (cp_type_quals (base) != 0)
4490 : {
4491 : /* DR 484: Can a base-specifier name a cv-qualified
4492 : class type? */
4493 12 : base = TYPE_MAIN_VARIANT (base);
4494 : }
4495 10954177 : if (annotations)
4496 9 : access = build_tree_list (access, nreverse (annotations));
4497 10954177 : result = build_tree_list (access, base);
4498 10954177 : if (virtual_p)
4499 25263 : TREE_TYPE (result) = integer_type_node;
4500 : }
4501 :
4502 10954180 : return result;
4503 : }
4504 :
4505 : /* If FNS is a member function, a set of member functions, or a
4506 : template-id referring to one or more member functions, return a
4507 : BASELINK for FNS, incorporating the current access context.
4508 : Otherwise, return FNS unchanged. */
4509 :
4510 : tree
4511 165505020 : baselink_for_fns (tree fns)
4512 : {
4513 165505020 : tree scope;
4514 165505020 : tree cl;
4515 :
4516 165505020 : if (BASELINK_P (fns)
4517 165505020 : || error_operand_p (fns))
4518 : return fns;
4519 :
4520 152277545 : scope = ovl_scope (fns);
4521 152277545 : if (!CLASS_TYPE_P (scope))
4522 : return fns;
4523 :
4524 8325578 : cl = currently_open_derived_class (scope);
4525 8325578 : if (!cl)
4526 6066654 : cl = scope;
4527 8325578 : tree access_path = TYPE_BINFO (cl);
4528 8325578 : tree conv_path = (cl == scope ? access_path
4529 671905 : : lookup_base (cl, scope, ba_any, NULL, tf_none));
4530 8325578 : return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
4531 : }
4532 :
4533 : /* Returns true iff we are currently parsing a lambda-declarator. */
4534 :
4535 : bool
4536 1892611679 : parsing_lambda_declarator ()
4537 : {
4538 1892611679 : cp_binding_level *b = current_binding_level;
4539 1894458843 : while (b->kind == sk_template_parms || b->kind == sk_function_parms)
4540 1847164 : b = b->level_chain;
4541 1892611679 : return b->kind == sk_lambda;
4542 : }
4543 :
4544 : /* Returns true iff DECL is a variable from a function outside
4545 : the current one. */
4546 :
4547 : static bool
4548 2535805419 : outer_var_p (tree decl)
4549 : {
4550 : /* These should have been stripped or otherwise handled by the caller. */
4551 2535805419 : gcc_checking_assert (!REFERENCE_REF_P (decl));
4552 :
4553 1670445560 : return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
4554 2328975849 : && DECL_FUNCTION_SCOPE_P (decl)
4555 : /* Don't get confused by temporaries. */
4556 1923557903 : && DECL_NAME (decl)
4557 4436516617 : && (DECL_CONTEXT (decl) != current_function_decl
4558 1890686996 : || parsing_nsdmi ()
4559 : /* Also consider captures as outer vars if we are in
4560 : decltype in a lambda declarator as in:
4561 : auto l = [j=0]() -> decltype((j)) { ... }
4562 : for the sake of finish_decltype_type.
4563 :
4564 : (Similar issue also affects non-lambdas, but vexing parse
4565 : makes it more difficult to handle than lambdas.) */
4566 1890686053 : || parsing_lambda_declarator ()));
4567 : }
4568 :
4569 : /* As above, but also checks that DECL is automatic. */
4570 :
4571 : bool
4572 2535805419 : outer_automatic_var_p (tree decl)
4573 : {
4574 2535805419 : return (outer_var_p (decl)
4575 2535805419 : && !TREE_STATIC (decl));
4576 : }
4577 :
4578 : /* Note whether capture proxy D is only used in a contract condition. */
4579 :
4580 : static void
4581 103449 : set_contract_capture_flag (tree d, bool val)
4582 : {
4583 103449 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (d));
4584 103449 : tree proxy = DECL_VALUE_EXPR (d);
4585 103449 : gcc_checking_assert (TREE_CODE (proxy) == COMPONENT_REF
4586 : && TREE_CODE (TREE_OPERAND (proxy, 1)) == FIELD_DECL);
4587 103449 : DECL_CONTRACT_CAPTURE_P (TREE_OPERAND (proxy, 1)) = val;
4588 103449 : }
4589 :
4590 : /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
4591 : rewrite it for lambda capture.
4592 :
4593 : If ODR_USE is true, we're being called from mark_use, and we complain about
4594 : use of constant variables. If ODR_USE is false, we're being called for the
4595 : id-expression, and we do lambda capture. */
4596 :
4597 : tree
4598 5039323 : process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
4599 : {
4600 5039323 : if (cp_unevaluated_operand)
4601 : {
4602 3113526 : tree type = TREE_TYPE (decl);
4603 3113526 : if (!dependent_type_p (type)
4604 3113526 : && variably_modified_type_p (type, NULL_TREE))
4605 : /* VLAs are used even in unevaluated context. */;
4606 : else
4607 : /* It's not a use (3.2) if we're in an unevaluated context. */
4608 3113520 : return decl;
4609 : }
4610 1925803 : if (decl == error_mark_node)
4611 : return decl;
4612 :
4613 1925797 : tree context = DECL_CONTEXT (decl);
4614 1925797 : tree containing_function = current_function_decl;
4615 1925797 : tree lambda_stack = NULL_TREE;
4616 1925797 : tree lambda_expr = NULL_TREE;
4617 1925797 : tree initializer = convert_from_reference (decl);
4618 1925797 : tree var = strip_normal_capture_proxy (decl);
4619 :
4620 : /* Mark it as used now even if the use is ill-formed. */
4621 1925797 : if (!mark_used (decl, complain))
4622 3 : return error_mark_node;
4623 :
4624 1925794 : if (parsing_nsdmi () || parsing_lambda_declarator ())
4625 : containing_function = NULL_TREE;
4626 :
4627 3850891 : if (containing_function && LAMBDA_FUNCTION_P (containing_function))
4628 : {
4629 : /* Check whether we've already built a proxy. */
4630 1925358 : tree d = retrieve_local_specialization (var);
4631 :
4632 1925358 : if (d && d != decl && is_capture_proxy (d))
4633 : {
4634 987822 : if (flag_contracts && !processing_contract_condition)
4635 : /* We might have created a capture for a contract_assert ref. to
4636 : some var, if that is now captured 'normally' then this is OK.
4637 : Otherwise we leave the capture marked as incorrect. */
4638 103446 : set_contract_capture_flag (d, false);
4639 987822 : if (DECL_CONTEXT (d) == containing_function)
4640 : /* We already have an inner proxy. */
4641 : return d;
4642 : else
4643 : /* We need to capture an outer proxy. */
4644 2526 : return process_outer_var_ref (d, complain, odr_use);
4645 : }
4646 : }
4647 :
4648 : /* If we are in a lambda function, we can move out until we hit
4649 : 1. the context,
4650 : 2. a non-lambda function, or
4651 : 3. a non-default capturing lambda function. */
4652 1878529 : while (context != containing_function
4653 : /* containing_function can be null with invalid generic lambdas. */
4654 1878529 : && containing_function
4655 2819761 : && LAMBDA_FUNCTION_P (containing_function))
4656 : {
4657 941232 : tree closure = DECL_CONTEXT (containing_function);
4658 941232 : lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
4659 :
4660 941232 : if (TYPE_CLASS_SCOPE_P (closure))
4661 : /* A lambda in an NSDMI (c++/64496). */
4662 : break;
4663 :
4664 941229 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4665 : break;
4666 :
4667 940557 : lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
4668 :
4669 940557 : containing_function = decl_function_context (containing_function);
4670 : }
4671 :
4672 : /* In a lambda within a template, wait until instantiation time to implicitly
4673 : capture a parameter pack. We want to wait because we don't know if we're
4674 : capturing the whole pack or a single element, and it's OK to wait because
4675 : find_parameter_packs_r walks into the lambda body. */
4676 937972 : if (context == containing_function
4677 937972 : && DECL_PACK_P (decl))
4678 : return decl;
4679 :
4680 897193 : if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
4681 : {
4682 6 : if (complain & tf_error)
4683 6 : error ("cannot capture member %qD of anonymous union", decl);
4684 6 : return error_mark_node;
4685 : }
4686 : /* Do lambda capture when processing the id-expression, not when
4687 : odr-using a variable, but uses in a contract must not cause a capture. */
4688 897187 : if (!odr_use && context == containing_function)
4689 : {
4690 896076 : decl = add_default_capture (lambda_stack,
4691 896076 : /*id=*/DECL_NAME (decl), initializer);
4692 896076 : if (flag_contracts && processing_contract_condition)
4693 3 : set_contract_capture_flag (decl, true);
4694 : }
4695 : /* Only an odr-use of an outer automatic variable causes an
4696 : error, and a constant variable can decay to a prvalue
4697 : constant without odr-use. So don't complain yet. */
4698 1111 : else if (!odr_use && decl_constant_var_p (var))
4699 : return var;
4700 308 : else if (lambda_expr)
4701 : {
4702 45 : if (complain & tf_error)
4703 : {
4704 43 : auto_diagnostic_group d;
4705 43 : error ("%qD is not captured", decl);
4706 43 : tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
4707 43 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4708 40 : inform (location_of (closure),
4709 : "the lambda has no capture-default");
4710 3 : else if (TYPE_CLASS_SCOPE_P (closure))
4711 3 : inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
4712 : "capture variables from the enclosing context",
4713 3 : TYPE_CONTEXT (closure));
4714 43 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4715 43 : }
4716 45 : return error_mark_node;
4717 : }
4718 263 : else if (processing_contract_condition && (TREE_CODE (decl) == PARM_DECL))
4719 : /* Use of a parameter in a contract condition is fine. */
4720 : return decl;
4721 : else
4722 : {
4723 46 : if (complain & tf_error)
4724 : {
4725 39 : auto_diagnostic_group d;
4726 57 : error (VAR_P (decl)
4727 : ? G_("use of local variable with automatic storage from "
4728 : "containing function")
4729 : : G_("use of parameter from containing function"));
4730 39 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4731 39 : }
4732 46 : return error_mark_node;
4733 : }
4734 : return decl;
4735 : }
4736 :
4737 : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4738 : id-expression. (See cp_parser_id_expression for details.) SCOPE,
4739 : if non-NULL, is the type or namespace used to explicitly qualify
4740 : ID_EXPRESSION. DECL is the entity to which that name has been
4741 : resolved.
4742 :
4743 : *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4744 : constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4745 : be set to true if this expression isn't permitted in a
4746 : constant-expression, but it is otherwise not set by this function.
4747 : *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4748 : constant-expression, but a non-constant expression is also
4749 : permissible.
4750 :
4751 : DONE is true if this expression is a complete postfix-expression;
4752 : it is false if this expression is followed by '->', '[', '(', etc.
4753 : ADDRESS_P is true iff this expression is the operand of '&'.
4754 : TEMPLATE_P is true iff the qualified-id was of the form
4755 : "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4756 : appears as a template argument.
4757 :
4758 : If an error occurs, and it is the kind of error that might cause
4759 : the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4760 : is the caller's responsibility to issue the message. *ERROR_MSG
4761 : will be a string with static storage duration, so the caller need
4762 : not "free" it.
4763 :
4764 : Return an expression for the entity, after issuing appropriate
4765 : diagnostics. This function is also responsible for transforming a
4766 : reference to a non-static member into a COMPONENT_REF that makes
4767 : the use of "this" explicit.
4768 :
4769 : Upon return, *IDK will be filled in appropriately. */
4770 : static cp_expr
4771 752278528 : finish_id_expression_1 (tree id_expression,
4772 : tree decl,
4773 : tree scope,
4774 : cp_id_kind *idk,
4775 : bool integral_constant_expression_p,
4776 : bool allow_non_integral_constant_expression_p,
4777 : bool *non_integral_constant_expression_p,
4778 : bool template_p,
4779 : bool done,
4780 : bool address_p,
4781 : bool template_arg_p,
4782 : const char **error_msg,
4783 : location_t location)
4784 : {
4785 752278528 : decl = strip_using_decl (decl);
4786 :
4787 : /* Initialize the output parameters. */
4788 752278528 : *idk = CP_ID_KIND_NONE;
4789 752278528 : *error_msg = NULL;
4790 :
4791 752278528 : if (id_expression == error_mark_node)
4792 12 : return error_mark_node;
4793 : /* If we have a template-id, then no further lookup is
4794 : required. If the template-id was for a template-class, we
4795 : will sometimes have a TYPE_DECL at this point. */
4796 752278516 : else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4797 701090311 : || TREE_CODE (decl) == TYPE_DECL)
4798 : ;
4799 : /* Look up the name. */
4800 : else
4801 : {
4802 701089408 : if (decl == error_mark_node)
4803 : {
4804 : /* Name lookup failed. */
4805 122167 : if (scope
4806 370 : && !dependent_namespace_p (scope)
4807 122537 : && (!TYPE_P (scope)
4808 116 : || (!dependentish_scope_p (scope)
4809 112 : && !(identifier_p (id_expression)
4810 97 : && IDENTIFIER_CONV_OP_P (id_expression)
4811 3 : && dependent_type_p (TREE_TYPE (id_expression))))))
4812 : {
4813 : /* If the qualifying type is non-dependent (and the name
4814 : does not name a conversion operator to a dependent
4815 : type), issue an error. */
4816 360 : qualified_name_lookup_error (scope, id_expression, decl, location);
4817 360 : return error_mark_node;
4818 : }
4819 121807 : else if (!scope)
4820 : {
4821 : /* It may be resolved via Koenig lookup. */
4822 121797 : *idk = CP_ID_KIND_UNQUALIFIED;
4823 121797 : return id_expression;
4824 : }
4825 : else
4826 : decl = id_expression;
4827 : }
4828 :
4829 : /* Remember that the name was used in the definition of
4830 : the current class so that we can check later to see if
4831 : the meaning would have been different after the class
4832 : was entirely defined. */
4833 700967241 : if (!scope && decl != error_mark_node && identifier_p (id_expression))
4834 626966949 : maybe_note_name_used_in_class (id_expression, decl);
4835 :
4836 : /* A use in unevaluated operand might not be instantiated appropriately
4837 : if tsubst_copy builds a dummy parm, or if we never instantiate a
4838 : generic lambda, so mark it now. */
4839 700967251 : if (processing_template_decl
4840 700967251 : && (cp_unevaluated_operand
4841 606145283 : || generic_lambda_fn_p (current_function_decl)))
4842 19053599 : mark_type_use (decl);
4843 :
4844 : /* Disallow uses of local variables from containing functions, except
4845 : within lambda-expressions. */
4846 700967251 : if (outer_automatic_var_p (decl))
4847 : {
4848 3438343 : decl = process_outer_var_ref (decl, tf_warning_or_error);
4849 3438343 : if (decl == error_mark_node)
4850 85 : return error_mark_node;
4851 : }
4852 :
4853 : /* Also disallow uses of function parameters outside the function
4854 : body, except inside an unevaluated context (i.e. decltype). */
4855 700967166 : if (TREE_CODE (decl) == PARM_DECL
4856 292396622 : && DECL_CONTEXT (decl) == NULL_TREE
4857 7844299 : && !CONSTRAINT_VAR_P (decl)
4858 4238751 : && !cp_unevaluated_operand
4859 374 : && !processing_contract_condition
4860 700967210 : && !processing_omp_trait_property_expr)
4861 : {
4862 26 : *error_msg = G_("use of parameter outside function body");
4863 26 : return error_mark_node;
4864 : }
4865 : }
4866 :
4867 : /* If we didn't find anything, or what we found was a type,
4868 : then this wasn't really an id-expression. */
4869 752156248 : if (TREE_CODE (decl) == TEMPLATE_DECL
4870 752156248 : && !DECL_FUNCTION_TEMPLATE_P (decl))
4871 : {
4872 51 : *error_msg = G_("missing template arguments");
4873 51 : return error_mark_node;
4874 : }
4875 752156197 : else if (TREE_CODE (decl) == TYPE_DECL
4876 752155294 : || TREE_CODE (decl) == NAMESPACE_DECL)
4877 : {
4878 918 : *error_msg = G_("expected primary-expression");
4879 918 : return error_mark_node;
4880 : }
4881 :
4882 : /* If the name resolved to a template parameter, there is no
4883 : need to look it up again later. */
4884 31824450 : if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
4885 765590280 : || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4886 : {
4887 18389449 : tree r;
4888 :
4889 18389449 : *idk = CP_ID_KIND_NONE;
4890 18389449 : if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4891 0 : decl = TEMPLATE_PARM_DECL (decl);
4892 18389449 : r = DECL_INITIAL (decl);
4893 18389449 : if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
4894 : {
4895 : /* If the entity is a template parameter object for a template
4896 : parameter of type T, the type of the expression is const T. */
4897 1085 : tree ctype = TREE_TYPE (r);
4898 1085 : ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
4899 : | TYPE_QUAL_CONST));
4900 1085 : r = build1 (VIEW_CONVERT_EXPR, ctype, r);
4901 : }
4902 18389449 : r = convert_from_reference (r);
4903 18389449 : if (integral_constant_expression_p
4904 3182566 : && !dependent_type_p (TREE_TYPE (decl))
4905 21097630 : && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
4906 : {
4907 505 : if (!allow_non_integral_constant_expression_p)
4908 6 : error ("template parameter %qD of type %qT is not allowed in "
4909 : "an integral constant expression because it is not of "
4910 6 : "integral or enumeration type", decl, TREE_TYPE (decl));
4911 505 : *non_integral_constant_expression_p = true;
4912 : }
4913 :
4914 18389449 : if (flag_contracts && processing_contract_condition)
4915 9 : r = constify_contract_access (r);
4916 :
4917 18389449 : return r;
4918 : }
4919 733765830 : else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
4920 : {
4921 9 : gcc_checking_assert (scope);
4922 9 : *idk = CP_ID_KIND_QUALIFIED;
4923 9 : cp_warn_deprecated_use_scopes (scope);
4924 9 : decl = finish_qualified_id_expr (scope, decl, done, address_p,
4925 : template_p, template_arg_p,
4926 : tf_warning_or_error);
4927 : }
4928 : else
4929 : {
4930 733765821 : if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4931 51188205 : && variable_template_p (TREE_OPERAND (decl, 0))
4932 745300766 : && !concept_check_p (decl))
4933 : /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
4934 : considered type-dependent) now, so that the dependence test that
4935 : follows gives us the right answer: if it represents a non-dependent
4936 : variable template-id then finish_template_variable will yield the
4937 : corresponding non-dependent VAR_DECL. */
4938 11534945 : decl = finish_template_variable (decl);
4939 :
4940 733765821 : bool dependent_p = type_dependent_expression_p (decl);
4941 :
4942 : /* If the declaration was explicitly qualified indicate
4943 : that. The semantics of `A::f(3)' are different than
4944 : `f(3)' if `f' is virtual. */
4945 1467531642 : *idk = (scope
4946 733765821 : ? CP_ID_KIND_QUALIFIED
4947 638794366 : : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4948 638794366 : ? CP_ID_KIND_TEMPLATE_ID
4949 : : (dependent_p
4950 608848008 : ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
4951 : : CP_ID_KIND_UNQUALIFIED)));
4952 :
4953 733765821 : if (dependent_p
4954 733765821 : && !scope
4955 419824698 : && DECL_P (decl)
4956 1124427953 : && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
4957 : /* Dependent type attributes on the decl mean that the TREE_TYPE is
4958 : wrong, so just return the identifier. */
4959 39 : return id_expression;
4960 :
4961 733765782 : if (DECL_CLASS_TEMPLATE_P (decl))
4962 : {
4963 0 : error ("use of class template %qT as expression", decl);
4964 0 : return error_mark_node;
4965 : }
4966 :
4967 733765782 : if (TREE_CODE (decl) == TREE_LIST)
4968 : {
4969 : /* Ambiguous reference to base members. */
4970 0 : auto_diagnostic_group d;
4971 0 : error ("request for member %qD is ambiguous in "
4972 : "multiple inheritance lattice", id_expression);
4973 0 : print_candidates (input_location, decl);
4974 0 : return error_mark_node;
4975 0 : }
4976 :
4977 : /* Mark variable-like entities as used. Functions are similarly
4978 : marked either below or after overload resolution. */
4979 733765782 : if ((VAR_P (decl)
4980 531701280 : || TREE_CODE (decl) == PARM_DECL
4981 239304690 : || TREE_CODE (decl) == CONST_DECL
4982 225869689 : || TREE_CODE (decl) == RESULT_DECL)
4983 1039597373 : && !mark_used (decl))
4984 12 : return error_mark_node;
4985 :
4986 : /* Only certain kinds of names are allowed in constant
4987 : expression. Template parameters have already
4988 : been handled above. */
4989 733765767 : if (! error_operand_p (decl)
4990 733765452 : && !dependent_p
4991 733765452 : && integral_constant_expression_p
4992 74324435 : && !decl_constant_var_p (decl)
4993 60597136 : && TREE_CODE (decl) != CONST_DECL
4994 52369807 : && !builtin_valid_in_constant_expr_p (decl)
4995 786087748 : && !concept_check_p (decl))
4996 : {
4997 51809794 : if (!allow_non_integral_constant_expression_p)
4998 : {
4999 30 : error ("%qD cannot appear in a constant-expression", decl);
5000 30 : return error_mark_node;
5001 : }
5002 51809764 : *non_integral_constant_expression_p = true;
5003 : }
5004 :
5005 733765737 : if (tree wrap = maybe_get_tls_wrapper_call (decl))
5006 : /* Replace an evaluated use of the thread_local variable with
5007 : a call to its wrapper. */
5008 : decl = wrap;
5009 733765225 : else if (concept_check_p (decl))
5010 : {
5011 : /* Nothing more to do. All of the analysis for concept checks
5012 : is done by build_conept_id, called from the parser. */
5013 : }
5014 718086590 : else if (scope)
5015 : {
5016 93212781 : if (TREE_CODE (decl) == SCOPE_REF)
5017 : {
5018 81960 : gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
5019 81960 : decl = TREE_OPERAND (decl, 1);
5020 : }
5021 :
5022 93212781 : decl = (adjust_result_of_qualified_name_lookup
5023 93212781 : (decl, scope, current_nonlambda_class_type()));
5024 :
5025 93212781 : cp_warn_deprecated_use_scopes (scope);
5026 :
5027 93212781 : if (TYPE_P (scope))
5028 13354633 : decl = finish_qualified_id_expr (scope,
5029 : decl,
5030 : done,
5031 : address_p,
5032 : template_p,
5033 : template_arg_p,
5034 : tf_warning_or_error);
5035 : else
5036 79858148 : decl = convert_from_reference (decl);
5037 : }
5038 624873809 : else if (TREE_CODE (decl) == FIELD_DECL)
5039 : {
5040 65374605 : if (flag_contracts && processing_contract_condition
5041 22 : && contract_class_ptr == current_class_ptr)
5042 : {
5043 4 : error ("%qD 'this' required when accessing a member within a "
5044 : "constructor precondition or destructor postcondition "
5045 : "contract check", decl);
5046 4 : return error_mark_node;
5047 : }
5048 : /* Since SCOPE is NULL here, this is an unqualified name.
5049 : Access checking has been performed during name lookup
5050 : already. Turn off checking to avoid duplicate errors. */
5051 65374601 : push_deferring_access_checks (dk_no_check);
5052 65374601 : decl = finish_non_static_data_member (decl, NULL_TREE,
5053 : /*qualifying_scope=*/NULL_TREE);
5054 65374601 : pop_deferring_access_checks ();
5055 : }
5056 559499204 : else if (is_overloaded_fn (decl))
5057 : {
5058 : /* We only need to look at the first function,
5059 : because all the fns share the attribute we're
5060 : concerned with (all member fns or all non-members). */
5061 59655306 : tree first_fn = get_first_fn (decl);
5062 59655306 : first_fn = STRIP_TEMPLATE (first_fn);
5063 :
5064 59655306 : if (!template_arg_p
5065 59655306 : && (TREE_CODE (first_fn) == USING_DECL
5066 59653432 : || (TREE_CODE (first_fn) == FUNCTION_DECL
5067 59653432 : && DECL_FUNCTION_MEMBER_P (first_fn)
5068 36189865 : && !shared_member_p (decl))))
5069 : {
5070 : /* A set of member functions. */
5071 27981038 : if (flag_contracts && processing_contract_condition
5072 16 : && contract_class_ptr == current_class_ptr)
5073 : {
5074 2 : error ("%qD 'this' required when accessing a member within a "
5075 : "constructor precondition or destructor postcondition "
5076 : "contract check", decl);
5077 2 : return error_mark_node;
5078 : }
5079 27981036 : decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
5080 27981036 : return finish_class_member_access_expr (decl, id_expression,
5081 : /*template_p=*/false,
5082 27981036 : tf_warning_or_error);
5083 : }
5084 :
5085 31674268 : decl = baselink_for_fns (decl);
5086 : }
5087 : else
5088 : {
5089 489191664 : if (DECL_P (decl) && DECL_NONLOCAL (decl)
5090 501300339 : && DECL_CLASS_SCOPE_P (decl))
5091 : {
5092 1456441 : tree context = context_for_name_lookup (decl);
5093 1456441 : if (context != current_class_type)
5094 : {
5095 762538 : tree path = currently_open_derived_class (context);
5096 762538 : if (!path)
5097 : /* PATH can be null for using an enum of an unrelated
5098 : class; we checked its access in lookup_using_decl.
5099 :
5100 : ??? Should this case make a clone instead, like
5101 : handle_using_decl? */
5102 23 : gcc_assert (TREE_CODE (decl) == CONST_DECL
5103 : /* This is for:
5104 : constexpr auto r = ^^S::i;
5105 : auto a = [:r:]; */
5106 : || flag_reflection);
5107 : else
5108 762515 : perform_or_defer_access_check (TYPE_BINFO (path),
5109 : decl, decl,
5110 : tf_warning_or_error);
5111 : }
5112 : }
5113 :
5114 499843898 : decl = convert_from_reference (decl);
5115 : }
5116 : }
5117 :
5118 705784704 : check_param_in_postcondition (decl, location);
5119 705784704 : if (flag_contracts && processing_contract_condition)
5120 1311 : decl = constify_contract_access (decl);
5121 :
5122 705784704 : return cp_expr (decl, location);
5123 : }
5124 :
5125 : /* As per finish_id_expression_1, but adding a wrapper node
5126 : around the result if needed to express LOCATION. */
5127 :
5128 : cp_expr
5129 752278528 : finish_id_expression (tree id_expression,
5130 : tree decl,
5131 : tree scope,
5132 : cp_id_kind *idk,
5133 : bool integral_constant_expression_p,
5134 : bool allow_non_integral_constant_expression_p,
5135 : bool *non_integral_constant_expression_p,
5136 : bool template_p,
5137 : bool done,
5138 : bool address_p,
5139 : bool template_arg_p,
5140 : const char **error_msg,
5141 : location_t location)
5142 : {
5143 752278528 : cp_expr result
5144 752278528 : = finish_id_expression_1 (id_expression, decl, scope, idk,
5145 : integral_constant_expression_p,
5146 : allow_non_integral_constant_expression_p,
5147 : non_integral_constant_expression_p,
5148 : template_p, done, address_p, template_arg_p,
5149 : error_msg, location);
5150 752278525 : return result.maybe_add_location_wrapper ();
5151 : }
5152 :
5153 : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
5154 : use as a type-specifier. */
5155 :
5156 : tree
5157 21143458 : finish_typeof (tree expr)
5158 : {
5159 21143458 : tree type;
5160 :
5161 21143458 : if (type_dependent_expression_p (expr))
5162 : {
5163 21052679 : type = cxx_make_type (TYPEOF_TYPE);
5164 21052679 : TYPEOF_TYPE_EXPR (type) = expr;
5165 21052679 : SET_TYPE_STRUCTURAL_EQUALITY (type);
5166 :
5167 21052679 : return type;
5168 : }
5169 :
5170 90779 : expr = mark_type_use (expr);
5171 :
5172 90779 : type = unlowered_expr_type (expr);
5173 :
5174 90779 : if (!type || type == unknown_type_node)
5175 : {
5176 3 : error ("type of %qE is unknown", expr);
5177 3 : return error_mark_node;
5178 : }
5179 :
5180 : return type;
5181 : }
5182 :
5183 : /* Implement the __underlying_type keyword: Return the underlying
5184 : type of TYPE, suitable for use as a type-specifier. */
5185 :
5186 : tree
5187 46658 : finish_underlying_type (tree type)
5188 : {
5189 46658 : if (!complete_type_or_else (type, NULL_TREE))
5190 3 : return error_mark_node;
5191 :
5192 46655 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5193 : {
5194 24 : error ("%qT is not an enumeration type", type);
5195 24 : return error_mark_node;
5196 : }
5197 :
5198 46631 : tree underlying_type = ENUM_UNDERLYING_TYPE (type);
5199 :
5200 : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5201 : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5202 : See finish_enum_value_list for details. */
5203 46631 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5204 54 : underlying_type
5205 54 : = c_common_type_for_mode (TYPE_MODE (underlying_type),
5206 54 : TYPE_UNSIGNED (underlying_type));
5207 :
5208 : return underlying_type;
5209 : }
5210 :
5211 : /* Implement the __type_pack_element keyword: Return the type
5212 : at index IDX within TYPES. */
5213 :
5214 : static tree
5215 117856 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
5216 : {
5217 117856 : idx = maybe_constant_value (idx, NULL_TREE, mce_true);
5218 117856 : if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
5219 : {
5220 6 : if (complain & tf_error)
5221 3 : error ("pack index has non-integral type %qT", TREE_TYPE (idx));
5222 6 : return error_mark_node;
5223 : }
5224 117850 : if (TREE_CODE (idx) != INTEGER_CST)
5225 : {
5226 1 : if (complain & tf_error)
5227 : {
5228 1 : error ("pack index is not an integral constant");
5229 1 : cxx_constant_value (idx);
5230 : }
5231 1 : return error_mark_node;
5232 : }
5233 117849 : if (tree_int_cst_sgn (idx) < 0)
5234 : {
5235 3 : if (complain & tf_error)
5236 3 : error ("pack index %qE is negative", idx);
5237 3 : return error_mark_node;
5238 : }
5239 117846 : if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
5240 : {
5241 30 : if (complain & tf_error)
5242 24 : error ("pack index %qE is out of range for pack of length %qd",
5243 24 : idx, TREE_VEC_LENGTH (types));
5244 30 : return error_mark_node;
5245 : }
5246 117816 : return TREE_VEC_ELT (types, tree_to_shwi (idx));
5247 : }
5248 :
5249 : /* In a pack-index T...[N], return the element at index IDX within TYPES.
5250 : PARENTHESIZED_P is true iff the pack index was wrapped in (). */
5251 :
5252 : tree
5253 10832 : pack_index_element (tree idx, tree types, bool parenthesized_p,
5254 : tsubst_flags_t complain)
5255 : {
5256 10832 : tree r = finish_type_pack_element (idx, types, complain);
5257 10832 : if (parenthesized_p)
5258 : /* For the benefit of decltype(auto). */
5259 22 : r = force_paren_expr (r);
5260 10832 : return r;
5261 : }
5262 :
5263 : /* Implement the __direct_bases keyword: Return the direct base classes
5264 : of type. */
5265 :
5266 : tree
5267 15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
5268 : {
5269 15 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5270 15 : || !NON_UNION_CLASS_TYPE_P (type))
5271 8 : return make_tree_vec (0);
5272 :
5273 7 : releasing_vec vector;
5274 7 : vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
5275 7 : tree binfo;
5276 7 : unsigned i;
5277 :
5278 : /* Virtual bases are initialized first */
5279 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5280 13 : if (BINFO_VIRTUAL_P (binfo))
5281 2 : vec_safe_push (vector, binfo);
5282 :
5283 : /* Now non-virtuals */
5284 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5285 13 : if (!BINFO_VIRTUAL_P (binfo))
5286 11 : vec_safe_push (vector, binfo);
5287 :
5288 7 : tree bases_vec = make_tree_vec (vector->length ());
5289 :
5290 27 : for (i = 0; i < vector->length (); ++i)
5291 13 : TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
5292 :
5293 7 : return bases_vec;
5294 7 : }
5295 :
5296 : /* Implement the __bases keyword: Return the base classes
5297 : of type */
5298 :
5299 : /* Find morally non-virtual base classes by walking binfo hierarchy */
5300 : /* Virtual base classes are handled separately in finish_bases */
5301 :
5302 : static tree
5303 73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
5304 : {
5305 : /* Don't walk bases of virtual bases */
5306 73 : return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
5307 : }
5308 :
5309 : static tree
5310 73 : dfs_calculate_bases_post (tree binfo, void *data_)
5311 : {
5312 73 : vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
5313 73 : if (!BINFO_VIRTUAL_P (binfo))
5314 48 : vec_safe_push (*data, BINFO_TYPE (binfo));
5315 73 : return NULL_TREE;
5316 : }
5317 :
5318 : /* Calculates the morally non-virtual base classes of a class */
5319 : static vec<tree, va_gc> *
5320 16 : calculate_bases_helper (tree type)
5321 : {
5322 16 : vec<tree, va_gc> *vector = make_tree_vector ();
5323 :
5324 : /* Now add non-virtual base classes in order of construction */
5325 16 : if (TYPE_BINFO (type))
5326 16 : dfs_walk_all (TYPE_BINFO (type),
5327 : dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
5328 16 : return vector;
5329 : }
5330 :
5331 : tree
5332 12 : calculate_bases (tree type, tsubst_flags_t complain)
5333 : {
5334 12 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5335 12 : || !NON_UNION_CLASS_TYPE_P (type))
5336 5 : return make_tree_vec (0);
5337 :
5338 7 : releasing_vec vector;
5339 7 : tree bases_vec = NULL_TREE;
5340 7 : unsigned i;
5341 7 : vec<tree, va_gc> *vbases;
5342 7 : tree binfo;
5343 :
5344 : /* First go through virtual base classes */
5345 7 : for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
5346 16 : vec_safe_iterate (vbases, i, &binfo); i++)
5347 : {
5348 9 : releasing_vec vbase_bases
5349 9 : = calculate_bases_helper (BINFO_TYPE (binfo));
5350 9 : vec_safe_splice (vector, vbase_bases);
5351 9 : }
5352 :
5353 : /* Now for the non-virtual bases */
5354 7 : releasing_vec nonvbases = calculate_bases_helper (type);
5355 7 : vec_safe_splice (vector, nonvbases);
5356 :
5357 : /* Note that during error recovery vector->length can even be zero. */
5358 7 : if (vector->length () > 1)
5359 : {
5360 : /* Last element is entire class, so don't copy */
5361 6 : bases_vec = make_tree_vec (vector->length () - 1);
5362 :
5363 53 : for (i = 0; i < vector->length () - 1; ++i)
5364 41 : TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
5365 : }
5366 : else
5367 1 : bases_vec = make_tree_vec (0);
5368 :
5369 7 : return bases_vec;
5370 7 : }
5371 :
5372 : tree
5373 28 : finish_bases (tree type, bool direct)
5374 : {
5375 28 : tree bases = NULL_TREE;
5376 :
5377 28 : if (!processing_template_decl)
5378 : {
5379 : /* Parameter packs can only be used in templates */
5380 0 : error ("parameter pack %<__bases%> only valid in template declaration");
5381 0 : return error_mark_node;
5382 : }
5383 :
5384 28 : bases = cxx_make_type (BASES);
5385 28 : BASES_TYPE (bases) = type;
5386 28 : BASES_DIRECT (bases) = direct;
5387 28 : SET_TYPE_STRUCTURAL_EQUALITY (bases);
5388 :
5389 28 : return bases;
5390 : }
5391 :
5392 : /* Perform C++-specific checks for __builtin_offsetof before calling
5393 : fold_offsetof. */
5394 :
5395 : tree
5396 2400 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
5397 : {
5398 : /* If we're processing a template, we can't finish the semantics yet.
5399 : Otherwise we can fold the entire expression now. */
5400 2400 : if (processing_template_decl)
5401 : {
5402 60 : expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
5403 60 : SET_EXPR_LOCATION (expr, loc);
5404 60 : return expr;
5405 : }
5406 :
5407 2340 : if (expr == error_mark_node)
5408 : return error_mark_node;
5409 :
5410 2323 : if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
5411 : {
5412 6 : error ("cannot apply %<offsetof%> to destructor %<~%T%>",
5413 6 : TREE_OPERAND (expr, 2));
5414 6 : return error_mark_node;
5415 : }
5416 4619 : if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
5417 4619 : || TREE_TYPE (expr) == unknown_type_node)
5418 : {
5419 30 : while (TREE_CODE (expr) == COMPONENT_REF
5420 30 : || TREE_CODE (expr) == COMPOUND_EXPR)
5421 12 : expr = TREE_OPERAND (expr, 1);
5422 :
5423 18 : if (DECL_P (expr))
5424 : {
5425 0 : auto_diagnostic_group d;
5426 0 : error ("cannot apply %<offsetof%> to member function %qD", expr);
5427 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
5428 0 : }
5429 : else
5430 18 : error ("cannot apply %<offsetof%> to member function");
5431 18 : return error_mark_node;
5432 : }
5433 2299 : if (TREE_CODE (expr) == CONST_DECL)
5434 : {
5435 3 : error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
5436 3 : return error_mark_node;
5437 : }
5438 2296 : if (REFERENCE_REF_P (expr))
5439 9 : expr = TREE_OPERAND (expr, 0);
5440 2296 : if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
5441 3 : return error_mark_node;
5442 2293 : if (warn_invalid_offsetof
5443 2293 : && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
5444 2293 : && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
5445 2338 : && cp_unevaluated_operand == 0)
5446 45 : warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
5447 : "non-standard-layout type %qT is conditionally-supported",
5448 45 : TREE_TYPE (TREE_TYPE (object_ptr)));
5449 2293 : return fold_offsetof (expr);
5450 : }
5451 :
5452 : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
5453 : function is broken out from the above for the benefit of the tree-ssa
5454 : project. */
5455 :
5456 : void
5457 336198 : simplify_aggr_init_expr (tree *tp)
5458 : {
5459 336198 : tree aggr_init_expr = *tp;
5460 :
5461 : /* Form an appropriate CALL_EXPR. */
5462 336198 : tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
5463 336198 : tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
5464 336198 : tree type = TREE_TYPE (slot);
5465 :
5466 336198 : tree call_expr;
5467 336198 : enum style_t { ctor, arg, pcc } style;
5468 :
5469 336198 : if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
5470 : style = ctor;
5471 : #ifdef PCC_STATIC_STRUCT_RETURN
5472 : else if (1)
5473 : style = pcc;
5474 : #endif
5475 : else
5476 : {
5477 88072 : gcc_assert (TREE_ADDRESSABLE (type));
5478 : style = arg;
5479 : }
5480 :
5481 336198 : call_expr = build_call_array_loc (input_location,
5482 336198 : TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
5483 : fn,
5484 336198 : aggr_init_expr_nargs (aggr_init_expr),
5485 336198 : AGGR_INIT_EXPR_ARGP (aggr_init_expr));
5486 336198 : TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
5487 336198 : CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
5488 336198 : CALL_EXPR_OPERATOR_SYNTAX (call_expr)
5489 336198 : = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
5490 336198 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
5491 336198 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
5492 336198 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
5493 :
5494 336198 : if (style == ctor)
5495 : {
5496 : /* Replace the first argument to the ctor with the address of the
5497 : slot. */
5498 248126 : cxx_mark_addressable (slot);
5499 248126 : CALL_EXPR_ARG (call_expr, 0) =
5500 248126 : build1 (ADDR_EXPR, build_pointer_type (type), slot);
5501 : }
5502 88072 : else if (style == arg)
5503 : {
5504 : /* Just mark it addressable here, and leave the rest to
5505 : expand_call{,_inline}. */
5506 88072 : cxx_mark_addressable (slot);
5507 88072 : CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
5508 88072 : call_expr = cp_build_init_expr (slot, call_expr);
5509 : }
5510 : else if (style == pcc)
5511 : {
5512 : /* If we're using the non-reentrant PCC calling convention, then we
5513 : need to copy the returned value out of the static buffer into the
5514 : SLOT. */
5515 : push_deferring_access_checks (dk_no_check);
5516 : call_expr = build_aggr_init (slot, call_expr,
5517 : DIRECT_BIND | LOOKUP_ONLYCONVERTING,
5518 : tf_warning_or_error);
5519 : pop_deferring_access_checks ();
5520 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
5521 : }
5522 :
5523 336198 : if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
5524 : {
5525 3316 : tree init = build_zero_init (type, NULL_TREE,
5526 : /*static_storage_p=*/false);
5527 3316 : init = cp_build_init_expr (slot, init);
5528 3316 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
5529 : init, call_expr);
5530 : }
5531 :
5532 336198 : *tp = call_expr;
5533 336198 : }
5534 :
5535 : /* Emit all thunks to FN that should be emitted when FN is emitted. */
5536 :
5537 : void
5538 57493125 : emit_associated_thunks (tree fn)
5539 : {
5540 : /* When we use vcall offsets, we emit thunks with the virtual
5541 : functions to which they thunk. The whole point of vcall offsets
5542 : is so that you can know statically the entire set of thunks that
5543 : will ever be needed for a given virtual function, thereby
5544 : enabling you to output all the thunks with the function itself. */
5545 57493125 : if (DECL_VIRTUAL_P (fn)
5546 : /* Do not emit thunks for extern template instantiations. */
5547 1084167 : && ! DECL_REALLY_EXTERN (fn)
5548 : /* Do not emit thunks for tentative decls, those will be processed
5549 : again at_eof if really needed. */
5550 58494616 : && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
5551 : {
5552 1000760 : tree thunk;
5553 :
5554 2005720 : for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
5555 : {
5556 4200 : if (!THUNK_ALIAS (thunk))
5557 : {
5558 4200 : use_thunk (thunk, /*emit_p=*/1);
5559 4200 : if (DECL_RESULT_THUNK_P (thunk))
5560 : {
5561 178 : tree probe;
5562 :
5563 178 : for (probe = DECL_THUNKS (thunk);
5564 327 : probe; probe = DECL_CHAIN (probe))
5565 149 : use_thunk (probe, /*emit_p=*/1);
5566 : }
5567 : }
5568 : else
5569 0 : gcc_assert (!DECL_THUNKS (thunk));
5570 : }
5571 : }
5572 57493125 : }
5573 :
5574 : /* Generate RTL for FN. */
5575 :
5576 : bool
5577 156806862 : expand_or_defer_fn_1 (tree fn)
5578 : {
5579 : /* When the parser calls us after finishing the body of a template
5580 : function, we don't really want to expand the body. */
5581 156806862 : if (processing_template_decl)
5582 : {
5583 : /* Normally, collection only occurs in rest_of_compilation. So,
5584 : if we don't collect here, we never collect junk generated
5585 : during the processing of templates until we hit a
5586 : non-template function. It's not safe to do this inside a
5587 : nested class, though, as the parser may have local state that
5588 : is not a GC root. */
5589 91601417 : if (!function_depth)
5590 91168560 : ggc_collect ();
5591 91601417 : return false;
5592 : }
5593 :
5594 65205445 : gcc_assert (DECL_SAVED_TREE (fn));
5595 :
5596 : /* We make a decision about linkage for these functions at the end
5597 : of the compilation. Until that point, we do not want the back
5598 : end to output them -- but we do want it to see the bodies of
5599 : these functions so that it can inline them as appropriate. */
5600 65205445 : if (DECL_DECLARED_INLINE_P (fn)
5601 1886017 : || DECL_IMPLICIT_INSTANTIATION (fn)
5602 65463325 : || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (fn))
5603 : {
5604 64947592 : if (DECL_INTERFACE_KNOWN (fn))
5605 : /* We've already made a decision as to how this function will
5606 : be handled. */;
5607 45885037 : else if (!at_eof
5608 16587122 : || DECL_IMMEDIATE_FUNCTION_P (fn)
5609 62038006 : || DECL_OMP_DECLARE_REDUCTION_P (fn))
5610 29732068 : tentative_decl_linkage (fn);
5611 : else
5612 16152969 : import_export_decl (fn);
5613 :
5614 : /* If the user wants us to keep all inline functions, then mark
5615 : this function as needed so that finish_file will make sure to
5616 : output it later. Similarly, all dllexport'd functions must
5617 : be emitted; there may be callers in other DLLs. */
5618 64947592 : if (DECL_DECLARED_INLINE_P (fn)
5619 63319428 : && !DECL_REALLY_EXTERN (fn)
5620 59801083 : && !DECL_IMMEDIATE_FUNCTION_P (fn)
5621 58837585 : && !DECL_OMP_DECLARE_REDUCTION_P (fn)
5622 123785177 : && (flag_keep_inline_functions
5623 58834803 : || (flag_keep_inline_dllexport
5624 58834803 : && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
5625 : {
5626 2782 : mark_needed (fn);
5627 2782 : DECL_EXTERNAL (fn) = 0;
5628 : }
5629 : }
5630 :
5631 : /* If this is a constructor or destructor body, we have to clone
5632 : it. */
5633 65205445 : if (maybe_clone_body (fn))
5634 : {
5635 : /* We don't want to process FN again, so pretend we've written
5636 : it out, even though we haven't. */
5637 7684160 : TREE_ASM_WRITTEN (fn) = 1;
5638 : /* If this is a constexpr function we still need the body to be
5639 : able to evaluate it. Similarly, with modules we only stream
5640 : the maybe-in-charge cdtor and regenerate the clones from it on
5641 : demand, so we also need to keep the body. Otherwise we don't
5642 : need it anymore. */
5643 7684160 : if (!maybe_constexpr_fn (fn)
5644 7684160 : && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
5645 3696260 : DECL_SAVED_TREE (fn) = void_node;
5646 7684160 : return false;
5647 : }
5648 :
5649 : /* There's no reason to do any of the work here if we're only doing
5650 : semantic analysis; this code just generates RTL. */
5651 57521285 : if (flag_syntax_only)
5652 : {
5653 : /* Pretend that this function has been written out so that we don't try
5654 : to expand it again. */
5655 28144 : TREE_ASM_WRITTEN (fn) = 1;
5656 28144 : return false;
5657 : }
5658 :
5659 57493141 : if (DECL_OMP_DECLARE_REDUCTION_P (fn))
5660 : return false;
5661 :
5662 : return true;
5663 : }
5664 :
5665 : void
5666 149142701 : expand_or_defer_fn (tree fn)
5667 : {
5668 149142701 : if (expand_or_defer_fn_1 (fn))
5669 : {
5670 49831453 : function_depth++;
5671 :
5672 : /* Expand or defer, at the whim of the compilation unit manager. */
5673 49831453 : cgraph_node::finalize_function (fn, function_depth > 1);
5674 49831453 : emit_associated_thunks (fn);
5675 :
5676 49831453 : function_depth--;
5677 :
5678 99662906 : if (DECL_IMMEDIATE_FUNCTION_P (fn))
5679 : {
5680 917945 : if (cgraph_node *node = cgraph_node::get (fn))
5681 : {
5682 917945 : node->body_removed = true;
5683 917945 : node->analyzed = false;
5684 917945 : node->definition = false;
5685 917945 : node->force_output = false;
5686 : }
5687 : }
5688 : }
5689 149142701 : }
5690 :
5691 428830 : class nrv_data
5692 : {
5693 : public:
5694 214415 : nrv_data () : visited (37) {}
5695 :
5696 : tree var;
5697 : tree result;
5698 : hash_set<tree> visited;
5699 : bool simple;
5700 : bool in_nrv_cleanup;
5701 : };
5702 :
5703 : /* Helper function for walk_tree, used by finalize_nrv below. */
5704 :
5705 : static tree
5706 19684955 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
5707 : {
5708 19684955 : class nrv_data *dp = (class nrv_data *)data;
5709 :
5710 : /* No need to walk into types. There wouldn't be any need to walk into
5711 : non-statements, except that we have to consider STMT_EXPRs. */
5712 19684955 : if (TYPE_P (*tp))
5713 178357 : *walk_subtrees = 0;
5714 :
5715 : /* Replace all uses of the NRV with the RESULT_DECL. */
5716 19506598 : else if (*tp == dp->var)
5717 465396 : *tp = dp->result;
5718 :
5719 : /* Avoid walking into the same tree more than once. Unfortunately, we
5720 : can't just use walk_tree_without duplicates because it would only call
5721 : us for the first occurrence of dp->var in the function body. */
5722 19041202 : else if (dp->visited.add (*tp))
5723 4223884 : *walk_subtrees = 0;
5724 :
5725 : /* If there's a label, we might need to destroy the NRV on goto (92407). */
5726 14817318 : else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
5727 3 : dp->simple = false;
5728 : /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
5729 : but differs from using NULL_TREE in that it indicates that we care
5730 : about the value of the RESULT_DECL. But preserve anything appended
5731 : by check_return_expr. */
5732 14817315 : else if (TREE_CODE (*tp) == RETURN_EXPR)
5733 : {
5734 219336 : tree *p = &TREE_OPERAND (*tp, 0);
5735 561083 : while (TREE_CODE (*p) == COMPOUND_EXPR)
5736 122411 : p = &TREE_OPERAND (*p, 0);
5737 219336 : if (TREE_CODE (*p) == INIT_EXPR
5738 219336 : && INIT_EXPR_NRV_P (*p))
5739 218949 : *p = dp->result;
5740 : }
5741 : /* Change all cleanups for the NRV to only run when not returning. */
5742 14597979 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5743 14597979 : && CLEANUP_DECL (*tp) == dp->var)
5744 : {
5745 118475 : dp->in_nrv_cleanup = true;
5746 118475 : cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
5747 118475 : dp->in_nrv_cleanup = false;
5748 118475 : cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
5749 118475 : *walk_subtrees = 0;
5750 :
5751 118475 : if (dp->simple)
5752 : /* For a simple NRV, just run it on the EH path. */
5753 117859 : CLEANUP_EH_ONLY (*tp) = true;
5754 : else
5755 : {
5756 : /* Not simple, we need to check current_retval_sentinel to decide
5757 : whether to run it. If it's set, we're returning normally and
5758 : don't want to destroy the NRV. If the sentinel is not set, we're
5759 : leaving scope some other way, either by flowing off the end of its
5760 : scope or throwing an exception. */
5761 1848 : tree cond = build3 (COND_EXPR, void_type_node,
5762 616 : current_retval_sentinel,
5763 616 : void_node, CLEANUP_EXPR (*tp));
5764 616 : CLEANUP_EXPR (*tp) = cond;
5765 : }
5766 :
5767 : /* If a cleanup might throw, we need to clear current_retval_sentinel on
5768 : the exception path, both so the check above succeeds and so an outer
5769 : cleanup added by maybe_splice_retval_cleanup doesn't run. */
5770 118475 : if (cp_function_chain->throwing_cleanup)
5771 : {
5772 190 : tree clear = build2 (MODIFY_EXPR, boolean_type_node,
5773 : current_retval_sentinel,
5774 : boolean_false_node);
5775 190 : if (dp->simple)
5776 : {
5777 : /* We're already only on the EH path, just prepend it. */
5778 180 : tree &exp = CLEANUP_EXPR (*tp);
5779 180 : exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
5780 : }
5781 : else
5782 : {
5783 : /* The cleanup runs on both normal and EH paths, we need another
5784 : CLEANUP_STMT to clear the flag only on the EH path. */
5785 10 : tree &bod = CLEANUP_BODY (*tp);
5786 10 : bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
5787 10 : bod, clear, current_retval_sentinel);
5788 10 : CLEANUP_EH_ONLY (bod) = true;
5789 : }
5790 : }
5791 : }
5792 : /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
5793 : want to destroy the retval before the variable goes out of scope. */
5794 14479504 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5795 4377 : && dp->in_nrv_cleanup
5796 14482506 : && CLEANUP_DECL (*tp) == dp->result)
5797 6 : CLEANUP_EXPR (*tp) = void_node;
5798 : /* Replace the DECL_EXPR for the NRV with an initialization of the
5799 : RESULT_DECL, if needed. */
5800 14479498 : else if (TREE_CODE (*tp) == DECL_EXPR
5801 14479498 : && DECL_EXPR_DECL (*tp) == dp->var)
5802 : {
5803 214417 : tree init;
5804 214417 : if (DECL_INITIAL (dp->var)
5805 214417 : && DECL_INITIAL (dp->var) != error_mark_node)
5806 87619 : init = cp_build_init_expr (dp->result,
5807 87619 : DECL_INITIAL (dp->var));
5808 : else
5809 126798 : init = build_empty_stmt (EXPR_LOCATION (*tp));
5810 214417 : DECL_INITIAL (dp->var) = NULL_TREE;
5811 214417 : SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
5812 214417 : *tp = init;
5813 : }
5814 :
5815 : /* Keep iterating. */
5816 19684955 : return NULL_TREE;
5817 : }
5818 :
5819 : /* Called from finish_function to implement the named return value
5820 : optimization by overriding all the RETURN_EXPRs and pertinent
5821 : CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5822 : RESULT_DECL for the function. */
5823 :
5824 : void
5825 214415 : finalize_nrv (tree fndecl, tree var)
5826 : {
5827 214415 : class nrv_data data;
5828 214415 : tree result = DECL_RESULT (fndecl);
5829 :
5830 : /* Copy name from VAR to RESULT. */
5831 214415 : DECL_NAME (result) = DECL_NAME (var);
5832 : /* Don't forget that we take its address. */
5833 214415 : TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
5834 : /* Finally set DECL_VALUE_EXPR to avoid assigning
5835 : a stack slot at -O0 for the original var and debug info
5836 : uses RESULT location for VAR. */
5837 214415 : SET_DECL_VALUE_EXPR (var, result);
5838 214415 : DECL_HAS_VALUE_EXPR_P (var) = 1;
5839 :
5840 214415 : data.var = var;
5841 214415 : data.result = result;
5842 214415 : data.in_nrv_cleanup = false;
5843 :
5844 : /* This is simpler for variables declared in the outer scope of
5845 : the function so we know that their lifetime always ends with a
5846 : return; see g++.dg/opt/nrv6.C. */
5847 214415 : tree outer = outer_curly_brace_block (fndecl);
5848 214415 : data.simple = chain_member (var, BLOCK_VARS (outer));
5849 :
5850 214415 : cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
5851 214415 : }
5852 :
5853 : /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5854 :
5855 : bool
5856 2239 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
5857 : bool need_copy_ctor, bool need_copy_assignment,
5858 : bool need_dtor)
5859 : {
5860 2239 : int save_errorcount = errorcount;
5861 2239 : tree info, t;
5862 :
5863 : /* Always allocate 3 elements for simplicity. These are the
5864 : function decls for the ctor, dtor, and assignment op.
5865 : This layout is known to the three lang hooks,
5866 : cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
5867 : and cxx_omp_clause_assign_op. */
5868 2239 : info = make_tree_vec (3);
5869 2239 : CP_OMP_CLAUSE_INFO (c) = info;
5870 :
5871 2239 : if (need_default_ctor || need_copy_ctor)
5872 : {
5873 1654 : if (need_default_ctor)
5874 1255 : t = get_default_ctor (type);
5875 : else
5876 399 : t = get_copy_ctor (type, tf_warning_or_error);
5877 :
5878 1654 : if (t && !trivial_fn_p (t))
5879 1400 : TREE_VEC_ELT (info, 0) = t;
5880 : }
5881 :
5882 2239 : if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
5883 1632 : TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
5884 :
5885 2239 : if (need_copy_assignment)
5886 : {
5887 397 : t = get_copy_assign (type);
5888 :
5889 397 : if (t && !trivial_fn_p (t))
5890 344 : TREE_VEC_ELT (info, 2) = t;
5891 : }
5892 :
5893 2239 : return errorcount != save_errorcount;
5894 : }
5895 :
5896 : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
5897 : FIELD_DECL, otherwise return DECL itself. */
5898 :
5899 : static tree
5900 26243 : omp_clause_decl_field (tree decl)
5901 : {
5902 26243 : if (VAR_P (decl)
5903 18396 : && DECL_HAS_VALUE_EXPR_P (decl)
5904 359 : && DECL_ARTIFICIAL (decl)
5905 359 : && DECL_LANG_SPECIFIC (decl)
5906 26578 : && DECL_OMP_PRIVATIZED_MEMBER (decl))
5907 : {
5908 328 : tree f = DECL_VALUE_EXPR (decl);
5909 328 : if (INDIRECT_REF_P (f))
5910 0 : f = TREE_OPERAND (f, 0);
5911 328 : if (TREE_CODE (f) == COMPONENT_REF)
5912 : {
5913 328 : f = TREE_OPERAND (f, 1);
5914 328 : gcc_assert (TREE_CODE (f) == FIELD_DECL);
5915 : return f;
5916 : }
5917 : }
5918 : return NULL_TREE;
5919 : }
5920 :
5921 : /* Adjust DECL if needed for printing using %qE. */
5922 :
5923 : static tree
5924 187 : omp_clause_printable_decl (tree decl)
5925 : {
5926 0 : tree t = omp_clause_decl_field (decl);
5927 187 : if (t)
5928 45 : return t;
5929 : return decl;
5930 : }
5931 :
5932 : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
5933 : VAR_DECL T that doesn't need a DECL_EXPR added, record it for
5934 : privatization. */
5935 :
5936 : static void
5937 219 : omp_note_field_privatization (tree f, tree t)
5938 : {
5939 219 : if (!omp_private_member_map)
5940 71 : omp_private_member_map = new hash_map<tree, tree>;
5941 219 : tree &v = omp_private_member_map->get_or_insert (f);
5942 219 : if (v == NULL_TREE)
5943 : {
5944 146 : v = t;
5945 146 : omp_private_member_vec.safe_push (f);
5946 : /* Signal that we don't want to create DECL_EXPR for this dummy var. */
5947 146 : omp_private_member_vec.safe_push (integer_zero_node);
5948 : }
5949 219 : }
5950 :
5951 : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
5952 : dummy VAR_DECL. */
5953 :
5954 : tree
5955 861 : omp_privatize_field (tree t, bool shared)
5956 : {
5957 861 : tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
5958 861 : if (m == error_mark_node)
5959 : return error_mark_node;
5960 861 : if (!omp_private_member_map && !shared)
5961 365 : omp_private_member_map = new hash_map<tree, tree>;
5962 861 : if (TYPE_REF_P (TREE_TYPE (t)))
5963 : {
5964 123 : gcc_assert (INDIRECT_REF_P (m));
5965 123 : m = TREE_OPERAND (m, 0);
5966 : }
5967 861 : tree vb = NULL_TREE;
5968 861 : tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
5969 861 : if (v == NULL_TREE)
5970 : {
5971 770 : v = create_temporary_var (TREE_TYPE (m));
5972 770 : retrofit_lang_decl (v);
5973 770 : DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
5974 770 : SET_DECL_VALUE_EXPR (v, m);
5975 770 : DECL_HAS_VALUE_EXPR_P (v) = 1;
5976 770 : if (!shared)
5977 690 : omp_private_member_vec.safe_push (t);
5978 : }
5979 861 : return v;
5980 : }
5981 :
5982 : /* C++ specialisation of the c_omp_address_inspector class. */
5983 :
5984 : class cp_omp_address_inspector : public c_omp_address_inspector
5985 : {
5986 : public:
5987 30734 : cp_omp_address_inspector (location_t loc, tree t)
5988 30734 : : c_omp_address_inspector (loc, t)
5989 : {
5990 : }
5991 :
5992 30734 : ~cp_omp_address_inspector ()
5993 : {
5994 22433 : }
5995 :
5996 130460 : bool processing_template_decl_p ()
5997 : {
5998 130460 : return processing_template_decl;
5999 : }
6000 :
6001 0 : void emit_unmappable_type_notes (tree t)
6002 : {
6003 0 : if (TREE_TYPE (t) != error_mark_node
6004 0 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
6005 0 : cxx_incomplete_type_inform (TREE_TYPE (t));
6006 0 : }
6007 :
6008 1058 : tree convert_from_reference (tree x)
6009 : {
6010 1058 : return ::convert_from_reference (x);
6011 : }
6012 :
6013 141 : tree build_array_ref (location_t loc, tree arr, tree idx)
6014 : {
6015 141 : return ::build_array_ref (loc, arr, idx);
6016 : }
6017 :
6018 22375 : bool check_clause (tree clause)
6019 : {
6020 22375 : if (TREE_CODE (orig) == COMPONENT_REF
6021 22375 : && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
6022 : tf_warning_or_error))
6023 : return false;
6024 22372 : if (!c_omp_address_inspector::check_clause (clause))
6025 : return false;
6026 : return true;
6027 : }
6028 : };
6029 :
6030 : /* Helper function for handle_omp_array_sections. Called recursively
6031 : to handle multiple array-section-subscripts. C is the clause,
6032 : T current expression (initially OMP_CLAUSE_DECL), which is either
6033 : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
6034 : expression if specified, TREE_VALUE length expression if specified,
6035 : TREE_CHAIN is what it has been specified after, or some decl.
6036 : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
6037 : set to true if any of the array-section-subscript could have length
6038 : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
6039 : first array-section-subscript which is known not to have length
6040 : of one. Given say:
6041 : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
6042 : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
6043 : all are or may have length of 1, array-section-subscript [:2] is the
6044 : first one known not to have length 1. For array-section-subscript
6045 : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
6046 : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
6047 : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
6048 : case though, as some lengths could be zero. */
6049 :
6050 : static tree
6051 20464 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
6052 : bool &maybe_zero_len, unsigned int &first_non_one,
6053 : enum c_omp_region_type ort)
6054 : {
6055 20464 : tree ret, low_bound, length, type;
6056 20464 : bool openacc = (ort & C_ORT_ACC) != 0;
6057 20464 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
6058 : {
6059 9274 : if (error_operand_p (t))
6060 6 : return error_mark_node;
6061 :
6062 9268 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6063 9268 : tree t_refto = ai.maybe_unconvert_ref (t);
6064 :
6065 9268 : if (!ai.check_clause (c))
6066 0 : return error_mark_node;
6067 9268 : else if (ai.component_access_p ()
6068 10656 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6069 64 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
6070 40 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
6071 1388 : t = ai.get_root_term (true);
6072 : else
6073 7880 : t = ai.unconverted_ref_origin ();
6074 9268 : if (t == error_mark_node)
6075 : return error_mark_node;
6076 9268 : ret = t_refto;
6077 9268 : if (TREE_CODE (t) == FIELD_DECL)
6078 33 : ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6079 9235 : else if (!VAR_P (t)
6080 2702 : && (openacc || !EXPR_P (t))
6081 2507 : && TREE_CODE (t) != PARM_DECL)
6082 : {
6083 48 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6084 : return NULL_TREE;
6085 30 : if (DECL_P (t))
6086 30 : error_at (OMP_CLAUSE_LOCATION (c),
6087 : "%qD is not a variable in %qs clause", t,
6088 30 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6089 : else
6090 0 : error_at (OMP_CLAUSE_LOCATION (c),
6091 : "%qE is not a variable in %qs clause", t,
6092 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6093 30 : return error_mark_node;
6094 : }
6095 9187 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6096 8997 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6097 17256 : && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
6098 : {
6099 17 : error_at (OMP_CLAUSE_LOCATION (c),
6100 : "%qD is threadprivate variable in %qs clause", t,
6101 17 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6102 17 : return error_mark_node;
6103 : }
6104 9203 : if (type_dependent_expression_p (ret))
6105 : return NULL_TREE;
6106 8516 : ret = convert_from_reference (ret);
6107 8516 : return ret;
6108 9268 : }
6109 :
6110 11190 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
6111 7387 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6112 6193 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6113 4909 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6114 13796 : && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
6115 43 : TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
6116 11190 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
6117 : maybe_zero_len, first_non_one, ort);
6118 11190 : if (ret == error_mark_node || ret == NULL_TREE)
6119 : return ret;
6120 :
6121 10186 : type = TREE_TYPE (ret);
6122 10186 : low_bound = TREE_OPERAND (t, 1);
6123 10186 : length = TREE_OPERAND (t, 2);
6124 8239 : if ((low_bound && type_dependent_expression_p (low_bound))
6125 18342 : || (length && type_dependent_expression_p (length)))
6126 88 : return NULL_TREE;
6127 :
6128 10098 : if (low_bound == error_mark_node || length == error_mark_node)
6129 : return error_mark_node;
6130 :
6131 10098 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
6132 : {
6133 69 : error_at (OMP_CLAUSE_LOCATION (c),
6134 : "low bound %qE of array section does not have integral type",
6135 : low_bound);
6136 69 : return error_mark_node;
6137 : }
6138 10029 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
6139 : {
6140 63 : error_at (OMP_CLAUSE_LOCATION (c),
6141 : "length %qE of array section does not have integral type",
6142 : length);
6143 63 : return error_mark_node;
6144 : }
6145 9966 : if (low_bound)
6146 8073 : low_bound = mark_rvalue_use (low_bound);
6147 9966 : if (length)
6148 9020 : length = mark_rvalue_use (length);
6149 : /* We need to reduce to real constant-values for checks below. */
6150 9020 : if (length)
6151 9020 : length = fold_simple (length);
6152 9966 : if (low_bound)
6153 8073 : low_bound = fold_simple (low_bound);
6154 8073 : if (low_bound
6155 8073 : && TREE_CODE (low_bound) == INTEGER_CST
6156 15221 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6157 7148 : > TYPE_PRECISION (sizetype))
6158 0 : low_bound = fold_convert (sizetype, low_bound);
6159 9966 : if (length
6160 9020 : && TREE_CODE (length) == INTEGER_CST
6161 16975 : && TYPE_PRECISION (TREE_TYPE (length))
6162 7009 : > TYPE_PRECISION (sizetype))
6163 0 : length = fold_convert (sizetype, length);
6164 9966 : if (low_bound == NULL_TREE)
6165 1893 : low_bound = integer_zero_node;
6166 :
6167 9966 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6168 9966 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
6169 5082 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
6170 : {
6171 60 : if (length != integer_one_node)
6172 : {
6173 36 : error_at (OMP_CLAUSE_LOCATION (c),
6174 : "expected single pointer in %qs clause",
6175 : user_omp_clause_code_name (c, openacc));
6176 36 : return error_mark_node;
6177 : }
6178 : }
6179 9930 : if (length != NULL_TREE)
6180 : {
6181 9008 : if (!integer_nonzerop (length))
6182 : {
6183 2058 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6184 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6185 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6186 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6187 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6188 : {
6189 459 : if (integer_zerop (length))
6190 : {
6191 28 : error_at (OMP_CLAUSE_LOCATION (c),
6192 : "zero length array section in %qs clause",
6193 28 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6194 28 : return error_mark_node;
6195 : }
6196 : }
6197 : else
6198 1599 : maybe_zero_len = true;
6199 : }
6200 8980 : if (first_non_one == types.length ()
6201 8980 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
6202 3930 : first_non_one++;
6203 : }
6204 9902 : if (TREE_CODE (type) == ARRAY_TYPE)
6205 : {
6206 5461 : if (length == NULL_TREE
6207 5461 : && (TYPE_DOMAIN (type) == NULL_TREE
6208 850 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
6209 : {
6210 30 : error_at (OMP_CLAUSE_LOCATION (c),
6211 : "for unknown bound array type length expression must "
6212 : "be specified");
6213 30 : return error_mark_node;
6214 : }
6215 5431 : if (TREE_CODE (low_bound) == INTEGER_CST
6216 5431 : && tree_int_cst_sgn (low_bound) == -1)
6217 : {
6218 153 : error_at (OMP_CLAUSE_LOCATION (c),
6219 : "negative low bound in array section in %qs clause",
6220 153 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6221 153 : return error_mark_node;
6222 : }
6223 5278 : if (length != NULL_TREE
6224 4476 : && TREE_CODE (length) == INTEGER_CST
6225 8836 : && tree_int_cst_sgn (length) == -1)
6226 : {
6227 153 : error_at (OMP_CLAUSE_LOCATION (c),
6228 : "negative length in array section in %qs clause",
6229 153 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6230 153 : return error_mark_node;
6231 : }
6232 5125 : if (TYPE_DOMAIN (type)
6233 5031 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6234 10156 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
6235 : == INTEGER_CST)
6236 : {
6237 4635 : tree size
6238 4635 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6239 4635 : size = size_binop (PLUS_EXPR, size, size_one_node);
6240 4635 : if (TREE_CODE (low_bound) == INTEGER_CST)
6241 : {
6242 3868 : if (tree_int_cst_lt (size, low_bound))
6243 : {
6244 54 : error_at (OMP_CLAUSE_LOCATION (c),
6245 : "low bound %qE above array section size "
6246 : "in %qs clause", low_bound,
6247 54 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6248 54 : return error_mark_node;
6249 : }
6250 3814 : if (tree_int_cst_equal (size, low_bound))
6251 : {
6252 17 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6253 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6254 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6255 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6256 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6257 : {
6258 17 : error_at (OMP_CLAUSE_LOCATION (c),
6259 : "zero length array section in %qs clause",
6260 17 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6261 17 : return error_mark_node;
6262 : }
6263 0 : maybe_zero_len = true;
6264 : }
6265 3797 : else if (length == NULL_TREE
6266 1420 : && first_non_one == types.length ()
6267 4095 : && tree_int_cst_equal
6268 298 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6269 : low_bound))
6270 195 : first_non_one++;
6271 : }
6272 767 : else if (length == NULL_TREE)
6273 : {
6274 20 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6275 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6276 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6277 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6278 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6279 13 : maybe_zero_len = true;
6280 40 : if (first_non_one == types.length ())
6281 17 : first_non_one++;
6282 : }
6283 4564 : if (length && TREE_CODE (length) == INTEGER_CST)
6284 : {
6285 3290 : if (tree_int_cst_lt (size, length))
6286 : {
6287 57 : error_at (OMP_CLAUSE_LOCATION (c),
6288 : "length %qE above array section size "
6289 : "in %qs clause", length,
6290 57 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6291 57 : return error_mark_node;
6292 : }
6293 3233 : if (TREE_CODE (low_bound) == INTEGER_CST)
6294 : {
6295 2899 : tree lbpluslen
6296 2899 : = size_binop (PLUS_EXPR,
6297 : fold_convert (sizetype, low_bound),
6298 : fold_convert (sizetype, length));
6299 2899 : if (TREE_CODE (lbpluslen) == INTEGER_CST
6300 2899 : && tree_int_cst_lt (size, lbpluslen))
6301 : {
6302 54 : error_at (OMP_CLAUSE_LOCATION (c),
6303 : "high bound %qE above array section size "
6304 : "in %qs clause", lbpluslen,
6305 54 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6306 54 : return error_mark_node;
6307 : }
6308 : }
6309 : }
6310 : }
6311 490 : else if (length == NULL_TREE)
6312 : {
6313 1 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6314 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6315 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6316 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6317 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6318 0 : maybe_zero_len = true;
6319 2 : if (first_non_one == types.length ())
6320 1 : first_non_one++;
6321 : }
6322 :
6323 : /* For [lb:] we will need to evaluate lb more than once. */
6324 3911 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6325 : {
6326 650 : tree lb = cp_save_expr (low_bound);
6327 650 : if (lb != low_bound)
6328 : {
6329 9 : TREE_OPERAND (t, 1) = lb;
6330 9 : low_bound = lb;
6331 : }
6332 : }
6333 : }
6334 4441 : else if (TYPE_PTR_P (type))
6335 : {
6336 4384 : if (length == NULL_TREE)
6337 : {
6338 42 : if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
6339 36 : error_at (OMP_CLAUSE_LOCATION (c),
6340 : "for array function parameter length expression "
6341 : "must be specified");
6342 : else
6343 6 : error_at (OMP_CLAUSE_LOCATION (c),
6344 : "for pointer type length expression must be specified");
6345 42 : return error_mark_node;
6346 : }
6347 4342 : if (length != NULL_TREE
6348 4342 : && TREE_CODE (length) == INTEGER_CST
6349 3249 : && tree_int_cst_sgn (length) == -1)
6350 : {
6351 84 : error_at (OMP_CLAUSE_LOCATION (c),
6352 : "negative length in array section in %qs clause",
6353 84 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6354 84 : return error_mark_node;
6355 : }
6356 : /* If there is a pointer type anywhere but in the very first
6357 : array-section-subscript, the array section could be non-contiguous. */
6358 4258 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6359 4216 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6360 7990 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
6361 : {
6362 : /* If any prior dimension has a non-one length, then deem this
6363 : array section as non-contiguous. */
6364 158 : for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
6365 69 : d = TREE_OPERAND (d, 0))
6366 : {
6367 89 : tree d_length = TREE_OPERAND (d, 2);
6368 89 : if (d_length == NULL_TREE || !integer_onep (d_length))
6369 : {
6370 20 : error_at (OMP_CLAUSE_LOCATION (c),
6371 : "array section is not contiguous in %qs clause",
6372 20 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6373 20 : return error_mark_node;
6374 : }
6375 : }
6376 : }
6377 : }
6378 : else
6379 : {
6380 57 : error_at (OMP_CLAUSE_LOCATION (c),
6381 : "%qE does not have pointer or array type", ret);
6382 57 : return error_mark_node;
6383 : }
6384 9181 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6385 8277 : types.safe_push (TREE_TYPE (ret));
6386 : /* We will need to evaluate lb more than once. */
6387 9181 : tree lb = cp_save_expr (low_bound);
6388 9181 : if (lb != low_bound)
6389 : {
6390 716 : TREE_OPERAND (t, 1) = lb;
6391 716 : low_bound = lb;
6392 : }
6393 : /* Temporarily disable -fstrong-eval-order for array reductions.
6394 : The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
6395 : is something the middle-end can't cope with and more importantly,
6396 : it needs to be the actual base variable that is privatized, not some
6397 : temporary assigned previous value of it. That, together with OpenMP
6398 : saying how many times the side-effects are evaluated is unspecified,
6399 : makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
6400 9181 : warning_sentinel s (flag_strong_eval_order,
6401 9181 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6402 8168 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6403 18481 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
6404 9181 : ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
6405 : tf_warning_or_error);
6406 9181 : return ret;
6407 9181 : }
6408 :
6409 : /* Handle array sections for clause C. */
6410 :
6411 : static bool
6412 9274 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
6413 : {
6414 9274 : bool maybe_zero_len = false;
6415 9274 : unsigned int first_non_one = 0;
6416 9274 : auto_vec<tree, 10> types;
6417 9274 : tree *tp = &OMP_CLAUSE_DECL (c);
6418 9274 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6419 8316 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6420 9480 : && OMP_ITERATOR_DECL_P (*tp))
6421 258 : tp = &TREE_VALUE (*tp);
6422 9274 : tree first = handle_omp_array_sections_1 (c, *tp, types,
6423 : maybe_zero_len, first_non_one,
6424 : ort);
6425 9274 : if (first == error_mark_node)
6426 : return true;
6427 8304 : if (first == NULL_TREE)
6428 : return false;
6429 7511 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6430 7511 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6431 : {
6432 850 : tree t = *tp;
6433 850 : tree tem = NULL_TREE;
6434 850 : if (processing_template_decl)
6435 : return false;
6436 : /* Need to evaluate side effects in the length expressions
6437 : if any. */
6438 751 : while (TREE_CODE (t) == TREE_LIST)
6439 : {
6440 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
6441 : {
6442 0 : if (tem == NULL_TREE)
6443 : tem = TREE_VALUE (t);
6444 : else
6445 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
6446 0 : TREE_VALUE (t), tem);
6447 : }
6448 0 : t = TREE_CHAIN (t);
6449 : }
6450 751 : if (tem)
6451 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
6452 751 : *tp = first;
6453 : }
6454 : else
6455 : {
6456 6661 : unsigned int num = types.length (), i;
6457 6661 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
6458 6661 : tree condition = NULL_TREE;
6459 :
6460 6661 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
6461 3 : maybe_zero_len = true;
6462 6661 : if (processing_template_decl && maybe_zero_len)
6463 : return false;
6464 :
6465 14012 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
6466 7429 : t = TREE_OPERAND (t, 0))
6467 : {
6468 7500 : gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
6469 :
6470 7500 : tree low_bound = TREE_OPERAND (t, 1);
6471 7500 : tree length = TREE_OPERAND (t, 2);
6472 :
6473 7500 : i--;
6474 7500 : if (low_bound
6475 6117 : && TREE_CODE (low_bound) == INTEGER_CST
6476 13006 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6477 5506 : > TYPE_PRECISION (sizetype))
6478 0 : low_bound = fold_convert (sizetype, low_bound);
6479 7500 : if (length
6480 6981 : && TREE_CODE (length) == INTEGER_CST
6481 12589 : && TYPE_PRECISION (TREE_TYPE (length))
6482 5089 : > TYPE_PRECISION (sizetype))
6483 0 : length = fold_convert (sizetype, length);
6484 7500 : if (low_bound == NULL_TREE)
6485 1383 : low_bound = integer_zero_node;
6486 7500 : if (!maybe_zero_len && i > first_non_one)
6487 : {
6488 629 : if (integer_nonzerop (low_bound))
6489 34 : goto do_warn_noncontiguous;
6490 595 : if (length != NULL_TREE
6491 273 : && TREE_CODE (length) == INTEGER_CST
6492 273 : && TYPE_DOMAIN (types[i])
6493 273 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
6494 868 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
6495 : == INTEGER_CST)
6496 : {
6497 273 : tree size;
6498 273 : size = size_binop (PLUS_EXPR,
6499 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6500 : size_one_node);
6501 273 : if (!tree_int_cst_equal (length, size))
6502 : {
6503 37 : do_warn_noncontiguous:
6504 142 : error_at (OMP_CLAUSE_LOCATION (c),
6505 : "array section is not contiguous in %qs "
6506 : "clause",
6507 71 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6508 71 : return true;
6509 : }
6510 : }
6511 558 : if (!processing_template_decl
6512 390 : && length != NULL_TREE
6513 723 : && TREE_SIDE_EFFECTS (length))
6514 : {
6515 0 : if (side_effects == NULL_TREE)
6516 : side_effects = length;
6517 : else
6518 0 : side_effects = build2 (COMPOUND_EXPR,
6519 0 : TREE_TYPE (side_effects),
6520 : length, side_effects);
6521 : }
6522 : }
6523 6871 : else if (processing_template_decl)
6524 698 : continue;
6525 : else
6526 : {
6527 6173 : tree l;
6528 :
6529 6173 : if (i > first_non_one
6530 6173 : && ((length && integer_nonzerop (length))
6531 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6532 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6533 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
6534 0 : continue;
6535 6173 : if (length)
6536 6056 : l = fold_convert (sizetype, length);
6537 : else
6538 : {
6539 117 : l = size_binop (PLUS_EXPR,
6540 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6541 : size_one_node);
6542 117 : l = size_binop (MINUS_EXPR, l,
6543 : fold_convert (sizetype, low_bound));
6544 : }
6545 6173 : if (i > first_non_one)
6546 : {
6547 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
6548 : size_zero_node);
6549 0 : if (condition == NULL_TREE)
6550 : condition = l;
6551 : else
6552 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
6553 : l, condition);
6554 : }
6555 6173 : else if (size == NULL_TREE)
6556 : {
6557 5895 : size = size_in_bytes (TREE_TYPE (types[i]));
6558 5895 : tree eltype = TREE_TYPE (types[num - 1]);
6559 5964 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6560 69 : eltype = TREE_TYPE (eltype);
6561 5895 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6562 5145 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6563 10287 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6564 1599 : size = size_binop (EXACT_DIV_EXPR, size,
6565 : size_in_bytes (eltype));
6566 5895 : size = size_binop (MULT_EXPR, size, l);
6567 5895 : if (condition)
6568 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
6569 : size, size_zero_node);
6570 : }
6571 : else
6572 278 : size = size_binop (MULT_EXPR, size, l);
6573 : }
6574 : }
6575 6512 : if (!processing_template_decl)
6576 : {
6577 5895 : if (side_effects)
6578 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
6579 5895 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6580 5145 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6581 10287 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6582 : {
6583 1599 : size = size_binop (MINUS_EXPR, size, size_one_node);
6584 1599 : size = save_expr (size);
6585 1599 : tree index_type = build_index_type (size);
6586 1599 : tree eltype = TREE_TYPE (first);
6587 1628 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6588 29 : eltype = TREE_TYPE (eltype);
6589 1599 : tree type = build_array_type (eltype, index_type);
6590 1599 : tree ptype = build_pointer_type (eltype);
6591 1599 : if (TYPE_REF_P (TREE_TYPE (t))
6592 1599 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
6593 152 : t = convert_from_reference (t);
6594 1447 : else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6595 629 : t = build_fold_addr_expr (t);
6596 1599 : tree t2 = build_fold_addr_expr (first);
6597 1599 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6598 : ptrdiff_type_node, t2);
6599 1599 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
6600 : ptrdiff_type_node, t2,
6601 1599 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6602 : ptrdiff_type_node, t));
6603 1599 : if (tree_fits_shwi_p (t2))
6604 1261 : t = build2 (MEM_REF, type, t,
6605 1261 : build_int_cst (ptype, tree_to_shwi (t2)));
6606 : else
6607 : {
6608 338 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6609 : sizetype, t2);
6610 338 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
6611 338 : TREE_TYPE (t), t, t2);
6612 338 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
6613 : }
6614 1599 : OMP_CLAUSE_DECL (c) = t;
6615 7494 : return false;
6616 : }
6617 4296 : OMP_CLAUSE_DECL (c) = first;
6618 4296 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
6619 : return false;
6620 4270 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
6621 4270 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
6622 3730 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
6623 3718 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
6624 4246 : OMP_CLAUSE_SIZE (c) = size;
6625 4270 : if (TREE_CODE (t) == FIELD_DECL)
6626 3 : t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6627 :
6628 4270 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6629 : return false;
6630 :
6631 3742 : if (TREE_CODE (first) == INDIRECT_REF)
6632 : {
6633 : /* Detect and skip adding extra nodes for pointer-to-member
6634 : mappings. These are unsupported for now. */
6635 2407 : tree tmp = TREE_OPERAND (first, 0);
6636 :
6637 2407 : if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
6638 1911 : tmp = TREE_OPERAND (tmp, 0);
6639 :
6640 2407 : if (TREE_CODE (tmp) == INDIRECT_REF)
6641 158 : tmp = TREE_OPERAND (tmp, 0);
6642 :
6643 2407 : if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
6644 : {
6645 466 : tree offset = TREE_OPERAND (tmp, 1);
6646 466 : STRIP_NOPS (offset);
6647 466 : if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
6648 : {
6649 36 : sorry_at (OMP_CLAUSE_LOCATION (c),
6650 : "pointer-to-member mapping %qE not supported",
6651 18 : OMP_CLAUSE_DECL (c));
6652 18 : return true;
6653 : }
6654 : }
6655 : }
6656 :
6657 : /* FIRST represents the first item of data that we are mapping.
6658 : E.g. if we're mapping an array, FIRST might resemble
6659 : "foo.bar.myarray[0]". */
6660 :
6661 3724 : auto_vec<omp_addr_token *, 10> addr_tokens;
6662 :
6663 3724 : if (!omp_parse_expr (addr_tokens, first))
6664 : return true;
6665 :
6666 3724 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6667 :
6668 3724 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
6669 3724 : if (nc != error_mark_node)
6670 : {
6671 3724 : using namespace omp_addr_tokenizer;
6672 :
6673 3724 : if (ai.maybe_zero_length_array_section (c))
6674 3700 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
6675 :
6676 : /* !!! If we're accessing a base decl via chained access
6677 : methods (e.g. multiple indirections), duplicate clause
6678 : detection won't work properly. Skip it in that case. */
6679 3724 : if ((addr_tokens[0]->type == STRUCTURE_BASE
6680 2707 : || addr_tokens[0]->type == ARRAY_BASE)
6681 3724 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
6682 3713 : && addr_tokens[1]->type == ACCESS_METHOD
6683 7437 : && omp_access_chain_p (addr_tokens, 1))
6684 216 : c = nc;
6685 :
6686 3724 : return false;
6687 : }
6688 7448 : }
6689 : }
6690 : return false;
6691 9274 : }
6692 :
6693 : /* Return identifier to look up for omp declare reduction. */
6694 :
6695 : tree
6696 7085 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
6697 : {
6698 7085 : const char *p = NULL;
6699 7085 : const char *m = NULL;
6700 7085 : switch (reduction_code)
6701 : {
6702 4188 : case PLUS_EXPR:
6703 4188 : case MULT_EXPR:
6704 4188 : case MINUS_EXPR:
6705 4188 : case BIT_AND_EXPR:
6706 4188 : case BIT_XOR_EXPR:
6707 4188 : case BIT_IOR_EXPR:
6708 4188 : case TRUTH_ANDIF_EXPR:
6709 4188 : case TRUTH_ORIF_EXPR:
6710 4188 : reduction_id = ovl_op_identifier (false, reduction_code);
6711 4188 : break;
6712 : case MIN_EXPR:
6713 : p = "min";
6714 : break;
6715 : case MAX_EXPR:
6716 : p = "max";
6717 : break;
6718 : default:
6719 : break;
6720 : }
6721 :
6722 4188 : if (p == NULL)
6723 : {
6724 6921 : if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
6725 0 : return error_mark_node;
6726 6921 : p = IDENTIFIER_POINTER (reduction_id);
6727 : }
6728 :
6729 7085 : if (type != NULL_TREE)
6730 2033 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6731 :
6732 7085 : const char prefix[] = "omp declare reduction ";
6733 7085 : size_t lenp = sizeof (prefix);
6734 7085 : if (strncmp (p, prefix, lenp - 1) == 0)
6735 2033 : lenp = 1;
6736 7085 : size_t len = strlen (p);
6737 7085 : size_t lenm = m ? strlen (m) + 1 : 0;
6738 7085 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6739 7085 : if (lenp > 1)
6740 5052 : memcpy (name, prefix, lenp - 1);
6741 7085 : memcpy (name + lenp - 1, p, len + 1);
6742 7085 : if (m)
6743 : {
6744 2033 : name[lenp + len - 1] = '~';
6745 2033 : memcpy (name + lenp + len, m, lenm);
6746 : }
6747 7085 : return get_identifier (name);
6748 : }
6749 :
6750 : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
6751 : FUNCTION_DECL or NULL_TREE if not found. */
6752 :
6753 : static tree
6754 1288 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
6755 : vec<tree> *ambiguousp)
6756 : {
6757 1288 : tree orig_id = id;
6758 1288 : tree baselink = NULL_TREE;
6759 1288 : if (identifier_p (id))
6760 : {
6761 1260 : cp_id_kind idk;
6762 1260 : bool nonint_cst_expression_p;
6763 1260 : const char *error_msg;
6764 1260 : id = omp_reduction_id (ERROR_MARK, id, type);
6765 1260 : tree decl = lookup_name (id);
6766 1260 : if (decl == NULL_TREE)
6767 80 : decl = error_mark_node;
6768 1260 : id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
6769 : &nonint_cst_expression_p, false, true, false,
6770 : false, &error_msg, loc);
6771 1260 : if (idk == CP_ID_KIND_UNQUALIFIED
6772 1340 : && identifier_p (id))
6773 : {
6774 80 : vec<tree, va_gc> *args = NULL;
6775 80 : vec_safe_push (args, build_reference_type (type));
6776 80 : id = perform_koenig_lookup (id, args, tf_none);
6777 : }
6778 : }
6779 28 : else if (TREE_CODE (id) == SCOPE_REF)
6780 28 : id = lookup_qualified_name (TREE_OPERAND (id, 0),
6781 : omp_reduction_id (ERROR_MARK,
6782 28 : TREE_OPERAND (id, 1),
6783 : type),
6784 : LOOK_want::NORMAL, false);
6785 1288 : tree fns = id;
6786 1288 : id = NULL_TREE;
6787 1288 : if (fns && is_overloaded_fn (fns))
6788 : {
6789 1214 : for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
6790 : {
6791 1214 : tree fndecl = *iter;
6792 1214 : if (TREE_CODE (fndecl) == FUNCTION_DECL)
6793 : {
6794 1214 : tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
6795 1214 : if (same_type_p (TREE_TYPE (argtype), type))
6796 : {
6797 1214 : id = fndecl;
6798 1214 : break;
6799 : }
6800 : }
6801 : }
6802 :
6803 1214 : if (id && BASELINK_P (fns))
6804 : {
6805 74 : if (baselinkp)
6806 0 : *baselinkp = fns;
6807 : else
6808 74 : baselink = fns;
6809 : }
6810 : }
6811 :
6812 1288 : if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
6813 : {
6814 35 : auto_vec<tree> ambiguous;
6815 35 : tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
6816 35 : unsigned int ix;
6817 35 : if (ambiguousp == NULL)
6818 19 : ambiguousp = &ambiguous;
6819 73 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
6820 : {
6821 52 : id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
6822 : baselinkp ? baselinkp : &baselink,
6823 : ambiguousp);
6824 38 : if (id == NULL_TREE)
6825 14 : continue;
6826 24 : if (!ambiguousp->is_empty ())
6827 3 : ambiguousp->safe_push (id);
6828 21 : else if (ret != NULL_TREE)
6829 : {
6830 6 : ambiguousp->safe_push (ret);
6831 6 : ambiguousp->safe_push (id);
6832 6 : ret = NULL_TREE;
6833 : }
6834 : else
6835 15 : ret = id;
6836 : }
6837 35 : if (ambiguousp != &ambiguous)
6838 16 : return ret;
6839 19 : if (!ambiguous.is_empty ())
6840 : {
6841 6 : auto_diagnostic_group d;
6842 6 : const char *str = _("candidates are:");
6843 6 : unsigned int idx;
6844 6 : tree udr;
6845 6 : error_at (loc, "user defined reduction lookup is ambiguous");
6846 27 : FOR_EACH_VEC_ELT (ambiguous, idx, udr)
6847 : {
6848 15 : inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
6849 15 : if (idx == 0)
6850 6 : str = get_spaces (str);
6851 : }
6852 6 : ret = error_mark_node;
6853 6 : baselink = NULL_TREE;
6854 6 : }
6855 19 : id = ret;
6856 35 : }
6857 1272 : if (id && baselink)
6858 74 : perform_or_defer_access_check (BASELINK_BINFO (baselink),
6859 : id, id, tf_warning_or_error);
6860 : return id;
6861 : }
6862 :
6863 : /* Return identifier to look up for omp declare mapper. */
6864 :
6865 : tree
6866 3995 : omp_mapper_id (tree mapper_id, tree type)
6867 : {
6868 3995 : const char *p = NULL;
6869 3995 : const char *m = NULL;
6870 :
6871 3995 : if (mapper_id == NULL_TREE)
6872 : p = "";
6873 68 : else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
6874 68 : p = IDENTIFIER_POINTER (mapper_id);
6875 : else
6876 0 : return error_mark_node;
6877 :
6878 3995 : if (type != NULL_TREE)
6879 3993 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6880 :
6881 3995 : const char prefix[] = "omp declare mapper ";
6882 3995 : size_t lenp = sizeof (prefix);
6883 3995 : if (strncmp (p, prefix, lenp - 1) == 0)
6884 2 : lenp = 1;
6885 3995 : size_t len = strlen (p);
6886 3995 : size_t lenm = m ? strlen (m) + 1 : 0;
6887 3995 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6888 3995 : memcpy (name, prefix, lenp - 1);
6889 3995 : memcpy (name + lenp - 1, p, len + 1);
6890 3995 : if (m)
6891 : {
6892 3993 : name[lenp + len - 1] = '~';
6893 3993 : memcpy (name + lenp + len, m, lenm);
6894 : }
6895 3995 : return get_identifier (name);
6896 : }
6897 :
6898 : tree
6899 8502 : cxx_omp_mapper_lookup (tree id, tree type)
6900 : {
6901 8502 : if (!RECORD_OR_UNION_TYPE_P (type))
6902 : return NULL_TREE;
6903 3773 : id = omp_mapper_id (id, type);
6904 3773 : return lookup_name (id);
6905 : }
6906 :
6907 : tree
6908 336 : cxx_omp_extract_mapper_directive (tree vardecl)
6909 : {
6910 336 : gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
6911 :
6912 : /* Instantiate the decl if we haven't already. */
6913 336 : mark_used (vardecl);
6914 336 : tree body = DECL_INITIAL (vardecl);
6915 :
6916 336 : if (TREE_CODE (body) == STATEMENT_LIST)
6917 : {
6918 0 : tree_stmt_iterator tsi = tsi_start (body);
6919 0 : gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
6920 0 : tsi_next (&tsi);
6921 0 : body = tsi_stmt (tsi);
6922 : }
6923 :
6924 336 : gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
6925 :
6926 336 : return body;
6927 : }
6928 :
6929 : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
6930 : nothing more complicated. */
6931 :
6932 : tree
6933 1782 : cxx_omp_map_array_section (location_t loc, tree t)
6934 : {
6935 1782 : tree low = TREE_OPERAND (t, 1);
6936 1782 : tree len = TREE_OPERAND (t, 2);
6937 :
6938 1782 : if (len && integer_onep (len))
6939 : {
6940 268 : t = TREE_OPERAND (t, 0);
6941 :
6942 268 : if (!low)
6943 17 : low = integer_zero_node;
6944 :
6945 268 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
6946 6 : t = convert_from_reference (t);
6947 :
6948 268 : if (TYPE_PTR_P (TREE_TYPE (t)))
6949 215 : t = build_array_ref (loc, t, low);
6950 : else
6951 53 : t = error_mark_node;
6952 : }
6953 :
6954 1782 : return t;
6955 : }
6956 :
6957 : /* Helper function for cp_parser_omp_declare_reduction_exprs
6958 : and tsubst_omp_udr.
6959 : Remove CLEANUP_STMT for data (omp_priv variable).
6960 : Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
6961 : DECL_EXPR. */
6962 :
6963 : tree
6964 4395 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
6965 : {
6966 4395 : if (TYPE_P (*tp))
6967 227 : *walk_subtrees = 0;
6968 4168 : else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
6969 52 : *tp = CLEANUP_BODY (*tp);
6970 4116 : else if (TREE_CODE (*tp) == DECL_EXPR)
6971 : {
6972 307 : tree decl = DECL_EXPR_DECL (*tp);
6973 307 : if (!processing_template_decl
6974 258 : && decl == (tree) data
6975 258 : && DECL_INITIAL (decl)
6976 399 : && DECL_INITIAL (decl) != error_mark_node)
6977 : {
6978 92 : tree list = NULL_TREE;
6979 92 : append_to_statement_list_force (*tp, &list);
6980 92 : tree init_expr = build2 (INIT_EXPR, void_type_node,
6981 92 : decl, DECL_INITIAL (decl));
6982 92 : DECL_INITIAL (decl) = NULL_TREE;
6983 92 : append_to_statement_list_force (init_expr, &list);
6984 92 : *tp = list;
6985 : }
6986 : }
6987 4395 : return NULL_TREE;
6988 : }
6989 :
6990 : /* Data passed from cp_check_omp_declare_reduction to
6991 : cp_check_omp_declare_reduction_r. */
6992 :
6993 : struct cp_check_omp_declare_reduction_data
6994 : {
6995 : location_t loc;
6996 : tree stmts[7];
6997 : bool combiner_p;
6998 : };
6999 :
7000 : /* Helper function for cp_check_omp_declare_reduction, called via
7001 : cp_walk_tree. */
7002 :
7003 : static tree
7004 14952 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
7005 : {
7006 14952 : struct cp_check_omp_declare_reduction_data *udr_data
7007 : = (struct cp_check_omp_declare_reduction_data *) data;
7008 14952 : if (SSA_VAR_P (*tp)
7009 2687 : && !DECL_ARTIFICIAL (*tp)
7010 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
7011 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
7012 : {
7013 135 : location_t loc = udr_data->loc;
7014 135 : if (udr_data->combiner_p)
7015 45 : error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
7016 : "variable %qD which is not %<omp_out%> nor %<omp_in%>",
7017 : *tp);
7018 : else
7019 90 : error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
7020 : "to variable %qD which is not %<omp_priv%> nor "
7021 : "%<omp_orig%>",
7022 : *tp);
7023 135 : return *tp;
7024 : }
7025 : return NULL_TREE;
7026 : }
7027 :
7028 : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
7029 :
7030 : bool
7031 1100 : cp_check_omp_declare_reduction (tree udr)
7032 : {
7033 1100 : tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
7034 1100 : gcc_assert (TYPE_REF_P (type));
7035 1100 : type = TREE_TYPE (type);
7036 1100 : int i;
7037 1100 : location_t loc = DECL_SOURCE_LOCATION (udr);
7038 :
7039 1100 : if (type == error_mark_node)
7040 : return false;
7041 1100 : if (ARITHMETIC_TYPE_P (type))
7042 : {
7043 : static enum tree_code predef_codes[]
7044 : = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
7045 : BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
7046 3276 : for (i = 0; i < 8; i++)
7047 : {
7048 2918 : tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
7049 2918 : const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
7050 2918 : const char *n2 = IDENTIFIER_POINTER (id);
7051 2918 : if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
7052 2918 : && (n1[IDENTIFIER_LENGTH (id)] == '~'
7053 0 : || n1[IDENTIFIER_LENGTH (id)] == '\0'))
7054 : break;
7055 : }
7056 :
7057 376 : if (i == 8
7058 358 : && TREE_CODE (type) != COMPLEX_EXPR)
7059 : {
7060 358 : const char prefix_minmax[] = "omp declare reduction m";
7061 358 : size_t prefix_size = sizeof (prefix_minmax) - 1;
7062 358 : const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
7063 358 : if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
7064 : prefix_minmax, prefix_size) == 0
7065 10 : && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
7066 4 : || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
7067 368 : && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
7068 6 : i = 0;
7069 : }
7070 376 : if (i < 8)
7071 : {
7072 24 : error_at (loc, "predeclared arithmetic type %qT in "
7073 : "%<#pragma omp declare reduction%>", type);
7074 24 : return false;
7075 : }
7076 : }
7077 : else if (FUNC_OR_METHOD_TYPE_P (type)
7078 : || TREE_CODE (type) == ARRAY_TYPE)
7079 : {
7080 24 : error_at (loc, "function or array type %qT in "
7081 : "%<#pragma omp declare reduction%>", type);
7082 24 : return false;
7083 : }
7084 : else if (TYPE_REF_P (type))
7085 : {
7086 0 : error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
7087 : type);
7088 0 : return false;
7089 : }
7090 700 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
7091 : {
7092 24 : error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
7093 : "type %qT in %<#pragma omp declare reduction%>", type);
7094 24 : return false;
7095 : }
7096 :
7097 1028 : tree body = DECL_SAVED_TREE (udr);
7098 1028 : if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
7099 : return true;
7100 :
7101 842 : tree_stmt_iterator tsi;
7102 842 : struct cp_check_omp_declare_reduction_data data;
7103 842 : memset (data.stmts, 0, sizeof data.stmts);
7104 842 : for (i = 0, tsi = tsi_start (body);
7105 4679 : i < 7 && !tsi_end_p (tsi);
7106 3837 : i++, tsi_next (&tsi))
7107 3837 : data.stmts[i] = tsi_stmt (tsi);
7108 842 : data.loc = loc;
7109 842 : gcc_assert (tsi_end_p (tsi));
7110 842 : if (i >= 3)
7111 : {
7112 842 : gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
7113 : && TREE_CODE (data.stmts[1]) == DECL_EXPR);
7114 842 : if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
7115 : return true;
7116 797 : data.combiner_p = true;
7117 797 : if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
7118 : &data, NULL))
7119 45 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
7120 : }
7121 797 : if (i >= 6)
7122 : {
7123 336 : gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
7124 : && TREE_CODE (data.stmts[4]) == DECL_EXPR);
7125 336 : data.combiner_p = false;
7126 336 : if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
7127 : &data, NULL)
7128 336 : || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
7129 : cp_check_omp_declare_reduction_r, &data, NULL))
7130 90 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */);
7131 336 : if (i == 7)
7132 198 : gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
7133 : }
7134 : return true;
7135 : }
7136 :
7137 : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
7138 : an inline call. But, remap
7139 : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
7140 : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
7141 :
7142 : static tree
7143 2198 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
7144 : tree decl, tree placeholder)
7145 : {
7146 2198 : copy_body_data id;
7147 2198 : hash_map<tree, tree> decl_map;
7148 :
7149 2198 : decl_map.put (omp_decl1, placeholder);
7150 2198 : decl_map.put (omp_decl2, decl);
7151 2198 : memset (&id, 0, sizeof (id));
7152 2198 : id.src_fn = DECL_CONTEXT (omp_decl1);
7153 2198 : id.dst_fn = current_function_decl;
7154 2198 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
7155 2198 : id.decl_map = &decl_map;
7156 :
7157 2198 : id.copy_decl = copy_decl_no_change;
7158 2198 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
7159 2198 : id.transform_new_cfg = true;
7160 2198 : id.transform_return_to_modify = false;
7161 2198 : id.eh_lp_nr = 0;
7162 2198 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
7163 2198 : return stmt;
7164 2198 : }
7165 :
7166 : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
7167 : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
7168 :
7169 : static tree
7170 15438 : find_omp_placeholder_r (tree *tp, int *, void *data)
7171 : {
7172 15438 : if (*tp == (tree) data)
7173 265 : return *tp;
7174 : return NULL_TREE;
7175 : }
7176 :
7177 : /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
7178 : Return true if there is some error and the clause should be removed. */
7179 :
7180 : static bool
7181 8855 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
7182 : {
7183 8855 : tree t = OMP_CLAUSE_DECL (c);
7184 8855 : bool predefined = false;
7185 8855 : if (TREE_CODE (t) == TREE_LIST)
7186 : {
7187 0 : gcc_assert (processing_template_decl);
7188 : return false;
7189 : }
7190 8855 : tree type = TREE_TYPE (t);
7191 8855 : if (TREE_CODE (t) == MEM_REF)
7192 1596 : type = TREE_TYPE (type);
7193 8855 : if (TYPE_REF_P (type))
7194 527 : type = TREE_TYPE (type);
7195 8855 : if (TREE_CODE (type) == ARRAY_TYPE)
7196 : {
7197 350 : tree oatype = type;
7198 350 : gcc_assert (TREE_CODE (t) != MEM_REF);
7199 703 : while (TREE_CODE (type) == ARRAY_TYPE)
7200 353 : type = TREE_TYPE (type);
7201 350 : if (!processing_template_decl)
7202 : {
7203 255 : t = require_complete_type (t);
7204 255 : if (t == error_mark_node
7205 255 : || !complete_type_or_else (oatype, NULL_TREE))
7206 9 : return true;
7207 246 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
7208 : TYPE_SIZE_UNIT (type));
7209 246 : if (integer_zerop (size))
7210 : {
7211 6 : error_at (OMP_CLAUSE_LOCATION (c),
7212 : "%qE in %<reduction%> clause is a zero size array",
7213 : omp_clause_printable_decl (t));
7214 3 : return true;
7215 : }
7216 243 : size = size_binop (MINUS_EXPR, size, size_one_node);
7217 243 : size = save_expr (size);
7218 243 : tree index_type = build_index_type (size);
7219 243 : tree atype = build_array_type (type, index_type);
7220 243 : tree ptype = build_pointer_type (type);
7221 243 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7222 146 : t = build_fold_addr_expr (t);
7223 243 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
7224 243 : OMP_CLAUSE_DECL (c) = t;
7225 : }
7226 : }
7227 8843 : if (type == error_mark_node)
7228 : return true;
7229 8840 : else if (ARITHMETIC_TYPE_P (type))
7230 7590 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
7231 : {
7232 : case PLUS_EXPR:
7233 : case MULT_EXPR:
7234 : case MINUS_EXPR:
7235 : case TRUTH_ANDIF_EXPR:
7236 : case TRUTH_ORIF_EXPR:
7237 : predefined = true;
7238 : break;
7239 246 : case MIN_EXPR:
7240 246 : case MAX_EXPR:
7241 246 : if (TREE_CODE (type) == COMPLEX_TYPE)
7242 : break;
7243 : predefined = true;
7244 : break;
7245 111 : case BIT_AND_EXPR:
7246 111 : case BIT_IOR_EXPR:
7247 111 : case BIT_XOR_EXPR:
7248 111 : if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
7249 : break;
7250 : predefined = true;
7251 : break;
7252 : default:
7253 : break;
7254 : }
7255 1250 : else if (TYPE_READONLY (type))
7256 : {
7257 18 : error_at (OMP_CLAUSE_LOCATION (c),
7258 : "%qE has const type for %<reduction%>",
7259 : omp_clause_printable_decl (t));
7260 9 : return true;
7261 : }
7262 1241 : else if (!processing_template_decl)
7263 : {
7264 1037 : t = require_complete_type (t);
7265 1037 : if (t == error_mark_node)
7266 : return true;
7267 1037 : OMP_CLAUSE_DECL (c) = t;
7268 : }
7269 :
7270 1037 : if (predefined)
7271 : {
7272 7368 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7273 7368 : return false;
7274 : }
7275 1463 : else if (processing_template_decl)
7276 : {
7277 213 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
7278 : return true;
7279 : return false;
7280 : }
7281 :
7282 1250 : tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7283 :
7284 1250 : type = TYPE_MAIN_VARIANT (type);
7285 1250 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7286 1250 : if (id == NULL_TREE)
7287 924 : id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
7288 : NULL_TREE, NULL_TREE);
7289 1250 : id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
7290 1250 : if (id)
7291 : {
7292 1205 : if (id == error_mark_node)
7293 : return true;
7294 1199 : mark_used (id);
7295 1199 : tree body = DECL_SAVED_TREE (id);
7296 1199 : if (!body)
7297 : return true;
7298 1196 : if (TREE_CODE (body) == STATEMENT_LIST)
7299 : {
7300 1196 : tree_stmt_iterator tsi;
7301 1196 : tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
7302 1196 : int i;
7303 1196 : tree stmts[7];
7304 1196 : tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
7305 1196 : atype = TREE_TYPE (atype);
7306 1196 : bool need_static_cast = !same_type_p (type, atype);
7307 1196 : memset (stmts, 0, sizeof stmts);
7308 1196 : for (i = 0, tsi = tsi_start (body);
7309 8518 : i < 7 && !tsi_end_p (tsi);
7310 7322 : i++, tsi_next (&tsi))
7311 7322 : stmts[i] = tsi_stmt (tsi);
7312 1196 : gcc_assert (tsi_end_p (tsi));
7313 :
7314 1196 : if (i >= 3)
7315 : {
7316 1196 : gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
7317 : && TREE_CODE (stmts[1]) == DECL_EXPR);
7318 1196 : placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
7319 1196 : DECL_ARTIFICIAL (placeholder) = 1;
7320 1196 : DECL_IGNORED_P (placeholder) = 1;
7321 1196 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
7322 1196 : if (TREE_CODE (t) == MEM_REF)
7323 : {
7324 600 : decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
7325 : type);
7326 600 : DECL_ARTIFICIAL (decl_placeholder) = 1;
7327 600 : DECL_IGNORED_P (decl_placeholder) = 1;
7328 600 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
7329 : }
7330 1196 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
7331 285 : cxx_mark_addressable (placeholder);
7332 1196 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
7333 1196 : && (decl_placeholder
7334 149 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7335 372 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7336 118 : : OMP_CLAUSE_DECL (c));
7337 1196 : tree omp_out = placeholder;
7338 1196 : tree omp_in = decl_placeholder ? decl_placeholder
7339 596 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7340 1196 : if (need_static_cast)
7341 : {
7342 7 : tree rtype = build_reference_type (atype);
7343 7 : omp_out = build_static_cast (input_location,
7344 : rtype, omp_out,
7345 : tf_warning_or_error);
7346 7 : omp_in = build_static_cast (input_location,
7347 : rtype, omp_in,
7348 : tf_warning_or_error);
7349 7 : if (omp_out == error_mark_node || omp_in == error_mark_node)
7350 3 : return true;
7351 7 : omp_out = convert_from_reference (omp_out);
7352 7 : omp_in = convert_from_reference (omp_in);
7353 : }
7354 1196 : OMP_CLAUSE_REDUCTION_MERGE (c)
7355 1196 : = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
7356 1196 : DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
7357 : }
7358 1196 : if (i >= 6)
7359 : {
7360 1005 : gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
7361 : && TREE_CODE (stmts[4]) == DECL_EXPR);
7362 1005 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
7363 1005 : && (decl_placeholder
7364 232 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7365 844 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7366 170 : : OMP_CLAUSE_DECL (c));
7367 1005 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
7368 216 : cxx_mark_addressable (placeholder);
7369 1005 : tree omp_priv = decl_placeholder ? decl_placeholder
7370 429 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7371 1005 : tree omp_orig = placeholder;
7372 1005 : if (need_static_cast)
7373 : {
7374 5 : if (i == 7)
7375 : {
7376 3 : error_at (OMP_CLAUSE_LOCATION (c),
7377 : "user defined reduction with constructor "
7378 : "initializer for base class %qT", atype);
7379 3 : return true;
7380 : }
7381 2 : tree rtype = build_reference_type (atype);
7382 2 : omp_priv = build_static_cast (input_location,
7383 : rtype, omp_priv,
7384 : tf_warning_or_error);
7385 2 : omp_orig = build_static_cast (input_location,
7386 : rtype, omp_orig,
7387 : tf_warning_or_error);
7388 2 : if (omp_priv == error_mark_node
7389 2 : || omp_orig == error_mark_node)
7390 : return true;
7391 2 : omp_priv = convert_from_reference (omp_priv);
7392 2 : omp_orig = convert_from_reference (omp_orig);
7393 : }
7394 1002 : if (i == 6)
7395 286 : *need_default_ctor = true;
7396 1002 : OMP_CLAUSE_REDUCTION_INIT (c)
7397 1002 : = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
7398 1002 : DECL_EXPR_DECL (stmts[3]),
7399 : omp_priv, omp_orig);
7400 1002 : if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
7401 : find_omp_placeholder_r, placeholder, NULL))
7402 238 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
7403 : }
7404 191 : else if (i >= 3)
7405 : {
7406 191 : if (CLASS_TYPE_P (type) && !pod_type_p (type))
7407 175 : *need_default_ctor = true;
7408 : else
7409 : {
7410 16 : tree init;
7411 16 : tree v = decl_placeholder ? decl_placeholder
7412 16 : : convert_from_reference (t);
7413 16 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
7414 7 : init = build_constructor (TREE_TYPE (v), NULL);
7415 : else
7416 9 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
7417 32 : OMP_CLAUSE_REDUCTION_INIT (c)
7418 32 : = cp_build_init_expr (v, init);
7419 : }
7420 : }
7421 : }
7422 : }
7423 1238 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7424 1193 : *need_dtor = true;
7425 : else
7426 : {
7427 90 : error_at (OMP_CLAUSE_LOCATION (c),
7428 : "user defined reduction not found for %qE",
7429 : omp_clause_printable_decl (t));
7430 45 : return true;
7431 : }
7432 1193 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7433 600 : gcc_assert (TYPE_SIZE_UNIT (type)
7434 : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
7435 : return false;
7436 : }
7437 :
7438 : /* Check an instance of an "omp declare mapper" function. */
7439 :
7440 : bool
7441 188 : cp_check_omp_declare_mapper (tree udm)
7442 : {
7443 188 : tree type = TREE_TYPE (udm);
7444 188 : location_t loc = DECL_SOURCE_LOCATION (udm);
7445 :
7446 188 : if (type == error_mark_node)
7447 : return false;
7448 :
7449 188 : if (!processing_template_decl && !RECORD_OR_UNION_TYPE_P (type))
7450 : {
7451 15 : error_at (loc, "%qT is not a struct, union or class type in "
7452 : "%<#pragma omp declare mapper%>", type);
7453 15 : return false;
7454 : }
7455 173 : if (!processing_template_decl && CLASSTYPE_VBASECLASSES (type))
7456 : {
7457 3 : error_at (loc, "%qT must not be a virtual base class in "
7458 : "%<#pragma omp declare mapper%>", type);
7459 3 : return false;
7460 : }
7461 :
7462 : return true;
7463 : }
7464 :
7465 : /* Called from finish_struct_1. linear(this) or linear(this:step)
7466 : clauses might not be finalized yet because the class has been incomplete
7467 : when parsing #pragma omp declare simd methods. Fix those up now. */
7468 :
7469 : void
7470 117820 : finish_omp_declare_simd_methods (tree t)
7471 : {
7472 117820 : if (processing_template_decl)
7473 : return;
7474 :
7475 804094 : for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
7476 : {
7477 1135559 : if (TREE_CODE (x) == USING_DECL
7478 686274 : || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
7479 449285 : continue;
7480 236989 : tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
7481 237097 : if (!ods || !TREE_VALUE (ods))
7482 236881 : continue;
7483 366 : for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
7484 258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7485 66 : && integer_zerop (OMP_CLAUSE_DECL (c))
7486 18 : && OMP_CLAUSE_LINEAR_STEP (c)
7487 276 : && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
7488 : {
7489 18 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
7490 18 : s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
7491 18 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
7492 18 : sizetype, s, TYPE_SIZE_UNIT (t));
7493 18 : OMP_CLAUSE_LINEAR_STEP (c) = s;
7494 : }
7495 : }
7496 : }
7497 :
7498 : /* Adjust sink depend/doacross clause to take into account pointer offsets.
7499 :
7500 : Return TRUE if there was a problem processing the offset, and the
7501 : whole clause should be removed. */
7502 :
7503 : static bool
7504 298 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
7505 : {
7506 298 : tree t = OMP_CLAUSE_DECL (sink_clause);
7507 298 : gcc_assert (TREE_CODE (t) == TREE_LIST);
7508 :
7509 : /* Make sure we don't adjust things twice for templates. */
7510 298 : if (processing_template_decl)
7511 : return false;
7512 :
7513 671 : for (; t; t = TREE_CHAIN (t))
7514 : {
7515 391 : tree decl = TREE_VALUE (t);
7516 391 : if (TYPE_PTR_P (TREE_TYPE (decl)))
7517 : {
7518 6 : tree offset = TREE_PURPOSE (t);
7519 6 : bool neg = wi::neg_p (wi::to_wide (offset));
7520 6 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
7521 6 : decl = mark_rvalue_use (decl);
7522 6 : decl = convert_from_reference (decl);
7523 12 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
7524 : neg ? MINUS_EXPR : PLUS_EXPR,
7525 : decl, offset);
7526 6 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
7527 : MINUS_EXPR, sizetype,
7528 : fold_convert (sizetype, t2),
7529 : fold_convert (sizetype, decl));
7530 6 : if (t2 == error_mark_node)
7531 : return true;
7532 6 : TREE_PURPOSE (t) = t2;
7533 : }
7534 : }
7535 : return false;
7536 : }
7537 :
7538 : /* Finish OpenMP iterators ITER. Return true if they are errorneous
7539 : and clauses containing them should be removed. */
7540 :
7541 : static bool
7542 614 : cp_omp_finish_iterators (tree iter)
7543 : {
7544 614 : bool ret = false;
7545 1393 : for (tree it = iter; it; it = TREE_CHAIN (it))
7546 : {
7547 779 : tree var = TREE_VEC_ELT (it, 0);
7548 779 : tree begin = TREE_VEC_ELT (it, 1);
7549 779 : tree end = TREE_VEC_ELT (it, 2);
7550 779 : tree step = TREE_VEC_ELT (it, 3);
7551 779 : tree orig_step;
7552 779 : tree type = TREE_TYPE (var);
7553 779 : location_t loc = DECL_SOURCE_LOCATION (var);
7554 779 : if (type == error_mark_node)
7555 : {
7556 0 : ret = true;
7557 218 : continue;
7558 : }
7559 779 : if (type_dependent_expression_p (var))
7560 59 : continue;
7561 720 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
7562 : {
7563 27 : error_at (loc, "iterator %qD has neither integral nor pointer type",
7564 : var);
7565 27 : ret = true;
7566 27 : continue;
7567 : }
7568 693 : else if (TYPE_READONLY (type))
7569 : {
7570 24 : error_at (loc, "iterator %qD has const qualified type", var);
7571 24 : ret = true;
7572 24 : continue;
7573 : }
7574 669 : if (type_dependent_expression_p (begin)
7575 660 : || type_dependent_expression_p (end)
7576 1329 : || type_dependent_expression_p (step))
7577 15 : continue;
7578 654 : else if (error_operand_p (step))
7579 : {
7580 0 : ret = true;
7581 0 : continue;
7582 : }
7583 654 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
7584 : {
7585 33 : error_at (EXPR_LOC_OR_LOC (step, loc),
7586 : "iterator step with non-integral type");
7587 21 : ret = true;
7588 21 : continue;
7589 : }
7590 :
7591 633 : begin = mark_rvalue_use (begin);
7592 633 : end = mark_rvalue_use (end);
7593 633 : step = mark_rvalue_use (step);
7594 633 : begin = cp_build_c_cast (input_location, type, begin,
7595 : tf_warning_or_error);
7596 633 : end = cp_build_c_cast (input_location, type, end,
7597 : tf_warning_or_error);
7598 633 : orig_step = step;
7599 633 : if (!processing_template_decl)
7600 556 : step = orig_step = save_expr (step);
7601 633 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
7602 633 : step = cp_build_c_cast (input_location, stype, step,
7603 : tf_warning_or_error);
7604 633 : if (POINTER_TYPE_P (type) && !processing_template_decl)
7605 : {
7606 66 : begin = save_expr (begin);
7607 66 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
7608 66 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
7609 : fold_convert (sizetype, step),
7610 : fold_convert (sizetype, begin));
7611 66 : step = fold_convert (ssizetype, step);
7612 : }
7613 633 : if (!processing_template_decl)
7614 : {
7615 556 : begin = maybe_constant_value (begin);
7616 556 : end = maybe_constant_value (end);
7617 556 : step = maybe_constant_value (step);
7618 556 : orig_step = maybe_constant_value (orig_step);
7619 : }
7620 633 : if (integer_zerop (step))
7621 : {
7622 27 : error_at (loc, "iterator %qD has zero step", var);
7623 27 : ret = true;
7624 27 : continue;
7625 : }
7626 :
7627 606 : if (begin == error_mark_node
7628 597 : || end == error_mark_node
7629 588 : || step == error_mark_node
7630 588 : || orig_step == error_mark_node)
7631 : {
7632 18 : ret = true;
7633 18 : continue;
7634 : }
7635 :
7636 588 : if (!processing_template_decl)
7637 : {
7638 511 : begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
7639 511 : end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
7640 511 : step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
7641 511 : orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
7642 : orig_step);
7643 : }
7644 588 : hash_set<tree> pset;
7645 588 : tree it2;
7646 744 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
7647 : {
7648 183 : tree var2 = TREE_VEC_ELT (it2, 0);
7649 183 : tree begin2 = TREE_VEC_ELT (it2, 1);
7650 183 : tree end2 = TREE_VEC_ELT (it2, 2);
7651 183 : tree step2 = TREE_VEC_ELT (it2, 3);
7652 183 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
7653 183 : if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
7654 : {
7655 9 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
7656 : "begin expression refers to outer iterator %qD", var);
7657 36 : break;
7658 : }
7659 174 : else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
7660 : {
7661 9 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
7662 : "end expression refers to outer iterator %qD", var);
7663 9 : break;
7664 : }
7665 165 : else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
7666 : {
7667 9 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
7668 : "step expression refers to outer iterator %qD", var);
7669 9 : break;
7670 : }
7671 : }
7672 588 : if (it2)
7673 : {
7674 27 : ret = true;
7675 27 : continue;
7676 : }
7677 561 : TREE_VEC_ELT (it, 1) = begin;
7678 561 : TREE_VEC_ELT (it, 2) = end;
7679 561 : if (processing_template_decl)
7680 71 : TREE_VEC_ELT (it, 3) = orig_step;
7681 : else
7682 : {
7683 490 : TREE_VEC_ELT (it, 3) = step;
7684 490 : TREE_VEC_ELT (it, 4) = orig_step;
7685 : }
7686 588 : }
7687 614 : return ret;
7688 : }
7689 :
7690 : /* Ensure that pointers are used in OpenACC attach and detach clauses.
7691 : Return true if an error has been detected. */
7692 :
7693 : static bool
7694 18474 : cp_oacc_check_attachments (tree c)
7695 : {
7696 18474 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
7697 : return false;
7698 :
7699 : /* OpenACC attach / detach clauses must be pointers. */
7700 14579 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
7701 14579 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
7702 : {
7703 196 : tree t = OMP_CLAUSE_DECL (c);
7704 196 : tree type;
7705 :
7706 232 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7707 36 : t = TREE_OPERAND (t, 0);
7708 :
7709 196 : type = TREE_TYPE (t);
7710 :
7711 196 : if (TREE_CODE (type) == REFERENCE_TYPE)
7712 36 : type = TREE_TYPE (type);
7713 :
7714 196 : if (TREE_CODE (type) != POINTER_TYPE)
7715 : {
7716 36 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
7717 : user_omp_clause_code_name (c, true));
7718 36 : return true;
7719 : }
7720 : }
7721 :
7722 : return false;
7723 : }
7724 :
7725 : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
7726 : happened. */
7727 :
7728 : tree
7729 813 : cp_finish_omp_init_prefer_type (tree pref_type)
7730 : {
7731 813 : if (processing_template_decl
7732 741 : || pref_type == NULL_TREE
7733 356 : || TREE_CODE (pref_type) != TREE_LIST)
7734 : return pref_type;
7735 :
7736 81 : tree t = TREE_PURPOSE (pref_type);
7737 81 : char *str = const_cast<char *> (TREE_STRING_POINTER (t));
7738 81 : tree fr_list = TREE_VALUE (pref_type);
7739 81 : int len = TREE_VEC_LENGTH (fr_list);
7740 81 : int cnt = 0;
7741 :
7742 270 : while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
7743 : {
7744 270 : str++;
7745 270 : if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
7746 : {
7747 : /* Assume a no or a single 'fr'. */
7748 150 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7749 150 : location_t loc = UNKNOWN_LOCATION;
7750 150 : tree value = TREE_VEC_ELT (fr_list, cnt);
7751 150 : if (value != NULL_TREE && value != error_mark_node)
7752 : {
7753 126 : loc = EXPR_LOCATION (value);
7754 126 : if (value && TREE_CODE (value) == NOP_EXPR)
7755 39 : value = TREE_OPERAND (value, 0);
7756 126 : value = cp_fully_fold (value);
7757 : }
7758 126 : if (value != NULL_TREE && value != error_mark_node)
7759 : {
7760 126 : if (TREE_CODE (value) != INTEGER_CST
7761 126 : || !tree_fits_shwi_p (value))
7762 0 : error_at (loc,
7763 : "expected string literal or "
7764 : "constant integer expression instead of %qE", value);
7765 : else
7766 : {
7767 126 : HOST_WIDE_INT n = tree_to_shwi (value);
7768 126 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
7769 : {
7770 48 : warning_at (loc, OPT_Wopenmp,
7771 : "unknown foreign runtime identifier %qwd", n);
7772 48 : n = GOMP_INTEROP_IFR_UNKNOWN;
7773 : }
7774 126 : str[0] = (char) n;
7775 : }
7776 : }
7777 150 : str++;
7778 : }
7779 120 : else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
7780 : {
7781 : /* Assume a no or a single 'fr'. */
7782 120 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7783 120 : str++;
7784 : }
7785 270 : str++;
7786 294 : while (str[0] != '\0')
7787 24 : str += strlen (str) + 1;
7788 270 : str++;
7789 270 : cnt++;
7790 270 : if (cnt >= len)
7791 : break;
7792 : }
7793 : return t;
7794 : }
7795 :
7796 : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
7797 : Remove any elements from the list that are invalid. */
7798 :
7799 : tree
7800 62562 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
7801 : {
7802 62562 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
7803 62562 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
7804 62562 : bitmap_head oacc_reduction_head, is_on_device_head;
7805 62562 : tree c, t, *pc;
7806 62562 : tree safelen = NULL_TREE;
7807 62562 : bool openacc = (ort & C_ORT_ACC) != 0;
7808 62562 : bool branch_seen = false;
7809 62562 : bool copyprivate_seen = false;
7810 62562 : bool ordered_seen = false;
7811 62562 : bool order_seen = false;
7812 62562 : bool schedule_seen = false;
7813 62562 : bool oacc_async = false;
7814 62562 : bool indir_component_ref_p = false;
7815 62562 : tree last_iterators = NULL_TREE;
7816 62562 : bool last_iterators_remove = false;
7817 : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
7818 : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
7819 62562 : int reduction_seen = 0;
7820 62562 : bool allocate_seen = false;
7821 62562 : tree detach_seen = NULL_TREE;
7822 62562 : bool mergeable_seen = false;
7823 62562 : bool implicit_moved = false;
7824 62562 : bool target_in_reduction_seen = false;
7825 62562 : bool num_tasks_seen = false;
7826 62562 : bool partial_seen = false;
7827 62562 : bool init_seen = false;
7828 62562 : bool init_use_destroy_seen = false;
7829 62562 : tree init_no_targetsync_clause = NULL_TREE;
7830 62562 : tree depend_clause = NULL_TREE;
7831 :
7832 62562 : bitmap_obstack_initialize (NULL);
7833 62562 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
7834 62562 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
7835 62562 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
7836 62562 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
7837 : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
7838 62562 : bitmap_initialize (&map_head, &bitmap_default_obstack);
7839 62562 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
7840 62562 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
7841 : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
7842 : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
7843 62562 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
7844 62562 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
7845 :
7846 62562 : if (openacc)
7847 28269 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
7848 15929 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
7849 : {
7850 : oacc_async = true;
7851 : break;
7852 : }
7853 :
7854 62562 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
7855 :
7856 160329 : for (pc = &clauses, c = clauses; c ; c = *pc)
7857 : {
7858 97767 : bool remove = false;
7859 97767 : bool field_ok = false;
7860 :
7861 : /* We've reached the end of a list of expanded nodes. Reset the group
7862 : start pointer. */
7863 97767 : if (c == grp_sentinel)
7864 : {
7865 5607 : if (grp_start_p
7866 5607 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
7867 96 : for (tree gc = *grp_start_p; gc != grp_sentinel;
7868 66 : gc = OMP_CLAUSE_CHAIN (gc))
7869 66 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
7870 : grp_start_p = NULL;
7871 : }
7872 :
7873 97767 : switch (OMP_CLAUSE_CODE (c))
7874 : {
7875 2100 : case OMP_CLAUSE_SHARED:
7876 2100 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7877 2100 : goto check_dup_generic;
7878 2576 : case OMP_CLAUSE_PRIVATE:
7879 2576 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7880 2576 : goto check_dup_generic;
7881 7337 : case OMP_CLAUSE_REDUCTION:
7882 7337 : if (reduction_seen == 0)
7883 6233 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
7884 1104 : else if (reduction_seen != -2
7885 2208 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
7886 1104 : ? -1 : 1))
7887 : {
7888 6 : error_at (OMP_CLAUSE_LOCATION (c),
7889 : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
7890 : "on the same construct");
7891 6 : reduction_seen = -2;
7892 : }
7893 : /* FALLTHRU */
7894 9482 : case OMP_CLAUSE_IN_REDUCTION:
7895 9482 : case OMP_CLAUSE_TASK_REDUCTION:
7896 9482 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7897 9482 : t = OMP_CLAUSE_DECL (c);
7898 9482 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7899 : {
7900 2207 : if (handle_omp_array_sections (c, ort))
7901 : {
7902 : remove = true;
7903 : break;
7904 : }
7905 2165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
7906 2165 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
7907 : {
7908 3 : error_at (OMP_CLAUSE_LOCATION (c),
7909 : "%<inscan%> %<reduction%> clause with array "
7910 : "section");
7911 3 : remove = true;
7912 3 : break;
7913 : }
7914 2162 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7915 : {
7916 4672 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7917 2510 : t = TREE_OPERAND (t, 0);
7918 : }
7919 : else
7920 : {
7921 0 : gcc_assert (TREE_CODE (t) == MEM_REF);
7922 0 : t = TREE_OPERAND (t, 0);
7923 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
7924 0 : t = TREE_OPERAND (t, 0);
7925 0 : if (TREE_CODE (t) == ADDR_EXPR
7926 0 : || INDIRECT_REF_P (t))
7927 0 : t = TREE_OPERAND (t, 0);
7928 : }
7929 2162 : tree n = omp_clause_decl_field (t);
7930 2162 : if (n)
7931 59 : t = n;
7932 2162 : goto check_dup_generic_t;
7933 : }
7934 7275 : if (oacc_async)
7935 7 : cxx_mark_addressable (t);
7936 7275 : goto check_dup_generic;
7937 98 : case OMP_CLAUSE_COPYPRIVATE:
7938 98 : copyprivate_seen = true;
7939 98 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7940 98 : goto check_dup_generic;
7941 277 : case OMP_CLAUSE_COPYIN:
7942 277 : goto check_dup_generic;
7943 1631 : case OMP_CLAUSE_LINEAR:
7944 1631 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7945 1631 : t = OMP_CLAUSE_DECL (c);
7946 1631 : if (ort != C_ORT_OMP_DECLARE_SIMD
7947 1631 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
7948 : {
7949 84 : if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
7950 : {
7951 42 : error_at (OMP_CLAUSE_LOCATION (c),
7952 : "modifier should not be specified in %<linear%> "
7953 : "clause on %<simd%> or %<for%> constructs when "
7954 : "not using OpenMP 5.2 modifiers");
7955 42 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
7956 : }
7957 42 : else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
7958 : {
7959 18 : error_at (OMP_CLAUSE_LOCATION (c),
7960 : "modifier other than %<val%> specified in "
7961 : "%<linear%> clause on %<simd%> or %<for%> "
7962 : "constructs when using OpenMP 5.2 modifiers");
7963 18 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
7964 : }
7965 : }
7966 1011 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
7967 2571 : && !type_dependent_expression_p (t))
7968 : {
7969 1529 : tree type = TREE_TYPE (t);
7970 1529 : if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7971 1448 : || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
7972 1598 : && !TYPE_REF_P (type))
7973 : {
7974 12 : error_at (OMP_CLAUSE_LOCATION (c),
7975 : "linear clause with %qs modifier applied to "
7976 : "non-reference variable with %qT type",
7977 12 : OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7978 12 : ? "ref" : "uval", TREE_TYPE (t));
7979 12 : remove = true;
7980 12 : break;
7981 : }
7982 1517 : if (TYPE_REF_P (type))
7983 281 : type = TREE_TYPE (type);
7984 1517 : if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
7985 : {
7986 1442 : if (!INTEGRAL_TYPE_P (type)
7987 85 : && !TYPE_PTR_P (type))
7988 : {
7989 18 : error_at (OMP_CLAUSE_LOCATION (c),
7990 : "linear clause applied to non-integral "
7991 : "non-pointer variable with %qT type",
7992 18 : TREE_TYPE (t));
7993 18 : remove = true;
7994 18 : break;
7995 : }
7996 : }
7997 : }
7998 1601 : t = OMP_CLAUSE_LINEAR_STEP (c);
7999 1601 : if (t == NULL_TREE)
8000 6 : t = integer_one_node;
8001 1601 : if (t == error_mark_node)
8002 : {
8003 : remove = true;
8004 : break;
8005 : }
8006 1601 : else if (!type_dependent_expression_p (t)
8007 1599 : && !INTEGRAL_TYPE_P (TREE_TYPE (t))
8008 1613 : && (ort != C_ORT_OMP_DECLARE_SIMD
8009 9 : || TREE_CODE (t) != PARM_DECL
8010 6 : || !TYPE_REF_P (TREE_TYPE (t))
8011 6 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
8012 : {
8013 6 : error_at (OMP_CLAUSE_LOCATION (c),
8014 : "linear step expression must be integral");
8015 6 : remove = true;
8016 6 : break;
8017 : }
8018 : else
8019 : {
8020 1595 : t = mark_rvalue_use (t);
8021 1595 : if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
8022 : {
8023 42 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
8024 42 : goto check_dup_generic;
8025 : }
8026 1553 : if (!processing_template_decl
8027 1553 : && (VAR_P (OMP_CLAUSE_DECL (c))
8028 835 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
8029 : {
8030 1372 : if (ort == C_ORT_OMP_DECLARE_SIMD)
8031 : {
8032 589 : t = maybe_constant_value (t);
8033 589 : if (TREE_CODE (t) != INTEGER_CST)
8034 : {
8035 6 : error_at (OMP_CLAUSE_LOCATION (c),
8036 : "%<linear%> clause step %qE is neither "
8037 : "constant nor a parameter", t);
8038 6 : remove = true;
8039 6 : break;
8040 : }
8041 : }
8042 1366 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8043 1366 : tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
8044 1366 : if (TYPE_REF_P (type))
8045 257 : type = TREE_TYPE (type);
8046 1366 : if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
8047 : {
8048 66 : type = build_pointer_type (type);
8049 66 : tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
8050 66 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8051 : d, t);
8052 66 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8053 : MINUS_EXPR, sizetype,
8054 : fold_convert (sizetype, t),
8055 : fold_convert (sizetype, d));
8056 66 : if (t == error_mark_node)
8057 : {
8058 : remove = true;
8059 : break;
8060 : }
8061 : }
8062 1300 : else if (TYPE_PTR_P (type)
8063 : /* Can't multiply the step yet if *this
8064 : is still incomplete type. */
8065 1300 : && (ort != C_ORT_OMP_DECLARE_SIMD
8066 45 : || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
8067 45 : || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
8068 30 : || DECL_NAME (OMP_CLAUSE_DECL (c))
8069 30 : != this_identifier
8070 30 : || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
8071 : {
8072 37 : tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
8073 37 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8074 : d, t);
8075 37 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8076 : MINUS_EXPR, sizetype,
8077 : fold_convert (sizetype, t),
8078 : fold_convert (sizetype, d));
8079 37 : if (t == error_mark_node)
8080 : {
8081 : remove = true;
8082 : break;
8083 : }
8084 : }
8085 : else
8086 1263 : t = fold_convert (type, t);
8087 : }
8088 1547 : OMP_CLAUSE_LINEAR_STEP (c) = t;
8089 : }
8090 1547 : goto check_dup_generic;
8091 14881 : check_dup_generic:
8092 14881 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8093 14881 : if (t)
8094 : {
8095 101 : if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
8096 101 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8097 : }
8098 : else
8099 14780 : t = OMP_CLAUSE_DECL (c);
8100 17310 : check_dup_generic_t:
8101 17310 : if (t == current_class_ptr
8102 17310 : && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
8103 102 : || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
8104 72 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
8105 : {
8106 24 : error_at (OMP_CLAUSE_LOCATION (c),
8107 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8108 : " clauses");
8109 24 : remove = true;
8110 24 : break;
8111 : }
8112 17286 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8113 586 : && (!field_ok || TREE_CODE (t) != FIELD_DECL))
8114 : {
8115 59 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8116 : break;
8117 39 : if (DECL_P (t))
8118 30 : error_at (OMP_CLAUSE_LOCATION (c),
8119 : "%qD is not a variable in clause %qs", t,
8120 15 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8121 : else
8122 48 : error_at (OMP_CLAUSE_LOCATION (c),
8123 : "%qE is not a variable in clause %qs", t,
8124 24 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8125 : remove = true;
8126 : }
8127 17227 : else if ((openacc
8128 2707 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
8129 14758 : || (ort == C_ORT_OMP
8130 12427 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
8131 12396 : || (OMP_CLAUSE_CODE (c)
8132 : == OMP_CLAUSE_USE_DEVICE_ADDR)))
8133 31878 : || (ort == C_ORT_OMP_TARGET
8134 936 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
8135 : {
8136 2854 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
8137 2854 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8138 275 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
8139 : {
8140 6 : error_at (OMP_CLAUSE_LOCATION (c),
8141 : "%qD appears more than once in data-sharing "
8142 : "clauses", t);
8143 6 : remove = true;
8144 6 : break;
8145 : }
8146 2848 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
8147 272 : target_in_reduction_seen = true;
8148 2848 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8149 : {
8150 12 : error_at (OMP_CLAUSE_LOCATION (c),
8151 : openacc
8152 : ? "%qD appears more than once in reduction clauses"
8153 : : "%qD appears more than once in data clauses",
8154 : t);
8155 6 : remove = true;
8156 : }
8157 : else
8158 2842 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8159 : }
8160 14373 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8161 14298 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8162 14295 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
8163 28668 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8164 : {
8165 78 : error_at (OMP_CLAUSE_LOCATION (c),
8166 : "%qD appears more than once in data clauses", t);
8167 78 : remove = true;
8168 : }
8169 14295 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
8170 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
8171 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
8172 3115 : && bitmap_bit_p (&map_head, DECL_UID (t)))
8173 : {
8174 9 : if (openacc)
8175 0 : error_at (OMP_CLAUSE_LOCATION (c),
8176 : "%qD appears more than once in data clauses", t);
8177 : else
8178 9 : error_at (OMP_CLAUSE_LOCATION (c),
8179 : "%qD appears both in data and map clauses", t);
8180 : remove = true;
8181 : }
8182 : else
8183 14286 : bitmap_set_bit (&generic_head, DECL_UID (t));
8184 17260 : if (!field_ok)
8185 : break;
8186 12852 : handle_field_decl:
8187 21366 : if (!remove
8188 21169 : && TREE_CODE (t) == FIELD_DECL
8189 16494 : && t == OMP_CLAUSE_DECL (c))
8190 : {
8191 795 : OMP_CLAUSE_DECL (c)
8192 795 : = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
8193 : == OMP_CLAUSE_SHARED));
8194 795 : if (OMP_CLAUSE_DECL (c) == error_mark_node)
8195 97266 : remove = true;
8196 : }
8197 : break;
8198 :
8199 3473 : case OMP_CLAUSE_FIRSTPRIVATE:
8200 3473 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
8201 : {
8202 447 : move_implicit:
8203 447 : implicit_moved = true;
8204 : /* Move firstprivate and map clauses with
8205 : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
8206 : clauses chain. */
8207 447 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
8208 447 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
8209 2804 : while (*pc1)
8210 2357 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
8211 2357 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
8212 : {
8213 275 : *pc3 = *pc1;
8214 275 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
8215 275 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8216 : }
8217 2082 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
8218 2082 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
8219 : {
8220 403 : *pc2 = *pc1;
8221 403 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
8222 403 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8223 : }
8224 : else
8225 1679 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
8226 447 : *pc3 = NULL;
8227 447 : *pc2 = cl2;
8228 447 : *pc1 = cl1;
8229 447 : continue;
8230 447 : }
8231 3216 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8232 3216 : if (t)
8233 69 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8234 : else
8235 3147 : t = OMP_CLAUSE_DECL (c);
8236 3216 : if (!openacc && t == current_class_ptr)
8237 : {
8238 6 : error_at (OMP_CLAUSE_LOCATION (c),
8239 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8240 : " clauses");
8241 6 : remove = true;
8242 6 : break;
8243 : }
8244 3210 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8245 333 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8246 333 : || TREE_CODE (t) != FIELD_DECL))
8247 : {
8248 41 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8249 : break;
8250 18 : if (DECL_P (t))
8251 12 : error_at (OMP_CLAUSE_LOCATION (c),
8252 : "%qD is not a variable in clause %<firstprivate%>",
8253 : t);
8254 : else
8255 6 : error_at (OMP_CLAUSE_LOCATION (c),
8256 : "%qE is not a variable in clause %<firstprivate%>",
8257 : t);
8258 18 : remove = true;
8259 : }
8260 3169 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8261 275 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
8262 3423 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8263 : remove = true;
8264 3169 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8265 3160 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8266 6326 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8267 : {
8268 15 : error_at (OMP_CLAUSE_LOCATION (c),
8269 : "%qD appears more than once in data clauses", t);
8270 15 : remove = true;
8271 : }
8272 3154 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8273 3154 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
8274 : {
8275 21 : if (openacc)
8276 0 : error_at (OMP_CLAUSE_LOCATION (c),
8277 : "%qD appears more than once in data clauses", t);
8278 21 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8279 21 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
8280 : /* Silently drop the clause. */;
8281 : else
8282 18 : error_at (OMP_CLAUSE_LOCATION (c),
8283 : "%qD appears both in data and map clauses", t);
8284 21 : remove = true;
8285 : }
8286 : else
8287 3133 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
8288 3187 : goto handle_field_decl;
8289 :
8290 2790 : case OMP_CLAUSE_LASTPRIVATE:
8291 2790 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8292 2790 : if (t)
8293 35 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8294 : else
8295 2755 : t = OMP_CLAUSE_DECL (c);
8296 2790 : if (!openacc && t == current_class_ptr)
8297 : {
8298 6 : error_at (OMP_CLAUSE_LOCATION (c),
8299 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8300 : " clauses");
8301 6 : remove = true;
8302 6 : break;
8303 : }
8304 2784 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8305 259 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8306 259 : || TREE_CODE (t) != FIELD_DECL))
8307 : {
8308 35 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8309 : break;
8310 9 : if (DECL_P (t))
8311 3 : error_at (OMP_CLAUSE_LOCATION (c),
8312 : "%qD is not a variable in clause %<lastprivate%>",
8313 : t);
8314 : else
8315 6 : error_at (OMP_CLAUSE_LOCATION (c),
8316 : "%qE is not a variable in clause %<lastprivate%>",
8317 : t);
8318 9 : remove = true;
8319 : }
8320 2749 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8321 2749 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8322 : {
8323 12 : error_at (OMP_CLAUSE_LOCATION (c),
8324 : "%qD appears more than once in data clauses", t);
8325 12 : remove = true;
8326 : }
8327 : else
8328 2737 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
8329 2758 : goto handle_field_decl;
8330 :
8331 2218 : case OMP_CLAUSE_IF:
8332 2218 : case OMP_CLAUSE_SELF:
8333 2218 : t = OMP_CLAUSE_OPERAND (c, 0);
8334 2218 : t = maybe_convert_cond (t);
8335 2218 : if (t == error_mark_node)
8336 : remove = true;
8337 2203 : else if (!processing_template_decl)
8338 2142 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8339 2218 : OMP_CLAUSE_OPERAND (c, 0) = t;
8340 2218 : break;
8341 :
8342 289 : case OMP_CLAUSE_FINAL:
8343 289 : t = OMP_CLAUSE_FINAL_EXPR (c);
8344 289 : t = maybe_convert_cond (t);
8345 289 : if (t == error_mark_node)
8346 : remove = true;
8347 289 : else if (!processing_template_decl)
8348 283 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8349 289 : OMP_CLAUSE_FINAL_EXPR (c) = t;
8350 289 : break;
8351 :
8352 92 : case OMP_CLAUSE_NOCONTEXT:
8353 92 : t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
8354 92 : t = maybe_convert_cond (t);
8355 92 : if (t == error_mark_node)
8356 : remove = true;
8357 89 : else if (!processing_template_decl)
8358 83 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8359 92 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
8360 92 : break;
8361 :
8362 80 : case OMP_CLAUSE_NOVARIANTS:
8363 80 : t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
8364 80 : t = maybe_convert_cond (t);
8365 80 : if (t == error_mark_node)
8366 : remove = true;
8367 77 : else if (!processing_template_decl)
8368 71 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8369 80 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
8370 80 : break;
8371 :
8372 1249 : case OMP_CLAUSE_GANG:
8373 : /* Operand 1 is the gang static: argument. */
8374 1249 : t = OMP_CLAUSE_OPERAND (c, 1);
8375 1249 : if (t != NULL_TREE)
8376 : {
8377 129 : if (t == error_mark_node)
8378 : remove = true;
8379 129 : else if (!type_dependent_expression_p (t)
8380 129 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8381 : {
8382 6 : error_at (OMP_CLAUSE_LOCATION (c),
8383 : "%<gang%> static expression must be integral");
8384 6 : remove = true;
8385 : }
8386 : else
8387 : {
8388 123 : t = mark_rvalue_use (t);
8389 123 : if (!processing_template_decl)
8390 : {
8391 123 : t = maybe_constant_value (t);
8392 123 : if (TREE_CODE (t) == INTEGER_CST
8393 109 : && tree_int_cst_sgn (t) != 1
8394 176 : && t != integer_minus_one_node)
8395 : {
8396 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8397 : "%<gang%> static value must be "
8398 : "positive");
8399 0 : t = integer_one_node;
8400 : }
8401 123 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8402 : }
8403 : }
8404 129 : OMP_CLAUSE_OPERAND (c, 1) = t;
8405 : }
8406 : /* Check operand 0, the num argument. */
8407 : /* FALLTHRU */
8408 :
8409 3480 : case OMP_CLAUSE_WORKER:
8410 3480 : case OMP_CLAUSE_VECTOR:
8411 3480 : if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
8412 : break;
8413 : /* FALLTHRU */
8414 :
8415 484 : case OMP_CLAUSE_NUM_TASKS:
8416 484 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
8417 136 : num_tasks_seen = true;
8418 : /* FALLTHRU */
8419 :
8420 3034 : case OMP_CLAUSE_NUM_TEAMS:
8421 3034 : case OMP_CLAUSE_NUM_THREADS:
8422 3034 : case OMP_CLAUSE_NUM_GANGS:
8423 3034 : case OMP_CLAUSE_NUM_WORKERS:
8424 3034 : case OMP_CLAUSE_DYN_GROUPPRIVATE:
8425 3034 : case OMP_CLAUSE_VECTOR_LENGTH:
8426 3034 : t = OMP_CLAUSE_OPERAND (c, 0);
8427 3034 : if (t == error_mark_node)
8428 : remove = true;
8429 3034 : else if (!type_dependent_expression_p (t)
8430 3034 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8431 : {
8432 99 : switch (OMP_CLAUSE_CODE (c))
8433 : {
8434 12 : case OMP_CLAUSE_GANG:
8435 12 : error_at (OMP_CLAUSE_LOCATION (c),
8436 12 : "%<gang%> num expression must be integral"); break;
8437 12 : case OMP_CLAUSE_VECTOR:
8438 12 : error_at (OMP_CLAUSE_LOCATION (c),
8439 : "%<vector%> length expression must be integral");
8440 12 : break;
8441 12 : case OMP_CLAUSE_WORKER:
8442 12 : error_at (OMP_CLAUSE_LOCATION (c),
8443 : "%<worker%> num expression must be integral");
8444 12 : break;
8445 63 : default:
8446 63 : error_at (OMP_CLAUSE_LOCATION (c),
8447 : "%qs expression must be integral",
8448 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8449 : }
8450 : remove = true;
8451 : }
8452 : else
8453 : {
8454 2935 : t = mark_rvalue_use (t);
8455 2935 : if (!processing_template_decl)
8456 : {
8457 2687 : t = maybe_constant_value (t);
8458 2687 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
8459 2652 : && TREE_CODE (t) == INTEGER_CST
8460 4142 : && tree_int_cst_sgn (t) != 1)
8461 : {
8462 85 : switch (OMP_CLAUSE_CODE (c))
8463 : {
8464 3 : case OMP_CLAUSE_GANG:
8465 3 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8466 : "%<gang%> num value must be positive");
8467 3 : break;
8468 0 : case OMP_CLAUSE_VECTOR:
8469 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8470 : "%<vector%> length value must be "
8471 : "positive");
8472 0 : break;
8473 0 : case OMP_CLAUSE_WORKER:
8474 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8475 : "%<worker%> num value must be "
8476 : "positive");
8477 0 : break;
8478 82 : default:
8479 82 : warning_at (OMP_CLAUSE_LOCATION (c),
8480 46 : (flag_openmp || flag_openmp_simd)
8481 82 : ? OPT_Wopenmp : 0,
8482 : "%qs value must be positive",
8483 : omp_clause_code_name
8484 82 : [OMP_CLAUSE_CODE (c)]);
8485 : }
8486 85 : t = integer_one_node;
8487 : }
8488 2602 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
8489 35 : && TREE_CODE (t) == INTEGER_CST
8490 2625 : && tree_int_cst_sgn (t) < 0)
8491 : {
8492 8 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8493 : "%<dyn_groupprivate%> value must be "
8494 : "non-negative");
8495 8 : t = integer_zero_node;
8496 : }
8497 2687 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8498 : }
8499 2935 : OMP_CLAUSE_OPERAND (c, 0) = t;
8500 : }
8501 3034 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
8502 752 : && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
8503 3313 : && !remove)
8504 : {
8505 279 : t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
8506 279 : if (t == error_mark_node)
8507 : remove = true;
8508 279 : else if (!type_dependent_expression_p (t)
8509 279 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8510 : {
8511 0 : error_at (OMP_CLAUSE_LOCATION (c),
8512 : "%qs expression must be integral",
8513 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8514 0 : remove = true;
8515 : }
8516 : else
8517 : {
8518 279 : t = mark_rvalue_use (t);
8519 279 : if (!processing_template_decl)
8520 : {
8521 213 : t = maybe_constant_value (t);
8522 213 : if (TREE_CODE (t) == INTEGER_CST
8523 213 : && tree_int_cst_sgn (t) != 1)
8524 : {
8525 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8526 : "%qs value must be positive",
8527 : omp_clause_code_name
8528 18 : [OMP_CLAUSE_CODE (c)]);
8529 18 : t = NULL_TREE;
8530 : }
8531 : else
8532 195 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8533 213 : tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
8534 213 : if (t
8535 195 : && TREE_CODE (t) == INTEGER_CST
8536 43 : && TREE_CODE (upper) == INTEGER_CST
8537 250 : && tree_int_cst_lt (upper, t))
8538 : {
8539 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8540 : "%<num_teams%> lower bound %qE bigger "
8541 : "than upper bound %qE", t, upper);
8542 18 : t = NULL_TREE;
8543 : }
8544 : }
8545 279 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
8546 : }
8547 : }
8548 : break;
8549 :
8550 3862 : case OMP_CLAUSE_SCHEDULE:
8551 3862 : t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
8552 3862 : if (t == NULL)
8553 : ;
8554 2078 : else if (t == error_mark_node)
8555 : remove = true;
8556 2078 : else if (!type_dependent_expression_p (t)
8557 2078 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8558 : {
8559 9 : error_at (OMP_CLAUSE_LOCATION (c),
8560 : "schedule chunk size expression must be integral");
8561 9 : remove = true;
8562 : }
8563 : else
8564 : {
8565 2069 : t = mark_rvalue_use (t);
8566 2069 : if (!processing_template_decl)
8567 : {
8568 2029 : t = maybe_constant_value (t);
8569 2029 : if (TREE_CODE (t) == INTEGER_CST
8570 2029 : && tree_int_cst_sgn (t) != 1)
8571 : {
8572 6 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8573 : "chunk size value must be positive");
8574 6 : t = integer_one_node;
8575 : }
8576 2029 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8577 : }
8578 2069 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8579 : }
8580 2078 : if (!remove)
8581 : schedule_seen = true;
8582 : break;
8583 :
8584 1268 : case OMP_CLAUSE_SIMDLEN:
8585 1268 : case OMP_CLAUSE_SAFELEN:
8586 1268 : t = OMP_CLAUSE_OPERAND (c, 0);
8587 1268 : if (t == error_mark_node)
8588 : remove = true;
8589 1268 : else if (!type_dependent_expression_p (t)
8590 1268 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8591 : {
8592 0 : error_at (OMP_CLAUSE_LOCATION (c),
8593 : "%qs length expression must be integral",
8594 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8595 0 : remove = true;
8596 : }
8597 : else
8598 : {
8599 1268 : t = mark_rvalue_use (t);
8600 1268 : if (!processing_template_decl)
8601 : {
8602 1219 : t = maybe_constant_value (t);
8603 1219 : if (TREE_CODE (t) != INTEGER_CST
8604 1219 : || tree_int_cst_sgn (t) != 1)
8605 : {
8606 0 : error_at (OMP_CLAUSE_LOCATION (c),
8607 : "%qs length expression must be positive "
8608 : "constant integer expression",
8609 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8610 0 : remove = true;
8611 : }
8612 : }
8613 1268 : OMP_CLAUSE_OPERAND (c, 0) = t;
8614 1268 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
8615 470 : safelen = c;
8616 : }
8617 : break;
8618 :
8619 388 : case OMP_CLAUSE_ASYNC:
8620 388 : t = OMP_CLAUSE_ASYNC_EXPR (c);
8621 388 : if (t == error_mark_node)
8622 : remove = true;
8623 373 : else if (!type_dependent_expression_p (t)
8624 373 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8625 : {
8626 12 : error_at (OMP_CLAUSE_LOCATION (c),
8627 : "%<async%> expression must be integral");
8628 12 : remove = true;
8629 : }
8630 : else
8631 : {
8632 361 : t = mark_rvalue_use (t);
8633 361 : if (!processing_template_decl)
8634 352 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8635 361 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
8636 : }
8637 : break;
8638 :
8639 204 : case OMP_CLAUSE_WAIT:
8640 204 : t = OMP_CLAUSE_WAIT_EXPR (c);
8641 204 : if (t == error_mark_node)
8642 : remove = true;
8643 204 : else if (!processing_template_decl)
8644 196 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8645 204 : OMP_CLAUSE_WAIT_EXPR (c) = t;
8646 204 : break;
8647 :
8648 637 : case OMP_CLAUSE_THREAD_LIMIT:
8649 637 : t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
8650 637 : if (t == error_mark_node)
8651 : remove = true;
8652 637 : else if (!type_dependent_expression_p (t)
8653 637 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8654 : {
8655 0 : error_at (OMP_CLAUSE_LOCATION (c),
8656 : "%<thread_limit%> expression must be integral");
8657 0 : remove = true;
8658 : }
8659 : else
8660 : {
8661 637 : t = mark_rvalue_use (t);
8662 637 : if (!processing_template_decl)
8663 : {
8664 583 : t = maybe_constant_value (t);
8665 583 : if (TREE_CODE (t) == INTEGER_CST
8666 583 : && tree_int_cst_sgn (t) != 1)
8667 : {
8668 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8669 : "%<thread_limit%> value must be positive");
8670 0 : t = integer_one_node;
8671 : }
8672 583 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8673 : }
8674 637 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
8675 : }
8676 : break;
8677 :
8678 770 : case OMP_CLAUSE_DEVICE:
8679 770 : t = OMP_CLAUSE_DEVICE_ID (c);
8680 770 : if (t == error_mark_node)
8681 : remove = true;
8682 770 : else if (!type_dependent_expression_p (t)
8683 770 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8684 : {
8685 6 : error_at (OMP_CLAUSE_LOCATION (c),
8686 : "%<device%> id must be integral");
8687 6 : remove = true;
8688 : }
8689 764 : else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
8690 66 : && TREE_CODE (t) == INTEGER_CST
8691 824 : && !integer_onep (t))
8692 : {
8693 3 : error_at (OMP_CLAUSE_LOCATION (c),
8694 : "the %<device%> clause expression must evaluate to "
8695 : "%<1%>");
8696 3 : remove = true;
8697 : }
8698 : else
8699 : {
8700 761 : t = mark_rvalue_use (t);
8701 761 : if (!processing_template_decl)
8702 750 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8703 761 : OMP_CLAUSE_DEVICE_ID (c) = t;
8704 : }
8705 : break;
8706 :
8707 1836 : case OMP_CLAUSE_DIST_SCHEDULE:
8708 1836 : t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
8709 1836 : if (t == NULL)
8710 : ;
8711 1815 : else if (t == error_mark_node)
8712 : remove = true;
8713 1815 : else if (!type_dependent_expression_p (t)
8714 1815 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8715 : {
8716 0 : error_at (OMP_CLAUSE_LOCATION (c),
8717 : "%<dist_schedule%> chunk size expression must be "
8718 : "integral");
8719 0 : remove = true;
8720 : }
8721 : else
8722 : {
8723 1815 : t = mark_rvalue_use (t);
8724 1815 : if (!processing_template_decl)
8725 1815 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8726 1815 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
8727 : }
8728 : break;
8729 :
8730 807 : case OMP_CLAUSE_ALIGNED:
8731 807 : t = OMP_CLAUSE_DECL (c);
8732 807 : if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
8733 : {
8734 0 : error_at (OMP_CLAUSE_LOCATION (c),
8735 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8736 : " clauses");
8737 0 : remove = true;
8738 0 : break;
8739 : }
8740 807 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8741 : {
8742 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8743 : break;
8744 0 : if (DECL_P (t))
8745 0 : error_at (OMP_CLAUSE_LOCATION (c),
8746 : "%qD is not a variable in %<aligned%> clause", t);
8747 : else
8748 0 : error_at (OMP_CLAUSE_LOCATION (c),
8749 : "%qE is not a variable in %<aligned%> clause", t);
8750 : remove = true;
8751 : }
8752 807 : else if (!type_dependent_expression_p (t)
8753 789 : && !TYPE_PTR_P (TREE_TYPE (t))
8754 111 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
8755 864 : && (!TYPE_REF_P (TREE_TYPE (t))
8756 39 : || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
8757 30 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
8758 : != ARRAY_TYPE))))
8759 : {
8760 33 : error_at (OMP_CLAUSE_LOCATION (c),
8761 : "%qE in %<aligned%> clause is neither a pointer nor "
8762 : "an array nor a reference to pointer or array", t);
8763 33 : remove = true;
8764 : }
8765 774 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8766 : {
8767 0 : error_at (OMP_CLAUSE_LOCATION (c),
8768 : "%qD appears more than once in %<aligned%> clauses",
8769 : t);
8770 0 : remove = true;
8771 : }
8772 : else
8773 774 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8774 807 : t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
8775 807 : if (t == error_mark_node)
8776 : remove = true;
8777 807 : else if (t == NULL_TREE)
8778 : break;
8779 744 : else if (!type_dependent_expression_p (t)
8780 744 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8781 : {
8782 0 : error_at (OMP_CLAUSE_LOCATION (c),
8783 : "%<aligned%> clause alignment expression must "
8784 : "be integral");
8785 0 : remove = true;
8786 : }
8787 : else
8788 : {
8789 744 : t = mark_rvalue_use (t);
8790 744 : if (!processing_template_decl)
8791 : {
8792 690 : t = maybe_constant_value (t);
8793 690 : if (TREE_CODE (t) != INTEGER_CST
8794 690 : || tree_int_cst_sgn (t) != 1)
8795 : {
8796 0 : error_at (OMP_CLAUSE_LOCATION (c),
8797 : "%<aligned%> clause alignment expression must "
8798 : "be positive constant integer expression");
8799 0 : remove = true;
8800 : }
8801 : }
8802 744 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
8803 : }
8804 : break;
8805 :
8806 369 : case OMP_CLAUSE_NONTEMPORAL:
8807 369 : t = OMP_CLAUSE_DECL (c);
8808 369 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8809 : {
8810 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8811 : break;
8812 0 : if (DECL_P (t))
8813 0 : error_at (OMP_CLAUSE_LOCATION (c),
8814 : "%qD is not a variable in %<nontemporal%> clause",
8815 : t);
8816 : else
8817 0 : error_at (OMP_CLAUSE_LOCATION (c),
8818 : "%qE is not a variable in %<nontemporal%> clause",
8819 : t);
8820 : remove = true;
8821 : }
8822 369 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8823 : {
8824 6 : error_at (OMP_CLAUSE_LOCATION (c),
8825 : "%qD appears more than once in %<nontemporal%> "
8826 : "clauses", t);
8827 6 : remove = true;
8828 : }
8829 : else
8830 363 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8831 : break;
8832 :
8833 2585 : case OMP_CLAUSE_ALLOCATE:
8834 2585 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8835 2585 : if (t)
8836 14 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8837 : else
8838 2571 : t = OMP_CLAUSE_DECL (c);
8839 2585 : if (t == current_class_ptr)
8840 : {
8841 0 : error_at (OMP_CLAUSE_LOCATION (c),
8842 : "%<this%> not allowed in %<allocate%> clause");
8843 0 : remove = true;
8844 0 : break;
8845 : }
8846 2585 : if (!VAR_P (t)
8847 558 : && TREE_CODE (t) != PARM_DECL
8848 45 : && TREE_CODE (t) != FIELD_DECL)
8849 : {
8850 3 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8851 : break;
8852 3 : if (DECL_P (t))
8853 3 : error_at (OMP_CLAUSE_LOCATION (c),
8854 : "%qD is not a variable in %<allocate%> clause", t);
8855 : else
8856 0 : error_at (OMP_CLAUSE_LOCATION (c),
8857 : "%qE is not a variable in %<allocate%> clause", t);
8858 : remove = true;
8859 : }
8860 2582 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8861 : {
8862 12 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8863 : "%qD appears more than once in %<allocate%> clauses",
8864 : t);
8865 12 : remove = true;
8866 : }
8867 : else
8868 : {
8869 2570 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8870 2570 : allocate_seen = true;
8871 : }
8872 2585 : tree allocator, align;
8873 2585 : align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
8874 2585 : if (error_operand_p (align))
8875 : {
8876 : remove = true;
8877 : break;
8878 : }
8879 2585 : if (align)
8880 : {
8881 207 : if (!type_dependent_expression_p (align)
8882 207 : && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
8883 : {
8884 4 : error_at (OMP_CLAUSE_LOCATION (c),
8885 : "%<allocate%> clause %<align%> modifier "
8886 : "argument needs to be positive constant "
8887 : "power of two integer expression");
8888 4 : remove = true;
8889 : }
8890 : else
8891 : {
8892 203 : align = mark_rvalue_use (align);
8893 203 : if (!processing_template_decl)
8894 : {
8895 188 : align = maybe_constant_value (align);
8896 188 : if (TREE_CODE (align) != INTEGER_CST
8897 185 : || !tree_fits_uhwi_p (align)
8898 373 : || !integer_pow2p (align))
8899 : {
8900 10 : error_at (OMP_CLAUSE_LOCATION (c),
8901 : "%<allocate%> clause %<align%> modifier "
8902 : "argument needs to be positive constant "
8903 : "power of two integer expression");
8904 10 : remove = true;
8905 : }
8906 : }
8907 : }
8908 207 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
8909 : }
8910 2585 : allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
8911 2585 : if (error_operand_p (allocator))
8912 : {
8913 : remove = true;
8914 : break;
8915 : }
8916 2585 : if (allocator == NULL_TREE)
8917 1537 : goto handle_field_decl;
8918 1048 : tree allocatort;
8919 1048 : allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
8920 1048 : if (!type_dependent_expression_p (allocator)
8921 1048 : && (TREE_CODE (allocatort) != ENUMERAL_TYPE
8922 1029 : || TYPE_NAME (allocatort) == NULL_TREE
8923 1029 : || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
8924 2058 : || (DECL_NAME (TYPE_NAME (allocatort))
8925 1029 : != get_identifier ("omp_allocator_handle_t"))
8926 1029 : || (TYPE_CONTEXT (allocatort)
8927 1029 : != DECL_CONTEXT (global_namespace))))
8928 : {
8929 16 : error_at (OMP_CLAUSE_LOCATION (c),
8930 : "%<allocate%> clause allocator expression has "
8931 : "type %qT rather than %<omp_allocator_handle_t%>",
8932 16 : TREE_TYPE (allocator));
8933 16 : remove = true;
8934 16 : break;
8935 : }
8936 : else
8937 : {
8938 1032 : allocator = mark_rvalue_use (allocator);
8939 1032 : if (!processing_template_decl)
8940 1013 : allocator = maybe_constant_value (allocator);
8941 1032 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
8942 : }
8943 1032 : goto handle_field_decl;
8944 :
8945 654 : case OMP_CLAUSE_DOACROSS:
8946 654 : t = OMP_CLAUSE_DECL (c);
8947 654 : if (t == NULL_TREE)
8948 : break;
8949 298 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
8950 : {
8951 298 : if (cp_finish_omp_clause_doacross_sink (c))
8952 12 : remove = true;
8953 : break;
8954 : }
8955 0 : gcc_unreachable ();
8956 141 : case OMP_CLAUSE_USES_ALLOCATORS:
8957 141 : t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
8958 141 : t = convert_from_reference (t);
8959 141 : if (t == error_mark_node)
8960 : {
8961 : remove = true;
8962 : break;
8963 : }
8964 129 : if (DECL_P (t)
8965 129 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8966 120 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8967 117 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
8968 : {
8969 3 : error_at (OMP_CLAUSE_LOCATION (c),
8970 : "%qE appears more than once in data clauses", t);
8971 3 : remove = true;
8972 : }
8973 126 : else if (DECL_P (t))
8974 117 : bitmap_set_bit (&generic_head, DECL_UID (t));
8975 129 : if (type_dependent_expression_p (t))
8976 : break;
8977 114 : if (TREE_CODE (t) == FIELD_DECL)
8978 : {
8979 0 : sorry_at (OMP_CLAUSE_LOCATION (c), "class member %qE not yet "
8980 : "supported in %<uses_allocators%> clause", t);
8981 0 : remove = true;
8982 0 : break;
8983 : }
8984 114 : if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
8985 219 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
8986 : "omp_allocator_handle_t") != 0)
8987 : {
8988 9 : error_at (OMP_CLAUSE_LOCATION (c),
8989 : "allocator %qE must be of %<omp_allocator_handle_t%> "
8990 : "type", t);
8991 9 : remove = true;
8992 9 : break;
8993 : }
8994 105 : tree init;
8995 105 : if (TREE_CODE (t) == CONST_DECL)
8996 15 : init = DECL_INITIAL(t);
8997 : else
8998 : init = t;
8999 105 : if (!DECL_P (t)
9000 105 : && (init == NULL_TREE
9001 9 : || TREE_CODE (init) != INTEGER_CST
9002 9 : || ((wi::to_widest (init) < 0
9003 9 : || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
9004 3 : && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
9005 3 : || (wi::to_widest (init)
9006 6 : > GOMP_OMPX_PREDEF_ALLOC_MAX)))))
9007 : {
9008 3 : remove = true;
9009 3 : error_at (OMP_CLAUSE_LOCATION (c),
9010 : "allocator %qE must be either a variable or a "
9011 : "predefined allocator", t);
9012 3 : break;
9013 : }
9014 102 : else if (TREE_CODE (t) == CONST_DECL)
9015 : {
9016 : /* omp_null_allocator is ignored and for predefined allocators,
9017 : not special handling is required; thus, remove them removed. */
9018 15 : remove = true;
9019 :
9020 15 : if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
9021 15 : || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
9022 : {
9023 0 : error_at (OMP_CLAUSE_LOCATION (c),
9024 : "modifiers cannot be used with predefined "
9025 : "allocators");
9026 0 : break;
9027 : }
9028 : }
9029 102 : t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
9030 102 : if (t == error_mark_node)
9031 : {
9032 : remove = true;
9033 : break;
9034 : }
9035 99 : if (t != NULL_TREE
9036 18 : && !type_dependent_expression_p (t)
9037 117 : && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
9038 15 : || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9039 24 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9040 : "omp_memspace_handle_t") != 0))
9041 : {
9042 6 : error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
9043 : " constant enum of %<omp_memspace_handle_t%> type", t);
9044 6 : remove = true;
9045 6 : break;
9046 : }
9047 93 : t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
9048 93 : if (t == error_mark_node)
9049 : {
9050 : remove = true;
9051 : break;
9052 : }
9053 90 : if (type_dependent_expression_p (t))
9054 : break;
9055 90 : if (t != NULL_TREE
9056 39 : && t != error_mark_node
9057 39 : && !type_dependent_expression_p (t)
9058 129 : && (!DECL_P (t)
9059 39 : || DECL_EXTERNAL (t)
9060 33 : || TREE_CODE (t) == PARM_DECL))
9061 : {
9062 12 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
9063 : "defined in same scope as the construct on which the "
9064 : "clause appears", t);
9065 12 : remove = true;
9066 : }
9067 90 : if (t != NULL_TREE)
9068 : {
9069 39 : bool type_err = false;
9070 :
9071 39 : if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
9072 33 : || DECL_SIZE (t) == NULL_TREE
9073 69 : || !COMPLETE_TYPE_P (TREE_TYPE (t)))
9074 : type_err = true;
9075 : else
9076 : {
9077 30 : tree elem_t = TREE_TYPE (TREE_TYPE (t));
9078 30 : if (TREE_CODE (elem_t) != RECORD_TYPE
9079 60 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
9080 : "omp_alloctrait_t") != 0
9081 60 : || !TYPE_READONLY (elem_t))
9082 : type_err = true;
9083 : }
9084 27 : if (type_err)
9085 : {
9086 12 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
9087 : "be of %<const omp_alloctrait_t []%> type", t);
9088 12 : remove = true;
9089 : }
9090 27 : else if (TREE_CODE (array_type_nelts_top (TREE_TYPE (t)))
9091 : != INTEGER_CST)
9092 : {
9093 3 : error_at (OMP_CLAUSE_LOCATION (c), "variable length traits "
9094 : "arrays are not supported");
9095 3 : remove = true;
9096 : }
9097 : else
9098 : {
9099 24 : tree cst_val = decl_constant_value (t);
9100 24 : if (cst_val == t)
9101 : {
9102 3 : error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
9103 : "initialized with constants");
9104 3 : remove = true;
9105 : }
9106 : }
9107 : }
9108 90 : if (remove)
9109 : break;
9110 54 : pc = &OMP_CLAUSE_CHAIN (c);
9111 54 : continue;
9112 1805 : case OMP_CLAUSE_DEPEND:
9113 1805 : depend_clause = c;
9114 : /* FALLTHRU */
9115 2171 : case OMP_CLAUSE_AFFINITY:
9116 2171 : t = OMP_CLAUSE_DECL (c);
9117 2171 : if (OMP_ITERATOR_DECL_P (t))
9118 : {
9119 622 : if (TREE_PURPOSE (t) != last_iterators)
9120 524 : last_iterators_remove
9121 524 : = cp_omp_finish_iterators (TREE_PURPOSE (t));
9122 622 : last_iterators = TREE_PURPOSE (t);
9123 622 : t = TREE_VALUE (t);
9124 622 : if (last_iterators_remove)
9125 144 : t = error_mark_node;
9126 : }
9127 : else
9128 : last_iterators = NULL_TREE;
9129 :
9130 2171 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9131 : {
9132 1164 : if (handle_omp_array_sections (c, ort))
9133 : remove = true;
9134 913 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9135 913 : && (OMP_CLAUSE_DEPEND_KIND (c)
9136 : == OMP_CLAUSE_DEPEND_DEPOBJ))
9137 : {
9138 6 : error_at (OMP_CLAUSE_LOCATION (c),
9139 : "%<depend%> clause with %<depobj%> dependence "
9140 : "type on array section");
9141 6 : remove = true;
9142 : }
9143 : break;
9144 : }
9145 1007 : if (t == error_mark_node)
9146 : remove = true;
9147 845 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9148 845 : && t == ridpointers[RID_OMP_ALL_MEMORY])
9149 : {
9150 33 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
9151 33 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
9152 : {
9153 9 : error_at (OMP_CLAUSE_LOCATION (c),
9154 : "%<omp_all_memory%> used with %<depend%> kind "
9155 : "other than %<out%> or %<inout%>");
9156 9 : remove = true;
9157 : }
9158 33 : if (processing_template_decl)
9159 : break;
9160 : }
9161 812 : else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9162 : break;
9163 620 : else if (!lvalue_p (t))
9164 : {
9165 19 : if (DECL_P (t))
9166 24 : error_at (OMP_CLAUSE_LOCATION (c),
9167 : "%qD is not lvalue expression nor array section "
9168 : "in %qs clause", t,
9169 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9170 : else
9171 14 : error_at (OMP_CLAUSE_LOCATION (c),
9172 : "%qE is not lvalue expression nor array section "
9173 : "in %qs clause", t,
9174 7 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9175 : remove = true;
9176 : }
9177 601 : else if (TREE_CODE (t) == COMPONENT_REF
9178 24 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
9179 625 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
9180 : {
9181 8 : error_at (OMP_CLAUSE_LOCATION (c),
9182 : "bit-field %qE in %qs clause", t,
9183 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9184 4 : remove = true;
9185 : }
9186 597 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9187 597 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
9188 : {
9189 130 : if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9190 8 : ? TREE_TYPE (TREE_TYPE (t))
9191 57 : : TREE_TYPE (t)))
9192 : {
9193 12 : error_at (OMP_CLAUSE_LOCATION (c),
9194 : "%qE does not have %<omp_depend_t%> type in "
9195 : "%<depend%> clause with %<depobj%> dependence "
9196 : "type", t);
9197 12 : remove = true;
9198 : }
9199 : }
9200 532 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9201 972 : && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9202 4 : ? TREE_TYPE (TREE_TYPE (t))
9203 436 : : TREE_TYPE (t)))
9204 : {
9205 15 : error_at (OMP_CLAUSE_LOCATION (c),
9206 : "%qE should not have %<omp_depend_t%> type in "
9207 : "%<depend%> clause with dependence type other than "
9208 : "%<depobj%>", t);
9209 15 : remove = true;
9210 : }
9211 64 : if (!remove)
9212 : {
9213 594 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
9214 24 : t = null_pointer_node;
9215 : else
9216 : {
9217 570 : tree addr = cp_build_addr_expr (t, tf_warning_or_error);
9218 570 : if (addr == error_mark_node)
9219 : {
9220 : remove = true;
9221 : break;
9222 : }
9223 570 : t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
9224 : addr, RO_UNARY_STAR,
9225 : tf_warning_or_error);
9226 570 : if (t == error_mark_node)
9227 : {
9228 : remove = true;
9229 : break;
9230 : }
9231 : }
9232 594 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
9233 136 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
9234 730 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
9235 : == TREE_VEC))
9236 136 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
9237 : else
9238 458 : OMP_CLAUSE_DECL (c) = t;
9239 : }
9240 : break;
9241 69 : case OMP_CLAUSE_DETACH:
9242 69 : t = OMP_CLAUSE_DECL (c);
9243 69 : if (detach_seen)
9244 : {
9245 3 : error_at (OMP_CLAUSE_LOCATION (c),
9246 : "too many %qs clauses on a task construct",
9247 : "detach");
9248 3 : remove = true;
9249 3 : break;
9250 : }
9251 66 : else if (error_operand_p (t))
9252 : {
9253 : remove = true;
9254 : break;
9255 : }
9256 : else
9257 : {
9258 63 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
9259 63 : if (!type_dependent_expression_p (t)
9260 63 : && (!INTEGRAL_TYPE_P (type)
9261 : || TREE_CODE (type) != ENUMERAL_TYPE
9262 51 : || TYPE_NAME (type) == NULL_TREE
9263 102 : || (DECL_NAME (TYPE_NAME (type))
9264 51 : != get_identifier ("omp_event_handle_t"))))
9265 : {
9266 6 : error_at (OMP_CLAUSE_LOCATION (c),
9267 : "%<detach%> clause event handle "
9268 : "has type %qT rather than "
9269 : "%<omp_event_handle_t%>",
9270 : type);
9271 6 : remove = true;
9272 : }
9273 63 : detach_seen = c;
9274 63 : cxx_mark_addressable (t);
9275 : }
9276 63 : break;
9277 :
9278 16110 : case OMP_CLAUSE_MAP:
9279 16110 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
9280 190 : goto move_implicit;
9281 15920 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
9282 15920 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
9283 : {
9284 : remove = true;
9285 : break;
9286 : }
9287 : /* FALLTHRU */
9288 19038 : case OMP_CLAUSE_TO:
9289 19038 : case OMP_CLAUSE_FROM:
9290 19038 : if (OMP_CLAUSE_ITERATORS (c)
9291 19038 : && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
9292 : {
9293 97266 : t = error_mark_node;
9294 : break;
9295 : }
9296 : /* FALLTHRU */
9297 19874 : case OMP_CLAUSE__CACHE_:
9298 19874 : {
9299 19874 : using namespace omp_addr_tokenizer;
9300 19874 : auto_vec<omp_addr_token *, 10> addr_tokens;
9301 :
9302 19874 : t = OMP_CLAUSE_DECL (c);
9303 19874 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9304 : {
9305 5875 : grp_start_p = pc;
9306 5875 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9307 :
9308 5875 : if (handle_omp_array_sections (c, ort))
9309 : remove = true;
9310 : else
9311 : {
9312 5109 : t = OMP_CLAUSE_DECL (c);
9313 5109 : if (TREE_CODE (t) != OMP_ARRAY_SECTION
9314 4252 : && !type_dependent_expression_p (t)
9315 9361 : && !omp_mappable_type (TREE_TYPE (t)))
9316 : {
9317 3 : auto_diagnostic_group d;
9318 6 : error_at (OMP_CLAUSE_LOCATION (c),
9319 : "array section does not have mappable type "
9320 : "in %qs clause",
9321 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9322 3 : if (TREE_TYPE (t) != error_mark_node
9323 3 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9324 3 : cxx_incomplete_type_inform (TREE_TYPE (t));
9325 3 : remove = true;
9326 3 : }
9327 6959 : while (TREE_CODE (t) == ARRAY_REF)
9328 1850 : t = TREE_OPERAND (t, 0);
9329 :
9330 5109 : if (type_dependent_expression_p (t))
9331 : break;
9332 :
9333 4635 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9334 :
9335 4635 : if (!ai.map_supported_p ()
9336 4635 : || !omp_parse_expr (addr_tokens, t))
9337 : {
9338 18 : sorry_at (OMP_CLAUSE_LOCATION (c),
9339 : "unsupported map expression %qE",
9340 9 : OMP_CLAUSE_DECL (c));
9341 9 : remove = true;
9342 9 : break;
9343 : }
9344 :
9345 : /* This check is to determine if this will be the only map
9346 : node created for this clause. Otherwise, we'll check
9347 : the following FIRSTPRIVATE_POINTER,
9348 : FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
9349 : iteration(s) of the loop. */
9350 9203 : if (addr_tokens.length () >= 4
9351 1063 : && addr_tokens[0]->type == STRUCTURE_BASE
9352 1057 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
9353 1057 : && addr_tokens[1]->type == ACCESS_METHOD
9354 1057 : && addr_tokens[2]->type == COMPONENT_SELECTOR
9355 977 : && addr_tokens[3]->type == ACCESS_METHOD
9356 5340 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
9357 551 : || (addr_tokens[3]->u.access_kind
9358 : == ACCESS_INDEXED_ARRAY)))
9359 : {
9360 165 : tree rt = addr_tokens[1]->expr;
9361 :
9362 165 : gcc_assert (DECL_P (rt));
9363 :
9364 165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9365 154 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9366 165 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
9367 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
9368 0 : || bitmap_bit_p (&map_firstprivate_head,
9369 0 : DECL_UID (rt))))
9370 : {
9371 : remove = true;
9372 : break;
9373 : }
9374 165 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
9375 : break;
9376 116 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
9377 : {
9378 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9379 0 : error_at (OMP_CLAUSE_LOCATION (c),
9380 : "%qD appears more than once in motion"
9381 : " clauses", rt);
9382 0 : else if (openacc)
9383 0 : error_at (OMP_CLAUSE_LOCATION (c),
9384 : "%qD appears more than once in data"
9385 : " clauses", rt);
9386 : else
9387 0 : error_at (OMP_CLAUSE_LOCATION (c),
9388 : "%qD appears more than once in map"
9389 : " clauses", rt);
9390 : remove = true;
9391 : }
9392 : else
9393 : {
9394 116 : bitmap_set_bit (&map_head, DECL_UID (rt));
9395 116 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
9396 : }
9397 : }
9398 4635 : }
9399 5343 : if (cp_oacc_check_attachments (c))
9400 12 : remove = true;
9401 5343 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9402 4409 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9403 4345 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9404 5441 : && !OMP_CLAUSE_SIZE (c))
9405 : /* In this case, we have a single array element which is a
9406 : pointer, and we already set OMP_CLAUSE_SIZE in
9407 : handle_omp_array_sections above. For attach/detach
9408 : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
9409 : to zero here. */
9410 60 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9411 : break;
9412 : }
9413 13999 : else if (type_dependent_expression_p (t))
9414 : break;
9415 13225 : else if (!omp_parse_expr (addr_tokens, t))
9416 : {
9417 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
9418 : "unsupported map expression %qE",
9419 0 : OMP_CLAUSE_DECL (c));
9420 0 : remove = true;
9421 0 : break;
9422 : }
9423 13225 : if (t == error_mark_node)
9424 : {
9425 : remove = true;
9426 : break;
9427 : }
9428 : /* OpenACC attach / detach clauses must be pointers. */
9429 13131 : if (cp_oacc_check_attachments (c))
9430 : {
9431 : remove = true;
9432 : break;
9433 : }
9434 13107 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9435 10146 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9436 10097 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9437 13181 : && !OMP_CLAUSE_SIZE (c))
9438 : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
9439 : bias) to zero here, so it is not set erroneously to the
9440 : pointer size later on in gimplify.cc. */
9441 66 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9442 :
9443 13107 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9444 :
9445 13107 : if (!ai.check_clause (c))
9446 : {
9447 : remove = true;
9448 : break;
9449 : }
9450 :
9451 13086 : if (!ai.map_supported_p ())
9452 : {
9453 88 : sorry_at (OMP_CLAUSE_LOCATION (c),
9454 : "unsupported map expression %qE",
9455 44 : OMP_CLAUSE_DECL (c));
9456 44 : remove = true;
9457 44 : break;
9458 : }
9459 :
9460 26084 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
9461 : || addr_tokens[0]->type == STRUCTURE_BASE)
9462 : && addr_tokens[1]->type == ACCESS_METHOD);
9463 :
9464 13042 : t = addr_tokens[1]->expr;
9465 :
9466 : /* This is used to prevent cxx_mark_addressable from being called
9467 : on 'this' for expressions like 'this->a', i.e. typical member
9468 : accesses. */
9469 13042 : indir_component_ref_p
9470 26084 : = (addr_tokens[0]->type == STRUCTURE_BASE
9471 13042 : && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
9472 :
9473 13042 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
9474 1 : goto skip_decl_checks;
9475 :
9476 : /* For OpenMP, we can access a struct "t" and "t.d" on the same
9477 : mapping. OpenACC allows multiple fields of the same structure
9478 : to be written. */
9479 13041 : if (addr_tokens[0]->type == STRUCTURE_BASE
9480 13041 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
9481 1239 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
9482 1294 : goto skip_decl_checks;
9483 :
9484 11747 : if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
9485 : {
9486 0 : OMP_CLAUSE_DECL (c)
9487 0 : = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
9488 0 : break;
9489 : }
9490 11747 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9491 : {
9492 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9493 : break;
9494 0 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9495 0 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9496 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
9497 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
9498 0 : || (!openacc && EXPR_P (t))))
9499 : break;
9500 0 : if (DECL_P (t))
9501 0 : error_at (OMP_CLAUSE_LOCATION (c),
9502 : "%qD is not a variable in %qs clause", t,
9503 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9504 : else
9505 0 : error_at (OMP_CLAUSE_LOCATION (c),
9506 : "%qE is not a variable in %qs clause", t,
9507 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9508 : remove = true;
9509 : }
9510 11747 : else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
9511 : {
9512 0 : error_at (OMP_CLAUSE_LOCATION (c),
9513 : "%qD is threadprivate variable in %qs clause", t,
9514 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9515 0 : remove = true;
9516 : }
9517 11747 : else if (!processing_template_decl
9518 11571 : && !TYPE_REF_P (TREE_TYPE (t))
9519 10898 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9520 7987 : || (OMP_CLAUSE_MAP_KIND (c)
9521 : != GOMP_MAP_FIRSTPRIVATE_POINTER))
9522 8940 : && !indir_component_ref_p
9523 8576 : && (t != current_class_ptr
9524 18 : || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9525 6 : || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
9526 20323 : && !cxx_mark_addressable (t))
9527 : remove = true;
9528 11747 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9529 8818 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9530 8818 : || (OMP_CLAUSE_MAP_KIND (c)
9531 : == GOMP_MAP_FIRSTPRIVATE_POINTER)
9532 6860 : || (OMP_CLAUSE_MAP_KIND (c)
9533 : == GOMP_MAP_ATTACH_DETACH)))
9534 9134 : && t == OMP_CLAUSE_DECL (c)
9535 8460 : && !type_dependent_expression_p (t)
9536 28667 : && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
9537 274 : ? TREE_TYPE (TREE_TYPE (t))
9538 8186 : : TREE_TYPE (t)))
9539 : {
9540 42 : auto_diagnostic_group d;
9541 84 : error_at (OMP_CLAUSE_LOCATION (c),
9542 : "%qD does not have a mappable type in %qs clause", t,
9543 42 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9544 42 : if (TREE_TYPE (t) != error_mark_node
9545 42 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9546 39 : cxx_incomplete_type_inform (TREE_TYPE (t));
9547 42 : remove = true;
9548 42 : }
9549 11705 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9550 8782 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
9551 93 : && !type_dependent_expression_p (t)
9552 11798 : && !INDIRECT_TYPE_P (TREE_TYPE (t)))
9553 : {
9554 6 : error_at (OMP_CLAUSE_LOCATION (c),
9555 : "%qD is not a pointer variable", t);
9556 6 : remove = true;
9557 : }
9558 11699 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9559 8776 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9560 12102 : && (bitmap_bit_p (&map_head, DECL_UID (t))
9561 367 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
9562 367 : || bitmap_bit_p (&map_firstprivate_head,
9563 367 : DECL_UID (t))))
9564 : remove = true;
9565 11660 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9566 11660 : && (OMP_CLAUSE_MAP_KIND (c)
9567 : == GOMP_MAP_FIRSTPRIVATE_POINTER))
9568 : {
9569 1952 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
9570 1952 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9571 3901 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
9572 : {
9573 15 : error_at (OMP_CLAUSE_LOCATION (c),
9574 : "%qD appears more than once in data clauses", t);
9575 15 : remove = true;
9576 : }
9577 1937 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9578 12 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9579 1945 : && openacc)
9580 : {
9581 3 : error_at (OMP_CLAUSE_LOCATION (c),
9582 : "%qD appears more than once in data clauses", t);
9583 3 : remove = true;
9584 : }
9585 : else
9586 1934 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9587 : }
9588 9708 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9589 9708 : && (OMP_CLAUSE_MAP_KIND (c)
9590 : == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
9591 115 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9592 9593 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9593 171 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9594 28 : && ort != C_ORT_OMP
9595 9621 : && ort != C_ORT_OMP_EXIT_DATA)
9596 : {
9597 18 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9598 0 : error_at (OMP_CLAUSE_LOCATION (c),
9599 : "%qD appears more than once in motion clauses", t);
9600 18 : else if (openacc)
9601 9 : error_at (OMP_CLAUSE_LOCATION (c),
9602 : "%qD appears more than once in data clauses", t);
9603 : else
9604 9 : error_at (OMP_CLAUSE_LOCATION (c),
9605 : "%qD appears more than once in map clauses", t);
9606 : remove = true;
9607 : }
9608 9575 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
9609 : {
9610 0 : error_at (OMP_CLAUSE_LOCATION (c),
9611 : "%qD appears more than once in data clauses", t);
9612 0 : remove = true;
9613 : }
9614 9575 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9615 9575 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
9616 : {
9617 27 : if (openacc)
9618 0 : error_at (OMP_CLAUSE_LOCATION (c),
9619 : "%qD appears more than once in data clauses", t);
9620 : else
9621 27 : error_at (OMP_CLAUSE_LOCATION (c),
9622 : "%qD appears both in data and map clauses", t);
9623 : remove = true;
9624 : }
9625 9548 : else if (!omp_access_chain_p (addr_tokens, 1))
9626 : {
9627 9468 : bitmap_set_bit (&map_head, DECL_UID (t));
9628 :
9629 9468 : tree decl = OMP_CLAUSE_DECL (c);
9630 9468 : if (t != decl
9631 9468 : && (TREE_CODE (decl) == COMPONENT_REF
9632 162 : || (INDIRECT_REF_P (decl)
9633 162 : && (TREE_CODE (TREE_OPERAND (decl, 0))
9634 : == COMPONENT_REF)
9635 150 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
9636 : 0))))))
9637 1141 : bitmap_set_bit (&map_field_head, DECL_UID (t));
9638 : }
9639 :
9640 4551 : skip_decl_checks:
9641 : /* If we call ai.expand_map_clause in handle_omp_array_sections,
9642 : the containing loop (here) iterates through the new nodes
9643 : created by that expansion. Avoid expanding those again (just
9644 : by checking the node type). */
9645 4551 : if (!remove
9646 12892 : && !processing_template_decl
9647 12719 : && ort != C_ORT_DECLARE_SIMD
9648 12719 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9649 9776 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
9650 7842 : && (OMP_CLAUSE_MAP_KIND (c)
9651 : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
9652 7727 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
9653 7727 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
9654 6733 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
9655 6684 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
9656 : {
9657 9602 : grp_start_p = pc;
9658 9602 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9659 9602 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
9660 : addr_tokens, ort);
9661 9602 : if (nc != error_mark_node)
9662 9602 : c = nc;
9663 : }
9664 19939 : }
9665 13042 : break;
9666 :
9667 596 : case OMP_CLAUSE_ENTER:
9668 596 : case OMP_CLAUSE_LINK:
9669 596 : t = OMP_CLAUSE_DECL (c);
9670 596 : const char *cname;
9671 596 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
9672 596 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
9673 596 : && OMP_CLAUSE_ENTER_TO (c))
9674 : cname = "to";
9675 596 : if (TREE_CODE (t) == FUNCTION_DECL
9676 596 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9677 : ;
9678 379 : else if (!VAR_P (t))
9679 : {
9680 12 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9681 : {
9682 9 : if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
9683 6 : error_at (OMP_CLAUSE_LOCATION (c),
9684 : "template %qE in clause %qs", t, cname);
9685 3 : else if (really_overloaded_fn (t))
9686 3 : error_at (OMP_CLAUSE_LOCATION (c),
9687 : "overloaded function name %qE in clause %qs", t,
9688 : cname);
9689 : else
9690 0 : error_at (OMP_CLAUSE_LOCATION (c),
9691 : "%qE is neither a variable nor a function name "
9692 : "in clause %qs", t, cname);
9693 : }
9694 : else
9695 3 : error_at (OMP_CLAUSE_LOCATION (c),
9696 : "%qE is not a variable in clause %qs", t, cname);
9697 : remove = true;
9698 : }
9699 367 : else if (DECL_THREAD_LOCAL_P (t))
9700 : {
9701 6 : error_at (OMP_CLAUSE_LOCATION (c),
9702 : "%qD is threadprivate variable in %qs clause", t,
9703 : cname);
9704 6 : remove = true;
9705 : }
9706 361 : else if (!omp_mappable_type (TREE_TYPE (t)))
9707 : {
9708 18 : auto_diagnostic_group d;
9709 18 : error_at (OMP_CLAUSE_LOCATION (c),
9710 : "%qD does not have a mappable type in %qs clause", t,
9711 : cname);
9712 18 : if (TREE_TYPE (t) != error_mark_node
9713 18 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9714 18 : cxx_incomplete_type_inform (TREE_TYPE (t));
9715 18 : remove = true;
9716 18 : }
9717 24 : if (remove)
9718 : break;
9719 560 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9720 : {
9721 24 : error_at (OMP_CLAUSE_LOCATION (c),
9722 : "%qE appears more than once on the same "
9723 : "%<declare target%> directive", t);
9724 24 : remove = true;
9725 : }
9726 : else
9727 536 : bitmap_set_bit (&generic_head, DECL_UID (t));
9728 : break;
9729 :
9730 457 : case OMP_CLAUSE_UNIFORM:
9731 457 : t = OMP_CLAUSE_DECL (c);
9732 457 : if (TREE_CODE (t) != PARM_DECL)
9733 : {
9734 0 : if (processing_template_decl)
9735 : break;
9736 0 : if (DECL_P (t))
9737 0 : error_at (OMP_CLAUSE_LOCATION (c),
9738 : "%qD is not an argument in %<uniform%> clause", t);
9739 : else
9740 0 : error_at (OMP_CLAUSE_LOCATION (c),
9741 : "%qE is not an argument in %<uniform%> clause", t);
9742 : remove = true;
9743 : break;
9744 : }
9745 : /* map_head bitmap is used as uniform_head if declare_simd. */
9746 457 : bitmap_set_bit (&map_head, DECL_UID (t));
9747 457 : goto check_dup_generic;
9748 :
9749 165 : case OMP_CLAUSE_GRAINSIZE:
9750 165 : t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
9751 165 : if (t == error_mark_node)
9752 : remove = true;
9753 165 : else if (!type_dependent_expression_p (t)
9754 165 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9755 : {
9756 0 : error_at (OMP_CLAUSE_LOCATION (c),
9757 : "%<grainsize%> expression must be integral");
9758 0 : remove = true;
9759 : }
9760 : else
9761 : {
9762 165 : t = mark_rvalue_use (t);
9763 165 : if (!processing_template_decl)
9764 : {
9765 164 : t = maybe_constant_value (t);
9766 164 : if (TREE_CODE (t) == INTEGER_CST
9767 164 : && tree_int_cst_sgn (t) != 1)
9768 : {
9769 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9770 : "%<grainsize%> value must be positive");
9771 0 : t = integer_one_node;
9772 : }
9773 164 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9774 : }
9775 165 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
9776 : }
9777 : break;
9778 :
9779 276 : case OMP_CLAUSE_PRIORITY:
9780 276 : t = OMP_CLAUSE_PRIORITY_EXPR (c);
9781 276 : if (t == error_mark_node)
9782 : remove = true;
9783 276 : else if (!type_dependent_expression_p (t)
9784 276 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9785 : {
9786 0 : error_at (OMP_CLAUSE_LOCATION (c),
9787 : "%<priority%> expression must be integral");
9788 0 : remove = true;
9789 : }
9790 : else
9791 : {
9792 276 : t = mark_rvalue_use (t);
9793 276 : if (!processing_template_decl)
9794 : {
9795 276 : t = maybe_constant_value (t);
9796 276 : if (TREE_CODE (t) == INTEGER_CST
9797 276 : && tree_int_cst_sgn (t) == -1)
9798 : {
9799 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9800 : "%<priority%> value must be non-negative");
9801 0 : t = integer_one_node;
9802 : }
9803 276 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9804 : }
9805 276 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
9806 : }
9807 : break;
9808 :
9809 228 : case OMP_CLAUSE_HINT:
9810 228 : t = OMP_CLAUSE_HINT_EXPR (c);
9811 228 : if (t == error_mark_node)
9812 : remove = true;
9813 228 : else if (!type_dependent_expression_p (t)
9814 228 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9815 : {
9816 9 : error_at (OMP_CLAUSE_LOCATION (c),
9817 : "%<hint%> expression must be integral");
9818 9 : remove = true;
9819 : }
9820 : else
9821 : {
9822 219 : t = mark_rvalue_use (t);
9823 219 : if (!processing_template_decl)
9824 : {
9825 171 : t = maybe_constant_value (t);
9826 171 : if (TREE_CODE (t) != INTEGER_CST)
9827 : {
9828 16 : error_at (OMP_CLAUSE_LOCATION (c),
9829 : "%<hint%> expression must be constant integer "
9830 : "expression");
9831 16 : remove = true;
9832 : }
9833 : }
9834 219 : OMP_CLAUSE_HINT_EXPR (c) = t;
9835 : }
9836 : break;
9837 :
9838 186 : case OMP_CLAUSE_FILTER:
9839 186 : t = OMP_CLAUSE_FILTER_EXPR (c);
9840 186 : if (t == error_mark_node)
9841 : remove = true;
9842 186 : else if (!type_dependent_expression_p (t)
9843 186 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9844 : {
9845 6 : error_at (OMP_CLAUSE_LOCATION (c),
9846 : "%<filter%> expression must be integral");
9847 6 : remove = true;
9848 : }
9849 : else
9850 : {
9851 180 : t = mark_rvalue_use (t);
9852 180 : if (!processing_template_decl)
9853 : {
9854 177 : t = maybe_constant_value (t);
9855 177 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9856 : }
9857 180 : OMP_CLAUSE_FILTER_EXPR (c) = t;
9858 : }
9859 : break;
9860 :
9861 433 : case OMP_CLAUSE_IS_DEVICE_PTR:
9862 433 : case OMP_CLAUSE_USE_DEVICE_PTR:
9863 433 : field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
9864 433 : t = OMP_CLAUSE_DECL (c);
9865 433 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
9866 329 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9867 433 : if (!type_dependent_expression_p (t))
9868 : {
9869 431 : tree type = TREE_TYPE (t);
9870 431 : if (!TYPE_PTR_P (type)
9871 431 : && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
9872 : {
9873 57 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
9874 57 : && ort == C_ORT_OMP)
9875 : {
9876 3 : error_at (OMP_CLAUSE_LOCATION (c),
9877 : "%qs variable is neither a pointer "
9878 : "nor reference to pointer",
9879 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9880 3 : remove = true;
9881 : }
9882 54 : else if (TREE_CODE (type) != ARRAY_TYPE
9883 54 : && (!TYPE_REF_P (type)
9884 2 : || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
9885 : {
9886 12 : error_at (OMP_CLAUSE_LOCATION (c),
9887 : "%qs variable is neither a pointer, nor an "
9888 : "array nor reference to pointer or array",
9889 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9890 12 : remove = true;
9891 : }
9892 : }
9893 : }
9894 433 : goto check_dup_generic;
9895 :
9896 267 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
9897 267 : t = OMP_CLAUSE_DECL (c);
9898 267 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9899 : {
9900 28 : if (handle_omp_array_sections (c, ort))
9901 : remove = true;
9902 : else
9903 : {
9904 28 : t = OMP_CLAUSE_DECL (c);
9905 30 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
9906 2 : t = TREE_OPERAND (t, 0);
9907 64 : while (INDIRECT_REF_P (t)
9908 64 : || TREE_CODE (t) == ARRAY_REF)
9909 36 : t = TREE_OPERAND (t, 0);
9910 : }
9911 : }
9912 267 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9913 : {
9914 267 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9915 267 : if (!processing_template_decl
9916 267 : && !cxx_mark_addressable (t))
9917 : remove = true;
9918 : }
9919 267 : goto check_dup_generic_t;
9920 :
9921 76 : case OMP_CLAUSE_USE_DEVICE_ADDR:
9922 76 : field_ok = true;
9923 76 : t = OMP_CLAUSE_DECL (c);
9924 76 : if (!processing_template_decl
9925 74 : && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9926 74 : && !TYPE_REF_P (TREE_TYPE (t))
9927 143 : && !cxx_mark_addressable (t))
9928 : remove = true;
9929 76 : goto check_dup_generic;
9930 :
9931 : case OMP_CLAUSE_NOWAIT:
9932 : case OMP_CLAUSE_DEFAULT:
9933 : case OMP_CLAUSE_UNTIED:
9934 : case OMP_CLAUSE_COLLAPSE:
9935 : case OMP_CLAUSE_PARALLEL:
9936 : case OMP_CLAUSE_FOR:
9937 : case OMP_CLAUSE_SECTIONS:
9938 : case OMP_CLAUSE_TASKGROUP:
9939 : case OMP_CLAUSE_PROC_BIND:
9940 : case OMP_CLAUSE_DEVICE_TYPE:
9941 : case OMP_CLAUSE_NOGROUP:
9942 : case OMP_CLAUSE_THREADS:
9943 : case OMP_CLAUSE_SIMD:
9944 : case OMP_CLAUSE_DEFAULTMAP:
9945 : case OMP_CLAUSE_BIND:
9946 : case OMP_CLAUSE_AUTO:
9947 : case OMP_CLAUSE_INDEPENDENT:
9948 : case OMP_CLAUSE_SEQ:
9949 : case OMP_CLAUSE_IF_PRESENT:
9950 : case OMP_CLAUSE_FINALIZE:
9951 : case OMP_CLAUSE_NOHOST:
9952 : case OMP_CLAUSE_INDIRECT:
9953 : break;
9954 :
9955 231 : case OMP_CLAUSE_MERGEABLE:
9956 231 : mergeable_seen = true;
9957 231 : break;
9958 :
9959 322 : case OMP_CLAUSE_TILE:
9960 754 : for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
9961 432 : list = TREE_CHAIN (list))
9962 : {
9963 432 : t = TREE_VALUE (list);
9964 :
9965 432 : if (t == error_mark_node)
9966 : remove = true;
9967 403 : else if (!type_dependent_expression_p (t)
9968 403 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9969 : {
9970 3 : error_at (OMP_CLAUSE_LOCATION (c),
9971 : "%<tile%> argument needs integral type");
9972 3 : remove = true;
9973 : }
9974 : else
9975 : {
9976 400 : t = mark_rvalue_use (t);
9977 400 : if (!processing_template_decl)
9978 : {
9979 : /* Zero is used to indicate '*', we permit you
9980 : to get there via an ICE of value zero. */
9981 385 : t = maybe_constant_value (t);
9982 385 : if (!tree_fits_shwi_p (t)
9983 369 : || tree_to_shwi (t) < 0)
9984 : {
9985 40 : error_at (OMP_CLAUSE_LOCATION (c),
9986 : "%<tile%> argument needs positive "
9987 : "integral constant");
9988 40 : remove = true;
9989 : }
9990 : }
9991 : }
9992 :
9993 : /* Update list item. */
9994 432 : TREE_VALUE (list) = t;
9995 : }
9996 : break;
9997 :
9998 1027 : case OMP_CLAUSE_SIZES:
9999 1027 : for (tree list = OMP_CLAUSE_SIZES_LIST (c);
10000 2688 : !remove && list; list = TREE_CHAIN (list))
10001 : {
10002 1661 : t = TREE_VALUE (list);
10003 :
10004 1661 : if (t == error_mark_node)
10005 0 : t = integer_one_node;
10006 1661 : else if (!type_dependent_expression_p (t)
10007 1661 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10008 : {
10009 8 : error_at (OMP_CLAUSE_LOCATION (c),
10010 : "%<sizes%> argument needs positive integral "
10011 : "constant");
10012 8 : t = integer_one_node;
10013 : }
10014 : else
10015 : {
10016 1653 : t = mark_rvalue_use (t);
10017 1653 : if (!processing_template_decl)
10018 : {
10019 1636 : t = maybe_constant_value (t);
10020 1636 : HOST_WIDE_INT n;
10021 1636 : if (!tree_fits_shwi_p (t)
10022 1632 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
10023 1632 : || (n = tree_to_shwi (t)) <= 0
10024 3240 : || (int)n != n)
10025 : {
10026 32 : error_at (OMP_CLAUSE_LOCATION (c),
10027 : "%<sizes%> argument needs positive "
10028 : "integral constant");
10029 32 : t = integer_one_node;
10030 : }
10031 : }
10032 : }
10033 :
10034 : /* Update list item. */
10035 1661 : TREE_VALUE (list) = t;
10036 : }
10037 : break;
10038 :
10039 630 : case OMP_CLAUSE_ORDERED:
10040 630 : ordered_seen = true;
10041 630 : break;
10042 :
10043 1549 : case OMP_CLAUSE_ORDER:
10044 1549 : if (order_seen)
10045 : remove = true;
10046 : else
10047 : order_seen = true;
10048 : break;
10049 :
10050 638 : case OMP_CLAUSE_INBRANCH:
10051 638 : case OMP_CLAUSE_NOTINBRANCH:
10052 638 : if (branch_seen)
10053 : {
10054 3 : error_at (OMP_CLAUSE_LOCATION (c),
10055 : "%<inbranch%> clause is incompatible with "
10056 : "%<notinbranch%>");
10057 3 : remove = true;
10058 : }
10059 : branch_seen = true;
10060 : break;
10061 :
10062 297 : case OMP_CLAUSE_INCLUSIVE:
10063 297 : case OMP_CLAUSE_EXCLUSIVE:
10064 297 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10065 297 : if (!t)
10066 297 : t = OMP_CLAUSE_DECL (c);
10067 297 : if (t == current_class_ptr)
10068 : {
10069 0 : error_at (OMP_CLAUSE_LOCATION (c),
10070 : "%<this%> allowed in OpenMP only in %<declare simd%>"
10071 : " clauses");
10072 0 : remove = true;
10073 0 : break;
10074 : }
10075 297 : if (!VAR_P (t)
10076 : && TREE_CODE (t) != PARM_DECL
10077 : && TREE_CODE (t) != FIELD_DECL)
10078 : {
10079 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
10080 : break;
10081 0 : if (DECL_P (t))
10082 0 : error_at (OMP_CLAUSE_LOCATION (c),
10083 : "%qD is not a variable in clause %qs", t,
10084 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10085 : else
10086 0 : error_at (OMP_CLAUSE_LOCATION (c),
10087 : "%qE is not a variable in clause %qs", t,
10088 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10089 : remove = true;
10090 : }
10091 : break;
10092 :
10093 : case OMP_CLAUSE_FULL:
10094 : break;
10095 :
10096 470 : case OMP_CLAUSE_PARTIAL:
10097 470 : partial_seen = true;
10098 470 : t = OMP_CLAUSE_PARTIAL_EXPR (c);
10099 470 : if (!t)
10100 : break;
10101 :
10102 313 : if (t == error_mark_node)
10103 : t = NULL_TREE;
10104 313 : else if (!type_dependent_expression_p (t)
10105 313 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10106 : {
10107 3 : error_at (OMP_CLAUSE_LOCATION (c),
10108 : "%<partial%> argument needs positive constant "
10109 : "integer expression");
10110 3 : t = NULL_TREE;
10111 : }
10112 : else
10113 : {
10114 310 : t = mark_rvalue_use (t);
10115 310 : if (!processing_template_decl)
10116 : {
10117 292 : t = maybe_constant_value (t);
10118 :
10119 292 : HOST_WIDE_INT n;
10120 584 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
10121 292 : || !tree_fits_shwi_p (t)
10122 286 : || (n = tree_to_shwi (t)) <= 0
10123 560 : || (int)n != n)
10124 : {
10125 24 : error_at (OMP_CLAUSE_LOCATION (c),
10126 : "%<partial%> argument needs positive "
10127 : "constant integer expression");
10128 24 : t = NULL_TREE;
10129 : }
10130 : }
10131 : }
10132 :
10133 313 : OMP_CLAUSE_PARTIAL_EXPR (c) = t;
10134 313 : break;
10135 549 : case OMP_CLAUSE_INIT:
10136 549 : init_seen = true;
10137 549 : OMP_CLAUSE_INIT_PREFER_TYPE (c)
10138 549 : = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
10139 549 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
10140 271 : init_no_targetsync_clause = c;
10141 : /* FALLTHRU */
10142 844 : case OMP_CLAUSE_DESTROY:
10143 844 : case OMP_CLAUSE_USE:
10144 844 : init_use_destroy_seen = true;
10145 844 : t = OMP_CLAUSE_DECL (c);
10146 844 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
10147 : {
10148 9 : error_at (OMP_CLAUSE_LOCATION (c),
10149 : "%qD appears more than once in action clauses", t);
10150 9 : remove = true;
10151 9 : break;
10152 : }
10153 835 : bitmap_set_bit (&generic_head, DECL_UID (t));
10154 : /* FALLTHRU */
10155 1099 : case OMP_CLAUSE_INTEROP:
10156 1099 : if (!processing_template_decl)
10157 : {
10158 1003 : if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
10159 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) && */
10160 1003 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
10161 : {
10162 126 : error_at (OMP_CLAUSE_LOCATION (c),
10163 : "%qD must be of %<omp_interop_t%>",
10164 63 : OMP_CLAUSE_DECL (c));
10165 63 : remove = true;
10166 : }
10167 940 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
10168 481 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
10169 1058 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
10170 : {
10171 36 : error_at (OMP_CLAUSE_LOCATION (c),
10172 18 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
10173 18 : remove = true;
10174 : }
10175 : }
10176 1099 : pc = &OMP_CLAUSE_CHAIN (c);
10177 1099 : break;
10178 0 : default:
10179 0 : gcc_unreachable ();
10180 54 : }
10181 :
10182 97266 : if (remove)
10183 : {
10184 2601 : if (grp_start_p)
10185 : {
10186 : /* If we found a clause to remove, we want to remove the whole
10187 : expanded group, otherwise gimplify
10188 : (omp_resolve_clause_dependencies) can get confused. */
10189 820 : *grp_start_p = grp_sentinel;
10190 820 : pc = grp_start_p;
10191 820 : grp_start_p = NULL;
10192 : }
10193 : else
10194 1781 : *pc = OMP_CLAUSE_CHAIN (c);
10195 : }
10196 : else
10197 94665 : pc = &OMP_CLAUSE_CHAIN (c);
10198 : }
10199 :
10200 62562 : if (grp_start_p
10201 62562 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
10202 140 : for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
10203 86 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
10204 :
10205 62562 : if (reduction_seen < 0 && (ordered_seen || schedule_seen))
10206 62562 : reduction_seen = -2;
10207 :
10208 158184 : for (pc = &clauses, c = clauses; c ; c = *pc)
10209 : {
10210 95622 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
10211 95622 : bool remove = false;
10212 95622 : bool need_complete_type = false;
10213 95622 : bool need_default_ctor = false;
10214 95622 : bool need_copy_ctor = false;
10215 95622 : bool need_copy_assignment = false;
10216 95622 : bool need_implicitly_determined = false;
10217 95622 : bool need_dtor = false;
10218 95622 : tree type, inner_type;
10219 :
10220 95622 : switch (c_kind)
10221 : {
10222 : case OMP_CLAUSE_SHARED:
10223 : need_implicitly_determined = true;
10224 : break;
10225 2540 : case OMP_CLAUSE_PRIVATE:
10226 2540 : need_complete_type = true;
10227 2540 : need_default_ctor = true;
10228 2540 : need_dtor = true;
10229 2540 : need_implicitly_determined = true;
10230 2540 : break;
10231 3156 : case OMP_CLAUSE_FIRSTPRIVATE:
10232 3156 : need_complete_type = true;
10233 3156 : need_copy_ctor = true;
10234 3156 : need_dtor = true;
10235 3156 : need_implicitly_determined = true;
10236 3156 : break;
10237 2763 : case OMP_CLAUSE_LASTPRIVATE:
10238 2763 : need_complete_type = true;
10239 2763 : need_copy_assignment = true;
10240 2763 : need_implicitly_determined = true;
10241 2763 : break;
10242 7286 : case OMP_CLAUSE_REDUCTION:
10243 7286 : if (reduction_seen == -2)
10244 27 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
10245 7286 : if (OMP_CLAUSE_REDUCTION_INSCAN (c))
10246 421 : need_copy_assignment = true;
10247 : need_implicitly_determined = true;
10248 : break;
10249 : case OMP_CLAUSE_IN_REDUCTION:
10250 : case OMP_CLAUSE_TASK_REDUCTION:
10251 : case OMP_CLAUSE_INCLUSIVE:
10252 : case OMP_CLAUSE_EXCLUSIVE:
10253 : need_implicitly_determined = true;
10254 : break;
10255 1550 : case OMP_CLAUSE_LINEAR:
10256 1550 : if (ort != C_ORT_OMP_DECLARE_SIMD)
10257 : need_implicitly_determined = true;
10258 679 : else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
10259 721 : && !bitmap_bit_p (&map_head,
10260 42 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
10261 : {
10262 6 : error_at (OMP_CLAUSE_LOCATION (c),
10263 : "%<linear%> clause step is a parameter %qD not "
10264 : "specified in %<uniform%> clause",
10265 6 : OMP_CLAUSE_LINEAR_STEP (c));
10266 6 : *pc = OMP_CLAUSE_CHAIN (c);
10267 74096 : continue;
10268 : }
10269 : break;
10270 : case OMP_CLAUSE_COPYPRIVATE:
10271 366 : need_copy_assignment = true;
10272 : break;
10273 : case OMP_CLAUSE_COPYIN:
10274 366 : need_copy_assignment = true;
10275 : break;
10276 798 : case OMP_CLAUSE_SIMDLEN:
10277 798 : if (safelen
10278 345 : && !processing_template_decl
10279 1143 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
10280 345 : OMP_CLAUSE_SIMDLEN_EXPR (c)))
10281 : {
10282 0 : error_at (OMP_CLAUSE_LOCATION (c),
10283 : "%<simdlen%> clause value is bigger than "
10284 : "%<safelen%> clause value");
10285 0 : OMP_CLAUSE_SIMDLEN_EXPR (c)
10286 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
10287 : }
10288 798 : pc = &OMP_CLAUSE_CHAIN (c);
10289 798 : continue;
10290 3853 : case OMP_CLAUSE_SCHEDULE:
10291 3853 : if (ordered_seen
10292 3853 : && (OMP_CLAUSE_SCHEDULE_KIND (c)
10293 : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
10294 : {
10295 21 : error_at (OMP_CLAUSE_LOCATION (c),
10296 : "%<nonmonotonic%> schedule modifier specified "
10297 : "together with %<ordered%> clause");
10298 42 : OMP_CLAUSE_SCHEDULE_KIND (c)
10299 21 : = (enum omp_clause_schedule_kind)
10300 21 : (OMP_CLAUSE_SCHEDULE_KIND (c)
10301 : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
10302 : }
10303 3853 : if (reduction_seen == -2)
10304 9 : error_at (OMP_CLAUSE_LOCATION (c),
10305 : "%qs clause specified together with %<inscan%> "
10306 : "%<reduction%> clause", "schedule");
10307 3853 : pc = &OMP_CLAUSE_CHAIN (c);
10308 3853 : continue;
10309 51 : case OMP_CLAUSE_NOGROUP:
10310 51 : if (reduction_seen)
10311 : {
10312 3 : error_at (OMP_CLAUSE_LOCATION (c),
10313 : "%<nogroup%> clause must not be used together with "
10314 : "%<reduction%> clause");
10315 3 : *pc = OMP_CLAUSE_CHAIN (c);
10316 3 : continue;
10317 : }
10318 48 : pc = &OMP_CLAUSE_CHAIN (c);
10319 48 : continue;
10320 165 : case OMP_CLAUSE_GRAINSIZE:
10321 165 : if (num_tasks_seen)
10322 : {
10323 6 : error_at (OMP_CLAUSE_LOCATION (c),
10324 : "%<grainsize%> clause must not be used together with "
10325 : "%<num_tasks%> clause");
10326 6 : *pc = OMP_CLAUSE_CHAIN (c);
10327 6 : continue;
10328 : }
10329 159 : pc = &OMP_CLAUSE_CHAIN (c);
10330 159 : continue;
10331 630 : case OMP_CLAUSE_ORDERED:
10332 630 : if (reduction_seen == -2)
10333 6 : error_at (OMP_CLAUSE_LOCATION (c),
10334 : "%qs clause specified together with %<inscan%> "
10335 : "%<reduction%> clause", "ordered");
10336 630 : pc = &OMP_CLAUSE_CHAIN (c);
10337 630 : continue;
10338 1525 : case OMP_CLAUSE_ORDER:
10339 1525 : if (ordered_seen)
10340 : {
10341 12 : error_at (OMP_CLAUSE_LOCATION (c),
10342 : "%<order%> clause must not be used together "
10343 : "with %<ordered%> clause");
10344 12 : *pc = OMP_CLAUSE_CHAIN (c);
10345 12 : continue;
10346 : }
10347 1513 : pc = &OMP_CLAUSE_CHAIN (c);
10348 1513 : continue;
10349 57 : case OMP_CLAUSE_DETACH:
10350 57 : if (mergeable_seen)
10351 : {
10352 6 : error_at (OMP_CLAUSE_LOCATION (c),
10353 : "%<detach%> clause must not be used together with "
10354 : "%<mergeable%> clause");
10355 6 : *pc = OMP_CLAUSE_CHAIN (c);
10356 6 : continue;
10357 : }
10358 51 : pc = &OMP_CLAUSE_CHAIN (c);
10359 51 : continue;
10360 15818 : case OMP_CLAUSE_MAP:
10361 15818 : if (target_in_reduction_seen && !processing_template_decl)
10362 : {
10363 684 : t = OMP_CLAUSE_DECL (c);
10364 684 : while (handled_component_p (t)
10365 : || INDIRECT_REF_P (t)
10366 : || TREE_CODE (t) == ADDR_EXPR
10367 : || TREE_CODE (t) == MEM_REF
10368 804 : || TREE_CODE (t) == NON_LVALUE_EXPR)
10369 120 : t = TREE_OPERAND (t, 0);
10370 684 : if (DECL_P (t)
10371 684 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
10372 342 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
10373 : }
10374 15818 : pc = &OMP_CLAUSE_CHAIN (c);
10375 15818 : continue;
10376 225 : case OMP_CLAUSE_FULL:
10377 225 : if (partial_seen)
10378 : {
10379 12 : error_at (OMP_CLAUSE_LOCATION (c),
10380 : "%<full%> clause must not be used together "
10381 : "with %<partial%> clause");
10382 12 : *pc = OMP_CLAUSE_CHAIN (c);
10383 12 : continue;
10384 : }
10385 213 : pc = &OMP_CLAUSE_CHAIN (c);
10386 213 : continue;
10387 6894 : case OMP_CLAUSE_NOWAIT:
10388 6894 : if (copyprivate_seen)
10389 : {
10390 6 : error_at (OMP_CLAUSE_LOCATION (c),
10391 : "%<nowait%> clause must not be used together "
10392 : "with %<copyprivate%> clause");
10393 6 : *pc = OMP_CLAUSE_CHAIN (c);
10394 6 : continue;
10395 : }
10396 : /* FALLTHRU */
10397 50324 : default:
10398 50324 : pc = &OMP_CLAUSE_CHAIN (c);
10399 50324 : continue;
10400 : }
10401 :
10402 22164 : t = OMP_CLAUSE_DECL (c);
10403 22164 : switch (c_kind)
10404 : {
10405 2763 : case OMP_CLAUSE_LASTPRIVATE:
10406 2763 : if (DECL_P (t)
10407 2763 : && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
10408 : {
10409 2666 : need_default_ctor = true;
10410 2666 : need_dtor = true;
10411 : }
10412 : break;
10413 :
10414 9425 : case OMP_CLAUSE_REDUCTION:
10415 9425 : case OMP_CLAUSE_IN_REDUCTION:
10416 9425 : case OMP_CLAUSE_TASK_REDUCTION:
10417 9425 : if (allocate_seen)
10418 : {
10419 1561 : if (TREE_CODE (t) == MEM_REF)
10420 : {
10421 162 : t = TREE_OPERAND (t, 0);
10422 162 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
10423 0 : t = TREE_OPERAND (t, 0);
10424 162 : if (TREE_CODE (t) == ADDR_EXPR
10425 120 : || INDIRECT_REF_P (t))
10426 80 : t = TREE_OPERAND (t, 0);
10427 162 : if (DECL_P (t))
10428 162 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10429 : }
10430 1399 : else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10431 : {
10432 192 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10433 96 : t = TREE_OPERAND (t, 0);
10434 96 : if (DECL_P (t))
10435 96 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10436 96 : t = OMP_CLAUSE_DECL (c);
10437 : }
10438 1303 : else if (DECL_P (t))
10439 1303 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10440 1561 : t = OMP_CLAUSE_DECL (c);
10441 : }
10442 9425 : if (processing_template_decl
10443 863 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10444 : break;
10445 8855 : if (finish_omp_reduction_clause (c, &need_default_ctor,
10446 : &need_dtor))
10447 : remove = true;
10448 : else
10449 8771 : t = OMP_CLAUSE_DECL (c);
10450 : break;
10451 :
10452 274 : case OMP_CLAUSE_COPYIN:
10453 274 : if (processing_template_decl
10454 0 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10455 : break;
10456 274 : if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
10457 : {
10458 15 : error_at (OMP_CLAUSE_LOCATION (c),
10459 : "%qE must be %<threadprivate%> for %<copyin%>", t);
10460 15 : remove = true;
10461 : }
10462 : break;
10463 :
10464 : default:
10465 : break;
10466 : }
10467 :
10468 22164 : if (processing_template_decl
10469 1544 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10470 : {
10471 632 : pc = &OMP_CLAUSE_CHAIN (c);
10472 632 : continue;
10473 : }
10474 :
10475 21532 : if (need_complete_type || need_copy_assignment)
10476 : {
10477 9190 : t = require_complete_type (t);
10478 9190 : if (t == error_mark_node)
10479 : remove = true;
10480 9166 : else if (!processing_template_decl
10481 8783 : && TYPE_REF_P (TREE_TYPE (t))
10482 9722 : && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
10483 : remove = true;
10484 : }
10485 21532 : if (need_implicitly_determined)
10486 : {
10487 20494 : const char *share_name = NULL;
10488 :
10489 20494 : if (allocate_seen
10490 4993 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10491 24608 : && DECL_P (t))
10492 3904 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10493 :
10494 20494 : if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
10495 : share_name = "threadprivate";
10496 20452 : else switch (cxx_omp_predetermined_sharing_1 (t))
10497 : {
10498 : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
10499 : break;
10500 47 : case OMP_CLAUSE_DEFAULT_SHARED:
10501 47 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10502 30 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
10503 64 : && c_omp_predefined_variable (t))
10504 : /* The __func__ variable and similar function-local predefined
10505 : variables may be listed in a shared or firstprivate
10506 : clause. */
10507 : break;
10508 31 : if (VAR_P (t)
10509 31 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10510 9 : && TREE_STATIC (t)
10511 40 : && cxx_omp_const_qual_no_mutable (t))
10512 : {
10513 6 : tree ctx = CP_DECL_CONTEXT (t);
10514 : /* const qualified static data members without mutable
10515 : member may be specified in firstprivate clause. */
10516 6 : if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
10517 : break;
10518 : }
10519 : share_name = "shared";
10520 : break;
10521 : case OMP_CLAUSE_DEFAULT_PRIVATE:
10522 : share_name = "private";
10523 : break;
10524 0 : default:
10525 0 : gcc_unreachable ();
10526 : }
10527 : if (share_name)
10528 : {
10529 67 : error_at (OMP_CLAUSE_LOCATION (c),
10530 : "%qE is predetermined %qs for %qs",
10531 : omp_clause_printable_decl (t), share_name,
10532 67 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10533 67 : remove = true;
10534 : }
10535 20427 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10536 18368 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
10537 35668 : && cxx_omp_const_qual_no_mutable (t))
10538 : {
10539 126 : error_at (OMP_CLAUSE_LOCATION (c),
10540 : "%<const%> qualified %qE without %<mutable%> member "
10541 : "may appear only in %<shared%> or %<firstprivate%> "
10542 : "clauses", omp_clause_printable_decl (t));
10543 63 : remove = true;
10544 : }
10545 : }
10546 :
10547 21532 : if (detach_seen
10548 16 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10549 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
10550 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10551 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
10552 21548 : && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
10553 : {
10554 6 : error_at (OMP_CLAUSE_LOCATION (c),
10555 : "the event handle of a %<detach%> clause "
10556 : "should not be in a data-sharing clause");
10557 6 : remove = true;
10558 : }
10559 :
10560 : /* We're interested in the base element, not arrays. */
10561 21532 : inner_type = type = TREE_TYPE (t);
10562 21532 : if ((need_complete_type
10563 : || need_copy_assignment
10564 12342 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
10565 5708 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
10566 4235 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
10567 29966 : && TYPE_REF_P (inner_type))
10568 878 : inner_type = TREE_TYPE (inner_type);
10569 24113 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
10570 2581 : inner_type = TREE_TYPE (inner_type);
10571 :
10572 : /* Check for special function availability by building a call to one.
10573 : Save the results, because later we won't be in the right context
10574 : for making these queries. */
10575 2387 : if (CLASS_TYPE_P (inner_type)
10576 2387 : && COMPLETE_TYPE_P (inner_type)
10577 2318 : && (need_default_ctor || need_copy_ctor
10578 1081 : || need_copy_assignment || need_dtor)
10579 1994 : && !type_dependent_expression_p (t)
10580 23526 : && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
10581 : need_copy_ctor, need_copy_assignment,
10582 : need_dtor))
10583 : remove = true;
10584 :
10585 21532 : if (!remove
10586 21532 : && c_kind == OMP_CLAUSE_SHARED
10587 2056 : && processing_template_decl)
10588 : {
10589 125 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10590 125 : if (t)
10591 5 : OMP_CLAUSE_DECL (c) = t;
10592 : }
10593 :
10594 21532 : if (remove)
10595 292 : *pc = OMP_CLAUSE_CHAIN (c);
10596 : else
10597 21240 : pc = &OMP_CLAUSE_CHAIN (c);
10598 : }
10599 :
10600 62562 : if (allocate_seen)
10601 16828 : for (pc = &clauses, c = clauses; c ; c = *pc)
10602 : {
10603 14544 : bool remove = false;
10604 14544 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
10605 2540 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
10606 2143 : && DECL_P (OMP_CLAUSE_DECL (c))
10607 16687 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
10608 : {
10609 15 : error_at (OMP_CLAUSE_LOCATION (c),
10610 : "%qD specified in %<allocate%> clause but not in "
10611 15 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
10612 15 : remove = true;
10613 : }
10614 14544 : if (remove)
10615 15 : *pc = OMP_CLAUSE_CHAIN (c);
10616 : else
10617 14529 : pc = &OMP_CLAUSE_CHAIN (c);
10618 : }
10619 :
10620 62562 : if (ort == C_ORT_OMP_INTEROP
10621 62562 : && depend_clause
10622 60 : && (!init_use_destroy_seen
10623 57 : || (init_seen && init_no_targetsync_clause)))
10624 : {
10625 9 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
10626 : "%<depend%> clause requires action clauses with "
10627 : "%<targetsync%> interop-type");
10628 9 : if (init_no_targetsync_clause)
10629 6 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
10630 : "%<init%> clause lacks the %<targetsync%> modifier");
10631 : }
10632 :
10633 62562 : bitmap_obstack_release (NULL);
10634 62562 : return clauses;
10635 : }
10636 :
10637 : /* Start processing OpenMP clauses that can include any
10638 : privatization clauses for non-static data members. */
10639 :
10640 : tree
10641 48423 : push_omp_privatization_clauses (bool ignore_next)
10642 : {
10643 48423 : if (omp_private_member_ignore_next)
10644 : {
10645 656 : omp_private_member_ignore_next = ignore_next;
10646 656 : return NULL_TREE;
10647 : }
10648 47767 : omp_private_member_ignore_next = ignore_next;
10649 47767 : if (omp_private_member_map)
10650 24 : omp_private_member_vec.safe_push (error_mark_node);
10651 47767 : return push_stmt_list ();
10652 : }
10653 :
10654 : /* Revert remapping of any non-static data members since
10655 : the last push_omp_privatization_clauses () call. */
10656 :
10657 : void
10658 48417 : pop_omp_privatization_clauses (tree stmt)
10659 : {
10660 48417 : if (stmt == NULL_TREE)
10661 : return;
10662 47761 : stmt = pop_stmt_list (stmt);
10663 47761 : if (omp_private_member_map)
10664 : {
10665 1280 : while (!omp_private_member_vec.is_empty ())
10666 : {
10667 850 : tree t = omp_private_member_vec.pop ();
10668 850 : if (t == error_mark_node)
10669 : {
10670 24 : add_stmt (stmt);
10671 24 : return;
10672 : }
10673 826 : bool no_decl_expr = t == integer_zero_node;
10674 826 : if (no_decl_expr)
10675 136 : t = omp_private_member_vec.pop ();
10676 826 : tree *v = omp_private_member_map->get (t);
10677 826 : gcc_assert (v);
10678 826 : if (!no_decl_expr)
10679 690 : add_decl_expr (*v);
10680 826 : omp_private_member_map->remove (t);
10681 : }
10682 860 : delete omp_private_member_map;
10683 430 : omp_private_member_map = NULL;
10684 : }
10685 47737 : add_stmt (stmt);
10686 : }
10687 :
10688 : /* Remember OpenMP privatization clauses mapping and clear it.
10689 : Used for lambdas. */
10690 :
10691 : void
10692 15281981 : save_omp_privatization_clauses (vec<tree> &save)
10693 : {
10694 15281981 : save = vNULL;
10695 15281981 : if (omp_private_member_ignore_next)
10696 2 : save.safe_push (integer_one_node);
10697 15281981 : omp_private_member_ignore_next = false;
10698 15281981 : if (!omp_private_member_map)
10699 : return;
10700 :
10701 0 : while (!omp_private_member_vec.is_empty ())
10702 : {
10703 0 : tree t = omp_private_member_vec.pop ();
10704 0 : if (t == error_mark_node)
10705 : {
10706 0 : save.safe_push (t);
10707 0 : continue;
10708 : }
10709 0 : tree n = t;
10710 0 : if (t == integer_zero_node)
10711 0 : t = omp_private_member_vec.pop ();
10712 0 : tree *v = omp_private_member_map->get (t);
10713 0 : gcc_assert (v);
10714 0 : save.safe_push (*v);
10715 0 : save.safe_push (t);
10716 0 : if (n != t)
10717 0 : save.safe_push (n);
10718 : }
10719 0 : delete omp_private_member_map;
10720 0 : omp_private_member_map = NULL;
10721 : }
10722 :
10723 : /* Restore OpenMP privatization clauses mapping saved by the
10724 : above function. */
10725 :
10726 : void
10727 15281981 : restore_omp_privatization_clauses (vec<tree> &save)
10728 : {
10729 15281981 : gcc_assert (omp_private_member_vec.is_empty ());
10730 15281981 : omp_private_member_ignore_next = false;
10731 15281981 : if (save.is_empty ())
10732 : return;
10733 4 : if (save.length () == 1 && save[0] == integer_one_node)
10734 : {
10735 2 : omp_private_member_ignore_next = true;
10736 2 : save.release ();
10737 2 : return;
10738 : }
10739 :
10740 0 : omp_private_member_map = new hash_map <tree, tree>;
10741 0 : while (!save.is_empty ())
10742 : {
10743 0 : tree t = save.pop ();
10744 0 : tree n = t;
10745 0 : if (t != error_mark_node)
10746 : {
10747 0 : if (t == integer_one_node)
10748 : {
10749 0 : omp_private_member_ignore_next = true;
10750 0 : gcc_assert (save.is_empty ());
10751 0 : break;
10752 : }
10753 0 : if (t == integer_zero_node)
10754 0 : t = save.pop ();
10755 0 : tree &v = omp_private_member_map->get_or_insert (t);
10756 0 : v = save.pop ();
10757 : }
10758 0 : omp_private_member_vec.safe_push (t);
10759 0 : if (n != t)
10760 0 : omp_private_member_vec.safe_push (n);
10761 : }
10762 0 : save.release ();
10763 : }
10764 :
10765 : /* For all variables in the tree_list VARS, mark them as thread local. */
10766 :
10767 : void
10768 238 : finish_omp_threadprivate (tree vars)
10769 : {
10770 238 : tree t;
10771 :
10772 : /* Mark every variable in VARS to be assigned thread local storage. */
10773 509 : for (t = vars; t; t = TREE_CHAIN (t))
10774 : {
10775 271 : tree v = TREE_PURPOSE (t);
10776 271 : location_t loc = EXPR_LOCATION (TREE_VALUE (t));
10777 :
10778 271 : if (error_operand_p (v))
10779 : ;
10780 271 : else if (!VAR_P (v))
10781 6 : error_at (loc, "%<threadprivate%> %qD is not file, namespace "
10782 : "or block scope variable", v);
10783 : /* If V had already been marked threadprivate, it doesn't matter
10784 : whether it had been used prior to this point. */
10785 265 : else if (TREE_USED (v)
10786 265 : && (DECL_LANG_SPECIFIC (v) == NULL
10787 3 : || !CP_DECL_THREADPRIVATE_P (v)))
10788 6 : error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10789 259 : else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10790 6 : error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10791 253 : else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
10792 3 : error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10793 201 : else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
10794 273 : && CP_DECL_CONTEXT (v) != current_class_type)
10795 6 : error_at (loc, "%<threadprivate%> %qE directive not "
10796 6 : "in %qT definition", v, CP_DECL_CONTEXT (v));
10797 : else
10798 : {
10799 : /* Allocate a LANG_SPECIFIC structure for V, if needed. */
10800 244 : if (DECL_LANG_SPECIFIC (v) == NULL)
10801 200 : retrofit_lang_decl (v);
10802 :
10803 244 : if (! CP_DECL_THREAD_LOCAL_P (v))
10804 : {
10805 244 : CP_DECL_THREAD_LOCAL_P (v) = true;
10806 244 : set_decl_tls_model (v, decl_default_tls_model (v));
10807 : /* If rtl has been already set for this var, call
10808 : make_decl_rtl once again, so that encode_section_info
10809 : has a chance to look at the new decl flags. */
10810 244 : if (DECL_RTL_SET_P (v))
10811 0 : make_decl_rtl (v);
10812 : }
10813 244 : CP_DECL_THREADPRIVATE_P (v) = 1;
10814 : }
10815 : }
10816 238 : }
10817 :
10818 : /* Build an OpenMP structured block. */
10819 :
10820 : tree
10821 63961 : begin_omp_structured_block (void)
10822 : {
10823 63961 : return do_pushlevel (sk_omp);
10824 : }
10825 :
10826 : tree
10827 63940 : finish_omp_structured_block (tree block)
10828 : {
10829 63940 : return do_poplevel (block);
10830 : }
10831 :
10832 : /* Similarly, except force the retention of the BLOCK. */
10833 :
10834 : tree
10835 14797 : begin_omp_parallel (void)
10836 : {
10837 14797 : keep_next_level (true);
10838 14797 : return begin_omp_structured_block ();
10839 : }
10840 :
10841 : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
10842 : statement. */
10843 :
10844 : tree
10845 768 : finish_oacc_data (tree clauses, tree block)
10846 : {
10847 768 : tree stmt;
10848 :
10849 768 : block = finish_omp_structured_block (block);
10850 :
10851 768 : stmt = make_node (OACC_DATA);
10852 768 : TREE_TYPE (stmt) = void_type_node;
10853 768 : OACC_DATA_CLAUSES (stmt) = clauses;
10854 768 : OACC_DATA_BODY (stmt) = block;
10855 :
10856 768 : return add_stmt (stmt);
10857 : }
10858 :
10859 : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
10860 : statement. */
10861 :
10862 : tree
10863 55 : finish_oacc_host_data (tree clauses, tree block)
10864 : {
10865 55 : tree stmt;
10866 :
10867 55 : block = finish_omp_structured_block (block);
10868 :
10869 55 : stmt = make_node (OACC_HOST_DATA);
10870 55 : TREE_TYPE (stmt) = void_type_node;
10871 55 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
10872 55 : OACC_HOST_DATA_BODY (stmt) = block;
10873 :
10874 55 : return add_stmt (stmt);
10875 : }
10876 :
10877 : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
10878 : statement. */
10879 :
10880 : tree
10881 4653 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
10882 : {
10883 4653 : body = finish_omp_structured_block (body);
10884 :
10885 4653 : tree stmt = make_node (code);
10886 4653 : TREE_TYPE (stmt) = void_type_node;
10887 4653 : OMP_BODY (stmt) = body;
10888 4653 : OMP_CLAUSES (stmt) = clauses;
10889 :
10890 4653 : return add_stmt (stmt);
10891 : }
10892 :
10893 : /* Used to walk OpenMP target directive body. */
10894 :
10895 : struct omp_target_walk_data
10896 : {
10897 : /* Holds the 'this' expression found in current function. */
10898 : tree current_object;
10899 :
10900 : /* True if the 'this' expression was accessed in the target body. */
10901 : bool this_expr_accessed;
10902 :
10903 : /* For non-static functions, record which pointer-typed members were
10904 : accessed, and the whole expression. */
10905 : hash_map<tree, tree> ptr_members_accessed;
10906 :
10907 : /* Record which lambda objects were accessed in target body. */
10908 : hash_set<tree> lambda_objects_accessed;
10909 :
10910 : /* For lambda functions, the __closure object expression of the current
10911 : function, and the set of captured variables accessed in target body. */
10912 : tree current_closure;
10913 : hash_set<tree> closure_vars_accessed;
10914 :
10915 : /* Local variables declared inside a BIND_EXPR, used to filter out such
10916 : variables when recording lambda_objects_accessed. */
10917 : hash_set<tree> local_decls;
10918 :
10919 : omp_mapper_list<tree> *mappers;
10920 : };
10921 :
10922 : /* Helper function of finish_omp_target_clauses, called via
10923 : cp_walk_tree_without_duplicates. Traverse body of OpenMP target
10924 : directive *TP, and fill out omp_target_walk_data passed in *PTR. */
10925 :
10926 : static tree
10927 226535 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
10928 : {
10929 226535 : tree t = *tp;
10930 226535 : struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
10931 226535 : tree current_object = data->current_object;
10932 226535 : tree current_closure = data->current_closure;
10933 226535 : omp_mapper_list<tree> *mlist = data->mappers;
10934 :
10935 : /* References inside of these expression codes shouldn't incur any
10936 : form of mapping, so return early. */
10937 226535 : if (TREE_CODE (t) == SIZEOF_EXPR
10938 226527 : || TREE_CODE (t) == ALIGNOF_EXPR)
10939 : {
10940 8 : *walk_subtrees = 0;
10941 8 : return NULL_TREE;
10942 : }
10943 :
10944 226527 : if (TREE_CODE (t) == OMP_CLAUSE)
10945 : return NULL_TREE;
10946 :
10947 213942 : if (!processing_template_decl)
10948 : {
10949 213942 : tree aggr_type = NULL_TREE;
10950 :
10951 213942 : if (TREE_CODE (t) == COMPONENT_REF
10952 213942 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
10953 2257 : aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
10954 211685 : else if ((TREE_CODE (t) == VAR_DECL
10955 : || TREE_CODE (t) == PARM_DECL
10956 : || TREE_CODE (t) == RESULT_DECL)
10957 16827 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
10958 1220 : aggr_type = TREE_TYPE (t);
10959 :
10960 3477 : if (aggr_type)
10961 : {
10962 3477 : tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
10963 3477 : if (mapper_fn)
10964 203 : mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
10965 : }
10966 : }
10967 :
10968 213942 : if (current_object)
10969 : {
10970 2564 : tree this_expr = TREE_OPERAND (current_object, 0);
10971 :
10972 2564 : if (operand_equal_p (t, this_expr))
10973 : {
10974 35 : data->this_expr_accessed = true;
10975 35 : *walk_subtrees = 0;
10976 35 : return NULL_TREE;
10977 : }
10978 :
10979 2529 : if (TREE_CODE (t) == COMPONENT_REF
10980 115 : && POINTER_TYPE_P (TREE_TYPE (t))
10981 36 : && operand_equal_p (TREE_OPERAND (t, 0), current_object)
10982 2563 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
10983 : {
10984 34 : data->this_expr_accessed = true;
10985 34 : tree fld = TREE_OPERAND (t, 1);
10986 34 : if (data->ptr_members_accessed.get (fld) == NULL)
10987 : {
10988 14 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
10989 4 : t = convert_from_reference (t);
10990 14 : data->ptr_members_accessed.put (fld, t);
10991 : }
10992 34 : *walk_subtrees = 0;
10993 34 : return NULL_TREE;
10994 : }
10995 : }
10996 :
10997 : /* When the current_function_decl is a lambda function, the closure object
10998 : argument's type seems to not yet have fields layed out, so a recording
10999 : of DECL_VALUE_EXPRs during the target body walk seems the only way to
11000 : find them. */
11001 213873 : if (current_closure
11002 300 : && (VAR_P (t)
11003 : || TREE_CODE (t) == PARM_DECL
11004 : || TREE_CODE (t) == RESULT_DECL)
11005 24 : && DECL_HAS_VALUE_EXPR_P (t)
11006 10 : && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
11007 213883 : && operand_equal_p (current_closure,
11008 10 : TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
11009 : {
11010 9 : if (!data->closure_vars_accessed.contains (t))
11011 9 : data->closure_vars_accessed.add (t);
11012 9 : *walk_subtrees = 0;
11013 9 : return NULL_TREE;
11014 : }
11015 :
11016 213864 : if (TREE_CODE (t) == BIND_EXPR)
11017 : {
11018 19914 : if (tree block = BIND_EXPR_BLOCK (t))
11019 22307 : for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
11020 2397 : if (!data->local_decls.contains (var))
11021 2397 : data->local_decls.add (var);
11022 19914 : return NULL_TREE;
11023 : }
11024 :
11025 198559 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
11026 : {
11027 39 : tree lt = TREE_TYPE (t);
11028 39 : gcc_assert (CLASS_TYPE_P (lt));
11029 :
11030 39 : if (!data->lambda_objects_accessed.contains (t)
11031 : /* Do not prepare to create target maps for locally declared
11032 : lambdas or anonymous ones. */
11033 39 : && !data->local_decls.contains (t)
11034 72 : && TREE_CODE (t) != TARGET_EXPR)
11035 13 : data->lambda_objects_accessed.add (t);
11036 39 : *walk_subtrees = 0;
11037 39 : return NULL_TREE;
11038 : }
11039 :
11040 : return NULL_TREE;
11041 : }
11042 :
11043 : /* Helper function for finish_omp_target, and also from tsubst_expr.
11044 : Create additional clauses for mapping of non-static members, lambda objects,
11045 : etc. */
11046 :
11047 : void
11048 6944 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
11049 : {
11050 6944 : omp_target_walk_data data;
11051 6944 : data.this_expr_accessed = false;
11052 6944 : data.current_object = NULL_TREE;
11053 :
11054 6944 : if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
11055 96 : if (tree ct = current_nonlambda_class_type ())
11056 : {
11057 95 : tree object = maybe_dummy_object (ct, NULL);
11058 95 : object = maybe_resolve_dummy (object, true);
11059 95 : data.current_object = object;
11060 : }
11061 :
11062 6944 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11063 : {
11064 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11065 8 : data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11066 : }
11067 : else
11068 6936 : data.current_closure = NULL_TREE;
11069 :
11070 6944 : auto_vec<tree, 16> new_clauses;
11071 :
11072 6944 : if (!processing_template_decl)
11073 : {
11074 6944 : hash_set<omp_name_type<tree> > seen_types;
11075 6944 : auto_vec<tree> mapper_fns;
11076 6944 : omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
11077 6944 : data.mappers = &mlist;
11078 :
11079 6944 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11080 : &data);
11081 :
11082 6944 : unsigned int i;
11083 6944 : tree mapper_fn;
11084 13983 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11085 95 : c_omp_find_nested_mappers (&mlist, mapper_fn);
11086 :
11087 7111 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11088 : {
11089 95 : tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
11090 95 : if (mapper == error_mark_node)
11091 0 : continue;
11092 95 : tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
11093 95 : tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
11094 95 : if (BASELINK_P (mapper_fn))
11095 0 : mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
11096 :
11097 95 : tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
11098 95 : OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
11099 95 : OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
11100 95 : OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
11101 :
11102 95 : new_clauses.safe_push (c);
11103 : }
11104 6944 : }
11105 : else
11106 : {
11107 0 : data.mappers = NULL;
11108 0 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11109 : &data);
11110 : }
11111 :
11112 6944 : tree omp_target_this_expr = NULL_TREE;
11113 6944 : tree *explicit_this_deref_map = NULL;
11114 6944 : if (data.this_expr_accessed)
11115 : {
11116 31 : omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
11117 :
11118 : /* See if explicit user-specified map(this[:]) clause already exists.
11119 : If not, we create an implicit map(tofrom:this[:1]) clause. */
11120 80 : for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
11121 50 : if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
11122 47 : && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
11123 40 : || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
11124 57 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
11125 : omp_target_this_expr))
11126 : {
11127 : explicit_this_deref_map = cp;
11128 : break;
11129 : }
11130 : }
11131 :
11132 6944 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11133 6944 : && (data.this_expr_accessed
11134 1 : || !data.closure_vars_accessed.is_empty ()))
11135 : {
11136 : /* For lambda functions, we need to first create a copy of the
11137 : __closure object. */
11138 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11139 8 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11140 8 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
11141 8 : OMP_CLAUSE_DECL (c)
11142 8 : = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11143 8 : OMP_CLAUSE_SIZE (c)
11144 8 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
11145 8 : new_clauses.safe_push (c);
11146 :
11147 8 : tree closure_obj = OMP_CLAUSE_DECL (c);
11148 8 : tree closure_type = TREE_TYPE (closure_obj);
11149 :
11150 16 : gcc_assert (LAMBDA_TYPE_P (closure_type)
11151 : && CLASS_TYPE_P (closure_type));
11152 :
11153 8 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11154 8 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
11155 8 : OMP_CLAUSE_DECL (c2) = closure;
11156 8 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11157 8 : new_clauses.safe_push (c2);
11158 : }
11159 :
11160 6944 : if (data.this_expr_accessed)
11161 : {
11162 : /* If the this-expr was accessed, create a map(*this) clause. */
11163 31 : enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11164 31 : if (explicit_this_deref_map)
11165 : {
11166 1 : tree this_map = *explicit_this_deref_map;
11167 1 : tree nc = OMP_CLAUSE_CHAIN (this_map);
11168 2 : gcc_assert (nc != NULL_TREE
11169 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11170 : && (OMP_CLAUSE_MAP_KIND (nc)
11171 : == GOMP_MAP_FIRSTPRIVATE_POINTER));
11172 1 : kind = OMP_CLAUSE_MAP_KIND (this_map);
11173 : /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
11174 : two-map sequence away from the chain. */
11175 1 : *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
11176 : }
11177 31 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11178 31 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11179 31 : OMP_CLAUSE_DECL (c)
11180 31 : = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
11181 31 : OMP_CLAUSE_SIZE (c)
11182 31 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
11183 31 : new_clauses.safe_push (c);
11184 :
11185 : /* If we're in a lambda function, the this-pointer will actually be
11186 : '__closure->this', a mapped member of __closure, hence always_pointer.
11187 : Otherwise it's a firstprivate pointer. */
11188 31 : enum gomp_map_kind ptr_kind
11189 31 : = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11190 31 : ? GOMP_MAP_ALWAYS_POINTER
11191 24 : : GOMP_MAP_FIRSTPRIVATE_POINTER);
11192 31 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11193 31 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11194 31 : OMP_CLAUSE_DECL (c) = omp_target_this_expr;
11195 31 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11196 31 : new_clauses.safe_push (c);
11197 : }
11198 :
11199 6944 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11200 : {
11201 8 : if (omp_target_this_expr)
11202 : {
11203 7 : STRIP_NOPS (omp_target_this_expr);
11204 7 : gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
11205 7 : omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
11206 : }
11207 :
11208 17 : for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
11209 34 : i != data.closure_vars_accessed.end (); ++i)
11210 : {
11211 9 : tree orig_decl = *i;
11212 9 : tree closure_expr = DECL_VALUE_EXPR (orig_decl);
11213 :
11214 9 : if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
11215 9 : || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
11216 : {
11217 : /* this-pointer is processed above, outside this loop. */
11218 3 : if (omp_target_this_expr
11219 3 : && operand_equal_p (closure_expr, omp_target_this_expr))
11220 0 : continue;
11221 :
11222 3 : bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
11223 3 : enum gomp_map_kind kind, ptr_kind, nc_kind;
11224 3 : tree size;
11225 :
11226 3 : if (ptr_p)
11227 : {
11228 : /* For pointers, default mapped as zero-length array
11229 : section. */
11230 2 : kind = GOMP_MAP_ALLOC;
11231 2 : nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
11232 2 : ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
11233 2 : size = size_zero_node;
11234 : }
11235 : else
11236 : {
11237 : /* For references, default mapped as appearing on map
11238 : clause. */
11239 1 : kind = GOMP_MAP_TOFROM;
11240 1 : nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
11241 1 : ptr_kind = GOMP_MAP_ALWAYS_POINTER;
11242 1 : size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
11243 : }
11244 :
11245 6 : for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
11246 3 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
11247 1 : && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
11248 1 : || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
11249 3 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
11250 : orig_decl))
11251 : {
11252 : /* If this was already specified by user as a map,
11253 : save the user specified map kind, delete the
11254 : "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
11255 : and insert our own sequence:
11256 : "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
11257 : */
11258 0 : tree nc = OMP_CLAUSE_CHAIN (*p);
11259 0 : gcc_assert (nc != NULL_TREE
11260 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11261 : && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
11262 : /* Update with user specified kind and size. */
11263 0 : kind = OMP_CLAUSE_MAP_KIND (*p);
11264 0 : size = OMP_CLAUSE_SIZE (*p);
11265 0 : *p = OMP_CLAUSE_CHAIN (nc);
11266 0 : break;
11267 : }
11268 :
11269 3 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11270 3 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11271 3 : OMP_CLAUSE_DECL (c)
11272 3 : = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
11273 3 : OMP_CLAUSE_SIZE (c) = size;
11274 3 : if (ptr_p)
11275 2 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11276 3 : new_clauses.safe_push (c);
11277 :
11278 3 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11279 3 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11280 3 : OMP_CLAUSE_DECL (c) = closure_expr;
11281 3 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11282 3 : new_clauses.safe_push (c);
11283 : }
11284 : }
11285 : }
11286 :
11287 6944 : if (!data.ptr_members_accessed.is_empty ())
11288 14 : for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
11289 56 : i != data.ptr_members_accessed.end (); ++i)
11290 : {
11291 : /* For each referenced member that is of pointer or reference-to-pointer
11292 : type, create the equivalent of map(alloc:this->ptr[:0]). */
11293 14 : tree field_decl = (*i).first;
11294 14 : tree ptr_member = (*i).second;
11295 :
11296 26 : for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
11297 : {
11298 16 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
11299 2 : continue;
11300 : /* If map(this->ptr[:N]) already exists, avoid creating another
11301 : such map. */
11302 14 : tree decl = OMP_CLAUSE_DECL (c);
11303 14 : if ((TREE_CODE (decl) == INDIRECT_REF
11304 10 : || TREE_CODE (decl) == MEM_REF)
11305 14 : && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
11306 4 : goto next_ptr_member;
11307 : }
11308 :
11309 10 : if (!cxx_mark_addressable (ptr_member))
11310 0 : gcc_unreachable ();
11311 :
11312 10 : if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
11313 : {
11314 : /* For reference to pointers, we need to map the referenced
11315 : pointer first for things to be correct. */
11316 4 : tree ptr_member_type = TREE_TYPE (ptr_member);
11317 :
11318 : /* Map pointer target as zero-length array section. */
11319 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11320 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11321 4 : OMP_CLAUSE_DECL (c)
11322 4 : = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
11323 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11324 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11325 :
11326 : /* Map pointer to zero-length array section. */
11327 4 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11328 4 : OMP_CLAUSE_SET_MAP_KIND
11329 : (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
11330 4 : OMP_CLAUSE_DECL (c2) = ptr_member;
11331 4 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11332 :
11333 : /* Attach reference-to-pointer field to pointer. */
11334 4 : tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11335 4 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
11336 4 : OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
11337 4 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
11338 :
11339 4 : new_clauses.safe_push (c);
11340 4 : new_clauses.safe_push (c2);
11341 4 : new_clauses.safe_push (c3);
11342 : }
11343 6 : else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
11344 : {
11345 : /* Map pointer target as zero-length array section. */
11346 6 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11347 6 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11348 6 : OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
11349 : RO_UNARY_STAR);
11350 6 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11351 6 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11352 :
11353 : /* Attach zero-length array section to pointer. */
11354 6 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11355 6 : OMP_CLAUSE_SET_MAP_KIND
11356 : (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11357 6 : OMP_CLAUSE_DECL (c2) = ptr_member;
11358 6 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11359 :
11360 6 : new_clauses.safe_push (c);
11361 6 : new_clauses.safe_push (c2);
11362 : }
11363 : else
11364 0 : gcc_unreachable ();
11365 :
11366 14 : next_ptr_member:
11367 14 : ;
11368 : }
11369 :
11370 6957 : for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
11371 6970 : i != data.lambda_objects_accessed.end (); ++i)
11372 : {
11373 13 : tree lobj = *i;
11374 13 : if (TREE_CODE (lobj) == TARGET_EXPR)
11375 0 : lobj = TARGET_EXPR_SLOT (lobj);
11376 :
11377 13 : tree lt = TREE_TYPE (lobj);
11378 26 : gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
11379 :
11380 13 : tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
11381 13 : OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
11382 13 : OMP_CLAUSE_DECL (lc) = lobj;
11383 13 : OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
11384 13 : new_clauses.safe_push (lc);
11385 :
11386 180 : for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
11387 : {
11388 167 : if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
11389 : {
11390 4 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11391 : lobj, fld, NULL_TREE);
11392 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11393 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11394 4 : OMP_CLAUSE_DECL (c)
11395 4 : = build_indirect_ref (loc, exp, RO_UNARY_STAR);
11396 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11397 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11398 4 : new_clauses.safe_push (c);
11399 :
11400 4 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11401 4 : OMP_CLAUSE_SET_MAP_KIND
11402 : (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11403 4 : OMP_CLAUSE_DECL (c) = exp;
11404 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11405 4 : new_clauses.safe_push (c);
11406 : }
11407 163 : else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
11408 : {
11409 0 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11410 : lobj, fld, NULL_TREE);
11411 0 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11412 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
11413 0 : OMP_CLAUSE_DECL (c)
11414 0 : = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
11415 0 : OMP_CLAUSE_SIZE (c)
11416 0 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
11417 0 : new_clauses.safe_push (c);
11418 :
11419 0 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11420 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
11421 0 : OMP_CLAUSE_DECL (c) = exp;
11422 0 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11423 0 : new_clauses.safe_push (c);
11424 : }
11425 : }
11426 : }
11427 :
11428 6944 : tree c = *clauses_ptr;
11429 14112 : for (int i = new_clauses.length () - 1; i >= 0; i--)
11430 : {
11431 224 : OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
11432 224 : c = new_clauses[i];
11433 : }
11434 6944 : *clauses_ptr = c;
11435 6944 : }
11436 :
11437 : /* Called from cp_parser_omp_target. Create additional implicit clauses for
11438 : OpenMP target directives, and do sanity checks. */
11439 :
11440 : tree
11441 6932 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
11442 : {
11443 6932 : if (!processing_template_decl)
11444 6119 : finish_omp_target_clauses (loc, body, &clauses);
11445 :
11446 6932 : tree stmt = make_node (OMP_TARGET);
11447 6932 : TREE_TYPE (stmt) = void_type_node;
11448 6932 : OMP_TARGET_CLAUSES (stmt) = clauses;
11449 6932 : OMP_TARGET_BODY (stmt) = body;
11450 6932 : OMP_TARGET_COMBINED (stmt) = combined_p;
11451 6932 : SET_EXPR_LOCATION (stmt, loc);
11452 :
11453 6932 : tree c = clauses;
11454 16542 : while (c)
11455 : {
11456 9610 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
11457 5534 : switch (OMP_CLAUSE_MAP_KIND (c))
11458 : {
11459 : case GOMP_MAP_TO:
11460 : case GOMP_MAP_ALWAYS_TO:
11461 : case GOMP_MAP_PRESENT_TO:
11462 : case GOMP_MAP_ALWAYS_PRESENT_TO:
11463 : case GOMP_MAP_FROM:
11464 : case GOMP_MAP_ALWAYS_FROM:
11465 : case GOMP_MAP_PRESENT_FROM:
11466 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
11467 : case GOMP_MAP_TOFROM:
11468 : case GOMP_MAP_ALWAYS_TOFROM:
11469 : case GOMP_MAP_PRESENT_TOFROM:
11470 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
11471 : case GOMP_MAP_ALLOC:
11472 : case GOMP_MAP_PRESENT_ALLOC:
11473 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
11474 : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
11475 : case GOMP_MAP_ALWAYS_POINTER:
11476 : case GOMP_MAP_ATTACH_DETACH:
11477 : case GOMP_MAP_ATTACH:
11478 : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
11479 : case GOMP_MAP_POINTER:
11480 : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
11481 : break;
11482 3 : default:
11483 3 : error_at (OMP_CLAUSE_LOCATION (c),
11484 : "%<#pragma omp target%> with map-type other "
11485 : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
11486 : "on %<map%> clause");
11487 3 : break;
11488 : }
11489 9610 : c = OMP_CLAUSE_CHAIN (c);
11490 : }
11491 6932 : return add_stmt (stmt);
11492 : }
11493 :
11494 : tree
11495 9321 : finish_omp_parallel (tree clauses, tree body)
11496 : {
11497 9321 : tree stmt;
11498 :
11499 9321 : body = finish_omp_structured_block (body);
11500 :
11501 9321 : stmt = make_node (OMP_PARALLEL);
11502 9321 : TREE_TYPE (stmt) = void_type_node;
11503 9321 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
11504 9321 : OMP_PARALLEL_BODY (stmt) = body;
11505 :
11506 9321 : return add_stmt (stmt);
11507 : }
11508 :
11509 : tree
11510 2161 : begin_omp_task (void)
11511 : {
11512 2161 : keep_next_level (true);
11513 2161 : return begin_omp_structured_block ();
11514 : }
11515 :
11516 : tree
11517 2161 : finish_omp_task (tree clauses, tree body)
11518 : {
11519 2161 : tree stmt;
11520 :
11521 2161 : body = finish_omp_structured_block (body);
11522 :
11523 2161 : stmt = make_node (OMP_TASK);
11524 2161 : TREE_TYPE (stmt) = void_type_node;
11525 2161 : OMP_TASK_CLAUSES (stmt) = clauses;
11526 2161 : OMP_TASK_BODY (stmt) = body;
11527 :
11528 2161 : return add_stmt (stmt);
11529 : }
11530 :
11531 : /* Helper function for finish_omp_for. Convert Ith random access iterator
11532 : into integral iterator. Return FALSE if successful. */
11533 :
11534 : static bool
11535 813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
11536 : tree declv, tree orig_declv, tree initv,
11537 : tree condv, tree incrv, tree *body,
11538 : tree *pre_body, tree &clauses,
11539 : int collapse, int ordered)
11540 : {
11541 813 : tree diff, iter_init, iter_incr = NULL, last;
11542 813 : tree incr_var = NULL, orig_pre_body, orig_body, c;
11543 813 : tree decl = TREE_VEC_ELT (declv, i);
11544 813 : tree init = TREE_VEC_ELT (initv, i);
11545 813 : tree cond = TREE_VEC_ELT (condv, i);
11546 813 : tree incr = TREE_VEC_ELT (incrv, i);
11547 813 : tree iter = decl;
11548 813 : location_t elocus = locus;
11549 :
11550 813 : if (init && EXPR_HAS_LOCATION (init))
11551 12 : elocus = EXPR_LOCATION (init);
11552 :
11553 813 : switch (TREE_CODE (cond))
11554 : {
11555 810 : case GT_EXPR:
11556 810 : case GE_EXPR:
11557 810 : case LT_EXPR:
11558 810 : case LE_EXPR:
11559 810 : case NE_EXPR:
11560 810 : if (TREE_OPERAND (cond, 1) == iter)
11561 42 : cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
11562 42 : TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
11563 810 : if (TREE_OPERAND (cond, 0) != iter)
11564 0 : cond = error_mark_node;
11565 : else
11566 : {
11567 810 : tree tem = build_x_binary_op (EXPR_LOCATION (cond),
11568 810 : TREE_CODE (cond),
11569 : iter, ERROR_MARK,
11570 810 : TREE_OPERAND (cond, 1), ERROR_MARK,
11571 : NULL_TREE, NULL, tf_warning_or_error);
11572 810 : if (error_operand_p (tem))
11573 : return true;
11574 : }
11575 : break;
11576 3 : default:
11577 3 : cond = error_mark_node;
11578 3 : break;
11579 : }
11580 810 : if (cond == error_mark_node)
11581 : {
11582 3 : error_at (elocus, "invalid controlling predicate");
11583 3 : return true;
11584 : }
11585 807 : diff = build_x_binary_op (elocus, MINUS_EXPR,
11586 807 : TREE_OPERAND (cond, 1), ERROR_MARK,
11587 : iter, ERROR_MARK,
11588 : NULL_TREE, NULL, tf_warning_or_error);
11589 807 : diff = cp_fully_fold (diff);
11590 807 : if (error_operand_p (diff))
11591 : return true;
11592 807 : if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
11593 : {
11594 0 : error_at (elocus, "difference between %qE and %qD does not have integer type",
11595 0 : TREE_OPERAND (cond, 1), iter);
11596 0 : return true;
11597 : }
11598 807 : if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
11599 807 : TREE_VEC_ELT (declv, i), NULL_TREE,
11600 : cond, cp_walk_subtrees))
11601 : return true;
11602 :
11603 762 : switch (TREE_CODE (incr))
11604 : {
11605 370 : case PREINCREMENT_EXPR:
11606 370 : case PREDECREMENT_EXPR:
11607 370 : case POSTINCREMENT_EXPR:
11608 370 : case POSTDECREMENT_EXPR:
11609 370 : if (TREE_OPERAND (incr, 0) != iter)
11610 : {
11611 0 : incr = error_mark_node;
11612 0 : break;
11613 : }
11614 370 : iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
11615 370 : TREE_CODE (incr), iter,
11616 : NULL_TREE, tf_warning_or_error);
11617 370 : if (error_operand_p (iter_incr))
11618 : return true;
11619 370 : else if (TREE_CODE (incr) == PREINCREMENT_EXPR
11620 219 : || TREE_CODE (incr) == POSTINCREMENT_EXPR)
11621 299 : incr = integer_one_node;
11622 : else
11623 71 : incr = integer_minus_one_node;
11624 : break;
11625 392 : case MODIFY_EXPR:
11626 392 : if (TREE_OPERAND (incr, 0) != iter)
11627 0 : incr = error_mark_node;
11628 392 : else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
11629 392 : || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
11630 : {
11631 392 : tree rhs = TREE_OPERAND (incr, 1);
11632 392 : if (TREE_OPERAND (rhs, 0) == iter)
11633 : {
11634 299 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
11635 : != INTEGER_TYPE)
11636 0 : incr = error_mark_node;
11637 : else
11638 : {
11639 299 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11640 299 : iter, TREE_CODE (rhs),
11641 299 : TREE_OPERAND (rhs, 1),
11642 : NULL_TREE,
11643 : tf_warning_or_error);
11644 299 : if (error_operand_p (iter_incr))
11645 : return true;
11646 299 : incr = TREE_OPERAND (rhs, 1);
11647 299 : incr = cp_convert (TREE_TYPE (diff), incr,
11648 : tf_warning_or_error);
11649 299 : if (TREE_CODE (rhs) == MINUS_EXPR)
11650 : {
11651 16 : incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
11652 16 : incr = fold_simple (incr);
11653 : }
11654 299 : if (TREE_CODE (incr) != INTEGER_CST
11655 299 : && (TREE_CODE (incr) != NOP_EXPR
11656 66 : || (TREE_CODE (TREE_OPERAND (incr, 0))
11657 : != INTEGER_CST)))
11658 : iter_incr = NULL;
11659 : }
11660 : }
11661 93 : else if (TREE_OPERAND (rhs, 1) == iter)
11662 : {
11663 93 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
11664 93 : || TREE_CODE (rhs) != PLUS_EXPR)
11665 0 : incr = error_mark_node;
11666 : else
11667 : {
11668 93 : iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
11669 : PLUS_EXPR,
11670 93 : TREE_OPERAND (rhs, 0),
11671 : ERROR_MARK, iter,
11672 : ERROR_MARK, NULL_TREE, NULL,
11673 : tf_warning_or_error);
11674 93 : if (error_operand_p (iter_incr))
11675 : return true;
11676 93 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11677 : iter, NOP_EXPR,
11678 : iter_incr, NULL_TREE,
11679 : tf_warning_or_error);
11680 93 : if (error_operand_p (iter_incr))
11681 : return true;
11682 93 : incr = TREE_OPERAND (rhs, 0);
11683 93 : iter_incr = NULL;
11684 : }
11685 : }
11686 : else
11687 0 : incr = error_mark_node;
11688 : }
11689 : else
11690 0 : incr = error_mark_node;
11691 : break;
11692 0 : default:
11693 0 : incr = error_mark_node;
11694 0 : break;
11695 : }
11696 :
11697 762 : if (incr == error_mark_node)
11698 : {
11699 0 : error_at (elocus, "invalid increment expression");
11700 0 : return true;
11701 : }
11702 :
11703 762 : incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
11704 762 : incr = cp_fully_fold (incr);
11705 762 : tree loop_iv_seen = NULL_TREE;
11706 1735 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11707 1093 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
11708 1093 : && OMP_CLAUSE_DECL (c) == iter)
11709 : {
11710 120 : if (code == OMP_TASKLOOP || code == OMP_LOOP)
11711 : {
11712 60 : loop_iv_seen = c;
11713 60 : OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
11714 : }
11715 : break;
11716 : }
11717 973 : else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
11718 113 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
11719 1007 : && OMP_CLAUSE_DECL (c) == iter)
11720 : {
11721 30 : loop_iv_seen = c;
11722 30 : if (code == OMP_TASKLOOP)
11723 25 : OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
11724 : }
11725 :
11726 762 : decl = create_temporary_var (TREE_TYPE (diff));
11727 762 : pushdecl (decl);
11728 762 : add_decl_expr (decl);
11729 762 : last = create_temporary_var (TREE_TYPE (diff));
11730 762 : pushdecl (last);
11731 762 : add_decl_expr (last);
11732 762 : if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
11733 10 : && (!ordered || (i < collapse && collapse > 1)))
11734 : {
11735 10 : incr_var = create_temporary_var (TREE_TYPE (diff));
11736 10 : pushdecl (incr_var);
11737 10 : add_decl_expr (incr_var);
11738 : }
11739 762 : gcc_assert (stmts_are_full_exprs_p ());
11740 762 : tree diffvar = NULL_TREE;
11741 762 : if (code == OMP_TASKLOOP)
11742 : {
11743 101 : if (!loop_iv_seen)
11744 : {
11745 38 : tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11746 38 : OMP_CLAUSE_DECL (ivc) = iter;
11747 38 : cxx_omp_finish_clause (ivc, NULL, false);
11748 38 : OMP_CLAUSE_CHAIN (ivc) = clauses;
11749 38 : clauses = ivc;
11750 : }
11751 101 : tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11752 101 : OMP_CLAUSE_DECL (lvc) = last;
11753 101 : OMP_CLAUSE_CHAIN (lvc) = clauses;
11754 101 : clauses = lvc;
11755 101 : diffvar = create_temporary_var (TREE_TYPE (diff));
11756 101 : pushdecl (diffvar);
11757 101 : add_decl_expr (diffvar);
11758 : }
11759 661 : else if (code == OMP_LOOP)
11760 : {
11761 43 : if (!loop_iv_seen)
11762 : {
11763 : /* While iterators on the loop construct are predetermined
11764 : lastprivate, if the decl is not declared inside of the
11765 : loop, OMP_CLAUSE_LASTPRIVATE should have been added
11766 : already. */
11767 16 : loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11768 16 : OMP_CLAUSE_DECL (loop_iv_seen) = iter;
11769 16 : OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
11770 16 : clauses = loop_iv_seen;
11771 : }
11772 27 : else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
11773 : {
11774 5 : OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
11775 5 : OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
11776 5 : OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
11777 : }
11778 43 : if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
11779 21 : cxx_omp_finish_clause (loop_iv_seen, NULL, false);
11780 : }
11781 :
11782 762 : orig_pre_body = *pre_body;
11783 762 : *pre_body = push_stmt_list ();
11784 762 : if (orig_pre_body)
11785 610 : add_stmt (orig_pre_body);
11786 762 : if (init != NULL)
11787 61 : finish_expr_stmt (build_x_modify_expr (elocus,
11788 : iter, NOP_EXPR, init,
11789 : NULL_TREE, tf_warning_or_error));
11790 762 : init = build_int_cst (TREE_TYPE (diff), 0);
11791 762 : if (c && iter_incr == NULL
11792 28 : && (!ordered || (i < collapse && collapse > 1)))
11793 : {
11794 28 : if (incr_var)
11795 : {
11796 10 : finish_expr_stmt (build_x_modify_expr (elocus,
11797 : incr_var, NOP_EXPR,
11798 : incr, NULL_TREE,
11799 : tf_warning_or_error));
11800 10 : incr = incr_var;
11801 : }
11802 28 : iter_incr = build_x_modify_expr (elocus,
11803 : iter, PLUS_EXPR, incr,
11804 : NULL_TREE, tf_warning_or_error);
11805 : }
11806 762 : if (c && ordered && i < collapse && collapse > 1)
11807 762 : iter_incr = incr;
11808 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11809 : last, NOP_EXPR, init,
11810 : NULL_TREE, tf_warning_or_error));
11811 762 : if (diffvar)
11812 : {
11813 101 : finish_expr_stmt (build_x_modify_expr (elocus,
11814 : diffvar, NOP_EXPR,
11815 : diff, NULL_TREE, tf_warning_or_error));
11816 101 : diff = diffvar;
11817 : }
11818 762 : *pre_body = pop_stmt_list (*pre_body);
11819 :
11820 1524 : cond = cp_build_binary_op (elocus,
11821 762 : TREE_CODE (cond), decl, diff,
11822 : tf_warning_or_error);
11823 762 : incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
11824 : elocus, incr, NULL_TREE);
11825 :
11826 762 : orig_body = *body;
11827 762 : *body = push_stmt_list ();
11828 762 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
11829 762 : iter_init = build_x_modify_expr (elocus,
11830 : iter, PLUS_EXPR, iter_init,
11831 : NULL_TREE, tf_warning_or_error);
11832 762 : if (iter_init != error_mark_node)
11833 759 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11834 762 : finish_expr_stmt (iter_init);
11835 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11836 : last, NOP_EXPR, decl,
11837 : NULL_TREE, tf_warning_or_error));
11838 762 : add_stmt (orig_body);
11839 762 : *body = pop_stmt_list (*body);
11840 :
11841 762 : if (c)
11842 : {
11843 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
11844 120 : if (!ordered)
11845 114 : finish_expr_stmt (iter_incr);
11846 : else
11847 : {
11848 6 : iter_init = decl;
11849 6 : if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
11850 2 : iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
11851 : iter_init, iter_incr);
11852 6 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
11853 6 : iter_init = build_x_modify_expr (elocus,
11854 : iter, PLUS_EXPR, iter_init,
11855 : NULL_TREE, tf_warning_or_error);
11856 6 : if (iter_init != error_mark_node)
11857 6 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11858 6 : finish_expr_stmt (iter_init);
11859 : }
11860 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c)
11861 240 : = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
11862 : }
11863 :
11864 762 : if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
11865 : {
11866 116 : tree t = TREE_VEC_ELT (orig_declv, i);
11867 116 : gcc_assert (TREE_PURPOSE (t) == NULL_TREE
11868 : && TREE_VALUE (t) == NULL_TREE
11869 : && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
11870 116 : TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
11871 116 : TREE_VALUE (t) = last;
11872 : }
11873 : else
11874 646 : TREE_VEC_ELT (orig_declv, i)
11875 1292 : = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
11876 762 : TREE_VEC_ELT (declv, i) = decl;
11877 762 : TREE_VEC_ELT (initv, i) = init;
11878 762 : TREE_VEC_ELT (condv, i) = cond;
11879 762 : TREE_VEC_ELT (incrv, i) = incr;
11880 :
11881 762 : return false;
11882 : }
11883 :
11884 : /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
11885 : are directly for their associated operands in the statement. DECL
11886 : and INIT are a combo; if DECL is NULL then INIT ought to be a
11887 : MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
11888 : optional statements that need to go before the loop into its
11889 : sk_omp scope. */
11890 :
11891 : tree
11892 21128 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
11893 : tree orig_declv, tree initv, tree condv, tree incrv,
11894 : tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
11895 : {
11896 21128 : tree omp_for = NULL, orig_incr = NULL;
11897 21128 : tree decl = NULL, init, cond, incr;
11898 21128 : location_t elocus;
11899 21128 : int i;
11900 21128 : int collapse = 1;
11901 21128 : int ordered = 0;
11902 21128 : auto_vec<location_t> init_locv;
11903 :
11904 21128 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
11905 21128 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
11906 21128 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
11907 21128 : if (TREE_VEC_LENGTH (declv) > 1)
11908 : {
11909 4054 : if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
11910 83 : collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
11911 : else
11912 : {
11913 3971 : if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
11914 3501 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
11915 470 : else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
11916 394 : collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
11917 3971 : if (collapse != TREE_VEC_LENGTH (declv))
11918 100 : ordered = TREE_VEC_LENGTH (declv);
11919 : }
11920 : }
11921 48601 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
11922 : {
11923 27509 : decl = TREE_VEC_ELT (declv, i);
11924 27509 : init = TREE_VEC_ELT (initv, i);
11925 27509 : cond = TREE_VEC_ELT (condv, i);
11926 27509 : incr = TREE_VEC_ELT (incrv, i);
11927 27509 : elocus = locus;
11928 :
11929 27509 : if (decl == global_namespace)
11930 : {
11931 1101 : gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
11932 1101 : TREE_VEC_ELT (declv, i) = NULL_TREE;
11933 1101 : init_locv.safe_push (UNKNOWN_LOCATION);
11934 1101 : continue;
11935 : }
11936 : /* We are going to throw out the init's original MODIFY_EXPR or
11937 : MODOP_EXPR below. Save its location so we can use it when
11938 : reconstructing the expression farther down. Alternatively, if the
11939 : initializer is a binding of the iteration variable, save
11940 : that location. Any of these locations in the initialization clause
11941 : for the current nested loop are better than using the argument locus,
11942 : that points to the "for" of the outermost loop in the nest. */
11943 26408 : if (init && EXPR_HAS_LOCATION (init))
11944 17872 : elocus = EXPR_LOCATION (init);
11945 8536 : else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
11946 : /* This can happen for class iterators. */
11947 0 : elocus = EXPR_LOCATION (decl);
11948 8536 : else if (decl && DECL_P (decl))
11949 : {
11950 8509 : if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
11951 8509 : elocus = DECL_SOURCE_LOCATION (decl);
11952 0 : else if (DECL_INITIAL (decl)
11953 0 : && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
11954 0 : elocus = EXPR_LOCATION (DECL_INITIAL (decl));
11955 : }
11956 26408 : init_locv.safe_push (elocus);
11957 :
11958 26408 : if (decl == NULL)
11959 : {
11960 16564 : if (init != NULL)
11961 16561 : switch (TREE_CODE (init))
11962 : {
11963 16176 : case MODIFY_EXPR:
11964 16176 : decl = TREE_OPERAND (init, 0);
11965 16176 : init = TREE_OPERAND (init, 1);
11966 16176 : break;
11967 367 : case MODOP_EXPR:
11968 367 : if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
11969 : {
11970 367 : decl = TREE_OPERAND (init, 0);
11971 367 : init = TREE_OPERAND (init, 2);
11972 : }
11973 : break;
11974 : default:
11975 : break;
11976 : }
11977 :
11978 16564 : if (decl == NULL)
11979 : {
11980 21 : error_at (locus,
11981 : "expected iteration declaration or initialization");
11982 21 : return NULL;
11983 : }
11984 : }
11985 :
11986 26387 : if (cond == global_namespace)
11987 170 : continue;
11988 :
11989 26217 : if (cond == NULL)
11990 : {
11991 9 : error_at (elocus, "missing controlling predicate");
11992 9 : return NULL;
11993 : }
11994 :
11995 26208 : if (incr == NULL)
11996 : {
11997 6 : error_at (elocus, "missing increment expression");
11998 6 : return NULL;
11999 : }
12000 :
12001 26202 : TREE_VEC_ELT (declv, i) = decl;
12002 26202 : TREE_VEC_ELT (initv, i) = init;
12003 : }
12004 :
12005 21092 : if (orig_inits)
12006 : {
12007 : bool fail = false;
12008 : tree orig_init;
12009 21214 : FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
12010 1181 : if (orig_init
12011 3396 : && !c_omp_check_loop_iv_exprs (locus, code,
12012 : orig_declv ? orig_declv : declv, i,
12013 1164 : TREE_VEC_ELT (declv, i), orig_init,
12014 : NULL_TREE, cp_walk_subtrees))
12015 : fail = true;
12016 20033 : if (fail)
12017 887 : return NULL;
12018 : }
12019 :
12020 21035 : if (dependent_omp_for_p (declv, initv, condv, incrv, body))
12021 : {
12022 453 : tree stmt;
12023 :
12024 453 : stmt = make_node (code);
12025 :
12026 1499 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
12027 : {
12028 593 : if (TREE_VEC_ELT (declv, i) == NULL_TREE)
12029 9 : continue;
12030 : /* This is really just a place-holder. We'll be decomposing this
12031 : again and going through the cp_build_modify_expr path below when
12032 : we instantiate the thing. */
12033 584 : TREE_VEC_ELT (initv, i)
12034 1168 : = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
12035 584 : TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
12036 : }
12037 :
12038 453 : TREE_TYPE (stmt) = void_type_node;
12039 453 : OMP_FOR_INIT (stmt) = initv;
12040 453 : OMP_FOR_COND (stmt) = condv;
12041 453 : OMP_FOR_INCR (stmt) = incrv;
12042 453 : OMP_FOR_BODY (stmt) = body;
12043 453 : OMP_FOR_PRE_BODY (stmt) = pre_body;
12044 453 : OMP_FOR_CLAUSES (stmt) = clauses;
12045 :
12046 453 : SET_EXPR_LOCATION (stmt, locus);
12047 453 : return add_stmt (stmt);
12048 : }
12049 :
12050 20582 : if (!orig_declv)
12051 19795 : orig_declv = copy_node (declv);
12052 :
12053 20582 : if (processing_template_decl)
12054 612 : orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
12055 :
12056 48030 : for (i = 0; i < TREE_VEC_LENGTH (declv); )
12057 : {
12058 27540 : decl = TREE_VEC_ELT (declv, i);
12059 27540 : init = TREE_VEC_ELT (initv, i);
12060 27540 : cond = TREE_VEC_ELT (condv, i);
12061 27540 : incr = TREE_VEC_ELT (incrv, i);
12062 27540 : if (orig_incr)
12063 844 : TREE_VEC_ELT (orig_incr, i) = incr;
12064 27540 : elocus = init_locv[i];
12065 :
12066 27540 : if (decl == NULL_TREE)
12067 : {
12068 1092 : i++;
12069 1092 : continue;
12070 : }
12071 :
12072 26448 : if (!DECL_P (decl))
12073 : {
12074 6 : error_at (elocus, "expected iteration declaration or initialization");
12075 6 : return NULL;
12076 : }
12077 :
12078 26442 : if (incr && TREE_CODE (incr) == MODOP_EXPR)
12079 : {
12080 1 : if (orig_incr)
12081 1 : TREE_VEC_ELT (orig_incr, i) = incr;
12082 1 : incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
12083 1 : TREE_CODE (TREE_OPERAND (incr, 1)),
12084 1 : TREE_OPERAND (incr, 2),
12085 : tf_warning_or_error);
12086 : }
12087 :
12088 26442 : if (CLASS_TYPE_P (TREE_TYPE (decl)))
12089 : {
12090 825 : if (code == OMP_SIMD)
12091 : {
12092 12 : error_at (elocus, "%<#pragma omp simd%> used with class "
12093 : "iteration variable %qE", decl);
12094 12 : return NULL;
12095 : }
12096 813 : if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
12097 : initv, condv, incrv, &body,
12098 : &pre_body, clauses,
12099 : collapse, ordered))
12100 : return NULL;
12101 762 : continue;
12102 : }
12103 :
12104 51234 : if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
12105 27203 : && !TYPE_PTR_P (TREE_TYPE (decl)))
12106 : {
12107 14 : error_at (elocus, "invalid type for iteration variable %qE", decl);
12108 14 : return NULL;
12109 : }
12110 :
12111 25603 : if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
12112 24842 : init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
12113 : tf_warning_or_error);
12114 : else
12115 761 : init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
12116 25603 : if (decl == error_mark_node || init == error_mark_node)
12117 : return NULL;
12118 :
12119 25594 : TREE_VEC_ELT (declv, i) = decl;
12120 25594 : TREE_VEC_ELT (initv, i) = init;
12121 25594 : TREE_VEC_ELT (condv, i) = cond;
12122 25594 : TREE_VEC_ELT (incrv, i) = incr;
12123 25594 : i++;
12124 : }
12125 :
12126 20490 : if (pre_body && IS_EMPTY_STMT (pre_body))
12127 0 : pre_body = NULL;
12128 :
12129 40980 : omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
12130 : incrv, body, pre_body,
12131 20490 : !processing_template_decl);
12132 :
12133 : /* Check for iterators appearing in lb, b or incr expressions. */
12134 20490 : if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
12135 : omp_for = NULL_TREE;
12136 :
12137 20004 : if (omp_for == NULL)
12138 702 : return NULL;
12139 :
12140 19788 : add_stmt (omp_for);
12141 :
12142 45448 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
12143 : {
12144 25660 : init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
12145 25660 : if (init == NULL_TREE)
12146 1032 : continue;
12147 24628 : decl = TREE_OPERAND (init, 0);
12148 24628 : cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
12149 24628 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
12150 :
12151 24628 : if (!processing_template_decl)
12152 : {
12153 24107 : if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
12154 : {
12155 106 : tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
12156 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
12157 106 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12158 106 : t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
12159 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
12160 212 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12161 : }
12162 : else
12163 : {
12164 24001 : tree t = TREE_OPERAND (init, 1);
12165 24001 : TREE_OPERAND (init, 1)
12166 48002 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12167 : }
12168 24107 : if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
12169 : {
12170 121 : tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
12171 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
12172 121 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12173 121 : t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
12174 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
12175 242 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12176 : }
12177 : else
12178 : {
12179 23986 : tree t = TREE_OPERAND (cond, 1);
12180 23986 : TREE_OPERAND (cond, 1)
12181 47972 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12182 : }
12183 : }
12184 :
12185 24628 : if (TREE_CODE (incr) != MODIFY_EXPR)
12186 18426 : continue;
12187 :
12188 6202 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
12189 70 : && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
12190 6272 : && !processing_template_decl)
12191 : {
12192 64 : tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
12193 64 : if (TREE_SIDE_EFFECTS (t)
12194 8 : && t != decl
12195 70 : && (TREE_CODE (t) != NOP_EXPR
12196 0 : || TREE_OPERAND (t, 0) != decl))
12197 6 : TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
12198 12 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12199 :
12200 64 : t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
12201 64 : if (TREE_SIDE_EFFECTS (t)
12202 56 : && t != decl
12203 120 : && (TREE_CODE (t) != NOP_EXPR
12204 5 : || TREE_OPERAND (t, 0) != decl))
12205 56 : TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
12206 112 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12207 : }
12208 :
12209 6202 : if (orig_incr)
12210 177 : TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
12211 : }
12212 19788 : OMP_FOR_CLAUSES (omp_for) = clauses;
12213 :
12214 : /* For simd loops with non-static data member iterators, we could have added
12215 : OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
12216 : step at this point, fill it in. */
12217 4735 : if (code == OMP_SIMD && !processing_template_decl
12218 24479 : && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
12219 4619 : for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
12220 561 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
12221 561 : if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
12222 : {
12223 4 : decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
12224 4 : gcc_assert (decl == OMP_CLAUSE_DECL (c));
12225 4 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
12226 4 : tree step, stept;
12227 4 : switch (TREE_CODE (incr))
12228 : {
12229 0 : case PREINCREMENT_EXPR:
12230 0 : case POSTINCREMENT_EXPR:
12231 : /* c_omp_for_incr_canonicalize_ptr() should have been
12232 : called to massage things appropriately. */
12233 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12234 0 : OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
12235 0 : break;
12236 0 : case PREDECREMENT_EXPR:
12237 0 : case POSTDECREMENT_EXPR:
12238 : /* c_omp_for_incr_canonicalize_ptr() should have been
12239 : called to massage things appropriately. */
12240 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12241 0 : OMP_CLAUSE_LINEAR_STEP (c)
12242 0 : = build_int_cst (TREE_TYPE (decl), -1);
12243 0 : break;
12244 4 : case MODIFY_EXPR:
12245 4 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12246 4 : incr = TREE_OPERAND (incr, 1);
12247 4 : switch (TREE_CODE (incr))
12248 : {
12249 4 : case PLUS_EXPR:
12250 4 : if (TREE_OPERAND (incr, 1) == decl)
12251 0 : step = TREE_OPERAND (incr, 0);
12252 : else
12253 4 : step = TREE_OPERAND (incr, 1);
12254 : break;
12255 0 : case MINUS_EXPR:
12256 0 : case POINTER_PLUS_EXPR:
12257 0 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12258 0 : step = TREE_OPERAND (incr, 1);
12259 0 : break;
12260 0 : default:
12261 0 : gcc_unreachable ();
12262 : }
12263 4 : stept = TREE_TYPE (decl);
12264 4 : if (INDIRECT_TYPE_P (stept))
12265 0 : stept = sizetype;
12266 4 : step = fold_convert (stept, step);
12267 4 : if (TREE_CODE (incr) == MINUS_EXPR)
12268 0 : step = fold_build1 (NEGATE_EXPR, stept, step);
12269 4 : OMP_CLAUSE_LINEAR_STEP (c) = step;
12270 4 : break;
12271 0 : default:
12272 0 : gcc_unreachable ();
12273 : }
12274 : }
12275 : /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
12276 : clauses, we need copy ctor for those rather than default ctor,
12277 : plus as for other lastprivates assignment op and dtor. */
12278 19788 : if (code == OMP_LOOP && !processing_template_decl)
12279 1993 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12280 1285 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
12281 204 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
12282 1307 : && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
12283 : false, true, true, true))
12284 0 : CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
12285 :
12286 : return omp_for;
12287 21128 : }
12288 :
12289 : /* Code walker for finish_omp_for_block: extract binding of DP->var
12290 : from its current block and move it to a new BIND_EXPR DP->b
12291 : surrounding the body of DP->omp_for. */
12292 :
12293 : struct fofb_data {
12294 : tree var;
12295 : tree b;
12296 : tree omp_for;
12297 : };
12298 :
12299 : static tree
12300 389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
12301 : {
12302 389 : struct fofb_data *fofb = (struct fofb_data *)dp;
12303 389 : if (TREE_CODE (*tp) == BIND_EXPR)
12304 578 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
12305 : {
12306 576 : if (*p == fofb->var)
12307 : {
12308 363 : *p = DECL_CHAIN (*p);
12309 363 : if (fofb->b == NULL_TREE)
12310 : {
12311 214 : fofb->b = make_node (BLOCK);
12312 214 : fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
12313 214 : OMP_FOR_BODY (fofb->omp_for), fofb->b);
12314 214 : TREE_SIDE_EFFECTS (fofb->b) = 1;
12315 214 : OMP_FOR_BODY (fofb->omp_for) = fofb->b;
12316 : }
12317 363 : DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
12318 363 : BIND_EXPR_VARS (fofb->b) = fofb->var;
12319 363 : BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
12320 363 : BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
12321 363 : return *tp;
12322 : }
12323 : }
12324 26 : if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
12325 22 : *walk_subtrees = false;
12326 : return NULL_TREE;
12327 : }
12328 :
12329 : /* Fix up range for decls. Those decls were pushed into BIND's
12330 : BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
12331 : and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
12332 : so that processing of combined loop directives can find them. */
12333 : tree
12334 14525 : finish_omp_for_block (tree bind, tree omp_for)
12335 : {
12336 14525 : if (omp_for == NULL_TREE
12337 14478 : || !OMP_FOR_ORIG_DECLS (omp_for)
12338 28435 : || bind == NULL_TREE)
12339 615 : return bind;
12340 13910 : struct fofb_data fofb;
12341 13910 : fofb.b = NULL_TREE;
12342 13910 : fofb.omp_for = omp_for;
12343 33347 : for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
12344 19437 : if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
12345 19215 : && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
12346 : == TREE_LIST)
12347 20268 : && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
12348 : {
12349 237 : tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
12350 602 : for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
12351 : {
12352 365 : fofb.var = TREE_VEC_ELT (v, j);
12353 365 : cp_walk_tree (&bind, finish_omp_for_block_walker,
12354 : (void *)&fofb, NULL);
12355 : }
12356 : }
12357 13910 : return bind;
12358 : }
12359 :
12360 : void
12361 3342 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
12362 : tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
12363 : tree clauses, enum omp_memory_order mo, bool weak)
12364 : {
12365 3342 : tree orig_lhs;
12366 3342 : tree orig_rhs;
12367 3342 : tree orig_v;
12368 3342 : tree orig_lhs1;
12369 3342 : tree orig_rhs1;
12370 3342 : tree orig_r;
12371 3342 : bool dependent_p;
12372 3342 : tree stmt;
12373 :
12374 3342 : orig_lhs = lhs;
12375 3342 : orig_rhs = rhs;
12376 3342 : orig_v = v;
12377 3342 : orig_lhs1 = lhs1;
12378 3342 : orig_rhs1 = rhs1;
12379 3342 : orig_r = r;
12380 3342 : dependent_p = false;
12381 3342 : stmt = NULL_TREE;
12382 :
12383 : /* Even in a template, we can detect invalid uses of the atomic
12384 : pragma if neither LHS nor RHS is type-dependent. */
12385 3342 : if (processing_template_decl)
12386 : {
12387 600 : dependent_p = (type_dependent_expression_p (lhs)
12388 237 : || (rhs && type_dependent_expression_p (rhs))
12389 234 : || (v && type_dependent_expression_p (v))
12390 234 : || (lhs1 && type_dependent_expression_p (lhs1))
12391 234 : || (rhs1 && type_dependent_expression_p (rhs1))
12392 834 : || (r
12393 25 : && r != void_list_node
12394 16 : && type_dependent_expression_p (r)));
12395 600 : if (clauses)
12396 : {
12397 30 : gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
12398 : && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
12399 : && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
12400 30 : if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
12401 30 : || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
12402 : dependent_p = true;
12403 : }
12404 : }
12405 576 : if (!dependent_p)
12406 : {
12407 2958 : bool swapped = false;
12408 2958 : if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
12409 : {
12410 143 : std::swap (rhs, rhs1);
12411 143 : swapped = !commutative_tree_code (opcode);
12412 : }
12413 2958 : if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
12414 : {
12415 0 : if (code == OMP_ATOMIC)
12416 0 : error ("%<#pragma omp atomic update%> uses two different "
12417 : "expressions for memory");
12418 : else
12419 0 : error ("%<#pragma omp atomic capture%> uses two different "
12420 : "expressions for memory");
12421 0 : return;
12422 : }
12423 2958 : if (lhs1 && !cp_tree_equal (lhs, lhs1))
12424 : {
12425 0 : if (code == OMP_ATOMIC)
12426 0 : error ("%<#pragma omp atomic update%> uses two different "
12427 : "expressions for memory");
12428 : else
12429 0 : error ("%<#pragma omp atomic capture%> uses two different "
12430 : "expressions for memory");
12431 0 : return;
12432 : }
12433 5916 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
12434 : v, lhs1, rhs1, r, swapped, mo, weak,
12435 2958 : processing_template_decl != 0);
12436 2958 : if (stmt == error_mark_node)
12437 : return;
12438 : }
12439 3312 : if (processing_template_decl)
12440 : {
12441 591 : if (code == OMP_ATOMIC_READ)
12442 : {
12443 167 : stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
12444 167 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12445 167 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12446 : }
12447 : else
12448 : {
12449 424 : if (opcode == NOP_EXPR)
12450 35 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
12451 389 : else if (opcode == COND_EXPR)
12452 : {
12453 124 : stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
12454 124 : if (orig_r)
12455 50 : stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
12456 : stmt);
12457 124 : stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
12458 : orig_lhs);
12459 124 : orig_rhs1 = NULL_TREE;
12460 : }
12461 : else
12462 265 : stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
12463 424 : if (orig_rhs1)
12464 182 : stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
12465 : COMPOUND_EXPR, orig_rhs1, stmt);
12466 424 : if (code != OMP_ATOMIC)
12467 : {
12468 233 : stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
12469 233 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12470 233 : OMP_ATOMIC_WEAK (stmt) = weak;
12471 233 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12472 : }
12473 : }
12474 591 : stmt = build2 (OMP_ATOMIC, void_type_node,
12475 : clauses ? clauses : integer_zero_node, stmt);
12476 591 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12477 591 : OMP_ATOMIC_WEAK (stmt) = weak;
12478 591 : SET_EXPR_LOCATION (stmt, loc);
12479 : }
12480 :
12481 : /* Avoid -Wunused-value warnings here, the whole construct has side-effects
12482 : and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
12483 : in some tree that appears to be unused, the value is not unused. */
12484 3312 : warning_sentinel w (warn_unused_value);
12485 3312 : finish_expr_stmt (stmt);
12486 3312 : }
12487 :
12488 : void
12489 359 : finish_omp_barrier (void)
12490 : {
12491 359 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
12492 359 : releasing_vec vec;
12493 359 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12494 359 : finish_expr_stmt (stmt);
12495 359 : }
12496 :
12497 : void
12498 397 : finish_omp_depobj (location_t loc, tree depobj,
12499 : enum omp_clause_depend_kind kind, tree clause)
12500 : {
12501 397 : if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
12502 : {
12503 343 : if (!lvalue_p (depobj))
12504 : {
12505 6 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
12506 : "%<depobj%> expression is not lvalue expression");
12507 6 : depobj = error_mark_node;
12508 : }
12509 : }
12510 :
12511 397 : if (processing_template_decl)
12512 : {
12513 114 : if (clause == NULL_TREE)
12514 47 : clause = build_int_cst (integer_type_node, kind);
12515 114 : add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
12516 114 : return;
12517 : }
12518 :
12519 283 : if (!error_operand_p (depobj))
12520 : {
12521 274 : tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
12522 274 : if (addr == error_mark_node)
12523 : depobj = error_mark_node;
12524 : else
12525 274 : depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
12526 : tf_warning_or_error);
12527 : }
12528 :
12529 283 : c_finish_omp_depobj (loc, depobj, kind, clause);
12530 : }
12531 :
12532 : void
12533 162 : finish_omp_flush (int mo)
12534 : {
12535 162 : tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
12536 162 : releasing_vec vec;
12537 162 : if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
12538 : {
12539 54 : fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
12540 54 : vec->quick_push (build_int_cst (integer_type_node, mo));
12541 : }
12542 162 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12543 162 : finish_expr_stmt (stmt);
12544 162 : }
12545 :
12546 : void
12547 111 : finish_omp_taskwait (void)
12548 : {
12549 111 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
12550 111 : releasing_vec vec;
12551 111 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12552 111 : finish_expr_stmt (stmt);
12553 111 : }
12554 :
12555 : void
12556 16 : finish_omp_taskyield (void)
12557 : {
12558 16 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
12559 16 : releasing_vec vec;
12560 16 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12561 16 : finish_expr_stmt (stmt);
12562 16 : }
12563 :
12564 : void
12565 596 : finish_omp_cancel (tree clauses)
12566 : {
12567 596 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
12568 596 : int mask = 0;
12569 596 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12570 : mask = 1;
12571 414 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12572 : mask = 2;
12573 285 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12574 : mask = 4;
12575 164 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12576 : mask = 8;
12577 : else
12578 : {
12579 0 : error ("%<#pragma omp cancel%> must specify one of "
12580 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12581 0 : return;
12582 : }
12583 596 : releasing_vec vec;
12584 596 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
12585 596 : if (ifc != NULL_TREE)
12586 : {
12587 70 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
12588 70 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
12589 6 : error_at (OMP_CLAUSE_LOCATION (ifc),
12590 : "expected %<cancel%> %<if%> clause modifier");
12591 : else
12592 : {
12593 64 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
12594 64 : if (ifc2 != NULL_TREE)
12595 : {
12596 3 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
12597 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
12598 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
12599 3 : error_at (OMP_CLAUSE_LOCATION (ifc2),
12600 : "expected %<cancel%> %<if%> clause modifier");
12601 : }
12602 : }
12603 :
12604 70 : if (!processing_template_decl)
12605 61 : ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
12606 : else
12607 9 : ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
12608 9 : OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
12609 : integer_zero_node, ERROR_MARK,
12610 : NULL_TREE, NULL, tf_warning_or_error);
12611 : }
12612 : else
12613 526 : ifc = boolean_true_node;
12614 596 : vec->quick_push (build_int_cst (integer_type_node, mask));
12615 596 : vec->quick_push (ifc);
12616 596 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12617 596 : finish_expr_stmt (stmt);
12618 596 : }
12619 :
12620 : void
12621 494 : finish_omp_cancellation_point (tree clauses)
12622 : {
12623 494 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
12624 494 : int mask = 0;
12625 494 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12626 : mask = 1;
12627 366 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12628 : mask = 2;
12629 261 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12630 : mask = 4;
12631 156 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12632 : mask = 8;
12633 : else
12634 : {
12635 3 : error ("%<#pragma omp cancellation point%> must specify one of "
12636 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12637 3 : return;
12638 : }
12639 491 : releasing_vec vec
12640 491 : = make_tree_vector_single (build_int_cst (integer_type_node, mask));
12641 491 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12642 491 : finish_expr_stmt (stmt);
12643 491 : }
12644 :
12645 : /* Begin a __transaction_atomic or __transaction_relaxed statement.
12646 : If PCOMPOUND is non-null, this is for a function-transaction-block, and we
12647 : should create an extra compound stmt. */
12648 :
12649 : tree
12650 303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
12651 : {
12652 303 : tree r;
12653 :
12654 303 : if (pcompound)
12655 21 : *pcompound = begin_compound_stmt (0);
12656 :
12657 303 : r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
12658 :
12659 : /* Only add the statement to the function if support enabled. */
12660 303 : if (flag_tm)
12661 297 : add_stmt (r);
12662 : else
12663 12 : error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
12664 : ? G_("%<__transaction_relaxed%> without "
12665 : "transactional memory support enabled")
12666 : : G_("%<__transaction_atomic%> without "
12667 : "transactional memory support enabled")));
12668 :
12669 303 : TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
12670 303 : TREE_SIDE_EFFECTS (r) = 1;
12671 303 : return r;
12672 : }
12673 :
12674 : /* End a __transaction_atomic or __transaction_relaxed statement.
12675 : If COMPOUND_STMT is non-null, this is for a function-transaction-block,
12676 : and we should end the compound. If NOEX is non-NULL, we wrap the body in
12677 : a MUST_NOT_THROW_EXPR with NOEX as condition. */
12678 :
12679 : void
12680 303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
12681 : {
12682 303 : TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
12683 303 : TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
12684 303 : TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
12685 303 : TRANSACTION_EXPR_IS_STMT (stmt) = 1;
12686 :
12687 : /* noexcept specifications are not allowed for function transactions. */
12688 303 : gcc_assert (!(noex && compound_stmt));
12689 303 : if (noex)
12690 : {
12691 51 : tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
12692 : noex);
12693 51 : protected_set_expr_location
12694 51 : (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
12695 51 : TREE_SIDE_EFFECTS (body) = 1;
12696 51 : TRANSACTION_EXPR_BODY (stmt) = body;
12697 : }
12698 :
12699 303 : if (compound_stmt)
12700 21 : finish_compound_stmt (compound_stmt);
12701 303 : }
12702 :
12703 : /* Build a __transaction_atomic or __transaction_relaxed expression. If
12704 : NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
12705 : condition. */
12706 :
12707 : tree
12708 116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
12709 : {
12710 116 : tree ret;
12711 116 : if (noex)
12712 : {
12713 57 : expr = build_must_not_throw_expr (expr, noex);
12714 57 : protected_set_expr_location (expr, loc);
12715 57 : TREE_SIDE_EFFECTS (expr) = 1;
12716 : }
12717 116 : ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
12718 116 : if (flags & TM_STMT_ATTR_RELAXED)
12719 4 : TRANSACTION_EXPR_RELAXED (ret) = 1;
12720 116 : TREE_SIDE_EFFECTS (ret) = 1;
12721 116 : SET_EXPR_LOCATION (ret, loc);
12722 116 : return ret;
12723 : }
12724 :
12725 : void
12726 98396 : init_cp_semantics (void)
12727 : {
12728 98396 : }
12729 :
12730 :
12731 : /* Get constant string at LOCATION. Returns true if successful,
12732 : otherwise false. */
12733 :
12734 : bool
12735 10630093 : cexpr_str::type_check (location_t location, bool allow_char8_t /*=false*/)
12736 : {
12737 10630093 : tsubst_flags_t complain = tf_warning_or_error;
12738 :
12739 10630093 : if (message == NULL_TREE
12740 10630093 : || message == error_mark_node
12741 21260183 : || check_for_bare_parameter_packs (message))
12742 3 : return false;
12743 :
12744 10630090 : if (TREE_CODE (message) != STRING_CST
12745 10630090 : && !type_dependent_expression_p (message))
12746 : {
12747 976 : message_sz
12748 976 : = finish_class_member_access_expr (message,
12749 : get_identifier ("size"),
12750 : false, complain);
12751 976 : if (message_sz != error_mark_node)
12752 889 : message_data
12753 889 : = finish_class_member_access_expr (message,
12754 : get_identifier ("data"),
12755 : false, complain);
12756 976 : if (message_sz == error_mark_node || message_data == error_mark_node)
12757 : {
12758 121 : error_at (location, "constexpr string must be a string "
12759 : "literal or object with %<size%> and "
12760 : "%<data%> members");
12761 292 : return false;
12762 : }
12763 855 : releasing_vec size_args, data_args;
12764 855 : message_sz = finish_call_expr (message_sz, &size_args, false, false,
12765 : complain);
12766 855 : message_data = finish_call_expr (message_data, &data_args, false, false,
12767 : complain);
12768 855 : if (message_sz == error_mark_node || message_data == error_mark_node)
12769 : return false;
12770 741 : message_sz = build_converted_constant_expr (size_type_node, message_sz,
12771 : complain);
12772 741 : if (message_sz == error_mark_node)
12773 : {
12774 15 : error_at (location, "constexpr string %<size()%> "
12775 : "must be implicitly convertible to "
12776 : "%<std::size_t%>");
12777 15 : return false;
12778 : }
12779 :
12780 726 : if (allow_char8_t
12781 37 : && POINTER_TYPE_P (TREE_TYPE (message_data))
12782 37 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
12783 37 : == char8_type_node)
12784 736 : && (TYPE_QUALS (TREE_TYPE (TREE_TYPE (message_data)))
12785 : == TYPE_QUAL_CONST))
12786 : return true;
12787 :
12788 716 : message_data = build_converted_constant_expr (const_string_type_node,
12789 : message_data, complain);
12790 716 : if (message_data == error_mark_node)
12791 : {
12792 32 : error_at (location, "constexpr string %<data()%> "
12793 : "must be implicitly convertible to "
12794 : "%<const char*%>");
12795 32 : return false;
12796 : }
12797 855 : }
12798 : return true;
12799 : }
12800 :
12801 : /* Extract constant string at LOCATON into output string STR.
12802 : Returns true if successful, otherwise false. */
12803 :
12804 : bool
12805 405 : cexpr_str::extract (location_t location, tree &str)
12806 : {
12807 405 : const char *msg;
12808 405 : int len;
12809 405 : if (!extract (location, msg, len))
12810 : return false;
12811 343 : str = build_string (len, msg);
12812 343 : return true;
12813 : }
12814 :
12815 : /* Extract constant string at LOCATION into output string MSG with LEN.
12816 : Returns true if successful, otherwise false. */
12817 :
12818 : bool
12819 2176 : cexpr_str::extract (location_t location, const char * &msg, int &len,
12820 : const constexpr_ctx *ctx /* = NULL */,
12821 : bool *non_constant_p /* = NULL */,
12822 : bool *overflow_p /* = NULL */,
12823 : tree *jump_target /* = NULL */)
12824 : {
12825 2176 : tsubst_flags_t complain = tf_warning_or_error;
12826 :
12827 2176 : msg = NULL;
12828 2176 : if (message_sz && message_data)
12829 : {
12830 620 : tree msz;
12831 620 : if (ctx)
12832 : {
12833 55 : msz = cxx_eval_constant_expression (ctx, message_sz, vc_prvalue,
12834 : non_constant_p, overflow_p,
12835 : jump_target);
12836 55 : if (*jump_target || *non_constant_p)
12837 : return false;
12838 : }
12839 : else
12840 565 : msz = cxx_constant_value (message_sz, NULL_TREE, complain);
12841 616 : if (!tree_fits_uhwi_p (msz))
12842 : {
12843 35 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
12844 35 : error_at (location,
12845 : "constexpr string %<size()%> "
12846 : "must be a constant expression");
12847 35 : return false;
12848 : }
12849 581 : else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
12850 : != tree_to_uhwi (msz))
12851 : {
12852 0 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
12853 0 : error_at (location,
12854 : "constexpr string message %<size()%> "
12855 : "%qE too large", msz);
12856 0 : return false;
12857 : }
12858 581 : len = tree_to_uhwi (msz);
12859 581 : tree data;
12860 581 : if (ctx)
12861 : {
12862 51 : data = cxx_eval_constant_expression (ctx, message_data, vc_prvalue,
12863 : non_constant_p, overflow_p,
12864 : jump_target);
12865 51 : if (*jump_target || *non_constant_p)
12866 : return false;
12867 47 : STRIP_NOPS (data);
12868 47 : if (TREE_CODE (data) != ADDR_EXPR)
12869 : {
12870 0 : unhandled:
12871 0 : if (!cxx_constexpr_quiet_p (ctx))
12872 0 : error_at (location, "unhandled return from %<data()%>");
12873 0 : return false;
12874 : }
12875 47 : tree str = TREE_OPERAND (data, 0);
12876 47 : unsigned HOST_WIDE_INT off = 0;
12877 47 : if (TREE_CODE (str) == ARRAY_REF
12878 47 : && tree_fits_uhwi_p (TREE_OPERAND (str, 1)))
12879 : {
12880 6 : off = tree_to_uhwi (TREE_OPERAND (str, 1));
12881 6 : str = TREE_OPERAND (str, 0);
12882 : }
12883 47 : str = cxx_eval_constant_expression (ctx, str, vc_prvalue,
12884 : non_constant_p, overflow_p,
12885 : jump_target);
12886 47 : if (*jump_target || *non_constant_p)
12887 : return false;
12888 47 : if (TREE_CODE (str) == STRING_CST)
12889 : {
12890 42 : if (TREE_STRING_LENGTH (str) < len
12891 42 : || (unsigned) TREE_STRING_LENGTH (str) < off
12892 84 : || (unsigned) TREE_STRING_LENGTH (str) < off + len)
12893 0 : goto unhandled;
12894 42 : msg = TREE_STRING_POINTER (str) + off;
12895 42 : goto translate;
12896 : }
12897 5 : if (TREE_CODE (str) != CONSTRUCTOR
12898 5 : || TREE_CODE (TREE_TYPE (str)) != ARRAY_TYPE)
12899 0 : goto unhandled;
12900 5 : char *b;
12901 5 : if (len < 64)
12902 5 : b = XALLOCAVEC (char, len + 1);
12903 : else
12904 : {
12905 0 : buf = XNEWVEC (char, len + 1);
12906 0 : b = buf;
12907 : }
12908 5 : msg = b;
12909 5 : memset (b, 0, len + 1);
12910 5 : tree field, value;
12911 5 : unsigned k;
12912 5 : unsigned HOST_WIDE_INT l = 0;
12913 79 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (str), k, field, value)
12914 79 : if (!tree_fits_shwi_p (value))
12915 0 : goto unhandled;
12916 79 : else if (field == NULL_TREE)
12917 : {
12918 0 : if (integer_zerop (value))
12919 : break;
12920 0 : if (l >= off && l < off + len)
12921 0 : b[l - off] = tree_to_shwi (value);
12922 0 : ++l;
12923 : }
12924 79 : else if (TREE_CODE (field) == RANGE_EXPR)
12925 : {
12926 0 : tree lo = TREE_OPERAND (field, 0);
12927 0 : tree hi = TREE_OPERAND (field, 1);
12928 0 : if (!tree_fits_uhwi_p (lo) || !tree_fits_uhwi_p (hi))
12929 0 : goto unhandled;
12930 0 : if (integer_zerop (value))
12931 : break;
12932 0 : unsigned HOST_WIDE_INT m = tree_to_uhwi (hi);
12933 0 : for (l = tree_to_uhwi (lo); l <= m; ++l)
12934 0 : if (l >= off && l < off + len)
12935 0 : b[l - off] = tree_to_shwi (value);
12936 : }
12937 79 : else if (tree_fits_uhwi_p (field))
12938 : {
12939 79 : l = tree_to_uhwi (field);
12940 79 : if (integer_zerop (value))
12941 : break;
12942 74 : if (l >= off && l < off + len)
12943 74 : b[l - off] = tree_to_shwi (value);
12944 74 : l++;
12945 : }
12946 5 : b[len] = '\0';
12947 : }
12948 : else
12949 : {
12950 530 : data = maybe_constant_value (message_data, NULL_TREE, mce_true);
12951 530 : if (!reduced_constant_expression_p (data))
12952 96 : data = NULL_TREE;
12953 530 : if (len)
12954 : {
12955 453 : if (data)
12956 379 : msg = c_getstr (data);
12957 453 : if (msg == NULL)
12958 119 : buf = XNEWVEC (char, len);
12959 1452 : for (int i = 0; i < len; ++i)
12960 : {
12961 1029 : tree t = message_data;
12962 1029 : if (i)
12963 1152 : t = build2 (POINTER_PLUS_EXPR,
12964 576 : TREE_TYPE (message_data), message_data,
12965 576 : size_int (i));
12966 1029 : t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
12967 1029 : tree t2 = cxx_constant_value (t, NULL_TREE, complain);
12968 1029 : if (!tree_fits_shwi_p (t2))
12969 : {
12970 30 : error_at (location,
12971 : "constexpr string %<data()[%d]%> "
12972 : "must be a constant expression", i);
12973 30 : return false;
12974 : }
12975 999 : if (msg == NULL)
12976 362 : buf[i] = tree_to_shwi (t2);
12977 : /* If c_getstr worked, just verify the first and
12978 : last characters using constant evaluation. */
12979 637 : else if (len > 2 && i == 0)
12980 266 : i = len - 2;
12981 : }
12982 423 : if (msg == NULL)
12983 104 : msg = buf;
12984 : }
12985 77 : else if (!data)
12986 : {
12987 : /* We don't have any function to test whether some
12988 : expression is a core constant expression. So, instead
12989 : test whether (message.data (), 0) is a constant
12990 : expression. */
12991 22 : data = build2 (COMPOUND_EXPR, integer_type_node,
12992 : message_data, integer_zero_node);
12993 22 : tree t = cxx_constant_value (data, NULL_TREE, complain);
12994 22 : if (!integer_zerop (t))
12995 : {
12996 22 : error_at (location,
12997 : "constexpr string %<data()%> "
12998 : "must be a core constant expression");
12999 22 : return false;
13000 : }
13001 : }
13002 : }
13003 : }
13004 : else
13005 : {
13006 1556 : tree eltype = TREE_TYPE (TREE_TYPE (message));
13007 1556 : int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
13008 1556 : msg = TREE_STRING_POINTER (message);
13009 1556 : len = TREE_STRING_LENGTH (message) / sz - 1;
13010 : }
13011 2081 : translate:
13012 2081 : if ((message_sz && message_data) || ctx)
13013 : {
13014 : /* Convert the string from execution charset to SOURCE_CHARSET. */
13015 618 : cpp_string istr, ostr;
13016 618 : istr.len = len;
13017 618 : istr.text = (const unsigned char *) msg;
13018 618 : enum cpp_ttype type = CPP_STRING;
13019 618 : if (message_sz && message_data)
13020 : {
13021 525 : if (POINTER_TYPE_P (TREE_TYPE (message_data))
13022 525 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
13023 525 : == char8_type_node))
13024 : type = CPP_UTF8STRING;
13025 : }
13026 93 : else if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message)))
13027 93 : == char8_type_node)
13028 618 : type = CPP_UTF8STRING;
13029 618 : if (len == 0)
13030 : ;
13031 530 : else if (!cpp_translate_string (parse_in, &istr, &ostr, type,
13032 : true))
13033 : {
13034 0 : if (type == CPP_UTF8STRING)
13035 0 : error_at (location, "could not convert constexpr string from "
13036 : "UTF-8 encoding to source character "
13037 : "set");
13038 : else
13039 0 : error_at (location, "could not convert constexpr string from "
13040 : "ordinary literal encoding to source character "
13041 : "set");
13042 0 : return false;
13043 : }
13044 : else
13045 : {
13046 530 : if (buf)
13047 104 : XDELETEVEC (buf);
13048 530 : msg = buf = const_cast <char *> ((const char *) ostr.text);
13049 530 : len = ostr.len;
13050 : }
13051 : }
13052 :
13053 : return true;
13054 : }
13055 :
13056 : /* Build a STATIC_ASSERT for a static assertion with the condition
13057 : CONDITION and the message text MESSAGE. LOCATION is the location
13058 : of the static assertion in the source code. When MEMBER_P, this
13059 : static assertion is a member of a class. If SHOW_EXPR_P is true,
13060 : print the condition (because it was instantiation-dependent).
13061 : If CONSTEVAL_BLOCK_P is true, this static assertion represents
13062 : a consteval block. */
13063 :
13064 : void
13065 10629530 : finish_static_assert (tree condition, tree message, location_t location,
13066 : bool member_p, bool show_expr_p,
13067 : bool consteval_block_p/*=false*/)
13068 : {
13069 10629530 : tsubst_flags_t complain = tf_warning_or_error;
13070 :
13071 10629530 : if (condition == NULL_TREE
13072 10629530 : || condition == error_mark_node)
13073 4458102 : return;
13074 :
13075 10629352 : if (check_for_bare_parameter_packs (condition))
13076 : return;
13077 :
13078 10629349 : cexpr_str cstr(message);
13079 10629349 : if (!cstr.type_check (location))
13080 : return;
13081 :
13082 : /* Save the condition in case it was a concept check. */
13083 10629255 : tree orig_condition = condition;
13084 :
13085 10629255 : if (instantiation_dependent_expression_p (condition)
13086 10629255 : || instantiation_dependent_expression_p (message))
13087 : {
13088 : /* We're in a template; build a STATIC_ASSERT and put it in
13089 : the right place. */
13090 4457559 : defer:
13091 4457559 : tree assertion = make_node (STATIC_ASSERT);
13092 4457559 : STATIC_ASSERT_CONDITION (assertion) = orig_condition;
13093 4457559 : STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
13094 4457559 : STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
13095 4457559 : CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
13096 :
13097 4457559 : if (member_p)
13098 2318075 : maybe_add_class_template_decl_list (current_class_type,
13099 : assertion,
13100 : /*friend_p=*/0);
13101 : else
13102 2139484 : add_stmt (assertion);
13103 :
13104 4457559 : return;
13105 : }
13106 :
13107 : /* Evaluate the consteval { }. This must be done only once. */
13108 6175048 : if (consteval_block_p)
13109 : {
13110 243 : cxx_constant_value (condition);
13111 243 : return;
13112 : }
13113 :
13114 : /* Fold the expression and convert it to a boolean value. */
13115 6174805 : condition = contextual_conv_bool (condition, complain);
13116 6174805 : condition = fold_non_dependent_expr (condition, complain,
13117 : /*manifestly_const_eval=*/true);
13118 :
13119 6174804 : if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
13120 : /* Do nothing; the condition is satisfied. */
13121 : ;
13122 : else
13123 : {
13124 5502 : iloc_sentinel ils (location);
13125 :
13126 5502 : if (integer_zerop (condition))
13127 : {
13128 : /* CWG2518: static_assert failure in a template is not IFNDR. */
13129 4975 : if (processing_template_decl)
13130 3352 : goto defer;
13131 :
13132 1623 : int len;
13133 1623 : const char *msg = NULL;
13134 1623 : if (!cstr.extract (location, msg, len))
13135 25 : return;
13136 :
13137 : /* See if we can find which clause was failing (for logical AND). */
13138 1598 : tree bad = find_failing_clause (NULL, orig_condition);
13139 : /* If not, or its location is unusable, fall back to the previous
13140 : location. */
13141 1598 : location_t cloc = cp_expr_loc_or_loc (bad, location);
13142 :
13143 1598 : auto_diagnostic_group d;
13144 :
13145 : /* Report the error. */
13146 1598 : if (len == 0)
13147 998 : error_at (cloc, "static assertion failed");
13148 : else
13149 600 : error_at (cloc, "static assertion failed: %.*s", len, msg);
13150 :
13151 1598 : diagnose_failing_condition (bad, cloc, show_expr_p);
13152 :
13153 : /* Suppress -Wreturn-type for functions with failed static_asserts.
13154 : Otherwise templates like:
13155 : if constexpr (whatever)
13156 : return something (args);
13157 : else
13158 : static_assert (false, "explanation");
13159 : get a useless extra -Wreturn-type warning. */
13160 1598 : if (current_function_decl)
13161 585 : suppress_warning (current_function_decl, OPT_Wreturn_type);
13162 1598 : }
13163 527 : else if (condition && condition != error_mark_node)
13164 : {
13165 522 : error ("non-constant condition for static assertion");
13166 522 : if (require_rvalue_constant_expression (condition))
13167 466 : cxx_constant_value (condition);
13168 : }
13169 5502 : }
13170 10629348 : }
13171 :
13172 : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
13173 : suitable for use as a type-specifier.
13174 :
13175 : ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
13176 : id-expression or a class member access, FALSE when it was parsed as
13177 : a full expression. */
13178 :
13179 : tree
13180 37834441 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
13181 : tsubst_flags_t complain)
13182 : {
13183 37834441 : tree type = NULL_TREE;
13184 :
13185 37834441 : if (!expr || error_operand_p (expr))
13186 212284 : return error_mark_node;
13187 :
13188 37622157 : if (TYPE_P (expr)
13189 37622157 : || TREE_CODE (expr) == TYPE_DECL
13190 75244295 : || (TREE_CODE (expr) == BIT_NOT_EXPR
13191 13256 : && TYPE_P (TREE_OPERAND (expr, 0))))
13192 : {
13193 28 : if (complain & tf_error)
13194 28 : error ("argument to %<decltype%> must be an expression");
13195 28 : return error_mark_node;
13196 : }
13197 :
13198 : /* decltype is an unevaluated context. */
13199 37622129 : cp_unevaluated u;
13200 :
13201 37622129 : processing_template_decl_sentinel ptds (/*reset=*/false);
13202 :
13203 : /* Depending on the resolution of DR 1172, we may later need to distinguish
13204 : instantiation-dependent but not type-dependent expressions so that, say,
13205 : A<decltype(sizeof(T))>::U doesn't require 'typename'. */
13206 37622129 : if (instantiation_dependent_uneval_expression_p (expr))
13207 : {
13208 6839731 : dependent:
13209 6840115 : type = cxx_make_type (DECLTYPE_TYPE);
13210 6840115 : DECLTYPE_TYPE_EXPR (type) = expr;
13211 13680230 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
13212 6840115 : = id_expression_or_member_access_p;
13213 6840115 : SET_TYPE_STRUCTURAL_EQUALITY (type);
13214 :
13215 6840115 : return type;
13216 : }
13217 30782398 : else if (processing_template_decl)
13218 : {
13219 4696 : expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
13220 4696 : if (expr == error_mark_node)
13221 : return error_mark_node;
13222 : /* Keep processing_template_decl cleared for the rest of the function
13223 : (for sake of the call to lvalue_kind below, which handles templated
13224 : and non-templated COND_EXPR differently). */
13225 4659 : processing_template_decl = 0;
13226 : }
13227 :
13228 : /* The type denoted by decltype(e) is defined as follows: */
13229 :
13230 30782361 : expr = resolve_nondeduced_context (expr, complain);
13231 30782361 : if (!mark_single_function (expr, complain))
13232 0 : return error_mark_node;
13233 :
13234 30782361 : if (invalid_nonstatic_memfn_p (input_location, expr, complain))
13235 18 : return error_mark_node;
13236 :
13237 30782343 : if (type_unknown_p (expr))
13238 : {
13239 18 : if (complain & tf_error)
13240 6 : error ("%<decltype%> cannot resolve address of overloaded function");
13241 18 : return error_mark_node;
13242 : }
13243 :
13244 30782325 : if (id_expression_or_member_access_p)
13245 : {
13246 : /* If e is an id-expression or a class member access (5.2.5
13247 : [expr.ref]), decltype(e) is defined as the type of the entity
13248 : named by e. If there is no such entity, or e names a set of
13249 : overloaded functions, the program is ill-formed. */
13250 413171 : if (identifier_p (expr))
13251 0 : expr = lookup_name (expr);
13252 :
13253 : /* If e is a constified expression inside a contract assertion,
13254 : strip the const wrapper. Per P2900R14, "For a function f with the
13255 : return type T , the result name is an lvalue of type const T , decltype(r)
13256 : is T , and decltype((r)) is const T&." */
13257 413171 : expr = strip_contract_const_wrapper (expr);
13258 :
13259 280089 : if (REFERENCE_REF_P (expr)
13260 413174 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
13261 : /* This can happen when the expression is, e.g., "a.b". Just
13262 : look at the underlying operand. */
13263 280770 : expr = TREE_OPERAND (expr, 0);
13264 :
13265 413171 : if (TREE_CODE (expr) == OFFSET_REF
13266 413171 : || TREE_CODE (expr) == MEMBER_REF
13267 413171 : || TREE_CODE (expr) == SCOPE_REF)
13268 : /* We're only interested in the field itself. If it is a
13269 : BASELINK, we will need to see through it in the next
13270 : step. */
13271 0 : expr = TREE_OPERAND (expr, 1);
13272 :
13273 413171 : if (BASELINK_P (expr))
13274 : /* See through BASELINK nodes to the underlying function. */
13275 5 : expr = BASELINK_FUNCTIONS (expr);
13276 :
13277 : /* decltype of a decomposition name drops references in the tuple case
13278 : (unlike decltype of a normal variable) and keeps cv-qualifiers from
13279 : the containing object in the other cases (unlike decltype of a member
13280 : access expression). */
13281 413171 : if (DECL_DECOMPOSITION_P (expr))
13282 : {
13283 1413 : if (ptds.saved)
13284 : {
13285 275 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr)
13286 : || (DECL_CONTEXT (expr)
13287 : != current_function_decl));
13288 : /* DECL_HAS_VALUE_EXPR_P is always set if
13289 : processing_template_decl at least for structured bindings
13290 : within the template. If lookup_decomp_type
13291 : returns non-NULL, it is the tuple case. */
13292 275 : if (tree ret = lookup_decomp_type (expr))
13293 : return ret;
13294 191 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
13295 : }
13296 1329 : if (DECL_HAS_VALUE_EXPR_P (expr))
13297 : /* Expr is an array or struct subobject proxy, handle
13298 : bit-fields properly. */
13299 1017 : return unlowered_expr_type (expr);
13300 : else
13301 : /* Expr is a reference variable for the tuple case. */
13302 312 : return lookup_decomp_type (expr);
13303 : }
13304 :
13305 411758 : switch (TREE_CODE (expr))
13306 : {
13307 241 : case FIELD_DECL:
13308 241 : if (DECL_BIT_FIELD_TYPE (expr))
13309 : {
13310 : type = DECL_BIT_FIELD_TYPE (expr);
13311 : break;
13312 : }
13313 : /* Fall through for fields that aren't bitfields. */
13314 117404 : gcc_fallthrough ();
13315 :
13316 117404 : case VAR_DECL:
13317 117404 : if (is_capture_proxy (expr))
13318 : {
13319 85 : if (is_normal_capture_proxy (expr))
13320 : {
13321 21 : expr = DECL_CAPTURED_VARIABLE (expr);
13322 21 : type = TREE_TYPE (expr);
13323 : }
13324 : else
13325 : {
13326 64 : expr = DECL_VALUE_EXPR (expr);
13327 64 : gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
13328 64 : expr = TREE_OPERAND (expr, 1);
13329 64 : type = TREE_TYPE (expr);
13330 : }
13331 : break;
13332 : }
13333 : /* Fall through for variables that aren't capture proxies. */
13334 407588 : gcc_fallthrough ();
13335 :
13336 407588 : case FUNCTION_DECL:
13337 407588 : case CONST_DECL:
13338 407588 : case PARM_DECL:
13339 407588 : case RESULT_DECL:
13340 407588 : case TEMPLATE_PARM_INDEX:
13341 407588 : expr = mark_type_use (expr);
13342 407588 : type = TREE_TYPE (expr);
13343 407588 : if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
13344 : {
13345 : /* decltype of an NTTP object is the type of the template
13346 : parameter, which is the object type modulo cv-quals. */
13347 1399 : int quals = cp_type_quals (type);
13348 1399 : gcc_checking_assert (quals & TYPE_QUAL_CONST);
13349 1399 : type = cv_unqualified (type);
13350 : }
13351 : break;
13352 :
13353 0 : case ERROR_MARK:
13354 0 : type = error_mark_node;
13355 0 : break;
13356 :
13357 3117 : case COMPONENT_REF:
13358 3117 : case COMPOUND_EXPR:
13359 3117 : mark_type_use (expr);
13360 3117 : type = is_bitfield_expr_with_lowered_type (expr);
13361 3117 : if (!type)
13362 3082 : type = TREE_TYPE (TREE_OPERAND (expr, 1));
13363 : break;
13364 :
13365 0 : case BIT_FIELD_REF:
13366 0 : gcc_unreachable ();
13367 :
13368 252 : case INTEGER_CST:
13369 252 : case PTRMEM_CST:
13370 : /* We can get here when the id-expression refers to an
13371 : enumerator or non-type template parameter. */
13372 252 : type = TREE_TYPE (expr);
13373 252 : break;
13374 :
13375 716 : default:
13376 : /* Handle instantiated template non-type arguments. */
13377 716 : type = TREE_TYPE (expr);
13378 716 : break;
13379 : }
13380 : }
13381 : else
13382 : {
13383 30369154 : tree decl = STRIP_REFERENCE_REF (expr);
13384 30369154 : tree lam = current_lambda_expr ();
13385 30369154 : if (lam && outer_automatic_var_p (decl))
13386 : {
13387 : /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
13388 : unevaluated operand within S would refer to an entity captured by
13389 : copy in some intervening lambda-expression, then let E be the
13390 : innermost such lambda-expression.
13391 :
13392 : If there is such a lambda-expression and if P is in E's function
13393 : parameter scope but not its parameter-declaration-clause, then the
13394 : type of the expression is the type of a class member access
13395 : expression naming the non-static data member that would be declared
13396 : for such a capture in the object parameter of the function call
13397 : operator of E." */
13398 : /* FIXME: This transformation needs to happen for all uses of an outer
13399 : local variable inside decltype, not just decltype((x)) (PR83167).
13400 : And we don't handle nested lambdas properly, where we need to
13401 : consider the outer lambdas as well (PR112926). */
13402 940 : tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
13403 : LOOK_want::HIDDEN_LAMBDA);
13404 :
13405 940 : if (cap && is_capture_proxy (cap))
13406 319 : type = TREE_TYPE (cap);
13407 621 : else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
13408 : {
13409 500 : type = TREE_TYPE (decl);
13410 500 : if (TYPE_REF_P (type)
13411 500 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
13412 25 : type = TREE_TYPE (type);
13413 : }
13414 :
13415 819 : if (type && !TYPE_REF_P (type))
13416 : {
13417 761 : int quals;
13418 761 : if (current_function_decl
13419 1428 : && LAMBDA_FUNCTION_P (current_function_decl)
13420 1428 : && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
13421 : {
13422 600 : tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
13423 600 : if (WILDCARD_TYPE_P (non_reference (obtype)))
13424 : /* We don't know what the eventual obtype quals will be. */
13425 384 : goto dependent;
13426 432 : auto direct_type = [](tree t){
13427 216 : if (INDIRECT_TYPE_P (t))
13428 108 : return TREE_TYPE (t);
13429 : return t;
13430 : };
13431 432 : quals = (cp_type_quals (type)
13432 216 : | cp_type_quals (direct_type (obtype)));
13433 : }
13434 : else
13435 : /* We are in the parameter clause, trailing return type, or
13436 : the requires clause and have no relevant c_f_decl yet. */
13437 251 : quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
13438 161 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
13439 377 : type = cp_build_qualified_type (type, quals);
13440 377 : type = build_reference_type (type);
13441 : }
13442 : }
13443 30368214 : else if (error_operand_p (expr))
13444 0 : type = error_mark_node;
13445 30368214 : else if (expr == current_class_ptr)
13446 : /* If the expression is just "this", we want the
13447 : cv-unqualified pointer for the "this" type. */
13448 0 : type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
13449 :
13450 377 : if (!type)
13451 : {
13452 : /* Otherwise, where T is the type of e, if e is an lvalue,
13453 : decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
13454 30368335 : cp_lvalue_kind clk = lvalue_kind (expr);
13455 30368335 : type = unlowered_expr_type (expr);
13456 30368335 : gcc_assert (!TYPE_REF_P (type));
13457 :
13458 : /* For vector types, pick a non-opaque variant. */
13459 30368335 : if (VECTOR_TYPE_P (type))
13460 2078 : type = strip_typedefs (type);
13461 :
13462 30368335 : if (clk != clk_none && !(clk & clk_class))
13463 8729979 : type = cp_build_reference_type (type, (clk & clk_rvalueref));
13464 : }
13465 : }
13466 :
13467 : return type;
13468 37622129 : }
13469 :
13470 : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
13471 : __has_nothrow_copy, depending on assign_p. Returns true iff all
13472 : the copy {ctor,assign} fns are nothrow. */
13473 :
13474 : static bool
13475 279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
13476 : {
13477 279 : tree fns = NULL_TREE;
13478 :
13479 279 : if (assign_p || TYPE_HAS_COPY_CTOR (type))
13480 276 : fns = get_class_binding (type, assign_p ? assign_op_identifier
13481 : : ctor_identifier);
13482 :
13483 279 : bool saw_copy = false;
13484 696 : for (ovl_iterator iter (fns); iter; ++iter)
13485 : {
13486 441 : tree fn = *iter;
13487 :
13488 441 : if (copy_fn_p (fn) > 0)
13489 : {
13490 423 : saw_copy = true;
13491 423 : if (!maybe_instantiate_noexcept (fn)
13492 423 : || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
13493 192 : return false;
13494 : }
13495 : }
13496 :
13497 87 : return saw_copy;
13498 : }
13499 :
13500 : /* Return true if BASE is a pointer-interconvertible base of DERIVED. */
13501 :
13502 : bool
13503 157 : pointer_interconvertible_base_of_p (tree base, tree derived,
13504 : bool explain/*=false*/)
13505 : {
13506 157 : if (base == error_mark_node || derived == error_mark_node)
13507 : return false;
13508 :
13509 157 : base = TYPE_MAIN_VARIANT (base);
13510 157 : derived = TYPE_MAIN_VARIANT (derived);
13511 157 : if (!NON_UNION_CLASS_TYPE_P (base))
13512 : {
13513 15 : if (explain)
13514 3 : inform (location_of (base),
13515 : "%qT is not a non-union class type", base);
13516 15 : return false;
13517 : }
13518 142 : if (!NON_UNION_CLASS_TYPE_P (derived))
13519 : {
13520 6 : if (explain)
13521 3 : inform (location_of (derived),
13522 : "%qT is not a non-union class type", derived);
13523 6 : return false;
13524 : }
13525 :
13526 136 : if (same_type_p (base, derived))
13527 : return true;
13528 :
13529 106 : if (!std_layout_type_p (derived))
13530 : {
13531 17 : if (explain)
13532 6 : inform (location_of (derived),
13533 : "%qT is not a standard-layout type", derived);
13534 17 : return false;
13535 : }
13536 :
13537 89 : if (!uniquely_derived_from_p (base, derived))
13538 : {
13539 16 : if (explain)
13540 : {
13541 : /* An ambiguous base should already be impossible due to
13542 : the std_layout_type_p check. */
13543 3 : gcc_checking_assert (!DERIVED_FROM_P (base, derived));
13544 3 : inform (location_of (derived),
13545 : "%qT is not a base of %qT", base, derived);
13546 : }
13547 16 : return false;
13548 : }
13549 :
13550 : return true;
13551 : }
13552 :
13553 : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
13554 : return true if MEMBERTYPE is the type of the first non-static data member
13555 : of TYPE or for unions of any members. */
13556 : static bool
13557 637 : first_nonstatic_data_member_p (tree type, tree membertype)
13558 : {
13559 1297 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
13560 : {
13561 1222 : if (TREE_CODE (field) != FIELD_DECL)
13562 135 : continue;
13563 1087 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
13564 60 : continue;
13565 1027 : if (DECL_FIELD_IS_BASE (field))
13566 45 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
13567 982 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13568 : {
13569 216 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
13570 138 : || std_layout_type_p (TREE_TYPE (field)))
13571 294 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
13572 : return true;
13573 : }
13574 766 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13575 : membertype))
13576 : return true;
13577 537 : if (TREE_CODE (type) != UNION_TYPE)
13578 : return false;
13579 : }
13580 : return false;
13581 : }
13582 :
13583 : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
13584 :
13585 : tree
13586 536 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
13587 : tree *args)
13588 : {
13589 : /* Unless users call the builtin directly, the following 3 checks should be
13590 : ensured from std::is_pointer_interconvertible_with_class function
13591 : template. */
13592 536 : if (nargs != 1)
13593 : {
13594 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13595 : "needs a single argument");
13596 6 : return boolean_false_node;
13597 : }
13598 530 : tree arg = args[0];
13599 530 : if (error_operand_p (arg))
13600 0 : return boolean_false_node;
13601 530 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
13602 : {
13603 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13604 : "argument is not pointer to member");
13605 6 : return boolean_false_node;
13606 : }
13607 :
13608 524 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
13609 18 : return boolean_false_node;
13610 :
13611 506 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
13612 506 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
13613 506 : if (!complete_type_or_else (basetype, NULL_TREE))
13614 3 : return boolean_false_node;
13615 :
13616 503 : if (TREE_CODE (basetype) != UNION_TYPE
13617 503 : && !std_layout_type_p (basetype))
13618 22 : return boolean_false_node;
13619 :
13620 481 : if (!first_nonstatic_data_member_p (basetype, membertype))
13621 132 : return boolean_false_node;
13622 :
13623 349 : if (TREE_CODE (arg) == PTRMEM_CST)
13624 68 : arg = cplus_expand_constant (arg);
13625 :
13626 349 : if (integer_nonzerop (arg))
13627 10 : return boolean_false_node;
13628 339 : if (integer_zerop (arg))
13629 71 : return boolean_true_node;
13630 :
13631 268 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
13632 : build_zero_cst (TREE_TYPE (arg)));
13633 : }
13634 :
13635 : /* Helper function for is_corresponding_member_aggr. Return true if
13636 : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
13637 : union or structure BASETYPE. */
13638 :
13639 : static bool
13640 90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
13641 : {
13642 222 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
13643 192 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
13644 36 : continue;
13645 156 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13646 : membertype))
13647 : {
13648 48 : if (TREE_CODE (arg) != INTEGER_CST
13649 48 : || tree_int_cst_equal (arg, byte_position (field)))
13650 48 : return true;
13651 : }
13652 108 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13653 : {
13654 18 : tree narg = arg;
13655 18 : if (TREE_CODE (basetype) != UNION_TYPE
13656 0 : && TREE_CODE (narg) == INTEGER_CST)
13657 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
13658 18 : if (is_corresponding_member_union (TREE_TYPE (field),
13659 : membertype, narg))
13660 : return true;
13661 : }
13662 : return false;
13663 : }
13664 :
13665 : /* Helper function for fold_builtin_is_corresponding_member call.
13666 : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
13667 : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
13668 : boolean_true_node if they are corresponding members, or for
13669 : non-constant ARG2 the highest member offset for corresponding
13670 : members. */
13671 :
13672 : static tree
13673 550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
13674 : tree arg1, tree basetype2, tree membertype2,
13675 : tree arg2)
13676 : {
13677 550 : tree field1 = TYPE_FIELDS (basetype1);
13678 550 : tree field2 = TYPE_FIELDS (basetype2);
13679 550 : tree ret = boolean_false_node;
13680 2376 : while (1)
13681 : {
13682 1463 : bool r = next_common_initial_sequence (field1, field2);
13683 1463 : if (field1 == NULL_TREE || field2 == NULL_TREE)
13684 : break;
13685 1331 : if (r
13686 1038 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
13687 : membertype1)
13688 1841 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
13689 : membertype2))
13690 : {
13691 504 : tree pos = byte_position (field1);
13692 504 : if (TREE_CODE (arg1) == INTEGER_CST
13693 504 : && tree_int_cst_equal (arg1, pos))
13694 : {
13695 92 : if (TREE_CODE (arg2) == INTEGER_CST)
13696 92 : return boolean_true_node;
13697 : return pos;
13698 : }
13699 412 : else if (TREE_CODE (arg1) != INTEGER_CST)
13700 1188 : ret = pos;
13701 : }
13702 1654 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
13703 944 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
13704 : {
13705 117 : if ((!lookup_attribute ("no_unique_address",
13706 117 : DECL_ATTRIBUTES (field1)))
13707 117 : != !lookup_attribute ("no_unique_address",
13708 117 : DECL_ATTRIBUTES (field2)))
13709 : break;
13710 117 : if (!tree_int_cst_equal (bit_position (field1),
13711 117 : bit_position (field2)))
13712 : break;
13713 99 : bool overlap = true;
13714 99 : tree pos = byte_position (field1);
13715 99 : if (TREE_CODE (arg1) == INTEGER_CST)
13716 : {
13717 27 : tree off1 = fold_convert (sizetype, arg1);
13718 27 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
13719 27 : if (tree_int_cst_lt (off1, pos)
13720 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
13721 : overlap = false;
13722 : }
13723 99 : if (TREE_CODE (arg2) == INTEGER_CST)
13724 : {
13725 27 : tree off2 = fold_convert (sizetype, arg2);
13726 27 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
13727 27 : if (tree_int_cst_lt (off2, pos)
13728 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
13729 : overlap = false;
13730 : }
13731 87 : if (overlap
13732 87 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
13733 126 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
13734 : {
13735 39 : tree narg1 = arg1;
13736 39 : if (TREE_CODE (arg1) == INTEGER_CST)
13737 9 : narg1 = size_binop (MINUS_EXPR,
13738 : fold_convert (sizetype, arg1), pos);
13739 39 : tree narg2 = arg2;
13740 39 : if (TREE_CODE (arg2) == INTEGER_CST)
13741 9 : narg2 = size_binop (MINUS_EXPR,
13742 : fold_convert (sizetype, arg2), pos);
13743 39 : tree t1 = TREE_TYPE (field1);
13744 39 : tree t2 = TREE_TYPE (field2);
13745 39 : tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
13746 : narg1, t2, membertype2,
13747 : narg2);
13748 39 : if (nret != boolean_false_node)
13749 : {
13750 39 : if (nret == boolean_true_node)
13751 : return nret;
13752 30 : if (TREE_CODE (arg1) == INTEGER_CST)
13753 0 : return size_binop (PLUS_EXPR, nret, pos);
13754 30 : ret = size_binop (PLUS_EXPR, nret, pos);
13755 : }
13756 : }
13757 60 : else if (overlap
13758 48 : && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
13759 108 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
13760 : {
13761 48 : tree narg1 = arg1;
13762 48 : if (TREE_CODE (arg1) == INTEGER_CST)
13763 6 : narg1 = size_binop (MINUS_EXPR,
13764 : fold_convert (sizetype, arg1), pos);
13765 48 : tree narg2 = arg2;
13766 48 : if (TREE_CODE (arg2) == INTEGER_CST)
13767 6 : narg2 = size_binop (MINUS_EXPR,
13768 : fold_convert (sizetype, arg2), pos);
13769 48 : if (is_corresponding_member_union (TREE_TYPE (field1),
13770 : membertype1, narg1)
13771 48 : && is_corresponding_member_union (TREE_TYPE (field2),
13772 : membertype2, narg2))
13773 : {
13774 24 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
13775 : "not well defined for anonymous unions");
13776 24 : return boolean_false_node;
13777 : }
13778 : }
13779 : }
13780 1188 : if (!r)
13781 : break;
13782 913 : field1 = DECL_CHAIN (field1);
13783 913 : field2 = DECL_CHAIN (field2);
13784 913 : }
13785 : return ret;
13786 : }
13787 :
13788 : /* Fold __builtin_is_corresponding_member call. */
13789 :
13790 : tree
13791 699 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
13792 : tree *args)
13793 : {
13794 : /* Unless users call the builtin directly, the following 3 checks should be
13795 : ensured from std::is_corresponding_member function template. */
13796 699 : if (nargs != 2)
13797 : {
13798 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13799 : "needs two arguments");
13800 9 : return boolean_false_node;
13801 : }
13802 690 : tree arg1 = args[0];
13803 690 : tree arg2 = args[1];
13804 690 : if (error_operand_p (arg1) || error_operand_p (arg2))
13805 0 : return boolean_false_node;
13806 711 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
13807 705 : || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
13808 : {
13809 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13810 : "argument is not pointer to member");
13811 9 : return boolean_false_node;
13812 : }
13813 :
13814 681 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
13815 681 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
13816 15 : return boolean_false_node;
13817 :
13818 666 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
13819 666 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
13820 666 : if (!complete_type_or_else (basetype1, NULL_TREE))
13821 12 : return boolean_false_node;
13822 :
13823 654 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
13824 654 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
13825 654 : if (!complete_type_or_else (basetype2, NULL_TREE))
13826 12 : return boolean_false_node;
13827 :
13828 627 : if (!NON_UNION_CLASS_TYPE_P (basetype1)
13829 627 : || !NON_UNION_CLASS_TYPE_P (basetype2)
13830 627 : || !std_layout_type_p (basetype1)
13831 1233 : || !std_layout_type_p (basetype2))
13832 51 : return boolean_false_node;
13833 :
13834 : /* If the member types aren't layout compatible, then they
13835 : can't be corresponding members. */
13836 591 : if (!layout_compatible_type_p (membertype1, membertype2))
13837 18 : return boolean_false_node;
13838 :
13839 573 : if (TREE_CODE (arg1) == PTRMEM_CST)
13840 176 : arg1 = cplus_expand_constant (arg1);
13841 573 : if (TREE_CODE (arg2) == PTRMEM_CST)
13842 182 : arg2 = cplus_expand_constant (arg2);
13843 :
13844 573 : if (null_member_pointer_value_p (arg1)
13845 573 : || null_member_pointer_value_p (arg2))
13846 9 : return boolean_false_node;
13847 :
13848 564 : if (TREE_CODE (arg1) == INTEGER_CST
13849 182 : && TREE_CODE (arg2) == INTEGER_CST
13850 746 : && !tree_int_cst_equal (arg1, arg2))
13851 53 : return boolean_false_node;
13852 :
13853 511 : if (TREE_CODE (arg2) == INTEGER_CST
13854 129 : && TREE_CODE (arg1) != INTEGER_CST)
13855 : {
13856 : std::swap (arg1, arg2);
13857 : std::swap (membertype1, membertype2);
13858 : std::swap (basetype1, basetype2);
13859 : }
13860 :
13861 511 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
13862 : basetype2, membertype2, arg2);
13863 511 : if (TREE_TYPE (ret) == boolean_type_node)
13864 : return ret;
13865 : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
13866 : already returns boolean_{true,false}_node whether those particular
13867 : members are corresponding members or not. Otherwise, if only
13868 : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
13869 : above), it returns boolean_false_node if it is certainly not a
13870 : corresponding member and otherwise we need to do a runtime check that
13871 : those two OFFSET_TYPE offsets are equal.
13872 : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
13873 : returns the largest offset at which the members would be corresponding
13874 : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
13875 304 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
13876 304 : if (TREE_CODE (arg1) == INTEGER_CST)
13877 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13878 : fold_convert (TREE_TYPE (arg1), arg2));
13879 304 : ret = fold_build2 (LE_EXPR, boolean_type_node,
13880 : fold_convert (pointer_sized_int_node, arg1),
13881 : fold_convert (pointer_sized_int_node, ret));
13882 304 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
13883 : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13884 : fold_convert (TREE_TYPE (arg1), arg2)));
13885 : }
13886 :
13887 : /* Fold __builtin_is_string_literal call. */
13888 :
13889 : tree
13890 1983 : fold_builtin_is_string_literal (location_t loc, int nargs, tree *args)
13891 : {
13892 : /* Unless users call the builtin directly, the following 3 checks should be
13893 : ensured from std::is_string_literal overloads. */
13894 1983 : if (nargs != 1)
13895 : {
13896 0 : error_at (loc, "%<__builtin_is_string_literal%> needs a single "
13897 : "argument");
13898 0 : return boolean_false_node;
13899 : }
13900 1983 : tree arg = args[0];
13901 1983 : if (error_operand_p (arg))
13902 0 : return boolean_false_node;
13903 1983 : if (!TYPE_PTR_P (TREE_TYPE (arg))
13904 1983 : || !TYPE_READONLY (TREE_TYPE (TREE_TYPE (arg)))
13905 3966 : || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (arg))))
13906 : {
13907 0 : arg_invalid:
13908 0 : error_at (loc, "%<__builtin_is_string_literal%> "
13909 : "argument is not %<const char*%>, %<const wchar_t*%>, "
13910 : "%<const char8_t*%>, %<const char16_t*%> or "
13911 : "%<const char32_t*%>");
13912 0 : return boolean_false_node;
13913 : }
13914 1983 : tree chart = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg)));
13915 1983 : if (chart != char_type_node
13916 1584 : && chart != wchar_type_node
13917 1188 : && chart != char8_type_node
13918 792 : && chart != char16_type_node
13919 396 : && chart != char32_type_node)
13920 0 : goto arg_invalid;
13921 :
13922 1983 : STRIP_NOPS (arg);
13923 3972 : while (TREE_CODE (arg) == POINTER_PLUS_EXPR)
13924 : {
13925 6 : arg = TREE_OPERAND (arg, 0);
13926 6 : STRIP_NOPS (arg);
13927 : }
13928 1983 : if (TREE_CODE (arg) != ADDR_EXPR)
13929 1955 : return boolean_false_node;
13930 28 : arg = TREE_OPERAND (arg, 0);
13931 28 : if (TREE_CODE (arg) == ARRAY_REF)
13932 12 : arg = TREE_OPERAND (arg, 0);
13933 28 : if (TREE_CODE (arg) != STRING_CST)
13934 8 : return boolean_false_node;
13935 20 : return boolean_true_node;
13936 : }
13937 :
13938 : /* [basic.types] 8. True iff TYPE is an object type. */
13939 :
13940 : static bool
13941 2806585 : object_type_p (const_tree type)
13942 : {
13943 2806585 : return (TREE_CODE (type) != FUNCTION_TYPE
13944 0 : && !TYPE_REF_P (type)
13945 2806585 : && !VOID_TYPE_P (type));
13946 : }
13947 :
13948 : /* [defns.referenceable] True iff TYPE is a referenceable type. */
13949 :
13950 : static bool
13951 3445644 : referenceable_type_p (const_tree type)
13952 : {
13953 3445644 : return (TYPE_REF_P (type)
13954 3446040 : || object_type_p (type)
13955 3446040 : || (FUNC_OR_METHOD_TYPE_P (type)
13956 333 : && type_memfn_quals (type) == TYPE_UNQUALIFIED
13957 273 : && type_memfn_rqual (type) == REF_QUAL_NONE));
13958 : }
13959 :
13960 : /* Actually evaluates the trait. */
13961 :
13962 : static bool
13963 17182614 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
13964 : {
13965 17182614 : enum tree_code type_code1;
13966 17182614 : tree t;
13967 :
13968 17182614 : type_code1 = TREE_CODE (type1);
13969 :
13970 17182614 : switch (kind)
13971 : {
13972 317 : case CPTK_HAS_NOTHROW_ASSIGN:
13973 317 : type1 = strip_array_types (type1);
13974 601 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
13975 601 : && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
13976 173 : || (CLASS_TYPE_P (type1)
13977 129 : && classtype_has_nothrow_assign_or_copy_p (type1,
13978 : true))));
13979 :
13980 215 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
13981 215 : type1 = strip_array_types (type1);
13982 215 : return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
13983 215 : || (CLASS_TYPE_P (type1)
13984 93 : && (t = locate_ctor (type1))
13985 60 : && maybe_instantiate_noexcept (t)
13986 58 : && TYPE_NOTHROW_P (TREE_TYPE (t))));
13987 :
13988 305 : case CPTK_HAS_NOTHROW_COPY:
13989 305 : type1 = strip_array_types (type1);
13990 305 : return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
13991 305 : || (CLASS_TYPE_P (type1)
13992 150 : && classtype_has_nothrow_assign_or_copy_p (type1, false)));
13993 :
13994 517 : case CPTK_HAS_TRIVIAL_ASSIGN:
13995 : /* ??? The standard seems to be missing the "or array of such a class
13996 : type" wording for this trait. */
13997 517 : type1 = strip_array_types (type1);
13998 1016 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
13999 1001 : && (trivial_type_p (type1)
14000 307 : || (CLASS_TYPE_P (type1)
14001 222 : && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
14002 :
14003 505 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14004 505 : type1 = strip_array_types (type1);
14005 505 : return (trivial_type_p (type1)
14006 505 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
14007 :
14008 526 : case CPTK_HAS_TRIVIAL_COPY:
14009 : /* ??? The standard seems to be missing the "or array of such a class
14010 : type" wording for this trait. */
14011 526 : type1 = strip_array_types (type1);
14012 878 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14013 863 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
14014 :
14015 761 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14016 761 : type1 = strip_array_types (type1);
14017 761 : if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
14018 : {
14019 123 : deferring_access_check_sentinel dacs (dk_no_check);
14020 123 : cp_unevaluated un;
14021 123 : tree fn = get_dtor (type1, tf_none);
14022 123 : if (!fn && !seen_error ())
14023 3 : warning (0, "checking %qs for type %qT with a destructor that "
14024 : "cannot be called", "__has_trivial_destructor", type1);
14025 123 : }
14026 1092 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14027 1089 : || (CLASS_TYPE_P (type1)
14028 284 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
14029 :
14030 57873 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14031 57873 : return type_has_unique_obj_representations (type1);
14032 :
14033 279 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14034 279 : return type_has_virtual_destructor (type1);
14035 :
14036 54520 : case CPTK_IS_ABSTRACT:
14037 54520 : return ABSTRACT_CLASS_TYPE_P (type1);
14038 :
14039 813 : case CPTK_IS_AGGREGATE:
14040 813 : return CP_AGGREGATE_TYPE_P (type1);
14041 :
14042 332176 : case CPTK_IS_ARRAY:
14043 332176 : return (type_code1 == ARRAY_TYPE
14044 : /* We don't want to report T[0] as being an array type.
14045 : This is for compatibility with an implementation of
14046 : std::is_array by template argument deduction, because
14047 : compute_array_index_type_loc rejects a zero-size array
14048 : in SFINAE context. */
14049 332176 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14050 :
14051 985331 : case CPTK_IS_ASSIGNABLE:
14052 985331 : return is_xible (MODIFY_EXPR, type1, type2);
14053 :
14054 486188 : case CPTK_IS_BASE_OF:
14055 486097 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14056 954143 : && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
14057 442793 : || DERIVED_FROM_P (type1, type2)));
14058 :
14059 42641 : case CPTK_IS_BOUNDED_ARRAY:
14060 42641 : return (type_code1 == ARRAY_TYPE
14061 1252 : && TYPE_DOMAIN (type1)
14062 : /* We don't want to report T[0] as being a bounded array type.
14063 : This is for compatibility with an implementation of
14064 : std::is_bounded_array by template argument deduction, because
14065 : compute_array_index_type_loc rejects a zero-size array
14066 : in SFINAE context. */
14067 43777 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14068 :
14069 499601 : case CPTK_IS_CLASS:
14070 499601 : return NON_UNION_CLASS_TYPE_P (type1);
14071 :
14072 577987 : case CPTK_IS_CONST:
14073 577987 : return CP_TYPE_CONST_P (type1);
14074 :
14075 2280820 : case CPTK_IS_CONSTRUCTIBLE:
14076 2280820 : return is_xible (INIT_EXPR, type1, type2);
14077 :
14078 3058447 : case CPTK_IS_CONVERTIBLE:
14079 3058447 : return is_convertible (type1, type2);
14080 :
14081 1960 : case CPTK_IS_DESTRUCTIBLE:
14082 1960 : return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14083 :
14084 209692 : case CPTK_IS_EMPTY:
14085 209692 : return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
14086 :
14087 625052 : case CPTK_IS_ENUM:
14088 625052 : return type_code1 == ENUMERAL_TYPE;
14089 :
14090 414506 : case CPTK_IS_FINAL:
14091 414506 : return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
14092 :
14093 45040 : case CPTK_IS_FUNCTION:
14094 45040 : return type_code1 == FUNCTION_TYPE;
14095 :
14096 800 : case CPTK_IS_IMPLICIT_LIFETIME:
14097 800 : return implicit_lifetime_type_p (type1);
14098 :
14099 46205 : case CPTK_IS_INVOCABLE:
14100 46205 : return !error_operand_p (build_invoke (type1, type2, tf_none));
14101 :
14102 195 : case CPTK_IS_LAYOUT_COMPATIBLE:
14103 195 : return layout_compatible_type_p (type1, type2);
14104 :
14105 197 : case CPTK_IS_LITERAL_TYPE:
14106 197 : return literal_type_p (type1);
14107 :
14108 46330 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14109 46330 : return TYPE_PTRMEMFUNC_P (type1);
14110 :
14111 46299 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14112 46299 : return TYPE_PTRDATAMEM_P (type1);
14113 :
14114 10296 : case CPTK_IS_MEMBER_POINTER:
14115 10296 : return TYPE_PTRMEM_P (type1);
14116 :
14117 440661 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14118 440661 : return is_nothrow_xible (MODIFY_EXPR, type1, type2);
14119 :
14120 885007 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14121 885007 : return is_nothrow_xible (INIT_EXPR, type1, type2);
14122 :
14123 667 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14124 667 : return is_nothrow_convertible (type1, type2);
14125 :
14126 23239 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14127 23239 : return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14128 :
14129 40594 : case CPTK_IS_NOTHROW_INVOCABLE:
14130 40594 : return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
14131 :
14132 1091162 : case CPTK_IS_OBJECT:
14133 1091162 : return object_type_p (type1);
14134 :
14135 142 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14136 142 : return pointer_interconvertible_base_of_p (type1, type2);
14137 :
14138 11051 : case CPTK_IS_POD:
14139 11051 : return pod_type_p (type1);
14140 :
14141 144875 : case CPTK_IS_POINTER:
14142 144875 : return TYPE_PTR_P (type1);
14143 :
14144 271 : case CPTK_IS_POLYMORPHIC:
14145 271 : return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
14146 :
14147 708786 : case CPTK_IS_REFERENCE:
14148 708786 : return type_code1 == REFERENCE_TYPE;
14149 :
14150 2487632 : case CPTK_IS_SAME:
14151 2487632 : return same_type_p (type1, type2);
14152 :
14153 373 : case CPTK_IS_SCOPED_ENUM:
14154 373 : return SCOPED_ENUM_P (type1);
14155 :
14156 58776 : case CPTK_IS_STD_LAYOUT:
14157 58776 : return std_layout_type_p (type1);
14158 :
14159 55211 : case CPTK_IS_TRIVIAL:
14160 55211 : return trivial_type_p (type1);
14161 :
14162 10176 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14163 10176 : return is_trivially_xible (MODIFY_EXPR, type1, type2);
14164 :
14165 67923 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14166 67923 : return is_trivially_xible (INIT_EXPR, type1, type2);
14167 :
14168 93338 : case CPTK_IS_TRIVIALLY_COPYABLE:
14169 93338 : return trivially_copyable_p (type1);
14170 :
14171 24804 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14172 24804 : return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14173 :
14174 91943 : case CPTK_IS_UNBOUNDED_ARRAY:
14175 91943 : return array_of_unknown_bound_p (type1);
14176 :
14177 253269 : case CPTK_IS_UNION:
14178 253269 : return type_code1 == UNION_TYPE;
14179 :
14180 712 : case CPTK_IS_VIRTUAL_BASE_OF:
14181 646 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14182 1342 : && lookup_base (type2, type1, ba_require_virtual,
14183 : NULL, tf_none) != NULL_TREE);
14184 :
14185 602872 : case CPTK_IS_VOLATILE:
14186 602872 : return CP_TYPE_VOLATILE_P (type1);
14187 :
14188 210608 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14189 210608 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
14190 :
14191 51912 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14192 51912 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
14193 :
14194 85 : case CPTK_IS_DEDUCIBLE:
14195 85 : return type_targs_deducible_from (type1, type2);
14196 :
14197 131 : case CPTK_IS_STRUCTURAL:
14198 131 : return structural_type_p (type1);
14199 :
14200 : /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
14201 : are handled in finish_trait_expr. */
14202 0 : case CPTK_RANK:
14203 0 : case CPTK_TYPE_ORDER:
14204 0 : case CPTK_STRUCTURED_BINDING_SIZE:
14205 0 : gcc_unreachable ();
14206 :
14207 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14208 : case CPTK_##CODE:
14209 : #include "cp-trait.def"
14210 : #undef DEFTRAIT_TYPE
14211 : /* Type-yielding traits are handled in finish_trait_type. */
14212 : break;
14213 : }
14214 :
14215 0 : gcc_unreachable ();
14216 : }
14217 :
14218 : /* Returns true if TYPE meets the requirements for the specified KIND,
14219 : false otherwise.
14220 :
14221 : When KIND == 1, TYPE must be an array of unknown bound,
14222 : or (possibly cv-qualified) void, or a complete type.
14223 :
14224 : When KIND == 2, TYPE must be a complete type, or array of complete type,
14225 : or (possibly cv-qualified) void.
14226 :
14227 : When KIND == 3:
14228 : If TYPE is a non-union class type, it must be complete.
14229 :
14230 : When KIND == 4:
14231 : If TYPE is a class type, it must be complete. */
14232 :
14233 : static bool
14234 18071367 : check_trait_type (tree type, int kind = 1)
14235 : {
14236 18071367 : if (type == NULL_TREE)
14237 : return true;
14238 :
14239 18071367 : if (TREE_CODE (type) == TREE_VEC)
14240 : {
14241 5902571 : for (tree arg : tree_vec_range (type))
14242 2585943 : if (!check_trait_type (arg, kind))
14243 21 : return false;
14244 3316628 : return true;
14245 : }
14246 :
14247 14754718 : if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
14248 : return true; // Array of unknown bound. Don't care about completeness.
14249 :
14250 14754174 : if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
14251 : return true; // Not a non-union class type. Don't care about completeness.
14252 :
14253 14643060 : if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
14254 : return true; // Not a class type. Don't care about completeness.
14255 :
14256 14642575 : if (VOID_TYPE_P (type))
14257 : return true;
14258 :
14259 14641475 : type = complete_type (strip_array_types (type));
14260 14641475 : if (!COMPLETE_TYPE_P (type)
14261 152 : && cxx_incomplete_type_diagnostic (NULL_TREE, type,
14262 : diagnostics::kind::permerror)
14263 14641627 : && !flag_permissive)
14264 : return false;
14265 : return true;
14266 : }
14267 :
14268 : /* True iff the conversion (if any) would be a direct reference
14269 : binding, not requiring complete types. This is LWG2939. */
14270 :
14271 : static bool
14272 6642243 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
14273 : {
14274 6642243 : tree from, to;
14275 6642243 : switch (kind)
14276 : {
14277 : /* These put the target type first. */
14278 : case CPTK_IS_CONSTRUCTIBLE:
14279 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14280 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14281 : case CPTK_IS_INVOCABLE:
14282 : case CPTK_IS_NOTHROW_INVOCABLE:
14283 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14284 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14285 : to = type1;
14286 : from = type2;
14287 : break;
14288 :
14289 : /* These put it second. */
14290 3059114 : case CPTK_IS_CONVERTIBLE:
14291 3059114 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14292 3059114 : to = type2;
14293 3059114 : from = type1;
14294 3059114 : break;
14295 :
14296 0 : default:
14297 0 : gcc_unreachable ();
14298 : }
14299 :
14300 6642243 : if (TREE_CODE (to) != REFERENCE_TYPE || !from)
14301 : return false;
14302 905176 : if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
14303 58980 : from = TREE_VEC_ELT (from, 0);
14304 905176 : return (TYPE_P (from)
14305 1802413 : && (same_type_ignoring_top_level_qualifiers_p
14306 897237 : (non_reference (to), non_reference (from))));
14307 : }
14308 :
14309 : /* Helper for finish_trait_expr and tsubst_expr. Handle
14310 : CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
14311 : way. */
14312 :
14313 : tree
14314 273 : finish_structured_binding_size (location_t loc, tree type,
14315 : tsubst_flags_t complain)
14316 : {
14317 273 : if (TYPE_REF_P (type))
14318 : {
14319 105 : if (complain & tf_error)
14320 99 : error_at (loc, "%qs argument %qT is a reference",
14321 : "__builtin_structured_binding_size", type);
14322 105 : return error_mark_node;
14323 : }
14324 168 : HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
14325 168 : if (ret == -1)
14326 63 : return error_mark_node;
14327 105 : return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
14328 : }
14329 :
14330 : /* Process a trait expression. */
14331 :
14332 : tree
14333 20357078 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
14334 : {
14335 20357078 : if (type1 == error_mark_node
14336 20357075 : || type2 == error_mark_node)
14337 : return error_mark_node;
14338 :
14339 20357075 : if (processing_template_decl)
14340 : {
14341 3174685 : tree trait_expr = make_node (TRAIT_EXPR);
14342 3174685 : if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
14343 29676 : TREE_TYPE (trait_expr) = size_type_node;
14344 3145009 : else if (kind == CPTK_TYPE_ORDER)
14345 : {
14346 2992 : tree val = type_order_value (type1, type1);
14347 2992 : if (val != error_mark_node)
14348 2992 : TREE_TYPE (trait_expr) = TREE_TYPE (val);
14349 : }
14350 : else
14351 3142017 : TREE_TYPE (trait_expr) = boolean_type_node;
14352 3174685 : TRAIT_EXPR_TYPE1 (trait_expr) = type1;
14353 3174685 : TRAIT_EXPR_TYPE2 (trait_expr) = type2;
14354 3174685 : TRAIT_EXPR_KIND (trait_expr) = kind;
14355 3174685 : TRAIT_EXPR_LOCATION (trait_expr) = loc;
14356 3174685 : return trait_expr;
14357 : }
14358 :
14359 17182390 : switch (kind)
14360 : {
14361 52366 : case CPTK_HAS_NOTHROW_ASSIGN:
14362 52366 : case CPTK_HAS_TRIVIAL_ASSIGN:
14363 52366 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
14364 52366 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14365 52366 : case CPTK_HAS_NOTHROW_COPY:
14366 52366 : case CPTK_HAS_TRIVIAL_COPY:
14367 52366 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14368 52366 : case CPTK_IS_DESTRUCTIBLE:
14369 52366 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14370 52366 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14371 52366 : if (!check_trait_type (type1))
14372 21 : return error_mark_node;
14373 : break;
14374 :
14375 276610 : case CPTK_IS_LITERAL_TYPE:
14376 276610 : case CPTK_IS_POD:
14377 276610 : case CPTK_IS_STD_LAYOUT:
14378 276610 : case CPTK_IS_TRIVIAL:
14379 276610 : case CPTK_IS_TRIVIALLY_COPYABLE:
14380 276610 : case CPTK_IS_STRUCTURAL:
14381 276610 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14382 276610 : if (!check_trait_type (type1, /* kind = */ 2))
14383 33 : return error_mark_node;
14384 : break;
14385 :
14386 264777 : case CPTK_IS_ABSTRACT:
14387 264777 : case CPTK_IS_EMPTY:
14388 264777 : case CPTK_IS_POLYMORPHIC:
14389 264777 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14390 264777 : if (!check_trait_type (type1, /* kind = */ 3))
14391 15 : return error_mark_node;
14392 : break;
14393 :
14394 : /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
14395 : type to know whether an array is an aggregate, so use kind=4 here. */
14396 416136 : case CPTK_IS_AGGREGATE:
14397 416136 : case CPTK_IS_FINAL:
14398 416136 : case CPTK_IS_IMPLICIT_LIFETIME:
14399 416136 : if (!check_trait_type (type1, /* kind = */ 4))
14400 17 : return error_mark_node;
14401 : break;
14402 :
14403 6642243 : case CPTK_IS_CONSTRUCTIBLE:
14404 6642243 : case CPTK_IS_CONVERTIBLE:
14405 6642243 : case CPTK_IS_INVOCABLE:
14406 6642243 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14407 6642243 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14408 6642243 : case CPTK_IS_NOTHROW_INVOCABLE:
14409 6642243 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14410 6642243 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14411 6642243 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14412 6642243 : /* Don't check completeness for direct reference binding. */;
14413 6642243 : if (same_type_ref_bind_p (kind, type1, type2))
14414 : break;
14415 7237787 : gcc_fallthrough ();
14416 :
14417 7237787 : case CPTK_IS_ASSIGNABLE:
14418 7237787 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14419 7237787 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14420 7237787 : if (!check_trait_type (type1)
14421 7237787 : || !check_trait_type (type2))
14422 63 : return error_mark_node;
14423 : break;
14424 :
14425 486333 : case CPTK_IS_BASE_OF:
14426 486333 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14427 486230 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14428 468085 : && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
14429 929226 : && !complete_type_or_else (type2, NULL_TREE))
14430 : /* We already issued an error. */
14431 3 : return error_mark_node;
14432 : break;
14433 :
14434 715 : case CPTK_IS_VIRTUAL_BASE_OF:
14435 649 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14436 1348 : && !complete_type_or_else (type2, NULL_TREE))
14437 : /* We already issued an error. */
14438 3 : return error_mark_node;
14439 : break;
14440 :
14441 : case CPTK_IS_ARRAY:
14442 : case CPTK_IS_BOUNDED_ARRAY:
14443 : case CPTK_IS_CLASS:
14444 : case CPTK_IS_CONST:
14445 : case CPTK_IS_ENUM:
14446 : case CPTK_IS_FUNCTION:
14447 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14448 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14449 : case CPTK_IS_MEMBER_POINTER:
14450 : case CPTK_IS_OBJECT:
14451 : case CPTK_IS_POINTER:
14452 : case CPTK_IS_REFERENCE:
14453 : case CPTK_IS_SAME:
14454 : case CPTK_IS_SCOPED_ENUM:
14455 : case CPTK_IS_UNBOUNDED_ARRAY:
14456 : case CPTK_IS_UNION:
14457 : case CPTK_IS_VOLATILE:
14458 : break;
14459 :
14460 : case CPTK_RANK:
14461 : {
14462 : size_t rank = 0;
14463 122 : for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
14464 80 : ++rank;
14465 42 : return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
14466 : loc);
14467 : }
14468 :
14469 230 : case CPTK_TYPE_ORDER:
14470 230 : return maybe_wrap_with_location (type_order_value (type1, type2), loc);
14471 :
14472 144 : case CPTK_STRUCTURED_BINDING_SIZE:
14473 144 : return finish_structured_binding_size (loc, type1, tf_warning_or_error);
14474 :
14475 204 : case CPTK_IS_LAYOUT_COMPATIBLE:
14476 204 : if (!array_of_unknown_bound_p (type1)
14477 189 : && TREE_CODE (type1) != VOID_TYPE
14478 387 : && !complete_type_or_else (type1, NULL_TREE))
14479 : /* We already issued an error. */
14480 6 : return error_mark_node;
14481 198 : if (!array_of_unknown_bound_p (type2)
14482 177 : && TREE_CODE (type2) != VOID_TYPE
14483 369 : && !complete_type_or_else (type2, NULL_TREE))
14484 : /* We already issued an error. */
14485 3 : return error_mark_node;
14486 : break;
14487 :
14488 85 : case CPTK_IS_DEDUCIBLE:
14489 85 : if (!DECL_TYPE_TEMPLATE_P (type1))
14490 : {
14491 0 : error ("%qD is not a class or alias template", type1);
14492 0 : return error_mark_node;
14493 : }
14494 : break;
14495 :
14496 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14497 : case CPTK_##CODE:
14498 : #include "cp-trait.def"
14499 : #undef DEFTRAIT_TYPE
14500 : /* Type-yielding traits are handled in finish_trait_type. */
14501 0 : gcc_unreachable ();
14502 : }
14503 :
14504 17181810 : tree val = (trait_expr_value (kind, type1, type2)
14505 17181810 : ? boolean_true_node : boolean_false_node);
14506 17181810 : return maybe_wrap_with_location (val, loc);
14507 : }
14508 :
14509 : /* Process a trait type. */
14510 :
14511 : tree
14512 7620669 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
14513 : tsubst_flags_t complain)
14514 : {
14515 7620669 : if (type1 == error_mark_node
14516 7620666 : || type2 == error_mark_node)
14517 : return error_mark_node;
14518 :
14519 7620666 : if (processing_template_decl)
14520 : {
14521 217502 : tree type = cxx_make_type (TRAIT_TYPE);
14522 217502 : TRAIT_TYPE_TYPE1 (type) = type1;
14523 217502 : TRAIT_TYPE_TYPE2 (type) = type2;
14524 217502 : TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
14525 : /* These traits are intended to be used in the definition of the ::type
14526 : member of the corresponding standard library type trait and aren't
14527 : mangleable (and thus won't appear directly in template signatures),
14528 : so structural equality should suffice. */
14529 217502 : SET_TYPE_STRUCTURAL_EQUALITY (type);
14530 217502 : return type;
14531 : }
14532 :
14533 7403164 : switch (kind)
14534 : {
14535 1189125 : case CPTK_ADD_LVALUE_REFERENCE:
14536 : /* [meta.trans.ref]. */
14537 1189125 : if (referenceable_type_p (type1))
14538 1189049 : return cp_build_reference_type (type1, /*rval=*/false);
14539 : return type1;
14540 :
14541 638716 : case CPTK_ADD_POINTER:
14542 : /* [meta.trans.ptr]. */
14543 638716 : if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
14544 : {
14545 638684 : if (TYPE_REF_P (type1))
14546 637623 : type1 = TREE_TYPE (type1);
14547 638684 : return build_pointer_type (type1);
14548 : }
14549 : return type1;
14550 :
14551 1617823 : case CPTK_ADD_RVALUE_REFERENCE:
14552 : /* [meta.trans.ref]. */
14553 1617823 : if (referenceable_type_p (type1))
14554 1617770 : return cp_build_reference_type (type1, /*rval=*/true);
14555 : return type1;
14556 :
14557 221870 : case CPTK_DECAY:
14558 221870 : if (TYPE_REF_P (type1))
14559 41119 : type1 = TREE_TYPE (type1);
14560 :
14561 221870 : if (TREE_CODE (type1) == ARRAY_TYPE)
14562 671 : return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
14563 671 : complain);
14564 221199 : else if (TREE_CODE (type1) == FUNCTION_TYPE)
14565 177 : return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
14566 : else
14567 221022 : return cv_unqualified (type1);
14568 :
14569 219 : case CPTK_REMOVE_ALL_EXTENTS:
14570 219 : return strip_array_types (type1);
14571 :
14572 943477 : case CPTK_REMOVE_CV:
14573 943477 : return cv_unqualified (type1);
14574 :
14575 430075 : case CPTK_REMOVE_CVREF:
14576 430075 : if (TYPE_REF_P (type1))
14577 161236 : type1 = TREE_TYPE (type1);
14578 430075 : return cv_unqualified (type1);
14579 :
14580 64288 : case CPTK_REMOVE_EXTENT:
14581 64288 : if (TREE_CODE (type1) == ARRAY_TYPE)
14582 9141 : type1 = TREE_TYPE (type1);
14583 : return type1;
14584 :
14585 42160 : case CPTK_REMOVE_POINTER:
14586 42160 : if (TYPE_PTR_P (type1))
14587 39447 : type1 = TREE_TYPE (type1);
14588 : return type1;
14589 :
14590 2101803 : case CPTK_REMOVE_REFERENCE:
14591 2101803 : if (TYPE_REF_P (type1))
14592 1267960 : type1 = TREE_TYPE (type1);
14593 : return type1;
14594 :
14595 107024 : case CPTK_TYPE_PACK_ELEMENT:
14596 107024 : return finish_type_pack_element (type1, type2, complain);
14597 :
14598 46584 : case CPTK_UNDERLYING_TYPE:
14599 46584 : return finish_underlying_type (type1);
14600 :
14601 : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
14602 : case CPTK_##CODE:
14603 : #include "cp-trait.def"
14604 : #undef DEFTRAIT_EXPR
14605 : /* Expression-yielding traits are handled in finish_trait_expr. */
14606 : case CPTK_BASES:
14607 : case CPTK_DIRECT_BASES:
14608 : /* BASES and DIRECT_BASES are handled in finish_bases. */
14609 : break;
14610 : }
14611 :
14612 0 : gcc_unreachable ();
14613 : }
14614 :
14615 : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
14616 : which is ignored for C++. */
14617 :
14618 : void
14619 0 : set_float_const_decimal64 (void)
14620 : {
14621 0 : }
14622 :
14623 : void
14624 0 : clear_float_const_decimal64 (void)
14625 : {
14626 0 : }
14627 :
14628 : bool
14629 1883409 : float_const_decimal64_p (void)
14630 : {
14631 1883409 : return 0;
14632 : }
14633 :
14634 :
14635 : /* Return true if T designates the implied `this' parameter. */
14636 :
14637 : bool
14638 5987798 : is_this_parameter (tree t)
14639 : {
14640 5987798 : if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
14641 : return false;
14642 3553572 : gcc_assert (TREE_CODE (t) == PARM_DECL
14643 : || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
14644 : || (cp_binding_oracle && VAR_P (t)));
14645 : return true;
14646 : }
14647 :
14648 : /* As above, or a C++23 explicit object parameter. */
14649 :
14650 : bool
14651 456 : is_object_parameter (tree t)
14652 : {
14653 456 : if (is_this_parameter (t))
14654 : return true;
14655 91 : if (TREE_CODE (t) != PARM_DECL)
14656 : return false;
14657 34 : tree ctx = DECL_CONTEXT (t);
14658 34 : return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
14659 62 : && t == DECL_ARGUMENTS (ctx));
14660 : }
14661 :
14662 : /* Insert the deduced return type for an auto function. */
14663 :
14664 : void
14665 897950 : apply_deduced_return_type (tree fco, tree return_type)
14666 : {
14667 897950 : tree result;
14668 :
14669 897950 : if (return_type == error_mark_node)
14670 : return;
14671 :
14672 897947 : if (DECL_CONV_FN_P (fco))
14673 42 : DECL_NAME (fco) = make_conv_op_name (return_type);
14674 :
14675 897947 : TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
14676 :
14677 897947 : maybe_update_postconditions (fco);
14678 :
14679 : /* Apply the type to the result object. */
14680 :
14681 897947 : result = DECL_RESULT (fco);
14682 897947 : if (result == NULL_TREE)
14683 : return;
14684 887083 : if (TREE_TYPE (result) == return_type)
14685 : return;
14686 :
14687 887077 : if (!processing_template_decl && !VOID_TYPE_P (return_type)
14688 1644583 : && !complete_type_or_else (return_type, NULL_TREE))
14689 : return;
14690 :
14691 : /* We already have a DECL_RESULT from start_preparsed_function.
14692 : Now we need to redo the work it and allocate_struct_function
14693 : did to reflect the new type. */
14694 887080 : result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
14695 887080 : TYPE_MAIN_VARIANT (return_type));
14696 887080 : DECL_ARTIFICIAL (result) = 1;
14697 887080 : DECL_IGNORED_P (result) = 1;
14698 887080 : cp_apply_type_quals_to_decl (cp_type_quals (return_type),
14699 : result);
14700 887080 : DECL_RESULT (fco) = result;
14701 :
14702 887080 : if (!uses_template_parms (fco))
14703 887080 : if (function *fun = DECL_STRUCT_FUNCTION (fco))
14704 : {
14705 886551 : bool aggr = aggregate_value_p (result, fco);
14706 : #ifdef PCC_STATIC_STRUCT_RETURN
14707 : fun->returns_pcc_struct = aggr;
14708 : #endif
14709 886551 : fun->returns_struct = aggr;
14710 : }
14711 : }
14712 :
14713 : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
14714 : this is a right unary fold. Otherwise it is a left unary fold. */
14715 :
14716 : static tree
14717 763340 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
14718 : {
14719 : /* Build a pack expansion (assuming expr has pack type). */
14720 763340 : if (!uses_parameter_packs (expr))
14721 : {
14722 3 : error_at (location_of (expr), "operand of fold expression has no "
14723 : "unexpanded parameter packs");
14724 3 : return error_mark_node;
14725 : }
14726 763337 : tree pack = make_pack_expansion (expr);
14727 :
14728 : /* Build the fold expression. */
14729 763337 : tree code = build_int_cstu (integer_type_node, abs (op));
14730 763337 : tree fold = build_min_nt_loc (loc, dir, code, pack);
14731 763337 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14732 763337 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14733 763337 : FOLD_EXPR_OP (fold),
14734 763337 : FOLD_EXPR_MODIFY_P (fold));
14735 763337 : return fold;
14736 : }
14737 :
14738 : tree
14739 18040 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
14740 : {
14741 18040 : return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
14742 : }
14743 :
14744 : tree
14745 745300 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
14746 : {
14747 745300 : return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
14748 : }
14749 :
14750 : /* Build a binary fold expression over EXPR1 and EXPR2. The
14751 : associativity of the fold is determined by EXPR1 and EXPR2 (whichever
14752 : has an unexpanded parameter pack). */
14753 :
14754 : static tree
14755 185614 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
14756 : int op, tree_code dir)
14757 : {
14758 185614 : pack = make_pack_expansion (pack);
14759 185614 : tree code = build_int_cstu (integer_type_node, abs (op));
14760 185614 : tree fold = build_min_nt_loc (loc, dir, code, pack, init);
14761 185614 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14762 185614 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14763 185614 : FOLD_EXPR_OP (fold),
14764 185614 : FOLD_EXPR_MODIFY_P (fold));
14765 185614 : return fold;
14766 : }
14767 :
14768 : tree
14769 185614 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
14770 : {
14771 : // Determine which expr has an unexpanded parameter pack and
14772 : // set the pack and initial term.
14773 185614 : bool pack1 = uses_parameter_packs (expr1);
14774 185614 : bool pack2 = uses_parameter_packs (expr2);
14775 185614 : if (pack1 && !pack2)
14776 801 : return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
14777 184813 : else if (pack2 && !pack1)
14778 184813 : return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
14779 : else
14780 : {
14781 0 : if (pack1)
14782 0 : error ("both arguments in binary fold have unexpanded parameter packs");
14783 : else
14784 0 : error ("no unexpanded parameter packs in binary fold");
14785 : }
14786 0 : return error_mark_node;
14787 : }
14788 :
14789 : /* Finish __builtin_launder (arg). */
14790 :
14791 : tree
14792 13058 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
14793 : {
14794 13058 : tree orig_arg = arg;
14795 13058 : if (!type_dependent_expression_p (arg))
14796 84 : arg = decay_conversion (arg, complain);
14797 13058 : if (error_operand_p (arg))
14798 0 : return error_mark_node;
14799 13058 : if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
14800 : {
14801 24 : error_at (loc, "type %qT of argument to %<__builtin_launder%> "
14802 24 : "is not a pointer to object type", TREE_TYPE (arg));
14803 24 : return error_mark_node;
14804 : }
14805 13034 : if (processing_template_decl)
14806 12974 : arg = orig_arg;
14807 13034 : return build_call_expr_internal_loc (loc, IFN_LAUNDER,
14808 26068 : TREE_TYPE (arg), 1, arg);
14809 : }
14810 :
14811 : /* Finish __builtin_convertvector (arg, type). */
14812 :
14813 : tree
14814 312 : cp_build_vec_convert (tree arg, location_t loc, tree type,
14815 : tsubst_flags_t complain)
14816 : {
14817 312 : if (error_operand_p (type))
14818 9 : return error_mark_node;
14819 303 : if (error_operand_p (arg))
14820 0 : return error_mark_node;
14821 :
14822 303 : tree ret = NULL_TREE;
14823 303 : if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
14824 295 : ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
14825 : decay_conversion (arg, complain),
14826 : loc, type, (complain & tf_error) != 0);
14827 :
14828 303 : if (!processing_template_decl)
14829 : return ret;
14830 :
14831 50 : return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
14832 : }
14833 :
14834 : /* Finish __builtin_bit_cast (type, arg). */
14835 :
14836 : tree
14837 275923 : cp_build_bit_cast (location_t loc, tree type, tree arg,
14838 : tsubst_flags_t complain)
14839 : {
14840 275923 : if (error_operand_p (type))
14841 0 : return error_mark_node;
14842 275923 : if (!dependent_type_p (type))
14843 : {
14844 200465 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
14845 9 : return error_mark_node;
14846 200456 : if (TREE_CODE (type) == ARRAY_TYPE)
14847 : {
14848 : /* std::bit_cast for destination ARRAY_TYPE is not possible,
14849 : as functions may not return an array, so don't bother trying
14850 : to support this (and then deal with VLAs etc.). */
14851 9 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14852 : "is an array type", type);
14853 9 : return error_mark_node;
14854 : }
14855 200447 : if (!trivially_copyable_p (type))
14856 : {
14857 18 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14858 : "is not trivially copyable", type);
14859 18 : return error_mark_node;
14860 : }
14861 200429 : if (consteval_only_p (type) || consteval_only_p (arg))
14862 : {
14863 4 : error_at (loc, "%<__builtin_bit_cast%> cannot be used with "
14864 : "consteval-only types");
14865 4 : return error_mark_node;
14866 : }
14867 : }
14868 :
14869 275883 : if (error_operand_p (arg))
14870 0 : return error_mark_node;
14871 :
14872 275883 : if (!type_dependent_expression_p (arg))
14873 : {
14874 109976 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
14875 : {
14876 : /* Don't perform array-to-pointer conversion. */
14877 39 : arg = mark_rvalue_use (arg, loc, true);
14878 39 : if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
14879 0 : return error_mark_node;
14880 : }
14881 : else
14882 109937 : arg = decay_conversion (arg, complain);
14883 :
14884 109976 : if (error_operand_p (arg))
14885 12 : return error_mark_node;
14886 :
14887 109964 : if (!trivially_copyable_p (TREE_TYPE (arg)))
14888 : {
14889 9 : error_at (cp_expr_loc_or_loc (arg, loc),
14890 : "%<__builtin_bit_cast%> source type %qT "
14891 9 : "is not trivially copyable", TREE_TYPE (arg));
14892 9 : return error_mark_node;
14893 : }
14894 109955 : if (!dependent_type_p (type)
14895 183069 : && !cp_tree_equal (TYPE_SIZE_UNIT (type),
14896 73114 : TYPE_SIZE_UNIT (TREE_TYPE (arg))))
14897 : {
14898 18 : error_at (loc, "%<__builtin_bit_cast%> source size %qE "
14899 : "not equal to destination type size %qE",
14900 18 : TYPE_SIZE_UNIT (TREE_TYPE (arg)),
14901 18 : TYPE_SIZE_UNIT (type));
14902 18 : return error_mark_node;
14903 : }
14904 : }
14905 :
14906 275844 : tree ret = build_min (BIT_CAST_EXPR, type, arg);
14907 275844 : SET_EXPR_LOCATION (ret, loc);
14908 :
14909 275844 : if (!processing_template_decl && CLASS_TYPE_P (type))
14910 300 : ret = get_target_expr (ret, complain);
14911 :
14912 : return ret;
14913 : }
14914 :
14915 : /* Diagnose invalid #pragma GCC unroll argument and adjust
14916 : it if needed. */
14917 :
14918 : tree
14919 23026 : cp_check_pragma_unroll (location_t loc, tree unroll)
14920 : {
14921 23026 : HOST_WIDE_INT lunroll = 0;
14922 23026 : if (type_dependent_expression_p (unroll))
14923 : ;
14924 45980 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
14925 45934 : || (!value_dependent_expression_p (unroll)
14926 22914 : && (!tree_fits_shwi_p (unroll)
14927 22888 : || (lunroll = tree_to_shwi (unroll)) < 0
14928 22873 : || lunroll >= USHRT_MAX)))
14929 : {
14930 90 : error_at (loc, "%<#pragma GCC unroll%> requires an"
14931 : " assignment-expression that evaluates to a non-negative"
14932 : " integral constant less than %u", USHRT_MAX);
14933 90 : unroll = integer_one_node;
14934 : }
14935 22900 : else if (TREE_CODE (unroll) == INTEGER_CST)
14936 : {
14937 22870 : unroll = fold_convert (integer_type_node, unroll);
14938 22870 : if (integer_zerop (unroll))
14939 12 : unroll = integer_one_node;
14940 : }
14941 23026 : return unroll;
14942 : }
14943 :
14944 : #include "gt-cp-semantics.h"
|