Branch data 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 : 22994977471 : push_deferring_access_checks (deferring_kind deferring)
146 : : {
147 : : /* For context like template instantiation, access checking
148 : : disabling applies to all nested context. */
149 : 22994977471 : if (deferred_access_no_check || deferring == dk_no_check)
150 : 293105143 : deferred_access_no_check++;
151 : : else
152 : : {
153 : 22701872328 : deferred_access e = {NULL, deferring};
154 : 22701872328 : vec_safe_push (deferred_access_stack, e);
155 : : }
156 : 22994977471 : }
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 : 422495744 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
163 : : {
164 : 422495744 : push_deferring_access_checks (dk_deferred);
165 : 422495744 : if (!deferred_access_no_check)
166 : 415798446 : deferred_access_stack->last().deferred_access_checks = checks;
167 : 422495744 : }
168 : :
169 : : /* Resume deferring access checks again after we stopped doing
170 : : this previously. */
171 : :
172 : : void
173 : 174577572 : resume_deferring_access_checks (void)
174 : : {
175 : 174577572 : if (!deferred_access_no_check)
176 : 174557344 : deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
177 : 174577572 : }
178 : :
179 : : /* Stop deferring access checks. */
180 : :
181 : : void
182 : 490051420 : stop_deferring_access_checks (void)
183 : : {
184 : 490051420 : if (!deferred_access_no_check)
185 : 489991383 : deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
186 : 490051420 : }
187 : :
188 : : /* Discard the current deferred access checks and restore the
189 : : previous states. */
190 : :
191 : : void
192 : 14320624456 : pop_deferring_access_checks (void)
193 : : {
194 : 14320624456 : if (deferred_access_no_check)
195 : 224235949 : deferred_access_no_check--;
196 : : else
197 : 14096388507 : deferred_access_stack->pop ();
198 : 14320624456 : }
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 : 1293344893 : get_deferred_access_checks (void)
207 : : {
208 : 1293344893 : if (deferred_access_no_check)
209 : : return NULL;
210 : : else
211 : 1280063359 : 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 : 8674218739 : pop_to_parent_deferring_access_checks (void)
220 : : {
221 : 8674218739 : if (deferred_access_no_check)
222 : 68869188 : deferred_access_no_check--;
223 : : else
224 : : {
225 : 8605349551 : vec<deferred_access_check, va_gc> *checks;
226 : 8605349551 : deferred_access *ptr;
227 : :
228 : 8605349551 : checks = (deferred_access_stack->last ().deferred_access_checks);
229 : :
230 : 8605349551 : deferred_access_stack->pop ();
231 : 8605349551 : ptr = &deferred_access_stack->last ();
232 : 8605349551 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
233 : : {
234 : : /* Check access. */
235 : 550190428 : 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 : 8250313747 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
244 : : {
245 : 106189182 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
246 : : {
247 : 9539447 : if (probe->binfo == chk->binfo &&
248 : 7585949 : probe->decl == chk->decl &&
249 : 928335 : probe->diag_decl == chk->diag_decl)
250 : 927577 : goto found;
251 : : }
252 : : /* Insert into parent's checks. */
253 : 96649735 : vec_safe_push (ptr->deferred_access_checks, *chk);
254 : 97577312 : found:;
255 : : }
256 : : }
257 : : }
258 : 8674218739 : }
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 : 545228079 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
334 : : tsubst_flags_t complain, access_failure_info *afi = NULL)
335 : : {
336 : 545228079 : gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
337 : :
338 : 545228079 : if (flag_new_inheriting_ctors
339 : 689724878 : && 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 : 75676 : decl = strip_inheriting_ctors (decl);
345 : 75676 : basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
346 : : ba_any, NULL, complain);
347 : : }
348 : :
349 : 545228079 : tree cs = current_scope ();
350 : 545228079 : if (in_template_context
351 : 545228079 : && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
352 : 40412884 : 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 : 40178619 : 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 : 505049460 : if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
382 : : {
383 : 21643 : if (flag_new_inheriting_ctors)
384 : 21613 : diag_decl = strip_inheriting_ctors (diag_decl);
385 : 21643 : 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 : 21643 : if (afi)
416 : 412 : afi->record_access_failure (basetype_path, decl, diag_decl);
417 : 21643 : 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 : 1111243413 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
431 : : tsubst_flags_t complain)
432 : : {
433 : 1111243413 : int i;
434 : 1111243413 : deferred_access_check *chk;
435 : 1111243413 : location_t loc = input_location;
436 : 1111243413 : bool ok = true;
437 : :
438 : 1111243413 : if (!checks)
439 : : return true;
440 : :
441 : 131476220 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
442 : : {
443 : 73212634 : input_location = chk->loc;
444 : 73212634 : ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
445 : : }
446 : :
447 : 58263586 : input_location = loc;
448 : 58263586 : 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 : 290344500 : perform_deferred_access_checks (tsubst_flags_t complain)
469 : : {
470 : 290344500 : 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 : 762155063 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
480 : : tsubst_flags_t complain,
481 : : access_failure_info *afi)
482 : : {
483 : 762155063 : int i;
484 : 762155063 : deferred_access *ptr;
485 : 762155063 : deferred_access_check *chk;
486 : :
487 : : /* Exit if we are in a context that no access checking is performed. */
488 : 762155063 : if (deferred_access_no_check)
489 : : return true;
490 : :
491 : 738509732 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
492 : :
493 : 738509732 : ptr = &deferred_access_stack->last ();
494 : :
495 : : /* If we are not supposed to defer access checks, just check now. */
496 : 738509732 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
497 : : {
498 : 472015445 : bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
499 : 685671867 : return (complain & tf_error) ? true : ok;
500 : : }
501 : :
502 : : /* See if we are already going to perform this check. */
503 : 322481027 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
504 : : {
505 : 74294693 : if (chk->decl == decl && chk->binfo == binfo &&
506 : 18308662 : chk->diag_decl == diag_decl)
507 : : {
508 : : return true;
509 : : }
510 : : }
511 : : /* If not, record the check. */
512 : 248186334 : deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
513 : 248186334 : vec_safe_push (ptr->deferred_access_checks, new_access);
514 : :
515 : 248186334 : 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 : 1472375255 : stmts_are_full_exprs_p (void)
524 : : {
525 : 1472375255 : 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 : 1328459294 : add_stmt (tree t)
534 : : {
535 : 1328459294 : enum tree_code code = TREE_CODE (t);
536 : :
537 : 1328459294 : if (EXPR_P (t) && code != LABEL_EXPR)
538 : : {
539 : 1276963523 : if (!EXPR_HAS_LOCATION (t))
540 : 192783791 : 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 : 1276963523 : if (STATEMENT_CODE_P (TREE_CODE (t)))
545 : 340138120 : STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
546 : : }
547 : :
548 : 1328459294 : if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
549 : 8308655 : 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 : 1328459294 : gcc_checking_assert (!stmt_list_stack->is_empty ());
554 : 1328459294 : append_to_statement_list_force (t, &cur_stmt_list);
555 : :
556 : 1328459294 : return t;
557 : : }
558 : :
559 : : /* Returns the stmt_tree to which statements are currently being added. */
560 : :
561 : : stmt_tree
562 : 7881784700 : current_stmt_tree (void)
563 : : {
564 : 7881784700 : return (cfun
565 : 7859262945 : ? &cfun->language->base.x_stmt_tree
566 : 7881784700 : : &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 : 640883 : maybe_cleanup_point_expr (tree expr)
573 : : {
574 : 640883 : if (!processing_template_decl && stmts_are_full_exprs_p ())
575 : 626841 : expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
576 : 640883 : 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 : 337864207 : maybe_cleanup_point_expr_void (tree expr)
586 : : {
587 : 337864207 : if (!processing_template_decl && stmts_are_full_exprs_p ())
588 : 131418838 : expr = fold_build_cleanup_point_expr (void_type_node, expr);
589 : 337864207 : return expr;
590 : : }
591 : :
592 : :
593 : :
594 : : /* Create a declaration statement for the declaration given by the DECL. */
595 : :
596 : : void
597 : 111049734 : add_decl_expr (tree decl)
598 : : {
599 : 111049734 : tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
600 : 111049734 : if (DECL_INITIAL (decl)
601 : 111049734 : || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
602 : 20300630 : r = maybe_cleanup_point_expr_void (r);
603 : 111049734 : add_stmt (r);
604 : 111049734 : }
605 : :
606 : : /* Set EXPR_LOCATION on one cleanup T to LOC. */
607 : :
608 : : static void
609 : 6123925 : set_one_cleanup_loc (tree t, location_t loc)
610 : : {
611 : 6123925 : if (!t)
612 : : return;
613 : :
614 : 6123925 : if (TREE_CODE (t) != POSTCONDITION_STMT)
615 : 6123925 : 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 : 6123925 : if (TREE_CODE (t) == NOP_EXPR
622 : 0 : && TREE_TYPE (t) == void_type_node
623 : 6123925 : && 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 : 1242700882 : set_cleanup_locs (tree stmts, location_t loc)
631 : : {
632 : 1248824807 : if (TREE_CODE (stmts) == CLEANUP_STMT)
633 : : {
634 : 6123925 : set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
635 : 6123925 : set_cleanup_locs (CLEANUP_BODY (stmts), loc);
636 : : }
637 : 1242700882 : else if (TREE_CODE (stmts) == STATEMENT_LIST)
638 : 1091414716 : for (tree stmt : tsi_range (stmts))
639 : 847465462 : set_cleanup_locs (stmt, loc);
640 : 1242700882 : }
641 : :
642 : : /* True iff the innermost block scope is a try block. */
643 : :
644 : : static bool
645 : 395235420 : at_try_scope ()
646 : : {
647 : 395235420 : cp_binding_level *b = current_binding_level;
648 : 395235870 : while (b && b->kind == sk_cleanup)
649 : 450 : b = b->level_chain;
650 : 395235420 : return b && b->kind == sk_try;
651 : : }
652 : :
653 : : /* Finish a scope. */
654 : :
655 : : tree
656 : 395235420 : do_poplevel (tree stmt_list)
657 : : {
658 : 395235420 : tree block = NULL;
659 : :
660 : 395235420 : bool was_try = at_try_scope ();
661 : :
662 : 395235420 : if (stmts_are_full_exprs_p ())
663 : 395174823 : block = poplevel (kept_level_p (), 1, 0);
664 : :
665 : : /* This needs to come after poplevel merges sk_cleanup statement_lists. */
666 : 395235420 : maybe_splice_retval_cleanup (stmt_list, was_try);
667 : :
668 : 395235420 : stmt_list = pop_stmt_list (stmt_list);
669 : :
670 : : /* input_location is the last token of the scope, usually a }. */
671 : 395235420 : set_cleanup_locs (stmt_list, input_location);
672 : :
673 : 395235420 : if (!processing_template_decl)
674 : : {
675 : 144778591 : stmt_list = c_build_bind_expr (input_location, block, stmt_list);
676 : : /* ??? See c_end_compound_stmt re statement expressions. */
677 : : }
678 : :
679 : 395235420 : return stmt_list;
680 : : }
681 : :
682 : : /* Begin a new scope. */
683 : :
684 : : tree
685 : 395199374 : do_pushlevel (scope_kind sk)
686 : : {
687 : 395199374 : tree ret = push_stmt_list ();
688 : 395199374 : if (stmts_are_full_exprs_p ())
689 : 395174883 : begin_scope (sk, NULL);
690 : 395199374 : 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 : 6123846 : push_cleanup (tree decl, tree cleanup, bool eh_only)
700 : : {
701 : 6123846 : tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
702 : 6123846 : CLEANUP_EH_ONLY (stmt) = eh_only;
703 : 6123846 : add_stmt (stmt);
704 : 6123846 : CLEANUP_BODY (stmt) = push_stmt_list ();
705 : 6123846 : }
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 : 18138404 : begin_maybe_infinite_loop (tree cond)
716 : : {
717 : : /* Only track this while parsing a function, not during instantiation. */
718 : 18138404 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
719 : 3294971 : && !processing_template_decl))
720 : : return;
721 : 14842887 : bool maybe_infinite = true;
722 : 14842887 : if (cond)
723 : : {
724 : 14529368 : cond = fold_non_dependent_expr (cond);
725 : 14529368 : maybe_infinite = integer_nonzerop (cond);
726 : : }
727 : 29372255 : vec_safe_push (cp_function_chain->infinite_loops,
728 : 14842887 : 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 : 1488325 : break_maybe_infinite_loop (void)
736 : : {
737 : 1488325 : if (!cfun)
738 : : return;
739 : 1488325 : 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 : 18138404 : end_maybe_infinite_loop (tree cond)
747 : : {
748 : 18138404 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
749 : 3294971 : && !processing_template_decl))
750 : : return;
751 : 14842887 : tree current = cp_function_chain->infinite_loops->pop();
752 : 14842887 : if (current != NULL_TREE)
753 : : {
754 : 4725563 : cond = fold_non_dependent_expr (cond);
755 : 4725563 : if (integer_nonzerop (cond))
756 : 300115 : 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 : 95215660 : begin_cond (tree *cond_p)
767 : : {
768 : 95215660 : if (processing_template_decl)
769 : 59045032 : *cond_p = push_stmt_list ();
770 : 95215660 : }
771 : :
772 : : /* Finish such a conditional. */
773 : :
774 : : static void
775 : 95215660 : finish_cond (tree *cond_p, tree expr)
776 : : {
777 : 95215660 : if (processing_template_decl)
778 : : {
779 : 59045032 : tree cond = pop_stmt_list (*cond_p);
780 : :
781 : 59045032 : if (expr == NULL_TREE)
782 : : /* Empty condition in 'for'. */
783 : 293541 : gcc_assert (empty_expr_stmt_p (cond));
784 : 58751491 : else if (check_for_bare_parameter_packs (expr))
785 : 0 : expr = error_mark_node;
786 : 58751491 : else if (!empty_expr_stmt_p (cond))
787 : 894697 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
788 : : }
789 : 95215660 : *cond_p = expr;
790 : 95215660 : }
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 : 12369084 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
809 : : {
810 : 12369084 : if (!TREE_SIDE_EFFECTS (*body_p))
811 : 12359716 : return;
812 : :
813 : 9368 : gcc_assert (!processing_template_decl);
814 : 9368 : *prep_p = *body_p;
815 : 9368 : 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 : 9368 : current_binding_level->keep = true;
840 : 9368 : 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 : 9368 : if (tsi_end_p (iter))
847 : 91 : *body_p = NULL_TREE;
848 : : else
849 : 9277 : *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 : 9368 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
862 : : {
863 : 9368 : *prep_p = do_poplevel (*prep_p);
864 : 9368 : gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
865 : 9368 : 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 : 9350 : tree stmt_list = BIND_EXPR_BODY (*prep_p);
872 : 9350 : gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
873 : 9350 : 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 : 9259 : tree_stmt_iterator iter = tsi_start (stmt_list);
893 : 9455 : while (tsi_stmt (iter) != *body_p)
894 : 196 : tsi_next (&iter);
895 : 9259 : *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 : 839885 : is_assignment_op_expr_p (tree t)
937 : : {
938 : 839885 : if (t == NULL_TREE)
939 : : return false;
940 : :
941 : 839885 : if (TREE_CODE (t) == MODIFY_EXPR
942 : 839885 : || (TREE_CODE (t) == MODOP_EXPR
943 : 330 : && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
944 : : return true;
945 : :
946 : 839198 : tree call = extract_call_expr (t);
947 : 839198 : if (call == NULL_TREE
948 : 126307 : || call == error_mark_node
949 : 965505 : || !CALL_EXPR_OPERATOR_SYNTAX (call))
950 : : return false;
951 : :
952 : 4399 : tree fndecl = cp_get_callee_fndecl_nofold (call);
953 : 4399 : return fndecl != NULL_TREE
954 : 4371 : && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
955 : 4450 : && 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 : 78 : if (bool *r = hash_map_safe_get (boolish_class_type_p_cache, type))
971 : 27 : return *r;
972 : :
973 : 18 : tree ops;
974 : 18 : bool has_bool_assignment = false;
975 : 18 : bool has_bool_conversion = false;
976 : :
977 : 18 : ops = lookup_fnfields (type, assign_op_identifier, /*protect=*/0, tf_none);
978 : 55 : for (tree op : ovl_range (BASELINK_FUNCTIONS (ops)))
979 : : {
980 : 29 : op = STRIP_TEMPLATE (op);
981 : 29 : if (TREE_CODE (op) != FUNCTION_DECL)
982 : 0 : continue;
983 : 29 : tree parm = DECL_CHAIN (DECL_ARGUMENTS (op));
984 : 29 : tree parm_type = non_reference (TREE_TYPE (parm));
985 : 29 : if (TREE_CODE (parm_type) == BOOLEAN_TYPE)
986 : : {
987 : : has_bool_assignment = true;
988 : : break;
989 : : }
990 : : }
991 : :
992 : 18 : if (has_bool_assignment)
993 : : {
994 : 3 : ops = lookup_conversions (type);
995 : 3 : for (; ops; ops = TREE_CHAIN (ops))
996 : : {
997 : 3 : tree op = TREE_VALUE (ops);
998 : 3 : if (!DECL_NONCONVERTING_P (op)
999 : 3 : && TREE_CODE (DECL_CONV_FN_TYPE (op)) == BOOLEAN_TYPE)
1000 : : {
1001 : : has_bool_conversion = true;
1002 : : break;
1003 : : }
1004 : : }
1005 : : }
1006 : :
1007 : 18 : bool boolish = has_bool_assignment && has_bool_conversion;
1008 : 18 : hash_map_safe_put<true> (boolish_class_type_p_cache, type, boolish);
1009 : 18 : 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 : 104478598 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
1019 : : tsubst_flags_t complain)
1020 : : {
1021 : 104478598 : tree type = TREE_TYPE (t);
1022 : 104478598 : t = STRIP_REFERENCE_REF (t);
1023 : :
1024 : 104478598 : if ((complain & tf_warning)
1025 : 104419551 : && warn_parentheses
1026 : 839885 : && 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 : 104478951 : && (!nested_p
1032 : 182 : || (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 : 104478598 : }
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 : 62402833 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
1072 : : {
1073 : 62402833 : tree *t = cond;
1074 : 62412698 : while (TREE_CODE (*t) == ANNOTATE_EXPR)
1075 : 9865 : t = &TREE_OPERAND (*t, 0);
1076 : :
1077 : 62402833 : if (t != cond)
1078 : : {
1079 : 9862 : m_annotations = *cond;
1080 : 9862 : *cond = *t;
1081 : 9862 : m_inner = t;
1082 : : }
1083 : 62402833 : }
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 : 62402833 : annotate_saver::restore (tree new_inner)
1092 : : {
1093 : 62402833 : 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 : 9862 : 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 : 9862 : *m_inner = new_inner;
1118 : 9862 : 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 : 99773525 : maybe_convert_cond (tree cond)
1127 : : {
1128 : : /* Empty conditions remain empty. */
1129 : 99773525 : if (!cond)
1130 : : return NULL_TREE;
1131 : :
1132 : : /* Wait until we instantiate templates before doing conversion. */
1133 : 99404646 : if (type_dependent_expression_p (cond))
1134 : 37001813 : return cond;
1135 : :
1136 : : /* Strip any ANNOTATE_EXPRs from COND. */
1137 : 62402833 : 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 : 546484 : if (DECL_DECOMPOSITION_P (cond)
1144 : 218 : && DECL_DECOMP_IS_BASE (cond)
1145 : 218 : && DECL_DECOMP_BASE (cond)
1146 : 62403048 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1147 : 56 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1148 : :
1149 : 62402833 : if (warn_sequence_point && !processing_template_decl)
1150 : 316742 : verify_sequence_points (cond);
1151 : :
1152 : 62402833 : maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
1153 : : tf_warning_or_error);
1154 : :
1155 : : /* Do the conversion. */
1156 : 62402833 : cond = convert_from_reference (cond);
1157 : 62402833 : cond = condition_conversion (cond);
1158 : :
1159 : : /* Restore any ANNOTATE_EXPRs around COND. */
1160 : 62402833 : return annotations.restore (cond);
1161 : : }
1162 : :
1163 : : /* Finish an expression-statement, whose EXPRESSION is as indicated. */
1164 : :
1165 : : tree
1166 : 179698654 : finish_expr_stmt (tree expr)
1167 : : {
1168 : 179698654 : tree r = NULL_TREE;
1169 : 179698654 : location_t loc = EXPR_LOCATION (expr);
1170 : :
1171 : 179211554 : if (expr != NULL_TREE)
1172 : : {
1173 : : /* If we ran into a problem, make sure we complained. */
1174 : 179698493 : gcc_assert (expr != error_mark_node || seen_error ());
1175 : :
1176 : 179698493 : if (!processing_template_decl)
1177 : : {
1178 : 78908707 : if (warn_sequence_point)
1179 : 793841 : verify_sequence_points (expr);
1180 : 78908707 : expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1181 : : }
1182 : 100789786 : else if (!type_dependent_expression_p (expr))
1183 : 21895216 : convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1184 : :
1185 : 179698490 : 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 : 179698490 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
1192 : : {
1193 : 179698311 : if (TREE_CODE (expr) != EXPR_STMT
1194 : 176623402 : && !STATEMENT_CLASS_P (expr)
1195 : 176619251 : && TREE_CODE (expr) != STATEMENT_LIST)
1196 : 176186592 : expr = build_stmt (loc, EXPR_STMT, expr);
1197 : 179698311 : expr = maybe_cleanup_point_expr_void (expr);
1198 : : }
1199 : :
1200 : 179698490 : r = add_stmt (expr);
1201 : : }
1202 : :
1203 : 179698651 : return r;
1204 : : }
1205 : :
1206 : :
1207 : : /* Begin an if-statement. Returns a newly created IF_STMT if
1208 : : appropriate. */
1209 : :
1210 : : tree
1211 : 81855834 : begin_if_stmt (void)
1212 : : {
1213 : 81855834 : tree r, scope;
1214 : 81855834 : scope = do_pushlevel (sk_cond);
1215 : 81855834 : r = build_stmt (input_location, IF_STMT, NULL_TREE,
1216 : : NULL_TREE, NULL_TREE, scope);
1217 : 81855834 : current_binding_level->this_entity = r;
1218 : 81855834 : begin_cond (&IF_COND (r));
1219 : 81855834 : 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 : 242126 : is_std_constant_evaluated_p (tree fn)
1227 : : {
1228 : : /* std::is_constant_evaluated takes no arguments. */
1229 : 242126 : if (call_expr_nargs (fn) != 0)
1230 : : return false;
1231 : :
1232 : 85274 : tree fndecl = cp_get_callee_fndecl_nofold (fn);
1233 : 85274 : if (fndecl == NULL_TREE)
1234 : : return false;
1235 : :
1236 : 26270 : if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
1237 : : BUILT_IN_FRONTEND))
1238 : : return true;
1239 : :
1240 : 26247 : if (!decl_in_std_namespace_p (fndecl))
1241 : : return false;
1242 : :
1243 : 11294 : tree name = DECL_NAME (fndecl);
1244 : 11294 : 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 : 4481955 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
1252 : : {
1253 : 4481955 : tree t = *tp;
1254 : :
1255 : 4481955 : if (TYPE_P (t) || TREE_CONSTANT (t))
1256 : : {
1257 : 790492 : *walk_subtrees = false;
1258 : 790492 : return NULL_TREE;
1259 : : }
1260 : :
1261 : 3691463 : switch (TREE_CODE (t))
1262 : : {
1263 : 242126 : case CALL_EXPR:
1264 : 242126 : 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 : 81937563 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
1284 : : bool trivial_infinite)
1285 : : {
1286 : 81937563 : if (!warn_tautological_compare)
1287 : : return;
1288 : :
1289 : : /* Suppress warning for std::is_constant_evaluated if the conditional
1290 : : comes from a macro. */
1291 : 1366770 : if (from_macro_expansion_at (EXPR_LOCATION (cond)))
1292 : : return;
1293 : :
1294 : 573766 : cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
1295 : : NULL);
1296 : 573766 : if (cond)
1297 : : {
1298 : 2234 : 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 : 2200 : 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 : 2192 : 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 : 4308 : 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 : 81855834 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
1330 : : {
1331 : 81855834 : tree cond = maybe_convert_cond (orig_cond);
1332 : 81855834 : maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
1333 : : /*trivial_infinite=*/false);
1334 : 81855834 : if (IF_STMT_CONSTEXPR_P (if_stmt)
1335 : 18870999 : && !type_dependent_expression_p (cond)
1336 : 14128914 : && require_constant_expression (cond)
1337 : 14128885 : && !instantiation_dependent_expression_p (cond)
1338 : : /* Wait until instantiation time, since only then COND has been
1339 : : converted to bool. */
1340 : 91522590 : && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
1341 : : {
1342 : 9666756 : cond = instantiate_non_dependent_expr (cond);
1343 : 9666756 : cond = cxx_constant_value (cond);
1344 : : }
1345 : 72189078 : else if (processing_template_decl)
1346 : 48898669 : cond = orig_cond;
1347 : 81855834 : finish_cond (&IF_COND (if_stmt), cond);
1348 : 81855834 : add_stmt (if_stmt);
1349 : 81855834 : THEN_CLAUSE (if_stmt) = push_stmt_list ();
1350 : 81855834 : 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 : 81826207 : finish_then_clause (tree if_stmt)
1358 : : {
1359 : 81826207 : THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
1360 : 81826207 : return if_stmt;
1361 : : }
1362 : :
1363 : : /* Begin the else-clause of an if-statement. */
1364 : :
1365 : : void
1366 : 30072322 : begin_else_clause (tree if_stmt)
1367 : : {
1368 : 30072322 : ELSE_CLAUSE (if_stmt) = push_stmt_list ();
1369 : 30072322 : }
1370 : :
1371 : : /* Finish the else-clause of an if-statement, which may be given by
1372 : : IF_STMT. */
1373 : :
1374 : : void
1375 : 30072284 : finish_else_clause (tree if_stmt)
1376 : : {
1377 : 30072284 : ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
1378 : 30072284 : }
1379 : :
1380 : : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1381 : : read. */
1382 : :
1383 : : static tree
1384 : 910498841 : maybe_mark_exp_read_r (tree *tp, int *, void *)
1385 : : {
1386 : 910498841 : tree t = *tp;
1387 : 910498841 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1388 : 54693950 : mark_exp_read (t);
1389 : 910498841 : return NULL_TREE;
1390 : : }
1391 : :
1392 : : /* Finish an if-statement. */
1393 : :
1394 : : void
1395 : 81826207 : finish_if_stmt (tree if_stmt)
1396 : : {
1397 : 81826207 : tree scope = IF_SCOPE (if_stmt);
1398 : 81826207 : IF_SCOPE (if_stmt) = NULL;
1399 : 81826207 : 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 : 18841372 : cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
1405 : : maybe_mark_exp_read_r, NULL);
1406 : 18841372 : cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
1407 : : maybe_mark_exp_read_r, NULL);
1408 : : }
1409 : 81826207 : add_stmt (do_poplevel (scope));
1410 : 81826207 : }
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 : 17545524 : finish_loop_cond (tree *condp, tree body)
1421 : : {
1422 : 17545524 : if (TREE_CODE (*condp) == INTEGER_CST)
1423 : : return;
1424 : 12743760 : bool trivially_empty = expr_first (body) == NULL_TREE;
1425 : 12743760 : bool trivial_infinite = false;
1426 : 12743760 : if (trivially_empty)
1427 : : {
1428 : 94983 : tree c = fold_non_dependent_expr (*condp, tf_none,
1429 : : /*manifestly_const_eval=*/true);
1430 : 94983 : trivial_infinite = c && integer_nonzerop (c);
1431 : : }
1432 : 12743760 : if (warn_tautological_compare)
1433 : : {
1434 : 81909 : tree cond = *condp;
1435 : 82264 : while (TREE_CODE (cond) == ANNOTATE_EXPR)
1436 : 355 : cond = TREE_OPERAND (cond, 0);
1437 : 81909 : if (trivial_infinite
1438 : 81973 : && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1439 : 64 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1440 : : /*trivial_infinite=*/true);
1441 : 81845 : else if (!trivially_empty
1442 : 347 : || !processing_template_decl
1443 : 82205 : || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1444 : 81665 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1445 : : /*trivial_infinite=*/false);
1446 : : }
1447 : 12743760 : 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 : 4861504 : begin_while_stmt (void)
1459 : : {
1460 : 4861504 : tree r;
1461 : 4861504 : r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1462 : : NULL_TREE, NULL_TREE);
1463 : 4861504 : add_stmt (r);
1464 : 4861504 : WHILE_BODY (r) = do_pushlevel (sk_block);
1465 : 4861504 : begin_cond (&WHILE_COND (r));
1466 : 4861504 : return r;
1467 : : }
1468 : :
1469 : : /* Process the COND of a while-statement, which may be given by
1470 : : WHILE_STMT. */
1471 : :
1472 : : void
1473 : 4861504 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
1474 : : tree unroll, bool novector)
1475 : : {
1476 : 4861504 : cond = maybe_convert_cond (cond);
1477 : 4861504 : finish_cond (&WHILE_COND (while_stmt), cond);
1478 : 4861504 : begin_maybe_infinite_loop (cond);
1479 : 4861504 : 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 : 4861504 : if (unroll && cond != error_mark_node)
1487 : 25744 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1488 : 12872 : TREE_TYPE (WHILE_COND (while_stmt)),
1489 : 12872 : WHILE_COND (while_stmt),
1490 : : build_int_cst (integer_type_node,
1491 : : annot_expr_unroll_kind),
1492 : : unroll);
1493 : 4861504 : 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 : 4861504 : adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
1501 : : &WHILE_COND_PREP (while_stmt),
1502 : : &WHILE_COND_CLEANUP (while_stmt));
1503 : 4861504 : }
1504 : :
1505 : : /* Finish a while-statement, which may be given by WHILE_STMT. */
1506 : :
1507 : : void
1508 : 4861504 : finish_while_stmt (tree while_stmt)
1509 : : {
1510 : 4861504 : end_maybe_infinite_loop (boolean_true_node);
1511 : 4861504 : if (WHILE_COND_PREP (while_stmt))
1512 : 9194 : finish_loop_cond_prep (&WHILE_BODY (while_stmt),
1513 : : &WHILE_COND_PREP (while_stmt),
1514 : 9194 : WHILE_COND_CLEANUP (while_stmt));
1515 : : else
1516 : 4852310 : WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
1517 : 4861504 : finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
1518 : 4861504 : }
1519 : :
1520 : : /* Begin a do-statement. Returns a newly created DO_STMT if
1521 : : appropriate. */
1522 : :
1523 : : tree
1524 : 5545319 : begin_do_stmt (void)
1525 : : {
1526 : 5545319 : tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
1527 : : NULL_TREE);
1528 : 5545319 : begin_maybe_infinite_loop (boolean_true_node);
1529 : 5545319 : add_stmt (r);
1530 : 5545319 : DO_BODY (r) = push_stmt_list ();
1531 : 5545319 : return r;
1532 : : }
1533 : :
1534 : : /* Finish the body of a do-statement, which may be given by DO_STMT. */
1535 : :
1536 : : void
1537 : 5545319 : finish_do_body (tree do_stmt)
1538 : : {
1539 : 5545319 : tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
1540 : :
1541 : 5545319 : if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
1542 : 517344 : body = STATEMENT_LIST_TAIL (body)->stmt;
1543 : :
1544 : 5545319 : if (IS_EMPTY_STMT (body))
1545 : 30 : warning (OPT_Wempty_body,
1546 : : "suggest explicit braces around empty body in %<do%> statement");
1547 : 5545319 : }
1548 : :
1549 : : /* Finish a do-statement, which may be given by DO_STMT, and whose
1550 : : COND is as indicated. */
1551 : :
1552 : : void
1553 : 5545319 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
1554 : : bool novector)
1555 : : {
1556 : 5545319 : cond = maybe_convert_cond (cond);
1557 : 5545319 : 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 : 5545319 : if (check_for_bare_parameter_packs (cond))
1562 : 3 : cond = error_mark_node;
1563 : 5545319 : 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 : 5545319 : 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 : 5545319 : 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 : 5545319 : DO_COND (do_stmt) = cond;
1576 : 5545319 : tree do_body = DO_BODY (do_stmt);
1577 : 5545289 : if (CONVERT_EXPR_P (do_body)
1578 : 30 : && integer_zerop (TREE_OPERAND (do_body, 0))
1579 : 5545349 : && VOID_TYPE_P (TREE_TYPE (do_body)))
1580 : : do_body = NULL_TREE;
1581 : 5545319 : finish_loop_cond (&DO_COND (do_stmt), do_body);
1582 : 5545319 : }
1583 : :
1584 : : /* Finish a return-statement. The EXPRESSION returned, if any, is as
1585 : : indicated. */
1586 : :
1587 : : tree
1588 : 130722252 : finish_return_stmt (tree expr)
1589 : : {
1590 : 130722252 : tree r;
1591 : 130722252 : bool no_warning;
1592 : 130722252 : bool dangling;
1593 : :
1594 : 130722252 : expr = check_return_expr (expr, &no_warning, &dangling);
1595 : :
1596 : 130722252 : if (error_operand_p (expr)
1597 : 130722252 : || (flag_openmp && !check_omp_return ()))
1598 : : {
1599 : : /* Suppress -Wreturn-type for this function. */
1600 : 1232 : if (warn_return_type)
1601 : 1226 : suppress_warning (current_function_decl, OPT_Wreturn_type);
1602 : 1232 : return error_mark_node;
1603 : : }
1604 : :
1605 : 130721020 : if (!processing_template_decl)
1606 : : {
1607 : 50972654 : if (warn_sequence_point)
1608 : 1008260 : verify_sequence_points (expr);
1609 : : }
1610 : :
1611 : 130721020 : r = build_stmt (input_location, RETURN_EXPR, expr);
1612 : 130721020 : RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
1613 : 130721020 : if (no_warning)
1614 : 33 : suppress_warning (r, OPT_Wreturn_type);
1615 : 130721020 : r = maybe_cleanup_point_expr_void (r);
1616 : 130721020 : r = add_stmt (r);
1617 : :
1618 : 130721020 : 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 : 7731581 : begin_for_scope (tree *init)
1627 : : {
1628 : 7731581 : tree scope = do_pushlevel (sk_for);
1629 : :
1630 : 7731581 : if (processing_template_decl)
1631 : 5929996 : *init = push_stmt_list ();
1632 : : else
1633 : 1801585 : *init = NULL_TREE;
1634 : :
1635 : 7731581 : 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 : 7507580 : begin_for_stmt (tree scope, tree init)
1644 : : {
1645 : 7507580 : tree r;
1646 : :
1647 : 7507580 : 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 : 7507580 : if (scope == NULL_TREE)
1652 : : {
1653 : 1568638 : gcc_assert (!init);
1654 : 1568638 : scope = begin_for_scope (&init);
1655 : : }
1656 : :
1657 : 7507580 : FOR_INIT_STMT (r) = init;
1658 : 7507580 : FOR_SCOPE (r) = scope;
1659 : :
1660 : 7507580 : 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 : 7507580 : finish_init_stmt (tree for_stmt)
1668 : : {
1669 : 7507580 : if (processing_template_decl)
1670 : 5705995 : FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
1671 : 7507580 : add_stmt (for_stmt);
1672 : 7507580 : FOR_BODY (for_stmt) = do_pushlevel (sk_block);
1673 : 7507580 : begin_cond (&FOR_COND (for_stmt));
1674 : 7507580 : }
1675 : :
1676 : : /* Finish the COND of a for-statement, which may be given by
1677 : : FOR_STMT. */
1678 : :
1679 : : void
1680 : 7507580 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
1681 : : bool novector)
1682 : : {
1683 : 7507580 : cond = maybe_convert_cond (cond);
1684 : 7507580 : finish_cond (&FOR_COND (for_stmt), cond);
1685 : 7507580 : begin_maybe_infinite_loop (cond);
1686 : 7507580 : 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 : 7507580 : 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 : 7507580 : 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 : 7507580 : adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
1708 : : &FOR_COND_CLEANUP (for_stmt));
1709 : 7507580 : }
1710 : :
1711 : : /* Finish the increment-EXPRESSION in a for-statement, which may be
1712 : : given by FOR_STMT. */
1713 : :
1714 : : void
1715 : 7495387 : finish_for_expr (tree expr, tree for_stmt)
1716 : : {
1717 : 7495387 : 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 : 7050843 : if (type_unknown_p (expr))
1722 : : {
1723 : 6 : cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1724 : 6 : expr = error_mark_node;
1725 : : }
1726 : 7050843 : if (!processing_template_decl)
1727 : : {
1728 : 1732092 : if (warn_sequence_point)
1729 : 14512 : verify_sequence_points (expr);
1730 : 1732092 : expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1731 : : tf_warning_or_error);
1732 : : }
1733 : 5318751 : else if (!type_dependent_expression_p (expr))
1734 : 1907297 : convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
1735 : 7050843 : expr = maybe_cleanup_point_expr_void (expr);
1736 : 7050843 : if (check_for_bare_parameter_packs (expr))
1737 : 0 : expr = error_mark_node;
1738 : 7050843 : 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 : 7731694 : find_range_for_decls (tree range_for_decl[3])
1749 : : {
1750 : 7731694 : 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 : 30926776 : for (int i = 0; i < 3; i++)
1756 : : {
1757 : 23195082 : tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1758 : 23195082 : if (IDENTIFIER_BINDING (id)
1759 : 23195082 : && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1760 : : {
1761 : 304975 : range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1762 : 304975 : gcc_assert (VAR_P (range_for_decl[i])
1763 : : && DECL_ARTIFICIAL (range_for_decl[i]));
1764 : : }
1765 : : }
1766 : 7731694 : }
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 : 7731581 : finish_for_stmt (tree for_stmt)
1775 : : {
1776 : 7731581 : end_maybe_infinite_loop (boolean_true_node);
1777 : :
1778 : 7731581 : if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1779 : 224001 : RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1780 : : else
1781 : : {
1782 : 7507580 : 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 : 7507406 : FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1788 : 7507580 : if (FOR_COND (for_stmt))
1789 : 7138701 : finish_loop_cond (&FOR_COND (for_stmt),
1790 : 7138701 : FOR_EXPR (for_stmt) ? integer_one_node
1791 : 136542 : : FOR_BODY (for_stmt));
1792 : : }
1793 : :
1794 : : /* Pop the scope for the body of the loop. */
1795 : 7731581 : tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1796 : 7731581 : ? &RANGE_FOR_SCOPE (for_stmt)
1797 : 7507580 : : &FOR_SCOPE (for_stmt));
1798 : 7731581 : tree scope = *scope_ptr;
1799 : 7731581 : *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 : 7731581 : tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1806 : 7731581 : find_range_for_decls (range_for_decl);
1807 : :
1808 : 7731581 : 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 : 7731581 : if (!stmts_are_full_exprs_p ())
1813 : 12193 : return;
1814 : :
1815 : 30877552 : for (int i = 0; i < 3; i++)
1816 : 23158164 : if (range_for_decl[i])
1817 : 304859 : DECL_NAME (range_for_decl[i])
1818 : 304859 : = 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 : 224001 : begin_range_for_stmt (tree scope, tree init)
1828 : : {
1829 : 224001 : begin_maybe_infinite_loop (boolean_false_node);
1830 : :
1831 : 224001 : tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1832 : : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1833 : :
1834 : 224001 : if (scope == NULL_TREE)
1835 : : {
1836 : 240 : gcc_assert (!init);
1837 : 240 : scope = begin_for_scope (&init);
1838 : : }
1839 : :
1840 : : /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1841 : 224001 : RANGE_FOR_INIT_STMT (r) = init;
1842 : 224001 : RANGE_FOR_SCOPE (r) = scope;
1843 : :
1844 : 224001 : 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 : 224001 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1853 : : {
1854 : 224001 : if (processing_template_decl)
1855 : 448002 : RANGE_FOR_INIT_STMT (range_for_stmt)
1856 : 448002 : = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1857 : 224001 : RANGE_FOR_DECL (range_for_stmt) = decl;
1858 : 224001 : RANGE_FOR_EXPR (range_for_stmt) = expr;
1859 : 224001 : add_stmt (range_for_stmt);
1860 : 224001 : RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1861 : 224001 : }
1862 : :
1863 : : /* Begin the scope of an expansion-statement. */
1864 : :
1865 : : tree
1866 : 1130 : begin_template_for_scope (tree *init)
1867 : : {
1868 : 1130 : tree scope = do_pushlevel (sk_template_for);
1869 : :
1870 : 1130 : if (processing_template_decl)
1871 : 352 : *init = push_stmt_list ();
1872 : : else
1873 : 778 : *init = NULL_TREE;
1874 : :
1875 : 1130 : return scope;
1876 : : }
1877 : :
1878 : : /* Finish a break-statement. */
1879 : :
1880 : : tree
1881 : 5562863 : 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 : 5562863 : if (!block_may_fallthru (cur_stmt_list))
1891 : 787 : return void_node;
1892 : 5562076 : note_break_stmt ();
1893 : 5562076 : return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
1894 : : }
1895 : :
1896 : : /* Finish a continue-statement. */
1897 : :
1898 : : tree
1899 : 224132 : finish_continue_stmt (void)
1900 : : {
1901 : 224132 : 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 : 990742 : begin_switch_stmt (void)
1909 : : {
1910 : 990742 : tree r, scope;
1911 : :
1912 : 990742 : scope = do_pushlevel (sk_cond);
1913 : 990742 : r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1914 : : scope, NULL_TREE);
1915 : :
1916 : 990742 : begin_cond (&SWITCH_STMT_COND (r));
1917 : :
1918 : 990742 : return r;
1919 : : }
1920 : :
1921 : : /* Finish the cond of a switch-statement. */
1922 : :
1923 : : void
1924 : 990742 : finish_switch_cond (tree cond, tree switch_stmt)
1925 : : {
1926 : 990742 : tree orig_type = NULL;
1927 : :
1928 : 990742 : if (!processing_template_decl)
1929 : : {
1930 : : /* Convert the condition to an integer or enumeration type. */
1931 : 611477 : 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 : 611531 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1940 : 18 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1941 : 611477 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1942 : 611477 : 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 : 611477 : orig_type = unlowered_expr_type (cond);
1950 : 611477 : if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1951 : 263025 : orig_type = TREE_TYPE (cond);
1952 : 611477 : if (cond != error_mark_node)
1953 : : {
1954 : : /* [stmt.switch]
1955 : :
1956 : : Integral promotions are performed. */
1957 : 611444 : cond = perform_integral_promotions (cond);
1958 : 611444 : cond = maybe_cleanup_point_expr (cond);
1959 : : }
1960 : : }
1961 : 990742 : if (check_for_bare_parameter_packs (cond))
1962 : 0 : cond = error_mark_node;
1963 : 990742 : else if (!processing_template_decl && warn_sequence_point)
1964 : 2720 : verify_sequence_points (cond);
1965 : :
1966 : 990742 : finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1967 : 990742 : SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1968 : 990742 : add_stmt (switch_stmt);
1969 : 990742 : push_switch (switch_stmt);
1970 : 990742 : SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1971 : 990742 : }
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 : 990742 : finish_switch_stmt (tree switch_stmt)
1978 : : {
1979 : 990742 : tree scope;
1980 : :
1981 : 1981484 : SWITCH_STMT_BODY (switch_stmt) =
1982 : 990742 : pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1983 : 990742 : pop_switch ();
1984 : :
1985 : 990742 : scope = SWITCH_STMT_SCOPE (switch_stmt);
1986 : 990742 : SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1987 : 990742 : add_stmt (do_poplevel (scope));
1988 : 990742 : }
1989 : :
1990 : : /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1991 : : appropriate. */
1992 : :
1993 : : tree
1994 : 1130374 : begin_try_block (void)
1995 : : {
1996 : 1130374 : tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1997 : 1130374 : add_stmt (r);
1998 : 1130374 : TRY_STMTS (r) = push_stmt_list ();
1999 : 1130374 : 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 : 1130374 : finish_try_block (tree try_block)
2023 : : {
2024 : 1130374 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2025 : 1130374 : TRY_HANDLERS (try_block) = push_stmt_list ();
2026 : 1130374 : }
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 : 1130374 : finish_handler_sequence (tree try_block)
2063 : : {
2064 : 1130374 : TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
2065 : 1130374 : check_handlers (TRY_HANDLERS (try_block));
2066 : 1130374 : }
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 : 1576951 : begin_handler (void)
2084 : : {
2085 : 1576951 : tree r;
2086 : :
2087 : 1576951 : r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
2088 : 1576951 : add_stmt (r);
2089 : :
2090 : : /* Create a binding level for the eh_info and the exception object
2091 : : cleanup. */
2092 : 1576951 : HANDLER_BODY (r) = do_pushlevel (sk_catch);
2093 : :
2094 : 1576951 : 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 : 1576951 : finish_handler_parms (tree decl, tree handler)
2103 : : {
2104 : 1576951 : tree type = NULL_TREE;
2105 : 1576951 : if (processing_template_decl)
2106 : : {
2107 : 1439403 : if (decl)
2108 : : {
2109 : 469599 : decl = pushdecl (decl);
2110 : 469599 : decl = push_template_decl (decl);
2111 : 469599 : HANDLER_PARMS (handler) = decl;
2112 : 469599 : type = TREE_TYPE (decl);
2113 : : }
2114 : : }
2115 : : else
2116 : : {
2117 : 137548 : type = expand_start_catch_block (decl);
2118 : 137548 : if (warn_catch_value
2119 : 2070 : && type != NULL_TREE
2120 : 709 : && type != error_mark_node
2121 : 138257 : && !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 : 1576951 : HANDLER_TYPE (handler) = type;
2143 : 1576951 : }
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 : 1576951 : finish_handler (tree handler)
2150 : : {
2151 : 1576951 : if (!processing_template_decl)
2152 : 137548 : expand_end_catch_block ();
2153 : 1576951 : HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
2154 : 1576951 : }
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 : 298214314 : begin_compound_stmt (unsigned int flags)
2165 : : {
2166 : 298214314 : tree r;
2167 : :
2168 : 298214314 : if (flags & BCS_NO_SCOPE)
2169 : : {
2170 : 7830474 : r = push_stmt_list ();
2171 : 7830474 : 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 : 7830474 : keep_next_level (false);
2178 : : }
2179 : : else
2180 : : {
2181 : 290383840 : scope_kind sk = sk_block;
2182 : 290383840 : if (flags & BCS_TRY_BLOCK)
2183 : : sk = sk_try;
2184 : 289253584 : else if (flags & BCS_TRANSACTION)
2185 : : sk = sk_transaction;
2186 : 289253349 : else if (flags & BCS_STMT_EXPR)
2187 : 29082 : sk = sk_stmt_expr;
2188 : 290383840 : 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 : 298214314 : if (processing_template_decl)
2198 : : {
2199 : 183812925 : r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
2200 : 183812925 : BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
2201 : 183812925 : BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
2202 : 183812925 : TREE_SIDE_EFFECTS (r) = 1;
2203 : : }
2204 : :
2205 : 298214314 : return r;
2206 : : }
2207 : :
2208 : : /* Finish a compound-statement, which is given by STMT. */
2209 : :
2210 : : void
2211 : 298214275 : finish_compound_stmt (tree stmt)
2212 : : {
2213 : 298214275 : if (TREE_CODE (stmt) == BIND_EXPR)
2214 : : {
2215 : 183812925 : 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 : 183812925 : if (TREE_CODE (body) == STATEMENT_LIST
2220 : 168420923 : && STATEMENT_LIST_HEAD (body) == NULL
2221 : 11308680 : && !BIND_EXPR_BODY_BLOCK (stmt)
2222 : 194623374 : && !BIND_EXPR_TRY_BLOCK (stmt))
2223 : : stmt = body;
2224 : : else
2225 : 173002573 : BIND_EXPR_BODY (stmt) = body;
2226 : : }
2227 : 114401350 : else if (STATEMENT_LIST_NO_SCOPE (stmt))
2228 : 7794368 : stmt = pop_stmt_list (stmt);
2229 : : else
2230 : : {
2231 : : /* Destroy any ObjC "super" receivers that may have been
2232 : : created. */
2233 : 106606982 : objc_clear_super_receiver ();
2234 : :
2235 : 106606982 : stmt = do_poplevel (stmt);
2236 : : }
2237 : :
2238 : : /* ??? See c_end_compound_stmt wrt statement expressions. */
2239 : 298214275 : add_stmt (stmt);
2240 : 298214275 : }
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 : 53465 : finish_asm_string_expression (location_t loc, tree string)
2248 : : {
2249 : 53465 : if (string == error_mark_node
2250 : 53452 : || 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 : 24785 : 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 : 24785 : tree r;
2277 : 24785 : tree t;
2278 : 24785 : int ninputs = list_length (input_operands);
2279 : 24785 : int noutputs = list_length (output_operands);
2280 : :
2281 : 24785 : if (!processing_template_decl)
2282 : : {
2283 : 12540 : const char *constraint;
2284 : 12540 : const char **oconstraints;
2285 : 12540 : bool allows_mem, allows_reg, is_inout;
2286 : 12540 : tree operand;
2287 : 12540 : int i;
2288 : :
2289 : 12540 : oconstraints = XALLOCAVEC (const char *, noutputs);
2290 : :
2291 : 24978 : string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
2292 : : string);
2293 : 12540 : if (string == error_mark_node)
2294 : 109 : return error_mark_node;
2295 : 37338 : for (int i = 0; i < 2; ++i)
2296 : 84674 : for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
2297 : : {
2298 : 34890 : tree s = TREE_VALUE (TREE_PURPOSE (t));
2299 : 69762 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2300 : 34890 : if (s == error_mark_node)
2301 : : return error_mark_node;
2302 : 34860 : TREE_VALUE (TREE_PURPOSE (t)) = s;
2303 : : }
2304 : 17866 : for (t = clobbers; t; t = TREE_CHAIN (t))
2305 : : {
2306 : 5435 : tree s = TREE_VALUE (t);
2307 : 10864 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2308 : 5435 : TREE_VALUE (t) = s;
2309 : : }
2310 : :
2311 : 12431 : string = resolve_asm_operand_names (string, output_operands,
2312 : : input_operands, labels);
2313 : :
2314 : 30690 : for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
2315 : : {
2316 : 18259 : 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 : 18259 : STRIP_NOPS (operand);
2325 : :
2326 : 18259 : operand = mark_lvalue_use (operand);
2327 : :
2328 : 18259 : if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
2329 : 9 : operand = error_mark_node;
2330 : :
2331 : 18259 : if (operand != error_mark_node
2332 : 18259 : && (TREE_READONLY (operand)
2333 : 18244 : || CP_TYPE_CONST_P (TREE_TYPE (operand))
2334 : : /* Functions are not modifiable, even though they are
2335 : : lvalues. */
2336 : 18244 : || 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 : 18244 : || (CLASS_TYPE_P (TREE_TYPE (operand))
2340 : 32 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
2341 : 6 : cxx_readonly_error (loc, operand, lv_asm);
2342 : :
2343 : : tree *op = &operand;
2344 : 18266 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2345 : 7 : op = &TREE_OPERAND (*op, 1);
2346 : 18259 : 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 : 18259 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2359 : 18259 : oconstraints[i] = constraint;
2360 : :
2361 : 18259 : 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 : 18250 : if (!allows_reg && !cxx_mark_addressable (*op))
2368 : 0 : operand = error_mark_node;
2369 : 18250 : 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 : 306 : 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 : 18238 : 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 : 18259 : TREE_VALUE (t) = operand;
2415 : : }
2416 : :
2417 : 29027 : for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
2418 : : {
2419 : 16596 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2420 : 16596 : bool constraint_parsed
2421 : 16596 : = 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 : 16596 : if (constraint_parsed && !allows_reg && allows_mem)
2427 : 172 : operand = mark_lvalue_use (TREE_VALUE (t));
2428 : : else
2429 : 16424 : 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 : 16596 : 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 : 16596 : if (constraint_parsed)
2444 : : {
2445 : : /* If the operand is going to end up in memory,
2446 : : mark it addressable. */
2447 : 16575 : 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 : 172 : STRIP_NOPS (operand);
2452 : :
2453 : 172 : tree *op = &operand;
2454 : 179 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2455 : 7 : op = &TREE_OPERAND (*op, 1);
2456 : 172 : 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 : 172 : if (!cxx_mark_addressable (*op))
2469 : 0 : operand = error_mark_node;
2470 : : }
2471 : 16403 : else if (!allows_reg && !allows_mem)
2472 : : {
2473 : : /* If constraint allows neither register nor memory,
2474 : : try harder to get a constant. */
2475 : 471 : tree constop = maybe_constant_value (operand);
2476 : 471 : if (TREE_CONSTANT (constop))
2477 : 444 : operand = constop;
2478 : : }
2479 : 16575 : 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 : 16575 : if (constraint[0] == ':' && operand != error_mark_node)
2486 : : {
2487 : 45 : tree t = operand;
2488 : 45 : STRIP_NOPS (t);
2489 : 45 : if (TREE_CODE (t) != ADDR_EXPR
2490 : 45 : || !(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 : : }
2499 : : }
2500 : : else
2501 : 21 : operand = error_mark_node;
2502 : :
2503 : 16596 : if (toplev_p && operand != error_mark_node)
2504 : : {
2505 : 114 : if (TREE_SIDE_EFFECTS (operand))
2506 : : {
2507 : 6 : error_at (loc, "side-effects in input operand outside "
2508 : : "of a function");
2509 : 6 : operand = error_mark_node;
2510 : : }
2511 : 108 : else if (allows_mem && lvalue_or_else (operand, lv_asm, tf_none))
2512 : : {
2513 : 21 : tree addr = cp_build_addr_expr (operand, tf_warning_or_error);
2514 : 21 : if (addr == error_mark_node)
2515 : 0 : operand = error_mark_node;
2516 : : else
2517 : : {
2518 : 21 : addr = maybe_constant_value (addr);
2519 : 21 : if (!initializer_constant_valid_p (addr,
2520 : 21 : TREE_TYPE (addr)))
2521 : : {
2522 : 3 : error_at (loc, "input operand outside of a "
2523 : : "function is not constant");
2524 : 3 : operand = error_mark_node;
2525 : : }
2526 : : else
2527 : 18 : operand = build_fold_indirect_ref (addr);
2528 : : }
2529 : : }
2530 : : else
2531 : : {
2532 : 87 : operand = maybe_constant_value (operand);
2533 : 87 : if (!initializer_constant_valid_p (operand,
2534 : 87 : TREE_TYPE (operand)))
2535 : : {
2536 : 3 : error_at (loc, "input operand outside of a "
2537 : : "function is not constant");
2538 : 3 : operand = error_mark_node;
2539 : : }
2540 : : }
2541 : : }
2542 : 16482 : else if (operand != error_mark_node && strstr (constraint, "-"))
2543 : : {
2544 : 9 : error_at (loc, "%<-%> modifier used inside of a function");
2545 : 9 : operand = error_mark_node;
2546 : : }
2547 : :
2548 : 16596 : TREE_VALUE (t) = operand;
2549 : : }
2550 : : }
2551 : :
2552 : 24676 : r = build_stmt (loc, ASM_EXPR, string,
2553 : : output_operands, input_operands,
2554 : : clobbers, labels);
2555 : 24676 : ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
2556 : 24676 : ASM_INLINE_P (r) = inline_p;
2557 : 24676 : if (toplev_p)
2558 : : {
2559 : 96 : symtab->finalize_toplevel_asm (r);
2560 : 96 : return r;
2561 : : }
2562 : 24580 : r = maybe_cleanup_point_expr_void (r);
2563 : 24580 : return add_stmt (r);
2564 : : }
2565 : :
2566 : : /* Finish a label with the indicated NAME. Returns the new label. */
2567 : :
2568 : : tree
2569 : 2478 : finish_label_stmt (tree name)
2570 : : {
2571 : 2478 : tree decl = define_label (input_location, name);
2572 : :
2573 : 2478 : if (decl == error_mark_node)
2574 : : return error_mark_node;
2575 : :
2576 : 2472 : add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
2577 : :
2578 : 2472 : return decl;
2579 : : }
2580 : :
2581 : : /* Finish a series of declarations for local labels. G++ allows users
2582 : : to declare "local" labels, i.e., labels with scope. This extension
2583 : : is useful when writing code involving statement-expressions. */
2584 : :
2585 : : void
2586 : 219 : finish_label_decl (tree name)
2587 : : {
2588 : 219 : if (!at_function_scope_p ())
2589 : : {
2590 : 0 : error ("%<__label__%> declarations are only allowed in function scopes");
2591 : 0 : return;
2592 : : }
2593 : :
2594 : 219 : add_decl_expr (declare_local_label (name));
2595 : : }
2596 : :
2597 : : /* When DECL goes out of scope, make sure that CLEANUP is executed. */
2598 : :
2599 : : void
2600 : 3919657 : finish_decl_cleanup (tree decl, tree cleanup)
2601 : : {
2602 : 3919657 : push_cleanup (decl, cleanup, false);
2603 : 3919657 : }
2604 : :
2605 : : /* If the current scope exits with an exception, run CLEANUP. */
2606 : :
2607 : : void
2608 : 2178641 : finish_eh_cleanup (tree cleanup)
2609 : : {
2610 : 2178641 : push_cleanup (NULL, cleanup, true);
2611 : 2178641 : }
2612 : :
2613 : : /* The MEM_INITS is a list of mem-initializers, in reverse of the
2614 : : order they were written by the user. Each node is as for
2615 : : emit_mem_initializers. */
2616 : :
2617 : : void
2618 : 20575187 : finish_mem_initializers (tree mem_inits)
2619 : : {
2620 : : /* Reorder the MEM_INITS so that they are in the order they appeared
2621 : : in the source program. */
2622 : 20575187 : mem_inits = nreverse (mem_inits);
2623 : :
2624 : 20575187 : if (processing_template_decl)
2625 : : {
2626 : : tree mem;
2627 : :
2628 : 33353078 : for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
2629 : : {
2630 : : /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
2631 : : check for bare parameter packs in the TREE_VALUE, because
2632 : : any parameter packs in the TREE_VALUE have already been
2633 : : bound as part of the TREE_PURPOSE. See
2634 : : make_pack_expansion for more information. */
2635 : 19740957 : if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
2636 : 19740957 : && check_for_bare_parameter_packs (TREE_VALUE (mem)))
2637 : 3 : TREE_VALUE (mem) = error_mark_node;
2638 : : }
2639 : :
2640 : 13612121 : add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
2641 : : CTOR_INITIALIZER, mem_inits));
2642 : : }
2643 : : else
2644 : 6963066 : emit_mem_initializers (mem_inits);
2645 : 20575187 : }
2646 : :
2647 : : /* Obfuscate EXPR if it looks like an id-expression or member access so
2648 : : that the call to finish_decltype in do_auto_deduction will give the
2649 : : right result. If EVEN_UNEVAL, do this even in unevaluated context. */
2650 : :
2651 : : tree
2652 : 47060350 : force_paren_expr (tree expr, bool even_uneval /* = false */)
2653 : : {
2654 : : /* This is only needed for decltype(auto) in C++14. */
2655 : 47060350 : if (cxx_dialect < cxx14)
2656 : : return expr;
2657 : :
2658 : : /* If we're in unevaluated context, we can't be deducing a
2659 : : return/initializer type, so we don't need to mess with this. */
2660 : 46418231 : if (cp_unevaluated_operand && !even_uneval)
2661 : : return expr;
2662 : :
2663 : 38960417 : if (TREE_CODE (expr) == COMPONENT_REF
2664 : 38903450 : || TREE_CODE (expr) == SCOPE_REF
2665 : 77857779 : || REFERENCE_REF_P (expr))
2666 : 892061 : REF_PARENTHESIZED_P (expr) = true;
2667 : 38068356 : else if (DECL_P (tree_strip_any_location_wrapper (expr)))
2668 : : {
2669 : 1913218 : location_t loc = cp_expr_location (expr);
2670 : 1913218 : const tree_code code = processing_template_decl ? PAREN_EXPR
2671 : : : VIEW_CONVERT_EXPR;
2672 : 1913218 : expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
2673 : 1913218 : REF_PARENTHESIZED_P (expr) = true;
2674 : : }
2675 : : return expr;
2676 : : }
2677 : :
2678 : : /* If T is an id-expression obfuscated by force_paren_expr, undo the
2679 : : obfuscation and return the underlying id-expression. Otherwise
2680 : : return T. */
2681 : :
2682 : : tree
2683 : 1217945541 : maybe_undo_parenthesized_ref (tree t)
2684 : : {
2685 : 1217945541 : if (cxx_dialect < cxx14)
2686 : : return t;
2687 : :
2688 : 1207939395 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
2689 : 1340146495 : && REF_PARENTHESIZED_P (t))
2690 : 292412 : t = TREE_OPERAND (t, 0);
2691 : :
2692 : : return t;
2693 : : }
2694 : :
2695 : : /* Finish a parenthesized expression EXPR. */
2696 : :
2697 : : cp_expr
2698 : 32385063 : finish_parenthesized_expr (cp_expr expr)
2699 : : {
2700 : 32385063 : if (EXPR_P (expr))
2701 : : {
2702 : : /* This inhibits warnings in maybe_warn_unparenthesized_assignment
2703 : : and c_common_truthvalue_conversion. */
2704 : 64483526 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
2705 : : /* And maybe_warn_sizeof_array_div. */
2706 : 64483526 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
2707 : : }
2708 : :
2709 : 32385063 : if (TREE_CODE (expr) == OFFSET_REF
2710 : 32385063 : || TREE_CODE (expr) == SCOPE_REF)
2711 : : /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
2712 : : enclosed in parentheses. */
2713 : 28910 : PTRMEM_OK_P (expr) = 0;
2714 : :
2715 : 32385063 : tree stripped_expr = tree_strip_any_location_wrapper (expr);
2716 : 32385063 : if (TREE_CODE (stripped_expr) == STRING_CST)
2717 : 819412 : PAREN_STRING_LITERAL_P (stripped_expr) = 1;
2718 : 31565651 : else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
2719 : 822 : PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
2720 : :
2721 : 32385063 : expr = cp_expr (force_paren_expr (expr), expr.get_location ());
2722 : :
2723 : 32385063 : return expr;
2724 : : }
2725 : :
2726 : : /* Finish a reference to a non-static data member (DECL) that is not
2727 : : preceded by `.' or `->'. */
2728 : :
2729 : : tree
2730 : 84293166 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
2731 : : tsubst_flags_t complain /* = tf_warning_or_error */)
2732 : : {
2733 : 84293166 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
2734 : 84293166 : bool try_omp_private = !object && omp_private_member_map;
2735 : 65156002 : tree ret;
2736 : :
2737 : 65156002 : if (!object)
2738 : : {
2739 : 65156002 : tree scope = qualifying_scope;
2740 : 65156002 : if (scope == NULL_TREE)
2741 : : {
2742 : 65144993 : scope = context_for_name_lookup (decl);
2743 : 65144993 : if (!TYPE_P (scope))
2744 : : {
2745 : : /* Can happen during error recovery (c++/85014). */
2746 : 3 : gcc_assert (seen_error ());
2747 : 3 : return error_mark_node;
2748 : : }
2749 : : }
2750 : 65155999 : object = maybe_dummy_object (scope, NULL);
2751 : : }
2752 : :
2753 : 84293163 : object = maybe_resolve_dummy (object, true);
2754 : 84293163 : if (object == error_mark_node)
2755 : : return error_mark_node;
2756 : :
2757 : : /* DR 613/850: Can use non-static data members without an associated
2758 : : object in sizeof/decltype/alignof. */
2759 : 84293160 : if (is_dummy_object (object)
2760 : 29618 : && !cp_unevaluated_operand
2761 : 84293254 : && (!processing_template_decl || !current_class_ref))
2762 : : {
2763 : 79 : if (complain & tf_error)
2764 : : {
2765 : 73 : auto_diagnostic_group d;
2766 : 73 : if (current_function_decl
2767 : 73 : && DECL_STATIC_FUNCTION_P (current_function_decl))
2768 : 3 : error ("invalid use of member %qD in static member function", decl);
2769 : 70 : else if (current_function_decl
2770 : 63 : && processing_contract_condition
2771 : 70 : && DECL_CONSTRUCTOR_P (current_function_decl))
2772 : 0 : error ("invalid use of member %qD in constructor %<pre%> contract", decl);
2773 : 70 : else if (current_function_decl
2774 : 63 : && processing_contract_condition
2775 : 70 : && DECL_DESTRUCTOR_P (current_function_decl))
2776 : 0 : error ("invalid use of member %qD in destructor %<post%> contract", decl);
2777 : : else
2778 : 70 : error ("invalid use of non-static data member %qD", decl);
2779 : 73 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
2780 : 73 : }
2781 : :
2782 : 79 : return error_mark_node;
2783 : : }
2784 : :
2785 : 84293081 : if (current_class_ptr)
2786 : 83879707 : TREE_USED (current_class_ptr) = 1;
2787 : 84293081 : if (processing_template_decl)
2788 : : {
2789 : 59495439 : tree type = TREE_TYPE (decl);
2790 : :
2791 : 59495439 : if (TYPE_REF_P (type))
2792 : : /* Quals on the object don't matter. */;
2793 : 57205985 : else if (PACK_EXPANSION_P (type))
2794 : : /* Don't bother trying to represent this. */
2795 : : type = NULL_TREE;
2796 : 57203717 : else if (!TREE_TYPE (object) || WILDCARD_TYPE_P (TREE_TYPE (object)))
2797 : : /* We don't know what the eventual quals will be, so punt until
2798 : : instantiation time.
2799 : :
2800 : : This can happen when called from build_capture_proxy for an explicit
2801 : : object lambda. It's a bit marginal to call this function in that
2802 : : case, since this function is for references to members of 'this',
2803 : : but the deduced type is required to be derived from the closure
2804 : : type, so it works. */
2805 : : type = NULL_TREE;
2806 : : else
2807 : : {
2808 : : /* Set the cv qualifiers. */
2809 : 57201642 : int quals = cp_type_quals (TREE_TYPE (object));
2810 : :
2811 : 57201642 : if (DECL_MUTABLE_P (decl))
2812 : 289167 : quals &= ~TYPE_QUAL_CONST;
2813 : :
2814 : 57201642 : quals |= cp_type_quals (TREE_TYPE (decl));
2815 : 57201642 : type = cp_build_qualified_type (type, quals);
2816 : : }
2817 : :
2818 : 59495439 : if (qualifying_scope)
2819 : : /* Wrap this in a SCOPE_REF for now. */
2820 : 9122 : ret = build_qualified_name (type, qualifying_scope, decl,
2821 : : /*template_p=*/false);
2822 : : else
2823 : 59486317 : ret = (convert_from_reference
2824 : 59486317 : (build_min (COMPONENT_REF, type, object, decl, NULL_TREE)));
2825 : : }
2826 : : /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
2827 : : QUALIFYING_SCOPE is also non-null. */
2828 : : else
2829 : : {
2830 : 24797642 : tree access_type = TREE_TYPE (object);
2831 : :
2832 : 24797642 : if (!perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
2833 : : decl, complain))
2834 : 0 : return error_mark_node;
2835 : :
2836 : : /* If the data member was named `C::M', convert `*this' to `C'
2837 : : first. */
2838 : 24797642 : if (qualifying_scope)
2839 : : {
2840 : 1851 : tree binfo = NULL_TREE;
2841 : 1851 : object = build_scoped_ref (object, qualifying_scope,
2842 : : &binfo);
2843 : : }
2844 : :
2845 : 24797642 : ret = build_class_member_access_expr (object, decl,
2846 : : /*access_path=*/NULL_TREE,
2847 : : /*preserve_reference=*/false,
2848 : : complain);
2849 : : }
2850 : 84293081 : if (try_omp_private)
2851 : : {
2852 : 1662 : tree *v = omp_private_member_map->get (decl);
2853 : 1662 : if (v)
2854 : 1234 : ret = convert_from_reference (*v);
2855 : : }
2856 : : return ret;
2857 : : }
2858 : :
2859 : : /* DECL was the declaration to which a qualified-id resolved. Issue
2860 : : an error message if it is not accessible. If OBJECT_TYPE is
2861 : : non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2862 : : type of `*x', or `x', respectively. If the DECL was named as
2863 : : `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like
2864 : : perform_access_checks above. */
2865 : :
2866 : : bool
2867 : 4770737125 : check_accessibility_of_qualified_id (tree decl,
2868 : : tree object_type,
2869 : : tree nested_name_specifier,
2870 : : tsubst_flags_t complain)
2871 : : {
2872 : : /* If we're not checking, return immediately. */
2873 : 4770737125 : if (deferred_access_no_check)
2874 : : return true;
2875 : :
2876 : : /* Determine the SCOPE of DECL. */
2877 : 4762822294 : tree scope = context_for_name_lookup (decl);
2878 : : /* If the SCOPE is not a type, then DECL is not a member. */
2879 : 4762822294 : if (!TYPE_P (scope)
2880 : : /* If SCOPE is dependent then we can't perform this access check now,
2881 : : and since we'll perform this access check again after substitution
2882 : : there's no need to explicitly defer it. */
2883 : 4762822294 : || dependent_type_p (scope))
2884 : 4202369559 : return true;
2885 : :
2886 : 560452735 : tree qualifying_type = NULL_TREE;
2887 : : /* Compute the scope through which DECL is being accessed. */
2888 : 560452735 : if (object_type
2889 : : /* OBJECT_TYPE might not be a class type; consider:
2890 : :
2891 : : class A { typedef int I; };
2892 : : I *p;
2893 : : p->A::I::~I();
2894 : :
2895 : : In this case, we will have "A::I" as the DECL, but "I" as the
2896 : : OBJECT_TYPE. */
2897 : 94021 : && CLASS_TYPE_P (object_type)
2898 : 560546739 : && DERIVED_FROM_P (scope, object_type))
2899 : : {
2900 : : /* If we are processing a `->' or `.' expression, use the type of the
2901 : : left-hand side. */
2902 : 93995 : if (tree open = currently_open_class (object_type))
2903 : : qualifying_type = open;
2904 : : else
2905 : : qualifying_type = object_type;
2906 : : }
2907 : 560358740 : else if (nested_name_specifier)
2908 : : {
2909 : : /* If the reference is to a non-static member of the
2910 : : current class, treat it as if it were referenced through
2911 : : `this'. */
2912 : 819203461 : if (DECL_NONSTATIC_MEMBER_P (decl)
2913 : 409651208 : && current_class_ptr)
2914 : 39718 : if (tree current = current_nonlambda_class_type ())
2915 : : {
2916 : 39695 : if (dependent_type_p (current))
2917 : : /* In general we can't know whether this access goes through
2918 : : `this' until instantiation time. Punt now, or else we might
2919 : : create a deferred access check that's not relative to `this'
2920 : : when it ought to be. We'll check this access again after
2921 : : substitution, e.g. from tsubst_qualified_id. */
2922 : : return true;
2923 : :
2924 : 3541 : if (DERIVED_FROM_P (scope, current))
2925 : : qualifying_type = current;
2926 : : }
2927 : : /* Otherwise, use the type indicated by the
2928 : : nested-name-specifier. */
2929 : : if (!qualifying_type)
2930 : : qualifying_type = nested_name_specifier;
2931 : : }
2932 : : else
2933 : : /* Otherwise, the name must be from the current class or one of
2934 : : its bases. */
2935 : 150757008 : qualifying_type = currently_open_derived_class (scope);
2936 : :
2937 : 560359309 : if (qualifying_type
2938 : : /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2939 : : or similar in a default argument value. */
2940 : 560416581 : && CLASS_TYPE_P (qualifying_type))
2941 : 534340795 : return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2942 : 534340795 : decl, complain);
2943 : :
2944 : : return true;
2945 : : }
2946 : :
2947 : : /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2948 : : class named to the left of the "::" operator. DONE is true if this
2949 : : expression is a complete postfix-expression; it is false if this
2950 : : expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2951 : : iff this expression is the operand of '&'. TEMPLATE_P is true iff
2952 : : the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2953 : : is true iff this qualified name appears as a template argument. */
2954 : :
2955 : : tree
2956 : 96705357 : finish_qualified_id_expr (tree qualifying_class,
2957 : : tree expr,
2958 : : bool done,
2959 : : bool address_p,
2960 : : bool template_p,
2961 : : bool template_arg_p,
2962 : : tsubst_flags_t complain)
2963 : : {
2964 : 96705357 : gcc_assert (TYPE_P (qualifying_class));
2965 : :
2966 : 96705357 : if (error_operand_p (expr))
2967 : 18 : return error_mark_node;
2968 : :
2969 : 96705339 : if (DECL_P (expr)
2970 : : /* Functions are marked after overload resolution; avoid redundant
2971 : : warnings. */
2972 : 89145400 : && TREE_CODE (expr) != FUNCTION_DECL
2973 : 185850703 : && !mark_used (expr, complain))
2974 : 0 : return error_mark_node;
2975 : :
2976 : 96705339 : if (template_p)
2977 : : {
2978 : 233932 : if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE)
2979 : : {
2980 : : /* cp_parser_lookup_name thought we were looking for a type,
2981 : : but we're actually looking for a declaration. */
2982 : 9 : qualifying_class = TYPE_CONTEXT (expr);
2983 : 9 : expr = TYPE_IDENTIFIER (expr);
2984 : : }
2985 : : else
2986 : 233923 : check_template_keyword (expr);
2987 : : }
2988 : :
2989 : : /* If EXPR occurs as the operand of '&', use special handling that
2990 : : permits a pointer-to-member. */
2991 : 96705339 : if (address_p && done
2992 : 154659 : && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
2993 : : {
2994 : 154657 : if (TREE_CODE (expr) == SCOPE_REF)
2995 : 0 : expr = TREE_OPERAND (expr, 1);
2996 : 154657 : expr = build_offset_ref (qualifying_class, expr,
2997 : : /*address_p=*/true, complain);
2998 : 154657 : return expr;
2999 : : }
3000 : :
3001 : : /* No need to check access within an enum. */
3002 : 96550682 : if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
3003 : 3394414 : && TREE_CODE (expr) != IDENTIFIER_NODE)
3004 : : return expr;
3005 : :
3006 : : /* Within the scope of a class, turn references to non-static
3007 : : members into expression of the form "this->...". */
3008 : 93156271 : if (template_arg_p)
3009 : : /* But, within a template argument, we do not want make the
3010 : : transformation, as there is no "this" pointer. */
3011 : : ;
3012 : 93153663 : else if (TREE_CODE (expr) == FIELD_DECL)
3013 : : {
3014 : 11009 : push_deferring_access_checks (dk_no_check);
3015 : 11009 : expr = finish_non_static_data_member (expr, NULL_TREE,
3016 : : qualifying_class, complain);
3017 : 11009 : pop_deferring_access_checks ();
3018 : : }
3019 : 93142654 : else if (BASELINK_P (expr))
3020 : : {
3021 : : /* See if any of the functions are non-static members. */
3022 : : /* If so, the expression may be relative to 'this'. */
3023 : 7125951 : if (!shared_member_p (expr)
3024 : 458496 : && current_class_ptr
3025 : 7583847 : && DERIVED_FROM_P (qualifying_class,
3026 : : current_nonlambda_class_type ()))
3027 : 457766 : expr = (build_class_member_access_expr
3028 : 457766 : (maybe_dummy_object (qualifying_class, NULL),
3029 : : expr,
3030 : 457766 : BASELINK_ACCESS_BINFO (expr),
3031 : : /*preserve_reference=*/false,
3032 : : complain));
3033 : 6668185 : else if (done)
3034 : : /* The expression is a qualified name whose address is not
3035 : : being taken. */
3036 : 2279 : expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
3037 : : complain);
3038 : : }
3039 : 86016703 : else if (!template_p
3040 : 85826963 : && TREE_CODE (expr) == TEMPLATE_DECL
3041 : 86016783 : && !DECL_FUNCTION_TEMPLATE_P (expr))
3042 : : {
3043 : 80 : if (complain & tf_error)
3044 : 4 : error ("%qE missing template arguments", expr);
3045 : 80 : return error_mark_node;
3046 : : }
3047 : : else
3048 : : {
3049 : : /* In a template, return a SCOPE_REF for most qualified-ids
3050 : : so that we can check access at instantiation time. But if
3051 : : we're looking at a member of the current instantiation, we
3052 : : know we have access and building up the SCOPE_REF confuses
3053 : : non-type template argument handling. */
3054 : 86016623 : if (processing_template_decl
3055 : 86016623 : && (!currently_open_class (qualifying_class)
3056 : 9801 : || TREE_CODE (expr) == IDENTIFIER_NODE
3057 : 9801 : || TREE_CODE (expr) == TEMPLATE_ID_EXPR
3058 : 82 : || TREE_CODE (expr) == BIT_NOT_EXPR))
3059 : 10598277 : expr = build_qualified_name (TREE_TYPE (expr),
3060 : : qualifying_class, expr,
3061 : : template_p);
3062 : 75418346 : else if (tree wrap = maybe_get_tls_wrapper_call (expr))
3063 : 9 : expr = wrap;
3064 : :
3065 : 86016623 : expr = convert_from_reference (expr);
3066 : : }
3067 : :
3068 : : return expr;
3069 : : }
3070 : :
3071 : : /* Begin a statement-expression. The value returned must be passed to
3072 : : finish_stmt_expr. */
3073 : :
3074 : : tree
3075 : 7852032 : begin_stmt_expr (void)
3076 : : {
3077 : 7852032 : return push_stmt_list ();
3078 : : }
3079 : :
3080 : : /* Process the final expression of a statement expression. EXPR can be
3081 : : NULL, if the final expression is empty. Return a STATEMENT_LIST
3082 : : containing all the statements in the statement-expression, or
3083 : : ERROR_MARK_NODE if there was an error. */
3084 : :
3085 : : tree
3086 : 29672 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
3087 : : {
3088 : 29672 : if (error_operand_p (expr))
3089 : : {
3090 : : /* The type of the statement-expression is the type of the last
3091 : : expression. */
3092 : 3 : TREE_TYPE (stmt_expr) = error_mark_node;
3093 : 3 : return error_mark_node;
3094 : : }
3095 : :
3096 : : /* If the last statement does not have "void" type, then the value
3097 : : of the last statement is the value of the entire expression. */
3098 : 29669 : if (expr)
3099 : : {
3100 : 29654 : tree type = TREE_TYPE (expr);
3101 : :
3102 : 29654 : if (type && type_unknown_p (type))
3103 : : {
3104 : 15 : error ("a statement expression is an insufficient context"
3105 : : " for overload resolution");
3106 : 15 : TREE_TYPE (stmt_expr) = error_mark_node;
3107 : 15 : return error_mark_node;
3108 : : }
3109 : 29639 : else if (processing_template_decl)
3110 : : {
3111 : : /* Not finish_expr_stmt because we don't want convert_to_void. */
3112 : 169 : expr = build_stmt (input_location, EXPR_STMT, expr);
3113 : 169 : expr = add_stmt (expr);
3114 : : /* Mark the last statement so that we can recognize it as such at
3115 : : template-instantiation time. */
3116 : 169 : EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
3117 : : }
3118 : 29470 : else if (VOID_TYPE_P (type))
3119 : : {
3120 : : /* Just treat this like an ordinary statement. */
3121 : 31 : expr = finish_expr_stmt (expr);
3122 : : }
3123 : : else
3124 : : {
3125 : : /* It actually has a value we need to deal with. First, force it
3126 : : to be an rvalue so that we won't need to build up a copy
3127 : : constructor call later when we try to assign it to something. */
3128 : 29439 : expr = force_rvalue (expr, tf_warning_or_error);
3129 : 29439 : if (error_operand_p (expr))
3130 : 0 : return error_mark_node;
3131 : :
3132 : : /* Update for array-to-pointer decay. */
3133 : 29439 : type = TREE_TYPE (expr);
3134 : :
3135 : : /* This TARGET_EXPR will initialize the outer one added by
3136 : : finish_stmt_expr. */
3137 : 29439 : set_target_expr_eliding (expr);
3138 : :
3139 : : /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
3140 : : normal statement, but don't convert to void or actually add
3141 : : the EXPR_STMT. */
3142 : 29439 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
3143 : 29439 : expr = maybe_cleanup_point_expr (expr);
3144 : 29439 : add_stmt (expr);
3145 : : }
3146 : :
3147 : : /* The type of the statement-expression is the type of the last
3148 : : expression. */
3149 : 29639 : TREE_TYPE (stmt_expr) = type;
3150 : : }
3151 : :
3152 : : return stmt_expr;
3153 : : }
3154 : :
3155 : : /* Finish a statement-expression. EXPR should be the value returned
3156 : : by the previous begin_stmt_expr. Returns an expression
3157 : : representing the statement-expression. */
3158 : :
3159 : : tree
3160 : 7852032 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
3161 : : {
3162 : 7852032 : tree type;
3163 : 7852032 : tree result;
3164 : :
3165 : 7852032 : if (error_operand_p (stmt_expr))
3166 : : {
3167 : 18 : pop_stmt_list (stmt_expr);
3168 : 18 : return error_mark_node;
3169 : : }
3170 : :
3171 : 7852014 : gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
3172 : :
3173 : 7852014 : type = TREE_TYPE (stmt_expr);
3174 : 7852014 : result = pop_stmt_list (stmt_expr);
3175 : 7852014 : TREE_TYPE (result) = type;
3176 : :
3177 : 7852014 : if (processing_template_decl)
3178 : : {
3179 : 36299 : result = build_min (STMT_EXPR, type, result);
3180 : 36299 : TREE_SIDE_EFFECTS (result) = 1;
3181 : 36299 : STMT_EXPR_NO_SCOPE (result) = has_no_scope;
3182 : : }
3183 : 7815715 : else if (CLASS_TYPE_P (type))
3184 : : {
3185 : : /* Wrap the statement-expression in a TARGET_EXPR so that the
3186 : : temporary object created by the final expression is destroyed at
3187 : : the end of the full-expression containing the
3188 : : statement-expression. */
3189 : 118 : result = force_target_expr (type, result, tf_warning_or_error);
3190 : : }
3191 : :
3192 : : return result;
3193 : : }
3194 : :
3195 : : /* Returns the expression which provides the value of STMT_EXPR. */
3196 : :
3197 : : tree
3198 : 191 : stmt_expr_value_expr (tree stmt_expr)
3199 : : {
3200 : 191 : tree t = STMT_EXPR_STMT (stmt_expr);
3201 : :
3202 : 191 : if (TREE_CODE (t) == BIND_EXPR)
3203 : 191 : t = BIND_EXPR_BODY (t);
3204 : :
3205 : 191 : if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
3206 : 158 : t = STATEMENT_LIST_TAIL (t)->stmt;
3207 : :
3208 : 191 : if (TREE_CODE (t) == EXPR_STMT)
3209 : 173 : t = EXPR_STMT_EXPR (t);
3210 : :
3211 : 191 : return t;
3212 : : }
3213 : :
3214 : : /* Return TRUE iff EXPR_STMT is an empty list of
3215 : : expression statements. */
3216 : :
3217 : : bool
3218 : 59045204 : empty_expr_stmt_p (tree expr_stmt)
3219 : : {
3220 : 59045207 : tree body = NULL_TREE;
3221 : :
3222 : 59045207 : if (expr_stmt == void_node)
3223 : : return true;
3224 : :
3225 : 59045204 : if (expr_stmt)
3226 : : {
3227 : 59045204 : if (TREE_CODE (expr_stmt) == EXPR_STMT)
3228 : 3 : body = EXPR_STMT_EXPR (expr_stmt);
3229 : 59045201 : else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
3230 : : body = expr_stmt;
3231 : : }
3232 : :
3233 : 3 : if (body)
3234 : : {
3235 : 58150371 : if (TREE_CODE (body) == STATEMENT_LIST)
3236 : 58150368 : return tsi_end_p (tsi_start (body));
3237 : : else
3238 : : return empty_expr_stmt_p (body);
3239 : : }
3240 : : return false;
3241 : : }
3242 : :
3243 : : /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
3244 : : the function (or functions) to call; ARGS are the arguments to the
3245 : : call. Returns the functions to be considered by overload resolution. */
3246 : :
3247 : : cp_expr
3248 : 19840247 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
3249 : : tsubst_flags_t complain)
3250 : : {
3251 : 19840247 : tree identifier = NULL_TREE;
3252 : 19840247 : tree functions = NULL_TREE;
3253 : 19840247 : tree tmpl_args = NULL_TREE;
3254 : 19840247 : bool template_id = false;
3255 : 19840247 : location_t loc = fn_expr.get_location ();
3256 : 19840247 : tree fn = fn_expr.get_value ();
3257 : :
3258 : 19840247 : STRIP_ANY_LOCATION_WRAPPER (fn);
3259 : :
3260 : 19840247 : if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
3261 : : {
3262 : : /* Use a separate flag to handle null args. */
3263 : 4137919 : template_id = true;
3264 : 4137919 : tmpl_args = TREE_OPERAND (fn, 1);
3265 : 4137919 : fn = TREE_OPERAND (fn, 0);
3266 : : }
3267 : :
3268 : : /* Find the name of the overloaded function. */
3269 : 19840247 : if (identifier_p (fn))
3270 : : identifier = fn;
3271 : : else
3272 : : {
3273 : 28634314 : functions = fn;
3274 : 19592485 : identifier = OVL_NAME (functions);
3275 : : }
3276 : :
3277 : : /* A call to a namespace-scope function using an unqualified name.
3278 : :
3279 : : Do Koenig lookup -- unless any of the arguments are
3280 : : type-dependent. */
3281 : 19840247 : if (!any_type_dependent_arguments_p (args)
3282 : 19840247 : && !any_dependent_template_arguments_p (tmpl_args))
3283 : : {
3284 : 18946982 : fn = lookup_arg_dependent (identifier, functions, args);
3285 : 18946982 : if (!fn)
3286 : : {
3287 : : /* The unqualified name could not be resolved. */
3288 : 56700 : if (complain & tf_error)
3289 : 390 : fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
3290 : : else
3291 : : fn = identifier;
3292 : : }
3293 : : }
3294 : :
3295 : 19840247 : if (fn && template_id && fn != error_mark_node)
3296 : 4137906 : fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
3297 : :
3298 : 19840247 : return cp_expr (fn, loc);
3299 : : }
3300 : :
3301 : : /* Generate an expression for `FN (ARGS)'. This may change the
3302 : : contents of ARGS.
3303 : :
3304 : : If DISALLOW_VIRTUAL is true, the call to FN will be not generated
3305 : : as a virtual call, even if FN is virtual. (This flag is set when
3306 : : encountering an expression where the function name is explicitly
3307 : : qualified. For example a call to `X::f' never generates a virtual
3308 : : call.)
3309 : :
3310 : : Returns code for the call. */
3311 : :
3312 : : tree
3313 : 407154685 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
3314 : : bool koenig_p, tsubst_flags_t complain)
3315 : : {
3316 : 407154685 : tree result;
3317 : 407154685 : tree orig_fn;
3318 : 407154685 : vec<tree, va_gc> *orig_args = *args;
3319 : :
3320 : 407154685 : if (fn == error_mark_node)
3321 : : return error_mark_node;
3322 : :
3323 : 407153681 : gcc_assert (!TYPE_P (fn));
3324 : :
3325 : : /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
3326 : : it so that we can tell this is a call to a known function. */
3327 : 407153681 : fn = maybe_undo_parenthesized_ref (fn);
3328 : :
3329 : 407153681 : STRIP_ANY_LOCATION_WRAPPER (fn);
3330 : :
3331 : 407153681 : orig_fn = fn;
3332 : :
3333 : 407153681 : if (concept_check_p (fn))
3334 : : {
3335 : 6 : error_at (EXPR_LOC_OR_LOC (fn, input_location),
3336 : : "cannot call a concept as a function");
3337 : 6 : return error_mark_node;
3338 : : }
3339 : :
3340 : 407153675 : if (processing_template_decl)
3341 : : {
3342 : : /* If FN is a local extern declaration (or set thereof) in a template,
3343 : : look it up again at instantiation time. */
3344 : 225726139 : if (is_overloaded_fn (fn))
3345 : : {
3346 : 138165112 : tree ifn = get_first_fn (fn);
3347 : 138165112 : if (TREE_CODE (ifn) == FUNCTION_DECL
3348 : 138165112 : && dependent_local_decl_p (ifn))
3349 : 38832 : orig_fn = DECL_NAME (ifn);
3350 : : }
3351 : :
3352 : : /* If the call expression is dependent, build a CALL_EXPR node
3353 : : with no type; type_dependent_expression_p recognizes
3354 : : expressions with no type as being dependent. */
3355 : 225726139 : if (type_dependent_expression_p (fn)
3356 : 225726139 : || any_type_dependent_arguments_p (*args))
3357 : : {
3358 : 204528171 : if (koenig_p
3359 : 10170554 : && TREE_CODE (orig_fn) == FUNCTION_DECL
3360 : 207681249 : && !fndecl_built_in_p (orig_fn))
3361 : : /* For an ADL-enabled call where unqualified lookup found a
3362 : : single non-template function, wrap it in an OVERLOAD so that
3363 : : later substitution doesn't overeagerly mark the function as
3364 : : used. */
3365 : 827438 : orig_fn = ovl_make (orig_fn, NULL_TREE);
3366 : 204528171 : result = build_min_nt_call_vec (orig_fn, *args);
3367 : 277712905 : SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
3368 : 204528171 : KOENIG_LOOKUP_P (result) = koenig_p;
3369 : : /* Disable the std::move warnings since this call was dependent
3370 : : (c++/89780, c++/107363). This also suppresses the
3371 : : -Wredundant-move warning. */
3372 : 204528171 : suppress_warning (result, OPT_Wpessimizing_move);
3373 : :
3374 : 204528171 : if (cfun && cp_function_chain && !cp_unevaluated_operand)
3375 : : {
3376 : 178466025 : bool abnormal = true;
3377 : 178671415 : for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
3378 : : {
3379 : 98618259 : tree fndecl = STRIP_TEMPLATE (*iter);
3380 : 98618259 : if (TREE_CODE (fndecl) != FUNCTION_DECL
3381 : 98618181 : || !TREE_THIS_VOLATILE (fndecl))
3382 : : {
3383 : : abnormal = false;
3384 : : break;
3385 : : }
3386 : : }
3387 : : /* FIXME: Stop warning about falling off end of non-void
3388 : : function. But this is wrong. Even if we only see
3389 : : no-return fns at this point, we could select a
3390 : : future-defined return fn during instantiation. Or
3391 : : vice-versa. */
3392 : 178466025 : if (abnormal)
3393 : 80053156 : current_function_returns_abnormally = 1;
3394 : : }
3395 : 204528171 : if (TREE_CODE (fn) == COMPONENT_REF)
3396 : 95228090 : maybe_generic_this_capture (TREE_OPERAND (fn, 0),
3397 : 95228090 : TREE_OPERAND (fn, 1));
3398 : 204528171 : return result;
3399 : : }
3400 : 21197968 : orig_args = make_tree_vector_copy (*args);
3401 : : }
3402 : :
3403 : 202625504 : if (TREE_CODE (fn) == COMPONENT_REF)
3404 : : {
3405 : 42311367 : tree member = TREE_OPERAND (fn, 1);
3406 : 42311367 : if (BASELINK_P (member))
3407 : : {
3408 : 42134619 : tree object = TREE_OPERAND (fn, 0);
3409 : 83827453 : return build_new_method_call (object, member,
3410 : : args, NULL_TREE,
3411 : : (disallow_virtual
3412 : : ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
3413 : : : LOOKUP_NORMAL),
3414 : : /*fn_p=*/NULL,
3415 : 42134619 : complain);
3416 : : }
3417 : : }
3418 : :
3419 : : /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
3420 : 160490885 : if (TREE_CODE (fn) == ADDR_EXPR
3421 : 160490885 : && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
3422 : 9 : fn = TREE_OPERAND (fn, 0);
3423 : :
3424 : 160490885 : if (is_overloaded_fn (fn))
3425 : 149207273 : fn = baselink_for_fns (fn);
3426 : :
3427 : 160490885 : result = NULL_TREE;
3428 : 160490885 : if (BASELINK_P (fn))
3429 : : {
3430 : 14750049 : tree object;
3431 : :
3432 : : /* A call to a member function. From [over.call.func]:
3433 : :
3434 : : If the keyword this is in scope and refers to the class of
3435 : : that member function, or a derived class thereof, then the
3436 : : function call is transformed into a qualified function call
3437 : : using (*this) as the postfix-expression to the left of the
3438 : : . operator.... [Otherwise] a contrived object of type T
3439 : : becomes the implied object argument.
3440 : :
3441 : : In this situation:
3442 : :
3443 : : struct A { void f(); };
3444 : : struct B : public A {};
3445 : : struct C : public A { void g() { B::f(); }};
3446 : :
3447 : : "the class of that member function" refers to `A'. But 11.2
3448 : : [class.access.base] says that we need to convert 'this' to B* as
3449 : : part of the access, so we pass 'B' to maybe_dummy_object. */
3450 : :
3451 : 14750049 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
3452 : : {
3453 : : /* A constructor call always uses a dummy object. (This constructor
3454 : : call which has the form A::A () is actually invalid and we are
3455 : : going to reject it later in build_new_method_call.) */
3456 : 39 : object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
3457 : : }
3458 : : else
3459 : 14750010 : object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
3460 : : NULL);
3461 : :
3462 : 16607133 : result = build_new_method_call (object, fn, args, NULL_TREE,
3463 : : (disallow_virtual
3464 : : ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
3465 : : : LOOKUP_NORMAL),
3466 : : /*fn_p=*/NULL,
3467 : : complain);
3468 : : }
3469 : 145740836 : else if (is_overloaded_fn (fn))
3470 : : {
3471 : : /* If the function is an overloaded builtin, resolve it. */
3472 : 134457224 : if (TREE_CODE (fn) == FUNCTION_DECL
3473 : 134457224 : && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
3474 : 19278338 : || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
3475 : 10213746 : result = resolve_overloaded_builtin (input_location, fn, *args,
3476 : : complain & tf_error);
3477 : :
3478 : 10213746 : if (!result)
3479 : : {
3480 : 134124837 : tree alloc_size_attr = NULL_TREE;
3481 : 134124837 : if (warn_calloc_transposed_args
3482 : 665128 : && TREE_CODE (fn) == FUNCTION_DECL
3483 : 134124837 : && (alloc_size_attr
3484 : 421878 : = lookup_attribute ("alloc_size",
3485 : 421878 : TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
3486 : 3489 : if (TREE_VALUE (alloc_size_attr) == NULL_TREE
3487 : 3489 : || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
3488 : : alloc_size_attr = NULL_TREE;
3489 : 132452142 : if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
3490 : 1672755 : && (complain & tf_warning)
3491 : 1478076 : && !vec_safe_is_empty (*args)
3492 : 135265238 : && !processing_template_decl)
3493 : : {
3494 : : location_t sizeof_arg_loc[6];
3495 : : tree sizeof_arg[6];
3496 : : unsigned int i;
3497 : 8188580 : for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
3498 : : {
3499 : 3070920 : tree t;
3500 : :
3501 : 3070920 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
3502 : 3070920 : sizeof_arg[i] = NULL_TREE;
3503 : 3070920 : if (i >= (*args)->length ())
3504 : 639233 : continue;
3505 : 2431687 : t = (**args)[i];
3506 : 2431687 : if (TREE_CODE (t) != SIZEOF_EXPR)
3507 : 2425112 : continue;
3508 : 6575 : if (SIZEOF_EXPR_TYPE_P (t))
3509 : 2601 : sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
3510 : : else
3511 : 3974 : sizeof_arg[i] = TREE_OPERAND (t, 0);
3512 : 6575 : sizeof_arg_loc[i] = EXPR_LOCATION (t);
3513 : : }
3514 : 1023580 : if (warn_sizeof_pointer_memaccess)
3515 : : {
3516 : 1023520 : auto same_p = same_type_ignoring_top_level_qualifiers_p;
3517 : 1023520 : sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
3518 : : sizeof_arg, same_p);
3519 : : }
3520 : 1023580 : if (alloc_size_attr)
3521 : 60 : warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
3522 : : alloc_size_attr);
3523 : : }
3524 : :
3525 : 134124837 : if ((complain & tf_warning)
3526 : 61068801 : && TREE_CODE (fn) == FUNCTION_DECL
3527 : 27802334 : && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
3528 : 199177 : && vec_safe_length (*args) == 3
3529 : 134324014 : && !any_type_dependent_arguments_p (*args))
3530 : : {
3531 : 199177 : tree arg0 = (*orig_args)[0];
3532 : 199177 : tree arg1 = (*orig_args)[1];
3533 : 199177 : tree arg2 = (*orig_args)[2];
3534 : 199177 : int literal_mask = ((literal_integer_zerop (arg1) << 1)
3535 : 199177 : | (literal_integer_zerop (arg2) << 2));
3536 : 199177 : warn_for_memset (input_location, arg0, arg2, literal_mask);
3537 : : }
3538 : :
3539 : : /* A call to a namespace-scope function. */
3540 : 134124837 : result = build_new_function_call (fn, args, complain);
3541 : : }
3542 : : }
3543 : 11283612 : else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
3544 : : {
3545 : 166231 : if (!vec_safe_is_empty (*args))
3546 : 0 : error ("arguments to destructor are not allowed");
3547 : : /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
3548 : : which case the postfix-expression is a possibly-parenthesized class
3549 : : member access), the function call destroys the object of scalar type
3550 : : denoted by the object expression of the class member access. */
3551 : 166231 : tree ob = TREE_OPERAND (fn, 0);
3552 : 166231 : if (obvalue_p (ob))
3553 : 166213 : result = build_trivial_dtor_call (ob, true);
3554 : : else
3555 : : /* No location to clobber. */
3556 : 18 : result = convert_to_void (ob, ICV_STATEMENT, complain);
3557 : : }
3558 : 11117381 : else if (CLASS_TYPE_P (TREE_TYPE (fn)))
3559 : : /* If the "function" is really an object of class type, it might
3560 : : have an overloaded `operator ()'. */
3561 : 4477766 : result = build_op_call (fn, args, complain);
3562 : :
3563 : 153505365 : if (!result)
3564 : : /* A call where the function is unknown. */
3565 : 6639615 : result = cp_build_function_call_vec (fn, args, complain);
3566 : :
3567 : 160477367 : if (processing_template_decl && result != error_mark_node)
3568 : : {
3569 : 15730428 : if (INDIRECT_REF_P (result))
3570 : 1139697 : result = TREE_OPERAND (result, 0);
3571 : :
3572 : : /* Prune all but the selected function from the original overload
3573 : : set so that we can avoid some duplicate work at instantiation time. */
3574 : 15730428 : if (TREE_CODE (result) == CALL_EXPR
3575 : 15721105 : && really_overloaded_fn (orig_fn))
3576 : : {
3577 : 5939211 : tree sel_fn = CALL_EXPR_FN (result);
3578 : 5939211 : if (TREE_CODE (sel_fn) == COMPONENT_REF)
3579 : : {
3580 : : /* The non-dependent result of build_new_method_call. */
3581 : 246596 : sel_fn = TREE_OPERAND (sel_fn, 1);
3582 : 246596 : gcc_assert (BASELINK_P (sel_fn));
3583 : : }
3584 : 5692615 : else if (TREE_CODE (sel_fn) == ADDR_EXPR)
3585 : : /* Our original callee wasn't wrapped in an ADDR_EXPR,
3586 : : so strip this ADDR_EXPR added by build_over_call. */
3587 : 5692615 : sel_fn = TREE_OPERAND (sel_fn, 0);
3588 : : orig_fn = sel_fn;
3589 : : }
3590 : :
3591 : 15730428 : tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
3592 : 15730428 : SET_EXPR_LOCATION (r, input_location);
3593 : 15730428 : KOENIG_LOOKUP_P (r) = koenig_p;
3594 : 15730428 : TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
3595 : 15730428 : release_tree_vector (orig_args);
3596 : 15730428 : result = convert_from_reference (r);
3597 : : }
3598 : :
3599 : : return result;
3600 : : }
3601 : :
3602 : : /* Finish a call to a postfix increment or decrement or EXPR. (Which
3603 : : is indicated by CODE, which should be POSTINCREMENT_EXPR or
3604 : : POSTDECREMENT_EXPR.) */
3605 : :
3606 : : cp_expr
3607 : 2558579 : finish_increment_expr (cp_expr expr, enum tree_code code)
3608 : : {
3609 : : /* input_location holds the location of the trailing operator token.
3610 : : Build a location of the form:
3611 : : expr++
3612 : : ~~~~^~
3613 : : with the caret at the operator token, ranging from the start
3614 : : of EXPR to the end of the operator token. */
3615 : 2558579 : location_t combined_loc = make_location (input_location,
3616 : : expr.get_start (),
3617 : : get_finish (input_location));
3618 : 2558579 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3619 : 2558579 : NULL_TREE, tf_warning_or_error);
3620 : : /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3621 : 2558579 : result.set_location (combined_loc);
3622 : 2558579 : return result;
3623 : : }
3624 : :
3625 : : /* Finish a use of `this'. Returns an expression for `this'. */
3626 : :
3627 : : tree
3628 : 34967988 : finish_this_expr (void)
3629 : : {
3630 : 34967988 : tree result = NULL_TREE;
3631 : :
3632 : 69935862 : if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
3633 : 34692578 : result = current_class_ptr;
3634 : 550804 : else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
3635 : 275336 : result = (lambda_expr_this_capture
3636 : 275336 : (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
3637 : : else
3638 : 74 : gcc_checking_assert (!current_class_ptr);
3639 : :
3640 : 34967914 : if (result)
3641 : : /* The keyword 'this' is a prvalue expression. */
3642 : 34967911 : return rvalue (result);
3643 : :
3644 : 77 : tree fn = current_nonlambda_function ();
3645 : 77 : if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
3646 : : {
3647 : 4 : auto_diagnostic_group d;
3648 : 4 : error ("%<this%> is unavailable for explicit object member "
3649 : : "functions");
3650 : 4 : tree xobj_parm = DECL_ARGUMENTS (fn);
3651 : 4 : gcc_assert (xobj_parm);
3652 : 4 : tree parm_name = DECL_NAME (xobj_parm);
3653 : :
3654 : 4 : static tree remembered_fn = NULL_TREE;
3655 : : /* Only output this diagnostic once per function. */
3656 : 4 : if (remembered_fn == fn)
3657 : : /* Early escape. */;
3658 : 4 : else if (parm_name)
3659 : 4 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3660 : : "use explicit object parameter %qs instead",
3661 : 2 : IDENTIFIER_POINTER (parm_name));
3662 : : else
3663 : 2 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3664 : : "name the explicit object parameter");
3665 : :
3666 : 4 : remembered_fn = fn;
3667 : 4 : }
3668 : 73 : else if (fn && DECL_STATIC_FUNCTION_P (fn))
3669 : 3 : error ("%<this%> is unavailable for static member functions");
3670 : 70 : else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
3671 : 0 : error ("invalid use of %<this%> in a constructor %<pre%> condition");
3672 : 70 : else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
3673 : 0 : error ("invalid use of %<this%> in a destructor %<post%> condition");
3674 : 70 : else if (fn)
3675 : 22 : error ("invalid use of %<this%> in non-member function");
3676 : : else
3677 : 48 : error ("invalid use of %<this%> at top level");
3678 : 77 : return error_mark_node;
3679 : : }
3680 : :
3681 : : /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3682 : : expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3683 : : the TYPE for the type given. If SCOPE is non-NULL, the expression
3684 : : was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3685 : :
3686 : : tree
3687 : 166282 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
3688 : : location_t loc, tsubst_flags_t complain)
3689 : : {
3690 : 166282 : if (object == error_mark_node || destructor == error_mark_node)
3691 : : return error_mark_node;
3692 : :
3693 : 166273 : gcc_assert (TYPE_P (destructor));
3694 : :
3695 : 166273 : if (!processing_template_decl)
3696 : : {
3697 : 166252 : if (scope == error_mark_node)
3698 : : {
3699 : 0 : if (complain & tf_error)
3700 : 0 : error_at (loc, "invalid qualifying scope in pseudo-destructor name");
3701 : 0 : return error_mark_node;
3702 : : }
3703 : 166252 : if (is_auto (destructor))
3704 : 3 : destructor = TREE_TYPE (object);
3705 : 166252 : if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
3706 : : {
3707 : 3 : if (complain & tf_error)
3708 : 3 : error_at (loc,
3709 : : "qualified type %qT does not match destructor name ~%qT",
3710 : : scope, destructor);
3711 : 3 : return error_mark_node;
3712 : : }
3713 : :
3714 : :
3715 : : /* [expr.pseudo] says both:
3716 : :
3717 : : The type designated by the pseudo-destructor-name shall be
3718 : : the same as the object type.
3719 : :
3720 : : and:
3721 : :
3722 : : The cv-unqualified versions of the object type and of the
3723 : : type designated by the pseudo-destructor-name shall be the
3724 : : same type.
3725 : :
3726 : : We implement the more generous second sentence, since that is
3727 : : what most other compilers do. */
3728 : 166249 : if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
3729 : : destructor))
3730 : : {
3731 : 12 : if (complain & tf_error)
3732 : 9 : error_at (loc, "%qE is not of type %qT", object, destructor);
3733 : 12 : return error_mark_node;
3734 : : }
3735 : : }
3736 : :
3737 : 166258 : tree type = (type_dependent_expression_p (object)
3738 : 166258 : ? NULL_TREE : void_type_node);
3739 : :
3740 : 166258 : return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
3741 : 166258 : scope, destructor);
3742 : : }
3743 : :
3744 : : /* Finish an expression of the form CODE EXPR. */
3745 : :
3746 : : cp_expr
3747 : 36726915 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
3748 : : tsubst_flags_t complain)
3749 : : {
3750 : : /* Build a location of the form:
3751 : : ++expr
3752 : : ^~~~~~
3753 : : with the caret at the operator token, ranging from the start
3754 : : of the operator token to the end of EXPR. */
3755 : 36726915 : location_t combined_loc = make_location (op_loc,
3756 : : op_loc, expr.get_finish ());
3757 : 36726915 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3758 : 36726915 : NULL_TREE, complain);
3759 : : /* TODO: build_x_unary_op doesn't always honor the location. */
3760 : 36726915 : result.set_location (combined_loc);
3761 : :
3762 : 36726915 : if (result == error_mark_node)
3763 : : return result;
3764 : :
3765 : 36726452 : if (!(complain & tf_warning))
3766 : : return result;
3767 : :
3768 : : /* These will never fold into a constant, so no need to check for
3769 : : overflow for them. */
3770 : 36726452 : if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
3771 : : return result;
3772 : :
3773 : 19619458 : tree result_ovl = result;
3774 : 19619458 : tree expr_ovl = expr;
3775 : :
3776 : 19619458 : if (!processing_template_decl)
3777 : 1753779 : expr_ovl = cp_fully_fold (expr_ovl);
3778 : :
3779 : 19619458 : if (!CONSTANT_CLASS_P (expr_ovl)
3780 : 19619458 : || TREE_OVERFLOW_P (expr_ovl))
3781 : : return result;
3782 : :
3783 : 242083 : if (!processing_template_decl)
3784 : 233027 : result_ovl = cp_fully_fold (result_ovl);
3785 : :
3786 : 242083 : if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
3787 : 9 : overflow_warning (combined_loc, result_ovl);
3788 : :
3789 : : return result;
3790 : : }
3791 : :
3792 : : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3793 : : elements. */
3794 : :
3795 : : static bool
3796 : 12 : maybe_zero_constructor_nelts (tree expr)
3797 : : {
3798 : 12 : if (CONSTRUCTOR_NELTS (expr) == 0)
3799 : : return true;
3800 : 12 : if (!processing_template_decl)
3801 : : return false;
3802 : 30 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
3803 : 21 : if (!PACK_EXPANSION_P (elt.value))
3804 : : return false;
3805 : : return true;
3806 : : }
3807 : :
3808 : : /* Finish a compound-literal expression or C++11 functional cast with aggregate
3809 : : initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3810 : : is being cast. */
3811 : :
3812 : : tree
3813 : 10105884 : finish_compound_literal (tree type, tree compound_literal,
3814 : : tsubst_flags_t complain,
3815 : : fcl_t fcl_context)
3816 : : {
3817 : 10105884 : if (type == error_mark_node)
3818 : : return error_mark_node;
3819 : :
3820 : 10105853 : if (TYPE_REF_P (type))
3821 : : {
3822 : 12 : compound_literal
3823 : 12 : = finish_compound_literal (TREE_TYPE (type), compound_literal,
3824 : : complain, fcl_context);
3825 : : /* The prvalue is then used to direct-initialize the reference. */
3826 : 12 : tree r = (perform_implicit_conversion_flags
3827 : 12 : (type, compound_literal, complain, LOOKUP_NORMAL));
3828 : 12 : return convert_from_reference (r);
3829 : : }
3830 : :
3831 : 10105841 : if (!TYPE_OBJ_P (type))
3832 : : {
3833 : : /* DR2351 */
3834 : 60 : if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
3835 : : {
3836 : 12 : if (!processing_template_decl)
3837 : 9 : return void_node;
3838 : 3 : TREE_TYPE (compound_literal) = type;
3839 : 3 : TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
3840 : 3 : CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
3841 : 3 : return compound_literal;
3842 : : }
3843 : 21 : else if (VOID_TYPE_P (type)
3844 : 15 : && processing_template_decl
3845 : 33 : && maybe_zero_constructor_nelts (compound_literal))
3846 : : /* If there are only packs in compound_literal, it could
3847 : : be void{} after pack expansion. */;
3848 : : else
3849 : : {
3850 : 12 : if (complain & tf_error)
3851 : 9 : error ("compound literal of non-object type %qT", type);
3852 : 12 : return error_mark_node;
3853 : : }
3854 : : }
3855 : :
3856 : 10105817 : if (template_placeholder_p (type))
3857 : : {
3858 : 172136 : type = do_auto_deduction (type, compound_literal, type, complain,
3859 : : adc_variable_type);
3860 : 172136 : if (type == error_mark_node)
3861 : : return error_mark_node;
3862 : : }
3863 : : /* C++23 auto{x}. */
3864 : 9933681 : else if (is_auto (type)
3865 : 109 : && !AUTO_IS_DECLTYPE (type)
3866 : 9933788 : && CONSTRUCTOR_NELTS (compound_literal) == 1)
3867 : : {
3868 : 101 : if (is_constrained_auto (type))
3869 : : {
3870 : 2 : if (complain & tf_error)
3871 : 2 : error ("%<auto{x}%> cannot be constrained");
3872 : 2 : return error_mark_node;
3873 : : }
3874 : 99 : else if (cxx_dialect < cxx23)
3875 : 1 : pedwarn (input_location, OPT_Wc__23_extensions,
3876 : : "%<auto{x}%> only available with "
3877 : : "%<-std=c++23%> or %<-std=gnu++23%>");
3878 : 99 : type = do_auto_deduction (type, compound_literal, type, complain,
3879 : : adc_variable_type);
3880 : 99 : if (type == error_mark_node)
3881 : : return error_mark_node;
3882 : : }
3883 : :
3884 : : /* Used to hold a copy of the compound literal in a template. */
3885 : 10105702 : tree orig_cl = NULL_TREE;
3886 : :
3887 : 10105702 : if (processing_template_decl)
3888 : : {
3889 : 4856568 : const bool dependent_p
3890 : 4856568 : = (instantiation_dependent_expression_p (compound_literal)
3891 : 4856568 : || dependent_type_p (type));
3892 : 1595927 : if (dependent_p)
3893 : : /* We're about to return, no need to copy. */
3894 : : orig_cl = compound_literal;
3895 : : else
3896 : : /* We're going to need a copy. */
3897 : 1595927 : orig_cl = unshare_constructor (compound_literal);
3898 : 4856568 : TREE_TYPE (orig_cl) = type;
3899 : : /* Mark the expression as a compound literal. */
3900 : 4856568 : TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
3901 : : /* And as instantiation-dependent. */
3902 : 4856568 : CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
3903 : 4856568 : if (fcl_context == fcl_c99)
3904 : 130 : CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
3905 : : /* If the compound literal is dependent, we're done for now. */
3906 : 4856568 : if (dependent_p)
3907 : : return orig_cl;
3908 : : /* Otherwise, do go on to e.g. check narrowing. */
3909 : : }
3910 : :
3911 : 6845061 : type = complete_type (type);
3912 : :
3913 : 6845061 : if (TYPE_NON_AGGREGATE_CLASS (type))
3914 : : {
3915 : : /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3916 : : everywhere that deals with function arguments would be a pain, so
3917 : : just wrap it in a TREE_LIST. The parser set a flag so we know
3918 : : that it came from T{} rather than T({}). */
3919 : 1085653 : CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
3920 : 1085653 : compound_literal = build_tree_list (NULL_TREE, compound_literal);
3921 : 1085653 : return build_functional_cast (input_location, type,
3922 : 1085653 : compound_literal, complain);
3923 : : }
3924 : :
3925 : 5759408 : if (TREE_CODE (type) == ARRAY_TYPE
3926 : 5759408 : && check_array_initializer (NULL_TREE, type, compound_literal))
3927 : 9 : return error_mark_node;
3928 : 5759399 : compound_literal = reshape_init (type, compound_literal, complain);
3929 : 5444416 : if (SCALAR_TYPE_P (type)
3930 : 844924 : && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
3931 : 5967262 : && !check_narrowing (type, compound_literal, complain))
3932 : 102 : return error_mark_node;
3933 : 5759297 : if (TREE_CODE (type) == ARRAY_TYPE
3934 : 5759297 : && TYPE_DOMAIN (type) == NULL_TREE)
3935 : : {
3936 : 1192 : cp_complete_array_type_or_error (&type, compound_literal,
3937 : : false, complain);
3938 : 1192 : if (type == error_mark_node)
3939 : : return error_mark_node;
3940 : : }
3941 : 5759294 : compound_literal = digest_init_flags (type, compound_literal,
3942 : : LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
3943 : : complain);
3944 : 5759294 : if (compound_literal == error_mark_node)
3945 : : return error_mark_node;
3946 : :
3947 : : /* If we're in a template, return the original compound literal. */
3948 : 5758710 : if (orig_cl)
3949 : : return orig_cl;
3950 : :
3951 : 4252420 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3952 : : {
3953 : 3460125 : TREE_HAS_CONSTRUCTOR (compound_literal) = true;
3954 : 3460125 : if (fcl_context == fcl_c99)
3955 : 37976 : CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
3956 : : }
3957 : :
3958 : : /* Put static/constant array temporaries in static variables. */
3959 : : /* FIXME all C99 compound literals should be variables rather than C++
3960 : : temporaries, unless they are used as an aggregate initializer. */
3961 : 5783653 : if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
3962 : 2726286 : && fcl_context == fcl_c99
3963 : 80 : && TREE_CODE (type) == ARRAY_TYPE
3964 : 28 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
3965 : 4252448 : && initializer_constant_valid_p (compound_literal, type))
3966 : : {
3967 : 28 : tree decl = create_temporary_var (type);
3968 : 28 : DECL_CONTEXT (decl) = NULL_TREE;
3969 : 28 : DECL_INITIAL (decl) = compound_literal;
3970 : 28 : TREE_STATIC (decl) = 1;
3971 : 28 : if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
3972 : : {
3973 : : /* 5.19 says that a constant expression can include an
3974 : : lvalue-rvalue conversion applied to "a glvalue of literal type
3975 : : that refers to a non-volatile temporary object initialized
3976 : : with a constant expression". Rather than try to communicate
3977 : : that this VAR_DECL is a temporary, just mark it constexpr. */
3978 : 24 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
3979 : 24 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
3980 : 24 : TREE_CONSTANT (decl) = true;
3981 : : }
3982 : 28 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
3983 : 28 : decl = pushdecl_top_level (decl);
3984 : 28 : DECL_NAME (decl) = make_anon_name ();
3985 : 28 : SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
3986 : : /* Make sure the destructor is callable. */
3987 : 28 : tree clean = cxx_maybe_build_cleanup (decl, complain);
3988 : 28 : if (clean == error_mark_node)
3989 : : return error_mark_node;
3990 : 28 : return decl;
3991 : : }
3992 : :
3993 : : /* Represent other compound literals with TARGET_EXPR so we produce
3994 : : a prvalue, and can elide copies. */
3995 : 4252392 : if (!VECTOR_TYPE_P (type)
3996 : 4215475 : && (TREE_CODE (compound_literal) == CONSTRUCTOR
3997 : 792289 : || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
3998 : : {
3999 : : /* The CONSTRUCTOR is now an initializer, not a compound literal. */
4000 : 3423186 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
4001 : 3423186 : TREE_HAS_CONSTRUCTOR (compound_literal) = false;
4002 : 3423186 : compound_literal = get_target_expr (compound_literal, complain);
4003 : : }
4004 : : else
4005 : : /* For e.g. int{42} just make sure it's a prvalue. */
4006 : 829206 : compound_literal = rvalue (compound_literal);
4007 : :
4008 : : return compound_literal;
4009 : : }
4010 : :
4011 : : /* Return the declaration for the function-name variable indicated by
4012 : : ID. */
4013 : :
4014 : : tree
4015 : 221491 : finish_fname (tree id)
4016 : : {
4017 : 221491 : tree decl = fname_decl (input_location, C_RID_CODE (id), id);
4018 : : /* [expr.prim.lambda.closure]/16 "Unless the compound-statement is that
4019 : : of a consteval-block-declaration, a variable __func__ is implicitly
4020 : : defined...". We could be in a consteval block in a function, though,
4021 : : and then we shouldn't warn. */
4022 : 221491 : if (current_function_decl
4023 : 221491 : && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
4024 : 4 : pedwarn (input_location, 0, "%qD is not defined outside of function scope",
4025 : : decl);
4026 : 221491 : if (processing_template_decl && current_function_decl
4027 : 152062 : && decl != error_mark_node)
4028 : 152062 : decl = DECL_NAME (decl);
4029 : 221491 : return decl;
4030 : : }
4031 : :
4032 : : /* Finish a translation unit. */
4033 : :
4034 : : void
4035 : 96095 : finish_translation_unit (void)
4036 : : {
4037 : : /* In case there were missing closebraces,
4038 : : get us back to the global binding level. */
4039 : 96095 : pop_everything ();
4040 : 192190 : while (current_namespace != global_namespace)
4041 : 0 : pop_namespace ();
4042 : :
4043 : : /* Do file scope __FUNCTION__ et al. */
4044 : 96095 : finish_fname_decls ();
4045 : :
4046 : 96095 : if (vec_safe_length (scope_chain->omp_declare_target_attribute))
4047 : : {
4048 : 12 : cp_omp_declare_target_attr
4049 : 12 : a = scope_chain->omp_declare_target_attribute->pop ();
4050 : 12 : if (!errorcount)
4051 : 9 : error ("%qs without corresponding %qs",
4052 : : a.device_type >= 0 ? "#pragma omp begin declare target"
4053 : : : "#pragma omp declare target",
4054 : : "#pragma omp end declare target");
4055 : 24 : vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
4056 : : }
4057 : 96095 : if (vec_safe_length (scope_chain->omp_declare_variant_attribute))
4058 : : {
4059 : 0 : if (!errorcount)
4060 : 0 : error ("%<omp begin declare variant%> without corresponding "
4061 : : "%<omp end declare variant%>");
4062 : 0 : vec_safe_truncate (scope_chain->omp_declare_variant_attribute, 0);
4063 : : }
4064 : 96095 : if (vec_safe_length (scope_chain->omp_begin_assumes))
4065 : : {
4066 : 3 : if (!errorcount)
4067 : 3 : error ("%qs without corresponding %qs",
4068 : : "#pragma omp begin assumes", "#pragma omp end assumes");
4069 : 3 : vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
4070 : : }
4071 : 96095 : }
4072 : :
4073 : : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
4074 : : Returns the parameter. */
4075 : :
4076 : : tree
4077 : 153682203 : finish_template_type_parm (tree aggr, tree identifier)
4078 : : {
4079 : 153682203 : if (aggr != class_type_node)
4080 : : {
4081 : 0 : permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
4082 : 0 : aggr = class_type_node;
4083 : : }
4084 : :
4085 : 153682203 : return build_tree_list (aggr, identifier);
4086 : : }
4087 : :
4088 : : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
4089 : : Returns the parameter. */
4090 : :
4091 : : tree
4092 : 377638 : finish_template_template_parm (tree aggr, tree identifier)
4093 : : {
4094 : 377638 : tree decl = build_decl (input_location,
4095 : : TYPE_DECL, identifier, NULL_TREE);
4096 : :
4097 : 377638 : tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
4098 : 377638 : DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
4099 : 377638 : DECL_TEMPLATE_RESULT (tmpl) = decl;
4100 : 377638 : DECL_ARTIFICIAL (decl) = 1;
4101 : :
4102 : : /* Associate the constraints with the underlying declaration,
4103 : : not the template. */
4104 : 377638 : tree constr = current_template_constraints ();
4105 : 377638 : set_constraints (decl, constr);
4106 : :
4107 : 377638 : end_template_decl ();
4108 : :
4109 : 377638 : gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
4110 : :
4111 : 377638 : check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
4112 : : /*is_primary=*/true, /*is_partial=*/false,
4113 : : /*is_friend=*/0);
4114 : :
4115 : 377638 : return finish_template_type_parm (aggr, tmpl);
4116 : : }
4117 : :
4118 : : /* ARGUMENT is the default-argument value for a template template
4119 : : parameter. If ARGUMENT is invalid, issue error messages and return
4120 : : the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
4121 : :
4122 : : tree
4123 : 945 : check_template_template_default_arg (tree argument)
4124 : : {
4125 : 945 : if (TREE_CODE (argument) != TEMPLATE_DECL
4126 : : && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
4127 : : && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
4128 : : {
4129 : : if (TREE_CODE (argument) == TYPE_DECL)
4130 : : {
4131 : 18 : if (tree t = maybe_get_template_decl_from_type_decl (argument))
4132 : 18 : if (TREE_CODE (t) == TEMPLATE_DECL)
4133 : : return t;
4134 : 15 : error ("invalid use of type %qT as a default value for a template "
4135 : 15 : "template-parameter", TREE_TYPE (argument));
4136 : : }
4137 : : else
4138 : 0 : error ("invalid default argument for a template template parameter");
4139 : 15 : return error_mark_node;
4140 : : }
4141 : :
4142 : : return argument;
4143 : : }
4144 : :
4145 : : /* Begin a class definition, as indicated by T. */
4146 : :
4147 : : tree
4148 : 29792578 : begin_class_definition (tree t)
4149 : : {
4150 : 29792578 : if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
4151 : 33 : return error_mark_node;
4152 : :
4153 : 29792664 : if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
4154 : : {
4155 : 9 : error ("definition of %q#T inside template parameter list", t);
4156 : 9 : return error_mark_node;
4157 : : }
4158 : :
4159 : : /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
4160 : : are passed the same as decimal scalar types. */
4161 : 29792536 : if (TREE_CODE (t) == RECORD_TYPE
4162 : 29293542 : && !processing_template_decl)
4163 : : {
4164 : 10676662 : tree ns = TYPE_CONTEXT (t);
4165 : 10676660 : if (ns && TREE_CODE (ns) == NAMESPACE_DECL
4166 : 8554869 : && DECL_CONTEXT (ns) == std_node
4167 : 2076191 : && DECL_NAME (ns)
4168 : 12752833 : && id_equal (DECL_NAME (ns), "decimal"))
4169 : : {
4170 : 150 : const char *n = TYPE_NAME_STRING (t);
4171 : 150 : if ((strcmp (n, "decimal32") == 0)
4172 : 101 : || (strcmp (n, "decimal64") == 0)
4173 : 46 : || (strcmp (n, "decimal128") == 0))
4174 : 147 : TYPE_TRANSPARENT_AGGR (t) = 1;
4175 : : }
4176 : : }
4177 : :
4178 : : /* A non-implicit typename comes from code like:
4179 : :
4180 : : template <typename T> struct A {
4181 : : template <typename U> struct A<T>::B ...
4182 : :
4183 : : This is erroneous. */
4184 : 19115874 : else if (TREE_CODE (t) == TYPENAME_TYPE)
4185 : : {
4186 : 0 : error ("invalid definition of qualified type %qT", t);
4187 : 0 : t = error_mark_node;
4188 : : }
4189 : :
4190 : 29792536 : if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
4191 : : {
4192 : 0 : t = make_class_type (RECORD_TYPE);
4193 : 0 : pushtag (make_anon_name (), t);
4194 : : }
4195 : :
4196 : 29792536 : if (TYPE_BEING_DEFINED (t))
4197 : : {
4198 : 0 : t = make_class_type (TREE_CODE (t));
4199 : 0 : pushtag (TYPE_IDENTIFIER (t), t);
4200 : : }
4201 : :
4202 : 29792536 : if (modules_p ())
4203 : : {
4204 : 109077 : if (!module_may_redeclare (TYPE_NAME (t)))
4205 : 0 : return error_mark_node;
4206 : 109077 : set_instantiating_module (TYPE_NAME (t));
4207 : 109077 : set_defining_module (TYPE_NAME (t));
4208 : : }
4209 : :
4210 : 29792536 : maybe_process_partial_specialization (t);
4211 : 29792536 : pushclass (t);
4212 : 29792536 : TYPE_BEING_DEFINED (t) = 1;
4213 : 29792536 : class_binding_level->defining_class_p = 1;
4214 : :
4215 : 29792536 : 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 : 62079549 : if (! TYPE_UNNAMED_P (t))
4229 : : {
4230 : 29073479 : struct c_fileinfo *finfo = \
4231 : 29073479 : get_fileinfo (LOCATION_FILE (input_location));
4232 : 29073479 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
4233 : 29073479 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X
4234 : : (t, finfo->interface_unknown);
4235 : : }
4236 : 29792536 : reset_specialization ();
4237 : :
4238 : : /* Make a declaration for this class in its own scope. */
4239 : 29792536 : build_self_reference ();
4240 : :
4241 : 29792536 : return t;
4242 : : }
4243 : :
4244 : : /* Finish the member declaration given by DECL. */
4245 : :
4246 : : void
4247 : 419578014 : finish_member_declaration (tree decl)
4248 : : {
4249 : 419578014 : if (decl == error_mark_node || decl == NULL_TREE)
4250 : : return;
4251 : :
4252 : 419577017 : 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 : 419577017 : gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
4259 : :
4260 : : /* Don't add decls after definition. */
4261 : 419577038 : 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 : 419577017 : TREE_PRIVATE (decl)
4268 : 419577017 : = (current_access_specifier == access_private_node);
4269 : 419577017 : TREE_PROTECTED (decl)
4270 : 419577017 : = (current_access_specifier == access_protected_node);
4271 : 419577017 : if (TREE_CODE (decl) == TEMPLATE_DECL)
4272 : : {
4273 : 46595590 : TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
4274 : 46595590 : 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 : 419577017 : if (TREE_CODE (decl) != CONST_DECL)
4280 : 417305827 : DECL_CONTEXT (decl) = current_class_type;
4281 : :
4282 : : /* Remember the single FIELD_DECL an anonymous aggregate type is used for. */
4283 : 419577017 : if (TREE_CODE (decl) == FIELD_DECL
4284 : 419577017 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
4285 : : {
4286 : 269845 : gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
4287 : 269845 : ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))) = decl;
4288 : : }
4289 : :
4290 : 419577017 : 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 : 3108181 : DECL_IGNORED_P (decl) = 1;
4294 : :
4295 : : /* Check for bare parameter packs in the non-static data member
4296 : : declaration. */
4297 : 419577017 : if (TREE_CODE (decl) == FIELD_DECL)
4298 : : {
4299 : 31506156 : if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
4300 : 9 : TREE_TYPE (decl) = error_mark_node;
4301 : 31506156 : 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 : 419577017 : if (DECL_LANG_SPECIFIC (decl))
4310 : 382589229 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
4311 : :
4312 : 419577017 : bool add = false;
4313 : :
4314 : : /* Functions and non-functions are added differently. */
4315 : 419577017 : if (DECL_DECLARES_FUNCTION_P (decl))
4316 : 213466451 : 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 : 206110566 : else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
4320 : 201558370 : || maybe_push_used_methods (decl)
4321 : 405904893 : || pushdecl_class_level (decl))
4322 : : add = true;
4323 : :
4324 : 213466451 : 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 : 419568555 : if (TREE_CODE (decl) == TYPE_DECL)
4337 : 147538886 : TYPE_FIELDS (current_class_type)
4338 : 295077772 : = chainon (TYPE_FIELDS (current_class_type), decl);
4339 : : else
4340 : : {
4341 : 272029669 : DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
4342 : 272029669 : TYPE_FIELDS (current_class_type) = decl;
4343 : : }
4344 : :
4345 : 419568555 : 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 : 87921616 : finish_template_decl (tree parms)
4355 : : {
4356 : 87921616 : if (parms)
4357 : 87921610 : end_template_decl ();
4358 : : else
4359 : 6 : end_specialization ();
4360 : 87921616 : }
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 : 17357769 : 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 : 17357769 : tree parms = current_template_parms;
4400 : 17357769 : int depth = template_class_depth (type);
4401 : 38629013 : for (int n = current_template_depth; n > depth && parms; --n)
4402 : 3913475 : parms = TREE_CHAIN (parms);
4403 : 17357769 : if (!parms)
4404 : : return type;
4405 : 17357759 : tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
4406 : 17357759 : tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
4407 : :
4408 : : // Search for a specialization whose type and constraints match.
4409 : 17357759 : tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
4410 : 17357759 : tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
4411 : 33813752 : while (specs)
4412 : : {
4413 : 16863908 : 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 : 16863908 : if (same_type_p (type, TREE_TYPE (specs))
4418 : 16863908 : && equivalent_constraints (cur_constr, spec_constr))
4419 : 407915 : return TREE_TYPE (specs);
4420 : 16455993 : 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 : 179396670 : finish_template_type (tree name, tree args, int entering_scope)
4435 : : {
4436 : 179396670 : tree type;
4437 : :
4438 : 179396670 : type = lookup_template_class (name, args,
4439 : : NULL_TREE, NULL_TREE,
4440 : : tf_warning_or_error | tf_user);
4441 : 179396667 : if (entering_scope)
4442 : 18365850 : 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 : 179396667 : if (flag_concepts
4447 : 176705748 : && entering_scope
4448 : 18004060 : && CLASS_TYPE_P (type)
4449 : 17846338 : && CLASSTYPE_TEMPLATE_INFO (type)
4450 : 17846329 : && dependent_type_p (type)
4451 : 196754436 : && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
4452 : 17357769 : type = fixup_template_type (type);
4453 : :
4454 : 179396667 : if (type == error_mark_node)
4455 : : return type;
4456 : 179394415 : else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
4457 : 142227603 : return TYPE_STUB_DECL (type);
4458 : : else
4459 : 37166812 : 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 : 10958451 : finish_base_specifier (tree base, tree access, bool virtual_p,
4473 : : tree annotations)
4474 : : {
4475 : 10958451 : tree result;
4476 : :
4477 : 10958451 : if (base == error_mark_node)
4478 : : {
4479 : 0 : error ("invalid base-class specification");
4480 : 0 : result = NULL_TREE;
4481 : : }
4482 : 10958451 : 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 : 10958448 : 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 : 10958448 : if (annotations)
4496 : 9 : access = build_tree_list (access, nreverse (annotations));
4497 : 10958448 : result = build_tree_list (access, base);
4498 : 10958448 : if (virtual_p)
4499 : 25348 : TREE_TYPE (result) = integer_type_node;
4500 : : }
4501 : :
4502 : 10958451 : 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 : 233515720 : baselink_for_fns (tree fns)
4512 : : {
4513 : 233515720 : tree scope;
4514 : 233515720 : tree cl;
4515 : :
4516 : 233515720 : if (BASELINK_P (fns)
4517 : 233515720 : || error_operand_p (fns))
4518 : : return fns;
4519 : :
4520 : 218880623 : scope = ovl_scope (fns);
4521 : 218880623 : if (!CLASS_TYPE_P (scope))
4522 : : return fns;
4523 : :
4524 : 8203582 : cl = currently_open_derived_class (scope);
4525 : 8203582 : if (!cl)
4526 : 5954213 : cl = scope;
4527 : 8203582 : tree access_path = TYPE_BINFO (cl);
4528 : 8203582 : tree conv_path = (cl == scope ? access_path
4529 : 669991 : : lookup_base (cl, scope, ba_any, NULL, tf_none));
4530 : 8203582 : 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 : 2228391521 : parsing_lambda_declarator ()
4537 : : {
4538 : 2228391521 : cp_binding_level *b = current_binding_level;
4539 : 2230265071 : while (b->kind == sk_template_parms || b->kind == sk_function_parms)
4540 : 1873550 : b = b->level_chain;
4541 : 2228391521 : 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 : 2940831155 : outer_var_p (tree decl)
4549 : : {
4550 : : /* These should have been stripped or otherwise handled by the caller. */
4551 : 2940831155 : gcc_checking_assert (!REFERENCE_REF_P (decl));
4552 : :
4553 : 1865680352 : return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
4554 : 2735304717 : && DECL_FUNCTION_SCOPE_P (decl)
4555 : : /* Don't get confused by temporaries. */
4556 : 2262037119 : && DECL_NAME (decl)
4557 : 5178660348 : && (DECL_CONTEXT (decl) != current_function_decl
4558 : 2226575345 : || 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 : 2226574402 : || parsing_lambda_declarator ()));
4567 : : }
4568 : :
4569 : : /* As above, but also checks that DECL is automatic. */
4570 : :
4571 : : bool
4572 : 2940831155 : outer_automatic_var_p (tree decl)
4573 : : {
4574 : 2940831155 : return (outer_var_p (decl)
4575 : 2940831155 : && !TREE_STATIC (decl));
4576 : : }
4577 : :
4578 : : /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
4579 : : rewrite it for lambda capture.
4580 : :
4581 : : If ODR_USE is true, we're being called from mark_use, and we complain about
4582 : : use of constant variables. If ODR_USE is false, we're being called for the
4583 : : id-expression, and we do lambda capture. */
4584 : :
4585 : : tree
4586 : 5318018 : process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
4587 : : {
4588 : 5318018 : if (cp_unevaluated_operand)
4589 : : {
4590 : 3500733 : tree type = TREE_TYPE (decl);
4591 : 3500733 : if (!dependent_type_p (type)
4592 : 3500733 : && variably_modified_type_p (type, NULL_TREE))
4593 : : /* VLAs are used even in unevaluated context. */;
4594 : : else
4595 : : /* It's not a use (3.2) if we're in an unevaluated context. */
4596 : 3500727 : return decl;
4597 : : }
4598 : 1817291 : if (decl == error_mark_node)
4599 : : return decl;
4600 : :
4601 : 1817291 : tree context = DECL_CONTEXT (decl);
4602 : 1817291 : tree containing_function = current_function_decl;
4603 : 1817291 : tree lambda_stack = NULL_TREE;
4604 : 1817291 : tree lambda_expr = NULL_TREE;
4605 : 1817291 : tree initializer = convert_from_reference (decl);
4606 : 1817291 : tree var = strip_normal_capture_proxy (decl);
4607 : :
4608 : : /* Mark it as used now even if the use is ill-formed. */
4609 : 1817291 : if (!mark_used (decl, complain))
4610 : 3 : return error_mark_node;
4611 : :
4612 : 1817288 : if (parsing_nsdmi () || parsing_lambda_declarator ())
4613 : : containing_function = NULL_TREE;
4614 : :
4615 : 3633879 : if (containing_function && LAMBDA_FUNCTION_P (containing_function))
4616 : : {
4617 : : /* Check whether we've already built a proxy. */
4618 : 1816852 : tree d = retrieve_local_specialization (var);
4619 : :
4620 : 1816852 : if (d && d != decl && is_capture_proxy (d))
4621 : : {
4622 : 948844 : if (DECL_CONTEXT (d) == containing_function)
4623 : : /* We already have an inner proxy. */
4624 : : return d;
4625 : : else
4626 : : /* We need to capture an outer proxy. */
4627 : 2223 : return process_outer_var_ref (d, complain, odr_use);
4628 : : }
4629 : : }
4630 : :
4631 : : /* If we are in a lambda function, we can move out until we hit
4632 : : 1. the context,
4633 : : 2. a non-lambda function, or
4634 : : 3. a non-default capturing lambda function. */
4635 : 1739447 : while (context != containing_function
4636 : : /* containing_function can be null with invalid generic lambdas. */
4637 : 1739447 : && containing_function
4638 : 2610806 : && LAMBDA_FUNCTION_P (containing_function))
4639 : : {
4640 : 871359 : tree closure = DECL_CONTEXT (containing_function);
4641 : 871359 : lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
4642 : :
4643 : 871359 : if (TYPE_CLASS_SCOPE_P (closure))
4644 : : /* A lambda in an NSDMI (c++/64496). */
4645 : : break;
4646 : :
4647 : 871356 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4648 : : break;
4649 : :
4650 : 871003 : lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
4651 : :
4652 : 871003 : containing_function = decl_function_context (containing_function);
4653 : : }
4654 : :
4655 : : /* In a lambda within a template, wait until instantiation time to implicitly
4656 : : capture a parameter pack. We want to wait because we don't know if we're
4657 : : capturing the whole pack or a single element, and it's OK to wait because
4658 : : find_parameter_packs_r walks into the lambda body. */
4659 : 868444 : if (context == containing_function
4660 : 868444 : && DECL_PACK_P (decl))
4661 : : return decl;
4662 : :
4663 : 829220 : if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
4664 : : {
4665 : 6 : if (complain & tf_error)
4666 : 6 : error ("cannot capture member %qD of anonymous union", decl);
4667 : 6 : return error_mark_node;
4668 : : }
4669 : : /* Do lambda capture when processing the id-expression, not when
4670 : : odr-using a variable. */
4671 : 829214 : if (!odr_use && context == containing_function)
4672 : 1656844 : decl = add_default_capture (lambda_stack,
4673 : 828422 : /*id=*/DECL_NAME (decl), initializer);
4674 : : /* Only an odr-use of an outer automatic variable causes an
4675 : : error, and a constant variable can decay to a prvalue
4676 : : constant without odr-use. So don't complain yet. */
4677 : 792 : else if (!odr_use && decl_constant_var_p (var))
4678 : : return var;
4679 : 308 : else if (lambda_expr)
4680 : : {
4681 : 45 : if (complain & tf_error)
4682 : : {
4683 : 43 : auto_diagnostic_group d;
4684 : 43 : error ("%qD is not captured", decl);
4685 : 43 : tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
4686 : 43 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4687 : 40 : inform (location_of (closure),
4688 : : "the lambda has no capture-default");
4689 : 3 : else if (TYPE_CLASS_SCOPE_P (closure))
4690 : 3 : inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
4691 : : "capture variables from the enclosing context",
4692 : 3 : TYPE_CONTEXT (closure));
4693 : 43 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4694 : 43 : }
4695 : 45 : return error_mark_node;
4696 : : }
4697 : 263 : else if (processing_contract_condition && (TREE_CODE (decl) == PARM_DECL))
4698 : : /* Use of a parameter in a contract condition is fine. */
4699 : : return decl;
4700 : : else
4701 : : {
4702 : 46 : if (complain & tf_error)
4703 : : {
4704 : 39 : auto_diagnostic_group d;
4705 : 57 : error (VAR_P (decl)
4706 : : ? G_("use of local variable with automatic storage from "
4707 : : "containing function")
4708 : : : G_("use of parameter from containing function"));
4709 : 39 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4710 : 39 : }
4711 : 46 : return error_mark_node;
4712 : : }
4713 : 828422 : return decl;
4714 : : }
4715 : :
4716 : : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4717 : : id-expression. (See cp_parser_id_expression for details.) SCOPE,
4718 : : if non-NULL, is the type or namespace used to explicitly qualify
4719 : : ID_EXPRESSION. DECL is the entity to which that name has been
4720 : : resolved.
4721 : :
4722 : : *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4723 : : constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4724 : : be set to true if this expression isn't permitted in a
4725 : : constant-expression, but it is otherwise not set by this function.
4726 : : *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4727 : : constant-expression, but a non-constant expression is also
4728 : : permissible.
4729 : :
4730 : : DONE is true if this expression is a complete postfix-expression;
4731 : : it is false if this expression is followed by '->', '[', '(', etc.
4732 : : ADDRESS_P is true iff this expression is the operand of '&'.
4733 : : TEMPLATE_P is true iff the qualified-id was of the form
4734 : : "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4735 : : appears as a template argument.
4736 : :
4737 : : If an error occurs, and it is the kind of error that might cause
4738 : : the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4739 : : is the caller's responsibility to issue the message. *ERROR_MSG
4740 : : will be a string with static storage duration, so the caller need
4741 : : not "free" it.
4742 : :
4743 : : Return an expression for the entity, after issuing appropriate
4744 : : diagnostics. This function is also responsible for transforming a
4745 : : reference to a non-static member into a COMPONENT_REF that makes
4746 : : the use of "this" explicit.
4747 : :
4748 : : Upon return, *IDK will be filled in appropriately. */
4749 : : static cp_expr
4750 : 746928581 : finish_id_expression_1 (tree id_expression,
4751 : : tree decl,
4752 : : tree scope,
4753 : : cp_id_kind *idk,
4754 : : bool integral_constant_expression_p,
4755 : : bool allow_non_integral_constant_expression_p,
4756 : : bool *non_integral_constant_expression_p,
4757 : : bool template_p,
4758 : : bool done,
4759 : : bool address_p,
4760 : : bool template_arg_p,
4761 : : const char **error_msg,
4762 : : location_t location)
4763 : : {
4764 : 746928581 : decl = strip_using_decl (decl);
4765 : :
4766 : : /* Initialize the output parameters. */
4767 : 746928581 : *idk = CP_ID_KIND_NONE;
4768 : 746928581 : *error_msg = NULL;
4769 : :
4770 : 746928581 : if (id_expression == error_mark_node)
4771 : 12 : return error_mark_node;
4772 : : /* If we have a template-id, then no further lookup is
4773 : : required. If the template-id was for a template-class, we
4774 : : will sometimes have a TYPE_DECL at this point. */
4775 : 746928569 : else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4776 : 696490258 : || TREE_CODE (decl) == TYPE_DECL)
4777 : : ;
4778 : : /* Look up the name. */
4779 : : else
4780 : : {
4781 : 696489369 : if (decl == error_mark_node)
4782 : : {
4783 : : /* Name lookup failed. */
4784 : 120430 : if (scope
4785 : 370 : && !dependent_namespace_p (scope)
4786 : 120800 : && (!TYPE_P (scope)
4787 : 116 : || (!dependentish_scope_p (scope)
4788 : 112 : && !(identifier_p (id_expression)
4789 : 97 : && IDENTIFIER_CONV_OP_P (id_expression)
4790 : 3 : && dependent_type_p (TREE_TYPE (id_expression))))))
4791 : : {
4792 : : /* If the qualifying type is non-dependent (and the name
4793 : : does not name a conversion operator to a dependent
4794 : : type), issue an error. */
4795 : 360 : qualified_name_lookup_error (scope, id_expression, decl, location);
4796 : 360 : return error_mark_node;
4797 : : }
4798 : 120070 : else if (!scope)
4799 : : {
4800 : : /* It may be resolved via Koenig lookup. */
4801 : 120060 : *idk = CP_ID_KIND_UNQUALIFIED;
4802 : 120060 : return id_expression;
4803 : : }
4804 : : else
4805 : : decl = id_expression;
4806 : : }
4807 : :
4808 : : /* Remember that the name was used in the definition of
4809 : : the current class so that we can check later to see if
4810 : : the meaning would have been different after the class
4811 : : was entirely defined. */
4812 : 696368939 : if (!scope && decl != error_mark_node && identifier_p (id_expression))
4813 : 622906718 : maybe_note_name_used_in_class (id_expression, decl);
4814 : :
4815 : : /* A use in unevaluated operand might not be instantiated appropriately
4816 : : if tsubst_copy builds a dummy parm, or if we never instantiate a
4817 : : generic lambda, so mark it now. */
4818 : 696368949 : if (processing_template_decl
4819 : 696368949 : && (cp_unevaluated_operand
4820 : 602099162 : || generic_lambda_fn_p (current_function_decl)))
4821 : 18800340 : mark_type_use (decl);
4822 : :
4823 : : /* Disallow uses of local variables from containing functions, except
4824 : : within lambda-expressions. */
4825 : 696368949 : if (outer_automatic_var_p (decl))
4826 : : {
4827 : 3319438 : decl = process_outer_var_ref (decl, tf_warning_or_error);
4828 : 3319438 : if (decl == error_mark_node)
4829 : 85 : return error_mark_node;
4830 : : }
4831 : :
4832 : : /* Also disallow uses of function parameters outside the function
4833 : : body, except inside an unevaluated context (i.e. decltype). */
4834 : 696368864 : if (TREE_CODE (decl) == PARM_DECL
4835 : 289909108 : && DECL_CONTEXT (decl) == NULL_TREE
4836 : 7838952 : && !CONSTRAINT_VAR_P (decl)
4837 : 4224139 : && !cp_unevaluated_operand
4838 : 374 : && !processing_contract_condition
4839 : 696368908 : && !processing_omp_trait_property_expr)
4840 : : {
4841 : 26 : *error_msg = G_("use of parameter outside function body");
4842 : 26 : return error_mark_node;
4843 : : }
4844 : : }
4845 : :
4846 : : /* If we didn't find anything, or what we found was a type,
4847 : : then this wasn't really an id-expression. */
4848 : 746808038 : if (TREE_CODE (decl) == TEMPLATE_DECL
4849 : 746808038 : && !DECL_FUNCTION_TEMPLATE_P (decl))
4850 : : {
4851 : 51 : *error_msg = G_("missing template arguments");
4852 : 51 : return error_mark_node;
4853 : : }
4854 : 746807987 : else if (TREE_CODE (decl) == TYPE_DECL
4855 : 746807098 : || TREE_CODE (decl) == NAMESPACE_DECL)
4856 : : {
4857 : 904 : *error_msg = G_("expected primary-expression");
4858 : 904 : return error_mark_node;
4859 : : }
4860 : :
4861 : : /* If the name resolved to a template parameter, there is no
4862 : : need to look it up again later. */
4863 : 31846094 : if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
4864 : 760234190 : || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4865 : : {
4866 : 18418987 : tree r;
4867 : :
4868 : 18418987 : *idk = CP_ID_KIND_NONE;
4869 : 18418987 : if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4870 : 0 : decl = TEMPLATE_PARM_DECL (decl);
4871 : 18418987 : r = DECL_INITIAL (decl);
4872 : 18418987 : if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
4873 : : {
4874 : : /* If the entity is a template parameter object for a template
4875 : : parameter of type T, the type of the expression is const T. */
4876 : 161 : tree ctype = TREE_TYPE (r);
4877 : 161 : ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
4878 : : | TYPE_QUAL_CONST));
4879 : 161 : r = build1 (VIEW_CONVERT_EXPR, ctype, r);
4880 : : }
4881 : 18418987 : r = convert_from_reference (r);
4882 : 18418987 : if (integral_constant_expression_p
4883 : 3160763 : && !dependent_type_p (TREE_TYPE (decl))
4884 : 21105741 : && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
4885 : : {
4886 : 330 : if (!allow_non_integral_constant_expression_p)
4887 : 6 : error ("template parameter %qD of type %qT is not allowed in "
4888 : : "an integral constant expression because it is not of "
4889 : 6 : "integral or enumeration type", decl, TREE_TYPE (decl));
4890 : 330 : *non_integral_constant_expression_p = true;
4891 : : }
4892 : :
4893 : 18418987 : if (flag_contracts && processing_contract_condition)
4894 : 9 : r = constify_contract_access (r);
4895 : :
4896 : 18418987 : return r;
4897 : : }
4898 : 728388096 : else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
4899 : : {
4900 : 9 : gcc_checking_assert (scope);
4901 : 9 : *idk = CP_ID_KIND_QUALIFIED;
4902 : 9 : cp_warn_deprecated_use_scopes (scope);
4903 : 9 : decl = finish_qualified_id_expr (scope, decl, done, address_p,
4904 : : template_p, template_arg_p,
4905 : : tf_warning_or_error);
4906 : : }
4907 : : else
4908 : : {
4909 : 728388087 : if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4910 : 50438311 : && variable_template_p (TREE_OPERAND (decl, 0))
4911 : 739711364 : && !concept_check_p (decl))
4912 : : /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
4913 : : considered type-dependent) now, so that the dependence test that
4914 : : follows gives us the right answer: if it represents a non-dependent
4915 : : variable template-id then finish_template_variable will yield the
4916 : : corresponding non-dependent VAR_DECL. */
4917 : 11323277 : decl = finish_template_variable (decl);
4918 : :
4919 : 728388087 : bool dependent_p = type_dependent_expression_p (decl);
4920 : :
4921 : : /* If the declaration was explicitly qualified indicate
4922 : : that. The semantics of `A::f(3)' are different than
4923 : : `f(3)' if `f' is virtual. */
4924 : 1456776174 : *idk = (scope
4925 : 728388087 : ? CP_ID_KIND_QUALIFIED
4926 : 634180339 : : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4927 : 634180339 : ? CP_ID_KIND_TEMPLATE_ID
4928 : : : (dependent_p
4929 : 604756600 : ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
4930 : : : CP_ID_KIND_UNQUALIFIED)));
4931 : :
4932 : 728388087 : if (dependent_p
4933 : 728388087 : && !scope
4934 : 416438151 : && DECL_P (decl)
4935 : 1116167771 : && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
4936 : : /* Dependent type attributes on the decl mean that the TREE_TYPE is
4937 : : wrong, so just return the identifier. */
4938 : 39 : return id_expression;
4939 : :
4940 : 728388048 : if (DECL_CLASS_TEMPLATE_P (decl))
4941 : : {
4942 : 0 : error ("use of class template %qT as expression", decl);
4943 : 0 : return error_mark_node;
4944 : : }
4945 : :
4946 : 728388048 : if (TREE_CODE (decl) == TREE_LIST)
4947 : : {
4948 : : /* Ambiguous reference to base members. */
4949 : 0 : auto_diagnostic_group d;
4950 : 0 : error ("request for member %qD is ambiguous in "
4951 : : "multiple inheritance lattice", id_expression);
4952 : 0 : print_candidates (input_location, decl);
4953 : 0 : return error_mark_node;
4954 : 0 : }
4955 : :
4956 : : /* Mark variable-like entities as used. Functions are similarly
4957 : : marked either below or after overload resolution. */
4958 : 728388048 : if ((VAR_P (decl)
4959 : 527120561 : || TREE_CODE (decl) == PARM_DECL
4960 : 237211485 : || TREE_CODE (decl) == CONST_DECL
4961 : 223784378 : || TREE_CODE (decl) == RESULT_DECL)
4962 : 1031724231 : && !mark_used (decl))
4963 : 12 : return error_mark_node;
4964 : :
4965 : : /* Only certain kinds of names are allowed in constant
4966 : : expression. Template parameters have already
4967 : : been handled above. */
4968 : 728388033 : if (! error_operand_p (decl)
4969 : 728387735 : && !dependent_p
4970 : 728387735 : && integral_constant_expression_p
4971 : 74176504 : && !decl_constant_var_p (decl)
4972 : 60439654 : && TREE_CODE (decl) != CONST_DECL
4973 : 52234624 : && !builtin_valid_in_constant_expr_p (decl)
4974 : 780575158 : && !concept_check_p (decl))
4975 : : {
4976 : 51676008 : if (!allow_non_integral_constant_expression_p)
4977 : : {
4978 : 30 : error ("%qD cannot appear in a constant-expression", decl);
4979 : 30 : return error_mark_node;
4980 : : }
4981 : 51675978 : *non_integral_constant_expression_p = true;
4982 : : }
4983 : :
4984 : 728388003 : if (tree wrap = maybe_get_tls_wrapper_call (decl))
4985 : : /* Replace an evaluated use of the thread_local variable with
4986 : : a call to its wrapper. */
4987 : : decl = wrap;
4988 : 728387491 : else if (concept_check_p (decl))
4989 : : {
4990 : : /* Nothing more to do. All of the analysis for concept checks
4991 : : is done by build_conept_id, called from the parser. */
4992 : : }
4993 : 712974565 : else if (scope)
4994 : : {
4995 : 92468416 : if (TREE_CODE (decl) == SCOPE_REF)
4996 : : {
4997 : 71728 : gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
4998 : 71728 : decl = TREE_OPERAND (decl, 1);
4999 : : }
5000 : :
5001 : 92468416 : decl = (adjust_result_of_qualified_name_lookup
5002 : 92468416 : (decl, scope, current_nonlambda_class_type()));
5003 : :
5004 : 92468416 : cp_warn_deprecated_use_scopes (scope);
5005 : :
5006 : 92468416 : if (TYPE_P (scope))
5007 : 13352405 : decl = finish_qualified_id_expr (scope,
5008 : : decl,
5009 : : done,
5010 : : address_p,
5011 : : template_p,
5012 : : template_arg_p,
5013 : : tf_warning_or_error);
5014 : : else
5015 : 79116011 : decl = convert_from_reference (decl);
5016 : : }
5017 : 620506149 : else if (TREE_CODE (decl) == FIELD_DECL)
5018 : : {
5019 : 65144100 : if (flag_contracts && processing_contract_condition
5020 : 22 : && contract_class_ptr == current_class_ptr)
5021 : : {
5022 : 4 : error ("%qD 'this' required when accessing a member within a "
5023 : : "constructor precondition or destructor postcondition "
5024 : : "contract check", decl);
5025 : 4 : return error_mark_node;
5026 : : }
5027 : : /* Since SCOPE is NULL here, this is an unqualified name.
5028 : : Access checking has been performed during name lookup
5029 : : already. Turn off checking to avoid duplicate errors. */
5030 : 65144096 : push_deferring_access_checks (dk_no_check);
5031 : 65144096 : decl = finish_non_static_data_member (decl, NULL_TREE,
5032 : : /*qualifying_scope=*/NULL_TREE);
5033 : 65144096 : pop_deferring_access_checks ();
5034 : : }
5035 : 555362049 : else if (is_overloaded_fn (decl))
5036 : : {
5037 : : /* We only need to look at the first function,
5038 : : because all the fns share the attribute we're
5039 : : concerned with (all member fns or all non-members). */
5040 : 58982042 : tree first_fn = get_first_fn (decl);
5041 : 58982042 : first_fn = STRIP_TEMPLATE (first_fn);
5042 : :
5043 : 58982042 : if (!template_arg_p
5044 : 58982042 : && (TREE_CODE (first_fn) == USING_DECL
5045 : 58980194 : || (TREE_CODE (first_fn) == FUNCTION_DECL
5046 : 58980194 : && DECL_FUNCTION_MEMBER_P (first_fn)
5047 : 35629769 : && !shared_member_p (decl))))
5048 : : {
5049 : : /* A set of member functions. */
5050 : 27542004 : if (flag_contracts && processing_contract_condition
5051 : 16 : && contract_class_ptr == current_class_ptr)
5052 : : {
5053 : 2 : error ("%qD 'this' required when accessing a member within a "
5054 : : "constructor precondition or destructor postcondition "
5055 : : "contract check", decl);
5056 : 2 : return error_mark_node;
5057 : : }
5058 : 27542002 : decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
5059 : 27542002 : return finish_class_member_access_expr (decl, id_expression,
5060 : : /*template_p=*/false,
5061 : 27542002 : tf_warning_or_error);
5062 : : }
5063 : :
5064 : 31440038 : decl = baselink_for_fns (decl);
5065 : : }
5066 : : else
5067 : : {
5068 : 485931302 : if (DECL_P (decl) && DECL_NONLOCAL (decl)
5069 : 497842111 : && DECL_CLASS_SCOPE_P (decl))
5070 : : {
5071 : 1462104 : tree context = context_for_name_lookup (decl);
5072 : 1462104 : if (context != current_class_type)
5073 : : {
5074 : 769372 : tree path = currently_open_derived_class (context);
5075 : 769372 : if (!path)
5076 : : /* PATH can be null for using an enum of an unrelated
5077 : : class; we checked its access in lookup_using_decl.
5078 : :
5079 : : ??? Should this case make a clone instead, like
5080 : : handle_using_decl? */
5081 : 11 : gcc_assert (TREE_CODE (decl) == CONST_DECL);
5082 : : else
5083 : 769361 : perform_or_defer_access_check (TYPE_BINFO (path),
5084 : : decl, decl,
5085 : : tf_warning_or_error);
5086 : : }
5087 : : }
5088 : :
5089 : 496380007 : decl = convert_from_reference (decl);
5090 : : }
5091 : : }
5092 : :
5093 : 700846004 : check_param_in_postcondition (decl, location);
5094 : 700846004 : if (flag_contracts && processing_contract_condition)
5095 : 1303 : decl = constify_contract_access (decl);
5096 : :
5097 : 700846004 : return cp_expr (decl, location);
5098 : : }
5099 : :
5100 : : /* As per finish_id_expression_1, but adding a wrapper node
5101 : : around the result if needed to express LOCATION. */
5102 : :
5103 : : cp_expr
5104 : 746928581 : finish_id_expression (tree id_expression,
5105 : : tree decl,
5106 : : tree scope,
5107 : : cp_id_kind *idk,
5108 : : bool integral_constant_expression_p,
5109 : : bool allow_non_integral_constant_expression_p,
5110 : : bool *non_integral_constant_expression_p,
5111 : : bool template_p,
5112 : : bool done,
5113 : : bool address_p,
5114 : : bool template_arg_p,
5115 : : const char **error_msg,
5116 : : location_t location)
5117 : : {
5118 : 746928581 : cp_expr result
5119 : 746928581 : = finish_id_expression_1 (id_expression, decl, scope, idk,
5120 : : integral_constant_expression_p,
5121 : : allow_non_integral_constant_expression_p,
5122 : : non_integral_constant_expression_p,
5123 : : template_p, done, address_p, template_arg_p,
5124 : : error_msg, location);
5125 : 746928578 : return result.maybe_add_location_wrapper ();
5126 : : }
5127 : :
5128 : : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
5129 : : use as a type-specifier. */
5130 : :
5131 : : tree
5132 : 21101811 : finish_typeof (tree expr)
5133 : : {
5134 : 21101811 : tree type;
5135 : :
5136 : 21101811 : if (type_dependent_expression_p (expr))
5137 : : {
5138 : 21011027 : type = cxx_make_type (TYPEOF_TYPE);
5139 : 21011027 : TYPEOF_TYPE_EXPR (type) = expr;
5140 : 21011027 : SET_TYPE_STRUCTURAL_EQUALITY (type);
5141 : :
5142 : 21011027 : return type;
5143 : : }
5144 : :
5145 : 90784 : expr = mark_type_use (expr);
5146 : :
5147 : 90784 : type = unlowered_expr_type (expr);
5148 : :
5149 : 90784 : if (!type || type == unknown_type_node)
5150 : : {
5151 : 3 : error ("type of %qE is unknown", expr);
5152 : 3 : return error_mark_node;
5153 : : }
5154 : :
5155 : : return type;
5156 : : }
5157 : :
5158 : : /* Implement the __underlying_type keyword: Return the underlying
5159 : : type of TYPE, suitable for use as a type-specifier. */
5160 : :
5161 : : tree
5162 : 46403 : finish_underlying_type (tree type)
5163 : : {
5164 : 46403 : if (!complete_type_or_else (type, NULL_TREE))
5165 : 3 : return error_mark_node;
5166 : :
5167 : 46400 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5168 : : {
5169 : 24 : error ("%qT is not an enumeration type", type);
5170 : 24 : return error_mark_node;
5171 : : }
5172 : :
5173 : 46376 : tree underlying_type = ENUM_UNDERLYING_TYPE (type);
5174 : :
5175 : : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5176 : : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5177 : : See finish_enum_value_list for details. */
5178 : 46376 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5179 : 54 : underlying_type
5180 : 54 : = c_common_type_for_mode (TYPE_MODE (underlying_type),
5181 : 54 : TYPE_UNSIGNED (underlying_type));
5182 : :
5183 : : return underlying_type;
5184 : : }
5185 : :
5186 : : /* Implement the __type_pack_element keyword: Return the type
5187 : : at index IDX within TYPES. */
5188 : :
5189 : : static tree
5190 : 113496 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
5191 : : {
5192 : 113496 : idx = maybe_constant_value (idx, NULL_TREE, mce_true);
5193 : 113496 : if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
5194 : : {
5195 : 6 : if (complain & tf_error)
5196 : 3 : error ("pack index has non-integral type %qT", TREE_TYPE (idx));
5197 : 6 : return error_mark_node;
5198 : : }
5199 : 113490 : if (TREE_CODE (idx) != INTEGER_CST)
5200 : : {
5201 : 1 : if (complain & tf_error)
5202 : : {
5203 : 1 : error ("pack index is not an integral constant");
5204 : 1 : cxx_constant_value (idx);
5205 : : }
5206 : 1 : return error_mark_node;
5207 : : }
5208 : 113489 : if (tree_int_cst_sgn (idx) < 0)
5209 : : {
5210 : 5 : if (complain & tf_error)
5211 : 5 : error ("pack index %qE is negative", idx);
5212 : 5 : return error_mark_node;
5213 : : }
5214 : 113484 : if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
5215 : : {
5216 : 28 : if (complain & tf_error)
5217 : 22 : error ("pack index %qE is out of range for pack of length %qd",
5218 : 22 : idx, TREE_VEC_LENGTH (types));
5219 : 28 : return error_mark_node;
5220 : : }
5221 : 113456 : return TREE_VEC_ELT (types, tree_to_shwi (idx));
5222 : : }
5223 : :
5224 : : /* In a pack-index T...[N], return the element at index IDX within TYPES.
5225 : : PARENTHESIZED_P is true iff the pack index was wrapped in (). */
5226 : :
5227 : : tree
5228 : 7610 : pack_index_element (tree idx, tree types, bool parenthesized_p,
5229 : : tsubst_flags_t complain)
5230 : : {
5231 : 7610 : tree r = finish_type_pack_element (idx, types, complain);
5232 : 7610 : if (parenthesized_p)
5233 : : /* For the benefit of decltype(auto). */
5234 : 22 : r = force_paren_expr (r);
5235 : 7610 : return r;
5236 : : }
5237 : :
5238 : : /* Implement the __direct_bases keyword: Return the direct base classes
5239 : : of type. */
5240 : :
5241 : : tree
5242 : 15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
5243 : : {
5244 : 15 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5245 : 15 : || !NON_UNION_CLASS_TYPE_P (type))
5246 : 8 : return make_tree_vec (0);
5247 : :
5248 : 7 : releasing_vec vector;
5249 : 7 : vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
5250 : 7 : tree binfo;
5251 : 7 : unsigned i;
5252 : :
5253 : : /* Virtual bases are initialized first */
5254 : 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5255 : 13 : if (BINFO_VIRTUAL_P (binfo))
5256 : 2 : vec_safe_push (vector, binfo);
5257 : :
5258 : : /* Now non-virtuals */
5259 : 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5260 : 13 : if (!BINFO_VIRTUAL_P (binfo))
5261 : 11 : vec_safe_push (vector, binfo);
5262 : :
5263 : 7 : tree bases_vec = make_tree_vec (vector->length ());
5264 : :
5265 : 27 : for (i = 0; i < vector->length (); ++i)
5266 : 13 : TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
5267 : :
5268 : 7 : return bases_vec;
5269 : 7 : }
5270 : :
5271 : : /* Implement the __bases keyword: Return the base classes
5272 : : of type */
5273 : :
5274 : : /* Find morally non-virtual base classes by walking binfo hierarchy */
5275 : : /* Virtual base classes are handled separately in finish_bases */
5276 : :
5277 : : static tree
5278 : 73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
5279 : : {
5280 : : /* Don't walk bases of virtual bases */
5281 : 73 : return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
5282 : : }
5283 : :
5284 : : static tree
5285 : 73 : dfs_calculate_bases_post (tree binfo, void *data_)
5286 : : {
5287 : 73 : vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
5288 : 73 : if (!BINFO_VIRTUAL_P (binfo))
5289 : 48 : vec_safe_push (*data, BINFO_TYPE (binfo));
5290 : 73 : return NULL_TREE;
5291 : : }
5292 : :
5293 : : /* Calculates the morally non-virtual base classes of a class */
5294 : : static vec<tree, va_gc> *
5295 : 16 : calculate_bases_helper (tree type)
5296 : : {
5297 : 16 : vec<tree, va_gc> *vector = make_tree_vector ();
5298 : :
5299 : : /* Now add non-virtual base classes in order of construction */
5300 : 16 : if (TYPE_BINFO (type))
5301 : 16 : dfs_walk_all (TYPE_BINFO (type),
5302 : : dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
5303 : 16 : return vector;
5304 : : }
5305 : :
5306 : : tree
5307 : 12 : calculate_bases (tree type, tsubst_flags_t complain)
5308 : : {
5309 : 12 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5310 : 12 : || !NON_UNION_CLASS_TYPE_P (type))
5311 : 5 : return make_tree_vec (0);
5312 : :
5313 : 7 : releasing_vec vector;
5314 : 7 : tree bases_vec = NULL_TREE;
5315 : 7 : unsigned i;
5316 : 7 : vec<tree, va_gc> *vbases;
5317 : 7 : tree binfo;
5318 : :
5319 : : /* First go through virtual base classes */
5320 : 7 : for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
5321 : 16 : vec_safe_iterate (vbases, i, &binfo); i++)
5322 : : {
5323 : 9 : releasing_vec vbase_bases
5324 : 9 : = calculate_bases_helper (BINFO_TYPE (binfo));
5325 : 9 : vec_safe_splice (vector, vbase_bases);
5326 : 9 : }
5327 : :
5328 : : /* Now for the non-virtual bases */
5329 : 7 : releasing_vec nonvbases = calculate_bases_helper (type);
5330 : 7 : vec_safe_splice (vector, nonvbases);
5331 : :
5332 : : /* Note that during error recovery vector->length can even be zero. */
5333 : 7 : if (vector->length () > 1)
5334 : : {
5335 : : /* Last element is entire class, so don't copy */
5336 : 6 : bases_vec = make_tree_vec (vector->length () - 1);
5337 : :
5338 : 53 : for (i = 0; i < vector->length () - 1; ++i)
5339 : 41 : TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
5340 : : }
5341 : : else
5342 : 1 : bases_vec = make_tree_vec (0);
5343 : :
5344 : 7 : return bases_vec;
5345 : 7 : }
5346 : :
5347 : : tree
5348 : 28 : finish_bases (tree type, bool direct)
5349 : : {
5350 : 28 : tree bases = NULL_TREE;
5351 : :
5352 : 28 : if (!processing_template_decl)
5353 : : {
5354 : : /* Parameter packs can only be used in templates */
5355 : 0 : error ("parameter pack %<__bases%> only valid in template declaration");
5356 : 0 : return error_mark_node;
5357 : : }
5358 : :
5359 : 28 : bases = cxx_make_type (BASES);
5360 : 28 : BASES_TYPE (bases) = type;
5361 : 28 : BASES_DIRECT (bases) = direct;
5362 : 28 : SET_TYPE_STRUCTURAL_EQUALITY (bases);
5363 : :
5364 : 28 : return bases;
5365 : : }
5366 : :
5367 : : /* Perform C++-specific checks for __builtin_offsetof before calling
5368 : : fold_offsetof. */
5369 : :
5370 : : tree
5371 : 2400 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
5372 : : {
5373 : : /* If we're processing a template, we can't finish the semantics yet.
5374 : : Otherwise we can fold the entire expression now. */
5375 : 2400 : if (processing_template_decl)
5376 : : {
5377 : 60 : expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
5378 : 60 : SET_EXPR_LOCATION (expr, loc);
5379 : 60 : return expr;
5380 : : }
5381 : :
5382 : 2340 : if (expr == error_mark_node)
5383 : : return error_mark_node;
5384 : :
5385 : 2323 : if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
5386 : : {
5387 : 6 : error ("cannot apply %<offsetof%> to destructor %<~%T%>",
5388 : 6 : TREE_OPERAND (expr, 2));
5389 : 6 : return error_mark_node;
5390 : : }
5391 : 4619 : if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
5392 : 4619 : || TREE_TYPE (expr) == unknown_type_node)
5393 : : {
5394 : 30 : while (TREE_CODE (expr) == COMPONENT_REF
5395 : 30 : || TREE_CODE (expr) == COMPOUND_EXPR)
5396 : 12 : expr = TREE_OPERAND (expr, 1);
5397 : :
5398 : 18 : if (DECL_P (expr))
5399 : : {
5400 : 0 : auto_diagnostic_group d;
5401 : 0 : error ("cannot apply %<offsetof%> to member function %qD", expr);
5402 : 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
5403 : 0 : }
5404 : : else
5405 : 18 : error ("cannot apply %<offsetof%> to member function");
5406 : 18 : return error_mark_node;
5407 : : }
5408 : 2299 : if (TREE_CODE (expr) == CONST_DECL)
5409 : : {
5410 : 3 : error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
5411 : 3 : return error_mark_node;
5412 : : }
5413 : 2296 : if (REFERENCE_REF_P (expr))
5414 : 9 : expr = TREE_OPERAND (expr, 0);
5415 : 2296 : if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
5416 : 3 : return error_mark_node;
5417 : 2293 : if (warn_invalid_offsetof
5418 : 2293 : && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
5419 : 2293 : && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
5420 : 2338 : && cp_unevaluated_operand == 0)
5421 : 45 : warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
5422 : : "non-standard-layout type %qT is conditionally-supported",
5423 : 45 : TREE_TYPE (TREE_TYPE (object_ptr)));
5424 : 2293 : return fold_offsetof (expr);
5425 : : }
5426 : :
5427 : : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
5428 : : function is broken out from the above for the benefit of the tree-ssa
5429 : : project. */
5430 : :
5431 : : void
5432 : 340020 : simplify_aggr_init_expr (tree *tp)
5433 : : {
5434 : 340020 : tree aggr_init_expr = *tp;
5435 : :
5436 : : /* Form an appropriate CALL_EXPR. */
5437 : 340020 : tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
5438 : 340020 : tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
5439 : 340020 : tree type = TREE_TYPE (slot);
5440 : :
5441 : 340020 : tree call_expr;
5442 : 340020 : enum style_t { ctor, arg, pcc } style;
5443 : :
5444 : 340020 : if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
5445 : : style = ctor;
5446 : : #ifdef PCC_STATIC_STRUCT_RETURN
5447 : : else if (1)
5448 : : style = pcc;
5449 : : #endif
5450 : : else
5451 : : {
5452 : 89255 : gcc_assert (TREE_ADDRESSABLE (type));
5453 : : style = arg;
5454 : : }
5455 : :
5456 : 340020 : call_expr = build_call_array_loc (input_location,
5457 : 340020 : TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
5458 : : fn,
5459 : 340020 : aggr_init_expr_nargs (aggr_init_expr),
5460 : 340020 : AGGR_INIT_EXPR_ARGP (aggr_init_expr));
5461 : 340020 : TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
5462 : 340020 : CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
5463 : 340020 : CALL_EXPR_OPERATOR_SYNTAX (call_expr)
5464 : 340020 : = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
5465 : 340020 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
5466 : 340020 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
5467 : 340020 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
5468 : :
5469 : 340020 : if (style == ctor)
5470 : : {
5471 : : /* Replace the first argument to the ctor with the address of the
5472 : : slot. */
5473 : 250765 : cxx_mark_addressable (slot);
5474 : 250765 : CALL_EXPR_ARG (call_expr, 0) =
5475 : 250765 : build1 (ADDR_EXPR, build_pointer_type (type), slot);
5476 : : }
5477 : 89255 : else if (style == arg)
5478 : : {
5479 : : /* Just mark it addressable here, and leave the rest to
5480 : : expand_call{,_inline}. */
5481 : 89255 : cxx_mark_addressable (slot);
5482 : 89255 : CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
5483 : 89255 : call_expr = cp_build_init_expr (slot, call_expr);
5484 : : }
5485 : : else if (style == pcc)
5486 : : {
5487 : : /* If we're using the non-reentrant PCC calling convention, then we
5488 : : need to copy the returned value out of the static buffer into the
5489 : : SLOT. */
5490 : : push_deferring_access_checks (dk_no_check);
5491 : : call_expr = build_aggr_init (slot, call_expr,
5492 : : DIRECT_BIND | LOOKUP_ONLYCONVERTING,
5493 : : tf_warning_or_error);
5494 : : pop_deferring_access_checks ();
5495 : : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
5496 : : }
5497 : :
5498 : 340020 : if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
5499 : : {
5500 : 3242 : tree init = build_zero_init (type, NULL_TREE,
5501 : : /*static_storage_p=*/false);
5502 : 3242 : init = cp_build_init_expr (slot, init);
5503 : 3242 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
5504 : : init, call_expr);
5505 : : }
5506 : :
5507 : 340020 : *tp = call_expr;
5508 : 340020 : }
5509 : :
5510 : : /* Emit all thunks to FN that should be emitted when FN is emitted. */
5511 : :
5512 : : void
5513 : 65524542 : emit_associated_thunks (tree fn)
5514 : : {
5515 : : /* When we use vcall offsets, we emit thunks with the virtual
5516 : : functions to which they thunk. The whole point of vcall offsets
5517 : : is so that you can know statically the entire set of thunks that
5518 : : will ever be needed for a given virtual function, thereby
5519 : : enabling you to output all the thunks with the function itself. */
5520 : 65524542 : if (DECL_VIRTUAL_P (fn)
5521 : : /* Do not emit thunks for extern template instantiations. */
5522 : 1331039 : && ! DECL_REALLY_EXTERN (fn)
5523 : : /* Do not emit thunks for tentative decls, those will be processed
5524 : : again at_eof if really needed. */
5525 : 66693248 : && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
5526 : : {
5527 : 1168025 : tree thunk;
5528 : :
5529 : 2340255 : for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
5530 : : {
5531 : 4205 : if (!THUNK_ALIAS (thunk))
5532 : : {
5533 : 4205 : use_thunk (thunk, /*emit_p=*/1);
5534 : 4205 : if (DECL_RESULT_THUNK_P (thunk))
5535 : : {
5536 : 178 : tree probe;
5537 : :
5538 : 178 : for (probe = DECL_THUNKS (thunk);
5539 : 327 : probe; probe = DECL_CHAIN (probe))
5540 : 149 : use_thunk (probe, /*emit_p=*/1);
5541 : : }
5542 : : }
5543 : : else
5544 : 0 : gcc_assert (!DECL_THUNKS (thunk));
5545 : : }
5546 : : }
5547 : 65524542 : }
5548 : :
5549 : : /* Generate RTL for FN. */
5550 : :
5551 : : bool
5552 : 165429564 : expand_or_defer_fn_1 (tree fn)
5553 : : {
5554 : : /* When the parser calls us after finishing the body of a template
5555 : : function, we don't really want to expand the body. */
5556 : 165429564 : if (processing_template_decl)
5557 : : {
5558 : : /* Normally, collection only occurs in rest_of_compilation. So,
5559 : : if we don't collect here, we never collect junk generated
5560 : : during the processing of templates until we hit a
5561 : : non-template function. It's not safe to do this inside a
5562 : : nested class, though, as the parser may have local state that
5563 : : is not a GC root. */
5564 : 91206076 : if (!function_depth)
5565 : 90774792 : ggc_collect ();
5566 : 91206076 : return false;
5567 : : }
5568 : :
5569 : 74223488 : gcc_assert (DECL_SAVED_TREE (fn));
5570 : :
5571 : : /* We make a decision about linkage for these functions at the end
5572 : : of the compilation. Until that point, we do not want the back
5573 : : end to output them -- but we do want it to see the bodies of
5574 : : these functions so that it can inline them as appropriate. */
5575 : 74223488 : if (DECL_DECLARED_INLINE_P (fn)
5576 : 2046083 : || DECL_IMPLICIT_INSTANTIATION (fn)
5577 : 74481721 : || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (fn))
5578 : : {
5579 : 73965282 : if (DECL_INTERFACE_KNOWN (fn))
5580 : : /* We've already made a decision as to how this function will
5581 : : be handled. */;
5582 : 52789543 : else if (!at_eof
5583 : 23665687 : || DECL_IMMEDIATE_FUNCTION_P (fn)
5584 : 75551949 : || DECL_OMP_DECLARE_REDUCTION_P (fn))
5585 : 30027137 : tentative_decl_linkage (fn);
5586 : : else
5587 : 22762406 : import_export_decl (fn);
5588 : :
5589 : : /* If the user wants us to keep all inline functions, then mark
5590 : : this function as needed so that finish_file will make sure to
5591 : : output it later. Similarly, all dllexport'd functions must
5592 : : be emitted; there may be callers in other DLLs. */
5593 : 73965282 : if (DECL_DECLARED_INLINE_P (fn)
5594 : 72177405 : && !DECL_REALLY_EXTERN (fn)
5595 : 69609740 : && !DECL_IMMEDIATE_FUNCTION_P (fn)
5596 : 68197183 : && !DECL_OMP_DECLARE_REDUCTION_P (fn)
5597 : 142162465 : && (flag_keep_inline_functions
5598 : 68194291 : || (flag_keep_inline_dllexport
5599 : 68194291 : && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
5600 : : {
5601 : 2892 : mark_needed (fn);
5602 : 2892 : DECL_EXTERNAL (fn) = 0;
5603 : : }
5604 : : }
5605 : :
5606 : : /* If this is a constructor or destructor body, we have to clone
5607 : : it. */
5608 : 74223488 : if (maybe_clone_body (fn))
5609 : : {
5610 : : /* We don't want to process FN again, so pretend we've written
5611 : : it out, even though we haven't. */
5612 : 8670802 : TREE_ASM_WRITTEN (fn) = 1;
5613 : : /* If this is a constexpr function we still need the body to be
5614 : : able to evaluate it. Similarly, with modules we only stream
5615 : : the maybe-in-charge cdtor and regenerate the clones from it on
5616 : : demand, so we also need to keep the body. Otherwise we don't
5617 : : need it anymore. */
5618 : 8670802 : if (!maybe_constexpr_fn (fn)
5619 : 8670802 : && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
5620 : 3805745 : DECL_SAVED_TREE (fn) = void_node;
5621 : 8670802 : return false;
5622 : : }
5623 : :
5624 : : /* There's no reason to do any of the work here if we're only doing
5625 : : semantic analysis; this code just generates RTL. */
5626 : 65552686 : if (flag_syntax_only)
5627 : : {
5628 : : /* Pretend that this function has been written out so that we don't try
5629 : : to expand it again. */
5630 : 28128 : TREE_ASM_WRITTEN (fn) = 1;
5631 : 28128 : return false;
5632 : : }
5633 : :
5634 : 65524558 : if (DECL_OMP_DECLARE_REDUCTION_P (fn))
5635 : : return false;
5636 : :
5637 : : return true;
5638 : : }
5639 : :
5640 : : void
5641 : 156777267 : expand_or_defer_fn (tree fn)
5642 : : {
5643 : 156777267 : if (expand_or_defer_fn_1 (fn))
5644 : : {
5645 : 56874736 : function_depth++;
5646 : :
5647 : : /* Expand or defer, at the whim of the compilation unit manager. */
5648 : 56874736 : cgraph_node::finalize_function (fn, function_depth > 1);
5649 : 56874736 : emit_associated_thunks (fn);
5650 : :
5651 : 56874736 : function_depth--;
5652 : :
5653 : 113749472 : if (DECL_IMMEDIATE_FUNCTION_P (fn))
5654 : : {
5655 : 1355039 : if (cgraph_node *node = cgraph_node::get (fn))
5656 : : {
5657 : 1355039 : node->body_removed = true;
5658 : 1355039 : node->analyzed = false;
5659 : 1355039 : node->definition = false;
5660 : 1355039 : node->force_output = false;
5661 : : }
5662 : : }
5663 : : }
5664 : 156777267 : }
5665 : :
5666 : 508966 : class nrv_data
5667 : : {
5668 : : public:
5669 : 254483 : nrv_data () : visited (37) {}
5670 : :
5671 : : tree var;
5672 : : tree result;
5673 : : hash_set<tree> visited;
5674 : : bool simple;
5675 : : bool in_nrv_cleanup;
5676 : : };
5677 : :
5678 : : /* Helper function for walk_tree, used by finalize_nrv below. */
5679 : :
5680 : : static tree
5681 : 27115647 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
5682 : : {
5683 : 27115647 : class nrv_data *dp = (class nrv_data *)data;
5684 : :
5685 : : /* No need to walk into types. There wouldn't be any need to walk into
5686 : : non-statements, except that we have to consider STMT_EXPRs. */
5687 : 27115647 : if (TYPE_P (*tp))
5688 : 202100 : *walk_subtrees = 0;
5689 : :
5690 : : /* Replace all uses of the NRV with the RESULT_DECL. */
5691 : 26913547 : else if (*tp == dp->var)
5692 : 578030 : *tp = dp->result;
5693 : :
5694 : : /* Avoid walking into the same tree more than once. Unfortunately, we
5695 : : can't just use walk_tree_without duplicates because it would only call
5696 : : us for the first occurrence of dp->var in the function body. */
5697 : 26335517 : else if (dp->visited.add (*tp))
5698 : 5792847 : *walk_subtrees = 0;
5699 : :
5700 : : /* If there's a label, we might need to destroy the NRV on goto (92407). */
5701 : 20542670 : else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
5702 : 3 : dp->simple = false;
5703 : : /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
5704 : : but differs from using NULL_TREE in that it indicates that we care
5705 : : about the value of the RESULT_DECL. But preserve anything appended
5706 : : by check_return_expr. */
5707 : 20542667 : else if (TREE_CODE (*tp) == RETURN_EXPR)
5708 : : {
5709 : 292537 : tree *p = &TREE_OPERAND (*tp, 0);
5710 : 756384 : while (TREE_CODE (*p) == COMPOUND_EXPR)
5711 : 171310 : p = &TREE_OPERAND (*p, 0);
5712 : 292537 : if (TREE_CODE (*p) == INIT_EXPR
5713 : 292537 : && INIT_EXPR_NRV_P (*p))
5714 : 292163 : *p = dp->result;
5715 : : }
5716 : : /* Change all cleanups for the NRV to only run when not returning. */
5717 : 20250130 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5718 : 20250130 : && CLEANUP_DECL (*tp) == dp->var)
5719 : : {
5720 : 134214 : dp->in_nrv_cleanup = true;
5721 : 134214 : cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
5722 : 134214 : dp->in_nrv_cleanup = false;
5723 : 134214 : cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
5724 : 134214 : *walk_subtrees = 0;
5725 : :
5726 : 134214 : if (dp->simple)
5727 : : /* For a simple NRV, just run it on the EH path. */
5728 : 133705 : CLEANUP_EH_ONLY (*tp) = true;
5729 : : else
5730 : : {
5731 : : /* Not simple, we need to check current_retval_sentinel to decide
5732 : : whether to run it. If it's set, we're returning normally and
5733 : : don't want to destroy the NRV. If the sentinel is not set, we're
5734 : : leaving scope some other way, either by flowing off the end of its
5735 : : scope or throwing an exception. */
5736 : 1527 : tree cond = build3 (COND_EXPR, void_type_node,
5737 : 509 : current_retval_sentinel,
5738 : 509 : void_node, CLEANUP_EXPR (*tp));
5739 : 509 : CLEANUP_EXPR (*tp) = cond;
5740 : : }
5741 : :
5742 : : /* If a cleanup might throw, we need to clear current_retval_sentinel on
5743 : : the exception path, both so the check above succeeds and so an outer
5744 : : cleanup added by maybe_splice_retval_cleanup doesn't run. */
5745 : 134214 : if (cp_function_chain->throwing_cleanup)
5746 : : {
5747 : 214 : tree clear = build2 (MODIFY_EXPR, boolean_type_node,
5748 : : current_retval_sentinel,
5749 : : boolean_false_node);
5750 : 214 : if (dp->simple)
5751 : : {
5752 : : /* We're already only on the EH path, just prepend it. */
5753 : 204 : tree &exp = CLEANUP_EXPR (*tp);
5754 : 204 : exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
5755 : : }
5756 : : else
5757 : : {
5758 : : /* The cleanup runs on both normal and EH paths, we need another
5759 : : CLEANUP_STMT to clear the flag only on the EH path. */
5760 : 10 : tree &bod = CLEANUP_BODY (*tp);
5761 : 10 : bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
5762 : 10 : bod, clear, current_retval_sentinel);
5763 : 10 : CLEANUP_EH_ONLY (bod) = true;
5764 : : }
5765 : : }
5766 : : }
5767 : : /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
5768 : : want to destroy the retval before the variable goes out of scope. */
5769 : 20115916 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5770 : 21091 : && dp->in_nrv_cleanup
5771 : 20135862 : && CLEANUP_DECL (*tp) == dp->result)
5772 : 6 : CLEANUP_EXPR (*tp) = void_node;
5773 : : /* Replace the DECL_EXPR for the NRV with an initialization of the
5774 : : RESULT_DECL, if needed. */
5775 : 20115910 : else if (TREE_CODE (*tp) == DECL_EXPR
5776 : 20115910 : && DECL_EXPR_DECL (*tp) == dp->var)
5777 : : {
5778 : 254485 : tree init;
5779 : 254485 : if (DECL_INITIAL (dp->var)
5780 : 254485 : && DECL_INITIAL (dp->var) != error_mark_node)
5781 : 95544 : init = cp_build_init_expr (dp->result,
5782 : 95544 : DECL_INITIAL (dp->var));
5783 : : else
5784 : 158941 : init = build_empty_stmt (EXPR_LOCATION (*tp));
5785 : 254485 : DECL_INITIAL (dp->var) = NULL_TREE;
5786 : 254485 : SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
5787 : 254485 : *tp = init;
5788 : : }
5789 : :
5790 : : /* Keep iterating. */
5791 : 27115647 : return NULL_TREE;
5792 : : }
5793 : :
5794 : : /* Called from finish_function to implement the named return value
5795 : : optimization by overriding all the RETURN_EXPRs and pertinent
5796 : : CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5797 : : RESULT_DECL for the function. */
5798 : :
5799 : : void
5800 : 254483 : finalize_nrv (tree fndecl, tree var)
5801 : : {
5802 : 254483 : class nrv_data data;
5803 : 254483 : tree result = DECL_RESULT (fndecl);
5804 : :
5805 : : /* Copy name from VAR to RESULT. */
5806 : 254483 : DECL_NAME (result) = DECL_NAME (var);
5807 : : /* Don't forget that we take its address. */
5808 : 254483 : TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
5809 : : /* Finally set DECL_VALUE_EXPR to avoid assigning
5810 : : a stack slot at -O0 for the original var and debug info
5811 : : uses RESULT location for VAR. */
5812 : 254483 : SET_DECL_VALUE_EXPR (var, result);
5813 : 254483 : DECL_HAS_VALUE_EXPR_P (var) = 1;
5814 : :
5815 : 254483 : data.var = var;
5816 : 254483 : data.result = result;
5817 : 254483 : data.in_nrv_cleanup = false;
5818 : :
5819 : : /* This is simpler for variables declared in the outer scope of
5820 : : the function so we know that their lifetime always ends with a
5821 : : return; see g++.dg/opt/nrv6.C. */
5822 : 254483 : tree outer = outer_curly_brace_block (fndecl);
5823 : 254483 : data.simple = chain_member (var, BLOCK_VARS (outer));
5824 : :
5825 : 254483 : cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
5826 : 254483 : }
5827 : :
5828 : : /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5829 : :
5830 : : bool
5831 : 2236 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
5832 : : bool need_copy_ctor, bool need_copy_assignment,
5833 : : bool need_dtor)
5834 : : {
5835 : 2236 : int save_errorcount = errorcount;
5836 : 2236 : tree info, t;
5837 : :
5838 : : /* Always allocate 3 elements for simplicity. These are the
5839 : : function decls for the ctor, dtor, and assignment op.
5840 : : This layout is known to the three lang hooks,
5841 : : cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
5842 : : and cxx_omp_clause_assign_op. */
5843 : 2236 : info = make_tree_vec (3);
5844 : 2236 : CP_OMP_CLAUSE_INFO (c) = info;
5845 : :
5846 : 2236 : if (need_default_ctor || need_copy_ctor)
5847 : : {
5848 : 1652 : if (need_default_ctor)
5849 : 1254 : t = get_default_ctor (type);
5850 : : else
5851 : 398 : t = get_copy_ctor (type, tf_warning_or_error);
5852 : :
5853 : 1652 : if (t && !trivial_fn_p (t))
5854 : 1400 : TREE_VEC_ELT (info, 0) = t;
5855 : : }
5856 : :
5857 : 2236 : if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
5858 : 1632 : TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
5859 : :
5860 : 2236 : if (need_copy_assignment)
5861 : : {
5862 : 397 : t = get_copy_assign (type);
5863 : :
5864 : 397 : if (t && !trivial_fn_p (t))
5865 : 344 : TREE_VEC_ELT (info, 2) = t;
5866 : : }
5867 : :
5868 : 2236 : return errorcount != save_errorcount;
5869 : : }
5870 : :
5871 : : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
5872 : : FIELD_DECL, otherwise return DECL itself. */
5873 : :
5874 : : static tree
5875 : 26138 : omp_clause_decl_field (tree decl)
5876 : : {
5877 : 26138 : if (VAR_P (decl)
5878 : 18291 : && DECL_HAS_VALUE_EXPR_P (decl)
5879 : 359 : && DECL_ARTIFICIAL (decl)
5880 : 359 : && DECL_LANG_SPECIFIC (decl)
5881 : 26473 : && DECL_OMP_PRIVATIZED_MEMBER (decl))
5882 : : {
5883 : 328 : tree f = DECL_VALUE_EXPR (decl);
5884 : 328 : if (INDIRECT_REF_P (f))
5885 : 0 : f = TREE_OPERAND (f, 0);
5886 : 328 : if (TREE_CODE (f) == COMPONENT_REF)
5887 : : {
5888 : 328 : f = TREE_OPERAND (f, 1);
5889 : 328 : gcc_assert (TREE_CODE (f) == FIELD_DECL);
5890 : : return f;
5891 : : }
5892 : : }
5893 : : return NULL_TREE;
5894 : : }
5895 : :
5896 : : /* Adjust DECL if needed for printing using %qE. */
5897 : :
5898 : : static tree
5899 : 187 : omp_clause_printable_decl (tree decl)
5900 : : {
5901 : 0 : tree t = omp_clause_decl_field (decl);
5902 : 187 : if (t)
5903 : 45 : return t;
5904 : : return decl;
5905 : : }
5906 : :
5907 : : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
5908 : : VAR_DECL T that doesn't need a DECL_EXPR added, record it for
5909 : : privatization. */
5910 : :
5911 : : static void
5912 : 219 : omp_note_field_privatization (tree f, tree t)
5913 : : {
5914 : 219 : if (!omp_private_member_map)
5915 : 71 : omp_private_member_map = new hash_map<tree, tree>;
5916 : 219 : tree &v = omp_private_member_map->get_or_insert (f);
5917 : 219 : if (v == NULL_TREE)
5918 : : {
5919 : 146 : v = t;
5920 : 146 : omp_private_member_vec.safe_push (f);
5921 : : /* Signal that we don't want to create DECL_EXPR for this dummy var. */
5922 : 146 : omp_private_member_vec.safe_push (integer_zero_node);
5923 : : }
5924 : 219 : }
5925 : :
5926 : : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
5927 : : dummy VAR_DECL. */
5928 : :
5929 : : tree
5930 : 861 : omp_privatize_field (tree t, bool shared)
5931 : : {
5932 : 861 : tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
5933 : 861 : if (m == error_mark_node)
5934 : : return error_mark_node;
5935 : 861 : if (!omp_private_member_map && !shared)
5936 : 365 : omp_private_member_map = new hash_map<tree, tree>;
5937 : 861 : if (TYPE_REF_P (TREE_TYPE (t)))
5938 : : {
5939 : 123 : gcc_assert (INDIRECT_REF_P (m));
5940 : 123 : m = TREE_OPERAND (m, 0);
5941 : : }
5942 : 861 : tree vb = NULL_TREE;
5943 : 861 : tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
5944 : 861 : if (v == NULL_TREE)
5945 : : {
5946 : 770 : v = create_temporary_var (TREE_TYPE (m));
5947 : 770 : retrofit_lang_decl (v);
5948 : 770 : DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
5949 : 770 : SET_DECL_VALUE_EXPR (v, m);
5950 : 770 : DECL_HAS_VALUE_EXPR_P (v) = 1;
5951 : 770 : if (!shared)
5952 : 690 : omp_private_member_vec.safe_push (t);
5953 : : }
5954 : 861 : return v;
5955 : : }
5956 : :
5957 : : /* C++ specialisation of the c_omp_address_inspector class. */
5958 : :
5959 : : class cp_omp_address_inspector : public c_omp_address_inspector
5960 : : {
5961 : : public:
5962 : 30546 : cp_omp_address_inspector (location_t loc, tree t)
5963 : 30546 : : c_omp_address_inspector (loc, t)
5964 : : {
5965 : : }
5966 : :
5967 : 30546 : ~cp_omp_address_inspector ()
5968 : : {
5969 : 22251 : }
5970 : :
5971 : 129546 : bool processing_template_decl_p ()
5972 : : {
5973 : 129546 : return processing_template_decl;
5974 : : }
5975 : :
5976 : 0 : void emit_unmappable_type_notes (tree t)
5977 : : {
5978 : 0 : if (TREE_TYPE (t) != error_mark_node
5979 : 0 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
5980 : 0 : cxx_incomplete_type_inform (TREE_TYPE (t));
5981 : 0 : }
5982 : :
5983 : 1058 : tree convert_from_reference (tree x)
5984 : : {
5985 : 1058 : return ::convert_from_reference (x);
5986 : : }
5987 : :
5988 : 141 : tree build_array_ref (location_t loc, tree arr, tree idx)
5989 : : {
5990 : 141 : return ::build_array_ref (loc, arr, idx);
5991 : : }
5992 : :
5993 : 22193 : bool check_clause (tree clause)
5994 : : {
5995 : 22193 : if (TREE_CODE (orig) == COMPONENT_REF
5996 : 22193 : && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
5997 : : tf_warning_or_error))
5998 : : return false;
5999 : 22190 : if (!c_omp_address_inspector::check_clause (clause))
6000 : : return false;
6001 : : return true;
6002 : : }
6003 : : };
6004 : :
6005 : : /* Helper function for handle_omp_array_sections. Called recursively
6006 : : to handle multiple array-section-subscripts. C is the clause,
6007 : : T current expression (initially OMP_CLAUSE_DECL), which is either
6008 : : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
6009 : : expression if specified, TREE_VALUE length expression if specified,
6010 : : TREE_CHAIN is what it has been specified after, or some decl.
6011 : : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
6012 : : set to true if any of the array-section-subscript could have length
6013 : : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
6014 : : first array-section-subscript which is known not to have length
6015 : : of one. Given say:
6016 : : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
6017 : : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
6018 : : all are or may have length of 1, array-section-subscript [:2] is the
6019 : : first one known not to have length 1. For array-section-subscript
6020 : : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
6021 : : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
6022 : : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
6023 : : case though, as some lengths could be zero. */
6024 : :
6025 : : static tree
6026 : 20456 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
6027 : : bool &maybe_zero_len, unsigned int &first_non_one,
6028 : : enum c_omp_region_type ort)
6029 : : {
6030 : 20456 : tree ret, low_bound, length, type;
6031 : 20456 : bool openacc = (ort & C_ORT_ACC) != 0;
6032 : 20456 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
6033 : : {
6034 : 9270 : if (error_operand_p (t))
6035 : 6 : return error_mark_node;
6036 : :
6037 : 9264 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6038 : 9264 : tree t_refto = ai.maybe_unconvert_ref (t);
6039 : :
6040 : 9264 : if (!ai.check_clause (c))
6041 : 0 : return error_mark_node;
6042 : 9264 : else if (ai.component_access_p ()
6043 : 10652 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6044 : 64 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
6045 : 40 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
6046 : 1388 : t = ai.get_root_term (true);
6047 : : else
6048 : 7876 : t = ai.unconverted_ref_origin ();
6049 : 9264 : if (t == error_mark_node)
6050 : : return error_mark_node;
6051 : 9264 : ret = t_refto;
6052 : 9264 : if (TREE_CODE (t) == FIELD_DECL)
6053 : 33 : ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6054 : 9231 : else if (!VAR_P (t)
6055 : 2698 : && (openacc || !EXPR_P (t))
6056 : 2503 : && TREE_CODE (t) != PARM_DECL)
6057 : : {
6058 : 48 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6059 : : return NULL_TREE;
6060 : 30 : if (DECL_P (t))
6061 : 30 : error_at (OMP_CLAUSE_LOCATION (c),
6062 : : "%qD is not a variable in %qs clause", t,
6063 : 30 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6064 : : else
6065 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
6066 : : "%qE is not a variable in %qs clause", t,
6067 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6068 : 30 : return error_mark_node;
6069 : : }
6070 : 9183 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6071 : 8993 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6072 : 17249 : && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
6073 : : {
6074 : 17 : error_at (OMP_CLAUSE_LOCATION (c),
6075 : : "%qD is threadprivate variable in %qs clause", t,
6076 : 17 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6077 : 17 : return error_mark_node;
6078 : : }
6079 : 9199 : if (type_dependent_expression_p (ret))
6080 : : return NULL_TREE;
6081 : 8512 : ret = convert_from_reference (ret);
6082 : 8512 : return ret;
6083 : 9264 : }
6084 : :
6085 : 11186 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
6086 : 7383 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6087 : 6189 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6088 : 4905 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6089 : 13792 : && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
6090 : 43 : TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
6091 : 11186 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
6092 : : maybe_zero_len, first_non_one, ort);
6093 : 11186 : if (ret == error_mark_node || ret == NULL_TREE)
6094 : : return ret;
6095 : :
6096 : 10182 : type = TREE_TYPE (ret);
6097 : 10182 : low_bound = TREE_OPERAND (t, 1);
6098 : 10182 : length = TREE_OPERAND (t, 2);
6099 : 8235 : if ((low_bound && type_dependent_expression_p (low_bound))
6100 : 18334 : || (length && type_dependent_expression_p (length)))
6101 : 88 : return NULL_TREE;
6102 : :
6103 : 10094 : if (low_bound == error_mark_node || length == error_mark_node)
6104 : : return error_mark_node;
6105 : :
6106 : 10094 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
6107 : : {
6108 : 69 : error_at (OMP_CLAUSE_LOCATION (c),
6109 : : "low bound %qE of array section does not have integral type",
6110 : : low_bound);
6111 : 69 : return error_mark_node;
6112 : : }
6113 : 10025 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
6114 : : {
6115 : 63 : error_at (OMP_CLAUSE_LOCATION (c),
6116 : : "length %qE of array section does not have integral type",
6117 : : length);
6118 : 63 : return error_mark_node;
6119 : : }
6120 : 9962 : if (low_bound)
6121 : 8069 : low_bound = mark_rvalue_use (low_bound);
6122 : 9962 : if (length)
6123 : 9016 : length = mark_rvalue_use (length);
6124 : : /* We need to reduce to real constant-values for checks below. */
6125 : 9016 : if (length)
6126 : 9016 : length = fold_simple (length);
6127 : 9962 : if (low_bound)
6128 : 8069 : low_bound = fold_simple (low_bound);
6129 : 8069 : if (low_bound
6130 : 8069 : && TREE_CODE (low_bound) == INTEGER_CST
6131 : 15213 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6132 : 7144 : > TYPE_PRECISION (sizetype))
6133 : 0 : low_bound = fold_convert (sizetype, low_bound);
6134 : 9962 : if (length
6135 : 9016 : && TREE_CODE (length) == INTEGER_CST
6136 : 16967 : && TYPE_PRECISION (TREE_TYPE (length))
6137 : 7005 : > TYPE_PRECISION (sizetype))
6138 : 0 : length = fold_convert (sizetype, length);
6139 : 9962 : if (low_bound == NULL_TREE)
6140 : 1893 : low_bound = integer_zero_node;
6141 : :
6142 : 9962 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6143 : 9962 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
6144 : 5079 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
6145 : : {
6146 : 60 : if (length != integer_one_node)
6147 : : {
6148 : 36 : error_at (OMP_CLAUSE_LOCATION (c),
6149 : : "expected single pointer in %qs clause",
6150 : : user_omp_clause_code_name (c, openacc));
6151 : 36 : return error_mark_node;
6152 : : }
6153 : : }
6154 : 9926 : if (length != NULL_TREE)
6155 : : {
6156 : 9004 : if (!integer_nonzerop (length))
6157 : : {
6158 : 2058 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6159 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6160 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6161 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6162 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6163 : : {
6164 : 459 : if (integer_zerop (length))
6165 : : {
6166 : 28 : error_at (OMP_CLAUSE_LOCATION (c),
6167 : : "zero length array section in %qs clause",
6168 : 28 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6169 : 28 : return error_mark_node;
6170 : : }
6171 : : }
6172 : : else
6173 : 1599 : maybe_zero_len = true;
6174 : : }
6175 : 8976 : if (first_non_one == types.length ()
6176 : 8976 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
6177 : 3926 : first_non_one++;
6178 : : }
6179 : 9898 : if (TREE_CODE (type) == ARRAY_TYPE)
6180 : : {
6181 : 5461 : if (length == NULL_TREE
6182 : 5461 : && (TYPE_DOMAIN (type) == NULL_TREE
6183 : 850 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
6184 : : {
6185 : 30 : error_at (OMP_CLAUSE_LOCATION (c),
6186 : : "for unknown bound array type length expression must "
6187 : : "be specified");
6188 : 30 : return error_mark_node;
6189 : : }
6190 : 5431 : if (TREE_CODE (low_bound) == INTEGER_CST
6191 : 5431 : && tree_int_cst_sgn (low_bound) == -1)
6192 : : {
6193 : 153 : error_at (OMP_CLAUSE_LOCATION (c),
6194 : : "negative low bound in array section in %qs clause",
6195 : 153 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6196 : 153 : return error_mark_node;
6197 : : }
6198 : 5278 : if (length != NULL_TREE
6199 : 4476 : && TREE_CODE (length) == INTEGER_CST
6200 : 8836 : && tree_int_cst_sgn (length) == -1)
6201 : : {
6202 : 153 : error_at (OMP_CLAUSE_LOCATION (c),
6203 : : "negative length in array section in %qs clause",
6204 : 153 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6205 : 153 : return error_mark_node;
6206 : : }
6207 : 5125 : if (TYPE_DOMAIN (type)
6208 : 5031 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6209 : 10156 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
6210 : : == INTEGER_CST)
6211 : : {
6212 : 4635 : tree size
6213 : 4635 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6214 : 4635 : size = size_binop (PLUS_EXPR, size, size_one_node);
6215 : 4635 : if (TREE_CODE (low_bound) == INTEGER_CST)
6216 : : {
6217 : 3868 : if (tree_int_cst_lt (size, low_bound))
6218 : : {
6219 : 54 : error_at (OMP_CLAUSE_LOCATION (c),
6220 : : "low bound %qE above array section size "
6221 : : "in %qs clause", low_bound,
6222 : 54 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6223 : 54 : return error_mark_node;
6224 : : }
6225 : 3814 : if (tree_int_cst_equal (size, low_bound))
6226 : : {
6227 : 17 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6228 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6229 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6230 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6231 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6232 : : {
6233 : 17 : error_at (OMP_CLAUSE_LOCATION (c),
6234 : : "zero length array section in %qs clause",
6235 : 17 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6236 : 17 : return error_mark_node;
6237 : : }
6238 : 0 : maybe_zero_len = true;
6239 : : }
6240 : 3797 : else if (length == NULL_TREE
6241 : 1420 : && first_non_one == types.length ()
6242 : 4095 : && tree_int_cst_equal
6243 : 298 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6244 : : low_bound))
6245 : 195 : first_non_one++;
6246 : : }
6247 : 767 : else if (length == NULL_TREE)
6248 : : {
6249 : 20 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6250 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6251 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6252 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6253 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6254 : 13 : maybe_zero_len = true;
6255 : 40 : if (first_non_one == types.length ())
6256 : 17 : first_non_one++;
6257 : : }
6258 : 4564 : if (length && TREE_CODE (length) == INTEGER_CST)
6259 : : {
6260 : 3290 : if (tree_int_cst_lt (size, length))
6261 : : {
6262 : 57 : error_at (OMP_CLAUSE_LOCATION (c),
6263 : : "length %qE above array section size "
6264 : : "in %qs clause", length,
6265 : 57 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6266 : 57 : return error_mark_node;
6267 : : }
6268 : 3233 : if (TREE_CODE (low_bound) == INTEGER_CST)
6269 : : {
6270 : 2899 : tree lbpluslen
6271 : 2899 : = size_binop (PLUS_EXPR,
6272 : : fold_convert (sizetype, low_bound),
6273 : : fold_convert (sizetype, length));
6274 : 2899 : if (TREE_CODE (lbpluslen) == INTEGER_CST
6275 : 2899 : && tree_int_cst_lt (size, lbpluslen))
6276 : : {
6277 : 54 : error_at (OMP_CLAUSE_LOCATION (c),
6278 : : "high bound %qE above array section size "
6279 : : "in %qs clause", lbpluslen,
6280 : 54 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6281 : 54 : return error_mark_node;
6282 : : }
6283 : : }
6284 : : }
6285 : : }
6286 : 490 : else if (length == NULL_TREE)
6287 : : {
6288 : 1 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6289 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6290 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6291 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6292 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6293 : 0 : maybe_zero_len = true;
6294 : 2 : if (first_non_one == types.length ())
6295 : 1 : first_non_one++;
6296 : : }
6297 : :
6298 : : /* For [lb:] we will need to evaluate lb more than once. */
6299 : 3911 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6300 : : {
6301 : 650 : tree lb = cp_save_expr (low_bound);
6302 : 650 : if (lb != low_bound)
6303 : : {
6304 : 9 : TREE_OPERAND (t, 1) = lb;
6305 : 9 : low_bound = lb;
6306 : : }
6307 : : }
6308 : : }
6309 : 4437 : else if (TYPE_PTR_P (type))
6310 : : {
6311 : 4380 : if (length == NULL_TREE)
6312 : : {
6313 : 42 : if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
6314 : 36 : error_at (OMP_CLAUSE_LOCATION (c),
6315 : : "for array function parameter length expression "
6316 : : "must be specified");
6317 : : else
6318 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
6319 : : "for pointer type length expression must be specified");
6320 : 42 : return error_mark_node;
6321 : : }
6322 : 4338 : if (length != NULL_TREE
6323 : 4338 : && TREE_CODE (length) == INTEGER_CST
6324 : 3245 : && tree_int_cst_sgn (length) == -1)
6325 : : {
6326 : 84 : error_at (OMP_CLAUSE_LOCATION (c),
6327 : : "negative length in array section in %qs clause",
6328 : 84 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6329 : 84 : return error_mark_node;
6330 : : }
6331 : : /* If there is a pointer type anywhere but in the very first
6332 : : array-section-subscript, the array section could be non-contiguous. */
6333 : 4254 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6334 : 4212 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6335 : 7983 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
6336 : : {
6337 : : /* If any prior dimension has a non-one length, then deem this
6338 : : array section as non-contiguous. */
6339 : 158 : for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
6340 : 69 : d = TREE_OPERAND (d, 0))
6341 : : {
6342 : 89 : tree d_length = TREE_OPERAND (d, 2);
6343 : 89 : if (d_length == NULL_TREE || !integer_onep (d_length))
6344 : : {
6345 : 20 : error_at (OMP_CLAUSE_LOCATION (c),
6346 : : "array section is not contiguous in %qs clause",
6347 : 20 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6348 : 20 : return error_mark_node;
6349 : : }
6350 : : }
6351 : : }
6352 : : }
6353 : : else
6354 : : {
6355 : 57 : error_at (OMP_CLAUSE_LOCATION (c),
6356 : : "%qE does not have pointer or array type", ret);
6357 : 57 : return error_mark_node;
6358 : : }
6359 : 9177 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6360 : 8274 : types.safe_push (TREE_TYPE (ret));
6361 : : /* We will need to evaluate lb more than once. */
6362 : 9177 : tree lb = cp_save_expr (low_bound);
6363 : 9177 : if (lb != low_bound)
6364 : : {
6365 : 716 : TREE_OPERAND (t, 1) = lb;
6366 : 716 : low_bound = lb;
6367 : : }
6368 : : /* Temporarily disable -fstrong-eval-order for array reductions.
6369 : : The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
6370 : : is something the middle-end can't cope with and more importantly,
6371 : : it needs to be the actual base variable that is privatized, not some
6372 : : temporary assigned previous value of it. That, together with OpenMP
6373 : : saying how many times the side-effects are evaluated is unspecified,
6374 : : makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
6375 : 9177 : warning_sentinel s (flag_strong_eval_order,
6376 : 9177 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6377 : 8164 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6378 : 18473 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
6379 : 9177 : ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
6380 : : tf_warning_or_error);
6381 : 9177 : return ret;
6382 : 9177 : }
6383 : :
6384 : : /* Handle array sections for clause C. */
6385 : :
6386 : : static bool
6387 : 9270 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
6388 : : {
6389 : 9270 : bool maybe_zero_len = false;
6390 : 9270 : unsigned int first_non_one = 0;
6391 : 9270 : auto_vec<tree, 10> types;
6392 : 9270 : tree *tp = &OMP_CLAUSE_DECL (c);
6393 : 9270 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6394 : 8313 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6395 : 9476 : && OMP_ITERATOR_DECL_P (*tp))
6396 : 258 : tp = &TREE_VALUE (*tp);
6397 : 9270 : tree first = handle_omp_array_sections_1 (c, *tp, types,
6398 : : maybe_zero_len, first_non_one,
6399 : : ort);
6400 : 9270 : if (first == error_mark_node)
6401 : : return true;
6402 : 8300 : if (first == NULL_TREE)
6403 : : return false;
6404 : 7507 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6405 : 7507 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6406 : : {
6407 : 849 : tree t = *tp;
6408 : 849 : tree tem = NULL_TREE;
6409 : 849 : if (processing_template_decl)
6410 : : return false;
6411 : : /* Need to evaluate side effects in the length expressions
6412 : : if any. */
6413 : 750 : while (TREE_CODE (t) == TREE_LIST)
6414 : : {
6415 : 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
6416 : : {
6417 : 0 : if (tem == NULL_TREE)
6418 : : tem = TREE_VALUE (t);
6419 : : else
6420 : 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
6421 : 0 : TREE_VALUE (t), tem);
6422 : : }
6423 : 0 : t = TREE_CHAIN (t);
6424 : : }
6425 : 750 : if (tem)
6426 : 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
6427 : 750 : *tp = first;
6428 : : }
6429 : : else
6430 : : {
6431 : 6658 : unsigned int num = types.length (), i;
6432 : 6658 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
6433 : 6658 : tree condition = NULL_TREE;
6434 : :
6435 : 6658 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
6436 : 3 : maybe_zero_len = true;
6437 : 6658 : if (processing_template_decl && maybe_zero_len)
6438 : : return false;
6439 : :
6440 : 14006 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
6441 : 7426 : t = TREE_OPERAND (t, 0))
6442 : : {
6443 : 7497 : gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
6444 : :
6445 : 7497 : tree low_bound = TREE_OPERAND (t, 1);
6446 : 7497 : tree length = TREE_OPERAND (t, 2);
6447 : :
6448 : 7497 : i--;
6449 : 7497 : if (low_bound
6450 : 6114 : && TREE_CODE (low_bound) == INTEGER_CST
6451 : 13000 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6452 : 5503 : > TYPE_PRECISION (sizetype))
6453 : 0 : low_bound = fold_convert (sizetype, low_bound);
6454 : 7497 : if (length
6455 : 6978 : && TREE_CODE (length) == INTEGER_CST
6456 : 12583 : && TYPE_PRECISION (TREE_TYPE (length))
6457 : 5086 : > TYPE_PRECISION (sizetype))
6458 : 0 : length = fold_convert (sizetype, length);
6459 : 7497 : if (low_bound == NULL_TREE)
6460 : 1383 : low_bound = integer_zero_node;
6461 : 7497 : if (!maybe_zero_len && i > first_non_one)
6462 : : {
6463 : 629 : if (integer_nonzerop (low_bound))
6464 : 34 : goto do_warn_noncontiguous;
6465 : 595 : if (length != NULL_TREE
6466 : 273 : && TREE_CODE (length) == INTEGER_CST
6467 : 273 : && TYPE_DOMAIN (types[i])
6468 : 273 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
6469 : 868 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
6470 : : == INTEGER_CST)
6471 : : {
6472 : 273 : tree size;
6473 : 273 : size = size_binop (PLUS_EXPR,
6474 : : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6475 : : size_one_node);
6476 : 273 : if (!tree_int_cst_equal (length, size))
6477 : : {
6478 : 37 : do_warn_noncontiguous:
6479 : 142 : error_at (OMP_CLAUSE_LOCATION (c),
6480 : : "array section is not contiguous in %qs "
6481 : : "clause",
6482 : 71 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6483 : 71 : return true;
6484 : : }
6485 : : }
6486 : 558 : if (!processing_template_decl
6487 : 390 : && length != NULL_TREE
6488 : 723 : && TREE_SIDE_EFFECTS (length))
6489 : : {
6490 : 0 : if (side_effects == NULL_TREE)
6491 : : side_effects = length;
6492 : : else
6493 : 0 : side_effects = build2 (COMPOUND_EXPR,
6494 : 0 : TREE_TYPE (side_effects),
6495 : : length, side_effects);
6496 : : }
6497 : : }
6498 : 6868 : else if (processing_template_decl)
6499 : 698 : continue;
6500 : : else
6501 : : {
6502 : 6170 : tree l;
6503 : :
6504 : 6170 : if (i > first_non_one
6505 : 6170 : && ((length && integer_nonzerop (length))
6506 : 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6507 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6508 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
6509 : 0 : continue;
6510 : 6170 : if (length)
6511 : 6053 : l = fold_convert (sizetype, length);
6512 : : else
6513 : : {
6514 : 117 : l = size_binop (PLUS_EXPR,
6515 : : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6516 : : size_one_node);
6517 : 117 : l = size_binop (MINUS_EXPR, l,
6518 : : fold_convert (sizetype, low_bound));
6519 : : }
6520 : 6170 : if (i > first_non_one)
6521 : : {
6522 : 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
6523 : : size_zero_node);
6524 : 0 : if (condition == NULL_TREE)
6525 : : condition = l;
6526 : : else
6527 : 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
6528 : : l, condition);
6529 : : }
6530 : 6170 : else if (size == NULL_TREE)
6531 : : {
6532 : 5892 : size = size_in_bytes (TREE_TYPE (types[i]));
6533 : 5892 : tree eltype = TREE_TYPE (types[num - 1]);
6534 : 5961 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6535 : 69 : eltype = TREE_TYPE (eltype);
6536 : 5892 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6537 : 5142 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6538 : 10281 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6539 : 1599 : size = size_binop (EXACT_DIV_EXPR, size,
6540 : : size_in_bytes (eltype));
6541 : 5892 : size = size_binop (MULT_EXPR, size, l);
6542 : 5892 : if (condition)
6543 : 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
6544 : : size, size_zero_node);
6545 : : }
6546 : : else
6547 : 278 : size = size_binop (MULT_EXPR, size, l);
6548 : : }
6549 : : }
6550 : 6509 : if (!processing_template_decl)
6551 : : {
6552 : 5892 : if (side_effects)
6553 : 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
6554 : 5892 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6555 : 5142 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6556 : 10281 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6557 : : {
6558 : 1599 : size = size_binop (MINUS_EXPR, size, size_one_node);
6559 : 1599 : size = save_expr (size);
6560 : 1599 : tree index_type = build_index_type (size);
6561 : 1599 : tree eltype = TREE_TYPE (first);
6562 : 1628 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6563 : 29 : eltype = TREE_TYPE (eltype);
6564 : 1599 : tree type = build_array_type (eltype, index_type);
6565 : 1599 : tree ptype = build_pointer_type (eltype);
6566 : 1599 : if (TYPE_REF_P (TREE_TYPE (t))
6567 : 1599 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
6568 : 152 : t = convert_from_reference (t);
6569 : 1447 : else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6570 : 629 : t = build_fold_addr_expr (t);
6571 : 1599 : tree t2 = build_fold_addr_expr (first);
6572 : 1599 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6573 : : ptrdiff_type_node, t2);
6574 : 1599 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
6575 : : ptrdiff_type_node, t2,
6576 : 1599 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6577 : : ptrdiff_type_node, t));
6578 : 1599 : if (tree_fits_shwi_p (t2))
6579 : 1261 : t = build2 (MEM_REF, type, t,
6580 : 1261 : build_int_cst (ptype, tree_to_shwi (t2)));
6581 : : else
6582 : : {
6583 : 338 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6584 : : sizetype, t2);
6585 : 338 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
6586 : 338 : TREE_TYPE (t), t, t2);
6587 : 338 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
6588 : : }
6589 : 1599 : OMP_CLAUSE_DECL (c) = t;
6590 : 7491 : return false;
6591 : : }
6592 : 4293 : OMP_CLAUSE_DECL (c) = first;
6593 : 4293 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
6594 : : return false;
6595 : 4267 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
6596 : 4267 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
6597 : 3727 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
6598 : 3715 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
6599 : 4243 : OMP_CLAUSE_SIZE (c) = size;
6600 : 4267 : if (TREE_CODE (t) == FIELD_DECL)
6601 : 3 : t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6602 : :
6603 : 4267 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6604 : : return false;
6605 : :
6606 : 3739 : if (TREE_CODE (first) == INDIRECT_REF)
6607 : : {
6608 : : /* Detect and skip adding extra nodes for pointer-to-member
6609 : : mappings. These are unsupported for now. */
6610 : 2404 : tree tmp = TREE_OPERAND (first, 0);
6611 : :
6612 : 2404 : if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
6613 : 1911 : tmp = TREE_OPERAND (tmp, 0);
6614 : :
6615 : 2404 : if (TREE_CODE (tmp) == INDIRECT_REF)
6616 : 158 : tmp = TREE_OPERAND (tmp, 0);
6617 : :
6618 : 2404 : if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
6619 : : {
6620 : 463 : tree offset = TREE_OPERAND (tmp, 1);
6621 : 463 : STRIP_NOPS (offset);
6622 : 463 : if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
6623 : : {
6624 : 36 : sorry_at (OMP_CLAUSE_LOCATION (c),
6625 : : "pointer-to-member mapping %qE not supported",
6626 : 18 : OMP_CLAUSE_DECL (c));
6627 : 18 : return true;
6628 : : }
6629 : : }
6630 : : }
6631 : :
6632 : : /* FIRST represents the first item of data that we are mapping.
6633 : : E.g. if we're mapping an array, FIRST might resemble
6634 : : "foo.bar.myarray[0]". */
6635 : :
6636 : 3721 : auto_vec<omp_addr_token *, 10> addr_tokens;
6637 : :
6638 : 3721 : if (!omp_parse_expr (addr_tokens, first))
6639 : : return true;
6640 : :
6641 : 3721 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6642 : :
6643 : 3721 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
6644 : 3721 : if (nc != error_mark_node)
6645 : : {
6646 : 3721 : using namespace omp_addr_tokenizer;
6647 : :
6648 : 3721 : if (ai.maybe_zero_length_array_section (c))
6649 : 3697 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
6650 : :
6651 : : /* !!! If we're accessing a base decl via chained access
6652 : : methods (e.g. multiple indirections), duplicate clause
6653 : : detection won't work properly. Skip it in that case. */
6654 : 3721 : if ((addr_tokens[0]->type == STRUCTURE_BASE
6655 : 2704 : || addr_tokens[0]->type == ARRAY_BASE)
6656 : 3721 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
6657 : 3710 : && addr_tokens[1]->type == ACCESS_METHOD
6658 : 7431 : && omp_access_chain_p (addr_tokens, 1))
6659 : 216 : c = nc;
6660 : :
6661 : 3721 : return false;
6662 : : }
6663 : 7442 : }
6664 : : }
6665 : : return false;
6666 : 9270 : }
6667 : :
6668 : : /* Return identifier to look up for omp declare reduction. */
6669 : :
6670 : : tree
6671 : 7081 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
6672 : : {
6673 : 7081 : const char *p = NULL;
6674 : 7081 : const char *m = NULL;
6675 : 7081 : switch (reduction_code)
6676 : : {
6677 : 4188 : case PLUS_EXPR:
6678 : 4188 : case MULT_EXPR:
6679 : 4188 : case MINUS_EXPR:
6680 : 4188 : case BIT_AND_EXPR:
6681 : 4188 : case BIT_XOR_EXPR:
6682 : 4188 : case BIT_IOR_EXPR:
6683 : 4188 : case TRUTH_ANDIF_EXPR:
6684 : 4188 : case TRUTH_ORIF_EXPR:
6685 : 4188 : reduction_id = ovl_op_identifier (false, reduction_code);
6686 : 4188 : break;
6687 : : case MIN_EXPR:
6688 : : p = "min";
6689 : : break;
6690 : : case MAX_EXPR:
6691 : : p = "max";
6692 : : break;
6693 : : default:
6694 : : break;
6695 : : }
6696 : :
6697 : 4188 : if (p == NULL)
6698 : : {
6699 : 6917 : if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
6700 : 0 : return error_mark_node;
6701 : 6917 : p = IDENTIFIER_POINTER (reduction_id);
6702 : : }
6703 : :
6704 : 7081 : if (type != NULL_TREE)
6705 : 2031 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6706 : :
6707 : 7081 : const char prefix[] = "omp declare reduction ";
6708 : 7081 : size_t lenp = sizeof (prefix);
6709 : 7081 : if (strncmp (p, prefix, lenp - 1) == 0)
6710 : 2031 : lenp = 1;
6711 : 7081 : size_t len = strlen (p);
6712 : 7081 : size_t lenm = m ? strlen (m) + 1 : 0;
6713 : 7081 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6714 : 7081 : if (lenp > 1)
6715 : 5050 : memcpy (name, prefix, lenp - 1);
6716 : 7081 : memcpy (name + lenp - 1, p, len + 1);
6717 : 7081 : if (m)
6718 : : {
6719 : 2031 : name[lenp + len - 1] = '~';
6720 : 2031 : memcpy (name + lenp + len, m, lenm);
6721 : : }
6722 : 7081 : return get_identifier (name);
6723 : : }
6724 : :
6725 : : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
6726 : : FUNCTION_DECL or NULL_TREE if not found. */
6727 : :
6728 : : static tree
6729 : 1287 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
6730 : : vec<tree> *ambiguousp)
6731 : : {
6732 : 1287 : tree orig_id = id;
6733 : 1287 : tree baselink = NULL_TREE;
6734 : 1287 : if (identifier_p (id))
6735 : : {
6736 : 1259 : cp_id_kind idk;
6737 : 1259 : bool nonint_cst_expression_p;
6738 : 1259 : const char *error_msg;
6739 : 1259 : id = omp_reduction_id (ERROR_MARK, id, type);
6740 : 1259 : tree decl = lookup_name (id);
6741 : 1259 : if (decl == NULL_TREE)
6742 : 80 : decl = error_mark_node;
6743 : 1259 : id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
6744 : : &nonint_cst_expression_p, false, true, false,
6745 : : false, &error_msg, loc);
6746 : 1259 : if (idk == CP_ID_KIND_UNQUALIFIED
6747 : 1339 : && identifier_p (id))
6748 : : {
6749 : 80 : vec<tree, va_gc> *args = NULL;
6750 : 80 : vec_safe_push (args, build_reference_type (type));
6751 : 80 : id = perform_koenig_lookup (id, args, tf_none);
6752 : : }
6753 : : }
6754 : 28 : else if (TREE_CODE (id) == SCOPE_REF)
6755 : 28 : id = lookup_qualified_name (TREE_OPERAND (id, 0),
6756 : : omp_reduction_id (ERROR_MARK,
6757 : 28 : TREE_OPERAND (id, 1),
6758 : : type),
6759 : : LOOK_want::NORMAL, false);
6760 : 1287 : tree fns = id;
6761 : 1287 : id = NULL_TREE;
6762 : 1287 : if (fns && is_overloaded_fn (fns))
6763 : : {
6764 : 1213 : for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
6765 : : {
6766 : 1213 : tree fndecl = *iter;
6767 : 1213 : if (TREE_CODE (fndecl) == FUNCTION_DECL)
6768 : : {
6769 : 1213 : tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
6770 : 1213 : if (same_type_p (TREE_TYPE (argtype), type))
6771 : : {
6772 : 1213 : id = fndecl;
6773 : 1213 : break;
6774 : : }
6775 : : }
6776 : : }
6777 : :
6778 : 1213 : if (id && BASELINK_P (fns))
6779 : : {
6780 : 74 : if (baselinkp)
6781 : 0 : *baselinkp = fns;
6782 : : else
6783 : 74 : baselink = fns;
6784 : : }
6785 : : }
6786 : :
6787 : 1287 : if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
6788 : : {
6789 : 35 : auto_vec<tree> ambiguous;
6790 : 35 : tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
6791 : 35 : unsigned int ix;
6792 : 35 : if (ambiguousp == NULL)
6793 : 19 : ambiguousp = &ambiguous;
6794 : 73 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
6795 : : {
6796 : 52 : id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
6797 : : baselinkp ? baselinkp : &baselink,
6798 : : ambiguousp);
6799 : 38 : if (id == NULL_TREE)
6800 : 14 : continue;
6801 : 24 : if (!ambiguousp->is_empty ())
6802 : 3 : ambiguousp->safe_push (id);
6803 : 21 : else if (ret != NULL_TREE)
6804 : : {
6805 : 6 : ambiguousp->safe_push (ret);
6806 : 6 : ambiguousp->safe_push (id);
6807 : 6 : ret = NULL_TREE;
6808 : : }
6809 : : else
6810 : 15 : ret = id;
6811 : : }
6812 : 35 : if (ambiguousp != &ambiguous)
6813 : 16 : return ret;
6814 : 19 : if (!ambiguous.is_empty ())
6815 : : {
6816 : 6 : auto_diagnostic_group d;
6817 : 6 : const char *str = _("candidates are:");
6818 : 6 : unsigned int idx;
6819 : 6 : tree udr;
6820 : 6 : error_at (loc, "user defined reduction lookup is ambiguous");
6821 : 27 : FOR_EACH_VEC_ELT (ambiguous, idx, udr)
6822 : : {
6823 : 15 : inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
6824 : 15 : if (idx == 0)
6825 : 6 : str = get_spaces (str);
6826 : : }
6827 : 6 : ret = error_mark_node;
6828 : 6 : baselink = NULL_TREE;
6829 : 6 : }
6830 : 19 : id = ret;
6831 : 35 : }
6832 : 1271 : if (id && baselink)
6833 : 74 : perform_or_defer_access_check (BASELINK_BINFO (baselink),
6834 : : id, id, tf_warning_or_error);
6835 : : return id;
6836 : : }
6837 : :
6838 : : /* Return identifier to look up for omp declare mapper. */
6839 : :
6840 : : tree
6841 : 3860 : omp_mapper_id (tree mapper_id, tree type)
6842 : : {
6843 : 3860 : const char *p = NULL;
6844 : 3860 : const char *m = NULL;
6845 : :
6846 : 3860 : if (mapper_id == NULL_TREE)
6847 : : p = "";
6848 : 68 : else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
6849 : 68 : p = IDENTIFIER_POINTER (mapper_id);
6850 : : else
6851 : 0 : return error_mark_node;
6852 : :
6853 : 3860 : if (type != NULL_TREE)
6854 : 3858 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6855 : :
6856 : 3860 : const char prefix[] = "omp declare mapper ";
6857 : 3860 : size_t lenp = sizeof (prefix);
6858 : 3860 : if (strncmp (p, prefix, lenp - 1) == 0)
6859 : 2 : lenp = 1;
6860 : 3860 : size_t len = strlen (p);
6861 : 3860 : size_t lenm = m ? strlen (m) + 1 : 0;
6862 : 3860 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6863 : 3860 : memcpy (name, prefix, lenp - 1);
6864 : 3860 : memcpy (name + lenp - 1, p, len + 1);
6865 : 3860 : if (m)
6866 : : {
6867 : 3858 : name[lenp + len - 1] = '~';
6868 : 3858 : memcpy (name + lenp + len, m, lenm);
6869 : : }
6870 : 3860 : return get_identifier (name);
6871 : : }
6872 : :
6873 : : tree
6874 : 6934 : cxx_omp_mapper_lookup (tree id, tree type)
6875 : : {
6876 : 6934 : if (!RECORD_OR_UNION_TYPE_P (type))
6877 : : return NULL_TREE;
6878 : 3647 : id = omp_mapper_id (id, type);
6879 : 3647 : return lookup_name (id);
6880 : : }
6881 : :
6882 : : tree
6883 : 273 : cxx_omp_extract_mapper_directive (tree vardecl)
6884 : : {
6885 : 273 : gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
6886 : :
6887 : : /* Instantiate the decl if we haven't already. */
6888 : 273 : mark_used (vardecl);
6889 : 273 : tree body = DECL_INITIAL (vardecl);
6890 : :
6891 : 273 : if (TREE_CODE (body) == STATEMENT_LIST)
6892 : : {
6893 : 0 : tree_stmt_iterator tsi = tsi_start (body);
6894 : 0 : gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
6895 : 0 : tsi_next (&tsi);
6896 : 0 : body = tsi_stmt (tsi);
6897 : : }
6898 : :
6899 : 273 : gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
6900 : :
6901 : 273 : return body;
6902 : : }
6903 : :
6904 : : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
6905 : : nothing more complicated. */
6906 : :
6907 : : tree
6908 : 1510 : cxx_omp_map_array_section (location_t loc, tree t)
6909 : : {
6910 : 1510 : tree low = TREE_OPERAND (t, 1);
6911 : 1510 : tree len = TREE_OPERAND (t, 2);
6912 : :
6913 : 1510 : if (len && integer_onep (len))
6914 : : {
6915 : 237 : t = TREE_OPERAND (t, 0);
6916 : :
6917 : 237 : if (!low)
6918 : 9 : low = integer_zero_node;
6919 : :
6920 : 237 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
6921 : 5 : t = convert_from_reference (t);
6922 : :
6923 : 237 : t = build_array_ref (loc, t, low);
6924 : : }
6925 : :
6926 : 1510 : return t;
6927 : : }
6928 : :
6929 : : /* Helper function for cp_parser_omp_declare_reduction_exprs
6930 : : and tsubst_omp_udr.
6931 : : Remove CLEANUP_STMT for data (omp_priv variable).
6932 : : Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
6933 : : DECL_EXPR. */
6934 : :
6935 : : tree
6936 : 4395 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
6937 : : {
6938 : 4395 : if (TYPE_P (*tp))
6939 : 227 : *walk_subtrees = 0;
6940 : 4168 : else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
6941 : 52 : *tp = CLEANUP_BODY (*tp);
6942 : 4116 : else if (TREE_CODE (*tp) == DECL_EXPR)
6943 : : {
6944 : 307 : tree decl = DECL_EXPR_DECL (*tp);
6945 : 307 : if (!processing_template_decl
6946 : 258 : && decl == (tree) data
6947 : 258 : && DECL_INITIAL (decl)
6948 : 399 : && DECL_INITIAL (decl) != error_mark_node)
6949 : : {
6950 : 92 : tree list = NULL_TREE;
6951 : 92 : append_to_statement_list_force (*tp, &list);
6952 : 92 : tree init_expr = build2 (INIT_EXPR, void_type_node,
6953 : 92 : decl, DECL_INITIAL (decl));
6954 : 92 : DECL_INITIAL (decl) = NULL_TREE;
6955 : 92 : append_to_statement_list_force (init_expr, &list);
6956 : 92 : *tp = list;
6957 : : }
6958 : : }
6959 : 4395 : return NULL_TREE;
6960 : : }
6961 : :
6962 : : /* Data passed from cp_check_omp_declare_reduction to
6963 : : cp_check_omp_declare_reduction_r. */
6964 : :
6965 : : struct cp_check_omp_declare_reduction_data
6966 : : {
6967 : : location_t loc;
6968 : : tree stmts[7];
6969 : : bool combiner_p;
6970 : : };
6971 : :
6972 : : /* Helper function for cp_check_omp_declare_reduction, called via
6973 : : cp_walk_tree. */
6974 : :
6975 : : static tree
6976 : 14949 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
6977 : : {
6978 : 14949 : struct cp_check_omp_declare_reduction_data *udr_data
6979 : : = (struct cp_check_omp_declare_reduction_data *) data;
6980 : 14949 : if (SSA_VAR_P (*tp)
6981 : 2687 : && !DECL_ARTIFICIAL (*tp)
6982 : 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
6983 : 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
6984 : : {
6985 : 135 : location_t loc = udr_data->loc;
6986 : 135 : if (udr_data->combiner_p)
6987 : 45 : error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
6988 : : "variable %qD which is not %<omp_out%> nor %<omp_in%>",
6989 : : *tp);
6990 : : else
6991 : 90 : error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
6992 : : "to variable %qD which is not %<omp_priv%> nor "
6993 : : "%<omp_orig%>",
6994 : : *tp);
6995 : 135 : return *tp;
6996 : : }
6997 : : return NULL_TREE;
6998 : : }
6999 : :
7000 : : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
7001 : :
7002 : : bool
7003 : 1099 : cp_check_omp_declare_reduction (tree udr)
7004 : : {
7005 : 1099 : tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
7006 : 1099 : gcc_assert (TYPE_REF_P (type));
7007 : 1099 : type = TREE_TYPE (type);
7008 : 1099 : int i;
7009 : 1099 : location_t loc = DECL_SOURCE_LOCATION (udr);
7010 : :
7011 : 1099 : if (type == error_mark_node)
7012 : : return false;
7013 : 1099 : if (ARITHMETIC_TYPE_P (type))
7014 : : {
7015 : : static enum tree_code predef_codes[]
7016 : : = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
7017 : : BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
7018 : 3276 : for (i = 0; i < 8; i++)
7019 : : {
7020 : 2918 : tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
7021 : 2918 : const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
7022 : 2918 : const char *n2 = IDENTIFIER_POINTER (id);
7023 : 2918 : if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
7024 : 2918 : && (n1[IDENTIFIER_LENGTH (id)] == '~'
7025 : 0 : || n1[IDENTIFIER_LENGTH (id)] == '\0'))
7026 : : break;
7027 : : }
7028 : :
7029 : 376 : if (i == 8
7030 : 358 : && TREE_CODE (type) != COMPLEX_EXPR)
7031 : : {
7032 : 358 : const char prefix_minmax[] = "omp declare reduction m";
7033 : 358 : size_t prefix_size = sizeof (prefix_minmax) - 1;
7034 : 358 : const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
7035 : 358 : if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
7036 : : prefix_minmax, prefix_size) == 0
7037 : 10 : && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
7038 : 4 : || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
7039 : 368 : && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
7040 : 6 : i = 0;
7041 : : }
7042 : 376 : if (i < 8)
7043 : : {
7044 : 24 : error_at (loc, "predeclared arithmetic type %qT in "
7045 : : "%<#pragma omp declare reduction%>", type);
7046 : 24 : return false;
7047 : : }
7048 : : }
7049 : : else if (FUNC_OR_METHOD_TYPE_P (type)
7050 : : || TREE_CODE (type) == ARRAY_TYPE)
7051 : : {
7052 : 24 : error_at (loc, "function or array type %qT in "
7053 : : "%<#pragma omp declare reduction%>", type);
7054 : 24 : return false;
7055 : : }
7056 : : else if (TYPE_REF_P (type))
7057 : : {
7058 : 0 : error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
7059 : : type);
7060 : 0 : return false;
7061 : : }
7062 : 699 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
7063 : : {
7064 : 24 : error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
7065 : : "type %qT in %<#pragma omp declare reduction%>", type);
7066 : 24 : return false;
7067 : : }
7068 : :
7069 : 1027 : tree body = DECL_SAVED_TREE (udr);
7070 : 1027 : if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
7071 : : return true;
7072 : :
7073 : 841 : tree_stmt_iterator tsi;
7074 : 841 : struct cp_check_omp_declare_reduction_data data;
7075 : 841 : memset (data.stmts, 0, sizeof data.stmts);
7076 : 841 : for (i = 0, tsi = tsi_start (body);
7077 : 4675 : i < 7 && !tsi_end_p (tsi);
7078 : 3834 : i++, tsi_next (&tsi))
7079 : 3834 : data.stmts[i] = tsi_stmt (tsi);
7080 : 841 : data.loc = loc;
7081 : 841 : gcc_assert (tsi_end_p (tsi));
7082 : 841 : if (i >= 3)
7083 : : {
7084 : 841 : gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
7085 : : && TREE_CODE (data.stmts[1]) == DECL_EXPR);
7086 : 841 : if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
7087 : : return true;
7088 : 796 : data.combiner_p = true;
7089 : 796 : if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
7090 : : &data, NULL))
7091 : 45 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
7092 : : }
7093 : 796 : if (i >= 6)
7094 : : {
7095 : 336 : gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
7096 : : && TREE_CODE (data.stmts[4]) == DECL_EXPR);
7097 : 336 : data.combiner_p = false;
7098 : 336 : if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
7099 : : &data, NULL)
7100 : 336 : || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
7101 : : cp_check_omp_declare_reduction_r, &data, NULL))
7102 : 90 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */);
7103 : 336 : if (i == 7)
7104 : 198 : gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
7105 : : }
7106 : : return true;
7107 : : }
7108 : :
7109 : : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
7110 : : an inline call. But, remap
7111 : : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
7112 : : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
7113 : :
7114 : : static tree
7115 : 2197 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
7116 : : tree decl, tree placeholder)
7117 : : {
7118 : 2197 : copy_body_data id;
7119 : 2197 : hash_map<tree, tree> decl_map;
7120 : :
7121 : 2197 : decl_map.put (omp_decl1, placeholder);
7122 : 2197 : decl_map.put (omp_decl2, decl);
7123 : 2197 : memset (&id, 0, sizeof (id));
7124 : 2197 : id.src_fn = DECL_CONTEXT (omp_decl1);
7125 : 2197 : id.dst_fn = current_function_decl;
7126 : 2197 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
7127 : 2197 : id.decl_map = &decl_map;
7128 : :
7129 : 2197 : id.copy_decl = copy_decl_no_change;
7130 : 2197 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
7131 : 2197 : id.transform_new_cfg = true;
7132 : 2197 : id.transform_return_to_modify = false;
7133 : 2197 : id.eh_lp_nr = 0;
7134 : 2197 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
7135 : 2197 : return stmt;
7136 : 2197 : }
7137 : :
7138 : : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
7139 : : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
7140 : :
7141 : : static tree
7142 : 15438 : find_omp_placeholder_r (tree *tp, int *, void *data)
7143 : : {
7144 : 15438 : if (*tp == (tree) data)
7145 : 265 : return *tp;
7146 : : return NULL_TREE;
7147 : : }
7148 : :
7149 : : /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
7150 : : Return true if there is some error and the clause should be removed. */
7151 : :
7152 : : static bool
7153 : 8854 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
7154 : : {
7155 : 8854 : tree t = OMP_CLAUSE_DECL (c);
7156 : 8854 : bool predefined = false;
7157 : 8854 : if (TREE_CODE (t) == TREE_LIST)
7158 : : {
7159 : 0 : gcc_assert (processing_template_decl);
7160 : : return false;
7161 : : }
7162 : 8854 : tree type = TREE_TYPE (t);
7163 : 8854 : if (TREE_CODE (t) == MEM_REF)
7164 : 1596 : type = TREE_TYPE (type);
7165 : 8854 : if (TYPE_REF_P (type))
7166 : 527 : type = TREE_TYPE (type);
7167 : 8854 : if (TREE_CODE (type) == ARRAY_TYPE)
7168 : : {
7169 : 350 : tree oatype = type;
7170 : 350 : gcc_assert (TREE_CODE (t) != MEM_REF);
7171 : 703 : while (TREE_CODE (type) == ARRAY_TYPE)
7172 : 353 : type = TREE_TYPE (type);
7173 : 350 : if (!processing_template_decl)
7174 : : {
7175 : 255 : t = require_complete_type (t);
7176 : 255 : if (t == error_mark_node
7177 : 255 : || !complete_type_or_else (oatype, NULL_TREE))
7178 : 9 : return true;
7179 : 246 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
7180 : : TYPE_SIZE_UNIT (type));
7181 : 246 : if (integer_zerop (size))
7182 : : {
7183 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7184 : : "%qE in %<reduction%> clause is a zero size array",
7185 : : omp_clause_printable_decl (t));
7186 : 3 : return true;
7187 : : }
7188 : 243 : size = size_binop (MINUS_EXPR, size, size_one_node);
7189 : 243 : size = save_expr (size);
7190 : 243 : tree index_type = build_index_type (size);
7191 : 243 : tree atype = build_array_type (type, index_type);
7192 : 243 : tree ptype = build_pointer_type (type);
7193 : 243 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7194 : 146 : t = build_fold_addr_expr (t);
7195 : 243 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
7196 : 243 : OMP_CLAUSE_DECL (c) = t;
7197 : : }
7198 : : }
7199 : 8842 : if (type == error_mark_node)
7200 : : return true;
7201 : 8839 : else if (ARITHMETIC_TYPE_P (type))
7202 : 7590 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
7203 : : {
7204 : : case PLUS_EXPR:
7205 : : case MULT_EXPR:
7206 : : case MINUS_EXPR:
7207 : : case TRUTH_ANDIF_EXPR:
7208 : : case TRUTH_ORIF_EXPR:
7209 : : predefined = true;
7210 : : break;
7211 : 246 : case MIN_EXPR:
7212 : 246 : case MAX_EXPR:
7213 : 246 : if (TREE_CODE (type) == COMPLEX_TYPE)
7214 : : break;
7215 : : predefined = true;
7216 : : break;
7217 : 111 : case BIT_AND_EXPR:
7218 : 111 : case BIT_IOR_EXPR:
7219 : 111 : case BIT_XOR_EXPR:
7220 : 111 : if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
7221 : : break;
7222 : : predefined = true;
7223 : : break;
7224 : : default:
7225 : : break;
7226 : : }
7227 : 1249 : else if (TYPE_READONLY (type))
7228 : : {
7229 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
7230 : : "%qE has const type for %<reduction%>",
7231 : : omp_clause_printable_decl (t));
7232 : 9 : return true;
7233 : : }
7234 : 1240 : else if (!processing_template_decl)
7235 : : {
7236 : 1036 : t = require_complete_type (t);
7237 : 1036 : if (t == error_mark_node)
7238 : : return true;
7239 : 1036 : OMP_CLAUSE_DECL (c) = t;
7240 : : }
7241 : :
7242 : 1036 : if (predefined)
7243 : : {
7244 : 7368 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7245 : 7368 : return false;
7246 : : }
7247 : 1462 : else if (processing_template_decl)
7248 : : {
7249 : 213 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
7250 : : return true;
7251 : : return false;
7252 : : }
7253 : :
7254 : 1249 : tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7255 : :
7256 : 1249 : type = TYPE_MAIN_VARIANT (type);
7257 : 1249 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7258 : 1249 : if (id == NULL_TREE)
7259 : 924 : id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
7260 : : NULL_TREE, NULL_TREE);
7261 : 1249 : id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
7262 : 1249 : if (id)
7263 : : {
7264 : 1204 : if (id == error_mark_node)
7265 : : return true;
7266 : 1198 : mark_used (id);
7267 : 1198 : tree body = DECL_SAVED_TREE (id);
7268 : 1198 : if (!body)
7269 : : return true;
7270 : 1195 : if (TREE_CODE (body) == STATEMENT_LIST)
7271 : : {
7272 : 1195 : tree_stmt_iterator tsi;
7273 : 1195 : tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
7274 : 1195 : int i;
7275 : 1195 : tree stmts[7];
7276 : 1195 : tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
7277 : 1195 : atype = TREE_TYPE (atype);
7278 : 1195 : bool need_static_cast = !same_type_p (type, atype);
7279 : 1195 : memset (stmts, 0, sizeof stmts);
7280 : 1195 : for (i = 0, tsi = tsi_start (body);
7281 : 8514 : i < 7 && !tsi_end_p (tsi);
7282 : 7319 : i++, tsi_next (&tsi))
7283 : 7319 : stmts[i] = tsi_stmt (tsi);
7284 : 1195 : gcc_assert (tsi_end_p (tsi));
7285 : :
7286 : 1195 : if (i >= 3)
7287 : : {
7288 : 1195 : gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
7289 : : && TREE_CODE (stmts[1]) == DECL_EXPR);
7290 : 1195 : placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
7291 : 1195 : DECL_ARTIFICIAL (placeholder) = 1;
7292 : 1195 : DECL_IGNORED_P (placeholder) = 1;
7293 : 1195 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
7294 : 1195 : if (TREE_CODE (t) == MEM_REF)
7295 : : {
7296 : 600 : decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
7297 : : type);
7298 : 600 : DECL_ARTIFICIAL (decl_placeholder) = 1;
7299 : 600 : DECL_IGNORED_P (decl_placeholder) = 1;
7300 : 600 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
7301 : : }
7302 : 1195 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
7303 : 285 : cxx_mark_addressable (placeholder);
7304 : 1195 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
7305 : 1195 : && (decl_placeholder
7306 : 149 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7307 : 372 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7308 : 118 : : OMP_CLAUSE_DECL (c));
7309 : 1195 : tree omp_out = placeholder;
7310 : 1195 : tree omp_in = decl_placeholder ? decl_placeholder
7311 : 595 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7312 : 1195 : if (need_static_cast)
7313 : : {
7314 : 7 : tree rtype = build_reference_type (atype);
7315 : 7 : omp_out = build_static_cast (input_location,
7316 : : rtype, omp_out,
7317 : : tf_warning_or_error);
7318 : 7 : omp_in = build_static_cast (input_location,
7319 : : rtype, omp_in,
7320 : : tf_warning_or_error);
7321 : 7 : if (omp_out == error_mark_node || omp_in == error_mark_node)
7322 : 3 : return true;
7323 : 7 : omp_out = convert_from_reference (omp_out);
7324 : 7 : omp_in = convert_from_reference (omp_in);
7325 : : }
7326 : 1195 : OMP_CLAUSE_REDUCTION_MERGE (c)
7327 : 1195 : = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
7328 : 1195 : DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
7329 : : }
7330 : 1195 : if (i >= 6)
7331 : : {
7332 : 1005 : gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
7333 : : && TREE_CODE (stmts[4]) == DECL_EXPR);
7334 : 1005 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
7335 : 1005 : && (decl_placeholder
7336 : 232 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7337 : 844 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7338 : 170 : : OMP_CLAUSE_DECL (c));
7339 : 1005 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
7340 : 216 : cxx_mark_addressable (placeholder);
7341 : 1005 : tree omp_priv = decl_placeholder ? decl_placeholder
7342 : 429 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7343 : 1005 : tree omp_orig = placeholder;
7344 : 1005 : if (need_static_cast)
7345 : : {
7346 : 5 : if (i == 7)
7347 : : {
7348 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
7349 : : "user defined reduction with constructor "
7350 : : "initializer for base class %qT", atype);
7351 : 3 : return true;
7352 : : }
7353 : 2 : tree rtype = build_reference_type (atype);
7354 : 2 : omp_priv = build_static_cast (input_location,
7355 : : rtype, omp_priv,
7356 : : tf_warning_or_error);
7357 : 2 : omp_orig = build_static_cast (input_location,
7358 : : rtype, omp_orig,
7359 : : tf_warning_or_error);
7360 : 2 : if (omp_priv == error_mark_node
7361 : 2 : || omp_orig == error_mark_node)
7362 : : return true;
7363 : 2 : omp_priv = convert_from_reference (omp_priv);
7364 : 2 : omp_orig = convert_from_reference (omp_orig);
7365 : : }
7366 : 1002 : if (i == 6)
7367 : 286 : *need_default_ctor = true;
7368 : 1002 : OMP_CLAUSE_REDUCTION_INIT (c)
7369 : 1002 : = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
7370 : 1002 : DECL_EXPR_DECL (stmts[3]),
7371 : : omp_priv, omp_orig);
7372 : 1002 : if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
7373 : : find_omp_placeholder_r, placeholder, NULL))
7374 : 238 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
7375 : : }
7376 : 190 : else if (i >= 3)
7377 : : {
7378 : 190 : if (CLASS_TYPE_P (type) && !pod_type_p (type))
7379 : 175 : *need_default_ctor = true;
7380 : : else
7381 : : {
7382 : 15 : tree init;
7383 : 15 : tree v = decl_placeholder ? decl_placeholder
7384 : 15 : : convert_from_reference (t);
7385 : 15 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
7386 : 6 : init = build_constructor (TREE_TYPE (v), NULL);
7387 : : else
7388 : 9 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
7389 : 30 : OMP_CLAUSE_REDUCTION_INIT (c)
7390 : 30 : = cp_build_init_expr (v, init);
7391 : : }
7392 : : }
7393 : : }
7394 : : }
7395 : 1237 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7396 : 1192 : *need_dtor = true;
7397 : : else
7398 : : {
7399 : 90 : error_at (OMP_CLAUSE_LOCATION (c),
7400 : : "user defined reduction not found for %qE",
7401 : : omp_clause_printable_decl (t));
7402 : 45 : return true;
7403 : : }
7404 : 1192 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7405 : 600 : gcc_assert (TYPE_SIZE_UNIT (type)
7406 : : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
7407 : : return false;
7408 : : }
7409 : :
7410 : : /* Check an instance of an "omp declare mapper" function. */
7411 : :
7412 : : bool
7413 : 179 : cp_check_omp_declare_mapper (tree udm)
7414 : : {
7415 : 179 : tree type = TREE_TYPE (udm);
7416 : 179 : location_t loc = DECL_SOURCE_LOCATION (udm);
7417 : :
7418 : 179 : if (type == error_mark_node)
7419 : : return false;
7420 : :
7421 : 179 : if (!processing_template_decl && !RECORD_OR_UNION_TYPE_P (type))
7422 : : {
7423 : 15 : error_at (loc, "%qT is not a struct, union or class type in "
7424 : : "%<#pragma omp declare mapper%>", type);
7425 : 15 : return false;
7426 : : }
7427 : 164 : if (!processing_template_decl && CLASSTYPE_VBASECLASSES (type))
7428 : : {
7429 : 3 : error_at (loc, "%qT must not be a virtual base class in "
7430 : : "%<#pragma omp declare mapper%>", type);
7431 : 3 : return false;
7432 : : }
7433 : :
7434 : : return true;
7435 : : }
7436 : :
7437 : : /* Called from finish_struct_1. linear(this) or linear(this:step)
7438 : : clauses might not be finalized yet because the class has been incomplete
7439 : : when parsing #pragma omp declare simd methods. Fix those up now. */
7440 : :
7441 : : void
7442 : 117774 : finish_omp_declare_simd_methods (tree t)
7443 : : {
7444 : 117774 : if (processing_template_decl)
7445 : : return;
7446 : :
7447 : 802913 : for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
7448 : : {
7449 : 1134200 : if (TREE_CODE (x) == USING_DECL
7450 : 685139 : || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
7451 : 449061 : continue;
7452 : 236078 : tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
7453 : 236186 : if (!ods || !TREE_VALUE (ods))
7454 : 235970 : continue;
7455 : 366 : for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
7456 : 258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7457 : 66 : && integer_zerop (OMP_CLAUSE_DECL (c))
7458 : 18 : && OMP_CLAUSE_LINEAR_STEP (c)
7459 : 276 : && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
7460 : : {
7461 : 18 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
7462 : 18 : s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
7463 : 18 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
7464 : 18 : sizetype, s, TYPE_SIZE_UNIT (t));
7465 : 18 : OMP_CLAUSE_LINEAR_STEP (c) = s;
7466 : : }
7467 : : }
7468 : : }
7469 : :
7470 : : /* Adjust sink depend/doacross clause to take into account pointer offsets.
7471 : :
7472 : : Return TRUE if there was a problem processing the offset, and the
7473 : : whole clause should be removed. */
7474 : :
7475 : : static bool
7476 : 298 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
7477 : : {
7478 : 298 : tree t = OMP_CLAUSE_DECL (sink_clause);
7479 : 298 : gcc_assert (TREE_CODE (t) == TREE_LIST);
7480 : :
7481 : : /* Make sure we don't adjust things twice for templates. */
7482 : 298 : if (processing_template_decl)
7483 : : return false;
7484 : :
7485 : 671 : for (; t; t = TREE_CHAIN (t))
7486 : : {
7487 : 391 : tree decl = TREE_VALUE (t);
7488 : 391 : if (TYPE_PTR_P (TREE_TYPE (decl)))
7489 : : {
7490 : 6 : tree offset = TREE_PURPOSE (t);
7491 : 6 : bool neg = wi::neg_p (wi::to_wide (offset));
7492 : 6 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
7493 : 6 : decl = mark_rvalue_use (decl);
7494 : 6 : decl = convert_from_reference (decl);
7495 : 12 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
7496 : : neg ? MINUS_EXPR : PLUS_EXPR,
7497 : : decl, offset);
7498 : 6 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
7499 : : MINUS_EXPR, sizetype,
7500 : : fold_convert (sizetype, t2),
7501 : : fold_convert (sizetype, decl));
7502 : 6 : if (t2 == error_mark_node)
7503 : : return true;
7504 : 6 : TREE_PURPOSE (t) = t2;
7505 : : }
7506 : : }
7507 : : return false;
7508 : : }
7509 : :
7510 : : /* Finish OpenMP iterators ITER. Return true if they are errorneous
7511 : : and clauses containing them should be removed. */
7512 : :
7513 : : static bool
7514 : 610 : cp_omp_finish_iterators (tree iter)
7515 : : {
7516 : 610 : bool ret = false;
7517 : 1385 : for (tree it = iter; it; it = TREE_CHAIN (it))
7518 : : {
7519 : 775 : tree var = TREE_VEC_ELT (it, 0);
7520 : 775 : tree begin = TREE_VEC_ELT (it, 1);
7521 : 775 : tree end = TREE_VEC_ELT (it, 2);
7522 : 775 : tree step = TREE_VEC_ELT (it, 3);
7523 : 775 : tree orig_step;
7524 : 775 : tree type = TREE_TYPE (var);
7525 : 775 : location_t loc = DECL_SOURCE_LOCATION (var);
7526 : 775 : if (type == error_mark_node)
7527 : : {
7528 : 0 : ret = true;
7529 : 218 : continue;
7530 : : }
7531 : 775 : if (type_dependent_expression_p (var))
7532 : 59 : continue;
7533 : 716 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
7534 : : {
7535 : 27 : error_at (loc, "iterator %qD has neither integral nor pointer type",
7536 : : var);
7537 : 27 : ret = true;
7538 : 27 : continue;
7539 : : }
7540 : 689 : else if (TYPE_READONLY (type))
7541 : : {
7542 : 24 : error_at (loc, "iterator %qD has const qualified type", var);
7543 : 24 : ret = true;
7544 : 24 : continue;
7545 : : }
7546 : 665 : if (type_dependent_expression_p (begin)
7547 : 656 : || type_dependent_expression_p (end)
7548 : 1321 : || type_dependent_expression_p (step))
7549 : 15 : continue;
7550 : 650 : else if (error_operand_p (step))
7551 : : {
7552 : 0 : ret = true;
7553 : 0 : continue;
7554 : : }
7555 : 650 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
7556 : : {
7557 : 33 : error_at (EXPR_LOC_OR_LOC (step, loc),
7558 : : "iterator step with non-integral type");
7559 : 21 : ret = true;
7560 : 21 : continue;
7561 : : }
7562 : :
7563 : 629 : begin = mark_rvalue_use (begin);
7564 : 629 : end = mark_rvalue_use (end);
7565 : 629 : step = mark_rvalue_use (step);
7566 : 629 : begin = cp_build_c_cast (input_location, type, begin,
7567 : : tf_warning_or_error);
7568 : 629 : end = cp_build_c_cast (input_location, type, end,
7569 : : tf_warning_or_error);
7570 : 629 : orig_step = step;
7571 : 629 : if (!processing_template_decl)
7572 : 552 : step = orig_step = save_expr (step);
7573 : 629 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
7574 : 629 : step = cp_build_c_cast (input_location, stype, step,
7575 : : tf_warning_or_error);
7576 : 629 : if (POINTER_TYPE_P (type) && !processing_template_decl)
7577 : : {
7578 : 66 : begin = save_expr (begin);
7579 : 66 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
7580 : 66 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
7581 : : fold_convert (sizetype, step),
7582 : : fold_convert (sizetype, begin));
7583 : 66 : step = fold_convert (ssizetype, step);
7584 : : }
7585 : 629 : if (!processing_template_decl)
7586 : : {
7587 : 552 : begin = maybe_constant_value (begin);
7588 : 552 : end = maybe_constant_value (end);
7589 : 552 : step = maybe_constant_value (step);
7590 : 552 : orig_step = maybe_constant_value (orig_step);
7591 : : }
7592 : 629 : if (integer_zerop (step))
7593 : : {
7594 : 27 : error_at (loc, "iterator %qD has zero step", var);
7595 : 27 : ret = true;
7596 : 27 : continue;
7597 : : }
7598 : :
7599 : 602 : if (begin == error_mark_node
7600 : 593 : || end == error_mark_node
7601 : 584 : || step == error_mark_node
7602 : 584 : || orig_step == error_mark_node)
7603 : : {
7604 : 18 : ret = true;
7605 : 18 : continue;
7606 : : }
7607 : :
7608 : 584 : if (!processing_template_decl)
7609 : : {
7610 : 507 : begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
7611 : 507 : end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
7612 : 507 : step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
7613 : 507 : orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
7614 : : orig_step);
7615 : : }
7616 : 584 : hash_set<tree> pset;
7617 : 584 : tree it2;
7618 : 740 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
7619 : : {
7620 : 183 : tree var2 = TREE_VEC_ELT (it2, 0);
7621 : 183 : tree begin2 = TREE_VEC_ELT (it2, 1);
7622 : 183 : tree end2 = TREE_VEC_ELT (it2, 2);
7623 : 183 : tree step2 = TREE_VEC_ELT (it2, 3);
7624 : 183 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
7625 : 183 : if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
7626 : : {
7627 : 9 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
7628 : : "begin expression refers to outer iterator %qD", var);
7629 : 36 : break;
7630 : : }
7631 : 174 : else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
7632 : : {
7633 : 9 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
7634 : : "end expression refers to outer iterator %qD", var);
7635 : 9 : break;
7636 : : }
7637 : 165 : else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
7638 : : {
7639 : 9 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
7640 : : "step expression refers to outer iterator %qD", var);
7641 : 9 : break;
7642 : : }
7643 : : }
7644 : 584 : if (it2)
7645 : : {
7646 : 27 : ret = true;
7647 : 27 : continue;
7648 : : }
7649 : 557 : TREE_VEC_ELT (it, 1) = begin;
7650 : 557 : TREE_VEC_ELT (it, 2) = end;
7651 : 557 : if (processing_template_decl)
7652 : 71 : TREE_VEC_ELT (it, 3) = orig_step;
7653 : : else
7654 : : {
7655 : 486 : TREE_VEC_ELT (it, 3) = step;
7656 : 486 : TREE_VEC_ELT (it, 4) = orig_step;
7657 : : }
7658 : 584 : }
7659 : 610 : return ret;
7660 : : }
7661 : :
7662 : : /* Ensure that pointers are used in OpenACC attach and detach clauses.
7663 : : Return true if an error has been detected. */
7664 : :
7665 : : static bool
7666 : 18293 : cp_oacc_check_attachments (tree c)
7667 : : {
7668 : 18293 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
7669 : : return false;
7670 : :
7671 : : /* OpenACC attach / detach clauses must be pointers. */
7672 : 14398 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
7673 : 14398 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
7674 : : {
7675 : 196 : tree t = OMP_CLAUSE_DECL (c);
7676 : 196 : tree type;
7677 : :
7678 : 232 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7679 : 36 : t = TREE_OPERAND (t, 0);
7680 : :
7681 : 196 : type = TREE_TYPE (t);
7682 : :
7683 : 196 : if (TREE_CODE (type) == REFERENCE_TYPE)
7684 : 36 : type = TREE_TYPE (type);
7685 : :
7686 : 196 : if (TREE_CODE (type) != POINTER_TYPE)
7687 : : {
7688 : 36 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
7689 : : user_omp_clause_code_name (c, true));
7690 : 36 : return true;
7691 : : }
7692 : : }
7693 : :
7694 : : return false;
7695 : : }
7696 : :
7697 : : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
7698 : : happened. */
7699 : :
7700 : : tree
7701 : 813 : cp_finish_omp_init_prefer_type (tree pref_type)
7702 : : {
7703 : 813 : if (processing_template_decl
7704 : 741 : || pref_type == NULL_TREE
7705 : 356 : || TREE_CODE (pref_type) != TREE_LIST)
7706 : : return pref_type;
7707 : :
7708 : 81 : tree t = TREE_PURPOSE (pref_type);
7709 : 81 : char *str = const_cast<char *> (TREE_STRING_POINTER (t));
7710 : 81 : tree fr_list = TREE_VALUE (pref_type);
7711 : 81 : int len = TREE_VEC_LENGTH (fr_list);
7712 : 81 : int cnt = 0;
7713 : :
7714 : 270 : while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
7715 : : {
7716 : 270 : str++;
7717 : 270 : if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
7718 : : {
7719 : : /* Assume a no or a single 'fr'. */
7720 : 150 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7721 : 150 : location_t loc = UNKNOWN_LOCATION;
7722 : 150 : tree value = TREE_VEC_ELT (fr_list, cnt);
7723 : 150 : if (value != NULL_TREE && value != error_mark_node)
7724 : : {
7725 : 126 : loc = EXPR_LOCATION (value);
7726 : 126 : if (value && TREE_CODE (value) == NOP_EXPR)
7727 : 39 : value = TREE_OPERAND (value, 0);
7728 : 126 : value = cp_fully_fold (value);
7729 : : }
7730 : 126 : if (value != NULL_TREE && value != error_mark_node)
7731 : : {
7732 : 126 : if (TREE_CODE (value) != INTEGER_CST
7733 : 126 : || !tree_fits_shwi_p (value))
7734 : 0 : error_at (loc,
7735 : : "expected string literal or "
7736 : : "constant integer expression instead of %qE", value);
7737 : : else
7738 : : {
7739 : 126 : HOST_WIDE_INT n = tree_to_shwi (value);
7740 : 126 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
7741 : : {
7742 : 48 : warning_at (loc, OPT_Wopenmp,
7743 : : "unknown foreign runtime identifier %qwd", n);
7744 : 48 : n = GOMP_INTEROP_IFR_UNKNOWN;
7745 : : }
7746 : 126 : str[0] = (char) n;
7747 : : }
7748 : : }
7749 : 150 : str++;
7750 : : }
7751 : 120 : else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
7752 : : {
7753 : : /* Assume a no or a single 'fr'. */
7754 : 120 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7755 : 120 : str++;
7756 : : }
7757 : 270 : str++;
7758 : 294 : while (str[0] != '\0')
7759 : 24 : str += strlen (str) + 1;
7760 : 270 : str++;
7761 : 270 : cnt++;
7762 : 270 : if (cnt >= len)
7763 : : break;
7764 : : }
7765 : : return t;
7766 : : }
7767 : :
7768 : : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
7769 : : Remove any elements from the list that are invalid. */
7770 : :
7771 : : tree
7772 : 62465 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
7773 : : {
7774 : 62465 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
7775 : 62465 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
7776 : 62465 : bitmap_head oacc_reduction_head, is_on_device_head;
7777 : 62465 : tree c, t, *pc;
7778 : 62465 : tree safelen = NULL_TREE;
7779 : 62465 : bool openacc = (ort & C_ORT_ACC) != 0;
7780 : 62465 : bool branch_seen = false;
7781 : 62465 : bool copyprivate_seen = false;
7782 : 62465 : bool ordered_seen = false;
7783 : 62465 : bool order_seen = false;
7784 : 62465 : bool schedule_seen = false;
7785 : 62465 : bool oacc_async = false;
7786 : 62465 : bool indir_component_ref_p = false;
7787 : 62465 : tree last_iterators = NULL_TREE;
7788 : 62465 : bool last_iterators_remove = false;
7789 : : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
7790 : : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
7791 : 62465 : int reduction_seen = 0;
7792 : 62465 : bool allocate_seen = false;
7793 : 62465 : tree detach_seen = NULL_TREE;
7794 : 62465 : bool mergeable_seen = false;
7795 : 62465 : bool implicit_moved = false;
7796 : 62465 : bool target_in_reduction_seen = false;
7797 : 62465 : bool num_tasks_seen = false;
7798 : 62465 : bool partial_seen = false;
7799 : 62465 : bool init_seen = false;
7800 : 62465 : bool init_use_destroy_seen = false;
7801 : 62465 : tree init_no_targetsync_clause = NULL_TREE;
7802 : 62465 : tree depend_clause = NULL_TREE;
7803 : :
7804 : 62465 : bitmap_obstack_initialize (NULL);
7805 : 62465 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
7806 : 62465 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
7807 : 62465 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
7808 : 62465 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
7809 : : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
7810 : 62465 : bitmap_initialize (&map_head, &bitmap_default_obstack);
7811 : 62465 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
7812 : 62465 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
7813 : : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
7814 : : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
7815 : 62465 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
7816 : 62465 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
7817 : :
7818 : 62465 : if (openacc)
7819 : 28277 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
7820 : 15933 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
7821 : : {
7822 : : oacc_async = true;
7823 : : break;
7824 : : }
7825 : :
7826 : 62465 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
7827 : :
7828 : 159944 : for (pc = &clauses, c = clauses; c ; c = *pc)
7829 : : {
7830 : 97479 : bool remove = false;
7831 : 97479 : bool field_ok = false;
7832 : :
7833 : : /* We've reached the end of a list of expanded nodes. Reset the group
7834 : : start pointer. */
7835 : 97479 : if (c == grp_sentinel)
7836 : : {
7837 : 5478 : if (grp_start_p
7838 : 5478 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
7839 : 96 : for (tree gc = *grp_start_p; gc != grp_sentinel;
7840 : 66 : gc = OMP_CLAUSE_CHAIN (gc))
7841 : 66 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
7842 : : grp_start_p = NULL;
7843 : : }
7844 : :
7845 : 97479 : switch (OMP_CLAUSE_CODE (c))
7846 : : {
7847 : 2100 : case OMP_CLAUSE_SHARED:
7848 : 2100 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7849 : 2100 : goto check_dup_generic;
7850 : 2547 : case OMP_CLAUSE_PRIVATE:
7851 : 2547 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7852 : 2547 : goto check_dup_generic;
7853 : 7336 : case OMP_CLAUSE_REDUCTION:
7854 : 7336 : if (reduction_seen == 0)
7855 : 6232 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
7856 : 1104 : else if (reduction_seen != -2
7857 : 2208 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
7858 : 1104 : ? -1 : 1))
7859 : : {
7860 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7861 : : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
7862 : : "on the same construct");
7863 : 6 : reduction_seen = -2;
7864 : : }
7865 : : /* FALLTHRU */
7866 : 9481 : case OMP_CLAUSE_IN_REDUCTION:
7867 : 9481 : case OMP_CLAUSE_TASK_REDUCTION:
7868 : 9481 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7869 : 9481 : t = OMP_CLAUSE_DECL (c);
7870 : 9481 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7871 : : {
7872 : 2207 : if (handle_omp_array_sections (c, ort))
7873 : : {
7874 : : remove = true;
7875 : : break;
7876 : : }
7877 : 2165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
7878 : 2165 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
7879 : : {
7880 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
7881 : : "%<inscan%> %<reduction%> clause with array "
7882 : : "section");
7883 : 3 : remove = true;
7884 : 3 : break;
7885 : : }
7886 : 2162 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7887 : : {
7888 : 4672 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7889 : 2510 : t = TREE_OPERAND (t, 0);
7890 : : }
7891 : : else
7892 : : {
7893 : 0 : gcc_assert (TREE_CODE (t) == MEM_REF);
7894 : 0 : t = TREE_OPERAND (t, 0);
7895 : 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
7896 : 0 : t = TREE_OPERAND (t, 0);
7897 : 0 : if (TREE_CODE (t) == ADDR_EXPR
7898 : 0 : || INDIRECT_REF_P (t))
7899 : 0 : t = TREE_OPERAND (t, 0);
7900 : : }
7901 : 2162 : tree n = omp_clause_decl_field (t);
7902 : 2162 : if (n)
7903 : 59 : t = n;
7904 : 2162 : goto check_dup_generic_t;
7905 : : }
7906 : 7274 : if (oacc_async)
7907 : 7 : cxx_mark_addressable (t);
7908 : 7274 : goto check_dup_generic;
7909 : 98 : case OMP_CLAUSE_COPYPRIVATE:
7910 : 98 : copyprivate_seen = true;
7911 : 98 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7912 : 98 : goto check_dup_generic;
7913 : 277 : case OMP_CLAUSE_COPYIN:
7914 : 277 : goto check_dup_generic;
7915 : 1631 : case OMP_CLAUSE_LINEAR:
7916 : 1631 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7917 : 1631 : t = OMP_CLAUSE_DECL (c);
7918 : 1631 : if (ort != C_ORT_OMP_DECLARE_SIMD
7919 : 1631 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
7920 : : {
7921 : 84 : if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
7922 : : {
7923 : 42 : error_at (OMP_CLAUSE_LOCATION (c),
7924 : : "modifier should not be specified in %<linear%> "
7925 : : "clause on %<simd%> or %<for%> constructs when "
7926 : : "not using OpenMP 5.2 modifiers");
7927 : 42 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
7928 : : }
7929 : 42 : else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
7930 : : {
7931 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
7932 : : "modifier other than %<val%> specified in "
7933 : : "%<linear%> clause on %<simd%> or %<for%> "
7934 : : "constructs when using OpenMP 5.2 modifiers");
7935 : 18 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
7936 : : }
7937 : : }
7938 : 1011 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
7939 : 2571 : && !type_dependent_expression_p (t))
7940 : : {
7941 : 1529 : tree type = TREE_TYPE (t);
7942 : 1529 : if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7943 : 1448 : || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
7944 : 1598 : && !TYPE_REF_P (type))
7945 : : {
7946 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
7947 : : "linear clause with %qs modifier applied to "
7948 : : "non-reference variable with %qT type",
7949 : 12 : OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7950 : 12 : ? "ref" : "uval", TREE_TYPE (t));
7951 : 12 : remove = true;
7952 : 12 : break;
7953 : : }
7954 : 1517 : if (TYPE_REF_P (type))
7955 : 281 : type = TREE_TYPE (type);
7956 : 1517 : if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
7957 : : {
7958 : 1442 : if (!INTEGRAL_TYPE_P (type)
7959 : 85 : && !TYPE_PTR_P (type))
7960 : : {
7961 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
7962 : : "linear clause applied to non-integral "
7963 : : "non-pointer variable with %qT type",
7964 : 18 : TREE_TYPE (t));
7965 : 18 : remove = true;
7966 : 18 : break;
7967 : : }
7968 : : }
7969 : : }
7970 : 1601 : t = OMP_CLAUSE_LINEAR_STEP (c);
7971 : 1601 : if (t == NULL_TREE)
7972 : 6 : t = integer_one_node;
7973 : 1601 : if (t == error_mark_node)
7974 : : {
7975 : : remove = true;
7976 : : break;
7977 : : }
7978 : 1601 : else if (!type_dependent_expression_p (t)
7979 : 1599 : && !INTEGRAL_TYPE_P (TREE_TYPE (t))
7980 : 1613 : && (ort != C_ORT_OMP_DECLARE_SIMD
7981 : 9 : || TREE_CODE (t) != PARM_DECL
7982 : 6 : || !TYPE_REF_P (TREE_TYPE (t))
7983 : 6 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
7984 : : {
7985 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7986 : : "linear step expression must be integral");
7987 : 6 : remove = true;
7988 : 6 : break;
7989 : : }
7990 : : else
7991 : : {
7992 : 1595 : t = mark_rvalue_use (t);
7993 : 1595 : if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
7994 : : {
7995 : 42 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
7996 : 42 : goto check_dup_generic;
7997 : : }
7998 : 1553 : if (!processing_template_decl
7999 : 1553 : && (VAR_P (OMP_CLAUSE_DECL (c))
8000 : 835 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
8001 : : {
8002 : 1372 : if (ort == C_ORT_OMP_DECLARE_SIMD)
8003 : : {
8004 : 589 : t = maybe_constant_value (t);
8005 : 589 : if (TREE_CODE (t) != INTEGER_CST)
8006 : : {
8007 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8008 : : "%<linear%> clause step %qE is neither "
8009 : : "constant nor a parameter", t);
8010 : 6 : remove = true;
8011 : 6 : break;
8012 : : }
8013 : : }
8014 : 1366 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8015 : 1366 : tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
8016 : 1366 : if (TYPE_REF_P (type))
8017 : 257 : type = TREE_TYPE (type);
8018 : 1366 : if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
8019 : : {
8020 : 66 : type = build_pointer_type (type);
8021 : 66 : tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
8022 : 66 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8023 : : d, t);
8024 : 66 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8025 : : MINUS_EXPR, sizetype,
8026 : : fold_convert (sizetype, t),
8027 : : fold_convert (sizetype, d));
8028 : 66 : if (t == error_mark_node)
8029 : : {
8030 : : remove = true;
8031 : : break;
8032 : : }
8033 : : }
8034 : 1300 : else if (TYPE_PTR_P (type)
8035 : : /* Can't multiply the step yet if *this
8036 : : is still incomplete type. */
8037 : 1300 : && (ort != C_ORT_OMP_DECLARE_SIMD
8038 : 45 : || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
8039 : 45 : || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
8040 : 30 : || DECL_NAME (OMP_CLAUSE_DECL (c))
8041 : 30 : != this_identifier
8042 : 30 : || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
8043 : : {
8044 : 37 : tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
8045 : 37 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8046 : : d, t);
8047 : 37 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8048 : : MINUS_EXPR, sizetype,
8049 : : fold_convert (sizetype, t),
8050 : : fold_convert (sizetype, d));
8051 : 37 : if (t == error_mark_node)
8052 : : {
8053 : : remove = true;
8054 : : break;
8055 : : }
8056 : : }
8057 : : else
8058 : 1263 : t = fold_convert (type, t);
8059 : : }
8060 : 1547 : OMP_CLAUSE_LINEAR_STEP (c) = t;
8061 : : }
8062 : 1547 : goto check_dup_generic;
8063 : 14850 : check_dup_generic:
8064 : 14850 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8065 : 14850 : if (t)
8066 : : {
8067 : 101 : if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
8068 : 101 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8069 : : }
8070 : : else
8071 : 14749 : t = OMP_CLAUSE_DECL (c);
8072 : 17278 : check_dup_generic_t:
8073 : 17278 : if (t == current_class_ptr
8074 : 17278 : && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
8075 : 102 : || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
8076 : 72 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
8077 : : {
8078 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
8079 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
8080 : : " clauses");
8081 : 24 : remove = true;
8082 : 24 : break;
8083 : : }
8084 : 17254 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8085 : 586 : && (!field_ok || TREE_CODE (t) != FIELD_DECL))
8086 : : {
8087 : 59 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8088 : : break;
8089 : 39 : if (DECL_P (t))
8090 : 30 : error_at (OMP_CLAUSE_LOCATION (c),
8091 : : "%qD is not a variable in clause %qs", t,
8092 : 15 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8093 : : else
8094 : 48 : error_at (OMP_CLAUSE_LOCATION (c),
8095 : : "%qE is not a variable in clause %qs", t,
8096 : 24 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8097 : : remove = true;
8098 : : }
8099 : 17195 : else if ((openacc
8100 : 2707 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
8101 : 14726 : || (ort == C_ORT_OMP
8102 : 12426 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
8103 : 12395 : || (OMP_CLAUSE_CODE (c)
8104 : : == OMP_CLAUSE_USE_DEVICE_ADDR)))
8105 : 31814 : || (ort == C_ORT_OMP_TARGET
8106 : 905 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
8107 : : {
8108 : 2854 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
8109 : 2854 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8110 : 275 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
8111 : : {
8112 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8113 : : "%qD appears more than once in data-sharing "
8114 : : "clauses", t);
8115 : 6 : remove = true;
8116 : 6 : break;
8117 : : }
8118 : 2848 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
8119 : 272 : target_in_reduction_seen = true;
8120 : 2848 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8121 : : {
8122 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8123 : : openacc
8124 : : ? "%qD appears more than once in reduction clauses"
8125 : : : "%qD appears more than once in data clauses",
8126 : : t);
8127 : 6 : remove = true;
8128 : : }
8129 : : else
8130 : 2842 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8131 : : }
8132 : 14341 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8133 : 14266 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8134 : 14263 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
8135 : 28604 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8136 : : {
8137 : 78 : error_at (OMP_CLAUSE_LOCATION (c),
8138 : : "%qD appears more than once in data clauses", t);
8139 : 78 : remove = true;
8140 : : }
8141 : 14263 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
8142 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
8143 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
8144 : 3084 : && bitmap_bit_p (&map_head, DECL_UID (t)))
8145 : : {
8146 : 9 : if (openacc)
8147 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8148 : : "%qD appears more than once in data clauses", t);
8149 : : else
8150 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
8151 : : "%qD appears both in data and map clauses", t);
8152 : : remove = true;
8153 : : }
8154 : : else
8155 : 14254 : bitmap_set_bit (&generic_head, DECL_UID (t));
8156 : 17228 : if (!field_ok)
8157 : : break;
8158 : 12821 : handle_field_decl:
8159 : 21261 : if (!remove
8160 : 21064 : && TREE_CODE (t) == FIELD_DECL
8161 : 16415 : && t == OMP_CLAUSE_DECL (c))
8162 : : {
8163 : 795 : OMP_CLAUSE_DECL (c)
8164 : 795 : = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
8165 : : == OMP_CLAUSE_SHARED));
8166 : 795 : if (OMP_CLAUSE_DECL (c) == error_mark_node)
8167 : 96978 : remove = true;
8168 : : }
8169 : : break;
8170 : :
8171 : 3447 : case OMP_CLAUSE_FIRSTPRIVATE:
8172 : 3447 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
8173 : : {
8174 : 447 : move_implicit:
8175 : 447 : implicit_moved = true;
8176 : : /* Move firstprivate and map clauses with
8177 : : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
8178 : : clauses chain. */
8179 : 447 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
8180 : 447 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
8181 : 2804 : while (*pc1)
8182 : 2357 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
8183 : 2357 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
8184 : : {
8185 : 275 : *pc3 = *pc1;
8186 : 275 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
8187 : 275 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8188 : : }
8189 : 2082 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
8190 : 2082 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
8191 : : {
8192 : 403 : *pc2 = *pc1;
8193 : 403 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
8194 : 403 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8195 : : }
8196 : : else
8197 : 1679 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
8198 : 447 : *pc3 = NULL;
8199 : 447 : *pc2 = cl2;
8200 : 447 : *pc1 = cl1;
8201 : 447 : continue;
8202 : 447 : }
8203 : 3190 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8204 : 3190 : if (t)
8205 : 69 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8206 : : else
8207 : 3121 : t = OMP_CLAUSE_DECL (c);
8208 : 3190 : if (!openacc && t == current_class_ptr)
8209 : : {
8210 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8211 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
8212 : : " clauses");
8213 : 6 : remove = true;
8214 : 6 : break;
8215 : : }
8216 : 3184 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8217 : 333 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8218 : 333 : || TREE_CODE (t) != FIELD_DECL))
8219 : : {
8220 : 41 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8221 : : break;
8222 : 18 : if (DECL_P (t))
8223 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8224 : : "%qD is not a variable in clause %<firstprivate%>",
8225 : : t);
8226 : : else
8227 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8228 : : "%qE is not a variable in clause %<firstprivate%>",
8229 : : t);
8230 : 18 : remove = true;
8231 : : }
8232 : 3143 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8233 : 275 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
8234 : 3397 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8235 : : remove = true;
8236 : 3143 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8237 : 3134 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8238 : 6274 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8239 : : {
8240 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
8241 : : "%qD appears more than once in data clauses", t);
8242 : 15 : remove = true;
8243 : : }
8244 : 3128 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8245 : 3128 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
8246 : : {
8247 : 21 : if (openacc)
8248 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8249 : : "%qD appears more than once in data clauses", t);
8250 : 21 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8251 : 21 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
8252 : : /* Silently drop the clause. */;
8253 : : else
8254 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
8255 : : "%qD appears both in data and map clauses", t);
8256 : 21 : remove = true;
8257 : : }
8258 : : else
8259 : 3107 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
8260 : 3161 : goto handle_field_decl;
8261 : :
8262 : 2790 : case OMP_CLAUSE_LASTPRIVATE:
8263 : 2790 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8264 : 2790 : if (t)
8265 : 35 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8266 : : else
8267 : 2755 : t = OMP_CLAUSE_DECL (c);
8268 : 2790 : if (!openacc && t == current_class_ptr)
8269 : : {
8270 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8271 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
8272 : : " clauses");
8273 : 6 : remove = true;
8274 : 6 : break;
8275 : : }
8276 : 2784 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8277 : 259 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8278 : 259 : || TREE_CODE (t) != FIELD_DECL))
8279 : : {
8280 : 35 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8281 : : break;
8282 : 9 : if (DECL_P (t))
8283 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8284 : : "%qD is not a variable in clause %<lastprivate%>",
8285 : : t);
8286 : : else
8287 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8288 : : "%qE is not a variable in clause %<lastprivate%>",
8289 : : t);
8290 : 9 : remove = true;
8291 : : }
8292 : 2749 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8293 : 2749 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8294 : : {
8295 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8296 : : "%qD appears more than once in data clauses", t);
8297 : 12 : remove = true;
8298 : : }
8299 : : else
8300 : 2737 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
8301 : 2758 : goto handle_field_decl;
8302 : :
8303 : 2218 : case OMP_CLAUSE_IF:
8304 : 2218 : case OMP_CLAUSE_SELF:
8305 : 2218 : t = OMP_CLAUSE_OPERAND (c, 0);
8306 : 2218 : t = maybe_convert_cond (t);
8307 : 2218 : if (t == error_mark_node)
8308 : : remove = true;
8309 : 2203 : else if (!processing_template_decl)
8310 : 2142 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8311 : 2218 : OMP_CLAUSE_OPERAND (c, 0) = t;
8312 : 2218 : break;
8313 : :
8314 : 289 : case OMP_CLAUSE_FINAL:
8315 : 289 : t = OMP_CLAUSE_FINAL_EXPR (c);
8316 : 289 : t = maybe_convert_cond (t);
8317 : 289 : if (t == error_mark_node)
8318 : : remove = true;
8319 : 289 : else if (!processing_template_decl)
8320 : 283 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8321 : 289 : OMP_CLAUSE_FINAL_EXPR (c) = t;
8322 : 289 : break;
8323 : :
8324 : 92 : case OMP_CLAUSE_NOCONTEXT:
8325 : 92 : t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
8326 : 92 : t = maybe_convert_cond (t);
8327 : 92 : if (t == error_mark_node)
8328 : : remove = true;
8329 : 89 : else if (!processing_template_decl)
8330 : 83 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8331 : 92 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
8332 : 92 : break;
8333 : :
8334 : 80 : case OMP_CLAUSE_NOVARIANTS:
8335 : 80 : t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
8336 : 80 : t = maybe_convert_cond (t);
8337 : 80 : if (t == error_mark_node)
8338 : : remove = true;
8339 : 77 : else if (!processing_template_decl)
8340 : 71 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8341 : 80 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
8342 : 80 : break;
8343 : :
8344 : 1249 : case OMP_CLAUSE_GANG:
8345 : : /* Operand 1 is the gang static: argument. */
8346 : 1249 : t = OMP_CLAUSE_OPERAND (c, 1);
8347 : 1249 : if (t != NULL_TREE)
8348 : : {
8349 : 129 : if (t == error_mark_node)
8350 : : remove = true;
8351 : 129 : else if (!type_dependent_expression_p (t)
8352 : 129 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8353 : : {
8354 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8355 : : "%<gang%> static expression must be integral");
8356 : 6 : remove = true;
8357 : : }
8358 : : else
8359 : : {
8360 : 123 : t = mark_rvalue_use (t);
8361 : 123 : if (!processing_template_decl)
8362 : : {
8363 : 123 : t = maybe_constant_value (t);
8364 : 123 : if (TREE_CODE (t) == INTEGER_CST
8365 : 109 : && tree_int_cst_sgn (t) != 1
8366 : 176 : && t != integer_minus_one_node)
8367 : : {
8368 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8369 : : "%<gang%> static value must be "
8370 : : "positive");
8371 : 0 : t = integer_one_node;
8372 : : }
8373 : 123 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8374 : : }
8375 : : }
8376 : 129 : OMP_CLAUSE_OPERAND (c, 1) = t;
8377 : : }
8378 : : /* Check operand 0, the num argument. */
8379 : : /* FALLTHRU */
8380 : :
8381 : 3480 : case OMP_CLAUSE_WORKER:
8382 : 3480 : case OMP_CLAUSE_VECTOR:
8383 : 3480 : if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
8384 : : break;
8385 : : /* FALLTHRU */
8386 : :
8387 : 484 : case OMP_CLAUSE_NUM_TASKS:
8388 : 484 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
8389 : 136 : num_tasks_seen = true;
8390 : : /* FALLTHRU */
8391 : :
8392 : 3034 : case OMP_CLAUSE_NUM_TEAMS:
8393 : 3034 : case OMP_CLAUSE_NUM_THREADS:
8394 : 3034 : case OMP_CLAUSE_NUM_GANGS:
8395 : 3034 : case OMP_CLAUSE_NUM_WORKERS:
8396 : 3034 : case OMP_CLAUSE_DYN_GROUPPRIVATE:
8397 : 3034 : case OMP_CLAUSE_VECTOR_LENGTH:
8398 : 3034 : t = OMP_CLAUSE_OPERAND (c, 0);
8399 : 3034 : if (t == error_mark_node)
8400 : : remove = true;
8401 : 3034 : else if (!type_dependent_expression_p (t)
8402 : 3034 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8403 : : {
8404 : 99 : switch (OMP_CLAUSE_CODE (c))
8405 : : {
8406 : 12 : case OMP_CLAUSE_GANG:
8407 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8408 : 12 : "%<gang%> num expression must be integral"); break;
8409 : 12 : case OMP_CLAUSE_VECTOR:
8410 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8411 : : "%<vector%> length expression must be integral");
8412 : 12 : break;
8413 : 12 : case OMP_CLAUSE_WORKER:
8414 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8415 : : "%<worker%> num expression must be integral");
8416 : 12 : break;
8417 : 63 : default:
8418 : 63 : error_at (OMP_CLAUSE_LOCATION (c),
8419 : : "%qs expression must be integral",
8420 : 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8421 : : }
8422 : : remove = true;
8423 : : }
8424 : : else
8425 : : {
8426 : 2935 : t = mark_rvalue_use (t);
8427 : 2935 : if (!processing_template_decl)
8428 : : {
8429 : 2687 : t = maybe_constant_value (t);
8430 : 2687 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
8431 : 2652 : && TREE_CODE (t) == INTEGER_CST
8432 : 4142 : && tree_int_cst_sgn (t) != 1)
8433 : : {
8434 : 85 : switch (OMP_CLAUSE_CODE (c))
8435 : : {
8436 : 3 : case OMP_CLAUSE_GANG:
8437 : 3 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8438 : : "%<gang%> num value must be positive");
8439 : 3 : break;
8440 : 0 : case OMP_CLAUSE_VECTOR:
8441 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8442 : : "%<vector%> length value must be "
8443 : : "positive");
8444 : 0 : break;
8445 : 0 : case OMP_CLAUSE_WORKER:
8446 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8447 : : "%<worker%> num value must be "
8448 : : "positive");
8449 : 0 : break;
8450 : 82 : default:
8451 : 82 : warning_at (OMP_CLAUSE_LOCATION (c),
8452 : 46 : (flag_openmp || flag_openmp_simd)
8453 : 82 : ? OPT_Wopenmp : 0,
8454 : : "%qs value must be positive",
8455 : : omp_clause_code_name
8456 : 82 : [OMP_CLAUSE_CODE (c)]);
8457 : : }
8458 : 85 : t = integer_one_node;
8459 : : }
8460 : 2602 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
8461 : 35 : && TREE_CODE (t) == INTEGER_CST
8462 : 2625 : && tree_int_cst_sgn (t) < 0)
8463 : : {
8464 : 8 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8465 : : "%<dyn_groupprivate%> value must be "
8466 : : "non-negative");
8467 : 8 : t = integer_zero_node;
8468 : : }
8469 : 2687 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8470 : : }
8471 : 2935 : OMP_CLAUSE_OPERAND (c, 0) = t;
8472 : : }
8473 : 3034 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
8474 : 752 : && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
8475 : 3313 : && !remove)
8476 : : {
8477 : 279 : t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
8478 : 279 : if (t == error_mark_node)
8479 : : remove = true;
8480 : 279 : else if (!type_dependent_expression_p (t)
8481 : 279 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8482 : : {
8483 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8484 : : "%qs expression must be integral",
8485 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8486 : 0 : remove = true;
8487 : : }
8488 : : else
8489 : : {
8490 : 279 : t = mark_rvalue_use (t);
8491 : 279 : if (!processing_template_decl)
8492 : : {
8493 : 213 : t = maybe_constant_value (t);
8494 : 213 : if (TREE_CODE (t) == INTEGER_CST
8495 : 213 : && tree_int_cst_sgn (t) != 1)
8496 : : {
8497 : 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8498 : : "%qs value must be positive",
8499 : : omp_clause_code_name
8500 : 18 : [OMP_CLAUSE_CODE (c)]);
8501 : 18 : t = NULL_TREE;
8502 : : }
8503 : : else
8504 : 195 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8505 : 213 : tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
8506 : 213 : if (t
8507 : 195 : && TREE_CODE (t) == INTEGER_CST
8508 : 43 : && TREE_CODE (upper) == INTEGER_CST
8509 : 250 : && tree_int_cst_lt (upper, t))
8510 : : {
8511 : 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8512 : : "%<num_teams%> lower bound %qE bigger "
8513 : : "than upper bound %qE", t, upper);
8514 : 18 : t = NULL_TREE;
8515 : : }
8516 : : }
8517 : 279 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
8518 : : }
8519 : : }
8520 : : break;
8521 : :
8522 : 3862 : case OMP_CLAUSE_SCHEDULE:
8523 : 3862 : t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
8524 : 3862 : if (t == NULL)
8525 : : ;
8526 : 2078 : else if (t == error_mark_node)
8527 : : remove = true;
8528 : 2078 : else if (!type_dependent_expression_p (t)
8529 : 2078 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8530 : : {
8531 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
8532 : : "schedule chunk size expression must be integral");
8533 : 9 : remove = true;
8534 : : }
8535 : : else
8536 : : {
8537 : 2069 : t = mark_rvalue_use (t);
8538 : 2069 : if (!processing_template_decl)
8539 : : {
8540 : 2029 : t = maybe_constant_value (t);
8541 : 2029 : if (TREE_CODE (t) == INTEGER_CST
8542 : 2029 : && tree_int_cst_sgn (t) != 1)
8543 : : {
8544 : 6 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8545 : : "chunk size value must be positive");
8546 : 6 : t = integer_one_node;
8547 : : }
8548 : 2029 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8549 : : }
8550 : 2069 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8551 : : }
8552 : 2078 : if (!remove)
8553 : : schedule_seen = true;
8554 : : break;
8555 : :
8556 : 1268 : case OMP_CLAUSE_SIMDLEN:
8557 : 1268 : case OMP_CLAUSE_SAFELEN:
8558 : 1268 : t = OMP_CLAUSE_OPERAND (c, 0);
8559 : 1268 : if (t == error_mark_node)
8560 : : remove = true;
8561 : 1268 : else if (!type_dependent_expression_p (t)
8562 : 1268 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8563 : : {
8564 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8565 : : "%qs length expression must be integral",
8566 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8567 : 0 : remove = true;
8568 : : }
8569 : : else
8570 : : {
8571 : 1268 : t = mark_rvalue_use (t);
8572 : 1268 : if (!processing_template_decl)
8573 : : {
8574 : 1219 : t = maybe_constant_value (t);
8575 : 1219 : if (TREE_CODE (t) != INTEGER_CST
8576 : 1219 : || tree_int_cst_sgn (t) != 1)
8577 : : {
8578 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8579 : : "%qs length expression must be positive "
8580 : : "constant integer expression",
8581 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8582 : 0 : remove = true;
8583 : : }
8584 : : }
8585 : 1268 : OMP_CLAUSE_OPERAND (c, 0) = t;
8586 : 1268 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
8587 : 470 : safelen = c;
8588 : : }
8589 : : break;
8590 : :
8591 : 388 : case OMP_CLAUSE_ASYNC:
8592 : 388 : t = OMP_CLAUSE_ASYNC_EXPR (c);
8593 : 388 : if (t == error_mark_node)
8594 : : remove = true;
8595 : 373 : else if (!type_dependent_expression_p (t)
8596 : 373 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8597 : : {
8598 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8599 : : "%<async%> expression must be integral");
8600 : 12 : remove = true;
8601 : : }
8602 : : else
8603 : : {
8604 : 361 : t = mark_rvalue_use (t);
8605 : 361 : if (!processing_template_decl)
8606 : 352 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8607 : 361 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
8608 : : }
8609 : : break;
8610 : :
8611 : 204 : case OMP_CLAUSE_WAIT:
8612 : 204 : t = OMP_CLAUSE_WAIT_EXPR (c);
8613 : 204 : if (t == error_mark_node)
8614 : : remove = true;
8615 : 204 : else if (!processing_template_decl)
8616 : 196 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8617 : 204 : OMP_CLAUSE_WAIT_EXPR (c) = t;
8618 : 204 : break;
8619 : :
8620 : 637 : case OMP_CLAUSE_THREAD_LIMIT:
8621 : 637 : t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
8622 : 637 : if (t == error_mark_node)
8623 : : remove = true;
8624 : 637 : else if (!type_dependent_expression_p (t)
8625 : 637 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8626 : : {
8627 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8628 : : "%<thread_limit%> expression must be integral");
8629 : 0 : remove = true;
8630 : : }
8631 : : else
8632 : : {
8633 : 637 : t = mark_rvalue_use (t);
8634 : 637 : if (!processing_template_decl)
8635 : : {
8636 : 583 : t = maybe_constant_value (t);
8637 : 583 : if (TREE_CODE (t) == INTEGER_CST
8638 : 583 : && tree_int_cst_sgn (t) != 1)
8639 : : {
8640 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8641 : : "%<thread_limit%> value must be positive");
8642 : 0 : t = integer_one_node;
8643 : : }
8644 : 583 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8645 : : }
8646 : 637 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
8647 : : }
8648 : : break;
8649 : :
8650 : 767 : case OMP_CLAUSE_DEVICE:
8651 : 767 : t = OMP_CLAUSE_DEVICE_ID (c);
8652 : 767 : if (t == error_mark_node)
8653 : : remove = true;
8654 : 767 : else if (!type_dependent_expression_p (t)
8655 : 767 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8656 : : {
8657 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8658 : : "%<device%> id must be integral");
8659 : 6 : remove = true;
8660 : : }
8661 : 761 : else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
8662 : 66 : && TREE_CODE (t) == INTEGER_CST
8663 : 821 : && !integer_onep (t))
8664 : : {
8665 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8666 : : "the %<device%> clause expression must evaluate to "
8667 : : "%<1%>");
8668 : 3 : remove = true;
8669 : : }
8670 : : else
8671 : : {
8672 : 758 : t = mark_rvalue_use (t);
8673 : 758 : if (!processing_template_decl)
8674 : 747 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8675 : 758 : OMP_CLAUSE_DEVICE_ID (c) = t;
8676 : : }
8677 : : break;
8678 : :
8679 : 1836 : case OMP_CLAUSE_DIST_SCHEDULE:
8680 : 1836 : t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
8681 : 1836 : if (t == NULL)
8682 : : ;
8683 : 1815 : else if (t == error_mark_node)
8684 : : remove = true;
8685 : 1815 : else if (!type_dependent_expression_p (t)
8686 : 1815 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8687 : : {
8688 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8689 : : "%<dist_schedule%> chunk size expression must be "
8690 : : "integral");
8691 : 0 : remove = true;
8692 : : }
8693 : : else
8694 : : {
8695 : 1815 : t = mark_rvalue_use (t);
8696 : 1815 : if (!processing_template_decl)
8697 : 1815 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8698 : 1815 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
8699 : : }
8700 : : break;
8701 : :
8702 : 807 : case OMP_CLAUSE_ALIGNED:
8703 : 807 : t = OMP_CLAUSE_DECL (c);
8704 : 807 : if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
8705 : : {
8706 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8707 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
8708 : : " clauses");
8709 : 0 : remove = true;
8710 : 0 : break;
8711 : : }
8712 : 807 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8713 : : {
8714 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8715 : : break;
8716 : 0 : if (DECL_P (t))
8717 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8718 : : "%qD is not a variable in %<aligned%> clause", t);
8719 : : else
8720 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8721 : : "%qE is not a variable in %<aligned%> clause", t);
8722 : : remove = true;
8723 : : }
8724 : 807 : else if (!type_dependent_expression_p (t)
8725 : 789 : && !TYPE_PTR_P (TREE_TYPE (t))
8726 : 111 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
8727 : 864 : && (!TYPE_REF_P (TREE_TYPE (t))
8728 : 39 : || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
8729 : 30 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
8730 : : != ARRAY_TYPE))))
8731 : : {
8732 : 33 : error_at (OMP_CLAUSE_LOCATION (c),
8733 : : "%qE in %<aligned%> clause is neither a pointer nor "
8734 : : "an array nor a reference to pointer or array", t);
8735 : 33 : remove = true;
8736 : : }
8737 : 774 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8738 : : {
8739 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8740 : : "%qD appears more than once in %<aligned%> clauses",
8741 : : t);
8742 : 0 : remove = true;
8743 : : }
8744 : : else
8745 : 774 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8746 : 807 : t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
8747 : 807 : if (t == error_mark_node)
8748 : : remove = true;
8749 : 807 : else if (t == NULL_TREE)
8750 : : break;
8751 : 744 : else if (!type_dependent_expression_p (t)
8752 : 744 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8753 : : {
8754 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8755 : : "%<aligned%> clause alignment expression must "
8756 : : "be integral");
8757 : 0 : remove = true;
8758 : : }
8759 : : else
8760 : : {
8761 : 744 : t = mark_rvalue_use (t);
8762 : 744 : if (!processing_template_decl)
8763 : : {
8764 : 690 : t = maybe_constant_value (t);
8765 : 690 : if (TREE_CODE (t) != INTEGER_CST
8766 : 690 : || tree_int_cst_sgn (t) != 1)
8767 : : {
8768 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8769 : : "%<aligned%> clause alignment expression must "
8770 : : "be positive constant integer expression");
8771 : 0 : remove = true;
8772 : : }
8773 : : }
8774 : 744 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
8775 : : }
8776 : : break;
8777 : :
8778 : 369 : case OMP_CLAUSE_NONTEMPORAL:
8779 : 369 : t = OMP_CLAUSE_DECL (c);
8780 : 369 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8781 : : {
8782 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8783 : : break;
8784 : 0 : if (DECL_P (t))
8785 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8786 : : "%qD is not a variable in %<nontemporal%> clause",
8787 : : t);
8788 : : else
8789 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8790 : : "%qE is not a variable in %<nontemporal%> clause",
8791 : : t);
8792 : : remove = true;
8793 : : }
8794 : 369 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8795 : : {
8796 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8797 : : "%qD appears more than once in %<nontemporal%> "
8798 : : "clauses", t);
8799 : 6 : remove = true;
8800 : : }
8801 : : else
8802 : 363 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8803 : : break;
8804 : :
8805 : 2537 : case OMP_CLAUSE_ALLOCATE:
8806 : 2537 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8807 : 2537 : if (t)
8808 : 14 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8809 : : else
8810 : 2523 : t = OMP_CLAUSE_DECL (c);
8811 : 2537 : if (t == current_class_ptr)
8812 : : {
8813 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8814 : : "%<this%> not allowed in %<allocate%> clause");
8815 : 0 : remove = true;
8816 : 0 : break;
8817 : : }
8818 : 2537 : if (!VAR_P (t)
8819 : 558 : && TREE_CODE (t) != PARM_DECL
8820 : 45 : && TREE_CODE (t) != FIELD_DECL)
8821 : : {
8822 : 3 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8823 : : break;
8824 : 3 : if (DECL_P (t))
8825 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8826 : : "%qD is not a variable in %<allocate%> clause", t);
8827 : : else
8828 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8829 : : "%qE is not a variable in %<allocate%> clause", t);
8830 : : remove = true;
8831 : : }
8832 : 2534 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8833 : : {
8834 : 12 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8835 : : "%qD appears more than once in %<allocate%> clauses",
8836 : : t);
8837 : 12 : remove = true;
8838 : : }
8839 : : else
8840 : : {
8841 : 2522 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8842 : 2522 : allocate_seen = true;
8843 : : }
8844 : 2537 : tree allocator, align;
8845 : 2537 : align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
8846 : 2537 : if (error_operand_p (align))
8847 : : {
8848 : : remove = true;
8849 : : break;
8850 : : }
8851 : 2537 : if (align)
8852 : : {
8853 : 171 : if (!type_dependent_expression_p (align)
8854 : 171 : && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
8855 : : {
8856 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
8857 : : "%<allocate%> clause %<align%> modifier "
8858 : : "argument needs to be positive constant "
8859 : : "power of two integer expression");
8860 : 4 : remove = true;
8861 : : }
8862 : : else
8863 : : {
8864 : 167 : align = mark_rvalue_use (align);
8865 : 167 : if (!processing_template_decl)
8866 : : {
8867 : 152 : align = maybe_constant_value (align);
8868 : 152 : if (TREE_CODE (align) != INTEGER_CST
8869 : 149 : || !tree_fits_uhwi_p (align)
8870 : 301 : || !integer_pow2p (align))
8871 : : {
8872 : 10 : error_at (OMP_CLAUSE_LOCATION (c),
8873 : : "%<allocate%> clause %<align%> modifier "
8874 : : "argument needs to be positive constant "
8875 : : "power of two integer expression");
8876 : 10 : remove = true;
8877 : : }
8878 : : }
8879 : : }
8880 : 171 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
8881 : : }
8882 : 2537 : allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
8883 : 2537 : if (error_operand_p (allocator))
8884 : : {
8885 : : remove = true;
8886 : : break;
8887 : : }
8888 : 2537 : if (allocator == NULL_TREE)
8889 : 1537 : goto handle_field_decl;
8890 : 1000 : tree allocatort;
8891 : 1000 : allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
8892 : 1000 : if (!type_dependent_expression_p (allocator)
8893 : 1000 : && (TREE_CODE (allocatort) != ENUMERAL_TYPE
8894 : 981 : || TYPE_NAME (allocatort) == NULL_TREE
8895 : 981 : || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
8896 : 1962 : || (DECL_NAME (TYPE_NAME (allocatort))
8897 : 981 : != get_identifier ("omp_allocator_handle_t"))
8898 : 981 : || (TYPE_CONTEXT (allocatort)
8899 : 981 : != DECL_CONTEXT (global_namespace))))
8900 : : {
8901 : 16 : error_at (OMP_CLAUSE_LOCATION (c),
8902 : : "%<allocate%> clause allocator expression has "
8903 : : "type %qT rather than %<omp_allocator_handle_t%>",
8904 : 16 : TREE_TYPE (allocator));
8905 : 16 : remove = true;
8906 : 16 : break;
8907 : : }
8908 : : else
8909 : : {
8910 : 984 : allocator = mark_rvalue_use (allocator);
8911 : 984 : if (!processing_template_decl)
8912 : 965 : allocator = maybe_constant_value (allocator);
8913 : 984 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
8914 : : }
8915 : 984 : goto handle_field_decl;
8916 : :
8917 : 654 : case OMP_CLAUSE_DOACROSS:
8918 : 654 : t = OMP_CLAUSE_DECL (c);
8919 : 654 : if (t == NULL_TREE)
8920 : : break;
8921 : 298 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
8922 : : {
8923 : 298 : if (cp_finish_omp_clause_doacross_sink (c))
8924 : 12 : remove = true;
8925 : : break;
8926 : : }
8927 : 0 : gcc_unreachable ();
8928 : 141 : case OMP_CLAUSE_USES_ALLOCATORS:
8929 : 141 : t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
8930 : 141 : t = convert_from_reference (t);
8931 : 141 : if (t == error_mark_node)
8932 : : {
8933 : : remove = true;
8934 : : break;
8935 : : }
8936 : 129 : if (DECL_P (t)
8937 : 129 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8938 : 120 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8939 : 117 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t))))
8940 : : {
8941 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8942 : : "%qE appears more than once in data clauses", t);
8943 : 3 : remove = true;
8944 : : }
8945 : 126 : else if (DECL_P (t))
8946 : 117 : bitmap_set_bit (&generic_head, DECL_UID (t));
8947 : 129 : if (type_dependent_expression_p (t))
8948 : : break;
8949 : 114 : if (TREE_CODE (t) == FIELD_DECL)
8950 : : {
8951 : 0 : sorry_at (OMP_CLAUSE_LOCATION (c), "class member %qE not yet "
8952 : : "supported in %<uses_allocators%> clause", t);
8953 : 0 : remove = true;
8954 : 0 : break;
8955 : : }
8956 : 114 : if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
8957 : 219 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
8958 : : "omp_allocator_handle_t") != 0)
8959 : : {
8960 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
8961 : : "allocator %qE must be of %<omp_allocator_handle_t%> "
8962 : : "type", t);
8963 : 9 : remove = true;
8964 : 9 : break;
8965 : : }
8966 : 105 : tree init;
8967 : 105 : if (TREE_CODE (t) == CONST_DECL)
8968 : 15 : init = DECL_INITIAL(t);
8969 : : else
8970 : : init = t;
8971 : 105 : if (!DECL_P (t)
8972 : 105 : && (init == NULL_TREE
8973 : 9 : || TREE_CODE (init) != INTEGER_CST
8974 : 9 : || ((wi::to_widest (init) < 0
8975 : 9 : || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
8976 : 3 : && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
8977 : 3 : || (wi::to_widest (init)
8978 : 6 : > GOMP_OMPX_PREDEF_ALLOC_MAX)))))
8979 : : {
8980 : 3 : remove = true;
8981 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8982 : : "allocator %qE must be either a variable or a "
8983 : : "predefined allocator", t);
8984 : 3 : break;
8985 : : }
8986 : 102 : else if (TREE_CODE (t) == CONST_DECL)
8987 : : {
8988 : : /* omp_null_allocator is ignored and for predefined allocators,
8989 : : not special handling is required; thus, remove them removed. */
8990 : 15 : remove = true;
8991 : :
8992 : 15 : if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
8993 : 15 : || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
8994 : : {
8995 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8996 : : "modifiers cannot be used with predefined "
8997 : : "allocators");
8998 : 0 : break;
8999 : : }
9000 : : }
9001 : 102 : t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
9002 : 102 : if (t == error_mark_node)
9003 : : {
9004 : : remove = true;
9005 : : break;
9006 : : }
9007 : 99 : if (t != NULL_TREE
9008 : 18 : && !type_dependent_expression_p (t)
9009 : 117 : && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
9010 : 15 : || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
9011 : 24 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
9012 : : "omp_memspace_handle_t") != 0))
9013 : : {
9014 : 6 : error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
9015 : : " constant enum of %<omp_memspace_handle_t%> type", t);
9016 : 6 : remove = true;
9017 : 6 : break;
9018 : : }
9019 : 93 : t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
9020 : 93 : if (t == error_mark_node)
9021 : : {
9022 : : remove = true;
9023 : : break;
9024 : : }
9025 : 90 : if (type_dependent_expression_p (t))
9026 : : break;
9027 : 90 : if (t != NULL_TREE
9028 : 39 : && t != error_mark_node
9029 : 39 : && !type_dependent_expression_p (t)
9030 : 129 : && (!DECL_P (t)
9031 : 39 : || DECL_EXTERNAL (t)
9032 : 33 : || TREE_CODE (t) == PARM_DECL))
9033 : : {
9034 : 12 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
9035 : : "defined in same scope as the construct on which the "
9036 : : "clause appears", t);
9037 : 12 : remove = true;
9038 : : }
9039 : 90 : if (t != NULL_TREE)
9040 : : {
9041 : 39 : bool type_err = false;
9042 : :
9043 : 39 : if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
9044 : 33 : || DECL_SIZE (t) == NULL_TREE
9045 : 69 : || !COMPLETE_TYPE_P (TREE_TYPE (t)))
9046 : : type_err = true;
9047 : : else
9048 : : {
9049 : 30 : tree elem_t = TREE_TYPE (TREE_TYPE (t));
9050 : 30 : if (TREE_CODE (elem_t) != RECORD_TYPE
9051 : 60 : || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
9052 : : "omp_alloctrait_t") != 0
9053 : 60 : || !TYPE_READONLY (elem_t))
9054 : : type_err = true;
9055 : : }
9056 : 27 : if (type_err)
9057 : : {
9058 : 12 : error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
9059 : : "be of %<const omp_alloctrait_t []%> type", t);
9060 : 12 : remove = true;
9061 : : }
9062 : 27 : else if (TREE_CODE (array_type_nelts_top (TREE_TYPE (t)))
9063 : : != INTEGER_CST)
9064 : : {
9065 : 3 : error_at (OMP_CLAUSE_LOCATION (c), "variable length traits "
9066 : : "arrays are not supported");
9067 : 3 : remove = true;
9068 : : }
9069 : : else
9070 : : {
9071 : 24 : tree cst_val = decl_constant_value (t);
9072 : 24 : if (cst_val == t)
9073 : : {
9074 : 3 : error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
9075 : : "initialized with constants");
9076 : 3 : remove = true;
9077 : : }
9078 : : }
9079 : : }
9080 : 90 : if (remove)
9081 : : break;
9082 : 54 : pc = &OMP_CLAUSE_CHAIN (c);
9083 : 54 : continue;
9084 : 1803 : case OMP_CLAUSE_DEPEND:
9085 : 1803 : depend_clause = c;
9086 : : /* FALLTHRU */
9087 : 2169 : case OMP_CLAUSE_AFFINITY:
9088 : 2169 : t = OMP_CLAUSE_DECL (c);
9089 : 2169 : if (OMP_ITERATOR_DECL_P (t))
9090 : : {
9091 : 621 : if (TREE_PURPOSE (t) != last_iterators)
9092 : 523 : last_iterators_remove
9093 : 523 : = cp_omp_finish_iterators (TREE_PURPOSE (t));
9094 : 621 : last_iterators = TREE_PURPOSE (t);
9095 : 621 : t = TREE_VALUE (t);
9096 : 621 : if (last_iterators_remove)
9097 : 144 : t = error_mark_node;
9098 : : }
9099 : : else
9100 : : last_iterators = NULL_TREE;
9101 : :
9102 : 2169 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9103 : : {
9104 : 1163 : if (handle_omp_array_sections (c, ort))
9105 : : remove = true;
9106 : 912 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9107 : 912 : && (OMP_CLAUSE_DEPEND_KIND (c)
9108 : : == OMP_CLAUSE_DEPEND_DEPOBJ))
9109 : : {
9110 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9111 : : "%<depend%> clause with %<depobj%> dependence "
9112 : : "type on array section");
9113 : 6 : remove = true;
9114 : : }
9115 : : break;
9116 : : }
9117 : 1006 : if (t == error_mark_node)
9118 : : remove = true;
9119 : 844 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9120 : 844 : && t == ridpointers[RID_OMP_ALL_MEMORY])
9121 : : {
9122 : 33 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
9123 : 33 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
9124 : : {
9125 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9126 : : "%<omp_all_memory%> used with %<depend%> kind "
9127 : : "other than %<out%> or %<inout%>");
9128 : 9 : remove = true;
9129 : : }
9130 : 33 : if (processing_template_decl)
9131 : : break;
9132 : : }
9133 : 811 : else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9134 : : break;
9135 : 619 : else if (!lvalue_p (t))
9136 : : {
9137 : 19 : if (DECL_P (t))
9138 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
9139 : : "%qD is not lvalue expression nor array section "
9140 : : "in %qs clause", t,
9141 : 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9142 : : else
9143 : 14 : error_at (OMP_CLAUSE_LOCATION (c),
9144 : : "%qE is not lvalue expression nor array section "
9145 : : "in %qs clause", t,
9146 : 7 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9147 : : remove = true;
9148 : : }
9149 : 600 : else if (TREE_CODE (t) == COMPONENT_REF
9150 : 24 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
9151 : 624 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
9152 : : {
9153 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
9154 : : "bit-field %qE in %qs clause", t,
9155 : 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9156 : 4 : remove = true;
9157 : : }
9158 : 596 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9159 : 596 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
9160 : : {
9161 : 130 : if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9162 : 8 : ? TREE_TYPE (TREE_TYPE (t))
9163 : 57 : : TREE_TYPE (t)))
9164 : : {
9165 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
9166 : : "%qE does not have %<omp_depend_t%> type in "
9167 : : "%<depend%> clause with %<depobj%> dependence "
9168 : : "type", t);
9169 : 12 : remove = true;
9170 : : }
9171 : : }
9172 : 531 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
9173 : 970 : && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
9174 : 4 : ? TREE_TYPE (TREE_TYPE (t))
9175 : 435 : : TREE_TYPE (t)))
9176 : : {
9177 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
9178 : : "%qE should not have %<omp_depend_t%> type in "
9179 : : "%<depend%> clause with dependence type other than "
9180 : : "%<depobj%>", t);
9181 : 15 : remove = true;
9182 : : }
9183 : 64 : if (!remove)
9184 : : {
9185 : 593 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
9186 : 24 : t = null_pointer_node;
9187 : : else
9188 : : {
9189 : 569 : tree addr = cp_build_addr_expr (t, tf_warning_or_error);
9190 : 569 : if (addr == error_mark_node)
9191 : : {
9192 : : remove = true;
9193 : : break;
9194 : : }
9195 : 569 : t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
9196 : : addr, RO_UNARY_STAR,
9197 : : tf_warning_or_error);
9198 : 569 : if (t == error_mark_node)
9199 : : {
9200 : : remove = true;
9201 : : break;
9202 : : }
9203 : : }
9204 : 593 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
9205 : 135 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
9206 : 728 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
9207 : : == TREE_VEC))
9208 : 135 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
9209 : : else
9210 : 458 : OMP_CLAUSE_DECL (c) = t;
9211 : : }
9212 : : break;
9213 : 69 : case OMP_CLAUSE_DETACH:
9214 : 69 : t = OMP_CLAUSE_DECL (c);
9215 : 69 : if (detach_seen)
9216 : : {
9217 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9218 : : "too many %qs clauses on a task construct",
9219 : : "detach");
9220 : 3 : remove = true;
9221 : 3 : break;
9222 : : }
9223 : 66 : else if (error_operand_p (t))
9224 : : {
9225 : : remove = true;
9226 : : break;
9227 : : }
9228 : : else
9229 : : {
9230 : 63 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
9231 : 63 : if (!type_dependent_expression_p (t)
9232 : 63 : && (!INTEGRAL_TYPE_P (type)
9233 : : || TREE_CODE (type) != ENUMERAL_TYPE
9234 : 51 : || TYPE_NAME (type) == NULL_TREE
9235 : 102 : || (DECL_NAME (TYPE_NAME (type))
9236 : 51 : != get_identifier ("omp_event_handle_t"))))
9237 : : {
9238 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9239 : : "%<detach%> clause event handle "
9240 : : "has type %qT rather than "
9241 : : "%<omp_event_handle_t%>",
9242 : : type);
9243 : 6 : remove = true;
9244 : : }
9245 : 63 : detach_seen = c;
9246 : 63 : cxx_mark_addressable (t);
9247 : : }
9248 : 63 : break;
9249 : :
9250 : 15929 : case OMP_CLAUSE_MAP:
9251 : 15929 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
9252 : 190 : goto move_implicit;
9253 : 15739 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
9254 : 15739 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
9255 : : {
9256 : : remove = true;
9257 : : break;
9258 : : }
9259 : : /* FALLTHRU */
9260 : 18857 : case OMP_CLAUSE_TO:
9261 : 18857 : case OMP_CLAUSE_FROM:
9262 : 18857 : if (OMP_CLAUSE_ITERATORS (c)
9263 : 18857 : && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
9264 : : {
9265 : 96978 : t = error_mark_node;
9266 : : break;
9267 : : }
9268 : : /* FALLTHRU */
9269 : 19693 : case OMP_CLAUSE__CACHE_:
9270 : 19693 : {
9271 : 19693 : using namespace omp_addr_tokenizer;
9272 : 19693 : auto_vec<omp_addr_token *, 10> addr_tokens;
9273 : :
9274 : 19693 : t = OMP_CLAUSE_DECL (c);
9275 : 19693 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9276 : : {
9277 : 5872 : grp_start_p = pc;
9278 : 5872 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9279 : :
9280 : 5872 : if (handle_omp_array_sections (c, ort))
9281 : : remove = true;
9282 : : else
9283 : : {
9284 : 5106 : t = OMP_CLAUSE_DECL (c);
9285 : 5106 : if (TREE_CODE (t) != OMP_ARRAY_SECTION
9286 : 4249 : && !type_dependent_expression_p (t)
9287 : 9355 : && !omp_mappable_type (TREE_TYPE (t)))
9288 : : {
9289 : 3 : auto_diagnostic_group d;
9290 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9291 : : "array section does not have mappable type "
9292 : : "in %qs clause",
9293 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9294 : 3 : if (TREE_TYPE (t) != error_mark_node
9295 : 3 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9296 : 3 : cxx_incomplete_type_inform (TREE_TYPE (t));
9297 : 3 : remove = true;
9298 : 3 : }
9299 : 6956 : while (TREE_CODE (t) == ARRAY_REF)
9300 : 1850 : t = TREE_OPERAND (t, 0);
9301 : :
9302 : 5106 : if (type_dependent_expression_p (t))
9303 : : break;
9304 : :
9305 : 4632 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9306 : :
9307 : 4632 : if (!ai.map_supported_p ()
9308 : 4632 : || !omp_parse_expr (addr_tokens, t))
9309 : : {
9310 : 18 : sorry_at (OMP_CLAUSE_LOCATION (c),
9311 : : "unsupported map expression %qE",
9312 : 9 : OMP_CLAUSE_DECL (c));
9313 : 9 : remove = true;
9314 : 9 : break;
9315 : : }
9316 : :
9317 : : /* This check is to determine if this will be the only map
9318 : : node created for this clause. Otherwise, we'll check
9319 : : the following FIRSTPRIVATE_POINTER,
9320 : : FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
9321 : : iteration(s) of the loop. */
9322 : 9197 : if (addr_tokens.length () >= 4
9323 : 1063 : && addr_tokens[0]->type == STRUCTURE_BASE
9324 : 1057 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
9325 : 1057 : && addr_tokens[1]->type == ACCESS_METHOD
9326 : 1057 : && addr_tokens[2]->type == COMPONENT_SELECTOR
9327 : 977 : && addr_tokens[3]->type == ACCESS_METHOD
9328 : 5337 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
9329 : 551 : || (addr_tokens[3]->u.access_kind
9330 : : == ACCESS_INDEXED_ARRAY)))
9331 : : {
9332 : 165 : tree rt = addr_tokens[1]->expr;
9333 : :
9334 : 165 : gcc_assert (DECL_P (rt));
9335 : :
9336 : 165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9337 : 154 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9338 : 165 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
9339 : 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
9340 : 0 : || bitmap_bit_p (&map_firstprivate_head,
9341 : 0 : DECL_UID (rt))))
9342 : : {
9343 : : remove = true;
9344 : : break;
9345 : : }
9346 : 165 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
9347 : : break;
9348 : 116 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
9349 : : {
9350 : 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9351 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9352 : : "%qD appears more than once in motion"
9353 : : " clauses", rt);
9354 : 0 : else if (openacc)
9355 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9356 : : "%qD appears more than once in data"
9357 : : " clauses", rt);
9358 : : else
9359 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9360 : : "%qD appears more than once in map"
9361 : : " clauses", rt);
9362 : : remove = true;
9363 : : }
9364 : : else
9365 : : {
9366 : 116 : bitmap_set_bit (&map_head, DECL_UID (rt));
9367 : 116 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
9368 : : }
9369 : : }
9370 : 4632 : }
9371 : 5340 : if (cp_oacc_check_attachments (c))
9372 : 12 : remove = true;
9373 : 5340 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9374 : 4406 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9375 : 4342 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9376 : 5438 : && !OMP_CLAUSE_SIZE (c))
9377 : : /* In this case, we have a single array element which is a
9378 : : pointer, and we already set OMP_CLAUSE_SIZE in
9379 : : handle_omp_array_sections above. For attach/detach
9380 : : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
9381 : : to zero here. */
9382 : 60 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9383 : : break;
9384 : : }
9385 : 13821 : else if (type_dependent_expression_p (t))
9386 : : break;
9387 : 13047 : else if (!omp_parse_expr (addr_tokens, t))
9388 : : {
9389 : 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
9390 : : "unsupported map expression %qE",
9391 : 0 : OMP_CLAUSE_DECL (c));
9392 : 0 : remove = true;
9393 : 0 : break;
9394 : : }
9395 : 13047 : if (t == error_mark_node)
9396 : : {
9397 : : remove = true;
9398 : : break;
9399 : : }
9400 : : /* OpenACC attach / detach clauses must be pointers. */
9401 : 12953 : if (cp_oacc_check_attachments (c))
9402 : : {
9403 : : remove = true;
9404 : : break;
9405 : : }
9406 : 12929 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9407 : 9968 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9408 : 9919 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9409 : 13003 : && !OMP_CLAUSE_SIZE (c))
9410 : : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
9411 : : bias) to zero here, so it is not set erroneously to the
9412 : : pointer size later on in gimplify.cc. */
9413 : 66 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9414 : :
9415 : 12929 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9416 : :
9417 : 12929 : if (!ai.check_clause (c))
9418 : : {
9419 : : remove = true;
9420 : : break;
9421 : : }
9422 : :
9423 : 12908 : if (!ai.map_supported_p ())
9424 : : {
9425 : 88 : sorry_at (OMP_CLAUSE_LOCATION (c),
9426 : : "unsupported map expression %qE",
9427 : 44 : OMP_CLAUSE_DECL (c));
9428 : 44 : remove = true;
9429 : 44 : break;
9430 : : }
9431 : :
9432 : 25728 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
9433 : : || addr_tokens[0]->type == STRUCTURE_BASE)
9434 : : && addr_tokens[1]->type == ACCESS_METHOD);
9435 : :
9436 : 12864 : t = addr_tokens[1]->expr;
9437 : :
9438 : : /* This is used to prevent cxx_mark_addressable from being called
9439 : : on 'this' for expressions like 'this->a', i.e. typical member
9440 : : accesses. */
9441 : 12864 : indir_component_ref_p
9442 : 25728 : = (addr_tokens[0]->type == STRUCTURE_BASE
9443 : 12864 : && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
9444 : :
9445 : 12864 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
9446 : 1 : goto skip_decl_checks;
9447 : :
9448 : : /* For OpenMP, we can access a struct "t" and "t.d" on the same
9449 : : mapping. OpenACC allows multiple fields of the same structure
9450 : : to be written. */
9451 : 12863 : if (addr_tokens[0]->type == STRUCTURE_BASE
9452 : 12863 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
9453 : 1197 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
9454 : 1168 : goto skip_decl_checks;
9455 : :
9456 : 11695 : if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
9457 : : {
9458 : 0 : OMP_CLAUSE_DECL (c)
9459 : 0 : = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
9460 : 0 : break;
9461 : : }
9462 : 11695 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9463 : : {
9464 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9465 : : break;
9466 : 0 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9467 : 0 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9468 : 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
9469 : 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
9470 : 0 : || (!openacc && EXPR_P (t))))
9471 : : break;
9472 : 0 : if (DECL_P (t))
9473 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9474 : : "%qD is not a variable in %qs clause", t,
9475 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9476 : : else
9477 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9478 : : "%qE is not a variable in %qs clause", t,
9479 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9480 : : remove = true;
9481 : : }
9482 : 11695 : else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
9483 : : {
9484 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9485 : : "%qD is threadprivate variable in %qs clause", t,
9486 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9487 : 0 : remove = true;
9488 : : }
9489 : 11695 : else if (!processing_template_decl
9490 : 11519 : && !TYPE_REF_P (TREE_TYPE (t))
9491 : 10846 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9492 : 7935 : || (OMP_CLAUSE_MAP_KIND (c)
9493 : : != GOMP_MAP_FIRSTPRIVATE_POINTER))
9494 : 8888 : && !indir_component_ref_p
9495 : 8524 : && (t != current_class_ptr
9496 : 18 : || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9497 : 6 : || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
9498 : 20219 : && !cxx_mark_addressable (t))
9499 : : remove = true;
9500 : 11695 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9501 : 8766 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9502 : 8766 : || (OMP_CLAUSE_MAP_KIND (c)
9503 : : == GOMP_MAP_FIRSTPRIVATE_POINTER)
9504 : 6808 : || (OMP_CLAUSE_MAP_KIND (c)
9505 : : == GOMP_MAP_ATTACH_DETACH)))
9506 : 9085 : && t == OMP_CLAUSE_DECL (c)
9507 : 8453 : && !type_dependent_expression_p (t)
9508 : 28601 : && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
9509 : 274 : ? TREE_TYPE (TREE_TYPE (t))
9510 : 8179 : : TREE_TYPE (t)))
9511 : : {
9512 : 42 : auto_diagnostic_group d;
9513 : 84 : error_at (OMP_CLAUSE_LOCATION (c),
9514 : : "%qD does not have a mappable type in %qs clause", t,
9515 : 42 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9516 : 42 : if (TREE_TYPE (t) != error_mark_node
9517 : 42 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9518 : 39 : cxx_incomplete_type_inform (TREE_TYPE (t));
9519 : 42 : remove = true;
9520 : 42 : }
9521 : 11653 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9522 : 8730 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
9523 : 93 : && !type_dependent_expression_p (t)
9524 : 11746 : && !INDIRECT_TYPE_P (TREE_TYPE (t)))
9525 : : {
9526 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9527 : : "%qD is not a pointer variable", t);
9528 : 6 : remove = true;
9529 : : }
9530 : 11647 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9531 : 8724 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9532 : 12050 : && (bitmap_bit_p (&map_head, DECL_UID (t))
9533 : 367 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
9534 : 367 : || bitmap_bit_p (&map_firstprivate_head,
9535 : 367 : DECL_UID (t))))
9536 : : remove = true;
9537 : 11608 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9538 : 11608 : && (OMP_CLAUSE_MAP_KIND (c)
9539 : : == GOMP_MAP_FIRSTPRIVATE_POINTER))
9540 : : {
9541 : 1952 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
9542 : 1952 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9543 : 3901 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
9544 : : {
9545 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
9546 : : "%qD appears more than once in data clauses", t);
9547 : 15 : remove = true;
9548 : : }
9549 : 1937 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9550 : 12 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9551 : 1945 : && openacc)
9552 : : {
9553 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9554 : : "%qD appears more than once in data clauses", t);
9555 : 3 : remove = true;
9556 : : }
9557 : : else
9558 : 1934 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9559 : : }
9560 : 9656 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9561 : 9656 : && (OMP_CLAUSE_MAP_KIND (c)
9562 : : == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
9563 : 115 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9564 : 9541 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9565 : 171 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9566 : 28 : && ort != C_ORT_OMP
9567 : 9569 : && ort != C_ORT_OMP_EXIT_DATA)
9568 : : {
9569 : 18 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9570 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9571 : : "%qD appears more than once in motion clauses", t);
9572 : 18 : else if (openacc)
9573 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9574 : : "%qD appears more than once in data clauses", t);
9575 : : else
9576 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9577 : : "%qD appears more than once in map clauses", t);
9578 : : remove = true;
9579 : : }
9580 : 9523 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
9581 : : {
9582 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9583 : : "%qD appears more than once in data clauses", t);
9584 : 0 : remove = true;
9585 : : }
9586 : 9523 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9587 : 9523 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
9588 : : {
9589 : 27 : if (openacc)
9590 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9591 : : "%qD appears more than once in data clauses", t);
9592 : : else
9593 : 27 : error_at (OMP_CLAUSE_LOCATION (c),
9594 : : "%qD appears both in data and map clauses", t);
9595 : : remove = true;
9596 : : }
9597 : 9496 : else if (!omp_access_chain_p (addr_tokens, 1))
9598 : : {
9599 : 9416 : bitmap_set_bit (&map_head, DECL_UID (t));
9600 : :
9601 : 9416 : tree decl = OMP_CLAUSE_DECL (c);
9602 : 9416 : if (t != decl
9603 : 9416 : && (TREE_CODE (decl) == COMPONENT_REF
9604 : 162 : || (INDIRECT_REF_P (decl)
9605 : 162 : && (TREE_CODE (TREE_OPERAND (decl, 0))
9606 : : == COMPONENT_REF)
9607 : 150 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
9608 : : 0))))))
9609 : 1099 : bitmap_set_bit (&map_field_head, DECL_UID (t));
9610 : : }
9611 : :
9612 : 4383 : skip_decl_checks:
9613 : : /* If we call ai.expand_map_clause in handle_omp_array_sections,
9614 : : the containing loop (here) iterates through the new nodes
9615 : : created by that expansion. Avoid expanding those again (just
9616 : : by checking the node type). */
9617 : 4383 : if (!remove
9618 : 12714 : && !processing_template_decl
9619 : 12541 : && ort != C_ORT_DECLARE_SIMD
9620 : 12541 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9621 : 9598 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
9622 : 7664 : && (OMP_CLAUSE_MAP_KIND (c)
9623 : : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
9624 : 7549 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
9625 : 7549 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
9626 : 6558 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
9627 : 6509 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
9628 : : {
9629 : 9427 : grp_start_p = pc;
9630 : 9427 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9631 : 9427 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
9632 : : addr_tokens, ort);
9633 : 9427 : if (nc != error_mark_node)
9634 : 9427 : c = nc;
9635 : : }
9636 : 19758 : }
9637 : 12864 : break;
9638 : :
9639 : 596 : case OMP_CLAUSE_ENTER:
9640 : 596 : case OMP_CLAUSE_LINK:
9641 : 596 : t = OMP_CLAUSE_DECL (c);
9642 : 596 : const char *cname;
9643 : 596 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
9644 : 596 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
9645 : 596 : && OMP_CLAUSE_ENTER_TO (c))
9646 : : cname = "to";
9647 : 596 : if (TREE_CODE (t) == FUNCTION_DECL
9648 : 596 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9649 : : ;
9650 : 379 : else if (!VAR_P (t))
9651 : : {
9652 : 12 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9653 : : {
9654 : 9 : if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
9655 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9656 : : "template %qE in clause %qs", t, cname);
9657 : 3 : else if (really_overloaded_fn (t))
9658 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9659 : : "overloaded function name %qE in clause %qs", t,
9660 : : cname);
9661 : : else
9662 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9663 : : "%qE is neither a variable nor a function name "
9664 : : "in clause %qs", t, cname);
9665 : : }
9666 : : else
9667 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9668 : : "%qE is not a variable in clause %qs", t, cname);
9669 : : remove = true;
9670 : : }
9671 : 367 : else if (DECL_THREAD_LOCAL_P (t))
9672 : : {
9673 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9674 : : "%qD is threadprivate variable in %qs clause", t,
9675 : : cname);
9676 : 6 : remove = true;
9677 : : }
9678 : 361 : else if (!omp_mappable_type (TREE_TYPE (t)))
9679 : : {
9680 : 18 : auto_diagnostic_group d;
9681 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
9682 : : "%qD does not have a mappable type in %qs clause", t,
9683 : : cname);
9684 : 18 : if (TREE_TYPE (t) != error_mark_node
9685 : 18 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9686 : 18 : cxx_incomplete_type_inform (TREE_TYPE (t));
9687 : 18 : remove = true;
9688 : 18 : }
9689 : 24 : if (remove)
9690 : : break;
9691 : 560 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9692 : : {
9693 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
9694 : : "%qE appears more than once on the same "
9695 : : "%<declare target%> directive", t);
9696 : 24 : remove = true;
9697 : : }
9698 : : else
9699 : 536 : bitmap_set_bit (&generic_head, DECL_UID (t));
9700 : : break;
9701 : :
9702 : 457 : case OMP_CLAUSE_UNIFORM:
9703 : 457 : t = OMP_CLAUSE_DECL (c);
9704 : 457 : if (TREE_CODE (t) != PARM_DECL)
9705 : : {
9706 : 0 : if (processing_template_decl)
9707 : : break;
9708 : 0 : if (DECL_P (t))
9709 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9710 : : "%qD is not an argument in %<uniform%> clause", t);
9711 : : else
9712 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9713 : : "%qE is not an argument in %<uniform%> clause", t);
9714 : : remove = true;
9715 : : break;
9716 : : }
9717 : : /* map_head bitmap is used as uniform_head if declare_simd. */
9718 : 457 : bitmap_set_bit (&map_head, DECL_UID (t));
9719 : 457 : goto check_dup_generic;
9720 : :
9721 : 165 : case OMP_CLAUSE_GRAINSIZE:
9722 : 165 : t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
9723 : 165 : if (t == error_mark_node)
9724 : : remove = true;
9725 : 165 : else if (!type_dependent_expression_p (t)
9726 : 165 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9727 : : {
9728 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9729 : : "%<grainsize%> expression must be integral");
9730 : 0 : remove = true;
9731 : : }
9732 : : else
9733 : : {
9734 : 165 : t = mark_rvalue_use (t);
9735 : 165 : if (!processing_template_decl)
9736 : : {
9737 : 164 : t = maybe_constant_value (t);
9738 : 164 : if (TREE_CODE (t) == INTEGER_CST
9739 : 164 : && tree_int_cst_sgn (t) != 1)
9740 : : {
9741 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9742 : : "%<grainsize%> value must be positive");
9743 : 0 : t = integer_one_node;
9744 : : }
9745 : 164 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9746 : : }
9747 : 165 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
9748 : : }
9749 : : break;
9750 : :
9751 : 276 : case OMP_CLAUSE_PRIORITY:
9752 : 276 : t = OMP_CLAUSE_PRIORITY_EXPR (c);
9753 : 276 : if (t == error_mark_node)
9754 : : remove = true;
9755 : 276 : else if (!type_dependent_expression_p (t)
9756 : 276 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9757 : : {
9758 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9759 : : "%<priority%> expression must be integral");
9760 : 0 : remove = true;
9761 : : }
9762 : : else
9763 : : {
9764 : 276 : t = mark_rvalue_use (t);
9765 : 276 : if (!processing_template_decl)
9766 : : {
9767 : 276 : t = maybe_constant_value (t);
9768 : 276 : if (TREE_CODE (t) == INTEGER_CST
9769 : 276 : && tree_int_cst_sgn (t) == -1)
9770 : : {
9771 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9772 : : "%<priority%> value must be non-negative");
9773 : 0 : t = integer_one_node;
9774 : : }
9775 : 276 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9776 : : }
9777 : 276 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
9778 : : }
9779 : : break;
9780 : :
9781 : 228 : case OMP_CLAUSE_HINT:
9782 : 228 : t = OMP_CLAUSE_HINT_EXPR (c);
9783 : 228 : if (t == error_mark_node)
9784 : : remove = true;
9785 : 228 : else if (!type_dependent_expression_p (t)
9786 : 228 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9787 : : {
9788 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9789 : : "%<hint%> expression must be integral");
9790 : 9 : remove = true;
9791 : : }
9792 : : else
9793 : : {
9794 : 219 : t = mark_rvalue_use (t);
9795 : 219 : if (!processing_template_decl)
9796 : : {
9797 : 171 : t = maybe_constant_value (t);
9798 : 171 : if (TREE_CODE (t) != INTEGER_CST)
9799 : : {
9800 : 16 : error_at (OMP_CLAUSE_LOCATION (c),
9801 : : "%<hint%> expression must be constant integer "
9802 : : "expression");
9803 : 16 : remove = true;
9804 : : }
9805 : : }
9806 : 219 : OMP_CLAUSE_HINT_EXPR (c) = t;
9807 : : }
9808 : : break;
9809 : :
9810 : 186 : case OMP_CLAUSE_FILTER:
9811 : 186 : t = OMP_CLAUSE_FILTER_EXPR (c);
9812 : 186 : if (t == error_mark_node)
9813 : : remove = true;
9814 : 186 : else if (!type_dependent_expression_p (t)
9815 : 186 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9816 : : {
9817 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9818 : : "%<filter%> expression must be integral");
9819 : 6 : remove = true;
9820 : : }
9821 : : else
9822 : : {
9823 : 180 : t = mark_rvalue_use (t);
9824 : 180 : if (!processing_template_decl)
9825 : : {
9826 : 177 : t = maybe_constant_value (t);
9827 : 177 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9828 : : }
9829 : 180 : OMP_CLAUSE_FILTER_EXPR (c) = t;
9830 : : }
9831 : : break;
9832 : :
9833 : 432 : case OMP_CLAUSE_IS_DEVICE_PTR:
9834 : 432 : case OMP_CLAUSE_USE_DEVICE_PTR:
9835 : 432 : field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
9836 : 432 : t = OMP_CLAUSE_DECL (c);
9837 : 432 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
9838 : 328 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9839 : 432 : if (!type_dependent_expression_p (t))
9840 : : {
9841 : 430 : tree type = TREE_TYPE (t);
9842 : 430 : if (!TYPE_PTR_P (type)
9843 : 430 : && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
9844 : : {
9845 : 57 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
9846 : 57 : && ort == C_ORT_OMP)
9847 : : {
9848 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9849 : : "%qs variable is neither a pointer "
9850 : : "nor reference to pointer",
9851 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9852 : 3 : remove = true;
9853 : : }
9854 : 54 : else if (TREE_CODE (type) != ARRAY_TYPE
9855 : 54 : && (!TYPE_REF_P (type)
9856 : 2 : || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
9857 : : {
9858 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
9859 : : "%qs variable is neither a pointer, nor an "
9860 : : "array nor reference to pointer or array",
9861 : 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9862 : 12 : remove = true;
9863 : : }
9864 : : }
9865 : : }
9866 : 432 : goto check_dup_generic;
9867 : :
9868 : 266 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
9869 : 266 : t = OMP_CLAUSE_DECL (c);
9870 : 266 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9871 : : {
9872 : 28 : if (handle_omp_array_sections (c, ort))
9873 : : remove = true;
9874 : : else
9875 : : {
9876 : 28 : t = OMP_CLAUSE_DECL (c);
9877 : 30 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
9878 : 2 : t = TREE_OPERAND (t, 0);
9879 : 64 : while (INDIRECT_REF_P (t)
9880 : 64 : || TREE_CODE (t) == ARRAY_REF)
9881 : 36 : t = TREE_OPERAND (t, 0);
9882 : : }
9883 : : }
9884 : 266 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9885 : : {
9886 : 266 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9887 : 266 : if (!processing_template_decl
9888 : 266 : && !cxx_mark_addressable (t))
9889 : : remove = true;
9890 : : }
9891 : 266 : goto check_dup_generic_t;
9892 : :
9893 : 76 : case OMP_CLAUSE_USE_DEVICE_ADDR:
9894 : 76 : field_ok = true;
9895 : 76 : t = OMP_CLAUSE_DECL (c);
9896 : 76 : if (!processing_template_decl
9897 : 74 : && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9898 : 74 : && !TYPE_REF_P (TREE_TYPE (t))
9899 : 143 : && !cxx_mark_addressable (t))
9900 : : remove = true;
9901 : 76 : goto check_dup_generic;
9902 : :
9903 : : case OMP_CLAUSE_NOWAIT:
9904 : : case OMP_CLAUSE_DEFAULT:
9905 : : case OMP_CLAUSE_UNTIED:
9906 : : case OMP_CLAUSE_COLLAPSE:
9907 : : case OMP_CLAUSE_PARALLEL:
9908 : : case OMP_CLAUSE_FOR:
9909 : : case OMP_CLAUSE_SECTIONS:
9910 : : case OMP_CLAUSE_TASKGROUP:
9911 : : case OMP_CLAUSE_PROC_BIND:
9912 : : case OMP_CLAUSE_DEVICE_TYPE:
9913 : : case OMP_CLAUSE_NOGROUP:
9914 : : case OMP_CLAUSE_THREADS:
9915 : : case OMP_CLAUSE_SIMD:
9916 : : case OMP_CLAUSE_DEFAULTMAP:
9917 : : case OMP_CLAUSE_BIND:
9918 : : case OMP_CLAUSE_AUTO:
9919 : : case OMP_CLAUSE_INDEPENDENT:
9920 : : case OMP_CLAUSE_SEQ:
9921 : : case OMP_CLAUSE_IF_PRESENT:
9922 : : case OMP_CLAUSE_FINALIZE:
9923 : : case OMP_CLAUSE_NOHOST:
9924 : : case OMP_CLAUSE_INDIRECT:
9925 : : break;
9926 : :
9927 : 231 : case OMP_CLAUSE_MERGEABLE:
9928 : 231 : mergeable_seen = true;
9929 : 231 : break;
9930 : :
9931 : 322 : case OMP_CLAUSE_TILE:
9932 : 754 : for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
9933 : 432 : list = TREE_CHAIN (list))
9934 : : {
9935 : 432 : t = TREE_VALUE (list);
9936 : :
9937 : 432 : if (t == error_mark_node)
9938 : : remove = true;
9939 : 403 : else if (!type_dependent_expression_p (t)
9940 : 403 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9941 : : {
9942 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9943 : : "%<tile%> argument needs integral type");
9944 : 3 : remove = true;
9945 : : }
9946 : : else
9947 : : {
9948 : 400 : t = mark_rvalue_use (t);
9949 : 400 : if (!processing_template_decl)
9950 : : {
9951 : : /* Zero is used to indicate '*', we permit you
9952 : : to get there via an ICE of value zero. */
9953 : 385 : t = maybe_constant_value (t);
9954 : 385 : if (!tree_fits_shwi_p (t)
9955 : 369 : || tree_to_shwi (t) < 0)
9956 : : {
9957 : 40 : error_at (OMP_CLAUSE_LOCATION (c),
9958 : : "%<tile%> argument needs positive "
9959 : : "integral constant");
9960 : 40 : remove = true;
9961 : : }
9962 : : }
9963 : : }
9964 : :
9965 : : /* Update list item. */
9966 : 432 : TREE_VALUE (list) = t;
9967 : : }
9968 : : break;
9969 : :
9970 : 1027 : case OMP_CLAUSE_SIZES:
9971 : 1027 : for (tree list = OMP_CLAUSE_SIZES_LIST (c);
9972 : 2688 : !remove && list; list = TREE_CHAIN (list))
9973 : : {
9974 : 1661 : t = TREE_VALUE (list);
9975 : :
9976 : 1661 : if (t == error_mark_node)
9977 : 0 : t = integer_one_node;
9978 : 1661 : else if (!type_dependent_expression_p (t)
9979 : 1661 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9980 : : {
9981 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
9982 : : "%<sizes%> argument needs positive integral "
9983 : : "constant");
9984 : 8 : t = integer_one_node;
9985 : : }
9986 : : else
9987 : : {
9988 : 1653 : t = mark_rvalue_use (t);
9989 : 1653 : if (!processing_template_decl)
9990 : : {
9991 : 1636 : t = maybe_constant_value (t);
9992 : 1636 : HOST_WIDE_INT n;
9993 : 1636 : if (!tree_fits_shwi_p (t)
9994 : 1632 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
9995 : 1632 : || (n = tree_to_shwi (t)) <= 0
9996 : 3240 : || (int)n != n)
9997 : : {
9998 : 32 : error_at (OMP_CLAUSE_LOCATION (c),
9999 : : "%<sizes%> argument needs positive "
10000 : : "integral constant");
10001 : 32 : t = integer_one_node;
10002 : : }
10003 : : }
10004 : : }
10005 : :
10006 : : /* Update list item. */
10007 : 1661 : TREE_VALUE (list) = t;
10008 : : }
10009 : : break;
10010 : :
10011 : 630 : case OMP_CLAUSE_ORDERED:
10012 : 630 : ordered_seen = true;
10013 : 630 : break;
10014 : :
10015 : 1549 : case OMP_CLAUSE_ORDER:
10016 : 1549 : if (order_seen)
10017 : : remove = true;
10018 : : else
10019 : : order_seen = true;
10020 : : break;
10021 : :
10022 : 638 : case OMP_CLAUSE_INBRANCH:
10023 : 638 : case OMP_CLAUSE_NOTINBRANCH:
10024 : 638 : if (branch_seen)
10025 : : {
10026 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
10027 : : "%<inbranch%> clause is incompatible with "
10028 : : "%<notinbranch%>");
10029 : 3 : remove = true;
10030 : : }
10031 : : branch_seen = true;
10032 : : break;
10033 : :
10034 : 297 : case OMP_CLAUSE_INCLUSIVE:
10035 : 297 : case OMP_CLAUSE_EXCLUSIVE:
10036 : 297 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10037 : 297 : if (!t)
10038 : 297 : t = OMP_CLAUSE_DECL (c);
10039 : 297 : if (t == current_class_ptr)
10040 : : {
10041 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
10042 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
10043 : : " clauses");
10044 : 0 : remove = true;
10045 : 0 : break;
10046 : : }
10047 : 297 : if (!VAR_P (t)
10048 : : && TREE_CODE (t) != PARM_DECL
10049 : : && TREE_CODE (t) != FIELD_DECL)
10050 : : {
10051 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
10052 : : break;
10053 : 0 : if (DECL_P (t))
10054 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
10055 : : "%qD is not a variable in clause %qs", t,
10056 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10057 : : else
10058 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
10059 : : "%qE is not a variable in clause %qs", t,
10060 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10061 : : remove = true;
10062 : : }
10063 : : break;
10064 : :
10065 : : case OMP_CLAUSE_FULL:
10066 : : break;
10067 : :
10068 : 470 : case OMP_CLAUSE_PARTIAL:
10069 : 470 : partial_seen = true;
10070 : 470 : t = OMP_CLAUSE_PARTIAL_EXPR (c);
10071 : 470 : if (!t)
10072 : : break;
10073 : :
10074 : 313 : if (t == error_mark_node)
10075 : : t = NULL_TREE;
10076 : 313 : else if (!type_dependent_expression_p (t)
10077 : 313 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
10078 : : {
10079 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
10080 : : "%<partial%> argument needs positive constant "
10081 : : "integer expression");
10082 : 3 : t = NULL_TREE;
10083 : : }
10084 : : else
10085 : : {
10086 : 310 : t = mark_rvalue_use (t);
10087 : 310 : if (!processing_template_decl)
10088 : : {
10089 : 292 : t = maybe_constant_value (t);
10090 : :
10091 : 292 : HOST_WIDE_INT n;
10092 : 584 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
10093 : 292 : || !tree_fits_shwi_p (t)
10094 : 286 : || (n = tree_to_shwi (t)) <= 0
10095 : 560 : || (int)n != n)
10096 : : {
10097 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
10098 : : "%<partial%> argument needs positive "
10099 : : "constant integer expression");
10100 : 24 : t = NULL_TREE;
10101 : : }
10102 : : }
10103 : : }
10104 : :
10105 : 313 : OMP_CLAUSE_PARTIAL_EXPR (c) = t;
10106 : 313 : break;
10107 : 549 : case OMP_CLAUSE_INIT:
10108 : 549 : init_seen = true;
10109 : 549 : OMP_CLAUSE_INIT_PREFER_TYPE (c)
10110 : 549 : = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
10111 : 549 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
10112 : 271 : init_no_targetsync_clause = c;
10113 : : /* FALLTHRU */
10114 : 844 : case OMP_CLAUSE_DESTROY:
10115 : 844 : case OMP_CLAUSE_USE:
10116 : 844 : init_use_destroy_seen = true;
10117 : 844 : t = OMP_CLAUSE_DECL (c);
10118 : 844 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
10119 : : {
10120 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
10121 : : "%qD appears more than once in action clauses", t);
10122 : 9 : remove = true;
10123 : 9 : break;
10124 : : }
10125 : 835 : bitmap_set_bit (&generic_head, DECL_UID (t));
10126 : : /* FALLTHRU */
10127 : 1099 : case OMP_CLAUSE_INTEROP:
10128 : 1099 : if (!processing_template_decl)
10129 : : {
10130 : 1003 : if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
10131 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) && */
10132 : 1003 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
10133 : : {
10134 : 126 : error_at (OMP_CLAUSE_LOCATION (c),
10135 : : "%qD must be of %<omp_interop_t%>",
10136 : 63 : OMP_CLAUSE_DECL (c));
10137 : 63 : remove = true;
10138 : : }
10139 : 940 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
10140 : 481 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
10141 : 1058 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
10142 : : {
10143 : 36 : error_at (OMP_CLAUSE_LOCATION (c),
10144 : 18 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
10145 : 18 : remove = true;
10146 : : }
10147 : : }
10148 : 1099 : pc = &OMP_CLAUSE_CHAIN (c);
10149 : 1099 : break;
10150 : 0 : default:
10151 : 0 : gcc_unreachable ();
10152 : 54 : }
10153 : :
10154 : 96978 : if (remove)
10155 : : {
10156 : 2601 : if (grp_start_p)
10157 : : {
10158 : : /* If we found a clause to remove, we want to remove the whole
10159 : : expanded group, otherwise gimplify
10160 : : (omp_resolve_clause_dependencies) can get confused. */
10161 : 820 : *grp_start_p = grp_sentinel;
10162 : 820 : pc = grp_start_p;
10163 : 820 : grp_start_p = NULL;
10164 : : }
10165 : : else
10166 : 1781 : *pc = OMP_CLAUSE_CHAIN (c);
10167 : : }
10168 : : else
10169 : 94377 : pc = &OMP_CLAUSE_CHAIN (c);
10170 : : }
10171 : :
10172 : 62465 : if (grp_start_p
10173 : 62465 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
10174 : 131 : for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
10175 : 80 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
10176 : :
10177 : 62465 : if (reduction_seen < 0 && (ordered_seen || schedule_seen))
10178 : 62465 : reduction_seen = -2;
10179 : :
10180 : 157799 : for (pc = &clauses, c = clauses; c ; c = *pc)
10181 : : {
10182 : 95334 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
10183 : 95334 : bool remove = false;
10184 : 95334 : bool need_complete_type = false;
10185 : 95334 : bool need_default_ctor = false;
10186 : 95334 : bool need_copy_ctor = false;
10187 : 95334 : bool need_copy_assignment = false;
10188 : 95334 : bool need_implicitly_determined = false;
10189 : 95334 : bool need_dtor = false;
10190 : 95334 : tree type, inner_type;
10191 : :
10192 : 95334 : switch (c_kind)
10193 : : {
10194 : : case OMP_CLAUSE_SHARED:
10195 : : need_implicitly_determined = true;
10196 : : break;
10197 : 2511 : case OMP_CLAUSE_PRIVATE:
10198 : 2511 : need_complete_type = true;
10199 : 2511 : need_default_ctor = true;
10200 : 2511 : need_dtor = true;
10201 : 2511 : need_implicitly_determined = true;
10202 : 2511 : break;
10203 : 3130 : case OMP_CLAUSE_FIRSTPRIVATE:
10204 : 3130 : need_complete_type = true;
10205 : 3130 : need_copy_ctor = true;
10206 : 3130 : need_dtor = true;
10207 : 3130 : need_implicitly_determined = true;
10208 : 3130 : break;
10209 : 2763 : case OMP_CLAUSE_LASTPRIVATE:
10210 : 2763 : need_complete_type = true;
10211 : 2763 : need_copy_assignment = true;
10212 : 2763 : need_implicitly_determined = true;
10213 : 2763 : break;
10214 : 7285 : case OMP_CLAUSE_REDUCTION:
10215 : 7285 : if (reduction_seen == -2)
10216 : 27 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
10217 : 7285 : if (OMP_CLAUSE_REDUCTION_INSCAN (c))
10218 : 421 : need_copy_assignment = true;
10219 : : need_implicitly_determined = true;
10220 : : break;
10221 : : case OMP_CLAUSE_IN_REDUCTION:
10222 : : case OMP_CLAUSE_TASK_REDUCTION:
10223 : : case OMP_CLAUSE_INCLUSIVE:
10224 : : case OMP_CLAUSE_EXCLUSIVE:
10225 : : need_implicitly_determined = true;
10226 : : break;
10227 : 1550 : case OMP_CLAUSE_LINEAR:
10228 : 1550 : if (ort != C_ORT_OMP_DECLARE_SIMD)
10229 : : need_implicitly_determined = true;
10230 : 679 : else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
10231 : 721 : && !bitmap_bit_p (&map_head,
10232 : 42 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
10233 : : {
10234 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10235 : : "%<linear%> clause step is a parameter %qD not "
10236 : : "specified in %<uniform%> clause",
10237 : 6 : OMP_CLAUSE_LINEAR_STEP (c));
10238 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
10239 : 73864 : continue;
10240 : : }
10241 : : break;
10242 : : case OMP_CLAUSE_COPYPRIVATE:
10243 : 366 : need_copy_assignment = true;
10244 : : break;
10245 : : case OMP_CLAUSE_COPYIN:
10246 : 366 : need_copy_assignment = true;
10247 : : break;
10248 : 798 : case OMP_CLAUSE_SIMDLEN:
10249 : 798 : if (safelen
10250 : 345 : && !processing_template_decl
10251 : 1143 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
10252 : 345 : OMP_CLAUSE_SIMDLEN_EXPR (c)))
10253 : : {
10254 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
10255 : : "%<simdlen%> clause value is bigger than "
10256 : : "%<safelen%> clause value");
10257 : 0 : OMP_CLAUSE_SIMDLEN_EXPR (c)
10258 : 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
10259 : : }
10260 : 798 : pc = &OMP_CLAUSE_CHAIN (c);
10261 : 798 : continue;
10262 : 3853 : case OMP_CLAUSE_SCHEDULE:
10263 : 3853 : if (ordered_seen
10264 : 3853 : && (OMP_CLAUSE_SCHEDULE_KIND (c)
10265 : : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
10266 : : {
10267 : 21 : error_at (OMP_CLAUSE_LOCATION (c),
10268 : : "%<nonmonotonic%> schedule modifier specified "
10269 : : "together with %<ordered%> clause");
10270 : 42 : OMP_CLAUSE_SCHEDULE_KIND (c)
10271 : 21 : = (enum omp_clause_schedule_kind)
10272 : 21 : (OMP_CLAUSE_SCHEDULE_KIND (c)
10273 : : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
10274 : : }
10275 : 3853 : if (reduction_seen == -2)
10276 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
10277 : : "%qs clause specified together with %<inscan%> "
10278 : : "%<reduction%> clause", "schedule");
10279 : 3853 : pc = &OMP_CLAUSE_CHAIN (c);
10280 : 3853 : continue;
10281 : 51 : case OMP_CLAUSE_NOGROUP:
10282 : 51 : if (reduction_seen)
10283 : : {
10284 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
10285 : : "%<nogroup%> clause must not be used together with "
10286 : : "%<reduction%> clause");
10287 : 3 : *pc = OMP_CLAUSE_CHAIN (c);
10288 : 3 : continue;
10289 : : }
10290 : 48 : pc = &OMP_CLAUSE_CHAIN (c);
10291 : 48 : continue;
10292 : 165 : case OMP_CLAUSE_GRAINSIZE:
10293 : 165 : if (num_tasks_seen)
10294 : : {
10295 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10296 : : "%<grainsize%> clause must not be used together with "
10297 : : "%<num_tasks%> clause");
10298 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
10299 : 6 : continue;
10300 : : }
10301 : 159 : pc = &OMP_CLAUSE_CHAIN (c);
10302 : 159 : continue;
10303 : 630 : case OMP_CLAUSE_ORDERED:
10304 : 630 : if (reduction_seen == -2)
10305 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10306 : : "%qs clause specified together with %<inscan%> "
10307 : : "%<reduction%> clause", "ordered");
10308 : 630 : pc = &OMP_CLAUSE_CHAIN (c);
10309 : 630 : continue;
10310 : 1525 : case OMP_CLAUSE_ORDER:
10311 : 1525 : if (ordered_seen)
10312 : : {
10313 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
10314 : : "%<order%> clause must not be used together "
10315 : : "with %<ordered%> clause");
10316 : 12 : *pc = OMP_CLAUSE_CHAIN (c);
10317 : 12 : continue;
10318 : : }
10319 : 1513 : pc = &OMP_CLAUSE_CHAIN (c);
10320 : 1513 : continue;
10321 : 57 : case OMP_CLAUSE_DETACH:
10322 : 57 : if (mergeable_seen)
10323 : : {
10324 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10325 : : "%<detach%> clause must not be used together with "
10326 : : "%<mergeable%> clause");
10327 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
10328 : 6 : continue;
10329 : : }
10330 : 51 : pc = &OMP_CLAUSE_CHAIN (c);
10331 : 51 : continue;
10332 : 15637 : case OMP_CLAUSE_MAP:
10333 : 15637 : if (target_in_reduction_seen && !processing_template_decl)
10334 : : {
10335 : 684 : t = OMP_CLAUSE_DECL (c);
10336 : 684 : while (handled_component_p (t)
10337 : : || INDIRECT_REF_P (t)
10338 : : || TREE_CODE (t) == ADDR_EXPR
10339 : : || TREE_CODE (t) == MEM_REF
10340 : 804 : || TREE_CODE (t) == NON_LVALUE_EXPR)
10341 : 120 : t = TREE_OPERAND (t, 0);
10342 : 684 : if (DECL_P (t)
10343 : 684 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
10344 : 342 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
10345 : : }
10346 : 15637 : pc = &OMP_CLAUSE_CHAIN (c);
10347 : 15637 : continue;
10348 : 225 : case OMP_CLAUSE_FULL:
10349 : 225 : if (partial_seen)
10350 : : {
10351 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
10352 : : "%<full%> clause must not be used together "
10353 : : "with %<partial%> clause");
10354 : 12 : *pc = OMP_CLAUSE_CHAIN (c);
10355 : 12 : continue;
10356 : : }
10357 : 213 : pc = &OMP_CLAUSE_CHAIN (c);
10358 : 213 : continue;
10359 : 6894 : case OMP_CLAUSE_NOWAIT:
10360 : 6894 : if (copyprivate_seen)
10361 : : {
10362 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10363 : : "%<nowait%> clause must not be used together "
10364 : : "with %<copyprivate%> clause");
10365 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
10366 : 6 : continue;
10367 : : }
10368 : : /* FALLTHRU */
10369 : 50273 : default:
10370 : 50273 : pc = &OMP_CLAUSE_CHAIN (c);
10371 : 50273 : continue;
10372 : : }
10373 : :
10374 : 22108 : t = OMP_CLAUSE_DECL (c);
10375 : 22108 : switch (c_kind)
10376 : : {
10377 : 2763 : case OMP_CLAUSE_LASTPRIVATE:
10378 : 2763 : if (DECL_P (t)
10379 : 2763 : && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
10380 : : {
10381 : 2666 : need_default_ctor = true;
10382 : 2666 : need_dtor = true;
10383 : : }
10384 : : break;
10385 : :
10386 : 9424 : case OMP_CLAUSE_REDUCTION:
10387 : 9424 : case OMP_CLAUSE_IN_REDUCTION:
10388 : 9424 : case OMP_CLAUSE_TASK_REDUCTION:
10389 : 9424 : if (allocate_seen)
10390 : : {
10391 : 1561 : if (TREE_CODE (t) == MEM_REF)
10392 : : {
10393 : 162 : t = TREE_OPERAND (t, 0);
10394 : 162 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
10395 : 0 : t = TREE_OPERAND (t, 0);
10396 : 162 : if (TREE_CODE (t) == ADDR_EXPR
10397 : 120 : || INDIRECT_REF_P (t))
10398 : 80 : t = TREE_OPERAND (t, 0);
10399 : 162 : if (DECL_P (t))
10400 : 162 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10401 : : }
10402 : 1399 : else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10403 : : {
10404 : 192 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10405 : 96 : t = TREE_OPERAND (t, 0);
10406 : 96 : if (DECL_P (t))
10407 : 96 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10408 : 96 : t = OMP_CLAUSE_DECL (c);
10409 : : }
10410 : 1303 : else if (DECL_P (t))
10411 : 1303 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10412 : 1561 : t = OMP_CLAUSE_DECL (c);
10413 : : }
10414 : 9424 : if (processing_template_decl
10415 : 863 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10416 : : break;
10417 : 8854 : if (finish_omp_reduction_clause (c, &need_default_ctor,
10418 : : &need_dtor))
10419 : : remove = true;
10420 : : else
10421 : 8770 : t = OMP_CLAUSE_DECL (c);
10422 : : break;
10423 : :
10424 : 274 : case OMP_CLAUSE_COPYIN:
10425 : 274 : if (processing_template_decl
10426 : 0 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10427 : : break;
10428 : 274 : if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
10429 : : {
10430 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
10431 : : "%qE must be %<threadprivate%> for %<copyin%>", t);
10432 : 15 : remove = true;
10433 : : }
10434 : : break;
10435 : :
10436 : : default:
10437 : : break;
10438 : : }
10439 : :
10440 : 22108 : if (processing_template_decl
10441 : 1544 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10442 : : {
10443 : 632 : pc = &OMP_CLAUSE_CHAIN (c);
10444 : 632 : continue;
10445 : : }
10446 : :
10447 : 21476 : if (need_complete_type || need_copy_assignment)
10448 : : {
10449 : 9135 : t = require_complete_type (t);
10450 : 9135 : if (t == error_mark_node)
10451 : : remove = true;
10452 : 9111 : else if (!processing_template_decl
10453 : 8728 : && TYPE_REF_P (TREE_TYPE (t))
10454 : 9639 : && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
10455 : : remove = true;
10456 : : }
10457 : 21476 : if (need_implicitly_determined)
10458 : : {
10459 : 20438 : const char *share_name = NULL;
10460 : :
10461 : 20438 : if (allocate_seen
10462 : 4945 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10463 : 24504 : && DECL_P (t))
10464 : 3856 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10465 : :
10466 : 20438 : if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
10467 : : share_name = "threadprivate";
10468 : 20396 : else switch (cxx_omp_predetermined_sharing_1 (t))
10469 : : {
10470 : : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
10471 : : break;
10472 : 47 : case OMP_CLAUSE_DEFAULT_SHARED:
10473 : 47 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10474 : 30 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
10475 : 64 : && c_omp_predefined_variable (t))
10476 : : /* The __func__ variable and similar function-local predefined
10477 : : variables may be listed in a shared or firstprivate
10478 : : clause. */
10479 : : break;
10480 : 31 : if (VAR_P (t)
10481 : 31 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10482 : 9 : && TREE_STATIC (t)
10483 : 40 : && cxx_omp_const_qual_no_mutable (t))
10484 : : {
10485 : 6 : tree ctx = CP_DECL_CONTEXT (t);
10486 : : /* const qualified static data members without mutable
10487 : : member may be specified in firstprivate clause. */
10488 : 6 : if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
10489 : : break;
10490 : : }
10491 : : share_name = "shared";
10492 : : break;
10493 : : case OMP_CLAUSE_DEFAULT_PRIVATE:
10494 : : share_name = "private";
10495 : : break;
10496 : 0 : default:
10497 : 0 : gcc_unreachable ();
10498 : : }
10499 : : if (share_name)
10500 : : {
10501 : 67 : error_at (OMP_CLAUSE_LOCATION (c),
10502 : : "%qE is predetermined %qs for %qs",
10503 : : omp_clause_printable_decl (t), share_name,
10504 : 67 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10505 : 67 : remove = true;
10506 : : }
10507 : 20371 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10508 : 18312 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
10509 : 35582 : && cxx_omp_const_qual_no_mutable (t))
10510 : : {
10511 : 126 : error_at (OMP_CLAUSE_LOCATION (c),
10512 : : "%<const%> qualified %qE without %<mutable%> member "
10513 : : "may appear only in %<shared%> or %<firstprivate%> "
10514 : : "clauses", omp_clause_printable_decl (t));
10515 : 63 : remove = true;
10516 : : }
10517 : : }
10518 : :
10519 : 21476 : if (detach_seen
10520 : 16 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10521 : 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
10522 : 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10523 : 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
10524 : 21492 : && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
10525 : : {
10526 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10527 : : "the event handle of a %<detach%> clause "
10528 : : "should not be in a data-sharing clause");
10529 : 6 : remove = true;
10530 : : }
10531 : :
10532 : : /* We're interested in the base element, not arrays. */
10533 : 21476 : inner_type = type = TREE_TYPE (t);
10534 : 21476 : if ((need_complete_type
10535 : : || need_copy_assignment
10536 : 12341 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
10537 : 5708 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
10538 : 4235 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
10539 : 29909 : && TYPE_REF_P (inner_type))
10540 : 850 : inner_type = TREE_TYPE (inner_type);
10541 : 24023 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
10542 : 2547 : inner_type = TREE_TYPE (inner_type);
10543 : :
10544 : : /* Check for special function availability by building a call to one.
10545 : : Save the results, because later we won't be in the right context
10546 : : for making these queries. */
10547 : 2384 : if (CLASS_TYPE_P (inner_type)
10548 : 2384 : && COMPLETE_TYPE_P (inner_type)
10549 : 2315 : && (need_default_ctor || need_copy_ctor
10550 : 1079 : || need_copy_assignment || need_dtor)
10551 : 1991 : && !type_dependent_expression_p (t)
10552 : 23467 : && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
10553 : : need_copy_ctor, need_copy_assignment,
10554 : : need_dtor))
10555 : : remove = true;
10556 : :
10557 : 21476 : if (!remove
10558 : 21476 : && c_kind == OMP_CLAUSE_SHARED
10559 : 2056 : && processing_template_decl)
10560 : : {
10561 : 125 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10562 : 125 : if (t)
10563 : 5 : OMP_CLAUSE_DECL (c) = t;
10564 : : }
10565 : :
10566 : 21476 : if (remove)
10567 : 292 : *pc = OMP_CLAUSE_CHAIN (c);
10568 : : else
10569 : 21184 : pc = &OMP_CLAUSE_CHAIN (c);
10570 : : }
10571 : :
10572 : 62465 : if (allocate_seen)
10573 : 16701 : for (pc = &clauses, c = clauses; c ; c = *pc)
10574 : : {
10575 : 14447 : bool remove = false;
10576 : 14447 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
10577 : 2492 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
10578 : 2095 : && DECL_P (OMP_CLAUSE_DECL (c))
10579 : 16542 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
10580 : : {
10581 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
10582 : : "%qD specified in %<allocate%> clause but not in "
10583 : 15 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
10584 : 15 : remove = true;
10585 : : }
10586 : 14447 : if (remove)
10587 : 15 : *pc = OMP_CLAUSE_CHAIN (c);
10588 : : else
10589 : 14432 : pc = &OMP_CLAUSE_CHAIN (c);
10590 : : }
10591 : :
10592 : 62465 : if (ort == C_ORT_OMP_INTEROP
10593 : 62465 : && depend_clause
10594 : 60 : && (!init_use_destroy_seen
10595 : 57 : || (init_seen && init_no_targetsync_clause)))
10596 : : {
10597 : 9 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
10598 : : "%<depend%> clause requires action clauses with "
10599 : : "%<targetsync%> interop-type");
10600 : 9 : if (init_no_targetsync_clause)
10601 : 6 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
10602 : : "%<init%> clause lacks the %<targetsync%> modifier");
10603 : : }
10604 : :
10605 : 62465 : bitmap_obstack_release (NULL);
10606 : 62465 : return clauses;
10607 : : }
10608 : :
10609 : : /* Start processing OpenMP clauses that can include any
10610 : : privatization clauses for non-static data members. */
10611 : :
10612 : : tree
10613 : 48332 : push_omp_privatization_clauses (bool ignore_next)
10614 : : {
10615 : 48332 : if (omp_private_member_ignore_next)
10616 : : {
10617 : 656 : omp_private_member_ignore_next = ignore_next;
10618 : 656 : return NULL_TREE;
10619 : : }
10620 : 47676 : omp_private_member_ignore_next = ignore_next;
10621 : 47676 : if (omp_private_member_map)
10622 : 24 : omp_private_member_vec.safe_push (error_mark_node);
10623 : 47676 : return push_stmt_list ();
10624 : : }
10625 : :
10626 : : /* Revert remapping of any non-static data members since
10627 : : the last push_omp_privatization_clauses () call. */
10628 : :
10629 : : void
10630 : 48326 : pop_omp_privatization_clauses (tree stmt)
10631 : : {
10632 : 48326 : if (stmt == NULL_TREE)
10633 : : return;
10634 : 47670 : stmt = pop_stmt_list (stmt);
10635 : 47670 : if (omp_private_member_map)
10636 : : {
10637 : 1280 : while (!omp_private_member_vec.is_empty ())
10638 : : {
10639 : 850 : tree t = omp_private_member_vec.pop ();
10640 : 850 : if (t == error_mark_node)
10641 : : {
10642 : 24 : add_stmt (stmt);
10643 : 24 : return;
10644 : : }
10645 : 826 : bool no_decl_expr = t == integer_zero_node;
10646 : 826 : if (no_decl_expr)
10647 : 136 : t = omp_private_member_vec.pop ();
10648 : 826 : tree *v = omp_private_member_map->get (t);
10649 : 826 : gcc_assert (v);
10650 : 826 : if (!no_decl_expr)
10651 : 690 : add_decl_expr (*v);
10652 : 826 : omp_private_member_map->remove (t);
10653 : : }
10654 : 860 : delete omp_private_member_map;
10655 : 430 : omp_private_member_map = NULL;
10656 : : }
10657 : 47646 : add_stmt (stmt);
10658 : : }
10659 : :
10660 : : /* Remember OpenMP privatization clauses mapping and clear it.
10661 : : Used for lambdas. */
10662 : :
10663 : : void
10664 : 19946394 : save_omp_privatization_clauses (vec<tree> &save)
10665 : : {
10666 : 19946394 : save = vNULL;
10667 : 19946394 : if (omp_private_member_ignore_next)
10668 : 2 : save.safe_push (integer_one_node);
10669 : 19946394 : omp_private_member_ignore_next = false;
10670 : 19946394 : if (!omp_private_member_map)
10671 : : return;
10672 : :
10673 : 0 : while (!omp_private_member_vec.is_empty ())
10674 : : {
10675 : 0 : tree t = omp_private_member_vec.pop ();
10676 : 0 : if (t == error_mark_node)
10677 : : {
10678 : 0 : save.safe_push (t);
10679 : 0 : continue;
10680 : : }
10681 : 0 : tree n = t;
10682 : 0 : if (t == integer_zero_node)
10683 : 0 : t = omp_private_member_vec.pop ();
10684 : 0 : tree *v = omp_private_member_map->get (t);
10685 : 0 : gcc_assert (v);
10686 : 0 : save.safe_push (*v);
10687 : 0 : save.safe_push (t);
10688 : 0 : if (n != t)
10689 : 0 : save.safe_push (n);
10690 : : }
10691 : 0 : delete omp_private_member_map;
10692 : 0 : omp_private_member_map = NULL;
10693 : : }
10694 : :
10695 : : /* Restore OpenMP privatization clauses mapping saved by the
10696 : : above function. */
10697 : :
10698 : : void
10699 : 19946394 : restore_omp_privatization_clauses (vec<tree> &save)
10700 : : {
10701 : 19946394 : gcc_assert (omp_private_member_vec.is_empty ());
10702 : 19946394 : omp_private_member_ignore_next = false;
10703 : 19946394 : if (save.is_empty ())
10704 : : return;
10705 : 4 : if (save.length () == 1 && save[0] == integer_one_node)
10706 : : {
10707 : 2 : omp_private_member_ignore_next = true;
10708 : 2 : save.release ();
10709 : 2 : return;
10710 : : }
10711 : :
10712 : 0 : omp_private_member_map = new hash_map <tree, tree>;
10713 : 0 : while (!save.is_empty ())
10714 : : {
10715 : 0 : tree t = save.pop ();
10716 : 0 : tree n = t;
10717 : 0 : if (t != error_mark_node)
10718 : : {
10719 : 0 : if (t == integer_one_node)
10720 : : {
10721 : 0 : omp_private_member_ignore_next = true;
10722 : 0 : gcc_assert (save.is_empty ());
10723 : 0 : break;
10724 : : }
10725 : 0 : if (t == integer_zero_node)
10726 : 0 : t = save.pop ();
10727 : 0 : tree &v = omp_private_member_map->get_or_insert (t);
10728 : 0 : v = save.pop ();
10729 : : }
10730 : 0 : omp_private_member_vec.safe_push (t);
10731 : 0 : if (n != t)
10732 : 0 : omp_private_member_vec.safe_push (n);
10733 : : }
10734 : 0 : save.release ();
10735 : : }
10736 : :
10737 : : /* For all variables in the tree_list VARS, mark them as thread local. */
10738 : :
10739 : : void
10740 : 238 : finish_omp_threadprivate (tree vars)
10741 : : {
10742 : 238 : tree t;
10743 : :
10744 : : /* Mark every variable in VARS to be assigned thread local storage. */
10745 : 509 : for (t = vars; t; t = TREE_CHAIN (t))
10746 : : {
10747 : 271 : tree v = TREE_PURPOSE (t);
10748 : 271 : location_t loc = EXPR_LOCATION (TREE_VALUE (t));
10749 : :
10750 : 271 : if (error_operand_p (v))
10751 : : ;
10752 : 271 : else if (!VAR_P (v))
10753 : 6 : error_at (loc, "%<threadprivate%> %qD is not file, namespace "
10754 : : "or block scope variable", v);
10755 : : /* If V had already been marked threadprivate, it doesn't matter
10756 : : whether it had been used prior to this point. */
10757 : 265 : else if (TREE_USED (v)
10758 : 265 : && (DECL_LANG_SPECIFIC (v) == NULL
10759 : 3 : || !CP_DECL_THREADPRIVATE_P (v)))
10760 : 6 : error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10761 : 259 : else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10762 : 6 : error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10763 : 253 : else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
10764 : 3 : error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10765 : 201 : else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
10766 : 273 : && CP_DECL_CONTEXT (v) != current_class_type)
10767 : 6 : error_at (loc, "%<threadprivate%> %qE directive not "
10768 : 6 : "in %qT definition", v, CP_DECL_CONTEXT (v));
10769 : : else
10770 : : {
10771 : : /* Allocate a LANG_SPECIFIC structure for V, if needed. */
10772 : 244 : if (DECL_LANG_SPECIFIC (v) == NULL)
10773 : 200 : retrofit_lang_decl (v);
10774 : :
10775 : 244 : if (! CP_DECL_THREAD_LOCAL_P (v))
10776 : : {
10777 : 244 : CP_DECL_THREAD_LOCAL_P (v) = true;
10778 : 244 : set_decl_tls_model (v, decl_default_tls_model (v));
10779 : : /* If rtl has been already set for this var, call
10780 : : make_decl_rtl once again, so that encode_section_info
10781 : : has a chance to look at the new decl flags. */
10782 : 244 : if (DECL_RTL_SET_P (v))
10783 : 0 : make_decl_rtl (v);
10784 : : }
10785 : 244 : CP_DECL_THREADPRIVATE_P (v) = 1;
10786 : : }
10787 : : }
10788 : 238 : }
10789 : :
10790 : : /* Build an OpenMP structured block. */
10791 : :
10792 : : tree
10793 : 63890 : begin_omp_structured_block (void)
10794 : : {
10795 : 63890 : return do_pushlevel (sk_omp);
10796 : : }
10797 : :
10798 : : tree
10799 : 63869 : finish_omp_structured_block (tree block)
10800 : : {
10801 : 63869 : return do_poplevel (block);
10802 : : }
10803 : :
10804 : : /* Similarly, except force the retention of the BLOCK. */
10805 : :
10806 : : tree
10807 : 14795 : begin_omp_parallel (void)
10808 : : {
10809 : 14795 : keep_next_level (true);
10810 : 14795 : return begin_omp_structured_block ();
10811 : : }
10812 : :
10813 : : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
10814 : : statement. */
10815 : :
10816 : : tree
10817 : 768 : finish_oacc_data (tree clauses, tree block)
10818 : : {
10819 : 768 : tree stmt;
10820 : :
10821 : 768 : block = finish_omp_structured_block (block);
10822 : :
10823 : 768 : stmt = make_node (OACC_DATA);
10824 : 768 : TREE_TYPE (stmt) = void_type_node;
10825 : 768 : OACC_DATA_CLAUSES (stmt) = clauses;
10826 : 768 : OACC_DATA_BODY (stmt) = block;
10827 : :
10828 : 768 : return add_stmt (stmt);
10829 : : }
10830 : :
10831 : : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
10832 : : statement. */
10833 : :
10834 : : tree
10835 : 55 : finish_oacc_host_data (tree clauses, tree block)
10836 : : {
10837 : 55 : tree stmt;
10838 : :
10839 : 55 : block = finish_omp_structured_block (block);
10840 : :
10841 : 55 : stmt = make_node (OACC_HOST_DATA);
10842 : 55 : TREE_TYPE (stmt) = void_type_node;
10843 : 55 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
10844 : 55 : OACC_HOST_DATA_BODY (stmt) = block;
10845 : :
10846 : 55 : return add_stmt (stmt);
10847 : : }
10848 : :
10849 : : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
10850 : : statement. */
10851 : :
10852 : : tree
10853 : 4653 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
10854 : : {
10855 : 4653 : body = finish_omp_structured_block (body);
10856 : :
10857 : 4653 : tree stmt = make_node (code);
10858 : 4653 : TREE_TYPE (stmt) = void_type_node;
10859 : 4653 : OMP_BODY (stmt) = body;
10860 : 4653 : OMP_CLAUSES (stmt) = clauses;
10861 : :
10862 : 4653 : return add_stmt (stmt);
10863 : : }
10864 : :
10865 : : /* Used to walk OpenMP target directive body. */
10866 : :
10867 : : struct omp_target_walk_data
10868 : : {
10869 : : /* Holds the 'this' expression found in current function. */
10870 : : tree current_object;
10871 : :
10872 : : /* True if the 'this' expression was accessed in the target body. */
10873 : : bool this_expr_accessed;
10874 : :
10875 : : /* For non-static functions, record which pointer-typed members were
10876 : : accessed, and the whole expression. */
10877 : : hash_map<tree, tree> ptr_members_accessed;
10878 : :
10879 : : /* Record which lambda objects were accessed in target body. */
10880 : : hash_set<tree> lambda_objects_accessed;
10881 : :
10882 : : /* For lambda functions, the __closure object expression of the current
10883 : : function, and the set of captured variables accessed in target body. */
10884 : : tree current_closure;
10885 : : hash_set<tree> closure_vars_accessed;
10886 : :
10887 : : /* Local variables declared inside a BIND_EXPR, used to filter out such
10888 : : variables when recording lambda_objects_accessed. */
10889 : : hash_set<tree> local_decls;
10890 : :
10891 : : omp_mapper_list<tree> *mappers;
10892 : : };
10893 : :
10894 : : /* Helper function of finish_omp_target_clauses, called via
10895 : : cp_walk_tree_without_duplicates. Traverse body of OpenMP target
10896 : : directive *TP, and fill out omp_target_walk_data passed in *PTR. */
10897 : :
10898 : : static tree
10899 : 225035 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
10900 : : {
10901 : 225035 : tree t = *tp;
10902 : 225035 : struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
10903 : 225035 : tree current_object = data->current_object;
10904 : 225035 : tree current_closure = data->current_closure;
10905 : 225035 : omp_mapper_list<tree> *mlist = data->mappers;
10906 : :
10907 : : /* References inside of these expression codes shouldn't incur any
10908 : : form of mapping, so return early. */
10909 : 225035 : if (TREE_CODE (t) == SIZEOF_EXPR
10910 : 225027 : || TREE_CODE (t) == ALIGNOF_EXPR)
10911 : : {
10912 : 8 : *walk_subtrees = 0;
10913 : 8 : return NULL_TREE;
10914 : : }
10915 : :
10916 : 225027 : if (TREE_CODE (t) == OMP_CLAUSE)
10917 : : return NULL_TREE;
10918 : :
10919 : 212442 : if (!processing_template_decl)
10920 : : {
10921 : 212442 : tree aggr_type = NULL_TREE;
10922 : :
10923 : 212442 : if (TREE_CODE (t) == COMPONENT_REF
10924 : 212442 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
10925 : 2227 : aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
10926 : 210215 : else if ((TREE_CODE (t) == VAR_DECL
10927 : : || TREE_CODE (t) == PARM_DECL
10928 : : || TREE_CODE (t) == RESULT_DECL)
10929 : 16728 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
10930 : 1206 : aggr_type = TREE_TYPE (t);
10931 : :
10932 : 3433 : if (aggr_type)
10933 : : {
10934 : 3433 : tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
10935 : 3433 : if (mapper_fn)
10936 : 167 : mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
10937 : : }
10938 : : }
10939 : :
10940 : 212442 : if (current_object)
10941 : : {
10942 : 2475 : tree this_expr = TREE_OPERAND (current_object, 0);
10943 : :
10944 : 2475 : if (operand_equal_p (t, this_expr))
10945 : : {
10946 : 35 : data->this_expr_accessed = true;
10947 : 35 : *walk_subtrees = 0;
10948 : 35 : return NULL_TREE;
10949 : : }
10950 : :
10951 : 2440 : if (TREE_CODE (t) == COMPONENT_REF
10952 : 115 : && POINTER_TYPE_P (TREE_TYPE (t))
10953 : 36 : && operand_equal_p (TREE_OPERAND (t, 0), current_object)
10954 : 2474 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
10955 : : {
10956 : 34 : data->this_expr_accessed = true;
10957 : 34 : tree fld = TREE_OPERAND (t, 1);
10958 : 34 : if (data->ptr_members_accessed.get (fld) == NULL)
10959 : : {
10960 : 14 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
10961 : 4 : t = convert_from_reference (t);
10962 : 14 : data->ptr_members_accessed.put (fld, t);
10963 : : }
10964 : 34 : *walk_subtrees = 0;
10965 : 34 : return NULL_TREE;
10966 : : }
10967 : : }
10968 : :
10969 : : /* When the current_function_decl is a lambda function, the closure object
10970 : : argument's type seems to not yet have fields layed out, so a recording
10971 : : of DECL_VALUE_EXPRs during the target body walk seems the only way to
10972 : : find them. */
10973 : 212373 : if (current_closure
10974 : 300 : && (VAR_P (t)
10975 : : || TREE_CODE (t) == PARM_DECL
10976 : : || TREE_CODE (t) == RESULT_DECL)
10977 : 24 : && DECL_HAS_VALUE_EXPR_P (t)
10978 : 10 : && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
10979 : 212383 : && operand_equal_p (current_closure,
10980 : 10 : TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
10981 : : {
10982 : 9 : if (!data->closure_vars_accessed.contains (t))
10983 : 9 : data->closure_vars_accessed.add (t);
10984 : 9 : *walk_subtrees = 0;
10985 : 9 : return NULL_TREE;
10986 : : }
10987 : :
10988 : 212364 : if (TREE_CODE (t) == BIND_EXPR)
10989 : : {
10990 : 19837 : if (tree block = BIND_EXPR_BLOCK (t))
10991 : 22214 : for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
10992 : 2381 : if (!data->local_decls.contains (var))
10993 : 2381 : data->local_decls.add (var);
10994 : 19837 : return NULL_TREE;
10995 : : }
10996 : :
10997 : 197091 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
10998 : : {
10999 : 39 : tree lt = TREE_TYPE (t);
11000 : 39 : gcc_assert (CLASS_TYPE_P (lt));
11001 : :
11002 : 39 : if (!data->lambda_objects_accessed.contains (t)
11003 : : /* Do not prepare to create target maps for locally declared
11004 : : lambdas or anonymous ones. */
11005 : 39 : && !data->local_decls.contains (t)
11006 : 72 : && TREE_CODE (t) != TARGET_EXPR)
11007 : 13 : data->lambda_objects_accessed.add (t);
11008 : 39 : *walk_subtrees = 0;
11009 : 39 : return NULL_TREE;
11010 : : }
11011 : :
11012 : : return NULL_TREE;
11013 : : }
11014 : :
11015 : : /* Helper function for finish_omp_target, and also from tsubst_expr.
11016 : : Create additional clauses for mapping of non-static members, lambda objects,
11017 : : etc. */
11018 : :
11019 : : void
11020 : 6895 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
11021 : : {
11022 : 6895 : omp_target_walk_data data;
11023 : 6895 : data.this_expr_accessed = false;
11024 : 6895 : data.current_object = NULL_TREE;
11025 : :
11026 : 6895 : if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
11027 : 96 : if (tree ct = current_nonlambda_class_type ())
11028 : : {
11029 : 95 : tree object = maybe_dummy_object (ct, NULL);
11030 : 95 : object = maybe_resolve_dummy (object, true);
11031 : 95 : data.current_object = object;
11032 : : }
11033 : :
11034 : 6895 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11035 : : {
11036 : 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11037 : 8 : data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11038 : : }
11039 : : else
11040 : 6887 : data.current_closure = NULL_TREE;
11041 : :
11042 : 6895 : auto_vec<tree, 16> new_clauses;
11043 : :
11044 : 6895 : if (!processing_template_decl)
11045 : : {
11046 : 6895 : hash_set<omp_name_type<tree> > seen_types;
11047 : 6895 : auto_vec<tree> mapper_fns;
11048 : 6895 : omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
11049 : 6895 : data.mappers = &mlist;
11050 : :
11051 : 6895 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11052 : : &data);
11053 : :
11054 : 6895 : unsigned int i;
11055 : 6895 : tree mapper_fn;
11056 : 13876 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11057 : 86 : c_omp_find_nested_mappers (&mlist, mapper_fn);
11058 : :
11059 : 7044 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
11060 : : {
11061 : 86 : tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
11062 : 86 : if (mapper == error_mark_node)
11063 : 0 : continue;
11064 : 86 : tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
11065 : 86 : tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
11066 : 86 : if (BASELINK_P (mapper_fn))
11067 : 0 : mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
11068 : :
11069 : 86 : tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
11070 : 86 : OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
11071 : 86 : OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
11072 : 86 : OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
11073 : :
11074 : 86 : new_clauses.safe_push (c);
11075 : : }
11076 : 6895 : }
11077 : : else
11078 : : {
11079 : 0 : data.mappers = NULL;
11080 : 0 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
11081 : : &data);
11082 : : }
11083 : :
11084 : 6895 : tree omp_target_this_expr = NULL_TREE;
11085 : 6895 : tree *explicit_this_deref_map = NULL;
11086 : 6895 : if (data.this_expr_accessed)
11087 : : {
11088 : 31 : omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
11089 : :
11090 : : /* See if explicit user-specified map(this[:]) clause already exists.
11091 : : If not, we create an implicit map(tofrom:this[:1]) clause. */
11092 : 80 : for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
11093 : 50 : if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
11094 : 47 : && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
11095 : 40 : || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
11096 : 57 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
11097 : : omp_target_this_expr))
11098 : : {
11099 : : explicit_this_deref_map = cp;
11100 : : break;
11101 : : }
11102 : : }
11103 : :
11104 : 6895 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11105 : 6895 : && (data.this_expr_accessed
11106 : 1 : || !data.closure_vars_accessed.is_empty ()))
11107 : : {
11108 : : /* For lambda functions, we need to first create a copy of the
11109 : : __closure object. */
11110 : 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
11111 : 8 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11112 : 8 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
11113 : 8 : OMP_CLAUSE_DECL (c)
11114 : 8 : = build_indirect_ref (loc, closure, RO_UNARY_STAR);
11115 : 8 : OMP_CLAUSE_SIZE (c)
11116 : 8 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
11117 : 8 : new_clauses.safe_push (c);
11118 : :
11119 : 8 : tree closure_obj = OMP_CLAUSE_DECL (c);
11120 : 8 : tree closure_type = TREE_TYPE (closure_obj);
11121 : :
11122 : 16 : gcc_assert (LAMBDA_TYPE_P (closure_type)
11123 : : && CLASS_TYPE_P (closure_type));
11124 : :
11125 : 8 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11126 : 8 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
11127 : 8 : OMP_CLAUSE_DECL (c2) = closure;
11128 : 8 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11129 : 8 : new_clauses.safe_push (c2);
11130 : : }
11131 : :
11132 : 6895 : if (data.this_expr_accessed)
11133 : : {
11134 : : /* If the this-expr was accessed, create a map(*this) clause. */
11135 : 31 : enum gomp_map_kind kind = GOMP_MAP_TOFROM;
11136 : 31 : if (explicit_this_deref_map)
11137 : : {
11138 : 1 : tree this_map = *explicit_this_deref_map;
11139 : 1 : tree nc = OMP_CLAUSE_CHAIN (this_map);
11140 : 2 : gcc_assert (nc != NULL_TREE
11141 : : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11142 : : && (OMP_CLAUSE_MAP_KIND (nc)
11143 : : == GOMP_MAP_FIRSTPRIVATE_POINTER));
11144 : 1 : kind = OMP_CLAUSE_MAP_KIND (this_map);
11145 : : /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
11146 : : two-map sequence away from the chain. */
11147 : 1 : *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
11148 : : }
11149 : 31 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11150 : 31 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11151 : 31 : OMP_CLAUSE_DECL (c)
11152 : 31 : = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
11153 : 31 : OMP_CLAUSE_SIZE (c)
11154 : 31 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
11155 : 31 : new_clauses.safe_push (c);
11156 : :
11157 : : /* If we're in a lambda function, the this-pointer will actually be
11158 : : '__closure->this', a mapped member of __closure, hence always_pointer.
11159 : : Otherwise it's a firstprivate pointer. */
11160 : 31 : enum gomp_map_kind ptr_kind
11161 : 31 : = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
11162 : 31 : ? GOMP_MAP_ALWAYS_POINTER
11163 : 24 : : GOMP_MAP_FIRSTPRIVATE_POINTER);
11164 : 31 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11165 : 31 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11166 : 31 : OMP_CLAUSE_DECL (c) = omp_target_this_expr;
11167 : 31 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11168 : 31 : new_clauses.safe_push (c);
11169 : : }
11170 : :
11171 : 6895 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
11172 : : {
11173 : 8 : if (omp_target_this_expr)
11174 : : {
11175 : 7 : STRIP_NOPS (omp_target_this_expr);
11176 : 7 : gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
11177 : 7 : omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
11178 : : }
11179 : :
11180 : 17 : for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
11181 : 34 : i != data.closure_vars_accessed.end (); ++i)
11182 : : {
11183 : 9 : tree orig_decl = *i;
11184 : 9 : tree closure_expr = DECL_VALUE_EXPR (orig_decl);
11185 : :
11186 : 9 : if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
11187 : 9 : || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
11188 : : {
11189 : : /* this-pointer is processed above, outside this loop. */
11190 : 3 : if (omp_target_this_expr
11191 : 3 : && operand_equal_p (closure_expr, omp_target_this_expr))
11192 : 0 : continue;
11193 : :
11194 : 3 : bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
11195 : 3 : enum gomp_map_kind kind, ptr_kind, nc_kind;
11196 : 3 : tree size;
11197 : :
11198 : 3 : if (ptr_p)
11199 : : {
11200 : : /* For pointers, default mapped as zero-length array
11201 : : section. */
11202 : 2 : kind = GOMP_MAP_ALLOC;
11203 : 2 : nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
11204 : 2 : ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
11205 : 2 : size = size_zero_node;
11206 : : }
11207 : : else
11208 : : {
11209 : : /* For references, default mapped as appearing on map
11210 : : clause. */
11211 : 1 : kind = GOMP_MAP_TOFROM;
11212 : 1 : nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
11213 : 1 : ptr_kind = GOMP_MAP_ALWAYS_POINTER;
11214 : 1 : size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
11215 : : }
11216 : :
11217 : 6 : for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
11218 : 3 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
11219 : 1 : && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
11220 : 1 : || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
11221 : 3 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
11222 : : orig_decl))
11223 : : {
11224 : : /* If this was already specified by user as a map,
11225 : : save the user specified map kind, delete the
11226 : : "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
11227 : : and insert our own sequence:
11228 : : "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
11229 : : */
11230 : 0 : tree nc = OMP_CLAUSE_CHAIN (*p);
11231 : 0 : gcc_assert (nc != NULL_TREE
11232 : : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11233 : : && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
11234 : : /* Update with user specified kind and size. */
11235 : 0 : kind = OMP_CLAUSE_MAP_KIND (*p);
11236 : 0 : size = OMP_CLAUSE_SIZE (*p);
11237 : 0 : *p = OMP_CLAUSE_CHAIN (nc);
11238 : 0 : break;
11239 : : }
11240 : :
11241 : 3 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11242 : 3 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11243 : 3 : OMP_CLAUSE_DECL (c)
11244 : 3 : = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
11245 : 3 : OMP_CLAUSE_SIZE (c) = size;
11246 : 3 : if (ptr_p)
11247 : 2 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11248 : 3 : new_clauses.safe_push (c);
11249 : :
11250 : 3 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11251 : 3 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11252 : 3 : OMP_CLAUSE_DECL (c) = closure_expr;
11253 : 3 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11254 : 3 : new_clauses.safe_push (c);
11255 : : }
11256 : : }
11257 : : }
11258 : :
11259 : 6895 : if (!data.ptr_members_accessed.is_empty ())
11260 : 14 : for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
11261 : 56 : i != data.ptr_members_accessed.end (); ++i)
11262 : : {
11263 : : /* For each referenced member that is of pointer or reference-to-pointer
11264 : : type, create the equivalent of map(alloc:this->ptr[:0]). */
11265 : 14 : tree field_decl = (*i).first;
11266 : 14 : tree ptr_member = (*i).second;
11267 : :
11268 : 26 : for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
11269 : : {
11270 : 16 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
11271 : 2 : continue;
11272 : : /* If map(this->ptr[:N]) already exists, avoid creating another
11273 : : such map. */
11274 : 14 : tree decl = OMP_CLAUSE_DECL (c);
11275 : 14 : if ((TREE_CODE (decl) == INDIRECT_REF
11276 : 10 : || TREE_CODE (decl) == MEM_REF)
11277 : 14 : && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
11278 : 4 : goto next_ptr_member;
11279 : : }
11280 : :
11281 : 10 : if (!cxx_mark_addressable (ptr_member))
11282 : 0 : gcc_unreachable ();
11283 : :
11284 : 10 : if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
11285 : : {
11286 : : /* For reference to pointers, we need to map the referenced
11287 : : pointer first for things to be correct. */
11288 : 4 : tree ptr_member_type = TREE_TYPE (ptr_member);
11289 : :
11290 : : /* Map pointer target as zero-length array section. */
11291 : 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11292 : 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11293 : 4 : OMP_CLAUSE_DECL (c)
11294 : 4 : = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
11295 : 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11296 : 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11297 : :
11298 : : /* Map pointer to zero-length array section. */
11299 : 4 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11300 : 4 : OMP_CLAUSE_SET_MAP_KIND
11301 : : (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
11302 : 4 : OMP_CLAUSE_DECL (c2) = ptr_member;
11303 : 4 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11304 : :
11305 : : /* Attach reference-to-pointer field to pointer. */
11306 : 4 : tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11307 : 4 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
11308 : 4 : OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
11309 : 4 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
11310 : :
11311 : 4 : new_clauses.safe_push (c);
11312 : 4 : new_clauses.safe_push (c2);
11313 : 4 : new_clauses.safe_push (c3);
11314 : : }
11315 : 6 : else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
11316 : : {
11317 : : /* Map pointer target as zero-length array section. */
11318 : 6 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11319 : 6 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11320 : 6 : OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
11321 : : RO_UNARY_STAR);
11322 : 6 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11323 : 6 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11324 : :
11325 : : /* Attach zero-length array section to pointer. */
11326 : 6 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11327 : 6 : OMP_CLAUSE_SET_MAP_KIND
11328 : : (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11329 : 6 : OMP_CLAUSE_DECL (c2) = ptr_member;
11330 : 6 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11331 : :
11332 : 6 : new_clauses.safe_push (c);
11333 : 6 : new_clauses.safe_push (c2);
11334 : : }
11335 : : else
11336 : 0 : gcc_unreachable ();
11337 : :
11338 : 14 : next_ptr_member:
11339 : 14 : ;
11340 : : }
11341 : :
11342 : 6908 : for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
11343 : 6921 : i != data.lambda_objects_accessed.end (); ++i)
11344 : : {
11345 : 13 : tree lobj = *i;
11346 : 13 : if (TREE_CODE (lobj) == TARGET_EXPR)
11347 : 0 : lobj = TARGET_EXPR_SLOT (lobj);
11348 : :
11349 : 13 : tree lt = TREE_TYPE (lobj);
11350 : 26 : gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
11351 : :
11352 : 13 : tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
11353 : 13 : OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
11354 : 13 : OMP_CLAUSE_DECL (lc) = lobj;
11355 : 13 : OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
11356 : 13 : new_clauses.safe_push (lc);
11357 : :
11358 : 180 : for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
11359 : : {
11360 : 167 : if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
11361 : : {
11362 : 4 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11363 : : lobj, fld, NULL_TREE);
11364 : 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11365 : 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11366 : 4 : OMP_CLAUSE_DECL (c)
11367 : 4 : = build_indirect_ref (loc, exp, RO_UNARY_STAR);
11368 : 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11369 : 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11370 : 4 : new_clauses.safe_push (c);
11371 : :
11372 : 4 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11373 : 4 : OMP_CLAUSE_SET_MAP_KIND
11374 : : (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11375 : 4 : OMP_CLAUSE_DECL (c) = exp;
11376 : 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11377 : 4 : new_clauses.safe_push (c);
11378 : : }
11379 : 163 : else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
11380 : : {
11381 : 0 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11382 : : lobj, fld, NULL_TREE);
11383 : 0 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11384 : 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
11385 : 0 : OMP_CLAUSE_DECL (c)
11386 : 0 : = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
11387 : 0 : OMP_CLAUSE_SIZE (c)
11388 : 0 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
11389 : 0 : new_clauses.safe_push (c);
11390 : :
11391 : 0 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11392 : 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
11393 : 0 : OMP_CLAUSE_DECL (c) = exp;
11394 : 0 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11395 : 0 : new_clauses.safe_push (c);
11396 : : }
11397 : : }
11398 : : }
11399 : :
11400 : 6895 : tree c = *clauses_ptr;
11401 : 14005 : for (int i = new_clauses.length () - 1; i >= 0; i--)
11402 : : {
11403 : 215 : OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
11404 : 215 : c = new_clauses[i];
11405 : : }
11406 : 6895 : *clauses_ptr = c;
11407 : 6895 : }
11408 : :
11409 : : /* Called from cp_parser_omp_target. Create additional implicit clauses for
11410 : : OpenMP target directives, and do sanity checks. */
11411 : :
11412 : : tree
11413 : 6883 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
11414 : : {
11415 : 6883 : if (!processing_template_decl)
11416 : 6070 : finish_omp_target_clauses (loc, body, &clauses);
11417 : :
11418 : 6883 : tree stmt = make_node (OMP_TARGET);
11419 : 6883 : TREE_TYPE (stmt) = void_type_node;
11420 : 6883 : OMP_TARGET_CLAUSES (stmt) = clauses;
11421 : 6883 : OMP_TARGET_BODY (stmt) = body;
11422 : 6883 : OMP_TARGET_COMBINED (stmt) = combined_p;
11423 : 6883 : SET_EXPR_LOCATION (stmt, loc);
11424 : :
11425 : 6883 : tree c = clauses;
11426 : 16369 : while (c)
11427 : : {
11428 : 9486 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
11429 : 5527 : switch (OMP_CLAUSE_MAP_KIND (c))
11430 : : {
11431 : : case GOMP_MAP_TO:
11432 : : case GOMP_MAP_ALWAYS_TO:
11433 : : case GOMP_MAP_PRESENT_TO:
11434 : : case GOMP_MAP_ALWAYS_PRESENT_TO:
11435 : : case GOMP_MAP_FROM:
11436 : : case GOMP_MAP_ALWAYS_FROM:
11437 : : case GOMP_MAP_PRESENT_FROM:
11438 : : case GOMP_MAP_ALWAYS_PRESENT_FROM:
11439 : : case GOMP_MAP_TOFROM:
11440 : : case GOMP_MAP_ALWAYS_TOFROM:
11441 : : case GOMP_MAP_PRESENT_TOFROM:
11442 : : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
11443 : : case GOMP_MAP_ALLOC:
11444 : : case GOMP_MAP_PRESENT_ALLOC:
11445 : : case GOMP_MAP_FIRSTPRIVATE_POINTER:
11446 : : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
11447 : : case GOMP_MAP_ALWAYS_POINTER:
11448 : : case GOMP_MAP_ATTACH_DETACH:
11449 : : case GOMP_MAP_ATTACH:
11450 : : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
11451 : : case GOMP_MAP_POINTER:
11452 : : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
11453 : : break;
11454 : 3 : default:
11455 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
11456 : : "%<#pragma omp target%> with map-type other "
11457 : : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
11458 : : "on %<map%> clause");
11459 : 3 : break;
11460 : : }
11461 : 9486 : c = OMP_CLAUSE_CHAIN (c);
11462 : : }
11463 : 6883 : return add_stmt (stmt);
11464 : : }
11465 : :
11466 : : tree
11467 : 9319 : finish_omp_parallel (tree clauses, tree body)
11468 : : {
11469 : 9319 : tree stmt;
11470 : :
11471 : 9319 : body = finish_omp_structured_block (body);
11472 : :
11473 : 9319 : stmt = make_node (OMP_PARALLEL);
11474 : 9319 : TREE_TYPE (stmt) = void_type_node;
11475 : 9319 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
11476 : 9319 : OMP_PARALLEL_BODY (stmt) = body;
11477 : :
11478 : 9319 : return add_stmt (stmt);
11479 : : }
11480 : :
11481 : : tree
11482 : 2160 : begin_omp_task (void)
11483 : : {
11484 : 2160 : keep_next_level (true);
11485 : 2160 : return begin_omp_structured_block ();
11486 : : }
11487 : :
11488 : : tree
11489 : 2160 : finish_omp_task (tree clauses, tree body)
11490 : : {
11491 : 2160 : tree stmt;
11492 : :
11493 : 2160 : body = finish_omp_structured_block (body);
11494 : :
11495 : 2160 : stmt = make_node (OMP_TASK);
11496 : 2160 : TREE_TYPE (stmt) = void_type_node;
11497 : 2160 : OMP_TASK_CLAUSES (stmt) = clauses;
11498 : 2160 : OMP_TASK_BODY (stmt) = body;
11499 : :
11500 : 2160 : return add_stmt (stmt);
11501 : : }
11502 : :
11503 : : /* Helper function for finish_omp_for. Convert Ith random access iterator
11504 : : into integral iterator. Return FALSE if successful. */
11505 : :
11506 : : static bool
11507 : 813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
11508 : : tree declv, tree orig_declv, tree initv,
11509 : : tree condv, tree incrv, tree *body,
11510 : : tree *pre_body, tree &clauses,
11511 : : int collapse, int ordered)
11512 : : {
11513 : 813 : tree diff, iter_init, iter_incr = NULL, last;
11514 : 813 : tree incr_var = NULL, orig_pre_body, orig_body, c;
11515 : 813 : tree decl = TREE_VEC_ELT (declv, i);
11516 : 813 : tree init = TREE_VEC_ELT (initv, i);
11517 : 813 : tree cond = TREE_VEC_ELT (condv, i);
11518 : 813 : tree incr = TREE_VEC_ELT (incrv, i);
11519 : 813 : tree iter = decl;
11520 : 813 : location_t elocus = locus;
11521 : :
11522 : 813 : if (init && EXPR_HAS_LOCATION (init))
11523 : 12 : elocus = EXPR_LOCATION (init);
11524 : :
11525 : 813 : switch (TREE_CODE (cond))
11526 : : {
11527 : 810 : case GT_EXPR:
11528 : 810 : case GE_EXPR:
11529 : 810 : case LT_EXPR:
11530 : 810 : case LE_EXPR:
11531 : 810 : case NE_EXPR:
11532 : 810 : if (TREE_OPERAND (cond, 1) == iter)
11533 : 42 : cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
11534 : 42 : TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
11535 : 810 : if (TREE_OPERAND (cond, 0) != iter)
11536 : 0 : cond = error_mark_node;
11537 : : else
11538 : : {
11539 : 810 : tree tem = build_x_binary_op (EXPR_LOCATION (cond),
11540 : 810 : TREE_CODE (cond),
11541 : : iter, ERROR_MARK,
11542 : 810 : TREE_OPERAND (cond, 1), ERROR_MARK,
11543 : : NULL_TREE, NULL, tf_warning_or_error);
11544 : 810 : if (error_operand_p (tem))
11545 : : return true;
11546 : : }
11547 : : break;
11548 : 3 : default:
11549 : 3 : cond = error_mark_node;
11550 : 3 : break;
11551 : : }
11552 : 810 : if (cond == error_mark_node)
11553 : : {
11554 : 3 : error_at (elocus, "invalid controlling predicate");
11555 : 3 : return true;
11556 : : }
11557 : 807 : diff = build_x_binary_op (elocus, MINUS_EXPR,
11558 : 807 : TREE_OPERAND (cond, 1), ERROR_MARK,
11559 : : iter, ERROR_MARK,
11560 : : NULL_TREE, NULL, tf_warning_or_error);
11561 : 807 : diff = cp_fully_fold (diff);
11562 : 807 : if (error_operand_p (diff))
11563 : : return true;
11564 : 807 : if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
11565 : : {
11566 : 0 : error_at (elocus, "difference between %qE and %qD does not have integer type",
11567 : 0 : TREE_OPERAND (cond, 1), iter);
11568 : 0 : return true;
11569 : : }
11570 : 807 : if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
11571 : 807 : TREE_VEC_ELT (declv, i), NULL_TREE,
11572 : : cond, cp_walk_subtrees))
11573 : : return true;
11574 : :
11575 : 762 : switch (TREE_CODE (incr))
11576 : : {
11577 : 370 : case PREINCREMENT_EXPR:
11578 : 370 : case PREDECREMENT_EXPR:
11579 : 370 : case POSTINCREMENT_EXPR:
11580 : 370 : case POSTDECREMENT_EXPR:
11581 : 370 : if (TREE_OPERAND (incr, 0) != iter)
11582 : : {
11583 : 0 : incr = error_mark_node;
11584 : 0 : break;
11585 : : }
11586 : 370 : iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
11587 : 370 : TREE_CODE (incr), iter,
11588 : : NULL_TREE, tf_warning_or_error);
11589 : 370 : if (error_operand_p (iter_incr))
11590 : : return true;
11591 : 370 : else if (TREE_CODE (incr) == PREINCREMENT_EXPR
11592 : 219 : || TREE_CODE (incr) == POSTINCREMENT_EXPR)
11593 : 299 : incr = integer_one_node;
11594 : : else
11595 : 71 : incr = integer_minus_one_node;
11596 : : break;
11597 : 392 : case MODIFY_EXPR:
11598 : 392 : if (TREE_OPERAND (incr, 0) != iter)
11599 : 0 : incr = error_mark_node;
11600 : 392 : else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
11601 : 392 : || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
11602 : : {
11603 : 392 : tree rhs = TREE_OPERAND (incr, 1);
11604 : 392 : if (TREE_OPERAND (rhs, 0) == iter)
11605 : : {
11606 : 299 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
11607 : : != INTEGER_TYPE)
11608 : 0 : incr = error_mark_node;
11609 : : else
11610 : : {
11611 : 299 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11612 : 299 : iter, TREE_CODE (rhs),
11613 : 299 : TREE_OPERAND (rhs, 1),
11614 : : NULL_TREE,
11615 : : tf_warning_or_error);
11616 : 299 : if (error_operand_p (iter_incr))
11617 : : return true;
11618 : 299 : incr = TREE_OPERAND (rhs, 1);
11619 : 299 : incr = cp_convert (TREE_TYPE (diff), incr,
11620 : : tf_warning_or_error);
11621 : 299 : if (TREE_CODE (rhs) == MINUS_EXPR)
11622 : : {
11623 : 16 : incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
11624 : 16 : incr = fold_simple (incr);
11625 : : }
11626 : 299 : if (TREE_CODE (incr) != INTEGER_CST
11627 : 299 : && (TREE_CODE (incr) != NOP_EXPR
11628 : 66 : || (TREE_CODE (TREE_OPERAND (incr, 0))
11629 : : != INTEGER_CST)))
11630 : : iter_incr = NULL;
11631 : : }
11632 : : }
11633 : 93 : else if (TREE_OPERAND (rhs, 1) == iter)
11634 : : {
11635 : 93 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
11636 : 93 : || TREE_CODE (rhs) != PLUS_EXPR)
11637 : 0 : incr = error_mark_node;
11638 : : else
11639 : : {
11640 : 93 : iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
11641 : : PLUS_EXPR,
11642 : 93 : TREE_OPERAND (rhs, 0),
11643 : : ERROR_MARK, iter,
11644 : : ERROR_MARK, NULL_TREE, NULL,
11645 : : tf_warning_or_error);
11646 : 93 : if (error_operand_p (iter_incr))
11647 : : return true;
11648 : 93 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11649 : : iter, NOP_EXPR,
11650 : : iter_incr, NULL_TREE,
11651 : : tf_warning_or_error);
11652 : 93 : if (error_operand_p (iter_incr))
11653 : : return true;
11654 : 93 : incr = TREE_OPERAND (rhs, 0);
11655 : 93 : iter_incr = NULL;
11656 : : }
11657 : : }
11658 : : else
11659 : 0 : incr = error_mark_node;
11660 : : }
11661 : : else
11662 : 0 : incr = error_mark_node;
11663 : : break;
11664 : 0 : default:
11665 : 0 : incr = error_mark_node;
11666 : 0 : break;
11667 : : }
11668 : :
11669 : 762 : if (incr == error_mark_node)
11670 : : {
11671 : 0 : error_at (elocus, "invalid increment expression");
11672 : 0 : return true;
11673 : : }
11674 : :
11675 : 762 : incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
11676 : 762 : incr = cp_fully_fold (incr);
11677 : 762 : tree loop_iv_seen = NULL_TREE;
11678 : 1735 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11679 : 1093 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
11680 : 1093 : && OMP_CLAUSE_DECL (c) == iter)
11681 : : {
11682 : 120 : if (code == OMP_TASKLOOP || code == OMP_LOOP)
11683 : : {
11684 : 60 : loop_iv_seen = c;
11685 : 60 : OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
11686 : : }
11687 : : break;
11688 : : }
11689 : 973 : else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
11690 : 113 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
11691 : 1007 : && OMP_CLAUSE_DECL (c) == iter)
11692 : : {
11693 : 30 : loop_iv_seen = c;
11694 : 30 : if (code == OMP_TASKLOOP)
11695 : 25 : OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
11696 : : }
11697 : :
11698 : 762 : decl = create_temporary_var (TREE_TYPE (diff));
11699 : 762 : pushdecl (decl);
11700 : 762 : add_decl_expr (decl);
11701 : 762 : last = create_temporary_var (TREE_TYPE (diff));
11702 : 762 : pushdecl (last);
11703 : 762 : add_decl_expr (last);
11704 : 762 : if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
11705 : 10 : && (!ordered || (i < collapse && collapse > 1)))
11706 : : {
11707 : 10 : incr_var = create_temporary_var (TREE_TYPE (diff));
11708 : 10 : pushdecl (incr_var);
11709 : 10 : add_decl_expr (incr_var);
11710 : : }
11711 : 762 : gcc_assert (stmts_are_full_exprs_p ());
11712 : 762 : tree diffvar = NULL_TREE;
11713 : 762 : if (code == OMP_TASKLOOP)
11714 : : {
11715 : 101 : if (!loop_iv_seen)
11716 : : {
11717 : 38 : tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11718 : 38 : OMP_CLAUSE_DECL (ivc) = iter;
11719 : 38 : cxx_omp_finish_clause (ivc, NULL, false);
11720 : 38 : OMP_CLAUSE_CHAIN (ivc) = clauses;
11721 : 38 : clauses = ivc;
11722 : : }
11723 : 101 : tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11724 : 101 : OMP_CLAUSE_DECL (lvc) = last;
11725 : 101 : OMP_CLAUSE_CHAIN (lvc) = clauses;
11726 : 101 : clauses = lvc;
11727 : 101 : diffvar = create_temporary_var (TREE_TYPE (diff));
11728 : 101 : pushdecl (diffvar);
11729 : 101 : add_decl_expr (diffvar);
11730 : : }
11731 : 661 : else if (code == OMP_LOOP)
11732 : : {
11733 : 43 : if (!loop_iv_seen)
11734 : : {
11735 : : /* While iterators on the loop construct are predetermined
11736 : : lastprivate, if the decl is not declared inside of the
11737 : : loop, OMP_CLAUSE_LASTPRIVATE should have been added
11738 : : already. */
11739 : 16 : loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11740 : 16 : OMP_CLAUSE_DECL (loop_iv_seen) = iter;
11741 : 16 : OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
11742 : 16 : clauses = loop_iv_seen;
11743 : : }
11744 : 27 : else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
11745 : : {
11746 : 5 : OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
11747 : 5 : OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
11748 : 5 : OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
11749 : : }
11750 : 43 : if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
11751 : 21 : cxx_omp_finish_clause (loop_iv_seen, NULL, false);
11752 : : }
11753 : :
11754 : 762 : orig_pre_body = *pre_body;
11755 : 762 : *pre_body = push_stmt_list ();
11756 : 762 : if (orig_pre_body)
11757 : 610 : add_stmt (orig_pre_body);
11758 : 762 : if (init != NULL)
11759 : 61 : finish_expr_stmt (build_x_modify_expr (elocus,
11760 : : iter, NOP_EXPR, init,
11761 : : NULL_TREE, tf_warning_or_error));
11762 : 762 : init = build_int_cst (TREE_TYPE (diff), 0);
11763 : 762 : if (c && iter_incr == NULL
11764 : 28 : && (!ordered || (i < collapse && collapse > 1)))
11765 : : {
11766 : 28 : if (incr_var)
11767 : : {
11768 : 10 : finish_expr_stmt (build_x_modify_expr (elocus,
11769 : : incr_var, NOP_EXPR,
11770 : : incr, NULL_TREE,
11771 : : tf_warning_or_error));
11772 : 10 : incr = incr_var;
11773 : : }
11774 : 28 : iter_incr = build_x_modify_expr (elocus,
11775 : : iter, PLUS_EXPR, incr,
11776 : : NULL_TREE, tf_warning_or_error);
11777 : : }
11778 : 762 : if (c && ordered && i < collapse && collapse > 1)
11779 : 762 : iter_incr = incr;
11780 : 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11781 : : last, NOP_EXPR, init,
11782 : : NULL_TREE, tf_warning_or_error));
11783 : 762 : if (diffvar)
11784 : : {
11785 : 101 : finish_expr_stmt (build_x_modify_expr (elocus,
11786 : : diffvar, NOP_EXPR,
11787 : : diff, NULL_TREE, tf_warning_or_error));
11788 : 101 : diff = diffvar;
11789 : : }
11790 : 762 : *pre_body = pop_stmt_list (*pre_body);
11791 : :
11792 : 1524 : cond = cp_build_binary_op (elocus,
11793 : 762 : TREE_CODE (cond), decl, diff,
11794 : : tf_warning_or_error);
11795 : 762 : incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
11796 : : elocus, incr, NULL_TREE);
11797 : :
11798 : 762 : orig_body = *body;
11799 : 762 : *body = push_stmt_list ();
11800 : 762 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
11801 : 762 : iter_init = build_x_modify_expr (elocus,
11802 : : iter, PLUS_EXPR, iter_init,
11803 : : NULL_TREE, tf_warning_or_error);
11804 : 762 : if (iter_init != error_mark_node)
11805 : 759 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11806 : 762 : finish_expr_stmt (iter_init);
11807 : 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11808 : : last, NOP_EXPR, decl,
11809 : : NULL_TREE, tf_warning_or_error));
11810 : 762 : add_stmt (orig_body);
11811 : 762 : *body = pop_stmt_list (*body);
11812 : :
11813 : 762 : if (c)
11814 : : {
11815 : 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
11816 : 120 : if (!ordered)
11817 : 114 : finish_expr_stmt (iter_incr);
11818 : : else
11819 : : {
11820 : 6 : iter_init = decl;
11821 : 6 : if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
11822 : 2 : iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
11823 : : iter_init, iter_incr);
11824 : 6 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
11825 : 6 : iter_init = build_x_modify_expr (elocus,
11826 : : iter, PLUS_EXPR, iter_init,
11827 : : NULL_TREE, tf_warning_or_error);
11828 : 6 : if (iter_init != error_mark_node)
11829 : 6 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11830 : 6 : finish_expr_stmt (iter_init);
11831 : : }
11832 : 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c)
11833 : 240 : = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
11834 : : }
11835 : :
11836 : 762 : if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
11837 : : {
11838 : 116 : tree t = TREE_VEC_ELT (orig_declv, i);
11839 : 116 : gcc_assert (TREE_PURPOSE (t) == NULL_TREE
11840 : : && TREE_VALUE (t) == NULL_TREE
11841 : : && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
11842 : 116 : TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
11843 : 116 : TREE_VALUE (t) = last;
11844 : : }
11845 : : else
11846 : 646 : TREE_VEC_ELT (orig_declv, i)
11847 : 1292 : = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
11848 : 762 : TREE_VEC_ELT (declv, i) = decl;
11849 : 762 : TREE_VEC_ELT (initv, i) = init;
11850 : 762 : TREE_VEC_ELT (condv, i) = cond;
11851 : 762 : TREE_VEC_ELT (incrv, i) = incr;
11852 : :
11853 : 762 : return false;
11854 : : }
11855 : :
11856 : : /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
11857 : : are directly for their associated operands in the statement. DECL
11858 : : and INIT are a combo; if DECL is NULL then INIT ought to be a
11859 : : MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
11860 : : optional statements that need to go before the loop into its
11861 : : sk_omp scope. */
11862 : :
11863 : : tree
11864 : 21128 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
11865 : : tree orig_declv, tree initv, tree condv, tree incrv,
11866 : : tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
11867 : : {
11868 : 21128 : tree omp_for = NULL, orig_incr = NULL;
11869 : 21128 : tree decl = NULL, init, cond, incr;
11870 : 21128 : location_t elocus;
11871 : 21128 : int i;
11872 : 21128 : int collapse = 1;
11873 : 21128 : int ordered = 0;
11874 : 21128 : auto_vec<location_t> init_locv;
11875 : :
11876 : 21128 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
11877 : 21128 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
11878 : 21128 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
11879 : 21128 : if (TREE_VEC_LENGTH (declv) > 1)
11880 : : {
11881 : 4054 : if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
11882 : 83 : collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
11883 : : else
11884 : : {
11885 : 3971 : if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
11886 : 3501 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
11887 : 470 : else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
11888 : 394 : collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
11889 : 3971 : if (collapse != TREE_VEC_LENGTH (declv))
11890 : 100 : ordered = TREE_VEC_LENGTH (declv);
11891 : : }
11892 : : }
11893 : 48601 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
11894 : : {
11895 : 27509 : decl = TREE_VEC_ELT (declv, i);
11896 : 27509 : init = TREE_VEC_ELT (initv, i);
11897 : 27509 : cond = TREE_VEC_ELT (condv, i);
11898 : 27509 : incr = TREE_VEC_ELT (incrv, i);
11899 : 27509 : elocus = locus;
11900 : :
11901 : 27509 : if (decl == global_namespace)
11902 : : {
11903 : 1101 : gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
11904 : 1101 : TREE_VEC_ELT (declv, i) = NULL_TREE;
11905 : 1101 : init_locv.safe_push (UNKNOWN_LOCATION);
11906 : 1101 : continue;
11907 : : }
11908 : : /* We are going to throw out the init's original MODIFY_EXPR or
11909 : : MODOP_EXPR below. Save its location so we can use it when
11910 : : reconstructing the expression farther down. Alternatively, if the
11911 : : initializer is a binding of the iteration variable, save
11912 : : that location. Any of these locations in the initialization clause
11913 : : for the current nested loop are better than using the argument locus,
11914 : : that points to the "for" of the outermost loop in the nest. */
11915 : 26408 : if (init && EXPR_HAS_LOCATION (init))
11916 : 17875 : elocus = EXPR_LOCATION (init);
11917 : 8533 : else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
11918 : : /* This can happen for class iterators. */
11919 : 0 : elocus = EXPR_LOCATION (decl);
11920 : 8533 : else if (decl && DECL_P (decl))
11921 : : {
11922 : 8506 : if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
11923 : 8506 : elocus = DECL_SOURCE_LOCATION (decl);
11924 : 0 : else if (DECL_INITIAL (decl)
11925 : 0 : && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
11926 : 0 : elocus = EXPR_LOCATION (DECL_INITIAL (decl));
11927 : : }
11928 : 26408 : init_locv.safe_push (elocus);
11929 : :
11930 : 26408 : if (decl == NULL)
11931 : : {
11932 : 16564 : if (init != NULL)
11933 : 16561 : switch (TREE_CODE (init))
11934 : : {
11935 : 16176 : case MODIFY_EXPR:
11936 : 16176 : decl = TREE_OPERAND (init, 0);
11937 : 16176 : init = TREE_OPERAND (init, 1);
11938 : 16176 : break;
11939 : 367 : case MODOP_EXPR:
11940 : 367 : if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
11941 : : {
11942 : 367 : decl = TREE_OPERAND (init, 0);
11943 : 367 : init = TREE_OPERAND (init, 2);
11944 : : }
11945 : : break;
11946 : : default:
11947 : : break;
11948 : : }
11949 : :
11950 : 16564 : if (decl == NULL)
11951 : : {
11952 : 21 : error_at (locus,
11953 : : "expected iteration declaration or initialization");
11954 : 21 : return NULL;
11955 : : }
11956 : : }
11957 : :
11958 : 26387 : if (cond == global_namespace)
11959 : 170 : continue;
11960 : :
11961 : 26217 : if (cond == NULL)
11962 : : {
11963 : 9 : error_at (elocus, "missing controlling predicate");
11964 : 9 : return NULL;
11965 : : }
11966 : :
11967 : 26208 : if (incr == NULL)
11968 : : {
11969 : 6 : error_at (elocus, "missing increment expression");
11970 : 6 : return NULL;
11971 : : }
11972 : :
11973 : 26202 : TREE_VEC_ELT (declv, i) = decl;
11974 : 26202 : TREE_VEC_ELT (initv, i) = init;
11975 : : }
11976 : :
11977 : 21092 : if (orig_inits)
11978 : : {
11979 : : bool fail = false;
11980 : : tree orig_init;
11981 : 21214 : FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
11982 : 1181 : if (orig_init
11983 : 3396 : && !c_omp_check_loop_iv_exprs (locus, code,
11984 : : orig_declv ? orig_declv : declv, i,
11985 : 1164 : TREE_VEC_ELT (declv, i), orig_init,
11986 : : NULL_TREE, cp_walk_subtrees))
11987 : : fail = true;
11988 : 20033 : if (fail)
11989 : 887 : return NULL;
11990 : : }
11991 : :
11992 : 21035 : if (dependent_omp_for_p (declv, initv, condv, incrv, body))
11993 : : {
11994 : 453 : tree stmt;
11995 : :
11996 : 453 : stmt = make_node (code);
11997 : :
11998 : 1499 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
11999 : : {
12000 : 593 : if (TREE_VEC_ELT (declv, i) == NULL_TREE)
12001 : 9 : continue;
12002 : : /* This is really just a place-holder. We'll be decomposing this
12003 : : again and going through the cp_build_modify_expr path below when
12004 : : we instantiate the thing. */
12005 : 584 : TREE_VEC_ELT (initv, i)
12006 : 1168 : = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
12007 : 584 : TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
12008 : : }
12009 : :
12010 : 453 : TREE_TYPE (stmt) = void_type_node;
12011 : 453 : OMP_FOR_INIT (stmt) = initv;
12012 : 453 : OMP_FOR_COND (stmt) = condv;
12013 : 453 : OMP_FOR_INCR (stmt) = incrv;
12014 : 453 : OMP_FOR_BODY (stmt) = body;
12015 : 453 : OMP_FOR_PRE_BODY (stmt) = pre_body;
12016 : 453 : OMP_FOR_CLAUSES (stmt) = clauses;
12017 : :
12018 : 453 : SET_EXPR_LOCATION (stmt, locus);
12019 : 453 : return add_stmt (stmt);
12020 : : }
12021 : :
12022 : 20582 : if (!orig_declv)
12023 : 19795 : orig_declv = copy_node (declv);
12024 : :
12025 : 20582 : if (processing_template_decl)
12026 : 612 : orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
12027 : :
12028 : 48030 : for (i = 0; i < TREE_VEC_LENGTH (declv); )
12029 : : {
12030 : 27540 : decl = TREE_VEC_ELT (declv, i);
12031 : 27540 : init = TREE_VEC_ELT (initv, i);
12032 : 27540 : cond = TREE_VEC_ELT (condv, i);
12033 : 27540 : incr = TREE_VEC_ELT (incrv, i);
12034 : 27540 : if (orig_incr)
12035 : 844 : TREE_VEC_ELT (orig_incr, i) = incr;
12036 : 27540 : elocus = init_locv[i];
12037 : :
12038 : 27540 : if (decl == NULL_TREE)
12039 : : {
12040 : 1092 : i++;
12041 : 1092 : continue;
12042 : : }
12043 : :
12044 : 26448 : if (!DECL_P (decl))
12045 : : {
12046 : 6 : error_at (elocus, "expected iteration declaration or initialization");
12047 : 6 : return NULL;
12048 : : }
12049 : :
12050 : 26442 : if (incr && TREE_CODE (incr) == MODOP_EXPR)
12051 : : {
12052 : 1 : if (orig_incr)
12053 : 1 : TREE_VEC_ELT (orig_incr, i) = incr;
12054 : 1 : incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
12055 : 1 : TREE_CODE (TREE_OPERAND (incr, 1)),
12056 : 1 : TREE_OPERAND (incr, 2),
12057 : : tf_warning_or_error);
12058 : : }
12059 : :
12060 : 26442 : if (CLASS_TYPE_P (TREE_TYPE (decl)))
12061 : : {
12062 : 825 : if (code == OMP_SIMD)
12063 : : {
12064 : 12 : error_at (elocus, "%<#pragma omp simd%> used with class "
12065 : : "iteration variable %qE", decl);
12066 : 12 : return NULL;
12067 : : }
12068 : 813 : if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
12069 : : initv, condv, incrv, &body,
12070 : : &pre_body, clauses,
12071 : : collapse, ordered))
12072 : : return NULL;
12073 : 762 : continue;
12074 : : }
12075 : :
12076 : 51234 : if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
12077 : 27203 : && !TYPE_PTR_P (TREE_TYPE (decl)))
12078 : : {
12079 : 14 : error_at (elocus, "invalid type for iteration variable %qE", decl);
12080 : 14 : return NULL;
12081 : : }
12082 : :
12083 : 25603 : if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
12084 : 24842 : init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
12085 : : tf_warning_or_error);
12086 : : else
12087 : 761 : init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
12088 : 25603 : if (decl == error_mark_node || init == error_mark_node)
12089 : : return NULL;
12090 : :
12091 : 25594 : TREE_VEC_ELT (declv, i) = decl;
12092 : 25594 : TREE_VEC_ELT (initv, i) = init;
12093 : 25594 : TREE_VEC_ELT (condv, i) = cond;
12094 : 25594 : TREE_VEC_ELT (incrv, i) = incr;
12095 : 25594 : i++;
12096 : : }
12097 : :
12098 : 20490 : if (pre_body && IS_EMPTY_STMT (pre_body))
12099 : 0 : pre_body = NULL;
12100 : :
12101 : 40980 : omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
12102 : : incrv, body, pre_body,
12103 : 20490 : !processing_template_decl);
12104 : :
12105 : : /* Check for iterators appearing in lb, b or incr expressions. */
12106 : 20490 : if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
12107 : : omp_for = NULL_TREE;
12108 : :
12109 : 20004 : if (omp_for == NULL)
12110 : 702 : return NULL;
12111 : :
12112 : 19788 : add_stmt (omp_for);
12113 : :
12114 : 45448 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
12115 : : {
12116 : 25660 : init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
12117 : 25660 : if (init == NULL_TREE)
12118 : 1032 : continue;
12119 : 24628 : decl = TREE_OPERAND (init, 0);
12120 : 24628 : cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
12121 : 24628 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
12122 : :
12123 : 24628 : if (!processing_template_decl)
12124 : : {
12125 : 24107 : if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
12126 : : {
12127 : 106 : tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
12128 : 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
12129 : 106 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12130 : 106 : t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
12131 : 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
12132 : 212 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12133 : : }
12134 : : else
12135 : : {
12136 : 24001 : tree t = TREE_OPERAND (init, 1);
12137 : 24001 : TREE_OPERAND (init, 1)
12138 : 48002 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12139 : : }
12140 : 24107 : if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
12141 : : {
12142 : 121 : tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
12143 : 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
12144 : 121 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12145 : 121 : t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
12146 : 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
12147 : 242 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12148 : : }
12149 : : else
12150 : : {
12151 : 23986 : tree t = TREE_OPERAND (cond, 1);
12152 : 23986 : TREE_OPERAND (cond, 1)
12153 : 47972 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12154 : : }
12155 : : }
12156 : :
12157 : 24628 : if (TREE_CODE (incr) != MODIFY_EXPR)
12158 : 18426 : continue;
12159 : :
12160 : 6202 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
12161 : 70 : && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
12162 : 6272 : && !processing_template_decl)
12163 : : {
12164 : 64 : tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
12165 : 64 : if (TREE_SIDE_EFFECTS (t)
12166 : 8 : && t != decl
12167 : 70 : && (TREE_CODE (t) != NOP_EXPR
12168 : 0 : || TREE_OPERAND (t, 0) != decl))
12169 : 6 : TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
12170 : 12 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12171 : :
12172 : 64 : t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
12173 : 64 : if (TREE_SIDE_EFFECTS (t)
12174 : 56 : && t != decl
12175 : 120 : && (TREE_CODE (t) != NOP_EXPR
12176 : 5 : || TREE_OPERAND (t, 0) != decl))
12177 : 56 : TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
12178 : 112 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
12179 : : }
12180 : :
12181 : 6202 : if (orig_incr)
12182 : 177 : TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
12183 : : }
12184 : 19788 : OMP_FOR_CLAUSES (omp_for) = clauses;
12185 : :
12186 : : /* For simd loops with non-static data member iterators, we could have added
12187 : : OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
12188 : : step at this point, fill it in. */
12189 : 4735 : if (code == OMP_SIMD && !processing_template_decl
12190 : 24479 : && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
12191 : 4619 : for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
12192 : 561 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
12193 : 561 : if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
12194 : : {
12195 : 4 : decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
12196 : 4 : gcc_assert (decl == OMP_CLAUSE_DECL (c));
12197 : 4 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
12198 : 4 : tree step, stept;
12199 : 4 : switch (TREE_CODE (incr))
12200 : : {
12201 : 0 : case PREINCREMENT_EXPR:
12202 : 0 : case POSTINCREMENT_EXPR:
12203 : : /* c_omp_for_incr_canonicalize_ptr() should have been
12204 : : called to massage things appropriately. */
12205 : 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12206 : 0 : OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
12207 : 0 : break;
12208 : 0 : case PREDECREMENT_EXPR:
12209 : 0 : case POSTDECREMENT_EXPR:
12210 : : /* c_omp_for_incr_canonicalize_ptr() should have been
12211 : : called to massage things appropriately. */
12212 : 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12213 : 0 : OMP_CLAUSE_LINEAR_STEP (c)
12214 : 0 : = build_int_cst (TREE_TYPE (decl), -1);
12215 : 0 : break;
12216 : 4 : case MODIFY_EXPR:
12217 : 4 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12218 : 4 : incr = TREE_OPERAND (incr, 1);
12219 : 4 : switch (TREE_CODE (incr))
12220 : : {
12221 : 4 : case PLUS_EXPR:
12222 : 4 : if (TREE_OPERAND (incr, 1) == decl)
12223 : 0 : step = TREE_OPERAND (incr, 0);
12224 : : else
12225 : 4 : step = TREE_OPERAND (incr, 1);
12226 : : break;
12227 : 0 : case MINUS_EXPR:
12228 : 0 : case POINTER_PLUS_EXPR:
12229 : 0 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12230 : 0 : step = TREE_OPERAND (incr, 1);
12231 : 0 : break;
12232 : 0 : default:
12233 : 0 : gcc_unreachable ();
12234 : : }
12235 : 4 : stept = TREE_TYPE (decl);
12236 : 4 : if (INDIRECT_TYPE_P (stept))
12237 : 0 : stept = sizetype;
12238 : 4 : step = fold_convert (stept, step);
12239 : 4 : if (TREE_CODE (incr) == MINUS_EXPR)
12240 : 0 : step = fold_build1 (NEGATE_EXPR, stept, step);
12241 : 4 : OMP_CLAUSE_LINEAR_STEP (c) = step;
12242 : 4 : break;
12243 : 0 : default:
12244 : 0 : gcc_unreachable ();
12245 : : }
12246 : : }
12247 : : /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
12248 : : clauses, we need copy ctor for those rather than default ctor,
12249 : : plus as for other lastprivates assignment op and dtor. */
12250 : 19788 : if (code == OMP_LOOP && !processing_template_decl)
12251 : 1993 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12252 : 1285 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
12253 : 204 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
12254 : 1307 : && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
12255 : : false, true, true, true))
12256 : 0 : CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
12257 : :
12258 : : return omp_for;
12259 : 21128 : }
12260 : :
12261 : : /* Code walker for finish_omp_for_block: extract binding of DP->var
12262 : : from its current block and move it to a new BIND_EXPR DP->b
12263 : : surrounding the body of DP->omp_for. */
12264 : :
12265 : : struct fofb_data {
12266 : : tree var;
12267 : : tree b;
12268 : : tree omp_for;
12269 : : };
12270 : :
12271 : : static tree
12272 : 389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
12273 : : {
12274 : 389 : struct fofb_data *fofb = (struct fofb_data *)dp;
12275 : 389 : if (TREE_CODE (*tp) == BIND_EXPR)
12276 : 578 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
12277 : : {
12278 : 576 : if (*p == fofb->var)
12279 : : {
12280 : 363 : *p = DECL_CHAIN (*p);
12281 : 363 : if (fofb->b == NULL_TREE)
12282 : : {
12283 : 214 : fofb->b = make_node (BLOCK);
12284 : 214 : fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
12285 : 214 : OMP_FOR_BODY (fofb->omp_for), fofb->b);
12286 : 214 : TREE_SIDE_EFFECTS (fofb->b) = 1;
12287 : 214 : OMP_FOR_BODY (fofb->omp_for) = fofb->b;
12288 : : }
12289 : 363 : DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
12290 : 363 : BIND_EXPR_VARS (fofb->b) = fofb->var;
12291 : 363 : BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
12292 : 363 : BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
12293 : 363 : return *tp;
12294 : : }
12295 : : }
12296 : 26 : if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
12297 : 22 : *walk_subtrees = false;
12298 : : return NULL_TREE;
12299 : : }
12300 : :
12301 : : /* Fix up range for decls. Those decls were pushed into BIND's
12302 : : BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
12303 : : and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
12304 : : so that processing of combined loop directives can find them. */
12305 : : tree
12306 : 14525 : finish_omp_for_block (tree bind, tree omp_for)
12307 : : {
12308 : 14525 : if (omp_for == NULL_TREE
12309 : 14478 : || !OMP_FOR_ORIG_DECLS (omp_for)
12310 : 28435 : || bind == NULL_TREE)
12311 : 615 : return bind;
12312 : 13910 : struct fofb_data fofb;
12313 : 13910 : fofb.b = NULL_TREE;
12314 : 13910 : fofb.omp_for = omp_for;
12315 : 33347 : for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
12316 : 19437 : if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
12317 : 19215 : && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
12318 : : == TREE_LIST)
12319 : 20268 : && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
12320 : : {
12321 : 237 : tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
12322 : 602 : for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
12323 : : {
12324 : 365 : fofb.var = TREE_VEC_ELT (v, j);
12325 : 365 : cp_walk_tree (&bind, finish_omp_for_block_walker,
12326 : : (void *)&fofb, NULL);
12327 : : }
12328 : : }
12329 : 13910 : return bind;
12330 : : }
12331 : :
12332 : : void
12333 : 3342 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
12334 : : tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
12335 : : tree clauses, enum omp_memory_order mo, bool weak)
12336 : : {
12337 : 3342 : tree orig_lhs;
12338 : 3342 : tree orig_rhs;
12339 : 3342 : tree orig_v;
12340 : 3342 : tree orig_lhs1;
12341 : 3342 : tree orig_rhs1;
12342 : 3342 : tree orig_r;
12343 : 3342 : bool dependent_p;
12344 : 3342 : tree stmt;
12345 : :
12346 : 3342 : orig_lhs = lhs;
12347 : 3342 : orig_rhs = rhs;
12348 : 3342 : orig_v = v;
12349 : 3342 : orig_lhs1 = lhs1;
12350 : 3342 : orig_rhs1 = rhs1;
12351 : 3342 : orig_r = r;
12352 : 3342 : dependent_p = false;
12353 : 3342 : stmt = NULL_TREE;
12354 : :
12355 : : /* Even in a template, we can detect invalid uses of the atomic
12356 : : pragma if neither LHS nor RHS is type-dependent. */
12357 : 3342 : if (processing_template_decl)
12358 : : {
12359 : 600 : dependent_p = (type_dependent_expression_p (lhs)
12360 : 237 : || (rhs && type_dependent_expression_p (rhs))
12361 : 234 : || (v && type_dependent_expression_p (v))
12362 : 234 : || (lhs1 && type_dependent_expression_p (lhs1))
12363 : 234 : || (rhs1 && type_dependent_expression_p (rhs1))
12364 : 834 : || (r
12365 : 25 : && r != void_list_node
12366 : 16 : && type_dependent_expression_p (r)));
12367 : 600 : if (clauses)
12368 : : {
12369 : 30 : gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
12370 : : && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
12371 : : && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
12372 : 30 : if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
12373 : 30 : || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
12374 : : dependent_p = true;
12375 : : }
12376 : : }
12377 : 576 : if (!dependent_p)
12378 : : {
12379 : 2958 : bool swapped = false;
12380 : 2958 : if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
12381 : : {
12382 : 143 : std::swap (rhs, rhs1);
12383 : 143 : swapped = !commutative_tree_code (opcode);
12384 : : }
12385 : 2958 : if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
12386 : : {
12387 : 0 : if (code == OMP_ATOMIC)
12388 : 0 : error ("%<#pragma omp atomic update%> uses two different "
12389 : : "expressions for memory");
12390 : : else
12391 : 0 : error ("%<#pragma omp atomic capture%> uses two different "
12392 : : "expressions for memory");
12393 : 0 : return;
12394 : : }
12395 : 2958 : if (lhs1 && !cp_tree_equal (lhs, lhs1))
12396 : : {
12397 : 0 : if (code == OMP_ATOMIC)
12398 : 0 : error ("%<#pragma omp atomic update%> uses two different "
12399 : : "expressions for memory");
12400 : : else
12401 : 0 : error ("%<#pragma omp atomic capture%> uses two different "
12402 : : "expressions for memory");
12403 : 0 : return;
12404 : : }
12405 : 5916 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
12406 : : v, lhs1, rhs1, r, swapped, mo, weak,
12407 : 2958 : processing_template_decl != 0);
12408 : 2958 : if (stmt == error_mark_node)
12409 : : return;
12410 : : }
12411 : 3312 : if (processing_template_decl)
12412 : : {
12413 : 591 : if (code == OMP_ATOMIC_READ)
12414 : : {
12415 : 167 : stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
12416 : 167 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12417 : 167 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12418 : : }
12419 : : else
12420 : : {
12421 : 424 : if (opcode == NOP_EXPR)
12422 : 35 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
12423 : 389 : else if (opcode == COND_EXPR)
12424 : : {
12425 : 124 : stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
12426 : 124 : if (orig_r)
12427 : 50 : stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
12428 : : stmt);
12429 : 124 : stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
12430 : : orig_lhs);
12431 : 124 : orig_rhs1 = NULL_TREE;
12432 : : }
12433 : : else
12434 : 265 : stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
12435 : 424 : if (orig_rhs1)
12436 : 182 : stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
12437 : : COMPOUND_EXPR, orig_rhs1, stmt);
12438 : 424 : if (code != OMP_ATOMIC)
12439 : : {
12440 : 233 : stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
12441 : 233 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12442 : 233 : OMP_ATOMIC_WEAK (stmt) = weak;
12443 : 233 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12444 : : }
12445 : : }
12446 : 591 : stmt = build2 (OMP_ATOMIC, void_type_node,
12447 : : clauses ? clauses : integer_zero_node, stmt);
12448 : 591 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12449 : 591 : OMP_ATOMIC_WEAK (stmt) = weak;
12450 : 591 : SET_EXPR_LOCATION (stmt, loc);
12451 : : }
12452 : :
12453 : : /* Avoid -Wunused-value warnings here, the whole construct has side-effects
12454 : : and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
12455 : : in some tree that appears to be unused, the value is not unused. */
12456 : 3312 : warning_sentinel w (warn_unused_value);
12457 : 3312 : finish_expr_stmt (stmt);
12458 : 3312 : }
12459 : :
12460 : : void
12461 : 359 : finish_omp_barrier (void)
12462 : : {
12463 : 359 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
12464 : 359 : releasing_vec vec;
12465 : 359 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12466 : 359 : finish_expr_stmt (stmt);
12467 : 359 : }
12468 : :
12469 : : void
12470 : 397 : finish_omp_depobj (location_t loc, tree depobj,
12471 : : enum omp_clause_depend_kind kind, tree clause)
12472 : : {
12473 : 397 : if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
12474 : : {
12475 : 343 : if (!lvalue_p (depobj))
12476 : : {
12477 : 6 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
12478 : : "%<depobj%> expression is not lvalue expression");
12479 : 6 : depobj = error_mark_node;
12480 : : }
12481 : : }
12482 : :
12483 : 397 : if (processing_template_decl)
12484 : : {
12485 : 114 : if (clause == NULL_TREE)
12486 : 47 : clause = build_int_cst (integer_type_node, kind);
12487 : 114 : add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
12488 : 114 : return;
12489 : : }
12490 : :
12491 : 283 : if (!error_operand_p (depobj))
12492 : : {
12493 : 274 : tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
12494 : 274 : if (addr == error_mark_node)
12495 : : depobj = error_mark_node;
12496 : : else
12497 : 274 : depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
12498 : : tf_warning_or_error);
12499 : : }
12500 : :
12501 : 283 : c_finish_omp_depobj (loc, depobj, kind, clause);
12502 : : }
12503 : :
12504 : : void
12505 : 162 : finish_omp_flush (int mo)
12506 : : {
12507 : 162 : tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
12508 : 162 : releasing_vec vec;
12509 : 162 : if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
12510 : : {
12511 : 54 : fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
12512 : 54 : vec->quick_push (build_int_cst (integer_type_node, mo));
12513 : : }
12514 : 162 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12515 : 162 : finish_expr_stmt (stmt);
12516 : 162 : }
12517 : :
12518 : : void
12519 : 111 : finish_omp_taskwait (void)
12520 : : {
12521 : 111 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
12522 : 111 : releasing_vec vec;
12523 : 111 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12524 : 111 : finish_expr_stmt (stmt);
12525 : 111 : }
12526 : :
12527 : : void
12528 : 16 : finish_omp_taskyield (void)
12529 : : {
12530 : 16 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
12531 : 16 : releasing_vec vec;
12532 : 16 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12533 : 16 : finish_expr_stmt (stmt);
12534 : 16 : }
12535 : :
12536 : : void
12537 : 596 : finish_omp_cancel (tree clauses)
12538 : : {
12539 : 596 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
12540 : 596 : int mask = 0;
12541 : 596 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12542 : : mask = 1;
12543 : 414 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12544 : : mask = 2;
12545 : 285 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12546 : : mask = 4;
12547 : 164 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12548 : : mask = 8;
12549 : : else
12550 : : {
12551 : 0 : error ("%<#pragma omp cancel%> must specify one of "
12552 : : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12553 : 0 : return;
12554 : : }
12555 : 596 : releasing_vec vec;
12556 : 596 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
12557 : 596 : if (ifc != NULL_TREE)
12558 : : {
12559 : 70 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
12560 : 70 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
12561 : 6 : error_at (OMP_CLAUSE_LOCATION (ifc),
12562 : : "expected %<cancel%> %<if%> clause modifier");
12563 : : else
12564 : : {
12565 : 64 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
12566 : 64 : if (ifc2 != NULL_TREE)
12567 : : {
12568 : 3 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
12569 : : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
12570 : : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
12571 : 3 : error_at (OMP_CLAUSE_LOCATION (ifc2),
12572 : : "expected %<cancel%> %<if%> clause modifier");
12573 : : }
12574 : : }
12575 : :
12576 : 70 : if (!processing_template_decl)
12577 : 61 : ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
12578 : : else
12579 : 9 : ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
12580 : 9 : OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
12581 : : integer_zero_node, ERROR_MARK,
12582 : : NULL_TREE, NULL, tf_warning_or_error);
12583 : : }
12584 : : else
12585 : 526 : ifc = boolean_true_node;
12586 : 596 : vec->quick_push (build_int_cst (integer_type_node, mask));
12587 : 596 : vec->quick_push (ifc);
12588 : 596 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12589 : 596 : finish_expr_stmt (stmt);
12590 : 596 : }
12591 : :
12592 : : void
12593 : 494 : finish_omp_cancellation_point (tree clauses)
12594 : : {
12595 : 494 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
12596 : 494 : int mask = 0;
12597 : 494 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12598 : : mask = 1;
12599 : 366 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12600 : : mask = 2;
12601 : 261 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12602 : : mask = 4;
12603 : 156 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12604 : : mask = 8;
12605 : : else
12606 : : {
12607 : 3 : error ("%<#pragma omp cancellation point%> must specify one of "
12608 : : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12609 : 3 : return;
12610 : : }
12611 : 491 : releasing_vec vec
12612 : 491 : = make_tree_vector_single (build_int_cst (integer_type_node, mask));
12613 : 491 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12614 : 491 : finish_expr_stmt (stmt);
12615 : 491 : }
12616 : :
12617 : : /* Begin a __transaction_atomic or __transaction_relaxed statement.
12618 : : If PCOMPOUND is non-null, this is for a function-transaction-block, and we
12619 : : should create an extra compound stmt. */
12620 : :
12621 : : tree
12622 : 303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
12623 : : {
12624 : 303 : tree r;
12625 : :
12626 : 303 : if (pcompound)
12627 : 21 : *pcompound = begin_compound_stmt (0);
12628 : :
12629 : 303 : r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
12630 : :
12631 : : /* Only add the statement to the function if support enabled. */
12632 : 303 : if (flag_tm)
12633 : 297 : add_stmt (r);
12634 : : else
12635 : 12 : error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
12636 : : ? G_("%<__transaction_relaxed%> without "
12637 : : "transactional memory support enabled")
12638 : : : G_("%<__transaction_atomic%> without "
12639 : : "transactional memory support enabled")));
12640 : :
12641 : 303 : TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
12642 : 303 : TREE_SIDE_EFFECTS (r) = 1;
12643 : 303 : return r;
12644 : : }
12645 : :
12646 : : /* End a __transaction_atomic or __transaction_relaxed statement.
12647 : : If COMPOUND_STMT is non-null, this is for a function-transaction-block,
12648 : : and we should end the compound. If NOEX is non-NULL, we wrap the body in
12649 : : a MUST_NOT_THROW_EXPR with NOEX as condition. */
12650 : :
12651 : : void
12652 : 303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
12653 : : {
12654 : 303 : TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
12655 : 303 : TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
12656 : 303 : TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
12657 : 303 : TRANSACTION_EXPR_IS_STMT (stmt) = 1;
12658 : :
12659 : : /* noexcept specifications are not allowed for function transactions. */
12660 : 303 : gcc_assert (!(noex && compound_stmt));
12661 : 303 : if (noex)
12662 : : {
12663 : 51 : tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
12664 : : noex);
12665 : 51 : protected_set_expr_location
12666 : 51 : (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
12667 : 51 : TREE_SIDE_EFFECTS (body) = 1;
12668 : 51 : TRANSACTION_EXPR_BODY (stmt) = body;
12669 : : }
12670 : :
12671 : 303 : if (compound_stmt)
12672 : 21 : finish_compound_stmt (compound_stmt);
12673 : 303 : }
12674 : :
12675 : : /* Build a __transaction_atomic or __transaction_relaxed expression. If
12676 : : NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
12677 : : condition. */
12678 : :
12679 : : tree
12680 : 116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
12681 : : {
12682 : 116 : tree ret;
12683 : 116 : if (noex)
12684 : : {
12685 : 57 : expr = build_must_not_throw_expr (expr, noex);
12686 : 57 : protected_set_expr_location (expr, loc);
12687 : 57 : TREE_SIDE_EFFECTS (expr) = 1;
12688 : : }
12689 : 116 : ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
12690 : 116 : if (flags & TM_STMT_ATTR_RELAXED)
12691 : 4 : TRANSACTION_EXPR_RELAXED (ret) = 1;
12692 : 116 : TREE_SIDE_EFFECTS (ret) = 1;
12693 : 116 : SET_EXPR_LOCATION (ret, loc);
12694 : 116 : return ret;
12695 : : }
12696 : :
12697 : : void
12698 : 97619 : init_cp_semantics (void)
12699 : : {
12700 : 97619 : }
12701 : :
12702 : :
12703 : : /* Get constant string at LOCATION. Returns true if successful,
12704 : : otherwise false. */
12705 : :
12706 : : bool
12707 : 10800965 : cexpr_str::type_check (location_t location)
12708 : : {
12709 : 10800965 : tsubst_flags_t complain = tf_warning_or_error;
12710 : :
12711 : 10800965 : if (message == NULL_TREE
12712 : 10800965 : || message == error_mark_node
12713 : 21601927 : || check_for_bare_parameter_packs (message))
12714 : 3 : return false;
12715 : :
12716 : 10800962 : if (TREE_CODE (message) != STRING_CST
12717 : 10800962 : && !type_dependent_expression_p (message))
12718 : : {
12719 : 901 : message_sz
12720 : 901 : = finish_class_member_access_expr (message,
12721 : : get_identifier ("size"),
12722 : : false, complain);
12723 : 901 : if (message_sz != error_mark_node)
12724 : 828 : message_data
12725 : 828 : = finish_class_member_access_expr (message,
12726 : : get_identifier ("data"),
12727 : : false, complain);
12728 : 901 : if (message_sz == error_mark_node || message_data == error_mark_node)
12729 : : {
12730 : 103 : error_at (location, "constexpr string must be a string "
12731 : : "literal or object with %<size%> and "
12732 : : "%<data%> members");
12733 : 262 : return false;
12734 : : }
12735 : 798 : releasing_vec size_args, data_args;
12736 : 798 : message_sz = finish_call_expr (message_sz, &size_args, false, false,
12737 : : complain);
12738 : 798 : message_data = finish_call_expr (message_data, &data_args, false, false,
12739 : : complain);
12740 : 798 : if (message_sz == error_mark_node || message_data == error_mark_node)
12741 : : return false;
12742 : 684 : message_sz = build_converted_constant_expr (size_type_node, message_sz,
12743 : : complain);
12744 : 684 : if (message_sz == error_mark_node)
12745 : : {
12746 : 15 : error_at (location, "constexpr string %<size()%> "
12747 : : "must be implicitly convertible to "
12748 : : "%<std::size_t%>");
12749 : 15 : return false;
12750 : : }
12751 : 669 : message_data = build_converted_constant_expr (const_string_type_node,
12752 : : message_data, complain);
12753 : 669 : if (message_data == error_mark_node)
12754 : : {
12755 : 30 : error_at (location, "constexpr string %<data()%> "
12756 : : "must be implicitly convertible to "
12757 : : "%<const char*%>");
12758 : 30 : return false;
12759 : : }
12760 : 798 : }
12761 : : return true;
12762 : : }
12763 : :
12764 : : /* Extract constant string at LOCATON into output string STR.
12765 : : Returns true if successful, otherwise false. */
12766 : :
12767 : : bool
12768 : 405 : cexpr_str::extract (location_t location, tree &str)
12769 : : {
12770 : 405 : const char *msg;
12771 : 405 : int len;
12772 : 405 : if (!extract (location, msg, len))
12773 : : return false;
12774 : 343 : str = build_string (len, msg);
12775 : 343 : return true;
12776 : : }
12777 : :
12778 : : /* Extract constant string at LOCATION into output string MSG with LEN.
12779 : : Returns true if successful, otherwise false. */
12780 : :
12781 : : bool
12782 : 2000 : cexpr_str::extract (location_t location, const char * & msg, int &len)
12783 : : {
12784 : 2000 : tsubst_flags_t complain = tf_warning_or_error;
12785 : :
12786 : 2000 : msg = NULL;
12787 : 2000 : if (message_sz && message_data)
12788 : : {
12789 : 565 : tree msz = cxx_constant_value (message_sz, NULL_TREE, complain);
12790 : 565 : if (!tree_fits_uhwi_p (msz))
12791 : : {
12792 : 35 : error_at (location,
12793 : : "constexpr string %<size()%> "
12794 : : "must be a constant expression");
12795 : 87 : return false;
12796 : : }
12797 : 530 : else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
12798 : : != tree_to_uhwi (msz))
12799 : : {
12800 : 0 : error_at (location,
12801 : : "constexpr string message %<size()%> "
12802 : : "%qE too large", msz);
12803 : 0 : return false;
12804 : : }
12805 : 530 : len = tree_to_uhwi (msz);
12806 : 530 : tree data = maybe_constant_value (message_data, NULL_TREE,
12807 : : mce_true);
12808 : 530 : if (!reduced_constant_expression_p (data))
12809 : 96 : data = NULL_TREE;
12810 : 530 : if (len)
12811 : : {
12812 : 453 : if (data)
12813 : 379 : msg = c_getstr (data);
12814 : 453 : if (msg == NULL)
12815 : 119 : buf = XNEWVEC (char, len);
12816 : 1452 : for (int i = 0; i < len; ++i)
12817 : : {
12818 : 1029 : tree t = message_data;
12819 : 1029 : if (i)
12820 : 1152 : t = build2 (POINTER_PLUS_EXPR,
12821 : 576 : TREE_TYPE (message_data), message_data,
12822 : 576 : size_int (i));
12823 : 1029 : t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
12824 : 1029 : tree t2 = cxx_constant_value (t, NULL_TREE, complain);
12825 : 1029 : if (!tree_fits_shwi_p (t2))
12826 : : {
12827 : 30 : error_at (location,
12828 : : "constexpr string %<data()[%d]%> "
12829 : : "must be a constant expression", i);
12830 : 30 : return false;
12831 : : }
12832 : 999 : if (msg == NULL)
12833 : 362 : buf[i] = tree_to_shwi (t2);
12834 : : /* If c_getstr worked, just verify the first and
12835 : : last characters using constant evaluation. */
12836 : 637 : else if (len > 2 && i == 0)
12837 : 266 : i = len - 2;
12838 : : }
12839 : 423 : if (msg == NULL)
12840 : 104 : msg = buf;
12841 : : }
12842 : 77 : else if (!data)
12843 : : {
12844 : : /* We don't have any function to test whether some
12845 : : expression is a core constant expression. So, instead
12846 : : test whether (message.data (), 0) is a constant
12847 : : expression. */
12848 : 22 : data = build2 (COMPOUND_EXPR, integer_type_node,
12849 : : message_data, integer_zero_node);
12850 : 22 : tree t = cxx_constant_value (data, NULL_TREE, complain);
12851 : 22 : if (!integer_zerop (t))
12852 : : {
12853 : 22 : error_at (location,
12854 : : "constexpr string %<data()%> "
12855 : : "must be a core constant expression");
12856 : 22 : return false;
12857 : : }
12858 : : }
12859 : : /* Convert the string from execution charset to SOURCE_CHARSET. */
12860 : 478 : cpp_string istr, ostr;
12861 : 478 : istr.len = len;
12862 : 478 : istr.text = (const unsigned char *) msg;
12863 : 478 : if (!cpp_translate_string (parse_in, &istr, &ostr, CPP_STRING, true))
12864 : : {
12865 : 0 : error_at (location, "could not convert constexpr string from "
12866 : : "ordinary literal encoding to source character "
12867 : : "set");
12868 : 0 : return false;
12869 : : }
12870 : : else
12871 : : {
12872 : 478 : if (buf)
12873 : 104 : XDELETEVEC (buf);
12874 : 478 : msg = buf = const_cast <char *> ((const char *) ostr.text);
12875 : 478 : len = ostr.len;
12876 : : }
12877 : 478 : }
12878 : : else
12879 : : {
12880 : 1435 : tree eltype = TREE_TYPE (TREE_TYPE (message));
12881 : 1435 : int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
12882 : 1435 : msg = TREE_STRING_POINTER (message);
12883 : 1435 : len = TREE_STRING_LENGTH (message) / sz - 1;
12884 : : }
12885 : :
12886 : : return true;
12887 : : }
12888 : :
12889 : : /* Build a STATIC_ASSERT for a static assertion with the condition
12890 : : CONDITION and the message text MESSAGE. LOCATION is the location
12891 : : of the static assertion in the source code. When MEMBER_P, this
12892 : : static assertion is a member of a class. If SHOW_EXPR_P is true,
12893 : : print the condition (because it was instantiation-dependent).
12894 : : If CONSTEVAL_BLOCK_P is true, this static assertion represents
12895 : : a consteval block. */
12896 : :
12897 : : void
12898 : 10800556 : finish_static_assert (tree condition, tree message, location_t location,
12899 : : bool member_p, bool show_expr_p,
12900 : : bool consteval_block_p/*=false*/)
12901 : : {
12902 : 10800556 : tsubst_flags_t complain = tf_warning_or_error;
12903 : :
12904 : 10800556 : if (condition == NULL_TREE
12905 : 10800556 : || condition == error_mark_node)
12906 : 4403771 : return;
12907 : :
12908 : 10800392 : if (check_for_bare_parameter_packs (condition))
12909 : : return;
12910 : :
12911 : 10800389 : cexpr_str cstr(message);
12912 : 10800389 : if (!cstr.type_check (location))
12913 : : return;
12914 : :
12915 : : /* Save the condition in case it was a concept check. */
12916 : 10800295 : tree orig_condition = condition;
12917 : :
12918 : 10800295 : if (instantiation_dependent_expression_p (condition)
12919 : 10800295 : || instantiation_dependent_expression_p (message))
12920 : : {
12921 : : /* We're in a template; build a STATIC_ASSERT and put it in
12922 : : the right place. */
12923 : 4403338 : defer:
12924 : 4403338 : tree assertion = make_node (STATIC_ASSERT);
12925 : 4403338 : STATIC_ASSERT_CONDITION (assertion) = orig_condition;
12926 : 4403338 : STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
12927 : 4403338 : STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
12928 : 4403338 : CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
12929 : :
12930 : 4403338 : if (member_p)
12931 : 2292428 : maybe_add_class_template_decl_list (current_class_type,
12932 : : assertion,
12933 : : /*friend_p=*/0);
12934 : : else
12935 : 2110910 : add_stmt (assertion);
12936 : :
12937 : 4403338 : return;
12938 : : }
12939 : :
12940 : : /* Evaluate the consteval { }. This must be done only once. */
12941 : 6399336 : if (consteval_block_p)
12942 : : {
12943 : 147 : cxx_constant_value (condition);
12944 : 147 : return;
12945 : : }
12946 : :
12947 : : /* Fold the expression and convert it to a boolean value. */
12948 : 6399189 : condition = contextual_conv_bool (condition, complain);
12949 : 6399189 : condition = fold_non_dependent_expr (condition, complain,
12950 : : /*manifestly_const_eval=*/true);
12951 : :
12952 : 6399188 : if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
12953 : : /* Do nothing; the condition is satisfied. */
12954 : : ;
12955 : : else
12956 : : {
12957 : 4466 : iloc_sentinel ils (location);
12958 : :
12959 : 4466 : if (integer_zerop (condition))
12960 : : {
12961 : : /* CWG2518: static_assert failure in a template is not IFNDR. */
12962 : 3974 : if (processing_template_decl)
12963 : 2379 : goto defer;
12964 : :
12965 : 1595 : int len;
12966 : 1595 : const char *msg = NULL;
12967 : 1595 : if (!cstr.extract (location, msg, len))
12968 : 25 : return;
12969 : :
12970 : : /* See if we can find which clause was failing (for logical AND). */
12971 : 1570 : tree bad = find_failing_clause (NULL, orig_condition);
12972 : : /* If not, or its location is unusable, fall back to the previous
12973 : : location. */
12974 : 1570 : location_t cloc = cp_expr_loc_or_loc (bad, location);
12975 : :
12976 : 1570 : auto_diagnostic_group d;
12977 : :
12978 : : /* Report the error. */
12979 : 1570 : if (len == 0)
12980 : 976 : error_at (cloc, "static assertion failed");
12981 : : else
12982 : 594 : error_at (cloc, "static assertion failed: %.*s", len, msg);
12983 : :
12984 : 1570 : diagnose_failing_condition (bad, cloc, show_expr_p);
12985 : :
12986 : : /* Suppress -Wreturn-type for functions with failed static_asserts.
12987 : : Otherwise templates like:
12988 : : if constexpr (whatever)
12989 : : return something (args);
12990 : : else
12991 : : static_assert (false, "explanation");
12992 : : get a useless extra -Wreturn-type warning. */
12993 : 1570 : if (current_function_decl)
12994 : 574 : suppress_warning (current_function_decl, OPT_Wreturn_type);
12995 : 1570 : }
12996 : 492 : else if (condition && condition != error_mark_node)
12997 : : {
12998 : 489 : error ("non-constant condition for static assertion");
12999 : 489 : if (require_rvalue_constant_expression (condition))
13000 : 433 : cxx_constant_value (condition);
13001 : : }
13002 : 4466 : }
13003 : 10800388 : }
13004 : :
13005 : : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
13006 : : suitable for use as a type-specifier.
13007 : :
13008 : : ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
13009 : : id-expression or a class member access, FALSE when it was parsed as
13010 : : a full expression. */
13011 : :
13012 : : tree
13013 : 62665293 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
13014 : : tsubst_flags_t complain)
13015 : : {
13016 : 62665293 : tree type = NULL_TREE;
13017 : :
13018 : 62665293 : if (!expr || error_operand_p (expr))
13019 : 224878 : return error_mark_node;
13020 : :
13021 : 62440415 : if (TYPE_P (expr)
13022 : 62440415 : || TREE_CODE (expr) == TYPE_DECL
13023 : 124880812 : || (TREE_CODE (expr) == BIT_NOT_EXPR
13024 : 13224 : && TYPE_P (TREE_OPERAND (expr, 0))))
13025 : : {
13026 : 27 : if (complain & tf_error)
13027 : 27 : error ("argument to %<decltype%> must be an expression");
13028 : 27 : return error_mark_node;
13029 : : }
13030 : :
13031 : : /* decltype is an unevaluated context. */
13032 : 62440388 : cp_unevaluated u;
13033 : :
13034 : 62440388 : processing_template_decl_sentinel ptds (/*reset=*/false);
13035 : :
13036 : : /* Depending on the resolution of DR 1172, we may later need to distinguish
13037 : : instantiation-dependent but not type-dependent expressions so that, say,
13038 : : A<decltype(sizeof(T))>::U doesn't require 'typename'. */
13039 : 62440388 : if (instantiation_dependent_uneval_expression_p (expr))
13040 : : {
13041 : 6832742 : dependent:
13042 : 6833126 : type = cxx_make_type (DECLTYPE_TYPE);
13043 : 6833126 : DECLTYPE_TYPE_EXPR (type) = expr;
13044 : 13666252 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
13045 : 6833126 : = id_expression_or_member_access_p;
13046 : 6833126 : SET_TYPE_STRUCTURAL_EQUALITY (type);
13047 : :
13048 : 6833126 : return type;
13049 : : }
13050 : 55607646 : else if (processing_template_decl)
13051 : : {
13052 : 4236 : expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
13053 : 4236 : if (expr == error_mark_node)
13054 : : return error_mark_node;
13055 : : /* Keep processing_template_decl cleared for the rest of the function
13056 : : (for sake of the call to lvalue_kind below, which handles templated
13057 : : and non-templated COND_EXPR differently). */
13058 : 4199 : processing_template_decl = 0;
13059 : : }
13060 : :
13061 : : /* The type denoted by decltype(e) is defined as follows: */
13062 : :
13063 : 55607609 : expr = resolve_nondeduced_context (expr, complain);
13064 : 55607609 : if (!mark_single_function (expr, complain))
13065 : 0 : return error_mark_node;
13066 : :
13067 : 55607609 : if (invalid_nonstatic_memfn_p (input_location, expr, complain))
13068 : 18 : return error_mark_node;
13069 : :
13070 : 55607591 : if (type_unknown_p (expr))
13071 : : {
13072 : 18 : if (complain & tf_error)
13073 : 6 : error ("%<decltype%> cannot resolve address of overloaded function");
13074 : 18 : return error_mark_node;
13075 : : }
13076 : :
13077 : 55607573 : if (id_expression_or_member_access_p)
13078 : : {
13079 : : /* If e is an id-expression or a class member access (5.2.5
13080 : : [expr.ref]), decltype(e) is defined as the type of the entity
13081 : : named by e. If there is no such entity, or e names a set of
13082 : : overloaded functions, the program is ill-formed. */
13083 : 2836483 : if (identifier_p (expr))
13084 : 0 : expr = lookup_name (expr);
13085 : :
13086 : : /* If e is a constified expression inside a contract assertion,
13087 : : strip the const wrapper. Per P2900R14, "For a function f with the
13088 : : return type T , the result name is an lvalue of type const T , decltype(r)
13089 : : is T , and decltype((r)) is const T&." */
13090 : 2836483 : expr = strip_contract_const_wrapper (expr);
13091 : :
13092 : 2836483 : if (INDIRECT_REF_P (expr)
13093 : 2836483 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
13094 : : /* This can happen when the expression is, e.g., "a.b". Just
13095 : : look at the underlying operand. */
13096 : 2598832 : expr = TREE_OPERAND (expr, 0);
13097 : :
13098 : 2836483 : if (TREE_CODE (expr) == OFFSET_REF
13099 : 2836483 : || TREE_CODE (expr) == MEMBER_REF
13100 : 2836483 : || TREE_CODE (expr) == SCOPE_REF)
13101 : : /* We're only interested in the field itself. If it is a
13102 : : BASELINK, we will need to see through it in the next
13103 : : step. */
13104 : 0 : expr = TREE_OPERAND (expr, 1);
13105 : :
13106 : 2836483 : if (BASELINK_P (expr))
13107 : : /* See through BASELINK nodes to the underlying function. */
13108 : 4 : expr = BASELINK_FUNCTIONS (expr);
13109 : :
13110 : : /* decltype of a decomposition name drops references in the tuple case
13111 : : (unlike decltype of a normal variable) and keeps cv-qualifiers from
13112 : : the containing object in the other cases (unlike decltype of a member
13113 : : access expression). */
13114 : 2836483 : if (DECL_DECOMPOSITION_P (expr))
13115 : : {
13116 : 1412 : if (ptds.saved)
13117 : : {
13118 : 275 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr)
13119 : : || (DECL_CONTEXT (expr)
13120 : : != current_function_decl));
13121 : : /* DECL_HAS_VALUE_EXPR_P is always set if
13122 : : processing_template_decl at least for structured bindings
13123 : : within the template. If lookup_decomp_type
13124 : : returns non-NULL, it is the tuple case. */
13125 : 275 : if (tree ret = lookup_decomp_type (expr))
13126 : : return ret;
13127 : 191 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
13128 : : }
13129 : 1328 : if (DECL_HAS_VALUE_EXPR_P (expr))
13130 : : /* Expr is an array or struct subobject proxy, handle
13131 : : bit-fields properly. */
13132 : 1016 : return unlowered_expr_type (expr);
13133 : : else
13134 : : /* Expr is a reference variable for the tuple case. */
13135 : 312 : return lookup_decomp_type (expr);
13136 : : }
13137 : :
13138 : 2835071 : switch (TREE_CODE (expr))
13139 : : {
13140 : 222 : case FIELD_DECL:
13141 : 222 : if (DECL_BIT_FIELD_TYPE (expr))
13142 : : {
13143 : : type = DECL_BIT_FIELD_TYPE (expr);
13144 : : break;
13145 : : }
13146 : : /* Fall through for fields that aren't bitfields. */
13147 : 195211 : gcc_fallthrough ();
13148 : :
13149 : 195211 : case VAR_DECL:
13150 : 195211 : if (is_capture_proxy (expr))
13151 : : {
13152 : 85 : if (is_normal_capture_proxy (expr))
13153 : : {
13154 : 21 : expr = DECL_CAPTURED_VARIABLE (expr);
13155 : 21 : type = TREE_TYPE (expr);
13156 : : }
13157 : : else
13158 : : {
13159 : 64 : expr = DECL_VALUE_EXPR (expr);
13160 : 64 : gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
13161 : 64 : expr = TREE_OPERAND (expr, 1);
13162 : 64 : type = TREE_TYPE (expr);
13163 : : }
13164 : : break;
13165 : : }
13166 : : /* Fall through for variables that aren't capture proxies. */
13167 : 2831413 : gcc_fallthrough ();
13168 : :
13169 : 2831413 : case FUNCTION_DECL:
13170 : 2831413 : case CONST_DECL:
13171 : 2831413 : case PARM_DECL:
13172 : 2831413 : case RESULT_DECL:
13173 : 2831413 : case TEMPLATE_PARM_INDEX:
13174 : 2831413 : expr = mark_type_use (expr);
13175 : 2831413 : type = TREE_TYPE (expr);
13176 : 2831413 : if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
13177 : : {
13178 : : /* decltype of an NTTP object is the type of the template
13179 : : parameter, which is the object type modulo cv-quals. */
13180 : 1093 : int quals = cp_type_quals (type);
13181 : 1093 : gcc_checking_assert (quals & TYPE_QUAL_CONST);
13182 : 1093 : type = cv_unqualified (type);
13183 : : }
13184 : : break;
13185 : :
13186 : 0 : case ERROR_MARK:
13187 : 0 : type = error_mark_node;
13188 : 0 : break;
13189 : :
13190 : 3013 : case COMPONENT_REF:
13191 : 3013 : case COMPOUND_EXPR:
13192 : 3013 : mark_type_use (expr);
13193 : 3013 : type = is_bitfield_expr_with_lowered_type (expr);
13194 : 3013 : if (!type)
13195 : 2978 : type = TREE_TYPE (TREE_OPERAND (expr, 1));
13196 : : break;
13197 : :
13198 : 0 : case BIT_FIELD_REF:
13199 : 0 : gcc_unreachable ();
13200 : :
13201 : 324 : case INTEGER_CST:
13202 : 324 : case PTRMEM_CST:
13203 : : /* We can get here when the id-expression refers to an
13204 : : enumerator or non-type template parameter. */
13205 : 324 : type = TREE_TYPE (expr);
13206 : 324 : break;
13207 : :
13208 : 236 : default:
13209 : : /* Handle instantiated template non-type arguments. */
13210 : 236 : type = TREE_TYPE (expr);
13211 : 236 : break;
13212 : : }
13213 : : }
13214 : : else
13215 : : {
13216 : 52771090 : tree decl = STRIP_REFERENCE_REF (expr);
13217 : 52771090 : tree lam = current_lambda_expr ();
13218 : 52771090 : if (lam && outer_automatic_var_p (decl))
13219 : : {
13220 : : /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
13221 : : unevaluated operand within S would refer to an entity captured by
13222 : : copy in some intervening lambda-expression, then let E be the
13223 : : innermost such lambda-expression.
13224 : :
13225 : : If there is such a lambda-expression and if P is in E's function
13226 : : parameter scope but not its parameter-declaration-clause, then the
13227 : : type of the expression is the type of a class member access
13228 : : expression naming the non-static data member that would be declared
13229 : : for such a capture in the object parameter of the function call
13230 : : operator of E." */
13231 : : /* FIXME: This transformation needs to happen for all uses of an outer
13232 : : local variable inside decltype, not just decltype((x)) (PR83167).
13233 : : And we don't handle nested lambdas properly, where we need to
13234 : : consider the outer lambdas as well (PR112926). */
13235 : 940 : tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
13236 : : LOOK_want::HIDDEN_LAMBDA);
13237 : :
13238 : 940 : if (cap && is_capture_proxy (cap))
13239 : 319 : type = TREE_TYPE (cap);
13240 : 621 : else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
13241 : : {
13242 : 500 : type = TREE_TYPE (decl);
13243 : 500 : if (TYPE_REF_P (type)
13244 : 500 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
13245 : 25 : type = TREE_TYPE (type);
13246 : : }
13247 : :
13248 : 819 : if (type && !TYPE_REF_P (type))
13249 : : {
13250 : 761 : int quals;
13251 : 761 : if (current_function_decl
13252 : 1428 : && LAMBDA_FUNCTION_P (current_function_decl)
13253 : 1428 : && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
13254 : : {
13255 : 600 : tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
13256 : 600 : if (WILDCARD_TYPE_P (non_reference (obtype)))
13257 : : /* We don't know what the eventual obtype quals will be. */
13258 : 384 : goto dependent;
13259 : 432 : auto direct_type = [](tree t){
13260 : 216 : if (INDIRECT_TYPE_P (t))
13261 : 108 : return TREE_TYPE (t);
13262 : : return t;
13263 : : };
13264 : 432 : quals = (cp_type_quals (type)
13265 : 216 : | cp_type_quals (direct_type (obtype)));
13266 : : }
13267 : : else
13268 : : /* We are in the parameter clause, trailing return type, or
13269 : : the requires clause and have no relevant c_f_decl yet. */
13270 : 251 : quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
13271 : 161 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
13272 : 377 : type = cp_build_qualified_type (type, quals);
13273 : 377 : type = build_reference_type (type);
13274 : : }
13275 : : }
13276 : 52770150 : else if (error_operand_p (expr))
13277 : 0 : type = error_mark_node;
13278 : 52770150 : else if (expr == current_class_ptr)
13279 : : /* If the expression is just "this", we want the
13280 : : cv-unqualified pointer for the "this" type. */
13281 : 0 : type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
13282 : :
13283 : 377 : if (!type)
13284 : : {
13285 : : /* Otherwise, where T is the type of e, if e is an lvalue,
13286 : : decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
13287 : 52770271 : cp_lvalue_kind clk = lvalue_kind (expr);
13288 : 52770271 : type = unlowered_expr_type (expr);
13289 : 52770271 : gcc_assert (!TYPE_REF_P (type));
13290 : :
13291 : : /* For vector types, pick a non-opaque variant. */
13292 : 52770271 : if (VECTOR_TYPE_P (type))
13293 : 127 : type = strip_typedefs (type);
13294 : :
13295 : 52770271 : if (clk != clk_none && !(clk & clk_class))
13296 : 10518077 : type = cp_build_reference_type (type, (clk & clk_rvalueref));
13297 : : }
13298 : : }
13299 : :
13300 : : return type;
13301 : 62440388 : }
13302 : :
13303 : : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
13304 : : __has_nothrow_copy, depending on assign_p. Returns true iff all
13305 : : the copy {ctor,assign} fns are nothrow. */
13306 : :
13307 : : static bool
13308 : 279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
13309 : : {
13310 : 279 : tree fns = NULL_TREE;
13311 : :
13312 : 279 : if (assign_p || TYPE_HAS_COPY_CTOR (type))
13313 : 276 : fns = get_class_binding (type, assign_p ? assign_op_identifier
13314 : : : ctor_identifier);
13315 : :
13316 : 279 : bool saw_copy = false;
13317 : 696 : for (ovl_iterator iter (fns); iter; ++iter)
13318 : : {
13319 : 441 : tree fn = *iter;
13320 : :
13321 : 441 : if (copy_fn_p (fn) > 0)
13322 : : {
13323 : 423 : saw_copy = true;
13324 : 423 : if (!maybe_instantiate_noexcept (fn)
13325 : 423 : || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
13326 : 192 : return false;
13327 : : }
13328 : : }
13329 : :
13330 : 87 : return saw_copy;
13331 : : }
13332 : :
13333 : : /* Return true if BASE is a pointer-interconvertible base of DERIVED. */
13334 : :
13335 : : bool
13336 : 157 : pointer_interconvertible_base_of_p (tree base, tree derived,
13337 : : bool explain/*=false*/)
13338 : : {
13339 : 157 : if (base == error_mark_node || derived == error_mark_node)
13340 : : return false;
13341 : :
13342 : 157 : base = TYPE_MAIN_VARIANT (base);
13343 : 157 : derived = TYPE_MAIN_VARIANT (derived);
13344 : 157 : if (!NON_UNION_CLASS_TYPE_P (base))
13345 : : {
13346 : 15 : if (explain)
13347 : 3 : inform (location_of (base),
13348 : : "%qT is not a non-union class type", base);
13349 : 15 : return false;
13350 : : }
13351 : 142 : if (!NON_UNION_CLASS_TYPE_P (derived))
13352 : : {
13353 : 6 : if (explain)
13354 : 3 : inform (location_of (derived),
13355 : : "%qT is not a non-union class type", derived);
13356 : 6 : return false;
13357 : : }
13358 : :
13359 : 136 : if (same_type_p (base, derived))
13360 : : return true;
13361 : :
13362 : 106 : if (!std_layout_type_p (derived))
13363 : : {
13364 : 17 : if (explain)
13365 : 6 : inform (location_of (derived),
13366 : : "%qT is not a standard-layout type", derived);
13367 : 17 : return false;
13368 : : }
13369 : :
13370 : 89 : if (!uniquely_derived_from_p (base, derived))
13371 : : {
13372 : 16 : if (explain)
13373 : : {
13374 : : /* An ambiguous base should already be impossible due to
13375 : : the std_layout_type_p check. */
13376 : 3 : gcc_checking_assert (!DERIVED_FROM_P (base, derived));
13377 : 3 : inform (location_of (derived),
13378 : : "%qT is not a base of %qT", base, derived);
13379 : : }
13380 : 16 : return false;
13381 : : }
13382 : :
13383 : : return true;
13384 : : }
13385 : :
13386 : : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
13387 : : return true if MEMBERTYPE is the type of the first non-static data member
13388 : : of TYPE or for unions of any members. */
13389 : : static bool
13390 : 637 : first_nonstatic_data_member_p (tree type, tree membertype)
13391 : : {
13392 : 1297 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
13393 : : {
13394 : 1222 : if (TREE_CODE (field) != FIELD_DECL)
13395 : 135 : continue;
13396 : 1087 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
13397 : 60 : continue;
13398 : 1027 : if (DECL_FIELD_IS_BASE (field))
13399 : 45 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
13400 : 982 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13401 : : {
13402 : 216 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
13403 : 138 : || std_layout_type_p (TREE_TYPE (field)))
13404 : 294 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
13405 : : return true;
13406 : : }
13407 : 766 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13408 : : membertype))
13409 : : return true;
13410 : 537 : if (TREE_CODE (type) != UNION_TYPE)
13411 : : return false;
13412 : : }
13413 : : return false;
13414 : : }
13415 : :
13416 : : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
13417 : :
13418 : : tree
13419 : 536 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
13420 : : tree *args)
13421 : : {
13422 : : /* Unless users call the builtin directly, the following 3 checks should be
13423 : : ensured from std::is_pointer_interconvertible_with_class function
13424 : : template. */
13425 : 536 : if (nargs != 1)
13426 : : {
13427 : 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13428 : : "needs a single argument");
13429 : 6 : return boolean_false_node;
13430 : : }
13431 : 530 : tree arg = args[0];
13432 : 530 : if (error_operand_p (arg))
13433 : 0 : return boolean_false_node;
13434 : 530 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
13435 : : {
13436 : 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13437 : : "argument is not pointer to member");
13438 : 6 : return boolean_false_node;
13439 : : }
13440 : :
13441 : 524 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
13442 : 18 : return boolean_false_node;
13443 : :
13444 : 506 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
13445 : 506 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
13446 : 506 : if (!complete_type_or_else (basetype, NULL_TREE))
13447 : 3 : return boolean_false_node;
13448 : :
13449 : 503 : if (TREE_CODE (basetype) != UNION_TYPE
13450 : 503 : && !std_layout_type_p (basetype))
13451 : 22 : return boolean_false_node;
13452 : :
13453 : 481 : if (!first_nonstatic_data_member_p (basetype, membertype))
13454 : 132 : return boolean_false_node;
13455 : :
13456 : 349 : if (TREE_CODE (arg) == PTRMEM_CST)
13457 : 68 : arg = cplus_expand_constant (arg);
13458 : :
13459 : 349 : if (integer_nonzerop (arg))
13460 : 10 : return boolean_false_node;
13461 : 339 : if (integer_zerop (arg))
13462 : 71 : return boolean_true_node;
13463 : :
13464 : 268 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
13465 : : build_zero_cst (TREE_TYPE (arg)));
13466 : : }
13467 : :
13468 : : /* Helper function for is_corresponding_member_aggr. Return true if
13469 : : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
13470 : : union or structure BASETYPE. */
13471 : :
13472 : : static bool
13473 : 90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
13474 : : {
13475 : 222 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
13476 : 192 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
13477 : 36 : continue;
13478 : 156 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13479 : : membertype))
13480 : : {
13481 : 48 : if (TREE_CODE (arg) != INTEGER_CST
13482 : 48 : || tree_int_cst_equal (arg, byte_position (field)))
13483 : 48 : return true;
13484 : : }
13485 : 108 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13486 : : {
13487 : 18 : tree narg = arg;
13488 : 18 : if (TREE_CODE (basetype) != UNION_TYPE
13489 : 0 : && TREE_CODE (narg) == INTEGER_CST)
13490 : 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
13491 : 18 : if (is_corresponding_member_union (TREE_TYPE (field),
13492 : : membertype, narg))
13493 : : return true;
13494 : : }
13495 : : return false;
13496 : : }
13497 : :
13498 : : /* Helper function for fold_builtin_is_corresponding_member call.
13499 : : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
13500 : : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
13501 : : boolean_true_node if they are corresponding members, or for
13502 : : non-constant ARG2 the highest member offset for corresponding
13503 : : members. */
13504 : :
13505 : : static tree
13506 : 550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
13507 : : tree arg1, tree basetype2, tree membertype2,
13508 : : tree arg2)
13509 : : {
13510 : 550 : tree field1 = TYPE_FIELDS (basetype1);
13511 : 550 : tree field2 = TYPE_FIELDS (basetype2);
13512 : 550 : tree ret = boolean_false_node;
13513 : 2376 : while (1)
13514 : : {
13515 : 1463 : bool r = next_common_initial_sequence (field1, field2);
13516 : 1463 : if (field1 == NULL_TREE || field2 == NULL_TREE)
13517 : : break;
13518 : 1331 : if (r
13519 : 1038 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
13520 : : membertype1)
13521 : 1841 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
13522 : : membertype2))
13523 : : {
13524 : 504 : tree pos = byte_position (field1);
13525 : 504 : if (TREE_CODE (arg1) == INTEGER_CST
13526 : 504 : && tree_int_cst_equal (arg1, pos))
13527 : : {
13528 : 92 : if (TREE_CODE (arg2) == INTEGER_CST)
13529 : 92 : return boolean_true_node;
13530 : : return pos;
13531 : : }
13532 : 412 : else if (TREE_CODE (arg1) != INTEGER_CST)
13533 : 1188 : ret = pos;
13534 : : }
13535 : 1654 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
13536 : 944 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
13537 : : {
13538 : 117 : if ((!lookup_attribute ("no_unique_address",
13539 : 117 : DECL_ATTRIBUTES (field1)))
13540 : 117 : != !lookup_attribute ("no_unique_address",
13541 : 117 : DECL_ATTRIBUTES (field2)))
13542 : : break;
13543 : 117 : if (!tree_int_cst_equal (bit_position (field1),
13544 : 117 : bit_position (field2)))
13545 : : break;
13546 : 99 : bool overlap = true;
13547 : 99 : tree pos = byte_position (field1);
13548 : 99 : if (TREE_CODE (arg1) == INTEGER_CST)
13549 : : {
13550 : 27 : tree off1 = fold_convert (sizetype, arg1);
13551 : 27 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
13552 : 27 : if (tree_int_cst_lt (off1, pos)
13553 : 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
13554 : : overlap = false;
13555 : : }
13556 : 99 : if (TREE_CODE (arg2) == INTEGER_CST)
13557 : : {
13558 : 27 : tree off2 = fold_convert (sizetype, arg2);
13559 : 27 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
13560 : 27 : if (tree_int_cst_lt (off2, pos)
13561 : 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
13562 : : overlap = false;
13563 : : }
13564 : 87 : if (overlap
13565 : 87 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
13566 : 126 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
13567 : : {
13568 : 39 : tree narg1 = arg1;
13569 : 39 : if (TREE_CODE (arg1) == INTEGER_CST)
13570 : 9 : narg1 = size_binop (MINUS_EXPR,
13571 : : fold_convert (sizetype, arg1), pos);
13572 : 39 : tree narg2 = arg2;
13573 : 39 : if (TREE_CODE (arg2) == INTEGER_CST)
13574 : 9 : narg2 = size_binop (MINUS_EXPR,
13575 : : fold_convert (sizetype, arg2), pos);
13576 : 39 : tree t1 = TREE_TYPE (field1);
13577 : 39 : tree t2 = TREE_TYPE (field2);
13578 : 39 : tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
13579 : : narg1, t2, membertype2,
13580 : : narg2);
13581 : 39 : if (nret != boolean_false_node)
13582 : : {
13583 : 39 : if (nret == boolean_true_node)
13584 : : return nret;
13585 : 30 : if (TREE_CODE (arg1) == INTEGER_CST)
13586 : 0 : return size_binop (PLUS_EXPR, nret, pos);
13587 : 30 : ret = size_binop (PLUS_EXPR, nret, pos);
13588 : : }
13589 : : }
13590 : 60 : else if (overlap
13591 : 48 : && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
13592 : 108 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
13593 : : {
13594 : 48 : tree narg1 = arg1;
13595 : 48 : if (TREE_CODE (arg1) == INTEGER_CST)
13596 : 6 : narg1 = size_binop (MINUS_EXPR,
13597 : : fold_convert (sizetype, arg1), pos);
13598 : 48 : tree narg2 = arg2;
13599 : 48 : if (TREE_CODE (arg2) == INTEGER_CST)
13600 : 6 : narg2 = size_binop (MINUS_EXPR,
13601 : : fold_convert (sizetype, arg2), pos);
13602 : 48 : if (is_corresponding_member_union (TREE_TYPE (field1),
13603 : : membertype1, narg1)
13604 : 48 : && is_corresponding_member_union (TREE_TYPE (field2),
13605 : : membertype2, narg2))
13606 : : {
13607 : 24 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
13608 : : "not well defined for anonymous unions");
13609 : 24 : return boolean_false_node;
13610 : : }
13611 : : }
13612 : : }
13613 : 1188 : if (!r)
13614 : : break;
13615 : 913 : field1 = DECL_CHAIN (field1);
13616 : 913 : field2 = DECL_CHAIN (field2);
13617 : 913 : }
13618 : : return ret;
13619 : : }
13620 : :
13621 : : /* Fold __builtin_is_corresponding_member call. */
13622 : :
13623 : : tree
13624 : 699 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
13625 : : tree *args)
13626 : : {
13627 : : /* Unless users call the builtin directly, the following 3 checks should be
13628 : : ensured from std::is_corresponding_member function template. */
13629 : 699 : if (nargs != 2)
13630 : : {
13631 : 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13632 : : "needs two arguments");
13633 : 9 : return boolean_false_node;
13634 : : }
13635 : 690 : tree arg1 = args[0];
13636 : 690 : tree arg2 = args[1];
13637 : 690 : if (error_operand_p (arg1) || error_operand_p (arg2))
13638 : 0 : return boolean_false_node;
13639 : 711 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
13640 : 705 : || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
13641 : : {
13642 : 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13643 : : "argument is not pointer to member");
13644 : 9 : return boolean_false_node;
13645 : : }
13646 : :
13647 : 681 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
13648 : 681 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
13649 : 15 : return boolean_false_node;
13650 : :
13651 : 666 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
13652 : 666 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
13653 : 666 : if (!complete_type_or_else (basetype1, NULL_TREE))
13654 : 12 : return boolean_false_node;
13655 : :
13656 : 654 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
13657 : 654 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
13658 : 654 : if (!complete_type_or_else (basetype2, NULL_TREE))
13659 : 12 : return boolean_false_node;
13660 : :
13661 : 627 : if (!NON_UNION_CLASS_TYPE_P (basetype1)
13662 : 627 : || !NON_UNION_CLASS_TYPE_P (basetype2)
13663 : 627 : || !std_layout_type_p (basetype1)
13664 : 1233 : || !std_layout_type_p (basetype2))
13665 : 51 : return boolean_false_node;
13666 : :
13667 : : /* If the member types aren't layout compatible, then they
13668 : : can't be corresponding members. */
13669 : 591 : if (!layout_compatible_type_p (membertype1, membertype2))
13670 : 18 : return boolean_false_node;
13671 : :
13672 : 573 : if (TREE_CODE (arg1) == PTRMEM_CST)
13673 : 176 : arg1 = cplus_expand_constant (arg1);
13674 : 573 : if (TREE_CODE (arg2) == PTRMEM_CST)
13675 : 182 : arg2 = cplus_expand_constant (arg2);
13676 : :
13677 : 573 : if (null_member_pointer_value_p (arg1)
13678 : 573 : || null_member_pointer_value_p (arg2))
13679 : 9 : return boolean_false_node;
13680 : :
13681 : 564 : if (TREE_CODE (arg1) == INTEGER_CST
13682 : 182 : && TREE_CODE (arg2) == INTEGER_CST
13683 : 746 : && !tree_int_cst_equal (arg1, arg2))
13684 : 53 : return boolean_false_node;
13685 : :
13686 : 511 : if (TREE_CODE (arg2) == INTEGER_CST
13687 : 129 : && TREE_CODE (arg1) != INTEGER_CST)
13688 : : {
13689 : : std::swap (arg1, arg2);
13690 : : std::swap (membertype1, membertype2);
13691 : : std::swap (basetype1, basetype2);
13692 : : }
13693 : :
13694 : 511 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
13695 : : basetype2, membertype2, arg2);
13696 : 511 : if (TREE_TYPE (ret) == boolean_type_node)
13697 : : return ret;
13698 : : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
13699 : : already returns boolean_{true,false}_node whether those particular
13700 : : members are corresponding members or not. Otherwise, if only
13701 : : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
13702 : : above), it returns boolean_false_node if it is certainly not a
13703 : : corresponding member and otherwise we need to do a runtime check that
13704 : : those two OFFSET_TYPE offsets are equal.
13705 : : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
13706 : : returns the largest offset at which the members would be corresponding
13707 : : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
13708 : 304 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
13709 : 304 : if (TREE_CODE (arg1) == INTEGER_CST)
13710 : 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13711 : : fold_convert (TREE_TYPE (arg1), arg2));
13712 : 304 : ret = fold_build2 (LE_EXPR, boolean_type_node,
13713 : : fold_convert (pointer_sized_int_node, arg1),
13714 : : fold_convert (pointer_sized_int_node, ret));
13715 : 304 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
13716 : : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13717 : : fold_convert (TREE_TYPE (arg1), arg2)));
13718 : : }
13719 : :
13720 : : /* Fold __builtin_is_string_literal call. */
13721 : :
13722 : : tree
13723 : 1548 : fold_builtin_is_string_literal (location_t loc, int nargs, tree *args)
13724 : : {
13725 : : /* Unless users call the builtin directly, the following 3 checks should be
13726 : : ensured from std::is_string_literal overloads. */
13727 : 1548 : if (nargs != 1)
13728 : : {
13729 : 0 : error_at (loc, "%<__builtin_is_string_literal%> needs a single "
13730 : : "argument");
13731 : 0 : return boolean_false_node;
13732 : : }
13733 : 1548 : tree arg = args[0];
13734 : 1548 : if (error_operand_p (arg))
13735 : 0 : return boolean_false_node;
13736 : 1548 : if (!TYPE_PTR_P (TREE_TYPE (arg))
13737 : 1548 : || !TYPE_READONLY (TREE_TYPE (TREE_TYPE (arg)))
13738 : 3096 : || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (arg))))
13739 : : {
13740 : 0 : arg_invalid:
13741 : 0 : error_at (loc, "%<__builtin_is_string_literal%> "
13742 : : "argument is not %<const char*%>, %<const wchar_t*%>, "
13743 : : "%<const char8_t*%>, %<const char16_t*%> or "
13744 : : "%<const char32_t*%>");
13745 : 0 : return boolean_false_node;
13746 : : }
13747 : 1548 : tree chart = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg)));
13748 : 1548 : if (chart != char_type_node
13749 : 1236 : && chart != wchar_type_node
13750 : 927 : && chart != char8_type_node
13751 : 618 : && chart != char16_type_node
13752 : 309 : && chart != char32_type_node)
13753 : 0 : goto arg_invalid;
13754 : :
13755 : 1548 : STRIP_NOPS (arg);
13756 : 3102 : while (TREE_CODE (arg) == POINTER_PLUS_EXPR)
13757 : : {
13758 : 6 : arg = TREE_OPERAND (arg, 0);
13759 : 6 : STRIP_NOPS (arg);
13760 : : }
13761 : 1548 : if (TREE_CODE (arg) != ADDR_EXPR)
13762 : 1520 : return boolean_false_node;
13763 : 28 : arg = TREE_OPERAND (arg, 0);
13764 : 28 : if (TREE_CODE (arg) == ARRAY_REF)
13765 : 12 : arg = TREE_OPERAND (arg, 0);
13766 : 28 : if (TREE_CODE (arg) != STRING_CST)
13767 : 8 : return boolean_false_node;
13768 : 20 : return boolean_true_node;
13769 : : }
13770 : :
13771 : : /* [basic.types] 8. True iff TYPE is an object type. */
13772 : :
13773 : : static bool
13774 : 3324836 : object_type_p (const_tree type)
13775 : : {
13776 : 3324836 : return (TREE_CODE (type) != FUNCTION_TYPE
13777 : 0 : && !TYPE_REF_P (type)
13778 : 3324836 : && !VOID_TYPE_P (type));
13779 : : }
13780 : :
13781 : : /* [defns.referenceable] True iff TYPE is a referenceable type. */
13782 : :
13783 : : static bool
13784 : 4057618 : referenceable_type_p (const_tree type)
13785 : : {
13786 : 4057618 : return (TYPE_REF_P (type)
13787 : 4058004 : || object_type_p (type)
13788 : 4058004 : || (FUNC_OR_METHOD_TYPE_P (type)
13789 : 324 : && type_memfn_quals (type) == TYPE_UNQUALIFIED
13790 : 264 : && type_memfn_rqual (type) == REF_QUAL_NONE));
13791 : : }
13792 : :
13793 : : /* Actually evaluates the trait. */
13794 : :
13795 : : static bool
13796 : 21919715 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
13797 : : {
13798 : 21919715 : enum tree_code type_code1;
13799 : 21919715 : tree t;
13800 : :
13801 : 21919715 : type_code1 = TREE_CODE (type1);
13802 : :
13803 : 21919715 : switch (kind)
13804 : : {
13805 : 317 : case CPTK_HAS_NOTHROW_ASSIGN:
13806 : 317 : type1 = strip_array_types (type1);
13807 : 601 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
13808 : 601 : && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
13809 : 173 : || (CLASS_TYPE_P (type1)
13810 : 129 : && classtype_has_nothrow_assign_or_copy_p (type1,
13811 : : true))));
13812 : :
13813 : 215 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
13814 : 215 : type1 = strip_array_types (type1);
13815 : 215 : return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
13816 : 215 : || (CLASS_TYPE_P (type1)
13817 : 93 : && (t = locate_ctor (type1))
13818 : 60 : && maybe_instantiate_noexcept (t)
13819 : 58 : && TYPE_NOTHROW_P (TREE_TYPE (t))));
13820 : :
13821 : 305 : case CPTK_HAS_NOTHROW_COPY:
13822 : 305 : type1 = strip_array_types (type1);
13823 : 305 : return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
13824 : 305 : || (CLASS_TYPE_P (type1)
13825 : 150 : && classtype_has_nothrow_assign_or_copy_p (type1, false)));
13826 : :
13827 : 517 : case CPTK_HAS_TRIVIAL_ASSIGN:
13828 : : /* ??? The standard seems to be missing the "or array of such a class
13829 : : type" wording for this trait. */
13830 : 517 : type1 = strip_array_types (type1);
13831 : 1016 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
13832 : 1001 : && (trivial_type_p (type1)
13833 : 307 : || (CLASS_TYPE_P (type1)
13834 : 222 : && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
13835 : :
13836 : 505 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
13837 : 505 : type1 = strip_array_types (type1);
13838 : 505 : return (trivial_type_p (type1)
13839 : 505 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
13840 : :
13841 : 526 : case CPTK_HAS_TRIVIAL_COPY:
13842 : : /* ??? The standard seems to be missing the "or array of such a class
13843 : : type" wording for this trait. */
13844 : 526 : type1 = strip_array_types (type1);
13845 : 878 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
13846 : 863 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
13847 : :
13848 : 761 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
13849 : 761 : type1 = strip_array_types (type1);
13850 : 761 : if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
13851 : : {
13852 : 123 : deferring_access_check_sentinel dacs (dk_no_check);
13853 : 123 : cp_unevaluated un;
13854 : 123 : tree fn = get_dtor (type1, tf_none);
13855 : 123 : if (!fn && !seen_error ())
13856 : 3 : warning (0, "checking %qs for type %qT with a destructor that "
13857 : : "cannot be called", "__has_trivial_destructor", type1);
13858 : 123 : }
13859 : 1092 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
13860 : 1089 : || (CLASS_TYPE_P (type1)
13861 : 284 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
13862 : :
13863 : 57362 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
13864 : 57362 : return type_has_unique_obj_representations (type1);
13865 : :
13866 : 279 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
13867 : 279 : return type_has_virtual_destructor (type1);
13868 : :
13869 : 54289 : case CPTK_IS_ABSTRACT:
13870 : 54289 : return ABSTRACT_CLASS_TYPE_P (type1);
13871 : :
13872 : 813 : case CPTK_IS_AGGREGATE:
13873 : 813 : return CP_AGGREGATE_TYPE_P (type1);
13874 : :
13875 : 482829 : case CPTK_IS_ARRAY:
13876 : 482829 : return (type_code1 == ARRAY_TYPE
13877 : : /* We don't want to report T[0] as being an array type.
13878 : : This is for compatibility with an implementation of
13879 : : std::is_array by template argument deduction, because
13880 : : compute_array_index_type_loc rejects a zero-size array
13881 : : in SFINAE context. */
13882 : 482829 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
13883 : :
13884 : 1110134 : case CPTK_IS_ASSIGNABLE:
13885 : 1110134 : return is_xible (MODIFY_EXPR, type1, type2);
13886 : :
13887 : 584158 : case CPTK_IS_BASE_OF:
13888 : 584067 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
13889 : 1149765 : && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
13890 : 531609 : || DERIVED_FROM_P (type1, type2)));
13891 : :
13892 : 90346 : case CPTK_IS_BOUNDED_ARRAY:
13893 : 90346 : return (type_code1 == ARRAY_TYPE
13894 : 1090 : && TYPE_DOMAIN (type1)
13895 : : /* We don't want to report T[0] as being a bounded array type.
13896 : : This is for compatibility with an implementation of
13897 : : std::is_bounded_array by template argument deduction, because
13898 : : compute_array_index_type_loc rejects a zero-size array
13899 : : in SFINAE context. */
13900 : 91320 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
13901 : :
13902 : 679409 : case CPTK_IS_CLASS:
13903 : 679409 : return NON_UNION_CLASS_TYPE_P (type1);
13904 : :
13905 : 707937 : case CPTK_IS_CONST:
13906 : 707937 : return CP_TYPE_CONST_P (type1);
13907 : :
13908 : 3022796 : case CPTK_IS_CONSTRUCTIBLE:
13909 : 3022796 : return is_xible (INIT_EXPR, type1, type2);
13910 : :
13911 : 3717580 : case CPTK_IS_CONVERTIBLE:
13912 : 3717580 : return is_convertible (type1, type2);
13913 : :
13914 : 1677 : case CPTK_IS_DESTRUCTIBLE:
13915 : 1677 : return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
13916 : :
13917 : 245802 : case CPTK_IS_EMPTY:
13918 : 245802 : return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
13919 : :
13920 : 711888 : case CPTK_IS_ENUM:
13921 : 711888 : return type_code1 == ENUMERAL_TYPE;
13922 : :
13923 : 448402 : case CPTK_IS_FINAL:
13924 : 448402 : return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
13925 : :
13926 : 61127 : case CPTK_IS_FUNCTION:
13927 : 61127 : return type_code1 == FUNCTION_TYPE;
13928 : :
13929 : 667 : case CPTK_IS_IMPLICIT_LIFETIME:
13930 : 667 : return implicit_lifetime_type_p (type1);
13931 : :
13932 : 45880 : case CPTK_IS_INVOCABLE:
13933 : 45880 : return !error_operand_p (build_invoke (type1, type2, tf_none));
13934 : :
13935 : 195 : case CPTK_IS_LAYOUT_COMPATIBLE:
13936 : 195 : return layout_compatible_type_p (type1, type2);
13937 : :
13938 : 197 : case CPTK_IS_LITERAL_TYPE:
13939 : 197 : return literal_type_p (type1);
13940 : :
13941 : 45997 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
13942 : 45997 : return TYPE_PTRMEMFUNC_P (type1);
13943 : :
13944 : 45966 : case CPTK_IS_MEMBER_OBJECT_POINTER:
13945 : 45966 : return TYPE_PTRDATAMEM_P (type1);
13946 : :
13947 : 10223 : case CPTK_IS_MEMBER_POINTER:
13948 : 10223 : return TYPE_PTRMEM_P (type1);
13949 : :
13950 : 544633 : case CPTK_IS_NOTHROW_ASSIGNABLE:
13951 : 544633 : return is_nothrow_xible (MODIFY_EXPR, type1, type2);
13952 : :
13953 : 1003489 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
13954 : 1003489 : return is_nothrow_xible (INIT_EXPR, type1, type2);
13955 : :
13956 : 667 : case CPTK_IS_NOTHROW_CONVERTIBLE:
13957 : 667 : return is_nothrow_convertible (type1, type2);
13958 : :
13959 : 23235 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
13960 : 23235 : return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
13961 : :
13962 : 40260 : case CPTK_IS_NOTHROW_INVOCABLE:
13963 : 40260 : return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
13964 : :
13965 : 1265429 : case CPTK_IS_OBJECT:
13966 : 1265429 : return object_type_p (type1);
13967 : :
13968 : 142 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
13969 : 142 : return pointer_interconvertible_base_of_p (type1, type2);
13970 : :
13971 : 11048 : case CPTK_IS_POD:
13972 : 11048 : return pod_type_p (type1);
13973 : :
13974 : 151675 : case CPTK_IS_POINTER:
13975 : 151675 : return TYPE_PTR_P (type1);
13976 : :
13977 : 277 : case CPTK_IS_POLYMORPHIC:
13978 : 277 : return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
13979 : :
13980 : 827521 : case CPTK_IS_REFERENCE:
13981 : 827521 : return type_code1 == REFERENCE_TYPE;
13982 : :
13983 : 4228223 : case CPTK_IS_SAME:
13984 : 4228223 : return same_type_p (type1, type2);
13985 : :
13986 : 373 : case CPTK_IS_SCOPED_ENUM:
13987 : 373 : return SCOPED_ENUM_P (type1);
13988 : :
13989 : 58524 : case CPTK_IS_STD_LAYOUT:
13990 : 58524 : return std_layout_type_p (type1);
13991 : :
13992 : 55163 : case CPTK_IS_TRIVIAL:
13993 : 55163 : return trivial_type_p (type1);
13994 : :
13995 : 9852 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
13996 : 9852 : return is_trivially_xible (MODIFY_EXPR, type1, type2);
13997 : :
13998 : 67533 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
13999 : 67533 : return is_trivially_xible (INIT_EXPR, type1, type2);
14000 : :
14001 : 109401 : case CPTK_IS_TRIVIALLY_COPYABLE:
14002 : 109401 : return trivially_copyable_p (type1);
14003 : :
14004 : 24330 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14005 : 24330 : return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
14006 : :
14007 : 91734 : case CPTK_IS_UNBOUNDED_ARRAY:
14008 : 91734 : return array_of_unknown_bound_p (type1);
14009 : :
14010 : 267858 : case CPTK_IS_UNION:
14011 : 267858 : return type_code1 == UNION_TYPE;
14012 : :
14013 : 712 : case CPTK_IS_VIRTUAL_BASE_OF:
14014 : 646 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14015 : 1342 : && lookup_base (type2, type1, ba_require_virtual,
14016 : : NULL, tf_none) != NULL_TREE);
14017 : :
14018 : 730400 : case CPTK_IS_VOLATILE:
14019 : 730400 : return CP_TYPE_VOLATILE_P (type1);
14020 : :
14021 : 226431 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14022 : 226431 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
14023 : :
14024 : 51599 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14025 : 51599 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
14026 : :
14027 : 79 : case CPTK_IS_DEDUCIBLE:
14028 : 79 : return type_targs_deducible_from (type1, type2);
14029 : :
14030 : 28 : case CPTK_IS_CONSTEVAL_ONLY:
14031 : 28 : return consteval_only_p (type1);
14032 : :
14033 : : /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
14034 : : are handled in finish_trait_expr. */
14035 : 0 : case CPTK_RANK:
14036 : 0 : case CPTK_TYPE_ORDER:
14037 : 0 : case CPTK_STRUCTURED_BINDING_SIZE:
14038 : 0 : gcc_unreachable ();
14039 : :
14040 : : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14041 : : case CPTK_##CODE:
14042 : : #include "cp-trait.def"
14043 : : #undef DEFTRAIT_TYPE
14044 : : /* Type-yielding traits are handled in finish_trait_type. */
14045 : : break;
14046 : : }
14047 : :
14048 : 0 : gcc_unreachable ();
14049 : : }
14050 : :
14051 : : /* Returns true if TYPE meets the requirements for the specified KIND,
14052 : : false otherwise.
14053 : :
14054 : : When KIND == 1, TYPE must be an array of unknown bound,
14055 : : or (possibly cv-qualified) void, or a complete type.
14056 : :
14057 : : When KIND == 2, TYPE must be a complete type, or array of complete type,
14058 : : or (possibly cv-qualified) void.
14059 : :
14060 : : When KIND == 3:
14061 : : If TYPE is a non-union class type, it must be complete.
14062 : :
14063 : : When KIND == 4:
14064 : : If TYPE is a class type, it must be complete. */
14065 : :
14066 : : static bool
14067 : 22003354 : check_trait_type (tree type, int kind = 1)
14068 : : {
14069 : 22003354 : if (type == NULL_TREE)
14070 : : return true;
14071 : :
14072 : 22003354 : if (TREE_CODE (type) == TREE_VEC)
14073 : : {
14074 : 7270893 : for (tree arg : tree_vec_range (type))
14075 : 3094145 : if (!check_trait_type (arg, kind))
14076 : 21 : return false;
14077 : 4176748 : return true;
14078 : : }
14079 : :
14080 : 17826585 : if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
14081 : : return true; // Array of unknown bound. Don't care about completeness.
14082 : :
14083 : 17826041 : if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
14084 : : return true; // Not a non-union class type. Don't care about completeness.
14085 : :
14086 : 17715381 : if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
14087 : : return true; // Not a class type. Don't care about completeness.
14088 : :
14089 : 17714888 : if (VOID_TYPE_P (type))
14090 : : return true;
14091 : :
14092 : 17713788 : type = complete_type (strip_array_types (type));
14093 : 17713788 : if (!COMPLETE_TYPE_P (type)
14094 : 152 : && cxx_incomplete_type_diagnostic (NULL_TREE, type,
14095 : : diagnostics::kind::permerror)
14096 : 17713940 : && !flag_permissive)
14097 : : return false;
14098 : : return true;
14099 : : }
14100 : :
14101 : : /* True iff the conversion (if any) would be a direct reference
14102 : : binding, not requiring complete types. This is LWG2939. */
14103 : :
14104 : : static bool
14105 : 8176295 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
14106 : : {
14107 : 8176295 : tree from, to;
14108 : 8176295 : switch (kind)
14109 : : {
14110 : : /* These put the target type first. */
14111 : : case CPTK_IS_CONSTRUCTIBLE:
14112 : : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14113 : : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14114 : : case CPTK_IS_INVOCABLE:
14115 : : case CPTK_IS_NOTHROW_INVOCABLE:
14116 : : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14117 : : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14118 : : to = type1;
14119 : : from = type2;
14120 : : break;
14121 : :
14122 : : /* These put it second. */
14123 : 3718247 : case CPTK_IS_CONVERTIBLE:
14124 : 3718247 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14125 : 3718247 : to = type2;
14126 : 3718247 : from = type1;
14127 : 3718247 : break;
14128 : :
14129 : 0 : default:
14130 : 0 : gcc_unreachable ();
14131 : : }
14132 : :
14133 : 8176295 : if (TREE_CODE (to) != REFERENCE_TYPE || !from)
14134 : : return false;
14135 : 997198 : if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
14136 : 57944 : from = TREE_VEC_ELT (from, 0);
14137 : 997198 : return (TYPE_P (from)
14138 : 1986662 : && (same_type_ignoring_top_level_qualifiers_p
14139 : 989464 : (non_reference (to), non_reference (from))));
14140 : : }
14141 : :
14142 : : /* Helper for finish_trait_expr and tsubst_expr. Handle
14143 : : CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
14144 : : way. */
14145 : :
14146 : : tree
14147 : 261 : finish_structured_binding_size (location_t loc, tree type,
14148 : : tsubst_flags_t complain)
14149 : : {
14150 : 261 : if (TYPE_REF_P (type))
14151 : : {
14152 : 105 : if (complain & tf_error)
14153 : 99 : error_at (loc, "%qs argument %qT is a reference",
14154 : : "__builtin_structured_binding_size", type);
14155 : 105 : return error_mark_node;
14156 : : }
14157 : 156 : HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
14158 : 156 : if (ret == -1)
14159 : 57 : return error_mark_node;
14160 : 99 : return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
14161 : : }
14162 : :
14163 : : /* Process a trait expression. */
14164 : :
14165 : : tree
14166 : 25111991 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
14167 : : {
14168 : 25111991 : if (type1 == error_mark_node
14169 : 25111988 : || type2 == error_mark_node)
14170 : : return error_mark_node;
14171 : :
14172 : 25111988 : if (processing_template_decl)
14173 : : {
14174 : 3192611 : tree trait_expr = make_node (TRAIT_EXPR);
14175 : 3192611 : if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
14176 : 29573 : TREE_TYPE (trait_expr) = size_type_node;
14177 : 3163038 : else if (kind == CPTK_TYPE_ORDER)
14178 : : {
14179 : 2710 : tree val = type_order_value (type1, type1);
14180 : 2710 : if (val != error_mark_node)
14181 : 2710 : TREE_TYPE (trait_expr) = TREE_TYPE (val);
14182 : : }
14183 : : else
14184 : 3160328 : TREE_TYPE (trait_expr) = boolean_type_node;
14185 : 3192611 : TRAIT_EXPR_TYPE1 (trait_expr) = type1;
14186 : 3192611 : TRAIT_EXPR_TYPE2 (trait_expr) = type2;
14187 : 3192611 : TRAIT_EXPR_KIND (trait_expr) = kind;
14188 : 3192611 : TRAIT_EXPR_LOCATION (trait_expr) = loc;
14189 : 3192611 : return trait_expr;
14190 : : }
14191 : :
14192 : 21919377 : switch (kind)
14193 : : {
14194 : 51605 : case CPTK_HAS_NOTHROW_ASSIGN:
14195 : 51605 : case CPTK_HAS_TRIVIAL_ASSIGN:
14196 : 51605 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
14197 : 51605 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
14198 : 51605 : case CPTK_HAS_NOTHROW_COPY:
14199 : 51605 : case CPTK_HAS_TRIVIAL_COPY:
14200 : 51605 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
14201 : 51605 : case CPTK_IS_DESTRUCTIBLE:
14202 : 51605 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
14203 : 51605 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
14204 : 51605 : if (!check_trait_type (type1))
14205 : 21 : return error_mark_node;
14206 : : break;
14207 : :
14208 : 291756 : case CPTK_IS_LITERAL_TYPE:
14209 : 291756 : case CPTK_IS_POD:
14210 : 291756 : case CPTK_IS_STD_LAYOUT:
14211 : 291756 : case CPTK_IS_TRIVIAL:
14212 : 291756 : case CPTK_IS_TRIVIALLY_COPYABLE:
14213 : 291756 : case CPTK_IS_CONSTEVAL_ONLY:
14214 : 291756 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
14215 : 291756 : if (!check_trait_type (type1, /* kind = */ 2))
14216 : 33 : return error_mark_node;
14217 : : break;
14218 : :
14219 : 300662 : case CPTK_IS_ABSTRACT:
14220 : 300662 : case CPTK_IS_EMPTY:
14221 : 300662 : case CPTK_IS_POLYMORPHIC:
14222 : 300662 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
14223 : 300662 : if (!check_trait_type (type1, /* kind = */ 3))
14224 : 15 : return error_mark_node;
14225 : : break;
14226 : :
14227 : : /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
14228 : : type to know whether an array is an aggregate, so use kind=4 here. */
14229 : 449899 : case CPTK_IS_AGGREGATE:
14230 : 449899 : case CPTK_IS_FINAL:
14231 : 449899 : case CPTK_IS_IMPLICIT_LIFETIME:
14232 : 449899 : if (!check_trait_type (type1, /* kind = */ 4))
14233 : 17 : return error_mark_node;
14234 : : break;
14235 : :
14236 : 8176295 : case CPTK_IS_CONSTRUCTIBLE:
14237 : 8176295 : case CPTK_IS_CONVERTIBLE:
14238 : 8176295 : case CPTK_IS_INVOCABLE:
14239 : 8176295 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
14240 : 8176295 : case CPTK_IS_NOTHROW_CONVERTIBLE:
14241 : 8176295 : case CPTK_IS_NOTHROW_INVOCABLE:
14242 : 8176295 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
14243 : 8176295 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
14244 : 8176295 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
14245 : 8176295 : /* Don't check completeness for direct reference binding. */;
14246 : 8176295 : if (same_type_ref_bind_p (kind, type1, type2))
14247 : : break;
14248 : 8907663 : gcc_fallthrough ();
14249 : :
14250 : 8907663 : case CPTK_IS_ASSIGNABLE:
14251 : 8907663 : case CPTK_IS_NOTHROW_ASSIGNABLE:
14252 : 8907663 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
14253 : 8907663 : if (!check_trait_type (type1)
14254 : 8907663 : || !check_trait_type (type2))
14255 : 63 : return error_mark_node;
14256 : : break;
14257 : :
14258 : 584303 : case CPTK_IS_BASE_OF:
14259 : 584303 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
14260 : 584200 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14261 : 565737 : && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
14262 : 1116012 : && !complete_type_or_else (type2, NULL_TREE))
14263 : : /* We already issued an error. */
14264 : 3 : return error_mark_node;
14265 : : break;
14266 : :
14267 : 715 : case CPTK_IS_VIRTUAL_BASE_OF:
14268 : 649 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
14269 : 1348 : && !complete_type_or_else (type2, NULL_TREE))
14270 : : /* We already issued an error. */
14271 : 3 : return error_mark_node;
14272 : : break;
14273 : :
14274 : : case CPTK_IS_ARRAY:
14275 : : case CPTK_IS_BOUNDED_ARRAY:
14276 : : case CPTK_IS_CLASS:
14277 : : case CPTK_IS_CONST:
14278 : : case CPTK_IS_ENUM:
14279 : : case CPTK_IS_FUNCTION:
14280 : : case CPTK_IS_MEMBER_FUNCTION_POINTER:
14281 : : case CPTK_IS_MEMBER_OBJECT_POINTER:
14282 : : case CPTK_IS_MEMBER_POINTER:
14283 : : case CPTK_IS_OBJECT:
14284 : : case CPTK_IS_POINTER:
14285 : : case CPTK_IS_REFERENCE:
14286 : : case CPTK_IS_SAME:
14287 : : case CPTK_IS_SCOPED_ENUM:
14288 : : case CPTK_IS_UNBOUNDED_ARRAY:
14289 : : case CPTK_IS_UNION:
14290 : : case CPTK_IS_VOLATILE:
14291 : : break;
14292 : :
14293 : : case CPTK_RANK:
14294 : : {
14295 : : size_t rank = 0;
14296 : 122 : for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
14297 : 80 : ++rank;
14298 : 42 : return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
14299 : : loc);
14300 : : }
14301 : :
14302 : 122 : case CPTK_TYPE_ORDER:
14303 : 122 : return maybe_wrap_with_location (type_order_value (type1, type2), loc);
14304 : :
14305 : 138 : case CPTK_STRUCTURED_BINDING_SIZE:
14306 : 138 : return finish_structured_binding_size (loc, type1, tf_warning_or_error);
14307 : :
14308 : 204 : case CPTK_IS_LAYOUT_COMPATIBLE:
14309 : 204 : if (!array_of_unknown_bound_p (type1)
14310 : 189 : && TREE_CODE (type1) != VOID_TYPE
14311 : 387 : && !complete_type_or_else (type1, NULL_TREE))
14312 : : /* We already issued an error. */
14313 : 6 : return error_mark_node;
14314 : 198 : if (!array_of_unknown_bound_p (type2)
14315 : 177 : && TREE_CODE (type2) != VOID_TYPE
14316 : 369 : && !complete_type_or_else (type2, NULL_TREE))
14317 : : /* We already issued an error. */
14318 : 3 : return error_mark_node;
14319 : : break;
14320 : :
14321 : 79 : case CPTK_IS_DEDUCIBLE:
14322 : 79 : if (!DECL_TYPE_TEMPLATE_P (type1))
14323 : : {
14324 : 0 : error ("%qD is not a class or alias template", type1);
14325 : 0 : return error_mark_node;
14326 : : }
14327 : : break;
14328 : :
14329 : : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14330 : : case CPTK_##CODE:
14331 : : #include "cp-trait.def"
14332 : : #undef DEFTRAIT_TYPE
14333 : : /* Type-yielding traits are handled in finish_trait_type. */
14334 : 0 : gcc_unreachable ();
14335 : : }
14336 : :
14337 : 21918911 : tree val = (trait_expr_value (kind, type1, type2)
14338 : 21918911 : ? boolean_true_node : boolean_false_node);
14339 : 21918911 : return maybe_wrap_with_location (val, loc);
14340 : : }
14341 : :
14342 : : /* Process a trait type. */
14343 : :
14344 : : tree
14345 : 9239257 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
14346 : : tsubst_flags_t complain)
14347 : : {
14348 : 9239257 : if (type1 == error_mark_node
14349 : 9239254 : || type2 == error_mark_node)
14350 : : return error_mark_node;
14351 : :
14352 : 9239254 : if (processing_template_decl)
14353 : : {
14354 : 216788 : tree type = cxx_make_type (TRAIT_TYPE);
14355 : 216788 : TRAIT_TYPE_TYPE1 (type) = type1;
14356 : 216788 : TRAIT_TYPE_TYPE2 (type) = type2;
14357 : 216788 : TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
14358 : : /* These traits are intended to be used in the definition of the ::type
14359 : : member of the corresponding standard library type trait and aren't
14360 : : mangleable (and thus won't appear directly in template signatures),
14361 : : so structural equality should suffice. */
14362 : 216788 : SET_TYPE_STRUCTURAL_EQUALITY (type);
14363 : 216788 : return type;
14364 : : }
14365 : :
14366 : 9022466 : switch (kind)
14367 : : {
14368 : 1411497 : case CPTK_ADD_LVALUE_REFERENCE:
14369 : : /* [meta.trans.ref]. */
14370 : 1411497 : if (referenceable_type_p (type1))
14371 : 1411422 : return cp_build_reference_type (type1, /*rval=*/false);
14372 : : return type1;
14373 : :
14374 : 733118 : case CPTK_ADD_POINTER:
14375 : : /* [meta.trans.ptr]. */
14376 : 733118 : if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
14377 : : {
14378 : 733086 : if (TYPE_REF_P (type1))
14379 : 732040 : type1 = TREE_TYPE (type1);
14380 : 733086 : return build_pointer_type (type1);
14381 : : }
14382 : : return type1;
14383 : :
14384 : 1913023 : case CPTK_ADD_RVALUE_REFERENCE:
14385 : : /* [meta.trans.ref]. */
14386 : 1913023 : if (referenceable_type_p (type1))
14387 : 1912970 : return cp_build_reference_type (type1, /*rval=*/true);
14388 : : return type1;
14389 : :
14390 : 270634 : case CPTK_DECAY:
14391 : 270634 : if (TYPE_REF_P (type1))
14392 : 40764 : type1 = TREE_TYPE (type1);
14393 : :
14394 : 270634 : if (TREE_CODE (type1) == ARRAY_TYPE)
14395 : 665 : return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
14396 : 665 : complain);
14397 : 269969 : else if (TREE_CODE (type1) == FUNCTION_TYPE)
14398 : 175 : return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
14399 : : else
14400 : 269794 : return cv_unqualified (type1);
14401 : :
14402 : 219 : case CPTK_REMOVE_ALL_EXTENTS:
14403 : 219 : return strip_array_types (type1);
14404 : :
14405 : 1116847 : case CPTK_REMOVE_CV:
14406 : 1116847 : return cv_unqualified (type1);
14407 : :
14408 : 659629 : case CPTK_REMOVE_CVREF:
14409 : 659629 : if (TYPE_REF_P (type1))
14410 : 331637 : type1 = TREE_TYPE (type1);
14411 : 659629 : return cv_unqualified (type1);
14412 : :
14413 : 64037 : case CPTK_REMOVE_EXTENT:
14414 : 64037 : if (TREE_CODE (type1) == ARRAY_TYPE)
14415 : 9107 : type1 = TREE_TYPE (type1);
14416 : : return type1;
14417 : :
14418 : 49839 : case CPTK_REMOVE_POINTER:
14419 : 49839 : if (TYPE_PTR_P (type1))
14420 : 47146 : type1 = TREE_TYPE (type1);
14421 : : return type1;
14422 : :
14423 : 2651408 : case CPTK_REMOVE_REFERENCE:
14424 : 2651408 : if (TYPE_REF_P (type1))
14425 : 1636113 : type1 = TREE_TYPE (type1);
14426 : : return type1;
14427 : :
14428 : 105886 : case CPTK_TYPE_PACK_ELEMENT:
14429 : 105886 : return finish_type_pack_element (type1, type2, complain);
14430 : :
14431 : 46329 : case CPTK_UNDERLYING_TYPE:
14432 : 46329 : return finish_underlying_type (type1);
14433 : :
14434 : : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
14435 : : case CPTK_##CODE:
14436 : : #include "cp-trait.def"
14437 : : #undef DEFTRAIT_EXPR
14438 : : /* Expression-yielding traits are handled in finish_trait_expr. */
14439 : : case CPTK_BASES:
14440 : : case CPTK_DIRECT_BASES:
14441 : : /* BASES and DIRECT_BASES are handled in finish_bases. */
14442 : : break;
14443 : : }
14444 : :
14445 : 0 : gcc_unreachable ();
14446 : : }
14447 : :
14448 : : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
14449 : : which is ignored for C++. */
14450 : :
14451 : : void
14452 : 0 : set_float_const_decimal64 (void)
14453 : : {
14454 : 0 : }
14455 : :
14456 : : void
14457 : 0 : clear_float_const_decimal64 (void)
14458 : : {
14459 : 0 : }
14460 : :
14461 : : bool
14462 : 1876437 : float_const_decimal64_p (void)
14463 : : {
14464 : 1876437 : return 0;
14465 : : }
14466 : :
14467 : :
14468 : : /* Return true if T designates the implied `this' parameter. */
14469 : :
14470 : : bool
14471 : 6301914 : is_this_parameter (tree t)
14472 : : {
14473 : 6301914 : if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
14474 : : return false;
14475 : 3609924 : gcc_assert (TREE_CODE (t) == PARM_DECL
14476 : : || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
14477 : : || (cp_binding_oracle && VAR_P (t)));
14478 : : return true;
14479 : : }
14480 : :
14481 : : /* As above, or a C++23 explicit object parameter. */
14482 : :
14483 : : bool
14484 : 456 : is_object_parameter (tree t)
14485 : : {
14486 : 456 : if (is_this_parameter (t))
14487 : : return true;
14488 : 91 : if (TREE_CODE (t) != PARM_DECL)
14489 : : return false;
14490 : 34 : tree ctx = DECL_CONTEXT (t);
14491 : 34 : return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
14492 : 62 : && t == DECL_ARGUMENTS (ctx));
14493 : : }
14494 : :
14495 : : /* Insert the deduced return type for an auto function. */
14496 : :
14497 : : void
14498 : 2236219 : apply_deduced_return_type (tree fco, tree return_type)
14499 : : {
14500 : 2236219 : tree result;
14501 : :
14502 : 2236219 : if (return_type == error_mark_node)
14503 : : return;
14504 : :
14505 : 2236216 : if (DECL_CONV_FN_P (fco))
14506 : 42 : DECL_NAME (fco) = make_conv_op_name (return_type);
14507 : :
14508 : 2236216 : TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
14509 : :
14510 : 2236216 : maybe_update_postconditions (fco);
14511 : :
14512 : : /* Apply the type to the result object. */
14513 : :
14514 : 2236216 : result = DECL_RESULT (fco);
14515 : 2236216 : if (result == NULL_TREE)
14516 : : return;
14517 : 2226781 : if (TREE_TYPE (result) == return_type)
14518 : : return;
14519 : :
14520 : 2226775 : if (!processing_template_decl && !VOID_TYPE_P (return_type)
14521 : 3728474 : && !complete_type_or_else (return_type, NULL_TREE))
14522 : : return;
14523 : :
14524 : : /* We already have a DECL_RESULT from start_preparsed_function.
14525 : : Now we need to redo the work it and allocate_struct_function
14526 : : did to reflect the new type. */
14527 : 2226778 : result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
14528 : 2226778 : TYPE_MAIN_VARIANT (return_type));
14529 : 2226778 : DECL_ARTIFICIAL (result) = 1;
14530 : 2226778 : DECL_IGNORED_P (result) = 1;
14531 : 2226778 : cp_apply_type_quals_to_decl (cp_type_quals (return_type),
14532 : : result);
14533 : 2226778 : DECL_RESULT (fco) = result;
14534 : :
14535 : 2226778 : if (!uses_template_parms (fco))
14536 : 2226778 : if (function *fun = DECL_STRUCT_FUNCTION (fco))
14537 : : {
14538 : 2226336 : bool aggr = aggregate_value_p (result, fco);
14539 : : #ifdef PCC_STATIC_STRUCT_RETURN
14540 : : fun->returns_pcc_struct = aggr;
14541 : : #endif
14542 : 2226336 : fun->returns_struct = aggr;
14543 : : }
14544 : : }
14545 : :
14546 : : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
14547 : : this is a right unary fold. Otherwise it is a left unary fold. */
14548 : :
14549 : : static tree
14550 : 736653 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
14551 : : {
14552 : : /* Build a pack expansion (assuming expr has pack type). */
14553 : 736653 : if (!uses_parameter_packs (expr))
14554 : : {
14555 : 3 : error_at (location_of (expr), "operand of fold expression has no "
14556 : : "unexpanded parameter packs");
14557 : 3 : return error_mark_node;
14558 : : }
14559 : 736650 : tree pack = make_pack_expansion (expr);
14560 : :
14561 : : /* Build the fold expression. */
14562 : 736650 : tree code = build_int_cstu (integer_type_node, abs (op));
14563 : 736650 : tree fold = build_min_nt_loc (loc, dir, code, pack);
14564 : 736650 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14565 : 736650 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14566 : 736650 : FOLD_EXPR_OP (fold),
14567 : 736650 : FOLD_EXPR_MODIFY_P (fold));
14568 : 736650 : return fold;
14569 : : }
14570 : :
14571 : : tree
14572 : 18003 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
14573 : : {
14574 : 18003 : return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
14575 : : }
14576 : :
14577 : : tree
14578 : 718650 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
14579 : : {
14580 : 718650 : return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
14581 : : }
14582 : :
14583 : : /* Build a binary fold expression over EXPR1 and EXPR2. The
14584 : : associativity of the fold is determined by EXPR1 and EXPR2 (whichever
14585 : : has an unexpanded parameter pack). */
14586 : :
14587 : : static tree
14588 : 9441 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
14589 : : int op, tree_code dir)
14590 : : {
14591 : 9441 : pack = make_pack_expansion (pack);
14592 : 9441 : tree code = build_int_cstu (integer_type_node, abs (op));
14593 : 9441 : tree fold = build_min_nt_loc (loc, dir, code, pack, init);
14594 : 9441 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14595 : 9441 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14596 : 9441 : FOLD_EXPR_OP (fold),
14597 : 9441 : FOLD_EXPR_MODIFY_P (fold));
14598 : 9441 : return fold;
14599 : : }
14600 : :
14601 : : tree
14602 : 9441 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
14603 : : {
14604 : : // Determine which expr has an unexpanded parameter pack and
14605 : : // set the pack and initial term.
14606 : 9441 : bool pack1 = uses_parameter_packs (expr1);
14607 : 9441 : bool pack2 = uses_parameter_packs (expr2);
14608 : 9441 : if (pack1 && !pack2)
14609 : 741 : return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
14610 : 8700 : else if (pack2 && !pack1)
14611 : 8700 : return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
14612 : : else
14613 : : {
14614 : 0 : if (pack1)
14615 : 0 : error ("both arguments in binary fold have unexpanded parameter packs");
14616 : : else
14617 : 0 : error ("no unexpanded parameter packs in binary fold");
14618 : : }
14619 : 0 : return error_mark_node;
14620 : : }
14621 : :
14622 : : /* Finish __builtin_launder (arg). */
14623 : :
14624 : : tree
14625 : 13029 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
14626 : : {
14627 : 13029 : tree orig_arg = arg;
14628 : 13029 : if (!type_dependent_expression_p (arg))
14629 : 84 : arg = decay_conversion (arg, complain);
14630 : 13029 : if (error_operand_p (arg))
14631 : 0 : return error_mark_node;
14632 : 13029 : if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
14633 : : {
14634 : 24 : error_at (loc, "type %qT of argument to %<__builtin_launder%> "
14635 : 24 : "is not a pointer to object type", TREE_TYPE (arg));
14636 : 24 : return error_mark_node;
14637 : : }
14638 : 13005 : if (processing_template_decl)
14639 : 12945 : arg = orig_arg;
14640 : 13005 : return build_call_expr_internal_loc (loc, IFN_LAUNDER,
14641 : 26010 : TREE_TYPE (arg), 1, arg);
14642 : : }
14643 : :
14644 : : /* Finish __builtin_convertvector (arg, type). */
14645 : :
14646 : : tree
14647 : 188 : cp_build_vec_convert (tree arg, location_t loc, tree type,
14648 : : tsubst_flags_t complain)
14649 : : {
14650 : 188 : if (error_operand_p (type))
14651 : 9 : return error_mark_node;
14652 : 179 : if (error_operand_p (arg))
14653 : 0 : return error_mark_node;
14654 : :
14655 : 179 : tree ret = NULL_TREE;
14656 : 179 : if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
14657 : 197 : ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
14658 : : decay_conversion (arg, complain),
14659 : : loc, type, (complain & tf_error) != 0);
14660 : :
14661 : 179 : if (!processing_template_decl)
14662 : : return ret;
14663 : :
14664 : 24 : return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
14665 : : }
14666 : :
14667 : : /* Finish __builtin_bit_cast (type, arg). */
14668 : :
14669 : : tree
14670 : 274020 : cp_build_bit_cast (location_t loc, tree type, tree arg,
14671 : : tsubst_flags_t complain)
14672 : : {
14673 : 274020 : if (error_operand_p (type))
14674 : 0 : return error_mark_node;
14675 : 274020 : if (!dependent_type_p (type))
14676 : : {
14677 : 199414 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
14678 : 9 : return error_mark_node;
14679 : 199405 : if (TREE_CODE (type) == ARRAY_TYPE)
14680 : : {
14681 : : /* std::bit_cast for destination ARRAY_TYPE is not possible,
14682 : : as functions may not return an array, so don't bother trying
14683 : : to support this (and then deal with VLAs etc.). */
14684 : 9 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14685 : : "is an array type", type);
14686 : 9 : return error_mark_node;
14687 : : }
14688 : 199396 : if (!trivially_copyable_p (type))
14689 : : {
14690 : 18 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14691 : : "is not trivially copyable", type);
14692 : 18 : return error_mark_node;
14693 : : }
14694 : : }
14695 : :
14696 : 273984 : if (error_operand_p (arg))
14697 : 0 : return error_mark_node;
14698 : :
14699 : 273984 : if (!type_dependent_expression_p (arg))
14700 : : {
14701 : 109242 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
14702 : : {
14703 : : /* Don't perform array-to-pointer conversion. */
14704 : 25 : arg = mark_rvalue_use (arg, loc, true);
14705 : 25 : if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
14706 : 0 : return error_mark_node;
14707 : : }
14708 : : else
14709 : 109217 : arg = decay_conversion (arg, complain);
14710 : :
14711 : 109242 : if (error_operand_p (arg))
14712 : 12 : return error_mark_node;
14713 : :
14714 : 109230 : if (!trivially_copyable_p (TREE_TYPE (arg)))
14715 : : {
14716 : 9 : error_at (cp_expr_loc_or_loc (arg, loc),
14717 : : "%<__builtin_bit_cast%> source type %qT "
14718 : 9 : "is not trivially copyable", TREE_TYPE (arg));
14719 : 9 : return error_mark_node;
14720 : : }
14721 : 109221 : if (!dependent_type_p (type)
14722 : 181822 : && !cp_tree_equal (TYPE_SIZE_UNIT (type),
14723 : 72601 : TYPE_SIZE_UNIT (TREE_TYPE (arg))))
14724 : : {
14725 : 18 : error_at (loc, "%<__builtin_bit_cast%> source size %qE "
14726 : : "not equal to destination type size %qE",
14727 : 18 : TYPE_SIZE_UNIT (TREE_TYPE (arg)),
14728 : 18 : TYPE_SIZE_UNIT (type));
14729 : 18 : return error_mark_node;
14730 : : }
14731 : : }
14732 : :
14733 : 273945 : tree ret = build_min (BIT_CAST_EXPR, type, arg);
14734 : 273945 : SET_EXPR_LOCATION (ret, loc);
14735 : :
14736 : 273945 : if (!processing_template_decl && CLASS_TYPE_P (type))
14737 : 226 : ret = get_target_expr (ret, complain);
14738 : :
14739 : : return ret;
14740 : : }
14741 : :
14742 : : /* Diagnose invalid #pragma GCC unroll argument and adjust
14743 : : it if needed. */
14744 : :
14745 : : tree
14746 : 22992 : cp_check_pragma_unroll (location_t loc, tree unroll)
14747 : : {
14748 : 22992 : HOST_WIDE_INT lunroll = 0;
14749 : 22992 : if (type_dependent_expression_p (unroll))
14750 : : ;
14751 : 45912 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
14752 : 45866 : || (!value_dependent_expression_p (unroll)
14753 : 22880 : && (!tree_fits_shwi_p (unroll)
14754 : 22854 : || (lunroll = tree_to_shwi (unroll)) < 0
14755 : 22839 : || lunroll >= USHRT_MAX)))
14756 : : {
14757 : 90 : error_at (loc, "%<#pragma GCC unroll%> requires an"
14758 : : " assignment-expression that evaluates to a non-negative"
14759 : : " integral constant less than %u", USHRT_MAX);
14760 : 90 : unroll = integer_one_node;
14761 : : }
14762 : 22866 : else if (TREE_CODE (unroll) == INTEGER_CST)
14763 : : {
14764 : 22836 : unroll = fold_convert (integer_type_node, unroll);
14765 : 22836 : if (integer_zerop (unroll))
14766 : 12 : unroll = integer_one_node;
14767 : : }
14768 : 22992 : return unroll;
14769 : : }
14770 : :
14771 : : #include "gt-cp-semantics.h"
|