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-2025 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 : :
51 : : /* There routines provide a modular interface to perform many parsing
52 : : operations. They may therefore be used during actual parsing, or
53 : : during template instantiation, which may be regarded as a
54 : : degenerate form of parsing. */
55 : :
56 : : static tree finalize_nrv_r (tree *, int *, void *);
57 : :
58 : : /* Used for OpenMP non-static data member privatization. */
59 : :
60 : : static hash_map<tree, tree> *omp_private_member_map;
61 : : static vec<tree> omp_private_member_vec;
62 : : static bool omp_private_member_ignore_next;
63 : :
64 : :
65 : : /* Deferred Access Checking Overview
66 : : ---------------------------------
67 : :
68 : : Most C++ expressions and declarations require access checking
69 : : to be performed during parsing. However, in several cases,
70 : : this has to be treated differently.
71 : :
72 : : For member declarations, access checking has to be deferred
73 : : until more information about the declaration is known. For
74 : : example:
75 : :
76 : : class A {
77 : : typedef int X;
78 : : public:
79 : : X f();
80 : : };
81 : :
82 : : A::X A::f();
83 : : A::X g();
84 : :
85 : : When we are parsing the function return type `A::X', we don't
86 : : really know if this is allowed until we parse the function name.
87 : :
88 : : Furthermore, some contexts require that access checking is
89 : : never performed at all. These include class heads, and template
90 : : instantiations.
91 : :
92 : : Typical use of access checking functions is described here:
93 : :
94 : : 1. When we enter a context that requires certain access checking
95 : : mode, the function `push_deferring_access_checks' is called with
96 : : DEFERRING argument specifying the desired mode. Access checking
97 : : may be performed immediately (dk_no_deferred), deferred
98 : : (dk_deferred), or not performed (dk_no_check).
99 : :
100 : : 2. When a declaration such as a type, or a variable, is encountered,
101 : : the function `perform_or_defer_access_check' is called. It
102 : : maintains a vector of all deferred checks.
103 : :
104 : : 3. The global `current_class_type' or `current_function_decl' is then
105 : : setup by the parser. `enforce_access' relies on these information
106 : : to check access.
107 : :
108 : : 4. Upon exiting the context mentioned in step 1,
109 : : `perform_deferred_access_checks' is called to check all declaration
110 : : stored in the vector. `pop_deferring_access_checks' is then
111 : : called to restore the previous access checking mode.
112 : :
113 : : In case of parsing error, we simply call `pop_deferring_access_checks'
114 : : without `perform_deferred_access_checks'. */
115 : :
116 : : struct GTY(()) deferred_access {
117 : : /* A vector representing name-lookups for which we have deferred
118 : : checking access controls. We cannot check the accessibility of
119 : : names used in a decl-specifier-seq until we know what is being
120 : : declared because code like:
121 : :
122 : : class A {
123 : : class B {};
124 : : B* f();
125 : : }
126 : :
127 : : A::B* A::f() { return 0; }
128 : :
129 : : is valid, even though `A::B' is not generally accessible. */
130 : : vec<deferred_access_check, va_gc> *deferred_access_checks;
131 : :
132 : : /* The current mode of access checks. */
133 : : enum deferring_kind deferring_access_checks_kind;
134 : : };
135 : :
136 : : /* Data for deferred access checking. */
137 : : static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack;
138 : : static GTY(()) unsigned deferred_access_no_check;
139 : :
140 : : /* Save the current deferred access states and start deferred
141 : : access checking iff DEFER_P is true. */
142 : :
143 : : void
144 : 20252510538 : push_deferring_access_checks (deferring_kind deferring)
145 : : {
146 : : /* For context like template instantiation, access checking
147 : : disabling applies to all nested context. */
148 : 20252510538 : if (deferred_access_no_check || deferring == dk_no_check)
149 : 284191935 : deferred_access_no_check++;
150 : : else
151 : : {
152 : 19968318603 : deferred_access e = {NULL, deferring};
153 : 19968318603 : vec_safe_push (deferred_access_stack, e);
154 : : }
155 : 20252510538 : }
156 : :
157 : : /* Save the current deferred access states and start deferred access
158 : : checking, continuing the set of deferred checks in CHECKS. */
159 : :
160 : : void
161 : 326058558 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
162 : : {
163 : 326058558 : push_deferring_access_checks (dk_deferred);
164 : 326058558 : if (!deferred_access_no_check)
165 : 319228973 : deferred_access_stack->last().deferred_access_checks = checks;
166 : 326058558 : }
167 : :
168 : : /* Resume deferring access checks again after we stopped doing
169 : : this previously. */
170 : :
171 : : void
172 : 168402515 : resume_deferring_access_checks (void)
173 : : {
174 : 168402515 : if (!deferred_access_no_check)
175 : 168384316 : deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
176 : 168402515 : }
177 : :
178 : : /* Stop deferring access checks. */
179 : :
180 : : void
181 : 463827443 : stop_deferring_access_checks (void)
182 : : {
183 : 463827443 : if (!deferred_access_no_check)
184 : 463773290 : deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
185 : 463827443 : }
186 : :
187 : : /* Discard the current deferred access checks and restore the
188 : : previous states. */
189 : :
190 : : void
191 : 12315259698 : pop_deferring_access_checks (void)
192 : : {
193 : 12315259698 : if (deferred_access_no_check)
194 : 212104656 : deferred_access_no_check--;
195 : : else
196 : 12103155042 : deferred_access_stack->pop ();
197 : 12315259698 : }
198 : :
199 : : /* Returns a TREE_LIST representing the deferred checks.
200 : : The TREE_PURPOSE of each node is the type through which the
201 : : access occurred; the TREE_VALUE is the declaration named.
202 : : */
203 : :
204 : : vec<deferred_access_check, va_gc> *
205 : 1088227000 : get_deferred_access_checks (void)
206 : : {
207 : 1088227000 : if (deferred_access_no_check)
208 : : return NULL;
209 : : else
210 : 1074689688 : return (deferred_access_stack->last().deferred_access_checks);
211 : : }
212 : :
213 : : /* Take current deferred checks and combine with the
214 : : previous states if we also defer checks previously.
215 : : Otherwise perform checks now. */
216 : :
217 : : void
218 : 7937117375 : pop_to_parent_deferring_access_checks (void)
219 : : {
220 : 7937117375 : if (deferred_access_no_check)
221 : 72087273 : deferred_access_no_check--;
222 : : else
223 : : {
224 : 7865030102 : vec<deferred_access_check, va_gc> *checks;
225 : 7865030102 : deferred_access *ptr;
226 : :
227 : 7865030102 : checks = (deferred_access_stack->last ().deferred_access_checks);
228 : :
229 : 7865030102 : deferred_access_stack->pop ();
230 : 7865030102 : ptr = &deferred_access_stack->last ();
231 : 7865030102 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
232 : : {
233 : : /* Check access. */
234 : 499456500 : perform_access_checks (checks, tf_warning_or_error);
235 : : }
236 : : else
237 : : {
238 : : /* Merge with parent. */
239 : : int i, j;
240 : : deferred_access_check *chk, *probe;
241 : :
242 : 7537179890 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
243 : : {
244 : 93848604 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
245 : : {
246 : 8847402 : if (probe->binfo == chk->binfo &&
247 : 6992004 : probe->decl == chk->decl &&
248 : 802662 : probe->diag_decl == chk->diag_decl)
249 : 801942 : goto found;
250 : : }
251 : : /* Insert into parent's checks. */
252 : 85001202 : vec_safe_push (ptr->deferred_access_checks, *chk);
253 : 85803144 : found:;
254 : : }
255 : : }
256 : : }
257 : 7937117375 : }
258 : :
259 : : /* Called from enforce_access. A class has attempted (but failed) to access
260 : : DECL. It is already established that a baseclass of that class,
261 : : PARENT_BINFO, has private access to DECL. Examine certain special cases
262 : : to find a decl that accurately describes the source of the problem. If
263 : : none of the special cases apply, simply return DECL as the source of the
264 : : problem. */
265 : :
266 : : static tree
267 : 182 : get_class_access_diagnostic_decl (tree parent_binfo, tree decl)
268 : : {
269 : : /* When a class is denied access to a decl in a baseclass, most of the
270 : : time it is because the decl itself was declared as private at the point
271 : : of declaration.
272 : :
273 : : However, in C++, there are (at least) two situations in which a decl
274 : : can be private even though it was not originally defined as such.
275 : : These two situations only apply if a baseclass had private access to
276 : : DECL (this function is only called if that is the case). */
277 : :
278 : : /* We should first check whether the reason the parent had private access
279 : : to DECL was simply because DECL was created and declared as private in
280 : : the parent. If it was, then DECL is definitively the source of the
281 : : problem. */
282 : 182 : if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl),
283 : : BINFO_TYPE (parent_binfo)))
284 : : return decl;
285 : :
286 : : /* 1. If the "using" keyword is used to inherit DECL within the parent,
287 : : this may cause DECL to be private, so we should return the using
288 : : statement as the source of the problem.
289 : :
290 : : Scan the fields of PARENT_BINFO and see if there are any using decls. If
291 : : there are, see if they inherit DECL. If they do, that's where DECL must
292 : : have been declared private. */
293 : :
294 : 66 : for (tree parent_field = TYPE_FIELDS (BINFO_TYPE (parent_binfo));
295 : 326 : parent_field;
296 : 260 : parent_field = DECL_CHAIN (parent_field))
297 : : /* Not necessary, but also check TREE_PRIVATE for the sake of
298 : : eliminating obviously non-relevant using decls. */
299 : 278 : if (TREE_CODE (parent_field) == USING_DECL
300 : 81 : && TREE_PRIVATE (parent_field))
301 : : {
302 : 78 : tree decl_stripped = strip_using_decl (parent_field);
303 : :
304 : : /* The using statement might be overloaded. If so, we need to
305 : : check all of the overloads. */
306 : 180 : for (ovl_iterator iter (decl_stripped); iter; ++iter)
307 : : /* If equal, the using statement inherits DECL, and so is the
308 : : source of the access failure, so return it. */
309 : 99 : if (*iter == decl)
310 : 18 : return parent_field;
311 : : }
312 : :
313 : : /* 2. If DECL was privately inherited by the parent class, then DECL will
314 : : be inaccessible, even though it may originally have been accessible to
315 : : deriving classes. In that case, the fault lies with the parent, since it
316 : : used a private inheritance, so we return the parent as the source of the
317 : : problem.
318 : :
319 : : Since this is the last check, we just assume it's true. At worst, it
320 : : will simply point to the class that failed to give access, which is
321 : : technically true. */
322 : 48 : return TYPE_NAME (BINFO_TYPE (parent_binfo));
323 : : }
324 : :
325 : : /* If the current scope isn't allowed to access DECL along
326 : : BASETYPE_PATH, give an error, or if we're parsing a function or class
327 : : template, defer the access check to be performed at instantiation time.
328 : : The most derived class in BASETYPE_PATH is the one used to qualify DECL.
329 : : DIAG_DECL is the declaration to use in the error diagnostic. */
330 : :
331 : : static bool
332 : 330667987 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
333 : : tsubst_flags_t complain, access_failure_info *afi = NULL)
334 : : {
335 : 330667987 : gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
336 : :
337 : 330667987 : if (flag_new_inheriting_ctors
338 : 423656858 : && DECL_INHERITED_CTOR (decl))
339 : : {
340 : : /* 7.3.3/18: The additional constructors are accessible if they would be
341 : : accessible when used to construct an object of the corresponding base
342 : : class. */
343 : 52742 : decl = strip_inheriting_ctors (decl);
344 : 52742 : basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
345 : : ba_any, NULL, complain);
346 : : }
347 : :
348 : 330667987 : tree cs = current_scope ();
349 : 330667987 : if (in_template_context
350 : 330667987 : && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
351 : 38635647 : if (tree template_info = get_template_info (cs))
352 : : {
353 : : /* When parsing a function or class template, we in general need to
354 : : defer access checks until template instantiation time, since a friend
355 : : declaration may grant access only to a particular specialization of
356 : : the template. */
357 : :
358 : 38413469 : if (accessible_p (basetype_path, decl, /*consider_local_p=*/true))
359 : : /* But if the member is deemed accessible at parse time, then we can
360 : : assume it'll be accessible at instantiation time. */
361 : : return true;
362 : :
363 : : /* Access of a dependent decl should be rechecked after tsubst'ing
364 : : into the user of the decl, rather than explicitly deferring the
365 : : check here. */
366 : 135 : gcc_assert (!uses_template_parms (decl));
367 : 135 : if (TREE_CODE (decl) == FIELD_DECL)
368 : 6 : gcc_assert (!uses_template_parms (DECL_CONTEXT (decl)));
369 : :
370 : : /* Defer this access check until instantiation time. */
371 : 135 : deferred_access_check access_check;
372 : 135 : access_check.binfo = basetype_path;
373 : 135 : access_check.decl = decl;
374 : 135 : access_check.diag_decl = diag_decl;
375 : 135 : access_check.loc = input_location;
376 : 135 : vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info), access_check);
377 : 135 : return true;
378 : : }
379 : :
380 : 292254518 : if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
381 : : {
382 : 23149 : if (flag_new_inheriting_ctors)
383 : 23119 : diag_decl = strip_inheriting_ctors (diag_decl);
384 : 23149 : if (complain & tf_error)
385 : : {
386 : 1150 : access_kind access_failure_reason = ak_none;
387 : :
388 : : /* By default, using the decl as the source of the problem will
389 : : usually give correct results. */
390 : 1150 : tree diag_location = diag_decl;
391 : :
392 : : /* However, if a parent of BASETYPE_PATH had private access to decl,
393 : : then it actually might be the case that the source of the problem
394 : : is not DECL. */
395 : 1150 : tree parent_binfo = get_parent_with_private_access (decl,
396 : : basetype_path);
397 : :
398 : : /* So if a parent did have private access, then we need to do
399 : : special checks to obtain the best diagnostic location decl. */
400 : 1150 : if (parent_binfo != NULL_TREE)
401 : : {
402 : 182 : diag_location = get_class_access_diagnostic_decl (parent_binfo,
403 : : diag_decl);
404 : :
405 : : /* We also at this point know that the reason access failed was
406 : : because decl was private. */
407 : 182 : access_failure_reason = ak_private;
408 : : }
409 : :
410 : : /* Finally, generate an error message. */
411 : 1150 : complain_about_access (decl, diag_decl, diag_location, true,
412 : : access_failure_reason);
413 : : }
414 : 23149 : if (afi)
415 : 412 : afi->record_access_failure (basetype_path, decl, diag_decl);
416 : 23149 : return false;
417 : : }
418 : :
419 : : return true;
420 : : }
421 : :
422 : : /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
423 : : is the BINFO indicating the qualifying scope used to access the
424 : : DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
425 : : or we aren't in SFINAE context or all the checks succeed return TRUE,
426 : : otherwise FALSE. */
427 : :
428 : : bool
429 : 950148902 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
430 : : tsubst_flags_t complain)
431 : : {
432 : 950148902 : int i;
433 : 950148902 : deferred_access_check *chk;
434 : 950148902 : location_t loc = input_location;
435 : 950148902 : bool ok = true;
436 : :
437 : 950148902 : if (!checks)
438 : : return true;
439 : :
440 : 107152465 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
441 : : {
442 : 59747713 : input_location = chk->loc;
443 : 59747713 : ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
444 : : }
445 : :
446 : 47404752 : input_location = loc;
447 : 47404752 : return (complain & tf_error) ? true : ok;
448 : : }
449 : :
450 : : /* Perform the deferred access checks.
451 : :
452 : : After performing the checks, we still have to keep the list
453 : : `deferred_access_stack->deferred_access_checks' since we may want
454 : : to check access for them again later in a different context.
455 : : For example:
456 : :
457 : : class A {
458 : : typedef int X;
459 : : static X a;
460 : : };
461 : : A::X A::a, x; // No error for `A::a', error for `x'
462 : :
463 : : We have to perform deferred access of `A::X', first with `A::a',
464 : : next with `x'. Return value like perform_access_checks above. */
465 : :
466 : : bool
467 : 243609116 : perform_deferred_access_checks (tsubst_flags_t complain)
468 : : {
469 : 243609116 : return perform_access_checks (get_deferred_access_checks (), complain);
470 : : }
471 : :
472 : : /* Defer checking the accessibility of DECL, when looked up in
473 : : BINFO. DIAG_DECL is the declaration to use to print diagnostics.
474 : : Return value like perform_access_checks above.
475 : : If non-NULL, report failures to AFI. */
476 : :
477 : : bool
478 : 506138255 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
479 : : tsubst_flags_t complain,
480 : : access_failure_info *afi)
481 : : {
482 : 506138255 : int i;
483 : 506138255 : deferred_access *ptr;
484 : 506138255 : deferred_access_check *chk;
485 : :
486 : : /* Exit if we are in a context that no access checking is performed. */
487 : 506138255 : if (deferred_access_no_check)
488 : : return true;
489 : :
490 : 484798646 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
491 : :
492 : 484798646 : ptr = &deferred_access_stack->last ();
493 : :
494 : : /* If we are not supposed to defer access checks, just check now. */
495 : 484798646 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
496 : : {
497 : 270920274 : bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
498 : 426582372 : return (complain & tf_error) ? true : ok;
499 : : }
500 : :
501 : : /* See if we are already going to perform this check. */
502 : 252185086 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
503 : : {
504 : 50746626 : if (chk->decl == decl && chk->binfo == binfo &&
505 : 12440556 : chk->diag_decl == diag_decl)
506 : : {
507 : : return true;
508 : : }
509 : : }
510 : : /* If not, record the check. */
511 : 201438460 : deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
512 : 201438460 : vec_safe_push (ptr->deferred_access_checks, new_access);
513 : :
514 : 201438460 : return true;
515 : : }
516 : :
517 : : /* Returns nonzero if the current statement is a full expression,
518 : : i.e. temporaries created during that statement should be destroyed
519 : : at the end of the statement. */
520 : :
521 : : int
522 : 1186901368 : stmts_are_full_exprs_p (void)
523 : : {
524 : 1186901368 : return current_stmt_tree ()->stmts_are_full_exprs_p;
525 : : }
526 : :
527 : : /* T is a statement. Add it to the statement-tree. This is the C++
528 : : version. The C/ObjC frontends have a slightly different version of
529 : : this function. */
530 : :
531 : : tree
532 : 1095512972 : add_stmt (tree t)
533 : : {
534 : 1095512972 : enum tree_code code = TREE_CODE (t);
535 : :
536 : 1095512972 : if (EXPR_P (t) && code != LABEL_EXPR)
537 : : {
538 : 1051613872 : if (!EXPR_HAS_LOCATION (t))
539 : 170607956 : SET_EXPR_LOCATION (t, input_location);
540 : :
541 : : /* When we expand a statement-tree, we must know whether or not the
542 : : statements are full-expressions. We record that fact here. */
543 : 1051613872 : if (STATEMENT_CODE_P (TREE_CODE (t)))
544 : 269814706 : STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
545 : : }
546 : :
547 : 1095512972 : if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
548 : 4052077 : STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
549 : :
550 : : /* Add T to the statement-tree. Non-side-effect statements need to be
551 : : recorded during statement expressions. */
552 : 1095512972 : gcc_checking_assert (!stmt_list_stack->is_empty ());
553 : 1095512972 : append_to_statement_list_force (t, &cur_stmt_list);
554 : :
555 : 1095512972 : return t;
556 : : }
557 : :
558 : : /* Returns the stmt_tree to which statements are currently being added. */
559 : :
560 : : stmt_tree
561 : 6408816017 : current_stmt_tree (void)
562 : : {
563 : 6408816017 : return (cfun
564 : 6392401329 : ? &cfun->language->base.x_stmt_tree
565 : 6408816017 : : &scope_chain->x_stmt_tree);
566 : : }
567 : :
568 : : /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
569 : :
570 : : static tree
571 : 351501 : maybe_cleanup_point_expr (tree expr)
572 : : {
573 : 351501 : if (!processing_template_decl && stmts_are_full_exprs_p ())
574 : 343658 : expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
575 : 351501 : return expr;
576 : : }
577 : :
578 : : /* Like maybe_cleanup_point_expr except have the type of the new expression be
579 : : void so we don't need to create a temporary variable to hold the inner
580 : : expression. The reason why we do this is because the original type might be
581 : : an aggregate and we cannot create a temporary variable for that type. */
582 : :
583 : : tree
584 : 271666461 : maybe_cleanup_point_expr_void (tree expr)
585 : : {
586 : 271666461 : if (!processing_template_decl && stmts_are_full_exprs_p ())
587 : 96537484 : expr = fold_build_cleanup_point_expr (void_type_node, expr);
588 : 271666461 : return expr;
589 : : }
590 : :
591 : :
592 : :
593 : : /* Create a declaration statement for the declaration given by the DECL. */
594 : :
595 : : void
596 : 89743727 : add_decl_expr (tree decl)
597 : : {
598 : 89743727 : tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
599 : 89743727 : if (DECL_INITIAL (decl)
600 : 89743727 : || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
601 : 10101682 : r = maybe_cleanup_point_expr_void (r);
602 : 89743727 : add_stmt (r);
603 : 89743727 : }
604 : :
605 : : /* Set EXPR_LOCATION on one cleanup T to LOC. */
606 : :
607 : : static void
608 : 5437103 : set_one_cleanup_loc (tree t, location_t loc)
609 : : {
610 : 5437103 : if (!t)
611 : : return;
612 : 5437103 : if (TREE_CODE (t) != POSTCONDITION_STMT)
613 : 5437103 : protected_set_expr_location (t, loc);
614 : : /* Avoid locus differences for C++ cdtor calls depending on whether
615 : : cdtor_returns_this: a conversion to void is added to discard the return
616 : : value, and this conversion ends up carrying the location, and when it
617 : : gets discarded, the location is lost. So hold it in the call as well. */
618 : 5437103 : if (TREE_CODE (t) == NOP_EXPR
619 : 0 : && TREE_TYPE (t) == void_type_node
620 : 5437103 : && TREE_CODE (TREE_OPERAND (t, 0)) == CALL_EXPR)
621 : 0 : protected_set_expr_location (TREE_OPERAND (t, 0), loc);
622 : : }
623 : :
624 : : /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC. */
625 : :
626 : : static void
627 : 1037601219 : set_cleanup_locs (tree stmts, location_t loc)
628 : : {
629 : 1043038322 : if (TREE_CODE (stmts) == CLEANUP_STMT)
630 : : {
631 : 5437103 : set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
632 : 5437103 : set_cleanup_locs (CLEANUP_BODY (stmts), loc);
633 : : }
634 : 1037601219 : else if (TREE_CODE (stmts) == STATEMENT_LIST)
635 : 927930872 : for (tree stmt : tsi_range (stmts))
636 : 715772899 : set_cleanup_locs (stmt, loc);
637 : 1037601219 : }
638 : :
639 : : /* True iff the innermost block scope is a try block. */
640 : :
641 : : static bool
642 : 321828320 : at_try_scope ()
643 : : {
644 : 321828320 : cp_binding_level *b = current_binding_level;
645 : 321828638 : while (b && b->kind == sk_cleanup)
646 : 318 : b = b->level_chain;
647 : 321828320 : return b && b->kind == sk_try;
648 : : }
649 : :
650 : : /* Finish a scope. */
651 : :
652 : : tree
653 : 321828320 : do_poplevel (tree stmt_list)
654 : : {
655 : 321828320 : tree block = NULL;
656 : :
657 : 321828320 : bool was_try = at_try_scope ();
658 : :
659 : 321828320 : if (stmts_are_full_exprs_p ())
660 : 321805881 : block = poplevel (kept_level_p (), 1, 0);
661 : :
662 : : /* This needs to come after poplevel merges sk_cleanup statement_lists. */
663 : 321828320 : maybe_splice_retval_cleanup (stmt_list, was_try);
664 : :
665 : 321828320 : stmt_list = pop_stmt_list (stmt_list);
666 : :
667 : : /* input_location is the last token of the scope, usually a }. */
668 : 321828320 : set_cleanup_locs (stmt_list, input_location);
669 : :
670 : 321828320 : if (!processing_template_decl)
671 : : {
672 : 100692779 : stmt_list = c_build_bind_expr (input_location, block, stmt_list);
673 : : /* ??? See c_end_compound_stmt re statement expressions. */
674 : : }
675 : :
676 : 321828320 : return stmt_list;
677 : : }
678 : :
679 : : /* Begin a new scope. */
680 : :
681 : : tree
682 : 321817835 : do_pushlevel (scope_kind sk)
683 : : {
684 : 321817835 : tree ret = push_stmt_list ();
685 : 321817835 : if (stmts_are_full_exprs_p ())
686 : 321805941 : begin_scope (sk, NULL);
687 : 321817835 : return ret;
688 : : }
689 : :
690 : : /* Queue a cleanup. CLEANUP is an expression/statement to be executed
691 : : when the current scope is exited. EH_ONLY is true when this is not
692 : : meant to apply to normal control flow transfer. DECL is the VAR_DECL
693 : : being cleaned up, if any, or null for temporaries or subobjects. */
694 : :
695 : : void
696 : 5436980 : push_cleanup (tree decl, tree cleanup, bool eh_only)
697 : : {
698 : 5436980 : tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
699 : 5436980 : CLEANUP_EH_ONLY (stmt) = eh_only;
700 : 5436980 : add_stmt (stmt);
701 : 5436980 : CLEANUP_BODY (stmt) = push_stmt_list ();
702 : 5436980 : }
703 : :
704 : : /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
705 : : the current loops, represented by 'NULL_TREE' if we've seen a possible
706 : : exit, and 'error_mark_node' if not. This is currently used only to
707 : : suppress the warning about a function with no return statements, and
708 : : therefore we don't bother noting returns as possible exits. We also
709 : : don't bother with gotos. */
710 : :
711 : : static void
712 : 16009733 : begin_maybe_infinite_loop (tree cond)
713 : : {
714 : : /* Only track this while parsing a function, not during instantiation. */
715 : 16009733 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
716 : 2335222 : && !processing_template_decl))
717 : : return;
718 : 13673976 : bool maybe_infinite = true;
719 : 13673976 : if (cond)
720 : : {
721 : 13440183 : cond = fold_non_dependent_expr (cond);
722 : 13440183 : maybe_infinite = integer_nonzerop (cond);
723 : : }
724 : 27114159 : vec_safe_push (cp_function_chain->infinite_loops,
725 : 13673976 : maybe_infinite ? error_mark_node : NULL_TREE);
726 : :
727 : : }
728 : :
729 : : /* A break is a possible exit for the current loop. */
730 : :
731 : : void
732 : 1410175 : break_maybe_infinite_loop (void)
733 : : {
734 : 1410175 : if (!cfun)
735 : : return;
736 : 1410175 : cp_function_chain->infinite_loops->last() = NULL_TREE;
737 : : }
738 : :
739 : : /* If we reach the end of the loop without seeing a possible exit, we have
740 : : an infinite loop. */
741 : :
742 : : static void
743 : 16009733 : end_maybe_infinite_loop (tree cond)
744 : : {
745 : 16009733 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
746 : 2335222 : && !processing_template_decl))
747 : : return;
748 : 13673976 : tree current = cp_function_chain->infinite_loops->pop();
749 : 13673976 : if (current != NULL_TREE)
750 : : {
751 : 4319437 : cond = fold_non_dependent_expr (cond);
752 : 4319437 : if (integer_nonzerop (cond))
753 : 223715 : current_function_infinite_loop = 1;
754 : : }
755 : : }
756 : :
757 : : /* Begin a conditional that might contain a declaration. When generating
758 : : normal code, we want the declaration to appear before the statement
759 : : containing the conditional. When generating template code, we want the
760 : : conditional to be rendered as the raw DECL_EXPR. */
761 : :
762 : : static void
763 : 70712391 : begin_cond (tree *cond_p)
764 : : {
765 : 70712391 : if (processing_template_decl)
766 : 49085375 : *cond_p = push_stmt_list ();
767 : 70712391 : }
768 : :
769 : : /* Finish such a conditional. */
770 : :
771 : : static void
772 : 70712391 : finish_cond (tree *cond_p, tree expr)
773 : : {
774 : 70712391 : if (processing_template_decl)
775 : : {
776 : 49085375 : tree cond = pop_stmt_list (*cond_p);
777 : :
778 : 49085375 : if (expr == NULL_TREE)
779 : : /* Empty condition in 'for'. */
780 : 226560 : gcc_assert (empty_expr_stmt_p (cond));
781 : 48858815 : else if (check_for_bare_parameter_packs (expr))
782 : 0 : expr = error_mark_node;
783 : 48858815 : else if (!empty_expr_stmt_p (cond))
784 : 647243 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
785 : : }
786 : 70712391 : *cond_p = expr;
787 : 70712391 : }
788 : :
789 : : /* If loop condition specifies a conditional with a declaration,
790 : : such as
791 : : while (A x = 42) { }
792 : : for (; A x = 42;) { }
793 : : move the *BODY_P statements as a BIND_EXPR into {FOR,WHILE}_COND_PREP
794 : : and if there are any CLEANUP_STMT at the end, remember their count in
795 : : {FOR,WHILE}_COND_CLEANUP.
796 : : genericize_c_loop will then handle it appropriately. In particular,
797 : : the {FOR,WHILE}_COND, {FOR,WHILE}_BODY, if used continue label and
798 : : FOR_EXPR will be appended into the {FOR,WHILE}_COND_PREP BIND_EXPR,
799 : : but it can't be done too early because only the actual body should
800 : : bind BREAK_STMT and CONTINUE_STMT to the inner loop.
801 : : The statement list for *BODY will be empty if the conditional did
802 : : not declare anything. */
803 : :
804 : : static void
805 : 10915818 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
806 : : {
807 : 10915818 : if (!TREE_SIDE_EFFECTS (*body_p))
808 : 10905641 : return;
809 : :
810 : 10177 : gcc_assert (!processing_template_decl);
811 : 10177 : *prep_p = *body_p;
812 : 10177 : if (*prep_p != cur_stmt_list)
813 : : {
814 : : /* There can be just one CLEANUP_STMT, or there could be multiple
815 : : nested CLEANUP_STMTs, e.g. for structured bindings used as
816 : : condition. */
817 : 97 : gcc_assert (stmt_list_stack->length () > 1);
818 : 97 : for (unsigned i = stmt_list_stack->length () - 2; ; --i)
819 : : {
820 : 109 : tree t = (*stmt_list_stack)[i];
821 : 109 : tree_stmt_iterator last = tsi_last (t);
822 : 218 : gcc_assert (tsi_one_before_end_p (last)
823 : : && TREE_CODE (tsi_stmt (last)) == CLEANUP_STMT
824 : : && (CLEANUP_BODY (tsi_stmt (last))
825 : : == (*stmt_list_stack)[i + 1])
826 : : && !CLEANUP_EH_ONLY (tsi_stmt (last)));
827 : 109 : if (t == *prep_p)
828 : : {
829 : 97 : *cleanup_p = build_int_cst (long_unsigned_type_node,
830 : 97 : stmt_list_stack->length () - 1 - i);
831 : 97 : break;
832 : : }
833 : 12 : gcc_assert (i >= 1);
834 : 12 : }
835 : : }
836 : 10177 : current_binding_level->keep = true;
837 : 10177 : tree_stmt_iterator iter = tsi_last (cur_stmt_list);
838 : : /* Temporarily store in {FOR,WHILE}_BODY the last statement of
839 : : the innnermost statement list or NULL if it has no statement.
840 : : This is used in finish_loop_cond_prep to find out the splitting
841 : : point and then {FOR,WHILE}_BODY will be changed to the actual
842 : : body. */
843 : 10177 : if (tsi_end_p (iter))
844 : 91 : *body_p = NULL_TREE;
845 : : else
846 : 10086 : *body_p = tsi_stmt (iter);
847 : : }
848 : :
849 : : /* Finalize {FOR,WHILE}_{BODY,COND_PREP} after the loop body.
850 : : The above function initialized *BODY_P to the last statement
851 : : in *PREP_P at that point.
852 : : Call do_poplevel on *PREP_P and move everything after that
853 : : former last statement into *BODY_P. genericize_c_loop
854 : : will later put those parts back together.
855 : : CLEANUP is {FOR,WHILE}_COND_CLEANUP. */
856 : :
857 : : static void
858 : 10177 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
859 : : {
860 : 10177 : *prep_p = do_poplevel (*prep_p);
861 : 10177 : gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
862 : 10177 : if (BIND_EXPR_BODY (*prep_p) == *body_p)
863 : : {
864 : 18 : gcc_assert (cleanup == NULL_TREE);
865 : 18 : *body_p = build_empty_stmt (input_location);
866 : 109 : return;
867 : : }
868 : 10159 : tree stmt_list = BIND_EXPR_BODY (*prep_p);
869 : 10159 : gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
870 : 10159 : if (cleanup)
871 : : {
872 : 97 : tree_stmt_iterator iter = tsi_last (stmt_list);
873 : 97 : gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
874 : 109 : for (unsigned depth = tree_to_uhwi (cleanup); depth > 1; --depth)
875 : : {
876 : 12 : gcc_assert (TREE_CODE (CLEANUP_BODY (tsi_stmt (iter)))
877 : : == STATEMENT_LIST);
878 : 12 : iter = tsi_last (CLEANUP_BODY (tsi_stmt (iter)));
879 : 12 : gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
880 : : }
881 : 97 : if (*body_p == NULL_TREE)
882 : : {
883 : 91 : *body_p = CLEANUP_BODY (tsi_stmt (iter));
884 : 91 : CLEANUP_BODY (tsi_stmt (iter)) = build_empty_stmt (input_location);
885 : 91 : return;
886 : : }
887 : 6 : stmt_list = CLEANUP_BODY (tsi_stmt (iter));
888 : : }
889 : 10068 : tree_stmt_iterator iter = tsi_start (stmt_list);
890 : 10264 : while (tsi_stmt (iter) != *body_p)
891 : 196 : tsi_next (&iter);
892 : 10068 : *body_p = tsi_split_stmt_list (input_location, iter);
893 : : }
894 : :
895 : : /* Finish a goto-statement. */
896 : :
897 : : tree
898 : 2709 : finish_goto_stmt (tree destination)
899 : : {
900 : 2709 : if (identifier_p (destination))
901 : 2575 : destination = lookup_label (destination);
902 : :
903 : : /* We warn about unused labels with -Wunused. That means we have to
904 : : mark the used labels as used. */
905 : 2709 : if (TREE_CODE (destination) == LABEL_DECL)
906 : 2575 : TREE_USED (destination) = 1;
907 : : else
908 : : {
909 : 134 : destination = mark_rvalue_use (destination);
910 : 134 : if (!processing_template_decl)
911 : : {
912 : 114 : destination = cp_convert (ptr_type_node, destination,
913 : : tf_warning_or_error);
914 : 114 : if (error_operand_p (destination))
915 : : return NULL_TREE;
916 : 105 : destination
917 : 105 : = fold_build_cleanup_point_expr (TREE_TYPE (destination),
918 : : destination);
919 : : }
920 : : }
921 : :
922 : 2700 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
923 : :
924 : 2700 : tree stmt = build_stmt (input_location, GOTO_EXPR, destination);
925 : 2700 : check_goto (&TREE_OPERAND (stmt, 0));
926 : :
927 : 2700 : return add_stmt (stmt);
928 : : }
929 : :
930 : : /* Returns true if T corresponds to an assignment operator expression. */
931 : :
932 : : static bool
933 : 830702 : is_assignment_op_expr_p (tree t)
934 : : {
935 : 830702 : if (t == NULL_TREE)
936 : : return false;
937 : :
938 : 830702 : if (TREE_CODE (t) == MODIFY_EXPR
939 : 830702 : || (TREE_CODE (t) == MODOP_EXPR
940 : 330 : && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
941 : : return true;
942 : :
943 : 830021 : tree call = extract_call_expr (t);
944 : 830021 : if (call == NULL_TREE
945 : 126202 : || call == error_mark_node
946 : 956223 : || !CALL_EXPR_OPERATOR_SYNTAX (call))
947 : : return false;
948 : :
949 : 4403 : tree fndecl = cp_get_callee_fndecl_nofold (call);
950 : 4403 : return fndecl != NULL_TREE
951 : 4374 : && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
952 : 4454 : && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR);
953 : : }
954 : :
955 : : /* Return true if TYPE is a class type that is convertible to
956 : : and assignable from bool. */
957 : :
958 : : static GTY((deletable)) hash_map<tree, bool> *boolish_class_type_p_cache;
959 : :
960 : : static bool
961 : 60 : boolish_class_type_p (tree type)
962 : : {
963 : 60 : type = TYPE_MAIN_VARIANT (type);
964 : 60 : if (!CLASS_TYPE_P (type) || !COMPLETE_TYPE_P (type))
965 : : return false;
966 : :
967 : 78 : if (bool *r = hash_map_safe_get (boolish_class_type_p_cache, type))
968 : 27 : return *r;
969 : :
970 : 18 : tree ops;
971 : 18 : bool has_bool_assignment = false;
972 : 18 : bool has_bool_conversion = false;
973 : :
974 : 18 : ops = lookup_fnfields (type, assign_op_identifier, /*protect=*/0, tf_none);
975 : 55 : for (tree op : ovl_range (BASELINK_FUNCTIONS (ops)))
976 : : {
977 : 29 : op = STRIP_TEMPLATE (op);
978 : 29 : if (TREE_CODE (op) != FUNCTION_DECL)
979 : 0 : continue;
980 : 29 : tree parm = DECL_CHAIN (DECL_ARGUMENTS (op));
981 : 29 : tree parm_type = non_reference (TREE_TYPE (parm));
982 : 29 : if (TREE_CODE (parm_type) == BOOLEAN_TYPE)
983 : : {
984 : : has_bool_assignment = true;
985 : : break;
986 : : }
987 : : }
988 : :
989 : 18 : if (has_bool_assignment)
990 : : {
991 : 3 : ops = lookup_conversions (type);
992 : 3 : for (; ops; ops = TREE_CHAIN (ops))
993 : : {
994 : 3 : tree op = TREE_VALUE (ops);
995 : 3 : if (!DECL_NONCONVERTING_P (op)
996 : 3 : && TREE_CODE (DECL_CONV_FN_TYPE (op)) == BOOLEAN_TYPE)
997 : : {
998 : : has_bool_conversion = true;
999 : : break;
1000 : : }
1001 : : }
1002 : : }
1003 : :
1004 : 18 : bool boolish = has_bool_assignment && has_bool_conversion;
1005 : 18 : hash_map_safe_put<true> (boolish_class_type_p_cache, type, boolish);
1006 : 18 : return boolish;
1007 : : }
1008 : :
1009 : :
1010 : : /* Maybe warn about an unparenthesized 'a = b' (appearing in a
1011 : : boolean context where 'a == b' might have been intended).
1012 : : NESTED_P is true if T is the RHS of another assignment. */
1013 : :
1014 : : void
1015 : 70171786 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
1016 : : tsubst_flags_t complain)
1017 : : {
1018 : 70171786 : tree type = TREE_TYPE (t);
1019 : 70171786 : t = STRIP_REFERENCE_REF (t);
1020 : :
1021 : 70171786 : if ((complain & tf_warning)
1022 : 70130442 : && warn_parentheses
1023 : 830702 : && is_assignment_op_expr_p (t)
1024 : : /* A parenthesized expression would've had this warning
1025 : : suppressed by finish_parenthesized_expr. */
1026 : 732 : && !warning_suppressed_p (t, OPT_Wparentheses)
1027 : : /* In c = a = b, don't warn if a has type bool or bool-like class. */
1028 : 70172133 : && (!nested_p
1029 : 176 : || (TREE_CODE (type) != BOOLEAN_TYPE
1030 : 60 : && !boolish_class_type_p (type))))
1031 : : {
1032 : 219 : warning_at (cp_expr_loc_or_input_loc (t), OPT_Wparentheses,
1033 : : "suggest parentheses around assignment used as truth value");
1034 : 219 : suppress_warning (t, OPT_Wparentheses);
1035 : : }
1036 : 70171786 : }
1037 : :
1038 : : /* Helper class for saving/restoring ANNOTATE_EXPRs. For a tree node t, users
1039 : : can construct one of these like so:
1040 : :
1041 : : annotate_saver s (&t);
1042 : :
1043 : : and t will be updated to have any annotations removed. The user can then
1044 : : transform t, and later restore the ANNOTATE_EXPRs with:
1045 : :
1046 : : t = s.restore (t).
1047 : :
1048 : : The intent is to ensure that any ANNOTATE_EXPRs remain the outermost
1049 : : expressions following any operations on t. */
1050 : :
1051 : : class annotate_saver {
1052 : : /* The chain of saved annotations, if there were any. Otherwise null. */
1053 : : tree m_annotations;
1054 : :
1055 : : /* If M_ANNOTATIONS is non-null, then M_INNER points to TREE_OPERAND (A, 0)
1056 : : for the innermost annotation A. */
1057 : : tree *m_inner;
1058 : :
1059 : : public:
1060 : : annotate_saver (tree *);
1061 : : tree restore (tree);
1062 : : };
1063 : :
1064 : : /* If *COND is an ANNOTATE_EXPR, walk through the chain of annotations, and set
1065 : : *COND equal to the first non-ANNOTATE_EXPR (saving a pointer to the
1066 : : original chain of annotations for later use in restore). */
1067 : :
1068 : 43818310 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
1069 : : {
1070 : 43818310 : tree *t = cond;
1071 : 43821766 : while (TREE_CODE (*t) == ANNOTATE_EXPR)
1072 : 3456 : t = &TREE_OPERAND (*t, 0);
1073 : :
1074 : 43818310 : if (t != cond)
1075 : : {
1076 : 3453 : m_annotations = *cond;
1077 : 3453 : *cond = *t;
1078 : 3453 : m_inner = t;
1079 : : }
1080 : 43818310 : }
1081 : :
1082 : : /* If we didn't strip any annotations on construction, return NEW_INNER
1083 : : unmodified. Otherwise, wrap the saved annotations around NEW_INNER (updating
1084 : : the types and flags of the annotations if needed) and return the resulting
1085 : : expression. */
1086 : :
1087 : : tree
1088 : 43818310 : annotate_saver::restore (tree new_inner)
1089 : : {
1090 : 43818310 : if (!m_annotations)
1091 : : return new_inner;
1092 : :
1093 : : /* If the type of the inner expression changed, we need to update the types
1094 : : of all the ANNOTATE_EXPRs. We may need to update the flags too, but we
1095 : : assume they only change if the type of the inner expression changes.
1096 : : The flag update logic assumes that the other operands to the
1097 : : ANNOTATE_EXPRs are always INTEGER_CSTs. */
1098 : 3453 : if (TREE_TYPE (new_inner) != TREE_TYPE (*m_inner))
1099 : : {
1100 : 6 : const bool new_readonly
1101 : 6 : = TREE_READONLY (new_inner) || CONSTANT_CLASS_P (new_inner);
1102 : :
1103 : 12 : for (tree c = m_annotations; c != *m_inner; c = TREE_OPERAND (c, 0))
1104 : : {
1105 : 6 : gcc_checking_assert (TREE_CODE (c) == ANNOTATE_EXPR
1106 : : && TREE_CODE (TREE_OPERAND (c, 1)) == INTEGER_CST
1107 : : && TREE_CODE (TREE_OPERAND (c, 2)) == INTEGER_CST);
1108 : 6 : TREE_TYPE (c) = TREE_TYPE (new_inner);
1109 : 6 : TREE_SIDE_EFFECTS (c) = TREE_SIDE_EFFECTS (new_inner);
1110 : 6 : TREE_READONLY (c) = new_readonly;
1111 : : }
1112 : : }
1113 : :
1114 : 3453 : *m_inner = new_inner;
1115 : 3453 : return m_annotations;
1116 : : }
1117 : :
1118 : : /* COND is the condition-expression for an if, while, etc.,
1119 : : statement. Convert it to a boolean value, if appropriate.
1120 : : In addition, verify sequence points if -Wsequence-point is enabled. */
1121 : :
1122 : : tree
1123 : 75041205 : maybe_convert_cond (tree cond)
1124 : : {
1125 : : /* Empty conditions remain empty. */
1126 : 75041205 : if (!cond)
1127 : : return NULL_TREE;
1128 : :
1129 : : /* Wait until we instantiate templates before doing conversion. */
1130 : 74750375 : if (type_dependent_expression_p (cond))
1131 : 30932065 : return cond;
1132 : :
1133 : : /* Strip any ANNOTATE_EXPRs from COND. */
1134 : 43818310 : annotate_saver annotations (&cond);
1135 : :
1136 : : /* For structured binding used in condition, the conversion needs to be
1137 : : evaluated before the individual variables are initialized in the
1138 : : std::tuple_{size,elemenet} case. cp_finish_decomp saved the conversion
1139 : : result in a TARGET_EXPR, pick it up from there. */
1140 : 362085 : if (DECL_DECOMPOSITION_P (cond)
1141 : 217 : && DECL_DECOMP_IS_BASE (cond)
1142 : 217 : && DECL_DECOMP_BASE (cond)
1143 : 43818524 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1144 : 56 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1145 : :
1146 : 43818310 : if (warn_sequence_point && !processing_template_decl)
1147 : 312631 : verify_sequence_points (cond);
1148 : :
1149 : 43818310 : maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
1150 : : tf_warning_or_error);
1151 : :
1152 : : /* Do the conversion. */
1153 : 43818310 : cond = convert_from_reference (cond);
1154 : 43818310 : cond = condition_conversion (cond);
1155 : :
1156 : : /* Restore any ANNOTATE_EXPRs around COND. */
1157 : 43818310 : return annotations.restore (cond);
1158 : : }
1159 : :
1160 : : /* Finish an expression-statement, whose EXPRESSION is as indicated. */
1161 : :
1162 : : tree
1163 : 145648678 : finish_expr_stmt (tree expr)
1164 : : {
1165 : 145648678 : tree r = NULL_TREE;
1166 : 145648678 : location_t loc = EXPR_LOCATION (expr);
1167 : :
1168 : 145429039 : if (expr != NULL_TREE)
1169 : : {
1170 : : /* If we ran into a problem, make sure we complained. */
1171 : 145648517 : gcc_assert (expr != error_mark_node || seen_error ());
1172 : :
1173 : 145648517 : if (!processing_template_decl)
1174 : : {
1175 : 54505108 : if (warn_sequence_point)
1176 : 786782 : verify_sequence_points (expr);
1177 : 54505108 : expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1178 : : }
1179 : 91143409 : else if (!type_dependent_expression_p (expr))
1180 : 18830843 : convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1181 : :
1182 : 145648514 : if (check_for_bare_parameter_packs (expr))
1183 : 24 : expr = error_mark_node;
1184 : :
1185 : : /* Simplification of inner statement expressions, compound exprs,
1186 : : etc can result in us already having an EXPR_STMT or other statement
1187 : : tree. Don't wrap them in EXPR_STMT. */
1188 : 145648514 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
1189 : : {
1190 : 145648335 : if (TREE_CODE (expr) != EXPR_STMT
1191 : 143706309 : && !STATEMENT_CLASS_P (expr)
1192 : 143702158 : && TREE_CODE (expr) != STATEMENT_LIST)
1193 : 143527537 : expr = build_stmt (loc, EXPR_STMT, expr);
1194 : 145648335 : expr = maybe_cleanup_point_expr_void (expr);
1195 : : }
1196 : :
1197 : 145648514 : r = add_stmt (expr);
1198 : : }
1199 : :
1200 : 145648675 : return r;
1201 : : }
1202 : :
1203 : :
1204 : : /* Begin an if-statement. Returns a newly created IF_STMT if
1205 : : appropriate. */
1206 : :
1207 : : tree
1208 : 59262020 : begin_if_stmt (void)
1209 : : {
1210 : 59262020 : tree r, scope;
1211 : 59262020 : scope = do_pushlevel (sk_cond);
1212 : 59262020 : r = build_stmt (input_location, IF_STMT, NULL_TREE,
1213 : : NULL_TREE, NULL_TREE, scope);
1214 : 59262020 : current_binding_level->this_entity = r;
1215 : 59262020 : begin_cond (&IF_COND (r));
1216 : 59262020 : return r;
1217 : : }
1218 : :
1219 : : /* Returns true if FN, a CALL_EXPR, is a call to
1220 : : std::is_constant_evaluated or __builtin_is_constant_evaluated. */
1221 : :
1222 : : static bool
1223 : 241429 : is_std_constant_evaluated_p (tree fn)
1224 : : {
1225 : : /* std::is_constant_evaluated takes no arguments. */
1226 : 241429 : if (call_expr_nargs (fn) != 0)
1227 : : return false;
1228 : :
1229 : 84890 : tree fndecl = cp_get_callee_fndecl_nofold (fn);
1230 : 84890 : if (fndecl == NULL_TREE)
1231 : : return false;
1232 : :
1233 : 25543 : if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
1234 : : BUILT_IN_FRONTEND))
1235 : : return true;
1236 : :
1237 : 25517 : if (!decl_in_std_namespace_p (fndecl))
1238 : : return false;
1239 : :
1240 : 10648 : tree name = DECL_NAME (fndecl);
1241 : 10648 : return name && id_equal (name, "is_constant_evaluated");
1242 : : }
1243 : :
1244 : : /* Callback function for maybe_warn_for_constant_evaluated that looks
1245 : : for calls to std::is_constant_evaluated in TP. */
1246 : :
1247 : : static tree
1248 : 4466132 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
1249 : : {
1250 : 4466132 : tree t = *tp;
1251 : :
1252 : 4466132 : if (TYPE_P (t) || TREE_CONSTANT (t))
1253 : : {
1254 : 784119 : *walk_subtrees = false;
1255 : 784119 : return NULL_TREE;
1256 : : }
1257 : :
1258 : 3682013 : switch (TREE_CODE (t))
1259 : : {
1260 : 241429 : case CALL_EXPR:
1261 : 241429 : if (is_std_constant_evaluated_p (t))
1262 : : return t;
1263 : : break;
1264 : 6 : case EXPR_STMT:
1265 : : /* Don't warn in statement expressions. */
1266 : 6 : *walk_subtrees = false;
1267 : 6 : return NULL_TREE;
1268 : : default:
1269 : : break;
1270 : : }
1271 : :
1272 : : return NULL_TREE;
1273 : : }
1274 : :
1275 : : /* In certain contexts, std::is_constant_evaluated() is always true (for
1276 : : instance, in a consteval function or in a constexpr if), or always false
1277 : : (e.g., in a non-constexpr non-consteval function) so give the user a clue. */
1278 : :
1279 : : static void
1280 : 59343783 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
1281 : : bool trivial_infinite)
1282 : : {
1283 : 59343783 : if (!warn_tautological_compare)
1284 : : return;
1285 : :
1286 : : /* Suppress warning for std::is_constant_evaluated if the conditional
1287 : : comes from a macro. */
1288 : 1359086 : if (from_macro_expansion_at (EXPR_LOCATION (cond)))
1289 : : return;
1290 : :
1291 : 569675 : cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
1292 : : NULL);
1293 : 569675 : if (cond)
1294 : : {
1295 : 2139 : if (constexpr_if)
1296 : 34 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1297 : : "%<std::is_constant_evaluated%> always evaluates to "
1298 : : "true in %<if constexpr%>");
1299 : 2105 : else if (trivial_infinite)
1300 : : {
1301 : 8 : auto_diagnostic_group d;
1302 : 8 : if (warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1303 : : "%<std::is_constant_evaluated%> evaluates to "
1304 : : "true when checking if trivially empty iteration "
1305 : : "statement is trivial infinite loop")
1306 : 8 : && !maybe_constexpr_fn (current_function_decl))
1307 : 8 : inform (EXPR_LOCATION (cond),
1308 : : "and evaluates to false when actually evaluating "
1309 : : "the condition in non-%<constexpr%> function");
1310 : 8 : }
1311 : 2097 : else if (!maybe_constexpr_fn (current_function_decl))
1312 : 38 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1313 : : "%<std::is_constant_evaluated%> always evaluates to "
1314 : : "false in a non-%<constexpr%> function");
1315 : 4118 : else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1316 : 3 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1317 : : "%<std::is_constant_evaluated%> always evaluates to "
1318 : : "true in a %<consteval%> function");
1319 : : }
1320 : : }
1321 : :
1322 : : /* Process the COND of an if-statement, which may be given by
1323 : : IF_STMT. */
1324 : :
1325 : : tree
1326 : 59262020 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
1327 : : {
1328 : 59262020 : tree cond = maybe_convert_cond (orig_cond);
1329 : 59262020 : maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
1330 : : /*trivial_infinite=*/false);
1331 : 59262020 : if (IF_STMT_CONSTEXPR_P (if_stmt)
1332 : 9528402 : && !type_dependent_expression_p (cond)
1333 : 6515050 : && require_constant_expression (cond)
1334 : 6515022 : && !instantiation_dependent_expression_p (cond)
1335 : : /* Wait until instantiation time, since only then COND has been
1336 : : converted to bool. */
1337 : 63234618 : && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
1338 : : {
1339 : 3972598 : cond = instantiate_non_dependent_expr (cond);
1340 : 3972598 : cond = cxx_constant_value (cond);
1341 : : }
1342 : 55289422 : else if (processing_template_decl)
1343 : 39877013 : cond = orig_cond;
1344 : 59262020 : finish_cond (&IF_COND (if_stmt), cond);
1345 : 59262020 : add_stmt (if_stmt);
1346 : 59262020 : THEN_CLAUSE (if_stmt) = push_stmt_list ();
1347 : 59262020 : return cond;
1348 : : }
1349 : :
1350 : : /* Finish the then-clause of an if-statement, which may be given by
1351 : : IF_STMT. */
1352 : :
1353 : : tree
1354 : 59252994 : finish_then_clause (tree if_stmt)
1355 : : {
1356 : 59252994 : THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
1357 : 59252994 : return if_stmt;
1358 : : }
1359 : :
1360 : : /* Begin the else-clause of an if-statement. */
1361 : :
1362 : : void
1363 : 21247803 : begin_else_clause (tree if_stmt)
1364 : : {
1365 : 21247803 : ELSE_CLAUSE (if_stmt) = push_stmt_list ();
1366 : 21247803 : }
1367 : :
1368 : : /* Finish the else-clause of an if-statement, which may be given by
1369 : : IF_STMT. */
1370 : :
1371 : : void
1372 : 21247765 : finish_else_clause (tree if_stmt)
1373 : : {
1374 : 21247765 : ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
1375 : 21247765 : }
1376 : :
1377 : : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1378 : : read. */
1379 : :
1380 : : static tree
1381 : 460950694 : maybe_mark_exp_read_r (tree *tp, int *, void *)
1382 : : {
1383 : 460950694 : tree t = *tp;
1384 : 460950694 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1385 : 28962705 : mark_exp_read (t);
1386 : 460950694 : return NULL_TREE;
1387 : : }
1388 : :
1389 : : /* Finish an if-statement. */
1390 : :
1391 : : void
1392 : 59252295 : finish_if_stmt (tree if_stmt)
1393 : : {
1394 : 59252295 : tree scope = IF_SCOPE (if_stmt);
1395 : 59252295 : IF_SCOPE (if_stmt) = NULL;
1396 : 59252295 : if (IF_STMT_CONSTEXPR_P (if_stmt))
1397 : : {
1398 : : /* Prevent various -Wunused warnings. We might not instantiate
1399 : : either of these branches, so we would not mark the variables
1400 : : used in that branch as read. */
1401 : 9519376 : cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
1402 : : maybe_mark_exp_read_r, NULL);
1403 : 9519376 : cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
1404 : : maybe_mark_exp_read_r, NULL);
1405 : : }
1406 : 59252295 : add_stmt (do_poplevel (scope));
1407 : 59252295 : }
1408 : :
1409 : : /* Determine if iteration statement with *CONDP condition and
1410 : : loop BODY is trivially empty iteration statement or even
1411 : : trivial infinite loop. In the latter case for -ffinite-loops
1412 : : add ANNOTATE_EXPR to mark the loop as maybe validly infinite.
1413 : : Also, emit -Wtautological-compare warning for std::is_constant_evaluated ()
1414 : : calls in the condition when needed. */
1415 : :
1416 : : static void
1417 : 15485073 : finish_loop_cond (tree *condp, tree body)
1418 : : {
1419 : 15485073 : if (TREE_CODE (*condp) == INTEGER_CST)
1420 : : return;
1421 : 11222573 : bool trivially_empty = expr_first (body) == NULL_TREE;
1422 : 11222573 : bool trivial_infinite = false;
1423 : 11222573 : if (trivially_empty)
1424 : : {
1425 : 73276 : tree c = fold_non_dependent_expr (*condp, tf_none,
1426 : : /*manifestly_const_eval=*/true);
1427 : 73276 : trivial_infinite = c && integer_nonzerop (c);
1428 : : }
1429 : 11222573 : if (warn_tautological_compare)
1430 : : {
1431 : 81941 : tree cond = *condp;
1432 : 82296 : while (TREE_CODE (cond) == ANNOTATE_EXPR)
1433 : 355 : cond = TREE_OPERAND (cond, 0);
1434 : 81941 : if (trivial_infinite
1435 : 82005 : && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1436 : 64 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1437 : : /*trivial_infinite=*/true);
1438 : 81877 : else if (!trivially_empty
1439 : 345 : || !processing_template_decl
1440 : 82233 : || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1441 : 81699 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1442 : : /*trivial_infinite=*/false);
1443 : : }
1444 : 11222573 : if (trivial_infinite && flag_finite_loops && !processing_template_decl)
1445 : 64 : *condp = build3 (ANNOTATE_EXPR, TREE_TYPE (*condp), *condp,
1446 : : build_int_cst (integer_type_node,
1447 : : annot_expr_maybe_infinite_kind),
1448 : : integer_zero_node);
1449 : : }
1450 : :
1451 : : /* Begin a while-statement. Returns a newly created WHILE_STMT if
1452 : : appropriate. */
1453 : :
1454 : : tree
1455 : 4044756 : begin_while_stmt (void)
1456 : : {
1457 : 4044756 : tree r;
1458 : 4044756 : r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1459 : : NULL_TREE, NULL_TREE);
1460 : 4044756 : add_stmt (r);
1461 : 4044756 : WHILE_BODY (r) = do_pushlevel (sk_block);
1462 : 4044756 : begin_cond (&WHILE_COND (r));
1463 : 4044756 : return r;
1464 : : }
1465 : :
1466 : : /* Process the COND of a while-statement, which may be given by
1467 : : WHILE_STMT. */
1468 : :
1469 : : void
1470 : 4044756 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
1471 : : tree unroll, bool novector)
1472 : : {
1473 : 4044756 : cond = maybe_convert_cond (cond);
1474 : 4044756 : finish_cond (&WHILE_COND (while_stmt), cond);
1475 : 4044756 : begin_maybe_infinite_loop (cond);
1476 : 4044756 : if (ivdep && cond != error_mark_node)
1477 : 24 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1478 : 12 : TREE_TYPE (WHILE_COND (while_stmt)),
1479 : 12 : WHILE_COND (while_stmt),
1480 : : build_int_cst (integer_type_node,
1481 : : annot_expr_ivdep_kind),
1482 : : integer_zero_node);
1483 : 4044756 : if (unroll && cond != error_mark_node)
1484 : 26298 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1485 : 13149 : TREE_TYPE (WHILE_COND (while_stmt)),
1486 : 13149 : WHILE_COND (while_stmt),
1487 : : build_int_cst (integer_type_node,
1488 : : annot_expr_unroll_kind),
1489 : : unroll);
1490 : 4044756 : if (novector && cond != error_mark_node)
1491 : 42 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1492 : 21 : TREE_TYPE (WHILE_COND (while_stmt)),
1493 : 21 : WHILE_COND (while_stmt),
1494 : : build_int_cst (integer_type_node,
1495 : : annot_expr_no_vector_kind),
1496 : : integer_zero_node);
1497 : 4044756 : adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
1498 : : &WHILE_COND_PREP (while_stmt),
1499 : : &WHILE_COND_CLEANUP (while_stmt));
1500 : 4044756 : }
1501 : :
1502 : : /* Finish a while-statement, which may be given by WHILE_STMT. */
1503 : :
1504 : : void
1505 : 4044756 : finish_while_stmt (tree while_stmt)
1506 : : {
1507 : 4044756 : end_maybe_infinite_loop (boolean_true_node);
1508 : 4044756 : if (WHILE_COND_PREP (while_stmt))
1509 : 10003 : finish_loop_cond_prep (&WHILE_BODY (while_stmt),
1510 : : &WHILE_COND_PREP (while_stmt),
1511 : 10003 : WHILE_COND_CLEANUP (while_stmt));
1512 : : else
1513 : 4034753 : WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
1514 : 4044756 : finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
1515 : 4044756 : }
1516 : :
1517 : : /* Begin a do-statement. Returns a newly created DO_STMT if
1518 : : appropriate. */
1519 : :
1520 : : tree
1521 : 4860085 : begin_do_stmt (void)
1522 : : {
1523 : 4860085 : tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
1524 : : NULL_TREE);
1525 : 4860085 : begin_maybe_infinite_loop (boolean_true_node);
1526 : 4860085 : add_stmt (r);
1527 : 4860085 : DO_BODY (r) = push_stmt_list ();
1528 : 4860085 : return r;
1529 : : }
1530 : :
1531 : : /* Finish the body of a do-statement, which may be given by DO_STMT. */
1532 : :
1533 : : void
1534 : 4860085 : finish_do_body (tree do_stmt)
1535 : : {
1536 : 4860085 : tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
1537 : :
1538 : 4860085 : if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
1539 : 414558 : body = STATEMENT_LIST_TAIL (body)->stmt;
1540 : :
1541 : 4860085 : if (IS_EMPTY_STMT (body))
1542 : 30 : warning (OPT_Wempty_body,
1543 : : "suggest explicit braces around empty body in %<do%> statement");
1544 : 4860085 : }
1545 : :
1546 : : /* Finish a do-statement, which may be given by DO_STMT, and whose
1547 : : COND is as indicated. */
1548 : :
1549 : : void
1550 : 4860085 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
1551 : : bool novector)
1552 : : {
1553 : 4860085 : cond = maybe_convert_cond (cond);
1554 : 4860085 : end_maybe_infinite_loop (cond);
1555 : : /* Unlike other iteration statements, the condition may not contain
1556 : : a declaration, so we don't call finish_cond which checks for
1557 : : unexpanded parameter packs. */
1558 : 4860085 : if (check_for_bare_parameter_packs (cond))
1559 : 3 : cond = error_mark_node;
1560 : 4860085 : if (ivdep && cond != error_mark_node)
1561 : 3 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1562 : : build_int_cst (integer_type_node, annot_expr_ivdep_kind),
1563 : : integer_zero_node);
1564 : 4860085 : if (unroll && cond != error_mark_node)
1565 : 9 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1566 : : build_int_cst (integer_type_node, annot_expr_unroll_kind),
1567 : : unroll);
1568 : 4860085 : if (novector && cond != error_mark_node)
1569 : 0 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1570 : : build_int_cst (integer_type_node, annot_expr_no_vector_kind),
1571 : : integer_zero_node);
1572 : 4860085 : DO_COND (do_stmt) = cond;
1573 : 4860085 : tree do_body = DO_BODY (do_stmt);
1574 : 4860055 : if (CONVERT_EXPR_P (do_body)
1575 : 30 : && integer_zerop (TREE_OPERAND (do_body, 0))
1576 : 4860115 : && VOID_TYPE_P (TREE_TYPE (do_body)))
1577 : : do_body = NULL_TREE;
1578 : 4860085 : finish_loop_cond (&DO_COND (do_stmt), do_body);
1579 : 4860085 : }
1580 : :
1581 : : /* Finish a return-statement. The EXPRESSION returned, if any, is as
1582 : : indicated. */
1583 : :
1584 : : tree
1585 : 109381076 : finish_return_stmt (tree expr)
1586 : : {
1587 : 109381076 : tree r;
1588 : 109381076 : bool no_warning;
1589 : 109381076 : bool dangling;
1590 : :
1591 : 109381076 : expr = check_return_expr (expr, &no_warning, &dangling);
1592 : :
1593 : 109381076 : if (error_operand_p (expr)
1594 : 109381076 : || (flag_openmp && !check_omp_return ()))
1595 : : {
1596 : : /* Suppress -Wreturn-type for this function. */
1597 : 1207 : if (warn_return_type)
1598 : 1201 : suppress_warning (current_function_decl, OPT_Wreturn_type);
1599 : 1207 : return error_mark_node;
1600 : : }
1601 : :
1602 : 109379869 : if (!processing_template_decl)
1603 : : {
1604 : 38951755 : if (warn_sequence_point)
1605 : 1003861 : verify_sequence_points (expr);
1606 : : }
1607 : :
1608 : 109379869 : r = build_stmt (input_location, RETURN_EXPR, expr);
1609 : 109379869 : RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
1610 : 109379869 : if (no_warning)
1611 : 35 : suppress_warning (r, OPT_Wreturn_type);
1612 : 109379869 : r = maybe_cleanup_point_expr_void (r);
1613 : 109379869 : r = add_stmt (r);
1614 : :
1615 : 109379869 : return r;
1616 : : }
1617 : :
1618 : : /* Begin the scope of a for-statement or a range-for-statement.
1619 : : Both the returned trees are to be used in a call to
1620 : : begin_for_stmt or begin_range_for_stmt. */
1621 : :
1622 : : tree
1623 : 7104892 : begin_for_scope (tree *init)
1624 : : {
1625 : 7104892 : tree scope = do_pushlevel (sk_for);
1626 : :
1627 : 7104892 : if (processing_template_decl)
1628 : 5667655 : *init = push_stmt_list ();
1629 : : else
1630 : 1437237 : *init = NULL_TREE;
1631 : :
1632 : 7104892 : return scope;
1633 : : }
1634 : :
1635 : : /* Begin a for-statement. Returns a new FOR_STMT.
1636 : : SCOPE and INIT should be the return of begin_for_scope,
1637 : : or both NULL_TREE */
1638 : :
1639 : : tree
1640 : 6871062 : begin_for_stmt (tree scope, tree init)
1641 : : {
1642 : 6871062 : tree r;
1643 : :
1644 : 6871062 : r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
1645 : : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
1646 : : NULL_TREE, NULL_TREE);
1647 : :
1648 : 6871062 : if (scope == NULL_TREE)
1649 : : {
1650 : 1235039 : gcc_assert (!init);
1651 : 1235039 : scope = begin_for_scope (&init);
1652 : : }
1653 : :
1654 : 6871062 : FOR_INIT_STMT (r) = init;
1655 : 6871062 : FOR_SCOPE (r) = scope;
1656 : :
1657 : 6871062 : return r;
1658 : : }
1659 : :
1660 : : /* Finish the init-statement of a for-statement, which may be
1661 : : given by FOR_STMT. */
1662 : :
1663 : : void
1664 : 6871062 : finish_init_stmt (tree for_stmt)
1665 : : {
1666 : 6871062 : if (processing_template_decl)
1667 : 5433825 : FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
1668 : 6871062 : add_stmt (for_stmt);
1669 : 6871062 : FOR_BODY (for_stmt) = do_pushlevel (sk_block);
1670 : 6871062 : begin_cond (&FOR_COND (for_stmt));
1671 : 6871062 : }
1672 : :
1673 : : /* Finish the COND of a for-statement, which may be given by
1674 : : FOR_STMT. */
1675 : :
1676 : : void
1677 : 6871062 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
1678 : : bool novector)
1679 : : {
1680 : 6871062 : cond = maybe_convert_cond (cond);
1681 : 6871062 : finish_cond (&FOR_COND (for_stmt), cond);
1682 : 6871062 : begin_maybe_infinite_loop (cond);
1683 : 6871062 : if (ivdep && cond != error_mark_node)
1684 : 68 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1685 : 34 : TREE_TYPE (FOR_COND (for_stmt)),
1686 : 34 : FOR_COND (for_stmt),
1687 : : build_int_cst (integer_type_node,
1688 : : annot_expr_ivdep_kind),
1689 : : integer_zero_node);
1690 : 6871062 : if (unroll && cond != error_mark_node)
1691 : 408 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1692 : 204 : TREE_TYPE (FOR_COND (for_stmt)),
1693 : 204 : FOR_COND (for_stmt),
1694 : : build_int_cst (integer_type_node,
1695 : : annot_expr_unroll_kind),
1696 : : unroll);
1697 : 6871062 : if (novector && cond && cond != error_mark_node)
1698 : 268 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1699 : 134 : TREE_TYPE (FOR_COND (for_stmt)),
1700 : 134 : FOR_COND (for_stmt),
1701 : : build_int_cst (integer_type_node,
1702 : : annot_expr_no_vector_kind),
1703 : : integer_zero_node);
1704 : 6871062 : adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
1705 : : &FOR_COND_CLEANUP (for_stmt));
1706 : 6871062 : }
1707 : :
1708 : : /* Finish the increment-EXPRESSION in a for-statement, which may be
1709 : : given by FOR_STMT. */
1710 : :
1711 : : void
1712 : 6865166 : finish_for_expr (tree expr, tree for_stmt)
1713 : : {
1714 : 6865166 : if (!expr)
1715 : : return;
1716 : : /* If EXPR is an overloaded function, issue an error; there is no
1717 : : context available to use to perform overload resolution. */
1718 : 6483108 : if (type_unknown_p (expr))
1719 : : {
1720 : 6 : cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1721 : 6 : expr = error_mark_node;
1722 : : }
1723 : 6483108 : if (!processing_template_decl)
1724 : : {
1725 : 1372448 : if (warn_sequence_point)
1726 : 14392 : verify_sequence_points (expr);
1727 : 1372448 : expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1728 : : tf_warning_or_error);
1729 : : }
1730 : 5110660 : else if (!type_dependent_expression_p (expr))
1731 : 1975452 : convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
1732 : 6483108 : expr = maybe_cleanup_point_expr_void (expr);
1733 : 6483108 : if (check_for_bare_parameter_packs (expr))
1734 : 0 : expr = error_mark_node;
1735 : 6483108 : FOR_EXPR (for_stmt) = expr;
1736 : : }
1737 : :
1738 : : /* During parsing of the body, range for uses "__for_{range,begin,end} "
1739 : : decl names to make those unaccessible by code in the body.
1740 : : Find those decls and store into RANGE_FOR_DECL array, so that they
1741 : : can be changed later to ones with underscore instead of space, so that
1742 : : it can be inspected in the debugger. */
1743 : :
1744 : : void
1745 : 7105005 : find_range_for_decls (tree range_for_decl[3])
1746 : : {
1747 : 7105005 : gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 1
1748 : : && CPTI_FOR_END__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 2
1749 : : && CPTI_FOR_RANGE_IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 3
1750 : : && CPTI_FOR_BEGIN_IDENTIFIER == CPTI_FOR_BEGIN__IDENTIFIER + 3
1751 : : && CPTI_FOR_END_IDENTIFIER == CPTI_FOR_END__IDENTIFIER + 3);
1752 : 28420020 : for (int i = 0; i < 3; i++)
1753 : : {
1754 : 21315015 : tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1755 : 21315015 : if (IDENTIFIER_BINDING (id)
1756 : 21315015 : && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1757 : : {
1758 : 208861 : range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1759 : 208861 : gcc_assert (VAR_P (range_for_decl[i])
1760 : : && DECL_ARTIFICIAL (range_for_decl[i]));
1761 : : }
1762 : : }
1763 : 7105005 : }
1764 : :
1765 : : /* Finish the body of a for-statement, which may be given by
1766 : : FOR_STMT. The increment-EXPR for the loop must be
1767 : : provided.
1768 : : It can also finish RANGE_FOR_STMT. */
1769 : :
1770 : : void
1771 : 7104892 : finish_for_stmt (tree for_stmt)
1772 : : {
1773 : 7104892 : end_maybe_infinite_loop (boolean_true_node);
1774 : :
1775 : 7104892 : if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1776 : 233830 : RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1777 : : else
1778 : : {
1779 : 6871062 : if (FOR_COND_PREP (for_stmt))
1780 : 174 : finish_loop_cond_prep (&FOR_BODY (for_stmt),
1781 : : &FOR_COND_PREP (for_stmt),
1782 : 174 : FOR_COND_CLEANUP (for_stmt));
1783 : : else
1784 : 6870888 : FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1785 : 6871062 : if (FOR_COND (for_stmt))
1786 : 6580232 : finish_loop_cond (&FOR_COND (for_stmt),
1787 : 6580232 : FOR_EXPR (for_stmt) ? integer_one_node
1788 : 135228 : : FOR_BODY (for_stmt));
1789 : : }
1790 : :
1791 : : /* Pop the scope for the body of the loop. */
1792 : 7104892 : tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1793 : 7104892 : ? &RANGE_FOR_SCOPE (for_stmt)
1794 : 6871062 : : &FOR_SCOPE (for_stmt));
1795 : 7104892 : tree scope = *scope_ptr;
1796 : 7104892 : *scope_ptr = NULL;
1797 : :
1798 : : /* During parsing of the body, range for uses "__for_{range,begin,end} "
1799 : : decl names to make those unaccessible by code in the body.
1800 : : Change it to ones with underscore instead of space, so that it can
1801 : : be inspected in the debugger. */
1802 : 7104892 : tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1803 : 7104892 : find_range_for_decls (range_for_decl);
1804 : :
1805 : 7104892 : add_stmt (do_poplevel (scope));
1806 : :
1807 : : /* If we're being called from build_vec_init, don't mess with the names of
1808 : : the variables for an enclosing range-for. */
1809 : 7104892 : if (!stmts_are_full_exprs_p ())
1810 : 5896 : return;
1811 : :
1812 : 28395984 : for (int i = 0; i < 3; i++)
1813 : 21296988 : if (range_for_decl[i])
1814 : 208745 : DECL_NAME (range_for_decl[i])
1815 : 208745 : = cp_global_trees[CPTI_FOR_RANGE_IDENTIFIER + i];
1816 : : }
1817 : :
1818 : : /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1819 : : SCOPE and INIT should be the return of begin_for_scope,
1820 : : or both NULL_TREE .
1821 : : To finish it call finish_for_stmt(). */
1822 : :
1823 : : tree
1824 : 233830 : begin_range_for_stmt (tree scope, tree init)
1825 : : {
1826 : 233830 : begin_maybe_infinite_loop (boolean_false_node);
1827 : :
1828 : 233830 : tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1829 : : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1830 : :
1831 : 233830 : if (scope == NULL_TREE)
1832 : : {
1833 : 6 : gcc_assert (!init);
1834 : 6 : scope = begin_for_scope (&init);
1835 : : }
1836 : :
1837 : : /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1838 : 233830 : RANGE_FOR_INIT_STMT (r) = init;
1839 : 233830 : RANGE_FOR_SCOPE (r) = scope;
1840 : :
1841 : 233830 : return r;
1842 : : }
1843 : :
1844 : : /* Finish the head of a range-based for statement, which may
1845 : : be given by RANGE_FOR_STMT. DECL must be the declaration
1846 : : and EXPR must be the loop expression. */
1847 : :
1848 : : void
1849 : 233830 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1850 : : {
1851 : 233830 : if (processing_template_decl)
1852 : 467660 : RANGE_FOR_INIT_STMT (range_for_stmt)
1853 : 467660 : = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1854 : 233830 : RANGE_FOR_DECL (range_for_stmt) = decl;
1855 : 233830 : RANGE_FOR_EXPR (range_for_stmt) = expr;
1856 : 233830 : add_stmt (range_for_stmt);
1857 : 233830 : RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1858 : 233830 : }
1859 : :
1860 : : /* Begin the scope of an expansion-statement. */
1861 : :
1862 : : tree
1863 : 1113 : begin_template_for_scope (tree *init)
1864 : : {
1865 : 1113 : tree scope = do_pushlevel (sk_template_for);
1866 : :
1867 : 1113 : if (processing_template_decl)
1868 : 351 : *init = push_stmt_list ();
1869 : : else
1870 : 762 : *init = NULL_TREE;
1871 : :
1872 : 1113 : return scope;
1873 : : }
1874 : :
1875 : : /* Finish a break-statement. */
1876 : :
1877 : : tree
1878 : 3666872 : finish_break_stmt (void)
1879 : : {
1880 : : /* In switch statements break is sometimes stylistically used after
1881 : : a return statement. This can lead to spurious warnings about
1882 : : control reaching the end of a non-void function when it is
1883 : : inlined. Note that we are calling block_may_fallthru with
1884 : : language specific tree nodes; this works because
1885 : : block_may_fallthru returns true when given something it does not
1886 : : understand. */
1887 : 3666872 : if (!block_may_fallthru (cur_stmt_list))
1888 : 791 : return void_node;
1889 : 3666081 : note_break_stmt ();
1890 : 3666081 : return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
1891 : : }
1892 : :
1893 : : /* Finish a continue-statement. */
1894 : :
1895 : : tree
1896 : 168709 : finish_continue_stmt (void)
1897 : : {
1898 : 168709 : return add_stmt (build_stmt (input_location, CONTINUE_STMT, NULL_TREE));
1899 : : }
1900 : :
1901 : : /* Begin a switch-statement. Returns a new SWITCH_STMT if
1902 : : appropriate. */
1903 : :
1904 : : tree
1905 : 534553 : begin_switch_stmt (void)
1906 : : {
1907 : 534553 : tree r, scope;
1908 : :
1909 : 534553 : scope = do_pushlevel (sk_cond);
1910 : 534553 : r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1911 : : scope, NULL_TREE);
1912 : :
1913 : 534553 : begin_cond (&SWITCH_STMT_COND (r));
1914 : :
1915 : 534553 : return r;
1916 : : }
1917 : :
1918 : : /* Finish the cond of a switch-statement. */
1919 : :
1920 : : void
1921 : 534553 : finish_switch_cond (tree cond, tree switch_stmt)
1922 : : {
1923 : 534553 : tree orig_type = NULL;
1924 : :
1925 : 534553 : if (!processing_template_decl)
1926 : : {
1927 : : /* Convert the condition to an integer or enumeration type. */
1928 : 328300 : tree orig_cond = cond;
1929 : : /* For structured binding used in condition, the conversion needs to be
1930 : : evaluated before the individual variables are initialized in the
1931 : : std::tuple_{size,elemenet} case. cp_finish_decomp saved the
1932 : : conversion result in a TARGET_EXPR, pick it up from there. */
1933 : 122 : if (DECL_DECOMPOSITION_P (cond)
1934 : 57 : && DECL_DECOMP_IS_BASE (cond)
1935 : 57 : && DECL_DECOMP_BASE (cond)
1936 : 328354 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1937 : 18 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1938 : 328300 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1939 : 328300 : if (cond == NULL_TREE)
1940 : : {
1941 : 42 : error_at (cp_expr_loc_or_input_loc (orig_cond),
1942 : : "switch quantity not an integer");
1943 : 27 : cond = error_mark_node;
1944 : : }
1945 : : /* We want unlowered type here to handle enum bit-fields. */
1946 : 328300 : orig_type = unlowered_expr_type (cond);
1947 : 328300 : if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1948 : 185473 : orig_type = TREE_TYPE (cond);
1949 : 328300 : if (cond != error_mark_node)
1950 : : {
1951 : : /* [stmt.switch]
1952 : :
1953 : : Integral promotions are performed. */
1954 : 328267 : cond = perform_integral_promotions (cond);
1955 : 328267 : cond = maybe_cleanup_point_expr (cond);
1956 : : }
1957 : : }
1958 : 534553 : if (check_for_bare_parameter_packs (cond))
1959 : 0 : cond = error_mark_node;
1960 : 534553 : else if (!processing_template_decl && warn_sequence_point)
1961 : 2615 : verify_sequence_points (cond);
1962 : :
1963 : 534553 : finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1964 : 534553 : SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1965 : 534553 : add_stmt (switch_stmt);
1966 : 534553 : push_switch (switch_stmt);
1967 : 534553 : SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1968 : 534553 : }
1969 : :
1970 : : /* Finish the body of a switch-statement, which may be given by
1971 : : SWITCH_STMT. The COND to switch on is indicated. */
1972 : :
1973 : : void
1974 : 534553 : finish_switch_stmt (tree switch_stmt)
1975 : : {
1976 : 534553 : tree scope;
1977 : :
1978 : 1069106 : SWITCH_STMT_BODY (switch_stmt) =
1979 : 534553 : pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1980 : 534553 : pop_switch ();
1981 : :
1982 : 534553 : scope = SWITCH_STMT_SCOPE (switch_stmt);
1983 : 534553 : SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1984 : 534553 : add_stmt (do_poplevel (scope));
1985 : 534553 : }
1986 : :
1987 : : /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1988 : : appropriate. */
1989 : :
1990 : : tree
1991 : 1184058 : begin_try_block (void)
1992 : : {
1993 : 1184058 : tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1994 : 1184058 : add_stmt (r);
1995 : 1184058 : TRY_STMTS (r) = push_stmt_list ();
1996 : 1184058 : return r;
1997 : : }
1998 : :
1999 : : /* Likewise, for a function-try-block. The block returned in
2000 : : *COMPOUND_STMT is an artificial outer scope, containing the
2001 : : function-try-block. */
2002 : :
2003 : : tree
2004 : 339 : begin_function_try_block (tree *compound_stmt)
2005 : : {
2006 : 339 : tree r;
2007 : : /* This outer scope does not exist in the C++ standard, but we need
2008 : : a place to put __FUNCTION__ and similar variables. */
2009 : 339 : *compound_stmt = begin_compound_stmt (0);
2010 : 339 : current_binding_level->artificial = 1;
2011 : 339 : r = begin_try_block ();
2012 : 339 : FN_TRY_BLOCK_P (r) = 1;
2013 : 339 : return r;
2014 : : }
2015 : :
2016 : : /* Finish a try-block, which may be given by TRY_BLOCK. */
2017 : :
2018 : : void
2019 : 1184058 : finish_try_block (tree try_block)
2020 : : {
2021 : 1184058 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2022 : 1184058 : TRY_HANDLERS (try_block) = push_stmt_list ();
2023 : 1184058 : }
2024 : :
2025 : : /* Finish the body of a cleanup try-block, which may be given by
2026 : : TRY_BLOCK. */
2027 : :
2028 : : void
2029 : 0 : finish_cleanup_try_block (tree try_block)
2030 : : {
2031 : 0 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2032 : 0 : }
2033 : :
2034 : : /* Finish an implicitly generated try-block, with a cleanup is given
2035 : : by CLEANUP. */
2036 : :
2037 : : void
2038 : 0 : finish_cleanup (tree cleanup, tree try_block)
2039 : : {
2040 : 0 : TRY_HANDLERS (try_block) = cleanup;
2041 : 0 : CLEANUP_P (try_block) = 1;
2042 : 0 : }
2043 : :
2044 : : /* Likewise, for a function-try-block. */
2045 : :
2046 : : void
2047 : 339 : finish_function_try_block (tree try_block)
2048 : : {
2049 : 339 : finish_try_block (try_block);
2050 : : /* FIXME : something queer about CTOR_INITIALIZER somehow following
2051 : : the try block, but moving it inside. */
2052 : 339 : in_function_try_handler = 1;
2053 : 339 : }
2054 : :
2055 : : /* Finish a handler-sequence for a try-block, which may be given by
2056 : : TRY_BLOCK. */
2057 : :
2058 : : void
2059 : 1184058 : finish_handler_sequence (tree try_block)
2060 : : {
2061 : 1184058 : TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
2062 : 1184058 : check_handlers (TRY_HANDLERS (try_block));
2063 : 1184058 : }
2064 : :
2065 : : /* Finish the handler-seq for a function-try-block, given by
2066 : : TRY_BLOCK. COMPOUND_STMT is the outer block created by
2067 : : begin_function_try_block. */
2068 : :
2069 : : void
2070 : 339 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
2071 : : {
2072 : 339 : in_function_try_handler = 0;
2073 : 339 : finish_handler_sequence (try_block);
2074 : 339 : finish_compound_stmt (compound_stmt);
2075 : 339 : }
2076 : :
2077 : : /* Begin a handler. Returns a HANDLER if appropriate. */
2078 : :
2079 : : tree
2080 : 1657624 : begin_handler (void)
2081 : : {
2082 : 1657624 : tree r;
2083 : :
2084 : 1657624 : r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
2085 : 1657624 : add_stmt (r);
2086 : :
2087 : : /* Create a binding level for the eh_info and the exception object
2088 : : cleanup. */
2089 : 1657624 : HANDLER_BODY (r) = do_pushlevel (sk_catch);
2090 : :
2091 : 1657624 : return r;
2092 : : }
2093 : :
2094 : : /* Finish the handler-parameters for a handler, which may be given by
2095 : : HANDLER. DECL is the declaration for the catch parameter, or NULL
2096 : : if this is a `catch (...)' clause. */
2097 : :
2098 : : void
2099 : 1657624 : finish_handler_parms (tree decl, tree handler)
2100 : : {
2101 : 1657624 : tree type = NULL_TREE;
2102 : 1657624 : if (processing_template_decl)
2103 : : {
2104 : 1508469 : if (decl)
2105 : : {
2106 : 498105 : decl = pushdecl (decl);
2107 : 498105 : decl = push_template_decl (decl);
2108 : 498105 : HANDLER_PARMS (handler) = decl;
2109 : 498105 : type = TREE_TYPE (decl);
2110 : : }
2111 : : }
2112 : : else
2113 : : {
2114 : 149155 : type = expand_start_catch_block (decl);
2115 : 149155 : if (warn_catch_value
2116 : 2079 : && type != NULL_TREE
2117 : 708 : && type != error_mark_node
2118 : 149863 : && !TYPE_REF_P (TREE_TYPE (decl)))
2119 : : {
2120 : 210 : tree orig_type = TREE_TYPE (decl);
2121 : 210 : if (CLASS_TYPE_P (orig_type))
2122 : : {
2123 : 96 : if (TYPE_POLYMORPHIC_P (orig_type))
2124 : 48 : warning_at (DECL_SOURCE_LOCATION (decl),
2125 : 48 : OPT_Wcatch_value_,
2126 : : "catching polymorphic type %q#T by value",
2127 : : orig_type);
2128 : 48 : else if (warn_catch_value > 1)
2129 : 36 : warning_at (DECL_SOURCE_LOCATION (decl),
2130 : 36 : OPT_Wcatch_value_,
2131 : : "catching type %q#T by value", orig_type);
2132 : : }
2133 : 114 : else if (warn_catch_value > 2)
2134 : 54 : warning_at (DECL_SOURCE_LOCATION (decl),
2135 : 54 : OPT_Wcatch_value_,
2136 : : "catching non-reference type %q#T", orig_type);
2137 : : }
2138 : : }
2139 : 1657624 : HANDLER_TYPE (handler) = type;
2140 : 1657624 : }
2141 : :
2142 : : /* Finish a handler, which may be given by HANDLER. The BLOCKs are
2143 : : the return value from the matching call to finish_handler_parms. */
2144 : :
2145 : : void
2146 : 1657624 : finish_handler (tree handler)
2147 : : {
2148 : 1657624 : if (!processing_template_decl)
2149 : 149155 : expand_end_catch_block ();
2150 : 1657624 : HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
2151 : 1657624 : }
2152 : :
2153 : : /* Begin a compound statement. FLAGS contains some bits that control the
2154 : : behavior and context. If BCS_NO_SCOPE is set, the compound statement
2155 : : does not define a scope. If BCS_FN_BODY is set, this is the outermost
2156 : : block of a function. If BCS_TRY_BLOCK is set, this is the block
2157 : : created on behalf of a TRY statement. Returns a token to be passed to
2158 : : finish_compound_stmt. */
2159 : :
2160 : : tree
2161 : 246423773 : begin_compound_stmt (unsigned int flags)
2162 : : {
2163 : 246423773 : tree r;
2164 : :
2165 : 246423773 : if (flags & BCS_NO_SCOPE)
2166 : : {
2167 : 4381721 : r = push_stmt_list ();
2168 : 4381721 : STATEMENT_LIST_NO_SCOPE (r) = 1;
2169 : :
2170 : : /* Normally, we try hard to keep the BLOCK for a statement-expression.
2171 : : But, if it's a statement-expression with a scopeless block, there's
2172 : : nothing to keep, and we don't want to accidentally keep a block
2173 : : *inside* the scopeless block. */
2174 : 4381721 : keep_next_level (false);
2175 : : }
2176 : : else
2177 : : {
2178 : 242042052 : scope_kind sk = sk_block;
2179 : 242042052 : if (flags & BCS_TRY_BLOCK)
2180 : : sk = sk_try;
2181 : 240857994 : else if (flags & BCS_TRANSACTION)
2182 : : sk = sk_transaction;
2183 : 240857759 : else if (flags & BCS_STMT_EXPR)
2184 : 29076 : sk = sk_stmt_expr;
2185 : 242042052 : r = do_pushlevel (sk);
2186 : : }
2187 : :
2188 : : /* When processing a template, we need to remember where the braces were,
2189 : : so that we can set up identical scopes when instantiating the template
2190 : : later. BIND_EXPR is a handy candidate for this.
2191 : : Note that do_poplevel won't create a BIND_EXPR itself here (and thus
2192 : : result in nested BIND_EXPRs), since we don't build BLOCK nodes when
2193 : : processing templates. */
2194 : 246423773 : if (processing_template_decl)
2195 : : {
2196 : 164634782 : r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
2197 : 164634782 : BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
2198 : 164634782 : BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
2199 : 164634782 : TREE_SIDE_EFFECTS (r) = 1;
2200 : : }
2201 : :
2202 : 246423773 : return r;
2203 : : }
2204 : :
2205 : : /* Finish a compound-statement, which is given by STMT. */
2206 : :
2207 : : void
2208 : 246423734 : finish_compound_stmt (tree stmt)
2209 : : {
2210 : 246423734 : if (TREE_CODE (stmt) == BIND_EXPR)
2211 : : {
2212 : 164634782 : tree body = do_poplevel (BIND_EXPR_BODY (stmt));
2213 : : /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
2214 : : discard the BIND_EXPR so it can be merged with the containing
2215 : : STATEMENT_LIST. */
2216 : 164634782 : if (TREE_CODE (body) == STATEMENT_LIST
2217 : 150730542 : && STATEMENT_LIST_HEAD (body) == NULL
2218 : 10907810 : && !BIND_EXPR_BODY_BLOCK (stmt)
2219 : 175024331 : && !BIND_EXPR_TRY_BLOCK (stmt))
2220 : : stmt = body;
2221 : : else
2222 : 154245336 : BIND_EXPR_BODY (stmt) = body;
2223 : : }
2224 : 81788952 : else if (STATEMENT_LIST_NO_SCOPE (stmt))
2225 : 4371176 : stmt = pop_stmt_list (stmt);
2226 : : else
2227 : : {
2228 : : /* Destroy any ObjC "super" receivers that may have been
2229 : : created. */
2230 : 77417776 : objc_clear_super_receiver ();
2231 : :
2232 : 77417776 : stmt = do_poplevel (stmt);
2233 : : }
2234 : :
2235 : : /* ??? See c_end_compound_stmt wrt statement expressions. */
2236 : 246423734 : add_stmt (stmt);
2237 : 246423734 : }
2238 : :
2239 : : /* Finish an asm string literal, which can be a string literal
2240 : : or parenthesized constant expression. Extract the string literal
2241 : : from the latter. */
2242 : :
2243 : : tree
2244 : 52242 : finish_asm_string_expression (location_t loc, tree string)
2245 : : {
2246 : 52242 : if (string == error_mark_node
2247 : 52229 : || TREE_CODE (string) == STRING_CST
2248 : 871 : || processing_template_decl)
2249 : : return string;
2250 : 564 : string = cxx_constant_value (string, tf_error);
2251 : 564 : if (TREE_CODE (string) == STRING_CST)
2252 : 10 : string = build1_loc (loc, PAREN_EXPR, TREE_TYPE (string),
2253 : : string);
2254 : 564 : cexpr_str cstr (string);
2255 : 564 : if (!cstr.type_check (loc))
2256 : 171 : return error_mark_node;
2257 : 393 : if (!cstr.extract (loc, string))
2258 : 62 : string = error_mark_node;
2259 : 393 : return string;
2260 : 564 : }
2261 : :
2262 : : /* Finish an asm-statement, whose components are a STRING, some
2263 : : OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
2264 : : LABELS. Also note whether the asm-statement should be
2265 : : considered volatile, and whether it is asm inline. TOPLEV_P
2266 : : is true if finishing namespace scope extended asm. */
2267 : :
2268 : : tree
2269 : 29520 : finish_asm_stmt (location_t loc, int volatile_p, tree string,
2270 : : tree output_operands, tree input_operands, tree clobbers,
2271 : : tree labels, bool inline_p, bool toplev_p)
2272 : : {
2273 : 29520 : tree r;
2274 : 29520 : tree t;
2275 : 29520 : int ninputs = list_length (input_operands);
2276 : 29520 : int noutputs = list_length (output_operands);
2277 : :
2278 : 29520 : if (!processing_template_decl)
2279 : : {
2280 : 12075 : const char *constraint;
2281 : 12075 : const char **oconstraints;
2282 : 12075 : bool allows_mem, allows_reg, is_inout;
2283 : 12075 : tree operand;
2284 : 12075 : int i;
2285 : :
2286 : 12075 : oconstraints = XALLOCAVEC (const char *, noutputs);
2287 : :
2288 : 24048 : string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
2289 : : string);
2290 : 12075 : if (string == error_mark_node)
2291 : 109 : return error_mark_node;
2292 : 35943 : for (int i = 0; i < 2; ++i)
2293 : 82111 : for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
2294 : : {
2295 : 34187 : tree s = TREE_VALUE (TREE_PURPOSE (t));
2296 : 68356 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2297 : 34187 : if (s == error_mark_node)
2298 : : return error_mark_node;
2299 : 34157 : TREE_VALUE (TREE_PURPOSE (t)) = s;
2300 : : }
2301 : 17358 : for (t = clobbers; t; t = TREE_CHAIN (t))
2302 : : {
2303 : 5392 : tree s = TREE_VALUE (t);
2304 : 10778 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2305 : 5392 : TREE_VALUE (t) = s;
2306 : : }
2307 : :
2308 : 11966 : string = resolve_asm_operand_names (string, output_operands,
2309 : : input_operands, labels);
2310 : :
2311 : 29817 : for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
2312 : : {
2313 : 17851 : operand = TREE_VALUE (t);
2314 : :
2315 : : /* ??? Really, this should not be here. Users should be using a
2316 : : proper lvalue, dammit. But there's a long history of using
2317 : : casts in the output operands. In cases like longlong.h, this
2318 : : becomes a primitive form of typechecking -- if the cast can be
2319 : : removed, then the output operand had a type of the proper width;
2320 : : otherwise we'll get an error. Gross, but ... */
2321 : 17851 : STRIP_NOPS (operand);
2322 : :
2323 : 17851 : operand = mark_lvalue_use (operand);
2324 : :
2325 : 17851 : if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
2326 : 9 : operand = error_mark_node;
2327 : :
2328 : 17851 : if (operand != error_mark_node
2329 : 17851 : && (TREE_READONLY (operand)
2330 : 17836 : || CP_TYPE_CONST_P (TREE_TYPE (operand))
2331 : : /* Functions are not modifiable, even though they are
2332 : : lvalues. */
2333 : 17836 : || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand))
2334 : : /* If it's an aggregate and any field is const, then it is
2335 : : effectively const. */
2336 : 17836 : || (CLASS_TYPE_P (TREE_TYPE (operand))
2337 : 32 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
2338 : 6 : cxx_readonly_error (loc, operand, lv_asm);
2339 : :
2340 : : tree *op = &operand;
2341 : 17858 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2342 : 7 : op = &TREE_OPERAND (*op, 1);
2343 : 17851 : switch (TREE_CODE (*op))
2344 : : {
2345 : 30 : case PREINCREMENT_EXPR:
2346 : 30 : case PREDECREMENT_EXPR:
2347 : 30 : case MODIFY_EXPR:
2348 : 30 : *op = genericize_compound_lvalue (*op);
2349 : 30 : op = &TREE_OPERAND (*op, 1);
2350 : 30 : break;
2351 : : default:
2352 : : break;
2353 : : }
2354 : :
2355 : 17851 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2356 : 17851 : oconstraints[i] = constraint;
2357 : :
2358 : 17851 : if (parse_output_constraint (&constraint, i, ninputs, noutputs,
2359 : : &allows_mem, &allows_reg, &is_inout,
2360 : : nullptr))
2361 : : {
2362 : : /* If the operand is going to end up in memory,
2363 : : mark it addressable. */
2364 : 17842 : if (!allows_reg && !cxx_mark_addressable (*op))
2365 : 0 : operand = error_mark_node;
2366 : 17842 : if (allows_reg && toplev_p)
2367 : : {
2368 : 3 : error_at (loc, "constraint allows registers outside of "
2369 : : "a function");
2370 : 3 : operand = error_mark_node;
2371 : : }
2372 : : }
2373 : : else
2374 : 9 : operand = error_mark_node;
2375 : :
2376 : 306 : if (toplev_p && operand != error_mark_node)
2377 : : {
2378 : 21 : if (TREE_SIDE_EFFECTS (operand))
2379 : : {
2380 : 0 : error_at (loc, "side-effects in output operand outside "
2381 : : "of a function");
2382 : 0 : operand = error_mark_node;
2383 : : }
2384 : : else
2385 : : {
2386 : 21 : tree addr
2387 : 21 : = cp_build_addr_expr (operand, tf_warning_or_error);
2388 : 21 : if (addr == error_mark_node)
2389 : 0 : operand = error_mark_node;
2390 : : else
2391 : : {
2392 : 21 : addr = maybe_constant_value (addr);
2393 : 21 : if (!initializer_constant_valid_p (addr,
2394 : 21 : TREE_TYPE (addr)))
2395 : : {
2396 : 3 : error_at (loc, "output operand outside of a "
2397 : : "function is not constant");
2398 : 3 : operand = error_mark_node;
2399 : : }
2400 : : else
2401 : 18 : operand = build_fold_indirect_ref (addr);
2402 : : }
2403 : : }
2404 : : }
2405 : 17830 : else if (operand != error_mark_node && strstr (constraint, "-"))
2406 : : {
2407 : 3 : error_at (loc, "%<-%> modifier used inside of a function");
2408 : 3 : operand = error_mark_node;
2409 : : }
2410 : :
2411 : 17851 : TREE_VALUE (t) = operand;
2412 : : }
2413 : :
2414 : 28267 : for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
2415 : : {
2416 : 16301 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2417 : 16301 : bool constraint_parsed
2418 : 16301 : = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
2419 : : oconstraints, &allows_mem, &allows_reg,
2420 : : nullptr);
2421 : : /* If the operand is going to end up in memory, don't call
2422 : : decay_conversion. */
2423 : 16301 : if (constraint_parsed && !allows_reg && allows_mem)
2424 : 164 : operand = mark_lvalue_use (TREE_VALUE (t));
2425 : : else
2426 : 16137 : operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error);
2427 : :
2428 : : /* If the type of the operand hasn't been determined (e.g.,
2429 : : because it involves an overloaded function), then issue
2430 : : an error message. There's no context available to
2431 : : resolve the overloading. */
2432 : 16301 : if (TREE_TYPE (operand) == unknown_type_node)
2433 : : {
2434 : 3 : error_at (loc,
2435 : : "type of %<asm%> operand %qE could not be determined",
2436 : 3 : TREE_VALUE (t));
2437 : 3 : operand = error_mark_node;
2438 : : }
2439 : :
2440 : 16301 : if (constraint_parsed)
2441 : : {
2442 : : /* If the operand is going to end up in memory,
2443 : : mark it addressable. */
2444 : 16283 : if (!allows_reg && allows_mem)
2445 : : {
2446 : : /* Strip the nops as we allow this case. FIXME, this really
2447 : : should be rejected or made deprecated. */
2448 : 164 : STRIP_NOPS (operand);
2449 : :
2450 : 164 : tree *op = &operand;
2451 : 171 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2452 : 7 : op = &TREE_OPERAND (*op, 1);
2453 : 164 : switch (TREE_CODE (*op))
2454 : : {
2455 : 27 : case PREINCREMENT_EXPR:
2456 : 27 : case PREDECREMENT_EXPR:
2457 : 27 : case MODIFY_EXPR:
2458 : 27 : *op = genericize_compound_lvalue (*op);
2459 : 27 : op = &TREE_OPERAND (*op, 1);
2460 : 27 : break;
2461 : : default:
2462 : : break;
2463 : : }
2464 : :
2465 : 164 : if (!cxx_mark_addressable (*op))
2466 : 0 : operand = error_mark_node;
2467 : : }
2468 : 16119 : else if (!allows_reg && !allows_mem)
2469 : : {
2470 : : /* If constraint allows neither register nor memory,
2471 : : try harder to get a constant. */
2472 : 471 : tree constop = maybe_constant_value (operand);
2473 : 471 : if (TREE_CONSTANT (constop))
2474 : 444 : operand = constop;
2475 : : }
2476 : 16283 : if (allows_reg && toplev_p)
2477 : : {
2478 : 3 : error_at (loc, "constraint allows registers outside of "
2479 : : "a function");
2480 : 3 : operand = error_mark_node;
2481 : : }
2482 : 16283 : if (constraint[0] == ':' && operand != error_mark_node)
2483 : : {
2484 : 45 : tree t = operand;
2485 : 45 : STRIP_NOPS (t);
2486 : 45 : if (TREE_CODE (t) != ADDR_EXPR
2487 : 45 : || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
2488 : 30 : || (VAR_P (TREE_OPERAND (t, 0))
2489 : 24 : && is_global_var (TREE_OPERAND (t, 0)))))
2490 : : {
2491 : 15 : error_at (loc, "%<:%> constraint operand is not address "
2492 : : "of a function or non-automatic variable");
2493 : 15 : operand = error_mark_node;
2494 : : }
2495 : : }
2496 : : }
2497 : : else
2498 : 18 : operand = error_mark_node;
2499 : :
2500 : 16301 : if (toplev_p && operand != error_mark_node)
2501 : : {
2502 : 114 : if (TREE_SIDE_EFFECTS (operand))
2503 : : {
2504 : 6 : error_at (loc, "side-effects in input operand outside "
2505 : : "of a function");
2506 : 6 : operand = error_mark_node;
2507 : : }
2508 : 108 : else if (allows_mem && lvalue_or_else (operand, lv_asm, tf_none))
2509 : : {
2510 : 21 : tree addr = cp_build_addr_expr (operand, tf_warning_or_error);
2511 : 21 : if (addr == error_mark_node)
2512 : 0 : operand = error_mark_node;
2513 : : else
2514 : : {
2515 : 21 : addr = maybe_constant_value (addr);
2516 : 21 : if (!initializer_constant_valid_p (addr,
2517 : 21 : TREE_TYPE (addr)))
2518 : : {
2519 : 3 : error_at (loc, "input operand outside of a "
2520 : : "function is not constant");
2521 : 3 : operand = error_mark_node;
2522 : : }
2523 : : else
2524 : 18 : operand = build_fold_indirect_ref (addr);
2525 : : }
2526 : : }
2527 : : else
2528 : : {
2529 : 87 : operand = maybe_constant_value (operand);
2530 : 87 : if (!initializer_constant_valid_p (operand,
2531 : 87 : TREE_TYPE (operand)))
2532 : : {
2533 : 3 : error_at (loc, "input operand outside of a "
2534 : : "function is not constant");
2535 : 3 : operand = error_mark_node;
2536 : : }
2537 : : }
2538 : : }
2539 : 16187 : else if (operand != error_mark_node && strstr (constraint, "-"))
2540 : : {
2541 : 9 : error_at (loc, "%<-%> modifier used inside of a function");
2542 : 9 : operand = error_mark_node;
2543 : : }
2544 : :
2545 : 16301 : TREE_VALUE (t) = operand;
2546 : : }
2547 : : }
2548 : :
2549 : 29411 : r = build_stmt (loc, ASM_EXPR, string,
2550 : : output_operands, input_operands,
2551 : : clobbers, labels);
2552 : 29411 : ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
2553 : 29411 : ASM_INLINE_P (r) = inline_p;
2554 : 29411 : if (toplev_p)
2555 : : {
2556 : 96 : symtab->finalize_toplevel_asm (r);
2557 : 96 : return r;
2558 : : }
2559 : 29315 : r = maybe_cleanup_point_expr_void (r);
2560 : 29315 : return add_stmt (r);
2561 : : }
2562 : :
2563 : : /* Finish a label with the indicated NAME. Returns the new label. */
2564 : :
2565 : : tree
2566 : 2474 : finish_label_stmt (tree name)
2567 : : {
2568 : 2474 : tree decl = define_label (input_location, name);
2569 : :
2570 : 2474 : if (decl == error_mark_node)
2571 : : return error_mark_node;
2572 : :
2573 : 2468 : add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
2574 : :
2575 : 2468 : return decl;
2576 : : }
2577 : :
2578 : : /* Finish a series of declarations for local labels. G++ allows users
2579 : : to declare "local" labels, i.e., labels with scope. This extension
2580 : : is useful when writing code involving statement-expressions. */
2581 : :
2582 : : void
2583 : 219 : finish_label_decl (tree name)
2584 : : {
2585 : 219 : if (!at_function_scope_p ())
2586 : : {
2587 : 0 : error ("%<__label__%> declarations are only allowed in function scopes");
2588 : 0 : return;
2589 : : }
2590 : :
2591 : 219 : add_decl_expr (declare_local_label (name));
2592 : : }
2593 : :
2594 : : /* When DECL goes out of scope, make sure that CLEANUP is executed. */
2595 : :
2596 : : void
2597 : 3297716 : finish_decl_cleanup (tree decl, tree cleanup)
2598 : : {
2599 : 3297716 : push_cleanup (decl, cleanup, false);
2600 : 3297716 : }
2601 : :
2602 : : /* If the current scope exits with an exception, run CLEANUP. */
2603 : :
2604 : : void
2605 : 2126519 : finish_eh_cleanup (tree cleanup)
2606 : : {
2607 : 2126519 : push_cleanup (NULL, cleanup, true);
2608 : 2126519 : }
2609 : :
2610 : : /* The MEM_INITS is a list of mem-initializers, in reverse of the
2611 : : order they were written by the user. Each node is as for
2612 : : emit_mem_initializers. */
2613 : :
2614 : : void
2615 : 19003537 : finish_mem_initializers (tree mem_inits)
2616 : : {
2617 : : /* Reorder the MEM_INITS so that they are in the order they appeared
2618 : : in the source program. */
2619 : 19003537 : mem_inits = nreverse (mem_inits);
2620 : :
2621 : 19003537 : if (processing_template_decl)
2622 : : {
2623 : : tree mem;
2624 : :
2625 : 32977994 : for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
2626 : : {
2627 : : /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
2628 : : check for bare parameter packs in the TREE_VALUE, because
2629 : : any parameter packs in the TREE_VALUE have already been
2630 : : bound as part of the TREE_PURPOSE. See
2631 : : make_pack_expansion for more information. */
2632 : 19435992 : if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
2633 : 19435992 : && check_for_bare_parameter_packs (TREE_VALUE (mem)))
2634 : 3 : TREE_VALUE (mem) = error_mark_node;
2635 : : }
2636 : :
2637 : 13542002 : add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
2638 : : CTOR_INITIALIZER, mem_inits));
2639 : : }
2640 : : else
2641 : 5461535 : emit_mem_initializers (mem_inits);
2642 : 19003537 : }
2643 : :
2644 : : /* Obfuscate EXPR if it looks like an id-expression or member access so
2645 : : that the call to finish_decltype in do_auto_deduction will give the
2646 : : right result. If EVEN_UNEVAL, do this even in unevaluated context. */
2647 : :
2648 : : tree
2649 : 35993747 : force_paren_expr (tree expr, bool even_uneval /* = false */)
2650 : : {
2651 : : /* This is only needed for decltype(auto) in C++14. */
2652 : 35993747 : if (cxx_dialect < cxx14)
2653 : : return expr;
2654 : :
2655 : : /* If we're in unevaluated context, we can't be deducing a
2656 : : return/initializer type, so we don't need to mess with this. */
2657 : 35375450 : if (cp_unevaluated_operand && !even_uneval)
2658 : : return expr;
2659 : :
2660 : 31652734 : if (TREE_CODE (expr) == COMPONENT_REF
2661 : 31592888 : || TREE_CODE (expr) == SCOPE_REF
2662 : 63238873 : || REFERENCE_REF_P (expr))
2663 : 477895 : REF_PARENTHESIZED_P (expr) = true;
2664 : 31174839 : else if (DECL_P (tree_strip_any_location_wrapper (expr)))
2665 : : {
2666 : 1952979 : location_t loc = cp_expr_location (expr);
2667 : 1952979 : const tree_code code = processing_template_decl ? PAREN_EXPR
2668 : : : VIEW_CONVERT_EXPR;
2669 : 1952979 : expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
2670 : 1952979 : REF_PARENTHESIZED_P (expr) = true;
2671 : : }
2672 : : return expr;
2673 : : }
2674 : :
2675 : : /* If T is an id-expression obfuscated by force_paren_expr, undo the
2676 : : obfuscation and return the underlying id-expression. Otherwise
2677 : : return T. */
2678 : :
2679 : : tree
2680 : 825739181 : maybe_undo_parenthesized_ref (tree t)
2681 : : {
2682 : 825739181 : if (cxx_dialect < cxx14)
2683 : : return t;
2684 : :
2685 : 816035404 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
2686 : 905964413 : && REF_PARENTHESIZED_P (t))
2687 : 280754 : t = TREE_OPERAND (t, 0);
2688 : :
2689 : : return t;
2690 : : }
2691 : :
2692 : : /* Finish a parenthesized expression EXPR. */
2693 : :
2694 : : cp_expr
2695 : 30111517 : finish_parenthesized_expr (cp_expr expr)
2696 : : {
2697 : 30111517 : if (EXPR_P (expr))
2698 : : {
2699 : : /* This inhibits warnings in maybe_warn_unparenthesized_assignment
2700 : : and c_common_truthvalue_conversion. */
2701 : 59951270 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
2702 : : /* And maybe_warn_sizeof_array_div. */
2703 : 59951270 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
2704 : : }
2705 : :
2706 : 30111517 : if (TREE_CODE (expr) == OFFSET_REF
2707 : 30111517 : || TREE_CODE (expr) == SCOPE_REF)
2708 : : /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
2709 : : enclosed in parentheses. */
2710 : 15454 : PTRMEM_OK_P (expr) = 0;
2711 : :
2712 : 30111517 : tree stripped_expr = tree_strip_any_location_wrapper (expr);
2713 : 30111517 : if (TREE_CODE (stripped_expr) == STRING_CST)
2714 : 882916 : PAREN_STRING_LITERAL_P (stripped_expr) = 1;
2715 : 29228601 : else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
2716 : 2602 : PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
2717 : :
2718 : 30111517 : expr = cp_expr (force_paren_expr (expr), expr.get_location ());
2719 : :
2720 : 30111517 : return expr;
2721 : : }
2722 : :
2723 : : /* Finish a reference to a non-static data member (DECL) that is not
2724 : : preceded by `.' or `->'. */
2725 : :
2726 : : tree
2727 : 67620405 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
2728 : : tsubst_flags_t complain /* = tf_warning_or_error */)
2729 : : {
2730 : 67620405 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
2731 : 67620405 : bool try_omp_private = !object && omp_private_member_map;
2732 : 58459095 : tree ret;
2733 : :
2734 : 58459095 : if (!object)
2735 : : {
2736 : 58459095 : tree scope = qualifying_scope;
2737 : 58459095 : if (scope == NULL_TREE)
2738 : : {
2739 : 58447227 : scope = context_for_name_lookup (decl);
2740 : 58447227 : if (!TYPE_P (scope))
2741 : : {
2742 : : /* Can happen during error recovery (c++/85014). */
2743 : 3 : gcc_assert (seen_error ());
2744 : 3 : return error_mark_node;
2745 : : }
2746 : : }
2747 : 58459092 : object = maybe_dummy_object (scope, NULL);
2748 : : }
2749 : :
2750 : 67620402 : object = maybe_resolve_dummy (object, true);
2751 : 67620402 : if (object == error_mark_node)
2752 : : return error_mark_node;
2753 : :
2754 : : /* DR 613/850: Can use non-static data members without an associated
2755 : : object in sizeof/decltype/alignof. */
2756 : 67620399 : if (is_dummy_object (object)
2757 : 42334 : && !cp_unevaluated_operand
2758 : 67620494 : && (!processing_template_decl || !current_class_ref))
2759 : : {
2760 : 80 : if (complain & tf_error)
2761 : : {
2762 : 74 : auto_diagnostic_group d;
2763 : 74 : if (current_function_decl
2764 : 74 : && DECL_STATIC_FUNCTION_P (current_function_decl))
2765 : 3 : error ("invalid use of member %qD in static member function", decl);
2766 : 71 : else if (current_function_decl
2767 : 65 : && processing_contract_condition
2768 : 75 : && DECL_CONSTRUCTOR_P (current_function_decl))
2769 : 1 : error ("invalid use of member %qD in constructor %<pre%> contract", decl);
2770 : 70 : else if (current_function_decl
2771 : 64 : && processing_contract_condition
2772 : 72 : && DECL_DESTRUCTOR_P (current_function_decl))
2773 : 1 : error ("invalid use of member %qD in destructor %<post%> contract", decl);
2774 : : else
2775 : 69 : error ("invalid use of non-static data member %qD", decl);
2776 : 74 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
2777 : 74 : }
2778 : :
2779 : 80 : return error_mark_node;
2780 : : }
2781 : :
2782 : 67620319 : if (current_class_ptr)
2783 : 67348035 : TREE_USED (current_class_ptr) = 1;
2784 : 67620319 : if (processing_template_decl)
2785 : : {
2786 : 53475816 : tree type = TREE_TYPE (decl);
2787 : :
2788 : 53475816 : if (TYPE_REF_P (type))
2789 : : /* Quals on the object don't matter. */;
2790 : 51417770 : else if (PACK_EXPANSION_P (type))
2791 : : /* Don't bother trying to represent this. */
2792 : : type = NULL_TREE;
2793 : 51413724 : else if (!TREE_TYPE (object) || WILDCARD_TYPE_P (TREE_TYPE (object)))
2794 : : /* We don't know what the eventual quals will be, so punt until
2795 : : instantiation time.
2796 : :
2797 : : This can happen when called from build_capture_proxy for an explicit
2798 : : object lambda. It's a bit marginal to call this function in that
2799 : : case, since this function is for references to members of 'this',
2800 : : but the deduced type is required to be derived from the closure
2801 : : type, so it works. */
2802 : : type = NULL_TREE;
2803 : : else
2804 : : {
2805 : : /* Set the cv qualifiers. */
2806 : 51408229 : int quals = cp_type_quals (TREE_TYPE (object));
2807 : :
2808 : 51408229 : if (DECL_MUTABLE_P (decl))
2809 : 242660 : quals &= ~TYPE_QUAL_CONST;
2810 : :
2811 : 51408229 : quals |= cp_type_quals (TREE_TYPE (decl));
2812 : 51408229 : type = cp_build_qualified_type (type, quals);
2813 : : }
2814 : :
2815 : 53475816 : if (qualifying_scope)
2816 : : /* Wrap this in a SCOPE_REF for now. */
2817 : 9924 : ret = build_qualified_name (type, qualifying_scope, decl,
2818 : : /*template_p=*/false);
2819 : : else
2820 : 53465892 : ret = (convert_from_reference
2821 : 53465892 : (build_min (COMPONENT_REF, type, object, decl, NULL_TREE)));
2822 : : }
2823 : : /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
2824 : : QUALIFYING_SCOPE is also non-null. */
2825 : : else
2826 : : {
2827 : 14144503 : tree access_type = TREE_TYPE (object);
2828 : :
2829 : 14144503 : if (!perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
2830 : : decl, complain))
2831 : 0 : return error_mark_node;
2832 : :
2833 : : /* If the data member was named `C::M', convert `*this' to `C'
2834 : : first. */
2835 : 14144503 : if (qualifying_scope)
2836 : : {
2837 : 1908 : tree binfo = NULL_TREE;
2838 : 1908 : object = build_scoped_ref (object, qualifying_scope,
2839 : : &binfo);
2840 : : }
2841 : :
2842 : 14144503 : ret = build_class_member_access_expr (object, decl,
2843 : : /*access_path=*/NULL_TREE,
2844 : : /*preserve_reference=*/false,
2845 : : complain);
2846 : : }
2847 : 67620319 : if (try_omp_private)
2848 : : {
2849 : 1662 : tree *v = omp_private_member_map->get (decl);
2850 : 1662 : if (v)
2851 : 1234 : ret = convert_from_reference (*v);
2852 : : }
2853 : : return ret;
2854 : : }
2855 : :
2856 : : /* DECL was the declaration to which a qualified-id resolved. Issue
2857 : : an error message if it is not accessible. If OBJECT_TYPE is
2858 : : non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2859 : : type of `*x', or `x', respectively. If the DECL was named as
2860 : : `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like
2861 : : perform_access_checks above. */
2862 : :
2863 : : bool
2864 : 4143550226 : check_accessibility_of_qualified_id (tree decl,
2865 : : tree object_type,
2866 : : tree nested_name_specifier,
2867 : : tsubst_flags_t complain)
2868 : : {
2869 : : /* If we're not checking, return immediately. */
2870 : 4143550226 : if (deferred_access_no_check)
2871 : : return true;
2872 : :
2873 : : /* Determine the SCOPE of DECL. */
2874 : 4135110470 : tree scope = context_for_name_lookup (decl);
2875 : : /* If the SCOPE is not a type, then DECL is not a member. */
2876 : 4135110470 : if (!TYPE_P (scope)
2877 : : /* If SCOPE is dependent then we can't perform this access check now,
2878 : : and since we'll perform this access check again after substitution
2879 : : there's no need to explicitly defer it. */
2880 : 4135110470 : || dependent_type_p (scope))
2881 : 3775632102 : return true;
2882 : :
2883 : 359478368 : tree qualifying_type = NULL_TREE;
2884 : : /* Compute the scope through which DECL is being accessed. */
2885 : 359478368 : if (object_type
2886 : : /* OBJECT_TYPE might not be a class type; consider:
2887 : :
2888 : : class A { typedef int I; };
2889 : : I *p;
2890 : : p->A::I::~I();
2891 : :
2892 : : In this case, we will have "A::I" as the DECL, but "I" as the
2893 : : OBJECT_TYPE. */
2894 : 84163 : && CLASS_TYPE_P (object_type)
2895 : 359562514 : && DERIVED_FROM_P (scope, object_type))
2896 : : {
2897 : : /* If we are processing a `->' or `.' expression, use the type of the
2898 : : left-hand side. */
2899 : 84137 : if (tree open = currently_open_class (object_type))
2900 : : qualifying_type = open;
2901 : : else
2902 : : qualifying_type = object_type;
2903 : : }
2904 : 359394231 : else if (nested_name_specifier)
2905 : : {
2906 : : /* If the reference is to a non-static member of the
2907 : : current class, treat it as if it were referenced through
2908 : : `this'. */
2909 : 471300199 : if (DECL_NONSTATIC_MEMBER_P (decl)
2910 : 235703686 : && current_class_ptr)
2911 : 42954 : if (tree current = current_nonlambda_class_type ())
2912 : : {
2913 : 42927 : if (dependent_type_p (current))
2914 : : /* In general we can't know whether this access goes through
2915 : : `this' until instantiation time. Punt now, or else we might
2916 : : create a deferred access check that's not relative to `this'
2917 : : when it ought to be. We'll check this access again after
2918 : : substitution, e.g. from tsubst_qualified_id. */
2919 : : return true;
2920 : :
2921 : 3565 : if (DERIVED_FROM_P (scope, current))
2922 : : qualifying_type = current;
2923 : : }
2924 : : /* Otherwise, use the type indicated by the
2925 : : nested-name-specifier. */
2926 : : if (!qualifying_type)
2927 : : qualifying_type = nested_name_specifier;
2928 : : }
2929 : : else
2930 : : /* Otherwise, the name must be from the current class or one of
2931 : : its bases. */
2932 : 123744130 : qualifying_type = currently_open_derived_class (scope);
2933 : :
2934 : 359380255 : if (qualifying_type
2935 : : /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2936 : : or similar in a default argument value. */
2937 : 359439006 : && CLASS_TYPE_P (qualifying_type))
2938 : 347789991 : return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2939 : 347789991 : decl, complain);
2940 : :
2941 : : return true;
2942 : : }
2943 : :
2944 : : /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2945 : : class named to the left of the "::" operator. DONE is true if this
2946 : : expression is a complete postfix-expression; it is false if this
2947 : : expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2948 : : iff this expression is the operand of '&'. TEMPLATE_P is true iff
2949 : : the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2950 : : is true iff this qualified name appears as a template argument. */
2951 : :
2952 : : tree
2953 : 68668986 : finish_qualified_id_expr (tree qualifying_class,
2954 : : tree expr,
2955 : : bool done,
2956 : : bool address_p,
2957 : : bool template_p,
2958 : : bool template_arg_p,
2959 : : tsubst_flags_t complain)
2960 : : {
2961 : 68668986 : gcc_assert (TYPE_P (qualifying_class));
2962 : :
2963 : 68668986 : if (error_operand_p (expr))
2964 : 18 : return error_mark_node;
2965 : :
2966 : 68668968 : if (DECL_P (expr)
2967 : : /* Functions are marked after overload resolution; avoid redundant
2968 : : warnings. */
2969 : 59225686 : && TREE_CODE (expr) != FUNCTION_DECL
2970 : 127894630 : && !mark_used (expr, complain))
2971 : 0 : return error_mark_node;
2972 : :
2973 : 68668968 : if (template_p)
2974 : : {
2975 : 3011538 : if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE)
2976 : : {
2977 : : /* cp_parser_lookup_name thought we were looking for a type,
2978 : : but we're actually looking for a declaration. */
2979 : 9 : qualifying_class = TYPE_CONTEXT (expr);
2980 : 9 : expr = TYPE_IDENTIFIER (expr);
2981 : : }
2982 : : else
2983 : 3011529 : check_template_keyword (expr);
2984 : : }
2985 : :
2986 : : /* If EXPR occurs as the operand of '&', use special handling that
2987 : : permits a pointer-to-member. */
2988 : 68668968 : if (address_p && done
2989 : 174120 : && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
2990 : : {
2991 : 174118 : if (TREE_CODE (expr) == SCOPE_REF)
2992 : 0 : expr = TREE_OPERAND (expr, 1);
2993 : 174118 : expr = build_offset_ref (qualifying_class, expr,
2994 : : /*address_p=*/true, complain);
2995 : 174118 : return expr;
2996 : : }
2997 : :
2998 : : /* No need to check access within an enum. */
2999 : 68494850 : if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
3000 : 1922205 : && TREE_CODE (expr) != IDENTIFIER_NODE)
3001 : : return expr;
3002 : :
3003 : : /* Within the scope of a class, turn references to non-static
3004 : : members into expression of the form "this->...". */
3005 : 66572648 : if (template_arg_p)
3006 : : /* But, within a template argument, we do not want make the
3007 : : transformation, as there is no "this" pointer. */
3008 : : ;
3009 : 66570040 : else if (TREE_CODE (expr) == FIELD_DECL)
3010 : : {
3011 : 11868 : push_deferring_access_checks (dk_no_check);
3012 : 11868 : expr = finish_non_static_data_member (expr, NULL_TREE,
3013 : : qualifying_class, complain);
3014 : 11868 : pop_deferring_access_checks ();
3015 : : }
3016 : 66558172 : else if (BASELINK_P (expr))
3017 : : {
3018 : : /* See if any of the functions are non-static members. */
3019 : : /* If so, the expression may be relative to 'this'. */
3020 : 8943583 : if (!shared_member_p (expr)
3021 : 292926 : && current_class_ptr
3022 : 9235815 : && DERIVED_FROM_P (qualifying_class,
3023 : : current_nonlambda_class_type ()))
3024 : 292091 : expr = (build_class_member_access_expr
3025 : 292091 : (maybe_dummy_object (qualifying_class, NULL),
3026 : : expr,
3027 : 292091 : BASELINK_ACCESS_BINFO (expr),
3028 : : /*preserve_reference=*/false,
3029 : : complain));
3030 : 8651492 : else if (done)
3031 : : /* The expression is a qualified name whose address is not
3032 : : being taken. */
3033 : 4921 : expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
3034 : : complain);
3035 : : }
3036 : 57614589 : else if (!template_p
3037 : 57317242 : && TREE_CODE (expr) == TEMPLATE_DECL
3038 : 57614707 : && !DECL_FUNCTION_TEMPLATE_P (expr))
3039 : : {
3040 : 118 : if (complain & tf_error)
3041 : 3 : error ("%qE missing template arguments", expr);
3042 : 118 : return error_mark_node;
3043 : : }
3044 : : else
3045 : : {
3046 : : /* In a template, return a SCOPE_REF for most qualified-ids
3047 : : so that we can check access at instantiation time. But if
3048 : : we're looking at a member of the current instantiation, we
3049 : : know we have access and building up the SCOPE_REF confuses
3050 : : non-type template argument handling. */
3051 : 57614471 : if (processing_template_decl
3052 : 57614471 : && (!currently_open_class (qualifying_class)
3053 : 4250 : || TREE_CODE (expr) == IDENTIFIER_NODE
3054 : 4250 : || TREE_CODE (expr) == TEMPLATE_ID_EXPR
3055 : 82 : || TREE_CODE (expr) == BIT_NOT_EXPR))
3056 : 10453250 : expr = build_qualified_name (TREE_TYPE (expr),
3057 : : qualifying_class, expr,
3058 : : template_p);
3059 : 47161221 : else if (tree wrap = maybe_get_tls_wrapper_call (expr))
3060 : 9 : expr = wrap;
3061 : :
3062 : 57614471 : expr = convert_from_reference (expr);
3063 : : }
3064 : :
3065 : : return expr;
3066 : : }
3067 : :
3068 : : /* Begin a statement-expression. The value returned must be passed to
3069 : : finish_stmt_expr. */
3070 : :
3071 : : tree
3072 : 4403452 : begin_stmt_expr (void)
3073 : : {
3074 : 4403452 : return push_stmt_list ();
3075 : : }
3076 : :
3077 : : /* Process the final expression of a statement expression. EXPR can be
3078 : : NULL, if the final expression is empty. Return a STATEMENT_LIST
3079 : : containing all the statements in the statement-expression, or
3080 : : ERROR_MARK_NODE if there was an error. */
3081 : :
3082 : : tree
3083 : 23467 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
3084 : : {
3085 : 23467 : if (error_operand_p (expr))
3086 : : {
3087 : : /* The type of the statement-expression is the type of the last
3088 : : expression. */
3089 : 3 : TREE_TYPE (stmt_expr) = error_mark_node;
3090 : 3 : return error_mark_node;
3091 : : }
3092 : :
3093 : : /* If the last statement does not have "void" type, then the value
3094 : : of the last statement is the value of the entire expression. */
3095 : 23464 : if (expr)
3096 : : {
3097 : 23449 : tree type = TREE_TYPE (expr);
3098 : :
3099 : 23449 : if (type && type_unknown_p (type))
3100 : : {
3101 : 15 : error ("a statement expression is an insufficient context"
3102 : : " for overload resolution");
3103 : 15 : TREE_TYPE (stmt_expr) = error_mark_node;
3104 : 15 : return error_mark_node;
3105 : : }
3106 : 23434 : else if (processing_template_decl)
3107 : : {
3108 : : /* Not finish_expr_stmt because we don't want convert_to_void. */
3109 : 169 : expr = build_stmt (input_location, EXPR_STMT, expr);
3110 : 169 : expr = add_stmt (expr);
3111 : : /* Mark the last statement so that we can recognize it as such at
3112 : : template-instantiation time. */
3113 : 169 : EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
3114 : : }
3115 : 23265 : else if (VOID_TYPE_P (type))
3116 : : {
3117 : : /* Just treat this like an ordinary statement. */
3118 : 31 : expr = finish_expr_stmt (expr);
3119 : : }
3120 : : else
3121 : : {
3122 : : /* It actually has a value we need to deal with. First, force it
3123 : : to be an rvalue so that we won't need to build up a copy
3124 : : constructor call later when we try to assign it to something. */
3125 : 23234 : expr = force_rvalue (expr, tf_warning_or_error);
3126 : 23234 : if (error_operand_p (expr))
3127 : 0 : return error_mark_node;
3128 : :
3129 : : /* Update for array-to-pointer decay. */
3130 : 23234 : type = TREE_TYPE (expr);
3131 : :
3132 : : /* This TARGET_EXPR will initialize the outer one added by
3133 : : finish_stmt_expr. */
3134 : 23234 : set_target_expr_eliding (expr);
3135 : :
3136 : : /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
3137 : : normal statement, but don't convert to void or actually add
3138 : : the EXPR_STMT. */
3139 : 23234 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
3140 : 23234 : expr = maybe_cleanup_point_expr (expr);
3141 : 23234 : add_stmt (expr);
3142 : : }
3143 : :
3144 : : /* The type of the statement-expression is the type of the last
3145 : : expression. */
3146 : 23434 : TREE_TYPE (stmt_expr) = type;
3147 : : }
3148 : :
3149 : : return stmt_expr;
3150 : : }
3151 : :
3152 : : /* Finish a statement-expression. EXPR should be the value returned
3153 : : by the previous begin_stmt_expr. Returns an expression
3154 : : representing the statement-expression. */
3155 : :
3156 : : tree
3157 : 4403452 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
3158 : : {
3159 : 4403452 : tree type;
3160 : 4403452 : tree result;
3161 : :
3162 : 4403452 : if (error_operand_p (stmt_expr))
3163 : : {
3164 : 18 : pop_stmt_list (stmt_expr);
3165 : 18 : return error_mark_node;
3166 : : }
3167 : :
3168 : 4403434 : gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
3169 : :
3170 : 4403434 : type = TREE_TYPE (stmt_expr);
3171 : 4403434 : result = pop_stmt_list (stmt_expr);
3172 : 4403434 : TREE_TYPE (result) = type;
3173 : :
3174 : 4403434 : if (processing_template_decl)
3175 : : {
3176 : 10738 : result = build_min (STMT_EXPR, type, result);
3177 : 10738 : TREE_SIDE_EFFECTS (result) = 1;
3178 : 10738 : STMT_EXPR_NO_SCOPE (result) = has_no_scope;
3179 : : }
3180 : 4392696 : else if (CLASS_TYPE_P (type))
3181 : : {
3182 : : /* Wrap the statement-expression in a TARGET_EXPR so that the
3183 : : temporary object created by the final expression is destroyed at
3184 : : the end of the full-expression containing the
3185 : : statement-expression. */
3186 : 118 : result = force_target_expr (type, result, tf_warning_or_error);
3187 : : }
3188 : :
3189 : : return result;
3190 : : }
3191 : :
3192 : : /* Returns the expression which provides the value of STMT_EXPR. */
3193 : :
3194 : : tree
3195 : 191 : stmt_expr_value_expr (tree stmt_expr)
3196 : : {
3197 : 191 : tree t = STMT_EXPR_STMT (stmt_expr);
3198 : :
3199 : 191 : if (TREE_CODE (t) == BIND_EXPR)
3200 : 191 : t = BIND_EXPR_BODY (t);
3201 : :
3202 : 191 : if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
3203 : 158 : t = STATEMENT_LIST_TAIL (t)->stmt;
3204 : :
3205 : 191 : if (TREE_CODE (t) == EXPR_STMT)
3206 : 173 : t = EXPR_STMT_EXPR (t);
3207 : :
3208 : 191 : return t;
3209 : : }
3210 : :
3211 : : /* Return TRUE iff EXPR_STMT is an empty list of
3212 : : expression statements. */
3213 : :
3214 : : bool
3215 : 49085547 : empty_expr_stmt_p (tree expr_stmt)
3216 : : {
3217 : 49085550 : tree body = NULL_TREE;
3218 : :
3219 : 49085550 : if (expr_stmt == void_node)
3220 : : return true;
3221 : :
3222 : 49085547 : if (expr_stmt)
3223 : : {
3224 : 49085547 : if (TREE_CODE (expr_stmt) == EXPR_STMT)
3225 : 3 : body = EXPR_STMT_EXPR (expr_stmt);
3226 : 49085544 : else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
3227 : : body = expr_stmt;
3228 : : }
3229 : :
3230 : 3 : if (body)
3231 : : {
3232 : 48438168 : if (TREE_CODE (body) == STATEMENT_LIST)
3233 : 48438165 : return tsi_end_p (tsi_start (body));
3234 : : else
3235 : : return empty_expr_stmt_p (body);
3236 : : }
3237 : : return false;
3238 : : }
3239 : :
3240 : : /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
3241 : : the function (or functions) to call; ARGS are the arguments to the
3242 : : call. Returns the functions to be considered by overload resolution. */
3243 : :
3244 : : cp_expr
3245 : 17378347 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
3246 : : tsubst_flags_t complain)
3247 : : {
3248 : 17378347 : tree identifier = NULL_TREE;
3249 : 17378347 : tree functions = NULL_TREE;
3250 : 17378347 : tree tmpl_args = NULL_TREE;
3251 : 17378347 : bool template_id = false;
3252 : 17378347 : location_t loc = fn_expr.get_location ();
3253 : 17378347 : tree fn = fn_expr.get_value ();
3254 : :
3255 : 17378347 : STRIP_ANY_LOCATION_WRAPPER (fn);
3256 : :
3257 : 17378347 : if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
3258 : : {
3259 : : /* Use a separate flag to handle null args. */
3260 : 2469583 : template_id = true;
3261 : 2469583 : tmpl_args = TREE_OPERAND (fn, 1);
3262 : 2469583 : fn = TREE_OPERAND (fn, 0);
3263 : : }
3264 : :
3265 : : /* Find the name of the overloaded function. */
3266 : 17378347 : if (identifier_p (fn))
3267 : : identifier = fn;
3268 : : else
3269 : : {
3270 : 24366087 : functions = fn;
3271 : 17272753 : identifier = OVL_NAME (functions);
3272 : : }
3273 : :
3274 : : /* A call to a namespace-scope function using an unqualified name.
3275 : :
3276 : : Do Koenig lookup -- unless any of the arguments are
3277 : : type-dependent. */
3278 : 17378347 : if (!any_type_dependent_arguments_p (args)
3279 : 17378347 : && !any_dependent_template_arguments_p (tmpl_args))
3280 : : {
3281 : 16511948 : fn = lookup_arg_dependent (identifier, functions, args);
3282 : 16511948 : if (!fn)
3283 : : {
3284 : : /* The unqualified name could not be resolved. */
3285 : 23839 : if (complain & tf_error)
3286 : 395 : fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
3287 : : else
3288 : : fn = identifier;
3289 : : }
3290 : : }
3291 : :
3292 : 17378347 : if (fn && template_id && fn != error_mark_node)
3293 : 2469570 : fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
3294 : :
3295 : 17378347 : return cp_expr (fn, loc);
3296 : : }
3297 : :
3298 : : /* Generate an expression for `FN (ARGS)'. This may change the
3299 : : contents of ARGS.
3300 : :
3301 : : If DISALLOW_VIRTUAL is true, the call to FN will be not generated
3302 : : as a virtual call, even if FN is virtual. (This flag is set when
3303 : : encountering an expression where the function name is explicitly
3304 : : qualified. For example a call to `X::f' never generates a virtual
3305 : : call.)
3306 : :
3307 : : Returns code for the call. */
3308 : :
3309 : : tree
3310 : 310414443 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
3311 : : bool koenig_p, tsubst_flags_t complain)
3312 : : {
3313 : 310414443 : tree result;
3314 : 310414443 : tree orig_fn;
3315 : 310414443 : vec<tree, va_gc> *orig_args = *args;
3316 : :
3317 : 310414443 : if (fn == error_mark_node)
3318 : : return error_mark_node;
3319 : :
3320 : 310413429 : gcc_assert (!TYPE_P (fn));
3321 : :
3322 : : /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
3323 : : it so that we can tell this is a call to a known function. */
3324 : 310413429 : fn = maybe_undo_parenthesized_ref (fn);
3325 : :
3326 : 310413429 : STRIP_ANY_LOCATION_WRAPPER (fn);
3327 : :
3328 : 310413429 : orig_fn = fn;
3329 : :
3330 : 310413429 : if (concept_check_p (fn))
3331 : : {
3332 : 6 : error_at (EXPR_LOC_OR_LOC (fn, input_location),
3333 : : "cannot call a concept as a function");
3334 : 6 : return error_mark_node;
3335 : : }
3336 : :
3337 : 310413423 : if (processing_template_decl)
3338 : : {
3339 : : /* If FN is a local extern declaration (or set thereof) in a template,
3340 : : look it up again at instantiation time. */
3341 : 204109292 : if (is_overloaded_fn (fn))
3342 : : {
3343 : 125841699 : tree ifn = get_first_fn (fn);
3344 : 125841699 : if (TREE_CODE (ifn) == FUNCTION_DECL
3345 : 125841699 : && dependent_local_decl_p (ifn))
3346 : 19929 : orig_fn = DECL_NAME (ifn);
3347 : : }
3348 : :
3349 : : /* If the call expression is dependent, build a CALL_EXPR node
3350 : : with no type; type_dependent_expression_p recognizes
3351 : : expressions with no type as being dependent. */
3352 : 204109292 : if (type_dependent_expression_p (fn)
3353 : 204109292 : || any_type_dependent_arguments_p (*args))
3354 : : {
3355 : 183362568 : if (koenig_p
3356 : 9695690 : && TREE_CODE (orig_fn) == FUNCTION_DECL
3357 : 185925617 : && !fndecl_built_in_p (orig_fn))
3358 : : /* For an ADL-enabled call where unqualified lookup found a
3359 : : single non-template function, wrap it in an OVERLOAD so that
3360 : : later substitution doesn't overeagerly mark the function as
3361 : : used. */
3362 : 418097 : orig_fn = ovl_make (orig_fn, NULL_TREE);
3363 : 183362568 : result = build_min_nt_call_vec (orig_fn, *args);
3364 : 244731065 : SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
3365 : 183362568 : KOENIG_LOOKUP_P (result) = koenig_p;
3366 : : /* Disable the std::move warnings since this call was dependent
3367 : : (c++/89780, c++/107363). This also suppresses the
3368 : : -Wredundant-move warning. */
3369 : 183362568 : suppress_warning (result, OPT_Wpessimizing_move);
3370 : :
3371 : 183362568 : if (cfun && cp_function_chain && !cp_unevaluated_operand)
3372 : : {
3373 : 158972447 : bool abnormal = true;
3374 : 159145770 : for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
3375 : : {
3376 : 88607448 : tree fndecl = STRIP_TEMPLATE (*iter);
3377 : 88607448 : if (TREE_CODE (fndecl) != FUNCTION_DECL
3378 : 88607370 : || !TREE_THIS_VOLATILE (fndecl))
3379 : : {
3380 : : abnormal = false;
3381 : : break;
3382 : : }
3383 : : }
3384 : : /* FIXME: Stop warning about falling off end of non-void
3385 : : function. But this is wrong. Even if we only see
3386 : : no-return fns at this point, we could select a
3387 : : future-defined return fn during instantiation. Or
3388 : : vice-versa. */
3389 : 158972447 : if (abnormal)
3390 : 70538322 : current_function_returns_abnormally = 1;
3391 : : }
3392 : 183362568 : if (TREE_CODE (fn) == COMPONENT_REF)
3393 : 90205833 : maybe_generic_this_capture (TREE_OPERAND (fn, 0),
3394 : 90205833 : TREE_OPERAND (fn, 1));
3395 : 183362568 : return result;
3396 : : }
3397 : 20746724 : orig_args = make_tree_vector_copy (*args);
3398 : : }
3399 : :
3400 : 127050855 : if (TREE_CODE (fn) == COMPONENT_REF)
3401 : : {
3402 : 25218705 : tree member = TREE_OPERAND (fn, 1);
3403 : 25218705 : if (BASELINK_P (member))
3404 : : {
3405 : 25036751 : tree object = TREE_OPERAND (fn, 0);
3406 : 49822865 : return build_new_method_call (object, member,
3407 : : args, NULL_TREE,
3408 : : (disallow_virtual
3409 : : ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
3410 : : : LOOKUP_NORMAL),
3411 : : /*fn_p=*/NULL,
3412 : 25036751 : complain);
3413 : : }
3414 : : }
3415 : :
3416 : : /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
3417 : 102014104 : if (TREE_CODE (fn) == ADDR_EXPR
3418 : 102014104 : && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
3419 : 9 : fn = TREE_OPERAND (fn, 0);
3420 : :
3421 : 102014104 : if (is_overloaded_fn (fn))
3422 : 97147271 : fn = baselink_for_fns (fn);
3423 : :
3424 : 102014104 : result = NULL_TREE;
3425 : 102014104 : if (BASELINK_P (fn))
3426 : : {
3427 : 15780678 : tree object;
3428 : :
3429 : : /* A call to a member function. From [over.call.func]:
3430 : :
3431 : : If the keyword this is in scope and refers to the class of
3432 : : that member function, or a derived class thereof, then the
3433 : : function call is transformed into a qualified function call
3434 : : using (*this) as the postfix-expression to the left of the
3435 : : . operator.... [Otherwise] a contrived object of type T
3436 : : becomes the implied object argument.
3437 : :
3438 : : In this situation:
3439 : :
3440 : : struct A { void f(); };
3441 : : struct B : public A {};
3442 : : struct C : public A { void g() { B::f(); }};
3443 : :
3444 : : "the class of that member function" refers to `A'. But 11.2
3445 : : [class.access.base] says that we need to convert 'this' to B* as
3446 : : part of the access, so we pass 'B' to maybe_dummy_object. */
3447 : :
3448 : 15780678 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
3449 : : {
3450 : : /* A constructor call always uses a dummy object. (This constructor
3451 : : call which has the form A::A () is actually invalid and we are
3452 : : going to reject it later in build_new_method_call.) */
3453 : 39 : object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
3454 : : }
3455 : : else
3456 : 15780639 : object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
3457 : : NULL);
3458 : :
3459 : 17448128 : result = build_new_method_call (object, fn, args, NULL_TREE,
3460 : : (disallow_virtual
3461 : : ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
3462 : : : LOOKUP_NORMAL),
3463 : : /*fn_p=*/NULL,
3464 : : complain);
3465 : : }
3466 : 86233426 : else if (is_overloaded_fn (fn))
3467 : : {
3468 : : /* If the function is an overloaded builtin, resolve it. */
3469 : 81366593 : if (TREE_CODE (fn) == FUNCTION_DECL
3470 : 81366593 : && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
3471 : 16086294 : || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
3472 : 9026137 : result = resolve_overloaded_builtin (input_location, fn, *args,
3473 : : complain & tf_error);
3474 : :
3475 : 9026137 : if (!result)
3476 : : {
3477 : 81121465 : tree alloc_size_attr = NULL_TREE;
3478 : 81121465 : if (warn_calloc_transposed_args
3479 : 644505 : && TREE_CODE (fn) == FUNCTION_DECL
3480 : 81121465 : && (alloc_size_attr
3481 : 419924 : = lookup_attribute ("alloc_size",
3482 : 419924 : TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
3483 : 3445 : if (TREE_VALUE (alloc_size_attr) == NULL_TREE
3484 : 3445 : || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
3485 : : alloc_size_attr = NULL_TREE;
3486 : 79456800 : if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
3487 : 1664725 : && (complain & tf_warning)
3488 : 1474601 : && !vec_safe_is_empty (*args)
3489 : 82260407 : && !processing_template_decl)
3490 : : {
3491 : : location_t sizeof_arg_loc[6];
3492 : : tree sizeof_arg[6];
3493 : : unsigned int i;
3494 : 8174812 : for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
3495 : : {
3496 : 3065757 : tree t;
3497 : :
3498 : 3065757 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
3499 : 3065757 : sizeof_arg[i] = NULL_TREE;
3500 : 3065757 : if (i >= (*args)->length ())
3501 : 639944 : continue;
3502 : 2425813 : t = (**args)[i];
3503 : 2425813 : if (TREE_CODE (t) != SIZEOF_EXPR)
3504 : 2419262 : continue;
3505 : 6551 : if (SIZEOF_EXPR_TYPE_P (t))
3506 : 2567 : sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
3507 : : else
3508 : 3984 : sizeof_arg[i] = TREE_OPERAND (t, 0);
3509 : 6551 : sizeof_arg_loc[i] = EXPR_LOCATION (t);
3510 : : }
3511 : 1021859 : if (warn_sizeof_pointer_memaccess)
3512 : : {
3513 : 1021799 : auto same_p = same_type_ignoring_top_level_qualifiers_p;
3514 : 1021799 : sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
3515 : : sizeof_arg, same_p);
3516 : : }
3517 : 1021859 : if (alloc_size_attr)
3518 : 60 : warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
3519 : : alloc_size_attr);
3520 : : }
3521 : :
3522 : 81121465 : if ((complain & tf_warning)
3523 : 50021714 : && TREE_CODE (fn) == FUNCTION_DECL
3524 : 23551000 : && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
3525 : 121412 : && vec_safe_length (*args) == 3
3526 : 81242877 : && !any_type_dependent_arguments_p (*args))
3527 : : {
3528 : 121412 : tree arg0 = (*orig_args)[0];
3529 : 121412 : tree arg1 = (*orig_args)[1];
3530 : 121412 : tree arg2 = (*orig_args)[2];
3531 : 121412 : int literal_mask = ((literal_integer_zerop (arg1) << 1)
3532 : 121412 : | (literal_integer_zerop (arg2) << 2));
3533 : 121412 : warn_for_memset (input_location, arg0, arg2, literal_mask);
3534 : : }
3535 : :
3536 : : /* A call to a namespace-scope function. */
3537 : 81121465 : result = build_new_function_call (fn, args, complain);
3538 : : }
3539 : : }
3540 : 4866833 : else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
3541 : : {
3542 : 58159 : if (!vec_safe_is_empty (*args))
3543 : 0 : error ("arguments to destructor are not allowed");
3544 : : /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
3545 : : which case the postfix-expression is a possibly-parenthesized class
3546 : : member access), the function call destroys the object of scalar type
3547 : : denoted by the object expression of the class member access. */
3548 : 58159 : tree ob = TREE_OPERAND (fn, 0);
3549 : 58159 : if (obvalue_p (ob))
3550 : 58141 : result = build_trivial_dtor_call (ob, true);
3551 : : else
3552 : : /* No location to clobber. */
3553 : 18 : result = convert_to_void (ob, ICV_STATEMENT, complain);
3554 : : }
3555 : 4808674 : else if (CLASS_TYPE_P (TREE_TYPE (fn)))
3556 : : /* If the "function" is really an object of class type, it might
3557 : : have an overloaded `operator ()'. */
3558 : 2029282 : result = build_op_call (fn, args, complain);
3559 : :
3560 : 98976066 : if (!result)
3561 : : /* A call where the function is unknown. */
3562 : 2779392 : result = cp_build_function_call_vec (fn, args, complain);
3563 : :
3564 : 102000586 : if (processing_template_decl && result != error_mark_node)
3565 : : {
3566 : 16436353 : if (INDIRECT_REF_P (result))
3567 : 1042710 : result = TREE_OPERAND (result, 0);
3568 : :
3569 : : /* Prune all but the selected function from the original overload
3570 : : set so that we can avoid some duplicate work at instantiation time. */
3571 : 16436353 : if (TREE_CODE (result) == CALL_EXPR
3572 : 16426226 : && really_overloaded_fn (orig_fn))
3573 : : {
3574 : 7563727 : tree sel_fn = CALL_EXPR_FN (result);
3575 : 7563727 : if (TREE_CODE (sel_fn) == COMPONENT_REF)
3576 : : {
3577 : : /* The non-dependent result of build_new_method_call. */
3578 : 2155088 : sel_fn = TREE_OPERAND (sel_fn, 1);
3579 : 2155088 : gcc_assert (BASELINK_P (sel_fn));
3580 : : }
3581 : 5408639 : else if (TREE_CODE (sel_fn) == ADDR_EXPR)
3582 : : /* Our original callee wasn't wrapped in an ADDR_EXPR,
3583 : : so strip this ADDR_EXPR added by build_over_call. */
3584 : 5408639 : sel_fn = TREE_OPERAND (sel_fn, 0);
3585 : : orig_fn = sel_fn;
3586 : : }
3587 : :
3588 : 16436353 : tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
3589 : 16436353 : SET_EXPR_LOCATION (r, input_location);
3590 : 16436353 : KOENIG_LOOKUP_P (r) = koenig_p;
3591 : 16436353 : TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
3592 : 16436353 : release_tree_vector (orig_args);
3593 : 16436353 : result = convert_from_reference (r);
3594 : : }
3595 : :
3596 : : return result;
3597 : : }
3598 : :
3599 : : /* Finish a call to a postfix increment or decrement or EXPR. (Which
3600 : : is indicated by CODE, which should be POSTINCREMENT_EXPR or
3601 : : POSTDECREMENT_EXPR.) */
3602 : :
3603 : : cp_expr
3604 : 2354077 : finish_increment_expr (cp_expr expr, enum tree_code code)
3605 : : {
3606 : : /* input_location holds the location of the trailing operator token.
3607 : : Build a location of the form:
3608 : : expr++
3609 : : ~~~~^~
3610 : : with the caret at the operator token, ranging from the start
3611 : : of EXPR to the end of the operator token. */
3612 : 2354077 : location_t combined_loc = make_location (input_location,
3613 : : expr.get_start (),
3614 : : get_finish (input_location));
3615 : 2354077 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3616 : 2354077 : NULL_TREE, tf_warning_or_error);
3617 : : /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3618 : 2354077 : result.set_location (combined_loc);
3619 : 2354077 : return result;
3620 : : }
3621 : :
3622 : : /* Finish a use of `this'. Returns an expression for `this'. */
3623 : :
3624 : : tree
3625 : 32836453 : finish_this_expr (void)
3626 : : {
3627 : 32836453 : tree result = NULL_TREE;
3628 : :
3629 : 65672792 : if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
3630 : 32625270 : result = current_class_ptr;
3631 : 422350 : else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
3632 : 211109 : result = (lambda_expr_this_capture
3633 : 211109 : (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
3634 : : else
3635 : 74 : gcc_checking_assert (!current_class_ptr);
3636 : :
3637 : 32836379 : if (result)
3638 : : /* The keyword 'this' is a prvalue expression. */
3639 : 32836376 : return rvalue (result);
3640 : :
3641 : 77 : tree fn = current_nonlambda_function ();
3642 : 77 : if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
3643 : : {
3644 : 4 : auto_diagnostic_group d;
3645 : 4 : error ("%<this%> is unavailable for explicit object member "
3646 : : "functions");
3647 : 4 : tree xobj_parm = DECL_ARGUMENTS (fn);
3648 : 4 : gcc_assert (xobj_parm);
3649 : 4 : tree parm_name = DECL_NAME (xobj_parm);
3650 : :
3651 : 4 : static tree remembered_fn = NULL_TREE;
3652 : : /* Only output this diagnostic once per function. */
3653 : 4 : if (remembered_fn == fn)
3654 : : /* Early escape. */;
3655 : 4 : else if (parm_name)
3656 : 4 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3657 : : "use explicit object parameter %qs instead",
3658 : 2 : IDENTIFIER_POINTER (parm_name));
3659 : : else
3660 : 2 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3661 : : "name the explicit object parameter");
3662 : :
3663 : 4 : remembered_fn = fn;
3664 : 4 : }
3665 : 73 : else if (fn && DECL_STATIC_FUNCTION_P (fn))
3666 : 3 : error ("%<this%> is unavailable for static member functions");
3667 : 70 : else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
3668 : 0 : error ("invalid use of %<this%> before it is valid");
3669 : 70 : else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
3670 : 0 : error ("invalid use of %<this%> after it is valid");
3671 : 70 : else if (fn)
3672 : 22 : error ("invalid use of %<this%> in non-member function");
3673 : : else
3674 : 48 : error ("invalid use of %<this%> at top level");
3675 : 77 : return error_mark_node;
3676 : : }
3677 : :
3678 : : /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3679 : : expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3680 : : the TYPE for the type given. If SCOPE is non-NULL, the expression
3681 : : was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3682 : :
3683 : : tree
3684 : 58210 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
3685 : : location_t loc, tsubst_flags_t complain)
3686 : : {
3687 : 58210 : if (object == error_mark_node || destructor == error_mark_node)
3688 : : return error_mark_node;
3689 : :
3690 : 58201 : gcc_assert (TYPE_P (destructor));
3691 : :
3692 : 58201 : if (!processing_template_decl)
3693 : : {
3694 : 58180 : if (scope == error_mark_node)
3695 : : {
3696 : 0 : if (complain & tf_error)
3697 : 0 : error_at (loc, "invalid qualifying scope in pseudo-destructor name");
3698 : 0 : return error_mark_node;
3699 : : }
3700 : 58180 : if (is_auto (destructor))
3701 : 3 : destructor = TREE_TYPE (object);
3702 : 58180 : if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
3703 : : {
3704 : 3 : if (complain & tf_error)
3705 : 3 : error_at (loc,
3706 : : "qualified type %qT does not match destructor name ~%qT",
3707 : : scope, destructor);
3708 : 3 : return error_mark_node;
3709 : : }
3710 : :
3711 : :
3712 : : /* [expr.pseudo] says both:
3713 : :
3714 : : The type designated by the pseudo-destructor-name shall be
3715 : : the same as the object type.
3716 : :
3717 : : and:
3718 : :
3719 : : The cv-unqualified versions of the object type and of the
3720 : : type designated by the pseudo-destructor-name shall be the
3721 : : same type.
3722 : :
3723 : : We implement the more generous second sentence, since that is
3724 : : what most other compilers do. */
3725 : 58177 : if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
3726 : : destructor))
3727 : : {
3728 : 12 : if (complain & tf_error)
3729 : 9 : error_at (loc, "%qE is not of type %qT", object, destructor);
3730 : 12 : return error_mark_node;
3731 : : }
3732 : : }
3733 : :
3734 : 58186 : tree type = (type_dependent_expression_p (object)
3735 : 58186 : ? NULL_TREE : void_type_node);
3736 : :
3737 : 58186 : return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
3738 : 58186 : scope, destructor);
3739 : : }
3740 : :
3741 : : /* Finish an expression of the form CODE EXPR. */
3742 : :
3743 : : cp_expr
3744 : 32923270 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
3745 : : tsubst_flags_t complain)
3746 : : {
3747 : : /* Build a location of the form:
3748 : : ++expr
3749 : : ^~~~~~
3750 : : with the caret at the operator token, ranging from the start
3751 : : of the operator token to the end of EXPR. */
3752 : 32923270 : location_t combined_loc = make_location (op_loc,
3753 : : op_loc, expr.get_finish ());
3754 : 32923270 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3755 : 32923270 : NULL_TREE, complain);
3756 : : /* TODO: build_x_unary_op doesn't always honor the location. */
3757 : 32923270 : result.set_location (combined_loc);
3758 : :
3759 : 32923270 : if (result == error_mark_node)
3760 : : return result;
3761 : :
3762 : 32922811 : if (!(complain & tf_warning))
3763 : : return result;
3764 : :
3765 : : /* These will never fold into a constant, so no need to check for
3766 : : overflow for them. */
3767 : 32922811 : if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
3768 : : return result;
3769 : :
3770 : 18044931 : tree result_ovl = result;
3771 : 18044931 : tree expr_ovl = expr;
3772 : :
3773 : 18044931 : if (!processing_template_decl)
3774 : 1532312 : expr_ovl = cp_fully_fold (expr_ovl);
3775 : :
3776 : 18044931 : if (!CONSTANT_CLASS_P (expr_ovl)
3777 : 18044931 : || TREE_OVERFLOW_P (expr_ovl))
3778 : : return result;
3779 : :
3780 : 224633 : if (!processing_template_decl)
3781 : 214776 : result_ovl = cp_fully_fold (result_ovl);
3782 : :
3783 : 224633 : if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
3784 : 9 : overflow_warning (combined_loc, result_ovl);
3785 : :
3786 : : return result;
3787 : : }
3788 : :
3789 : : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3790 : : elements. */
3791 : :
3792 : : static bool
3793 : 12 : maybe_zero_constructor_nelts (tree expr)
3794 : : {
3795 : 12 : if (CONSTRUCTOR_NELTS (expr) == 0)
3796 : : return true;
3797 : 12 : if (!processing_template_decl)
3798 : : return false;
3799 : 30 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
3800 : 21 : if (!PACK_EXPANSION_P (elt.value))
3801 : : return false;
3802 : : return true;
3803 : : }
3804 : :
3805 : : /* Finish a compound-literal expression or C++11 functional cast with aggregate
3806 : : initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3807 : : is being cast. */
3808 : :
3809 : : tree
3810 : 7352138 : finish_compound_literal (tree type, tree compound_literal,
3811 : : tsubst_flags_t complain,
3812 : : fcl_t fcl_context)
3813 : : {
3814 : 7352138 : if (type == error_mark_node)
3815 : : return error_mark_node;
3816 : :
3817 : 7352125 : if (TYPE_REF_P (type))
3818 : : {
3819 : 12 : compound_literal
3820 : 12 : = finish_compound_literal (TREE_TYPE (type), compound_literal,
3821 : : complain, fcl_context);
3822 : : /* The prvalue is then used to direct-initialize the reference. */
3823 : 12 : tree r = (perform_implicit_conversion_flags
3824 : 12 : (type, compound_literal, complain, LOOKUP_NORMAL));
3825 : 12 : return convert_from_reference (r);
3826 : : }
3827 : :
3828 : 7352113 : if (!TYPE_OBJ_P (type))
3829 : : {
3830 : : /* DR2351 */
3831 : 60 : if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
3832 : : {
3833 : 12 : if (!processing_template_decl)
3834 : 9 : return void_node;
3835 : 3 : TREE_TYPE (compound_literal) = type;
3836 : 3 : TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
3837 : 3 : CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
3838 : 3 : return compound_literal;
3839 : : }
3840 : 21 : else if (VOID_TYPE_P (type)
3841 : 15 : && processing_template_decl
3842 : 33 : && maybe_zero_constructor_nelts (compound_literal))
3843 : : /* If there are only packs in compound_literal, it could
3844 : : be void{} after pack expansion. */;
3845 : : else
3846 : : {
3847 : 12 : if (complain & tf_error)
3848 : 9 : error ("compound literal of non-object type %qT", type);
3849 : 12 : return error_mark_node;
3850 : : }
3851 : : }
3852 : :
3853 : 7352089 : if (template_placeholder_p (type))
3854 : : {
3855 : 63769 : type = do_auto_deduction (type, compound_literal, type, complain,
3856 : : adc_variable_type);
3857 : 63769 : if (type == error_mark_node)
3858 : : return error_mark_node;
3859 : : }
3860 : : /* C++23 auto{x}. */
3861 : 7288320 : else if (is_auto (type)
3862 : 109 : && !AUTO_IS_DECLTYPE (type)
3863 : 7288427 : && CONSTRUCTOR_NELTS (compound_literal) == 1)
3864 : : {
3865 : 101 : if (is_constrained_auto (type))
3866 : : {
3867 : 2 : if (complain & tf_error)
3868 : 2 : error ("%<auto{x}%> cannot be constrained");
3869 : 2 : return error_mark_node;
3870 : : }
3871 : 99 : else if (cxx_dialect < cxx23)
3872 : 1 : pedwarn (input_location, OPT_Wc__23_extensions,
3873 : : "%<auto{x}%> only available with "
3874 : : "%<-std=c++23%> or %<-std=gnu++23%>");
3875 : 99 : type = do_auto_deduction (type, compound_literal, type, complain,
3876 : : adc_variable_type);
3877 : 99 : if (type == error_mark_node)
3878 : : return error_mark_node;
3879 : : }
3880 : :
3881 : : /* Used to hold a copy of the compound literal in a template. */
3882 : 7351985 : tree orig_cl = NULL_TREE;
3883 : :
3884 : 7351985 : if (processing_template_decl)
3885 : : {
3886 : 3485757 : const bool dependent_p
3887 : 3485757 : = (instantiation_dependent_expression_p (compound_literal)
3888 : 3485757 : || dependent_type_p (type));
3889 : 855313 : if (dependent_p)
3890 : : /* We're about to return, no need to copy. */
3891 : : orig_cl = compound_literal;
3892 : : else
3893 : : /* We're going to need a copy. */
3894 : 855313 : orig_cl = unshare_constructor (compound_literal);
3895 : 3485757 : TREE_TYPE (orig_cl) = type;
3896 : : /* Mark the expression as a compound literal. */
3897 : 3485757 : TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
3898 : : /* And as instantiation-dependent. */
3899 : 3485757 : CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
3900 : 3485757 : if (fcl_context == fcl_c99)
3901 : 158 : CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
3902 : : /* If the compound literal is dependent, we're done for now. */
3903 : 3485757 : if (dependent_p)
3904 : : return orig_cl;
3905 : : /* Otherwise, do go on to e.g. check narrowing. */
3906 : : }
3907 : :
3908 : 4721541 : type = complete_type (type);
3909 : :
3910 : 4721541 : if (TYPE_NON_AGGREGATE_CLASS (type))
3911 : : {
3912 : : /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3913 : : everywhere that deals with function arguments would be a pain, so
3914 : : just wrap it in a TREE_LIST. The parser set a flag so we know
3915 : : that it came from T{} rather than T({}). */
3916 : 603570 : CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
3917 : 603570 : compound_literal = build_tree_list (NULL_TREE, compound_literal);
3918 : 603570 : return build_functional_cast (input_location, type,
3919 : 603570 : compound_literal, complain);
3920 : : }
3921 : :
3922 : 4117971 : if (TREE_CODE (type) == ARRAY_TYPE
3923 : 4117971 : && check_array_initializer (NULL_TREE, type, compound_literal))
3924 : 9 : return error_mark_node;
3925 : 4117962 : compound_literal = reshape_init (type, compound_literal, complain);
3926 : 3906745 : if (SCALAR_TYPE_P (type)
3927 : 465537 : && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
3928 : 4178928 : && !check_narrowing (type, compound_literal, complain))
3929 : 102 : return error_mark_node;
3930 : 4117860 : if (TREE_CODE (type) == ARRAY_TYPE
3931 : 4117860 : && TYPE_DOMAIN (type) == NULL_TREE)
3932 : : {
3933 : 1519 : cp_complete_array_type_or_error (&type, compound_literal,
3934 : : false, complain);
3935 : 1519 : if (type == error_mark_node)
3936 : : return error_mark_node;
3937 : : }
3938 : 4117857 : compound_literal = digest_init_flags (type, compound_literal,
3939 : : LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
3940 : : complain);
3941 : 4117857 : if (compound_literal == error_mark_node)
3942 : : return error_mark_node;
3943 : :
3944 : : /* If we're in a template, return the original compound literal. */
3945 : 4117259 : if (orig_cl)
3946 : : return orig_cl;
3947 : :
3948 : 3319537 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3949 : : {
3950 : 2894764 : TREE_HAS_CONSTRUCTOR (compound_literal) = true;
3951 : 2894764 : if (fcl_context == fcl_c99)
3952 : 38275 : CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
3953 : : }
3954 : :
3955 : : /* Put static/constant array temporaries in static variables. */
3956 : : /* FIXME all C99 compound literals should be variables rather than C++
3957 : : temporaries, unless they are used as an aggregate initializer. */
3958 : 4302824 : if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
3959 : 2340242 : && fcl_context == fcl_c99
3960 : 80 : && TREE_CODE (type) == ARRAY_TYPE
3961 : 28 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
3962 : 3319565 : && initializer_constant_valid_p (compound_literal, type))
3963 : : {
3964 : 28 : tree decl = create_temporary_var (type);
3965 : 28 : DECL_CONTEXT (decl) = NULL_TREE;
3966 : 28 : DECL_INITIAL (decl) = compound_literal;
3967 : 28 : TREE_STATIC (decl) = 1;
3968 : 28 : if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
3969 : : {
3970 : : /* 5.19 says that a constant expression can include an
3971 : : lvalue-rvalue conversion applied to "a glvalue of literal type
3972 : : that refers to a non-volatile temporary object initialized
3973 : : with a constant expression". Rather than try to communicate
3974 : : that this VAR_DECL is a temporary, just mark it constexpr. */
3975 : 24 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
3976 : 24 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
3977 : 24 : TREE_CONSTANT (decl) = true;
3978 : : }
3979 : 28 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
3980 : 28 : decl = pushdecl_top_level (decl);
3981 : 28 : DECL_NAME (decl) = make_anon_name ();
3982 : 28 : SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
3983 : : /* Make sure the destructor is callable. */
3984 : 28 : tree clean = cxx_maybe_build_cleanup (decl, complain);
3985 : 28 : if (clean == error_mark_node)
3986 : : return error_mark_node;
3987 : 28 : return decl;
3988 : : }
3989 : :
3990 : : /* Represent other compound literals with TARGET_EXPR so we produce
3991 : : a prvalue, and can elide copies. */
3992 : 3319509 : if (!VECTOR_TYPE_P (type)
3993 : 3282592 : && (TREE_CODE (compound_literal) == CONSTRUCTOR
3994 : 424767 : || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
3995 : : {
3996 : : /* The CONSTRUCTOR is now an initializer, not a compound literal. */
3997 : 2857825 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3998 : 2857825 : TREE_HAS_CONSTRUCTOR (compound_literal) = false;
3999 : 2857825 : compound_literal = get_target_expr (compound_literal, complain);
4000 : : }
4001 : : else
4002 : : /* For e.g. int{42} just make sure it's a prvalue. */
4003 : 461684 : compound_literal = rvalue (compound_literal);
4004 : :
4005 : : return compound_literal;
4006 : : }
4007 : :
4008 : : /* Return the declaration for the function-name variable indicated by
4009 : : ID. */
4010 : :
4011 : : tree
4012 : 198247 : finish_fname (tree id)
4013 : : {
4014 : 198247 : tree decl = fname_decl (input_location, C_RID_CODE (id), id);
4015 : : /* [expr.prim.lambda.closure]/16 "Unless the compound-statement is that
4016 : : of a consteval-block-declaration, a variable __func__ is implicitly
4017 : : defined...". We could be in a consteval block in a function, though,
4018 : : and then we shouldn't warn. */
4019 : 198247 : if (current_function_decl
4020 : 198247 : && !current_nonlambda_function (/*only_skip_consteval_block_p=*/true))
4021 : 4 : pedwarn (input_location, 0, "%qD is not defined outside of function scope",
4022 : : decl);
4023 : 198247 : if (processing_template_decl && current_function_decl
4024 : 123150 : && decl != error_mark_node)
4025 : 123150 : decl = DECL_NAME (decl);
4026 : 198247 : return decl;
4027 : : }
4028 : :
4029 : : /* Finish a translation unit. */
4030 : :
4031 : : void
4032 : 95285 : finish_translation_unit (void)
4033 : : {
4034 : : /* In case there were missing closebraces,
4035 : : get us back to the global binding level. */
4036 : 95285 : pop_everything ();
4037 : 190570 : while (current_namespace != global_namespace)
4038 : 0 : pop_namespace ();
4039 : :
4040 : : /* Do file scope __FUNCTION__ et al. */
4041 : 95285 : finish_fname_decls ();
4042 : :
4043 : 95285 : if (vec_safe_length (scope_chain->omp_declare_target_attribute))
4044 : : {
4045 : 12 : cp_omp_declare_target_attr
4046 : 12 : a = scope_chain->omp_declare_target_attribute->pop ();
4047 : 12 : if (!errorcount)
4048 : 9 : error ("%qs without corresponding %qs",
4049 : : a.device_type >= 0 ? "#pragma omp begin declare target"
4050 : : : "#pragma omp declare target",
4051 : : "#pragma omp end declare target");
4052 : 24 : vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
4053 : : }
4054 : 95285 : if (vec_safe_length (scope_chain->omp_declare_variant_attribute))
4055 : : {
4056 : 0 : if (!errorcount)
4057 : 0 : error ("%<omp begin declare variant%> without corresponding "
4058 : : "%<omp end declare variant%>");
4059 : 0 : vec_safe_truncate (scope_chain->omp_declare_variant_attribute, 0);
4060 : : }
4061 : 95285 : if (vec_safe_length (scope_chain->omp_begin_assumes))
4062 : : {
4063 : 3 : if (!errorcount)
4064 : 3 : error ("%qs without corresponding %qs",
4065 : : "#pragma omp begin assumes", "#pragma omp end assumes");
4066 : 3 : vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
4067 : : }
4068 : 95285 : }
4069 : :
4070 : : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
4071 : : Returns the parameter. */
4072 : :
4073 : : tree
4074 : 145239960 : finish_template_type_parm (tree aggr, tree identifier)
4075 : : {
4076 : 145239960 : if (aggr != class_type_node)
4077 : : {
4078 : 0 : permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
4079 : 0 : aggr = class_type_node;
4080 : : }
4081 : :
4082 : 145239960 : return build_tree_list (aggr, identifier);
4083 : : }
4084 : :
4085 : : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
4086 : : Returns the parameter. */
4087 : :
4088 : : tree
4089 : 339742 : finish_template_template_parm (tree aggr, tree identifier)
4090 : : {
4091 : 339742 : tree decl = build_decl (input_location,
4092 : : TYPE_DECL, identifier, NULL_TREE);
4093 : :
4094 : 339742 : tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
4095 : 339742 : DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
4096 : 339742 : DECL_TEMPLATE_RESULT (tmpl) = decl;
4097 : 339742 : DECL_ARTIFICIAL (decl) = 1;
4098 : :
4099 : : /* Associate the constraints with the underlying declaration,
4100 : : not the template. */
4101 : 339742 : tree constr = current_template_constraints ();
4102 : 339742 : set_constraints (decl, constr);
4103 : :
4104 : 339742 : end_template_decl ();
4105 : :
4106 : 339742 : gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
4107 : :
4108 : 339742 : check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
4109 : : /*is_primary=*/true, /*is_partial=*/false,
4110 : : /*is_friend=*/0);
4111 : :
4112 : 339742 : return finish_template_type_parm (aggr, tmpl);
4113 : : }
4114 : :
4115 : : /* ARGUMENT is the default-argument value for a template template
4116 : : parameter. If ARGUMENT is invalid, issue error messages and return
4117 : : the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
4118 : :
4119 : : tree
4120 : 866 : check_template_template_default_arg (tree argument)
4121 : : {
4122 : 866 : if (TREE_CODE (argument) != TEMPLATE_DECL
4123 : : && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
4124 : : && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
4125 : : {
4126 : : if (TREE_CODE (argument) == TYPE_DECL)
4127 : : {
4128 : 18 : if (tree t = maybe_get_template_decl_from_type_decl (argument))
4129 : 18 : if (TREE_CODE (t) == TEMPLATE_DECL)
4130 : : return t;
4131 : 15 : error ("invalid use of type %qT as a default value for a template "
4132 : 15 : "template-parameter", TREE_TYPE (argument));
4133 : : }
4134 : : else
4135 : 0 : error ("invalid default argument for a template template parameter");
4136 : 15 : return error_mark_node;
4137 : : }
4138 : :
4139 : : return argument;
4140 : : }
4141 : :
4142 : : /* Begin a class definition, as indicated by T. */
4143 : :
4144 : : tree
4145 : 26630808 : begin_class_definition (tree t)
4146 : : {
4147 : 26630808 : if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
4148 : 33 : return error_mark_node;
4149 : :
4150 : 26630891 : if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
4151 : : {
4152 : 9 : error ("definition of %q#T inside template parameter list", t);
4153 : 9 : return error_mark_node;
4154 : : }
4155 : :
4156 : : /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
4157 : : are passed the same as decimal scalar types. */
4158 : 26630766 : if (TREE_CODE (t) == RECORD_TYPE
4159 : 26162228 : && !processing_template_decl)
4160 : : {
4161 : 8897278 : tree ns = TYPE_CONTEXT (t);
4162 : 8897278 : if (ns && TREE_CODE (ns) == NAMESPACE_DECL
4163 : 7144481 : && DECL_CONTEXT (ns) == std_node
4164 : 959065 : && DECL_NAME (ns)
4165 : 9856323 : && id_equal (DECL_NAME (ns), "decimal"))
4166 : : {
4167 : 150 : const char *n = TYPE_NAME_STRING (t);
4168 : 150 : if ((strcmp (n, "decimal32") == 0)
4169 : 101 : || (strcmp (n, "decimal64") == 0)
4170 : 46 : || (strcmp (n, "decimal128") == 0))
4171 : 147 : TYPE_TRANSPARENT_AGGR (t) = 1;
4172 : : }
4173 : : }
4174 : :
4175 : : /* A non-implicit typename comes from code like:
4176 : :
4177 : : template <typename T> struct A {
4178 : : template <typename U> struct A<T>::B ...
4179 : :
4180 : : This is erroneous. */
4181 : 17733488 : else if (TREE_CODE (t) == TYPENAME_TYPE)
4182 : : {
4183 : 0 : error ("invalid definition of qualified type %qT", t);
4184 : 0 : t = error_mark_node;
4185 : : }
4186 : :
4187 : 26630766 : if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
4188 : : {
4189 : 0 : t = make_class_type (RECORD_TYPE);
4190 : 0 : pushtag (make_anon_name (), t);
4191 : : }
4192 : :
4193 : 26630766 : if (TYPE_BEING_DEFINED (t))
4194 : : {
4195 : 0 : t = make_class_type (TREE_CODE (t));
4196 : 0 : pushtag (TYPE_IDENTIFIER (t), t);
4197 : : }
4198 : :
4199 : 26630766 : if (modules_p ())
4200 : : {
4201 : 109324 : if (!module_may_redeclare (TYPE_NAME (t)))
4202 : 0 : return error_mark_node;
4203 : 109324 : set_instantiating_module (TYPE_NAME (t));
4204 : 109324 : set_defining_module (TYPE_NAME (t));
4205 : : }
4206 : :
4207 : 26630766 : maybe_process_partial_specialization (t);
4208 : 26630766 : pushclass (t);
4209 : 26630766 : TYPE_BEING_DEFINED (t) = 1;
4210 : 26630766 : class_binding_level->defining_class_p = 1;
4211 : :
4212 : 26630766 : if (flag_pack_struct)
4213 : : {
4214 : 99 : tree v;
4215 : 99 : TYPE_PACKED (t) = 1;
4216 : : /* Even though the type is being defined for the first time
4217 : : here, there might have been a forward declaration, so there
4218 : : might be cv-qualified variants of T. */
4219 : 99 : for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
4220 : 0 : TYPE_PACKED (v) = 1;
4221 : : }
4222 : : /* Reset the interface data, at the earliest possible
4223 : : moment, as it might have been set via a class foo;
4224 : : before. */
4225 : 54984887 : if (! TYPE_UNNAMED_P (t))
4226 : : {
4227 : 25952507 : struct c_fileinfo *finfo = \
4228 : 25952507 : get_fileinfo (LOCATION_FILE (input_location));
4229 : 25952507 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
4230 : 25952507 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X
4231 : : (t, finfo->interface_unknown);
4232 : : }
4233 : 26630766 : reset_specialization ();
4234 : :
4235 : : /* Make a declaration for this class in its own scope. */
4236 : 26630766 : build_self_reference ();
4237 : :
4238 : 26630766 : return t;
4239 : : }
4240 : :
4241 : : /* Finish the member declaration given by DECL. */
4242 : :
4243 : : void
4244 : 361003813 : finish_member_declaration (tree decl)
4245 : : {
4246 : 361003813 : if (decl == error_mark_node || decl == NULL_TREE)
4247 : : return;
4248 : :
4249 : 361002805 : if (decl == void_type_node)
4250 : : /* The COMPONENT was a friend, not a member, and so there's
4251 : : nothing for us to do. */
4252 : : return;
4253 : :
4254 : : /* We should see only one DECL at a time. */
4255 : 361002805 : gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
4256 : :
4257 : : /* Don't add decls after definition. */
4258 : 361002826 : gcc_assert (TYPE_BEING_DEFINED (current_class_type)
4259 : : /* We can add lambda types when late parsing default
4260 : : arguments. */
4261 : : || LAMBDA_TYPE_P (TREE_TYPE (decl)));
4262 : :
4263 : : /* Set up access control for DECL. */
4264 : 361002805 : TREE_PRIVATE (decl)
4265 : 361002805 : = (current_access_specifier == access_private_node);
4266 : 361002805 : TREE_PROTECTED (decl)
4267 : 361002805 : = (current_access_specifier == access_protected_node);
4268 : 361002805 : if (TREE_CODE (decl) == TEMPLATE_DECL)
4269 : : {
4270 : 41610616 : TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
4271 : 41610616 : TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
4272 : : }
4273 : :
4274 : : /* Mark the DECL as a member of the current class, unless it's
4275 : : a member of an enumeration. */
4276 : 361002805 : if (TREE_CODE (decl) != CONST_DECL)
4277 : 358610738 : DECL_CONTEXT (decl) = current_class_type;
4278 : :
4279 : : /* Remember the single FIELD_DECL an anonymous aggregate type is used for. */
4280 : 361002805 : if (TREE_CODE (decl) == FIELD_DECL
4281 : 361002805 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
4282 : : {
4283 : 177359 : gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
4284 : 177359 : ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))) = decl;
4285 : : }
4286 : :
4287 : 361002805 : if (TREE_CODE (decl) == USING_DECL)
4288 : : /* Avoid debug info for class-scope USING_DECLS for now, we'll
4289 : : call cp_emit_debug_info_for_using later. */
4290 : 3085433 : DECL_IGNORED_P (decl) = 1;
4291 : :
4292 : : /* Check for bare parameter packs in the non-static data member
4293 : : declaration. */
4294 : 361002805 : if (TREE_CODE (decl) == FIELD_DECL)
4295 : : {
4296 : 25878058 : if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
4297 : 9 : TREE_TYPE (decl) = error_mark_node;
4298 : 25878058 : if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
4299 : 0 : DECL_ATTRIBUTES (decl) = NULL_TREE;
4300 : : }
4301 : :
4302 : : /* [dcl.link]
4303 : :
4304 : : A C language linkage is ignored for the names of class members
4305 : : and the member function type of class member functions. */
4306 : 361002805 : if (DECL_LANG_SPECIFIC (decl))
4307 : 329582984 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
4308 : :
4309 : 361002805 : bool add = false;
4310 : :
4311 : : /* Functions and non-functions are added differently. */
4312 : 361002805 : if (DECL_DECLARES_FUNCTION_P (decl))
4313 : 189350646 : add = add_method (current_class_type, decl, false);
4314 : : /* Enter the DECL into the scope of the class, if the class
4315 : : isn't a closure (whose fields are supposed to be unnamed). */
4316 : 171652159 : else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
4317 : 169174460 : || maybe_push_used_methods (decl)
4318 : 339304389 : || pushdecl_class_level (decl))
4319 : : add = true;
4320 : :
4321 : 189350646 : if (add)
4322 : : {
4323 : : /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
4324 : : go at the beginning. The reason is that
4325 : : legacy_nonfn_member_lookup searches the list in order, and we
4326 : : want a field name to override a type name so that the "struct
4327 : : stat hack" will work. In particular:
4328 : :
4329 : : struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
4330 : :
4331 : : is valid. */
4332 : :
4333 : 360995912 : if (TREE_CODE (decl) == TYPE_DECL)
4334 : 121058194 : TYPE_FIELDS (current_class_type)
4335 : 242116388 : = chainon (TYPE_FIELDS (current_class_type), decl);
4336 : : else
4337 : : {
4338 : 239937718 : DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
4339 : 239937718 : TYPE_FIELDS (current_class_type) = decl;
4340 : : }
4341 : :
4342 : 360995912 : maybe_add_class_template_decl_list (current_class_type, decl,
4343 : : /*friend_p=*/0);
4344 : : }
4345 : : }
4346 : :
4347 : : /* Finish processing a complete template declaration. The PARMS are
4348 : : the template parameters. */
4349 : :
4350 : : void
4351 : 83038431 : finish_template_decl (tree parms)
4352 : : {
4353 : 83038431 : if (parms)
4354 : 83038425 : end_template_decl ();
4355 : : else
4356 : 6 : end_specialization ();
4357 : 83038431 : }
4358 : :
4359 : : // Returns the template type of the class scope being entered. If we're
4360 : : // entering a constrained class scope. TYPE is the class template
4361 : : // scope being entered and we may need to match the intended type with
4362 : : // a constrained specialization. For example:
4363 : : //
4364 : : // template<Object T>
4365 : : // struct S { void f(); }; #1
4366 : : //
4367 : : // template<Object T>
4368 : : // void S<T>::f() { } #2
4369 : : //
4370 : : // We check, in #2, that S<T> refers precisely to the type declared by
4371 : : // #1 (i.e., that the constraints match). Note that the following should
4372 : : // be an error since there is no specialization of S<T> that is
4373 : : // unconstrained, but this is not diagnosed here.
4374 : : //
4375 : : // template<typename T>
4376 : : // void S<T>::f() { }
4377 : : //
4378 : : // We cannot diagnose this problem here since this function also matches
4379 : : // qualified template names that are not part of a definition. For example:
4380 : : //
4381 : : // template<Integral T, Floating_point U>
4382 : : // typename pair<T, U>::first_type void f(T, U);
4383 : : //
4384 : : // Here, it is unlikely that there is a partial specialization of
4385 : : // pair constrained for Integral and Floating_point arguments.
4386 : : //
4387 : : // The general rule is: if a constrained specialization with matching
4388 : : // constraints is found return that type. Also note that if TYPE is not a
4389 : : // class-type (e.g. a typename type), then no fixup is needed.
4390 : :
4391 : : static tree
4392 : 5627393 : fixup_template_type (tree type)
4393 : : {
4394 : : // Find the template parameter list at the a depth appropriate to
4395 : : // the scope we're trying to enter.
4396 : 5627393 : tree parms = current_template_parms;
4397 : 5627393 : int depth = template_class_depth (type);
4398 : 12495907 : for (int n = current_template_depth; n > depth && parms; --n)
4399 : 1241121 : parms = TREE_CHAIN (parms);
4400 : 5627393 : if (!parms)
4401 : : return type;
4402 : 5627383 : tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
4403 : 5627383 : tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
4404 : :
4405 : : // Search for a specialization whose type and constraints match.
4406 : 5627383 : tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
4407 : 5627383 : tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
4408 : 10770259 : while (specs)
4409 : : {
4410 : 5265690 : tree spec_constr = get_constraints (TREE_VALUE (specs));
4411 : :
4412 : : // If the type and constraints match a specialization, then we
4413 : : // are entering that type.
4414 : 5265690 : if (same_type_p (type, TREE_TYPE (specs))
4415 : 5265690 : && equivalent_constraints (cur_constr, spec_constr))
4416 : 122814 : return TREE_TYPE (specs);
4417 : 5142876 : specs = TREE_CHAIN (specs);
4418 : : }
4419 : :
4420 : : // If no specialization matches, then must return the type
4421 : : // previously found.
4422 : : return type;
4423 : : }
4424 : :
4425 : : /* Finish processing a template-id (which names a type) of the form
4426 : : NAME < ARGS >. Return the TYPE_DECL for the type named by the
4427 : : template-id. If ENTERING_SCOPE is nonzero we are about to enter
4428 : : the scope of template-id indicated. */
4429 : :
4430 : : tree
4431 : 169943426 : finish_template_type (tree name, tree args, int entering_scope)
4432 : : {
4433 : 169943426 : tree type;
4434 : :
4435 : 169943426 : type = lookup_template_class (name, args,
4436 : : NULL_TREE, NULL_TREE,
4437 : : tf_warning_or_error | tf_user);
4438 : 169943423 : if (entering_scope)
4439 : 19098743 : type = adjust_type_for_entering_scope (type);
4440 : :
4441 : : /* If we might be entering the scope of a partial specialization,
4442 : : find the one with the right constraints. */
4443 : 169943423 : if (flag_concepts
4444 : 61285994 : && entering_scope
4445 : 5847139 : && CLASS_TYPE_P (type)
4446 : 5786204 : && CLASSTYPE_TEMPLATE_INFO (type)
4447 : 5786195 : && dependent_type_p (type)
4448 : 175570816 : && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
4449 : 5627393 : type = fixup_template_type (type);
4450 : :
4451 : 169943423 : if (type == error_mark_node)
4452 : : return type;
4453 : 169941175 : else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
4454 : 142569188 : return TYPE_STUB_DECL (type);
4455 : : else
4456 : 27371987 : return TYPE_NAME (type);
4457 : : }
4458 : :
4459 : : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
4460 : : Return a TREE_LIST containing the ACCESS_SPECIFIER and the
4461 : : BASE_CLASS, or NULL_TREE if an error occurred. The
4462 : : ACCESS_SPECIFIER is one of
4463 : : access_{default,public,protected_private}_node. For a virtual base
4464 : : we set TREE_TYPE. */
4465 : :
4466 : : tree
4467 : 10959735 : finish_base_specifier (tree base, tree access, bool virtual_p)
4468 : : {
4469 : 10959735 : tree result;
4470 : :
4471 : 10959735 : if (base == error_mark_node)
4472 : : {
4473 : 0 : error ("invalid base-class specification");
4474 : 0 : result = NULL_TREE;
4475 : : }
4476 : 10959735 : else if (! MAYBE_CLASS_TYPE_P (base))
4477 : : {
4478 : 3 : error ("%qT is not a class type", base);
4479 : 3 : result = NULL_TREE;
4480 : : }
4481 : : else
4482 : : {
4483 : 10959732 : if (cp_type_quals (base) != 0)
4484 : : {
4485 : : /* DR 484: Can a base-specifier name a cv-qualified
4486 : : class type? */
4487 : 12 : base = TYPE_MAIN_VARIANT (base);
4488 : : }
4489 : 10959732 : result = build_tree_list (access, base);
4490 : 10959732 : if (virtual_p)
4491 : 26490 : TREE_TYPE (result) = integer_type_node;
4492 : : }
4493 : :
4494 : 10959735 : return result;
4495 : : }
4496 : :
4497 : : /* If FNS is a member function, a set of member functions, or a
4498 : : template-id referring to one or more member functions, return a
4499 : : BASELINK for FNS, incorporating the current access context.
4500 : : Otherwise, return FNS unchanged. */
4501 : :
4502 : : tree
4503 : 151556758 : baselink_for_fns (tree fns)
4504 : : {
4505 : 151556758 : tree scope;
4506 : 151556758 : tree cl;
4507 : :
4508 : 151556758 : if (BASELINK_P (fns)
4509 : 151556758 : || error_operand_p (fns))
4510 : : return fns;
4511 : :
4512 : 135811544 : scope = ovl_scope (fns);
4513 : 135811544 : if (!CLASS_TYPE_P (scope))
4514 : : return fns;
4515 : :
4516 : 6689521 : cl = currently_open_derived_class (scope);
4517 : 6689521 : if (!cl)
4518 : 4695912 : cl = scope;
4519 : 6689521 : tree access_path = TYPE_BINFO (cl);
4520 : 6689521 : tree conv_path = (cl == scope ? access_path
4521 : 745038 : : lookup_base (cl, scope, ba_any, NULL, tf_none));
4522 : 6689521 : return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
4523 : : }
4524 : :
4525 : : /* Returns true iff we are currently parsing a lambda-declarator. */
4526 : :
4527 : : static bool
4528 : 1535765673 : parsing_lambda_declarator ()
4529 : : {
4530 : 1535765673 : cp_binding_level *b = current_binding_level;
4531 : 1537335335 : while (b->kind == sk_template_parms || b->kind == sk_function_parms)
4532 : 1569662 : b = b->level_chain;
4533 : 1535765673 : return b->kind == sk_lambda;
4534 : : }
4535 : :
4536 : : /* Returns true iff DECL is a variable from a function outside
4537 : : the current one. */
4538 : :
4539 : : static bool
4540 : 2050436531 : outer_var_p (tree decl)
4541 : : {
4542 : : /* These should have been stripped or otherwise handled by the caller. */
4543 : 2050436531 : gcc_checking_assert (!REFERENCE_REF_P (decl));
4544 : :
4545 : 1315162603 : return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
4546 : 1864876387 : && DECL_FUNCTION_SCOPE_P (decl)
4547 : : /* Don't get confused by temporaries. */
4548 : 1553325628 : && DECL_NAME (decl)
4549 : 3592043448 : && (DECL_CONTEXT (decl) != current_function_decl
4550 : 1534581661 : || parsing_nsdmi ()
4551 : : /* Also consider captures as outer vars if we are in
4552 : : decltype in a lambda declarator as in:
4553 : : auto l = [j=0]() -> decltype((j)) { ... }
4554 : : for the sake of finish_decltype_type.
4555 : :
4556 : : (Similar issue also affects non-lambdas, but vexing parse
4557 : : makes it more difficult to handle than lambdas.) */
4558 : 1534581197 : || parsing_lambda_declarator ()));
4559 : : }
4560 : :
4561 : : /* As above, but also checks that DECL is automatic. */
4562 : :
4563 : : bool
4564 : 2050436531 : outer_automatic_var_p (tree decl)
4565 : : {
4566 : 2050436531 : return (outer_var_p (decl)
4567 : 2050436531 : && !TREE_STATIC (decl));
4568 : : }
4569 : :
4570 : : /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
4571 : : rewrite it for lambda capture.
4572 : :
4573 : : If ODR_USE is true, we're being called from mark_use, and we complain about
4574 : : use of constant variables. If ODR_USE is false, we're being called for the
4575 : : id-expression, and we do lambda capture. */
4576 : :
4577 : : tree
4578 : 3090582 : process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
4579 : : {
4580 : 3090582 : if (cp_unevaluated_operand)
4581 : : {
4582 : 1906004 : tree type = TREE_TYPE (decl);
4583 : 1906004 : if (!dependent_type_p (type)
4584 : 1906004 : && variably_modified_type_p (type, NULL_TREE))
4585 : : /* VLAs are used even in unevaluated context. */;
4586 : : else
4587 : : /* It's not a use (3.2) if we're in an unevaluated context. */
4588 : 1905998 : return decl;
4589 : : }
4590 : 1184584 : if (decl == error_mark_node)
4591 : : return decl;
4592 : :
4593 : 1184584 : tree context = DECL_CONTEXT (decl);
4594 : 1184584 : tree containing_function = current_function_decl;
4595 : 1184584 : tree lambda_stack = NULL_TREE;
4596 : 1184584 : tree lambda_expr = NULL_TREE;
4597 : 1184584 : tree initializer = convert_from_reference (decl);
4598 : 1184584 : tree var = strip_normal_capture_proxy (decl);
4599 : :
4600 : : /* Mark it as used now even if the use is ill-formed. */
4601 : 1184584 : if (!mark_used (decl, complain))
4602 : 3 : return error_mark_node;
4603 : :
4604 : 1184581 : if (parsing_nsdmi () || parsing_lambda_declarator ())
4605 : : containing_function = NULL_TREE;
4606 : :
4607 : 2368608 : if (containing_function && LAMBDA_FUNCTION_P (containing_function))
4608 : : {
4609 : : /* Check whether we've already built a proxy. */
4610 : 1184213 : tree d = retrieve_local_specialization (var);
4611 : :
4612 : 1184213 : if (d && d != decl && is_capture_proxy (d))
4613 : : {
4614 : 609062 : if (DECL_CONTEXT (d) == containing_function)
4615 : : /* We already have an inner proxy. */
4616 : : return d;
4617 : : else
4618 : : /* We need to capture an outer proxy. */
4619 : 4420 : return process_outer_var_ref (d, complain, odr_use);
4620 : : }
4621 : : }
4622 : :
4623 : : /* If we are in a lambda function, we can move out until we hit
4624 : : 1. the context,
4625 : : 2. a non-lambda function, or
4626 : : 3. a non-default capturing lambda function. */
4627 : 1155994 : while (context != containing_function
4628 : : /* containing_function can be null with invalid generic lambdas. */
4629 : 1155994 : && containing_function
4630 : 1736810 : && LAMBDA_FUNCTION_P (containing_function))
4631 : : {
4632 : 580816 : tree closure = DECL_CONTEXT (containing_function);
4633 : 580816 : lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
4634 : :
4635 : 580816 : if (TYPE_CLASS_SCOPE_P (closure))
4636 : : /* A lambda in an NSDMI (c++/64496). */
4637 : : break;
4638 : :
4639 : 580813 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4640 : : break;
4641 : :
4642 : 580475 : lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
4643 : :
4644 : 580475 : containing_function = decl_function_context (containing_function);
4645 : : }
4646 : :
4647 : : /* In a lambda within a template, wait until instantiation time to implicitly
4648 : : capture a parameter pack. We want to wait because we don't know if we're
4649 : : capturing the whole pack or a single element, and it's OK to wait because
4650 : : find_parameter_packs_r walks into the lambda body. */
4651 : 575519 : if (context == containing_function
4652 : 575519 : && DECL_PACK_P (decl))
4653 : : return decl;
4654 : :
4655 : 538855 : if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
4656 : : {
4657 : 6 : if (complain & tf_error)
4658 : 6 : error ("cannot capture member %qD of anonymous union", decl);
4659 : 6 : return error_mark_node;
4660 : : }
4661 : : /* Do lambda capture when processing the id-expression, not when
4662 : : odr-using a variable. */
4663 : 538849 : if (!odr_use && context == containing_function)
4664 : 1076280 : decl = add_default_capture (lambda_stack,
4665 : 538140 : /*id=*/DECL_NAME (decl), initializer);
4666 : : /* Only an odr-use of an outer automatic variable causes an
4667 : : error, and a constant variable can decay to a prvalue
4668 : : constant without odr-use. So don't complain yet. */
4669 : 709 : else if (!odr_use && decl_constant_var_p (var))
4670 : : return var;
4671 : 254 : else if (lambda_expr)
4672 : : {
4673 : 43 : if (complain & tf_error)
4674 : : {
4675 : 43 : auto_diagnostic_group d;
4676 : 43 : error ("%qD is not captured", decl);
4677 : 43 : tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
4678 : 43 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4679 : 40 : inform (location_of (closure),
4680 : : "the lambda has no capture-default");
4681 : 3 : else if (TYPE_CLASS_SCOPE_P (closure))
4682 : 3 : inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
4683 : : "capture variables from the enclosing context",
4684 : 3 : TYPE_CONTEXT (closure));
4685 : 43 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4686 : 43 : }
4687 : 43 : return error_mark_node;
4688 : : }
4689 : 211 : else if (processing_contract_condition && (TREE_CODE (decl) == PARM_DECL))
4690 : : /* Use of a parameter in a contract condition is fine. */
4691 : : return decl;
4692 : : else
4693 : : {
4694 : 39 : if (complain & tf_error)
4695 : : {
4696 : 39 : auto_diagnostic_group d;
4697 : 57 : error (VAR_P (decl)
4698 : : ? G_("use of local variable with automatic storage from "
4699 : : "containing function")
4700 : : : G_("use of parameter from containing function"));
4701 : 39 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4702 : 39 : }
4703 : 39 : return error_mark_node;
4704 : : }
4705 : 538140 : return decl;
4706 : : }
4707 : :
4708 : : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4709 : : id-expression. (See cp_parser_id_expression for details.) SCOPE,
4710 : : if non-NULL, is the type or namespace used to explicitly qualify
4711 : : ID_EXPRESSION. DECL is the entity to which that name has been
4712 : : resolved.
4713 : :
4714 : : *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4715 : : constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4716 : : be set to true if this expression isn't permitted in a
4717 : : constant-expression, but it is otherwise not set by this function.
4718 : : *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4719 : : constant-expression, but a non-constant expression is also
4720 : : permissible.
4721 : :
4722 : : DONE is true if this expression is a complete postfix-expression;
4723 : : it is false if this expression is followed by '->', '[', '(', etc.
4724 : : ADDRESS_P is true iff this expression is the operand of '&'.
4725 : : TEMPLATE_P is true iff the qualified-id was of the form
4726 : : "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4727 : : appears as a template argument.
4728 : :
4729 : : If an error occurs, and it is the kind of error that might cause
4730 : : the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4731 : : is the caller's responsibility to issue the message. *ERROR_MSG
4732 : : will be a string with static storage duration, so the caller need
4733 : : not "free" it.
4734 : :
4735 : : Return an expression for the entity, after issuing appropriate
4736 : : diagnostics. This function is also responsible for transforming a
4737 : : reference to a non-static member into a COMPONENT_REF that makes
4738 : : the use of "this" explicit.
4739 : :
4740 : : Upon return, *IDK will be filled in appropriately. */
4741 : : static cp_expr
4742 : 651990885 : finish_id_expression_1 (tree id_expression,
4743 : : tree decl,
4744 : : tree scope,
4745 : : cp_id_kind *idk,
4746 : : bool integral_constant_expression_p,
4747 : : bool allow_non_integral_constant_expression_p,
4748 : : bool *non_integral_constant_expression_p,
4749 : : bool template_p,
4750 : : bool done,
4751 : : bool address_p,
4752 : : bool template_arg_p,
4753 : : const char **error_msg,
4754 : : location_t location)
4755 : : {
4756 : 651990885 : decl = strip_using_decl (decl);
4757 : :
4758 : : /* Initialize the output parameters. */
4759 : 651990885 : *idk = CP_ID_KIND_NONE;
4760 : 651990885 : *error_msg = NULL;
4761 : :
4762 : 651990885 : if (id_expression == error_mark_node)
4763 : 12 : return error_mark_node;
4764 : : /* If we have a template-id, then no further lookup is
4765 : : required. If the template-id was for a template-class, we
4766 : : will sometimes have a TYPE_DECL at this point. */
4767 : 651990873 : else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4768 : 616813626 : || TREE_CODE (decl) == TYPE_DECL)
4769 : : ;
4770 : : /* Look up the name. */
4771 : : else
4772 : : {
4773 : 616812739 : if (decl == error_mark_node)
4774 : : {
4775 : : /* Name lookup failed. */
4776 : 96562 : if (scope
4777 : 96562 : && (!TYPE_P (scope)
4778 : 116 : || (!dependentish_scope_p (scope)
4779 : 112 : && !(identifier_p (id_expression)
4780 : 97 : && IDENTIFIER_CONV_OP_P (id_expression)
4781 : 3 : && dependent_type_p (TREE_TYPE (id_expression))))))
4782 : : {
4783 : : /* If the qualifying type is non-dependent (and the name
4784 : : does not name a conversion operator to a dependent
4785 : : type), issue an error. */
4786 : 364 : qualified_name_lookup_error (scope, id_expression, decl, location);
4787 : 364 : return error_mark_node;
4788 : : }
4789 : 96198 : else if (!scope)
4790 : : {
4791 : : /* It may be resolved via Koenig lookup. */
4792 : 96188 : *idk = CP_ID_KIND_UNQUALIFIED;
4793 : 96188 : return id_expression;
4794 : : }
4795 : : else
4796 : : decl = id_expression;
4797 : : }
4798 : :
4799 : : /* Remember that the name was used in the definition of
4800 : : the current class so that we can check later to see if
4801 : : the meaning would have been different after the class
4802 : : was entirely defined. */
4803 : 616716177 : if (!scope && decl != error_mark_node && identifier_p (id_expression))
4804 : 559372646 : maybe_note_name_used_in_class (id_expression, decl);
4805 : :
4806 : : /* A use in unevaluated operand might not be instantiated appropriately
4807 : : if tsubst_copy builds a dummy parm, or if we never instantiate a
4808 : : generic lambda, so mark it now. */
4809 : 616716187 : if (processing_template_decl && cp_unevaluated_operand)
4810 : 10850253 : mark_type_use (decl);
4811 : :
4812 : : /* Disallow uses of local variables from containing functions, except
4813 : : within lambda-expressions. */
4814 : 616716187 : if (outer_automatic_var_p (decl))
4815 : : {
4816 : 2120963 : decl = process_outer_var_ref (decl, tf_warning_or_error);
4817 : 2120963 : if (decl == error_mark_node)
4818 : 85 : return error_mark_node;
4819 : : }
4820 : :
4821 : : /* Also disallow uses of function parameters outside the function
4822 : : body, except inside an unevaluated context (i.e. decltype). */
4823 : 616716102 : if (TREE_CODE (decl) == PARM_DECL
4824 : 259827724 : && DECL_CONTEXT (decl) == NULL_TREE
4825 : 5039383 : && !CONSTRAINT_VAR_P (decl)
4826 : 3650152 : && !cp_unevaluated_operand
4827 : 455 : && !processing_contract_condition
4828 : 616716146 : && !processing_omp_trait_property_expr)
4829 : : {
4830 : 26 : *error_msg = G_("use of parameter outside function body");
4831 : 26 : return error_mark_node;
4832 : : }
4833 : : }
4834 : :
4835 : : /* If we didn't find anything, or what we found was a type,
4836 : : then this wasn't really an id-expression. */
4837 : 651894210 : if (TREE_CODE (decl) == TEMPLATE_DECL
4838 : 651894210 : && !DECL_FUNCTION_TEMPLATE_P (decl))
4839 : : {
4840 : 51 : *error_msg = G_("missing template arguments");
4841 : 51 : return error_mark_node;
4842 : : }
4843 : 651894159 : else if (TREE_CODE (decl) == TYPE_DECL
4844 : 651893272 : || TREE_CODE (decl) == NAMESPACE_DECL)
4845 : : {
4846 : 902 : *error_msg = G_("expected primary-expression");
4847 : 902 : return error_mark_node;
4848 : : }
4849 : :
4850 : : /* If the name resolved to a template parameter, there is no
4851 : : need to look it up again later. */
4852 : 29973642 : if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
4853 : 662781074 : || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4854 : : {
4855 : 19085825 : tree r;
4856 : :
4857 : 19085825 : *idk = CP_ID_KIND_NONE;
4858 : 19085825 : if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4859 : 0 : decl = TEMPLATE_PARM_DECL (decl);
4860 : 19085825 : r = DECL_INITIAL (decl);
4861 : 19085825 : if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
4862 : : {
4863 : : /* If the entity is a template parameter object for a template
4864 : : parameter of type T, the type of the expression is const T. */
4865 : 162 : tree ctype = TREE_TYPE (r);
4866 : 162 : ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
4867 : : | TYPE_QUAL_CONST));
4868 : 162 : r = build1 (VIEW_CONVERT_EXPR, ctype, r);
4869 : : }
4870 : 19085825 : r = convert_from_reference (r);
4871 : 19085825 : if (integral_constant_expression_p
4872 : 3180547 : && !dependent_type_p (TREE_TYPE (decl))
4873 : 21732904 : && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
4874 : : {
4875 : 102 : if (!allow_non_integral_constant_expression_p)
4876 : 6 : error ("template parameter %qD of type %qT is not allowed in "
4877 : : "an integral constant expression because it is not of "
4878 : 6 : "integral or enumeration type", decl, TREE_TYPE (decl));
4879 : 102 : *non_integral_constant_expression_p = true;
4880 : : }
4881 : 19085825 : return r;
4882 : : }
4883 : 632807432 : else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
4884 : : {
4885 : 9 : gcc_checking_assert (scope);
4886 : 9 : *idk = CP_ID_KIND_QUALIFIED;
4887 : 9 : cp_warn_deprecated_use_scopes (scope);
4888 : 9 : decl = finish_qualified_id_expr (scope, decl, done, address_p,
4889 : : template_p, template_arg_p,
4890 : : tf_warning_or_error);
4891 : : }
4892 : : else
4893 : : {
4894 : 632807423 : if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4895 : 35177247 : && variable_template_p (TREE_OPERAND (decl, 0))
4896 : 640387071 : && !concept_check_p (decl))
4897 : : /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
4898 : : considered type-dependent) now, so that the dependence test that
4899 : : follows gives us the right answer: if it represents a non-dependent
4900 : : variable template-id then finish_template_variable will yield the
4901 : : corresponding non-dependent VAR_DECL. */
4902 : 7579648 : decl = finish_template_variable (decl);
4903 : :
4904 : 632807423 : bool dependent_p = type_dependent_expression_p (decl);
4905 : :
4906 : : /* If the declaration was explicitly qualified indicate
4907 : : that. The semantics of `A::f(3)' are different than
4908 : : `f(3)' if `f' is virtual. */
4909 : 1265614846 : *idk = (scope
4910 : 632807423 : ? CP_ID_KIND_QUALIFIED
4911 : 557993741 : : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4912 : 557993741 : ? CP_ID_KIND_TEMPLATE_ID
4913 : : : (dependent_p
4914 : 540413215 : ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
4915 : : : CP_ID_KIND_UNQUALIFIED)));
4916 : :
4917 : 632807423 : if (dependent_p
4918 : 632807423 : && !scope
4919 : 370680837 : && DECL_P (decl)
4920 : 978936396 : && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
4921 : : /* Dependent type attributes on the decl mean that the TREE_TYPE is
4922 : : wrong, so just return the identifier. */
4923 : 39 : return id_expression;
4924 : :
4925 : 632807384 : if (DECL_CLASS_TEMPLATE_P (decl))
4926 : : {
4927 : 0 : error ("use of class template %qT as expression", decl);
4928 : 0 : return error_mark_node;
4929 : : }
4930 : :
4931 : 632807384 : if (TREE_CODE (decl) == TREE_LIST)
4932 : : {
4933 : : /* Ambiguous reference to base members. */
4934 : 0 : auto_diagnostic_group d;
4935 : 0 : error ("request for member %qD is ambiguous in "
4936 : : "multiple inheritance lattice", id_expression);
4937 : 0 : print_candidates (decl);
4938 : 0 : return error_mark_node;
4939 : 0 : }
4940 : :
4941 : : /* Mark variable-like entities as used. Functions are similarly
4942 : : marked either below or after overload resolution. */
4943 : 632807384 : if ((VAR_P (decl)
4944 : 461320799 : || TREE_CODE (decl) == PARM_DECL
4945 : 201493107 : || TREE_CODE (decl) == CONST_DECL
4946 : 190605290 : || TREE_CODE (decl) == RESULT_DECL)
4947 : 903522893 : && !mark_used (decl))
4948 : 12 : return error_mark_node;
4949 : :
4950 : : /* Only certain kinds of names are allowed in constant
4951 : : expression. Template parameters have already
4952 : : been handled above. */
4953 : 632807369 : if (! error_operand_p (decl)
4954 : 632807084 : && !dependent_p
4955 : 632807084 : && integral_constant_expression_p
4956 : 60360329 : && !decl_constant_var_p (decl)
4957 : 49945570 : && TREE_CODE (decl) != CONST_DECL
4958 : 43345272 : && !builtin_valid_in_constant_expr_p (decl)
4959 : 676115840 : && !concept_check_p (decl))
4960 : : {
4961 : 43053693 : if (!allow_non_integral_constant_expression_p)
4962 : : {
4963 : 30 : error ("%qD cannot appear in a constant-expression", decl);
4964 : 30 : return error_mark_node;
4965 : : }
4966 : 43053663 : *non_integral_constant_expression_p = true;
4967 : : }
4968 : :
4969 : 632807339 : if (tree wrap = maybe_get_tls_wrapper_call (decl))
4970 : : /* Replace an evaluated use of the thread_local variable with
4971 : : a call to its wrapper. */
4972 : : decl = wrap;
4973 : 632806827 : else if (concept_check_p (decl))
4974 : : {
4975 : : /* Nothing more to do. All of the analysis for concept checks
4976 : : is done by build_conept_id, called from the parser. */
4977 : : }
4978 : 626163444 : else if (scope)
4979 : : {
4980 : 73932864 : if (TREE_CODE (decl) == SCOPE_REF)
4981 : : {
4982 : 28263 : gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
4983 : 28263 : decl = TREE_OPERAND (decl, 1);
4984 : : }
4985 : :
4986 : 73932864 : decl = (adjust_result_of_qualified_name_lookup
4987 : 73932864 : (decl, scope, current_nonlambda_class_type()));
4988 : :
4989 : 73932864 : cp_warn_deprecated_use_scopes (scope);
4990 : :
4991 : 73932864 : if (TYPE_P (scope))
4992 : 11070404 : decl = finish_qualified_id_expr (scope,
4993 : : decl,
4994 : : done,
4995 : : address_p,
4996 : : template_p,
4997 : : template_arg_p,
4998 : : tf_warning_or_error);
4999 : : else
5000 : 62862460 : decl = convert_from_reference (decl);
5001 : : }
5002 : 552230580 : else if (TREE_CODE (decl) == FIELD_DECL)
5003 : : {
5004 : : /* Since SCOPE is NULL here, this is an unqualified name.
5005 : : Access checking has been performed during name lookup
5006 : : already. Turn off checking to avoid duplicate errors. */
5007 : 58446330 : push_deferring_access_checks (dk_no_check);
5008 : 58446330 : decl = finish_non_static_data_member (decl, NULL_TREE,
5009 : : /*qualifying_scope=*/NULL_TREE);
5010 : 58446330 : pop_deferring_access_checks ();
5011 : : }
5012 : 493784250 : else if (is_overloaded_fn (decl))
5013 : : {
5014 : : /* We only need to look at the first function,
5015 : : because all the fns share the attribute we're
5016 : : concerned with (all member fns or all non-members). */
5017 : 56755604 : tree first_fn = get_first_fn (decl);
5018 : 56755604 : first_fn = STRIP_TEMPLATE (first_fn);
5019 : :
5020 : 56755604 : if (!template_arg_p
5021 : 56755604 : && (TREE_CODE (first_fn) == USING_DECL
5022 : 56753758 : || (TREE_CODE (first_fn) == FUNCTION_DECL
5023 : 56753758 : && DECL_FUNCTION_MEMBER_P (first_fn)
5024 : 33582011 : && !shared_member_p (decl))))
5025 : : {
5026 : : /* A set of member functions. */
5027 : 26928817 : decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
5028 : 26928817 : return finish_class_member_access_expr (decl, id_expression,
5029 : : /*template_p=*/false,
5030 : 26928817 : tf_warning_or_error);
5031 : : }
5032 : :
5033 : 29826787 : decl = baselink_for_fns (decl);
5034 : : }
5035 : : else
5036 : : {
5037 : 429934737 : if (DECL_P (decl) && DECL_NONLOCAL (decl)
5038 : 438432640 : && DECL_CLASS_SCOPE_P (decl))
5039 : : {
5040 : 1403994 : tree context = context_for_name_lookup (decl);
5041 : 1403994 : if (context != current_class_type)
5042 : : {
5043 : 812321 : tree path = currently_open_derived_class (context);
5044 : 812321 : if (!path)
5045 : : /* PATH can be null for using an enum of an unrelated
5046 : : class; we checked its access in lookup_using_decl.
5047 : :
5048 : : ??? Should this case make a clone instead, like
5049 : : handle_using_decl? */
5050 : 11 : gcc_assert (TREE_CODE (decl) == CONST_DECL);
5051 : : else
5052 : 812310 : perform_or_defer_access_check (TYPE_BINFO (path),
5053 : : decl, decl,
5054 : : tf_warning_or_error);
5055 : : }
5056 : : }
5057 : :
5058 : 437028646 : decl = convert_from_reference (decl);
5059 : : }
5060 : : }
5061 : :
5062 : 605878531 : return cp_expr (decl, location);
5063 : : }
5064 : :
5065 : : /* As per finish_id_expression_1, but adding a wrapper node
5066 : : around the result if needed to express LOCATION. */
5067 : :
5068 : : cp_expr
5069 : 651990885 : finish_id_expression (tree id_expression,
5070 : : tree decl,
5071 : : tree scope,
5072 : : cp_id_kind *idk,
5073 : : bool integral_constant_expression_p,
5074 : : bool allow_non_integral_constant_expression_p,
5075 : : bool *non_integral_constant_expression_p,
5076 : : bool template_p,
5077 : : bool done,
5078 : : bool address_p,
5079 : : bool template_arg_p,
5080 : : const char **error_msg,
5081 : : location_t location)
5082 : : {
5083 : 651990885 : cp_expr result
5084 : 651990885 : = finish_id_expression_1 (id_expression, decl, scope, idk,
5085 : : integral_constant_expression_p,
5086 : : allow_non_integral_constant_expression_p,
5087 : : non_integral_constant_expression_p,
5088 : : template_p, done, address_p, template_arg_p,
5089 : : error_msg, location);
5090 : 651990882 : return result.maybe_add_location_wrapper ();
5091 : : }
5092 : :
5093 : : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
5094 : : use as a type-specifier. */
5095 : :
5096 : : tree
5097 : 20151768 : finish_typeof (tree expr)
5098 : : {
5099 : 20151768 : tree type;
5100 : :
5101 : 20151768 : if (type_dependent_expression_p (expr))
5102 : : {
5103 : 20058683 : type = cxx_make_type (TYPEOF_TYPE);
5104 : 20058683 : TYPEOF_TYPE_EXPR (type) = expr;
5105 : 20058683 : SET_TYPE_STRUCTURAL_EQUALITY (type);
5106 : :
5107 : 20058683 : return type;
5108 : : }
5109 : :
5110 : 93085 : expr = mark_type_use (expr);
5111 : :
5112 : 93085 : type = unlowered_expr_type (expr);
5113 : :
5114 : 93085 : if (!type || type == unknown_type_node)
5115 : : {
5116 : 3 : error ("type of %qE is unknown", expr);
5117 : 3 : return error_mark_node;
5118 : : }
5119 : :
5120 : : return type;
5121 : : }
5122 : :
5123 : : /* Implement the __underlying_type keyword: Return the underlying
5124 : : type of TYPE, suitable for use as a type-specifier. */
5125 : :
5126 : : tree
5127 : 44076 : finish_underlying_type (tree type)
5128 : : {
5129 : 44076 : if (!complete_type_or_else (type, NULL_TREE))
5130 : 3 : return error_mark_node;
5131 : :
5132 : 44073 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5133 : : {
5134 : 24 : error ("%qT is not an enumeration type", type);
5135 : 24 : return error_mark_node;
5136 : : }
5137 : :
5138 : 44049 : tree underlying_type = ENUM_UNDERLYING_TYPE (type);
5139 : :
5140 : : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5141 : : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5142 : : See finish_enum_value_list for details. */
5143 : 44049 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5144 : 52 : underlying_type
5145 : 52 : = c_common_type_for_mode (TYPE_MODE (underlying_type),
5146 : 52 : TYPE_UNSIGNED (underlying_type));
5147 : :
5148 : : return underlying_type;
5149 : : }
5150 : :
5151 : : /* Implement the __type_pack_element keyword: Return the type
5152 : : at index IDX within TYPES. */
5153 : :
5154 : : static tree
5155 : 94415 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
5156 : : {
5157 : 94415 : idx = maybe_constant_value (idx, NULL_TREE, mce_true);
5158 : 94415 : if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
5159 : : {
5160 : 6 : if (complain & tf_error)
5161 : 3 : error ("pack index has non-integral type %qT", TREE_TYPE (idx));
5162 : 6 : return error_mark_node;
5163 : : }
5164 : 94409 : if (TREE_CODE (idx) != INTEGER_CST)
5165 : : {
5166 : 1 : if (complain & tf_error)
5167 : : {
5168 : 1 : error ("pack index is not an integral constant");
5169 : 1 : cxx_constant_value (idx);
5170 : : }
5171 : 1 : return error_mark_node;
5172 : : }
5173 : 94408 : if (tree_int_cst_sgn (idx) < 0)
5174 : : {
5175 : 5 : if (complain & tf_error)
5176 : 5 : error ("pack index %qE is negative", idx);
5177 : 5 : return error_mark_node;
5178 : : }
5179 : 94403 : if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
5180 : : {
5181 : 25 : if (complain & tf_error)
5182 : 19 : error ("pack index %qE is out of range for pack of length %qd",
5183 : 19 : idx, TREE_VEC_LENGTH (types));
5184 : 25 : return error_mark_node;
5185 : : }
5186 : 94378 : return TREE_VEC_ELT (types, tree_to_shwi (idx));
5187 : : }
5188 : :
5189 : : /* In a pack-index T...[N], return the element at index IDX within TYPES.
5190 : : PARENTHESIZED_P is true iff the pack index was wrapped in (). */
5191 : :
5192 : : tree
5193 : 1586 : pack_index_element (tree idx, tree types, bool parenthesized_p,
5194 : : tsubst_flags_t complain)
5195 : : {
5196 : 1586 : tree r = finish_type_pack_element (idx, types, complain);
5197 : 1586 : if (parenthesized_p)
5198 : : /* For the benefit of decltype(auto). */
5199 : 22 : r = force_paren_expr (r);
5200 : 1586 : return r;
5201 : : }
5202 : :
5203 : : /* Implement the __direct_bases keyword: Return the direct base classes
5204 : : of type. */
5205 : :
5206 : : tree
5207 : 15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
5208 : : {
5209 : 15 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5210 : 15 : || !NON_UNION_CLASS_TYPE_P (type))
5211 : 8 : return make_tree_vec (0);
5212 : :
5213 : 7 : releasing_vec vector;
5214 : 7 : vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
5215 : 7 : tree binfo;
5216 : 7 : unsigned i;
5217 : :
5218 : : /* Virtual bases are initialized first */
5219 : 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5220 : 13 : if (BINFO_VIRTUAL_P (binfo))
5221 : 2 : vec_safe_push (vector, binfo);
5222 : :
5223 : : /* Now non-virtuals */
5224 : 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5225 : 13 : if (!BINFO_VIRTUAL_P (binfo))
5226 : 11 : vec_safe_push (vector, binfo);
5227 : :
5228 : 7 : tree bases_vec = make_tree_vec (vector->length ());
5229 : :
5230 : 27 : for (i = 0; i < vector->length (); ++i)
5231 : 13 : TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
5232 : :
5233 : 7 : return bases_vec;
5234 : 7 : }
5235 : :
5236 : : /* Implement the __bases keyword: Return the base classes
5237 : : of type */
5238 : :
5239 : : /* Find morally non-virtual base classes by walking binfo hierarchy */
5240 : : /* Virtual base classes are handled separately in finish_bases */
5241 : :
5242 : : static tree
5243 : 73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
5244 : : {
5245 : : /* Don't walk bases of virtual bases */
5246 : 73 : return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
5247 : : }
5248 : :
5249 : : static tree
5250 : 73 : dfs_calculate_bases_post (tree binfo, void *data_)
5251 : : {
5252 : 73 : vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
5253 : 73 : if (!BINFO_VIRTUAL_P (binfo))
5254 : 48 : vec_safe_push (*data, BINFO_TYPE (binfo));
5255 : 73 : return NULL_TREE;
5256 : : }
5257 : :
5258 : : /* Calculates the morally non-virtual base classes of a class */
5259 : : static vec<tree, va_gc> *
5260 : 16 : calculate_bases_helper (tree type)
5261 : : {
5262 : 16 : vec<tree, va_gc> *vector = make_tree_vector ();
5263 : :
5264 : : /* Now add non-virtual base classes in order of construction */
5265 : 16 : if (TYPE_BINFO (type))
5266 : 16 : dfs_walk_all (TYPE_BINFO (type),
5267 : : dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
5268 : 16 : return vector;
5269 : : }
5270 : :
5271 : : tree
5272 : 12 : calculate_bases (tree type, tsubst_flags_t complain)
5273 : : {
5274 : 12 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5275 : 12 : || !NON_UNION_CLASS_TYPE_P (type))
5276 : 5 : return make_tree_vec (0);
5277 : :
5278 : 7 : releasing_vec vector;
5279 : 7 : tree bases_vec = NULL_TREE;
5280 : 7 : unsigned i;
5281 : 7 : vec<tree, va_gc> *vbases;
5282 : 7 : tree binfo;
5283 : :
5284 : : /* First go through virtual base classes */
5285 : 7 : for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
5286 : 16 : vec_safe_iterate (vbases, i, &binfo); i++)
5287 : : {
5288 : 9 : releasing_vec vbase_bases
5289 : 9 : = calculate_bases_helper (BINFO_TYPE (binfo));
5290 : 9 : vec_safe_splice (vector, vbase_bases);
5291 : 9 : }
5292 : :
5293 : : /* Now for the non-virtual bases */
5294 : 7 : releasing_vec nonvbases = calculate_bases_helper (type);
5295 : 7 : vec_safe_splice (vector, nonvbases);
5296 : :
5297 : : /* Note that during error recovery vector->length can even be zero. */
5298 : 7 : if (vector->length () > 1)
5299 : : {
5300 : : /* Last element is entire class, so don't copy */
5301 : 6 : bases_vec = make_tree_vec (vector->length () - 1);
5302 : :
5303 : 53 : for (i = 0; i < vector->length () - 1; ++i)
5304 : 41 : TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
5305 : : }
5306 : : else
5307 : 1 : bases_vec = make_tree_vec (0);
5308 : :
5309 : 7 : return bases_vec;
5310 : 7 : }
5311 : :
5312 : : tree
5313 : 28 : finish_bases (tree type, bool direct)
5314 : : {
5315 : 28 : tree bases = NULL_TREE;
5316 : :
5317 : 28 : if (!processing_template_decl)
5318 : : {
5319 : : /* Parameter packs can only be used in templates */
5320 : 0 : error ("parameter pack %<__bases%> only valid in template declaration");
5321 : 0 : return error_mark_node;
5322 : : }
5323 : :
5324 : 28 : bases = cxx_make_type (BASES);
5325 : 28 : BASES_TYPE (bases) = type;
5326 : 28 : BASES_DIRECT (bases) = direct;
5327 : 28 : SET_TYPE_STRUCTURAL_EQUALITY (bases);
5328 : :
5329 : 28 : return bases;
5330 : : }
5331 : :
5332 : : /* Perform C++-specific checks for __builtin_offsetof before calling
5333 : : fold_offsetof. */
5334 : :
5335 : : tree
5336 : 2381 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
5337 : : {
5338 : : /* If we're processing a template, we can't finish the semantics yet.
5339 : : Otherwise we can fold the entire expression now. */
5340 : 2381 : if (processing_template_decl)
5341 : : {
5342 : 60 : expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
5343 : 60 : SET_EXPR_LOCATION (expr, loc);
5344 : 60 : return expr;
5345 : : }
5346 : :
5347 : 2321 : if (expr == error_mark_node)
5348 : : return error_mark_node;
5349 : :
5350 : 2304 : if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
5351 : : {
5352 : 6 : error ("cannot apply %<offsetof%> to destructor %<~%T%>",
5353 : 6 : TREE_OPERAND (expr, 2));
5354 : 6 : return error_mark_node;
5355 : : }
5356 : 4581 : if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
5357 : 4581 : || TREE_TYPE (expr) == unknown_type_node)
5358 : : {
5359 : 30 : while (TREE_CODE (expr) == COMPONENT_REF
5360 : 30 : || TREE_CODE (expr) == COMPOUND_EXPR)
5361 : 12 : expr = TREE_OPERAND (expr, 1);
5362 : :
5363 : 18 : if (DECL_P (expr))
5364 : : {
5365 : 0 : auto_diagnostic_group d;
5366 : 0 : error ("cannot apply %<offsetof%> to member function %qD", expr);
5367 : 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
5368 : 0 : }
5369 : : else
5370 : 18 : error ("cannot apply %<offsetof%> to member function");
5371 : 18 : return error_mark_node;
5372 : : }
5373 : 2280 : if (TREE_CODE (expr) == CONST_DECL)
5374 : : {
5375 : 3 : error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
5376 : 3 : return error_mark_node;
5377 : : }
5378 : 2277 : if (REFERENCE_REF_P (expr))
5379 : 9 : expr = TREE_OPERAND (expr, 0);
5380 : 2277 : if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
5381 : 3 : return error_mark_node;
5382 : 2274 : if (warn_invalid_offsetof
5383 : 2274 : && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
5384 : 2274 : && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
5385 : 2319 : && cp_unevaluated_operand == 0)
5386 : 45 : warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
5387 : : "non-standard-layout type %qT is conditionally-supported",
5388 : 45 : TREE_TYPE (TREE_TYPE (object_ptr)));
5389 : 2274 : return fold_offsetof (expr);
5390 : : }
5391 : :
5392 : : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
5393 : : function is broken out from the above for the benefit of the tree-ssa
5394 : : project. */
5395 : :
5396 : : void
5397 : 378864 : simplify_aggr_init_expr (tree *tp)
5398 : : {
5399 : 378864 : tree aggr_init_expr = *tp;
5400 : :
5401 : : /* Form an appropriate CALL_EXPR. */
5402 : 378864 : tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
5403 : 378864 : tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
5404 : 378864 : tree type = TREE_TYPE (slot);
5405 : :
5406 : 378864 : tree call_expr;
5407 : 378864 : enum style_t { ctor, arg, pcc } style;
5408 : :
5409 : 378864 : if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
5410 : : style = ctor;
5411 : : #ifdef PCC_STATIC_STRUCT_RETURN
5412 : : else if (1)
5413 : : style = pcc;
5414 : : #endif
5415 : : else
5416 : : {
5417 : 96401 : gcc_assert (TREE_ADDRESSABLE (type));
5418 : : style = arg;
5419 : : }
5420 : :
5421 : 378864 : call_expr = build_call_array_loc (input_location,
5422 : 378864 : TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
5423 : : fn,
5424 : 378864 : aggr_init_expr_nargs (aggr_init_expr),
5425 : 378864 : AGGR_INIT_EXPR_ARGP (aggr_init_expr));
5426 : 378864 : TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
5427 : 378864 : CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
5428 : 378864 : CALL_EXPR_OPERATOR_SYNTAX (call_expr)
5429 : 378864 : = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
5430 : 378864 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
5431 : 378864 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
5432 : 378864 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
5433 : :
5434 : 378864 : if (style == ctor)
5435 : : {
5436 : : /* Replace the first argument to the ctor with the address of the
5437 : : slot. */
5438 : 282463 : cxx_mark_addressable (slot);
5439 : 282463 : CALL_EXPR_ARG (call_expr, 0) =
5440 : 282463 : build1 (ADDR_EXPR, build_pointer_type (type), slot);
5441 : : }
5442 : 96401 : else if (style == arg)
5443 : : {
5444 : : /* Just mark it addressable here, and leave the rest to
5445 : : expand_call{,_inline}. */
5446 : 96401 : cxx_mark_addressable (slot);
5447 : 96401 : CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
5448 : 96401 : call_expr = cp_build_init_expr (slot, call_expr);
5449 : : }
5450 : : else if (style == pcc)
5451 : : {
5452 : : /* If we're using the non-reentrant PCC calling convention, then we
5453 : : need to copy the returned value out of the static buffer into the
5454 : : SLOT. */
5455 : : push_deferring_access_checks (dk_no_check);
5456 : : call_expr = build_aggr_init (slot, call_expr,
5457 : : DIRECT_BIND | LOOKUP_ONLYCONVERTING,
5458 : : tf_warning_or_error);
5459 : : pop_deferring_access_checks ();
5460 : : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
5461 : : }
5462 : :
5463 : 378864 : if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
5464 : : {
5465 : 3693 : tree init = build_zero_init (type, NULL_TREE,
5466 : : /*static_storage_p=*/false);
5467 : 3693 : init = cp_build_init_expr (slot, init);
5468 : 3693 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
5469 : : init, call_expr);
5470 : : }
5471 : :
5472 : 378864 : *tp = call_expr;
5473 : 378864 : }
5474 : :
5475 : : /* Emit all thunks to FN that should be emitted when FN is emitted. */
5476 : :
5477 : : void
5478 : 51955212 : emit_associated_thunks (tree fn)
5479 : : {
5480 : : /* When we use vcall offsets, we emit thunks with the virtual
5481 : : functions to which they thunk. The whole point of vcall offsets
5482 : : is so that you can know statically the entire set of thunks that
5483 : : will ever be needed for a given virtual function, thereby
5484 : : enabling you to output all the thunks with the function itself. */
5485 : 51955212 : if (DECL_VIRTUAL_P (fn)
5486 : : /* Do not emit thunks for extern template instantiations. */
5487 : 1054778 : && ! DECL_REALLY_EXTERN (fn)
5488 : : /* Do not emit thunks for tentative decls, those will be processed
5489 : : again at_eof if really needed. */
5490 : 52948438 : && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
5491 : : {
5492 : 992306 : tree thunk;
5493 : :
5494 : 1988861 : for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
5495 : : {
5496 : 4249 : if (!THUNK_ALIAS (thunk))
5497 : : {
5498 : 4249 : use_thunk (thunk, /*emit_p=*/1);
5499 : 4249 : if (DECL_RESULT_THUNK_P (thunk))
5500 : : {
5501 : 178 : tree probe;
5502 : :
5503 : 178 : for (probe = DECL_THUNKS (thunk);
5504 : 327 : probe; probe = DECL_CHAIN (probe))
5505 : 149 : use_thunk (probe, /*emit_p=*/1);
5506 : : }
5507 : : }
5508 : : else
5509 : 0 : gcc_assert (!DECL_THUNKS (thunk));
5510 : : }
5511 : : }
5512 : 51955212 : }
5513 : :
5514 : : /* Generate RTL for FN. */
5515 : :
5516 : : bool
5517 : 146018199 : expand_or_defer_fn_1 (tree fn)
5518 : : {
5519 : : /* When the parser calls us after finishing the body of a template
5520 : : function, we don't really want to expand the body. */
5521 : 146018199 : if (processing_template_decl)
5522 : : {
5523 : : /* Normally, collection only occurs in rest_of_compilation. So,
5524 : : if we don't collect here, we never collect junk generated
5525 : : during the processing of templates until we hit a
5526 : : non-template function. It's not safe to do this inside a
5527 : : nested class, though, as the parser may have local state that
5528 : : is not a GC root. */
5529 : 87033915 : if (!function_depth)
5530 : 86643806 : ggc_collect ();
5531 : 87033915 : return false;
5532 : : }
5533 : :
5534 : 58984284 : gcc_assert (DECL_SAVED_TREE (fn));
5535 : :
5536 : : /* We make a decision about linkage for these functions at the end
5537 : : of the compilation. Until that point, we do not want the back
5538 : : end to output them -- but we do want it to see the bodies of
5539 : : these functions so that it can inline them as appropriate. */
5540 : 58984284 : if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn))
5541 : : {
5542 : 58728726 : if (DECL_INTERFACE_KNOWN (fn))
5543 : : /* We've already made a decision as to how this function will
5544 : : be handled. */;
5545 : 40743689 : else if (!at_eof
5546 : 15634815 : || DECL_IMMEDIATE_FUNCTION_P (fn)
5547 : 56025032 : || DECL_OMP_DECLARE_REDUCTION_P (fn))
5548 : 25462346 : tentative_decl_linkage (fn);
5549 : : else
5550 : 15281343 : import_export_decl (fn);
5551 : :
5552 : : /* If the user wants us to keep all inline functions, then mark
5553 : : this function as needed so that finish_file will make sure to
5554 : : output it later. Similarly, all dllexport'd functions must
5555 : : be emitted; there may be callers in other DLLs. */
5556 : 58728726 : if (DECL_DECLARED_INLINE_P (fn)
5557 : 56850319 : && !DECL_REALLY_EXTERN (fn)
5558 : 53734195 : && !DECL_IMMEDIATE_FUNCTION_P (fn)
5559 : 53151721 : && !DECL_OMP_DECLARE_REDUCTION_P (fn)
5560 : 111880447 : && (flag_keep_inline_functions
5561 : 53149374 : || (flag_keep_inline_dllexport
5562 : 53149374 : && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
5563 : : {
5564 : 2347 : mark_needed (fn);
5565 : 2347 : DECL_EXTERNAL (fn) = 0;
5566 : : }
5567 : : }
5568 : :
5569 : : /* If this is a constructor or destructor body, we have to clone
5570 : : it. */
5571 : 58984284 : if (maybe_clone_body (fn))
5572 : : {
5573 : : /* We don't want to process FN again, so pretend we've written
5574 : : it out, even though we haven't. */
5575 : 7001847 : TREE_ASM_WRITTEN (fn) = 1;
5576 : : /* If this is a constexpr function we still need the body to be
5577 : : able to evaluate it. Similarly, with modules we only stream
5578 : : the maybe-in-charge cdtor and regenerate the clones from it on
5579 : : demand, so we also need to keep the body. Otherwise we don't
5580 : : need it anymore. */
5581 : 7001847 : if (!DECL_DECLARED_CONSTEXPR_P (fn)
5582 : 7001847 : && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
5583 : 4462892 : DECL_SAVED_TREE (fn) = void_node;
5584 : 7001847 : return false;
5585 : : }
5586 : :
5587 : : /* There's no reason to do any of the work here if we're only doing
5588 : : semantic analysis; this code just generates RTL. */
5589 : 51982437 : if (flag_syntax_only)
5590 : : {
5591 : : /* Pretend that this function has been written out so that we don't try
5592 : : to expand it again. */
5593 : 27209 : TREE_ASM_WRITTEN (fn) = 1;
5594 : 27209 : return false;
5595 : : }
5596 : :
5597 : 51955228 : if (DECL_OMP_DECLARE_REDUCTION_P (fn))
5598 : : return false;
5599 : :
5600 : : return true;
5601 : : }
5602 : :
5603 : : void
5604 : 139036059 : expand_or_defer_fn (tree fn)
5605 : : {
5606 : 139036059 : if (expand_or_defer_fn_1 (fn))
5607 : : {
5608 : 44975408 : function_depth++;
5609 : :
5610 : : /* Expand or defer, at the whim of the compilation unit manager. */
5611 : 44975408 : cgraph_node::finalize_function (fn, function_depth > 1);
5612 : 44975408 : emit_associated_thunks (fn);
5613 : :
5614 : 44975408 : function_depth--;
5615 : :
5616 : 89950816 : if (DECL_IMMEDIATE_FUNCTION_P (fn))
5617 : : {
5618 : 556897 : if (cgraph_node *node = cgraph_node::get (fn))
5619 : : {
5620 : 556897 : node->body_removed = true;
5621 : 556897 : node->analyzed = false;
5622 : 556897 : node->definition = false;
5623 : 556897 : node->force_output = false;
5624 : : }
5625 : : }
5626 : : }
5627 : 139036059 : }
5628 : :
5629 : 380222 : class nrv_data
5630 : : {
5631 : : public:
5632 : 190111 : nrv_data () : visited (37) {}
5633 : :
5634 : : tree var;
5635 : : tree result;
5636 : : hash_set<tree> visited;
5637 : : bool simple;
5638 : : bool in_nrv_cleanup;
5639 : : };
5640 : :
5641 : : /* Helper function for walk_tree, used by finalize_nrv below. */
5642 : :
5643 : : static tree
5644 : 20097046 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
5645 : : {
5646 : 20097046 : class nrv_data *dp = (class nrv_data *)data;
5647 : :
5648 : : /* No need to walk into types. There wouldn't be any need to walk into
5649 : : non-statements, except that we have to consider STMT_EXPRs. */
5650 : 20097046 : if (TYPE_P (*tp))
5651 : 173760 : *walk_subtrees = 0;
5652 : :
5653 : : /* Replace all uses of the NRV with the RESULT_DECL. */
5654 : 19923286 : else if (*tp == dp->var)
5655 : 489501 : *tp = dp->result;
5656 : :
5657 : : /* Avoid walking into the same tree more than once. Unfortunately, we
5658 : : can't just use walk_tree_without duplicates because it would only call
5659 : : us for the first occurrence of dp->var in the function body. */
5660 : 19433785 : else if (dp->visited.add (*tp))
5661 : 4269854 : *walk_subtrees = 0;
5662 : :
5663 : : /* If there's a label, we might need to destroy the NRV on goto (92407). */
5664 : 15163931 : else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
5665 : 3 : dp->simple = false;
5666 : : /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
5667 : : but differs from using NULL_TREE in that it indicates that we care
5668 : : about the value of the RESULT_DECL. But preserve anything appended
5669 : : by check_return_expr. */
5670 : 15163928 : else if (TREE_CODE (*tp) == RETURN_EXPR)
5671 : : {
5672 : 202618 : tree *p = &TREE_OPERAND (*tp, 0);
5673 : 546041 : while (TREE_CODE (*p) == COMPOUND_EXPR)
5674 : 140805 : p = &TREE_OPERAND (*p, 0);
5675 : 202618 : if (TREE_CODE (*p) == INIT_EXPR
5676 : 202618 : && INIT_EXPR_NRV_P (*p))
5677 : 202256 : *p = dp->result;
5678 : : }
5679 : : /* Change all cleanups for the NRV to only run when not returning. */
5680 : 14961310 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5681 : 14961310 : && CLEANUP_DECL (*tp) == dp->var)
5682 : : {
5683 : 129234 : dp->in_nrv_cleanup = true;
5684 : 129234 : cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
5685 : 129234 : dp->in_nrv_cleanup = false;
5686 : 129234 : cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
5687 : 129234 : *walk_subtrees = 0;
5688 : :
5689 : 129234 : if (dp->simple)
5690 : : /* For a simple NRV, just run it on the EH path. */
5691 : 128752 : CLEANUP_EH_ONLY (*tp) = true;
5692 : : else
5693 : : {
5694 : : /* Not simple, we need to check current_retval_sentinel to decide
5695 : : whether to run it. If it's set, we're returning normally and
5696 : : don't want to destroy the NRV. If the sentinel is not set, we're
5697 : : leaving scope some other way, either by flowing off the end of its
5698 : : scope or throwing an exception. */
5699 : 1446 : tree cond = build3 (COND_EXPR, void_type_node,
5700 : 482 : current_retval_sentinel,
5701 : 482 : void_node, CLEANUP_EXPR (*tp));
5702 : 482 : CLEANUP_EXPR (*tp) = cond;
5703 : : }
5704 : :
5705 : : /* If a cleanup might throw, we need to clear current_retval_sentinel on
5706 : : the exception path, both so the check above succeeds and so an outer
5707 : : cleanup added by maybe_splice_retval_cleanup doesn't run. */
5708 : 129234 : if (cp_function_chain->throwing_cleanup)
5709 : : {
5710 : 170 : tree clear = build2 (MODIFY_EXPR, boolean_type_node,
5711 : : current_retval_sentinel,
5712 : : boolean_false_node);
5713 : 170 : if (dp->simple)
5714 : : {
5715 : : /* We're already only on the EH path, just prepend it. */
5716 : 160 : tree &exp = CLEANUP_EXPR (*tp);
5717 : 160 : exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
5718 : : }
5719 : : else
5720 : : {
5721 : : /* The cleanup runs on both normal and EH paths, we need another
5722 : : CLEANUP_STMT to clear the flag only on the EH path. */
5723 : 10 : tree &bod = CLEANUP_BODY (*tp);
5724 : 10 : bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
5725 : 10 : bod, clear, current_retval_sentinel);
5726 : 10 : CLEANUP_EH_ONLY (bod) = true;
5727 : : }
5728 : : }
5729 : : }
5730 : : /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
5731 : : want to destroy the retval before the variable goes out of scope. */
5732 : 14832076 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5733 : 8067 : && dp->in_nrv_cleanup
5734 : 14839048 : && CLEANUP_DECL (*tp) == dp->result)
5735 : 6 : CLEANUP_EXPR (*tp) = void_node;
5736 : : /* Replace the DECL_EXPR for the NRV with an initialization of the
5737 : : RESULT_DECL, if needed. */
5738 : 14832070 : else if (TREE_CODE (*tp) == DECL_EXPR
5739 : 14832070 : && DECL_EXPR_DECL (*tp) == dp->var)
5740 : : {
5741 : 190113 : tree init;
5742 : 190113 : if (DECL_INITIAL (dp->var)
5743 : 190113 : && DECL_INITIAL (dp->var) != error_mark_node)
5744 : 49068 : init = cp_build_init_expr (dp->result,
5745 : 49068 : DECL_INITIAL (dp->var));
5746 : : else
5747 : 141045 : init = build_empty_stmt (EXPR_LOCATION (*tp));
5748 : 190113 : DECL_INITIAL (dp->var) = NULL_TREE;
5749 : 190113 : SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
5750 : 190113 : *tp = init;
5751 : : }
5752 : :
5753 : : /* Keep iterating. */
5754 : 20097046 : return NULL_TREE;
5755 : : }
5756 : :
5757 : : /* Called from finish_function to implement the named return value
5758 : : optimization by overriding all the RETURN_EXPRs and pertinent
5759 : : CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5760 : : RESULT_DECL for the function. */
5761 : :
5762 : : void
5763 : 190111 : finalize_nrv (tree fndecl, tree var)
5764 : : {
5765 : 190111 : class nrv_data data;
5766 : 190111 : tree result = DECL_RESULT (fndecl);
5767 : :
5768 : : /* Copy name from VAR to RESULT. */
5769 : 190111 : DECL_NAME (result) = DECL_NAME (var);
5770 : : /* Don't forget that we take its address. */
5771 : 190111 : TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
5772 : : /* Finally set DECL_VALUE_EXPR to avoid assigning
5773 : : a stack slot at -O0 for the original var and debug info
5774 : : uses RESULT location for VAR. */
5775 : 190111 : SET_DECL_VALUE_EXPR (var, result);
5776 : 190111 : DECL_HAS_VALUE_EXPR_P (var) = 1;
5777 : :
5778 : 190111 : data.var = var;
5779 : 190111 : data.result = result;
5780 : 190111 : data.in_nrv_cleanup = false;
5781 : :
5782 : : /* This is simpler for variables declared in the outer scope of
5783 : : the function so we know that their lifetime always ends with a
5784 : : return; see g++.dg/opt/nrv6.C. */
5785 : 190111 : tree outer = outer_curly_brace_block (fndecl);
5786 : 190111 : data.simple = chain_member (var, BLOCK_VARS (outer));
5787 : :
5788 : 190111 : cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
5789 : 190111 : }
5790 : :
5791 : : /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5792 : :
5793 : : bool
5794 : 2239 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
5795 : : bool need_copy_ctor, bool need_copy_assignment,
5796 : : bool need_dtor)
5797 : : {
5798 : 2239 : int save_errorcount = errorcount;
5799 : 2239 : tree info, t;
5800 : :
5801 : : /* Always allocate 3 elements for simplicity. These are the
5802 : : function decls for the ctor, dtor, and assignment op.
5803 : : This layout is known to the three lang hooks,
5804 : : cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
5805 : : and cxx_omp_clause_assign_op. */
5806 : 2239 : info = make_tree_vec (3);
5807 : 2239 : CP_OMP_CLAUSE_INFO (c) = info;
5808 : :
5809 : 2239 : if (need_default_ctor || need_copy_ctor)
5810 : : {
5811 : 1655 : if (need_default_ctor)
5812 : 1254 : t = get_default_ctor (type);
5813 : : else
5814 : 401 : t = get_copy_ctor (type, tf_warning_or_error);
5815 : :
5816 : 1655 : if (t && !trivial_fn_p (t))
5817 : 1400 : TREE_VEC_ELT (info, 0) = t;
5818 : : }
5819 : :
5820 : 2239 : if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
5821 : 1635 : TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
5822 : :
5823 : 2239 : if (need_copy_assignment)
5824 : : {
5825 : 397 : t = get_copy_assign (type);
5826 : :
5827 : 397 : if (t && !trivial_fn_p (t))
5828 : 344 : TREE_VEC_ELT (info, 2) = t;
5829 : : }
5830 : :
5831 : 2239 : return errorcount != save_errorcount;
5832 : : }
5833 : :
5834 : : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
5835 : : FIELD_DECL, otherwise return DECL itself. */
5836 : :
5837 : : static tree
5838 : 26088 : omp_clause_decl_field (tree decl)
5839 : : {
5840 : 26088 : if (VAR_P (decl)
5841 : 18265 : && DECL_HAS_VALUE_EXPR_P (decl)
5842 : 359 : && DECL_ARTIFICIAL (decl)
5843 : 359 : && DECL_LANG_SPECIFIC (decl)
5844 : 26423 : && DECL_OMP_PRIVATIZED_MEMBER (decl))
5845 : : {
5846 : 328 : tree f = DECL_VALUE_EXPR (decl);
5847 : 328 : if (INDIRECT_REF_P (f))
5848 : 0 : f = TREE_OPERAND (f, 0);
5849 : 328 : if (TREE_CODE (f) == COMPONENT_REF)
5850 : : {
5851 : 328 : f = TREE_OPERAND (f, 1);
5852 : 328 : gcc_assert (TREE_CODE (f) == FIELD_DECL);
5853 : : return f;
5854 : : }
5855 : : }
5856 : : return NULL_TREE;
5857 : : }
5858 : :
5859 : : /* Adjust DECL if needed for printing using %qE. */
5860 : :
5861 : : static tree
5862 : 187 : omp_clause_printable_decl (tree decl)
5863 : : {
5864 : 0 : tree t = omp_clause_decl_field (decl);
5865 : 187 : if (t)
5866 : 45 : return t;
5867 : : return decl;
5868 : : }
5869 : :
5870 : : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
5871 : : VAR_DECL T that doesn't need a DECL_EXPR added, record it for
5872 : : privatization. */
5873 : :
5874 : : static void
5875 : 219 : omp_note_field_privatization (tree f, tree t)
5876 : : {
5877 : 219 : if (!omp_private_member_map)
5878 : 71 : omp_private_member_map = new hash_map<tree, tree>;
5879 : 219 : tree &v = omp_private_member_map->get_or_insert (f);
5880 : 219 : if (v == NULL_TREE)
5881 : : {
5882 : 146 : v = t;
5883 : 146 : omp_private_member_vec.safe_push (f);
5884 : : /* Signal that we don't want to create DECL_EXPR for this dummy var. */
5885 : 146 : omp_private_member_vec.safe_push (integer_zero_node);
5886 : : }
5887 : 219 : }
5888 : :
5889 : : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
5890 : : dummy VAR_DECL. */
5891 : :
5892 : : tree
5893 : 861 : omp_privatize_field (tree t, bool shared)
5894 : : {
5895 : 861 : tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
5896 : 861 : if (m == error_mark_node)
5897 : : return error_mark_node;
5898 : 861 : if (!omp_private_member_map && !shared)
5899 : 365 : omp_private_member_map = new hash_map<tree, tree>;
5900 : 861 : if (TYPE_REF_P (TREE_TYPE (t)))
5901 : : {
5902 : 123 : gcc_assert (INDIRECT_REF_P (m));
5903 : 123 : m = TREE_OPERAND (m, 0);
5904 : : }
5905 : 861 : tree vb = NULL_TREE;
5906 : 861 : tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
5907 : 861 : if (v == NULL_TREE)
5908 : : {
5909 : 770 : v = create_temporary_var (TREE_TYPE (m));
5910 : 770 : retrofit_lang_decl (v);
5911 : 770 : DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
5912 : 770 : SET_DECL_VALUE_EXPR (v, m);
5913 : 770 : DECL_HAS_VALUE_EXPR_P (v) = 1;
5914 : 770 : if (!shared)
5915 : 690 : omp_private_member_vec.safe_push (t);
5916 : : }
5917 : 861 : return v;
5918 : : }
5919 : :
5920 : : /* C++ specialisation of the c_omp_address_inspector class. */
5921 : :
5922 : : class cp_omp_address_inspector : public c_omp_address_inspector
5923 : : {
5924 : : public:
5925 : 30479 : cp_omp_address_inspector (location_t loc, tree t)
5926 : 30479 : : c_omp_address_inspector (loc, t)
5927 : : {
5928 : : }
5929 : :
5930 : 30479 : ~cp_omp_address_inspector ()
5931 : : {
5932 : 22208 : }
5933 : :
5934 : 129314 : bool processing_template_decl_p ()
5935 : : {
5936 : 129314 : return processing_template_decl;
5937 : : }
5938 : :
5939 : 0 : void emit_unmappable_type_notes (tree t)
5940 : : {
5941 : 0 : if (TREE_TYPE (t) != error_mark_node
5942 : 0 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
5943 : 0 : cxx_incomplete_type_inform (TREE_TYPE (t));
5944 : 0 : }
5945 : :
5946 : 1058 : tree convert_from_reference (tree x)
5947 : : {
5948 : 1058 : return ::convert_from_reference (x);
5949 : : }
5950 : :
5951 : 141 : tree build_array_ref (location_t loc, tree arr, tree idx)
5952 : : {
5953 : 141 : return ::build_array_ref (loc, arr, idx);
5954 : : }
5955 : :
5956 : 22150 : bool check_clause (tree clause)
5957 : : {
5958 : 22150 : if (TREE_CODE (orig) == COMPONENT_REF
5959 : 22150 : && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
5960 : : tf_warning_or_error))
5961 : : return false;
5962 : 22147 : if (!c_omp_address_inspector::check_clause (clause))
5963 : : return false;
5964 : : return true;
5965 : : }
5966 : : };
5967 : :
5968 : : /* Helper function for handle_omp_array_sections. Called recursively
5969 : : to handle multiple array-section-subscripts. C is the clause,
5970 : : T current expression (initially OMP_CLAUSE_DECL), which is either
5971 : : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
5972 : : expression if specified, TREE_VALUE length expression if specified,
5973 : : TREE_CHAIN is what it has been specified after, or some decl.
5974 : : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
5975 : : set to true if any of the array-section-subscript could have length
5976 : : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
5977 : : first array-section-subscript which is known not to have length
5978 : : of one. Given say:
5979 : : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
5980 : : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
5981 : : all are or may have length of 1, array-section-subscript [:2] is the
5982 : : first one known not to have length 1. For array-section-subscript
5983 : : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
5984 : : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
5985 : : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
5986 : : case though, as some lengths could be zero. */
5987 : :
5988 : : static tree
5989 : 20432 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
5990 : : bool &maybe_zero_len, unsigned int &first_non_one,
5991 : : enum c_omp_region_type ort)
5992 : : {
5993 : 20432 : tree ret, low_bound, length, type;
5994 : 20432 : bool openacc = (ort & C_ORT_ACC) != 0;
5995 : 20432 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
5996 : : {
5997 : 9258 : if (error_operand_p (t))
5998 : 6 : return error_mark_node;
5999 : :
6000 : 9252 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6001 : 9252 : tree t_refto = ai.maybe_unconvert_ref (t);
6002 : :
6003 : 9252 : if (!ai.check_clause (c))
6004 : 0 : return error_mark_node;
6005 : 9252 : else if (ai.component_access_p ()
6006 : 10640 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6007 : 64 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
6008 : 40 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
6009 : 1388 : t = ai.get_root_term (true);
6010 : : else
6011 : 7864 : t = ai.unconverted_ref_origin ();
6012 : 9252 : if (t == error_mark_node)
6013 : : return error_mark_node;
6014 : 9252 : ret = t_refto;
6015 : 9252 : if (TREE_CODE (t) == FIELD_DECL)
6016 : 33 : ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6017 : 9219 : else if (!VAR_P (t)
6018 : 2698 : && (openacc || !EXPR_P (t))
6019 : 2503 : && TREE_CODE (t) != PARM_DECL)
6020 : : {
6021 : 48 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6022 : : return NULL_TREE;
6023 : 30 : if (DECL_P (t))
6024 : 30 : error_at (OMP_CLAUSE_LOCATION (c),
6025 : : "%qD is not a variable in %qs clause", t,
6026 : 30 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6027 : : else
6028 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
6029 : : "%qE is not a variable in %qs clause", t,
6030 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6031 : 30 : return error_mark_node;
6032 : : }
6033 : 9171 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6034 : 8981 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6035 : 17225 : && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
6036 : : {
6037 : 17 : error_at (OMP_CLAUSE_LOCATION (c),
6038 : : "%qD is threadprivate variable in %qs clause", t,
6039 : 17 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6040 : 17 : return error_mark_node;
6041 : : }
6042 : 9187 : if (type_dependent_expression_p (ret))
6043 : : return NULL_TREE;
6044 : 8500 : ret = convert_from_reference (ret);
6045 : 8500 : return ret;
6046 : 9252 : }
6047 : :
6048 : 11174 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
6049 : 7371 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6050 : 6177 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6051 : 4893 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6052 : 13780 : && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
6053 : 43 : TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
6054 : 11174 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
6055 : : maybe_zero_len, first_non_one, ort);
6056 : 11174 : if (ret == error_mark_node || ret == NULL_TREE)
6057 : : return ret;
6058 : :
6059 : 10170 : type = TREE_TYPE (ret);
6060 : 10170 : low_bound = TREE_OPERAND (t, 1);
6061 : 10170 : length = TREE_OPERAND (t, 2);
6062 : 8211 : if ((low_bound && type_dependent_expression_p (low_bound))
6063 : 18298 : || (length && type_dependent_expression_p (length)))
6064 : 88 : return NULL_TREE;
6065 : :
6066 : 10082 : if (low_bound == error_mark_node || length == error_mark_node)
6067 : : return error_mark_node;
6068 : :
6069 : 10082 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
6070 : : {
6071 : 69 : error_at (OMP_CLAUSE_LOCATION (c),
6072 : : "low bound %qE of array section does not have integral type",
6073 : : low_bound);
6074 : 69 : return error_mark_node;
6075 : : }
6076 : 10013 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
6077 : : {
6078 : 63 : error_at (OMP_CLAUSE_LOCATION (c),
6079 : : "length %qE of array section does not have integral type",
6080 : : length);
6081 : 63 : return error_mark_node;
6082 : : }
6083 : 9950 : if (low_bound)
6084 : 8045 : low_bound = mark_rvalue_use (low_bound);
6085 : 9950 : if (length)
6086 : 9004 : length = mark_rvalue_use (length);
6087 : : /* We need to reduce to real constant-values for checks below. */
6088 : 9004 : if (length)
6089 : 9004 : length = fold_simple (length);
6090 : 9950 : if (low_bound)
6091 : 8045 : low_bound = fold_simple (low_bound);
6092 : 8045 : if (low_bound
6093 : 8045 : && TREE_CODE (low_bound) == INTEGER_CST
6094 : 15165 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6095 : 7120 : > TYPE_PRECISION (sizetype))
6096 : 0 : low_bound = fold_convert (sizetype, low_bound);
6097 : 9950 : if (length
6098 : 9004 : && TREE_CODE (length) == INTEGER_CST
6099 : 16943 : && TYPE_PRECISION (TREE_TYPE (length))
6100 : 6993 : > TYPE_PRECISION (sizetype))
6101 : 0 : length = fold_convert (sizetype, length);
6102 : 9950 : if (low_bound == NULL_TREE)
6103 : 1905 : low_bound = integer_zero_node;
6104 : :
6105 : 9950 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6106 : 9950 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
6107 : 5067 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
6108 : : {
6109 : 60 : if (length != integer_one_node)
6110 : : {
6111 : 36 : error_at (OMP_CLAUSE_LOCATION (c),
6112 : : "expected single pointer in %qs clause",
6113 : : user_omp_clause_code_name (c, openacc));
6114 : 36 : return error_mark_node;
6115 : : }
6116 : : }
6117 : 9914 : if (length != NULL_TREE)
6118 : : {
6119 : 8992 : if (!integer_nonzerop (length))
6120 : : {
6121 : 2058 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6122 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6123 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6124 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6125 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6126 : : {
6127 : 459 : if (integer_zerop (length))
6128 : : {
6129 : 28 : error_at (OMP_CLAUSE_LOCATION (c),
6130 : : "zero length array section in %qs clause",
6131 : 28 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6132 : 28 : return error_mark_node;
6133 : : }
6134 : : }
6135 : : else
6136 : 1599 : maybe_zero_len = true;
6137 : : }
6138 : 8964 : if (first_non_one == types.length ()
6139 : 8964 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
6140 : 3926 : first_non_one++;
6141 : : }
6142 : 9886 : if (TREE_CODE (type) == ARRAY_TYPE)
6143 : : {
6144 : 5449 : if (length == NULL_TREE
6145 : 5449 : && (TYPE_DOMAIN (type) == NULL_TREE
6146 : 850 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
6147 : : {
6148 : 30 : error_at (OMP_CLAUSE_LOCATION (c),
6149 : : "for unknown bound array type length expression must "
6150 : : "be specified");
6151 : 30 : return error_mark_node;
6152 : : }
6153 : 5419 : if (TREE_CODE (low_bound) == INTEGER_CST
6154 : 5419 : && tree_int_cst_sgn (low_bound) == -1)
6155 : : {
6156 : 153 : error_at (OMP_CLAUSE_LOCATION (c),
6157 : : "negative low bound in array section in %qs clause",
6158 : 153 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6159 : 153 : return error_mark_node;
6160 : : }
6161 : 5266 : if (length != NULL_TREE
6162 : 4464 : && TREE_CODE (length) == INTEGER_CST
6163 : 8812 : && tree_int_cst_sgn (length) == -1)
6164 : : {
6165 : 153 : error_at (OMP_CLAUSE_LOCATION (c),
6166 : : "negative length in array section in %qs clause",
6167 : 153 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6168 : 153 : return error_mark_node;
6169 : : }
6170 : 5113 : if (TYPE_DOMAIN (type)
6171 : 5019 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6172 : 10132 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
6173 : : == INTEGER_CST)
6174 : : {
6175 : 4623 : tree size
6176 : 4623 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6177 : 4623 : size = size_binop (PLUS_EXPR, size, size_one_node);
6178 : 4623 : if (TREE_CODE (low_bound) == INTEGER_CST)
6179 : : {
6180 : 3856 : if (tree_int_cst_lt (size, low_bound))
6181 : : {
6182 : 54 : error_at (OMP_CLAUSE_LOCATION (c),
6183 : : "low bound %qE above array section size "
6184 : : "in %qs clause", low_bound,
6185 : 54 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6186 : 54 : return error_mark_node;
6187 : : }
6188 : 3802 : if (tree_int_cst_equal (size, low_bound))
6189 : : {
6190 : 17 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6191 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6192 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6193 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6194 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6195 : : {
6196 : 17 : error_at (OMP_CLAUSE_LOCATION (c),
6197 : : "zero length array section in %qs clause",
6198 : 17 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6199 : 17 : return error_mark_node;
6200 : : }
6201 : 0 : maybe_zero_len = true;
6202 : : }
6203 : 3785 : else if (length == NULL_TREE
6204 : 1420 : && first_non_one == types.length ()
6205 : 4083 : && tree_int_cst_equal
6206 : 298 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6207 : : low_bound))
6208 : 195 : first_non_one++;
6209 : : }
6210 : 767 : else if (length == NULL_TREE)
6211 : : {
6212 : 20 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6213 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6214 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6215 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6216 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6217 : 13 : maybe_zero_len = true;
6218 : 40 : if (first_non_one == types.length ())
6219 : 17 : first_non_one++;
6220 : : }
6221 : 4552 : if (length && TREE_CODE (length) == INTEGER_CST)
6222 : : {
6223 : 3278 : if (tree_int_cst_lt (size, length))
6224 : : {
6225 : 57 : error_at (OMP_CLAUSE_LOCATION (c),
6226 : : "length %qE above array section size "
6227 : : "in %qs clause", length,
6228 : 57 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6229 : 57 : return error_mark_node;
6230 : : }
6231 : 3221 : if (TREE_CODE (low_bound) == INTEGER_CST)
6232 : : {
6233 : 2887 : tree lbpluslen
6234 : 2887 : = size_binop (PLUS_EXPR,
6235 : : fold_convert (sizetype, low_bound),
6236 : : fold_convert (sizetype, length));
6237 : 2887 : if (TREE_CODE (lbpluslen) == INTEGER_CST
6238 : 2887 : && tree_int_cst_lt (size, lbpluslen))
6239 : : {
6240 : 54 : error_at (OMP_CLAUSE_LOCATION (c),
6241 : : "high bound %qE above array section size "
6242 : : "in %qs clause", lbpluslen,
6243 : 54 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6244 : 54 : return error_mark_node;
6245 : : }
6246 : : }
6247 : : }
6248 : : }
6249 : 490 : else if (length == NULL_TREE)
6250 : : {
6251 : 1 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6252 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6253 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6254 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6255 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6256 : 0 : maybe_zero_len = true;
6257 : 2 : if (first_non_one == types.length ())
6258 : 1 : first_non_one++;
6259 : : }
6260 : :
6261 : : /* For [lb:] we will need to evaluate lb more than once. */
6262 : 3899 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6263 : : {
6264 : 650 : tree lb = cp_save_expr (low_bound);
6265 : 650 : if (lb != low_bound)
6266 : : {
6267 : 9 : TREE_OPERAND (t, 1) = lb;
6268 : 9 : low_bound = lb;
6269 : : }
6270 : : }
6271 : : }
6272 : 4437 : else if (TYPE_PTR_P (type))
6273 : : {
6274 : 4380 : if (length == NULL_TREE)
6275 : : {
6276 : 42 : if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
6277 : 36 : error_at (OMP_CLAUSE_LOCATION (c),
6278 : : "for array function parameter length expression "
6279 : : "must be specified");
6280 : : else
6281 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
6282 : : "for pointer type length expression must be specified");
6283 : 42 : return error_mark_node;
6284 : : }
6285 : 4338 : if (length != NULL_TREE
6286 : 4338 : && TREE_CODE (length) == INTEGER_CST
6287 : 3245 : && tree_int_cst_sgn (length) == -1)
6288 : : {
6289 : 84 : error_at (OMP_CLAUSE_LOCATION (c),
6290 : : "negative length in array section in %qs clause",
6291 : 84 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6292 : 84 : return error_mark_node;
6293 : : }
6294 : : /* If there is a pointer type anywhere but in the very first
6295 : : array-section-subscript, the array section could be non-contiguous. */
6296 : 4254 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6297 : 4212 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6298 : 7983 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
6299 : : {
6300 : : /* If any prior dimension has a non-one length, then deem this
6301 : : array section as non-contiguous. */
6302 : 158 : for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
6303 : 69 : d = TREE_OPERAND (d, 0))
6304 : : {
6305 : 89 : tree d_length = TREE_OPERAND (d, 2);
6306 : 89 : if (d_length == NULL_TREE || !integer_onep (d_length))
6307 : : {
6308 : 20 : error_at (OMP_CLAUSE_LOCATION (c),
6309 : : "array section is not contiguous in %qs clause",
6310 : 20 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6311 : 20 : return error_mark_node;
6312 : : }
6313 : : }
6314 : : }
6315 : : }
6316 : : else
6317 : : {
6318 : 57 : error_at (OMP_CLAUSE_LOCATION (c),
6319 : : "%qE does not have pointer or array type", ret);
6320 : 57 : return error_mark_node;
6321 : : }
6322 : 9165 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6323 : 8262 : types.safe_push (TREE_TYPE (ret));
6324 : : /* We will need to evaluate lb more than once. */
6325 : 9165 : tree lb = cp_save_expr (low_bound);
6326 : 9165 : if (lb != low_bound)
6327 : : {
6328 : 716 : TREE_OPERAND (t, 1) = lb;
6329 : 716 : low_bound = lb;
6330 : : }
6331 : : /* Temporarily disable -fstrong-eval-order for array reductions.
6332 : : The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
6333 : : is something the middle-end can't cope with and more importantly,
6334 : : it needs to be the actual base variable that is privatized, not some
6335 : : temporary assigned previous value of it. That, together with OpenMP
6336 : : saying how many times the side-effects are evaluated is unspecified,
6337 : : makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
6338 : 9165 : warning_sentinel s (flag_strong_eval_order,
6339 : 9165 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6340 : 8152 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6341 : 18449 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
6342 : 9165 : ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
6343 : : tf_warning_or_error);
6344 : 9165 : return ret;
6345 : 9165 : }
6346 : :
6347 : : /* Handle array sections for clause C. */
6348 : :
6349 : : static bool
6350 : 9258 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
6351 : : {
6352 : 9258 : bool maybe_zero_len = false;
6353 : 9258 : unsigned int first_non_one = 0;
6354 : 9258 : auto_vec<tree, 10> types;
6355 : 9258 : tree *tp = &OMP_CLAUSE_DECL (c);
6356 : 9258 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6357 : 8301 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6358 : 9464 : && OMP_ITERATOR_DECL_P (*tp))
6359 : 258 : tp = &TREE_VALUE (*tp);
6360 : 9258 : tree first = handle_omp_array_sections_1 (c, *tp, types,
6361 : : maybe_zero_len, first_non_one,
6362 : : ort);
6363 : 9258 : if (first == error_mark_node)
6364 : : return true;
6365 : 8288 : if (first == NULL_TREE)
6366 : : return false;
6367 : 7495 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6368 : 7495 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6369 : : {
6370 : 849 : tree t = *tp;
6371 : 849 : tree tem = NULL_TREE;
6372 : 849 : if (processing_template_decl)
6373 : : return false;
6374 : : /* Need to evaluate side effects in the length expressions
6375 : : if any. */
6376 : 750 : while (TREE_CODE (t) == TREE_LIST)
6377 : : {
6378 : 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
6379 : : {
6380 : 0 : if (tem == NULL_TREE)
6381 : : tem = TREE_VALUE (t);
6382 : : else
6383 : 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
6384 : 0 : TREE_VALUE (t), tem);
6385 : : }
6386 : 0 : t = TREE_CHAIN (t);
6387 : : }
6388 : 750 : if (tem)
6389 : 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
6390 : 750 : *tp = first;
6391 : : }
6392 : : else
6393 : : {
6394 : 6646 : unsigned int num = types.length (), i;
6395 : 6646 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
6396 : 6646 : tree condition = NULL_TREE;
6397 : :
6398 : 6646 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
6399 : 3 : maybe_zero_len = true;
6400 : 6646 : if (processing_template_decl && maybe_zero_len)
6401 : : return false;
6402 : :
6403 : 13982 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
6404 : 7414 : t = TREE_OPERAND (t, 0))
6405 : : {
6406 : 7485 : gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
6407 : :
6408 : 7485 : tree low_bound = TREE_OPERAND (t, 1);
6409 : 7485 : tree length = TREE_OPERAND (t, 2);
6410 : :
6411 : 7485 : i--;
6412 : 7485 : if (low_bound
6413 : 6090 : && TREE_CODE (low_bound) == INTEGER_CST
6414 : 12964 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6415 : 5479 : > TYPE_PRECISION (sizetype))
6416 : 0 : low_bound = fold_convert (sizetype, low_bound);
6417 : 7485 : if (length
6418 : 6966 : && TREE_CODE (length) == INTEGER_CST
6419 : 12559 : && TYPE_PRECISION (TREE_TYPE (length))
6420 : 5074 : > TYPE_PRECISION (sizetype))
6421 : 0 : length = fold_convert (sizetype, length);
6422 : 7485 : if (low_bound == NULL_TREE)
6423 : 1395 : low_bound = integer_zero_node;
6424 : 7485 : if (!maybe_zero_len && i > first_non_one)
6425 : : {
6426 : 629 : if (integer_nonzerop (low_bound))
6427 : 34 : goto do_warn_noncontiguous;
6428 : 595 : if (length != NULL_TREE
6429 : 273 : && TREE_CODE (length) == INTEGER_CST
6430 : 273 : && TYPE_DOMAIN (types[i])
6431 : 273 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
6432 : 868 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
6433 : : == INTEGER_CST)
6434 : : {
6435 : 273 : tree size;
6436 : 273 : size = size_binop (PLUS_EXPR,
6437 : : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6438 : : size_one_node);
6439 : 273 : if (!tree_int_cst_equal (length, size))
6440 : : {
6441 : 37 : do_warn_noncontiguous:
6442 : 142 : error_at (OMP_CLAUSE_LOCATION (c),
6443 : : "array section is not contiguous in %qs "
6444 : : "clause",
6445 : 71 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6446 : 71 : return true;
6447 : : }
6448 : : }
6449 : 558 : if (!processing_template_decl
6450 : 390 : && length != NULL_TREE
6451 : 723 : && TREE_SIDE_EFFECTS (length))
6452 : : {
6453 : 0 : if (side_effects == NULL_TREE)
6454 : : side_effects = length;
6455 : : else
6456 : 0 : side_effects = build2 (COMPOUND_EXPR,
6457 : 0 : TREE_TYPE (side_effects),
6458 : : length, side_effects);
6459 : : }
6460 : : }
6461 : 6856 : else if (processing_template_decl)
6462 : 698 : continue;
6463 : : else
6464 : : {
6465 : 6158 : tree l;
6466 : :
6467 : 6158 : if (i > first_non_one
6468 : 6158 : && ((length && integer_nonzerop (length))
6469 : 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6470 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6471 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
6472 : 0 : continue;
6473 : 6158 : if (length)
6474 : 6041 : l = fold_convert (sizetype, length);
6475 : : else
6476 : : {
6477 : 117 : l = size_binop (PLUS_EXPR,
6478 : : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6479 : : size_one_node);
6480 : 117 : l = size_binop (MINUS_EXPR, l,
6481 : : fold_convert (sizetype, low_bound));
6482 : : }
6483 : 6158 : if (i > first_non_one)
6484 : : {
6485 : 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
6486 : : size_zero_node);
6487 : 0 : if (condition == NULL_TREE)
6488 : : condition = l;
6489 : : else
6490 : 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
6491 : : l, condition);
6492 : : }
6493 : 6158 : else if (size == NULL_TREE)
6494 : : {
6495 : 5880 : size = size_in_bytes (TREE_TYPE (types[i]));
6496 : 5880 : tree eltype = TREE_TYPE (types[num - 1]);
6497 : 5949 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6498 : 69 : eltype = TREE_TYPE (eltype);
6499 : 5880 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6500 : 5130 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6501 : 10257 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6502 : 1599 : size = size_binop (EXACT_DIV_EXPR, size,
6503 : : size_in_bytes (eltype));
6504 : 5880 : size = size_binop (MULT_EXPR, size, l);
6505 : 5880 : if (condition)
6506 : 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
6507 : : size, size_zero_node);
6508 : : }
6509 : : else
6510 : 278 : size = size_binop (MULT_EXPR, size, l);
6511 : : }
6512 : : }
6513 : 6497 : if (!processing_template_decl)
6514 : : {
6515 : 5880 : if (side_effects)
6516 : 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
6517 : 5880 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6518 : 5130 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6519 : 10257 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6520 : : {
6521 : 1599 : size = size_binop (MINUS_EXPR, size, size_one_node);
6522 : 1599 : size = save_expr (size);
6523 : 1599 : tree index_type = build_index_type (size);
6524 : 1599 : tree eltype = TREE_TYPE (first);
6525 : 1628 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6526 : 29 : eltype = TREE_TYPE (eltype);
6527 : 1599 : tree type = build_array_type (eltype, index_type);
6528 : 1599 : tree ptype = build_pointer_type (eltype);
6529 : 1599 : if (TYPE_REF_P (TREE_TYPE (t))
6530 : 1599 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
6531 : 152 : t = convert_from_reference (t);
6532 : 1447 : else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6533 : 629 : t = build_fold_addr_expr (t);
6534 : 1599 : tree t2 = build_fold_addr_expr (first);
6535 : 1599 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6536 : : ptrdiff_type_node, t2);
6537 : 1599 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
6538 : : ptrdiff_type_node, t2,
6539 : 1599 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6540 : : ptrdiff_type_node, t));
6541 : 1599 : if (tree_fits_shwi_p (t2))
6542 : 1261 : t = build2 (MEM_REF, type, t,
6543 : 1261 : build_int_cst (ptype, tree_to_shwi (t2)));
6544 : : else
6545 : : {
6546 : 338 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6547 : : sizetype, t2);
6548 : 338 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
6549 : 338 : TREE_TYPE (t), t, t2);
6550 : 338 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
6551 : : }
6552 : 1599 : OMP_CLAUSE_DECL (c) = t;
6553 : 7479 : return false;
6554 : : }
6555 : 4281 : OMP_CLAUSE_DECL (c) = first;
6556 : 4281 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
6557 : : return false;
6558 : 4255 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
6559 : 4255 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
6560 : 3715 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
6561 : 3703 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
6562 : 4231 : OMP_CLAUSE_SIZE (c) = size;
6563 : 4255 : if (TREE_CODE (t) == FIELD_DECL)
6564 : 3 : t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6565 : :
6566 : 4255 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6567 : : return false;
6568 : :
6569 : 3727 : if (TREE_CODE (first) == INDIRECT_REF)
6570 : : {
6571 : : /* Detect and skip adding extra nodes for pointer-to-member
6572 : : mappings. These are unsupported for now. */
6573 : 2404 : tree tmp = TREE_OPERAND (first, 0);
6574 : :
6575 : 2404 : if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
6576 : 1911 : tmp = TREE_OPERAND (tmp, 0);
6577 : :
6578 : 2404 : if (TREE_CODE (tmp) == INDIRECT_REF)
6579 : 158 : tmp = TREE_OPERAND (tmp, 0);
6580 : :
6581 : 2404 : if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
6582 : : {
6583 : 463 : tree offset = TREE_OPERAND (tmp, 1);
6584 : 463 : STRIP_NOPS (offset);
6585 : 463 : if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
6586 : : {
6587 : 36 : sorry_at (OMP_CLAUSE_LOCATION (c),
6588 : : "pointer-to-member mapping %qE not supported",
6589 : 18 : OMP_CLAUSE_DECL (c));
6590 : 18 : return true;
6591 : : }
6592 : : }
6593 : : }
6594 : :
6595 : : /* FIRST represents the first item of data that we are mapping.
6596 : : E.g. if we're mapping an array, FIRST might resemble
6597 : : "foo.bar.myarray[0]". */
6598 : :
6599 : 3709 : auto_vec<omp_addr_token *, 10> addr_tokens;
6600 : :
6601 : 3709 : if (!omp_parse_expr (addr_tokens, first))
6602 : : return true;
6603 : :
6604 : 3709 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6605 : :
6606 : 3709 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
6607 : 3709 : if (nc != error_mark_node)
6608 : : {
6609 : 3709 : using namespace omp_addr_tokenizer;
6610 : :
6611 : 3709 : if (ai.maybe_zero_length_array_section (c))
6612 : 3685 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
6613 : :
6614 : : /* !!! If we're accessing a base decl via chained access
6615 : : methods (e.g. multiple indirections), duplicate clause
6616 : : detection won't work properly. Skip it in that case. */
6617 : 3709 : if ((addr_tokens[0]->type == STRUCTURE_BASE
6618 : 2692 : || addr_tokens[0]->type == ARRAY_BASE)
6619 : 3709 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
6620 : 3698 : && addr_tokens[1]->type == ACCESS_METHOD
6621 : 7407 : && omp_access_chain_p (addr_tokens, 1))
6622 : 216 : c = nc;
6623 : :
6624 : 3709 : return false;
6625 : : }
6626 : 7418 : }
6627 : : }
6628 : : return false;
6629 : 9258 : }
6630 : :
6631 : : /* Return identifier to look up for omp declare reduction. */
6632 : :
6633 : : tree
6634 : 7081 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
6635 : : {
6636 : 7081 : const char *p = NULL;
6637 : 7081 : const char *m = NULL;
6638 : 7081 : switch (reduction_code)
6639 : : {
6640 : 4188 : case PLUS_EXPR:
6641 : 4188 : case MULT_EXPR:
6642 : 4188 : case MINUS_EXPR:
6643 : 4188 : case BIT_AND_EXPR:
6644 : 4188 : case BIT_XOR_EXPR:
6645 : 4188 : case BIT_IOR_EXPR:
6646 : 4188 : case TRUTH_ANDIF_EXPR:
6647 : 4188 : case TRUTH_ORIF_EXPR:
6648 : 4188 : reduction_id = ovl_op_identifier (false, reduction_code);
6649 : 4188 : break;
6650 : : case MIN_EXPR:
6651 : : p = "min";
6652 : : break;
6653 : : case MAX_EXPR:
6654 : : p = "max";
6655 : : break;
6656 : : default:
6657 : : break;
6658 : : }
6659 : :
6660 : 4188 : if (p == NULL)
6661 : : {
6662 : 6917 : if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
6663 : 0 : return error_mark_node;
6664 : 6917 : p = IDENTIFIER_POINTER (reduction_id);
6665 : : }
6666 : :
6667 : 7081 : if (type != NULL_TREE)
6668 : 2031 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6669 : :
6670 : 7081 : const char prefix[] = "omp declare reduction ";
6671 : 7081 : size_t lenp = sizeof (prefix);
6672 : 7081 : if (strncmp (p, prefix, lenp - 1) == 0)
6673 : 2031 : lenp = 1;
6674 : 7081 : size_t len = strlen (p);
6675 : 7081 : size_t lenm = m ? strlen (m) + 1 : 0;
6676 : 7081 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6677 : 7081 : if (lenp > 1)
6678 : 5050 : memcpy (name, prefix, lenp - 1);
6679 : 7081 : memcpy (name + lenp - 1, p, len + 1);
6680 : 7081 : if (m)
6681 : : {
6682 : 2031 : name[lenp + len - 1] = '~';
6683 : 2031 : memcpy (name + lenp + len, m, lenm);
6684 : : }
6685 : 7081 : return get_identifier (name);
6686 : : }
6687 : :
6688 : : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
6689 : : FUNCTION_DECL or NULL_TREE if not found. */
6690 : :
6691 : : static tree
6692 : 1287 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
6693 : : vec<tree> *ambiguousp)
6694 : : {
6695 : 1287 : tree orig_id = id;
6696 : 1287 : tree baselink = NULL_TREE;
6697 : 1287 : if (identifier_p (id))
6698 : : {
6699 : 1259 : cp_id_kind idk;
6700 : 1259 : bool nonint_cst_expression_p;
6701 : 1259 : const char *error_msg;
6702 : 1259 : id = omp_reduction_id (ERROR_MARK, id, type);
6703 : 1259 : tree decl = lookup_name (id);
6704 : 1259 : if (decl == NULL_TREE)
6705 : 80 : decl = error_mark_node;
6706 : 1259 : id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
6707 : : &nonint_cst_expression_p, false, true, false,
6708 : : false, &error_msg, loc);
6709 : 1259 : if (idk == CP_ID_KIND_UNQUALIFIED
6710 : 1339 : && identifier_p (id))
6711 : : {
6712 : 80 : vec<tree, va_gc> *args = NULL;
6713 : 80 : vec_safe_push (args, build_reference_type (type));
6714 : 80 : id = perform_koenig_lookup (id, args, tf_none);
6715 : : }
6716 : : }
6717 : 28 : else if (TREE_CODE (id) == SCOPE_REF)
6718 : 28 : id = lookup_qualified_name (TREE_OPERAND (id, 0),
6719 : : omp_reduction_id (ERROR_MARK,
6720 : 28 : TREE_OPERAND (id, 1),
6721 : : type),
6722 : : LOOK_want::NORMAL, false);
6723 : 1287 : tree fns = id;
6724 : 1287 : id = NULL_TREE;
6725 : 1287 : if (fns && is_overloaded_fn (fns))
6726 : : {
6727 : 1213 : for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
6728 : : {
6729 : 1213 : tree fndecl = *iter;
6730 : 1213 : if (TREE_CODE (fndecl) == FUNCTION_DECL)
6731 : : {
6732 : 1213 : tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
6733 : 1213 : if (same_type_p (TREE_TYPE (argtype), type))
6734 : : {
6735 : 1213 : id = fndecl;
6736 : 1213 : break;
6737 : : }
6738 : : }
6739 : : }
6740 : :
6741 : 1213 : if (id && BASELINK_P (fns))
6742 : : {
6743 : 74 : if (baselinkp)
6744 : 0 : *baselinkp = fns;
6745 : : else
6746 : 74 : baselink = fns;
6747 : : }
6748 : : }
6749 : :
6750 : 1287 : if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
6751 : : {
6752 : 35 : auto_vec<tree> ambiguous;
6753 : 35 : tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
6754 : 35 : unsigned int ix;
6755 : 35 : if (ambiguousp == NULL)
6756 : 19 : ambiguousp = &ambiguous;
6757 : 73 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
6758 : : {
6759 : 52 : id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
6760 : : baselinkp ? baselinkp : &baselink,
6761 : : ambiguousp);
6762 : 38 : if (id == NULL_TREE)
6763 : 14 : continue;
6764 : 24 : if (!ambiguousp->is_empty ())
6765 : 3 : ambiguousp->safe_push (id);
6766 : 21 : else if (ret != NULL_TREE)
6767 : : {
6768 : 6 : ambiguousp->safe_push (ret);
6769 : 6 : ambiguousp->safe_push (id);
6770 : 6 : ret = NULL_TREE;
6771 : : }
6772 : : else
6773 : 15 : ret = id;
6774 : : }
6775 : 35 : if (ambiguousp != &ambiguous)
6776 : 16 : return ret;
6777 : 19 : if (!ambiguous.is_empty ())
6778 : : {
6779 : 6 : auto_diagnostic_group d;
6780 : 6 : const char *str = _("candidates are:");
6781 : 6 : unsigned int idx;
6782 : 6 : tree udr;
6783 : 6 : error_at (loc, "user defined reduction lookup is ambiguous");
6784 : 27 : FOR_EACH_VEC_ELT (ambiguous, idx, udr)
6785 : : {
6786 : 15 : inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
6787 : 15 : if (idx == 0)
6788 : 6 : str = get_spaces (str);
6789 : : }
6790 : 6 : ret = error_mark_node;
6791 : 6 : baselink = NULL_TREE;
6792 : 6 : }
6793 : 19 : id = ret;
6794 : 35 : }
6795 : 1271 : if (id && baselink)
6796 : 74 : perform_or_defer_access_check (BASELINK_BINFO (baselink),
6797 : : id, id, tf_warning_or_error);
6798 : : return id;
6799 : : }
6800 : :
6801 : : /* Return identifier to look up for omp declare mapper. */
6802 : :
6803 : : tree
6804 : 3907 : omp_mapper_id (tree mapper_id, tree type)
6805 : : {
6806 : 3907 : const char *p = NULL;
6807 : 3907 : const char *m = NULL;
6808 : :
6809 : 3907 : if (mapper_id == NULL_TREE)
6810 : : p = "";
6811 : 68 : else if (TREE_CODE (mapper_id) == IDENTIFIER_NODE)
6812 : 68 : p = IDENTIFIER_POINTER (mapper_id);
6813 : : else
6814 : 0 : return error_mark_node;
6815 : :
6816 : 3907 : if (type != NULL_TREE)
6817 : 3905 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6818 : :
6819 : 3907 : const char prefix[] = "omp declare mapper ";
6820 : 3907 : size_t lenp = sizeof (prefix);
6821 : 3907 : if (strncmp (p, prefix, lenp - 1) == 0)
6822 : 2 : lenp = 1;
6823 : 3907 : size_t len = strlen (p);
6824 : 3907 : size_t lenm = m ? strlen (m) + 1 : 0;
6825 : 3907 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6826 : 3907 : memcpy (name, prefix, lenp - 1);
6827 : 3907 : memcpy (name + lenp - 1, p, len + 1);
6828 : 3907 : if (m)
6829 : : {
6830 : 3905 : name[lenp + len - 1] = '~';
6831 : 3905 : memcpy (name + lenp + len, m, lenm);
6832 : : }
6833 : 3907 : return get_identifier (name);
6834 : : }
6835 : :
6836 : : tree
6837 : 6957 : cxx_omp_mapper_lookup (tree id, tree type)
6838 : : {
6839 : 6957 : if (!RECORD_OR_UNION_TYPE_P (type))
6840 : : return NULL_TREE;
6841 : 3694 : id = omp_mapper_id (id, type);
6842 : 3694 : return lookup_name (id);
6843 : : }
6844 : :
6845 : : tree
6846 : 273 : cxx_omp_extract_mapper_directive (tree vardecl)
6847 : : {
6848 : 273 : gcc_assert (TREE_CODE (vardecl) == VAR_DECL);
6849 : :
6850 : : /* Instantiate the decl if we haven't already. */
6851 : 273 : mark_used (vardecl);
6852 : 273 : tree body = DECL_INITIAL (vardecl);
6853 : :
6854 : 273 : if (TREE_CODE (body) == STATEMENT_LIST)
6855 : : {
6856 : 0 : tree_stmt_iterator tsi = tsi_start (body);
6857 : 0 : gcc_assert (TREE_CODE (tsi_stmt (tsi)) == DECL_EXPR);
6858 : 0 : tsi_next (&tsi);
6859 : 0 : body = tsi_stmt (tsi);
6860 : : }
6861 : :
6862 : 273 : gcc_assert (TREE_CODE (body) == OMP_DECLARE_MAPPER);
6863 : :
6864 : 273 : return body;
6865 : : }
6866 : :
6867 : : /* For now we can handle singleton OMP_ARRAY_SECTIONs with custom mappers, but
6868 : : nothing more complicated. */
6869 : :
6870 : : tree
6871 : 1510 : cxx_omp_map_array_section (location_t loc, tree t)
6872 : : {
6873 : 1510 : tree low = TREE_OPERAND (t, 1);
6874 : 1510 : tree len = TREE_OPERAND (t, 2);
6875 : :
6876 : 1510 : if (len && integer_onep (len))
6877 : : {
6878 : 237 : t = TREE_OPERAND (t, 0);
6879 : :
6880 : 237 : if (!low)
6881 : 9 : low = integer_zero_node;
6882 : :
6883 : 237 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
6884 : 5 : t = convert_from_reference (t);
6885 : :
6886 : 237 : t = build_array_ref (loc, t, low);
6887 : : }
6888 : :
6889 : 1510 : return t;
6890 : : }
6891 : :
6892 : : /* Helper function for cp_parser_omp_declare_reduction_exprs
6893 : : and tsubst_omp_udr.
6894 : : Remove CLEANUP_STMT for data (omp_priv variable).
6895 : : Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
6896 : : DECL_EXPR. */
6897 : :
6898 : : tree
6899 : 4395 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
6900 : : {
6901 : 4395 : if (TYPE_P (*tp))
6902 : 227 : *walk_subtrees = 0;
6903 : 4168 : else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
6904 : 52 : *tp = CLEANUP_BODY (*tp);
6905 : 4116 : else if (TREE_CODE (*tp) == DECL_EXPR)
6906 : : {
6907 : 307 : tree decl = DECL_EXPR_DECL (*tp);
6908 : 307 : if (!processing_template_decl
6909 : 258 : && decl == (tree) data
6910 : 258 : && DECL_INITIAL (decl)
6911 : 399 : && DECL_INITIAL (decl) != error_mark_node)
6912 : : {
6913 : 92 : tree list = NULL_TREE;
6914 : 92 : append_to_statement_list_force (*tp, &list);
6915 : 92 : tree init_expr = build2 (INIT_EXPR, void_type_node,
6916 : 92 : decl, DECL_INITIAL (decl));
6917 : 92 : DECL_INITIAL (decl) = NULL_TREE;
6918 : 92 : append_to_statement_list_force (init_expr, &list);
6919 : 92 : *tp = list;
6920 : : }
6921 : : }
6922 : 4395 : return NULL_TREE;
6923 : : }
6924 : :
6925 : : /* Data passed from cp_check_omp_declare_reduction to
6926 : : cp_check_omp_declare_reduction_r. */
6927 : :
6928 : : struct cp_check_omp_declare_reduction_data
6929 : : {
6930 : : location_t loc;
6931 : : tree stmts[7];
6932 : : bool combiner_p;
6933 : : };
6934 : :
6935 : : /* Helper function for cp_check_omp_declare_reduction, called via
6936 : : cp_walk_tree. */
6937 : :
6938 : : static tree
6939 : 14949 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
6940 : : {
6941 : 14949 : struct cp_check_omp_declare_reduction_data *udr_data
6942 : : = (struct cp_check_omp_declare_reduction_data *) data;
6943 : 14949 : if (SSA_VAR_P (*tp)
6944 : 2687 : && !DECL_ARTIFICIAL (*tp)
6945 : 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
6946 : 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
6947 : : {
6948 : 135 : location_t loc = udr_data->loc;
6949 : 135 : if (udr_data->combiner_p)
6950 : 45 : error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
6951 : : "variable %qD which is not %<omp_out%> nor %<omp_in%>",
6952 : : *tp);
6953 : : else
6954 : 90 : error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
6955 : : "to variable %qD which is not %<omp_priv%> nor "
6956 : : "%<omp_orig%>",
6957 : : *tp);
6958 : 135 : return *tp;
6959 : : }
6960 : : return NULL_TREE;
6961 : : }
6962 : :
6963 : : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
6964 : :
6965 : : bool
6966 : 1099 : cp_check_omp_declare_reduction (tree udr)
6967 : : {
6968 : 1099 : tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
6969 : 1099 : gcc_assert (TYPE_REF_P (type));
6970 : 1099 : type = TREE_TYPE (type);
6971 : 1099 : int i;
6972 : 1099 : location_t loc = DECL_SOURCE_LOCATION (udr);
6973 : :
6974 : 1099 : if (type == error_mark_node)
6975 : : return false;
6976 : 1099 : if (ARITHMETIC_TYPE_P (type))
6977 : : {
6978 : : static enum tree_code predef_codes[]
6979 : : = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
6980 : : BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
6981 : 3276 : for (i = 0; i < 8; i++)
6982 : : {
6983 : 2918 : tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
6984 : 2918 : const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
6985 : 2918 : const char *n2 = IDENTIFIER_POINTER (id);
6986 : 2918 : if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
6987 : 2918 : && (n1[IDENTIFIER_LENGTH (id)] == '~'
6988 : 0 : || n1[IDENTIFIER_LENGTH (id)] == '\0'))
6989 : : break;
6990 : : }
6991 : :
6992 : 376 : if (i == 8
6993 : 358 : && TREE_CODE (type) != COMPLEX_EXPR)
6994 : : {
6995 : 358 : const char prefix_minmax[] = "omp declare reduction m";
6996 : 358 : size_t prefix_size = sizeof (prefix_minmax) - 1;
6997 : 358 : const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
6998 : 358 : if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
6999 : : prefix_minmax, prefix_size) == 0
7000 : 10 : && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
7001 : 4 : || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
7002 : 368 : && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
7003 : 6 : i = 0;
7004 : : }
7005 : 376 : if (i < 8)
7006 : : {
7007 : 24 : error_at (loc, "predeclared arithmetic type %qT in "
7008 : : "%<#pragma omp declare reduction%>", type);
7009 : 24 : return false;
7010 : : }
7011 : : }
7012 : : else if (FUNC_OR_METHOD_TYPE_P (type)
7013 : : || TREE_CODE (type) == ARRAY_TYPE)
7014 : : {
7015 : 24 : error_at (loc, "function or array type %qT in "
7016 : : "%<#pragma omp declare reduction%>", type);
7017 : 24 : return false;
7018 : : }
7019 : : else if (TYPE_REF_P (type))
7020 : : {
7021 : 0 : error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
7022 : : type);
7023 : 0 : return false;
7024 : : }
7025 : 699 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
7026 : : {
7027 : 24 : error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
7028 : : "type %qT in %<#pragma omp declare reduction%>", type);
7029 : 24 : return false;
7030 : : }
7031 : :
7032 : 1027 : tree body = DECL_SAVED_TREE (udr);
7033 : 1027 : if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
7034 : : return true;
7035 : :
7036 : 841 : tree_stmt_iterator tsi;
7037 : 841 : struct cp_check_omp_declare_reduction_data data;
7038 : 841 : memset (data.stmts, 0, sizeof data.stmts);
7039 : 841 : for (i = 0, tsi = tsi_start (body);
7040 : 4675 : i < 7 && !tsi_end_p (tsi);
7041 : 3834 : i++, tsi_next (&tsi))
7042 : 3834 : data.stmts[i] = tsi_stmt (tsi);
7043 : 841 : data.loc = loc;
7044 : 841 : gcc_assert (tsi_end_p (tsi));
7045 : 841 : if (i >= 3)
7046 : : {
7047 : 841 : gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
7048 : : && TREE_CODE (data.stmts[1]) == DECL_EXPR);
7049 : 841 : if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
7050 : : return true;
7051 : 796 : data.combiner_p = true;
7052 : 796 : if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
7053 : : &data, NULL))
7054 : 45 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
7055 : : }
7056 : 796 : if (i >= 6)
7057 : : {
7058 : 336 : gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
7059 : : && TREE_CODE (data.stmts[4]) == DECL_EXPR);
7060 : 336 : data.combiner_p = false;
7061 : 336 : if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
7062 : : &data, NULL)
7063 : 336 : || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
7064 : : cp_check_omp_declare_reduction_r, &data, NULL))
7065 : 90 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */);
7066 : 336 : if (i == 7)
7067 : 198 : gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
7068 : : }
7069 : : return true;
7070 : : }
7071 : :
7072 : : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
7073 : : an inline call. But, remap
7074 : : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
7075 : : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
7076 : :
7077 : : static tree
7078 : 2197 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
7079 : : tree decl, tree placeholder)
7080 : : {
7081 : 2197 : copy_body_data id;
7082 : 2197 : hash_map<tree, tree> decl_map;
7083 : :
7084 : 2197 : decl_map.put (omp_decl1, placeholder);
7085 : 2197 : decl_map.put (omp_decl2, decl);
7086 : 2197 : memset (&id, 0, sizeof (id));
7087 : 2197 : id.src_fn = DECL_CONTEXT (omp_decl1);
7088 : 2197 : id.dst_fn = current_function_decl;
7089 : 2197 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
7090 : 2197 : id.decl_map = &decl_map;
7091 : :
7092 : 2197 : id.copy_decl = copy_decl_no_change;
7093 : 2197 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
7094 : 2197 : id.transform_new_cfg = true;
7095 : 2197 : id.transform_return_to_modify = false;
7096 : 2197 : id.eh_lp_nr = 0;
7097 : 2197 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
7098 : 2197 : return stmt;
7099 : 2197 : }
7100 : :
7101 : : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
7102 : : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
7103 : :
7104 : : static tree
7105 : 15438 : find_omp_placeholder_r (tree *tp, int *, void *data)
7106 : : {
7107 : 15438 : if (*tp == (tree) data)
7108 : 265 : return *tp;
7109 : : return NULL_TREE;
7110 : : }
7111 : :
7112 : : /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
7113 : : Return true if there is some error and the clause should be removed. */
7114 : :
7115 : : static bool
7116 : 8852 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
7117 : : {
7118 : 8852 : tree t = OMP_CLAUSE_DECL (c);
7119 : 8852 : bool predefined = false;
7120 : 8852 : if (TREE_CODE (t) == TREE_LIST)
7121 : : {
7122 : 0 : gcc_assert (processing_template_decl);
7123 : : return false;
7124 : : }
7125 : 8852 : tree type = TREE_TYPE (t);
7126 : 8852 : if (TREE_CODE (t) == MEM_REF)
7127 : 1596 : type = TREE_TYPE (type);
7128 : 8852 : if (TYPE_REF_P (type))
7129 : 527 : type = TREE_TYPE (type);
7130 : 8852 : if (TREE_CODE (type) == ARRAY_TYPE)
7131 : : {
7132 : 350 : tree oatype = type;
7133 : 350 : gcc_assert (TREE_CODE (t) != MEM_REF);
7134 : 703 : while (TREE_CODE (type) == ARRAY_TYPE)
7135 : 353 : type = TREE_TYPE (type);
7136 : 350 : if (!processing_template_decl)
7137 : : {
7138 : 255 : t = require_complete_type (t);
7139 : 255 : if (t == error_mark_node
7140 : 255 : || !complete_type_or_else (oatype, NULL_TREE))
7141 : 9 : return true;
7142 : 246 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
7143 : : TYPE_SIZE_UNIT (type));
7144 : 246 : if (integer_zerop (size))
7145 : : {
7146 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7147 : : "%qE in %<reduction%> clause is a zero size array",
7148 : : omp_clause_printable_decl (t));
7149 : 3 : return true;
7150 : : }
7151 : 243 : size = size_binop (MINUS_EXPR, size, size_one_node);
7152 : 243 : size = save_expr (size);
7153 : 243 : tree index_type = build_index_type (size);
7154 : 243 : tree atype = build_array_type (type, index_type);
7155 : 243 : tree ptype = build_pointer_type (type);
7156 : 243 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7157 : 146 : t = build_fold_addr_expr (t);
7158 : 243 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
7159 : 243 : OMP_CLAUSE_DECL (c) = t;
7160 : : }
7161 : : }
7162 : 8840 : if (type == error_mark_node)
7163 : : return true;
7164 : 8837 : else if (ARITHMETIC_TYPE_P (type))
7165 : 7588 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
7166 : : {
7167 : : case PLUS_EXPR:
7168 : : case MULT_EXPR:
7169 : : case MINUS_EXPR:
7170 : : case TRUTH_ANDIF_EXPR:
7171 : : case TRUTH_ORIF_EXPR:
7172 : : predefined = true;
7173 : : break;
7174 : 246 : case MIN_EXPR:
7175 : 246 : case MAX_EXPR:
7176 : 246 : if (TREE_CODE (type) == COMPLEX_TYPE)
7177 : : break;
7178 : : predefined = true;
7179 : : break;
7180 : 111 : case BIT_AND_EXPR:
7181 : 111 : case BIT_IOR_EXPR:
7182 : 111 : case BIT_XOR_EXPR:
7183 : 111 : if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
7184 : : break;
7185 : : predefined = true;
7186 : : break;
7187 : : default:
7188 : : break;
7189 : : }
7190 : 1249 : else if (TYPE_READONLY (type))
7191 : : {
7192 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
7193 : : "%qE has const type for %<reduction%>",
7194 : : omp_clause_printable_decl (t));
7195 : 9 : return true;
7196 : : }
7197 : 1240 : else if (!processing_template_decl)
7198 : : {
7199 : 1036 : t = require_complete_type (t);
7200 : 1036 : if (t == error_mark_node)
7201 : : return true;
7202 : 1036 : OMP_CLAUSE_DECL (c) = t;
7203 : : }
7204 : :
7205 : 1036 : if (predefined)
7206 : : {
7207 : 7366 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7208 : 7366 : return false;
7209 : : }
7210 : 1462 : else if (processing_template_decl)
7211 : : {
7212 : 213 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
7213 : : return true;
7214 : : return false;
7215 : : }
7216 : :
7217 : 1249 : tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7218 : :
7219 : 1249 : type = TYPE_MAIN_VARIANT (type);
7220 : 1249 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7221 : 1249 : if (id == NULL_TREE)
7222 : 924 : id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
7223 : : NULL_TREE, NULL_TREE);
7224 : 1249 : id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
7225 : 1249 : if (id)
7226 : : {
7227 : 1204 : if (id == error_mark_node)
7228 : : return true;
7229 : 1198 : mark_used (id);
7230 : 1198 : tree body = DECL_SAVED_TREE (id);
7231 : 1198 : if (!body)
7232 : : return true;
7233 : 1195 : if (TREE_CODE (body) == STATEMENT_LIST)
7234 : : {
7235 : 1195 : tree_stmt_iterator tsi;
7236 : 1195 : tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
7237 : 1195 : int i;
7238 : 1195 : tree stmts[7];
7239 : 1195 : tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
7240 : 1195 : atype = TREE_TYPE (atype);
7241 : 1195 : bool need_static_cast = !same_type_p (type, atype);
7242 : 1195 : memset (stmts, 0, sizeof stmts);
7243 : 1195 : for (i = 0, tsi = tsi_start (body);
7244 : 8514 : i < 7 && !tsi_end_p (tsi);
7245 : 7319 : i++, tsi_next (&tsi))
7246 : 7319 : stmts[i] = tsi_stmt (tsi);
7247 : 1195 : gcc_assert (tsi_end_p (tsi));
7248 : :
7249 : 1195 : if (i >= 3)
7250 : : {
7251 : 1195 : gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
7252 : : && TREE_CODE (stmts[1]) == DECL_EXPR);
7253 : 1195 : placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
7254 : 1195 : DECL_ARTIFICIAL (placeholder) = 1;
7255 : 1195 : DECL_IGNORED_P (placeholder) = 1;
7256 : 1195 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
7257 : 1195 : if (TREE_CODE (t) == MEM_REF)
7258 : : {
7259 : 600 : decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
7260 : : type);
7261 : 600 : DECL_ARTIFICIAL (decl_placeholder) = 1;
7262 : 600 : DECL_IGNORED_P (decl_placeholder) = 1;
7263 : 600 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
7264 : : }
7265 : 1195 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
7266 : 285 : cxx_mark_addressable (placeholder);
7267 : 1195 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
7268 : 1195 : && (decl_placeholder
7269 : 149 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7270 : 372 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7271 : 118 : : OMP_CLAUSE_DECL (c));
7272 : 1195 : tree omp_out = placeholder;
7273 : 1195 : tree omp_in = decl_placeholder ? decl_placeholder
7274 : 595 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7275 : 1195 : if (need_static_cast)
7276 : : {
7277 : 7 : tree rtype = build_reference_type (atype);
7278 : 7 : omp_out = build_static_cast (input_location,
7279 : : rtype, omp_out,
7280 : : tf_warning_or_error);
7281 : 7 : omp_in = build_static_cast (input_location,
7282 : : rtype, omp_in,
7283 : : tf_warning_or_error);
7284 : 7 : if (omp_out == error_mark_node || omp_in == error_mark_node)
7285 : 3 : return true;
7286 : 7 : omp_out = convert_from_reference (omp_out);
7287 : 7 : omp_in = convert_from_reference (omp_in);
7288 : : }
7289 : 1195 : OMP_CLAUSE_REDUCTION_MERGE (c)
7290 : 1195 : = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
7291 : 1195 : DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
7292 : : }
7293 : 1195 : if (i >= 6)
7294 : : {
7295 : 1005 : gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
7296 : : && TREE_CODE (stmts[4]) == DECL_EXPR);
7297 : 1005 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
7298 : 1005 : && (decl_placeholder
7299 : 232 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7300 : 844 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7301 : 170 : : OMP_CLAUSE_DECL (c));
7302 : 1005 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
7303 : 216 : cxx_mark_addressable (placeholder);
7304 : 1005 : tree omp_priv = decl_placeholder ? decl_placeholder
7305 : 429 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7306 : 1005 : tree omp_orig = placeholder;
7307 : 1005 : if (need_static_cast)
7308 : : {
7309 : 5 : if (i == 7)
7310 : : {
7311 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
7312 : : "user defined reduction with constructor "
7313 : : "initializer for base class %qT", atype);
7314 : 3 : return true;
7315 : : }
7316 : 2 : tree rtype = build_reference_type (atype);
7317 : 2 : omp_priv = build_static_cast (input_location,
7318 : : rtype, omp_priv,
7319 : : tf_warning_or_error);
7320 : 2 : omp_orig = build_static_cast (input_location,
7321 : : rtype, omp_orig,
7322 : : tf_warning_or_error);
7323 : 2 : if (omp_priv == error_mark_node
7324 : 2 : || omp_orig == error_mark_node)
7325 : : return true;
7326 : 2 : omp_priv = convert_from_reference (omp_priv);
7327 : 2 : omp_orig = convert_from_reference (omp_orig);
7328 : : }
7329 : 1002 : if (i == 6)
7330 : 286 : *need_default_ctor = true;
7331 : 1002 : OMP_CLAUSE_REDUCTION_INIT (c)
7332 : 1002 : = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
7333 : 1002 : DECL_EXPR_DECL (stmts[3]),
7334 : : omp_priv, omp_orig);
7335 : 1002 : if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
7336 : : find_omp_placeholder_r, placeholder, NULL))
7337 : 238 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
7338 : : }
7339 : 190 : else if (i >= 3)
7340 : : {
7341 : 190 : if (CLASS_TYPE_P (type) && !pod_type_p (type))
7342 : 175 : *need_default_ctor = true;
7343 : : else
7344 : : {
7345 : 15 : tree init;
7346 : 15 : tree v = decl_placeholder ? decl_placeholder
7347 : 15 : : convert_from_reference (t);
7348 : 15 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
7349 : 6 : init = build_constructor (TREE_TYPE (v), NULL);
7350 : : else
7351 : 9 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
7352 : 30 : OMP_CLAUSE_REDUCTION_INIT (c)
7353 : 30 : = cp_build_init_expr (v, init);
7354 : : }
7355 : : }
7356 : : }
7357 : : }
7358 : 1237 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7359 : 1192 : *need_dtor = true;
7360 : : else
7361 : : {
7362 : 90 : error_at (OMP_CLAUSE_LOCATION (c),
7363 : : "user defined reduction not found for %qE",
7364 : : omp_clause_printable_decl (t));
7365 : 45 : return true;
7366 : : }
7367 : 1192 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7368 : 600 : gcc_assert (TYPE_SIZE_UNIT (type)
7369 : : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
7370 : : return false;
7371 : : }
7372 : :
7373 : : /* Check an instance of an "omp declare mapper" function. */
7374 : :
7375 : : bool
7376 : 179 : cp_check_omp_declare_mapper (tree udm)
7377 : : {
7378 : 179 : tree type = TREE_TYPE (udm);
7379 : 179 : location_t loc = DECL_SOURCE_LOCATION (udm);
7380 : :
7381 : 179 : if (type == error_mark_node)
7382 : : return false;
7383 : :
7384 : 179 : if (!processing_template_decl && !RECORD_OR_UNION_TYPE_P (type))
7385 : : {
7386 : 15 : error_at (loc, "%qT is not a struct, union or class type in "
7387 : : "%<#pragma omp declare mapper%>", type);
7388 : 15 : return false;
7389 : : }
7390 : 164 : if (!processing_template_decl && CLASSTYPE_VBASECLASSES (type))
7391 : : {
7392 : 3 : error_at (loc, "%qT must not be a virtual base class in "
7393 : : "%<#pragma omp declare mapper%>", type);
7394 : 3 : return false;
7395 : : }
7396 : :
7397 : : return true;
7398 : : }
7399 : :
7400 : : /* Called from finish_struct_1. linear(this) or linear(this:step)
7401 : : clauses might not be finalized yet because the class has been incomplete
7402 : : when parsing #pragma omp declare simd methods. Fix those up now. */
7403 : :
7404 : : void
7405 : 120947 : finish_omp_declare_simd_methods (tree t)
7406 : : {
7407 : 120947 : if (processing_template_decl)
7408 : : return;
7409 : :
7410 : 817357 : for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
7411 : : {
7412 : 1160589 : if (TREE_CODE (x) == USING_DECL
7413 : 696410 : || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
7414 : 464179 : continue;
7415 : 232231 : tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
7416 : 232339 : if (!ods || !TREE_VALUE (ods))
7417 : 232123 : continue;
7418 : 366 : for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
7419 : 258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7420 : 66 : && integer_zerop (OMP_CLAUSE_DECL (c))
7421 : 18 : && OMP_CLAUSE_LINEAR_STEP (c)
7422 : 276 : && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
7423 : : {
7424 : 18 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
7425 : 18 : s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
7426 : 18 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
7427 : 18 : sizetype, s, TYPE_SIZE_UNIT (t));
7428 : 18 : OMP_CLAUSE_LINEAR_STEP (c) = s;
7429 : : }
7430 : : }
7431 : : }
7432 : :
7433 : : /* Adjust sink depend/doacross clause to take into account pointer offsets.
7434 : :
7435 : : Return TRUE if there was a problem processing the offset, and the
7436 : : whole clause should be removed. */
7437 : :
7438 : : static bool
7439 : 295 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
7440 : : {
7441 : 295 : tree t = OMP_CLAUSE_DECL (sink_clause);
7442 : 295 : gcc_assert (TREE_CODE (t) == TREE_LIST);
7443 : :
7444 : : /* Make sure we don't adjust things twice for templates. */
7445 : 295 : if (processing_template_decl)
7446 : : return false;
7447 : :
7448 : 665 : for (; t; t = TREE_CHAIN (t))
7449 : : {
7450 : 388 : tree decl = TREE_VALUE (t);
7451 : 388 : if (TYPE_PTR_P (TREE_TYPE (decl)))
7452 : : {
7453 : 6 : tree offset = TREE_PURPOSE (t);
7454 : 6 : bool neg = wi::neg_p (wi::to_wide (offset));
7455 : 6 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
7456 : 6 : decl = mark_rvalue_use (decl);
7457 : 6 : decl = convert_from_reference (decl);
7458 : 12 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
7459 : : neg ? MINUS_EXPR : PLUS_EXPR,
7460 : : decl, offset);
7461 : 6 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
7462 : : MINUS_EXPR, sizetype,
7463 : : fold_convert (sizetype, t2),
7464 : : fold_convert (sizetype, decl));
7465 : 6 : if (t2 == error_mark_node)
7466 : : return true;
7467 : 6 : TREE_PURPOSE (t) = t2;
7468 : : }
7469 : : }
7470 : : return false;
7471 : : }
7472 : :
7473 : : /* Finish OpenMP iterators ITER. Return true if they are errorneous
7474 : : and clauses containing them should be removed. */
7475 : :
7476 : : static bool
7477 : 610 : cp_omp_finish_iterators (tree iter)
7478 : : {
7479 : 610 : bool ret = false;
7480 : 1385 : for (tree it = iter; it; it = TREE_CHAIN (it))
7481 : : {
7482 : 775 : tree var = TREE_VEC_ELT (it, 0);
7483 : 775 : tree begin = TREE_VEC_ELT (it, 1);
7484 : 775 : tree end = TREE_VEC_ELT (it, 2);
7485 : 775 : tree step = TREE_VEC_ELT (it, 3);
7486 : 775 : tree orig_step;
7487 : 775 : tree type = TREE_TYPE (var);
7488 : 775 : location_t loc = DECL_SOURCE_LOCATION (var);
7489 : 775 : if (type == error_mark_node)
7490 : : {
7491 : 0 : ret = true;
7492 : 218 : continue;
7493 : : }
7494 : 775 : if (type_dependent_expression_p (var))
7495 : 59 : continue;
7496 : 716 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
7497 : : {
7498 : 27 : error_at (loc, "iterator %qD has neither integral nor pointer type",
7499 : : var);
7500 : 27 : ret = true;
7501 : 27 : continue;
7502 : : }
7503 : 689 : else if (TYPE_READONLY (type))
7504 : : {
7505 : 24 : error_at (loc, "iterator %qD has const qualified type", var);
7506 : 24 : ret = true;
7507 : 24 : continue;
7508 : : }
7509 : 665 : if (type_dependent_expression_p (begin)
7510 : 656 : || type_dependent_expression_p (end)
7511 : 1321 : || type_dependent_expression_p (step))
7512 : 15 : continue;
7513 : 650 : else if (error_operand_p (step))
7514 : : {
7515 : 0 : ret = true;
7516 : 0 : continue;
7517 : : }
7518 : 650 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
7519 : : {
7520 : 33 : error_at (EXPR_LOC_OR_LOC (step, loc),
7521 : : "iterator step with non-integral type");
7522 : 21 : ret = true;
7523 : 21 : continue;
7524 : : }
7525 : :
7526 : 629 : begin = mark_rvalue_use (begin);
7527 : 629 : end = mark_rvalue_use (end);
7528 : 629 : step = mark_rvalue_use (step);
7529 : 629 : begin = cp_build_c_cast (input_location, type, begin,
7530 : : tf_warning_or_error);
7531 : 629 : end = cp_build_c_cast (input_location, type, end,
7532 : : tf_warning_or_error);
7533 : 629 : orig_step = step;
7534 : 629 : if (!processing_template_decl)
7535 : 552 : step = orig_step = save_expr (step);
7536 : 629 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
7537 : 629 : step = cp_build_c_cast (input_location, stype, step,
7538 : : tf_warning_or_error);
7539 : 629 : if (POINTER_TYPE_P (type) && !processing_template_decl)
7540 : : {
7541 : 66 : begin = save_expr (begin);
7542 : 66 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
7543 : 66 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
7544 : : fold_convert (sizetype, step),
7545 : : fold_convert (sizetype, begin));
7546 : 66 : step = fold_convert (ssizetype, step);
7547 : : }
7548 : 629 : if (!processing_template_decl)
7549 : : {
7550 : 552 : begin = maybe_constant_value (begin);
7551 : 552 : end = maybe_constant_value (end);
7552 : 552 : step = maybe_constant_value (step);
7553 : 552 : orig_step = maybe_constant_value (orig_step);
7554 : : }
7555 : 629 : if (integer_zerop (step))
7556 : : {
7557 : 27 : error_at (loc, "iterator %qD has zero step", var);
7558 : 27 : ret = true;
7559 : 27 : continue;
7560 : : }
7561 : :
7562 : 602 : if (begin == error_mark_node
7563 : 593 : || end == error_mark_node
7564 : 584 : || step == error_mark_node
7565 : 584 : || orig_step == error_mark_node)
7566 : : {
7567 : 18 : ret = true;
7568 : 18 : continue;
7569 : : }
7570 : :
7571 : 584 : if (!processing_template_decl)
7572 : : {
7573 : 507 : begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
7574 : 507 : end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
7575 : 507 : step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
7576 : 507 : orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
7577 : : orig_step);
7578 : : }
7579 : 584 : hash_set<tree> pset;
7580 : 584 : tree it2;
7581 : 740 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
7582 : : {
7583 : 183 : tree var2 = TREE_VEC_ELT (it2, 0);
7584 : 183 : tree begin2 = TREE_VEC_ELT (it2, 1);
7585 : 183 : tree end2 = TREE_VEC_ELT (it2, 2);
7586 : 183 : tree step2 = TREE_VEC_ELT (it2, 3);
7587 : 183 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
7588 : 183 : if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
7589 : : {
7590 : 9 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
7591 : : "begin expression refers to outer iterator %qD", var);
7592 : 36 : break;
7593 : : }
7594 : 174 : else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
7595 : : {
7596 : 9 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
7597 : : "end expression refers to outer iterator %qD", var);
7598 : 9 : break;
7599 : : }
7600 : 165 : else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
7601 : : {
7602 : 9 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
7603 : : "step expression refers to outer iterator %qD", var);
7604 : 9 : break;
7605 : : }
7606 : : }
7607 : 584 : if (it2)
7608 : : {
7609 : 27 : ret = true;
7610 : 27 : continue;
7611 : : }
7612 : 557 : TREE_VEC_ELT (it, 1) = begin;
7613 : 557 : TREE_VEC_ELT (it, 2) = end;
7614 : 557 : if (processing_template_decl)
7615 : 71 : TREE_VEC_ELT (it, 3) = orig_step;
7616 : : else
7617 : : {
7618 : 486 : TREE_VEC_ELT (it, 3) = step;
7619 : 486 : TREE_VEC_ELT (it, 4) = orig_step;
7620 : : }
7621 : 584 : }
7622 : 610 : return ret;
7623 : : }
7624 : :
7625 : : /* Ensure that pointers are used in OpenACC attach and detach clauses.
7626 : : Return true if an error has been detected. */
7627 : :
7628 : : static bool
7629 : 18250 : cp_oacc_check_attachments (tree c)
7630 : : {
7631 : 18250 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
7632 : : return false;
7633 : :
7634 : : /* OpenACC attach / detach clauses must be pointers. */
7635 : 14355 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
7636 : 14355 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
7637 : : {
7638 : 196 : tree t = OMP_CLAUSE_DECL (c);
7639 : 196 : tree type;
7640 : :
7641 : 232 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7642 : 36 : t = TREE_OPERAND (t, 0);
7643 : :
7644 : 196 : type = TREE_TYPE (t);
7645 : :
7646 : 196 : if (TREE_CODE (type) == REFERENCE_TYPE)
7647 : 36 : type = TREE_TYPE (type);
7648 : :
7649 : 196 : if (TREE_CODE (type) != POINTER_TYPE)
7650 : : {
7651 : 36 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
7652 : : user_omp_clause_code_name (c, true));
7653 : 36 : return true;
7654 : : }
7655 : : }
7656 : :
7657 : : return false;
7658 : : }
7659 : :
7660 : : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
7661 : : happened. */
7662 : :
7663 : : tree
7664 : 813 : cp_finish_omp_init_prefer_type (tree pref_type)
7665 : : {
7666 : 813 : if (processing_template_decl
7667 : 741 : || pref_type == NULL_TREE
7668 : 356 : || TREE_CODE (pref_type) != TREE_LIST)
7669 : : return pref_type;
7670 : :
7671 : 81 : tree t = TREE_PURPOSE (pref_type);
7672 : 81 : char *str = const_cast<char *> (TREE_STRING_POINTER (t));
7673 : 81 : tree fr_list = TREE_VALUE (pref_type);
7674 : 81 : int len = TREE_VEC_LENGTH (fr_list);
7675 : 81 : int cnt = 0;
7676 : :
7677 : 270 : while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
7678 : : {
7679 : 270 : str++;
7680 : 270 : if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
7681 : : {
7682 : : /* Assume a no or a single 'fr'. */
7683 : 150 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7684 : 150 : location_t loc = UNKNOWN_LOCATION;
7685 : 150 : tree value = TREE_VEC_ELT (fr_list, cnt);
7686 : 150 : if (value != NULL_TREE && value != error_mark_node)
7687 : : {
7688 : 126 : loc = EXPR_LOCATION (value);
7689 : 126 : if (value && TREE_CODE (value) == NOP_EXPR)
7690 : 39 : value = TREE_OPERAND (value, 0);
7691 : 126 : value = cp_fully_fold (value);
7692 : : }
7693 : 126 : if (value != NULL_TREE && value != error_mark_node)
7694 : : {
7695 : 126 : if (TREE_CODE (value) != INTEGER_CST
7696 : 126 : || !tree_fits_shwi_p (value))
7697 : 0 : error_at (loc,
7698 : : "expected string literal or "
7699 : : "constant integer expression instead of %qE", value);
7700 : : else
7701 : : {
7702 : 126 : HOST_WIDE_INT n = tree_to_shwi (value);
7703 : 126 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
7704 : : {
7705 : 48 : warning_at (loc, OPT_Wopenmp,
7706 : : "unknown foreign runtime identifier %qwd", n);
7707 : 48 : n = GOMP_INTEROP_IFR_UNKNOWN;
7708 : : }
7709 : 126 : str[0] = (char) n;
7710 : : }
7711 : : }
7712 : 150 : str++;
7713 : : }
7714 : 120 : else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
7715 : : {
7716 : : /* Assume a no or a single 'fr'. */
7717 : 120 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7718 : 120 : str++;
7719 : : }
7720 : 270 : str++;
7721 : 294 : while (str[0] != '\0')
7722 : 24 : str += strlen (str) + 1;
7723 : 270 : str++;
7724 : 270 : cnt++;
7725 : 270 : if (cnt >= len)
7726 : : break;
7727 : : }
7728 : : return t;
7729 : : }
7730 : :
7731 : : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
7732 : : Remove any elements from the list that are invalid. */
7733 : :
7734 : : tree
7735 : 62183 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
7736 : : {
7737 : 62183 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
7738 : 62183 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
7739 : 62183 : bitmap_head oacc_reduction_head, is_on_device_head;
7740 : 62183 : tree c, t, *pc;
7741 : 62183 : tree safelen = NULL_TREE;
7742 : 62183 : bool openacc = (ort & C_ORT_ACC) != 0;
7743 : 62183 : bool branch_seen = false;
7744 : 62183 : bool copyprivate_seen = false;
7745 : 62183 : bool ordered_seen = false;
7746 : 62183 : bool order_seen = false;
7747 : 62183 : bool schedule_seen = false;
7748 : 62183 : bool oacc_async = false;
7749 : 62183 : bool indir_component_ref_p = false;
7750 : 62183 : tree last_iterators = NULL_TREE;
7751 : 62183 : bool last_iterators_remove = false;
7752 : : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
7753 : : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
7754 : 62183 : int reduction_seen = 0;
7755 : 62183 : bool allocate_seen = false;
7756 : 62183 : tree detach_seen = NULL_TREE;
7757 : 62183 : bool mergeable_seen = false;
7758 : 62183 : bool implicit_moved = false;
7759 : 62183 : bool target_in_reduction_seen = false;
7760 : 62183 : bool num_tasks_seen = false;
7761 : 62183 : bool partial_seen = false;
7762 : 62183 : bool init_seen = false;
7763 : 62183 : bool init_use_destroy_seen = false;
7764 : 62183 : tree init_no_targetsync_clause = NULL_TREE;
7765 : 62183 : tree depend_clause = NULL_TREE;
7766 : :
7767 : 62183 : bitmap_obstack_initialize (NULL);
7768 : 62183 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
7769 : 62183 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
7770 : 62183 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
7771 : 62183 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
7772 : : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
7773 : 62183 : bitmap_initialize (&map_head, &bitmap_default_obstack);
7774 : 62183 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
7775 : 62183 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
7776 : : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
7777 : : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
7778 : 62183 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
7779 : 62183 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
7780 : :
7781 : 62183 : if (openacc)
7782 : 28283 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
7783 : 15936 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
7784 : : {
7785 : : oacc_async = true;
7786 : : break;
7787 : : }
7788 : :
7789 : 62183 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
7790 : :
7791 : 159329 : for (pc = &clauses, c = clauses; c ; c = *pc)
7792 : : {
7793 : 97146 : bool remove = false;
7794 : 97146 : bool field_ok = false;
7795 : :
7796 : : /* We've reached the end of a list of expanded nodes. Reset the group
7797 : : start pointer. */
7798 : 97146 : if (c == grp_sentinel)
7799 : : {
7800 : 5485 : if (grp_start_p
7801 : 5485 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
7802 : 96 : for (tree gc = *grp_start_p; gc != grp_sentinel;
7803 : 66 : gc = OMP_CLAUSE_CHAIN (gc))
7804 : 66 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
7805 : : grp_start_p = NULL;
7806 : : }
7807 : :
7808 : 97146 : switch (OMP_CLAUSE_CODE (c))
7809 : : {
7810 : 2097 : case OMP_CLAUSE_SHARED:
7811 : 2097 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7812 : 2097 : goto check_dup_generic;
7813 : 2541 : case OMP_CLAUSE_PRIVATE:
7814 : 2541 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7815 : 2541 : goto check_dup_generic;
7816 : 7337 : case OMP_CLAUSE_REDUCTION:
7817 : 7337 : if (reduction_seen == 0)
7818 : 6233 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
7819 : 1104 : else if (reduction_seen != -2
7820 : 2208 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
7821 : 1104 : ? -1 : 1))
7822 : : {
7823 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7824 : : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
7825 : : "on the same construct");
7826 : 6 : reduction_seen = -2;
7827 : : }
7828 : : /* FALLTHRU */
7829 : 9479 : case OMP_CLAUSE_IN_REDUCTION:
7830 : 9479 : case OMP_CLAUSE_TASK_REDUCTION:
7831 : 9479 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7832 : 9479 : t = OMP_CLAUSE_DECL (c);
7833 : 9479 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7834 : : {
7835 : 2207 : if (handle_omp_array_sections (c, ort))
7836 : : {
7837 : : remove = true;
7838 : : break;
7839 : : }
7840 : 2165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
7841 : 2165 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
7842 : : {
7843 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
7844 : : "%<inscan%> %<reduction%> clause with array "
7845 : : "section");
7846 : 3 : remove = true;
7847 : 3 : break;
7848 : : }
7849 : 2162 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7850 : : {
7851 : 4672 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7852 : 2510 : t = TREE_OPERAND (t, 0);
7853 : : }
7854 : : else
7855 : : {
7856 : 0 : gcc_assert (TREE_CODE (t) == MEM_REF);
7857 : 0 : t = TREE_OPERAND (t, 0);
7858 : 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
7859 : 0 : t = TREE_OPERAND (t, 0);
7860 : 0 : if (TREE_CODE (t) == ADDR_EXPR
7861 : 0 : || INDIRECT_REF_P (t))
7862 : 0 : t = TREE_OPERAND (t, 0);
7863 : : }
7864 : 2162 : tree n = omp_clause_decl_field (t);
7865 : 2162 : if (n)
7866 : 59 : t = n;
7867 : 2162 : goto check_dup_generic_t;
7868 : : }
7869 : 7272 : if (oacc_async)
7870 : 7 : cxx_mark_addressable (t);
7871 : 7272 : goto check_dup_generic;
7872 : 98 : case OMP_CLAUSE_COPYPRIVATE:
7873 : 98 : copyprivate_seen = true;
7874 : 98 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7875 : 98 : goto check_dup_generic;
7876 : 277 : case OMP_CLAUSE_COPYIN:
7877 : 277 : goto check_dup_generic;
7878 : 1613 : case OMP_CLAUSE_LINEAR:
7879 : 1613 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7880 : 1613 : t = OMP_CLAUSE_DECL (c);
7881 : 1613 : if (ort != C_ORT_OMP_DECLARE_SIMD
7882 : 1613 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
7883 : : {
7884 : 84 : if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
7885 : : {
7886 : 42 : error_at (OMP_CLAUSE_LOCATION (c),
7887 : : "modifier should not be specified in %<linear%> "
7888 : : "clause on %<simd%> or %<for%> constructs when "
7889 : : "not using OpenMP 5.2 modifiers");
7890 : 42 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
7891 : : }
7892 : 42 : else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
7893 : : {
7894 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
7895 : : "modifier other than %<val%> specified in "
7896 : : "%<linear%> clause on %<simd%> or %<for%> "
7897 : : "constructs when using OpenMP 5.2 modifiers");
7898 : 18 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
7899 : : }
7900 : : }
7901 : 993 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
7902 : 2535 : && !type_dependent_expression_p (t))
7903 : : {
7904 : 1511 : tree type = TREE_TYPE (t);
7905 : 1511 : if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7906 : 1436 : || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
7907 : 1574 : && !TYPE_REF_P (type))
7908 : : {
7909 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
7910 : : "linear clause with %qs modifier applied to "
7911 : : "non-reference variable with %qT type",
7912 : 12 : OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7913 : 12 : ? "ref" : "uval", TREE_TYPE (t));
7914 : 12 : remove = true;
7915 : 12 : break;
7916 : : }
7917 : 1499 : if (TYPE_REF_P (type))
7918 : 269 : type = TREE_TYPE (type);
7919 : 1499 : if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
7920 : : {
7921 : 1430 : if (!INTEGRAL_TYPE_P (type)
7922 : 85 : && !TYPE_PTR_P (type))
7923 : : {
7924 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
7925 : : "linear clause applied to non-integral "
7926 : : "non-pointer variable with %qT type",
7927 : 18 : TREE_TYPE (t));
7928 : 18 : remove = true;
7929 : 18 : break;
7930 : : }
7931 : : }
7932 : : }
7933 : 1583 : t = OMP_CLAUSE_LINEAR_STEP (c);
7934 : 1583 : if (t == NULL_TREE)
7935 : 6 : t = integer_one_node;
7936 : 1583 : if (t == error_mark_node)
7937 : : {
7938 : : remove = true;
7939 : : break;
7940 : : }
7941 : 1583 : else if (!type_dependent_expression_p (t)
7942 : 1581 : && !INTEGRAL_TYPE_P (TREE_TYPE (t))
7943 : 1595 : && (ort != C_ORT_OMP_DECLARE_SIMD
7944 : 9 : || TREE_CODE (t) != PARM_DECL
7945 : 6 : || !TYPE_REF_P (TREE_TYPE (t))
7946 : 6 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
7947 : : {
7948 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7949 : : "linear step expression must be integral");
7950 : 6 : remove = true;
7951 : 6 : break;
7952 : : }
7953 : : else
7954 : : {
7955 : 1577 : t = mark_rvalue_use (t);
7956 : 1577 : if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
7957 : : {
7958 : 42 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
7959 : 42 : goto check_dup_generic;
7960 : : }
7961 : 1535 : if (!processing_template_decl
7962 : 1535 : && (VAR_P (OMP_CLAUSE_DECL (c))
7963 : 817 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
7964 : : {
7965 : 1354 : if (ort == C_ORT_OMP_DECLARE_SIMD)
7966 : : {
7967 : 571 : t = maybe_constant_value (t);
7968 : 571 : if (TREE_CODE (t) != INTEGER_CST)
7969 : : {
7970 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7971 : : "%<linear%> clause step %qE is neither "
7972 : : "constant nor a parameter", t);
7973 : 6 : remove = true;
7974 : 6 : break;
7975 : : }
7976 : : }
7977 : 1348 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7978 : 1348 : tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
7979 : 1348 : if (TYPE_REF_P (type))
7980 : 245 : type = TREE_TYPE (type);
7981 : 1348 : if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
7982 : : {
7983 : 60 : type = build_pointer_type (type);
7984 : 60 : tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
7985 : 60 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
7986 : : d, t);
7987 : 60 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
7988 : : MINUS_EXPR, sizetype,
7989 : : fold_convert (sizetype, t),
7990 : : fold_convert (sizetype, d));
7991 : 60 : if (t == error_mark_node)
7992 : : {
7993 : : remove = true;
7994 : : break;
7995 : : }
7996 : : }
7997 : 1288 : else if (TYPE_PTR_P (type)
7998 : : /* Can't multiply the step yet if *this
7999 : : is still incomplete type. */
8000 : 1288 : && (ort != C_ORT_OMP_DECLARE_SIMD
8001 : 45 : || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
8002 : 45 : || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
8003 : 30 : || DECL_NAME (OMP_CLAUSE_DECL (c))
8004 : 30 : != this_identifier
8005 : 30 : || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
8006 : : {
8007 : 37 : tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
8008 : 37 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
8009 : : d, t);
8010 : 37 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
8011 : : MINUS_EXPR, sizetype,
8012 : : fold_convert (sizetype, t),
8013 : : fold_convert (sizetype, d));
8014 : 37 : if (t == error_mark_node)
8015 : : {
8016 : : remove = true;
8017 : : break;
8018 : : }
8019 : : }
8020 : : else
8021 : 1251 : t = fold_convert (type, t);
8022 : : }
8023 : 1529 : OMP_CLAUSE_LINEAR_STEP (c) = t;
8024 : : }
8025 : 1529 : goto check_dup_generic;
8026 : 14821 : check_dup_generic:
8027 : 14821 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8028 : 14821 : if (t)
8029 : : {
8030 : 101 : if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
8031 : 101 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8032 : : }
8033 : : else
8034 : 14720 : t = OMP_CLAUSE_DECL (c);
8035 : 17249 : check_dup_generic_t:
8036 : 17249 : if (t == current_class_ptr
8037 : 17249 : && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
8038 : 102 : || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
8039 : 72 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
8040 : : {
8041 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
8042 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
8043 : : " clauses");
8044 : 24 : remove = true;
8045 : 24 : break;
8046 : : }
8047 : 17225 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8048 : 586 : && (!field_ok || TREE_CODE (t) != FIELD_DECL))
8049 : : {
8050 : 59 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8051 : : break;
8052 : 39 : if (DECL_P (t))
8053 : 30 : error_at (OMP_CLAUSE_LOCATION (c),
8054 : : "%qD is not a variable in clause %qs", t,
8055 : 15 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8056 : : else
8057 : 48 : error_at (OMP_CLAUSE_LOCATION (c),
8058 : : "%qE is not a variable in clause %qs", t,
8059 : 24 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8060 : : remove = true;
8061 : : }
8062 : 17166 : else if ((openacc
8063 : 2707 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
8064 : 14697 : || (ort == C_ORT_OMP
8065 : 12418 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
8066 : 12387 : || (OMP_CLAUSE_CODE (c)
8067 : : == OMP_CLAUSE_USE_DEVICE_ADDR)))
8068 : 31756 : || (ort == C_ORT_OMP_TARGET
8069 : 902 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
8070 : : {
8071 : 2854 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
8072 : 2854 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
8073 : 275 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
8074 : : {
8075 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8076 : : "%qD appears more than once in data-sharing "
8077 : : "clauses", t);
8078 : 6 : remove = true;
8079 : 6 : break;
8080 : : }
8081 : 2848 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
8082 : 272 : target_in_reduction_seen = true;
8083 : 2848 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8084 : : {
8085 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8086 : : openacc
8087 : : ? "%qD appears more than once in reduction clauses"
8088 : : : "%qD appears more than once in data clauses",
8089 : : t);
8090 : 6 : remove = true;
8091 : : }
8092 : : else
8093 : 2842 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8094 : : }
8095 : 14312 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8096 : 14240 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8097 : 14237 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
8098 : 28549 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8099 : : {
8100 : 75 : error_at (OMP_CLAUSE_LOCATION (c),
8101 : : "%qD appears more than once in data clauses", t);
8102 : 75 : remove = true;
8103 : : }
8104 : 14237 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
8105 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
8106 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
8107 : 3081 : && bitmap_bit_p (&map_head, DECL_UID (t)))
8108 : : {
8109 : 9 : if (openacc)
8110 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8111 : : "%qD appears more than once in data clauses", t);
8112 : : else
8113 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
8114 : : "%qD appears both in data and map clauses", t);
8115 : : remove = true;
8116 : : }
8117 : : else
8118 : 14228 : bitmap_set_bit (&generic_head, DECL_UID (t));
8119 : 17199 : if (!field_ok)
8120 : : break;
8121 : 12810 : handle_field_decl:
8122 : 21229 : if (!remove
8123 : 21035 : && TREE_CODE (t) == FIELD_DECL
8124 : 16398 : && t == OMP_CLAUSE_DECL (c))
8125 : : {
8126 : 795 : OMP_CLAUSE_DECL (c)
8127 : 795 : = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
8128 : : == OMP_CLAUSE_SHARED));
8129 : 795 : if (OMP_CLAUSE_DECL (c) == error_mark_node)
8130 : 96694 : remove = true;
8131 : : }
8132 : : break;
8133 : :
8134 : 3435 : case OMP_CLAUSE_FIRSTPRIVATE:
8135 : 3435 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
8136 : : {
8137 : 452 : move_implicit:
8138 : 452 : implicit_moved = true;
8139 : : /* Move firstprivate and map clauses with
8140 : : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
8141 : : clauses chain. */
8142 : 452 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
8143 : 452 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
8144 : 2814 : while (*pc1)
8145 : 2362 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
8146 : 2362 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
8147 : : {
8148 : 275 : *pc3 = *pc1;
8149 : 275 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
8150 : 275 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8151 : : }
8152 : 2087 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
8153 : 2087 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
8154 : : {
8155 : 408 : *pc2 = *pc1;
8156 : 408 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
8157 : 408 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
8158 : : }
8159 : : else
8160 : 1679 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
8161 : 452 : *pc3 = NULL;
8162 : 452 : *pc2 = cl2;
8163 : 452 : *pc1 = cl1;
8164 : 452 : continue;
8165 : 452 : }
8166 : 3178 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8167 : 3178 : if (t)
8168 : 69 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8169 : : else
8170 : 3109 : t = OMP_CLAUSE_DECL (c);
8171 : 3178 : if (!openacc && t == current_class_ptr)
8172 : : {
8173 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8174 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
8175 : : " clauses");
8176 : 6 : remove = true;
8177 : 6 : break;
8178 : : }
8179 : 3172 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8180 : 333 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8181 : 333 : || TREE_CODE (t) != FIELD_DECL))
8182 : : {
8183 : 41 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8184 : : break;
8185 : 18 : if (DECL_P (t))
8186 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8187 : : "%qD is not a variable in clause %<firstprivate%>",
8188 : : t);
8189 : : else
8190 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8191 : : "%qE is not a variable in clause %<firstprivate%>",
8192 : : t);
8193 : 18 : remove = true;
8194 : : }
8195 : 3131 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8196 : 275 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
8197 : 3385 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8198 : : remove = true;
8199 : 3131 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8200 : 3122 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8201 : 6250 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8202 : : {
8203 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
8204 : : "%qD appears more than once in data clauses", t);
8205 : 15 : remove = true;
8206 : : }
8207 : 3116 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8208 : 3116 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
8209 : : {
8210 : 21 : if (openacc)
8211 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8212 : : "%qD appears more than once in data clauses", t);
8213 : 21 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8214 : 21 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
8215 : : /* Silently drop the clause. */;
8216 : : else
8217 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
8218 : : "%qD appears both in data and map clauses", t);
8219 : 21 : remove = true;
8220 : : }
8221 : : else
8222 : 3095 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
8223 : 3149 : goto handle_field_decl;
8224 : :
8225 : 2787 : case OMP_CLAUSE_LASTPRIVATE:
8226 : 2787 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8227 : 2787 : if (t)
8228 : 35 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8229 : : else
8230 : 2752 : t = OMP_CLAUSE_DECL (c);
8231 : 2787 : if (!openacc && t == current_class_ptr)
8232 : : {
8233 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8234 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
8235 : : " clauses");
8236 : 6 : remove = true;
8237 : 6 : break;
8238 : : }
8239 : 2781 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8240 : 259 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8241 : 259 : || TREE_CODE (t) != FIELD_DECL))
8242 : : {
8243 : 35 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8244 : : break;
8245 : 9 : if (DECL_P (t))
8246 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8247 : : "%qD is not a variable in clause %<lastprivate%>",
8248 : : t);
8249 : : else
8250 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8251 : : "%qE is not a variable in clause %<lastprivate%>",
8252 : : t);
8253 : 9 : remove = true;
8254 : : }
8255 : 2746 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8256 : 2746 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8257 : : {
8258 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8259 : : "%qD appears more than once in data clauses", t);
8260 : 12 : remove = true;
8261 : : }
8262 : : else
8263 : 2734 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
8264 : 2755 : goto handle_field_decl;
8265 : :
8266 : 2215 : case OMP_CLAUSE_IF:
8267 : 2215 : case OMP_CLAUSE_SELF:
8268 : 2215 : t = OMP_CLAUSE_OPERAND (c, 0);
8269 : 2215 : t = maybe_convert_cond (t);
8270 : 2215 : if (t == error_mark_node)
8271 : : remove = true;
8272 : 2200 : else if (!processing_template_decl)
8273 : 2139 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8274 : 2215 : OMP_CLAUSE_OPERAND (c, 0) = t;
8275 : 2215 : break;
8276 : :
8277 : 286 : case OMP_CLAUSE_FINAL:
8278 : 286 : t = OMP_CLAUSE_FINAL_EXPR (c);
8279 : 286 : t = maybe_convert_cond (t);
8280 : 286 : if (t == error_mark_node)
8281 : : remove = true;
8282 : 286 : else if (!processing_template_decl)
8283 : 280 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8284 : 286 : OMP_CLAUSE_FINAL_EXPR (c) = t;
8285 : 286 : break;
8286 : :
8287 : 92 : case OMP_CLAUSE_NOCONTEXT:
8288 : 92 : t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
8289 : 92 : t = maybe_convert_cond (t);
8290 : 92 : if (t == error_mark_node)
8291 : : remove = true;
8292 : 89 : else if (!processing_template_decl)
8293 : 83 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8294 : 92 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
8295 : 92 : break;
8296 : :
8297 : 80 : case OMP_CLAUSE_NOVARIANTS:
8298 : 80 : t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
8299 : 80 : t = maybe_convert_cond (t);
8300 : 80 : if (t == error_mark_node)
8301 : : remove = true;
8302 : 77 : else if (!processing_template_decl)
8303 : 71 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8304 : 80 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
8305 : 80 : break;
8306 : :
8307 : 1249 : case OMP_CLAUSE_GANG:
8308 : : /* Operand 1 is the gang static: argument. */
8309 : 1249 : t = OMP_CLAUSE_OPERAND (c, 1);
8310 : 1249 : if (t != NULL_TREE)
8311 : : {
8312 : 129 : if (t == error_mark_node)
8313 : : remove = true;
8314 : 129 : else if (!type_dependent_expression_p (t)
8315 : 129 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8316 : : {
8317 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8318 : : "%<gang%> static expression must be integral");
8319 : 6 : remove = true;
8320 : : }
8321 : : else
8322 : : {
8323 : 123 : t = mark_rvalue_use (t);
8324 : 123 : if (!processing_template_decl)
8325 : : {
8326 : 123 : t = maybe_constant_value (t);
8327 : 123 : if (TREE_CODE (t) == INTEGER_CST
8328 : 109 : && tree_int_cst_sgn (t) != 1
8329 : 176 : && t != integer_minus_one_node)
8330 : : {
8331 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8332 : : "%<gang%> static value must be "
8333 : : "positive");
8334 : 0 : t = integer_one_node;
8335 : : }
8336 : 123 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8337 : : }
8338 : : }
8339 : 129 : OMP_CLAUSE_OPERAND (c, 1) = t;
8340 : : }
8341 : : /* Check operand 0, the num argument. */
8342 : : /* FALLTHRU */
8343 : :
8344 : 3480 : case OMP_CLAUSE_WORKER:
8345 : 3480 : case OMP_CLAUSE_VECTOR:
8346 : 3480 : if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
8347 : : break;
8348 : : /* FALLTHRU */
8349 : :
8350 : 481 : case OMP_CLAUSE_NUM_TASKS:
8351 : 481 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
8352 : 133 : num_tasks_seen = true;
8353 : : /* FALLTHRU */
8354 : :
8355 : 3031 : case OMP_CLAUSE_NUM_TEAMS:
8356 : 3031 : case OMP_CLAUSE_NUM_THREADS:
8357 : 3031 : case OMP_CLAUSE_NUM_GANGS:
8358 : 3031 : case OMP_CLAUSE_NUM_WORKERS:
8359 : 3031 : case OMP_CLAUSE_DYN_GROUPPRIVATE:
8360 : 3031 : case OMP_CLAUSE_VECTOR_LENGTH:
8361 : 3031 : t = OMP_CLAUSE_OPERAND (c, 0);
8362 : 3031 : if (t == error_mark_node)
8363 : : remove = true;
8364 : 3031 : else if (!type_dependent_expression_p (t)
8365 : 3031 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8366 : : {
8367 : 99 : switch (OMP_CLAUSE_CODE (c))
8368 : : {
8369 : 12 : case OMP_CLAUSE_GANG:
8370 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8371 : 12 : "%<gang%> num expression must be integral"); break;
8372 : 12 : case OMP_CLAUSE_VECTOR:
8373 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8374 : : "%<vector%> length expression must be integral");
8375 : 12 : break;
8376 : 12 : case OMP_CLAUSE_WORKER:
8377 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8378 : : "%<worker%> num expression must be integral");
8379 : 12 : break;
8380 : 63 : default:
8381 : 63 : error_at (OMP_CLAUSE_LOCATION (c),
8382 : : "%qs expression must be integral",
8383 : 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8384 : : }
8385 : : remove = true;
8386 : : }
8387 : : else
8388 : : {
8389 : 2932 : t = mark_rvalue_use (t);
8390 : 2932 : if (!processing_template_decl)
8391 : : {
8392 : 2684 : t = maybe_constant_value (t);
8393 : 2684 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DYN_GROUPPRIVATE
8394 : 2649 : && TREE_CODE (t) == INTEGER_CST
8395 : 4139 : && tree_int_cst_sgn (t) != 1)
8396 : : {
8397 : 85 : switch (OMP_CLAUSE_CODE (c))
8398 : : {
8399 : 3 : case OMP_CLAUSE_GANG:
8400 : 3 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8401 : : "%<gang%> num value must be positive");
8402 : 3 : break;
8403 : 0 : case OMP_CLAUSE_VECTOR:
8404 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8405 : : "%<vector%> length value must be "
8406 : : "positive");
8407 : 0 : break;
8408 : 0 : case OMP_CLAUSE_WORKER:
8409 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8410 : : "%<worker%> num value must be "
8411 : : "positive");
8412 : 0 : break;
8413 : 82 : default:
8414 : 82 : warning_at (OMP_CLAUSE_LOCATION (c),
8415 : 46 : (flag_openmp || flag_openmp_simd)
8416 : 82 : ? OPT_Wopenmp : 0,
8417 : : "%qs value must be positive",
8418 : : omp_clause_code_name
8419 : 82 : [OMP_CLAUSE_CODE (c)]);
8420 : : }
8421 : 85 : t = integer_one_node;
8422 : : }
8423 : 2599 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DYN_GROUPPRIVATE
8424 : 35 : && TREE_CODE (t) == INTEGER_CST
8425 : 2622 : && tree_int_cst_sgn (t) < 0)
8426 : : {
8427 : 8 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8428 : : "%<dyn_groupprivate%> value must be "
8429 : : "non-negative");
8430 : 8 : t = integer_zero_node;
8431 : : }
8432 : 2684 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8433 : : }
8434 : 2932 : OMP_CLAUSE_OPERAND (c, 0) = t;
8435 : : }
8436 : 3031 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
8437 : 752 : && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
8438 : 3310 : && !remove)
8439 : : {
8440 : 279 : t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
8441 : 279 : if (t == error_mark_node)
8442 : : remove = true;
8443 : 279 : else if (!type_dependent_expression_p (t)
8444 : 279 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8445 : : {
8446 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8447 : : "%qs expression must be integral",
8448 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8449 : 0 : remove = true;
8450 : : }
8451 : : else
8452 : : {
8453 : 279 : t = mark_rvalue_use (t);
8454 : 279 : if (!processing_template_decl)
8455 : : {
8456 : 213 : t = maybe_constant_value (t);
8457 : 213 : if (TREE_CODE (t) == INTEGER_CST
8458 : 213 : && tree_int_cst_sgn (t) != 1)
8459 : : {
8460 : 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8461 : : "%qs value must be positive",
8462 : : omp_clause_code_name
8463 : 18 : [OMP_CLAUSE_CODE (c)]);
8464 : 18 : t = NULL_TREE;
8465 : : }
8466 : : else
8467 : 195 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8468 : 213 : tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
8469 : 213 : if (t
8470 : 195 : && TREE_CODE (t) == INTEGER_CST
8471 : 43 : && TREE_CODE (upper) == INTEGER_CST
8472 : 250 : && tree_int_cst_lt (upper, t))
8473 : : {
8474 : 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8475 : : "%<num_teams%> lower bound %qE bigger "
8476 : : "than upper bound %qE", t, upper);
8477 : 18 : t = NULL_TREE;
8478 : : }
8479 : : }
8480 : 279 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
8481 : : }
8482 : : }
8483 : : break;
8484 : :
8485 : 3859 : case OMP_CLAUSE_SCHEDULE:
8486 : 3859 : t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
8487 : 3859 : if (t == NULL)
8488 : : ;
8489 : 2075 : else if (t == error_mark_node)
8490 : : remove = true;
8491 : 2075 : else if (!type_dependent_expression_p (t)
8492 : 2075 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8493 : : {
8494 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
8495 : : "schedule chunk size expression must be integral");
8496 : 9 : remove = true;
8497 : : }
8498 : : else
8499 : : {
8500 : 2066 : t = mark_rvalue_use (t);
8501 : 2066 : if (!processing_template_decl)
8502 : : {
8503 : 2026 : t = maybe_constant_value (t);
8504 : 2026 : if (TREE_CODE (t) == INTEGER_CST
8505 : 2026 : && tree_int_cst_sgn (t) != 1)
8506 : : {
8507 : 6 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8508 : : "chunk size value must be positive");
8509 : 6 : t = integer_one_node;
8510 : : }
8511 : 2026 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8512 : : }
8513 : 2066 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8514 : : }
8515 : 2075 : if (!remove)
8516 : : schedule_seen = true;
8517 : : break;
8518 : :
8519 : 1268 : case OMP_CLAUSE_SIMDLEN:
8520 : 1268 : case OMP_CLAUSE_SAFELEN:
8521 : 1268 : t = OMP_CLAUSE_OPERAND (c, 0);
8522 : 1268 : if (t == error_mark_node)
8523 : : remove = true;
8524 : 1268 : else if (!type_dependent_expression_p (t)
8525 : 1268 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8526 : : {
8527 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8528 : : "%qs length expression must be integral",
8529 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8530 : 0 : remove = true;
8531 : : }
8532 : : else
8533 : : {
8534 : 1268 : t = mark_rvalue_use (t);
8535 : 1268 : if (!processing_template_decl)
8536 : : {
8537 : 1219 : t = maybe_constant_value (t);
8538 : 1219 : if (TREE_CODE (t) != INTEGER_CST
8539 : 1219 : || tree_int_cst_sgn (t) != 1)
8540 : : {
8541 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8542 : : "%qs length expression must be positive "
8543 : : "constant integer expression",
8544 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8545 : 0 : remove = true;
8546 : : }
8547 : : }
8548 : 1268 : OMP_CLAUSE_OPERAND (c, 0) = t;
8549 : 1268 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
8550 : 470 : safelen = c;
8551 : : }
8552 : : break;
8553 : :
8554 : 388 : case OMP_CLAUSE_ASYNC:
8555 : 388 : t = OMP_CLAUSE_ASYNC_EXPR (c);
8556 : 388 : if (t == error_mark_node)
8557 : : remove = true;
8558 : 373 : else if (!type_dependent_expression_p (t)
8559 : 373 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8560 : : {
8561 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8562 : : "%<async%> expression must be integral");
8563 : 12 : remove = true;
8564 : : }
8565 : : else
8566 : : {
8567 : 361 : t = mark_rvalue_use (t);
8568 : 361 : if (!processing_template_decl)
8569 : 352 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8570 : 361 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
8571 : : }
8572 : : break;
8573 : :
8574 : 204 : case OMP_CLAUSE_WAIT:
8575 : 204 : t = OMP_CLAUSE_WAIT_EXPR (c);
8576 : 204 : if (t == error_mark_node)
8577 : : remove = true;
8578 : 204 : else if (!processing_template_decl)
8579 : 196 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8580 : 204 : OMP_CLAUSE_WAIT_EXPR (c) = t;
8581 : 204 : break;
8582 : :
8583 : 637 : case OMP_CLAUSE_THREAD_LIMIT:
8584 : 637 : t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
8585 : 637 : if (t == error_mark_node)
8586 : : remove = true;
8587 : 637 : else if (!type_dependent_expression_p (t)
8588 : 637 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8589 : : {
8590 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8591 : : "%<thread_limit%> expression must be integral");
8592 : 0 : remove = true;
8593 : : }
8594 : : else
8595 : : {
8596 : 637 : t = mark_rvalue_use (t);
8597 : 637 : if (!processing_template_decl)
8598 : : {
8599 : 583 : t = maybe_constant_value (t);
8600 : 583 : if (TREE_CODE (t) == INTEGER_CST
8601 : 583 : && tree_int_cst_sgn (t) != 1)
8602 : : {
8603 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8604 : : "%<thread_limit%> value must be positive");
8605 : 0 : t = integer_one_node;
8606 : : }
8607 : 583 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8608 : : }
8609 : 637 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
8610 : : }
8611 : : break;
8612 : :
8613 : 771 : case OMP_CLAUSE_DEVICE:
8614 : 771 : t = OMP_CLAUSE_DEVICE_ID (c);
8615 : 771 : if (t == error_mark_node)
8616 : : remove = true;
8617 : 771 : else if (!type_dependent_expression_p (t)
8618 : 771 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8619 : : {
8620 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8621 : : "%<device%> id must be integral");
8622 : 6 : remove = true;
8623 : : }
8624 : 765 : else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
8625 : 66 : && TREE_CODE (t) == INTEGER_CST
8626 : 825 : && !integer_onep (t))
8627 : : {
8628 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8629 : : "the %<device%> clause expression must evaluate to "
8630 : : "%<1%>");
8631 : 3 : remove = true;
8632 : : }
8633 : : else
8634 : : {
8635 : 762 : t = mark_rvalue_use (t);
8636 : 762 : if (!processing_template_decl)
8637 : 751 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8638 : 762 : OMP_CLAUSE_DEVICE_ID (c) = t;
8639 : : }
8640 : : break;
8641 : :
8642 : 1836 : case OMP_CLAUSE_DIST_SCHEDULE:
8643 : 1836 : t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
8644 : 1836 : if (t == NULL)
8645 : : ;
8646 : 1815 : else if (t == error_mark_node)
8647 : : remove = true;
8648 : 1815 : else if (!type_dependent_expression_p (t)
8649 : 1815 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8650 : : {
8651 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8652 : : "%<dist_schedule%> chunk size expression must be "
8653 : : "integral");
8654 : 0 : remove = true;
8655 : : }
8656 : : else
8657 : : {
8658 : 1815 : t = mark_rvalue_use (t);
8659 : 1815 : if (!processing_template_decl)
8660 : 1815 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8661 : 1815 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
8662 : : }
8663 : : break;
8664 : :
8665 : 807 : case OMP_CLAUSE_ALIGNED:
8666 : 807 : t = OMP_CLAUSE_DECL (c);
8667 : 807 : if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
8668 : : {
8669 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8670 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
8671 : : " clauses");
8672 : 0 : remove = true;
8673 : 0 : break;
8674 : : }
8675 : 807 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8676 : : {
8677 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8678 : : break;
8679 : 0 : if (DECL_P (t))
8680 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8681 : : "%qD is not a variable in %<aligned%> clause", t);
8682 : : else
8683 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8684 : : "%qE is not a variable in %<aligned%> clause", t);
8685 : : remove = true;
8686 : : }
8687 : 807 : else if (!type_dependent_expression_p (t)
8688 : 789 : && !TYPE_PTR_P (TREE_TYPE (t))
8689 : 111 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
8690 : 864 : && (!TYPE_REF_P (TREE_TYPE (t))
8691 : 39 : || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
8692 : 30 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
8693 : : != ARRAY_TYPE))))
8694 : : {
8695 : 33 : error_at (OMP_CLAUSE_LOCATION (c),
8696 : : "%qE in %<aligned%> clause is neither a pointer nor "
8697 : : "an array nor a reference to pointer or array", t);
8698 : 33 : remove = true;
8699 : : }
8700 : 774 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8701 : : {
8702 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8703 : : "%qD appears more than once in %<aligned%> clauses",
8704 : : t);
8705 : 0 : remove = true;
8706 : : }
8707 : : else
8708 : 774 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8709 : 807 : t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
8710 : 807 : if (t == error_mark_node)
8711 : : remove = true;
8712 : 807 : else if (t == NULL_TREE)
8713 : : break;
8714 : 744 : else if (!type_dependent_expression_p (t)
8715 : 744 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8716 : : {
8717 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8718 : : "%<aligned%> clause alignment expression must "
8719 : : "be integral");
8720 : 0 : remove = true;
8721 : : }
8722 : : else
8723 : : {
8724 : 744 : t = mark_rvalue_use (t);
8725 : 744 : if (!processing_template_decl)
8726 : : {
8727 : 690 : t = maybe_constant_value (t);
8728 : 690 : if (TREE_CODE (t) != INTEGER_CST
8729 : 690 : || tree_int_cst_sgn (t) != 1)
8730 : : {
8731 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8732 : : "%<aligned%> clause alignment expression must "
8733 : : "be positive constant integer expression");
8734 : 0 : remove = true;
8735 : : }
8736 : : }
8737 : 744 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
8738 : : }
8739 : : break;
8740 : :
8741 : 369 : case OMP_CLAUSE_NONTEMPORAL:
8742 : 369 : t = OMP_CLAUSE_DECL (c);
8743 : 369 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8744 : : {
8745 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8746 : : break;
8747 : 0 : if (DECL_P (t))
8748 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8749 : : "%qD is not a variable in %<nontemporal%> clause",
8750 : : t);
8751 : : else
8752 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8753 : : "%qE is not a variable in %<nontemporal%> clause",
8754 : : t);
8755 : : remove = true;
8756 : : }
8757 : 369 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8758 : : {
8759 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8760 : : "%qD appears more than once in %<nontemporal%> "
8761 : : "clauses", t);
8762 : 6 : remove = true;
8763 : : }
8764 : : else
8765 : 363 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8766 : : break;
8767 : :
8768 : 2531 : case OMP_CLAUSE_ALLOCATE:
8769 : 2531 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8770 : 2531 : if (t)
8771 : 14 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8772 : : else
8773 : 2517 : t = OMP_CLAUSE_DECL (c);
8774 : 2531 : if (t == current_class_ptr)
8775 : : {
8776 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8777 : : "%<this%> not allowed in %<allocate%> clause");
8778 : 0 : remove = true;
8779 : 0 : break;
8780 : : }
8781 : 2531 : if (!VAR_P (t)
8782 : 558 : && TREE_CODE (t) != PARM_DECL
8783 : 45 : && TREE_CODE (t) != FIELD_DECL)
8784 : : {
8785 : 3 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8786 : : break;
8787 : 3 : if (DECL_P (t))
8788 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8789 : : "%qD is not a variable in %<allocate%> clause", t);
8790 : : else
8791 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8792 : : "%qE is not a variable in %<allocate%> clause", t);
8793 : : remove = true;
8794 : : }
8795 : 2528 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8796 : : {
8797 : 12 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8798 : : "%qD appears more than once in %<allocate%> clauses",
8799 : : t);
8800 : 12 : remove = true;
8801 : : }
8802 : : else
8803 : : {
8804 : 2516 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8805 : 2516 : allocate_seen = true;
8806 : : }
8807 : 2531 : tree allocator, align;
8808 : 2531 : align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
8809 : 2531 : if (error_operand_p (align))
8810 : : {
8811 : : remove = true;
8812 : : break;
8813 : : }
8814 : 2531 : if (align)
8815 : : {
8816 : 171 : if (!type_dependent_expression_p (align)
8817 : 171 : && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
8818 : : {
8819 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
8820 : : "%<allocate%> clause %<align%> modifier "
8821 : : "argument needs to be positive constant "
8822 : : "power of two integer expression");
8823 : 4 : remove = true;
8824 : : }
8825 : : else
8826 : : {
8827 : 167 : align = mark_rvalue_use (align);
8828 : 167 : if (!processing_template_decl)
8829 : : {
8830 : 152 : align = maybe_constant_value (align);
8831 : 152 : if (TREE_CODE (align) != INTEGER_CST
8832 : 149 : || !tree_fits_uhwi_p (align)
8833 : 301 : || !integer_pow2p (align))
8834 : : {
8835 : 10 : error_at (OMP_CLAUSE_LOCATION (c),
8836 : : "%<allocate%> clause %<align%> modifier "
8837 : : "argument needs to be positive constant "
8838 : : "power of two integer expression");
8839 : 10 : remove = true;
8840 : : }
8841 : : }
8842 : : }
8843 : 171 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
8844 : : }
8845 : 2531 : allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
8846 : 2531 : if (error_operand_p (allocator))
8847 : : {
8848 : : remove = true;
8849 : : break;
8850 : : }
8851 : 2531 : if (allocator == NULL_TREE)
8852 : 1537 : goto handle_field_decl;
8853 : 994 : tree allocatort;
8854 : 994 : allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
8855 : 994 : if (!type_dependent_expression_p (allocator)
8856 : 994 : && (TREE_CODE (allocatort) != ENUMERAL_TYPE
8857 : 975 : || TYPE_NAME (allocatort) == NULL_TREE
8858 : 975 : || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
8859 : 1950 : || (DECL_NAME (TYPE_NAME (allocatort))
8860 : 975 : != get_identifier ("omp_allocator_handle_t"))
8861 : 975 : || (TYPE_CONTEXT (allocatort)
8862 : 975 : != DECL_CONTEXT (global_namespace))))
8863 : : {
8864 : 16 : error_at (OMP_CLAUSE_LOCATION (c),
8865 : : "%<allocate%> clause allocator expression has "
8866 : : "type %qT rather than %<omp_allocator_handle_t%>",
8867 : 16 : TREE_TYPE (allocator));
8868 : 16 : remove = true;
8869 : 16 : break;
8870 : : }
8871 : : else
8872 : : {
8873 : 978 : allocator = mark_rvalue_use (allocator);
8874 : 978 : if (!processing_template_decl)
8875 : 959 : allocator = maybe_constant_value (allocator);
8876 : 978 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
8877 : : }
8878 : 978 : goto handle_field_decl;
8879 : :
8880 : 648 : case OMP_CLAUSE_DOACROSS:
8881 : 648 : t = OMP_CLAUSE_DECL (c);
8882 : 648 : if (t == NULL_TREE)
8883 : : break;
8884 : 295 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
8885 : : {
8886 : 295 : if (cp_finish_omp_clause_doacross_sink (c))
8887 : 9 : remove = true;
8888 : : break;
8889 : : }
8890 : 0 : gcc_unreachable ();
8891 : 1803 : case OMP_CLAUSE_DEPEND:
8892 : 1803 : depend_clause = c;
8893 : : /* FALLTHRU */
8894 : 2169 : case OMP_CLAUSE_AFFINITY:
8895 : 2169 : t = OMP_CLAUSE_DECL (c);
8896 : 2169 : if (OMP_ITERATOR_DECL_P (t))
8897 : : {
8898 : 621 : if (TREE_PURPOSE (t) != last_iterators)
8899 : 523 : last_iterators_remove
8900 : 523 : = cp_omp_finish_iterators (TREE_PURPOSE (t));
8901 : 621 : last_iterators = TREE_PURPOSE (t);
8902 : 621 : t = TREE_VALUE (t);
8903 : 621 : if (last_iterators_remove)
8904 : 144 : t = error_mark_node;
8905 : : }
8906 : : else
8907 : : last_iterators = NULL_TREE;
8908 : :
8909 : 2169 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
8910 : : {
8911 : 1163 : if (handle_omp_array_sections (c, ort))
8912 : : remove = true;
8913 : 912 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
8914 : 912 : && (OMP_CLAUSE_DEPEND_KIND (c)
8915 : : == OMP_CLAUSE_DEPEND_DEPOBJ))
8916 : : {
8917 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8918 : : "%<depend%> clause with %<depobj%> dependence "
8919 : : "type on array section");
8920 : 6 : remove = true;
8921 : : }
8922 : : break;
8923 : : }
8924 : 1006 : if (t == error_mark_node)
8925 : : remove = true;
8926 : 844 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
8927 : 844 : && t == ridpointers[RID_OMP_ALL_MEMORY])
8928 : : {
8929 : 33 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
8930 : 33 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
8931 : : {
8932 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
8933 : : "%<omp_all_memory%> used with %<depend%> kind "
8934 : : "other than %<out%> or %<inout%>");
8935 : 9 : remove = true;
8936 : : }
8937 : 33 : if (processing_template_decl)
8938 : : break;
8939 : : }
8940 : 811 : else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8941 : : break;
8942 : 619 : else if (!lvalue_p (t))
8943 : : {
8944 : 19 : if (DECL_P (t))
8945 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
8946 : : "%qD is not lvalue expression nor array section "
8947 : : "in %qs clause", t,
8948 : 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8949 : : else
8950 : 14 : error_at (OMP_CLAUSE_LOCATION (c),
8951 : : "%qE is not lvalue expression nor array section "
8952 : : "in %qs clause", t,
8953 : 7 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8954 : : remove = true;
8955 : : }
8956 : 600 : else if (TREE_CODE (t) == COMPONENT_REF
8957 : 24 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
8958 : 624 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
8959 : : {
8960 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
8961 : : "bit-field %qE in %qs clause", t,
8962 : 4 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8963 : 4 : remove = true;
8964 : : }
8965 : 596 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
8966 : 596 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
8967 : : {
8968 : 130 : if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
8969 : 8 : ? TREE_TYPE (TREE_TYPE (t))
8970 : 57 : : TREE_TYPE (t)))
8971 : : {
8972 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8973 : : "%qE does not have %<omp_depend_t%> type in "
8974 : : "%<depend%> clause with %<depobj%> dependence "
8975 : : "type", t);
8976 : 12 : remove = true;
8977 : : }
8978 : : }
8979 : 531 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
8980 : 970 : && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
8981 : 4 : ? TREE_TYPE (TREE_TYPE (t))
8982 : 435 : : TREE_TYPE (t)))
8983 : : {
8984 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
8985 : : "%qE should not have %<omp_depend_t%> type in "
8986 : : "%<depend%> clause with dependence type other than "
8987 : : "%<depobj%>", t);
8988 : 15 : remove = true;
8989 : : }
8990 : 64 : if (!remove)
8991 : : {
8992 : 593 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
8993 : 24 : t = null_pointer_node;
8994 : : else
8995 : : {
8996 : 569 : tree addr = cp_build_addr_expr (t, tf_warning_or_error);
8997 : 569 : if (addr == error_mark_node)
8998 : : {
8999 : : remove = true;
9000 : : break;
9001 : : }
9002 : 569 : t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
9003 : : addr, RO_UNARY_STAR,
9004 : : tf_warning_or_error);
9005 : 569 : if (t == error_mark_node)
9006 : : {
9007 : : remove = true;
9008 : : break;
9009 : : }
9010 : : }
9011 : 593 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
9012 : 135 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
9013 : 728 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
9014 : : == TREE_VEC))
9015 : 135 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
9016 : : else
9017 : 458 : OMP_CLAUSE_DECL (c) = t;
9018 : : }
9019 : : break;
9020 : 69 : case OMP_CLAUSE_DETACH:
9021 : 69 : t = OMP_CLAUSE_DECL (c);
9022 : 69 : if (detach_seen)
9023 : : {
9024 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9025 : : "too many %qs clauses on a task construct",
9026 : : "detach");
9027 : 3 : remove = true;
9028 : 3 : break;
9029 : : }
9030 : 66 : else if (error_operand_p (t))
9031 : : {
9032 : : remove = true;
9033 : : break;
9034 : : }
9035 : : else
9036 : : {
9037 : 63 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
9038 : 63 : if (!type_dependent_expression_p (t)
9039 : 63 : && (!INTEGRAL_TYPE_P (type)
9040 : : || TREE_CODE (type) != ENUMERAL_TYPE
9041 : 51 : || TYPE_NAME (type) == NULL_TREE
9042 : 102 : || (DECL_NAME (TYPE_NAME (type))
9043 : 51 : != get_identifier ("omp_event_handle_t"))))
9044 : : {
9045 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9046 : : "%<detach%> clause event handle "
9047 : : "has type %qT rather than "
9048 : : "%<omp_event_handle_t%>",
9049 : : type);
9050 : 6 : remove = true;
9051 : : }
9052 : 63 : detach_seen = c;
9053 : 63 : cxx_mark_addressable (t);
9054 : : }
9055 : 63 : break;
9056 : :
9057 : 15864 : case OMP_CLAUSE_MAP:
9058 : 15864 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
9059 : 195 : goto move_implicit;
9060 : 15669 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
9061 : 15669 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
9062 : : {
9063 : : remove = true;
9064 : : break;
9065 : : }
9066 : : /* FALLTHRU */
9067 : 18787 : case OMP_CLAUSE_TO:
9068 : 18787 : case OMP_CLAUSE_FROM:
9069 : 18787 : if (OMP_CLAUSE_ITERATORS (c)
9070 : 18787 : && cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
9071 : : {
9072 : 96694 : t = error_mark_node;
9073 : : break;
9074 : : }
9075 : : /* FALLTHRU */
9076 : 19623 : case OMP_CLAUSE__CACHE_:
9077 : 19623 : {
9078 : 19623 : using namespace omp_addr_tokenizer;
9079 : 19623 : auto_vec<omp_addr_token *, 10> addr_tokens;
9080 : :
9081 : 19623 : t = OMP_CLAUSE_DECL (c);
9082 : 19623 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9083 : : {
9084 : 5860 : grp_start_p = pc;
9085 : 5860 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9086 : :
9087 : 5860 : if (handle_omp_array_sections (c, ort))
9088 : : remove = true;
9089 : : else
9090 : : {
9091 : 5094 : t = OMP_CLAUSE_DECL (c);
9092 : 5094 : if (TREE_CODE (t) != OMP_ARRAY_SECTION
9093 : 4237 : && !type_dependent_expression_p (t)
9094 : 9331 : && !omp_mappable_type (TREE_TYPE (t)))
9095 : : {
9096 : 3 : auto_diagnostic_group d;
9097 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9098 : : "array section does not have mappable type "
9099 : : "in %qs clause",
9100 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9101 : 3 : if (TREE_TYPE (t) != error_mark_node
9102 : 3 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9103 : 3 : cxx_incomplete_type_inform (TREE_TYPE (t));
9104 : 3 : remove = true;
9105 : 3 : }
9106 : 6932 : while (TREE_CODE (t) == ARRAY_REF)
9107 : 1838 : t = TREE_OPERAND (t, 0);
9108 : :
9109 : 5094 : if (type_dependent_expression_p (t))
9110 : : break;
9111 : :
9112 : 4620 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9113 : :
9114 : 4620 : if (!ai.map_supported_p ()
9115 : 4620 : || !omp_parse_expr (addr_tokens, t))
9116 : : {
9117 : 18 : sorry_at (OMP_CLAUSE_LOCATION (c),
9118 : : "unsupported map expression %qE",
9119 : 9 : OMP_CLAUSE_DECL (c));
9120 : 9 : remove = true;
9121 : 9 : break;
9122 : : }
9123 : :
9124 : : /* This check is to determine if this will be the only map
9125 : : node created for this clause. Otherwise, we'll check
9126 : : the following FIRSTPRIVATE_POINTER,
9127 : : FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
9128 : : iteration(s) of the loop. */
9129 : 9173 : if (addr_tokens.length () >= 4
9130 : 1063 : && addr_tokens[0]->type == STRUCTURE_BASE
9131 : 1057 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
9132 : 1057 : && addr_tokens[1]->type == ACCESS_METHOD
9133 : 1057 : && addr_tokens[2]->type == COMPONENT_SELECTOR
9134 : 977 : && addr_tokens[3]->type == ACCESS_METHOD
9135 : 5325 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
9136 : 551 : || (addr_tokens[3]->u.access_kind
9137 : : == ACCESS_INDEXED_ARRAY)))
9138 : : {
9139 : 165 : tree rt = addr_tokens[1]->expr;
9140 : :
9141 : 165 : gcc_assert (DECL_P (rt));
9142 : :
9143 : 165 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9144 : 154 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9145 : 165 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
9146 : 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
9147 : 0 : || bitmap_bit_p (&map_firstprivate_head,
9148 : 0 : DECL_UID (rt))))
9149 : : {
9150 : : remove = true;
9151 : : break;
9152 : : }
9153 : 165 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
9154 : : break;
9155 : 116 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
9156 : : {
9157 : 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9158 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9159 : : "%qD appears more than once in motion"
9160 : : " clauses", rt);
9161 : 0 : else if (openacc)
9162 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9163 : : "%qD appears more than once in data"
9164 : : " clauses", rt);
9165 : : else
9166 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9167 : : "%qD appears more than once in map"
9168 : : " clauses", rt);
9169 : : remove = true;
9170 : : }
9171 : : else
9172 : : {
9173 : 116 : bitmap_set_bit (&map_head, DECL_UID (rt));
9174 : 116 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
9175 : : }
9176 : : }
9177 : 4620 : }
9178 : 5328 : if (cp_oacc_check_attachments (c))
9179 : 12 : remove = true;
9180 : 5328 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9181 : 4394 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9182 : 4330 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9183 : 5426 : && !OMP_CLAUSE_SIZE (c))
9184 : : /* In this case, we have a single array element which is a
9185 : : pointer, and we already set OMP_CLAUSE_SIZE in
9186 : : handle_omp_array_sections above. For attach/detach
9187 : : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
9188 : : to zero here. */
9189 : 60 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9190 : : break;
9191 : : }
9192 : 13763 : else if (type_dependent_expression_p (t))
9193 : : break;
9194 : 12989 : else if (!omp_parse_expr (addr_tokens, t))
9195 : : {
9196 : 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
9197 : : "unsupported map expression %qE",
9198 : 0 : OMP_CLAUSE_DECL (c));
9199 : 0 : remove = true;
9200 : 0 : break;
9201 : : }
9202 : 12989 : if (t == error_mark_node)
9203 : : {
9204 : : remove = true;
9205 : : break;
9206 : : }
9207 : : /* OpenACC attach / detach clauses must be pointers. */
9208 : 12922 : if (cp_oacc_check_attachments (c))
9209 : : {
9210 : : remove = true;
9211 : : break;
9212 : : }
9213 : 12898 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9214 : 9937 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
9215 : 9888 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
9216 : 12972 : && !OMP_CLAUSE_SIZE (c))
9217 : : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
9218 : : bias) to zero here, so it is not set erroneously to the
9219 : : pointer size later on in gimplify.cc. */
9220 : 66 : OMP_CLAUSE_SIZE (c) = size_zero_node;
9221 : :
9222 : 12898 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9223 : :
9224 : 12898 : if (!ai.check_clause (c))
9225 : : {
9226 : : remove = true;
9227 : : break;
9228 : : }
9229 : :
9230 : 12877 : if (!ai.map_supported_p ())
9231 : : {
9232 : 88 : sorry_at (OMP_CLAUSE_LOCATION (c),
9233 : : "unsupported map expression %qE",
9234 : 44 : OMP_CLAUSE_DECL (c));
9235 : 44 : remove = true;
9236 : 44 : break;
9237 : : }
9238 : :
9239 : 25666 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
9240 : : || addr_tokens[0]->type == STRUCTURE_BASE)
9241 : : && addr_tokens[1]->type == ACCESS_METHOD);
9242 : :
9243 : 12833 : t = addr_tokens[1]->expr;
9244 : :
9245 : : /* This is used to prevent cxx_mark_addressable from being called
9246 : : on 'this' for expressions like 'this->a', i.e. typical member
9247 : : accesses. */
9248 : 12833 : indir_component_ref_p
9249 : 25666 : = (addr_tokens[0]->type == STRUCTURE_BASE
9250 : 12833 : && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
9251 : :
9252 : 12833 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
9253 : 1 : goto skip_decl_checks;
9254 : :
9255 : : /* For OpenMP, we can access a struct "t" and "t.d" on the same
9256 : : mapping. OpenACC allows multiple fields of the same structure
9257 : : to be written. */
9258 : 12832 : if (addr_tokens[0]->type == STRUCTURE_BASE
9259 : 12832 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
9260 : 1197 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
9261 : 1168 : goto skip_decl_checks;
9262 : :
9263 : 11664 : if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
9264 : : {
9265 : 0 : OMP_CLAUSE_DECL (c)
9266 : 0 : = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
9267 : 0 : break;
9268 : : }
9269 : 11664 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9270 : : {
9271 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9272 : : break;
9273 : 0 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9274 : 0 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9275 : 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
9276 : 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
9277 : 0 : || (!openacc && EXPR_P (t))))
9278 : : break;
9279 : 0 : if (DECL_P (t))
9280 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9281 : : "%qD is not a variable in %qs clause", t,
9282 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9283 : : else
9284 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9285 : : "%qE is not a variable in %qs clause", t,
9286 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9287 : : remove = true;
9288 : : }
9289 : 11664 : else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
9290 : : {
9291 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9292 : : "%qD is threadprivate variable in %qs clause", t,
9293 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9294 : 0 : remove = true;
9295 : : }
9296 : 11664 : else if (!processing_template_decl
9297 : 11488 : && !TYPE_REF_P (TREE_TYPE (t))
9298 : 10815 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9299 : 7904 : || (OMP_CLAUSE_MAP_KIND (c)
9300 : : != GOMP_MAP_FIRSTPRIVATE_POINTER))
9301 : 8881 : && !indir_component_ref_p
9302 : 8517 : && (t != current_class_ptr
9303 : 18 : || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9304 : 6 : || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
9305 : 20181 : && !cxx_mark_addressable (t))
9306 : : remove = true;
9307 : 11664 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9308 : 8735 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9309 : 8735 : || (OMP_CLAUSE_MAP_KIND (c)
9310 : : == GOMP_MAP_FIRSTPRIVATE_POINTER)
9311 : 6801 : || (OMP_CLAUSE_MAP_KIND (c)
9312 : : == GOMP_MAP_ATTACH_DETACH)))
9313 : 9078 : && t == OMP_CLAUSE_DECL (c)
9314 : 8446 : && !type_dependent_expression_p (t)
9315 : 28556 : && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
9316 : 274 : ? TREE_TYPE (TREE_TYPE (t))
9317 : 8172 : : TREE_TYPE (t)))
9318 : : {
9319 : 42 : auto_diagnostic_group d;
9320 : 84 : error_at (OMP_CLAUSE_LOCATION (c),
9321 : : "%qD does not have a mappable type in %qs clause", t,
9322 : 42 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9323 : 42 : if (TREE_TYPE (t) != error_mark_node
9324 : 42 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9325 : 39 : cxx_incomplete_type_inform (TREE_TYPE (t));
9326 : 42 : remove = true;
9327 : 42 : }
9328 : 11622 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9329 : 8699 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
9330 : 93 : && !type_dependent_expression_p (t)
9331 : 11715 : && !INDIRECT_TYPE_P (TREE_TYPE (t)))
9332 : : {
9333 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9334 : : "%qD is not a pointer variable", t);
9335 : 6 : remove = true;
9336 : : }
9337 : 11616 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9338 : 8693 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9339 : 12024 : && (bitmap_bit_p (&map_head, DECL_UID (t))
9340 : 372 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
9341 : 372 : || bitmap_bit_p (&map_firstprivate_head,
9342 : 372 : DECL_UID (t))))
9343 : : remove = true;
9344 : 11577 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9345 : 11577 : && (OMP_CLAUSE_MAP_KIND (c)
9346 : : == GOMP_MAP_FIRSTPRIVATE_POINTER))
9347 : : {
9348 : 1928 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
9349 : 1928 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9350 : 3853 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
9351 : : {
9352 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
9353 : : "%qD appears more than once in data clauses", t);
9354 : 15 : remove = true;
9355 : : }
9356 : 1913 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9357 : 12 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9358 : 1921 : && openacc)
9359 : : {
9360 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9361 : : "%qD appears more than once in data clauses", t);
9362 : 3 : remove = true;
9363 : : }
9364 : : else
9365 : 1910 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9366 : : }
9367 : 9649 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9368 : 9649 : && (OMP_CLAUSE_MAP_KIND (c)
9369 : : == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
9370 : 115 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9371 : 9534 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9372 : 171 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9373 : 28 : && ort != C_ORT_OMP
9374 : 9562 : && ort != C_ORT_OMP_EXIT_DATA)
9375 : : {
9376 : 18 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9377 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9378 : : "%qD appears more than once in motion clauses", t);
9379 : 18 : else if (openacc)
9380 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9381 : : "%qD appears more than once in data clauses", t);
9382 : : else
9383 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9384 : : "%qD appears more than once in map clauses", t);
9385 : : remove = true;
9386 : : }
9387 : 9516 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
9388 : : {
9389 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9390 : : "%qD appears more than once in data clauses", t);
9391 : 0 : remove = true;
9392 : : }
9393 : 9516 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9394 : 9516 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
9395 : : {
9396 : 27 : if (openacc)
9397 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9398 : : "%qD appears more than once in data clauses", t);
9399 : : else
9400 : 27 : error_at (OMP_CLAUSE_LOCATION (c),
9401 : : "%qD appears both in data and map clauses", t);
9402 : : remove = true;
9403 : : }
9404 : 9489 : else if (!omp_access_chain_p (addr_tokens, 1))
9405 : : {
9406 : 9409 : bitmap_set_bit (&map_head, DECL_UID (t));
9407 : :
9408 : 9409 : tree decl = OMP_CLAUSE_DECL (c);
9409 : 9409 : if (t != decl
9410 : 9409 : && (TREE_CODE (decl) == COMPONENT_REF
9411 : 162 : || (INDIRECT_REF_P (decl)
9412 : 162 : && (TREE_CODE (TREE_OPERAND (decl, 0))
9413 : : == COMPONENT_REF)
9414 : 150 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
9415 : : 0))))))
9416 : 1099 : bitmap_set_bit (&map_field_head, DECL_UID (t));
9417 : : }
9418 : :
9419 : 4359 : skip_decl_checks:
9420 : : /* If we call ai.expand_map_clause in handle_omp_array_sections,
9421 : : the containing loop (here) iterates through the new nodes
9422 : : created by that expansion. Avoid expanding those again (just
9423 : : by checking the node type). */
9424 : 4359 : if (!remove
9425 : 12683 : && !processing_template_decl
9426 : 12510 : && ort != C_ORT_DECLARE_SIMD
9427 : 12510 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9428 : 9567 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
9429 : 7657 : && (OMP_CLAUSE_MAP_KIND (c)
9430 : : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
9431 : 7542 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
9432 : 7542 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
9433 : 6551 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
9434 : 6502 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
9435 : : {
9436 : 9420 : grp_start_p = pc;
9437 : 9420 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9438 : 9420 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
9439 : : addr_tokens, ort);
9440 : 9420 : if (nc != error_mark_node)
9441 : 9420 : c = nc;
9442 : : }
9443 : 19688 : }
9444 : 12833 : break;
9445 : :
9446 : 591 : case OMP_CLAUSE_ENTER:
9447 : 591 : case OMP_CLAUSE_LINK:
9448 : 591 : t = OMP_CLAUSE_DECL (c);
9449 : 591 : const char *cname;
9450 : 591 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
9451 : 591 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
9452 : 591 : && OMP_CLAUSE_ENTER_TO (c))
9453 : : cname = "to";
9454 : 591 : if (TREE_CODE (t) == FUNCTION_DECL
9455 : 591 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9456 : : ;
9457 : 377 : else if (!VAR_P (t))
9458 : : {
9459 : 12 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9460 : : {
9461 : 9 : if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
9462 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9463 : : "template %qE in clause %qs", t, cname);
9464 : 3 : else if (really_overloaded_fn (t))
9465 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9466 : : "overloaded function name %qE in clause %qs", t,
9467 : : cname);
9468 : : else
9469 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9470 : : "%qE is neither a variable nor a function name "
9471 : : "in clause %qs", t, cname);
9472 : : }
9473 : : else
9474 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9475 : : "%qE is not a variable in clause %qs", t, cname);
9476 : : remove = true;
9477 : : }
9478 : 365 : else if (DECL_THREAD_LOCAL_P (t))
9479 : : {
9480 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9481 : : "%qD is threadprivate variable in %qs clause", t,
9482 : : cname);
9483 : 6 : remove = true;
9484 : : }
9485 : 359 : else if (!omp_mappable_type (TREE_TYPE (t)))
9486 : : {
9487 : 18 : auto_diagnostic_group d;
9488 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
9489 : : "%qD does not have a mappable type in %qs clause", t,
9490 : : cname);
9491 : 18 : if (TREE_TYPE (t) != error_mark_node
9492 : 18 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9493 : 18 : cxx_incomplete_type_inform (TREE_TYPE (t));
9494 : 18 : remove = true;
9495 : 18 : }
9496 : 24 : if (remove)
9497 : : break;
9498 : 555 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9499 : : {
9500 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
9501 : : "%qE appears more than once on the same "
9502 : : "%<declare target%> directive", t);
9503 : 24 : remove = true;
9504 : : }
9505 : : else
9506 : 531 : bitmap_set_bit (&generic_head, DECL_UID (t));
9507 : : break;
9508 : :
9509 : 457 : case OMP_CLAUSE_UNIFORM:
9510 : 457 : t = OMP_CLAUSE_DECL (c);
9511 : 457 : if (TREE_CODE (t) != PARM_DECL)
9512 : : {
9513 : 0 : if (processing_template_decl)
9514 : : break;
9515 : 0 : if (DECL_P (t))
9516 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9517 : : "%qD is not an argument in %<uniform%> clause", t);
9518 : : else
9519 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9520 : : "%qE is not an argument in %<uniform%> clause", t);
9521 : : remove = true;
9522 : : break;
9523 : : }
9524 : : /* map_head bitmap is used as uniform_head if declare_simd. */
9525 : 457 : bitmap_set_bit (&map_head, DECL_UID (t));
9526 : 457 : goto check_dup_generic;
9527 : :
9528 : 165 : case OMP_CLAUSE_GRAINSIZE:
9529 : 165 : t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
9530 : 165 : if (t == error_mark_node)
9531 : : remove = true;
9532 : 165 : else if (!type_dependent_expression_p (t)
9533 : 165 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9534 : : {
9535 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9536 : : "%<grainsize%> expression must be integral");
9537 : 0 : remove = true;
9538 : : }
9539 : : else
9540 : : {
9541 : 165 : t = mark_rvalue_use (t);
9542 : 165 : if (!processing_template_decl)
9543 : : {
9544 : 164 : t = maybe_constant_value (t);
9545 : 164 : if (TREE_CODE (t) == INTEGER_CST
9546 : 164 : && tree_int_cst_sgn (t) != 1)
9547 : : {
9548 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9549 : : "%<grainsize%> value must be positive");
9550 : 0 : t = integer_one_node;
9551 : : }
9552 : 164 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9553 : : }
9554 : 165 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
9555 : : }
9556 : : break;
9557 : :
9558 : 273 : case OMP_CLAUSE_PRIORITY:
9559 : 273 : t = OMP_CLAUSE_PRIORITY_EXPR (c);
9560 : 273 : if (t == error_mark_node)
9561 : : remove = true;
9562 : 273 : else if (!type_dependent_expression_p (t)
9563 : 273 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9564 : : {
9565 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9566 : : "%<priority%> expression must be integral");
9567 : 0 : remove = true;
9568 : : }
9569 : : else
9570 : : {
9571 : 273 : t = mark_rvalue_use (t);
9572 : 273 : if (!processing_template_decl)
9573 : : {
9574 : 273 : t = maybe_constant_value (t);
9575 : 273 : if (TREE_CODE (t) == INTEGER_CST
9576 : 273 : && tree_int_cst_sgn (t) == -1)
9577 : : {
9578 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9579 : : "%<priority%> value must be non-negative");
9580 : 0 : t = integer_one_node;
9581 : : }
9582 : 273 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9583 : : }
9584 : 273 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
9585 : : }
9586 : : break;
9587 : :
9588 : 228 : case OMP_CLAUSE_HINT:
9589 : 228 : t = OMP_CLAUSE_HINT_EXPR (c);
9590 : 228 : if (t == error_mark_node)
9591 : : remove = true;
9592 : 228 : else if (!type_dependent_expression_p (t)
9593 : 228 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9594 : : {
9595 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9596 : : "%<hint%> expression must be integral");
9597 : 9 : remove = true;
9598 : : }
9599 : : else
9600 : : {
9601 : 219 : t = mark_rvalue_use (t);
9602 : 219 : if (!processing_template_decl)
9603 : : {
9604 : 171 : t = maybe_constant_value (t);
9605 : 171 : if (TREE_CODE (t) != INTEGER_CST)
9606 : : {
9607 : 16 : error_at (OMP_CLAUSE_LOCATION (c),
9608 : : "%<hint%> expression must be constant integer "
9609 : : "expression");
9610 : 16 : remove = true;
9611 : : }
9612 : : }
9613 : 219 : OMP_CLAUSE_HINT_EXPR (c) = t;
9614 : : }
9615 : : break;
9616 : :
9617 : 183 : case OMP_CLAUSE_FILTER:
9618 : 183 : t = OMP_CLAUSE_FILTER_EXPR (c);
9619 : 183 : if (t == error_mark_node)
9620 : : remove = true;
9621 : 183 : else if (!type_dependent_expression_p (t)
9622 : 183 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9623 : : {
9624 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9625 : : "%<filter%> expression must be integral");
9626 : 6 : remove = true;
9627 : : }
9628 : : else
9629 : : {
9630 : 177 : t = mark_rvalue_use (t);
9631 : 177 : if (!processing_template_decl)
9632 : : {
9633 : 174 : t = maybe_constant_value (t);
9634 : 174 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9635 : : }
9636 : 177 : OMP_CLAUSE_FILTER_EXPR (c) = t;
9637 : : }
9638 : : break;
9639 : :
9640 : 432 : case OMP_CLAUSE_IS_DEVICE_PTR:
9641 : 432 : case OMP_CLAUSE_USE_DEVICE_PTR:
9642 : 432 : field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
9643 : 432 : t = OMP_CLAUSE_DECL (c);
9644 : 432 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
9645 : 328 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9646 : 432 : if (!type_dependent_expression_p (t))
9647 : : {
9648 : 430 : tree type = TREE_TYPE (t);
9649 : 430 : if (!TYPE_PTR_P (type)
9650 : 430 : && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
9651 : : {
9652 : 57 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
9653 : 57 : && ort == C_ORT_OMP)
9654 : : {
9655 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9656 : : "%qs variable is neither a pointer "
9657 : : "nor reference to pointer",
9658 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9659 : 3 : remove = true;
9660 : : }
9661 : 54 : else if (TREE_CODE (type) != ARRAY_TYPE
9662 : 54 : && (!TYPE_REF_P (type)
9663 : 2 : || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
9664 : : {
9665 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
9666 : : "%qs variable is neither a pointer, nor an "
9667 : : "array nor reference to pointer or array",
9668 : 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9669 : 12 : remove = true;
9670 : : }
9671 : : }
9672 : : }
9673 : 432 : goto check_dup_generic;
9674 : :
9675 : 266 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
9676 : 266 : t = OMP_CLAUSE_DECL (c);
9677 : 266 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9678 : : {
9679 : 28 : if (handle_omp_array_sections (c, ort))
9680 : : remove = true;
9681 : : else
9682 : : {
9683 : 28 : t = OMP_CLAUSE_DECL (c);
9684 : 30 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
9685 : 2 : t = TREE_OPERAND (t, 0);
9686 : 64 : while (INDIRECT_REF_P (t)
9687 : 64 : || TREE_CODE (t) == ARRAY_REF)
9688 : 36 : t = TREE_OPERAND (t, 0);
9689 : : }
9690 : : }
9691 : 266 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9692 : : {
9693 : 266 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9694 : 266 : if (!processing_template_decl
9695 : 266 : && !cxx_mark_addressable (t))
9696 : : remove = true;
9697 : : }
9698 : 266 : goto check_dup_generic_t;
9699 : :
9700 : 76 : case OMP_CLAUSE_USE_DEVICE_ADDR:
9701 : 76 : field_ok = true;
9702 : 76 : t = OMP_CLAUSE_DECL (c);
9703 : 76 : if (!processing_template_decl
9704 : 74 : && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9705 : 74 : && !TYPE_REF_P (TREE_TYPE (t))
9706 : 143 : && !cxx_mark_addressable (t))
9707 : : remove = true;
9708 : 76 : goto check_dup_generic;
9709 : :
9710 : : case OMP_CLAUSE_NOWAIT:
9711 : : case OMP_CLAUSE_DEFAULT:
9712 : : case OMP_CLAUSE_UNTIED:
9713 : : case OMP_CLAUSE_COLLAPSE:
9714 : : case OMP_CLAUSE_PARALLEL:
9715 : : case OMP_CLAUSE_FOR:
9716 : : case OMP_CLAUSE_SECTIONS:
9717 : : case OMP_CLAUSE_TASKGROUP:
9718 : : case OMP_CLAUSE_PROC_BIND:
9719 : : case OMP_CLAUSE_DEVICE_TYPE:
9720 : : case OMP_CLAUSE_NOGROUP:
9721 : : case OMP_CLAUSE_THREADS:
9722 : : case OMP_CLAUSE_SIMD:
9723 : : case OMP_CLAUSE_DEFAULTMAP:
9724 : : case OMP_CLAUSE_BIND:
9725 : : case OMP_CLAUSE_AUTO:
9726 : : case OMP_CLAUSE_INDEPENDENT:
9727 : : case OMP_CLAUSE_SEQ:
9728 : : case OMP_CLAUSE_IF_PRESENT:
9729 : : case OMP_CLAUSE_FINALIZE:
9730 : : case OMP_CLAUSE_NOHOST:
9731 : : case OMP_CLAUSE_INDIRECT:
9732 : : break;
9733 : :
9734 : 228 : case OMP_CLAUSE_MERGEABLE:
9735 : 228 : mergeable_seen = true;
9736 : 228 : break;
9737 : :
9738 : 322 : case OMP_CLAUSE_TILE:
9739 : 754 : for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
9740 : 432 : list = TREE_CHAIN (list))
9741 : : {
9742 : 432 : t = TREE_VALUE (list);
9743 : :
9744 : 432 : if (t == error_mark_node)
9745 : : remove = true;
9746 : 403 : else if (!type_dependent_expression_p (t)
9747 : 403 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9748 : : {
9749 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9750 : : "%<tile%> argument needs integral type");
9751 : 3 : remove = true;
9752 : : }
9753 : : else
9754 : : {
9755 : 400 : t = mark_rvalue_use (t);
9756 : 400 : if (!processing_template_decl)
9757 : : {
9758 : : /* Zero is used to indicate '*', we permit you
9759 : : to get there via an ICE of value zero. */
9760 : 385 : t = maybe_constant_value (t);
9761 : 385 : if (!tree_fits_shwi_p (t)
9762 : 369 : || tree_to_shwi (t) < 0)
9763 : : {
9764 : 40 : error_at (OMP_CLAUSE_LOCATION (c),
9765 : : "%<tile%> argument needs positive "
9766 : : "integral constant");
9767 : 40 : remove = true;
9768 : : }
9769 : : }
9770 : : }
9771 : :
9772 : : /* Update list item. */
9773 : 432 : TREE_VALUE (list) = t;
9774 : : }
9775 : : break;
9776 : :
9777 : 1027 : case OMP_CLAUSE_SIZES:
9778 : 1027 : for (tree list = OMP_CLAUSE_SIZES_LIST (c);
9779 : 2688 : !remove && list; list = TREE_CHAIN (list))
9780 : : {
9781 : 1661 : t = TREE_VALUE (list);
9782 : :
9783 : 1661 : if (t == error_mark_node)
9784 : 0 : t = integer_one_node;
9785 : 1661 : else if (!type_dependent_expression_p (t)
9786 : 1661 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9787 : : {
9788 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
9789 : : "%<sizes%> argument needs positive integral "
9790 : : "constant");
9791 : 8 : t = integer_one_node;
9792 : : }
9793 : : else
9794 : : {
9795 : 1653 : t = mark_rvalue_use (t);
9796 : 1653 : if (!processing_template_decl)
9797 : : {
9798 : 1636 : t = maybe_constant_value (t);
9799 : 1636 : HOST_WIDE_INT n;
9800 : 1636 : if (!tree_fits_shwi_p (t)
9801 : 1632 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
9802 : 1632 : || (n = tree_to_shwi (t)) <= 0
9803 : 3240 : || (int)n != n)
9804 : : {
9805 : 32 : error_at (OMP_CLAUSE_LOCATION (c),
9806 : : "%<sizes%> argument needs positive "
9807 : : "integral constant");
9808 : 32 : t = integer_one_node;
9809 : : }
9810 : : }
9811 : : }
9812 : :
9813 : : /* Update list item. */
9814 : 1661 : TREE_VALUE (list) = t;
9815 : : }
9816 : : break;
9817 : :
9818 : 627 : case OMP_CLAUSE_ORDERED:
9819 : 627 : ordered_seen = true;
9820 : 627 : break;
9821 : :
9822 : 1549 : case OMP_CLAUSE_ORDER:
9823 : 1549 : if (order_seen)
9824 : : remove = true;
9825 : : else
9826 : : order_seen = true;
9827 : : break;
9828 : :
9829 : 638 : case OMP_CLAUSE_INBRANCH:
9830 : 638 : case OMP_CLAUSE_NOTINBRANCH:
9831 : 638 : if (branch_seen)
9832 : : {
9833 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9834 : : "%<inbranch%> clause is incompatible with "
9835 : : "%<notinbranch%>");
9836 : 3 : remove = true;
9837 : : }
9838 : : branch_seen = true;
9839 : : break;
9840 : :
9841 : 297 : case OMP_CLAUSE_INCLUSIVE:
9842 : 297 : case OMP_CLAUSE_EXCLUSIVE:
9843 : 297 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
9844 : 297 : if (!t)
9845 : 297 : t = OMP_CLAUSE_DECL (c);
9846 : 297 : if (t == current_class_ptr)
9847 : : {
9848 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9849 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
9850 : : " clauses");
9851 : 0 : remove = true;
9852 : 0 : break;
9853 : : }
9854 : 297 : if (!VAR_P (t)
9855 : : && TREE_CODE (t) != PARM_DECL
9856 : : && TREE_CODE (t) != FIELD_DECL)
9857 : : {
9858 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9859 : : break;
9860 : 0 : if (DECL_P (t))
9861 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9862 : : "%qD is not a variable in clause %qs", t,
9863 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9864 : : else
9865 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9866 : : "%qE is not a variable in clause %qs", t,
9867 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9868 : : remove = true;
9869 : : }
9870 : : break;
9871 : :
9872 : : case OMP_CLAUSE_FULL:
9873 : : break;
9874 : :
9875 : 470 : case OMP_CLAUSE_PARTIAL:
9876 : 470 : partial_seen = true;
9877 : 470 : t = OMP_CLAUSE_PARTIAL_EXPR (c);
9878 : 470 : if (!t)
9879 : : break;
9880 : :
9881 : 313 : if (t == error_mark_node)
9882 : : t = NULL_TREE;
9883 : 313 : else if (!type_dependent_expression_p (t)
9884 : 313 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9885 : : {
9886 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9887 : : "%<partial%> argument needs positive constant "
9888 : : "integer expression");
9889 : 3 : t = NULL_TREE;
9890 : : }
9891 : : else
9892 : : {
9893 : 310 : t = mark_rvalue_use (t);
9894 : 310 : if (!processing_template_decl)
9895 : : {
9896 : 292 : t = maybe_constant_value (t);
9897 : :
9898 : 292 : HOST_WIDE_INT n;
9899 : 584 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
9900 : 292 : || !tree_fits_shwi_p (t)
9901 : 286 : || (n = tree_to_shwi (t)) <= 0
9902 : 560 : || (int)n != n)
9903 : : {
9904 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
9905 : : "%<partial%> argument needs positive "
9906 : : "constant integer expression");
9907 : 24 : t = NULL_TREE;
9908 : : }
9909 : : }
9910 : : }
9911 : :
9912 : 313 : OMP_CLAUSE_PARTIAL_EXPR (c) = t;
9913 : 313 : break;
9914 : 549 : case OMP_CLAUSE_INIT:
9915 : 549 : init_seen = true;
9916 : 549 : OMP_CLAUSE_INIT_PREFER_TYPE (c)
9917 : 549 : = cp_finish_omp_init_prefer_type (OMP_CLAUSE_INIT_PREFER_TYPE (c));
9918 : 549 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
9919 : 271 : init_no_targetsync_clause = c;
9920 : : /* FALLTHRU */
9921 : 844 : case OMP_CLAUSE_DESTROY:
9922 : 844 : case OMP_CLAUSE_USE:
9923 : 844 : init_use_destroy_seen = true;
9924 : 844 : t = OMP_CLAUSE_DECL (c);
9925 : 844 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9926 : : {
9927 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9928 : : "%qD appears more than once in action clauses", t);
9929 : 9 : remove = true;
9930 : 9 : break;
9931 : : }
9932 : 835 : bitmap_set_bit (&generic_head, DECL_UID (t));
9933 : : /* FALLTHRU */
9934 : 1099 : case OMP_CLAUSE_INTEROP:
9935 : 1099 : if (!processing_template_decl)
9936 : : {
9937 : 1003 : if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
9938 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) && */
9939 : 1003 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
9940 : : {
9941 : 126 : error_at (OMP_CLAUSE_LOCATION (c),
9942 : : "%qD must be of %<omp_interop_t%>",
9943 : 63 : OMP_CLAUSE_DECL (c));
9944 : 63 : remove = true;
9945 : : }
9946 : 940 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
9947 : 481 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
9948 : 1058 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
9949 : : {
9950 : 36 : error_at (OMP_CLAUSE_LOCATION (c),
9951 : 18 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
9952 : 18 : remove = true;
9953 : : }
9954 : : }
9955 : 1099 : pc = &OMP_CLAUSE_CHAIN (c);
9956 : 1099 : break;
9957 : 0 : default:
9958 : 0 : gcc_unreachable ();
9959 : : }
9960 : :
9961 : 96694 : if (remove)
9962 : : {
9963 : 2499 : if (grp_start_p)
9964 : : {
9965 : : /* If we found a clause to remove, we want to remove the whole
9966 : : expanded group, otherwise gimplify
9967 : : (omp_resolve_clause_dependencies) can get confused. */
9968 : 820 : *grp_start_p = grp_sentinel;
9969 : 820 : pc = grp_start_p;
9970 : 820 : grp_start_p = NULL;
9971 : : }
9972 : : else
9973 : 1679 : *pc = OMP_CLAUSE_CHAIN (c);
9974 : : }
9975 : : else
9976 : 94195 : pc = &OMP_CLAUSE_CHAIN (c);
9977 : : }
9978 : :
9979 : 62183 : if (grp_start_p
9980 : 62183 : && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
9981 : 131 : for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
9982 : 80 : OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
9983 : :
9984 : 62183 : if (reduction_seen < 0 && (ordered_seen || schedule_seen))
9985 : 62183 : reduction_seen = -2;
9986 : :
9987 : 157281 : for (pc = &clauses, c = clauses; c ; c = *pc)
9988 : : {
9989 : 95098 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
9990 : 95098 : bool remove = false;
9991 : 95098 : bool need_complete_type = false;
9992 : 95098 : bool need_default_ctor = false;
9993 : 95098 : bool need_copy_ctor = false;
9994 : 95098 : bool need_copy_assignment = false;
9995 : 95098 : bool need_implicitly_determined = false;
9996 : 95098 : bool need_dtor = false;
9997 : 95098 : tree type, inner_type;
9998 : :
9999 : 95098 : switch (c_kind)
10000 : : {
10001 : : case OMP_CLAUSE_SHARED:
10002 : : need_implicitly_determined = true;
10003 : : break;
10004 : 2508 : case OMP_CLAUSE_PRIVATE:
10005 : 2508 : need_complete_type = true;
10006 : 2508 : need_default_ctor = true;
10007 : 2508 : need_dtor = true;
10008 : 2508 : need_implicitly_determined = true;
10009 : 2508 : break;
10010 : 3118 : case OMP_CLAUSE_FIRSTPRIVATE:
10011 : 3118 : need_complete_type = true;
10012 : 3118 : need_copy_ctor = true;
10013 : 3118 : need_dtor = true;
10014 : 3118 : need_implicitly_determined = true;
10015 : 3118 : break;
10016 : 2760 : case OMP_CLAUSE_LASTPRIVATE:
10017 : 2760 : need_complete_type = true;
10018 : 2760 : need_copy_assignment = true;
10019 : 2760 : need_implicitly_determined = true;
10020 : 2760 : break;
10021 : 7286 : case OMP_CLAUSE_REDUCTION:
10022 : 7286 : if (reduction_seen == -2)
10023 : 27 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
10024 : 7286 : if (OMP_CLAUSE_REDUCTION_INSCAN (c))
10025 : 421 : need_copy_assignment = true;
10026 : : need_implicitly_determined = true;
10027 : : break;
10028 : : case OMP_CLAUSE_IN_REDUCTION:
10029 : : case OMP_CLAUSE_TASK_REDUCTION:
10030 : : case OMP_CLAUSE_INCLUSIVE:
10031 : : case OMP_CLAUSE_EXCLUSIVE:
10032 : : need_implicitly_determined = true;
10033 : : break;
10034 : 1532 : case OMP_CLAUSE_LINEAR:
10035 : 1532 : if (ort != C_ORT_OMP_DECLARE_SIMD)
10036 : : need_implicitly_determined = true;
10037 : 661 : else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
10038 : 703 : && !bitmap_bit_p (&map_head,
10039 : 42 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
10040 : : {
10041 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10042 : : "%<linear%> clause step is a parameter %qD not "
10043 : : "specified in %<uniform%> clause",
10044 : 6 : OMP_CLAUSE_LINEAR_STEP (c));
10045 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
10046 : 73669 : continue;
10047 : : }
10048 : : break;
10049 : : case OMP_CLAUSE_COPYPRIVATE:
10050 : 366 : need_copy_assignment = true;
10051 : : break;
10052 : : case OMP_CLAUSE_COPYIN:
10053 : 366 : need_copy_assignment = true;
10054 : : break;
10055 : 798 : case OMP_CLAUSE_SIMDLEN:
10056 : 798 : if (safelen
10057 : 345 : && !processing_template_decl
10058 : 1143 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
10059 : 345 : OMP_CLAUSE_SIMDLEN_EXPR (c)))
10060 : : {
10061 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
10062 : : "%<simdlen%> clause value is bigger than "
10063 : : "%<safelen%> clause value");
10064 : 0 : OMP_CLAUSE_SIMDLEN_EXPR (c)
10065 : 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
10066 : : }
10067 : 798 : pc = &OMP_CLAUSE_CHAIN (c);
10068 : 798 : continue;
10069 : 3850 : case OMP_CLAUSE_SCHEDULE:
10070 : 3850 : if (ordered_seen
10071 : 3850 : && (OMP_CLAUSE_SCHEDULE_KIND (c)
10072 : : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
10073 : : {
10074 : 21 : error_at (OMP_CLAUSE_LOCATION (c),
10075 : : "%<nonmonotonic%> schedule modifier specified "
10076 : : "together with %<ordered%> clause");
10077 : 42 : OMP_CLAUSE_SCHEDULE_KIND (c)
10078 : 21 : = (enum omp_clause_schedule_kind)
10079 : 21 : (OMP_CLAUSE_SCHEDULE_KIND (c)
10080 : : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
10081 : : }
10082 : 3850 : if (reduction_seen == -2)
10083 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
10084 : : "%qs clause specified together with %<inscan%> "
10085 : : "%<reduction%> clause", "schedule");
10086 : 3850 : pc = &OMP_CLAUSE_CHAIN (c);
10087 : 3850 : continue;
10088 : 51 : case OMP_CLAUSE_NOGROUP:
10089 : 51 : if (reduction_seen)
10090 : : {
10091 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
10092 : : "%<nogroup%> clause must not be used together with "
10093 : : "%<reduction%> clause");
10094 : 3 : *pc = OMP_CLAUSE_CHAIN (c);
10095 : 3 : continue;
10096 : : }
10097 : 48 : pc = &OMP_CLAUSE_CHAIN (c);
10098 : 48 : continue;
10099 : 165 : case OMP_CLAUSE_GRAINSIZE:
10100 : 165 : if (num_tasks_seen)
10101 : : {
10102 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10103 : : "%<grainsize%> clause must not be used together with "
10104 : : "%<num_tasks%> clause");
10105 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
10106 : 6 : continue;
10107 : : }
10108 : 159 : pc = &OMP_CLAUSE_CHAIN (c);
10109 : 159 : continue;
10110 : 627 : case OMP_CLAUSE_ORDERED:
10111 : 627 : if (reduction_seen == -2)
10112 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10113 : : "%qs clause specified together with %<inscan%> "
10114 : : "%<reduction%> clause", "ordered");
10115 : 627 : pc = &OMP_CLAUSE_CHAIN (c);
10116 : 627 : continue;
10117 : 1525 : case OMP_CLAUSE_ORDER:
10118 : 1525 : if (ordered_seen)
10119 : : {
10120 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
10121 : : "%<order%> clause must not be used together "
10122 : : "with %<ordered%> clause");
10123 : 12 : *pc = OMP_CLAUSE_CHAIN (c);
10124 : 12 : continue;
10125 : : }
10126 : 1513 : pc = &OMP_CLAUSE_CHAIN (c);
10127 : 1513 : continue;
10128 : 57 : case OMP_CLAUSE_DETACH:
10129 : 57 : if (mergeable_seen)
10130 : : {
10131 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10132 : : "%<detach%> clause must not be used together with "
10133 : : "%<mergeable%> clause");
10134 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
10135 : 6 : continue;
10136 : : }
10137 : 51 : pc = &OMP_CLAUSE_CHAIN (c);
10138 : 51 : continue;
10139 : 15594 : case OMP_CLAUSE_MAP:
10140 : 15594 : if (target_in_reduction_seen && !processing_template_decl)
10141 : : {
10142 : 684 : t = OMP_CLAUSE_DECL (c);
10143 : 684 : while (handled_component_p (t)
10144 : : || INDIRECT_REF_P (t)
10145 : : || TREE_CODE (t) == ADDR_EXPR
10146 : : || TREE_CODE (t) == MEM_REF
10147 : 804 : || TREE_CODE (t) == NON_LVALUE_EXPR)
10148 : 120 : t = TREE_OPERAND (t, 0);
10149 : 684 : if (DECL_P (t)
10150 : 684 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
10151 : 342 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
10152 : : }
10153 : 15594 : pc = &OMP_CLAUSE_CHAIN (c);
10154 : 15594 : continue;
10155 : 225 : case OMP_CLAUSE_FULL:
10156 : 225 : if (partial_seen)
10157 : : {
10158 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
10159 : : "%<full%> clause must not be used together "
10160 : : "with %<partial%> clause");
10161 : 12 : *pc = OMP_CLAUSE_CHAIN (c);
10162 : 12 : continue;
10163 : : }
10164 : 213 : pc = &OMP_CLAUSE_CHAIN (c);
10165 : 213 : continue;
10166 : 6895 : case OMP_CLAUSE_NOWAIT:
10167 : 6895 : if (copyprivate_seen)
10168 : : {
10169 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10170 : : "%<nowait%> clause must not be used together "
10171 : : "with %<copyprivate%> clause");
10172 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
10173 : 6 : continue;
10174 : : }
10175 : : /* FALLTHRU */
10176 : 50127 : default:
10177 : 50127 : pc = &OMP_CLAUSE_CHAIN (c);
10178 : 50127 : continue;
10179 : : }
10180 : :
10181 : 22067 : t = OMP_CLAUSE_DECL (c);
10182 : 22067 : switch (c_kind)
10183 : : {
10184 : 2760 : case OMP_CLAUSE_LASTPRIVATE:
10185 : 2760 : if (DECL_P (t)
10186 : 2760 : && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
10187 : : {
10188 : 2663 : need_default_ctor = true;
10189 : 2663 : need_dtor = true;
10190 : : }
10191 : : break;
10192 : :
10193 : 9422 : case OMP_CLAUSE_REDUCTION:
10194 : 9422 : case OMP_CLAUSE_IN_REDUCTION:
10195 : 9422 : case OMP_CLAUSE_TASK_REDUCTION:
10196 : 9422 : if (allocate_seen)
10197 : : {
10198 : 1561 : if (TREE_CODE (t) == MEM_REF)
10199 : : {
10200 : 162 : t = TREE_OPERAND (t, 0);
10201 : 162 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
10202 : 0 : t = TREE_OPERAND (t, 0);
10203 : 162 : if (TREE_CODE (t) == ADDR_EXPR
10204 : 120 : || INDIRECT_REF_P (t))
10205 : 80 : t = TREE_OPERAND (t, 0);
10206 : 162 : if (DECL_P (t))
10207 : 162 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10208 : : }
10209 : 1399 : else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
10210 : : {
10211 : 192 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
10212 : 96 : t = TREE_OPERAND (t, 0);
10213 : 96 : if (DECL_P (t))
10214 : 96 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10215 : 96 : t = OMP_CLAUSE_DECL (c);
10216 : : }
10217 : 1303 : else if (DECL_P (t))
10218 : 1303 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10219 : 1561 : t = OMP_CLAUSE_DECL (c);
10220 : : }
10221 : 9422 : if (processing_template_decl
10222 : 863 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10223 : : break;
10224 : 8852 : if (finish_omp_reduction_clause (c, &need_default_ctor,
10225 : : &need_dtor))
10226 : : remove = true;
10227 : : else
10228 : 8768 : t = OMP_CLAUSE_DECL (c);
10229 : : break;
10230 : :
10231 : 274 : case OMP_CLAUSE_COPYIN:
10232 : 274 : if (processing_template_decl
10233 : 0 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10234 : : break;
10235 : 274 : if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
10236 : : {
10237 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
10238 : : "%qE must be %<threadprivate%> for %<copyin%>", t);
10239 : 15 : remove = true;
10240 : : }
10241 : : break;
10242 : :
10243 : : default:
10244 : : break;
10245 : : }
10246 : :
10247 : 22067 : if (processing_template_decl
10248 : 1544 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10249 : : {
10250 : 632 : pc = &OMP_CLAUSE_CHAIN (c);
10251 : 632 : continue;
10252 : : }
10253 : :
10254 : 21435 : if (need_complete_type || need_copy_assignment)
10255 : : {
10256 : 9117 : t = require_complete_type (t);
10257 : 9117 : if (t == error_mark_node)
10258 : : remove = true;
10259 : 9093 : else if (!processing_template_decl
10260 : 8710 : && TYPE_REF_P (TREE_TYPE (t))
10261 : 9621 : && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
10262 : : remove = true;
10263 : : }
10264 : 21435 : if (need_implicitly_determined)
10265 : : {
10266 : 20415 : const char *share_name = NULL;
10267 : :
10268 : 20415 : if (allocate_seen
10269 : 4939 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10270 : 24475 : && DECL_P (t))
10271 : 3850 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10272 : :
10273 : 20415 : if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
10274 : : share_name = "threadprivate";
10275 : 20373 : else switch (cxx_omp_predetermined_sharing_1 (t))
10276 : : {
10277 : : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
10278 : : break;
10279 : 47 : case OMP_CLAUSE_DEFAULT_SHARED:
10280 : 47 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10281 : 30 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
10282 : 64 : && c_omp_predefined_variable (t))
10283 : : /* The __func__ variable and similar function-local predefined
10284 : : variables may be listed in a shared or firstprivate
10285 : : clause. */
10286 : : break;
10287 : 31 : if (VAR_P (t)
10288 : 31 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10289 : 9 : && TREE_STATIC (t)
10290 : 40 : && cxx_omp_const_qual_no_mutable (t))
10291 : : {
10292 : 6 : tree ctx = CP_DECL_CONTEXT (t);
10293 : : /* const qualified static data members without mutable
10294 : : member may be specified in firstprivate clause. */
10295 : 6 : if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
10296 : : break;
10297 : : }
10298 : : share_name = "shared";
10299 : : break;
10300 : : case OMP_CLAUSE_DEFAULT_PRIVATE:
10301 : : share_name = "private";
10302 : : break;
10303 : 0 : default:
10304 : 0 : gcc_unreachable ();
10305 : : }
10306 : : if (share_name)
10307 : : {
10308 : 67 : error_at (OMP_CLAUSE_LOCATION (c),
10309 : : "%qE is predetermined %qs for %qs",
10310 : : omp_clause_printable_decl (t), share_name,
10311 : 67 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10312 : 67 : remove = true;
10313 : : }
10314 : 20348 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10315 : 18292 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
10316 : 35551 : && cxx_omp_const_qual_no_mutable (t))
10317 : : {
10318 : 126 : error_at (OMP_CLAUSE_LOCATION (c),
10319 : : "%<const%> qualified %qE without %<mutable%> member "
10320 : : "may appear only in %<shared%> or %<firstprivate%> "
10321 : : "clauses", omp_clause_printable_decl (t));
10322 : 63 : remove = true;
10323 : : }
10324 : : }
10325 : :
10326 : 21435 : if (detach_seen
10327 : 16 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10328 : 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
10329 : 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10330 : 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
10331 : 21451 : && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
10332 : : {
10333 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10334 : : "the event handle of a %<detach%> clause "
10335 : : "should not be in a data-sharing clause");
10336 : 6 : remove = true;
10337 : : }
10338 : :
10339 : : /* We're interested in the base element, not arrays. */
10340 : 21435 : inner_type = type = TREE_TYPE (t);
10341 : 21435 : if ((need_complete_type
10342 : : || need_copy_assignment
10343 : 12318 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
10344 : 5684 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
10345 : 4214 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
10346 : 29866 : && TYPE_REF_P (inner_type))
10347 : 850 : inner_type = TREE_TYPE (inner_type);
10348 : 23982 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
10349 : 2547 : inner_type = TREE_TYPE (inner_type);
10350 : :
10351 : : /* Check for special function availability by building a call to one.
10352 : : Save the results, because later we won't be in the right context
10353 : : for making these queries. */
10354 : 2384 : if (CLASS_TYPE_P (inner_type)
10355 : 2384 : && COMPLETE_TYPE_P (inner_type)
10356 : 2315 : && (need_default_ctor || need_copy_ctor
10357 : 1079 : || need_copy_assignment || need_dtor)
10358 : 1991 : && !type_dependent_expression_p (t)
10359 : 23426 : && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
10360 : : need_copy_ctor, need_copy_assignment,
10361 : : need_dtor))
10362 : : remove = true;
10363 : :
10364 : 21435 : if (!remove
10365 : 21435 : && c_kind == OMP_CLAUSE_SHARED
10366 : 2053 : && processing_template_decl)
10367 : : {
10368 : 125 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10369 : 125 : if (t)
10370 : 5 : OMP_CLAUSE_DECL (c) = t;
10371 : : }
10372 : :
10373 : 21435 : if (remove)
10374 : 292 : *pc = OMP_CLAUSE_CHAIN (c);
10375 : : else
10376 : 21143 : pc = &OMP_CLAUSE_CHAIN (c);
10377 : : }
10378 : :
10379 : 62183 : if (allocate_seen)
10380 : 16683 : for (pc = &clauses, c = clauses; c ; c = *pc)
10381 : : {
10382 : 14435 : bool remove = false;
10383 : 14435 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
10384 : 2486 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
10385 : 2089 : && DECL_P (OMP_CLAUSE_DECL (c))
10386 : 16524 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
10387 : : {
10388 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
10389 : : "%qD specified in %<allocate%> clause but not in "
10390 : 15 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
10391 : 15 : remove = true;
10392 : : }
10393 : 14435 : if (remove)
10394 : 15 : *pc = OMP_CLAUSE_CHAIN (c);
10395 : : else
10396 : 14420 : pc = &OMP_CLAUSE_CHAIN (c);
10397 : : }
10398 : :
10399 : 62183 : if (ort == C_ORT_OMP_INTEROP
10400 : 62183 : && depend_clause
10401 : 60 : && (!init_use_destroy_seen
10402 : 57 : || (init_seen && init_no_targetsync_clause)))
10403 : : {
10404 : 9 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
10405 : : "%<depend%> clause requires action clauses with "
10406 : : "%<targetsync%> interop-type");
10407 : 9 : if (init_no_targetsync_clause)
10408 : 6 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
10409 : : "%<init%> clause lacks the %<targetsync%> modifier");
10410 : : }
10411 : :
10412 : 62183 : bitmap_obstack_release (NULL);
10413 : 62183 : return clauses;
10414 : : }
10415 : :
10416 : : /* Start processing OpenMP clauses that can include any
10417 : : privatization clauses for non-static data members. */
10418 : :
10419 : : tree
10420 : 48138 : push_omp_privatization_clauses (bool ignore_next)
10421 : : {
10422 : 48138 : if (omp_private_member_ignore_next)
10423 : : {
10424 : 647 : omp_private_member_ignore_next = ignore_next;
10425 : 647 : return NULL_TREE;
10426 : : }
10427 : 47491 : omp_private_member_ignore_next = ignore_next;
10428 : 47491 : if (omp_private_member_map)
10429 : 24 : omp_private_member_vec.safe_push (error_mark_node);
10430 : 47491 : return push_stmt_list ();
10431 : : }
10432 : :
10433 : : /* Revert remapping of any non-static data members since
10434 : : the last push_omp_privatization_clauses () call. */
10435 : :
10436 : : void
10437 : 48132 : pop_omp_privatization_clauses (tree stmt)
10438 : : {
10439 : 48132 : if (stmt == NULL_TREE)
10440 : : return;
10441 : 47485 : stmt = pop_stmt_list (stmt);
10442 : 47485 : if (omp_private_member_map)
10443 : : {
10444 : 1280 : while (!omp_private_member_vec.is_empty ())
10445 : : {
10446 : 850 : tree t = omp_private_member_vec.pop ();
10447 : 850 : if (t == error_mark_node)
10448 : : {
10449 : 24 : add_stmt (stmt);
10450 : 24 : return;
10451 : : }
10452 : 826 : bool no_decl_expr = t == integer_zero_node;
10453 : 826 : if (no_decl_expr)
10454 : 136 : t = omp_private_member_vec.pop ();
10455 : 826 : tree *v = omp_private_member_map->get (t);
10456 : 826 : gcc_assert (v);
10457 : 826 : if (!no_decl_expr)
10458 : 690 : add_decl_expr (*v);
10459 : 826 : omp_private_member_map->remove (t);
10460 : : }
10461 : 860 : delete omp_private_member_map;
10462 : 430 : omp_private_member_map = NULL;
10463 : : }
10464 : 47461 : add_stmt (stmt);
10465 : : }
10466 : :
10467 : : /* Remember OpenMP privatization clauses mapping and clear it.
10468 : : Used for lambdas. */
10469 : :
10470 : : void
10471 : 9114414 : save_omp_privatization_clauses (vec<tree> &save)
10472 : : {
10473 : 9114414 : save = vNULL;
10474 : 9114414 : if (omp_private_member_ignore_next)
10475 : 2 : save.safe_push (integer_one_node);
10476 : 9114414 : omp_private_member_ignore_next = false;
10477 : 9114414 : if (!omp_private_member_map)
10478 : : return;
10479 : :
10480 : 0 : while (!omp_private_member_vec.is_empty ())
10481 : : {
10482 : 0 : tree t = omp_private_member_vec.pop ();
10483 : 0 : if (t == error_mark_node)
10484 : : {
10485 : 0 : save.safe_push (t);
10486 : 0 : continue;
10487 : : }
10488 : 0 : tree n = t;
10489 : 0 : if (t == integer_zero_node)
10490 : 0 : t = omp_private_member_vec.pop ();
10491 : 0 : tree *v = omp_private_member_map->get (t);
10492 : 0 : gcc_assert (v);
10493 : 0 : save.safe_push (*v);
10494 : 0 : save.safe_push (t);
10495 : 0 : if (n != t)
10496 : 0 : save.safe_push (n);
10497 : : }
10498 : 0 : delete omp_private_member_map;
10499 : 0 : omp_private_member_map = NULL;
10500 : : }
10501 : :
10502 : : /* Restore OpenMP privatization clauses mapping saved by the
10503 : : above function. */
10504 : :
10505 : : void
10506 : 9114414 : restore_omp_privatization_clauses (vec<tree> &save)
10507 : : {
10508 : 9114414 : gcc_assert (omp_private_member_vec.is_empty ());
10509 : 9114414 : omp_private_member_ignore_next = false;
10510 : 9114414 : if (save.is_empty ())
10511 : : return;
10512 : 4 : if (save.length () == 1 && save[0] == integer_one_node)
10513 : : {
10514 : 2 : omp_private_member_ignore_next = true;
10515 : 2 : save.release ();
10516 : 2 : return;
10517 : : }
10518 : :
10519 : 0 : omp_private_member_map = new hash_map <tree, tree>;
10520 : 0 : while (!save.is_empty ())
10521 : : {
10522 : 0 : tree t = save.pop ();
10523 : 0 : tree n = t;
10524 : 0 : if (t != error_mark_node)
10525 : : {
10526 : 0 : if (t == integer_one_node)
10527 : : {
10528 : 0 : omp_private_member_ignore_next = true;
10529 : 0 : gcc_assert (save.is_empty ());
10530 : 0 : break;
10531 : : }
10532 : 0 : if (t == integer_zero_node)
10533 : 0 : t = save.pop ();
10534 : 0 : tree &v = omp_private_member_map->get_or_insert (t);
10535 : 0 : v = save.pop ();
10536 : : }
10537 : 0 : omp_private_member_vec.safe_push (t);
10538 : 0 : if (n != t)
10539 : 0 : omp_private_member_vec.safe_push (n);
10540 : : }
10541 : 0 : save.release ();
10542 : : }
10543 : :
10544 : : /* For all variables in the tree_list VARS, mark them as thread local. */
10545 : :
10546 : : void
10547 : 238 : finish_omp_threadprivate (tree vars)
10548 : : {
10549 : 238 : tree t;
10550 : :
10551 : : /* Mark every variable in VARS to be assigned thread local storage. */
10552 : 509 : for (t = vars; t; t = TREE_CHAIN (t))
10553 : : {
10554 : 271 : tree v = TREE_PURPOSE (t);
10555 : 271 : location_t loc = EXPR_LOCATION (TREE_VALUE (t));
10556 : :
10557 : 271 : if (error_operand_p (v))
10558 : : ;
10559 : 271 : else if (!VAR_P (v))
10560 : 6 : error_at (loc, "%<threadprivate%> %qD is not file, namespace "
10561 : : "or block scope variable", v);
10562 : : /* If V had already been marked threadprivate, it doesn't matter
10563 : : whether it had been used prior to this point. */
10564 : 265 : else if (TREE_USED (v)
10565 : 265 : && (DECL_LANG_SPECIFIC (v) == NULL
10566 : 3 : || !CP_DECL_THREADPRIVATE_P (v)))
10567 : 6 : error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10568 : 259 : else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10569 : 6 : error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10570 : 253 : else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
10571 : 3 : error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10572 : 201 : else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
10573 : 273 : && CP_DECL_CONTEXT (v) != current_class_type)
10574 : 6 : error_at (loc, "%<threadprivate%> %qE directive not "
10575 : 6 : "in %qT definition", v, CP_DECL_CONTEXT (v));
10576 : : else
10577 : : {
10578 : : /* Allocate a LANG_SPECIFIC structure for V, if needed. */
10579 : 244 : if (DECL_LANG_SPECIFIC (v) == NULL)
10580 : 200 : retrofit_lang_decl (v);
10581 : :
10582 : 244 : if (! CP_DECL_THREAD_LOCAL_P (v))
10583 : : {
10584 : 244 : CP_DECL_THREAD_LOCAL_P (v) = true;
10585 : 244 : set_decl_tls_model (v, decl_default_tls_model (v));
10586 : : /* If rtl has been already set for this var, call
10587 : : make_decl_rtl once again, so that encode_section_info
10588 : : has a chance to look at the new decl flags. */
10589 : 244 : if (DECL_RTL_SET_P (v))
10590 : 0 : make_decl_rtl (v);
10591 : : }
10592 : 244 : CP_DECL_THREADPRIVATE_P (v) = 1;
10593 : : }
10594 : : }
10595 : 238 : }
10596 : :
10597 : : /* Build an OpenMP structured block. */
10598 : :
10599 : : tree
10600 : 63679 : begin_omp_structured_block (void)
10601 : : {
10602 : 63679 : return do_pushlevel (sk_omp);
10603 : : }
10604 : :
10605 : : tree
10606 : 63658 : finish_omp_structured_block (tree block)
10607 : : {
10608 : 63658 : return do_poplevel (block);
10609 : : }
10610 : :
10611 : : /* Similarly, except force the retention of the BLOCK. */
10612 : :
10613 : : tree
10614 : 14775 : begin_omp_parallel (void)
10615 : : {
10616 : 14775 : keep_next_level (true);
10617 : 14775 : return begin_omp_structured_block ();
10618 : : }
10619 : :
10620 : : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
10621 : : statement. */
10622 : :
10623 : : tree
10624 : 768 : finish_oacc_data (tree clauses, tree block)
10625 : : {
10626 : 768 : tree stmt;
10627 : :
10628 : 768 : block = finish_omp_structured_block (block);
10629 : :
10630 : 768 : stmt = make_node (OACC_DATA);
10631 : 768 : TREE_TYPE (stmt) = void_type_node;
10632 : 768 : OACC_DATA_CLAUSES (stmt) = clauses;
10633 : 768 : OACC_DATA_BODY (stmt) = block;
10634 : :
10635 : 768 : return add_stmt (stmt);
10636 : : }
10637 : :
10638 : : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
10639 : : statement. */
10640 : :
10641 : : tree
10642 : 55 : finish_oacc_host_data (tree clauses, tree block)
10643 : : {
10644 : 55 : tree stmt;
10645 : :
10646 : 55 : block = finish_omp_structured_block (block);
10647 : :
10648 : 55 : stmt = make_node (OACC_HOST_DATA);
10649 : 55 : TREE_TYPE (stmt) = void_type_node;
10650 : 55 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
10651 : 55 : OACC_HOST_DATA_BODY (stmt) = block;
10652 : :
10653 : 55 : return add_stmt (stmt);
10654 : : }
10655 : :
10656 : : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
10657 : : statement. */
10658 : :
10659 : : tree
10660 : 4653 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
10661 : : {
10662 : 4653 : body = finish_omp_structured_block (body);
10663 : :
10664 : 4653 : tree stmt = make_node (code);
10665 : 4653 : TREE_TYPE (stmt) = void_type_node;
10666 : 4653 : OMP_BODY (stmt) = body;
10667 : 4653 : OMP_CLAUSES (stmt) = clauses;
10668 : :
10669 : 4653 : return add_stmt (stmt);
10670 : : }
10671 : :
10672 : : /* Used to walk OpenMP target directive body. */
10673 : :
10674 : : struct omp_target_walk_data
10675 : : {
10676 : : /* Holds the 'this' expression found in current function. */
10677 : : tree current_object;
10678 : :
10679 : : /* True if the 'this' expression was accessed in the target body. */
10680 : : bool this_expr_accessed;
10681 : :
10682 : : /* For non-static functions, record which pointer-typed members were
10683 : : accessed, and the whole expression. */
10684 : : hash_map<tree, tree> ptr_members_accessed;
10685 : :
10686 : : /* Record which lambda objects were accessed in target body. */
10687 : : hash_set<tree> lambda_objects_accessed;
10688 : :
10689 : : /* For lambda functions, the __closure object expression of the current
10690 : : function, and the set of captured variables accessed in target body. */
10691 : : tree current_closure;
10692 : : hash_set<tree> closure_vars_accessed;
10693 : :
10694 : : /* Local variables declared inside a BIND_EXPR, used to filter out such
10695 : : variables when recording lambda_objects_accessed. */
10696 : : hash_set<tree> local_decls;
10697 : :
10698 : : omp_mapper_list<tree> *mappers;
10699 : : };
10700 : :
10701 : : /* Helper function of finish_omp_target_clauses, called via
10702 : : cp_walk_tree_without_duplicates. Traverse body of OpenMP target
10703 : : directive *TP, and fill out omp_target_walk_data passed in *PTR. */
10704 : :
10705 : : static tree
10706 : 225896 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
10707 : : {
10708 : 225896 : tree t = *tp;
10709 : 225896 : struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
10710 : 225896 : tree current_object = data->current_object;
10711 : 225896 : tree current_closure = data->current_closure;
10712 : 225896 : omp_mapper_list<tree> *mlist = data->mappers;
10713 : :
10714 : : /* References inside of these expression codes shouldn't incur any
10715 : : form of mapping, so return early. */
10716 : 225896 : if (TREE_CODE (t) == SIZEOF_EXPR
10717 : 225888 : || TREE_CODE (t) == ALIGNOF_EXPR)
10718 : : {
10719 : 8 : *walk_subtrees = 0;
10720 : 8 : return NULL_TREE;
10721 : : }
10722 : :
10723 : 225888 : if (TREE_CODE (t) == OMP_CLAUSE)
10724 : : return NULL_TREE;
10725 : :
10726 : 213295 : if (!processing_template_decl)
10727 : : {
10728 : 213295 : tree aggr_type = NULL_TREE;
10729 : :
10730 : 213295 : if (TREE_CODE (t) == COMPONENT_REF
10731 : 213295 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
10732 : 2231 : aggr_type = TREE_TYPE (TREE_OPERAND (t, 0));
10733 : 211064 : else if ((TREE_CODE (t) == VAR_DECL
10734 : : || TREE_CODE (t) == PARM_DECL
10735 : : || TREE_CODE (t) == RESULT_DECL)
10736 : 16810 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)))
10737 : 1249 : aggr_type = TREE_TYPE (t);
10738 : :
10739 : 3480 : if (aggr_type)
10740 : : {
10741 : 3480 : tree mapper_fn = cxx_omp_mapper_lookup (NULL_TREE, aggr_type);
10742 : 3480 : if (mapper_fn)
10743 : 167 : mlist->add_mapper (NULL_TREE, aggr_type, mapper_fn);
10744 : : }
10745 : : }
10746 : :
10747 : 213295 : if (current_object)
10748 : : {
10749 : 2472 : tree this_expr = TREE_OPERAND (current_object, 0);
10750 : :
10751 : 2472 : if (operand_equal_p (t, this_expr))
10752 : : {
10753 : 35 : data->this_expr_accessed = true;
10754 : 35 : *walk_subtrees = 0;
10755 : 35 : return NULL_TREE;
10756 : : }
10757 : :
10758 : 2437 : if (TREE_CODE (t) == COMPONENT_REF
10759 : 115 : && POINTER_TYPE_P (TREE_TYPE (t))
10760 : 36 : && operand_equal_p (TREE_OPERAND (t, 0), current_object)
10761 : 2471 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
10762 : : {
10763 : 34 : data->this_expr_accessed = true;
10764 : 34 : tree fld = TREE_OPERAND (t, 1);
10765 : 34 : if (data->ptr_members_accessed.get (fld) == NULL)
10766 : : {
10767 : 14 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
10768 : 4 : t = convert_from_reference (t);
10769 : 14 : data->ptr_members_accessed.put (fld, t);
10770 : : }
10771 : 34 : *walk_subtrees = 0;
10772 : 34 : return NULL_TREE;
10773 : : }
10774 : : }
10775 : :
10776 : : /* When the current_function_decl is a lambda function, the closure object
10777 : : argument's type seems to not yet have fields layed out, so a recording
10778 : : of DECL_VALUE_EXPRs during the target body walk seems the only way to
10779 : : find them. */
10780 : 213226 : if (current_closure
10781 : 300 : && (VAR_P (t)
10782 : : || TREE_CODE (t) == PARM_DECL
10783 : : || TREE_CODE (t) == RESULT_DECL)
10784 : 24 : && DECL_HAS_VALUE_EXPR_P (t)
10785 : 10 : && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
10786 : 213236 : && operand_equal_p (current_closure,
10787 : 10 : TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
10788 : : {
10789 : 9 : if (!data->closure_vars_accessed.contains (t))
10790 : 9 : data->closure_vars_accessed.add (t);
10791 : 9 : *walk_subtrees = 0;
10792 : 9 : return NULL_TREE;
10793 : : }
10794 : :
10795 : 213217 : if (TREE_CODE (t) == BIND_EXPR)
10796 : : {
10797 : 19730 : if (tree block = BIND_EXPR_BLOCK (t))
10798 : 22132 : for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
10799 : 2406 : if (!data->local_decls.contains (var))
10800 : 2406 : data->local_decls.add (var);
10801 : 19730 : return NULL_TREE;
10802 : : }
10803 : :
10804 : 198123 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
10805 : : {
10806 : 39 : tree lt = TREE_TYPE (t);
10807 : 39 : gcc_assert (CLASS_TYPE_P (lt));
10808 : :
10809 : 39 : if (!data->lambda_objects_accessed.contains (t)
10810 : : /* Do not prepare to create target maps for locally declared
10811 : : lambdas or anonymous ones. */
10812 : 39 : && !data->local_decls.contains (t)
10813 : 72 : && TREE_CODE (t) != TARGET_EXPR)
10814 : 13 : data->lambda_objects_accessed.add (t);
10815 : 39 : *walk_subtrees = 0;
10816 : 39 : return NULL_TREE;
10817 : : }
10818 : :
10819 : : return NULL_TREE;
10820 : : }
10821 : :
10822 : : /* Helper function for finish_omp_target, and also from tsubst_expr.
10823 : : Create additional clauses for mapping of non-static members, lambda objects,
10824 : : etc. */
10825 : :
10826 : : void
10827 : 6752 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
10828 : : {
10829 : 6752 : omp_target_walk_data data;
10830 : 6752 : data.this_expr_accessed = false;
10831 : 6752 : data.current_object = NULL_TREE;
10832 : :
10833 : 6752 : if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
10834 : 96 : if (tree ct = current_nonlambda_class_type ())
10835 : : {
10836 : 95 : tree object = maybe_dummy_object (ct, NULL);
10837 : 95 : object = maybe_resolve_dummy (object, true);
10838 : 95 : data.current_object = object;
10839 : : }
10840 : :
10841 : 6752 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
10842 : : {
10843 : 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
10844 : 8 : data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
10845 : : }
10846 : : else
10847 : 6744 : data.current_closure = NULL_TREE;
10848 : :
10849 : 6752 : auto_vec<tree, 16> new_clauses;
10850 : :
10851 : 6752 : if (!processing_template_decl)
10852 : : {
10853 : 6752 : hash_set<omp_name_type<tree> > seen_types;
10854 : 6752 : auto_vec<tree> mapper_fns;
10855 : 6752 : omp_mapper_list<tree> mlist (&seen_types, &mapper_fns);
10856 : 6752 : data.mappers = &mlist;
10857 : :
10858 : 6752 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
10859 : : &data);
10860 : :
10861 : 6752 : unsigned int i;
10862 : 6752 : tree mapper_fn;
10863 : 13590 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
10864 : 86 : c_omp_find_nested_mappers (&mlist, mapper_fn);
10865 : :
10866 : 6901 : FOR_EACH_VEC_ELT (mapper_fns, i, mapper_fn)
10867 : : {
10868 : 86 : tree mapper = cxx_omp_extract_mapper_directive (mapper_fn);
10869 : 86 : if (mapper == error_mark_node)
10870 : 0 : continue;
10871 : 86 : tree mapper_name = OMP_DECLARE_MAPPER_ID (mapper);
10872 : 86 : tree decl = OMP_DECLARE_MAPPER_DECL (mapper);
10873 : 86 : if (BASELINK_P (mapper_fn))
10874 : 0 : mapper_fn = BASELINK_FUNCTIONS (mapper_fn);
10875 : :
10876 : 86 : tree c = build_omp_clause (loc, OMP_CLAUSE__MAPPER_BINDING_);
10877 : 86 : OMP_CLAUSE__MAPPER_BINDING__ID (c) = mapper_name;
10878 : 86 : OMP_CLAUSE__MAPPER_BINDING__DECL (c) = decl;
10879 : 86 : OMP_CLAUSE__MAPPER_BINDING__MAPPER (c) = mapper_fn;
10880 : :
10881 : 86 : new_clauses.safe_push (c);
10882 : : }
10883 : 6752 : }
10884 : : else
10885 : : {
10886 : 0 : data.mappers = NULL;
10887 : 0 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r,
10888 : : &data);
10889 : : }
10890 : :
10891 : 6752 : tree omp_target_this_expr = NULL_TREE;
10892 : 6752 : tree *explicit_this_deref_map = NULL;
10893 : 6752 : if (data.this_expr_accessed)
10894 : : {
10895 : 31 : omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
10896 : :
10897 : : /* See if explicit user-specified map(this[:]) clause already exists.
10898 : : If not, we create an implicit map(tofrom:this[:1]) clause. */
10899 : 80 : for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
10900 : 50 : if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
10901 : 47 : && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
10902 : 40 : || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
10903 : 57 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
10904 : : omp_target_this_expr))
10905 : : {
10906 : : explicit_this_deref_map = cp;
10907 : : break;
10908 : : }
10909 : : }
10910 : :
10911 : 6752 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
10912 : 6752 : && (data.this_expr_accessed
10913 : 1 : || !data.closure_vars_accessed.is_empty ()))
10914 : : {
10915 : : /* For lambda functions, we need to first create a copy of the
10916 : : __closure object. */
10917 : 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
10918 : 8 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10919 : 8 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
10920 : 8 : OMP_CLAUSE_DECL (c)
10921 : 8 : = build_indirect_ref (loc, closure, RO_UNARY_STAR);
10922 : 8 : OMP_CLAUSE_SIZE (c)
10923 : 8 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
10924 : 8 : new_clauses.safe_push (c);
10925 : :
10926 : 8 : tree closure_obj = OMP_CLAUSE_DECL (c);
10927 : 8 : tree closure_type = TREE_TYPE (closure_obj);
10928 : :
10929 : 16 : gcc_assert (LAMBDA_TYPE_P (closure_type)
10930 : : && CLASS_TYPE_P (closure_type));
10931 : :
10932 : 8 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
10933 : 8 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
10934 : 8 : OMP_CLAUSE_DECL (c2) = closure;
10935 : 8 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
10936 : 8 : new_clauses.safe_push (c2);
10937 : : }
10938 : :
10939 : 6752 : if (data.this_expr_accessed)
10940 : : {
10941 : : /* If the this-expr was accessed, create a map(*this) clause. */
10942 : 31 : enum gomp_map_kind kind = GOMP_MAP_TOFROM;
10943 : 31 : if (explicit_this_deref_map)
10944 : : {
10945 : 1 : tree this_map = *explicit_this_deref_map;
10946 : 1 : tree nc = OMP_CLAUSE_CHAIN (this_map);
10947 : 2 : gcc_assert (nc != NULL_TREE
10948 : : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
10949 : : && (OMP_CLAUSE_MAP_KIND (nc)
10950 : : == GOMP_MAP_FIRSTPRIVATE_POINTER));
10951 : 1 : kind = OMP_CLAUSE_MAP_KIND (this_map);
10952 : : /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
10953 : : two-map sequence away from the chain. */
10954 : 1 : *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
10955 : : }
10956 : 31 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10957 : 31 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
10958 : 31 : OMP_CLAUSE_DECL (c)
10959 : 31 : = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
10960 : 31 : OMP_CLAUSE_SIZE (c)
10961 : 31 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
10962 : 31 : new_clauses.safe_push (c);
10963 : :
10964 : : /* If we're in a lambda function, the this-pointer will actually be
10965 : : '__closure->this', a mapped member of __closure, hence always_pointer.
10966 : : Otherwise it's a firstprivate pointer. */
10967 : 31 : enum gomp_map_kind ptr_kind
10968 : 31 : = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
10969 : 31 : ? GOMP_MAP_ALWAYS_POINTER
10970 : 24 : : GOMP_MAP_FIRSTPRIVATE_POINTER);
10971 : 31 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10972 : 31 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
10973 : 31 : OMP_CLAUSE_DECL (c) = omp_target_this_expr;
10974 : 31 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10975 : 31 : new_clauses.safe_push (c);
10976 : : }
10977 : :
10978 : 6752 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
10979 : : {
10980 : 8 : if (omp_target_this_expr)
10981 : : {
10982 : 7 : STRIP_NOPS (omp_target_this_expr);
10983 : 7 : gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
10984 : 7 : omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
10985 : : }
10986 : :
10987 : 17 : for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
10988 : 34 : i != data.closure_vars_accessed.end (); ++i)
10989 : : {
10990 : 9 : tree orig_decl = *i;
10991 : 9 : tree closure_expr = DECL_VALUE_EXPR (orig_decl);
10992 : :
10993 : 9 : if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
10994 : 9 : || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
10995 : : {
10996 : : /* this-pointer is processed above, outside this loop. */
10997 : 3 : if (omp_target_this_expr
10998 : 3 : && operand_equal_p (closure_expr, omp_target_this_expr))
10999 : 0 : continue;
11000 : :
11001 : 3 : bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
11002 : 3 : enum gomp_map_kind kind, ptr_kind, nc_kind;
11003 : 3 : tree size;
11004 : :
11005 : 3 : if (ptr_p)
11006 : : {
11007 : : /* For pointers, default mapped as zero-length array
11008 : : section. */
11009 : 2 : kind = GOMP_MAP_ALLOC;
11010 : 2 : nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
11011 : 2 : ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
11012 : 2 : size = size_zero_node;
11013 : : }
11014 : : else
11015 : : {
11016 : : /* For references, default mapped as appearing on map
11017 : : clause. */
11018 : 1 : kind = GOMP_MAP_TOFROM;
11019 : 1 : nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
11020 : 1 : ptr_kind = GOMP_MAP_ALWAYS_POINTER;
11021 : 1 : size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
11022 : : }
11023 : :
11024 : 6 : for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
11025 : 3 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
11026 : 1 : && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
11027 : 1 : || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
11028 : 3 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
11029 : : orig_decl))
11030 : : {
11031 : : /* If this was already specified by user as a map,
11032 : : save the user specified map kind, delete the
11033 : : "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
11034 : : and insert our own sequence:
11035 : : "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
11036 : : */
11037 : 0 : tree nc = OMP_CLAUSE_CHAIN (*p);
11038 : 0 : gcc_assert (nc != NULL_TREE
11039 : : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
11040 : : && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
11041 : : /* Update with user specified kind and size. */
11042 : 0 : kind = OMP_CLAUSE_MAP_KIND (*p);
11043 : 0 : size = OMP_CLAUSE_SIZE (*p);
11044 : 0 : *p = OMP_CLAUSE_CHAIN (nc);
11045 : 0 : break;
11046 : : }
11047 : :
11048 : 3 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11049 : 3 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
11050 : 3 : OMP_CLAUSE_DECL (c)
11051 : 3 : = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
11052 : 3 : OMP_CLAUSE_SIZE (c) = size;
11053 : 3 : if (ptr_p)
11054 : 2 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11055 : 3 : new_clauses.safe_push (c);
11056 : :
11057 : 3 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11058 : 3 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
11059 : 3 : OMP_CLAUSE_DECL (c) = closure_expr;
11060 : 3 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11061 : 3 : new_clauses.safe_push (c);
11062 : : }
11063 : : }
11064 : : }
11065 : :
11066 : 6752 : if (!data.ptr_members_accessed.is_empty ())
11067 : 14 : for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
11068 : 56 : i != data.ptr_members_accessed.end (); ++i)
11069 : : {
11070 : : /* For each referenced member that is of pointer or reference-to-pointer
11071 : : type, create the equivalent of map(alloc:this->ptr[:0]). */
11072 : 14 : tree field_decl = (*i).first;
11073 : 14 : tree ptr_member = (*i).second;
11074 : :
11075 : 26 : for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
11076 : : {
11077 : 16 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
11078 : 2 : continue;
11079 : : /* If map(this->ptr[:N]) already exists, avoid creating another
11080 : : such map. */
11081 : 14 : tree decl = OMP_CLAUSE_DECL (c);
11082 : 14 : if ((TREE_CODE (decl) == INDIRECT_REF
11083 : 10 : || TREE_CODE (decl) == MEM_REF)
11084 : 14 : && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
11085 : 4 : goto next_ptr_member;
11086 : : }
11087 : :
11088 : 10 : if (!cxx_mark_addressable (ptr_member))
11089 : 0 : gcc_unreachable ();
11090 : :
11091 : 10 : if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
11092 : : {
11093 : : /* For reference to pointers, we need to map the referenced
11094 : : pointer first for things to be correct. */
11095 : 4 : tree ptr_member_type = TREE_TYPE (ptr_member);
11096 : :
11097 : : /* Map pointer target as zero-length array section. */
11098 : 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11099 : 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11100 : 4 : OMP_CLAUSE_DECL (c)
11101 : 4 : = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
11102 : 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11103 : 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11104 : :
11105 : : /* Map pointer to zero-length array section. */
11106 : 4 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11107 : 4 : OMP_CLAUSE_SET_MAP_KIND
11108 : : (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
11109 : 4 : OMP_CLAUSE_DECL (c2) = ptr_member;
11110 : 4 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11111 : :
11112 : : /* Attach reference-to-pointer field to pointer. */
11113 : 4 : tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11114 : 4 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
11115 : 4 : OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
11116 : 4 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
11117 : :
11118 : 4 : new_clauses.safe_push (c);
11119 : 4 : new_clauses.safe_push (c2);
11120 : 4 : new_clauses.safe_push (c3);
11121 : : }
11122 : 6 : else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
11123 : : {
11124 : : /* Map pointer target as zero-length array section. */
11125 : 6 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11126 : 6 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11127 : 6 : OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
11128 : : RO_UNARY_STAR);
11129 : 6 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11130 : 6 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11131 : :
11132 : : /* Attach zero-length array section to pointer. */
11133 : 6 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
11134 : 6 : OMP_CLAUSE_SET_MAP_KIND
11135 : : (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11136 : 6 : OMP_CLAUSE_DECL (c2) = ptr_member;
11137 : 6 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
11138 : :
11139 : 6 : new_clauses.safe_push (c);
11140 : 6 : new_clauses.safe_push (c2);
11141 : : }
11142 : : else
11143 : 0 : gcc_unreachable ();
11144 : :
11145 : 14 : next_ptr_member:
11146 : 14 : ;
11147 : : }
11148 : :
11149 : 6765 : for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
11150 : 6778 : i != data.lambda_objects_accessed.end (); ++i)
11151 : : {
11152 : 13 : tree lobj = *i;
11153 : 13 : if (TREE_CODE (lobj) == TARGET_EXPR)
11154 : 0 : lobj = TARGET_EXPR_SLOT (lobj);
11155 : :
11156 : 13 : tree lt = TREE_TYPE (lobj);
11157 : 26 : gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
11158 : :
11159 : 13 : tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
11160 : 13 : OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
11161 : 13 : OMP_CLAUSE_DECL (lc) = lobj;
11162 : 13 : OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
11163 : 13 : new_clauses.safe_push (lc);
11164 : :
11165 : 180 : for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
11166 : : {
11167 : 167 : if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
11168 : : {
11169 : 4 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11170 : : lobj, fld, NULL_TREE);
11171 : 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11172 : 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
11173 : 4 : OMP_CLAUSE_DECL (c)
11174 : 4 : = build_indirect_ref (loc, exp, RO_UNARY_STAR);
11175 : 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11176 : 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
11177 : 4 : new_clauses.safe_push (c);
11178 : :
11179 : 4 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11180 : 4 : OMP_CLAUSE_SET_MAP_KIND
11181 : : (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
11182 : 4 : OMP_CLAUSE_DECL (c) = exp;
11183 : 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11184 : 4 : new_clauses.safe_push (c);
11185 : : }
11186 : 163 : else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
11187 : : {
11188 : 0 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
11189 : : lobj, fld, NULL_TREE);
11190 : 0 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11191 : 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
11192 : 0 : OMP_CLAUSE_DECL (c)
11193 : 0 : = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
11194 : 0 : OMP_CLAUSE_SIZE (c)
11195 : 0 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
11196 : 0 : new_clauses.safe_push (c);
11197 : :
11198 : 0 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
11199 : 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
11200 : 0 : OMP_CLAUSE_DECL (c) = exp;
11201 : 0 : OMP_CLAUSE_SIZE (c) = size_zero_node;
11202 : 0 : new_clauses.safe_push (c);
11203 : : }
11204 : : }
11205 : : }
11206 : :
11207 : 6752 : tree c = *clauses_ptr;
11208 : 13719 : for (int i = new_clauses.length () - 1; i >= 0; i--)
11209 : : {
11210 : 215 : OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
11211 : 215 : c = new_clauses[i];
11212 : : }
11213 : 6752 : *clauses_ptr = c;
11214 : 6752 : }
11215 : :
11216 : : /* Called from cp_parser_omp_target. Create additional implicit clauses for
11217 : : OpenMP target directives, and do sanity checks. */
11218 : :
11219 : : tree
11220 : 6743 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
11221 : : {
11222 : 6743 : if (!processing_template_decl)
11223 : 5945 : finish_omp_target_clauses (loc, body, &clauses);
11224 : :
11225 : 6743 : tree stmt = make_node (OMP_TARGET);
11226 : 6743 : TREE_TYPE (stmt) = void_type_node;
11227 : 6743 : OMP_TARGET_CLAUSES (stmt) = clauses;
11228 : 6743 : OMP_TARGET_BODY (stmt) = body;
11229 : 6743 : OMP_TARGET_COMBINED (stmt) = combined_p;
11230 : 6743 : SET_EXPR_LOCATION (stmt, loc);
11231 : :
11232 : 6743 : tree c = clauses;
11233 : 16098 : while (c)
11234 : : {
11235 : 9355 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
11236 : 5460 : switch (OMP_CLAUSE_MAP_KIND (c))
11237 : : {
11238 : : case GOMP_MAP_TO:
11239 : : case GOMP_MAP_ALWAYS_TO:
11240 : : case GOMP_MAP_PRESENT_TO:
11241 : : case GOMP_MAP_ALWAYS_PRESENT_TO:
11242 : : case GOMP_MAP_FROM:
11243 : : case GOMP_MAP_ALWAYS_FROM:
11244 : : case GOMP_MAP_PRESENT_FROM:
11245 : : case GOMP_MAP_ALWAYS_PRESENT_FROM:
11246 : : case GOMP_MAP_TOFROM:
11247 : : case GOMP_MAP_ALWAYS_TOFROM:
11248 : : case GOMP_MAP_PRESENT_TOFROM:
11249 : : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
11250 : : case GOMP_MAP_ALLOC:
11251 : : case GOMP_MAP_PRESENT_ALLOC:
11252 : : case GOMP_MAP_FIRSTPRIVATE_POINTER:
11253 : : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
11254 : : case GOMP_MAP_ALWAYS_POINTER:
11255 : : case GOMP_MAP_ATTACH_DETACH:
11256 : : case GOMP_MAP_ATTACH:
11257 : : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
11258 : : case GOMP_MAP_POINTER:
11259 : : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
11260 : : break;
11261 : 3 : default:
11262 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
11263 : : "%<#pragma omp target%> with map-type other "
11264 : : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
11265 : : "on %<map%> clause");
11266 : 3 : break;
11267 : : }
11268 : 9355 : c = OMP_CLAUSE_CHAIN (c);
11269 : : }
11270 : 6743 : return add_stmt (stmt);
11271 : : }
11272 : :
11273 : : tree
11274 : 9299 : finish_omp_parallel (tree clauses, tree body)
11275 : : {
11276 : 9299 : tree stmt;
11277 : :
11278 : 9299 : body = finish_omp_structured_block (body);
11279 : :
11280 : 9299 : stmt = make_node (OMP_PARALLEL);
11281 : 9299 : TREE_TYPE (stmt) = void_type_node;
11282 : 9299 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
11283 : 9299 : OMP_PARALLEL_BODY (stmt) = body;
11284 : :
11285 : 9299 : return add_stmt (stmt);
11286 : : }
11287 : :
11288 : : tree
11289 : 2160 : begin_omp_task (void)
11290 : : {
11291 : 2160 : keep_next_level (true);
11292 : 2160 : return begin_omp_structured_block ();
11293 : : }
11294 : :
11295 : : tree
11296 : 2160 : finish_omp_task (tree clauses, tree body)
11297 : : {
11298 : 2160 : tree stmt;
11299 : :
11300 : 2160 : body = finish_omp_structured_block (body);
11301 : :
11302 : 2160 : stmt = make_node (OMP_TASK);
11303 : 2160 : TREE_TYPE (stmt) = void_type_node;
11304 : 2160 : OMP_TASK_CLAUSES (stmt) = clauses;
11305 : 2160 : OMP_TASK_BODY (stmt) = body;
11306 : :
11307 : 2160 : return add_stmt (stmt);
11308 : : }
11309 : :
11310 : : /* Helper function for finish_omp_for. Convert Ith random access iterator
11311 : : into integral iterator. Return FALSE if successful. */
11312 : :
11313 : : static bool
11314 : 813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
11315 : : tree declv, tree orig_declv, tree initv,
11316 : : tree condv, tree incrv, tree *body,
11317 : : tree *pre_body, tree &clauses,
11318 : : int collapse, int ordered)
11319 : : {
11320 : 813 : tree diff, iter_init, iter_incr = NULL, last;
11321 : 813 : tree incr_var = NULL, orig_pre_body, orig_body, c;
11322 : 813 : tree decl = TREE_VEC_ELT (declv, i);
11323 : 813 : tree init = TREE_VEC_ELT (initv, i);
11324 : 813 : tree cond = TREE_VEC_ELT (condv, i);
11325 : 813 : tree incr = TREE_VEC_ELT (incrv, i);
11326 : 813 : tree iter = decl;
11327 : 813 : location_t elocus = locus;
11328 : :
11329 : 813 : if (init && EXPR_HAS_LOCATION (init))
11330 : 12 : elocus = EXPR_LOCATION (init);
11331 : :
11332 : 813 : switch (TREE_CODE (cond))
11333 : : {
11334 : 810 : case GT_EXPR:
11335 : 810 : case GE_EXPR:
11336 : 810 : case LT_EXPR:
11337 : 810 : case LE_EXPR:
11338 : 810 : case NE_EXPR:
11339 : 810 : if (TREE_OPERAND (cond, 1) == iter)
11340 : 42 : cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
11341 : 42 : TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
11342 : 810 : if (TREE_OPERAND (cond, 0) != iter)
11343 : 0 : cond = error_mark_node;
11344 : : else
11345 : : {
11346 : 810 : tree tem = build_x_binary_op (EXPR_LOCATION (cond),
11347 : 810 : TREE_CODE (cond),
11348 : : iter, ERROR_MARK,
11349 : 810 : TREE_OPERAND (cond, 1), ERROR_MARK,
11350 : : NULL_TREE, NULL, tf_warning_or_error);
11351 : 810 : if (error_operand_p (tem))
11352 : : return true;
11353 : : }
11354 : : break;
11355 : 3 : default:
11356 : 3 : cond = error_mark_node;
11357 : 3 : break;
11358 : : }
11359 : 810 : if (cond == error_mark_node)
11360 : : {
11361 : 3 : error_at (elocus, "invalid controlling predicate");
11362 : 3 : return true;
11363 : : }
11364 : 807 : diff = build_x_binary_op (elocus, MINUS_EXPR,
11365 : 807 : TREE_OPERAND (cond, 1), ERROR_MARK,
11366 : : iter, ERROR_MARK,
11367 : : NULL_TREE, NULL, tf_warning_or_error);
11368 : 807 : diff = cp_fully_fold (diff);
11369 : 807 : if (error_operand_p (diff))
11370 : : return true;
11371 : 807 : if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
11372 : : {
11373 : 0 : error_at (elocus, "difference between %qE and %qD does not have integer type",
11374 : 0 : TREE_OPERAND (cond, 1), iter);
11375 : 0 : return true;
11376 : : }
11377 : 807 : if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
11378 : 807 : TREE_VEC_ELT (declv, i), NULL_TREE,
11379 : : cond, cp_walk_subtrees))
11380 : : return true;
11381 : :
11382 : 762 : switch (TREE_CODE (incr))
11383 : : {
11384 : 370 : case PREINCREMENT_EXPR:
11385 : 370 : case PREDECREMENT_EXPR:
11386 : 370 : case POSTINCREMENT_EXPR:
11387 : 370 : case POSTDECREMENT_EXPR:
11388 : 370 : if (TREE_OPERAND (incr, 0) != iter)
11389 : : {
11390 : 0 : incr = error_mark_node;
11391 : 0 : break;
11392 : : }
11393 : 370 : iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
11394 : 370 : TREE_CODE (incr), iter,
11395 : : NULL_TREE, tf_warning_or_error);
11396 : 370 : if (error_operand_p (iter_incr))
11397 : : return true;
11398 : 370 : else if (TREE_CODE (incr) == PREINCREMENT_EXPR
11399 : 219 : || TREE_CODE (incr) == POSTINCREMENT_EXPR)
11400 : 299 : incr = integer_one_node;
11401 : : else
11402 : 71 : incr = integer_minus_one_node;
11403 : : break;
11404 : 392 : case MODIFY_EXPR:
11405 : 392 : if (TREE_OPERAND (incr, 0) != iter)
11406 : 0 : incr = error_mark_node;
11407 : 392 : else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
11408 : 392 : || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
11409 : : {
11410 : 392 : tree rhs = TREE_OPERAND (incr, 1);
11411 : 392 : if (TREE_OPERAND (rhs, 0) == iter)
11412 : : {
11413 : 299 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
11414 : : != INTEGER_TYPE)
11415 : 0 : incr = error_mark_node;
11416 : : else
11417 : : {
11418 : 299 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11419 : 299 : iter, TREE_CODE (rhs),
11420 : 299 : TREE_OPERAND (rhs, 1),
11421 : : NULL_TREE,
11422 : : tf_warning_or_error);
11423 : 299 : if (error_operand_p (iter_incr))
11424 : : return true;
11425 : 299 : incr = TREE_OPERAND (rhs, 1);
11426 : 299 : incr = cp_convert (TREE_TYPE (diff), incr,
11427 : : tf_warning_or_error);
11428 : 299 : if (TREE_CODE (rhs) == MINUS_EXPR)
11429 : : {
11430 : 16 : incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
11431 : 16 : incr = fold_simple (incr);
11432 : : }
11433 : 299 : if (TREE_CODE (incr) != INTEGER_CST
11434 : 299 : && (TREE_CODE (incr) != NOP_EXPR
11435 : 66 : || (TREE_CODE (TREE_OPERAND (incr, 0))
11436 : : != INTEGER_CST)))
11437 : : iter_incr = NULL;
11438 : : }
11439 : : }
11440 : 93 : else if (TREE_OPERAND (rhs, 1) == iter)
11441 : : {
11442 : 93 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
11443 : 93 : || TREE_CODE (rhs) != PLUS_EXPR)
11444 : 0 : incr = error_mark_node;
11445 : : else
11446 : : {
11447 : 93 : iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
11448 : : PLUS_EXPR,
11449 : 93 : TREE_OPERAND (rhs, 0),
11450 : : ERROR_MARK, iter,
11451 : : ERROR_MARK, NULL_TREE, NULL,
11452 : : tf_warning_or_error);
11453 : 93 : if (error_operand_p (iter_incr))
11454 : : return true;
11455 : 93 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11456 : : iter, NOP_EXPR,
11457 : : iter_incr, NULL_TREE,
11458 : : tf_warning_or_error);
11459 : 93 : if (error_operand_p (iter_incr))
11460 : : return true;
11461 : 93 : incr = TREE_OPERAND (rhs, 0);
11462 : 93 : iter_incr = NULL;
11463 : : }
11464 : : }
11465 : : else
11466 : 0 : incr = error_mark_node;
11467 : : }
11468 : : else
11469 : 0 : incr = error_mark_node;
11470 : : break;
11471 : 0 : default:
11472 : 0 : incr = error_mark_node;
11473 : 0 : break;
11474 : : }
11475 : :
11476 : 762 : if (incr == error_mark_node)
11477 : : {
11478 : 0 : error_at (elocus, "invalid increment expression");
11479 : 0 : return true;
11480 : : }
11481 : :
11482 : 762 : incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
11483 : 762 : incr = cp_fully_fold (incr);
11484 : 762 : tree loop_iv_seen = NULL_TREE;
11485 : 1735 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11486 : 1093 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
11487 : 1093 : && OMP_CLAUSE_DECL (c) == iter)
11488 : : {
11489 : 120 : if (code == OMP_TASKLOOP || code == OMP_LOOP)
11490 : : {
11491 : 60 : loop_iv_seen = c;
11492 : 60 : OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
11493 : : }
11494 : : break;
11495 : : }
11496 : 973 : else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
11497 : 113 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
11498 : 1007 : && OMP_CLAUSE_DECL (c) == iter)
11499 : : {
11500 : 30 : loop_iv_seen = c;
11501 : 30 : if (code == OMP_TASKLOOP)
11502 : 25 : OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
11503 : : }
11504 : :
11505 : 762 : decl = create_temporary_var (TREE_TYPE (diff));
11506 : 762 : pushdecl (decl);
11507 : 762 : add_decl_expr (decl);
11508 : 762 : last = create_temporary_var (TREE_TYPE (diff));
11509 : 762 : pushdecl (last);
11510 : 762 : add_decl_expr (last);
11511 : 762 : if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
11512 : 10 : && (!ordered || (i < collapse && collapse > 1)))
11513 : : {
11514 : 10 : incr_var = create_temporary_var (TREE_TYPE (diff));
11515 : 10 : pushdecl (incr_var);
11516 : 10 : add_decl_expr (incr_var);
11517 : : }
11518 : 762 : gcc_assert (stmts_are_full_exprs_p ());
11519 : 762 : tree diffvar = NULL_TREE;
11520 : 762 : if (code == OMP_TASKLOOP)
11521 : : {
11522 : 101 : if (!loop_iv_seen)
11523 : : {
11524 : 38 : tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11525 : 38 : OMP_CLAUSE_DECL (ivc) = iter;
11526 : 38 : cxx_omp_finish_clause (ivc, NULL, false);
11527 : 38 : OMP_CLAUSE_CHAIN (ivc) = clauses;
11528 : 38 : clauses = ivc;
11529 : : }
11530 : 101 : tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11531 : 101 : OMP_CLAUSE_DECL (lvc) = last;
11532 : 101 : OMP_CLAUSE_CHAIN (lvc) = clauses;
11533 : 101 : clauses = lvc;
11534 : 101 : diffvar = create_temporary_var (TREE_TYPE (diff));
11535 : 101 : pushdecl (diffvar);
11536 : 101 : add_decl_expr (diffvar);
11537 : : }
11538 : 661 : else if (code == OMP_LOOP)
11539 : : {
11540 : 43 : if (!loop_iv_seen)
11541 : : {
11542 : : /* While iterators on the loop construct are predetermined
11543 : : lastprivate, if the decl is not declared inside of the
11544 : : loop, OMP_CLAUSE_LASTPRIVATE should have been added
11545 : : already. */
11546 : 16 : loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11547 : 16 : OMP_CLAUSE_DECL (loop_iv_seen) = iter;
11548 : 16 : OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
11549 : 16 : clauses = loop_iv_seen;
11550 : : }
11551 : 27 : else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
11552 : : {
11553 : 5 : OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
11554 : 5 : OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
11555 : 5 : OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
11556 : : }
11557 : 43 : if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
11558 : 21 : cxx_omp_finish_clause (loop_iv_seen, NULL, false);
11559 : : }
11560 : :
11561 : 762 : orig_pre_body = *pre_body;
11562 : 762 : *pre_body = push_stmt_list ();
11563 : 762 : if (orig_pre_body)
11564 : 610 : add_stmt (orig_pre_body);
11565 : 762 : if (init != NULL)
11566 : 61 : finish_expr_stmt (build_x_modify_expr (elocus,
11567 : : iter, NOP_EXPR, init,
11568 : : NULL_TREE, tf_warning_or_error));
11569 : 762 : init = build_int_cst (TREE_TYPE (diff), 0);
11570 : 762 : if (c && iter_incr == NULL
11571 : 28 : && (!ordered || (i < collapse && collapse > 1)))
11572 : : {
11573 : 28 : if (incr_var)
11574 : : {
11575 : 10 : finish_expr_stmt (build_x_modify_expr (elocus,
11576 : : incr_var, NOP_EXPR,
11577 : : incr, NULL_TREE,
11578 : : tf_warning_or_error));
11579 : 10 : incr = incr_var;
11580 : : }
11581 : 28 : iter_incr = build_x_modify_expr (elocus,
11582 : : iter, PLUS_EXPR, incr,
11583 : : NULL_TREE, tf_warning_or_error);
11584 : : }
11585 : 762 : if (c && ordered && i < collapse && collapse > 1)
11586 : 762 : iter_incr = incr;
11587 : 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11588 : : last, NOP_EXPR, init,
11589 : : NULL_TREE, tf_warning_or_error));
11590 : 762 : if (diffvar)
11591 : : {
11592 : 101 : finish_expr_stmt (build_x_modify_expr (elocus,
11593 : : diffvar, NOP_EXPR,
11594 : : diff, NULL_TREE, tf_warning_or_error));
11595 : 101 : diff = diffvar;
11596 : : }
11597 : 762 : *pre_body = pop_stmt_list (*pre_body);
11598 : :
11599 : 1524 : cond = cp_build_binary_op (elocus,
11600 : 762 : TREE_CODE (cond), decl, diff,
11601 : : tf_warning_or_error);
11602 : 762 : incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
11603 : : elocus, incr, NULL_TREE);
11604 : :
11605 : 762 : orig_body = *body;
11606 : 762 : *body = push_stmt_list ();
11607 : 762 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
11608 : 762 : iter_init = build_x_modify_expr (elocus,
11609 : : iter, PLUS_EXPR, iter_init,
11610 : : NULL_TREE, tf_warning_or_error);
11611 : 762 : if (iter_init != error_mark_node)
11612 : 759 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11613 : 762 : finish_expr_stmt (iter_init);
11614 : 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11615 : : last, NOP_EXPR, decl,
11616 : : NULL_TREE, tf_warning_or_error));
11617 : 762 : add_stmt (orig_body);
11618 : 762 : *body = pop_stmt_list (*body);
11619 : :
11620 : 762 : if (c)
11621 : : {
11622 : 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
11623 : 120 : if (!ordered)
11624 : 114 : finish_expr_stmt (iter_incr);
11625 : : else
11626 : : {
11627 : 6 : iter_init = decl;
11628 : 6 : if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
11629 : 2 : iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
11630 : : iter_init, iter_incr);
11631 : 6 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
11632 : 6 : iter_init = build_x_modify_expr (elocus,
11633 : : iter, PLUS_EXPR, iter_init,
11634 : : NULL_TREE, tf_warning_or_error);
11635 : 6 : if (iter_init != error_mark_node)
11636 : 6 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11637 : 6 : finish_expr_stmt (iter_init);
11638 : : }
11639 : 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c)
11640 : 240 : = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
11641 : : }
11642 : :
11643 : 762 : if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
11644 : : {
11645 : 116 : tree t = TREE_VEC_ELT (orig_declv, i);
11646 : 116 : gcc_assert (TREE_PURPOSE (t) == NULL_TREE
11647 : : && TREE_VALUE (t) == NULL_TREE
11648 : : && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
11649 : 116 : TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
11650 : 116 : TREE_VALUE (t) = last;
11651 : : }
11652 : : else
11653 : 646 : TREE_VEC_ELT (orig_declv, i)
11654 : 1292 : = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
11655 : 762 : TREE_VEC_ELT (declv, i) = decl;
11656 : 762 : TREE_VEC_ELT (initv, i) = init;
11657 : 762 : TREE_VEC_ELT (condv, i) = cond;
11658 : 762 : TREE_VEC_ELT (incrv, i) = incr;
11659 : :
11660 : 762 : return false;
11661 : : }
11662 : :
11663 : : /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
11664 : : are directly for their associated operands in the statement. DECL
11665 : : and INIT are a combo; if DECL is NULL then INIT ought to be a
11666 : : MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
11667 : : optional statements that need to go before the loop into its
11668 : : sk_omp scope. */
11669 : :
11670 : : tree
11671 : 21120 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
11672 : : tree orig_declv, tree initv, tree condv, tree incrv,
11673 : : tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
11674 : : {
11675 : 21120 : tree omp_for = NULL, orig_incr = NULL;
11676 : 21120 : tree decl = NULL, init, cond, incr;
11677 : 21120 : location_t elocus;
11678 : 21120 : int i;
11679 : 21120 : int collapse = 1;
11680 : 21120 : int ordered = 0;
11681 : 21120 : auto_vec<location_t> init_locv;
11682 : :
11683 : 21120 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
11684 : 21120 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
11685 : 21120 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
11686 : 21120 : if (TREE_VEC_LENGTH (declv) > 1)
11687 : : {
11688 : 4048 : if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
11689 : 83 : collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
11690 : : else
11691 : : {
11692 : 3965 : if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
11693 : 3495 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
11694 : 470 : else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
11695 : 394 : collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
11696 : 3965 : if (collapse != TREE_VEC_LENGTH (declv))
11697 : 100 : ordered = TREE_VEC_LENGTH (declv);
11698 : : }
11699 : : }
11700 : 48579 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
11701 : : {
11702 : 27495 : decl = TREE_VEC_ELT (declv, i);
11703 : 27495 : init = TREE_VEC_ELT (initv, i);
11704 : 27495 : cond = TREE_VEC_ELT (condv, i);
11705 : 27495 : incr = TREE_VEC_ELT (incrv, i);
11706 : 27495 : elocus = locus;
11707 : :
11708 : 27495 : if (decl == global_namespace)
11709 : : {
11710 : 1101 : gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
11711 : 1101 : TREE_VEC_ELT (declv, i) = NULL_TREE;
11712 : 1101 : init_locv.safe_push (UNKNOWN_LOCATION);
11713 : 1101 : continue;
11714 : : }
11715 : : /* We are going to throw out the init's original MODIFY_EXPR or
11716 : : MODOP_EXPR below. Save its location so we can use it when
11717 : : reconstructing the expression farther down. Alternatively, if the
11718 : : initializer is a binding of the iteration variable, save
11719 : : that location. Any of these locations in the initialization clause
11720 : : for the current nested loop are better than using the argument locus,
11721 : : that points to the "for" of the outermost loop in the nest. */
11722 : 26394 : if (init && EXPR_HAS_LOCATION (init))
11723 : 17872 : elocus = EXPR_LOCATION (init);
11724 : 8522 : else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
11725 : : /* This can happen for class iterators. */
11726 : 0 : elocus = EXPR_LOCATION (decl);
11727 : 8522 : else if (decl && DECL_P (decl))
11728 : : {
11729 : 8495 : if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
11730 : 8495 : elocus = DECL_SOURCE_LOCATION (decl);
11731 : 0 : else if (DECL_INITIAL (decl)
11732 : 0 : && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
11733 : 0 : elocus = EXPR_LOCATION (DECL_INITIAL (decl));
11734 : : }
11735 : 26394 : init_locv.safe_push (elocus);
11736 : :
11737 : 26394 : if (decl == NULL)
11738 : : {
11739 : 16561 : if (init != NULL)
11740 : 16558 : switch (TREE_CODE (init))
11741 : : {
11742 : 16173 : case MODIFY_EXPR:
11743 : 16173 : decl = TREE_OPERAND (init, 0);
11744 : 16173 : init = TREE_OPERAND (init, 1);
11745 : 16173 : break;
11746 : 367 : case MODOP_EXPR:
11747 : 367 : if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
11748 : : {
11749 : 367 : decl = TREE_OPERAND (init, 0);
11750 : 367 : init = TREE_OPERAND (init, 2);
11751 : : }
11752 : : break;
11753 : : default:
11754 : : break;
11755 : : }
11756 : :
11757 : 16561 : if (decl == NULL)
11758 : : {
11759 : 21 : error_at (locus,
11760 : : "expected iteration declaration or initialization");
11761 : 21 : return NULL;
11762 : : }
11763 : : }
11764 : :
11765 : 26373 : if (cond == global_namespace)
11766 : 170 : continue;
11767 : :
11768 : 26203 : if (cond == NULL)
11769 : : {
11770 : 9 : error_at (elocus, "missing controlling predicate");
11771 : 9 : return NULL;
11772 : : }
11773 : :
11774 : 26194 : if (incr == NULL)
11775 : : {
11776 : 6 : error_at (elocus, "missing increment expression");
11777 : 6 : return NULL;
11778 : : }
11779 : :
11780 : 26188 : TREE_VEC_ELT (declv, i) = decl;
11781 : 26188 : TREE_VEC_ELT (initv, i) = init;
11782 : : }
11783 : :
11784 : 21084 : if (orig_inits)
11785 : : {
11786 : : bool fail = false;
11787 : : tree orig_init;
11788 : 21209 : FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
11789 : 1181 : if (orig_init
11790 : 3396 : && !c_omp_check_loop_iv_exprs (locus, code,
11791 : : orig_declv ? orig_declv : declv, i,
11792 : 1164 : TREE_VEC_ELT (declv, i), orig_init,
11793 : : NULL_TREE, cp_walk_subtrees))
11794 : : fail = true;
11795 : 20028 : if (fail)
11796 : 887 : return NULL;
11797 : : }
11798 : :
11799 : 21027 : if (dependent_omp_for_p (declv, initv, condv, incrv, body))
11800 : : {
11801 : 453 : tree stmt;
11802 : :
11803 : 453 : stmt = make_node (code);
11804 : :
11805 : 1499 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
11806 : : {
11807 : 593 : if (TREE_VEC_ELT (declv, i) == NULL_TREE)
11808 : 9 : continue;
11809 : : /* This is really just a place-holder. We'll be decomposing this
11810 : : again and going through the cp_build_modify_expr path below when
11811 : : we instantiate the thing. */
11812 : 584 : TREE_VEC_ELT (initv, i)
11813 : 1168 : = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
11814 : 584 : TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
11815 : : }
11816 : :
11817 : 453 : TREE_TYPE (stmt) = void_type_node;
11818 : 453 : OMP_FOR_INIT (stmt) = initv;
11819 : 453 : OMP_FOR_COND (stmt) = condv;
11820 : 453 : OMP_FOR_INCR (stmt) = incrv;
11821 : 453 : OMP_FOR_BODY (stmt) = body;
11822 : 453 : OMP_FOR_PRE_BODY (stmt) = pre_body;
11823 : 453 : OMP_FOR_CLAUSES (stmt) = clauses;
11824 : :
11825 : 453 : SET_EXPR_LOCATION (stmt, locus);
11826 : 453 : return add_stmt (stmt);
11827 : : }
11828 : :
11829 : 20574 : if (!orig_declv)
11830 : 19790 : orig_declv = copy_node (declv);
11831 : :
11832 : 20574 : if (processing_template_decl)
11833 : 609 : orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
11834 : :
11835 : 48008 : for (i = 0; i < TREE_VEC_LENGTH (declv); )
11836 : : {
11837 : 27526 : decl = TREE_VEC_ELT (declv, i);
11838 : 27526 : init = TREE_VEC_ELT (initv, i);
11839 : 27526 : cond = TREE_VEC_ELT (condv, i);
11840 : 27526 : incr = TREE_VEC_ELT (incrv, i);
11841 : 27526 : if (orig_incr)
11842 : 838 : TREE_VEC_ELT (orig_incr, i) = incr;
11843 : 27526 : elocus = init_locv[i];
11844 : :
11845 : 27526 : if (decl == NULL_TREE)
11846 : : {
11847 : 1092 : i++;
11848 : 1092 : continue;
11849 : : }
11850 : :
11851 : 26434 : if (!DECL_P (decl))
11852 : : {
11853 : 6 : error_at (elocus, "expected iteration declaration or initialization");
11854 : 6 : return NULL;
11855 : : }
11856 : :
11857 : 26428 : if (incr && TREE_CODE (incr) == MODOP_EXPR)
11858 : : {
11859 : 1 : if (orig_incr)
11860 : 1 : TREE_VEC_ELT (orig_incr, i) = incr;
11861 : 1 : incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
11862 : 1 : TREE_CODE (TREE_OPERAND (incr, 1)),
11863 : 1 : TREE_OPERAND (incr, 2),
11864 : : tf_warning_or_error);
11865 : : }
11866 : :
11867 : 26428 : if (CLASS_TYPE_P (TREE_TYPE (decl)))
11868 : : {
11869 : 825 : if (code == OMP_SIMD)
11870 : : {
11871 : 12 : error_at (elocus, "%<#pragma omp simd%> used with class "
11872 : : "iteration variable %qE", decl);
11873 : 12 : return NULL;
11874 : : }
11875 : 813 : if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
11876 : : initv, condv, incrv, &body,
11877 : : &pre_body, clauses,
11878 : : collapse, ordered))
11879 : : return NULL;
11880 : 762 : continue;
11881 : : }
11882 : :
11883 : 51206 : if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
11884 : 27186 : && !TYPE_PTR_P (TREE_TYPE (decl)))
11885 : : {
11886 : 14 : error_at (elocus, "invalid type for iteration variable %qE", decl);
11887 : 14 : return NULL;
11888 : : }
11889 : :
11890 : 25589 : if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
11891 : 24834 : init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
11892 : : tf_warning_or_error);
11893 : : else
11894 : 755 : init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
11895 : 25589 : if (decl == error_mark_node || init == error_mark_node)
11896 : : return NULL;
11897 : :
11898 : 25580 : TREE_VEC_ELT (declv, i) = decl;
11899 : 25580 : TREE_VEC_ELT (initv, i) = init;
11900 : 25580 : TREE_VEC_ELT (condv, i) = cond;
11901 : 25580 : TREE_VEC_ELT (incrv, i) = incr;
11902 : 25580 : i++;
11903 : : }
11904 : :
11905 : 20482 : if (pre_body && IS_EMPTY_STMT (pre_body))
11906 : 0 : pre_body = NULL;
11907 : :
11908 : 40964 : omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
11909 : : incrv, body, pre_body,
11910 : 20482 : !processing_template_decl);
11911 : :
11912 : : /* Check for iterators appearing in lb, b or incr expressions. */
11913 : 20482 : if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
11914 : : omp_for = NULL_TREE;
11915 : :
11916 : 19996 : if (omp_for == NULL)
11917 : 702 : return NULL;
11918 : :
11919 : 19780 : add_stmt (omp_for);
11920 : :
11921 : 45426 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
11922 : : {
11923 : 25646 : init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
11924 : 25646 : if (init == NULL_TREE)
11925 : 1032 : continue;
11926 : 24614 : decl = TREE_OPERAND (init, 0);
11927 : 24614 : cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
11928 : 24614 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
11929 : :
11930 : 24614 : if (!processing_template_decl)
11931 : : {
11932 : 24099 : if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
11933 : : {
11934 : 106 : tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
11935 : 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
11936 : 106 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11937 : 106 : t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
11938 : 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
11939 : 212 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11940 : : }
11941 : : else
11942 : : {
11943 : 23993 : tree t = TREE_OPERAND (init, 1);
11944 : 23993 : TREE_OPERAND (init, 1)
11945 : 47986 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11946 : : }
11947 : 24099 : if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
11948 : : {
11949 : 121 : tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
11950 : 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
11951 : 121 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11952 : 121 : t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
11953 : 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
11954 : 242 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11955 : : }
11956 : : else
11957 : : {
11958 : 23978 : tree t = TREE_OPERAND (cond, 1);
11959 : 23978 : TREE_OPERAND (cond, 1)
11960 : 47956 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11961 : : }
11962 : : }
11963 : :
11964 : 24614 : if (TREE_CODE (incr) != MODIFY_EXPR)
11965 : 18415 : continue;
11966 : :
11967 : 6199 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
11968 : 70 : && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
11969 : 6269 : && !processing_template_decl)
11970 : : {
11971 : 64 : tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
11972 : 64 : if (TREE_SIDE_EFFECTS (t)
11973 : 8 : && t != decl
11974 : 70 : && (TREE_CODE (t) != NOP_EXPR
11975 : 0 : || TREE_OPERAND (t, 0) != decl))
11976 : 6 : TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
11977 : 12 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11978 : :
11979 : 64 : t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
11980 : 64 : if (TREE_SIDE_EFFECTS (t)
11981 : 56 : && t != decl
11982 : 120 : && (TREE_CODE (t) != NOP_EXPR
11983 : 5 : || TREE_OPERAND (t, 0) != decl))
11984 : 56 : TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
11985 : 112 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11986 : : }
11987 : :
11988 : 6199 : if (orig_incr)
11989 : 177 : TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
11990 : : }
11991 : 19780 : OMP_FOR_CLAUSES (omp_for) = clauses;
11992 : :
11993 : : /* For simd loops with non-static data member iterators, we could have added
11994 : : OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
11995 : : step at this point, fill it in. */
11996 : 4735 : if (code == OMP_SIMD && !processing_template_decl
11997 : 24471 : && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
11998 : 4619 : for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
11999 : 561 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
12000 : 561 : if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
12001 : : {
12002 : 4 : decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
12003 : 4 : gcc_assert (decl == OMP_CLAUSE_DECL (c));
12004 : 4 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
12005 : 4 : tree step, stept;
12006 : 4 : switch (TREE_CODE (incr))
12007 : : {
12008 : 0 : case PREINCREMENT_EXPR:
12009 : 0 : case POSTINCREMENT_EXPR:
12010 : : /* c_omp_for_incr_canonicalize_ptr() should have been
12011 : : called to massage things appropriately. */
12012 : 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12013 : 0 : OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
12014 : 0 : break;
12015 : 0 : case PREDECREMENT_EXPR:
12016 : 0 : case POSTDECREMENT_EXPR:
12017 : : /* c_omp_for_incr_canonicalize_ptr() should have been
12018 : : called to massage things appropriately. */
12019 : 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
12020 : 0 : OMP_CLAUSE_LINEAR_STEP (c)
12021 : 0 : = build_int_cst (TREE_TYPE (decl), -1);
12022 : 0 : break;
12023 : 4 : case MODIFY_EXPR:
12024 : 4 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12025 : 4 : incr = TREE_OPERAND (incr, 1);
12026 : 4 : switch (TREE_CODE (incr))
12027 : : {
12028 : 4 : case PLUS_EXPR:
12029 : 4 : if (TREE_OPERAND (incr, 1) == decl)
12030 : 0 : step = TREE_OPERAND (incr, 0);
12031 : : else
12032 : 4 : step = TREE_OPERAND (incr, 1);
12033 : : break;
12034 : 0 : case MINUS_EXPR:
12035 : 0 : case POINTER_PLUS_EXPR:
12036 : 0 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
12037 : 0 : step = TREE_OPERAND (incr, 1);
12038 : 0 : break;
12039 : 0 : default:
12040 : 0 : gcc_unreachable ();
12041 : : }
12042 : 4 : stept = TREE_TYPE (decl);
12043 : 4 : if (INDIRECT_TYPE_P (stept))
12044 : 0 : stept = sizetype;
12045 : 4 : step = fold_convert (stept, step);
12046 : 4 : if (TREE_CODE (incr) == MINUS_EXPR)
12047 : 0 : step = fold_build1 (NEGATE_EXPR, stept, step);
12048 : 4 : OMP_CLAUSE_LINEAR_STEP (c) = step;
12049 : 4 : break;
12050 : 0 : default:
12051 : 0 : gcc_unreachable ();
12052 : : }
12053 : : }
12054 : : /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
12055 : : clauses, we need copy ctor for those rather than default ctor,
12056 : : plus as for other lastprivates assignment op and dtor. */
12057 : 19780 : if (code == OMP_LOOP && !processing_template_decl)
12058 : 1993 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
12059 : 1285 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
12060 : 204 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
12061 : 1307 : && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
12062 : : false, true, true, true))
12063 : 0 : CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
12064 : :
12065 : : return omp_for;
12066 : 21120 : }
12067 : :
12068 : : /* Code walker for finish_omp_for_block: extract binding of DP->var
12069 : : from its current block and move it to a new BIND_EXPR DP->b
12070 : : surrounding the body of DP->omp_for. */
12071 : :
12072 : : struct fofb_data {
12073 : : tree var;
12074 : : tree b;
12075 : : tree omp_for;
12076 : : };
12077 : :
12078 : : static tree
12079 : 389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
12080 : : {
12081 : 389 : struct fofb_data *fofb = (struct fofb_data *)dp;
12082 : 389 : if (TREE_CODE (*tp) == BIND_EXPR)
12083 : 578 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
12084 : : {
12085 : 576 : if (*p == fofb->var)
12086 : : {
12087 : 363 : *p = DECL_CHAIN (*p);
12088 : 363 : if (fofb->b == NULL_TREE)
12089 : : {
12090 : 214 : fofb->b = make_node (BLOCK);
12091 : 214 : fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
12092 : 214 : OMP_FOR_BODY (fofb->omp_for), fofb->b);
12093 : 214 : TREE_SIDE_EFFECTS (fofb->b) = 1;
12094 : 214 : OMP_FOR_BODY (fofb->omp_for) = fofb->b;
12095 : : }
12096 : 363 : DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
12097 : 363 : BIND_EXPR_VARS (fofb->b) = fofb->var;
12098 : 363 : BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
12099 : 363 : BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
12100 : 363 : return *tp;
12101 : : }
12102 : : }
12103 : 26 : if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
12104 : 22 : *walk_subtrees = false;
12105 : : return NULL_TREE;
12106 : : }
12107 : :
12108 : : /* Fix up range for decls. Those decls were pushed into BIND's
12109 : : BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
12110 : : and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
12111 : : so that processing of combined loop directives can find them. */
12112 : : tree
12113 : 14514 : finish_omp_for_block (tree bind, tree omp_for)
12114 : : {
12115 : 14514 : if (omp_for == NULL_TREE
12116 : 14467 : || !OMP_FOR_ORIG_DECLS (omp_for)
12117 : 28416 : || bind == NULL_TREE)
12118 : 612 : return bind;
12119 : 13902 : struct fofb_data fofb;
12120 : 13902 : fofb.b = NULL_TREE;
12121 : 13902 : fofb.omp_for = omp_for;
12122 : 33325 : for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
12123 : 19423 : if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
12124 : 19201 : && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
12125 : : == TREE_LIST)
12126 : 20254 : && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
12127 : : {
12128 : 237 : tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
12129 : 602 : for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
12130 : : {
12131 : 365 : fofb.var = TREE_VEC_ELT (v, j);
12132 : 365 : cp_walk_tree (&bind, finish_omp_for_block_walker,
12133 : : (void *)&fofb, NULL);
12134 : : }
12135 : : }
12136 : 13902 : return bind;
12137 : : }
12138 : :
12139 : : void
12140 : 3342 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
12141 : : tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
12142 : : tree clauses, enum omp_memory_order mo, bool weak)
12143 : : {
12144 : 3342 : tree orig_lhs;
12145 : 3342 : tree orig_rhs;
12146 : 3342 : tree orig_v;
12147 : 3342 : tree orig_lhs1;
12148 : 3342 : tree orig_rhs1;
12149 : 3342 : tree orig_r;
12150 : 3342 : bool dependent_p;
12151 : 3342 : tree stmt;
12152 : :
12153 : 3342 : orig_lhs = lhs;
12154 : 3342 : orig_rhs = rhs;
12155 : 3342 : orig_v = v;
12156 : 3342 : orig_lhs1 = lhs1;
12157 : 3342 : orig_rhs1 = rhs1;
12158 : 3342 : orig_r = r;
12159 : 3342 : dependent_p = false;
12160 : 3342 : stmt = NULL_TREE;
12161 : :
12162 : : /* Even in a template, we can detect invalid uses of the atomic
12163 : : pragma if neither LHS nor RHS is type-dependent. */
12164 : 3342 : if (processing_template_decl)
12165 : : {
12166 : 600 : dependent_p = (type_dependent_expression_p (lhs)
12167 : 237 : || (rhs && type_dependent_expression_p (rhs))
12168 : 234 : || (v && type_dependent_expression_p (v))
12169 : 234 : || (lhs1 && type_dependent_expression_p (lhs1))
12170 : 234 : || (rhs1 && type_dependent_expression_p (rhs1))
12171 : 834 : || (r
12172 : 25 : && r != void_list_node
12173 : 16 : && type_dependent_expression_p (r)));
12174 : 600 : if (clauses)
12175 : : {
12176 : 30 : gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
12177 : : && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
12178 : : && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
12179 : 30 : if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
12180 : 30 : || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
12181 : : dependent_p = true;
12182 : : }
12183 : : }
12184 : 576 : if (!dependent_p)
12185 : : {
12186 : 2958 : bool swapped = false;
12187 : 2958 : if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
12188 : : {
12189 : 143 : std::swap (rhs, rhs1);
12190 : 143 : swapped = !commutative_tree_code (opcode);
12191 : : }
12192 : 2958 : if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
12193 : : {
12194 : 0 : if (code == OMP_ATOMIC)
12195 : 0 : error ("%<#pragma omp atomic update%> uses two different "
12196 : : "expressions for memory");
12197 : : else
12198 : 0 : error ("%<#pragma omp atomic capture%> uses two different "
12199 : : "expressions for memory");
12200 : 0 : return;
12201 : : }
12202 : 2958 : if (lhs1 && !cp_tree_equal (lhs, lhs1))
12203 : : {
12204 : 0 : if (code == OMP_ATOMIC)
12205 : 0 : error ("%<#pragma omp atomic update%> uses two different "
12206 : : "expressions for memory");
12207 : : else
12208 : 0 : error ("%<#pragma omp atomic capture%> uses two different "
12209 : : "expressions for memory");
12210 : 0 : return;
12211 : : }
12212 : 5916 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
12213 : : v, lhs1, rhs1, r, swapped, mo, weak,
12214 : 2958 : processing_template_decl != 0);
12215 : 2958 : if (stmt == error_mark_node)
12216 : : return;
12217 : : }
12218 : 3312 : if (processing_template_decl)
12219 : : {
12220 : 591 : if (code == OMP_ATOMIC_READ)
12221 : : {
12222 : 167 : stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
12223 : 167 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12224 : 167 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12225 : : }
12226 : : else
12227 : : {
12228 : 424 : if (opcode == NOP_EXPR)
12229 : 35 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
12230 : 389 : else if (opcode == COND_EXPR)
12231 : : {
12232 : 124 : stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
12233 : 124 : if (orig_r)
12234 : 50 : stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
12235 : : stmt);
12236 : 124 : stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
12237 : : orig_lhs);
12238 : 124 : orig_rhs1 = NULL_TREE;
12239 : : }
12240 : : else
12241 : 265 : stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
12242 : 424 : if (orig_rhs1)
12243 : 182 : stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
12244 : : COMPOUND_EXPR, orig_rhs1, stmt);
12245 : 424 : if (code != OMP_ATOMIC)
12246 : : {
12247 : 233 : stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
12248 : 233 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12249 : 233 : OMP_ATOMIC_WEAK (stmt) = weak;
12250 : 233 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
12251 : : }
12252 : : }
12253 : 591 : stmt = build2 (OMP_ATOMIC, void_type_node,
12254 : : clauses ? clauses : integer_zero_node, stmt);
12255 : 591 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
12256 : 591 : OMP_ATOMIC_WEAK (stmt) = weak;
12257 : 591 : SET_EXPR_LOCATION (stmt, loc);
12258 : : }
12259 : :
12260 : : /* Avoid -Wunused-value warnings here, the whole construct has side-effects
12261 : : and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
12262 : : in some tree that appears to be unused, the value is not unused. */
12263 : 3312 : warning_sentinel w (warn_unused_value);
12264 : 3312 : finish_expr_stmt (stmt);
12265 : 3312 : }
12266 : :
12267 : : void
12268 : 359 : finish_omp_barrier (void)
12269 : : {
12270 : 359 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
12271 : 359 : releasing_vec vec;
12272 : 359 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12273 : 359 : finish_expr_stmt (stmt);
12274 : 359 : }
12275 : :
12276 : : void
12277 : 397 : finish_omp_depobj (location_t loc, tree depobj,
12278 : : enum omp_clause_depend_kind kind, tree clause)
12279 : : {
12280 : 397 : if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
12281 : : {
12282 : 343 : if (!lvalue_p (depobj))
12283 : : {
12284 : 6 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
12285 : : "%<depobj%> expression is not lvalue expression");
12286 : 6 : depobj = error_mark_node;
12287 : : }
12288 : : }
12289 : :
12290 : 397 : if (processing_template_decl)
12291 : : {
12292 : 114 : if (clause == NULL_TREE)
12293 : 47 : clause = build_int_cst (integer_type_node, kind);
12294 : 114 : add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
12295 : 114 : return;
12296 : : }
12297 : :
12298 : 283 : if (!error_operand_p (depobj))
12299 : : {
12300 : 274 : tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
12301 : 274 : if (addr == error_mark_node)
12302 : : depobj = error_mark_node;
12303 : : else
12304 : 274 : depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
12305 : : tf_warning_or_error);
12306 : : }
12307 : :
12308 : 283 : c_finish_omp_depobj (loc, depobj, kind, clause);
12309 : : }
12310 : :
12311 : : void
12312 : 162 : finish_omp_flush (int mo)
12313 : : {
12314 : 162 : tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
12315 : 162 : releasing_vec vec;
12316 : 162 : if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
12317 : : {
12318 : 54 : fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
12319 : 54 : vec->quick_push (build_int_cst (integer_type_node, mo));
12320 : : }
12321 : 162 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12322 : 162 : finish_expr_stmt (stmt);
12323 : 162 : }
12324 : :
12325 : : void
12326 : 111 : finish_omp_taskwait (void)
12327 : : {
12328 : 111 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
12329 : 111 : releasing_vec vec;
12330 : 111 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12331 : 111 : finish_expr_stmt (stmt);
12332 : 111 : }
12333 : :
12334 : : void
12335 : 16 : finish_omp_taskyield (void)
12336 : : {
12337 : 16 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
12338 : 16 : releasing_vec vec;
12339 : 16 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12340 : 16 : finish_expr_stmt (stmt);
12341 : 16 : }
12342 : :
12343 : : void
12344 : 596 : finish_omp_cancel (tree clauses)
12345 : : {
12346 : 596 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
12347 : 596 : int mask = 0;
12348 : 596 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12349 : : mask = 1;
12350 : 414 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12351 : : mask = 2;
12352 : 285 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12353 : : mask = 4;
12354 : 164 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12355 : : mask = 8;
12356 : : else
12357 : : {
12358 : 0 : error ("%<#pragma omp cancel%> must specify one of "
12359 : : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12360 : 0 : return;
12361 : : }
12362 : 596 : releasing_vec vec;
12363 : 596 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
12364 : 596 : if (ifc != NULL_TREE)
12365 : : {
12366 : 70 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
12367 : 70 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
12368 : 6 : error_at (OMP_CLAUSE_LOCATION (ifc),
12369 : : "expected %<cancel%> %<if%> clause modifier");
12370 : : else
12371 : : {
12372 : 64 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
12373 : 64 : if (ifc2 != NULL_TREE)
12374 : : {
12375 : 3 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
12376 : : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
12377 : : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
12378 : 3 : error_at (OMP_CLAUSE_LOCATION (ifc2),
12379 : : "expected %<cancel%> %<if%> clause modifier");
12380 : : }
12381 : : }
12382 : :
12383 : 70 : if (!processing_template_decl)
12384 : 61 : ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
12385 : : else
12386 : 9 : ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
12387 : 9 : OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
12388 : : integer_zero_node, ERROR_MARK,
12389 : : NULL_TREE, NULL, tf_warning_or_error);
12390 : : }
12391 : : else
12392 : 526 : ifc = boolean_true_node;
12393 : 596 : vec->quick_push (build_int_cst (integer_type_node, mask));
12394 : 596 : vec->quick_push (ifc);
12395 : 596 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12396 : 596 : finish_expr_stmt (stmt);
12397 : 596 : }
12398 : :
12399 : : void
12400 : 494 : finish_omp_cancellation_point (tree clauses)
12401 : : {
12402 : 494 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
12403 : 494 : int mask = 0;
12404 : 494 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12405 : : mask = 1;
12406 : 366 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12407 : : mask = 2;
12408 : 261 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12409 : : mask = 4;
12410 : 156 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12411 : : mask = 8;
12412 : : else
12413 : : {
12414 : 3 : error ("%<#pragma omp cancellation point%> must specify one of "
12415 : : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12416 : 3 : return;
12417 : : }
12418 : 491 : releasing_vec vec
12419 : 491 : = make_tree_vector_single (build_int_cst (integer_type_node, mask));
12420 : 491 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12421 : 491 : finish_expr_stmt (stmt);
12422 : 491 : }
12423 : :
12424 : : /* Begin a __transaction_atomic or __transaction_relaxed statement.
12425 : : If PCOMPOUND is non-null, this is for a function-transaction-block, and we
12426 : : should create an extra compound stmt. */
12427 : :
12428 : : tree
12429 : 303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
12430 : : {
12431 : 303 : tree r;
12432 : :
12433 : 303 : if (pcompound)
12434 : 21 : *pcompound = begin_compound_stmt (0);
12435 : :
12436 : 303 : r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
12437 : :
12438 : : /* Only add the statement to the function if support enabled. */
12439 : 303 : if (flag_tm)
12440 : 297 : add_stmt (r);
12441 : : else
12442 : 12 : error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
12443 : : ? G_("%<__transaction_relaxed%> without "
12444 : : "transactional memory support enabled")
12445 : : : G_("%<__transaction_atomic%> without "
12446 : : "transactional memory support enabled")));
12447 : :
12448 : 303 : TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
12449 : 303 : TREE_SIDE_EFFECTS (r) = 1;
12450 : 303 : return r;
12451 : : }
12452 : :
12453 : : /* End a __transaction_atomic or __transaction_relaxed statement.
12454 : : If COMPOUND_STMT is non-null, this is for a function-transaction-block,
12455 : : and we should end the compound. If NOEX is non-NULL, we wrap the body in
12456 : : a MUST_NOT_THROW_EXPR with NOEX as condition. */
12457 : :
12458 : : void
12459 : 303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
12460 : : {
12461 : 303 : TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
12462 : 303 : TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
12463 : 303 : TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
12464 : 303 : TRANSACTION_EXPR_IS_STMT (stmt) = 1;
12465 : :
12466 : : /* noexcept specifications are not allowed for function transactions. */
12467 : 303 : gcc_assert (!(noex && compound_stmt));
12468 : 303 : if (noex)
12469 : : {
12470 : 51 : tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
12471 : : noex);
12472 : 51 : protected_set_expr_location
12473 : 51 : (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
12474 : 51 : TREE_SIDE_EFFECTS (body) = 1;
12475 : 51 : TRANSACTION_EXPR_BODY (stmt) = body;
12476 : : }
12477 : :
12478 : 303 : if (compound_stmt)
12479 : 21 : finish_compound_stmt (compound_stmt);
12480 : 303 : }
12481 : :
12482 : : /* Build a __transaction_atomic or __transaction_relaxed expression. If
12483 : : NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
12484 : : condition. */
12485 : :
12486 : : tree
12487 : 116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
12488 : : {
12489 : 116 : tree ret;
12490 : 116 : if (noex)
12491 : : {
12492 : 57 : expr = build_must_not_throw_expr (expr, noex);
12493 : 57 : protected_set_expr_location (expr, loc);
12494 : 57 : TREE_SIDE_EFFECTS (expr) = 1;
12495 : : }
12496 : 116 : ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
12497 : 116 : if (flags & TM_STMT_ATTR_RELAXED)
12498 : 4 : TRANSACTION_EXPR_RELAXED (ret) = 1;
12499 : 116 : TREE_SIDE_EFFECTS (ret) = 1;
12500 : 116 : SET_EXPR_LOCATION (ret, loc);
12501 : 116 : return ret;
12502 : : }
12503 : :
12504 : : void
12505 : 96838 : init_cp_semantics (void)
12506 : : {
12507 : 96838 : }
12508 : :
12509 : :
12510 : : /* Get constant string at LOCATION. Returns true if successful,
12511 : : otherwise false. */
12512 : :
12513 : : bool
12514 : 9355710 : cexpr_str::type_check (location_t location)
12515 : : {
12516 : 9355710 : tsubst_flags_t complain = tf_warning_or_error;
12517 : :
12518 : 9355710 : if (message == NULL_TREE
12519 : 9355710 : || message == error_mark_node
12520 : 18711417 : || check_for_bare_parameter_packs (message))
12521 : 3 : return false;
12522 : :
12523 : 9355707 : if (TREE_CODE (message) != STRING_CST
12524 : 9355707 : && !type_dependent_expression_p (message))
12525 : : {
12526 : 887 : message_sz
12527 : 887 : = finish_class_member_access_expr (message,
12528 : : get_identifier ("size"),
12529 : : false, complain);
12530 : 887 : if (message_sz != error_mark_node)
12531 : 814 : message_data
12532 : 814 : = finish_class_member_access_expr (message,
12533 : : get_identifier ("data"),
12534 : : false, complain);
12535 : 887 : if (message_sz == error_mark_node || message_data == error_mark_node)
12536 : : {
12537 : 103 : error_at (location, "constexpr string must be a string "
12538 : : "literal or object with %<size%> and "
12539 : : "%<data%> members");
12540 : 262 : return false;
12541 : : }
12542 : 784 : releasing_vec size_args, data_args;
12543 : 784 : message_sz = finish_call_expr (message_sz, &size_args, false, false,
12544 : : complain);
12545 : 784 : message_data = finish_call_expr (message_data, &data_args, false, false,
12546 : : complain);
12547 : 784 : if (message_sz == error_mark_node || message_data == error_mark_node)
12548 : : return false;
12549 : 670 : message_sz = build_converted_constant_expr (size_type_node, message_sz,
12550 : : complain);
12551 : 670 : if (message_sz == error_mark_node)
12552 : : {
12553 : 15 : error_at (location, "constexpr string %<size()%> "
12554 : : "must be implicitly convertible to "
12555 : : "%<std::size_t%>");
12556 : 15 : return false;
12557 : : }
12558 : 655 : message_data = build_converted_constant_expr (const_string_type_node,
12559 : : message_data, complain);
12560 : 655 : if (message_data == error_mark_node)
12561 : : {
12562 : 30 : error_at (location, "constexpr string %<data()%> "
12563 : : "must be implicitly convertible to "
12564 : : "%<const char*%>");
12565 : 30 : return false;
12566 : : }
12567 : 784 : }
12568 : : return true;
12569 : : }
12570 : :
12571 : : /* Extract constant string at LOCATON into output string STR.
12572 : : Returns true if successful, otherwise false. */
12573 : :
12574 : : bool
12575 : 393 : cexpr_str::extract (location_t location, tree &str)
12576 : : {
12577 : 393 : const char *msg;
12578 : 393 : int len;
12579 : 393 : if (!extract (location, msg, len))
12580 : : return false;
12581 : 331 : str = build_string (len, msg);
12582 : 331 : return true;
12583 : : }
12584 : :
12585 : : /* Extract constant string at LOCATION into output string MSG with LEN.
12586 : : Returns true if successful, otherwise false. */
12587 : :
12588 : : bool
12589 : 2150 : cexpr_str::extract (location_t location, const char * & msg, int &len)
12590 : : {
12591 : 2150 : tsubst_flags_t complain = tf_warning_or_error;
12592 : :
12593 : 2150 : msg = NULL;
12594 : 2150 : if (message_sz && message_data)
12595 : : {
12596 : 551 : tree msz = cxx_constant_value (message_sz, NULL_TREE, complain);
12597 : 551 : if (!tree_fits_uhwi_p (msz))
12598 : : {
12599 : 35 : error_at (location,
12600 : : "constexpr string %<size()%> "
12601 : : "must be a constant expression");
12602 : 35 : return false;
12603 : : }
12604 : 516 : else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
12605 : : != tree_to_uhwi (msz))
12606 : : {
12607 : 0 : error_at (location,
12608 : : "constexpr string message %<size()%> "
12609 : : "%qE too large", msz);
12610 : 0 : return false;
12611 : : }
12612 : 516 : len = tree_to_uhwi (msz);
12613 : 516 : tree data = maybe_constant_value (message_data, NULL_TREE,
12614 : : mce_true);
12615 : 516 : if (!reduced_constant_expression_p (data))
12616 : 96 : data = NULL_TREE;
12617 : 516 : if (len)
12618 : : {
12619 : 439 : if (data)
12620 : 365 : msg = c_getstr (data);
12621 : 439 : if (msg == NULL)
12622 : 119 : buf = XNEWVEC (char, len);
12623 : 1413 : for (int i = 0; i < len; ++i)
12624 : : {
12625 : 1004 : tree t = message_data;
12626 : 1004 : if (i)
12627 : 1130 : t = build2 (POINTER_PLUS_EXPR,
12628 : 565 : TREE_TYPE (message_data), message_data,
12629 : 565 : size_int (i));
12630 : 1004 : t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
12631 : 1004 : tree t2 = cxx_constant_value (t, NULL_TREE, complain);
12632 : 1004 : if (!tree_fits_shwi_p (t2))
12633 : : {
12634 : 30 : error_at (location,
12635 : : "constexpr string %<data()[%d]%> "
12636 : : "must be a constant expression", i);
12637 : 30 : return false;
12638 : : }
12639 : 974 : if (msg == NULL)
12640 : 362 : buf[i] = tree_to_shwi (t2);
12641 : : /* If c_getstr worked, just verify the first and
12642 : : last characters using constant evaluation. */
12643 : 612 : else if (len > 2 && i == 0)
12644 : 258 : i = len - 2;
12645 : : }
12646 : 409 : if (msg == NULL)
12647 : 104 : msg = buf;
12648 : : }
12649 : 77 : else if (!data)
12650 : : {
12651 : : /* We don't have any function to test whether some
12652 : : expression is a core constant expression. So, instead
12653 : : test whether (message.data (), 0) is a constant
12654 : : expression. */
12655 : 22 : data = build2 (COMPOUND_EXPR, integer_type_node,
12656 : : message_data, integer_zero_node);
12657 : 22 : tree t = cxx_constant_value (data, NULL_TREE, complain);
12658 : 22 : if (!integer_zerop (t))
12659 : : {
12660 : 22 : error_at (location,
12661 : : "constexpr string %<data()%> "
12662 : : "must be a core constant expression");
12663 : 22 : return false;
12664 : : }
12665 : : }
12666 : : }
12667 : : else
12668 : : {
12669 : 1599 : tree eltype = TREE_TYPE (TREE_TYPE (message));
12670 : 1599 : int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
12671 : 1599 : msg = TREE_STRING_POINTER (message);
12672 : 1599 : len = TREE_STRING_LENGTH (message) / sz - 1;
12673 : : }
12674 : :
12675 : : return true;
12676 : : }
12677 : :
12678 : : /* Build a STATIC_ASSERT for a static assertion with the condition
12679 : : CONDITION and the message text MESSAGE. LOCATION is the location
12680 : : of the static assertion in the source code. When MEMBER_P, this
12681 : : static assertion is a member of a class. If SHOW_EXPR_P is true,
12682 : : print the condition (because it was instantiation-dependent).
12683 : : If CONSTEVAL_BLOCK_P is true, this static assertion represents
12684 : : a consteval block. */
12685 : :
12686 : : void
12687 : 9355306 : finish_static_assert (tree condition, tree message, location_t location,
12688 : : bool member_p, bool show_expr_p,
12689 : : bool consteval_block_p/*=false*/)
12690 : : {
12691 : 9355306 : tsubst_flags_t complain = tf_warning_or_error;
12692 : :
12693 : 9355306 : if (condition == NULL_TREE
12694 : 9355306 : || condition == error_mark_node)
12695 : 4190828 : return;
12696 : :
12697 : 9355149 : if (check_for_bare_parameter_packs (condition))
12698 : : return;
12699 : :
12700 : 9355146 : cexpr_str cstr(message);
12701 : 9355146 : if (!cstr.type_check (location))
12702 : : return;
12703 : :
12704 : : /* Save the condition in case it was a concept check. */
12705 : 9355052 : tree orig_condition = condition;
12706 : :
12707 : 9355052 : if (instantiation_dependent_expression_p (condition)
12708 : 9355052 : || instantiation_dependent_expression_p (message))
12709 : : {
12710 : : /* We're in a template; build a STATIC_ASSERT and put it in
12711 : : the right place. */
12712 : 4190498 : defer:
12713 : 4190498 : tree assertion = make_node (STATIC_ASSERT);
12714 : 4190498 : STATIC_ASSERT_CONDITION (assertion) = orig_condition;
12715 : 4190498 : STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
12716 : 4190498 : STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
12717 : 4190498 : CONSTEVAL_BLOCK_P (assertion) = consteval_block_p;
12718 : :
12719 : 4190498 : if (member_p)
12720 : 2240329 : maybe_add_class_template_decl_list (current_class_type,
12721 : : assertion,
12722 : : /*friend_p=*/0);
12723 : : else
12724 : 1950169 : add_stmt (assertion);
12725 : :
12726 : 4190498 : return;
12727 : : }
12728 : :
12729 : : /* Evaluate the consteval { }. This must be done only once. */
12730 : 5172020 : if (consteval_block_p)
12731 : : {
12732 : 51 : cxx_constant_value (condition);
12733 : 51 : return;
12734 : : }
12735 : :
12736 : : /* Fold the expression and convert it to a boolean value. */
12737 : 5171969 : condition = contextual_conv_bool (condition, complain);
12738 : 5171969 : condition = fold_non_dependent_expr (condition, complain,
12739 : : /*manifestly_const_eval=*/true);
12740 : :
12741 : 5171968 : if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
12742 : : /* Do nothing; the condition is satisfied. */
12743 : : ;
12744 : : else
12745 : : {
12746 : 9605 : iloc_sentinel ils (location);
12747 : :
12748 : 9605 : if (integer_zerop (condition))
12749 : : {
12750 : : /* CWG2518: static_assert failure in a template is not IFNDR. */
12751 : 9223 : if (processing_template_decl)
12752 : 7466 : goto defer;
12753 : :
12754 : 1757 : int len;
12755 : 1757 : const char *msg = NULL;
12756 : 1757 : if (!cstr.extract (location, msg, len))
12757 : 25 : return;
12758 : :
12759 : : /* See if we can find which clause was failing (for logical AND). */
12760 : 1732 : tree bad = find_failing_clause (NULL, orig_condition);
12761 : : /* If not, or its location is unusable, fall back to the previous
12762 : : location. */
12763 : 1732 : location_t cloc = cp_expr_loc_or_loc (bad, location);
12764 : :
12765 : 1732 : auto_diagnostic_group d;
12766 : :
12767 : : /* Report the error. */
12768 : 1732 : if (len == 0)
12769 : 1085 : error_at (cloc, "static assertion failed");
12770 : : else
12771 : 647 : error_at (cloc, "static assertion failed: %.*s", len, msg);
12772 : :
12773 : 1732 : diagnose_failing_condition (bad, cloc, show_expr_p);
12774 : 1732 : }
12775 : 382 : else if (condition && condition != error_mark_node)
12776 : : {
12777 : 379 : error ("non-constant condition for static assertion");
12778 : 379 : if (require_rvalue_constant_expression (condition))
12779 : 323 : cxx_constant_value (condition);
12780 : : }
12781 : 9605 : }
12782 : 9355145 : }
12783 : :
12784 : : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
12785 : : suitable for use as a type-specifier.
12786 : :
12787 : : ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
12788 : : id-expression or a class member access, FALSE when it was parsed as
12789 : : a full expression. */
12790 : :
12791 : : tree
12792 : 29341476 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
12793 : : tsubst_flags_t complain)
12794 : : {
12795 : 29341476 : tree type = NULL_TREE;
12796 : :
12797 : 29341476 : if (!expr || error_operand_p (expr))
12798 : 128740 : return error_mark_node;
12799 : :
12800 : 29212736 : if (TYPE_P (expr)
12801 : 29212736 : || TREE_CODE (expr) == TYPE_DECL
12802 : 58425454 : || (TREE_CODE (expr) == BIT_NOT_EXPR
12803 : 13550 : && TYPE_P (TREE_OPERAND (expr, 0))))
12804 : : {
12805 : 27 : if (complain & tf_error)
12806 : 27 : error ("argument to %<decltype%> must be an expression");
12807 : 27 : return error_mark_node;
12808 : : }
12809 : :
12810 : : /* decltype is an unevaluated context. */
12811 : 29212709 : cp_unevaluated u;
12812 : :
12813 : 29212709 : processing_template_decl_sentinel ptds (/*reset=*/false);
12814 : :
12815 : : /* Depending on the resolution of DR 1172, we may later need to distinguish
12816 : : instantiation-dependent but not type-dependent expressions so that, say,
12817 : : A<decltype(sizeof(T))>::U doesn't require 'typename'. */
12818 : 29212709 : if (instantiation_dependent_uneval_expression_p (expr))
12819 : : {
12820 : 4935804 : dependent:
12821 : 4936188 : type = cxx_make_type (DECLTYPE_TYPE);
12822 : 4936188 : DECLTYPE_TYPE_EXPR (type) = expr;
12823 : 9872376 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
12824 : 4936188 : = id_expression_or_member_access_p;
12825 : 4936188 : SET_TYPE_STRUCTURAL_EQUALITY (type);
12826 : :
12827 : 4936188 : return type;
12828 : : }
12829 : 24276905 : else if (processing_template_decl)
12830 : : {
12831 : 4901 : expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
12832 : 4901 : if (expr == error_mark_node)
12833 : : return error_mark_node;
12834 : : /* Keep processing_template_decl cleared for the rest of the function
12835 : : (for sake of the call to lvalue_kind below, which handles templated
12836 : : and non-templated COND_EXPR differently). */
12837 : 4864 : processing_template_decl = 0;
12838 : : }
12839 : :
12840 : : /* The type denoted by decltype(e) is defined as follows: */
12841 : :
12842 : 24276868 : expr = resolve_nondeduced_context (expr, complain);
12843 : 24276868 : if (!mark_single_function (expr, complain))
12844 : 0 : return error_mark_node;
12845 : :
12846 : 24276868 : if (invalid_nonstatic_memfn_p (input_location, expr, complain))
12847 : 18 : return error_mark_node;
12848 : :
12849 : 24276850 : if (type_unknown_p (expr))
12850 : : {
12851 : 18 : if (complain & tf_error)
12852 : 6 : error ("%<decltype%> cannot resolve address of overloaded function");
12853 : 18 : return error_mark_node;
12854 : : }
12855 : :
12856 : 24276832 : if (id_expression_or_member_access_p)
12857 : : {
12858 : : /* If e is an id-expression or a class member access (5.2.5
12859 : : [expr.ref]), decltype(e) is defined as the type of the entity
12860 : : named by e. If there is no such entity, or e names a set of
12861 : : overloaded functions, the program is ill-formed. */
12862 : 973673 : if (identifier_p (expr))
12863 : 0 : expr = lookup_name (expr);
12864 : :
12865 : 973673 : if (INDIRECT_REF_P (expr)
12866 : 973673 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
12867 : : /* This can happen when the expression is, e.g., "a.b". Just
12868 : : look at the underlying operand. */
12869 : 836519 : expr = TREE_OPERAND (expr, 0);
12870 : :
12871 : 973673 : if (TREE_CODE (expr) == OFFSET_REF
12872 : 973673 : || TREE_CODE (expr) == MEMBER_REF
12873 : 973673 : || TREE_CODE (expr) == SCOPE_REF)
12874 : : /* We're only interested in the field itself. If it is a
12875 : : BASELINK, we will need to see through it in the next
12876 : : step. */
12877 : 0 : expr = TREE_OPERAND (expr, 1);
12878 : :
12879 : 973673 : if (BASELINK_P (expr))
12880 : : /* See through BASELINK nodes to the underlying function. */
12881 : 3 : expr = BASELINK_FUNCTIONS (expr);
12882 : :
12883 : : /* decltype of a decomposition name drops references in the tuple case
12884 : : (unlike decltype of a normal variable) and keeps cv-qualifiers from
12885 : : the containing object in the other cases (unlike decltype of a member
12886 : : access expression). */
12887 : 973673 : if (DECL_DECOMPOSITION_P (expr))
12888 : : {
12889 : 1403 : if (ptds.saved)
12890 : : {
12891 : 266 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
12892 : : /* DECL_HAS_VALUE_EXPR_P is always set if
12893 : : processing_template_decl. If lookup_decomp_type
12894 : : returns non-NULL, it is the tuple case. */
12895 : 266 : if (tree ret = lookup_decomp_type (expr))
12896 : : return ret;
12897 : : }
12898 : 1328 : if (DECL_HAS_VALUE_EXPR_P (expr))
12899 : : /* Expr is an array or struct subobject proxy, handle
12900 : : bit-fields properly. */
12901 : 1016 : return unlowered_expr_type (expr);
12902 : : else
12903 : : /* Expr is a reference variable for the tuple case. */
12904 : 312 : return lookup_decomp_type (expr);
12905 : : }
12906 : :
12907 : 972270 : switch (TREE_CODE (expr))
12908 : : {
12909 : 57 : case FIELD_DECL:
12910 : 57 : if (DECL_BIT_FIELD_TYPE (expr))
12911 : : {
12912 : : type = DECL_BIT_FIELD_TYPE (expr);
12913 : : break;
12914 : : }
12915 : : /* Fall through for fields that aren't bitfields. */
12916 : 120597 : gcc_fallthrough ();
12917 : :
12918 : 120597 : case VAR_DECL:
12919 : 120597 : if (is_capture_proxy (expr))
12920 : : {
12921 : 85 : if (is_normal_capture_proxy (expr))
12922 : : {
12923 : 21 : expr = DECL_CAPTURED_VARIABLE (expr);
12924 : 21 : type = TREE_TYPE (expr);
12925 : : }
12926 : : else
12927 : : {
12928 : 64 : expr = DECL_VALUE_EXPR (expr);
12929 : 64 : gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
12930 : 64 : expr = TREE_OPERAND (expr, 1);
12931 : 64 : type = TREE_TYPE (expr);
12932 : : }
12933 : : break;
12934 : : }
12935 : : /* Fall through for variables that aren't capture proxies. */
12936 : 968770 : gcc_fallthrough ();
12937 : :
12938 : 968770 : case FUNCTION_DECL:
12939 : 968770 : case CONST_DECL:
12940 : 968770 : case PARM_DECL:
12941 : 968770 : case RESULT_DECL:
12942 : 968770 : case TEMPLATE_PARM_INDEX:
12943 : 968770 : expr = mark_type_use (expr);
12944 : 968770 : type = TREE_TYPE (expr);
12945 : 968770 : if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
12946 : : {
12947 : : /* decltype of an NTTP object is the type of the template
12948 : : parameter, which is the object type modulo cv-quals. */
12949 : 1052 : int quals = cp_type_quals (type);
12950 : 1052 : gcc_checking_assert (quals & TYPE_QUAL_CONST);
12951 : 1052 : type = cv_unqualified (type);
12952 : : }
12953 : : break;
12954 : :
12955 : 0 : case ERROR_MARK:
12956 : 0 : type = error_mark_node;
12957 : 0 : break;
12958 : :
12959 : 2866 : case COMPONENT_REF:
12960 : 2866 : case COMPOUND_EXPR:
12961 : 2866 : mark_type_use (expr);
12962 : 2866 : type = is_bitfield_expr_with_lowered_type (expr);
12963 : 2866 : if (!type)
12964 : 2833 : type = TREE_TYPE (TREE_OPERAND (expr, 1));
12965 : : break;
12966 : :
12967 : 0 : case BIT_FIELD_REF:
12968 : 0 : gcc_unreachable ();
12969 : :
12970 : 317 : case INTEGER_CST:
12971 : 317 : case PTRMEM_CST:
12972 : : /* We can get here when the id-expression refers to an
12973 : : enumerator or non-type template parameter. */
12974 : 317 : type = TREE_TYPE (expr);
12975 : 317 : break;
12976 : :
12977 : 232 : default:
12978 : : /* Handle instantiated template non-type arguments. */
12979 : 232 : type = TREE_TYPE (expr);
12980 : 232 : break;
12981 : : }
12982 : : }
12983 : : else
12984 : : {
12985 : 23303159 : tree decl = STRIP_REFERENCE_REF (expr);
12986 : 23303159 : tree lam = current_lambda_expr ();
12987 : 23303159 : if (lam && outer_automatic_var_p (decl))
12988 : : {
12989 : : /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
12990 : : unevaluated operand within S would refer to an entity captured by
12991 : : copy in some intervening lambda-expression, then let E be the
12992 : : innermost such lambda-expression.
12993 : :
12994 : : If there is such a lambda-expression and if P is in E's function
12995 : : parameter scope but not its parameter-declaration-clause, then the
12996 : : type of the expression is the type of a class member access
12997 : : expression naming the non-static data member that would be declared
12998 : : for such a capture in the object parameter of the function call
12999 : : operator of E." */
13000 : : /* FIXME: This transformation needs to happen for all uses of an outer
13001 : : local variable inside decltype, not just decltype((x)) (PR83167).
13002 : : And we don't handle nested lambdas properly, where we need to
13003 : : consider the outer lambdas as well (PR112926). */
13004 : 940 : tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
13005 : : LOOK_want::HIDDEN_LAMBDA);
13006 : :
13007 : 940 : if (cap && is_capture_proxy (cap))
13008 : 319 : type = TREE_TYPE (cap);
13009 : 621 : else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
13010 : : {
13011 : 500 : type = TREE_TYPE (decl);
13012 : 500 : if (TYPE_REF_P (type)
13013 : 500 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
13014 : 25 : type = TREE_TYPE (type);
13015 : : }
13016 : :
13017 : 819 : if (type && !TYPE_REF_P (type))
13018 : : {
13019 : 761 : int quals;
13020 : 761 : if (current_function_decl
13021 : 1428 : && LAMBDA_FUNCTION_P (current_function_decl)
13022 : 1428 : && DECL_XOBJ_MEMBER_FUNCTION_P (current_function_decl))
13023 : : {
13024 : 600 : tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
13025 : 600 : if (WILDCARD_TYPE_P (non_reference (obtype)))
13026 : : /* We don't know what the eventual obtype quals will be. */
13027 : 384 : goto dependent;
13028 : 432 : auto direct_type = [](tree t){
13029 : 216 : if (INDIRECT_TYPE_P (t))
13030 : 108 : return TREE_TYPE (t);
13031 : : return t;
13032 : : };
13033 : 432 : quals = (cp_type_quals (type)
13034 : 216 : | cp_type_quals (direct_type (obtype)));
13035 : : }
13036 : : else
13037 : : /* We are in the parameter clause, trailing return type, or
13038 : : the requires clause and have no relevant c_f_decl yet. */
13039 : 251 : quals = (LAMBDA_EXPR_CONST_QUAL_P (lam)
13040 : 161 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
13041 : 377 : type = cp_build_qualified_type (type, quals);
13042 : 377 : type = build_reference_type (type);
13043 : : }
13044 : : }
13045 : 23302219 : else if (error_operand_p (expr))
13046 : 0 : type = error_mark_node;
13047 : 23302219 : else if (expr == current_class_ptr)
13048 : : /* If the expression is just "this", we want the
13049 : : cv-unqualified pointer for the "this" type. */
13050 : 0 : type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
13051 : :
13052 : 377 : if (!type)
13053 : : {
13054 : : /* Otherwise, where T is the type of e, if e is an lvalue,
13055 : : decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
13056 : 23302340 : cp_lvalue_kind clk = lvalue_kind (expr);
13057 : 23302340 : type = unlowered_expr_type (expr);
13058 : 23302340 : gcc_assert (!TYPE_REF_P (type));
13059 : :
13060 : : /* For vector types, pick a non-opaque variant. */
13061 : 23302340 : if (VECTOR_TYPE_P (type))
13062 : 127 : type = strip_typedefs (type);
13063 : :
13064 : 23302340 : if (clk != clk_none && !(clk & clk_class))
13065 : 4514259 : type = cp_build_reference_type (type, (clk & clk_rvalueref));
13066 : : }
13067 : : }
13068 : :
13069 : : return type;
13070 : 29212709 : }
13071 : :
13072 : : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
13073 : : __has_nothrow_copy, depending on assign_p. Returns true iff all
13074 : : the copy {ctor,assign} fns are nothrow. */
13075 : :
13076 : : static bool
13077 : 279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
13078 : : {
13079 : 279 : tree fns = NULL_TREE;
13080 : :
13081 : 279 : if (assign_p || TYPE_HAS_COPY_CTOR (type))
13082 : 276 : fns = get_class_binding (type, assign_p ? assign_op_identifier
13083 : : : ctor_identifier);
13084 : :
13085 : 279 : bool saw_copy = false;
13086 : 696 : for (ovl_iterator iter (fns); iter; ++iter)
13087 : : {
13088 : 441 : tree fn = *iter;
13089 : :
13090 : 441 : if (copy_fn_p (fn) > 0)
13091 : : {
13092 : 423 : saw_copy = true;
13093 : 423 : if (!maybe_instantiate_noexcept (fn)
13094 : 423 : || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
13095 : 192 : return false;
13096 : : }
13097 : : }
13098 : :
13099 : 87 : return saw_copy;
13100 : : }
13101 : :
13102 : : /* Return true if BASE is a pointer-interconvertible base of DERIVED. */
13103 : :
13104 : : bool
13105 : 160 : pointer_interconvertible_base_of_p (tree base, tree derived,
13106 : : bool explain/*=false*/)
13107 : : {
13108 : 160 : if (base == error_mark_node || derived == error_mark_node)
13109 : : return false;
13110 : :
13111 : 160 : base = TYPE_MAIN_VARIANT (base);
13112 : 160 : derived = TYPE_MAIN_VARIANT (derived);
13113 : 160 : if (!NON_UNION_CLASS_TYPE_P (base))
13114 : : {
13115 : 17 : if (explain)
13116 : 3 : inform (location_of (base),
13117 : : "%qT is not a non-union class type", base);
13118 : 17 : return false;
13119 : : }
13120 : 143 : if (!NON_UNION_CLASS_TYPE_P (derived))
13121 : : {
13122 : 6 : if (explain)
13123 : 3 : inform (location_of (derived),
13124 : : "%qT is not a non-union class type", derived);
13125 : 6 : return false;
13126 : : }
13127 : :
13128 : 137 : if (same_type_p (base, derived))
13129 : : return true;
13130 : :
13131 : 106 : if (!std_layout_type_p (derived))
13132 : : {
13133 : 17 : if (explain)
13134 : 6 : inform (location_of (derived),
13135 : : "%qT is not a standard-layout type", derived);
13136 : 17 : return false;
13137 : : }
13138 : :
13139 : 89 : if (!uniquely_derived_from_p (base, derived))
13140 : : {
13141 : 16 : if (explain)
13142 : : {
13143 : : /* An ambiguous base should already be impossible due to
13144 : : the std_layout_type_p check. */
13145 : 3 : gcc_checking_assert (!DERIVED_FROM_P (base, derived));
13146 : 3 : inform (location_of (derived),
13147 : : "%qT is not a base of %qT", base, derived);
13148 : : }
13149 : 16 : return false;
13150 : : }
13151 : :
13152 : : return true;
13153 : : }
13154 : :
13155 : : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
13156 : : return true if MEMBERTYPE is the type of the first non-static data member
13157 : : of TYPE or for unions of any members. */
13158 : : static bool
13159 : 647 : first_nonstatic_data_member_p (tree type, tree membertype)
13160 : : {
13161 : 1307 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
13162 : : {
13163 : 1232 : if (TREE_CODE (field) != FIELD_DECL)
13164 : 135 : continue;
13165 : 1097 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
13166 : 60 : continue;
13167 : 1037 : if (DECL_FIELD_IS_BASE (field))
13168 : 45 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
13169 : 992 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13170 : : {
13171 : 216 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
13172 : 138 : || std_layout_type_p (TREE_TYPE (field)))
13173 : 294 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
13174 : : return true;
13175 : : }
13176 : 776 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13177 : : membertype))
13178 : : return true;
13179 : 540 : if (TREE_CODE (type) != UNION_TYPE)
13180 : : return false;
13181 : : }
13182 : : return false;
13183 : : }
13184 : :
13185 : : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
13186 : :
13187 : : tree
13188 : 553 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
13189 : : tree *args)
13190 : : {
13191 : : /* Unless users call the builtin directly, the following 3 checks should be
13192 : : ensured from std::is_pointer_interconvertible_with_class function
13193 : : template. */
13194 : 553 : if (nargs != 1)
13195 : : {
13196 : 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13197 : : "needs a single argument");
13198 : 6 : return boolean_false_node;
13199 : : }
13200 : 547 : tree arg = args[0];
13201 : 547 : if (error_operand_p (arg))
13202 : 0 : return boolean_false_node;
13203 : 547 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
13204 : : {
13205 : 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
13206 : : "argument is not pointer to member");
13207 : 6 : return boolean_false_node;
13208 : : }
13209 : :
13210 : 541 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
13211 : 21 : return boolean_false_node;
13212 : :
13213 : 520 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
13214 : 520 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
13215 : 520 : if (!complete_type_or_else (basetype, NULL_TREE))
13216 : 3 : return boolean_false_node;
13217 : :
13218 : 517 : if (TREE_CODE (basetype) != UNION_TYPE
13219 : 517 : && !std_layout_type_p (basetype))
13220 : 26 : return boolean_false_node;
13221 : :
13222 : 491 : if (!first_nonstatic_data_member_p (basetype, membertype))
13223 : 135 : return boolean_false_node;
13224 : :
13225 : 356 : if (TREE_CODE (arg) == PTRMEM_CST)
13226 : 70 : arg = cplus_expand_constant (arg);
13227 : :
13228 : 356 : if (integer_nonzerop (arg))
13229 : 11 : return boolean_false_node;
13230 : 345 : if (integer_zerop (arg))
13231 : 73 : return boolean_true_node;
13232 : :
13233 : 272 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
13234 : : build_zero_cst (TREE_TYPE (arg)));
13235 : : }
13236 : :
13237 : : /* Helper function for is_corresponding_member_aggr. Return true if
13238 : : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
13239 : : union or structure BASETYPE. */
13240 : :
13241 : : static bool
13242 : 90 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
13243 : : {
13244 : 222 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
13245 : 192 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
13246 : 36 : continue;
13247 : 156 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
13248 : : membertype))
13249 : : {
13250 : 48 : if (TREE_CODE (arg) != INTEGER_CST
13251 : 48 : || tree_int_cst_equal (arg, byte_position (field)))
13252 : 48 : return true;
13253 : : }
13254 : 108 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
13255 : : {
13256 : 18 : tree narg = arg;
13257 : 18 : if (TREE_CODE (basetype) != UNION_TYPE
13258 : 0 : && TREE_CODE (narg) == INTEGER_CST)
13259 : 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
13260 : 18 : if (is_corresponding_member_union (TREE_TYPE (field),
13261 : : membertype, narg))
13262 : : return true;
13263 : : }
13264 : : return false;
13265 : : }
13266 : :
13267 : : /* Helper function for fold_builtin_is_corresponding_member call.
13268 : : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
13269 : : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
13270 : : boolean_true_node if they are corresponding members, or for
13271 : : non-constant ARG2 the highest member offset for corresponding
13272 : : members. */
13273 : :
13274 : : static tree
13275 : 553 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
13276 : : tree arg1, tree basetype2, tree membertype2,
13277 : : tree arg2)
13278 : : {
13279 : 553 : tree field1 = TYPE_FIELDS (basetype1);
13280 : 553 : tree field2 = TYPE_FIELDS (basetype2);
13281 : 553 : tree ret = boolean_false_node;
13282 : 2383 : while (1)
13283 : : {
13284 : 1468 : bool r = next_common_initial_sequence (field1, field2);
13285 : 1468 : if (field1 == NULL_TREE || field2 == NULL_TREE)
13286 : : break;
13287 : 1334 : if (r
13288 : 1041 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
13289 : : membertype1)
13290 : 1847 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
13291 : : membertype2))
13292 : : {
13293 : 507 : tree pos = byte_position (field1);
13294 : 507 : if (TREE_CODE (arg1) == INTEGER_CST
13295 : 507 : && tree_int_cst_equal (arg1, pos))
13296 : : {
13297 : 93 : if (TREE_CODE (arg2) == INTEGER_CST)
13298 : 93 : return boolean_true_node;
13299 : : return pos;
13300 : : }
13301 : 414 : else if (TREE_CODE (arg1) != INTEGER_CST)
13302 : 1190 : ret = pos;
13303 : : }
13304 : 1654 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
13305 : 944 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
13306 : : {
13307 : 117 : if ((!lookup_attribute ("no_unique_address",
13308 : 117 : DECL_ATTRIBUTES (field1)))
13309 : 117 : != !lookup_attribute ("no_unique_address",
13310 : 117 : DECL_ATTRIBUTES (field2)))
13311 : : break;
13312 : 117 : if (!tree_int_cst_equal (bit_position (field1),
13313 : 117 : bit_position (field2)))
13314 : : break;
13315 : 99 : bool overlap = true;
13316 : 99 : tree pos = byte_position (field1);
13317 : 99 : if (TREE_CODE (arg1) == INTEGER_CST)
13318 : : {
13319 : 27 : tree off1 = fold_convert (sizetype, arg1);
13320 : 27 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
13321 : 27 : if (tree_int_cst_lt (off1, pos)
13322 : 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
13323 : : overlap = false;
13324 : : }
13325 : 99 : if (TREE_CODE (arg2) == INTEGER_CST)
13326 : : {
13327 : 27 : tree off2 = fold_convert (sizetype, arg2);
13328 : 27 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
13329 : 27 : if (tree_int_cst_lt (off2, pos)
13330 : 27 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
13331 : : overlap = false;
13332 : : }
13333 : 87 : if (overlap
13334 : 87 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
13335 : 126 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
13336 : : {
13337 : 39 : tree narg1 = arg1;
13338 : 39 : if (TREE_CODE (arg1) == INTEGER_CST)
13339 : 9 : narg1 = size_binop (MINUS_EXPR,
13340 : : fold_convert (sizetype, arg1), pos);
13341 : 39 : tree narg2 = arg2;
13342 : 39 : if (TREE_CODE (arg2) == INTEGER_CST)
13343 : 9 : narg2 = size_binop (MINUS_EXPR,
13344 : : fold_convert (sizetype, arg2), pos);
13345 : 39 : tree t1 = TREE_TYPE (field1);
13346 : 39 : tree t2 = TREE_TYPE (field2);
13347 : 39 : tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
13348 : : narg1, t2, membertype2,
13349 : : narg2);
13350 : 39 : if (nret != boolean_false_node)
13351 : : {
13352 : 39 : if (nret == boolean_true_node)
13353 : : return nret;
13354 : 30 : if (TREE_CODE (arg1) == INTEGER_CST)
13355 : 0 : return size_binop (PLUS_EXPR, nret, pos);
13356 : 30 : ret = size_binop (PLUS_EXPR, nret, pos);
13357 : : }
13358 : : }
13359 : 60 : else if (overlap
13360 : 48 : && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
13361 : 108 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
13362 : : {
13363 : 48 : tree narg1 = arg1;
13364 : 48 : if (TREE_CODE (arg1) == INTEGER_CST)
13365 : 6 : narg1 = size_binop (MINUS_EXPR,
13366 : : fold_convert (sizetype, arg1), pos);
13367 : 48 : tree narg2 = arg2;
13368 : 48 : if (TREE_CODE (arg2) == INTEGER_CST)
13369 : 6 : narg2 = size_binop (MINUS_EXPR,
13370 : : fold_convert (sizetype, arg2), pos);
13371 : 48 : if (is_corresponding_member_union (TREE_TYPE (field1),
13372 : : membertype1, narg1)
13373 : 48 : && is_corresponding_member_union (TREE_TYPE (field2),
13374 : : membertype2, narg2))
13375 : : {
13376 : 24 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
13377 : : "not well defined for anonymous unions");
13378 : 24 : return boolean_false_node;
13379 : : }
13380 : : }
13381 : : }
13382 : 1190 : if (!r)
13383 : : break;
13384 : 915 : field1 = DECL_CHAIN (field1);
13385 : 915 : field2 = DECL_CHAIN (field2);
13386 : 915 : }
13387 : : return ret;
13388 : : }
13389 : :
13390 : : /* Fold __builtin_is_corresponding_member call. */
13391 : :
13392 : : tree
13393 : 705 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
13394 : : tree *args)
13395 : : {
13396 : : /* Unless users call the builtin directly, the following 3 checks should be
13397 : : ensured from std::is_corresponding_member function template. */
13398 : 705 : if (nargs != 2)
13399 : : {
13400 : 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13401 : : "needs two arguments");
13402 : 9 : return boolean_false_node;
13403 : : }
13404 : 696 : tree arg1 = args[0];
13405 : 696 : tree arg2 = args[1];
13406 : 696 : if (error_operand_p (arg1) || error_operand_p (arg2))
13407 : 0 : return boolean_false_node;
13408 : 717 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
13409 : 711 : || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
13410 : : {
13411 : 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13412 : : "argument is not pointer to member");
13413 : 9 : return boolean_false_node;
13414 : : }
13415 : :
13416 : 687 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
13417 : 687 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
13418 : 15 : return boolean_false_node;
13419 : :
13420 : 672 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
13421 : 672 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
13422 : 672 : if (!complete_type_or_else (basetype1, NULL_TREE))
13423 : 12 : return boolean_false_node;
13424 : :
13425 : 660 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
13426 : 660 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
13427 : 660 : if (!complete_type_or_else (basetype2, NULL_TREE))
13428 : 12 : return boolean_false_node;
13429 : :
13430 : 633 : if (!NON_UNION_CLASS_TYPE_P (basetype1)
13431 : 633 : || !NON_UNION_CLASS_TYPE_P (basetype2)
13432 : 633 : || !std_layout_type_p (basetype1)
13433 : 1242 : || !std_layout_type_p (basetype2))
13434 : 54 : return boolean_false_node;
13435 : :
13436 : : /* If the member types aren't layout compatible, then they
13437 : : can't be corresponding members. */
13438 : 594 : if (!layout_compatible_type_p (membertype1, membertype2))
13439 : 18 : return boolean_false_node;
13440 : :
13441 : 576 : if (TREE_CODE (arg1) == PTRMEM_CST)
13442 : 177 : arg1 = cplus_expand_constant (arg1);
13443 : 576 : if (TREE_CODE (arg2) == PTRMEM_CST)
13444 : 183 : arg2 = cplus_expand_constant (arg2);
13445 : :
13446 : 576 : if (null_member_pointer_value_p (arg1)
13447 : 576 : || null_member_pointer_value_p (arg2))
13448 : 9 : return boolean_false_node;
13449 : :
13450 : 567 : if (TREE_CODE (arg1) == INTEGER_CST
13451 : 183 : && TREE_CODE (arg2) == INTEGER_CST
13452 : 750 : && !tree_int_cst_equal (arg1, arg2))
13453 : 53 : return boolean_false_node;
13454 : :
13455 : 514 : if (TREE_CODE (arg2) == INTEGER_CST
13456 : 130 : && TREE_CODE (arg1) != INTEGER_CST)
13457 : : {
13458 : : std::swap (arg1, arg2);
13459 : : std::swap (membertype1, membertype2);
13460 : : std::swap (basetype1, basetype2);
13461 : : }
13462 : :
13463 : 514 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
13464 : : basetype2, membertype2, arg2);
13465 : 514 : if (TREE_TYPE (ret) == boolean_type_node)
13466 : : return ret;
13467 : : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
13468 : : already returns boolean_{true,false}_node whether those particular
13469 : : members are corresponding members or not. Otherwise, if only
13470 : : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
13471 : : above), it returns boolean_false_node if it is certainly not a
13472 : : corresponding member and otherwise we need to do a runtime check that
13473 : : those two OFFSET_TYPE offsets are equal.
13474 : : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
13475 : : returns the largest offset at which the members would be corresponding
13476 : : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
13477 : 306 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
13478 : 306 : if (TREE_CODE (arg1) == INTEGER_CST)
13479 : 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13480 : : fold_convert (TREE_TYPE (arg1), arg2));
13481 : 306 : ret = fold_build2 (LE_EXPR, boolean_type_node,
13482 : : fold_convert (pointer_sized_int_node, arg1),
13483 : : fold_convert (pointer_sized_int_node, ret));
13484 : 306 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
13485 : : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13486 : : fold_convert (TREE_TYPE (arg1), arg2)));
13487 : : }
13488 : :
13489 : : /* [basic.types] 8. True iff TYPE is an object type. */
13490 : :
13491 : : static bool
13492 : 2331062 : object_type_p (const_tree type)
13493 : : {
13494 : 2331062 : return (TREE_CODE (type) != FUNCTION_TYPE
13495 : 0 : && !TYPE_REF_P (type)
13496 : 2331062 : && !VOID_TYPE_P (type));
13497 : : }
13498 : :
13499 : : /* [defns.referenceable] True iff TYPE is a referenceable type. */
13500 : :
13501 : : static bool
13502 : 2642505 : referenceable_type_p (const_tree type)
13503 : : {
13504 : 2642505 : return (TYPE_REF_P (type)
13505 : 2642864 : || object_type_p (type)
13506 : 2642864 : || (FUNC_OR_METHOD_TYPE_P (type)
13507 : 300 : && type_memfn_quals (type) == TYPE_UNQUALIFIED
13508 : 244 : && type_memfn_rqual (type) == REF_QUAL_NONE));
13509 : : }
13510 : :
13511 : : /* Actually evaluates the trait. */
13512 : :
13513 : : static bool
13514 : 12387834 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
13515 : : {
13516 : 12387834 : enum tree_code type_code1;
13517 : 12387834 : tree t;
13518 : :
13519 : 12387834 : type_code1 = TREE_CODE (type1);
13520 : :
13521 : 12387834 : switch (kind)
13522 : : {
13523 : 317 : case CPTK_HAS_NOTHROW_ASSIGN:
13524 : 317 : type1 = strip_array_types (type1);
13525 : 601 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
13526 : 601 : && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
13527 : 173 : || (CLASS_TYPE_P (type1)
13528 : 129 : && classtype_has_nothrow_assign_or_copy_p (type1,
13529 : : true))));
13530 : :
13531 : 215 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
13532 : 215 : type1 = strip_array_types (type1);
13533 : 215 : return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
13534 : 215 : || (CLASS_TYPE_P (type1)
13535 : 93 : && (t = locate_ctor (type1))
13536 : 60 : && maybe_instantiate_noexcept (t)
13537 : 58 : && TYPE_NOTHROW_P (TREE_TYPE (t))));
13538 : :
13539 : 305 : case CPTK_HAS_NOTHROW_COPY:
13540 : 305 : type1 = strip_array_types (type1);
13541 : 305 : return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
13542 : 305 : || (CLASS_TYPE_P (type1)
13543 : 150 : && classtype_has_nothrow_assign_or_copy_p (type1, false)));
13544 : :
13545 : 517 : case CPTK_HAS_TRIVIAL_ASSIGN:
13546 : : /* ??? The standard seems to be missing the "or array of such a class
13547 : : type" wording for this trait. */
13548 : 517 : type1 = strip_array_types (type1);
13549 : 1016 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
13550 : 1001 : && (trivial_type_p (type1)
13551 : 307 : || (CLASS_TYPE_P (type1)
13552 : 222 : && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
13553 : :
13554 : 512 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
13555 : 512 : type1 = strip_array_types (type1);
13556 : 512 : return (trivial_type_p (type1)
13557 : 512 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
13558 : :
13559 : 526 : case CPTK_HAS_TRIVIAL_COPY:
13560 : : /* ??? The standard seems to be missing the "or array of such a class
13561 : : type" wording for this trait. */
13562 : 526 : type1 = strip_array_types (type1);
13563 : 878 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
13564 : 863 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
13565 : :
13566 : 785 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
13567 : 785 : type1 = strip_array_types (type1);
13568 : 785 : if (CLASS_TYPE_P (type1) && type_build_dtor_call (type1))
13569 : : {
13570 : 123 : deferring_access_check_sentinel dacs (dk_no_check);
13571 : 123 : cp_unevaluated un;
13572 : 123 : tree fn = get_dtor (type1, tf_none);
13573 : 123 : if (!fn && !seen_error ())
13574 : 3 : warning (0, "checking %qs for type %qT with a destructor that "
13575 : : "cannot be called", "__has_trivial_destructor", type1);
13576 : 123 : }
13577 : 1122 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
13578 : 1119 : || (CLASS_TYPE_P (type1)
13579 : 290 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
13580 : :
13581 : 23554 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
13582 : 23554 : return type_has_unique_obj_representations (type1);
13583 : :
13584 : 279 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
13585 : 279 : return type_has_virtual_destructor (type1);
13586 : :
13587 : 59103 : case CPTK_IS_ABSTRACT:
13588 : 59103 : return ABSTRACT_CLASS_TYPE_P (type1);
13589 : :
13590 : 813 : case CPTK_IS_AGGREGATE:
13591 : 813 : return CP_AGGREGATE_TYPE_P (type1);
13592 : :
13593 : 277918 : case CPTK_IS_ARRAY:
13594 : 277918 : return (type_code1 == ARRAY_TYPE
13595 : : /* We don't want to report T[0] as being an array type.
13596 : : This is for compatibility with an implementation of
13597 : : std::is_array by template argument deduction, because
13598 : : compute_array_index_type_loc rejects a zero-size array
13599 : : in SFINAE context. */
13600 : 277918 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
13601 : :
13602 : 741814 : case CPTK_IS_ASSIGNABLE:
13603 : 741814 : return is_xible (MODIFY_EXPR, type1, type2);
13604 : :
13605 : 252590 : case CPTK_IS_BASE_OF:
13606 : 252493 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
13607 : 484718 : && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
13608 : 218457 : || DERIVED_FROM_P (type1, type2)));
13609 : :
13610 : 34407 : case CPTK_IS_BOUNDED_ARRAY:
13611 : 34407 : return (type_code1 == ARRAY_TYPE
13612 : 1339 : && TYPE_DOMAIN (type1)
13613 : : /* We don't want to report T[0] as being a bounded array type.
13614 : : This is for compatibility with an implementation of
13615 : : std::is_bounded_array by template argument deduction, because
13616 : : compute_array_index_type_loc rejects a zero-size array
13617 : : in SFINAE context. */
13618 : 35610 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
13619 : :
13620 : 333186 : case CPTK_IS_CLASS:
13621 : 333186 : return NON_UNION_CLASS_TYPE_P (type1);
13622 : :
13623 : 334933 : case CPTK_IS_CONST:
13624 : 334933 : return CP_TYPE_CONST_P (type1);
13625 : :
13626 : 1561395 : case CPTK_IS_CONSTRUCTIBLE:
13627 : 1561395 : return is_xible (INIT_EXPR, type1, type2);
13628 : :
13629 : 1689462 : case CPTK_IS_CONVERTIBLE:
13630 : 1689462 : return is_convertible (type1, type2);
13631 : :
13632 : 1068 : case CPTK_IS_DESTRUCTIBLE:
13633 : 1068 : return is_xible (BIT_NOT_EXPR, type1, NULL_TREE);
13634 : :
13635 : 230826 : case CPTK_IS_EMPTY:
13636 : 230826 : return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
13637 : :
13638 : 465621 : case CPTK_IS_ENUM:
13639 : 465621 : return type_code1 == ENUMERAL_TYPE;
13640 : :
13641 : 414445 : case CPTK_IS_FINAL:
13642 : 414445 : return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
13643 : :
13644 : 36435 : case CPTK_IS_FUNCTION:
13645 : 36435 : return type_code1 == FUNCTION_TYPE;
13646 : :
13647 : 640 : case CPTK_IS_IMPLICIT_LIFETIME:
13648 : 640 : return implicit_lifetime_type_p (type1);
13649 : :
13650 : 50928 : case CPTK_IS_INVOCABLE:
13651 : 50928 : return !error_operand_p (build_invoke (type1, type2, tf_none));
13652 : :
13653 : 213 : case CPTK_IS_LAYOUT_COMPATIBLE:
13654 : 213 : return layout_compatible_type_p (type1, type2);
13655 : :
13656 : 211 : case CPTK_IS_LITERAL_TYPE:
13657 : 211 : return literal_type_p (type1);
13658 : :
13659 : 50034 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
13660 : 50034 : return TYPE_PTRMEMFUNC_P (type1);
13661 : :
13662 : 49917 : case CPTK_IS_MEMBER_OBJECT_POINTER:
13663 : 49917 : return TYPE_PTRDATAMEM_P (type1);
13664 : :
13665 : 11109 : case CPTK_IS_MEMBER_POINTER:
13666 : 11109 : return TYPE_PTRMEM_P (type1);
13667 : :
13668 : 333879 : case CPTK_IS_NOTHROW_ASSIGNABLE:
13669 : 333879 : return is_nothrow_xible (MODIFY_EXPR, type1, type2);
13670 : :
13671 : 672405 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
13672 : 672405 : return is_nothrow_xible (INIT_EXPR, type1, type2);
13673 : :
13674 : 752 : case CPTK_IS_NOTHROW_CONVERTIBLE:
13675 : 752 : return is_nothrow_convertible (type1, type2);
13676 : :
13677 : 24446 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
13678 : 24446 : return is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE);
13679 : :
13680 : 43706 : case CPTK_IS_NOTHROW_INVOCABLE:
13681 : 43706 : return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
13682 : :
13683 : 890765 : case CPTK_IS_OBJECT:
13684 : 890765 : return object_type_p (type1);
13685 : :
13686 : 145 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
13687 : 145 : return pointer_interconvertible_base_of_p (type1, type2);
13688 : :
13689 : 11840 : case CPTK_IS_POD:
13690 : 11840 : return pod_type_p (type1);
13691 : :
13692 : 109528 : case CPTK_IS_POINTER:
13693 : 109528 : return TYPE_PTR_P (type1);
13694 : :
13695 : 267 : case CPTK_IS_POLYMORPHIC:
13696 : 267 : return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
13697 : :
13698 : 352434 : case CPTK_IS_REFERENCE:
13699 : 352434 : return type_code1 == REFERENCE_TYPE;
13700 : :
13701 : 2463824 : case CPTK_IS_SAME:
13702 : 2463824 : return same_type_p (type1, type2);
13703 : :
13704 : 373 : case CPTK_IS_SCOPED_ENUM:
13705 : 373 : return SCOPED_ENUM_P (type1);
13706 : :
13707 : 51533 : case CPTK_IS_STD_LAYOUT:
13708 : 51533 : return std_layout_type_p (type1);
13709 : :
13710 : 34632 : case CPTK_IS_TRIVIAL:
13711 : 34632 : return trivial_type_p (type1);
13712 : :
13713 : 7442 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
13714 : 7442 : return is_trivially_xible (MODIFY_EXPR, type1, type2);
13715 : :
13716 : 59096 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
13717 : 59096 : return is_trivially_xible (INIT_EXPR, type1, type2);
13718 : :
13719 : 70479 : case CPTK_IS_TRIVIALLY_COPYABLE:
13720 : 70479 : return trivially_copyable_p (type1);
13721 : :
13722 : 25243 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
13723 : 25243 : return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE);
13724 : :
13725 : 32462 : case CPTK_IS_UNBOUNDED_ARRAY:
13726 : 32462 : return array_of_unknown_bound_p (type1);
13727 : :
13728 : 117490 : case CPTK_IS_UNION:
13729 : 117490 : return type_code1 == UNION_TYPE;
13730 : :
13731 : 693 : case CPTK_IS_VIRTUAL_BASE_OF:
13732 : 627 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
13733 : 1305 : && lookup_base (type2, type1, ba_require_virtual,
13734 : : NULL, tf_none) != NULL_TREE);
13735 : :
13736 : 333186 : case CPTK_IS_VOLATILE:
13737 : 333186 : return CP_TYPE_VOLATILE_P (type1);
13738 : :
13739 : 71355 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
13740 : 71355 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
13741 : :
13742 : 55702 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
13743 : 55702 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
13744 : :
13745 : 79 : case CPTK_IS_DEDUCIBLE:
13746 : 79 : return type_targs_deducible_from (type1, type2);
13747 : :
13748 : : /* __array_rank, __builtin_type_order and __builtin_structured_binding_size
13749 : : are handled in finish_trait_expr. */
13750 : 0 : case CPTK_RANK:
13751 : 0 : case CPTK_TYPE_ORDER:
13752 : 0 : case CPTK_STRUCTURED_BINDING_SIZE:
13753 : 0 : gcc_unreachable ();
13754 : :
13755 : : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
13756 : : case CPTK_##CODE:
13757 : : #include "cp-trait.def"
13758 : : #undef DEFTRAIT_TYPE
13759 : : /* Type-yielding traits are handled in finish_trait_type. */
13760 : : break;
13761 : : }
13762 : :
13763 : 0 : gcc_unreachable ();
13764 : : }
13765 : :
13766 : : /* Returns true if TYPE meets the requirements for the specified KIND,
13767 : : false otherwise.
13768 : :
13769 : : When KIND == 1, TYPE must be an array of unknown bound,
13770 : : or (possibly cv-qualified) void, or a complete type.
13771 : :
13772 : : When KIND == 2, TYPE must be a complete type, or array of complete type,
13773 : : or (possibly cv-qualified) void.
13774 : :
13775 : : When KIND == 3:
13776 : : If TYPE is a non-union class type, it must be complete.
13777 : :
13778 : : When KIND == 4:
13779 : : If TYPE is a class type, it must be complete. */
13780 : :
13781 : : static bool
13782 : 12567888 : check_trait_type (tree type, int kind = 1)
13783 : : {
13784 : 12567888 : if (type == NULL_TREE)
13785 : : return true;
13786 : :
13787 : 12567888 : if (TREE_CODE (type) == TREE_VEC)
13788 : : {
13789 : 4154397 : for (tree arg : tree_vec_range (type))
13790 : 1770095 : if (!check_trait_type (arg, kind))
13791 : 21 : return false;
13792 : 2384302 : return true;
13793 : : }
13794 : :
13795 : 10183565 : if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
13796 : : return true; // Array of unknown bound. Don't care about completeness.
13797 : :
13798 : 10183052 : if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
13799 : : return true; // Not a non-union class type. Don't care about completeness.
13800 : :
13801 : 10077053 : if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
13802 : : return true; // Not a class type. Don't care about completeness.
13803 : :
13804 : 10076560 : if (VOID_TYPE_P (type))
13805 : : return true;
13806 : :
13807 : 10075462 : type = complete_type (strip_array_types (type));
13808 : 10075462 : if (!COMPLETE_TYPE_P (type)
13809 : 152 : && cxx_incomplete_type_diagnostic (NULL_TREE, type,
13810 : : diagnostics::kind::permerror)
13811 : 10075614 : && !flag_permissive)
13812 : : return false;
13813 : : return true;
13814 : : }
13815 : :
13816 : : /* True iff the conversion (if any) would be a direct reference
13817 : : binding, not requiring complete types. This is LWG2939. */
13818 : :
13819 : : static bool
13820 : 4204861 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
13821 : : {
13822 : 4204861 : tree from, to;
13823 : 4204861 : switch (kind)
13824 : : {
13825 : : /* These put the target type first. */
13826 : : case CPTK_IS_CONSTRUCTIBLE:
13827 : : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
13828 : : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
13829 : : case CPTK_IS_INVOCABLE:
13830 : : case CPTK_IS_NOTHROW_INVOCABLE:
13831 : : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
13832 : : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
13833 : : to = type1;
13834 : : from = type2;
13835 : : break;
13836 : :
13837 : : /* These put it second. */
13838 : 1690214 : case CPTK_IS_CONVERTIBLE:
13839 : 1690214 : case CPTK_IS_NOTHROW_CONVERTIBLE:
13840 : 1690214 : to = type2;
13841 : 1690214 : from = type1;
13842 : 1690214 : break;
13843 : :
13844 : 0 : default:
13845 : 0 : gcc_unreachable ();
13846 : : }
13847 : :
13848 : 4204861 : if (TREE_CODE (to) != REFERENCE_TYPE || !from)
13849 : : return false;
13850 : 435672 : if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
13851 : 63553 : from = TREE_VEC_ELT (from, 0);
13852 : 435672 : return (TYPE_P (from)
13853 : 862203 : && (same_type_ignoring_top_level_qualifiers_p
13854 : 426531 : (non_reference (to), non_reference (from))));
13855 : : }
13856 : :
13857 : : /* Helper for finish_trait_expr and tsubst_expr. Handle
13858 : : CPTK_STRUCTURED_BINDING_SIZE in possibly SFINAE-friendly
13859 : : way. */
13860 : :
13861 : : tree
13862 : 261 : finish_structured_binding_size (location_t loc, tree type,
13863 : : tsubst_flags_t complain)
13864 : : {
13865 : 261 : if (TYPE_REF_P (type))
13866 : : {
13867 : 105 : if (complain & tf_error)
13868 : 99 : error_at (loc, "%qs argument %qT is a reference",
13869 : : "__builtin_structured_binding_size", type);
13870 : 105 : return error_mark_node;
13871 : : }
13872 : 156 : HOST_WIDE_INT ret = cp_decomp_size (loc, type, complain);
13873 : 156 : if (ret == -1)
13874 : 57 : return error_mark_node;
13875 : 99 : return maybe_wrap_with_location (build_int_cst (size_type_node, ret), loc);
13876 : : }
13877 : :
13878 : : /* Process a trait expression. */
13879 : :
13880 : : tree
13881 : 15555551 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
13882 : : {
13883 : 15555551 : if (type1 == error_mark_node
13884 : 15555548 : || type2 == error_mark_node)
13885 : : return error_mark_node;
13886 : :
13887 : 15555548 : if (processing_template_decl)
13888 : : {
13889 : 3168052 : tree trait_expr = make_node (TRAIT_EXPR);
13890 : 3168052 : if (kind == CPTK_RANK || kind == CPTK_STRUCTURED_BINDING_SIZE)
13891 : 30209 : TREE_TYPE (trait_expr) = size_type_node;
13892 : 3137843 : else if (kind == CPTK_TYPE_ORDER)
13893 : : {
13894 : 4042 : tree val = type_order_value (type1, type1);
13895 : 4042 : if (val != error_mark_node)
13896 : 4042 : TREE_TYPE (trait_expr) = TREE_TYPE (val);
13897 : : }
13898 : : else
13899 : 3133801 : TREE_TYPE (trait_expr) = boolean_type_node;
13900 : 3168052 : TRAIT_EXPR_TYPE1 (trait_expr) = type1;
13901 : 3168052 : TRAIT_EXPR_TYPE2 (trait_expr) = type2;
13902 : 3168052 : TRAIT_EXPR_KIND (trait_expr) = kind;
13903 : 3168052 : TRAIT_EXPR_LOCATION (trait_expr) = loc;
13904 : 3168052 : return trait_expr;
13905 : : }
13906 : :
13907 : 12387496 : switch (kind)
13908 : : {
13909 : 53151 : case CPTK_HAS_NOTHROW_ASSIGN:
13910 : 53151 : case CPTK_HAS_TRIVIAL_ASSIGN:
13911 : 53151 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
13912 : 53151 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
13913 : 53151 : case CPTK_HAS_NOTHROW_COPY:
13914 : 53151 : case CPTK_HAS_TRIVIAL_COPY:
13915 : 53151 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
13916 : 53151 : case CPTK_IS_DESTRUCTIBLE:
13917 : 53151 : case CPTK_IS_NOTHROW_DESTRUCTIBLE:
13918 : 53151 : case CPTK_IS_TRIVIALLY_DESTRUCTIBLE:
13919 : 53151 : if (!check_trait_type (type1))
13920 : 21 : return error_mark_node;
13921 : : break;
13922 : :
13923 : 192282 : case CPTK_IS_LITERAL_TYPE:
13924 : 192282 : case CPTK_IS_POD:
13925 : 192282 : case CPTK_IS_STD_LAYOUT:
13926 : 192282 : case CPTK_IS_TRIVIAL:
13927 : 192282 : case CPTK_IS_TRIVIALLY_COPYABLE:
13928 : 192282 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
13929 : 192282 : if (!check_trait_type (type1, /* kind = */ 2))
13930 : 33 : return error_mark_node;
13931 : : break;
13932 : :
13933 : 290490 : case CPTK_IS_ABSTRACT:
13934 : 290490 : case CPTK_IS_EMPTY:
13935 : 290490 : case CPTK_IS_POLYMORPHIC:
13936 : 290490 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
13937 : 290490 : if (!check_trait_type (type1, /* kind = */ 3))
13938 : 15 : return error_mark_node;
13939 : : break;
13940 : :
13941 : : /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
13942 : : type to know whether an array is an aggregate, so use kind=4 here. */
13943 : 415915 : case CPTK_IS_AGGREGATE:
13944 : 415915 : case CPTK_IS_FINAL:
13945 : 415915 : case CPTK_IS_IMPLICIT_LIFETIME:
13946 : 415915 : if (!check_trait_type (type1, /* kind = */ 4))
13947 : 17 : return error_mark_node;
13948 : : break;
13949 : :
13950 : 4204861 : case CPTK_IS_CONSTRUCTIBLE:
13951 : 4204861 : case CPTK_IS_CONVERTIBLE:
13952 : 4204861 : case CPTK_IS_INVOCABLE:
13953 : 4204861 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
13954 : 4204861 : case CPTK_IS_NOTHROW_CONVERTIBLE:
13955 : 4204861 : case CPTK_IS_NOTHROW_INVOCABLE:
13956 : 4204861 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
13957 : 4204861 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
13958 : 4204861 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
13959 : 4204861 : /* Don't check completeness for direct reference binding. */;
13960 : 4204861 : if (same_type_ref_bind_p (kind, type1, type2))
13961 : : break;
13962 : 4922997 : gcc_fallthrough ();
13963 : :
13964 : 4922997 : case CPTK_IS_ASSIGNABLE:
13965 : 4922997 : case CPTK_IS_NOTHROW_ASSIGNABLE:
13966 : 4922997 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
13967 : 4922997 : if (!check_trait_type (type1)
13968 : 4922997 : || !check_trait_type (type2))
13969 : 63 : return error_mark_node;
13970 : : break;
13971 : :
13972 : 252738 : case CPTK_IS_BASE_OF:
13973 : 252738 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
13974 : 252627 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
13975 : 232259 : && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
13976 : 471295 : && !complete_type_or_else (type2, NULL_TREE))
13977 : : /* We already issued an error. */
13978 : 3 : return error_mark_node;
13979 : : break;
13980 : :
13981 : 696 : case CPTK_IS_VIRTUAL_BASE_OF:
13982 : 630 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
13983 : 1311 : && !complete_type_or_else (type2, NULL_TREE))
13984 : : /* We already issued an error. */
13985 : 3 : return error_mark_node;
13986 : : break;
13987 : :
13988 : : case CPTK_IS_ARRAY:
13989 : : case CPTK_IS_BOUNDED_ARRAY:
13990 : : case CPTK_IS_CLASS:
13991 : : case CPTK_IS_CONST:
13992 : : case CPTK_IS_ENUM:
13993 : : case CPTK_IS_FUNCTION:
13994 : : case CPTK_IS_MEMBER_FUNCTION_POINTER:
13995 : : case CPTK_IS_MEMBER_OBJECT_POINTER:
13996 : : case CPTK_IS_MEMBER_POINTER:
13997 : : case CPTK_IS_OBJECT:
13998 : : case CPTK_IS_POINTER:
13999 : : case CPTK_IS_REFERENCE:
14000 : : case CPTK_IS_SAME:
14001 : : case CPTK_IS_SCOPED_ENUM:
14002 : : case CPTK_IS_UNBOUNDED_ARRAY:
14003 : : case CPTK_IS_UNION:
14004 : : case CPTK_IS_VOLATILE:
14005 : : break;
14006 : :
14007 : : case CPTK_RANK:
14008 : : {
14009 : : size_t rank = 0;
14010 : 122 : for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
14011 : 80 : ++rank;
14012 : 42 : return maybe_wrap_with_location (build_int_cst (size_type_node, rank),
14013 : : loc);
14014 : : }
14015 : :
14016 : 122 : case CPTK_TYPE_ORDER:
14017 : 122 : return maybe_wrap_with_location (type_order_value (type1, type2), loc);
14018 : :
14019 : 138 : case CPTK_STRUCTURED_BINDING_SIZE:
14020 : 138 : return finish_structured_binding_size (loc, type1, tf_warning_or_error);
14021 : :
14022 : 222 : case CPTK_IS_LAYOUT_COMPATIBLE:
14023 : 222 : if (!array_of_unknown_bound_p (type1)
14024 : 205 : && TREE_CODE (type1) != VOID_TYPE
14025 : 420 : && !complete_type_or_else (type1, NULL_TREE))
14026 : : /* We already issued an error. */
14027 : 6 : return error_mark_node;
14028 : 216 : if (!array_of_unknown_bound_p (type2)
14029 : 191 : && TREE_CODE (type2) != VOID_TYPE
14030 : 400 : && !complete_type_or_else (type2, NULL_TREE))
14031 : : /* We already issued an error. */
14032 : 3 : return error_mark_node;
14033 : : break;
14034 : :
14035 : 79 : case CPTK_IS_DEDUCIBLE:
14036 : 79 : if (!DECL_TYPE_TEMPLATE_P (type1))
14037 : : {
14038 : 0 : error ("%qD is not a class or alias template", type1);
14039 : 0 : return error_mark_node;
14040 : : }
14041 : : break;
14042 : :
14043 : : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
14044 : : case CPTK_##CODE:
14045 : : #include "cp-trait.def"
14046 : : #undef DEFTRAIT_TYPE
14047 : : /* Type-yielding traits are handled in finish_trait_type. */
14048 : 0 : gcc_unreachable ();
14049 : : }
14050 : :
14051 : 12387030 : tree val = (trait_expr_value (kind, type1, type2)
14052 : 12387030 : ? boolean_true_node : boolean_false_node);
14053 : 12387030 : return maybe_wrap_with_location (val, loc);
14054 : : }
14055 : :
14056 : : /* Process a trait type. */
14057 : :
14058 : : tree
14059 : 5728512 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
14060 : : tsubst_flags_t complain)
14061 : : {
14062 : 5728512 : if (type1 == error_mark_node
14063 : 5728509 : || type2 == error_mark_node)
14064 : : return error_mark_node;
14065 : :
14066 : 5728509 : if (processing_template_decl)
14067 : : {
14068 : 213774 : tree type = cxx_make_type (TRAIT_TYPE);
14069 : 213774 : TRAIT_TYPE_TYPE1 (type) = type1;
14070 : 213774 : TRAIT_TYPE_TYPE2 (type) = type2;
14071 : 213774 : TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
14072 : : /* These traits are intended to be used in the definition of the ::type
14073 : : member of the corresponding standard library type trait and aren't
14074 : : mangleable (and thus won't appear directly in template signatures),
14075 : : so structural equality should suffice. */
14076 : 213774 : SET_TYPE_STRUCTURAL_EQUALITY (type);
14077 : 213774 : return type;
14078 : : }
14079 : :
14080 : 5514735 : switch (kind)
14081 : : {
14082 : 1041179 : case CPTK_ADD_LVALUE_REFERENCE:
14083 : : /* [meta.trans.ref]. */
14084 : 1041179 : if (referenceable_type_p (type1))
14085 : 1041106 : return cp_build_reference_type (type1, /*rval=*/false);
14086 : : return type1;
14087 : :
14088 : 311675 : case CPTK_ADD_POINTER:
14089 : : /* [meta.trans.ptr]. */
14090 : 311675 : if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
14091 : : {
14092 : 311643 : if (TYPE_REF_P (type1))
14093 : 310524 : type1 = TREE_TYPE (type1);
14094 : 311643 : return build_pointer_type (type1);
14095 : : }
14096 : : return type1;
14097 : :
14098 : 1289667 : case CPTK_ADD_RVALUE_REFERENCE:
14099 : : /* [meta.trans.ref]. */
14100 : 1289667 : if (referenceable_type_p (type1))
14101 : 1289621 : return cp_build_reference_type (type1, /*rval=*/true);
14102 : : return type1;
14103 : :
14104 : 167126 : case CPTK_DECAY:
14105 : 167126 : if (TYPE_REF_P (type1))
14106 : 30346 : type1 = TREE_TYPE (type1);
14107 : :
14108 : 167126 : if (TREE_CODE (type1) == ARRAY_TYPE)
14109 : 718 : return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
14110 : 718 : complain);
14111 : 166408 : else if (TREE_CODE (type1) == FUNCTION_TYPE)
14112 : 162 : return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
14113 : : else
14114 : 166246 : return cv_unqualified (type1);
14115 : :
14116 : 262 : case CPTK_REMOVE_ALL_EXTENTS:
14117 : 262 : return strip_array_types (type1);
14118 : :
14119 : 731288 : case CPTK_REMOVE_CV:
14120 : 731288 : return cv_unqualified (type1);
14121 : :
14122 : 262886 : case CPTK_REMOVE_CVREF:
14123 : 262886 : if (TYPE_REF_P (type1))
14124 : 113753 : type1 = TREE_TYPE (type1);
14125 : 262886 : return cv_unqualified (type1);
14126 : :
14127 : 55373 : case CPTK_REMOVE_EXTENT:
14128 : 55373 : if (TREE_CODE (type1) == ARRAY_TYPE)
14129 : 2769 : type1 = TREE_TYPE (type1);
14130 : : return type1;
14131 : :
14132 : 18349 : case CPTK_REMOVE_POINTER:
14133 : 18349 : if (TYPE_PTR_P (type1))
14134 : 15278 : type1 = TREE_TYPE (type1);
14135 : : return type1;
14136 : :
14137 : 1500101 : case CPTK_REMOVE_REFERENCE:
14138 : 1500101 : if (TYPE_REF_P (type1))
14139 : 906865 : type1 = TREE_TYPE (type1);
14140 : : return type1;
14141 : :
14142 : 92829 : case CPTK_TYPE_PACK_ELEMENT:
14143 : 92829 : return finish_type_pack_element (type1, type2, complain);
14144 : :
14145 : 44000 : case CPTK_UNDERLYING_TYPE:
14146 : 44000 : return finish_underlying_type (type1);
14147 : :
14148 : : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
14149 : : case CPTK_##CODE:
14150 : : #include "cp-trait.def"
14151 : : #undef DEFTRAIT_EXPR
14152 : : /* Expression-yielding traits are handled in finish_trait_expr. */
14153 : : case CPTK_BASES:
14154 : : case CPTK_DIRECT_BASES:
14155 : : /* BASES and DIRECT_BASES are handled in finish_bases. */
14156 : : break;
14157 : : }
14158 : :
14159 : 0 : gcc_unreachable ();
14160 : : }
14161 : :
14162 : : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
14163 : : which is ignored for C++. */
14164 : :
14165 : : void
14166 : 0 : set_float_const_decimal64 (void)
14167 : : {
14168 : 0 : }
14169 : :
14170 : : void
14171 : 0 : clear_float_const_decimal64 (void)
14172 : : {
14173 : 0 : }
14174 : :
14175 : : bool
14176 : 1982366 : float_const_decimal64_p (void)
14177 : : {
14178 : 1982366 : return 0;
14179 : : }
14180 : :
14181 : :
14182 : : /* Return true if T designates the implied `this' parameter. */
14183 : :
14184 : : bool
14185 : 4483656 : is_this_parameter (tree t)
14186 : : {
14187 : 4483656 : if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
14188 : : return false;
14189 : 2933202 : gcc_assert (TREE_CODE (t) == PARM_DECL
14190 : : || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
14191 : : || (cp_binding_oracle && VAR_P (t)));
14192 : : return true;
14193 : : }
14194 : :
14195 : : /* As above, or a C++23 explicit object parameter. */
14196 : :
14197 : : bool
14198 : 456 : is_object_parameter (tree t)
14199 : : {
14200 : 456 : if (is_this_parameter (t))
14201 : : return true;
14202 : 91 : if (TREE_CODE (t) != PARM_DECL)
14203 : : return false;
14204 : 34 : tree ctx = DECL_CONTEXT (t);
14205 : 34 : return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
14206 : 62 : && t == DECL_ARGUMENTS (ctx));
14207 : : }
14208 : :
14209 : : /* Insert the deduced return type for an auto function. */
14210 : :
14211 : : void
14212 : 921804 : apply_deduced_return_type (tree fco, tree return_type)
14213 : : {
14214 : 921804 : tree result;
14215 : :
14216 : 921804 : if (return_type == error_mark_node)
14217 : : return;
14218 : :
14219 : 921801 : if (DECL_CONV_FN_P (fco))
14220 : 42 : DECL_NAME (fco) = make_conv_op_name (return_type);
14221 : :
14222 : 921801 : TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
14223 : :
14224 : 921801 : maybe_update_postconditions (fco);
14225 : :
14226 : : /* Apply the type to the result object. */
14227 : :
14228 : 921801 : result = DECL_RESULT (fco);
14229 : 921801 : if (result == NULL_TREE)
14230 : : return;
14231 : 919063 : if (TREE_TYPE (result) == return_type)
14232 : : return;
14233 : :
14234 : 919057 : if (!processing_template_decl && !VOID_TYPE_P (return_type)
14235 : 1569469 : && !complete_type_or_else (return_type, NULL_TREE))
14236 : : return;
14237 : :
14238 : : /* We already have a DECL_RESULT from start_preparsed_function.
14239 : : Now we need to redo the work it and allocate_struct_function
14240 : : did to reflect the new type. */
14241 : 919060 : result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
14242 : 919060 : TYPE_MAIN_VARIANT (return_type));
14243 : 919060 : DECL_ARTIFICIAL (result) = 1;
14244 : 919060 : DECL_IGNORED_P (result) = 1;
14245 : 919060 : cp_apply_type_quals_to_decl (cp_type_quals (return_type),
14246 : : result);
14247 : 919060 : DECL_RESULT (fco) = result;
14248 : :
14249 : 919060 : if (!uses_template_parms (fco))
14250 : 919060 : if (function *fun = DECL_STRUCT_FUNCTION (fco))
14251 : : {
14252 : 918931 : bool aggr = aggregate_value_p (result, fco);
14253 : : #ifdef PCC_STATIC_STRUCT_RETURN
14254 : : fun->returns_pcc_struct = aggr;
14255 : : #endif
14256 : 918931 : fun->returns_struct = aggr;
14257 : : }
14258 : : }
14259 : :
14260 : : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
14261 : : this is a right unary fold. Otherwise it is a left unary fold. */
14262 : :
14263 : : static tree
14264 : 683665 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
14265 : : {
14266 : : /* Build a pack expansion (assuming expr has pack type). */
14267 : 683665 : if (!uses_parameter_packs (expr))
14268 : : {
14269 : 3 : error_at (location_of (expr), "operand of fold expression has no "
14270 : : "unexpanded parameter packs");
14271 : 3 : return error_mark_node;
14272 : : }
14273 : 683662 : tree pack = make_pack_expansion (expr);
14274 : :
14275 : : /* Build the fold expression. */
14276 : 683662 : tree code = build_int_cstu (integer_type_node, abs (op));
14277 : 683662 : tree fold = build_min_nt_loc (loc, dir, code, pack);
14278 : 683662 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14279 : 683662 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14280 : 683662 : FOLD_EXPR_OP (fold),
14281 : 683662 : FOLD_EXPR_MODIFY_P (fold));
14282 : 683662 : return fold;
14283 : : }
14284 : :
14285 : : tree
14286 : 38167 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
14287 : : {
14288 : 38167 : return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
14289 : : }
14290 : :
14291 : : tree
14292 : 645498 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
14293 : : {
14294 : 645498 : return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
14295 : : }
14296 : :
14297 : : /* Build a binary fold expression over EXPR1 and EXPR2. The
14298 : : associativity of the fold is determined by EXPR1 and EXPR2 (whichever
14299 : : has an unexpanded parameter pack). */
14300 : :
14301 : : static tree
14302 : 21538 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
14303 : : int op, tree_code dir)
14304 : : {
14305 : 21538 : pack = make_pack_expansion (pack);
14306 : 21538 : tree code = build_int_cstu (integer_type_node, abs (op));
14307 : 21538 : tree fold = build_min_nt_loc (loc, dir, code, pack, init);
14308 : 21538 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
14309 : 21538 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
14310 : 21538 : FOLD_EXPR_OP (fold),
14311 : 21538 : FOLD_EXPR_MODIFY_P (fold));
14312 : 21538 : return fold;
14313 : : }
14314 : :
14315 : : tree
14316 : 21538 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
14317 : : {
14318 : : // Determine which expr has an unexpanded parameter pack and
14319 : : // set the pack and initial term.
14320 : 21538 : bool pack1 = uses_parameter_packs (expr1);
14321 : 21538 : bool pack2 = uses_parameter_packs (expr2);
14322 : 21538 : if (pack1 && !pack2)
14323 : 1626 : return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
14324 : 19912 : else if (pack2 && !pack1)
14325 : 19912 : return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
14326 : : else
14327 : : {
14328 : 0 : if (pack1)
14329 : 0 : error ("both arguments in binary fold have unexpanded parameter packs");
14330 : : else
14331 : 0 : error ("no unexpanded parameter packs in binary fold");
14332 : : }
14333 : 0 : return error_mark_node;
14334 : : }
14335 : :
14336 : : /* Finish __builtin_launder (arg). */
14337 : :
14338 : : tree
14339 : 13172 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
14340 : : {
14341 : 13172 : tree orig_arg = arg;
14342 : 13172 : if (!type_dependent_expression_p (arg))
14343 : 84 : arg = decay_conversion (arg, complain);
14344 : 13172 : if (error_operand_p (arg))
14345 : 0 : return error_mark_node;
14346 : 13172 : if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
14347 : : {
14348 : 24 : error_at (loc, "type %qT of argument to %<__builtin_launder%> "
14349 : 24 : "is not a pointer to object type", TREE_TYPE (arg));
14350 : 24 : return error_mark_node;
14351 : : }
14352 : 13148 : if (processing_template_decl)
14353 : 13088 : arg = orig_arg;
14354 : 13148 : return build_call_expr_internal_loc (loc, IFN_LAUNDER,
14355 : 26296 : TREE_TYPE (arg), 1, arg);
14356 : : }
14357 : :
14358 : : /* Finish __builtin_convertvector (arg, type). */
14359 : :
14360 : : tree
14361 : 185 : cp_build_vec_convert (tree arg, location_t loc, tree type,
14362 : : tsubst_flags_t complain)
14363 : : {
14364 : 185 : if (error_operand_p (type))
14365 : 9 : return error_mark_node;
14366 : 176 : if (error_operand_p (arg))
14367 : 0 : return error_mark_node;
14368 : :
14369 : 176 : tree ret = NULL_TREE;
14370 : 176 : if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
14371 : 194 : ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
14372 : : decay_conversion (arg, complain),
14373 : : loc, type, (complain & tf_error) != 0);
14374 : :
14375 : 176 : if (!processing_template_decl)
14376 : : return ret;
14377 : :
14378 : 24 : return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
14379 : : }
14380 : :
14381 : : /* Finish __builtin_bit_cast (type, arg). */
14382 : :
14383 : : tree
14384 : 86515 : cp_build_bit_cast (location_t loc, tree type, tree arg,
14385 : : tsubst_flags_t complain)
14386 : : {
14387 : 86515 : if (error_operand_p (type))
14388 : 0 : return error_mark_node;
14389 : 86515 : if (!dependent_type_p (type))
14390 : : {
14391 : 65329 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
14392 : 9 : return error_mark_node;
14393 : 65320 : if (TREE_CODE (type) == ARRAY_TYPE)
14394 : : {
14395 : : /* std::bit_cast for destination ARRAY_TYPE is not possible,
14396 : : as functions may not return an array, so don't bother trying
14397 : : to support this (and then deal with VLAs etc.). */
14398 : 9 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14399 : : "is an array type", type);
14400 : 9 : return error_mark_node;
14401 : : }
14402 : 65311 : if (!trivially_copyable_p (type))
14403 : : {
14404 : 18 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14405 : : "is not trivially copyable", type);
14406 : 18 : return error_mark_node;
14407 : : }
14408 : : }
14409 : :
14410 : 86479 : if (error_operand_p (arg))
14411 : 0 : return error_mark_node;
14412 : :
14413 : 86479 : if (!type_dependent_expression_p (arg))
14414 : : {
14415 : 21741 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
14416 : : {
14417 : : /* Don't perform array-to-pointer conversion. */
14418 : 26 : arg = mark_rvalue_use (arg, loc, true);
14419 : 26 : if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
14420 : 0 : return error_mark_node;
14421 : : }
14422 : : else
14423 : 21715 : arg = decay_conversion (arg, complain);
14424 : :
14425 : 21741 : if (error_operand_p (arg))
14426 : 12 : return error_mark_node;
14427 : :
14428 : 21729 : if (!trivially_copyable_p (TREE_TYPE (arg)))
14429 : : {
14430 : 9 : error_at (cp_expr_loc_or_loc (arg, loc),
14431 : : "%<__builtin_bit_cast%> source type %qT "
14432 : 9 : "is not trivially copyable", TREE_TYPE (arg));
14433 : 9 : return error_mark_node;
14434 : : }
14435 : 21720 : if (!dependent_type_p (type)
14436 : 37946 : && !cp_tree_equal (TYPE_SIZE_UNIT (type),
14437 : 16226 : TYPE_SIZE_UNIT (TREE_TYPE (arg))))
14438 : : {
14439 : 18 : error_at (loc, "%<__builtin_bit_cast%> source size %qE "
14440 : : "not equal to destination type size %qE",
14441 : 18 : TYPE_SIZE_UNIT (TREE_TYPE (arg)),
14442 : 18 : TYPE_SIZE_UNIT (type));
14443 : 18 : return error_mark_node;
14444 : : }
14445 : : }
14446 : :
14447 : 86440 : tree ret = build_min (BIT_CAST_EXPR, type, arg);
14448 : 86440 : SET_EXPR_LOCATION (ret, loc);
14449 : :
14450 : 86440 : if (!processing_template_decl && CLASS_TYPE_P (type))
14451 : 224 : ret = get_target_expr (ret, complain);
14452 : :
14453 : : return ret;
14454 : : }
14455 : :
14456 : : /* Diagnose invalid #pragma GCC unroll argument and adjust
14457 : : it if needed. */
14458 : :
14459 : : tree
14460 : 16860 : cp_check_pragma_unroll (location_t loc, tree unroll)
14461 : : {
14462 : 16860 : HOST_WIDE_INT lunroll = 0;
14463 : 16860 : if (type_dependent_expression_p (unroll))
14464 : : ;
14465 : 33648 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
14466 : 33602 : || (!value_dependent_expression_p (unroll)
14467 : 16748 : && (!tree_fits_shwi_p (unroll)
14468 : 16722 : || (lunroll = tree_to_shwi (unroll)) < 0
14469 : 16707 : || lunroll >= USHRT_MAX)))
14470 : : {
14471 : 90 : error_at (loc, "%<#pragma GCC unroll%> requires an"
14472 : : " assignment-expression that evaluates to a non-negative"
14473 : : " integral constant less than %u", USHRT_MAX);
14474 : 90 : unroll = integer_one_node;
14475 : : }
14476 : 16734 : else if (TREE_CODE (unroll) == INTEGER_CST)
14477 : : {
14478 : 16704 : unroll = fold_convert (integer_type_node, unroll);
14479 : 16704 : if (integer_zerop (unroll))
14480 : 12 : unroll = integer_one_node;
14481 : : }
14482 : 16860 : return unroll;
14483 : : }
14484 : :
14485 : : #include "gt-cp-semantics.h"
|