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 "attribs.h"
44 : #include "gomp-constants.h"
45 : #include "predict.h"
46 : #include "memmodel.h"
47 : #include "gimplify.h"
48 : #include "contracts.h"
49 : #include "c-family/c-pragma.h"
50 : #include "gcc-rich-location.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 24232160652 : push_deferring_access_checks (deferring_kind deferring)
146 : {
147 : /* For context like template instantiation, access checking
148 : disabling applies to all nested context. */
149 24232160652 : if (deferred_access_no_check || deferring == dk_no_check)
150 311410142 : deferred_access_no_check++;
151 : else
152 : {
153 23920750510 : deferred_access e = {NULL, deferring};
154 23920750510 : vec_safe_push (deferred_access_stack, e);
155 : }
156 24232160652 : }
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 390176294 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
163 : {
164 390176294 : push_deferring_access_checks (dk_deferred);
165 390176294 : if (!deferred_access_no_check)
166 382463128 : deferred_access_stack->last().deferred_access_checks = checks;
167 390176294 : }
168 :
169 : /* Resume deferring access checks again after we stopped doing
170 : this previously. */
171 :
172 : void
173 184822193 : resume_deferring_access_checks (void)
174 : {
175 184822193 : if (!deferred_access_no_check)
176 184795456 : deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
177 184822193 : }
178 :
179 : /* Stop deferring access checks. */
180 :
181 : void
182 518151435 : stop_deferring_access_checks (void)
183 : {
184 518151435 : if (!deferred_access_no_check)
185 518073783 : deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
186 518151435 : }
187 :
188 : /* Discard the current deferred access checks and restore the
189 : previous states. */
190 :
191 : void
192 15027860650 : pop_deferring_access_checks (void)
193 : {
194 15027860650 : if (deferred_access_no_check)
195 239005597 : deferred_access_no_check--;
196 : else
197 14788855053 : deferred_access_stack->pop ();
198 15027860650 : }
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 1297871460 : get_deferred_access_checks (void)
207 : {
208 1297871460 : if (deferred_access_no_check)
209 : return NULL;
210 : else
211 1281971866 : 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 9204162375 : pop_to_parent_deferring_access_checks (void)
220 : {
221 9204162375 : if (deferred_access_no_check)
222 72404537 : deferred_access_no_check--;
223 : else
224 : {
225 9131757838 : vec<deferred_access_check, va_gc> *checks;
226 9131757838 : deferred_access *ptr;
227 :
228 9131757838 : checks = (deferred_access_stack->last ().deferred_access_checks);
229 :
230 9131757838 : deferred_access_stack->pop ();
231 9131757838 : ptr = &deferred_access_stack->last ();
232 9131757838 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
233 : {
234 : /* Check access. */
235 575382134 : 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 8759921444 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
244 : {
245 110577859 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
246 : {
247 9792974 : if (probe->binfo == chk->binfo &&
248 7775255 : probe->decl == chk->decl &&
249 988925 : probe->diag_decl == chk->diag_decl)
250 987985 : goto found;
251 : }
252 : /* Insert into parent's checks. */
253 100784885 : vec_safe_push (ptr->deferred_access_checks, *chk);
254 101772870 : found:;
255 : }
256 : }
257 : }
258 9204162375 : }
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 421756036 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
334 : tsubst_flags_t complain, access_failure_info *afi = NULL)
335 : {
336 421756036 : gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
337 :
338 421756036 : if (flag_new_inheriting_ctors
339 533143084 : && 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 62991 : decl = strip_inheriting_ctors (decl);
345 62991 : basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
346 : ba_any, NULL, complain);
347 : }
348 :
349 421756036 : tree cs = current_scope ();
350 421756036 : if (in_template_context
351 421756036 : && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
352 41912508 : 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 41667980 : 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 380088056 : if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
382 : {
383 22185 : if (flag_new_inheriting_ctors)
384 22155 : diag_decl = strip_inheriting_ctors (diag_decl);
385 22185 : if (complain & tf_error)
386 : {
387 1159 : access_kind access_failure_reason = ak_none;
388 :
389 : /* By default, using the decl as the source of the problem will
390 : usually give correct results. */
391 1159 : tree diag_location = diag_decl;
392 :
393 : /* However, if a parent of BASETYPE_PATH had private access to decl,
394 : then it actually might be the case that the source of the problem
395 : is not DECL. */
396 1159 : tree parent_binfo = get_parent_with_private_access (decl,
397 : basetype_path);
398 :
399 : /* So if a parent did have private access, then we need to do
400 : special checks to obtain the best diagnostic location decl. */
401 1159 : if (parent_binfo != NULL_TREE)
402 : {
403 182 : diag_location = get_class_access_diagnostic_decl (parent_binfo,
404 : diag_decl);
405 :
406 : /* We also at this point know that the reason access failed was
407 : because decl was private. */
408 182 : access_failure_reason = ak_private;
409 : }
410 :
411 : /* Finally, generate an error message. */
412 1159 : complain_about_access (decl, diag_decl, diag_location, true,
413 : access_failure_reason);
414 : }
415 22185 : if (afi)
416 412 : afi->record_access_failure (basetype_path, decl, diag_decl);
417 : return false;
418 : }
419 :
420 : return true;
421 : }
422 :
423 : /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
424 : is the BINFO indicating the qualifying scope used to access the
425 : DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
426 : or we aren't in SFINAE context or all the checks succeed return TRUE,
427 : otherwise FALSE. */
428 :
429 : bool
430 1103879735 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
431 : tsubst_flags_t complain)
432 : {
433 1103879735 : int i;
434 1103879735 : deferred_access_check *chk;
435 1103879735 : location_t loc = input_location;
436 1103879735 : bool ok = true;
437 :
438 1103879735 : if (!checks)
439 : return true;
440 :
441 127936787 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
442 : {
443 71238135 : input_location = chk->loc;
444 71238135 : ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
445 : }
446 :
447 56698652 : input_location = loc;
448 56698652 : 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 288451363 : perform_deferred_access_checks (tsubst_flags_t complain)
469 : {
470 288451363 : 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 633183208 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
480 : tsubst_flags_t complain,
481 : access_failure_info *afi)
482 : {
483 633183208 : int i;
484 633183208 : deferred_access *ptr;
485 633183208 : deferred_access_check *chk;
486 :
487 : /* Exit if we are in a context that no access checking is performed. */
488 633183208 : if (deferred_access_no_check)
489 : return true;
490 :
491 602600360 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
492 :
493 602600360 : ptr = &deferred_access_stack->last ();
494 :
495 : /* If we are not supposed to defer access checks, just check now. */
496 602600360 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
497 : {
498 350517901 : bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
499 350517901 : return (complain & tf_error) ? true : ok;
500 : }
501 :
502 : /* See if we are already going to perform this check. */
503 306835804 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
504 : {
505 71893074 : if (chk->decl == decl && chk->binfo == binfo &&
506 17140810 : chk->diag_decl == diag_decl)
507 : {
508 : return true;
509 : }
510 : }
511 : /* If not, record the check. */
512 234942730 : deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
513 234942730 : vec_safe_push (ptr->deferred_access_checks, new_access);
514 :
515 234942730 : 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 1413463344 : stmts_are_full_exprs_p (void)
524 : {
525 1413463344 : 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 1313528815 : add_stmt (tree t)
534 : {
535 1313528815 : enum tree_code code = TREE_CODE (t);
536 :
537 1313528815 : if (EXPR_P (t) && code != LABEL_EXPR)
538 : {
539 1263218609 : if (!EXPR_HAS_LOCATION (t))
540 201928251 : 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 1263218609 : if (STATEMENT_CODE_P (TREE_CODE (t)))
545 329397441 : STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
546 : }
547 :
548 1313528815 : if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
549 6003048 : 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 1313528815 : gcc_checking_assert (!stmt_list_stack->is_empty ());
554 1313528815 : append_to_statement_list_force (t, &cur_stmt_list);
555 :
556 1313528815 : return t;
557 : }
558 :
559 : /* Returns the stmt_tree to which statements are currently being added. */
560 :
561 : stmt_tree
562 7674746592 : current_stmt_tree (void)
563 : {
564 7674746592 : return (cfun
565 7651121408 : ? &cfun->language->base.x_stmt_tree
566 7674746592 : : &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 330449 : maybe_cleanup_point_expr (tree expr)
573 : {
574 330449 : if (!processing_template_decl && stmts_are_full_exprs_p ())
575 317110 : expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
576 330449 : 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 325563792 : maybe_cleanup_point_expr_void (tree expr)
586 : {
587 325563792 : if (!processing_template_decl && stmts_are_full_exprs_p ())
588 109131844 : expr = fold_build_cleanup_point_expr (void_type_node, expr);
589 325563792 : return expr;
590 : }
591 :
592 :
593 :
594 : /* Create a declaration statement for the declaration given by the DECL. */
595 :
596 : void
597 110135507 : add_decl_expr (tree decl)
598 : {
599 110135507 : tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
600 110135507 : if (DECL_INITIAL (decl)
601 110135507 : || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
602 19604789 : r = maybe_cleanup_point_expr_void (r);
603 110135507 : add_stmt (r);
604 110135507 : }
605 :
606 : /* Set EXPR_LOCATION on one cleanup T to LOC. */
607 :
608 : static void
609 5841477 : set_one_cleanup_loc (tree t, location_t loc)
610 : {
611 5841477 : if (!t)
612 : return;
613 :
614 5841477 : if (TREE_CODE (t) != POSTCONDITION_STMT)
615 5841477 : 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 5841477 : if (TREE_CODE (t) == NOP_EXPR
622 0 : && TREE_TYPE (t) == void_type_node
623 5841477 : && 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 1239434262 : set_cleanup_locs (tree stmts, location_t loc)
631 : {
632 1245275739 : if (TREE_CODE (stmts) == CLEANUP_STMT)
633 : {
634 5841477 : set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
635 5841477 : set_cleanup_locs (CLEANUP_BODY (stmts), loc);
636 : }
637 1239434262 : else if (TREE_CODE (stmts) == STATEMENT_LIST)
638 1101055198 : for (tree stmt : tsi_range (stmts))
639 852860849 : set_cleanup_locs (stmt, loc);
640 1239434262 : }
641 :
642 : /* True iff the innermost block scope is a try block. */
643 :
644 : static bool
645 386573413 : at_try_scope ()
646 : {
647 386573413 : cp_binding_level *b = current_binding_level;
648 386573700 : while (b && b->kind == sk_cleanup)
649 287 : b = b->level_chain;
650 386573413 : return b && b->kind == sk_try;
651 : }
652 :
653 : /* Finish a scope. */
654 :
655 : tree
656 386573413 : do_poplevel (tree stmt_list)
657 : {
658 386573413 : tree block = NULL;
659 :
660 386573413 : bool was_try = at_try_scope ();
661 :
662 386573413 : if (stmts_are_full_exprs_p ())
663 386510905 : block = poplevel (kept_level_p (), 1, 0);
664 :
665 : /* This needs to come after poplevel merges sk_cleanup statement_lists. */
666 386573413 : maybe_splice_retval_cleanup (stmt_list, was_try);
667 :
668 386573413 : stmt_list = pop_stmt_list (stmt_list);
669 :
670 : /* input_location is the last token of the scope, usually a }. */
671 386573413 : set_cleanup_locs (stmt_list, input_location);
672 :
673 386573413 : if (!processing_template_decl)
674 : {
675 118978408 : stmt_list = c_build_bind_expr (input_location, block, stmt_list);
676 : /* ??? See c_end_compound_stmt re statement expressions. */
677 : }
678 :
679 386573413 : return stmt_list;
680 : }
681 :
682 : /* Begin a new scope. */
683 :
684 : tree
685 386535799 : do_pushlevel (scope_kind sk)
686 : {
687 386535799 : tree ret = push_stmt_list ();
688 386535799 : if (stmts_are_full_exprs_p ())
689 386510965 : begin_scope (sk, NULL);
690 386535799 : 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 5841352 : push_cleanup (tree decl, tree cleanup, bool eh_only)
700 : {
701 5841352 : tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
702 5841352 : CLEANUP_EH_ONLY (stmt) = eh_only;
703 5841352 : add_stmt (stmt);
704 5841352 : CLEANUP_BODY (stmt) = push_stmt_list ();
705 5841352 : }
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 18469799 : begin_maybe_infinite_loop (tree cond)
716 : {
717 : /* Only track this while parsing a function, not during instantiation. */
718 18469799 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
719 2706724 : && !processing_template_decl))
720 : return;
721 15762571 : bool maybe_infinite = true;
722 15762571 : if (cond)
723 : {
724 15455738 : cond = fold_non_dependent_expr (cond);
725 15455738 : maybe_infinite = integer_nonzerop (cond);
726 : }
727 31218309 : vec_safe_push (cp_function_chain->infinite_loops,
728 15762571 : 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 1545180 : break_maybe_infinite_loop (void)
736 : {
737 1545180 : if (!cfun)
738 : return;
739 1545180 : 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 18469799 : end_maybe_infinite_loop (tree cond)
747 : {
748 18469799 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
749 2706724 : && !processing_template_decl))
750 : return;
751 15762571 : tree current = cp_function_chain->infinite_loops->pop();
752 15762571 : if (current != NULL_TREE)
753 : {
754 5114886 : cond = fold_non_dependent_expr (cond);
755 5114886 : if (integer_nonzerop (cond))
756 331280 : 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 89551237 : begin_cond (tree *cond_p)
767 : {
768 89551237 : if (processing_template_decl)
769 63385785 : *cond_p = push_stmt_list ();
770 89551237 : }
771 :
772 : /* Finish such a conditional. */
773 :
774 : static void
775 89551237 : finish_cond (tree *cond_p, tree expr)
776 : {
777 89551237 : if (processing_template_decl)
778 : {
779 63385785 : tree cond = pop_stmt_list (*cond_p);
780 :
781 63385785 : if (expr == NULL_TREE)
782 : /* Empty condition in 'for'. */
783 286142 : gcc_assert (empty_expr_stmt_p (cond));
784 63099643 : else if (check_for_bare_parameter_packs (expr))
785 0 : expr = error_mark_node;
786 63099643 : else if (!empty_expr_stmt_p (cond))
787 975173 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
788 : }
789 89551237 : *cond_p = expr;
790 89551237 : }
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 12433013 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
809 : {
810 12433013 : if (!TREE_SIDE_EFFECTS (*body_p))
811 12423299 : return;
812 :
813 9714 : gcc_assert (!processing_template_decl);
814 9714 : *prep_p = *body_p;
815 9714 : 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 9714 : current_binding_level->keep = true;
840 9714 : 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 9714 : if (tsi_end_p (iter))
847 : *body_p = NULL_TREE;
848 : else
849 9623 : *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 9714 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
862 : {
863 9714 : *prep_p = do_poplevel (*prep_p);
864 9714 : gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
865 9714 : 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 9696 : tree stmt_list = BIND_EXPR_BODY (*prep_p);
872 9696 : gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
873 9696 : 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 9605 : tree_stmt_iterator iter = tsi_start (stmt_list);
893 9837 : while (tsi_stmt (iter) != *body_p)
894 232 : tsi_next (&iter);
895 9605 : *body_p = tsi_split_stmt_list (input_location, iter);
896 : }
897 :
898 : /* Finish a goto-statement. */
899 :
900 : tree
901 2767 : finish_goto_stmt (tree destination)
902 : {
903 2767 : if (identifier_p (destination))
904 2621 : 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 2767 : if (TREE_CODE (destination) == LABEL_DECL)
909 2621 : TREE_USED (destination) = 1;
910 : else
911 : {
912 146 : destination = mark_rvalue_use (destination);
913 146 : if (!processing_template_decl)
914 : {
915 126 : destination = cp_convert (ptr_type_node, destination,
916 : tf_warning_or_error);
917 126 : if (error_operand_p (destination))
918 : return NULL_TREE;
919 117 : destination
920 117 : = fold_build_cleanup_point_expr (TREE_TYPE (destination),
921 : destination);
922 : }
923 : }
924 :
925 2758 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
926 :
927 2758 : tree stmt = build_stmt (input_location, GOTO_EXPR, destination);
928 2758 : check_goto (&TREE_OPERAND (stmt, 0));
929 :
930 2758 : return add_stmt (stmt);
931 : }
932 :
933 : /* Returns true if T corresponds to an assignment operator expression. */
934 :
935 : static bool
936 883397 : is_assignment_op_expr_p (tree t)
937 : {
938 883397 : if (t == NULL_TREE)
939 : return false;
940 :
941 883397 : if (TREE_CODE (t) == MODIFY_EXPR
942 883397 : || (TREE_CODE (t) == MODOP_EXPR
943 336 : && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
944 : return true;
945 :
946 882710 : tree call = extract_call_expr (t);
947 882710 : if (call == NULL_TREE
948 129924 : || call == error_mark_node
949 1012634 : || !CALL_EXPR_OPERATOR_SYNTAX (call))
950 : return false;
951 :
952 4682 : tree fndecl = cp_get_callee_fndecl_nofold (call);
953 4682 : return fndecl != NULL_TREE
954 4584 : && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
955 4733 : && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR);
956 : }
957 :
958 : /* Return true if TYPE is a class type that is convertible to
959 : and assignable from bool. */
960 :
961 : static GTY((deletable)) hash_map<tree, bool> *boolish_class_type_p_cache;
962 :
963 : static bool
964 60 : boolish_class_type_p (tree type)
965 : {
966 60 : type = TYPE_MAIN_VARIANT (type);
967 60 : if (!CLASS_TYPE_P (type) || !COMPLETE_TYPE_P (type))
968 : return false;
969 :
970 77 : if (bool *r = hash_map_safe_get (boolish_class_type_p_cache, type))
971 26 : return *r;
972 :
973 19 : tree ops;
974 19 : bool has_bool_assignment = false;
975 19 : bool has_bool_conversion = false;
976 :
977 19 : ops = lookup_fnfields (type, assign_op_identifier, /*protect=*/0, tf_none);
978 58 : for (tree op : ovl_range (BASELINK_FUNCTIONS (ops)))
979 : {
980 31 : op = STRIP_TEMPLATE (op);
981 31 : if (TREE_CODE (op) != FUNCTION_DECL)
982 0 : continue;
983 31 : tree parm = DECL_CHAIN (DECL_ARGUMENTS (op));
984 31 : tree parm_type = non_reference (TREE_TYPE (parm));
985 31 : if (TREE_CODE (parm_type) == BOOLEAN_TYPE)
986 : {
987 : has_bool_assignment = true;
988 : break;
989 : }
990 : }
991 :
992 19 : if (has_bool_assignment)
993 : {
994 4 : ops = lookup_conversions (type);
995 8 : for (; ops; ops = TREE_CHAIN (ops))
996 : {
997 4 : tree op = TREE_VALUE (ops);
998 4 : if (!DECL_NONCONVERTING_P (op)
999 4 : && TREE_CODE (DECL_CONV_FN_TYPE (op)) == BOOLEAN_TYPE)
1000 : {
1001 : has_bool_conversion = true;
1002 : break;
1003 : }
1004 : }
1005 : }
1006 :
1007 19 : bool boolish = has_bool_assignment && has_bool_conversion;
1008 19 : hash_map_safe_put<true> (boolish_class_type_p_cache, type, boolish);
1009 19 : return boolish;
1010 : }
1011 :
1012 :
1013 : /* Maybe warn about an unparenthesized 'a = b' (appearing in a
1014 : boolean context where 'a == b' might have been intended).
1015 : NESTED_P is true if T is the RHS of another assignment. */
1016 :
1017 : void
1018 92437914 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
1019 : tsubst_flags_t complain)
1020 : {
1021 92437914 : tree type = TREE_TYPE (t);
1022 92437914 : t = STRIP_REFERENCE_REF (t);
1023 :
1024 92437914 : if ((complain & tf_warning)
1025 92377365 : && warn_parentheses
1026 883397 : && 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 92438261 : && (!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 92437914 : }
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 54744355 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
1072 : {
1073 54744355 : tree *t = cond;
1074 54754647 : while (TREE_CODE (*t) == ANNOTATE_EXPR)
1075 10292 : t = &TREE_OPERAND (*t, 0);
1076 :
1077 54744355 : if (t != cond)
1078 : {
1079 10289 : m_annotations = *cond;
1080 10289 : *cond = *t;
1081 10289 : m_inner = t;
1082 : }
1083 54744355 : }
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 54744355 : annotate_saver::restore (tree new_inner)
1092 : {
1093 54744355 : 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 10289 : 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 10289 : *m_inner = new_inner;
1118 10289 : 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 94578399 : maybe_convert_cond (tree cond)
1127 : {
1128 : /* Empty conditions remain empty. */
1129 94578399 : if (!cond)
1130 : return NULL_TREE;
1131 :
1132 : /* Wait until we instantiate templates before doing conversion. */
1133 94212699 : if (type_dependent_expression_p (cond))
1134 39468344 : return cond;
1135 :
1136 : /* Strip any ANNOTATE_EXPRs from COND. */
1137 54744355 : annotate_saver annotations (&cond);
1138 :
1139 : /* For structured binding used in condition, the conversion needs to be
1140 : evaluated before the individual variables are initialized in the
1141 : std::tuple_{size,element} case. cp_finish_decomp saved the conversion
1142 : result in a NON_LVALUE_EXPR, pick it up from there. */
1143 380783 : if (DECL_DECOMPOSITION_P (cond)
1144 228 : && DECL_DECOMP_IS_BASE (cond)
1145 228 : && DECL_DECOMP_BASE (cond)
1146 54744580 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == NON_LVALUE_EXPR)
1147 59 : cond = TREE_OPERAND (DECL_DECOMP_BASE (cond), 0);
1148 :
1149 54744355 : if (warn_sequence_point && !processing_template_decl)
1150 329023 : verify_sequence_points (cond);
1151 :
1152 54744355 : maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
1153 : tf_warning_or_error);
1154 :
1155 : /* Do the conversion. */
1156 54744355 : cond = convert_from_reference (cond);
1157 54744355 : cond = condition_conversion (cond);
1158 :
1159 : /* Restore any ANNOTATE_EXPRs around COND. */
1160 54744355 : return annotations.restore (cond);
1161 : }
1162 :
1163 : /* Finish an expression-statement, whose EXPRESSION is as indicated. */
1164 :
1165 : tree
1166 166993311 : finish_expr_stmt (tree expr)
1167 : {
1168 166993311 : tree r = NULL_TREE;
1169 166993311 : location_t loc = EXPR_LOCATION (expr);
1170 :
1171 166804473 : if (expr != NULL_TREE)
1172 : {
1173 : /* If we ran into a problem, make sure we complained. */
1174 166993150 : gcc_assert (expr != error_mark_node || seen_error ());
1175 :
1176 166993150 : if (!processing_template_decl)
1177 : {
1178 60890140 : if (warn_sequence_point)
1179 819395 : verify_sequence_points (expr);
1180 60890140 : expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1181 : }
1182 106103010 : else if (!type_dependent_expression_p (expr))
1183 23050084 : convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1184 :
1185 166993147 : 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 166993147 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
1192 : {
1193 166992968 : if (TREE_CODE (expr) != EXPR_STMT
1194 164487126 : && !STATEMENT_CLASS_P (expr)
1195 164482969 : && TREE_CODE (expr) != STATEMENT_LIST)
1196 164325709 : expr = build_stmt (loc, EXPR_STMT, expr);
1197 166992968 : expr = maybe_cleanup_point_expr_void (expr);
1198 : }
1199 :
1200 166993147 : r = add_stmt (expr);
1201 : }
1202 :
1203 166993308 : return r;
1204 : }
1205 :
1206 :
1207 : /* Begin an if-statement. Returns a newly created IF_STMT if
1208 : appropriate. */
1209 :
1210 : tree
1211 76382835 : begin_if_stmt (void)
1212 : {
1213 76382835 : tree r, scope;
1214 76382835 : scope = do_pushlevel (sk_cond);
1215 76382835 : r = build_stmt (input_location, IF_STMT, NULL_TREE,
1216 : NULL_TREE, NULL_TREE, scope);
1217 76382835 : current_binding_level->this_entity = r;
1218 76382835 : begin_cond (&IF_COND (r));
1219 76382835 : 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 254740 : is_std_constant_evaluated_p (tree fn)
1227 : {
1228 : /* std::is_constant_evaluated takes no arguments. */
1229 254740 : if (call_expr_nargs (fn) != 0)
1230 : return false;
1231 :
1232 91139 : tree fndecl = cp_get_callee_fndecl_nofold (fn);
1233 91139 : if (fndecl == NULL_TREE)
1234 : return false;
1235 :
1236 28362 : if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
1237 : BUILT_IN_FRONTEND))
1238 : return true;
1239 :
1240 28333 : if (!decl_in_std_namespace_p (fndecl))
1241 : return false;
1242 :
1243 12992 : tree name = DECL_NAME (fndecl);
1244 12992 : return name && id_equal (name, "is_constant_evaluated");
1245 : }
1246 :
1247 : /* Callback function for maybe_warn_for_constant_evaluated that looks
1248 : for calls to std::is_constant_evaluated in TP. */
1249 :
1250 : static tree
1251 4729522 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
1252 : {
1253 4729522 : tree t = *tp;
1254 :
1255 4729522 : if (TYPE_P (t) || TREE_CONSTANT (t))
1256 : {
1257 837585 : *walk_subtrees = false;
1258 837585 : return NULL_TREE;
1259 : }
1260 :
1261 3891937 : switch (TREE_CODE (t))
1262 : {
1263 254740 : case CALL_EXPR:
1264 254740 : if (is_std_constant_evaluated_p (t))
1265 2396 : return t;
1266 : break;
1267 6 : case EXPR_STMT:
1268 : /* Don't warn in statement expressions. */
1269 6 : *walk_subtrees = false;
1270 6 : return NULL_TREE;
1271 : default:
1272 : break;
1273 : }
1274 :
1275 : return NULL_TREE;
1276 : }
1277 :
1278 : /* In certain contexts, std::is_constant_evaluated() is always true (for
1279 : instance, in a consteval function or in a constexpr if), or always false
1280 : (e.g., in a non-constexpr non-consteval function) so give the user a clue. */
1281 :
1282 : static void
1283 76468737 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
1284 : bool trivial_infinite)
1285 : {
1286 76468737 : if (!warn_tautological_compare)
1287 : return;
1288 :
1289 : /* Suppress warning for std::is_constant_evaluated if the conditional
1290 : comes from a macro. */
1291 1442328 : if (from_macro_expansion_at (EXPR_LOCATION (cond)))
1292 : return;
1293 :
1294 609349 : cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
1295 : NULL);
1296 609349 : if (cond)
1297 : {
1298 2396 : if (constexpr_if)
1299 34 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1300 : "%<std::is_constant_evaluated%> always evaluates to "
1301 : "true in %<if constexpr%>");
1302 2362 : else if (trivial_infinite)
1303 : {
1304 8 : auto_diagnostic_group d;
1305 8 : if (warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1306 : "%<std::is_constant_evaluated%> evaluates to "
1307 : "true when checking if trivially empty iteration "
1308 : "statement is trivial infinite loop")
1309 8 : && !maybe_constexpr_fn (current_function_decl))
1310 8 : inform (EXPR_LOCATION (cond),
1311 : "and evaluates to false when actually evaluating "
1312 : "the condition in non-%<constexpr%> function");
1313 8 : }
1314 2354 : else if (!maybe_constexpr_fn (current_function_decl))
1315 38 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1316 : "%<std::is_constant_evaluated%> always evaluates to "
1317 : "false in a non-%<constexpr%> function");
1318 4632 : else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1319 3 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1320 : "%<std::is_constant_evaluated%> always evaluates to "
1321 : "true in a %<consteval%> function");
1322 : }
1323 : }
1324 :
1325 : /* Process the COND of an if-statement, which may be given by
1326 : IF_STMT. */
1327 :
1328 : tree
1329 76382835 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
1330 : {
1331 76382835 : tree cond = maybe_convert_cond (orig_cond);
1332 76382835 : maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
1333 : /*trivial_infinite=*/false);
1334 76382835 : if (IF_STMT_CONSTEXPR_P (if_stmt)
1335 16371587 : && !type_dependent_expression_p (cond)
1336 11310852 : && require_constant_expression (cond)
1337 11310821 : && !instantiation_dependent_expression_p (cond)
1338 : /* Wait until instantiation time, since only then COND has been
1339 : converted to bool. */
1340 82585247 : && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
1341 : {
1342 6202412 : cond = instantiate_non_dependent_expr (cond);
1343 6202412 : cond = cxx_constant_value (cond);
1344 : }
1345 70180423 : else if (processing_template_decl)
1346 52677801 : cond = orig_cond;
1347 76382835 : finish_cond (&IF_COND (if_stmt), cond);
1348 76382835 : add_stmt (if_stmt);
1349 76382835 : THEN_CLAUSE (if_stmt) = push_stmt_list ();
1350 76382835 : 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 76374991 : finish_then_clause (tree if_stmt)
1358 : {
1359 76374991 : THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
1360 76374991 : return if_stmt;
1361 : }
1362 :
1363 : /* Begin the else-clause of an if-statement. */
1364 :
1365 : void
1366 28455813 : begin_else_clause (tree if_stmt)
1367 : {
1368 28455813 : ELSE_CLAUSE (if_stmt) = push_stmt_list ();
1369 28455813 : }
1370 :
1371 : /* Finish the else-clause of an if-statement, which may be given by
1372 : IF_STMT. */
1373 :
1374 : void
1375 28455775 : finish_else_clause (tree if_stmt)
1376 : {
1377 28455775 : ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
1378 28455775 : }
1379 :
1380 : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1381 : read. */
1382 :
1383 : static tree
1384 879492167 : maybe_mark_exp_read_r (tree *tp, int *, void *)
1385 : {
1386 879492167 : tree t = *tp;
1387 879492167 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1388 51556663 : mark_exp_read (t);
1389 879492167 : return NULL_TREE;
1390 : }
1391 :
1392 : /* Finish an if-statement. */
1393 :
1394 : void
1395 76374991 : finish_if_stmt (tree if_stmt)
1396 : {
1397 76374991 : tree scope = IF_SCOPE (if_stmt);
1398 76374991 : IF_SCOPE (if_stmt) = NULL;
1399 76374991 : 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 16363743 : cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
1405 : maybe_mark_exp_read_r, NULL);
1406 16363743 : cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
1407 : maybe_mark_exp_read_r, NULL);
1408 : }
1409 76374991 : add_stmt (do_poplevel (scope));
1410 76374991 : }
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 17826565 : finish_loop_cond (tree *condp, tree body)
1421 : {
1422 17826565 : if (TREE_CODE (*condp) == INTEGER_CST)
1423 : return;
1424 12766256 : bool trivially_empty = expr_first (body) == NULL_TREE;
1425 12766256 : bool trivial_infinite = false;
1426 12766256 : if (trivially_empty)
1427 : {
1428 98903 : tree c = fold_non_dependent_expr (*condp, tf_none,
1429 : /*manifestly_const_eval=*/true);
1430 98903 : trivial_infinite = c && integer_nonzerop (c);
1431 : }
1432 12766256 : if (warn_tautological_compare)
1433 : {
1434 86104 : tree cond = *condp;
1435 86471 : while (TREE_CODE (cond) == ANNOTATE_EXPR)
1436 367 : cond = TREE_OPERAND (cond, 0);
1437 86104 : if (trivial_infinite
1438 86168 : && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1439 64 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1440 : /*trivial_infinite=*/true);
1441 86040 : else if (!trivially_empty
1442 375 : || !processing_template_decl
1443 86444 : || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1444 85838 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1445 : /*trivial_infinite=*/false);
1446 : }
1447 12766256 : 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 4864112 : begin_while_stmt (void)
1459 : {
1460 4864112 : tree r;
1461 4864112 : r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1462 : NULL_TREE, NULL_TREE);
1463 4864112 : add_stmt (r);
1464 4864112 : WHILE_BODY (r) = do_pushlevel (sk_block);
1465 4864112 : begin_cond (&WHILE_COND (r));
1466 4864112 : return r;
1467 : }
1468 :
1469 : /* Process the COND of a while-statement, which may be given by
1470 : WHILE_STMT. */
1471 :
1472 : void
1473 4864112 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
1474 : tree unroll, bool novector)
1475 : {
1476 4864112 : cond = maybe_convert_cond (cond);
1477 4864112 : finish_cond (&WHILE_COND (while_stmt), cond);
1478 4864112 : begin_maybe_infinite_loop (cond);
1479 4864112 : 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 4864112 : if (unroll && cond != error_mark_node)
1487 27142 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1488 13571 : TREE_TYPE (WHILE_COND (while_stmt)),
1489 13571 : WHILE_COND (while_stmt),
1490 : build_int_cst (integer_type_node,
1491 : annot_expr_unroll_kind),
1492 : unroll);
1493 4864112 : 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 4864112 : adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
1501 : &WHILE_COND_PREP (while_stmt),
1502 : &WHILE_COND_CLEANUP (while_stmt));
1503 4864112 : }
1504 :
1505 : /* Finish a while-statement, which may be given by WHILE_STMT. */
1506 :
1507 : void
1508 4864112 : finish_while_stmt (tree while_stmt)
1509 : {
1510 4864112 : end_maybe_infinite_loop (boolean_true_node);
1511 4864112 : if (WHILE_COND_PREP (while_stmt))
1512 9540 : finish_loop_cond_prep (&WHILE_BODY (while_stmt),
1513 : &WHILE_COND_PREP (while_stmt),
1514 9540 : WHILE_COND_CLEANUP (while_stmt));
1515 : else
1516 4854572 : WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
1517 4864112 : finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
1518 4864112 : }
1519 :
1520 : /* Begin a do-statement. Returns a newly created DO_STMT if
1521 : appropriate. */
1522 :
1523 : tree
1524 5759252 : begin_do_stmt (void)
1525 : {
1526 5759252 : tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
1527 : NULL_TREE);
1528 5759252 : begin_maybe_infinite_loop (boolean_true_node);
1529 5759252 : add_stmt (r);
1530 5759252 : DO_BODY (r) = push_stmt_list ();
1531 5759252 : return r;
1532 : }
1533 :
1534 : /* Finish the body of a do-statement, which may be given by DO_STMT. */
1535 :
1536 : void
1537 5759252 : finish_do_body (tree do_stmt)
1538 : {
1539 5759252 : tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
1540 :
1541 5759252 : if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
1542 538033 : body = STATEMENT_LIST_TAIL (body)->stmt;
1543 :
1544 5759252 : if (IS_EMPTY_STMT (body))
1545 30 : warning (OPT_Wempty_body,
1546 : "suggest explicit braces around empty body in %<do%> statement");
1547 5759252 : }
1548 :
1549 : /* Finish a do-statement, which may be given by DO_STMT, and whose
1550 : COND is as indicated. */
1551 :
1552 : void
1553 5759252 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
1554 : bool novector)
1555 : {
1556 5759252 : cond = maybe_convert_cond (cond);
1557 5759252 : 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 5759252 : if (check_for_bare_parameter_packs (cond))
1562 3 : cond = error_mark_node;
1563 5759252 : 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 5759252 : 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 5759252 : 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 5759252 : DO_COND (do_stmt) = cond;
1576 5759252 : tree do_body = DO_BODY (do_stmt);
1577 5759222 : if (CONVERT_EXPR_P (do_body)
1578 30 : && integer_zerop (TREE_OPERAND (do_body, 0))
1579 5759282 : && VOID_TYPE_P (TREE_TYPE (do_body)))
1580 : do_body = NULL_TREE;
1581 5759252 : finish_loop_cond (&DO_COND (do_stmt), do_body);
1582 5759252 : }
1583 :
1584 : /* Finish a return-statement. The EXPRESSION returned, if any, is as
1585 : indicated. */
1586 :
1587 : tree
1588 131793375 : finish_return_stmt (tree expr)
1589 : {
1590 131793375 : tree r;
1591 131793375 : bool no_warning;
1592 131793375 : bool dangling;
1593 :
1594 131793375 : expr = check_return_expr (expr, &no_warning, &dangling);
1595 :
1596 131793375 : if (error_operand_p (expr)
1597 131793375 : || (flag_openmp && !check_omp_return ()))
1598 : {
1599 : /* Suppress -Wreturn-type for this function. */
1600 1360 : if (warn_return_type)
1601 1354 : suppress_warning (current_function_decl, OPT_Wreturn_type);
1602 1360 : return error_mark_node;
1603 : }
1604 :
1605 131792015 : if (!processing_template_decl)
1606 : {
1607 46033032 : if (warn_sequence_point)
1608 1040002 : verify_sequence_points (expr);
1609 : }
1610 :
1611 131792015 : r = build_stmt (input_location, RETURN_EXPR, expr);
1612 131792015 : RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
1613 131792015 : if (no_warning)
1614 33 : suppress_warning (r, OPT_Wreturn_type);
1615 131792015 : r = maybe_cleanup_point_expr_void (r);
1616 131792015 : r = add_stmt (r);
1617 :
1618 131792015 : 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 7846435 : begin_for_scope (tree *init)
1627 : {
1628 7846435 : tree scope = do_pushlevel (sk_for);
1629 :
1630 7846435 : if (processing_template_decl)
1631 6236626 : *init = push_stmt_list ();
1632 : else
1633 1609809 : *init = NULL_TREE;
1634 :
1635 7846435 : 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 7568901 : begin_for_stmt (tree scope, tree init)
1644 : {
1645 7568901 : tree r;
1646 :
1647 7568901 : 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 7568901 : if (scope == NULL_TREE)
1652 : {
1653 1365641 : gcc_assert (!init);
1654 1365641 : scope = begin_for_scope (&init);
1655 : }
1656 :
1657 7568901 : FOR_INIT_STMT (r) = init;
1658 7568901 : FOR_SCOPE (r) = scope;
1659 :
1660 7568901 : 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 7568901 : finish_init_stmt (tree for_stmt)
1668 : {
1669 7568901 : if (processing_template_decl)
1670 5959092 : FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
1671 7568901 : add_stmt (for_stmt);
1672 7568901 : FOR_BODY (for_stmt) = do_pushlevel (sk_block);
1673 7568901 : begin_cond (&FOR_COND (for_stmt));
1674 7568901 : }
1675 :
1676 : /* Finish the COND of a for-statement, which may be given by
1677 : FOR_STMT. */
1678 :
1679 : void
1680 7568901 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
1681 : bool novector)
1682 : {
1683 7568901 : cond = maybe_convert_cond (cond);
1684 7568901 : finish_cond (&FOR_COND (for_stmt), cond);
1685 7568901 : begin_maybe_infinite_loop (cond);
1686 7568901 : 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 7568901 : 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 7568901 : 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 7568901 : adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
1708 : &FOR_COND_CLEANUP (for_stmt));
1709 7568901 : }
1710 :
1711 : /* Finish the increment-EXPRESSION in a for-statement, which may be
1712 : given by FOR_STMT. */
1713 :
1714 : void
1715 7556538 : finish_for_expr (tree expr, tree for_stmt)
1716 : {
1717 7556538 : 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 7102373 : if (type_unknown_p (expr))
1722 : {
1723 6 : cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1724 6 : expr = error_mark_node;
1725 : }
1726 7102373 : if (!processing_template_decl)
1727 : {
1728 1536646 : if (warn_sequence_point)
1729 15015 : verify_sequence_points (expr);
1730 1536646 : expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1731 : tf_warning_or_error);
1732 : }
1733 5565727 : else if (!type_dependent_expression_p (expr))
1734 2015093 : convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
1735 7102373 : expr = maybe_cleanup_point_expr_void (expr);
1736 7102373 : if (check_for_bare_parameter_packs (expr))
1737 0 : expr = error_mark_node;
1738 7102373 : 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 7846548 : find_range_for_decls (tree range_for_decl[3])
1749 : {
1750 7846548 : 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 31386192 : for (int i = 0; i < 3; i++)
1756 : {
1757 23539644 : tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1758 23539644 : if (IDENTIFIER_BINDING (id)
1759 23539644 : && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1760 : {
1761 276130 : range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1762 276130 : gcc_assert (VAR_P (range_for_decl[i])
1763 : && DECL_ARTIFICIAL (range_for_decl[i]));
1764 : }
1765 : }
1766 7846548 : }
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 7846435 : finish_for_stmt (tree for_stmt)
1775 : {
1776 7846435 : end_maybe_infinite_loop (boolean_true_node);
1777 :
1778 7846435 : if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1779 277534 : RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1780 : else
1781 : {
1782 7568901 : 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 7568727 : FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1788 7568901 : if (FOR_COND (for_stmt))
1789 7203201 : finish_loop_cond (&FOR_COND (for_stmt),
1790 7203201 : FOR_EXPR (for_stmt) ? integer_one_node
1791 141321 : : FOR_BODY (for_stmt));
1792 : }
1793 :
1794 : /* Pop the scope for the body of the loop. */
1795 7846435 : tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1796 7846435 : ? &RANGE_FOR_SCOPE (for_stmt)
1797 7568901 : : &FOR_SCOPE (for_stmt));
1798 7846435 : tree scope = *scope_ptr;
1799 7846435 : *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 7846435 : tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1806 7846435 : find_range_for_decls (range_for_decl);
1807 :
1808 7846435 : 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 7846435 : if (!stmts_are_full_exprs_p ())
1813 12363 : return;
1814 :
1815 31336288 : for (int i = 0; i < 3; i++)
1816 23502216 : if (range_for_decl[i])
1817 276014 : DECL_NAME (range_for_decl[i])
1818 276014 : = 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 277534 : begin_range_for_stmt (tree scope, tree init)
1828 : {
1829 277534 : begin_maybe_infinite_loop (boolean_false_node);
1830 :
1831 277534 : tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1832 : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1833 :
1834 277534 : if (scope == NULL_TREE)
1835 : {
1836 506 : gcc_assert (!init);
1837 506 : scope = begin_for_scope (&init);
1838 : }
1839 :
1840 : /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1841 277534 : RANGE_FOR_INIT_STMT (r) = init;
1842 277534 : RANGE_FOR_SCOPE (r) = scope;
1843 :
1844 277534 : 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 277534 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1853 : {
1854 277534 : if (processing_template_decl)
1855 555068 : RANGE_FOR_INIT_STMT (range_for_stmt)
1856 555068 : = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1857 277534 : RANGE_FOR_DECL (range_for_stmt) = decl;
1858 277534 : RANGE_FOR_EXPR (range_for_stmt) = expr;
1859 277534 : add_stmt (range_for_stmt);
1860 277534 : RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1861 277534 : }
1862 :
1863 : /* Begin the scope of an expansion-statement. */
1864 :
1865 : tree
1866 2324 : begin_template_for_scope (tree *init)
1867 : {
1868 2324 : tree scope = do_pushlevel (sk_template_for);
1869 :
1870 2324 : if (processing_template_decl)
1871 547 : *init = push_stmt_list ();
1872 : else
1873 1777 : *init = NULL_TREE;
1874 :
1875 2324 : return scope;
1876 : }
1877 :
1878 : /* Finish a break-statement. */
1879 :
1880 : tree
1881 4893019 : 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 4893019 : if (!block_may_fallthru (cur_stmt_list))
1891 921 : return void_node;
1892 4892098 : note_break_stmt ();
1893 4892098 : return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
1894 : }
1895 :
1896 : /* Finish a continue-statement. */
1897 :
1898 : tree
1899 262446 : finish_continue_stmt (void)
1900 : {
1901 262446 : 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 735389 : begin_switch_stmt (void)
1909 : {
1910 735389 : tree r, scope;
1911 :
1912 735389 : scope = do_pushlevel (sk_cond);
1913 735389 : r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1914 : scope, NULL_TREE);
1915 :
1916 735389 : begin_cond (&SWITCH_STMT_COND (r));
1917 :
1918 735389 : return r;
1919 : }
1920 :
1921 : /* Finish the cond of a switch-statement. */
1922 :
1923 : void
1924 735389 : finish_switch_cond (tree cond, tree switch_stmt)
1925 : {
1926 735389 : tree orig_type = NULL;
1927 :
1928 735389 : if (!processing_template_decl)
1929 : {
1930 : /* Convert the condition to an integer or enumeration type. */
1931 301677 : tree orig_cond = cond;
1932 : /* For structured binding used in condition, the conversion needs to be
1933 : evaluated before the individual variables are initialized in the
1934 : std::tuple_{size,element} case. cp_finish_decomp saved the
1935 : conversion result in a NON_LVALUE_EXPR, pick it up from there. */
1936 122 : if (DECL_DECOMPOSITION_P (cond)
1937 57 : && DECL_DECOMP_IS_BASE (cond)
1938 57 : && DECL_DECOMP_BASE (cond)
1939 301731 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == NON_LVALUE_EXPR)
1940 18 : cond = TREE_OPERAND (DECL_DECOMP_BASE (cond), 0);
1941 301677 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1942 301677 : 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 301677 : orig_type = unlowered_expr_type (cond);
1950 301677 : if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1951 207219 : orig_type = TREE_TYPE (cond);
1952 301677 : if (cond != error_mark_node)
1953 : {
1954 : /* [stmt.switch]
1955 :
1956 : Integral promotions are performed. */
1957 301641 : cond = perform_integral_promotions (cond);
1958 301641 : cond = maybe_cleanup_point_expr (cond);
1959 : }
1960 : }
1961 735389 : if (check_for_bare_parameter_packs (cond))
1962 0 : cond = error_mark_node;
1963 735389 : else if (!processing_template_decl && warn_sequence_point)
1964 2853 : verify_sequence_points (cond);
1965 :
1966 735389 : finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1967 735389 : SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1968 735389 : add_stmt (switch_stmt);
1969 735389 : push_switch (switch_stmt);
1970 735389 : SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1971 735389 : }
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 735389 : finish_switch_stmt (tree switch_stmt)
1978 : {
1979 735389 : tree scope;
1980 :
1981 1470778 : SWITCH_STMT_BODY (switch_stmt) =
1982 735389 : pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1983 735389 : pop_switch ();
1984 :
1985 735389 : scope = SWITCH_STMT_SCOPE (switch_stmt);
1986 735389 : SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1987 735389 : add_stmt (do_poplevel (scope));
1988 735389 : }
1989 :
1990 : /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1991 : appropriate. */
1992 :
1993 : tree
1994 1194187 : begin_try_block (void)
1995 : {
1996 1194187 : tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1997 1194187 : add_stmt (r);
1998 1194187 : TRY_STMTS (r) = push_stmt_list ();
1999 1194187 : 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 2251 : begin_function_try_block (tree *compound_stmt)
2008 : {
2009 2251 : 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 2251 : *compound_stmt = begin_compound_stmt (0);
2013 2251 : current_binding_level->artificial = 1;
2014 2251 : r = begin_try_block ();
2015 2251 : FN_TRY_BLOCK_P (r) = 1;
2016 2251 : return r;
2017 : }
2018 :
2019 : /* Finish a try-block, which may be given by TRY_BLOCK. */
2020 :
2021 : void
2022 1194187 : finish_try_block (tree try_block)
2023 : {
2024 1194187 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2025 1194187 : TRY_HANDLERS (try_block) = push_stmt_list ();
2026 1194187 : }
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 2251 : finish_function_try_block (tree try_block)
2051 : {
2052 2251 : finish_try_block (try_block);
2053 : /* FIXME : something queer about CTOR_INITIALIZER somehow following
2054 : the try block, but moving it inside. */
2055 2251 : in_function_try_handler = 1;
2056 2251 : }
2057 :
2058 : /* Finish a handler-sequence for a try-block, which may be given by
2059 : TRY_BLOCK. */
2060 :
2061 : void
2062 1194187 : finish_handler_sequence (tree try_block)
2063 : {
2064 1194187 : TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
2065 1194187 : check_handlers (TRY_HANDLERS (try_block));
2066 1194187 : }
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 2251 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
2074 : {
2075 2251 : in_function_try_handler = 0;
2076 2251 : finish_handler_sequence (try_block);
2077 2251 : finish_compound_stmt (compound_stmt);
2078 2251 : }
2079 :
2080 : /* Begin a handler. Returns a HANDLER if appropriate. */
2081 :
2082 : tree
2083 1662447 : begin_handler (void)
2084 : {
2085 1662447 : tree r;
2086 :
2087 1662447 : r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
2088 1662447 : add_stmt (r);
2089 :
2090 : /* Create a binding level for the eh_info and the exception object
2091 : cleanup. */
2092 1662447 : HANDLER_BODY (r) = do_pushlevel (sk_catch);
2093 :
2094 1662447 : 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 1662447 : finish_handler_parms (tree decl, tree handler)
2103 : {
2104 1662447 : tree type = NULL_TREE;
2105 1662447 : if (processing_template_decl)
2106 : {
2107 1515853 : if (decl)
2108 : {
2109 491766 : decl = pushdecl (decl);
2110 491766 : decl = push_template_decl (decl);
2111 491766 : HANDLER_PARMS (handler) = decl;
2112 491766 : type = TREE_TYPE (decl);
2113 : }
2114 : }
2115 : else
2116 : {
2117 146594 : type = expand_start_catch_block (decl);
2118 146594 : if (warn_catch_value
2119 2116 : && type != NULL_TREE
2120 711 : && type != error_mark_node
2121 147305 : && !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 1662447 : HANDLER_TYPE (handler) = type;
2143 1662447 : }
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 1662447 : finish_handler (tree handler)
2150 : {
2151 1662447 : if (!processing_template_decl)
2152 146594 : expand_end_catch_block ();
2153 1662447 : HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
2154 1662447 : }
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 292726134 : begin_compound_stmt (unsigned int flags)
2165 : {
2166 292726134 : tree r;
2167 :
2168 292726134 : if (flags & BCS_NO_SCOPE)
2169 : {
2170 5599561 : r = push_stmt_list ();
2171 5599561 : 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 5599561 : keep_next_level (false);
2178 : }
2179 : else
2180 : {
2181 287126573 : scope_kind sk = sk_block;
2182 287126573 : if (flags & BCS_TRY_BLOCK)
2183 : sk = sk_try;
2184 285932638 : else if (flags & BCS_TRANSACTION)
2185 : sk = sk_transaction;
2186 285932403 : else if (flags & BCS_STMT_EXPR)
2187 29154 : sk = sk_stmt_expr;
2188 287126573 : 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 292726134 : if (processing_template_decl)
2198 : {
2199 196173096 : r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
2200 196173096 : BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
2201 196173096 : BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
2202 196173096 : TREE_SIDE_EFFECTS (r) = 1;
2203 : }
2204 :
2205 292726134 : return r;
2206 : }
2207 :
2208 : /* Finish a compound-statement, which is given by STMT. */
2209 :
2210 : void
2211 292726089 : finish_compound_stmt (tree stmt)
2212 : {
2213 292726089 : if (TREE_CODE (stmt) == BIND_EXPR)
2214 : {
2215 196173096 : 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 196173096 : if (TREE_CODE (body) == STATEMENT_LIST
2220 178273823 : && STATEMENT_LIST_HEAD (body) == NULL
2221 11842434 : && !BIND_EXPR_BODY_BLOCK (stmt)
2222 207500754 : && !BIND_EXPR_TRY_BLOCK (stmt))
2223 : stmt = body;
2224 : else
2225 184845535 : BIND_EXPR_BODY (stmt) = body;
2226 : }
2227 96552993 : else if (STATEMENT_LIST_NO_SCOPE (stmt))
2228 5561887 : stmt = pop_stmt_list (stmt);
2229 : else
2230 : {
2231 : /* Destroy any ObjC "super" receivers that may have been
2232 : created. */
2233 90991106 : objc_clear_super_receiver ();
2234 :
2235 90991106 : stmt = do_poplevel (stmt);
2236 : }
2237 :
2238 : /* ??? See c_end_compound_stmt wrt statement expressions. */
2239 292726089 : add_stmt (stmt);
2240 292726089 : }
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 58088 : finish_asm_string_expression (location_t loc, tree string)
2248 : {
2249 58088 : if (string == error_mark_node
2250 58075 : || 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 32753 : 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 32753 : tree r;
2277 32753 : tree t;
2278 32753 : int ninputs = list_length (input_operands);
2279 32753 : int noutputs = list_length (output_operands);
2280 :
2281 32753 : if (!processing_template_decl)
2282 : {
2283 12671 : const char *constraint;
2284 12671 : const char **oconstraints;
2285 12671 : bool allows_mem, allows_reg, is_inout;
2286 12671 : tree operand;
2287 12671 : int i;
2288 :
2289 12671 : oconstraints = XALLOCAVEC (const char *, noutputs);
2290 :
2291 25240 : string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
2292 : string);
2293 12671 : if (string == error_mark_node)
2294 109 : return error_mark_node;
2295 37731 : for (int i = 0; i < 2; ++i)
2296 60897 : for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
2297 : {
2298 35758 : tree s = TREE_VALUE (TREE_PURPOSE (t));
2299 71498 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2300 35758 : if (s == error_mark_node)
2301 : return error_mark_node;
2302 35728 : TREE_VALUE (TREE_PURPOSE (t)) = s;
2303 : }
2304 21621 : for (t = clobbers; t; t = TREE_CHAIN (t))
2305 : {
2306 9059 : tree s = TREE_VALUE (t);
2307 18112 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2308 9059 : TREE_VALUE (t) = s;
2309 : }
2310 :
2311 12562 : string = resolve_asm_operand_names (string, output_operands,
2312 : input_operands, labels);
2313 :
2314 43704 : for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
2315 : {
2316 18580 : 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 18580 : STRIP_NOPS (operand);
2325 :
2326 18580 : operand = mark_lvalue_use (operand);
2327 :
2328 18580 : if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
2329 9 : operand = error_mark_node;
2330 :
2331 18580 : if (operand != error_mark_node
2332 18580 : && (TREE_READONLY (operand)
2333 18565 : || CP_TYPE_CONST_P (TREE_TYPE (operand))
2334 : /* Functions are not modifiable, even though they are
2335 : lvalues. */
2336 18565 : || 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 18565 : || (CLASS_TYPE_P (TREE_TYPE (operand))
2340 426 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
2341 6 : cxx_readonly_error (loc, operand, lv_asm);
2342 :
2343 18580 : tree *op = &operand;
2344 18587 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2345 7 : op = &TREE_OPERAND (*op, 1);
2346 18580 : 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 18580 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2359 18580 : oconstraints[i] = constraint;
2360 :
2361 18580 : 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 18571 : if (!allows_reg && !cxx_mark_addressable (*op))
2368 0 : operand = error_mark_node;
2369 18571 : 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 715 : 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 18559 : 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 18580 : TREE_VALUE (t) = operand;
2415 : }
2416 :
2417 29705 : for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
2418 : {
2419 17143 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2420 17143 : bool constraint_parsed
2421 17143 : = 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 17143 : if (constraint_parsed && !allows_reg && allows_mem)
2427 573 : operand = mark_lvalue_use (TREE_VALUE (t));
2428 : else
2429 16570 : 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 17143 : 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 17143 : if (constraint_parsed)
2444 : {
2445 : /* If the operand is going to end up in memory,
2446 : mark it addressable. */
2447 17122 : 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 573 : STRIP_NOPS (operand);
2452 :
2453 573 : tree *op = &operand;
2454 580 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2455 7 : op = &TREE_OPERAND (*op, 1);
2456 573 : 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 573 : if (!cxx_mark_addressable (*op))
2469 0 : operand = error_mark_node;
2470 : }
2471 16549 : else if (!allows_reg && !allows_mem)
2472 : {
2473 : /* If constraint allows neither register nor memory,
2474 : try harder to get a constant. */
2475 465 : tree constop = maybe_constant_value (operand);
2476 465 : if (TREE_CONSTANT (constop))
2477 438 : operand = constop;
2478 : }
2479 17122 : 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 17122 : 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 17143 : 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 17026 : 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 17143 : TREE_VALUE (t) = operand;
2551 : }
2552 : }
2553 :
2554 32644 : r = build_stmt (loc, ASM_EXPR, string,
2555 : output_operands, input_operands,
2556 : clobbers, labels);
2557 32644 : ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
2558 32644 : ASM_INLINE_P (r) = inline_p;
2559 32644 : if (toplev_p)
2560 : {
2561 99 : symtab->finalize_toplevel_asm (r);
2562 99 : return r;
2563 : }
2564 32545 : r = maybe_cleanup_point_expr_void (r);
2565 32545 : return add_stmt (r);
2566 : }
2567 :
2568 : /* Finish a label with the indicated NAME. Returns the new label. */
2569 :
2570 : tree
2571 2542 : finish_label_stmt (tree name)
2572 : {
2573 2542 : tree decl = define_label (input_location, name);
2574 :
2575 2542 : if (decl == error_mark_node)
2576 : return error_mark_node;
2577 :
2578 2536 : add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
2579 :
2580 2536 : 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 3575389 : finish_decl_cleanup (tree decl, tree cleanup)
2603 : {
2604 3575389 : push_cleanup (decl, cleanup, false);
2605 3575389 : }
2606 :
2607 : /* If the current scope exits with an exception, run CLEANUP. */
2608 :
2609 : void
2610 2256071 : finish_eh_cleanup (tree cleanup)
2611 : {
2612 2256071 : push_cleanup (NULL, cleanup, true);
2613 2256071 : }
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 20815089 : 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 20815089 : mem_inits = nreverse (mem_inits);
2625 :
2626 20815089 : if (processing_template_decl)
2627 : {
2628 : tree mem;
2629 :
2630 35201415 : 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 20825480 : if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
2638 20825480 : && check_for_bare_parameter_packs (TREE_VALUE (mem)))
2639 3 : TREE_VALUE (mem) = error_mark_node;
2640 : }
2641 :
2642 14375935 : add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
2643 : CTOR_INITIALIZER, mem_inits));
2644 : }
2645 : else
2646 6439154 : emit_mem_initializers (mem_inits);
2647 20815089 : }
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 45846591 : force_paren_expr (tree expr, bool even_uneval /* = false */)
2655 : {
2656 : /* This is only needed for decltype(auto) in C++14. */
2657 45846591 : 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 45227960 : if (cp_unevaluated_operand && !even_uneval)
2663 : return expr;
2664 :
2665 37606340 : if (TREE_CODE (expr) == COMPONENT_REF
2666 37544274 : || TREE_CODE (expr) == SCOPE_REF
2667 75143659 : || REFERENCE_REF_P (expr))
2668 625609 : REF_PARENTHESIZED_P (expr) = true;
2669 36980731 : else if (DECL_P (tree_strip_any_location_wrapper (expr)))
2670 : {
2671 1750732 : location_t loc = cp_expr_location (expr);
2672 1750732 : const tree_code code = processing_template_decl ? PAREN_EXPR
2673 : : VIEW_CONVERT_EXPR;
2674 1750732 : expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
2675 1750732 : 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 1017641162 : maybe_undo_parenthesized_ref (tree t)
2686 : {
2687 1017641162 : if (cxx_dialect < cxx14)
2688 : return t;
2689 :
2690 1007763773 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
2691 1117373925 : && REF_PARENTHESIZED_P (t))
2692 202113 : t = TREE_OPERAND (t, 0);
2693 :
2694 : return t;
2695 : }
2696 :
2697 : /* Finish a parenthesized expression EXPR. */
2698 :
2699 : cp_expr
2700 34093932 : finish_parenthesized_expr (cp_expr expr)
2701 : {
2702 34093932 : if (EXPR_P (expr))
2703 : {
2704 : /* This inhibits warnings in maybe_warn_unparenthesized_assignment
2705 : and c_common_truthvalue_conversion. */
2706 67779009 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
2707 : /* And maybe_warn_sizeof_array_div. */
2708 67779009 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
2709 : }
2710 :
2711 34093932 : if (TREE_CODE (expr) == OFFSET_REF
2712 34093932 : || 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 31456 : PTRMEM_OK_P (expr) = 0;
2716 :
2717 34093932 : tree stripped_expr = tree_strip_any_location_wrapper (expr);
2718 34093932 : if (TREE_CODE (stripped_expr) == STRING_CST)
2719 902951 : PAREN_STRING_LITERAL_P (stripped_expr) = 1;
2720 33190981 : else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
2721 1492 : PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
2722 :
2723 34093932 : expr = cp_expr (force_paren_expr (expr), expr.get_location ());
2724 :
2725 34093932 : 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 79147043 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
2733 : tsubst_flags_t complain /* = tf_warning_or_error */)
2734 : {
2735 79147043 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
2736 79147043 : bool try_omp_private = !object && omp_private_member_map;
2737 68730667 : tree ret;
2738 :
2739 68730667 : if (!object)
2740 : {
2741 68730667 : tree scope = qualifying_scope;
2742 68730667 : if (scope == NULL_TREE)
2743 : {
2744 68718517 : scope = context_for_name_lookup (decl);
2745 68718517 : 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 68730664 : object = maybe_dummy_object (scope, NULL);
2753 : }
2754 :
2755 79147040 : object = maybe_resolve_dummy (object, true);
2756 79147040 : 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 79147037 : if (is_dummy_object (object)
2762 36251 : && !cp_unevaluated_operand
2763 79147143 : && (!processing_template_decl || !current_class_ref))
2764 : {
2765 91 : if (complain & tf_error)
2766 : {
2767 74 : auto_diagnostic_group d;
2768 74 : if (current_function_decl
2769 74 : && DECL_STATIC_FUNCTION_P (current_function_decl))
2770 3 : error ("invalid use of member %qD in static member function", decl);
2771 71 : else if (current_function_decl
2772 63 : && processing_contract_condition
2773 71 : && DECL_CONSTRUCTOR_P (current_function_decl))
2774 0 : error ("invalid use of member %qD in constructor %<pre%> contract", decl);
2775 71 : else if (current_function_decl
2776 63 : && processing_contract_condition
2777 71 : && DECL_DESTRUCTOR_P (current_function_decl))
2778 0 : error ("invalid use of member %qD in destructor %<post%> contract", decl);
2779 : else
2780 71 : error ("invalid use of non-static data member %qD", decl);
2781 74 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
2782 74 : }
2783 :
2784 91 : return error_mark_node;
2785 : }
2786 :
2787 79146946 : if (current_class_ptr)
2788 78816567 : TREE_USED (current_class_ptr) = 1;
2789 79146946 : if (processing_template_decl)
2790 : {
2791 62985851 : tree type = TREE_TYPE (decl);
2792 :
2793 62985851 : if (TYPE_REF_P (type))
2794 : /* Quals on the object don't matter. */;
2795 60576330 : else if (PACK_EXPANSION_P (type))
2796 : /* Don't bother trying to represent this. */
2797 : type = NULL_TREE;
2798 60573286 : 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 60568688 : auto quals = cp_type_quals (TREE_TYPE (object));
2812 :
2813 60568688 : if (DECL_MUTABLE_P (decl))
2814 241113 : quals &= ~TYPE_QUAL_CONST;
2815 :
2816 60568688 : quals |= cp_type_quals (TREE_TYPE (decl));
2817 60568688 : type = cp_build_qualified_type (type, quals);
2818 : }
2819 :
2820 62985851 : if (qualifying_scope)
2821 : /* Wrap this in a SCOPE_REF for now. */
2822 9472 : ret = build_qualified_name (type, qualifying_scope, decl,
2823 : /*template_p=*/false);
2824 : else
2825 62976379 : ret = (convert_from_reference
2826 62976379 : (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 16161095 : tree access_type = TREE_TYPE (object);
2833 :
2834 16161095 : 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 16161095 : if (qualifying_scope)
2841 : {
2842 2631 : tree binfo = NULL_TREE;
2843 2631 : object = build_scoped_ref (object, qualifying_scope,
2844 : &binfo);
2845 : }
2846 :
2847 16161095 : ret = build_class_member_access_expr (object, decl,
2848 : /*access_path=*/NULL_TREE,
2849 : /*preserve_reference=*/false,
2850 : complain);
2851 : }
2852 79146946 : 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 4949881520 : 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 4949881520 : if (deferred_access_no_check)
2876 : return true;
2877 :
2878 : /* Determine the SCOPE of DECL. */
2879 4938659556 : tree scope = context_for_name_lookup (decl);
2880 : /* If the SCOPE is not a type, then DECL is not a member. */
2881 4938659556 : 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 4938659556 : || dependent_type_p (scope))
2886 : return true;
2887 :
2888 472442566 : tree qualifying_type = NULL_TREE;
2889 : /* Compute the scope through which DECL is being accessed. */
2890 472442566 : 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 99744 : && CLASS_TYPE_P (object_type)
2900 472542293 : && 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 99718 : if (tree open = currently_open_class (object_type))
2905 : qualifying_type = open;
2906 : else
2907 : qualifying_type = object_type;
2908 : }
2909 472342848 : 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 629840035 : if (DECL_NONSTATIC_MEMBER_P (decl)
2915 314972695 : && current_class_ptr)
2916 41791 : if (tree current = current_nonlambda_class_type ())
2917 : {
2918 41746 : 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 4199 : 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 157422829 : qualifying_type = currently_open_derived_class (scope);
2938 :
2939 472342775 : 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 472405019 : && CLASS_TYPE_P (qualifying_type))
2943 444336134 : return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2944 444336134 : 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 85155240 : 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 85155240 : gcc_assert (TYPE_P (qualifying_class));
2967 :
2968 85155240 : if (error_operand_p (expr))
2969 21 : return error_mark_node;
2970 :
2971 85155219 : if (DECL_P (expr)
2972 : /* Functions are marked after overload resolution; avoid redundant
2973 : warnings. */
2974 77941764 : && TREE_CODE (expr) != FUNCTION_DECL
2975 163096959 : && !mark_used (expr, complain))
2976 0 : return error_mark_node;
2977 :
2978 85155219 : if (template_p)
2979 : {
2980 263242 : 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 263233 : 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 85155219 : if (address_p && done
2994 162613 : && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
2995 : {
2996 162611 : if (TREE_CODE (expr) == SCOPE_REF)
2997 0 : expr = TREE_OPERAND (expr, 1);
2998 162611 : expr = build_offset_ref (qualifying_class, expr,
2999 : /*address_p=*/true, complain);
3000 162611 : return expr;
3001 : }
3002 :
3003 : /* No need to check access within an enum. */
3004 84992608 : if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
3005 3774099 : && 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 81218512 : 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 81215828 : else if (TREE_CODE (expr) == FIELD_DECL)
3015 : {
3016 12150 : push_deferring_access_checks (dk_no_check);
3017 12150 : expr = finish_non_static_data_member (expr, NULL_TREE,
3018 : qualifying_class, complain);
3019 12150 : pop_deferring_access_checks ();
3020 : }
3021 81203678 : 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 6727842 : if (!shared_member_p (expr)
3026 447866 : && current_class_ptr
3027 7175021 : && DERIVED_FROM_P (qualifying_class,
3028 : current_nonlambda_class_type ()))
3029 446865 : expr = (build_class_member_access_expr
3030 446865 : (maybe_dummy_object (qualifying_class, NULL),
3031 : expr,
3032 446865 : BASELINK_ACCESS_BINFO (expr),
3033 : /*preserve_reference=*/false,
3034 : complain));
3035 6280977 : else if (done)
3036 : /* The expression is a qualified name whose address is not
3037 : being taken. */
3038 3621 : expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
3039 : complain);
3040 : }
3041 74475836 : else if (!template_p
3042 74262616 : && TREE_CODE (expr) == TEMPLATE_DECL
3043 74475920 : && !DECL_FUNCTION_TEMPLATE_P (expr))
3044 : {
3045 84 : if (complain & tf_error)
3046 5 : error ("%qE missing template arguments", expr);
3047 84 : 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 74475752 : if (processing_template_decl
3057 74475752 : && (!currently_open_class (qualifying_class)
3058 10606 : || TREE_CODE (expr) == IDENTIFIER_NODE
3059 10606 : || TREE_CODE (expr) == TEMPLATE_ID_EXPR
3060 82 : || TREE_CODE (expr) == BIT_NOT_EXPR))
3061 10929437 : expr = build_qualified_name (TREE_TYPE (expr),
3062 : qualifying_class, expr,
3063 : template_p);
3064 63546315 : else if (tree wrap = maybe_get_tls_wrapper_call (expr))
3065 9 : expr = wrap;
3066 :
3067 74475752 : 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 5621291 : begin_stmt_expr (void)
3078 : {
3079 5621291 : 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 29041 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
3089 : {
3090 29041 : 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 29038 : if (expr)
3101 : {
3102 29023 : tree type = TREE_TYPE (expr);
3103 :
3104 29023 : 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 29008 : 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 28839 : 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 28808 : expr = force_rvalue (expr, tf_warning_or_error);
3131 28808 : if (error_operand_p (expr))
3132 0 : return error_mark_node;
3133 :
3134 : /* Update for array-to-pointer decay. */
3135 28808 : type = TREE_TYPE (expr);
3136 :
3137 : /* This TARGET_EXPR will initialize the outer one added by
3138 : finish_stmt_expr. */
3139 28808 : 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 28808 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
3145 28808 : expr = maybe_cleanup_point_expr (expr);
3146 28808 : add_stmt (expr);
3147 : }
3148 :
3149 : /* The type of the statement-expression is the type of the last
3150 : expression. */
3151 29008 : 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 5621291 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
3163 : {
3164 5621291 : tree type;
3165 5621291 : tree result;
3166 :
3167 5621291 : if (error_operand_p (stmt_expr))
3168 : {
3169 18 : pop_stmt_list (stmt_expr);
3170 18 : return error_mark_node;
3171 : }
3172 :
3173 5621273 : gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
3174 :
3175 5621273 : type = TREE_TYPE (stmt_expr);
3176 5621273 : result = pop_stmt_list (stmt_expr);
3177 5621273 : TREE_TYPE (result) = type;
3178 :
3179 5621273 : if (processing_template_decl)
3180 : {
3181 37867 : result = build_min (STMT_EXPR, type, result);
3182 37867 : TREE_SIDE_EFFECTS (result) = 1;
3183 37867 : STMT_EXPR_NO_SCOPE (result) = has_no_scope;
3184 : }
3185 5583406 : 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 63385957 : empty_expr_stmt_p (tree expr_stmt)
3221 : {
3222 63385962 : tree body = NULL_TREE;
3223 :
3224 63385962 : if (expr_stmt == void_node)
3225 : return true;
3226 :
3227 63385959 : if (expr_stmt)
3228 : {
3229 63385959 : if (TREE_CODE (expr_stmt) == EXPR_STMT)
3230 5 : body = EXPR_STMT_EXPR (expr_stmt);
3231 63385954 : else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
3232 : body = expr_stmt;
3233 : }
3234 :
3235 5 : if (body)
3236 : {
3237 62410650 : if (TREE_CODE (body) == STATEMENT_LIST)
3238 62410645 : 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 19176625 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
3251 : tsubst_flags_t complain)
3252 : {
3253 19176625 : tree identifier = NULL_TREE;
3254 19176625 : tree functions = NULL_TREE;
3255 19176625 : tree tmpl_args = NULL_TREE;
3256 19176625 : bool template_id = false;
3257 19176625 : location_t loc = fn_expr.get_location ();
3258 19176625 : tree fn = fn_expr.get_value ();
3259 :
3260 19176625 : STRIP_ANY_LOCATION_WRAPPER (fn);
3261 :
3262 19176625 : if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
3263 : {
3264 : /* Use a separate flag to handle null args. */
3265 3668346 : template_id = true;
3266 3668346 : tmpl_args = TREE_OPERAND (fn, 1);
3267 3668346 : fn = TREE_OPERAND (fn, 0);
3268 : }
3269 :
3270 : /* Find the name of the overloaded function. */
3271 19176625 : if (identifier_p (fn))
3272 : identifier = fn;
3273 : else
3274 : {
3275 27094181 : functions = fn;
3276 18977725 : 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 19176625 : if (!any_type_dependent_arguments_p (args)
3284 19176625 : && !any_dependent_template_arguments_p (tmpl_args))
3285 : {
3286 18316657 : fn = lookup_arg_dependent (identifier, functions, args);
3287 18316657 : if (!fn)
3288 : {
3289 : /* The unqualified name could not be resolved. */
3290 59068 : if (complain & tf_error)
3291 393 : fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
3292 : else
3293 : fn = identifier;
3294 : }
3295 : }
3296 :
3297 19176625 : if (fn && template_id && fn != error_mark_node)
3298 3668333 : fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
3299 :
3300 19176625 : return cp_expr (fn, loc);
3301 : }
3302 :
3303 : /* Analyze call to a front-end builtin FN with arguments *ARGS. Return true
3304 : if the call is correct, false if erroneous. */
3305 :
3306 : static bool
3307 127363 : check_frontend_builtin (tree fn, vec<tree, va_gc> **args,
3308 : tsubst_flags_t complain)
3309 : {
3310 127363 : tree arg, ptype, type;
3311 127363 : switch (DECL_UNCHECKED_FUNCTION_CODE (fn))
3312 : {
3313 864 : case CP_BUILT_IN_IS_WITHIN_LIFETIME:
3314 864 : case CP_BUILT_IN_START_LIFETIME:
3315 : /* Unless users call the builtin directly, the following 2 checks
3316 : should be ensured from std::is_within_lifetime or
3317 : std::start_lifetime template. */
3318 864 : if (vec_safe_length (*args) != 1)
3319 : {
3320 14 : if (complain & tf_error)
3321 14 : error ("%qE needs a single argument", DECL_NAME (fn));
3322 : return false;
3323 : }
3324 850 : arg = (**args)[0];
3325 850 : if (error_operand_p (arg))
3326 : return false;
3327 850 : ptype = TREE_TYPE (arg);
3328 850 : if (!POINTER_TYPE_P (ptype))
3329 : {
3330 13 : if (complain & tf_error)
3331 13 : error ("%qE argument type %qT is not pointer type",
3332 13 : DECL_NAME (fn), ptype);
3333 : return false;
3334 : }
3335 837 : if (DECL_UNCHECKED_FUNCTION_CODE (fn) == CP_BUILT_IN_IS_WITHIN_LIFETIME)
3336 : return true;
3337 347 : type = TREE_TYPE (ptype);
3338 347 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
3339 : return false;
3340 347 : if (!CP_AGGREGATE_TYPE_P (type))
3341 : {
3342 10 : if (complain & tf_error)
3343 10 : error ("%qE argument type %qT is not a pointer to aggregate type",
3344 10 : DECL_NAME (fn), ptype);
3345 : return false;
3346 : }
3347 337 : if (!implicit_lifetime_type_p (type))
3348 : {
3349 4 : if (complain & tf_error)
3350 4 : error ("%qE argument type %qT is not a pointer to "
3351 4 : "implicit-lifetime type", DECL_NAME (fn), ptype);
3352 : return false;
3353 : }
3354 : return true;
3355 : default:
3356 : return true;
3357 : }
3358 : }
3359 :
3360 : /* Generate an expression for `FN (ARGS)'. This may change the
3361 : contents of ARGS.
3362 :
3363 : If DISALLOW_VIRTUAL is true, the call to FN will be not generated
3364 : as a virtual call, even if FN is virtual. (This flag is set when
3365 : encountering an expression where the function name is explicitly
3366 : qualified. For example a call to `X::f' never generates a virtual
3367 : call.)
3368 :
3369 : Returns code for the call. */
3370 :
3371 : tree
3372 372473067 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
3373 : bool koenig_p, tsubst_flags_t complain)
3374 : {
3375 372473067 : tree result;
3376 372473067 : tree orig_fn;
3377 372473067 : vec<tree, va_gc> *orig_args = *args;
3378 372473067 : tsubst_flags_t orig_complain = complain;
3379 :
3380 372473067 : if (fn == error_mark_node)
3381 : return error_mark_node;
3382 :
3383 372471997 : complain &= ~tf_any_viable;
3384 372471997 : gcc_assert (!TYPE_P (fn));
3385 :
3386 : /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
3387 : it so that we can tell this is a call to a known function. */
3388 372471997 : fn = maybe_undo_parenthesized_ref (fn);
3389 :
3390 372471997 : STRIP_ANY_LOCATION_WRAPPER (fn);
3391 :
3392 372471997 : orig_fn = fn;
3393 :
3394 372471997 : if (concept_check_p (fn))
3395 : {
3396 6 : error_at (EXPR_LOC_OR_LOC (fn, input_location),
3397 : "cannot call a concept as a function");
3398 6 : return error_mark_node;
3399 : }
3400 :
3401 372471991 : if (processing_template_decl)
3402 : {
3403 : /* If FN is a local extern declaration (or set thereof) in a template,
3404 : look it up again at instantiation time. */
3405 239784454 : if (is_overloaded_fn (fn))
3406 : {
3407 147020815 : tree ifn = get_first_fn (fn);
3408 147020815 : if (TREE_CODE (ifn) == FUNCTION_DECL
3409 147020815 : && dependent_local_decl_p (ifn))
3410 40579 : orig_fn = DECL_NAME (ifn);
3411 : }
3412 :
3413 : /* If the call expression is dependent, build a CALL_EXPR node
3414 : with no type; type_dependent_expression_p recognizes
3415 : expressions with no type as being dependent. */
3416 239784454 : if (type_dependent_expression_p (fn)
3417 239784454 : || any_type_dependent_arguments_p (*args))
3418 : {
3419 217979732 : if (koenig_p
3420 10635421 : && TREE_CODE (orig_fn) == FUNCTION_DECL
3421 221314115 : && !fndecl_built_in_p (orig_fn))
3422 : /* For an ADL-enabled call where unqualified lookup found a
3423 : single non-template function, wrap it in an OVERLOAD so that
3424 : later substitution doesn't overeagerly mark the function as
3425 : used. */
3426 856550 : orig_fn = ovl_make (orig_fn, NULL_TREE);
3427 217979732 : result = build_min_nt_call_vec (orig_fn, *args);
3428 296331066 : SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
3429 217979732 : KOENIG_LOOKUP_P (result) = koenig_p;
3430 : /* Disable the std::move warnings since this call was dependent
3431 : (c++/89780, c++/107363). This also suppresses the
3432 : -Wredundant-move warning. */
3433 217979732 : suppress_warning (result, OPT_Wpessimizing_move);
3434 :
3435 217979732 : if (cfun && cp_function_chain && !cp_unevaluated_operand)
3436 : {
3437 189949053 : bool abnormal = true;
3438 190234412 : for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
3439 : {
3440 105477738 : tree fndecl = STRIP_TEMPLATE (*iter);
3441 105477738 : if (TREE_CODE (fndecl) != FUNCTION_DECL
3442 105477660 : || !TREE_THIS_VOLATILE (fndecl))
3443 : {
3444 : abnormal = false;
3445 : break;
3446 : }
3447 : }
3448 : /* FIXME: Stop warning about falling off end of non-void
3449 : function. But this is wrong. Even if we only see
3450 : no-return fns at this point, we could select a
3451 : future-defined return fn during instantiation. Or
3452 : vice-versa. */
3453 189949053 : if (abnormal)
3454 84756674 : current_function_returns_abnormally = 1;
3455 : }
3456 217979732 : if (TREE_CODE (fn) == COMPONENT_REF)
3457 100870626 : maybe_generic_this_capture (TREE_OPERAND (fn, 0),
3458 100870626 : TREE_OPERAND (fn, 1));
3459 : return result;
3460 : }
3461 21804722 : orig_args = make_tree_vector_copy (*args);
3462 : }
3463 :
3464 154492259 : if (TREE_CODE (fn) == COMPONENT_REF)
3465 : {
3466 29436601 : tree member = TREE_OPERAND (fn, 1);
3467 29436601 : if (BASELINK_P (member))
3468 : {
3469 29247846 : tree object = TREE_OPERAND (fn, 0);
3470 58087079 : return build_new_method_call (object, member,
3471 : args, NULL_TREE,
3472 : (disallow_virtual
3473 : ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
3474 : : LOOKUP_NORMAL),
3475 : /*fn_p=*/NULL,
3476 29247846 : complain);
3477 : }
3478 : }
3479 :
3480 : /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
3481 125244413 : if (TREE_CODE (fn) == ADDR_EXPR
3482 125244413 : && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
3483 9 : fn = TREE_OPERAND (fn, 0);
3484 :
3485 125244413 : if (is_overloaded_fn (fn))
3486 116420725 : fn = baselink_for_fns (fn);
3487 :
3488 125244413 : result = NULL_TREE;
3489 125244413 : if (BASELINK_P (fn))
3490 : {
3491 14158042 : tree object;
3492 :
3493 : /* A call to a member function. From [over.call.func]:
3494 :
3495 : If the keyword this is in scope and refers to the class of
3496 : that member function, or a derived class thereof, then the
3497 : function call is transformed into a qualified function call
3498 : using (*this) as the postfix-expression to the left of the
3499 : . operator.... [Otherwise] a contrived object of type T
3500 : becomes the implied object argument.
3501 :
3502 : In this situation:
3503 :
3504 : struct A { void f(); };
3505 : struct B : public A {};
3506 : struct C : public A { void g() { B::f(); }};
3507 :
3508 : "the class of that member function" refers to `A'. But 11.2
3509 : [class.access.base] says that we need to convert 'this' to B* as
3510 : part of the access, so we pass 'B' to maybe_dummy_object. */
3511 :
3512 14158042 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
3513 : {
3514 : /* A constructor call always uses a dummy object. (This constructor
3515 : call which has the form A::A () is actually invalid and we are
3516 : going to reject it later in build_new_method_call.) */
3517 39 : object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
3518 : }
3519 : else
3520 14158003 : object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
3521 : NULL);
3522 :
3523 16147615 : result = build_new_method_call (object, fn, args, NULL_TREE,
3524 : (disallow_virtual
3525 : ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
3526 : : LOOKUP_NORMAL),
3527 : /*fn_p=*/NULL,
3528 : complain);
3529 : }
3530 111086371 : else if (is_overloaded_fn (fn))
3531 : {
3532 : /* If the function is an overloaded builtin, resolve it. */
3533 102262683 : if (TREE_CODE (fn) == FUNCTION_DECL
3534 102262683 : && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
3535 18946062 : || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
3536 9604040 : result = resolve_overloaded_builtin (input_location, fn, *args,
3537 : complain & tf_error);
3538 :
3539 9604040 : if (!result)
3540 : {
3541 101918344 : tree alloc_size_attr = NULL_TREE;
3542 101918344 : if (warn_calloc_transposed_args
3543 715753 : && TREE_CODE (fn) == FUNCTION_DECL
3544 101918344 : && (alloc_size_attr
3545 432841 : = lookup_attribute ("alloc_size",
3546 432841 : TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
3547 3399 : if (TREE_VALUE (alloc_size_attr) == NULL_TREE
3548 3399 : || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
3549 : alloc_size_attr = NULL_TREE;
3550 100175316 : if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
3551 1743088 : && (complain & tf_warning)
3552 1522323 : && !vec_safe_is_empty (*args)
3553 103086162 : && !processing_template_decl)
3554 : {
3555 : location_t sizeof_arg_loc[6];
3556 : tree sizeof_arg[6];
3557 : unsigned int i;
3558 8390996 : for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
3559 : {
3560 3146826 : tree t;
3561 :
3562 3146826 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
3563 3146826 : sizeof_arg[i] = NULL_TREE;
3564 3146826 : if (i >= (*args)->length ())
3565 657497 : continue;
3566 2489329 : t = (**args)[i];
3567 2489329 : if (TREE_CODE (t) != SIZEOF_EXPR)
3568 2482654 : continue;
3569 6675 : if (SIZEOF_EXPR_TYPE_P (t))
3570 2663 : sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
3571 : else
3572 4012 : sizeof_arg[i] = TREE_OPERAND (t, 0);
3573 6675 : sizeof_arg_loc[i] = EXPR_LOCATION (t);
3574 : }
3575 1048882 : if (warn_sizeof_pointer_memaccess)
3576 : {
3577 1048822 : auto same_p = same_type_ignoring_top_level_qualifiers_p;
3578 1048822 : sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
3579 : sizeof_arg, same_p);
3580 : }
3581 1048882 : if (alloc_size_attr)
3582 60 : warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
3583 : alloc_size_attr);
3584 : }
3585 :
3586 101918344 : if ((complain & tf_warning)
3587 56208976 : && TREE_CODE (fn) == FUNCTION_DECL
3588 26803099 : && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
3589 145425 : && vec_safe_length (*args) == 3
3590 102063769 : && !any_type_dependent_arguments_p (*args))
3591 : {
3592 145425 : tree arg0 = (*orig_args)[0];
3593 145425 : tree arg1 = (*orig_args)[1];
3594 145425 : tree arg2 = (*orig_args)[2];
3595 145425 : int literal_mask = ((literal_integer_zerop (arg1) << 1)
3596 145425 : | (literal_integer_zerop (arg2) << 2));
3597 145425 : warn_for_memset (input_location, arg0, arg2, literal_mask);
3598 : }
3599 :
3600 101918344 : if (TREE_CODE (fn) == FUNCTION_DECL
3601 26929280 : && fndecl_built_in_p (fn, BUILT_IN_FRONTEND)
3602 102045707 : && !check_frontend_builtin (fn, args, complain))
3603 41 : return error_mark_node;
3604 :
3605 : /* A call to a namespace-scope function. */
3606 101918303 : result = build_new_function_call (fn, args, orig_complain);
3607 : }
3608 : }
3609 8823688 : else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
3610 : {
3611 159214 : if (!vec_safe_is_empty (*args))
3612 0 : error ("arguments to destructor are not allowed");
3613 : /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
3614 : which case the postfix-expression is a possibly-parenthesized class
3615 : member access), the function call destroys the object of scalar type
3616 : denoted by the object expression of the class member access. */
3617 159214 : tree ob = TREE_OPERAND (fn, 0);
3618 159214 : if (obvalue_p (ob))
3619 159196 : result = build_trivial_dtor_call (ob, true);
3620 : else
3621 : /* No location to clobber. */
3622 18 : result = convert_to_void (ob, ICV_STATEMENT, complain);
3623 : }
3624 8664474 : else if (CLASS_TYPE_P (TREE_TYPE (fn)))
3625 : /* If the "function" is really an object of class type, it might
3626 : have an overloaded `operator ()'. */
3627 2634860 : result = build_op_call (fn, args, complain);
3628 :
3629 118856901 : if (!result)
3630 : /* A call where the function is unknown. */
3631 6029614 : result = cp_build_function_call_vec (fn, args, complain);
3632 :
3633 125230854 : if (processing_template_decl && result != error_mark_node)
3634 : {
3635 16687813 : if (INDIRECT_REF_P (result))
3636 1135894 : result = TREE_OPERAND (result, 0);
3637 :
3638 : /* Prune all but the selected function from the original overload
3639 : set so that we can avoid some duplicate work at instantiation time. */
3640 16687813 : if (TREE_CODE (result) == CALL_EXPR
3641 16678096 : && really_overloaded_fn (orig_fn))
3642 : {
3643 6157558 : tree sel_fn = CALL_EXPR_FN (result);
3644 6157558 : if (TREE_CODE (sel_fn) == COMPONENT_REF)
3645 : {
3646 : /* The non-dependent result of build_new_method_call. */
3647 260050 : sel_fn = TREE_OPERAND (sel_fn, 1);
3648 260050 : gcc_assert (BASELINK_P (sel_fn));
3649 : }
3650 5897508 : else if (TREE_CODE (sel_fn) == ADDR_EXPR)
3651 : /* Our original callee wasn't wrapped in an ADDR_EXPR,
3652 : so strip this ADDR_EXPR added by build_over_call. */
3653 5897508 : sel_fn = TREE_OPERAND (sel_fn, 0);
3654 : orig_fn = sel_fn;
3655 : }
3656 :
3657 16687813 : tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
3658 16687813 : SET_EXPR_LOCATION (r, input_location);
3659 16687813 : KOENIG_LOOKUP_P (r) = koenig_p;
3660 16687813 : TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
3661 16687813 : release_tree_vector (orig_args);
3662 16687813 : result = convert_from_reference (r);
3663 : }
3664 :
3665 : return result;
3666 : }
3667 :
3668 : /* Finish a call to a postfix increment or decrement or EXPR. (Which
3669 : is indicated by CODE, which should be POSTINCREMENT_EXPR or
3670 : POSTDECREMENT_EXPR.) */
3671 :
3672 : cp_expr
3673 2663543 : finish_increment_expr (cp_expr expr, enum tree_code code)
3674 : {
3675 : /* input_location holds the location of the trailing operator token.
3676 : Build a location of the form:
3677 : expr++
3678 : ~~~~^~
3679 : with the caret at the operator token, ranging from the start
3680 : of EXPR to the end of the operator token. */
3681 2663543 : location_t combined_loc = make_location (input_location,
3682 : expr.get_start (),
3683 : get_finish (input_location));
3684 2663543 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3685 2663543 : NULL_TREE, tf_warning_or_error);
3686 : /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3687 2663543 : result.set_location (combined_loc);
3688 2663543 : return result;
3689 : }
3690 :
3691 : /* Finish a use of `this'. Returns an expression for `this'. */
3692 :
3693 : tree
3694 36768336 : finish_this_expr (void)
3695 : {
3696 36768336 : tree result = NULL_TREE;
3697 :
3698 73536548 : if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
3699 36469033 : result = current_class_ptr;
3700 598590 : else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
3701 299227 : result = (lambda_expr_this_capture
3702 299227 : (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
3703 : else
3704 76 : gcc_checking_assert (!current_class_ptr);
3705 :
3706 36768260 : if (result)
3707 : /* The keyword 'this' is a prvalue expression. */
3708 36768257 : return rvalue (result);
3709 :
3710 79 : tree fn = current_nonlambda_function ();
3711 79 : if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
3712 : {
3713 6 : auto_diagnostic_group d;
3714 6 : error ("%<this%> is unavailable for explicit object member "
3715 : "functions");
3716 6 : tree xobj_parm = DECL_ARGUMENTS (fn);
3717 6 : gcc_assert (xobj_parm);
3718 6 : tree parm_name = DECL_NAME (xobj_parm);
3719 :
3720 6 : static tree remembered_fn = NULL_TREE;
3721 : /* Only output this diagnostic once per function. */
3722 6 : if (remembered_fn == fn)
3723 : /* Early escape. */;
3724 6 : else if (parm_name)
3725 6 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3726 : "use explicit object parameter %qs instead",
3727 3 : IDENTIFIER_POINTER (parm_name));
3728 : else
3729 3 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3730 : "name the explicit object parameter");
3731 :
3732 6 : remembered_fn = fn;
3733 6 : }
3734 73 : else if (fn && DECL_STATIC_FUNCTION_P (fn))
3735 3 : error ("%<this%> is unavailable for static member functions");
3736 70 : else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
3737 0 : error ("invalid use of %<this%> in a constructor %<pre%> condition");
3738 70 : else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
3739 0 : error ("invalid use of %<this%> in a destructor %<post%> condition");
3740 70 : else if (fn)
3741 22 : error ("invalid use of %<this%> in non-member function");
3742 : else
3743 48 : error ("invalid use of %<this%> at top level");
3744 79 : return error_mark_node;
3745 : }
3746 :
3747 : /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3748 : expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3749 : the TYPE for the type given. If SCOPE is non-NULL, the expression
3750 : was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3751 :
3752 : tree
3753 159265 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
3754 : location_t loc, tsubst_flags_t complain)
3755 : {
3756 159265 : if (object == error_mark_node || destructor == error_mark_node)
3757 : return error_mark_node;
3758 :
3759 159256 : gcc_assert (TYPE_P (destructor));
3760 :
3761 159256 : if (!processing_template_decl)
3762 : {
3763 159235 : if (scope == error_mark_node)
3764 : {
3765 0 : if (complain & tf_error)
3766 0 : error_at (loc, "invalid qualifying scope in pseudo-destructor name");
3767 0 : return error_mark_node;
3768 : }
3769 159235 : if (is_auto (destructor))
3770 3 : destructor = TREE_TYPE (object);
3771 159235 : if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
3772 : {
3773 3 : if (complain & tf_error)
3774 3 : error_at (loc,
3775 : "qualified type %qT does not match destructor name ~%qT",
3776 : scope, destructor);
3777 3 : return error_mark_node;
3778 : }
3779 :
3780 :
3781 : /* [expr.pseudo] says both:
3782 :
3783 : The type designated by the pseudo-destructor-name shall be
3784 : the same as the object type.
3785 :
3786 : and:
3787 :
3788 : The cv-unqualified versions of the object type and of the
3789 : type designated by the pseudo-destructor-name shall be the
3790 : same type.
3791 :
3792 : We implement the more generous second sentence, since that is
3793 : what most other compilers do. */
3794 159232 : if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
3795 : destructor))
3796 : {
3797 12 : if (complain & tf_error)
3798 9 : error_at (loc, "%qE is not of type %qT", object, destructor);
3799 12 : return error_mark_node;
3800 : }
3801 : }
3802 :
3803 159241 : tree type = (type_dependent_expression_p (object)
3804 159241 : ? NULL_TREE : void_type_node);
3805 :
3806 159241 : return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
3807 159241 : scope, destructor);
3808 : }
3809 :
3810 : /* Finish an expression of the form CODE EXPR. */
3811 :
3812 : cp_expr
3813 39143097 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
3814 : tsubst_flags_t complain)
3815 : {
3816 : /* Build a location of the form:
3817 : ++expr
3818 : ^~~~~~
3819 : with the caret at the operator token, ranging from the start
3820 : of the operator token to the end of EXPR. */
3821 39143097 : location_t combined_loc = make_location (op_loc,
3822 : op_loc, expr.get_finish ());
3823 39143097 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3824 39143097 : NULL_TREE, complain);
3825 : /* TODO: build_x_unary_op doesn't always honor the location. */
3826 39143097 : result.set_location (combined_loc);
3827 :
3828 39143097 : if (result == error_mark_node)
3829 : return result;
3830 :
3831 39142594 : if (!(complain & tf_warning))
3832 : return result;
3833 :
3834 : /* These will never fold into a constant, so no need to check for
3835 : overflow for them. */
3836 39142594 : if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
3837 : return result;
3838 :
3839 21167773 : tree result_ovl = result;
3840 21167773 : tree expr_ovl = expr;
3841 :
3842 21167773 : if (!processing_template_decl)
3843 1846171 : expr_ovl = cp_fully_fold (expr_ovl);
3844 :
3845 21167773 : if (!CONSTANT_CLASS_P (expr_ovl)
3846 21167773 : || TREE_OVERFLOW_P (expr_ovl))
3847 : return result;
3848 :
3849 256740 : if (!processing_template_decl)
3850 247129 : result_ovl = cp_fully_fold (result_ovl);
3851 :
3852 256740 : if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
3853 9 : overflow_warning (combined_loc, result_ovl);
3854 :
3855 : return result;
3856 : }
3857 :
3858 : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3859 : elements. */
3860 :
3861 : static bool
3862 12 : maybe_zero_constructor_nelts (tree expr)
3863 : {
3864 12 : if (CONSTRUCTOR_NELTS (expr) == 0)
3865 : return true;
3866 12 : if (!processing_template_decl)
3867 : return false;
3868 30 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
3869 21 : if (!PACK_EXPANSION_P (elt.value))
3870 : return false;
3871 : return true;
3872 : }
3873 :
3874 : /* Finish a compound-literal expression or C++11 functional cast with aggregate
3875 : initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3876 : is being cast. */
3877 :
3878 : tree
3879 10127489 : finish_compound_literal (tree type, tree compound_literal,
3880 : tsubst_flags_t complain,
3881 : fcl_t fcl_context)
3882 : {
3883 10127489 : if (type == error_mark_node)
3884 : return error_mark_node;
3885 :
3886 10127437 : if (TYPE_REF_P (type))
3887 : {
3888 12 : compound_literal
3889 12 : = finish_compound_literal (TREE_TYPE (type), compound_literal,
3890 : complain, fcl_context);
3891 : /* The prvalue is then used to direct-initialize the reference. */
3892 12 : tree r = (perform_implicit_conversion_flags
3893 12 : (type, compound_literal, complain, LOOKUP_NORMAL));
3894 12 : return convert_from_reference (r);
3895 : }
3896 :
3897 10127425 : if (!TYPE_OBJ_P (type))
3898 : {
3899 : /* DR2351 */
3900 60 : if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
3901 : {
3902 12 : if (!processing_template_decl)
3903 9 : return void_node;
3904 3 : TREE_TYPE (compound_literal) = type;
3905 3 : TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
3906 3 : CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
3907 3 : return compound_literal;
3908 : }
3909 21 : else if (VOID_TYPE_P (type)
3910 15 : && processing_template_decl
3911 33 : && maybe_zero_constructor_nelts (compound_literal))
3912 : /* If there are only packs in compound_literal, it could
3913 : be void{} after pack expansion. */;
3914 : else
3915 : {
3916 12 : if (complain & tf_error)
3917 9 : error ("compound literal of non-object type %qT", type);
3918 12 : return error_mark_node;
3919 : }
3920 : }
3921 :
3922 10127401 : if (template_placeholder_p (type))
3923 : {
3924 193458 : type = do_auto_deduction (type, compound_literal, type, complain,
3925 : adc_variable_type);
3926 193458 : if (type == error_mark_node)
3927 : return error_mark_node;
3928 : }
3929 : /* C++23 auto{x}. */
3930 9933943 : else if (is_auto (type)
3931 162 : && !AUTO_IS_DECLTYPE (type)
3932 9934102 : && CONSTRUCTOR_NELTS (compound_literal) == 1)
3933 : {
3934 150 : if (is_constrained_auto (type))
3935 : {
3936 3 : if (complain & tf_error)
3937 3 : error ("%<auto{x}%> cannot be constrained");
3938 3 : return error_mark_node;
3939 : }
3940 147 : else if (cxx_dialect < cxx23)
3941 : {
3942 1 : if ((complain & tf_warning_or_error) == 0)
3943 0 : return error_mark_node;
3944 1 : pedwarn (input_location, OPT_Wc__23_extensions,
3945 : "%<auto{x}%> only available with "
3946 : "%<-std=c++23%> or %<-std=gnu++23%>");
3947 : }
3948 147 : type = do_auto_deduction (type, compound_literal, type, complain,
3949 : adc_variable_type);
3950 147 : if (type == error_mark_node)
3951 : return error_mark_node;
3952 : }
3953 :
3954 : /* Used to hold a copy of the compound literal in a template. */
3955 10127254 : tree orig_cl = NULL_TREE;
3956 :
3957 10127254 : if (processing_template_decl)
3958 : {
3959 5231846 : const bool dependent_p
3960 5231846 : = (instantiation_dependent_expression_p (compound_literal)
3961 5231846 : || dependent_type_p (type));
3962 1752924 : if (dependent_p)
3963 : /* We're about to return, no need to copy. */
3964 : orig_cl = compound_literal;
3965 : else
3966 : /* We're going to need a copy. */
3967 1752924 : orig_cl = unshare_constructor (compound_literal);
3968 5231846 : TREE_TYPE (orig_cl) = type;
3969 : /* Mark the expression as a compound literal. */
3970 5231846 : TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
3971 : /* And as instantiation-dependent. */
3972 5231846 : CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
3973 5231846 : if (fcl_context == fcl_c99)
3974 130 : CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
3975 : /* If the compound literal is dependent, we're done for now. */
3976 5231846 : if (dependent_p)
3977 : return orig_cl;
3978 : /* Otherwise, do go on to e.g. check narrowing. */
3979 : }
3980 :
3981 6648332 : type = complete_type (type);
3982 :
3983 6648332 : if (TYPE_NON_AGGREGATE_CLASS (type))
3984 : {
3985 : /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3986 : everywhere that deals with function arguments would be a pain, so
3987 : just wrap it in a TREE_LIST. The parser set a flag so we know
3988 : that it came from T{} rather than T({}). */
3989 1076960 : CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
3990 1076960 : compound_literal = build_tree_list (NULL_TREE, compound_literal);
3991 1076960 : return build_functional_cast (input_location, type,
3992 1076960 : compound_literal, complain);
3993 : }
3994 :
3995 5571372 : if (TREE_CODE (type) == ARRAY_TYPE
3996 5571372 : && check_array_initializer (NULL_TREE, type, compound_literal))
3997 9 : return error_mark_node;
3998 5571363 : compound_literal = reshape_init (type, compound_literal, complain);
3999 5571363 : if (SCALAR_TYPE_P (type)
4000 746310 : && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
4001 216849 : && !check_narrowing (type, compound_literal, complain))
4002 131 : return error_mark_node;
4003 5571232 : if (TREE_CODE (type) == ARRAY_TYPE
4004 5571232 : && TYPE_DOMAIN (type) == NULL_TREE)
4005 : {
4006 1253 : cp_complete_array_type_or_error (&type, compound_literal,
4007 : false, complain);
4008 1253 : if (type == error_mark_node)
4009 : return error_mark_node;
4010 : }
4011 5571229 : if (abstract_virtuals_error (ACU_UNKNOWN, type, complain))
4012 7 : return error_mark_node;
4013 5571222 : compound_literal = digest_init_flags (type, compound_literal,
4014 : LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
4015 : complain);
4016 5571222 : if (compound_literal == error_mark_node)
4017 : return error_mark_node;
4018 :
4019 : /* If we're in a template, return the original compound literal. */
4020 5570542 : if (orig_cl)
4021 : return orig_cl;
4022 :
4023 3905794 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
4024 : {
4025 3215425 : TREE_HAS_CONSTRUCTOR (compound_literal) = true;
4026 3215425 : if (fcl_context == fcl_c99)
4027 37973 : CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
4028 : }
4029 :
4030 : /* Put static/constant array temporaries in static variables. */
4031 : /* FIXME all C99 compound literals should be variables rather than C++
4032 : temporaries, unless they are used as an aggregate initializer. */
4033 5243994 : if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
4034 2577012 : && fcl_context == fcl_c99
4035 83 : && TREE_CODE (type) == ARRAY_TYPE
4036 31 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
4037 3905825 : && initializer_constant_valid_p (compound_literal, type))
4038 : {
4039 31 : tree decl = create_temporary_var (type);
4040 31 : DECL_CONTEXT (decl) = NULL_TREE;
4041 31 : DECL_INITIAL (decl) = compound_literal;
4042 31 : TREE_STATIC (decl) = 1;
4043 31 : if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
4044 : {
4045 : /* 5.19 says that a constant expression can include an
4046 : lvalue-rvalue conversion applied to "a glvalue of literal type
4047 : that refers to a non-volatile temporary object initialized
4048 : with a constant expression". Rather than try to communicate
4049 : that this VAR_DECL is a temporary, just mark it constexpr. */
4050 24 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
4051 24 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
4052 24 : TREE_CONSTANT (decl) = true;
4053 : }
4054 31 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
4055 31 : decl = pushdecl_top_level (decl);
4056 31 : DECL_NAME (decl) = make_anon_name ();
4057 31 : SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
4058 : /* Make sure the destructor is callable. */
4059 31 : tree clean = cxx_maybe_build_cleanup (decl, complain);
4060 31 : if (clean == error_mark_node)
4061 : return error_mark_node;
4062 31 : return decl;
4063 : }
4064 :
4065 : /* Represent other compound literals with TARGET_EXPR so we produce
4066 : a prvalue, and can elide copies. */
4067 3905763 : if (!VECTOR_TYPE_P (type)
4068 3865190 : && (TREE_CODE (compound_literal) == CONSTRUCTOR
4069 690363 : || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
4070 : {
4071 : /* The CONSTRUCTOR is now an initializer, not a compound literal. */
4072 3174827 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
4073 3174827 : TREE_HAS_CONSTRUCTOR (compound_literal) = false;
4074 3174827 : compound_literal = get_target_expr (compound_literal, complain);
4075 : }
4076 : else
4077 : /* For e.g. int{42} just make sure it's a prvalue. */
4078 730936 : compound_literal = rvalue (compound_literal);
4079 :
4080 : return compound_literal;
4081 : }
4082 :
4083 : /* Return the declaration for the function-name variable indicated by
4084 : ID. */
4085 :
4086 : tree
4087 308111 : finish_fname (tree id)
4088 : {
4089 308111 : tree decl = fname_decl (input_location, C_RID_CODE (id), id);
4090 : /* [expr.prim.lambda.closure]/16 "Unless the compound-statement is that
4091 : of a consteval-block-declaration, a variable __func__ is implicitly
4092 : defined...". We could be in a consteval block in a function, though,
4093 : and then we shouldn't warn. */
4094 308111 : if (current_function_decl
4095 308111 : && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
4096 8 : pedwarn (input_location, 0, "%qD is not defined outside of function scope",
4097 : decl);
4098 308111 : if (processing_template_decl && current_function_decl
4099 229257 : && decl != error_mark_node)
4100 229257 : decl = DECL_NAME (decl);
4101 308111 : return decl;
4102 : }
4103 :
4104 : /* Finish a translation unit. */
4105 :
4106 : void
4107 99419 : finish_translation_unit (void)
4108 : {
4109 : /* In case there were missing closebraces,
4110 : get us back to the global binding level. */
4111 99419 : pop_everything ();
4112 198838 : while (current_namespace != global_namespace)
4113 0 : pop_namespace ();
4114 :
4115 : /* Do file scope __FUNCTION__ et al. */
4116 99419 : finish_fname_decls ();
4117 :
4118 99419 : if (vec_safe_length (scope_chain->omp_declare_target_attribute))
4119 : {
4120 12 : cp_omp_declare_target_attr
4121 12 : a = scope_chain->omp_declare_target_attribute->pop ();
4122 12 : if (!errorcount)
4123 9 : error ("%qs without corresponding %qs",
4124 : a.device_type >= 0 ? "#pragma omp begin declare target"
4125 : : "#pragma omp declare target",
4126 : "#pragma omp end declare target");
4127 24 : vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
4128 : }
4129 99419 : if (vec_safe_length (scope_chain->omp_declare_variant_attribute))
4130 : {
4131 0 : if (!errorcount)
4132 0 : error ("%<omp begin declare variant%> without corresponding "
4133 : "%<omp end declare variant%>");
4134 0 : vec_safe_truncate (scope_chain->omp_declare_variant_attribute, 0);
4135 : }
4136 99419 : if (vec_safe_length (scope_chain->omp_begin_assumes))
4137 : {
4138 3 : if (!errorcount)
4139 3 : error ("%qs without corresponding %qs",
4140 : "#pragma omp begin assumes", "#pragma omp end assumes");
4141 3 : vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
4142 : }
4143 99419 : }
4144 :
4145 : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
4146 : Returns the parameter. */
4147 :
4148 : tree
4149 163343674 : finish_template_type_parm (tree aggr, tree identifier)
4150 : {
4151 163343674 : if (aggr != class_type_node)
4152 : {
4153 0 : permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
4154 0 : aggr = class_type_node;
4155 : }
4156 :
4157 163343674 : return build_tree_list (aggr, identifier);
4158 : }
4159 :
4160 : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
4161 : Returns the parameter. */
4162 :
4163 : tree
4164 413772 : finish_template_template_parm (tree aggr, tree identifier)
4165 : {
4166 413772 : tree decl = build_decl (input_location,
4167 : TYPE_DECL, identifier, NULL_TREE);
4168 :
4169 413772 : tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
4170 413772 : DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
4171 413772 : DECL_TEMPLATE_RESULT (tmpl) = decl;
4172 413772 : DECL_ARTIFICIAL (decl) = 1;
4173 :
4174 : /* Associate the constraints with the underlying declaration,
4175 : not the template. */
4176 413772 : tree constr = current_template_constraints ();
4177 413772 : set_constraints (decl, constr);
4178 :
4179 413772 : end_template_decl ();
4180 :
4181 413772 : gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
4182 :
4183 413772 : check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
4184 : /*is_primary=*/true, /*is_partial=*/false,
4185 : /*is_friend=*/0);
4186 :
4187 413772 : return finish_template_type_parm (aggr, tmpl);
4188 : }
4189 :
4190 : /* ARGUMENT is the default-argument value for a template template
4191 : parameter. If ARGUMENT is invalid, issue error messages and return
4192 : the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
4193 :
4194 : tree
4195 876 : check_template_template_default_arg (tree argument)
4196 : {
4197 876 : if (TREE_CODE (argument) != TEMPLATE_DECL
4198 : && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
4199 : && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
4200 : {
4201 : if (TREE_CODE (argument) == TYPE_DECL)
4202 : {
4203 18 : if (tree t = maybe_get_template_decl_from_type_decl (argument))
4204 18 : if (TREE_CODE (t) == TEMPLATE_DECL)
4205 : return t;
4206 15 : error ("invalid use of type %qT as a default value for a template "
4207 15 : "template-parameter", TREE_TYPE (argument));
4208 : }
4209 : else
4210 0 : error ("invalid default argument for a template template parameter");
4211 15 : return error_mark_node;
4212 : }
4213 :
4214 : return argument;
4215 : }
4216 :
4217 : /* Begin a class definition, as indicated by T. */
4218 :
4219 : tree
4220 31336173 : begin_class_definition (tree t)
4221 : {
4222 31336173 : if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
4223 33 : return error_mark_node;
4224 :
4225 31336290 : if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
4226 : {
4227 24 : error ("definition of %q#T inside template parameter list", t);
4228 24 : return error_mark_node;
4229 : }
4230 :
4231 : /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
4232 : are passed the same as decimal scalar types. */
4233 31336116 : if (TREE_CODE (t) == RECORD_TYPE
4234 30814000 : && !processing_template_decl)
4235 : {
4236 11038162 : tree ns = TYPE_CONTEXT (t);
4237 11038159 : if (ns && TREE_CODE (ns) == NAMESPACE_DECL
4238 9055237 : && DECL_CONTEXT (ns) == std_node
4239 2203534 : && DECL_NAME (ns)
4240 13241676 : && id_equal (DECL_NAME (ns), "decimal"))
4241 : {
4242 150 : const char *n = TYPE_NAME_STRING (t);
4243 150 : if ((strcmp (n, "decimal32") == 0)
4244 101 : || (strcmp (n, "decimal64") == 0)
4245 46 : || (strcmp (n, "decimal128") == 0))
4246 147 : TYPE_TRANSPARENT_AGGR (t) = 1;
4247 : }
4248 : }
4249 :
4250 : /* A non-implicit typename comes from code like:
4251 :
4252 : template <typename T> struct A {
4253 : template <typename U> struct A<T>::B ...
4254 :
4255 : This is erroneous. */
4256 20297954 : else if (TREE_CODE (t) == TYPENAME_TYPE)
4257 : {
4258 0 : error ("invalid definition of qualified type %qT", t);
4259 0 : t = error_mark_node;
4260 : }
4261 :
4262 31336116 : if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
4263 : {
4264 0 : t = make_class_type (RECORD_TYPE);
4265 0 : pushtag (make_anon_name (), t);
4266 : }
4267 :
4268 31336116 : if (TYPE_BEING_DEFINED (t))
4269 : {
4270 0 : t = make_class_type (TREE_CODE (t));
4271 0 : pushtag (TYPE_IDENTIFIER (t), t);
4272 : }
4273 :
4274 31336116 : maybe_process_partial_specialization (t);
4275 31336116 : pushclass (t);
4276 31336116 : TYPE_BEING_DEFINED (t) = 1;
4277 31336116 : class_binding_level->defining_class_p = 1;
4278 :
4279 31336116 : if (flag_pack_struct)
4280 : {
4281 99 : tree v;
4282 99 : TYPE_PACKED (t) = 1;
4283 : /* Even though the type is being defined for the first time
4284 : here, there might have been a forward declaration, so there
4285 : might be cv-qualified variants of T. */
4286 99 : for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
4287 0 : TYPE_PACKED (v) = 1;
4288 : }
4289 : /* Reset the interface data, at the earliest possible
4290 : moment, as it might have been set via a class foo;
4291 : before. */
4292 65090938 : if (! TYPE_UNNAMED_P (t))
4293 : {
4294 30586884 : struct c_fileinfo *finfo = \
4295 30586884 : get_fileinfo (LOCATION_FILE (input_location));
4296 30586884 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
4297 30586884 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X
4298 : (t, finfo->interface_unknown);
4299 : }
4300 31336116 : reset_specialization ();
4301 :
4302 : /* Make a declaration for this class in its own scope. */
4303 31336116 : build_self_reference ();
4304 :
4305 31336116 : return t;
4306 : }
4307 :
4308 : /* Finish the member declaration given by DECL. */
4309 :
4310 : void
4311 423443842 : finish_member_declaration (tree decl)
4312 : {
4313 423443842 : if (decl == error_mark_node || decl == NULL_TREE)
4314 : return;
4315 :
4316 423442793 : if (decl == void_type_node)
4317 : /* The COMPONENT was a friend, not a member, and so there's
4318 : nothing for us to do. */
4319 : return;
4320 :
4321 : /* We should see only one DECL at a time. */
4322 423442793 : gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
4323 :
4324 : /* Don't add decls after definition. */
4325 423442814 : gcc_assert (TYPE_BEING_DEFINED (current_class_type)
4326 : /* We can add lambda types when late parsing default
4327 : arguments. */
4328 : || LAMBDA_TYPE_P (TREE_TYPE (decl)));
4329 :
4330 : /* Set up access control for DECL. */
4331 423442793 : TREE_PRIVATE (decl)
4332 423442793 : = (current_access_specifier == access_private_node);
4333 423442793 : TREE_PROTECTED (decl)
4334 423442793 : = (current_access_specifier == access_protected_node);
4335 423442793 : if (TREE_CODE (decl) == TEMPLATE_DECL)
4336 : {
4337 48685124 : TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
4338 48685124 : TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
4339 : }
4340 :
4341 : /* Mark the DECL as a member of the current class, unless it's
4342 : a member of an enumeration. */
4343 423442793 : if (TREE_CODE (decl) != CONST_DECL)
4344 421064504 : DECL_CONTEXT (decl) = current_class_type;
4345 :
4346 423442793 : if (TREE_TYPE (decl)
4347 419875984 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl))
4348 423831640 : && TREE_CODE (decl) != TYPE_DECL)
4349 : {
4350 : /* Remember the single FIELD_DECL an anonymous aggregate type is used
4351 : for. */
4352 283473 : if (TREE_CODE (decl) == FIELD_DECL && DECL_NAME (decl) == NULL_TREE)
4353 : {
4354 283457 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
4355 283457 : gcc_assert (!ANON_AGGR_TYPE_FIELD (type));
4356 283457 : SET_ANON_AGGR_TYPE_FIELD (type, decl);
4357 : }
4358 : /* [class.union.anon]/1: Each object of such an unnamed type shall
4359 : be such an unnamed object. */
4360 16 : else if (ANON_UNION_TYPE_P (TREE_TYPE (decl)))
4361 : {
4362 10 : tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
4363 10 : auto_diagnostic_group d;
4364 10 : error_at (location_of (decl),
4365 : "declaration of member %qD with anonymous union type %qT",
4366 10 : decl, TREE_TYPE (decl));
4367 10 : inform (DECL_SOURCE_LOCATION (adecl),
4368 : "anonymous union declared here");
4369 10 : }
4370 : else
4371 : {
4372 6 : tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
4373 6 : auto_diagnostic_group d;
4374 6 : error_at (location_of (decl),
4375 : "declaration of member %qD with anonymous struct type %qT",
4376 6 : decl, TREE_TYPE (decl));
4377 6 : inform (DECL_SOURCE_LOCATION (adecl),
4378 : "anonymous struct declared here");
4379 6 : }
4380 : }
4381 423159320 : else if (TREE_TYPE (decl)
4382 419592511 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
4383 424734052 : && TREE_CODE (decl) != TYPE_DECL)
4384 : {
4385 1510104 : tree type = strip_array_types (TREE_TYPE (decl));
4386 1510104 : if (ANON_AGGR_TYPE_P (type))
4387 : {
4388 : /* [class.union.anon]/1: Each object of such an unnamed type shall
4389 : be such an unnamed object. */
4390 12 : tree adecl = TYPE_MAIN_DECL (TYPE_MAIN_VARIANT (type));
4391 12 : auto_diagnostic_group d;
4392 12 : if (ANON_UNION_TYPE_P (type))
4393 : {
4394 8 : error_at (location_of (decl),
4395 : "declaration of member %qD with array of anonymous "
4396 8 : "union type %qT", decl, TREE_TYPE (decl));
4397 8 : inform (DECL_SOURCE_LOCATION (adecl),
4398 : "anonymous union declared here");
4399 : }
4400 : else
4401 : {
4402 4 : error_at (location_of (decl),
4403 : "declaration of member %qD with array of anonymous "
4404 4 : "struct type %qT", decl, TREE_TYPE (decl));
4405 4 : inform (DECL_SOURCE_LOCATION (adecl),
4406 : "anonymous struct declared here");
4407 : }
4408 12 : }
4409 : }
4410 :
4411 423442793 : if (TREE_CODE (decl) == USING_DECL)
4412 : /* Avoid debug info for class-scope USING_DECLS for now, we'll
4413 : call cp_emit_debug_info_for_using later. */
4414 3475527 : DECL_IGNORED_P (decl) = 1;
4415 :
4416 : /* Check for bare parameter packs in the non-static data member
4417 : declaration. */
4418 423442793 : if (TREE_CODE (decl) == FIELD_DECL)
4419 : {
4420 31140560 : if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
4421 9 : TREE_TYPE (decl) = error_mark_node;
4422 31140560 : if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
4423 0 : DECL_ATTRIBUTES (decl) = NULL_TREE;
4424 : }
4425 :
4426 : /* [dcl.link]
4427 :
4428 : A C language linkage is ignored for the names of class members
4429 : and the member function type of class member functions. */
4430 423442793 : if (DECL_LANG_SPECIFIC (decl))
4431 386408766 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
4432 :
4433 423442793 : bool add = false;
4434 :
4435 : /* Functions and non-functions are added differently. */
4436 423442793 : if (DECL_DECLARES_FUNCTION_P (decl))
4437 219158081 : add = add_method (current_class_type, decl, false);
4438 : /* Enter the DECL into the scope of the class, if the class
4439 : isn't a closure (whose fields are supposed to be unnamed). */
4440 204284712 : else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
4441 200377945 : || maybe_push_used_methods (decl)
4442 402752693 : || pushdecl_class_level (decl))
4443 : add = true;
4444 :
4445 219158081 : if (add)
4446 : {
4447 : /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
4448 : go at the beginning. The reason is that
4449 : legacy_nonfn_member_lookup searches the list in order, and we
4450 : want a field name to override a type name so that the "struct
4451 : stat hack" will work. In particular:
4452 :
4453 : struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
4454 :
4455 : is valid. */
4456 :
4457 423429317 : if (TREE_CODE (decl) == TYPE_DECL)
4458 144768110 : TYPE_FIELDS (current_class_type)
4459 289536220 : = chainon (TYPE_FIELDS (current_class_type), decl);
4460 : else
4461 : {
4462 278661207 : DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
4463 278661207 : TYPE_FIELDS (current_class_type) = decl;
4464 : }
4465 :
4466 423429317 : maybe_add_class_template_decl_list (current_class_type, decl,
4467 : /*friend_p=*/0);
4468 : }
4469 : }
4470 :
4471 : /* Finish processing a complete template declaration. The PARMS are
4472 : the template parameters. */
4473 :
4474 : void
4475 93735720 : finish_template_decl (tree parms)
4476 : {
4477 93735720 : if (parms)
4478 93735711 : end_template_decl ();
4479 : else
4480 9 : end_specialization ();
4481 93735720 : }
4482 :
4483 : // Returns the template type of the class scope being entered. If we're
4484 : // entering a constrained class scope. TYPE is the class template
4485 : // scope being entered and we may need to match the intended type with
4486 : // a constrained specialization. For example:
4487 : //
4488 : // template<Object T>
4489 : // struct S { void f(); }; #1
4490 : //
4491 : // template<Object T>
4492 : // void S<T>::f() { } #2
4493 : //
4494 : // We check, in #2, that S<T> refers precisely to the type declared by
4495 : // #1 (i.e., that the constraints match). Note that the following should
4496 : // be an error since there is no specialization of S<T> that is
4497 : // unconstrained, but this is not diagnosed here.
4498 : //
4499 : // template<typename T>
4500 : // void S<T>::f() { }
4501 : //
4502 : // We cannot diagnose this problem here since this function also matches
4503 : // qualified template names that are not part of a definition. For example:
4504 : //
4505 : // template<Integral T, Floating_point U>
4506 : // typename pair<T, U>::first_type void f(T, U);
4507 : //
4508 : // Here, it is unlikely that there is a partial specialization of
4509 : // pair constrained for Integral and Floating_point arguments.
4510 : //
4511 : // The general rule is: if a constrained specialization with matching
4512 : // constraints is found return that type. Also note that if TYPE is not a
4513 : // class-type (e.g. a typename type), then no fixup is needed.
4514 :
4515 : static tree
4516 18417636 : fixup_template_type (tree type)
4517 : {
4518 : // Find the template parameter list at the a depth appropriate to
4519 : // the scope we're trying to enter.
4520 18417636 : tree parms = current_template_parms;
4521 18417636 : int depth = template_class_depth (type);
4522 22724207 : for (int n = current_template_depth; n > depth && parms; --n)
4523 4306571 : parms = TREE_CHAIN (parms);
4524 18417636 : if (!parms)
4525 : return type;
4526 18417626 : tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
4527 18417626 : tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
4528 :
4529 : // Search for a specialization whose type and constraints match.
4530 18417626 : tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
4531 18417626 : tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
4532 35694156 : while (specs)
4533 : {
4534 17719683 : tree spec_constr = get_constraints (TREE_VALUE (specs));
4535 :
4536 : // If the type and constraints match a specialization, then we
4537 : // are entering that type.
4538 17719683 : if (same_type_p (type, TREE_TYPE (specs))
4539 17719683 : && equivalent_constraints (cur_constr, spec_constr))
4540 443153 : return TREE_TYPE (specs);
4541 17276530 : specs = TREE_CHAIN (specs);
4542 : }
4543 :
4544 : // If no specialization matches, then must return the type
4545 : // previously found.
4546 : return type;
4547 : }
4548 :
4549 : /* Finish processing a template-id (which names a type) of the form
4550 : NAME < ARGS >. Return the TYPE_DECL for the type named by the
4551 : template-id. If ENTERING_SCOPE is nonzero we are about to enter
4552 : the scope of template-id indicated. */
4553 :
4554 : tree
4555 190248389 : finish_template_type (tree name, tree args, int entering_scope)
4556 : {
4557 190248389 : tree type;
4558 :
4559 190248389 : type = lookup_template_class (name, args,
4560 : NULL_TREE, NULL_TREE,
4561 : tf_warning_or_error | tf_user);
4562 190248386 : if (entering_scope)
4563 19444361 : type = adjust_type_for_entering_scope (type);
4564 :
4565 : /* If we might be entering the scope of a partial specialization,
4566 : find the one with the right constraints. */
4567 190248386 : if (flag_concepts
4568 187561426 : && entering_scope
4569 19086459 : && CLASS_TYPE_P (type)
4570 18918217 : && CLASSTYPE_TEMPLATE_INFO (type)
4571 18918208 : && dependent_type_p (type)
4572 208666022 : && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
4573 18417636 : type = fixup_template_type (type);
4574 :
4575 190248386 : if (type == error_mark_node)
4576 : return type;
4577 190246096 : else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
4578 149376778 : return TYPE_STUB_DECL (type);
4579 : else
4580 40869318 : return TYPE_NAME (type);
4581 : }
4582 :
4583 : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER
4584 : and ANNOTATIONS.
4585 : Return a TREE_LIST containing the ACCESS_SPECIFIER (or if there are
4586 : ANNOTATIONS, TREE_LIST containing the ACCESS_SPECIFIER and ANNOTATIONS)
4587 : and the BASE_CLASS, or NULL_TREE if an error occurred. The
4588 : ACCESS_SPECIFIER is one of
4589 : access_{default,public,protected,private}_node. For a virtual base
4590 : we set TREE_TYPE. */
4591 :
4592 : tree
4593 11518972 : finish_base_specifier (tree base, tree access, bool virtual_p,
4594 : tree annotations)
4595 : {
4596 11518972 : tree result;
4597 :
4598 11518972 : if (base == error_mark_node)
4599 : {
4600 0 : error ("invalid base-class specification");
4601 0 : result = NULL_TREE;
4602 : }
4603 11518972 : else if (! MAYBE_CLASS_TYPE_P (base))
4604 : {
4605 3 : error ("%qT is not a class type", base);
4606 3 : result = NULL_TREE;
4607 : }
4608 : else
4609 : {
4610 11518969 : if (cp_type_quals (base) != 0)
4611 : {
4612 : /* DR 484: Can a base-specifier name a cv-qualified
4613 : class type? */
4614 12 : base = TYPE_MAIN_VARIANT (base);
4615 : }
4616 11518969 : if (annotations)
4617 18 : access = build_tree_list (access, nreverse (annotations));
4618 11518969 : result = build_tree_list (access, base);
4619 11518969 : if (virtual_p)
4620 26221 : TREE_TYPE (result) = integer_type_node;
4621 : }
4622 :
4623 11518972 : return result;
4624 : }
4625 :
4626 : /* If FNS is a member function, a set of member functions, or a
4627 : template-id referring to one or more member functions, return a
4628 : BASELINK for FNS, incorporating the current access context.
4629 : Otherwise, return FNS unchanged. If IGNORE_CURRENT_CLASS_P is
4630 : true, we do not consider the currently open derived class. */
4631 :
4632 : tree
4633 187217213 : baselink_for_fns (tree fns, bool ignore_current_class_p/*=false*/)
4634 : {
4635 187217213 : if (BASELINK_P (fns) || error_operand_p (fns))
4636 : return fns;
4637 :
4638 173179342 : tree scope = ovl_scope (fns);
4639 173179342 : if (!CLASS_TYPE_P (scope))
4640 : return fns;
4641 :
4642 8993555 : tree cl = (ignore_current_class_p
4643 8993555 : ? NULL_TREE
4644 8991815 : : currently_open_derived_class (scope));
4645 8991815 : if (!cl)
4646 : cl = scope;
4647 8993555 : tree access_path = TYPE_BINFO (cl);
4648 8993555 : tree conv_path = (cl == scope ? access_path
4649 712723 : : lookup_base (cl, scope, ba_any, NULL, tf_none));
4650 8993555 : return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
4651 : }
4652 :
4653 : /* Returns true iff we are currently parsing a lambda-declarator. */
4654 :
4655 : bool
4656 2004029870 : parsing_lambda_declarator ()
4657 : {
4658 2004029870 : cp_binding_level *b = current_binding_level;
4659 2006081995 : while (b->kind == sk_template_parms || b->kind == sk_function_parms)
4660 2052125 : b = b->level_chain;
4661 2004029870 : return b->kind == sk_lambda;
4662 : }
4663 :
4664 : /* Returns true iff DECL is a variable from a function outside
4665 : the current one. */
4666 :
4667 : static bool
4668 2676818557 : outer_var_p (tree decl)
4669 : {
4670 : /* These should have been stripped or otherwise handled by the caller. */
4671 2676818557 : gcc_checking_assert (!REFERENCE_REF_P (decl));
4672 :
4673 1757031413 : return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
4674 2458133527 : && DECL_FUNCTION_SCOPE_P (decl)
4675 : /* Don't get confused by temporaries. */
4676 2036390794 : && DECL_NAME (decl)
4677 4689064756 : && (DECL_CONTEXT (decl) != current_function_decl
4678 2001828377 : || parsing_nsdmi ()
4679 : /* Also consider captures as outer vars if we are in
4680 : decltype in a lambda declarator as in:
4681 : auto l = [j=0]() -> decltype((j)) { ... }
4682 : for the sake of finish_decltype_type.
4683 :
4684 : (Similar issue also affects non-lambdas, but vexing parse
4685 : makes it more difficult to handle than lambdas.) */
4686 2001827000 : || parsing_lambda_declarator ()));
4687 : }
4688 :
4689 : /* As above, but also checks that DECL is automatic. */
4690 :
4691 : bool
4692 2676818557 : outer_automatic_var_p (tree decl)
4693 : {
4694 2676818557 : return (outer_var_p (decl)
4695 2676818557 : && !TREE_STATIC (decl));
4696 : }
4697 :
4698 : /* Note whether capture proxy D is only used in a contract condition. */
4699 :
4700 : static void
4701 181875 : set_contract_capture_flag (tree d, bool val)
4702 : {
4703 181875 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (d));
4704 181875 : tree proxy = DECL_VALUE_EXPR (d);
4705 181875 : gcc_checking_assert (TREE_CODE (proxy) == COMPONENT_REF
4706 : && TREE_CODE (TREE_OPERAND (proxy, 1)) == FIELD_DECL);
4707 181875 : DECL_CONTRACT_CAPTURE_P (TREE_OPERAND (proxy, 1)) = val;
4708 181875 : }
4709 :
4710 : /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
4711 : rewrite it for lambda capture.
4712 :
4713 : If ODR_USE is true, we're being called from mark_use, and we complain about
4714 : use of constant variables. If ODR_USE is false, we're being called for the
4715 : id-expression, and we do lambda capture. */
4716 :
4717 : tree
4718 5364455 : process_outer_var_ref (tree decl, tsubst_flags_t complain,
4719 : bool odr_use/*=false*/)
4720 : {
4721 5370968 : bool in_typeid_probe = false;
4722 5370968 : if (cp_unevaluated_operand)
4723 : {
4724 3167914 : tree type = TREE_TYPE (decl);
4725 3167914 : if (!dependent_type_p (type)
4726 3167914 : && variably_modified_type_p (type, NULL_TREE))
4727 : /* VLAs are used even in unevaluated context. */;
4728 3167908 : else if (cp_unevaluated_operand > cp_unevaluated_typeid_cutoff)
4729 : /* It's not a use (3.2) if we're in an unevaluated context. */
4730 : return decl;
4731 : else
4732 : /* Inside a typeid operand's own probe: capture is still
4733 : attempted below ([expr.prim.lambda.capture]/7), but a missing
4734 : capture-default must not be diagnosed yet - see below. */
4735 : in_typeid_probe = true;
4736 : }
4737 2203123 : if (decl == error_mark_node)
4738 : return decl;
4739 :
4740 2203117 : tree context = DECL_CONTEXT (decl);
4741 2203117 : tree containing_function = current_function_decl;
4742 2203117 : tree lambda_stack = NULL_TREE;
4743 2203117 : tree lambda_expr = NULL_TREE;
4744 2203117 : tree initializer = convert_from_reference (decl);
4745 2203117 : tree var = strip_normal_capture_proxy (decl);
4746 :
4747 : /* Mark it as used now even if the use is ill-formed. */
4748 2203117 : if (!mark_used (decl, complain))
4749 3 : return error_mark_node;
4750 :
4751 2203114 : if (parsing_nsdmi () || parsing_lambda_declarator ())
4752 : containing_function = NULL_TREE;
4753 :
4754 4405321 : if (containing_function && LAMBDA_FUNCTION_P (containing_function))
4755 : {
4756 : /* Check whether we've already built a proxy. */
4757 2202556 : tree d = retrieve_local_specialization (var);
4758 :
4759 2202556 : if (d && d != decl && is_capture_proxy (d))
4760 : {
4761 1131466 : if (flag_contracts && !processing_contract_condition)
4762 : /* We might have created a capture for a contract_assert ref. to
4763 : some var, if that is now captured 'normally' then this is OK.
4764 : Otherwise we leave the capture marked as incorrect. */
4765 181869 : set_contract_capture_flag (d, false);
4766 1131466 : if (DECL_CONTEXT (d) == containing_function)
4767 : /* We already have an inner proxy. */
4768 : return d;
4769 : else
4770 : /* We need to capture an outer proxy. */
4771 : return process_outer_var_ref (d, complain, odr_use);
4772 : }
4773 : }
4774 :
4775 : /* If we are in a lambda function, we can move out until we hit
4776 : 1. the context,
4777 : 2. a non-lambda function, or
4778 : 3. a non-default capturing lambda function. */
4779 2149616 : while (context != containing_function
4780 : /* containing_function can be null with invalid generic lambdas. */
4781 2149616 : && containing_function
4782 3229002 : && LAMBDA_FUNCTION_P (containing_function))
4783 : {
4784 1079386 : tree closure = DECL_CONTEXT (containing_function);
4785 1079386 : lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
4786 :
4787 1079386 : if (TYPE_CLASS_SCOPE_P (closure))
4788 : /* A lambda in an NSDMI (c++/64496). */
4789 : break;
4790 :
4791 1079383 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4792 : break;
4793 :
4794 1077968 : lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
4795 :
4796 1077968 : containing_function = decl_function_context (containing_function);
4797 : }
4798 :
4799 : /* In a lambda within a template, wait until instantiation time to implicitly
4800 : capture a parameter pack. We want to wait because we don't know if we're
4801 : capturing the whole pack or a single element, and it's OK to wait because
4802 : find_parameter_packs_r walks into the lambda body. */
4803 1071648 : if (context == containing_function
4804 1071648 : && DECL_PACK_P (decl))
4805 : return decl;
4806 :
4807 1027309 : if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
4808 : {
4809 6 : if (complain & tf_error)
4810 6 : error ("cannot capture member %qD of anonymous union", decl);
4811 6 : return error_mark_node;
4812 : }
4813 : /* Do lambda capture when processing the id-expression, not when
4814 : odr-using a variable, but uses in a contract must not cause a capture. */
4815 1027303 : if (!odr_use && context == containing_function)
4816 : {
4817 1025327 : decl = add_default_capture (lambda_stack,
4818 1025327 : /*id=*/DECL_NAME (decl), initializer);
4819 1025327 : if (flag_contracts && processing_contract_condition)
4820 6 : set_contract_capture_flag (decl, true);
4821 : }
4822 : /* Capture was attempted above; whether it's really needed depends on
4823 : an evaluated-ness we don't know yet. Defer instead of diagnosing:
4824 : a later, non-probe pass will complain if the operand turns out
4825 : evaluated, and there's nothing to complain about if it doesn't. */
4826 1976 : else if (in_typeid_probe)
4827 : return var;
4828 : /* Only an odr-use of an outer automatic variable causes an
4829 : error, and a constant variable can decay to a prvalue
4830 : constant without odr-use. So don't complain yet. */
4831 1967 : else if (!odr_use && decl_constant_var_p (var))
4832 : return var;
4833 : /* Don't complain when DECL is dependent, because it can turn out to
4834 : be constant (and therefore needing no capture) when instantiating. */
4835 438 : else if (VAR_P (var) && instantiation_dependent_expression_p (var))
4836 : return var;
4837 420 : else if (lambda_expr)
4838 : {
4839 60 : if (complain & tf_error)
4840 : {
4841 56 : auto_diagnostic_group d;
4842 56 : error ("%qD is not captured", decl);
4843 56 : tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
4844 56 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4845 53 : inform (location_of (closure),
4846 : "the lambda has no capture-default");
4847 3 : else if (TYPE_CLASS_SCOPE_P (closure))
4848 3 : inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
4849 : "capture variables from the enclosing context",
4850 3 : TYPE_CONTEXT (closure));
4851 56 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4852 56 : }
4853 60 : return error_mark_node;
4854 : }
4855 360 : else if (processing_contract_condition && TREE_CODE (decl) == PARM_DECL)
4856 : /* Use of a parameter in a contract condition is fine. */
4857 : return decl;
4858 : else
4859 : {
4860 53 : if (complain & tf_error)
4861 : {
4862 39 : auto_diagnostic_group d;
4863 57 : error (VAR_P (decl)
4864 : ? G_("use of local variable with automatic storage from "
4865 : "containing function")
4866 : : G_("use of parameter from containing function"));
4867 39 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4868 39 : }
4869 53 : return error_mark_node;
4870 : }
4871 : return decl;
4872 : }
4873 :
4874 : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4875 : id-expression. (See cp_parser_id_expression for details.) SCOPE,
4876 : if non-NULL, is the type or namespace used to explicitly qualify
4877 : ID_EXPRESSION. DECL is the entity to which that name has been
4878 : resolved.
4879 :
4880 : *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4881 : constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4882 : be set to true if this expression isn't permitted in a
4883 : constant-expression, but it is otherwise not set by this function.
4884 : *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4885 : constant-expression, but a non-constant expression is also
4886 : permissible.
4887 :
4888 : DONE is true if this expression is a complete postfix-expression;
4889 : it is false if this expression is followed by '->', '[', '(', etc.
4890 : ADDRESS_P is true iff this expression is the operand of '&'.
4891 : TEMPLATE_P is true iff the qualified-id was of the form
4892 : "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4893 : appears as a template argument.
4894 :
4895 : If an error occurs, and it is the kind of error that might cause
4896 : the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4897 : is the caller's responsibility to issue the message. *ERROR_MSG
4898 : will be a string with static storage duration, so the caller need
4899 : not "free" it.
4900 :
4901 : Return an expression for the entity, after issuing appropriate
4902 : diagnostics. This function is also responsible for transforming a
4903 : reference to a non-static member into a COMPONENT_REF that makes
4904 : the use of "this" explicit.
4905 :
4906 : Upon return, *IDK will be filled in appropriately. */
4907 : static cp_expr
4908 794792451 : finish_id_expression_1 (tree id_expression,
4909 : tree decl,
4910 : tree scope,
4911 : cp_id_kind *idk,
4912 : bool integral_constant_expression_p,
4913 : bool allow_non_integral_constant_expression_p,
4914 : bool *non_integral_constant_expression_p,
4915 : bool template_p,
4916 : bool done,
4917 : bool address_p,
4918 : bool template_arg_p,
4919 : const char **error_msg,
4920 : location_t location)
4921 : {
4922 794792451 : decl = strip_using_decl (decl);
4923 :
4924 : /* Initialize the output parameters. */
4925 794792451 : *idk = CP_ID_KIND_NONE;
4926 794792451 : *error_msg = NULL;
4927 :
4928 794792451 : if (id_expression == error_mark_node)
4929 12 : return error_mark_node;
4930 : /* If we have a template-id, then no further lookup is
4931 : required. If the template-id was for a template-class, we
4932 : will sometimes have a TYPE_DECL at this point. */
4933 794792439 : else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4934 739489722 : || TREE_CODE (decl) == TYPE_DECL)
4935 : ;
4936 : /* Look up the name. */
4937 : else
4938 : {
4939 739488795 : if (decl == error_mark_node)
4940 : {
4941 : /* Name lookup failed. */
4942 131178 : if (scope
4943 374 : && !dependent_namespace_p (scope)
4944 131552 : && (!TYPE_P (scope)
4945 119 : || (!dependentish_scope_p (scope)
4946 115 : && !(identifier_p (id_expression)
4947 100 : && IDENTIFIER_CONV_OP_P (id_expression)
4948 3 : && dependent_type_p (TREE_TYPE (id_expression))))))
4949 : {
4950 : /* If the qualifying type is non-dependent (and the name
4951 : does not name a conversion operator to a dependent
4952 : type), issue an error. */
4953 364 : qualified_name_lookup_error (scope, id_expression, decl, location);
4954 364 : return error_mark_node;
4955 : }
4956 130814 : else if (!scope)
4957 : {
4958 : /* It may be resolved via Koenig lookup. */
4959 130804 : *idk = CP_ID_KIND_UNQUALIFIED;
4960 130804 : return id_expression;
4961 : }
4962 : else
4963 : decl = id_expression;
4964 : }
4965 :
4966 : /* Remember that the name was used in the definition of
4967 : the current class so that we can check later to see if
4968 : the meaning would have been different after the class
4969 : was entirely defined. */
4970 739357617 : if (!scope && decl != error_mark_node && identifier_p (id_expression))
4971 661146474 : maybe_note_name_used_in_class (id_expression, decl);
4972 :
4973 : /* A use in unevaluated operand might not be instantiated appropriately
4974 : if tsubst_copy builds a dummy parm, or if we never instantiate a
4975 : generic lambda, so mark it now. */
4976 739357627 : if (processing_template_decl
4977 739357627 : && (cp_unevaluated_operand
4978 640031023 : || generic_lambda_fn_p (current_function_decl)))
4979 20565565 : mark_type_use (decl);
4980 :
4981 : /* Disallow uses of local variables from containing functions, except
4982 : within lambda-expressions. */
4983 739357627 : if (outer_automatic_var_p (decl))
4984 : {
4985 3825355 : decl = process_outer_var_ref (decl, tf_warning_or_error);
4986 3825355 : if (decl == error_mark_node)
4987 92 : return error_mark_node;
4988 : }
4989 :
4990 : /* Also disallow uses of function parameters outside the function
4991 : body, except inside an unevaluated context (i.e. decltype). */
4992 739357535 : if (TREE_CODE (decl) == PARM_DECL
4993 307830835 : && DECL_CONTEXT (decl) == NULL_TREE
4994 8271457 : && !CONSTRAINT_VAR_P (decl)
4995 4452825 : && !cp_unevaluated_operand
4996 595 : && !processing_contract_condition
4997 739357591 : && !processing_omp_trait_property_expr)
4998 : {
4999 38 : *error_msg = G_("use of parameter outside function body");
5000 38 : return error_mark_node;
5001 : }
5002 : }
5003 :
5004 : /* If we didn't find anything, or what we found was a type,
5005 : then this wasn't really an id-expression. */
5006 794661141 : if (TREE_CODE (decl) == TEMPLATE_DECL
5007 794661141 : && !DECL_FUNCTION_TEMPLATE_P (decl))
5008 : {
5009 51 : *error_msg = G_("missing template arguments");
5010 51 : return error_mark_node;
5011 : }
5012 794661090 : else if (TREE_CODE (decl) == TYPE_DECL
5013 794660163 : || TREE_CODE (decl) == NAMESPACE_DECL)
5014 : {
5015 942 : *error_msg = G_("expected primary-expression");
5016 942 : return error_mark_node;
5017 : }
5018 :
5019 : /* If the name resolved to a template parameter, there is no
5020 : need to look it up again later. */
5021 33984194 : if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
5022 808746824 : || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
5023 : {
5024 19897518 : tree r;
5025 :
5026 19897518 : *idk = CP_ID_KIND_NONE;
5027 19897518 : if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
5028 0 : decl = TEMPLATE_PARM_DECL (decl);
5029 19897518 : r = DECL_INITIAL (decl);
5030 19897518 : if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
5031 : {
5032 : /* If the entity is a template parameter object for a template
5033 : parameter of type T, the type of the expression is const T. */
5034 2969 : tree ctype = TREE_TYPE (r);
5035 2969 : ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
5036 : | TYPE_QUAL_CONST));
5037 2969 : r = build1 (VIEW_CONVERT_EXPR, ctype, r);
5038 : }
5039 19897518 : r = convert_from_reference (r);
5040 19897518 : if (integral_constant_expression_p
5041 3457130 : && !dependent_type_p (TREE_TYPE (decl))
5042 22852308 : && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
5043 : {
5044 1039 : if (!allow_non_integral_constant_expression_p)
5045 6 : error ("template parameter %qD of type %qT is not allowed in "
5046 : "an integral constant expression because it is not of "
5047 6 : "integral or enumeration type", decl, TREE_TYPE (decl));
5048 1039 : *non_integral_constant_expression_p = true;
5049 : }
5050 :
5051 19897518 : if (flag_contracts && processing_contract_condition)
5052 27 : r = constify_contract_access (r);
5053 :
5054 19897518 : return r;
5055 : }
5056 774762630 : else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
5057 : {
5058 9 : gcc_checking_assert (scope);
5059 9 : *idk = CP_ID_KIND_QUALIFIED;
5060 9 : cp_warn_deprecated_use_scopes (scope);
5061 9 : decl = finish_qualified_id_expr (scope, decl, done, address_p,
5062 : template_p, template_arg_p,
5063 : tf_warning_or_error);
5064 : }
5065 : else
5066 : {
5067 774762621 : if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
5068 55302717 : && variable_template_p (TREE_OPERAND (decl, 0))
5069 787331656 : && !concept_check_p (decl))
5070 : /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
5071 : considered type-dependent) now, so that the dependence test that
5072 : follows gives us the right answer: if it represents a non-dependent
5073 : variable template-id then finish_template_variable will yield the
5074 : corresponding non-dependent VAR_DECL. */
5075 12569035 : decl = finish_template_variable (decl);
5076 :
5077 774762621 : bool dependent_p = type_dependent_expression_p (decl);
5078 :
5079 : /* If the declaration was explicitly qualified indicate
5080 : that. The semantics of `A::f(3)' are different than
5081 : `f(3)' if `f' is virtual. */
5082 1549525242 : *idk = (scope
5083 774762621 : ? CP_ID_KIND_QUALIFIED
5084 674028698 : : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
5085 674028698 : ? CP_ID_KIND_TEMPLATE_ID
5086 : : (dependent_p
5087 641536846 : ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
5088 : : CP_ID_KIND_UNQUALIFIED)));
5089 :
5090 774762621 : if (dependent_p
5091 774762621 : && !scope
5092 444475925 : && DECL_P (decl)
5093 1187715347 : && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
5094 : /* Dependent type attributes on the decl mean that the TREE_TYPE is
5095 : wrong, so just return the identifier. */
5096 39 : return id_expression;
5097 :
5098 774762582 : if (DECL_CLASS_TEMPLATE_P (decl))
5099 : {
5100 0 : error ("use of class template %qT as expression", decl);
5101 0 : return error_mark_node;
5102 : }
5103 :
5104 774762582 : if (TREE_CODE (decl) == TREE_LIST)
5105 : {
5106 : /* Ambiguous reference to base members. */
5107 0 : auto_diagnostic_group d;
5108 0 : error ("request for member %qD is ambiguous in "
5109 : "multiple inheritance lattice", id_expression);
5110 0 : print_candidates (input_location, decl);
5111 0 : return error_mark_node;
5112 0 : }
5113 :
5114 : /* Mark variable-like entities as used. Functions are similarly
5115 : marked either below or after overload resolution. */
5116 774762582 : if ((VAR_P (decl)
5117 561542467 : || TREE_CODE (decl) == PARM_DECL
5118 253711676 : || TREE_CODE (decl) == CONST_DECL
5119 239625000 : || TREE_CODE (decl) == RESULT_DECL)
5120 1096680049 : && !mark_used (decl))
5121 12 : return error_mark_node;
5122 :
5123 : /* Only certain kinds of names are allowed in constant
5124 : expression. Template parameters have already
5125 : been handled above. */
5126 774762567 : if (! error_operand_p (decl)
5127 774762239 : && !dependent_p
5128 774762239 : && integral_constant_expression_p
5129 77984230 : && !decl_constant_var_p (decl)
5130 63397118 : && TREE_CODE (decl) != CONST_DECL
5131 54730456 : && !builtin_valid_in_constant_expr_p (decl)
5132 829443090 : && !concept_check_p (decl))
5133 : {
5134 54110752 : if (!allow_non_integral_constant_expression_p)
5135 : {
5136 31 : error ("%qD cannot appear in a constant-expression", decl);
5137 31 : return error_mark_node;
5138 : }
5139 54110721 : *non_integral_constant_expression_p = true;
5140 : }
5141 :
5142 774762536 : if (tree wrap = maybe_get_tls_wrapper_call (decl))
5143 : /* Replace an evaluated use of the thread_local variable with
5144 : a call to its wrapper. */
5145 : decl = wrap;
5146 774762024 : else if (concept_check_p (decl))
5147 : {
5148 : /* Nothing more to do. All of the analysis for concept checks
5149 : is done by build_conept_id, called from the parser. */
5150 : }
5151 757747131 : else if (scope)
5152 : {
5153 98772223 : if (TREE_CODE (decl) == SCOPE_REF)
5154 : {
5155 89975 : gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
5156 89975 : decl = TREE_OPERAND (decl, 1);
5157 : }
5158 :
5159 98772223 : decl = (adjust_result_of_qualified_name_lookup
5160 98772223 : (decl, scope, current_nonlambda_class_type()));
5161 :
5162 98772223 : cp_warn_deprecated_use_scopes (scope);
5163 :
5164 98772223 : if (TYPE_P (scope))
5165 14074417 : decl = finish_qualified_id_expr (scope,
5166 : decl,
5167 : done,
5168 : address_p,
5169 : template_p,
5170 : template_arg_p,
5171 : tf_warning_or_error);
5172 : else
5173 84697806 : decl = convert_from_reference (decl);
5174 : }
5175 658974908 : else if (TREE_CODE (decl) == FIELD_DECL)
5176 : {
5177 68717626 : if (flag_contracts && processing_contract_condition
5178 40 : && contract_class_ptr == current_class_ptr)
5179 : {
5180 6 : error ("%qD 'this' required when accessing a member within a "
5181 : "constructor precondition or destructor postcondition "
5182 : "contract check", decl);
5183 6 : return error_mark_node;
5184 : }
5185 : /* Since SCOPE is NULL here, this is an unqualified name.
5186 : Access checking has been performed during name lookup
5187 : already. Turn off checking to avoid duplicate errors. */
5188 68717620 : push_deferring_access_checks (dk_no_check);
5189 68717620 : decl = finish_non_static_data_member (decl, NULL_TREE,
5190 : /*qualifying_scope=*/NULL_TREE);
5191 68717620 : pop_deferring_access_checks ();
5192 : }
5193 590257282 : else if (is_overloaded_fn (decl))
5194 : {
5195 : /* We only need to look at the first function,
5196 : because all the fns share the attribute we're
5197 : concerned with (all member fns or all non-members). */
5198 63477301 : tree first_fn = get_first_fn (decl);
5199 63477301 : first_fn = STRIP_TEMPLATE (first_fn);
5200 :
5201 63477301 : if (!template_arg_p
5202 63477301 : && (TREE_CODE (first_fn) == USING_DECL
5203 63475395 : || (TREE_CODE (first_fn) == FUNCTION_DECL
5204 63475395 : && DECL_FUNCTION_MEMBER_P (first_fn)
5205 38846108 : && !shared_member_p (decl))))
5206 : {
5207 : /* A set of member functions. */
5208 29976183 : if (flag_contracts && processing_contract_condition
5209 24 : && contract_class_ptr == current_class_ptr)
5210 : {
5211 3 : error ("%qD 'this' required when accessing a member within a "
5212 : "constructor precondition or destructor postcondition "
5213 : "contract check", decl);
5214 3 : return error_mark_node;
5215 : }
5216 29976180 : decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
5217 29976180 : return finish_class_member_access_expr (decl, id_expression,
5218 : /*template_p=*/false,
5219 29976180 : tf_warning_or_error);
5220 : }
5221 :
5222 33501118 : decl = baselink_for_fns (decl);
5223 : }
5224 : else
5225 : {
5226 515164885 : if (DECL_P (decl) && DECL_NONLOCAL (decl)
5227 528292487 : && DECL_CLASS_SCOPE_P (decl))
5228 : {
5229 1512506 : tree context = context_for_name_lookup (decl);
5230 1512506 : if (context != current_class_type)
5231 : {
5232 791521 : tree path = currently_open_derived_class (context);
5233 791521 : if (!path)
5234 : /* PATH can be null for using an enum of an unrelated
5235 : class; we checked its access in lookup_using_decl.
5236 :
5237 : ??? Should this case make a clone instead, like
5238 : handle_using_decl? */
5239 43 : gcc_assert (TREE_CODE (decl) == CONST_DECL
5240 : /* This is for:
5241 : constexpr auto r = ^^S::i;
5242 : auto a = [:r:]; */
5243 : || flag_reflection);
5244 : else
5245 791478 : perform_or_defer_access_check (TYPE_BINFO (path),
5246 : decl, decl,
5247 : tf_warning_or_error);
5248 : }
5249 : }
5250 :
5251 526779981 : decl = convert_from_reference (decl);
5252 : }
5253 : }
5254 :
5255 744786356 : check_param_in_postcondition (decl, location);
5256 744786356 : if (flag_contracts && processing_contract_condition)
5257 2190 : decl = constify_contract_access (decl);
5258 :
5259 744786356 : return cp_expr (decl, location);
5260 : }
5261 :
5262 : /* As per finish_id_expression_1, but adding a wrapper node
5263 : around the result if needed to express LOCATION. */
5264 :
5265 : cp_expr
5266 794792451 : finish_id_expression (tree id_expression,
5267 : tree decl,
5268 : tree scope,
5269 : cp_id_kind *idk,
5270 : bool integral_constant_expression_p,
5271 : bool allow_non_integral_constant_expression_p,
5272 : bool *non_integral_constant_expression_p,
5273 : bool template_p,
5274 : bool done,
5275 : bool address_p,
5276 : bool template_arg_p,
5277 : const char **error_msg,
5278 : location_t location)
5279 : {
5280 794792451 : cp_expr result
5281 794792451 : = finish_id_expression_1 (id_expression, decl, scope, idk,
5282 : integral_constant_expression_p,
5283 : allow_non_integral_constant_expression_p,
5284 : non_integral_constant_expression_p,
5285 : template_p, done, address_p, template_arg_p,
5286 : error_msg, location);
5287 794792448 : return result.maybe_add_location_wrapper ();
5288 : }
5289 :
5290 : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
5291 : use as a type-specifier. */
5292 :
5293 : tree
5294 22141630 : finish_typeof (tree expr)
5295 : {
5296 22141630 : tree type;
5297 :
5298 22141630 : if (type_dependent_expression_p (expr))
5299 : {
5300 22049326 : type = cxx_make_type (TYPEOF_TYPE);
5301 22049326 : TYPEOF_TYPE_EXPR (type) = expr;
5302 22049326 : SET_TYPE_STRUCTURAL_EQUALITY (type);
5303 :
5304 22049326 : return type;
5305 : }
5306 :
5307 92304 : expr = mark_type_use (expr);
5308 :
5309 92304 : type = unlowered_expr_type (expr);
5310 :
5311 92304 : if (!type || type == unknown_type_node)
5312 : {
5313 3 : error ("type of %qE is unknown", expr);
5314 3 : return error_mark_node;
5315 : }
5316 :
5317 : return type;
5318 : }
5319 :
5320 : /* Implement the __underlying_type keyword: Return the underlying
5321 : type of TYPE, suitable for use as a type-specifier. */
5322 :
5323 : tree
5324 48613 : finish_underlying_type (tree type)
5325 : {
5326 48613 : if (!complete_type_or_else (type, NULL_TREE))
5327 3 : return error_mark_node;
5328 :
5329 48610 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5330 : {
5331 24 : error ("%qT is not an enumeration type", type);
5332 24 : return error_mark_node;
5333 : }
5334 :
5335 48586 : tree underlying_type = ENUM_UNDERLYING_TYPE (type);
5336 :
5337 : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5338 : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5339 : See finish_enum_value_list for details. */
5340 48586 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5341 56 : underlying_type
5342 56 : = c_common_type_for_mode (TYPE_MODE (underlying_type),
5343 56 : TYPE_UNSIGNED (underlying_type));
5344 :
5345 : return underlying_type;
5346 : }
5347 :
5348 : /* Implement the __type_pack_element keyword: Return the type
5349 : at index IDX within TYPES. */
5350 :
5351 : static tree
5352 135030 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
5353 : {
5354 135030 : idx = maybe_constant_value (idx, NULL_TREE, mce_true);
5355 135030 : if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
5356 : {
5357 6 : if (complain & tf_error)
5358 3 : error ("pack index has non-integral type %qT", TREE_TYPE (idx));
5359 6 : return error_mark_node;
5360 : }
5361 135024 : if (TREE_CODE (idx) != INTEGER_CST)
5362 : {
5363 2 : if (complain & tf_error)
5364 : {
5365 2 : error ("pack index is not an integral constant");
5366 2 : cxx_constant_value (idx);
5367 : }
5368 2 : return error_mark_node;
5369 : }
5370 135022 : if (tree_int_cst_sgn (idx) < 0)
5371 : {
5372 3 : if (complain & tf_error)
5373 3 : error ("pack index %qE is negative", idx);
5374 3 : return error_mark_node;
5375 : }
5376 135019 : if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
5377 : {
5378 35 : if (complain & tf_error)
5379 29 : error ("pack index %qE is out of range for pack of length %qd",
5380 29 : idx, TREE_VEC_LENGTH (types));
5381 35 : return error_mark_node;
5382 : }
5383 134984 : return TREE_VEC_ELT (types, tree_to_shwi (idx));
5384 : }
5385 :
5386 : /* In a pack-index T...[N], return the element at index IDX within TYPES.
5387 : PARENTHESIZED_P is true iff the pack index was wrapped in (). */
5388 :
5389 : tree
5390 22552 : pack_index_element (tree idx, tree types, bool parenthesized_p,
5391 : tsubst_flags_t complain)
5392 : {
5393 22552 : tree r = finish_type_pack_element (idx, types, complain);
5394 22552 : if (parenthesized_p)
5395 : /* For the benefit of decltype(auto). */
5396 35 : r = force_paren_expr (r);
5397 22552 : return r;
5398 : }
5399 :
5400 : /* Implement the __direct_bases keyword: Return the direct base classes
5401 : of type. */
5402 :
5403 : tree
5404 15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
5405 : {
5406 15 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5407 15 : || !NON_UNION_CLASS_TYPE_P (type))
5408 8 : return make_tree_vec (0);
5409 :
5410 7 : releasing_vec vector;
5411 7 : vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
5412 7 : tree binfo;
5413 7 : unsigned i;
5414 :
5415 : /* Virtual bases are initialized first */
5416 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5417 13 : if (BINFO_VIRTUAL_P (binfo))
5418 2 : vec_safe_push (vector, binfo);
5419 :
5420 : /* Now non-virtuals */
5421 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5422 13 : if (!BINFO_VIRTUAL_P (binfo))
5423 11 : vec_safe_push (vector, binfo);
5424 :
5425 7 : tree bases_vec = make_tree_vec (vector->length ());
5426 :
5427 27 : for (i = 0; i < vector->length (); ++i)
5428 13 : TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
5429 :
5430 7 : return bases_vec;
5431 7 : }
5432 :
5433 : /* Implement the __bases keyword: Return the base classes
5434 : of type */
5435 :
5436 : /* Find morally non-virtual base classes by walking binfo hierarchy */
5437 : /* Virtual base classes are handled separately in finish_bases */
5438 :
5439 : static tree
5440 73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
5441 : {
5442 : /* Don't walk bases of virtual bases */
5443 73 : return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
5444 : }
5445 :
5446 : static tree
5447 73 : dfs_calculate_bases_post (tree binfo, void *data_)
5448 : {
5449 73 : vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
5450 73 : if (!BINFO_VIRTUAL_P (binfo))
5451 48 : vec_safe_push (*data, BINFO_TYPE (binfo));
5452 73 : return NULL_TREE;
5453 : }
5454 :
5455 : /* Calculates the morally non-virtual base classes of a class */
5456 : static vec<tree, va_gc> *
5457 16 : calculate_bases_helper (tree type)
5458 : {
5459 16 : vec<tree, va_gc> *vector = make_tree_vector ();
5460 :
5461 : /* Now add non-virtual base classes in order of construction */
5462 16 : if (TYPE_BINFO (type))
5463 16 : dfs_walk_all (TYPE_BINFO (type),
5464 : dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
5465 16 : return vector;
5466 : }
5467 :
5468 : tree
5469 12 : calculate_bases (tree type, tsubst_flags_t complain)
5470 : {
5471 12 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5472 12 : || !NON_UNION_CLASS_TYPE_P (type))
5473 5 : return make_tree_vec (0);
5474 :
5475 7 : releasing_vec vector;
5476 7 : tree bases_vec = NULL_TREE;
5477 7 : unsigned i;
5478 7 : vec<tree, va_gc> *vbases;
5479 7 : tree binfo;
5480 :
5481 : /* First go through virtual base classes */
5482 7 : for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
5483 16 : vec_safe_iterate (vbases, i, &binfo); i++)
5484 : {
5485 9 : releasing_vec vbase_bases
5486 9 : = calculate_bases_helper (BINFO_TYPE (binfo));
5487 9 : vec_safe_splice (vector, vbase_bases);
5488 9 : }
5489 :
5490 : /* Now for the non-virtual bases */
5491 7 : releasing_vec nonvbases = calculate_bases_helper (type);
5492 7 : vec_safe_splice (vector, nonvbases);
5493 :
5494 : /* Note that during error recovery vector->length can even be zero. */
5495 7 : if (vector->length () > 1)
5496 : {
5497 : /* Last element is entire class, so don't copy */
5498 6 : bases_vec = make_tree_vec (vector->length () - 1);
5499 :
5500 53 : for (i = 0; i < vector->length () - 1; ++i)
5501 41 : TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
5502 : }
5503 : else
5504 1 : bases_vec = make_tree_vec (0);
5505 :
5506 7 : return bases_vec;
5507 7 : }
5508 :
5509 : tree
5510 28 : finish_bases (tree type, bool direct)
5511 : {
5512 28 : tree bases = NULL_TREE;
5513 :
5514 28 : if (!processing_template_decl)
5515 : {
5516 : /* Parameter packs can only be used in templates */
5517 0 : error ("parameter pack %<__bases%> only valid in template declaration");
5518 0 : return error_mark_node;
5519 : }
5520 :
5521 28 : bases = cxx_make_type (BASES);
5522 28 : BASES_TYPE (bases) = type;
5523 28 : BASES_DIRECT (bases) = direct;
5524 28 : SET_TYPE_STRUCTURAL_EQUALITY (bases);
5525 :
5526 28 : return bases;
5527 : }
5528 :
5529 : /* Perform C++-specific checks for __builtin_offsetof before calling
5530 : fold_offsetof. */
5531 :
5532 : tree
5533 2497 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
5534 : {
5535 : /* If we're processing a template, we can't finish the semantics yet.
5536 : Otherwise we can fold the entire expression now. */
5537 2497 : if (processing_template_decl)
5538 : {
5539 60 : expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
5540 60 : SET_EXPR_LOCATION (expr, loc);
5541 60 : return expr;
5542 : }
5543 :
5544 2437 : if (expr == error_mark_node)
5545 : return error_mark_node;
5546 :
5547 2420 : if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
5548 : {
5549 6 : error ("cannot apply %<offsetof%> to destructor %<~%T%>",
5550 6 : TREE_OPERAND (expr, 2));
5551 6 : return error_mark_node;
5552 : }
5553 4813 : if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
5554 4813 : || TREE_TYPE (expr) == unknown_type_node)
5555 : {
5556 30 : while (TREE_CODE (expr) == COMPONENT_REF
5557 30 : || TREE_CODE (expr) == COMPOUND_EXPR)
5558 12 : expr = TREE_OPERAND (expr, 1);
5559 :
5560 18 : if (DECL_P (expr))
5561 : {
5562 0 : auto_diagnostic_group d;
5563 0 : error ("cannot apply %<offsetof%> to member function %qD", expr);
5564 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
5565 0 : }
5566 : else
5567 18 : error ("cannot apply %<offsetof%> to member function");
5568 18 : return error_mark_node;
5569 : }
5570 2396 : if (TREE_CODE (expr) == CONST_DECL)
5571 : {
5572 3 : error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
5573 3 : return error_mark_node;
5574 : }
5575 2393 : if (REFERENCE_REF_P (expr))
5576 9 : expr = TREE_OPERAND (expr, 0);
5577 2393 : if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
5578 3 : return error_mark_node;
5579 2390 : if (warn_invalid_offsetof
5580 2390 : && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
5581 2390 : && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
5582 2435 : && cp_unevaluated_operand == 0)
5583 45 : warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
5584 : "non-standard-layout type %qT is conditionally-supported",
5585 45 : TREE_TYPE (TREE_TYPE (object_ptr)));
5586 2390 : return fold_offsetof (expr);
5587 : }
5588 :
5589 : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
5590 : function is broken out from the above for the benefit of the tree-ssa
5591 : project. */
5592 :
5593 : void
5594 368938 : simplify_aggr_init_expr (tree *tp)
5595 : {
5596 368938 : tree aggr_init_expr = *tp;
5597 :
5598 : /* Form an appropriate CALL_EXPR. */
5599 368938 : tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
5600 368938 : tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
5601 368938 : tree type = TREE_TYPE (slot);
5602 :
5603 368938 : tree call_expr;
5604 368938 : enum style_t { ctor, arg, pcc } style;
5605 :
5606 368938 : if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
5607 : style = ctor;
5608 : #ifdef PCC_STATIC_STRUCT_RETURN
5609 : else if (1)
5610 : style = pcc;
5611 : #endif
5612 : else
5613 : {
5614 100199 : gcc_assert (TREE_ADDRESSABLE (type));
5615 : style = arg;
5616 : }
5617 :
5618 368938 : call_expr = build_call_array_loc (input_location,
5619 368938 : TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
5620 : fn,
5621 368938 : aggr_init_expr_nargs (aggr_init_expr),
5622 368938 : AGGR_INIT_EXPR_ARGP (aggr_init_expr));
5623 368938 : TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
5624 368938 : CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
5625 368938 : CALL_EXPR_OPERATOR_SYNTAX (call_expr)
5626 368938 : = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
5627 368938 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
5628 368938 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
5629 368938 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
5630 :
5631 368938 : if (style == ctor)
5632 : {
5633 : /* Replace the first argument to the ctor with the address of the
5634 : slot. */
5635 268739 : cxx_mark_addressable (slot);
5636 268739 : CALL_EXPR_ARG (call_expr, 0) =
5637 268739 : build1 (ADDR_EXPR, build_pointer_type (type), slot);
5638 : }
5639 100199 : else if (style == arg)
5640 : {
5641 : /* Just mark it addressable here, and leave the rest to
5642 : expand_call{,_inline}. */
5643 100199 : cxx_mark_addressable (slot);
5644 100199 : CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
5645 100199 : call_expr = cp_build_init_expr (slot, call_expr);
5646 : }
5647 : else if (style == pcc)
5648 : {
5649 : /* If we're using the non-reentrant PCC calling convention, then we
5650 : need to copy the returned value out of the static buffer into the
5651 : SLOT. */
5652 : push_deferring_access_checks (dk_no_check);
5653 : call_expr = build_aggr_init (slot, call_expr,
5654 : DIRECT_BIND | LOOKUP_ONLYCONVERTING,
5655 : tf_warning_or_error);
5656 : pop_deferring_access_checks ();
5657 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
5658 : }
5659 :
5660 368938 : if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
5661 : {
5662 4144 : tree init = build_zero_init (type, NULL_TREE,
5663 : /*static_storage_p=*/false);
5664 4144 : init = cp_build_init_expr (slot, init);
5665 4144 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
5666 : init, call_expr);
5667 : }
5668 :
5669 368938 : *tp = call_expr;
5670 368938 : }
5671 :
5672 : /* Emit all thunks to FN that should be emitted when FN is emitted. */
5673 :
5674 : void
5675 60936412 : emit_associated_thunks (tree fn)
5676 : {
5677 : /* When we use vcall offsets, we emit thunks with the virtual
5678 : functions to which they thunk. The whole point of vcall offsets
5679 : is so that you can know statically the entire set of thunks that
5680 : will ever be needed for a given virtual function, thereby
5681 : enabling you to output all the thunks with the function itself. */
5682 60936412 : if (DECL_VIRTUAL_P (fn)
5683 : /* Do not emit thunks for extern template instantiations. */
5684 1159070 : && ! DECL_REALLY_EXTERN (fn)
5685 : /* Do not emit thunks for tentative decls, those will be processed
5686 : again at_eof if really needed. */
5687 61978029 : && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
5688 : {
5689 1040446 : tree thunk;
5690 :
5691 1044916 : for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
5692 : {
5693 4470 : if (!THUNK_ALIAS (thunk))
5694 : {
5695 4470 : use_thunk (thunk, /*emit_p=*/1);
5696 4470 : if (DECL_RESULT_THUNK_P (thunk))
5697 : {
5698 181 : tree probe;
5699 :
5700 181 : for (probe = DECL_THUNKS (thunk);
5701 333 : probe; probe = DECL_CHAIN (probe))
5702 152 : use_thunk (probe, /*emit_p=*/1);
5703 : }
5704 : }
5705 : else
5706 0 : gcc_assert (!DECL_THUNKS (thunk));
5707 : }
5708 : }
5709 60936412 : }
5710 :
5711 : /* Generate RTL for FN. */
5712 :
5713 : bool
5714 165781600 : expand_or_defer_fn_1 (tree fn)
5715 : {
5716 : /* When the parser calls us after finishing the body of a template
5717 : function, we don't really want to expand the body. */
5718 165781600 : if (processing_template_decl)
5719 : {
5720 : /* Normally, collection only occurs in rest_of_compilation. So,
5721 : if we don't collect here, we never collect junk generated
5722 : during the processing of templates until we hit a
5723 : non-template function. It's not safe to do this inside a
5724 : nested class, though, as the parser may have local state that
5725 : is not a GC root. */
5726 96709432 : if (!function_depth)
5727 96263038 : ggc_collect ();
5728 : return false;
5729 : }
5730 :
5731 69072168 : gcc_assert (DECL_SAVED_TREE (fn));
5732 :
5733 : /* We make a decision about linkage for these functions at the end
5734 : of the compilation. Until that point, we do not want the back
5735 : end to output them -- but we do want it to see the bodies of
5736 : these functions so that it can inline them as appropriate. */
5737 69072168 : if (DECL_DECLARED_INLINE_P (fn)
5738 1943237 : || DECL_IMPLICIT_INSTANTIATION (fn)
5739 69333637 : || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (fn))
5740 : {
5741 68810726 : if (DECL_INTERFACE_KNOWN (fn))
5742 : /* We've already made a decision as to how this function will
5743 : be handled. */;
5744 48708518 : else if (!at_eof
5745 17675811 : || DECL_IMMEDIATE_FUNCTION_P (fn)
5746 65951579 : || DECL_OMP_DECLARE_REDUCTION_P (fn))
5747 31465457 : tentative_decl_linkage (fn);
5748 : else
5749 17243061 : import_export_decl (fn);
5750 :
5751 : /* If the user wants us to keep all inline functions, then mark
5752 : this function as needed so that finish_file will make sure to
5753 : output it later. Similarly, all dllexport'd functions must
5754 : be emitted; there may be callers in other DLLs. */
5755 68810726 : if (DECL_DECLARED_INLINE_P (fn)
5756 67128931 : && !DECL_REALLY_EXTERN (fn)
5757 63429195 : && !DECL_IMMEDIATE_FUNCTION_P (fn)
5758 62384137 : && !DECL_OMP_DECLARE_REDUCTION_P (fn)
5759 131194863 : && (flag_keep_inline_functions
5760 62381344 : || (flag_keep_inline_dllexport
5761 62381344 : && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
5762 : {
5763 2793 : mark_needed (fn);
5764 2793 : DECL_EXTERNAL (fn) = 0;
5765 : }
5766 : }
5767 :
5768 : /* If this is a constructor or destructor body, we have to clone
5769 : it. */
5770 69072168 : if (maybe_clone_body (fn))
5771 : {
5772 : /* We don't want to process FN again, so pretend we've written
5773 : it out, even though we haven't. */
5774 8107537 : TREE_ASM_WRITTEN (fn) = 1;
5775 : /* If this is a constexpr function we still need the body to be
5776 : able to evaluate it. Similarly, with modules we only stream
5777 : the maybe-in-charge cdtor and regenerate the clones from it on
5778 : demand, so we also need to keep the body. Otherwise we don't
5779 : need it anymore. */
5780 8107537 : if (!maybe_constexpr_fn (fn)
5781 8107537 : && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
5782 3783646 : DECL_SAVED_TREE (fn) = void_node;
5783 : return false;
5784 : }
5785 :
5786 : /* There's no reason to do any of the work here if we're only doing
5787 : semantic analysis; this code just generates RTL. */
5788 60964631 : if (flag_syntax_only)
5789 : {
5790 : /* Pretend that this function has been written out so that we don't try
5791 : to expand it again. */
5792 28203 : TREE_ASM_WRITTEN (fn) = 1;
5793 28203 : return false;
5794 : }
5795 :
5796 60936428 : if (DECL_OMP_DECLARE_REDUCTION_P (fn))
5797 16 : return false;
5798 :
5799 : return true;
5800 : }
5801 :
5802 : void
5803 157691648 : expand_or_defer_fn (tree fn)
5804 : {
5805 157691648 : if (expand_or_defer_fn_1 (fn))
5806 : {
5807 52848951 : function_depth++;
5808 :
5809 : /* Expand or defer, at the whim of the compilation unit manager. */
5810 52848951 : cgraph_node::finalize_function (fn, function_depth > 1);
5811 52848951 : emit_associated_thunks (fn);
5812 :
5813 52848951 : function_depth--;
5814 :
5815 105697902 : if (DECL_IMMEDIATE_FUNCTION_P (fn))
5816 : {
5817 1001368 : if (cgraph_node *node = cgraph_node::get (fn))
5818 : {
5819 1001368 : node->body_removed = true;
5820 1001368 : node->analyzed = false;
5821 1001368 : node->definition = false;
5822 1001368 : node->force_output = false;
5823 : }
5824 : }
5825 : }
5826 157691648 : }
5827 :
5828 459516 : class nrv_data
5829 : {
5830 : public:
5831 229758 : nrv_data () : visited (37) {}
5832 :
5833 : tree var;
5834 : tree result;
5835 : hash_set<tree> visited;
5836 : bool simple;
5837 : bool in_nrv_cleanup;
5838 : };
5839 :
5840 : /* Helper function for walk_tree, used by finalize_nrv below. */
5841 :
5842 : static tree
5843 20914199 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
5844 : {
5845 20914199 : class nrv_data *dp = (class nrv_data *)data;
5846 :
5847 : /* No need to walk into types. There wouldn't be any need to walk into
5848 : non-statements, except that we have to consider STMT_EXPRs. */
5849 20914199 : if (TYPE_P (*tp))
5850 190242 : *walk_subtrees = 0;
5851 :
5852 : /* Replace all uses of the NRV with the RESULT_DECL. */
5853 20723957 : else if (*tp == dp->var)
5854 499708 : *tp = dp->result;
5855 :
5856 : /* Avoid walking into the same tree more than once. Unfortunately, we
5857 : can't just use walk_tree_without duplicates because it would only call
5858 : us for the first occurrence of dp->var in the function body. */
5859 20224249 : else if (dp->visited.add (*tp))
5860 4439838 : *walk_subtrees = 0;
5861 :
5862 : /* If there's a label, we might need to destroy the NRV on goto (92407). */
5863 15784411 : else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
5864 3 : dp->simple = false;
5865 : /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
5866 : but differs from using NULL_TREE in that it indicates that we care
5867 : about the value of the RESULT_DECL. But preserve anything appended
5868 : by check_return_expr. */
5869 15784408 : else if (TREE_CODE (*tp) == RETURN_EXPR)
5870 : {
5871 235950 : tree *p = &TREE_OPERAND (*tp, 0);
5872 604875 : while (TREE_CODE (*p) == COMPOUND_EXPR)
5873 132975 : p = &TREE_OPERAND (*p, 0);
5874 235950 : if (TREE_CODE (*p) == INIT_EXPR
5875 235950 : && INIT_EXPR_NRV_P (*p))
5876 235540 : *p = dp->result;
5877 : }
5878 : /* Change all cleanups for the NRV to only run when not returning. */
5879 15548458 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5880 15548458 : && CLEANUP_DECL (*tp) == dp->var)
5881 : {
5882 127793 : dp->in_nrv_cleanup = true;
5883 127793 : cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
5884 127793 : dp->in_nrv_cleanup = false;
5885 127793 : cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
5886 127793 : *walk_subtrees = 0;
5887 :
5888 127793 : if (dp->simple)
5889 : /* For a simple NRV, just run it on the EH path. */
5890 127132 : CLEANUP_EH_ONLY (*tp) = true;
5891 : else
5892 : {
5893 : /* Not simple, we need to check current_retval_sentinel to decide
5894 : whether to run it. If it's set, we're returning normally and
5895 : don't want to destroy the NRV. If the sentinel is not set, we're
5896 : leaving scope some other way, either by flowing off the end of its
5897 : scope or throwing an exception. */
5898 1983 : tree cond = build3 (COND_EXPR, void_type_node,
5899 661 : current_retval_sentinel,
5900 661 : void_node, CLEANUP_EXPR (*tp));
5901 661 : CLEANUP_EXPR (*tp) = cond;
5902 : }
5903 :
5904 : /* If a cleanup might throw, we need to clear current_retval_sentinel on
5905 : the exception path, both so the check above succeeds and so an outer
5906 : cleanup added by maybe_splice_retval_cleanup doesn't run. */
5907 127793 : if (cp_function_chain->throwing_cleanup)
5908 : {
5909 166 : tree clear = build2 (MODIFY_EXPR, boolean_type_node,
5910 : current_retval_sentinel,
5911 : boolean_false_node);
5912 166 : if (dp->simple)
5913 : {
5914 : /* We're already only on the EH path, just prepend it. */
5915 156 : tree &exp = CLEANUP_EXPR (*tp);
5916 156 : exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
5917 : }
5918 : else
5919 : {
5920 : /* The cleanup runs on both normal and EH paths, we need another
5921 : CLEANUP_STMT to clear the flag only on the EH path. */
5922 10 : tree &bod = CLEANUP_BODY (*tp);
5923 10 : bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
5924 10 : bod, clear, current_retval_sentinel);
5925 10 : CLEANUP_EH_ONLY (bod) = true;
5926 : }
5927 : }
5928 : }
5929 : /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
5930 : want to destroy the retval before the variable goes out of scope. */
5931 15420665 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5932 4878 : && dp->in_nrv_cleanup
5933 15424152 : && CLEANUP_DECL (*tp) == dp->result)
5934 6 : CLEANUP_EXPR (*tp) = void_node;
5935 : /* Replace the DECL_EXPR for the NRV with an initialization of the
5936 : RESULT_DECL, if needed. */
5937 15420659 : else if (TREE_CODE (*tp) == DECL_EXPR
5938 15420659 : && DECL_EXPR_DECL (*tp) == dp->var)
5939 : {
5940 229760 : tree init;
5941 229760 : if (DECL_INITIAL (dp->var)
5942 229760 : && DECL_INITIAL (dp->var) != error_mark_node)
5943 94115 : init = cp_build_init_expr (dp->result,
5944 94115 : DECL_INITIAL (dp->var));
5945 : else
5946 135645 : init = build_empty_stmt (EXPR_LOCATION (*tp));
5947 229760 : DECL_INITIAL (dp->var) = NULL_TREE;
5948 229760 : SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
5949 229760 : *tp = init;
5950 : }
5951 :
5952 : /* Keep iterating. */
5953 20914199 : return NULL_TREE;
5954 : }
5955 :
5956 : /* Called from finish_function to implement the named return value
5957 : optimization by overriding all the RETURN_EXPRs and pertinent
5958 : CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5959 : RESULT_DECL for the function. */
5960 :
5961 : void
5962 229758 : finalize_nrv (tree fndecl, tree var)
5963 : {
5964 229758 : class nrv_data data;
5965 229758 : tree result = DECL_RESULT (fndecl);
5966 :
5967 : /* Copy name from VAR to RESULT. */
5968 229758 : DECL_NAME (result) = DECL_NAME (var);
5969 : /* Don't forget that we take its address. */
5970 229758 : TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
5971 : /* Finally set DECL_VALUE_EXPR to avoid assigning
5972 : a stack slot at -O0 for the original var and debug info
5973 : uses RESULT location for VAR. */
5974 229758 : SET_DECL_VALUE_EXPR (var, result);
5975 229758 : DECL_HAS_VALUE_EXPR_P (var) = 1;
5976 :
5977 229758 : data.var = var;
5978 229758 : data.result = result;
5979 229758 : data.in_nrv_cleanup = false;
5980 :
5981 : /* This is simpler for variables declared in the outer scope of
5982 : the function so we know that their lifetime always ends with a
5983 : return; see g++.dg/opt/nrv6.C. */
5984 229758 : tree outer = outer_curly_brace_block (fndecl);
5985 229758 : data.simple = chain_member (var, BLOCK_VARS (outer));
5986 :
5987 229758 : cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
5988 229758 : }
5989 :
5990 : /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5991 :
5992 : bool
5993 2283 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
5994 : bool need_copy_ctor, bool need_copy_assignment,
5995 : bool need_dtor)
5996 : {
5997 2283 : int save_errorcount = errorcount;
5998 2283 : tree info, t;
5999 :
6000 : /* Always allocate 3 elements for simplicity. These are the
6001 : function decls for the ctor, dtor, and assignment op.
6002 : This layout is known to the three lang hooks,
6003 : cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
6004 : and cxx_omp_clause_assign_op. */
6005 2283 : info = make_tree_vec (3);
6006 2283 : CP_OMP_CLAUSE_INFO (c) = info;
6007 :
6008 2283 : if (need_default_ctor || need_copy_ctor)
6009 : {
6010 1672 : if (need_default_ctor)
6011 1271 : t = get_default_ctor (type);
6012 : else
6013 401 : t = get_copy_ctor (type, tf_warning_or_error);
6014 :
6015 1672 : if (t && !trivial_fn_p (t))
6016 1416 : TREE_VEC_ELT (info, 0) = t;
6017 : }
6018 :
6019 2283 : if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
6020 1664 : TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
6021 :
6022 2283 : if (need_copy_assignment)
6023 : {
6024 397 : t = get_copy_assign (type);
6025 :
6026 397 : if (t && !trivial_fn_p (t))
6027 344 : TREE_VEC_ELT (info, 2) = t;
6028 : }
6029 :
6030 2283 : return errorcount != save_errorcount;
6031 : }
6032 :
6033 : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
6034 : FIELD_DECL, otherwise return DECL itself. */
6035 :
6036 : static tree
6037 26773 : omp_clause_decl_field (tree decl)
6038 : {
6039 26773 : if (VAR_P (decl)
6040 18706 : && DECL_HAS_VALUE_EXPR_P (decl)
6041 359 : && DECL_ARTIFICIAL (decl)
6042 359 : && DECL_LANG_SPECIFIC (decl)
6043 27108 : && DECL_OMP_PRIVATIZED_MEMBER (decl))
6044 : {
6045 328 : tree f = DECL_VALUE_EXPR (decl);
6046 328 : if (INDIRECT_REF_P (f))
6047 0 : f = TREE_OPERAND (f, 0);
6048 328 : if (TREE_CODE (f) == COMPONENT_REF)
6049 : {
6050 328 : f = TREE_OPERAND (f, 1);
6051 328 : gcc_assert (TREE_CODE (f) == FIELD_DECL);
6052 : return f;
6053 : }
6054 : }
6055 : return NULL_TREE;
6056 : }
6057 :
6058 : /* Adjust DECL if needed for printing using %qE. */
6059 :
6060 : static tree
6061 187 : omp_clause_printable_decl (tree decl)
6062 : {
6063 0 : tree t = omp_clause_decl_field (decl);
6064 187 : if (t)
6065 45 : return t;
6066 : return decl;
6067 : }
6068 :
6069 : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
6070 : VAR_DECL T that doesn't need a DECL_EXPR added, record it for
6071 : privatization. */
6072 :
6073 : static void
6074 219 : omp_note_field_privatization (tree f, tree t)
6075 : {
6076 219 : if (!omp_private_member_map)
6077 71 : omp_private_member_map = new hash_map<tree, tree>;
6078 219 : tree &v = omp_private_member_map->get_or_insert (f);
6079 219 : if (v == NULL_TREE)
6080 : {
6081 146 : v = t;
6082 146 : omp_private_member_vec.safe_push (f);
6083 : /* Signal that we don't want to create DECL_EXPR for this dummy var. */
6084 146 : omp_private_member_vec.safe_push (integer_zero_node);
6085 : }
6086 219 : }
6087 :
6088 : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
6089 : dummy VAR_DECL. */
6090 :
6091 : tree
6092 861 : omp_privatize_field (tree t, bool shared)
6093 : {
6094 861 : tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6095 861 : if (m == error_mark_node)
6096 : return error_mark_node;
6097 861 : if (!omp_private_member_map && !shared)
6098 365 : omp_private_member_map = new hash_map<tree, tree>;
6099 861 : if (TYPE_REF_P (TREE_TYPE (t)))
6100 : {
6101 123 : gcc_assert (INDIRECT_REF_P (m));
6102 123 : m = TREE_OPERAND (m, 0);
6103 : }
6104 861 : tree vb = NULL_TREE;
6105 861 : tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
6106 861 : if (v == NULL_TREE)
6107 : {
6108 770 : v = create_temporary_var (TREE_TYPE (m));
6109 770 : retrofit_lang_decl (v);
6110 770 : DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
6111 770 : SET_DECL_VALUE_EXPR (v, m);
6112 770 : DECL_HAS_VALUE_EXPR_P (v) = 1;
6113 770 : if (!shared)
6114 690 : omp_private_member_vec.safe_push (t);
6115 : }
6116 861 : return v;
6117 : }
6118 :
6119 : /* C++ specialisation of the c_omp_address_inspector class. */
6120 :
6121 : class cp_omp_address_inspector : public c_omp_address_inspector
6122 : {
6123 : public:
6124 31572 : cp_omp_address_inspector (location_t loc, tree t)
6125 31572 : : c_omp_address_inspector (loc, t)
6126 : {
6127 : }
6128 :
6129 31572 : ~cp_omp_address_inspector ()
6130 : {
6131 23125 : }
6132 :
6133 134817 : bool processing_template_decl_p ()
6134 : {
6135 134817 : return processing_template_decl;
6136 : }
6137 :
6138 0 : void emit_unmappable_type_notes (tree t)
6139 : {
6140 0 : if (TREE_TYPE (t) != error_mark_node
6141 0 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
6142 0 : cxx_incomplete_type_inform (TREE_TYPE (t));
6143 0 : }
6144 :
6145 1062 : tree convert_from_reference (tree x)
6146 : {
6147 1062 : return ::convert_from_reference (x);
6148 : }
6149 :
6150 147 : tree build_array_ref (location_t loc, tree arr, tree idx)
6151 : {
6152 147 : return ::build_array_ref (loc, arr, idx);
6153 : }
6154 :
6155 23067 : bool check_clause (tree clause)
6156 : {
6157 23067 : if (TREE_CODE (orig) == COMPONENT_REF
6158 23067 : && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
6159 : tf_warning_or_error))
6160 : return false;
6161 23064 : if (!c_omp_address_inspector::check_clause (clause))
6162 : return false;
6163 : return true;
6164 : }
6165 : };
6166 :
6167 : /* Helper function for handle_omp_array_sections. Called recursively
6168 : to handle multiple array-section-subscripts. C is the clause,
6169 : T current expression (initially OMP_CLAUSE_DECL), which is either
6170 : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
6171 : expression if specified, TREE_VALUE length expression if specified,
6172 : TREE_CHAIN is what it has been specified after, or some decl.
6173 : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
6174 : set to true if any of the array-section-subscript could have length
6175 : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
6176 : first array-section-subscript which is known not to have length
6177 : of one. Given say:
6178 : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
6179 : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
6180 : all are or may have length of 1, array-section-subscript [:2] is the
6181 : first one known not to have length 1. For array-section-subscript
6182 : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
6183 : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
6184 : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
6185 : case though, as some lengths could be zero. */
6186 :
6187 : static tree
6188 21514 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
6189 : bool &maybe_zero_len, unsigned int &first_non_one,
6190 : enum c_omp_region_type ort)
6191 : {
6192 21514 : tree ret, low_bound, length, type;
6193 21514 : bool openacc = (ort & C_ORT_ACC) != 0;
6194 21514 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
6195 : {
6196 9718 : if (error_operand_p (t))
6197 6 : return error_mark_node;
6198 :
6199 9712 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6200 9712 : tree t_refto = ai.maybe_unconvert_ref (t);
6201 :
6202 9712 : if (!ai.check_clause (c))
6203 0 : return error_mark_node;
6204 9712 : else if (ai.component_access_p ()
6205 11100 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6206 64 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
6207 40 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
6208 1388 : t = ai.get_root_term (true);
6209 : else
6210 8324 : t = ai.unconverted_ref_origin ();
6211 9712 : if (t == error_mark_node)
6212 : return error_mark_node;
6213 9712 : ret = t_refto;
6214 9712 : if (TREE_CODE (t) == FIELD_DECL)
6215 33 : ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6216 9679 : else if (!VAR_P (t)
6217 2871 : && (openacc || !EXPR_P (t))
6218 2676 : && TREE_CODE (t) != PARM_DECL)
6219 : {
6220 51 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6221 : return NULL_TREE;
6222 33 : if (DECL_P (t))
6223 33 : error_at (OMP_CLAUSE_LOCATION (c),
6224 : "%qD is not a variable in %qs clause", t,
6225 33 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6226 : else
6227 0 : error_at (OMP_CLAUSE_LOCATION (c),
6228 : "%qE is not a variable in %qs clause", t,
6229 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6230 33 : return error_mark_node;
6231 : }
6232 9628 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6233 9237 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6234 17936 : && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
6235 : {
6236 18 : error_at (OMP_CLAUSE_LOCATION (c),
6237 : "%qD is threadprivate variable in %qs clause", t,
6238 18 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6239 18 : return error_mark_node;
6240 : }
6241 9643 : if (type_dependent_expression_p (ret))
6242 : return NULL_TREE;
6243 8932 : ret = convert_from_reference (ret);
6244 8932 : return ret;
6245 9712 : }
6246 :
6247 11796 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
6248 7869 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6249 6567 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6250 5283 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6251 14510 : && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
6252 43 : TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
6253 11796 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
6254 : maybe_zero_len, first_non_one, ort);
6255 11796 : if (ret == error_mark_node || ret == NULL_TREE)
6256 : return ret;
6257 :
6258 10726 : type = TREE_TYPE (ret);
6259 10726 : low_bound = TREE_OPERAND (t, 1);
6260 10726 : length = TREE_OPERAND (t, 2);
6261 8607 : if ((low_bound && type_dependent_expression_p (low_bound))
6262 19250 : || (length && type_dependent_expression_p (length)))
6263 : return NULL_TREE;
6264 :
6265 10638 : if (low_bound == error_mark_node || length == error_mark_node)
6266 : return error_mark_node;
6267 :
6268 10626 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
6269 : {
6270 75 : error_at (OMP_CLAUSE_LOCATION (c),
6271 : "low bound %qE of array section does not have integral type",
6272 : low_bound);
6273 75 : return error_mark_node;
6274 : }
6275 10551 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
6276 : {
6277 75 : error_at (OMP_CLAUSE_LOCATION (c),
6278 : "length %qE of array section does not have integral type",
6279 : length);
6280 75 : return error_mark_node;
6281 : }
6282 10476 : if (low_bound)
6283 8423 : low_bound = mark_rvalue_use (low_bound);
6284 10476 : if (length)
6285 9413 : length = mark_rvalue_use (length);
6286 : /* We need to reduce to real constant-values for checks below. */
6287 9413 : if (length)
6288 9413 : length = fold_simple (length);
6289 10476 : if (low_bound)
6290 8423 : low_bound = fold_simple (low_bound);
6291 8423 : if (low_bound
6292 8423 : && TREE_CODE (low_bound) == INTEGER_CST
6293 15909 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6294 7486 : > TYPE_PRECISION (sizetype))
6295 0 : low_bound = fold_convert (sizetype, low_bound);
6296 10476 : if (length
6297 9413 : && TREE_CODE (length) == INTEGER_CST
6298 17866 : && TYPE_PRECISION (TREE_TYPE (length))
6299 7390 : > TYPE_PRECISION (sizetype))
6300 0 : length = fold_convert (sizetype, length);
6301 10476 : if (low_bound == NULL_TREE)
6302 2053 : low_bound = integer_zero_node;
6303 :
6304 10476 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6305 10476 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
6306 5168 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
6307 : {
6308 60 : if (length != integer_one_node)
6309 : {
6310 36 : error_at (OMP_CLAUSE_LOCATION (c),
6311 : "expected single pointer in %qs clause",
6312 : user_omp_clause_code_name (c, openacc));
6313 36 : return error_mark_node;
6314 : }
6315 : }
6316 10440 : if (length != NULL_TREE)
6317 : {
6318 9401 : if (!integer_nonzerop (length))
6319 : {
6320 2078 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6321 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6322 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6323 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6324 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6325 : {
6326 479 : if (integer_zerop (length))
6327 : {
6328 36 : error_at (OMP_CLAUSE_LOCATION (c),
6329 : "zero length array section in %qs clause",
6330 36 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6331 36 : return error_mark_node;
6332 : }
6333 : }
6334 : else
6335 1599 : maybe_zero_len = true;
6336 : }
6337 9365 : if (first_non_one == types.length ()
6338 9365 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
6339 3999 : first_non_one++;
6340 : }
6341 10404 : if (TREE_CODE (type) == ARRAY_TYPE)
6342 : {
6343 5796 : if (length == NULL_TREE
6344 5796 : && (TYPE_DOMAIN (type) == NULL_TREE
6345 955 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
6346 : {
6347 33 : error_at (OMP_CLAUSE_LOCATION (c),
6348 : "for unknown bound array type length expression must "
6349 : "be specified");
6350 33 : return error_mark_node;
6351 : }
6352 5763 : if (TREE_CODE (low_bound) == INTEGER_CST
6353 5763 : && tree_int_cst_sgn (low_bound) == -1)
6354 : {
6355 177 : error_at (OMP_CLAUSE_LOCATION (c),
6356 : "negative low bound in array section in %qs clause",
6357 177 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6358 177 : return error_mark_node;
6359 : }
6360 5586 : if (length != NULL_TREE
6361 4688 : && TREE_CODE (length) == INTEGER_CST
6362 9348 : && tree_int_cst_sgn (length) == -1)
6363 : {
6364 177 : error_at (OMP_CLAUSE_LOCATION (c),
6365 : "negative length in array section in %qs clause",
6366 177 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6367 177 : return error_mark_node;
6368 : }
6369 5409 : if (TYPE_DOMAIN (type)
6370 5310 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6371 10719 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
6372 : == INTEGER_CST)
6373 : {
6374 4914 : tree size
6375 4914 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6376 4914 : size = size_binop (PLUS_EXPR, size, size_one_node);
6377 4914 : if (TREE_CODE (low_bound) == INTEGER_CST)
6378 : {
6379 4137 : if (tree_int_cst_lt (size, low_bound))
6380 : {
6381 63 : error_at (OMP_CLAUSE_LOCATION (c),
6382 : "low bound %qE above array section size "
6383 : "in %qs clause", low_bound,
6384 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6385 63 : return error_mark_node;
6386 : }
6387 4074 : if (tree_int_cst_equal (size, low_bound))
6388 : {
6389 21 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6390 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6391 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6392 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6393 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6394 : {
6395 21 : error_at (OMP_CLAUSE_LOCATION (c),
6396 : "zero length array section in %qs clause",
6397 21 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6398 21 : return error_mark_node;
6399 : }
6400 0 : maybe_zero_len = true;
6401 : }
6402 4053 : else if (length == NULL_TREE
6403 1578 : && first_non_one == types.length ()
6404 4406 : && tree_int_cst_equal
6405 353 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6406 : low_bound))
6407 207 : first_non_one++;
6408 : }
6409 777 : else if (length == NULL_TREE)
6410 : {
6411 24 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6412 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6413 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6414 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6415 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6416 13 : maybe_zero_len = true;
6417 48 : if (first_non_one == types.length ())
6418 21 : first_non_one++;
6419 : }
6420 4830 : if (length && TREE_CODE (length) == INTEGER_CST)
6421 : {
6422 3465 : if (tree_int_cst_lt (size, length))
6423 : {
6424 63 : error_at (OMP_CLAUSE_LOCATION (c),
6425 : "length %qE above array section size "
6426 : "in %qs clause", length,
6427 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6428 63 : return error_mark_node;
6429 : }
6430 3402 : if (TREE_CODE (low_bound) == INTEGER_CST)
6431 : {
6432 3064 : tree lbpluslen
6433 3064 : = size_binop (PLUS_EXPR,
6434 : fold_convert (sizetype, low_bound),
6435 : fold_convert (sizetype, length));
6436 3064 : if (TREE_CODE (lbpluslen) == INTEGER_CST
6437 3064 : && tree_int_cst_lt (size, lbpluslen))
6438 : {
6439 60 : error_at (OMP_CLAUSE_LOCATION (c),
6440 : "high bound %qE above array section size "
6441 : "in %qs clause", lbpluslen,
6442 60 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6443 60 : return error_mark_node;
6444 : }
6445 : }
6446 : }
6447 : }
6448 495 : else if (length == NULL_TREE)
6449 : {
6450 1 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6451 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6452 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6453 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6454 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6455 0 : maybe_zero_len = true;
6456 2 : if (first_non_one == types.length ())
6457 1 : first_non_one++;
6458 : }
6459 :
6460 : /* For [lb:] we will need to evaluate lb more than once. */
6461 4157 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6462 : {
6463 733 : tree lb = cp_save_expr (low_bound);
6464 733 : if (lb != low_bound)
6465 : {
6466 13 : TREE_OPERAND (t, 1) = lb;
6467 13 : low_bound = lb;
6468 : }
6469 : }
6470 : }
6471 4608 : else if (TYPE_PTR_P (type))
6472 : {
6473 4548 : if (length == NULL_TREE)
6474 : {
6475 51 : if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
6476 45 : error_at (OMP_CLAUSE_LOCATION (c),
6477 : "for array function parameter length expression "
6478 : "must be specified");
6479 : else
6480 6 : error_at (OMP_CLAUSE_LOCATION (c),
6481 : "for pointer type length expression must be specified");
6482 51 : return error_mark_node;
6483 : }
6484 4497 : if (length != NULL_TREE
6485 4497 : && TREE_CODE (length) == INTEGER_CST
6486 3400 : && tree_int_cst_sgn (length) == -1)
6487 : {
6488 96 : error_at (OMP_CLAUSE_LOCATION (c),
6489 : "negative length in array section in %qs clause",
6490 96 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6491 96 : return error_mark_node;
6492 : }
6493 : /* If there is a pointer type anywhere but in the very first
6494 : array-section-subscript, the array section could be non-contiguous. */
6495 4401 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6496 4299 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6497 8215 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
6498 : {
6499 : /* If any prior dimension has a non-one length, then deem this
6500 : array section as non-contiguous. */
6501 159 : for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
6502 69 : d = TREE_OPERAND (d, 0))
6503 : {
6504 90 : tree d_length = TREE_OPERAND (d, 2);
6505 90 : if (d_length == NULL_TREE || !integer_onep (d_length))
6506 : {
6507 21 : error_at (OMP_CLAUSE_LOCATION (c),
6508 : "array section is not contiguous in %qs clause",
6509 21 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6510 21 : return error_mark_node;
6511 : }
6512 : }
6513 : }
6514 : }
6515 : else
6516 : {
6517 60 : error_at (OMP_CLAUSE_LOCATION (c),
6518 : "%qE does not have pointer or array type", ret);
6519 60 : return error_mark_node;
6520 : }
6521 9582 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6522 8677 : types.safe_push (TREE_TYPE (ret));
6523 : /* We will need to evaluate lb more than once. */
6524 9582 : tree lb = cp_save_expr (low_bound);
6525 9582 : if (lb != low_bound)
6526 : {
6527 722 : TREE_OPERAND (t, 1) = lb;
6528 722 : low_bound = lb;
6529 : }
6530 : /* Temporarily disable -fstrong-eval-order for array reductions.
6531 : The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
6532 : is something the middle-end can't cope with and more importantly,
6533 : it needs to be the actual base variable that is privatized, not some
6534 : temporary assigned previous value of it. That, together with OpenMP
6535 : saying how many times the side-effects are evaluated is unspecified,
6536 : makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
6537 9582 : warning_sentinel s (flag_strong_eval_order,
6538 9582 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6539 8485 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6540 16933 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
6541 9582 : ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
6542 : tf_warning_or_error);
6543 9582 : return ret;
6544 9582 : }
6545 :
6546 : /* Handle array sections for clause C. */
6547 :
6548 : static bool
6549 9718 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
6550 : {
6551 9718 : bool maybe_zero_len = false;
6552 9718 : unsigned int first_non_one = 0;
6553 9718 : auto_vec<tree, 10> types;
6554 9718 : tree *tp = &OMP_CLAUSE_DECL (c);
6555 9718 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6556 8759 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6557 10127 : && OMP_ITERATOR_DECL_P (*tp))
6558 258 : tp = &TREE_VALUE (*tp);
6559 9718 : tree first = handle_omp_array_sections_1 (c, *tp, types,
6560 : maybe_zero_len, first_non_one,
6561 : ort);
6562 9718 : if (first == error_mark_node)
6563 : return true;
6564 8605 : if (first == NULL_TREE)
6565 : return false;
6566 7788 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6567 7788 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6568 : {
6569 951 : tree t = *tp;
6570 951 : tree tem = NULL_TREE;
6571 951 : if (processing_template_decl)
6572 : return false;
6573 : /* Need to evaluate side effects in the length expressions
6574 : if any. */
6575 852 : while (TREE_CODE (t) == TREE_LIST)
6576 : {
6577 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
6578 : {
6579 0 : if (tem == NULL_TREE)
6580 : tem = TREE_VALUE (t);
6581 : else
6582 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
6583 0 : TREE_VALUE (t), tem);
6584 : }
6585 0 : t = TREE_CHAIN (t);
6586 : }
6587 852 : if (tem)
6588 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
6589 852 : *tp = first;
6590 : }
6591 : else
6592 : {
6593 6837 : unsigned int num = types.length (), i;
6594 6837 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
6595 6837 : tree condition = NULL_TREE;
6596 :
6597 6837 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
6598 3 : maybe_zero_len = true;
6599 6837 : if (processing_template_decl && maybe_zero_len)
6600 : return false;
6601 :
6602 14382 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
6603 7623 : t = TREE_OPERAND (t, 0))
6604 : {
6605 7698 : gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
6606 :
6607 7698 : tree low_bound = TREE_OPERAND (t, 1);
6608 7698 : tree length = TREE_OPERAND (t, 2);
6609 :
6610 7698 : i--;
6611 7698 : if (low_bound
6612 6252 : && TREE_CODE (low_bound) == INTEGER_CST
6613 13339 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6614 5641 : > TYPE_PRECISION (sizetype))
6615 0 : low_bound = fold_convert (sizetype, low_bound);
6616 7698 : if (length
6617 7149 : && TREE_CODE (length) == INTEGER_CST
6618 12955 : && TYPE_PRECISION (TREE_TYPE (length))
6619 5257 : > TYPE_PRECISION (sizetype))
6620 0 : length = fold_convert (sizetype, length);
6621 7698 : if (low_bound == NULL_TREE)
6622 1446 : low_bound = integer_zero_node;
6623 7698 : if (!maybe_zero_len && i > first_non_one)
6624 : {
6625 646 : if (integer_nonzerop (low_bound))
6626 36 : goto do_warn_noncontiguous;
6627 610 : if (length != NULL_TREE
6628 282 : && TREE_CODE (length) == INTEGER_CST
6629 282 : && TYPE_DOMAIN (types[i])
6630 282 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
6631 892 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
6632 : == INTEGER_CST)
6633 : {
6634 282 : tree size;
6635 282 : size = size_binop (PLUS_EXPR,
6636 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6637 : size_one_node);
6638 282 : if (!tree_int_cst_equal (length, size))
6639 : {
6640 39 : do_warn_noncontiguous:
6641 150 : error_at (OMP_CLAUSE_LOCATION (c),
6642 : "array section is not contiguous in %qs "
6643 : "clause",
6644 75 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6645 75 : return true;
6646 : }
6647 : }
6648 571 : if (!processing_template_decl
6649 401 : && length != NULL_TREE
6650 742 : && TREE_SIDE_EFFECTS (length))
6651 : {
6652 0 : if (side_effects == NULL_TREE)
6653 : side_effects = length;
6654 : else
6655 0 : side_effects = build2 (COMPOUND_EXPR,
6656 0 : TREE_TYPE (side_effects),
6657 : length, side_effects);
6658 : }
6659 : }
6660 7052 : else if (processing_template_decl)
6661 726 : continue;
6662 : else
6663 : {
6664 6326 : tree l;
6665 :
6666 6326 : if (i > first_non_one
6667 6326 : && ((length && integer_nonzerop (length))
6668 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6669 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6670 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
6671 0 : continue;
6672 6326 : if (length)
6673 6187 : l = fold_convert (sizetype, length);
6674 : else
6675 : {
6676 139 : l = size_binop (PLUS_EXPR,
6677 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6678 : size_one_node);
6679 139 : l = size_binop (MINUS_EXPR, l,
6680 : fold_convert (sizetype, low_bound));
6681 : }
6682 6326 : if (i > first_non_one)
6683 : {
6684 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
6685 : size_zero_node);
6686 0 : if (condition == NULL_TREE)
6687 : condition = l;
6688 : else
6689 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
6690 : l, condition);
6691 : }
6692 6326 : else if (size == NULL_TREE)
6693 : {
6694 6039 : size = size_in_bytes (TREE_TYPE (types[i]));
6695 6039 : tree eltype = TREE_TYPE (types[num - 1]);
6696 6110 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6697 71 : eltype = TREE_TYPE (eltype);
6698 6039 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6699 5229 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6700 10515 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6701 1659 : size = size_binop (EXACT_DIV_EXPR, size,
6702 : size_in_bytes (eltype));
6703 6039 : size = size_binop (MULT_EXPR, size, l);
6704 6039 : if (condition)
6705 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
6706 : size, size_zero_node);
6707 : }
6708 : else
6709 287 : size = size_binop (MULT_EXPR, size, l);
6710 : }
6711 : }
6712 6684 : if (!processing_template_decl)
6713 : {
6714 6039 : if (side_effects)
6715 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
6716 6039 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6717 5229 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6718 10515 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6719 : {
6720 1659 : size = size_binop (MINUS_EXPR, size, size_one_node);
6721 1659 : size = save_expr (size);
6722 1659 : tree index_type = build_index_type (size);
6723 1659 : tree eltype = TREE_TYPE (first);
6724 1688 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6725 29 : eltype = TREE_TYPE (eltype);
6726 1659 : tree type = build_array_type (eltype, index_type);
6727 1659 : tree ptype = build_pointer_type (eltype);
6728 1659 : if (TYPE_REF_P (TREE_TYPE (t))
6729 1659 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
6730 170 : t = convert_from_reference (t);
6731 1489 : else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6732 641 : t = build_fold_addr_expr (t);
6733 1659 : tree t2 = build_fold_addr_expr (first);
6734 1659 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6735 : ptrdiff_type_node, t2);
6736 1659 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
6737 : ptrdiff_type_node, t2,
6738 1659 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6739 : ptrdiff_type_node, t));
6740 1659 : if (tree_fits_shwi_p (t2))
6741 1321 : t = build2 (MEM_REF, type, t,
6742 1321 : build_int_cst (ptype, tree_to_shwi (t2)));
6743 : else
6744 : {
6745 338 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6746 : sizetype, t2);
6747 338 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
6748 338 : TREE_TYPE (t), t, t2);
6749 338 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
6750 : }
6751 1659 : OMP_CLAUSE_DECL (c) = t;
6752 6039 : return false;
6753 : }
6754 4380 : OMP_CLAUSE_DECL (c) = first;
6755 4380 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
6756 : return false;
6757 4354 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
6758 4354 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
6759 3788 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
6760 3776 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
6761 4330 : OMP_CLAUSE_SIZE (c) = size;
6762 4354 : if (TREE_CODE (t) == FIELD_DECL)
6763 3 : t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6764 :
6765 4354 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6766 : return false;
6767 :
6768 3800 : if (TREE_CODE (first) == INDIRECT_REF)
6769 : {
6770 : /* Detect and skip adding extra nodes for pointer-to-member
6771 : mappings. These are unsupported for now. */
6772 2414 : tree tmp = TREE_OPERAND (first, 0);
6773 :
6774 2414 : if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
6775 1916 : tmp = TREE_OPERAND (tmp, 0);
6776 :
6777 2414 : if (TREE_CODE (tmp) == INDIRECT_REF)
6778 158 : tmp = TREE_OPERAND (tmp, 0);
6779 :
6780 2414 : if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
6781 : {
6782 468 : tree offset = TREE_OPERAND (tmp, 1);
6783 468 : STRIP_NOPS (offset);
6784 468 : if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
6785 : {
6786 36 : sorry_at (OMP_CLAUSE_LOCATION (c),
6787 : "pointer-to-member mapping %qE not supported",
6788 18 : OMP_CLAUSE_DECL (c));
6789 18 : return true;
6790 : }
6791 : }
6792 : }
6793 :
6794 : /* FIRST represents the first item of data that we are mapping.
6795 : E.g. if we're mapping an array, FIRST might resemble
6796 : "foo.bar.myarray[0]". */
6797 :
6798 3782 : auto_vec<omp_addr_token *, 10> addr_tokens;
6799 :
6800 3782 : if (!omp_parse_expr (addr_tokens, first))
6801 : return true;
6802 :
6803 3782 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6804 :
6805 3782 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
6806 3782 : if (nc != error_mark_node)
6807 : {
6808 3782 : using namespace omp_addr_tokenizer;
6809 :
6810 3782 : if (ai.maybe_zero_length_array_section (c))
6811 3758 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
6812 :
6813 : /* !!! If we're accessing a base decl via chained access
6814 : methods (e.g. multiple indirections), duplicate clause
6815 : detection won't work properly. Skip it in that case. */
6816 3782 : if ((addr_tokens[0]->type == STRUCTURE_BASE
6817 2765 : || addr_tokens[0]->type == ARRAY_BASE)
6818 3782 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
6819 3771 : && addr_tokens[1]->type == ACCESS_METHOD
6820 7553 : && omp_access_chain_p (addr_tokens, 1))
6821 218 : c = nc;
6822 :
6823 3782 : return false;
6824 : }
6825 7564 : }
6826 : }
6827 : return false;
6828 9718 : }
6829 :
6830 : /* Return identifier to look up for omp declare reduction. */
6831 :
6832 : tree
6833 7185 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
6834 : {
6835 7185 : const char *p = NULL;
6836 7185 : const char *m = NULL;
6837 7185 : switch (reduction_code)
6838 : {
6839 4236 : case PLUS_EXPR:
6840 4236 : case MULT_EXPR:
6841 4236 : case MINUS_EXPR:
6842 4236 : case BIT_AND_EXPR:
6843 4236 : case BIT_XOR_EXPR:
6844 4236 : case BIT_IOR_EXPR:
6845 4236 : case TRUTH_ANDIF_EXPR:
6846 4236 : case TRUTH_ORIF_EXPR:
6847 4236 : reduction_id = ovl_op_identifier (false, reduction_code);
6848 4236 : break;
6849 : case MIN_EXPR:
6850 : p = "min";
6851 : break;
6852 : case MAX_EXPR:
6853 : p = "max";
6854 : break;
6855 : default:
6856 : break;
6857 : }
6858 :
6859 4236 : if (p == NULL)
6860 : {
6861 7021 : if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
6862 0 : return error_mark_node;
6863 7021 : p = IDENTIFIER_POINTER (reduction_id);
6864 : }
6865 :
6866 7185 : if (type != NULL_TREE)
6867 2083 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6868 :
6869 7185 : const char prefix[] = "omp declare reduction ";
6870 7185 : size_t lenp = sizeof (prefix);
6871 7185 : if (strncmp (p, prefix, lenp - 1) == 0)
6872 2083 : lenp = 1;
6873 7185 : size_t len = strlen (p);
6874 7185 : size_t lenm = m ? strlen (m) + 1 : 0;
6875 7185 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6876 7185 : if (lenp > 1)
6877 5102 : memcpy (name, prefix, lenp - 1);
6878 7185 : memcpy (name + lenp - 1, p, len + 1);
6879 7185 : if (m)
6880 : {
6881 2083 : name[lenp + len - 1] = '~';
6882 2083 : memcpy (name + lenp + len, m, lenm);
6883 : }
6884 7185 : return get_identifier (name);
6885 : }
6886 :
6887 : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
6888 : FUNCTION_DECL or NULL_TREE if not found. */
6889 :
6890 : static tree
6891 1330 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
6892 : vec<tree> *ambiguousp)
6893 : {
6894 1330 : tree orig_id = id;
6895 1330 : tree baselink = NULL_TREE;
6896 1330 : if (identifier_p (id))
6897 : {
6898 1302 : cp_id_kind idk;
6899 1302 : bool nonint_cst_expression_p;
6900 1302 : const char *error_msg;
6901 1302 : id = omp_reduction_id (ERROR_MARK, id, type);
6902 1302 : tree decl = lookup_name (id);
6903 1302 : if (decl == NULL_TREE)
6904 80 : decl = error_mark_node;
6905 1302 : id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
6906 : &nonint_cst_expression_p, false, true, false,
6907 : false, &error_msg, loc);
6908 1302 : if (idk == CP_ID_KIND_UNQUALIFIED
6909 1382 : && identifier_p (id))
6910 : {
6911 80 : vec<tree, va_gc> *args = NULL;
6912 80 : vec_safe_push (args, build_reference_type (type));
6913 80 : id = perform_koenig_lookup (id, args, tf_none);
6914 : }
6915 : }
6916 28 : else if (TREE_CODE (id) == SCOPE_REF)
6917 28 : id = lookup_qualified_name (TREE_OPERAND (id, 0),
6918 : omp_reduction_id (ERROR_MARK,
6919 28 : TREE_OPERAND (id, 1),
6920 : type),
6921 : LOOK_want::NORMAL, false);
6922 1330 : tree fns = id;
6923 1330 : id = NULL_TREE;
6924 1330 : if (fns && is_overloaded_fn (fns))
6925 : {
6926 1256 : for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
6927 : {
6928 1256 : tree fndecl = *iter;
6929 1256 : if (TREE_CODE (fndecl) == FUNCTION_DECL)
6930 : {
6931 1256 : tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
6932 1256 : if (same_type_p (TREE_TYPE (argtype), type))
6933 : {
6934 1256 : id = fndecl;
6935 1256 : break;
6936 : }
6937 : }
6938 : }
6939 :
6940 1256 : if (id && BASELINK_P (fns))
6941 : {
6942 74 : if (baselinkp)
6943 0 : *baselinkp = fns;
6944 : else
6945 74 : baselink = fns;
6946 : }
6947 : }
6948 :
6949 1330 : if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
6950 : {
6951 35 : auto_vec<tree> ambiguous;
6952 35 : tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
6953 35 : unsigned int ix;
6954 35 : if (ambiguousp == NULL)
6955 19 : ambiguousp = &ambiguous;
6956 73 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
6957 : {
6958 62 : id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
6959 : baselinkp ? baselinkp : &baselink,
6960 : ambiguousp);
6961 38 : if (id == NULL_TREE)
6962 14 : continue;
6963 24 : if (!ambiguousp->is_empty ())
6964 3 : ambiguousp->safe_push (id);
6965 21 : else if (ret != NULL_TREE)
6966 : {
6967 6 : ambiguousp->safe_push (ret);
6968 6 : ambiguousp->safe_push (id);
6969 6 : ret = NULL_TREE;
6970 : }
6971 : else
6972 15 : ret = id;
6973 : }
6974 35 : if (ambiguousp != &ambiguous)
6975 16 : return ret;
6976 19 : if (!ambiguous.is_empty ())
6977 : {
6978 6 : auto_diagnostic_group d;
6979 6 : const char *str = _("candidates are:");
6980 6 : unsigned int idx;
6981 6 : tree udr;
6982 6 : error_at (loc, "user defined reduction lookup is ambiguous");
6983 27 : FOR_EACH_VEC_ELT (ambiguous, idx, udr)
6984 : {
6985 15 : inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
6986 15 : if (idx == 0)
6987 6 : str = get_spaces (str);
6988 : }
6989 6 : ret = error_mark_node;
6990 6 : baselink = NULL_TREE;
6991 6 : }
6992 19 : id = ret;
6993 35 : }
6994 1314 : if (id && baselink)
6995 74 : perform_or_defer_access_check (BASELINK_BINFO (baselink),
6996 : id, id, tf_warning_or_error);
6997 : return id;
6998 : }
6999 :
7000 : /* Return identifier to look up for omp declare mapper. */
7001 :
7002 : tree
7003 4124 : omp_mapper_id (tree mapper_id, tree type)
7004 : {
7005 4124 : const char *p = NULL;
7006 4124 : const char *m = NULL;
7007 :
7008 4124 : if (mapper_id == NULL_TREE)
7009 : p = "";
7010 91 : else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
7011 91 : p = IDENTIFIER_POINTER (mapper_id);
7012 : else
7013 0 : return error_mark_node;
7014 :
7015 4124 : if (type != NULL_TREE)
7016 4116 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
7017 :
7018 4124 : const char prefix[] = "omp declare mapper ";
7019 4124 : size_t lenp = sizeof (prefix);
7020 4124 : if (strncmp (p, prefix, lenp - 1) == 0)
7021 8 : lenp = 1;
7022 4124 : size_t len = strlen (p);
7023 4124 : size_t lenm = m ? strlen (m) + 1 : 0;
7024 4124 : char *name = XALLOCAVEC (char, lenp + len + lenm);
7025 4124 : memcpy (name, prefix, lenp - 1);
7026 4124 : memcpy (name + lenp - 1, p, len + 1);
7027 4124 : if (m)
7028 : {
7029 4116 : name[lenp + len - 1] = '~';
7030 4116 : memcpy (name + lenp + len, m, lenm);
7031 : }
7032 4124 : return get_identifier (name);
7033 : }
7034 :
7035 : tree
7036 12127 : cxx_omp_mapper_lookup (tree id, tree type)
7037 : {
7038 12127 : if (!RECORD_OR_UNION_TYPE_P (type))
7039 : return NULL_TREE;
7040 3883 : id = omp_mapper_id (id, type);
7041 3883 : return lookup_name (id);
7042 : }
7043 :
7044 : tree
7045 375 : cxx_omp_extract_mapper_directive (tree vardecl)
7046 : {
7047 375 : gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
7048 :
7049 : /* Instantiate the decl if we haven't already. */
7050 375 : mark_used (vardecl);
7051 375 : tree body = DECL_INITIAL (vardecl);
7052 :
7053 375 : if (TREE_CODE (body) == STATEMENT_LIST)
7054 : {
7055 0 : tree_stmt_iterator tsi = tsi_start (body);
7056 0 : gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
7057 0 : tsi_next (&tsi);
7058 0 : body = tsi_stmt (tsi);
7059 : }
7060 :
7061 375 : gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
7062 :
7063 375 : return body;
7064 : }
7065 :
7066 : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
7067 : nothing more complicated. */
7068 :
7069 : tree
7070 1969 : cxx_omp_map_array_section (location_t loc, tree t)
7071 : {
7072 1969 : tree low = TREE_OPERAND (t, 1);
7073 1969 : tree len = TREE_OPERAND (t, 2);
7074 :
7075 1969 : if (len && integer_onep (len))
7076 : {
7077 327 : t = TREE_OPERAND (t, 0);
7078 :
7079 327 : if (!low)
7080 26 : low = integer_zero_node;
7081 :
7082 327 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
7083 6 : t = convert_from_reference (t);
7084 :
7085 327 : if (TYPE_PTR_P (TREE_TYPE (t))
7086 327 : || TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7087 327 : t = build_array_ref (loc, t, low);
7088 : else
7089 : /* handle_omp_array_sections_1 has already diagnosed the error. */
7090 0 : t = error_mark_node;
7091 : }
7092 :
7093 1969 : return t;
7094 : }
7095 :
7096 : /* Helper function for cp_parser_omp_declare_reduction_exprs
7097 : and tsubst_omp_udr.
7098 : Remove CLEANUP_STMT for data (omp_priv variable).
7099 : Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
7100 : DECL_EXPR. */
7101 :
7102 : tree
7103 4511 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
7104 : {
7105 4511 : if (TYPE_P (*tp))
7106 232 : *walk_subtrees = 0;
7107 4279 : else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
7108 54 : *tp = CLEANUP_BODY (*tp);
7109 4225 : else if (TREE_CODE (*tp) == DECL_EXPR)
7110 : {
7111 312 : tree decl = DECL_EXPR_DECL (*tp);
7112 312 : if (!processing_template_decl
7113 263 : && decl == (tree) data
7114 263 : && DECL_INITIAL (decl)
7115 404 : && DECL_INITIAL (decl) != error_mark_node)
7116 : {
7117 92 : tree list = NULL_TREE;
7118 92 : append_to_statement_list_force (*tp, &list);
7119 92 : tree init_expr = build2 (INIT_EXPR, void_type_node,
7120 92 : decl, DECL_INITIAL (decl));
7121 92 : DECL_INITIAL (decl) = NULL_TREE;
7122 92 : append_to_statement_list_force (init_expr, &list);
7123 92 : *tp = list;
7124 : }
7125 : }
7126 4511 : return NULL_TREE;
7127 : }
7128 :
7129 : /* Data passed from cp_check_omp_declare_reduction to
7130 : cp_check_omp_declare_reduction_r. */
7131 :
7132 : struct cp_check_omp_declare_reduction_data
7133 : {
7134 : location_t loc;
7135 : tree stmts[7];
7136 : bool combiner_p;
7137 : };
7138 :
7139 : /* Helper function for cp_check_omp_declare_reduction, called via
7140 : cp_walk_tree. */
7141 :
7142 : static tree
7143 15162 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
7144 : {
7145 15162 : struct cp_check_omp_declare_reduction_data *udr_data
7146 : = (struct cp_check_omp_declare_reduction_data *) data;
7147 15162 : if (SSA_VAR_P (*tp)
7148 2720 : && !DECL_ARTIFICIAL (*tp)
7149 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
7150 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
7151 : {
7152 135 : location_t loc = udr_data->loc;
7153 135 : if (udr_data->combiner_p)
7154 45 : error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
7155 : "variable %qD which is not %<omp_out%> nor %<omp_in%>",
7156 : *tp);
7157 : else
7158 90 : error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
7159 : "to variable %qD which is not %<omp_priv%> nor "
7160 : "%<omp_orig%>",
7161 : *tp);
7162 135 : return *tp;
7163 : }
7164 : return NULL_TREE;
7165 : }
7166 :
7167 : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
7168 :
7169 : bool
7170 1108 : cp_check_omp_declare_reduction (tree udr)
7171 : {
7172 1108 : tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
7173 1108 : gcc_assert (TYPE_REF_P (type));
7174 1108 : type = TREE_TYPE (type);
7175 1108 : int i;
7176 1108 : location_t loc = DECL_SOURCE_LOCATION (udr);
7177 :
7178 1108 : if (type == error_mark_node)
7179 : return false;
7180 1108 : if (ARITHMETIC_TYPE_P (type))
7181 : {
7182 : static enum tree_code predef_codes[]
7183 : = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
7184 : BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
7185 3276 : for (i = 0; i < 8; i++)
7186 : {
7187 2918 : tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
7188 2918 : const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
7189 2918 : const char *n2 = IDENTIFIER_POINTER (id);
7190 2918 : if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
7191 2918 : && (n1[IDENTIFIER_LENGTH (id)] == '~'
7192 0 : || n1[IDENTIFIER_LENGTH (id)] == '\0'))
7193 : break;
7194 : }
7195 :
7196 376 : if (i == 8
7197 358 : && TREE_CODE (type) != COMPLEX_EXPR)
7198 : {
7199 358 : const char prefix_minmax[] = "omp declare reduction m";
7200 358 : size_t prefix_size = sizeof (prefix_minmax) - 1;
7201 358 : const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
7202 358 : if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
7203 : prefix_minmax, prefix_size) == 0
7204 10 : && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
7205 4 : || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
7206 368 : && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
7207 6 : i = 0;
7208 : }
7209 376 : if (i < 8)
7210 : {
7211 24 : error_at (loc, "predeclared arithmetic type %qT in "
7212 : "%<#pragma omp declare reduction%>", type);
7213 24 : return false;
7214 : }
7215 : }
7216 : else if (FUNC_OR_METHOD_TYPE_P (type)
7217 : || TREE_CODE (type) == ARRAY_TYPE)
7218 : {
7219 24 : error_at (loc, "function or array type %qT in "
7220 : "%<#pragma omp declare reduction%>", type);
7221 24 : return false;
7222 : }
7223 : else if (TYPE_REF_P (type))
7224 : {
7225 0 : error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
7226 : type);
7227 0 : return false;
7228 : }
7229 708 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
7230 : {
7231 24 : error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
7232 : "type %qT in %<#pragma omp declare reduction%>", type);
7233 24 : return false;
7234 : }
7235 :
7236 1036 : tree body = DECL_SAVED_TREE (udr);
7237 1036 : if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
7238 : return true;
7239 :
7240 850 : tree_stmt_iterator tsi;
7241 850 : struct cp_check_omp_declare_reduction_data data;
7242 850 : memset (data.stmts, 0, sizeof data.stmts);
7243 850 : for (i = 0, tsi = tsi_start (body);
7244 4737 : i < 7 && !tsi_end_p (tsi);
7245 3887 : i++, tsi_next (&tsi))
7246 3887 : data.stmts[i] = tsi_stmt (tsi);
7247 850 : data.loc = loc;
7248 850 : gcc_assert (tsi_end_p (tsi));
7249 850 : if (i >= 3)
7250 : {
7251 850 : gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
7252 : && TREE_CODE (data.stmts[1]) == DECL_EXPR);
7253 850 : if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
7254 : return true;
7255 805 : data.combiner_p = true;
7256 805 : if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
7257 : &data, NULL))
7258 45 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
7259 : }
7260 805 : if (i >= 6)
7261 : {
7262 343 : gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
7263 : && TREE_CODE (data.stmts[4]) == DECL_EXPR);
7264 343 : data.combiner_p = false;
7265 343 : if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
7266 : &data, NULL)
7267 343 : || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
7268 : cp_check_omp_declare_reduction_r, &data, NULL))
7269 90 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */);
7270 343 : if (i == 7)
7271 203 : gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
7272 : }
7273 : return true;
7274 : }
7275 :
7276 : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
7277 : an inline call. But, remap
7278 : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
7279 : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
7280 :
7281 : static tree
7282 2281 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
7283 : tree decl, tree placeholder)
7284 : {
7285 2281 : copy_body_data id;
7286 2281 : hash_map<tree, tree> decl_map;
7287 :
7288 2281 : decl_map.put (omp_decl1, placeholder);
7289 2281 : decl_map.put (omp_decl2, decl);
7290 2281 : memset (&id, 0, sizeof (id));
7291 2281 : id.src_fn = DECL_CONTEXT (omp_decl1);
7292 2281 : id.dst_fn = current_function_decl;
7293 2281 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
7294 2281 : id.decl_map = &decl_map;
7295 :
7296 2281 : id.copy_decl = copy_decl_no_change;
7297 2281 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
7298 2281 : id.transform_new_cfg = true;
7299 2281 : id.transform_return_to_modify = false;
7300 2281 : id.eh_lp_nr = 0;
7301 2281 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
7302 2281 : return stmt;
7303 2281 : }
7304 :
7305 : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
7306 : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
7307 :
7308 : static tree
7309 16021 : find_omp_placeholder_r (tree *tp, int *, void *data)
7310 : {
7311 16021 : if (*tp == (tree) data)
7312 290 : return *tp;
7313 : return NULL_TREE;
7314 : }
7315 :
7316 : /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
7317 : Return true if there is some error and the clause should be removed. */
7318 :
7319 : static bool
7320 9051 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
7321 : {
7322 9051 : tree t = OMP_CLAUSE_DECL (c);
7323 9051 : bool predefined = false;
7324 9051 : if (TREE_CODE (t) == TREE_LIST)
7325 : {
7326 0 : gcc_assert (processing_template_decl);
7327 : return false;
7328 : }
7329 9051 : tree type = TREE_TYPE (t);
7330 9051 : if (TREE_CODE (t) == MEM_REF)
7331 1656 : type = TREE_TYPE (type);
7332 9051 : if (TYPE_REF_P (type))
7333 589 : type = TREE_TYPE (type);
7334 9051 : if (TREE_CODE (type) == ARRAY_TYPE)
7335 : {
7336 377 : tree oatype = type;
7337 377 : gcc_assert (TREE_CODE (t) != MEM_REF);
7338 757 : while (TREE_CODE (type) == ARRAY_TYPE)
7339 380 : type = TREE_TYPE (type);
7340 377 : if (!processing_template_decl)
7341 : {
7342 270 : t = require_complete_type (t);
7343 270 : if (t == error_mark_node
7344 270 : || !complete_type_or_else (oatype, NULL_TREE))
7345 : return true;
7346 261 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
7347 : TYPE_SIZE_UNIT (type));
7348 261 : if (integer_zerop (size))
7349 : {
7350 6 : error_at (OMP_CLAUSE_LOCATION (c),
7351 : "%qE in %<reduction%> clause is a zero size array",
7352 : omp_clause_printable_decl (t));
7353 3 : return true;
7354 : }
7355 258 : size = size_binop (MINUS_EXPR, size, size_one_node);
7356 258 : size = save_expr (size);
7357 258 : tree index_type = build_index_type (size);
7358 258 : tree atype = build_array_type (type, index_type);
7359 258 : tree ptype = build_pointer_type (type);
7360 258 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7361 152 : t = build_fold_addr_expr (t);
7362 258 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
7363 258 : OMP_CLAUSE_DECL (c) = t;
7364 : }
7365 : }
7366 9039 : if (type == error_mark_node)
7367 : return true;
7368 9036 : else if (ARITHMETIC_TYPE_P (type))
7369 7735 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
7370 : {
7371 : case PLUS_EXPR:
7372 : case MULT_EXPR:
7373 : case MINUS_EXPR:
7374 : case TRUTH_ANDIF_EXPR:
7375 : case TRUTH_ORIF_EXPR:
7376 : predefined = true;
7377 : break;
7378 246 : case MIN_EXPR:
7379 246 : case MAX_EXPR:
7380 246 : if (TREE_CODE (type) == COMPLEX_TYPE)
7381 : break;
7382 : predefined = true;
7383 : break;
7384 111 : case BIT_AND_EXPR:
7385 111 : case BIT_IOR_EXPR:
7386 111 : case BIT_XOR_EXPR:
7387 111 : if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
7388 : break;
7389 : predefined = true;
7390 : break;
7391 : default:
7392 : break;
7393 : }
7394 1301 : else if (TYPE_READONLY (type))
7395 : {
7396 18 : error_at (OMP_CLAUSE_LOCATION (c),
7397 : "%qE has const type for %<reduction%>",
7398 : omp_clause_printable_decl (t));
7399 9 : return true;
7400 : }
7401 1292 : else if (!processing_template_decl)
7402 : {
7403 1079 : t = require_complete_type (t);
7404 1079 : if (t == error_mark_node)
7405 : return true;
7406 1079 : OMP_CLAUSE_DECL (c) = t;
7407 : }
7408 :
7409 1079 : if (predefined)
7410 : {
7411 7513 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7412 7513 : return false;
7413 : }
7414 1514 : else if (processing_template_decl)
7415 : {
7416 222 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
7417 : return true;
7418 219 : return false;
7419 : }
7420 :
7421 1292 : tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7422 :
7423 1292 : type = TYPE_MAIN_VARIANT (type);
7424 1292 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7425 1292 : if (id == NULL_TREE)
7426 965 : id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
7427 : NULL_TREE, NULL_TREE);
7428 1292 : id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
7429 1292 : if (id)
7430 : {
7431 1247 : if (id == error_mark_node)
7432 : return true;
7433 1241 : mark_used (id);
7434 1241 : tree body = DECL_SAVED_TREE (id);
7435 1241 : if (!body)
7436 : return true;
7437 1238 : if (TREE_CODE (body) == STATEMENT_LIST)
7438 : {
7439 1238 : tree_stmt_iterator tsi;
7440 1238 : tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
7441 1238 : int i;
7442 1238 : tree stmts[7];
7443 1238 : tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
7444 1238 : atype = TREE_TYPE (atype);
7445 1238 : bool need_static_cast = !same_type_p (type, atype);
7446 1238 : memset (stmts, 0, sizeof stmts);
7447 1238 : for (i = 0, tsi = tsi_start (body);
7448 8834 : i < 7 && !tsi_end_p (tsi);
7449 7596 : i++, tsi_next (&tsi))
7450 7596 : stmts[i] = tsi_stmt (tsi);
7451 1238 : gcc_assert (tsi_end_p (tsi));
7452 :
7453 1238 : if (i >= 3)
7454 : {
7455 1238 : gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
7456 : && TREE_CODE (stmts[1]) == DECL_EXPR);
7457 1238 : placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
7458 1238 : DECL_ARTIFICIAL (placeholder) = 1;
7459 1238 : DECL_IGNORED_P (placeholder) = 1;
7460 1238 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
7461 1238 : if (TREE_CODE (t) == MEM_REF)
7462 : {
7463 600 : decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
7464 : type);
7465 600 : DECL_ARTIFICIAL (decl_placeholder) = 1;
7466 600 : DECL_IGNORED_P (decl_placeholder) = 1;
7467 600 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
7468 : }
7469 1238 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
7470 310 : cxx_mark_addressable (placeholder);
7471 1238 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
7472 1238 : && (decl_placeholder
7473 174 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7474 390 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7475 127 : : OMP_CLAUSE_DECL (c));
7476 1238 : tree omp_out = placeholder;
7477 1238 : tree omp_in = decl_placeholder ? decl_placeholder
7478 638 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7479 1238 : if (need_static_cast)
7480 : {
7481 7 : tree rtype = build_reference_type (atype);
7482 7 : omp_out = build_static_cast (input_location,
7483 : rtype, omp_out,
7484 : tf_warning_or_error);
7485 7 : omp_in = build_static_cast (input_location,
7486 : rtype, omp_in,
7487 : tf_warning_or_error);
7488 7 : if (omp_out == error_mark_node || omp_in == error_mark_node)
7489 3 : return true;
7490 7 : omp_out = convert_from_reference (omp_out);
7491 7 : omp_in = convert_from_reference (omp_in);
7492 : }
7493 1238 : OMP_CLAUSE_REDUCTION_MERGE (c)
7494 1238 : = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
7495 1238 : DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
7496 : }
7497 1238 : if (i >= 6)
7498 : {
7499 1046 : gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
7500 : && TREE_CODE (stmts[4]) == DECL_EXPR);
7501 1046 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
7502 1046 : && (decl_placeholder
7503 264 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7504 844 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7505 170 : : OMP_CLAUSE_DECL (c));
7506 1046 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
7507 241 : cxx_mark_addressable (placeholder);
7508 1046 : tree omp_priv = decl_placeholder ? decl_placeholder
7509 470 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7510 1046 : tree omp_orig = placeholder;
7511 1046 : if (need_static_cast)
7512 : {
7513 5 : if (i == 7)
7514 : {
7515 3 : error_at (OMP_CLAUSE_LOCATION (c),
7516 : "user defined reduction with constructor "
7517 : "initializer for base class %qT", atype);
7518 3 : return true;
7519 : }
7520 2 : tree rtype = build_reference_type (atype);
7521 2 : omp_priv = build_static_cast (input_location,
7522 : rtype, omp_priv,
7523 : tf_warning_or_error);
7524 2 : omp_orig = build_static_cast (input_location,
7525 : rtype, omp_orig,
7526 : tf_warning_or_error);
7527 2 : if (omp_priv == error_mark_node
7528 2 : || omp_orig == error_mark_node)
7529 : return true;
7530 2 : omp_priv = convert_from_reference (omp_priv);
7531 2 : omp_orig = convert_from_reference (omp_orig);
7532 : }
7533 1043 : if (i == 6)
7534 302 : *need_default_ctor = true;
7535 1043 : OMP_CLAUSE_REDUCTION_INIT (c)
7536 1043 : = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
7537 1043 : DECL_EXPR_DECL (stmts[3]),
7538 : omp_priv, omp_orig);
7539 1043 : if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
7540 : find_omp_placeholder_r, placeholder, NULL))
7541 263 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
7542 : }
7543 192 : else if (i >= 3)
7544 : {
7545 192 : if (CLASS_TYPE_P (type) && !pod_type_p (type))
7546 175 : *need_default_ctor = true;
7547 : else
7548 : {
7549 17 : tree init;
7550 17 : tree v = decl_placeholder ? decl_placeholder
7551 17 : : convert_from_reference (t);
7552 17 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
7553 8 : init = build_constructor (TREE_TYPE (v), NULL);
7554 : else
7555 9 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
7556 34 : OMP_CLAUSE_REDUCTION_INIT (c)
7557 34 : = cp_build_init_expr (v, init);
7558 : }
7559 : }
7560 : }
7561 : }
7562 1280 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7563 1235 : *need_dtor = true;
7564 : else
7565 : {
7566 90 : error_at (OMP_CLAUSE_LOCATION (c),
7567 : "user defined reduction not found for %qE",
7568 : omp_clause_printable_decl (t));
7569 45 : return true;
7570 : }
7571 1235 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7572 600 : gcc_assert (TYPE_SIZE_UNIT (type)
7573 : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
7574 : return false;
7575 : }
7576 :
7577 : /* Check an instance of an "omp declare mapper" function. */
7578 :
7579 : bool
7580 208 : cp_check_omp_declare_mapper (tree udm)
7581 : {
7582 208 : tree var = OMP_DECLARE_MAPPER_DECL (udm);
7583 208 : tree type = TREE_TYPE (var);
7584 208 : location_t loc = DECL_SOURCE_LOCATION (var);
7585 :
7586 208 : if (type == error_mark_node)
7587 : return false;
7588 :
7589 208 : if (processing_template_decl)
7590 : return true;
7591 :
7592 197 : if (!RECORD_OR_UNION_TYPE_P (type))
7593 : {
7594 17 : error_at (loc, "%qT is not a struct, union or class type in "
7595 : "%<#pragma omp declare mapper%>", type);
7596 17 : return false;
7597 : }
7598 180 : if (CLASSTYPE_VBASECLASSES (type))
7599 : {
7600 3 : error_at (loc, "%qT must not be a virtual base class in "
7601 : "%<#pragma omp declare mapper%>", type);
7602 3 : return false;
7603 : }
7604 :
7605 177 : tree c = OMP_DECLARE_MAPPER_CLAUSES (udm);
7606 215 : for ( ; c; c = OMP_CLAUSE_CHAIN (c))
7607 : {
7608 187 : tree dvar = OMP_CLAUSE_DECL (c);
7609 400 : while (!DECL_P (dvar) && TREE_OPERAND_LENGTH (dvar))
7610 213 : dvar = TREE_OPERAND (dvar, 0);
7611 187 : if (dvar == var)
7612 : break;
7613 : }
7614 177 : if (!c)
7615 : {
7616 : // After template handling, the var is mangled, demangle it
7617 28 : const char *name = IDENTIFIER_POINTER (DECL_NAME (var));
7618 28 : char *n = NULL;
7619 28 : if (startswith (name, "omp declare mapper "))
7620 : {
7621 3 : name += strlen ("omp declare mapper ");
7622 3 : n = xstrdup (name);
7623 3 : n[strchr (n, '~')-n] = '\0';
7624 3 : name = n;
7625 : }
7626 28 : error_at (loc, "at least one %<map%> clause must map %qs or an "
7627 : "element of it", name);
7628 28 : if (n)
7629 3 : free (n);
7630 : return false;
7631 : }
7632 :
7633 : /* FIXME: The vardecl created for the mapper_id uses DECL_DECLARED_CONSTEXPR_P
7634 : = 1, which is set to false in finalize_literal_type_property for C++ < 11,
7635 : leading to an error in ensure_literal_type_for_constexpr_object.
7636 : Examples (compile with -std=c++98): gcc.dg/gomp/declare-mapper-13.c and
7637 : libgomp.c++/declare-mapper-{5,6,8}.C. */
7638 149 : if (cxx_dialect < cxx11)
7639 : {
7640 0 : sorry_at (loc, "%<#pragma omp declare mapper%> with %<-std=%> set to "
7641 : "before C++11");
7642 0 : return false;
7643 : }
7644 :
7645 : return true;
7646 : }
7647 :
7648 : /* Called from finish_struct_1. linear(this) or linear(this:step)
7649 : clauses might not be finalized yet because the class has been incomplete
7650 : when parsing #pragma omp declare simd methods. Fix those up now. */
7651 :
7652 : void
7653 120201 : finish_omp_declare_simd_methods (tree t)
7654 : {
7655 120201 : if (processing_template_decl)
7656 : return;
7657 :
7658 817085 : for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
7659 : {
7660 1153736 : if (TREE_CODE (x) == USING_DECL
7661 696884 : || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
7662 456852 : continue;
7663 240032 : tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
7664 240140 : if (!ods || !TREE_VALUE (ods))
7665 239924 : continue;
7666 366 : for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
7667 258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7668 66 : && integer_zerop (OMP_CLAUSE_DECL (c))
7669 18 : && OMP_CLAUSE_LINEAR_STEP (c)
7670 276 : && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
7671 : {
7672 18 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
7673 18 : s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
7674 18 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
7675 18 : sizetype, s, TYPE_SIZE_UNIT (t));
7676 18 : OMP_CLAUSE_LINEAR_STEP (c) = s;
7677 : }
7678 : }
7679 : }
7680 :
7681 : /* Adjust sink depend/doacross clause to take into account pointer offsets.
7682 :
7683 : Return TRUE if there was a problem processing the offset, and the
7684 : whole clause should be removed. */
7685 :
7686 : static bool
7687 298 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
7688 : {
7689 298 : tree t = OMP_CLAUSE_DECL (sink_clause);
7690 298 : gcc_assert (TREE_CODE (t) == TREE_LIST);
7691 :
7692 : /* Make sure we don't adjust things twice for templates. */
7693 298 : if (processing_template_decl)
7694 : return false;
7695 :
7696 671 : for (; t; t = TREE_CHAIN (t))
7697 : {
7698 391 : tree decl = TREE_VALUE (t);
7699 391 : if (TYPE_PTR_P (TREE_TYPE (decl)))
7700 : {
7701 6 : tree offset = TREE_PURPOSE (t);
7702 6 : bool neg = wi::neg_p (wi::to_wide (offset));
7703 6 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
7704 6 : decl = mark_rvalue_use (decl);
7705 6 : decl = convert_from_reference (decl);
7706 12 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
7707 : neg ? MINUS_EXPR : PLUS_EXPR,
7708 : decl, offset);
7709 6 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
7710 : MINUS_EXPR, sizetype,
7711 : fold_convert (sizetype, t2),
7712 : fold_convert (sizetype, decl));
7713 6 : if (t2 == error_mark_node)
7714 : return true;
7715 6 : TREE_PURPOSE (t) = t2;
7716 : }
7717 : }
7718 : return false;
7719 : }
7720 :
7721 : /* Finish OpenMP iterators ITER. Return true if they are erroneous
7722 : and clauses containing them should be removed. */
7723 :
7724 : static bool
7725 624 : cp_omp_finish_iterators (tree iter)
7726 : {
7727 624 : bool ret = false;
7728 1413 : for (tree it = iter; it; it = TREE_CHAIN (it))
7729 : {
7730 789 : tree var = OMP_ITERATOR_VAR (it);
7731 789 : tree begin = OMP_ITERATOR_BEGIN (it);
7732 789 : tree end = OMP_ITERATOR_END (it);
7733 789 : tree step = OMP_ITERATOR_STEP (it);
7734 789 : tree orig_step;
7735 789 : tree type = TREE_TYPE (var);
7736 789 : location_t loc = DECL_SOURCE_LOCATION (var);
7737 789 : if (type == error_mark_node)
7738 : {
7739 0 : ret = true;
7740 218 : continue;
7741 : }
7742 789 : if (type_dependent_expression_p (var))
7743 59 : continue;
7744 730 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
7745 : {
7746 27 : error_at (loc, "iterator %qD has neither integral nor pointer type",
7747 : var);
7748 27 : ret = true;
7749 27 : continue;
7750 : }
7751 703 : else if (TYPE_READONLY (type))
7752 : {
7753 24 : error_at (loc, "iterator %qD has const qualified type", var);
7754 24 : ret = true;
7755 24 : continue;
7756 : }
7757 679 : if (type_dependent_expression_p (begin)
7758 670 : || type_dependent_expression_p (end)
7759 1349 : || type_dependent_expression_p (step))
7760 15 : continue;
7761 664 : else if (error_operand_p (step))
7762 : {
7763 0 : ret = true;
7764 0 : continue;
7765 : }
7766 664 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
7767 : {
7768 21 : error_at (EXPR_LOC_OR_LOC (step, loc),
7769 : "iterator step with non-integral type");
7770 21 : ret = true;
7771 21 : continue;
7772 : }
7773 :
7774 643 : begin = mark_rvalue_use (begin);
7775 643 : end = mark_rvalue_use (end);
7776 643 : step = mark_rvalue_use (step);
7777 643 : begin = cp_build_c_cast (input_location, type, begin,
7778 : tf_warning_or_error);
7779 643 : end = cp_build_c_cast (input_location, type, end,
7780 : tf_warning_or_error);
7781 643 : orig_step = step;
7782 643 : if (!processing_template_decl)
7783 566 : step = orig_step = save_expr (step);
7784 643 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
7785 643 : step = cp_build_c_cast (input_location, stype, step,
7786 : tf_warning_or_error);
7787 643 : if (POINTER_TYPE_P (type) && !processing_template_decl)
7788 : {
7789 66 : begin = save_expr (begin);
7790 66 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
7791 66 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
7792 : fold_convert (sizetype, step),
7793 : fold_convert (sizetype, begin));
7794 66 : step = fold_convert (ssizetype, step);
7795 : }
7796 643 : if (!processing_template_decl)
7797 : {
7798 566 : begin = maybe_constant_value (begin);
7799 566 : end = maybe_constant_value (end);
7800 566 : step = maybe_constant_value (step);
7801 566 : orig_step = maybe_constant_value (orig_step);
7802 : }
7803 643 : if (integer_zerop (step))
7804 : {
7805 27 : error_at (loc, "iterator %qD has zero step", var);
7806 27 : ret = true;
7807 27 : continue;
7808 : }
7809 :
7810 616 : if (begin == error_mark_node
7811 607 : || end == error_mark_node
7812 598 : || step == error_mark_node
7813 598 : || orig_step == error_mark_node)
7814 : {
7815 18 : ret = true;
7816 18 : continue;
7817 : }
7818 :
7819 598 : if (!processing_template_decl)
7820 : {
7821 521 : begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
7822 521 : end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
7823 521 : step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
7824 521 : orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
7825 : orig_step);
7826 : }
7827 598 : hash_set<tree> pset;
7828 598 : tree it2;
7829 754 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
7830 : {
7831 183 : tree var2 = OMP_ITERATOR_VAR (it2);
7832 183 : tree begin2 = OMP_ITERATOR_BEGIN (it2);
7833 183 : tree end2 = OMP_ITERATOR_END (it2);
7834 183 : tree step2 = OMP_ITERATOR_STEP (it2);
7835 183 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
7836 183 : if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
7837 : {
7838 9 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
7839 : "begin expression refers to outer iterator %qD", var);
7840 36 : break;
7841 : }
7842 174 : else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
7843 : {
7844 9 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
7845 : "end expression refers to outer iterator %qD", var);
7846 9 : break;
7847 : }
7848 165 : else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
7849 : {
7850 9 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
7851 : "step expression refers to outer iterator %qD", var);
7852 9 : break;
7853 : }
7854 : }
7855 598 : if (it2)
7856 : {
7857 27 : ret = true;
7858 27 : continue;
7859 : }
7860 571 : OMP_ITERATOR_BEGIN (it) = begin;
7861 571 : OMP_ITERATOR_END (it) = end;
7862 571 : if (processing_template_decl)
7863 71 : OMP_ITERATOR_STEP (it) = orig_step;
7864 : else
7865 : {
7866 500 : OMP_ITERATOR_STEP (it) = step;
7867 500 : OMP_ITERATOR_ORIG_STEP (it) = orig_step;
7868 : }
7869 598 : }
7870 624 : return ret;
7871 : }
7872 :
7873 : /* Ensure that pointers are used in OpenACC attach and detach clauses.
7874 : Return true if an error has been detected. */
7875 :
7876 : static bool
7877 18854 : cp_oacc_check_attachments (tree c)
7878 : {
7879 18854 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
7880 : return false;
7881 :
7882 : /* OpenACC attach / detach clauses must be pointers. */
7883 14819 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
7884 14819 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
7885 : {
7886 196 : tree t = OMP_CLAUSE_DECL (c);
7887 196 : tree type;
7888 :
7889 232 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7890 36 : t = TREE_OPERAND (t, 0);
7891 :
7892 196 : type = TREE_TYPE (t);
7893 :
7894 196 : if (TREE_CODE (type) == REFERENCE_TYPE)
7895 36 : type = TREE_TYPE (type);
7896 :
7897 196 : if (TREE_CODE (type) != POINTER_TYPE)
7898 : {
7899 36 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
7900 : user_omp_clause_code_name (c, true));
7901 36 : return true;
7902 : }
7903 : }
7904 :
7905 : return false;
7906 : }
7907 :
7908 : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
7909 : happened. */
7910 :
7911 : tree
7912 813 : cp_finish_omp_init_prefer_type (tree pref_type)
7913 : {
7914 813 : if (processing_template_decl
7915 741 : || pref_type == NULL_TREE
7916 356 : || TREE_CODE (pref_type) != TREE_LIST)
7917 : return pref_type;
7918 :
7919 81 : tree t = TREE_PURPOSE (pref_type);
7920 81 : char *str = const_cast<char *> (TREE_STRING_POINTER (t));
7921 81 : tree fr_list = TREE_VALUE (pref_type);
7922 81 : int len = TREE_VEC_LENGTH (fr_list);
7923 81 : int cnt = 0;
7924 :
7925 270 : while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
7926 : {
7927 270 : str++;
7928 270 : if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
7929 : {
7930 : /* Assume a no or a single 'fr'. */
7931 150 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7932 150 : location_t loc = UNKNOWN_LOCATION;
7933 150 : tree value = TREE_VEC_ELT (fr_list, cnt);
7934 150 : if (value != NULL_TREE && value != error_mark_node)
7935 : {
7936 126 : loc = EXPR_LOCATION (value);
7937 126 : if (value && TREE_CODE (value) == NOP_EXPR)
7938 39 : value = TREE_OPERAND (value, 0);
7939 126 : value = cp_fully_fold (value);
7940 : }
7941 126 : if (value != NULL_TREE && value != error_mark_node)
7942 : {
7943 126 : if (TREE_CODE (value) != INTEGER_CST
7944 126 : || !tree_fits_shwi_p (value))
7945 0 : error_at (loc,
7946 : "expected string literal or "
7947 : "constant integer expression instead of %qE", value);
7948 : else
7949 : {
7950 126 : HOST_WIDE_INT n = tree_to_shwi (value);
7951 126 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
7952 : {
7953 48 : warning_at (loc, OPT_Wopenmp,
7954 : "unknown foreign runtime identifier %qwd", n);
7955 48 : n = GOMP_INTEROP_IFR_UNKNOWN;
7956 : }
7957 126 : str[0] = (char) n;
7958 : }
7959 : }
7960 150 : str++;
7961 : }
7962 120 : else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
7963 : {
7964 : /* Assume a no or a single 'fr'. */
7965 120 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7966 120 : str++;
7967 : }
7968 270 : str++;
7969 294 : while (str[0] != '\0')
7970 24 : str += strlen (str) + 1;
7971 270 : str++;
7972 270 : cnt++;
7973 270 : if (cnt >= len)
7974 : break;
7975 : }
7976 : return t;
7977 : }
7978 :
7979 : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
7980 : Remove any elements from the list that are invalid. */
7981 :
7982 : tree
7983 63702 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
7984 : {
7985 63702 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
7986 63702 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
7987 63702 : bitmap_head oacc_reduction_head, is_on_device_head;
7988 63702 : tree c, t, *pc;
7989 63702 : tree safelen = NULL_TREE;
7990 63702 : bool openacc = (ort & C_ORT_ACC) != 0;
7991 63702 : bool branch_seen = false;
7992 63702 : bool copyprivate_seen = false;
7993 63702 : bool ordered_seen = false;
7994 63702 : bool order_seen = false;
7995 63702 : bool schedule_seen = false;
7996 63702 : bool oacc_async = false;
7997 63702 : bool indir_component_ref_p = false;
7998 63702 : tree last_iterators = NULL_TREE;
7999 63702 : bool last_iterators_remove = false;
8000 : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
8001 : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
8002 63702 : int reduction_seen = 0;
8003 63702 : bool allocate_seen = false;
8004 63702 : tree detach_seen = NULL_TREE;
8005 63702 : bool mergeable_seen = false;
8006 63702 : bool implicit_moved = false;
8007 63702 : bool target_in_reduction_seen = false;
8008 63702 : bool num_tasks_seen = false;
8009 63702 : bool partial_seen = false;
8010 63702 : bool init_seen = false;
8011 63702 : bool init_use_destroy_seen = false;
8012 63702 : tree init_no_targetsync_clause = NULL_TREE;
8013 63702 : tree depend_clause = NULL_TREE;
8014 :
8015 63702 : if (!openacc)
8016 50882 : clauses = omp_remove_duplicate_maps (clauses, true);
8017 :
8018 63702 : bitmap_obstack_initialize (NULL);
8019 63702 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
8020 63702 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
8021 63702 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
8022 63702 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
8023 : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
8024 63702 : bitmap_initialize (&map_head, &bitmap_default_obstack);
8025 63702 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
8026 63702 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
8027 : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
8028 : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
8029 63702 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
8030 63702 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
8031 :
8032 63702 : if (openacc)
8033 28438 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
8034 16006 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
8035 : {
8036 : oacc_async = true;
8037 : break;
8038 : }
8039 :
8040 63702 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
8041 :
8042 162886 : for (pc = &clauses, c = clauses; c ; c = *pc)
8043 : {
8044 99184 : bool remove = false;
8045 99184 : bool field_ok = false;
8046 :
8047 : /* We've reached the end of a list of expanded nodes. Reset the group
8048 : start pointer. */
8049 99184 : if (c == grp_sentinel)
8050 : {
8051 5713 : if (grp_start_p
8052 5713 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
8053 96 : for (tree gc = *grp_start_p; gc != grp_sentinel;
8054 66 : gc = OMP_CLAUSE_CHAIN (gc))
8055 66 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
8056 : grp_start_p = NULL;
8057 : }
8058 :
8059 99184 : switch (OMP_CLAUSE_CODE (c))
8060 : {
8061 2100 : case OMP_CLAUSE_SHARED:
8062 2100 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8063 2100 : goto check_dup_generic;
8064 2584 : case OMP_CLAUSE_PRIVATE:
8065 2584 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8066 2584 : goto check_dup_generic;
8067 7557 : case OMP_CLAUSE_REDUCTION:
8068 7557 : if (reduction_seen == 0)
8069 6432 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
8070 1125 : else if (reduction_seen != -2
8071 2250 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
8072 1125 : ? -1 : 1))
8073 : {
8074 6 : error_at (OMP_CLAUSE_LOCATION (c),
8075 : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
8076 : "on the same construct");
8077 6 : reduction_seen = -2;
8078 : }
8079 : /* FALLTHRU */
8080 9726 : case OMP_CLAUSE_IN_REDUCTION:
8081 9726 : case OMP_CLAUSE_TASK_REDUCTION:
8082 9726 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8083 9726 : t = OMP_CLAUSE_DECL (c);
8084 9726 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
8085 : {
8086 2315 : if (handle_omp_array_sections (c, ort))
8087 : {
8088 : remove = true;
8089 : break;
8090 : }
8091 2273 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
8092 2273 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
8093 : {
8094 3 : error_at (OMP_CLAUSE_LOCATION (c),
8095 : "%<inscan%> %<reduction%> clause with array "
8096 : "section");
8097 3 : remove = true;
8098 3 : break;
8099 : }
8100 2270 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
8101 : {
8102 4888 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
8103 2618 : t = TREE_OPERAND (t, 0);
8104 : }
8105 : else
8106 : {
8107 0 : gcc_assert (TREE_CODE (t) == MEM_REF);
8108 0 : t = TREE_OPERAND (t, 0);
8109 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
8110 0 : t = TREE_OPERAND (t, 0);
8111 0 : if (TREE_CODE (t) == ADDR_EXPR
8112 0 : || INDIRECT_REF_P (t))
8113 0 : t = TREE_OPERAND (t, 0);
8114 : }
8115 2270 : tree n = omp_clause_decl_field (t);
8116 2270 : if (n)
8117 59 : t = n;
8118 2270 : goto check_dup_generic_t;
8119 : }
8120 7411 : if (oacc_async)
8121 7 : cxx_mark_addressable (t);
8122 7411 : goto check_dup_generic;
8123 98 : case OMP_CLAUSE_COPYPRIVATE:
8124 98 : copyprivate_seen = true;
8125 98 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8126 98 : goto check_dup_generic;
8127 280 : case OMP_CLAUSE_COPYIN:
8128 280 : goto check_dup_generic;
8129 1631 : case OMP_CLAUSE_LINEAR:
8130 1631 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
8131 1631 : t = OMP_CLAUSE_DECL (c);
8132 1631 : if (ort != C_ORT_OMP_DECLARE_SIMD
8133 1631 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
8134 : {
8135 84 : if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
8136 : {
8137 42 : error_at (OMP_CLAUSE_LOCATION (c),
8138 : "modifier should not be specified in %<linear%> "
8139 : "clause on %<simd%> or %<for%> constructs when "
8140 : "not using OpenMP 5.2 modifiers");
8141 42 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
8142 : }
8143 42 : else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
8144 : {
8145 18 : error_at (OMP_CLAUSE_LOCATION (c),
8146 : "modifier other than %<val%> specified in "
8147 : "%<linear%> clause on %<simd%> or %<for%> "
8148 : "constructs when using OpenMP 5.2 modifiers");
8149 18 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
8150 : }
8151 : }
8152 1011 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
8153 2571 : && !type_dependent_expression_p (t))
8154 : {
8155 1529 : tree type = TREE_TYPE (t);
8156 1529 : if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
8157 1448 : || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
8158 1598 : && !TYPE_REF_P (type))
8159 : {
8160 12 : error_at (OMP_CLAUSE_LOCATION (c),
8161 : "linear clause with %qs modifier applied to "
8162 : "non-reference variable with %qT type",
8163 12 : OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
8164 12 : ? "ref" : "uval", TREE_TYPE (t));
8165 12 : remove = true;
8166 12 : break;
8167 : }
8168 1517 : if (TYPE_REF_P (type))
8169 281 : type = TREE_TYPE (type);
8170 1517 : if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
8171 : {
8172 1442 : if (!INTEGRAL_TYPE_P (type)
8173 85 : && !TYPE_PTR_P (type))
8174 : {
8175 18 : error_at (OMP_CLAUSE_LOCATION (c),
8176 : "linear clause applied to non-integral "
8177 : "non-pointer variable with %qT type",
8178 18 : TREE_TYPE (t));
8179 18 : remove = true;
8180 18 : break;
8181 : }
8182 : }
8183 : }
8184 1601 : t = OMP_CLAUSE_LINEAR_STEP (c);
8185 1601 : if (t == NULL_TREE)
8186 6 : t = integer_one_node;
8187 1601 : if (t == error_mark_node)
8188 : {
8189 : remove = true;
8190 : break;
8191 : }
8192 1601 : else if (!type_dependent_expression_p (t)
8193 1599 : && !INTEGRAL_TYPE_P (TREE_TYPE (t))
8194 1613 : && (ort != C_ORT_OMP_DECLARE_SIMD
8195 9 : || TREE_CODE (t) != PARM_DECL
8196 6 : || !TYPE_REF_P (TREE_TYPE (t))
8197 6 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
8198 : {
8199 6 : error_at (OMP_CLAUSE_LOCATION (c),
8200 : "linear step expression must be integral");
8201 6 : remove = true;
8202 6 : break;
8203 : }
8204 : else
8205 : {
8206 1595 : t = mark_rvalue_use (t);
8207 1595 : if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
8208 : {
8209 42 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
8210 42 : goto check_dup_generic;
8211 : }
8212 1553 : if (!processing_template_decl
8213 1553 : && (VAR_P (OMP_CLAUSE_DECL (c))
8214 835 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
8215 : {
8216 1372 : if (ort == C_ORT_OMP_DECLARE_SIMD)
8217 : {
8218 589 : t = maybe_constant_value (t);
8219 589 : if (TREE_CODE (t) != INTEGER_CST)
8220 : {
8221 6 : error_at (OMP_CLAUSE_LOCATION (c),
8222 : "%<linear%> clause step %qE is neither "
8223 : "constant nor a parameter", t);
8224 6 : remove = true;
8225 6 : break;
8226 : }
8227 : }
8228 1366 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8229 1366 : tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
8230 1366 : if (TYPE_REF_P (type))
8231 257 : type = TREE_TYPE (type);
8232 1366 : if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
8233 : {
8234 66 : type = build_pointer_type (type);
8235 66 : tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
8236 66 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8237 : d, t);
8238 66 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8239 : MINUS_EXPR, sizetype,
8240 : fold_convert (sizetype, t),
8241 : fold_convert (sizetype, d));
8242 66 : if (t == error_mark_node)
8243 : {
8244 : remove = true;
8245 : break;
8246 : }
8247 : }
8248 1300 : else if (TYPE_PTR_P (type)
8249 : /* Can't multiply the step yet if *this
8250 : is still incomplete type. */
8251 1300 : && (ort != C_ORT_OMP_DECLARE_SIMD
8252 45 : || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
8253 45 : || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
8254 30 : || DECL_NAME (OMP_CLAUSE_DECL (c))
8255 30 : != this_identifier
8256 30 : || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
8257 : {
8258 37 : tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
8259 37 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8260 : d, t);
8261 37 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8262 : MINUS_EXPR, sizetype,
8263 : fold_convert (sizetype, t),
8264 : fold_convert (sizetype, d));
8265 37 : if (t == error_mark_node)
8266 : {
8267 : remove = true;
8268 : break;
8269 : }
8270 : }
8271 : else
8272 1263 : t = fold_convert (type, t);
8273 : }
8274 1547 : OMP_CLAUSE_LINEAR_STEP (c) = t;
8275 : }
8276 1547 : goto check_dup_generic;
8277 15028 : check_dup_generic:
8278 15028 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8279 15028 : if (t)
8280 : {
8281 101 : if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
8282 101 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8283 : }
8284 : else
8285 14927 : t = OMP_CLAUSE_DECL (c);
8286 17565 : check_dup_generic_t:
8287 17565 : if (t == current_class_ptr
8288 17565 : && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
8289 102 : || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
8290 72 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
8291 : {
8292 24 : error_at (OMP_CLAUSE_LOCATION (c),
8293 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8294 : " clauses");
8295 24 : remove = true;
8296 24 : break;
8297 : }
8298 17541 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8299 586 : && (!field_ok || TREE_CODE (t) != FIELD_DECL))
8300 : {
8301 59 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8302 : break;
8303 39 : if (DECL_P (t))
8304 30 : error_at (OMP_CLAUSE_LOCATION (c),
8305 : "%qD is not a variable in clause %qs", t,
8306 15 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8307 : else
8308 48 : error_at (OMP_CLAUSE_LOCATION (c),
8309 : "%qE is not a variable in clause %qs", t,
8310 24 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8311 : remove = true;
8312 : }
8313 17482 : else if ((openacc
8314 2707 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
8315 15013 : || (ort == C_ORT_OMP
8316 12680 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
8317 12649 : || (OMP_CLAUSE_CODE (c)
8318 : == OMP_CLAUSE_USE_DEVICE_ADDR)))
8319 32388 : || (ort == C_ORT_OMP_TARGET
8320 938 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
8321 : {
8322 2854 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
8323 2854 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8324 275 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
8325 : {
8326 6 : error_at (OMP_CLAUSE_LOCATION (c),
8327 : "%qD appears more than once in data-sharing "
8328 : "clauses", t);
8329 6 : remove = true;
8330 6 : break;
8331 : }
8332 2848 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
8333 272 : target_in_reduction_seen = true;
8334 2848 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8335 : {
8336 12 : error_at (OMP_CLAUSE_LOCATION (c),
8337 : openacc
8338 : ? "%qD appears more than once in reduction clauses"
8339 : : "%qD appears more than once in data clauses",
8340 : t);
8341 6 : remove = true;
8342 : }
8343 : else
8344 2842 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8345 : }
8346 14628 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8347 14555 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8348 14552 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
8349 29180 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8350 : {
8351 76 : error_at (OMP_CLAUSE_LOCATION (c),
8352 : "%qD appears more than once in data clauses", t);
8353 76 : remove = true;
8354 : }
8355 14552 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
8356 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
8357 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
8358 3125 : && bitmap_bit_p (&map_head, DECL_UID (t)))
8359 : {
8360 9 : if (openacc)
8361 0 : error_at (OMP_CLAUSE_LOCATION (c),
8362 : "%qD appears more than once in data clauses", t);
8363 : else
8364 9 : error_at (OMP_CLAUSE_LOCATION (c),
8365 : "%qD appears both in data and map clauses", t);
8366 : remove = true;
8367 : }
8368 : else
8369 14543 : bitmap_set_bit (&generic_head, DECL_UID (t));
8370 17515 : if (!field_ok)
8371 : break;
8372 13104 : handle_field_decl:
8373 21884 : if (!remove
8374 21689 : && TREE_CODE (t) == FIELD_DECL
8375 16973 : && t == OMP_CLAUSE_DECL (c))
8376 : {
8377 795 : OMP_CLAUSE_DECL (c)
8378 795 : = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
8379 : == OMP_CLAUSE_SHARED));
8380 795 : if (OMP_CLAUSE_DECL (c) == error_mark_node)
8381 98715 : remove = true;
8382 : }
8383 : break;
8384 :
8385 3512 : case OMP_CLAUSE_FIRSTPRIVATE:
8386 3512 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
8387 : {
8388 414 : move_implicit:
8389 414 : implicit_moved = true;
8390 : /* Move firstprivate and map clauses with
8391 : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
8392 : clauses chain. */
8393 414 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
8394 414 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
8395 2704 : while (*pc1)
8396 2290 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
8397 2290 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
8398 : {
8399 275 : *pc3 = *pc1;
8400 275 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
8401 275 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8402 : }
8403 2015 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
8404 2015 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
8405 : {
8406 370 : *pc2 = *pc1;
8407 370 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
8408 370 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8409 : }
8410 : else
8411 1645 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
8412 414 : *pc3 = NULL;
8413 414 : *pc2 = cl2;
8414 414 : *pc1 = cl1;
8415 414 : continue;
8416 414 : }
8417 3255 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8418 3255 : if (t)
8419 69 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8420 : else
8421 3186 : t = OMP_CLAUSE_DECL (c);
8422 3255 : if (!openacc && t == current_class_ptr)
8423 : {
8424 6 : error_at (OMP_CLAUSE_LOCATION (c),
8425 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8426 : " clauses");
8427 6 : remove = true;
8428 6 : break;
8429 : }
8430 3249 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8431 333 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8432 333 : || TREE_CODE (t) != FIELD_DECL))
8433 : {
8434 41 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8435 : break;
8436 18 : if (DECL_P (t))
8437 12 : error_at (OMP_CLAUSE_LOCATION (c),
8438 : "%qD is not a variable in clause %<firstprivate%>",
8439 : t);
8440 : else
8441 6 : error_at (OMP_CLAUSE_LOCATION (c),
8442 : "%qE is not a variable in clause %<firstprivate%>",
8443 : t);
8444 : remove = true;
8445 : }
8446 3208 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8447 275 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
8448 3462 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8449 : remove = true;
8450 3208 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8451 3199 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8452 6404 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8453 : {
8454 15 : error_at (OMP_CLAUSE_LOCATION (c),
8455 : "%qD appears more than once in data clauses", t);
8456 15 : remove = true;
8457 : }
8458 3193 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8459 3193 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
8460 : {
8461 21 : if (openacc)
8462 0 : error_at (OMP_CLAUSE_LOCATION (c),
8463 : "%qD appears more than once in data clauses", t);
8464 21 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8465 21 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
8466 : /* Silently drop the clause. */;
8467 : else
8468 18 : error_at (OMP_CLAUSE_LOCATION (c),
8469 : "%qD appears both in data and map clauses", t);
8470 : remove = true;
8471 : }
8472 : else
8473 3172 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
8474 3226 : goto handle_field_decl;
8475 :
8476 2793 : case OMP_CLAUSE_LASTPRIVATE:
8477 2793 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8478 2793 : if (t)
8479 35 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8480 : else
8481 2758 : t = OMP_CLAUSE_DECL (c);
8482 2793 : if (!openacc && t == current_class_ptr)
8483 : {
8484 6 : error_at (OMP_CLAUSE_LOCATION (c),
8485 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8486 : " clauses");
8487 6 : remove = true;
8488 6 : break;
8489 : }
8490 2787 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8491 259 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8492 259 : || TREE_CODE (t) != FIELD_DECL))
8493 : {
8494 35 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8495 : break;
8496 9 : if (DECL_P (t))
8497 3 : error_at (OMP_CLAUSE_LOCATION (c),
8498 : "%qD is not a variable in clause %<lastprivate%>",
8499 : t);
8500 : else
8501 6 : error_at (OMP_CLAUSE_LOCATION (c),
8502 : "%qE is not a variable in clause %<lastprivate%>",
8503 : t);
8504 : remove = true;
8505 : }
8506 2752 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8507 2752 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8508 : {
8509 12 : error_at (OMP_CLAUSE_LOCATION (c),
8510 : "%qD appears more than once in data clauses", t);
8511 12 : remove = true;
8512 : }
8513 : else
8514 2740 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
8515 2761 : goto handle_field_decl;
8516 :
8517 2229 : case OMP_CLAUSE_IF:
8518 2229 : case OMP_CLAUSE_SELF:
8519 2229 : t = OMP_CLAUSE_OPERAND (c, 0);
8520 2229 : t = maybe_convert_cond (t);
8521 2229 : if (t == error_mark_node)
8522 : remove = true;
8523 2214 : else if (!processing_template_decl)
8524 2151 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8525 2229 : OMP_CLAUSE_OPERAND (c, 0) = t;
8526 2229 : break;
8527 :
8528 289 : case OMP_CLAUSE_FINAL:
8529 289 : t = OMP_CLAUSE_FINAL_EXPR (c);
8530 289 : t = maybe_convert_cond (t);
8531 289 : if (t == error_mark_node)
8532 : remove = true;
8533 289 : else if (!processing_template_decl)
8534 283 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8535 289 : OMP_CLAUSE_FINAL_EXPR (c) = t;
8536 289 : break;
8537 :
8538 92 : case OMP_CLAUSE_NOCONTEXT:
8539 92 : t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
8540 92 : t = maybe_convert_cond (t);
8541 92 : if (t == error_mark_node)
8542 : remove = true;
8543 89 : else if (!processing_template_decl)
8544 83 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8545 92 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
8546 92 : break;
8547 :
8548 80 : case OMP_CLAUSE_NOVARIANTS:
8549 80 : t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
8550 80 : t = maybe_convert_cond (t);
8551 80 : if (t == error_mark_node)
8552 : remove = true;
8553 77 : else if (!processing_template_decl)
8554 71 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8555 80 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
8556 80 : break;
8557 :
8558 1249 : case OMP_CLAUSE_GANG:
8559 : /* Operand 1 is the gang static: argument. */
8560 1249 : t = OMP_CLAUSE_OPERAND (c, 1);
8561 1249 : if (t != NULL_TREE)
8562 : {
8563 129 : if (t == error_mark_node)
8564 : remove = true;
8565 129 : else if (!type_dependent_expression_p (t)
8566 129 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8567 : {
8568 6 : error_at (OMP_CLAUSE_LOCATION (c),
8569 : "%<gang%> static expression must be integral");
8570 6 : remove = true;
8571 : }
8572 : else
8573 : {
8574 123 : t = mark_rvalue_use (t);
8575 123 : if (!processing_template_decl)
8576 : {
8577 123 : t = maybe_constant_value (t);
8578 123 : if (TREE_CODE (t) == INTEGER_CST
8579 109 : && tree_int_cst_sgn (t) != 1
8580 176 : && t != integer_minus_one_node)
8581 : {
8582 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8583 : "%<gang%> static value must be "
8584 : "positive");
8585 0 : t = integer_one_node;
8586 : }
8587 123 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8588 : }
8589 : }
8590 129 : OMP_CLAUSE_OPERAND (c, 1) = t;
8591 : }
8592 : /* Check operand 0, the num argument. */
8593 : /* FALLTHRU */
8594 :
8595 3480 : case OMP_CLAUSE_WORKER:
8596 3480 : case OMP_CLAUSE_VECTOR:
8597 3480 : if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
8598 : break;
8599 : /* FALLTHRU */
8600 :
8601 484 : case OMP_CLAUSE_NUM_TASKS:
8602 484 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
8603 136 : num_tasks_seen = true;
8604 : /* FALLTHRU */
8605 :
8606 3035 : case OMP_CLAUSE_NUM_TEAMS:
8607 3035 : case OMP_CLAUSE_NUM_THREADS:
8608 3035 : case OMP_CLAUSE_NUM_GANGS:
8609 3035 : case OMP_CLAUSE_NUM_WORKERS:
8610 3035 : case OMP_CLAUSE_DYN_GROUPPRIVATE:
8611 3035 : case OMP_CLAUSE_VECTOR_LENGTH:
8612 3035 : t = OMP_CLAUSE_OPERAND (c, 0);
8613 3035 : if (t == error_mark_node)
8614 : remove = true;
8615 3035 : else if (!type_dependent_expression_p (t)
8616 3035 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8617 : {
8618 99 : switch (OMP_CLAUSE_CODE (c))
8619 : {
8620 12 : case OMP_CLAUSE_GANG:
8621 12 : error_at (OMP_CLAUSE_LOCATION (c),
8622 12 : "%<gang%> num expression must be integral"); break;
8623 12 : case OMP_CLAUSE_VECTOR:
8624 12 : error_at (OMP_CLAUSE_LOCATION (c),
8625 : "%<vector%> length expression must be integral");
8626 12 : break;
8627 12 : case OMP_CLAUSE_WORKER:
8628 12 : error_at (OMP_CLAUSE_LOCATION (c),
8629 : "%<worker%> num expression must be integral");
8630 12 : break;
8631 63 : default:
8632 63 : error_at (OMP_CLAUSE_LOCATION (c),
8633 : "%qs expression must be integral",
8634 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8635 : }
8636 : remove = true;
8637 : }
8638 : else
8639 : {
8640 2936 : t = mark_rvalue_use (t);
8641 2936 : if (!processing_template_decl)
8642 : {
8643 2688 : t = maybe_constant_value (t);
8644 2688 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
8645 2653 : && TREE_CODE (t) == INTEGER_CST
8646 4144 : && tree_int_cst_sgn (t) != 1)
8647 : {
8648 85 : switch (OMP_CLAUSE_CODE (c))
8649 : {
8650 3 : case OMP_CLAUSE_GANG:
8651 3 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8652 : "%<gang%> num value must be positive");
8653 3 : break;
8654 0 : case OMP_CLAUSE_VECTOR:
8655 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8656 : "%<vector%> length value must be "
8657 : "positive");
8658 0 : break;
8659 0 : case OMP_CLAUSE_WORKER:
8660 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8661 : "%<worker%> num value must be "
8662 : "positive");
8663 0 : break;
8664 82 : default:
8665 82 : warning_at (OMP_CLAUSE_LOCATION (c),
8666 46 : (flag_openmp || flag_openmp_simd)
8667 82 : ? OPT_Wopenmp : 0,
8668 : "%qs value must be positive",
8669 : omp_clause_code_name
8670 82 : [OMP_CLAUSE_CODE (c)]);
8671 : }
8672 85 : t = integer_one_node;
8673 : }
8674 2603 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
8675 35 : && TREE_CODE (t) == INTEGER_CST
8676 2626 : && tree_int_cst_sgn (t) < 0)
8677 : {
8678 8 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8679 : "%<dyn_groupprivate%> value must be "
8680 : "non-negative");
8681 8 : t = integer_zero_node;
8682 : }
8683 2688 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8684 : }
8685 2936 : OMP_CLAUSE_OPERAND (c, 0) = t;
8686 : }
8687 3035 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
8688 753 : && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
8689 3314 : && !remove)
8690 : {
8691 279 : t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
8692 279 : if (t == error_mark_node)
8693 : remove = true;
8694 279 : else if (!type_dependent_expression_p (t)
8695 279 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8696 : {
8697 0 : error_at (OMP_CLAUSE_LOCATION (c),
8698 : "%qs expression must be integral",
8699 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8700 0 : remove = true;
8701 : }
8702 : else
8703 : {
8704 279 : t = mark_rvalue_use (t);
8705 279 : if (!processing_template_decl)
8706 : {
8707 213 : t = maybe_constant_value (t);
8708 213 : if (TREE_CODE (t) == INTEGER_CST
8709 213 : && tree_int_cst_sgn (t) != 1)
8710 : {
8711 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8712 : "%qs value must be positive",
8713 : omp_clause_code_name
8714 18 : [OMP_CLAUSE_CODE (c)]);
8715 18 : t = NULL_TREE;
8716 : }
8717 : else
8718 195 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8719 213 : tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
8720 213 : if (t
8721 195 : && TREE_CODE (t) == INTEGER_CST
8722 43 : && TREE_CODE (upper) == INTEGER_CST
8723 250 : && tree_int_cst_lt (upper, t))
8724 : {
8725 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8726 : "%<num_teams%> lower bound %qE bigger "
8727 : "than upper bound %qE", t, upper);
8728 18 : t = NULL_TREE;
8729 : }
8730 : }
8731 279 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
8732 : }
8733 : }
8734 : break;
8735 :
8736 3892 : case OMP_CLAUSE_SCHEDULE:
8737 3892 : t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
8738 3892 : if (t == NULL)
8739 : ;
8740 2093 : else if (t == error_mark_node)
8741 : remove = true;
8742 2093 : else if (!type_dependent_expression_p (t)
8743 2093 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8744 : {
8745 9 : error_at (OMP_CLAUSE_LOCATION (c),
8746 : "schedule chunk size expression must be integral");
8747 9 : remove = true;
8748 : }
8749 : else
8750 : {
8751 2084 : t = mark_rvalue_use (t);
8752 2084 : if (!processing_template_decl)
8753 : {
8754 2044 : t = maybe_constant_value (t);
8755 2044 : if (TREE_CODE (t) == INTEGER_CST
8756 2044 : && tree_int_cst_sgn (t) != 1)
8757 : {
8758 6 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8759 : "chunk size value must be positive");
8760 6 : t = integer_one_node;
8761 : }
8762 2044 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8763 : }
8764 2084 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8765 : }
8766 2093 : if (!remove)
8767 : schedule_seen = true;
8768 : break;
8769 :
8770 894 : case OMP_CLAUSE_SIMDLEN:
8771 894 : t = OMP_CLAUSE_SIMDLEN_TYPE (c);
8772 894 : if (t == error_mark_node)
8773 : remove = true;
8774 75 : else if (t && !dependent_type_p (t)
8775 942 : && !ARITHMETIC_TYPE_P (t))
8776 : {
8777 3 : error_at (OMP_CLAUSE_LOCATION (c),
8778 : "expected arithmetic type name as argument to the "
8779 : "%<scaled%> modifier");
8780 3 : remove = true;
8781 : }
8782 894 : t = OMP_CLAUSE_SIMDLEN_DIVISOR (c);
8783 894 : if (t == error_mark_node)
8784 : remove = true;
8785 54 : else if (t && !type_dependent_expression_p (t)
8786 947 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8787 : {
8788 0 : error_at (OMP_CLAUSE_LOCATION (c),
8789 : "%qs divisor expression of the %<scaled%> modifier "
8790 : "must be integral",
8791 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8792 0 : remove = true;
8793 : }
8794 893 : else if (t)
8795 : {
8796 54 : t = mark_rvalue_use (t);
8797 54 : if (!processing_template_decl)
8798 : {
8799 40 : t = maybe_constant_value (t);
8800 40 : if (TREE_CODE (t) != INTEGER_CST
8801 40 : || tree_int_cst_sgn (t) != 1)
8802 : {
8803 16 : error_at (OMP_CLAUSE_LOCATION (c),
8804 : "%qs divisor expression of the %<scaled%> "
8805 : "modifier must be a positive constant integer "
8806 : "expression",
8807 8 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8808 8 : remove = true;
8809 : }
8810 : }
8811 54 : OMP_CLAUSE_SIMDLEN_DIVISOR (c) = t;
8812 : }
8813 : /* FALLTHRU */
8814 1364 : case OMP_CLAUSE_SAFELEN:
8815 1364 : t = OMP_CLAUSE_OPERAND (c, 0);
8816 1364 : if (t == error_mark_node)
8817 : remove = true;
8818 1358 : else if (!type_dependent_expression_p (t)
8819 1358 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8820 : {
8821 0 : error_at (OMP_CLAUSE_LOCATION (c),
8822 : "%qs length expression must be integral",
8823 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8824 0 : remove = true;
8825 : }
8826 : else
8827 : {
8828 1358 : t = mark_rvalue_use (t);
8829 1358 : if (!processing_template_decl)
8830 : {
8831 1291 : t = maybe_constant_value (t);
8832 1291 : if (TREE_CODE (t) != INTEGER_CST
8833 1291 : || tree_int_cst_sgn (t) != 1)
8834 : {
8835 0 : error_at (OMP_CLAUSE_LOCATION (c),
8836 : "%qs length expression must be positive "
8837 : "constant integer expression",
8838 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8839 0 : remove = true;
8840 : }
8841 : }
8842 1358 : OMP_CLAUSE_OPERAND (c, 0) = t;
8843 1358 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
8844 470 : safelen = c;
8845 : }
8846 : break;
8847 :
8848 388 : case OMP_CLAUSE_ASYNC:
8849 388 : t = OMP_CLAUSE_ASYNC_EXPR (c);
8850 388 : if (t == error_mark_node)
8851 : remove = true;
8852 373 : else if (!type_dependent_expression_p (t)
8853 373 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8854 : {
8855 12 : error_at (OMP_CLAUSE_LOCATION (c),
8856 : "%<async%> expression must be integral");
8857 12 : remove = true;
8858 : }
8859 : else
8860 : {
8861 361 : t = mark_rvalue_use (t);
8862 361 : if (!processing_template_decl)
8863 352 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8864 361 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
8865 : }
8866 : break;
8867 :
8868 204 : case OMP_CLAUSE_WAIT:
8869 204 : t = OMP_CLAUSE_WAIT_EXPR (c);
8870 204 : if (t == error_mark_node)
8871 : remove = true;
8872 204 : else if (!processing_template_decl)
8873 196 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8874 204 : OMP_CLAUSE_WAIT_EXPR (c) = t;
8875 204 : break;
8876 :
8877 637 : case OMP_CLAUSE_THREAD_LIMIT:
8878 637 : t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
8879 637 : if (t == error_mark_node)
8880 : remove = true;
8881 637 : else if (!type_dependent_expression_p (t)
8882 637 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8883 : {
8884 0 : error_at (OMP_CLAUSE_LOCATION (c),
8885 : "%<thread_limit%> expression must be integral");
8886 0 : remove = true;
8887 : }
8888 : else
8889 : {
8890 637 : t = mark_rvalue_use (t);
8891 637 : if (!processing_template_decl)
8892 : {
8893 583 : t = maybe_constant_value (t);
8894 583 : if (TREE_CODE (t) == INTEGER_CST
8895 583 : && tree_int_cst_sgn (t) != 1)
8896 : {
8897 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8898 : "%<thread_limit%> value must be positive");
8899 0 : t = integer_one_node;
8900 : }
8901 583 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8902 : }
8903 637 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
8904 : }
8905 : break;
8906 :
8907 770 : case OMP_CLAUSE_DEVICE:
8908 770 : t = OMP_CLAUSE_DEVICE_ID (c);
8909 770 : if (t == error_mark_node)
8910 : remove = true;
8911 770 : else if (!type_dependent_expression_p (t)
8912 770 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8913 : {
8914 6 : error_at (OMP_CLAUSE_LOCATION (c),
8915 : "%<device%> id must be integral");
8916 6 : remove = true;
8917 : }
8918 764 : else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
8919 66 : && TREE_CODE (t) == INTEGER_CST
8920 824 : && !integer_onep (t))
8921 : {
8922 3 : error_at (OMP_CLAUSE_LOCATION (c),
8923 : "the %<device%> clause expression must evaluate to "
8924 : "%<1%>");
8925 3 : remove = true;
8926 : }
8927 : else
8928 : {
8929 761 : t = mark_rvalue_use (t);
8930 761 : if (!processing_template_decl)
8931 750 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8932 761 : OMP_CLAUSE_DEVICE_ID (c) = t;
8933 : }
8934 : break;
8935 :
8936 1848 : case OMP_CLAUSE_DIST_SCHEDULE:
8937 1848 : t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
8938 1848 : if (t == NULL)
8939 : ;
8940 1827 : else if (t == error_mark_node)
8941 : remove = true;
8942 1827 : else if (!type_dependent_expression_p (t)
8943 1827 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8944 : {
8945 0 : error_at (OMP_CLAUSE_LOCATION (c),
8946 : "%<dist_schedule%> chunk size expression must be "
8947 : "integral");
8948 0 : remove = true;
8949 : }
8950 : else
8951 : {
8952 1827 : t = mark_rvalue_use (t);
8953 1827 : if (!processing_template_decl)
8954 1827 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8955 1827 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
8956 : }
8957 : break;
8958 :
8959 807 : case OMP_CLAUSE_ALIGNED:
8960 807 : t = OMP_CLAUSE_DECL (c);
8961 807 : if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
8962 : {
8963 0 : error_at (OMP_CLAUSE_LOCATION (c),
8964 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8965 : " clauses");
8966 0 : remove = true;
8967 0 : break;
8968 : }
8969 807 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8970 : {
8971 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8972 : break;
8973 0 : if (DECL_P (t))
8974 0 : error_at (OMP_CLAUSE_LOCATION (c),
8975 : "%qD is not a variable in %<aligned%> clause", t);
8976 : else
8977 0 : error_at (OMP_CLAUSE_LOCATION (c),
8978 : "%qE is not a variable in %<aligned%> clause", t);
8979 : remove = true;
8980 : }
8981 807 : else if (!type_dependent_expression_p (t)
8982 789 : && !TYPE_PTR_P (TREE_TYPE (t))
8983 111 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
8984 864 : && (!TYPE_REF_P (TREE_TYPE (t))
8985 39 : || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
8986 30 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
8987 : != ARRAY_TYPE))))
8988 : {
8989 33 : error_at (OMP_CLAUSE_LOCATION (c),
8990 : "%qE in %<aligned%> clause is neither a pointer nor "
8991 : "an array nor a reference to pointer or array", t);
8992 33 : remove = true;
8993 : }
8994 774 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8995 : {
8996 0 : error_at (OMP_CLAUSE_LOCATION (c),
8997 : "%qD appears more than once in %<aligned%> clauses",
8998 : t);
8999 0 : remove = true;
9000 : }
9001 : else
9002 774 : bitmap_set_bit (&aligned_head, DECL_UID (t));
9003 807 : t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
9004 807 : if (t == error_mark_node)
9005 : remove = true;
9006 807 : else if (t == NULL_TREE)
9007 : break;
9008 744 : else if (!type_dependent_expression_p (t)
9009 744 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9010 : {
9011 0 : error_at (OMP_CLAUSE_LOCATION (c),
9012 : "%<aligned%> clause alignment expression must "
9013 : "be integral");
9014 0 : remove = true;
9015 : }
9016 : else
9017 : {
9018 744 : t = mark_rvalue_use (t);
9019 744 : if (!processing_template_decl)
9020 : {
9021 690 : t = maybe_constant_value (t);
9022 690 : if (TREE_CODE (t) != INTEGER_CST
9023 690 : || tree_int_cst_sgn (t) != 1)
9024 : {
9025 0 : error_at (OMP_CLAUSE_LOCATION (c),
9026 : "%<aligned%> clause alignment expression must "
9027 : "be positive constant integer expression");
9028 0 : remove = true;
9029 : }
9030 : }
9031 744 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
9032 : }
9033 : break;
9034 :
9035 369 : case OMP_CLAUSE_NONTEMPORAL:
9036 369 : t = OMP_CLAUSE_DECL (c);
9037 369 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9038 : {
9039 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9040 : break;
9041 0 : if (DECL_P (t))
9042 0 : error_at (OMP_CLAUSE_LOCATION (c),
9043 : "%qD is not a variable in %<nontemporal%> clause",
9044 : t);
9045 : else
9046 0 : error_at (OMP_CLAUSE_LOCATION (c),
9047 : "%qE is not a variable in %<nontemporal%> clause",
9048 : t);
9049 : remove = true;
9050 : }
9051 369 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
9052 : {
9053 6 : error_at (OMP_CLAUSE_LOCATION (c),
9054 : "%qD appears more than once in %<nontemporal%> "
9055 : "clauses", t);
9056 6 : remove = true;
9057 : }
9058 : else
9059 363 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
9060 : break;
9061 :
9062 2809 : case OMP_CLAUSE_ALLOCATE:
9063 2809 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
9064 2809 : if (t)
9065 14 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
9066 : else
9067 2795 : t = OMP_CLAUSE_DECL (c);
9068 2809 : if (t == current_class_ptr)
9069 : {
9070 0 : error_at (OMP_CLAUSE_LOCATION (c),
9071 : "%<this%> not allowed in %<allocate%> clause");
9072 0 : remove = true;
9073 0 : break;
9074 : }
9075 2809 : if (!VAR_P (t)
9076 678 : && TREE_CODE (t) != PARM_DECL
9077 45 : && TREE_CODE (t) != FIELD_DECL)
9078 : {
9079 3 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9080 : break;
9081 3 : if (DECL_P (t))
9082 3 : error_at (OMP_CLAUSE_LOCATION (c),
9083 : "%qD is not a variable in %<allocate%> clause", t);
9084 : else
9085 0 : error_at (OMP_CLAUSE_LOCATION (c),
9086 : "%qE is not a variable in %<allocate%> clause", t);
9087 : remove = true;
9088 : }
9089 2806 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
9090 : {
9091 12 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9092 : "%qD appears more than once in %<allocate%> clauses",
9093 : t);
9094 12 : remove = true;
9095 : }
9096 : else
9097 : {
9098 2794 : bitmap_set_bit (&aligned_head, DECL_UID (t));
9099 2794 : allocate_seen = true;
9100 : }
9101 2809 : tree allocator, align;
9102 2809 : align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
9103 2809 : if (error_operand_p (align))
9104 : {
9105 : remove = true;
9106 : break;
9107 : }
9108 2809 : if (align)
9109 : {
9110 211 : if (!type_dependent_expression_p (align)
9111 211 : && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
9112 : {
9113 4 : error_at (OMP_CLAUSE_LOCATION (c),
9114 : "%<allocate%> clause %<align%> modifier "
9115 : "argument needs to be positive constant "
9116 : "power of two integer expression");
9117 4 : remove = true;
9118 : }
9119 : else
9120 : {
9121 207 : align = mark_rvalue_use (align);
9122 207 : if (!processing_template_decl)
9123 : {
9124 192 : align = maybe_constant_value (align);
9125 192 : if (TREE_CODE (align) != INTEGER_CST
9126 189 : || !tree_fits_uhwi_p (align)
9127 381 : || !integer_pow2p (align))
9128 : {
9129 10 : error_at (OMP_CLAUSE_LOCATION (c),
9130 : "%<allocate%> clause %<align%> modifier "
9131 : "argument needs to be positive constant "
9132 : "power of two integer expression");
9133 10 : remove = true;
9134 : }
9135 : }
9136 : }
9137 211 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
9138 : }
9139 2809 : allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
9140 2809 : if (error_operand_p (allocator))
9141 : {
9142 : remove = true;
9143 : break;
9144 : }
9145 2809 : if (allocator == NULL_TREE)
9146 1751 : goto handle_field_decl;
9147 1058 : tree allocatort;
9148 1058 : allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
9149 1058 : if (!type_dependent_expression_p (allocator)
9150 1058 : && (TREE_CODE (allocatort) != ENUMERAL_TYPE
9151 1039 : || TYPE_NAME (allocatort) == NULL_TREE
9152 1039 : || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
9153 2078 : || (DECL_NAME (TYPE_NAME (allocatort))
9154 1039 : != get_identifier ("omp_allocator_handle_t"))
9155 1039 : || (TYPE_CONTEXT (allocatort)
9156 1039 : != DECL_CONTEXT (global_namespace))))
9157 : {
9158 16 : error_at (OMP_CLAUSE_LOCATION (c),
9159 : "%<allocate%> clause allocator expression has "
9160 : "type %qT rather than %<omp_allocator_handle_t%>",
9161 16 : TREE_TYPE (allocator));
9162 16 : remove = true;
9163 16 : break;
9164 : }
9165 : else
9166 : {
9167 1042 : allocator = mark_rvalue_use (allocator);
9168 1042 : if (!processing_template_decl)
9169 1023 : allocator = maybe_constant_value (allocator);
9170 1042 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
9171 : }
9172 1042 : goto handle_field_decl;
9173 :
9174 654 : case OMP_CLAUSE_DOACROSS:
9175 654 : t = OMP_CLAUSE_DECL (c);
9176 654 : if (t == NULL_TREE)
9177 : break;
9178 298 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
9179 : {
9180 298 : if (cp_finish_omp_clause_doacross_sink (c))
9181 98715 : remove = true;
9182 : break;
9183 : }
9184 0 : gcc_unreachable ();
9185 89 : case OMP_CLAUSE_USES_ALLOCATORS:
9186 89 : t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
9187 89 : t = convert_from_reference (t);
9188 89 : if (t == error_mark_node)
9189 : {
9190 : remove = true;
9191 : break;
9192 : }
9193 82 : if (DECL_P (t)
9194 82 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
9195 79 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9196 78 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
9197 : {
9198 1 : error_at (OMP_CLAUSE_LOCATION (c),
9199 : "%qE appears more than once in data clauses", t);
9200 1 : remove = true;
9201 : }
9202 81 : else if (DECL_P (t))
9203 78 : bitmap_set_bit (&generic_head, DECL_UID (t));
9204 82 : if (type_dependent_expression_p (t))
9205 : break;
9206 77 : if (TREE_CODE (t) == FIELD_DECL)
9207 : {
9208 0 : sorry_at (OMP_CLAUSE_LOCATION (c), "class member %qE not yet "
9209 : "supported in %<uses_allocators%> clause", t);
9210 0 : remove = true;
9211 0 : break;
9212 : }
9213 77 : if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9214 151 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9215 : "omp_allocator_handle_t") != 0)
9216 : {
9217 3 : error_at (OMP_CLAUSE_LOCATION (c),
9218 : "allocator %qE must be of %<omp_allocator_handle_t%> "
9219 : "type", t);
9220 3 : remove = true;
9221 3 : break;
9222 : }
9223 74 : tree init;
9224 74 : if (TREE_CODE (t) == CONST_DECL)
9225 7 : init = DECL_INITIAL(t);
9226 : else
9227 : init = t;
9228 74 : if (!DECL_P (t)
9229 74 : && (init == NULL_TREE
9230 3 : || TREE_CODE (init) != INTEGER_CST
9231 3 : || ((wi::to_widest (init) < 0
9232 3 : || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
9233 1 : && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
9234 1 : || (wi::to_widest (init)
9235 2 : > GOMP_OMPX_PREDEF_ALLOC_MAX)))))
9236 : {
9237 1 : remove = true;
9238 1 : error_at (OMP_CLAUSE_LOCATION (c),
9239 : "allocator %qE must be either a variable or a "
9240 : "predefined allocator", t);
9241 1 : break;
9242 : }
9243 73 : else if (TREE_CODE (t) == CONST_DECL)
9244 : {
9245 : /* omp_null_allocator is ignored and for predefined allocators,
9246 : not special handling is required; thus, remove them removed. */
9247 7 : remove = true;
9248 :
9249 7 : if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
9250 7 : || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
9251 : {
9252 0 : error_at (OMP_CLAUSE_LOCATION (c),
9253 : "modifiers cannot be used with predefined "
9254 : "allocators");
9255 0 : break;
9256 : }
9257 : }
9258 73 : t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
9259 73 : if (t == error_mark_node)
9260 : {
9261 : remove = true;
9262 : break;
9263 : }
9264 72 : if (t != NULL_TREE
9265 16 : && !type_dependent_expression_p (t)
9266 88 : && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
9267 15 : || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9268 28 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9269 : "omp_memspace_handle_t") != 0))
9270 : {
9271 2 : error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
9272 : " constant enum of %<omp_memspace_handle_t%> type", t);
9273 2 : remove = true;
9274 2 : break;
9275 : }
9276 70 : t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
9277 70 : if (t == error_mark_node)
9278 : {
9279 : remove = true;
9280 : break;
9281 : }
9282 69 : if (type_dependent_expression_p (t))
9283 : break;
9284 69 : if (t != NULL_TREE
9285 41 : && t != error_mark_node
9286 41 : && !type_dependent_expression_p (t)
9287 110 : && (!DECL_P (t)
9288 41 : || DECL_EXTERNAL (t)
9289 39 : || TREE_CODE (t) == PARM_DECL))
9290 : {
9291 4 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
9292 : "defined in same scope as the construct on which the "
9293 : "clause appears", t);
9294 4 : remove = true;
9295 : }
9296 69 : if (t != NULL_TREE)
9297 : {
9298 41 : bool type_err = false;
9299 :
9300 41 : if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
9301 39 : || DECL_SIZE (t) == NULL_TREE
9302 79 : || !COMPLETE_TYPE_P (TREE_TYPE (t)))
9303 : type_err = true;
9304 : else
9305 : {
9306 38 : tree elem_t = TREE_TYPE (TREE_TYPE (t));
9307 38 : if (TREE_CODE (elem_t) != RECORD_TYPE
9308 76 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
9309 : "omp_alloctrait_t") != 0
9310 76 : || !TYPE_READONLY (elem_t))
9311 : type_err = true;
9312 : }
9313 37 : if (type_err)
9314 : {
9315 4 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
9316 : "be of %<const omp_alloctrait_t []%> type", t);
9317 4 : remove = true;
9318 : }
9319 37 : else if (TREE_CODE (array_type_nelts_top (TREE_TYPE (t)))
9320 : != INTEGER_CST)
9321 : {
9322 1 : error_at (OMP_CLAUSE_LOCATION (c), "variable length traits "
9323 : "arrays are not supported");
9324 1 : remove = true;
9325 : }
9326 : else
9327 : {
9328 36 : tree cst_val = decl_constant_value (t);
9329 36 : if (cst_val == t)
9330 : {
9331 1 : error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
9332 : "initialized with constants");
9333 1 : remove = true;
9334 : }
9335 : }
9336 : }
9337 69 : if (remove)
9338 : break;
9339 55 : pc = &OMP_CLAUSE_CHAIN (c);
9340 55 : continue;
9341 1807 : case OMP_CLAUSE_DEPEND:
9342 1807 : depend_clause = c;
9343 : /* FALLTHRU */
9344 2416 : case OMP_CLAUSE_AFFINITY:
9345 2416 : t = OMP_CLAUSE_DECL (c);
9346 2416 : if (OMP_ITERATOR_DECL_P (t))
9347 : {
9348 623 : if (TREE_PURPOSE (t) != last_iterators)
9349 525 : last_iterators_remove
9350 525 : = cp_omp_finish_iterators (TREE_PURPOSE (t));
9351 623 : last_iterators = TREE_PURPOSE (t);
9352 623 : t = TREE_VALUE (t);
9353 623 : if (last_iterators_remove)
9354 144 : t = error_mark_node;
9355 : }
9356 : else
9357 : last_iterators = NULL_TREE;
9358 :
9359 2416 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9360 : {
9361 1368 : if (handle_omp_array_sections (c, ort))
9362 : remove = true;
9363 1014 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9364 1014 : && (OMP_CLAUSE_DEPEND_KIND (c)
9365 : == OMP_CLAUSE_DEPEND_DEPOBJ))
9366 : {
9367 6 : error_at (OMP_CLAUSE_LOCATION (c),
9368 : "%<depend%> clause with %<depobj%> dependence "
9369 : "type on array section");
9370 6 : remove = true;
9371 : }
9372 : break;
9373 : }
9374 1048 : if (t == error_mark_node)
9375 : remove = true;
9376 886 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9377 886 : && t == ridpointers[RID_OMP_ALL_MEMORY])
9378 : {
9379 33 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
9380 33 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
9381 : {
9382 9 : error_at (OMP_CLAUSE_LOCATION (c),
9383 : "%<omp_all_memory%> used with %<depend%> kind "
9384 : "other than %<out%> or %<inout%>");
9385 9 : remove = true;
9386 : }
9387 33 : if (processing_template_decl)
9388 : break;
9389 : }
9390 853 : else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9391 : break;
9392 661 : else if (!lvalue_p (t))
9393 : {
9394 21 : if (DECL_P (t))
9395 24 : error_at (OMP_CLAUSE_LOCATION (c),
9396 : "%qD is not lvalue expression nor array section "
9397 : "in %qs clause", t,
9398 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9399 : else
9400 18 : error_at (OMP_CLAUSE_LOCATION (c),
9401 : "%qE is not lvalue expression nor array section "
9402 : "in %qs clause", t,
9403 9 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9404 : remove = true;
9405 : }
9406 640 : else if (TREE_CODE (t) == COMPONENT_REF
9407 36 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
9408 676 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
9409 : {
9410 12 : error_at (OMP_CLAUSE_LOCATION (c),
9411 : "bit-field %qE in %qs clause", t,
9412 6 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9413 6 : remove = true;
9414 : }
9415 634 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9416 634 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
9417 : {
9418 130 : if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9419 8 : ? TREE_TYPE (TREE_TYPE (t))
9420 57 : : TREE_TYPE (t)))
9421 : {
9422 12 : error_at (OMP_CLAUSE_LOCATION (c),
9423 : "%qE does not have %<omp_depend_t%> type in "
9424 : "%<depend%> clause with %<depobj%> dependence "
9425 : "type", t);
9426 12 : remove = true;
9427 : }
9428 : }
9429 569 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9430 1010 : && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9431 4 : ? TREE_TYPE (TREE_TYPE (t))
9432 437 : : TREE_TYPE (t)))
9433 : {
9434 15 : error_at (OMP_CLAUSE_LOCATION (c),
9435 : "%qE should not have %<omp_depend_t%> type in "
9436 : "%<depend%> clause with dependence type other than "
9437 : "%<depobj%>", t);
9438 15 : remove = true;
9439 : }
9440 87 : if (!remove)
9441 : {
9442 631 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
9443 24 : t = null_pointer_node;
9444 : else
9445 : {
9446 607 : tree addr = cp_build_addr_expr (t, tf_warning_or_error);
9447 607 : if (addr == error_mark_node)
9448 : {
9449 : remove = true;
9450 : break;
9451 : }
9452 607 : t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
9453 : addr, RO_UNARY_STAR,
9454 : tf_warning_or_error);
9455 607 : if (t == error_mark_node)
9456 : {
9457 : remove = true;
9458 : break;
9459 : }
9460 : }
9461 631 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
9462 137 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
9463 768 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
9464 : == TREE_VEC))
9465 137 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
9466 : else
9467 494 : OMP_CLAUSE_DECL (c) = t;
9468 : }
9469 : break;
9470 69 : case OMP_CLAUSE_DETACH:
9471 69 : t = OMP_CLAUSE_DECL (c);
9472 69 : if (detach_seen)
9473 : {
9474 3 : error_at (OMP_CLAUSE_LOCATION (c),
9475 : "too many %qs clauses on a task construct",
9476 : "detach");
9477 3 : remove = true;
9478 3 : break;
9479 : }
9480 66 : else if (error_operand_p (t))
9481 : {
9482 : remove = true;
9483 : break;
9484 : }
9485 : else
9486 : {
9487 63 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
9488 63 : if (!type_dependent_expression_p (t)
9489 63 : && (!INTEGRAL_TYPE_P (type)
9490 : || TREE_CODE (type) != ENUMERAL_TYPE
9491 51 : || TYPE_NAME (type) == NULL_TREE
9492 102 : || (DECL_NAME (TYPE_NAME (type))
9493 51 : != get_identifier ("omp_event_handle_t"))))
9494 : {
9495 6 : error_at (OMP_CLAUSE_LOCATION (c),
9496 : "%<detach%> clause event handle "
9497 : "has type %qT rather than "
9498 : "%<omp_event_handle_t%>",
9499 : type);
9500 6 : remove = true;
9501 : }
9502 63 : detach_seen = c;
9503 63 : cxx_mark_addressable (t);
9504 : }
9505 63 : break;
9506 :
9507 16365 : case OMP_CLAUSE_MAP:
9508 16365 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
9509 157 : goto move_implicit;
9510 16208 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
9511 16208 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
9512 : {
9513 : remove = true;
9514 : break;
9515 : }
9516 : /* FALLTHRU */
9517 19395 : case OMP_CLAUSE_TO:
9518 19395 : case OMP_CLAUSE_FROM:
9519 19395 : if (OMP_CLAUSE_ITERATORS (c)
9520 19395 : && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
9521 : {
9522 98715 : t = error_mark_node;
9523 : break;
9524 : }
9525 : /* FALLTHRU */
9526 20283 : case OMP_CLAUSE__CACHE_:
9527 20283 : {
9528 20283 : using namespace omp_addr_tokenizer;
9529 20283 : auto_vec<omp_addr_token *, 10> addr_tokens;
9530 :
9531 20283 : t = OMP_CLAUSE_DECL (c);
9532 20283 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9533 : {
9534 6007 : grp_start_p = pc;
9535 6007 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9536 :
9537 6007 : if (handle_omp_array_sections (c, ort))
9538 : remove = true;
9539 : else
9540 : {
9541 5197 : t = OMP_CLAUSE_DECL (c);
9542 5197 : if (TREE_CODE (t) != OMP_ARRAY_SECTION
9543 4336 : && !type_dependent_expression_p (t)
9544 9533 : && !omp_mappable_type (TREE_TYPE (t)))
9545 : {
9546 3 : auto_diagnostic_group d;
9547 6 : error_at (OMP_CLAUSE_LOCATION (c),
9548 : "array section does not have mappable type "
9549 : "in %qs clause",
9550 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9551 3 : if (TREE_TYPE (t) != error_mark_node
9552 3 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9553 3 : cxx_incomplete_type_inform (TREE_TYPE (t));
9554 3 : remove = true;
9555 3 : }
9556 7122 : while (TREE_CODE (t) == ARRAY_REF)
9557 1925 : t = TREE_OPERAND (t, 0);
9558 :
9559 5197 : if (type_dependent_expression_p (t))
9560 : break;
9561 :
9562 4723 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9563 :
9564 4723 : if (!ai.map_supported_p ()
9565 4723 : || !omp_parse_expr (addr_tokens, t))
9566 : {
9567 18 : sorry_at (OMP_CLAUSE_LOCATION (c),
9568 : "unsupported map expression %qE",
9569 9 : OMP_CLAUSE_DECL (c));
9570 9 : remove = true;
9571 9 : break;
9572 : }
9573 :
9574 : /* This check is to determine if this will be the only map
9575 : node created for this clause. Otherwise, we'll check
9576 : the following FIRSTPRIVATE_POINTER,
9577 : FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
9578 : iteration(s) of the loop. */
9579 9379 : if (addr_tokens.length () >= 4
9580 1063 : && addr_tokens[0]->type == STRUCTURE_BASE
9581 1057 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
9582 1057 : && addr_tokens[1]->type == ACCESS_METHOD
9583 1057 : && addr_tokens[2]->type == COMPONENT_SELECTOR
9584 977 : && addr_tokens[3]->type == ACCESS_METHOD
9585 5428 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
9586 551 : || (addr_tokens[3]->u.access_kind
9587 : == ACCESS_INDEXED_ARRAY)))
9588 : {
9589 165 : tree rt = addr_tokens[1]->expr;
9590 :
9591 165 : gcc_assert (DECL_P (rt));
9592 :
9593 165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9594 154 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9595 165 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
9596 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
9597 0 : || bitmap_bit_p (&map_firstprivate_head,
9598 0 : DECL_UID (rt))))
9599 : {
9600 : remove = true;
9601 : break;
9602 : }
9603 165 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
9604 : break;
9605 116 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
9606 : {
9607 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9608 0 : error_at (OMP_CLAUSE_LOCATION (c),
9609 : "%qD appears more than once in motion"
9610 : " clauses", rt);
9611 0 : else if (openacc)
9612 0 : error_at (OMP_CLAUSE_LOCATION (c),
9613 : "%qD appears more than once in data"
9614 : " clauses", rt);
9615 : else
9616 0 : error_at (OMP_CLAUSE_LOCATION (c),
9617 : "%qD appears more than once in map"
9618 : " clauses", rt);
9619 : remove = true;
9620 : }
9621 : else
9622 : {
9623 116 : bitmap_set_bit (&map_head, DECL_UID (rt));
9624 116 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
9625 : }
9626 : }
9627 4723 : }
9628 5475 : if (cp_oacc_check_attachments (c))
9629 12 : remove = true;
9630 5475 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9631 4485 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9632 4421 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9633 5573 : && !OMP_CLAUSE_SIZE (c))
9634 : /* In this case, we have a single array element which is a
9635 : pointer, and we already set OMP_CLAUSE_SIZE in
9636 : handle_omp_array_sections above. For attach/detach
9637 : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
9638 : to zero here. */
9639 60 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9640 : break;
9641 : }
9642 14276 : else if (type_dependent_expression_p (t))
9643 : break;
9644 13493 : else if (!omp_parse_expr (addr_tokens, t))
9645 : {
9646 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
9647 : "unsupported map expression %qE",
9648 0 : OMP_CLAUSE_DECL (c));
9649 0 : remove = true;
9650 0 : break;
9651 : }
9652 13493 : if (t == error_mark_node)
9653 : {
9654 : remove = true;
9655 : break;
9656 : }
9657 :
9658 13379 : tree attr;
9659 13379 : if (DECL_P (t)
9660 10693 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9661 7770 : && (attr = lookup_attribute ("omp declare target",
9662 7770 : DECL_ATTRIBUTES (t)))
9663 13911 : && value_member (get_identifier ("local"),
9664 532 : TREE_VALUE (attr)))
9665 : {
9666 0 : error_at (OMP_CLAUSE_LOCATION (c),
9667 : "device-local variable %qD cannot appear "
9668 : "in map clause", t);
9669 0 : remove = true;
9670 0 : break;
9671 : }
9672 :
9673 : /* OpenACC attach / detach clauses must be pointers. */
9674 13379 : if (cp_oacc_check_attachments (c))
9675 : {
9676 : remove = true;
9677 : break;
9678 : }
9679 13355 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9680 10310 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9681 10261 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9682 13429 : && !OMP_CLAUSE_SIZE (c))
9683 : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
9684 : bias) to zero here, so it is not set erroneously to the
9685 : pointer size later on in gimplify.cc. */
9686 66 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9687 :
9688 13355 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9689 :
9690 13355 : if (!ai.check_clause (c))
9691 : {
9692 : remove = true;
9693 : break;
9694 : }
9695 :
9696 13334 : if (!ai.map_supported_p ())
9697 : {
9698 88 : sorry_at (OMP_CLAUSE_LOCATION (c),
9699 : "unsupported map expression %qE",
9700 44 : OMP_CLAUSE_DECL (c));
9701 44 : remove = true;
9702 44 : break;
9703 : }
9704 :
9705 26580 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
9706 : || addr_tokens[0]->type == STRUCTURE_BASE)
9707 : && addr_tokens[1]->type == ACCESS_METHOD);
9708 :
9709 13290 : t = addr_tokens[1]->expr;
9710 :
9711 : /* This is used to prevent cxx_mark_addressable from being called
9712 : on 'this' for expressions like 'this->a', i.e. typical member
9713 : accesses. */
9714 13290 : indir_component_ref_p
9715 26580 : = (addr_tokens[0]->type == STRUCTURE_BASE
9716 13290 : && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
9717 :
9718 13290 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
9719 1 : goto skip_decl_checks;
9720 :
9721 : /* For OpenMP, we can access a struct "t" and "t.d" on the same
9722 : mapping. OpenACC allows multiple fields of the same structure
9723 : to be written. */
9724 13289 : if (addr_tokens[0]->type == STRUCTURE_BASE
9725 13289 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
9726 1263 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
9727 1351 : goto skip_decl_checks;
9728 :
9729 11938 : if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
9730 : {
9731 0 : OMP_CLAUSE_DECL (c)
9732 0 : = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
9733 0 : break;
9734 : }
9735 11938 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9736 : {
9737 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9738 : break;
9739 0 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9740 0 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9741 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
9742 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
9743 0 : || (!openacc && EXPR_P (t))))
9744 : break;
9745 0 : if (DECL_P (t))
9746 0 : error_at (OMP_CLAUSE_LOCATION (c),
9747 : "%qD is not a variable in %qs clause", t,
9748 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9749 : else
9750 0 : error_at (OMP_CLAUSE_LOCATION (c),
9751 : "%qE is not a variable in %qs clause", t,
9752 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9753 : remove = true;
9754 : }
9755 11938 : else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
9756 : {
9757 0 : error_at (OMP_CLAUSE_LOCATION (c),
9758 : "%qD is threadprivate variable in %qs clause", t,
9759 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9760 0 : remove = true;
9761 : }
9762 11938 : else if (!processing_template_decl
9763 11759 : && !TYPE_REF_P (TREE_TYPE (t))
9764 11082 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9765 8147 : || (OMP_CLAUSE_MAP_KIND (c)
9766 : != GOMP_MAP_FIRSTPRIVATE_POINTER))
9767 9098 : && !indir_component_ref_p
9768 8734 : && (t != current_class_ptr
9769 18 : || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9770 6 : || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
9771 20672 : && !cxx_mark_addressable (t))
9772 : remove = true;
9773 11938 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9774 8985 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9775 8985 : || (OMP_CLAUSE_MAP_KIND (c)
9776 : == GOMP_MAP_FIRSTPRIVATE_POINTER)
9777 7001 : || (OMP_CLAUSE_MAP_KIND (c)
9778 : == GOMP_MAP_ATTACH_DETACH)))
9779 9294 : && t == OMP_CLAUSE_DECL (c)
9780 8596 : && !type_dependent_expression_p (t)
9781 29130 : && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
9782 278 : ? TREE_TYPE (TREE_TYPE (t))
9783 8318 : : TREE_TYPE (t)))
9784 : {
9785 42 : auto_diagnostic_group d;
9786 84 : error_at (OMP_CLAUSE_LOCATION (c),
9787 : "%qD does not have a mappable type in %qs clause", t,
9788 42 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9789 42 : if (TREE_TYPE (t) != error_mark_node
9790 42 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9791 39 : cxx_incomplete_type_inform (TREE_TYPE (t));
9792 42 : remove = true;
9793 42 : }
9794 11896 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9795 8949 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
9796 93 : && !type_dependent_expression_p (t)
9797 11989 : && !INDIRECT_TYPE_P (TREE_TYPE (t)))
9798 : {
9799 6 : error_at (OMP_CLAUSE_LOCATION (c),
9800 : "%qD is not a pointer variable", t);
9801 6 : remove = true;
9802 : }
9803 11890 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9804 8943 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9805 12260 : && (bitmap_bit_p (&map_head, DECL_UID (t))
9806 367 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
9807 367 : || bitmap_bit_p (&map_firstprivate_head,
9808 367 : DECL_UID (t))))
9809 : remove = true;
9810 11884 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9811 11884 : && (OMP_CLAUSE_MAP_KIND (c)
9812 : == GOMP_MAP_FIRSTPRIVATE_POINTER))
9813 : {
9814 1978 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
9815 1978 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9816 3953 : || (openacc
9817 1364 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
9818 : {
9819 12 : error_at (OMP_CLAUSE_LOCATION (c),
9820 : "%qD appears more than once in data clauses", t);
9821 12 : remove = true;
9822 : }
9823 1966 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9824 12 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9825 1974 : && openacc)
9826 : {
9827 3 : error_at (OMP_CLAUSE_LOCATION (c),
9828 : "%qD appears more than once in data clauses", t);
9829 3 : remove = true;
9830 : }
9831 : else
9832 1963 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9833 : }
9834 9906 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9835 9906 : && (OMP_CLAUSE_MAP_KIND (c)
9836 : == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
9837 115 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9838 9791 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9839 181 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9840 38 : && ort != C_ORT_OMP
9841 38 : && ort != C_ORT_OMP_TARGET
9842 9807 : && ort != C_ORT_OMP_EXIT_DATA)
9843 : {
9844 9 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9845 0 : error_at (OMP_CLAUSE_LOCATION (c),
9846 : "%qD appears more than once in motion clauses", t);
9847 9 : else if (openacc)
9848 9 : error_at (OMP_CLAUSE_LOCATION (c),
9849 : "%qD appears more than once in data clauses", t);
9850 : else
9851 0 : error_at (OMP_CLAUSE_LOCATION (c),
9852 : "%qD appears more than once in map clauses", t);
9853 : remove = true;
9854 : }
9855 9782 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
9856 : {
9857 0 : error_at (OMP_CLAUSE_LOCATION (c),
9858 : "%qD appears more than once in data clauses", t);
9859 0 : remove = true;
9860 : }
9861 9782 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9862 9782 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
9863 : {
9864 27 : if (openacc)
9865 0 : error_at (OMP_CLAUSE_LOCATION (c),
9866 : "%qD appears more than once in data clauses", t);
9867 : else
9868 27 : error_at (OMP_CLAUSE_LOCATION (c),
9869 : "%qD appears both in data and map clauses", t);
9870 : remove = true;
9871 : }
9872 9755 : else if (!omp_access_chain_p (addr_tokens, 1))
9873 : {
9874 9675 : bitmap_set_bit (&map_head, DECL_UID (t));
9875 :
9876 9675 : tree decl = OMP_CLAUSE_DECL (c);
9877 9675 : if (t != decl
9878 9675 : && (TREE_CODE (decl) == COMPONENT_REF
9879 162 : || (INDIRECT_REF_P (decl)
9880 162 : && (TREE_CODE (TREE_OPERAND (decl, 0))
9881 : == COMPONENT_REF)
9882 150 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
9883 : 0))))))
9884 1165 : bitmap_set_bit (&map_field_head, DECL_UID (t));
9885 : }
9886 :
9887 4694 : skip_decl_checks:
9888 : /* If we call ai.expand_map_clause in handle_omp_array_sections,
9889 : the containing loop (here) iterates through the new nodes
9890 : created by that expansion. Avoid expanding those again (just
9891 : by checking the node type). */
9892 4694 : if (!remove
9893 13185 : && !processing_template_decl
9894 13009 : && ort != C_ORT_DECLARE_SIMD
9895 13009 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9896 9982 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
9897 8019 : && (OMP_CLAUSE_MAP_KIND (c)
9898 : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
9899 7904 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
9900 7904 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
9901 6905 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
9902 6856 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
9903 : {
9904 9858 : grp_start_p = pc;
9905 9858 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9906 9858 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
9907 : addr_tokens, ort);
9908 9858 : if (nc != error_mark_node)
9909 9858 : c = nc;
9910 : }
9911 20348 : }
9912 13290 : break;
9913 :
9914 645 : case OMP_CLAUSE_ENTER:
9915 645 : case OMP_CLAUSE_LINK:
9916 645 : case OMP_CLAUSE_LOCAL:
9917 645 : t = OMP_CLAUSE_DECL (c);
9918 645 : const char *cname;
9919 645 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
9920 645 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
9921 645 : && OMP_CLAUSE_ENTER_TO (c))
9922 : cname = "to";
9923 645 : if (TREE_CODE (t) == FUNCTION_DECL
9924 645 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9925 : ;
9926 428 : else if (!VAR_P (t))
9927 : {
9928 12 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9929 : {
9930 9 : if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
9931 6 : error_at (OMP_CLAUSE_LOCATION (c),
9932 : "template %qE in clause %qs", t, cname);
9933 3 : else if (really_overloaded_fn (t))
9934 3 : error_at (OMP_CLAUSE_LOCATION (c),
9935 : "overloaded function name %qE in clause %qs", t,
9936 : cname);
9937 : else
9938 0 : error_at (OMP_CLAUSE_LOCATION (c),
9939 : "%qE is neither a variable nor a function name "
9940 : "in clause %qs", t, cname);
9941 : }
9942 : else
9943 3 : error_at (OMP_CLAUSE_LOCATION (c),
9944 : "%qE is not a variable in clause %qs", t, cname);
9945 : remove = true;
9946 : }
9947 416 : else if (DECL_THREAD_LOCAL_P (t))
9948 : {
9949 6 : error_at (OMP_CLAUSE_LOCATION (c),
9950 : "%qD is threadprivate variable in %qs clause", t,
9951 : cname);
9952 6 : remove = true;
9953 : }
9954 410 : else if (!omp_mappable_type (TREE_TYPE (t)))
9955 : {
9956 18 : auto_diagnostic_group d;
9957 18 : error_at (OMP_CLAUSE_LOCATION (c),
9958 : "%qD does not have a mappable type in %qs clause", t,
9959 : cname);
9960 18 : if (TREE_TYPE (t) != error_mark_node
9961 18 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9962 18 : cxx_incomplete_type_inform (TREE_TYPE (t));
9963 18 : remove = true;
9964 18 : }
9965 36 : if (remove)
9966 : break;
9967 609 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9968 : {
9969 30 : error_at (OMP_CLAUSE_LOCATION (c),
9970 : "%qE appears more than once on the same "
9971 : "%<declare target%> directive", t);
9972 30 : remove = true;
9973 : }
9974 : else
9975 579 : bitmap_set_bit (&generic_head, DECL_UID (t));
9976 : break;
9977 :
9978 457 : case OMP_CLAUSE_UNIFORM:
9979 457 : t = OMP_CLAUSE_DECL (c);
9980 457 : if (TREE_CODE (t) != PARM_DECL)
9981 : {
9982 0 : if (processing_template_decl)
9983 : break;
9984 0 : if (DECL_P (t))
9985 0 : error_at (OMP_CLAUSE_LOCATION (c),
9986 : "%qD is not an argument in %<uniform%> clause", t);
9987 : else
9988 0 : error_at (OMP_CLAUSE_LOCATION (c),
9989 : "%qE is not an argument in %<uniform%> clause", t);
9990 : remove = true;
9991 : break;
9992 : }
9993 : /* map_head bitmap is used as uniform_head if declare_simd. */
9994 457 : bitmap_set_bit (&map_head, DECL_UID (t));
9995 457 : goto check_dup_generic;
9996 :
9997 165 : case OMP_CLAUSE_GRAINSIZE:
9998 165 : t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
9999 165 : if (t == error_mark_node)
10000 : remove = true;
10001 165 : else if (!type_dependent_expression_p (t)
10002 165 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10003 : {
10004 0 : error_at (OMP_CLAUSE_LOCATION (c),
10005 : "%<grainsize%> expression must be integral");
10006 0 : remove = true;
10007 : }
10008 : else
10009 : {
10010 165 : t = mark_rvalue_use (t);
10011 165 : if (!processing_template_decl)
10012 : {
10013 164 : t = maybe_constant_value (t);
10014 164 : if (TREE_CODE (t) == INTEGER_CST
10015 164 : && tree_int_cst_sgn (t) != 1)
10016 : {
10017 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
10018 : "%<grainsize%> value must be positive");
10019 0 : t = integer_one_node;
10020 : }
10021 164 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10022 : }
10023 165 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
10024 : }
10025 : break;
10026 :
10027 276 : case OMP_CLAUSE_PRIORITY:
10028 276 : t = OMP_CLAUSE_PRIORITY_EXPR (c);
10029 276 : if (t == error_mark_node)
10030 : remove = true;
10031 276 : else if (!type_dependent_expression_p (t)
10032 276 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10033 : {
10034 0 : error_at (OMP_CLAUSE_LOCATION (c),
10035 : "%<priority%> expression must be integral");
10036 0 : remove = true;
10037 : }
10038 : else
10039 : {
10040 276 : t = mark_rvalue_use (t);
10041 276 : if (!processing_template_decl)
10042 : {
10043 276 : t = maybe_constant_value (t);
10044 276 : if (TREE_CODE (t) == INTEGER_CST
10045 276 : && tree_int_cst_sgn (t) == -1)
10046 : {
10047 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
10048 : "%<priority%> value must be non-negative");
10049 0 : t = integer_one_node;
10050 : }
10051 276 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10052 : }
10053 276 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
10054 : }
10055 : break;
10056 :
10057 228 : case OMP_CLAUSE_HINT:
10058 228 : t = OMP_CLAUSE_HINT_EXPR (c);
10059 228 : if (t == error_mark_node)
10060 : remove = true;
10061 228 : else if (!type_dependent_expression_p (t)
10062 228 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10063 : {
10064 9 : error_at (OMP_CLAUSE_LOCATION (c),
10065 : "%<hint%> expression must be integral");
10066 9 : remove = true;
10067 : }
10068 : else
10069 : {
10070 219 : t = mark_rvalue_use (t);
10071 219 : if (!processing_template_decl)
10072 : {
10073 171 : t = maybe_constant_value (t);
10074 171 : if (TREE_CODE (t) != INTEGER_CST)
10075 : {
10076 16 : error_at (OMP_CLAUSE_LOCATION (c),
10077 : "%<hint%> expression must be constant integer "
10078 : "expression");
10079 16 : remove = true;
10080 : }
10081 : }
10082 219 : OMP_CLAUSE_HINT_EXPR (c) = t;
10083 : }
10084 : break;
10085 :
10086 186 : case OMP_CLAUSE_FILTER:
10087 186 : t = OMP_CLAUSE_FILTER_EXPR (c);
10088 186 : if (t == error_mark_node)
10089 : remove = true;
10090 186 : else if (!type_dependent_expression_p (t)
10091 186 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10092 : {
10093 6 : error_at (OMP_CLAUSE_LOCATION (c),
10094 : "%<filter%> expression must be integral");
10095 6 : remove = true;
10096 : }
10097 : else
10098 : {
10099 180 : t = mark_rvalue_use (t);
10100 180 : if (!processing_template_decl)
10101 : {
10102 177 : t = maybe_constant_value (t);
10103 177 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
10104 : }
10105 180 : OMP_CLAUSE_FILTER_EXPR (c) = t;
10106 : }
10107 : break;
10108 :
10109 433 : case OMP_CLAUSE_IS_DEVICE_PTR:
10110 433 : case OMP_CLAUSE_USE_DEVICE_PTR:
10111 433 : field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
10112 433 : t = OMP_CLAUSE_DECL (c);
10113 433 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
10114 329 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
10115 433 : if (!type_dependent_expression_p (t))
10116 : {
10117 431 : tree type = TREE_TYPE (t);
10118 431 : if (!TYPE_PTR_P (type)
10119 431 : && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
10120 : {
10121 57 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
10122 57 : && ort == C_ORT_OMP)
10123 : {
10124 3 : error_at (OMP_CLAUSE_LOCATION (c),
10125 : "%qs variable is neither a pointer "
10126 : "nor reference to pointer",
10127 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10128 3 : remove = true;
10129 : }
10130 54 : else if (TREE_CODE (type) != ARRAY_TYPE
10131 54 : && (!TYPE_REF_P (type)
10132 2 : || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
10133 : {
10134 12 : error_at (OMP_CLAUSE_LOCATION (c),
10135 : "%qs variable is neither a pointer, nor an "
10136 : "array nor reference to pointer or array",
10137 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10138 12 : remove = true;
10139 : }
10140 : }
10141 : }
10142 433 : goto check_dup_generic;
10143 :
10144 267 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
10145 267 : t = OMP_CLAUSE_DECL (c);
10146 267 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10147 : {
10148 28 : if (handle_omp_array_sections (c, ort))
10149 : remove = true;
10150 : else
10151 : {
10152 28 : t = OMP_CLAUSE_DECL (c);
10153 30 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10154 2 : t = TREE_OPERAND (t, 0);
10155 64 : while (INDIRECT_REF_P (t)
10156 64 : || TREE_CODE (t) == ARRAY_REF)
10157 36 : t = TREE_OPERAND (t, 0);
10158 : }
10159 : }
10160 267 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
10161 : {
10162 267 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
10163 267 : if (!processing_template_decl
10164 267 : && !cxx_mark_addressable (t))
10165 : remove = true;
10166 : }
10167 267 : goto check_dup_generic_t;
10168 :
10169 76 : case OMP_CLAUSE_USE_DEVICE_ADDR:
10170 76 : field_ok = true;
10171 76 : t = OMP_CLAUSE_DECL (c);
10172 76 : if (!processing_template_decl
10173 74 : && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
10174 74 : && !TYPE_REF_P (TREE_TYPE (t))
10175 143 : && !cxx_mark_addressable (t))
10176 : remove = true;
10177 76 : goto check_dup_generic;
10178 :
10179 : case OMP_CLAUSE_NOWAIT:
10180 : case OMP_CLAUSE_DEFAULT:
10181 : case OMP_CLAUSE_UNTIED:
10182 : case OMP_CLAUSE_COLLAPSE:
10183 : case OMP_CLAUSE_PARALLEL:
10184 : case OMP_CLAUSE_FOR:
10185 : case OMP_CLAUSE_SECTIONS:
10186 : case OMP_CLAUSE_TASKGROUP:
10187 : case OMP_CLAUSE_PROC_BIND:
10188 : case OMP_CLAUSE_DEVICE_TYPE:
10189 : case OMP_CLAUSE_NOGROUP:
10190 : case OMP_CLAUSE_THREADS:
10191 : case OMP_CLAUSE_SIMD:
10192 : case OMP_CLAUSE_DEFAULTMAP:
10193 : case OMP_CLAUSE_BIND:
10194 : case OMP_CLAUSE_AUTO:
10195 : case OMP_CLAUSE_INDEPENDENT:
10196 : case OMP_CLAUSE_SEQ:
10197 : case OMP_CLAUSE_IF_PRESENT:
10198 : case OMP_CLAUSE_FINALIZE:
10199 : case OMP_CLAUSE_NOHOST:
10200 : case OMP_CLAUSE_INDIRECT:
10201 : break;
10202 :
10203 231 : case OMP_CLAUSE_MERGEABLE:
10204 231 : mergeable_seen = true;
10205 231 : break;
10206 :
10207 322 : case OMP_CLAUSE_TILE:
10208 754 : for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
10209 432 : list = TREE_CHAIN (list))
10210 : {
10211 432 : t = TREE_VALUE (list);
10212 :
10213 432 : if (t == error_mark_node)
10214 : remove = true;
10215 403 : else if (!type_dependent_expression_p (t)
10216 403 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10217 : {
10218 3 : error_at (OMP_CLAUSE_LOCATION (c),
10219 : "%<tile%> argument needs integral type");
10220 3 : remove = true;
10221 : }
10222 : else
10223 : {
10224 400 : t = mark_rvalue_use (t);
10225 400 : if (!processing_template_decl)
10226 : {
10227 : /* Zero is used to indicate '*', we permit you
10228 : to get there via an ICE of value zero. */
10229 385 : t = maybe_constant_value (t);
10230 385 : if (!tree_fits_shwi_p (t)
10231 369 : || tree_to_shwi (t) < 0)
10232 : {
10233 40 : error_at (OMP_CLAUSE_LOCATION (c),
10234 : "%<tile%> argument needs positive "
10235 : "integral constant");
10236 40 : remove = true;
10237 : }
10238 : }
10239 : }
10240 :
10241 : /* Update list item. */
10242 432 : TREE_VALUE (list) = t;
10243 : }
10244 : break;
10245 :
10246 1027 : case OMP_CLAUSE_SIZES:
10247 1027 : for (tree list = OMP_CLAUSE_SIZES_LIST (c);
10248 2688 : !remove && list; list = TREE_CHAIN (list))
10249 : {
10250 1661 : t = TREE_VALUE (list);
10251 :
10252 1661 : if (t == error_mark_node)
10253 0 : t = integer_one_node;
10254 1661 : else if (!type_dependent_expression_p (t)
10255 1661 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10256 : {
10257 8 : error_at (OMP_CLAUSE_LOCATION (c),
10258 : "%<sizes%> argument needs positive integral "
10259 : "constant");
10260 8 : t = integer_one_node;
10261 : }
10262 : else
10263 : {
10264 1653 : t = mark_rvalue_use (t);
10265 1653 : if (!processing_template_decl)
10266 : {
10267 1636 : t = maybe_constant_value (t);
10268 1636 : HOST_WIDE_INT n;
10269 1636 : if (!tree_fits_shwi_p (t)
10270 1632 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
10271 1632 : || (n = tree_to_shwi (t)) <= 0
10272 3240 : || (int)n != n)
10273 : {
10274 32 : error_at (OMP_CLAUSE_LOCATION (c),
10275 : "%<sizes%> argument needs positive "
10276 : "integral constant");
10277 32 : t = integer_one_node;
10278 : }
10279 : }
10280 : }
10281 :
10282 : /* Update list item. */
10283 1661 : TREE_VALUE (list) = t;
10284 : }
10285 : break;
10286 :
10287 630 : case OMP_CLAUSE_ORDERED:
10288 630 : ordered_seen = true;
10289 630 : break;
10290 :
10291 1549 : case OMP_CLAUSE_ORDER:
10292 1549 : if (order_seen)
10293 : remove = true;
10294 : else
10295 : order_seen = true;
10296 : break;
10297 :
10298 638 : case OMP_CLAUSE_INBRANCH:
10299 638 : case OMP_CLAUSE_NOTINBRANCH:
10300 638 : if (branch_seen)
10301 : {
10302 3 : error_at (OMP_CLAUSE_LOCATION (c),
10303 : "%<inbranch%> clause is incompatible with "
10304 : "%<notinbranch%>");
10305 3 : remove = true;
10306 : }
10307 : branch_seen = true;
10308 : break;
10309 :
10310 306 : case OMP_CLAUSE_INCLUSIVE:
10311 306 : case OMP_CLAUSE_EXCLUSIVE:
10312 306 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10313 306 : if (!t)
10314 306 : t = OMP_CLAUSE_DECL (c);
10315 306 : if (t == current_class_ptr)
10316 : {
10317 0 : error_at (OMP_CLAUSE_LOCATION (c),
10318 : "%<this%> allowed in OpenMP only in %<declare simd%>"
10319 : " clauses");
10320 0 : remove = true;
10321 0 : break;
10322 : }
10323 306 : if (!VAR_P (t)
10324 : && TREE_CODE (t) != PARM_DECL
10325 : && TREE_CODE (t) != FIELD_DECL)
10326 : {
10327 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
10328 : break;
10329 0 : if (DECL_P (t))
10330 0 : error_at (OMP_CLAUSE_LOCATION (c),
10331 : "%qD is not a variable in clause %qs", t,
10332 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10333 : else
10334 0 : error_at (OMP_CLAUSE_LOCATION (c),
10335 : "%qE is not a variable in clause %qs", t,
10336 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10337 : remove = true;
10338 : }
10339 : break;
10340 :
10341 : case OMP_CLAUSE_FULL:
10342 : break;
10343 :
10344 470 : case OMP_CLAUSE_PARTIAL:
10345 470 : partial_seen = true;
10346 470 : t = OMP_CLAUSE_PARTIAL_EXPR (c);
10347 470 : if (!t)
10348 : break;
10349 :
10350 313 : if (t == error_mark_node)
10351 : t = NULL_TREE;
10352 313 : else if (!type_dependent_expression_p (t)
10353 313 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10354 : {
10355 3 : error_at (OMP_CLAUSE_LOCATION (c),
10356 : "%<partial%> argument needs positive constant "
10357 : "integer expression");
10358 3 : t = NULL_TREE;
10359 : }
10360 : else
10361 : {
10362 310 : t = mark_rvalue_use (t);
10363 310 : if (!processing_template_decl)
10364 : {
10365 292 : t = maybe_constant_value (t);
10366 :
10367 292 : HOST_WIDE_INT n;
10368 584 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
10369 292 : || !tree_fits_shwi_p (t)
10370 286 : || (n = tree_to_shwi (t)) <= 0
10371 560 : || (int)n != n)
10372 : {
10373 24 : error_at (OMP_CLAUSE_LOCATION (c),
10374 : "%<partial%> argument needs positive "
10375 : "constant integer expression");
10376 24 : t = NULL_TREE;
10377 : }
10378 : }
10379 : }
10380 :
10381 313 : OMP_CLAUSE_PARTIAL_EXPR (c) = t;
10382 313 : break;
10383 549 : case OMP_CLAUSE_INIT:
10384 549 : init_seen = true;
10385 549 : OMP_CLAUSE_INIT_PREFER_TYPE (c)
10386 549 : = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
10387 549 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
10388 271 : init_no_targetsync_clause = c;
10389 : /* FALLTHRU */
10390 844 : case OMP_CLAUSE_DESTROY:
10391 844 : case OMP_CLAUSE_USE:
10392 844 : init_use_destroy_seen = true;
10393 844 : t = OMP_CLAUSE_DECL (c);
10394 844 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
10395 : {
10396 9 : error_at (OMP_CLAUSE_LOCATION (c),
10397 : "%qD appears more than once in action clauses", t);
10398 9 : remove = true;
10399 9 : break;
10400 : }
10401 835 : bitmap_set_bit (&generic_head, DECL_UID (t));
10402 : /* FALLTHRU */
10403 1099 : case OMP_CLAUSE_INTEROP:
10404 1099 : if (!processing_template_decl)
10405 : {
10406 1003 : if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
10407 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) && */
10408 1003 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
10409 : {
10410 126 : error_at (OMP_CLAUSE_LOCATION (c),
10411 : "%qD must be of %<omp_interop_t%>",
10412 63 : OMP_CLAUSE_DECL (c));
10413 63 : remove = true;
10414 : }
10415 940 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
10416 481 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
10417 1058 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
10418 : {
10419 36 : error_at (OMP_CLAUSE_LOCATION (c),
10420 18 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
10421 18 : remove = true;
10422 : }
10423 : }
10424 1099 : pc = &OMP_CLAUSE_CHAIN (c);
10425 1099 : break;
10426 0 : default:
10427 0 : gcc_unreachable ();
10428 55 : }
10429 :
10430 98715 : if (remove)
10431 : {
10432 2733 : if (grp_start_p)
10433 : {
10434 : /* If we found a clause to remove, we want to remove the whole
10435 : expanded group, otherwise gimplify
10436 : (omp_resolve_clause_dependencies) can get confused. */
10437 861 : *grp_start_p = grp_sentinel;
10438 861 : pc = grp_start_p;
10439 861 : grp_start_p = NULL;
10440 : }
10441 : else
10442 1872 : *pc = OMP_CLAUSE_CHAIN (c);
10443 : }
10444 : else
10445 95982 : pc = &OMP_CLAUSE_CHAIN (c);
10446 : }
10447 :
10448 63702 : if (grp_start_p
10449 63702 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
10450 158 : for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
10451 95 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
10452 :
10453 63702 : if (reduction_seen < 0 && (ordered_seen || schedule_seen))
10454 63702 : reduction_seen = -2;
10455 :
10456 160651 : for (pc = &clauses, c = clauses; c ; c = *pc)
10457 : {
10458 96949 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
10459 96949 : bool remove = false;
10460 96949 : bool need_complete_type = false;
10461 96949 : bool need_default_ctor = false;
10462 96949 : bool need_copy_ctor = false;
10463 96949 : bool need_copy_assignment = false;
10464 96949 : bool need_implicitly_determined = false;
10465 96949 : bool need_dtor = false;
10466 96949 : tree type, inner_type;
10467 :
10468 96949 : switch (c_kind)
10469 : {
10470 : case OMP_CLAUSE_SHARED:
10471 : need_implicitly_determined = true;
10472 : break;
10473 2550 : case OMP_CLAUSE_PRIVATE:
10474 2550 : need_complete_type = true;
10475 2550 : need_default_ctor = true;
10476 2550 : need_dtor = true;
10477 2550 : need_implicitly_determined = true;
10478 2550 : break;
10479 3195 : case OMP_CLAUSE_FIRSTPRIVATE:
10480 3195 : need_complete_type = true;
10481 3195 : need_copy_ctor = true;
10482 3195 : need_dtor = true;
10483 3195 : need_implicitly_determined = true;
10484 3195 : break;
10485 2766 : case OMP_CLAUSE_LASTPRIVATE:
10486 2766 : need_complete_type = true;
10487 2766 : need_copy_assignment = true;
10488 2766 : need_implicitly_determined = true;
10489 2766 : break;
10490 7506 : case OMP_CLAUSE_REDUCTION:
10491 7506 : if (reduction_seen == -2)
10492 27 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
10493 7506 : if (OMP_CLAUSE_REDUCTION_INSCAN (c))
10494 436 : need_copy_assignment = true;
10495 : need_implicitly_determined = true;
10496 : break;
10497 : case OMP_CLAUSE_IN_REDUCTION:
10498 : case OMP_CLAUSE_TASK_REDUCTION:
10499 : case OMP_CLAUSE_INCLUSIVE:
10500 : case OMP_CLAUSE_EXCLUSIVE:
10501 : need_implicitly_determined = true;
10502 : break;
10503 1550 : case OMP_CLAUSE_LINEAR:
10504 1550 : if (ort != C_ORT_OMP_DECLARE_SIMD)
10505 : need_implicitly_determined = true;
10506 679 : else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
10507 721 : && !bitmap_bit_p (&map_head,
10508 42 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
10509 : {
10510 6 : error_at (OMP_CLAUSE_LOCATION (c),
10511 : "%<linear%> clause step is a parameter %qD not "
10512 : "specified in %<uniform%> clause",
10513 6 : OMP_CLAUSE_LINEAR_STEP (c));
10514 6 : *pc = OMP_CLAUSE_CHAIN (c);
10515 75157 : continue;
10516 : }
10517 : break;
10518 : case OMP_CLAUSE_COPYPRIVATE:
10519 369 : need_copy_assignment = true;
10520 : break;
10521 : case OMP_CLAUSE_COPYIN:
10522 369 : need_copy_assignment = true;
10523 : break;
10524 873 : case OMP_CLAUSE_SIMDLEN:
10525 873 : if (safelen
10526 345 : && !processing_template_decl
10527 1218 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
10528 345 : OMP_CLAUSE_SIMDLEN_EXPR (c)))
10529 : {
10530 : /* Note: How a scaling factor affects this, is underspecified in
10531 : OpenMP; cf. OpenMP spec issue #5160. Presumably, it means:
10532 : savelen >= simdlen * scale_factor
10533 : with
10534 : scale_factor = MAX (1, FLOOR_DIV_EXPR (VL(type), divisor))
10535 : and OpenMP states that VL(type) might be only known at runtime.
10536 : Hence scale_factor >= 1 and, conservatively, assume == 1 for
10537 : this error check. */
10538 0 : error_at (OMP_CLAUSE_LOCATION (c),
10539 : "%<simdlen%> clause value is bigger than "
10540 : "%<safelen%> clause value");
10541 0 : OMP_CLAUSE_SIMDLEN_EXPR (c)
10542 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
10543 : }
10544 873 : pc = &OMP_CLAUSE_CHAIN (c);
10545 873 : continue;
10546 3883 : case OMP_CLAUSE_SCHEDULE:
10547 3883 : if (ordered_seen
10548 3883 : && (OMP_CLAUSE_SCHEDULE_KIND (c)
10549 : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
10550 : {
10551 21 : error_at (OMP_CLAUSE_LOCATION (c),
10552 : "%<nonmonotonic%> schedule modifier specified "
10553 : "together with %<ordered%> clause");
10554 42 : OMP_CLAUSE_SCHEDULE_KIND (c)
10555 21 : = (enum omp_clause_schedule_kind)
10556 21 : (OMP_CLAUSE_SCHEDULE_KIND (c)
10557 : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
10558 : }
10559 3883 : if (reduction_seen == -2)
10560 9 : error_at (OMP_CLAUSE_LOCATION (c),
10561 : "%qs clause specified together with %<inscan%> "
10562 : "%<reduction%> clause", "schedule");
10563 3883 : pc = &OMP_CLAUSE_CHAIN (c);
10564 3883 : continue;
10565 51 : case OMP_CLAUSE_NOGROUP:
10566 51 : if (reduction_seen)
10567 : {
10568 3 : error_at (OMP_CLAUSE_LOCATION (c),
10569 : "%<nogroup%> clause must not be used together with "
10570 : "%<reduction%> clause");
10571 3 : *pc = OMP_CLAUSE_CHAIN (c);
10572 3 : continue;
10573 : }
10574 48 : pc = &OMP_CLAUSE_CHAIN (c);
10575 48 : continue;
10576 165 : case OMP_CLAUSE_GRAINSIZE:
10577 165 : if (num_tasks_seen)
10578 : {
10579 6 : error_at (OMP_CLAUSE_LOCATION (c),
10580 : "%<grainsize%> clause must not be used together with "
10581 : "%<num_tasks%> clause");
10582 6 : *pc = OMP_CLAUSE_CHAIN (c);
10583 6 : continue;
10584 : }
10585 159 : pc = &OMP_CLAUSE_CHAIN (c);
10586 159 : continue;
10587 630 : case OMP_CLAUSE_ORDERED:
10588 630 : if (reduction_seen == -2)
10589 6 : error_at (OMP_CLAUSE_LOCATION (c),
10590 : "%qs clause specified together with %<inscan%> "
10591 : "%<reduction%> clause", "ordered");
10592 630 : pc = &OMP_CLAUSE_CHAIN (c);
10593 630 : continue;
10594 1525 : case OMP_CLAUSE_ORDER:
10595 1525 : if (ordered_seen)
10596 : {
10597 12 : error_at (OMP_CLAUSE_LOCATION (c),
10598 : "%<order%> clause must not be used together "
10599 : "with %<ordered%> clause");
10600 12 : *pc = OMP_CLAUSE_CHAIN (c);
10601 12 : continue;
10602 : }
10603 1513 : pc = &OMP_CLAUSE_CHAIN (c);
10604 1513 : continue;
10605 57 : case OMP_CLAUSE_DETACH:
10606 57 : if (mergeable_seen)
10607 : {
10608 6 : error_at (OMP_CLAUSE_LOCATION (c),
10609 : "%<detach%> clause must not be used together with "
10610 : "%<mergeable%> clause");
10611 6 : *pc = OMP_CLAUSE_CHAIN (c);
10612 6 : continue;
10613 : }
10614 51 : pc = &OMP_CLAUSE_CHAIN (c);
10615 51 : continue;
10616 16107 : case OMP_CLAUSE_MAP:
10617 16107 : if (target_in_reduction_seen && !processing_template_decl)
10618 : {
10619 684 : t = OMP_CLAUSE_DECL (c);
10620 684 : while (handled_component_p (t)
10621 : || INDIRECT_REF_P (t)
10622 : || TREE_CODE (t) == ADDR_EXPR
10623 : || TREE_CODE (t) == MEM_REF
10624 804 : || TREE_CODE (t) == NON_LVALUE_EXPR)
10625 120 : t = TREE_OPERAND (t, 0);
10626 684 : if (DECL_P (t)
10627 684 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
10628 342 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
10629 : }
10630 16107 : pc = &OMP_CLAUSE_CHAIN (c);
10631 16107 : continue;
10632 225 : case OMP_CLAUSE_FULL:
10633 225 : if (partial_seen)
10634 : {
10635 12 : error_at (OMP_CLAUSE_LOCATION (c),
10636 : "%<full%> clause must not be used together "
10637 : "with %<partial%> clause");
10638 12 : *pc = OMP_CLAUSE_CHAIN (c);
10639 12 : continue;
10640 : }
10641 213 : pc = &OMP_CLAUSE_CHAIN (c);
10642 213 : continue;
10643 6953 : case OMP_CLAUSE_NOWAIT:
10644 6953 : if (copyprivate_seen)
10645 : {
10646 6 : error_at (OMP_CLAUSE_LOCATION (c),
10647 : "%<nowait%> clause must not be used together "
10648 : "with %<copyprivate%> clause");
10649 6 : *pc = OMP_CLAUSE_CHAIN (c);
10650 6 : continue;
10651 : }
10652 : /* FALLTHRU */
10653 50949 : default:
10654 50949 : pc = &OMP_CLAUSE_CHAIN (c);
10655 50949 : continue;
10656 : }
10657 :
10658 22472 : t = OMP_CLAUSE_DECL (c);
10659 22472 : switch (c_kind)
10660 : {
10661 2766 : case OMP_CLAUSE_LASTPRIVATE:
10662 2766 : if (DECL_P (t)
10663 2766 : && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
10664 : {
10665 2666 : need_default_ctor = true;
10666 2666 : need_dtor = true;
10667 : }
10668 : break;
10669 :
10670 9669 : case OMP_CLAUSE_REDUCTION:
10671 9669 : case OMP_CLAUSE_IN_REDUCTION:
10672 9669 : case OMP_CLAUSE_TASK_REDUCTION:
10673 9669 : if (allocate_seen)
10674 : {
10675 1711 : if (TREE_CODE (t) == MEM_REF)
10676 : {
10677 222 : t = TREE_OPERAND (t, 0);
10678 222 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
10679 0 : t = TREE_OPERAND (t, 0);
10680 222 : if (TREE_CODE (t) == ADDR_EXPR
10681 168 : || INDIRECT_REF_P (t))
10682 110 : t = TREE_OPERAND (t, 0);
10683 222 : if (DECL_P (t))
10684 222 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10685 : }
10686 1489 : else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10687 : {
10688 288 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10689 144 : t = TREE_OPERAND (t, 0);
10690 144 : if (DECL_P (t))
10691 144 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10692 144 : t = OMP_CLAUSE_DECL (c);
10693 : }
10694 1345 : else if (DECL_P (t))
10695 1345 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10696 1711 : t = OMP_CLAUSE_DECL (c);
10697 : }
10698 9669 : if (processing_template_decl
10699 929 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10700 : break;
10701 9051 : if (finish_omp_reduction_clause (c, &need_default_ctor,
10702 : &need_dtor))
10703 : remove = true;
10704 : else
10705 8967 : t = OMP_CLAUSE_DECL (c);
10706 : break;
10707 :
10708 277 : case OMP_CLAUSE_COPYIN:
10709 277 : if (processing_template_decl
10710 0 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10711 : break;
10712 277 : if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
10713 : {
10714 15 : error_at (OMP_CLAUSE_LOCATION (c),
10715 : "%qE must be %<threadprivate%> for %<copyin%>", t);
10716 15 : remove = true;
10717 : }
10718 : break;
10719 :
10720 : default:
10721 : break;
10722 : }
10723 :
10724 22472 : if (processing_template_decl
10725 1618 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10726 : {
10727 680 : pc = &OMP_CLAUSE_CHAIN (c);
10728 680 : continue;
10729 : }
10730 :
10731 21792 : if (need_complete_type || need_copy_assignment)
10732 : {
10733 9260 : t = require_complete_type (t);
10734 9260 : if (t == error_mark_node)
10735 : remove = true;
10736 9236 : else if (!processing_template_decl
10737 8845 : && TYPE_REF_P (TREE_TYPE (t))
10738 9792 : && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
10739 : remove = true;
10740 : }
10741 21792 : if (need_implicitly_determined)
10742 : {
10743 20751 : const char *share_name = NULL;
10744 :
10745 20751 : if (allocate_seen
10746 5114 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10747 24986 : && DECL_P (t))
10748 3950 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10749 :
10750 20751 : if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
10751 : share_name = "threadprivate";
10752 20709 : else switch (cxx_omp_predetermined_sharing_1 (t))
10753 : {
10754 : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
10755 : break;
10756 47 : case OMP_CLAUSE_DEFAULT_SHARED:
10757 47 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10758 30 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
10759 64 : && c_omp_predefined_variable (t))
10760 : /* The __func__ variable and similar function-local predefined
10761 : variables may be listed in a shared or firstprivate
10762 : clause. */
10763 : break;
10764 31 : if (VAR_P (t)
10765 31 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10766 9 : && TREE_STATIC (t)
10767 40 : && cxx_omp_const_qual_no_mutable (t))
10768 : {
10769 6 : tree ctx = CP_DECL_CONTEXT (t);
10770 : /* const qualified static data members without mutable
10771 : member may be specified in firstprivate clause. */
10772 6 : if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
10773 : break;
10774 : }
10775 : share_name = "shared";
10776 : break;
10777 : case OMP_CLAUSE_DEFAULT_PRIVATE:
10778 : share_name = "private";
10779 : break;
10780 0 : default:
10781 0 : gcc_unreachable ();
10782 : }
10783 : if (share_name)
10784 : {
10785 67 : error_at (OMP_CLAUSE_LOCATION (c),
10786 : "%qE is predetermined %qs for %qs",
10787 : omp_clause_printable_decl (t), share_name,
10788 67 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10789 67 : remove = true;
10790 : }
10791 20684 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10792 18625 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
10793 36143 : && cxx_omp_const_qual_no_mutable (t))
10794 : {
10795 126 : error_at (OMP_CLAUSE_LOCATION (c),
10796 : "%<const%> qualified %qE without %<mutable%> member "
10797 : "may appear only in %<shared%> or %<firstprivate%> "
10798 : "clauses", omp_clause_printable_decl (t));
10799 63 : remove = true;
10800 : }
10801 : }
10802 :
10803 21792 : if (detach_seen
10804 16 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10805 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
10806 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10807 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
10808 21808 : && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
10809 : {
10810 6 : error_at (OMP_CLAUSE_LOCATION (c),
10811 : "the event handle of a %<detach%> clause "
10812 : "should not be in a data-sharing clause");
10813 6 : remove = true;
10814 : }
10815 :
10816 : /* We're interested in the base element, not arrays. */
10817 21792 : inner_type = type = TREE_TYPE (t);
10818 21792 : if ((need_complete_type
10819 : || need_copy_assignment
10820 12532 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
10821 5741 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
10822 4244 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
10823 30407 : && TYPE_REF_P (inner_type))
10824 931 : inner_type = TREE_TYPE (inner_type);
10825 24483 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
10826 2691 : inner_type = TREE_TYPE (inner_type);
10827 :
10828 : /* Check for special function availability by building a call to one.
10829 : Save the results, because later we won't be in the right context
10830 : for making these queries. */
10831 2430 : if (CLASS_TYPE_P (inner_type)
10832 2430 : && COMPLETE_TYPE_P (inner_type)
10833 2361 : && (need_default_ctor || need_copy_ctor
10834 1108 : || need_copy_assignment || need_dtor)
10835 2037 : && !type_dependent_expression_p (t)
10836 23829 : && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
10837 : need_copy_ctor, need_copy_assignment,
10838 : need_dtor))
10839 : remove = true;
10840 :
10841 21792 : if (!remove
10842 21792 : && c_kind == OMP_CLAUSE_SHARED
10843 2056 : && processing_template_decl)
10844 : {
10845 125 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10846 125 : if (t)
10847 5 : OMP_CLAUSE_DECL (c) = t;
10848 : }
10849 :
10850 21792 : if (remove)
10851 292 : *pc = OMP_CLAUSE_CHAIN (c);
10852 : else
10853 21500 : pc = &OMP_CLAUSE_CHAIN (c);
10854 : }
10855 :
10856 63702 : if (allocate_seen)
10857 17449 : for (pc = &clauses, c = clauses; c ; c = *pc)
10858 : {
10859 14948 : bool remove = false;
10860 14948 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
10861 2764 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
10862 2312 : && DECL_P (OMP_CLAUSE_DECL (c))
10863 17260 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
10864 : {
10865 15 : error_at (OMP_CLAUSE_LOCATION (c),
10866 : "%qD specified in %<allocate%> clause but not in "
10867 15 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
10868 15 : remove = true;
10869 : }
10870 14948 : if (remove)
10871 15 : *pc = OMP_CLAUSE_CHAIN (c);
10872 : else
10873 14933 : pc = &OMP_CLAUSE_CHAIN (c);
10874 : }
10875 :
10876 63702 : if (ort == C_ORT_OMP_INTEROP
10877 63702 : && depend_clause
10878 60 : && (!init_use_destroy_seen
10879 57 : || (init_seen && init_no_targetsync_clause)))
10880 : {
10881 9 : auto_diagnostic_group d;
10882 9 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
10883 : "%<depend%> clause requires action clauses with "
10884 : "%<targetsync%> interop-type");
10885 9 : if (init_no_targetsync_clause)
10886 6 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
10887 : "%<init%> clause lacks the %<targetsync%> modifier");
10888 9 : }
10889 :
10890 63702 : bitmap_obstack_release (NULL);
10891 63702 : return clauses;
10892 : }
10893 :
10894 : /* Start processing OpenMP clauses that can include any
10895 : privatization clauses for non-static data members. */
10896 :
10897 : tree
10898 49324 : push_omp_privatization_clauses (bool ignore_next)
10899 : {
10900 49324 : if (omp_private_member_ignore_next)
10901 : {
10902 722 : omp_private_member_ignore_next = ignore_next;
10903 722 : return NULL_TREE;
10904 : }
10905 48602 : omp_private_member_ignore_next = ignore_next;
10906 48602 : if (omp_private_member_map)
10907 24 : omp_private_member_vec.safe_push (error_mark_node);
10908 48602 : return push_stmt_list ();
10909 : }
10910 :
10911 : /* Revert remapping of any non-static data members since
10912 : the last push_omp_privatization_clauses () call. */
10913 :
10914 : void
10915 49318 : pop_omp_privatization_clauses (tree stmt)
10916 : {
10917 49318 : if (stmt == NULL_TREE)
10918 : return;
10919 48596 : stmt = pop_stmt_list (stmt);
10920 48596 : if (omp_private_member_map)
10921 : {
10922 1280 : while (!omp_private_member_vec.is_empty ())
10923 : {
10924 850 : tree t = omp_private_member_vec.pop ();
10925 850 : if (t == error_mark_node)
10926 : {
10927 24 : add_stmt (stmt);
10928 24 : return;
10929 : }
10930 826 : bool no_decl_expr = t == integer_zero_node;
10931 826 : if (no_decl_expr)
10932 136 : t = omp_private_member_vec.pop ();
10933 826 : tree *v = omp_private_member_map->get (t);
10934 826 : gcc_assert (v);
10935 826 : if (!no_decl_expr)
10936 690 : add_decl_expr (*v);
10937 826 : omp_private_member_map->remove (t);
10938 : }
10939 860 : delete omp_private_member_map;
10940 430 : omp_private_member_map = NULL;
10941 : }
10942 48572 : add_stmt (stmt);
10943 : }
10944 :
10945 : /* Remember OpenMP privatization clauses mapping and clear it.
10946 : Used for lambdas. */
10947 :
10948 : void
10949 16259573 : save_omp_privatization_clauses (vec<tree> &save)
10950 : {
10951 16259573 : save = vNULL;
10952 16259573 : if (omp_private_member_ignore_next)
10953 2 : save.safe_push (integer_one_node);
10954 16259573 : omp_private_member_ignore_next = false;
10955 16259573 : if (!omp_private_member_map)
10956 : return;
10957 :
10958 0 : while (!omp_private_member_vec.is_empty ())
10959 : {
10960 0 : tree t = omp_private_member_vec.pop ();
10961 0 : if (t == error_mark_node)
10962 : {
10963 0 : save.safe_push (t);
10964 0 : continue;
10965 : }
10966 0 : tree n = t;
10967 0 : if (t == integer_zero_node)
10968 0 : t = omp_private_member_vec.pop ();
10969 0 : tree *v = omp_private_member_map->get (t);
10970 0 : gcc_assert (v);
10971 0 : save.safe_push (*v);
10972 0 : save.safe_push (t);
10973 0 : if (n != t)
10974 0 : save.safe_push (n);
10975 : }
10976 0 : delete omp_private_member_map;
10977 0 : omp_private_member_map = NULL;
10978 : }
10979 :
10980 : /* Restore OpenMP privatization clauses mapping saved by the
10981 : above function. */
10982 :
10983 : void
10984 16259573 : restore_omp_privatization_clauses (vec<tree> &save)
10985 : {
10986 16259573 : gcc_assert (omp_private_member_vec.is_empty ());
10987 16259573 : omp_private_member_ignore_next = false;
10988 16259573 : if (save.is_empty ())
10989 : return;
10990 4 : if (save.length () == 1 && save[0] == integer_one_node)
10991 : {
10992 2 : omp_private_member_ignore_next = true;
10993 2 : save.release ();
10994 2 : return;
10995 : }
10996 :
10997 0 : omp_private_member_map = new hash_map <tree, tree>;
10998 0 : while (!save.is_empty ())
10999 : {
11000 0 : tree t = save.pop ();
11001 0 : tree n = t;
11002 0 : if (t != error_mark_node)
11003 : {
11004 0 : if (t == integer_one_node)
11005 : {
11006 0 : omp_private_member_ignore_next = true;
11007 0 : gcc_assert (save.is_empty ());
11008 0 : break;
11009 : }
11010 0 : if (t == integer_zero_node)
11011 0 : t = save.pop ();
11012 0 : tree &v = omp_private_member_map->get_or_insert (t);
11013 0 : v = save.pop ();
11014 : }
11015 0 : omp_private_member_vec.safe_push (t);
11016 0 : if (n != t)
11017 0 : omp_private_member_vec.safe_push (n);
11018 : }
11019 0 : save.release ();
11020 : }
11021 :
11022 : /* For all variables in the tree_list VARS, mark them as thread local. */
11023 :
11024 : void
11025 244 : finish_omp_threadprivate (tree vars)
11026 : {
11027 244 : tree t;
11028 :
11029 : /* Mark every variable in VARS to be assigned thread local storage. */
11030 521 : for (t = vars; t; t = TREE_CHAIN (t))
11031 : {
11032 277 : tree v = TREE_PURPOSE (t);
11033 277 : location_t loc = EXPR_LOCATION (TREE_VALUE (t));
11034 :
11035 277 : if (error_operand_p (v))
11036 : ;
11037 277 : else if (!VAR_P (v))
11038 6 : error_at (loc, "%<threadprivate%> %qD is not file, namespace "
11039 : "or block scope variable", v);
11040 : /* If V had already been marked threadprivate, it doesn't matter
11041 : whether it had been used prior to this point. */
11042 271 : else if (TREE_USED (v)
11043 271 : && (DECL_LANG_SPECIFIC (v) == NULL
11044 3 : || !CP_DECL_THREADPRIVATE_P (v)))
11045 6 : error_at (loc, "%qE declared %<threadprivate%> after first use", v);
11046 265 : else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
11047 6 : error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
11048 259 : else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
11049 3 : error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
11050 207 : else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
11051 279 : && CP_DECL_CONTEXT (v) != current_class_type)
11052 6 : error_at (loc, "%<threadprivate%> %qE directive not "
11053 6 : "in %qT definition", v, CP_DECL_CONTEXT (v));
11054 : else
11055 : {
11056 : /* Allocate a LANG_SPECIFIC structure for V, if needed. */
11057 250 : if (DECL_LANG_SPECIFIC (v) == NULL)
11058 206 : retrofit_lang_decl (v);
11059 :
11060 250 : if (! CP_DECL_THREAD_LOCAL_P (v))
11061 : {
11062 250 : CP_DECL_THREAD_LOCAL_P (v) = true;
11063 250 : set_decl_tls_model (v, decl_default_tls_model (v));
11064 : /* If rtl has been already set for this var, call
11065 : make_decl_rtl once again, so that encode_section_info
11066 : has a chance to look at the new decl flags. */
11067 250 : if (DECL_RTL_SET_P (v))
11068 0 : make_decl_rtl (v);
11069 : }
11070 250 : CP_DECL_THREADPRIVATE_P (v) = 1;
11071 : }
11072 : }
11073 244 : }
11074 :
11075 : /* Build an OpenMP structured block. */
11076 :
11077 : tree
11078 64846 : begin_omp_structured_block (void)
11079 : {
11080 64846 : return do_pushlevel (sk_omp);
11081 : }
11082 :
11083 : tree
11084 64831 : finish_omp_structured_block (tree block)
11085 : {
11086 64831 : return do_poplevel (block);
11087 : }
11088 :
11089 : /* Similarly, except force the retention of the BLOCK. */
11090 :
11091 : tree
11092 14990 : begin_omp_parallel (void)
11093 : {
11094 14990 : keep_next_level (true);
11095 14990 : return begin_omp_structured_block ();
11096 : }
11097 :
11098 : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
11099 : statement. */
11100 :
11101 : tree
11102 768 : finish_oacc_data (tree clauses, tree block)
11103 : {
11104 768 : tree stmt;
11105 :
11106 768 : block = finish_omp_structured_block (block);
11107 :
11108 768 : stmt = make_node (OACC_DATA);
11109 768 : TREE_TYPE (stmt) = void_type_node;
11110 768 : OACC_DATA_CLAUSES (stmt) = clauses;
11111 768 : OACC_DATA_BODY (stmt) = block;
11112 :
11113 768 : return add_stmt (stmt);
11114 : }
11115 :
11116 : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
11117 : statement. */
11118 :
11119 : tree
11120 55 : finish_oacc_host_data (tree clauses, tree block)
11121 : {
11122 55 : tree stmt;
11123 :
11124 55 : block = finish_omp_structured_block (block);
11125 :
11126 55 : stmt = make_node (OACC_HOST_DATA);
11127 55 : TREE_TYPE (stmt) = void_type_node;
11128 55 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
11129 55 : OACC_HOST_DATA_BODY (stmt) = block;
11130 :
11131 55 : return add_stmt (stmt);
11132 : }
11133 :
11134 : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
11135 : statement. */
11136 :
11137 : tree
11138 4689 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
11139 : {
11140 4689 : body = finish_omp_structured_block (body);
11141 :
11142 4689 : tree stmt = make_node (code);
11143 4689 : TREE_TYPE (stmt) = void_type_node;
11144 4689 : OMP_BODY (stmt) = body;
11145 4689 : OMP_CLAUSES (stmt) = clauses;
11146 :
11147 4689 : return add_stmt (stmt);
11148 : }
11149 :
11150 : /* Used to walk OpenMP target directive body. */
11151 :
11152 : struct omp_target_walk_data
11153 : {
11154 : /* Holds the 'this' expression found in current function. */
11155 : tree current_object;
11156 :
11157 : /* True if the 'this' expression was accessed in the target body. */
11158 : bool this_expr_accessed;
11159 :
11160 : /* For non-static functions, record which pointer-typed members were
11161 : accessed, and the whole expression. */
11162 : hash_map<tree, tree> ptr_members_accessed;
11163 :
11164 : /* Record which lambda objects were accessed in target body. */
11165 : hash_set<tree> lambda_objects_accessed;
11166 :
11167 : /* For lambda functions, the __closure object expression of the current
11168 : function, and the set of captured variables accessed in target body. */
11169 : tree current_closure;
11170 : hash_set<tree> closure_vars_accessed;
11171 :
11172 : /* Local variables declared inside a BIND_EXPR, used to filter out such
11173 : variables when recording lambda_objects_accessed. */
11174 : hash_set<tree> local_decls;
11175 :
11176 : omp_mapper_list<tree> *mappers;
11177 : };
11178 :
11179 : /* Helper function of finish_omp_target_clauses, called via
11180 : cp_walk_tree_without_duplicates. Traverse body of OpenMP target
11181 : directive *TP, and fill out omp_target_walk_data passed in *PTR. */
11182 :
11183 : static tree
11184 230826 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
11185 : {
11186 230826 : tree t = *tp;
11187 230826 : struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
11188 230826 : tree current_object = data->current_object;
11189 230826 : tree current_closure = data->current_closure;
11190 230826 : omp_mapper_list<tree> *mlist = data->mappers;
11191 :
11192 : /* References inside of these expression codes shouldn't incur any
11193 : form of mapping, so return early. */
11194 230826 : if (TREE_CODE (t) == SIZEOF_EXPR
11195 230818 : || TREE_CODE (t) == ALIGNOF_EXPR)
11196 : {
11197 8 : *walk_subtrees = 0;
11198 8 : return NULL_TREE;
11199 : }
11200 :
11201 230818 : if (TREE_CODE (t) == OMP_CLAUSE)
11202 : return NULL_TREE;
11203 :
11204 218216 : if (!processing_template_decl)
11205 : {
11206 218216 : tree aggr_type = NULL_TREE;
11207 :
11208 218216 : if (TREE_CODE (t) == COMPONENT_REF
11209 218216 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
11210 2280 : aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
11211 215936 : else if ((TREE_CODE (t) == VAR_DECL
11212 : || TREE_CODE (t) == PARM_DECL
11213 : || TREE_CODE (t) == RESULT_DECL)
11214 17121 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
11215 1250 : aggr_type = TREE_TYPE (t);
11216 :
11217 3530 : if (aggr_type)
11218 : {
11219 3530 : tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
11220 3530 : if (mapper_fn)
11221 199 : mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
11222 : }
11223 : }
11224 :
11225 218216 : if (current_object)
11226 : {
11227 2565 : tree this_expr = TREE_OPERAND (current_object, 0);
11228 :
11229 2565 : if (operand_equal_p (t, this_expr))
11230 : {
11231 35 : data->this_expr_accessed = true;
11232 35 : *walk_subtrees = 0;
11233 35 : return NULL_TREE;
11234 : }
11235 :
11236 2530 : if (TREE_CODE (t) == COMPONENT_REF
11237 115 : && POINTER_TYPE_P (TREE_TYPE (t))
11238 36 : && operand_equal_p (TREE_OPERAND (t, 0), current_object)
11239 2564 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
11240 : {
11241 34 : data->this_expr_accessed = true;
11242 34 : tree fld = TREE_OPERAND (t, 1);
11243 34 : if (data->ptr_members_accessed.get (fld) == NULL)
11244 : {
11245 14 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
11246 4 : t = convert_from_reference (t);
11247 14 : data->ptr_members_accessed.put (fld, t);
11248 : }
11249 34 : *walk_subtrees = 0;
11250 34 : return NULL_TREE;
11251 : }
11252 : }
11253 :
11254 : /* When the current_function_decl is a lambda function, the closure object
11255 : argument's type seems to not yet have fields laid out, so a recording
11256 : of DECL_VALUE_EXPRs during the target body walk seems the only way to
11257 : find them. */
11258 218147 : if (current_closure
11259 301 : && (VAR_P (t)
11260 : || TREE_CODE (t) == PARM_DECL
11261 : || TREE_CODE (t) == RESULT_DECL)
11262 24 : && DECL_HAS_VALUE_EXPR_P (t)
11263 10 : && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
11264 218157 : && operand_equal_p (current_closure,
11265 10 : TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
11266 : {
11267 9 : if (!data->closure_vars_accessed.contains (t))
11268 9 : data->closure_vars_accessed.add (t);
11269 9 : *walk_subtrees = 0;
11270 9 : return NULL_TREE;
11271 : }
11272 :
11273 218138 : if (TREE_CODE (t) == BIND_EXPR)
11274 : {
11275 20124 : if (tree block = BIND_EXPR_BLOCK (t))
11276 22632 : for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
11277 2512 : if ((VAR_P (var)
11278 : || TREE_CODE (var) == PARM_DECL
11279 : || TREE_CODE (var) == RESULT_DECL)
11280 2472 : && !data->local_decls.contains (var))
11281 2472 : data->local_decls.add (var);
11282 : return NULL_TREE;
11283 : }
11284 :
11285 : /* Note, this really should be done during gimplification using
11286 : a target hook instead, as a magic declare mapper for the lambda
11287 : types. */
11288 198014 : if (tree lt = TREE_TYPE (t))
11289 191374 : if (LAMBDA_TYPE_P (lt))
11290 : {
11291 118 : gcc_assert (CLASS_TYPE_P (lt));
11292 :
11293 118 : if (location_wrapper_p (t))
11294 : /* The wrapped DECL gets handled when walking its operand. */
11295 0 : return NULL_TREE;
11296 :
11297 118 : if (TREE_CODE (t) == TARGET_EXPR
11298 118 : && !data->local_decls.contains (TARGET_EXPR_SLOT (t)))
11299 21 : data->local_decls.add (TARGET_EXPR_SLOT (t));
11300 :
11301 118 : tree b = t;
11302 118 : while (TREE_CODE (b) == COMPONENT_REF
11303 : /* Note, this isn't fully correct. We can handle it
11304 : this way for constant index, or when it is e.g.
11305 : a value of firstprivatized variable, but we can't
11306 : do that if something in the index expression is
11307 : local to the target region. */
11308 143 : || TREE_CODE (b) == ARRAY_REF)
11309 25 : b = TREE_OPERAND (b, 0);
11310 118 : STRIP_ANY_LOCATION_WRAPPER (b);
11311 118 : if ((VAR_P (b)
11312 : || TREE_CODE (b) == PARM_DECL
11313 : || TREE_CODE (b) == RESULT_DECL)
11314 48 : && !data->lambda_objects_accessed.contains (t)
11315 : /* Do not prepare to create target maps for locally declared
11316 : lambdas or anonymous ones. */
11317 48 : && !data->local_decls.contains (b))
11318 18 : data->lambda_objects_accessed.add (t);
11319 : }
11320 :
11321 : return NULL_TREE;
11322 : }
11323 :
11324 : /* Helper function for finish_omp_target, and also from tsubst_expr.
11325 : Create additional clauses for mapping of non-static members, lambda objects,
11326 : etc. */
11327 :
11328 : void
11329 6997 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
11330 : {
11331 6997 : omp_target_walk_data data;
11332 6997 : data.this_expr_accessed = false;
11333 6997 : data.current_object = NULL_TREE;
11334 :
11335 6997 : if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
11336 96 : if (tree ct = current_nonlambda_class_type ())
11337 : {
11338 95 : tree object = maybe_dummy_object (ct, NULL);
11339 95 : object = maybe_resolve_dummy (object, true);
11340 95 : data.current_object = object;
11341 : }
11342 :
11343 6997 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11344 : {
11345 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11346 8 : data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11347 : }
11348 : else
11349 : data.current_closure = NULL_TREE;
11350 :
11351 6997 : auto_vec<tree, 16> new_clauses;
11352 :
11353 6997 : if (!processing_template_decl)
11354 : {
11355 6997 : hash_set<omp_name_type<tree> > seen_types;
11356 6997 : auto_vec<tree> mapper_fns;
11357 6997 : omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
11358 6997 : data.mappers = &mlist;
11359 :
11360 6997 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11361 : &data);
11362 :
11363 6997 : unsigned int i;
11364 6997 : tree mapper_fn;
11365 14087 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11366 93 : c_omp_find_nested_mappers (&mlist, mapper_fn);
11367 :
11368 7160 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11369 : {
11370 93 : tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
11371 93 : if (mapper == error_mark_node)
11372 0 : continue;
11373 93 : tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
11374 93 : tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
11375 93 : if (BASELINK_P (mapper_fn))
11376 0 : mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
11377 :
11378 93 : tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
11379 93 : OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
11380 93 : OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
11381 93 : OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
11382 :
11383 93 : new_clauses.safe_push (c);
11384 : }
11385 6997 : }
11386 : else
11387 : {
11388 0 : data.mappers = NULL;
11389 0 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11390 : &data);
11391 : }
11392 :
11393 6997 : tree omp_target_this_expr = NULL_TREE;
11394 6997 : tree *explicit_this_deref_map = NULL;
11395 6997 : if (data.this_expr_accessed)
11396 : {
11397 31 : omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
11398 :
11399 : /* See if explicit user-specified map(this[:]) clause already exists.
11400 : If not, we create an implicit map(tofrom:this[:1]) clause. */
11401 80 : for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
11402 50 : if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
11403 47 : && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
11404 40 : || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
11405 57 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
11406 : omp_target_this_expr))
11407 : {
11408 : explicit_this_deref_map = cp;
11409 : break;
11410 : }
11411 : }
11412 :
11413 6997 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11414 6997 : && (data.this_expr_accessed
11415 1 : || !data.closure_vars_accessed.is_empty ()))
11416 : {
11417 : /* For lambda functions, we need to first create a copy of the
11418 : __closure object. */
11419 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11420 8 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11421 8 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
11422 8 : OMP_CLAUSE_DECL (c)
11423 8 : = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11424 8 : OMP_CLAUSE_SIZE (c)
11425 8 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
11426 8 : new_clauses.safe_push (c);
11427 :
11428 8 : tree closure_obj = OMP_CLAUSE_DECL (c);
11429 8 : tree closure_type = TREE_TYPE (closure_obj);
11430 :
11431 16 : gcc_assert (LAMBDA_TYPE_P (closure_type)
11432 : && CLASS_TYPE_P (closure_type));
11433 :
11434 8 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11435 8 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
11436 8 : OMP_CLAUSE_DECL (c2) = closure;
11437 8 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11438 8 : new_clauses.safe_push (c2);
11439 : }
11440 :
11441 6997 : if (data.this_expr_accessed)
11442 : {
11443 : /* If the this-expr was accessed, create a map(*this) clause. */
11444 31 : enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11445 31 : if (explicit_this_deref_map)
11446 : {
11447 1 : tree this_map = *explicit_this_deref_map;
11448 1 : tree nc = OMP_CLAUSE_CHAIN (this_map);
11449 2 : gcc_assert (nc != NULL_TREE
11450 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11451 : && (OMP_CLAUSE_MAP_KIND (nc)
11452 : == GOMP_MAP_FIRSTPRIVATE_POINTER));
11453 1 : kind = OMP_CLAUSE_MAP_KIND (this_map);
11454 : /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
11455 : two-map sequence away from the chain. */
11456 1 : *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
11457 : }
11458 31 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11459 31 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11460 31 : OMP_CLAUSE_DECL (c)
11461 31 : = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
11462 31 : OMP_CLAUSE_SIZE (c)
11463 31 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
11464 31 : new_clauses.safe_push (c);
11465 :
11466 : /* If we're in a lambda function, the this-pointer will actually be
11467 : '__closure->this', a mapped member of __closure, hence always_pointer.
11468 : Otherwise it's a firstprivate pointer. */
11469 31 : enum gomp_map_kind ptr_kind
11470 31 : = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11471 31 : ? GOMP_MAP_ALWAYS_POINTER
11472 24 : : GOMP_MAP_FIRSTPRIVATE_POINTER);
11473 31 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11474 31 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11475 31 : OMP_CLAUSE_DECL (c) = omp_target_this_expr;
11476 31 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11477 31 : new_clauses.safe_push (c);
11478 : }
11479 :
11480 6997 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11481 : {
11482 8 : if (omp_target_this_expr)
11483 : {
11484 7 : STRIP_NOPS (omp_target_this_expr);
11485 7 : gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
11486 7 : omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
11487 : }
11488 :
11489 17 : for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
11490 25 : i != data.closure_vars_accessed.end (); ++i)
11491 : {
11492 9 : tree orig_decl = *i;
11493 9 : tree closure_expr = DECL_VALUE_EXPR (orig_decl);
11494 :
11495 9 : if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
11496 9 : || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
11497 : {
11498 : /* this-pointer is processed above, outside this loop. */
11499 3 : if (omp_target_this_expr
11500 3 : && operand_equal_p (closure_expr, omp_target_this_expr))
11501 0 : continue;
11502 :
11503 3 : bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
11504 3 : enum gomp_map_kind kind, ptr_kind, nc_kind;
11505 3 : tree size;
11506 :
11507 3 : if (ptr_p)
11508 : {
11509 : /* For pointers, default mapped as zero-length array
11510 : section. */
11511 2 : kind = GOMP_MAP_ALLOC;
11512 2 : nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
11513 2 : ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
11514 2 : size = size_zero_node;
11515 : }
11516 : else
11517 : {
11518 : /* For references, default mapped as appearing on map
11519 : clause. */
11520 1 : kind = GOMP_MAP_TOFROM;
11521 1 : nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
11522 1 : ptr_kind = GOMP_MAP_ALWAYS_POINTER;
11523 1 : size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
11524 : }
11525 :
11526 6 : for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
11527 3 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
11528 1 : && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
11529 1 : || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
11530 3 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
11531 : orig_decl))
11532 : {
11533 : /* If this was already specified by user as a map,
11534 : save the user specified map kind, delete the
11535 : "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
11536 : and insert our own sequence:
11537 : "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
11538 : */
11539 0 : tree nc = OMP_CLAUSE_CHAIN (*p);
11540 0 : gcc_assert (nc != NULL_TREE
11541 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11542 : && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
11543 : /* Update with user specified kind and size. */
11544 0 : kind = OMP_CLAUSE_MAP_KIND (*p);
11545 0 : size = OMP_CLAUSE_SIZE (*p);
11546 0 : *p = OMP_CLAUSE_CHAIN (nc);
11547 0 : break;
11548 : }
11549 :
11550 3 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11551 3 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11552 3 : OMP_CLAUSE_DECL (c)
11553 3 : = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
11554 3 : OMP_CLAUSE_SIZE (c) = size;
11555 3 : if (ptr_p)
11556 2 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11557 3 : new_clauses.safe_push (c);
11558 :
11559 3 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11560 3 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11561 3 : OMP_CLAUSE_DECL (c) = closure_expr;
11562 3 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11563 3 : new_clauses.safe_push (c);
11564 : }
11565 : }
11566 : }
11567 :
11568 6997 : if (!data.ptr_members_accessed.is_empty ())
11569 14 : for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
11570 42 : i != data.ptr_members_accessed.end (); ++i)
11571 : {
11572 : /* For each referenced member that is of pointer or reference-to-pointer
11573 : type, create the equivalent of map(alloc:this->ptr[:0]). */
11574 14 : tree field_decl = (*i).first;
11575 14 : tree ptr_member = (*i).second;
11576 :
11577 26 : for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
11578 : {
11579 16 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
11580 2 : continue;
11581 : /* If map(this->ptr[:N]) already exists, avoid creating another
11582 : such map. */
11583 14 : tree decl = OMP_CLAUSE_DECL (c);
11584 14 : if ((TREE_CODE (decl) == INDIRECT_REF
11585 10 : || TREE_CODE (decl) == MEM_REF)
11586 14 : && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
11587 4 : goto next_ptr_member;
11588 : }
11589 :
11590 10 : if (!cxx_mark_addressable (ptr_member))
11591 0 : gcc_unreachable ();
11592 :
11593 10 : if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
11594 : {
11595 : /* For reference to pointers, we need to map the referenced
11596 : pointer first for things to be correct. */
11597 4 : tree ptr_member_type = TREE_TYPE (ptr_member);
11598 :
11599 : /* Map pointer target as zero-length array section. */
11600 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11601 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11602 4 : OMP_CLAUSE_DECL (c)
11603 4 : = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
11604 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11605 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11606 :
11607 : /* Map pointer to zero-length array section. */
11608 4 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11609 4 : OMP_CLAUSE_SET_MAP_KIND
11610 : (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
11611 4 : OMP_CLAUSE_DECL (c2) = ptr_member;
11612 4 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11613 :
11614 : /* Attach reference-to-pointer field to pointer. */
11615 4 : tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11616 4 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
11617 4 : OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
11618 4 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
11619 :
11620 4 : new_clauses.safe_push (c);
11621 4 : new_clauses.safe_push (c2);
11622 4 : new_clauses.safe_push (c3);
11623 : }
11624 6 : else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
11625 : {
11626 : /* Map pointer target as zero-length array section. */
11627 6 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11628 6 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11629 6 : OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
11630 : RO_UNARY_STAR);
11631 6 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11632 6 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11633 :
11634 : /* Attach zero-length array section to pointer. */
11635 6 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11636 6 : OMP_CLAUSE_SET_MAP_KIND
11637 : (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11638 6 : OMP_CLAUSE_DECL (c2) = ptr_member;
11639 6 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11640 :
11641 6 : new_clauses.safe_push (c);
11642 6 : new_clauses.safe_push (c2);
11643 : }
11644 : else
11645 0 : gcc_unreachable ();
11646 :
11647 14 : next_ptr_member:
11648 14 : ;
11649 : }
11650 :
11651 7015 : for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
11652 7015 : i != data.lambda_objects_accessed.end (); ++i)
11653 : {
11654 18 : tree lobj = *i;
11655 18 : if (TREE_CODE (lobj) == TARGET_EXPR)
11656 0 : lobj = TARGET_EXPR_SLOT (lobj);
11657 :
11658 18 : tree lt = TREE_TYPE (lobj);
11659 36 : gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
11660 :
11661 18 : tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
11662 18 : OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
11663 18 : OMP_CLAUSE_DECL (lc) = lobj;
11664 18 : OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
11665 18 : new_clauses.safe_push (lc);
11666 :
11667 274 : for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
11668 : {
11669 256 : if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
11670 : {
11671 4 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11672 : lobj, fld, NULL_TREE);
11673 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11674 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11675 4 : OMP_CLAUSE_DECL (c)
11676 4 : = build_indirect_ref (loc, exp, RO_UNARY_STAR);
11677 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11678 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11679 4 : new_clauses.safe_push (c);
11680 :
11681 4 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11682 4 : OMP_CLAUSE_SET_MAP_KIND
11683 : (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11684 4 : OMP_CLAUSE_DECL (c) = exp;
11685 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11686 4 : new_clauses.safe_push (c);
11687 : }
11688 252 : else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
11689 : {
11690 14 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11691 : lobj, fld, NULL_TREE);
11692 14 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11693 14 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
11694 14 : OMP_CLAUSE_DECL (c)
11695 14 : = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
11696 14 : OMP_CLAUSE_SIZE (c)
11697 14 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
11698 14 : new_clauses.safe_push (c);
11699 :
11700 14 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11701 14 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
11702 14 : OMP_CLAUSE_DECL (c) = exp;
11703 14 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11704 14 : new_clauses.safe_push (c);
11705 : }
11706 : }
11707 : }
11708 :
11709 6997 : tree c = *clauses_ptr;
11710 14249 : for (int i = new_clauses.length () - 1; i >= 0; i--)
11711 : {
11712 255 : OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
11713 255 : c = new_clauses[i];
11714 : }
11715 6997 : *clauses_ptr = c;
11716 6997 : }
11717 :
11718 : /* Called from cp_parser_omp_target. Create additional implicit clauses for
11719 : OpenMP target directives, and do sanity checks. */
11720 :
11721 : tree
11722 6987 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
11723 : {
11724 6987 : if (!processing_template_decl)
11725 6178 : finish_omp_target_clauses (loc, body, &clauses);
11726 :
11727 6987 : tree stmt = make_node (OMP_TARGET);
11728 6987 : TREE_TYPE (stmt) = void_type_node;
11729 6987 : OMP_TARGET_CLAUSES (stmt) = clauses;
11730 6987 : OMP_TARGET_BODY (stmt) = body;
11731 6987 : OMP_TARGET_COMBINED (stmt) = combined_p;
11732 6987 : SET_EXPR_LOCATION (stmt, loc);
11733 :
11734 6987 : tree c = clauses;
11735 16831 : while (c)
11736 : {
11737 9844 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
11738 5726 : switch (OMP_CLAUSE_MAP_KIND (c))
11739 : {
11740 : case GOMP_MAP_TO:
11741 : case GOMP_MAP_ALWAYS_TO:
11742 : case GOMP_MAP_PRESENT_TO:
11743 : case GOMP_MAP_ALWAYS_PRESENT_TO:
11744 : case GOMP_MAP_FROM:
11745 : case GOMP_MAP_ALWAYS_FROM:
11746 : case GOMP_MAP_PRESENT_FROM:
11747 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
11748 : case GOMP_MAP_TOFROM:
11749 : case GOMP_MAP_ALWAYS_TOFROM:
11750 : case GOMP_MAP_PRESENT_TOFROM:
11751 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
11752 : case GOMP_MAP_ALLOC:
11753 : case GOMP_MAP_PRESENT_ALLOC:
11754 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
11755 : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
11756 : case GOMP_MAP_ALWAYS_POINTER:
11757 : case GOMP_MAP_ATTACH_DETACH:
11758 : case GOMP_MAP_ATTACH:
11759 : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
11760 : case GOMP_MAP_POINTER:
11761 : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
11762 : break;
11763 3 : default:
11764 3 : error_at (OMP_CLAUSE_LOCATION (c),
11765 : "%<#pragma omp target%> with map-type other "
11766 : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
11767 : "on %<map%> clause");
11768 3 : break;
11769 : }
11770 9844 : c = OMP_CLAUSE_CHAIN (c);
11771 : }
11772 6987 : return add_stmt (stmt);
11773 : }
11774 :
11775 : tree
11776 9478 : finish_omp_parallel (tree clauses, tree body)
11777 : {
11778 9478 : tree stmt;
11779 :
11780 9478 : body = finish_omp_structured_block (body);
11781 :
11782 9478 : stmt = make_node (OMP_PARALLEL);
11783 9478 : TREE_TYPE (stmt) = void_type_node;
11784 9478 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
11785 9478 : OMP_PARALLEL_BODY (stmt) = body;
11786 :
11787 9478 : return add_stmt (stmt);
11788 : }
11789 :
11790 : tree
11791 2418 : begin_omp_task (void)
11792 : {
11793 2418 : keep_next_level (true);
11794 2418 : return begin_omp_structured_block ();
11795 : }
11796 :
11797 : tree
11798 2418 : finish_omp_task (tree clauses, tree body)
11799 : {
11800 2418 : tree stmt;
11801 :
11802 2418 : body = finish_omp_structured_block (body);
11803 :
11804 2418 : stmt = make_node (OMP_TASK);
11805 2418 : TREE_TYPE (stmt) = void_type_node;
11806 2418 : OMP_TASK_CLAUSES (stmt) = clauses;
11807 2418 : OMP_TASK_BODY (stmt) = body;
11808 :
11809 2418 : return add_stmt (stmt);
11810 : }
11811 :
11812 : /* Helper function for finish_omp_for. Convert Ith random access iterator
11813 : into integral iterator. Return FALSE if successful. */
11814 :
11815 : static bool
11816 813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
11817 : tree declv, tree orig_declv, tree initv,
11818 : tree condv, tree incrv, tree *body,
11819 : tree *pre_body, tree &clauses,
11820 : int collapse, int ordered)
11821 : {
11822 813 : tree diff, iter_init, iter_incr = NULL, last;
11823 813 : tree incr_var = NULL, orig_pre_body, orig_body, c;
11824 813 : tree decl = TREE_VEC_ELT (declv, i);
11825 813 : tree init = TREE_VEC_ELT (initv, i);
11826 813 : tree cond = TREE_VEC_ELT (condv, i);
11827 813 : tree incr = TREE_VEC_ELT (incrv, i);
11828 813 : tree iter = decl;
11829 813 : location_t elocus = locus;
11830 :
11831 813 : if (init && EXPR_HAS_LOCATION (init))
11832 12 : elocus = EXPR_LOCATION (init);
11833 :
11834 813 : switch (TREE_CODE (cond))
11835 : {
11836 810 : case GT_EXPR:
11837 810 : case GE_EXPR:
11838 810 : case LT_EXPR:
11839 810 : case LE_EXPR:
11840 810 : case NE_EXPR:
11841 810 : if (TREE_OPERAND (cond, 1) == iter)
11842 42 : cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
11843 42 : TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
11844 810 : if (TREE_OPERAND (cond, 0) != iter)
11845 0 : cond = error_mark_node;
11846 : else
11847 : {
11848 810 : tree tem = build_x_binary_op (EXPR_LOCATION (cond),
11849 810 : TREE_CODE (cond),
11850 : iter, ERROR_MARK,
11851 810 : TREE_OPERAND (cond, 1), ERROR_MARK,
11852 : NULL_TREE, NULL, tf_warning_or_error);
11853 810 : if (error_operand_p (tem))
11854 : return true;
11855 : }
11856 : break;
11857 3 : default:
11858 3 : cond = error_mark_node;
11859 3 : break;
11860 : }
11861 810 : if (cond == error_mark_node)
11862 : {
11863 3 : error_at (elocus, "invalid controlling predicate");
11864 3 : return true;
11865 : }
11866 807 : diff = build_x_binary_op (elocus, MINUS_EXPR,
11867 807 : TREE_OPERAND (cond, 1), ERROR_MARK,
11868 : iter, ERROR_MARK,
11869 : NULL_TREE, NULL, tf_warning_or_error);
11870 807 : diff = cp_fully_fold (diff);
11871 807 : if (error_operand_p (diff))
11872 : return true;
11873 807 : if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
11874 : {
11875 0 : error_at (elocus, "difference between %qE and %qD does not have integer type",
11876 0 : TREE_OPERAND (cond, 1), iter);
11877 0 : return true;
11878 : }
11879 807 : if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
11880 807 : TREE_VEC_ELT (declv, i), NULL_TREE,
11881 : cond, cp_walk_subtrees))
11882 : return true;
11883 :
11884 762 : switch (TREE_CODE (incr))
11885 : {
11886 370 : case PREINCREMENT_EXPR:
11887 370 : case PREDECREMENT_EXPR:
11888 370 : case POSTINCREMENT_EXPR:
11889 370 : case POSTDECREMENT_EXPR:
11890 370 : if (TREE_OPERAND (incr, 0) != iter)
11891 : {
11892 0 : incr = error_mark_node;
11893 0 : break;
11894 : }
11895 370 : iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
11896 370 : TREE_CODE (incr), iter,
11897 : NULL_TREE, tf_warning_or_error);
11898 370 : if (error_operand_p (iter_incr))
11899 : return true;
11900 370 : else if (TREE_CODE (incr) == PREINCREMENT_EXPR
11901 219 : || TREE_CODE (incr) == POSTINCREMENT_EXPR)
11902 299 : incr = integer_one_node;
11903 : else
11904 71 : incr = integer_minus_one_node;
11905 : break;
11906 392 : case MODIFY_EXPR:
11907 392 : if (TREE_OPERAND (incr, 0) != iter)
11908 0 : incr = error_mark_node;
11909 392 : else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
11910 392 : || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
11911 : {
11912 392 : tree rhs = TREE_OPERAND (incr, 1);
11913 392 : if (TREE_OPERAND (rhs, 0) == iter)
11914 : {
11915 299 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
11916 : != INTEGER_TYPE)
11917 0 : incr = error_mark_node;
11918 : else
11919 : {
11920 299 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11921 299 : iter, TREE_CODE (rhs),
11922 299 : TREE_OPERAND (rhs, 1),
11923 : NULL_TREE,
11924 : tf_warning_or_error);
11925 299 : if (error_operand_p (iter_incr))
11926 : return true;
11927 299 : incr = TREE_OPERAND (rhs, 1);
11928 299 : incr = cp_convert (TREE_TYPE (diff), incr,
11929 : tf_warning_or_error);
11930 299 : if (TREE_CODE (rhs) == MINUS_EXPR)
11931 : {
11932 16 : incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
11933 16 : incr = fold_simple (incr);
11934 : }
11935 299 : if (TREE_CODE (incr) != INTEGER_CST
11936 299 : && (TREE_CODE (incr) != NOP_EXPR
11937 66 : || (TREE_CODE (TREE_OPERAND (incr, 0))
11938 : != INTEGER_CST)))
11939 : iter_incr = NULL;
11940 : }
11941 : }
11942 93 : else if (TREE_OPERAND (rhs, 1) == iter)
11943 : {
11944 93 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
11945 93 : || TREE_CODE (rhs) != PLUS_EXPR)
11946 0 : incr = error_mark_node;
11947 : else
11948 : {
11949 93 : iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
11950 : PLUS_EXPR,
11951 93 : TREE_OPERAND (rhs, 0),
11952 : ERROR_MARK, iter,
11953 : ERROR_MARK, NULL_TREE, NULL,
11954 : tf_warning_or_error);
11955 93 : if (error_operand_p (iter_incr))
11956 : return true;
11957 93 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11958 : iter, NOP_EXPR,
11959 : iter_incr, NULL_TREE,
11960 : tf_warning_or_error);
11961 93 : if (error_operand_p (iter_incr))
11962 : return true;
11963 93 : incr = TREE_OPERAND (rhs, 0);
11964 93 : iter_incr = NULL;
11965 : }
11966 : }
11967 : else
11968 0 : incr = error_mark_node;
11969 : }
11970 : else
11971 0 : incr = error_mark_node;
11972 : break;
11973 0 : default:
11974 0 : incr = error_mark_node;
11975 0 : break;
11976 : }
11977 :
11978 762 : if (incr == error_mark_node)
11979 : {
11980 0 : error_at (elocus, "invalid increment expression");
11981 0 : return true;
11982 : }
11983 :
11984 762 : incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
11985 762 : incr = cp_fully_fold (incr);
11986 762 : tree loop_iv_seen = NULL_TREE;
11987 1735 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11988 1093 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
11989 1093 : && OMP_CLAUSE_DECL (c) == iter)
11990 : {
11991 120 : if (code == OMP_TASKLOOP || code == OMP_LOOP)
11992 : {
11993 60 : loop_iv_seen = c;
11994 60 : OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
11995 : }
11996 : break;
11997 : }
11998 973 : else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
11999 113 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
12000 1007 : && OMP_CLAUSE_DECL (c) == iter)
12001 : {
12002 30 : loop_iv_seen = c;
12003 30 : if (code == OMP_TASKLOOP)
12004 25 : OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
12005 : }
12006 :
12007 762 : decl = create_temporary_var (TREE_TYPE (diff));
12008 762 : pushdecl (decl);
12009 762 : add_decl_expr (decl);
12010 762 : last = create_temporary_var (TREE_TYPE (diff));
12011 762 : pushdecl (last);
12012 762 : add_decl_expr (last);
12013 762 : if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
12014 10 : && (!ordered || (i < collapse && collapse > 1)))
12015 : {
12016 10 : incr_var = create_temporary_var (TREE_TYPE (diff));
12017 10 : pushdecl (incr_var);
12018 10 : add_decl_expr (incr_var);
12019 : }
12020 762 : gcc_assert (stmts_are_full_exprs_p ());
12021 762 : tree diffvar = NULL_TREE;
12022 762 : if (code == OMP_TASKLOOP)
12023 : {
12024 101 : if (!loop_iv_seen)
12025 : {
12026 38 : tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
12027 38 : OMP_CLAUSE_DECL (ivc) = iter;
12028 38 : cxx_omp_finish_clause (ivc, NULL, false);
12029 38 : OMP_CLAUSE_CHAIN (ivc) = clauses;
12030 38 : clauses = ivc;
12031 : }
12032 101 : tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
12033 101 : OMP_CLAUSE_DECL (lvc) = last;
12034 101 : OMP_CLAUSE_CHAIN (lvc) = clauses;
12035 101 : clauses = lvc;
12036 101 : diffvar = create_temporary_var (TREE_TYPE (diff));
12037 101 : pushdecl (diffvar);
12038 101 : add_decl_expr (diffvar);
12039 : }
12040 661 : else if (code == OMP_LOOP)
12041 : {
12042 43 : if (!loop_iv_seen)
12043 : {
12044 : /* While iterators on the loop construct are predetermined
12045 : lastprivate, if the decl is not declared inside of the
12046 : loop, OMP_CLAUSE_LASTPRIVATE should have been added
12047 : already. */
12048 16 : loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
12049 16 : OMP_CLAUSE_DECL (loop_iv_seen) = iter;
12050 16 : OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
12051 16 : clauses = loop_iv_seen;
12052 : }
12053 27 : else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
12054 : {
12055 5 : OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
12056 5 : OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
12057 5 : OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
12058 : }
12059 43 : if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
12060 21 : cxx_omp_finish_clause (loop_iv_seen, NULL, false);
12061 : }
12062 :
12063 762 : orig_pre_body = *pre_body;
12064 762 : *pre_body = push_stmt_list ();
12065 762 : if (orig_pre_body)
12066 610 : add_stmt (orig_pre_body);
12067 762 : if (init != NULL)
12068 61 : finish_expr_stmt (build_x_modify_expr (elocus,
12069 : iter, NOP_EXPR, init,
12070 : NULL_TREE, tf_warning_or_error));
12071 762 : init = build_int_cst (TREE_TYPE (diff), 0);
12072 762 : if (c && iter_incr == NULL
12073 28 : && (!ordered || (i < collapse && collapse > 1)))
12074 : {
12075 28 : if (incr_var)
12076 : {
12077 10 : finish_expr_stmt (build_x_modify_expr (elocus,
12078 : incr_var, NOP_EXPR,
12079 : incr, NULL_TREE,
12080 : tf_warning_or_error));
12081 10 : incr = incr_var;
12082 : }
12083 28 : iter_incr = build_x_modify_expr (elocus,
12084 : iter, PLUS_EXPR, incr,
12085 : NULL_TREE, tf_warning_or_error);
12086 : }
12087 762 : if (c && ordered && i < collapse && collapse > 1)
12088 762 : iter_incr = incr;
12089 762 : finish_expr_stmt (build_x_modify_expr (elocus,
12090 : last, NOP_EXPR, init,
12091 : NULL_TREE, tf_warning_or_error));
12092 762 : if (diffvar)
12093 : {
12094 101 : finish_expr_stmt (build_x_modify_expr (elocus,
12095 : diffvar, NOP_EXPR,
12096 : diff, NULL_TREE, tf_warning_or_error));
12097 101 : diff = diffvar;
12098 : }
12099 762 : *pre_body = pop_stmt_list (*pre_body);
12100 :
12101 1524 : cond = cp_build_binary_op (elocus,
12102 762 : TREE_CODE (cond), decl, diff,
12103 : tf_warning_or_error);
12104 762 : incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
12105 : elocus, incr, NULL_TREE);
12106 :
12107 762 : orig_body = *body;
12108 762 : *body = push_stmt_list ();
12109 762 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
12110 762 : iter_init = build_x_modify_expr (elocus,
12111 : iter, PLUS_EXPR, iter_init,
12112 : NULL_TREE, tf_warning_or_error);
12113 762 : if (iter_init != error_mark_node)
12114 759 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
12115 762 : finish_expr_stmt (iter_init);
12116 762 : finish_expr_stmt (build_x_modify_expr (elocus,
12117 : last, NOP_EXPR, decl,
12118 : NULL_TREE, tf_warning_or_error));
12119 762 : add_stmt (orig_body);
12120 762 : *body = pop_stmt_list (*body);
12121 :
12122 762 : if (c)
12123 : {
12124 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
12125 120 : if (!ordered)
12126 114 : finish_expr_stmt (iter_incr);
12127 : else
12128 : {
12129 6 : iter_init = decl;
12130 6 : if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
12131 2 : iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
12132 : iter_init, iter_incr);
12133 6 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
12134 6 : iter_init = build_x_modify_expr (elocus,
12135 : iter, PLUS_EXPR, iter_init,
12136 : NULL_TREE, tf_warning_or_error);
12137 6 : if (iter_init != error_mark_node)
12138 6 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
12139 6 : finish_expr_stmt (iter_init);
12140 : }
12141 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c)
12142 240 : = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
12143 : }
12144 :
12145 762 : if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
12146 : {
12147 116 : tree t = TREE_VEC_ELT (orig_declv, i);
12148 116 : gcc_assert (TREE_PURPOSE (t) == NULL_TREE
12149 : && TREE_VALUE (t) == NULL_TREE
12150 : && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
12151 116 : TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
12152 116 : TREE_VALUE (t) = last;
12153 : }
12154 : else
12155 646 : TREE_VEC_ELT (orig_declv, i)
12156 1292 : = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
12157 762 : TREE_VEC_ELT (declv, i) = decl;
12158 762 : TREE_VEC_ELT (initv, i) = init;
12159 762 : TREE_VEC_ELT (condv, i) = cond;
12160 762 : TREE_VEC_ELT (incrv, i) = incr;
12161 :
12162 762 : return false;
12163 : }
12164 :
12165 : /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
12166 : are directly for their associated operands in the statement. DECL
12167 : and INIT are a combo; if DECL is NULL then INIT ought to be a
12168 : MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
12169 : optional statements that need to go before the loop into its
12170 : sk_omp scope. */
12171 :
12172 : tree
12173 21292 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
12174 : tree orig_declv, tree initv, tree condv, tree incrv,
12175 : tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
12176 : {
12177 21292 : tree omp_for = NULL, orig_incr = NULL;
12178 21292 : tree decl = NULL, init, cond, incr;
12179 21292 : location_t elocus;
12180 21292 : int i;
12181 21292 : int collapse = 1;
12182 21292 : int ordered = 0;
12183 21292 : auto_vec<location_t> init_locv;
12184 :
12185 21292 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
12186 21292 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
12187 21292 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
12188 21292 : if (TREE_VEC_LENGTH (declv) > 1)
12189 : {
12190 4054 : if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
12191 83 : collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
12192 : else
12193 : {
12194 3971 : if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
12195 3501 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
12196 470 : else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
12197 394 : collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
12198 3971 : if (collapse != TREE_VEC_LENGTH (declv))
12199 100 : ordered = TREE_VEC_LENGTH (declv);
12200 : }
12201 : }
12202 48929 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
12203 : {
12204 27673 : decl = TREE_VEC_ELT (declv, i);
12205 27673 : init = TREE_VEC_ELT (initv, i);
12206 27673 : cond = TREE_VEC_ELT (condv, i);
12207 27673 : incr = TREE_VEC_ELT (incrv, i);
12208 27673 : elocus = locus;
12209 :
12210 27673 : if (decl == global_namespace)
12211 : {
12212 1101 : gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
12213 1101 : TREE_VEC_ELT (declv, i) = NULL_TREE;
12214 1101 : init_locv.safe_push (UNKNOWN_LOCATION);
12215 1101 : continue;
12216 : }
12217 : /* We are going to throw out the init's original MODIFY_EXPR or
12218 : MODOP_EXPR below. Save its location so we can use it when
12219 : reconstructing the expression farther down. Alternatively, if the
12220 : initializer is a binding of the iteration variable, save
12221 : that location. Any of these locations in the initialization clause
12222 : for the current nested loop are better than using the argument locus,
12223 : that points to the "for" of the outermost loop in the nest. */
12224 26572 : if (init && EXPR_HAS_LOCATION (init))
12225 17962 : elocus = EXPR_LOCATION (init);
12226 8610 : else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
12227 : /* This can happen for class iterators. */
12228 0 : elocus = EXPR_LOCATION (decl);
12229 8610 : else if (decl && DECL_P (decl))
12230 : {
12231 8583 : if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
12232 8583 : elocus = DECL_SOURCE_LOCATION (decl);
12233 0 : else if (DECL_INITIAL (decl)
12234 0 : && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
12235 0 : elocus = EXPR_LOCATION (DECL_INITIAL (decl));
12236 : }
12237 26572 : init_locv.safe_push (elocus);
12238 :
12239 26572 : if (decl == NULL)
12240 : {
12241 16654 : if (init != NULL)
12242 16651 : switch (TREE_CODE (init))
12243 : {
12244 16244 : case MODIFY_EXPR:
12245 16244 : decl = TREE_OPERAND (init, 0);
12246 16244 : init = TREE_OPERAND (init, 1);
12247 16244 : break;
12248 389 : case MODOP_EXPR:
12249 389 : if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
12250 : {
12251 389 : decl = TREE_OPERAND (init, 0);
12252 389 : init = TREE_OPERAND (init, 2);
12253 : }
12254 : break;
12255 : default:
12256 : break;
12257 : }
12258 :
12259 16654 : if (decl == NULL)
12260 : {
12261 21 : error_at (locus,
12262 : "expected iteration declaration or initialization");
12263 21 : return NULL;
12264 : }
12265 : }
12266 :
12267 26551 : if (cond == global_namespace)
12268 170 : continue;
12269 :
12270 26381 : if (cond == NULL)
12271 : {
12272 9 : error_at (elocus, "missing controlling predicate");
12273 9 : return NULL;
12274 : }
12275 :
12276 26372 : if (incr == NULL)
12277 : {
12278 6 : error_at (elocus, "missing increment expression");
12279 6 : return NULL;
12280 : }
12281 :
12282 26366 : TREE_VEC_ELT (declv, i) = decl;
12283 26366 : TREE_VEC_ELT (initv, i) = init;
12284 : }
12285 :
12286 21256 : if (orig_inits)
12287 : {
12288 : bool fail = false;
12289 : tree orig_init;
12290 21356 : FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
12291 1181 : if (orig_init
12292 3396 : && !c_omp_check_loop_iv_exprs (locus, code,
12293 : orig_declv ? orig_declv : declv, i,
12294 1164 : TREE_VEC_ELT (declv, i), orig_init,
12295 : NULL_TREE, cp_walk_subtrees))
12296 : fail = true;
12297 20175 : if (fail)
12298 21292 : return NULL;
12299 : }
12300 :
12301 21199 : if (dependent_omp_for_p (declv, initv, condv, incrv, body))
12302 : {
12303 453 : tree stmt;
12304 :
12305 453 : stmt = make_node (code);
12306 :
12307 1499 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
12308 : {
12309 593 : if (TREE_VEC_ELT (declv, i) == NULL_TREE)
12310 9 : continue;
12311 : /* This is really just a place-holder. We'll be decomposing this
12312 : again and going through the cp_build_modify_expr path below when
12313 : we instantiate the thing. */
12314 584 : TREE_VEC_ELT (initv, i)
12315 1168 : = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
12316 584 : TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
12317 : }
12318 :
12319 453 : TREE_TYPE (stmt) = void_type_node;
12320 453 : OMP_FOR_INIT (stmt) = initv;
12321 453 : OMP_FOR_COND (stmt) = condv;
12322 453 : OMP_FOR_INCR (stmt) = incrv;
12323 453 : OMP_FOR_BODY (stmt) = body;
12324 453 : OMP_FOR_PRE_BODY (stmt) = pre_body;
12325 453 : OMP_FOR_CLAUSES (stmt) = clauses;
12326 :
12327 453 : SET_EXPR_LOCATION (stmt, locus);
12328 453 : return add_stmt (stmt);
12329 : }
12330 :
12331 20746 : if (!orig_declv)
12332 19937 : orig_declv = copy_node (declv);
12333 :
12334 20746 : if (processing_template_decl)
12335 634 : orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
12336 :
12337 48358 : for (i = 0; i < TREE_VEC_LENGTH (declv); )
12338 : {
12339 27704 : decl = TREE_VEC_ELT (declv, i);
12340 27704 : init = TREE_VEC_ELT (initv, i);
12341 27704 : cond = TREE_VEC_ELT (condv, i);
12342 27704 : incr = TREE_VEC_ELT (incrv, i);
12343 27704 : if (orig_incr)
12344 866 : TREE_VEC_ELT (orig_incr, i) = incr;
12345 27704 : elocus = init_locv[i];
12346 :
12347 27704 : if (decl == NULL_TREE)
12348 : {
12349 1092 : i++;
12350 1092 : continue;
12351 : }
12352 :
12353 26612 : if (!DECL_P (decl))
12354 : {
12355 6 : error_at (elocus, "expected iteration declaration or initialization");
12356 6 : return NULL;
12357 : }
12358 :
12359 26606 : if (incr && TREE_CODE (incr) == MODOP_EXPR)
12360 : {
12361 1 : if (orig_incr)
12362 1 : TREE_VEC_ELT (orig_incr, i) = incr;
12363 1 : incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
12364 1 : TREE_CODE (TREE_OPERAND (incr, 1)),
12365 1 : TREE_OPERAND (incr, 2),
12366 : tf_warning_or_error);
12367 : }
12368 :
12369 26606 : if (CLASS_TYPE_P (TREE_TYPE (decl)))
12370 : {
12371 825 : if (code == OMP_SIMD)
12372 : {
12373 12 : error_at (elocus, "%<#pragma omp simd%> used with class "
12374 : "iteration variable %qE", decl);
12375 12 : return NULL;
12376 : }
12377 813 : if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
12378 : initv, condv, incrv, &body,
12379 : &pre_body, clauses,
12380 : collapse, ordered))
12381 : return NULL;
12382 762 : continue;
12383 : }
12384 :
12385 51562 : if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
12386 27367 : && !TYPE_PTR_P (TREE_TYPE (decl)))
12387 : {
12388 14 : error_at (elocus, "invalid type for iteration variable %qE", decl);
12389 14 : return NULL;
12390 : }
12391 :
12392 25767 : if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
12393 24984 : init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
12394 : tf_warning_or_error);
12395 : else
12396 783 : init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
12397 25767 : if (decl == error_mark_node || init == error_mark_node)
12398 : return NULL;
12399 :
12400 25758 : TREE_VEC_ELT (declv, i) = decl;
12401 25758 : TREE_VEC_ELT (initv, i) = init;
12402 25758 : TREE_VEC_ELT (condv, i) = cond;
12403 25758 : TREE_VEC_ELT (incrv, i) = incr;
12404 25758 : i++;
12405 : }
12406 :
12407 20654 : if (pre_body && IS_EMPTY_STMT (pre_body))
12408 0 : pre_body = NULL;
12409 :
12410 41308 : omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
12411 : incrv, body, pre_body,
12412 20654 : !processing_template_decl);
12413 :
12414 : /* Check for iterators appearing in lb, b or incr expressions. */
12415 20654 : if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
12416 : omp_for = NULL_TREE;
12417 :
12418 20168 : if (omp_for == NULL)
12419 : return NULL;
12420 :
12421 19952 : add_stmt (omp_for);
12422 :
12423 65728 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
12424 : {
12425 25824 : init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
12426 25824 : if (init == NULL_TREE)
12427 1032 : continue;
12428 24792 : decl = TREE_OPERAND (init, 0);
12429 24792 : cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
12430 24792 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
12431 :
12432 24792 : if (!processing_template_decl)
12433 : {
12434 24249 : if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
12435 : {
12436 106 : tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
12437 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
12438 106 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12439 106 : t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
12440 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
12441 212 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12442 : }
12443 : else
12444 : {
12445 24143 : tree t = TREE_OPERAND (init, 1);
12446 24143 : TREE_OPERAND (init, 1)
12447 48286 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12448 : }
12449 24249 : if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
12450 : {
12451 121 : tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
12452 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
12453 121 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12454 121 : t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
12455 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
12456 242 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12457 : }
12458 : else
12459 : {
12460 24128 : tree t = TREE_OPERAND (cond, 1);
12461 24128 : TREE_OPERAND (cond, 1)
12462 48256 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12463 : }
12464 : }
12465 :
12466 24792 : if (TREE_CODE (incr) != MODIFY_EXPR)
12467 18587 : continue;
12468 :
12469 6205 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
12470 70 : && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
12471 6275 : && !processing_template_decl)
12472 : {
12473 64 : tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
12474 64 : if (TREE_SIDE_EFFECTS (t)
12475 8 : && t != decl
12476 70 : && (TREE_CODE (t) != NOP_EXPR
12477 0 : || TREE_OPERAND (t, 0) != decl))
12478 6 : TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
12479 12 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12480 :
12481 64 : t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
12482 64 : if (TREE_SIDE_EFFECTS (t)
12483 56 : && t != decl
12484 120 : && (TREE_CODE (t) != NOP_EXPR
12485 5 : || TREE_OPERAND (t, 0) != decl))
12486 56 : TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
12487 112 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12488 : }
12489 :
12490 6205 : if (orig_incr)
12491 177 : TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
12492 : }
12493 19952 : OMP_FOR_CLAUSES (omp_for) = clauses;
12494 :
12495 : /* For simd loops with non-static data member iterators, we could have added
12496 : OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
12497 : step at this point, fill it in. */
12498 4783 : if (code == OMP_SIMD && !processing_template_decl
12499 24691 : && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
12500 4667 : for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
12501 561 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
12502 561 : if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
12503 : {
12504 4 : decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
12505 4 : gcc_assert (decl == OMP_CLAUSE_DECL (c));
12506 4 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
12507 4 : tree step, stept;
12508 4 : switch (TREE_CODE (incr))
12509 : {
12510 0 : case PREINCREMENT_EXPR:
12511 0 : case POSTINCREMENT_EXPR:
12512 : /* c_omp_for_incr_canonicalize_ptr() should have been
12513 : called to massage things appropriately. */
12514 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12515 0 : OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
12516 0 : break;
12517 0 : case PREDECREMENT_EXPR:
12518 0 : case POSTDECREMENT_EXPR:
12519 : /* c_omp_for_incr_canonicalize_ptr() should have been
12520 : called to massage things appropriately. */
12521 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12522 0 : OMP_CLAUSE_LINEAR_STEP (c)
12523 0 : = build_int_cst (TREE_TYPE (decl), -1);
12524 0 : break;
12525 4 : case MODIFY_EXPR:
12526 4 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12527 4 : incr = TREE_OPERAND (incr, 1);
12528 4 : switch (TREE_CODE (incr))
12529 : {
12530 4 : case PLUS_EXPR:
12531 4 : if (TREE_OPERAND (incr, 1) == decl)
12532 0 : step = TREE_OPERAND (incr, 0);
12533 : else
12534 4 : step = TREE_OPERAND (incr, 1);
12535 : break;
12536 0 : case MINUS_EXPR:
12537 0 : case POINTER_PLUS_EXPR:
12538 0 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12539 0 : step = TREE_OPERAND (incr, 1);
12540 0 : break;
12541 0 : default:
12542 0 : gcc_unreachable ();
12543 : }
12544 4 : stept = TREE_TYPE (decl);
12545 4 : if (INDIRECT_TYPE_P (stept))
12546 0 : stept = sizetype;
12547 4 : step = fold_convert (stept, step);
12548 4 : if (TREE_CODE (incr) == MINUS_EXPR)
12549 0 : step = fold_build1 (NEGATE_EXPR, stept, step);
12550 4 : OMP_CLAUSE_LINEAR_STEP (c) = step;
12551 4 : break;
12552 0 : default:
12553 0 : gcc_unreachable ();
12554 : }
12555 : }
12556 : /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
12557 : clauses, we need copy ctor for those rather than default ctor,
12558 : plus as for other lastprivates assignment op and dtor. */
12559 19952 : if (code == OMP_LOOP && !processing_template_decl)
12560 1995 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12561 1286 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
12562 204 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
12563 1308 : && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
12564 : false, true, true, true))
12565 0 : CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
12566 :
12567 : return omp_for;
12568 21292 : }
12569 :
12570 : /* Code walker for finish_omp_for_block: extract binding of DP->var
12571 : from its current block and move it to a new BIND_EXPR DP->b
12572 : surrounding the body of DP->omp_for. */
12573 :
12574 : struct fofb_data {
12575 : tree var;
12576 : tree b;
12577 : tree omp_for;
12578 : };
12579 :
12580 : static tree
12581 389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
12582 : {
12583 389 : struct fofb_data *fofb = (struct fofb_data *)dp;
12584 389 : if (TREE_CODE (*tp) == BIND_EXPR)
12585 578 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
12586 : {
12587 576 : if (*p == fofb->var)
12588 : {
12589 363 : *p = DECL_CHAIN (*p);
12590 363 : if (fofb->b == NULL_TREE)
12591 : {
12592 214 : fofb->b = make_node (BLOCK);
12593 214 : fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
12594 214 : OMP_FOR_BODY (fofb->omp_for), fofb->b);
12595 214 : TREE_SIDE_EFFECTS (fofb->b) = 1;
12596 214 : OMP_FOR_BODY (fofb->omp_for) = fofb->b;
12597 : }
12598 363 : DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
12599 363 : BIND_EXPR_VARS (fofb->b) = fofb->var;
12600 363 : BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
12601 363 : BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
12602 363 : return *tp;
12603 : }
12604 : }
12605 26 : if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
12606 22 : *walk_subtrees = false;
12607 : return NULL_TREE;
12608 : }
12609 :
12610 : /* Fix up range for decls. Those decls were pushed into BIND's
12611 : BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
12612 : and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
12613 : so that processing of combined loop directives can find them. */
12614 : tree
12615 14711 : finish_omp_for_block (tree bind, tree omp_for)
12616 : {
12617 14711 : if (omp_for == NULL_TREE
12618 14664 : || !OMP_FOR_ORIG_DECLS (omp_for)
12619 28785 : || bind == NULL_TREE)
12620 637 : return bind;
12621 14074 : struct fofb_data fofb;
12622 14074 : fofb.b = NULL_TREE;
12623 14074 : fofb.omp_for = omp_for;
12624 33675 : for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
12625 19601 : if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
12626 19379 : && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
12627 : == TREE_LIST)
12628 20432 : && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
12629 : {
12630 237 : tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
12631 602 : for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
12632 : {
12633 365 : fofb.var = TREE_VEC_ELT (v, j);
12634 365 : cp_walk_tree (&bind, finish_omp_for_block_walker,
12635 : (void *)&fofb, NULL);
12636 : }
12637 : }
12638 14074 : return bind;
12639 : }
12640 :
12641 : /* Validate an OpenMP allocate directive, then add the ALLOC and ALIGN exprs to
12642 : the "omp allocate" attr of each decl found in VARS. The value of attr is
12643 : a TREE_LIST with ALLOC stored in its purpose member and ALIGN stored in its
12644 : value member. ALLOC and ALIGN are exprs passed as arguments to the
12645 : allocator and align clauses of the directive. VARS may be NULL_TREE if
12646 : there were errors during parsing.
12647 : #pragma omp allocate(VARS) allocator(ALLOC) align(ALIGN)
12648 :
12649 : If processing_template_decl, a stmt of tree_code OMP_ALLOCATE is added to
12650 : the function instead. LOC is used to initialize EXPR_LOCATION of the stmt.
12651 :
12652 : If any errors occur, the "omp allocate" attr is marked so the middle end
12653 : knows to skip it during gimplification. */
12654 :
12655 : void
12656 2958 : finish_omp_allocate (const location_t loc, const tree var_list,
12657 : const tree alloc_in, const tree align_in,
12658 : const tree context)
12659 : {
12660 : /* Takes a VAR_DECL. */
12661 2958 : using var_predicate = bool (*)(const_tree);
12662 12039 : const auto any_of_vars = [&var_list] (var_predicate predicate)
12663 : {
12664 17392 : for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))
12665 8723 : if (predicate (TREE_PURPOSE (vn)))
12666 : return true;
12667 : return false;
12668 2958 : };
12669 2958 : const bool global = !DECL_DECLARES_FUNCTION_P (context);
12670 2958 : const var_predicate tree_static_p = [&] () -> var_predicate
12671 : {
12672 : /* If this directive is not in a function, all the vars are static. */
12673 2958 : if (global)
12674 : return [] (const_tree) -> bool { return true; };
12675 : else
12676 2859 : return [] (const_tree t) -> bool { return TREE_STATIC (t); };
12677 2958 : } (); /* IILE. */
12678 2958 : const bool any_static_vars = any_of_vars (tree_static_p);
12679 :
12680 : /* Create an auto_diagnostic_group before calling this. */
12681 2958 : const auto emit_diag_for_var_group
12682 176 : = [] (const var_predicate pred,
12683 : void (*diag_fn)(rich_location *, const char *, ...),
12684 : const char *msg,
12685 : const const_tree var_list)
12686 : {
12687 714 : auto next_match = [&pred] (const_tree first)
12688 : {
12689 538 : const_tree vn = first;
12690 558 : for (; vn != NULL_TREE; vn = TREE_CHAIN (vn))
12691 206 : if (TREE_PURPOSE (vn) != error_mark_node
12692 206 : && pred (TREE_PURPOSE (vn)))
12693 : return vn;
12694 : return vn;
12695 176 : };
12696 176 : gcc_assert (var_list != NULL_TREE);
12697 176 : const const_tree first_node = next_match (var_list);
12698 176 : gcc_assert (first_node != NULL_TREE);
12699 :
12700 176 : gcc_rich_location rich_loc (EXPR_LOCATION (TREE_VALUE (first_node)));
12701 : /* Don't add another range for the first node. */
12702 176 : for (const_tree vn = next_match (TREE_CHAIN (first_node));
12703 181 : vn != NULL_TREE;
12704 5 : vn = next_match (TREE_CHAIN (vn)))
12705 5 : rich_loc.add_range (EXPR_LOCATION (TREE_VALUE (vn)));
12706 176 : diag_fn (&rich_loc, msg);
12707 :
12708 176 : const_tree vn = first_node;
12709 533 : for (; vn != NULL_TREE; vn = next_match (TREE_CHAIN (vn)))
12710 362 : inform (DECL_SOURCE_LOCATION (TREE_PURPOSE (vn)),
12711 181 : "%qD declared here", TREE_PURPOSE (vn));
12712 176 : };
12713 :
12714 : /* Defer error marking vars until after other diagnostics are done, we might
12715 : still need access to them when diagnosing the allocator clause. */
12716 2958 : hash_set<tree> deferred_erroneous_var_nodes;
12717 :
12718 2958 : const auto ref_var_p
12719 2910 : = [] (const_tree t) -> bool { return TYPE_REF_P (TREE_TYPE (t)); };
12720 2958 : if (any_of_vars (ref_var_p))
12721 : {
12722 75 : auto_diagnostic_group d;
12723 75 : emit_diag_for_var_group (ref_var_p,
12724 : &error_at,
12725 : G_("variables with reference type may not "
12726 : "appear in an %<allocate%> directive"),
12727 : var_list);
12728 150 : for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))
12729 : {
12730 75 : if (!ref_var_p (TREE_PURPOSE (vn)))
12731 0 : continue;
12732 75 : deferred_erroneous_var_nodes.add (vn);
12733 : }
12734 75 : }
12735 :
12736 : /* (OpenMP 5.2, 174:15) Type: expression of integer type
12737 : Properties: constant, positive */
12738 8874 : const tree align = [&align_in] ()
12739 : {
12740 2958 : if (!align_in || align_in == error_mark_node)
12741 : return align_in;
12742 :
12743 1313 : auto emit_align_err = [&align_in] ()
12744 : {
12745 116 : error_at (EXPR_LOCATION (align_in),
12746 : "%<align%> clause argument needs to be positive constant "
12747 : "power of two integer expression");
12748 1313 : };
12749 1197 : if (processing_template_decl)
12750 : return align_in;
12751 :
12752 : /* Identity conversions are okay. */
12753 608 : const tree converted_align
12754 608 : = build_converted_constant_expr (size_type_node, align_in, tf_error);
12755 608 : gcc_assert (converted_align != NULL_TREE);
12756 608 : if (converted_align == error_mark_node)
12757 : {
12758 11 : emit_align_err ();
12759 11 : return error_mark_node;
12760 : }
12761 :
12762 597 : const tree folded_align = cxx_constant_value (converted_align);
12763 597 : if (folded_align == error_mark_node)
12764 : {
12765 5 : emit_align_err ();
12766 5 : return error_mark_node;
12767 : }
12768 592 : gcc_assert (TREE_CONSTANT (folded_align));
12769 : /* (OpenMP 5.2, 175:10) alignment must evaluate to a power of two. */
12770 592 : if (tree_int_cst_sgn (folded_align) != 1
12771 592 : || !integer_pow2p (folded_align))
12772 : {
12773 100 : emit_align_err ();
12774 100 : return error_mark_node;
12775 : }
12776 : return folded_align;
12777 2958 : } (); /* IILE. */
12778 :
12779 : /* (OpenMP 5.2, 175:17) Type: expression of allocator_handle type
12780 : Properties: default */
12781 8874 : const tree alloc = [&] ()
12782 : {
12783 2958 : if (alloc_in == error_mark_node)
12784 : return error_mark_node;
12785 : /* (OpenMP 5.2 176:26-28)
12786 : If a list item has static storage duration, the allocator clause must
12787 : be specified and the allocator expression in the clause must be a
12788 : constant expression that evaluates to one of the predefined memory
12789 : allocator values. */
12790 3056 : const auto emit_diag_for_static_vars = [&] ()
12791 : {
12792 101 : emit_diag_for_var_group (tree_static_p,
12793 : &inform,
12794 : G_("because one or more variables with "
12795 : "static storage duration appear "
12796 : "in the %<allocate%> directive"),
12797 : var_list);
12798 3056 : };
12799 2955 : if (alloc_in == NULL_TREE)
12800 : {
12801 1135 : if (!any_static_vars)
12802 : return NULL_TREE;
12803 : else
12804 : {
12805 9 : auto_diagnostic_group d;
12806 9 : error_at (loc, "%<allocator%> clause must be specified");
12807 9 : emit_diag_for_static_vars ();
12808 9 : return error_mark_node;
12809 9 : }
12810 : gcc_unreachable ();
12811 : }
12812 1820 : if (processing_template_decl)
12813 : return alloc_in;
12814 :
12815 4068 : const tree alloc_type = [&] ()
12816 : {
12817 1356 : static tree cached_alloc_type = NULL_TREE;
12818 1356 : if (cached_alloc_type != NULL_TREE)
12819 : return cached_alloc_type;
12820 :
12821 68 : const tree alloc_type_decl
12822 68 : = lookup_qualified_name (global_namespace,
12823 : get_identifier ("omp_allocator_handle_t"),
12824 : LOOK_want::TYPE);
12825 : /* User didn't include omp.h... */
12826 68 : if (alloc_type_decl == error_mark_node)
12827 : {
12828 : /* We need to wait until instantiation to complain about it if
12829 : alloc_in could possibly be well-formed. */
12830 0 : if (processing_template_decl
12831 0 : && (type_dependent_expression_p (alloc_in)
12832 : /* No one sane would have a conversion template and
12833 : use it this way, but it would still technically be
12834 : correct so we have to account for it. */
12835 0 : || (CLASS_TYPE_P (TREE_TYPE (alloc_in))
12836 0 : && TYPE_HAS_CONVERSION (TREE_TYPE (alloc_in)))))
12837 : {
12838 0 : gcc_assert (cached_alloc_type == NULL_TREE);
12839 : return cached_alloc_type;
12840 : }
12841 0 : auto_diagnostic_group d;
12842 0 : gcc_rich_location loc (EXPR_LOCATION (alloc_in));
12843 0 : maybe_add_include_fixit (&loc, "<omp.h>", false);
12844 0 : error_at (&loc,
12845 : "%<allocator%> clause requires a valid declaration "
12846 : "of %<omp_allocator_handle_t%>");
12847 0 : inform (&loc,
12848 : "%<omp_allocator_handle_t%> is defined in header "
12849 : "%<<omp.h>%>");
12850 0 : cached_alloc_type = error_mark_node;
12851 0 : return cached_alloc_type;
12852 0 : }
12853 136 : const auto underlying_type_is_valid = [] (const const_tree type)
12854 : {
12855 68 : const const_tree canonical_type = TYPE_CANONICAL (type);
12856 68 : if (cxx_dialect >= cxx11)
12857 54 : return canonical_type == uintptr_type_node;
12858 14 : gcc_assert (cxx_dialect < cxx11);
12859 : /* Pre c++11 we can't just assume the underlying type. */
12860 14 : return TYPE_UNSIGNED (canonical_type) == true
12861 14 : && wi::to_widest (TYPE_SIZE (canonical_type))
12862 28 : == wi::to_widest (TYPE_SIZE (uintptr_type_node))
12863 14 : && wi::to_widest (TYPE_MIN_VALUE (canonical_type))
12864 28 : == wi::to_widest (TYPE_MIN_VALUE (uintptr_type_node))
12865 28 : && wi::to_widest (TYPE_MAX_VALUE (canonical_type))
12866 28 : == wi::to_widest (TYPE_MAX_VALUE (uintptr_type_node));
12867 : };
12868 68 : const tree alloc_type = TREE_TYPE (alloc_type_decl);
12869 68 : if (TREE_CODE (alloc_type) != ENUMERAL_TYPE
12870 68 : || !underlying_type_is_valid (TREE_TYPE (alloc_type)))
12871 : {
12872 0 : auto_diagnostic_group d;
12873 0 : error_at (EXPR_LOCATION (alloc_in),
12874 : "%<allocator%> clause requires a valid declaration "
12875 : "of %<omp_allocator_handle_t%>");
12876 : /* This diagnostic is not very good, especially if it somehow
12877 : is the declaration in omp.h. */
12878 0 : inform (DECL_SOURCE_LOCATION (alloc_type_decl),
12879 : "invalid type declared here");
12880 0 : cached_alloc_type = error_mark_node;
12881 0 : }
12882 : else
12883 68 : cached_alloc_type = alloc_type;
12884 68 : gcc_assert (cached_alloc_type != NULL_TREE);
12885 : return cached_alloc_type;
12886 1356 : } (); /* IILE. */
12887 : /* Any sane user will include omp.h before we get here, unfortunately
12888 : insane doesn't mean incorrect. */
12889 1356 : if (alloc_type == NULL_TREE)
12890 0 : return alloc_in;
12891 : /* We can't do anything meaningful with alloc_in if we lack a valid
12892 : omp_allocator_handle_t type. */
12893 1356 : if (alloc_type == error_mark_node)
12894 : return error_mark_node;
12895 :
12896 : /* Identity conversion is okay. */
12897 1356 : const tree converted_alloc
12898 1356 : = any_static_vars
12899 1356 : ? build_converted_constant_expr (alloc_type, alloc_in, tf_error)
12900 1136 : : perform_implicit_conversion (alloc_type, alloc_in, tf_error);
12901 :
12902 : /* The expr is not manifestly constant-evaluated in this case, only do
12903 : simple folding even if it is potentially a constant expression. */
12904 1356 : if (!any_static_vars)
12905 1136 : return maybe_fold_non_dependent_expr (converted_alloc, tf_none);
12906 :
12907 : /* Per OpenMP 5.2 176:26-28 quoted above, the allocator clause is
12908 : manifestly constant-evaluated in this case. */
12909 220 : const tree ret = cxx_constant_value (converted_alloc);
12910 220 : if (ret == error_mark_node)
12911 : {
12912 5 : auto_diagnostic_group d;
12913 5 : error_at (EXPR_LOCATION (alloc_in),
12914 : "%<allocator%> clause requires a constant "
12915 : "predefined allocator");
12916 5 : emit_diag_for_static_vars ();
12917 5 : return error_mark_node;
12918 5 : }
12919 215 : gcc_assert (TREE_CONSTANT (ret));
12920 215 : wi::tree_to_widest_ref alloc_value = wi::to_widest (ret);
12921 : /* MAX is inclusive. */
12922 215 : const bool predefined_allocator_p
12923 215 : = (alloc_value >= 1
12924 200 : && alloc_value <= GOMP_OMP_PREDEF_ALLOC_MAX)
12925 281 : || (alloc_value >= GOMP_OMPX_PREDEF_ALLOC_MIN
12926 45 : && alloc_value <= GOMP_OMPX_PREDEF_ALLOC_MAX);
12927 155 : if (!predefined_allocator_p)
12928 : {
12929 60 : auto_diagnostic_group d;
12930 60 : error_at (EXPR_LOCATION (alloc_in),
12931 : "%<allocator%> clause requires a constant "
12932 : "predefined allocator");
12933 60 : emit_diag_for_static_vars ();
12934 60 : inform (EXPR_LOCATION (alloc_in),
12935 : "expression evaluates to %qwu", tree_to_uhwi (ret));
12936 60 : return error_mark_node;
12937 60 : }
12938 155 : else if (alloc_value == GOMP_OMP_PREDEF_ALLOC_CGROUP
12939 146 : || alloc_value == GOMP_OMP_PREDEF_ALLOC_PTEAM
12940 301 : || alloc_value == GOMP_OMP_PREDEF_ALLOC_THREAD)
12941 : {
12942 27 : auto_diagnostic_group d;
12943 27 : error_at (EXPR_LOCATION (alloc_in),
12944 : "%<allocator%> clause must not "
12945 : "be %<omp_cgroup_mem_alloc%>, %<omp_pteam_mem_alloc%>, "
12946 : "or %<omp_thread_mem_alloc%>");
12947 27 : emit_diag_for_static_vars ();
12948 27 : inform (EXPR_LOCATION (alloc_in),
12949 : "expression evaluates to %qwu", tree_to_uhwi (ret));
12950 27 : }
12951 : return ret;
12952 2958 : } (); /* IILE. */
12953 :
12954 4794 : auto finalize_allocate_attr = [] (tree var, tree alloc, tree align)
12955 : {
12956 : /* This should only be called once for each var, either after a
12957 : diagnostic, or when we are finished with the directive. */
12958 1836 : gcc_assert (var != NULL_TREE && var != error_mark_node);
12959 :
12960 : /* Replace the old attr in place to maintain the invariants of
12961 : DECL_ATTRIBUTES as described in cp_parser_omp_allocate.
12962 : Unfortunately lookup_attribute does not return an "iterator" to the
12963 : attr so we have to write the lookup ourselves here. */
12964 5508 : tree *const attr_it = [&] ()
12965 : {
12966 1836 : tree *it = &DECL_ATTRIBUTES (var);
12967 1836 : for (; *it != NULL_TREE; it = &TREE_CHAIN (*it))
12968 1836 : if (is_attribute_p ("omp allocate", get_attribute_name (*it)))
12969 1836 : return it;
12970 0 : gcc_unreachable ();
12971 1836 : } (); /* IILE. */
12972 : /* Don't modify the old attr, for various reasons it isn't marked
12973 : dependent so substitution does not copy it. */
12974 1836 : const_tree old_attr = *attr_it;
12975 : /* There should only be one attr. */
12976 1836 : gcc_checking_assert (!lookup_attribute ("omp allocate",
12977 : TREE_CHAIN (old_attr)));
12978 : /* This location is where the var was specified in the directive. */
12979 1836 : const tree arg_loc = TREE_VALUE (old_attr);
12980 1836 : gcc_assert (arg_loc != NULL_TREE && TREE_CODE (arg_loc) == NOP_EXPR);
12981 : /* Smuggle the location, we might still need it for diagnostics, such as
12982 : if we are still parsing a function. */
12983 1836 : const tree attr_value = tree_cons (alloc, align, arg_loc);
12984 :
12985 : /* As noted above, we create the final attr ourselves instead of having
12986 : substitution handle it. */
12987 1836 : *attr_it = tree_cons (TREE_PURPOSE (old_attr),
12988 : attr_value,
12989 1836 : TREE_CHAIN (old_attr));
12990 1836 : };
12991 3187 : auto finalize_var_node_with_error = [&] (tree node)
12992 : {
12993 : /* We can't remove the attribute, the variable still needs to be marked
12994 : in case that we are still parsing a function for the first time.
12995 : We avoid handling error_mark_node in varpool_node::finalize_decl by
12996 : setting align to NULL_TREE. */
12997 229 : finalize_allocate_attr (TREE_PURPOSE (node), error_mark_node, NULL_TREE);
12998 : /* Prevent further diagnostics for this var. */
12999 229 : TREE_PURPOSE (node) = error_mark_node;
13000 3187 : };
13001 :
13002 5718 : for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))
13003 2760 : if (deferred_erroneous_var_nodes.contains (vn))
13004 75 : finalize_var_node_with_error (vn);
13005 :
13006 : /* Even if there have been errors, save the current state, there might be
13007 : more to diagnose on a later instantiation. */
13008 2958 : if (processing_template_decl)
13009 : {
13010 1046 : tree allocate_stmt = make_node (OMP_ALLOCATE);
13011 : /* This shouldn't matter, but better to set it anyway. */
13012 1046 : TREE_SIDE_EFFECTS (allocate_stmt) = 0;
13013 1046 : SET_EXPR_LOCATION (allocate_stmt, loc);
13014 1046 : OMP_ALLOCATE_VARS (allocate_stmt) = var_list;
13015 1046 : OMP_ALLOCATE_ALLOCATOR (allocate_stmt) = alloc;
13016 1046 : OMP_ALLOCATE_ALIGN (allocate_stmt) = align;
13017 1046 : add_stmt (allocate_stmt);
13018 1046 : return;
13019 : }
13020 1838 : else if (alloc == error_mark_node || align == error_mark_node || !var_list
13021 3517 : || any_of_vars (&error_operand_p))
13022 : {
13023 : /* The directive is fully instantiated, but there were errors. */
13024 563 : for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))
13025 : /* Don't mark vars a second time. */
13026 211 : if (TREE_PURPOSE (vn) != error_mark_node)
13027 154 : finalize_var_node_with_error (vn);
13028 : return;
13029 : }
13030 :
13031 1560 : gcc_assert (!processing_template_decl
13032 : && alloc != error_mark_node
13033 : && align != error_mark_node
13034 : && var_list != NULL_TREE
13035 : && !any_of_vars (&error_operand_p));
13036 :
13037 : /* We can technically finalize earlier if everything (vars, alloc, align) is
13038 : substituted and the alloc expr doesn't contain any local variables, this
13039 : isn't worth the added complexity for now though. */
13040 3167 : for (tree vn = var_list; vn != NULL_TREE; vn = TREE_CHAIN (vn))
13041 1607 : finalize_allocate_attr (TREE_PURPOSE (vn), alloc, align);
13042 2958 : }
13043 :
13044 : void
13045 3351 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
13046 : tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
13047 : tree clauses, enum omp_memory_order mo, bool weak)
13048 : {
13049 3351 : tree orig_lhs;
13050 3351 : tree orig_rhs;
13051 3351 : tree orig_v;
13052 3351 : tree orig_lhs1;
13053 3351 : tree orig_rhs1;
13054 3351 : tree orig_r;
13055 3351 : bool dependent_p;
13056 3351 : tree stmt;
13057 :
13058 3351 : orig_lhs = lhs;
13059 3351 : orig_rhs = rhs;
13060 3351 : orig_v = v;
13061 3351 : orig_lhs1 = lhs1;
13062 3351 : orig_rhs1 = rhs1;
13063 3351 : orig_r = r;
13064 3351 : dependent_p = false;
13065 3351 : stmt = NULL_TREE;
13066 :
13067 : /* Even in a template, we can detect invalid uses of the atomic
13068 : pragma if neither LHS nor RHS is type-dependent. */
13069 3351 : if (processing_template_decl)
13070 : {
13071 600 : dependent_p = (type_dependent_expression_p (lhs)
13072 237 : || (rhs && type_dependent_expression_p (rhs))
13073 234 : || (v && type_dependent_expression_p (v))
13074 234 : || (lhs1 && type_dependent_expression_p (lhs1))
13075 234 : || (rhs1 && type_dependent_expression_p (rhs1))
13076 834 : || (r
13077 25 : && r != void_list_node
13078 16 : && type_dependent_expression_p (r)));
13079 600 : if (clauses)
13080 : {
13081 30 : gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
13082 : && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
13083 : && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
13084 30 : if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
13085 30 : || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
13086 : dependent_p = true;
13087 : }
13088 : }
13089 576 : if (!dependent_p)
13090 : {
13091 2967 : bool swapped = false;
13092 2967 : if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
13093 : {
13094 143 : std::swap (rhs, rhs1);
13095 143 : swapped = !commutative_tree_code (opcode);
13096 : }
13097 2967 : if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
13098 : {
13099 0 : if (code == OMP_ATOMIC)
13100 0 : error ("%<#pragma omp atomic update%> uses two different "
13101 : "expressions for memory");
13102 : else
13103 0 : error ("%<#pragma omp atomic capture%> uses two different "
13104 : "expressions for memory");
13105 : return;
13106 : }
13107 2967 : if (lhs1 && !cp_tree_equal (lhs, lhs1))
13108 : {
13109 0 : if (code == OMP_ATOMIC)
13110 0 : error ("%<#pragma omp atomic update%> uses two different "
13111 : "expressions for memory");
13112 : else
13113 0 : error ("%<#pragma omp atomic capture%> uses two different "
13114 : "expressions for memory");
13115 : return;
13116 : }
13117 5934 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
13118 : v, lhs1, rhs1, r, swapped, mo, weak,
13119 2967 : processing_template_decl != 0);
13120 2967 : if (stmt == error_mark_node)
13121 : return;
13122 : }
13123 3321 : if (processing_template_decl)
13124 : {
13125 591 : if (code == OMP_ATOMIC_READ)
13126 : {
13127 167 : stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
13128 167 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
13129 167 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
13130 : }
13131 : else
13132 : {
13133 424 : if (opcode == NOP_EXPR)
13134 35 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
13135 389 : else if (opcode == COND_EXPR)
13136 : {
13137 124 : stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
13138 124 : if (orig_r)
13139 50 : stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
13140 : stmt);
13141 124 : stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
13142 : orig_lhs);
13143 124 : orig_rhs1 = NULL_TREE;
13144 : }
13145 : else
13146 265 : stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
13147 424 : if (orig_rhs1)
13148 182 : stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
13149 : COMPOUND_EXPR, orig_rhs1, stmt);
13150 424 : if (code != OMP_ATOMIC)
13151 : {
13152 233 : stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
13153 233 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
13154 233 : OMP_ATOMIC_WEAK (stmt) = weak;
13155 233 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
13156 : }
13157 : }
13158 591 : stmt = build2 (OMP_ATOMIC, void_type_node,
13159 : clauses ? clauses : integer_zero_node, stmt);
13160 591 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
13161 591 : OMP_ATOMIC_WEAK (stmt) = weak;
13162 591 : SET_EXPR_LOCATION (stmt, loc);
13163 : }
13164 :
13165 : /* Avoid -Wunused-value warnings here, the whole construct has side-effects
13166 : and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
13167 : in some tree that appears to be unused, the value is not unused. */
13168 3321 : warning_sentinel w (warn_unused_value);
13169 3321 : finish_expr_stmt (stmt);
13170 3321 : }
13171 :
13172 : void
13173 359 : finish_omp_barrier (void)
13174 : {
13175 359 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
13176 359 : releasing_vec vec;
13177 359 : vec->quick_push (build_int_cst (integer_type_node, GOMP_BARRIER_EXPLICIT));
13178 359 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
13179 359 : finish_expr_stmt (stmt);
13180 359 : }
13181 :
13182 : void
13183 397 : finish_omp_depobj (location_t loc, tree depobj,
13184 : enum omp_clause_depend_kind kind, tree clause)
13185 : {
13186 397 : if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
13187 : {
13188 343 : if (!lvalue_p (depobj))
13189 : {
13190 6 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
13191 : "%<depobj%> expression is not lvalue expression");
13192 6 : depobj = error_mark_node;
13193 : }
13194 : }
13195 :
13196 397 : if (processing_template_decl)
13197 : {
13198 114 : if (clause == NULL_TREE)
13199 47 : clause = build_int_cst (integer_type_node, kind);
13200 114 : add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
13201 114 : return;
13202 : }
13203 :
13204 283 : if (!error_operand_p (depobj))
13205 : {
13206 274 : tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
13207 274 : if (addr == error_mark_node)
13208 : depobj = error_mark_node;
13209 : else
13210 274 : depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
13211 : tf_warning_or_error);
13212 : }
13213 :
13214 283 : c_finish_omp_depobj (loc, depobj, kind, clause);
13215 : }
13216 :
13217 : void
13218 162 : finish_omp_flush (int mo)
13219 : {
13220 162 : tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
13221 162 : releasing_vec vec;
13222 162 : if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
13223 : {
13224 54 : fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
13225 54 : vec->quick_push (build_int_cst (integer_type_node, mo));
13226 : }
13227 162 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
13228 162 : finish_expr_stmt (stmt);
13229 162 : }
13230 :
13231 : void
13232 111 : finish_omp_taskwait (void)
13233 : {
13234 111 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
13235 111 : releasing_vec vec;
13236 111 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
13237 111 : finish_expr_stmt (stmt);
13238 111 : }
13239 :
13240 : void
13241 16 : finish_omp_taskyield (void)
13242 : {
13243 16 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
13244 16 : releasing_vec vec;
13245 16 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
13246 16 : finish_expr_stmt (stmt);
13247 16 : }
13248 :
13249 : void
13250 596 : finish_omp_cancel (tree clauses)
13251 : {
13252 596 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
13253 596 : int mask = 0;
13254 596 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
13255 : mask = 1;
13256 414 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
13257 : mask = 2;
13258 285 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
13259 : mask = 4;
13260 164 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
13261 : mask = 8;
13262 : else
13263 : {
13264 0 : error ("%<#pragma omp cancel%> must specify one of "
13265 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
13266 0 : return;
13267 : }
13268 596 : releasing_vec vec;
13269 596 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
13270 596 : if (ifc != NULL_TREE)
13271 : {
13272 70 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
13273 70 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
13274 6 : error_at (OMP_CLAUSE_LOCATION (ifc),
13275 : "expected %<cancel%> %<if%> clause modifier");
13276 : else
13277 : {
13278 64 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
13279 64 : if (ifc2 != NULL_TREE)
13280 : {
13281 3 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
13282 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
13283 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
13284 3 : error_at (OMP_CLAUSE_LOCATION (ifc2),
13285 : "expected %<cancel%> %<if%> clause modifier");
13286 : }
13287 : }
13288 :
13289 70 : if (!processing_template_decl)
13290 61 : ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
13291 : else
13292 9 : ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
13293 9 : OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
13294 : integer_zero_node, ERROR_MARK,
13295 : NULL_TREE, NULL, tf_warning_or_error);
13296 : }
13297 : else
13298 526 : ifc = boolean_true_node;
13299 596 : vec->quick_push (build_int_cst (integer_type_node, mask));
13300 596 : vec->quick_push (ifc);
13301 596 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
13302 596 : finish_expr_stmt (stmt);
13303 596 : }
13304 :
13305 : void
13306 494 : finish_omp_cancellation_point (tree clauses)
13307 : {
13308 494 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
13309 494 : int mask = 0;
13310 494 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
13311 : mask = 1;
13312 366 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
13313 : mask = 2;
13314 261 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
13315 : mask = 4;
13316 156 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
13317 : mask = 8;
13318 : else
13319 : {
13320 3 : error ("%<#pragma omp cancellation point%> must specify one of "
13321 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
13322 3 : return;
13323 : }
13324 491 : releasing_vec vec
13325 491 : = make_tree_vector_single (build_int_cst (integer_type_node, mask));
13326 491 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
13327 491 : finish_expr_stmt (stmt);
13328 491 : }
13329 :
13330 : /* Begin a __transaction_atomic or __transaction_relaxed statement.
13331 : If PCOMPOUND is non-null, this is for a function-transaction-block, and we
13332 : should create an extra compound stmt. */
13333 :
13334 : tree
13335 303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
13336 : {
13337 303 : tree r;
13338 :
13339 303 : if (pcompound)
13340 21 : *pcompound = begin_compound_stmt (0);
13341 :
13342 303 : r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
13343 :
13344 : /* Only add the statement to the function if support enabled. */
13345 303 : if (flag_tm)
13346 297 : add_stmt (r);
13347 : else
13348 12 : error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
13349 : ? G_("%<__transaction_relaxed%> without "
13350 : "transactional memory support enabled")
13351 : : G_("%<__transaction_atomic%> without "
13352 : "transactional memory support enabled")));
13353 :
13354 303 : TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
13355 303 : TREE_SIDE_EFFECTS (r) = 1;
13356 303 : return r;
13357 : }
13358 :
13359 : /* End a __transaction_atomic or __transaction_relaxed statement.
13360 : If COMPOUND_STMT is non-null, this is for a function-transaction-block,
13361 : and we should end the compound. If NOEX is non-NULL, we wrap the body in
13362 : a MUST_NOT_THROW_EXPR with NOEX as condition. */
13363 :
13364 : void
13365 303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
13366 : {
13367 303 : TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
13368 303 : TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
13369 303 : TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
13370 303 : TRANSACTION_EXPR_IS_STMT (stmt) = 1;
13371 :
13372 : /* noexcept specifications are not allowed for function transactions. */
13373 303 : gcc_assert (!(noex && compound_stmt));
13374 303 : if (noex)
13375 : {
13376 51 : tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
13377 : noex);
13378 51 : protected_set_expr_location
13379 51 : (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
13380 51 : TREE_SIDE_EFFECTS (body) = 1;
13381 51 : TRANSACTION_EXPR_BODY (stmt) = body;
13382 : }
13383 :
13384 303 : if (compound_stmt)
13385 21 : finish_compound_stmt (compound_stmt);
13386 303 : }
13387 :
13388 : /* Build a __transaction_atomic or __transaction_relaxed expression. If
13389 : NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
13390 : condition. */
13391 :
13392 : tree
13393 116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
13394 : {
13395 116 : tree ret;
13396 116 : if (noex)
13397 : {
13398 57 : expr = build_must_not_throw_expr (expr, noex);
13399 57 : protected_set_expr_location (expr, loc);
13400 57 : TREE_SIDE_EFFECTS (expr) = 1;
13401 : }
13402 116 : ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
13403 116 : if (flags & TM_STMT_ATTR_RELAXED)
13404 4 : TRANSACTION_EXPR_RELAXED (ret) = 1;
13405 116 : TREE_SIDE_EFFECTS (ret) = 1;
13406 116 : SET_EXPR_LOCATION (ret, loc);
13407 116 : return ret;
13408 : }
13409 :
13410 : void
13411 100969 : init_cp_semantics (void)
13412 : {
13413 100969 : }
13414 :
13415 :
13416 : /* Get constant string at LOCATION. Returns true if successful,
13417 : otherwise false. */
13418 :
13419 : bool
13420 11279913 : cexpr_str::type_check (location_t location, bool allow_char8_t /*=false*/)
13421 : {
13422 11279913 : tsubst_flags_t complain = tf_warning_or_error;
13423 :
13424 11279913 : if (message == NULL_TREE
13425 11279913 : || message == error_mark_node
13426 22559823 : || check_for_bare_parameter_packs (message))
13427 : return false;
13428 :
13429 11279910 : if (TREE_CODE (message) != STRING_CST
13430 11279910 : && !type_dependent_expression_p (message))
13431 : {
13432 1053 : message_sz
13433 1053 : = finish_class_member_access_expr (message,
13434 : get_identifier ("size"),
13435 : false, complain);
13436 1053 : if (message_sz != error_mark_node)
13437 952 : message_data
13438 952 : = finish_class_member_access_expr (message,
13439 : get_identifier ("data"),
13440 : false, complain);
13441 1053 : if (message_sz == error_mark_node || message_data == error_mark_node)
13442 : {
13443 139 : error_at (location, "constexpr string must be a string "
13444 : "literal or object with %<size%> and "
13445 : "%<data%> members");
13446 322 : return false;
13447 : }
13448 914 : releasing_vec size_args, data_args;
13449 914 : message_sz = finish_call_expr (message_sz, &size_args, false, false,
13450 : complain);
13451 914 : message_data = finish_call_expr (message_data, &data_args, false, false,
13452 : complain);
13453 914 : if (message_sz == error_mark_node || message_data == error_mark_node)
13454 : return false;
13455 800 : message_sz = build_converted_constant_expr (size_type_node, message_sz,
13456 : complain);
13457 800 : if (message_sz == error_mark_node)
13458 : {
13459 15 : error_at (location, "constexpr string %<size()%> "
13460 : "must be implicitly convertible to "
13461 : "%<std::size_t%>");
13462 15 : return false;
13463 : }
13464 :
13465 785 : if (allow_char8_t
13466 74 : && POINTER_TYPE_P (TREE_TYPE (message_data))
13467 74 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
13468 74 : == char8_type_node)
13469 805 : && (TYPE_QUALS (TREE_TYPE (TREE_TYPE (message_data)))
13470 183 : == TYPE_QUAL_CONST))
13471 : return true;
13472 :
13473 765 : message_data = build_converted_constant_expr (const_string_type_node,
13474 : message_data, complain);
13475 765 : if (message_data == error_mark_node)
13476 : {
13477 34 : error_at (location, "constexpr string %<data()%> "
13478 : "must be implicitly convertible to "
13479 : "%<const char*%>");
13480 34 : return false;
13481 : }
13482 914 : }
13483 : return true;
13484 : }
13485 :
13486 : /* Extract constant string at LOCATON into output string STR.
13487 : Returns true if successful, otherwise false. */
13488 :
13489 : bool
13490 405 : cexpr_str::extract (location_t location, tree &str)
13491 : {
13492 405 : const char *msg;
13493 405 : int len;
13494 405 : if (!extract (location, msg, len))
13495 : return false;
13496 343 : str = build_string (len, msg);
13497 343 : return true;
13498 : }
13499 :
13500 : /* Extract constant string at LOCATION into output string MSG with LEN.
13501 : Returns true if successful, otherwise false. */
13502 :
13503 : bool
13504 2707 : cexpr_str::extract (location_t location, const char * &msg, int &len,
13505 : const constexpr_ctx *ctx /* = NULL */,
13506 : bool *non_constant_p /* = NULL */,
13507 : bool *overflow_p /* = NULL */,
13508 : tree *jump_target /* = NULL */)
13509 : {
13510 2707 : tsubst_flags_t complain = tf_warning_or_error;
13511 :
13512 2707 : msg = NULL;
13513 2707 : if (message_sz && message_data)
13514 : {
13515 677 : tree msz;
13516 677 : if (ctx)
13517 : {
13518 110 : msz = cxx_eval_constant_expression (ctx, message_sz, vc_prvalue,
13519 : non_constant_p, overflow_p,
13520 : jump_target);
13521 110 : if (*jump_target || *non_constant_p)
13522 : return false;
13523 : }
13524 : else
13525 567 : msz = cxx_constant_value (message_sz, NULL_TREE, complain);
13526 669 : if (!tree_fits_uhwi_p (msz))
13527 : {
13528 35 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
13529 35 : error_at (location,
13530 : "constexpr string %<size()%> "
13531 : "must be a constant expression");
13532 : return false;
13533 : }
13534 634 : else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
13535 : != tree_to_uhwi (msz))
13536 : {
13537 0 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
13538 0 : error_at (location,
13539 : "constexpr string message %<size()%> "
13540 : "%qE too large", msz);
13541 : return false;
13542 : }
13543 634 : len = tree_to_uhwi (msz);
13544 634 : tree data;
13545 634 : if (ctx)
13546 : {
13547 102 : data = cxx_eval_constant_expression (ctx, message_data, vc_prvalue,
13548 : non_constant_p, overflow_p,
13549 : jump_target);
13550 102 : if (*jump_target || *non_constant_p)
13551 : return false;
13552 94 : STRIP_NOPS (data);
13553 94 : if (TREE_CODE (data) != ADDR_EXPR)
13554 : {
13555 0 : unhandled:
13556 0 : if (!cxx_constexpr_quiet_p (ctx))
13557 0 : error_at (location, "unhandled return from %<data()%>");
13558 : return false;
13559 : }
13560 94 : tree str = TREE_OPERAND (data, 0);
13561 94 : unsigned HOST_WIDE_INT off = 0;
13562 94 : if (TREE_CODE (str) == ARRAY_REF
13563 94 : && tree_fits_uhwi_p (TREE_OPERAND (str, 1)))
13564 : {
13565 12 : off = tree_to_uhwi (TREE_OPERAND (str, 1));
13566 12 : str = TREE_OPERAND (str, 0);
13567 : }
13568 94 : str = cxx_eval_constant_expression (ctx, str, vc_prvalue,
13569 : non_constant_p, overflow_p,
13570 : jump_target);
13571 94 : if (*jump_target || *non_constant_p)
13572 : return false;
13573 94 : if (TREE_CODE (str) == STRING_CST)
13574 : {
13575 84 : if (TREE_STRING_LENGTH (str) < len
13576 84 : || (unsigned) TREE_STRING_LENGTH (str) < off
13577 168 : || (unsigned) TREE_STRING_LENGTH (str) < off + len)
13578 0 : goto unhandled;
13579 84 : msg = TREE_STRING_POINTER (str) + off;
13580 84 : goto translate;
13581 : }
13582 10 : if (TREE_CODE (str) != CONSTRUCTOR
13583 10 : || TREE_CODE (TREE_TYPE (str)) != ARRAY_TYPE)
13584 0 : goto unhandled;
13585 10 : char *b;
13586 10 : if (len < 64)
13587 10 : b = XALLOCAVEC (char, len + 1);
13588 : else
13589 : {
13590 0 : buf = XNEWVEC (char, len + 1);
13591 0 : b = buf;
13592 : }
13593 10 : msg = b;
13594 10 : memset (b, 0, len + 1);
13595 10 : tree field, value;
13596 10 : unsigned k;
13597 10 : unsigned HOST_WIDE_INT l = 0;
13598 158 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (str), k, field, value)
13599 158 : if (!tree_fits_shwi_p (value))
13600 0 : goto unhandled;
13601 158 : else if (field == NULL_TREE)
13602 : {
13603 0 : if (integer_zerop (value))
13604 : break;
13605 0 : if (l >= off && l < off + len)
13606 0 : b[l - off] = tree_to_shwi (value);
13607 0 : ++l;
13608 : }
13609 158 : else if (TREE_CODE (field) == RANGE_EXPR)
13610 : {
13611 0 : tree lo = TREE_OPERAND (field, 0);
13612 0 : tree hi = TREE_OPERAND (field, 1);
13613 0 : if (!tree_fits_uhwi_p (lo) || !tree_fits_uhwi_p (hi))
13614 0 : goto unhandled;
13615 0 : if (integer_zerop (value))
13616 : break;
13617 0 : unsigned HOST_WIDE_INT m = tree_to_uhwi (hi);
13618 0 : for (l = tree_to_uhwi (lo); l <= m; ++l)
13619 0 : if (l >= off && l < off + len)
13620 0 : b[l - off] = tree_to_shwi (value);
13621 : }
13622 158 : else if (tree_fits_uhwi_p (field))
13623 : {
13624 158 : l = tree_to_uhwi (field);
13625 158 : if (integer_zerop (value))
13626 : break;
13627 148 : if (l >= off && l < off + len)
13628 148 : b[l - off] = tree_to_shwi (value);
13629 148 : l++;
13630 : }
13631 10 : b[len] = '\0';
13632 : }
13633 : else
13634 : {
13635 532 : data = maybe_constant_value (message_data, NULL_TREE, mce_true);
13636 532 : if (!reduced_constant_expression_p (data))
13637 96 : data = NULL_TREE;
13638 532 : if (len)
13639 : {
13640 455 : if (data)
13641 381 : msg = c_getstr (data);
13642 455 : if (msg == NULL)
13643 119 : buf = XNEWVEC (char, len);
13644 1458 : for (int i = 0; i < len; ++i)
13645 : {
13646 1033 : tree t = message_data;
13647 1033 : if (i)
13648 1156 : t = build2 (POINTER_PLUS_EXPR,
13649 578 : TREE_TYPE (message_data), message_data,
13650 578 : size_int (i));
13651 1033 : t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
13652 1033 : tree t2 = cxx_constant_value (t, NULL_TREE, complain);
13653 1033 : if (!tree_fits_shwi_p (t2))
13654 : {
13655 30 : error_at (location,
13656 : "constexpr string %<data()[%d]%> "
13657 : "must be a constant expression", i);
13658 30 : return false;
13659 : }
13660 1003 : if (msg == NULL)
13661 362 : buf[i] = tree_to_shwi (t2);
13662 : /* If c_getstr worked, just verify the first and
13663 : last characters using constant evaluation. */
13664 641 : else if (len > 2 && i == 0)
13665 268 : i = len - 2;
13666 : }
13667 425 : if (msg == NULL)
13668 104 : msg = buf;
13669 : }
13670 77 : else if (!data)
13671 : {
13672 : /* We don't have any function to test whether some
13673 : expression is a core constant expression. So, instead
13674 : test whether (message.data (), 0) is a constant
13675 : expression. */
13676 22 : data = build2 (COMPOUND_EXPR, integer_type_node,
13677 : message_data, integer_zero_node);
13678 22 : tree t = cxx_constant_value (data, NULL_TREE, complain);
13679 22 : if (!integer_zerop (t))
13680 : {
13681 22 : error_at (location,
13682 : "constexpr string %<data()%> "
13683 : "must be a core constant expression");
13684 22 : return false;
13685 : }
13686 : }
13687 : }
13688 : }
13689 : else
13690 : {
13691 2030 : tree eltype = TREE_TYPE (TREE_TYPE (message));
13692 2030 : int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
13693 2030 : msg = TREE_STRING_POINTER (message);
13694 2030 : len = TREE_STRING_LENGTH (message) / sz - 1;
13695 : }
13696 2604 : translate:
13697 2604 : if ((message_sz && message_data) || ctx)
13698 : {
13699 : /* Convert the string from execution charset to SOURCE_CHARSET. */
13700 768 : cpp_string istr, ostr;
13701 768 : istr.len = len;
13702 768 : istr.text = (const unsigned char *) msg;
13703 768 : enum cpp_ttype type = CPP_STRING;
13704 768 : if (message_sz && message_data)
13705 : {
13706 574 : if (POINTER_TYPE_P (TREE_TYPE (message_data))
13707 574 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
13708 574 : == char8_type_node))
13709 : type = CPP_UTF8STRING;
13710 : }
13711 194 : else if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message)))
13712 194 : == char8_type_node)
13713 768 : type = CPP_UTF8STRING;
13714 768 : if (len == 0)
13715 : ;
13716 643 : else if (!cpp_translate_string (parse_in, &istr, &ostr, type,
13717 : true))
13718 : {
13719 0 : if (type == CPP_UTF8STRING)
13720 0 : error_at (location, "could not convert constexpr string from "
13721 : "UTF-8 encoding to source character "
13722 : "set");
13723 : else
13724 0 : error_at (location, "could not convert constexpr string from "
13725 : "ordinary literal encoding to source character "
13726 : "set");
13727 0 : return false;
13728 : }
13729 : else
13730 : {
13731 643 : if (buf)
13732 104 : XDELETEVEC (buf);
13733 643 : msg = buf = const_cast <char *> ((const char *) ostr.text);
13734 643 : len = ostr.len;
13735 : }
13736 : }
13737 :
13738 : return true;
13739 : }
13740 :
13741 : /* Build a STATIC_ASSERT for a static assertion with the condition
13742 : CONDITION and the message text MESSAGE. LOCATION is the location
13743 : of the static assertion in the source code. When MEMBER_P, this
13744 : static assertion is a member of a class. If SHOW_EXPR_P is true,
13745 : print the condition (because it was instantiation-dependent).
13746 : If CONSTEVAL_BLOCK_P is true, this static assertion represents
13747 : a consteval block. */
13748 :
13749 : void
13750 11279222 : finish_static_assert (tree condition, tree message, location_t location,
13751 : bool member_p, bool show_expr_p,
13752 : bool consteval_block_p/*=false*/)
13753 : {
13754 11279222 : tsubst_flags_t complain = tf_warning_or_error;
13755 :
13756 11279222 : if (condition == NULL_TREE
13757 11279222 : || condition == error_mark_node)
13758 4781739 : return;
13759 :
13760 11278996 : if (check_for_bare_parameter_packs (condition))
13761 : return;
13762 :
13763 11278993 : cexpr_str cstr(message);
13764 11278993 : if (!cstr.type_check (location))
13765 : return;
13766 :
13767 : /* Save the condition in case it was a concept check. */
13768 11278899 : tree orig_condition = condition;
13769 :
13770 11278899 : if (instantiation_dependent_expression_p (condition)
13771 11278899 : || instantiation_dependent_expression_p (message))
13772 : {
13773 : /* We're in a template; build a STATIC_ASSERT and put it in
13774 : the right place. */
13775 4780864 : defer:
13776 4780864 : tree assertion = make_node (STATIC_ASSERT);
13777 4780864 : STATIC_ASSERT_CONDITION (assertion) = orig_condition;
13778 4780864 : STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
13779 4780864 : STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
13780 4780864 : CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
13781 :
13782 4780864 : if (member_p)
13783 2447460 : maybe_add_class_template_decl_list (current_class_type,
13784 : assertion,
13785 : /*friend_p=*/0);
13786 : else
13787 2333404 : add_stmt (assertion);
13788 :
13789 : return;
13790 : }
13791 :
13792 : /* Evaluate the consteval { }. This must be done only once. */
13793 6504107 : if (consteval_block_p)
13794 : {
13795 527 : cxx_constant_value (condition);
13796 527 : return;
13797 : }
13798 :
13799 : /* Fold the expression and convert it to a boolean value. */
13800 6503580 : condition = contextual_conv_bool (condition, complain);
13801 6503580 : condition = fold_non_dependent_expr (condition, complain,
13802 : /*manifestly_const_eval=*/true);
13803 :
13804 6503578 : if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
13805 : /* Do nothing; the condition is satisfied. */
13806 : ;
13807 : else
13808 : {
13809 8934 : iloc_sentinel ils (location);
13810 :
13811 8934 : if (integer_zerop (condition))
13812 : {
13813 : /* CWG2518: static_assert failure in a template is not IFNDR. */
13814 8070 : if (processing_template_decl)
13815 6072 : goto defer;
13816 :
13817 1998 : int len;
13818 1998 : const char *msg = NULL;
13819 1998 : if (!cstr.extract (location, msg, len))
13820 25 : return;
13821 :
13822 : /* See if we can find which clause was failing (for logical AND). */
13823 1973 : tree bad = find_failing_clause (NULL, orig_condition);
13824 : /* If not, or its location is unusable, fall back to the previous
13825 : location. */
13826 1973 : location_t cloc = cp_expr_loc_or_loc (bad, location);
13827 :
13828 1973 : auto_diagnostic_group d;
13829 :
13830 : /* Report the error. */
13831 1973 : if (len == 0)
13832 1261 : error_at (cloc, "static assertion failed");
13833 : else
13834 712 : error_at (cloc, "static assertion failed: %.*s", len, msg);
13835 :
13836 1973 : diagnose_failing_condition (bad, cloc, show_expr_p);
13837 :
13838 : /* Suppress -Wreturn-type for functions with failed static_asserts.
13839 : Otherwise templates like:
13840 : if constexpr (whatever)
13841 : return something (args);
13842 : else
13843 : static_assert (false, "explanation");
13844 : get a useless extra -Wreturn-type warning. */
13845 1973 : if (current_function_decl)
13846 758 : suppress_warning (current_function_decl, OPT_Wreturn_type);
13847 1973 : }
13848 864 : else if (condition && condition != error_mark_node)
13849 : {
13850 858 : error ("non-constant condition for static assertion");
13851 858 : if (require_rvalue_constant_expression (condition))
13852 796 : cxx_constant_value (condition);
13853 : }
13854 8934 : }
13855 11278991 : }
13856 :
13857 : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
13858 : suitable for use as a type-specifier.
13859 :
13860 : ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
13861 : id-expression or a class member access, FALSE when it was parsed as
13862 : a full expression. */
13863 :
13864 : tree
13865 43863945 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
13866 : tsubst_flags_t complain)
13867 : {
13868 43863945 : tree type = NULL_TREE;
13869 :
13870 43863945 : if (!expr || error_operand_p (expr))
13871 241351 : return error_mark_node;
13872 :
13873 43622594 : if (TYPE_P (expr)
13874 43622594 : || TREE_CODE (expr) == TYPE_DECL
13875 87245168 : || (TREE_CODE (expr) == BIT_NOT_EXPR
13876 16146 : && TYPE_P (TREE_OPERAND (expr, 0))))
13877 : {
13878 29 : if (complain & tf_error)
13879 29 : error ("argument to %<decltype%> must be an expression");
13880 29 : return error_mark_node;
13881 : }
13882 :
13883 : /* decltype is an unevaluated context. */
13884 43622565 : cp_unevaluated u;
13885 :
13886 43622565 : processing_template_decl_sentinel ptds (/*reset=*/false);
13887 :
13888 : /* Depending on the resolution of DR 1172, we may later need to distinguish
13889 : instantiation-dependent but not type-dependent expressions so that, say,
13890 : A<decltype(sizeof(T))>::U doesn't require 'typename'. */
13891 43622565 : if (instantiation_dependent_uneval_expression_p (expr))
13892 : {
13893 7330099 : dependent:
13894 7330675 : type = cxx_make_type (DECLTYPE_TYPE);
13895 7330675 : DECLTYPE_TYPE_EXPR (type) = expr;
13896 14661350 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
13897 7330675 : = id_expression_or_member_access_p;
13898 7330675 : SET_TYPE_STRUCTURAL_EQUALITY (type);
13899 :
13900 7330675 : return type;
13901 : }
13902 36292466 : else if (processing_template_decl)
13903 : {
13904 7502 : expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
13905 7502 : if (expr == error_mark_node)
13906 : return error_mark_node;
13907 : /* Keep processing_template_decl cleared for the rest of the function
13908 : (for sake of the call to lvalue_kind below, which handles templated
13909 : and non-templated COND_EXPR differently). */
13910 7465 : processing_template_decl = 0;
13911 : }
13912 :
13913 : /* The type denoted by decltype(e) is defined as follows: */
13914 :
13915 36292429 : expr = resolve_nondeduced_context (expr, complain);
13916 36292429 : if (!mark_single_function (expr, complain))
13917 0 : return error_mark_node;
13918 :
13919 36292429 : if (invalid_nonstatic_memfn_p (input_location, expr, complain))
13920 18 : return error_mark_node;
13921 :
13922 36292411 : if (type_unknown_p (expr))
13923 : {
13924 18 : if (complain & tf_error)
13925 6 : error ("%<decltype%> cannot resolve address of overloaded function");
13926 18 : return error_mark_node;
13927 : }
13928 :
13929 36292393 : if (id_expression_or_member_access_p)
13930 : {
13931 : /* If e is an id-expression or a class member access (5.2.5
13932 : [expr.ref]), decltype(e) is defined as the type of the entity
13933 : named by e. If there is no such entity, or e names a set of
13934 : overloaded functions, the program is ill-formed. */
13935 551018 : if (identifier_p (expr))
13936 0 : expr = lookup_name (expr);
13937 :
13938 : /* If e is a constified expression inside a contract assertion,
13939 : strip the const wrapper. Per P2900R14, "For a function f with the
13940 : return type T , the result name is an lvalue of type const T , decltype(r)
13941 : is T , and decltype((r)) is const T&." */
13942 551018 : expr = strip_contract_const_wrapper (expr);
13943 :
13944 377671 : if (REFERENCE_REF_P (expr)
13945 551023 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
13946 : /* This can happen when the expression is, e.g., "a.b". Just
13947 : look at the underlying operand. */
13948 380942 : expr = TREE_OPERAND (expr, 0);
13949 :
13950 551018 : if (TREE_CODE (expr) == OFFSET_REF
13951 551018 : || TREE_CODE (expr) == MEMBER_REF
13952 551018 : || TREE_CODE (expr) == SCOPE_REF)
13953 : /* We're only interested in the field itself. If it is a
13954 : BASELINK, we will need to see through it in the next
13955 : step. */
13956 0 : expr = TREE_OPERAND (expr, 1);
13957 :
13958 551018 : if (BASELINK_P (expr))
13959 : /* See through BASELINK nodes to the underlying function. */
13960 7 : expr = BASELINK_FUNCTIONS (expr);
13961 :
13962 : /* decltype of a decomposition name drops references in the tuple case
13963 : (unlike decltype of a normal variable) and keeps cv-qualifiers from
13964 : the containing object in the other cases (unlike decltype of a member
13965 : access expression). */
13966 551018 : if (DECL_DECOMPOSITION_P (expr))
13967 : {
13968 1449 : if (ptds.saved)
13969 : {
13970 275 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr)
13971 : || (DECL_CONTEXT (expr)
13972 : != current_function_decl));
13973 : /* DECL_HAS_VALUE_EXPR_P is always set if
13974 : processing_template_decl at least for structured bindings
13975 : within the template. If lookup_decomp_type
13976 : returns non-NULL, it is the tuple case. */
13977 275 : if (tree ret = lookup_decomp_type (expr))
13978 : return ret;
13979 191 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
13980 : }
13981 1365 : if (DECL_HAS_VALUE_EXPR_P (expr))
13982 : /* Expr is an array or struct subobject proxy, handle
13983 : bit-fields properly. */
13984 1021 : return unlowered_expr_type (expr);
13985 : else
13986 : /* Expr is a reference variable for the tuple case. */
13987 344 : return lookup_decomp_type (expr);
13988 : }
13989 :
13990 549569 : switch (TREE_CODE (expr))
13991 : {
13992 650 : case FIELD_DECL:
13993 650 : if (DECL_BIT_FIELD_TYPE (expr))
13994 : {
13995 : type = DECL_BIT_FIELD_TYPE (expr);
13996 : break;
13997 : }
13998 : /* Fall through for fields that aren't bitfields. */
13999 145915 : gcc_fallthrough ();
14000 :
14001 145915 : case VAR_DECL:
14002 145915 : if (is_capture_proxy (expr))
14003 : {
14004 99 : if (is_normal_capture_proxy (expr))
14005 : {
14006 21 : expr = DECL_CAPTURED_VARIABLE (expr);
14007 21 : type = TREE_TYPE (expr);
14008 : }
14009 : else
14010 : {
14011 78 : expr = DECL_VALUE_EXPR (expr);
14012 78 : gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
14013 78 : expr = TREE_OPERAND (expr, 1);
14014 78 : type = TREE_TYPE (expr);
14015 : }
14016 : break;
14017 : }
14018 : /* Fall through for variables that aren't capture proxies. */
14019 538497 : gcc_fallthrough ();
14020 :
14021 538497 : case FUNCTION_DECL:
14022 538497 : case CONST_DECL:
14023 538497 : case PARM_DECL:
14024 538497 : case RESULT_DECL:
14025 538497 : case TEMPLATE_PARM_INDEX:
14026 538497 : expr = mark_type_use (expr);
14027 538497 : type = TREE_TYPE (expr);
14028 538497 : if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
14029 : {
14030 : /* decltype of an NTTP object is the type of the template
14031 : parameter, which is the object type modulo cv-quals. */
14032 2643 : int quals = cp_type_quals (type);
14033 2643 : gcc_checking_assert (quals & TYPE_QUAL_CONST);
14034 2643 : type = cv_unqualified (type);
14035 : }
14036 : break;
14037 :
14038 0 : case ERROR_MARK:
14039 0 : type = error_mark_node;
14040 0 : break;
14041 :
14042 3520 : case COMPONENT_REF:
14043 3520 : case COMPOUND_EXPR:
14044 3520 : mark_type_use (expr);
14045 3520 : type = is_bitfield_expr_with_lowered_type (expr);
14046 3520 : if (!type)
14047 3483 : type = TREE_TYPE (TREE_OPERAND (expr, 1));
14048 : break;
14049 :
14050 0 : case BIT_FIELD_REF:
14051 0 : gcc_unreachable ();
14052 :
14053 3512 : case INTEGER_CST:
14054 3512 : case PTRMEM_CST:
14055 : /* We can get here when the id-expression refers to an
14056 : enumerator or non-type template parameter. */
14057 3512 : type = TREE_TYPE (expr);
14058 3512 : break;
14059 :
14060 3941 : default:
14061 : /* Handle instantiated template non-type arguments. */
14062 3941 : type = TREE_TYPE (expr);
14063 3941 : break;
14064 : }
14065 : }
14066 : else
14067 : {
14068 35741375 : tree decl = STRIP_REFERENCE_REF (expr);
14069 35741375 : tree lam = current_lambda_expr ();
14070 35741375 : if (lam && outer_automatic_var_p (decl))
14071 : {
14072 : /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
14073 : unevaluated operand within S would refer to an entity captured by
14074 : copy in some intervening lambda-expression, then let E be the
14075 : innermost such lambda-expression.
14076 :
14077 : If there is such a lambda-expression and if P is in E's function
14078 : parameter scope but not its parameter-declaration-clause, then the
14079 : type of the expression is the type of a class member access
14080 : expression naming the non-static data member that would be declared
14081 : for such a capture in the object parameter of the function call
14082 : operator of E." */
14083 : /* FIXME: This transformation needs to happen for all uses of an outer
14084 : local variable inside decltype, not just decltype((x)) (PR83167).
14085 : And we don't handle nested lambdas properly, where we need to
14086 : consider the outer lambdas as well (PR112926). */
14087 1379 : tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
14088 : LOOK_want::HIDDEN_LAMBDA);
14089 :
14090 1379 : if (cap && is_capture_proxy (cap))
14091 467 : type = TREE_TYPE (cap);
14092 912 : else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
14093 : {
14094 738 : type = TREE_TYPE (decl);
14095 738 : if (TYPE_REF_P (type)
14096 738 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
14097 36 : type = TREE_TYPE (type);
14098 : }
14099 :
14100 1205 : if (type && !TYPE_REF_P (type))
14101 : {
14102 1121 : cv_qualifier quals;
14103 1121 : if (current_function_decl
14104 2104 : && LAMBDA_FUNCTION_P (current_function_decl)
14105 2104 : && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
14106 : {
14107 900 : tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
14108 900 : if (WILDCARD_TYPE_P (non_reference (obtype)))
14109 : /* We don't know what the eventual obtype quals will be. */
14110 576 : goto dependent;
14111 648 : auto direct_type = [](tree t){
14112 324 : if (INDIRECT_TYPE_P (t))
14113 162 : return TREE_TYPE (t);
14114 : return t;
14115 : };
14116 324 : quals = (cp_type_quals (type)
14117 324 : | cp_type_quals (direct_type (obtype)));
14118 : }
14119 : else
14120 : /* We are in the parameter clause, trailing return type, or
14121 : the requires clause and have no relevant c_f_decl yet. */
14122 349 : quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
14123 221 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
14124 545 : type = cp_build_qualified_type (type, quals);
14125 545 : type = build_reference_type (type);
14126 : }
14127 : }
14128 35739996 : else if (error_operand_p (expr))
14129 0 : type = error_mark_node;
14130 35739996 : else if (expr == current_class_ptr)
14131 : /* If the expression is just "this", we want the
14132 : cv-unqualified pointer for the "this" type. */
14133 0 : type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
14134 :
14135 545 : if (!type)
14136 : {
14137 : /* Otherwise, where T is the type of e, if e is an lvalue,
14138 : decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
14139 35740170 : cp_lvalue_kind clk = lvalue_kind (expr);
14140 35740170 : type = unlowered_expr_type (expr);
14141 35740170 : gcc_assert (!TYPE_REF_P (type));
14142 :
14143 : /* For vector types, pick a non-opaque variant. */
14144 35740170 : if (VECTOR_TYPE_P (type))
14145 4421 : type = strip_typedefs (type);
14146 :
14147 35740170 : if (clk != clk_none && !(clk & clk_class))
14148 8996176 : type = cp_build_reference_type (type, (clk & clk_rvalueref));
14149 : }
14150 : }
14151 :
14152 : return type;
14153 43622565 : }
14154 :
14155 : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
14156 : __has_nothrow_copy, depending on assign_p. Returns true iff all
14157 : the copy {ctor,assign} fns are nothrow. */
14158 :
14159 : static bool
14160 351 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
14161 : {
14162 351 : tree fns = NULL_TREE;
14163 :
14164 351 : if (assign_p || TYPE_HAS_COPY_CTOR (type))
14165 348 : fns = get_class_binding (type, assign_p ? assign_op_identifier
14166 : : ctor_identifier);
14167 :
14168 351 : bool saw_copy = false;
14169 894 : for (ovl_iterator iter (fns); iter; ++iter)
14170 : {
14171 561 : tree fn = *iter;
14172 :
14173 561 : if (copy_fn_p (fn) > 0)
14174 : {
14175 525 : saw_copy = true;
14176 525 : if (!maybe_instantiate_noexcept (fn)
14177 525 : || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
14178 234 : return false;
14179 : }
14180 : }
14181 :
14182 117 : return saw_copy;
14183 : }
14184 :
14185 : /* Return true if BASE is a pointer-interconvertible base of DERIVED. */
14186 :
14187 : bool
14188 183 : pointer_interconvertible_base_of_p (tree base, tree derived,
14189 : bool explain/*=false*/)
14190 : {
14191 183 : if (base == error_mark_node || derived == error_mark_node)
14192 : return false;
14193 :
14194 183 : base = TYPE_MAIN_VARIANT (base);
14195 183 : derived = TYPE_MAIN_VARIANT (derived);
14196 183 : if (!NON_UNION_CLASS_TYPE_P (base))
14197 : {
14198 17 : if (explain)
14199 3 : inform (location_of (base),
14200 : "%qT is not a non-union class type", base);
14201 : return false;
14202 : }
14203 166 : if (!NON_UNION_CLASS_TYPE_P (derived))
14204 : {
14205 8 : if (explain)
14206 3 : inform (location_of (derived),
14207 : "%qT is not a non-union class type", derived);
14208 : return false;
14209 : }
14210 :
14211 158 : if (same_type_p (base, derived))
14212 : return true;
14213 :
14214 117 : if (!std_layout_type_p (derived))
14215 : {
14216 18 : if (explain)
14217 6 : inform (location_of (derived),
14218 : "%qT is not a standard-layout type", derived);
14219 : return false;
14220 : }
14221 :
14222 99 : if (!uniquely_derived_from_p (base, derived))
14223 : {
14224 18 : if (explain)
14225 : {
14226 : /* An ambiguous base should already be impossible due to
14227 : the std_layout_type_p check. */
14228 3 : gcc_checking_assert (!DERIVED_FROM_P (base, derived));
14229 3 : inform (location_of (derived),
14230 : "%qT is not a base of %qT", base, derived);
14231 : }
14232 : return false;
14233 : }
14234 :
14235 : return true;
14236 : }
14237 :
14238 : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
14239 : return true if MEMBERTYPE is the type of the first non-static data member
14240 : of TYPE or for unions of any members. */
14241 : static bool
14242 637 : first_nonstatic_data_member_p (tree type, tree membertype)
14243 : {
14244 1297 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
14245 : {
14246 1222 : if (TREE_CODE (field) != FIELD_DECL)
14247 135 : continue;
14248 1087 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
14249 60 : continue;
14250 1027 : if (DECL_FIELD_IS_BASE (field))
14251 45 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
14252 982 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
14253 : {
14254 216 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
14255 138 : || std_layout_type_p (TREE_TYPE (field)))
14256 294 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
14257 : return true;
14258 : }
14259 766 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
14260 : membertype))
14261 : return true;
14262 537 : if (TREE_CODE (type) != UNION_TYPE)
14263 : return false;
14264 : }
14265 : return false;
14266 : }
14267 :
14268 : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
14269 :
14270 : tree
14271 536 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
14272 : tree *args)
14273 : {
14274 : /* Unless users call the builtin directly, the following 3 checks should be
14275 : ensured from std::is_pointer_interconvertible_with_class function
14276 : template. */
14277 536 : if (nargs != 1)
14278 : {
14279 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
14280 : "needs a single argument");
14281 6 : return boolean_false_node;
14282 : }
14283 530 : tree arg = args[0];
14284 530 : if (error_operand_p (arg))
14285 0 : return boolean_false_node;
14286 530 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
14287 : {
14288 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
14289 : "argument is not pointer to member");
14290 6 : return boolean_false_node;
14291 : }
14292 :
14293 524 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
14294 18 : return boolean_false_node;
14295 :
14296 506 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
14297 506 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
14298 506 : if (!complete_type_or_else (basetype, NULL_TREE))
14299 3 : return boolean_false_node;
14300 :
14301 503 : if (TREE_CODE (basetype) != UNION_TYPE
14302 503 : && !std_layout_type_p (basetype))
14303 22 : return boolean_false_node;
14304 :
14305 481 : if (!first_nonstatic_data_member_p (basetype, membertype))
14306 132 : return boolean_false_node;
14307 :
14308 349 : if (TREE_CODE (arg) == PTRMEM_CST)
14309 68 : arg = cplus_expand_constant (arg);
14310 :
14311 349 : if (integer_nonzerop (arg))
14312 10 : return boolean_false_node;
14313 339 : if (integer_zerop (arg))
14314 71 : return boolean_true_node;
14315 :
14316 268 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
14317 : build_zero_cst (TREE_TYPE (arg)));
14318 : }
14319 :
14320 : /* Helper function for is_corresponding_member_aggr. Return true if
14321 : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
14322 : union or structure BASETYPE. */
14323 :
14324 : static bool
14325 90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
14326 : {
14327 222 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
14328 192 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
14329 36 : continue;
14330 156 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
14331 : membertype))
14332 : {
14333 48 : if (TREE_CODE (arg) != INTEGER_CST
14334 48 : || tree_int_cst_equal (arg, byte_position (field)))
14335 : return true;
14336 : }
14337 108 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
14338 : {
14339 18 : tree narg = arg;
14340 18 : if (TREE_CODE (basetype) != UNION_TYPE
14341 0 : && TREE_CODE (narg) == INTEGER_CST)
14342 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
14343 18 : if (is_corresponding_member_union (TREE_TYPE (field),
14344 : membertype, narg))
14345 : return true;
14346 : }
14347 : return false;
14348 : }
14349 :
14350 : /* Helper function for fold_builtin_is_corresponding_member call.
14351 : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
14352 : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
14353 : boolean_true_node if they are corresponding members, or for
14354 : non-constant ARG2 the highest member offset for corresponding
14355 : members. */
14356 :
14357 : static tree
14358 550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
14359 : tree arg1, tree basetype2, tree membertype2,
14360 : tree arg2)
14361 : {
14362 550 : tree field1 = TYPE_FIELDS (basetype1);
14363 550 : tree field2 = TYPE_FIELDS (basetype2);
14364 550 : tree ret = boolean_false_node;
14365 2376 : while (1)
14366 : {
14367 1463 : bool r = next_common_initial_sequence (field1, field2);
14368 1463 : if (field1 == NULL_TREE || field2 == NULL_TREE)
14369 : break;
14370 1331 : if (r
14371 1038 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
14372 : membertype1)
14373 1841 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
14374 : membertype2))
14375 : {
14376 504 : tree pos = byte_position (field1);
14377 504 : if (TREE_CODE (arg1) == INTEGER_CST
14378 504 : && tree_int_cst_equal (arg1, pos))
14379 : {
14380 92 : if (TREE_CODE (arg2) == INTEGER_CST)
14381 92 : return boolean_true_node;
14382 : return pos;
14383 : }
14384 412 : else if (TREE_CODE (arg1) != INTEGER_CST)
14385 1188 : ret = pos;
14386 : }
14387 1654 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
14388 944 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
14389 : {
14390 117 : if ((!lookup_attribute ("no_unique_address",
14391 117 : DECL_ATTRIBUTES (field1)))
14392 117 : != !lookup_attribute ("no_unique_address",
14393 117 : DECL_ATTRIBUTES (field2)))
14394 : break;
14395 117 : if (!tree_int_cst_equal (bit_position (field1),
14396 117 : bit_position (field2)))
14397 : break;
14398 99 : bool overlap = true;
14399 99 : tree pos = byte_position (field1);
14400 99 : if (TREE_CODE (arg1) == INTEGER_CST)
14401 : {
14402 27 : tree off1 = fold_convert (sizetype, arg1);
14403 27 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
14404 27 : if (tree_int_cst_lt (off1, pos)
14405 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
14406 : overlap = false;
14407 : }
14408 99 : if (TREE_CODE (arg2) == INTEGER_CST)
14409 : {
14410 27 : tree off2 = fold_convert (sizetype, arg2);
14411 27 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
14412 27 : if (tree_int_cst_lt (off2, pos)
14413 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
14414 : overlap = false;
14415 : }
14416 87 : if (overlap
14417 87 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
14418 126 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
14419 : {
14420 39 : tree narg1 = arg1;
14421 39 : if (TREE_CODE (arg1) == INTEGER_CST)
14422 9 : narg1 = size_binop (MINUS_EXPR,
14423 : fold_convert (sizetype, arg1), pos);
14424 39 : tree narg2 = arg2;
14425 39 : if (TREE_CODE (arg2) == INTEGER_CST)
14426 9 : narg2 = size_binop (MINUS_EXPR,
14427 : fold_convert (sizetype, arg2), pos);
14428 39 : tree t1 = TREE_TYPE (field1);
14429 39 : tree t2 = TREE_TYPE (field2);
14430 39 : tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
14431 : narg1, t2, membertype2,
14432 : narg2);
14433 39 : if (nret != boolean_false_node)
14434 : {
14435 39 : if (nret == boolean_true_node)
14436 : return nret;
14437 30 : if (TREE_CODE (arg1) == INTEGER_CST)
14438 0 : return size_binop (PLUS_EXPR, nret, pos);
14439 30 : ret = size_binop (PLUS_EXPR, nret, pos);
14440 : }
14441 : }
14442 60 : else if (overlap
14443 48 : && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
14444 108 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
14445 : {
14446 48 : tree narg1 = arg1;
14447 48 : if (TREE_CODE (arg1) == INTEGER_CST)
14448 6 : narg1 = size_binop (MINUS_EXPR,
14449 : fold_convert (sizetype, arg1), pos);
14450 48 : tree narg2 = arg2;
14451 48 : if (TREE_CODE (arg2) == INTEGER_CST)
14452 6 : narg2 = size_binop (MINUS_EXPR,
14453 : fold_convert (sizetype, arg2), pos);
14454 48 : if (is_corresponding_member_union (TREE_TYPE (field1),
14455 : membertype1, narg1)
14456 48 : && is_corresponding_member_union (TREE_TYPE (field2),
14457 : membertype2, narg2))
14458 : {
14459 24 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
14460 : "not well defined for anonymous unions");
14461 24 : return boolean_false_node;
14462 : }
14463 : }
14464 : }
14465 1188 : if (!r)
14466 : break;
14467 913 : field1 = DECL_CHAIN (field1);
14468 913 : field2 = DECL_CHAIN (field2);
14469 913 : }
14470 : return ret;
14471 : }
14472 :
14473 : /* Fold __builtin_is_corresponding_member call. */
14474 :
14475 : tree
14476 699 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
14477 : tree *args)
14478 : {
14479 : /* Unless users call the builtin directly, the following 3 checks should be
14480 : ensured from std::is_corresponding_member function template. */
14481 699 : if (nargs != 2)
14482 : {
14483 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
14484 : "needs two arguments");
14485 9 : return boolean_false_node;
14486 : }
14487 690 : tree arg1 = args[0];
14488 690 : tree arg2 = args[1];
14489 690 : if (error_operand_p (arg1) || error_operand_p (arg2))
14490 0 : return boolean_false_node;
14491 711 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
14492 705 : || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
14493 : {
14494 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
14495 : "argument is not pointer to member");
14496 9 : return boolean_false_node;
14497 : }
14498 :
14499 681 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
14500 681 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
14501 15 : return boolean_false_node;
14502 :
14503 666 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
14504 666 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
14505 666 : if (!complete_type_or_else (basetype1, NULL_TREE))
14506 12 : return boolean_false_node;
14507 :
14508 654 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
14509 654 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
14510 654 : if (!complete_type_or_else (basetype2, NULL_TREE))
14511 12 : return boolean_false_node;
14512 :
14513 627 : if (!NON_UNION_CLASS_TYPE_P (basetype1)
14514 627 : || !NON_UNION_CLASS_TYPE_P (basetype2)
14515 627 : || !std_layout_type_p (basetype1)
14516 1233 : || !std_layout_type_p (basetype2))
14517 51 : return boolean_false_node;
14518 :
14519 : /* If the member types aren't layout compatible, then they
14520 : can't be corresponding members. */
14521 591 : if (!layout_compatible_type_p (membertype1, membertype2))
14522 18 : return boolean_false_node;
14523 :
14524 573 : if (TREE_CODE (arg1) == PTRMEM_CST)
14525 176 : arg1 = cplus_expand_constant (arg1);
14526 573 : if (TREE_CODE (arg2) == PTRMEM_CST)
14527 182 : arg2 = cplus_expand_constant (arg2);
14528 :
14529 573 : if (null_member_pointer_value_p (arg1)
14530 573 : || null_member_pointer_value_p (arg2))
14531 9 : return boolean_false_node;
14532 :
14533 564 : if (TREE_CODE (arg1) == INTEGER_CST
14534 182 : && TREE_CODE (arg2) == INTEGER_CST
14535 746 : && !tree_int_cst_equal (arg1, arg2))
14536 53 : return boolean_false_node;
14537 :
14538 511 : if (TREE_CODE (arg2) == INTEGER_CST
14539 129 : && TREE_CODE (arg1) != INTEGER_CST)
14540 : {
14541 : std::swap (arg1, arg2);
14542 : std::swap (membertype1, membertype2);
14543 : std::swap (basetype1, basetype2);
14544 : }
14545 :
14546 511 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
14547 : basetype2, membertype2, arg2);
14548 511 : if (TREE_TYPE (ret) == boolean_type_node)
14549 : return ret;
14550 : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
14551 : already returns boolean_{true,false}_node whether those particular
14552 : members are corresponding members or not. Otherwise, if only
14553 : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
14554 : above), it returns boolean_false_node if it is certainly not a
14555 : corresponding member and otherwise we need to do a runtime check that
14556 : those two OFFSET_TYPE offsets are equal.
14557 : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
14558 : returns the largest offset at which the members would be corresponding
14559 : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
14560 304 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
14561 304 : if (TREE_CODE (arg1) == INTEGER_CST)
14562 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
14563 : fold_convert (TREE_TYPE (arg1), arg2));
14564 304 : ret = fold_build2 (LE_EXPR, boolean_type_node,
14565 : fold_convert (pointer_sized_int_node, arg1),
14566 : fold_convert (pointer_sized_int_node, ret));
14567 304 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
14568 : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
14569 : fold_convert (TREE_TYPE (arg1), arg2)));
14570 : }
14571 :
14572 : /* Fold __builtin_is_string_literal call. */
14573 :
14574 : tree
14575 4351 : fold_builtin_is_string_literal (location_t loc, int nargs, tree *args)
14576 : {
14577 : /* Unless users call the builtin directly, the following 3 checks should be
14578 : ensured from std::is_string_literal overloads. */
14579 4351 : if (nargs != 1)
14580 : {
14581 0 : error_at (loc, "%<__builtin_is_string_literal%> needs a single "
14582 : "argument");
14583 0 : return boolean_false_node;
14584 : }
14585 4351 : tree arg = args[0];
14586 4351 : if (error_operand_p (arg))
14587 0 : return boolean_false_node;
14588 4351 : if (!TYPE_PTR_P (TREE_TYPE (arg))
14589 4351 : || !TYPE_READONLY (TREE_TYPE (TREE_TYPE (arg)))
14590 8702 : || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (arg))))
14591 : {
14592 0 : arg_invalid:
14593 0 : error_at (loc, "%<__builtin_is_string_literal%> "
14594 : "argument is not %<const char*%>, %<const wchar_t*%>, "
14595 : "%<const char8_t*%>, %<const char16_t*%> or "
14596 : "%<const char32_t*%>");
14597 0 : return boolean_false_node;
14598 : }
14599 4351 : tree chart = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg)));
14600 4351 : if (chart != char_type_node
14601 3476 : && chart != wchar_type_node
14602 2607 : && chart != char8_type_node
14603 1738 : && chart != char16_type_node
14604 869 : && chart != char32_type_node)
14605 0 : goto arg_invalid;
14606 :
14607 4351 : STRIP_NOPS (arg);
14608 8714 : while (TREE_CODE (arg) == POINTER_PLUS_EXPR)
14609 : {
14610 12 : arg = TREE_OPERAND (arg, 0);
14611 12 : STRIP_NOPS (arg);
14612 : }
14613 4351 : if (TREE_CODE (arg) != ADDR_EXPR)
14614 4295 : return boolean_false_node;
14615 56 : arg = TREE_OPERAND (arg, 0);
14616 56 : if (TREE_CODE (arg) == ARRAY_REF)
14617 24 : arg = TREE_OPERAND (arg, 0);
14618 56 : if (TREE_CODE (arg) != STRING_CST)
14619 16 : return boolean_false_node;
14620 40 : return boolean_true_node;
14621 : }
14622 :
14623 : /* [basic.types] 8. True iff TYPE is an object type. */
14624 :
14625 : static bool
14626 2936655 : object_type_p (const_tree type)
14627 : {
14628 2936655 : return (TREE_CODE (type) != FUNCTION_TYPE
14629 0 : && !TYPE_REF_P (type)
14630 2936655 : && !VOID_TYPE_P (type));
14631 : }
14632 :
14633 : /* [defns.referenceable] True iff TYPE is a referenceable type. */
14634 :
14635 : static bool
14636 3581409 : referenceable_type_p (const_tree type)
14637 : {
14638 3581409 : return (TYPE_REF_P (type)
14639 3581865 : || object_type_p (type)
14640 3581865 : || (FUNC_OR_METHOD_TYPE_P (type)
14641 385 : && type_memfn_quals (type) == TYPE_UNQUALIFIED
14642 319 : && type_memfn_rqual (type) == REF_QUAL_NONE));
14643 : }
14644 :
14645 : /* Actually evaluates the trait. */
14646 :
14647 : static bool
14648 18123154 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
14649 : {
14650 18123154 : enum tree_code type_code1;
14651 18123154 : tree t;
14652 :
14653 18123154 : type_code1 = TREE_CODE (type1);
14654 :
14655 18123154 : switch (kind)
14656 : {
14657 377 : case CPTK_HAS_NOTHROW_ASSIGN:
14658 377 : type1 = strip_array_types (type1);
14659 377 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
14660 715 : && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
14661 206 : || (CLASS_TYPE_P (type1)
14662 156 : && classtype_has_nothrow_assign_or_copy_p (type1,
14663 : true))));
14664 :
14665 254 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
14666 254 : type1 = strip_array_types (type1);
14667 254 : return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
14668 254 : || (CLASS_TYPE_P (type1)
14669 111 : && (t = locate_ctor (type1))
14670 72 : && maybe_instantiate_noexcept (t)
14671 70 : && TYPE_NOTHROW_P (TREE_TYPE (t))));
14672 :
14673 380 : case CPTK_HAS_NOTHROW_COPY:
14674 380 : type1 = strip_array_types (type1);
14675 380 : return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
14676 380 : || (CLASS_TYPE_P (type1)
14677 195 : && classtype_has_nothrow_assign_or_copy_p (type1, false)));
14678 :
14679 613 : case CPTK_HAS_TRIVIAL_ASSIGN:
14680 : /* ??? The standard seems to be missing the "or array of such a class
14681 : type" wording for this trait. */
14682 613 : type1 = strip_array_types (type1);
14683 613 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
14684 1187 : && (trivial_type_p (type1)
14685 364 : || (CLASS_TYPE_P (type1)
14686 267 : && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
14687 :
14688 617 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14689 617 : type1 = strip_array_types (type1);
14690 617 : return (trivial_type_p (type1)
14691 617 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
14692 :
14693 640 : case CPTK_HAS_TRIVIAL_COPY:
14694 : /* ??? The standard seems to be missing the "or array of such a class
14695 : type" wording for this trait. */
14696 640 : type1 = strip_array_types (type1);
14697 1073 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14698 1055 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
14699 :
14700 808 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14701 808 : type1 = strip_array_types (type1);
14702 808 : if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
14703 : {
14704 129 : deferring_access_check_sentinel dacs (dk_no_check);
14705 129 : cp_unevaluated un;
14706 129 : tree fn = get_dtor (type1, tf_none);
14707 129 : if (!fn && !seen_error ())
14708 3 : warning (0, "checking %qs for type %qT with a destructor that "
14709 : "cannot be called", "__has_trivial_destructor", type1);
14710 129 : }
14711 1160 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14712 1157 : || (CLASS_TYPE_P (type1)
14713 299 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
14714 :
14715 61241 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14716 61241 : return type_has_unique_obj_representations (type1);
14717 :
14718 338 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14719 338 : return type_has_virtual_destructor (type1);
14720 :
14721 56424 : case CPTK_IS_ABSTRACT:
14722 56424 : return ABSTRACT_CLASS_TYPE_P (type1);
14723 :
14724 1160 : case CPTK_IS_AGGREGATE:
14725 1160 : return CP_AGGREGATE_TYPE_P (type1);
14726 :
14727 373273 : case CPTK_IS_ARRAY:
14728 373273 : return (type_code1 == ARRAY_TYPE
14729 : /* We don't want to report T[0] as being an array type.
14730 : This is for compatibility with an implementation of
14731 : std::is_array by template argument deduction, because
14732 : compute_array_index_type_loc rejects a zero-size array
14733 : in SFINAE context. */
14734 373273 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14735 :
14736 1031294 : case CPTK_IS_ASSIGNABLE:
14737 1031294 : return is_xible (MODIFY_EXPR, type1, type2);
14738 :
14739 518431 : case CPTK_IS_BASE_OF:
14740 518328 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14741 1017989 : && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
14742 471462 : || DERIVED_FROM_P (type1, type2)));
14743 :
14744 58484 : case CPTK_IS_BOUNDED_ARRAY:
14745 58484 : return (type_code1 == ARRAY_TYPE
14746 1668 : && TYPE_DOMAIN (type1)
14747 : /* We don't want to report T[0] as being a bounded array type.
14748 : This is for compatibility with an implementation of
14749 : std::is_bounded_array by template argument deduction, because
14750 : compute_array_index_type_loc rejects a zero-size array
14751 : in SFINAE context. */
14752 60024 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14753 :
14754 540644 : case CPTK_IS_CLASS:
14755 540644 : return NON_UNION_CLASS_TYPE_P (type1);
14756 :
14757 591047 : case CPTK_IS_CONST:
14758 591047 : return CP_TYPE_CONST_P (type1);
14759 :
14760 2400207 : case CPTK_IS_CONSTRUCTIBLE:
14761 2400207 : return is_xible (INIT_EXPR, type1, type2);
14762 :
14763 3174888 : case CPTK_IS_CONVERTIBLE:
14764 3174888 : return is_convertible (type1, type2);
14765 :
14766 3372 : case CPTK_IS_DESTRUCTIBLE:
14767 3372 : return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14768 :
14769 220709 : case CPTK_IS_EMPTY:
14770 220709 : return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
14771 :
14772 668375 : case CPTK_IS_ENUM:
14773 668375 : return type_code1 == ENUMERAL_TYPE;
14774 :
14775 435886 : case CPTK_IS_FINAL:
14776 435886 : return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
14777 :
14778 47988 : case CPTK_IS_FUNCTION:
14779 47988 : return type_code1 == FUNCTION_TYPE;
14780 :
14781 1401 : case CPTK_IS_IMPLICIT_LIFETIME:
14782 1401 : return implicit_lifetime_type_p (type1);
14783 :
14784 49038 : case CPTK_IS_INVOCABLE:
14785 49038 : return !error_operand_p (build_invoke (type1, type2, tf_none));
14786 :
14787 221 : case CPTK_IS_LAYOUT_COMPATIBLE:
14788 221 : return layout_compatible_type_p (type1, type2);
14789 :
14790 197 : case CPTK_IS_LITERAL_TYPE:
14791 197 : return literal_type_p (type1);
14792 :
14793 48868 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14794 48868 : return TYPE_PTRMEMFUNC_P (type1);
14795 :
14796 48855 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14797 48855 : return TYPE_PTRDATAMEM_P (type1);
14798 :
14799 10960 : case CPTK_IS_MEMBER_POINTER:
14800 10960 : return TYPE_PTRMEM_P (type1);
14801 :
14802 463213 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14803 463213 : return is_nothrow_xible (MODIFY_EXPR, type1, type2);
14804 :
14805 931788 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14806 931788 : return is_nothrow_xible (INIT_EXPR, type1, type2);
14807 :
14808 683 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14809 683 : return is_nothrow_convertible (type1, type2);
14810 :
14811 24041 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14812 24041 : return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14813 :
14814 43916 : case CPTK_IS_NOTHROW_INVOCABLE:
14815 43916 : return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
14816 :
14817 1132776 : case CPTK_IS_OBJECT:
14818 1132776 : return object_type_p (type1);
14819 :
14820 168 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14821 168 : return pointer_interconvertible_base_of_p (type1, type2);
14822 :
14823 11487 : case CPTK_IS_POD:
14824 11487 : return pod_type_p (type1);
14825 :
14826 152337 : case CPTK_IS_POINTER:
14827 152337 : return TYPE_PTR_P (type1);
14828 :
14829 313 : case CPTK_IS_POLYMORPHIC:
14830 313 : return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
14831 :
14832 719569 : case CPTK_IS_REFERENCE:
14833 719569 : return type_code1 == REFERENCE_TYPE;
14834 :
14835 2678764 : case CPTK_IS_SAME:
14836 2678764 : return same_type_p (type1, type2);
14837 :
14838 373 : case CPTK_IS_SCOPED_ENUM:
14839 373 : return SCOPED_ENUM_P (type1);
14840 :
14841 62656 : case CPTK_IS_STD_LAYOUT:
14842 62656 : return std_layout_type_p (type1);
14843 :
14844 58212 : case CPTK_IS_TRIVIAL:
14845 58212 : return trivial_type_p (type1);
14846 :
14847 12890 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14848 12890 : return is_trivially_xible (MODIFY_EXPR, type1, type2);
14849 :
14850 74848 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14851 74848 : return is_trivially_xible (INIT_EXPR, type1, type2);
14852 :
14853 118451 : case CPTK_IS_TRIVIALLY_COPYABLE:
14854 118451 : return trivially_copyable_p (type1);
14855 :
14856 27346 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14857 27346 : return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14858 :
14859 97551 : case CPTK_IS_UNBOUNDED_ARRAY:
14860 97551 : return array_of_unknown_bound_p (type1);
14861 :
14862 272332 : case CPTK_IS_UNION:
14863 272332 : return type_code1 == UNION_TYPE;
14864 :
14865 883 : case CPTK_IS_VIRTUAL_BASE_OF:
14866 803 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14867 1664 : && lookup_base (type2, type1, ba_require_virtual,
14868 : NULL, tf_none) != NULL_TREE);
14869 :
14870 615272 : case CPTK_IS_VOLATILE:
14871 615272 : return CP_TYPE_VOLATILE_P (type1);
14872 :
14873 221681 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14874 221681 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
14875 :
14876 54265 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14877 54265 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
14878 :
14879 85 : case CPTK_IS_DEDUCIBLE:
14880 85 : return type_targs_deducible_from (type1, type2);
14881 :
14882 264 : case CPTK_IS_STRUCTURAL:
14883 264 : return structural_type_p (type1);
14884 :
14885 : /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
14886 : are handled in finish_trait_expr. */
14887 0 : case CPTK_RANK:
14888 0 : case CPTK_TYPE_ORDER:
14889 0 : case CPTK_STRUCTURED_BINDING_SIZE:
14890 0 : gcc_unreachable ();
14891 :
14892 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14893 : case CPTK_##CODE:
14894 : #include "cp-trait.def"
14895 : #undef DEFTRAIT_TYPE
14896 : /* Type-yielding traits are handled in finish_trait_type. */
14897 : break;
14898 : }
14899 :
14900 0 : gcc_unreachable ();
14901 : }
14902 :
14903 : /* Returns true if TYPE meets the requirements for the specified KIND,
14904 : false otherwise.
14905 :
14906 : When KIND == 1, TYPE must be an array of unknown bound,
14907 : or (possibly cv-qualified) void, or a complete type.
14908 :
14909 : When KIND == 2, TYPE must be a complete type, or array of complete type,
14910 : or (possibly cv-qualified) void.
14911 :
14912 : When KIND == 3:
14913 : If TYPE is a non-union class type, it must be complete.
14914 :
14915 : When KIND == 4:
14916 : If TYPE is a class type, it must be complete.
14917 :
14918 : If COMPLAIN is not tf_none, we permerror and return false if that doesn't
14919 : produce a hard error. */
14920 :
14921 : static bool
14922 19055609 : check_trait_type (tree type, int kind, tsubst_flags_t complain)
14923 : {
14924 19055609 : if (type == NULL_TREE)
14925 : return true;
14926 :
14927 19055609 : if (TREE_CODE (type) == TREE_VEC)
14928 : {
14929 6222402 : for (tree arg : tree_vec_range (type))
14930 2727162 : if (!check_trait_type (arg, kind, complain))
14931 123 : return false;
14932 3495240 : return true;
14933 : }
14934 :
14935 15560246 : if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
14936 : return true; // Array of unknown bound. Don't care about completeness.
14937 :
14938 15559367 : if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
14939 : return true; // Not a non-union class type. Don't care about completeness.
14940 :
14941 15444283 : if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
14942 : return true; // Not a class type. Don't care about completeness.
14943 :
14944 15443345 : if (VOID_TYPE_P (type))
14945 : return true;
14946 :
14947 15441674 : type = complete_type (strip_array_types (type));
14948 15441674 : if (!COMPLETE_TYPE_P (type)
14949 : /* If we're not emitting error messages, always return false for
14950 : incomplete types. */
14951 15441674 : && (complain == tf_none
14952 184 : || (cxx_incomplete_type_diagnostic (NULL_TREE, type,
14953 : diagnostics::kind::permerror)
14954 184 : && !flag_permissive)))
14955 889 : return false;
14956 : return true;
14957 : }
14958 :
14959 : /* True iff the conversion (if any) would be a direct reference
14960 : binding, not requiring complete types. This is LWG2939. */
14961 :
14962 : static bool
14963 6675886 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
14964 : {
14965 6675886 : tree from, to;
14966 6675886 : switch (kind)
14967 : {
14968 : /* These put the target type first. */
14969 : case CPTK_IS_CONSTRUCTIBLE:
14970 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14971 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14972 : case CPTK_IS_INVOCABLE:
14973 : case CPTK_IS_NOTHROW_INVOCABLE:
14974 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14975 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14976 : to = type1;
14977 : from = type2;
14978 : break;
14979 :
14980 : /* These put it second. */
14981 3175643 : case CPTK_IS_CONVERTIBLE:
14982 3175643 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14983 3175643 : to = type2;
14984 3175643 : from = type1;
14985 3175643 : break;
14986 :
14987 0 : default:
14988 0 : gcc_unreachable ();
14989 : }
14990 :
14991 6675886 : if (TREE_CODE (to) != REFERENCE_TYPE || !from)
14992 : return false;
14993 907202 : if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
14994 62344 : from = TREE_VEC_ELT (from, 0);
14995 907202 : return (TYPE_P (from)
14996 1804212 : && (same_type_ignoring_top_level_qualifiers_p
14997 897010 : (non_reference (to), non_reference (from))));
14998 : }
14999 :
15000 : /* Helper for finish_trait_expr and tsubst_expr. Handle
15001 : CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
15002 : way. */
15003 :
15004 : tree
15005 276 : finish_structured_binding_size (location_t loc, tree type,
15006 : tsubst_flags_t complain)
15007 : {
15008 276 : if (TYPE_REF_P (type))
15009 : {
15010 105 : if (complain & tf_error)
15011 99 : error_at (loc, "%qs argument %qT is a reference",
15012 : "__builtin_structured_binding_size", type);
15013 105 : return error_mark_node;
15014 : }
15015 171 : HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
15016 171 : if (ret == -1)
15017 60 : return error_mark_node;
15018 111 : return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
15019 : }
15020 :
15021 : /* Process a trait expression. */
15022 :
15023 : tree
15024 21567470 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2,
15025 : tsubst_flags_t complain/*=tf_warning_or_error*/)
15026 : {
15027 21567470 : if (type1 == error_mark_node
15028 21567467 : || type2 == error_mark_node)
15029 : return error_mark_node;
15030 :
15031 21567467 : if (processing_template_decl)
15032 : {
15033 3443543 : tree trait_expr = make_node (TRAIT_EXPR);
15034 3443543 : if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
15035 31473 : TREE_TYPE (trait_expr) = size_type_node;
15036 3412070 : else if (kind == CPTK_TYPE_ORDER)
15037 : {
15038 4631 : tree val = type_order_value (type1, type1);
15039 4631 : if (val != error_mark_node)
15040 4631 : TREE_TYPE (trait_expr) = TREE_TYPE (val);
15041 : }
15042 : else
15043 3407439 : TREE_TYPE (trait_expr) = boolean_type_node;
15044 3443543 : TRAIT_EXPR_TYPE1 (trait_expr) = type1;
15045 3443543 : TRAIT_EXPR_TYPE2 (trait_expr) = type2;
15046 3443543 : TRAIT_EXPR_KIND (trait_expr) = kind;
15047 3443543 : TRAIT_EXPR_LOCATION (trait_expr) = loc;
15048 3443543 : return trait_expr;
15049 : }
15050 :
15051 18123924 : switch (kind)
15052 : {
15053 57533 : case CPTK_HAS_NOTHROW_ASSIGN:
15054 57533 : case CPTK_HAS_TRIVIAL_ASSIGN:
15055 57533 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
15056 57533 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
15057 57533 : case CPTK_HAS_NOTHROW_COPY:
15058 57533 : case CPTK_HAS_TRIVIAL_COPY:
15059 57533 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
15060 57533 : case CPTK_IS_DESTRUCTIBLE:
15061 57533 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
15062 57533 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
15063 57533 : if (!check_trait_type (type1, /*kind=*/1, complain))
15064 57 : return error_mark_node;
15065 : break;
15066 :
15067 312641 : case CPTK_IS_LITERAL_TYPE:
15068 312641 : case CPTK_IS_POD:
15069 312641 : case CPTK_IS_STD_LAYOUT:
15070 312641 : case CPTK_IS_TRIVIAL:
15071 312641 : case CPTK_IS_TRIVIALLY_COPYABLE:
15072 312641 : case CPTK_IS_STRUCTURAL:
15073 312641 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
15074 312641 : if (!check_trait_type (type1, /* kind = */ 2, complain))
15075 133 : return error_mark_node;
15076 : break;
15077 :
15078 277823 : case CPTK_IS_ABSTRACT:
15079 277823 : case CPTK_IS_EMPTY:
15080 277823 : case CPTK_IS_POLYMORPHIC:
15081 277823 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
15082 277823 : if (!check_trait_type (type1, /* kind = */ 3, complain))
15083 39 : return error_mark_node;
15084 : break;
15085 :
15086 : /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
15087 : type to know whether an array is an aggregate, so use kind=4 here. */
15088 438502 : case CPTK_IS_AGGREGATE:
15089 438502 : case CPTK_IS_FINAL:
15090 438502 : case CPTK_IS_IMPLICIT_LIFETIME:
15091 438502 : if (!check_trait_type (type1, /* kind = */ 4, complain))
15092 55 : return error_mark_node;
15093 : break;
15094 :
15095 6675886 : case CPTK_IS_CONSTRUCTIBLE:
15096 6675886 : case CPTK_IS_CONVERTIBLE:
15097 6675886 : case CPTK_IS_INVOCABLE:
15098 6675886 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
15099 6675886 : case CPTK_IS_NOTHROW_CONVERTIBLE:
15100 6675886 : case CPTK_IS_NOTHROW_INVOCABLE:
15101 6675886 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
15102 6675886 : /* Don't check completeness for direct reference binding. */;
15103 6675886 : if (same_type_ref_bind_p (kind, type1, type2))
15104 : break;
15105 7621029 : gcc_fallthrough ();
15106 :
15107 7621029 : case CPTK_IS_ASSIGNABLE:
15108 7621029 : case CPTK_IS_NOTHROW_ASSIGNABLE:
15109 7621029 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
15110 7621029 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
15111 7621029 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
15112 7621029 : if (!check_trait_type (type1, /*kind=*/1, complain)
15113 7621029 : || !check_trait_type (type2, /*kind=*/1, complain))
15114 602 : return error_mark_node;
15115 : break;
15116 :
15117 518626 : case CPTK_IS_BASE_OF:
15118 518626 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
15119 518509 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
15120 499734 : && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
15121 990223 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
15122 : /* We already issued an error. */
15123 27 : return error_mark_node;
15124 : break;
15125 :
15126 910 : case CPTK_IS_VIRTUAL_BASE_OF:
15127 830 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
15128 1718 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
15129 : /* We already issued an error. */
15130 27 : return error_mark_node;
15131 : break;
15132 :
15133 : case CPTK_IS_ARRAY:
15134 : case CPTK_IS_BOUNDED_ARRAY:
15135 : case CPTK_IS_CLASS:
15136 : case CPTK_IS_CONST:
15137 : case CPTK_IS_ENUM:
15138 : case CPTK_IS_FUNCTION:
15139 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
15140 : case CPTK_IS_MEMBER_OBJECT_POINTER:
15141 : case CPTK_IS_MEMBER_POINTER:
15142 : case CPTK_IS_OBJECT:
15143 : case CPTK_IS_POINTER:
15144 : case CPTK_IS_REFERENCE:
15145 : case CPTK_IS_SAME:
15146 : case CPTK_IS_SCOPED_ENUM:
15147 : case CPTK_IS_UNBOUNDED_ARRAY:
15148 : case CPTK_IS_UNION:
15149 : case CPTK_IS_VOLATILE:
15150 : break;
15151 :
15152 : case CPTK_RANK:
15153 : {
15154 : size_t rank = 0;
15155 122 : for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
15156 80 : ++rank;
15157 42 : return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
15158 : loc);
15159 : }
15160 :
15161 460 : case CPTK_TYPE_ORDER:
15162 460 : return maybe_wrap_with_location (type_order_value (type1, type2), loc);
15163 :
15164 279 : case CPTK_STRUCTURED_BINDING_SIZE:
15165 279 : if (!check_trait_type (type1, /* kind = */ 4, complain))
15166 3 : return error_mark_node;
15167 276 : return finish_structured_binding_size (loc, type1, complain);
15168 :
15169 242 : case CPTK_IS_LAYOUT_COMPATIBLE:
15170 242 : if (!array_of_unknown_bound_p (type1)
15171 223 : && TREE_CODE (type1) != VOID_TYPE
15172 456 : && !complete_type_or_maybe_complain (type1, NULL_TREE, complain))
15173 : /* We already issued an error. */
15174 12 : return error_mark_node;
15175 230 : if (!array_of_unknown_bound_p (type2)
15176 203 : && TREE_CODE (type2) != VOID_TYPE
15177 424 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
15178 : /* We already issued an error. */
15179 9 : return error_mark_node;
15180 : break;
15181 :
15182 85 : case CPTK_IS_DEDUCIBLE:
15183 85 : if (!DECL_TYPE_TEMPLATE_P (type1))
15184 : {
15185 0 : error ("%qD is not a class or alias template", type1);
15186 0 : return error_mark_node;
15187 : }
15188 : break;
15189 :
15190 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
15191 : case CPTK_##CODE:
15192 : #include "cp-trait.def"
15193 : #undef DEFTRAIT_TYPE
15194 : /* Type-yielding traits are handled in finish_trait_type. */
15195 0 : gcc_unreachable ();
15196 : }
15197 :
15198 18122182 : tree val = (trait_expr_value (kind, type1, type2)
15199 18122182 : ? boolean_true_node : boolean_false_node);
15200 18122182 : return maybe_wrap_with_location (val, loc);
15201 : }
15202 :
15203 : /* Process a trait type. */
15204 :
15205 : tree
15206 8005072 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
15207 : tsubst_flags_t complain)
15208 : {
15209 8006016 : if (type1 == error_mark_node
15210 8006013 : || type2 == error_mark_node)
15211 : return error_mark_node;
15212 :
15213 8006013 : if (processing_template_decl)
15214 : {
15215 230868 : tree type = cxx_make_type (TRAIT_TYPE);
15216 230868 : TRAIT_TYPE_TYPE1 (type) = type1;
15217 230868 : TRAIT_TYPE_TYPE2 (type) = type2;
15218 230868 : TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
15219 : /* These traits are intended to be used in the definition of the ::type
15220 : member of the corresponding standard library type trait and aren't
15221 : mangleable (and thus won't appear directly in template signatures),
15222 : so structural equality should suffice. */
15223 230868 : SET_TYPE_STRUCTURAL_EQUALITY (type);
15224 230868 : return type;
15225 : }
15226 :
15227 7775145 : switch (kind)
15228 : {
15229 1249299 : case CPTK_ADD_LVALUE_REFERENCE:
15230 : /* [meta.trans.ref]. */
15231 1249299 : if (referenceable_type_p (type1))
15232 1249212 : return cp_build_reference_type (type1, /*rval=*/false);
15233 : return type1;
15234 :
15235 644505 : case CPTK_ADD_POINTER:
15236 : /* [meta.trans.ptr]. */
15237 644505 : if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
15238 : {
15239 644473 : if (TYPE_REF_P (type1))
15240 643272 : type1 = TREE_TYPE (type1);
15241 644473 : return build_pointer_type (type1);
15242 : }
15243 : return type1;
15244 :
15245 1687629 : case CPTK_ADD_RVALUE_REFERENCE:
15246 : /* [meta.trans.ref]. */
15247 1687629 : if (referenceable_type_p (type1))
15248 1687571 : return cp_build_reference_type (type1, /*rval=*/true);
15249 : return type1;
15250 :
15251 238459 : case CPTK_DECAY:
15252 238459 : if (TYPE_REF_P (type1))
15253 43155 : type1 = TREE_TYPE (type1);
15254 :
15255 238459 : if (TREE_CODE (type1) == ARRAY_TYPE)
15256 735 : return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
15257 735 : complain);
15258 237724 : else if (TREE_CODE (type1) == FUNCTION_TYPE)
15259 : return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
15260 : else
15261 237515 : return cv_unqualified (type1);
15262 :
15263 223 : case CPTK_REMOVE_ALL_EXTENTS:
15264 223 : return strip_array_types (type1);
15265 :
15266 997471 : case CPTK_REMOVE_CV:
15267 997471 : return cv_unqualified (type1);
15268 :
15269 479518 : case CPTK_REMOVE_CVREF:
15270 479518 : if (TYPE_REF_P (type1))
15271 182839 : type1 = TREE_TYPE (type1);
15272 479518 : return cv_unqualified (type1);
15273 :
15274 66464 : case CPTK_REMOVE_EXTENT:
15275 66464 : if (TREE_CODE (type1) == ARRAY_TYPE)
15276 9447 : type1 = TREE_TYPE (type1);
15277 : return type1;
15278 :
15279 44902 : case CPTK_REMOVE_POINTER:
15280 44902 : if (TYPE_PTR_P (type1))
15281 42000 : type1 = TREE_TYPE (type1);
15282 : return type1;
15283 :
15284 2205676 : case CPTK_REMOVE_REFERENCE:
15285 2205676 : if (TYPE_REF_P (type1))
15286 1338832 : type1 = TREE_TYPE (type1);
15287 : return type1;
15288 :
15289 112478 : case CPTK_TYPE_PACK_ELEMENT:
15290 112478 : return finish_type_pack_element (type1, type2, complain);
15291 :
15292 48521 : case CPTK_UNDERLYING_TYPE:
15293 48521 : return finish_underlying_type (type1);
15294 :
15295 : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
15296 : case CPTK_##CODE:
15297 : #include "cp-trait.def"
15298 : #undef DEFTRAIT_EXPR
15299 : /* Expression-yielding traits are handled in finish_trait_expr. */
15300 : case CPTK_BASES:
15301 : case CPTK_DIRECT_BASES:
15302 : /* BASES and DIRECT_BASES are handled in finish_bases. */
15303 : break;
15304 : }
15305 :
15306 0 : gcc_unreachable ();
15307 : }
15308 :
15309 : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
15310 : which is ignored for C++. */
15311 :
15312 : void
15313 0 : set_float_const_decimal64 (void)
15314 : {
15315 0 : }
15316 :
15317 : void
15318 0 : clear_float_const_decimal64 (void)
15319 : {
15320 0 : }
15321 :
15322 : bool
15323 1888922 : float_const_decimal64_p (void)
15324 : {
15325 1888922 : return 0;
15326 : }
15327 :
15328 :
15329 : /* Return true if T designates the implied `this' parameter. */
15330 :
15331 : bool
15332 6617454 : is_this_parameter (tree t)
15333 : {
15334 6617454 : if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
15335 : return false;
15336 3856871 : gcc_assert (TREE_CODE (t) == PARM_DECL
15337 : || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
15338 : || (cp_binding_oracle && VAR_P (t)));
15339 : return true;
15340 : }
15341 :
15342 : /* As above, or a C++23 explicit object parameter. */
15343 :
15344 : bool
15345 456 : is_object_parameter (tree t)
15346 : {
15347 456 : if (is_this_parameter (t))
15348 : return true;
15349 91 : if (TREE_CODE (t) != PARM_DECL)
15350 : return false;
15351 34 : tree ctx = DECL_CONTEXT (t);
15352 34 : return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
15353 62 : && t == DECL_ARGUMENTS (ctx));
15354 : }
15355 :
15356 : /* Insert the deduced return type for an auto function. */
15357 :
15358 : void
15359 1212756 : apply_deduced_return_type (tree fco, tree return_type)
15360 : {
15361 1212756 : tree result;
15362 :
15363 1212756 : if (return_type == error_mark_node)
15364 : return;
15365 :
15366 1212753 : if (DECL_CONV_FN_P (fco))
15367 42 : DECL_NAME (fco) = make_conv_op_name (return_type);
15368 :
15369 1212753 : TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
15370 :
15371 1212753 : maybe_update_postconditions (fco);
15372 :
15373 : /* Apply the type to the result object. */
15374 :
15375 1212753 : result = DECL_RESULT (fco);
15376 1212753 : if (result == NULL_TREE)
15377 : return;
15378 1200257 : if (TREE_TYPE (result) == return_type)
15379 : return;
15380 :
15381 1200254 : if (!processing_template_decl && !VOID_TYPE_P (return_type)
15382 2240611 : && !complete_type_or_else (return_type, NULL_TREE))
15383 : return;
15384 :
15385 : /* We already have a DECL_RESULT from start_preparsed_function.
15386 : Now we need to redo the work it and allocate_struct_function
15387 : did to reflect the new type. */
15388 1200254 : result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
15389 1200254 : TYPE_MAIN_VARIANT (return_type));
15390 1200254 : DECL_ARTIFICIAL (result) = 1;
15391 1200254 : DECL_IGNORED_P (result) = 1;
15392 1200254 : cp_apply_type_quals_to_decl (cp_type_quals (return_type),
15393 : result);
15394 1200254 : DECL_RESULT (fco) = result;
15395 :
15396 1200254 : if (!uses_template_parms (fco))
15397 1200254 : if (function *fun = DECL_STRUCT_FUNCTION (fco))
15398 : {
15399 1199244 : bool aggr = aggregate_value_p (result, fco);
15400 : #ifdef PCC_STATIC_STRUCT_RETURN
15401 : fun->returns_pcc_struct = aggr;
15402 : #endif
15403 1199244 : fun->returns_struct = aggr;
15404 : }
15405 : }
15406 :
15407 : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
15408 : this is a right unary fold. Otherwise it is a left unary fold. */
15409 :
15410 : static tree
15411 844078 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
15412 : {
15413 : /* Build a pack expansion (assuming expr has pack type). */
15414 844078 : if (!uses_parameter_packs (expr))
15415 : {
15416 3 : error_at (location_of (expr), "operand of fold expression has no "
15417 : "unexpanded parameter packs");
15418 3 : return error_mark_node;
15419 : }
15420 844075 : tree pack = make_pack_expansion (expr);
15421 :
15422 : /* Build the fold expression. */
15423 844075 : tree code = build_int_cstu (integer_type_node, abs (op));
15424 844075 : tree fold = build_min_nt_loc (loc, dir, code, pack);
15425 844075 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
15426 844075 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
15427 844075 : FOLD_EXPR_OP (fold),
15428 844075 : FOLD_EXPR_MODIFY_P (fold));
15429 844075 : return fold;
15430 : }
15431 :
15432 : tree
15433 26472 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
15434 : {
15435 26472 : return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
15436 : }
15437 :
15438 : tree
15439 817606 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
15440 : {
15441 817606 : return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
15442 : }
15443 :
15444 : /* Build a binary fold expression over EXPR1 and EXPR2. The
15445 : associativity of the fold is determined by EXPR1 and EXPR2 (whichever
15446 : has an unexpanded parameter pack). */
15447 :
15448 : static tree
15449 196706 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
15450 : int op, tree_code dir)
15451 : {
15452 196706 : pack = make_pack_expansion (pack);
15453 196706 : tree code = build_int_cstu (integer_type_node, abs (op));
15454 196706 : tree fold = build_min_nt_loc (loc, dir, code, pack, init);
15455 196706 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
15456 196706 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
15457 196706 : FOLD_EXPR_OP (fold),
15458 196706 : FOLD_EXPR_MODIFY_P (fold));
15459 196706 : return fold;
15460 : }
15461 :
15462 : tree
15463 196706 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
15464 : {
15465 : // Determine which expr has an unexpanded parameter pack and
15466 : // set the pack and initial term.
15467 196706 : bool pack1 = uses_parameter_packs (expr1);
15468 196706 : bool pack2 = uses_parameter_packs (expr2);
15469 196706 : if (pack1 && !pack2)
15470 1101 : return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
15471 195605 : else if (pack2 && !pack1)
15472 195605 : return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
15473 : else
15474 : {
15475 0 : if (pack1)
15476 0 : error ("both arguments in binary fold have unexpanded parameter packs");
15477 : else
15478 0 : error ("no unexpanded parameter packs in binary fold");
15479 : }
15480 0 : return error_mark_node;
15481 : }
15482 :
15483 : /* Finish __builtin_launder (arg). */
15484 :
15485 : tree
15486 13894 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
15487 : {
15488 13894 : tree orig_arg = arg;
15489 13894 : if (!type_dependent_expression_p (arg))
15490 84 : arg = decay_conversion (arg, complain);
15491 13894 : if (error_operand_p (arg))
15492 0 : return error_mark_node;
15493 13894 : if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
15494 : {
15495 24 : error_at (loc, "type %qT of argument to %<__builtin_launder%> "
15496 24 : "is not a pointer to object type", TREE_TYPE (arg));
15497 24 : return error_mark_node;
15498 : }
15499 13870 : if (processing_template_decl)
15500 13810 : arg = orig_arg;
15501 13870 : return build_call_expr_internal_loc (loc, IFN_LAUNDER,
15502 27740 : TREE_TYPE (arg), 1, arg);
15503 : }
15504 :
15505 : /* Finish __builtin_convertvector (arg, type). */
15506 :
15507 : tree
15508 486 : cp_build_vec_convert (tree arg, location_t loc, tree type,
15509 : tsubst_flags_t complain)
15510 : {
15511 486 : if (error_operand_p (type))
15512 9 : return error_mark_node;
15513 477 : if (error_operand_p (arg))
15514 0 : return error_mark_node;
15515 :
15516 477 : tree ret = NULL_TREE;
15517 477 : if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
15518 439 : ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
15519 : decay_conversion (arg, complain),
15520 : loc, type, (complain & tf_error) != 0);
15521 :
15522 477 : if (!processing_template_decl)
15523 : return ret;
15524 :
15525 80 : return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
15526 : }
15527 :
15528 : /* Finish __builtin_bit_cast (type, arg). */
15529 :
15530 : tree
15531 291065 : cp_build_bit_cast (location_t loc, tree type, tree arg,
15532 : tsubst_flags_t complain)
15533 : {
15534 291065 : if (error_operand_p (type))
15535 0 : return error_mark_node;
15536 291065 : if (!dependent_type_p (type))
15537 : {
15538 210996 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
15539 9 : return error_mark_node;
15540 210987 : if (TREE_CODE (type) == ARRAY_TYPE)
15541 : {
15542 : /* std::bit_cast for destination ARRAY_TYPE is not possible,
15543 : as functions may not return an array, so don't bother trying
15544 : to support this (and then deal with VLAs etc.). */
15545 9 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
15546 : "is an array type", type);
15547 9 : return error_mark_node;
15548 : }
15549 210978 : if (!trivially_copyable_p (type))
15550 : {
15551 18 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
15552 : "is not trivially copyable", type);
15553 18 : return error_mark_node;
15554 : }
15555 : }
15556 :
15557 291029 : if (error_operand_p (arg))
15558 0 : return error_mark_node;
15559 :
15560 291029 : if (!type_dependent_expression_p (arg))
15561 : {
15562 114664 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
15563 : {
15564 : /* Don't perform array-to-pointer conversion. */
15565 375 : arg = mark_rvalue_use (arg, loc, true);
15566 375 : if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
15567 0 : return error_mark_node;
15568 : }
15569 : else
15570 114289 : arg = decay_conversion (arg, complain);
15571 :
15572 114664 : if (error_operand_p (arg))
15573 12 : return error_mark_node;
15574 :
15575 114652 : if (!trivially_copyable_p (TREE_TYPE (arg)))
15576 : {
15577 9 : error_at (cp_expr_loc_or_loc (arg, loc),
15578 : "%<__builtin_bit_cast%> source type %qT "
15579 9 : "is not trivially copyable", TREE_TYPE (arg));
15580 9 : return error_mark_node;
15581 : }
15582 114643 : if (!dependent_type_p (type)
15583 191126 : && !cp_tree_equal (TYPE_SIZE_UNIT (type),
15584 76483 : TYPE_SIZE_UNIT (TREE_TYPE (arg))))
15585 : {
15586 18 : error_at (loc, "%<__builtin_bit_cast%> source size %qE "
15587 : "not equal to destination type size %qE",
15588 18 : TYPE_SIZE_UNIT (TREE_TYPE (arg)),
15589 18 : TYPE_SIZE_UNIT (type));
15590 18 : return error_mark_node;
15591 : }
15592 : }
15593 :
15594 290990 : tree ret = build_min (BIT_CAST_EXPR, type, arg);
15595 290990 : SET_EXPR_LOCATION (ret, loc);
15596 :
15597 290990 : if (!processing_template_decl && CLASS_TYPE_P (type))
15598 874 : ret = get_target_expr (ret, complain);
15599 :
15600 : return ret;
15601 : }
15602 :
15603 : /* Diagnose invalid #pragma GCC unroll argument and adjust
15604 : it if needed. */
15605 :
15606 : tree
15607 24118 : cp_check_pragma_unroll (location_t loc, tree unroll)
15608 : {
15609 24118 : HOST_WIDE_INT lunroll = 0;
15610 24118 : if (type_dependent_expression_p (unroll))
15611 : ;
15612 48164 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
15613 48118 : || (!value_dependent_expression_p (unroll)
15614 24006 : && (!tree_fits_shwi_p (unroll)
15615 23980 : || (lunroll = tree_to_shwi (unroll)) < 0
15616 23965 : || lunroll >= USHRT_MAX)))
15617 : {
15618 90 : error_at (loc, "%<#pragma GCC unroll%> requires an"
15619 : " assignment-expression that evaluates to a non-negative"
15620 : " integral constant less than %u", USHRT_MAX);
15621 90 : unroll = integer_one_node;
15622 : }
15623 23992 : else if (TREE_CODE (unroll) == INTEGER_CST)
15624 : {
15625 23962 : unroll = fold_convert (integer_type_node, unroll);
15626 23962 : if (integer_zerop (unroll))
15627 12 : unroll = integer_one_node;
15628 : }
15629 24118 : return unroll;
15630 : }
15631 :
15632 : #include "gt-cp-semantics.h"
|