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 23106183828 : push_deferring_access_checks (deferring_kind deferring)
146 : {
147 : /* For context like template instantiation, access checking
148 : disabling applies to all nested context. */
149 23106183828 : if (deferred_access_no_check || deferring == dk_no_check)
150 296258208 : deferred_access_no_check++;
151 : else
152 : {
153 22809925620 : deferred_access e = {NULL, deferring};
154 22809925620 : vec_safe_push (deferred_access_stack, e);
155 : }
156 23106183828 : }
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 364562230 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
163 : {
164 364562230 : push_deferring_access_checks (dk_deferred);
165 364562230 : if (!deferred_access_no_check)
166 357756455 : deferred_access_stack->last().deferred_access_checks = checks;
167 364562230 : }
168 :
169 : /* Resume deferring access checks again after we stopped doing
170 : this previously. */
171 :
172 : void
173 176648266 : resume_deferring_access_checks (void)
174 : {
175 176648266 : if (!deferred_access_no_check)
176 176627983 : deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
177 176648266 : }
178 :
179 : /* Stop deferring access checks. */
180 :
181 : void
182 495833139 : stop_deferring_access_checks (void)
183 : {
184 495833139 : if (!deferred_access_no_check)
185 495772958 : deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
186 495833139 : }
187 :
188 : /* Discard the current deferred access checks and restore the
189 : previous states. */
190 :
191 : void
192 14321132800 : pop_deferring_access_checks (void)
193 : {
194 14321132800 : if (deferred_access_no_check)
195 226446499 : deferred_access_no_check--;
196 : else
197 14094686301 : deferred_access_stack->pop ();
198 14321132800 : }
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 1228483335 : get_deferred_access_checks (void)
207 : {
208 1228483335 : if (deferred_access_no_check)
209 : return NULL;
210 : else
211 1215005773 : 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 8784916033 : pop_to_parent_deferring_access_checks (void)
220 : {
221 8784916033 : if (deferred_access_no_check)
222 69811703 : deferred_access_no_check--;
223 : else
224 : {
225 8715104330 : vec<deferred_access_check, va_gc> *checks;
226 8715104330 : deferred_access *ptr;
227 :
228 8715104330 : checks = (deferred_access_stack->last ().deferred_access_checks);
229 :
230 8715104330 : deferred_access_stack->pop ();
231 8715104330 : ptr = &deferred_access_stack->last ();
232 8715104330 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
233 : {
234 : /* Check access. */
235 550257655 : 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 8361847599 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
244 : {
245 107185075 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
246 : {
247 9623575 : if (probe->binfo == chk->binfo &&
248 7639092 : probe->decl == chk->decl &&
249 939726 : probe->diag_decl == chk->diag_decl)
250 938962 : goto found;
251 : }
252 : /* Insert into parent's checks. */
253 97561500 : vec_safe_push (ptr->deferred_access_checks, *chk);
254 98500462 : found:;
255 : }
256 : }
257 : }
258 8784916033 : }
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 396288730 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
334 : tsubst_flags_t complain, access_failure_info *afi = NULL)
335 : {
336 396288730 : gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
337 :
338 396288730 : if (flag_new_inheriting_ctors
339 502328086 : && 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 59481 : decl = strip_inheriting_ctors (decl);
345 59481 : basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
346 : ba_any, NULL, complain);
347 : }
348 :
349 396288730 : tree cs = current_scope ();
350 396288730 : if (in_template_context
351 396288730 : && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
352 40766004 : 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 40529596 : 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 355759134 : if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
382 : {
383 21694 : if (flag_new_inheriting_ctors)
384 21664 : diag_decl = strip_inheriting_ctors (diag_decl);
385 21694 : if (complain & tf_error)
386 : {
387 1151 : access_kind access_failure_reason = ak_none;
388 :
389 : /* By default, using the decl as the source of the problem will
390 : usually give correct results. */
391 1151 : tree diag_location = diag_decl;
392 :
393 : /* However, if a parent of BASETYPE_PATH had private access to decl,
394 : then it actually might be the case that the source of the problem
395 : is not DECL. */
396 1151 : tree parent_binfo = get_parent_with_private_access (decl,
397 : basetype_path);
398 :
399 : /* So if a parent did have private access, then we need to do
400 : special checks to obtain the best diagnostic location decl. */
401 1151 : if (parent_binfo != NULL_TREE)
402 : {
403 182 : diag_location = get_class_access_diagnostic_decl (parent_binfo,
404 : diag_decl);
405 :
406 : /* We also at this point know that the reason access failed was
407 : because decl was private. */
408 182 : access_failure_reason = ak_private;
409 : }
410 :
411 : /* Finally, generate an error message. */
412 1151 : complain_about_access (decl, diag_decl, diag_location, true,
413 : access_failure_reason);
414 : }
415 21694 : if (afi)
416 412 : afi->record_access_failure (basetype_path, decl, diag_decl);
417 21694 : 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 1047259372 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
431 : tsubst_flags_t complain)
432 : {
433 1047259372 : int i;
434 1047259372 : deferred_access_check *chk;
435 1047259372 : location_t loc = input_location;
436 1047259372 : bool ok = true;
437 :
438 1047259372 : if (!checks)
439 : return true;
440 :
441 124231208 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
442 : {
443 69209773 : input_location = chk->loc;
444 69209773 : ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
445 : }
446 :
447 55021435 : input_location = loc;
448 55021435 : 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 274915699 : perform_deferred_access_checks (tsubst_flags_t complain)
469 : {
470 274915699 : 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 595852330 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
480 : tsubst_flags_t complain,
481 : access_failure_info *afi)
482 : {
483 595852330 : int i;
484 595852330 : deferred_access *ptr;
485 595852330 : deferred_access_check *chk;
486 :
487 : /* Exit if we are in a context that no access checking is performed. */
488 595852330 : if (deferred_access_no_check)
489 : return true;
490 :
491 571912709 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
492 :
493 571912709 : ptr = &deferred_access_stack->last ();
494 :
495 : /* If we are not supposed to defer access checks, just check now. */
496 571912709 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
497 : {
498 327078957 : bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
499 498795090 : return (complain & tf_error) ? true : ok;
500 : }
501 :
502 : /* See if we are already going to perform this check. */
503 298892048 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
504 : {
505 71355153 : if (chk->decl == decl && chk->binfo == binfo &&
506 17297592 : chk->diag_decl == diag_decl)
507 : {
508 : return true;
509 : }
510 : }
511 : /* If not, record the check. */
512 227536895 : deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
513 227536895 : vec_safe_push (ptr->deferred_access_checks, new_access);
514 :
515 227536895 : 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 1440209035 : stmts_are_full_exprs_p (void)
524 : {
525 1440209035 : 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 1248814430 : add_stmt (tree t)
534 : {
535 1248814430 : enum tree_code code = TREE_CODE (t);
536 :
537 1248814430 : if (EXPR_P (t) && code != LABEL_EXPR)
538 : {
539 1200342807 : if (!EXPR_HAS_LOCATION (t))
540 191760445 : 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 1200342807 : if (STATEMENT_CODE_P (TREE_CODE (t)))
545 311285437 : STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
546 : }
547 :
548 1248814430 : if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
549 5358541 : 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 1248814430 : gcc_checking_assert (!stmt_list_stack->is_empty ());
554 1248814430 : append_to_statement_list_force (t, &cur_stmt_list);
555 :
556 1248814430 : return t;
557 : }
558 :
559 : /* Returns the stmt_tree to which statements are currently being added. */
560 :
561 : stmt_tree
562 7372688054 : current_stmt_tree (void)
563 : {
564 7372688054 : return (cfun
565 7334832094 : ? &cfun->language->base.x_stmt_tree
566 7372688054 : : &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 288980 : maybe_cleanup_point_expr (tree expr)
573 : {
574 288980 : if (!processing_template_decl && stmts_are_full_exprs_p ())
575 274922 : expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
576 288980 : 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 308987829 : maybe_cleanup_point_expr_void (tree expr)
586 : {
587 308987829 : if (!processing_template_decl && stmts_are_full_exprs_p ())
588 102873929 : expr = fold_build_cleanup_point_expr (void_type_node, expr);
589 308987829 : return expr;
590 : }
591 :
592 :
593 :
594 : /* Create a declaration statement for the declaration given by the DECL. */
595 :
596 : void
597 104632831 : add_decl_expr (tree decl)
598 : {
599 104632831 : tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
600 104632831 : if (DECL_INITIAL (decl)
601 104632831 : || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
602 18690777 : r = maybe_cleanup_point_expr_void (r);
603 104632831 : add_stmt (r);
604 104632831 : }
605 :
606 : /* Set EXPR_LOCATION on one cleanup T to LOC. */
607 :
608 : static void
609 5541628 : set_one_cleanup_loc (tree t, location_t loc)
610 : {
611 5541628 : if (!t)
612 : return;
613 :
614 5541628 : if (TREE_CODE (t) != POSTCONDITION_STMT)
615 5541628 : 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 5541628 : if (TREE_CODE (t) == NOP_EXPR
622 0 : && TREE_TYPE (t) == void_type_node
623 5541628 : && 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 1180874569 : set_cleanup_locs (tree stmts, location_t loc)
631 : {
632 1186416197 : if (TREE_CODE (stmts) == CLEANUP_STMT)
633 : {
634 5541628 : set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
635 5541628 : set_cleanup_locs (CLEANUP_BODY (stmts), loc);
636 : }
637 1180874569 : else if (TREE_CODE (stmts) == STATEMENT_LIST)
638 1053237244 : for (tree stmt : tsi_range (stmts))
639 815607465 : set_cleanup_locs (stmt, loc);
640 1180874569 : }
641 :
642 : /* True iff the innermost block scope is a try block. */
643 :
644 : static bool
645 365267104 : at_try_scope ()
646 : {
647 365267104 : cp_binding_level *b = current_binding_level;
648 365267548 : while (b && b->kind == sk_cleanup)
649 444 : b = b->level_chain;
650 365267104 : return b && b->kind == sk_try;
651 : }
652 :
653 : /* Finish a scope. */
654 :
655 : tree
656 365267104 : do_poplevel (tree stmt_list)
657 : {
658 365267104 : tree block = NULL;
659 :
660 365267104 : bool was_try = at_try_scope ();
661 :
662 365267104 : if (stmts_are_full_exprs_p ())
663 365206115 : block = poplevel (kept_level_p (), 1, 0);
664 :
665 : /* This needs to come after poplevel merges sk_cleanup statement_lists. */
666 365267104 : maybe_splice_retval_cleanup (stmt_list, was_try);
667 :
668 365267104 : stmt_list = pop_stmt_list (stmt_list);
669 :
670 : /* input_location is the last token of the scope, usually a }. */
671 365267104 : set_cleanup_locs (stmt_list, input_location);
672 :
673 365267104 : if (!processing_template_decl)
674 : {
675 111298975 : stmt_list = c_build_bind_expr (input_location, block, stmt_list);
676 : /* ??? See c_end_compound_stmt re statement expressions. */
677 : }
678 :
679 365267104 : return stmt_list;
680 : }
681 :
682 : /* Begin a new scope. */
683 :
684 : tree
685 365230752 : do_pushlevel (scope_kind sk)
686 : {
687 365230752 : tree ret = push_stmt_list ();
688 365230752 : if (stmts_are_full_exprs_p ())
689 365206175 : begin_scope (sk, NULL);
690 365230752 : 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 5541546 : push_cleanup (tree decl, tree cleanup, bool eh_only)
700 : {
701 5541546 : tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
702 5541546 : CLEANUP_EH_ONLY (stmt) = eh_only;
703 5541546 : add_stmt (stmt);
704 5541546 : CLEANUP_BODY (stmt) = push_stmt_list ();
705 5541546 : }
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 17590278 : begin_maybe_infinite_loop (tree cond)
716 : {
717 : /* Only track this while parsing a function, not during instantiation. */
718 17590278 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
719 2563489 : && !processing_template_decl))
720 : return;
721 15026244 : bool maybe_infinite = true;
722 15026244 : if (cond)
723 : {
724 14719337 : cond = fold_non_dependent_expr (cond);
725 14719337 : maybe_infinite = integer_nonzerop (cond);
726 : }
727 29745581 : vec_safe_push (cp_function_chain->infinite_loops,
728 15026244 : 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 1490420 : break_maybe_infinite_loop (void)
736 : {
737 1490420 : if (!cfun)
738 : return;
739 1490420 : 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 17590278 : end_maybe_infinite_loop (tree cond)
747 : {
748 17590278 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
749 2563489 : && !processing_template_decl))
750 : return;
751 15026244 : tree current = cp_function_chain->infinite_loops->pop();
752 15026244 : if (current != NULL_TREE)
753 : {
754 4826238 : cond = fold_non_dependent_expr (cond);
755 4826238 : if (integer_nonzerop (cond))
756 302797 : 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 84035552 : begin_cond (tree *cond_p)
767 : {
768 84035552 : if (processing_template_decl)
769 60001319 : *cond_p = push_stmt_list ();
770 84035552 : }
771 :
772 : /* Finish such a conditional. */
773 :
774 : static void
775 84035552 : finish_cond (tree *cond_p, tree expr)
776 : {
777 84035552 : if (processing_template_decl)
778 : {
779 60001319 : tree cond = pop_stmt_list (*cond_p);
780 :
781 60001319 : if (expr == NULL_TREE)
782 : /* Empty condition in 'for'. */
783 286795 : gcc_assert (empty_expr_stmt_p (cond));
784 59714524 : else if (check_for_bare_parameter_packs (expr))
785 0 : expr = error_mark_node;
786 59714524 : else if (!empty_expr_stmt_p (cond))
787 903741 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
788 : }
789 84035552 : *cond_p = expr;
790 84035552 : }
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 11935863 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
809 : {
810 11935863 : if (!TREE_SIDE_EFFECTS (*body_p))
811 11926430 : return;
812 :
813 9433 : gcc_assert (!processing_template_decl);
814 9433 : *prep_p = *body_p;
815 9433 : 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 9433 : current_binding_level->keep = true;
840 9433 : 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 9433 : if (tsi_end_p (iter))
847 91 : *body_p = NULL_TREE;
848 : else
849 9342 : *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 9433 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
862 : {
863 9433 : *prep_p = do_poplevel (*prep_p);
864 9433 : gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
865 9433 : 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 9415 : tree stmt_list = BIND_EXPR_BODY (*prep_p);
872 9415 : gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
873 9415 : 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 9324 : tree_stmt_iterator iter = tsi_start (stmt_list);
893 9520 : while (tsi_stmt (iter) != *body_p)
894 196 : tsi_next (&iter);
895 9324 : *body_p = tsi_split_stmt_list (input_location, iter);
896 : }
897 :
898 : /* Finish a goto-statement. */
899 :
900 : tree
901 2710 : finish_goto_stmt (tree destination)
902 : {
903 2710 : if (identifier_p (destination))
904 2573 : destination = lookup_label (destination);
905 :
906 : /* We warn about unused labels with -Wunused. That means we have to
907 : mark the used labels as used. */
908 2710 : if (TREE_CODE (destination) == LABEL_DECL)
909 2573 : TREE_USED (destination) = 1;
910 : else
911 : {
912 137 : destination = mark_rvalue_use (destination);
913 137 : if (!processing_template_decl)
914 : {
915 117 : destination = cp_convert (ptr_type_node, destination,
916 : tf_warning_or_error);
917 117 : if (error_operand_p (destination))
918 : return NULL_TREE;
919 108 : destination
920 108 : = fold_build_cleanup_point_expr (TREE_TYPE (destination),
921 : destination);
922 : }
923 : }
924 :
925 2701 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
926 :
927 2701 : tree stmt = build_stmt (input_location, GOTO_EXPR, destination);
928 2701 : check_goto (&TREE_OPERAND (stmt, 0));
929 :
930 2701 : return add_stmt (stmt);
931 : }
932 :
933 : /* Returns true if T corresponds to an assignment operator expression. */
934 :
935 : static bool
936 871921 : is_assignment_op_expr_p (tree t)
937 : {
938 871921 : if (t == NULL_TREE)
939 : return false;
940 :
941 871921 : if (TREE_CODE (t) == MODIFY_EXPR
942 871921 : || (TREE_CODE (t) == MODOP_EXPR
943 336 : && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
944 : return true;
945 :
946 871234 : tree call = extract_call_expr (t);
947 871234 : if (call == NULL_TREE
948 128518 : || call == error_mark_node
949 999752 : || !CALL_EXPR_OPERATOR_SYNTAX (call))
950 : return false;
951 :
952 4605 : tree fndecl = cp_get_callee_fndecl_nofold (call);
953 4605 : return fndecl != NULL_TREE
954 4569 : && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
955 4656 : && 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 86378701 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
1019 : tsubst_flags_t complain)
1020 : {
1021 86378701 : tree type = TREE_TYPE (t);
1022 86378701 : t = STRIP_REFERENCE_REF (t);
1023 :
1024 86378701 : if ((complain & tf_warning)
1025 86319238 : && warn_parentheses
1026 871921 : && 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 86379048 : && (!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 86378701 : }
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 50878641 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
1072 : {
1073 50878641 : tree *t = cond;
1074 50888582 : while (TREE_CODE (*t) == ANNOTATE_EXPR)
1075 9941 : t = &TREE_OPERAND (*t, 0);
1076 :
1077 50878641 : if (t != cond)
1078 : {
1079 9938 : m_annotations = *cond;
1080 9938 : *cond = *t;
1081 9938 : m_inner = t;
1082 : }
1083 50878641 : }
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 50878641 : annotate_saver::restore (tree new_inner)
1092 : {
1093 50878641 : 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 9938 : 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 9938 : *m_inner = new_inner;
1118 9938 : 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 88815359 : maybe_convert_cond (tree cond)
1127 : {
1128 : /* Empty conditions remain empty. */
1129 88815359 : if (!cond)
1130 : return NULL_TREE;
1131 :
1132 : /* Wait until we instantiate templates before doing conversion. */
1133 88452361 : if (type_dependent_expression_p (cond))
1134 37573720 : return cond;
1135 :
1136 : /* Strip any ANNOTATE_EXPRs from COND. */
1137 50878641 : annotate_saver annotations (&cond);
1138 :
1139 : /* For structured binding used in condition, the conversion needs to be
1140 : evaluated before the individual variables are initialized in the
1141 : std::tuple_{size,elemenet} case. cp_finish_decomp saved the conversion
1142 : result in a TARGET_EXPR, pick it up from there. */
1143 351325 : if (DECL_DECOMPOSITION_P (cond)
1144 224 : && DECL_DECOMP_IS_BASE (cond)
1145 224 : && DECL_DECOMP_BASE (cond)
1146 50878862 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1147 56 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1148 :
1149 50878641 : if (warn_sequence_point && !processing_template_decl)
1150 323907 : verify_sequence_points (cond);
1151 :
1152 50878641 : maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
1153 : tf_warning_or_error);
1154 :
1155 : /* Do the conversion. */
1156 50878641 : cond = convert_from_reference (cond);
1157 50878641 : cond = condition_conversion (cond);
1158 :
1159 : /* Restore any ANNOTATE_EXPRs around COND. */
1160 50878641 : return annotations.restore (cond);
1161 : }
1162 :
1163 : /* Finish an expression-statement, whose EXPRESSION is as indicated. */
1164 :
1165 : tree
1166 159011617 : finish_expr_stmt (tree expr)
1167 : {
1168 159011617 : tree r = NULL_TREE;
1169 159011617 : location_t loc = EXPR_LOCATION (expr);
1170 :
1171 158854786 : if (expr != NULL_TREE)
1172 : {
1173 : /* If we ran into a problem, make sure we complained. */
1174 159011456 : gcc_assert (expr != error_mark_node || seen_error ());
1175 :
1176 159011456 : if (!processing_template_decl)
1177 : {
1178 57038074 : if (warn_sequence_point)
1179 806733 : verify_sequence_points (expr);
1180 57038074 : expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1181 : }
1182 101973382 : else if (!type_dependent_expression_p (expr))
1183 22163061 : convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1184 :
1185 159011453 : 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 159011453 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
1192 : {
1193 159011274 : if (TREE_CODE (expr) != EXPR_STMT
1194 156620153 : && !STATEMENT_CLASS_P (expr)
1195 156616002 : && TREE_CODE (expr) != STATEMENT_LIST)
1196 156497273 : expr = build_stmt (loc, EXPR_STMT, expr);
1197 159011274 : expr = maybe_cleanup_point_expr_void (expr);
1198 : }
1199 :
1200 159011453 : r = add_stmt (expr);
1201 : }
1202 :
1203 159011614 : return r;
1204 : }
1205 :
1206 :
1207 : /* Begin an if-statement. Returns a newly created IF_STMT if
1208 : appropriate. */
1209 :
1210 : tree
1211 71430441 : begin_if_stmt (void)
1212 : {
1213 71430441 : tree r, scope;
1214 71430441 : scope = do_pushlevel (sk_cond);
1215 71430441 : r = build_stmt (input_location, IF_STMT, NULL_TREE,
1216 : NULL_TREE, NULL_TREE, scope);
1217 71430441 : current_binding_level->this_entity = r;
1218 71430441 : begin_cond (&IF_COND (r));
1219 71430441 : 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 252043 : is_std_constant_evaluated_p (tree fn)
1227 : {
1228 : /* std::is_constant_evaluated takes no arguments. */
1229 252043 : if (call_expr_nargs (fn) != 0)
1230 : return false;
1231 :
1232 89792 : tree fndecl = cp_get_callee_fndecl_nofold (fn);
1233 89792 : if (fndecl == NULL_TREE)
1234 : return false;
1235 :
1236 27650 : if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
1237 : BUILT_IN_FRONTEND))
1238 : return true;
1239 :
1240 27621 : if (!decl_in_std_namespace_p (fndecl))
1241 : return false;
1242 :
1243 12284 : tree name = DECL_NAME (fndecl);
1244 12284 : 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 4668947 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
1252 : {
1253 4668947 : tree t = *tp;
1254 :
1255 4668947 : if (TYPE_P (t) || TREE_CONSTANT (t))
1256 : {
1257 823323 : *walk_subtrees = false;
1258 823323 : return NULL_TREE;
1259 : }
1260 :
1261 3845624 : switch (TREE_CODE (t))
1262 : {
1263 252043 : case CALL_EXPR:
1264 252043 : 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 71515989 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
1284 : bool trivial_infinite)
1285 : {
1286 71515989 : if (!warn_tautological_compare)
1287 : return;
1288 :
1289 : /* Suppress warning for std::is_constant_evaluated if the conditional
1290 : comes from a macro. */
1291 1423368 : if (from_macro_expansion_at (EXPR_LOCATION (cond)))
1292 : return;
1293 :
1294 600245 : cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
1295 : NULL);
1296 600245 : if (cond)
1297 : {
1298 2446 : 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 2412 : 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 2404 : 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 4732 : 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 71430441 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
1330 : {
1331 71430441 : tree cond = maybe_convert_cond (orig_cond);
1332 71430441 : maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
1333 : /*trivial_infinite=*/false);
1334 71430441 : if (IF_STMT_CONSTEXPR_P (if_stmt)
1335 14722254 : && !type_dependent_expression_p (cond)
1336 9898821 : && require_constant_expression (cond)
1337 9898792 : && !instantiation_dependent_expression_p (cond)
1338 : /* Wait until instantiation time, since only then COND has been
1339 : converted to bool. */
1340 76776288 : && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
1341 : {
1342 5345847 : cond = instantiate_non_dependent_expr (cond);
1343 5345847 : cond = cxx_constant_value (cond);
1344 : }
1345 66084594 : else if (processing_template_decl)
1346 49719826 : cond = orig_cond;
1347 71430441 : finish_cond (&IF_COND (if_stmt), cond);
1348 71430441 : add_stmt (if_stmt);
1349 71430441 : THEN_CLAUSE (if_stmt) = push_stmt_list ();
1350 71430441 : 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 71425582 : finish_then_clause (tree if_stmt)
1358 : {
1359 71425582 : THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
1360 71425582 : return if_stmt;
1361 : }
1362 :
1363 : /* Begin the else-clause of an if-statement. */
1364 :
1365 : void
1366 26718148 : begin_else_clause (tree if_stmt)
1367 : {
1368 26718148 : ELSE_CLAUSE (if_stmt) = push_stmt_list ();
1369 26718148 : }
1370 :
1371 : /* Finish the else-clause of an if-statement, which may be given by
1372 : IF_STMT. */
1373 :
1374 : void
1375 26718110 : finish_else_clause (tree if_stmt)
1376 : {
1377 26718110 : ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
1378 26718110 : }
1379 :
1380 : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1381 : read. */
1382 :
1383 : static tree
1384 792646844 : maybe_mark_exp_read_r (tree *tp, int *, void *)
1385 : {
1386 792646844 : tree t = *tp;
1387 792646844 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1388 45761282 : mark_exp_read (t);
1389 792646844 : return NULL_TREE;
1390 : }
1391 :
1392 : /* Finish an if-statement. */
1393 :
1394 : void
1395 71425582 : finish_if_stmt (tree if_stmt)
1396 : {
1397 71425582 : tree scope = IF_SCOPE (if_stmt);
1398 71425582 : IF_SCOPE (if_stmt) = NULL;
1399 71425582 : 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 14717395 : cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
1405 : maybe_mark_exp_read_r, NULL);
1406 14717395 : cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
1407 : maybe_mark_exp_read_r, NULL);
1408 : }
1409 71425582 : add_stmt (do_poplevel (scope));
1410 71425582 : }
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 17018632 : finish_loop_cond (tree *condp, tree body)
1421 : {
1422 17018632 : if (TREE_CODE (*condp) == INTEGER_CST)
1423 : return;
1424 12266159 : bool trivially_empty = expr_first (body) == NULL_TREE;
1425 12266159 : bool trivial_infinite = false;
1426 12266159 : if (trivially_empty)
1427 : {
1428 95748 : tree c = fold_non_dependent_expr (*condp, tf_none,
1429 : /*manifestly_const_eval=*/true);
1430 95748 : trivial_infinite = c && integer_nonzerop (c);
1431 : }
1432 12266159 : if (warn_tautological_compare)
1433 : {
1434 85750 : tree cond = *condp;
1435 86117 : while (TREE_CODE (cond) == ANNOTATE_EXPR)
1436 367 : cond = TREE_OPERAND (cond, 0);
1437 85750 : if (trivial_infinite
1438 85814 : && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1439 64 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1440 : /*trivial_infinite=*/true);
1441 85686 : else if (!trivially_empty
1442 375 : || !processing_template_decl
1443 86090 : || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1444 85484 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1445 : /*trivial_infinite=*/false);
1446 : }
1447 12266159 : 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 4664827 : begin_while_stmt (void)
1459 : {
1460 4664827 : tree r;
1461 4664827 : r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1462 : NULL_TREE, NULL_TREE);
1463 4664827 : add_stmt (r);
1464 4664827 : WHILE_BODY (r) = do_pushlevel (sk_block);
1465 4664827 : begin_cond (&WHILE_COND (r));
1466 4664827 : return r;
1467 : }
1468 :
1469 : /* Process the COND of a while-statement, which may be given by
1470 : WHILE_STMT. */
1471 :
1472 : void
1473 4664827 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
1474 : tree unroll, bool novector)
1475 : {
1476 4664827 : cond = maybe_convert_cond (cond);
1477 4664827 : finish_cond (&WHILE_COND (while_stmt), cond);
1478 4664827 : begin_maybe_infinite_loop (cond);
1479 4664827 : 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 4664827 : if (unroll && cond != error_mark_node)
1487 26122 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1488 13061 : TREE_TYPE (WHILE_COND (while_stmt)),
1489 13061 : WHILE_COND (while_stmt),
1490 : build_int_cst (integer_type_node,
1491 : annot_expr_unroll_kind),
1492 : unroll);
1493 4664827 : 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 4664827 : adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
1501 : &WHILE_COND_PREP (while_stmt),
1502 : &WHILE_COND_CLEANUP (while_stmt));
1503 4664827 : }
1504 :
1505 : /* Finish a while-statement, which may be given by WHILE_STMT. */
1506 :
1507 : void
1508 4664827 : finish_while_stmt (tree while_stmt)
1509 : {
1510 4664827 : end_maybe_infinite_loop (boolean_true_node);
1511 4664827 : if (WHILE_COND_PREP (while_stmt))
1512 9259 : finish_loop_cond_prep (&WHILE_BODY (while_stmt),
1513 : &WHILE_COND_PREP (while_stmt),
1514 9259 : WHILE_COND_CLEANUP (while_stmt));
1515 : else
1516 4655568 : WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
1517 4664827 : finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
1518 4664827 : }
1519 :
1520 : /* Begin a do-statement. Returns a newly created DO_STMT if
1521 : appropriate. */
1522 :
1523 : tree
1524 5445767 : begin_do_stmt (void)
1525 : {
1526 5445767 : tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
1527 : NULL_TREE);
1528 5445767 : begin_maybe_infinite_loop (boolean_true_node);
1529 5445767 : add_stmt (r);
1530 5445767 : DO_BODY (r) = push_stmt_list ();
1531 5445767 : return r;
1532 : }
1533 :
1534 : /* Finish the body of a do-statement, which may be given by DO_STMT. */
1535 :
1536 : void
1537 5445767 : finish_do_body (tree do_stmt)
1538 : {
1539 5445767 : tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
1540 :
1541 5445767 : if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
1542 521623 : body = STATEMENT_LIST_TAIL (body)->stmt;
1543 :
1544 5445767 : if (IS_EMPTY_STMT (body))
1545 30 : warning (OPT_Wempty_body,
1546 : "suggest explicit braces around empty body in %<do%> statement");
1547 5445767 : }
1548 :
1549 : /* Finish a do-statement, which may be given by DO_STMT, and whose
1550 : COND is as indicated. */
1551 :
1552 : void
1553 5445767 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
1554 : bool novector)
1555 : {
1556 5445767 : cond = maybe_convert_cond (cond);
1557 5445767 : 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 5445767 : if (check_for_bare_parameter_packs (cond))
1562 3 : cond = error_mark_node;
1563 5445767 : 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 5445767 : 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 5445767 : 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 5445767 : DO_COND (do_stmt) = cond;
1576 5445767 : tree do_body = DO_BODY (do_stmt);
1577 5445737 : if (CONVERT_EXPR_P (do_body)
1578 30 : && integer_zerop (TREE_OPERAND (do_body, 0))
1579 5445797 : && VOID_TYPE_P (TREE_TYPE (do_body)))
1580 : do_body = NULL_TREE;
1581 5445767 : finish_loop_cond (&DO_COND (do_stmt), do_body);
1582 5445767 : }
1583 :
1584 : /* Finish a return-statement. The EXPRESSION returned, if any, is as
1585 : indicated. */
1586 :
1587 : tree
1588 124415217 : finish_return_stmt (tree expr)
1589 : {
1590 124415217 : tree r;
1591 124415217 : bool no_warning;
1592 124415217 : bool dangling;
1593 :
1594 124415217 : expr = check_return_expr (expr, &no_warning, &dangling);
1595 :
1596 124415217 : if (error_operand_p (expr)
1597 124415217 : || (flag_openmp && !check_omp_return ()))
1598 : {
1599 : /* Suppress -Wreturn-type for this function. */
1600 1243 : if (warn_return_type)
1601 1237 : suppress_warning (current_function_decl, OPT_Wreturn_type);
1602 1243 : return error_mark_node;
1603 : }
1604 :
1605 124413974 : if (!processing_template_decl)
1606 : {
1607 43580283 : if (warn_sequence_point)
1608 1021500 : verify_sequence_points (expr);
1609 : }
1610 :
1611 124413974 : r = build_stmt (input_location, RETURN_EXPR, expr);
1612 124413974 : RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
1613 124413974 : if (no_warning)
1614 33 : suppress_warning (r, OPT_Wreturn_type);
1615 124413974 : r = maybe_cleanup_point_expr_void (r);
1616 124413974 : r = add_stmt (r);
1617 :
1618 124413974 : 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 7479684 : begin_for_scope (tree *init)
1627 : {
1628 7479684 : tree scope = do_pushlevel (sk_for);
1629 :
1630 7479684 : if (processing_template_decl)
1631 5939414 : *init = push_stmt_list ();
1632 : else
1633 1540270 : *init = NULL_TREE;
1634 :
1635 7479684 : 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 7271036 : begin_for_stmt (tree scope, tree init)
1644 : {
1645 7271036 : tree r;
1646 :
1647 7271036 : 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 7271036 : if (scope == NULL_TREE)
1652 : {
1653 1295889 : gcc_assert (!init);
1654 1295889 : scope = begin_for_scope (&init);
1655 : }
1656 :
1657 7271036 : FOR_INIT_STMT (r) = init;
1658 7271036 : FOR_SCOPE (r) = scope;
1659 :
1660 7271036 : 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 7271036 : finish_init_stmt (tree for_stmt)
1668 : {
1669 7271036 : if (processing_template_decl)
1670 5730766 : FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
1671 7271036 : add_stmt (for_stmt);
1672 7271036 : FOR_BODY (for_stmt) = do_pushlevel (sk_block);
1673 7271036 : begin_cond (&FOR_COND (for_stmt));
1674 7271036 : }
1675 :
1676 : /* Finish the COND of a for-statement, which may be given by
1677 : FOR_STMT. */
1678 :
1679 : void
1680 7271036 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
1681 : bool novector)
1682 : {
1683 7271036 : cond = maybe_convert_cond (cond);
1684 7271036 : finish_cond (&FOR_COND (for_stmt), cond);
1685 7271036 : begin_maybe_infinite_loop (cond);
1686 7271036 : 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 7271036 : 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 7271036 : 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 7271036 : adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
1708 : &FOR_COND_CLEANUP (for_stmt));
1709 7271036 : }
1710 :
1711 : /* Finish the increment-EXPRESSION in a for-statement, which may be
1712 : given by FOR_STMT. */
1713 :
1714 : void
1715 7258800 : finish_for_expr (tree expr, tree for_stmt)
1716 : {
1717 7258800 : 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 6809936 : if (type_unknown_p (expr))
1722 : {
1723 6 : cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1724 6 : expr = error_mark_node;
1725 : }
1726 6809936 : if (!processing_template_decl)
1727 : {
1728 1470008 : if (warn_sequence_point)
1729 14876 : verify_sequence_points (expr);
1730 1470008 : expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1731 : tf_warning_or_error);
1732 : }
1733 5339928 : else if (!type_dependent_expression_p (expr))
1734 1914826 : convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
1735 6809936 : expr = maybe_cleanup_point_expr_void (expr);
1736 6809936 : if (check_for_bare_parameter_packs (expr))
1737 0 : expr = error_mark_node;
1738 6809936 : 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 7479797 : find_range_for_decls (tree range_for_decl[3])
1749 : {
1750 7479797 : 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 29919188 : for (int i = 0; i < 3; i++)
1756 : {
1757 22439391 : tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1758 22439391 : if (IDENTIFIER_BINDING (id)
1759 22439391 : && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1760 : {
1761 258946 : range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1762 258946 : gcc_assert (VAR_P (range_for_decl[i])
1763 : && DECL_ARTIFICIAL (range_for_decl[i]));
1764 : }
1765 : }
1766 7479797 : }
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 7479684 : finish_for_stmt (tree for_stmt)
1775 : {
1776 7479684 : end_maybe_infinite_loop (boolean_true_node);
1777 :
1778 7479684 : if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1779 208648 : RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1780 : else
1781 : {
1782 7271036 : 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 7270862 : FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1788 7271036 : if (FOR_COND (for_stmt))
1789 6908038 : finish_loop_cond (&FOR_COND (for_stmt),
1790 6908038 : FOR_EXPR (for_stmt) ? integer_one_node
1791 137645 : : FOR_BODY (for_stmt));
1792 : }
1793 :
1794 : /* Pop the scope for the body of the loop. */
1795 7479684 : tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1796 7479684 : ? &RANGE_FOR_SCOPE (for_stmt)
1797 7271036 : : &FOR_SCOPE (for_stmt));
1798 7479684 : tree scope = *scope_ptr;
1799 7479684 : *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 7479684 : tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1806 7479684 : find_range_for_decls (range_for_decl);
1807 :
1808 7479684 : 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 7479684 : if (!stmts_are_full_exprs_p ())
1813 12236 : return;
1814 :
1815 29869792 : for (int i = 0; i < 3; i++)
1816 22402344 : if (range_for_decl[i])
1817 258830 : DECL_NAME (range_for_decl[i])
1818 258830 : = 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 208648 : begin_range_for_stmt (tree scope, tree init)
1828 : {
1829 208648 : begin_maybe_infinite_loop (boolean_false_node);
1830 :
1831 208648 : tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1832 : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1833 :
1834 208648 : if (scope == NULL_TREE)
1835 : {
1836 254 : gcc_assert (!init);
1837 254 : scope = begin_for_scope (&init);
1838 : }
1839 :
1840 : /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1841 208648 : RANGE_FOR_INIT_STMT (r) = init;
1842 208648 : RANGE_FOR_SCOPE (r) = scope;
1843 :
1844 208648 : 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 208648 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1853 : {
1854 208648 : if (processing_template_decl)
1855 417296 : RANGE_FOR_INIT_STMT (range_for_stmt)
1856 417296 : = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1857 208648 : RANGE_FOR_DECL (range_for_stmt) = decl;
1858 208648 : RANGE_FOR_EXPR (range_for_stmt) = expr;
1859 208648 : add_stmt (range_for_stmt);
1860 208648 : RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1861 208648 : }
1862 :
1863 : /* Begin the scope of an expansion-statement. */
1864 :
1865 : tree
1866 1443 : begin_template_for_scope (tree *init)
1867 : {
1868 1443 : tree scope = do_pushlevel (sk_template_for);
1869 :
1870 1443 : if (processing_template_decl)
1871 419 : *init = push_stmt_list ();
1872 : else
1873 1024 : *init = NULL_TREE;
1874 :
1875 1443 : return scope;
1876 : }
1877 :
1878 : /* Finish a break-statement. */
1879 :
1880 : tree
1881 4658108 : 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 4658108 : if (!block_may_fallthru (cur_stmt_list))
1891 711 : return void_node;
1892 4657397 : note_break_stmt ();
1893 4657397 : return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
1894 : }
1895 :
1896 : /* Finish a continue-statement. */
1897 :
1898 : tree
1899 225774 : finish_continue_stmt (void)
1900 : {
1901 225774 : 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 669248 : begin_switch_stmt (void)
1909 : {
1910 669248 : tree r, scope;
1911 :
1912 669248 : scope = do_pushlevel (sk_cond);
1913 669248 : r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1914 : scope, NULL_TREE);
1915 :
1916 669248 : begin_cond (&SWITCH_STMT_COND (r));
1917 :
1918 669248 : return r;
1919 : }
1920 :
1921 : /* Finish the cond of a switch-statement. */
1922 :
1923 : void
1924 669248 : finish_switch_cond (tree cond, tree switch_stmt)
1925 : {
1926 669248 : tree orig_type = NULL;
1927 :
1928 669248 : if (!processing_template_decl)
1929 : {
1930 : /* Convert the condition to an integer or enumeration type. */
1931 259558 : tree orig_cond = cond;
1932 : /* For structured binding used in condition, the conversion needs to be
1933 : evaluated before the individual variables are initialized in the
1934 : std::tuple_{size,elemenet} case. cp_finish_decomp saved the
1935 : conversion result in a TARGET_EXPR, pick it up from there. */
1936 122 : if (DECL_DECOMPOSITION_P (cond)
1937 57 : && DECL_DECOMP_IS_BASE (cond)
1938 57 : && DECL_DECOMP_BASE (cond)
1939 259612 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1940 18 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1941 259558 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1942 259558 : 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 259558 : orig_type = unlowered_expr_type (cond);
1950 259558 : if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1951 182788 : orig_type = TREE_TYPE (cond);
1952 259558 : if (cond != error_mark_node)
1953 : {
1954 : /* [stmt.switch]
1955 :
1956 : Integral promotions are performed. */
1957 259525 : cond = perform_integral_promotions (cond);
1958 259525 : cond = maybe_cleanup_point_expr (cond);
1959 : }
1960 : }
1961 669248 : if (check_for_bare_parameter_packs (cond))
1962 0 : cond = error_mark_node;
1963 669248 : else if (!processing_template_decl && warn_sequence_point)
1964 2776 : verify_sequence_points (cond);
1965 :
1966 669248 : finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1967 669248 : SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1968 669248 : add_stmt (switch_stmt);
1969 669248 : push_switch (switch_stmt);
1970 669248 : SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1971 669248 : }
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 669248 : finish_switch_stmt (tree switch_stmt)
1978 : {
1979 669248 : tree scope;
1980 :
1981 1338496 : SWITCH_STMT_BODY (switch_stmt) =
1982 669248 : pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1983 669248 : pop_switch ();
1984 :
1985 669248 : scope = SWITCH_STMT_SCOPE (switch_stmt);
1986 669248 : SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1987 669248 : add_stmt (do_poplevel (scope));
1988 669248 : }
1989 :
1990 : /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1991 : appropriate. */
1992 :
1993 : tree
1994 1139416 : begin_try_block (void)
1995 : {
1996 1139416 : tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1997 1139416 : add_stmt (r);
1998 1139416 : TRY_STMTS (r) = push_stmt_list ();
1999 1139416 : return r;
2000 : }
2001 :
2002 : /* Likewise, for a function-try-block. The block returned in
2003 : *COMPOUND_STMT is an artificial outer scope, containing the
2004 : function-try-block. */
2005 :
2006 : tree
2007 330 : begin_function_try_block (tree *compound_stmt)
2008 : {
2009 330 : tree r;
2010 : /* This outer scope does not exist in the C++ standard, but we need
2011 : a place to put __FUNCTION__ and similar variables. */
2012 330 : *compound_stmt = begin_compound_stmt (0);
2013 330 : current_binding_level->artificial = 1;
2014 330 : r = begin_try_block ();
2015 330 : FN_TRY_BLOCK_P (r) = 1;
2016 330 : return r;
2017 : }
2018 :
2019 : /* Finish a try-block, which may be given by TRY_BLOCK. */
2020 :
2021 : void
2022 1139416 : finish_try_block (tree try_block)
2023 : {
2024 1139416 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2025 1139416 : TRY_HANDLERS (try_block) = push_stmt_list ();
2026 1139416 : }
2027 :
2028 : /* Finish the body of a cleanup try-block, which may be given by
2029 : TRY_BLOCK. */
2030 :
2031 : void
2032 0 : finish_cleanup_try_block (tree try_block)
2033 : {
2034 0 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2035 0 : }
2036 :
2037 : /* Finish an implicitly generated try-block, with a cleanup is given
2038 : by CLEANUP. */
2039 :
2040 : void
2041 0 : finish_cleanup (tree cleanup, tree try_block)
2042 : {
2043 0 : TRY_HANDLERS (try_block) = cleanup;
2044 0 : CLEANUP_P (try_block) = 1;
2045 0 : }
2046 :
2047 : /* Likewise, for a function-try-block. */
2048 :
2049 : void
2050 330 : finish_function_try_block (tree try_block)
2051 : {
2052 330 : finish_try_block (try_block);
2053 : /* FIXME : something queer about CTOR_INITIALIZER somehow following
2054 : the try block, but moving it inside. */
2055 330 : in_function_try_handler = 1;
2056 330 : }
2057 :
2058 : /* Finish a handler-sequence for a try-block, which may be given by
2059 : TRY_BLOCK. */
2060 :
2061 : void
2062 1139416 : finish_handler_sequence (tree try_block)
2063 : {
2064 1139416 : TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
2065 1139416 : check_handlers (TRY_HANDLERS (try_block));
2066 1139416 : }
2067 :
2068 : /* Finish the handler-seq for a function-try-block, given by
2069 : TRY_BLOCK. COMPOUND_STMT is the outer block created by
2070 : begin_function_try_block. */
2071 :
2072 : void
2073 330 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
2074 : {
2075 330 : in_function_try_handler = 0;
2076 330 : finish_handler_sequence (try_block);
2077 330 : finish_compound_stmt (compound_stmt);
2078 330 : }
2079 :
2080 : /* Begin a handler. Returns a HANDLER if appropriate. */
2081 :
2082 : tree
2083 1589164 : begin_handler (void)
2084 : {
2085 1589164 : tree r;
2086 :
2087 1589164 : r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
2088 1589164 : add_stmt (r);
2089 :
2090 : /* Create a binding level for the eh_info and the exception object
2091 : cleanup. */
2092 1589164 : HANDLER_BODY (r) = do_pushlevel (sk_catch);
2093 :
2094 1589164 : 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 1589164 : finish_handler_parms (tree decl, tree handler)
2103 : {
2104 1589164 : tree type = NULL_TREE;
2105 1589164 : if (processing_template_decl)
2106 : {
2107 1450403 : if (decl)
2108 : {
2109 472898 : decl = pushdecl (decl);
2110 472898 : decl = push_template_decl (decl);
2111 472898 : HANDLER_PARMS (handler) = decl;
2112 472898 : type = TREE_TYPE (decl);
2113 : }
2114 : }
2115 : else
2116 : {
2117 138761 : type = expand_start_catch_block (decl);
2118 138761 : if (warn_catch_value
2119 2118 : && type != NULL_TREE
2120 711 : && type != error_mark_node
2121 139472 : && !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 1589164 : HANDLER_TYPE (handler) = type;
2143 1589164 : }
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 1589164 : finish_handler (tree handler)
2150 : {
2151 1589164 : if (!processing_template_decl)
2152 138761 : expand_end_catch_block ();
2153 1589164 : HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
2154 1589164 : }
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 276994987 : begin_compound_stmt (unsigned int flags)
2165 : {
2166 276994987 : tree r;
2167 :
2168 276994987 : if (flags & BCS_NO_SCOPE)
2169 : {
2170 5145687 : r = push_stmt_list ();
2171 5145687 : 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 5145687 : keep_next_level (false);
2178 : }
2179 : else
2180 : {
2181 271849300 : scope_kind sk = sk_block;
2182 271849300 : if (flags & BCS_TRY_BLOCK)
2183 : sk = sk_try;
2184 270710003 : else if (flags & BCS_TRANSACTION)
2185 : sk = sk_transaction;
2186 270709768 : else if (flags & BCS_STMT_EXPR)
2187 29082 : sk = sk_stmt_expr;
2188 271849300 : 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 276994987 : if (processing_template_decl)
2198 : {
2199 186362681 : r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
2200 186362681 : BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
2201 186362681 : BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
2202 186362681 : TREE_SIDE_EFFECTS (r) = 1;
2203 : }
2204 :
2205 276994987 : return r;
2206 : }
2207 :
2208 : /* Finish a compound-statement, which is given by STMT. */
2209 :
2210 : void
2211 276994948 : finish_compound_stmt (tree stmt)
2212 : {
2213 276994948 : if (TREE_CODE (stmt) == BIND_EXPR)
2214 : {
2215 186362681 : 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 186362681 : if (TREE_CODE (body) == STATEMENT_LIST
2220 170598647 : && STATEMENT_LIST_HEAD (body) == NULL
2221 11427254 : && !BIND_EXPR_BODY_BLOCK (stmt)
2222 197287650 : && !BIND_EXPR_TRY_BLOCK (stmt))
2223 : stmt = body;
2224 : else
2225 175437809 : BIND_EXPR_BODY (stmt) = body;
2226 : }
2227 90632267 : else if (STATEMENT_LIST_NO_SCOPE (stmt))
2228 5109275 : stmt = pop_stmt_list (stmt);
2229 : else
2230 : {
2231 : /* Destroy any ObjC "super" receivers that may have been
2232 : created. */
2233 85522992 : objc_clear_super_receiver ();
2234 :
2235 85522992 : stmt = do_poplevel (stmt);
2236 : }
2237 :
2238 : /* ??? See c_end_compound_stmt wrt statement expressions. */
2239 276994948 : add_stmt (stmt);
2240 276994948 : }
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 54017 : finish_asm_string_expression (location_t loc, tree string)
2248 : {
2249 54017 : if (string == error_mark_node
2250 54004 : || 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 25781 : 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 25781 : tree r;
2277 25781 : tree t;
2278 25781 : int ninputs = list_length (input_operands);
2279 25781 : int noutputs = list_length (output_operands);
2280 :
2281 25781 : if (!processing_template_decl)
2282 : {
2283 12400 : const char *constraint;
2284 12400 : const char **oconstraints;
2285 12400 : bool allows_mem, allows_reg, is_inout;
2286 12400 : tree operand;
2287 12400 : int i;
2288 :
2289 12400 : oconstraints = XALLOCAVEC (const char *, noutputs);
2290 :
2291 24698 : string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
2292 : string);
2293 12400 : if (string == error_mark_node)
2294 109 : return error_mark_node;
2295 36918 : for (int i = 0; i < 2; ++i)
2296 84788 : for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
2297 : {
2298 35564 : tree s = TREE_VALUE (TREE_PURPOSE (t));
2299 71110 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2300 35564 : if (s == error_mark_node)
2301 : return error_mark_node;
2302 35534 : TREE_VALUE (TREE_PURPOSE (t)) = s;
2303 : }
2304 17744 : for (t = clobbers; t; t = TREE_CHAIN (t))
2305 : {
2306 5453 : tree s = TREE_VALUE (t);
2307 10900 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2308 5453 : TREE_VALUE (t) = s;
2309 : }
2310 :
2311 12291 : string = resolve_asm_operand_names (string, output_operands,
2312 : input_operands, labels);
2313 :
2314 30892 : for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
2315 : {
2316 18601 : 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 18601 : STRIP_NOPS (operand);
2325 :
2326 18601 : operand = mark_lvalue_use (operand);
2327 :
2328 18601 : if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
2329 9 : operand = error_mark_node;
2330 :
2331 18601 : if (operand != error_mark_node
2332 18601 : && (TREE_READONLY (operand)
2333 18586 : || CP_TYPE_CONST_P (TREE_TYPE (operand))
2334 : /* Functions are not modifiable, even though they are
2335 : lvalues. */
2336 18586 : || 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 18586 : || (CLASS_TYPE_P (TREE_TYPE (operand))
2340 150 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
2341 6 : cxx_readonly_error (loc, operand, lv_asm);
2342 :
2343 : tree *op = &operand;
2344 18608 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2345 7 : op = &TREE_OPERAND (*op, 1);
2346 18601 : 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 18601 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2359 18601 : oconstraints[i] = constraint;
2360 :
2361 18601 : 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 18592 : if (!allows_reg && !cxx_mark_addressable (*op))
2368 0 : operand = error_mark_node;
2369 18592 : if (allows_reg && toplev_p)
2370 : {
2371 3 : error_at (loc, "constraint allows registers outside of "
2372 : "a function");
2373 3 : operand = error_mark_node;
2374 : }
2375 : }
2376 : else
2377 9 : operand = error_mark_node;
2378 :
2379 439 : if (toplev_p && operand != error_mark_node)
2380 : {
2381 21 : if (TREE_SIDE_EFFECTS (operand))
2382 : {
2383 0 : error_at (loc, "side-effects in output operand outside "
2384 : "of a function");
2385 0 : operand = error_mark_node;
2386 : }
2387 : else
2388 : {
2389 21 : tree addr
2390 21 : = cp_build_addr_expr (operand, tf_warning_or_error);
2391 21 : if (addr == error_mark_node)
2392 0 : operand = error_mark_node;
2393 : else
2394 : {
2395 21 : addr = maybe_constant_value (addr);
2396 21 : if (!initializer_constant_valid_p (addr,
2397 21 : TREE_TYPE (addr)))
2398 : {
2399 3 : error_at (loc, "output operand outside of a "
2400 : "function is not constant");
2401 3 : operand = error_mark_node;
2402 : }
2403 : else
2404 18 : operand = build_fold_indirect_ref (addr);
2405 : }
2406 : }
2407 : }
2408 18580 : 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 18601 : TREE_VALUE (t) = operand;
2415 : }
2416 :
2417 29219 : for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
2418 : {
2419 16928 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2420 16928 : bool constraint_parsed
2421 16928 : = 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 16928 : if (constraint_parsed && !allows_reg && allows_mem)
2427 302 : operand = mark_lvalue_use (TREE_VALUE (t));
2428 : else
2429 16626 : 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 16928 : 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 16928 : if (constraint_parsed)
2444 : {
2445 : /* If the operand is going to end up in memory,
2446 : mark it addressable. */
2447 16907 : 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 302 : STRIP_NOPS (operand);
2452 :
2453 302 : tree *op = &operand;
2454 309 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2455 7 : op = &TREE_OPERAND (*op, 1);
2456 302 : 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 302 : if (!cxx_mark_addressable (*op))
2469 0 : operand = error_mark_node;
2470 : }
2471 16605 : else if (!allows_reg && !allows_mem)
2472 : {
2473 : /* If constraint allows neither register nor memory,
2474 : try harder to get a constant. */
2475 474 : tree constop = maybe_constant_value (operand);
2476 474 : if (TREE_CONSTANT (constop))
2477 447 : operand = constop;
2478 : }
2479 16907 : 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 16907 : 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 16928 : 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 16811 : 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 16928 : TREE_VALUE (t) = operand;
2551 : }
2552 : }
2553 :
2554 25672 : r = build_stmt (loc, ASM_EXPR, string,
2555 : output_operands, input_operands,
2556 : clobbers, labels);
2557 25672 : ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
2558 25672 : ASM_INLINE_P (r) = inline_p;
2559 25672 : if (toplev_p)
2560 : {
2561 99 : symtab->finalize_toplevel_asm (r);
2562 99 : return r;
2563 : }
2564 25573 : r = maybe_cleanup_point_expr_void (r);
2565 25573 : return add_stmt (r);
2566 : }
2567 :
2568 : /* Finish a label with the indicated NAME. Returns the new label. */
2569 :
2570 : tree
2571 2478 : finish_label_stmt (tree name)
2572 : {
2573 2478 : tree decl = define_label (input_location, name);
2574 :
2575 2478 : if (decl == error_mark_node)
2576 : return error_mark_node;
2577 :
2578 2472 : add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
2579 :
2580 2472 : return decl;
2581 : }
2582 :
2583 : /* Finish a series of declarations for local labels. G++ allows users
2584 : to declare "local" labels, i.e., labels with scope. This extension
2585 : is useful when writing code involving statement-expressions. */
2586 :
2587 : void
2588 219 : finish_label_decl (tree name)
2589 : {
2590 219 : if (!at_function_scope_p ())
2591 : {
2592 0 : error ("%<__label__%> declarations are only allowed in function scopes");
2593 0 : return;
2594 : }
2595 :
2596 219 : add_decl_expr (declare_local_label (name));
2597 : }
2598 :
2599 : /* When DECL goes out of scope, make sure that CLEANUP is executed. */
2600 :
2601 : void
2602 3373925 : finish_decl_cleanup (tree decl, tree cleanup)
2603 : {
2604 3373925 : push_cleanup (decl, cleanup, false);
2605 3373925 : }
2606 :
2607 : /* If the current scope exits with an exception, run CLEANUP. */
2608 :
2609 : void
2610 2158629 : finish_eh_cleanup (tree cleanup)
2611 : {
2612 2158629 : push_cleanup (NULL, cleanup, true);
2613 2158629 : }
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 19949563 : 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 19949563 : mem_inits = nreverse (mem_inits);
2625 :
2626 19949563 : if (processing_template_decl)
2627 : {
2628 : tree mem;
2629 :
2630 33767463 : 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 19987864 : if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
2638 19987864 : && check_for_bare_parameter_packs (TREE_VALUE (mem)))
2639 3 : TREE_VALUE (mem) = error_mark_node;
2640 : }
2641 :
2642 13779599 : add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
2643 : CTOR_INITIALIZER, mem_inits));
2644 : }
2645 : else
2646 6169964 : emit_mem_initializers (mem_inits);
2647 19949563 : }
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 44424148 : force_paren_expr (tree expr, bool even_uneval /* = false */)
2655 : {
2656 : /* This is only needed for decltype(auto) in C++14. */
2657 44424148 : 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 43783053 : if (cp_unevaluated_operand && !even_uneval)
2663 : return expr;
2664 :
2665 36541819 : if (TREE_CODE (expr) == COMPONENT_REF
2666 36484646 : || TREE_CODE (expr) == SCOPE_REF
2667 73020479 : || REFERENCE_REF_P (expr))
2668 649047 : REF_PARENTHESIZED_P (expr) = true;
2669 35892772 : else if (DECL_P (tree_strip_any_location_wrapper (expr)))
2670 : {
2671 1723050 : location_t loc = cp_expr_location (expr);
2672 1723050 : const tree_code code = processing_template_decl ? PAREN_EXPR
2673 : : VIEW_CONVERT_EXPR;
2674 1723050 : expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
2675 1723050 : 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 944716267 : maybe_undo_parenthesized_ref (tree t)
2686 : {
2687 944716267 : if (cxx_dialect < cxx14)
2688 : return t;
2689 :
2690 934719639 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
2691 1037736929 : && REF_PARENTHESIZED_P (t))
2692 193028 : t = TREE_OPERAND (t, 0);
2693 :
2694 : return t;
2695 : }
2696 :
2697 : /* Finish a parenthesized expression EXPR. */
2698 :
2699 : cp_expr
2700 32618156 : finish_parenthesized_expr (cp_expr expr)
2701 : {
2702 32618156 : if (EXPR_P (expr))
2703 : {
2704 : /* This inhibits warnings in maybe_warn_unparenthesized_assignment
2705 : and c_common_truthvalue_conversion. */
2706 64947758 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
2707 : /* And maybe_warn_sizeof_array_div. */
2708 64947758 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
2709 : }
2710 :
2711 32618156 : if (TREE_CODE (expr) == OFFSET_REF
2712 32618156 : || 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 29141 : PTRMEM_OK_P (expr) = 0;
2716 :
2717 32618156 : tree stripped_expr = tree_strip_any_location_wrapper (expr);
2718 32618156 : if (TREE_CODE (stripped_expr) == STRING_CST)
2719 847498 : PAREN_STRING_LITERAL_P (stripped_expr) = 1;
2720 31770658 : else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
2721 906 : PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
2722 :
2723 32618156 : expr = cp_expr (force_paren_expr (expr), expr.get_location ());
2724 :
2725 32618156 : 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 75031758 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
2733 : tsubst_flags_t complain /* = tf_warning_or_error */)
2734 : {
2735 75031758 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
2736 75031758 : bool try_omp_private = !object && omp_private_member_map;
2737 65722946 : tree ret;
2738 :
2739 65722946 : if (!object)
2740 : {
2741 65722946 : tree scope = qualifying_scope;
2742 65722946 : if (scope == NULL_TREE)
2743 : {
2744 65711820 : scope = context_for_name_lookup (decl);
2745 65711820 : 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 65722943 : object = maybe_dummy_object (scope, NULL);
2753 : }
2754 :
2755 75031755 : object = maybe_resolve_dummy (object, true);
2756 75031755 : 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 75031752 : if (is_dummy_object (object)
2762 30756 : && !cp_unevaluated_operand
2763 75031849 : && (!processing_template_decl || !current_class_ref))
2764 : {
2765 82 : if (complain & tf_error)
2766 : {
2767 73 : auto_diagnostic_group d;
2768 73 : if (current_function_decl
2769 73 : && DECL_STATIC_FUNCTION_P (current_function_decl))
2770 3 : error ("invalid use of member %qD in static member function", decl);
2771 70 : else if (current_function_decl
2772 63 : && processing_contract_condition
2773 70 : && DECL_CONSTRUCTOR_P (current_function_decl))
2774 0 : error ("invalid use of member %qD in constructor %<pre%> contract", decl);
2775 70 : else if (current_function_decl
2776 63 : && processing_contract_condition
2777 70 : && DECL_DESTRUCTOR_P (current_function_decl))
2778 0 : error ("invalid use of member %qD in destructor %<post%> contract", decl);
2779 : else
2780 70 : error ("invalid use of non-static data member %qD", decl);
2781 73 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
2782 73 : }
2783 :
2784 82 : return error_mark_node;
2785 : }
2786 :
2787 75031670 : if (current_class_ptr)
2788 74765126 : TREE_USED (current_class_ptr) = 1;
2789 75031670 : if (processing_template_decl)
2790 : {
2791 59940033 : tree type = TREE_TYPE (decl);
2792 :
2793 59940033 : if (TYPE_REF_P (type))
2794 : /* Quals on the object don't matter. */;
2795 57716682 : else if (PACK_EXPANSION_P (type))
2796 : /* Don't bother trying to represent this. */
2797 : type = NULL_TREE;
2798 57714290 : 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 57712007 : int quals = cp_type_quals (TREE_TYPE (object));
2812 :
2813 57712007 : if (DECL_MUTABLE_P (decl))
2814 291416 : quals &= ~TYPE_QUAL_CONST;
2815 :
2816 57712007 : quals |= cp_type_quals (TREE_TYPE (decl));
2817 57712007 : type = cp_build_qualified_type (type, quals);
2818 : }
2819 :
2820 59940033 : if (qualifying_scope)
2821 : /* Wrap this in a SCOPE_REF for now. */
2822 9187 : ret = build_qualified_name (type, qualifying_scope, decl,
2823 : /*template_p=*/false);
2824 : else
2825 59930846 : ret = (convert_from_reference
2826 59930846 : (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 15091637 : tree access_type = TREE_TYPE (object);
2833 :
2834 15091637 : 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 15091637 : if (qualifying_scope)
2841 : {
2842 1900 : tree binfo = NULL_TREE;
2843 1900 : object = build_scoped_ref (object, qualifying_scope,
2844 : &binfo);
2845 : }
2846 :
2847 15091637 : ret = build_class_member_access_expr (object, decl,
2848 : /*access_path=*/NULL_TREE,
2849 : /*preserve_reference=*/false,
2850 : complain);
2851 : }
2852 75031670 : 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 4713444743 : 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 4713444743 : if (deferred_access_no_check)
2876 : return true;
2877 :
2878 : /* Determine the SCOPE of DECL. */
2879 4705532813 : tree scope = context_for_name_lookup (decl);
2880 : /* If the SCOPE is not a type, then DECL is not a member. */
2881 4705532813 : 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 4705532813 : || dependent_type_p (scope))
2886 4257304148 : return true;
2887 :
2888 448228665 : tree qualifying_type = NULL_TREE;
2889 : /* Compute the scope through which DECL is being accessed. */
2890 448228665 : 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 95202 : && CLASS_TYPE_P (object_type)
2900 448323850 : && 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 95176 : if (tree open = currently_open_class (object_type))
2905 : qualifying_type = open;
2906 : else
2907 : qualifying_type = object_type;
2908 : }
2909 448133489 : 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 591886489 : if (DECL_NONSTATIC_MEMBER_P (decl)
2915 295993093 : && current_class_ptr)
2916 40002 : if (tree current = current_nonlambda_class_type ())
2917 : {
2918 39979 : if (dependent_type_p (current))
2919 : /* In general we can't know whether this access goes through
2920 : `this' until instantiation time. Punt now, or else we might
2921 : create a deferred access check that's not relative to `this'
2922 : when it ought to be. We'll check this access again after
2923 : substitution, e.g. from tsubst_qualified_id. */
2924 : return true;
2925 :
2926 3565 : if (DERIVED_FROM_P (scope, current))
2927 : qualifying_type = current;
2928 : }
2929 : /* Otherwise, use the type indicated by the
2930 : nested-name-specifier. */
2931 : if (!qualifying_type)
2932 : qualifying_type = nested_name_specifier;
2933 : }
2934 : else
2935 : /* Otherwise, the name must be from the current class or one of
2936 : its bases. */
2937 152190243 : qualifying_type = currently_open_derived_class (scope);
2938 :
2939 448134071 : 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 448192251 : && CLASS_TYPE_P (qualifying_type))
2943 421935417 : return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2944 421935417 : 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 82811548 : 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 82811548 : gcc_assert (TYPE_P (qualifying_class));
2967 :
2968 82811548 : if (error_operand_p (expr))
2969 21 : return error_mark_node;
2970 :
2971 82811527 : if (DECL_P (expr)
2972 : /* Functions are marked after overload resolution; avoid redundant
2973 : warnings. */
2974 75943198 : && TREE_CODE (expr) != FUNCTION_DECL
2975 158754701 : && !mark_used (expr, complain))
2976 0 : return error_mark_node;
2977 :
2978 82811527 : if (template_p)
2979 : {
2980 241326 : 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 241317 : 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 82811527 : if (address_p && done
2994 155977 : && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
2995 : {
2996 155975 : if (TREE_CODE (expr) == SCOPE_REF)
2997 0 : expr = TREE_OPERAND (expr, 1);
2998 155975 : expr = build_offset_ref (qualifying_class, expr,
2999 : /*address_p=*/true, complain);
3000 155975 : return expr;
3001 : }
3002 :
3003 : /* No need to check access within an enum. */
3004 82655552 : if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
3005 3430264 : && 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 79225291 : 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 79222683 : else if (TREE_CODE (expr) == FIELD_DECL)
3015 : {
3016 11126 : push_deferring_access_checks (dk_no_check);
3017 11126 : expr = finish_non_static_data_member (expr, NULL_TREE,
3018 : qualifying_class, complain);
3019 11126 : pop_deferring_access_checks ();
3020 : }
3021 79211557 : 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 6427093 : if (!shared_member_p (expr)
3026 397155 : && current_class_ptr
3027 6823608 : && DERIVED_FROM_P (qualifying_class,
3028 : current_nonlambda_class_type ()))
3029 396313 : expr = (build_class_member_access_expr
3030 396313 : (maybe_dummy_object (qualifying_class, NULL),
3031 : expr,
3032 396313 : BASELINK_ACCESS_BINFO (expr),
3033 : /*preserve_reference=*/false,
3034 : complain));
3035 6030780 : else if (done)
3036 : /* The expression is a qualified name whose address is not
3037 : being taken. */
3038 2452 : expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
3039 : complain);
3040 : }
3041 72784464 : else if (!template_p
3042 72589708 : && TREE_CODE (expr) == TEMPLATE_DECL
3043 72784544 : && !DECL_FUNCTION_TEMPLATE_P (expr))
3044 : {
3045 80 : if (complain & tf_error)
3046 4 : error ("%qE missing template arguments", expr);
3047 80 : return error_mark_node;
3048 : }
3049 : else
3050 : {
3051 : /* In a template, return a SCOPE_REF for most qualified-ids
3052 : so that we can check access at instantiation time. But if
3053 : we're looking at a member of the current instantiation, we
3054 : know we have access and building up the SCOPE_REF confuses
3055 : non-type template argument handling. */
3056 72784384 : if (processing_template_decl
3057 72784384 : && (!currently_open_class (qualifying_class)
3058 9933 : || TREE_CODE (expr) == IDENTIFIER_NODE
3059 9933 : || TREE_CODE (expr) == TEMPLATE_ID_EXPR
3060 82 : || TREE_CODE (expr) == BIT_NOT_EXPR))
3061 10660321 : expr = build_qualified_name (TREE_TYPE (expr),
3062 : qualifying_class, expr,
3063 : template_p);
3064 62124063 : else if (tree wrap = maybe_get_tls_wrapper_call (expr))
3065 9 : expr = wrap;
3066 :
3067 72784384 : 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 5167249 : begin_stmt_expr (void)
3078 : {
3079 5167249 : 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 29688 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
3089 : {
3090 29688 : 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 29685 : if (expr)
3101 : {
3102 29670 : tree type = TREE_TYPE (expr);
3103 :
3104 29670 : 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 29655 : 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 29486 : 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 29455 : expr = force_rvalue (expr, tf_warning_or_error);
3131 29455 : if (error_operand_p (expr))
3132 0 : return error_mark_node;
3133 :
3134 : /* Update for array-to-pointer decay. */
3135 29455 : type = TREE_TYPE (expr);
3136 :
3137 : /* This TARGET_EXPR will initialize the outer one added by
3138 : finish_stmt_expr. */
3139 29455 : 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 29455 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
3145 29455 : expr = maybe_cleanup_point_expr (expr);
3146 29455 : add_stmt (expr);
3147 : }
3148 :
3149 : /* The type of the statement-expression is the type of the last
3150 : expression. */
3151 29655 : 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 5167249 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
3163 : {
3164 5167249 : tree type;
3165 5167249 : tree result;
3166 :
3167 5167249 : if (error_operand_p (stmt_expr))
3168 : {
3169 18 : pop_stmt_list (stmt_expr);
3170 18 : return error_mark_node;
3171 : }
3172 :
3173 5167231 : gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
3174 :
3175 5167231 : type = TREE_TYPE (stmt_expr);
3176 5167231 : result = pop_stmt_list (stmt_expr);
3177 5167231 : TREE_TYPE (result) = type;
3178 :
3179 5167231 : if (processing_template_decl)
3180 : {
3181 36605 : result = build_min (STMT_EXPR, type, result);
3182 36605 : TREE_SIDE_EFFECTS (result) = 1;
3183 36605 : STMT_EXPR_NO_SCOPE (result) = has_no_scope;
3184 : }
3185 5130626 : 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 60001491 : empty_expr_stmt_p (tree expr_stmt)
3221 : {
3222 60001495 : tree body = NULL_TREE;
3223 :
3224 60001495 : if (expr_stmt == void_node)
3225 : return true;
3226 :
3227 60001492 : if (expr_stmt)
3228 : {
3229 60001492 : if (TREE_CODE (expr_stmt) == EXPR_STMT)
3230 4 : body = EXPR_STMT_EXPR (expr_stmt);
3231 60001488 : else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
3232 : body = expr_stmt;
3233 : }
3234 :
3235 4 : if (body)
3236 : {
3237 59097615 : if (TREE_CODE (body) == STATEMENT_LIST)
3238 59097611 : 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 18299406 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
3251 : tsubst_flags_t complain)
3252 : {
3253 18299406 : tree identifier = NULL_TREE;
3254 18299406 : tree functions = NULL_TREE;
3255 18299406 : tree tmpl_args = NULL_TREE;
3256 18299406 : bool template_id = false;
3257 18299406 : location_t loc = fn_expr.get_location ();
3258 18299406 : tree fn = fn_expr.get_value ();
3259 :
3260 18299406 : STRIP_ANY_LOCATION_WRAPPER (fn);
3261 :
3262 18299406 : if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
3263 : {
3264 : /* Use a separate flag to handle null args. */
3265 3600124 : template_id = true;
3266 3600124 : tmpl_args = TREE_OPERAND (fn, 1);
3267 3600124 : fn = TREE_OPERAND (fn, 0);
3268 : }
3269 :
3270 : /* Find the name of the overloaded function. */
3271 18299406 : if (identifier_p (fn))
3272 : identifier = fn;
3273 : else
3274 : {
3275 25960303 : functions = fn;
3276 18114394 : 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 18299406 : if (!any_type_dependent_arguments_p (args)
3284 18299406 : && !any_dependent_template_arguments_p (tmpl_args))
3285 : {
3286 17398384 : fn = lookup_arg_dependent (identifier, functions, args);
3287 17398384 : if (!fn)
3288 : {
3289 : /* The unqualified name could not be resolved. */
3290 57141 : if (complain & tf_error)
3291 390 : fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
3292 : else
3293 : fn = identifier;
3294 : }
3295 : }
3296 :
3297 18299406 : if (fn && template_id && fn != error_mark_node)
3298 3600111 : fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
3299 :
3300 18299406 : 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 346454715 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
3316 : bool koenig_p, tsubst_flags_t complain)
3317 : {
3318 346454715 : tree result;
3319 346454715 : tree orig_fn;
3320 346454715 : vec<tree, va_gc> *orig_args = *args;
3321 346454715 : tsubst_flags_t orig_complain = complain;
3322 :
3323 346454715 : if (fn == error_mark_node)
3324 : return error_mark_node;
3325 :
3326 346453700 : complain &= ~tf_any_viable;
3327 346453700 : 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 346453700 : fn = maybe_undo_parenthesized_ref (fn);
3332 :
3333 346453700 : STRIP_ANY_LOCATION_WRAPPER (fn);
3334 :
3335 346453700 : orig_fn = fn;
3336 :
3337 346453700 : 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 346453694 : 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 228612522 : if (is_overloaded_fn (fn))
3349 : {
3350 140233000 : tree ifn = get_first_fn (fn);
3351 140233000 : if (TREE_CODE (ifn) == FUNCTION_DECL
3352 140233000 : && dependent_local_decl_p (ifn))
3353 39199 : 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 228612522 : if (type_dependent_expression_p (fn)
3360 228612522 : || any_type_dependent_arguments_p (*args))
3361 : {
3362 207113779 : if (koenig_p
3363 10267032 : && TREE_CODE (orig_fn) == FUNCTION_DECL
3364 210291393 : && !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 835972 : orig_fn = ovl_make (orig_fn, NULL_TREE);
3370 207113779 : result = build_min_nt_call_vec (orig_fn, *args);
3371 281410506 : SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
3372 207113779 : 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 207113779 : suppress_warning (result, OPT_Wpessimizing_move);
3377 :
3378 207113779 : if (cfun && cp_function_chain && !cp_unevaluated_operand)
3379 : {
3380 180727640 : bool abnormal = true;
3381 180943762 : for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
3382 : {
3383 100146976 : tree fndecl = STRIP_TEMPLATE (*iter);
3384 100146976 : if (TREE_CODE (fndecl) != FUNCTION_DECL
3385 100146898 : || !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 180727640 : if (abnormal)
3397 80796786 : current_function_returns_abnormally = 1;
3398 : }
3399 207113779 : if (TREE_CODE (fn) == COMPONENT_REF)
3400 96183102 : maybe_generic_this_capture (TREE_OPERAND (fn, 0),
3401 96183102 : TREE_OPERAND (fn, 1));
3402 207113779 : return result;
3403 : }
3404 21498743 : orig_args = make_tree_vector_copy (*args);
3405 : }
3406 :
3407 139339915 : if (TREE_CODE (fn) == COMPONENT_REF)
3408 : {
3409 28476785 : tree member = TREE_OPERAND (fn, 1);
3410 28476785 : if (BASELINK_P (member))
3411 : {
3412 28296043 : tree object = TREE_OPERAND (fn, 0);
3413 56229121 : 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 28296043 : complain);
3420 : }
3421 : }
3422 :
3423 : /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
3424 111043872 : if (TREE_CODE (fn) == ADDR_EXPR
3425 111043872 : && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
3426 9 : fn = TREE_OPERAND (fn, 0);
3427 :
3428 111043872 : if (is_overloaded_fn (fn))
3429 102735176 : fn = baselink_for_fns (fn);
3430 :
3431 111043872 : result = NULL_TREE;
3432 111043872 : if (BASELINK_P (fn))
3433 : {
3434 13430293 : 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 13430293 : 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 13430254 : object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
3464 : NULL);
3465 :
3466 15309171 : 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 97613579 : else if (is_overloaded_fn (fn))
3474 : {
3475 : /* If the function is an overloaded builtin, resolve it. */
3476 89304883 : if (TREE_CODE (fn) == FUNCTION_DECL
3477 89304883 : && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
3478 18080119 : || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
3479 8955066 : result = resolve_overloaded_builtin (input_location, fn, *args,
3480 : complain & tf_error);
3481 :
3482 8955066 : if (!result)
3483 : {
3484 88970033 : tree alloc_size_attr = NULL_TREE;
3485 88970033 : if (warn_calloc_transposed_args
3486 685992 : && TREE_CODE (fn) == FUNCTION_DECL
3487 88970033 : && (alloc_size_attr
3488 430704 : = lookup_attribute ("alloc_size",
3489 430704 : TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
3490 3353 : if (TREE_VALUE (alloc_size_attr) == NULL_TREE
3491 3353 : || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
3492 : alloc_size_attr = NULL_TREE;
3493 87283663 : if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
3494 1686430 : && (complain & tf_warning)
3495 1492702 : && !vec_safe_is_empty (*args)
3496 90118193 : && !processing_template_decl)
3497 : {
3498 : location_t sizeof_arg_loc[6];
3499 : tree sizeof_arg[6];
3500 : unsigned int i;
3501 8239404 : for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
3502 : {
3503 3089979 : tree t;
3504 :
3505 3089979 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
3506 3089979 : sizeof_arg[i] = NULL_TREE;
3507 3089979 : if (i >= (*args)->length ())
3508 649503 : continue;
3509 2440476 : t = (**args)[i];
3510 2440476 : if (TREE_CODE (t) != SIZEOF_EXPR)
3511 2433827 : continue;
3512 6649 : if (SIZEOF_EXPR_TYPE_P (t))
3513 2653 : sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
3514 : else
3515 3996 : sizeof_arg[i] = TREE_OPERAND (t, 0);
3516 6649 : sizeof_arg_loc[i] = EXPR_LOCATION (t);
3517 : }
3518 1029933 : if (warn_sizeof_pointer_memaccess)
3519 : {
3520 1029873 : auto same_p = same_type_ignoring_top_level_qualifiers_p;
3521 1029873 : sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
3522 : sizeof_arg, same_p);
3523 : }
3524 1029933 : if (alloc_size_attr)
3525 60 : warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
3526 : alloc_size_attr);
3527 : }
3528 :
3529 88970033 : if ((complain & tf_warning)
3530 53219426 : && TREE_CODE (fn) == FUNCTION_DECL
3531 25332728 : && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
3532 133900 : && vec_safe_length (*args) == 3
3533 89103933 : && !any_type_dependent_arguments_p (*args))
3534 : {
3535 133900 : tree arg0 = (*orig_args)[0];
3536 133900 : tree arg1 = (*orig_args)[1];
3537 133900 : tree arg2 = (*orig_args)[2];
3538 133900 : int literal_mask = ((literal_integer_zerop (arg1) << 1)
3539 133900 : | (literal_integer_zerop (arg2) << 2));
3540 133900 : warn_for_memset (input_location, arg0, arg2, literal_mask);
3541 : }
3542 :
3543 : /* A call to a namespace-scope function. */
3544 88970033 : result = build_new_function_call (fn, args, orig_complain);
3545 : }
3546 : }
3547 8308696 : else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
3548 : {
3549 151296 : 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 151296 : tree ob = TREE_OPERAND (fn, 0);
3556 151296 : if (obvalue_p (ob))
3557 151278 : 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 8157400 : 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 2177985 : result = build_op_call (fn, args, complain);
3566 :
3567 104716089 : if (!result)
3568 : /* A call where the function is unknown. */
3569 5979415 : result = cp_build_function_call_vec (fn, args, complain);
3570 :
3571 111030354 : if (processing_template_decl && result != error_mark_node)
3572 : {
3573 15982826 : if (INDIRECT_REF_P (result))
3574 1141008 : 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 15982826 : if (TREE_CODE (result) == CALL_EXPR
3579 15973407 : && really_overloaded_fn (orig_fn))
3580 : {
3581 6007558 : tree sel_fn = CALL_EXPR_FN (result);
3582 6007558 : if (TREE_CODE (sel_fn) == COMPONENT_REF)
3583 : {
3584 : /* The non-dependent result of build_new_method_call. */
3585 248867 : sel_fn = TREE_OPERAND (sel_fn, 1);
3586 248867 : gcc_assert (BASELINK_P (sel_fn));
3587 : }
3588 5758691 : 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 5758691 : sel_fn = TREE_OPERAND (sel_fn, 0);
3592 : orig_fn = sel_fn;
3593 : }
3594 :
3595 15982826 : tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
3596 15982826 : SET_EXPR_LOCATION (r, input_location);
3597 15982826 : KOENIG_LOOKUP_P (r) = koenig_p;
3598 15982826 : TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
3599 15982826 : release_tree_vector (orig_args);
3600 15982826 : 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 2577864 : 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 2577864 : location_t combined_loc = make_location (input_location,
3620 : expr.get_start (),
3621 : get_finish (input_location));
3622 2577864 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3623 2577864 : NULL_TREE, tf_warning_or_error);
3624 : /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3625 2577864 : result.set_location (combined_loc);
3626 2577864 : return result;
3627 : }
3628 :
3629 : /* Finish a use of `this'. Returns an expression for `this'. */
3630 :
3631 : tree
3632 35325680 : finish_this_expr (void)
3633 : {
3634 35325680 : tree result = NULL_TREE;
3635 :
3636 70651246 : if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
3637 35048569 : result = current_class_ptr;
3638 554206 : else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
3639 277037 : result = (lambda_expr_this_capture
3640 277037 : (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
3641 : else
3642 74 : gcc_checking_assert (!current_class_ptr);
3643 :
3644 35325606 : if (result)
3645 : /* The keyword 'this' is a prvalue expression. */
3646 35325603 : return rvalue (result);
3647 :
3648 77 : tree fn = current_nonlambda_function ();
3649 77 : if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
3650 : {
3651 4 : auto_diagnostic_group d;
3652 4 : error ("%<this%> is unavailable for explicit object member "
3653 : "functions");
3654 4 : tree xobj_parm = DECL_ARGUMENTS (fn);
3655 4 : gcc_assert (xobj_parm);
3656 4 : tree parm_name = DECL_NAME (xobj_parm);
3657 :
3658 4 : static tree remembered_fn = NULL_TREE;
3659 : /* Only output this diagnostic once per function. */
3660 4 : if (remembered_fn == fn)
3661 : /* Early escape. */;
3662 4 : else if (parm_name)
3663 4 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3664 : "use explicit object parameter %qs instead",
3665 2 : IDENTIFIER_POINTER (parm_name));
3666 : else
3667 2 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3668 : "name the explicit object parameter");
3669 :
3670 4 : remembered_fn = fn;
3671 4 : }
3672 73 : else if (fn && DECL_STATIC_FUNCTION_P (fn))
3673 3 : error ("%<this%> is unavailable for static member functions");
3674 70 : else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
3675 0 : error ("invalid use of %<this%> in a constructor %<pre%> condition");
3676 70 : else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
3677 0 : error ("invalid use of %<this%> in a destructor %<post%> condition");
3678 70 : else if (fn)
3679 22 : error ("invalid use of %<this%> in non-member function");
3680 : else
3681 48 : error ("invalid use of %<this%> at top level");
3682 77 : return error_mark_node;
3683 : }
3684 :
3685 : /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3686 : expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3687 : the TYPE for the type given. If SCOPE is non-NULL, the expression
3688 : was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3689 :
3690 : tree
3691 151347 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
3692 : location_t loc, tsubst_flags_t complain)
3693 : {
3694 151347 : if (object == error_mark_node || destructor == error_mark_node)
3695 : return error_mark_node;
3696 :
3697 151338 : gcc_assert (TYPE_P (destructor));
3698 :
3699 151338 : if (!processing_template_decl)
3700 : {
3701 151317 : 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 151317 : if (is_auto (destructor))
3708 3 : destructor = TREE_TYPE (object);
3709 151317 : 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 151314 : 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 151323 : tree type = (type_dependent_expression_p (object)
3742 151323 : ? NULL_TREE : void_type_node);
3743 :
3744 151323 : return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
3745 151323 : scope, destructor);
3746 : }
3747 :
3748 : /* Finish an expression of the form CODE EXPR. */
3749 :
3750 : cp_expr
3751 37315742 : 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 37315742 : location_t combined_loc = make_location (op_loc,
3760 : op_loc, expr.get_finish ());
3761 37315742 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3762 37315742 : NULL_TREE, complain);
3763 : /* TODO: build_x_unary_op doesn't always honor the location. */
3764 37315742 : result.set_location (combined_loc);
3765 :
3766 37315742 : if (result == error_mark_node)
3767 : return result;
3768 :
3769 37315278 : 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 37315278 : if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
3775 : return result;
3776 :
3777 20064876 : tree result_ovl = result;
3778 20064876 : tree expr_ovl = expr;
3779 :
3780 20064876 : if (!processing_template_decl)
3781 1770863 : expr_ovl = cp_fully_fold (expr_ovl);
3782 :
3783 20064876 : if (!CONSTANT_CLASS_P (expr_ovl)
3784 20064876 : || TREE_OVERFLOW_P (expr_ovl))
3785 : return result;
3786 :
3787 244867 : if (!processing_template_decl)
3788 235746 : result_ovl = cp_fully_fold (result_ovl);
3789 :
3790 244867 : 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 9380855 : finish_compound_literal (tree type, tree compound_literal,
3818 : tsubst_flags_t complain,
3819 : fcl_t fcl_context)
3820 : {
3821 9380855 : if (type == error_mark_node)
3822 : return error_mark_node;
3823 :
3824 9380806 : 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 9380794 : 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 9380770 : if (template_placeholder_p (type))
3861 : {
3862 176751 : type = do_auto_deduction (type, compound_literal, type, complain,
3863 : adc_variable_type);
3864 176751 : if (type == error_mark_node)
3865 : return error_mark_node;
3866 : }
3867 : /* C++23 auto{x}. */
3868 9204019 : else if (is_auto (type)
3869 109 : && !AUTO_IS_DECLTYPE (type)
3870 9204126 : && CONSTRUCTOR_NELTS (compound_literal) == 1)
3871 : {
3872 101 : if (is_constrained_auto (type))
3873 : {
3874 2 : if (complain & tf_error)
3875 2 : error ("%<auto{x}%> cannot be constrained");
3876 2 : return error_mark_node;
3877 : }
3878 99 : else if (cxx_dialect < cxx23)
3879 : {
3880 1 : if ((complain & tf_warning_or_error) == 0)
3881 0 : return error_mark_node;
3882 1 : pedwarn (input_location, OPT_Wc__23_extensions,
3883 : "%<auto{x}%> only available with "
3884 : "%<-std=c++23%> or %<-std=gnu++23%>");
3885 : }
3886 99 : type = do_auto_deduction (type, compound_literal, type, complain,
3887 : adc_variable_type);
3888 99 : if (type == error_mark_node)
3889 : return error_mark_node;
3890 : }
3891 :
3892 : /* Used to hold a copy of the compound literal in a template. */
3893 9380651 : tree orig_cl = NULL_TREE;
3894 :
3895 9380651 : if (processing_template_decl)
3896 : {
3897 4911966 : const bool dependent_p
3898 4911966 : = (instantiation_dependent_expression_p (compound_literal)
3899 4911966 : || dependent_type_p (type));
3900 1628464 : 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 1628464 : orig_cl = unshare_constructor (compound_literal);
3906 4911966 : TREE_TYPE (orig_cl) = type;
3907 : /* Mark the expression as a compound literal. */
3908 4911966 : TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
3909 : /* And as instantiation-dependent. */
3910 4911966 : CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
3911 4911966 : 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 4911966 : if (dependent_p)
3915 : return orig_cl;
3916 : /* Otherwise, do go on to e.g. check narrowing. */
3917 : }
3918 :
3919 6097149 : type = complete_type (type);
3920 :
3921 6097149 : 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 1037588 : CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
3928 1037588 : compound_literal = build_tree_list (NULL_TREE, compound_literal);
3929 1037588 : return build_functional_cast (input_location, type,
3930 1037588 : compound_literal, complain);
3931 : }
3932 :
3933 5059561 : if (TREE_CODE (type) == ARRAY_TYPE
3934 5059561 : && check_array_initializer (NULL_TREE, type, compound_literal))
3935 9 : return error_mark_node;
3936 5059552 : compound_literal = reshape_init (type, compound_literal, complain);
3937 4873677 : if (SCALAR_TYPE_P (type)
3938 684240 : && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
3939 5269258 : && !check_narrowing (type, compound_literal, complain))
3940 102 : return error_mark_node;
3941 5059450 : if (TREE_CODE (type) == ARRAY_TYPE
3942 5059450 : && TYPE_DOMAIN (type) == NULL_TREE)
3943 : {
3944 1194 : cp_complete_array_type_or_error (&type, compound_literal,
3945 : false, complain);
3946 1194 : if (type == error_mark_node)
3947 : return error_mark_node;
3948 : }
3949 5059447 : compound_literal = digest_init_flags (type, compound_literal,
3950 : LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
3951 : complain);
3952 5059447 : 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 5058849 : if (orig_cl)
3957 : return orig_cl;
3958 :
3959 3521320 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3960 : {
3961 2890383 : TREE_HAS_CONSTRUCTOR (compound_literal) = true;
3962 2890383 : if (fcl_context == fcl_c99)
3963 38167 : 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 4594283 : if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
3970 2454083 : && fcl_context == fcl_c99
3971 80 : && TREE_CODE (type) == ARRAY_TYPE
3972 28 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
3973 3521348 : && initializer_constant_valid_p (compound_literal, type))
3974 : {
3975 28 : tree decl = create_temporary_var (type);
3976 28 : DECL_CONTEXT (decl) = NULL_TREE;
3977 28 : DECL_INITIAL (decl) = compound_literal;
3978 28 : TREE_STATIC (decl) = 1;
3979 28 : 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 28 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
3991 28 : decl = pushdecl_top_level (decl);
3992 28 : DECL_NAME (decl) = make_anon_name ();
3993 28 : SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
3994 : /* Make sure the destructor is callable. */
3995 28 : tree clean = cxx_maybe_build_cleanup (decl, complain);
3996 28 : if (clean == error_mark_node)
3997 : return error_mark_node;
3998 28 : return decl;
3999 : }
4000 :
4001 : /* Represent other compound literals with TARGET_EXPR so we produce
4002 : a prvalue, and can elide copies. */
4003 3521292 : if (!VECTOR_TYPE_P (type)
4004 3482626 : && (TREE_CODE (compound_literal) == CONSTRUCTOR
4005 630931 : || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
4006 : {
4007 : /* The CONSTRUCTOR is now an initializer, not a compound literal. */
4008 2851695 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
4009 2851695 : TREE_HAS_CONSTRUCTOR (compound_literal) = false;
4010 2851695 : 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 669597 : 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 232393 : finish_fname (tree id)
4024 : {
4025 232393 : 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 232393 : if (current_function_decl
4031 232393 : && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
4032 4 : pedwarn (input_location, 0, "%qD is not defined outside of function scope",
4033 : decl);
4034 232393 : if (processing_template_decl && current_function_decl
4035 161268 : && decl != error_mark_node)
4036 161268 : decl = DECL_NAME (decl);
4037 232393 : return decl;
4038 : }
4039 :
4040 : /* Finish a translation unit. */
4041 :
4042 : void
4043 96815 : finish_translation_unit (void)
4044 : {
4045 : /* In case there were missing closebraces,
4046 : get us back to the global binding level. */
4047 96815 : pop_everything ();
4048 193630 : while (current_namespace != global_namespace)
4049 0 : pop_namespace ();
4050 :
4051 : /* Do file scope __FUNCTION__ et al. */
4052 96815 : finish_fname_decls ();
4053 :
4054 96815 : 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 96815 : 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 96815 : 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 96815 : }
4080 :
4081 : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
4082 : Returns the parameter. */
4083 :
4084 : tree
4085 156036686 : finish_template_type_parm (tree aggr, tree identifier)
4086 : {
4087 156036686 : 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 156036686 : 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 389577 : finish_template_template_parm (tree aggr, tree identifier)
4101 : {
4102 389577 : tree decl = build_decl (input_location,
4103 : TYPE_DECL, identifier, NULL_TREE);
4104 :
4105 389577 : tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
4106 389577 : DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
4107 389577 : DECL_TEMPLATE_RESULT (tmpl) = decl;
4108 389577 : DECL_ARTIFICIAL (decl) = 1;
4109 :
4110 : /* Associate the constraints with the underlying declaration,
4111 : not the template. */
4112 389577 : tree constr = current_template_constraints ();
4113 389577 : set_constraints (decl, constr);
4114 :
4115 389577 : end_template_decl ();
4116 :
4117 389577 : gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
4118 :
4119 389577 : check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
4120 : /*is_primary=*/true, /*is_partial=*/false,
4121 : /*is_friend=*/0);
4122 :
4123 389577 : 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 941 : check_template_template_default_arg (tree argument)
4132 : {
4133 941 : 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 29773503 : begin_class_definition (tree t)
4157 : {
4158 29773503 : if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
4159 33 : return error_mark_node;
4160 :
4161 29773601 : 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 29773461 : if (TREE_CODE (t) == RECORD_TYPE
4170 29269608 : && !processing_template_decl)
4171 : {
4172 10455357 : tree ns = TYPE_CONTEXT (t);
4173 10455355 : if (ns && TREE_CODE (ns) == NAMESPACE_DECL
4174 8659001 : && DECL_CONTEXT (ns) == std_node
4175 2106674 : && DECL_NAME (ns)
4176 12562011 : && 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 19318104 : 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 29773461 : 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 29773461 : 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 29773461 : maybe_process_partial_specialization (t);
4211 29773461 : pushclass (t);
4212 29773461 : TYPE_BEING_DEFINED (t) = 1;
4213 29773461 : class_binding_level->defining_class_p = 1;
4214 :
4215 29773461 : 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 61726391 : if (! TYPE_UNNAMED_P (t))
4229 : {
4230 29047582 : struct c_fileinfo *finfo = \
4231 29047582 : get_fileinfo (LOCATION_FILE (input_location));
4232 29047582 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
4233 29047582 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X
4234 : (t, finfo->interface_unknown);
4235 : }
4236 29773461 : reset_specialization ();
4237 :
4238 : /* Make a declaration for this class in its own scope. */
4239 29773461 : build_self_reference ();
4240 :
4241 29773461 : return t;
4242 : }
4243 :
4244 : /* Finish the member declaration given by DECL. */
4245 :
4246 : void
4247 403867489 : finish_member_declaration (tree decl)
4248 : {
4249 403867489 : if (decl == error_mark_node || decl == NULL_TREE)
4250 : return;
4251 :
4252 403866488 : 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 403866488 : gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
4259 :
4260 : /* Don't add decls after definition. */
4261 403866509 : 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 403866488 : TREE_PRIVATE (decl)
4268 403866488 : = (current_access_specifier == access_private_node);
4269 403866488 : TREE_PROTECTED (decl)
4270 403866488 : = (current_access_specifier == access_protected_node);
4271 403866488 : if (TREE_CODE (decl) == TEMPLATE_DECL)
4272 : {
4273 45723083 : TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
4274 45723083 : 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 403866488 : if (TREE_CODE (decl) != CONST_DECL)
4280 401654327 : DECL_CONTEXT (decl) = current_class_type;
4281 :
4282 : /* Remember the single FIELD_DECL an anonymous aggregate type is used for. */
4283 403866488 : if (TREE_CODE (decl) == FIELD_DECL
4284 403866488 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
4285 : {
4286 256040 : gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
4287 256040 : ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))) = decl;
4288 : }
4289 :
4290 403866488 : 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 3116623 : DECL_IGNORED_P (decl) = 1;
4294 :
4295 : /* Check for bare parameter packs in the non-static data member
4296 : declaration. */
4297 403866488 : if (TREE_CODE (decl) == FIELD_DECL)
4298 : {
4299 29034608 : if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
4300 9 : TREE_TYPE (decl) = error_mark_node;
4301 29034608 : 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 403866488 : if (DECL_LANG_SPECIFIC (decl))
4310 369399852 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
4311 :
4312 403866488 : bool add = false;
4313 :
4314 : /* Functions and non-functions are added differently. */
4315 403866488 : if (DECL_DECLARES_FUNCTION_P (decl))
4316 208797399 : 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 195069089 : else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
4320 191719787 : || maybe_push_used_methods (decl)
4321 385025558 : || pushdecl_class_level (decl))
4322 : add = true;
4323 :
4324 208797399 : 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 403857028 : if (TREE_CODE (decl) == TYPE_DECL)
4337 139282359 : TYPE_FIELDS (current_class_type)
4338 278564718 : = chainon (TYPE_FIELDS (current_class_type), decl);
4339 : else
4340 : {
4341 264574669 : DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
4342 264574669 : TYPE_FIELDS (current_class_type) = decl;
4343 : }
4344 :
4345 403857028 : 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 89177952 : finish_template_decl (tree parms)
4355 : {
4356 89177952 : if (parms)
4357 89177943 : end_template_decl ();
4358 : else
4359 9 : end_specialization ();
4360 89177952 : }
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 17610767 : 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 17610767 : tree parms = current_template_parms;
4400 17610767 : int depth = template_class_depth (type);
4401 39244720 : for (int n = current_template_depth; n > depth && parms; --n)
4402 4023186 : parms = TREE_CHAIN (parms);
4403 17610767 : if (!parms)
4404 : return type;
4405 17610757 : tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
4406 17610757 : tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
4407 :
4408 : // Search for a specialization whose type and constraints match.
4409 17610757 : tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
4410 17610757 : tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
4411 34240074 : while (specs)
4412 : {
4413 17040999 : 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 17040999 : if (same_type_p (type, TREE_TYPE (specs))
4418 17040999 : && equivalent_constraints (cur_constr, spec_constr))
4419 411682 : return TREE_TYPE (specs);
4420 16629317 : 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 181943840 : finish_template_type (tree name, tree args, int entering_scope)
4435 : {
4436 181943840 : tree type;
4437 :
4438 181943840 : type = lookup_template_class (name, args,
4439 : NULL_TREE, NULL_TREE,
4440 : tf_warning_or_error | tf_user);
4441 181943837 : if (entering_scope)
4442 18625631 : 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 181943837 : if (flag_concepts
4447 179248179 : && entering_scope
4448 18262999 : && CLASS_TYPE_P (type)
4449 18102976 : && CLASSTYPE_TEMPLATE_INFO (type)
4450 18102967 : && dependent_type_p (type)
4451 199554604 : && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
4452 17610767 : type = fixup_template_type (type);
4453 :
4454 181943837 : if (type == error_mark_node)
4455 : return type;
4456 181941573 : else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
4457 144051472 : return TYPE_STUB_DECL (type);
4458 : else
4459 37890101 : 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 11077731 : finish_base_specifier (tree base, tree access, bool virtual_p,
4473 : tree annotations)
4474 : {
4475 11077731 : tree result;
4476 :
4477 11077731 : if (base == error_mark_node)
4478 : {
4479 0 : error ("invalid base-class specification");
4480 0 : result = NULL_TREE;
4481 : }
4482 11077731 : 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 11077728 : 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 11077728 : if (annotations)
4496 9 : access = build_tree_list (access, nreverse (annotations));
4497 11077728 : result = build_tree_list (access, base);
4498 11077728 : if (virtual_p)
4499 25487 : TREE_TYPE (result) = integer_type_node;
4500 : }
4501 :
4502 11077731 : 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 166167989 : baselink_for_fns (tree fns)
4512 : {
4513 166167989 : tree scope;
4514 166167989 : tree cl;
4515 :
4516 166167989 : if (BASELINK_P (fns)
4517 166167989 : || error_operand_p (fns))
4518 : return fns;
4519 :
4520 152853598 : scope = ovl_scope (fns);
4521 152853598 : if (!CLASS_TYPE_P (scope))
4522 : return fns;
4523 :
4524 8388472 : cl = currently_open_derived_class (scope);
4525 8388472 : if (!cl)
4526 6108599 : cl = scope;
4527 8388472 : tree access_path = TYPE_BINFO (cl);
4528 8388472 : tree conv_path = (cl == scope ? access_path
4529 678957 : : lookup_base (cl, scope, ba_any, NULL, tf_none));
4530 8388472 : 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 1910553871 : parsing_lambda_declarator ()
4537 : {
4538 1910553871 : cp_binding_level *b = current_binding_level;
4539 1912410382 : while (b->kind == sk_template_parms || b->kind == sk_function_parms)
4540 1856511 : b = b->level_chain;
4541 1910553871 : 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 2556777297 : outer_var_p (tree decl)
4549 : {
4550 : /* These should have been stripped or otherwise handled by the caller. */
4551 2556777297 : gcc_checking_assert (!REFERENCE_REF_P (decl));
4552 :
4553 1687249178 : return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
4554 2348740122 : && DECL_FUNCTION_SCOPE_P (decl)
4555 : /* Don't get confused by temporaries. */
4556 1941690257 : && DECL_NAME (decl)
4557 4475479046 : && (DECL_CONTEXT (decl) != current_function_decl
4558 1908624155 : || 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 1908623212 : || parsing_lambda_declarator ()));
4567 : }
4568 :
4569 : /* As above, but also checks that DECL is automatic. */
4570 :
4571 : bool
4572 2556777297 : outer_automatic_var_p (tree decl)
4573 : {
4574 2556777297 : return (outer_var_p (decl)
4575 2556777297 : && !TREE_STATIC (decl));
4576 : }
4577 :
4578 : /* Note whether capture proxy D is only used in a contract condition. */
4579 :
4580 : static void
4581 102121 : set_contract_capture_flag (tree d, bool val)
4582 : {
4583 102121 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (d));
4584 102121 : tree proxy = DECL_VALUE_EXPR (d);
4585 102121 : gcc_checking_assert (TREE_CODE (proxy) == COMPONENT_REF
4586 : && TREE_CODE (TREE_OPERAND (proxy, 1)) == FIELD_DECL);
4587 102121 : DECL_CONTRACT_CAPTURE_P (TREE_OPERAND (proxy, 1)) = val;
4588 102121 : }
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 5064036 : process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
4599 : {
4600 5064036 : if (cp_unevaluated_operand)
4601 : {
4602 3133206 : tree type = TREE_TYPE (decl);
4603 3133206 : if (!dependent_type_p (type)
4604 3133206 : && variably_modified_type_p (type, NULL_TREE))
4605 : /* VLAs are used even in unevaluated context. */;
4606 : else
4607 : /* It's not a use (3.2) if we're in an unevaluated context. */
4608 3133200 : return decl;
4609 : }
4610 1930836 : if (decl == error_mark_node)
4611 : return decl;
4612 :
4613 1930830 : tree context = DECL_CONTEXT (decl);
4614 1930830 : tree containing_function = current_function_decl;
4615 1930830 : tree lambda_stack = NULL_TREE;
4616 1930830 : tree lambda_expr = NULL_TREE;
4617 1930830 : tree initializer = convert_from_reference (decl);
4618 1930830 : tree var = strip_normal_capture_proxy (decl);
4619 :
4620 : /* Mark it as used now even if the use is ill-formed. */
4621 1930830 : if (!mark_used (decl, complain))
4622 3 : return error_mark_node;
4623 :
4624 1930827 : if (parsing_nsdmi () || parsing_lambda_declarator ())
4625 : containing_function = NULL_TREE;
4626 :
4627 3860957 : if (containing_function && LAMBDA_FUNCTION_P (containing_function))
4628 : {
4629 : /* Check whether we've already built a proxy. */
4630 1930391 : tree d = retrieve_local_specialization (var);
4631 :
4632 1930391 : if (d && d != decl && is_capture_proxy (d))
4633 : {
4634 989808 : if (flag_contracts && !processing_contract_condition)
4635 : /* We might have created a capture for a contract_assert ref. to
4636 : some var, if that is now captured 'normally' then this is OK.
4637 : Otherwise we leave the capture marked as incorrect. */
4638 102118 : set_contract_capture_flag (d, false);
4639 989808 : if (DECL_CONTEXT (d) == containing_function)
4640 : /* We already have an inner proxy. */
4641 : return d;
4642 : else
4643 : /* We need to capture an outer proxy. */
4644 2428 : return process_outer_var_ref (d, complain, odr_use);
4645 : }
4646 : }
4647 :
4648 : /* If we are in a lambda function, we can move out until we hit
4649 : 1. the context,
4650 : 2. a non-lambda function, or
4651 : 3. a non-default capturing lambda function. */
4652 1884586 : while (context != containing_function
4653 : /* containing_function can be null with invalid generic lambdas. */
4654 1884586 : && containing_function
4655 2828828 : && LAMBDA_FUNCTION_P (containing_function))
4656 : {
4657 944242 : tree closure = DECL_CONTEXT (containing_function);
4658 944242 : lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
4659 :
4660 944242 : if (TYPE_CLASS_SCOPE_P (closure))
4661 : /* A lambda in an NSDMI (c++/64496). */
4662 : break;
4663 :
4664 944239 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4665 : break;
4666 :
4667 943567 : lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
4668 :
4669 943567 : containing_function = decl_function_context (containing_function);
4670 : }
4671 :
4672 : /* In a lambda within a template, wait until instantiation time to implicitly
4673 : capture a parameter pack. We want to wait because we don't know if we're
4674 : capturing the whole pack or a single element, and it's OK to wait because
4675 : find_parameter_packs_r walks into the lambda body. */
4676 941019 : if (context == containing_function
4677 941019 : && DECL_PACK_P (decl))
4678 : return decl;
4679 :
4680 900163 : if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
4681 : {
4682 6 : if (complain & tf_error)
4683 6 : error ("cannot capture member %qD of anonymous union", decl);
4684 6 : return error_mark_node;
4685 : }
4686 : /* Do lambda capture when processing the id-expression, not when
4687 : odr-using a variable, but uses in a contract must not cause a capture. */
4688 900157 : if (!odr_use && context == containing_function)
4689 : {
4690 899046 : decl = add_default_capture (lambda_stack,
4691 899046 : /*id=*/DECL_NAME (decl), initializer);
4692 899046 : if (flag_contracts && processing_contract_condition)
4693 3 : set_contract_capture_flag (decl, true);
4694 : }
4695 : /* Only an odr-use of an outer automatic variable causes an
4696 : error, and a constant variable can decay to a prvalue
4697 : constant without odr-use. So don't complain yet. */
4698 1111 : else if (!odr_use && decl_constant_var_p (var))
4699 : return var;
4700 308 : else if (lambda_expr)
4701 : {
4702 45 : if (complain & tf_error)
4703 : {
4704 43 : auto_diagnostic_group d;
4705 43 : error ("%qD is not captured", decl);
4706 43 : tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
4707 43 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4708 40 : inform (location_of (closure),
4709 : "the lambda has no capture-default");
4710 3 : else if (TYPE_CLASS_SCOPE_P (closure))
4711 3 : inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
4712 : "capture variables from the enclosing context",
4713 3 : TYPE_CONTEXT (closure));
4714 43 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4715 43 : }
4716 45 : return error_mark_node;
4717 : }
4718 263 : else if (processing_contract_condition && (TREE_CODE (decl) == PARM_DECL))
4719 : /* Use of a parameter in a contract condition is fine. */
4720 : return decl;
4721 : else
4722 : {
4723 46 : if (complain & tf_error)
4724 : {
4725 39 : auto_diagnostic_group d;
4726 57 : error (VAR_P (decl)
4727 : ? G_("use of local variable with automatic storage from "
4728 : "containing function")
4729 : : G_("use of parameter from containing function"));
4730 39 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4731 39 : }
4732 46 : return error_mark_node;
4733 : }
4734 : return decl;
4735 : }
4736 :
4737 : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4738 : id-expression. (See cp_parser_id_expression for details.) SCOPE,
4739 : if non-NULL, is the type or namespace used to explicitly qualify
4740 : ID_EXPRESSION. DECL is the entity to which that name has been
4741 : resolved.
4742 :
4743 : *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4744 : constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4745 : be set to true if this expression isn't permitted in a
4746 : constant-expression, but it is otherwise not set by this function.
4747 : *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4748 : constant-expression, but a non-constant expression is also
4749 : permissible.
4750 :
4751 : DONE is true if this expression is a complete postfix-expression;
4752 : it is false if this expression is followed by '->', '[', '(', etc.
4753 : ADDRESS_P is true iff this expression is the operand of '&'.
4754 : TEMPLATE_P is true iff the qualified-id was of the form
4755 : "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4756 : appears as a template argument.
4757 :
4758 : If an error occurs, and it is the kind of error that might cause
4759 : the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4760 : is the caller's responsibility to issue the message. *ERROR_MSG
4761 : will be a string with static storage duration, so the caller need
4762 : not "free" it.
4763 :
4764 : Return an expression for the entity, after issuing appropriate
4765 : diagnostics. This function is also responsible for transforming a
4766 : reference to a non-static member into a COMPONENT_REF that makes
4767 : the use of "this" explicit.
4768 :
4769 : Upon return, *IDK will be filled in appropriately. */
4770 : static cp_expr
4771 756868754 : finish_id_expression_1 (tree id_expression,
4772 : tree decl,
4773 : tree scope,
4774 : cp_id_kind *idk,
4775 : bool integral_constant_expression_p,
4776 : bool allow_non_integral_constant_expression_p,
4777 : bool *non_integral_constant_expression_p,
4778 : bool template_p,
4779 : bool done,
4780 : bool address_p,
4781 : bool template_arg_p,
4782 : const char **error_msg,
4783 : location_t location)
4784 : {
4785 756868754 : decl = strip_using_decl (decl);
4786 :
4787 : /* Initialize the output parameters. */
4788 756868754 : *idk = CP_ID_KIND_NONE;
4789 756868754 : *error_msg = NULL;
4790 :
4791 756868754 : if (id_expression == error_mark_node)
4792 12 : return error_mark_node;
4793 : /* If we have a template-id, then no further lookup is
4794 : required. If the template-id was for a template-class, we
4795 : will sometimes have a TYPE_DECL at this point. */
4796 756868742 : else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4797 705373544 : || TREE_CODE (decl) == TYPE_DECL)
4798 : ;
4799 : /* Look up the name. */
4800 : else
4801 : {
4802 705372647 : if (decl == error_mark_node)
4803 : {
4804 : /* Name lookup failed. */
4805 122989 : if (scope
4806 370 : && !dependent_namespace_p (scope)
4807 123359 : && (!TYPE_P (scope)
4808 116 : || (!dependentish_scope_p (scope)
4809 112 : && !(identifier_p (id_expression)
4810 97 : && IDENTIFIER_CONV_OP_P (id_expression)
4811 3 : && dependent_type_p (TREE_TYPE (id_expression))))))
4812 : {
4813 : /* If the qualifying type is non-dependent (and the name
4814 : does not name a conversion operator to a dependent
4815 : type), issue an error. */
4816 360 : qualified_name_lookup_error (scope, id_expression, decl, location);
4817 360 : return error_mark_node;
4818 : }
4819 122629 : else if (!scope)
4820 : {
4821 : /* It may be resolved via Koenig lookup. */
4822 122619 : *idk = CP_ID_KIND_UNQUALIFIED;
4823 122619 : return id_expression;
4824 : }
4825 : else
4826 : decl = id_expression;
4827 : }
4828 :
4829 : /* Remember that the name was used in the definition of
4830 : the current class so that we can check later to see if
4831 : the meaning would have been different after the class
4832 : was entirely defined. */
4833 705249658 : if (!scope && decl != error_mark_node && identifier_p (id_expression))
4834 630746386 : maybe_note_name_used_in_class (id_expression, decl);
4835 :
4836 : /* A use in unevaluated operand might not be instantiated appropriately
4837 : if tsubst_copy builds a dummy parm, or if we never instantiate a
4838 : generic lambda, so mark it now. */
4839 705249668 : if (processing_template_decl
4840 705249668 : && (cp_unevaluated_operand
4841 609872631 : || generic_lambda_fn_p (current_function_decl)))
4842 19117027 : mark_type_use (decl);
4843 :
4844 : /* Disallow uses of local variables from containing functions, except
4845 : within lambda-expressions. */
4846 705249668 : if (outer_automatic_var_p (decl))
4847 : {
4848 3457129 : decl = process_outer_var_ref (decl, tf_warning_or_error);
4849 3457129 : if (decl == error_mark_node)
4850 85 : return error_mark_node;
4851 : }
4852 :
4853 : /* Also disallow uses of function parameters outside the function
4854 : body, except inside an unevaluated context (i.e. decltype). */
4855 705249583 : if (TREE_CODE (decl) == PARM_DECL
4856 294304423 : && DECL_CONTEXT (decl) == NULL_TREE
4857 7920639 : && !CONSTRAINT_VAR_P (decl)
4858 4275194 : && !cp_unevaluated_operand
4859 374 : && !processing_contract_condition
4860 705249627 : && !processing_omp_trait_property_expr)
4861 : {
4862 26 : *error_msg = G_("use of parameter outside function body");
4863 26 : return error_mark_node;
4864 : }
4865 : }
4866 :
4867 : /* If we didn't find anything, or what we found was a type,
4868 : then this wasn't really an id-expression. */
4869 756745652 : if (TREE_CODE (decl) == TEMPLATE_DECL
4870 756745652 : && !DECL_FUNCTION_TEMPLATE_P (decl))
4871 : {
4872 51 : *error_msg = G_("missing template arguments");
4873 51 : return error_mark_node;
4874 : }
4875 756745601 : else if (TREE_CODE (decl) == TYPE_DECL
4876 756744704 : || TREE_CODE (decl) == NAMESPACE_DECL)
4877 : {
4878 912 : *error_msg = G_("expected primary-expression");
4879 912 : return error_mark_node;
4880 : }
4881 :
4882 : /* If the name resolved to a template parameter, there is no
4883 : need to look it up again later. */
4884 32019242 : if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
4885 770267786 : || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4886 : {
4887 18496145 : tree r;
4888 :
4889 18496145 : *idk = CP_ID_KIND_NONE;
4890 18496145 : if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4891 0 : decl = TEMPLATE_PARM_DECL (decl);
4892 18496145 : r = DECL_INITIAL (decl);
4893 18496145 : if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
4894 : {
4895 : /* If the entity is a template parameter object for a template
4896 : parameter of type T, the type of the expression is const T. */
4897 1085 : tree ctype = TREE_TYPE (r);
4898 1085 : ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
4899 : | TYPE_QUAL_CONST));
4900 1085 : r = build1 (VIEW_CONVERT_EXPR, ctype, r);
4901 : }
4902 18496145 : r = convert_from_reference (r);
4903 18496145 : if (integral_constant_expression_p
4904 3194538 : && !dependent_type_p (TREE_TYPE (decl))
4905 21214895 : && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
4906 : {
4907 502 : if (!allow_non_integral_constant_expression_p)
4908 6 : error ("template parameter %qD of type %qT is not allowed in "
4909 : "an integral constant expression because it is not of "
4910 6 : "integral or enumeration type", decl, TREE_TYPE (decl));
4911 502 : *non_integral_constant_expression_p = true;
4912 : }
4913 :
4914 18496145 : if (flag_contracts && processing_contract_condition)
4915 9 : r = constify_contract_access (r);
4916 :
4917 18496145 : return r;
4918 : }
4919 738248544 : else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
4920 : {
4921 9 : gcc_checking_assert (scope);
4922 9 : *idk = CP_ID_KIND_QUALIFIED;
4923 9 : cp_warn_deprecated_use_scopes (scope);
4924 9 : decl = finish_qualified_id_expr (scope, decl, done, address_p,
4925 : template_p, template_arg_p,
4926 : tf_warning_or_error);
4927 : }
4928 : else
4929 : {
4930 738248535 : if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4931 51495198 : && variable_template_p (TREE_OPERAND (decl, 0))
4932 749830344 : && !concept_check_p (decl))
4933 : /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
4934 : considered type-dependent) now, so that the dependence test that
4935 : follows gives us the right answer: if it represents a non-dependent
4936 : variable template-id then finish_template_variable will yield the
4937 : corresponding non-dependent VAR_DECL. */
4938 11581809 : decl = finish_template_variable (decl);
4939 :
4940 738248535 : bool dependent_p = type_dependent_expression_p (decl);
4941 :
4942 : /* If the declaration was explicitly qualified indicate
4943 : that. The semantics of `A::f(3)' are different than
4944 : `f(3)' if `f' is virtual. */
4945 1476497070 : *idk = (scope
4946 738248535 : ? CP_ID_KIND_QUALIFIED
4947 642646173 : : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4948 642646173 : ? CP_ID_KIND_TEMPLATE_ID
4949 : : (dependent_p
4950 612523162 : ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
4951 : : CP_ID_KIND_UNQUALIFIED)));
4952 :
4953 738248535 : if (dependent_p
4954 738248535 : && !scope
4955 422380492 : && DECL_P (decl)
4956 1131295212 : && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
4957 : /* Dependent type attributes on the decl mean that the TREE_TYPE is
4958 : wrong, so just return the identifier. */
4959 39 : return id_expression;
4960 :
4961 738248496 : if (DECL_CLASS_TEMPLATE_P (decl))
4962 : {
4963 0 : error ("use of class template %qT as expression", decl);
4964 0 : return error_mark_node;
4965 : }
4966 :
4967 738248496 : if (TREE_CODE (decl) == TREE_LIST)
4968 : {
4969 : /* Ambiguous reference to base members. */
4970 0 : auto_diagnostic_group d;
4971 0 : error ("request for member %qD is ambiguous in "
4972 : "multiple inheritance lattice", id_expression);
4973 0 : print_candidates (input_location, decl);
4974 0 : return error_mark_node;
4975 0 : }
4976 :
4977 : /* Mark variable-like entities as used. Functions are similarly
4978 : marked either below or after overload resolution. */
4979 738248496 : if ((VAR_P (decl)
4980 535014936 : || TREE_CODE (decl) == PARM_DECL
4981 240710545 : || TREE_CODE (decl) == CONST_DECL
4982 227187448 : || TREE_CODE (decl) == RESULT_DECL)
4983 1046075984 : && !mark_used (decl))
4984 12 : return error_mark_node;
4985 :
4986 : /* Only certain kinds of names are allowed in constant
4987 : expression. Template parameters have already
4988 : been handled above. */
4989 738248481 : if (! error_operand_p (decl)
4990 738248180 : && !dependent_p
4991 738248180 : && integral_constant_expression_p
4992 74747275 : && !decl_constant_var_p (decl)
4993 60937993 : && TREE_CODE (decl) != CONST_DECL
4994 52648771 : && !builtin_valid_in_constant_expr_p (decl)
4995 790849286 : && !concept_check_p (decl))
4996 : {
4997 52085534 : if (!allow_non_integral_constant_expression_p)
4998 : {
4999 30 : error ("%qD cannot appear in a constant-expression", decl);
5000 30 : return error_mark_node;
5001 : }
5002 52085504 : *non_integral_constant_expression_p = true;
5003 : }
5004 :
5005 738248451 : if (tree wrap = maybe_get_tls_wrapper_call (decl))
5006 : /* Replace an evaluated use of the thread_local variable with
5007 : a call to its wrapper. */
5008 : decl = wrap;
5009 738247939 : else if (concept_check_p (decl))
5010 : {
5011 : /* Nothing more to do. All of the analysis for concept checks
5012 : is done by build_conept_id, called from the parser. */
5013 : }
5014 722468678 : else if (scope)
5015 : {
5016 93834558 : if (TREE_CODE (decl) == SCOPE_REF)
5017 : {
5018 72300 : gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
5019 72300 : decl = TREE_OPERAND (decl, 1);
5020 : }
5021 :
5022 93834558 : decl = (adjust_result_of_qualified_name_lookup
5023 93834558 : (decl, scope, current_nonlambda_class_type()));
5024 :
5025 93834558 : cp_warn_deprecated_use_scopes (scope);
5026 :
5027 93834558 : if (TYPE_P (scope))
5028 13445368 : decl = finish_qualified_id_expr (scope,
5029 : decl,
5030 : done,
5031 : address_p,
5032 : template_p,
5033 : template_arg_p,
5034 : tf_warning_or_error);
5035 : else
5036 80389190 : decl = convert_from_reference (decl);
5037 : }
5038 628634120 : else if (TREE_CODE (decl) == FIELD_DECL)
5039 : {
5040 65710927 : if (flag_contracts && processing_contract_condition
5041 22 : && contract_class_ptr == current_class_ptr)
5042 : {
5043 4 : error ("%qD 'this' required when accessing a member within a "
5044 : "constructor precondition or destructor postcondition "
5045 : "contract check", decl);
5046 4 : return error_mark_node;
5047 : }
5048 : /* Since SCOPE is NULL here, this is an unqualified name.
5049 : Access checking has been performed during name lookup
5050 : already. Turn off checking to avoid duplicate errors. */
5051 65710923 : push_deferring_access_checks (dk_no_check);
5052 65710923 : decl = finish_non_static_data_member (decl, NULL_TREE,
5053 : /*qualifying_scope=*/NULL_TREE);
5054 65710923 : pop_deferring_access_checks ();
5055 : }
5056 562923193 : else if (is_overloaded_fn (decl))
5057 : {
5058 : /* We only need to look at the first function,
5059 : because all the fns share the attribute we're
5060 : concerned with (all member fns or all non-members). */
5061 60005684 : tree first_fn = get_first_fn (decl);
5062 60005684 : first_fn = STRIP_TEMPLATE (first_fn);
5063 :
5064 60005684 : if (!template_arg_p
5065 60005684 : && (TREE_CODE (first_fn) == USING_DECL
5066 60003836 : || (TREE_CODE (first_fn) == FUNCTION_DECL
5067 60003836 : && DECL_FUNCTION_MEMBER_P (first_fn)
5068 36418064 : && !shared_member_p (decl))))
5069 : {
5070 : /* A set of member functions. */
5071 28146691 : if (flag_contracts && processing_contract_condition
5072 16 : && contract_class_ptr == current_class_ptr)
5073 : {
5074 2 : error ("%qD 'this' required when accessing a member within a "
5075 : "constructor precondition or destructor postcondition "
5076 : "contract check", decl);
5077 2 : return error_mark_node;
5078 : }
5079 28146689 : decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
5080 28146689 : return finish_class_member_access_expr (decl, id_expression,
5081 : /*template_p=*/false,
5082 28146689 : tf_warning_or_error);
5083 : }
5084 :
5085 31858993 : decl = baselink_for_fns (decl);
5086 : }
5087 : else
5088 : {
5089 492223404 : if (DECL_P (decl) && DECL_NONLOCAL (decl)
5090 504383134 : && DECL_CLASS_SCOPE_P (decl))
5091 : {
5092 1465625 : tree context = context_for_name_lookup (decl);
5093 1465625 : if (context != current_class_type)
5094 : {
5095 767095 : tree path = currently_open_derived_class (context);
5096 767095 : if (!path)
5097 : /* PATH can be null for using an enum of an unrelated
5098 : class; we checked its access in lookup_using_decl.
5099 :
5100 : ??? Should this case make a clone instead, like
5101 : handle_using_decl? */
5102 23 : gcc_assert (TREE_CODE (decl) == CONST_DECL
5103 : /* This is for:
5104 : constexpr auto r = ^^S::i;
5105 : auto a = [:r:]; */
5106 : || flag_reflection);
5107 : else
5108 767072 : perform_or_defer_access_check (TYPE_BINFO (path),
5109 : decl, decl,
5110 : tf_warning_or_error);
5111 : }
5112 : }
5113 :
5114 502917509 : decl = convert_from_reference (decl);
5115 : }
5116 : }
5117 :
5118 710101765 : check_param_in_postcondition (decl, location);
5119 710101765 : if (flag_contracts && processing_contract_condition)
5120 1309 : decl = constify_contract_access (decl);
5121 :
5122 710101765 : return cp_expr (decl, location);
5123 : }
5124 :
5125 : /* As per finish_id_expression_1, but adding a wrapper node
5126 : around the result if needed to express LOCATION. */
5127 :
5128 : cp_expr
5129 756868754 : finish_id_expression (tree id_expression,
5130 : tree decl,
5131 : tree scope,
5132 : cp_id_kind *idk,
5133 : bool integral_constant_expression_p,
5134 : bool allow_non_integral_constant_expression_p,
5135 : bool *non_integral_constant_expression_p,
5136 : bool template_p,
5137 : bool done,
5138 : bool address_p,
5139 : bool template_arg_p,
5140 : const char **error_msg,
5141 : location_t location)
5142 : {
5143 756868754 : cp_expr result
5144 756868754 : = finish_id_expression_1 (id_expression, decl, scope, idk,
5145 : integral_constant_expression_p,
5146 : allow_non_integral_constant_expression_p,
5147 : non_integral_constant_expression_p,
5148 : template_p, done, address_p, template_arg_p,
5149 : error_msg, location);
5150 756868751 : return result.maybe_add_location_wrapper ();
5151 : }
5152 :
5153 : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
5154 : use as a type-specifier. */
5155 :
5156 : tree
5157 21252065 : finish_typeof (tree expr)
5158 : {
5159 21252065 : tree type;
5160 :
5161 21252065 : if (type_dependent_expression_p (expr))
5162 : {
5163 21160919 : type = cxx_make_type (TYPEOF_TYPE);
5164 21160919 : TYPEOF_TYPE_EXPR (type) = expr;
5165 21160919 : SET_TYPE_STRUCTURAL_EQUALITY (type);
5166 :
5167 21160919 : return type;
5168 : }
5169 :
5170 91146 : expr = mark_type_use (expr);
5171 :
5172 91146 : type = unlowered_expr_type (expr);
5173 :
5174 91146 : if (!type || type == unknown_type_node)
5175 : {
5176 3 : error ("type of %qE is unknown", expr);
5177 3 : return error_mark_node;
5178 : }
5179 :
5180 : return type;
5181 : }
5182 :
5183 : /* Implement the __underlying_type keyword: Return the underlying
5184 : type of TYPE, suitable for use as a type-specifier. */
5185 :
5186 : tree
5187 46804 : finish_underlying_type (tree type)
5188 : {
5189 46804 : if (!complete_type_or_else (type, NULL_TREE))
5190 3 : return error_mark_node;
5191 :
5192 46801 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5193 : {
5194 24 : error ("%qT is not an enumeration type", type);
5195 24 : return error_mark_node;
5196 : }
5197 :
5198 46777 : tree underlying_type = ENUM_UNDERLYING_TYPE (type);
5199 :
5200 : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5201 : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5202 : See finish_enum_value_list for details. */
5203 46777 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5204 54 : underlying_type
5205 54 : = c_common_type_for_mode (TYPE_MODE (underlying_type),
5206 54 : TYPE_UNSIGNED (underlying_type));
5207 :
5208 : return underlying_type;
5209 : }
5210 :
5211 : /* Implement the __type_pack_element keyword: Return the type
5212 : at index IDX within TYPES. */
5213 :
5214 : static tree
5215 118175 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
5216 : {
5217 118175 : idx = maybe_constant_value (idx, NULL_TREE, mce_true);
5218 118175 : if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
5219 : {
5220 6 : if (complain & tf_error)
5221 3 : error ("pack index has non-integral type %qT", TREE_TYPE (idx));
5222 6 : return error_mark_node;
5223 : }
5224 118169 : if (TREE_CODE (idx) != INTEGER_CST)
5225 : {
5226 1 : if (complain & tf_error)
5227 : {
5228 1 : error ("pack index is not an integral constant");
5229 1 : cxx_constant_value (idx);
5230 : }
5231 1 : return error_mark_node;
5232 : }
5233 118168 : if (tree_int_cst_sgn (idx) < 0)
5234 : {
5235 3 : if (complain & tf_error)
5236 3 : error ("pack index %qE is negative", idx);
5237 3 : return error_mark_node;
5238 : }
5239 118165 : if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
5240 : {
5241 30 : if (complain & tf_error)
5242 24 : error ("pack index %qE is out of range for pack of length %qd",
5243 24 : idx, TREE_VEC_LENGTH (types));
5244 30 : return error_mark_node;
5245 : }
5246 118135 : return TREE_VEC_ELT (types, tree_to_shwi (idx));
5247 : }
5248 :
5249 : /* In a pack-index T...[N], return the element at index IDX within TYPES.
5250 : PARENTHESIZED_P is true iff the pack index was wrapped in (). */
5251 :
5252 : tree
5253 10832 : pack_index_element (tree idx, tree types, bool parenthesized_p,
5254 : tsubst_flags_t complain)
5255 : {
5256 10832 : tree r = finish_type_pack_element (idx, types, complain);
5257 10832 : if (parenthesized_p)
5258 : /* For the benefit of decltype(auto). */
5259 22 : r = force_paren_expr (r);
5260 10832 : return r;
5261 : }
5262 :
5263 : /* Implement the __direct_bases keyword: Return the direct base classes
5264 : of type. */
5265 :
5266 : tree
5267 15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
5268 : {
5269 15 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5270 15 : || !NON_UNION_CLASS_TYPE_P (type))
5271 8 : return make_tree_vec (0);
5272 :
5273 7 : releasing_vec vector;
5274 7 : vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
5275 7 : tree binfo;
5276 7 : unsigned i;
5277 :
5278 : /* Virtual bases are initialized first */
5279 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5280 13 : if (BINFO_VIRTUAL_P (binfo))
5281 2 : vec_safe_push (vector, binfo);
5282 :
5283 : /* Now non-virtuals */
5284 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5285 13 : if (!BINFO_VIRTUAL_P (binfo))
5286 11 : vec_safe_push (vector, binfo);
5287 :
5288 7 : tree bases_vec = make_tree_vec (vector->length ());
5289 :
5290 27 : for (i = 0; i < vector->length (); ++i)
5291 13 : TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
5292 :
5293 7 : return bases_vec;
5294 7 : }
5295 :
5296 : /* Implement the __bases keyword: Return the base classes
5297 : of type */
5298 :
5299 : /* Find morally non-virtual base classes by walking binfo hierarchy */
5300 : /* Virtual base classes are handled separately in finish_bases */
5301 :
5302 : static tree
5303 73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
5304 : {
5305 : /* Don't walk bases of virtual bases */
5306 73 : return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
5307 : }
5308 :
5309 : static tree
5310 73 : dfs_calculate_bases_post (tree binfo, void *data_)
5311 : {
5312 73 : vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
5313 73 : if (!BINFO_VIRTUAL_P (binfo))
5314 48 : vec_safe_push (*data, BINFO_TYPE (binfo));
5315 73 : return NULL_TREE;
5316 : }
5317 :
5318 : /* Calculates the morally non-virtual base classes of a class */
5319 : static vec<tree, va_gc> *
5320 16 : calculate_bases_helper (tree type)
5321 : {
5322 16 : vec<tree, va_gc> *vector = make_tree_vector ();
5323 :
5324 : /* Now add non-virtual base classes in order of construction */
5325 16 : if (TYPE_BINFO (type))
5326 16 : dfs_walk_all (TYPE_BINFO (type),
5327 : dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
5328 16 : return vector;
5329 : }
5330 :
5331 : tree
5332 12 : calculate_bases (tree type, tsubst_flags_t complain)
5333 : {
5334 12 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5335 12 : || !NON_UNION_CLASS_TYPE_P (type))
5336 5 : return make_tree_vec (0);
5337 :
5338 7 : releasing_vec vector;
5339 7 : tree bases_vec = NULL_TREE;
5340 7 : unsigned i;
5341 7 : vec<tree, va_gc> *vbases;
5342 7 : tree binfo;
5343 :
5344 : /* First go through virtual base classes */
5345 7 : for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
5346 16 : vec_safe_iterate (vbases, i, &binfo); i++)
5347 : {
5348 9 : releasing_vec vbase_bases
5349 9 : = calculate_bases_helper (BINFO_TYPE (binfo));
5350 9 : vec_safe_splice (vector, vbase_bases);
5351 9 : }
5352 :
5353 : /* Now for the non-virtual bases */
5354 7 : releasing_vec nonvbases = calculate_bases_helper (type);
5355 7 : vec_safe_splice (vector, nonvbases);
5356 :
5357 : /* Note that during error recovery vector->length can even be zero. */
5358 7 : if (vector->length () > 1)
5359 : {
5360 : /* Last element is entire class, so don't copy */
5361 6 : bases_vec = make_tree_vec (vector->length () - 1);
5362 :
5363 53 : for (i = 0; i < vector->length () - 1; ++i)
5364 41 : TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
5365 : }
5366 : else
5367 1 : bases_vec = make_tree_vec (0);
5368 :
5369 7 : return bases_vec;
5370 7 : }
5371 :
5372 : tree
5373 28 : finish_bases (tree type, bool direct)
5374 : {
5375 28 : tree bases = NULL_TREE;
5376 :
5377 28 : if (!processing_template_decl)
5378 : {
5379 : /* Parameter packs can only be used in templates */
5380 0 : error ("parameter pack %<__bases%> only valid in template declaration");
5381 0 : return error_mark_node;
5382 : }
5383 :
5384 28 : bases = cxx_make_type (BASES);
5385 28 : BASES_TYPE (bases) = type;
5386 28 : BASES_DIRECT (bases) = direct;
5387 28 : SET_TYPE_STRUCTURAL_EQUALITY (bases);
5388 :
5389 28 : return bases;
5390 : }
5391 :
5392 : /* Perform C++-specific checks for __builtin_offsetof before calling
5393 : fold_offsetof. */
5394 :
5395 : tree
5396 2400 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
5397 : {
5398 : /* If we're processing a template, we can't finish the semantics yet.
5399 : Otherwise we can fold the entire expression now. */
5400 2400 : if (processing_template_decl)
5401 : {
5402 60 : expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
5403 60 : SET_EXPR_LOCATION (expr, loc);
5404 60 : return expr;
5405 : }
5406 :
5407 2340 : if (expr == error_mark_node)
5408 : return error_mark_node;
5409 :
5410 2323 : if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
5411 : {
5412 6 : error ("cannot apply %<offsetof%> to destructor %<~%T%>",
5413 6 : TREE_OPERAND (expr, 2));
5414 6 : return error_mark_node;
5415 : }
5416 4619 : if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
5417 4619 : || TREE_TYPE (expr) == unknown_type_node)
5418 : {
5419 30 : while (TREE_CODE (expr) == COMPONENT_REF
5420 30 : || TREE_CODE (expr) == COMPOUND_EXPR)
5421 12 : expr = TREE_OPERAND (expr, 1);
5422 :
5423 18 : if (DECL_P (expr))
5424 : {
5425 0 : auto_diagnostic_group d;
5426 0 : error ("cannot apply %<offsetof%> to member function %qD", expr);
5427 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
5428 0 : }
5429 : else
5430 18 : error ("cannot apply %<offsetof%> to member function");
5431 18 : return error_mark_node;
5432 : }
5433 2299 : if (TREE_CODE (expr) == CONST_DECL)
5434 : {
5435 3 : error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
5436 3 : return error_mark_node;
5437 : }
5438 2296 : if (REFERENCE_REF_P (expr))
5439 9 : expr = TREE_OPERAND (expr, 0);
5440 2296 : if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
5441 3 : return error_mark_node;
5442 2293 : if (warn_invalid_offsetof
5443 2293 : && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
5444 2293 : && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
5445 2338 : && cp_unevaluated_operand == 0)
5446 45 : warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
5447 : "non-standard-layout type %qT is conditionally-supported",
5448 45 : TREE_TYPE (TREE_TYPE (object_ptr)));
5449 2293 : return fold_offsetof (expr);
5450 : }
5451 :
5452 : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
5453 : function is broken out from the above for the benefit of the tree-ssa
5454 : project. */
5455 :
5456 : void
5457 339720 : simplify_aggr_init_expr (tree *tp)
5458 : {
5459 339720 : tree aggr_init_expr = *tp;
5460 :
5461 : /* Form an appropriate CALL_EXPR. */
5462 339720 : tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
5463 339720 : tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
5464 339720 : tree type = TREE_TYPE (slot);
5465 :
5466 339720 : tree call_expr;
5467 339720 : enum style_t { ctor, arg, pcc } style;
5468 :
5469 339720 : if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
5470 : style = ctor;
5471 : #ifdef PCC_STATIC_STRUCT_RETURN
5472 : else if (1)
5473 : style = pcc;
5474 : #endif
5475 : else
5476 : {
5477 88468 : gcc_assert (TREE_ADDRESSABLE (type));
5478 : style = arg;
5479 : }
5480 :
5481 339720 : call_expr = build_call_array_loc (input_location,
5482 339720 : TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
5483 : fn,
5484 339720 : aggr_init_expr_nargs (aggr_init_expr),
5485 339720 : AGGR_INIT_EXPR_ARGP (aggr_init_expr));
5486 339720 : TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
5487 339720 : CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
5488 339720 : CALL_EXPR_OPERATOR_SYNTAX (call_expr)
5489 339720 : = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
5490 339720 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
5491 339720 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
5492 339720 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
5493 :
5494 339720 : if (style == ctor)
5495 : {
5496 : /* Replace the first argument to the ctor with the address of the
5497 : slot. */
5498 251252 : cxx_mark_addressable (slot);
5499 251252 : CALL_EXPR_ARG (call_expr, 0) =
5500 251252 : build1 (ADDR_EXPR, build_pointer_type (type), slot);
5501 : }
5502 88468 : else if (style == arg)
5503 : {
5504 : /* Just mark it addressable here, and leave the rest to
5505 : expand_call{,_inline}. */
5506 88468 : cxx_mark_addressable (slot);
5507 88468 : CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
5508 88468 : call_expr = cp_build_init_expr (slot, call_expr);
5509 : }
5510 : else if (style == pcc)
5511 : {
5512 : /* If we're using the non-reentrant PCC calling convention, then we
5513 : need to copy the returned value out of the static buffer into the
5514 : SLOT. */
5515 : push_deferring_access_checks (dk_no_check);
5516 : call_expr = build_aggr_init (slot, call_expr,
5517 : DIRECT_BIND | LOOKUP_ONLYCONVERTING,
5518 : tf_warning_or_error);
5519 : pop_deferring_access_checks ();
5520 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
5521 : }
5522 :
5523 339720 : if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
5524 : {
5525 3338 : tree init = build_zero_init (type, NULL_TREE,
5526 : /*static_storage_p=*/false);
5527 3338 : init = cp_build_init_expr (slot, init);
5528 3338 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
5529 : init, call_expr);
5530 : }
5531 :
5532 339720 : *tp = call_expr;
5533 339720 : }
5534 :
5535 : /* Emit all thunks to FN that should be emitted when FN is emitted. */
5536 :
5537 : void
5538 57920303 : emit_associated_thunks (tree fn)
5539 : {
5540 : /* When we use vcall offsets, we emit thunks with the virtual
5541 : functions to which they thunk. The whole point of vcall offsets
5542 : is so that you can know statically the entire set of thunks that
5543 : will ever be needed for a given virtual function, thereby
5544 : enabling you to output all the thunks with the function itself. */
5545 57920303 : if (DECL_VIRTUAL_P (fn)
5546 : /* Do not emit thunks for extern template instantiations. */
5547 1090128 : && ! DECL_REALLY_EXTERN (fn)
5548 : /* Do not emit thunks for tentative decls, those will be processed
5549 : again at_eof if really needed. */
5550 58927865 : && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
5551 : {
5552 1006831 : tree thunk;
5553 :
5554 2017862 : for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
5555 : {
5556 4200 : if (!THUNK_ALIAS (thunk))
5557 : {
5558 4200 : use_thunk (thunk, /*emit_p=*/1);
5559 4200 : if (DECL_RESULT_THUNK_P (thunk))
5560 : {
5561 178 : tree probe;
5562 :
5563 178 : for (probe = DECL_THUNKS (thunk);
5564 327 : probe; probe = DECL_CHAIN (probe))
5565 149 : use_thunk (probe, /*emit_p=*/1);
5566 : }
5567 : }
5568 : else
5569 0 : gcc_assert (!DECL_THUNKS (thunk));
5570 : }
5571 : }
5572 57920303 : }
5573 :
5574 : /* Generate RTL for FN. */
5575 :
5576 : bool
5577 157946686 : expand_or_defer_fn_1 (tree fn)
5578 : {
5579 : /* When the parser calls us after finishing the body of a template
5580 : function, we don't really want to expand the body. */
5581 157946686 : if (processing_template_decl)
5582 : {
5583 : /* Normally, collection only occurs in rest_of_compilation. So,
5584 : if we don't collect here, we never collect junk generated
5585 : during the processing of templates until we hit a
5586 : non-template function. It's not safe to do this inside a
5587 : nested class, though, as the parser may have local state that
5588 : is not a GC root. */
5589 92243916 : if (!function_depth)
5590 91807529 : ggc_collect ();
5591 92243916 : return false;
5592 : }
5593 :
5594 65702770 : gcc_assert (DECL_SAVED_TREE (fn));
5595 :
5596 : /* We make a decision about linkage for these functions at the end
5597 : of the compilation. Until that point, we do not want the back
5598 : end to output them -- but we do want it to see the bodies of
5599 : these functions so that it can inline them as appropriate. */
5600 65702770 : if (DECL_DECLARED_INLINE_P (fn)
5601 1896460 : || DECL_IMPLICIT_INSTANTIATION (fn)
5602 65962047 : || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (fn))
5603 : {
5604 65443520 : if (DECL_INTERFACE_KNOWN (fn))
5605 : /* We've already made a decision as to how this function will
5606 : be handled. */;
5607 46234819 : else if (!at_eof
5608 16817247 : || DECL_IMMEDIATE_FUNCTION_P (fn)
5609 62620838 : || DECL_OMP_DECLARE_REDUCTION_P (fn))
5610 29848800 : tentative_decl_linkage (fn);
5611 : else
5612 16386019 : import_export_decl (fn);
5613 :
5614 : /* If the user wants us to keep all inline functions, then mark
5615 : this function as needed so that finish_file will make sure to
5616 : output it later. Similarly, all dllexport'd functions must
5617 : be emitted; there may be callers in other DLLs. */
5618 65443520 : if (DECL_DECLARED_INLINE_P (fn)
5619 63806310 : && !DECL_REALLY_EXTERN (fn)
5620 60264056 : && !DECL_IMMEDIATE_FUNCTION_P (fn)
5621 59305299 : && !DECL_OMP_DECLARE_REDUCTION_P (fn)
5622 124748819 : && (flag_keep_inline_functions
5623 59302517 : || (flag_keep_inline_dllexport
5624 59302517 : && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
5625 : {
5626 2782 : mark_needed (fn);
5627 2782 : DECL_EXTERNAL (fn) = 0;
5628 : }
5629 : }
5630 :
5631 : /* If this is a constructor or destructor body, we have to clone
5632 : it. */
5633 65702770 : if (maybe_clone_body (fn))
5634 : {
5635 : /* We don't want to process FN again, so pretend we've written
5636 : it out, even though we haven't. */
5637 7754312 : TREE_ASM_WRITTEN (fn) = 1;
5638 : /* If this is a constexpr function we still need the body to be
5639 : able to evaluate it. Similarly, with modules we only stream
5640 : the maybe-in-charge cdtor and regenerate the clones from it on
5641 : demand, so we also need to keep the body. Otherwise we don't
5642 : need it anymore. */
5643 7754312 : if (!maybe_constexpr_fn (fn)
5644 7754312 : && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
5645 3748915 : DECL_SAVED_TREE (fn) = void_node;
5646 7754312 : return false;
5647 : }
5648 :
5649 : /* There's no reason to do any of the work here if we're only doing
5650 : semantic analysis; this code just generates RTL. */
5651 57948458 : if (flag_syntax_only)
5652 : {
5653 : /* Pretend that this function has been written out so that we don't try
5654 : to expand it again. */
5655 28139 : TREE_ASM_WRITTEN (fn) = 1;
5656 28139 : return false;
5657 : }
5658 :
5659 57920319 : if (DECL_OMP_DECLARE_REDUCTION_P (fn))
5660 : return false;
5661 :
5662 : return true;
5663 : }
5664 :
5665 : void
5666 150211891 : expand_or_defer_fn (tree fn)
5667 : {
5668 150211891 : if (expand_or_defer_fn_1 (fn))
5669 : {
5670 50187997 : function_depth++;
5671 :
5672 : /* Expand or defer, at the whim of the compilation unit manager. */
5673 50187997 : cgraph_node::finalize_function (fn, function_depth > 1);
5674 50187997 : emit_associated_thunks (fn);
5675 :
5676 50187997 : function_depth--;
5677 :
5678 100375994 : if (DECL_IMMEDIATE_FUNCTION_P (fn))
5679 : {
5680 915258 : if (cgraph_node *node = cgraph_node::get (fn))
5681 : {
5682 915258 : node->body_removed = true;
5683 915258 : node->analyzed = false;
5684 915258 : node->definition = false;
5685 915258 : node->force_output = false;
5686 : }
5687 : }
5688 : }
5689 150211891 : }
5690 :
5691 432444 : class nrv_data
5692 : {
5693 : public:
5694 216222 : nrv_data () : visited (37) {}
5695 :
5696 : tree var;
5697 : tree result;
5698 : hash_set<tree> visited;
5699 : bool simple;
5700 : bool in_nrv_cleanup;
5701 : };
5702 :
5703 : /* Helper function for walk_tree, used by finalize_nrv below. */
5704 :
5705 : static tree
5706 19812074 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
5707 : {
5708 19812074 : class nrv_data *dp = (class nrv_data *)data;
5709 :
5710 : /* No need to walk into types. There wouldn't be any need to walk into
5711 : non-statements, except that we have to consider STMT_EXPRs. */
5712 19812074 : if (TYPE_P (*tp))
5713 179626 : *walk_subtrees = 0;
5714 :
5715 : /* Replace all uses of the NRV with the RESULT_DECL. */
5716 19632448 : else if (*tp == dp->var)
5717 469091 : *tp = dp->result;
5718 :
5719 : /* Avoid walking into the same tree more than once. Unfortunately, we
5720 : can't just use walk_tree_without duplicates because it would only call
5721 : us for the first occurrence of dp->var in the function body. */
5722 19163357 : else if (dp->visited.add (*tp))
5723 4243994 : *walk_subtrees = 0;
5724 :
5725 : /* If there's a label, we might need to destroy the NRV on goto (92407). */
5726 14919363 : else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
5727 3 : dp->simple = false;
5728 : /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
5729 : but differs from using NULL_TREE in that it indicates that we care
5730 : about the value of the RESULT_DECL. But preserve anything appended
5731 : by check_return_expr. */
5732 14919360 : else if (TREE_CODE (*tp) == RETURN_EXPR)
5733 : {
5734 221132 : tree *p = &TREE_OPERAND (*tp, 0);
5735 565718 : while (TREE_CODE (*p) == COMPOUND_EXPR)
5736 123454 : p = &TREE_OPERAND (*p, 0);
5737 221132 : if (TREE_CODE (*p) == INIT_EXPR
5738 221132 : && INIT_EXPR_NRV_P (*p))
5739 220745 : *p = dp->result;
5740 : }
5741 : /* Change all cleanups for the NRV to only run when not returning. */
5742 14698228 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5743 14698228 : && CLEANUP_DECL (*tp) == dp->var)
5744 : {
5745 119550 : dp->in_nrv_cleanup = true;
5746 119550 : cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
5747 119550 : dp->in_nrv_cleanup = false;
5748 119550 : cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
5749 119550 : *walk_subtrees = 0;
5750 :
5751 119550 : if (dp->simple)
5752 : /* For a simple NRV, just run it on the EH path. */
5753 118934 : CLEANUP_EH_ONLY (*tp) = true;
5754 : else
5755 : {
5756 : /* Not simple, we need to check current_retval_sentinel to decide
5757 : whether to run it. If it's set, we're returning normally and
5758 : don't want to destroy the NRV. If the sentinel is not set, we're
5759 : leaving scope some other way, either by flowing off the end of its
5760 : scope or throwing an exception. */
5761 1848 : tree cond = build3 (COND_EXPR, void_type_node,
5762 616 : current_retval_sentinel,
5763 616 : void_node, CLEANUP_EXPR (*tp));
5764 616 : CLEANUP_EXPR (*tp) = cond;
5765 : }
5766 :
5767 : /* If a cleanup might throw, we need to clear current_retval_sentinel on
5768 : the exception path, both so the check above succeeds and so an outer
5769 : cleanup added by maybe_splice_retval_cleanup doesn't run. */
5770 119550 : if (cp_function_chain->throwing_cleanup)
5771 : {
5772 212 : tree clear = build2 (MODIFY_EXPR, boolean_type_node,
5773 : current_retval_sentinel,
5774 : boolean_false_node);
5775 212 : if (dp->simple)
5776 : {
5777 : /* We're already only on the EH path, just prepend it. */
5778 202 : tree &exp = CLEANUP_EXPR (*tp);
5779 202 : exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
5780 : }
5781 : else
5782 : {
5783 : /* The cleanup runs on both normal and EH paths, we need another
5784 : CLEANUP_STMT to clear the flag only on the EH path. */
5785 10 : tree &bod = CLEANUP_BODY (*tp);
5786 10 : bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
5787 10 : bod, clear, current_retval_sentinel);
5788 10 : CLEANUP_EH_ONLY (bod) = true;
5789 : }
5790 : }
5791 : }
5792 : /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
5793 : want to destroy the retval before the variable goes out of scope. */
5794 14578678 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5795 4493 : && dp->in_nrv_cleanup
5796 14581774 : && CLEANUP_DECL (*tp) == dp->result)
5797 6 : CLEANUP_EXPR (*tp) = void_node;
5798 : /* Replace the DECL_EXPR for the NRV with an initialization of the
5799 : RESULT_DECL, if needed. */
5800 14578672 : else if (TREE_CODE (*tp) == DECL_EXPR
5801 14578672 : && DECL_EXPR_DECL (*tp) == dp->var)
5802 : {
5803 216224 : tree init;
5804 216224 : if (DECL_INITIAL (dp->var)
5805 216224 : && DECL_INITIAL (dp->var) != error_mark_node)
5806 88364 : init = cp_build_init_expr (dp->result,
5807 88364 : DECL_INITIAL (dp->var));
5808 : else
5809 127860 : init = build_empty_stmt (EXPR_LOCATION (*tp));
5810 216224 : DECL_INITIAL (dp->var) = NULL_TREE;
5811 216224 : SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
5812 216224 : *tp = init;
5813 : }
5814 :
5815 : /* Keep iterating. */
5816 19812074 : return NULL_TREE;
5817 : }
5818 :
5819 : /* Called from finish_function to implement the named return value
5820 : optimization by overriding all the RETURN_EXPRs and pertinent
5821 : CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5822 : RESULT_DECL for the function. */
5823 :
5824 : void
5825 216222 : finalize_nrv (tree fndecl, tree var)
5826 : {
5827 216222 : class nrv_data data;
5828 216222 : tree result = DECL_RESULT (fndecl);
5829 :
5830 : /* Copy name from VAR to RESULT. */
5831 216222 : DECL_NAME (result) = DECL_NAME (var);
5832 : /* Don't forget that we take its address. */
5833 216222 : TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
5834 : /* Finally set DECL_VALUE_EXPR to avoid assigning
5835 : a stack slot at -O0 for the original var and debug info
5836 : uses RESULT location for VAR. */
5837 216222 : SET_DECL_VALUE_EXPR (var, result);
5838 216222 : DECL_HAS_VALUE_EXPR_P (var) = 1;
5839 :
5840 216222 : data.var = var;
5841 216222 : data.result = result;
5842 216222 : data.in_nrv_cleanup = false;
5843 :
5844 : /* This is simpler for variables declared in the outer scope of
5845 : the function so we know that their lifetime always ends with a
5846 : return; see g++.dg/opt/nrv6.C. */
5847 216222 : tree outer = outer_curly_brace_block (fndecl);
5848 216222 : data.simple = chain_member (var, BLOCK_VARS (outer));
5849 :
5850 216222 : cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
5851 216222 : }
5852 :
5853 : /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5854 :
5855 : bool
5856 2239 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
5857 : bool need_copy_ctor, bool need_copy_assignment,
5858 : bool need_dtor)
5859 : {
5860 2239 : int save_errorcount = errorcount;
5861 2239 : tree info, t;
5862 :
5863 : /* Always allocate 3 elements for simplicity. These are the
5864 : function decls for the ctor, dtor, and assignment op.
5865 : This layout is known to the three lang hooks,
5866 : cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
5867 : and cxx_omp_clause_assign_op. */
5868 2239 : info = make_tree_vec (3);
5869 2239 : CP_OMP_CLAUSE_INFO (c) = info;
5870 :
5871 2239 : if (need_default_ctor || need_copy_ctor)
5872 : {
5873 1654 : if (need_default_ctor)
5874 1255 : t = get_default_ctor (type);
5875 : else
5876 399 : t = get_copy_ctor (type, tf_warning_or_error);
5877 :
5878 1654 : if (t && !trivial_fn_p (t))
5879 1400 : TREE_VEC_ELT (info, 0) = t;
5880 : }
5881 :
5882 2239 : if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
5883 1632 : TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
5884 :
5885 2239 : if (need_copy_assignment)
5886 : {
5887 397 : t = get_copy_assign (type);
5888 :
5889 397 : if (t && !trivial_fn_p (t))
5890 344 : TREE_VEC_ELT (info, 2) = t;
5891 : }
5892 :
5893 2239 : return errorcount != save_errorcount;
5894 : }
5895 :
5896 : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
5897 : FIELD_DECL, otherwise return DECL itself. */
5898 :
5899 : static tree
5900 26243 : omp_clause_decl_field (tree decl)
5901 : {
5902 26243 : if (VAR_P (decl)
5903 18396 : && DECL_HAS_VALUE_EXPR_P (decl)
5904 359 : && DECL_ARTIFICIAL (decl)
5905 359 : && DECL_LANG_SPECIFIC (decl)
5906 26578 : && DECL_OMP_PRIVATIZED_MEMBER (decl))
5907 : {
5908 328 : tree f = DECL_VALUE_EXPR (decl);
5909 328 : if (INDIRECT_REF_P (f))
5910 0 : f = TREE_OPERAND (f, 0);
5911 328 : if (TREE_CODE (f) == COMPONENT_REF)
5912 : {
5913 328 : f = TREE_OPERAND (f, 1);
5914 328 : gcc_assert (TREE_CODE (f) == FIELD_DECL);
5915 : return f;
5916 : }
5917 : }
5918 : return NULL_TREE;
5919 : }
5920 :
5921 : /* Adjust DECL if needed for printing using %qE. */
5922 :
5923 : static tree
5924 187 : omp_clause_printable_decl (tree decl)
5925 : {
5926 0 : tree t = omp_clause_decl_field (decl);
5927 187 : if (t)
5928 45 : return t;
5929 : return decl;
5930 : }
5931 :
5932 : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
5933 : VAR_DECL T that doesn't need a DECL_EXPR added, record it for
5934 : privatization. */
5935 :
5936 : static void
5937 219 : omp_note_field_privatization (tree f, tree t)
5938 : {
5939 219 : if (!omp_private_member_map)
5940 71 : omp_private_member_map = new hash_map<tree, tree>;
5941 219 : tree &v = omp_private_member_map->get_or_insert (f);
5942 219 : if (v == NULL_TREE)
5943 : {
5944 146 : v = t;
5945 146 : omp_private_member_vec.safe_push (f);
5946 : /* Signal that we don't want to create DECL_EXPR for this dummy var. */
5947 146 : omp_private_member_vec.safe_push (integer_zero_node);
5948 : }
5949 219 : }
5950 :
5951 : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
5952 : dummy VAR_DECL. */
5953 :
5954 : tree
5955 861 : omp_privatize_field (tree t, bool shared)
5956 : {
5957 861 : tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
5958 861 : if (m == error_mark_node)
5959 : return error_mark_node;
5960 861 : if (!omp_private_member_map && !shared)
5961 365 : omp_private_member_map = new hash_map<tree, tree>;
5962 861 : if (TYPE_REF_P (TREE_TYPE (t)))
5963 : {
5964 123 : gcc_assert (INDIRECT_REF_P (m));
5965 123 : m = TREE_OPERAND (m, 0);
5966 : }
5967 861 : tree vb = NULL_TREE;
5968 861 : tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
5969 861 : if (v == NULL_TREE)
5970 : {
5971 770 : v = create_temporary_var (TREE_TYPE (m));
5972 770 : retrofit_lang_decl (v);
5973 770 : DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
5974 770 : SET_DECL_VALUE_EXPR (v, m);
5975 770 : DECL_HAS_VALUE_EXPR_P (v) = 1;
5976 770 : if (!shared)
5977 690 : omp_private_member_vec.safe_push (t);
5978 : }
5979 861 : return v;
5980 : }
5981 :
5982 : /* C++ specialisation of the c_omp_address_inspector class. */
5983 :
5984 : class cp_omp_address_inspector : public c_omp_address_inspector
5985 : {
5986 : public:
5987 30566 : cp_omp_address_inspector (location_t loc, tree t)
5988 30566 : : c_omp_address_inspector (loc, t)
5989 : {
5990 : }
5991 :
5992 30566 : ~cp_omp_address_inspector ()
5993 : {
5994 22265 : }
5995 :
5996 129620 : bool processing_template_decl_p ()
5997 : {
5998 129620 : return processing_template_decl;
5999 : }
6000 :
6001 0 : void emit_unmappable_type_notes (tree t)
6002 : {
6003 0 : if (TREE_TYPE (t) != error_mark_node
6004 0 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
6005 0 : cxx_incomplete_type_inform (TREE_TYPE (t));
6006 0 : }
6007 :
6008 1058 : tree convert_from_reference (tree x)
6009 : {
6010 1058 : return ::convert_from_reference (x);
6011 : }
6012 :
6013 141 : tree build_array_ref (location_t loc, tree arr, tree idx)
6014 : {
6015 141 : return ::build_array_ref (loc, arr, idx);
6016 : }
6017 :
6018 22207 : bool check_clause (tree clause)
6019 : {
6020 22207 : if (TREE_CODE (orig) == COMPONENT_REF
6021 22207 : && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
6022 : tf_warning_or_error))
6023 : return false;
6024 22204 : if (!c_omp_address_inspector::check_clause (clause))
6025 : return false;
6026 : return true;
6027 : }
6028 : };
6029 :
6030 : /* Helper function for handle_omp_array_sections. Called recursively
6031 : to handle multiple array-section-subscripts. C is the clause,
6032 : T current expression (initially OMP_CLAUSE_DECL), which is either
6033 : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
6034 : expression if specified, TREE_VALUE length expression if specified,
6035 : TREE_CHAIN is what it has been specified after, or some decl.
6036 : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
6037 : set to true if any of the array-section-subscript could have length
6038 : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
6039 : first array-section-subscript which is known not to have length
6040 : of one. Given say:
6041 : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
6042 : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
6043 : all are or may have length of 1, array-section-subscript [:2] is the
6044 : first one known not to have length 1. For array-section-subscript
6045 : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
6046 : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
6047 : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
6048 : case though, as some lengths could be zero. */
6049 :
6050 : static tree
6051 20464 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
6052 : bool &maybe_zero_len, unsigned int &first_non_one,
6053 : enum c_omp_region_type ort)
6054 : {
6055 20464 : tree ret, low_bound, length, type;
6056 20464 : bool openacc = (ort & C_ORT_ACC) != 0;
6057 20464 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
6058 : {
6059 9274 : if (error_operand_p (t))
6060 6 : return error_mark_node;
6061 :
6062 9268 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6063 9268 : tree t_refto = ai.maybe_unconvert_ref (t);
6064 :
6065 9268 : if (!ai.check_clause (c))
6066 0 : return error_mark_node;
6067 9268 : else if (ai.component_access_p ()
6068 10656 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6069 64 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
6070 40 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
6071 1388 : t = ai.get_root_term (true);
6072 : else
6073 7880 : t = ai.unconverted_ref_origin ();
6074 9268 : if (t == error_mark_node)
6075 : return error_mark_node;
6076 9268 : ret = t_refto;
6077 9268 : if (TREE_CODE (t) == FIELD_DECL)
6078 33 : ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6079 9235 : else if (!VAR_P (t)
6080 2702 : && (openacc || !EXPR_P (t))
6081 2507 : && TREE_CODE (t) != PARM_DECL)
6082 : {
6083 48 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6084 : return NULL_TREE;
6085 30 : if (DECL_P (t))
6086 30 : error_at (OMP_CLAUSE_LOCATION (c),
6087 : "%qD is not a variable in %qs clause", t,
6088 30 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6089 : else
6090 0 : error_at (OMP_CLAUSE_LOCATION (c),
6091 : "%qE is not a variable in %qs clause", t,
6092 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6093 30 : return error_mark_node;
6094 : }
6095 9187 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6096 8997 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6097 17256 : && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
6098 : {
6099 17 : error_at (OMP_CLAUSE_LOCATION (c),
6100 : "%qD is threadprivate variable in %qs clause", t,
6101 17 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6102 17 : return error_mark_node;
6103 : }
6104 9203 : if (type_dependent_expression_p (ret))
6105 : return NULL_TREE;
6106 8516 : ret = convert_from_reference (ret);
6107 8516 : return ret;
6108 9268 : }
6109 :
6110 11190 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
6111 7387 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6112 6193 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6113 4909 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6114 13796 : && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
6115 43 : TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
6116 11190 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
6117 : maybe_zero_len, first_non_one, ort);
6118 11190 : if (ret == error_mark_node || ret == NULL_TREE)
6119 : return ret;
6120 :
6121 10186 : type = TREE_TYPE (ret);
6122 10186 : low_bound = TREE_OPERAND (t, 1);
6123 10186 : length = TREE_OPERAND (t, 2);
6124 8239 : if ((low_bound && type_dependent_expression_p (low_bound))
6125 18342 : || (length && type_dependent_expression_p (length)))
6126 88 : return NULL_TREE;
6127 :
6128 10098 : if (low_bound == error_mark_node || length == error_mark_node)
6129 : return error_mark_node;
6130 :
6131 10098 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
6132 : {
6133 69 : error_at (OMP_CLAUSE_LOCATION (c),
6134 : "low bound %qE of array section does not have integral type",
6135 : low_bound);
6136 69 : return error_mark_node;
6137 : }
6138 10029 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
6139 : {
6140 63 : error_at (OMP_CLAUSE_LOCATION (c),
6141 : "length %qE of array section does not have integral type",
6142 : length);
6143 63 : return error_mark_node;
6144 : }
6145 9966 : if (low_bound)
6146 8073 : low_bound = mark_rvalue_use (low_bound);
6147 9966 : if (length)
6148 9020 : length = mark_rvalue_use (length);
6149 : /* We need to reduce to real constant-values for checks below. */
6150 9020 : if (length)
6151 9020 : length = fold_simple (length);
6152 9966 : if (low_bound)
6153 8073 : low_bound = fold_simple (low_bound);
6154 8073 : if (low_bound
6155 8073 : && TREE_CODE (low_bound) == INTEGER_CST
6156 15221 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6157 7148 : > TYPE_PRECISION (sizetype))
6158 0 : low_bound = fold_convert (sizetype, low_bound);
6159 9966 : if (length
6160 9020 : && TREE_CODE (length) == INTEGER_CST
6161 16975 : && TYPE_PRECISION (TREE_TYPE (length))
6162 7009 : > TYPE_PRECISION (sizetype))
6163 0 : length = fold_convert (sizetype, length);
6164 9966 : if (low_bound == NULL_TREE)
6165 1893 : low_bound = integer_zero_node;
6166 :
6167 9966 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6168 9966 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
6169 5082 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
6170 : {
6171 60 : if (length != integer_one_node)
6172 : {
6173 36 : error_at (OMP_CLAUSE_LOCATION (c),
6174 : "expected single pointer in %qs clause",
6175 : user_omp_clause_code_name (c, openacc));
6176 36 : return error_mark_node;
6177 : }
6178 : }
6179 9930 : if (length != NULL_TREE)
6180 : {
6181 9008 : if (!integer_nonzerop (length))
6182 : {
6183 2058 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6184 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6185 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6186 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6187 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6188 : {
6189 459 : if (integer_zerop (length))
6190 : {
6191 28 : error_at (OMP_CLAUSE_LOCATION (c),
6192 : "zero length array section in %qs clause",
6193 28 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6194 28 : return error_mark_node;
6195 : }
6196 : }
6197 : else
6198 1599 : maybe_zero_len = true;
6199 : }
6200 8980 : if (first_non_one == types.length ()
6201 8980 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
6202 3930 : first_non_one++;
6203 : }
6204 9902 : if (TREE_CODE (type) == ARRAY_TYPE)
6205 : {
6206 5461 : if (length == NULL_TREE
6207 5461 : && (TYPE_DOMAIN (type) == NULL_TREE
6208 850 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
6209 : {
6210 30 : error_at (OMP_CLAUSE_LOCATION (c),
6211 : "for unknown bound array type length expression must "
6212 : "be specified");
6213 30 : return error_mark_node;
6214 : }
6215 5431 : if (TREE_CODE (low_bound) == INTEGER_CST
6216 5431 : && tree_int_cst_sgn (low_bound) == -1)
6217 : {
6218 153 : error_at (OMP_CLAUSE_LOCATION (c),
6219 : "negative low bound in array section in %qs clause",
6220 153 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6221 153 : return error_mark_node;
6222 : }
6223 5278 : if (length != NULL_TREE
6224 4476 : && TREE_CODE (length) == INTEGER_CST
6225 8836 : && tree_int_cst_sgn (length) == -1)
6226 : {
6227 153 : error_at (OMP_CLAUSE_LOCATION (c),
6228 : "negative length in array section in %qs clause",
6229 153 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6230 153 : return error_mark_node;
6231 : }
6232 5125 : if (TYPE_DOMAIN (type)
6233 5031 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6234 10156 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
6235 : == INTEGER_CST)
6236 : {
6237 4635 : tree size
6238 4635 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6239 4635 : size = size_binop (PLUS_EXPR, size, size_one_node);
6240 4635 : if (TREE_CODE (low_bound) == INTEGER_CST)
6241 : {
6242 3868 : if (tree_int_cst_lt (size, low_bound))
6243 : {
6244 54 : error_at (OMP_CLAUSE_LOCATION (c),
6245 : "low bound %qE above array section size "
6246 : "in %qs clause", low_bound,
6247 54 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6248 54 : return error_mark_node;
6249 : }
6250 3814 : if (tree_int_cst_equal (size, low_bound))
6251 : {
6252 17 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6253 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6254 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6255 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6256 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6257 : {
6258 17 : error_at (OMP_CLAUSE_LOCATION (c),
6259 : "zero length array section in %qs clause",
6260 17 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6261 17 : return error_mark_node;
6262 : }
6263 0 : maybe_zero_len = true;
6264 : }
6265 3797 : else if (length == NULL_TREE
6266 1420 : && first_non_one == types.length ()
6267 4095 : && tree_int_cst_equal
6268 298 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6269 : low_bound))
6270 195 : first_non_one++;
6271 : }
6272 767 : else if (length == NULL_TREE)
6273 : {
6274 20 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6275 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6276 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6277 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6278 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6279 13 : maybe_zero_len = true;
6280 40 : if (first_non_one == types.length ())
6281 17 : first_non_one++;
6282 : }
6283 4564 : if (length && TREE_CODE (length) == INTEGER_CST)
6284 : {
6285 3290 : if (tree_int_cst_lt (size, length))
6286 : {
6287 57 : error_at (OMP_CLAUSE_LOCATION (c),
6288 : "length %qE above array section size "
6289 : "in %qs clause", length,
6290 57 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6291 57 : return error_mark_node;
6292 : }
6293 3233 : if (TREE_CODE (low_bound) == INTEGER_CST)
6294 : {
6295 2899 : tree lbpluslen
6296 2899 : = size_binop (PLUS_EXPR,
6297 : fold_convert (sizetype, low_bound),
6298 : fold_convert (sizetype, length));
6299 2899 : if (TREE_CODE (lbpluslen) == INTEGER_CST
6300 2899 : && tree_int_cst_lt (size, lbpluslen))
6301 : {
6302 54 : error_at (OMP_CLAUSE_LOCATION (c),
6303 : "high bound %qE above array section size "
6304 : "in %qs clause", lbpluslen,
6305 54 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6306 54 : return error_mark_node;
6307 : }
6308 : }
6309 : }
6310 : }
6311 490 : else if (length == NULL_TREE)
6312 : {
6313 1 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6314 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6315 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6316 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6317 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6318 0 : maybe_zero_len = true;
6319 2 : if (first_non_one == types.length ())
6320 1 : first_non_one++;
6321 : }
6322 :
6323 : /* For [lb:] we will need to evaluate lb more than once. */
6324 3911 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6325 : {
6326 650 : tree lb = cp_save_expr (low_bound);
6327 650 : if (lb != low_bound)
6328 : {
6329 9 : TREE_OPERAND (t, 1) = lb;
6330 9 : low_bound = lb;
6331 : }
6332 : }
6333 : }
6334 4441 : else if (TYPE_PTR_P (type))
6335 : {
6336 4384 : if (length == NULL_TREE)
6337 : {
6338 42 : if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
6339 36 : error_at (OMP_CLAUSE_LOCATION (c),
6340 : "for array function parameter length expression "
6341 : "must be specified");
6342 : else
6343 6 : error_at (OMP_CLAUSE_LOCATION (c),
6344 : "for pointer type length expression must be specified");
6345 42 : return error_mark_node;
6346 : }
6347 4342 : if (length != NULL_TREE
6348 4342 : && TREE_CODE (length) == INTEGER_CST
6349 3249 : && tree_int_cst_sgn (length) == -1)
6350 : {
6351 84 : error_at (OMP_CLAUSE_LOCATION (c),
6352 : "negative length in array section in %qs clause",
6353 84 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6354 84 : return error_mark_node;
6355 : }
6356 : /* If there is a pointer type anywhere but in the very first
6357 : array-section-subscript, the array section could be non-contiguous. */
6358 4258 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6359 4216 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6360 7990 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
6361 : {
6362 : /* If any prior dimension has a non-one length, then deem this
6363 : array section as non-contiguous. */
6364 158 : for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
6365 69 : d = TREE_OPERAND (d, 0))
6366 : {
6367 89 : tree d_length = TREE_OPERAND (d, 2);
6368 89 : if (d_length == NULL_TREE || !integer_onep (d_length))
6369 : {
6370 20 : error_at (OMP_CLAUSE_LOCATION (c),
6371 : "array section is not contiguous in %qs clause",
6372 20 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6373 20 : return error_mark_node;
6374 : }
6375 : }
6376 : }
6377 : }
6378 : else
6379 : {
6380 57 : error_at (OMP_CLAUSE_LOCATION (c),
6381 : "%qE does not have pointer or array type", ret);
6382 57 : return error_mark_node;
6383 : }
6384 9181 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6385 8277 : types.safe_push (TREE_TYPE (ret));
6386 : /* We will need to evaluate lb more than once. */
6387 9181 : tree lb = cp_save_expr (low_bound);
6388 9181 : if (lb != low_bound)
6389 : {
6390 716 : TREE_OPERAND (t, 1) = lb;
6391 716 : low_bound = lb;
6392 : }
6393 : /* Temporarily disable -fstrong-eval-order for array reductions.
6394 : The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
6395 : is something the middle-end can't cope with and more importantly,
6396 : it needs to be the actual base variable that is privatized, not some
6397 : temporary assigned previous value of it. That, together with OpenMP
6398 : saying how many times the side-effects are evaluated is unspecified,
6399 : makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
6400 9181 : warning_sentinel s (flag_strong_eval_order,
6401 9181 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6402 8168 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6403 18481 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
6404 9181 : ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
6405 : tf_warning_or_error);
6406 9181 : return ret;
6407 9181 : }
6408 :
6409 : /* Handle array sections for clause C. */
6410 :
6411 : static bool
6412 9274 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
6413 : {
6414 9274 : bool maybe_zero_len = false;
6415 9274 : unsigned int first_non_one = 0;
6416 9274 : auto_vec<tree, 10> types;
6417 9274 : tree *tp = &OMP_CLAUSE_DECL (c);
6418 9274 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6419 8316 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6420 9480 : && OMP_ITERATOR_DECL_P (*tp))
6421 258 : tp = &TREE_VALUE (*tp);
6422 9274 : tree first = handle_omp_array_sections_1 (c, *tp, types,
6423 : maybe_zero_len, first_non_one,
6424 : ort);
6425 9274 : if (first == error_mark_node)
6426 : return true;
6427 8304 : if (first == NULL_TREE)
6428 : return false;
6429 7511 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6430 7511 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6431 : {
6432 850 : tree t = *tp;
6433 850 : tree tem = NULL_TREE;
6434 850 : if (processing_template_decl)
6435 : return false;
6436 : /* Need to evaluate side effects in the length expressions
6437 : if any. */
6438 751 : while (TREE_CODE (t) == TREE_LIST)
6439 : {
6440 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
6441 : {
6442 0 : if (tem == NULL_TREE)
6443 : tem = TREE_VALUE (t);
6444 : else
6445 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
6446 0 : TREE_VALUE (t), tem);
6447 : }
6448 0 : t = TREE_CHAIN (t);
6449 : }
6450 751 : if (tem)
6451 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
6452 751 : *tp = first;
6453 : }
6454 : else
6455 : {
6456 6661 : unsigned int num = types.length (), i;
6457 6661 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
6458 6661 : tree condition = NULL_TREE;
6459 :
6460 6661 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
6461 3 : maybe_zero_len = true;
6462 6661 : if (processing_template_decl && maybe_zero_len)
6463 : return false;
6464 :
6465 14012 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
6466 7429 : t = TREE_OPERAND (t, 0))
6467 : {
6468 7500 : gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
6469 :
6470 7500 : tree low_bound = TREE_OPERAND (t, 1);
6471 7500 : tree length = TREE_OPERAND (t, 2);
6472 :
6473 7500 : i--;
6474 7500 : if (low_bound
6475 6117 : && TREE_CODE (low_bound) == INTEGER_CST
6476 13006 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6477 5506 : > TYPE_PRECISION (sizetype))
6478 0 : low_bound = fold_convert (sizetype, low_bound);
6479 7500 : if (length
6480 6981 : && TREE_CODE (length) == INTEGER_CST
6481 12589 : && TYPE_PRECISION (TREE_TYPE (length))
6482 5089 : > TYPE_PRECISION (sizetype))
6483 0 : length = fold_convert (sizetype, length);
6484 7500 : if (low_bound == NULL_TREE)
6485 1383 : low_bound = integer_zero_node;
6486 7500 : if (!maybe_zero_len && i > first_non_one)
6487 : {
6488 629 : if (integer_nonzerop (low_bound))
6489 34 : goto do_warn_noncontiguous;
6490 595 : if (length != NULL_TREE
6491 273 : && TREE_CODE (length) == INTEGER_CST
6492 273 : && TYPE_DOMAIN (types[i])
6493 273 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
6494 868 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
6495 : == INTEGER_CST)
6496 : {
6497 273 : tree size;
6498 273 : size = size_binop (PLUS_EXPR,
6499 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6500 : size_one_node);
6501 273 : if (!tree_int_cst_equal (length, size))
6502 : {
6503 37 : do_warn_noncontiguous:
6504 142 : error_at (OMP_CLAUSE_LOCATION (c),
6505 : "array section is not contiguous in %qs "
6506 : "clause",
6507 71 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6508 71 : return true;
6509 : }
6510 : }
6511 558 : if (!processing_template_decl
6512 390 : && length != NULL_TREE
6513 723 : && TREE_SIDE_EFFECTS (length))
6514 : {
6515 0 : if (side_effects == NULL_TREE)
6516 : side_effects = length;
6517 : else
6518 0 : side_effects = build2 (COMPOUND_EXPR,
6519 0 : TREE_TYPE (side_effects),
6520 : length, side_effects);
6521 : }
6522 : }
6523 6871 : else if (processing_template_decl)
6524 698 : continue;
6525 : else
6526 : {
6527 6173 : tree l;
6528 :
6529 6173 : if (i > first_non_one
6530 6173 : && ((length && integer_nonzerop (length))
6531 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6532 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6533 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
6534 0 : continue;
6535 6173 : if (length)
6536 6056 : l = fold_convert (sizetype, length);
6537 : else
6538 : {
6539 117 : l = size_binop (PLUS_EXPR,
6540 : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6541 : size_one_node);
6542 117 : l = size_binop (MINUS_EXPR, l,
6543 : fold_convert (sizetype, low_bound));
6544 : }
6545 6173 : if (i > first_non_one)
6546 : {
6547 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
6548 : size_zero_node);
6549 0 : if (condition == NULL_TREE)
6550 : condition = l;
6551 : else
6552 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
6553 : l, condition);
6554 : }
6555 6173 : else if (size == NULL_TREE)
6556 : {
6557 5895 : size = size_in_bytes (TREE_TYPE (types[i]));
6558 5895 : tree eltype = TREE_TYPE (types[num - 1]);
6559 5964 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6560 69 : eltype = TREE_TYPE (eltype);
6561 5895 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6562 5145 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6563 10287 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6564 1599 : size = size_binop (EXACT_DIV_EXPR, size,
6565 : size_in_bytes (eltype));
6566 5895 : size = size_binop (MULT_EXPR, size, l);
6567 5895 : if (condition)
6568 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
6569 : size, size_zero_node);
6570 : }
6571 : else
6572 278 : size = size_binop (MULT_EXPR, size, l);
6573 : }
6574 : }
6575 6512 : if (!processing_template_decl)
6576 : {
6577 5895 : if (side_effects)
6578 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
6579 5895 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6580 5145 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6581 10287 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6582 : {
6583 1599 : size = size_binop (MINUS_EXPR, size, size_one_node);
6584 1599 : size = save_expr (size);
6585 1599 : tree index_type = build_index_type (size);
6586 1599 : tree eltype = TREE_TYPE (first);
6587 1628 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6588 29 : eltype = TREE_TYPE (eltype);
6589 1599 : tree type = build_array_type (eltype, index_type);
6590 1599 : tree ptype = build_pointer_type (eltype);
6591 1599 : if (TYPE_REF_P (TREE_TYPE (t))
6592 1599 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
6593 152 : t = convert_from_reference (t);
6594 1447 : else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6595 629 : t = build_fold_addr_expr (t);
6596 1599 : tree t2 = build_fold_addr_expr (first);
6597 1599 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6598 : ptrdiff_type_node, t2);
6599 1599 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
6600 : ptrdiff_type_node, t2,
6601 1599 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6602 : ptrdiff_type_node, t));
6603 1599 : if (tree_fits_shwi_p (t2))
6604 1261 : t = build2 (MEM_REF, type, t,
6605 1261 : build_int_cst (ptype, tree_to_shwi (t2)));
6606 : else
6607 : {
6608 338 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6609 : sizetype, t2);
6610 338 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
6611 338 : TREE_TYPE (t), t, t2);
6612 338 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
6613 : }
6614 1599 : OMP_CLAUSE_DECL (c) = t;
6615 7494 : return false;
6616 : }
6617 4296 : OMP_CLAUSE_DECL (c) = first;
6618 4296 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
6619 : return false;
6620 4270 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
6621 4270 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
6622 3730 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
6623 3718 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
6624 4246 : OMP_CLAUSE_SIZE (c) = size;
6625 4270 : if (TREE_CODE (t) == FIELD_DECL)
6626 3 : t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6627 :
6628 4270 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6629 : return false;
6630 :
6631 3742 : if (TREE_CODE (first) == INDIRECT_REF)
6632 : {
6633 : /* Detect and skip adding extra nodes for pointer-to-member
6634 : mappings. These are unsupported for now. */
6635 2407 : tree tmp = TREE_OPERAND (first, 0);
6636 :
6637 2407 : if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
6638 1911 : tmp = TREE_OPERAND (tmp, 0);
6639 :
6640 2407 : if (TREE_CODE (tmp) == INDIRECT_REF)
6641 158 : tmp = TREE_OPERAND (tmp, 0);
6642 :
6643 2407 : if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
6644 : {
6645 466 : tree offset = TREE_OPERAND (tmp, 1);
6646 466 : STRIP_NOPS (offset);
6647 466 : if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
6648 : {
6649 36 : sorry_at (OMP_CLAUSE_LOCATION (c),
6650 : "pointer-to-member mapping %qE not supported",
6651 18 : OMP_CLAUSE_DECL (c));
6652 18 : return true;
6653 : }
6654 : }
6655 : }
6656 :
6657 : /* FIRST represents the first item of data that we are mapping.
6658 : E.g. if we're mapping an array, FIRST might resemble
6659 : "foo.bar.myarray[0]". */
6660 :
6661 3724 : auto_vec<omp_addr_token *, 10> addr_tokens;
6662 :
6663 3724 : if (!omp_parse_expr (addr_tokens, first))
6664 : return true;
6665 :
6666 3724 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6667 :
6668 3724 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
6669 3724 : if (nc != error_mark_node)
6670 : {
6671 3724 : using namespace omp_addr_tokenizer;
6672 :
6673 3724 : if (ai.maybe_zero_length_array_section (c))
6674 3700 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
6675 :
6676 : /* !!! If we're accessing a base decl via chained access
6677 : methods (e.g. multiple indirections), duplicate clause
6678 : detection won't work properly. Skip it in that case. */
6679 3724 : if ((addr_tokens[0]->type == STRUCTURE_BASE
6680 2707 : || addr_tokens[0]->type == ARRAY_BASE)
6681 3724 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
6682 3713 : && addr_tokens[1]->type == ACCESS_METHOD
6683 7437 : && omp_access_chain_p (addr_tokens, 1))
6684 216 : c = nc;
6685 :
6686 3724 : return false;
6687 : }
6688 7448 : }
6689 : }
6690 : return false;
6691 9274 : }
6692 :
6693 : /* Return identifier to look up for omp declare reduction. */
6694 :
6695 : tree
6696 7085 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
6697 : {
6698 7085 : const char *p = NULL;
6699 7085 : const char *m = NULL;
6700 7085 : switch (reduction_code)
6701 : {
6702 4188 : case PLUS_EXPR:
6703 4188 : case MULT_EXPR:
6704 4188 : case MINUS_EXPR:
6705 4188 : case BIT_AND_EXPR:
6706 4188 : case BIT_XOR_EXPR:
6707 4188 : case BIT_IOR_EXPR:
6708 4188 : case TRUTH_ANDIF_EXPR:
6709 4188 : case TRUTH_ORIF_EXPR:
6710 4188 : reduction_id = ovl_op_identifier (false, reduction_code);
6711 4188 : break;
6712 : case MIN_EXPR:
6713 : p = "min";
6714 : break;
6715 : case MAX_EXPR:
6716 : p = "max";
6717 : break;
6718 : default:
6719 : break;
6720 : }
6721 :
6722 4188 : if (p == NULL)
6723 : {
6724 6921 : if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
6725 0 : return error_mark_node;
6726 6921 : p = IDENTIFIER_POINTER (reduction_id);
6727 : }
6728 :
6729 7085 : if (type != NULL_TREE)
6730 2033 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6731 :
6732 7085 : const char prefix[] = "omp declare reduction ";
6733 7085 : size_t lenp = sizeof (prefix);
6734 7085 : if (strncmp (p, prefix, lenp - 1) == 0)
6735 2033 : lenp = 1;
6736 7085 : size_t len = strlen (p);
6737 7085 : size_t lenm = m ? strlen (m) + 1 : 0;
6738 7085 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6739 7085 : if (lenp > 1)
6740 5052 : memcpy (name, prefix, lenp - 1);
6741 7085 : memcpy (name + lenp - 1, p, len + 1);
6742 7085 : if (m)
6743 : {
6744 2033 : name[lenp + len - 1] = '~';
6745 2033 : memcpy (name + lenp + len, m, lenm);
6746 : }
6747 7085 : return get_identifier (name);
6748 : }
6749 :
6750 : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
6751 : FUNCTION_DECL or NULL_TREE if not found. */
6752 :
6753 : static tree
6754 1288 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
6755 : vec<tree> *ambiguousp)
6756 : {
6757 1288 : tree orig_id = id;
6758 1288 : tree baselink = NULL_TREE;
6759 1288 : if (identifier_p (id))
6760 : {
6761 1260 : cp_id_kind idk;
6762 1260 : bool nonint_cst_expression_p;
6763 1260 : const char *error_msg;
6764 1260 : id = omp_reduction_id (ERROR_MARK, id, type);
6765 1260 : tree decl = lookup_name (id);
6766 1260 : if (decl == NULL_TREE)
6767 80 : decl = error_mark_node;
6768 1260 : id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
6769 : &nonint_cst_expression_p, false, true, false,
6770 : false, &error_msg, loc);
6771 1260 : if (idk == CP_ID_KIND_UNQUALIFIED
6772 1340 : && identifier_p (id))
6773 : {
6774 80 : vec<tree, va_gc> *args = NULL;
6775 80 : vec_safe_push (args, build_reference_type (type));
6776 80 : id = perform_koenig_lookup (id, args, tf_none);
6777 : }
6778 : }
6779 28 : else if (TREE_CODE (id) == SCOPE_REF)
6780 28 : id = lookup_qualified_name (TREE_OPERAND (id, 0),
6781 : omp_reduction_id (ERROR_MARK,
6782 28 : TREE_OPERAND (id, 1),
6783 : type),
6784 : LOOK_want::NORMAL, false);
6785 1288 : tree fns = id;
6786 1288 : id = NULL_TREE;
6787 1288 : if (fns && is_overloaded_fn (fns))
6788 : {
6789 1214 : for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
6790 : {
6791 1214 : tree fndecl = *iter;
6792 1214 : if (TREE_CODE (fndecl) == FUNCTION_DECL)
6793 : {
6794 1214 : tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
6795 1214 : if (same_type_p (TREE_TYPE (argtype), type))
6796 : {
6797 1214 : id = fndecl;
6798 1214 : break;
6799 : }
6800 : }
6801 : }
6802 :
6803 1214 : if (id && BASELINK_P (fns))
6804 : {
6805 74 : if (baselinkp)
6806 0 : *baselinkp = fns;
6807 : else
6808 74 : baselink = fns;
6809 : }
6810 : }
6811 :
6812 1288 : if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
6813 : {
6814 35 : auto_vec<tree> ambiguous;
6815 35 : tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
6816 35 : unsigned int ix;
6817 35 : if (ambiguousp == NULL)
6818 19 : ambiguousp = &ambiguous;
6819 73 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
6820 : {
6821 52 : id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
6822 : baselinkp ? baselinkp : &baselink,
6823 : ambiguousp);
6824 38 : if (id == NULL_TREE)
6825 14 : continue;
6826 24 : if (!ambiguousp->is_empty ())
6827 3 : ambiguousp->safe_push (id);
6828 21 : else if (ret != NULL_TREE)
6829 : {
6830 6 : ambiguousp->safe_push (ret);
6831 6 : ambiguousp->safe_push (id);
6832 6 : ret = NULL_TREE;
6833 : }
6834 : else
6835 15 : ret = id;
6836 : }
6837 35 : if (ambiguousp != &ambiguous)
6838 16 : return ret;
6839 19 : if (!ambiguous.is_empty ())
6840 : {
6841 6 : auto_diagnostic_group d;
6842 6 : const char *str = _("candidates are:");
6843 6 : unsigned int idx;
6844 6 : tree udr;
6845 6 : error_at (loc, "user defined reduction lookup is ambiguous");
6846 27 : FOR_EACH_VEC_ELT (ambiguous, idx, udr)
6847 : {
6848 15 : inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
6849 15 : if (idx == 0)
6850 6 : str = get_spaces (str);
6851 : }
6852 6 : ret = error_mark_node;
6853 6 : baselink = NULL_TREE;
6854 6 : }
6855 19 : id = ret;
6856 35 : }
6857 1272 : if (id && baselink)
6858 74 : perform_or_defer_access_check (BASELINK_BINFO (baselink),
6859 : id, id, tf_warning_or_error);
6860 : return id;
6861 : }
6862 :
6863 : /* Return identifier to look up for omp declare mapper. */
6864 :
6865 : tree
6866 3877 : omp_mapper_id (tree mapper_id, tree type)
6867 : {
6868 3877 : const char *p = NULL;
6869 3877 : const char *m = NULL;
6870 :
6871 3877 : if (mapper_id == NULL_TREE)
6872 : p = "";
6873 68 : else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
6874 68 : p = IDENTIFIER_POINTER (mapper_id);
6875 : else
6876 0 : return error_mark_node;
6877 :
6878 3877 : if (type != NULL_TREE)
6879 3875 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6880 :
6881 3877 : const char prefix[] = "omp declare mapper ";
6882 3877 : size_t lenp = sizeof (prefix);
6883 3877 : if (strncmp (p, prefix, lenp - 1) == 0)
6884 2 : lenp = 1;
6885 3877 : size_t len = strlen (p);
6886 3877 : size_t lenm = m ? strlen (m) + 1 : 0;
6887 3877 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6888 3877 : memcpy (name, prefix, lenp - 1);
6889 3877 : memcpy (name + lenp - 1, p, len + 1);
6890 3877 : if (m)
6891 : {
6892 3875 : name[lenp + len - 1] = '~';
6893 3875 : memcpy (name + lenp + len, m, lenm);
6894 : }
6895 3877 : return get_identifier (name);
6896 : }
6897 :
6898 : tree
6899 6955 : cxx_omp_mapper_lookup (tree id, tree type)
6900 : {
6901 6955 : if (!RECORD_OR_UNION_TYPE_P (type))
6902 : return NULL_TREE;
6903 3661 : id = omp_mapper_id (id, type);
6904 3661 : return lookup_name (id);
6905 : }
6906 :
6907 : tree
6908 282 : cxx_omp_extract_mapper_directive (tree vardecl)
6909 : {
6910 282 : gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
6911 :
6912 : /* Instantiate the decl if we haven't already. */
6913 282 : mark_used (vardecl);
6914 282 : tree body = DECL_INITIAL (vardecl);
6915 :
6916 282 : if (TREE_CODE (body) == STATEMENT_LIST)
6917 : {
6918 0 : tree_stmt_iterator tsi = tsi_start (body);
6919 0 : gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
6920 0 : tsi_next (&tsi);
6921 0 : body = tsi_stmt (tsi);
6922 : }
6923 :
6924 282 : gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
6925 :
6926 282 : return body;
6927 : }
6928 :
6929 : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
6930 : nothing more complicated. */
6931 :
6932 : tree
6933 1510 : cxx_omp_map_array_section (location_t loc, tree t)
6934 : {
6935 1510 : tree low = TREE_OPERAND (t, 1);
6936 1510 : tree len = TREE_OPERAND (t, 2);
6937 :
6938 1510 : if (len && integer_onep (len))
6939 : {
6940 237 : t = TREE_OPERAND (t, 0);
6941 :
6942 237 : if (!low)
6943 9 : low = integer_zero_node;
6944 :
6945 237 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
6946 5 : t = convert_from_reference (t);
6947 :
6948 237 : t = build_array_ref (loc, t, low);
6949 : }
6950 :
6951 1510 : return t;
6952 : }
6953 :
6954 : /* Helper function for cp_parser_omp_declare_reduction_exprs
6955 : and tsubst_omp_udr.
6956 : Remove CLEANUP_STMT for data (omp_priv variable).
6957 : Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
6958 : DECL_EXPR. */
6959 :
6960 : tree
6961 4395 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
6962 : {
6963 4395 : if (TYPE_P (*tp))
6964 227 : *walk_subtrees = 0;
6965 4168 : else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
6966 52 : *tp = CLEANUP_BODY (*tp);
6967 4116 : else if (TREE_CODE (*tp) == DECL_EXPR)
6968 : {
6969 307 : tree decl = DECL_EXPR_DECL (*tp);
6970 307 : if (!processing_template_decl
6971 258 : && decl == (tree) data
6972 258 : && DECL_INITIAL (decl)
6973 399 : && DECL_INITIAL (decl) != error_mark_node)
6974 : {
6975 92 : tree list = NULL_TREE;
6976 92 : append_to_statement_list_force (*tp, &list);
6977 92 : tree init_expr = build2 (INIT_EXPR, void_type_node,
6978 92 : decl, DECL_INITIAL (decl));
6979 92 : DECL_INITIAL (decl) = NULL_TREE;
6980 92 : append_to_statement_list_force (init_expr, &list);
6981 92 : *tp = list;
6982 : }
6983 : }
6984 4395 : return NULL_TREE;
6985 : }
6986 :
6987 : /* Data passed from cp_check_omp_declare_reduction to
6988 : cp_check_omp_declare_reduction_r. */
6989 :
6990 : struct cp_check_omp_declare_reduction_data
6991 : {
6992 : location_t loc;
6993 : tree stmts[7];
6994 : bool combiner_p;
6995 : };
6996 :
6997 : /* Helper function for cp_check_omp_declare_reduction, called via
6998 : cp_walk_tree. */
6999 :
7000 : static tree
7001 14952 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
7002 : {
7003 14952 : struct cp_check_omp_declare_reduction_data *udr_data
7004 : = (struct cp_check_omp_declare_reduction_data *) data;
7005 14952 : if (SSA_VAR_P (*tp)
7006 2687 : && !DECL_ARTIFICIAL (*tp)
7007 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
7008 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
7009 : {
7010 135 : location_t loc = udr_data->loc;
7011 135 : if (udr_data->combiner_p)
7012 45 : error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
7013 : "variable %qD which is not %<omp_out%> nor %<omp_in%>",
7014 : *tp);
7015 : else
7016 90 : error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
7017 : "to variable %qD which is not %<omp_priv%> nor "
7018 : "%<omp_orig%>",
7019 : *tp);
7020 135 : return *tp;
7021 : }
7022 : return NULL_TREE;
7023 : }
7024 :
7025 : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
7026 :
7027 : bool
7028 1100 : cp_check_omp_declare_reduction (tree udr)
7029 : {
7030 1100 : tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
7031 1100 : gcc_assert (TYPE_REF_P (type));
7032 1100 : type = TREE_TYPE (type);
7033 1100 : int i;
7034 1100 : location_t loc = DECL_SOURCE_LOCATION (udr);
7035 :
7036 1100 : if (type == error_mark_node)
7037 : return false;
7038 1100 : if (ARITHMETIC_TYPE_P (type))
7039 : {
7040 : static enum tree_code predef_codes[]
7041 : = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
7042 : BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
7043 3276 : for (i = 0; i < 8; i++)
7044 : {
7045 2918 : tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
7046 2918 : const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
7047 2918 : const char *n2 = IDENTIFIER_POINTER (id);
7048 2918 : if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
7049 2918 : && (n1[IDENTIFIER_LENGTH (id)] == '~'
7050 0 : || n1[IDENTIFIER_LENGTH (id)] == '\0'))
7051 : break;
7052 : }
7053 :
7054 376 : if (i == 8
7055 358 : && TREE_CODE (type) != COMPLEX_EXPR)
7056 : {
7057 358 : const char prefix_minmax[] = "omp declare reduction m";
7058 358 : size_t prefix_size = sizeof (prefix_minmax) - 1;
7059 358 : const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
7060 358 : if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
7061 : prefix_minmax, prefix_size) == 0
7062 10 : && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
7063 4 : || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
7064 368 : && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
7065 6 : i = 0;
7066 : }
7067 376 : if (i < 8)
7068 : {
7069 24 : error_at (loc, "predeclared arithmetic type %qT in "
7070 : "%<#pragma omp declare reduction%>", type);
7071 24 : return false;
7072 : }
7073 : }
7074 : else if (FUNC_OR_METHOD_TYPE_P (type)
7075 : || TREE_CODE (type) == ARRAY_TYPE)
7076 : {
7077 24 : error_at (loc, "function or array type %qT in "
7078 : "%<#pragma omp declare reduction%>", type);
7079 24 : return false;
7080 : }
7081 : else if (TYPE_REF_P (type))
7082 : {
7083 0 : error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
7084 : type);
7085 0 : return false;
7086 : }
7087 700 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
7088 : {
7089 24 : error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
7090 : "type %qT in %<#pragma omp declare reduction%>", type);
7091 24 : return false;
7092 : }
7093 :
7094 1028 : tree body = DECL_SAVED_TREE (udr);
7095 1028 : if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
7096 : return true;
7097 :
7098 842 : tree_stmt_iterator tsi;
7099 842 : struct cp_check_omp_declare_reduction_data data;
7100 842 : memset (data.stmts, 0, sizeof data.stmts);
7101 842 : for (i = 0, tsi = tsi_start (body);
7102 4679 : i < 7 && !tsi_end_p (tsi);
7103 3837 : i++, tsi_next (&tsi))
7104 3837 : data.stmts[i] = tsi_stmt (tsi);
7105 842 : data.loc = loc;
7106 842 : gcc_assert (tsi_end_p (tsi));
7107 842 : if (i >= 3)
7108 : {
7109 842 : gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
7110 : && TREE_CODE (data.stmts[1]) == DECL_EXPR);
7111 842 : if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
7112 : return true;
7113 797 : data.combiner_p = true;
7114 797 : if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
7115 : &data, NULL))
7116 45 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
7117 : }
7118 797 : if (i >= 6)
7119 : {
7120 336 : gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
7121 : && TREE_CODE (data.stmts[4]) == DECL_EXPR);
7122 336 : data.combiner_p = false;
7123 336 : if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
7124 : &data, NULL)
7125 336 : || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
7126 : cp_check_omp_declare_reduction_r, &data, NULL))
7127 90 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */);
7128 336 : if (i == 7)
7129 198 : gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
7130 : }
7131 : return true;
7132 : }
7133 :
7134 : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
7135 : an inline call. But, remap
7136 : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
7137 : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
7138 :
7139 : static tree
7140 2198 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
7141 : tree decl, tree placeholder)
7142 : {
7143 2198 : copy_body_data id;
7144 2198 : hash_map<tree, tree> decl_map;
7145 :
7146 2198 : decl_map.put (omp_decl1, placeholder);
7147 2198 : decl_map.put (omp_decl2, decl);
7148 2198 : memset (&id, 0, sizeof (id));
7149 2198 : id.src_fn = DECL_CONTEXT (omp_decl1);
7150 2198 : id.dst_fn = current_function_decl;
7151 2198 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
7152 2198 : id.decl_map = &decl_map;
7153 :
7154 2198 : id.copy_decl = copy_decl_no_change;
7155 2198 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
7156 2198 : id.transform_new_cfg = true;
7157 2198 : id.transform_return_to_modify = false;
7158 2198 : id.eh_lp_nr = 0;
7159 2198 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
7160 2198 : return stmt;
7161 2198 : }
7162 :
7163 : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
7164 : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
7165 :
7166 : static tree
7167 15438 : find_omp_placeholder_r (tree *tp, int *, void *data)
7168 : {
7169 15438 : if (*tp == (tree) data)
7170 265 : return *tp;
7171 : return NULL_TREE;
7172 : }
7173 :
7174 : /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
7175 : Return true if there is some error and the clause should be removed. */
7176 :
7177 : static bool
7178 8855 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
7179 : {
7180 8855 : tree t = OMP_CLAUSE_DECL (c);
7181 8855 : bool predefined = false;
7182 8855 : if (TREE_CODE (t) == TREE_LIST)
7183 : {
7184 0 : gcc_assert (processing_template_decl);
7185 : return false;
7186 : }
7187 8855 : tree type = TREE_TYPE (t);
7188 8855 : if (TREE_CODE (t) == MEM_REF)
7189 1596 : type = TREE_TYPE (type);
7190 8855 : if (TYPE_REF_P (type))
7191 527 : type = TREE_TYPE (type);
7192 8855 : if (TREE_CODE (type) == ARRAY_TYPE)
7193 : {
7194 350 : tree oatype = type;
7195 350 : gcc_assert (TREE_CODE (t) != MEM_REF);
7196 703 : while (TREE_CODE (type) == ARRAY_TYPE)
7197 353 : type = TREE_TYPE (type);
7198 350 : if (!processing_template_decl)
7199 : {
7200 255 : t = require_complete_type (t);
7201 255 : if (t == error_mark_node
7202 255 : || !complete_type_or_else (oatype, NULL_TREE))
7203 9 : return true;
7204 246 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
7205 : TYPE_SIZE_UNIT (type));
7206 246 : if (integer_zerop (size))
7207 : {
7208 6 : error_at (OMP_CLAUSE_LOCATION (c),
7209 : "%qE in %<reduction%> clause is a zero size array",
7210 : omp_clause_printable_decl (t));
7211 3 : return true;
7212 : }
7213 243 : size = size_binop (MINUS_EXPR, size, size_one_node);
7214 243 : size = save_expr (size);
7215 243 : tree index_type = build_index_type (size);
7216 243 : tree atype = build_array_type (type, index_type);
7217 243 : tree ptype = build_pointer_type (type);
7218 243 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7219 146 : t = build_fold_addr_expr (t);
7220 243 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
7221 243 : OMP_CLAUSE_DECL (c) = t;
7222 : }
7223 : }
7224 8843 : if (type == error_mark_node)
7225 : return true;
7226 8840 : else if (ARITHMETIC_TYPE_P (type))
7227 7590 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
7228 : {
7229 : case PLUS_EXPR:
7230 : case MULT_EXPR:
7231 : case MINUS_EXPR:
7232 : case TRUTH_ANDIF_EXPR:
7233 : case TRUTH_ORIF_EXPR:
7234 : predefined = true;
7235 : break;
7236 246 : case MIN_EXPR:
7237 246 : case MAX_EXPR:
7238 246 : if (TREE_CODE (type) == COMPLEX_TYPE)
7239 : break;
7240 : predefined = true;
7241 : break;
7242 111 : case BIT_AND_EXPR:
7243 111 : case BIT_IOR_EXPR:
7244 111 : case BIT_XOR_EXPR:
7245 111 : if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
7246 : break;
7247 : predefined = true;
7248 : break;
7249 : default:
7250 : break;
7251 : }
7252 1250 : else if (TYPE_READONLY (type))
7253 : {
7254 18 : error_at (OMP_CLAUSE_LOCATION (c),
7255 : "%qE has const type for %<reduction%>",
7256 : omp_clause_printable_decl (t));
7257 9 : return true;
7258 : }
7259 1241 : else if (!processing_template_decl)
7260 : {
7261 1037 : t = require_complete_type (t);
7262 1037 : if (t == error_mark_node)
7263 : return true;
7264 1037 : OMP_CLAUSE_DECL (c) = t;
7265 : }
7266 :
7267 1037 : if (predefined)
7268 : {
7269 7368 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7270 7368 : return false;
7271 : }
7272 1463 : else if (processing_template_decl)
7273 : {
7274 213 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
7275 : return true;
7276 : return false;
7277 : }
7278 :
7279 1250 : tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7280 :
7281 1250 : type = TYPE_MAIN_VARIANT (type);
7282 1250 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7283 1250 : if (id == NULL_TREE)
7284 924 : id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
7285 : NULL_TREE, NULL_TREE);
7286 1250 : id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
7287 1250 : if (id)
7288 : {
7289 1205 : if (id == error_mark_node)
7290 : return true;
7291 1199 : mark_used (id);
7292 1199 : tree body = DECL_SAVED_TREE (id);
7293 1199 : if (!body)
7294 : return true;
7295 1196 : if (TREE_CODE (body) == STATEMENT_LIST)
7296 : {
7297 1196 : tree_stmt_iterator tsi;
7298 1196 : tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
7299 1196 : int i;
7300 1196 : tree stmts[7];
7301 1196 : tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
7302 1196 : atype = TREE_TYPE (atype);
7303 1196 : bool need_static_cast = !same_type_p (type, atype);
7304 1196 : memset (stmts, 0, sizeof stmts);
7305 1196 : for (i = 0, tsi = tsi_start (body);
7306 8518 : i < 7 && !tsi_end_p (tsi);
7307 7322 : i++, tsi_next (&tsi))
7308 7322 : stmts[i] = tsi_stmt (tsi);
7309 1196 : gcc_assert (tsi_end_p (tsi));
7310 :
7311 1196 : if (i >= 3)
7312 : {
7313 1196 : gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
7314 : && TREE_CODE (stmts[1]) == DECL_EXPR);
7315 1196 : placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
7316 1196 : DECL_ARTIFICIAL (placeholder) = 1;
7317 1196 : DECL_IGNORED_P (placeholder) = 1;
7318 1196 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
7319 1196 : if (TREE_CODE (t) == MEM_REF)
7320 : {
7321 600 : decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
7322 : type);
7323 600 : DECL_ARTIFICIAL (decl_placeholder) = 1;
7324 600 : DECL_IGNORED_P (decl_placeholder) = 1;
7325 600 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
7326 : }
7327 1196 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
7328 285 : cxx_mark_addressable (placeholder);
7329 1196 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
7330 1196 : && (decl_placeholder
7331 149 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7332 372 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7333 118 : : OMP_CLAUSE_DECL (c));
7334 1196 : tree omp_out = placeholder;
7335 1196 : tree omp_in = decl_placeholder ? decl_placeholder
7336 596 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7337 1196 : if (need_static_cast)
7338 : {
7339 7 : tree rtype = build_reference_type (atype);
7340 7 : omp_out = build_static_cast (input_location,
7341 : rtype, omp_out,
7342 : tf_warning_or_error);
7343 7 : omp_in = build_static_cast (input_location,
7344 : rtype, omp_in,
7345 : tf_warning_or_error);
7346 7 : if (omp_out == error_mark_node || omp_in == error_mark_node)
7347 3 : return true;
7348 7 : omp_out = convert_from_reference (omp_out);
7349 7 : omp_in = convert_from_reference (omp_in);
7350 : }
7351 1196 : OMP_CLAUSE_REDUCTION_MERGE (c)
7352 1196 : = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
7353 1196 : DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
7354 : }
7355 1196 : if (i >= 6)
7356 : {
7357 1005 : gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
7358 : && TREE_CODE (stmts[4]) == DECL_EXPR);
7359 1005 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
7360 1005 : && (decl_placeholder
7361 232 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7362 844 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7363 170 : : OMP_CLAUSE_DECL (c));
7364 1005 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
7365 216 : cxx_mark_addressable (placeholder);
7366 1005 : tree omp_priv = decl_placeholder ? decl_placeholder
7367 429 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7368 1005 : tree omp_orig = placeholder;
7369 1005 : if (need_static_cast)
7370 : {
7371 5 : if (i == 7)
7372 : {
7373 3 : error_at (OMP_CLAUSE_LOCATION (c),
7374 : "user defined reduction with constructor "
7375 : "initializer for base class %qT", atype);
7376 3 : return true;
7377 : }
7378 2 : tree rtype = build_reference_type (atype);
7379 2 : omp_priv = build_static_cast (input_location,
7380 : rtype, omp_priv,
7381 : tf_warning_or_error);
7382 2 : omp_orig = build_static_cast (input_location,
7383 : rtype, omp_orig,
7384 : tf_warning_or_error);
7385 2 : if (omp_priv == error_mark_node
7386 2 : || omp_orig == error_mark_node)
7387 : return true;
7388 2 : omp_priv = convert_from_reference (omp_priv);
7389 2 : omp_orig = convert_from_reference (omp_orig);
7390 : }
7391 1002 : if (i == 6)
7392 286 : *need_default_ctor = true;
7393 1002 : OMP_CLAUSE_REDUCTION_INIT (c)
7394 1002 : = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
7395 1002 : DECL_EXPR_DECL (stmts[3]),
7396 : omp_priv, omp_orig);
7397 1002 : if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
7398 : find_omp_placeholder_r, placeholder, NULL))
7399 238 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
7400 : }
7401 191 : else if (i >= 3)
7402 : {
7403 191 : if (CLASS_TYPE_P (type) && !pod_type_p (type))
7404 175 : *need_default_ctor = true;
7405 : else
7406 : {
7407 16 : tree init;
7408 16 : tree v = decl_placeholder ? decl_placeholder
7409 16 : : convert_from_reference (t);
7410 16 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
7411 7 : init = build_constructor (TREE_TYPE (v), NULL);
7412 : else
7413 9 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
7414 32 : OMP_CLAUSE_REDUCTION_INIT (c)
7415 32 : = cp_build_init_expr (v, init);
7416 : }
7417 : }
7418 : }
7419 : }
7420 1238 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7421 1193 : *need_dtor = true;
7422 : else
7423 : {
7424 90 : error_at (OMP_CLAUSE_LOCATION (c),
7425 : "user defined reduction not found for %qE",
7426 : omp_clause_printable_decl (t));
7427 45 : return true;
7428 : }
7429 1193 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7430 600 : gcc_assert (TYPE_SIZE_UNIT (type)
7431 : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
7432 : return false;
7433 : }
7434 :
7435 : /* Check an instance of an "omp declare mapper" function. */
7436 :
7437 : bool
7438 182 : cp_check_omp_declare_mapper (tree udm)
7439 : {
7440 182 : tree type = TREE_TYPE (udm);
7441 182 : location_t loc = DECL_SOURCE_LOCATION (udm);
7442 :
7443 182 : if (type == error_mark_node)
7444 : return false;
7445 :
7446 182 : if (!processing_template_decl && !RECORD_OR_UNION_TYPE_P (type))
7447 : {
7448 15 : error_at (loc, "%qT is not a struct, union or class type in "
7449 : "%<#pragma omp declare mapper%>", type);
7450 15 : return false;
7451 : }
7452 167 : if (!processing_template_decl && CLASSTYPE_VBASECLASSES (type))
7453 : {
7454 3 : error_at (loc, "%qT must not be a virtual base class in "
7455 : "%<#pragma omp declare mapper%>", type);
7456 3 : return false;
7457 : }
7458 :
7459 : return true;
7460 : }
7461 :
7462 : /* Called from finish_struct_1. linear(this) or linear(this:step)
7463 : clauses might not be finalized yet because the class has been incomplete
7464 : when parsing #pragma omp declare simd methods. Fix those up now. */
7465 :
7466 : void
7467 117814 : finish_omp_declare_simd_methods (tree t)
7468 : {
7469 117814 : if (processing_template_decl)
7470 : return;
7471 :
7472 804058 : for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
7473 : {
7474 1135499 : if (TREE_CODE (x) == USING_DECL
7475 686244 : || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
7476 449255 : continue;
7477 236989 : tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
7478 237097 : if (!ods || !TREE_VALUE (ods))
7479 236881 : continue;
7480 366 : for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
7481 258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7482 66 : && integer_zerop (OMP_CLAUSE_DECL (c))
7483 18 : && OMP_CLAUSE_LINEAR_STEP (c)
7484 276 : && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
7485 : {
7486 18 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
7487 18 : s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
7488 18 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
7489 18 : sizetype, s, TYPE_SIZE_UNIT (t));
7490 18 : OMP_CLAUSE_LINEAR_STEP (c) = s;
7491 : }
7492 : }
7493 : }
7494 :
7495 : /* Adjust sink depend/doacross clause to take into account pointer offsets.
7496 :
7497 : Return TRUE if there was a problem processing the offset, and the
7498 : whole clause should be removed. */
7499 :
7500 : static bool
7501 298 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
7502 : {
7503 298 : tree t = OMP_CLAUSE_DECL (sink_clause);
7504 298 : gcc_assert (TREE_CODE (t) == TREE_LIST);
7505 :
7506 : /* Make sure we don't adjust things twice for templates. */
7507 298 : if (processing_template_decl)
7508 : return false;
7509 :
7510 671 : for (; t; t = TREE_CHAIN (t))
7511 : {
7512 391 : tree decl = TREE_VALUE (t);
7513 391 : if (TYPE_PTR_P (TREE_TYPE (decl)))
7514 : {
7515 6 : tree offset = TREE_PURPOSE (t);
7516 6 : bool neg = wi::neg_p (wi::to_wide (offset));
7517 6 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
7518 6 : decl = mark_rvalue_use (decl);
7519 6 : decl = convert_from_reference (decl);
7520 12 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
7521 : neg ? MINUS_EXPR : PLUS_EXPR,
7522 : decl, offset);
7523 6 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
7524 : MINUS_EXPR, sizetype,
7525 : fold_convert (sizetype, t2),
7526 : fold_convert (sizetype, decl));
7527 6 : if (t2 == error_mark_node)
7528 : return true;
7529 6 : TREE_PURPOSE (t) = t2;
7530 : }
7531 : }
7532 : return false;
7533 : }
7534 :
7535 : /* Finish OpenMP iterators ITER. Return true if they are errorneous
7536 : and clauses containing them should be removed. */
7537 :
7538 : static bool
7539 614 : cp_omp_finish_iterators (tree iter)
7540 : {
7541 614 : bool ret = false;
7542 1393 : for (tree it = iter; it; it = TREE_CHAIN (it))
7543 : {
7544 779 : tree var = TREE_VEC_ELT (it, 0);
7545 779 : tree begin = TREE_VEC_ELT (it, 1);
7546 779 : tree end = TREE_VEC_ELT (it, 2);
7547 779 : tree step = TREE_VEC_ELT (it, 3);
7548 779 : tree orig_step;
7549 779 : tree type = TREE_TYPE (var);
7550 779 : location_t loc = DECL_SOURCE_LOCATION (var);
7551 779 : if (type == error_mark_node)
7552 : {
7553 0 : ret = true;
7554 218 : continue;
7555 : }
7556 779 : if (type_dependent_expression_p (var))
7557 59 : continue;
7558 720 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
7559 : {
7560 27 : error_at (loc, "iterator %qD has neither integral nor pointer type",
7561 : var);
7562 27 : ret = true;
7563 27 : continue;
7564 : }
7565 693 : else if (TYPE_READONLY (type))
7566 : {
7567 24 : error_at (loc, "iterator %qD has const qualified type", var);
7568 24 : ret = true;
7569 24 : continue;
7570 : }
7571 669 : if (type_dependent_expression_p (begin)
7572 660 : || type_dependent_expression_p (end)
7573 1329 : || type_dependent_expression_p (step))
7574 15 : continue;
7575 654 : else if (error_operand_p (step))
7576 : {
7577 0 : ret = true;
7578 0 : continue;
7579 : }
7580 654 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
7581 : {
7582 33 : error_at (EXPR_LOC_OR_LOC (step, loc),
7583 : "iterator step with non-integral type");
7584 21 : ret = true;
7585 21 : continue;
7586 : }
7587 :
7588 633 : begin = mark_rvalue_use (begin);
7589 633 : end = mark_rvalue_use (end);
7590 633 : step = mark_rvalue_use (step);
7591 633 : begin = cp_build_c_cast (input_location, type, begin,
7592 : tf_warning_or_error);
7593 633 : end = cp_build_c_cast (input_location, type, end,
7594 : tf_warning_or_error);
7595 633 : orig_step = step;
7596 633 : if (!processing_template_decl)
7597 556 : step = orig_step = save_expr (step);
7598 633 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
7599 633 : step = cp_build_c_cast (input_location, stype, step,
7600 : tf_warning_or_error);
7601 633 : if (POINTER_TYPE_P (type) && !processing_template_decl)
7602 : {
7603 66 : begin = save_expr (begin);
7604 66 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
7605 66 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
7606 : fold_convert (sizetype, step),
7607 : fold_convert (sizetype, begin));
7608 66 : step = fold_convert (ssizetype, step);
7609 : }
7610 633 : if (!processing_template_decl)
7611 : {
7612 556 : begin = maybe_constant_value (begin);
7613 556 : end = maybe_constant_value (end);
7614 556 : step = maybe_constant_value (step);
7615 556 : orig_step = maybe_constant_value (orig_step);
7616 : }
7617 633 : if (integer_zerop (step))
7618 : {
7619 27 : error_at (loc, "iterator %qD has zero step", var);
7620 27 : ret = true;
7621 27 : continue;
7622 : }
7623 :
7624 606 : if (begin == error_mark_node
7625 597 : || end == error_mark_node
7626 588 : || step == error_mark_node
7627 588 : || orig_step == error_mark_node)
7628 : {
7629 18 : ret = true;
7630 18 : continue;
7631 : }
7632 :
7633 588 : if (!processing_template_decl)
7634 : {
7635 511 : begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
7636 511 : end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
7637 511 : step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
7638 511 : orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
7639 : orig_step);
7640 : }
7641 588 : hash_set<tree> pset;
7642 588 : tree it2;
7643 744 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
7644 : {
7645 183 : tree var2 = TREE_VEC_ELT (it2, 0);
7646 183 : tree begin2 = TREE_VEC_ELT (it2, 1);
7647 183 : tree end2 = TREE_VEC_ELT (it2, 2);
7648 183 : tree step2 = TREE_VEC_ELT (it2, 3);
7649 183 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
7650 183 : if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
7651 : {
7652 9 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
7653 : "begin expression refers to outer iterator %qD", var);
7654 36 : break;
7655 : }
7656 174 : else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
7657 : {
7658 9 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
7659 : "end expression refers to outer iterator %qD", var);
7660 9 : break;
7661 : }
7662 165 : else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
7663 : {
7664 9 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
7665 : "step expression refers to outer iterator %qD", var);
7666 9 : break;
7667 : }
7668 : }
7669 588 : if (it2)
7670 : {
7671 27 : ret = true;
7672 27 : continue;
7673 : }
7674 561 : TREE_VEC_ELT (it, 1) = begin;
7675 561 : TREE_VEC_ELT (it, 2) = end;
7676 561 : if (processing_template_decl)
7677 71 : TREE_VEC_ELT (it, 3) = orig_step;
7678 : else
7679 : {
7680 490 : TREE_VEC_ELT (it, 3) = step;
7681 490 : TREE_VEC_ELT (it, 4) = orig_step;
7682 : }
7683 588 : }
7684 614 : return ret;
7685 : }
7686 :
7687 : /* Ensure that pointers are used in OpenACC attach and detach clauses.
7688 : Return true if an error has been detected. */
7689 :
7690 : static bool
7691 18306 : cp_oacc_check_attachments (tree c)
7692 : {
7693 18306 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
7694 : return false;
7695 :
7696 : /* OpenACC attach / detach clauses must be pointers. */
7697 14411 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
7698 14411 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
7699 : {
7700 196 : tree t = OMP_CLAUSE_DECL (c);
7701 196 : tree type;
7702 :
7703 232 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7704 36 : t = TREE_OPERAND (t, 0);
7705 :
7706 196 : type = TREE_TYPE (t);
7707 :
7708 196 : if (TREE_CODE (type) == REFERENCE_TYPE)
7709 36 : type = TREE_TYPE (type);
7710 :
7711 196 : if (TREE_CODE (type) != POINTER_TYPE)
7712 : {
7713 36 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
7714 : user_omp_clause_code_name (c, true));
7715 36 : return true;
7716 : }
7717 : }
7718 :
7719 : return false;
7720 : }
7721 :
7722 : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
7723 : happened. */
7724 :
7725 : tree
7726 813 : cp_finish_omp_init_prefer_type (tree pref_type)
7727 : {
7728 813 : if (processing_template_decl
7729 741 : || pref_type == NULL_TREE
7730 356 : || TREE_CODE (pref_type) != TREE_LIST)
7731 : return pref_type;
7732 :
7733 81 : tree t = TREE_PURPOSE (pref_type);
7734 81 : char *str = const_cast<char *> (TREE_STRING_POINTER (t));
7735 81 : tree fr_list = TREE_VALUE (pref_type);
7736 81 : int len = TREE_VEC_LENGTH (fr_list);
7737 81 : int cnt = 0;
7738 :
7739 270 : while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
7740 : {
7741 270 : str++;
7742 270 : if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
7743 : {
7744 : /* Assume a no or a single 'fr'. */
7745 150 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7746 150 : location_t loc = UNKNOWN_LOCATION;
7747 150 : tree value = TREE_VEC_ELT (fr_list, cnt);
7748 150 : if (value != NULL_TREE && value != error_mark_node)
7749 : {
7750 126 : loc = EXPR_LOCATION (value);
7751 126 : if (value && TREE_CODE (value) == NOP_EXPR)
7752 39 : value = TREE_OPERAND (value, 0);
7753 126 : value = cp_fully_fold (value);
7754 : }
7755 126 : if (value != NULL_TREE && value != error_mark_node)
7756 : {
7757 126 : if (TREE_CODE (value) != INTEGER_CST
7758 126 : || !tree_fits_shwi_p (value))
7759 0 : error_at (loc,
7760 : "expected string literal or "
7761 : "constant integer expression instead of %qE", value);
7762 : else
7763 : {
7764 126 : HOST_WIDE_INT n = tree_to_shwi (value);
7765 126 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
7766 : {
7767 48 : warning_at (loc, OPT_Wopenmp,
7768 : "unknown foreign runtime identifier %qwd", n);
7769 48 : n = GOMP_INTEROP_IFR_UNKNOWN;
7770 : }
7771 126 : str[0] = (char) n;
7772 : }
7773 : }
7774 150 : str++;
7775 : }
7776 120 : else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
7777 : {
7778 : /* Assume a no or a single 'fr'. */
7779 120 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7780 120 : str++;
7781 : }
7782 270 : str++;
7783 294 : while (str[0] != '\0')
7784 24 : str += strlen (str) + 1;
7785 270 : str++;
7786 270 : cnt++;
7787 270 : if (cnt >= len)
7788 : break;
7789 : }
7790 : return t;
7791 : }
7792 :
7793 : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
7794 : Remove any elements from the list that are invalid. */
7795 :
7796 : tree
7797 62516 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
7798 : {
7799 62516 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
7800 62516 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
7801 62516 : bitmap_head oacc_reduction_head, is_on_device_head;
7802 62516 : tree c, t, *pc;
7803 62516 : tree safelen = NULL_TREE;
7804 62516 : bool openacc = (ort & C_ORT_ACC) != 0;
7805 62516 : bool branch_seen = false;
7806 62516 : bool copyprivate_seen = false;
7807 62516 : bool ordered_seen = false;
7808 62516 : bool order_seen = false;
7809 62516 : bool schedule_seen = false;
7810 62516 : bool oacc_async = false;
7811 62516 : bool indir_component_ref_p = false;
7812 62516 : tree last_iterators = NULL_TREE;
7813 62516 : bool last_iterators_remove = false;
7814 : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
7815 : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
7816 62516 : int reduction_seen = 0;
7817 62516 : bool allocate_seen = false;
7818 62516 : tree detach_seen = NULL_TREE;
7819 62516 : bool mergeable_seen = false;
7820 62516 : bool implicit_moved = false;
7821 62516 : bool target_in_reduction_seen = false;
7822 62516 : bool num_tasks_seen = false;
7823 62516 : bool partial_seen = false;
7824 62516 : bool init_seen = false;
7825 62516 : bool init_use_destroy_seen = false;
7826 62516 : tree init_no_targetsync_clause = NULL_TREE;
7827 62516 : tree depend_clause = NULL_TREE;
7828 :
7829 62516 : bitmap_obstack_initialize (NULL);
7830 62516 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
7831 62516 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
7832 62516 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
7833 62516 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
7834 : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
7835 62516 : bitmap_initialize (&map_head, &bitmap_default_obstack);
7836 62516 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
7837 62516 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
7838 : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
7839 : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
7840 62516 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
7841 62516 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
7842 :
7843 62516 : if (openacc)
7844 28273 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
7845 15931 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
7846 : {
7847 : oacc_async = true;
7848 : break;
7849 : }
7850 :
7851 62516 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
7852 :
7853 160117 : for (pc = &clauses, c = clauses; c ; c = *pc)
7854 : {
7855 97601 : bool remove = false;
7856 97601 : bool field_ok = false;
7857 :
7858 : /* We've reached the end of a list of expanded nodes. Reset the group
7859 : start pointer. */
7860 97601 : if (c == grp_sentinel)
7861 : {
7862 5481 : if (grp_start_p
7863 5481 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
7864 96 : for (tree gc = *grp_start_p; gc != grp_sentinel;
7865 66 : gc = OMP_CLAUSE_CHAIN (gc))
7866 66 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
7867 : grp_start_p = NULL;
7868 : }
7869 :
7870 97601 : switch (OMP_CLAUSE_CODE (c))
7871 : {
7872 2100 : case OMP_CLAUSE_SHARED:
7873 2100 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7874 2100 : goto check_dup_generic;
7875 2576 : case OMP_CLAUSE_PRIVATE:
7876 2576 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7877 2576 : goto check_dup_generic;
7878 7337 : case OMP_CLAUSE_REDUCTION:
7879 7337 : if (reduction_seen == 0)
7880 6233 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
7881 1104 : else if (reduction_seen != -2
7882 2208 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
7883 1104 : ? -1 : 1))
7884 : {
7885 6 : error_at (OMP_CLAUSE_LOCATION (c),
7886 : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
7887 : "on the same construct");
7888 6 : reduction_seen = -2;
7889 : }
7890 : /* FALLTHRU */
7891 9482 : case OMP_CLAUSE_IN_REDUCTION:
7892 9482 : case OMP_CLAUSE_TASK_REDUCTION:
7893 9482 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7894 9482 : t = OMP_CLAUSE_DECL (c);
7895 9482 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7896 : {
7897 2207 : if (handle_omp_array_sections (c, ort))
7898 : {
7899 : remove = true;
7900 : break;
7901 : }
7902 2165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
7903 2165 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
7904 : {
7905 3 : error_at (OMP_CLAUSE_LOCATION (c),
7906 : "%<inscan%> %<reduction%> clause with array "
7907 : "section");
7908 3 : remove = true;
7909 3 : break;
7910 : }
7911 2162 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7912 : {
7913 4672 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7914 2510 : t = TREE_OPERAND (t, 0);
7915 : }
7916 : else
7917 : {
7918 0 : gcc_assert (TREE_CODE (t) == MEM_REF);
7919 0 : t = TREE_OPERAND (t, 0);
7920 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
7921 0 : t = TREE_OPERAND (t, 0);
7922 0 : if (TREE_CODE (t) == ADDR_EXPR
7923 0 : || INDIRECT_REF_P (t))
7924 0 : t = TREE_OPERAND (t, 0);
7925 : }
7926 2162 : tree n = omp_clause_decl_field (t);
7927 2162 : if (n)
7928 59 : t = n;
7929 2162 : goto check_dup_generic_t;
7930 : }
7931 7275 : if (oacc_async)
7932 7 : cxx_mark_addressable (t);
7933 7275 : goto check_dup_generic;
7934 98 : case OMP_CLAUSE_COPYPRIVATE:
7935 98 : copyprivate_seen = true;
7936 98 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7937 98 : goto check_dup_generic;
7938 277 : case OMP_CLAUSE_COPYIN:
7939 277 : goto check_dup_generic;
7940 1631 : case OMP_CLAUSE_LINEAR:
7941 1631 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7942 1631 : t = OMP_CLAUSE_DECL (c);
7943 1631 : if (ort != C_ORT_OMP_DECLARE_SIMD
7944 1631 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
7945 : {
7946 84 : if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
7947 : {
7948 42 : error_at (OMP_CLAUSE_LOCATION (c),
7949 : "modifier should not be specified in %<linear%> "
7950 : "clause on %<simd%> or %<for%> constructs when "
7951 : "not using OpenMP 5.2 modifiers");
7952 42 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
7953 : }
7954 42 : else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
7955 : {
7956 18 : error_at (OMP_CLAUSE_LOCATION (c),
7957 : "modifier other than %<val%> specified in "
7958 : "%<linear%> clause on %<simd%> or %<for%> "
7959 : "constructs when using OpenMP 5.2 modifiers");
7960 18 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
7961 : }
7962 : }
7963 1011 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
7964 2571 : && !type_dependent_expression_p (t))
7965 : {
7966 1529 : tree type = TREE_TYPE (t);
7967 1529 : if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7968 1448 : || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
7969 1598 : && !TYPE_REF_P (type))
7970 : {
7971 12 : error_at (OMP_CLAUSE_LOCATION (c),
7972 : "linear clause with %qs modifier applied to "
7973 : "non-reference variable with %qT type",
7974 12 : OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7975 12 : ? "ref" : "uval", TREE_TYPE (t));
7976 12 : remove = true;
7977 12 : break;
7978 : }
7979 1517 : if (TYPE_REF_P (type))
7980 281 : type = TREE_TYPE (type);
7981 1517 : if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
7982 : {
7983 1442 : if (!INTEGRAL_TYPE_P (type)
7984 85 : && !TYPE_PTR_P (type))
7985 : {
7986 18 : error_at (OMP_CLAUSE_LOCATION (c),
7987 : "linear clause applied to non-integral "
7988 : "non-pointer variable with %qT type",
7989 18 : TREE_TYPE (t));
7990 18 : remove = true;
7991 18 : break;
7992 : }
7993 : }
7994 : }
7995 1601 : t = OMP_CLAUSE_LINEAR_STEP (c);
7996 1601 : if (t == NULL_TREE)
7997 6 : t = integer_one_node;
7998 1601 : if (t == error_mark_node)
7999 : {
8000 : remove = true;
8001 : break;
8002 : }
8003 1601 : else if (!type_dependent_expression_p (t)
8004 1599 : && !INTEGRAL_TYPE_P (TREE_TYPE (t))
8005 1613 : && (ort != C_ORT_OMP_DECLARE_SIMD
8006 9 : || TREE_CODE (t) != PARM_DECL
8007 6 : || !TYPE_REF_P (TREE_TYPE (t))
8008 6 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
8009 : {
8010 6 : error_at (OMP_CLAUSE_LOCATION (c),
8011 : "linear step expression must be integral");
8012 6 : remove = true;
8013 6 : break;
8014 : }
8015 : else
8016 : {
8017 1595 : t = mark_rvalue_use (t);
8018 1595 : if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
8019 : {
8020 42 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
8021 42 : goto check_dup_generic;
8022 : }
8023 1553 : if (!processing_template_decl
8024 1553 : && (VAR_P (OMP_CLAUSE_DECL (c))
8025 835 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
8026 : {
8027 1372 : if (ort == C_ORT_OMP_DECLARE_SIMD)
8028 : {
8029 589 : t = maybe_constant_value (t);
8030 589 : if (TREE_CODE (t) != INTEGER_CST)
8031 : {
8032 6 : error_at (OMP_CLAUSE_LOCATION (c),
8033 : "%<linear%> clause step %qE is neither "
8034 : "constant nor a parameter", t);
8035 6 : remove = true;
8036 6 : break;
8037 : }
8038 : }
8039 1366 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8040 1366 : tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
8041 1366 : if (TYPE_REF_P (type))
8042 257 : type = TREE_TYPE (type);
8043 1366 : if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
8044 : {
8045 66 : type = build_pointer_type (type);
8046 66 : tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
8047 66 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8048 : d, t);
8049 66 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8050 : MINUS_EXPR, sizetype,
8051 : fold_convert (sizetype, t),
8052 : fold_convert (sizetype, d));
8053 66 : if (t == error_mark_node)
8054 : {
8055 : remove = true;
8056 : break;
8057 : }
8058 : }
8059 1300 : else if (TYPE_PTR_P (type)
8060 : /* Can't multiply the step yet if *this
8061 : is still incomplete type. */
8062 1300 : && (ort != C_ORT_OMP_DECLARE_SIMD
8063 45 : || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
8064 45 : || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
8065 30 : || DECL_NAME (OMP_CLAUSE_DECL (c))
8066 30 : != this_identifier
8067 30 : || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
8068 : {
8069 37 : tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
8070 37 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8071 : d, t);
8072 37 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8073 : MINUS_EXPR, sizetype,
8074 : fold_convert (sizetype, t),
8075 : fold_convert (sizetype, d));
8076 37 : if (t == error_mark_node)
8077 : {
8078 : remove = true;
8079 : break;
8080 : }
8081 : }
8082 : else
8083 1263 : t = fold_convert (type, t);
8084 : }
8085 1547 : OMP_CLAUSE_LINEAR_STEP (c) = t;
8086 : }
8087 1547 : goto check_dup_generic;
8088 14881 : check_dup_generic:
8089 14881 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8090 14881 : if (t)
8091 : {
8092 101 : if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
8093 101 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8094 : }
8095 : else
8096 14780 : t = OMP_CLAUSE_DECL (c);
8097 17310 : check_dup_generic_t:
8098 17310 : if (t == current_class_ptr
8099 17310 : && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
8100 102 : || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
8101 72 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
8102 : {
8103 24 : error_at (OMP_CLAUSE_LOCATION (c),
8104 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8105 : " clauses");
8106 24 : remove = true;
8107 24 : break;
8108 : }
8109 17286 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8110 586 : && (!field_ok || TREE_CODE (t) != FIELD_DECL))
8111 : {
8112 59 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8113 : break;
8114 39 : if (DECL_P (t))
8115 30 : error_at (OMP_CLAUSE_LOCATION (c),
8116 : "%qD is not a variable in clause %qs", t,
8117 15 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8118 : else
8119 48 : error_at (OMP_CLAUSE_LOCATION (c),
8120 : "%qE is not a variable in clause %qs", t,
8121 24 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8122 : remove = true;
8123 : }
8124 17227 : else if ((openacc
8125 2707 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
8126 14758 : || (ort == C_ORT_OMP
8127 12427 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
8128 12396 : || (OMP_CLAUSE_CODE (c)
8129 : == OMP_CLAUSE_USE_DEVICE_ADDR)))
8130 31878 : || (ort == C_ORT_OMP_TARGET
8131 936 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
8132 : {
8133 2854 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
8134 2854 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8135 275 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
8136 : {
8137 6 : error_at (OMP_CLAUSE_LOCATION (c),
8138 : "%qD appears more than once in data-sharing "
8139 : "clauses", t);
8140 6 : remove = true;
8141 6 : break;
8142 : }
8143 2848 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
8144 272 : target_in_reduction_seen = true;
8145 2848 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8146 : {
8147 12 : error_at (OMP_CLAUSE_LOCATION (c),
8148 : openacc
8149 : ? "%qD appears more than once in reduction clauses"
8150 : : "%qD appears more than once in data clauses",
8151 : t);
8152 6 : remove = true;
8153 : }
8154 : else
8155 2842 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8156 : }
8157 14373 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8158 14298 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8159 14295 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
8160 28668 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8161 : {
8162 78 : error_at (OMP_CLAUSE_LOCATION (c),
8163 : "%qD appears more than once in data clauses", t);
8164 78 : remove = true;
8165 : }
8166 14295 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
8167 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
8168 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
8169 3115 : && bitmap_bit_p (&map_head, DECL_UID (t)))
8170 : {
8171 9 : if (openacc)
8172 0 : error_at (OMP_CLAUSE_LOCATION (c),
8173 : "%qD appears more than once in data clauses", t);
8174 : else
8175 9 : error_at (OMP_CLAUSE_LOCATION (c),
8176 : "%qD appears both in data and map clauses", t);
8177 : remove = true;
8178 : }
8179 : else
8180 14286 : bitmap_set_bit (&generic_head, DECL_UID (t));
8181 17260 : if (!field_ok)
8182 : break;
8183 12852 : handle_field_decl:
8184 21366 : if (!remove
8185 21169 : && TREE_CODE (t) == FIELD_DECL
8186 16494 : && t == OMP_CLAUSE_DECL (c))
8187 : {
8188 795 : OMP_CLAUSE_DECL (c)
8189 795 : = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
8190 : == OMP_CLAUSE_SHARED));
8191 795 : if (OMP_CLAUSE_DECL (c) == error_mark_node)
8192 97100 : remove = true;
8193 : }
8194 : break;
8195 :
8196 3473 : case OMP_CLAUSE_FIRSTPRIVATE:
8197 3473 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
8198 : {
8199 447 : move_implicit:
8200 447 : implicit_moved = true;
8201 : /* Move firstprivate and map clauses with
8202 : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
8203 : clauses chain. */
8204 447 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
8205 447 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
8206 2804 : while (*pc1)
8207 2357 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
8208 2357 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
8209 : {
8210 275 : *pc3 = *pc1;
8211 275 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
8212 275 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8213 : }
8214 2082 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
8215 2082 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
8216 : {
8217 403 : *pc2 = *pc1;
8218 403 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
8219 403 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8220 : }
8221 : else
8222 1679 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
8223 447 : *pc3 = NULL;
8224 447 : *pc2 = cl2;
8225 447 : *pc1 = cl1;
8226 447 : continue;
8227 447 : }
8228 3216 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8229 3216 : if (t)
8230 69 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8231 : else
8232 3147 : t = OMP_CLAUSE_DECL (c);
8233 3216 : if (!openacc && t == current_class_ptr)
8234 : {
8235 6 : error_at (OMP_CLAUSE_LOCATION (c),
8236 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8237 : " clauses");
8238 6 : remove = true;
8239 6 : break;
8240 : }
8241 3210 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8242 333 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8243 333 : || TREE_CODE (t) != FIELD_DECL))
8244 : {
8245 41 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8246 : break;
8247 18 : if (DECL_P (t))
8248 12 : error_at (OMP_CLAUSE_LOCATION (c),
8249 : "%qD is not a variable in clause %<firstprivate%>",
8250 : t);
8251 : else
8252 6 : error_at (OMP_CLAUSE_LOCATION (c),
8253 : "%qE is not a variable in clause %<firstprivate%>",
8254 : t);
8255 18 : remove = true;
8256 : }
8257 3169 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8258 275 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
8259 3423 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8260 : remove = true;
8261 3169 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8262 3160 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8263 6326 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8264 : {
8265 15 : error_at (OMP_CLAUSE_LOCATION (c),
8266 : "%qD appears more than once in data clauses", t);
8267 15 : remove = true;
8268 : }
8269 3154 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8270 3154 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
8271 : {
8272 21 : if (openacc)
8273 0 : error_at (OMP_CLAUSE_LOCATION (c),
8274 : "%qD appears more than once in data clauses", t);
8275 21 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8276 21 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
8277 : /* Silently drop the clause. */;
8278 : else
8279 18 : error_at (OMP_CLAUSE_LOCATION (c),
8280 : "%qD appears both in data and map clauses", t);
8281 21 : remove = true;
8282 : }
8283 : else
8284 3133 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
8285 3187 : goto handle_field_decl;
8286 :
8287 2790 : case OMP_CLAUSE_LASTPRIVATE:
8288 2790 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8289 2790 : if (t)
8290 35 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8291 : else
8292 2755 : t = OMP_CLAUSE_DECL (c);
8293 2790 : if (!openacc && t == current_class_ptr)
8294 : {
8295 6 : error_at (OMP_CLAUSE_LOCATION (c),
8296 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8297 : " clauses");
8298 6 : remove = true;
8299 6 : break;
8300 : }
8301 2784 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8302 259 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8303 259 : || TREE_CODE (t) != FIELD_DECL))
8304 : {
8305 35 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8306 : break;
8307 9 : if (DECL_P (t))
8308 3 : error_at (OMP_CLAUSE_LOCATION (c),
8309 : "%qD is not a variable in clause %<lastprivate%>",
8310 : t);
8311 : else
8312 6 : error_at (OMP_CLAUSE_LOCATION (c),
8313 : "%qE is not a variable in clause %<lastprivate%>",
8314 : t);
8315 9 : remove = true;
8316 : }
8317 2749 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8318 2749 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8319 : {
8320 12 : error_at (OMP_CLAUSE_LOCATION (c),
8321 : "%qD appears more than once in data clauses", t);
8322 12 : remove = true;
8323 : }
8324 : else
8325 2737 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
8326 2758 : goto handle_field_decl;
8327 :
8328 2218 : case OMP_CLAUSE_IF:
8329 2218 : case OMP_CLAUSE_SELF:
8330 2218 : t = OMP_CLAUSE_OPERAND (c, 0);
8331 2218 : t = maybe_convert_cond (t);
8332 2218 : if (t == error_mark_node)
8333 : remove = true;
8334 2203 : else if (!processing_template_decl)
8335 2142 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8336 2218 : OMP_CLAUSE_OPERAND (c, 0) = t;
8337 2218 : break;
8338 :
8339 289 : case OMP_CLAUSE_FINAL:
8340 289 : t = OMP_CLAUSE_FINAL_EXPR (c);
8341 289 : t = maybe_convert_cond (t);
8342 289 : if (t == error_mark_node)
8343 : remove = true;
8344 289 : else if (!processing_template_decl)
8345 283 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8346 289 : OMP_CLAUSE_FINAL_EXPR (c) = t;
8347 289 : break;
8348 :
8349 92 : case OMP_CLAUSE_NOCONTEXT:
8350 92 : t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
8351 92 : t = maybe_convert_cond (t);
8352 92 : if (t == error_mark_node)
8353 : remove = true;
8354 89 : else if (!processing_template_decl)
8355 83 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8356 92 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
8357 92 : break;
8358 :
8359 80 : case OMP_CLAUSE_NOVARIANTS:
8360 80 : t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
8361 80 : t = maybe_convert_cond (t);
8362 80 : if (t == error_mark_node)
8363 : remove = true;
8364 77 : else if (!processing_template_decl)
8365 71 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8366 80 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
8367 80 : break;
8368 :
8369 1249 : case OMP_CLAUSE_GANG:
8370 : /* Operand 1 is the gang static: argument. */
8371 1249 : t = OMP_CLAUSE_OPERAND (c, 1);
8372 1249 : if (t != NULL_TREE)
8373 : {
8374 129 : if (t == error_mark_node)
8375 : remove = true;
8376 129 : else if (!type_dependent_expression_p (t)
8377 129 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8378 : {
8379 6 : error_at (OMP_CLAUSE_LOCATION (c),
8380 : "%<gang%> static expression must be integral");
8381 6 : remove = true;
8382 : }
8383 : else
8384 : {
8385 123 : t = mark_rvalue_use (t);
8386 123 : if (!processing_template_decl)
8387 : {
8388 123 : t = maybe_constant_value (t);
8389 123 : if (TREE_CODE (t) == INTEGER_CST
8390 109 : && tree_int_cst_sgn (t) != 1
8391 176 : && t != integer_minus_one_node)
8392 : {
8393 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8394 : "%<gang%> static value must be "
8395 : "positive");
8396 0 : t = integer_one_node;
8397 : }
8398 123 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8399 : }
8400 : }
8401 129 : OMP_CLAUSE_OPERAND (c, 1) = t;
8402 : }
8403 : /* Check operand 0, the num argument. */
8404 : /* FALLTHRU */
8405 :
8406 3480 : case OMP_CLAUSE_WORKER:
8407 3480 : case OMP_CLAUSE_VECTOR:
8408 3480 : if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
8409 : break;
8410 : /* FALLTHRU */
8411 :
8412 484 : case OMP_CLAUSE_NUM_TASKS:
8413 484 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
8414 136 : num_tasks_seen = true;
8415 : /* FALLTHRU */
8416 :
8417 3034 : case OMP_CLAUSE_NUM_TEAMS:
8418 3034 : case OMP_CLAUSE_NUM_THREADS:
8419 3034 : case OMP_CLAUSE_NUM_GANGS:
8420 3034 : case OMP_CLAUSE_NUM_WORKERS:
8421 3034 : case OMP_CLAUSE_DYN_GROUPPRIVATE:
8422 3034 : case OMP_CLAUSE_VECTOR_LENGTH:
8423 3034 : t = OMP_CLAUSE_OPERAND (c, 0);
8424 3034 : if (t == error_mark_node)
8425 : remove = true;
8426 3034 : else if (!type_dependent_expression_p (t)
8427 3034 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8428 : {
8429 99 : switch (OMP_CLAUSE_CODE (c))
8430 : {
8431 12 : case OMP_CLAUSE_GANG:
8432 12 : error_at (OMP_CLAUSE_LOCATION (c),
8433 12 : "%<gang%> num expression must be integral"); break;
8434 12 : case OMP_CLAUSE_VECTOR:
8435 12 : error_at (OMP_CLAUSE_LOCATION (c),
8436 : "%<vector%> length expression must be integral");
8437 12 : break;
8438 12 : case OMP_CLAUSE_WORKER:
8439 12 : error_at (OMP_CLAUSE_LOCATION (c),
8440 : "%<worker%> num expression must be integral");
8441 12 : break;
8442 63 : default:
8443 63 : error_at (OMP_CLAUSE_LOCATION (c),
8444 : "%qs expression must be integral",
8445 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8446 : }
8447 : remove = true;
8448 : }
8449 : else
8450 : {
8451 2935 : t = mark_rvalue_use (t);
8452 2935 : if (!processing_template_decl)
8453 : {
8454 2687 : t = maybe_constant_value (t);
8455 2687 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
8456 2652 : && TREE_CODE (t) == INTEGER_CST
8457 4142 : && tree_int_cst_sgn (t) != 1)
8458 : {
8459 85 : switch (OMP_CLAUSE_CODE (c))
8460 : {
8461 3 : case OMP_CLAUSE_GANG:
8462 3 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8463 : "%<gang%> num value must be positive");
8464 3 : break;
8465 0 : case OMP_CLAUSE_VECTOR:
8466 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8467 : "%<vector%> length value must be "
8468 : "positive");
8469 0 : break;
8470 0 : case OMP_CLAUSE_WORKER:
8471 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8472 : "%<worker%> num value must be "
8473 : "positive");
8474 0 : break;
8475 82 : default:
8476 82 : warning_at (OMP_CLAUSE_LOCATION (c),
8477 46 : (flag_openmp || flag_openmp_simd)
8478 82 : ? OPT_Wopenmp : 0,
8479 : "%qs value must be positive",
8480 : omp_clause_code_name
8481 82 : [OMP_CLAUSE_CODE (c)]);
8482 : }
8483 85 : t = integer_one_node;
8484 : }
8485 2602 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
8486 35 : && TREE_CODE (t) == INTEGER_CST
8487 2625 : && tree_int_cst_sgn (t) < 0)
8488 : {
8489 8 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8490 : "%<dyn_groupprivate%> value must be "
8491 : "non-negative");
8492 8 : t = integer_zero_node;
8493 : }
8494 2687 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8495 : }
8496 2935 : OMP_CLAUSE_OPERAND (c, 0) = t;
8497 : }
8498 3034 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
8499 752 : && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
8500 3313 : && !remove)
8501 : {
8502 279 : t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
8503 279 : if (t == error_mark_node)
8504 : remove = true;
8505 279 : else if (!type_dependent_expression_p (t)
8506 279 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8507 : {
8508 0 : error_at (OMP_CLAUSE_LOCATION (c),
8509 : "%qs expression must be integral",
8510 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8511 0 : remove = true;
8512 : }
8513 : else
8514 : {
8515 279 : t = mark_rvalue_use (t);
8516 279 : if (!processing_template_decl)
8517 : {
8518 213 : t = maybe_constant_value (t);
8519 213 : if (TREE_CODE (t) == INTEGER_CST
8520 213 : && tree_int_cst_sgn (t) != 1)
8521 : {
8522 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8523 : "%qs value must be positive",
8524 : omp_clause_code_name
8525 18 : [OMP_CLAUSE_CODE (c)]);
8526 18 : t = NULL_TREE;
8527 : }
8528 : else
8529 195 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8530 213 : tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
8531 213 : if (t
8532 195 : && TREE_CODE (t) == INTEGER_CST
8533 43 : && TREE_CODE (upper) == INTEGER_CST
8534 250 : && tree_int_cst_lt (upper, t))
8535 : {
8536 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8537 : "%<num_teams%> lower bound %qE bigger "
8538 : "than upper bound %qE", t, upper);
8539 18 : t = NULL_TREE;
8540 : }
8541 : }
8542 279 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
8543 : }
8544 : }
8545 : break;
8546 :
8547 3862 : case OMP_CLAUSE_SCHEDULE:
8548 3862 : t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
8549 3862 : if (t == NULL)
8550 : ;
8551 2078 : else if (t == error_mark_node)
8552 : remove = true;
8553 2078 : else if (!type_dependent_expression_p (t)
8554 2078 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8555 : {
8556 9 : error_at (OMP_CLAUSE_LOCATION (c),
8557 : "schedule chunk size expression must be integral");
8558 9 : remove = true;
8559 : }
8560 : else
8561 : {
8562 2069 : t = mark_rvalue_use (t);
8563 2069 : if (!processing_template_decl)
8564 : {
8565 2029 : t = maybe_constant_value (t);
8566 2029 : if (TREE_CODE (t) == INTEGER_CST
8567 2029 : && tree_int_cst_sgn (t) != 1)
8568 : {
8569 6 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8570 : "chunk size value must be positive");
8571 6 : t = integer_one_node;
8572 : }
8573 2029 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8574 : }
8575 2069 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8576 : }
8577 2078 : if (!remove)
8578 : schedule_seen = true;
8579 : break;
8580 :
8581 1268 : case OMP_CLAUSE_SIMDLEN:
8582 1268 : case OMP_CLAUSE_SAFELEN:
8583 1268 : t = OMP_CLAUSE_OPERAND (c, 0);
8584 1268 : if (t == error_mark_node)
8585 : remove = true;
8586 1268 : else if (!type_dependent_expression_p (t)
8587 1268 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8588 : {
8589 0 : error_at (OMP_CLAUSE_LOCATION (c),
8590 : "%qs length expression must be integral",
8591 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8592 0 : remove = true;
8593 : }
8594 : else
8595 : {
8596 1268 : t = mark_rvalue_use (t);
8597 1268 : if (!processing_template_decl)
8598 : {
8599 1219 : t = maybe_constant_value (t);
8600 1219 : if (TREE_CODE (t) != INTEGER_CST
8601 1219 : || tree_int_cst_sgn (t) != 1)
8602 : {
8603 0 : error_at (OMP_CLAUSE_LOCATION (c),
8604 : "%qs length expression must be positive "
8605 : "constant integer expression",
8606 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8607 0 : remove = true;
8608 : }
8609 : }
8610 1268 : OMP_CLAUSE_OPERAND (c, 0) = t;
8611 1268 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
8612 470 : safelen = c;
8613 : }
8614 : break;
8615 :
8616 388 : case OMP_CLAUSE_ASYNC:
8617 388 : t = OMP_CLAUSE_ASYNC_EXPR (c);
8618 388 : if (t == error_mark_node)
8619 : remove = true;
8620 373 : else if (!type_dependent_expression_p (t)
8621 373 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8622 : {
8623 12 : error_at (OMP_CLAUSE_LOCATION (c),
8624 : "%<async%> expression must be integral");
8625 12 : remove = true;
8626 : }
8627 : else
8628 : {
8629 361 : t = mark_rvalue_use (t);
8630 361 : if (!processing_template_decl)
8631 352 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8632 361 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
8633 : }
8634 : break;
8635 :
8636 204 : case OMP_CLAUSE_WAIT:
8637 204 : t = OMP_CLAUSE_WAIT_EXPR (c);
8638 204 : if (t == error_mark_node)
8639 : remove = true;
8640 204 : else if (!processing_template_decl)
8641 196 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8642 204 : OMP_CLAUSE_WAIT_EXPR (c) = t;
8643 204 : break;
8644 :
8645 637 : case OMP_CLAUSE_THREAD_LIMIT:
8646 637 : t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
8647 637 : if (t == error_mark_node)
8648 : remove = true;
8649 637 : else if (!type_dependent_expression_p (t)
8650 637 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8651 : {
8652 0 : error_at (OMP_CLAUSE_LOCATION (c),
8653 : "%<thread_limit%> expression must be integral");
8654 0 : remove = true;
8655 : }
8656 : else
8657 : {
8658 637 : t = mark_rvalue_use (t);
8659 637 : if (!processing_template_decl)
8660 : {
8661 583 : t = maybe_constant_value (t);
8662 583 : if (TREE_CODE (t) == INTEGER_CST
8663 583 : && tree_int_cst_sgn (t) != 1)
8664 : {
8665 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8666 : "%<thread_limit%> value must be positive");
8667 0 : t = integer_one_node;
8668 : }
8669 583 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8670 : }
8671 637 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
8672 : }
8673 : break;
8674 :
8675 770 : case OMP_CLAUSE_DEVICE:
8676 770 : t = OMP_CLAUSE_DEVICE_ID (c);
8677 770 : if (t == error_mark_node)
8678 : remove = true;
8679 770 : else if (!type_dependent_expression_p (t)
8680 770 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8681 : {
8682 6 : error_at (OMP_CLAUSE_LOCATION (c),
8683 : "%<device%> id must be integral");
8684 6 : remove = true;
8685 : }
8686 764 : else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
8687 66 : && TREE_CODE (t) == INTEGER_CST
8688 824 : && !integer_onep (t))
8689 : {
8690 3 : error_at (OMP_CLAUSE_LOCATION (c),
8691 : "the %<device%> clause expression must evaluate to "
8692 : "%<1%>");
8693 3 : remove = true;
8694 : }
8695 : else
8696 : {
8697 761 : t = mark_rvalue_use (t);
8698 761 : if (!processing_template_decl)
8699 750 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8700 761 : OMP_CLAUSE_DEVICE_ID (c) = t;
8701 : }
8702 : break;
8703 :
8704 1836 : case OMP_CLAUSE_DIST_SCHEDULE:
8705 1836 : t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
8706 1836 : if (t == NULL)
8707 : ;
8708 1815 : else if (t == error_mark_node)
8709 : remove = true;
8710 1815 : else if (!type_dependent_expression_p (t)
8711 1815 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8712 : {
8713 0 : error_at (OMP_CLAUSE_LOCATION (c),
8714 : "%<dist_schedule%> chunk size expression must be "
8715 : "integral");
8716 0 : remove = true;
8717 : }
8718 : else
8719 : {
8720 1815 : t = mark_rvalue_use (t);
8721 1815 : if (!processing_template_decl)
8722 1815 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8723 1815 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
8724 : }
8725 : break;
8726 :
8727 807 : case OMP_CLAUSE_ALIGNED:
8728 807 : t = OMP_CLAUSE_DECL (c);
8729 807 : if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
8730 : {
8731 0 : error_at (OMP_CLAUSE_LOCATION (c),
8732 : "%<this%> allowed in OpenMP only in %<declare simd%>"
8733 : " clauses");
8734 0 : remove = true;
8735 0 : break;
8736 : }
8737 807 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8738 : {
8739 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8740 : break;
8741 0 : if (DECL_P (t))
8742 0 : error_at (OMP_CLAUSE_LOCATION (c),
8743 : "%qD is not a variable in %<aligned%> clause", t);
8744 : else
8745 0 : error_at (OMP_CLAUSE_LOCATION (c),
8746 : "%qE is not a variable in %<aligned%> clause", t);
8747 : remove = true;
8748 : }
8749 807 : else if (!type_dependent_expression_p (t)
8750 789 : && !TYPE_PTR_P (TREE_TYPE (t))
8751 111 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
8752 864 : && (!TYPE_REF_P (TREE_TYPE (t))
8753 39 : || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
8754 30 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
8755 : != ARRAY_TYPE))))
8756 : {
8757 33 : error_at (OMP_CLAUSE_LOCATION (c),
8758 : "%qE in %<aligned%> clause is neither a pointer nor "
8759 : "an array nor a reference to pointer or array", t);
8760 33 : remove = true;
8761 : }
8762 774 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8763 : {
8764 0 : error_at (OMP_CLAUSE_LOCATION (c),
8765 : "%qD appears more than once in %<aligned%> clauses",
8766 : t);
8767 0 : remove = true;
8768 : }
8769 : else
8770 774 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8771 807 : t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
8772 807 : if (t == error_mark_node)
8773 : remove = true;
8774 807 : else if (t == NULL_TREE)
8775 : break;
8776 744 : else if (!type_dependent_expression_p (t)
8777 744 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8778 : {
8779 0 : error_at (OMP_CLAUSE_LOCATION (c),
8780 : "%<aligned%> clause alignment expression must "
8781 : "be integral");
8782 0 : remove = true;
8783 : }
8784 : else
8785 : {
8786 744 : t = mark_rvalue_use (t);
8787 744 : if (!processing_template_decl)
8788 : {
8789 690 : t = maybe_constant_value (t);
8790 690 : if (TREE_CODE (t) != INTEGER_CST
8791 690 : || tree_int_cst_sgn (t) != 1)
8792 : {
8793 0 : error_at (OMP_CLAUSE_LOCATION (c),
8794 : "%<aligned%> clause alignment expression must "
8795 : "be positive constant integer expression");
8796 0 : remove = true;
8797 : }
8798 : }
8799 744 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
8800 : }
8801 : break;
8802 :
8803 369 : case OMP_CLAUSE_NONTEMPORAL:
8804 369 : t = OMP_CLAUSE_DECL (c);
8805 369 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8806 : {
8807 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8808 : break;
8809 0 : if (DECL_P (t))
8810 0 : error_at (OMP_CLAUSE_LOCATION (c),
8811 : "%qD is not a variable in %<nontemporal%> clause",
8812 : t);
8813 : else
8814 0 : error_at (OMP_CLAUSE_LOCATION (c),
8815 : "%qE is not a variable in %<nontemporal%> clause",
8816 : t);
8817 : remove = true;
8818 : }
8819 369 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8820 : {
8821 6 : error_at (OMP_CLAUSE_LOCATION (c),
8822 : "%qD appears more than once in %<nontemporal%> "
8823 : "clauses", t);
8824 6 : remove = true;
8825 : }
8826 : else
8827 363 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8828 : break;
8829 :
8830 2585 : case OMP_CLAUSE_ALLOCATE:
8831 2585 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8832 2585 : if (t)
8833 14 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8834 : else
8835 2571 : t = OMP_CLAUSE_DECL (c);
8836 2585 : if (t == current_class_ptr)
8837 : {
8838 0 : error_at (OMP_CLAUSE_LOCATION (c),
8839 : "%<this%> not allowed in %<allocate%> clause");
8840 0 : remove = true;
8841 0 : break;
8842 : }
8843 2585 : if (!VAR_P (t)
8844 558 : && TREE_CODE (t) != PARM_DECL
8845 45 : && TREE_CODE (t) != FIELD_DECL)
8846 : {
8847 3 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8848 : break;
8849 3 : if (DECL_P (t))
8850 3 : error_at (OMP_CLAUSE_LOCATION (c),
8851 : "%qD is not a variable in %<allocate%> clause", t);
8852 : else
8853 0 : error_at (OMP_CLAUSE_LOCATION (c),
8854 : "%qE is not a variable in %<allocate%> clause", t);
8855 : remove = true;
8856 : }
8857 2582 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8858 : {
8859 12 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8860 : "%qD appears more than once in %<allocate%> clauses",
8861 : t);
8862 12 : remove = true;
8863 : }
8864 : else
8865 : {
8866 2570 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8867 2570 : allocate_seen = true;
8868 : }
8869 2585 : tree allocator, align;
8870 2585 : align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
8871 2585 : if (error_operand_p (align))
8872 : {
8873 : remove = true;
8874 : break;
8875 : }
8876 2585 : if (align)
8877 : {
8878 207 : if (!type_dependent_expression_p (align)
8879 207 : && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
8880 : {
8881 4 : error_at (OMP_CLAUSE_LOCATION (c),
8882 : "%<allocate%> clause %<align%> modifier "
8883 : "argument needs to be positive constant "
8884 : "power of two integer expression");
8885 4 : remove = true;
8886 : }
8887 : else
8888 : {
8889 203 : align = mark_rvalue_use (align);
8890 203 : if (!processing_template_decl)
8891 : {
8892 188 : align = maybe_constant_value (align);
8893 188 : if (TREE_CODE (align) != INTEGER_CST
8894 185 : || !tree_fits_uhwi_p (align)
8895 373 : || !integer_pow2p (align))
8896 : {
8897 10 : error_at (OMP_CLAUSE_LOCATION (c),
8898 : "%<allocate%> clause %<align%> modifier "
8899 : "argument needs to be positive constant "
8900 : "power of two integer expression");
8901 10 : remove = true;
8902 : }
8903 : }
8904 : }
8905 207 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
8906 : }
8907 2585 : allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
8908 2585 : if (error_operand_p (allocator))
8909 : {
8910 : remove = true;
8911 : break;
8912 : }
8913 2585 : if (allocator == NULL_TREE)
8914 1537 : goto handle_field_decl;
8915 1048 : tree allocatort;
8916 1048 : allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
8917 1048 : if (!type_dependent_expression_p (allocator)
8918 1048 : && (TREE_CODE (allocatort) != ENUMERAL_TYPE
8919 1029 : || TYPE_NAME (allocatort) == NULL_TREE
8920 1029 : || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
8921 2058 : || (DECL_NAME (TYPE_NAME (allocatort))
8922 1029 : != get_identifier ("omp_allocator_handle_t"))
8923 1029 : || (TYPE_CONTEXT (allocatort)
8924 1029 : != DECL_CONTEXT (global_namespace))))
8925 : {
8926 16 : error_at (OMP_CLAUSE_LOCATION (c),
8927 : "%<allocate%> clause allocator expression has "
8928 : "type %qT rather than %<omp_allocator_handle_t%>",
8929 16 : TREE_TYPE (allocator));
8930 16 : remove = true;
8931 16 : break;
8932 : }
8933 : else
8934 : {
8935 1032 : allocator = mark_rvalue_use (allocator);
8936 1032 : if (!processing_template_decl)
8937 1013 : allocator = maybe_constant_value (allocator);
8938 1032 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
8939 : }
8940 1032 : goto handle_field_decl;
8941 :
8942 654 : case OMP_CLAUSE_DOACROSS:
8943 654 : t = OMP_CLAUSE_DECL (c);
8944 654 : if (t == NULL_TREE)
8945 : break;
8946 298 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
8947 : {
8948 298 : if (cp_finish_omp_clause_doacross_sink (c))
8949 12 : remove = true;
8950 : break;
8951 : }
8952 0 : gcc_unreachable ();
8953 141 : case OMP_CLAUSE_USES_ALLOCATORS:
8954 141 : t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
8955 141 : t = convert_from_reference (t);
8956 141 : if (t == error_mark_node)
8957 : {
8958 : remove = true;
8959 : break;
8960 : }
8961 129 : if (DECL_P (t)
8962 129 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8963 120 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8964 117 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
8965 : {
8966 3 : error_at (OMP_CLAUSE_LOCATION (c),
8967 : "%qE appears more than once in data clauses", t);
8968 3 : remove = true;
8969 : }
8970 126 : else if (DECL_P (t))
8971 117 : bitmap_set_bit (&generic_head, DECL_UID (t));
8972 129 : if (type_dependent_expression_p (t))
8973 : break;
8974 114 : if (TREE_CODE (t) == FIELD_DECL)
8975 : {
8976 0 : sorry_at (OMP_CLAUSE_LOCATION (c), "class member %qE not yet "
8977 : "supported in %<uses_allocators%> clause", t);
8978 0 : remove = true;
8979 0 : break;
8980 : }
8981 114 : if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
8982 219 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
8983 : "omp_allocator_handle_t") != 0)
8984 : {
8985 9 : error_at (OMP_CLAUSE_LOCATION (c),
8986 : "allocator %qE must be of %<omp_allocator_handle_t%> "
8987 : "type", t);
8988 9 : remove = true;
8989 9 : break;
8990 : }
8991 105 : tree init;
8992 105 : if (TREE_CODE (t) == CONST_DECL)
8993 15 : init = DECL_INITIAL(t);
8994 : else
8995 : init = t;
8996 105 : if (!DECL_P (t)
8997 105 : && (init == NULL_TREE
8998 9 : || TREE_CODE (init) != INTEGER_CST
8999 9 : || ((wi::to_widest (init) < 0
9000 9 : || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
9001 3 : && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
9002 3 : || (wi::to_widest (init)
9003 6 : > GOMP_OMPX_PREDEF_ALLOC_MAX)))))
9004 : {
9005 3 : remove = true;
9006 3 : error_at (OMP_CLAUSE_LOCATION (c),
9007 : "allocator %qE must be either a variable or a "
9008 : "predefined allocator", t);
9009 3 : break;
9010 : }
9011 102 : else if (TREE_CODE (t) == CONST_DECL)
9012 : {
9013 : /* omp_null_allocator is ignored and for predefined allocators,
9014 : not special handling is required; thus, remove them removed. */
9015 15 : remove = true;
9016 :
9017 15 : if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
9018 15 : || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
9019 : {
9020 0 : error_at (OMP_CLAUSE_LOCATION (c),
9021 : "modifiers cannot be used with predefined "
9022 : "allocators");
9023 0 : break;
9024 : }
9025 : }
9026 102 : t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
9027 102 : if (t == error_mark_node)
9028 : {
9029 : remove = true;
9030 : break;
9031 : }
9032 99 : if (t != NULL_TREE
9033 18 : && !type_dependent_expression_p (t)
9034 117 : && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
9035 15 : || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9036 24 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9037 : "omp_memspace_handle_t") != 0))
9038 : {
9039 6 : error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
9040 : " constant enum of %<omp_memspace_handle_t%> type", t);
9041 6 : remove = true;
9042 6 : break;
9043 : }
9044 93 : t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
9045 93 : if (t == error_mark_node)
9046 : {
9047 : remove = true;
9048 : break;
9049 : }
9050 90 : if (type_dependent_expression_p (t))
9051 : break;
9052 90 : if (t != NULL_TREE
9053 39 : && t != error_mark_node
9054 39 : && !type_dependent_expression_p (t)
9055 129 : && (!DECL_P (t)
9056 39 : || DECL_EXTERNAL (t)
9057 33 : || TREE_CODE (t) == PARM_DECL))
9058 : {
9059 12 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
9060 : "defined in same scope as the construct on which the "
9061 : "clause appears", t);
9062 12 : remove = true;
9063 : }
9064 90 : if (t != NULL_TREE)
9065 : {
9066 39 : bool type_err = false;
9067 :
9068 39 : if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
9069 33 : || DECL_SIZE (t) == NULL_TREE
9070 69 : || !COMPLETE_TYPE_P (TREE_TYPE (t)))
9071 : type_err = true;
9072 : else
9073 : {
9074 30 : tree elem_t = TREE_TYPE (TREE_TYPE (t));
9075 30 : if (TREE_CODE (elem_t) != RECORD_TYPE
9076 60 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
9077 : "omp_alloctrait_t") != 0
9078 60 : || !TYPE_READONLY (elem_t))
9079 : type_err = true;
9080 : }
9081 27 : if (type_err)
9082 : {
9083 12 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
9084 : "be of %<const omp_alloctrait_t []%> type", t);
9085 12 : remove = true;
9086 : }
9087 27 : else if (TREE_CODE (array_type_nelts_top (TREE_TYPE (t)))
9088 : != INTEGER_CST)
9089 : {
9090 3 : error_at (OMP_CLAUSE_LOCATION (c), "variable length traits "
9091 : "arrays are not supported");
9092 3 : remove = true;
9093 : }
9094 : else
9095 : {
9096 24 : tree cst_val = decl_constant_value (t);
9097 24 : if (cst_val == t)
9098 : {
9099 3 : error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
9100 : "initialized with constants");
9101 3 : remove = true;
9102 : }
9103 : }
9104 : }
9105 90 : if (remove)
9106 : break;
9107 54 : pc = &OMP_CLAUSE_CHAIN (c);
9108 54 : continue;
9109 1805 : case OMP_CLAUSE_DEPEND:
9110 1805 : depend_clause = c;
9111 : /* FALLTHRU */
9112 2171 : case OMP_CLAUSE_AFFINITY:
9113 2171 : t = OMP_CLAUSE_DECL (c);
9114 2171 : if (OMP_ITERATOR_DECL_P (t))
9115 : {
9116 622 : if (TREE_PURPOSE (t) != last_iterators)
9117 524 : last_iterators_remove
9118 524 : = cp_omp_finish_iterators (TREE_PURPOSE (t));
9119 622 : last_iterators = TREE_PURPOSE (t);
9120 622 : t = TREE_VALUE (t);
9121 622 : if (last_iterators_remove)
9122 144 : t = error_mark_node;
9123 : }
9124 : else
9125 : last_iterators = NULL_TREE;
9126 :
9127 2171 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9128 : {
9129 1164 : if (handle_omp_array_sections (c, ort))
9130 : remove = true;
9131 913 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9132 913 : && (OMP_CLAUSE_DEPEND_KIND (c)
9133 : == OMP_CLAUSE_DEPEND_DEPOBJ))
9134 : {
9135 6 : error_at (OMP_CLAUSE_LOCATION (c),
9136 : "%<depend%> clause with %<depobj%> dependence "
9137 : "type on array section");
9138 6 : remove = true;
9139 : }
9140 : break;
9141 : }
9142 1007 : if (t == error_mark_node)
9143 : remove = true;
9144 845 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9145 845 : && t == ridpointers[RID_OMP_ALL_MEMORY])
9146 : {
9147 33 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
9148 33 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
9149 : {
9150 9 : error_at (OMP_CLAUSE_LOCATION (c),
9151 : "%<omp_all_memory%> used with %<depend%> kind "
9152 : "other than %<out%> or %<inout%>");
9153 9 : remove = true;
9154 : }
9155 33 : if (processing_template_decl)
9156 : break;
9157 : }
9158 812 : else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9159 : break;
9160 620 : else if (!lvalue_p (t))
9161 : {
9162 19 : if (DECL_P (t))
9163 24 : error_at (OMP_CLAUSE_LOCATION (c),
9164 : "%qD is not lvalue expression nor array section "
9165 : "in %qs clause", t,
9166 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9167 : else
9168 14 : error_at (OMP_CLAUSE_LOCATION (c),
9169 : "%qE is not lvalue expression nor array section "
9170 : "in %qs clause", t,
9171 7 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9172 : remove = true;
9173 : }
9174 601 : else if (TREE_CODE (t) == COMPONENT_REF
9175 24 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
9176 625 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
9177 : {
9178 8 : error_at (OMP_CLAUSE_LOCATION (c),
9179 : "bit-field %qE in %qs clause", t,
9180 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9181 4 : remove = true;
9182 : }
9183 597 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9184 597 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
9185 : {
9186 130 : if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9187 8 : ? TREE_TYPE (TREE_TYPE (t))
9188 57 : : TREE_TYPE (t)))
9189 : {
9190 12 : error_at (OMP_CLAUSE_LOCATION (c),
9191 : "%qE does not have %<omp_depend_t%> type in "
9192 : "%<depend%> clause with %<depobj%> dependence "
9193 : "type", t);
9194 12 : remove = true;
9195 : }
9196 : }
9197 532 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9198 972 : && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9199 4 : ? TREE_TYPE (TREE_TYPE (t))
9200 436 : : TREE_TYPE (t)))
9201 : {
9202 15 : error_at (OMP_CLAUSE_LOCATION (c),
9203 : "%qE should not have %<omp_depend_t%> type in "
9204 : "%<depend%> clause with dependence type other than "
9205 : "%<depobj%>", t);
9206 15 : remove = true;
9207 : }
9208 64 : if (!remove)
9209 : {
9210 594 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
9211 24 : t = null_pointer_node;
9212 : else
9213 : {
9214 570 : tree addr = cp_build_addr_expr (t, tf_warning_or_error);
9215 570 : if (addr == error_mark_node)
9216 : {
9217 : remove = true;
9218 : break;
9219 : }
9220 570 : t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
9221 : addr, RO_UNARY_STAR,
9222 : tf_warning_or_error);
9223 570 : if (t == error_mark_node)
9224 : {
9225 : remove = true;
9226 : break;
9227 : }
9228 : }
9229 594 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
9230 136 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
9231 730 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
9232 : == TREE_VEC))
9233 136 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
9234 : else
9235 458 : OMP_CLAUSE_DECL (c) = t;
9236 : }
9237 : break;
9238 69 : case OMP_CLAUSE_DETACH:
9239 69 : t = OMP_CLAUSE_DECL (c);
9240 69 : if (detach_seen)
9241 : {
9242 3 : error_at (OMP_CLAUSE_LOCATION (c),
9243 : "too many %qs clauses on a task construct",
9244 : "detach");
9245 3 : remove = true;
9246 3 : break;
9247 : }
9248 66 : else if (error_operand_p (t))
9249 : {
9250 : remove = true;
9251 : break;
9252 : }
9253 : else
9254 : {
9255 63 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
9256 63 : if (!type_dependent_expression_p (t)
9257 63 : && (!INTEGRAL_TYPE_P (type)
9258 : || TREE_CODE (type) != ENUMERAL_TYPE
9259 51 : || TYPE_NAME (type) == NULL_TREE
9260 102 : || (DECL_NAME (TYPE_NAME (type))
9261 51 : != get_identifier ("omp_event_handle_t"))))
9262 : {
9263 6 : error_at (OMP_CLAUSE_LOCATION (c),
9264 : "%<detach%> clause event handle "
9265 : "has type %qT rather than "
9266 : "%<omp_event_handle_t%>",
9267 : type);
9268 6 : remove = true;
9269 : }
9270 63 : detach_seen = c;
9271 63 : cxx_mark_addressable (t);
9272 : }
9273 63 : break;
9274 :
9275 15942 : case OMP_CLAUSE_MAP:
9276 15942 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
9277 190 : goto move_implicit;
9278 15752 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
9279 15752 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
9280 : {
9281 : remove = true;
9282 : break;
9283 : }
9284 : /* FALLTHRU */
9285 18870 : case OMP_CLAUSE_TO:
9286 18870 : case OMP_CLAUSE_FROM:
9287 18870 : if (OMP_CLAUSE_ITERATORS (c)
9288 18870 : && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
9289 : {
9290 97100 : t = error_mark_node;
9291 : break;
9292 : }
9293 : /* FALLTHRU */
9294 19706 : case OMP_CLAUSE__CACHE_:
9295 19706 : {
9296 19706 : using namespace omp_addr_tokenizer;
9297 19706 : auto_vec<omp_addr_token *, 10> addr_tokens;
9298 :
9299 19706 : t = OMP_CLAUSE_DECL (c);
9300 19706 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9301 : {
9302 5875 : grp_start_p = pc;
9303 5875 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9304 :
9305 5875 : if (handle_omp_array_sections (c, ort))
9306 : remove = true;
9307 : else
9308 : {
9309 5109 : t = OMP_CLAUSE_DECL (c);
9310 5109 : if (TREE_CODE (t) != OMP_ARRAY_SECTION
9311 4252 : && !type_dependent_expression_p (t)
9312 9361 : && !omp_mappable_type (TREE_TYPE (t)))
9313 : {
9314 3 : auto_diagnostic_group d;
9315 6 : error_at (OMP_CLAUSE_LOCATION (c),
9316 : "array section does not have mappable type "
9317 : "in %qs clause",
9318 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9319 3 : if (TREE_TYPE (t) != error_mark_node
9320 3 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9321 3 : cxx_incomplete_type_inform (TREE_TYPE (t));
9322 3 : remove = true;
9323 3 : }
9324 6959 : while (TREE_CODE (t) == ARRAY_REF)
9325 1850 : t = TREE_OPERAND (t, 0);
9326 :
9327 5109 : if (type_dependent_expression_p (t))
9328 : break;
9329 :
9330 4635 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9331 :
9332 4635 : if (!ai.map_supported_p ()
9333 4635 : || !omp_parse_expr (addr_tokens, t))
9334 : {
9335 18 : sorry_at (OMP_CLAUSE_LOCATION (c),
9336 : "unsupported map expression %qE",
9337 9 : OMP_CLAUSE_DECL (c));
9338 9 : remove = true;
9339 9 : break;
9340 : }
9341 :
9342 : /* This check is to determine if this will be the only map
9343 : node created for this clause. Otherwise, we'll check
9344 : the following FIRSTPRIVATE_POINTER,
9345 : FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
9346 : iteration(s) of the loop. */
9347 9203 : if (addr_tokens.length () >= 4
9348 1063 : && addr_tokens[0]->type == STRUCTURE_BASE
9349 1057 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
9350 1057 : && addr_tokens[1]->type == ACCESS_METHOD
9351 1057 : && addr_tokens[2]->type == COMPONENT_SELECTOR
9352 977 : && addr_tokens[3]->type == ACCESS_METHOD
9353 5340 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
9354 551 : || (addr_tokens[3]->u.access_kind
9355 : == ACCESS_INDEXED_ARRAY)))
9356 : {
9357 165 : tree rt = addr_tokens[1]->expr;
9358 :
9359 165 : gcc_assert (DECL_P (rt));
9360 :
9361 165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9362 154 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9363 165 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
9364 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
9365 0 : || bitmap_bit_p (&map_firstprivate_head,
9366 0 : DECL_UID (rt))))
9367 : {
9368 : remove = true;
9369 : break;
9370 : }
9371 165 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
9372 : break;
9373 116 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
9374 : {
9375 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9376 0 : error_at (OMP_CLAUSE_LOCATION (c),
9377 : "%qD appears more than once in motion"
9378 : " clauses", rt);
9379 0 : else if (openacc)
9380 0 : error_at (OMP_CLAUSE_LOCATION (c),
9381 : "%qD appears more than once in data"
9382 : " clauses", rt);
9383 : else
9384 0 : error_at (OMP_CLAUSE_LOCATION (c),
9385 : "%qD appears more than once in map"
9386 : " clauses", rt);
9387 : remove = true;
9388 : }
9389 : else
9390 : {
9391 116 : bitmap_set_bit (&map_head, DECL_UID (rt));
9392 116 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
9393 : }
9394 : }
9395 4635 : }
9396 5343 : if (cp_oacc_check_attachments (c))
9397 12 : remove = true;
9398 5343 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9399 4409 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9400 4345 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9401 5441 : && !OMP_CLAUSE_SIZE (c))
9402 : /* In this case, we have a single array element which is a
9403 : pointer, and we already set OMP_CLAUSE_SIZE in
9404 : handle_omp_array_sections above. For attach/detach
9405 : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
9406 : to zero here. */
9407 60 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9408 : break;
9409 : }
9410 13831 : else if (type_dependent_expression_p (t))
9411 : break;
9412 13057 : else if (!omp_parse_expr (addr_tokens, t))
9413 : {
9414 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
9415 : "unsupported map expression %qE",
9416 0 : OMP_CLAUSE_DECL (c));
9417 0 : remove = true;
9418 0 : break;
9419 : }
9420 13057 : if (t == error_mark_node)
9421 : {
9422 : remove = true;
9423 : break;
9424 : }
9425 : /* OpenACC attach / detach clauses must be pointers. */
9426 12963 : if (cp_oacc_check_attachments (c))
9427 : {
9428 : remove = true;
9429 : break;
9430 : }
9431 12939 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9432 9978 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9433 9929 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9434 13013 : && !OMP_CLAUSE_SIZE (c))
9435 : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
9436 : bias) to zero here, so it is not set erroneously to the
9437 : pointer size later on in gimplify.cc. */
9438 66 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9439 :
9440 12939 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9441 :
9442 12939 : if (!ai.check_clause (c))
9443 : {
9444 : remove = true;
9445 : break;
9446 : }
9447 :
9448 12918 : if (!ai.map_supported_p ())
9449 : {
9450 88 : sorry_at (OMP_CLAUSE_LOCATION (c),
9451 : "unsupported map expression %qE",
9452 44 : OMP_CLAUSE_DECL (c));
9453 44 : remove = true;
9454 44 : break;
9455 : }
9456 :
9457 25748 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
9458 : || addr_tokens[0]->type == STRUCTURE_BASE)
9459 : && addr_tokens[1]->type == ACCESS_METHOD);
9460 :
9461 12874 : t = addr_tokens[1]->expr;
9462 :
9463 : /* This is used to prevent cxx_mark_addressable from being called
9464 : on 'this' for expressions like 'this->a', i.e. typical member
9465 : accesses. */
9466 12874 : indir_component_ref_p
9467 25748 : = (addr_tokens[0]->type == STRUCTURE_BASE
9468 12874 : && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
9469 :
9470 12874 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
9471 1 : goto skip_decl_checks;
9472 :
9473 : /* For OpenMP, we can access a struct "t" and "t.d" on the same
9474 : mapping. OpenACC allows multiple fields of the same structure
9475 : to be written. */
9476 12873 : if (addr_tokens[0]->type == STRUCTURE_BASE
9477 12873 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
9478 1197 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
9479 1168 : goto skip_decl_checks;
9480 :
9481 11705 : if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
9482 : {
9483 0 : OMP_CLAUSE_DECL (c)
9484 0 : = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
9485 0 : break;
9486 : }
9487 11705 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9488 : {
9489 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9490 : break;
9491 0 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9492 0 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9493 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
9494 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
9495 0 : || (!openacc && EXPR_P (t))))
9496 : break;
9497 0 : if (DECL_P (t))
9498 0 : error_at (OMP_CLAUSE_LOCATION (c),
9499 : "%qD is not a variable in %qs clause", t,
9500 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9501 : else
9502 0 : error_at (OMP_CLAUSE_LOCATION (c),
9503 : "%qE is not a variable in %qs clause", t,
9504 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9505 : remove = true;
9506 : }
9507 11705 : else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
9508 : {
9509 0 : error_at (OMP_CLAUSE_LOCATION (c),
9510 : "%qD is threadprivate variable in %qs clause", t,
9511 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9512 0 : remove = true;
9513 : }
9514 11705 : else if (!processing_template_decl
9515 11529 : && !TYPE_REF_P (TREE_TYPE (t))
9516 10856 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9517 7945 : || (OMP_CLAUSE_MAP_KIND (c)
9518 : != GOMP_MAP_FIRSTPRIVATE_POINTER))
9519 8898 : && !indir_component_ref_p
9520 8534 : && (t != current_class_ptr
9521 18 : || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9522 6 : || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
9523 20239 : && !cxx_mark_addressable (t))
9524 : remove = true;
9525 11705 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9526 8776 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9527 8776 : || (OMP_CLAUSE_MAP_KIND (c)
9528 : == GOMP_MAP_FIRSTPRIVATE_POINTER)
9529 6818 : || (OMP_CLAUSE_MAP_KIND (c)
9530 : == GOMP_MAP_ATTACH_DETACH)))
9531 9092 : && t == OMP_CLAUSE_DECL (c)
9532 8460 : && !type_dependent_expression_p (t)
9533 28625 : && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
9534 274 : ? TREE_TYPE (TREE_TYPE (t))
9535 8186 : : TREE_TYPE (t)))
9536 : {
9537 42 : auto_diagnostic_group d;
9538 84 : error_at (OMP_CLAUSE_LOCATION (c),
9539 : "%qD does not have a mappable type in %qs clause", t,
9540 42 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9541 42 : if (TREE_TYPE (t) != error_mark_node
9542 42 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9543 39 : cxx_incomplete_type_inform (TREE_TYPE (t));
9544 42 : remove = true;
9545 42 : }
9546 11663 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9547 8740 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
9548 93 : && !type_dependent_expression_p (t)
9549 11756 : && !INDIRECT_TYPE_P (TREE_TYPE (t)))
9550 : {
9551 6 : error_at (OMP_CLAUSE_LOCATION (c),
9552 : "%qD is not a pointer variable", t);
9553 6 : remove = true;
9554 : }
9555 11657 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9556 8734 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9557 12060 : && (bitmap_bit_p (&map_head, DECL_UID (t))
9558 367 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
9559 367 : || bitmap_bit_p (&map_firstprivate_head,
9560 367 : DECL_UID (t))))
9561 : remove = true;
9562 11618 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9563 11618 : && (OMP_CLAUSE_MAP_KIND (c)
9564 : == GOMP_MAP_FIRSTPRIVATE_POINTER))
9565 : {
9566 1952 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
9567 1952 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9568 3901 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
9569 : {
9570 15 : error_at (OMP_CLAUSE_LOCATION (c),
9571 : "%qD appears more than once in data clauses", t);
9572 15 : remove = true;
9573 : }
9574 1937 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9575 12 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9576 1945 : && openacc)
9577 : {
9578 3 : error_at (OMP_CLAUSE_LOCATION (c),
9579 : "%qD appears more than once in data clauses", t);
9580 3 : remove = true;
9581 : }
9582 : else
9583 1934 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9584 : }
9585 9666 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9586 9666 : && (OMP_CLAUSE_MAP_KIND (c)
9587 : == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
9588 115 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9589 9551 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9590 171 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9591 28 : && ort != C_ORT_OMP
9592 9579 : && ort != C_ORT_OMP_EXIT_DATA)
9593 : {
9594 18 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9595 0 : error_at (OMP_CLAUSE_LOCATION (c),
9596 : "%qD appears more than once in motion clauses", t);
9597 18 : else if (openacc)
9598 9 : error_at (OMP_CLAUSE_LOCATION (c),
9599 : "%qD appears more than once in data clauses", t);
9600 : else
9601 9 : error_at (OMP_CLAUSE_LOCATION (c),
9602 : "%qD appears more than once in map clauses", t);
9603 : remove = true;
9604 : }
9605 9533 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
9606 : {
9607 0 : error_at (OMP_CLAUSE_LOCATION (c),
9608 : "%qD appears more than once in data clauses", t);
9609 0 : remove = true;
9610 : }
9611 9533 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9612 9533 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
9613 : {
9614 27 : if (openacc)
9615 0 : error_at (OMP_CLAUSE_LOCATION (c),
9616 : "%qD appears more than once in data clauses", t);
9617 : else
9618 27 : error_at (OMP_CLAUSE_LOCATION (c),
9619 : "%qD appears both in data and map clauses", t);
9620 : remove = true;
9621 : }
9622 9506 : else if (!omp_access_chain_p (addr_tokens, 1))
9623 : {
9624 9426 : bitmap_set_bit (&map_head, DECL_UID (t));
9625 :
9626 9426 : tree decl = OMP_CLAUSE_DECL (c);
9627 9426 : if (t != decl
9628 9426 : && (TREE_CODE (decl) == COMPONENT_REF
9629 162 : || (INDIRECT_REF_P (decl)
9630 162 : && (TREE_CODE (TREE_OPERAND (decl, 0))
9631 : == COMPONENT_REF)
9632 150 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
9633 : 0))))))
9634 1099 : bitmap_set_bit (&map_field_head, DECL_UID (t));
9635 : }
9636 :
9637 4383 : skip_decl_checks:
9638 : /* If we call ai.expand_map_clause in handle_omp_array_sections,
9639 : the containing loop (here) iterates through the new nodes
9640 : created by that expansion. Avoid expanding those again (just
9641 : by checking the node type). */
9642 4383 : if (!remove
9643 12724 : && !processing_template_decl
9644 12551 : && ort != C_ORT_DECLARE_SIMD
9645 12551 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9646 9608 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
9647 7674 : && (OMP_CLAUSE_MAP_KIND (c)
9648 : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
9649 7559 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
9650 7559 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
9651 6565 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
9652 6516 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
9653 : {
9654 9434 : grp_start_p = pc;
9655 9434 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9656 9434 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
9657 : addr_tokens, ort);
9658 9434 : if (nc != error_mark_node)
9659 9434 : c = nc;
9660 : }
9661 19771 : }
9662 12874 : break;
9663 :
9664 596 : case OMP_CLAUSE_ENTER:
9665 596 : case OMP_CLAUSE_LINK:
9666 596 : t = OMP_CLAUSE_DECL (c);
9667 596 : const char *cname;
9668 596 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
9669 596 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
9670 596 : && OMP_CLAUSE_ENTER_TO (c))
9671 : cname = "to";
9672 596 : if (TREE_CODE (t) == FUNCTION_DECL
9673 596 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9674 : ;
9675 379 : else if (!VAR_P (t))
9676 : {
9677 12 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9678 : {
9679 9 : if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
9680 6 : error_at (OMP_CLAUSE_LOCATION (c),
9681 : "template %qE in clause %qs", t, cname);
9682 3 : else if (really_overloaded_fn (t))
9683 3 : error_at (OMP_CLAUSE_LOCATION (c),
9684 : "overloaded function name %qE in clause %qs", t,
9685 : cname);
9686 : else
9687 0 : error_at (OMP_CLAUSE_LOCATION (c),
9688 : "%qE is neither a variable nor a function name "
9689 : "in clause %qs", t, cname);
9690 : }
9691 : else
9692 3 : error_at (OMP_CLAUSE_LOCATION (c),
9693 : "%qE is not a variable in clause %qs", t, cname);
9694 : remove = true;
9695 : }
9696 367 : else if (DECL_THREAD_LOCAL_P (t))
9697 : {
9698 6 : error_at (OMP_CLAUSE_LOCATION (c),
9699 : "%qD is threadprivate variable in %qs clause", t,
9700 : cname);
9701 6 : remove = true;
9702 : }
9703 361 : else if (!omp_mappable_type (TREE_TYPE (t)))
9704 : {
9705 18 : auto_diagnostic_group d;
9706 18 : error_at (OMP_CLAUSE_LOCATION (c),
9707 : "%qD does not have a mappable type in %qs clause", t,
9708 : cname);
9709 18 : if (TREE_TYPE (t) != error_mark_node
9710 18 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9711 18 : cxx_incomplete_type_inform (TREE_TYPE (t));
9712 18 : remove = true;
9713 18 : }
9714 24 : if (remove)
9715 : break;
9716 560 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9717 : {
9718 24 : error_at (OMP_CLAUSE_LOCATION (c),
9719 : "%qE appears more than once on the same "
9720 : "%<declare target%> directive", t);
9721 24 : remove = true;
9722 : }
9723 : else
9724 536 : bitmap_set_bit (&generic_head, DECL_UID (t));
9725 : break;
9726 :
9727 457 : case OMP_CLAUSE_UNIFORM:
9728 457 : t = OMP_CLAUSE_DECL (c);
9729 457 : if (TREE_CODE (t) != PARM_DECL)
9730 : {
9731 0 : if (processing_template_decl)
9732 : break;
9733 0 : if (DECL_P (t))
9734 0 : error_at (OMP_CLAUSE_LOCATION (c),
9735 : "%qD is not an argument in %<uniform%> clause", t);
9736 : else
9737 0 : error_at (OMP_CLAUSE_LOCATION (c),
9738 : "%qE is not an argument in %<uniform%> clause", t);
9739 : remove = true;
9740 : break;
9741 : }
9742 : /* map_head bitmap is used as uniform_head if declare_simd. */
9743 457 : bitmap_set_bit (&map_head, DECL_UID (t));
9744 457 : goto check_dup_generic;
9745 :
9746 165 : case OMP_CLAUSE_GRAINSIZE:
9747 165 : t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
9748 165 : if (t == error_mark_node)
9749 : remove = true;
9750 165 : else if (!type_dependent_expression_p (t)
9751 165 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9752 : {
9753 0 : error_at (OMP_CLAUSE_LOCATION (c),
9754 : "%<grainsize%> expression must be integral");
9755 0 : remove = true;
9756 : }
9757 : else
9758 : {
9759 165 : t = mark_rvalue_use (t);
9760 165 : if (!processing_template_decl)
9761 : {
9762 164 : t = maybe_constant_value (t);
9763 164 : if (TREE_CODE (t) == INTEGER_CST
9764 164 : && tree_int_cst_sgn (t) != 1)
9765 : {
9766 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9767 : "%<grainsize%> value must be positive");
9768 0 : t = integer_one_node;
9769 : }
9770 164 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9771 : }
9772 165 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
9773 : }
9774 : break;
9775 :
9776 276 : case OMP_CLAUSE_PRIORITY:
9777 276 : t = OMP_CLAUSE_PRIORITY_EXPR (c);
9778 276 : if (t == error_mark_node)
9779 : remove = true;
9780 276 : else if (!type_dependent_expression_p (t)
9781 276 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9782 : {
9783 0 : error_at (OMP_CLAUSE_LOCATION (c),
9784 : "%<priority%> expression must be integral");
9785 0 : remove = true;
9786 : }
9787 : else
9788 : {
9789 276 : t = mark_rvalue_use (t);
9790 276 : if (!processing_template_decl)
9791 : {
9792 276 : t = maybe_constant_value (t);
9793 276 : if (TREE_CODE (t) == INTEGER_CST
9794 276 : && tree_int_cst_sgn (t) == -1)
9795 : {
9796 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9797 : "%<priority%> value must be non-negative");
9798 0 : t = integer_one_node;
9799 : }
9800 276 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9801 : }
9802 276 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
9803 : }
9804 : break;
9805 :
9806 228 : case OMP_CLAUSE_HINT:
9807 228 : t = OMP_CLAUSE_HINT_EXPR (c);
9808 228 : if (t == error_mark_node)
9809 : remove = true;
9810 228 : else if (!type_dependent_expression_p (t)
9811 228 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9812 : {
9813 9 : error_at (OMP_CLAUSE_LOCATION (c),
9814 : "%<hint%> expression must be integral");
9815 9 : remove = true;
9816 : }
9817 : else
9818 : {
9819 219 : t = mark_rvalue_use (t);
9820 219 : if (!processing_template_decl)
9821 : {
9822 171 : t = maybe_constant_value (t);
9823 171 : if (TREE_CODE (t) != INTEGER_CST)
9824 : {
9825 16 : error_at (OMP_CLAUSE_LOCATION (c),
9826 : "%<hint%> expression must be constant integer "
9827 : "expression");
9828 16 : remove = true;
9829 : }
9830 : }
9831 219 : OMP_CLAUSE_HINT_EXPR (c) = t;
9832 : }
9833 : break;
9834 :
9835 186 : case OMP_CLAUSE_FILTER:
9836 186 : t = OMP_CLAUSE_FILTER_EXPR (c);
9837 186 : if (t == error_mark_node)
9838 : remove = true;
9839 186 : else if (!type_dependent_expression_p (t)
9840 186 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9841 : {
9842 6 : error_at (OMP_CLAUSE_LOCATION (c),
9843 : "%<filter%> expression must be integral");
9844 6 : remove = true;
9845 : }
9846 : else
9847 : {
9848 180 : t = mark_rvalue_use (t);
9849 180 : if (!processing_template_decl)
9850 : {
9851 177 : t = maybe_constant_value (t);
9852 177 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9853 : }
9854 180 : OMP_CLAUSE_FILTER_EXPR (c) = t;
9855 : }
9856 : break;
9857 :
9858 433 : case OMP_CLAUSE_IS_DEVICE_PTR:
9859 433 : case OMP_CLAUSE_USE_DEVICE_PTR:
9860 433 : field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
9861 433 : t = OMP_CLAUSE_DECL (c);
9862 433 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
9863 329 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9864 433 : if (!type_dependent_expression_p (t))
9865 : {
9866 431 : tree type = TREE_TYPE (t);
9867 431 : if (!TYPE_PTR_P (type)
9868 431 : && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
9869 : {
9870 57 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
9871 57 : && ort == C_ORT_OMP)
9872 : {
9873 3 : error_at (OMP_CLAUSE_LOCATION (c),
9874 : "%qs variable is neither a pointer "
9875 : "nor reference to pointer",
9876 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9877 3 : remove = true;
9878 : }
9879 54 : else if (TREE_CODE (type) != ARRAY_TYPE
9880 54 : && (!TYPE_REF_P (type)
9881 2 : || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
9882 : {
9883 12 : error_at (OMP_CLAUSE_LOCATION (c),
9884 : "%qs variable is neither a pointer, nor an "
9885 : "array nor reference to pointer or array",
9886 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9887 12 : remove = true;
9888 : }
9889 : }
9890 : }
9891 433 : goto check_dup_generic;
9892 :
9893 267 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
9894 267 : t = OMP_CLAUSE_DECL (c);
9895 267 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9896 : {
9897 28 : if (handle_omp_array_sections (c, ort))
9898 : remove = true;
9899 : else
9900 : {
9901 28 : t = OMP_CLAUSE_DECL (c);
9902 30 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
9903 2 : t = TREE_OPERAND (t, 0);
9904 64 : while (INDIRECT_REF_P (t)
9905 64 : || TREE_CODE (t) == ARRAY_REF)
9906 36 : t = TREE_OPERAND (t, 0);
9907 : }
9908 : }
9909 267 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9910 : {
9911 267 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9912 267 : if (!processing_template_decl
9913 267 : && !cxx_mark_addressable (t))
9914 : remove = true;
9915 : }
9916 267 : goto check_dup_generic_t;
9917 :
9918 76 : case OMP_CLAUSE_USE_DEVICE_ADDR:
9919 76 : field_ok = true;
9920 76 : t = OMP_CLAUSE_DECL (c);
9921 76 : if (!processing_template_decl
9922 74 : && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9923 74 : && !TYPE_REF_P (TREE_TYPE (t))
9924 143 : && !cxx_mark_addressable (t))
9925 : remove = true;
9926 76 : goto check_dup_generic;
9927 :
9928 : case OMP_CLAUSE_NOWAIT:
9929 : case OMP_CLAUSE_DEFAULT:
9930 : case OMP_CLAUSE_UNTIED:
9931 : case OMP_CLAUSE_COLLAPSE:
9932 : case OMP_CLAUSE_PARALLEL:
9933 : case OMP_CLAUSE_FOR:
9934 : case OMP_CLAUSE_SECTIONS:
9935 : case OMP_CLAUSE_TASKGROUP:
9936 : case OMP_CLAUSE_PROC_BIND:
9937 : case OMP_CLAUSE_DEVICE_TYPE:
9938 : case OMP_CLAUSE_NOGROUP:
9939 : case OMP_CLAUSE_THREADS:
9940 : case OMP_CLAUSE_SIMD:
9941 : case OMP_CLAUSE_DEFAULTMAP:
9942 : case OMP_CLAUSE_BIND:
9943 : case OMP_CLAUSE_AUTO:
9944 : case OMP_CLAUSE_INDEPENDENT:
9945 : case OMP_CLAUSE_SEQ:
9946 : case OMP_CLAUSE_IF_PRESENT:
9947 : case OMP_CLAUSE_FINALIZE:
9948 : case OMP_CLAUSE_NOHOST:
9949 : case OMP_CLAUSE_INDIRECT:
9950 : break;
9951 :
9952 231 : case OMP_CLAUSE_MERGEABLE:
9953 231 : mergeable_seen = true;
9954 231 : break;
9955 :
9956 322 : case OMP_CLAUSE_TILE:
9957 754 : for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
9958 432 : list = TREE_CHAIN (list))
9959 : {
9960 432 : t = TREE_VALUE (list);
9961 :
9962 432 : if (t == error_mark_node)
9963 : remove = true;
9964 403 : else if (!type_dependent_expression_p (t)
9965 403 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9966 : {
9967 3 : error_at (OMP_CLAUSE_LOCATION (c),
9968 : "%<tile%> argument needs integral type");
9969 3 : remove = true;
9970 : }
9971 : else
9972 : {
9973 400 : t = mark_rvalue_use (t);
9974 400 : if (!processing_template_decl)
9975 : {
9976 : /* Zero is used to indicate '*', we permit you
9977 : to get there via an ICE of value zero. */
9978 385 : t = maybe_constant_value (t);
9979 385 : if (!tree_fits_shwi_p (t)
9980 369 : || tree_to_shwi (t) < 0)
9981 : {
9982 40 : error_at (OMP_CLAUSE_LOCATION (c),
9983 : "%<tile%> argument needs positive "
9984 : "integral constant");
9985 40 : remove = true;
9986 : }
9987 : }
9988 : }
9989 :
9990 : /* Update list item. */
9991 432 : TREE_VALUE (list) = t;
9992 : }
9993 : break;
9994 :
9995 1027 : case OMP_CLAUSE_SIZES:
9996 1027 : for (tree list = OMP_CLAUSE_SIZES_LIST (c);
9997 2688 : !remove && list; list = TREE_CHAIN (list))
9998 : {
9999 1661 : t = TREE_VALUE (list);
10000 :
10001 1661 : if (t == error_mark_node)
10002 0 : t = integer_one_node;
10003 1661 : else if (!type_dependent_expression_p (t)
10004 1661 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10005 : {
10006 8 : error_at (OMP_CLAUSE_LOCATION (c),
10007 : "%<sizes%> argument needs positive integral "
10008 : "constant");
10009 8 : t = integer_one_node;
10010 : }
10011 : else
10012 : {
10013 1653 : t = mark_rvalue_use (t);
10014 1653 : if (!processing_template_decl)
10015 : {
10016 1636 : t = maybe_constant_value (t);
10017 1636 : HOST_WIDE_INT n;
10018 1636 : if (!tree_fits_shwi_p (t)
10019 1632 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
10020 1632 : || (n = tree_to_shwi (t)) <= 0
10021 3240 : || (int)n != n)
10022 : {
10023 32 : error_at (OMP_CLAUSE_LOCATION (c),
10024 : "%<sizes%> argument needs positive "
10025 : "integral constant");
10026 32 : t = integer_one_node;
10027 : }
10028 : }
10029 : }
10030 :
10031 : /* Update list item. */
10032 1661 : TREE_VALUE (list) = t;
10033 : }
10034 : break;
10035 :
10036 630 : case OMP_CLAUSE_ORDERED:
10037 630 : ordered_seen = true;
10038 630 : break;
10039 :
10040 1549 : case OMP_CLAUSE_ORDER:
10041 1549 : if (order_seen)
10042 : remove = true;
10043 : else
10044 : order_seen = true;
10045 : break;
10046 :
10047 638 : case OMP_CLAUSE_INBRANCH:
10048 638 : case OMP_CLAUSE_NOTINBRANCH:
10049 638 : if (branch_seen)
10050 : {
10051 3 : error_at (OMP_CLAUSE_LOCATION (c),
10052 : "%<inbranch%> clause is incompatible with "
10053 : "%<notinbranch%>");
10054 3 : remove = true;
10055 : }
10056 : branch_seen = true;
10057 : break;
10058 :
10059 297 : case OMP_CLAUSE_INCLUSIVE:
10060 297 : case OMP_CLAUSE_EXCLUSIVE:
10061 297 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10062 297 : if (!t)
10063 297 : t = OMP_CLAUSE_DECL (c);
10064 297 : if (t == current_class_ptr)
10065 : {
10066 0 : error_at (OMP_CLAUSE_LOCATION (c),
10067 : "%<this%> allowed in OpenMP only in %<declare simd%>"
10068 : " clauses");
10069 0 : remove = true;
10070 0 : break;
10071 : }
10072 297 : if (!VAR_P (t)
10073 : && TREE_CODE (t) != PARM_DECL
10074 : && TREE_CODE (t) != FIELD_DECL)
10075 : {
10076 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
10077 : break;
10078 0 : if (DECL_P (t))
10079 0 : error_at (OMP_CLAUSE_LOCATION (c),
10080 : "%qD is not a variable in clause %qs", t,
10081 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10082 : else
10083 0 : error_at (OMP_CLAUSE_LOCATION (c),
10084 : "%qE is not a variable in clause %qs", t,
10085 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10086 : remove = true;
10087 : }
10088 : break;
10089 :
10090 : case OMP_CLAUSE_FULL:
10091 : break;
10092 :
10093 470 : case OMP_CLAUSE_PARTIAL:
10094 470 : partial_seen = true;
10095 470 : t = OMP_CLAUSE_PARTIAL_EXPR (c);
10096 470 : if (!t)
10097 : break;
10098 :
10099 313 : if (t == error_mark_node)
10100 : t = NULL_TREE;
10101 313 : else if (!type_dependent_expression_p (t)
10102 313 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10103 : {
10104 3 : error_at (OMP_CLAUSE_LOCATION (c),
10105 : "%<partial%> argument needs positive constant "
10106 : "integer expression");
10107 3 : t = NULL_TREE;
10108 : }
10109 : else
10110 : {
10111 310 : t = mark_rvalue_use (t);
10112 310 : if (!processing_template_decl)
10113 : {
10114 292 : t = maybe_constant_value (t);
10115 :
10116 292 : HOST_WIDE_INT n;
10117 584 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
10118 292 : || !tree_fits_shwi_p (t)
10119 286 : || (n = tree_to_shwi (t)) <= 0
10120 560 : || (int)n != n)
10121 : {
10122 24 : error_at (OMP_CLAUSE_LOCATION (c),
10123 : "%<partial%> argument needs positive "
10124 : "constant integer expression");
10125 24 : t = NULL_TREE;
10126 : }
10127 : }
10128 : }
10129 :
10130 313 : OMP_CLAUSE_PARTIAL_EXPR (c) = t;
10131 313 : break;
10132 549 : case OMP_CLAUSE_INIT:
10133 549 : init_seen = true;
10134 549 : OMP_CLAUSE_INIT_PREFER_TYPE (c)
10135 549 : = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
10136 549 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
10137 271 : init_no_targetsync_clause = c;
10138 : /* FALLTHRU */
10139 844 : case OMP_CLAUSE_DESTROY:
10140 844 : case OMP_CLAUSE_USE:
10141 844 : init_use_destroy_seen = true;
10142 844 : t = OMP_CLAUSE_DECL (c);
10143 844 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
10144 : {
10145 9 : error_at (OMP_CLAUSE_LOCATION (c),
10146 : "%qD appears more than once in action clauses", t);
10147 9 : remove = true;
10148 9 : break;
10149 : }
10150 835 : bitmap_set_bit (&generic_head, DECL_UID (t));
10151 : /* FALLTHRU */
10152 1099 : case OMP_CLAUSE_INTEROP:
10153 1099 : if (!processing_template_decl)
10154 : {
10155 1003 : if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
10156 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) && */
10157 1003 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
10158 : {
10159 126 : error_at (OMP_CLAUSE_LOCATION (c),
10160 : "%qD must be of %<omp_interop_t%>",
10161 63 : OMP_CLAUSE_DECL (c));
10162 63 : remove = true;
10163 : }
10164 940 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
10165 481 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
10166 1058 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
10167 : {
10168 36 : error_at (OMP_CLAUSE_LOCATION (c),
10169 18 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
10170 18 : remove = true;
10171 : }
10172 : }
10173 1099 : pc = &OMP_CLAUSE_CHAIN (c);
10174 1099 : break;
10175 0 : default:
10176 0 : gcc_unreachable ();
10177 54 : }
10178 :
10179 97100 : if (remove)
10180 : {
10181 2601 : if (grp_start_p)
10182 : {
10183 : /* If we found a clause to remove, we want to remove the whole
10184 : expanded group, otherwise gimplify
10185 : (omp_resolve_clause_dependencies) can get confused. */
10186 820 : *grp_start_p = grp_sentinel;
10187 820 : pc = grp_start_p;
10188 820 : grp_start_p = NULL;
10189 : }
10190 : else
10191 1781 : *pc = OMP_CLAUSE_CHAIN (c);
10192 : }
10193 : else
10194 94499 : pc = &OMP_CLAUSE_CHAIN (c);
10195 : }
10196 :
10197 62516 : if (grp_start_p
10198 62516 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
10199 140 : for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
10200 86 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
10201 :
10202 62516 : if (reduction_seen < 0 && (ordered_seen || schedule_seen))
10203 62516 : reduction_seen = -2;
10204 :
10205 157972 : for (pc = &clauses, c = clauses; c ; c = *pc)
10206 : {
10207 95456 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
10208 95456 : bool remove = false;
10209 95456 : bool need_complete_type = false;
10210 95456 : bool need_default_ctor = false;
10211 95456 : bool need_copy_ctor = false;
10212 95456 : bool need_copy_assignment = false;
10213 95456 : bool need_implicitly_determined = false;
10214 95456 : bool need_dtor = false;
10215 95456 : tree type, inner_type;
10216 :
10217 95456 : switch (c_kind)
10218 : {
10219 : case OMP_CLAUSE_SHARED:
10220 : need_implicitly_determined = true;
10221 : break;
10222 2540 : case OMP_CLAUSE_PRIVATE:
10223 2540 : need_complete_type = true;
10224 2540 : need_default_ctor = true;
10225 2540 : need_dtor = true;
10226 2540 : need_implicitly_determined = true;
10227 2540 : break;
10228 3156 : case OMP_CLAUSE_FIRSTPRIVATE:
10229 3156 : need_complete_type = true;
10230 3156 : need_copy_ctor = true;
10231 3156 : need_dtor = true;
10232 3156 : need_implicitly_determined = true;
10233 3156 : break;
10234 2763 : case OMP_CLAUSE_LASTPRIVATE:
10235 2763 : need_complete_type = true;
10236 2763 : need_copy_assignment = true;
10237 2763 : need_implicitly_determined = true;
10238 2763 : break;
10239 7286 : case OMP_CLAUSE_REDUCTION:
10240 7286 : if (reduction_seen == -2)
10241 27 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
10242 7286 : if (OMP_CLAUSE_REDUCTION_INSCAN (c))
10243 421 : need_copy_assignment = true;
10244 : need_implicitly_determined = true;
10245 : break;
10246 : case OMP_CLAUSE_IN_REDUCTION:
10247 : case OMP_CLAUSE_TASK_REDUCTION:
10248 : case OMP_CLAUSE_INCLUSIVE:
10249 : case OMP_CLAUSE_EXCLUSIVE:
10250 : need_implicitly_determined = true;
10251 : break;
10252 1550 : case OMP_CLAUSE_LINEAR:
10253 1550 : if (ort != C_ORT_OMP_DECLARE_SIMD)
10254 : need_implicitly_determined = true;
10255 679 : else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
10256 721 : && !bitmap_bit_p (&map_head,
10257 42 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
10258 : {
10259 6 : error_at (OMP_CLAUSE_LOCATION (c),
10260 : "%<linear%> clause step is a parameter %qD not "
10261 : "specified in %<uniform%> clause",
10262 6 : OMP_CLAUSE_LINEAR_STEP (c));
10263 6 : *pc = OMP_CLAUSE_CHAIN (c);
10264 73930 : continue;
10265 : }
10266 : break;
10267 : case OMP_CLAUSE_COPYPRIVATE:
10268 366 : need_copy_assignment = true;
10269 : break;
10270 : case OMP_CLAUSE_COPYIN:
10271 366 : need_copy_assignment = true;
10272 : break;
10273 798 : case OMP_CLAUSE_SIMDLEN:
10274 798 : if (safelen
10275 345 : && !processing_template_decl
10276 1143 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
10277 345 : OMP_CLAUSE_SIMDLEN_EXPR (c)))
10278 : {
10279 0 : error_at (OMP_CLAUSE_LOCATION (c),
10280 : "%<simdlen%> clause value is bigger than "
10281 : "%<safelen%> clause value");
10282 0 : OMP_CLAUSE_SIMDLEN_EXPR (c)
10283 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
10284 : }
10285 798 : pc = &OMP_CLAUSE_CHAIN (c);
10286 798 : continue;
10287 3853 : case OMP_CLAUSE_SCHEDULE:
10288 3853 : if (ordered_seen
10289 3853 : && (OMP_CLAUSE_SCHEDULE_KIND (c)
10290 : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
10291 : {
10292 21 : error_at (OMP_CLAUSE_LOCATION (c),
10293 : "%<nonmonotonic%> schedule modifier specified "
10294 : "together with %<ordered%> clause");
10295 42 : OMP_CLAUSE_SCHEDULE_KIND (c)
10296 21 : = (enum omp_clause_schedule_kind)
10297 21 : (OMP_CLAUSE_SCHEDULE_KIND (c)
10298 : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
10299 : }
10300 3853 : if (reduction_seen == -2)
10301 9 : error_at (OMP_CLAUSE_LOCATION (c),
10302 : "%qs clause specified together with %<inscan%> "
10303 : "%<reduction%> clause", "schedule");
10304 3853 : pc = &OMP_CLAUSE_CHAIN (c);
10305 3853 : continue;
10306 51 : case OMP_CLAUSE_NOGROUP:
10307 51 : if (reduction_seen)
10308 : {
10309 3 : error_at (OMP_CLAUSE_LOCATION (c),
10310 : "%<nogroup%> clause must not be used together with "
10311 : "%<reduction%> clause");
10312 3 : *pc = OMP_CLAUSE_CHAIN (c);
10313 3 : continue;
10314 : }
10315 48 : pc = &OMP_CLAUSE_CHAIN (c);
10316 48 : continue;
10317 165 : case OMP_CLAUSE_GRAINSIZE:
10318 165 : if (num_tasks_seen)
10319 : {
10320 6 : error_at (OMP_CLAUSE_LOCATION (c),
10321 : "%<grainsize%> clause must not be used together with "
10322 : "%<num_tasks%> clause");
10323 6 : *pc = OMP_CLAUSE_CHAIN (c);
10324 6 : continue;
10325 : }
10326 159 : pc = &OMP_CLAUSE_CHAIN (c);
10327 159 : continue;
10328 630 : case OMP_CLAUSE_ORDERED:
10329 630 : if (reduction_seen == -2)
10330 6 : error_at (OMP_CLAUSE_LOCATION (c),
10331 : "%qs clause specified together with %<inscan%> "
10332 : "%<reduction%> clause", "ordered");
10333 630 : pc = &OMP_CLAUSE_CHAIN (c);
10334 630 : continue;
10335 1525 : case OMP_CLAUSE_ORDER:
10336 1525 : if (ordered_seen)
10337 : {
10338 12 : error_at (OMP_CLAUSE_LOCATION (c),
10339 : "%<order%> clause must not be used together "
10340 : "with %<ordered%> clause");
10341 12 : *pc = OMP_CLAUSE_CHAIN (c);
10342 12 : continue;
10343 : }
10344 1513 : pc = &OMP_CLAUSE_CHAIN (c);
10345 1513 : continue;
10346 57 : case OMP_CLAUSE_DETACH:
10347 57 : if (mergeable_seen)
10348 : {
10349 6 : error_at (OMP_CLAUSE_LOCATION (c),
10350 : "%<detach%> clause must not be used together with "
10351 : "%<mergeable%> clause");
10352 6 : *pc = OMP_CLAUSE_CHAIN (c);
10353 6 : continue;
10354 : }
10355 51 : pc = &OMP_CLAUSE_CHAIN (c);
10356 51 : continue;
10357 15650 : case OMP_CLAUSE_MAP:
10358 15650 : if (target_in_reduction_seen && !processing_template_decl)
10359 : {
10360 684 : t = OMP_CLAUSE_DECL (c);
10361 684 : while (handled_component_p (t)
10362 : || INDIRECT_REF_P (t)
10363 : || TREE_CODE (t) == ADDR_EXPR
10364 : || TREE_CODE (t) == MEM_REF
10365 804 : || TREE_CODE (t) == NON_LVALUE_EXPR)
10366 120 : t = TREE_OPERAND (t, 0);
10367 684 : if (DECL_P (t)
10368 684 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
10369 342 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
10370 : }
10371 15650 : pc = &OMP_CLAUSE_CHAIN (c);
10372 15650 : continue;
10373 225 : case OMP_CLAUSE_FULL:
10374 225 : if (partial_seen)
10375 : {
10376 12 : error_at (OMP_CLAUSE_LOCATION (c),
10377 : "%<full%> clause must not be used together "
10378 : "with %<partial%> clause");
10379 12 : *pc = OMP_CLAUSE_CHAIN (c);
10380 12 : continue;
10381 : }
10382 213 : pc = &OMP_CLAUSE_CHAIN (c);
10383 213 : continue;
10384 6894 : case OMP_CLAUSE_NOWAIT:
10385 6894 : if (copyprivate_seen)
10386 : {
10387 6 : error_at (OMP_CLAUSE_LOCATION (c),
10388 : "%<nowait%> clause must not be used together "
10389 : "with %<copyprivate%> clause");
10390 6 : *pc = OMP_CLAUSE_CHAIN (c);
10391 6 : continue;
10392 : }
10393 : /* FALLTHRU */
10394 50326 : default:
10395 50326 : pc = &OMP_CLAUSE_CHAIN (c);
10396 50326 : continue;
10397 : }
10398 :
10399 22164 : t = OMP_CLAUSE_DECL (c);
10400 22164 : switch (c_kind)
10401 : {
10402 2763 : case OMP_CLAUSE_LASTPRIVATE:
10403 2763 : if (DECL_P (t)
10404 2763 : && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
10405 : {
10406 2666 : need_default_ctor = true;
10407 2666 : need_dtor = true;
10408 : }
10409 : break;
10410 :
10411 9425 : case OMP_CLAUSE_REDUCTION:
10412 9425 : case OMP_CLAUSE_IN_REDUCTION:
10413 9425 : case OMP_CLAUSE_TASK_REDUCTION:
10414 9425 : if (allocate_seen)
10415 : {
10416 1561 : if (TREE_CODE (t) == MEM_REF)
10417 : {
10418 162 : t = TREE_OPERAND (t, 0);
10419 162 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
10420 0 : t = TREE_OPERAND (t, 0);
10421 162 : if (TREE_CODE (t) == ADDR_EXPR
10422 120 : || INDIRECT_REF_P (t))
10423 80 : t = TREE_OPERAND (t, 0);
10424 162 : if (DECL_P (t))
10425 162 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10426 : }
10427 1399 : else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10428 : {
10429 192 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10430 96 : t = TREE_OPERAND (t, 0);
10431 96 : if (DECL_P (t))
10432 96 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10433 96 : t = OMP_CLAUSE_DECL (c);
10434 : }
10435 1303 : else if (DECL_P (t))
10436 1303 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10437 1561 : t = OMP_CLAUSE_DECL (c);
10438 : }
10439 9425 : if (processing_template_decl
10440 863 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10441 : break;
10442 8855 : if (finish_omp_reduction_clause (c, &need_default_ctor,
10443 : &need_dtor))
10444 : remove = true;
10445 : else
10446 8771 : t = OMP_CLAUSE_DECL (c);
10447 : break;
10448 :
10449 274 : case OMP_CLAUSE_COPYIN:
10450 274 : if (processing_template_decl
10451 0 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10452 : break;
10453 274 : if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
10454 : {
10455 15 : error_at (OMP_CLAUSE_LOCATION (c),
10456 : "%qE must be %<threadprivate%> for %<copyin%>", t);
10457 15 : remove = true;
10458 : }
10459 : break;
10460 :
10461 : default:
10462 : break;
10463 : }
10464 :
10465 22164 : if (processing_template_decl
10466 1544 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10467 : {
10468 632 : pc = &OMP_CLAUSE_CHAIN (c);
10469 632 : continue;
10470 : }
10471 :
10472 21532 : if (need_complete_type || need_copy_assignment)
10473 : {
10474 9190 : t = require_complete_type (t);
10475 9190 : if (t == error_mark_node)
10476 : remove = true;
10477 9166 : else if (!processing_template_decl
10478 8783 : && TYPE_REF_P (TREE_TYPE (t))
10479 9722 : && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
10480 : remove = true;
10481 : }
10482 21532 : if (need_implicitly_determined)
10483 : {
10484 20494 : const char *share_name = NULL;
10485 :
10486 20494 : if (allocate_seen
10487 4993 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10488 24608 : && DECL_P (t))
10489 3904 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10490 :
10491 20494 : if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
10492 : share_name = "threadprivate";
10493 20452 : else switch (cxx_omp_predetermined_sharing_1 (t))
10494 : {
10495 : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
10496 : break;
10497 47 : case OMP_CLAUSE_DEFAULT_SHARED:
10498 47 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10499 30 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
10500 64 : && c_omp_predefined_variable (t))
10501 : /* The __func__ variable and similar function-local predefined
10502 : variables may be listed in a shared or firstprivate
10503 : clause. */
10504 : break;
10505 31 : if (VAR_P (t)
10506 31 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10507 9 : && TREE_STATIC (t)
10508 40 : && cxx_omp_const_qual_no_mutable (t))
10509 : {
10510 6 : tree ctx = CP_DECL_CONTEXT (t);
10511 : /* const qualified static data members without mutable
10512 : member may be specified in firstprivate clause. */
10513 6 : if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
10514 : break;
10515 : }
10516 : share_name = "shared";
10517 : break;
10518 : case OMP_CLAUSE_DEFAULT_PRIVATE:
10519 : share_name = "private";
10520 : break;
10521 0 : default:
10522 0 : gcc_unreachable ();
10523 : }
10524 : if (share_name)
10525 : {
10526 67 : error_at (OMP_CLAUSE_LOCATION (c),
10527 : "%qE is predetermined %qs for %qs",
10528 : omp_clause_printable_decl (t), share_name,
10529 67 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10530 67 : remove = true;
10531 : }
10532 20427 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10533 18368 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
10534 35668 : && cxx_omp_const_qual_no_mutable (t))
10535 : {
10536 126 : error_at (OMP_CLAUSE_LOCATION (c),
10537 : "%<const%> qualified %qE without %<mutable%> member "
10538 : "may appear only in %<shared%> or %<firstprivate%> "
10539 : "clauses", omp_clause_printable_decl (t));
10540 63 : remove = true;
10541 : }
10542 : }
10543 :
10544 21532 : if (detach_seen
10545 16 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10546 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
10547 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10548 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
10549 21548 : && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
10550 : {
10551 6 : error_at (OMP_CLAUSE_LOCATION (c),
10552 : "the event handle of a %<detach%> clause "
10553 : "should not be in a data-sharing clause");
10554 6 : remove = true;
10555 : }
10556 :
10557 : /* We're interested in the base element, not arrays. */
10558 21532 : inner_type = type = TREE_TYPE (t);
10559 21532 : if ((need_complete_type
10560 : || need_copy_assignment
10561 12342 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
10562 5708 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
10563 4235 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
10564 29966 : && TYPE_REF_P (inner_type))
10565 878 : inner_type = TREE_TYPE (inner_type);
10566 24113 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
10567 2581 : inner_type = TREE_TYPE (inner_type);
10568 :
10569 : /* Check for special function availability by building a call to one.
10570 : Save the results, because later we won't be in the right context
10571 : for making these queries. */
10572 2387 : if (CLASS_TYPE_P (inner_type)
10573 2387 : && COMPLETE_TYPE_P (inner_type)
10574 2318 : && (need_default_ctor || need_copy_ctor
10575 1081 : || need_copy_assignment || need_dtor)
10576 1994 : && !type_dependent_expression_p (t)
10577 23526 : && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
10578 : need_copy_ctor, need_copy_assignment,
10579 : need_dtor))
10580 : remove = true;
10581 :
10582 21532 : if (!remove
10583 21532 : && c_kind == OMP_CLAUSE_SHARED
10584 2056 : && processing_template_decl)
10585 : {
10586 125 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10587 125 : if (t)
10588 5 : OMP_CLAUSE_DECL (c) = t;
10589 : }
10590 :
10591 21532 : if (remove)
10592 292 : *pc = OMP_CLAUSE_CHAIN (c);
10593 : else
10594 21240 : pc = &OMP_CLAUSE_CHAIN (c);
10595 : }
10596 :
10597 62516 : if (allocate_seen)
10598 16828 : for (pc = &clauses, c = clauses; c ; c = *pc)
10599 : {
10600 14544 : bool remove = false;
10601 14544 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
10602 2540 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
10603 2143 : && DECL_P (OMP_CLAUSE_DECL (c))
10604 16687 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
10605 : {
10606 15 : error_at (OMP_CLAUSE_LOCATION (c),
10607 : "%qD specified in %<allocate%> clause but not in "
10608 15 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
10609 15 : remove = true;
10610 : }
10611 14544 : if (remove)
10612 15 : *pc = OMP_CLAUSE_CHAIN (c);
10613 : else
10614 14529 : pc = &OMP_CLAUSE_CHAIN (c);
10615 : }
10616 :
10617 62516 : if (ort == C_ORT_OMP_INTEROP
10618 62516 : && depend_clause
10619 60 : && (!init_use_destroy_seen
10620 57 : || (init_seen && init_no_targetsync_clause)))
10621 : {
10622 9 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
10623 : "%<depend%> clause requires action clauses with "
10624 : "%<targetsync%> interop-type");
10625 9 : if (init_no_targetsync_clause)
10626 6 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
10627 : "%<init%> clause lacks the %<targetsync%> modifier");
10628 : }
10629 :
10630 62516 : bitmap_obstack_release (NULL);
10631 62516 : return clauses;
10632 : }
10633 :
10634 : /* Start processing OpenMP clauses that can include any
10635 : privatization clauses for non-static data members. */
10636 :
10637 : tree
10638 48381 : push_omp_privatization_clauses (bool ignore_next)
10639 : {
10640 48381 : if (omp_private_member_ignore_next)
10641 : {
10642 656 : omp_private_member_ignore_next = ignore_next;
10643 656 : return NULL_TREE;
10644 : }
10645 47725 : omp_private_member_ignore_next = ignore_next;
10646 47725 : if (omp_private_member_map)
10647 24 : omp_private_member_vec.safe_push (error_mark_node);
10648 47725 : return push_stmt_list ();
10649 : }
10650 :
10651 : /* Revert remapping of any non-static data members since
10652 : the last push_omp_privatization_clauses () call. */
10653 :
10654 : void
10655 48375 : pop_omp_privatization_clauses (tree stmt)
10656 : {
10657 48375 : if (stmt == NULL_TREE)
10658 : return;
10659 47719 : stmt = pop_stmt_list (stmt);
10660 47719 : if (omp_private_member_map)
10661 : {
10662 1280 : while (!omp_private_member_vec.is_empty ())
10663 : {
10664 850 : tree t = omp_private_member_vec.pop ();
10665 850 : if (t == error_mark_node)
10666 : {
10667 24 : add_stmt (stmt);
10668 24 : return;
10669 : }
10670 826 : bool no_decl_expr = t == integer_zero_node;
10671 826 : if (no_decl_expr)
10672 136 : t = omp_private_member_vec.pop ();
10673 826 : tree *v = omp_private_member_map->get (t);
10674 826 : gcc_assert (v);
10675 826 : if (!no_decl_expr)
10676 690 : add_decl_expr (*v);
10677 826 : omp_private_member_map->remove (t);
10678 : }
10679 860 : delete omp_private_member_map;
10680 430 : omp_private_member_map = NULL;
10681 : }
10682 47695 : add_stmt (stmt);
10683 : }
10684 :
10685 : /* Remember OpenMP privatization clauses mapping and clear it.
10686 : Used for lambdas. */
10687 :
10688 : void
10689 15119699 : save_omp_privatization_clauses (vec<tree> &save)
10690 : {
10691 15119699 : save = vNULL;
10692 15119699 : if (omp_private_member_ignore_next)
10693 2 : save.safe_push (integer_one_node);
10694 15119699 : omp_private_member_ignore_next = false;
10695 15119699 : if (!omp_private_member_map)
10696 : return;
10697 :
10698 0 : while (!omp_private_member_vec.is_empty ())
10699 : {
10700 0 : tree t = omp_private_member_vec.pop ();
10701 0 : if (t == error_mark_node)
10702 : {
10703 0 : save.safe_push (t);
10704 0 : continue;
10705 : }
10706 0 : tree n = t;
10707 0 : if (t == integer_zero_node)
10708 0 : t = omp_private_member_vec.pop ();
10709 0 : tree *v = omp_private_member_map->get (t);
10710 0 : gcc_assert (v);
10711 0 : save.safe_push (*v);
10712 0 : save.safe_push (t);
10713 0 : if (n != t)
10714 0 : save.safe_push (n);
10715 : }
10716 0 : delete omp_private_member_map;
10717 0 : omp_private_member_map = NULL;
10718 : }
10719 :
10720 : /* Restore OpenMP privatization clauses mapping saved by the
10721 : above function. */
10722 :
10723 : void
10724 15119699 : restore_omp_privatization_clauses (vec<tree> &save)
10725 : {
10726 15119699 : gcc_assert (omp_private_member_vec.is_empty ());
10727 15119699 : omp_private_member_ignore_next = false;
10728 15119699 : if (save.is_empty ())
10729 : return;
10730 4 : if (save.length () == 1 && save[0] == integer_one_node)
10731 : {
10732 2 : omp_private_member_ignore_next = true;
10733 2 : save.release ();
10734 2 : return;
10735 : }
10736 :
10737 0 : omp_private_member_map = new hash_map <tree, tree>;
10738 0 : while (!save.is_empty ())
10739 : {
10740 0 : tree t = save.pop ();
10741 0 : tree n = t;
10742 0 : if (t != error_mark_node)
10743 : {
10744 0 : if (t == integer_one_node)
10745 : {
10746 0 : omp_private_member_ignore_next = true;
10747 0 : gcc_assert (save.is_empty ());
10748 0 : break;
10749 : }
10750 0 : if (t == integer_zero_node)
10751 0 : t = save.pop ();
10752 0 : tree &v = omp_private_member_map->get_or_insert (t);
10753 0 : v = save.pop ();
10754 : }
10755 0 : omp_private_member_vec.safe_push (t);
10756 0 : if (n != t)
10757 0 : omp_private_member_vec.safe_push (n);
10758 : }
10759 0 : save.release ();
10760 : }
10761 :
10762 : /* For all variables in the tree_list VARS, mark them as thread local. */
10763 :
10764 : void
10765 238 : finish_omp_threadprivate (tree vars)
10766 : {
10767 238 : tree t;
10768 :
10769 : /* Mark every variable in VARS to be assigned thread local storage. */
10770 509 : for (t = vars; t; t = TREE_CHAIN (t))
10771 : {
10772 271 : tree v = TREE_PURPOSE (t);
10773 271 : location_t loc = EXPR_LOCATION (TREE_VALUE (t));
10774 :
10775 271 : if (error_operand_p (v))
10776 : ;
10777 271 : else if (!VAR_P (v))
10778 6 : error_at (loc, "%<threadprivate%> %qD is not file, namespace "
10779 : "or block scope variable", v);
10780 : /* If V had already been marked threadprivate, it doesn't matter
10781 : whether it had been used prior to this point. */
10782 265 : else if (TREE_USED (v)
10783 265 : && (DECL_LANG_SPECIFIC (v) == NULL
10784 3 : || !CP_DECL_THREADPRIVATE_P (v)))
10785 6 : error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10786 259 : else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10787 6 : error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10788 253 : else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
10789 3 : error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10790 201 : else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
10791 273 : && CP_DECL_CONTEXT (v) != current_class_type)
10792 6 : error_at (loc, "%<threadprivate%> %qE directive not "
10793 6 : "in %qT definition", v, CP_DECL_CONTEXT (v));
10794 : else
10795 : {
10796 : /* Allocate a LANG_SPECIFIC structure for V, if needed. */
10797 244 : if (DECL_LANG_SPECIFIC (v) == NULL)
10798 200 : retrofit_lang_decl (v);
10799 :
10800 244 : if (! CP_DECL_THREAD_LOCAL_P (v))
10801 : {
10802 244 : CP_DECL_THREAD_LOCAL_P (v) = true;
10803 244 : set_decl_tls_model (v, decl_default_tls_model (v));
10804 : /* If rtl has been already set for this var, call
10805 : make_decl_rtl once again, so that encode_section_info
10806 : has a chance to look at the new decl flags. */
10807 244 : if (DECL_RTL_SET_P (v))
10808 0 : make_decl_rtl (v);
10809 : }
10810 244 : CP_DECL_THREADPRIVATE_P (v) = 1;
10811 : }
10812 : }
10813 238 : }
10814 :
10815 : /* Build an OpenMP structured block. */
10816 :
10817 : tree
10818 63943 : begin_omp_structured_block (void)
10819 : {
10820 63943 : return do_pushlevel (sk_omp);
10821 : }
10822 :
10823 : tree
10824 63922 : finish_omp_structured_block (tree block)
10825 : {
10826 63922 : return do_poplevel (block);
10827 : }
10828 :
10829 : /* Similarly, except force the retention of the BLOCK. */
10830 :
10831 : tree
10832 14797 : begin_omp_parallel (void)
10833 : {
10834 14797 : keep_next_level (true);
10835 14797 : return begin_omp_structured_block ();
10836 : }
10837 :
10838 : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
10839 : statement. */
10840 :
10841 : tree
10842 768 : finish_oacc_data (tree clauses, tree block)
10843 : {
10844 768 : tree stmt;
10845 :
10846 768 : block = finish_omp_structured_block (block);
10847 :
10848 768 : stmt = make_node (OACC_DATA);
10849 768 : TREE_TYPE (stmt) = void_type_node;
10850 768 : OACC_DATA_CLAUSES (stmt) = clauses;
10851 768 : OACC_DATA_BODY (stmt) = block;
10852 :
10853 768 : return add_stmt (stmt);
10854 : }
10855 :
10856 : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
10857 : statement. */
10858 :
10859 : tree
10860 55 : finish_oacc_host_data (tree clauses, tree block)
10861 : {
10862 55 : tree stmt;
10863 :
10864 55 : block = finish_omp_structured_block (block);
10865 :
10866 55 : stmt = make_node (OACC_HOST_DATA);
10867 55 : TREE_TYPE (stmt) = void_type_node;
10868 55 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
10869 55 : OACC_HOST_DATA_BODY (stmt) = block;
10870 :
10871 55 : return add_stmt (stmt);
10872 : }
10873 :
10874 : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
10875 : statement. */
10876 :
10877 : tree
10878 4653 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
10879 : {
10880 4653 : body = finish_omp_structured_block (body);
10881 :
10882 4653 : tree stmt = make_node (code);
10883 4653 : TREE_TYPE (stmt) = void_type_node;
10884 4653 : OMP_BODY (stmt) = body;
10885 4653 : OMP_CLAUSES (stmt) = clauses;
10886 :
10887 4653 : return add_stmt (stmt);
10888 : }
10889 :
10890 : /* Used to walk OpenMP target directive body. */
10891 :
10892 : struct omp_target_walk_data
10893 : {
10894 : /* Holds the 'this' expression found in current function. */
10895 : tree current_object;
10896 :
10897 : /* True if the 'this' expression was accessed in the target body. */
10898 : bool this_expr_accessed;
10899 :
10900 : /* For non-static functions, record which pointer-typed members were
10901 : accessed, and the whole expression. */
10902 : hash_map<tree, tree> ptr_members_accessed;
10903 :
10904 : /* Record which lambda objects were accessed in target body. */
10905 : hash_set<tree> lambda_objects_accessed;
10906 :
10907 : /* For lambda functions, the __closure object expression of the current
10908 : function, and the set of captured variables accessed in target body. */
10909 : tree current_closure;
10910 : hash_set<tree> closure_vars_accessed;
10911 :
10912 : /* Local variables declared inside a BIND_EXPR, used to filter out such
10913 : variables when recording lambda_objects_accessed. */
10914 : hash_set<tree> local_decls;
10915 :
10916 : omp_mapper_list<tree> *mappers;
10917 : };
10918 :
10919 : /* Helper function of finish_omp_target_clauses, called via
10920 : cp_walk_tree_without_duplicates. Traverse body of OpenMP target
10921 : directive *TP, and fill out omp_target_walk_data passed in *PTR. */
10922 :
10923 : static tree
10924 226322 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
10925 : {
10926 226322 : tree t = *tp;
10927 226322 : struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
10928 226322 : tree current_object = data->current_object;
10929 226322 : tree current_closure = data->current_closure;
10930 226322 : omp_mapper_list<tree> *mlist = data->mappers;
10931 :
10932 : /* References inside of these expression codes shouldn't incur any
10933 : form of mapping, so return early. */
10934 226322 : if (TREE_CODE (t) == SIZEOF_EXPR
10935 226314 : || TREE_CODE (t) == ALIGNOF_EXPR)
10936 : {
10937 8 : *walk_subtrees = 0;
10938 8 : return NULL_TREE;
10939 : }
10940 :
10941 226314 : if (TREE_CODE (t) == OMP_CLAUSE)
10942 : return NULL_TREE;
10943 :
10944 213729 : if (!processing_template_decl)
10945 : {
10946 213729 : tree aggr_type = NULL_TREE;
10947 :
10948 213729 : if (TREE_CODE (t) == COMPONENT_REF
10949 213729 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
10950 2233 : aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
10951 211496 : else if ((TREE_CODE (t) == VAR_DECL
10952 : || TREE_CODE (t) == PARM_DECL
10953 : || TREE_CODE (t) == RESULT_DECL)
10954 16821 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
10955 1214 : aggr_type = TREE_TYPE (t);
10956 :
10957 3447 : if (aggr_type)
10958 : {
10959 3447 : tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
10960 3447 : if (mapper_fn)
10961 173 : mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
10962 : }
10963 : }
10964 :
10965 213729 : if (current_object)
10966 : {
10967 2564 : tree this_expr = TREE_OPERAND (current_object, 0);
10968 :
10969 2564 : if (operand_equal_p (t, this_expr))
10970 : {
10971 35 : data->this_expr_accessed = true;
10972 35 : *walk_subtrees = 0;
10973 35 : return NULL_TREE;
10974 : }
10975 :
10976 2529 : if (TREE_CODE (t) == COMPONENT_REF
10977 115 : && POINTER_TYPE_P (TREE_TYPE (t))
10978 36 : && operand_equal_p (TREE_OPERAND (t, 0), current_object)
10979 2563 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
10980 : {
10981 34 : data->this_expr_accessed = true;
10982 34 : tree fld = TREE_OPERAND (t, 1);
10983 34 : if (data->ptr_members_accessed.get (fld) == NULL)
10984 : {
10985 14 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
10986 4 : t = convert_from_reference (t);
10987 14 : data->ptr_members_accessed.put (fld, t);
10988 : }
10989 34 : *walk_subtrees = 0;
10990 34 : return NULL_TREE;
10991 : }
10992 : }
10993 :
10994 : /* When the current_function_decl is a lambda function, the closure object
10995 : argument's type seems to not yet have fields layed out, so a recording
10996 : of DECL_VALUE_EXPRs during the target body walk seems the only way to
10997 : find them. */
10998 213660 : if (current_closure
10999 300 : && (VAR_P (t)
11000 : || TREE_CODE (t) == PARM_DECL
11001 : || TREE_CODE (t) == RESULT_DECL)
11002 24 : && DECL_HAS_VALUE_EXPR_P (t)
11003 10 : && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
11004 213670 : && operand_equal_p (current_closure,
11005 10 : TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
11006 : {
11007 9 : if (!data->closure_vars_accessed.contains (t))
11008 9 : data->closure_vars_accessed.add (t);
11009 9 : *walk_subtrees = 0;
11010 9 : return NULL_TREE;
11011 : }
11012 :
11013 213651 : if (TREE_CODE (t) == BIND_EXPR)
11014 : {
11015 19908 : if (tree block = BIND_EXPR_BLOCK (t))
11016 22301 : for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
11017 2397 : if (!data->local_decls.contains (var))
11018 2397 : data->local_decls.add (var);
11019 19908 : return NULL_TREE;
11020 : }
11021 :
11022 198324 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
11023 : {
11024 39 : tree lt = TREE_TYPE (t);
11025 39 : gcc_assert (CLASS_TYPE_P (lt));
11026 :
11027 39 : if (!data->lambda_objects_accessed.contains (t)
11028 : /* Do not prepare to create target maps for locally declared
11029 : lambdas or anonymous ones. */
11030 39 : && !data->local_decls.contains (t)
11031 72 : && TREE_CODE (t) != TARGET_EXPR)
11032 13 : data->lambda_objects_accessed.add (t);
11033 39 : *walk_subtrees = 0;
11034 39 : return NULL_TREE;
11035 : }
11036 :
11037 : return NULL_TREE;
11038 : }
11039 :
11040 : /* Helper function for finish_omp_target, and also from tsubst_expr.
11041 : Create additional clauses for mapping of non-static members, lambda objects,
11042 : etc. */
11043 :
11044 : void
11045 6938 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
11046 : {
11047 6938 : omp_target_walk_data data;
11048 6938 : data.this_expr_accessed = false;
11049 6938 : data.current_object = NULL_TREE;
11050 :
11051 6938 : if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
11052 96 : if (tree ct = current_nonlambda_class_type ())
11053 : {
11054 95 : tree object = maybe_dummy_object (ct, NULL);
11055 95 : object = maybe_resolve_dummy (object, true);
11056 95 : data.current_object = object;
11057 : }
11058 :
11059 6938 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11060 : {
11061 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11062 8 : data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11063 : }
11064 : else
11065 6930 : data.current_closure = NULL_TREE;
11066 :
11067 6938 : auto_vec<tree, 16> new_clauses;
11068 :
11069 6938 : if (!processing_template_decl)
11070 : {
11071 6938 : hash_set<omp_name_type<tree> > seen_types;
11072 6938 : auto_vec<tree> mapper_fns;
11073 6938 : omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
11074 6938 : data.mappers = &mlist;
11075 :
11076 6938 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11077 : &data);
11078 :
11079 6938 : unsigned int i;
11080 6938 : tree mapper_fn;
11081 13965 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11082 89 : c_omp_find_nested_mappers (&mlist, mapper_fn);
11083 :
11084 7093 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11085 : {
11086 89 : tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
11087 89 : if (mapper == error_mark_node)
11088 0 : continue;
11089 89 : tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
11090 89 : tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
11091 89 : if (BASELINK_P (mapper_fn))
11092 0 : mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
11093 :
11094 89 : tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
11095 89 : OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
11096 89 : OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
11097 89 : OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
11098 :
11099 89 : new_clauses.safe_push (c);
11100 : }
11101 6938 : }
11102 : else
11103 : {
11104 0 : data.mappers = NULL;
11105 0 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11106 : &data);
11107 : }
11108 :
11109 6938 : tree omp_target_this_expr = NULL_TREE;
11110 6938 : tree *explicit_this_deref_map = NULL;
11111 6938 : if (data.this_expr_accessed)
11112 : {
11113 31 : omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
11114 :
11115 : /* See if explicit user-specified map(this[:]) clause already exists.
11116 : If not, we create an implicit map(tofrom:this[:1]) clause. */
11117 80 : for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
11118 50 : if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
11119 47 : && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
11120 40 : || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
11121 57 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
11122 : omp_target_this_expr))
11123 : {
11124 : explicit_this_deref_map = cp;
11125 : break;
11126 : }
11127 : }
11128 :
11129 6938 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11130 6938 : && (data.this_expr_accessed
11131 1 : || !data.closure_vars_accessed.is_empty ()))
11132 : {
11133 : /* For lambda functions, we need to first create a copy of the
11134 : __closure object. */
11135 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11136 8 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11137 8 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
11138 8 : OMP_CLAUSE_DECL (c)
11139 8 : = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11140 8 : OMP_CLAUSE_SIZE (c)
11141 8 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
11142 8 : new_clauses.safe_push (c);
11143 :
11144 8 : tree closure_obj = OMP_CLAUSE_DECL (c);
11145 8 : tree closure_type = TREE_TYPE (closure_obj);
11146 :
11147 16 : gcc_assert (LAMBDA_TYPE_P (closure_type)
11148 : && CLASS_TYPE_P (closure_type));
11149 :
11150 8 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11151 8 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
11152 8 : OMP_CLAUSE_DECL (c2) = closure;
11153 8 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11154 8 : new_clauses.safe_push (c2);
11155 : }
11156 :
11157 6938 : if (data.this_expr_accessed)
11158 : {
11159 : /* If the this-expr was accessed, create a map(*this) clause. */
11160 31 : enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11161 31 : if (explicit_this_deref_map)
11162 : {
11163 1 : tree this_map = *explicit_this_deref_map;
11164 1 : tree nc = OMP_CLAUSE_CHAIN (this_map);
11165 2 : gcc_assert (nc != NULL_TREE
11166 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11167 : && (OMP_CLAUSE_MAP_KIND (nc)
11168 : == GOMP_MAP_FIRSTPRIVATE_POINTER));
11169 1 : kind = OMP_CLAUSE_MAP_KIND (this_map);
11170 : /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
11171 : two-map sequence away from the chain. */
11172 1 : *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
11173 : }
11174 31 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11175 31 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11176 31 : OMP_CLAUSE_DECL (c)
11177 31 : = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
11178 31 : OMP_CLAUSE_SIZE (c)
11179 31 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
11180 31 : new_clauses.safe_push (c);
11181 :
11182 : /* If we're in a lambda function, the this-pointer will actually be
11183 : '__closure->this', a mapped member of __closure, hence always_pointer.
11184 : Otherwise it's a firstprivate pointer. */
11185 31 : enum gomp_map_kind ptr_kind
11186 31 : = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11187 31 : ? GOMP_MAP_ALWAYS_POINTER
11188 24 : : GOMP_MAP_FIRSTPRIVATE_POINTER);
11189 31 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11190 31 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11191 31 : OMP_CLAUSE_DECL (c) = omp_target_this_expr;
11192 31 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11193 31 : new_clauses.safe_push (c);
11194 : }
11195 :
11196 6938 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11197 : {
11198 8 : if (omp_target_this_expr)
11199 : {
11200 7 : STRIP_NOPS (omp_target_this_expr);
11201 7 : gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
11202 7 : omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
11203 : }
11204 :
11205 17 : for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
11206 34 : i != data.closure_vars_accessed.end (); ++i)
11207 : {
11208 9 : tree orig_decl = *i;
11209 9 : tree closure_expr = DECL_VALUE_EXPR (orig_decl);
11210 :
11211 9 : if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
11212 9 : || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
11213 : {
11214 : /* this-pointer is processed above, outside this loop. */
11215 3 : if (omp_target_this_expr
11216 3 : && operand_equal_p (closure_expr, omp_target_this_expr))
11217 0 : continue;
11218 :
11219 3 : bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
11220 3 : enum gomp_map_kind kind, ptr_kind, nc_kind;
11221 3 : tree size;
11222 :
11223 3 : if (ptr_p)
11224 : {
11225 : /* For pointers, default mapped as zero-length array
11226 : section. */
11227 2 : kind = GOMP_MAP_ALLOC;
11228 2 : nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
11229 2 : ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
11230 2 : size = size_zero_node;
11231 : }
11232 : else
11233 : {
11234 : /* For references, default mapped as appearing on map
11235 : clause. */
11236 1 : kind = GOMP_MAP_TOFROM;
11237 1 : nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
11238 1 : ptr_kind = GOMP_MAP_ALWAYS_POINTER;
11239 1 : size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
11240 : }
11241 :
11242 6 : for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
11243 3 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
11244 1 : && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
11245 1 : || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
11246 3 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
11247 : orig_decl))
11248 : {
11249 : /* If this was already specified by user as a map,
11250 : save the user specified map kind, delete the
11251 : "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
11252 : and insert our own sequence:
11253 : "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
11254 : */
11255 0 : tree nc = OMP_CLAUSE_CHAIN (*p);
11256 0 : gcc_assert (nc != NULL_TREE
11257 : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11258 : && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
11259 : /* Update with user specified kind and size. */
11260 0 : kind = OMP_CLAUSE_MAP_KIND (*p);
11261 0 : size = OMP_CLAUSE_SIZE (*p);
11262 0 : *p = OMP_CLAUSE_CHAIN (nc);
11263 0 : break;
11264 : }
11265 :
11266 3 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11267 3 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11268 3 : OMP_CLAUSE_DECL (c)
11269 3 : = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
11270 3 : OMP_CLAUSE_SIZE (c) = size;
11271 3 : if (ptr_p)
11272 2 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11273 3 : new_clauses.safe_push (c);
11274 :
11275 3 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11276 3 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11277 3 : OMP_CLAUSE_DECL (c) = closure_expr;
11278 3 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11279 3 : new_clauses.safe_push (c);
11280 : }
11281 : }
11282 : }
11283 :
11284 6938 : if (!data.ptr_members_accessed.is_empty ())
11285 14 : for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
11286 56 : i != data.ptr_members_accessed.end (); ++i)
11287 : {
11288 : /* For each referenced member that is of pointer or reference-to-pointer
11289 : type, create the equivalent of map(alloc:this->ptr[:0]). */
11290 14 : tree field_decl = (*i).first;
11291 14 : tree ptr_member = (*i).second;
11292 :
11293 26 : for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
11294 : {
11295 16 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
11296 2 : continue;
11297 : /* If map(this->ptr[:N]) already exists, avoid creating another
11298 : such map. */
11299 14 : tree decl = OMP_CLAUSE_DECL (c);
11300 14 : if ((TREE_CODE (decl) == INDIRECT_REF
11301 10 : || TREE_CODE (decl) == MEM_REF)
11302 14 : && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
11303 4 : goto next_ptr_member;
11304 : }
11305 :
11306 10 : if (!cxx_mark_addressable (ptr_member))
11307 0 : gcc_unreachable ();
11308 :
11309 10 : if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
11310 : {
11311 : /* For reference to pointers, we need to map the referenced
11312 : pointer first for things to be correct. */
11313 4 : tree ptr_member_type = TREE_TYPE (ptr_member);
11314 :
11315 : /* Map pointer target as zero-length array section. */
11316 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11317 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11318 4 : OMP_CLAUSE_DECL (c)
11319 4 : = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
11320 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11321 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11322 :
11323 : /* Map pointer to zero-length array section. */
11324 4 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11325 4 : OMP_CLAUSE_SET_MAP_KIND
11326 : (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
11327 4 : OMP_CLAUSE_DECL (c2) = ptr_member;
11328 4 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11329 :
11330 : /* Attach reference-to-pointer field to pointer. */
11331 4 : tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11332 4 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
11333 4 : OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
11334 4 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
11335 :
11336 4 : new_clauses.safe_push (c);
11337 4 : new_clauses.safe_push (c2);
11338 4 : new_clauses.safe_push (c3);
11339 : }
11340 6 : else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
11341 : {
11342 : /* Map pointer target as zero-length array section. */
11343 6 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11344 6 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11345 6 : OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
11346 : RO_UNARY_STAR);
11347 6 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11348 6 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11349 :
11350 : /* Attach zero-length array section to pointer. */
11351 6 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11352 6 : OMP_CLAUSE_SET_MAP_KIND
11353 : (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11354 6 : OMP_CLAUSE_DECL (c2) = ptr_member;
11355 6 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11356 :
11357 6 : new_clauses.safe_push (c);
11358 6 : new_clauses.safe_push (c2);
11359 : }
11360 : else
11361 0 : gcc_unreachable ();
11362 :
11363 14 : next_ptr_member:
11364 14 : ;
11365 : }
11366 :
11367 6951 : for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
11368 6964 : i != data.lambda_objects_accessed.end (); ++i)
11369 : {
11370 13 : tree lobj = *i;
11371 13 : if (TREE_CODE (lobj) == TARGET_EXPR)
11372 0 : lobj = TARGET_EXPR_SLOT (lobj);
11373 :
11374 13 : tree lt = TREE_TYPE (lobj);
11375 26 : gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
11376 :
11377 13 : tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
11378 13 : OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
11379 13 : OMP_CLAUSE_DECL (lc) = lobj;
11380 13 : OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
11381 13 : new_clauses.safe_push (lc);
11382 :
11383 180 : for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
11384 : {
11385 167 : if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
11386 : {
11387 4 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11388 : lobj, fld, NULL_TREE);
11389 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11390 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11391 4 : OMP_CLAUSE_DECL (c)
11392 4 : = build_indirect_ref (loc, exp, RO_UNARY_STAR);
11393 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11394 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11395 4 : new_clauses.safe_push (c);
11396 :
11397 4 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11398 4 : OMP_CLAUSE_SET_MAP_KIND
11399 : (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11400 4 : OMP_CLAUSE_DECL (c) = exp;
11401 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11402 4 : new_clauses.safe_push (c);
11403 : }
11404 163 : else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
11405 : {
11406 0 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11407 : lobj, fld, NULL_TREE);
11408 0 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11409 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
11410 0 : OMP_CLAUSE_DECL (c)
11411 0 : = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
11412 0 : OMP_CLAUSE_SIZE (c)
11413 0 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
11414 0 : new_clauses.safe_push (c);
11415 :
11416 0 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11417 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
11418 0 : OMP_CLAUSE_DECL (c) = exp;
11419 0 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11420 0 : new_clauses.safe_push (c);
11421 : }
11422 : }
11423 : }
11424 :
11425 6938 : tree c = *clauses_ptr;
11426 14094 : for (int i = new_clauses.length () - 1; i >= 0; i--)
11427 : {
11428 218 : OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
11429 218 : c = new_clauses[i];
11430 : }
11431 6938 : *clauses_ptr = c;
11432 6938 : }
11433 :
11434 : /* Called from cp_parser_omp_target. Create additional implicit clauses for
11435 : OpenMP target directives, and do sanity checks. */
11436 :
11437 : tree
11438 6926 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
11439 : {
11440 6926 : if (!processing_template_decl)
11441 6113 : finish_omp_target_clauses (loc, body, &clauses);
11442 :
11443 6926 : tree stmt = make_node (OMP_TARGET);
11444 6926 : TREE_TYPE (stmt) = void_type_node;
11445 6926 : OMP_TARGET_CLAUSES (stmt) = clauses;
11446 6926 : OMP_TARGET_BODY (stmt) = body;
11447 6926 : OMP_TARGET_COMBINED (stmt) = combined_p;
11448 6926 : SET_EXPR_LOCATION (stmt, loc);
11449 :
11450 6926 : tree c = clauses;
11451 16530 : while (c)
11452 : {
11453 9604 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
11454 5534 : switch (OMP_CLAUSE_MAP_KIND (c))
11455 : {
11456 : case GOMP_MAP_TO:
11457 : case GOMP_MAP_ALWAYS_TO:
11458 : case GOMP_MAP_PRESENT_TO:
11459 : case GOMP_MAP_ALWAYS_PRESENT_TO:
11460 : case GOMP_MAP_FROM:
11461 : case GOMP_MAP_ALWAYS_FROM:
11462 : case GOMP_MAP_PRESENT_FROM:
11463 : case GOMP_MAP_ALWAYS_PRESENT_FROM:
11464 : case GOMP_MAP_TOFROM:
11465 : case GOMP_MAP_ALWAYS_TOFROM:
11466 : case GOMP_MAP_PRESENT_TOFROM:
11467 : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
11468 : case GOMP_MAP_ALLOC:
11469 : case GOMP_MAP_PRESENT_ALLOC:
11470 : case GOMP_MAP_FIRSTPRIVATE_POINTER:
11471 : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
11472 : case GOMP_MAP_ALWAYS_POINTER:
11473 : case GOMP_MAP_ATTACH_DETACH:
11474 : case GOMP_MAP_ATTACH:
11475 : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
11476 : case GOMP_MAP_POINTER:
11477 : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
11478 : break;
11479 3 : default:
11480 3 : error_at (OMP_CLAUSE_LOCATION (c),
11481 : "%<#pragma omp target%> with map-type other "
11482 : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
11483 : "on %<map%> clause");
11484 3 : break;
11485 : }
11486 9604 : c = OMP_CLAUSE_CHAIN (c);
11487 : }
11488 6926 : return add_stmt (stmt);
11489 : }
11490 :
11491 : tree
11492 9321 : finish_omp_parallel (tree clauses, tree body)
11493 : {
11494 9321 : tree stmt;
11495 :
11496 9321 : body = finish_omp_structured_block (body);
11497 :
11498 9321 : stmt = make_node (OMP_PARALLEL);
11499 9321 : TREE_TYPE (stmt) = void_type_node;
11500 9321 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
11501 9321 : OMP_PARALLEL_BODY (stmt) = body;
11502 :
11503 9321 : return add_stmt (stmt);
11504 : }
11505 :
11506 : tree
11507 2161 : begin_omp_task (void)
11508 : {
11509 2161 : keep_next_level (true);
11510 2161 : return begin_omp_structured_block ();
11511 : }
11512 :
11513 : tree
11514 2161 : finish_omp_task (tree clauses, tree body)
11515 : {
11516 2161 : tree stmt;
11517 :
11518 2161 : body = finish_omp_structured_block (body);
11519 :
11520 2161 : stmt = make_node (OMP_TASK);
11521 2161 : TREE_TYPE (stmt) = void_type_node;
11522 2161 : OMP_TASK_CLAUSES (stmt) = clauses;
11523 2161 : OMP_TASK_BODY (stmt) = body;
11524 :
11525 2161 : return add_stmt (stmt);
11526 : }
11527 :
11528 : /* Helper function for finish_omp_for. Convert Ith random access iterator
11529 : into integral iterator. Return FALSE if successful. */
11530 :
11531 : static bool
11532 813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
11533 : tree declv, tree orig_declv, tree initv,
11534 : tree condv, tree incrv, tree *body,
11535 : tree *pre_body, tree &clauses,
11536 : int collapse, int ordered)
11537 : {
11538 813 : tree diff, iter_init, iter_incr = NULL, last;
11539 813 : tree incr_var = NULL, orig_pre_body, orig_body, c;
11540 813 : tree decl = TREE_VEC_ELT (declv, i);
11541 813 : tree init = TREE_VEC_ELT (initv, i);
11542 813 : tree cond = TREE_VEC_ELT (condv, i);
11543 813 : tree incr = TREE_VEC_ELT (incrv, i);
11544 813 : tree iter = decl;
11545 813 : location_t elocus = locus;
11546 :
11547 813 : if (init && EXPR_HAS_LOCATION (init))
11548 12 : elocus = EXPR_LOCATION (init);
11549 :
11550 813 : switch (TREE_CODE (cond))
11551 : {
11552 810 : case GT_EXPR:
11553 810 : case GE_EXPR:
11554 810 : case LT_EXPR:
11555 810 : case LE_EXPR:
11556 810 : case NE_EXPR:
11557 810 : if (TREE_OPERAND (cond, 1) == iter)
11558 42 : cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
11559 42 : TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
11560 810 : if (TREE_OPERAND (cond, 0) != iter)
11561 0 : cond = error_mark_node;
11562 : else
11563 : {
11564 810 : tree tem = build_x_binary_op (EXPR_LOCATION (cond),
11565 810 : TREE_CODE (cond),
11566 : iter, ERROR_MARK,
11567 810 : TREE_OPERAND (cond, 1), ERROR_MARK,
11568 : NULL_TREE, NULL, tf_warning_or_error);
11569 810 : if (error_operand_p (tem))
11570 : return true;
11571 : }
11572 : break;
11573 3 : default:
11574 3 : cond = error_mark_node;
11575 3 : break;
11576 : }
11577 810 : if (cond == error_mark_node)
11578 : {
11579 3 : error_at (elocus, "invalid controlling predicate");
11580 3 : return true;
11581 : }
11582 807 : diff = build_x_binary_op (elocus, MINUS_EXPR,
11583 807 : TREE_OPERAND (cond, 1), ERROR_MARK,
11584 : iter, ERROR_MARK,
11585 : NULL_TREE, NULL, tf_warning_or_error);
11586 807 : diff = cp_fully_fold (diff);
11587 807 : if (error_operand_p (diff))
11588 : return true;
11589 807 : if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
11590 : {
11591 0 : error_at (elocus, "difference between %qE and %qD does not have integer type",
11592 0 : TREE_OPERAND (cond, 1), iter);
11593 0 : return true;
11594 : }
11595 807 : if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
11596 807 : TREE_VEC_ELT (declv, i), NULL_TREE,
11597 : cond, cp_walk_subtrees))
11598 : return true;
11599 :
11600 762 : switch (TREE_CODE (incr))
11601 : {
11602 370 : case PREINCREMENT_EXPR:
11603 370 : case PREDECREMENT_EXPR:
11604 370 : case POSTINCREMENT_EXPR:
11605 370 : case POSTDECREMENT_EXPR:
11606 370 : if (TREE_OPERAND (incr, 0) != iter)
11607 : {
11608 0 : incr = error_mark_node;
11609 0 : break;
11610 : }
11611 370 : iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
11612 370 : TREE_CODE (incr), iter,
11613 : NULL_TREE, tf_warning_or_error);
11614 370 : if (error_operand_p (iter_incr))
11615 : return true;
11616 370 : else if (TREE_CODE (incr) == PREINCREMENT_EXPR
11617 219 : || TREE_CODE (incr) == POSTINCREMENT_EXPR)
11618 299 : incr = integer_one_node;
11619 : else
11620 71 : incr = integer_minus_one_node;
11621 : break;
11622 392 : case MODIFY_EXPR:
11623 392 : if (TREE_OPERAND (incr, 0) != iter)
11624 0 : incr = error_mark_node;
11625 392 : else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
11626 392 : || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
11627 : {
11628 392 : tree rhs = TREE_OPERAND (incr, 1);
11629 392 : if (TREE_OPERAND (rhs, 0) == iter)
11630 : {
11631 299 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
11632 : != INTEGER_TYPE)
11633 0 : incr = error_mark_node;
11634 : else
11635 : {
11636 299 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11637 299 : iter, TREE_CODE (rhs),
11638 299 : TREE_OPERAND (rhs, 1),
11639 : NULL_TREE,
11640 : tf_warning_or_error);
11641 299 : if (error_operand_p (iter_incr))
11642 : return true;
11643 299 : incr = TREE_OPERAND (rhs, 1);
11644 299 : incr = cp_convert (TREE_TYPE (diff), incr,
11645 : tf_warning_or_error);
11646 299 : if (TREE_CODE (rhs) == MINUS_EXPR)
11647 : {
11648 16 : incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
11649 16 : incr = fold_simple (incr);
11650 : }
11651 299 : if (TREE_CODE (incr) != INTEGER_CST
11652 299 : && (TREE_CODE (incr) != NOP_EXPR
11653 66 : || (TREE_CODE (TREE_OPERAND (incr, 0))
11654 : != INTEGER_CST)))
11655 : iter_incr = NULL;
11656 : }
11657 : }
11658 93 : else if (TREE_OPERAND (rhs, 1) == iter)
11659 : {
11660 93 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
11661 93 : || TREE_CODE (rhs) != PLUS_EXPR)
11662 0 : incr = error_mark_node;
11663 : else
11664 : {
11665 93 : iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
11666 : PLUS_EXPR,
11667 93 : TREE_OPERAND (rhs, 0),
11668 : ERROR_MARK, iter,
11669 : ERROR_MARK, NULL_TREE, NULL,
11670 : tf_warning_or_error);
11671 93 : if (error_operand_p (iter_incr))
11672 : return true;
11673 93 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11674 : iter, NOP_EXPR,
11675 : iter_incr, NULL_TREE,
11676 : tf_warning_or_error);
11677 93 : if (error_operand_p (iter_incr))
11678 : return true;
11679 93 : incr = TREE_OPERAND (rhs, 0);
11680 93 : iter_incr = NULL;
11681 : }
11682 : }
11683 : else
11684 0 : incr = error_mark_node;
11685 : }
11686 : else
11687 0 : incr = error_mark_node;
11688 : break;
11689 0 : default:
11690 0 : incr = error_mark_node;
11691 0 : break;
11692 : }
11693 :
11694 762 : if (incr == error_mark_node)
11695 : {
11696 0 : error_at (elocus, "invalid increment expression");
11697 0 : return true;
11698 : }
11699 :
11700 762 : incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
11701 762 : incr = cp_fully_fold (incr);
11702 762 : tree loop_iv_seen = NULL_TREE;
11703 1735 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11704 1093 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
11705 1093 : && OMP_CLAUSE_DECL (c) == iter)
11706 : {
11707 120 : if (code == OMP_TASKLOOP || code == OMP_LOOP)
11708 : {
11709 60 : loop_iv_seen = c;
11710 60 : OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
11711 : }
11712 : break;
11713 : }
11714 973 : else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
11715 113 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
11716 1007 : && OMP_CLAUSE_DECL (c) == iter)
11717 : {
11718 30 : loop_iv_seen = c;
11719 30 : if (code == OMP_TASKLOOP)
11720 25 : OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
11721 : }
11722 :
11723 762 : decl = create_temporary_var (TREE_TYPE (diff));
11724 762 : pushdecl (decl);
11725 762 : add_decl_expr (decl);
11726 762 : last = create_temporary_var (TREE_TYPE (diff));
11727 762 : pushdecl (last);
11728 762 : add_decl_expr (last);
11729 762 : if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
11730 10 : && (!ordered || (i < collapse && collapse > 1)))
11731 : {
11732 10 : incr_var = create_temporary_var (TREE_TYPE (diff));
11733 10 : pushdecl (incr_var);
11734 10 : add_decl_expr (incr_var);
11735 : }
11736 762 : gcc_assert (stmts_are_full_exprs_p ());
11737 762 : tree diffvar = NULL_TREE;
11738 762 : if (code == OMP_TASKLOOP)
11739 : {
11740 101 : if (!loop_iv_seen)
11741 : {
11742 38 : tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11743 38 : OMP_CLAUSE_DECL (ivc) = iter;
11744 38 : cxx_omp_finish_clause (ivc, NULL, false);
11745 38 : OMP_CLAUSE_CHAIN (ivc) = clauses;
11746 38 : clauses = ivc;
11747 : }
11748 101 : tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11749 101 : OMP_CLAUSE_DECL (lvc) = last;
11750 101 : OMP_CLAUSE_CHAIN (lvc) = clauses;
11751 101 : clauses = lvc;
11752 101 : diffvar = create_temporary_var (TREE_TYPE (diff));
11753 101 : pushdecl (diffvar);
11754 101 : add_decl_expr (diffvar);
11755 : }
11756 661 : else if (code == OMP_LOOP)
11757 : {
11758 43 : if (!loop_iv_seen)
11759 : {
11760 : /* While iterators on the loop construct are predetermined
11761 : lastprivate, if the decl is not declared inside of the
11762 : loop, OMP_CLAUSE_LASTPRIVATE should have been added
11763 : already. */
11764 16 : loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11765 16 : OMP_CLAUSE_DECL (loop_iv_seen) = iter;
11766 16 : OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
11767 16 : clauses = loop_iv_seen;
11768 : }
11769 27 : else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
11770 : {
11771 5 : OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
11772 5 : OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
11773 5 : OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
11774 : }
11775 43 : if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
11776 21 : cxx_omp_finish_clause (loop_iv_seen, NULL, false);
11777 : }
11778 :
11779 762 : orig_pre_body = *pre_body;
11780 762 : *pre_body = push_stmt_list ();
11781 762 : if (orig_pre_body)
11782 610 : add_stmt (orig_pre_body);
11783 762 : if (init != NULL)
11784 61 : finish_expr_stmt (build_x_modify_expr (elocus,
11785 : iter, NOP_EXPR, init,
11786 : NULL_TREE, tf_warning_or_error));
11787 762 : init = build_int_cst (TREE_TYPE (diff), 0);
11788 762 : if (c && iter_incr == NULL
11789 28 : && (!ordered || (i < collapse && collapse > 1)))
11790 : {
11791 28 : if (incr_var)
11792 : {
11793 10 : finish_expr_stmt (build_x_modify_expr (elocus,
11794 : incr_var, NOP_EXPR,
11795 : incr, NULL_TREE,
11796 : tf_warning_or_error));
11797 10 : incr = incr_var;
11798 : }
11799 28 : iter_incr = build_x_modify_expr (elocus,
11800 : iter, PLUS_EXPR, incr,
11801 : NULL_TREE, tf_warning_or_error);
11802 : }
11803 762 : if (c && ordered && i < collapse && collapse > 1)
11804 762 : iter_incr = incr;
11805 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11806 : last, NOP_EXPR, init,
11807 : NULL_TREE, tf_warning_or_error));
11808 762 : if (diffvar)
11809 : {
11810 101 : finish_expr_stmt (build_x_modify_expr (elocus,
11811 : diffvar, NOP_EXPR,
11812 : diff, NULL_TREE, tf_warning_or_error));
11813 101 : diff = diffvar;
11814 : }
11815 762 : *pre_body = pop_stmt_list (*pre_body);
11816 :
11817 1524 : cond = cp_build_binary_op (elocus,
11818 762 : TREE_CODE (cond), decl, diff,
11819 : tf_warning_or_error);
11820 762 : incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
11821 : elocus, incr, NULL_TREE);
11822 :
11823 762 : orig_body = *body;
11824 762 : *body = push_stmt_list ();
11825 762 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
11826 762 : iter_init = build_x_modify_expr (elocus,
11827 : iter, PLUS_EXPR, iter_init,
11828 : NULL_TREE, tf_warning_or_error);
11829 762 : if (iter_init != error_mark_node)
11830 759 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11831 762 : finish_expr_stmt (iter_init);
11832 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11833 : last, NOP_EXPR, decl,
11834 : NULL_TREE, tf_warning_or_error));
11835 762 : add_stmt (orig_body);
11836 762 : *body = pop_stmt_list (*body);
11837 :
11838 762 : if (c)
11839 : {
11840 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
11841 120 : if (!ordered)
11842 114 : finish_expr_stmt (iter_incr);
11843 : else
11844 : {
11845 6 : iter_init = decl;
11846 6 : if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
11847 2 : iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
11848 : iter_init, iter_incr);
11849 6 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
11850 6 : iter_init = build_x_modify_expr (elocus,
11851 : iter, PLUS_EXPR, iter_init,
11852 : NULL_TREE, tf_warning_or_error);
11853 6 : if (iter_init != error_mark_node)
11854 6 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11855 6 : finish_expr_stmt (iter_init);
11856 : }
11857 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c)
11858 240 : = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
11859 : }
11860 :
11861 762 : if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
11862 : {
11863 116 : tree t = TREE_VEC_ELT (orig_declv, i);
11864 116 : gcc_assert (TREE_PURPOSE (t) == NULL_TREE
11865 : && TREE_VALUE (t) == NULL_TREE
11866 : && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
11867 116 : TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
11868 116 : TREE_VALUE (t) = last;
11869 : }
11870 : else
11871 646 : TREE_VEC_ELT (orig_declv, i)
11872 1292 : = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
11873 762 : TREE_VEC_ELT (declv, i) = decl;
11874 762 : TREE_VEC_ELT (initv, i) = init;
11875 762 : TREE_VEC_ELT (condv, i) = cond;
11876 762 : TREE_VEC_ELT (incrv, i) = incr;
11877 :
11878 762 : return false;
11879 : }
11880 :
11881 : /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
11882 : are directly for their associated operands in the statement. DECL
11883 : and INIT are a combo; if DECL is NULL then INIT ought to be a
11884 : MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
11885 : optional statements that need to go before the loop into its
11886 : sk_omp scope. */
11887 :
11888 : tree
11889 21128 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
11890 : tree orig_declv, tree initv, tree condv, tree incrv,
11891 : tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
11892 : {
11893 21128 : tree omp_for = NULL, orig_incr = NULL;
11894 21128 : tree decl = NULL, init, cond, incr;
11895 21128 : location_t elocus;
11896 21128 : int i;
11897 21128 : int collapse = 1;
11898 21128 : int ordered = 0;
11899 21128 : auto_vec<location_t> init_locv;
11900 :
11901 21128 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
11902 21128 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
11903 21128 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
11904 21128 : if (TREE_VEC_LENGTH (declv) > 1)
11905 : {
11906 4054 : if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
11907 83 : collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
11908 : else
11909 : {
11910 3971 : if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
11911 3501 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
11912 470 : else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
11913 394 : collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
11914 3971 : if (collapse != TREE_VEC_LENGTH (declv))
11915 100 : ordered = TREE_VEC_LENGTH (declv);
11916 : }
11917 : }
11918 48601 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
11919 : {
11920 27509 : decl = TREE_VEC_ELT (declv, i);
11921 27509 : init = TREE_VEC_ELT (initv, i);
11922 27509 : cond = TREE_VEC_ELT (condv, i);
11923 27509 : incr = TREE_VEC_ELT (incrv, i);
11924 27509 : elocus = locus;
11925 :
11926 27509 : if (decl == global_namespace)
11927 : {
11928 1101 : gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
11929 1101 : TREE_VEC_ELT (declv, i) = NULL_TREE;
11930 1101 : init_locv.safe_push (UNKNOWN_LOCATION);
11931 1101 : continue;
11932 : }
11933 : /* We are going to throw out the init's original MODIFY_EXPR or
11934 : MODOP_EXPR below. Save its location so we can use it when
11935 : reconstructing the expression farther down. Alternatively, if the
11936 : initializer is a binding of the iteration variable, save
11937 : that location. Any of these locations in the initialization clause
11938 : for the current nested loop are better than using the argument locus,
11939 : that points to the "for" of the outermost loop in the nest. */
11940 26408 : if (init && EXPR_HAS_LOCATION (init))
11941 17872 : elocus = EXPR_LOCATION (init);
11942 8536 : else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
11943 : /* This can happen for class iterators. */
11944 0 : elocus = EXPR_LOCATION (decl);
11945 8536 : else if (decl && DECL_P (decl))
11946 : {
11947 8509 : if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
11948 8509 : elocus = DECL_SOURCE_LOCATION (decl);
11949 0 : else if (DECL_INITIAL (decl)
11950 0 : && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
11951 0 : elocus = EXPR_LOCATION (DECL_INITIAL (decl));
11952 : }
11953 26408 : init_locv.safe_push (elocus);
11954 :
11955 26408 : if (decl == NULL)
11956 : {
11957 16564 : if (init != NULL)
11958 16561 : switch (TREE_CODE (init))
11959 : {
11960 16176 : case MODIFY_EXPR:
11961 16176 : decl = TREE_OPERAND (init, 0);
11962 16176 : init = TREE_OPERAND (init, 1);
11963 16176 : break;
11964 367 : case MODOP_EXPR:
11965 367 : if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
11966 : {
11967 367 : decl = TREE_OPERAND (init, 0);
11968 367 : init = TREE_OPERAND (init, 2);
11969 : }
11970 : break;
11971 : default:
11972 : break;
11973 : }
11974 :
11975 16564 : if (decl == NULL)
11976 : {
11977 21 : error_at (locus,
11978 : "expected iteration declaration or initialization");
11979 21 : return NULL;
11980 : }
11981 : }
11982 :
11983 26387 : if (cond == global_namespace)
11984 170 : continue;
11985 :
11986 26217 : if (cond == NULL)
11987 : {
11988 9 : error_at (elocus, "missing controlling predicate");
11989 9 : return NULL;
11990 : }
11991 :
11992 26208 : if (incr == NULL)
11993 : {
11994 6 : error_at (elocus, "missing increment expression");
11995 6 : return NULL;
11996 : }
11997 :
11998 26202 : TREE_VEC_ELT (declv, i) = decl;
11999 26202 : TREE_VEC_ELT (initv, i) = init;
12000 : }
12001 :
12002 21092 : if (orig_inits)
12003 : {
12004 : bool fail = false;
12005 : tree orig_init;
12006 21214 : FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
12007 1181 : if (orig_init
12008 3396 : && !c_omp_check_loop_iv_exprs (locus, code,
12009 : orig_declv ? orig_declv : declv, i,
12010 1164 : TREE_VEC_ELT (declv, i), orig_init,
12011 : NULL_TREE, cp_walk_subtrees))
12012 : fail = true;
12013 20033 : if (fail)
12014 887 : return NULL;
12015 : }
12016 :
12017 21035 : if (dependent_omp_for_p (declv, initv, condv, incrv, body))
12018 : {
12019 453 : tree stmt;
12020 :
12021 453 : stmt = make_node (code);
12022 :
12023 1499 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
12024 : {
12025 593 : if (TREE_VEC_ELT (declv, i) == NULL_TREE)
12026 9 : continue;
12027 : /* This is really just a place-holder. We'll be decomposing this
12028 : again and going through the cp_build_modify_expr path below when
12029 : we instantiate the thing. */
12030 584 : TREE_VEC_ELT (initv, i)
12031 1168 : = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
12032 584 : TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
12033 : }
12034 :
12035 453 : TREE_TYPE (stmt) = void_type_node;
12036 453 : OMP_FOR_INIT (stmt) = initv;
12037 453 : OMP_FOR_COND (stmt) = condv;
12038 453 : OMP_FOR_INCR (stmt) = incrv;
12039 453 : OMP_FOR_BODY (stmt) = body;
12040 453 : OMP_FOR_PRE_BODY (stmt) = pre_body;
12041 453 : OMP_FOR_CLAUSES (stmt) = clauses;
12042 :
12043 453 : SET_EXPR_LOCATION (stmt, locus);
12044 453 : return add_stmt (stmt);
12045 : }
12046 :
12047 20582 : if (!orig_declv)
12048 19795 : orig_declv = copy_node (declv);
12049 :
12050 20582 : if (processing_template_decl)
12051 612 : orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
12052 :
12053 48030 : for (i = 0; i < TREE_VEC_LENGTH (declv); )
12054 : {
12055 27540 : decl = TREE_VEC_ELT (declv, i);
12056 27540 : init = TREE_VEC_ELT (initv, i);
12057 27540 : cond = TREE_VEC_ELT (condv, i);
12058 27540 : incr = TREE_VEC_ELT (incrv, i);
12059 27540 : if (orig_incr)
12060 844 : TREE_VEC_ELT (orig_incr, i) = incr;
12061 27540 : elocus = init_locv[i];
12062 :
12063 27540 : if (decl == NULL_TREE)
12064 : {
12065 1092 : i++;
12066 1092 : continue;
12067 : }
12068 :
12069 26448 : if (!DECL_P (decl))
12070 : {
12071 6 : error_at (elocus, "expected iteration declaration or initialization");
12072 6 : return NULL;
12073 : }
12074 :
12075 26442 : if (incr && TREE_CODE (incr) == MODOP_EXPR)
12076 : {
12077 1 : if (orig_incr)
12078 1 : TREE_VEC_ELT (orig_incr, i) = incr;
12079 1 : incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
12080 1 : TREE_CODE (TREE_OPERAND (incr, 1)),
12081 1 : TREE_OPERAND (incr, 2),
12082 : tf_warning_or_error);
12083 : }
12084 :
12085 26442 : if (CLASS_TYPE_P (TREE_TYPE (decl)))
12086 : {
12087 825 : if (code == OMP_SIMD)
12088 : {
12089 12 : error_at (elocus, "%<#pragma omp simd%> used with class "
12090 : "iteration variable %qE", decl);
12091 12 : return NULL;
12092 : }
12093 813 : if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
12094 : initv, condv, incrv, &body,
12095 : &pre_body, clauses,
12096 : collapse, ordered))
12097 : return NULL;
12098 762 : continue;
12099 : }
12100 :
12101 51234 : if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
12102 27203 : && !TYPE_PTR_P (TREE_TYPE (decl)))
12103 : {
12104 14 : error_at (elocus, "invalid type for iteration variable %qE", decl);
12105 14 : return NULL;
12106 : }
12107 :
12108 25603 : if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
12109 24842 : init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
12110 : tf_warning_or_error);
12111 : else
12112 761 : init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
12113 25603 : if (decl == error_mark_node || init == error_mark_node)
12114 : return NULL;
12115 :
12116 25594 : TREE_VEC_ELT (declv, i) = decl;
12117 25594 : TREE_VEC_ELT (initv, i) = init;
12118 25594 : TREE_VEC_ELT (condv, i) = cond;
12119 25594 : TREE_VEC_ELT (incrv, i) = incr;
12120 25594 : i++;
12121 : }
12122 :
12123 20490 : if (pre_body && IS_EMPTY_STMT (pre_body))
12124 0 : pre_body = NULL;
12125 :
12126 40980 : omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
12127 : incrv, body, pre_body,
12128 20490 : !processing_template_decl);
12129 :
12130 : /* Check for iterators appearing in lb, b or incr expressions. */
12131 20490 : if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
12132 : omp_for = NULL_TREE;
12133 :
12134 20004 : if (omp_for == NULL)
12135 702 : return NULL;
12136 :
12137 19788 : add_stmt (omp_for);
12138 :
12139 45448 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
12140 : {
12141 25660 : init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
12142 25660 : if (init == NULL_TREE)
12143 1032 : continue;
12144 24628 : decl = TREE_OPERAND (init, 0);
12145 24628 : cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
12146 24628 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
12147 :
12148 24628 : if (!processing_template_decl)
12149 : {
12150 24107 : if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
12151 : {
12152 106 : tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
12153 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
12154 106 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12155 106 : t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
12156 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
12157 212 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12158 : }
12159 : else
12160 : {
12161 24001 : tree t = TREE_OPERAND (init, 1);
12162 24001 : TREE_OPERAND (init, 1)
12163 48002 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12164 : }
12165 24107 : if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
12166 : {
12167 121 : tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
12168 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
12169 121 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12170 121 : t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
12171 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
12172 242 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12173 : }
12174 : else
12175 : {
12176 23986 : tree t = TREE_OPERAND (cond, 1);
12177 23986 : TREE_OPERAND (cond, 1)
12178 47972 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12179 : }
12180 : }
12181 :
12182 24628 : if (TREE_CODE (incr) != MODIFY_EXPR)
12183 18426 : continue;
12184 :
12185 6202 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
12186 70 : && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
12187 6272 : && !processing_template_decl)
12188 : {
12189 64 : tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
12190 64 : if (TREE_SIDE_EFFECTS (t)
12191 8 : && t != decl
12192 70 : && (TREE_CODE (t) != NOP_EXPR
12193 0 : || TREE_OPERAND (t, 0) != decl))
12194 6 : TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
12195 12 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12196 :
12197 64 : t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
12198 64 : if (TREE_SIDE_EFFECTS (t)
12199 56 : && t != decl
12200 120 : && (TREE_CODE (t) != NOP_EXPR
12201 5 : || TREE_OPERAND (t, 0) != decl))
12202 56 : TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
12203 112 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12204 : }
12205 :
12206 6202 : if (orig_incr)
12207 177 : TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
12208 : }
12209 19788 : OMP_FOR_CLAUSES (omp_for) = clauses;
12210 :
12211 : /* For simd loops with non-static data member iterators, we could have added
12212 : OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
12213 : step at this point, fill it in. */
12214 4735 : if (code == OMP_SIMD && !processing_template_decl
12215 24479 : && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
12216 4619 : for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
12217 561 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
12218 561 : if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
12219 : {
12220 4 : decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
12221 4 : gcc_assert (decl == OMP_CLAUSE_DECL (c));
12222 4 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
12223 4 : tree step, stept;
12224 4 : switch (TREE_CODE (incr))
12225 : {
12226 0 : case PREINCREMENT_EXPR:
12227 0 : case POSTINCREMENT_EXPR:
12228 : /* c_omp_for_incr_canonicalize_ptr() should have been
12229 : called to massage things appropriately. */
12230 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12231 0 : OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
12232 0 : break;
12233 0 : case PREDECREMENT_EXPR:
12234 0 : case POSTDECREMENT_EXPR:
12235 : /* c_omp_for_incr_canonicalize_ptr() should have been
12236 : called to massage things appropriately. */
12237 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12238 0 : OMP_CLAUSE_LINEAR_STEP (c)
12239 0 : = build_int_cst (TREE_TYPE (decl), -1);
12240 0 : break;
12241 4 : case MODIFY_EXPR:
12242 4 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12243 4 : incr = TREE_OPERAND (incr, 1);
12244 4 : switch (TREE_CODE (incr))
12245 : {
12246 4 : case PLUS_EXPR:
12247 4 : if (TREE_OPERAND (incr, 1) == decl)
12248 0 : step = TREE_OPERAND (incr, 0);
12249 : else
12250 4 : step = TREE_OPERAND (incr, 1);
12251 : break;
12252 0 : case MINUS_EXPR:
12253 0 : case POINTER_PLUS_EXPR:
12254 0 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12255 0 : step = TREE_OPERAND (incr, 1);
12256 0 : break;
12257 0 : default:
12258 0 : gcc_unreachable ();
12259 : }
12260 4 : stept = TREE_TYPE (decl);
12261 4 : if (INDIRECT_TYPE_P (stept))
12262 0 : stept = sizetype;
12263 4 : step = fold_convert (stept, step);
12264 4 : if (TREE_CODE (incr) == MINUS_EXPR)
12265 0 : step = fold_build1 (NEGATE_EXPR, stept, step);
12266 4 : OMP_CLAUSE_LINEAR_STEP (c) = step;
12267 4 : break;
12268 0 : default:
12269 0 : gcc_unreachable ();
12270 : }
12271 : }
12272 : /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
12273 : clauses, we need copy ctor for those rather than default ctor,
12274 : plus as for other lastprivates assignment op and dtor. */
12275 19788 : if (code == OMP_LOOP && !processing_template_decl)
12276 1993 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12277 1285 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
12278 204 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
12279 1307 : && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
12280 : false, true, true, true))
12281 0 : CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
12282 :
12283 : return omp_for;
12284 21128 : }
12285 :
12286 : /* Code walker for finish_omp_for_block: extract binding of DP->var
12287 : from its current block and move it to a new BIND_EXPR DP->b
12288 : surrounding the body of DP->omp_for. */
12289 :
12290 : struct fofb_data {
12291 : tree var;
12292 : tree b;
12293 : tree omp_for;
12294 : };
12295 :
12296 : static tree
12297 389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
12298 : {
12299 389 : struct fofb_data *fofb = (struct fofb_data *)dp;
12300 389 : if (TREE_CODE (*tp) == BIND_EXPR)
12301 578 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
12302 : {
12303 576 : if (*p == fofb->var)
12304 : {
12305 363 : *p = DECL_CHAIN (*p);
12306 363 : if (fofb->b == NULL_TREE)
12307 : {
12308 214 : fofb->b = make_node (BLOCK);
12309 214 : fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
12310 214 : OMP_FOR_BODY (fofb->omp_for), fofb->b);
12311 214 : TREE_SIDE_EFFECTS (fofb->b) = 1;
12312 214 : OMP_FOR_BODY (fofb->omp_for) = fofb->b;
12313 : }
12314 363 : DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
12315 363 : BIND_EXPR_VARS (fofb->b) = fofb->var;
12316 363 : BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
12317 363 : BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
12318 363 : return *tp;
12319 : }
12320 : }
12321 26 : if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
12322 22 : *walk_subtrees = false;
12323 : return NULL_TREE;
12324 : }
12325 :
12326 : /* Fix up range for decls. Those decls were pushed into BIND's
12327 : BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
12328 : and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
12329 : so that processing of combined loop directives can find them. */
12330 : tree
12331 14525 : finish_omp_for_block (tree bind, tree omp_for)
12332 : {
12333 14525 : if (omp_for == NULL_TREE
12334 14478 : || !OMP_FOR_ORIG_DECLS (omp_for)
12335 28435 : || bind == NULL_TREE)
12336 615 : return bind;
12337 13910 : struct fofb_data fofb;
12338 13910 : fofb.b = NULL_TREE;
12339 13910 : fofb.omp_for = omp_for;
12340 33347 : for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
12341 19437 : if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
12342 19215 : && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
12343 : == TREE_LIST)
12344 20268 : && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
12345 : {
12346 237 : tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
12347 602 : for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
12348 : {
12349 365 : fofb.var = TREE_VEC_ELT (v, j);
12350 365 : cp_walk_tree (&bind, finish_omp_for_block_walker,
12351 : (void *)&fofb, NULL);
12352 : }
12353 : }
12354 13910 : return bind;
12355 : }
12356 :
12357 : void
12358 3342 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
12359 : tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
12360 : tree clauses, enum omp_memory_order mo, bool weak)
12361 : {
12362 3342 : tree orig_lhs;
12363 3342 : tree orig_rhs;
12364 3342 : tree orig_v;
12365 3342 : tree orig_lhs1;
12366 3342 : tree orig_rhs1;
12367 3342 : tree orig_r;
12368 3342 : bool dependent_p;
12369 3342 : tree stmt;
12370 :
12371 3342 : orig_lhs = lhs;
12372 3342 : orig_rhs = rhs;
12373 3342 : orig_v = v;
12374 3342 : orig_lhs1 = lhs1;
12375 3342 : orig_rhs1 = rhs1;
12376 3342 : orig_r = r;
12377 3342 : dependent_p = false;
12378 3342 : stmt = NULL_TREE;
12379 :
12380 : /* Even in a template, we can detect invalid uses of the atomic
12381 : pragma if neither LHS nor RHS is type-dependent. */
12382 3342 : if (processing_template_decl)
12383 : {
12384 600 : dependent_p = (type_dependent_expression_p (lhs)
12385 237 : || (rhs && type_dependent_expression_p (rhs))
12386 234 : || (v && type_dependent_expression_p (v))
12387 234 : || (lhs1 && type_dependent_expression_p (lhs1))
12388 234 : || (rhs1 && type_dependent_expression_p (rhs1))
12389 834 : || (r
12390 25 : && r != void_list_node
12391 16 : && type_dependent_expression_p (r)));
12392 600 : if (clauses)
12393 : {
12394 30 : gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
12395 : && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
12396 : && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
12397 30 : if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
12398 30 : || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
12399 : dependent_p = true;
12400 : }
12401 : }
12402 576 : if (!dependent_p)
12403 : {
12404 2958 : bool swapped = false;
12405 2958 : if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
12406 : {
12407 143 : std::swap (rhs, rhs1);
12408 143 : swapped = !commutative_tree_code (opcode);
12409 : }
12410 2958 : if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
12411 : {
12412 0 : if (code == OMP_ATOMIC)
12413 0 : error ("%<#pragma omp atomic update%> uses two different "
12414 : "expressions for memory");
12415 : else
12416 0 : error ("%<#pragma omp atomic capture%> uses two different "
12417 : "expressions for memory");
12418 0 : return;
12419 : }
12420 2958 : if (lhs1 && !cp_tree_equal (lhs, lhs1))
12421 : {
12422 0 : if (code == OMP_ATOMIC)
12423 0 : error ("%<#pragma omp atomic update%> uses two different "
12424 : "expressions for memory");
12425 : else
12426 0 : error ("%<#pragma omp atomic capture%> uses two different "
12427 : "expressions for memory");
12428 0 : return;
12429 : }
12430 5916 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
12431 : v, lhs1, rhs1, r, swapped, mo, weak,
12432 2958 : processing_template_decl != 0);
12433 2958 : if (stmt == error_mark_node)
12434 : return;
12435 : }
12436 3312 : if (processing_template_decl)
12437 : {
12438 591 : if (code == OMP_ATOMIC_READ)
12439 : {
12440 167 : stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
12441 167 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12442 167 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12443 : }
12444 : else
12445 : {
12446 424 : if (opcode == NOP_EXPR)
12447 35 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
12448 389 : else if (opcode == COND_EXPR)
12449 : {
12450 124 : stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
12451 124 : if (orig_r)
12452 50 : stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
12453 : stmt);
12454 124 : stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
12455 : orig_lhs);
12456 124 : orig_rhs1 = NULL_TREE;
12457 : }
12458 : else
12459 265 : stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
12460 424 : if (orig_rhs1)
12461 182 : stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
12462 : COMPOUND_EXPR, orig_rhs1, stmt);
12463 424 : if (code != OMP_ATOMIC)
12464 : {
12465 233 : stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
12466 233 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12467 233 : OMP_ATOMIC_WEAK (stmt) = weak;
12468 233 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12469 : }
12470 : }
12471 591 : stmt = build2 (OMP_ATOMIC, void_type_node,
12472 : clauses ? clauses : integer_zero_node, stmt);
12473 591 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12474 591 : OMP_ATOMIC_WEAK (stmt) = weak;
12475 591 : SET_EXPR_LOCATION (stmt, loc);
12476 : }
12477 :
12478 : /* Avoid -Wunused-value warnings here, the whole construct has side-effects
12479 : and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
12480 : in some tree that appears to be unused, the value is not unused. */
12481 3312 : warning_sentinel w (warn_unused_value);
12482 3312 : finish_expr_stmt (stmt);
12483 3312 : }
12484 :
12485 : void
12486 359 : finish_omp_barrier (void)
12487 : {
12488 359 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
12489 359 : releasing_vec vec;
12490 359 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12491 359 : finish_expr_stmt (stmt);
12492 359 : }
12493 :
12494 : void
12495 397 : finish_omp_depobj (location_t loc, tree depobj,
12496 : enum omp_clause_depend_kind kind, tree clause)
12497 : {
12498 397 : if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
12499 : {
12500 343 : if (!lvalue_p (depobj))
12501 : {
12502 6 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
12503 : "%<depobj%> expression is not lvalue expression");
12504 6 : depobj = error_mark_node;
12505 : }
12506 : }
12507 :
12508 397 : if (processing_template_decl)
12509 : {
12510 114 : if (clause == NULL_TREE)
12511 47 : clause = build_int_cst (integer_type_node, kind);
12512 114 : add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
12513 114 : return;
12514 : }
12515 :
12516 283 : if (!error_operand_p (depobj))
12517 : {
12518 274 : tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
12519 274 : if (addr == error_mark_node)
12520 : depobj = error_mark_node;
12521 : else
12522 274 : depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
12523 : tf_warning_or_error);
12524 : }
12525 :
12526 283 : c_finish_omp_depobj (loc, depobj, kind, clause);
12527 : }
12528 :
12529 : void
12530 162 : finish_omp_flush (int mo)
12531 : {
12532 162 : tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
12533 162 : releasing_vec vec;
12534 162 : if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
12535 : {
12536 54 : fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
12537 54 : vec->quick_push (build_int_cst (integer_type_node, mo));
12538 : }
12539 162 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12540 162 : finish_expr_stmt (stmt);
12541 162 : }
12542 :
12543 : void
12544 111 : finish_omp_taskwait (void)
12545 : {
12546 111 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
12547 111 : releasing_vec vec;
12548 111 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12549 111 : finish_expr_stmt (stmt);
12550 111 : }
12551 :
12552 : void
12553 16 : finish_omp_taskyield (void)
12554 : {
12555 16 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
12556 16 : releasing_vec vec;
12557 16 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12558 16 : finish_expr_stmt (stmt);
12559 16 : }
12560 :
12561 : void
12562 596 : finish_omp_cancel (tree clauses)
12563 : {
12564 596 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
12565 596 : int mask = 0;
12566 596 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12567 : mask = 1;
12568 414 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12569 : mask = 2;
12570 285 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12571 : mask = 4;
12572 164 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12573 : mask = 8;
12574 : else
12575 : {
12576 0 : error ("%<#pragma omp cancel%> must specify one of "
12577 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12578 0 : return;
12579 : }
12580 596 : releasing_vec vec;
12581 596 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
12582 596 : if (ifc != NULL_TREE)
12583 : {
12584 70 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
12585 70 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
12586 6 : error_at (OMP_CLAUSE_LOCATION (ifc),
12587 : "expected %<cancel%> %<if%> clause modifier");
12588 : else
12589 : {
12590 64 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
12591 64 : if (ifc2 != NULL_TREE)
12592 : {
12593 3 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
12594 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
12595 : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
12596 3 : error_at (OMP_CLAUSE_LOCATION (ifc2),
12597 : "expected %<cancel%> %<if%> clause modifier");
12598 : }
12599 : }
12600 :
12601 70 : if (!processing_template_decl)
12602 61 : ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
12603 : else
12604 9 : ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
12605 9 : OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
12606 : integer_zero_node, ERROR_MARK,
12607 : NULL_TREE, NULL, tf_warning_or_error);
12608 : }
12609 : else
12610 526 : ifc = boolean_true_node;
12611 596 : vec->quick_push (build_int_cst (integer_type_node, mask));
12612 596 : vec->quick_push (ifc);
12613 596 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12614 596 : finish_expr_stmt (stmt);
12615 596 : }
12616 :
12617 : void
12618 494 : finish_omp_cancellation_point (tree clauses)
12619 : {
12620 494 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
12621 494 : int mask = 0;
12622 494 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12623 : mask = 1;
12624 366 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12625 : mask = 2;
12626 261 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12627 : mask = 4;
12628 156 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12629 : mask = 8;
12630 : else
12631 : {
12632 3 : error ("%<#pragma omp cancellation point%> must specify one of "
12633 : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12634 3 : return;
12635 : }
12636 491 : releasing_vec vec
12637 491 : = make_tree_vector_single (build_int_cst (integer_type_node, mask));
12638 491 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12639 491 : finish_expr_stmt (stmt);
12640 491 : }
12641 :
12642 : /* Begin a __transaction_atomic or __transaction_relaxed statement.
12643 : If PCOMPOUND is non-null, this is for a function-transaction-block, and we
12644 : should create an extra compound stmt. */
12645 :
12646 : tree
12647 303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
12648 : {
12649 303 : tree r;
12650 :
12651 303 : if (pcompound)
12652 21 : *pcompound = begin_compound_stmt (0);
12653 :
12654 303 : r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
12655 :
12656 : /* Only add the statement to the function if support enabled. */
12657 303 : if (flag_tm)
12658 297 : add_stmt (r);
12659 : else
12660 12 : error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
12661 : ? G_("%<__transaction_relaxed%> without "
12662 : "transactional memory support enabled")
12663 : : G_("%<__transaction_atomic%> without "
12664 : "transactional memory support enabled")));
12665 :
12666 303 : TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
12667 303 : TREE_SIDE_EFFECTS (r) = 1;
12668 303 : return r;
12669 : }
12670 :
12671 : /* End a __transaction_atomic or __transaction_relaxed statement.
12672 : If COMPOUND_STMT is non-null, this is for a function-transaction-block,
12673 : and we should end the compound. If NOEX is non-NULL, we wrap the body in
12674 : a MUST_NOT_THROW_EXPR with NOEX as condition. */
12675 :
12676 : void
12677 303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
12678 : {
12679 303 : TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
12680 303 : TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
12681 303 : TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
12682 303 : TRANSACTION_EXPR_IS_STMT (stmt) = 1;
12683 :
12684 : /* noexcept specifications are not allowed for function transactions. */
12685 303 : gcc_assert (!(noex && compound_stmt));
12686 303 : if (noex)
12687 : {
12688 51 : tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
12689 : noex);
12690 51 : protected_set_expr_location
12691 51 : (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
12692 51 : TREE_SIDE_EFFECTS (body) = 1;
12693 51 : TRANSACTION_EXPR_BODY (stmt) = body;
12694 : }
12695 :
12696 303 : if (compound_stmt)
12697 21 : finish_compound_stmt (compound_stmt);
12698 303 : }
12699 :
12700 : /* Build a __transaction_atomic or __transaction_relaxed expression. If
12701 : NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
12702 : condition. */
12703 :
12704 : tree
12705 116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
12706 : {
12707 116 : tree ret;
12708 116 : if (noex)
12709 : {
12710 57 : expr = build_must_not_throw_expr (expr, noex);
12711 57 : protected_set_expr_location (expr, loc);
12712 57 : TREE_SIDE_EFFECTS (expr) = 1;
12713 : }
12714 116 : ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
12715 116 : if (flags & TM_STMT_ATTR_RELAXED)
12716 4 : TRANSACTION_EXPR_RELAXED (ret) = 1;
12717 116 : TREE_SIDE_EFFECTS (ret) = 1;
12718 116 : SET_EXPR_LOCATION (ret, loc);
12719 116 : return ret;
12720 : }
12721 :
12722 : void
12723 98333 : init_cp_semantics (void)
12724 : {
12725 98333 : }
12726 :
12727 :
12728 : /* Get constant string at LOCATION. Returns true if successful,
12729 : otherwise false. */
12730 :
12731 : bool
12732 10489128 : cexpr_str::type_check (location_t location, bool allow_char8_t /*=false*/)
12733 : {
12734 10489128 : tsubst_flags_t complain = tf_warning_or_error;
12735 :
12736 10489128 : if (message == NULL_TREE
12737 10489128 : || message == error_mark_node
12738 20978253 : || check_for_bare_parameter_packs (message))
12739 3 : return false;
12740 :
12741 10489125 : if (TREE_CODE (message) != STRING_CST
12742 10489125 : && !type_dependent_expression_p (message))
12743 : {
12744 976 : message_sz
12745 976 : = finish_class_member_access_expr (message,
12746 : get_identifier ("size"),
12747 : false, complain);
12748 976 : if (message_sz != error_mark_node)
12749 889 : message_data
12750 889 : = finish_class_member_access_expr (message,
12751 : get_identifier ("data"),
12752 : false, complain);
12753 976 : if (message_sz == error_mark_node || message_data == error_mark_node)
12754 : {
12755 121 : error_at (location, "constexpr string must be a string "
12756 : "literal or object with %<size%> and "
12757 : "%<data%> members");
12758 292 : return false;
12759 : }
12760 855 : releasing_vec size_args, data_args;
12761 855 : message_sz = finish_call_expr (message_sz, &size_args, false, false,
12762 : complain);
12763 855 : message_data = finish_call_expr (message_data, &data_args, false, false,
12764 : complain);
12765 855 : if (message_sz == error_mark_node || message_data == error_mark_node)
12766 : return false;
12767 741 : message_sz = build_converted_constant_expr (size_type_node, message_sz,
12768 : complain);
12769 741 : if (message_sz == error_mark_node)
12770 : {
12771 15 : error_at (location, "constexpr string %<size()%> "
12772 : "must be implicitly convertible to "
12773 : "%<std::size_t%>");
12774 15 : return false;
12775 : }
12776 :
12777 726 : if (allow_char8_t
12778 37 : && POINTER_TYPE_P (TREE_TYPE (message_data))
12779 37 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
12780 37 : == char8_type_node)
12781 736 : && (TYPE_QUALS (TREE_TYPE (TREE_TYPE (message_data)))
12782 : == TYPE_QUAL_CONST))
12783 : return true;
12784 :
12785 716 : message_data = build_converted_constant_expr (const_string_type_node,
12786 : message_data, complain);
12787 716 : if (message_data == error_mark_node)
12788 : {
12789 32 : error_at (location, "constexpr string %<data()%> "
12790 : "must be implicitly convertible to "
12791 : "%<const char*%>");
12792 32 : return false;
12793 : }
12794 855 : }
12795 : return true;
12796 : }
12797 :
12798 : /* Extract constant string at LOCATON into output string STR.
12799 : Returns true if successful, otherwise false. */
12800 :
12801 : bool
12802 405 : cexpr_str::extract (location_t location, tree &str)
12803 : {
12804 405 : const char *msg;
12805 405 : int len;
12806 405 : if (!extract (location, msg, len))
12807 : return false;
12808 343 : str = build_string (len, msg);
12809 343 : return true;
12810 : }
12811 :
12812 : /* Extract constant string at LOCATION into output string MSG with LEN.
12813 : Returns true if successful, otherwise false. */
12814 :
12815 : bool
12816 2162 : cexpr_str::extract (location_t location, const char * &msg, int &len,
12817 : const constexpr_ctx *ctx /* = NULL */,
12818 : bool *non_constant_p /* = NULL */,
12819 : bool *overflow_p /* = NULL */,
12820 : tree *jump_target /* = NULL */)
12821 : {
12822 2162 : tsubst_flags_t complain = tf_warning_or_error;
12823 :
12824 2162 : msg = NULL;
12825 2162 : if (message_sz && message_data)
12826 : {
12827 620 : tree msz;
12828 620 : if (ctx)
12829 : {
12830 55 : msz = cxx_eval_constant_expression (ctx, message_sz, vc_prvalue,
12831 : non_constant_p, overflow_p,
12832 : jump_target);
12833 55 : if (*jump_target || *non_constant_p)
12834 : return false;
12835 : }
12836 : else
12837 565 : msz = cxx_constant_value (message_sz, NULL_TREE, complain);
12838 616 : if (!tree_fits_uhwi_p (msz))
12839 : {
12840 35 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
12841 35 : error_at (location,
12842 : "constexpr string %<size()%> "
12843 : "must be a constant expression");
12844 35 : return false;
12845 : }
12846 581 : else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
12847 : != tree_to_uhwi (msz))
12848 : {
12849 0 : if (!ctx || !cxx_constexpr_quiet_p (ctx))
12850 0 : error_at (location,
12851 : "constexpr string message %<size()%> "
12852 : "%qE too large", msz);
12853 0 : return false;
12854 : }
12855 581 : len = tree_to_uhwi (msz);
12856 581 : tree data;
12857 581 : if (ctx)
12858 : {
12859 51 : data = cxx_eval_constant_expression (ctx, message_data, vc_prvalue,
12860 : non_constant_p, overflow_p,
12861 : jump_target);
12862 51 : if (*jump_target || *non_constant_p)
12863 : return false;
12864 47 : STRIP_NOPS (data);
12865 47 : if (TREE_CODE (data) != ADDR_EXPR)
12866 : {
12867 0 : unhandled:
12868 0 : if (!cxx_constexpr_quiet_p (ctx))
12869 0 : error_at (location, "unhandled return from %<data()%>");
12870 0 : return false;
12871 : }
12872 47 : tree str = TREE_OPERAND (data, 0);
12873 47 : unsigned HOST_WIDE_INT off = 0;
12874 47 : if (TREE_CODE (str) == ARRAY_REF
12875 47 : && tree_fits_uhwi_p (TREE_OPERAND (str, 1)))
12876 : {
12877 6 : off = tree_to_uhwi (TREE_OPERAND (str, 1));
12878 6 : str = TREE_OPERAND (str, 0);
12879 : }
12880 47 : str = cxx_eval_constant_expression (ctx, str, vc_prvalue,
12881 : non_constant_p, overflow_p,
12882 : jump_target);
12883 47 : if (*jump_target || *non_constant_p)
12884 : return false;
12885 47 : if (TREE_CODE (str) == STRING_CST)
12886 : {
12887 42 : if (TREE_STRING_LENGTH (str) < len
12888 42 : || (unsigned) TREE_STRING_LENGTH (str) < off
12889 84 : || (unsigned) TREE_STRING_LENGTH (str) < off + len)
12890 0 : goto unhandled;
12891 42 : msg = TREE_STRING_POINTER (str) + off;
12892 42 : goto translate;
12893 : }
12894 5 : if (TREE_CODE (str) != CONSTRUCTOR
12895 5 : || TREE_CODE (TREE_TYPE (str)) != ARRAY_TYPE)
12896 0 : goto unhandled;
12897 5 : char *b;
12898 5 : if (len < 64)
12899 5 : b = XALLOCAVEC (char, len + 1);
12900 : else
12901 : {
12902 0 : buf = XNEWVEC (char, len + 1);
12903 0 : b = buf;
12904 : }
12905 5 : msg = b;
12906 5 : memset (b, 0, len + 1);
12907 5 : tree field, value;
12908 5 : unsigned k;
12909 5 : unsigned HOST_WIDE_INT l = 0;
12910 79 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (str), k, field, value)
12911 79 : if (!tree_fits_shwi_p (value))
12912 0 : goto unhandled;
12913 79 : else if (field == NULL_TREE)
12914 : {
12915 0 : if (integer_zerop (value))
12916 : break;
12917 0 : if (l >= off && l < off + len)
12918 0 : b[l - off] = tree_to_shwi (value);
12919 0 : ++l;
12920 : }
12921 79 : else if (TREE_CODE (field) == RANGE_EXPR)
12922 : {
12923 0 : tree lo = TREE_OPERAND (field, 0);
12924 0 : tree hi = TREE_OPERAND (field, 1);
12925 0 : if (!tree_fits_uhwi_p (lo) || !tree_fits_uhwi_p (hi))
12926 0 : goto unhandled;
12927 0 : if (integer_zerop (value))
12928 : break;
12929 0 : unsigned HOST_WIDE_INT m = tree_to_uhwi (hi);
12930 0 : for (l = tree_to_uhwi (lo); l <= m; ++l)
12931 0 : if (l >= off && l < off + len)
12932 0 : b[l - off] = tree_to_shwi (value);
12933 : }
12934 79 : else if (tree_fits_uhwi_p (field))
12935 : {
12936 79 : l = tree_to_uhwi (field);
12937 79 : if (integer_zerop (value))
12938 : break;
12939 74 : if (l >= off && l < off + len)
12940 74 : b[l - off] = tree_to_shwi (value);
12941 74 : l++;
12942 : }
12943 5 : b[len] = '\0';
12944 : }
12945 : else
12946 : {
12947 530 : data = maybe_constant_value (message_data, NULL_TREE, mce_true);
12948 530 : if (!reduced_constant_expression_p (data))
12949 96 : data = NULL_TREE;
12950 530 : if (len)
12951 : {
12952 453 : if (data)
12953 379 : msg = c_getstr (data);
12954 453 : if (msg == NULL)
12955 119 : buf = XNEWVEC (char, len);
12956 1452 : for (int i = 0; i < len; ++i)
12957 : {
12958 1029 : tree t = message_data;
12959 1029 : if (i)
12960 1152 : t = build2 (POINTER_PLUS_EXPR,
12961 576 : TREE_TYPE (message_data), message_data,
12962 576 : size_int (i));
12963 1029 : t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
12964 1029 : tree t2 = cxx_constant_value (t, NULL_TREE, complain);
12965 1029 : if (!tree_fits_shwi_p (t2))
12966 : {
12967 30 : error_at (location,
12968 : "constexpr string %<data()[%d]%> "
12969 : "must be a constant expression", i);
12970 30 : return false;
12971 : }
12972 999 : if (msg == NULL)
12973 362 : buf[i] = tree_to_shwi (t2);
12974 : /* If c_getstr worked, just verify the first and
12975 : last characters using constant evaluation. */
12976 637 : else if (len > 2 && i == 0)
12977 266 : i = len - 2;
12978 : }
12979 423 : if (msg == NULL)
12980 104 : msg = buf;
12981 : }
12982 77 : else if (!data)
12983 : {
12984 : /* We don't have any function to test whether some
12985 : expression is a core constant expression. So, instead
12986 : test whether (message.data (), 0) is a constant
12987 : expression. */
12988 22 : data = build2 (COMPOUND_EXPR, integer_type_node,
12989 : message_data, integer_zero_node);
12990 22 : tree t = cxx_constant_value (data, NULL_TREE, complain);
12991 22 : if (!integer_zerop (t))
12992 : {
12993 22 : error_at (location,
12994 : "constexpr string %<data()%> "
12995 : "must be a core constant expression");
12996 22 : return false;
12997 : }
12998 : }
12999 : }
13000 : }
13001 : else
13002 : {
13003 1542 : tree eltype = TREE_TYPE (TREE_TYPE (message));
13004 1542 : int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
13005 1542 : msg = TREE_STRING_POINTER (message);
13006 1542 : len = TREE_STRING_LENGTH (message) / sz - 1;
13007 : }
13008 2067 : translate:
13009 2067 : if ((message_sz && message_data) || ctx)
13010 : {
13011 : /* Convert the string from execution charset to SOURCE_CHARSET. */
13012 618 : cpp_string istr, ostr;
13013 618 : istr.len = len;
13014 618 : istr.text = (const unsigned char *) msg;
13015 618 : enum cpp_ttype type = CPP_STRING;
13016 618 : if (message_sz && message_data)
13017 : {
13018 525 : if (POINTER_TYPE_P (TREE_TYPE (message_data))
13019 525 : && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message_data)))
13020 525 : == char8_type_node))
13021 : type = CPP_UTF8STRING;
13022 : }
13023 93 : else if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (message)))
13024 93 : == char8_type_node)
13025 618 : type = CPP_UTF8STRING;
13026 618 : if (len == 0)
13027 : ;
13028 530 : else if (!cpp_translate_string (parse_in, &istr, &ostr, type,
13029 : true))
13030 : {
13031 0 : if (type == CPP_UTF8STRING)
13032 0 : error_at (location, "could not convert constexpr string from "
13033 : "UTF-8 encoding to source character "
13034 : "set");
13035 : else
13036 0 : error_at (location, "could not convert constexpr string from "
13037 : "ordinary literal encoding to source character "
13038 : "set");
13039 0 : return false;
13040 : }
13041 : else
13042 : {
13043 530 : if (buf)
13044 104 : XDELETEVEC (buf);
13045 530 : msg = buf = const_cast <char *> ((const char *) ostr.text);
13046 530 : len = ostr.len;
13047 : }
13048 : }
13049 :
13050 : return true;
13051 : }
13052 :
13053 : /* Build a STATIC_ASSERT for a static assertion with the condition
13054 : CONDITION and the message text MESSAGE. LOCATION is the location
13055 : of the static assertion in the source code. When MEMBER_P, this
13056 : static assertion is a member of a class. If SHOW_EXPR_P is true,
13057 : print the condition (because it was instantiation-dependent).
13058 : If CONSTEVAL_BLOCK_P is true, this static assertion represents
13059 : a consteval block. */
13060 :
13061 : void
13062 10488551 : finish_static_assert (tree condition, tree message, location_t location,
13063 : bool member_p, bool show_expr_p,
13064 : bool consteval_block_p/*=false*/)
13065 : {
13066 10488551 : tsubst_flags_t complain = tf_warning_or_error;
13067 :
13068 10488551 : if (condition == NULL_TREE
13069 10488551 : || condition == error_mark_node)
13070 4472764 : return;
13071 :
13072 10488387 : if (check_for_bare_parameter_packs (condition))
13073 : return;
13074 :
13075 10488384 : cexpr_str cstr(message);
13076 10488384 : if (!cstr.type_check (location))
13077 : return;
13078 :
13079 : /* Save the condition in case it was a concept check. */
13080 10488290 : tree orig_condition = condition;
13081 :
13082 10488290 : if (instantiation_dependent_expression_p (condition)
13083 10488290 : || instantiation_dependent_expression_p (message))
13084 : {
13085 : /* We're in a template; build a STATIC_ASSERT and put it in
13086 : the right place. */
13087 4472236 : defer:
13088 4472236 : tree assertion = make_node (STATIC_ASSERT);
13089 4472236 : STATIC_ASSERT_CONDITION (assertion) = orig_condition;
13090 4472236 : STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
13091 4472236 : STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
13092 4472236 : CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
13093 :
13094 4472236 : if (member_p)
13095 2323436 : maybe_add_class_template_decl_list (current_class_type,
13096 : assertion,
13097 : /*friend_p=*/0);
13098 : else
13099 2148800 : add_stmt (assertion);
13100 :
13101 4472236 : return;
13102 : }
13103 :
13104 : /* Evaluate the consteval { }. This must be done only once. */
13105 6019378 : if (consteval_block_p)
13106 : {
13107 242 : cxx_constant_value (condition);
13108 242 : return;
13109 : }
13110 :
13111 : /* Fold the expression and convert it to a boolean value. */
13112 6019136 : condition = contextual_conv_bool (condition, complain);
13113 6019136 : condition = fold_non_dependent_expr (condition, complain,
13114 : /*manifestly_const_eval=*/true);
13115 :
13116 6019135 : if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
13117 : /* Do nothing; the condition is satisfied. */
13118 : ;
13119 : else
13120 : {
13121 5458 : iloc_sentinel ils (location);
13122 :
13123 5458 : if (integer_zerop (condition))
13124 : {
13125 : /* CWG2518: static_assert failure in a template is not IFNDR. */
13126 4933 : if (processing_template_decl)
13127 3324 : goto defer;
13128 :
13129 1609 : int len;
13130 1609 : const char *msg = NULL;
13131 1609 : if (!cstr.extract (location, msg, len))
13132 25 : return;
13133 :
13134 : /* See if we can find which clause was failing (for logical AND). */
13135 1584 : tree bad = find_failing_clause (NULL, orig_condition);
13136 : /* If not, or its location is unusable, fall back to the previous
13137 : location. */
13138 1584 : location_t cloc = cp_expr_loc_or_loc (bad, location);
13139 :
13140 1584 : auto_diagnostic_group d;
13141 :
13142 : /* Report the error. */
13143 1584 : if (len == 0)
13144 987 : error_at (cloc, "static assertion failed");
13145 : else
13146 597 : error_at (cloc, "static assertion failed: %.*s", len, msg);
13147 :
13148 1584 : diagnose_failing_condition (bad, cloc, show_expr_p);
13149 :
13150 : /* Suppress -Wreturn-type for functions with failed static_asserts.
13151 : Otherwise templates like:
13152 : if constexpr (whatever)
13153 : return something (args);
13154 : else
13155 : static_assert (false, "explanation");
13156 : get a useless extra -Wreturn-type warning. */
13157 1584 : if (current_function_decl)
13158 583 : suppress_warning (current_function_decl, OPT_Wreturn_type);
13159 1584 : }
13160 525 : else if (condition && condition != error_mark_node)
13161 : {
13162 522 : error ("non-constant condition for static assertion");
13163 522 : if (require_rvalue_constant_expression (condition))
13164 466 : cxx_constant_value (condition);
13165 : }
13166 5458 : }
13167 10488383 : }
13168 :
13169 : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
13170 : suitable for use as a type-specifier.
13171 :
13172 : ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
13173 : id-expression or a class member access, FALSE when it was parsed as
13174 : a full expression. */
13175 :
13176 : tree
13177 37908801 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
13178 : tsubst_flags_t complain)
13179 : {
13180 37908801 : tree type = NULL_TREE;
13181 :
13182 37908801 : if (!expr || error_operand_p (expr))
13183 210414 : return error_mark_node;
13184 :
13185 37698387 : if (TYPE_P (expr)
13186 37698387 : || TREE_CODE (expr) == TYPE_DECL
13187 75396755 : || (TREE_CODE (expr) == BIT_NOT_EXPR
13188 13416 : && TYPE_P (TREE_OPERAND (expr, 0))))
13189 : {
13190 28 : if (complain & tf_error)
13191 28 : error ("argument to %<decltype%> must be an expression");
13192 28 : return error_mark_node;
13193 : }
13194 :
13195 : /* decltype is an unevaluated context. */
13196 37698359 : cp_unevaluated u;
13197 :
13198 37698359 : processing_template_decl_sentinel ptds (/*reset=*/false);
13199 :
13200 : /* Depending on the resolution of DR 1172, we may later need to distinguish
13201 : instantiation-dependent but not type-dependent expressions so that, say,
13202 : A<decltype(sizeof(T))>::U doesn't require 'typename'. */
13203 37698359 : if (instantiation_dependent_uneval_expression_p (expr))
13204 : {
13205 6838847 : dependent:
13206 6839231 : type = cxx_make_type (DECLTYPE_TYPE);
13207 6839231 : DECLTYPE_TYPE_EXPR (type) = expr;
13208 13678462 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
13209 6839231 : = id_expression_or_member_access_p;
13210 6839231 : SET_TYPE_STRUCTURAL_EQUALITY (type);
13211 :
13212 6839231 : return type;
13213 : }
13214 30859512 : else if (processing_template_decl)
13215 : {
13216 4676 : expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
13217 4676 : if (expr == error_mark_node)
13218 : return error_mark_node;
13219 : /* Keep processing_template_decl cleared for the rest of the function
13220 : (for sake of the call to lvalue_kind below, which handles templated
13221 : and non-templated COND_EXPR differently). */
13222 4639 : processing_template_decl = 0;
13223 : }
13224 :
13225 : /* The type denoted by decltype(e) is defined as follows: */
13226 :
13227 30859475 : expr = resolve_nondeduced_context (expr, complain);
13228 30859475 : if (!mark_single_function (expr, complain))
13229 0 : return error_mark_node;
13230 :
13231 30859475 : if (invalid_nonstatic_memfn_p (input_location, expr, complain))
13232 18 : return error_mark_node;
13233 :
13234 30859457 : if (type_unknown_p (expr))
13235 : {
13236 18 : if (complain & tf_error)
13237 6 : error ("%<decltype%> cannot resolve address of overloaded function");
13238 18 : return error_mark_node;
13239 : }
13240 :
13241 30859439 : if (id_expression_or_member_access_p)
13242 : {
13243 : /* If e is an id-expression or a class member access (5.2.5
13244 : [expr.ref]), decltype(e) is defined as the type of the entity
13245 : named by e. If there is no such entity, or e names a set of
13246 : overloaded functions, the program is ill-formed. */
13247 410545 : if (identifier_p (expr))
13248 0 : expr = lookup_name (expr);
13249 :
13250 : /* If e is a constified expression inside a contract assertion,
13251 : strip the const wrapper. Per P2900R14, "For a function f with the
13252 : return type T , the result name is an lvalue of type const T , decltype(r)
13253 : is T , and decltype((r)) is const T&." */
13254 410545 : expr = strip_contract_const_wrapper (expr);
13255 :
13256 410545 : if (INDIRECT_REF_P (expr)
13257 410545 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
13258 : /* This can happen when the expression is, e.g., "a.b". Just
13259 : look at the underlying operand. */
13260 277543 : expr = TREE_OPERAND (expr, 0);
13261 :
13262 410545 : if (TREE_CODE (expr) == OFFSET_REF
13263 410545 : || TREE_CODE (expr) == MEMBER_REF
13264 410545 : || TREE_CODE (expr) == SCOPE_REF)
13265 : /* We're only interested in the field itself. If it is a
13266 : BASELINK, we will need to see through it in the next
13267 : step. */
13268 0 : expr = TREE_OPERAND (expr, 1);
13269 :
13270 410545 : if (BASELINK_P (expr))
13271 : /* See through BASELINK nodes to the underlying function. */
13272 5 : expr = BASELINK_FUNCTIONS (expr);
13273 :
13274 : /* decltype of a decomposition name drops references in the tuple case
13275 : (unlike decltype of a normal variable) and keeps cv-qualifiers from
13276 : the containing object in the other cases (unlike decltype of a member
13277 : access expression). */
13278 410545 : if (DECL_DECOMPOSITION_P (expr))
13279 : {
13280 1413 : if (ptds.saved)
13281 : {
13282 275 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr)
13283 : || (DECL_CONTEXT (expr)
13284 : != current_function_decl));
13285 : /* DECL_HAS_VALUE_EXPR_P is always set if
13286 : processing_template_decl at least for structured bindings
13287 : within the template. If lookup_decomp_type
13288 : returns non-NULL, it is the tuple case. */
13289 275 : if (tree ret = lookup_decomp_type (expr))
13290 : return ret;
13291 191 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
13292 : }
13293 1329 : if (DECL_HAS_VALUE_EXPR_P (expr))
13294 : /* Expr is an array or struct subobject proxy, handle
13295 : bit-fields properly. */
13296 1017 : return unlowered_expr_type (expr);
13297 : else
13298 : /* Expr is a reference variable for the tuple case. */
13299 312 : return lookup_decomp_type (expr);
13300 : }
13301 :
13302 409132 : switch (TREE_CODE (expr))
13303 : {
13304 240 : case FIELD_DECL:
13305 240 : if (DECL_BIT_FIELD_TYPE (expr))
13306 : {
13307 : type = DECL_BIT_FIELD_TYPE (expr);
13308 : break;
13309 : }
13310 : /* Fall through for fields that aren't bitfields. */
13311 117415 : gcc_fallthrough ();
13312 :
13313 117415 : case VAR_DECL:
13314 117415 : if (is_capture_proxy (expr))
13315 : {
13316 85 : if (is_normal_capture_proxy (expr))
13317 : {
13318 21 : expr = DECL_CAPTURED_VARIABLE (expr);
13319 21 : type = TREE_TYPE (expr);
13320 : }
13321 : else
13322 : {
13323 64 : expr = DECL_VALUE_EXPR (expr);
13324 64 : gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
13325 64 : expr = TREE_OPERAND (expr, 1);
13326 64 : type = TREE_TYPE (expr);
13327 : }
13328 : break;
13329 : }
13330 : /* Fall through for variables that aren't capture proxies. */
13331 405173 : gcc_fallthrough ();
13332 :
13333 405173 : case FUNCTION_DECL:
13334 405173 : case CONST_DECL:
13335 405173 : case PARM_DECL:
13336 405173 : case RESULT_DECL:
13337 405173 : case TEMPLATE_PARM_INDEX:
13338 405173 : expr = mark_type_use (expr);
13339 405173 : type = TREE_TYPE (expr);
13340 405173 : if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
13341 : {
13342 : /* decltype of an NTTP object is the type of the template
13343 : parameter, which is the object type modulo cv-quals. */
13344 1347 : int quals = cp_type_quals (type);
13345 1347 : gcc_checking_assert (quals & TYPE_QUAL_CONST);
13346 1347 : type = cv_unqualified (type);
13347 : }
13348 : break;
13349 :
13350 0 : case ERROR_MARK:
13351 0 : type = error_mark_node;
13352 0 : break;
13353 :
13354 3077 : case COMPONENT_REF:
13355 3077 : case COMPOUND_EXPR:
13356 3077 : mark_type_use (expr);
13357 3077 : type = is_bitfield_expr_with_lowered_type (expr);
13358 3077 : if (!type)
13359 3042 : type = TREE_TYPE (TREE_OPERAND (expr, 1));
13360 : break;
13361 :
13362 0 : case BIT_FIELD_REF:
13363 0 : gcc_unreachable ();
13364 :
13365 246 : case INTEGER_CST:
13366 246 : case PTRMEM_CST:
13367 : /* We can get here when the id-expression refers to an
13368 : enumerator or non-type template parameter. */
13369 246 : type = TREE_TYPE (expr);
13370 246 : break;
13371 :
13372 551 : default:
13373 : /* Handle instantiated template non-type arguments. */
13374 551 : type = TREE_TYPE (expr);
13375 551 : break;
13376 : }
13377 : }
13378 : else
13379 : {
13380 30448894 : tree decl = STRIP_REFERENCE_REF (expr);
13381 30448894 : tree lam = current_lambda_expr ();
13382 30448894 : if (lam && outer_automatic_var_p (decl))
13383 : {
13384 : /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
13385 : unevaluated operand within S would refer to an entity captured by
13386 : copy in some intervening lambda-expression, then let E be the
13387 : innermost such lambda-expression.
13388 :
13389 : If there is such a lambda-expression and if P is in E's function
13390 : parameter scope but not its parameter-declaration-clause, then the
13391 : type of the expression is the type of a class member access
13392 : expression naming the non-static data member that would be declared
13393 : for such a capture in the object parameter of the function call
13394 : operator of E." */
13395 : /* FIXME: This transformation needs to happen for all uses of an outer
13396 : local variable inside decltype, not just decltype((x)) (PR83167).
13397 : And we don't handle nested lambdas properly, where we need to
13398 : consider the outer lambdas as well (PR112926). */
13399 940 : tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
13400 : LOOK_want::HIDDEN_LAMBDA);
13401 :
13402 940 : if (cap && is_capture_proxy (cap))
13403 319 : type = TREE_TYPE (cap);
13404 621 : else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
13405 : {
13406 500 : type = TREE_TYPE (decl);
13407 500 : if (TYPE_REF_P (type)
13408 500 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
13409 25 : type = TREE_TYPE (type);
13410 : }
13411 :
13412 819 : if (type && !TYPE_REF_P (type))
13413 : {
13414 761 : int quals;
13415 761 : if (current_function_decl
13416 1428 : && LAMBDA_FUNCTION_P (current_function_decl)
13417 1428 : && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
13418 : {
13419 600 : tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
13420 600 : if (WILDCARD_TYPE_P (non_reference (obtype)))
13421 : /* We don't know what the eventual obtype quals will be. */
13422 384 : goto dependent;
13423 432 : auto direct_type = [](tree t){
13424 216 : if (INDIRECT_TYPE_P (t))
13425 108 : return TREE_TYPE (t);
13426 : return t;
13427 : };
13428 432 : quals = (cp_type_quals (type)
13429 216 : | cp_type_quals (direct_type (obtype)));
13430 : }
13431 : else
13432 : /* We are in the parameter clause, trailing return type, or
13433 : the requires clause and have no relevant c_f_decl yet. */
13434 251 : quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
13435 161 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
13436 377 : type = cp_build_qualified_type (type, quals);
13437 377 : type = build_reference_type (type);
13438 : }
13439 : }
13440 30447954 : else if (error_operand_p (expr))
13441 0 : type = error_mark_node;
13442 30447954 : else if (expr == current_class_ptr)
13443 : /* If the expression is just "this", we want the
13444 : cv-unqualified pointer for the "this" type. */
13445 0 : type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
13446 :
13447 377 : if (!type)
13448 : {
13449 : /* Otherwise, where T is the type of e, if e is an lvalue,
13450 : decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
13451 30448075 : cp_lvalue_kind clk = lvalue_kind (expr);
13452 30448075 : type = unlowered_expr_type (expr);
13453 30448075 : gcc_assert (!TYPE_REF_P (type));
13454 :
13455 : /* For vector types, pick a non-opaque variant. */
13456 30448075 : if (VECTOR_TYPE_P (type))
13457 2079 : type = strip_typedefs (type);
13458 :
13459 30448075 : if (clk != clk_none && !(clk & clk_class))
13460 8782860 : type = cp_build_reference_type (type, (clk & clk_rvalueref));
13461 : }
13462 : }
13463 :
13464 : return type;
13465 37698359 : }
13466 :
13467 : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
13468 : __has_nothrow_copy, depending on assign_p. Returns true iff all
13469 : the copy {ctor,assign} fns are nothrow. */
13470 :
13471 : static bool
13472 279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
13473 : {
13474 279 : tree fns = NULL_TREE;
13475 :
13476 279 : if (assign_p || TYPE_HAS_COPY_CTOR (type))
13477 276 : fns = get_class_binding (type, assign_p ? assign_op_identifier
13478 : : ctor_identifier);
13479 :
13480 279 : bool saw_copy = false;
13481 696 : for (ovl_iterator iter (fns); iter; ++iter)
13482 : {
13483 441 : tree fn = *iter;
13484 :
13485 441 : if (copy_fn_p (fn) > 0)
13486 : {
13487 423 : saw_copy = true;
13488 423 : if (!maybe_instantiate_noexcept (fn)
13489 423 : || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
13490 192 : return false;
13491 : }
13492 : }
13493 :
13494 87 : return saw_copy;
13495 : }
13496 :
13497 : /* Return true if BASE is a pointer-interconvertible base of DERIVED. */
13498 :
13499 : bool
13500 157 : pointer_interconvertible_base_of_p (tree base, tree derived,
13501 : bool explain/*=false*/)
13502 : {
13503 157 : if (base == error_mark_node || derived == error_mark_node)
13504 : return false;
13505 :
13506 157 : base = TYPE_MAIN_VARIANT (base);
13507 157 : derived = TYPE_MAIN_VARIANT (derived);
13508 157 : if (!NON_UNION_CLASS_TYPE_P (base))
13509 : {
13510 15 : if (explain)
13511 3 : inform (location_of (base),
13512 : "%qT is not a non-union class type", base);
13513 15 : return false;
13514 : }
13515 142 : if (!NON_UNION_CLASS_TYPE_P (derived))
13516 : {
13517 6 : if (explain)
13518 3 : inform (location_of (derived),
13519 : "%qT is not a non-union class type", derived);
13520 6 : return false;
13521 : }
13522 :
13523 136 : if (same_type_p (base, derived))
13524 : return true;
13525 :
13526 106 : if (!std_layout_type_p (derived))
13527 : {
13528 17 : if (explain)
13529 6 : inform (location_of (derived),
13530 : "%qT is not a standard-layout type", derived);
13531 17 : return false;
13532 : }
13533 :
13534 89 : if (!uniquely_derived_from_p (base, derived))
13535 : {
13536 16 : if (explain)
13537 : {
13538 : /* An ambiguous base should already be impossible due to
13539 : the std_layout_type_p check. */
13540 3 : gcc_checking_assert (!DERIVED_FROM_P (base, derived));
13541 3 : inform (location_of (derived),
13542 : "%qT is not a base of %qT", base, derived);
13543 : }
13544 16 : return false;
13545 : }
13546 :
13547 : return true;
13548 : }
13549 :
13550 : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
13551 : return true if MEMBERTYPE is the type of the first non-static data member
13552 : of TYPE or for unions of any members. */
13553 : static bool
13554 637 : first_nonstatic_data_member_p (tree type, tree membertype)
13555 : {
13556 1297 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
13557 : {
13558 1222 : if (TREE_CODE (field) != FIELD_DECL)
13559 135 : continue;
13560 1087 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
13561 60 : continue;
13562 1027 : if (DECL_FIELD_IS_BASE (field))
13563 45 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
13564 982 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13565 : {
13566 216 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
13567 138 : || std_layout_type_p (TREE_TYPE (field)))
13568 294 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
13569 : return true;
13570 : }
13571 766 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13572 : membertype))
13573 : return true;
13574 537 : if (TREE_CODE (type) != UNION_TYPE)
13575 : return false;
13576 : }
13577 : return false;
13578 : }
13579 :
13580 : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
13581 :
13582 : tree
13583 536 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
13584 : tree *args)
13585 : {
13586 : /* Unless users call the builtin directly, the following 3 checks should be
13587 : ensured from std::is_pointer_interconvertible_with_class function
13588 : template. */
13589 536 : if (nargs != 1)
13590 : {
13591 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13592 : "needs a single argument");
13593 6 : return boolean_false_node;
13594 : }
13595 530 : tree arg = args[0];
13596 530 : if (error_operand_p (arg))
13597 0 : return boolean_false_node;
13598 530 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
13599 : {
13600 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13601 : "argument is not pointer to member");
13602 6 : return boolean_false_node;
13603 : }
13604 :
13605 524 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
13606 18 : return boolean_false_node;
13607 :
13608 506 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
13609 506 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
13610 506 : if (!complete_type_or_else (basetype, NULL_TREE))
13611 3 : return boolean_false_node;
13612 :
13613 503 : if (TREE_CODE (basetype) != UNION_TYPE
13614 503 : && !std_layout_type_p (basetype))
13615 22 : return boolean_false_node;
13616 :
13617 481 : if (!first_nonstatic_data_member_p (basetype, membertype))
13618 132 : return boolean_false_node;
13619 :
13620 349 : if (TREE_CODE (arg) == PTRMEM_CST)
13621 68 : arg = cplus_expand_constant (arg);
13622 :
13623 349 : if (integer_nonzerop (arg))
13624 10 : return boolean_false_node;
13625 339 : if (integer_zerop (arg))
13626 71 : return boolean_true_node;
13627 :
13628 268 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
13629 : build_zero_cst (TREE_TYPE (arg)));
13630 : }
13631 :
13632 : /* Helper function for is_corresponding_member_aggr. Return true if
13633 : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
13634 : union or structure BASETYPE. */
13635 :
13636 : static bool
13637 90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
13638 : {
13639 222 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
13640 192 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
13641 36 : continue;
13642 156 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13643 : membertype))
13644 : {
13645 48 : if (TREE_CODE (arg) != INTEGER_CST
13646 48 : || tree_int_cst_equal (arg, byte_position (field)))
13647 48 : return true;
13648 : }
13649 108 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13650 : {
13651 18 : tree narg = arg;
13652 18 : if (TREE_CODE (basetype) != UNION_TYPE
13653 0 : && TREE_CODE (narg) == INTEGER_CST)
13654 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
13655 18 : if (is_corresponding_member_union (TREE_TYPE (field),
13656 : membertype, narg))
13657 : return true;
13658 : }
13659 : return false;
13660 : }
13661 :
13662 : /* Helper function for fold_builtin_is_corresponding_member call.
13663 : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
13664 : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
13665 : boolean_true_node if they are corresponding members, or for
13666 : non-constant ARG2 the highest member offset for corresponding
13667 : members. */
13668 :
13669 : static tree
13670 550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
13671 : tree arg1, tree basetype2, tree membertype2,
13672 : tree arg2)
13673 : {
13674 550 : tree field1 = TYPE_FIELDS (basetype1);
13675 550 : tree field2 = TYPE_FIELDS (basetype2);
13676 550 : tree ret = boolean_false_node;
13677 2376 : while (1)
13678 : {
13679 1463 : bool r = next_common_initial_sequence (field1, field2);
13680 1463 : if (field1 == NULL_TREE || field2 == NULL_TREE)
13681 : break;
13682 1331 : if (r
13683 1038 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
13684 : membertype1)
13685 1841 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
13686 : membertype2))
13687 : {
13688 504 : tree pos = byte_position (field1);
13689 504 : if (TREE_CODE (arg1) == INTEGER_CST
13690 504 : && tree_int_cst_equal (arg1, pos))
13691 : {
13692 92 : if (TREE_CODE (arg2) == INTEGER_CST)
13693 92 : return boolean_true_node;
13694 : return pos;
13695 : }
13696 412 : else if (TREE_CODE (arg1) != INTEGER_CST)
13697 1188 : ret = pos;
13698 : }
13699 1654 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
13700 944 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
13701 : {
13702 117 : if ((!lookup_attribute ("no_unique_address",
13703 117 : DECL_ATTRIBUTES (field1)))
13704 117 : != !lookup_attribute ("no_unique_address",
13705 117 : DECL_ATTRIBUTES (field2)))
13706 : break;
13707 117 : if (!tree_int_cst_equal (bit_position (field1),
13708 117 : bit_position (field2)))
13709 : break;
13710 99 : bool overlap = true;
13711 99 : tree pos = byte_position (field1);
13712 99 : if (TREE_CODE (arg1) == INTEGER_CST)
13713 : {
13714 27 : tree off1 = fold_convert (sizetype, arg1);
13715 27 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
13716 27 : if (tree_int_cst_lt (off1, pos)
13717 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
13718 : overlap = false;
13719 : }
13720 99 : if (TREE_CODE (arg2) == INTEGER_CST)
13721 : {
13722 27 : tree off2 = fold_convert (sizetype, arg2);
13723 27 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
13724 27 : if (tree_int_cst_lt (off2, pos)
13725 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
13726 : overlap = false;
13727 : }
13728 87 : if (overlap
13729 87 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
13730 126 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
13731 : {
13732 39 : tree narg1 = arg1;
13733 39 : if (TREE_CODE (arg1) == INTEGER_CST)
13734 9 : narg1 = size_binop (MINUS_EXPR,
13735 : fold_convert (sizetype, arg1), pos);
13736 39 : tree narg2 = arg2;
13737 39 : if (TREE_CODE (arg2) == INTEGER_CST)
13738 9 : narg2 = size_binop (MINUS_EXPR,
13739 : fold_convert (sizetype, arg2), pos);
13740 39 : tree t1 = TREE_TYPE (field1);
13741 39 : tree t2 = TREE_TYPE (field2);
13742 39 : tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
13743 : narg1, t2, membertype2,
13744 : narg2);
13745 39 : if (nret != boolean_false_node)
13746 : {
13747 39 : if (nret == boolean_true_node)
13748 : return nret;
13749 30 : if (TREE_CODE (arg1) == INTEGER_CST)
13750 0 : return size_binop (PLUS_EXPR, nret, pos);
13751 30 : ret = size_binop (PLUS_EXPR, nret, pos);
13752 : }
13753 : }
13754 60 : else if (overlap
13755 48 : && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
13756 108 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
13757 : {
13758 48 : tree narg1 = arg1;
13759 48 : if (TREE_CODE (arg1) == INTEGER_CST)
13760 6 : narg1 = size_binop (MINUS_EXPR,
13761 : fold_convert (sizetype, arg1), pos);
13762 48 : tree narg2 = arg2;
13763 48 : if (TREE_CODE (arg2) == INTEGER_CST)
13764 6 : narg2 = size_binop (MINUS_EXPR,
13765 : fold_convert (sizetype, arg2), pos);
13766 48 : if (is_corresponding_member_union (TREE_TYPE (field1),
13767 : membertype1, narg1)
13768 48 : && is_corresponding_member_union (TREE_TYPE (field2),
13769 : membertype2, narg2))
13770 : {
13771 24 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
13772 : "not well defined for anonymous unions");
13773 24 : return boolean_false_node;
13774 : }
13775 : }
13776 : }
13777 1188 : if (!r)
13778 : break;
13779 913 : field1 = DECL_CHAIN (field1);
13780 913 : field2 = DECL_CHAIN (field2);
13781 913 : }
13782 : return ret;
13783 : }
13784 :
13785 : /* Fold __builtin_is_corresponding_member call. */
13786 :
13787 : tree
13788 699 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
13789 : tree *args)
13790 : {
13791 : /* Unless users call the builtin directly, the following 3 checks should be
13792 : ensured from std::is_corresponding_member function template. */
13793 699 : if (nargs != 2)
13794 : {
13795 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13796 : "needs two arguments");
13797 9 : return boolean_false_node;
13798 : }
13799 690 : tree arg1 = args[0];
13800 690 : tree arg2 = args[1];
13801 690 : if (error_operand_p (arg1) || error_operand_p (arg2))
13802 0 : return boolean_false_node;
13803 711 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
13804 705 : || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
13805 : {
13806 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13807 : "argument is not pointer to member");
13808 9 : return boolean_false_node;
13809 : }
13810 :
13811 681 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
13812 681 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
13813 15 : return boolean_false_node;
13814 :
13815 666 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
13816 666 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
13817 666 : if (!complete_type_or_else (basetype1, NULL_TREE))
13818 12 : return boolean_false_node;
13819 :
13820 654 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
13821 654 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
13822 654 : if (!complete_type_or_else (basetype2, NULL_TREE))
13823 12 : return boolean_false_node;
13824 :
13825 627 : if (!NON_UNION_CLASS_TYPE_P (basetype1)
13826 627 : || !NON_UNION_CLASS_TYPE_P (basetype2)
13827 627 : || !std_layout_type_p (basetype1)
13828 1233 : || !std_layout_type_p (basetype2))
13829 51 : return boolean_false_node;
13830 :
13831 : /* If the member types aren't layout compatible, then they
13832 : can't be corresponding members. */
13833 591 : if (!layout_compatible_type_p (membertype1, membertype2))
13834 18 : return boolean_false_node;
13835 :
13836 573 : if (TREE_CODE (arg1) == PTRMEM_CST)
13837 176 : arg1 = cplus_expand_constant (arg1);
13838 573 : if (TREE_CODE (arg2) == PTRMEM_CST)
13839 182 : arg2 = cplus_expand_constant (arg2);
13840 :
13841 573 : if (null_member_pointer_value_p (arg1)
13842 573 : || null_member_pointer_value_p (arg2))
13843 9 : return boolean_false_node;
13844 :
13845 564 : if (TREE_CODE (arg1) == INTEGER_CST
13846 182 : && TREE_CODE (arg2) == INTEGER_CST
13847 746 : && !tree_int_cst_equal (arg1, arg2))
13848 53 : return boolean_false_node;
13849 :
13850 511 : if (TREE_CODE (arg2) == INTEGER_CST
13851 129 : && TREE_CODE (arg1) != INTEGER_CST)
13852 : {
13853 : std::swap (arg1, arg2);
13854 : std::swap (membertype1, membertype2);
13855 : std::swap (basetype1, basetype2);
13856 : }
13857 :
13858 511 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
13859 : basetype2, membertype2, arg2);
13860 511 : if (TREE_TYPE (ret) == boolean_type_node)
13861 : return ret;
13862 : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
13863 : already returns boolean_{true,false}_node whether those particular
13864 : members are corresponding members or not. Otherwise, if only
13865 : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
13866 : above), it returns boolean_false_node if it is certainly not a
13867 : corresponding member and otherwise we need to do a runtime check that
13868 : those two OFFSET_TYPE offsets are equal.
13869 : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
13870 : returns the largest offset at which the members would be corresponding
13871 : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
13872 304 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
13873 304 : if (TREE_CODE (arg1) == INTEGER_CST)
13874 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13875 : fold_convert (TREE_TYPE (arg1), arg2));
13876 304 : ret = fold_build2 (LE_EXPR, boolean_type_node,
13877 : fold_convert (pointer_sized_int_node, arg1),
13878 : fold_convert (pointer_sized_int_node, ret));
13879 304 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
13880 : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13881 : fold_convert (TREE_TYPE (arg1), arg2)));
13882 : }
13883 :
13884 : /* Fold __builtin_is_string_literal call. */
13885 :
13886 : tree
13887 1928 : fold_builtin_is_string_literal (location_t loc, int nargs, tree *args)
13888 : {
13889 : /* Unless users call the builtin directly, the following 3 checks should be
13890 : ensured from std::is_string_literal overloads. */
13891 1928 : if (nargs != 1)
13892 : {
13893 0 : error_at (loc, "%<__builtin_is_string_literal%> needs a single "
13894 : "argument");
13895 0 : return boolean_false_node;
13896 : }
13897 1928 : tree arg = args[0];
13898 1928 : if (error_operand_p (arg))
13899 0 : return boolean_false_node;
13900 1928 : if (!TYPE_PTR_P (TREE_TYPE (arg))
13901 1928 : || !TYPE_READONLY (TREE_TYPE (TREE_TYPE (arg)))
13902 3856 : || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (arg))))
13903 : {
13904 0 : arg_invalid:
13905 0 : error_at (loc, "%<__builtin_is_string_literal%> "
13906 : "argument is not %<const char*%>, %<const wchar_t*%>, "
13907 : "%<const char8_t*%>, %<const char16_t*%> or "
13908 : "%<const char32_t*%>");
13909 0 : return boolean_false_node;
13910 : }
13911 1928 : tree chart = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg)));
13912 1928 : if (chart != char_type_node
13913 1540 : && chart != wchar_type_node
13914 1155 : && chart != char8_type_node
13915 770 : && chart != char16_type_node
13916 385 : && chart != char32_type_node)
13917 0 : goto arg_invalid;
13918 :
13919 1928 : STRIP_NOPS (arg);
13920 3862 : while (TREE_CODE (arg) == POINTER_PLUS_EXPR)
13921 : {
13922 6 : arg = TREE_OPERAND (arg, 0);
13923 6 : STRIP_NOPS (arg);
13924 : }
13925 1928 : if (TREE_CODE (arg) != ADDR_EXPR)
13926 1900 : return boolean_false_node;
13927 28 : arg = TREE_OPERAND (arg, 0);
13928 28 : if (TREE_CODE (arg) == ARRAY_REF)
13929 12 : arg = TREE_OPERAND (arg, 0);
13930 28 : if (TREE_CODE (arg) != STRING_CST)
13931 8 : return boolean_false_node;
13932 20 : return boolean_true_node;
13933 : }
13934 :
13935 : /* [basic.types] 8. True iff TYPE is an object type. */
13936 :
13937 : static bool
13938 2762175 : object_type_p (const_tree type)
13939 : {
13940 2762175 : return (TREE_CODE (type) != FUNCTION_TYPE
13941 0 : && !TYPE_REF_P (type)
13942 2762175 : && !VOID_TYPE_P (type));
13943 : }
13944 :
13945 : /* [defns.referenceable] True iff TYPE is a referenceable type. */
13946 :
13947 : static bool
13948 3405030 : referenceable_type_p (const_tree type)
13949 : {
13950 3405030 : return (TYPE_REF_P (type)
13951 3405425 : || object_type_p (type)
13952 3405425 : || (FUNC_OR_METHOD_TYPE_P (type)
13953 333 : && type_memfn_quals (type) == TYPE_UNQUALIFIED
13954 273 : && type_memfn_rqual (type) == REF_QUAL_NONE));
13955 : }
13956 :
13957 : /* Actually evaluates the trait. */
13958 :
13959 : static bool
13960 17271097 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
13961 : {
13962 17271097 : enum tree_code type_code1;
13963 17271097 : tree t;
13964 :
13965 17271097 : type_code1 = TREE_CODE (type1);
13966 :
13967 17271097 : switch (kind)
13968 : {
13969 317 : case CPTK_HAS_NOTHROW_ASSIGN:
13970 317 : type1 = strip_array_types (type1);
13971 601 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
13972 601 : && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
13973 173 : || (CLASS_TYPE_P (type1)
13974 129 : && classtype_has_nothrow_assign_or_copy_p (type1,
13975 : true))));
13976 :
13977 215 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
13978 215 : type1 = strip_array_types (type1);
13979 215 : return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
13980 215 : || (CLASS_TYPE_P (type1)
13981 93 : && (t = locate_ctor (type1))
13982 60 : && maybe_instantiate_noexcept (t)
13983 58 : && TYPE_NOTHROW_P (TREE_TYPE (t))));
13984 :
13985 305 : case CPTK_HAS_NOTHROW_COPY:
13986 305 : type1 = strip_array_types (type1);
13987 305 : return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
13988 305 : || (CLASS_TYPE_P (type1)
13989 150 : && classtype_has_nothrow_assign_or_copy_p (type1, false)));
13990 :
13991 517 : case CPTK_HAS_TRIVIAL_ASSIGN:
13992 : /* ??? The standard seems to be missing the "or array of such a class
13993 : type" wording for this trait. */
13994 517 : type1 = strip_array_types (type1);
13995 1016 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
13996 1001 : && (trivial_type_p (type1)
13997 307 : || (CLASS_TYPE_P (type1)
13998 222 : && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
13999 :
14000 505 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14001 505 : type1 = strip_array_types (type1);
14002 505 : return (trivial_type_p (type1)
14003 505 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
14004 :
14005 526 : case CPTK_HAS_TRIVIAL_COPY:
14006 : /* ??? The standard seems to be missing the "or array of such a class
14007 : type" wording for this trait. */
14008 526 : type1 = strip_array_types (type1);
14009 878 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14010 863 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
14011 :
14012 761 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14013 761 : type1 = strip_array_types (type1);
14014 761 : if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
14015 : {
14016 123 : deferring_access_check_sentinel dacs (dk_no_check);
14017 123 : cp_unevaluated un;
14018 123 : tree fn = get_dtor (type1, tf_none);
14019 123 : if (!fn && !seen_error ())
14020 3 : warning (0, "checking %qs for type %qT with a destructor that "
14021 : "cannot be called", "__has_trivial_destructor", type1);
14022 123 : }
14023 1092 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
14024 1089 : || (CLASS_TYPE_P (type1)
14025 284 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
14026 :
14027 58029 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14028 58029 : return type_has_unique_obj_representations (type1);
14029 :
14030 279 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14031 279 : return type_has_virtual_destructor (type1);
14032 :
14033 54682 : case CPTK_IS_ABSTRACT:
14034 54682 : return ABSTRACT_CLASS_TYPE_P (type1);
14035 :
14036 813 : case CPTK_IS_AGGREGATE:
14037 813 : return CP_AGGREGATE_TYPE_P (type1);
14038 :
14039 333318 : case CPTK_IS_ARRAY:
14040 333318 : return (type_code1 == ARRAY_TYPE
14041 : /* We don't want to report T[0] as being an array type.
14042 : This is for compatibility with an implementation of
14043 : std::is_array by template argument deduction, because
14044 : compute_array_index_type_loc rejects a zero-size array
14045 : in SFINAE context. */
14046 333318 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14047 :
14048 988742 : case CPTK_IS_ASSIGNABLE:
14049 988742 : return is_xible (MODIFY_EXPR, type1, type2);
14050 :
14051 489340 : case CPTK_IS_BASE_OF:
14052 489249 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14053 960391 : && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
14054 445698 : || DERIVED_FROM_P (type1, type2)));
14055 :
14056 42579 : case CPTK_IS_BOUNDED_ARRAY:
14057 42579 : return (type_code1 == ARRAY_TYPE
14058 1251 : && TYPE_DOMAIN (type1)
14059 : /* We don't want to report T[0] as being a bounded array type.
14060 : This is for compatibility with an implementation of
14061 : std::is_bounded_array by template argument deduction, because
14062 : compute_array_index_type_loc rejects a zero-size array
14063 : in SFINAE context. */
14064 43714 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
14065 :
14066 501972 : case CPTK_IS_CLASS:
14067 501972 : return NON_UNION_CLASS_TYPE_P (type1);
14068 :
14069 581986 : case CPTK_IS_CONST:
14070 581986 : return CP_TYPE_CONST_P (type1);
14071 :
14072 2234062 : case CPTK_IS_CONSTRUCTIBLE:
14073 2234062 : return is_xible (INIT_EXPR, type1, type2);
14074 :
14075 3073934 : case CPTK_IS_CONVERTIBLE:
14076 3073934 : return is_convertible (type1, type2);
14077 :
14078 1938 : case CPTK_IS_DESTRUCTIBLE:
14079 1938 : return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14080 :
14081 247776 : case CPTK_IS_EMPTY:
14082 247776 : return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
14083 :
14084 630535 : case CPTK_IS_ENUM:
14085 630535 : return type_code1 == ENUMERAL_TYPE;
14086 :
14087 453171 : case CPTK_IS_FINAL:
14088 453171 : return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
14089 :
14090 45173 : case CPTK_IS_FUNCTION:
14091 45173 : return type_code1 == FUNCTION_TYPE;
14092 :
14093 800 : case CPTK_IS_IMPLICIT_LIFETIME:
14094 800 : return implicit_lifetime_type_p (type1);
14095 :
14096 46343 : case CPTK_IS_INVOCABLE:
14097 46343 : return !error_operand_p (build_invoke (type1, type2, tf_none));
14098 :
14099 195 : case CPTK_IS_LAYOUT_COMPATIBLE:
14100 195 : return layout_compatible_type_p (type1, type2);
14101 :
14102 197 : case CPTK_IS_LITERAL_TYPE:
14103 197 : return literal_type_p (type1);
14104 :
14105 46388 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14106 46388 : return TYPE_PTRMEMFUNC_P (type1);
14107 :
14108 46357 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14109 46357 : return TYPE_PTRDATAMEM_P (type1);
14110 :
14111 10318 : case CPTK_IS_MEMBER_POINTER:
14112 10318 : return TYPE_PTRMEM_P (type1);
14113 :
14114 442771 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14115 442771 : return is_nothrow_xible (MODIFY_EXPR, type1, type2);
14116 :
14117 889539 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14118 889539 : return is_nothrow_xible (INIT_EXPR, type1, type2);
14119 :
14120 667 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14121 667 : return is_nothrow_convertible (type1, type2);
14122 :
14123 23399 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14124 23399 : return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14125 :
14126 40706 : case CPTK_IS_NOTHROW_INVOCABLE:
14127 40706 : return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
14128 :
14129 1096738 : case CPTK_IS_OBJECT:
14130 1096738 : return object_type_p (type1);
14131 :
14132 142 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14133 142 : return pointer_interconvertible_base_of_p (type1, type2);
14134 :
14135 11123 : case CPTK_IS_POD:
14136 11123 : return pod_type_p (type1);
14137 :
14138 145342 : case CPTK_IS_POINTER:
14139 145342 : return TYPE_PTR_P (type1);
14140 :
14141 271 : case CPTK_IS_POLYMORPHIC:
14142 271 : return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
14143 :
14144 713511 : case CPTK_IS_REFERENCE:
14145 713511 : return type_code1 == REFERENCE_TYPE;
14146 :
14147 2481409 : case CPTK_IS_SAME:
14148 2481409 : return same_type_p (type1, type2);
14149 :
14150 373 : case CPTK_IS_SCOPED_ENUM:
14151 373 : return SCOPED_ENUM_P (type1);
14152 :
14153 59596 : case CPTK_IS_STD_LAYOUT:
14154 59596 : return std_layout_type_p (type1);
14155 :
14156 55799 : case CPTK_IS_TRIVIAL:
14157 55799 : return trivial_type_p (type1);
14158 :
14159 10198 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14160 10198 : return is_trivially_xible (MODIFY_EXPR, type1, type2);
14161 :
14162 68761 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14163 68761 : return is_trivially_xible (INIT_EXPR, type1, type2);
14164 :
14165 94244 : case CPTK_IS_TRIVIALLY_COPYABLE:
14166 94244 : return trivially_copyable_p (type1);
14167 :
14168 24708 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14169 24708 : return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14170 :
14171 93148 : case CPTK_IS_UNBOUNDED_ARRAY:
14172 93148 : return array_of_unknown_bound_p (type1);
14173 :
14174 255292 : case CPTK_IS_UNION:
14175 255292 : return type_code1 == UNION_TYPE;
14176 :
14177 712 : case CPTK_IS_VIRTUAL_BASE_OF:
14178 646 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14179 1342 : && lookup_base (type2, type1, ba_require_virtual,
14180 : NULL, tf_none) != NULL_TREE);
14181 :
14182 606933 : case CPTK_IS_VOLATILE:
14183 606933 : return CP_TYPE_VOLATILE_P (type1);
14184 :
14185 211422 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14186 211422 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
14187 :
14188 52004 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14189 52004 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
14190 :
14191 85 : case CPTK_IS_DEDUCIBLE:
14192 85 : return type_targs_deducible_from (type1, type2);
14193 :
14194 131 : case CPTK_IS_STRUCTURAL:
14195 131 : return structural_type_p (type1);
14196 :
14197 : /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
14198 : are handled in finish_trait_expr. */
14199 0 : case CPTK_RANK:
14200 0 : case CPTK_TYPE_ORDER:
14201 0 : case CPTK_STRUCTURED_BINDING_SIZE:
14202 0 : gcc_unreachable ();
14203 :
14204 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14205 : case CPTK_##CODE:
14206 : #include "cp-trait.def"
14207 : #undef DEFTRAIT_TYPE
14208 : /* Type-yielding traits are handled in finish_trait_type. */
14209 : break;
14210 : }
14211 :
14212 0 : gcc_unreachable ();
14213 : }
14214 :
14215 : /* Returns true if TYPE meets the requirements for the specified KIND,
14216 : false otherwise.
14217 :
14218 : When KIND == 1, TYPE must be an array of unknown bound,
14219 : or (possibly cv-qualified) void, or a complete type.
14220 :
14221 : When KIND == 2, TYPE must be a complete type, or array of complete type,
14222 : or (possibly cv-qualified) void.
14223 :
14224 : When KIND == 3:
14225 : If TYPE is a non-union class type, it must be complete.
14226 :
14227 : When KIND == 4:
14228 : If TYPE is a class type, it must be complete. */
14229 :
14230 : static bool
14231 18057349 : check_trait_type (tree type, int kind = 1)
14232 : {
14233 18057349 : if (type == NULL_TREE)
14234 : return true;
14235 :
14236 18057349 : if (TREE_CODE (type) == TREE_VEC)
14237 : {
14238 5817860 : for (tree arg : tree_vec_range (type))
14239 2541694 : if (!check_trait_type (arg, kind))
14240 21 : return false;
14241 3276166 : return true;
14242 : }
14243 :
14244 14781162 : if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
14245 : return true; // Array of unknown bound. Don't care about completeness.
14246 :
14247 14780618 : if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
14248 : return true; // Not a non-union class type. Don't care about completeness.
14249 :
14250 14669146 : if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
14251 : return true; // Not a class type. Don't care about completeness.
14252 :
14253 14668659 : if (VOID_TYPE_P (type))
14254 : return true;
14255 :
14256 14667559 : type = complete_type (strip_array_types (type));
14257 14667559 : if (!COMPLETE_TYPE_P (type)
14258 152 : && cxx_incomplete_type_diagnostic (NULL_TREE, type,
14259 : diagnostics::kind::permerror)
14260 14667711 : && !flag_permissive)
14261 : return false;
14262 : return true;
14263 : }
14264 :
14265 : /* True iff the conversion (if any) would be a direct reference
14266 : binding, not requiring complete types. This is LWG2939. */
14267 :
14268 : static bool
14269 6617498 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
14270 : {
14271 6617498 : tree from, to;
14272 6617498 : switch (kind)
14273 : {
14274 : /* These put the target type first. */
14275 : case CPTK_IS_CONSTRUCTIBLE:
14276 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14277 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14278 : case CPTK_IS_INVOCABLE:
14279 : case CPTK_IS_NOTHROW_INVOCABLE:
14280 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14281 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14282 : to = type1;
14283 : from = type2;
14284 : break;
14285 :
14286 : /* These put it second. */
14287 3074601 : case CPTK_IS_CONVERTIBLE:
14288 3074601 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14289 3074601 : to = type2;
14290 3074601 : from = type1;
14291 3074601 : break;
14292 :
14293 0 : default:
14294 0 : gcc_unreachable ();
14295 : }
14296 :
14297 6617498 : if (TREE_CODE (to) != REFERENCE_TYPE || !from)
14298 : return false;
14299 910785 : if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
14300 58514 : from = TREE_VEC_ELT (from, 0);
14301 910785 : return (TYPE_P (from)
14302 1813623 : && (same_type_ignoring_top_level_qualifiers_p
14303 902838 : (non_reference (to), non_reference (from))));
14304 : }
14305 :
14306 : /* Helper for finish_trait_expr and tsubst_expr. Handle
14307 : CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
14308 : way. */
14309 :
14310 : tree
14311 273 : finish_structured_binding_size (location_t loc, tree type,
14312 : tsubst_flags_t complain)
14313 : {
14314 273 : if (TYPE_REF_P (type))
14315 : {
14316 105 : if (complain & tf_error)
14317 99 : error_at (loc, "%qs argument %qT is a reference",
14318 : "__builtin_structured_binding_size", type);
14319 105 : return error_mark_node;
14320 : }
14321 168 : HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
14322 168 : if (ret == -1)
14323 63 : return error_mark_node;
14324 105 : return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
14325 : }
14326 :
14327 : /* Process a trait expression. */
14328 :
14329 : tree
14330 20534777 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
14331 : {
14332 20534777 : if (type1 == error_mark_node
14333 20534774 : || type2 == error_mark_node)
14334 : return error_mark_node;
14335 :
14336 20534774 : if (processing_template_decl)
14337 : {
14338 3264009 : tree trait_expr = make_node (TRAIT_EXPR);
14339 3264009 : if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
14340 29992 : TREE_TYPE (trait_expr) = size_type_node;
14341 3234017 : else if (kind == CPTK_TYPE_ORDER)
14342 : {
14343 2964 : tree val = type_order_value (type1, type1);
14344 2964 : if (val != error_mark_node)
14345 2964 : TREE_TYPE (trait_expr) = TREE_TYPE (val);
14346 : }
14347 : else
14348 3231053 : TREE_TYPE (trait_expr) = boolean_type_node;
14349 3264009 : TRAIT_EXPR_TYPE1 (trait_expr) = type1;
14350 3264009 : TRAIT_EXPR_TYPE2 (trait_expr) = type2;
14351 3264009 : TRAIT_EXPR_KIND (trait_expr) = kind;
14352 3264009 : TRAIT_EXPR_LOCATION (trait_expr) = loc;
14353 3264009 : return trait_expr;
14354 : }
14355 :
14356 17270765 : switch (kind)
14357 : {
14358 52408 : case CPTK_HAS_NOTHROW_ASSIGN:
14359 52408 : case CPTK_HAS_TRIVIAL_ASSIGN:
14360 52408 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
14361 52408 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14362 52408 : case CPTK_HAS_NOTHROW_COPY:
14363 52408 : case CPTK_HAS_TRIVIAL_COPY:
14364 52408 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14365 52408 : case CPTK_IS_DESTRUCTIBLE:
14366 52408 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14367 52408 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14368 52408 : if (!check_trait_type (type1))
14369 21 : return error_mark_node;
14370 : break;
14371 :
14372 279152 : case CPTK_IS_LITERAL_TYPE:
14373 279152 : case CPTK_IS_POD:
14374 279152 : case CPTK_IS_STD_LAYOUT:
14375 279152 : case CPTK_IS_TRIVIAL:
14376 279152 : case CPTK_IS_TRIVIALLY_COPYABLE:
14377 279152 : case CPTK_IS_STRUCTURAL:
14378 279152 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14379 279152 : if (!check_trait_type (type1, /* kind = */ 2))
14380 33 : return error_mark_node;
14381 : break;
14382 :
14383 303023 : case CPTK_IS_ABSTRACT:
14384 303023 : case CPTK_IS_EMPTY:
14385 303023 : case CPTK_IS_POLYMORPHIC:
14386 303023 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14387 303023 : if (!check_trait_type (type1, /* kind = */ 3))
14388 15 : return error_mark_node;
14389 : break;
14390 :
14391 : /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
14392 : type to know whether an array is an aggregate, so use kind=4 here. */
14393 454801 : case CPTK_IS_AGGREGATE:
14394 454801 : case CPTK_IS_FINAL:
14395 454801 : case CPTK_IS_IMPLICIT_LIFETIME:
14396 454801 : if (!check_trait_type (type1, /* kind = */ 4))
14397 17 : return error_mark_node;
14398 : break;
14399 :
14400 6617498 : case CPTK_IS_CONSTRUCTIBLE:
14401 6617498 : case CPTK_IS_CONVERTIBLE:
14402 6617498 : case CPTK_IS_INVOCABLE:
14403 6617498 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14404 6617498 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14405 6617498 : case CPTK_IS_NOTHROW_INVOCABLE:
14406 6617498 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14407 6617498 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14408 6617498 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14409 6617498 : /* Don't check completeness for direct reference binding. */;
14410 6617498 : if (same_type_ref_bind_p (kind, type1, type2))
14411 : break;
14412 7213155 : gcc_fallthrough ();
14413 :
14414 7213155 : case CPTK_IS_ASSIGNABLE:
14415 7213155 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14416 7213155 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14417 7213155 : if (!check_trait_type (type1)
14418 7213155 : || !check_trait_type (type2))
14419 63 : return error_mark_node;
14420 : break;
14421 :
14422 489485 : case CPTK_IS_BASE_OF:
14423 489485 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14424 489382 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14425 471181 : && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
14426 935283 : && !complete_type_or_else (type2, NULL_TREE))
14427 : /* We already issued an error. */
14428 3 : return error_mark_node;
14429 : break;
14430 :
14431 715 : case CPTK_IS_VIRTUAL_BASE_OF:
14432 649 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14433 1348 : && !complete_type_or_else (type2, NULL_TREE))
14434 : /* We already issued an error. */
14435 3 : return error_mark_node;
14436 : break;
14437 :
14438 : case CPTK_IS_ARRAY:
14439 : case CPTK_IS_BOUNDED_ARRAY:
14440 : case CPTK_IS_CLASS:
14441 : case CPTK_IS_CONST:
14442 : case CPTK_IS_ENUM:
14443 : case CPTK_IS_FUNCTION:
14444 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14445 : case CPTK_IS_MEMBER_OBJECT_POINTER:
14446 : case CPTK_IS_MEMBER_POINTER:
14447 : case CPTK_IS_OBJECT:
14448 : case CPTK_IS_POINTER:
14449 : case CPTK_IS_REFERENCE:
14450 : case CPTK_IS_SAME:
14451 : case CPTK_IS_SCOPED_ENUM:
14452 : case CPTK_IS_UNBOUNDED_ARRAY:
14453 : case CPTK_IS_UNION:
14454 : case CPTK_IS_VOLATILE:
14455 : break;
14456 :
14457 : case CPTK_RANK:
14458 : {
14459 : size_t rank = 0;
14460 122 : for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
14461 80 : ++rank;
14462 42 : return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
14463 : loc);
14464 : }
14465 :
14466 122 : case CPTK_TYPE_ORDER:
14467 122 : return maybe_wrap_with_location (type_order_value (type1, type2), loc);
14468 :
14469 144 : case CPTK_STRUCTURED_BINDING_SIZE:
14470 144 : return finish_structured_binding_size (loc, type1, tf_warning_or_error);
14471 :
14472 204 : case CPTK_IS_LAYOUT_COMPATIBLE:
14473 204 : if (!array_of_unknown_bound_p (type1)
14474 189 : && TREE_CODE (type1) != VOID_TYPE
14475 387 : && !complete_type_or_else (type1, NULL_TREE))
14476 : /* We already issued an error. */
14477 6 : return error_mark_node;
14478 198 : if (!array_of_unknown_bound_p (type2)
14479 177 : && TREE_CODE (type2) != VOID_TYPE
14480 369 : && !complete_type_or_else (type2, NULL_TREE))
14481 : /* We already issued an error. */
14482 3 : return error_mark_node;
14483 : break;
14484 :
14485 85 : case CPTK_IS_DEDUCIBLE:
14486 85 : if (!DECL_TYPE_TEMPLATE_P (type1))
14487 : {
14488 0 : error ("%qD is not a class or alias template", type1);
14489 0 : return error_mark_node;
14490 : }
14491 : break;
14492 :
14493 : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14494 : case CPTK_##CODE:
14495 : #include "cp-trait.def"
14496 : #undef DEFTRAIT_TYPE
14497 : /* Type-yielding traits are handled in finish_trait_type. */
14498 0 : gcc_unreachable ();
14499 : }
14500 :
14501 17270293 : tree val = (trait_expr_value (kind, type1, type2)
14502 17270293 : ? boolean_true_node : boolean_false_node);
14503 17270293 : return maybe_wrap_with_location (val, loc);
14504 : }
14505 :
14506 : /* Process a trait type. */
14507 :
14508 : tree
14509 7581092 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
14510 : tsubst_flags_t complain)
14511 : {
14512 7581092 : if (type1 == error_mark_node
14513 7581089 : || type2 == error_mark_node)
14514 : return error_mark_node;
14515 :
14516 7581089 : if (processing_template_decl)
14517 : {
14518 219890 : tree type = cxx_make_type (TRAIT_TYPE);
14519 219890 : TRAIT_TYPE_TYPE1 (type) = type1;
14520 219890 : TRAIT_TYPE_TYPE2 (type) = type2;
14521 219890 : TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
14522 : /* These traits are intended to be used in the definition of the ::type
14523 : member of the corresponding standard library type trait and aren't
14524 : mangleable (and thus won't appear directly in template signatures),
14525 : so structural equality should suffice. */
14526 219890 : SET_TYPE_STRUCTURAL_EQUALITY (type);
14527 219890 : return type;
14528 : }
14529 :
14530 7361199 : switch (kind)
14531 : {
14532 1194615 : case CPTK_ADD_LVALUE_REFERENCE:
14533 : /* [meta.trans.ref]. */
14534 1194615 : if (referenceable_type_p (type1))
14535 1194540 : return cp_build_reference_type (type1, /*rval=*/false);
14536 : return type1;
14537 :
14538 643198 : case CPTK_ADD_POINTER:
14539 : /* [meta.trans.ptr]. */
14540 643198 : if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
14541 : {
14542 643166 : if (TYPE_REF_P (type1))
14543 642106 : type1 = TREE_TYPE (type1);
14544 643166 : return build_pointer_type (type1);
14545 : }
14546 : return type1;
14547 :
14548 1567237 : case CPTK_ADD_RVALUE_REFERENCE:
14549 : /* [meta.trans.ref]. */
14550 1567237 : if (referenceable_type_p (type1))
14551 1567184 : return cp_build_reference_type (type1, /*rval=*/true);
14552 : return type1;
14553 :
14554 222621 : case CPTK_DECAY:
14555 222621 : if (TYPE_REF_P (type1))
14556 41276 : type1 = TREE_TYPE (type1);
14557 :
14558 222621 : if (TREE_CODE (type1) == ARRAY_TYPE)
14559 670 : return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
14560 670 : complain);
14561 221951 : else if (TREE_CODE (type1) == FUNCTION_TYPE)
14562 177 : return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
14563 : else
14564 221774 : return cv_unqualified (type1);
14565 :
14566 219 : case CPTK_REMOVE_ALL_EXTENTS:
14567 219 : return strip_array_types (type1);
14568 :
14569 949544 : case CPTK_REMOVE_CV:
14570 949544 : return cv_unqualified (type1);
14571 :
14572 429133 : case CPTK_REMOVE_CVREF:
14573 429133 : if (TYPE_REF_P (type1))
14574 160806 : type1 = TREE_TYPE (type1);
14575 429133 : return cv_unqualified (type1);
14576 :
14577 64496 : case CPTK_REMOVE_EXTENT:
14578 64496 : if (TREE_CODE (type1) == ARRAY_TYPE)
14579 9172 : type1 = TREE_TYPE (type1);
14580 : return type1;
14581 :
14582 42227 : case CPTK_REMOVE_POINTER:
14583 42227 : if (TYPE_PTR_P (type1))
14584 39519 : type1 = TREE_TYPE (type1);
14585 : return type1;
14586 :
14587 2093836 : case CPTK_REMOVE_REFERENCE:
14588 2093836 : if (TYPE_REF_P (type1))
14589 1274568 : type1 = TREE_TYPE (type1);
14590 : return type1;
14591 :
14592 107343 : case CPTK_TYPE_PACK_ELEMENT:
14593 107343 : return finish_type_pack_element (type1, type2, complain);
14594 :
14595 46730 : case CPTK_UNDERLYING_TYPE:
14596 46730 : return finish_underlying_type (type1);
14597 :
14598 : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
14599 : case CPTK_##CODE:
14600 : #include "cp-trait.def"
14601 : #undef DEFTRAIT_EXPR
14602 : /* Expression-yielding traits are handled in finish_trait_expr. */
14603 : case CPTK_BASES:
14604 : case CPTK_DIRECT_BASES:
14605 : /* BASES and DIRECT_BASES are handled in finish_bases. */
14606 : break;
14607 : }
14608 :
14609 0 : gcc_unreachable ();
14610 : }
14611 :
14612 : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
14613 : which is ignored for C++. */
14614 :
14615 : void
14616 0 : set_float_const_decimal64 (void)
14617 : {
14618 0 : }
14619 :
14620 : void
14621 0 : clear_float_const_decimal64 (void)
14622 : {
14623 0 : }
14624 :
14625 : bool
14626 1888849 : float_const_decimal64_p (void)
14627 : {
14628 1888849 : return 0;
14629 : }
14630 :
14631 :
14632 : /* Return true if T designates the implied `this' parameter. */
14633 :
14634 : bool
14635 6024563 : is_this_parameter (tree t)
14636 : {
14637 6024563 : if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
14638 : return false;
14639 3578738 : gcc_assert (TREE_CODE (t) == PARM_DECL
14640 : || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
14641 : || (cp_binding_oracle && VAR_P (t)));
14642 : return true;
14643 : }
14644 :
14645 : /* As above, or a C++23 explicit object parameter. */
14646 :
14647 : bool
14648 456 : is_object_parameter (tree t)
14649 : {
14650 456 : if (is_this_parameter (t))
14651 : return true;
14652 91 : if (TREE_CODE (t) != PARM_DECL)
14653 : return false;
14654 34 : tree ctx = DECL_CONTEXT (t);
14655 34 : return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
14656 62 : && t == DECL_ARGUMENTS (ctx));
14657 : }
14658 :
14659 : /* Insert the deduced return type for an auto function. */
14660 :
14661 : void
14662 898767 : apply_deduced_return_type (tree fco, tree return_type)
14663 : {
14664 898767 : tree result;
14665 :
14666 898767 : if (return_type == error_mark_node)
14667 : return;
14668 :
14669 898764 : if (DECL_CONV_FN_P (fco))
14670 42 : DECL_NAME (fco) = make_conv_op_name (return_type);
14671 :
14672 898764 : TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
14673 :
14674 898764 : maybe_update_postconditions (fco);
14675 :
14676 : /* Apply the type to the result object. */
14677 :
14678 898764 : result = DECL_RESULT (fco);
14679 898764 : if (result == NULL_TREE)
14680 : return;
14681 887891 : if (TREE_TYPE (result) == return_type)
14682 : return;
14683 :
14684 887885 : if (!processing_template_decl && !VOID_TYPE_P (return_type)
14685 1646701 : && !complete_type_or_else (return_type, NULL_TREE))
14686 : return;
14687 :
14688 : /* We already have a DECL_RESULT from start_preparsed_function.
14689 : Now we need to redo the work it and allocate_struct_function
14690 : did to reflect the new type. */
14691 887888 : result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
14692 887888 : TYPE_MAIN_VARIANT (return_type));
14693 887888 : DECL_ARTIFICIAL (result) = 1;
14694 887888 : DECL_IGNORED_P (result) = 1;
14695 887888 : cp_apply_type_quals_to_decl (cp_type_quals (return_type),
14696 : result);
14697 887888 : DECL_RESULT (fco) = result;
14698 :
14699 887888 : if (!uses_template_parms (fco))
14700 887888 : if (function *fun = DECL_STRUCT_FUNCTION (fco))
14701 : {
14702 887370 : bool aggr = aggregate_value_p (result, fco);
14703 : #ifdef PCC_STATIC_STRUCT_RETURN
14704 : fun->returns_pcc_struct = aggr;
14705 : #endif
14706 887370 : fun->returns_struct = aggr;
14707 : }
14708 : }
14709 :
14710 : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
14711 : this is a right unary fold. Otherwise it is a left unary fold. */
14712 :
14713 : static tree
14714 754980 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
14715 : {
14716 : /* Build a pack expansion (assuming expr has pack type). */
14717 754980 : if (!uses_parameter_packs (expr))
14718 : {
14719 3 : error_at (location_of (expr), "operand of fold expression has no "
14720 : "unexpanded parameter packs");
14721 3 : return error_mark_node;
14722 : }
14723 754977 : tree pack = make_pack_expansion (expr);
14724 :
14725 : /* Build the fold expression. */
14726 754977 : tree code = build_int_cstu (integer_type_node, abs (op));
14727 754977 : tree fold = build_min_nt_loc (loc, dir, code, pack);
14728 754977 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14729 754977 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14730 754977 : FOLD_EXPR_OP (fold),
14731 754977 : FOLD_EXPR_MODIFY_P (fold));
14732 754977 : return fold;
14733 : }
14734 :
14735 : tree
14736 17875 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
14737 : {
14738 17875 : return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
14739 : }
14740 :
14741 : tree
14742 737105 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
14743 : {
14744 737105 : return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
14745 : }
14746 :
14747 : /* Build a binary fold expression over EXPR1 and EXPR2. The
14748 : associativity of the fold is determined by EXPR1 and EXPR2 (whichever
14749 : has an unexpanded parameter pack). */
14750 :
14751 : static tree
14752 186105 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
14753 : int op, tree_code dir)
14754 : {
14755 186105 : pack = make_pack_expansion (pack);
14756 186105 : tree code = build_int_cstu (integer_type_node, abs (op));
14757 186105 : tree fold = build_min_nt_loc (loc, dir, code, pack, init);
14758 186105 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14759 186105 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14760 186105 : FOLD_EXPR_OP (fold),
14761 186105 : FOLD_EXPR_MODIFY_P (fold));
14762 186105 : return fold;
14763 : }
14764 :
14765 : tree
14766 186105 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
14767 : {
14768 : // Determine which expr has an unexpanded parameter pack and
14769 : // set the pack and initial term.
14770 186105 : bool pack1 = uses_parameter_packs (expr1);
14771 186105 : bool pack2 = uses_parameter_packs (expr2);
14772 186105 : if (pack1 && !pack2)
14773 797 : return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
14774 185308 : else if (pack2 && !pack1)
14775 185308 : return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
14776 : else
14777 : {
14778 0 : if (pack1)
14779 0 : error ("both arguments in binary fold have unexpanded parameter packs");
14780 : else
14781 0 : error ("no unexpanded parameter packs in binary fold");
14782 : }
14783 0 : return error_mark_node;
14784 : }
14785 :
14786 : /* Finish __builtin_launder (arg). */
14787 :
14788 : tree
14789 13219 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
14790 : {
14791 13219 : tree orig_arg = arg;
14792 13219 : if (!type_dependent_expression_p (arg))
14793 84 : arg = decay_conversion (arg, complain);
14794 13219 : if (error_operand_p (arg))
14795 0 : return error_mark_node;
14796 13219 : if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
14797 : {
14798 24 : error_at (loc, "type %qT of argument to %<__builtin_launder%> "
14799 24 : "is not a pointer to object type", TREE_TYPE (arg));
14800 24 : return error_mark_node;
14801 : }
14802 13195 : if (processing_template_decl)
14803 13135 : arg = orig_arg;
14804 13195 : return build_call_expr_internal_loc (loc, IFN_LAUNDER,
14805 26390 : TREE_TYPE (arg), 1, arg);
14806 : }
14807 :
14808 : /* Finish __builtin_convertvector (arg, type). */
14809 :
14810 : tree
14811 312 : cp_build_vec_convert (tree arg, location_t loc, tree type,
14812 : tsubst_flags_t complain)
14813 : {
14814 312 : if (error_operand_p (type))
14815 9 : return error_mark_node;
14816 303 : if (error_operand_p (arg))
14817 0 : return error_mark_node;
14818 :
14819 303 : tree ret = NULL_TREE;
14820 303 : if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
14821 295 : ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
14822 : decay_conversion (arg, complain),
14823 : loc, type, (complain & tf_error) != 0);
14824 :
14825 303 : if (!processing_template_decl)
14826 : return ret;
14827 :
14828 50 : return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
14829 : }
14830 :
14831 : /* Finish __builtin_bit_cast (type, arg). */
14832 :
14833 : tree
14834 278039 : cp_build_bit_cast (location_t loc, tree type, tree arg,
14835 : tsubst_flags_t complain)
14836 : {
14837 278039 : if (error_operand_p (type))
14838 0 : return error_mark_node;
14839 278039 : if (!dependent_type_p (type))
14840 : {
14841 201971 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
14842 9 : return error_mark_node;
14843 201962 : if (TREE_CODE (type) == ARRAY_TYPE)
14844 : {
14845 : /* std::bit_cast for destination ARRAY_TYPE is not possible,
14846 : as functions may not return an array, so don't bother trying
14847 : to support this (and then deal with VLAs etc.). */
14848 9 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14849 : "is an array type", type);
14850 9 : return error_mark_node;
14851 : }
14852 201953 : if (!trivially_copyable_p (type))
14853 : {
14854 18 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14855 : "is not trivially copyable", type);
14856 18 : return error_mark_node;
14857 : }
14858 201935 : if (consteval_only_p (type) || consteval_only_p (arg))
14859 : {
14860 4 : error_at (loc, "%<__builtin_bit_cast%> cannot be used with "
14861 : "consteval-only types");
14862 4 : return error_mark_node;
14863 : }
14864 : }
14865 :
14866 277999 : if (error_operand_p (arg))
14867 0 : return error_mark_node;
14868 :
14869 277999 : if (!type_dependent_expression_p (arg))
14870 : {
14871 110348 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
14872 : {
14873 : /* Don't perform array-to-pointer conversion. */
14874 39 : arg = mark_rvalue_use (arg, loc, true);
14875 39 : if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
14876 0 : return error_mark_node;
14877 : }
14878 : else
14879 110309 : arg = decay_conversion (arg, complain);
14880 :
14881 110348 : if (error_operand_p (arg))
14882 12 : return error_mark_node;
14883 :
14884 110336 : if (!trivially_copyable_p (TREE_TYPE (arg)))
14885 : {
14886 9 : error_at (cp_expr_loc_or_loc (arg, loc),
14887 : "%<__builtin_bit_cast%> source type %qT "
14888 9 : "is not trivially copyable", TREE_TYPE (arg));
14889 9 : return error_mark_node;
14890 : }
14891 110327 : if (!dependent_type_p (type)
14892 183689 : && !cp_tree_equal (TYPE_SIZE_UNIT (type),
14893 73362 : TYPE_SIZE_UNIT (TREE_TYPE (arg))))
14894 : {
14895 18 : error_at (loc, "%<__builtin_bit_cast%> source size %qE "
14896 : "not equal to destination type size %qE",
14897 18 : TYPE_SIZE_UNIT (TREE_TYPE (arg)),
14898 18 : TYPE_SIZE_UNIT (type));
14899 18 : return error_mark_node;
14900 : }
14901 : }
14902 :
14903 277960 : tree ret = build_min (BIT_CAST_EXPR, type, arg);
14904 277960 : SET_EXPR_LOCATION (ret, loc);
14905 :
14906 277960 : if (!processing_template_decl && CLASS_TYPE_P (type))
14907 300 : ret = get_target_expr (ret, complain);
14908 :
14909 : return ret;
14910 : }
14911 :
14912 : /* Diagnose invalid #pragma GCC unroll argument and adjust
14913 : it if needed. */
14914 :
14915 : tree
14916 23257 : cp_check_pragma_unroll (location_t loc, tree unroll)
14917 : {
14918 23257 : HOST_WIDE_INT lunroll = 0;
14919 23257 : if (type_dependent_expression_p (unroll))
14920 : ;
14921 46442 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
14922 46396 : || (!value_dependent_expression_p (unroll)
14923 23145 : && (!tree_fits_shwi_p (unroll)
14924 23119 : || (lunroll = tree_to_shwi (unroll)) < 0
14925 23104 : || lunroll >= USHRT_MAX)))
14926 : {
14927 90 : error_at (loc, "%<#pragma GCC unroll%> requires an"
14928 : " assignment-expression that evaluates to a non-negative"
14929 : " integral constant less than %u", USHRT_MAX);
14930 90 : unroll = integer_one_node;
14931 : }
14932 23131 : else if (TREE_CODE (unroll) == INTEGER_CST)
14933 : {
14934 23101 : unroll = fold_convert (integer_type_node, unroll);
14935 23101 : if (integer_zerop (unroll))
14936 12 : unroll = integer_one_node;
14937 : }
14938 23257 : return unroll;
14939 : }
14940 :
14941 : #include "gt-cp-semantics.h"
|