Line data Source code
1 : /* Perform the semantic phase of parsing, i.e., the process of
2 : building tree structure, checking semantic consistency, and
3 : building RTL. These routines are used both during actual parsing
4 : and during the instantiation of template functions.
5 :
6 : Copyright (C) 1998-2026 Free Software Foundation, Inc.
7 : Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 : formerly in parse.y and pt.cc.
9 :
10 : This file is part of GCC.
11 :
12 : GCC is free software; you can redistribute it and/or modify it
13 : under the terms of the GNU General Public License as published by
14 : the Free Software Foundation; either version 3, or (at your option)
15 : any later version.
16 :
17 : GCC is distributed in the hope that it will be useful, but
18 : WITHOUT ANY WARRANTY; without even the implied warranty of
19 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 : General Public License for more details.
21 :
22 : You should have received a copy of the GNU General Public License
23 : along with GCC; see the file COPYING3. If not see
24 : <http://www.gnu.org/licenses/>. */
25 :
26 : #include "config.h"
27 : #include "system.h"
28 : #include "coretypes.h"
29 : #include "target.h"
30 : #include "bitmap.h"
31 : #include "cp-tree.h"
32 : #include "stringpool.h"
33 : #include "cgraph.h"
34 : #include "stmt.h"
35 : #include "varasm.h"
36 : #include "stor-layout.h"
37 : #include "c-family/c-objc.h"
38 : #include "tree-inline.h"
39 : #include "intl.h"
40 : #include "tree-iterator.h"
41 : #include "omp-general.h"
42 : #include "convert.h"
43 : #include "stringpool.h"
44 : #include "attribs.h"
45 : #include "gomp-constants.h"
46 : #include "predict.h"
47 : #include "memmodel.h"
48 : #include "gimplify.h"
49 : #include "contracts.h"
50 : #include "c-family/c-pragma.h"
51 :
52 : /* There routines provide a modular interface to perform many parsing
53 : operations. They may therefore be used during actual parsing, or
54 : during template instantiation, which may be regarded as a
55 : degenerate form of parsing. */
56 :
57 : static tree finalize_nrv_r (tree *, int *, void *);
58 :
59 : /* Used for OpenMP non-static data member privatization. */
60 :
61 : static hash_map<tree, tree> *omp_private_member_map;
62 : static vec<tree> omp_private_member_vec;
63 : static bool omp_private_member_ignore_next;
64 :
65 :
66 : /* Deferred Access Checking Overview
67 : ---------------------------------
68 :
69 : Most C++ expressions and declarations require access checking
70 : to be performed during parsing. However, in several cases,
71 : this has to be treated differently.
72 :
73 : For member declarations, access checking has to be deferred
74 : until more information about the declaration is known. For
75 : example:
76 :
77 : class A {
78 : typedef int X;
79 : public:
80 : X f();
81 : };
82 :
83 : A::X A::f();
84 : A::X g();
85 :
86 : When we are parsing the function return type `A::X', we don't
87 : really know if this is allowed until we parse the function name.
88 :
89 : Furthermore, some contexts require that access checking is
90 : never performed at all. These include class heads, and template
91 : instantiations.
92 :
93 : Typical use of access checking functions is described here:
94 :
95 : 1. When we enter a context that requires certain access checking
96 : mode, the function `push_deferring_access_checks' is called with
97 : DEFERRING argument specifying the desired mode. Access checking
98 : may be performed immediately (dk_no_deferred), deferred
99 : (dk_deferred), or not performed (dk_no_check).
100 :
101 : 2. When a declaration such as a type, or a variable, is encountered,
102 : the function `perform_or_defer_access_check' is called. It
103 : maintains a vector of all deferred checks.
104 :
105 : 3. The global `current_class_type' or `current_function_decl' is then
106 : setup by the parser. `enforce_access' relies on these information
107 : to check access.
108 :
109 : 4. Upon exiting the context mentioned in step 1,
110 : `perform_deferred_access_checks' is called to check all declaration
111 : stored in the vector. `pop_deferring_access_checks' is then
112 : called to restore the previous access checking mode.
113 :
114 : In case of parsing error, we simply call `pop_deferring_access_checks'
115 : without `perform_deferred_access_checks'. */
116 :
117 : struct GTY(()) deferred_access {
118 : /* A vector representing name-lookups for which we have deferred
119 : checking access controls. We cannot check the accessibility of
120 : names used in a decl-specifier-seq until we know what is being
121 : declared because code like:
122 :
123 : class A {
124 : class B {};
125 : B* f();
126 : }
127 :
128 : A::B* A::f() { return 0; }
129 :
130 : is valid, even though `A::B' is not generally accessible. */
131 : vec<deferred_access_check, va_gc> *deferred_access_checks;
132 :
133 : /* The current mode of access checks. */
134 : enum deferring_kind deferring_access_checks_kind;
135 : };
136 :
137 : /* Data for deferred access checking. */
138 : static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack;
139 : static GTY(()) unsigned deferred_access_no_check;
140 :
141 : /* Save the current deferred access states and start deferred
142 : access checking iff DEFER_P is true. */
143 :
144 : void
145 24306679474 : push_deferring_access_checks (deferring_kind deferring)
146 : {
147 : /* For context like template instantiation, access checking
148 : disabling applies to all nested context. */
149 24306679474 : if (deferred_access_no_check || deferring == dk_no_check)
150 313772491 : deferred_access_no_check++;
151 : else
152 : {
153 23992906983 : deferred_access e = {NULL, deferring};
154 23992906983 : vec_safe_push (deferred_access_stack, e);
155 : }
156 24306679474 : }
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 389941938 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
163 : {
164 389941938 : push_deferring_access_checks (dk_deferred);
165 389941938 : if (!deferred_access_no_check)
166 382116700 : deferred_access_stack->last().deferred_access_checks = checks;
167 389941938 : }
168 :
169 : /* Resume deferring access checks again after we stopped doing
170 : this previously. */
171 :
172 : void
173 185292186 : resume_deferring_access_checks (void)
174 : {
175 185292186 : if (!deferred_access_no_check)
176 185271857 : deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
177 185292186 : }
178 :
179 : /* Stop deferring access checks. */
180 :
181 : void
182 520336152 : stop_deferring_access_checks (void)
183 : {
184 520336152 : if (!deferred_access_no_check)
185 520275895 : deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
186 520336152 : }
187 :
188 : /* Discard the current deferred access checks and restore the
189 : previous states. */
190 :
191 : void
192 15068868764 : pop_deferring_access_checks (void)
193 : {
194 15068868764 : if (deferred_access_no_check)
195 240372469 : deferred_access_no_check--;
196 : else
197 14828496295 : deferred_access_stack->pop ();
198 15068868764 : }
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 1299931273 : get_deferred_access_checks (void)
207 : {
208 1299931273 : if (deferred_access_no_check)
209 : return NULL;
210 : else
211 1283823414 : 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 9237673856 : pop_to_parent_deferring_access_checks (void)
220 : {
221 9237673856 : if (deferred_access_no_check)
222 73400016 : deferred_access_no_check--;
223 : else
224 : {
225 9164273840 : vec<deferred_access_check, va_gc> *checks;
226 9164273840 : deferred_access *ptr;
227 :
228 9164273840 : checks = (deferred_access_stack->last ().deferred_access_checks);
229 :
230 9164273840 : deferred_access_stack->pop ();
231 9164273840 : ptr = &deferred_access_stack->last ();
232 9164273840 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
233 : {
234 : /* Check access. */
235 577543286 : 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 8792791814 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
244 : {
245 111992796 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
246 : {
247 9947041 : if (probe->binfo == chk->binfo &&
248 7867801 : probe->decl == chk->decl &&
249 985815 : probe->diag_decl == chk->diag_decl)
250 984875 : goto found;
251 : }
252 : /* Insert into parent's checks. */
253 102045755 : vec_safe_push (ptr->deferred_access_checks, *chk);
254 103030630 : found:;
255 : }
256 : }
257 : }
258 9237673856 : }
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 422255920 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
334 : tsubst_flags_t complain, access_failure_info *afi = NULL)
335 : {
336 422255920 : gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
337 :
338 422255920 : if (flag_new_inheriting_ctors
339 533441603 : && 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 62505 : decl = strip_inheriting_ctors (decl);
345 62505 : basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
346 : ba_any, NULL, complain);
347 : }
348 :
349 422255920 : tree cs = current_scope ();
350 422255920 : if (in_template_context
351 422255920 : && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
352 42381015 : 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 42134390 : 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 380121530 : if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
382 : {
383 22348 : if (flag_new_inheriting_ctors)
384 22318 : diag_decl = strip_inheriting_ctors (diag_decl);
385 22348 : if (complain & tf_error)
386 : {
387 1153 : 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 1153 : 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 1153 : 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 1153 : 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 1153 : complain_about_access (decl, diag_decl, diag_location, true,
413 : access_failure_reason);
414 : }
415 22348 : if (afi)
416 412 : afi->record_access_failure (basetype_path, decl, diag_decl);
417 22348 : 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 1106695796 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
431 : tsubst_flags_t complain)
432 : {
433 1106695796 : int i;
434 1106695796 : deferred_access_check *chk;
435 1106695796 : location_t loc = input_location;
436 1106695796 : bool ok = true;
437 :
438 1106695796 : if (!checks)
439 : return true;
440 :
441 128909416 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
442 : {
443 71747103 : input_location = chk->loc;
444 71747103 : ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
445 : }
446 :
447 57162313 : input_location = loc;
448 57162313 : 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 289179599 : perform_deferred_access_checks (tsubst_flags_t complain)
469 : {
470 289179599 : 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 629588122 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
480 : tsubst_flags_t complain,
481 : access_failure_info *afi)
482 : {
483 629588122 : int i;
484 629588122 : deferred_access *ptr;
485 629588122 : deferred_access_check *chk;
486 :
487 : /* Exit if we are in a context that no access checking is performed. */
488 629588122 : if (deferred_access_no_check)
489 : return true;
490 :
491 603986858 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
492 :
493 603986858 : ptr = &deferred_access_stack->last ();
494 :
495 : /* If we are not supposed to defer access checks, just check now. */
496 603986858 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
497 : {
498 350508817 : bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
499 531973951 : return (complain & tf_error) ? true : ok;
500 : }
501 :
502 : /* See if we are already going to perform this check. */
503 308385104 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
504 : {
505 72070469 : if (chk->decl == decl && chk->binfo == binfo &&
506 17164461 : chk->diag_decl == diag_decl)
507 : {
508 : return true;
509 : }
510 : }
511 : /* If not, record the check. */
512 236314635 : deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
513 236314635 : vec_safe_push (ptr->deferred_access_checks, new_access);
514 :
515 236314635 : 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 1520503279 : stmts_are_full_exprs_p (void)
524 : {
525 1520503279 : 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 1313491289 : add_stmt (tree t)
534 : {
535 1313491289 : enum tree_code code = TREE_CODE (t);
536 :
537 1313491289 : if (EXPR_P (t) && code != LABEL_EXPR)
538 : {
539 1262847672 : if (!EXPR_HAS_LOCATION (t))
540 201759327 : 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 1262847672 : if (STATEMENT_CODE_P (TREE_CODE (t)))
545 328894671 : STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
546 : }
547 :
548 1313491289 : if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
549 5823161 : 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 1313491289 : gcc_checking_assert (!stmt_list_stack->is_empty ());
554 1313491289 : append_to_statement_list_force (t, &cur_stmt_list);
555 :
556 1313491289 : return t;
557 : }
558 :
559 : /* Returns the stmt_tree to which statements are currently being added. */
560 :
561 : stmt_tree
562 7776067903 : current_stmt_tree (void)
563 : {
564 7776067903 : return (cfun
565 7737267070 : ? &cfun->language->base.x_stmt_tree
566 7776067903 : : &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 323662 : maybe_cleanup_point_expr (tree expr)
573 : {
574 323662 : if (!processing_template_decl && stmts_are_full_exprs_p ())
575 310181 : expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
576 323662 : 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 325793853 : maybe_cleanup_point_expr_void (tree expr)
586 : {
587 325793853 : if (!processing_template_decl && stmts_are_full_exprs_p ())
588 109058313 : expr = fold_build_cleanup_point_expr (void_type_node, expr);
589 325793853 : return expr;
590 : }
591 :
592 :
593 :
594 : /* Create a declaration statement for the declaration given by the DECL. */
595 :
596 : void
597 110067621 : add_decl_expr (tree decl)
598 : {
599 110067621 : tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
600 110067621 : if (DECL_INITIAL (decl)
601 110067621 : || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
602 19689706 : r = maybe_cleanup_point_expr_void (r);
603 110067621 : add_stmt (r);
604 110067621 : }
605 :
606 : /* Set EXPR_LOCATION on one cleanup T to LOC. */
607 :
608 : static void
609 5853847 : set_one_cleanup_loc (tree t, location_t loc)
610 : {
611 5853847 : if (!t)
612 : return;
613 :
614 5853847 : if (TREE_CODE (t) != POSTCONDITION_STMT)
615 5853847 : 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 5853847 : if (TREE_CODE (t) == NOP_EXPR
622 0 : && TREE_TYPE (t) == void_type_node
623 5853847 : && 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 1239951364 : set_cleanup_locs (tree stmts, location_t loc)
631 : {
632 1245805211 : if (TREE_CODE (stmts) == CLEANUP_STMT)
633 : {
634 5853847 : set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
635 5853847 : set_cleanup_locs (CLEANUP_BODY (stmts), loc);
636 : }
637 1239951364 : else if (TREE_CODE (stmts) == STATEMENT_LIST)
638 1102882913 : for (tree stmt : tsi_range (stmts))
639 854155445 : set_cleanup_locs (stmt, loc);
640 1239951364 : }
641 :
642 : /* True iff the innermost block scope is a try block. */
643 :
644 : static bool
645 385795919 : at_try_scope ()
646 : {
647 385795919 : cp_binding_level *b = current_binding_level;
648 385796369 : while (b && b->kind == sk_cleanup)
649 450 : b = b->level_chain;
650 385795919 : return b && b->kind == sk_try;
651 : }
652 :
653 : /* Finish a scope. */
654 :
655 : tree
656 385795919 : do_poplevel (tree stmt_list)
657 : {
658 385795919 : tree block = NULL;
659 :
660 385795919 : bool was_try = at_try_scope ();
661 :
662 385795919 : if (stmts_are_full_exprs_p ())
663 385733036 : block = poplevel (kept_level_p (), 1, 0);
664 :
665 : /* This needs to come after poplevel merges sk_cleanup statement_lists. */
666 385795919 : maybe_splice_retval_cleanup (stmt_list, was_try);
667 :
668 385795919 : stmt_list = pop_stmt_list (stmt_list);
669 :
670 : /* input_location is the last token of the scope, usually a }. */
671 385795919 : set_cleanup_locs (stmt_list, input_location);
672 :
673 385795919 : if (!processing_template_decl)
674 : {
675 118566088 : stmt_list = c_build_bind_expr (input_location, block, stmt_list);
676 : /* ??? See c_end_compound_stmt re statement expressions. */
677 : }
678 :
679 385795919 : return stmt_list;
680 : }
681 :
682 : /* Begin a new scope. */
683 :
684 : tree
685 385758226 : do_pushlevel (scope_kind sk)
686 : {
687 385758226 : tree ret = push_stmt_list ();
688 385758226 : if (stmts_are_full_exprs_p ())
689 385733090 : begin_scope (sk, NULL);
690 385758226 : 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 5853780 : push_cleanup (tree decl, tree cleanup, bool eh_only)
700 : {
701 5853780 : tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
702 5853780 : CLEANUP_EH_ONLY (stmt) = eh_only;
703 5853780 : add_stmt (stmt);
704 5853780 : CLEANUP_BODY (stmt) = push_stmt_list ();
705 5853780 : }
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 18421839 : begin_maybe_infinite_loop (tree cond)
716 : {
717 : /* Only track this while parsing a function, not during instantiation. */
718 18421839 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
719 2702543 : && !processing_template_decl))
720 : return;
721 15718798 : bool maybe_infinite = true;
722 15718798 : if (cond)
723 : {
724 15407957 : cond = fold_non_dependent_expr (cond);
725 15407957 : maybe_infinite = integer_nonzerop (cond);
726 : }
727 31126755 : vec_safe_push (cp_function_chain->infinite_loops,
728 15718798 : 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 1535259 : break_maybe_infinite_loop (void)
736 : {
737 1535259 : if (!cfun)
738 : return;
739 1535259 : 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 18421839 : end_maybe_infinite_loop (tree cond)
747 : {
748 18421839 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
749 2702543 : && !processing_template_decl))
750 : return;
751 15718798 : tree current = cp_function_chain->infinite_loops->pop();
752 15718798 : if (current != NULL_TREE)
753 : {
754 5084605 : cond = fold_non_dependent_expr (cond);
755 5084605 : if (integer_nonzerop (cond))
756 315475 : 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 89024951 : begin_cond (tree *cond_p)
767 : {
768 89024951 : if (processing_template_decl)
769 63136609 : *cond_p = push_stmt_list ();
770 89024951 : }
771 :
772 : /* Finish such a conditional. */
773 :
774 : static void
775 89024951 : finish_cond (tree *cond_p, tree expr)
776 : {
777 89024951 : if (processing_template_decl)
778 : {
779 63136609 : tree cond = pop_stmt_list (*cond_p);
780 :
781 63136609 : if (expr == NULL_TREE)
782 : /* Empty condition in 'for'. */
783 290133 : gcc_assert (empty_expr_stmt_p (cond));
784 62846476 : else if (check_for_bare_parameter_packs (expr))
785 0 : expr = error_mark_node;
786 62846476 : else if (!empty_expr_stmt_p (cond))
787 935091 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
788 : }
789 89024951 : *cond_p = expr;
790 89024951 : }
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 12412455 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
809 : {
810 12412455 : if (!TREE_SIDE_EFFECTS (*body_p))
811 12402721 : return;
812 :
813 9734 : gcc_assert (!processing_template_decl);
814 9734 : *prep_p = *body_p;
815 9734 : 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 9734 : current_binding_level->keep = true;
840 9734 : 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 9734 : if (tsi_end_p (iter))
847 91 : *body_p = NULL_TREE;
848 : else
849 9643 : *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 9734 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
862 : {
863 9734 : *prep_p = do_poplevel (*prep_p);
864 9734 : gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
865 9734 : 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 9716 : tree stmt_list = BIND_EXPR_BODY (*prep_p);
872 9716 : gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
873 9716 : 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 9625 : tree_stmt_iterator iter = tsi_start (stmt_list);
893 9857 : while (tsi_stmt (iter) != *body_p)
894 232 : tsi_next (&iter);
895 9625 : *body_p = tsi_split_stmt_list (input_location, iter);
896 : }
897 :
898 : /* Finish a goto-statement. */
899 :
900 : tree
901 2713 : finish_goto_stmt (tree destination)
902 : {
903 2713 : if (identifier_p (destination))
904 2576 : 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 2713 : if (TREE_CODE (destination) == LABEL_DECL)
909 2576 : TREE_USED (destination) = 1;
910 : else
911 : {
912 137 : destination = mark_rvalue_use (destination);
913 137 : if (!processing_template_decl)
914 : {
915 117 : destination = cp_convert (ptr_type_node, destination,
916 : tf_warning_or_error);
917 117 : if (error_operand_p (destination))
918 : return NULL_TREE;
919 108 : destination
920 108 : = fold_build_cleanup_point_expr (TREE_TYPE (destination),
921 : destination);
922 : }
923 : }
924 :
925 2704 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
926 :
927 2704 : tree stmt = build_stmt (input_location, GOTO_EXPR, destination);
928 2704 : check_goto (&TREE_OPERAND (stmt, 0));
929 :
930 2704 : return add_stmt (stmt);
931 : }
932 :
933 : /* Returns true if T corresponds to an assignment operator expression. */
934 :
935 : static bool
936 875488 : is_assignment_op_expr_p (tree t)
937 : {
938 875488 : if (t == NULL_TREE)
939 : return false;
940 :
941 875488 : if (TREE_CODE (t) == MODIFY_EXPR
942 875488 : || (TREE_CODE (t) == MODOP_EXPR
943 336 : && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
944 : return true;
945 :
946 874801 : tree call = extract_call_expr (t);
947 874801 : if (call == NULL_TREE
948 129556 : || call == error_mark_node
949 1004357 : || !CALL_EXPR_OPERATOR_SYNTAX (call))
950 : return false;
951 :
952 4650 : tree fndecl = cp_get_callee_fndecl_nofold (call);
953 4650 : return fndecl != NULL_TREE
954 4552 : && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
955 4701 : && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR);
956 : }
957 :
958 : /* Return true if TYPE is a class type that is convertible to
959 : and assignable from bool. */
960 :
961 : static GTY((deletable)) hash_map<tree, bool> *boolish_class_type_p_cache;
962 :
963 : static bool
964 60 : boolish_class_type_p (tree type)
965 : {
966 60 : type = TYPE_MAIN_VARIANT (type);
967 60 : if (!CLASS_TYPE_P (type) || !COMPLETE_TYPE_P (type))
968 : return false;
969 :
970 77 : if (bool *r = hash_map_safe_get (boolish_class_type_p_cache, type))
971 26 : return *r;
972 :
973 19 : tree ops;
974 19 : bool has_bool_assignment = false;
975 19 : bool has_bool_conversion = false;
976 :
977 19 : ops = lookup_fnfields (type, assign_op_identifier, /*protect=*/0, tf_none);
978 58 : for (tree op : ovl_range (BASELINK_FUNCTIONS (ops)))
979 : {
980 31 : op = STRIP_TEMPLATE (op);
981 31 : if (TREE_CODE (op) != FUNCTION_DECL)
982 0 : continue;
983 31 : tree parm = DECL_CHAIN (DECL_ARGUMENTS (op));
984 31 : tree parm_type = non_reference (TREE_TYPE (parm));
985 31 : if (TREE_CODE (parm_type) == BOOLEAN_TYPE)
986 : {
987 : has_bool_assignment = true;
988 : break;
989 : }
990 : }
991 :
992 19 : if (has_bool_assignment)
993 : {
994 4 : ops = lookup_conversions (type);
995 4 : for (; ops; ops = TREE_CHAIN (ops))
996 : {
997 4 : tree op = TREE_VALUE (ops);
998 4 : if (!DECL_NONCONVERTING_P (op)
999 4 : && TREE_CODE (DECL_CONV_FN_TYPE (op)) == BOOLEAN_TYPE)
1000 : {
1001 : has_bool_conversion = true;
1002 : break;
1003 : }
1004 : }
1005 : }
1006 :
1007 19 : bool boolish = has_bool_assignment && has_bool_conversion;
1008 19 : hash_map_safe_put<true> (boolish_class_type_p_cache, type, boolish);
1009 19 : return boolish;
1010 : }
1011 :
1012 :
1013 : /* Maybe warn about an unparenthesized 'a = b' (appearing in a
1014 : boolean context where 'a == b' might have been intended).
1015 : NESTED_P is true if T is the RHS of another assignment. */
1016 :
1017 : void
1018 91904904 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
1019 : tsubst_flags_t complain)
1020 : {
1021 91904904 : tree type = TREE_TYPE (t);
1022 91904904 : t = STRIP_REFERENCE_REF (t);
1023 :
1024 91904904 : if ((complain & tf_warning)
1025 91843464 : && warn_parentheses
1026 875488 : && 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 91905251 : && (!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 91904904 : }
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 54230713 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
1072 : {
1073 54230713 : tree *t = cond;
1074 54241060 : while (TREE_CODE (*t) == ANNOTATE_EXPR)
1075 10347 : t = &TREE_OPERAND (*t, 0);
1076 :
1077 54230713 : if (t != cond)
1078 : {
1079 10344 : m_annotations = *cond;
1080 10344 : *cond = *t;
1081 10344 : m_inner = t;
1082 : }
1083 54230713 : }
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 54230713 : annotate_saver::restore (tree new_inner)
1092 : {
1093 54230713 : 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 10344 : 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 10344 : *m_inner = new_inner;
1118 10344 : 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 94048383 : maybe_convert_cond (tree cond)
1127 : {
1128 : /* Empty conditions remain empty. */
1129 94048383 : if (!cond)
1130 : return NULL_TREE;
1131 :
1132 : /* Wait until we instantiate templates before doing conversion. */
1133 93677768 : if (type_dependent_expression_p (cond))
1134 39447055 : return cond;
1135 :
1136 : /* Strip any ANNOTATE_EXPRs from COND. */
1137 54230713 : annotate_saver annotations (&cond);
1138 :
1139 : /* For structured binding used in condition, the conversion needs to be
1140 : evaluated before the individual variables are initialized in the
1141 : std::tuple_{size,element} case. cp_finish_decomp saved the conversion
1142 : result in a TARGET_EXPR, pick it up from there. */
1143 376362 : if (DECL_DECOMPOSITION_P (cond)
1144 225 : && DECL_DECOMP_IS_BASE (cond)
1145 225 : && DECL_DECOMP_BASE (cond)
1146 54230935 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1147 56 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1148 :
1149 54230713 : if (warn_sequence_point && !processing_template_decl)
1150 326559 : verify_sequence_points (cond);
1151 :
1152 54230713 : maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
1153 : tf_warning_or_error);
1154 :
1155 : /* Do the conversion. */
1156 54230713 : cond = convert_from_reference (cond);
1157 54230713 : cond = condition_conversion (cond);
1158 :
1159 : /* Restore any ANNOTATE_EXPRs around COND. */
1160 54230713 : return annotations.restore (cond);
1161 : }
1162 :
1163 : /* Finish an expression-statement, whose EXPRESSION is as indicated. */
1164 :
1165 : tree
1166 167608710 : finish_expr_stmt (tree expr)
1167 : {
1168 167608710 : tree r = NULL_TREE;
1169 167608710 : location_t loc = EXPR_LOCATION (expr);
1170 :
1171 167423301 : if (expr != NULL_TREE)
1172 : {
1173 : /* If we ran into a problem, make sure we complained. */
1174 167608549 : gcc_assert (expr != error_mark_node || seen_error ());
1175 :
1176 167608549 : if (!processing_template_decl)
1177 : {
1178 60604813 : if (warn_sequence_point)
1179 812169 : verify_sequence_points (expr);
1180 60604813 : expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1181 : }
1182 107003736 : else if (!type_dependent_expression_p (expr))
1183 23183566 : convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1184 :
1185 167608546 : 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 167608546 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
1192 : {
1193 167608367 : if (TREE_CODE (expr) != EXPR_STMT
1194 165102858 : && !STATEMENT_CLASS_P (expr)
1195 165098707 : && TREE_CODE (expr) != STATEMENT_LIST)
1196 164953417 : expr = build_stmt (loc, EXPR_STMT, expr);
1197 167608367 : expr = maybe_cleanup_point_expr_void (expr);
1198 : }
1199 :
1200 167608546 : r = add_stmt (expr);
1201 : }
1202 :
1203 167608707 : return r;
1204 : }
1205 :
1206 :
1207 : /* Begin an if-statement. Returns a newly created IF_STMT if
1208 : appropriate. */
1209 :
1210 : tree
1211 75891631 : begin_if_stmt (void)
1212 : {
1213 75891631 : tree r, scope;
1214 75891631 : scope = do_pushlevel (sk_cond);
1215 75891631 : r = build_stmt (input_location, IF_STMT, NULL_TREE,
1216 : NULL_TREE, NULL_TREE, scope);
1217 75891631 : current_binding_level->this_entity = r;
1218 75891631 : begin_cond (&IF_COND (r));
1219 75891631 : 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 252464 : is_std_constant_evaluated_p (tree fn)
1227 : {
1228 : /* std::is_constant_evaluated takes no arguments. */
1229 252464 : if (call_expr_nargs (fn) != 0)
1230 : return false;
1231 :
1232 90241 : tree fndecl = cp_get_callee_fndecl_nofold (fn);
1233 90241 : if (fndecl == NULL_TREE)
1234 : return false;
1235 :
1236 28283 : if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
1237 : BUILT_IN_FRONTEND))
1238 : return true;
1239 :
1240 28254 : if (!decl_in_std_namespace_p (fndecl))
1241 : return false;
1242 :
1243 12915 : tree name = DECL_NAME (fndecl);
1244 12915 : 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 4679171 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
1252 : {
1253 4679171 : tree t = *tp;
1254 :
1255 4679171 : if (TYPE_P (t) || TREE_CONSTANT (t))
1256 : {
1257 828844 : *walk_subtrees = false;
1258 828844 : return NULL_TREE;
1259 : }
1260 :
1261 3850327 : switch (TREE_CODE (t))
1262 : {
1263 252464 : case CALL_EXPR:
1264 252464 : if (is_std_constant_evaluated_p (t))
1265 : return t;
1266 : break;
1267 6 : case EXPR_STMT:
1268 : /* Don't warn in statement expressions. */
1269 6 : *walk_subtrees = false;
1270 6 : return NULL_TREE;
1271 : default:
1272 : break;
1273 : }
1274 :
1275 : return NULL_TREE;
1276 : }
1277 :
1278 : /* In certain contexts, std::is_constant_evaluated() is always true (for
1279 : instance, in a consteval function or in a constexpr if), or always false
1280 : (e.g., in a non-constexpr non-consteval function) so give the user a clue. */
1281 :
1282 : static void
1283 75977219 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
1284 : bool trivial_infinite)
1285 : {
1286 75977219 : if (!warn_tautological_compare)
1287 : return;
1288 :
1289 : /* Suppress warning for std::is_constant_evaluated if the conditional
1290 : comes from a macro. */
1291 1430408 : if (from_macro_expansion_at (EXPR_LOCATION (cond)))
1292 : return;
1293 :
1294 603679 : cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
1295 : NULL);
1296 603679 : if (cond)
1297 : {
1298 2390 : if (constexpr_if)
1299 34 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1300 : "%<std::is_constant_evaluated%> always evaluates to "
1301 : "true in %<if constexpr%>");
1302 2356 : else if (trivial_infinite)
1303 : {
1304 8 : auto_diagnostic_group d;
1305 8 : if (warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1306 : "%<std::is_constant_evaluated%> evaluates to "
1307 : "true when checking if trivially empty iteration "
1308 : "statement is trivial infinite loop")
1309 8 : && !maybe_constexpr_fn (current_function_decl))
1310 8 : inform (EXPR_LOCATION (cond),
1311 : "and evaluates to false when actually evaluating "
1312 : "the condition in non-%<constexpr%> function");
1313 8 : }
1314 2348 : else if (!maybe_constexpr_fn (current_function_decl))
1315 38 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1316 : "%<std::is_constant_evaluated%> always evaluates to "
1317 : "false in a non-%<constexpr%> function");
1318 4620 : else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1319 3 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1320 : "%<std::is_constant_evaluated%> always evaluates to "
1321 : "true in a %<consteval%> function");
1322 : }
1323 : }
1324 :
1325 : /* Process the COND of an if-statement, which may be given by
1326 : IF_STMT. */
1327 :
1328 : tree
1329 75891631 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
1330 : {
1331 75891631 : tree cond = maybe_convert_cond (orig_cond);
1332 75891631 : maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
1333 : /*trivial_infinite=*/false);
1334 75891631 : if (IF_STMT_CONSTEXPR_P (if_stmt)
1335 16048350 : && !type_dependent_expression_p (cond)
1336 10947209 : && require_constant_expression (cond)
1337 10947178 : && !instantiation_dependent_expression_p (cond)
1338 : /* Wait until instantiation time, since only then COND has been
1339 : converted to bool. */
1340 81906488 : && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
1341 : {
1342 6014857 : cond = instantiate_non_dependent_expr (cond);
1343 6014857 : cond = cxx_constant_value (cond);
1344 : }
1345 69876774 : else if (processing_template_decl)
1346 52463050 : cond = orig_cond;
1347 75891631 : finish_cond (&IF_COND (if_stmt), cond);
1348 75891631 : add_stmt (if_stmt);
1349 75891631 : THEN_CLAUSE (if_stmt) = push_stmt_list ();
1350 75891631 : 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 75883925 : finish_then_clause (tree if_stmt)
1358 : {
1359 75883925 : THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
1360 75883925 : return if_stmt;
1361 : }
1362 :
1363 : /* Begin the else-clause of an if-statement. */
1364 :
1365 : void
1366 28439386 : begin_else_clause (tree if_stmt)
1367 : {
1368 28439386 : ELSE_CLAUSE (if_stmt) = push_stmt_list ();
1369 28439386 : }
1370 :
1371 : /* Finish the else-clause of an if-statement, which may be given by
1372 : IF_STMT. */
1373 :
1374 : void
1375 28439348 : finish_else_clause (tree if_stmt)
1376 : {
1377 28439348 : ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
1378 28439348 : }
1379 :
1380 : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1381 : read. */
1382 :
1383 : static tree
1384 860166857 : maybe_mark_exp_read_r (tree *tp, int *, void *)
1385 : {
1386 860166857 : tree t = *tp;
1387 860166857 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1388 50025001 : mark_exp_read (t);
1389 860166857 : return NULL_TREE;
1390 : }
1391 :
1392 : /* Finish an if-statement. */
1393 :
1394 : void
1395 75883925 : finish_if_stmt (tree if_stmt)
1396 : {
1397 75883925 : tree scope = IF_SCOPE (if_stmt);
1398 75883925 : IF_SCOPE (if_stmt) = NULL;
1399 75883925 : 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 16040644 : cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
1405 : maybe_mark_exp_read_r, NULL);
1406 16040644 : cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
1407 : maybe_mark_exp_read_r, NULL);
1408 : }
1409 75883925 : add_stmt (do_poplevel (scope));
1410 75883925 : }
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 17782846 : finish_loop_cond (tree *condp, tree body)
1421 : {
1422 17782846 : if (TREE_CODE (*condp) == INTEGER_CST)
1423 : return;
1424 12770223 : bool trivially_empty = expr_first (body) == NULL_TREE;
1425 12770223 : bool trivial_infinite = false;
1426 12770223 : if (trivially_empty)
1427 : {
1428 99425 : tree c = fold_non_dependent_expr (*condp, tf_none,
1429 : /*manifestly_const_eval=*/true);
1430 99425 : trivial_infinite = c && integer_nonzerop (c);
1431 : }
1432 12770223 : if (warn_tautological_compare)
1433 : {
1434 85790 : tree cond = *condp;
1435 86157 : while (TREE_CODE (cond) == ANNOTATE_EXPR)
1436 367 : cond = TREE_OPERAND (cond, 0);
1437 85790 : if (trivial_infinite
1438 85854 : && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1439 64 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1440 : /*trivial_infinite=*/true);
1441 85726 : else if (!trivially_empty
1442 375 : || !processing_template_decl
1443 86130 : || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1444 85524 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1445 : /*trivial_infinite=*/false);
1446 : }
1447 12770223 : 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 4854355 : begin_while_stmt (void)
1459 : {
1460 4854355 : tree r;
1461 4854355 : r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1462 : NULL_TREE, NULL_TREE);
1463 4854355 : add_stmt (r);
1464 4854355 : WHILE_BODY (r) = do_pushlevel (sk_block);
1465 4854355 : begin_cond (&WHILE_COND (r));
1466 4854355 : return r;
1467 : }
1468 :
1469 : /* Process the COND of a while-statement, which may be given by
1470 : WHILE_STMT. */
1471 :
1472 : void
1473 4854355 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
1474 : tree unroll, bool novector)
1475 : {
1476 4854355 : cond = maybe_convert_cond (cond);
1477 4854355 : finish_cond (&WHILE_COND (while_stmt), cond);
1478 4854355 : begin_maybe_infinite_loop (cond);
1479 4854355 : 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 4854355 : if (unroll && cond != error_mark_node)
1487 27798 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1488 13899 : TREE_TYPE (WHILE_COND (while_stmt)),
1489 13899 : WHILE_COND (while_stmt),
1490 : build_int_cst (integer_type_node,
1491 : annot_expr_unroll_kind),
1492 : unroll);
1493 4854355 : 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 4854355 : adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
1501 : &WHILE_COND_PREP (while_stmt),
1502 : &WHILE_COND_CLEANUP (while_stmt));
1503 4854355 : }
1504 :
1505 : /* Finish a while-statement, which may be given by WHILE_STMT. */
1506 :
1507 : void
1508 4854355 : finish_while_stmt (tree while_stmt)
1509 : {
1510 4854355 : end_maybe_infinite_loop (boolean_true_node);
1511 4854355 : if (WHILE_COND_PREP (while_stmt))
1512 9560 : finish_loop_cond_prep (&WHILE_BODY (while_stmt),
1513 : &WHILE_COND_PREP (while_stmt),
1514 9560 : WHILE_COND_CLEANUP (while_stmt));
1515 : else
1516 4844795 : WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
1517 4854355 : finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
1518 4854355 : }
1519 :
1520 : /* Begin a do-statement. Returns a newly created DO_STMT if
1521 : appropriate. */
1522 :
1523 : tree
1524 5741006 : begin_do_stmt (void)
1525 : {
1526 5741006 : tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
1527 : NULL_TREE);
1528 5741006 : begin_maybe_infinite_loop (boolean_true_node);
1529 5741006 : add_stmt (r);
1530 5741006 : DO_BODY (r) = push_stmt_list ();
1531 5741006 : return r;
1532 : }
1533 :
1534 : /* Finish the body of a do-statement, which may be given by DO_STMT. */
1535 :
1536 : void
1537 5741006 : finish_do_body (tree do_stmt)
1538 : {
1539 5741006 : tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
1540 :
1541 5741006 : if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
1542 542629 : body = STATEMENT_LIST_TAIL (body)->stmt;
1543 :
1544 5741006 : if (IS_EMPTY_STMT (body))
1545 30 : warning (OPT_Wempty_body,
1546 : "suggest explicit braces around empty body in %<do%> statement");
1547 5741006 : }
1548 :
1549 : /* Finish a do-statement, which may be given by DO_STMT, and whose
1550 : COND is as indicated. */
1551 :
1552 : void
1553 5741006 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
1554 : bool novector)
1555 : {
1556 5741006 : cond = maybe_convert_cond (cond);
1557 5741006 : 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 5741006 : if (check_for_bare_parameter_packs (cond))
1562 3 : cond = error_mark_node;
1563 5741006 : 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 5741006 : 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 5741006 : 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 5741006 : DO_COND (do_stmt) = cond;
1576 5741006 : tree do_body = DO_BODY (do_stmt);
1577 5740976 : if (CONVERT_EXPR_P (do_body)
1578 30 : && integer_zerop (TREE_OPERAND (do_body, 0))
1579 5741036 : && VOID_TYPE_P (TREE_TYPE (do_body)))
1580 : do_body = NULL_TREE;
1581 5741006 : finish_loop_cond (&DO_COND (do_stmt), do_body);
1582 5741006 : }
1583 :
1584 : /* Finish a return-statement. The EXPRESSION returned, if any, is as
1585 : indicated. */
1586 :
1587 : tree
1588 131341477 : finish_return_stmt (tree expr)
1589 : {
1590 131341477 : tree r;
1591 131341477 : bool no_warning;
1592 131341477 : bool dangling;
1593 :
1594 131341477 : expr = check_return_expr (expr, &no_warning, &dangling);
1595 :
1596 131341477 : if (error_operand_p (expr)
1597 131341477 : || (flag_openmp && !check_omp_return ()))
1598 : {
1599 : /* Suppress -Wreturn-type for this function. */
1600 1343 : if (warn_return_type)
1601 1337 : suppress_warning (current_function_decl, OPT_Wreturn_type);
1602 1343 : return error_mark_node;
1603 : }
1604 :
1605 131340134 : if (!processing_template_decl)
1606 : {
1607 46136129 : if (warn_sequence_point)
1608 1023184 : verify_sequence_points (expr);
1609 : }
1610 :
1611 131340134 : r = build_stmt (input_location, RETURN_EXPR, expr);
1612 131340134 : RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
1613 131340134 : if (no_warning)
1614 33 : suppress_warning (r, OPT_Wreturn_type);
1615 131340134 : r = maybe_cleanup_point_expr_void (r);
1616 131340134 : r = add_stmt (r);
1617 :
1618 131340134 : 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 7826478 : begin_for_scope (tree *init)
1627 : {
1628 7826478 : tree scope = do_pushlevel (sk_for);
1629 :
1630 7826478 : if (processing_template_decl)
1631 6211696 : *init = push_stmt_list ();
1632 : else
1633 1614782 : *init = NULL_TREE;
1634 :
1635 7826478 : 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 7558100 : begin_for_stmt (tree scope, tree init)
1644 : {
1645 7558100 : tree r;
1646 :
1647 7558100 : 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 7558100 : if (scope == NULL_TREE)
1652 : {
1653 1366420 : gcc_assert (!init);
1654 1366420 : scope = begin_for_scope (&init);
1655 : }
1656 :
1657 7558100 : FOR_INIT_STMT (r) = init;
1658 7558100 : FOR_SCOPE (r) = scope;
1659 :
1660 7558100 : 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 7558100 : finish_init_stmt (tree for_stmt)
1668 : {
1669 7558100 : if (processing_template_decl)
1670 5943318 : FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
1671 7558100 : add_stmt (for_stmt);
1672 7558100 : FOR_BODY (for_stmt) = do_pushlevel (sk_block);
1673 7558100 : begin_cond (&FOR_COND (for_stmt));
1674 7558100 : }
1675 :
1676 : /* Finish the COND of a for-statement, which may be given by
1677 : FOR_STMT. */
1678 :
1679 : void
1680 7558100 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
1681 : bool novector)
1682 : {
1683 7558100 : cond = maybe_convert_cond (cond);
1684 7558100 : finish_cond (&FOR_COND (for_stmt), cond);
1685 7558100 : begin_maybe_infinite_loop (cond);
1686 7558100 : 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 7558100 : 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 7558100 : 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 7558100 : adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
1708 : &FOR_COND_CLEANUP (for_stmt));
1709 7558100 : }
1710 :
1711 : /* Finish the increment-EXPRESSION in a for-statement, which may be
1712 : given by FOR_STMT. */
1713 :
1714 : void
1715 7545586 : finish_for_expr (tree expr, tree for_stmt)
1716 : {
1717 7545586 : 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 7084882 : if (type_unknown_p (expr))
1722 : {
1723 6 : cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1724 6 : expr = error_mark_node;
1725 : }
1726 7084882 : if (!processing_template_decl)
1727 : {
1728 1540569 : if (warn_sequence_point)
1729 14955 : verify_sequence_points (expr);
1730 1540569 : expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1731 : tf_warning_or_error);
1732 : }
1733 5544313 : else if (!type_dependent_expression_p (expr))
1734 1978201 : convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
1735 7084882 : expr = maybe_cleanup_point_expr_void (expr);
1736 7084882 : if (check_for_bare_parameter_packs (expr))
1737 0 : expr = error_mark_node;
1738 7084882 : 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 7826591 : find_range_for_decls (tree range_for_decl[3])
1749 : {
1750 7826591 : 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 31306364 : for (int i = 0; i < 3; i++)
1756 : {
1757 23479773 : tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1758 23479773 : if (IDENTIFIER_BINDING (id)
1759 23479773 : && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1760 : {
1761 274891 : range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1762 274891 : gcc_assert (VAR_P (range_for_decl[i])
1763 : && DECL_ARTIFICIAL (range_for_decl[i]));
1764 : }
1765 : }
1766 7826591 : }
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 7826478 : finish_for_stmt (tree for_stmt)
1775 : {
1776 7826478 : end_maybe_infinite_loop (boolean_true_node);
1777 :
1778 7826478 : if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1779 268378 : RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1780 : else
1781 : {
1782 7558100 : 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 7557926 : FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1788 7558100 : if (FOR_COND (for_stmt))
1789 7187485 : finish_loop_cond (&FOR_COND (for_stmt),
1790 7187485 : FOR_EXPR (for_stmt) ? integer_one_node
1791 143425 : : FOR_BODY (for_stmt));
1792 : }
1793 :
1794 : /* Pop the scope for the body of the loop. */
1795 7826478 : tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1796 7826478 : ? &RANGE_FOR_SCOPE (for_stmt)
1797 7558100 : : &FOR_SCOPE (for_stmt));
1798 7826478 : tree scope = *scope_ptr;
1799 7826478 : *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 7826478 : tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1806 7826478 : find_range_for_decls (range_for_decl);
1807 :
1808 7826478 : 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 7826478 : if (!stmts_are_full_exprs_p ())
1813 12514 : return;
1814 :
1815 31255856 : for (int i = 0; i < 3; i++)
1816 23441892 : if (range_for_decl[i])
1817 274775 : DECL_NAME (range_for_decl[i])
1818 274775 : = 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 268378 : begin_range_for_stmt (tree scope, tree init)
1828 : {
1829 268378 : begin_maybe_infinite_loop (boolean_false_node);
1830 :
1831 268378 : tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1832 : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1833 :
1834 268378 : 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 268378 : RANGE_FOR_INIT_STMT (r) = init;
1842 268378 : RANGE_FOR_SCOPE (r) = scope;
1843 :
1844 268378 : 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 268378 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1853 : {
1854 268378 : if (processing_template_decl)
1855 536756 : RANGE_FOR_INIT_STMT (range_for_stmt)
1856 536756 : = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1857 268378 : RANGE_FOR_DECL (range_for_stmt) = decl;
1858 268378 : RANGE_FOR_EXPR (range_for_stmt) = expr;
1859 268378 : add_stmt (range_for_stmt);
1860 268378 : RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1861 268378 : }
1862 :
1863 : /* Begin the scope of an expansion-statement. */
1864 :
1865 : tree
1866 2312 : begin_template_for_scope (tree *init)
1867 : {
1868 2312 : tree scope = do_pushlevel (sk_template_for);
1869 :
1870 2312 : if (processing_template_decl)
1871 547 : *init = push_stmt_list ();
1872 : else
1873 1765 : *init = NULL_TREE;
1874 :
1875 2312 : return scope;
1876 : }
1877 :
1878 : /* Finish a break-statement. */
1879 :
1880 : tree
1881 4858797 : 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 4858797 : if (!block_may_fallthru (cur_stmt_list))
1891 714 : return void_node;
1892 4858083 : note_break_stmt ();
1893 4858083 : return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
1894 : }
1895 :
1896 : /* Finish a continue-statement. */
1897 :
1898 : tree
1899 233474 : finish_continue_stmt (void)
1900 : {
1901 233474 : 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 720865 : begin_switch_stmt (void)
1909 : {
1910 720865 : tree r, scope;
1911 :
1912 720865 : scope = do_pushlevel (sk_cond);
1913 720865 : r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1914 : scope, NULL_TREE);
1915 :
1916 720865 : begin_cond (&SWITCH_STMT_COND (r));
1917 :
1918 720865 : return r;
1919 : }
1920 :
1921 : /* Finish the cond of a switch-statement. */
1922 :
1923 : void
1924 720865 : finish_switch_cond (tree cond, tree switch_stmt)
1925 : {
1926 720865 : tree orig_type = NULL;
1927 :
1928 720865 : if (!processing_template_decl)
1929 : {
1930 : /* Convert the condition to an integer or enumeration type. */
1931 294811 : tree orig_cond = cond;
1932 : /* For structured binding used in condition, the conversion needs to be
1933 : evaluated before the individual variables are initialized in the
1934 : std::tuple_{size,element} case. cp_finish_decomp saved the
1935 : conversion result in a TARGET_EXPR, pick it up from there. */
1936 122 : if (DECL_DECOMPOSITION_P (cond)
1937 57 : && DECL_DECOMP_IS_BASE (cond)
1938 57 : && DECL_DECOMP_BASE (cond)
1939 294865 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1940 18 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1941 294811 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1942 294811 : 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 294811 : orig_type = unlowered_expr_type (cond);
1950 294811 : if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1951 206363 : orig_type = TREE_TYPE (cond);
1952 294811 : if (cond != error_mark_node)
1953 : {
1954 : /* [stmt.switch]
1955 :
1956 : Integral promotions are performed. */
1957 294778 : cond = perform_integral_promotions (cond);
1958 294778 : cond = maybe_cleanup_point_expr (cond);
1959 : }
1960 : }
1961 720865 : if (check_for_bare_parameter_packs (cond))
1962 0 : cond = error_mark_node;
1963 720865 : else if (!processing_template_decl && warn_sequence_point)
1964 2797 : verify_sequence_points (cond);
1965 :
1966 720865 : finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1967 720865 : SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1968 720865 : add_stmt (switch_stmt);
1969 720865 : push_switch (switch_stmt);
1970 720865 : SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1971 720865 : }
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 720865 : finish_switch_stmt (tree switch_stmt)
1978 : {
1979 720865 : tree scope;
1980 :
1981 1441730 : SWITCH_STMT_BODY (switch_stmt) =
1982 720865 : pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1983 720865 : pop_switch ();
1984 :
1985 720865 : scope = SWITCH_STMT_SCOPE (switch_stmt);
1986 720865 : SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1987 720865 : add_stmt (do_poplevel (scope));
1988 720865 : }
1989 :
1990 : /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1991 : appropriate. */
1992 :
1993 : tree
1994 1186758 : begin_try_block (void)
1995 : {
1996 1186758 : tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1997 1186758 : add_stmt (r);
1998 1186758 : TRY_STMTS (r) = push_stmt_list ();
1999 1186758 : 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 2180 : begin_function_try_block (tree *compound_stmt)
2008 : {
2009 2180 : 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 2180 : *compound_stmt = begin_compound_stmt (0);
2013 2180 : current_binding_level->artificial = 1;
2014 2180 : r = begin_try_block ();
2015 2180 : FN_TRY_BLOCK_P (r) = 1;
2016 2180 : return r;
2017 : }
2018 :
2019 : /* Finish a try-block, which may be given by TRY_BLOCK. */
2020 :
2021 : void
2022 1186758 : finish_try_block (tree try_block)
2023 : {
2024 1186758 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2025 1186758 : TRY_HANDLERS (try_block) = push_stmt_list ();
2026 1186758 : }
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 2180 : finish_function_try_block (tree try_block)
2051 : {
2052 2180 : finish_try_block (try_block);
2053 : /* FIXME : something queer about CTOR_INITIALIZER somehow following
2054 : the try block, but moving it inside. */
2055 2180 : in_function_try_handler = 1;
2056 2180 : }
2057 :
2058 : /* Finish a handler-sequence for a try-block, which may be given by
2059 : TRY_BLOCK. */
2060 :
2061 : void
2062 1186758 : finish_handler_sequence (tree try_block)
2063 : {
2064 1186758 : TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
2065 1186758 : check_handlers (TRY_HANDLERS (try_block));
2066 1186758 : }
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 2180 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
2074 : {
2075 2180 : in_function_try_handler = 0;
2076 2180 : finish_handler_sequence (try_block);
2077 2180 : finish_compound_stmt (compound_stmt);
2078 2180 : }
2079 :
2080 : /* Begin a handler. Returns a HANDLER if appropriate. */
2081 :
2082 : tree
2083 1654007 : begin_handler (void)
2084 : {
2085 1654007 : tree r;
2086 :
2087 1654007 : r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
2088 1654007 : add_stmt (r);
2089 :
2090 : /* Create a binding level for the eh_info and the exception object
2091 : cleanup. */
2092 1654007 : HANDLER_BODY (r) = do_pushlevel (sk_catch);
2093 :
2094 1654007 : 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 1654007 : finish_handler_parms (tree decl, tree handler)
2103 : {
2104 1654007 : tree type = NULL_TREE;
2105 1654007 : if (processing_template_decl)
2106 : {
2107 1509216 : if (decl)
2108 : {
2109 490795 : decl = pushdecl (decl);
2110 490795 : decl = push_template_decl (decl);
2111 490795 : HANDLER_PARMS (handler) = decl;
2112 490795 : type = TREE_TYPE (decl);
2113 : }
2114 : }
2115 : else
2116 : {
2117 144791 : type = expand_start_catch_block (decl);
2118 144791 : if (warn_catch_value
2119 2116 : && type != NULL_TREE
2120 711 : && type != error_mark_node
2121 145502 : && !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 1654007 : HANDLER_TYPE (handler) = type;
2143 1654007 : }
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 1654007 : finish_handler (tree handler)
2150 : {
2151 1654007 : if (!processing_template_decl)
2152 144791 : expand_end_catch_block ();
2153 1654007 : HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
2154 1654007 : }
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 292470620 : begin_compound_stmt (unsigned int flags)
2165 : {
2166 292470620 : tree r;
2167 :
2168 292470620 : if (flags & BCS_NO_SCOPE)
2169 : {
2170 5556983 : r = push_stmt_list ();
2171 5556983 : 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 5556983 : keep_next_level (false);
2178 : }
2179 : else
2180 : {
2181 286913637 : scope_kind sk = sk_block;
2182 286913637 : if (flags & BCS_TRY_BLOCK)
2183 : sk = sk_try;
2184 285727070 : else if (flags & BCS_TRANSACTION)
2185 : sk = sk_transaction;
2186 285726835 : else if (flags & BCS_STMT_EXPR)
2187 29088 : sk = sk_stmt_expr;
2188 286913637 : 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 292470620 : if (processing_template_decl)
2198 : {
2199 196097969 : r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
2200 196097969 : BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
2201 196097969 : BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
2202 196097969 : TREE_SIDE_EFFECTS (r) = 1;
2203 : }
2204 :
2205 292470620 : return r;
2206 : }
2207 :
2208 : /* Finish a compound-statement, which is given by STMT. */
2209 :
2210 : void
2211 292470581 : finish_compound_stmt (tree stmt)
2212 : {
2213 292470581 : if (TREE_CODE (stmt) == BIND_EXPR)
2214 : {
2215 196097969 : 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 196097969 : if (TREE_CODE (body) == STATEMENT_LIST
2220 178433804 : && STATEMENT_LIST_HEAD (body) == NULL
2221 11915704 : && !BIND_EXPR_BODY_BLOCK (stmt)
2222 207492195 : && !BIND_EXPR_TRY_BLOCK (stmt))
2223 : stmt = body;
2224 : else
2225 184703840 : BIND_EXPR_BODY (stmt) = body;
2226 : }
2227 96372612 : else if (STATEMENT_LIST_NO_SCOPE (stmt))
2228 5519236 : stmt = pop_stmt_list (stmt);
2229 : else
2230 : {
2231 : /* Destroy any ObjC "super" receivers that may have been
2232 : created. */
2233 90853376 : objc_clear_super_receiver ();
2234 :
2235 90853376 : stmt = do_poplevel (stmt);
2236 : }
2237 :
2238 : /* ??? See c_end_compound_stmt wrt statement expressions. */
2239 292470581 : add_stmt (stmt);
2240 292470581 : }
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 55344 : finish_asm_string_expression (location_t loc, tree string)
2248 : {
2249 55344 : if (string == error_mark_node
2250 55331 : || 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 32008 : 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 32008 : tree r;
2277 32008 : tree t;
2278 32008 : int ninputs = list_length (input_operands);
2279 32008 : int noutputs = list_length (output_operands);
2280 :
2281 32008 : if (!processing_template_decl)
2282 : {
2283 12702 : const char *constraint;
2284 12702 : const char **oconstraints;
2285 12702 : bool allows_mem, allows_reg, is_inout;
2286 12702 : tree operand;
2287 12702 : int i;
2288 :
2289 12702 : oconstraints = XALLOCAVEC (const char *, noutputs);
2290 :
2291 25302 : string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
2292 : string);
2293 12702 : if (string == error_mark_node)
2294 109 : return error_mark_node;
2295 37824 : for (int i = 0; i < 2; ++i)
2296 87057 : for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
2297 : {
2298 36625 : tree s = TREE_VALUE (TREE_PURPOSE (t));
2299 73232 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2300 36625 : if (s == error_mark_node)
2301 : return error_mark_node;
2302 36595 : TREE_VALUE (TREE_PURPOSE (t)) = s;
2303 : }
2304 18010 : for (t = clobbers; t; t = TREE_CHAIN (t))
2305 : {
2306 5417 : tree s = TREE_VALUE (t);
2307 10828 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2308 5417 : TREE_VALUE (t) = s;
2309 : }
2310 :
2311 12593 : string = resolve_asm_operand_names (string, output_operands,
2312 : input_operands, labels);
2313 :
2314 31714 : for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
2315 : {
2316 19121 : 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 19121 : STRIP_NOPS (operand);
2325 :
2326 19121 : operand = mark_lvalue_use (operand);
2327 :
2328 19121 : if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
2329 9 : operand = error_mark_node;
2330 :
2331 19121 : if (operand != error_mark_node
2332 19121 : && (TREE_READONLY (operand)
2333 19106 : || CP_TYPE_CONST_P (TREE_TYPE (operand))
2334 : /* Functions are not modifiable, even though they are
2335 : lvalues. */
2336 19106 : || 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 19106 : || (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 : tree *op = &operand;
2344 19128 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2345 7 : op = &TREE_OPERAND (*op, 1);
2346 19121 : 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 19121 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2359 19121 : oconstraints[i] = constraint;
2360 :
2361 19121 : 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 19112 : if (!allows_reg && !cxx_mark_addressable (*op))
2368 0 : operand = error_mark_node;
2369 19112 : if (allows_reg && toplev_p)
2370 : {
2371 3 : error_at (loc, "constraint allows registers outside of "
2372 : "a function");
2373 3 : operand = error_mark_node;
2374 : }
2375 : }
2376 : else
2377 9 : operand = error_mark_node;
2378 :
2379 812 : if (toplev_p && operand != error_mark_node)
2380 : {
2381 21 : if (TREE_SIDE_EFFECTS (operand))
2382 : {
2383 0 : error_at (loc, "side-effects in output operand outside "
2384 : "of a function");
2385 0 : operand = error_mark_node;
2386 : }
2387 : else
2388 : {
2389 21 : tree addr
2390 21 : = cp_build_addr_expr (operand, tf_warning_or_error);
2391 21 : if (addr == error_mark_node)
2392 0 : operand = error_mark_node;
2393 : else
2394 : {
2395 21 : addr = maybe_constant_value (addr);
2396 21 : if (!initializer_constant_valid_p (addr,
2397 21 : TREE_TYPE (addr)))
2398 : {
2399 3 : error_at (loc, "output operand outside of a "
2400 : "function is not constant");
2401 3 : operand = error_mark_node;
2402 : }
2403 : else
2404 18 : operand = build_fold_indirect_ref (addr);
2405 : }
2406 : }
2407 : }
2408 19100 : 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 19121 : TREE_VALUE (t) = operand;
2415 : }
2416 :
2417 30062 : for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
2418 : {
2419 17469 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2420 17469 : bool constraint_parsed
2421 17469 : = 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 17469 : if (constraint_parsed && !allows_reg && allows_mem)
2427 670 : operand = mark_lvalue_use (TREE_VALUE (t));
2428 : else
2429 16799 : 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 17469 : 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 17469 : if (constraint_parsed)
2444 : {
2445 : /* If the operand is going to end up in memory,
2446 : mark it addressable. */
2447 17448 : 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 670 : STRIP_NOPS (operand);
2452 :
2453 670 : tree *op = &operand;
2454 677 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2455 7 : op = &TREE_OPERAND (*op, 1);
2456 670 : 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 670 : if (!cxx_mark_addressable (*op))
2469 0 : operand = error_mark_node;
2470 : }
2471 16778 : 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 17448 : 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 17448 : 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 17469 : 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 17352 : 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 17469 : TREE_VALUE (t) = operand;
2551 : }
2552 : }
2553 :
2554 31899 : r = build_stmt (loc, ASM_EXPR, string,
2555 : output_operands, input_operands,
2556 : clobbers, labels);
2557 31899 : ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
2558 31899 : ASM_INLINE_P (r) = inline_p;
2559 31899 : if (toplev_p)
2560 : {
2561 99 : symtab->finalize_toplevel_asm (r);
2562 99 : return r;
2563 : }
2564 31800 : r = maybe_cleanup_point_expr_void (r);
2565 31800 : return add_stmt (r);
2566 : }
2567 :
2568 : /* Finish a label with the indicated NAME. Returns the new label. */
2569 :
2570 : tree
2571 2488 : finish_label_stmt (tree name)
2572 : {
2573 2488 : tree decl = define_label (input_location, name);
2574 :
2575 2488 : if (decl == error_mark_node)
2576 : return error_mark_node;
2577 :
2578 2482 : add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
2579 :
2580 2482 : 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 3576244 : finish_decl_cleanup (tree decl, tree cleanup)
2603 : {
2604 3576244 : push_cleanup (decl, cleanup, false);
2605 3576244 : }
2606 :
2607 : /* If the current scope exits with an exception, run CLEANUP. */
2608 :
2609 : void
2610 2267877 : finish_eh_cleanup (tree cleanup)
2611 : {
2612 2267877 : push_cleanup (NULL, cleanup, true);
2613 2267877 : }
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 20877426 : 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 20877426 : mem_inits = nreverse (mem_inits);
2625 :
2626 20877426 : if (processing_template_decl)
2627 : {
2628 : tree mem;
2629 :
2630 35274942 : 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 20863328 : if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
2638 20863328 : && check_for_bare_parameter_packs (TREE_VALUE (mem)))
2639 3 : TREE_VALUE (mem) = error_mark_node;
2640 : }
2641 :
2642 14411614 : add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
2643 : CTOR_INITIALIZER, mem_inits));
2644 : }
2645 : else
2646 6465812 : emit_mem_initializers (mem_inits);
2647 20877426 : }
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 46005714 : force_paren_expr (tree expr, bool even_uneval /* = false */)
2655 : {
2656 : /* This is only needed for decltype(auto) in C++14. */
2657 46005714 : 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 45362294 : if (cp_unevaluated_operand && !even_uneval)
2663 : return expr;
2664 :
2665 37697772 : if (TREE_CODE (expr) == COMPONENT_REF
2666 37639644 : || TREE_CODE (expr) == SCOPE_REF
2667 75330695 : || REFERENCE_REF_P (expr))
2668 604257 : REF_PARENTHESIZED_P (expr) = true;
2669 37093515 : else if (DECL_P (tree_strip_any_location_wrapper (expr)))
2670 : {
2671 1785556 : location_t loc = cp_expr_location (expr);
2672 1785556 : const tree_code code = processing_template_decl ? PAREN_EXPR
2673 : : VIEW_CONVERT_EXPR;
2674 1785556 : expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
2675 1785556 : 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 1015132360 : maybe_undo_parenthesized_ref (tree t)
2686 : {
2687 1015132360 : if (cxx_dialect < cxx14)
2688 : return t;
2689 :
2690 1005095649 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
2691 1114010360 : && REF_PARENTHESIZED_P (t))
2692 204430 : t = TREE_OPERAND (t, 0);
2693 :
2694 : return t;
2695 : }
2696 :
2697 : /* Finish a parenthesized expression EXPR. */
2698 :
2699 : cp_expr
2700 34285606 : finish_parenthesized_expr (cp_expr expr)
2701 : {
2702 34285606 : if (EXPR_P (expr))
2703 : {
2704 : /* This inhibits warnings in maybe_warn_unparenthesized_assignment
2705 : and c_common_truthvalue_conversion. */
2706 68274417 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
2707 : /* And maybe_warn_sizeof_array_div. */
2708 68274417 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
2709 : }
2710 :
2711 34285606 : if (TREE_CODE (expr) == OFFSET_REF
2712 34285606 : || 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 31503 : PTRMEM_OK_P (expr) = 0;
2716 :
2717 34285606 : tree stripped_expr = tree_strip_any_location_wrapper (expr);
2718 34285606 : if (TREE_CODE (stripped_expr) == STRING_CST)
2719 883836 : PAREN_STRING_LITERAL_P (stripped_expr) = 1;
2720 33401770 : else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
2721 1432 : PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
2722 :
2723 34285606 : expr = cp_expr (force_paren_expr (expr), expr.get_location ());
2724 :
2725 34285606 : 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 78802062 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
2733 : tsubst_flags_t complain /* = tf_warning_or_error */)
2734 : {
2735 78802062 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
2736 78802062 : bool try_omp_private = !object && omp_private_member_map;
2737 68697423 : tree ret;
2738 :
2739 68697423 : if (!object)
2740 : {
2741 68697423 : tree scope = qualifying_scope;
2742 68697423 : if (scope == NULL_TREE)
2743 : {
2744 68685869 : scope = context_for_name_lookup (decl);
2745 68685869 : 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 68697420 : object = maybe_dummy_object (scope, NULL);
2753 : }
2754 :
2755 78802059 : object = maybe_resolve_dummy (object, true);
2756 78802059 : 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 78802056 : if (is_dummy_object (object)
2762 35805 : && !cp_unevaluated_operand
2763 78802162 : && (!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 78801965 : if (current_class_ptr)
2788 78476474 : TREE_USED (current_class_ptr) = 1;
2789 78801965 : if (processing_template_decl)
2790 : {
2791 62727879 : tree type = TREE_TYPE (decl);
2792 :
2793 62727879 : if (TYPE_REF_P (type))
2794 : /* Quals on the object don't matter. */;
2795 60373718 : else if (PACK_EXPANSION_P (type))
2796 : /* Don't bother trying to represent this. */
2797 : type = NULL_TREE;
2798 60370746 : 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 60367126 : int quals = cp_type_quals (TREE_TYPE (object));
2812 :
2813 60367126 : if (DECL_MUTABLE_P (decl))
2814 243033 : quals &= ~TYPE_QUAL_CONST;
2815 :
2816 60367126 : quals |= cp_type_quals (TREE_TYPE (decl));
2817 60367126 : type = cp_build_qualified_type (type, quals);
2818 : }
2819 :
2820 62727879 : if (qualifying_scope)
2821 : /* Wrap this in a SCOPE_REF for now. */
2822 9486 : ret = build_qualified_name (type, qualifying_scope, decl,
2823 : /*template_p=*/false);
2824 : else
2825 62718393 : ret = (convert_from_reference
2826 62718393 : (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 16074086 : tree access_type = TREE_TYPE (object);
2833 :
2834 16074086 : 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 16074086 : if (qualifying_scope)
2841 : {
2842 2021 : tree binfo = NULL_TREE;
2843 2021 : object = build_scoped_ref (object, qualifying_scope,
2844 : &binfo);
2845 : }
2846 :
2847 16074086 : ret = build_class_member_access_expr (object, decl,
2848 : /*access_path=*/NULL_TREE,
2849 : /*preserve_reference=*/false,
2850 : complain);
2851 : }
2852 78801965 : 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 4956807838 : 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 4956807838 : if (deferred_access_no_check)
2876 : return true;
2877 :
2878 : /* Determine the SCOPE of DECL. */
2879 4945600686 : tree scope = context_for_name_lookup (decl);
2880 : /* If the SCOPE is not a type, then DECL is not a member. */
2881 4945600686 : 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 4945600686 : || dependent_type_p (scope))
2886 4472340517 : return true;
2887 :
2888 473260169 : tree qualifying_type = NULL_TREE;
2889 : /* Compute the scope through which DECL is being accessed. */
2890 473260169 : 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 101153 : && CLASS_TYPE_P (object_type)
2900 473361305 : && 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 101127 : if (tree open = currently_open_class (object_type))
2905 : qualifying_type = open;
2906 : else
2907 : qualifying_type = object_type;
2908 : }
2909 473159042 : 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 628446767 : if (DECL_NONSTATIC_MEMBER_P (decl)
2915 314275272 : && current_class_ptr)
2916 41215 : if (tree current = current_nonlambda_class_type ())
2917 : {
2918 41192 : 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 3584 : 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 158935657 : qualifying_type = currently_open_derived_class (scope);
2938 :
2939 473159730 : 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 473222561 : && CLASS_TYPE_P (qualifying_type))
2943 445881499 : return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2944 445881499 : 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 84863774 : 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 84863774 : gcc_assert (TYPE_P (qualifying_class));
2967 :
2968 84863774 : if (error_operand_p (expr))
2969 21 : return error_mark_node;
2970 :
2971 84863753 : if (DECL_P (expr)
2972 : /* Functions are marked after overload resolution; avoid redundant
2973 : warnings. */
2974 77611277 : && TREE_CODE (expr) != FUNCTION_DECL
2975 162475006 : && !mark_used (expr, complain))
2976 0 : return error_mark_node;
2977 :
2978 84863753 : if (template_p)
2979 : {
2980 268831 : 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 268822 : 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 84863753 : if (address_p && done
2994 162928 : && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
2995 : {
2996 162926 : if (TREE_CODE (expr) == SCOPE_REF)
2997 0 : expr = TREE_OPERAND (expr, 1);
2998 162926 : expr = build_offset_ref (qualifying_class, expr,
2999 : /*address_p=*/true, complain);
3000 162926 : return expr;
3001 : }
3002 :
3003 : /* No need to check access within an enum. */
3004 84700827 : if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
3005 3605190 : && 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 81095640 : 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 81092976 : else if (TREE_CODE (expr) == FIELD_DECL)
3015 : {
3016 11554 : push_deferring_access_checks (dk_no_check);
3017 11554 : expr = finish_non_static_data_member (expr, NULL_TREE,
3018 : qualifying_class, complain);
3019 11554 : pop_deferring_access_checks ();
3020 : }
3021 81081422 : 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 6767114 : if (!shared_member_p (expr)
3026 449268 : && current_class_ptr
3027 7215695 : && DERIVED_FROM_P (qualifying_class,
3028 : current_nonlambda_class_type ()))
3029 448267 : expr = (build_class_member_access_expr
3030 448267 : (maybe_dummy_object (qualifying_class, NULL),
3031 : expr,
3032 448267 : BASELINK_ACCESS_BINFO (expr),
3033 : /*preserve_reference=*/false,
3034 : complain));
3035 6318847 : else if (done)
3036 : /* The expression is a qualified name whose address is not
3037 : being taken. */
3038 3277 : expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
3039 : complain);
3040 : }
3041 74314308 : else if (!template_p
3042 74102238 : && TREE_CODE (expr) == TEMPLATE_DECL
3043 74314391 : && !DECL_FUNCTION_TEMPLATE_P (expr))
3044 : {
3045 83 : if (complain & tf_error)
3046 5 : error ("%qE missing template arguments", expr);
3047 83 : return error_mark_node;
3048 : }
3049 : else
3050 : {
3051 : /* In a template, return a SCOPE_REF for most qualified-ids
3052 : so that we can check access at instantiation time. But if
3053 : we're looking at a member of the current instantiation, we
3054 : know we have access and building up the SCOPE_REF confuses
3055 : non-type template argument handling. */
3056 74314225 : if (processing_template_decl
3057 74314225 : && (!currently_open_class (qualifying_class)
3058 10588 : || TREE_CODE (expr) == IDENTIFIER_NODE
3059 10588 : || TREE_CODE (expr) == TEMPLATE_ID_EXPR
3060 82 : || TREE_CODE (expr) == BIT_NOT_EXPR))
3061 11100505 : expr = build_qualified_name (TREE_TYPE (expr),
3062 : qualifying_class, expr,
3063 : template_p);
3064 63213720 : else if (tree wrap = maybe_get_tls_wrapper_call (expr))
3065 9 : expr = wrap;
3066 :
3067 74314225 : 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 5578439 : begin_stmt_expr (void)
3078 : {
3079 5578439 : 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 29117 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
3089 : {
3090 29117 : 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 29114 : if (expr)
3101 : {
3102 29099 : tree type = TREE_TYPE (expr);
3103 :
3104 29099 : 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 29084 : 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 28915 : 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 28884 : expr = force_rvalue (expr, tf_warning_or_error);
3131 28884 : if (error_operand_p (expr))
3132 0 : return error_mark_node;
3133 :
3134 : /* Update for array-to-pointer decay. */
3135 28884 : type = TREE_TYPE (expr);
3136 :
3137 : /* This TARGET_EXPR will initialize the outer one added by
3138 : finish_stmt_expr. */
3139 28884 : 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 28884 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
3145 28884 : expr = maybe_cleanup_point_expr (expr);
3146 28884 : add_stmt (expr);
3147 : }
3148 :
3149 : /* The type of the statement-expression is the type of the last
3150 : expression. */
3151 29084 : 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 5578439 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
3163 : {
3164 5578439 : tree type;
3165 5578439 : tree result;
3166 :
3167 5578439 : if (error_operand_p (stmt_expr))
3168 : {
3169 18 : pop_stmt_list (stmt_expr);
3170 18 : return error_mark_node;
3171 : }
3172 :
3173 5578421 : gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
3174 :
3175 5578421 : type = TREE_TYPE (stmt_expr);
3176 5578421 : result = pop_stmt_list (stmt_expr);
3177 5578421 : TREE_TYPE (result) = type;
3178 :
3179 5578421 : if (processing_template_decl)
3180 : {
3181 37940 : result = build_min (STMT_EXPR, type, result);
3182 37940 : TREE_SIDE_EFFECTS (result) = 1;
3183 37940 : STMT_EXPR_NO_SCOPE (result) = has_no_scope;
3184 : }
3185 5540481 : 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 63136781 : empty_expr_stmt_p (tree expr_stmt)
3221 : {
3222 63136786 : tree body = NULL_TREE;
3223 :
3224 63136786 : if (expr_stmt == void_node)
3225 : return true;
3226 :
3227 63136783 : if (expr_stmt)
3228 : {
3229 63136783 : if (TREE_CODE (expr_stmt) == EXPR_STMT)
3230 5 : body = EXPR_STMT_EXPR (expr_stmt);
3231 63136778 : else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
3232 : body = expr_stmt;
3233 : }
3234 :
3235 5 : if (body)
3236 : {
3237 62201556 : if (TREE_CODE (body) == STATEMENT_LIST)
3238 62201551 : 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 19152330 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
3251 : tsubst_flags_t complain)
3252 : {
3253 19152330 : tree identifier = NULL_TREE;
3254 19152330 : tree functions = NULL_TREE;
3255 19152330 : tree tmpl_args = NULL_TREE;
3256 19152330 : bool template_id = false;
3257 19152330 : location_t loc = fn_expr.get_location ();
3258 19152330 : tree fn = fn_expr.get_value ();
3259 :
3260 19152330 : STRIP_ANY_LOCATION_WRAPPER (fn);
3261 :
3262 19152330 : if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
3263 : {
3264 : /* Use a separate flag to handle null args. */
3265 3747253 : template_id = true;
3266 3747253 : tmpl_args = TREE_OPERAND (fn, 1);
3267 3747253 : fn = TREE_OPERAND (fn, 0);
3268 : }
3269 :
3270 : /* Find the name of the overloaded function. */
3271 19152330 : if (identifier_p (fn))
3272 : identifier = fn;
3273 : else
3274 : {
3275 27133767 : functions = fn;
3276 18953122 : 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 19152330 : if (!any_type_dependent_arguments_p (args)
3284 19152330 : && !any_dependent_template_arguments_p (tmpl_args))
3285 : {
3286 18214458 : fn = lookup_arg_dependent (identifier, functions, args);
3287 18214458 : if (!fn)
3288 : {
3289 : /* The unqualified name could not be resolved. */
3290 59126 : if (complain & tf_error)
3291 391 : fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
3292 : else
3293 : fn = identifier;
3294 : }
3295 : }
3296 :
3297 19152330 : if (fn && template_id && fn != error_mark_node)
3298 3747240 : fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
3299 :
3300 19152330 : return cp_expr (fn, loc);
3301 : }
3302 :
3303 : /* Generate an expression for `FN (ARGS)'. This may change the
3304 : contents of ARGS.
3305 :
3306 : If DISALLOW_VIRTUAL is true, the call to FN will be not generated
3307 : as a virtual call, even if FN is virtual. (This flag is set when
3308 : encountering an expression where the function name is explicitly
3309 : qualified. For example a call to `X::f' never generates a virtual
3310 : call.)
3311 :
3312 : Returns code for the call. */
3313 :
3314 : tree
3315 372681614 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
3316 : bool koenig_p, tsubst_flags_t complain)
3317 : {
3318 372681614 : tree result;
3319 372681614 : tree orig_fn;
3320 372681614 : vec<tree, va_gc> *orig_args = *args;
3321 372681614 : tsubst_flags_t orig_complain = complain;
3322 :
3323 372681614 : if (fn == error_mark_node)
3324 : return error_mark_node;
3325 :
3326 372680555 : complain &= ~tf_any_viable;
3327 372680555 : gcc_assert (!TYPE_P (fn));
3328 :
3329 : /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
3330 : it so that we can tell this is a call to a known function. */
3331 372680555 : fn = maybe_undo_parenthesized_ref (fn);
3332 :
3333 372680555 : STRIP_ANY_LOCATION_WRAPPER (fn);
3334 :
3335 372680555 : orig_fn = fn;
3336 :
3337 372680555 : if (concept_check_p (fn))
3338 : {
3339 6 : error_at (EXPR_LOC_OR_LOC (fn, input_location),
3340 : "cannot call a concept as a function");
3341 6 : return error_mark_node;
3342 : }
3343 :
3344 372680549 : if (processing_template_decl)
3345 : {
3346 : /* If FN is a local extern declaration (or set thereof) in a template,
3347 : look it up again at instantiation time. */
3348 240755974 : if (is_overloaded_fn (fn))
3349 : {
3350 148042964 : tree ifn = get_first_fn (fn);
3351 148042964 : if (TREE_CODE (ifn) == FUNCTION_DECL
3352 148042964 : && dependent_local_decl_p (ifn))
3353 40920 : orig_fn = DECL_NAME (ifn);
3354 : }
3355 :
3356 : /* If the call expression is dependent, build a CALL_EXPR node
3357 : with no type; type_dependent_expression_p recognizes
3358 : expressions with no type as being dependent. */
3359 240755974 : if (type_dependent_expression_p (fn)
3360 240755974 : || any_type_dependent_arguments_p (*args))
3361 : {
3362 218348975 : if (koenig_p
3363 10747929 : && TREE_CODE (orig_fn) == FUNCTION_DECL
3364 221688423 : && !fndecl_built_in_p (orig_fn))
3365 : /* For an ADL-enabled call where unqualified lookup found a
3366 : single non-template function, wrap it in an OVERLOAD so that
3367 : later substitution doesn't overeagerly mark the function as
3368 : used. */
3369 874862 : orig_fn = ovl_make (orig_fn, NULL_TREE);
3370 218348975 : result = build_min_nt_call_vec (orig_fn, *args);
3371 296793188 : SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
3372 218348975 : KOENIG_LOOKUP_P (result) = koenig_p;
3373 : /* Disable the std::move warnings since this call was dependent
3374 : (c++/89780, c++/107363). This also suppresses the
3375 : -Wredundant-move warning. */
3376 218348975 : suppress_warning (result, OPT_Wpessimizing_move);
3377 :
3378 218348975 : if (cfun && cp_function_chain && !cp_unevaluated_operand)
3379 : {
3380 190067831 : bool abnormal = true;
3381 190342537 : for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
3382 : {
3383 105733039 : tree fndecl = STRIP_TEMPLATE (*iter);
3384 105733039 : if (TREE_CODE (fndecl) != FUNCTION_DECL
3385 105732961 : || !TREE_THIS_VOLATILE (fndecl))
3386 : {
3387 : abnormal = false;
3388 : break;
3389 : }
3390 : }
3391 : /* FIXME: Stop warning about falling off end of non-void
3392 : function. But this is wrong. Even if we only see
3393 : no-return fns at this point, we could select a
3394 : future-defined return fn during instantiation. Or
3395 : vice-versa. */
3396 190067831 : if (abnormal)
3397 84609498 : current_function_returns_abnormally = 1;
3398 : }
3399 218348975 : if (TREE_CODE (fn) == COMPONENT_REF)
3400 101007190 : maybe_generic_this_capture (TREE_OPERAND (fn, 0),
3401 101007190 : TREE_OPERAND (fn, 1));
3402 218348975 : return result;
3403 : }
3404 22406999 : orig_args = make_tree_vector_copy (*args);
3405 : }
3406 :
3407 154331574 : if (TREE_CODE (fn) == COMPONENT_REF)
3408 : {
3409 29788608 : tree member = TREE_OPERAND (fn, 1);
3410 29788608 : if (BASELINK_P (member))
3411 : {
3412 29599492 : tree object = TREE_OPERAND (fn, 0);
3413 58789021 : return build_new_method_call (object, member,
3414 : args, NULL_TREE,
3415 : (disallow_virtual
3416 : ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
3417 : : LOOKUP_NORMAL),
3418 : /*fn_p=*/NULL,
3419 29599492 : complain);
3420 : }
3421 : }
3422 :
3423 : /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
3424 124732082 : if (TREE_CODE (fn) == ADDR_EXPR
3425 124732082 : && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
3426 9 : fn = TREE_OPERAND (fn, 0);
3427 :
3428 124732082 : if (is_overloaded_fn (fn))
3429 115947249 : fn = baselink_for_fns (fn);
3430 :
3431 124732082 : result = NULL_TREE;
3432 124732082 : if (BASELINK_P (fn))
3433 : {
3434 14240123 : tree object;
3435 :
3436 : /* A call to a member function. From [over.call.func]:
3437 :
3438 : If the keyword this is in scope and refers to the class of
3439 : that member function, or a derived class thereof, then the
3440 : function call is transformed into a qualified function call
3441 : using (*this) as the postfix-expression to the left of the
3442 : . operator.... [Otherwise] a contrived object of type T
3443 : becomes the implied object argument.
3444 :
3445 : In this situation:
3446 :
3447 : struct A { void f(); };
3448 : struct B : public A {};
3449 : struct C : public A { void g() { B::f(); }};
3450 :
3451 : "the class of that member function" refers to `A'. But 11.2
3452 : [class.access.base] says that we need to convert 'this' to B* as
3453 : part of the access, so we pass 'B' to maybe_dummy_object. */
3454 :
3455 14240123 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
3456 : {
3457 : /* A constructor call always uses a dummy object. (This constructor
3458 : call which has the form A::A () is actually invalid and we are
3459 : going to reject it later in build_new_method_call.) */
3460 39 : object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
3461 : }
3462 : else
3463 14240084 : object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
3464 : NULL);
3465 :
3466 16256173 : result = build_new_method_call (object, fn, args, NULL_TREE,
3467 : (disallow_virtual
3468 : ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
3469 : : LOOKUP_NORMAL),
3470 : /*fn_p=*/NULL,
3471 : complain);
3472 : }
3473 110491959 : else if (is_overloaded_fn (fn))
3474 : {
3475 : /* If the function is an overloaded builtin, resolve it. */
3476 101707126 : if (TREE_CODE (fn) == FUNCTION_DECL
3477 101707126 : && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
3478 18958877 : || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
3479 9466378 : result = resolve_overloaded_builtin (input_location, fn, *args,
3480 : complain & tf_error);
3481 :
3482 9466378 : if (!result)
3483 : {
3484 101361564 : tree alloc_size_attr = NULL_TREE;
3485 101361564 : if (warn_calloc_transposed_args
3486 703833 : && TREE_CODE (fn) == FUNCTION_DECL
3487 101361564 : && (alloc_size_attr
3488 430639 : = lookup_attribute ("alloc_size",
3489 430639 : TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
3490 3401 : if (TREE_VALUE (alloc_size_attr) == NULL_TREE
3491 3401 : || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
3492 : alloc_size_attr = NULL_TREE;
3493 99654975 : if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
3494 1706649 : && (complain & tf_warning)
3495 1493533 : && !vec_safe_is_empty (*args)
3496 102511166 : && !processing_template_decl)
3497 : {
3498 : location_t sizeof_arg_loc[6];
3499 : tree sizeof_arg[6];
3500 : unsigned int i;
3501 8248044 : for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
3502 : {
3503 3093219 : tree t;
3504 :
3505 3093219 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
3506 3093219 : sizeof_arg[i] = NULL_TREE;
3507 3093219 : if (i >= (*args)->length ())
3508 651901 : continue;
3509 2441318 : t = (**args)[i];
3510 2441318 : if (TREE_CODE (t) != SIZEOF_EXPR)
3511 2434670 : continue;
3512 6648 : if (SIZEOF_EXPR_TYPE_P (t))
3513 2654 : sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
3514 : else
3515 3994 : sizeof_arg[i] = TREE_OPERAND (t, 0);
3516 6648 : sizeof_arg_loc[i] = EXPR_LOCATION (t);
3517 : }
3518 1031013 : if (warn_sizeof_pointer_memaccess)
3519 : {
3520 1030953 : auto same_p = same_type_ignoring_top_level_qualifiers_p;
3521 1030953 : sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
3522 : sizeof_arg, same_p);
3523 : }
3524 1031013 : if (alloc_size_attr)
3525 60 : warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
3526 : alloc_size_attr);
3527 : }
3528 :
3529 101361564 : if ((complain & tf_warning)
3530 55998939 : && TREE_CODE (fn) == FUNCTION_DECL
3531 26710633 : && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
3532 142205 : && vec_safe_length (*args) == 3
3533 101503769 : && !any_type_dependent_arguments_p (*args))
3534 : {
3535 142205 : tree arg0 = (*orig_args)[0];
3536 142205 : tree arg1 = (*orig_args)[1];
3537 142205 : tree arg2 = (*orig_args)[2];
3538 142205 : int literal_mask = ((literal_integer_zerop (arg1) << 1)
3539 142205 : | (literal_integer_zerop (arg2) << 2));
3540 142205 : warn_for_memset (input_location, arg0, arg2, literal_mask);
3541 : }
3542 :
3543 : /* A call to a namespace-scope function. */
3544 101361564 : result = build_new_function_call (fn, args, orig_complain);
3545 : }
3546 : }
3547 8784833 : else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
3548 : {
3549 160863 : if (!vec_safe_is_empty (*args))
3550 0 : error ("arguments to destructor are not allowed");
3551 : /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
3552 : which case the postfix-expression is a possibly-parenthesized class
3553 : member access), the function call destroys the object of scalar type
3554 : denoted by the object expression of the class member access. */
3555 160863 : tree ob = TREE_OPERAND (fn, 0);
3556 160863 : if (obvalue_p (ob))
3557 160845 : result = build_trivial_dtor_call (ob, true);
3558 : else
3559 : /* No location to clobber. */
3560 18 : result = convert_to_void (ob, ICV_STATEMENT, complain);
3561 : }
3562 8623970 : else if (CLASS_TYPE_P (TREE_TYPE (fn)))
3563 : /* If the "function" is really an object of class type, it might
3564 : have an overloaded `operator ()'. */
3565 2587282 : result = build_op_call (fn, args, complain);
3566 :
3567 118336314 : if (!result)
3568 : /* A call where the function is unknown. */
3569 6036688 : result = cp_build_function_call_vec (fn, args, complain);
3570 :
3571 124718564 : if (processing_template_decl && result != error_mark_node)
3572 : {
3573 16758398 : if (INDIRECT_REF_P (result))
3574 1141126 : result = TREE_OPERAND (result, 0);
3575 :
3576 : /* Prune all but the selected function from the original overload
3577 : set so that we can avoid some duplicate work at instantiation time. */
3578 16758398 : if (TREE_CODE (result) == CALL_EXPR
3579 16748670 : && really_overloaded_fn (orig_fn))
3580 : {
3581 6217034 : tree sel_fn = CALL_EXPR_FN (result);
3582 6217034 : if (TREE_CODE (sel_fn) == COMPONENT_REF)
3583 : {
3584 : /* The non-dependent result of build_new_method_call. */
3585 261008 : sel_fn = TREE_OPERAND (sel_fn, 1);
3586 261008 : gcc_assert (BASELINK_P (sel_fn));
3587 : }
3588 5956026 : else if (TREE_CODE (sel_fn) == ADDR_EXPR)
3589 : /* Our original callee wasn't wrapped in an ADDR_EXPR,
3590 : so strip this ADDR_EXPR added by build_over_call. */
3591 5956026 : sel_fn = TREE_OPERAND (sel_fn, 0);
3592 : orig_fn = sel_fn;
3593 : }
3594 :
3595 16758398 : tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
3596 16758398 : SET_EXPR_LOCATION (r, input_location);
3597 16758398 : KOENIG_LOOKUP_P (r) = koenig_p;
3598 16758398 : TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
3599 16758398 : release_tree_vector (orig_args);
3600 16758398 : result = convert_from_reference (r);
3601 : }
3602 :
3603 : return result;
3604 : }
3605 :
3606 : /* Finish a call to a postfix increment or decrement or EXPR. (Which
3607 : is indicated by CODE, which should be POSTINCREMENT_EXPR or
3608 : POSTDECREMENT_EXPR.) */
3609 :
3610 : cp_expr
3611 2677848 : finish_increment_expr (cp_expr expr, enum tree_code code)
3612 : {
3613 : /* input_location holds the location of the trailing operator token.
3614 : Build a location of the form:
3615 : expr++
3616 : ~~~~^~
3617 : with the caret at the operator token, ranging from the start
3618 : of EXPR to the end of the operator token. */
3619 2677848 : location_t combined_loc = make_location (input_location,
3620 : expr.get_start (),
3621 : get_finish (input_location));
3622 2677848 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3623 2677848 : NULL_TREE, tf_warning_or_error);
3624 : /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3625 2677848 : result.set_location (combined_loc);
3626 2677848 : return result;
3627 : }
3628 :
3629 : /* Finish a use of `this'. Returns an expression for `this'. */
3630 :
3631 : tree
3632 36741614 : finish_this_expr (void)
3633 : {
3634 36741614 : tree result = NULL_TREE;
3635 :
3636 73483104 : if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
3637 36454458 : result = current_class_ptr;
3638 574296 : else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
3639 287080 : result = (lambda_expr_this_capture
3640 287080 : (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
3641 : else
3642 76 : gcc_checking_assert (!current_class_ptr);
3643 :
3644 36741538 : if (result)
3645 : /* The keyword 'this' is a prvalue expression. */
3646 36741535 : return rvalue (result);
3647 :
3648 79 : tree fn = current_nonlambda_function ();
3649 79 : if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
3650 : {
3651 6 : auto_diagnostic_group d;
3652 6 : error ("%<this%> is unavailable for explicit object member "
3653 : "functions");
3654 6 : tree xobj_parm = DECL_ARGUMENTS (fn);
3655 6 : gcc_assert (xobj_parm);
3656 6 : tree parm_name = DECL_NAME (xobj_parm);
3657 :
3658 6 : static tree remembered_fn = NULL_TREE;
3659 : /* Only output this diagnostic once per function. */
3660 6 : if (remembered_fn == fn)
3661 : /* Early escape. */;
3662 6 : else if (parm_name)
3663 6 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3664 : "use explicit object parameter %qs instead",
3665 3 : IDENTIFIER_POINTER (parm_name));
3666 : else
3667 3 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3668 : "name the explicit object parameter");
3669 :
3670 6 : remembered_fn = fn;
3671 6 : }
3672 73 : else if (fn && DECL_STATIC_FUNCTION_P (fn))
3673 3 : error ("%<this%> is unavailable for static member functions");
3674 70 : else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
3675 0 : error ("invalid use of %<this%> in a constructor %<pre%> condition");
3676 70 : else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
3677 0 : error ("invalid use of %<this%> in a destructor %<post%> condition");
3678 70 : else if (fn)
3679 22 : error ("invalid use of %<this%> in non-member function");
3680 : else
3681 48 : error ("invalid use of %<this%> at top level");
3682 79 : return error_mark_node;
3683 : }
3684 :
3685 : /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3686 : expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3687 : the TYPE for the type given. If SCOPE is non-NULL, the expression
3688 : was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3689 :
3690 : tree
3691 160914 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
3692 : location_t loc, tsubst_flags_t complain)
3693 : {
3694 160914 : if (object == error_mark_node || destructor == error_mark_node)
3695 : return error_mark_node;
3696 :
3697 160905 : gcc_assert (TYPE_P (destructor));
3698 :
3699 160905 : if (!processing_template_decl)
3700 : {
3701 160884 : if (scope == error_mark_node)
3702 : {
3703 0 : if (complain & tf_error)
3704 0 : error_at (loc, "invalid qualifying scope in pseudo-destructor name");
3705 0 : return error_mark_node;
3706 : }
3707 160884 : if (is_auto (destructor))
3708 3 : destructor = TREE_TYPE (object);
3709 160884 : if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
3710 : {
3711 3 : if (complain & tf_error)
3712 3 : error_at (loc,
3713 : "qualified type %qT does not match destructor name ~%qT",
3714 : scope, destructor);
3715 3 : return error_mark_node;
3716 : }
3717 :
3718 :
3719 : /* [expr.pseudo] says both:
3720 :
3721 : The type designated by the pseudo-destructor-name shall be
3722 : the same as the object type.
3723 :
3724 : and:
3725 :
3726 : The cv-unqualified versions of the object type and of the
3727 : type designated by the pseudo-destructor-name shall be the
3728 : same type.
3729 :
3730 : We implement the more generous second sentence, since that is
3731 : what most other compilers do. */
3732 160881 : if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
3733 : destructor))
3734 : {
3735 12 : if (complain & tf_error)
3736 9 : error_at (loc, "%qE is not of type %qT", object, destructor);
3737 12 : return error_mark_node;
3738 : }
3739 : }
3740 :
3741 160890 : tree type = (type_dependent_expression_p (object)
3742 160890 : ? NULL_TREE : void_type_node);
3743 :
3744 160890 : return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
3745 160890 : scope, destructor);
3746 : }
3747 :
3748 : /* Finish an expression of the form CODE EXPR. */
3749 :
3750 : cp_expr
3751 39175552 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
3752 : tsubst_flags_t complain)
3753 : {
3754 : /* Build a location of the form:
3755 : ++expr
3756 : ^~~~~~
3757 : with the caret at the operator token, ranging from the start
3758 : of the operator token to the end of EXPR. */
3759 39175552 : location_t combined_loc = make_location (op_loc,
3760 : op_loc, expr.get_finish ());
3761 39175552 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3762 39175552 : NULL_TREE, complain);
3763 : /* TODO: build_x_unary_op doesn't always honor the location. */
3764 39175552 : result.set_location (combined_loc);
3765 :
3766 39175552 : if (result == error_mark_node)
3767 : return result;
3768 :
3769 39175067 : if (!(complain & tf_warning))
3770 : return result;
3771 :
3772 : /* These will never fold into a constant, so no need to check for
3773 : overflow for them. */
3774 39175067 : if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
3775 : return result;
3776 :
3777 21157752 : tree result_ovl = result;
3778 21157752 : tree expr_ovl = expr;
3779 :
3780 21157752 : if (!processing_template_decl)
3781 1857484 : expr_ovl = cp_fully_fold (expr_ovl);
3782 :
3783 21157752 : if (!CONSTANT_CLASS_P (expr_ovl)
3784 21157752 : || TREE_OVERFLOW_P (expr_ovl))
3785 : return result;
3786 :
3787 259123 : if (!processing_template_decl)
3788 249700 : result_ovl = cp_fully_fold (result_ovl);
3789 :
3790 259123 : if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
3791 9 : overflow_warning (combined_loc, result_ovl);
3792 :
3793 : return result;
3794 : }
3795 :
3796 : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3797 : elements. */
3798 :
3799 : static bool
3800 12 : maybe_zero_constructor_nelts (tree expr)
3801 : {
3802 12 : if (CONSTRUCTOR_NELTS (expr) == 0)
3803 : return true;
3804 12 : if (!processing_template_decl)
3805 : return false;
3806 30 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
3807 21 : if (!PACK_EXPANSION_P (elt.value))
3808 : return false;
3809 : return true;
3810 : }
3811 :
3812 : /* Finish a compound-literal expression or C++11 functional cast with aggregate
3813 : initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3814 : is being cast. */
3815 :
3816 : tree
3817 9983517 : finish_compound_literal (tree type, tree compound_literal,
3818 : tsubst_flags_t complain,
3819 : fcl_t fcl_context)
3820 : {
3821 9983517 : if (type == error_mark_node)
3822 : return error_mark_node;
3823 :
3824 9983465 : if (TYPE_REF_P (type))
3825 : {
3826 12 : compound_literal
3827 12 : = finish_compound_literal (TREE_TYPE (type), compound_literal,
3828 : complain, fcl_context);
3829 : /* The prvalue is then used to direct-initialize the reference. */
3830 12 : tree r = (perform_implicit_conversion_flags
3831 12 : (type, compound_literal, complain, LOOKUP_NORMAL));
3832 12 : return convert_from_reference (r);
3833 : }
3834 :
3835 9983453 : if (!TYPE_OBJ_P (type))
3836 : {
3837 : /* DR2351 */
3838 60 : if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
3839 : {
3840 12 : if (!processing_template_decl)
3841 9 : return void_node;
3842 3 : TREE_TYPE (compound_literal) = type;
3843 3 : TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
3844 3 : CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
3845 3 : return compound_literal;
3846 : }
3847 21 : else if (VOID_TYPE_P (type)
3848 15 : && processing_template_decl
3849 33 : && maybe_zero_constructor_nelts (compound_literal))
3850 : /* If there are only packs in compound_literal, it could
3851 : be void{} after pack expansion. */;
3852 : else
3853 : {
3854 12 : if (complain & tf_error)
3855 9 : error ("compound literal of non-object type %qT", type);
3856 12 : return error_mark_node;
3857 : }
3858 : }
3859 :
3860 9983429 : if (template_placeholder_p (type))
3861 : {
3862 193157 : type = do_auto_deduction (type, compound_literal, type, complain,
3863 : adc_variable_type);
3864 193157 : if (type == error_mark_node)
3865 : return error_mark_node;
3866 : }
3867 : /* C++23 auto{x}. */
3868 9790272 : else if (is_auto (type)
3869 162 : && !AUTO_IS_DECLTYPE (type)
3870 9790431 : && CONSTRUCTOR_NELTS (compound_literal) == 1)
3871 : {
3872 150 : if (is_constrained_auto (type))
3873 : {
3874 3 : if (complain & tf_error)
3875 3 : error ("%<auto{x}%> cannot be constrained");
3876 3 : return error_mark_node;
3877 : }
3878 147 : else if (cxx_dialect < cxx23)
3879 : {
3880 1 : if ((complain & tf_warning_or_error) == 0)
3881 0 : return error_mark_node;
3882 1 : pedwarn (input_location, OPT_Wc__23_extensions,
3883 : "%<auto{x}%> only available with "
3884 : "%<-std=c++23%> or %<-std=gnu++23%>");
3885 : }
3886 147 : type = do_auto_deduction (type, compound_literal, type, complain,
3887 : adc_variable_type);
3888 147 : if (type == error_mark_node)
3889 : return error_mark_node;
3890 : }
3891 :
3892 : /* Used to hold a copy of the compound literal in a template. */
3893 9983284 : tree orig_cl = NULL_TREE;
3894 :
3895 9983284 : if (processing_template_decl)
3896 : {
3897 5237323 : const bool dependent_p
3898 5237323 : = (instantiation_dependent_expression_p (compound_literal)
3899 5237323 : || dependent_type_p (type));
3900 1739418 : if (dependent_p)
3901 : /* We're about to return, no need to copy. */
3902 : orig_cl = compound_literal;
3903 : else
3904 : /* We're going to need a copy. */
3905 1739418 : orig_cl = unshare_constructor (compound_literal);
3906 5237323 : TREE_TYPE (orig_cl) = type;
3907 : /* Mark the expression as a compound literal. */
3908 5237323 : TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
3909 : /* And as instantiation-dependent. */
3910 5237323 : CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
3911 5237323 : if (fcl_context == fcl_c99)
3912 130 : CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
3913 : /* If the compound literal is dependent, we're done for now. */
3914 5237323 : if (dependent_p)
3915 : return orig_cl;
3916 : /* Otherwise, do go on to e.g. check narrowing. */
3917 : }
3918 :
3919 6485379 : type = complete_type (type);
3920 :
3921 6485379 : if (TYPE_NON_AGGREGATE_CLASS (type))
3922 : {
3923 : /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3924 : everywhere that deals with function arguments would be a pain, so
3925 : just wrap it in a TREE_LIST. The parser set a flag so we know
3926 : that it came from T{} rather than T({}). */
3927 1090403 : CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
3928 1090403 : compound_literal = build_tree_list (NULL_TREE, compound_literal);
3929 1090403 : return build_functional_cast (input_location, type,
3930 1090403 : compound_literal, complain);
3931 : }
3932 :
3933 5394976 : if (TREE_CODE (type) == ARRAY_TYPE
3934 5394976 : && check_array_initializer (NULL_TREE, type, compound_literal))
3935 9 : return error_mark_node;
3936 5394967 : compound_literal = reshape_init (type, compound_literal, complain);
3937 5185047 : if (SCALAR_TYPE_P (type)
3938 740113 : && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
3939 5612270 : && !check_narrowing (type, compound_literal, complain))
3940 131 : return error_mark_node;
3941 5394836 : if (TREE_CODE (type) == ARRAY_TYPE
3942 5394836 : && TYPE_DOMAIN (type) == NULL_TREE)
3943 : {
3944 1253 : cp_complete_array_type_or_error (&type, compound_literal,
3945 : false, complain);
3946 1253 : if (type == error_mark_node)
3947 : return error_mark_node;
3948 : }
3949 5394833 : compound_literal = digest_init_flags (type, compound_literal,
3950 : LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
3951 : complain);
3952 5394833 : if (compound_literal == error_mark_node)
3953 : return error_mark_node;
3954 :
3955 : /* If we're in a template, return the original compound literal. */
3956 5394209 : if (orig_cl)
3957 : return orig_cl;
3958 :
3959 3752228 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3960 : {
3961 3068598 : TREE_HAS_CONSTRUCTOR (compound_literal) = true;
3962 3068598 : if (fcl_context == fcl_c99)
3963 37961 : CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
3964 : }
3965 :
3966 : /* Put static/constant array temporaries in static variables. */
3967 : /* FIXME all C99 compound literals should be variables rather than C++
3968 : temporaries, unless they are used as an aggregate initializer. */
3969 4934771 : if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
3970 2579067 : && fcl_context == fcl_c99
3971 83 : && TREE_CODE (type) == ARRAY_TYPE
3972 31 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
3973 3752259 : && initializer_constant_valid_p (compound_literal, type))
3974 : {
3975 31 : tree decl = create_temporary_var (type);
3976 31 : DECL_CONTEXT (decl) = NULL_TREE;
3977 31 : DECL_INITIAL (decl) = compound_literal;
3978 31 : TREE_STATIC (decl) = 1;
3979 31 : if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
3980 : {
3981 : /* 5.19 says that a constant expression can include an
3982 : lvalue-rvalue conversion applied to "a glvalue of literal type
3983 : that refers to a non-volatile temporary object initialized
3984 : with a constant expression". Rather than try to communicate
3985 : that this VAR_DECL is a temporary, just mark it constexpr. */
3986 24 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
3987 24 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
3988 24 : TREE_CONSTANT (decl) = true;
3989 : }
3990 31 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
3991 31 : decl = pushdecl_top_level (decl);
3992 31 : DECL_NAME (decl) = make_anon_name ();
3993 31 : SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
3994 : /* Make sure the destructor is callable. */
3995 31 : tree clean = cxx_maybe_build_cleanup (decl, complain);
3996 31 : if (clean == error_mark_node)
3997 : return error_mark_node;
3998 31 : return decl;
3999 : }
4000 :
4001 : /* Represent other compound literals with TARGET_EXPR so we produce
4002 : a prvalue, and can elide copies. */
4003 3752197 : if (!VECTOR_TYPE_P (type)
4004 3711630 : && (TREE_CODE (compound_literal) == CONSTRUCTOR
4005 683624 : || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
4006 : {
4007 : /* The CONSTRUCTOR is now an initializer, not a compound literal. */
4008 3028006 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
4009 3028006 : TREE_HAS_CONSTRUCTOR (compound_literal) = false;
4010 3028006 : compound_literal = get_target_expr (compound_literal, complain);
4011 : }
4012 : else
4013 : /* For e.g. int{42} just make sure it's a prvalue. */
4014 724191 : compound_literal = rvalue (compound_literal);
4015 :
4016 : return compound_literal;
4017 : }
4018 :
4019 : /* Return the declaration for the function-name variable indicated by
4020 : ID. */
4021 :
4022 : tree
4023 293246 : finish_fname (tree id)
4024 : {
4025 293246 : tree decl = fname_decl (input_location, C_RID_CODE (id), id);
4026 : /* [expr.prim.lambda.closure]/16 "Unless the compound-statement is that
4027 : of a consteval-block-declaration, a variable __func__ is implicitly
4028 : defined...". We could be in a consteval block in a function, though,
4029 : and then we shouldn't warn. */
4030 293246 : if (current_function_decl
4031 293246 : && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
4032 8 : pedwarn (input_location, 0, "%qD is not defined outside of function scope",
4033 : decl);
4034 293246 : if (processing_template_decl && current_function_decl
4035 215584 : && decl != error_mark_node)
4036 215584 : decl = DECL_NAME (decl);
4037 293246 : return decl;
4038 : }
4039 :
4040 : /* Finish a translation unit. */
4041 :
4042 : void
4043 98673 : finish_translation_unit (void)
4044 : {
4045 : /* In case there were missing closebraces,
4046 : get us back to the global binding level. */
4047 98673 : pop_everything ();
4048 197346 : while (current_namespace != global_namespace)
4049 0 : pop_namespace ();
4050 :
4051 : /* Do file scope __FUNCTION__ et al. */
4052 98673 : finish_fname_decls ();
4053 :
4054 98673 : if (vec_safe_length (scope_chain->omp_declare_target_attribute))
4055 : {
4056 12 : cp_omp_declare_target_attr
4057 12 : a = scope_chain->omp_declare_target_attribute->pop ();
4058 12 : if (!errorcount)
4059 9 : error ("%qs without corresponding %qs",
4060 : a.device_type >= 0 ? "#pragma omp begin declare target"
4061 : : "#pragma omp declare target",
4062 : "#pragma omp end declare target");
4063 24 : vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
4064 : }
4065 98673 : if (vec_safe_length (scope_chain->omp_declare_variant_attribute))
4066 : {
4067 0 : if (!errorcount)
4068 0 : error ("%<omp begin declare variant%> without corresponding "
4069 : "%<omp end declare variant%>");
4070 0 : vec_safe_truncate (scope_chain->omp_declare_variant_attribute, 0);
4071 : }
4072 98673 : if (vec_safe_length (scope_chain->omp_begin_assumes))
4073 : {
4074 3 : if (!errorcount)
4075 3 : error ("%qs without corresponding %qs",
4076 : "#pragma omp begin assumes", "#pragma omp end assumes");
4077 3 : vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
4078 : }
4079 98673 : }
4080 :
4081 : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
4082 : Returns the parameter. */
4083 :
4084 : tree
4085 164061325 : finish_template_type_parm (tree aggr, tree identifier)
4086 : {
4087 164061325 : if (aggr != class_type_node)
4088 : {
4089 0 : permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
4090 0 : aggr = class_type_node;
4091 : }
4092 :
4093 164061325 : return build_tree_list (aggr, identifier);
4094 : }
4095 :
4096 : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
4097 : Returns the parameter. */
4098 :
4099 : tree
4100 418155 : finish_template_template_parm (tree aggr, tree identifier)
4101 : {
4102 418155 : tree decl = build_decl (input_location,
4103 : TYPE_DECL, identifier, NULL_TREE);
4104 :
4105 418155 : tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
4106 418155 : DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
4107 418155 : DECL_TEMPLATE_RESULT (tmpl) = decl;
4108 418155 : DECL_ARTIFICIAL (decl) = 1;
4109 :
4110 : /* Associate the constraints with the underlying declaration,
4111 : not the template. */
4112 418155 : tree constr = current_template_constraints ();
4113 418155 : set_constraints (decl, constr);
4114 :
4115 418155 : end_template_decl ();
4116 :
4117 418155 : gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
4118 :
4119 418155 : check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
4120 : /*is_primary=*/true, /*is_partial=*/false,
4121 : /*is_friend=*/0);
4122 :
4123 418155 : return finish_template_type_parm (aggr, tmpl);
4124 : }
4125 :
4126 : /* ARGUMENT is the default-argument value for a template template
4127 : parameter. If ARGUMENT is invalid, issue error messages and return
4128 : the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
4129 :
4130 : tree
4131 946 : check_template_template_default_arg (tree argument)
4132 : {
4133 946 : if (TREE_CODE (argument) != TEMPLATE_DECL
4134 : && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
4135 : && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
4136 : {
4137 : if (TREE_CODE (argument) == TYPE_DECL)
4138 : {
4139 18 : if (tree t = maybe_get_template_decl_from_type_decl (argument))
4140 18 : if (TREE_CODE (t) == TEMPLATE_DECL)
4141 : return t;
4142 15 : error ("invalid use of type %qT as a default value for a template "
4143 15 : "template-parameter", TREE_TYPE (argument));
4144 : }
4145 : else
4146 0 : error ("invalid default argument for a template template parameter");
4147 15 : return error_mark_node;
4148 : }
4149 :
4150 : return argument;
4151 : }
4152 :
4153 : /* Begin a class definition, as indicated by T. */
4154 :
4155 : tree
4156 31524084 : begin_class_definition (tree t)
4157 : {
4158 31524084 : if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
4159 33 : return error_mark_node;
4160 :
4161 31524189 : if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
4162 : {
4163 9 : error ("definition of %q#T inside template parameter list", t);
4164 9 : return error_mark_node;
4165 : }
4166 :
4167 : /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
4168 : are passed the same as decimal scalar types. */
4169 31524042 : if (TREE_CODE (t) == RECORD_TYPE
4170 30996416 : && !processing_template_decl)
4171 : {
4172 11144761 : tree ns = TYPE_CONTEXT (t);
4173 11144758 : if (ns && TREE_CODE (ns) == NAMESPACE_DECL
4174 9156657 : && DECL_CONTEXT (ns) == std_node
4175 2205615 : && DECL_NAME (ns)
4176 13350356 : && id_equal (DECL_NAME (ns), "decimal"))
4177 : {
4178 150 : const char *n = TYPE_NAME_STRING (t);
4179 150 : if ((strcmp (n, "decimal32") == 0)
4180 101 : || (strcmp (n, "decimal64") == 0)
4181 46 : || (strcmp (n, "decimal128") == 0))
4182 147 : TYPE_TRANSPARENT_AGGR (t) = 1;
4183 : }
4184 : }
4185 :
4186 : /* A non-implicit typename comes from code like:
4187 :
4188 : template <typename T> struct A {
4189 : template <typename U> struct A<T>::B ...
4190 :
4191 : This is erroneous. */
4192 20379281 : else if (TREE_CODE (t) == TYPENAME_TYPE)
4193 : {
4194 0 : error ("invalid definition of qualified type %qT", t);
4195 0 : t = error_mark_node;
4196 : }
4197 :
4198 31524042 : if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
4199 : {
4200 0 : t = make_class_type (RECORD_TYPE);
4201 0 : pushtag (make_anon_name (), t);
4202 : }
4203 :
4204 31524042 : if (TYPE_BEING_DEFINED (t))
4205 : {
4206 0 : t = make_class_type (TREE_CODE (t));
4207 0 : pushtag (TYPE_IDENTIFIER (t), t);
4208 : }
4209 :
4210 31524042 : maybe_process_partial_specialization (t);
4211 31524042 : pushclass (t);
4212 31524042 : TYPE_BEING_DEFINED (t) = 1;
4213 31524042 : class_binding_level->defining_class_p = 1;
4214 :
4215 31524042 : if (flag_pack_struct)
4216 : {
4217 99 : tree v;
4218 99 : TYPE_PACKED (t) = 1;
4219 : /* Even though the type is being defined for the first time
4220 : here, there might have been a forward declaration, so there
4221 : might be cv-qualified variants of T. */
4222 99 : for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
4223 0 : TYPE_PACKED (v) = 1;
4224 : }
4225 : /* Reset the interface data, at the earliest possible
4226 : moment, as it might have been set via a class foo;
4227 : before. */
4228 65399136 : if (! TYPE_UNNAMED_P (t))
4229 : {
4230 30765300 : struct c_fileinfo *finfo = \
4231 30765300 : get_fileinfo (LOCATION_FILE (input_location));
4232 30765300 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
4233 30765300 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X
4234 : (t, finfo->interface_unknown);
4235 : }
4236 31524042 : reset_specialization ();
4237 :
4238 : /* Make a declaration for this class in its own scope. */
4239 31524042 : build_self_reference ();
4240 :
4241 31524042 : return t;
4242 : }
4243 :
4244 : /* Finish the member declaration given by DECL. */
4245 :
4246 : void
4247 426330609 : finish_member_declaration (tree decl)
4248 : {
4249 426330609 : if (decl == error_mark_node || decl == NULL_TREE)
4250 : return;
4251 :
4252 426329560 : if (decl == void_type_node)
4253 : /* The COMPONENT was a friend, not a member, and so there's
4254 : nothing for us to do. */
4255 : return;
4256 :
4257 : /* We should see only one DECL at a time. */
4258 426329560 : gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
4259 :
4260 : /* Don't add decls after definition. */
4261 426329581 : gcc_assert (TYPE_BEING_DEFINED (current_class_type)
4262 : /* We can add lambda types when late parsing default
4263 : arguments. */
4264 : || LAMBDA_TYPE_P (TREE_TYPE (decl)));
4265 :
4266 : /* Set up access control for DECL. */
4267 426329560 : TREE_PRIVATE (decl)
4268 426329560 : = (current_access_specifier == access_private_node);
4269 426329560 : TREE_PROTECTED (decl)
4270 426329560 : = (current_access_specifier == access_protected_node);
4271 426329560 : if (TREE_CODE (decl) == TEMPLATE_DECL)
4272 : {
4273 48663569 : TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
4274 48663569 : TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
4275 : }
4276 :
4277 : /* Mark the DECL as a member of the current class, unless it's
4278 : a member of an enumeration. */
4279 426329560 : if (TREE_CODE (decl) != CONST_DECL)
4280 423925877 : DECL_CONTEXT (decl) = current_class_type;
4281 :
4282 : /* Remember the single FIELD_DECL an anonymous aggregate type is used for. */
4283 426329560 : if (TREE_CODE (decl) == FIELD_DECL
4284 426329560 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
4285 : {
4286 286816 : gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
4287 286816 : SET_ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl)), decl);
4288 : }
4289 :
4290 426329560 : if (TREE_CODE (decl) == USING_DECL)
4291 : /* Avoid debug info for class-scope USING_DECLS for now, we'll
4292 : call cp_emit_debug_info_for_using later. */
4293 3475992 : DECL_IGNORED_P (decl) = 1;
4294 :
4295 : /* Check for bare parameter packs in the non-static data member
4296 : declaration. */
4297 426329560 : if (TREE_CODE (decl) == FIELD_DECL)
4298 : {
4299 31199130 : if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
4300 9 : TREE_TYPE (decl) = error_mark_node;
4301 31199130 : if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
4302 0 : DECL_ATTRIBUTES (decl) = NULL_TREE;
4303 : }
4304 :
4305 : /* [dcl.link]
4306 :
4307 : A C language linkage is ignored for the names of class members
4308 : and the member function type of class member functions. */
4309 426329560 : if (DECL_LANG_SPECIFIC (decl))
4310 389174609 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
4311 :
4312 426329560 : bool add = false;
4313 :
4314 : /* Functions and non-functions are added differently. */
4315 426329560 : if (DECL_DECLARES_FUNCTION_P (decl))
4316 220473398 : add = add_method (current_class_type, decl, false);
4317 : /* Enter the DECL into the scope of the class, if the class
4318 : isn't a closure (whose fields are supposed to be unnamed). */
4319 205856162 : else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
4320 202164598 : || maybe_push_used_methods (decl)
4321 406099736 : || pushdecl_class_level (decl))
4322 : add = true;
4323 :
4324 220473398 : if (add)
4325 : {
4326 : /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
4327 : go at the beginning. The reason is that
4328 : legacy_nonfn_member_lookup searches the list in order, and we
4329 : want a field name to override a type name so that the "struct
4330 : stat hack" will work. In particular:
4331 :
4332 : struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
4333 :
4334 : is valid. */
4335 :
4336 426316325 : if (TREE_CODE (decl) == TYPE_DECL)
4337 146082032 : TYPE_FIELDS (current_class_type)
4338 292164064 : = chainon (TYPE_FIELDS (current_class_type), decl);
4339 : else
4340 : {
4341 280234293 : DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
4342 280234293 : TYPE_FIELDS (current_class_type) = decl;
4343 : }
4344 :
4345 426316325 : maybe_add_class_template_decl_list (current_class_type, decl,
4346 : /*friend_p=*/0);
4347 : }
4348 : }
4349 :
4350 : /* Finish processing a complete template declaration. The PARMS are
4351 : the template parameters. */
4352 :
4353 : void
4354 93980335 : finish_template_decl (tree parms)
4355 : {
4356 93980335 : if (parms)
4357 93980326 : end_template_decl ();
4358 : else
4359 9 : end_specialization ();
4360 93980335 : }
4361 :
4362 : // Returns the template type of the class scope being entered. If we're
4363 : // entering a constrained class scope. TYPE is the class template
4364 : // scope being entered and we may need to match the intended type with
4365 : // a constrained specialization. For example:
4366 : //
4367 : // template<Object T>
4368 : // struct S { void f(); }; #1
4369 : //
4370 : // template<Object T>
4371 : // void S<T>::f() { } #2
4372 : //
4373 : // We check, in #2, that S<T> refers precisely to the type declared by
4374 : // #1 (i.e., that the constraints match). Note that the following should
4375 : // be an error since there is no specialization of S<T> that is
4376 : // unconstrained, but this is not diagnosed here.
4377 : //
4378 : // template<typename T>
4379 : // void S<T>::f() { }
4380 : //
4381 : // We cannot diagnose this problem here since this function also matches
4382 : // qualified template names that are not part of a definition. For example:
4383 : //
4384 : // template<Integral T, Floating_point U>
4385 : // typename pair<T, U>::first_type void f(T, U);
4386 : //
4387 : // Here, it is unlikely that there is a partial specialization of
4388 : // pair constrained for Integral and Floating_point arguments.
4389 : //
4390 : // The general rule is: if a constrained specialization with matching
4391 : // constraints is found return that type. Also note that if TYPE is not a
4392 : // class-type (e.g. a typename type), then no fixup is needed.
4393 :
4394 : static tree
4395 18449541 : fixup_template_type (tree type)
4396 : {
4397 : // Find the template parameter list at the a depth appropriate to
4398 : // the scope we're trying to enter.
4399 18449541 : tree parms = current_template_parms;
4400 18449541 : int depth = template_class_depth (type);
4401 41093872 : for (int n = current_template_depth; n > depth && parms; --n)
4402 4194790 : parms = TREE_CHAIN (parms);
4403 18449541 : if (!parms)
4404 : return type;
4405 18449531 : tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
4406 18449531 : tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
4407 :
4408 : // Search for a specialization whose type and constraints match.
4409 18449531 : tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
4410 18449531 : tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
4411 35757710 : while (specs)
4412 : {
4413 17752065 : tree spec_constr = get_constraints (TREE_VALUE (specs));
4414 :
4415 : // If the type and constraints match a specialization, then we
4416 : // are entering that type.
4417 17752065 : if (same_type_p (type, TREE_TYPE (specs))
4418 17752065 : && equivalent_constraints (cur_constr, spec_constr))
4419 443886 : return TREE_TYPE (specs);
4420 17308179 : specs = TREE_CHAIN (specs);
4421 : }
4422 :
4423 : // If no specialization matches, then must return the type
4424 : // previously found.
4425 : return type;
4426 : }
4427 :
4428 : /* Finish processing a template-id (which names a type) of the form
4429 : NAME < ARGS >. Return the TYPE_DECL for the type named by the
4430 : template-id. If ENTERING_SCOPE is nonzero we are about to enter
4431 : the scope of template-id indicated. */
4432 :
4433 : tree
4434 191081978 : finish_template_type (tree name, tree args, int entering_scope)
4435 : {
4436 191081978 : tree type;
4437 :
4438 191081978 : type = lookup_template_class (name, args,
4439 : NULL_TREE, NULL_TREE,
4440 : tf_warning_or_error | tf_user);
4441 191081975 : if (entering_scope)
4442 19502643 : type = adjust_type_for_entering_scope (type);
4443 :
4444 : /* If we might be entering the scope of a partial specialization,
4445 : find the one with the right constraints. */
4446 191081975 : if (flag_concepts
4447 188323519 : && entering_scope
4448 19129614 : && CLASS_TYPE_P (type)
4449 18958384 : && CLASSTYPE_TEMPLATE_INFO (type)
4450 18958375 : && dependent_type_p (type)
4451 209531516 : && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
4452 18449541 : type = fixup_template_type (type);
4453 :
4454 191081975 : if (type == error_mark_node)
4455 : return type;
4456 191079685 : else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
4457 150032782 : return TYPE_STUB_DECL (type);
4458 : else
4459 41046903 : return TYPE_NAME (type);
4460 : }
4461 :
4462 : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER
4463 : and ANNOTATIONS.
4464 : Return a TREE_LIST containing the ACCESS_SPECIFIER (or if there are
4465 : ANNOTATIONS, TREE_LIST containing the ACCESS_SPECIFIER and ANNOTATIONS)
4466 : and the BASE_CLASS, or NULL_TREE if an error occurred. The
4467 : ACCESS_SPECIFIER is one of
4468 : access_{default,public,protected,private}_node. For a virtual base
4469 : we set TREE_TYPE. */
4470 :
4471 : tree
4472 11636535 : finish_base_specifier (tree base, tree access, bool virtual_p,
4473 : tree annotations)
4474 : {
4475 11636535 : tree result;
4476 :
4477 11636535 : if (base == error_mark_node)
4478 : {
4479 0 : error ("invalid base-class specification");
4480 0 : result = NULL_TREE;
4481 : }
4482 11636535 : else if (! MAYBE_CLASS_TYPE_P (base))
4483 : {
4484 3 : error ("%qT is not a class type", base);
4485 3 : result = NULL_TREE;
4486 : }
4487 : else
4488 : {
4489 11636532 : if (cp_type_quals (base) != 0)
4490 : {
4491 : /* DR 484: Can a base-specifier name a cv-qualified
4492 : class type? */
4493 12 : base = TYPE_MAIN_VARIANT (base);
4494 : }
4495 11636532 : if (annotations)
4496 18 : access = build_tree_list (access, nreverse (annotations));
4497 11636532 : result = build_tree_list (access, base);
4498 11636532 : if (virtual_p)
4499 26620 : TREE_TYPE (result) = integer_type_node;
4500 : }
4501 :
4502 11636535 : return result;
4503 : }
4504 :
4505 : /* If FNS is a member function, a set of member functions, or a
4506 : template-id referring to one or more member functions, return a
4507 : BASELINK for FNS, incorporating the current access context.
4508 : Otherwise, return FNS unchanged. */
4509 :
4510 : tree
4511 186559635 : baselink_for_fns (tree fns)
4512 : {
4513 186559635 : tree scope;
4514 186559635 : tree cl;
4515 :
4516 186559635 : if (BASELINK_P (fns)
4517 186559635 : || error_operand_p (fns))
4518 : return fns;
4519 :
4520 172440157 : scope = ovl_scope (fns);
4521 172440157 : if (!CLASS_TYPE_P (scope))
4522 : return fns;
4523 :
4524 9034428 : cl = currently_open_derived_class (scope);
4525 9034428 : if (!cl)
4526 6602090 : cl = scope;
4527 9034428 : tree access_path = TYPE_BINFO (cl);
4528 9034428 : tree conv_path = (cl == scope ? access_path
4529 725460 : : lookup_base (cl, scope, ba_any, NULL, tf_none));
4530 9034428 : return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
4531 : }
4532 :
4533 : /* Returns true iff we are currently parsing a lambda-declarator. */
4534 :
4535 : bool
4536 2003195918 : parsing_lambda_declarator ()
4537 : {
4538 2003195918 : cp_binding_level *b = current_binding_level;
4539 2005216365 : while (b->kind == sk_template_parms || b->kind == sk_function_parms)
4540 2020447 : b = b->level_chain;
4541 2003195918 : return b->kind == sk_lambda;
4542 : }
4543 :
4544 : /* Returns true iff DECL is a variable from a function outside
4545 : the current one. */
4546 :
4547 : static bool
4548 2675395692 : outer_var_p (tree decl)
4549 : {
4550 : /* These should have been stripped or otherwise handled by the caller. */
4551 2675395692 : gcc_checking_assert (!REFERENCE_REF_P (decl));
4552 :
4553 1762175543 : return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
4554 2456917262 : && DECL_FUNCTION_SCOPE_P (decl)
4555 : /* Don't get confused by temporaries. */
4556 2035408992 : && DECL_NAME (decl)
4557 4686775407 : && (DECL_CONTEXT (decl) != current_function_decl
4558 2001088221 : || parsing_nsdmi ()
4559 : /* Also consider captures as outer vars if we are in
4560 : decltype in a lambda declarator as in:
4561 : auto l = [j=0]() -> decltype((j)) { ... }
4562 : for the sake of finish_decltype_type.
4563 :
4564 : (Similar issue also affects non-lambdas, but vexing parse
4565 : makes it more difficult to handle than lambdas.) */
4566 2001086874 : || parsing_lambda_declarator ()));
4567 : }
4568 :
4569 : /* As above, but also checks that DECL is automatic. */
4570 :
4571 : bool
4572 2675395692 : outer_automatic_var_p (tree decl)
4573 : {
4574 2675395692 : return (outer_var_p (decl)
4575 2675395692 : && !TREE_STATIC (decl));
4576 : }
4577 :
4578 : /* Note whether capture proxy D is only used in a contract condition. */
4579 :
4580 : static void
4581 160069 : set_contract_capture_flag (tree d, bool val)
4582 : {
4583 160069 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (d));
4584 160069 : tree proxy = DECL_VALUE_EXPR (d);
4585 160069 : gcc_checking_assert (TREE_CODE (proxy) == COMPONENT_REF
4586 : && TREE_CODE (TREE_OPERAND (proxy, 1)) == FIELD_DECL);
4587 160069 : DECL_CONTRACT_CAPTURE_P (TREE_OPERAND (proxy, 1)) = val;
4588 160069 : }
4589 :
4590 : /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
4591 : rewrite it for lambda capture.
4592 :
4593 : If ODR_USE is true, we're being called from mark_use, and we complain about
4594 : use of constant variables. If ODR_USE is false, we're being called for the
4595 : id-expression, and we do lambda capture. */
4596 :
4597 : tree
4598 5279173 : process_outer_var_ref (tree decl, tsubst_flags_t complain,
4599 : bool odr_use/*=false*/)
4600 : {
4601 5279173 : if (cp_unevaluated_operand)
4602 : {
4603 3169892 : tree type = TREE_TYPE (decl);
4604 3169892 : if (!dependent_type_p (type)
4605 3169892 : && variably_modified_type_p (type, NULL_TREE))
4606 : /* VLAs are used even in unevaluated context. */;
4607 : else
4608 : /* It's not a use (3.2) if we're in an unevaluated context. */
4609 3169886 : return decl;
4610 : }
4611 2109287 : if (decl == error_mark_node)
4612 : return decl;
4613 :
4614 2109281 : tree context = DECL_CONTEXT (decl);
4615 2109281 : tree containing_function = current_function_decl;
4616 2109281 : tree lambda_stack = NULL_TREE;
4617 2109281 : tree lambda_expr = NULL_TREE;
4618 2109281 : tree initializer = convert_from_reference (decl);
4619 2109281 : tree var = strip_normal_capture_proxy (decl);
4620 :
4621 : /* Mark it as used now even if the use is ill-formed. */
4622 2109281 : if (!mark_used (decl, complain))
4623 3 : return error_mark_node;
4624 :
4625 2109278 : if (parsing_nsdmi () || parsing_lambda_declarator ())
4626 : containing_function = NULL_TREE;
4627 :
4628 4217648 : if (containing_function && LAMBDA_FUNCTION_P (containing_function))
4629 : {
4630 : /* Check whether we've already built a proxy. */
4631 2108709 : tree d = retrieve_local_specialization (var);
4632 :
4633 2108709 : if (d && d != decl && is_capture_proxy (d))
4634 : {
4635 1080045 : if (flag_contracts && !processing_contract_condition)
4636 : /* We might have created a capture for a contract_assert ref. to
4637 : some var, if that is now captured 'normally' then this is OK.
4638 : Otherwise we leave the capture marked as incorrect. */
4639 160063 : set_contract_capture_flag (d, false);
4640 1080045 : if (DECL_CONTEXT (d) == containing_function)
4641 : /* We already have an inner proxy. */
4642 : return d;
4643 : else
4644 : /* We need to capture an outer proxy. */
4645 3877 : return process_outer_var_ref (d, complain, odr_use);
4646 : }
4647 : }
4648 :
4649 : /* If we are in a lambda function, we can move out until we hit
4650 : 1. the context,
4651 : 2. a non-lambda function, or
4652 : 3. a non-default capturing lambda function. */
4653 2062222 : while (context != containing_function
4654 : /* containing_function can be null with invalid generic lambdas. */
4655 2062222 : && containing_function
4656 3096452 : && LAMBDA_FUNCTION_P (containing_function))
4657 : {
4658 1034230 : tree closure = DECL_CONTEXT (containing_function);
4659 1034230 : lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
4660 :
4661 1034230 : if (TYPE_CLASS_SCOPE_P (closure))
4662 : /* A lambda in an NSDMI (c++/64496). */
4663 : break;
4664 :
4665 1034227 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4666 : break;
4667 :
4668 1032989 : lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
4669 :
4670 1032989 : containing_function = decl_function_context (containing_function);
4671 : }
4672 :
4673 : /* In a lambda within a template, wait until instantiation time to implicitly
4674 : capture a parameter pack. We want to wait because we don't know if we're
4675 : capturing the whole pack or a single element, and it's OK to wait because
4676 : find_parameter_packs_r walks into the lambda body. */
4677 1029233 : if (context == containing_function
4678 1029233 : && DECL_PACK_P (decl))
4679 : return decl;
4680 :
4681 985065 : if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
4682 : {
4683 6 : if (complain & tf_error)
4684 6 : error ("cannot capture member %qD of anonymous union", decl);
4685 6 : return error_mark_node;
4686 : }
4687 : /* Do lambda capture when processing the id-expression, not when
4688 : odr-using a variable, but uses in a contract must not cause a capture. */
4689 985059 : if (!odr_use && context == containing_function)
4690 : {
4691 983249 : decl = add_default_capture (lambda_stack,
4692 983249 : /*id=*/DECL_NAME (decl), initializer);
4693 983249 : if (flag_contracts && processing_contract_condition)
4694 6 : set_contract_capture_flag (decl, true);
4695 : }
4696 : /* Only an odr-use of an outer automatic variable causes an
4697 : error, and a constant variable can decay to a prvalue
4698 : constant without odr-use. So don't complain yet. */
4699 1810 : else if (!odr_use && decl_constant_var_p (var))
4700 : return var;
4701 : /* Don't complain when DECL is dependent, because it can turn out to
4702 : be constant (and therefore needing no capture) when instantiating. */
4703 452 : else if (VAR_P (var) && instantiation_dependent_expression_p (var))
4704 : return var;
4705 434 : else if (lambda_expr)
4706 : {
4707 60 : if (complain & tf_error)
4708 : {
4709 56 : auto_diagnostic_group d;
4710 56 : error ("%qD is not captured", decl);
4711 56 : tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
4712 56 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4713 53 : inform (location_of (closure),
4714 : "the lambda has no capture-default");
4715 3 : else if (TYPE_CLASS_SCOPE_P (closure))
4716 3 : inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
4717 : "capture variables from the enclosing context",
4718 3 : TYPE_CONTEXT (closure));
4719 56 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4720 56 : }
4721 60 : return error_mark_node;
4722 : }
4723 374 : else if (processing_contract_condition && TREE_CODE (decl) == PARM_DECL)
4724 : /* Use of a parameter in a contract condition is fine. */
4725 : return decl;
4726 : else
4727 : {
4728 53 : if (complain & tf_error)
4729 : {
4730 39 : auto_diagnostic_group d;
4731 57 : error (VAR_P (decl)
4732 : ? G_("use of local variable with automatic storage from "
4733 : "containing function")
4734 : : G_("use of parameter from containing function"));
4735 39 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4736 39 : }
4737 53 : return error_mark_node;
4738 : }
4739 : return decl;
4740 : }
4741 :
4742 : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4743 : id-expression. (See cp_parser_id_expression for details.) SCOPE,
4744 : if non-NULL, is the type or namespace used to explicitly qualify
4745 : ID_EXPRESSION. DECL is the entity to which that name has been
4746 : resolved.
4747 :
4748 : *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4749 : constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4750 : be set to true if this expression isn't permitted in a
4751 : constant-expression, but it is otherwise not set by this function.
4752 : *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4753 : constant-expression, but a non-constant expression is also
4754 : permissible.
4755 :
4756 : DONE is true if this expression is a complete postfix-expression;
4757 : it is false if this expression is followed by '->', '[', '(', etc.
4758 : ADDRESS_P is true iff this expression is the operand of '&'.
4759 : TEMPLATE_P is true iff the qualified-id was of the form
4760 : "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4761 : appears as a template argument.
4762 :
4763 : If an error occurs, and it is the kind of error that might cause
4764 : the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4765 : is the caller's responsibility to issue the message. *ERROR_MSG
4766 : will be a string with static storage duration, so the caller need
4767 : not "free" it.
4768 :
4769 : Return an expression for the entity, after issuing appropriate
4770 : diagnostics. This function is also responsible for transforming a
4771 : reference to a non-static member into a COMPONENT_REF that makes
4772 : the use of "this" explicit.
4773 :
4774 : Upon return, *IDK will be filled in appropriately. */
4775 : static cp_expr
4776 795795514 : finish_id_expression_1 (tree id_expression,
4777 : tree decl,
4778 : tree scope,
4779 : cp_id_kind *idk,
4780 : bool integral_constant_expression_p,
4781 : bool allow_non_integral_constant_expression_p,
4782 : bool *non_integral_constant_expression_p,
4783 : bool template_p,
4784 : bool done,
4785 : bool address_p,
4786 : bool template_arg_p,
4787 : const char **error_msg,
4788 : location_t location)
4789 : {
4790 795795514 : decl = strip_using_decl (decl);
4791 :
4792 : /* Initialize the output parameters. */
4793 795795514 : *idk = CP_ID_KIND_NONE;
4794 795795514 : *error_msg = NULL;
4795 :
4796 795795514 : if (id_expression == error_mark_node)
4797 12 : return error_mark_node;
4798 : /* If we have a template-id, then no further lookup is
4799 : required. If the template-id was for a template-class, we
4800 : will sometimes have a TYPE_DECL at this point. */
4801 795795502 : else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4802 740323319 : || TREE_CODE (decl) == TYPE_DECL)
4803 : ;
4804 : /* Look up the name. */
4805 : else
4806 : {
4807 740322398 : if (decl == error_mark_node)
4808 : {
4809 : /* Name lookup failed. */
4810 132261 : if (scope
4811 374 : && !dependent_namespace_p (scope)
4812 132635 : && (!TYPE_P (scope)
4813 119 : || (!dependentish_scope_p (scope)
4814 115 : && !(identifier_p (id_expression)
4815 100 : && IDENTIFIER_CONV_OP_P (id_expression)
4816 3 : && dependent_type_p (TREE_TYPE (id_expression))))))
4817 : {
4818 : /* If the qualifying type is non-dependent (and the name
4819 : does not name a conversion operator to a dependent
4820 : type), issue an error. */
4821 364 : qualified_name_lookup_error (scope, id_expression, decl, location);
4822 364 : return error_mark_node;
4823 : }
4824 131897 : else if (!scope)
4825 : {
4826 : /* It may be resolved via Koenig lookup. */
4827 131887 : *idk = CP_ID_KIND_UNQUALIFIED;
4828 131887 : return id_expression;
4829 : }
4830 : else
4831 : decl = id_expression;
4832 : }
4833 :
4834 : /* Remember that the name was used in the definition of
4835 : the current class so that we can check later to see if
4836 : the meaning would have been different after the class
4837 : was entirely defined. */
4838 740190137 : if (!scope && decl != error_mark_node && identifier_p (id_expression))
4839 661818402 : maybe_note_name_used_in_class (id_expression, decl);
4840 :
4841 : /* A use in unevaluated operand might not be instantiated appropriately
4842 : if tsubst_copy builds a dummy parm, or if we never instantiate a
4843 : generic lambda, so mark it now. */
4844 740190147 : if (processing_template_decl
4845 740190147 : && (cp_unevaluated_operand
4846 640070507 : || generic_lambda_fn_p (current_function_decl)))
4847 20570558 : mark_type_use (decl);
4848 :
4849 : /* Disallow uses of local variables from containing functions, except
4850 : within lambda-expressions. */
4851 740190147 : if (outer_automatic_var_p (decl))
4852 : {
4853 3753471 : decl = process_outer_var_ref (decl, tf_warning_or_error);
4854 3753471 : if (decl == error_mark_node)
4855 92 : return error_mark_node;
4856 : }
4857 :
4858 : /* Also disallow uses of function parameters outside the function
4859 : body, except inside an unevaluated context (i.e. decltype). */
4860 740190055 : if (TREE_CODE (decl) == PARM_DECL
4861 309208688 : && DECL_CONTEXT (decl) == NULL_TREE
4862 8401603 : && !CONSTRAINT_VAR_P (decl)
4863 4508807 : && !cp_unevaluated_operand
4864 563 : && !processing_contract_condition
4865 740190111 : && !processing_omp_trait_property_expr)
4866 : {
4867 38 : *error_msg = G_("use of parameter outside function body");
4868 38 : return error_mark_node;
4869 : }
4870 : }
4871 :
4872 : /* If we didn't find anything, or what we found was a type,
4873 : then this wasn't really an id-expression. */
4874 795663121 : if (TREE_CODE (decl) == TEMPLATE_DECL
4875 795663121 : && !DECL_FUNCTION_TEMPLATE_P (decl))
4876 : {
4877 51 : *error_msg = G_("missing template arguments");
4878 51 : return error_mark_node;
4879 : }
4880 795663070 : else if (TREE_CODE (decl) == TYPE_DECL
4881 795662149 : || TREE_CODE (decl) == NAMESPACE_DECL)
4882 : {
4883 936 : *error_msg = G_("expected primary-expression");
4884 936 : return error_mark_node;
4885 : }
4886 :
4887 : /* If the name resolved to a template parameter, there is no
4888 : need to look it up again later. */
4889 33669028 : if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
4890 809733500 : || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4891 : {
4892 19597662 : tree r;
4893 :
4894 19597662 : *idk = CP_ID_KIND_NONE;
4895 19597662 : if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4896 0 : decl = TEMPLATE_PARM_DECL (decl);
4897 19597662 : r = DECL_INITIAL (decl);
4898 19597662 : if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
4899 : {
4900 : /* If the entity is a template parameter object for a template
4901 : parameter of type T, the type of the expression is const T. */
4902 2966 : tree ctype = TREE_TYPE (r);
4903 2966 : ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
4904 : | TYPE_QUAL_CONST));
4905 2966 : r = build1 (VIEW_CONVERT_EXPR, ctype, r);
4906 : }
4907 19597662 : r = convert_from_reference (r);
4908 19597662 : if (integral_constant_expression_p
4909 3375229 : && !dependent_type_p (TREE_TYPE (decl))
4910 22470937 : && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
4911 : {
4912 1017 : if (!allow_non_integral_constant_expression_p)
4913 6 : error ("template parameter %qD of type %qT is not allowed in "
4914 : "an integral constant expression because it is not of "
4915 6 : "integral or enumeration type", decl, TREE_TYPE (decl));
4916 1017 : *non_integral_constant_expression_p = true;
4917 : }
4918 :
4919 19597662 : if (flag_contracts && processing_contract_condition)
4920 15 : r = constify_contract_access (r);
4921 :
4922 19597662 : return r;
4923 : }
4924 776064472 : else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
4925 : {
4926 9 : gcc_checking_assert (scope);
4927 9 : *idk = CP_ID_KIND_QUALIFIED;
4928 9 : cp_warn_deprecated_use_scopes (scope);
4929 9 : decl = finish_qualified_id_expr (scope, decl, done, address_p,
4930 : template_p, template_arg_p,
4931 : tf_warning_or_error);
4932 : }
4933 : else
4934 : {
4935 776064463 : if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4936 55472183 : && variable_template_p (TREE_OPERAND (decl, 0))
4937 788655605 : && !concept_check_p (decl))
4938 : /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
4939 : considered type-dependent) now, so that the dependence test that
4940 : follows gives us the right answer: if it represents a non-dependent
4941 : variable template-id then finish_template_variable will yield the
4942 : corresponding non-dependent VAR_DECL. */
4943 12591142 : decl = finish_template_variable (decl);
4944 :
4945 776064463 : bool dependent_p = type_dependent_expression_p (decl);
4946 :
4947 : /* If the declaration was explicitly qualified indicate
4948 : that. The semantics of `A::f(3)' are different than
4949 : `f(3)' if `f' is virtual. */
4950 1552128926 : *idk = (scope
4951 776064463 : ? CP_ID_KIND_QUALIFIED
4952 675089498 : : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4953 675089498 : ? CP_ID_KIND_TEMPLATE_ID
4954 : : (dependent_p
4955 642512555 : ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
4956 : : CP_ID_KIND_UNQUALIFIED)));
4957 :
4958 776064463 : if (dependent_p
4959 776064463 : && !scope
4960 444582744 : && DECL_P (decl)
4961 1189143951 : && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
4962 : /* Dependent type attributes on the decl mean that the TREE_TYPE is
4963 : wrong, so just return the identifier. */
4964 39 : return id_expression;
4965 :
4966 776064424 : if (DECL_CLASS_TEMPLATE_P (decl))
4967 : {
4968 0 : error ("use of class template %qT as expression", decl);
4969 0 : return error_mark_node;
4970 : }
4971 :
4972 776064424 : if (TREE_CODE (decl) == TREE_LIST)
4973 : {
4974 : /* Ambiguous reference to base members. */
4975 0 : auto_diagnostic_group d;
4976 0 : error ("request for member %qD is ambiguous in "
4977 : "multiple inheritance lattice", id_expression);
4978 0 : print_candidates (input_location, decl);
4979 0 : return error_mark_node;
4980 0 : }
4981 :
4982 : /* Mark variable-like entities as used. Functions are similarly
4983 : marked either below or after overload resolution. */
4984 776064424 : if ((VAR_P (decl)
4985 563181638 : || TREE_CODE (decl) == PARM_DECL
4986 253972994 : || TREE_CODE (decl) == CONST_DECL
4987 239901628 : || TREE_CODE (decl) == RESULT_DECL)
4988 1099344434 : && !mark_used (decl))
4989 12 : return error_mark_node;
4990 :
4991 : /* Only certain kinds of names are allowed in constant
4992 : expression. Template parameters have already
4993 : been handled above. */
4994 776064409 : if (! error_operand_p (decl)
4995 776064083 : && !dependent_p
4996 776064083 : && integral_constant_expression_p
4997 78013781 : && !decl_constant_var_p (decl)
4998 63578464 : && TREE_CODE (decl) != CONST_DECL
4999 54928598 : && !builtin_valid_in_constant_expr_p (decl)
5000 830943058 : && !concept_check_p (decl))
5001 : {
5002 54315956 : if (!allow_non_integral_constant_expression_p)
5003 : {
5004 30 : error ("%qD cannot appear in a constant-expression", decl);
5005 30 : return error_mark_node;
5006 : }
5007 54315926 : *non_integral_constant_expression_p = true;
5008 : }
5009 :
5010 776064379 : if (tree wrap = maybe_get_tls_wrapper_call (decl))
5011 : /* Replace an evaluated use of the thread_local variable with
5012 : a call to its wrapper. */
5013 : decl = wrap;
5014 776063867 : else if (concept_check_p (decl))
5015 : {
5016 : /* Nothing more to do. All of the analysis for concept checks
5017 : is done by build_conept_id, called from the parser. */
5018 : }
5019 759009841 : else if (scope)
5020 : {
5021 99020163 : if (TREE_CODE (decl) == SCOPE_REF)
5022 : {
5023 90548 : gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
5024 90548 : decl = TREE_OPERAND (decl, 1);
5025 : }
5026 :
5027 99020163 : decl = (adjust_result_of_qualified_name_lookup
5028 99020163 : (decl, scope, current_nonlambda_class_type()));
5029 :
5030 99020163 : cp_warn_deprecated_use_scopes (scope);
5031 :
5032 99020163 : if (TYPE_P (scope))
5033 14075068 : decl = finish_qualified_id_expr (scope,
5034 : decl,
5035 : done,
5036 : address_p,
5037 : template_p,
5038 : template_arg_p,
5039 : tf_warning_or_error);
5040 : else
5041 84945095 : decl = convert_from_reference (decl);
5042 : }
5043 659989678 : else if (TREE_CODE (decl) == FIELD_DECL)
5044 : {
5045 68684978 : if (flag_contracts && processing_contract_condition
5046 37 : && contract_class_ptr == current_class_ptr)
5047 : {
5048 6 : error ("%qD 'this' required when accessing a member within a "
5049 : "constructor precondition or destructor postcondition "
5050 : "contract check", decl);
5051 6 : return error_mark_node;
5052 : }
5053 : /* Since SCOPE is NULL here, this is an unqualified name.
5054 : Access checking has been performed during name lookup
5055 : already. Turn off checking to avoid duplicate errors. */
5056 68684972 : push_deferring_access_checks (dk_no_check);
5057 68684972 : decl = finish_non_static_data_member (decl, NULL_TREE,
5058 : /*qualifying_scope=*/NULL_TREE);
5059 68684972 : pop_deferring_access_checks ();
5060 : }
5061 591304700 : else if (is_overloaded_fn (decl))
5062 : {
5063 : /* We only need to look at the first function,
5064 : because all the fns share the attribute we're
5065 : concerned with (all member fns or all non-members). */
5066 63461420 : tree first_fn = get_first_fn (decl);
5067 63461420 : first_fn = STRIP_TEMPLATE (first_fn);
5068 :
5069 63461420 : if (!template_arg_p
5070 63461420 : && (TREE_CODE (first_fn) == USING_DECL
5071 63459538 : || (TREE_CODE (first_fn) == FUNCTION_DECL
5072 63459538 : && DECL_FUNCTION_MEMBER_P (first_fn)
5073 38743063 : && !shared_member_p (decl))))
5074 : {
5075 : /* A set of member functions. */
5076 29830827 : if (flag_contracts && processing_contract_condition
5077 24 : && contract_class_ptr == current_class_ptr)
5078 : {
5079 3 : error ("%qD 'this' required when accessing a member within a "
5080 : "constructor precondition or destructor postcondition "
5081 : "contract check", decl);
5082 3 : return error_mark_node;
5083 : }
5084 29830824 : decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
5085 29830824 : return finish_class_member_access_expr (decl, id_expression,
5086 : /*template_p=*/false,
5087 29830824 : tf_warning_or_error);
5088 : }
5089 :
5090 33630593 : decl = baselink_for_fns (decl);
5091 : }
5092 : else
5093 : {
5094 516202712 : if (DECL_P (decl) && DECL_NONLOCAL (decl)
5095 529368251 : && DECL_CLASS_SCOPE_P (decl))
5096 : {
5097 1524971 : tree context = context_for_name_lookup (decl);
5098 1524971 : if (context != current_class_type)
5099 : {
5100 797422 : tree path = currently_open_derived_class (context);
5101 797422 : if (!path)
5102 : /* PATH can be null for using an enum of an unrelated
5103 : class; we checked its access in lookup_using_decl.
5104 :
5105 : ??? Should this case make a clone instead, like
5106 : handle_using_decl? */
5107 43 : gcc_assert (TREE_CODE (decl) == CONST_DECL
5108 : /* This is for:
5109 : constexpr auto r = ^^S::i;
5110 : auto a = [:r:]; */
5111 : || flag_reflection);
5112 : else
5113 797379 : perform_or_defer_access_check (TYPE_BINFO (path),
5114 : decl, decl,
5115 : tf_warning_or_error);
5116 : }
5117 : }
5118 :
5119 527843280 : decl = convert_from_reference (decl);
5120 : }
5121 : }
5122 :
5123 746233555 : check_param_in_postcondition (decl, location);
5124 746233555 : if (flag_contracts && processing_contract_condition)
5125 2033 : decl = constify_contract_access (decl);
5126 :
5127 746233555 : return cp_expr (decl, location);
5128 : }
5129 :
5130 : /* As per finish_id_expression_1, but adding a wrapper node
5131 : around the result if needed to express LOCATION. */
5132 :
5133 : cp_expr
5134 795795514 : finish_id_expression (tree id_expression,
5135 : tree decl,
5136 : tree scope,
5137 : cp_id_kind *idk,
5138 : bool integral_constant_expression_p,
5139 : bool allow_non_integral_constant_expression_p,
5140 : bool *non_integral_constant_expression_p,
5141 : bool template_p,
5142 : bool done,
5143 : bool address_p,
5144 : bool template_arg_p,
5145 : const char **error_msg,
5146 : location_t location)
5147 : {
5148 795795514 : cp_expr result
5149 795795514 : = finish_id_expression_1 (id_expression, decl, scope, idk,
5150 : integral_constant_expression_p,
5151 : allow_non_integral_constant_expression_p,
5152 : non_integral_constant_expression_p,
5153 : template_p, done, address_p, template_arg_p,
5154 : error_msg, location);
5155 795795511 : return result.maybe_add_location_wrapper ();
5156 : }
5157 :
5158 : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
5159 : use as a type-specifier. */
5160 :
5161 : tree
5162 21967086 : finish_typeof (tree expr)
5163 : {
5164 21967086 : tree type;
5165 :
5166 21967086 : if (type_dependent_expression_p (expr))
5167 : {
5168 21874182 : type = cxx_make_type (TYPEOF_TYPE);
5169 21874182 : TYPEOF_TYPE_EXPR (type) = expr;
5170 21874182 : SET_TYPE_STRUCTURAL_EQUALITY (type);
5171 :
5172 21874182 : return type;
5173 : }
5174 :
5175 92904 : expr = mark_type_use (expr);
5176 :
5177 92904 : type = unlowered_expr_type (expr);
5178 :
5179 92904 : if (!type || type == unknown_type_node)
5180 : {
5181 3 : error ("type of %qE is unknown", expr);
5182 3 : return error_mark_node;
5183 : }
5184 :
5185 : return type;
5186 : }
5187 :
5188 : /* Implement the __underlying_type keyword: Return the underlying
5189 : type of TYPE, suitable for use as a type-specifier. */
5190 :
5191 : tree
5192 48663 : finish_underlying_type (tree type)
5193 : {
5194 48663 : if (!complete_type_or_else (type, NULL_TREE))
5195 3 : return error_mark_node;
5196 :
5197 48660 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5198 : {
5199 24 : error ("%qT is not an enumeration type", type);
5200 24 : return error_mark_node;
5201 : }
5202 :
5203 48636 : tree underlying_type = ENUM_UNDERLYING_TYPE (type);
5204 :
5205 : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5206 : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5207 : See finish_enum_value_list for details. */
5208 48636 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5209 56 : underlying_type
5210 56 : = c_common_type_for_mode (TYPE_MODE (underlying_type),
5211 56 : TYPE_UNSIGNED (underlying_type));
5212 :
5213 : return underlying_type;
5214 : }
5215 :
5216 : /* Implement the __type_pack_element keyword: Return the type
5217 : at index IDX within TYPES. */
5218 :
5219 : static tree
5220 135212 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
5221 : {
5222 135212 : idx = maybe_constant_value (idx, NULL_TREE, mce_true);
5223 135212 : if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
5224 : {
5225 6 : if (complain & tf_error)
5226 3 : error ("pack index has non-integral type %qT", TREE_TYPE (idx));
5227 6 : return error_mark_node;
5228 : }
5229 135206 : if (TREE_CODE (idx) != INTEGER_CST)
5230 : {
5231 2 : if (complain & tf_error)
5232 : {
5233 2 : error ("pack index is not an integral constant");
5234 2 : cxx_constant_value (idx);
5235 : }
5236 2 : return error_mark_node;
5237 : }
5238 135204 : if (tree_int_cst_sgn (idx) < 0)
5239 : {
5240 3 : if (complain & tf_error)
5241 3 : error ("pack index %qE is negative", idx);
5242 3 : return error_mark_node;
5243 : }
5244 135201 : if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
5245 : {
5246 35 : if (complain & tf_error)
5247 29 : error ("pack index %qE is out of range for pack of length %qd",
5248 29 : idx, TREE_VEC_LENGTH (types));
5249 35 : return error_mark_node;
5250 : }
5251 135166 : return TREE_VEC_ELT (types, tree_to_shwi (idx));
5252 : }
5253 :
5254 : /* In a pack-index T...[N], return the element at index IDX within TYPES.
5255 : PARENTHESIZED_P is true iff the pack index was wrapped in (). */
5256 :
5257 : tree
5258 22546 : pack_index_element (tree idx, tree types, bool parenthesized_p,
5259 : tsubst_flags_t complain)
5260 : {
5261 22546 : tree r = finish_type_pack_element (idx, types, complain);
5262 22546 : if (parenthesized_p)
5263 : /* For the benefit of decltype(auto). */
5264 35 : r = force_paren_expr (r);
5265 22546 : return r;
5266 : }
5267 :
5268 : /* Implement the __direct_bases keyword: Return the direct base classes
5269 : of type. */
5270 :
5271 : tree
5272 15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
5273 : {
5274 15 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5275 15 : || !NON_UNION_CLASS_TYPE_P (type))
5276 8 : return make_tree_vec (0);
5277 :
5278 7 : releasing_vec vector;
5279 7 : vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
5280 7 : tree binfo;
5281 7 : unsigned i;
5282 :
5283 : /* Virtual bases are initialized first */
5284 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5285 13 : if (BINFO_VIRTUAL_P (binfo))
5286 2 : vec_safe_push (vector, binfo);
5287 :
5288 : /* Now non-virtuals */
5289 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5290 13 : if (!BINFO_VIRTUAL_P (binfo))
5291 11 : vec_safe_push (vector, binfo);
5292 :
5293 7 : tree bases_vec = make_tree_vec (vector->length ());
5294 :
5295 27 : for (i = 0; i < vector->length (); ++i)
5296 13 : TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
5297 :
5298 7 : return bases_vec;
5299 7 : }
5300 :
5301 : /* Implement the __bases keyword: Return the base classes
5302 : of type */
5303 :
5304 : /* Find morally non-virtual base classes by walking binfo hierarchy */
5305 : /* Virtual base classes are handled separately in finish_bases */
5306 :
5307 : static tree
5308 73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
5309 : {
5310 : /* Don't walk bases of virtual bases */
5311 73 : return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
5312 : }
5313 :
5314 : static tree
5315 73 : dfs_calculate_bases_post (tree binfo, void *data_)
5316 : {
5317 73 : vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
5318 73 : if (!BINFO_VIRTUAL_P (binfo))
5319 48 : vec_safe_push (*data, BINFO_TYPE (binfo));
5320 73 : return NULL_TREE;
5321 : }
5322 :
5323 : /* Calculates the morally non-virtual base classes of a class */
5324 : static vec<tree, va_gc> *
5325 16 : calculate_bases_helper (tree type)
5326 : {
5327 16 : vec<tree, va_gc> *vector = make_tree_vector ();
5328 :
5329 : /* Now add non-virtual base classes in order of construction */
5330 16 : if (TYPE_BINFO (type))
5331 16 : dfs_walk_all (TYPE_BINFO (type),
5332 : dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
5333 16 : return vector;
5334 : }
5335 :
5336 : tree
5337 12 : calculate_bases (tree type, tsubst_flags_t complain)
5338 : {
5339 12 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5340 12 : || !NON_UNION_CLASS_TYPE_P (type))
5341 5 : return make_tree_vec (0);
5342 :
5343 7 : releasing_vec vector;
5344 7 : tree bases_vec = NULL_TREE;
5345 7 : unsigned i;
5346 7 : vec<tree, va_gc> *vbases;
5347 7 : tree binfo;
5348 :
5349 : /* First go through virtual base classes */
5350 7 : for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
5351 16 : vec_safe_iterate (vbases, i, &binfo); i++)
5352 : {
5353 9 : releasing_vec vbase_bases
5354 9 : = calculate_bases_helper (BINFO_TYPE (binfo));
5355 9 : vec_safe_splice (vector, vbase_bases);
5356 9 : }
5357 :
5358 : /* Now for the non-virtual bases */
5359 7 : releasing_vec nonvbases = calculate_bases_helper (type);
5360 7 : vec_safe_splice (vector, nonvbases);
5361 :
5362 : /* Note that during error recovery vector->length can even be zero. */
5363 7 : if (vector->length () > 1)
5364 : {
5365 : /* Last element is entire class, so don't copy */
5366 6 : bases_vec = make_tree_vec (vector->length () - 1);
5367 :
5368 53 : for (i = 0; i < vector->length () - 1; ++i)
5369 41 : TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
5370 : }
5371 : else
5372 1 : bases_vec = make_tree_vec (0);
5373 :
5374 7 : return bases_vec;
5375 7 : }
5376 :
5377 : tree
5378 28 : finish_bases (tree type, bool direct)
5379 : {
5380 28 : tree bases = NULL_TREE;
5381 :
5382 28 : if (!processing_template_decl)
5383 : {
5384 : /* Parameter packs can only be used in templates */
5385 0 : error ("parameter pack %<__bases%> only valid in template declaration");
5386 0 : return error_mark_node;
5387 : }
5388 :
5389 28 : bases = cxx_make_type (BASES);
5390 28 : BASES_TYPE (bases) = type;
5391 28 : BASES_DIRECT (bases) = direct;
5392 28 : SET_TYPE_STRUCTURAL_EQUALITY (bases);
5393 :
5394 28 : return bases;
5395 : }
5396 :
5397 : /* Perform C++-specific checks for __builtin_offsetof before calling
5398 : fold_offsetof. */
5399 :
5400 : tree
5401 2419 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
5402 : {
5403 : /* If we're processing a template, we can't finish the semantics yet.
5404 : Otherwise we can fold the entire expression now. */
5405 2419 : if (processing_template_decl)
5406 : {
5407 60 : expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
5408 60 : SET_EXPR_LOCATION (expr, loc);
5409 60 : return expr;
5410 : }
5411 :
5412 2359 : if (expr == error_mark_node)
5413 : return error_mark_node;
5414 :
5415 2342 : if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
5416 : {
5417 6 : error ("cannot apply %<offsetof%> to destructor %<~%T%>",
5418 6 : TREE_OPERAND (expr, 2));
5419 6 : return error_mark_node;
5420 : }
5421 4657 : if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
5422 4657 : || TREE_TYPE (expr) == unknown_type_node)
5423 : {
5424 30 : while (TREE_CODE (expr) == COMPONENT_REF
5425 30 : || TREE_CODE (expr) == COMPOUND_EXPR)
5426 12 : expr = TREE_OPERAND (expr, 1);
5427 :
5428 18 : if (DECL_P (expr))
5429 : {
5430 0 : auto_diagnostic_group d;
5431 0 : error ("cannot apply %<offsetof%> to member function %qD", expr);
5432 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
5433 0 : }
5434 : else
5435 18 : error ("cannot apply %<offsetof%> to member function");
5436 18 : return error_mark_node;
5437 : }
5438 2318 : if (TREE_CODE (expr) == CONST_DECL)
5439 : {
5440 3 : error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
5441 3 : return error_mark_node;
5442 : }
5443 2315 : if (REFERENCE_REF_P (expr))
5444 9 : expr = TREE_OPERAND (expr, 0);
5445 2315 : if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
5446 3 : return error_mark_node;
5447 2312 : if (warn_invalid_offsetof
5448 2312 : && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
5449 2312 : && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
5450 2357 : && cp_unevaluated_operand == 0)
5451 45 : warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
5452 : "non-standard-layout type %qT is conditionally-supported",
5453 45 : TREE_TYPE (TREE_TYPE (object_ptr)));
5454 2312 : return fold_offsetof (expr);
5455 : }
5456 :
5457 : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
5458 : function is broken out from the above for the benefit of the tree-ssa
5459 : project. */
5460 :
5461 : void
5462 362004 : simplify_aggr_init_expr (tree *tp)
5463 : {
5464 362004 : tree aggr_init_expr = *tp;
5465 :
5466 : /* Form an appropriate CALL_EXPR. */
5467 362004 : tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
5468 362004 : tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
5469 362004 : tree type = TREE_TYPE (slot);
5470 :
5471 362004 : tree call_expr;
5472 362004 : enum style_t { ctor, arg, pcc } style;
5473 :
5474 362004 : if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
5475 : style = ctor;
5476 : #ifdef PCC_STATIC_STRUCT_RETURN
5477 : else if (1)
5478 : style = pcc;
5479 : #endif
5480 : else
5481 : {
5482 95602 : gcc_assert (TREE_ADDRESSABLE (type));
5483 : style = arg;
5484 : }
5485 :
5486 362004 : call_expr = build_call_array_loc (input_location,
5487 362004 : TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
5488 : fn,
5489 362004 : aggr_init_expr_nargs (aggr_init_expr),
5490 362004 : AGGR_INIT_EXPR_ARGP (aggr_init_expr));
5491 362004 : TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
5492 362004 : CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
5493 362004 : CALL_EXPR_OPERATOR_SYNTAX (call_expr)
5494 362004 : = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
5495 362004 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
5496 362004 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
5497 362004 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
5498 :
5499 362004 : if (style == ctor)
5500 : {
5501 : /* Replace the first argument to the ctor with the address of the
5502 : slot. */
5503 266402 : cxx_mark_addressable (slot);
5504 266402 : CALL_EXPR_ARG (call_expr, 0) =
5505 266402 : build1 (ADDR_EXPR, build_pointer_type (type), slot);
5506 : }
5507 95602 : else if (style == arg)
5508 : {
5509 : /* Just mark it addressable here, and leave the rest to
5510 : expand_call{,_inline}. */
5511 95602 : cxx_mark_addressable (slot);
5512 95602 : CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
5513 95602 : call_expr = cp_build_init_expr (slot, call_expr);
5514 : }
5515 : else if (style == pcc)
5516 : {
5517 : /* If we're using the non-reentrant PCC calling convention, then we
5518 : need to copy the returned value out of the static buffer into the
5519 : SLOT. */
5520 : push_deferring_access_checks (dk_no_check);
5521 : call_expr = build_aggr_init (slot, call_expr,
5522 : DIRECT_BIND | LOOKUP_ONLYCONVERTING,
5523 : tf_warning_or_error);
5524 : pop_deferring_access_checks ();
5525 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
5526 : }
5527 :
5528 362004 : if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
5529 : {
5530 3568 : tree init = build_zero_init (type, NULL_TREE,
5531 : /*static_storage_p=*/false);
5532 3568 : init = cp_build_init_expr (slot, init);
5533 3568 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
5534 : init, call_expr);
5535 : }
5536 :
5537 362004 : *tp = call_expr;
5538 362004 : }
5539 :
5540 : /* Emit all thunks to FN that should be emitted when FN is emitted. */
5541 :
5542 : void
5543 61125649 : emit_associated_thunks (tree fn)
5544 : {
5545 : /* When we use vcall offsets, we emit thunks with the virtual
5546 : functions to which they thunk. The whole point of vcall offsets
5547 : is so that you can know statically the entire set of thunks that
5548 : will ever be needed for a given virtual function, thereby
5549 : enabling you to output all the thunks with the function itself. */
5550 61125649 : if (DECL_VIRTUAL_P (fn)
5551 : /* Do not emit thunks for extern template instantiations. */
5552 1163626 : && ! DECL_REALLY_EXTERN (fn)
5553 : /* Do not emit thunks for tentative decls, those will be processed
5554 : again at_eof if really needed. */
5555 62174453 : && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
5556 : {
5557 1047762 : tree thunk;
5558 :
5559 2099754 : for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
5560 : {
5561 4230 : if (!THUNK_ALIAS (thunk))
5562 : {
5563 4230 : use_thunk (thunk, /*emit_p=*/1);
5564 4230 : if (DECL_RESULT_THUNK_P (thunk))
5565 : {
5566 178 : tree probe;
5567 :
5568 178 : for (probe = DECL_THUNKS (thunk);
5569 327 : probe; probe = DECL_CHAIN (probe))
5570 149 : use_thunk (probe, /*emit_p=*/1);
5571 : }
5572 : }
5573 : else
5574 0 : gcc_assert (!DECL_THUNKS (thunk));
5575 : }
5576 : }
5577 61125649 : }
5578 :
5579 : /* Generate RTL for FN. */
5580 :
5581 : bool
5582 166186745 : expand_or_defer_fn_1 (tree fn)
5583 : {
5584 : /* When the parser calls us after finishing the body of a template
5585 : function, we don't really want to expand the body. */
5586 166186745 : if (processing_template_decl)
5587 : {
5588 : /* Normally, collection only occurs in rest_of_compilation. So,
5589 : if we don't collect here, we never collect junk generated
5590 : during the processing of templates until we hit a
5591 : non-template function. It's not safe to do this inside a
5592 : nested class, though, as the parser may have local state that
5593 : is not a GC root. */
5594 96887195 : if (!function_depth)
5595 96425756 : ggc_collect ();
5596 96887195 : return false;
5597 : }
5598 :
5599 69299550 : gcc_assert (DECL_SAVED_TREE (fn));
5600 :
5601 : /* We make a decision about linkage for these functions at the end
5602 : of the compilation. Until that point, we do not want the back
5603 : end to output them -- but we do want it to see the bodies of
5604 : these functions so that it can inline them as appropriate. */
5605 69299550 : if (DECL_DECLARED_INLINE_P (fn)
5606 1949083 : || DECL_IMPLICIT_INSTANTIATION (fn)
5607 69562198 : || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (fn))
5608 : {
5609 69036929 : if (DECL_INTERFACE_KNOWN (fn))
5610 : /* We've already made a decision as to how this function will
5611 : be handled. */;
5612 48863373 : else if (!at_eof
5613 17606582 : || DECL_IMMEDIATE_FUNCTION_P (fn)
5614 66002283 : || DECL_OMP_DECLARE_REDUCTION_P (fn))
5615 31724463 : tentative_decl_linkage (fn);
5616 : else
5617 17138910 : import_export_decl (fn);
5618 :
5619 : /* If the user wants us to keep all inline functions, then mark
5620 : this function as needed so that finish_file will make sure to
5621 : output it later. Similarly, all dllexport'd functions must
5622 : be emitted; there may be callers in other DLLs. */
5623 69036929 : if (DECL_DECLARED_INLINE_P (fn)
5624 67350467 : && !DECL_REALLY_EXTERN (fn)
5625 63643908 : && !DECL_IMMEDIATE_FUNCTION_P (fn)
5626 62517779 : && !DECL_OMP_DECLARE_REDUCTION_P (fn)
5627 131554708 : && (flag_keep_inline_functions
5628 62514989 : || (flag_keep_inline_dllexport
5629 62514989 : && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
5630 : {
5631 2790 : mark_needed (fn);
5632 2790 : DECL_EXTERNAL (fn) = 0;
5633 : }
5634 : }
5635 :
5636 : /* If this is a constructor or destructor body, we have to clone
5637 : it. */
5638 69299550 : if (maybe_clone_body (fn))
5639 : {
5640 : /* We don't want to process FN again, so pretend we've written
5641 : it out, even though we haven't. */
5642 8145701 : TREE_ASM_WRITTEN (fn) = 1;
5643 : /* If this is a constexpr function we still need the body to be
5644 : able to evaluate it. Similarly, with modules we only stream
5645 : the maybe-in-charge cdtor and regenerate the clones from it on
5646 : demand, so we also need to keep the body. Otherwise we don't
5647 : need it anymore. */
5648 8145701 : if (!maybe_constexpr_fn (fn)
5649 8145701 : && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
5650 3820357 : DECL_SAVED_TREE (fn) = void_node;
5651 8145701 : return false;
5652 : }
5653 :
5654 : /* There's no reason to do any of the work here if we're only doing
5655 : semantic analysis; this code just generates RTL. */
5656 61153849 : if (flag_syntax_only)
5657 : {
5658 : /* Pretend that this function has been written out so that we don't try
5659 : to expand it again. */
5660 28184 : TREE_ASM_WRITTEN (fn) = 1;
5661 28184 : return false;
5662 : }
5663 :
5664 61125665 : if (DECL_OMP_DECLARE_REDUCTION_P (fn))
5665 : return false;
5666 :
5667 : return true;
5668 : }
5669 :
5670 : void
5671 158066823 : expand_or_defer_fn (tree fn)
5672 : {
5673 158066823 : if (expand_or_defer_fn_1 (fn))
5674 : {
5675 53008218 : function_depth++;
5676 :
5677 : /* Expand or defer, at the whim of the compilation unit manager. */
5678 53008218 : cgraph_node::finalize_function (fn, function_depth > 1);
5679 53008218 : emit_associated_thunks (fn);
5680 :
5681 53008218 : function_depth--;
5682 :
5683 106016436 : if (DECL_IMMEDIATE_FUNCTION_P (fn))
5684 : {
5685 1065347 : if (cgraph_node *node = cgraph_node::get (fn))
5686 : {
5687 1065347 : node->body_removed = true;
5688 1065347 : node->analyzed = false;
5689 1065347 : node->definition = false;
5690 1065347 : node->force_output = false;
5691 : }
5692 : }
5693 : }
5694 158066823 : }
5695 :
5696 464836 : class nrv_data
5697 : {
5698 : public:
5699 232418 : nrv_data () : visited (37) {}
5700 :
5701 : tree var;
5702 : tree result;
5703 : hash_set<tree> visited;
5704 : bool simple;
5705 : bool in_nrv_cleanup;
5706 : };
5707 :
5708 : /* Helper function for walk_tree, used by finalize_nrv below. */
5709 :
5710 : static tree
5711 21094236 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
5712 : {
5713 21094236 : class nrv_data *dp = (class nrv_data *)data;
5714 :
5715 : /* No need to walk into types. There wouldn't be any need to walk into
5716 : non-statements, except that we have to consider STMT_EXPRs. */
5717 21094236 : if (TYPE_P (*tp))
5718 192091 : *walk_subtrees = 0;
5719 :
5720 : /* Replace all uses of the NRV with the RESULT_DECL. */
5721 20902145 : else if (*tp == dp->var)
5722 505063 : *tp = dp->result;
5723 :
5724 : /* Avoid walking into the same tree more than once. Unfortunately, we
5725 : can't just use walk_tree_without duplicates because it would only call
5726 : us for the first occurrence of dp->var in the function body. */
5727 20397082 : else if (dp->visited.add (*tp))
5728 4467740 : *walk_subtrees = 0;
5729 :
5730 : /* If there's a label, we might need to destroy the NRV on goto (92407). */
5731 15929342 : else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
5732 3 : dp->simple = false;
5733 : /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
5734 : but differs from using NULL_TREE in that it indicates that we care
5735 : about the value of the RESULT_DECL. But preserve anything appended
5736 : by check_return_expr. */
5737 15929339 : else if (TREE_CODE (*tp) == RETURN_EXPR)
5738 : {
5739 238521 : tree *p = &TREE_OPERAND (*tp, 0);
5740 611497 : while (TREE_CODE (*p) == COMPOUND_EXPR)
5741 134455 : p = &TREE_OPERAND (*p, 0);
5742 238521 : if (TREE_CODE (*p) == INIT_EXPR
5743 238521 : && INIT_EXPR_NRV_P (*p))
5744 238113 : *p = dp->result;
5745 : }
5746 : /* Change all cleanups for the NRV to only run when not returning. */
5747 15690818 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5748 15690818 : && CLEANUP_DECL (*tp) == dp->var)
5749 : {
5750 129423 : dp->in_nrv_cleanup = true;
5751 129423 : cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
5752 129423 : dp->in_nrv_cleanup = false;
5753 129423 : cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
5754 129423 : *walk_subtrees = 0;
5755 :
5756 129423 : if (dp->simple)
5757 : /* For a simple NRV, just run it on the EH path. */
5758 128772 : CLEANUP_EH_ONLY (*tp) = true;
5759 : else
5760 : {
5761 : /* Not simple, we need to check current_retval_sentinel to decide
5762 : whether to run it. If it's set, we're returning normally and
5763 : don't want to destroy the NRV. If the sentinel is not set, we're
5764 : leaving scope some other way, either by flowing off the end of its
5765 : scope or throwing an exception. */
5766 1953 : tree cond = build3 (COND_EXPR, void_type_node,
5767 651 : current_retval_sentinel,
5768 651 : void_node, CLEANUP_EXPR (*tp));
5769 651 : CLEANUP_EXPR (*tp) = cond;
5770 : }
5771 :
5772 : /* If a cleanup might throw, we need to clear current_retval_sentinel on
5773 : the exception path, both so the check above succeeds and so an outer
5774 : cleanup added by maybe_splice_retval_cleanup doesn't run. */
5775 129423 : if (cp_function_chain->throwing_cleanup)
5776 : {
5777 214 : tree clear = build2 (MODIFY_EXPR, boolean_type_node,
5778 : current_retval_sentinel,
5779 : boolean_false_node);
5780 214 : if (dp->simple)
5781 : {
5782 : /* We're already only on the EH path, just prepend it. */
5783 204 : tree &exp = CLEANUP_EXPR (*tp);
5784 204 : exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
5785 : }
5786 : else
5787 : {
5788 : /* The cleanup runs on both normal and EH paths, we need another
5789 : CLEANUP_STMT to clear the flag only on the EH path. */
5790 10 : tree &bod = CLEANUP_BODY (*tp);
5791 10 : bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
5792 10 : bod, clear, current_retval_sentinel);
5793 10 : CLEANUP_EH_ONLY (bod) = true;
5794 : }
5795 : }
5796 : }
5797 : /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
5798 : want to destroy the retval before the variable goes out of scope. */
5799 15561395 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5800 5145 : && dp->in_nrv_cleanup
5801 15565083 : && CLEANUP_DECL (*tp) == dp->result)
5802 6 : CLEANUP_EXPR (*tp) = void_node;
5803 : /* Replace the DECL_EXPR for the NRV with an initialization of the
5804 : RESULT_DECL, if needed. */
5805 15561389 : else if (TREE_CODE (*tp) == DECL_EXPR
5806 15561389 : && DECL_EXPR_DECL (*tp) == dp->var)
5807 : {
5808 232420 : tree init;
5809 232420 : if (DECL_INITIAL (dp->var)
5810 232420 : && DECL_INITIAL (dp->var) != error_mark_node)
5811 95340 : init = cp_build_init_expr (dp->result,
5812 95340 : DECL_INITIAL (dp->var));
5813 : else
5814 137080 : init = build_empty_stmt (EXPR_LOCATION (*tp));
5815 232420 : DECL_INITIAL (dp->var) = NULL_TREE;
5816 232420 : SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
5817 232420 : *tp = init;
5818 : }
5819 :
5820 : /* Keep iterating. */
5821 21094236 : return NULL_TREE;
5822 : }
5823 :
5824 : /* Called from finish_function to implement the named return value
5825 : optimization by overriding all the RETURN_EXPRs and pertinent
5826 : CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5827 : RESULT_DECL for the function. */
5828 :
5829 : void
5830 232418 : finalize_nrv (tree fndecl, tree var)
5831 : {
5832 232418 : class nrv_data data;
5833 232418 : tree result = DECL_RESULT (fndecl);
5834 :
5835 : /* Copy name from VAR to RESULT. */
5836 232418 : DECL_NAME (result) = DECL_NAME (var);
5837 : /* Don't forget that we take its address. */
5838 232418 : TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
5839 : /* Finally set DECL_VALUE_EXPR to avoid assigning
5840 : a stack slot at -O0 for the original var and debug info
5841 : uses RESULT location for VAR. */
5842 232418 : SET_DECL_VALUE_EXPR (var, result);
5843 232418 : DECL_HAS_VALUE_EXPR_P (var) = 1;
5844 :
5845 232418 : data.var = var;
5846 232418 : data.result = result;
5847 232418 : data.in_nrv_cleanup = false;
5848 :
5849 : /* This is simpler for variables declared in the outer scope of
5850 : the function so we know that their lifetime always ends with a
5851 : return; see g++.dg/opt/nrv6.C. */
5852 232418 : tree outer = outer_curly_brace_block (fndecl);
5853 232418 : data.simple = chain_member (var, BLOCK_VARS (outer));
5854 :
5855 232418 : cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
5856 232418 : }
5857 :
5858 : /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5859 :
5860 : bool
5861 2249 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
5862 : bool need_copy_ctor, bool need_copy_assignment,
5863 : bool need_dtor)
5864 : {
5865 2249 : int save_errorcount = errorcount;
5866 2249 : tree info, t;
5867 :
5868 : /* Always allocate 3 elements for simplicity. These are the
5869 : function decls for the ctor, dtor, and assignment op.
5870 : This layout is known to the three lang hooks,
5871 : cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
5872 : and cxx_omp_clause_assign_op. */
5873 2249 : info = make_tree_vec (3);
5874 2249 : CP_OMP_CLAUSE_INFO (c) = info;
5875 :
5876 2249 : if (need_default_ctor || need_copy_ctor)
5877 : {
5878 1654 : if (need_default_ctor)
5879 1255 : t = get_default_ctor (type);
5880 : else
5881 399 : t = get_copy_ctor (type, tf_warning_or_error);
5882 :
5883 1654 : if (t && !trivial_fn_p (t))
5884 1400 : TREE_VEC_ELT (info, 0) = t;
5885 : }
5886 :
5887 2249 : if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
5888 1632 : TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
5889 :
5890 2249 : if (need_copy_assignment)
5891 : {
5892 397 : t = get_copy_assign (type);
5893 :
5894 397 : if (t && !trivial_fn_p (t))
5895 344 : TREE_VEC_ELT (info, 2) = t;
5896 : }
5897 :
5898 2249 : return errorcount != save_errorcount;
5899 : }
5900 :
5901 : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
5902 : FIELD_DECL, otherwise return DECL itself. */
5903 :
5904 : static tree
5905 26301 : omp_clause_decl_field (tree decl)
5906 : {
5907 26301 : if (VAR_P (decl)
5908 18448 : && DECL_HAS_VALUE_EXPR_P (decl)
5909 359 : && DECL_ARTIFICIAL (decl)
5910 359 : && DECL_LANG_SPECIFIC (decl)
5911 26636 : && DECL_OMP_PRIVATIZED_MEMBER (decl))
5912 : {
5913 328 : tree f = DECL_VALUE_EXPR (decl);
5914 328 : if (INDIRECT_REF_P (f))
5915 0 : f = TREE_OPERAND (f, 0);
5916 328 : if (TREE_CODE (f) == COMPONENT_REF)
5917 : {
5918 328 : f = TREE_OPERAND (f, 1);
5919 328 : gcc_assert (TREE_CODE (f) == FIELD_DECL);
5920 : return f;
5921 : }
5922 : }
5923 : return NULL_TREE;
5924 : }
5925 :
5926 : /* Adjust DECL if needed for printing using %qE. */
5927 :
5928 : static tree
5929 187 : omp_clause_printable_decl (tree decl)
5930 : {
5931 0 : tree t = omp_clause_decl_field (decl);
5932 187 : if (t)
5933 45 : return t;
5934 : return decl;
5935 : }
5936 :
5937 : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
5938 : VAR_DECL T that doesn't need a DECL_EXPR added, record it for
5939 : privatization. */
5940 :
5941 : static void
5942 219 : omp_note_field_privatization (tree f, tree t)
5943 : {
5944 219 : if (!omp_private_member_map)
5945 71 : omp_private_member_map = new hash_map<tree, tree>;
5946 219 : tree &v = omp_private_member_map->get_or_insert (f);
5947 219 : if (v == NULL_TREE)
5948 : {
5949 146 : v = t;
5950 146 : omp_private_member_vec.safe_push (f);
5951 : /* Signal that we don't want to create DECL_EXPR for this dummy var. */
5952 146 : omp_private_member_vec.safe_push (integer_zero_node);
5953 : }
5954 219 : }
5955 :
5956 : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
5957 : dummy VAR_DECL. */
5958 :
5959 : tree
5960 861 : omp_privatize_field (tree t, bool shared)
5961 : {
5962 861 : tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
5963 861 : if (m == error_mark_node)
5964 : return error_mark_node;
5965 861 : if (!omp_private_member_map && !shared)
5966 365 : omp_private_member_map = new hash_map<tree, tree>;
5967 861 : if (TYPE_REF_P (TREE_TYPE (t)))
5968 : {
5969 123 : gcc_assert (INDIRECT_REF_P (m));
5970 123 : m = TREE_OPERAND (m, 0);
5971 : }
5972 861 : tree vb = NULL_TREE;
5973 861 : tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
5974 861 : if (v == NULL_TREE)
5975 : {
5976 770 : v = create_temporary_var (TREE_TYPE (m));
5977 770 : retrofit_lang_decl (v);
5978 770 : DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
5979 770 : SET_DECL_VALUE_EXPR (v, m);
5980 770 : DECL_HAS_VALUE_EXPR_P (v) = 1;
5981 770 : if (!shared)
5982 690 : omp_private_member_vec.safe_push (t);
5983 : }
5984 861 : return v;
5985 : }
5986 :
5987 : /* C++ specialisation of the c_omp_address_inspector class. */
5988 :
5989 : class cp_omp_address_inspector : public c_omp_address_inspector
5990 : {
5991 : public:
5992 30914 : cp_omp_address_inspector (location_t loc, tree t)
5993 30914 : : c_omp_address_inspector (loc, t)
5994 : {
5995 : }
5996 :
5997 30914 : ~cp_omp_address_inspector ()
5998 : {
5999 22605 : }
6000 :
6001 131252 : bool processing_template_decl_p ()
6002 : {
6003 131252 : return processing_template_decl;
6004 : }
6005 :
6006 0 : void emit_unmappable_type_notes (tree t)
6007 : {
6008 0 : if (TREE_TYPE (t) != error_mark_node
6009 0 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
6010 0 : cxx_incomplete_type_inform (TREE_TYPE (t));
6011 0 : }
6012 :
6013 1062 : tree convert_from_reference (tree x)
6014 : {
6015 1062 : return ::convert_from_reference (x);
6016 : }
6017 :
6018 145 : tree build_array_ref (location_t loc, tree arr, tree idx)
6019 : {
6020 145 : return ::build_array_ref (loc, arr, idx);
6021 : }
6022 :
6023 22547 : bool check_clause (tree clause)
6024 : {
6025 22547 : if (TREE_CODE (orig) == COMPONENT_REF
6026 22547 : && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
6027 : tf_warning_or_error))
6028 : return false;
6029 22544 : if (!c_omp_address_inspector::check_clause (clause))
6030 : return false;
6031 : return true;
6032 : }
6033 : };
6034 :
6035 : /* Helper function for handle_omp_array_sections. Called recursively
6036 : to handle multiple array-section-subscripts. C is the clause,
6037 : T current expression (initially OMP_CLAUSE_DECL), which is either
6038 : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
6039 : expression if specified, TREE_VALUE length expression if specified,
6040 : TREE_CHAIN is what it has been specified after, or some decl.
6041 : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
6042 : set to true if any of the array-section-subscript could have length
6043 : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
6044 : first array-section-subscript which is known not to have length
6045 : of one. Given say:
6046 : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
6047 : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
6048 : all are or may have length of 1, array-section-subscript [:2] is the
6049 : first one known not to have length 1. For array-section-subscript
6050 : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
6051 : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
6052 : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
6053 : case though, as some lengths could be zero. */
6054 :
6055 : static tree
6056 20474 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
6057 : bool &maybe_zero_len, unsigned int &first_non_one,
6058 : enum c_omp_region_type ort)
6059 : {
6060 20474 : tree ret, low_bound, length, type;
6061 20474 : bool openacc = (ort & C_ORT_ACC) != 0;
6062 20474 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
6063 : {
6064 9279 : if (error_operand_p (t))
6065 6 : return error_mark_node;
6066 :
6067 9273 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6068 9273 : tree t_refto = ai.maybe_unconvert_ref (t);
6069 :
6070 9273 : if (!ai.check_clause (c))
6071 0 : return error_mark_node;
6072 9273 : else if (ai.component_access_p ()
6073 10661 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6074 64 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
6075 40 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
6076 1388 : t = ai.get_root_term (true);
6077 : else
6078 7885 : t = ai.unconverted_ref_origin ();
6079 9273 : if (t == error_mark_node)
6080 : return error_mark_node;
6081 9273 : ret = t_refto;
6082 9273 : if (TREE_CODE (t) == FIELD_DECL)
6083 33 : ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6084 9240 : else if (!VAR_P (t)
6085 2700 : && (openacc || !EXPR_P (t))
6086 2505 : && TREE_CODE (t) != PARM_DECL)
6087 : {
6088 48 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6089 : return NULL_TREE;
6090 30 : if (DECL_P (t))
6091 30 : error_at (OMP_CLAUSE_LOCATION (c),
6092 : "%qD is not a variable in %qs clause", t,
6093 30 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6094 : else
6095 0 : error_at (OMP_CLAUSE_LOCATION (c),
6096 : "%qE is not a variable in %qs clause", t,
6097 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6098 30 : return error_mark_node;
6099 : }
6100 9192 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6101 9002 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6102 17265 : && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
6103 : {
6104 17 : error_at (OMP_CLAUSE_LOCATION (c),
6105 : "%qD is threadprivate variable in %qs clause", t,
6106 17 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6107 17 : return error_mark_node;
6108 : }
6109 9208 : if (type_dependent_expression_p (ret))
6110 : return NULL_TREE;
6111 8521 : ret = convert_from_reference (ret);
6112 8521 : return ret;
6113 9273 : }
6114 :
6115 11195 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
6116 7392 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6117 6198 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6118 4914 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6119 13801 : && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
6120 43 : TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
6121 11195 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
6122 : maybe_zero_len, first_non_one, ort);
6123 11195 : if (ret == error_mark_node || ret == NULL_TREE)
6124 : return ret;
6125 :
6126 10191 : type = TREE_TYPE (ret);
6127 10191 : low_bound = TREE_OPERAND (t, 1);
6128 10191 : length = TREE_OPERAND (t, 2);
6129 8244 : if ((low_bound && type_dependent_expression_p (low_bound))
6130 18352 : || (length && type_dependent_expression_p (length)))
6131 88 : return NULL_TREE;
6132 :
6133 10103 : if (low_bound == error_mark_node || length == error_mark_node)
6134 : return error_mark_node;
6135 :
6136 10103 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
6137 : {
6138 69 : error_at (OMP_CLAUSE_LOCATION (c),
6139 : "low bound %qE of array section does not have integral type",
6140 : low_bound);
6141 69 : return error_mark_node;
6142 : }
6143 10034 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
6144 : {
6145 63 : error_at (OMP_CLAUSE_LOCATION (c),
6146 : "length %qE of array section does not have integral type",
6147 : length);
6148 63 : return error_mark_node;
6149 : }
6150 9971 : if (low_bound)
6151 8078 : low_bound = mark_rvalue_use (low_bound);
6152 9971 : if (length)
6153 9025 : length = mark_rvalue_use (length);
6154 : /* We need to reduce to real constant-values for checks below. */
6155 9025 : if (length)
6156 9025 : length = fold_simple (length);
6157 9971 : if (low_bound)
6158 8078 : low_bound = fold_simple (low_bound);
6159 8078 : if (low_bound
6160 8078 : && TREE_CODE (low_bound) == INTEGER_CST
6161 15231 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6162 7153 : > TYPE_PRECISION (sizetype))
6163 0 : low_bound = fold_convert (sizetype, low_bound);
6164 9971 : if (length
6165 9025 : && TREE_CODE (length) == INTEGER_CST
6166 16985 : && TYPE_PRECISION (TREE_TYPE (length))
6167 7014 : > TYPE_PRECISION (sizetype))
6168 0 : length = fold_convert (sizetype, length);
6169 9971 : if (low_bound == NULL_TREE)
6170 1893 : low_bound = integer_zero_node;
6171 :
6172 9971 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6173 9971 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
6174 5086 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
6175 : {
6176 60 : if (length != integer_one_node)
6177 : {
6178 36 : error_at (OMP_CLAUSE_LOCATION (c),
6179 : "expected single pointer in %qs clause",
6180 : user_omp_clause_code_name (c, openacc));
6181 36 : return error_mark_node;
6182 : }
6183 : }
6184 9935 : if (length != NULL_TREE)
6185 : {
6186 9013 : if (!integer_nonzerop (length))
6187 : {
6188 2058 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6189 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6190 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6191 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6192 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6193 : {
6194 459 : if (integer_zerop (length))
6195 : {
6196 28 : error_at (OMP_CLAUSE_LOCATION (c),
6197 : "zero length array section in %qs clause",
6198 28 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6199 28 : return error_mark_node;
6200 : }
6201 : }
6202 : else
6203 1599 : maybe_zero_len = true;
6204 : }
6205 8985 : if (first_non_one == types.length ()
6206 8985 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
6207 3928 : first_non_one++;
6208 : }
6209 9907 : if (TREE_CODE (type) == ARRAY_TYPE)
6210 : {
6211 5461 : if (length == NULL_TREE
6212 5461 : && (TYPE_DOMAIN (type) == NULL_TREE
6213 850 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
6214 : {
6215 30 : error_at (OMP_CLAUSE_LOCATION (c),
6216 : "for unknown bound array type length expression must "
6217 : "be specified");
6218 30 : return error_mark_node;
6219 : }
6220 5431 : if (TREE_CODE (low_bound) == INTEGER_CST
6221 5431 : && tree_int_cst_sgn (low_bound) == -1)
6222 : {
6223 153 : error_at (OMP_CLAUSE_LOCATION (c),
6224 : "negative low bound in array section in %qs clause",
6225 153 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6226 153 : return error_mark_node;
6227 : }
6228 5278 : if (length != NULL_TREE
6229 4476 : && TREE_CODE (length) == INTEGER_CST
6230 8836 : && tree_int_cst_sgn (length) == -1)
6231 : {
6232 153 : error_at (OMP_CLAUSE_LOCATION (c),
6233 : "negative length in array section in %qs clause",
6234 153 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6235 153 : return error_mark_node;
6236 : }
6237 5125 : if (TYPE_DOMAIN (type)
6238 5031 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6239 10156 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
6240 : == INTEGER_CST)
6241 : {
6242 4635 : tree size
6243 4635 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6244 4635 : size = size_binop (PLUS_EXPR, size, size_one_node);
6245 4635 : if (TREE_CODE (low_bound) == INTEGER_CST)
6246 : {
6247 3868 : if (tree_int_cst_lt (size, low_bound))
6248 : {
6249 54 : error_at (OMP_CLAUSE_LOCATION (c),
6250 : "low bound %qE above array section size "
6251 : "in %qs clause", low_bound,
6252 54 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6253 54 : return error_mark_node;
6254 : }
6255 3814 : if (tree_int_cst_equal (size, low_bound))
6256 : {
6257 17 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6258 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6259 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6260 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6261 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6262 : {
6263 17 : error_at (OMP_CLAUSE_LOCATION (c),
6264 : "zero length array section in %qs clause",
6265 17 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6266 17 : return error_mark_node;
6267 : }
6268 0 : maybe_zero_len = true;
6269 : }
6270 3797 : else if (length == NULL_TREE
6271 1420 : && first_non_one == types.length ()
6272 4095 : && tree_int_cst_equal
6273 298 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6274 : low_bound))
6275 195 : first_non_one++;
6276 : }
6277 767 : else if (length == NULL_TREE)
6278 : {
6279 20 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6280 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6281 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6282 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6283 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6284 13 : maybe_zero_len = true;
6285 40 : if (first_non_one == types.length ())
6286 17 : first_non_one++;
6287 : }
6288 4564 : if (length && TREE_CODE (length) == INTEGER_CST)
6289 : {
6290 3290 : if (tree_int_cst_lt (size, length))
6291 : {
6292 57 : error_at (OMP_CLAUSE_LOCATION (c),
6293 : "length %qE above array section size "
6294 : "in %qs clause", length,
6295 57 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6296 57 : return error_mark_node;
6297 : }
6298 3233 : if (TREE_CODE (low_bound) == INTEGER_CST)
6299 : {
6300 2899 : tree lbpluslen
6301 2899 : = size_binop (PLUS_EXPR,
6302 : fold_convert (sizetype, low_bound),
6303 : fold_convert (sizetype, length));
6304 2899 : if (TREE_CODE (lbpluslen) == INTEGER_CST
6305 2899 : && tree_int_cst_lt (size, lbpluslen))
6306 : {
6307 54 : error_at (OMP_CLAUSE_LOCATION (c),
6308 : "high bound %qE above array section size "
6309 : "in %qs clause", lbpluslen,
6310 54 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6311 54 : return error_mark_node;
6312 : }
6313 : }
6314 : }
6315 : }
6316 490 : else if (length == NULL_TREE)
6317 : {
6318 1 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6319 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6320 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6321 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6322 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6323 0 : maybe_zero_len = true;
6324 2 : if (first_non_one == types.length ())
6325 1 : first_non_one++;
6326 : }
6327 :
6328 : /* For [lb:] we will need to evaluate lb more than once. */
6329 3911 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6330 : {
6331 650 : tree lb = cp_save_expr (low_bound);
6332 650 : if (lb != low_bound)
6333 : {
6334 9 : TREE_OPERAND (t, 1) = lb;
6335 9 : low_bound = lb;
6336 : }
6337 : }
6338 : }
6339 4446 : else if (TYPE_PTR_P (type))
6340 : {
6341 4389 : if (length == NULL_TREE)
6342 : {
6343 42 : if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
6344 36 : error_at (OMP_CLAUSE_LOCATION (c),
6345 : "for array function parameter length expression "
6346 : "must be specified");
6347 : else
6348 6 : error_at (OMP_CLAUSE_LOCATION (c),
6349 : "for pointer type length expression must be specified");
6350 42 : return error_mark_node;
6351 : }
6352 4347 : if (length != NULL_TREE
6353 4347 : && TREE_CODE (length) == INTEGER_CST
6354 3254 : && tree_int_cst_sgn (length) == -1)
6355 : {
6356 84 : error_at (OMP_CLAUSE_LOCATION (c),
6357 : "negative length in array section in %qs clause",
6358 84 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6359 84 : return error_mark_node;
6360 : }
6361 : /* If there is a pointer type anywhere but in the very first
6362 : array-section-subscript, the array section could be non-contiguous. */
6363 4263 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6364 4221 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6365 7999 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
6366 : {
6367 : /* If any prior dimension has a non-one length, then deem this
6368 : array section as non-contiguous. */
6369 158 : for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
6370 69 : d = TREE_OPERAND (d, 0))
6371 : {
6372 89 : tree d_length = TREE_OPERAND (d, 2);
6373 89 : if (d_length == NULL_TREE || !integer_onep (d_length))
6374 : {
6375 20 : error_at (OMP_CLAUSE_LOCATION (c),
6376 : "array section is not contiguous in %qs clause",
6377 20 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6378 20 : return error_mark_node;
6379 : }
6380 : }
6381 : }
6382 : }
6383 : else
6384 : {
6385 57 : error_at (OMP_CLAUSE_LOCATION (c),
6386 : "%qE does not have pointer or array type", ret);
6387 57 : return error_mark_node;
6388 : }
6389 9186 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6390 8281 : types.safe_push (TREE_TYPE (ret));
6391 : /* We will need to evaluate lb more than once. */
6392 9186 : tree lb = cp_save_expr (low_bound);
6393 9186 : if (lb != low_bound)
6394 : {
6395 716 : TREE_OPERAND (t, 1) = lb;
6396 716 : low_bound = lb;
6397 : }
6398 : /* Temporarily disable -fstrong-eval-order for array reductions.
6399 : The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
6400 : is something the middle-end can't cope with and more importantly,
6401 : it needs to be the actual base variable that is privatized, not some
6402 : temporary assigned previous value of it. That, together with OpenMP
6403 : saying how many times the side-effects are evaluated is unspecified,
6404 : makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
6405 9186 : warning_sentinel s (flag_strong_eval_order,
6406 9186 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6407 8173 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6408 18491 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
6409 9186 : ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
6410 : tf_warning_or_error);
6411 9186 : return ret;
6412 9186 : }
6413 :
6414 : /* Handle array sections for clause C. */
6415 :
6416 : static bool
6417 9279 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
6418 : {
6419 9279 : bool maybe_zero_len = false;
6420 9279 : unsigned int first_non_one = 0;
6421 9279 : auto_vec<tree, 10> types;
6422 9279 : tree *tp = &OMP_CLAUSE_DECL (c);
6423 9279 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6424 8320 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6425 9485 : && OMP_ITERATOR_DECL_P (*tp))
6426 258 : tp = &TREE_VALUE (*tp);
6427 9279 : tree first = handle_omp_array_sections_1 (c, *tp, types,
6428 : maybe_zero_len, first_non_one,
6429 : ort);
6430 9279 : if (first == error_mark_node)
6431 : return true;
6432 8309 : if (first == NULL_TREE)
6433 : return false;
6434 7516 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6435 7516 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6436 : {
6437 851 : tree t = *tp;
6438 851 : tree tem = NULL_TREE;
6439 851 : if (processing_template_decl)
6440 : return false;
6441 : /* Need to evaluate side effects in the length expressions
6442 : if any. */
6443 752 : while (TREE_CODE (t) == TREE_LIST)
6444 : {
6445 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
6446 : {
6447 0 : if (tem == NULL_TREE)
6448 : tem = TREE_VALUE (t);
6449 : else
6450 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
6451 0 : TREE_VALUE (t), tem);
6452 : }
6453 0 : t = TREE_CHAIN (t);
6454 : }
6455 752 : if (tem)
6456 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
6457 752 : *tp = first;
6458 : }
6459 : else
6460 : {
6461 6665 : unsigned int num = types.length (), i;
6462 6665 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
6463 6665 : tree condition = NULL_TREE;
6464 :
6465 6665 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
6466 3 : maybe_zero_len = true;
6467 6665 : if (processing_template_decl && maybe_zero_len)
6468 : return false;
6469 :
6470 14020 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
6471 7433 : t = TREE_OPERAND (t, 0))
6472 : {
6473 7504 : gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
6474 :
6475 7504 : tree low_bound = TREE_OPERAND (t, 1);
6476 7504 : tree length = TREE_OPERAND (t, 2);
6477 :
6478 7504 : i--;
6479 7504 : if (low_bound
6480 6121 : && TREE_CODE (low_bound) == INTEGER_CST
6481 13014 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6482 5510 : > TYPE_PRECISION (sizetype))
6483 0 : low_bound = fold_convert (sizetype, low_bound);
6484 7504 : if (length
6485 6985 : && TREE_CODE (length) == INTEGER_CST
6486 12597 : && TYPE_PRECISION (TREE_TYPE (length))
6487 5093 : > TYPE_PRECISION (sizetype))
6488 0 : length = fold_convert (sizetype, length);
6489 7504 : if (low_bound == NULL_TREE)
6490 1383 : low_bound = integer_zero_node;
6491 7504 : if (!maybe_zero_len && i > first_non_one)
6492 : {
6493 629 : if (integer_nonzerop (low_bound))
6494 34 : goto do_warn_noncontiguous;
6495 595 : if (length != NULL_TREE
6496 273 : && TREE_CODE (length) == INTEGER_CST
6497 273 : && TYPE_DOMAIN (types[i])
6498 273 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
6499 868 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
6500 : == INTEGER_CST)
6501 : {
6502 273 : tree size;
6503 273 : size = size_binop (PLUS_EXPR,
6504 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6505 : size_one_node);
6506 273 : if (!tree_int_cst_equal (length, size))
6507 : {
6508 37 : do_warn_noncontiguous:
6509 142 : error_at (OMP_CLAUSE_LOCATION (c),
6510 : "array section is not contiguous in %qs "
6511 : "clause",
6512 71 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6513 71 : return true;
6514 : }
6515 : }
6516 558 : if (!processing_template_decl
6517 390 : && length != NULL_TREE
6518 723 : && TREE_SIDE_EFFECTS (length))
6519 : {
6520 0 : if (side_effects == NULL_TREE)
6521 : side_effects = length;
6522 : else
6523 0 : side_effects = build2 (COMPOUND_EXPR,
6524 0 : TREE_TYPE (side_effects),
6525 : length, side_effects);
6526 : }
6527 : }
6528 6875 : else if (processing_template_decl)
6529 698 : continue;
6530 : else
6531 : {
6532 6177 : tree l;
6533 :
6534 6177 : if (i > first_non_one
6535 6177 : && ((length && integer_nonzerop (length))
6536 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6537 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6538 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
6539 0 : continue;
6540 6177 : if (length)
6541 6060 : l = fold_convert (sizetype, length);
6542 : else
6543 : {
6544 117 : l = size_binop (PLUS_EXPR,
6545 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6546 : size_one_node);
6547 117 : l = size_binop (MINUS_EXPR, l,
6548 : fold_convert (sizetype, low_bound));
6549 : }
6550 6177 : if (i > first_non_one)
6551 : {
6552 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
6553 : size_zero_node);
6554 0 : if (condition == NULL_TREE)
6555 : condition = l;
6556 : else
6557 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
6558 : l, condition);
6559 : }
6560 6177 : else if (size == NULL_TREE)
6561 : {
6562 5899 : size = size_in_bytes (TREE_TYPE (types[i]));
6563 5899 : tree eltype = TREE_TYPE (types[num - 1]);
6564 5968 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6565 69 : eltype = TREE_TYPE (eltype);
6566 5899 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6567 5149 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6568 10295 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6569 1599 : size = size_binop (EXACT_DIV_EXPR, size,
6570 : size_in_bytes (eltype));
6571 5899 : size = size_binop (MULT_EXPR, size, l);
6572 5899 : if (condition)
6573 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
6574 : size, size_zero_node);
6575 : }
6576 : else
6577 278 : size = size_binop (MULT_EXPR, size, l);
6578 : }
6579 : }
6580 6516 : if (!processing_template_decl)
6581 : {
6582 5899 : if (side_effects)
6583 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
6584 5899 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6585 5149 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6586 10295 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6587 : {
6588 1599 : size = size_binop (MINUS_EXPR, size, size_one_node);
6589 1599 : size = save_expr (size);
6590 1599 : tree index_type = build_index_type (size);
6591 1599 : tree eltype = TREE_TYPE (first);
6592 1628 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6593 29 : eltype = TREE_TYPE (eltype);
6594 1599 : tree type = build_array_type (eltype, index_type);
6595 1599 : tree ptype = build_pointer_type (eltype);
6596 1599 : if (TYPE_REF_P (TREE_TYPE (t))
6597 1599 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
6598 152 : t = convert_from_reference (t);
6599 1447 : else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6600 629 : t = build_fold_addr_expr (t);
6601 1599 : tree t2 = build_fold_addr_expr (first);
6602 1599 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6603 : ptrdiff_type_node, t2);
6604 1599 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
6605 : ptrdiff_type_node, t2,
6606 1599 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6607 : ptrdiff_type_node, t));
6608 1599 : if (tree_fits_shwi_p (t2))
6609 1261 : t = build2 (MEM_REF, type, t,
6610 1261 : build_int_cst (ptype, tree_to_shwi (t2)));
6611 : else
6612 : {
6613 338 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6614 : sizetype, t2);
6615 338 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
6616 338 : TREE_TYPE (t), t, t2);
6617 338 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
6618 : }
6619 1599 : OMP_CLAUSE_DECL (c) = t;
6620 7498 : return false;
6621 : }
6622 4300 : OMP_CLAUSE_DECL (c) = first;
6623 4300 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
6624 : return false;
6625 4274 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
6626 4274 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
6627 3734 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
6628 3722 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
6629 4250 : OMP_CLAUSE_SIZE (c) = size;
6630 4274 : if (TREE_CODE (t) == FIELD_DECL)
6631 3 : t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6632 :
6633 4274 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6634 : return false;
6635 :
6636 3746 : if (TREE_CODE (first) == INDIRECT_REF)
6637 : {
6638 : /* Detect and skip adding extra nodes for pointer-to-member
6639 : mappings. These are unsupported for now. */
6640 2411 : tree tmp = TREE_OPERAND (first, 0);
6641 :
6642 2411 : if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
6643 1915 : tmp = TREE_OPERAND (tmp, 0);
6644 :
6645 2411 : if (TREE_CODE (tmp) == INDIRECT_REF)
6646 158 : tmp = TREE_OPERAND (tmp, 0);
6647 :
6648 2411 : if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
6649 : {
6650 466 : tree offset = TREE_OPERAND (tmp, 1);
6651 466 : STRIP_NOPS (offset);
6652 466 : if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
6653 : {
6654 36 : sorry_at (OMP_CLAUSE_LOCATION (c),
6655 : "pointer-to-member mapping %qE not supported",
6656 18 : OMP_CLAUSE_DECL (c));
6657 18 : return true;
6658 : }
6659 : }
6660 : }
6661 :
6662 : /* FIRST represents the first item of data that we are mapping.
6663 : E.g. if we're mapping an array, FIRST might resemble
6664 : "foo.bar.myarray[0]". */
6665 :
6666 3728 : auto_vec<omp_addr_token *, 10> addr_tokens;
6667 :
6668 3728 : if (!omp_parse_expr (addr_tokens, first))
6669 : return true;
6670 :
6671 3728 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6672 :
6673 3728 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
6674 3728 : if (nc != error_mark_node)
6675 : {
6676 3728 : using namespace omp_addr_tokenizer;
6677 :
6678 3728 : if (ai.maybe_zero_length_array_section (c))
6679 3704 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
6680 :
6681 : /* !!! If we're accessing a base decl via chained access
6682 : methods (e.g. multiple indirections), duplicate clause
6683 : detection won't work properly. Skip it in that case. */
6684 3728 : if ((addr_tokens[0]->type == STRUCTURE_BASE
6685 2711 : || addr_tokens[0]->type == ARRAY_BASE)
6686 3728 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
6687 3717 : && addr_tokens[1]->type == ACCESS_METHOD
6688 7445 : && omp_access_chain_p (addr_tokens, 1))
6689 216 : c = nc;
6690 :
6691 3728 : return false;
6692 : }
6693 7456 : }
6694 : }
6695 : return false;
6696 9279 : }
6697 :
6698 : /* Return identifier to look up for omp declare reduction. */
6699 :
6700 : tree
6701 7113 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
6702 : {
6703 7113 : const char *p = NULL;
6704 7113 : const char *m = NULL;
6705 7113 : switch (reduction_code)
6706 : {
6707 4200 : case PLUS_EXPR:
6708 4200 : case MULT_EXPR:
6709 4200 : case MINUS_EXPR:
6710 4200 : case BIT_AND_EXPR:
6711 4200 : case BIT_XOR_EXPR:
6712 4200 : case BIT_IOR_EXPR:
6713 4200 : case TRUTH_ANDIF_EXPR:
6714 4200 : case TRUTH_ORIF_EXPR:
6715 4200 : reduction_id = ovl_op_identifier (false, reduction_code);
6716 4200 : break;
6717 : case MIN_EXPR:
6718 : p = "min";
6719 : break;
6720 : case MAX_EXPR:
6721 : p = "max";
6722 : break;
6723 : default:
6724 : break;
6725 : }
6726 :
6727 4200 : if (p == NULL)
6728 : {
6729 6949 : if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
6730 0 : return error_mark_node;
6731 6949 : p = IDENTIFIER_POINTER (reduction_id);
6732 : }
6733 :
6734 7113 : if (type != NULL_TREE)
6735 2047 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6736 :
6737 7113 : const char prefix[] = "omp declare reduction ";
6738 7113 : size_t lenp = sizeof (prefix);
6739 7113 : if (strncmp (p, prefix, lenp - 1) == 0)
6740 2047 : lenp = 1;
6741 7113 : size_t len = strlen (p);
6742 7113 : size_t lenm = m ? strlen (m) + 1 : 0;
6743 7113 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6744 7113 : if (lenp > 1)
6745 5066 : memcpy (name, prefix, lenp - 1);
6746 7113 : memcpy (name + lenp - 1, p, len + 1);
6747 7113 : if (m)
6748 : {
6749 2047 : name[lenp + len - 1] = '~';
6750 2047 : memcpy (name + lenp + len, m, lenm);
6751 : }
6752 7113 : return get_identifier (name);
6753 : }
6754 :
6755 : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
6756 : FUNCTION_DECL or NULL_TREE if not found. */
6757 :
6758 : static tree
6759 1298 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
6760 : vec<tree> *ambiguousp)
6761 : {
6762 1298 : tree orig_id = id;
6763 1298 : tree baselink = NULL_TREE;
6764 1298 : if (identifier_p (id))
6765 : {
6766 1270 : cp_id_kind idk;
6767 1270 : bool nonint_cst_expression_p;
6768 1270 : const char *error_msg;
6769 1270 : id = omp_reduction_id (ERROR_MARK, id, type);
6770 1270 : tree decl = lookup_name (id);
6771 1270 : if (decl == NULL_TREE)
6772 80 : decl = error_mark_node;
6773 1270 : id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
6774 : &nonint_cst_expression_p, false, true, false,
6775 : false, &error_msg, loc);
6776 1270 : if (idk == CP_ID_KIND_UNQUALIFIED
6777 1350 : && identifier_p (id))
6778 : {
6779 80 : vec<tree, va_gc> *args = NULL;
6780 80 : vec_safe_push (args, build_reference_type (type));
6781 80 : id = perform_koenig_lookup (id, args, tf_none);
6782 : }
6783 : }
6784 28 : else if (TREE_CODE (id) == SCOPE_REF)
6785 28 : id = lookup_qualified_name (TREE_OPERAND (id, 0),
6786 : omp_reduction_id (ERROR_MARK,
6787 28 : TREE_OPERAND (id, 1),
6788 : type),
6789 : LOOK_want::NORMAL, false);
6790 1298 : tree fns = id;
6791 1298 : id = NULL_TREE;
6792 1298 : if (fns && is_overloaded_fn (fns))
6793 : {
6794 1224 : for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
6795 : {
6796 1224 : tree fndecl = *iter;
6797 1224 : if (TREE_CODE (fndecl) == FUNCTION_DECL)
6798 : {
6799 1224 : tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
6800 1224 : if (same_type_p (TREE_TYPE (argtype), type))
6801 : {
6802 1224 : id = fndecl;
6803 1224 : break;
6804 : }
6805 : }
6806 : }
6807 :
6808 1224 : if (id && BASELINK_P (fns))
6809 : {
6810 74 : if (baselinkp)
6811 0 : *baselinkp = fns;
6812 : else
6813 74 : baselink = fns;
6814 : }
6815 : }
6816 :
6817 1298 : if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
6818 : {
6819 35 : auto_vec<tree> ambiguous;
6820 35 : tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
6821 35 : unsigned int ix;
6822 35 : if (ambiguousp == NULL)
6823 19 : ambiguousp = &ambiguous;
6824 73 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
6825 : {
6826 52 : id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
6827 : baselinkp ? baselinkp : &baselink,
6828 : ambiguousp);
6829 38 : if (id == NULL_TREE)
6830 14 : continue;
6831 24 : if (!ambiguousp->is_empty ())
6832 3 : ambiguousp->safe_push (id);
6833 21 : else if (ret != NULL_TREE)
6834 : {
6835 6 : ambiguousp->safe_push (ret);
6836 6 : ambiguousp->safe_push (id);
6837 6 : ret = NULL_TREE;
6838 : }
6839 : else
6840 15 : ret = id;
6841 : }
6842 35 : if (ambiguousp != &ambiguous)
6843 16 : return ret;
6844 19 : if (!ambiguous.is_empty ())
6845 : {
6846 6 : auto_diagnostic_group d;
6847 6 : const char *str = _("candidates are:");
6848 6 : unsigned int idx;
6849 6 : tree udr;
6850 6 : error_at (loc, "user defined reduction lookup is ambiguous");
6851 27 : FOR_EACH_VEC_ELT (ambiguous, idx, udr)
6852 : {
6853 15 : inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
6854 15 : if (idx == 0)
6855 6 : str = get_spaces (str);
6856 : }
6857 6 : ret = error_mark_node;
6858 6 : baselink = NULL_TREE;
6859 6 : }
6860 19 : id = ret;
6861 35 : }
6862 1282 : if (id && baselink)
6863 74 : perform_or_defer_access_check (BASELINK_BINFO (baselink),
6864 : id, id, tf_warning_or_error);
6865 : return id;
6866 : }
6867 :
6868 : /* Return identifier to look up for omp declare mapper. */
6869 :
6870 : tree
6871 4067 : omp_mapper_id (tree mapper_id, tree type)
6872 : {
6873 4067 : const char *p = NULL;
6874 4067 : const char *m = NULL;
6875 :
6876 4067 : if (mapper_id == NULL_TREE)
6877 : p = "";
6878 91 : else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
6879 91 : p = IDENTIFIER_POINTER (mapper_id);
6880 : else
6881 0 : return error_mark_node;
6882 :
6883 4067 : if (type != NULL_TREE)
6884 4059 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6885 :
6886 4067 : const char prefix[] = "omp declare mapper ";
6887 4067 : size_t lenp = sizeof (prefix);
6888 4067 : if (strncmp (p, prefix, lenp - 1) == 0)
6889 8 : lenp = 1;
6890 4067 : size_t len = strlen (p);
6891 4067 : size_t lenm = m ? strlen (m) + 1 : 0;
6892 4067 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6893 4067 : memcpy (name, prefix, lenp - 1);
6894 4067 : memcpy (name + lenp - 1, p, len + 1);
6895 4067 : if (m)
6896 : {
6897 4059 : name[lenp + len - 1] = '~';
6898 4059 : memcpy (name + lenp + len, m, lenm);
6899 : }
6900 4067 : return get_identifier (name);
6901 : }
6902 :
6903 : tree
6904 11960 : cxx_omp_mapper_lookup (tree id, tree type)
6905 : {
6906 11960 : if (!RECORD_OR_UNION_TYPE_P (type))
6907 : return NULL_TREE;
6908 3826 : id = omp_mapper_id (id, type);
6909 3826 : return lookup_name (id);
6910 : }
6911 :
6912 : tree
6913 375 : cxx_omp_extract_mapper_directive (tree vardecl)
6914 : {
6915 375 : gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
6916 :
6917 : /* Instantiate the decl if we haven't already. */
6918 375 : mark_used (vardecl);
6919 375 : tree body = DECL_INITIAL (vardecl);
6920 :
6921 375 : if (TREE_CODE (body) == STATEMENT_LIST)
6922 : {
6923 0 : tree_stmt_iterator tsi = tsi_start (body);
6924 0 : gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
6925 0 : tsi_next (&tsi);
6926 0 : body = tsi_stmt (tsi);
6927 : }
6928 :
6929 375 : gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
6930 :
6931 375 : return body;
6932 : }
6933 :
6934 : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
6935 : nothing more complicated. */
6936 :
6937 : tree
6938 1910 : cxx_omp_map_array_section (location_t loc, tree t)
6939 : {
6940 1910 : tree low = TREE_OPERAND (t, 1);
6941 1910 : tree len = TREE_OPERAND (t, 2);
6942 :
6943 1910 : if (len && integer_onep (len))
6944 : {
6945 300 : t = TREE_OPERAND (t, 0);
6946 :
6947 300 : if (!low)
6948 17 : low = integer_zero_node;
6949 :
6950 300 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
6951 6 : t = convert_from_reference (t);
6952 :
6953 300 : if (TYPE_PTR_P (TREE_TYPE (t))
6954 300 : || TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6955 300 : t = build_array_ref (loc, t, low);
6956 : else
6957 : /* handle_omp_array_sections_1 has already diagnosed the error. */
6958 0 : t = error_mark_node;
6959 : }
6960 :
6961 1910 : return t;
6962 : }
6963 :
6964 : /* Helper function for cp_parser_omp_declare_reduction_exprs
6965 : and tsubst_omp_udr.
6966 : Remove CLEANUP_STMT for data (omp_priv variable).
6967 : Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
6968 : DECL_EXPR. */
6969 :
6970 : tree
6971 4449 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
6972 : {
6973 4449 : if (TYPE_P (*tp))
6974 230 : *walk_subtrees = 0;
6975 4219 : else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
6976 52 : *tp = CLEANUP_BODY (*tp);
6977 4167 : else if (TREE_CODE (*tp) == DECL_EXPR)
6978 : {
6979 310 : tree decl = DECL_EXPR_DECL (*tp);
6980 310 : if (!processing_template_decl
6981 261 : && decl == (tree) data
6982 261 : && DECL_INITIAL (decl)
6983 402 : && DECL_INITIAL (decl) != error_mark_node)
6984 : {
6985 92 : tree list = NULL_TREE;
6986 92 : append_to_statement_list_force (*tp, &list);
6987 92 : tree init_expr = build2 (INIT_EXPR, void_type_node,
6988 92 : decl, DECL_INITIAL (decl));
6989 92 : DECL_INITIAL (decl) = NULL_TREE;
6990 92 : append_to_statement_list_force (init_expr, &list);
6991 92 : *tp = list;
6992 : }
6993 : }
6994 4449 : return NULL_TREE;
6995 : }
6996 :
6997 : /* Data passed from cp_check_omp_declare_reduction to
6998 : cp_check_omp_declare_reduction_r. */
6999 :
7000 : struct cp_check_omp_declare_reduction_data
7001 : {
7002 : location_t loc;
7003 : tree stmts[7];
7004 : bool combiner_p;
7005 : };
7006 :
7007 : /* Helper function for cp_check_omp_declare_reduction, called via
7008 : cp_walk_tree. */
7009 :
7010 : static tree
7011 15042 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
7012 : {
7013 15042 : struct cp_check_omp_declare_reduction_data *udr_data
7014 : = (struct cp_check_omp_declare_reduction_data *) data;
7015 15042 : if (SSA_VAR_P (*tp)
7016 2702 : && !DECL_ARTIFICIAL (*tp)
7017 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
7018 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
7019 : {
7020 135 : location_t loc = udr_data->loc;
7021 135 : if (udr_data->combiner_p)
7022 45 : error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
7023 : "variable %qD which is not %<omp_out%> nor %<omp_in%>",
7024 : *tp);
7025 : else
7026 90 : error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
7027 : "to variable %qD which is not %<omp_priv%> nor "
7028 : "%<omp_orig%>",
7029 : *tp);
7030 135 : return *tp;
7031 : }
7032 : return NULL_TREE;
7033 : }
7034 :
7035 : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
7036 :
7037 : bool
7038 1104 : cp_check_omp_declare_reduction (tree udr)
7039 : {
7040 1104 : tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
7041 1104 : gcc_assert (TYPE_REF_P (type));
7042 1104 : type = TREE_TYPE (type);
7043 1104 : int i;
7044 1104 : location_t loc = DECL_SOURCE_LOCATION (udr);
7045 :
7046 1104 : if (type == error_mark_node)
7047 : return false;
7048 1104 : if (ARITHMETIC_TYPE_P (type))
7049 : {
7050 : static enum tree_code predef_codes[]
7051 : = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
7052 : BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
7053 3276 : for (i = 0; i < 8; i++)
7054 : {
7055 2918 : tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
7056 2918 : const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
7057 2918 : const char *n2 = IDENTIFIER_POINTER (id);
7058 2918 : if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
7059 2918 : && (n1[IDENTIFIER_LENGTH (id)] == '~'
7060 0 : || n1[IDENTIFIER_LENGTH (id)] == '\0'))
7061 : break;
7062 : }
7063 :
7064 376 : if (i == 8
7065 358 : && TREE_CODE (type) != COMPLEX_EXPR)
7066 : {
7067 358 : const char prefix_minmax[] = "omp declare reduction m";
7068 358 : size_t prefix_size = sizeof (prefix_minmax) - 1;
7069 358 : const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
7070 358 : if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
7071 : prefix_minmax, prefix_size) == 0
7072 10 : && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
7073 4 : || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
7074 368 : && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
7075 6 : i = 0;
7076 : }
7077 376 : if (i < 8)
7078 : {
7079 24 : error_at (loc, "predeclared arithmetic type %qT in "
7080 : "%<#pragma omp declare reduction%>", type);
7081 24 : return false;
7082 : }
7083 : }
7084 : else if (FUNC_OR_METHOD_TYPE_P (type)
7085 : || TREE_CODE (type) == ARRAY_TYPE)
7086 : {
7087 24 : error_at (loc, "function or array type %qT in "
7088 : "%<#pragma omp declare reduction%>", type);
7089 24 : return false;
7090 : }
7091 : else if (TYPE_REF_P (type))
7092 : {
7093 0 : error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
7094 : type);
7095 0 : return false;
7096 : }
7097 704 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
7098 : {
7099 24 : error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
7100 : "type %qT in %<#pragma omp declare reduction%>", type);
7101 24 : return false;
7102 : }
7103 :
7104 1032 : tree body = DECL_SAVED_TREE (udr);
7105 1032 : if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
7106 : return true;
7107 :
7108 846 : tree_stmt_iterator tsi;
7109 846 : struct cp_check_omp_declare_reduction_data data;
7110 846 : memset (data.stmts, 0, sizeof data.stmts);
7111 846 : for (i = 0, tsi = tsi_start (body);
7112 4707 : i < 7 && !tsi_end_p (tsi);
7113 3861 : i++, tsi_next (&tsi))
7114 3861 : data.stmts[i] = tsi_stmt (tsi);
7115 846 : data.loc = loc;
7116 846 : gcc_assert (tsi_end_p (tsi));
7117 846 : if (i >= 3)
7118 : {
7119 846 : gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
7120 : && TREE_CODE (data.stmts[1]) == DECL_EXPR);
7121 846 : if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
7122 : return true;
7123 801 : data.combiner_p = true;
7124 801 : if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
7125 : &data, NULL))
7126 45 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
7127 : }
7128 801 : if (i >= 6)
7129 : {
7130 339 : gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
7131 : && TREE_CODE (data.stmts[4]) == DECL_EXPR);
7132 339 : data.combiner_p = false;
7133 339 : if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
7134 : &data, NULL)
7135 339 : || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
7136 : cp_check_omp_declare_reduction_r, &data, NULL))
7137 90 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */);
7138 339 : if (i == 7)
7139 201 : gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
7140 : }
7141 : return true;
7142 : }
7143 :
7144 : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
7145 : an inline call. But, remap
7146 : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
7147 : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
7148 :
7149 : static tree
7150 2217 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
7151 : tree decl, tree placeholder)
7152 : {
7153 2217 : copy_body_data id;
7154 2217 : hash_map<tree, tree> decl_map;
7155 :
7156 2217 : decl_map.put (omp_decl1, placeholder);
7157 2217 : decl_map.put (omp_decl2, decl);
7158 2217 : memset (&id, 0, sizeof (id));
7159 2217 : id.src_fn = DECL_CONTEXT (omp_decl1);
7160 2217 : id.dst_fn = current_function_decl;
7161 2217 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
7162 2217 : id.decl_map = &decl_map;
7163 :
7164 2217 : id.copy_decl = copy_decl_no_change;
7165 2217 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
7166 2217 : id.transform_new_cfg = true;
7167 2217 : id.transform_return_to_modify = false;
7168 2217 : id.eh_lp_nr = 0;
7169 2217 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
7170 2217 : return stmt;
7171 2217 : }
7172 :
7173 : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
7174 : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
7175 :
7176 : static tree
7177 15573 : find_omp_placeholder_r (tree *tp, int *, void *data)
7178 : {
7179 15573 : if (*tp == (tree) data)
7180 274 : return *tp;
7181 : return NULL_TREE;
7182 : }
7183 :
7184 : /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
7185 : Return true if there is some error and the clause should be removed. */
7186 :
7187 : static bool
7188 8898 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
7189 : {
7190 8898 : tree t = OMP_CLAUSE_DECL (c);
7191 8898 : bool predefined = false;
7192 8898 : if (TREE_CODE (t) == TREE_LIST)
7193 : {
7194 0 : gcc_assert (processing_template_decl);
7195 : return false;
7196 : }
7197 8898 : tree type = TREE_TYPE (t);
7198 8898 : if (TREE_CODE (t) == MEM_REF)
7199 1596 : type = TREE_TYPE (type);
7200 8898 : if (TYPE_REF_P (type))
7201 527 : type = TREE_TYPE (type);
7202 8898 : if (TREE_CODE (type) == ARRAY_TYPE)
7203 : {
7204 350 : tree oatype = type;
7205 350 : gcc_assert (TREE_CODE (t) != MEM_REF);
7206 703 : while (TREE_CODE (type) == ARRAY_TYPE)
7207 353 : type = TREE_TYPE (type);
7208 350 : if (!processing_template_decl)
7209 : {
7210 255 : t = require_complete_type (t);
7211 255 : if (t == error_mark_node
7212 255 : || !complete_type_or_else (oatype, NULL_TREE))
7213 9 : return true;
7214 246 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
7215 : TYPE_SIZE_UNIT (type));
7216 246 : if (integer_zerop (size))
7217 : {
7218 6 : error_at (OMP_CLAUSE_LOCATION (c),
7219 : "%qE in %<reduction%> clause is a zero size array",
7220 : omp_clause_printable_decl (t));
7221 3 : return true;
7222 : }
7223 243 : size = size_binop (MINUS_EXPR, size, size_one_node);
7224 243 : size = save_expr (size);
7225 243 : tree index_type = build_index_type (size);
7226 243 : tree atype = build_array_type (type, index_type);
7227 243 : tree ptype = build_pointer_type (type);
7228 243 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7229 146 : t = build_fold_addr_expr (t);
7230 243 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
7231 243 : OMP_CLAUSE_DECL (c) = t;
7232 : }
7233 : }
7234 8886 : if (type == error_mark_node)
7235 : return true;
7236 8883 : else if (ARITHMETIC_TYPE_P (type))
7237 7623 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
7238 : {
7239 : case PLUS_EXPR:
7240 : case MULT_EXPR:
7241 : case MINUS_EXPR:
7242 : case TRUTH_ANDIF_EXPR:
7243 : case TRUTH_ORIF_EXPR:
7244 : predefined = true;
7245 : break;
7246 246 : case MIN_EXPR:
7247 246 : case MAX_EXPR:
7248 246 : if (TREE_CODE (type) == COMPLEX_TYPE)
7249 : break;
7250 : predefined = true;
7251 : break;
7252 111 : case BIT_AND_EXPR:
7253 111 : case BIT_IOR_EXPR:
7254 111 : case BIT_XOR_EXPR:
7255 111 : if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
7256 : break;
7257 : predefined = true;
7258 : break;
7259 : default:
7260 : break;
7261 : }
7262 1260 : else if (TYPE_READONLY (type))
7263 : {
7264 18 : error_at (OMP_CLAUSE_LOCATION (c),
7265 : "%qE has const type for %<reduction%>",
7266 : omp_clause_printable_decl (t));
7267 9 : return true;
7268 : }
7269 1251 : else if (!processing_template_decl)
7270 : {
7271 1047 : t = require_complete_type (t);
7272 1047 : if (t == error_mark_node)
7273 : return true;
7274 1047 : OMP_CLAUSE_DECL (c) = t;
7275 : }
7276 :
7277 1047 : if (predefined)
7278 : {
7279 7401 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7280 7401 : return false;
7281 : }
7282 1473 : else if (processing_template_decl)
7283 : {
7284 213 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
7285 : return true;
7286 : return false;
7287 : }
7288 :
7289 1260 : tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7290 :
7291 1260 : type = TYPE_MAIN_VARIANT (type);
7292 1260 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7293 1260 : if (id == NULL_TREE)
7294 933 : id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
7295 : NULL_TREE, NULL_TREE);
7296 1260 : id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
7297 1260 : if (id)
7298 : {
7299 1215 : if (id == error_mark_node)
7300 : return true;
7301 1209 : mark_used (id);
7302 1209 : tree body = DECL_SAVED_TREE (id);
7303 1209 : if (!body)
7304 : return true;
7305 1206 : if (TREE_CODE (body) == STATEMENT_LIST)
7306 : {
7307 1206 : tree_stmt_iterator tsi;
7308 1206 : tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
7309 1206 : int i;
7310 1206 : tree stmts[7];
7311 1206 : tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
7312 1206 : atype = TREE_TYPE (atype);
7313 1206 : bool need_static_cast = !same_type_p (type, atype);
7314 1206 : memset (stmts, 0, sizeof stmts);
7315 1206 : for (i = 0, tsi = tsi_start (body);
7316 8594 : i < 7 && !tsi_end_p (tsi);
7317 7388 : i++, tsi_next (&tsi))
7318 7388 : stmts[i] = tsi_stmt (tsi);
7319 1206 : gcc_assert (tsi_end_p (tsi));
7320 :
7321 1206 : if (i >= 3)
7322 : {
7323 1206 : gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
7324 : && TREE_CODE (stmts[1]) == DECL_EXPR);
7325 1206 : placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
7326 1206 : DECL_ARTIFICIAL (placeholder) = 1;
7327 1206 : DECL_IGNORED_P (placeholder) = 1;
7328 1206 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
7329 1206 : if (TREE_CODE (t) == MEM_REF)
7330 : {
7331 600 : decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
7332 : type);
7333 600 : DECL_ARTIFICIAL (decl_placeholder) = 1;
7334 600 : DECL_IGNORED_P (decl_placeholder) = 1;
7335 600 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
7336 : }
7337 1206 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
7338 294 : cxx_mark_addressable (placeholder);
7339 1206 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
7340 1206 : && (decl_placeholder
7341 158 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7342 390 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7343 127 : : OMP_CLAUSE_DECL (c));
7344 1206 : tree omp_out = placeholder;
7345 1206 : tree omp_in = decl_placeholder ? decl_placeholder
7346 606 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7347 1206 : if (need_static_cast)
7348 : {
7349 7 : tree rtype = build_reference_type (atype);
7350 7 : omp_out = build_static_cast (input_location,
7351 : rtype, omp_out,
7352 : tf_warning_or_error);
7353 7 : omp_in = build_static_cast (input_location,
7354 : rtype, omp_in,
7355 : tf_warning_or_error);
7356 7 : if (omp_out == error_mark_node || omp_in == error_mark_node)
7357 3 : return true;
7358 7 : omp_out = convert_from_reference (omp_out);
7359 7 : omp_in = convert_from_reference (omp_in);
7360 : }
7361 1206 : OMP_CLAUSE_REDUCTION_MERGE (c)
7362 1206 : = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
7363 1206 : DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
7364 : }
7365 1206 : if (i >= 6)
7366 : {
7367 1014 : gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
7368 : && TREE_CODE (stmts[4]) == DECL_EXPR);
7369 1014 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
7370 1014 : && (decl_placeholder
7371 232 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7372 844 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7373 170 : : OMP_CLAUSE_DECL (c));
7374 1014 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
7375 225 : cxx_mark_addressable (placeholder);
7376 1014 : tree omp_priv = decl_placeholder ? decl_placeholder
7377 438 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7378 1014 : tree omp_orig = placeholder;
7379 1014 : if (need_static_cast)
7380 : {
7381 5 : if (i == 7)
7382 : {
7383 3 : error_at (OMP_CLAUSE_LOCATION (c),
7384 : "user defined reduction with constructor "
7385 : "initializer for base class %qT", atype);
7386 3 : return true;
7387 : }
7388 2 : tree rtype = build_reference_type (atype);
7389 2 : omp_priv = build_static_cast (input_location,
7390 : rtype, omp_priv,
7391 : tf_warning_or_error);
7392 2 : omp_orig = build_static_cast (input_location,
7393 : rtype, omp_orig,
7394 : tf_warning_or_error);
7395 2 : if (omp_priv == error_mark_node
7396 2 : || omp_orig == error_mark_node)
7397 : return true;
7398 2 : omp_priv = convert_from_reference (omp_priv);
7399 2 : omp_orig = convert_from_reference (omp_orig);
7400 : }
7401 1011 : if (i == 6)
7402 286 : *need_default_ctor = true;
7403 1011 : OMP_CLAUSE_REDUCTION_INIT (c)
7404 1011 : = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
7405 1011 : DECL_EXPR_DECL (stmts[3]),
7406 : omp_priv, omp_orig);
7407 1011 : if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
7408 : find_omp_placeholder_r, placeholder, NULL))
7409 247 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
7410 : }
7411 192 : else if (i >= 3)
7412 : {
7413 192 : if (CLASS_TYPE_P (type) && !pod_type_p (type))
7414 175 : *need_default_ctor = true;
7415 : else
7416 : {
7417 17 : tree init;
7418 17 : tree v = decl_placeholder ? decl_placeholder
7419 17 : : convert_from_reference (t);
7420 17 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
7421 8 : init = build_constructor (TREE_TYPE (v), NULL);
7422 : else
7423 9 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
7424 34 : OMP_CLAUSE_REDUCTION_INIT (c)
7425 34 : = cp_build_init_expr (v, init);
7426 : }
7427 : }
7428 : }
7429 : }
7430 1248 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7431 1203 : *need_dtor = true;
7432 : else
7433 : {
7434 90 : error_at (OMP_CLAUSE_LOCATION (c),
7435 : "user defined reduction not found for %qE",
7436 : omp_clause_printable_decl (t));
7437 45 : return true;
7438 : }
7439 1203 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7440 600 : gcc_assert (TYPE_SIZE_UNIT (type)
7441 : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
7442 : return false;
7443 : }
7444 :
7445 : /* Check an instance of an "omp declare mapper" function. */
7446 :
7447 : bool
7448 208 : cp_check_omp_declare_mapper (tree udm)
7449 : {
7450 208 : tree var = OMP_DECLARE_MAPPER_DECL (udm);
7451 208 : tree type = TREE_TYPE (var);
7452 208 : location_t loc = DECL_SOURCE_LOCATION (var);
7453 :
7454 208 : if (type == error_mark_node)
7455 : return false;
7456 :
7457 208 : if (processing_template_decl)
7458 : return true;
7459 :
7460 197 : if (!RECORD_OR_UNION_TYPE_P (type))
7461 : {
7462 17 : error_at (loc, "%qT is not a struct, union or class type in "
7463 : "%<#pragma omp declare mapper%>", type);
7464 17 : return false;
7465 : }
7466 180 : if (CLASSTYPE_VBASECLASSES (type))
7467 : {
7468 3 : error_at (loc, "%qT must not be a virtual base class in "
7469 : "%<#pragma omp declare mapper%>", type);
7470 3 : return false;
7471 : }
7472 :
7473 177 : tree c = OMP_DECLARE_MAPPER_CLAUSES (udm);
7474 215 : for ( ; c; c = OMP_CLAUSE_CHAIN (c))
7475 : {
7476 187 : tree dvar = OMP_CLAUSE_DECL (c);
7477 400 : while (!DECL_P (dvar) && TREE_OPERAND_LENGTH (dvar))
7478 213 : dvar = TREE_OPERAND (dvar, 0);
7479 187 : if (dvar == var)
7480 : break;
7481 : }
7482 177 : if (!c)
7483 : {
7484 : // After template handling, the var is mangled, demangle it
7485 28 : const char *name = IDENTIFIER_POINTER (DECL_NAME (var));
7486 28 : char *n = NULL;
7487 28 : if (startswith (name, "omp declare mapper "))
7488 : {
7489 3 : name += strlen ("omp declare mapper ");
7490 3 : n = xstrdup (name);
7491 3 : n[strchr (n, '~')-n] = '\0';
7492 3 : name = n;
7493 : }
7494 28 : error_at (loc, "at least one %<map%> clause must map %qs or an "
7495 : "element of it", name);
7496 28 : if (n)
7497 3 : free (n);
7498 28 : return false;
7499 : }
7500 :
7501 : /* FIXME: The vardecl created for the mapper_id uses DECL_DECLARED_CONSTEXPR_P
7502 : = 1, which is set to false in finalize_literal_type_property for C++ < 11,
7503 : leading to an error in ensure_literal_type_for_constexpr_object.
7504 : Examples (compile with -std=c++98): gcc.dg/gomp/declare-mapper-13.c and
7505 : libgomp.c++/declare-mapper-{5,6,8}.C. */
7506 149 : if (cxx_dialect < cxx11)
7507 : {
7508 0 : sorry_at (loc, "%<#pragma omp declare mapper%> with %<-std=%> set to "
7509 : "before C++11");
7510 0 : return false;
7511 : }
7512 :
7513 : return true;
7514 : }
7515 :
7516 : /* Called from finish_struct_1. linear(this) or linear(this:step)
7517 : clauses might not be finalized yet because the class has been incomplete
7518 : when parsing #pragma omp declare simd methods. Fix those up now. */
7519 :
7520 : void
7521 118312 : finish_omp_declare_simd_methods (tree t)
7522 : {
7523 118312 : if (processing_template_decl)
7524 : return;
7525 :
7526 808374 : for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
7527 : {
7528 1142076 : if (TREE_CODE (x) == USING_DECL
7529 690062 : || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
7530 452014 : continue;
7531 238048 : tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
7532 238156 : if (!ods || !TREE_VALUE (ods))
7533 237940 : continue;
7534 366 : for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
7535 258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7536 66 : && integer_zerop (OMP_CLAUSE_DECL (c))
7537 18 : && OMP_CLAUSE_LINEAR_STEP (c)
7538 276 : && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
7539 : {
7540 18 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
7541 18 : s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
7542 18 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
7543 18 : sizetype, s, TYPE_SIZE_UNIT (t));
7544 18 : OMP_CLAUSE_LINEAR_STEP (c) = s;
7545 : }
7546 : }
7547 : }
7548 :
7549 : /* Adjust sink depend/doacross clause to take into account pointer offsets.
7550 :
7551 : Return TRUE if there was a problem processing the offset, and the
7552 : whole clause should be removed. */
7553 :
7554 : static bool
7555 298 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
7556 : {
7557 298 : tree t = OMP_CLAUSE_DECL (sink_clause);
7558 298 : gcc_assert (TREE_CODE (t) == TREE_LIST);
7559 :
7560 : /* Make sure we don't adjust things twice for templates. */
7561 298 : if (processing_template_decl)
7562 : return false;
7563 :
7564 671 : for (; t; t = TREE_CHAIN (t))
7565 : {
7566 391 : tree decl = TREE_VALUE (t);
7567 391 : if (TYPE_PTR_P (TREE_TYPE (decl)))
7568 : {
7569 6 : tree offset = TREE_PURPOSE (t);
7570 6 : bool neg = wi::neg_p (wi::to_wide (offset));
7571 6 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
7572 6 : decl = mark_rvalue_use (decl);
7573 6 : decl = convert_from_reference (decl);
7574 12 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
7575 : neg ? MINUS_EXPR : PLUS_EXPR,
7576 : decl, offset);
7577 6 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
7578 : MINUS_EXPR, sizetype,
7579 : fold_convert (sizetype, t2),
7580 : fold_convert (sizetype, decl));
7581 6 : if (t2 == error_mark_node)
7582 : return true;
7583 6 : TREE_PURPOSE (t) = t2;
7584 : }
7585 : }
7586 : return false;
7587 : }
7588 :
7589 : /* Finish OpenMP iterators ITER. Return true if they are erroneous
7590 : and clauses containing them should be removed. */
7591 :
7592 : static bool
7593 615 : cp_omp_finish_iterators (tree iter)
7594 : {
7595 615 : bool ret = false;
7596 1395 : for (tree it = iter; it; it = TREE_CHAIN (it))
7597 : {
7598 780 : tree var = OMP_ITERATOR_VAR (it);
7599 780 : tree begin = OMP_ITERATOR_BEGIN (it);
7600 780 : tree end = OMP_ITERATOR_END (it);
7601 780 : tree step = OMP_ITERATOR_STEP (it);
7602 780 : tree orig_step;
7603 780 : tree type = TREE_TYPE (var);
7604 780 : location_t loc = DECL_SOURCE_LOCATION (var);
7605 780 : if (type == error_mark_node)
7606 : {
7607 0 : ret = true;
7608 218 : continue;
7609 : }
7610 780 : if (type_dependent_expression_p (var))
7611 59 : continue;
7612 721 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
7613 : {
7614 27 : error_at (loc, "iterator %qD has neither integral nor pointer type",
7615 : var);
7616 27 : ret = true;
7617 27 : continue;
7618 : }
7619 694 : else if (TYPE_READONLY (type))
7620 : {
7621 24 : error_at (loc, "iterator %qD has const qualified type", var);
7622 24 : ret = true;
7623 24 : continue;
7624 : }
7625 670 : if (type_dependent_expression_p (begin)
7626 661 : || type_dependent_expression_p (end)
7627 1331 : || type_dependent_expression_p (step))
7628 15 : continue;
7629 655 : else if (error_operand_p (step))
7630 : {
7631 0 : ret = true;
7632 0 : continue;
7633 : }
7634 655 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
7635 : {
7636 33 : error_at (EXPR_LOC_OR_LOC (step, loc),
7637 : "iterator step with non-integral type");
7638 21 : ret = true;
7639 21 : continue;
7640 : }
7641 :
7642 634 : begin = mark_rvalue_use (begin);
7643 634 : end = mark_rvalue_use (end);
7644 634 : step = mark_rvalue_use (step);
7645 634 : begin = cp_build_c_cast (input_location, type, begin,
7646 : tf_warning_or_error);
7647 634 : end = cp_build_c_cast (input_location, type, end,
7648 : tf_warning_or_error);
7649 634 : orig_step = step;
7650 634 : if (!processing_template_decl)
7651 557 : step = orig_step = save_expr (step);
7652 634 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
7653 634 : step = cp_build_c_cast (input_location, stype, step,
7654 : tf_warning_or_error);
7655 634 : if (POINTER_TYPE_P (type) && !processing_template_decl)
7656 : {
7657 66 : begin = save_expr (begin);
7658 66 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
7659 66 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
7660 : fold_convert (sizetype, step),
7661 : fold_convert (sizetype, begin));
7662 66 : step = fold_convert (ssizetype, step);
7663 : }
7664 634 : if (!processing_template_decl)
7665 : {
7666 557 : begin = maybe_constant_value (begin);
7667 557 : end = maybe_constant_value (end);
7668 557 : step = maybe_constant_value (step);
7669 557 : orig_step = maybe_constant_value (orig_step);
7670 : }
7671 634 : if (integer_zerop (step))
7672 : {
7673 27 : error_at (loc, "iterator %qD has zero step", var);
7674 27 : ret = true;
7675 27 : continue;
7676 : }
7677 :
7678 607 : if (begin == error_mark_node
7679 598 : || end == error_mark_node
7680 589 : || step == error_mark_node
7681 589 : || orig_step == error_mark_node)
7682 : {
7683 18 : ret = true;
7684 18 : continue;
7685 : }
7686 :
7687 589 : if (!processing_template_decl)
7688 : {
7689 512 : begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
7690 512 : end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
7691 512 : step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
7692 512 : orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
7693 : orig_step);
7694 : }
7695 589 : hash_set<tree> pset;
7696 589 : tree it2;
7697 745 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
7698 : {
7699 183 : tree var2 = OMP_ITERATOR_VAR (it2);
7700 183 : tree begin2 = OMP_ITERATOR_BEGIN (it2);
7701 183 : tree end2 = OMP_ITERATOR_END (it2);
7702 183 : tree step2 = OMP_ITERATOR_STEP (it2);
7703 183 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
7704 183 : if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
7705 : {
7706 9 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
7707 : "begin expression refers to outer iterator %qD", var);
7708 36 : break;
7709 : }
7710 174 : else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
7711 : {
7712 9 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
7713 : "end expression refers to outer iterator %qD", var);
7714 9 : break;
7715 : }
7716 165 : else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
7717 : {
7718 9 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
7719 : "step expression refers to outer iterator %qD", var);
7720 9 : break;
7721 : }
7722 : }
7723 589 : if (it2)
7724 : {
7725 27 : ret = true;
7726 27 : continue;
7727 : }
7728 562 : OMP_ITERATOR_BEGIN (it) = begin;
7729 562 : OMP_ITERATOR_END (it) = end;
7730 562 : if (processing_template_decl)
7731 71 : OMP_ITERATOR_STEP (it) = orig_step;
7732 : else
7733 : {
7734 491 : OMP_ITERATOR_STEP (it) = step;
7735 491 : OMP_ITERATOR_ORIG_STEP (it) = orig_step;
7736 : }
7737 589 : }
7738 615 : return ret;
7739 : }
7740 :
7741 : /* Ensure that pointers are used in OpenACC attach and detach clauses.
7742 : Return true if an error has been detected. */
7743 :
7744 : static bool
7745 18645 : cp_oacc_check_attachments (tree c)
7746 : {
7747 18645 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
7748 : return false;
7749 :
7750 : /* OpenACC attach / detach clauses must be pointers. */
7751 14666 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
7752 14666 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
7753 : {
7754 196 : tree t = OMP_CLAUSE_DECL (c);
7755 196 : tree type;
7756 :
7757 232 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7758 36 : t = TREE_OPERAND (t, 0);
7759 :
7760 196 : type = TREE_TYPE (t);
7761 :
7762 196 : if (TREE_CODE (type) == REFERENCE_TYPE)
7763 36 : type = TREE_TYPE (type);
7764 :
7765 196 : if (TREE_CODE (type) != POINTER_TYPE)
7766 : {
7767 36 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
7768 : user_omp_clause_code_name (c, true));
7769 36 : return true;
7770 : }
7771 : }
7772 :
7773 : return false;
7774 : }
7775 :
7776 : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
7777 : happened. */
7778 :
7779 : tree
7780 813 : cp_finish_omp_init_prefer_type (tree pref_type)
7781 : {
7782 813 : if (processing_template_decl
7783 741 : || pref_type == NULL_TREE
7784 356 : || TREE_CODE (pref_type) != TREE_LIST)
7785 : return pref_type;
7786 :
7787 81 : tree t = TREE_PURPOSE (pref_type);
7788 81 : char *str = const_cast<char *> (TREE_STRING_POINTER (t));
7789 81 : tree fr_list = TREE_VALUE (pref_type);
7790 81 : int len = TREE_VEC_LENGTH (fr_list);
7791 81 : int cnt = 0;
7792 :
7793 270 : while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
7794 : {
7795 270 : str++;
7796 270 : if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
7797 : {
7798 : /* Assume a no or a single 'fr'. */
7799 150 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7800 150 : location_t loc = UNKNOWN_LOCATION;
7801 150 : tree value = TREE_VEC_ELT (fr_list, cnt);
7802 150 : if (value != NULL_TREE && value != error_mark_node)
7803 : {
7804 126 : loc = EXPR_LOCATION (value);
7805 126 : if (value && TREE_CODE (value) == NOP_EXPR)
7806 39 : value = TREE_OPERAND (value, 0);
7807 126 : value = cp_fully_fold (value);
7808 : }
7809 126 : if (value != NULL_TREE && value != error_mark_node)
7810 : {
7811 126 : if (TREE_CODE (value) != INTEGER_CST
7812 126 : || !tree_fits_shwi_p (value))
7813 0 : error_at (loc,
7814 : "expected string literal or "
7815 : "constant integer expression instead of %qE", value);
7816 : else
7817 : {
7818 126 : HOST_WIDE_INT n = tree_to_shwi (value);
7819 126 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
7820 : {
7821 48 : warning_at (loc, OPT_Wopenmp,
7822 : "unknown foreign runtime identifier %qwd", n);
7823 48 : n = GOMP_INTEROP_IFR_UNKNOWN;
7824 : }
7825 126 : str[0] = (char) n;
7826 : }
7827 : }
7828 150 : str++;
7829 : }
7830 120 : else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
7831 : {
7832 : /* Assume a no or a single 'fr'. */
7833 120 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7834 120 : str++;
7835 : }
7836 270 : str++;
7837 294 : while (str[0] != '\0')
7838 24 : str += strlen (str) + 1;
7839 270 : str++;
7840 270 : cnt++;
7841 270 : if (cnt >= len)
7842 : break;
7843 : }
7844 : return t;
7845 : }
7846 :
7847 : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
7848 : Remove any elements from the list that are invalid. */
7849 :
7850 : tree
7851 62754 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
7852 : {
7853 62754 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
7854 62754 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
7855 62754 : bitmap_head oacc_reduction_head, is_on_device_head;
7856 62754 : tree c, t, *pc;
7857 62754 : tree safelen = NULL_TREE;
7858 62754 : bool openacc = (ort & C_ORT_ACC) != 0;
7859 62754 : bool branch_seen = false;
7860 62754 : bool copyprivate_seen = false;
7861 62754 : bool ordered_seen = false;
7862 62754 : bool order_seen = false;
7863 62754 : bool schedule_seen = false;
7864 62754 : bool oacc_async = false;
7865 62754 : bool indir_component_ref_p = false;
7866 62754 : tree last_iterators = NULL_TREE;
7867 62754 : bool last_iterators_remove = false;
7868 : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
7869 : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
7870 62754 : int reduction_seen = 0;
7871 62754 : bool allocate_seen = false;
7872 62754 : tree detach_seen = NULL_TREE;
7873 62754 : bool mergeable_seen = false;
7874 62754 : bool implicit_moved = false;
7875 62754 : bool target_in_reduction_seen = false;
7876 62754 : bool num_tasks_seen = false;
7877 62754 : bool partial_seen = false;
7878 62754 : bool init_seen = false;
7879 62754 : bool init_use_destroy_seen = false;
7880 62754 : tree init_no_targetsync_clause = NULL_TREE;
7881 62754 : tree depend_clause = NULL_TREE;
7882 :
7883 62754 : if (!openacc)
7884 50023 : clauses = omp_remove_duplicate_maps (clauses, true);
7885 :
7886 62754 : bitmap_obstack_initialize (NULL);
7887 62754 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
7888 62754 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
7889 62754 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
7890 62754 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
7891 : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
7892 62754 : bitmap_initialize (&map_head, &bitmap_default_obstack);
7893 62754 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
7894 62754 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
7895 : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
7896 : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
7897 62754 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
7898 62754 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
7899 :
7900 62754 : if (openacc)
7901 28275 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
7902 15932 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
7903 : {
7904 : oacc_async = true;
7905 : break;
7906 : }
7907 :
7908 62754 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
7909 :
7910 160726 : for (pc = &clauses, c = clauses; c ; c = *pc)
7911 : {
7912 97972 : bool remove = false;
7913 97972 : bool field_ok = false;
7914 :
7915 : /* We've reached the end of a list of expanded nodes. Reset the group
7916 : start pointer. */
7917 97972 : if (c == grp_sentinel)
7918 : {
7919 5668 : if (grp_start_p
7920 5668 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
7921 96 : for (tree gc = *grp_start_p; gc != grp_sentinel;
7922 66 : gc = OMP_CLAUSE_CHAIN (gc))
7923 66 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
7924 : grp_start_p = NULL;
7925 : }
7926 :
7927 97972 : switch (OMP_CLAUSE_CODE (c))
7928 : {
7929 2100 : case OMP_CLAUSE_SHARED:
7930 2100 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7931 2100 : goto check_dup_generic;
7932 2577 : case OMP_CLAUSE_PRIVATE:
7933 2577 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7934 2577 : goto check_dup_generic;
7935 7380 : case OMP_CLAUSE_REDUCTION:
7936 7380 : if (reduction_seen == 0)
7937 6261 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
7938 1119 : else if (reduction_seen != -2
7939 2238 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
7940 1119 : ? -1 : 1))
7941 : {
7942 6 : error_at (OMP_CLAUSE_LOCATION (c),
7943 : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
7944 : "on the same construct");
7945 6 : reduction_seen = -2;
7946 : }
7947 : /* FALLTHRU */
7948 9525 : case OMP_CLAUSE_IN_REDUCTION:
7949 9525 : case OMP_CLAUSE_TASK_REDUCTION:
7950 9525 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7951 9525 : t = OMP_CLAUSE_DECL (c);
7952 9525 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7953 : {
7954 2207 : if (handle_omp_array_sections (c, ort))
7955 : {
7956 : remove = true;
7957 : break;
7958 : }
7959 2165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
7960 2165 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
7961 : {
7962 3 : error_at (OMP_CLAUSE_LOCATION (c),
7963 : "%<inscan%> %<reduction%> clause with array "
7964 : "section");
7965 3 : remove = true;
7966 3 : break;
7967 : }
7968 2162 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7969 : {
7970 4672 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7971 2510 : t = TREE_OPERAND (t, 0);
7972 : }
7973 : else
7974 : {
7975 0 : gcc_assert (TREE_CODE (t) == MEM_REF);
7976 0 : t = TREE_OPERAND (t, 0);
7977 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
7978 0 : t = TREE_OPERAND (t, 0);
7979 0 : if (TREE_CODE (t) == ADDR_EXPR
7980 0 : || INDIRECT_REF_P (t))
7981 0 : t = TREE_OPERAND (t, 0);
7982 : }
7983 2162 : tree n = omp_clause_decl_field (t);
7984 2162 : if (n)
7985 59 : t = n;
7986 2162 : goto check_dup_generic_t;
7987 : }
7988 7318 : if (oacc_async)
7989 7 : cxx_mark_addressable (t);
7990 7318 : goto check_dup_generic;
7991 98 : case OMP_CLAUSE_COPYPRIVATE:
7992 98 : copyprivate_seen = true;
7993 98 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7994 98 : goto check_dup_generic;
7995 280 : case OMP_CLAUSE_COPYIN:
7996 280 : goto check_dup_generic;
7997 1631 : case OMP_CLAUSE_LINEAR:
7998 1631 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7999 1631 : t = OMP_CLAUSE_DECL (c);
8000 1631 : if (ort != C_ORT_OMP_DECLARE_SIMD
8001 1631 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
8002 : {
8003 84 : if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
8004 : {
8005 42 : error_at (OMP_CLAUSE_LOCATION (c),
8006 : "modifier should not be specified in %<linear%> "
8007 : "clause on %<simd%> or %<for%> constructs when "
8008 : "not using OpenMP 5.2 modifiers");
8009 42 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
8010 : }
8011 42 : else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
8012 : {
8013 18 : error_at (OMP_CLAUSE_LOCATION (c),
8014 : "modifier other than %<val%> specified in "
8015 : "%<linear%> clause on %<simd%> or %<for%> "
8016 : "constructs when using OpenMP 5.2 modifiers");
8017 18 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
8018 : }
8019 : }
8020 1011 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
8021 2571 : && !type_dependent_expression_p (t))
8022 : {
8023 1529 : tree type = TREE_TYPE (t);
8024 1529 : if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
8025 1448 : || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
8026 1598 : && !TYPE_REF_P (type))
8027 : {
8028 12 : error_at (OMP_CLAUSE_LOCATION (c),
8029 : "linear clause with %qs modifier applied to "
8030 : "non-reference variable with %qT type",
8031 12 : OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
8032 12 : ? "ref" : "uval", TREE_TYPE (t));
8033 12 : remove = true;
8034 12 : break;
8035 : }
8036 1517 : if (TYPE_REF_P (type))
8037 281 : type = TREE_TYPE (type);
8038 1517 : if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
8039 : {
8040 1442 : if (!INTEGRAL_TYPE_P (type)
8041 85 : && !TYPE_PTR_P (type))
8042 : {
8043 18 : error_at (OMP_CLAUSE_LOCATION (c),
8044 : "linear clause applied to non-integral "
8045 : "non-pointer variable with %qT type",
8046 18 : TREE_TYPE (t));
8047 18 : remove = true;
8048 18 : break;
8049 : }
8050 : }
8051 : }
8052 1601 : t = OMP_CLAUSE_LINEAR_STEP (c);
8053 1601 : if (t == NULL_TREE)
8054 6 : t = integer_one_node;
8055 1601 : if (t == error_mark_node)
8056 : {
8057 : remove = true;
8058 : break;
8059 : }
8060 1601 : else if (!type_dependent_expression_p (t)
8061 1599 : && !INTEGRAL_TYPE_P (TREE_TYPE (t))
8062 1613 : && (ort != C_ORT_OMP_DECLARE_SIMD
8063 9 : || TREE_CODE (t) != PARM_DECL
8064 6 : || !TYPE_REF_P (TREE_TYPE (t))
8065 6 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
8066 : {
8067 6 : error_at (OMP_CLAUSE_LOCATION (c),
8068 : "linear step expression must be integral");
8069 6 : remove = true;
8070 6 : break;
8071 : }
8072 : else
8073 : {
8074 1595 : t = mark_rvalue_use (t);
8075 1595 : if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
8076 : {
8077 42 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
8078 42 : goto check_dup_generic;
8079 : }
8080 1553 : if (!processing_template_decl
8081 1553 : && (VAR_P (OMP_CLAUSE_DECL (c))
8082 835 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
8083 : {
8084 1372 : if (ort == C_ORT_OMP_DECLARE_SIMD)
8085 : {
8086 589 : t = maybe_constant_value (t);
8087 589 : if (TREE_CODE (t) != INTEGER_CST)
8088 : {
8089 6 : error_at (OMP_CLAUSE_LOCATION (c),
8090 : "%<linear%> clause step %qE is neither "
8091 : "constant nor a parameter", t);
8092 6 : remove = true;
8093 6 : break;
8094 : }
8095 : }
8096 1366 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8097 1366 : tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
8098 1366 : if (TYPE_REF_P (type))
8099 257 : type = TREE_TYPE (type);
8100 1366 : if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
8101 : {
8102 66 : type = build_pointer_type (type);
8103 66 : tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
8104 66 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8105 : d, t);
8106 66 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8107 : MINUS_EXPR, sizetype,
8108 : fold_convert (sizetype, t),
8109 : fold_convert (sizetype, d));
8110 66 : if (t == error_mark_node)
8111 : {
8112 : remove = true;
8113 : break;
8114 : }
8115 : }
8116 1300 : else if (TYPE_PTR_P (type)
8117 : /* Can't multiply the step yet if *this
8118 : is still incomplete type. */
8119 1300 : && (ort != C_ORT_OMP_DECLARE_SIMD
8120 45 : || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
8121 45 : || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
8122 30 : || DECL_NAME (OMP_CLAUSE_DECL (c))
8123 30 : != this_identifier
8124 30 : || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
8125 : {
8126 37 : tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
8127 37 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8128 : d, t);
8129 37 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8130 : MINUS_EXPR, sizetype,
8131 : fold_convert (sizetype, t),
8132 : fold_convert (sizetype, d));
8133 37 : if (t == error_mark_node)
8134 : {
8135 : remove = true;
8136 : break;
8137 : }
8138 : }
8139 : else
8140 1263 : t = fold_convert (type, t);
8141 : }
8142 1547 : OMP_CLAUSE_LINEAR_STEP (c) = t;
8143 : }
8144 1547 : goto check_dup_generic;
8145 14928 : check_dup_generic:
8146 14928 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8147 14928 : if (t)
8148 : {
8149 101 : if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
8150 101 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8151 : }
8152 : else
8153 14827 : t = OMP_CLAUSE_DECL (c);
8154 17357 : check_dup_generic_t:
8155 17357 : if (t == current_class_ptr
8156 17357 : && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
8157 102 : || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
8158 72 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
8159 : {
8160 24 : error_at (OMP_CLAUSE_LOCATION (c),
8161 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8162 : " clauses");
8163 24 : remove = true;
8164 24 : break;
8165 : }
8166 17333 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8167 586 : && (!field_ok || TREE_CODE (t) != FIELD_DECL))
8168 : {
8169 59 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8170 : break;
8171 39 : if (DECL_P (t))
8172 30 : error_at (OMP_CLAUSE_LOCATION (c),
8173 : "%qD is not a variable in clause %qs", t,
8174 15 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8175 : else
8176 48 : error_at (OMP_CLAUSE_LOCATION (c),
8177 : "%qE is not a variable in clause %qs", t,
8178 24 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8179 : remove = true;
8180 : }
8181 17274 : else if ((openacc
8182 2707 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
8183 14805 : || (ort == C_ORT_OMP
8184 12476 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
8185 12445 : || (OMP_CLAUSE_CODE (c)
8186 : == OMP_CLAUSE_USE_DEVICE_ADDR)))
8187 31972 : || (ort == C_ORT_OMP_TARGET
8188 934 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
8189 : {
8190 2854 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
8191 2854 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8192 275 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
8193 : {
8194 6 : error_at (OMP_CLAUSE_LOCATION (c),
8195 : "%qD appears more than once in data-sharing "
8196 : "clauses", t);
8197 6 : remove = true;
8198 6 : break;
8199 : }
8200 2848 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
8201 272 : target_in_reduction_seen = true;
8202 2848 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8203 : {
8204 12 : error_at (OMP_CLAUSE_LOCATION (c),
8205 : openacc
8206 : ? "%qD appears more than once in reduction clauses"
8207 : : "%qD appears more than once in data clauses",
8208 : t);
8209 6 : remove = true;
8210 : }
8211 : else
8212 2842 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8213 : }
8214 14420 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8215 14347 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8216 14344 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
8217 28764 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8218 : {
8219 76 : error_at (OMP_CLAUSE_LOCATION (c),
8220 : "%qD appears more than once in data clauses", t);
8221 76 : remove = true;
8222 : }
8223 14344 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
8224 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
8225 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
8226 3118 : && bitmap_bit_p (&map_head, DECL_UID (t)))
8227 : {
8228 9 : if (openacc)
8229 0 : error_at (OMP_CLAUSE_LOCATION (c),
8230 : "%qD appears more than once in data clauses", t);
8231 : else
8232 9 : error_at (OMP_CLAUSE_LOCATION (c),
8233 : "%qD appears both in data and map clauses", t);
8234 : remove = true;
8235 : }
8236 : else
8237 14335 : bitmap_set_bit (&generic_head, DECL_UID (t));
8238 17307 : if (!field_ok)
8239 : break;
8240 12896 : handle_field_decl:
8241 21418 : if (!remove
8242 21223 : && TREE_CODE (t) == FIELD_DECL
8243 16540 : && t == OMP_CLAUSE_DECL (c))
8244 : {
8245 795 : OMP_CLAUSE_DECL (c)
8246 795 : = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
8247 : == OMP_CLAUSE_SHARED));
8248 795 : if (OMP_CLAUSE_DECL (c) == error_mark_node)
8249 97516 : remove = true;
8250 : }
8251 : break;
8252 :
8253 3476 : case OMP_CLAUSE_FIRSTPRIVATE:
8254 3476 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
8255 : {
8256 414 : move_implicit:
8257 414 : implicit_moved = true;
8258 : /* Move firstprivate and map clauses with
8259 : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
8260 : clauses chain. */
8261 414 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
8262 414 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
8263 2704 : while (*pc1)
8264 2290 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
8265 2290 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
8266 : {
8267 275 : *pc3 = *pc1;
8268 275 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
8269 275 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8270 : }
8271 2015 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
8272 2015 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
8273 : {
8274 370 : *pc2 = *pc1;
8275 370 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
8276 370 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8277 : }
8278 : else
8279 1645 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
8280 414 : *pc3 = NULL;
8281 414 : *pc2 = cl2;
8282 414 : *pc1 = cl1;
8283 414 : continue;
8284 414 : }
8285 3219 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8286 3219 : if (t)
8287 69 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8288 : else
8289 3150 : t = OMP_CLAUSE_DECL (c);
8290 3219 : if (!openacc && t == current_class_ptr)
8291 : {
8292 6 : error_at (OMP_CLAUSE_LOCATION (c),
8293 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8294 : " clauses");
8295 6 : remove = true;
8296 6 : break;
8297 : }
8298 3213 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8299 333 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8300 333 : || TREE_CODE (t) != FIELD_DECL))
8301 : {
8302 41 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8303 : break;
8304 18 : if (DECL_P (t))
8305 12 : error_at (OMP_CLAUSE_LOCATION (c),
8306 : "%qD is not a variable in clause %<firstprivate%>",
8307 : t);
8308 : else
8309 6 : error_at (OMP_CLAUSE_LOCATION (c),
8310 : "%qE is not a variable in clause %<firstprivate%>",
8311 : t);
8312 18 : remove = true;
8313 : }
8314 3172 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8315 275 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
8316 3426 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8317 : remove = true;
8318 3172 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8319 3163 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8320 6332 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8321 : {
8322 15 : error_at (OMP_CLAUSE_LOCATION (c),
8323 : "%qD appears more than once in data clauses", t);
8324 15 : remove = true;
8325 : }
8326 3157 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8327 3157 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
8328 : {
8329 21 : if (openacc)
8330 0 : error_at (OMP_CLAUSE_LOCATION (c),
8331 : "%qD appears more than once in data clauses", t);
8332 21 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8333 21 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
8334 : /* Silently drop the clause. */;
8335 : else
8336 18 : error_at (OMP_CLAUSE_LOCATION (c),
8337 : "%qD appears both in data and map clauses", t);
8338 21 : remove = true;
8339 : }
8340 : else
8341 3136 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
8342 3190 : goto handle_field_decl;
8343 :
8344 2793 : case OMP_CLAUSE_LASTPRIVATE:
8345 2793 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8346 2793 : if (t)
8347 35 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8348 : else
8349 2758 : t = OMP_CLAUSE_DECL (c);
8350 2793 : if (!openacc && t == current_class_ptr)
8351 : {
8352 6 : error_at (OMP_CLAUSE_LOCATION (c),
8353 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8354 : " clauses");
8355 6 : remove = true;
8356 6 : break;
8357 : }
8358 2787 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8359 259 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8360 259 : || TREE_CODE (t) != FIELD_DECL))
8361 : {
8362 35 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8363 : break;
8364 9 : if (DECL_P (t))
8365 3 : error_at (OMP_CLAUSE_LOCATION (c),
8366 : "%qD is not a variable in clause %<lastprivate%>",
8367 : t);
8368 : else
8369 6 : error_at (OMP_CLAUSE_LOCATION (c),
8370 : "%qE is not a variable in clause %<lastprivate%>",
8371 : t);
8372 9 : remove = true;
8373 : }
8374 2752 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8375 2752 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8376 : {
8377 12 : error_at (OMP_CLAUSE_LOCATION (c),
8378 : "%qD appears more than once in data clauses", t);
8379 12 : remove = true;
8380 : }
8381 : else
8382 2740 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
8383 2761 : goto handle_field_decl;
8384 :
8385 2221 : case OMP_CLAUSE_IF:
8386 2221 : case OMP_CLAUSE_SELF:
8387 2221 : t = OMP_CLAUSE_OPERAND (c, 0);
8388 2221 : t = maybe_convert_cond (t);
8389 2221 : if (t == error_mark_node)
8390 : remove = true;
8391 2206 : else if (!processing_template_decl)
8392 2145 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8393 2221 : OMP_CLAUSE_OPERAND (c, 0) = t;
8394 2221 : break;
8395 :
8396 289 : case OMP_CLAUSE_FINAL:
8397 289 : t = OMP_CLAUSE_FINAL_EXPR (c);
8398 289 : t = maybe_convert_cond (t);
8399 289 : if (t == error_mark_node)
8400 : remove = true;
8401 289 : else if (!processing_template_decl)
8402 283 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8403 289 : OMP_CLAUSE_FINAL_EXPR (c) = t;
8404 289 : break;
8405 :
8406 92 : case OMP_CLAUSE_NOCONTEXT:
8407 92 : t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
8408 92 : t = maybe_convert_cond (t);
8409 92 : if (t == error_mark_node)
8410 : remove = true;
8411 89 : else if (!processing_template_decl)
8412 83 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8413 92 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
8414 92 : break;
8415 :
8416 80 : case OMP_CLAUSE_NOVARIANTS:
8417 80 : t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
8418 80 : t = maybe_convert_cond (t);
8419 80 : if (t == error_mark_node)
8420 : remove = true;
8421 77 : else if (!processing_template_decl)
8422 71 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8423 80 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
8424 80 : break;
8425 :
8426 1249 : case OMP_CLAUSE_GANG:
8427 : /* Operand 1 is the gang static: argument. */
8428 1249 : t = OMP_CLAUSE_OPERAND (c, 1);
8429 1249 : if (t != NULL_TREE)
8430 : {
8431 129 : if (t == error_mark_node)
8432 : remove = true;
8433 129 : else if (!type_dependent_expression_p (t)
8434 129 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8435 : {
8436 6 : error_at (OMP_CLAUSE_LOCATION (c),
8437 : "%<gang%> static expression must be integral");
8438 6 : remove = true;
8439 : }
8440 : else
8441 : {
8442 123 : t = mark_rvalue_use (t);
8443 123 : if (!processing_template_decl)
8444 : {
8445 123 : t = maybe_constant_value (t);
8446 123 : if (TREE_CODE (t) == INTEGER_CST
8447 109 : && tree_int_cst_sgn (t) != 1
8448 176 : && t != integer_minus_one_node)
8449 : {
8450 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8451 : "%<gang%> static value must be "
8452 : "positive");
8453 0 : t = integer_one_node;
8454 : }
8455 123 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8456 : }
8457 : }
8458 129 : OMP_CLAUSE_OPERAND (c, 1) = t;
8459 : }
8460 : /* Check operand 0, the num argument. */
8461 : /* FALLTHRU */
8462 :
8463 3480 : case OMP_CLAUSE_WORKER:
8464 3480 : case OMP_CLAUSE_VECTOR:
8465 3480 : if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
8466 : break;
8467 : /* FALLTHRU */
8468 :
8469 484 : case OMP_CLAUSE_NUM_TASKS:
8470 484 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
8471 136 : num_tasks_seen = true;
8472 : /* FALLTHRU */
8473 :
8474 3034 : case OMP_CLAUSE_NUM_TEAMS:
8475 3034 : case OMP_CLAUSE_NUM_THREADS:
8476 3034 : case OMP_CLAUSE_NUM_GANGS:
8477 3034 : case OMP_CLAUSE_NUM_WORKERS:
8478 3034 : case OMP_CLAUSE_DYN_GROUPPRIVATE:
8479 3034 : case OMP_CLAUSE_VECTOR_LENGTH:
8480 3034 : t = OMP_CLAUSE_OPERAND (c, 0);
8481 3034 : if (t == error_mark_node)
8482 : remove = true;
8483 3034 : else if (!type_dependent_expression_p (t)
8484 3034 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8485 : {
8486 99 : switch (OMP_CLAUSE_CODE (c))
8487 : {
8488 12 : case OMP_CLAUSE_GANG:
8489 12 : error_at (OMP_CLAUSE_LOCATION (c),
8490 12 : "%<gang%> num expression must be integral"); break;
8491 12 : case OMP_CLAUSE_VECTOR:
8492 12 : error_at (OMP_CLAUSE_LOCATION (c),
8493 : "%<vector%> length expression must be integral");
8494 12 : break;
8495 12 : case OMP_CLAUSE_WORKER:
8496 12 : error_at (OMP_CLAUSE_LOCATION (c),
8497 : "%<worker%> num expression must be integral");
8498 12 : break;
8499 63 : default:
8500 63 : error_at (OMP_CLAUSE_LOCATION (c),
8501 : "%qs expression must be integral",
8502 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8503 : }
8504 : remove = true;
8505 : }
8506 : else
8507 : {
8508 2935 : t = mark_rvalue_use (t);
8509 2935 : if (!processing_template_decl)
8510 : {
8511 2687 : t = maybe_constant_value (t);
8512 2687 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
8513 2652 : && TREE_CODE (t) == INTEGER_CST
8514 4142 : && tree_int_cst_sgn (t) != 1)
8515 : {
8516 85 : switch (OMP_CLAUSE_CODE (c))
8517 : {
8518 3 : case OMP_CLAUSE_GANG:
8519 3 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8520 : "%<gang%> num value must be positive");
8521 3 : break;
8522 0 : case OMP_CLAUSE_VECTOR:
8523 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8524 : "%<vector%> length value must be "
8525 : "positive");
8526 0 : break;
8527 0 : case OMP_CLAUSE_WORKER:
8528 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8529 : "%<worker%> num value must be "
8530 : "positive");
8531 0 : break;
8532 82 : default:
8533 82 : warning_at (OMP_CLAUSE_LOCATION (c),
8534 46 : (flag_openmp || flag_openmp_simd)
8535 82 : ? OPT_Wopenmp : 0,
8536 : "%qs value must be positive",
8537 : omp_clause_code_name
8538 82 : [OMP_CLAUSE_CODE (c)]);
8539 : }
8540 85 : t = integer_one_node;
8541 : }
8542 2602 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
8543 35 : && TREE_CODE (t) == INTEGER_CST
8544 2625 : && tree_int_cst_sgn (t) < 0)
8545 : {
8546 8 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8547 : "%<dyn_groupprivate%> value must be "
8548 : "non-negative");
8549 8 : t = integer_zero_node;
8550 : }
8551 2687 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8552 : }
8553 2935 : OMP_CLAUSE_OPERAND (c, 0) = t;
8554 : }
8555 3034 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
8556 752 : && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
8557 3313 : && !remove)
8558 : {
8559 279 : t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
8560 279 : if (t == error_mark_node)
8561 : remove = true;
8562 279 : else if (!type_dependent_expression_p (t)
8563 279 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8564 : {
8565 0 : error_at (OMP_CLAUSE_LOCATION (c),
8566 : "%qs expression must be integral",
8567 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8568 0 : remove = true;
8569 : }
8570 : else
8571 : {
8572 279 : t = mark_rvalue_use (t);
8573 279 : if (!processing_template_decl)
8574 : {
8575 213 : t = maybe_constant_value (t);
8576 213 : if (TREE_CODE (t) == INTEGER_CST
8577 213 : && tree_int_cst_sgn (t) != 1)
8578 : {
8579 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8580 : "%qs value must be positive",
8581 : omp_clause_code_name
8582 18 : [OMP_CLAUSE_CODE (c)]);
8583 18 : t = NULL_TREE;
8584 : }
8585 : else
8586 195 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8587 213 : tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
8588 213 : if (t
8589 195 : && TREE_CODE (t) == INTEGER_CST
8590 43 : && TREE_CODE (upper) == INTEGER_CST
8591 250 : && tree_int_cst_lt (upper, t))
8592 : {
8593 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8594 : "%<num_teams%> lower bound %qE bigger "
8595 : "than upper bound %qE", t, upper);
8596 18 : t = NULL_TREE;
8597 : }
8598 : }
8599 279 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
8600 : }
8601 : }
8602 : break;
8603 :
8604 3886 : case OMP_CLAUSE_SCHEDULE:
8605 3886 : t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
8606 3886 : if (t == NULL)
8607 : ;
8608 2090 : else if (t == error_mark_node)
8609 : remove = true;
8610 2090 : else if (!type_dependent_expression_p (t)
8611 2090 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8612 : {
8613 9 : error_at (OMP_CLAUSE_LOCATION (c),
8614 : "schedule chunk size expression must be integral");
8615 9 : remove = true;
8616 : }
8617 : else
8618 : {
8619 2081 : t = mark_rvalue_use (t);
8620 2081 : if (!processing_template_decl)
8621 : {
8622 2041 : t = maybe_constant_value (t);
8623 2041 : if (TREE_CODE (t) == INTEGER_CST
8624 2041 : && tree_int_cst_sgn (t) != 1)
8625 : {
8626 6 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8627 : "chunk size value must be positive");
8628 6 : t = integer_one_node;
8629 : }
8630 2041 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8631 : }
8632 2081 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8633 : }
8634 2090 : if (!remove)
8635 : schedule_seen = true;
8636 : break;
8637 :
8638 1268 : case OMP_CLAUSE_SIMDLEN:
8639 1268 : case OMP_CLAUSE_SAFELEN:
8640 1268 : t = OMP_CLAUSE_OPERAND (c, 0);
8641 1268 : if (t == error_mark_node)
8642 : remove = true;
8643 1268 : else if (!type_dependent_expression_p (t)
8644 1268 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8645 : {
8646 0 : error_at (OMP_CLAUSE_LOCATION (c),
8647 : "%qs length expression must be integral",
8648 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8649 0 : remove = true;
8650 : }
8651 : else
8652 : {
8653 1268 : t = mark_rvalue_use (t);
8654 1268 : if (!processing_template_decl)
8655 : {
8656 1219 : t = maybe_constant_value (t);
8657 1219 : if (TREE_CODE (t) != INTEGER_CST
8658 1219 : || tree_int_cst_sgn (t) != 1)
8659 : {
8660 0 : error_at (OMP_CLAUSE_LOCATION (c),
8661 : "%qs length expression must be positive "
8662 : "constant integer expression",
8663 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8664 0 : remove = true;
8665 : }
8666 : }
8667 1268 : OMP_CLAUSE_OPERAND (c, 0) = t;
8668 1268 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
8669 470 : safelen = c;
8670 : }
8671 : break;
8672 :
8673 388 : case OMP_CLAUSE_ASYNC:
8674 388 : t = OMP_CLAUSE_ASYNC_EXPR (c);
8675 388 : if (t == error_mark_node)
8676 : remove = true;
8677 373 : else if (!type_dependent_expression_p (t)
8678 373 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8679 : {
8680 12 : error_at (OMP_CLAUSE_LOCATION (c),
8681 : "%<async%> expression must be integral");
8682 12 : remove = true;
8683 : }
8684 : else
8685 : {
8686 361 : t = mark_rvalue_use (t);
8687 361 : if (!processing_template_decl)
8688 352 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8689 361 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
8690 : }
8691 : break;
8692 :
8693 204 : case OMP_CLAUSE_WAIT:
8694 204 : t = OMP_CLAUSE_WAIT_EXPR (c);
8695 204 : if (t == error_mark_node)
8696 : remove = true;
8697 204 : else if (!processing_template_decl)
8698 196 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8699 204 : OMP_CLAUSE_WAIT_EXPR (c) = t;
8700 204 : break;
8701 :
8702 637 : case OMP_CLAUSE_THREAD_LIMIT:
8703 637 : t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
8704 637 : if (t == error_mark_node)
8705 : remove = true;
8706 637 : else if (!type_dependent_expression_p (t)
8707 637 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8708 : {
8709 0 : error_at (OMP_CLAUSE_LOCATION (c),
8710 : "%<thread_limit%> expression must be integral");
8711 0 : remove = true;
8712 : }
8713 : else
8714 : {
8715 637 : t = mark_rvalue_use (t);
8716 637 : if (!processing_template_decl)
8717 : {
8718 583 : t = maybe_constant_value (t);
8719 583 : if (TREE_CODE (t) == INTEGER_CST
8720 583 : && tree_int_cst_sgn (t) != 1)
8721 : {
8722 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8723 : "%<thread_limit%> value must be positive");
8724 0 : t = integer_one_node;
8725 : }
8726 583 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8727 : }
8728 637 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
8729 : }
8730 : break;
8731 :
8732 770 : case OMP_CLAUSE_DEVICE:
8733 770 : t = OMP_CLAUSE_DEVICE_ID (c);
8734 770 : if (t == error_mark_node)
8735 : remove = true;
8736 770 : else if (!type_dependent_expression_p (t)
8737 770 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8738 : {
8739 6 : error_at (OMP_CLAUSE_LOCATION (c),
8740 : "%<device%> id must be integral");
8741 6 : remove = true;
8742 : }
8743 764 : else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
8744 66 : && TREE_CODE (t) == INTEGER_CST
8745 824 : && !integer_onep (t))
8746 : {
8747 3 : error_at (OMP_CLAUSE_LOCATION (c),
8748 : "the %<device%> clause expression must evaluate to "
8749 : "%<1%>");
8750 3 : remove = true;
8751 : }
8752 : else
8753 : {
8754 761 : t = mark_rvalue_use (t);
8755 761 : if (!processing_template_decl)
8756 750 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8757 761 : OMP_CLAUSE_DEVICE_ID (c) = t;
8758 : }
8759 : break;
8760 :
8761 1845 : case OMP_CLAUSE_DIST_SCHEDULE:
8762 1845 : t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
8763 1845 : if (t == NULL)
8764 : ;
8765 1824 : else if (t == error_mark_node)
8766 : remove = true;
8767 1824 : else if (!type_dependent_expression_p (t)
8768 1824 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8769 : {
8770 0 : error_at (OMP_CLAUSE_LOCATION (c),
8771 : "%<dist_schedule%> chunk size expression must be "
8772 : "integral");
8773 0 : remove = true;
8774 : }
8775 : else
8776 : {
8777 1824 : t = mark_rvalue_use (t);
8778 1824 : if (!processing_template_decl)
8779 1824 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8780 1824 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
8781 : }
8782 : break;
8783 :
8784 807 : case OMP_CLAUSE_ALIGNED:
8785 807 : t = OMP_CLAUSE_DECL (c);
8786 807 : if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
8787 : {
8788 0 : error_at (OMP_CLAUSE_LOCATION (c),
8789 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8790 : " clauses");
8791 0 : remove = true;
8792 0 : break;
8793 : }
8794 807 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8795 : {
8796 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8797 : break;
8798 0 : if (DECL_P (t))
8799 0 : error_at (OMP_CLAUSE_LOCATION (c),
8800 : "%qD is not a variable in %<aligned%> clause", t);
8801 : else
8802 0 : error_at (OMP_CLAUSE_LOCATION (c),
8803 : "%qE is not a variable in %<aligned%> clause", t);
8804 : remove = true;
8805 : }
8806 807 : else if (!type_dependent_expression_p (t)
8807 789 : && !TYPE_PTR_P (TREE_TYPE (t))
8808 111 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
8809 864 : && (!TYPE_REF_P (TREE_TYPE (t))
8810 39 : || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
8811 30 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
8812 : != ARRAY_TYPE))))
8813 : {
8814 33 : error_at (OMP_CLAUSE_LOCATION (c),
8815 : "%qE in %<aligned%> clause is neither a pointer nor "
8816 : "an array nor a reference to pointer or array", t);
8817 33 : remove = true;
8818 : }
8819 774 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8820 : {
8821 0 : error_at (OMP_CLAUSE_LOCATION (c),
8822 : "%qD appears more than once in %<aligned%> clauses",
8823 : t);
8824 0 : remove = true;
8825 : }
8826 : else
8827 774 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8828 807 : t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
8829 807 : if (t == error_mark_node)
8830 : remove = true;
8831 807 : else if (t == NULL_TREE)
8832 : break;
8833 744 : else if (!type_dependent_expression_p (t)
8834 744 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8835 : {
8836 0 : error_at (OMP_CLAUSE_LOCATION (c),
8837 : "%<aligned%> clause alignment expression must "
8838 : "be integral");
8839 0 : remove = true;
8840 : }
8841 : else
8842 : {
8843 744 : t = mark_rvalue_use (t);
8844 744 : if (!processing_template_decl)
8845 : {
8846 690 : t = maybe_constant_value (t);
8847 690 : if (TREE_CODE (t) != INTEGER_CST
8848 690 : || tree_int_cst_sgn (t) != 1)
8849 : {
8850 0 : error_at (OMP_CLAUSE_LOCATION (c),
8851 : "%<aligned%> clause alignment expression must "
8852 : "be positive constant integer expression");
8853 0 : remove = true;
8854 : }
8855 : }
8856 744 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
8857 : }
8858 : break;
8859 :
8860 369 : case OMP_CLAUSE_NONTEMPORAL:
8861 369 : t = OMP_CLAUSE_DECL (c);
8862 369 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8863 : {
8864 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8865 : break;
8866 0 : if (DECL_P (t))
8867 0 : error_at (OMP_CLAUSE_LOCATION (c),
8868 : "%qD is not a variable in %<nontemporal%> clause",
8869 : t);
8870 : else
8871 0 : error_at (OMP_CLAUSE_LOCATION (c),
8872 : "%qE is not a variable in %<nontemporal%> clause",
8873 : t);
8874 : remove = true;
8875 : }
8876 369 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8877 : {
8878 6 : error_at (OMP_CLAUSE_LOCATION (c),
8879 : "%qD appears more than once in %<nontemporal%> "
8880 : "clauses", t);
8881 6 : remove = true;
8882 : }
8883 : else
8884 363 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8885 : break;
8886 :
8887 2587 : case OMP_CLAUSE_ALLOCATE:
8888 2587 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8889 2587 : if (t)
8890 14 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8891 : else
8892 2573 : t = OMP_CLAUSE_DECL (c);
8893 2587 : if (t == current_class_ptr)
8894 : {
8895 0 : error_at (OMP_CLAUSE_LOCATION (c),
8896 : "%<this%> not allowed in %<allocate%> clause");
8897 0 : remove = true;
8898 0 : break;
8899 : }
8900 2587 : if (!VAR_P (t)
8901 558 : && TREE_CODE (t) != PARM_DECL
8902 45 : && TREE_CODE (t) != FIELD_DECL)
8903 : {
8904 3 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8905 : break;
8906 3 : if (DECL_P (t))
8907 3 : error_at (OMP_CLAUSE_LOCATION (c),
8908 : "%qD is not a variable in %<allocate%> clause", t);
8909 : else
8910 0 : error_at (OMP_CLAUSE_LOCATION (c),
8911 : "%qE is not a variable in %<allocate%> clause", t);
8912 : remove = true;
8913 : }
8914 2584 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8915 : {
8916 12 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8917 : "%qD appears more than once in %<allocate%> clauses",
8918 : t);
8919 12 : remove = true;
8920 : }
8921 : else
8922 : {
8923 2572 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8924 2572 : allocate_seen = true;
8925 : }
8926 2587 : tree allocator, align;
8927 2587 : align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
8928 2587 : if (error_operand_p (align))
8929 : {
8930 : remove = true;
8931 : break;
8932 : }
8933 2587 : if (align)
8934 : {
8935 211 : if (!type_dependent_expression_p (align)
8936 211 : && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
8937 : {
8938 4 : error_at (OMP_CLAUSE_LOCATION (c),
8939 : "%<allocate%> clause %<align%> modifier "
8940 : "argument needs to be positive constant "
8941 : "power of two integer expression");
8942 4 : remove = true;
8943 : }
8944 : else
8945 : {
8946 207 : align = mark_rvalue_use (align);
8947 207 : if (!processing_template_decl)
8948 : {
8949 192 : align = maybe_constant_value (align);
8950 192 : if (TREE_CODE (align) != INTEGER_CST
8951 189 : || !tree_fits_uhwi_p (align)
8952 381 : || !integer_pow2p (align))
8953 : {
8954 10 : error_at (OMP_CLAUSE_LOCATION (c),
8955 : "%<allocate%> clause %<align%> modifier "
8956 : "argument needs to be positive constant "
8957 : "power of two integer expression");
8958 10 : remove = true;
8959 : }
8960 : }
8961 : }
8962 211 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
8963 : }
8964 2587 : allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
8965 2587 : if (error_operand_p (allocator))
8966 : {
8967 : remove = true;
8968 : break;
8969 : }
8970 2587 : if (allocator == NULL_TREE)
8971 1537 : goto handle_field_decl;
8972 1050 : tree allocatort;
8973 1050 : allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
8974 1050 : if (!type_dependent_expression_p (allocator)
8975 1050 : && (TREE_CODE (allocatort) != ENUMERAL_TYPE
8976 1031 : || TYPE_NAME (allocatort) == NULL_TREE
8977 1031 : || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
8978 2062 : || (DECL_NAME (TYPE_NAME (allocatort))
8979 1031 : != get_identifier ("omp_allocator_handle_t"))
8980 1031 : || (TYPE_CONTEXT (allocatort)
8981 1031 : != DECL_CONTEXT (global_namespace))))
8982 : {
8983 16 : error_at (OMP_CLAUSE_LOCATION (c),
8984 : "%<allocate%> clause allocator expression has "
8985 : "type %qT rather than %<omp_allocator_handle_t%>",
8986 16 : TREE_TYPE (allocator));
8987 16 : remove = true;
8988 16 : break;
8989 : }
8990 : else
8991 : {
8992 1034 : allocator = mark_rvalue_use (allocator);
8993 1034 : if (!processing_template_decl)
8994 1015 : allocator = maybe_constant_value (allocator);
8995 1034 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
8996 : }
8997 1034 : goto handle_field_decl;
8998 :
8999 654 : case OMP_CLAUSE_DOACROSS:
9000 654 : t = OMP_CLAUSE_DECL (c);
9001 654 : if (t == NULL_TREE)
9002 : break;
9003 298 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
9004 : {
9005 298 : if (cp_finish_omp_clause_doacross_sink (c))
9006 4 : remove = true;
9007 : break;
9008 : }
9009 0 : gcc_unreachable ();
9010 73 : case OMP_CLAUSE_USES_ALLOCATORS:
9011 73 : t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
9012 73 : t = convert_from_reference (t);
9013 73 : if (t == error_mark_node)
9014 : {
9015 : remove = true;
9016 : break;
9017 : }
9018 69 : if (DECL_P (t)
9019 69 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
9020 66 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9021 65 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
9022 : {
9023 1 : error_at (OMP_CLAUSE_LOCATION (c),
9024 : "%qE appears more than once in data clauses", t);
9025 1 : remove = true;
9026 : }
9027 68 : else if (DECL_P (t))
9028 65 : bitmap_set_bit (&generic_head, DECL_UID (t));
9029 69 : if (type_dependent_expression_p (t))
9030 : break;
9031 64 : if (TREE_CODE (t) == FIELD_DECL)
9032 : {
9033 0 : sorry_at (OMP_CLAUSE_LOCATION (c), "class member %qE not yet "
9034 : "supported in %<uses_allocators%> clause", t);
9035 0 : remove = true;
9036 0 : break;
9037 : }
9038 64 : if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9039 125 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9040 : "omp_allocator_handle_t") != 0)
9041 : {
9042 3 : error_at (OMP_CLAUSE_LOCATION (c),
9043 : "allocator %qE must be of %<omp_allocator_handle_t%> "
9044 : "type", t);
9045 3 : remove = true;
9046 3 : break;
9047 : }
9048 61 : tree init;
9049 61 : if (TREE_CODE (t) == CONST_DECL)
9050 7 : init = DECL_INITIAL(t);
9051 : else
9052 : init = t;
9053 61 : if (!DECL_P (t)
9054 61 : && (init == NULL_TREE
9055 3 : || TREE_CODE (init) != INTEGER_CST
9056 3 : || ((wi::to_widest (init) < 0
9057 3 : || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
9058 1 : && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
9059 1 : || (wi::to_widest (init)
9060 2 : > GOMP_OMPX_PREDEF_ALLOC_MAX)))))
9061 : {
9062 1 : remove = true;
9063 1 : error_at (OMP_CLAUSE_LOCATION (c),
9064 : "allocator %qE must be either a variable or a "
9065 : "predefined allocator", t);
9066 1 : break;
9067 : }
9068 60 : else if (TREE_CODE (t) == CONST_DECL)
9069 : {
9070 : /* omp_null_allocator is ignored and for predefined allocators,
9071 : not special handling is required; thus, remove them removed. */
9072 7 : remove = true;
9073 :
9074 7 : if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
9075 7 : || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
9076 : {
9077 0 : error_at (OMP_CLAUSE_LOCATION (c),
9078 : "modifiers cannot be used with predefined "
9079 : "allocators");
9080 0 : break;
9081 : }
9082 : }
9083 60 : t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
9084 60 : if (t == error_mark_node)
9085 : {
9086 : remove = true;
9087 : break;
9088 : }
9089 59 : if (t != NULL_TREE
9090 9 : && !type_dependent_expression_p (t)
9091 68 : && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
9092 8 : || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9093 14 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9094 : "omp_memspace_handle_t") != 0))
9095 : {
9096 2 : error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
9097 : " constant enum of %<omp_memspace_handle_t%> type", t);
9098 2 : remove = true;
9099 2 : break;
9100 : }
9101 57 : t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
9102 57 : if (t == error_mark_node)
9103 : {
9104 : remove = true;
9105 : break;
9106 : }
9107 56 : if (type_dependent_expression_p (t))
9108 : break;
9109 56 : if (t != NULL_TREE
9110 28 : && t != error_mark_node
9111 28 : && !type_dependent_expression_p (t)
9112 84 : && (!DECL_P (t)
9113 28 : || DECL_EXTERNAL (t)
9114 26 : || TREE_CODE (t) == PARM_DECL))
9115 : {
9116 4 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
9117 : "defined in same scope as the construct on which the "
9118 : "clause appears", t);
9119 4 : remove = true;
9120 : }
9121 56 : if (t != NULL_TREE)
9122 : {
9123 28 : bool type_err = false;
9124 :
9125 28 : if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
9126 26 : || DECL_SIZE (t) == NULL_TREE
9127 53 : || !COMPLETE_TYPE_P (TREE_TYPE (t)))
9128 : type_err = true;
9129 : else
9130 : {
9131 25 : tree elem_t = TREE_TYPE (TREE_TYPE (t));
9132 25 : if (TREE_CODE (elem_t) != RECORD_TYPE
9133 50 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
9134 : "omp_alloctrait_t") != 0
9135 50 : || !TYPE_READONLY (elem_t))
9136 : type_err = true;
9137 : }
9138 24 : if (type_err)
9139 : {
9140 4 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
9141 : "be of %<const omp_alloctrait_t []%> type", t);
9142 4 : remove = true;
9143 : }
9144 24 : else if (TREE_CODE (array_type_nelts_top (TREE_TYPE (t)))
9145 : != INTEGER_CST)
9146 : {
9147 1 : error_at (OMP_CLAUSE_LOCATION (c), "variable length traits "
9148 : "arrays are not supported");
9149 1 : remove = true;
9150 : }
9151 : else
9152 : {
9153 23 : tree cst_val = decl_constant_value (t);
9154 23 : if (cst_val == t)
9155 : {
9156 1 : error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
9157 : "initialized with constants");
9158 1 : remove = true;
9159 : }
9160 : }
9161 : }
9162 56 : if (remove)
9163 : break;
9164 42 : pc = &OMP_CLAUSE_CHAIN (c);
9165 42 : continue;
9166 1807 : case OMP_CLAUSE_DEPEND:
9167 1807 : depend_clause = c;
9168 : /* FALLTHRU */
9169 2173 : case OMP_CLAUSE_AFFINITY:
9170 2173 : t = OMP_CLAUSE_DECL (c);
9171 2173 : if (OMP_ITERATOR_DECL_P (t))
9172 : {
9173 623 : if (TREE_PURPOSE (t) != last_iterators)
9174 525 : last_iterators_remove
9175 525 : = cp_omp_finish_iterators (TREE_PURPOSE (t));
9176 623 : last_iterators = TREE_PURPOSE (t);
9177 623 : t = TREE_VALUE (t);
9178 623 : if (last_iterators_remove)
9179 144 : t = error_mark_node;
9180 : }
9181 : else
9182 : last_iterators = NULL_TREE;
9183 :
9184 2173 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9185 : {
9186 1165 : if (handle_omp_array_sections (c, ort))
9187 : remove = true;
9188 914 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9189 914 : && (OMP_CLAUSE_DEPEND_KIND (c)
9190 : == OMP_CLAUSE_DEPEND_DEPOBJ))
9191 : {
9192 6 : error_at (OMP_CLAUSE_LOCATION (c),
9193 : "%<depend%> clause with %<depobj%> dependence "
9194 : "type on array section");
9195 6 : remove = true;
9196 : }
9197 : break;
9198 : }
9199 1008 : if (t == error_mark_node)
9200 : remove = true;
9201 846 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9202 846 : && t == ridpointers[RID_OMP_ALL_MEMORY])
9203 : {
9204 33 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
9205 33 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
9206 : {
9207 9 : error_at (OMP_CLAUSE_LOCATION (c),
9208 : "%<omp_all_memory%> used with %<depend%> kind "
9209 : "other than %<out%> or %<inout%>");
9210 9 : remove = true;
9211 : }
9212 33 : if (processing_template_decl)
9213 : break;
9214 : }
9215 813 : else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9216 : break;
9217 621 : else if (!lvalue_p (t))
9218 : {
9219 19 : if (DECL_P (t))
9220 24 : error_at (OMP_CLAUSE_LOCATION (c),
9221 : "%qD is not lvalue expression nor array section "
9222 : "in %qs clause", t,
9223 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9224 : else
9225 14 : error_at (OMP_CLAUSE_LOCATION (c),
9226 : "%qE is not lvalue expression nor array section "
9227 : "in %qs clause", t,
9228 7 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9229 : remove = true;
9230 : }
9231 602 : else if (TREE_CODE (t) == COMPONENT_REF
9232 24 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
9233 626 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
9234 : {
9235 8 : error_at (OMP_CLAUSE_LOCATION (c),
9236 : "bit-field %qE in %qs clause", t,
9237 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9238 4 : remove = true;
9239 : }
9240 598 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9241 598 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
9242 : {
9243 130 : if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9244 8 : ? TREE_TYPE (TREE_TYPE (t))
9245 57 : : TREE_TYPE (t)))
9246 : {
9247 12 : error_at (OMP_CLAUSE_LOCATION (c),
9248 : "%qE does not have %<omp_depend_t%> type in "
9249 : "%<depend%> clause with %<depobj%> dependence "
9250 : "type", t);
9251 12 : remove = true;
9252 : }
9253 : }
9254 533 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9255 974 : && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9256 4 : ? TREE_TYPE (TREE_TYPE (t))
9257 437 : : TREE_TYPE (t)))
9258 : {
9259 15 : error_at (OMP_CLAUSE_LOCATION (c),
9260 : "%qE should not have %<omp_depend_t%> type in "
9261 : "%<depend%> clause with dependence type other than "
9262 : "%<depobj%>", t);
9263 15 : remove = true;
9264 : }
9265 64 : if (!remove)
9266 : {
9267 595 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
9268 24 : t = null_pointer_node;
9269 : else
9270 : {
9271 571 : tree addr = cp_build_addr_expr (t, tf_warning_or_error);
9272 571 : if (addr == error_mark_node)
9273 : {
9274 : remove = true;
9275 : break;
9276 : }
9277 571 : t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
9278 : addr, RO_UNARY_STAR,
9279 : tf_warning_or_error);
9280 571 : if (t == error_mark_node)
9281 : {
9282 : remove = true;
9283 : break;
9284 : }
9285 : }
9286 595 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
9287 137 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
9288 732 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
9289 : == TREE_VEC))
9290 137 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
9291 : else
9292 458 : OMP_CLAUSE_DECL (c) = t;
9293 : }
9294 : break;
9295 69 : case OMP_CLAUSE_DETACH:
9296 69 : t = OMP_CLAUSE_DECL (c);
9297 69 : if (detach_seen)
9298 : {
9299 3 : error_at (OMP_CLAUSE_LOCATION (c),
9300 : "too many %qs clauses on a task construct",
9301 : "detach");
9302 3 : remove = true;
9303 3 : break;
9304 : }
9305 66 : else if (error_operand_p (t))
9306 : {
9307 : remove = true;
9308 : break;
9309 : }
9310 : else
9311 : {
9312 63 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
9313 63 : if (!type_dependent_expression_p (t)
9314 63 : && (!INTEGRAL_TYPE_P (type)
9315 : || TREE_CODE (type) != ENUMERAL_TYPE
9316 51 : || TYPE_NAME (type) == NULL_TREE
9317 102 : || (DECL_NAME (TYPE_NAME (type))
9318 51 : != get_identifier ("omp_event_handle_t"))))
9319 : {
9320 6 : error_at (OMP_CLAUSE_LOCATION (c),
9321 : "%<detach%> clause event handle "
9322 : "has type %qT rather than "
9323 : "%<omp_event_handle_t%>",
9324 : type);
9325 6 : remove = true;
9326 : }
9327 63 : detach_seen = c;
9328 63 : cxx_mark_addressable (t);
9329 : }
9330 63 : break;
9331 :
9332 16197 : case OMP_CLAUSE_MAP:
9333 16197 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
9334 157 : goto move_implicit;
9335 16040 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
9336 16040 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
9337 : {
9338 : remove = true;
9339 : break;
9340 : }
9341 : /* FALLTHRU */
9342 19218 : case OMP_CLAUSE_TO:
9343 19218 : case OMP_CLAUSE_FROM:
9344 19218 : if (OMP_CLAUSE_ITERATORS (c)
9345 19218 : && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
9346 : {
9347 97516 : t = error_mark_node;
9348 : break;
9349 : }
9350 : /* FALLTHRU */
9351 20054 : case OMP_CLAUSE__CACHE_:
9352 20054 : {
9353 20054 : using namespace omp_addr_tokenizer;
9354 20054 : auto_vec<omp_addr_token *, 10> addr_tokens;
9355 :
9356 20054 : t = OMP_CLAUSE_DECL (c);
9357 20054 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9358 : {
9359 5879 : grp_start_p = pc;
9360 5879 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9361 :
9362 5879 : if (handle_omp_array_sections (c, ort))
9363 : remove = true;
9364 : else
9365 : {
9366 5113 : t = OMP_CLAUSE_DECL (c);
9367 5113 : if (TREE_CODE (t) != OMP_ARRAY_SECTION
9368 4256 : && !type_dependent_expression_p (t)
9369 9369 : && !omp_mappable_type (TREE_TYPE (t)))
9370 : {
9371 3 : auto_diagnostic_group d;
9372 6 : error_at (OMP_CLAUSE_LOCATION (c),
9373 : "array section does not have mappable type "
9374 : "in %qs clause",
9375 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9376 3 : if (TREE_TYPE (t) != error_mark_node
9377 3 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9378 3 : cxx_incomplete_type_inform (TREE_TYPE (t));
9379 3 : remove = true;
9380 3 : }
9381 6963 : while (TREE_CODE (t) == ARRAY_REF)
9382 1850 : t = TREE_OPERAND (t, 0);
9383 :
9384 5113 : if (type_dependent_expression_p (t))
9385 : break;
9386 :
9387 4639 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9388 :
9389 4639 : if (!ai.map_supported_p ()
9390 4639 : || !omp_parse_expr (addr_tokens, t))
9391 : {
9392 18 : sorry_at (OMP_CLAUSE_LOCATION (c),
9393 : "unsupported map expression %qE",
9394 9 : OMP_CLAUSE_DECL (c));
9395 9 : remove = true;
9396 9 : break;
9397 : }
9398 :
9399 : /* This check is to determine if this will be the only map
9400 : node created for this clause. Otherwise, we'll check
9401 : the following FIRSTPRIVATE_POINTER,
9402 : FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
9403 : iteration(s) of the loop. */
9404 9211 : if (addr_tokens.length () >= 4
9405 1063 : && addr_tokens[0]->type == STRUCTURE_BASE
9406 1057 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
9407 1057 : && addr_tokens[1]->type == ACCESS_METHOD
9408 1057 : && addr_tokens[2]->type == COMPONENT_SELECTOR
9409 977 : && addr_tokens[3]->type == ACCESS_METHOD
9410 5344 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
9411 551 : || (addr_tokens[3]->u.access_kind
9412 : == ACCESS_INDEXED_ARRAY)))
9413 : {
9414 165 : tree rt = addr_tokens[1]->expr;
9415 :
9416 165 : gcc_assert (DECL_P (rt));
9417 :
9418 165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9419 154 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9420 165 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
9421 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
9422 0 : || bitmap_bit_p (&map_firstprivate_head,
9423 0 : DECL_UID (rt))))
9424 : {
9425 : remove = true;
9426 : break;
9427 : }
9428 165 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
9429 : break;
9430 116 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
9431 : {
9432 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9433 0 : error_at (OMP_CLAUSE_LOCATION (c),
9434 : "%qD appears more than once in motion"
9435 : " clauses", rt);
9436 0 : else if (openacc)
9437 0 : error_at (OMP_CLAUSE_LOCATION (c),
9438 : "%qD appears more than once in data"
9439 : " clauses", rt);
9440 : else
9441 0 : error_at (OMP_CLAUSE_LOCATION (c),
9442 : "%qD appears more than once in map"
9443 : " clauses", rt);
9444 : remove = true;
9445 : }
9446 : else
9447 : {
9448 116 : bitmap_set_bit (&map_head, DECL_UID (rt));
9449 116 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
9450 : }
9451 : }
9452 4639 : }
9453 5347 : if (cp_oacc_check_attachments (c))
9454 12 : remove = true;
9455 5347 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9456 4413 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9457 4349 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9458 5445 : && !OMP_CLAUSE_SIZE (c))
9459 : /* In this case, we have a single array element which is a
9460 : pointer, and we already set OMP_CLAUSE_SIZE in
9461 : handle_omp_array_sections above. For attach/detach
9462 : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
9463 : to zero here. */
9464 60 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9465 : break;
9466 : }
9467 14175 : else if (type_dependent_expression_p (t))
9468 : break;
9469 13392 : else if (!omp_parse_expr (addr_tokens, t))
9470 : {
9471 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
9472 : "unsupported map expression %qE",
9473 0 : OMP_CLAUSE_DECL (c));
9474 0 : remove = true;
9475 0 : break;
9476 : }
9477 13392 : if (t == error_mark_node)
9478 : {
9479 : remove = true;
9480 : break;
9481 : }
9482 : /* OpenACC attach / detach clauses must be pointers. */
9483 13298 : if (cp_oacc_check_attachments (c))
9484 : {
9485 : remove = true;
9486 : break;
9487 : }
9488 13274 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9489 10229 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9490 10180 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9491 13348 : && !OMP_CLAUSE_SIZE (c))
9492 : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
9493 : bias) to zero here, so it is not set erroneously to the
9494 : pointer size later on in gimplify.cc. */
9495 66 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9496 :
9497 13274 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9498 :
9499 13274 : if (!ai.check_clause (c))
9500 : {
9501 : remove = true;
9502 : break;
9503 : }
9504 :
9505 13253 : if (!ai.map_supported_p ())
9506 : {
9507 88 : sorry_at (OMP_CLAUSE_LOCATION (c),
9508 : "unsupported map expression %qE",
9509 44 : OMP_CLAUSE_DECL (c));
9510 44 : remove = true;
9511 44 : break;
9512 : }
9513 :
9514 26418 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
9515 : || addr_tokens[0]->type == STRUCTURE_BASE)
9516 : && addr_tokens[1]->type == ACCESS_METHOD);
9517 :
9518 13209 : t = addr_tokens[1]->expr;
9519 :
9520 : /* This is used to prevent cxx_mark_addressable from being called
9521 : on 'this' for expressions like 'this->a', i.e. typical member
9522 : accesses. */
9523 13209 : indir_component_ref_p
9524 26418 : = (addr_tokens[0]->type == STRUCTURE_BASE
9525 13209 : && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
9526 :
9527 13209 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
9528 1 : goto skip_decl_checks;
9529 :
9530 : /* For OpenMP, we can access a struct "t" and "t.d" on the same
9531 : mapping. OpenACC allows multiple fields of the same structure
9532 : to be written. */
9533 13208 : if (addr_tokens[0]->type == STRUCTURE_BASE
9534 13208 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
9535 1263 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
9536 1351 : goto skip_decl_checks;
9537 :
9538 11857 : if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
9539 : {
9540 0 : OMP_CLAUSE_DECL (c)
9541 0 : = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
9542 0 : break;
9543 : }
9544 11857 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9545 : {
9546 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9547 : break;
9548 0 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9549 0 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9550 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
9551 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
9552 0 : || (!openacc && EXPR_P (t))))
9553 : break;
9554 0 : if (DECL_P (t))
9555 0 : error_at (OMP_CLAUSE_LOCATION (c),
9556 : "%qD is not a variable in %qs clause", t,
9557 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9558 : else
9559 0 : error_at (OMP_CLAUSE_LOCATION (c),
9560 : "%qE is not a variable in %qs clause", t,
9561 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9562 : remove = true;
9563 : }
9564 11857 : else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
9565 : {
9566 0 : error_at (OMP_CLAUSE_LOCATION (c),
9567 : "%qD is threadprivate variable in %qs clause", t,
9568 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9569 0 : remove = true;
9570 : }
9571 11857 : else if (!processing_template_decl
9572 11681 : && !TYPE_REF_P (TREE_TYPE (t))
9573 11004 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9574 8069 : || (OMP_CLAUSE_MAP_KIND (c)
9575 : != GOMP_MAP_FIRSTPRIVATE_POINTER))
9576 9047 : && !indir_component_ref_p
9577 8683 : && (t != current_class_ptr
9578 18 : || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9579 6 : || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
9580 20540 : && !cxx_mark_addressable (t))
9581 : remove = true;
9582 11857 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9583 8904 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9584 8904 : || (OMP_CLAUSE_MAP_KIND (c)
9585 : == GOMP_MAP_FIRSTPRIVATE_POINTER)
9586 6947 : || (OMP_CLAUSE_MAP_KIND (c)
9587 : == GOMP_MAP_ATTACH_DETACH)))
9588 9240 : && t == OMP_CLAUSE_DECL (c)
9589 8542 : && !type_dependent_expression_p (t)
9590 28941 : && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
9591 278 : ? TREE_TYPE (TREE_TYPE (t))
9592 8264 : : TREE_TYPE (t)))
9593 : {
9594 42 : auto_diagnostic_group d;
9595 84 : error_at (OMP_CLAUSE_LOCATION (c),
9596 : "%qD does not have a mappable type in %qs clause", t,
9597 42 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9598 42 : if (TREE_TYPE (t) != error_mark_node
9599 42 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9600 39 : cxx_incomplete_type_inform (TREE_TYPE (t));
9601 42 : remove = true;
9602 42 : }
9603 11815 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9604 8868 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
9605 93 : && !type_dependent_expression_p (t)
9606 11908 : && !INDIRECT_TYPE_P (TREE_TYPE (t)))
9607 : {
9608 6 : error_at (OMP_CLAUSE_LOCATION (c),
9609 : "%qD is not a pointer variable", t);
9610 6 : remove = true;
9611 : }
9612 11809 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9613 8862 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9614 12179 : && (bitmap_bit_p (&map_head, DECL_UID (t))
9615 367 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
9616 367 : || bitmap_bit_p (&map_firstprivate_head,
9617 367 : DECL_UID (t))))
9618 : remove = true;
9619 11803 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9620 11803 : && (OMP_CLAUSE_MAP_KIND (c)
9621 : == GOMP_MAP_FIRSTPRIVATE_POINTER))
9622 : {
9623 1951 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
9624 1951 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9625 3899 : || (openacc
9626 1362 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
9627 : {
9628 12 : error_at (OMP_CLAUSE_LOCATION (c),
9629 : "%qD appears more than once in data clauses", t);
9630 12 : remove = true;
9631 : }
9632 1939 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9633 12 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9634 1947 : && openacc)
9635 : {
9636 3 : error_at (OMP_CLAUSE_LOCATION (c),
9637 : "%qD appears more than once in data clauses", t);
9638 3 : remove = true;
9639 : }
9640 : else
9641 1936 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9642 : }
9643 9852 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9644 9852 : && (OMP_CLAUSE_MAP_KIND (c)
9645 : == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
9646 115 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9647 9737 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9648 181 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9649 38 : && ort != C_ORT_OMP
9650 38 : && ort != C_ORT_OMP_TARGET
9651 9753 : && ort != C_ORT_OMP_EXIT_DATA)
9652 : {
9653 9 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9654 0 : error_at (OMP_CLAUSE_LOCATION (c),
9655 : "%qD appears more than once in motion clauses", t);
9656 9 : else if (openacc)
9657 9 : error_at (OMP_CLAUSE_LOCATION (c),
9658 : "%qD appears more than once in data clauses", t);
9659 : else
9660 0 : error_at (OMP_CLAUSE_LOCATION (c),
9661 : "%qD appears more than once in map clauses", t);
9662 : remove = true;
9663 : }
9664 9728 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
9665 : {
9666 0 : error_at (OMP_CLAUSE_LOCATION (c),
9667 : "%qD appears more than once in data clauses", t);
9668 0 : remove = true;
9669 : }
9670 9728 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9671 9728 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
9672 : {
9673 27 : if (openacc)
9674 0 : error_at (OMP_CLAUSE_LOCATION (c),
9675 : "%qD appears more than once in data clauses", t);
9676 : else
9677 27 : error_at (OMP_CLAUSE_LOCATION (c),
9678 : "%qD appears both in data and map clauses", t);
9679 : remove = true;
9680 : }
9681 9701 : else if (!omp_access_chain_p (addr_tokens, 1))
9682 : {
9683 9621 : bitmap_set_bit (&map_head, DECL_UID (t));
9684 :
9685 9621 : tree decl = OMP_CLAUSE_DECL (c);
9686 9621 : if (t != decl
9687 9621 : && (TREE_CODE (decl) == COMPONENT_REF
9688 162 : || (INDIRECT_REF_P (decl)
9689 162 : && (TREE_CODE (TREE_OPERAND (decl, 0))
9690 : == COMPONENT_REF)
9691 150 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
9692 : 0))))))
9693 1165 : bitmap_set_bit (&map_field_head, DECL_UID (t));
9694 : }
9695 :
9696 4631 : skip_decl_checks:
9697 : /* If we call ai.expand_map_clause in handle_omp_array_sections,
9698 : the containing loop (here) iterates through the new nodes
9699 : created by that expansion. Avoid expanding those again (just
9700 : by checking the node type). */
9701 4631 : if (!remove
9702 13104 : && !processing_template_decl
9703 12931 : && ort != C_ORT_DECLARE_SIMD
9704 12931 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9705 9904 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
9706 7968 : && (OMP_CLAUSE_MAP_KIND (c)
9707 : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
9708 7853 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
9709 7853 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
9710 6854 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
9711 6805 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
9712 : {
9713 9807 : grp_start_p = pc;
9714 9807 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9715 9807 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
9716 : addr_tokens, ort);
9717 9807 : if (nc != error_mark_node)
9718 9807 : c = nc;
9719 : }
9720 20119 : }
9721 13209 : break;
9722 :
9723 596 : case OMP_CLAUSE_ENTER:
9724 596 : case OMP_CLAUSE_LINK:
9725 596 : t = OMP_CLAUSE_DECL (c);
9726 596 : const char *cname;
9727 596 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
9728 596 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
9729 596 : && OMP_CLAUSE_ENTER_TO (c))
9730 : cname = "to";
9731 596 : if (TREE_CODE (t) == FUNCTION_DECL
9732 596 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9733 : ;
9734 379 : else if (!VAR_P (t))
9735 : {
9736 12 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9737 : {
9738 9 : if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
9739 6 : error_at (OMP_CLAUSE_LOCATION (c),
9740 : "template %qE in clause %qs", t, cname);
9741 3 : else if (really_overloaded_fn (t))
9742 3 : error_at (OMP_CLAUSE_LOCATION (c),
9743 : "overloaded function name %qE in clause %qs", t,
9744 : cname);
9745 : else
9746 0 : error_at (OMP_CLAUSE_LOCATION (c),
9747 : "%qE is neither a variable nor a function name "
9748 : "in clause %qs", t, cname);
9749 : }
9750 : else
9751 3 : error_at (OMP_CLAUSE_LOCATION (c),
9752 : "%qE is not a variable in clause %qs", t, cname);
9753 : remove = true;
9754 : }
9755 367 : else if (DECL_THREAD_LOCAL_P (t))
9756 : {
9757 6 : error_at (OMP_CLAUSE_LOCATION (c),
9758 : "%qD is threadprivate variable in %qs clause", t,
9759 : cname);
9760 6 : remove = true;
9761 : }
9762 361 : else if (!omp_mappable_type (TREE_TYPE (t)))
9763 : {
9764 18 : auto_diagnostic_group d;
9765 18 : error_at (OMP_CLAUSE_LOCATION (c),
9766 : "%qD does not have a mappable type in %qs clause", t,
9767 : cname);
9768 18 : if (TREE_TYPE (t) != error_mark_node
9769 18 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9770 18 : cxx_incomplete_type_inform (TREE_TYPE (t));
9771 18 : remove = true;
9772 18 : }
9773 24 : if (remove)
9774 : break;
9775 560 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9776 : {
9777 24 : error_at (OMP_CLAUSE_LOCATION (c),
9778 : "%qE appears more than once on the same "
9779 : "%<declare target%> directive", t);
9780 24 : remove = true;
9781 : }
9782 : else
9783 536 : bitmap_set_bit (&generic_head, DECL_UID (t));
9784 : break;
9785 :
9786 457 : case OMP_CLAUSE_UNIFORM:
9787 457 : t = OMP_CLAUSE_DECL (c);
9788 457 : if (TREE_CODE (t) != PARM_DECL)
9789 : {
9790 0 : if (processing_template_decl)
9791 : break;
9792 0 : if (DECL_P (t))
9793 0 : error_at (OMP_CLAUSE_LOCATION (c),
9794 : "%qD is not an argument in %<uniform%> clause", t);
9795 : else
9796 0 : error_at (OMP_CLAUSE_LOCATION (c),
9797 : "%qE is not an argument in %<uniform%> clause", t);
9798 : remove = true;
9799 : break;
9800 : }
9801 : /* map_head bitmap is used as uniform_head if declare_simd. */
9802 457 : bitmap_set_bit (&map_head, DECL_UID (t));
9803 457 : goto check_dup_generic;
9804 :
9805 165 : case OMP_CLAUSE_GRAINSIZE:
9806 165 : t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
9807 165 : if (t == error_mark_node)
9808 : remove = true;
9809 165 : else if (!type_dependent_expression_p (t)
9810 165 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9811 : {
9812 0 : error_at (OMP_CLAUSE_LOCATION (c),
9813 : "%<grainsize%> expression must be integral");
9814 0 : remove = true;
9815 : }
9816 : else
9817 : {
9818 165 : t = mark_rvalue_use (t);
9819 165 : if (!processing_template_decl)
9820 : {
9821 164 : t = maybe_constant_value (t);
9822 164 : if (TREE_CODE (t) == INTEGER_CST
9823 164 : && tree_int_cst_sgn (t) != 1)
9824 : {
9825 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9826 : "%<grainsize%> value must be positive");
9827 0 : t = integer_one_node;
9828 : }
9829 164 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9830 : }
9831 165 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
9832 : }
9833 : break;
9834 :
9835 276 : case OMP_CLAUSE_PRIORITY:
9836 276 : t = OMP_CLAUSE_PRIORITY_EXPR (c);
9837 276 : if (t == error_mark_node)
9838 : remove = true;
9839 276 : else if (!type_dependent_expression_p (t)
9840 276 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9841 : {
9842 0 : error_at (OMP_CLAUSE_LOCATION (c),
9843 : "%<priority%> expression must be integral");
9844 0 : remove = true;
9845 : }
9846 : else
9847 : {
9848 276 : t = mark_rvalue_use (t);
9849 276 : if (!processing_template_decl)
9850 : {
9851 276 : t = maybe_constant_value (t);
9852 276 : if (TREE_CODE (t) == INTEGER_CST
9853 276 : && tree_int_cst_sgn (t) == -1)
9854 : {
9855 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9856 : "%<priority%> value must be non-negative");
9857 0 : t = integer_one_node;
9858 : }
9859 276 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9860 : }
9861 276 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
9862 : }
9863 : break;
9864 :
9865 228 : case OMP_CLAUSE_HINT:
9866 228 : t = OMP_CLAUSE_HINT_EXPR (c);
9867 228 : if (t == error_mark_node)
9868 : remove = true;
9869 228 : else if (!type_dependent_expression_p (t)
9870 228 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9871 : {
9872 9 : error_at (OMP_CLAUSE_LOCATION (c),
9873 : "%<hint%> expression must be integral");
9874 9 : remove = true;
9875 : }
9876 : else
9877 : {
9878 219 : t = mark_rvalue_use (t);
9879 219 : if (!processing_template_decl)
9880 : {
9881 171 : t = maybe_constant_value (t);
9882 171 : if (TREE_CODE (t) != INTEGER_CST)
9883 : {
9884 16 : error_at (OMP_CLAUSE_LOCATION (c),
9885 : "%<hint%> expression must be constant integer "
9886 : "expression");
9887 16 : remove = true;
9888 : }
9889 : }
9890 219 : OMP_CLAUSE_HINT_EXPR (c) = t;
9891 : }
9892 : break;
9893 :
9894 186 : case OMP_CLAUSE_FILTER:
9895 186 : t = OMP_CLAUSE_FILTER_EXPR (c);
9896 186 : if (t == error_mark_node)
9897 : remove = true;
9898 186 : else if (!type_dependent_expression_p (t)
9899 186 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9900 : {
9901 6 : error_at (OMP_CLAUSE_LOCATION (c),
9902 : "%<filter%> expression must be integral");
9903 6 : remove = true;
9904 : }
9905 : else
9906 : {
9907 180 : t = mark_rvalue_use (t);
9908 180 : if (!processing_template_decl)
9909 : {
9910 177 : t = maybe_constant_value (t);
9911 177 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9912 : }
9913 180 : OMP_CLAUSE_FILTER_EXPR (c) = t;
9914 : }
9915 : break;
9916 :
9917 433 : case OMP_CLAUSE_IS_DEVICE_PTR:
9918 433 : case OMP_CLAUSE_USE_DEVICE_PTR:
9919 433 : field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
9920 433 : t = OMP_CLAUSE_DECL (c);
9921 433 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
9922 329 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9923 433 : if (!type_dependent_expression_p (t))
9924 : {
9925 431 : tree type = TREE_TYPE (t);
9926 431 : if (!TYPE_PTR_P (type)
9927 431 : && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
9928 : {
9929 57 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
9930 57 : && ort == C_ORT_OMP)
9931 : {
9932 3 : error_at (OMP_CLAUSE_LOCATION (c),
9933 : "%qs variable is neither a pointer "
9934 : "nor reference to pointer",
9935 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9936 3 : remove = true;
9937 : }
9938 54 : else if (TREE_CODE (type) != ARRAY_TYPE
9939 54 : && (!TYPE_REF_P (type)
9940 2 : || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
9941 : {
9942 12 : error_at (OMP_CLAUSE_LOCATION (c),
9943 : "%qs variable is neither a pointer, nor an "
9944 : "array nor reference to pointer or array",
9945 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9946 12 : remove = true;
9947 : }
9948 : }
9949 : }
9950 433 : goto check_dup_generic;
9951 :
9952 267 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
9953 267 : t = OMP_CLAUSE_DECL (c);
9954 267 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9955 : {
9956 28 : if (handle_omp_array_sections (c, ort))
9957 : remove = true;
9958 : else
9959 : {
9960 28 : t = OMP_CLAUSE_DECL (c);
9961 30 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
9962 2 : t = TREE_OPERAND (t, 0);
9963 64 : while (INDIRECT_REF_P (t)
9964 64 : || TREE_CODE (t) == ARRAY_REF)
9965 36 : t = TREE_OPERAND (t, 0);
9966 : }
9967 : }
9968 267 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9969 : {
9970 267 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9971 267 : if (!processing_template_decl
9972 267 : && !cxx_mark_addressable (t))
9973 : remove = true;
9974 : }
9975 267 : goto check_dup_generic_t;
9976 :
9977 76 : case OMP_CLAUSE_USE_DEVICE_ADDR:
9978 76 : field_ok = true;
9979 76 : t = OMP_CLAUSE_DECL (c);
9980 76 : if (!processing_template_decl
9981 74 : && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9982 74 : && !TYPE_REF_P (TREE_TYPE (t))
9983 143 : && !cxx_mark_addressable (t))
9984 : remove = true;
9985 76 : goto check_dup_generic;
9986 :
9987 : case OMP_CLAUSE_NOWAIT:
9988 : case OMP_CLAUSE_DEFAULT:
9989 : case OMP_CLAUSE_UNTIED:
9990 : case OMP_CLAUSE_COLLAPSE:
9991 : case OMP_CLAUSE_PARALLEL:
9992 : case OMP_CLAUSE_FOR:
9993 : case OMP_CLAUSE_SECTIONS:
9994 : case OMP_CLAUSE_TASKGROUP:
9995 : case OMP_CLAUSE_PROC_BIND:
9996 : case OMP_CLAUSE_DEVICE_TYPE:
9997 : case OMP_CLAUSE_NOGROUP:
9998 : case OMP_CLAUSE_THREADS:
9999 : case OMP_CLAUSE_SIMD:
10000 : case OMP_CLAUSE_DEFAULTMAP:
10001 : case OMP_CLAUSE_BIND:
10002 : case OMP_CLAUSE_AUTO:
10003 : case OMP_CLAUSE_INDEPENDENT:
10004 : case OMP_CLAUSE_SEQ:
10005 : case OMP_CLAUSE_IF_PRESENT:
10006 : case OMP_CLAUSE_FINALIZE:
10007 : case OMP_CLAUSE_NOHOST:
10008 : case OMP_CLAUSE_INDIRECT:
10009 : break;
10010 :
10011 231 : case OMP_CLAUSE_MERGEABLE:
10012 231 : mergeable_seen = true;
10013 231 : break;
10014 :
10015 322 : case OMP_CLAUSE_TILE:
10016 754 : for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
10017 432 : list = TREE_CHAIN (list))
10018 : {
10019 432 : t = TREE_VALUE (list);
10020 :
10021 432 : if (t == error_mark_node)
10022 : remove = true;
10023 403 : else if (!type_dependent_expression_p (t)
10024 403 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10025 : {
10026 3 : error_at (OMP_CLAUSE_LOCATION (c),
10027 : "%<tile%> argument needs integral type");
10028 3 : remove = true;
10029 : }
10030 : else
10031 : {
10032 400 : t = mark_rvalue_use (t);
10033 400 : if (!processing_template_decl)
10034 : {
10035 : /* Zero is used to indicate '*', we permit you
10036 : to get there via an ICE of value zero. */
10037 385 : t = maybe_constant_value (t);
10038 385 : if (!tree_fits_shwi_p (t)
10039 369 : || tree_to_shwi (t) < 0)
10040 : {
10041 40 : error_at (OMP_CLAUSE_LOCATION (c),
10042 : "%<tile%> argument needs positive "
10043 : "integral constant");
10044 40 : remove = true;
10045 : }
10046 : }
10047 : }
10048 :
10049 : /* Update list item. */
10050 432 : TREE_VALUE (list) = t;
10051 : }
10052 : break;
10053 :
10054 1027 : case OMP_CLAUSE_SIZES:
10055 1027 : for (tree list = OMP_CLAUSE_SIZES_LIST (c);
10056 2688 : !remove && list; list = TREE_CHAIN (list))
10057 : {
10058 1661 : t = TREE_VALUE (list);
10059 :
10060 1661 : if (t == error_mark_node)
10061 0 : t = integer_one_node;
10062 1661 : else if (!type_dependent_expression_p (t)
10063 1661 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10064 : {
10065 8 : error_at (OMP_CLAUSE_LOCATION (c),
10066 : "%<sizes%> argument needs positive integral "
10067 : "constant");
10068 8 : t = integer_one_node;
10069 : }
10070 : else
10071 : {
10072 1653 : t = mark_rvalue_use (t);
10073 1653 : if (!processing_template_decl)
10074 : {
10075 1636 : t = maybe_constant_value (t);
10076 1636 : HOST_WIDE_INT n;
10077 1636 : if (!tree_fits_shwi_p (t)
10078 1632 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
10079 1632 : || (n = tree_to_shwi (t)) <= 0
10080 3240 : || (int)n != n)
10081 : {
10082 32 : error_at (OMP_CLAUSE_LOCATION (c),
10083 : "%<sizes%> argument needs positive "
10084 : "integral constant");
10085 32 : t = integer_one_node;
10086 : }
10087 : }
10088 : }
10089 :
10090 : /* Update list item. */
10091 1661 : TREE_VALUE (list) = t;
10092 : }
10093 : break;
10094 :
10095 630 : case OMP_CLAUSE_ORDERED:
10096 630 : ordered_seen = true;
10097 630 : break;
10098 :
10099 1549 : case OMP_CLAUSE_ORDER:
10100 1549 : if (order_seen)
10101 : remove = true;
10102 : else
10103 : order_seen = true;
10104 : break;
10105 :
10106 638 : case OMP_CLAUSE_INBRANCH:
10107 638 : case OMP_CLAUSE_NOTINBRANCH:
10108 638 : if (branch_seen)
10109 : {
10110 3 : error_at (OMP_CLAUSE_LOCATION (c),
10111 : "%<inbranch%> clause is incompatible with "
10112 : "%<notinbranch%>");
10113 3 : remove = true;
10114 : }
10115 : branch_seen = true;
10116 : break;
10117 :
10118 300 : case OMP_CLAUSE_INCLUSIVE:
10119 300 : case OMP_CLAUSE_EXCLUSIVE:
10120 300 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10121 300 : if (!t)
10122 300 : t = OMP_CLAUSE_DECL (c);
10123 300 : if (t == current_class_ptr)
10124 : {
10125 0 : error_at (OMP_CLAUSE_LOCATION (c),
10126 : "%<this%> allowed in OpenMP only in %<declare simd%>"
10127 : " clauses");
10128 0 : remove = true;
10129 0 : break;
10130 : }
10131 300 : if (!VAR_P (t)
10132 : && TREE_CODE (t) != PARM_DECL
10133 : && TREE_CODE (t) != FIELD_DECL)
10134 : {
10135 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
10136 : break;
10137 0 : if (DECL_P (t))
10138 0 : error_at (OMP_CLAUSE_LOCATION (c),
10139 : "%qD is not a variable in clause %qs", t,
10140 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10141 : else
10142 0 : error_at (OMP_CLAUSE_LOCATION (c),
10143 : "%qE is not a variable in clause %qs", t,
10144 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10145 : remove = true;
10146 : }
10147 : break;
10148 :
10149 : case OMP_CLAUSE_FULL:
10150 : break;
10151 :
10152 470 : case OMP_CLAUSE_PARTIAL:
10153 470 : partial_seen = true;
10154 470 : t = OMP_CLAUSE_PARTIAL_EXPR (c);
10155 470 : if (!t)
10156 : break;
10157 :
10158 313 : if (t == error_mark_node)
10159 : t = NULL_TREE;
10160 313 : else if (!type_dependent_expression_p (t)
10161 313 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10162 : {
10163 3 : error_at (OMP_CLAUSE_LOCATION (c),
10164 : "%<partial%> argument needs positive constant "
10165 : "integer expression");
10166 3 : t = NULL_TREE;
10167 : }
10168 : else
10169 : {
10170 310 : t = mark_rvalue_use (t);
10171 310 : if (!processing_template_decl)
10172 : {
10173 292 : t = maybe_constant_value (t);
10174 :
10175 292 : HOST_WIDE_INT n;
10176 584 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
10177 292 : || !tree_fits_shwi_p (t)
10178 286 : || (n = tree_to_shwi (t)) <= 0
10179 560 : || (int)n != n)
10180 : {
10181 24 : error_at (OMP_CLAUSE_LOCATION (c),
10182 : "%<partial%> argument needs positive "
10183 : "constant integer expression");
10184 24 : t = NULL_TREE;
10185 : }
10186 : }
10187 : }
10188 :
10189 313 : OMP_CLAUSE_PARTIAL_EXPR (c) = t;
10190 313 : break;
10191 549 : case OMP_CLAUSE_INIT:
10192 549 : init_seen = true;
10193 549 : OMP_CLAUSE_INIT_PREFER_TYPE (c)
10194 549 : = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
10195 549 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
10196 271 : init_no_targetsync_clause = c;
10197 : /* FALLTHRU */
10198 844 : case OMP_CLAUSE_DESTROY:
10199 844 : case OMP_CLAUSE_USE:
10200 844 : init_use_destroy_seen = true;
10201 844 : t = OMP_CLAUSE_DECL (c);
10202 844 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
10203 : {
10204 9 : error_at (OMP_CLAUSE_LOCATION (c),
10205 : "%qD appears more than once in action clauses", t);
10206 9 : remove = true;
10207 9 : break;
10208 : }
10209 835 : bitmap_set_bit (&generic_head, DECL_UID (t));
10210 : /* FALLTHRU */
10211 1099 : case OMP_CLAUSE_INTEROP:
10212 1099 : if (!processing_template_decl)
10213 : {
10214 1003 : if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
10215 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) && */
10216 1003 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
10217 : {
10218 126 : error_at (OMP_CLAUSE_LOCATION (c),
10219 : "%qD must be of %<omp_interop_t%>",
10220 63 : OMP_CLAUSE_DECL (c));
10221 63 : remove = true;
10222 : }
10223 940 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
10224 481 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
10225 1058 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
10226 : {
10227 36 : error_at (OMP_CLAUSE_LOCATION (c),
10228 18 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
10229 18 : remove = true;
10230 : }
10231 : }
10232 1099 : pc = &OMP_CLAUSE_CHAIN (c);
10233 1099 : break;
10234 0 : default:
10235 0 : gcc_unreachable ();
10236 42 : }
10237 :
10238 97516 : if (remove)
10239 : {
10240 2532 : if (grp_start_p)
10241 : {
10242 : /* If we found a clause to remove, we want to remove the whole
10243 : expanded group, otherwise gimplify
10244 : (omp_resolve_clause_dependencies) can get confused. */
10245 817 : *grp_start_p = grp_sentinel;
10246 817 : pc = grp_start_p;
10247 817 : grp_start_p = NULL;
10248 : }
10249 : else
10250 1715 : *pc = OMP_CLAUSE_CHAIN (c);
10251 : }
10252 : else
10253 94984 : pc = &OMP_CLAUSE_CHAIN (c);
10254 : }
10255 :
10256 62754 : if (grp_start_p
10257 62754 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
10258 140 : for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
10259 86 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
10260 :
10261 62754 : if (reduction_seen < 0 && (ordered_seen || schedule_seen))
10262 62754 : reduction_seen = -2;
10263 :
10264 158690 : for (pc = &clauses, c = clauses; c ; c = *pc)
10265 : {
10266 95936 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
10267 95936 : bool remove = false;
10268 95936 : bool need_complete_type = false;
10269 95936 : bool need_default_ctor = false;
10270 95936 : bool need_copy_ctor = false;
10271 95936 : bool need_copy_assignment = false;
10272 95936 : bool need_implicitly_determined = false;
10273 95936 : bool need_dtor = false;
10274 95936 : tree type, inner_type;
10275 :
10276 95936 : switch (c_kind)
10277 : {
10278 : case OMP_CLAUSE_SHARED:
10279 : need_implicitly_determined = true;
10280 : break;
10281 2543 : case OMP_CLAUSE_PRIVATE:
10282 2543 : need_complete_type = true;
10283 2543 : need_default_ctor = true;
10284 2543 : need_dtor = true;
10285 2543 : need_implicitly_determined = true;
10286 2543 : break;
10287 3159 : case OMP_CLAUSE_FIRSTPRIVATE:
10288 3159 : need_complete_type = true;
10289 3159 : need_copy_ctor = true;
10290 3159 : need_dtor = true;
10291 3159 : need_implicitly_determined = true;
10292 3159 : break;
10293 2766 : case OMP_CLAUSE_LASTPRIVATE:
10294 2766 : need_complete_type = true;
10295 2766 : need_copy_assignment = true;
10296 2766 : need_implicitly_determined = true;
10297 2766 : break;
10298 7329 : case OMP_CLAUSE_REDUCTION:
10299 7329 : if (reduction_seen == -2)
10300 27 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
10301 7329 : if (OMP_CLAUSE_REDUCTION_INSCAN (c))
10302 424 : need_copy_assignment = true;
10303 : need_implicitly_determined = true;
10304 : break;
10305 : case OMP_CLAUSE_IN_REDUCTION:
10306 : case OMP_CLAUSE_TASK_REDUCTION:
10307 : case OMP_CLAUSE_INCLUSIVE:
10308 : case OMP_CLAUSE_EXCLUSIVE:
10309 : need_implicitly_determined = true;
10310 : break;
10311 1550 : case OMP_CLAUSE_LINEAR:
10312 1550 : if (ort != C_ORT_OMP_DECLARE_SIMD)
10313 : need_implicitly_determined = true;
10314 679 : else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
10315 721 : && !bitmap_bit_p (&map_head,
10316 42 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
10317 : {
10318 6 : error_at (OMP_CLAUSE_LOCATION (c),
10319 : "%<linear%> clause step is a parameter %qD not "
10320 : "specified in %<uniform%> clause",
10321 6 : OMP_CLAUSE_LINEAR_STEP (c));
10322 6 : *pc = OMP_CLAUSE_CHAIN (c);
10323 74352 : continue;
10324 : }
10325 : break;
10326 : case OMP_CLAUSE_COPYPRIVATE:
10327 369 : need_copy_assignment = true;
10328 : break;
10329 : case OMP_CLAUSE_COPYIN:
10330 369 : need_copy_assignment = true;
10331 : break;
10332 798 : case OMP_CLAUSE_SIMDLEN:
10333 798 : if (safelen
10334 345 : && !processing_template_decl
10335 1143 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
10336 345 : OMP_CLAUSE_SIMDLEN_EXPR (c)))
10337 : {
10338 0 : error_at (OMP_CLAUSE_LOCATION (c),
10339 : "%<simdlen%> clause value is bigger than "
10340 : "%<safelen%> clause value");
10341 0 : OMP_CLAUSE_SIMDLEN_EXPR (c)
10342 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
10343 : }
10344 798 : pc = &OMP_CLAUSE_CHAIN (c);
10345 798 : continue;
10346 3877 : case OMP_CLAUSE_SCHEDULE:
10347 3877 : if (ordered_seen
10348 3877 : && (OMP_CLAUSE_SCHEDULE_KIND (c)
10349 : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
10350 : {
10351 21 : error_at (OMP_CLAUSE_LOCATION (c),
10352 : "%<nonmonotonic%> schedule modifier specified "
10353 : "together with %<ordered%> clause");
10354 42 : OMP_CLAUSE_SCHEDULE_KIND (c)
10355 21 : = (enum omp_clause_schedule_kind)
10356 21 : (OMP_CLAUSE_SCHEDULE_KIND (c)
10357 : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
10358 : }
10359 3877 : if (reduction_seen == -2)
10360 9 : error_at (OMP_CLAUSE_LOCATION (c),
10361 : "%qs clause specified together with %<inscan%> "
10362 : "%<reduction%> clause", "schedule");
10363 3877 : pc = &OMP_CLAUSE_CHAIN (c);
10364 3877 : continue;
10365 51 : case OMP_CLAUSE_NOGROUP:
10366 51 : if (reduction_seen)
10367 : {
10368 3 : error_at (OMP_CLAUSE_LOCATION (c),
10369 : "%<nogroup%> clause must not be used together with "
10370 : "%<reduction%> clause");
10371 3 : *pc = OMP_CLAUSE_CHAIN (c);
10372 3 : continue;
10373 : }
10374 48 : pc = &OMP_CLAUSE_CHAIN (c);
10375 48 : continue;
10376 165 : case OMP_CLAUSE_GRAINSIZE:
10377 165 : if (num_tasks_seen)
10378 : {
10379 6 : error_at (OMP_CLAUSE_LOCATION (c),
10380 : "%<grainsize%> clause must not be used together with "
10381 : "%<num_tasks%> clause");
10382 6 : *pc = OMP_CLAUSE_CHAIN (c);
10383 6 : continue;
10384 : }
10385 159 : pc = &OMP_CLAUSE_CHAIN (c);
10386 159 : continue;
10387 630 : case OMP_CLAUSE_ORDERED:
10388 630 : if (reduction_seen == -2)
10389 6 : error_at (OMP_CLAUSE_LOCATION (c),
10390 : "%qs clause specified together with %<inscan%> "
10391 : "%<reduction%> clause", "ordered");
10392 630 : pc = &OMP_CLAUSE_CHAIN (c);
10393 630 : continue;
10394 1525 : case OMP_CLAUSE_ORDER:
10395 1525 : if (ordered_seen)
10396 : {
10397 12 : error_at (OMP_CLAUSE_LOCATION (c),
10398 : "%<order%> clause must not be used together "
10399 : "with %<ordered%> clause");
10400 12 : *pc = OMP_CLAUSE_CHAIN (c);
10401 12 : continue;
10402 : }
10403 1513 : pc = &OMP_CLAUSE_CHAIN (c);
10404 1513 : continue;
10405 57 : case OMP_CLAUSE_DETACH:
10406 57 : if (mergeable_seen)
10407 : {
10408 6 : error_at (OMP_CLAUSE_LOCATION (c),
10409 : "%<detach%> clause must not be used together with "
10410 : "%<mergeable%> clause");
10411 6 : *pc = OMP_CLAUSE_CHAIN (c);
10412 6 : continue;
10413 : }
10414 51 : pc = &OMP_CLAUSE_CHAIN (c);
10415 51 : continue;
10416 15966 : case OMP_CLAUSE_MAP:
10417 15966 : if (target_in_reduction_seen && !processing_template_decl)
10418 : {
10419 684 : t = OMP_CLAUSE_DECL (c);
10420 684 : while (handled_component_p (t)
10421 : || INDIRECT_REF_P (t)
10422 : || TREE_CODE (t) == ADDR_EXPR
10423 : || TREE_CODE (t) == MEM_REF
10424 804 : || TREE_CODE (t) == NON_LVALUE_EXPR)
10425 120 : t = TREE_OPERAND (t, 0);
10426 684 : if (DECL_P (t)
10427 684 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
10428 342 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
10429 : }
10430 15966 : pc = &OMP_CLAUSE_CHAIN (c);
10431 15966 : continue;
10432 225 : case OMP_CLAUSE_FULL:
10433 225 : if (partial_seen)
10434 : {
10435 12 : error_at (OMP_CLAUSE_LOCATION (c),
10436 : "%<full%> clause must not be used together "
10437 : "with %<partial%> clause");
10438 12 : *pc = OMP_CLAUSE_CHAIN (c);
10439 12 : continue;
10440 : }
10441 213 : pc = &OMP_CLAUSE_CHAIN (c);
10442 213 : continue;
10443 6894 : case OMP_CLAUSE_NOWAIT:
10444 6894 : if (copyprivate_seen)
10445 : {
10446 6 : error_at (OMP_CLAUSE_LOCATION (c),
10447 : "%<nowait%> clause must not be used together "
10448 : "with %<copyprivate%> clause");
10449 6 : *pc = OMP_CLAUSE_CHAIN (c);
10450 6 : continue;
10451 : }
10452 : /* FALLTHRU */
10453 50408 : default:
10454 50408 : pc = &OMP_CLAUSE_CHAIN (c);
10455 50408 : continue;
10456 : }
10457 :
10458 22222 : t = OMP_CLAUSE_DECL (c);
10459 22222 : switch (c_kind)
10460 : {
10461 2766 : case OMP_CLAUSE_LASTPRIVATE:
10462 2766 : if (DECL_P (t)
10463 2766 : && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
10464 : {
10465 2666 : need_default_ctor = true;
10466 2666 : need_dtor = true;
10467 : }
10468 : break;
10469 :
10470 9468 : case OMP_CLAUSE_REDUCTION:
10471 9468 : case OMP_CLAUSE_IN_REDUCTION:
10472 9468 : case OMP_CLAUSE_TASK_REDUCTION:
10473 9468 : if (allocate_seen)
10474 : {
10475 1561 : if (TREE_CODE (t) == MEM_REF)
10476 : {
10477 162 : t = TREE_OPERAND (t, 0);
10478 162 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
10479 0 : t = TREE_OPERAND (t, 0);
10480 162 : if (TREE_CODE (t) == ADDR_EXPR
10481 120 : || INDIRECT_REF_P (t))
10482 80 : t = TREE_OPERAND (t, 0);
10483 162 : if (DECL_P (t))
10484 162 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10485 : }
10486 1399 : else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10487 : {
10488 192 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10489 96 : t = TREE_OPERAND (t, 0);
10490 96 : if (DECL_P (t))
10491 96 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10492 96 : t = OMP_CLAUSE_DECL (c);
10493 : }
10494 1303 : else if (DECL_P (t))
10495 1303 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10496 1561 : t = OMP_CLAUSE_DECL (c);
10497 : }
10498 9468 : if (processing_template_decl
10499 863 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10500 : break;
10501 8898 : if (finish_omp_reduction_clause (c, &need_default_ctor,
10502 : &need_dtor))
10503 : remove = true;
10504 : else
10505 8814 : t = OMP_CLAUSE_DECL (c);
10506 : break;
10507 :
10508 277 : case OMP_CLAUSE_COPYIN:
10509 277 : if (processing_template_decl
10510 0 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10511 : break;
10512 277 : if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
10513 : {
10514 15 : error_at (OMP_CLAUSE_LOCATION (c),
10515 : "%qE must be %<threadprivate%> for %<copyin%>", t);
10516 15 : remove = true;
10517 : }
10518 : break;
10519 :
10520 : default:
10521 : break;
10522 : }
10523 :
10524 22222 : if (processing_template_decl
10525 1544 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10526 : {
10527 632 : pc = &OMP_CLAUSE_CHAIN (c);
10528 632 : continue;
10529 : }
10530 :
10531 21590 : if (need_complete_type || need_copy_assignment)
10532 : {
10533 9205 : t = require_complete_type (t);
10534 9205 : if (t == error_mark_node)
10535 : remove = true;
10536 9181 : else if (!processing_template_decl
10537 8798 : && TYPE_REF_P (TREE_TYPE (t))
10538 9737 : && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
10539 : remove = true;
10540 : }
10541 21590 : if (need_implicitly_determined)
10542 : {
10543 20549 : const char *share_name = NULL;
10544 :
10545 20549 : if (allocate_seen
10546 4995 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10547 24665 : && DECL_P (t))
10548 3906 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10549 :
10550 20549 : if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
10551 : share_name = "threadprivate";
10552 20507 : else switch (cxx_omp_predetermined_sharing_1 (t))
10553 : {
10554 : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
10555 : break;
10556 47 : case OMP_CLAUSE_DEFAULT_SHARED:
10557 47 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10558 30 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
10559 64 : && c_omp_predefined_variable (t))
10560 : /* The __func__ variable and similar function-local predefined
10561 : variables may be listed in a shared or firstprivate
10562 : clause. */
10563 : break;
10564 31 : if (VAR_P (t)
10565 31 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10566 9 : && TREE_STATIC (t)
10567 40 : && cxx_omp_const_qual_no_mutable (t))
10568 : {
10569 6 : tree ctx = CP_DECL_CONTEXT (t);
10570 : /* const qualified static data members without mutable
10571 : member may be specified in firstprivate clause. */
10572 6 : if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
10573 : break;
10574 : }
10575 : share_name = "shared";
10576 : break;
10577 : case OMP_CLAUSE_DEFAULT_PRIVATE:
10578 : share_name = "private";
10579 : break;
10580 0 : default:
10581 0 : gcc_unreachable ();
10582 : }
10583 : if (share_name)
10584 : {
10585 67 : error_at (OMP_CLAUSE_LOCATION (c),
10586 : "%qE is predetermined %qs for %qs",
10587 : omp_clause_printable_decl (t), share_name,
10588 67 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10589 67 : remove = true;
10590 : }
10591 20482 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10592 18423 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
10593 35775 : && cxx_omp_const_qual_no_mutable (t))
10594 : {
10595 126 : error_at (OMP_CLAUSE_LOCATION (c),
10596 : "%<const%> qualified %qE without %<mutable%> member "
10597 : "may appear only in %<shared%> or %<firstprivate%> "
10598 : "clauses", omp_clause_printable_decl (t));
10599 63 : remove = true;
10600 : }
10601 : }
10602 :
10603 21590 : if (detach_seen
10604 16 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10605 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
10606 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10607 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
10608 21606 : && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
10609 : {
10610 6 : error_at (OMP_CLAUSE_LOCATION (c),
10611 : "the event handle of a %<detach%> clause "
10612 : "should not be in a data-sharing clause");
10613 6 : remove = true;
10614 : }
10615 :
10616 : /* We're interested in the base element, not arrays. */
10617 21590 : inner_type = type = TREE_TYPE (t);
10618 21590 : if ((need_complete_type
10619 : || need_copy_assignment
10620 12385 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
10621 5711 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
10622 4238 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
10623 30064 : && TYPE_REF_P (inner_type))
10624 878 : inner_type = TREE_TYPE (inner_type);
10625 24177 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
10626 2587 : inner_type = TREE_TYPE (inner_type);
10627 :
10628 : /* Check for special function availability by building a call to one.
10629 : Save the results, because later we won't be in the right context
10630 : for making these queries. */
10631 2397 : if (CLASS_TYPE_P (inner_type)
10632 2397 : && COMPLETE_TYPE_P (inner_type)
10633 2328 : && (need_default_ctor || need_copy_ctor
10634 1091 : || need_copy_assignment || need_dtor)
10635 2004 : && !type_dependent_expression_p (t)
10636 23594 : && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
10637 : need_copy_ctor, need_copy_assignment,
10638 : need_dtor))
10639 : remove = true;
10640 :
10641 21590 : if (!remove
10642 21590 : && c_kind == OMP_CLAUSE_SHARED
10643 2056 : && processing_template_decl)
10644 : {
10645 125 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10646 125 : if (t)
10647 5 : OMP_CLAUSE_DECL (c) = t;
10648 : }
10649 :
10650 21590 : if (remove)
10651 292 : *pc = OMP_CLAUSE_CHAIN (c);
10652 : else
10653 21298 : pc = &OMP_CLAUSE_CHAIN (c);
10654 : }
10655 :
10656 62754 : if (allocate_seen)
10657 16834 : for (pc = &clauses, c = clauses; c ; c = *pc)
10658 : {
10659 14551 : bool remove = false;
10660 14551 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
10661 2542 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
10662 2145 : && DECL_P (OMP_CLAUSE_DECL (c))
10663 16696 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
10664 : {
10665 15 : error_at (OMP_CLAUSE_LOCATION (c),
10666 : "%qD specified in %<allocate%> clause but not in "
10667 15 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
10668 15 : remove = true;
10669 : }
10670 14551 : if (remove)
10671 15 : *pc = OMP_CLAUSE_CHAIN (c);
10672 : else
10673 14536 : pc = &OMP_CLAUSE_CHAIN (c);
10674 : }
10675 :
10676 62754 : if (ort == C_ORT_OMP_INTEROP
10677 62754 : && depend_clause
10678 60 : && (!init_use_destroy_seen
10679 57 : || (init_seen && init_no_targetsync_clause)))
10680 : {
10681 9 : auto_diagnostic_group d;
10682 9 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
10683 : "%<depend%> clause requires action clauses with "
10684 : "%<targetsync%> interop-type");
10685 9 : if (init_no_targetsync_clause)
10686 6 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
10687 : "%<init%> clause lacks the %<targetsync%> modifier");
10688 9 : }
10689 :
10690 62754 : bitmap_obstack_release (NULL);
10691 62754 : return clauses;
10692 : }
10693 :
10694 : /* Start processing OpenMP clauses that can include any
10695 : privatization clauses for non-static data members. */
10696 :
10697 : tree
10698 48613 : push_omp_privatization_clauses (bool ignore_next)
10699 : {
10700 48613 : if (omp_private_member_ignore_next)
10701 : {
10702 656 : omp_private_member_ignore_next = ignore_next;
10703 656 : return NULL_TREE;
10704 : }
10705 47957 : omp_private_member_ignore_next = ignore_next;
10706 47957 : if (omp_private_member_map)
10707 24 : omp_private_member_vec.safe_push (error_mark_node);
10708 47957 : return push_stmt_list ();
10709 : }
10710 :
10711 : /* Revert remapping of any non-static data members since
10712 : the last push_omp_privatization_clauses () call. */
10713 :
10714 : void
10715 48607 : pop_omp_privatization_clauses (tree stmt)
10716 : {
10717 48607 : if (stmt == NULL_TREE)
10718 : return;
10719 47951 : stmt = pop_stmt_list (stmt);
10720 47951 : if (omp_private_member_map)
10721 : {
10722 1280 : while (!omp_private_member_vec.is_empty ())
10723 : {
10724 850 : tree t = omp_private_member_vec.pop ();
10725 850 : if (t == error_mark_node)
10726 : {
10727 24 : add_stmt (stmt);
10728 24 : return;
10729 : }
10730 826 : bool no_decl_expr = t == integer_zero_node;
10731 826 : if (no_decl_expr)
10732 136 : t = omp_private_member_vec.pop ();
10733 826 : tree *v = omp_private_member_map->get (t);
10734 826 : gcc_assert (v);
10735 826 : if (!no_decl_expr)
10736 690 : add_decl_expr (*v);
10737 826 : omp_private_member_map->remove (t);
10738 : }
10739 860 : delete omp_private_member_map;
10740 430 : omp_private_member_map = NULL;
10741 : }
10742 47927 : add_stmt (stmt);
10743 : }
10744 :
10745 : /* Remember OpenMP privatization clauses mapping and clear it.
10746 : Used for lambdas. */
10747 :
10748 : void
10749 16256329 : save_omp_privatization_clauses (vec<tree> &save)
10750 : {
10751 16256329 : save = vNULL;
10752 16256329 : if (omp_private_member_ignore_next)
10753 2 : save.safe_push (integer_one_node);
10754 16256329 : omp_private_member_ignore_next = false;
10755 16256329 : if (!omp_private_member_map)
10756 : return;
10757 :
10758 0 : while (!omp_private_member_vec.is_empty ())
10759 : {
10760 0 : tree t = omp_private_member_vec.pop ();
10761 0 : if (t == error_mark_node)
10762 : {
10763 0 : save.safe_push (t);
10764 0 : continue;
10765 : }
10766 0 : tree n = t;
10767 0 : if (t == integer_zero_node)
10768 0 : t = omp_private_member_vec.pop ();
10769 0 : tree *v = omp_private_member_map->get (t);
10770 0 : gcc_assert (v);
10771 0 : save.safe_push (*v);
10772 0 : save.safe_push (t);
10773 0 : if (n != t)
10774 0 : save.safe_push (n);
10775 : }
10776 0 : delete omp_private_member_map;
10777 0 : omp_private_member_map = NULL;
10778 : }
10779 :
10780 : /* Restore OpenMP privatization clauses mapping saved by the
10781 : above function. */
10782 :
10783 : void
10784 16256329 : restore_omp_privatization_clauses (vec<tree> &save)
10785 : {
10786 16256329 : gcc_assert (omp_private_member_vec.is_empty ());
10787 16256329 : omp_private_member_ignore_next = false;
10788 16256329 : if (save.is_empty ())
10789 : return;
10790 4 : if (save.length () == 1 && save[0] == integer_one_node)
10791 : {
10792 2 : omp_private_member_ignore_next = true;
10793 2 : save.release ();
10794 2 : return;
10795 : }
10796 :
10797 0 : omp_private_member_map = new hash_map <tree, tree>;
10798 0 : while (!save.is_empty ())
10799 : {
10800 0 : tree t = save.pop ();
10801 0 : tree n = t;
10802 0 : if (t != error_mark_node)
10803 : {
10804 0 : if (t == integer_one_node)
10805 : {
10806 0 : omp_private_member_ignore_next = true;
10807 0 : gcc_assert (save.is_empty ());
10808 0 : break;
10809 : }
10810 0 : if (t == integer_zero_node)
10811 0 : t = save.pop ();
10812 0 : tree &v = omp_private_member_map->get_or_insert (t);
10813 0 : v = save.pop ();
10814 : }
10815 0 : omp_private_member_vec.safe_push (t);
10816 0 : if (n != t)
10817 0 : omp_private_member_vec.safe_push (n);
10818 : }
10819 0 : save.release ();
10820 : }
10821 :
10822 : /* For all variables in the tree_list VARS, mark them as thread local. */
10823 :
10824 : void
10825 241 : finish_omp_threadprivate (tree vars)
10826 : {
10827 241 : tree t;
10828 :
10829 : /* Mark every variable in VARS to be assigned thread local storage. */
10830 515 : for (t = vars; t; t = TREE_CHAIN (t))
10831 : {
10832 274 : tree v = TREE_PURPOSE (t);
10833 274 : location_t loc = EXPR_LOCATION (TREE_VALUE (t));
10834 :
10835 274 : if (error_operand_p (v))
10836 : ;
10837 274 : else if (!VAR_P (v))
10838 6 : error_at (loc, "%<threadprivate%> %qD is not file, namespace "
10839 : "or block scope variable", v);
10840 : /* If V had already been marked threadprivate, it doesn't matter
10841 : whether it had been used prior to this point. */
10842 268 : else if (TREE_USED (v)
10843 268 : && (DECL_LANG_SPECIFIC (v) == NULL
10844 3 : || !CP_DECL_THREADPRIVATE_P (v)))
10845 6 : error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10846 262 : else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10847 6 : error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10848 256 : else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
10849 3 : error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10850 204 : else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
10851 276 : && CP_DECL_CONTEXT (v) != current_class_type)
10852 6 : error_at (loc, "%<threadprivate%> %qE directive not "
10853 6 : "in %qT definition", v, CP_DECL_CONTEXT (v));
10854 : else
10855 : {
10856 : /* Allocate a LANG_SPECIFIC structure for V, if needed. */
10857 247 : if (DECL_LANG_SPECIFIC (v) == NULL)
10858 203 : retrofit_lang_decl (v);
10859 :
10860 247 : if (! CP_DECL_THREAD_LOCAL_P (v))
10861 : {
10862 247 : CP_DECL_THREAD_LOCAL_P (v) = true;
10863 247 : set_decl_tls_model (v, decl_default_tls_model (v));
10864 : /* If rtl has been already set for this var, call
10865 : make_decl_rtl once again, so that encode_section_info
10866 : has a chance to look at the new decl flags. */
10867 247 : if (DECL_RTL_SET_P (v))
10868 0 : make_decl_rtl (v);
10869 : }
10870 247 : CP_DECL_THREADPRIVATE_P (v) = 1;
10871 : }
10872 : }
10873 241 : }
10874 :
10875 : /* Build an OpenMP structured block. */
10876 :
10877 : tree
10878 64090 : begin_omp_structured_block (void)
10879 : {
10880 64090 : return do_pushlevel (sk_omp);
10881 : }
10882 :
10883 : tree
10884 64075 : finish_omp_structured_block (tree block)
10885 : {
10886 64075 : return do_poplevel (block);
10887 : }
10888 :
10889 : /* Similarly, except force the retention of the BLOCK. */
10890 :
10891 : tree
10892 14821 : begin_omp_parallel (void)
10893 : {
10894 14821 : keep_next_level (true);
10895 14821 : return begin_omp_structured_block ();
10896 : }
10897 :
10898 : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
10899 : statement. */
10900 :
10901 : tree
10902 768 : finish_oacc_data (tree clauses, tree block)
10903 : {
10904 768 : tree stmt;
10905 :
10906 768 : block = finish_omp_structured_block (block);
10907 :
10908 768 : stmt = make_node (OACC_DATA);
10909 768 : TREE_TYPE (stmt) = void_type_node;
10910 768 : OACC_DATA_CLAUSES (stmt) = clauses;
10911 768 : OACC_DATA_BODY (stmt) = block;
10912 :
10913 768 : return add_stmt (stmt);
10914 : }
10915 :
10916 : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
10917 : statement. */
10918 :
10919 : tree
10920 55 : finish_oacc_host_data (tree clauses, tree block)
10921 : {
10922 55 : tree stmt;
10923 :
10924 55 : block = finish_omp_structured_block (block);
10925 :
10926 55 : stmt = make_node (OACC_HOST_DATA);
10927 55 : TREE_TYPE (stmt) = void_type_node;
10928 55 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
10929 55 : OACC_HOST_DATA_BODY (stmt) = block;
10930 :
10931 55 : return add_stmt (stmt);
10932 : }
10933 :
10934 : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
10935 : statement. */
10936 :
10937 : tree
10938 4653 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
10939 : {
10940 4653 : body = finish_omp_structured_block (body);
10941 :
10942 4653 : tree stmt = make_node (code);
10943 4653 : TREE_TYPE (stmt) = void_type_node;
10944 4653 : OMP_BODY (stmt) = body;
10945 4653 : OMP_CLAUSES (stmt) = clauses;
10946 :
10947 4653 : return add_stmt (stmt);
10948 : }
10949 :
10950 : /* Used to walk OpenMP target directive body. */
10951 :
10952 : struct omp_target_walk_data
10953 : {
10954 : /* Holds the 'this' expression found in current function. */
10955 : tree current_object;
10956 :
10957 : /* True if the 'this' expression was accessed in the target body. */
10958 : bool this_expr_accessed;
10959 :
10960 : /* For non-static functions, record which pointer-typed members were
10961 : accessed, and the whole expression. */
10962 : hash_map<tree, tree> ptr_members_accessed;
10963 :
10964 : /* Record which lambda objects were accessed in target body. */
10965 : hash_set<tree> lambda_objects_accessed;
10966 :
10967 : /* For lambda functions, the __closure object expression of the current
10968 : function, and the set of captured variables accessed in target body. */
10969 : tree current_closure;
10970 : hash_set<tree> closure_vars_accessed;
10971 :
10972 : /* Local variables declared inside a BIND_EXPR, used to filter out such
10973 : variables when recording lambda_objects_accessed. */
10974 : hash_set<tree> local_decls;
10975 :
10976 : omp_mapper_list<tree> *mappers;
10977 : };
10978 :
10979 : /* Helper function of finish_omp_target_clauses, called via
10980 : cp_walk_tree_without_duplicates. Traverse body of OpenMP target
10981 : directive *TP, and fill out omp_target_walk_data passed in *PTR. */
10982 :
10983 : static tree
10984 228134 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
10985 : {
10986 228134 : tree t = *tp;
10987 228134 : struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
10988 228134 : tree current_object = data->current_object;
10989 228134 : tree current_closure = data->current_closure;
10990 228134 : omp_mapper_list<tree> *mlist = data->mappers;
10991 :
10992 : /* References inside of these expression codes shouldn't incur any
10993 : form of mapping, so return early. */
10994 228134 : if (TREE_CODE (t) == SIZEOF_EXPR
10995 228126 : || TREE_CODE (t) == ALIGNOF_EXPR)
10996 : {
10997 8 : *walk_subtrees = 0;
10998 8 : return NULL_TREE;
10999 : }
11000 :
11001 228126 : if (TREE_CODE (t) == OMP_CLAUSE)
11002 : return NULL_TREE;
11003 :
11004 215534 : if (!processing_template_decl)
11005 : {
11006 215534 : tree aggr_type = NULL_TREE;
11007 :
11008 215534 : if (TREE_CODE (t) == COMPONENT_REF
11009 215534 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
11010 2257 : aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
11011 213277 : else if ((TREE_CODE (t) == VAR_DECL
11012 : || TREE_CODE (t) == PARM_DECL
11013 : || TREE_CODE (t) == RESULT_DECL)
11014 16946 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
11015 1216 : aggr_type = TREE_TYPE (t);
11016 :
11017 3473 : if (aggr_type)
11018 : {
11019 3473 : tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
11020 3473 : if (mapper_fn)
11021 199 : mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
11022 : }
11023 : }
11024 :
11025 215534 : if (current_object)
11026 : {
11027 2564 : tree this_expr = TREE_OPERAND (current_object, 0);
11028 :
11029 2564 : if (operand_equal_p (t, this_expr))
11030 : {
11031 35 : data->this_expr_accessed = true;
11032 35 : *walk_subtrees = 0;
11033 35 : return NULL_TREE;
11034 : }
11035 :
11036 2529 : if (TREE_CODE (t) == COMPONENT_REF
11037 115 : && POINTER_TYPE_P (TREE_TYPE (t))
11038 36 : && operand_equal_p (TREE_OPERAND (t, 0), current_object)
11039 2563 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
11040 : {
11041 34 : data->this_expr_accessed = true;
11042 34 : tree fld = TREE_OPERAND (t, 1);
11043 34 : if (data->ptr_members_accessed.get (fld) == NULL)
11044 : {
11045 14 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
11046 4 : t = convert_from_reference (t);
11047 14 : data->ptr_members_accessed.put (fld, t);
11048 : }
11049 34 : *walk_subtrees = 0;
11050 34 : return NULL_TREE;
11051 : }
11052 : }
11053 :
11054 : /* When the current_function_decl is a lambda function, the closure object
11055 : argument's type seems to not yet have fields laid out, so a recording
11056 : of DECL_VALUE_EXPRs during the target body walk seems the only way to
11057 : find them. */
11058 215465 : if (current_closure
11059 300 : && (VAR_P (t)
11060 : || TREE_CODE (t) == PARM_DECL
11061 : || TREE_CODE (t) == RESULT_DECL)
11062 24 : && DECL_HAS_VALUE_EXPR_P (t)
11063 10 : && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
11064 215475 : && operand_equal_p (current_closure,
11065 10 : TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
11066 : {
11067 9 : if (!data->closure_vars_accessed.contains (t))
11068 9 : data->closure_vars_accessed.add (t);
11069 9 : *walk_subtrees = 0;
11070 9 : return NULL_TREE;
11071 : }
11072 :
11073 215456 : if (TREE_CODE (t) == BIND_EXPR)
11074 : {
11075 19992 : if (tree block = BIND_EXPR_BLOCK (t))
11076 22436 : for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
11077 2448 : if (!data->local_decls.contains (var))
11078 2448 : data->local_decls.add (var);
11079 19992 : return NULL_TREE;
11080 : }
11081 :
11082 200067 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
11083 : {
11084 39 : tree lt = TREE_TYPE (t);
11085 39 : gcc_assert (CLASS_TYPE_P (lt));
11086 :
11087 39 : if (!data->lambda_objects_accessed.contains (t)
11088 : /* Do not prepare to create target maps for locally declared
11089 : lambdas or anonymous ones. */
11090 39 : && !data->local_decls.contains (t)
11091 72 : && TREE_CODE (t) != TARGET_EXPR)
11092 13 : data->lambda_objects_accessed.add (t);
11093 39 : *walk_subtrees = 0;
11094 39 : return NULL_TREE;
11095 : }
11096 :
11097 : return NULL_TREE;
11098 : }
11099 :
11100 : /* Helper function for finish_omp_target, and also from tsubst_expr.
11101 : Create additional clauses for mapping of non-static members, lambda objects,
11102 : etc. */
11103 :
11104 : void
11105 6945 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
11106 : {
11107 6945 : omp_target_walk_data data;
11108 6945 : data.this_expr_accessed = false;
11109 6945 : data.current_object = NULL_TREE;
11110 :
11111 6945 : if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
11112 96 : if (tree ct = current_nonlambda_class_type ())
11113 : {
11114 95 : tree object = maybe_dummy_object (ct, NULL);
11115 95 : object = maybe_resolve_dummy (object, true);
11116 95 : data.current_object = object;
11117 : }
11118 :
11119 6945 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11120 : {
11121 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11122 8 : data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11123 : }
11124 : else
11125 6937 : data.current_closure = NULL_TREE;
11126 :
11127 6945 : auto_vec<tree, 16> new_clauses;
11128 :
11129 6945 : if (!processing_template_decl)
11130 : {
11131 6945 : hash_set<omp_name_type<tree> > seen_types;
11132 6945 : auto_vec<tree> mapper_fns;
11133 6945 : omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
11134 6945 : data.mappers = &mlist;
11135 :
11136 6945 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11137 : &data);
11138 :
11139 6945 : unsigned int i;
11140 6945 : tree mapper_fn;
11141 13983 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11142 93 : c_omp_find_nested_mappers (&mlist, mapper_fn);
11143 :
11144 7108 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11145 : {
11146 93 : tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
11147 93 : if (mapper == error_mark_node)
11148 0 : continue;
11149 93 : tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
11150 93 : tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
11151 93 : if (BASELINK_P (mapper_fn))
11152 0 : mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
11153 :
11154 93 : tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
11155 93 : OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
11156 93 : OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
11157 93 : OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
11158 :
11159 93 : new_clauses.safe_push (c);
11160 : }
11161 6945 : }
11162 : else
11163 : {
11164 0 : data.mappers = NULL;
11165 0 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11166 : &data);
11167 : }
11168 :
11169 6945 : tree omp_target_this_expr = NULL_TREE;
11170 6945 : tree *explicit_this_deref_map = NULL;
11171 6945 : if (data.this_expr_accessed)
11172 : {
11173 31 : omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
11174 :
11175 : /* See if explicit user-specified map(this[:]) clause already exists.
11176 : If not, we create an implicit map(tofrom:this[:1]) clause. */
11177 80 : for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
11178 50 : if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
11179 47 : && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
11180 40 : || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
11181 57 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
11182 : omp_target_this_expr))
11183 : {
11184 : explicit_this_deref_map = cp;
11185 : break;
11186 : }
11187 : }
11188 :
11189 6945 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11190 6945 : && (data.this_expr_accessed
11191 1 : || !data.closure_vars_accessed.is_empty ()))
11192 : {
11193 : /* For lambda functions, we need to first create a copy of the
11194 : __closure object. */
11195 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11196 8 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11197 8 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
11198 8 : OMP_CLAUSE_DECL (c)
11199 8 : = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11200 8 : OMP_CLAUSE_SIZE (c)
11201 8 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
11202 8 : new_clauses.safe_push (c);
11203 :
11204 8 : tree closure_obj = OMP_CLAUSE_DECL (c);
11205 8 : tree closure_type = TREE_TYPE (closure_obj);
11206 :
11207 16 : gcc_assert (LAMBDA_TYPE_P (closure_type)
11208 : && CLASS_TYPE_P (closure_type));
11209 :
11210 8 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11211 8 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
11212 8 : OMP_CLAUSE_DECL (c2) = closure;
11213 8 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11214 8 : new_clauses.safe_push (c2);
11215 : }
11216 :
11217 6945 : if (data.this_expr_accessed)
11218 : {
11219 : /* If the this-expr was accessed, create a map(*this) clause. */
11220 31 : enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11221 31 : if (explicit_this_deref_map)
11222 : {
11223 1 : tree this_map = *explicit_this_deref_map;
11224 1 : tree nc = OMP_CLAUSE_CHAIN (this_map);
11225 2 : gcc_assert (nc != NULL_TREE
11226 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11227 : && (OMP_CLAUSE_MAP_KIND (nc)
11228 : == GOMP_MAP_FIRSTPRIVATE_POINTER));
11229 1 : kind = OMP_CLAUSE_MAP_KIND (this_map);
11230 : /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
11231 : two-map sequence away from the chain. */
11232 1 : *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
11233 : }
11234 31 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11235 31 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11236 31 : OMP_CLAUSE_DECL (c)
11237 31 : = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
11238 31 : OMP_CLAUSE_SIZE (c)
11239 31 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
11240 31 : new_clauses.safe_push (c);
11241 :
11242 : /* If we're in a lambda function, the this-pointer will actually be
11243 : '__closure->this', a mapped member of __closure, hence always_pointer.
11244 : Otherwise it's a firstprivate pointer. */
11245 31 : enum gomp_map_kind ptr_kind
11246 31 : = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11247 31 : ? GOMP_MAP_ALWAYS_POINTER
11248 24 : : GOMP_MAP_FIRSTPRIVATE_POINTER);
11249 31 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11250 31 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11251 31 : OMP_CLAUSE_DECL (c) = omp_target_this_expr;
11252 31 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11253 31 : new_clauses.safe_push (c);
11254 : }
11255 :
11256 6945 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11257 : {
11258 8 : if (omp_target_this_expr)
11259 : {
11260 7 : STRIP_NOPS (omp_target_this_expr);
11261 7 : gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
11262 7 : omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
11263 : }
11264 :
11265 17 : for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
11266 34 : i != data.closure_vars_accessed.end (); ++i)
11267 : {
11268 9 : tree orig_decl = *i;
11269 9 : tree closure_expr = DECL_VALUE_EXPR (orig_decl);
11270 :
11271 9 : if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
11272 9 : || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
11273 : {
11274 : /* this-pointer is processed above, outside this loop. */
11275 3 : if (omp_target_this_expr
11276 3 : && operand_equal_p (closure_expr, omp_target_this_expr))
11277 0 : continue;
11278 :
11279 3 : bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
11280 3 : enum gomp_map_kind kind, ptr_kind, nc_kind;
11281 3 : tree size;
11282 :
11283 3 : if (ptr_p)
11284 : {
11285 : /* For pointers, default mapped as zero-length array
11286 : section. */
11287 2 : kind = GOMP_MAP_ALLOC;
11288 2 : nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
11289 2 : ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
11290 2 : size = size_zero_node;
11291 : }
11292 : else
11293 : {
11294 : /* For references, default mapped as appearing on map
11295 : clause. */
11296 1 : kind = GOMP_MAP_TOFROM;
11297 1 : nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
11298 1 : ptr_kind = GOMP_MAP_ALWAYS_POINTER;
11299 1 : size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
11300 : }
11301 :
11302 6 : for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
11303 3 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
11304 1 : && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
11305 1 : || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
11306 3 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
11307 : orig_decl))
11308 : {
11309 : /* If this was already specified by user as a map,
11310 : save the user specified map kind, delete the
11311 : "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
11312 : and insert our own sequence:
11313 : "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
11314 : */
11315 0 : tree nc = OMP_CLAUSE_CHAIN (*p);
11316 0 : gcc_assert (nc != NULL_TREE
11317 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11318 : && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
11319 : /* Update with user specified kind and size. */
11320 0 : kind = OMP_CLAUSE_MAP_KIND (*p);
11321 0 : size = OMP_CLAUSE_SIZE (*p);
11322 0 : *p = OMP_CLAUSE_CHAIN (nc);
11323 0 : break;
11324 : }
11325 :
11326 3 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11327 3 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11328 3 : OMP_CLAUSE_DECL (c)
11329 3 : = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
11330 3 : OMP_CLAUSE_SIZE (c) = size;
11331 3 : if (ptr_p)
11332 2 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11333 3 : new_clauses.safe_push (c);
11334 :
11335 3 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11336 3 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11337 3 : OMP_CLAUSE_DECL (c) = closure_expr;
11338 3 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11339 3 : new_clauses.safe_push (c);
11340 : }
11341 : }
11342 : }
11343 :
11344 6945 : if (!data.ptr_members_accessed.is_empty ())
11345 14 : for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
11346 56 : i != data.ptr_members_accessed.end (); ++i)
11347 : {
11348 : /* For each referenced member that is of pointer or reference-to-pointer
11349 : type, create the equivalent of map(alloc:this->ptr[:0]). */
11350 14 : tree field_decl = (*i).first;
11351 14 : tree ptr_member = (*i).second;
11352 :
11353 26 : for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
11354 : {
11355 16 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
11356 2 : continue;
11357 : /* If map(this->ptr[:N]) already exists, avoid creating another
11358 : such map. */
11359 14 : tree decl = OMP_CLAUSE_DECL (c);
11360 14 : if ((TREE_CODE (decl) == INDIRECT_REF
11361 10 : || TREE_CODE (decl) == MEM_REF)
11362 14 : && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
11363 4 : goto next_ptr_member;
11364 : }
11365 :
11366 10 : if (!cxx_mark_addressable (ptr_member))
11367 0 : gcc_unreachable ();
11368 :
11369 10 : if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
11370 : {
11371 : /* For reference to pointers, we need to map the referenced
11372 : pointer first for things to be correct. */
11373 4 : tree ptr_member_type = TREE_TYPE (ptr_member);
11374 :
11375 : /* Map pointer target as zero-length array section. */
11376 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11377 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11378 4 : OMP_CLAUSE_DECL (c)
11379 4 : = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
11380 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11381 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11382 :
11383 : /* Map pointer to zero-length array section. */
11384 4 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11385 4 : OMP_CLAUSE_SET_MAP_KIND
11386 : (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
11387 4 : OMP_CLAUSE_DECL (c2) = ptr_member;
11388 4 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11389 :
11390 : /* Attach reference-to-pointer field to pointer. */
11391 4 : tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11392 4 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
11393 4 : OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
11394 4 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
11395 :
11396 4 : new_clauses.safe_push (c);
11397 4 : new_clauses.safe_push (c2);
11398 4 : new_clauses.safe_push (c3);
11399 : }
11400 6 : else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
11401 : {
11402 : /* Map pointer target as zero-length array section. */
11403 6 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11404 6 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11405 6 : OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
11406 : RO_UNARY_STAR);
11407 6 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11408 6 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11409 :
11410 : /* Attach zero-length array section to pointer. */
11411 6 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11412 6 : OMP_CLAUSE_SET_MAP_KIND
11413 : (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11414 6 : OMP_CLAUSE_DECL (c2) = ptr_member;
11415 6 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11416 :
11417 6 : new_clauses.safe_push (c);
11418 6 : new_clauses.safe_push (c2);
11419 : }
11420 : else
11421 0 : gcc_unreachable ();
11422 :
11423 14 : next_ptr_member:
11424 14 : ;
11425 : }
11426 :
11427 6958 : for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
11428 6971 : i != data.lambda_objects_accessed.end (); ++i)
11429 : {
11430 13 : tree lobj = *i;
11431 13 : if (TREE_CODE (lobj) == TARGET_EXPR)
11432 0 : lobj = TARGET_EXPR_SLOT (lobj);
11433 :
11434 13 : tree lt = TREE_TYPE (lobj);
11435 26 : gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
11436 :
11437 13 : tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
11438 13 : OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
11439 13 : OMP_CLAUSE_DECL (lc) = lobj;
11440 13 : OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
11441 13 : new_clauses.safe_push (lc);
11442 :
11443 180 : for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
11444 : {
11445 167 : if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
11446 : {
11447 4 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11448 : lobj, fld, NULL_TREE);
11449 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11450 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11451 4 : OMP_CLAUSE_DECL (c)
11452 4 : = build_indirect_ref (loc, exp, RO_UNARY_STAR);
11453 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11454 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11455 4 : new_clauses.safe_push (c);
11456 :
11457 4 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11458 4 : OMP_CLAUSE_SET_MAP_KIND
11459 : (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11460 4 : OMP_CLAUSE_DECL (c) = exp;
11461 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11462 4 : new_clauses.safe_push (c);
11463 : }
11464 163 : else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
11465 : {
11466 0 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11467 : lobj, fld, NULL_TREE);
11468 0 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11469 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
11470 0 : OMP_CLAUSE_DECL (c)
11471 0 : = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
11472 0 : OMP_CLAUSE_SIZE (c)
11473 0 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
11474 0 : new_clauses.safe_push (c);
11475 :
11476 0 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11477 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
11478 0 : OMP_CLAUSE_DECL (c) = exp;
11479 0 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11480 0 : new_clauses.safe_push (c);
11481 : }
11482 : }
11483 : }
11484 :
11485 6945 : tree c = *clauses_ptr;
11486 14112 : for (int i = new_clauses.length () - 1; i >= 0; i--)
11487 : {
11488 222 : OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
11489 222 : c = new_clauses[i];
11490 : }
11491 6945 : *clauses_ptr = c;
11492 6945 : }
11493 :
11494 : /* Called from cp_parser_omp_target. Create additional implicit clauses for
11495 : OpenMP target directives, and do sanity checks. */
11496 :
11497 : tree
11498 6935 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
11499 : {
11500 6935 : if (!processing_template_decl)
11501 6132 : finish_omp_target_clauses (loc, body, &clauses);
11502 :
11503 6935 : tree stmt = make_node (OMP_TARGET);
11504 6935 : TREE_TYPE (stmt) = void_type_node;
11505 6935 : OMP_TARGET_CLAUSES (stmt) = clauses;
11506 6935 : OMP_TARGET_BODY (stmt) = body;
11507 6935 : OMP_TARGET_COMBINED (stmt) = combined_p;
11508 6935 : SET_EXPR_LOCATION (stmt, loc);
11509 :
11510 6935 : tree c = clauses;
11511 16614 : while (c)
11512 : {
11513 9679 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
11514 5618 : switch (OMP_CLAUSE_MAP_KIND (c))
11515 : {
11516 : case GOMP_MAP_TO:
11517 : case GOMP_MAP_ALWAYS_TO:
11518 : case GOMP_MAP_PRESENT_TO:
11519 : case GOMP_MAP_ALWAYS_PRESENT_TO:
11520 : case GOMP_MAP_FROM:
11521 : case GOMP_MAP_ALWAYS_FROM:
11522 : case GOMP_MAP_PRESENT_FROM:
11523 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
11524 : case GOMP_MAP_TOFROM:
11525 : case GOMP_MAP_ALWAYS_TOFROM:
11526 : case GOMP_MAP_PRESENT_TOFROM:
11527 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
11528 : case GOMP_MAP_ALLOC:
11529 : case GOMP_MAP_PRESENT_ALLOC:
11530 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
11531 : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
11532 : case GOMP_MAP_ALWAYS_POINTER:
11533 : case GOMP_MAP_ATTACH_DETACH:
11534 : case GOMP_MAP_ATTACH:
11535 : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
11536 : case GOMP_MAP_POINTER:
11537 : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
11538 : break;
11539 3 : default:
11540 3 : error_at (OMP_CLAUSE_LOCATION (c),
11541 : "%<#pragma omp target%> with map-type other "
11542 : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
11543 : "on %<map%> clause");
11544 3 : break;
11545 : }
11546 9679 : c = OMP_CLAUSE_CHAIN (c);
11547 : }
11548 6935 : return add_stmt (stmt);
11549 : }
11550 :
11551 : tree
11552 9345 : finish_omp_parallel (tree clauses, tree body)
11553 : {
11554 9345 : tree stmt;
11555 :
11556 9345 : body = finish_omp_structured_block (body);
11557 :
11558 9345 : stmt = make_node (OMP_PARALLEL);
11559 9345 : TREE_TYPE (stmt) = void_type_node;
11560 9345 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
11561 9345 : OMP_PARALLEL_BODY (stmt) = body;
11562 :
11563 9345 : return add_stmt (stmt);
11564 : }
11565 :
11566 : tree
11567 2162 : begin_omp_task (void)
11568 : {
11569 2162 : keep_next_level (true);
11570 2162 : return begin_omp_structured_block ();
11571 : }
11572 :
11573 : tree
11574 2162 : finish_omp_task (tree clauses, tree body)
11575 : {
11576 2162 : tree stmt;
11577 :
11578 2162 : body = finish_omp_structured_block (body);
11579 :
11580 2162 : stmt = make_node (OMP_TASK);
11581 2162 : TREE_TYPE (stmt) = void_type_node;
11582 2162 : OMP_TASK_CLAUSES (stmt) = clauses;
11583 2162 : OMP_TASK_BODY (stmt) = body;
11584 :
11585 2162 : return add_stmt (stmt);
11586 : }
11587 :
11588 : /* Helper function for finish_omp_for. Convert Ith random access iterator
11589 : into integral iterator. Return FALSE if successful. */
11590 :
11591 : static bool
11592 813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
11593 : tree declv, tree orig_declv, tree initv,
11594 : tree condv, tree incrv, tree *body,
11595 : tree *pre_body, tree &clauses,
11596 : int collapse, int ordered)
11597 : {
11598 813 : tree diff, iter_init, iter_incr = NULL, last;
11599 813 : tree incr_var = NULL, orig_pre_body, orig_body, c;
11600 813 : tree decl = TREE_VEC_ELT (declv, i);
11601 813 : tree init = TREE_VEC_ELT (initv, i);
11602 813 : tree cond = TREE_VEC_ELT (condv, i);
11603 813 : tree incr = TREE_VEC_ELT (incrv, i);
11604 813 : tree iter = decl;
11605 813 : location_t elocus = locus;
11606 :
11607 813 : if (init && EXPR_HAS_LOCATION (init))
11608 12 : elocus = EXPR_LOCATION (init);
11609 :
11610 813 : switch (TREE_CODE (cond))
11611 : {
11612 810 : case GT_EXPR:
11613 810 : case GE_EXPR:
11614 810 : case LT_EXPR:
11615 810 : case LE_EXPR:
11616 810 : case NE_EXPR:
11617 810 : if (TREE_OPERAND (cond, 1) == iter)
11618 42 : cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
11619 42 : TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
11620 810 : if (TREE_OPERAND (cond, 0) != iter)
11621 0 : cond = error_mark_node;
11622 : else
11623 : {
11624 810 : tree tem = build_x_binary_op (EXPR_LOCATION (cond),
11625 810 : TREE_CODE (cond),
11626 : iter, ERROR_MARK,
11627 810 : TREE_OPERAND (cond, 1), ERROR_MARK,
11628 : NULL_TREE, NULL, tf_warning_or_error);
11629 810 : if (error_operand_p (tem))
11630 : return true;
11631 : }
11632 : break;
11633 3 : default:
11634 3 : cond = error_mark_node;
11635 3 : break;
11636 : }
11637 810 : if (cond == error_mark_node)
11638 : {
11639 3 : error_at (elocus, "invalid controlling predicate");
11640 3 : return true;
11641 : }
11642 807 : diff = build_x_binary_op (elocus, MINUS_EXPR,
11643 807 : TREE_OPERAND (cond, 1), ERROR_MARK,
11644 : iter, ERROR_MARK,
11645 : NULL_TREE, NULL, tf_warning_or_error);
11646 807 : diff = cp_fully_fold (diff);
11647 807 : if (error_operand_p (diff))
11648 : return true;
11649 807 : if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
11650 : {
11651 0 : error_at (elocus, "difference between %qE and %qD does not have integer type",
11652 0 : TREE_OPERAND (cond, 1), iter);
11653 0 : return true;
11654 : }
11655 807 : if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
11656 807 : TREE_VEC_ELT (declv, i), NULL_TREE,
11657 : cond, cp_walk_subtrees))
11658 : return true;
11659 :
11660 762 : switch (TREE_CODE (incr))
11661 : {
11662 370 : case PREINCREMENT_EXPR:
11663 370 : case PREDECREMENT_EXPR:
11664 370 : case POSTINCREMENT_EXPR:
11665 370 : case POSTDECREMENT_EXPR:
11666 370 : if (TREE_OPERAND (incr, 0) != iter)
11667 : {
11668 0 : incr = error_mark_node;
11669 0 : break;
11670 : }
11671 370 : iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
11672 370 : TREE_CODE (incr), iter,
11673 : NULL_TREE, tf_warning_or_error);
11674 370 : if (error_operand_p (iter_incr))
11675 : return true;
11676 370 : else if (TREE_CODE (incr) == PREINCREMENT_EXPR
11677 219 : || TREE_CODE (incr) == POSTINCREMENT_EXPR)
11678 299 : incr = integer_one_node;
11679 : else
11680 71 : incr = integer_minus_one_node;
11681 : break;
11682 392 : case MODIFY_EXPR:
11683 392 : if (TREE_OPERAND (incr, 0) != iter)
11684 0 : incr = error_mark_node;
11685 392 : else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
11686 392 : || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
11687 : {
11688 392 : tree rhs = TREE_OPERAND (incr, 1);
11689 392 : if (TREE_OPERAND (rhs, 0) == iter)
11690 : {
11691 299 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
11692 : != INTEGER_TYPE)
11693 0 : incr = error_mark_node;
11694 : else
11695 : {
11696 299 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11697 299 : iter, TREE_CODE (rhs),
11698 299 : TREE_OPERAND (rhs, 1),
11699 : NULL_TREE,
11700 : tf_warning_or_error);
11701 299 : if (error_operand_p (iter_incr))
11702 : return true;
11703 299 : incr = TREE_OPERAND (rhs, 1);
11704 299 : incr = cp_convert (TREE_TYPE (diff), incr,
11705 : tf_warning_or_error);
11706 299 : if (TREE_CODE (rhs) == MINUS_EXPR)
11707 : {
11708 16 : incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
11709 16 : incr = fold_simple (incr);
11710 : }
11711 299 : if (TREE_CODE (incr) != INTEGER_CST
11712 299 : && (TREE_CODE (incr) != NOP_EXPR
11713 66 : || (TREE_CODE (TREE_OPERAND (incr, 0))
11714 : != INTEGER_CST)))
11715 : iter_incr = NULL;
11716 : }
11717 : }
11718 93 : else if (TREE_OPERAND (rhs, 1) == iter)
11719 : {
11720 93 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
11721 93 : || TREE_CODE (rhs) != PLUS_EXPR)
11722 0 : incr = error_mark_node;
11723 : else
11724 : {
11725 93 : iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
11726 : PLUS_EXPR,
11727 93 : TREE_OPERAND (rhs, 0),
11728 : ERROR_MARK, iter,
11729 : ERROR_MARK, NULL_TREE, NULL,
11730 : tf_warning_or_error);
11731 93 : if (error_operand_p (iter_incr))
11732 : return true;
11733 93 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11734 : iter, NOP_EXPR,
11735 : iter_incr, NULL_TREE,
11736 : tf_warning_or_error);
11737 93 : if (error_operand_p (iter_incr))
11738 : return true;
11739 93 : incr = TREE_OPERAND (rhs, 0);
11740 93 : iter_incr = NULL;
11741 : }
11742 : }
11743 : else
11744 0 : incr = error_mark_node;
11745 : }
11746 : else
11747 0 : incr = error_mark_node;
11748 : break;
11749 0 : default:
11750 0 : incr = error_mark_node;
11751 0 : break;
11752 : }
11753 :
11754 762 : if (incr == error_mark_node)
11755 : {
11756 0 : error_at (elocus, "invalid increment expression");
11757 0 : return true;
11758 : }
11759 :
11760 762 : incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
11761 762 : incr = cp_fully_fold (incr);
11762 762 : tree loop_iv_seen = NULL_TREE;
11763 1735 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11764 1093 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
11765 1093 : && OMP_CLAUSE_DECL (c) == iter)
11766 : {
11767 120 : if (code == OMP_TASKLOOP || code == OMP_LOOP)
11768 : {
11769 60 : loop_iv_seen = c;
11770 60 : OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
11771 : }
11772 : break;
11773 : }
11774 973 : else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
11775 113 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
11776 1007 : && OMP_CLAUSE_DECL (c) == iter)
11777 : {
11778 30 : loop_iv_seen = c;
11779 30 : if (code == OMP_TASKLOOP)
11780 25 : OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
11781 : }
11782 :
11783 762 : decl = create_temporary_var (TREE_TYPE (diff));
11784 762 : pushdecl (decl);
11785 762 : add_decl_expr (decl);
11786 762 : last = create_temporary_var (TREE_TYPE (diff));
11787 762 : pushdecl (last);
11788 762 : add_decl_expr (last);
11789 762 : if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
11790 10 : && (!ordered || (i < collapse && collapse > 1)))
11791 : {
11792 10 : incr_var = create_temporary_var (TREE_TYPE (diff));
11793 10 : pushdecl (incr_var);
11794 10 : add_decl_expr (incr_var);
11795 : }
11796 762 : gcc_assert (stmts_are_full_exprs_p ());
11797 762 : tree diffvar = NULL_TREE;
11798 762 : if (code == OMP_TASKLOOP)
11799 : {
11800 101 : if (!loop_iv_seen)
11801 : {
11802 38 : tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11803 38 : OMP_CLAUSE_DECL (ivc) = iter;
11804 38 : cxx_omp_finish_clause (ivc, NULL, false);
11805 38 : OMP_CLAUSE_CHAIN (ivc) = clauses;
11806 38 : clauses = ivc;
11807 : }
11808 101 : tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11809 101 : OMP_CLAUSE_DECL (lvc) = last;
11810 101 : OMP_CLAUSE_CHAIN (lvc) = clauses;
11811 101 : clauses = lvc;
11812 101 : diffvar = create_temporary_var (TREE_TYPE (diff));
11813 101 : pushdecl (diffvar);
11814 101 : add_decl_expr (diffvar);
11815 : }
11816 661 : else if (code == OMP_LOOP)
11817 : {
11818 43 : if (!loop_iv_seen)
11819 : {
11820 : /* While iterators on the loop construct are predetermined
11821 : lastprivate, if the decl is not declared inside of the
11822 : loop, OMP_CLAUSE_LASTPRIVATE should have been added
11823 : already. */
11824 16 : loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11825 16 : OMP_CLAUSE_DECL (loop_iv_seen) = iter;
11826 16 : OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
11827 16 : clauses = loop_iv_seen;
11828 : }
11829 27 : else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
11830 : {
11831 5 : OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
11832 5 : OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
11833 5 : OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
11834 : }
11835 43 : if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
11836 21 : cxx_omp_finish_clause (loop_iv_seen, NULL, false);
11837 : }
11838 :
11839 762 : orig_pre_body = *pre_body;
11840 762 : *pre_body = push_stmt_list ();
11841 762 : if (orig_pre_body)
11842 610 : add_stmt (orig_pre_body);
11843 762 : if (init != NULL)
11844 61 : finish_expr_stmt (build_x_modify_expr (elocus,
11845 : iter, NOP_EXPR, init,
11846 : NULL_TREE, tf_warning_or_error));
11847 762 : init = build_int_cst (TREE_TYPE (diff), 0);
11848 762 : if (c && iter_incr == NULL
11849 28 : && (!ordered || (i < collapse && collapse > 1)))
11850 : {
11851 28 : if (incr_var)
11852 : {
11853 10 : finish_expr_stmt (build_x_modify_expr (elocus,
11854 : incr_var, NOP_EXPR,
11855 : incr, NULL_TREE,
11856 : tf_warning_or_error));
11857 10 : incr = incr_var;
11858 : }
11859 28 : iter_incr = build_x_modify_expr (elocus,
11860 : iter, PLUS_EXPR, incr,
11861 : NULL_TREE, tf_warning_or_error);
11862 : }
11863 762 : if (c && ordered && i < collapse && collapse > 1)
11864 762 : iter_incr = incr;
11865 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11866 : last, NOP_EXPR, init,
11867 : NULL_TREE, tf_warning_or_error));
11868 762 : if (diffvar)
11869 : {
11870 101 : finish_expr_stmt (build_x_modify_expr (elocus,
11871 : diffvar, NOP_EXPR,
11872 : diff, NULL_TREE, tf_warning_or_error));
11873 101 : diff = diffvar;
11874 : }
11875 762 : *pre_body = pop_stmt_list (*pre_body);
11876 :
11877 1524 : cond = cp_build_binary_op (elocus,
11878 762 : TREE_CODE (cond), decl, diff,
11879 : tf_warning_or_error);
11880 762 : incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
11881 : elocus, incr, NULL_TREE);
11882 :
11883 762 : orig_body = *body;
11884 762 : *body = push_stmt_list ();
11885 762 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
11886 762 : iter_init = build_x_modify_expr (elocus,
11887 : iter, PLUS_EXPR, iter_init,
11888 : NULL_TREE, tf_warning_or_error);
11889 762 : if (iter_init != error_mark_node)
11890 759 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11891 762 : finish_expr_stmt (iter_init);
11892 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11893 : last, NOP_EXPR, decl,
11894 : NULL_TREE, tf_warning_or_error));
11895 762 : add_stmt (orig_body);
11896 762 : *body = pop_stmt_list (*body);
11897 :
11898 762 : if (c)
11899 : {
11900 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
11901 120 : if (!ordered)
11902 114 : finish_expr_stmt (iter_incr);
11903 : else
11904 : {
11905 6 : iter_init = decl;
11906 6 : if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
11907 2 : iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
11908 : iter_init, iter_incr);
11909 6 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
11910 6 : iter_init = build_x_modify_expr (elocus,
11911 : iter, PLUS_EXPR, iter_init,
11912 : NULL_TREE, tf_warning_or_error);
11913 6 : if (iter_init != error_mark_node)
11914 6 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11915 6 : finish_expr_stmt (iter_init);
11916 : }
11917 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c)
11918 240 : = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
11919 : }
11920 :
11921 762 : if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
11922 : {
11923 116 : tree t = TREE_VEC_ELT (orig_declv, i);
11924 116 : gcc_assert (TREE_PURPOSE (t) == NULL_TREE
11925 : && TREE_VALUE (t) == NULL_TREE
11926 : && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
11927 116 : TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
11928 116 : TREE_VALUE (t) = last;
11929 : }
11930 : else
11931 646 : TREE_VEC_ELT (orig_declv, i)
11932 1292 : = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
11933 762 : TREE_VEC_ELT (declv, i) = decl;
11934 762 : TREE_VEC_ELT (initv, i) = init;
11935 762 : TREE_VEC_ELT (condv, i) = cond;
11936 762 : TREE_VEC_ELT (incrv, i) = incr;
11937 :
11938 762 : return false;
11939 : }
11940 :
11941 : /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
11942 : are directly for their associated operands in the statement. DECL
11943 : and INIT are a combo; if DECL is NULL then INIT ought to be a
11944 : MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
11945 : optional statements that need to go before the loop into its
11946 : sk_omp scope. */
11947 :
11948 : tree
11949 21176 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
11950 : tree orig_declv, tree initv, tree condv, tree incrv,
11951 : tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
11952 : {
11953 21176 : tree omp_for = NULL, orig_incr = NULL;
11954 21176 : tree decl = NULL, init, cond, incr;
11955 21176 : location_t elocus;
11956 21176 : int i;
11957 21176 : int collapse = 1;
11958 21176 : int ordered = 0;
11959 21176 : auto_vec<location_t> init_locv;
11960 :
11961 21176 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
11962 21176 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
11963 21176 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
11964 21176 : if (TREE_VEC_LENGTH (declv) > 1)
11965 : {
11966 4054 : if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
11967 83 : collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
11968 : else
11969 : {
11970 3971 : if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
11971 3501 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
11972 470 : else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
11973 394 : collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
11974 3971 : if (collapse != TREE_VEC_LENGTH (declv))
11975 100 : ordered = TREE_VEC_LENGTH (declv);
11976 : }
11977 : }
11978 48697 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
11979 : {
11980 27557 : decl = TREE_VEC_ELT (declv, i);
11981 27557 : init = TREE_VEC_ELT (initv, i);
11982 27557 : cond = TREE_VEC_ELT (condv, i);
11983 27557 : incr = TREE_VEC_ELT (incrv, i);
11984 27557 : elocus = locus;
11985 :
11986 27557 : if (decl == global_namespace)
11987 : {
11988 1101 : gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
11989 1101 : TREE_VEC_ELT (declv, i) = NULL_TREE;
11990 1101 : init_locv.safe_push (UNKNOWN_LOCATION);
11991 1101 : continue;
11992 : }
11993 : /* We are going to throw out the init's original MODIFY_EXPR or
11994 : MODOP_EXPR below. Save its location so we can use it when
11995 : reconstructing the expression farther down. Alternatively, if the
11996 : initializer is a binding of the iteration variable, save
11997 : that location. Any of these locations in the initialization clause
11998 : for the current nested loop are better than using the argument locus,
11999 : that points to the "for" of the outermost loop in the nest. */
12000 26456 : if (init && EXPR_HAS_LOCATION (init))
12001 17920 : elocus = EXPR_LOCATION (init);
12002 8536 : else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
12003 : /* This can happen for class iterators. */
12004 0 : elocus = EXPR_LOCATION (decl);
12005 8536 : else if (decl && DECL_P (decl))
12006 : {
12007 8509 : if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
12008 8509 : elocus = DECL_SOURCE_LOCATION (decl);
12009 0 : else if (DECL_INITIAL (decl)
12010 0 : && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
12011 0 : elocus = EXPR_LOCATION (DECL_INITIAL (decl));
12012 : }
12013 26456 : init_locv.safe_push (elocus);
12014 :
12015 26456 : if (decl == NULL)
12016 : {
12017 16612 : if (init != NULL)
12018 16609 : switch (TREE_CODE (init))
12019 : {
12020 16224 : case MODIFY_EXPR:
12021 16224 : decl = TREE_OPERAND (init, 0);
12022 16224 : init = TREE_OPERAND (init, 1);
12023 16224 : break;
12024 367 : case MODOP_EXPR:
12025 367 : if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
12026 : {
12027 367 : decl = TREE_OPERAND (init, 0);
12028 367 : init = TREE_OPERAND (init, 2);
12029 : }
12030 : break;
12031 : default:
12032 : break;
12033 : }
12034 :
12035 16612 : if (decl == NULL)
12036 : {
12037 21 : error_at (locus,
12038 : "expected iteration declaration or initialization");
12039 21 : return NULL;
12040 : }
12041 : }
12042 :
12043 26435 : if (cond == global_namespace)
12044 170 : continue;
12045 :
12046 26265 : if (cond == NULL)
12047 : {
12048 9 : error_at (elocus, "missing controlling predicate");
12049 9 : return NULL;
12050 : }
12051 :
12052 26256 : if (incr == NULL)
12053 : {
12054 6 : error_at (elocus, "missing increment expression");
12055 6 : return NULL;
12056 : }
12057 :
12058 26250 : TREE_VEC_ELT (declv, i) = decl;
12059 26250 : TREE_VEC_ELT (initv, i) = init;
12060 : }
12061 :
12062 21140 : if (orig_inits)
12063 : {
12064 : bool fail = false;
12065 : tree orig_init;
12066 21262 : FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
12067 1181 : if (orig_init
12068 3396 : && !c_omp_check_loop_iv_exprs (locus, code,
12069 : orig_declv ? orig_declv : declv, i,
12070 1164 : TREE_VEC_ELT (declv, i), orig_init,
12071 : NULL_TREE, cp_walk_subtrees))
12072 : fail = true;
12073 20081 : if (fail)
12074 887 : return NULL;
12075 : }
12076 :
12077 21083 : if (dependent_omp_for_p (declv, initv, condv, incrv, body))
12078 : {
12079 453 : tree stmt;
12080 :
12081 453 : stmt = make_node (code);
12082 :
12083 1499 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
12084 : {
12085 593 : if (TREE_VEC_ELT (declv, i) == NULL_TREE)
12086 9 : continue;
12087 : /* This is really just a place-holder. We'll be decomposing this
12088 : again and going through the cp_build_modify_expr path below when
12089 : we instantiate the thing. */
12090 584 : TREE_VEC_ELT (initv, i)
12091 1168 : = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
12092 584 : TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
12093 : }
12094 :
12095 453 : TREE_TYPE (stmt) = void_type_node;
12096 453 : OMP_FOR_INIT (stmt) = initv;
12097 453 : OMP_FOR_COND (stmt) = condv;
12098 453 : OMP_FOR_INCR (stmt) = incrv;
12099 453 : OMP_FOR_BODY (stmt) = body;
12100 453 : OMP_FOR_PRE_BODY (stmt) = pre_body;
12101 453 : OMP_FOR_CLAUSES (stmt) = clauses;
12102 :
12103 453 : SET_EXPR_LOCATION (stmt, locus);
12104 453 : return add_stmt (stmt);
12105 : }
12106 :
12107 20630 : if (!orig_declv)
12108 19843 : orig_declv = copy_node (declv);
12109 :
12110 20630 : if (processing_template_decl)
12111 612 : orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
12112 :
12113 48126 : for (i = 0; i < TREE_VEC_LENGTH (declv); )
12114 : {
12115 27588 : decl = TREE_VEC_ELT (declv, i);
12116 27588 : init = TREE_VEC_ELT (initv, i);
12117 27588 : cond = TREE_VEC_ELT (condv, i);
12118 27588 : incr = TREE_VEC_ELT (incrv, i);
12119 27588 : if (orig_incr)
12120 844 : TREE_VEC_ELT (orig_incr, i) = incr;
12121 27588 : elocus = init_locv[i];
12122 :
12123 27588 : if (decl == NULL_TREE)
12124 : {
12125 1092 : i++;
12126 1092 : continue;
12127 : }
12128 :
12129 26496 : if (!DECL_P (decl))
12130 : {
12131 6 : error_at (elocus, "expected iteration declaration or initialization");
12132 6 : return NULL;
12133 : }
12134 :
12135 26490 : if (incr && TREE_CODE (incr) == MODOP_EXPR)
12136 : {
12137 1 : if (orig_incr)
12138 1 : TREE_VEC_ELT (orig_incr, i) = incr;
12139 1 : incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
12140 1 : TREE_CODE (TREE_OPERAND (incr, 1)),
12141 1 : TREE_OPERAND (incr, 2),
12142 : tf_warning_or_error);
12143 : }
12144 :
12145 26490 : if (CLASS_TYPE_P (TREE_TYPE (decl)))
12146 : {
12147 825 : if (code == OMP_SIMD)
12148 : {
12149 12 : error_at (elocus, "%<#pragma omp simd%> used with class "
12150 : "iteration variable %qE", decl);
12151 12 : return NULL;
12152 : }
12153 813 : if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
12154 : initv, condv, incrv, &body,
12155 : &pre_body, clauses,
12156 : collapse, ordered))
12157 : return NULL;
12158 762 : continue;
12159 : }
12160 :
12161 51330 : if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
12162 27251 : && !TYPE_PTR_P (TREE_TYPE (decl)))
12163 : {
12164 14 : error_at (elocus, "invalid type for iteration variable %qE", decl);
12165 14 : return NULL;
12166 : }
12167 :
12168 25651 : if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
12169 24890 : init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
12170 : tf_warning_or_error);
12171 : else
12172 761 : init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
12173 25651 : if (decl == error_mark_node || init == error_mark_node)
12174 : return NULL;
12175 :
12176 25642 : TREE_VEC_ELT (declv, i) = decl;
12177 25642 : TREE_VEC_ELT (initv, i) = init;
12178 25642 : TREE_VEC_ELT (condv, i) = cond;
12179 25642 : TREE_VEC_ELT (incrv, i) = incr;
12180 25642 : i++;
12181 : }
12182 :
12183 20538 : if (pre_body && IS_EMPTY_STMT (pre_body))
12184 0 : pre_body = NULL;
12185 :
12186 41076 : omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
12187 : incrv, body, pre_body,
12188 20538 : !processing_template_decl);
12189 :
12190 : /* Check for iterators appearing in lb, b or incr expressions. */
12191 20538 : if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
12192 : omp_for = NULL_TREE;
12193 :
12194 20052 : if (omp_for == NULL)
12195 702 : return NULL;
12196 :
12197 19836 : add_stmt (omp_for);
12198 :
12199 45544 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
12200 : {
12201 25708 : init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
12202 25708 : if (init == NULL_TREE)
12203 1032 : continue;
12204 24676 : decl = TREE_OPERAND (init, 0);
12205 24676 : cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
12206 24676 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
12207 :
12208 24676 : if (!processing_template_decl)
12209 : {
12210 24155 : if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
12211 : {
12212 106 : tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
12213 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
12214 106 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12215 106 : t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
12216 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
12217 212 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12218 : }
12219 : else
12220 : {
12221 24049 : tree t = TREE_OPERAND (init, 1);
12222 24049 : TREE_OPERAND (init, 1)
12223 48098 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12224 : }
12225 24155 : if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
12226 : {
12227 121 : tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
12228 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
12229 121 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12230 121 : t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
12231 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
12232 242 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12233 : }
12234 : else
12235 : {
12236 24034 : tree t = TREE_OPERAND (cond, 1);
12237 24034 : TREE_OPERAND (cond, 1)
12238 48068 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12239 : }
12240 : }
12241 :
12242 24676 : if (TREE_CODE (incr) != MODIFY_EXPR)
12243 18471 : continue;
12244 :
12245 6205 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
12246 70 : && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
12247 6275 : && !processing_template_decl)
12248 : {
12249 64 : tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
12250 64 : if (TREE_SIDE_EFFECTS (t)
12251 8 : && t != decl
12252 70 : && (TREE_CODE (t) != NOP_EXPR
12253 0 : || TREE_OPERAND (t, 0) != decl))
12254 6 : TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
12255 12 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12256 :
12257 64 : t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
12258 64 : if (TREE_SIDE_EFFECTS (t)
12259 56 : && t != decl
12260 120 : && (TREE_CODE (t) != NOP_EXPR
12261 5 : || TREE_OPERAND (t, 0) != decl))
12262 56 : TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
12263 112 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12264 : }
12265 :
12266 6205 : if (orig_incr)
12267 177 : TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
12268 : }
12269 19836 : OMP_FOR_CLAUSES (omp_for) = clauses;
12270 :
12271 : /* For simd loops with non-static data member iterators, we could have added
12272 : OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
12273 : step at this point, fill it in. */
12274 4735 : if (code == OMP_SIMD && !processing_template_decl
12275 24527 : && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
12276 4619 : for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
12277 561 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
12278 561 : if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
12279 : {
12280 4 : decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
12281 4 : gcc_assert (decl == OMP_CLAUSE_DECL (c));
12282 4 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
12283 4 : tree step, stept;
12284 4 : switch (TREE_CODE (incr))
12285 : {
12286 0 : case PREINCREMENT_EXPR:
12287 0 : case POSTINCREMENT_EXPR:
12288 : /* c_omp_for_incr_canonicalize_ptr() should have been
12289 : called to massage things appropriately. */
12290 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12291 0 : OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
12292 0 : break;
12293 0 : case PREDECREMENT_EXPR:
12294 0 : case POSTDECREMENT_EXPR:
12295 : /* c_omp_for_incr_canonicalize_ptr() should have been
12296 : called to massage things appropriately. */
12297 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12298 0 : OMP_CLAUSE_LINEAR_STEP (c)
12299 0 : = build_int_cst (TREE_TYPE (decl), -1);
12300 0 : break;
12301 4 : case MODIFY_EXPR:
12302 4 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12303 4 : incr = TREE_OPERAND (incr, 1);
12304 4 : switch (TREE_CODE (incr))
12305 : {
12306 4 : case PLUS_EXPR:
12307 4 : if (TREE_OPERAND (incr, 1) == decl)
12308 0 : step = TREE_OPERAND (incr, 0);
12309 : else
12310 4 : step = TREE_OPERAND (incr, 1);
12311 : break;
12312 0 : case MINUS_EXPR:
12313 0 : case POINTER_PLUS_EXPR:
12314 0 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12315 0 : step = TREE_OPERAND (incr, 1);
12316 0 : break;
12317 0 : default:
12318 0 : gcc_unreachable ();
12319 : }
12320 4 : stept = TREE_TYPE (decl);
12321 4 : if (INDIRECT_TYPE_P (stept))
12322 0 : stept = sizetype;
12323 4 : step = fold_convert (stept, step);
12324 4 : if (TREE_CODE (incr) == MINUS_EXPR)
12325 0 : step = fold_build1 (NEGATE_EXPR, stept, step);
12326 4 : OMP_CLAUSE_LINEAR_STEP (c) = step;
12327 4 : break;
12328 0 : default:
12329 0 : gcc_unreachable ();
12330 : }
12331 : }
12332 : /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
12333 : clauses, we need copy ctor for those rather than default ctor,
12334 : plus as for other lastprivates assignment op and dtor. */
12335 19836 : if (code == OMP_LOOP && !processing_template_decl)
12336 1993 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12337 1285 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
12338 204 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
12339 1307 : && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
12340 : false, true, true, true))
12341 0 : CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
12342 :
12343 : return omp_for;
12344 21176 : }
12345 :
12346 : /* Code walker for finish_omp_for_block: extract binding of DP->var
12347 : from its current block and move it to a new BIND_EXPR DP->b
12348 : surrounding the body of DP->omp_for. */
12349 :
12350 : struct fofb_data {
12351 : tree var;
12352 : tree b;
12353 : tree omp_for;
12354 : };
12355 :
12356 : static tree
12357 389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
12358 : {
12359 389 : struct fofb_data *fofb = (struct fofb_data *)dp;
12360 389 : if (TREE_CODE (*tp) == BIND_EXPR)
12361 578 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
12362 : {
12363 576 : if (*p == fofb->var)
12364 : {
12365 363 : *p = DECL_CHAIN (*p);
12366 363 : if (fofb->b == NULL_TREE)
12367 : {
12368 214 : fofb->b = make_node (BLOCK);
12369 214 : fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
12370 214 : OMP_FOR_BODY (fofb->omp_for), fofb->b);
12371 214 : TREE_SIDE_EFFECTS (fofb->b) = 1;
12372 214 : OMP_FOR_BODY (fofb->omp_for) = fofb->b;
12373 : }
12374 363 : DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
12375 363 : BIND_EXPR_VARS (fofb->b) = fofb->var;
12376 363 : BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
12377 363 : BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
12378 363 : return *tp;
12379 : }
12380 : }
12381 26 : if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
12382 22 : *walk_subtrees = false;
12383 : return NULL_TREE;
12384 : }
12385 :
12386 : /* Fix up range for decls. Those decls were pushed into BIND's
12387 : BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
12388 : and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
12389 : so that processing of combined loop directives can find them. */
12390 : tree
12391 14573 : finish_omp_for_block (tree bind, tree omp_for)
12392 : {
12393 14573 : if (omp_for == NULL_TREE
12394 14526 : || !OMP_FOR_ORIG_DECLS (omp_for)
12395 28531 : || bind == NULL_TREE)
12396 615 : return bind;
12397 13958 : struct fofb_data fofb;
12398 13958 : fofb.b = NULL_TREE;
12399 13958 : fofb.omp_for = omp_for;
12400 33443 : for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
12401 19485 : if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
12402 19263 : && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
12403 : == TREE_LIST)
12404 20316 : && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
12405 : {
12406 237 : tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
12407 602 : for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
12408 : {
12409 365 : fofb.var = TREE_VEC_ELT (v, j);
12410 365 : cp_walk_tree (&bind, finish_omp_for_block_walker,
12411 : (void *)&fofb, NULL);
12412 : }
12413 : }
12414 13958 : return bind;
12415 : }
12416 :
12417 : void
12418 3345 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
12419 : tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
12420 : tree clauses, enum omp_memory_order mo, bool weak)
12421 : {
12422 3345 : tree orig_lhs;
12423 3345 : tree orig_rhs;
12424 3345 : tree orig_v;
12425 3345 : tree orig_lhs1;
12426 3345 : tree orig_rhs1;
12427 3345 : tree orig_r;
12428 3345 : bool dependent_p;
12429 3345 : tree stmt;
12430 :
12431 3345 : orig_lhs = lhs;
12432 3345 : orig_rhs = rhs;
12433 3345 : orig_v = v;
12434 3345 : orig_lhs1 = lhs1;
12435 3345 : orig_rhs1 = rhs1;
12436 3345 : orig_r = r;
12437 3345 : dependent_p = false;
12438 3345 : stmt = NULL_TREE;
12439 :
12440 : /* Even in a template, we can detect invalid uses of the atomic
12441 : pragma if neither LHS nor RHS is type-dependent. */
12442 3345 : if (processing_template_decl)
12443 : {
12444 600 : dependent_p = (type_dependent_expression_p (lhs)
12445 237 : || (rhs && type_dependent_expression_p (rhs))
12446 234 : || (v && type_dependent_expression_p (v))
12447 234 : || (lhs1 && type_dependent_expression_p (lhs1))
12448 234 : || (rhs1 && type_dependent_expression_p (rhs1))
12449 834 : || (r
12450 25 : && r != void_list_node
12451 16 : && type_dependent_expression_p (r)));
12452 600 : if (clauses)
12453 : {
12454 30 : gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
12455 : && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
12456 : && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
12457 30 : if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
12458 30 : || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
12459 : dependent_p = true;
12460 : }
12461 : }
12462 576 : if (!dependent_p)
12463 : {
12464 2961 : bool swapped = false;
12465 2961 : if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
12466 : {
12467 143 : std::swap (rhs, rhs1);
12468 143 : swapped = !commutative_tree_code (opcode);
12469 : }
12470 2961 : if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
12471 : {
12472 0 : if (code == OMP_ATOMIC)
12473 0 : error ("%<#pragma omp atomic update%> uses two different "
12474 : "expressions for memory");
12475 : else
12476 0 : error ("%<#pragma omp atomic capture%> uses two different "
12477 : "expressions for memory");
12478 0 : return;
12479 : }
12480 2961 : if (lhs1 && !cp_tree_equal (lhs, lhs1))
12481 : {
12482 0 : if (code == OMP_ATOMIC)
12483 0 : error ("%<#pragma omp atomic update%> uses two different "
12484 : "expressions for memory");
12485 : else
12486 0 : error ("%<#pragma omp atomic capture%> uses two different "
12487 : "expressions for memory");
12488 0 : return;
12489 : }
12490 5922 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
12491 : v, lhs1, rhs1, r, swapped, mo, weak,
12492 2961 : processing_template_decl != 0);
12493 2961 : if (stmt == error_mark_node)
12494 : return;
12495 : }
12496 3315 : if (processing_template_decl)
12497 : {
12498 591 : if (code == OMP_ATOMIC_READ)
12499 : {
12500 167 : stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
12501 167 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12502 167 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12503 : }
12504 : else
12505 : {
12506 424 : if (opcode == NOP_EXPR)
12507 35 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
12508 389 : else if (opcode == COND_EXPR)
12509 : {
12510 124 : stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
12511 124 : if (orig_r)
12512 50 : stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
12513 : stmt);
12514 124 : stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
12515 : orig_lhs);
12516 124 : orig_rhs1 = NULL_TREE;
12517 : }
12518 : else
12519 265 : stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
12520 424 : if (orig_rhs1)
12521 182 : stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
12522 : COMPOUND_EXPR, orig_rhs1, stmt);
12523 424 : if (code != OMP_ATOMIC)
12524 : {
12525 233 : stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
12526 233 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12527 233 : OMP_ATOMIC_WEAK (stmt) = weak;
12528 233 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12529 : }
12530 : }
12531 591 : stmt = build2 (OMP_ATOMIC, void_type_node,
12532 : clauses ? clauses : integer_zero_node, stmt);
12533 591 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12534 591 : OMP_ATOMIC_WEAK (stmt) = weak;
12535 591 : SET_EXPR_LOCATION (stmt, loc);
12536 : }
12537 :
12538 : /* Avoid -Wunused-value warnings here, the whole construct has side-effects
12539 : and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
12540 : in some tree that appears to be unused, the value is not unused. */
12541 3315 : warning_sentinel w (warn_unused_value);
12542 3315 : finish_expr_stmt (stmt);
12543 3315 : }
12544 :
12545 : void
12546 359 : finish_omp_barrier (void)
12547 : {
12548 359 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
12549 359 : releasing_vec vec;
12550 359 : vec->quick_push (build_int_cst (integer_type_node, GOMP_BARRIER_EXPLICIT));
12551 359 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12552 359 : finish_expr_stmt (stmt);
12553 359 : }
12554 :
12555 : void
12556 397 : finish_omp_depobj (location_t loc, tree depobj,
12557 : enum omp_clause_depend_kind kind, tree clause)
12558 : {
12559 397 : if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
12560 : {
12561 343 : if (!lvalue_p (depobj))
12562 : {
12563 6 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
12564 : "%<depobj%> expression is not lvalue expression");
12565 6 : depobj = error_mark_node;
12566 : }
12567 : }
12568 :
12569 397 : if (processing_template_decl)
12570 : {
12571 114 : if (clause == NULL_TREE)
12572 47 : clause = build_int_cst (integer_type_node, kind);
12573 114 : add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
12574 114 : return;
12575 : }
12576 :
12577 283 : if (!error_operand_p (depobj))
12578 : {
12579 274 : tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
12580 274 : if (addr == error_mark_node)
12581 : depobj = error_mark_node;
12582 : else
12583 274 : depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
12584 : tf_warning_or_error);
12585 : }
12586 :
12587 283 : c_finish_omp_depobj (loc, depobj, kind, clause);
12588 : }
12589 :
12590 : void
12591 162 : finish_omp_flush (int mo)
12592 : {
12593 162 : tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
12594 162 : releasing_vec vec;
12595 162 : if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
12596 : {
12597 54 : fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
12598 54 : vec->quick_push (build_int_cst (integer_type_node, mo));
12599 : }
12600 162 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12601 162 : finish_expr_stmt (stmt);
12602 162 : }
12603 :
12604 : void
12605 111 : finish_omp_taskwait (void)
12606 : {
12607 111 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
12608 111 : releasing_vec vec;
12609 111 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12610 111 : finish_expr_stmt (stmt);
12611 111 : }
12612 :
12613 : void
12614 16 : finish_omp_taskyield (void)
12615 : {
12616 16 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
12617 16 : releasing_vec vec;
12618 16 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12619 16 : finish_expr_stmt (stmt);
12620 16 : }
12621 :
12622 : void
12623 596 : finish_omp_cancel (tree clauses)
12624 : {
12625 596 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
12626 596 : int mask = 0;
12627 596 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12628 : mask = 1;
12629 414 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12630 : mask = 2;
12631 285 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12632 : mask = 4;
12633 164 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12634 : mask = 8;
12635 : else
12636 : {
12637 0 : error ("%<#pragma omp cancel%> must specify one of "
12638 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12639 0 : return;
12640 : }
12641 596 : releasing_vec vec;
12642 596 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
12643 596 : if (ifc != NULL_TREE)
12644 : {
12645 70 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
12646 70 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
12647 6 : error_at (OMP_CLAUSE_LOCATION (ifc),
12648 : "expected %<cancel%> %<if%> clause modifier");
12649 : else
12650 : {
12651 64 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
12652 64 : if (ifc2 != NULL_TREE)
12653 : {
12654 3 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
12655 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
12656 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
12657 3 : error_at (OMP_CLAUSE_LOCATION (ifc2),
12658 : "expected %<cancel%> %<if%> clause modifier");
12659 : }
12660 : }
12661 :
12662 70 : if (!processing_template_decl)
12663 61 : ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
12664 : else
12665 9 : ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
12666 9 : OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
12667 : integer_zero_node, ERROR_MARK,
12668 : NULL_TREE, NULL, tf_warning_or_error);
12669 : }
12670 : else
12671 526 : ifc = boolean_true_node;
12672 596 : vec->quick_push (build_int_cst (integer_type_node, mask));
12673 596 : vec->quick_push (ifc);
12674 596 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12675 596 : finish_expr_stmt (stmt);
12676 596 : }
12677 :
12678 : void
12679 494 : finish_omp_cancellation_point (tree clauses)
12680 : {
12681 494 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
12682 494 : int mask = 0;
12683 494 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12684 : mask = 1;
12685 366 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12686 : mask = 2;
12687 261 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12688 : mask = 4;
12689 156 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12690 : mask = 8;
12691 : else
12692 : {
12693 3 : error ("%<#pragma omp cancellation point%> must specify one of "
12694 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12695 3 : return;
12696 : }
12697 491 : releasing_vec vec
12698 491 : = make_tree_vector_single (build_int_cst (integer_type_node, mask));
12699 491 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12700 491 : finish_expr_stmt (stmt);
12701 491 : }
12702 :
12703 : /* Begin a __transaction_atomic or __transaction_relaxed statement.
12704 : If PCOMPOUND is non-null, this is for a function-transaction-block, and we
12705 : should create an extra compound stmt. */
12706 :
12707 : tree
12708 303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
12709 : {
12710 303 : tree r;
12711 :
12712 303 : if (pcompound)
12713 21 : *pcompound = begin_compound_stmt (0);
12714 :
12715 303 : r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
12716 :
12717 : /* Only add the statement to the function if support enabled. */
12718 303 : if (flag_tm)
12719 297 : add_stmt (r);
12720 : else
12721 12 : error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
12722 : ? G_("%<__transaction_relaxed%> without "
12723 : "transactional memory support enabled")
12724 : : G_("%<__transaction_atomic%> without "
12725 : "transactional memory support enabled")));
12726 :
12727 303 : TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
12728 303 : TREE_SIDE_EFFECTS (r) = 1;
12729 303 : return r;
12730 : }
12731 :
12732 : /* End a __transaction_atomic or __transaction_relaxed statement.
12733 : If COMPOUND_STMT is non-null, this is for a function-transaction-block,
12734 : and we should end the compound. If NOEX is non-NULL, we wrap the body in
12735 : a MUST_NOT_THROW_EXPR with NOEX as condition. */
12736 :
12737 : void
12738 303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
12739 : {
12740 303 : TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
12741 303 : TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
12742 303 : TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
12743 303 : TRANSACTION_EXPR_IS_STMT (stmt) = 1;
12744 :
12745 : /* noexcept specifications are not allowed for function transactions. */
12746 303 : gcc_assert (!(noex && compound_stmt));
12747 303 : if (noex)
12748 : {
12749 51 : tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
12750 : noex);
12751 51 : protected_set_expr_location
12752 51 : (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
12753 51 : TREE_SIDE_EFFECTS (body) = 1;
12754 51 : TRANSACTION_EXPR_BODY (stmt) = body;
12755 : }
12756 :
12757 303 : if (compound_stmt)
12758 21 : finish_compound_stmt (compound_stmt);
12759 303 : }
12760 :
12761 : /* Build a __transaction_atomic or __transaction_relaxed expression. If
12762 : NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
12763 : condition. */
12764 :
12765 : tree
12766 116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
12767 : {
12768 116 : tree ret;
12769 116 : if (noex)
12770 : {
12771 57 : expr = build_must_not_throw_expr (expr, noex);
12772 57 : protected_set_expr_location (expr, loc);
12773 57 : TREE_SIDE_EFFECTS (expr) = 1;
12774 : }
12775 116 : ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
12776 116 : if (flags & TM_STMT_ATTR_RELAXED)
12777 4 : TRANSACTION_EXPR_RELAXED (ret) = 1;
12778 116 : TREE_SIDE_EFFECTS (ret) = 1;
12779 116 : SET_EXPR_LOCATION (ret, loc);
12780 116 : return ret;
12781 : }
12782 :
12783 : void
12784 100241 : init_cp_semantics (void)
12785 : {
12786 100241 : }
12787 :
12788 :
12789 : /* Get constant string at LOCATION. Returns true if successful,
12790 : otherwise false. */
12791 :
12792 : bool
12793 11335579 : cexpr_str::type_check (location_t location, bool allow_char8_t /*=false*/)
12794 : {
12795 11335579 : tsubst_flags_t complain = tf_warning_or_error;
12796 :
12797 11335579 : if (message == NULL_TREE
12798 11335579 : || message == error_mark_node
12799 22671155 : || check_for_bare_parameter_packs (message))
12800 3 : return false;
12801 :
12802 11335576 : if (TREE_CODE (message) != STRING_CST
12803 11335576 : && !type_dependent_expression_p (message))
12804 : {
12805 1053 : message_sz
12806 1053 : = finish_class_member_access_expr (message,
12807 : get_identifier ("size"),
12808 : false, complain);
12809 1053 : if (message_sz != error_mark_node)
12810 952 : message_data
12811 952 : = finish_class_member_access_expr (message,
12812 : get_identifier ("data"),
12813 : false, complain);
12814 1053 : if (message_sz == error_mark_node || message_data == error_mark_node)
12815 : {
12816 139 : error_at (location, "constexpr string must be a string "
12817 : "literal or object with %<size%> and "
12818 : "%<data%> members");
12819 322 : return false;
12820 : }
12821 914 : releasing_vec size_args, data_args;
12822 914 : message_sz = finish_call_expr (message_sz, &size_args, false, false,
12823 : complain);
12824 914 : message_data = finish_call_expr (message_data, &data_args, false, false,
12825 : complain);
12826 914 : if (message_sz == error_mark_node || message_data == error_mark_node)
12827 : return false;
12828 800 : message_sz = build_converted_constant_expr (size_type_node, message_sz,
12829 : complain);
12830 800 : if (message_sz == error_mark_node)
12831 : {
12832 15 : error_at (location, "constexpr string %<size()%> "
12833 : "must be implicitly convertible to "
12834 : "%<std::size_t%>");
12835 15 : return false;
12836 : }
12837 :
12838 785 : if (allow_char8_t
12839 74 : && POINTER_TYPE_P (TREE_TYPE (message_data))
12840 74 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
12841 74 : == char8_type_node)
12842 805 : && (TYPE_QUALS (TREE_TYPE (TREE_TYPE (message_data)))
12843 : == TYPE_QUAL_CONST))
12844 : return true;
12845 :
12846 765 : message_data = build_converted_constant_expr (const_string_type_node,
12847 : message_data, complain);
12848 765 : if (message_data == error_mark_node)
12849 : {
12850 34 : error_at (location, "constexpr string %<data()%> "
12851 : "must be implicitly convertible to "
12852 : "%<const char*%>");
12853 34 : return false;
12854 : }
12855 914 : }
12856 : return true;
12857 : }
12858 :
12859 : /* Extract constant string at LOCATON into output string STR.
12860 : Returns true if successful, otherwise false. */
12861 :
12862 : bool
12863 405 : cexpr_str::extract (location_t location, tree &str)
12864 : {
12865 405 : const char *msg;
12866 405 : int len;
12867 405 : if (!extract (location, msg, len))
12868 : return false;
12869 343 : str = build_string (len, msg);
12870 343 : return true;
12871 : }
12872 :
12873 : /* Extract constant string at LOCATION into output string MSG with LEN.
12874 : Returns true if successful, otherwise false. */
12875 :
12876 : bool
12877 2669 : cexpr_str::extract (location_t location, const char * &msg, int &len,
12878 : const constexpr_ctx *ctx /* = NULL */,
12879 : bool *non_constant_p /* = NULL */,
12880 : bool *overflow_p /* = NULL */,
12881 : tree *jump_target /* = NULL */)
12882 : {
12883 2669 : tsubst_flags_t complain = tf_warning_or_error;
12884 :
12885 2669 : msg = NULL;
12886 2669 : if (message_sz && message_data)
12887 : {
12888 677 : tree msz;
12889 677 : if (ctx)
12890 : {
12891 110 : msz = cxx_eval_constant_expression (ctx, message_sz, vc_prvalue,
12892 : non_constant_p, overflow_p,
12893 : jump_target);
12894 110 : if (*jump_target || *non_constant_p)
12895 : return false;
12896 : }
12897 : else
12898 567 : msz = cxx_constant_value (message_sz, NULL_TREE, complain);
12899 669 : if (!tree_fits_uhwi_p (msz))
12900 : {
12901 35 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
12902 35 : error_at (location,
12903 : "constexpr string %<size()%> "
12904 : "must be a constant expression");
12905 35 : return false;
12906 : }
12907 634 : else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
12908 : != tree_to_uhwi (msz))
12909 : {
12910 0 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
12911 0 : error_at (location,
12912 : "constexpr string message %<size()%> "
12913 : "%qE too large", msz);
12914 0 : return false;
12915 : }
12916 634 : len = tree_to_uhwi (msz);
12917 634 : tree data;
12918 634 : if (ctx)
12919 : {
12920 102 : data = cxx_eval_constant_expression (ctx, message_data, vc_prvalue,
12921 : non_constant_p, overflow_p,
12922 : jump_target);
12923 102 : if (*jump_target || *non_constant_p)
12924 : return false;
12925 94 : STRIP_NOPS (data);
12926 94 : if (TREE_CODE (data) != ADDR_EXPR)
12927 : {
12928 0 : unhandled:
12929 0 : if (!cxx_constexpr_quiet_p (ctx))
12930 0 : error_at (location, "unhandled return from %<data()%>");
12931 0 : return false;
12932 : }
12933 94 : tree str = TREE_OPERAND (data, 0);
12934 94 : unsigned HOST_WIDE_INT off = 0;
12935 94 : if (TREE_CODE (str) == ARRAY_REF
12936 94 : && tree_fits_uhwi_p (TREE_OPERAND (str, 1)))
12937 : {
12938 12 : off = tree_to_uhwi (TREE_OPERAND (str, 1));
12939 12 : str = TREE_OPERAND (str, 0);
12940 : }
12941 94 : str = cxx_eval_constant_expression (ctx, str, vc_prvalue,
12942 : non_constant_p, overflow_p,
12943 : jump_target);
12944 94 : if (*jump_target || *non_constant_p)
12945 : return false;
12946 94 : if (TREE_CODE (str) == STRING_CST)
12947 : {
12948 84 : if (TREE_STRING_LENGTH (str) < len
12949 84 : || (unsigned) TREE_STRING_LENGTH (str) < off
12950 168 : || (unsigned) TREE_STRING_LENGTH (str) < off + len)
12951 0 : goto unhandled;
12952 84 : msg = TREE_STRING_POINTER (str) + off;
12953 84 : goto translate;
12954 : }
12955 10 : if (TREE_CODE (str) != CONSTRUCTOR
12956 10 : || TREE_CODE (TREE_TYPE (str)) != ARRAY_TYPE)
12957 0 : goto unhandled;
12958 10 : char *b;
12959 10 : if (len < 64)
12960 10 : b = XALLOCAVEC (char, len + 1);
12961 : else
12962 : {
12963 0 : buf = XNEWVEC (char, len + 1);
12964 0 : b = buf;
12965 : }
12966 10 : msg = b;
12967 10 : memset (b, 0, len + 1);
12968 10 : tree field, value;
12969 10 : unsigned k;
12970 10 : unsigned HOST_WIDE_INT l = 0;
12971 158 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (str), k, field, value)
12972 158 : if (!tree_fits_shwi_p (value))
12973 0 : goto unhandled;
12974 158 : else if (field == NULL_TREE)
12975 : {
12976 0 : if (integer_zerop (value))
12977 : break;
12978 0 : if (l >= off && l < off + len)
12979 0 : b[l - off] = tree_to_shwi (value);
12980 0 : ++l;
12981 : }
12982 158 : else if (TREE_CODE (field) == RANGE_EXPR)
12983 : {
12984 0 : tree lo = TREE_OPERAND (field, 0);
12985 0 : tree hi = TREE_OPERAND (field, 1);
12986 0 : if (!tree_fits_uhwi_p (lo) || !tree_fits_uhwi_p (hi))
12987 0 : goto unhandled;
12988 0 : if (integer_zerop (value))
12989 : break;
12990 0 : unsigned HOST_WIDE_INT m = tree_to_uhwi (hi);
12991 0 : for (l = tree_to_uhwi (lo); l <= m; ++l)
12992 0 : if (l >= off && l < off + len)
12993 0 : b[l - off] = tree_to_shwi (value);
12994 : }
12995 158 : else if (tree_fits_uhwi_p (field))
12996 : {
12997 158 : l = tree_to_uhwi (field);
12998 158 : if (integer_zerop (value))
12999 : break;
13000 148 : if (l >= off && l < off + len)
13001 148 : b[l - off] = tree_to_shwi (value);
13002 148 : l++;
13003 : }
13004 10 : b[len] = '\0';
13005 : }
13006 : else
13007 : {
13008 532 : data = maybe_constant_value (message_data, NULL_TREE, mce_true);
13009 532 : if (!reduced_constant_expression_p (data))
13010 96 : data = NULL_TREE;
13011 532 : if (len)
13012 : {
13013 455 : if (data)
13014 381 : msg = c_getstr (data);
13015 455 : if (msg == NULL)
13016 119 : buf = XNEWVEC (char, len);
13017 1458 : for (int i = 0; i < len; ++i)
13018 : {
13019 1033 : tree t = message_data;
13020 1033 : if (i)
13021 1156 : t = build2 (POINTER_PLUS_EXPR,
13022 578 : TREE_TYPE (message_data), message_data,
13023 578 : size_int (i));
13024 1033 : t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
13025 1033 : tree t2 = cxx_constant_value (t, NULL_TREE, complain);
13026 1033 : if (!tree_fits_shwi_p (t2))
13027 : {
13028 30 : error_at (location,
13029 : "constexpr string %<data()[%d]%> "
13030 : "must be a constant expression", i);
13031 30 : return false;
13032 : }
13033 1003 : if (msg == NULL)
13034 362 : buf[i] = tree_to_shwi (t2);
13035 : /* If c_getstr worked, just verify the first and
13036 : last characters using constant evaluation. */
13037 641 : else if (len > 2 && i == 0)
13038 268 : i = len - 2;
13039 : }
13040 425 : if (msg == NULL)
13041 104 : msg = buf;
13042 : }
13043 77 : else if (!data)
13044 : {
13045 : /* We don't have any function to test whether some
13046 : expression is a core constant expression. So, instead
13047 : test whether (message.data (), 0) is a constant
13048 : expression. */
13049 22 : data = build2 (COMPOUND_EXPR, integer_type_node,
13050 : message_data, integer_zero_node);
13051 22 : tree t = cxx_constant_value (data, NULL_TREE, complain);
13052 22 : if (!integer_zerop (t))
13053 : {
13054 22 : error_at (location,
13055 : "constexpr string %<data()%> "
13056 : "must be a core constant expression");
13057 22 : return false;
13058 : }
13059 : }
13060 : }
13061 : }
13062 : else
13063 : {
13064 1992 : tree eltype = TREE_TYPE (TREE_TYPE (message));
13065 1992 : int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
13066 1992 : msg = TREE_STRING_POINTER (message);
13067 1992 : len = TREE_STRING_LENGTH (message) / sz - 1;
13068 : }
13069 2566 : translate:
13070 2566 : if ((message_sz && message_data) || ctx)
13071 : {
13072 : /* Convert the string from execution charset to SOURCE_CHARSET. */
13073 768 : cpp_string istr, ostr;
13074 768 : istr.len = len;
13075 768 : istr.text = (const unsigned char *) msg;
13076 768 : enum cpp_ttype type = CPP_STRING;
13077 768 : if (message_sz && message_data)
13078 : {
13079 574 : if (POINTER_TYPE_P (TREE_TYPE (message_data))
13080 574 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
13081 574 : == char8_type_node))
13082 : type = CPP_UTF8STRING;
13083 : }
13084 194 : else if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message)))
13085 194 : == char8_type_node)
13086 768 : type = CPP_UTF8STRING;
13087 768 : if (len == 0)
13088 : ;
13089 643 : else if (!cpp_translate_string (parse_in, &istr, &ostr, type,
13090 : true))
13091 : {
13092 0 : if (type == CPP_UTF8STRING)
13093 0 : error_at (location, "could not convert constexpr string from "
13094 : "UTF-8 encoding to source character "
13095 : "set");
13096 : else
13097 0 : error_at (location, "could not convert constexpr string from "
13098 : "ordinary literal encoding to source character "
13099 : "set");
13100 0 : return false;
13101 : }
13102 : else
13103 : {
13104 643 : if (buf)
13105 104 : XDELETEVEC (buf);
13106 643 : msg = buf = const_cast <char *> ((const char *) ostr.text);
13107 643 : len = ostr.len;
13108 : }
13109 : }
13110 :
13111 : return true;
13112 : }
13113 :
13114 : /* Build a STATIC_ASSERT for a static assertion with the condition
13115 : CONDITION and the message text MESSAGE. LOCATION is the location
13116 : of the static assertion in the source code. When MEMBER_P, this
13117 : static assertion is a member of a class. If SHOW_EXPR_P is true,
13118 : print the condition (because it was instantiation-dependent).
13119 : If CONSTEVAL_BLOCK_P is true, this static assertion represents
13120 : a consteval block. */
13121 :
13122 : void
13123 11334870 : finish_static_assert (tree condition, tree message, location_t location,
13124 : bool member_p, bool show_expr_p,
13125 : bool consteval_block_p/*=false*/)
13126 : {
13127 11334870 : tsubst_flags_t complain = tf_warning_or_error;
13128 :
13129 11334870 : if (condition == NULL_TREE
13130 11334870 : || condition == error_mark_node)
13131 4796753 : return;
13132 :
13133 11334662 : if (check_for_bare_parameter_packs (condition))
13134 : return;
13135 :
13136 11334659 : cexpr_str cstr(message);
13137 11334659 : if (!cstr.type_check (location))
13138 : return;
13139 :
13140 : /* Save the condition in case it was a concept check. */
13141 11334565 : tree orig_condition = condition;
13142 :
13143 11334565 : if (instantiation_dependent_expression_p (condition)
13144 11334565 : || instantiation_dependent_expression_p (message))
13145 : {
13146 : /* We're in a template; build a STATIC_ASSERT and put it in
13147 : the right place. */
13148 4795931 : defer:
13149 4795931 : tree assertion = make_node (STATIC_ASSERT);
13150 4795931 : STATIC_ASSERT_CONDITION (assertion) = orig_condition;
13151 4795931 : STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
13152 4795931 : STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
13153 4795931 : CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
13154 :
13155 4795931 : if (member_p)
13156 2466631 : maybe_add_class_template_decl_list (current_class_type,
13157 : assertion,
13158 : /*friend_p=*/0);
13159 : else
13160 2329300 : add_stmt (assertion);
13161 :
13162 4795931 : return;
13163 : }
13164 :
13165 : /* Evaluate the consteval { }. This must be done only once. */
13166 6544554 : if (consteval_block_p)
13167 : {
13168 492 : cxx_constant_value (condition);
13169 492 : return;
13170 : }
13171 :
13172 : /* Fold the expression and convert it to a boolean value. */
13173 6544062 : condition = contextual_conv_bool (condition, complain);
13174 6544062 : condition = fold_non_dependent_expr (condition, complain,
13175 : /*manifestly_const_eval=*/true);
13176 :
13177 6544060 : if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
13178 : /* Do nothing; the condition is satisfied. */
13179 : ;
13180 : else
13181 : {
13182 8738 : iloc_sentinel ils (location);
13183 :
13184 8738 : if (integer_zerop (condition))
13185 : {
13186 : /* CWG2518: static_assert failure in a template is not IFNDR. */
13187 7880 : if (processing_template_decl)
13188 5920 : goto defer;
13189 :
13190 1960 : int len;
13191 1960 : const char *msg = NULL;
13192 1960 : if (!cstr.extract (location, msg, len))
13193 25 : return;
13194 :
13195 : /* See if we can find which clause was failing (for logical AND). */
13196 1935 : tree bad = find_failing_clause (NULL, orig_condition);
13197 : /* If not, or its location is unusable, fall back to the previous
13198 : location. */
13199 1935 : location_t cloc = cp_expr_loc_or_loc (bad, location);
13200 :
13201 1935 : auto_diagnostic_group d;
13202 :
13203 : /* Report the error. */
13204 1935 : if (len == 0)
13205 1213 : error_at (cloc, "static assertion failed");
13206 : else
13207 722 : error_at (cloc, "static assertion failed: %.*s", len, msg);
13208 :
13209 1935 : diagnose_failing_condition (bad, cloc, show_expr_p);
13210 :
13211 : /* Suppress -Wreturn-type for functions with failed static_asserts.
13212 : Otherwise templates like:
13213 : if constexpr (whatever)
13214 : return something (args);
13215 : else
13216 : static_assert (false, "explanation");
13217 : get a useless extra -Wreturn-type warning. */
13218 1935 : if (current_function_decl)
13219 751 : suppress_warning (current_function_decl, OPT_Wreturn_type);
13220 1935 : }
13221 858 : else if (condition && condition != error_mark_node)
13222 : {
13223 852 : error ("non-constant condition for static assertion");
13224 852 : if (require_rvalue_constant_expression (condition))
13225 790 : cxx_constant_value (condition);
13226 : }
13227 8738 : }
13228 11334657 : }
13229 :
13230 : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
13231 : suitable for use as a type-specifier.
13232 :
13233 : ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
13234 : id-expression or a class member access, FALSE when it was parsed as
13235 : a full expression. */
13236 :
13237 : tree
13238 43545430 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
13239 : tsubst_flags_t complain)
13240 : {
13241 43545430 : tree type = NULL_TREE;
13242 :
13243 43545430 : if (!expr || error_operand_p (expr))
13244 240512 : return error_mark_node;
13245 :
13246 43304918 : if (TYPE_P (expr)
13247 43304918 : || TREE_CODE (expr) == TYPE_DECL
13248 86609816 : || (TREE_CODE (expr) == BIT_NOT_EXPR
13249 16338 : && TYPE_P (TREE_OPERAND (expr, 0))))
13250 : {
13251 29 : if (complain & tf_error)
13252 29 : error ("argument to %<decltype%> must be an expression");
13253 29 : return error_mark_node;
13254 : }
13255 :
13256 : /* decltype is an unevaluated context. */
13257 43304889 : cp_unevaluated u;
13258 :
13259 43304889 : processing_template_decl_sentinel ptds (/*reset=*/false);
13260 :
13261 : /* Depending on the resolution of DR 1172, we may later need to distinguish
13262 : instantiation-dependent but not type-dependent expressions so that, say,
13263 : A<decltype(sizeof(T))>::U doesn't require 'typename'. */
13264 43304889 : if (instantiation_dependent_uneval_expression_p (expr))
13265 : {
13266 7357145 : dependent:
13267 7357721 : type = cxx_make_type (DECLTYPE_TYPE);
13268 7357721 : DECLTYPE_TYPE_EXPR (type) = expr;
13269 14715442 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
13270 7357721 : = id_expression_or_member_access_p;
13271 7357721 : SET_TYPE_STRUCTURAL_EQUALITY (type);
13272 :
13273 7357721 : return type;
13274 : }
13275 35947744 : else if (processing_template_decl)
13276 : {
13277 7346 : expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
13278 7346 : if (expr == error_mark_node)
13279 : return error_mark_node;
13280 : /* Keep processing_template_decl cleared for the rest of the function
13281 : (for sake of the call to lvalue_kind below, which handles templated
13282 : and non-templated COND_EXPR differently). */
13283 7309 : processing_template_decl = 0;
13284 : }
13285 :
13286 : /* The type denoted by decltype(e) is defined as follows: */
13287 :
13288 35947707 : expr = resolve_nondeduced_context (expr, complain);
13289 35947707 : if (!mark_single_function (expr, complain))
13290 0 : return error_mark_node;
13291 :
13292 35947707 : if (invalid_nonstatic_memfn_p (input_location, expr, complain))
13293 18 : return error_mark_node;
13294 :
13295 35947689 : if (type_unknown_p (expr))
13296 : {
13297 18 : if (complain & tf_error)
13298 6 : error ("%<decltype%> cannot resolve address of overloaded function");
13299 18 : return error_mark_node;
13300 : }
13301 :
13302 35947671 : if (id_expression_or_member_access_p)
13303 : {
13304 : /* If e is an id-expression or a class member access (5.2.5
13305 : [expr.ref]), decltype(e) is defined as the type of the entity
13306 : named by e. If there is no such entity, or e names a set of
13307 : overloaded functions, the program is ill-formed. */
13308 536078 : if (identifier_p (expr))
13309 0 : expr = lookup_name (expr);
13310 :
13311 : /* If e is a constified expression inside a contract assertion,
13312 : strip the const wrapper. Per P2900R14, "For a function f with the
13313 : return type T , the result name is an lvalue of type const T , decltype(r)
13314 : is T , and decltype((r)) is const T&." */
13315 536078 : expr = strip_contract_const_wrapper (expr);
13316 :
13317 367102 : if (REFERENCE_REF_P (expr)
13318 536083 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
13319 : /* This can happen when the expression is, e.g., "a.b". Just
13320 : look at the underlying operand. */
13321 370373 : expr = TREE_OPERAND (expr, 0);
13322 :
13323 536078 : if (TREE_CODE (expr) == OFFSET_REF
13324 536078 : || TREE_CODE (expr) == MEMBER_REF
13325 536078 : || TREE_CODE (expr) == SCOPE_REF)
13326 : /* We're only interested in the field itself. If it is a
13327 : BASELINK, we will need to see through it in the next
13328 : step. */
13329 0 : expr = TREE_OPERAND (expr, 1);
13330 :
13331 536078 : if (BASELINK_P (expr))
13332 : /* See through BASELINK nodes to the underlying function. */
13333 7 : expr = BASELINK_FUNCTIONS (expr);
13334 :
13335 : /* decltype of a decomposition name drops references in the tuple case
13336 : (unlike decltype of a normal variable) and keeps cv-qualifiers from
13337 : the containing object in the other cases (unlike decltype of a member
13338 : access expression). */
13339 536078 : if (DECL_DECOMPOSITION_P (expr))
13340 : {
13341 1449 : if (ptds.saved)
13342 : {
13343 275 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr)
13344 : || (DECL_CONTEXT (expr)
13345 : != current_function_decl));
13346 : /* DECL_HAS_VALUE_EXPR_P is always set if
13347 : processing_template_decl at least for structured bindings
13348 : within the template. If lookup_decomp_type
13349 : returns non-NULL, it is the tuple case. */
13350 275 : if (tree ret = lookup_decomp_type (expr))
13351 : return ret;
13352 191 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
13353 : }
13354 1365 : if (DECL_HAS_VALUE_EXPR_P (expr))
13355 : /* Expr is an array or struct subobject proxy, handle
13356 : bit-fields properly. */
13357 1021 : return unlowered_expr_type (expr);
13358 : else
13359 : /* Expr is a reference variable for the tuple case. */
13360 344 : return lookup_decomp_type (expr);
13361 : }
13362 :
13363 534629 : switch (TREE_CODE (expr))
13364 : {
13365 650 : case FIELD_DECL:
13366 650 : if (DECL_BIT_FIELD_TYPE (expr))
13367 : {
13368 : type = DECL_BIT_FIELD_TYPE (expr);
13369 : break;
13370 : }
13371 : /* Fall through for fields that aren't bitfields. */
13372 141830 : gcc_fallthrough ();
13373 :
13374 141830 : case VAR_DECL:
13375 141830 : if (is_capture_proxy (expr))
13376 : {
13377 99 : if (is_normal_capture_proxy (expr))
13378 : {
13379 21 : expr = DECL_CAPTURED_VARIABLE (expr);
13380 21 : type = TREE_TYPE (expr);
13381 : }
13382 : else
13383 : {
13384 78 : expr = DECL_VALUE_EXPR (expr);
13385 78 : gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
13386 78 : expr = TREE_OPERAND (expr, 1);
13387 78 : type = TREE_TYPE (expr);
13388 : }
13389 : break;
13390 : }
13391 : /* Fall through for variables that aren't capture proxies. */
13392 523610 : gcc_fallthrough ();
13393 :
13394 523610 : case FUNCTION_DECL:
13395 523610 : case CONST_DECL:
13396 523610 : case PARM_DECL:
13397 523610 : case RESULT_DECL:
13398 523610 : case TEMPLATE_PARM_INDEX:
13399 523610 : expr = mark_type_use (expr);
13400 523610 : type = TREE_TYPE (expr);
13401 523610 : if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
13402 : {
13403 : /* decltype of an NTTP object is the type of the template
13404 : parameter, which is the object type modulo cv-quals. */
13405 2643 : int quals = cp_type_quals (type);
13406 2643 : gcc_checking_assert (quals & TYPE_QUAL_CONST);
13407 2643 : type = cv_unqualified (type);
13408 : }
13409 : break;
13410 :
13411 0 : case ERROR_MARK:
13412 0 : type = error_mark_node;
13413 0 : break;
13414 :
13415 3492 : case COMPONENT_REF:
13416 3492 : case COMPOUND_EXPR:
13417 3492 : mark_type_use (expr);
13418 3492 : type = is_bitfield_expr_with_lowered_type (expr);
13419 3492 : if (!type)
13420 3455 : type = TREE_TYPE (TREE_OPERAND (expr, 1));
13421 : break;
13422 :
13423 0 : case BIT_FIELD_REF:
13424 0 : gcc_unreachable ();
13425 :
13426 3481 : case INTEGER_CST:
13427 3481 : case PTRMEM_CST:
13428 : /* We can get here when the id-expression refers to an
13429 : enumerator or non-type template parameter. */
13430 3481 : type = TREE_TYPE (expr);
13431 3481 : break;
13432 :
13433 3947 : default:
13434 : /* Handle instantiated template non-type arguments. */
13435 3947 : type = TREE_TYPE (expr);
13436 3947 : break;
13437 : }
13438 : }
13439 : else
13440 : {
13441 35411593 : tree decl = STRIP_REFERENCE_REF (expr);
13442 35411593 : tree lam = current_lambda_expr ();
13443 35411593 : if (lam && outer_automatic_var_p (decl))
13444 : {
13445 : /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
13446 : unevaluated operand within S would refer to an entity captured by
13447 : copy in some intervening lambda-expression, then let E be the
13448 : innermost such lambda-expression.
13449 :
13450 : If there is such a lambda-expression and if P is in E's function
13451 : parameter scope but not its parameter-declaration-clause, then the
13452 : type of the expression is the type of a class member access
13453 : expression naming the non-static data member that would be declared
13454 : for such a capture in the object parameter of the function call
13455 : operator of E." */
13456 : /* FIXME: This transformation needs to happen for all uses of an outer
13457 : local variable inside decltype, not just decltype((x)) (PR83167).
13458 : And we don't handle nested lambdas properly, where we need to
13459 : consider the outer lambdas as well (PR112926). */
13460 1379 : tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
13461 : LOOK_want::HIDDEN_LAMBDA);
13462 :
13463 1379 : if (cap && is_capture_proxy (cap))
13464 467 : type = TREE_TYPE (cap);
13465 912 : else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
13466 : {
13467 738 : type = TREE_TYPE (decl);
13468 738 : if (TYPE_REF_P (type)
13469 738 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
13470 36 : type = TREE_TYPE (type);
13471 : }
13472 :
13473 1205 : if (type && !TYPE_REF_P (type))
13474 : {
13475 1121 : int quals;
13476 1121 : if (current_function_decl
13477 2104 : && LAMBDA_FUNCTION_P (current_function_decl)
13478 2104 : && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
13479 : {
13480 900 : tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
13481 900 : if (WILDCARD_TYPE_P (non_reference (obtype)))
13482 : /* We don't know what the eventual obtype quals will be. */
13483 576 : goto dependent;
13484 648 : auto direct_type = [](tree t){
13485 324 : if (INDIRECT_TYPE_P (t))
13486 162 : return TREE_TYPE (t);
13487 : return t;
13488 : };
13489 648 : quals = (cp_type_quals (type)
13490 324 : | cp_type_quals (direct_type (obtype)));
13491 : }
13492 : else
13493 : /* We are in the parameter clause, trailing return type, or
13494 : the requires clause and have no relevant c_f_decl yet. */
13495 349 : quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
13496 221 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
13497 545 : type = cp_build_qualified_type (type, quals);
13498 545 : type = build_reference_type (type);
13499 : }
13500 : }
13501 35410214 : else if (error_operand_p (expr))
13502 0 : type = error_mark_node;
13503 35410214 : else if (expr == current_class_ptr)
13504 : /* If the expression is just "this", we want the
13505 : cv-unqualified pointer for the "this" type. */
13506 0 : type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
13507 :
13508 545 : if (!type)
13509 : {
13510 : /* Otherwise, where T is the type of e, if e is an lvalue,
13511 : decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
13512 35410388 : cp_lvalue_kind clk = lvalue_kind (expr);
13513 35410388 : type = unlowered_expr_type (expr);
13514 35410388 : gcc_assert (!TYPE_REF_P (type));
13515 :
13516 : /* For vector types, pick a non-opaque variant. */
13517 35410388 : if (VECTOR_TYPE_P (type))
13518 4421 : type = strip_typedefs (type);
13519 :
13520 35410388 : if (clk != clk_none && !(clk & clk_class))
13521 8986766 : type = cp_build_reference_type (type, (clk & clk_rvalueref));
13522 : }
13523 : }
13524 :
13525 : return type;
13526 43304889 : }
13527 :
13528 : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
13529 : __has_nothrow_copy, depending on assign_p. Returns true iff all
13530 : the copy {ctor,assign} fns are nothrow. */
13531 :
13532 : static bool
13533 279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
13534 : {
13535 279 : tree fns = NULL_TREE;
13536 :
13537 279 : if (assign_p || TYPE_HAS_COPY_CTOR (type))
13538 276 : fns = get_class_binding (type, assign_p ? assign_op_identifier
13539 : : ctor_identifier);
13540 :
13541 279 : bool saw_copy = false;
13542 696 : for (ovl_iterator iter (fns); iter; ++iter)
13543 : {
13544 441 : tree fn = *iter;
13545 :
13546 441 : if (copy_fn_p (fn) > 0)
13547 : {
13548 423 : saw_copy = true;
13549 423 : if (!maybe_instantiate_noexcept (fn)
13550 423 : || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
13551 192 : return false;
13552 : }
13553 : }
13554 :
13555 87 : return saw_copy;
13556 : }
13557 :
13558 : /* Return true if BASE is a pointer-interconvertible base of DERIVED. */
13559 :
13560 : bool
13561 183 : pointer_interconvertible_base_of_p (tree base, tree derived,
13562 : bool explain/*=false*/)
13563 : {
13564 183 : if (base == error_mark_node || derived == error_mark_node)
13565 : return false;
13566 :
13567 183 : base = TYPE_MAIN_VARIANT (base);
13568 183 : derived = TYPE_MAIN_VARIANT (derived);
13569 183 : if (!NON_UNION_CLASS_TYPE_P (base))
13570 : {
13571 17 : if (explain)
13572 3 : inform (location_of (base),
13573 : "%qT is not a non-union class type", base);
13574 17 : return false;
13575 : }
13576 166 : if (!NON_UNION_CLASS_TYPE_P (derived))
13577 : {
13578 8 : if (explain)
13579 3 : inform (location_of (derived),
13580 : "%qT is not a non-union class type", derived);
13581 8 : return false;
13582 : }
13583 :
13584 158 : if (same_type_p (base, derived))
13585 : return true;
13586 :
13587 117 : if (!std_layout_type_p (derived))
13588 : {
13589 18 : if (explain)
13590 6 : inform (location_of (derived),
13591 : "%qT is not a standard-layout type", derived);
13592 18 : return false;
13593 : }
13594 :
13595 99 : if (!uniquely_derived_from_p (base, derived))
13596 : {
13597 18 : if (explain)
13598 : {
13599 : /* An ambiguous base should already be impossible due to
13600 : the std_layout_type_p check. */
13601 3 : gcc_checking_assert (!DERIVED_FROM_P (base, derived));
13602 3 : inform (location_of (derived),
13603 : "%qT is not a base of %qT", base, derived);
13604 : }
13605 18 : return false;
13606 : }
13607 :
13608 : return true;
13609 : }
13610 :
13611 : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
13612 : return true if MEMBERTYPE is the type of the first non-static data member
13613 : of TYPE or for unions of any members. */
13614 : static bool
13615 637 : first_nonstatic_data_member_p (tree type, tree membertype)
13616 : {
13617 1297 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
13618 : {
13619 1222 : if (TREE_CODE (field) != FIELD_DECL)
13620 135 : continue;
13621 1087 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
13622 60 : continue;
13623 1027 : if (DECL_FIELD_IS_BASE (field))
13624 45 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
13625 982 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13626 : {
13627 216 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
13628 138 : || std_layout_type_p (TREE_TYPE (field)))
13629 294 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
13630 : return true;
13631 : }
13632 766 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13633 : membertype))
13634 : return true;
13635 537 : if (TREE_CODE (type) != UNION_TYPE)
13636 : return false;
13637 : }
13638 : return false;
13639 : }
13640 :
13641 : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
13642 :
13643 : tree
13644 536 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
13645 : tree *args)
13646 : {
13647 : /* Unless users call the builtin directly, the following 3 checks should be
13648 : ensured from std::is_pointer_interconvertible_with_class function
13649 : template. */
13650 536 : if (nargs != 1)
13651 : {
13652 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13653 : "needs a single argument");
13654 6 : return boolean_false_node;
13655 : }
13656 530 : tree arg = args[0];
13657 530 : if (error_operand_p (arg))
13658 0 : return boolean_false_node;
13659 530 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
13660 : {
13661 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13662 : "argument is not pointer to member");
13663 6 : return boolean_false_node;
13664 : }
13665 :
13666 524 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
13667 18 : return boolean_false_node;
13668 :
13669 506 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
13670 506 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
13671 506 : if (!complete_type_or_else (basetype, NULL_TREE))
13672 3 : return boolean_false_node;
13673 :
13674 503 : if (TREE_CODE (basetype) != UNION_TYPE
13675 503 : && !std_layout_type_p (basetype))
13676 22 : return boolean_false_node;
13677 :
13678 481 : if (!first_nonstatic_data_member_p (basetype, membertype))
13679 132 : return boolean_false_node;
13680 :
13681 349 : if (TREE_CODE (arg) == PTRMEM_CST)
13682 68 : arg = cplus_expand_constant (arg);
13683 :
13684 349 : if (integer_nonzerop (arg))
13685 10 : return boolean_false_node;
13686 339 : if (integer_zerop (arg))
13687 71 : return boolean_true_node;
13688 :
13689 268 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
13690 : build_zero_cst (TREE_TYPE (arg)));
13691 : }
13692 :
13693 : /* Helper function for is_corresponding_member_aggr. Return true if
13694 : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
13695 : union or structure BASETYPE. */
13696 :
13697 : static bool
13698 90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
13699 : {
13700 222 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
13701 192 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
13702 36 : continue;
13703 156 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13704 : membertype))
13705 : {
13706 48 : if (TREE_CODE (arg) != INTEGER_CST
13707 48 : || tree_int_cst_equal (arg, byte_position (field)))
13708 48 : return true;
13709 : }
13710 108 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13711 : {
13712 18 : tree narg = arg;
13713 18 : if (TREE_CODE (basetype) != UNION_TYPE
13714 0 : && TREE_CODE (narg) == INTEGER_CST)
13715 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
13716 18 : if (is_corresponding_member_union (TREE_TYPE (field),
13717 : membertype, narg))
13718 : return true;
13719 : }
13720 : return false;
13721 : }
13722 :
13723 : /* Helper function for fold_builtin_is_corresponding_member call.
13724 : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
13725 : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
13726 : boolean_true_node if they are corresponding members, or for
13727 : non-constant ARG2 the highest member offset for corresponding
13728 : members. */
13729 :
13730 : static tree
13731 550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
13732 : tree arg1, tree basetype2, tree membertype2,
13733 : tree arg2)
13734 : {
13735 550 : tree field1 = TYPE_FIELDS (basetype1);
13736 550 : tree field2 = TYPE_FIELDS (basetype2);
13737 550 : tree ret = boolean_false_node;
13738 2376 : while (1)
13739 : {
13740 1463 : bool r = next_common_initial_sequence (field1, field2);
13741 1463 : if (field1 == NULL_TREE || field2 == NULL_TREE)
13742 : break;
13743 1331 : if (r
13744 1038 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
13745 : membertype1)
13746 1841 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
13747 : membertype2))
13748 : {
13749 504 : tree pos = byte_position (field1);
13750 504 : if (TREE_CODE (arg1) == INTEGER_CST
13751 504 : && tree_int_cst_equal (arg1, pos))
13752 : {
13753 92 : if (TREE_CODE (arg2) == INTEGER_CST)
13754 92 : return boolean_true_node;
13755 : return pos;
13756 : }
13757 412 : else if (TREE_CODE (arg1) != INTEGER_CST)
13758 1188 : ret = pos;
13759 : }
13760 1654 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
13761 944 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
13762 : {
13763 117 : if ((!lookup_attribute ("no_unique_address",
13764 117 : DECL_ATTRIBUTES (field1)))
13765 117 : != !lookup_attribute ("no_unique_address",
13766 117 : DECL_ATTRIBUTES (field2)))
13767 : break;
13768 117 : if (!tree_int_cst_equal (bit_position (field1),
13769 117 : bit_position (field2)))
13770 : break;
13771 99 : bool overlap = true;
13772 99 : tree pos = byte_position (field1);
13773 99 : if (TREE_CODE (arg1) == INTEGER_CST)
13774 : {
13775 27 : tree off1 = fold_convert (sizetype, arg1);
13776 27 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
13777 27 : if (tree_int_cst_lt (off1, pos)
13778 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
13779 : overlap = false;
13780 : }
13781 99 : if (TREE_CODE (arg2) == INTEGER_CST)
13782 : {
13783 27 : tree off2 = fold_convert (sizetype, arg2);
13784 27 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
13785 27 : if (tree_int_cst_lt (off2, pos)
13786 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
13787 : overlap = false;
13788 : }
13789 87 : if (overlap
13790 87 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
13791 126 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
13792 : {
13793 39 : tree narg1 = arg1;
13794 39 : if (TREE_CODE (arg1) == INTEGER_CST)
13795 9 : narg1 = size_binop (MINUS_EXPR,
13796 : fold_convert (sizetype, arg1), pos);
13797 39 : tree narg2 = arg2;
13798 39 : if (TREE_CODE (arg2) == INTEGER_CST)
13799 9 : narg2 = size_binop (MINUS_EXPR,
13800 : fold_convert (sizetype, arg2), pos);
13801 39 : tree t1 = TREE_TYPE (field1);
13802 39 : tree t2 = TREE_TYPE (field2);
13803 39 : tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
13804 : narg1, t2, membertype2,
13805 : narg2);
13806 39 : if (nret != boolean_false_node)
13807 : {
13808 39 : if (nret == boolean_true_node)
13809 : return nret;
13810 30 : if (TREE_CODE (arg1) == INTEGER_CST)
13811 0 : return size_binop (PLUS_EXPR, nret, pos);
13812 30 : ret = size_binop (PLUS_EXPR, nret, pos);
13813 : }
13814 : }
13815 60 : else if (overlap
13816 48 : && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
13817 108 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
13818 : {
13819 48 : tree narg1 = arg1;
13820 48 : if (TREE_CODE (arg1) == INTEGER_CST)
13821 6 : narg1 = size_binop (MINUS_EXPR,
13822 : fold_convert (sizetype, arg1), pos);
13823 48 : tree narg2 = arg2;
13824 48 : if (TREE_CODE (arg2) == INTEGER_CST)
13825 6 : narg2 = size_binop (MINUS_EXPR,
13826 : fold_convert (sizetype, arg2), pos);
13827 48 : if (is_corresponding_member_union (TREE_TYPE (field1),
13828 : membertype1, narg1)
13829 48 : && is_corresponding_member_union (TREE_TYPE (field2),
13830 : membertype2, narg2))
13831 : {
13832 24 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
13833 : "not well defined for anonymous unions");
13834 24 : return boolean_false_node;
13835 : }
13836 : }
13837 : }
13838 1188 : if (!r)
13839 : break;
13840 913 : field1 = DECL_CHAIN (field1);
13841 913 : field2 = DECL_CHAIN (field2);
13842 913 : }
13843 : return ret;
13844 : }
13845 :
13846 : /* Fold __builtin_is_corresponding_member call. */
13847 :
13848 : tree
13849 699 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
13850 : tree *args)
13851 : {
13852 : /* Unless users call the builtin directly, the following 3 checks should be
13853 : ensured from std::is_corresponding_member function template. */
13854 699 : if (nargs != 2)
13855 : {
13856 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13857 : "needs two arguments");
13858 9 : return boolean_false_node;
13859 : }
13860 690 : tree arg1 = args[0];
13861 690 : tree arg2 = args[1];
13862 690 : if (error_operand_p (arg1) || error_operand_p (arg2))
13863 0 : return boolean_false_node;
13864 711 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
13865 705 : || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
13866 : {
13867 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13868 : "argument is not pointer to member");
13869 9 : return boolean_false_node;
13870 : }
13871 :
13872 681 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
13873 681 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
13874 15 : return boolean_false_node;
13875 :
13876 666 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
13877 666 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
13878 666 : if (!complete_type_or_else (basetype1, NULL_TREE))
13879 12 : return boolean_false_node;
13880 :
13881 654 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
13882 654 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
13883 654 : if (!complete_type_or_else (basetype2, NULL_TREE))
13884 12 : return boolean_false_node;
13885 :
13886 627 : if (!NON_UNION_CLASS_TYPE_P (basetype1)
13887 627 : || !NON_UNION_CLASS_TYPE_P (basetype2)
13888 627 : || !std_layout_type_p (basetype1)
13889 1233 : || !std_layout_type_p (basetype2))
13890 51 : return boolean_false_node;
13891 :
13892 : /* If the member types aren't layout compatible, then they
13893 : can't be corresponding members. */
13894 591 : if (!layout_compatible_type_p (membertype1, membertype2))
13895 18 : return boolean_false_node;
13896 :
13897 573 : if (TREE_CODE (arg1) == PTRMEM_CST)
13898 176 : arg1 = cplus_expand_constant (arg1);
13899 573 : if (TREE_CODE (arg2) == PTRMEM_CST)
13900 182 : arg2 = cplus_expand_constant (arg2);
13901 :
13902 573 : if (null_member_pointer_value_p (arg1)
13903 573 : || null_member_pointer_value_p (arg2))
13904 9 : return boolean_false_node;
13905 :
13906 564 : if (TREE_CODE (arg1) == INTEGER_CST
13907 182 : && TREE_CODE (arg2) == INTEGER_CST
13908 746 : && !tree_int_cst_equal (arg1, arg2))
13909 53 : return boolean_false_node;
13910 :
13911 511 : if (TREE_CODE (arg2) == INTEGER_CST
13912 129 : && TREE_CODE (arg1) != INTEGER_CST)
13913 : {
13914 : std::swap (arg1, arg2);
13915 : std::swap (membertype1, membertype2);
13916 : std::swap (basetype1, basetype2);
13917 : }
13918 :
13919 511 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
13920 : basetype2, membertype2, arg2);
13921 511 : if (TREE_TYPE (ret) == boolean_type_node)
13922 : return ret;
13923 : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
13924 : already returns boolean_{true,false}_node whether those particular
13925 : members are corresponding members or not. Otherwise, if only
13926 : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
13927 : above), it returns boolean_false_node if it is certainly not a
13928 : corresponding member and otherwise we need to do a runtime check that
13929 : those two OFFSET_TYPE offsets are equal.
13930 : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
13931 : returns the largest offset at which the members would be corresponding
13932 : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
13933 304 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
13934 304 : if (TREE_CODE (arg1) == INTEGER_CST)
13935 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13936 : fold_convert (TREE_TYPE (arg1), arg2));
13937 304 : ret = fold_build2 (LE_EXPR, boolean_type_node,
13938 : fold_convert (pointer_sized_int_node, arg1),
13939 : fold_convert (pointer_sized_int_node, ret));
13940 304 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
13941 : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13942 : fold_convert (TREE_TYPE (arg1), arg2)));
13943 : }
13944 :
13945 : /* Fold __builtin_is_string_literal call. */
13946 :
13947 : tree
13948 4156 : fold_builtin_is_string_literal (location_t loc, int nargs, tree *args)
13949 : {
13950 : /* Unless users call the builtin directly, the following 3 checks should be
13951 : ensured from std::is_string_literal overloads. */
13952 4156 : if (nargs != 1)
13953 : {
13954 0 : error_at (loc, "%<__builtin_is_string_literal%> needs a single "
13955 : "argument");
13956 0 : return boolean_false_node;
13957 : }
13958 4156 : tree arg = args[0];
13959 4156 : if (error_operand_p (arg))
13960 0 : return boolean_false_node;
13961 4156 : if (!TYPE_PTR_P (TREE_TYPE (arg))
13962 4156 : || !TYPE_READONLY (TREE_TYPE (TREE_TYPE (arg)))
13963 8312 : || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (arg))))
13964 : {
13965 0 : arg_invalid:
13966 0 : error_at (loc, "%<__builtin_is_string_literal%> "
13967 : "argument is not %<const char*%>, %<const wchar_t*%>, "
13968 : "%<const char8_t*%>, %<const char16_t*%> or "
13969 : "%<const char32_t*%>");
13970 0 : return boolean_false_node;
13971 : }
13972 4156 : tree chart = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg)));
13973 4156 : if (chart != char_type_node
13974 3320 : && chart != wchar_type_node
13975 2490 : && chart != char8_type_node
13976 1660 : && chart != char16_type_node
13977 830 : && chart != char32_type_node)
13978 0 : goto arg_invalid;
13979 :
13980 4156 : STRIP_NOPS (arg);
13981 8324 : while (TREE_CODE (arg) == POINTER_PLUS_EXPR)
13982 : {
13983 12 : arg = TREE_OPERAND (arg, 0);
13984 12 : STRIP_NOPS (arg);
13985 : }
13986 4156 : if (TREE_CODE (arg) != ADDR_EXPR)
13987 4100 : return boolean_false_node;
13988 56 : arg = TREE_OPERAND (arg, 0);
13989 56 : if (TREE_CODE (arg) == ARRAY_REF)
13990 24 : arg = TREE_OPERAND (arg, 0);
13991 56 : if (TREE_CODE (arg) != STRING_CST)
13992 16 : return boolean_false_node;
13993 40 : return boolean_true_node;
13994 : }
13995 :
13996 : /* [basic.types] 8. True iff TYPE is an object type. */
13997 :
13998 : static bool
13999 2927357 : object_type_p (const_tree type)
14000 : {
14001 2927357 : return (TREE_CODE (type) != FUNCTION_TYPE
14002 0 : && !TYPE_REF_P (type)
14003 2927357 : && !VOID_TYPE_P (type));
14004 : }
14005 :
14006 : /* [defns.referenceable] True iff TYPE is a referenceable type. */
14007 :
14008 : static bool
14009 3572139 : referenceable_type_p (const_tree type)
14010 : {
14011 3572139 : return (TYPE_REF_P (type)
14012 3572595 : || object_type_p (type)
14013 3572595 : || (FUNC_OR_METHOD_TYPE_P (type)
14014 385 : && type_memfn_quals (type) == TYPE_UNQUALIFIED
14015 319 : && type_memfn_rqual (type) == REF_QUAL_NONE));
14016 : }
14017 :
14018 : /* Actually evaluates the trait. */
14019 :
14020 : static bool
14021 18135645 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
14022 : {
14023 18135645 : enum tree_code type_code1;
14024 18135645 : tree t;
14025 :
14026 18135645 : type_code1 = TREE_CODE (type1);
14027 :
14028 18135645 : switch (kind)
14029 : {
14030 317 : case CPTK_HAS_NOTHROW_ASSIGN:
14031 317 : type1 = strip_array_types (type1);
14032 601 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
14033 601 : && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
14034 173 : || (CLASS_TYPE_P (type1)
14035 129 : && classtype_has_nothrow_assign_or_copy_p (type1,
14036 : true))));
14037 :
14038 215 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
14039 215 : type1 = strip_array_types (type1);
14040 215 : return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
14041 215 : || (CLASS_TYPE_P (type1)
14042 93 : && (t = locate_ctor (type1))
14043 60 : && maybe_instantiate_noexcept (t)
14044 58 : && TYPE_NOTHROW_P (TREE_TYPE (t))));
14045 :
14046 305 : case CPTK_HAS_NOTHROW_COPY:
14047 305 : type1 = strip_array_types (type1);
14048 305 : return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
14049 305 : || (CLASS_TYPE_P (type1)
14050 150 : && classtype_has_nothrow_assign_or_copy_p (type1, false)));
14051 :
14052 517 : case CPTK_HAS_TRIVIAL_ASSIGN:
14053 : /* ??? The standard seems to be missing the "or array of such a class
14054 : type" wording for this trait. */
14055 517 : type1 = strip_array_types (type1);
14056 1016 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
14057 1001 : && (trivial_type_p (type1)
14058 307 : || (CLASS_TYPE_P (type1)
14059 222 : && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
14060 :
14061 543 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14062 543 : type1 = strip_array_types (type1);
14063 543 : return (trivial_type_p (type1)
14064 543 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
14065 :
14066 526 : case CPTK_HAS_TRIVIAL_COPY:
14067 : /* ??? The standard seems to be missing the "or array of such a class
14068 : type" wording for this trait. */
14069 526 : type1 = strip_array_types (type1);
14070 878 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14071 863 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
14072 :
14073 762 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14074 762 : type1 = strip_array_types (type1);
14075 762 : if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
14076 : {
14077 123 : deferring_access_check_sentinel dacs (dk_no_check);
14078 123 : cp_unevaluated un;
14079 123 : tree fn = get_dtor (type1, tf_none);
14080 123 : if (!fn && !seen_error ())
14081 3 : warning (0, "checking %qs for type %qT with a destructor that "
14082 : "cannot be called", "__has_trivial_destructor", type1);
14083 123 : }
14084 1094 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14085 1091 : || (CLASS_TYPE_P (type1)
14086 285 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
14087 :
14088 61173 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14089 61173 : return type_has_unique_obj_representations (type1);
14090 :
14091 311 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14092 311 : return type_has_virtual_destructor (type1);
14093 :
14094 56520 : case CPTK_IS_ABSTRACT:
14095 56520 : return ABSTRACT_CLASS_TYPE_P (type1);
14096 :
14097 871 : case CPTK_IS_AGGREGATE:
14098 871 : return CP_AGGREGATE_TYPE_P (type1);
14099 :
14100 370382 : case CPTK_IS_ARRAY:
14101 370382 : return (type_code1 == ARRAY_TYPE
14102 : /* We don't want to report T[0] as being an array type.
14103 : This is for compatibility with an implementation of
14104 : std::is_array by template argument deduction, because
14105 : compute_array_index_type_loc rejects a zero-size array
14106 : in SFINAE context. */
14107 370382 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14108 :
14109 1028320 : case CPTK_IS_ASSIGNABLE:
14110 1028320 : return is_xible (MODIFY_EXPR, type1, type2);
14111 :
14112 517139 : case CPTK_IS_BASE_OF:
14113 517048 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14114 1015380 : && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
14115 470003 : || DERIVED_FROM_P (type1, type2)));
14116 :
14117 58018 : case CPTK_IS_BOUNDED_ARRAY:
14118 58018 : return (type_code1 == ARRAY_TYPE
14119 1660 : && TYPE_DOMAIN (type1)
14120 : /* We don't want to report T[0] as being a bounded array type.
14121 : This is for compatibility with an implementation of
14122 : std::is_bounded_array by template argument deduction, because
14123 : compute_array_index_type_loc rejects a zero-size array
14124 : in SFINAE context. */
14125 59550 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14126 :
14127 538167 : case CPTK_IS_CLASS:
14128 538167 : return NON_UNION_CLASS_TYPE_P (type1);
14129 :
14130 591333 : case CPTK_IS_CONST:
14131 591333 : return CP_TYPE_CONST_P (type1);
14132 :
14133 2397339 : case CPTK_IS_CONSTRUCTIBLE:
14134 2397339 : return is_xible (INIT_EXPR, type1, type2);
14135 :
14136 3180955 : case CPTK_IS_CONVERTIBLE:
14137 3180955 : return is_convertible (type1, type2);
14138 :
14139 3291 : case CPTK_IS_DESTRUCTIBLE:
14140 3291 : return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14141 :
14142 218351 : case CPTK_IS_EMPTY:
14143 218351 : return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
14144 :
14145 677295 : case CPTK_IS_ENUM:
14146 677295 : return type_code1 == ENUMERAL_TYPE;
14147 :
14148 434084 : case CPTK_IS_FINAL:
14149 434084 : return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
14150 :
14151 48120 : case CPTK_IS_FUNCTION:
14152 48120 : return type_code1 == FUNCTION_TYPE;
14153 :
14154 1247 : case CPTK_IS_IMPLICIT_LIFETIME:
14155 1247 : return implicit_lifetime_type_p (type1);
14156 :
14157 49052 : case CPTK_IS_INVOCABLE:
14158 49052 : return !error_operand_p (build_invoke (type1, type2, tf_none));
14159 :
14160 221 : case CPTK_IS_LAYOUT_COMPATIBLE:
14161 221 : return layout_compatible_type_p (type1, type2);
14162 :
14163 197 : case CPTK_IS_LITERAL_TYPE:
14164 197 : return literal_type_p (type1);
14165 :
14166 48822 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14167 48822 : return TYPE_PTRMEMFUNC_P (type1);
14168 :
14169 48809 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14170 48809 : return TYPE_PTRDATAMEM_P (type1);
14171 :
14172 11012 : case CPTK_IS_MEMBER_POINTER:
14173 11012 : return TYPE_PTRMEM_P (type1);
14174 :
14175 463018 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14176 463018 : return is_nothrow_xible (MODIFY_EXPR, type1, type2);
14177 :
14178 933881 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14179 933881 : return is_nothrow_xible (INIT_EXPR, type1, type2);
14180 :
14181 683 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14182 683 : return is_nothrow_convertible (type1, type2);
14183 :
14184 24259 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14185 24259 : return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14186 :
14187 43977 : case CPTK_IS_NOTHROW_INVOCABLE:
14188 43977 : return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
14189 :
14190 1133529 : case CPTK_IS_OBJECT:
14191 1133529 : return object_type_p (type1);
14192 :
14193 168 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14194 168 : return pointer_interconvertible_base_of_p (type1, type2);
14195 :
14196 11548 : case CPTK_IS_POD:
14197 11548 : return pod_type_p (type1);
14198 :
14199 152611 : case CPTK_IS_POINTER:
14200 152611 : return TYPE_PTR_P (type1);
14201 :
14202 289 : case CPTK_IS_POLYMORPHIC:
14203 289 : return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
14204 :
14205 719508 : case CPTK_IS_REFERENCE:
14206 719508 : return type_code1 == REFERENCE_TYPE;
14207 :
14208 2681076 : case CPTK_IS_SAME:
14209 2681076 : return same_type_p (type1, type2);
14210 :
14211 373 : case CPTK_IS_SCOPED_ENUM:
14212 373 : return SCOPED_ENUM_P (type1);
14213 :
14214 64171 : case CPTK_IS_STD_LAYOUT:
14215 64171 : return std_layout_type_p (type1);
14216 :
14217 59418 : case CPTK_IS_TRIVIAL:
14218 59418 : return trivial_type_p (type1);
14219 :
14220 12660 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14221 12660 : return is_trivially_xible (MODIFY_EXPR, type1, type2);
14222 :
14223 76076 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14224 76076 : return is_trivially_xible (INIT_EXPR, type1, type2);
14225 :
14226 119928 : case CPTK_IS_TRIVIALLY_COPYABLE:
14227 119928 : return trivially_copyable_p (type1);
14228 :
14229 27304 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14230 27304 : return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14231 :
14232 99298 : case CPTK_IS_UNBOUNDED_ARRAY:
14233 99298 : return array_of_unknown_bound_p (type1);
14234 :
14235 275177 : case CPTK_IS_UNION:
14236 275177 : return type_code1 == UNION_TYPE;
14237 :
14238 751 : case CPTK_IS_VIRTUAL_BASE_OF:
14239 683 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14240 1415 : && lookup_base (type2, type1, ba_require_virtual,
14241 : NULL, tf_none) != NULL_TREE);
14242 :
14243 615641 : case CPTK_IS_VOLATILE:
14244 615641 : return CP_TYPE_VOLATILE_P (type1);
14245 :
14246 221403 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14247 221403 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
14248 :
14249 54335 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14250 54335 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
14251 :
14252 85 : case CPTK_IS_DEDUCIBLE:
14253 85 : return type_targs_deducible_from (type1, type2);
14254 :
14255 264 : case CPTK_IS_STRUCTURAL:
14256 264 : return structural_type_p (type1);
14257 :
14258 : /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
14259 : are handled in finish_trait_expr. */
14260 0 : case CPTK_RANK:
14261 0 : case CPTK_TYPE_ORDER:
14262 0 : case CPTK_STRUCTURED_BINDING_SIZE:
14263 0 : gcc_unreachable ();
14264 :
14265 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14266 : case CPTK_##CODE:
14267 : #include "cp-trait.def"
14268 : #undef DEFTRAIT_TYPE
14269 : /* Type-yielding traits are handled in finish_trait_type. */
14270 : break;
14271 : }
14272 :
14273 0 : gcc_unreachable ();
14274 : }
14275 :
14276 : /* Returns true if TYPE meets the requirements for the specified KIND,
14277 : false otherwise.
14278 :
14279 : When KIND == 1, TYPE must be an array of unknown bound,
14280 : or (possibly cv-qualified) void, or a complete type.
14281 :
14282 : When KIND == 2, TYPE must be a complete type, or array of complete type,
14283 : or (possibly cv-qualified) void.
14284 :
14285 : When KIND == 3:
14286 : If TYPE is a non-union class type, it must be complete.
14287 :
14288 : When KIND == 4:
14289 : If TYPE is a class type, it must be complete.
14290 :
14291 : If COMPLAIN is not tf_none, we permerror and return false if that doesn't
14292 : produce a hard error. */
14293 :
14294 : static bool
14295 19027957 : check_trait_type (tree type, int kind, tsubst_flags_t complain)
14296 : {
14297 19027957 : if (type == NULL_TREE)
14298 : return true;
14299 :
14300 19027957 : if (TREE_CODE (type) == TREE_VEC)
14301 : {
14302 6218641 : for (tree arg : tree_vec_range (type))
14303 2722979 : if (!check_trait_type (arg, kind, complain))
14304 123 : return false;
14305 3495662 : return true;
14306 : }
14307 :
14308 15532172 : if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
14309 : return true; // Array of unknown bound. Don't care about completeness.
14310 :
14311 15531320 : if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
14312 : return true; // Not a non-union class type. Don't care about completeness.
14313 :
14314 15416007 : if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
14315 : return true; // Not a class type. Don't care about completeness.
14316 :
14317 15415476 : if (VOID_TYPE_P (type))
14318 : return true;
14319 :
14320 15413841 : type = complete_type (strip_array_types (type));
14321 15413841 : if (!COMPLETE_TYPE_P (type)
14322 : /* If we're not emitting error messages, always return false for
14323 : incomplete types. */
14324 15413841 : && (complain == tf_none
14325 160 : || (cxx_incomplete_type_diagnostic (NULL_TREE, type,
14326 : diagnostics::kind::permerror)
14327 160 : && !flag_permissive)))
14328 865 : return false;
14329 : return true;
14330 : }
14331 :
14332 : /* True iff the conversion (if any) would be a direct reference
14333 : binding, not requiring complete types. This is LWG2939. */
14334 :
14335 : static bool
14336 6958243 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
14337 : {
14338 6958243 : tree from, to;
14339 6958243 : switch (kind)
14340 : {
14341 : /* These put the target type first. */
14342 : case CPTK_IS_CONSTRUCTIBLE:
14343 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14344 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14345 : case CPTK_IS_INVOCABLE:
14346 : case CPTK_IS_NOTHROW_INVOCABLE:
14347 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14348 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14349 : to = type1;
14350 : from = type2;
14351 : break;
14352 :
14353 : /* These put it second. */
14354 3181710 : case CPTK_IS_CONVERTIBLE:
14355 3181710 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14356 3181710 : to = type2;
14357 3181710 : from = type1;
14358 3181710 : break;
14359 :
14360 0 : default:
14361 0 : gcc_unreachable ();
14362 : }
14363 :
14364 6958243 : if (TREE_CODE (to) != REFERENCE_TYPE || !from)
14365 : return false;
14366 922250 : if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
14367 62672 : from = TREE_VEC_ELT (from, 0);
14368 922250 : return (TYPE_P (from)
14369 1834434 : && (same_type_ignoring_top_level_qualifiers_p
14370 912184 : (non_reference (to), non_reference (from))));
14371 : }
14372 :
14373 : /* Helper for finish_trait_expr and tsubst_expr. Handle
14374 : CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
14375 : way. */
14376 :
14377 : tree
14378 273 : finish_structured_binding_size (location_t loc, tree type,
14379 : tsubst_flags_t complain)
14380 : {
14381 273 : if (TYPE_REF_P (type))
14382 : {
14383 105 : if (complain & tf_error)
14384 99 : error_at (loc, "%qs argument %qT is a reference",
14385 : "__builtin_structured_binding_size", type);
14386 105 : return error_mark_node;
14387 : }
14388 168 : HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
14389 168 : if (ret == -1)
14390 63 : return error_mark_node;
14391 105 : return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
14392 : }
14393 :
14394 : /* Process a trait expression. */
14395 :
14396 : tree
14397 21550114 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2,
14398 : tsubst_flags_t complain/*=tf_warning_or_error*/)
14399 : {
14400 21550114 : if (type1 == error_mark_node
14401 21550111 : || type2 == error_mark_node)
14402 : return error_mark_node;
14403 :
14404 21550111 : if (processing_template_decl)
14405 : {
14406 3413684 : tree trait_expr = make_node (TRAIT_EXPR);
14407 3413684 : if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
14408 32072 : TREE_TYPE (trait_expr) = size_type_node;
14409 3381612 : else if (kind == CPTK_TYPE_ORDER)
14410 : {
14411 4456 : tree val = type_order_value (type1, type1);
14412 4456 : if (val != error_mark_node)
14413 4456 : TREE_TYPE (trait_expr) = TREE_TYPE (val);
14414 : }
14415 : else
14416 3377156 : TREE_TYPE (trait_expr) = boolean_type_node;
14417 3413684 : TRAIT_EXPR_TYPE1 (trait_expr) = type1;
14418 3413684 : TRAIT_EXPR_TYPE2 (trait_expr) = type2;
14419 3413684 : TRAIT_EXPR_KIND (trait_expr) = kind;
14420 3413684 : TRAIT_EXPR_LOCATION (trait_expr) = loc;
14421 3413684 : return trait_expr;
14422 : }
14423 :
14424 18136427 : switch (kind)
14425 : {
14426 57292 : case CPTK_HAS_NOTHROW_ASSIGN:
14427 57292 : case CPTK_HAS_TRIVIAL_ASSIGN:
14428 57292 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
14429 57292 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14430 57292 : case CPTK_HAS_NOTHROW_COPY:
14431 57292 : case CPTK_HAS_TRIVIAL_COPY:
14432 57292 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14433 57292 : case CPTK_IS_DESTRUCTIBLE:
14434 57292 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14435 57292 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14436 57292 : if (!check_trait_type (type1, /*kind=*/1, complain))
14437 57 : return error_mark_node;
14438 : break;
14439 :
14440 316832 : case CPTK_IS_LITERAL_TYPE:
14441 316832 : case CPTK_IS_POD:
14442 316832 : case CPTK_IS_STD_LAYOUT:
14443 316832 : case CPTK_IS_TRIVIAL:
14444 316832 : case CPTK_IS_TRIVIALLY_COPYABLE:
14445 316832 : case CPTK_IS_STRUCTURAL:
14446 316832 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14447 316832 : if (!check_trait_type (type1, /* kind = */ 2, complain))
14448 133 : return error_mark_node;
14449 : break;
14450 :
14451 275510 : case CPTK_IS_ABSTRACT:
14452 275510 : case CPTK_IS_EMPTY:
14453 275510 : case CPTK_IS_POLYMORPHIC:
14454 275510 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14455 275510 : if (!check_trait_type (type1, /* kind = */ 3, complain))
14456 39 : return error_mark_node;
14457 : break;
14458 :
14459 : /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
14460 : type to know whether an array is an aggregate, so use kind=4 here. */
14461 436257 : case CPTK_IS_AGGREGATE:
14462 436257 : case CPTK_IS_FINAL:
14463 436257 : case CPTK_IS_IMPLICIT_LIFETIME:
14464 436257 : if (!check_trait_type (type1, /* kind = */ 4, complain))
14465 55 : return error_mark_node;
14466 : break;
14467 :
14468 6958243 : case CPTK_IS_CONSTRUCTIBLE:
14469 6958243 : case CPTK_IS_CONVERTIBLE:
14470 6958243 : case CPTK_IS_INVOCABLE:
14471 6958243 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14472 6958243 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14473 6958243 : case CPTK_IS_NOTHROW_INVOCABLE:
14474 6958243 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14475 6958243 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14476 6958243 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14477 6958243 : /* Don't check completeness for direct reference binding. */;
14478 6958243 : if (same_type_ref_bind_p (kind, type1, type2))
14479 : break;
14480 7609738 : gcc_fallthrough ();
14481 :
14482 7609738 : case CPTK_IS_ASSIGNABLE:
14483 7609738 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14484 7609738 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14485 7609738 : if (!check_trait_type (type1, /*kind=*/1, complain)
14486 7609738 : || !check_trait_type (type2, /*kind=*/1, complain))
14487 581 : return error_mark_node;
14488 : break;
14489 :
14490 517334 : case CPTK_IS_BASE_OF:
14491 517334 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14492 517229 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14493 498417 : && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
14494 987472 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
14495 : /* We already issued an error. */
14496 27 : return error_mark_node;
14497 : break;
14498 :
14499 778 : case CPTK_IS_VIRTUAL_BASE_OF:
14500 710 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14501 1469 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
14502 : /* We already issued an error. */
14503 27 : return error_mark_node;
14504 : break;
14505 :
14506 : case CPTK_IS_ARRAY:
14507 : case CPTK_IS_BOUNDED_ARRAY:
14508 : case CPTK_IS_CLASS:
14509 : case CPTK_IS_CONST:
14510 : case CPTK_IS_ENUM:
14511 : case CPTK_IS_FUNCTION:
14512 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14513 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14514 : case CPTK_IS_MEMBER_POINTER:
14515 : case CPTK_IS_OBJECT:
14516 : case CPTK_IS_POINTER:
14517 : case CPTK_IS_REFERENCE:
14518 : case CPTK_IS_SAME:
14519 : case CPTK_IS_SCOPED_ENUM:
14520 : case CPTK_IS_UNBOUNDED_ARRAY:
14521 : case CPTK_IS_UNION:
14522 : case CPTK_IS_VOLATILE:
14523 : break;
14524 :
14525 : case CPTK_RANK:
14526 : {
14527 : size_t rank = 0;
14528 122 : for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
14529 80 : ++rank;
14530 42 : return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
14531 : loc);
14532 : }
14533 :
14534 460 : case CPTK_TYPE_ORDER:
14535 460 : return maybe_wrap_with_location (type_order_value (type1, type2), loc);
14536 :
14537 144 : case CPTK_STRUCTURED_BINDING_SIZE:
14538 144 : return finish_structured_binding_size (loc, type1, complain);
14539 :
14540 242 : case CPTK_IS_LAYOUT_COMPATIBLE:
14541 242 : if (!array_of_unknown_bound_p (type1)
14542 223 : && TREE_CODE (type1) != VOID_TYPE
14543 456 : && !complete_type_or_maybe_complain (type1, NULL_TREE, complain))
14544 : /* We already issued an error. */
14545 12 : return error_mark_node;
14546 230 : if (!array_of_unknown_bound_p (type2)
14547 203 : && TREE_CODE (type2) != VOID_TYPE
14548 424 : && !complete_type_or_maybe_complain (type2, NULL_TREE, complain))
14549 : /* We already issued an error. */
14550 9 : return error_mark_node;
14551 : break;
14552 :
14553 85 : case CPTK_IS_DEDUCIBLE:
14554 85 : if (!DECL_TYPE_TEMPLATE_P (type1))
14555 : {
14556 0 : error ("%qD is not a class or alias template", type1);
14557 0 : return error_mark_node;
14558 : }
14559 : break;
14560 :
14561 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14562 : case CPTK_##CODE:
14563 : #include "cp-trait.def"
14564 : #undef DEFTRAIT_TYPE
14565 : /* Type-yielding traits are handled in finish_trait_type. */
14566 0 : gcc_unreachable ();
14567 : }
14568 :
14569 18134841 : tree val = (trait_expr_value (kind, type1, type2)
14570 18134841 : ? boolean_true_node : boolean_false_node);
14571 18134841 : return maybe_wrap_with_location (val, loc);
14572 : }
14573 :
14574 : /* Process a trait type. */
14575 :
14576 : tree
14577 7997161 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
14578 : tsubst_flags_t complain)
14579 : {
14580 7997161 : if (type1 == error_mark_node
14581 7997158 : || type2 == error_mark_node)
14582 : return error_mark_node;
14583 :
14584 7997158 : if (processing_template_decl)
14585 : {
14586 235403 : tree type = cxx_make_type (TRAIT_TYPE);
14587 235403 : TRAIT_TYPE_TYPE1 (type) = type1;
14588 235403 : TRAIT_TYPE_TYPE2 (type) = type2;
14589 235403 : TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
14590 : /* These traits are intended to be used in the definition of the ::type
14591 : member of the corresponding standard library type trait and aren't
14592 : mangleable (and thus won't appear directly in template signatures),
14593 : so structural equality should suffice. */
14594 235403 : SET_TYPE_STRUCTURAL_EQUALITY (type);
14595 235403 : return type;
14596 : }
14597 :
14598 7761755 : switch (kind)
14599 : {
14600 1246705 : case CPTK_ADD_LVALUE_REFERENCE:
14601 : /* [meta.trans.ref]. */
14602 1246705 : if (referenceable_type_p (type1))
14603 1246618 : return cp_build_reference_type (type1, /*rval=*/false);
14604 : return type1;
14605 :
14606 644432 : case CPTK_ADD_POINTER:
14607 : /* [meta.trans.ptr]. */
14608 644432 : if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
14609 : {
14610 644400 : if (TYPE_REF_P (type1))
14611 643208 : type1 = TREE_TYPE (type1);
14612 644400 : return build_pointer_type (type1);
14613 : }
14614 : return type1;
14615 :
14616 1681026 : case CPTK_ADD_RVALUE_REFERENCE:
14617 : /* [meta.trans.ref]. */
14618 1681026 : if (referenceable_type_p (type1))
14619 1680968 : return cp_build_reference_type (type1, /*rval=*/true);
14620 : return type1;
14621 :
14622 238987 : case CPTK_DECAY:
14623 238987 : if (TYPE_REF_P (type1))
14624 43253 : type1 = TREE_TYPE (type1);
14625 :
14626 238987 : if (TREE_CODE (type1) == ARRAY_TYPE)
14627 726 : return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
14628 726 : complain);
14629 238261 : else if (TREE_CODE (type1) == FUNCTION_TYPE)
14630 209 : return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
14631 : else
14632 238052 : return cv_unqualified (type1);
14633 :
14634 223 : case CPTK_REMOVE_ALL_EXTENTS:
14635 223 : return strip_array_types (type1);
14636 :
14637 1001188 : case CPTK_REMOVE_CV:
14638 1001188 : return cv_unqualified (type1);
14639 :
14640 475289 : case CPTK_REMOVE_CVREF:
14641 475289 : if (TYPE_REF_P (type1))
14642 181285 : type1 = TREE_TYPE (type1);
14643 475289 : return cv_unqualified (type1);
14644 :
14645 66600 : case CPTK_REMOVE_EXTENT:
14646 66600 : if (TREE_CODE (type1) == ARRAY_TYPE)
14647 9467 : type1 = TREE_TYPE (type1);
14648 : return type1;
14649 :
14650 44821 : case CPTK_REMOVE_POINTER:
14651 44821 : if (TYPE_PTR_P (type1))
14652 41935 : type1 = TREE_TYPE (type1);
14653 : return type1;
14654 :
14655 2201247 : case CPTK_REMOVE_REFERENCE:
14656 2201247 : if (TYPE_REF_P (type1))
14657 1334881 : type1 = TREE_TYPE (type1);
14658 : return type1;
14659 :
14660 112666 : case CPTK_TYPE_PACK_ELEMENT:
14661 112666 : return finish_type_pack_element (type1, type2, complain);
14662 :
14663 48571 : case CPTK_UNDERLYING_TYPE:
14664 48571 : return finish_underlying_type (type1);
14665 :
14666 : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
14667 : case CPTK_##CODE:
14668 : #include "cp-trait.def"
14669 : #undef DEFTRAIT_EXPR
14670 : /* Expression-yielding traits are handled in finish_trait_expr. */
14671 : case CPTK_BASES:
14672 : case CPTK_DIRECT_BASES:
14673 : /* BASES and DIRECT_BASES are handled in finish_bases. */
14674 : break;
14675 : }
14676 :
14677 0 : gcc_unreachable ();
14678 : }
14679 :
14680 : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
14681 : which is ignored for C++. */
14682 :
14683 : void
14684 0 : set_float_const_decimal64 (void)
14685 : {
14686 0 : }
14687 :
14688 : void
14689 0 : clear_float_const_decimal64 (void)
14690 : {
14691 0 : }
14692 :
14693 : bool
14694 1966291 : float_const_decimal64_p (void)
14695 : {
14696 1966291 : return 0;
14697 : }
14698 :
14699 :
14700 : /* Return true if T designates the implied `this' parameter. */
14701 :
14702 : bool
14703 6552701 : is_this_parameter (tree t)
14704 : {
14705 6552701 : if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
14706 : return false;
14707 3878737 : gcc_assert (TREE_CODE (t) == PARM_DECL
14708 : || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
14709 : || (cp_binding_oracle && VAR_P (t)));
14710 : return true;
14711 : }
14712 :
14713 : /* As above, or a C++23 explicit object parameter. */
14714 :
14715 : bool
14716 456 : is_object_parameter (tree t)
14717 : {
14718 456 : if (is_this_parameter (t))
14719 : return true;
14720 91 : if (TREE_CODE (t) != PARM_DECL)
14721 : return false;
14722 34 : tree ctx = DECL_CONTEXT (t);
14723 34 : return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
14724 62 : && t == DECL_ARGUMENTS (ctx));
14725 : }
14726 :
14727 : /* Insert the deduced return type for an auto function. */
14728 :
14729 : void
14730 1063784 : apply_deduced_return_type (tree fco, tree return_type)
14731 : {
14732 1063784 : tree result;
14733 :
14734 1063784 : if (return_type == error_mark_node)
14735 : return;
14736 :
14737 1063781 : if (DECL_CONV_FN_P (fco))
14738 42 : DECL_NAME (fco) = make_conv_op_name (return_type);
14739 :
14740 1063781 : TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
14741 :
14742 1063781 : maybe_update_postconditions (fco);
14743 :
14744 : /* Apply the type to the result object. */
14745 :
14746 1063781 : result = DECL_RESULT (fco);
14747 1063781 : if (result == NULL_TREE)
14748 : return;
14749 1051389 : if (TREE_TYPE (result) == return_type)
14750 : return;
14751 :
14752 1051383 : if (!processing_template_decl && !VOID_TYPE_P (return_type)
14753 1945749 : && !complete_type_or_else (return_type, NULL_TREE))
14754 : return;
14755 :
14756 : /* We already have a DECL_RESULT from start_preparsed_function.
14757 : Now we need to redo the work it and allocate_struct_function
14758 : did to reflect the new type. */
14759 1051386 : result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
14760 1051386 : TYPE_MAIN_VARIANT (return_type));
14761 1051386 : DECL_ARTIFICIAL (result) = 1;
14762 1051386 : DECL_IGNORED_P (result) = 1;
14763 1051386 : cp_apply_type_quals_to_decl (cp_type_quals (return_type),
14764 : result);
14765 1051386 : DECL_RESULT (fco) = result;
14766 :
14767 1051386 : if (!uses_template_parms (fco))
14768 1051386 : if (function *fun = DECL_STRUCT_FUNCTION (fco))
14769 : {
14770 1050417 : bool aggr = aggregate_value_p (result, fco);
14771 : #ifdef PCC_STATIC_STRUCT_RETURN
14772 : fun->returns_pcc_struct = aggr;
14773 : #endif
14774 1050417 : fun->returns_struct = aggr;
14775 : }
14776 : }
14777 :
14778 : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
14779 : this is a right unary fold. Otherwise it is a left unary fold. */
14780 :
14781 : static tree
14782 845415 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
14783 : {
14784 : /* Build a pack expansion (assuming expr has pack type). */
14785 845415 : if (!uses_parameter_packs (expr))
14786 : {
14787 3 : error_at (location_of (expr), "operand of fold expression has no "
14788 : "unexpanded parameter packs");
14789 3 : return error_mark_node;
14790 : }
14791 845412 : tree pack = make_pack_expansion (expr);
14792 :
14793 : /* Build the fold expression. */
14794 845412 : tree code = build_int_cstu (integer_type_node, abs (op));
14795 845412 : tree fold = build_min_nt_loc (loc, dir, code, pack);
14796 845412 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14797 845412 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14798 845412 : FOLD_EXPR_OP (fold),
14799 845412 : FOLD_EXPR_MODIFY_P (fold));
14800 845412 : return fold;
14801 : }
14802 :
14803 : tree
14804 25553 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
14805 : {
14806 25553 : return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
14807 : }
14808 :
14809 : tree
14810 819862 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
14811 : {
14812 819862 : return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
14813 : }
14814 :
14815 : /* Build a binary fold expression over EXPR1 and EXPR2. The
14816 : associativity of the fold is determined by EXPR1 and EXPR2 (whichever
14817 : has an unexpanded parameter pack). */
14818 :
14819 : static tree
14820 196559 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
14821 : int op, tree_code dir)
14822 : {
14823 196559 : pack = make_pack_expansion (pack);
14824 196559 : tree code = build_int_cstu (integer_type_node, abs (op));
14825 196559 : tree fold = build_min_nt_loc (loc, dir, code, pack, init);
14826 196559 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14827 196559 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14828 196559 : FOLD_EXPR_OP (fold),
14829 196559 : FOLD_EXPR_MODIFY_P (fold));
14830 196559 : return fold;
14831 : }
14832 :
14833 : tree
14834 196559 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
14835 : {
14836 : // Determine which expr has an unexpanded parameter pack and
14837 : // set the pack and initial term.
14838 196559 : bool pack1 = uses_parameter_packs (expr1);
14839 196559 : bool pack2 = uses_parameter_packs (expr2);
14840 196559 : if (pack1 && !pack2)
14841 1071 : return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
14842 195488 : else if (pack2 && !pack1)
14843 195488 : return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
14844 : else
14845 : {
14846 0 : if (pack1)
14847 0 : error ("both arguments in binary fold have unexpanded parameter packs");
14848 : else
14849 0 : error ("no unexpanded parameter packs in binary fold");
14850 : }
14851 0 : return error_mark_node;
14852 : }
14853 :
14854 : /* Finish __builtin_launder (arg). */
14855 :
14856 : tree
14857 14207 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
14858 : {
14859 14207 : tree orig_arg = arg;
14860 14207 : if (!type_dependent_expression_p (arg))
14861 84 : arg = decay_conversion (arg, complain);
14862 14207 : if (error_operand_p (arg))
14863 0 : return error_mark_node;
14864 14207 : if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
14865 : {
14866 24 : error_at (loc, "type %qT of argument to %<__builtin_launder%> "
14867 24 : "is not a pointer to object type", TREE_TYPE (arg));
14868 24 : return error_mark_node;
14869 : }
14870 14183 : if (processing_template_decl)
14871 14123 : arg = orig_arg;
14872 14183 : return build_call_expr_internal_loc (loc, IFN_LAUNDER,
14873 28366 : TREE_TYPE (arg), 1, arg);
14874 : }
14875 :
14876 : /* Finish __builtin_convertvector (arg, type). */
14877 :
14878 : tree
14879 462 : cp_build_vec_convert (tree arg, location_t loc, tree type,
14880 : tsubst_flags_t complain)
14881 : {
14882 462 : if (error_operand_p (type))
14883 9 : return error_mark_node;
14884 453 : if (error_operand_p (arg))
14885 0 : return error_mark_node;
14886 :
14887 453 : tree ret = NULL_TREE;
14888 453 : if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
14889 415 : ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
14890 : decay_conversion (arg, complain),
14891 : loc, type, (complain & tf_error) != 0);
14892 :
14893 453 : if (!processing_template_decl)
14894 : return ret;
14895 :
14896 80 : return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
14897 : }
14898 :
14899 : /* Finish __builtin_bit_cast (type, arg). */
14900 :
14901 : tree
14902 294376 : cp_build_bit_cast (location_t loc, tree type, tree arg,
14903 : tsubst_flags_t complain)
14904 : {
14905 294376 : if (error_operand_p (type))
14906 0 : return error_mark_node;
14907 294376 : if (!dependent_type_p (type))
14908 : {
14909 213364 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
14910 9 : return error_mark_node;
14911 213355 : if (TREE_CODE (type) == ARRAY_TYPE)
14912 : {
14913 : /* std::bit_cast for destination ARRAY_TYPE is not possible,
14914 : as functions may not return an array, so don't bother trying
14915 : to support this (and then deal with VLAs etc.). */
14916 9 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14917 : "is an array type", type);
14918 9 : return error_mark_node;
14919 : }
14920 213346 : if (!trivially_copyable_p (type))
14921 : {
14922 18 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14923 : "is not trivially copyable", type);
14924 18 : return error_mark_node;
14925 : }
14926 213328 : if (consteval_only_p (type) || consteval_only_p (arg))
14927 : {
14928 8 : error_at (loc, "%<__builtin_bit_cast%> cannot be used with "
14929 : "consteval-only types");
14930 8 : return error_mark_node;
14931 : }
14932 : }
14933 :
14934 294332 : if (error_operand_p (arg))
14935 0 : return error_mark_node;
14936 :
14937 294332 : if (!type_dependent_expression_p (arg))
14938 : {
14939 114812 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
14940 : {
14941 : /* Don't perform array-to-pointer conversion. */
14942 375 : arg = mark_rvalue_use (arg, loc, true);
14943 375 : if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
14944 0 : return error_mark_node;
14945 : }
14946 : else
14947 114437 : arg = decay_conversion (arg, complain);
14948 :
14949 114812 : if (error_operand_p (arg))
14950 12 : return error_mark_node;
14951 :
14952 114800 : if (!trivially_copyable_p (TREE_TYPE (arg)))
14953 : {
14954 9 : error_at (cp_expr_loc_or_loc (arg, loc),
14955 : "%<__builtin_bit_cast%> source type %qT "
14956 9 : "is not trivially copyable", TREE_TYPE (arg));
14957 9 : return error_mark_node;
14958 : }
14959 114791 : if (!dependent_type_p (type)
14960 191382 : && !cp_tree_equal (TYPE_SIZE_UNIT (type),
14961 76591 : TYPE_SIZE_UNIT (TREE_TYPE (arg))))
14962 : {
14963 18 : error_at (loc, "%<__builtin_bit_cast%> source size %qE "
14964 : "not equal to destination type size %qE",
14965 18 : TYPE_SIZE_UNIT (TREE_TYPE (arg)),
14966 18 : TYPE_SIZE_UNIT (type));
14967 18 : return error_mark_node;
14968 : }
14969 : }
14970 :
14971 294293 : tree ret = build_min (BIT_CAST_EXPR, type, arg);
14972 294293 : SET_EXPR_LOCATION (ret, loc);
14973 :
14974 294293 : if (!processing_template_decl && CLASS_TYPE_P (type))
14975 872 : ret = get_target_expr (ret, complain);
14976 :
14977 : return ret;
14978 : }
14979 :
14980 : /* Diagnose invalid #pragma GCC unroll argument and adjust
14981 : it if needed. */
14982 :
14983 : tree
14984 24501 : cp_check_pragma_unroll (location_t loc, tree unroll)
14985 : {
14986 24501 : HOST_WIDE_INT lunroll = 0;
14987 24501 : if (type_dependent_expression_p (unroll))
14988 : ;
14989 48930 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
14990 48884 : || (!value_dependent_expression_p (unroll)
14991 24389 : && (!tree_fits_shwi_p (unroll)
14992 24363 : || (lunroll = tree_to_shwi (unroll)) < 0
14993 24348 : || lunroll >= USHRT_MAX)))
14994 : {
14995 90 : error_at (loc, "%<#pragma GCC unroll%> requires an"
14996 : " assignment-expression that evaluates to a non-negative"
14997 : " integral constant less than %u", USHRT_MAX);
14998 90 : unroll = integer_one_node;
14999 : }
15000 24375 : else if (TREE_CODE (unroll) == INTEGER_CST)
15001 : {
15002 24345 : unroll = fold_convert (integer_type_node, unroll);
15003 24345 : if (integer_zerop (unroll))
15004 12 : unroll = integer_one_node;
15005 : }
15006 24501 : return unroll;
15007 : }
15008 :
15009 : #include "gt-cp-semantics.h"
|