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 : :
49 : : /* There routines provide a modular interface to perform many parsing
50 : : operations. They may therefore be used during actual parsing, or
51 : : during template instantiation, which may be regarded as a
52 : : degenerate form of parsing. */
53 : :
54 : : static tree maybe_convert_cond (tree);
55 : : static tree finalize_nrv_r (tree *, int *, void *);
56 : :
57 : : /* Used for OpenMP non-static data member privatization. */
58 : :
59 : : static hash_map<tree, tree> *omp_private_member_map;
60 : : static vec<tree> omp_private_member_vec;
61 : : static bool omp_private_member_ignore_next;
62 : :
63 : :
64 : : /* Deferred Access Checking Overview
65 : : ---------------------------------
66 : :
67 : : Most C++ expressions and declarations require access checking
68 : : to be performed during parsing. However, in several cases,
69 : : this has to be treated differently.
70 : :
71 : : For member declarations, access checking has to be deferred
72 : : until more information about the declaration is known. For
73 : : example:
74 : :
75 : : class A {
76 : : typedef int X;
77 : : public:
78 : : X f();
79 : : };
80 : :
81 : : A::X A::f();
82 : : A::X g();
83 : :
84 : : When we are parsing the function return type `A::X', we don't
85 : : really know if this is allowed until we parse the function name.
86 : :
87 : : Furthermore, some contexts require that access checking is
88 : : never performed at all. These include class heads, and template
89 : : instantiations.
90 : :
91 : : Typical use of access checking functions is described here:
92 : :
93 : : 1. When we enter a context that requires certain access checking
94 : : mode, the function `push_deferring_access_checks' is called with
95 : : DEFERRING argument specifying the desired mode. Access checking
96 : : may be performed immediately (dk_no_deferred), deferred
97 : : (dk_deferred), or not performed (dk_no_check).
98 : :
99 : : 2. When a declaration such as a type, or a variable, is encountered,
100 : : the function `perform_or_defer_access_check' is called. It
101 : : maintains a vector of all deferred checks.
102 : :
103 : : 3. The global `current_class_type' or `current_function_decl' is then
104 : : setup by the parser. `enforce_access' relies on these information
105 : : to check access.
106 : :
107 : : 4. Upon exiting the context mentioned in step 1,
108 : : `perform_deferred_access_checks' is called to check all declaration
109 : : stored in the vector. `pop_deferring_access_checks' is then
110 : : called to restore the previous access checking mode.
111 : :
112 : : In case of parsing error, we simply call `pop_deferring_access_checks'
113 : : without `perform_deferred_access_checks'. */
114 : :
115 : : struct GTY(()) deferred_access {
116 : : /* A vector representing name-lookups for which we have deferred
117 : : checking access controls. We cannot check the accessibility of
118 : : names used in a decl-specifier-seq until we know what is being
119 : : declared because code like:
120 : :
121 : : class A {
122 : : class B {};
123 : : B* f();
124 : : }
125 : :
126 : : A::B* A::f() { return 0; }
127 : :
128 : : is valid, even though `A::B' is not generally accessible. */
129 : : vec<deferred_access_check, va_gc> *deferred_access_checks;
130 : :
131 : : /* The current mode of access checks. */
132 : : enum deferring_kind deferring_access_checks_kind;
133 : : };
134 : :
135 : : /* Data for deferred access checking. */
136 : : static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack;
137 : : static GTY(()) unsigned deferred_access_no_check;
138 : :
139 : : /* Save the current deferred access states and start deferred
140 : : access checking iff DEFER_P is true. */
141 : :
142 : : void
143 : 18460279606 : push_deferring_access_checks (deferring_kind deferring)
144 : : {
145 : : /* For context like template instantiation, access checking
146 : : disabling applies to all nested context. */
147 : 18460279606 : if (deferred_access_no_check || deferring == dk_no_check)
148 : 265983259 : deferred_access_no_check++;
149 : : else
150 : : {
151 : 18194296347 : deferred_access e = {NULL, deferring};
152 : 18194296347 : vec_safe_push (deferred_access_stack, e);
153 : : }
154 : 18460279606 : }
155 : :
156 : : /* Save the current deferred access states and start deferred access
157 : : checking, continuing the set of deferred checks in CHECKS. */
158 : :
159 : : void
160 : 283179091 : reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
161 : : {
162 : 283179091 : push_deferring_access_checks (dk_deferred);
163 : 283179091 : if (!deferred_access_no_check)
164 : 276779712 : deferred_access_stack->last().deferred_access_checks = checks;
165 : 283179091 : }
166 : :
167 : : /* Resume deferring access checks again after we stopped doing
168 : : this previously. */
169 : :
170 : : void
171 : 156121831 : resume_deferring_access_checks (void)
172 : : {
173 : 156121831 : if (!deferred_access_no_check)
174 : 156104142 : deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
175 : 156121831 : }
176 : :
177 : : /* Stop deferring access checks. */
178 : :
179 : : void
180 : 429344766 : stop_deferring_access_checks (void)
181 : : {
182 : 429344766 : if (!deferred_access_no_check)
183 : 429292738 : deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
184 : 429344766 : }
185 : :
186 : : /* Discard the current deferred access checks and restore the
187 : : previous states. */
188 : :
189 : : void
190 : 11157358170 : pop_deferring_access_checks (void)
191 : : {
192 : 11157358170 : if (deferred_access_no_check)
193 : 197011718 : deferred_access_no_check--;
194 : : else
195 : 10960346452 : deferred_access_stack->pop ();
196 : 11157358170 : }
197 : :
198 : : /* Returns a TREE_LIST representing the deferred checks.
199 : : The TREE_PURPOSE of each node is the type through which the
200 : : access occurred; the TREE_VALUE is the declaration named.
201 : : */
202 : :
203 : : vec<deferred_access_check, va_gc> *
204 : 974732694 : get_deferred_access_checks (void)
205 : : {
206 : 974732694 : if (deferred_access_no_check)
207 : : return NULL;
208 : : else
209 : 962050111 : return (deferred_access_stack->last().deferred_access_checks);
210 : : }
211 : :
212 : : /* Take current deferred checks and combine with the
213 : : previous states if we also defer checks previously.
214 : : Otherwise perform checks now. */
215 : :
216 : : void
217 : 7302791279 : pop_to_parent_deferring_access_checks (void)
218 : : {
219 : 7302791279 : if (deferred_access_no_check)
220 : 68971535 : deferred_access_no_check--;
221 : : else
222 : : {
223 : 7233819744 : vec<deferred_access_check, va_gc> *checks;
224 : 7233819744 : deferred_access *ptr;
225 : :
226 : 7233819744 : checks = (deferred_access_stack->last ().deferred_access_checks);
227 : :
228 : 7233819744 : deferred_access_stack->pop ();
229 : 7233819744 : ptr = &deferred_access_stack->last ();
230 : 7233819744 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
231 : : {
232 : : /* Check access. */
233 : 459390867 : perform_access_checks (checks, tf_warning_or_error);
234 : : }
235 : : else
236 : : {
237 : : /* Merge with parent. */
238 : : int i, j;
239 : : deferred_access_check *chk, *probe;
240 : :
241 : 6932878597 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
242 : : {
243 : 86826511 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
244 : : {
245 : 8284764 : if (probe->binfo == chk->binfo &&
246 : 6602488 : probe->decl == chk->decl &&
247 : 683171 : probe->diag_decl == chk->diag_decl)
248 : 683113 : goto found;
249 : : }
250 : : /* Insert into parent's checks. */
251 : 78541747 : vec_safe_push (ptr->deferred_access_checks, *chk);
252 : 79224860 : found:;
253 : : }
254 : : }
255 : : }
256 : 7302791279 : }
257 : :
258 : : /* Called from enforce_access. A class has attempted (but failed) to access
259 : : DECL. It is already established that a baseclass of that class,
260 : : PARENT_BINFO, has private access to DECL. Examine certain special cases
261 : : to find a decl that accurately describes the source of the problem. If
262 : : none of the special cases apply, simply return DECL as the source of the
263 : : problem. */
264 : :
265 : : static tree
266 : 182 : get_class_access_diagnostic_decl (tree parent_binfo, tree decl)
267 : : {
268 : : /* When a class is denied access to a decl in a baseclass, most of the
269 : : time it is because the decl itself was declared as private at the point
270 : : of declaration.
271 : :
272 : : However, in C++, there are (at least) two situations in which a decl
273 : : can be private even though it was not originally defined as such.
274 : : These two situations only apply if a baseclass had private access to
275 : : DECL (this function is only called if that is the case). */
276 : :
277 : : /* We should first check whether the reason the parent had private access
278 : : to DECL was simply because DECL was created and declared as private in
279 : : the parent. If it was, then DECL is definitively the source of the
280 : : problem. */
281 : 182 : if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl),
282 : : BINFO_TYPE (parent_binfo)))
283 : : return decl;
284 : :
285 : : /* 1. If the "using" keyword is used to inherit DECL within the parent,
286 : : this may cause DECL to be private, so we should return the using
287 : : statement as the source of the problem.
288 : :
289 : : Scan the fields of PARENT_BINFO and see if there are any using decls. If
290 : : there are, see if they inherit DECL. If they do, that's where DECL must
291 : : have been declared private. */
292 : :
293 : 66 : for (tree parent_field = TYPE_FIELDS (BINFO_TYPE (parent_binfo));
294 : 326 : parent_field;
295 : 260 : parent_field = DECL_CHAIN (parent_field))
296 : : /* Not necessary, but also check TREE_PRIVATE for the sake of
297 : : eliminating obviously non-relevant using decls. */
298 : 278 : if (TREE_CODE (parent_field) == USING_DECL
299 : 278 : && TREE_PRIVATE (parent_field))
300 : : {
301 : 78 : tree decl_stripped = strip_using_decl (parent_field);
302 : :
303 : : /* The using statement might be overloaded. If so, we need to
304 : : check all of the overloads. */
305 : 180 : for (ovl_iterator iter (decl_stripped); iter; ++iter)
306 : : /* If equal, the using statement inherits DECL, and so is the
307 : : source of the access failure, so return it. */
308 : 99 : if (*iter == decl)
309 : 18 : return parent_field;
310 : : }
311 : :
312 : : /* 2. If DECL was privately inherited by the parent class, then DECL will
313 : : be inaccessible, even though it may originally have been accessible to
314 : : deriving classes. In that case, the fault lies with the parent, since it
315 : : used a private inheritance, so we return the parent as the source of the
316 : : problem.
317 : :
318 : : Since this is the last check, we just assume it's true. At worst, it
319 : : will simply point to the class that failed to give access, which is
320 : : technically true. */
321 : 48 : return TYPE_NAME (BINFO_TYPE (parent_binfo));
322 : : }
323 : :
324 : : /* If the current scope isn't allowed to access DECL along
325 : : BASETYPE_PATH, give an error, or if we're parsing a function or class
326 : : template, defer the access check to be performed at instantiation time.
327 : : The most derived class in BASETYPE_PATH is the one used to qualify DECL.
328 : : DIAG_DECL is the declaration to use in the error diagnostic. */
329 : :
330 : : static bool
331 : 265871682 : enforce_access (tree basetype_path, tree decl, tree diag_decl,
332 : : tsubst_flags_t complain, access_failure_info *afi = NULL)
333 : : {
334 : 265871682 : gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
335 : :
336 : 265871682 : if (flag_new_inheriting_ctors
337 : 345048842 : && DECL_INHERITED_CTOR (decl))
338 : : {
339 : : /* 7.3.3/18: The additional constructors are accessible if they would be
340 : : accessible when used to construct an object of the corresponding base
341 : : class. */
342 : 40655 : decl = strip_inheriting_ctors (decl);
343 : 40655 : basetype_path = lookup_base (basetype_path, DECL_CONTEXT (decl),
344 : : ba_any, NULL, complain);
345 : : }
346 : :
347 : 265871682 : tree cs = current_scope ();
348 : 265871682 : if (in_template_context
349 : 265871682 : && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
350 : 36449350 : if (tree template_info = get_template_info (cs))
351 : : {
352 : : /* When parsing a function or class template, we in general need to
353 : : defer access checks until template instantiation time, since a friend
354 : : declaration may grant access only to a particular specialization of
355 : : the template. */
356 : :
357 : 36237233 : if (accessible_p (basetype_path, decl, /*consider_local_p=*/true))
358 : : /* But if the member is deemed accessible at parse time, then we can
359 : : assume it'll be accessible at instantiation time. */
360 : : return true;
361 : :
362 : : /* Access of a dependent decl should be rechecked after tsubst'ing
363 : : into the user of the decl, rather than explicitly deferring the
364 : : check here. */
365 : 141 : gcc_assert (!uses_template_parms (decl));
366 : 141 : if (TREE_CODE (decl) == FIELD_DECL)
367 : 6 : gcc_assert (!uses_template_parms (DECL_CONTEXT (decl)));
368 : :
369 : : /* Defer this access check until instantiation time. */
370 : 141 : deferred_access_check access_check;
371 : 141 : access_check.binfo = basetype_path;
372 : 141 : access_check.decl = decl;
373 : 141 : access_check.diag_decl = diag_decl;
374 : 141 : access_check.loc = input_location;
375 : 141 : vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info), access_check);
376 : 141 : return true;
377 : : }
378 : :
379 : 229634449 : if (!accessible_p (basetype_path, decl, /*consider_local_p=*/true))
380 : : {
381 : 22146 : if (flag_new_inheriting_ctors)
382 : 22116 : diag_decl = strip_inheriting_ctors (diag_decl);
383 : 22146 : if (complain & tf_error)
384 : : {
385 : 1114 : access_kind access_failure_reason = ak_none;
386 : :
387 : : /* By default, using the decl as the source of the problem will
388 : : usually give correct results. */
389 : 1114 : tree diag_location = diag_decl;
390 : :
391 : : /* However, if a parent of BASETYPE_PATH had private access to decl,
392 : : then it actually might be the case that the source of the problem
393 : : is not DECL. */
394 : 1114 : tree parent_binfo = get_parent_with_private_access (decl,
395 : : basetype_path);
396 : :
397 : : /* So if a parent did have private access, then we need to do
398 : : special checks to obtain the best diagnostic location decl. */
399 : 1114 : if (parent_binfo != NULL_TREE)
400 : : {
401 : 182 : diag_location = get_class_access_diagnostic_decl (parent_binfo,
402 : : diag_decl);
403 : :
404 : : /* We also at this point know that the reason access failed was
405 : : because decl was private. */
406 : 182 : access_failure_reason = ak_private;
407 : : }
408 : :
409 : : /* Finally, generate an error message. */
410 : 1114 : complain_about_access (decl, diag_decl, diag_location, true,
411 : : access_failure_reason);
412 : : }
413 : 22146 : if (afi)
414 : 406 : afi->record_access_failure (basetype_path, decl, diag_decl);
415 : 22146 : return false;
416 : : }
417 : :
418 : : return true;
419 : : }
420 : :
421 : : /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
422 : : is the BINFO indicating the qualifying scope used to access the
423 : : DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
424 : : or we aren't in SFINAE context or all the checks succeed return TRUE,
425 : : otherwise FALSE. */
426 : :
427 : : bool
428 : 854454987 : perform_access_checks (vec<deferred_access_check, va_gc> *checks,
429 : : tsubst_flags_t complain)
430 : : {
431 : 854454987 : int i;
432 : 854454987 : deferred_access_check *chk;
433 : 854454987 : location_t loc = input_location;
434 : 854454987 : bool ok = true;
435 : :
436 : 854454987 : if (!checks)
437 : : return true;
438 : :
439 : 92109850 : FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
440 : : {
441 : 52045076 : input_location = chk->loc;
442 : 52045076 : ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
443 : : }
444 : :
445 : 40064774 : input_location = loc;
446 : 40064774 : return (complain & tf_error) ? true : ok;
447 : : }
448 : :
449 : : /* Perform the deferred access checks.
450 : :
451 : : After performing the checks, we still have to keep the list
452 : : `deferred_access_stack->deferred_access_checks' since we may want
453 : : to check access for them again later in a different context.
454 : : For example:
455 : :
456 : : class A {
457 : : typedef int X;
458 : : static X a;
459 : : };
460 : : A::X A::a, x; // No error for `A::a', error for `x'
461 : :
462 : : We have to perform deferred access of `A::X', first with `A::a',
463 : : next with `x'. Return value like perform_access_checks above. */
464 : :
465 : : bool
466 : 216376936 : perform_deferred_access_checks (tsubst_flags_t complain)
467 : : {
468 : 216376936 : return perform_access_checks (get_deferred_access_checks (), complain);
469 : : }
470 : :
471 : : /* Defer checking the accessibility of DECL, when looked up in
472 : : BINFO. DIAG_DECL is the declaration to use to print diagnostics.
473 : : Return value like perform_access_checks above.
474 : : If non-NULL, report failures to AFI. */
475 : :
476 : : bool
477 : 420545867 : perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
478 : : tsubst_flags_t complain,
479 : : access_failure_info *afi)
480 : : {
481 : 420545867 : int i;
482 : 420545867 : deferred_access *ptr;
483 : 420545867 : deferred_access_check *chk;
484 : :
485 : : /* Exit if we are in a context that no access checking is performed. */
486 : 420545867 : if (deferred_access_no_check)
487 : : return true;
488 : :
489 : 400795883 : gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
490 : :
491 : 400795883 : ptr = &deferred_access_stack->last ();
492 : :
493 : : /* If we are not supposed to defer access checks, just check now. */
494 : 400795883 : if (ptr->deferring_access_checks_kind == dk_no_deferred)
495 : : {
496 : 213826606 : bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
497 : 358449718 : return (complain & tf_error) ? true : ok;
498 : : }
499 : :
500 : : /* See if we are already going to perform this check. */
501 : 223742829 : FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
502 : : {
503 : 48106387 : if (chk->decl == decl && chk->binfo == binfo &&
504 : 11333167 : chk->diag_decl == diag_decl)
505 : : {
506 : : return true;
507 : : }
508 : : }
509 : : /* If not, record the check. */
510 : 175636442 : deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
511 : 175636442 : vec_safe_push (ptr->deferred_access_checks, new_access);
512 : :
513 : 175636442 : return true;
514 : : }
515 : :
516 : : /* Returns nonzero if the current statement is a full expression,
517 : : i.e. temporaries created during that statement should be destroyed
518 : : at the end of the statement. */
519 : :
520 : : int
521 : 1070183953 : stmts_are_full_exprs_p (void)
522 : : {
523 : 1070183953 : return current_stmt_tree ()->stmts_are_full_exprs_p;
524 : : }
525 : :
526 : : /* T is a statement. Add it to the statement-tree. This is the C++
527 : : version. The C/ObjC frontends have a slightly different version of
528 : : this function. */
529 : :
530 : : tree
531 : 990671657 : add_stmt (tree t)
532 : : {
533 : 990671657 : enum tree_code code = TREE_CODE (t);
534 : :
535 : 990671657 : if (EXPR_P (t) && code != LABEL_EXPR)
536 : : {
537 : 950236251 : if (!EXPR_HAS_LOCATION (t))
538 : 159537162 : SET_EXPR_LOCATION (t, input_location);
539 : :
540 : : /* When we expand a statement-tree, we must know whether or not the
541 : : statements are full-expressions. We record that fact here. */
542 : 950236251 : if (STATEMENT_CODE_P (TREE_CODE (t)))
543 : 240870618 : STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
544 : : }
545 : :
546 : 990671657 : if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
547 : 3198818 : STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
548 : :
549 : : /* Add T to the statement-tree. Non-side-effect statements need to be
550 : : recorded during statement expressions. */
551 : 990671657 : gcc_checking_assert (!stmt_list_stack->is_empty ());
552 : 990671657 : append_to_statement_list_force (t, &cur_stmt_list);
553 : :
554 : 990671657 : return t;
555 : : }
556 : :
557 : : /* Returns the stmt_tree to which statements are currently being added. */
558 : :
559 : : stmt_tree
560 : 5772472703 : current_stmt_tree (void)
561 : : {
562 : 5772472703 : return (cfun
563 : 5758370031 : ? &cfun->language->base.x_stmt_tree
564 : 5772472703 : : &scope_chain->x_stmt_tree);
565 : : }
566 : :
567 : : /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
568 : :
569 : : static tree
570 : 297319 : maybe_cleanup_point_expr (tree expr)
571 : : {
572 : 297319 : if (!processing_template_decl && stmts_are_full_exprs_p ())
573 : 290116 : expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
574 : 297319 : return expr;
575 : : }
576 : :
577 : : /* Like maybe_cleanup_point_expr except have the type of the new expression be
578 : : void so we don't need to create a temporary variable to hold the inner
579 : : expression. The reason why we do this is because the original type might be
580 : : an aggregate and we cannot create a temporary variable for that type. */
581 : :
582 : : tree
583 : 246653933 : maybe_cleanup_point_expr_void (tree expr)
584 : : {
585 : 246653933 : if (!processing_template_decl && stmts_are_full_exprs_p ())
586 : 90125219 : expr = fold_build_cleanup_point_expr (void_type_node, expr);
587 : 246653933 : return expr;
588 : : }
589 : :
590 : :
591 : :
592 : : /* Create a declaration statement for the declaration given by the DECL. */
593 : :
594 : : void
595 : 79291187 : add_decl_expr (tree decl)
596 : : {
597 : 79291187 : tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
598 : 79291187 : if (DECL_INITIAL (decl)
599 : 79291187 : || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
600 : 6096875 : r = maybe_cleanup_point_expr_void (r);
601 : 79291187 : add_stmt (r);
602 : 79291187 : }
603 : :
604 : : /* Set EXPR_LOCATION on one cleanup T to LOC. */
605 : :
606 : : static void
607 : 5068681 : set_one_cleanup_loc (tree t, location_t loc)
608 : : {
609 : 5068681 : if (!t)
610 : : return;
611 : 5068681 : if (TREE_CODE (t) != POSTCONDITION_STMT)
612 : 5068681 : protected_set_expr_location (t, loc);
613 : : /* Avoid locus differences for C++ cdtor calls depending on whether
614 : : cdtor_returns_this: a conversion to void is added to discard the return
615 : : value, and this conversion ends up carrying the location, and when it
616 : : gets discarded, the location is lost. So hold it in the call as well. */
617 : 5068681 : if (TREE_CODE (t) == NOP_EXPR
618 : 0 : && TREE_TYPE (t) == void_type_node
619 : 5068681 : && TREE_CODE (TREE_OPERAND (t, 0)) == CALL_EXPR)
620 : 0 : protected_set_expr_location (TREE_OPERAND (t, 0), loc);
621 : : }
622 : :
623 : : /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC. */
624 : :
625 : : static void
626 : 937177187 : set_cleanup_locs (tree stmts, location_t loc)
627 : : {
628 : 942245868 : if (TREE_CODE (stmts) == CLEANUP_STMT)
629 : : {
630 : 5068681 : set_one_cleanup_loc (CLEANUP_EXPR (stmts), loc);
631 : 5068681 : set_cleanup_locs (CLEANUP_BODY (stmts), loc);
632 : : }
633 : 937177187 : else if (TREE_CODE (stmts) == STATEMENT_LIST)
634 : 842295091 : for (tree stmt : tsi_range (stmts))
635 : 648204715 : set_cleanup_locs (stmt, loc);
636 : 937177187 : }
637 : :
638 : : /* True iff the innermost block scope is a try block. */
639 : :
640 : : static bool
641 : 288972472 : at_try_scope ()
642 : : {
643 : 288972472 : cp_binding_level *b = current_binding_level;
644 : 288972760 : while (b && b->kind == sk_cleanup)
645 : 288 : b = b->level_chain;
646 : 288972472 : return b && b->kind == sk_try;
647 : : }
648 : :
649 : : /* Finish a scope. */
650 : :
651 : : tree
652 : 288972472 : do_poplevel (tree stmt_list)
653 : : {
654 : 288972472 : tree block = NULL;
655 : :
656 : 288972472 : bool was_try = at_try_scope ();
657 : :
658 : 288972472 : if (stmts_are_full_exprs_p ())
659 : 288952985 : block = poplevel (kept_level_p (), 1, 0);
660 : :
661 : : /* This needs to come after poplevel merges sk_cleanup statement_lists. */
662 : 288972472 : maybe_splice_retval_cleanup (stmt_list, was_try);
663 : :
664 : 288972472 : stmt_list = pop_stmt_list (stmt_list);
665 : :
666 : : /* input_location is the last token of the scope, usually a }. */
667 : 288972472 : set_cleanup_locs (stmt_list, input_location);
668 : :
669 : 288972472 : if (!processing_template_decl)
670 : : {
671 : 88239713 : stmt_list = c_build_bind_expr (input_location, block, stmt_list);
672 : : /* ??? See c_end_compound_stmt re statement expressions. */
673 : : }
674 : :
675 : 288972472 : return stmt_list;
676 : : }
677 : :
678 : : /* Begin a new scope. */
679 : :
680 : : static tree
681 : 288963933 : do_pushlevel (scope_kind sk)
682 : : {
683 : 288963933 : tree ret = push_stmt_list ();
684 : 288963933 : if (stmts_are_full_exprs_p ())
685 : 288953032 : begin_scope (sk, NULL);
686 : 288963933 : return ret;
687 : : }
688 : :
689 : : /* Queue a cleanup. CLEANUP is an expression/statement to be executed
690 : : when the current scope is exited. EH_ONLY is true when this is not
691 : : meant to apply to normal control flow transfer. DECL is the VAR_DECL
692 : : being cleaned up, if any, or null for temporaries or subobjects. */
693 : :
694 : : void
695 : 5068562 : push_cleanup (tree decl, tree cleanup, bool eh_only)
696 : : {
697 : 5068562 : tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
698 : 5068562 : CLEANUP_EH_ONLY (stmt) = eh_only;
699 : 5068562 : add_stmt (stmt);
700 : 5068562 : CLEANUP_BODY (stmt) = push_stmt_list ();
701 : 5068562 : }
702 : :
703 : : /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
704 : : the current loops, represented by 'NULL_TREE' if we've seen a possible
705 : : exit, and 'error_mark_node' if not. This is currently used only to
706 : : suppress the warning about a function with no return statements, and
707 : : therefore we don't bother noting returns as possible exits. We also
708 : : don't bother with gotos. */
709 : :
710 : : static void
711 : 14772605 : begin_maybe_infinite_loop (tree cond)
712 : : {
713 : : /* Only track this while parsing a function, not during instantiation. */
714 : 14772605 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
715 : 2108603 : && !processing_template_decl))
716 : : return;
717 : 12663471 : bool maybe_infinite = true;
718 : 12663471 : if (cond)
719 : : {
720 : 12452574 : cond = fold_non_dependent_expr (cond);
721 : 12452574 : maybe_infinite = integer_nonzerop (cond);
722 : : }
723 : 25116045 : vec_safe_push (cp_function_chain->infinite_loops,
724 : 12663471 : maybe_infinite ? error_mark_node : NULL_TREE);
725 : :
726 : : }
727 : :
728 : : /* A break is a possible exit for the current loop. */
729 : :
730 : : void
731 : 1326399 : break_maybe_infinite_loop (void)
732 : : {
733 : 1326399 : if (!cfun)
734 : : return;
735 : 1326399 : cp_function_chain->infinite_loops->last() = NULL_TREE;
736 : : }
737 : :
738 : : /* If we reach the end of the loop without seeing a possible exit, we have
739 : : an infinite loop. */
740 : :
741 : : static void
742 : 14772605 : end_maybe_infinite_loop (tree cond)
743 : : {
744 : 14772605 : if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
745 : 2108603 : && !processing_template_decl))
746 : : return;
747 : 12663471 : tree current = cp_function_chain->infinite_loops->pop();
748 : 12663471 : if (current != NULL_TREE)
749 : : {
750 : 3999060 : cond = fold_non_dependent_expr (cond);
751 : 3999060 : if (integer_nonzerop (cond))
752 : 200617 : current_function_infinite_loop = 1;
753 : : }
754 : : }
755 : :
756 : : /* Begin a conditional that might contain a declaration. When generating
757 : : normal code, we want the declaration to appear before the statement
758 : : containing the conditional. When generating template code, we want the
759 : : conditional to be rendered as the raw DECL_EXPR. */
760 : :
761 : : static void
762 : 62005711 : begin_cond (tree *cond_p)
763 : : {
764 : 62005711 : if (processing_template_decl)
765 : 43694046 : *cond_p = push_stmt_list ();
766 : 62005711 : }
767 : :
768 : : /* Finish such a conditional. */
769 : :
770 : : static void
771 : 62005711 : finish_cond (tree *cond_p, tree expr)
772 : : {
773 : 62005711 : if (processing_template_decl)
774 : : {
775 : 43694046 : tree cond = pop_stmt_list (*cond_p);
776 : :
777 : 43694046 : if (expr == NULL_TREE)
778 : : /* Empty condition in 'for'. */
779 : 208846 : gcc_assert (empty_expr_stmt_p (cond));
780 : 43485200 : else if (check_for_bare_parameter_packs (expr))
781 : 0 : expr = error_mark_node;
782 : 43485200 : else if (!empty_expr_stmt_p (cond))
783 : 582486 : expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
784 : : }
785 : 62005711 : *cond_p = expr;
786 : 62005711 : }
787 : :
788 : : /* If loop condition specifies a conditional with a declaration,
789 : : such as
790 : : while (A x = 42) { }
791 : : for (; A x = 42;) { }
792 : : move the *BODY_P statements as a BIND_EXPR into {FOR,WHILE}_COND_PREP
793 : : and if there are any CLEANUP_STMT at the end, remember their count in
794 : : {FOR,WHILE}_COND_CLEANUP.
795 : : genericize_c_loop will then handle it appropriately. In particular,
796 : : the {FOR,WHILE}_COND, {FOR,WHILE}_BODY, if used continue label and
797 : : FOR_EXPR will be appended into the {FOR,WHILE}_COND_PREP BIND_EXPR,
798 : : but it can't be done too early because only the actual body should
799 : : bind BREAK_STMT and CONTINUE_STMT to the inner loop.
800 : : The statement list for *BODY will be empty if the conditional did
801 : : not declare anything. */
802 : :
803 : : static void
804 : 10078460 : adjust_loop_decl_cond (tree *body_p, tree *prep_p, tree *cleanup_p)
805 : : {
806 : 10078460 : if (!TREE_SIDE_EFFECTS (*body_p))
807 : 10068655 : return;
808 : :
809 : 9805 : gcc_assert (!processing_template_decl);
810 : 9805 : *prep_p = *body_p;
811 : 9805 : if (*prep_p != cur_stmt_list)
812 : : {
813 : : /* There can be just one CLEANUP_STMT, or there could be multiple
814 : : nested CLEANUP_STMTs, e.g. for structured bindings used as
815 : : condition. */
816 : 97 : gcc_assert (stmt_list_stack->length () > 1);
817 : 97 : for (unsigned i = stmt_list_stack->length () - 2; ; --i)
818 : : {
819 : 109 : tree t = (*stmt_list_stack)[i];
820 : 109 : tree_stmt_iterator last = tsi_last (t);
821 : 218 : gcc_assert (tsi_one_before_end_p (last)
822 : : && TREE_CODE (tsi_stmt (last)) == CLEANUP_STMT
823 : : && (CLEANUP_BODY (tsi_stmt (last))
824 : : == (*stmt_list_stack)[i + 1])
825 : : && !CLEANUP_EH_ONLY (tsi_stmt (last)));
826 : 109 : if (t == *prep_p)
827 : : {
828 : 97 : *cleanup_p = build_int_cst (long_unsigned_type_node,
829 : 97 : stmt_list_stack->length () - 1 - i);
830 : 97 : break;
831 : : }
832 : 12 : gcc_assert (i >= 1);
833 : 12 : }
834 : : }
835 : 9805 : current_binding_level->keep = true;
836 : 9805 : tree_stmt_iterator iter = tsi_last (cur_stmt_list);
837 : : /* Temporarily store in {FOR,WHILE}_BODY the last statement of
838 : : the innnermost statement list or NULL if it has no statement.
839 : : This is used in finish_loop_cond_prep to find out the splitting
840 : : point and then {FOR,WHILE}_BODY will be changed to the actual
841 : : body. */
842 : 9805 : if (tsi_end_p (iter))
843 : 91 : *body_p = NULL_TREE;
844 : : else
845 : 9714 : *body_p = tsi_stmt (iter);
846 : : }
847 : :
848 : : /* Finalize {FOR,WHILE}_{BODY,COND_PREP} after the loop body.
849 : : The above function initialized *BODY_P to the last statement
850 : : in *PREP_P at that point.
851 : : Call do_poplevel on *PREP_P and move everything after that
852 : : former last statement into *BODY_P. genericize_c_loop
853 : : will later put those parts back together.
854 : : CLEANUP is {FOR,WHILE}_COND_CLEANUP. */
855 : :
856 : : static void
857 : 9805 : finish_loop_cond_prep (tree *body_p, tree *prep_p, tree cleanup)
858 : : {
859 : 9805 : *prep_p = do_poplevel (*prep_p);
860 : 9805 : gcc_assert (TREE_CODE (*prep_p) == BIND_EXPR);
861 : 9805 : if (BIND_EXPR_BODY (*prep_p) == *body_p)
862 : : {
863 : 18 : gcc_assert (cleanup == NULL_TREE);
864 : 18 : *body_p = build_empty_stmt (input_location);
865 : 109 : return;
866 : : }
867 : 9787 : tree stmt_list = BIND_EXPR_BODY (*prep_p);
868 : 9787 : gcc_assert (TREE_CODE (stmt_list) == STATEMENT_LIST);
869 : 9787 : if (cleanup)
870 : : {
871 : 97 : tree_stmt_iterator iter = tsi_last (stmt_list);
872 : 97 : gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
873 : 109 : for (unsigned depth = tree_to_uhwi (cleanup); depth > 1; --depth)
874 : : {
875 : 12 : gcc_assert (TREE_CODE (CLEANUP_BODY (tsi_stmt (iter)))
876 : : == STATEMENT_LIST);
877 : 12 : iter = tsi_last (CLEANUP_BODY (tsi_stmt (iter)));
878 : 12 : gcc_assert (TREE_CODE (tsi_stmt (iter)) == CLEANUP_STMT);
879 : : }
880 : 97 : if (*body_p == NULL_TREE)
881 : : {
882 : 91 : *body_p = CLEANUP_BODY (tsi_stmt (iter));
883 : 91 : CLEANUP_BODY (tsi_stmt (iter)) = build_empty_stmt (input_location);
884 : 91 : return;
885 : : }
886 : 6 : stmt_list = CLEANUP_BODY (tsi_stmt (iter));
887 : : }
888 : 9696 : tree_stmt_iterator iter = tsi_start (stmt_list);
889 : 9892 : while (tsi_stmt (iter) != *body_p)
890 : 196 : tsi_next (&iter);
891 : 9696 : *body_p = tsi_split_stmt_list (input_location, iter);
892 : : }
893 : :
894 : : /* Finish a goto-statement. */
895 : :
896 : : tree
897 : 1566 : finish_goto_stmt (tree destination)
898 : : {
899 : 1566 : if (identifier_p (destination))
900 : 1444 : destination = lookup_label (destination);
901 : :
902 : : /* We warn about unused labels with -Wunused. That means we have to
903 : : mark the used labels as used. */
904 : 1566 : if (TREE_CODE (destination) == LABEL_DECL)
905 : 1444 : TREE_USED (destination) = 1;
906 : : else
907 : : {
908 : 122 : destination = mark_rvalue_use (destination);
909 : 122 : if (!processing_template_decl)
910 : : {
911 : 102 : destination = cp_convert (ptr_type_node, destination,
912 : : tf_warning_or_error);
913 : 102 : if (error_operand_p (destination))
914 : : return NULL_TREE;
915 : 93 : destination
916 : 93 : = fold_build_cleanup_point_expr (TREE_TYPE (destination),
917 : : destination);
918 : : }
919 : : }
920 : :
921 : 1557 : check_goto (destination);
922 : :
923 : 1557 : add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
924 : 1557 : return add_stmt (build_stmt (input_location, GOTO_EXPR, destination));
925 : : }
926 : :
927 : : /* Returns true if T corresponds to an assignment operator expression. */
928 : :
929 : : static bool
930 : 712654 : is_assignment_op_expr_p (tree t)
931 : : {
932 : 712654 : if (t == NULL_TREE)
933 : : return false;
934 : :
935 : 712654 : if (TREE_CODE (t) == MODIFY_EXPR
936 : 712654 : || (TREE_CODE (t) == MODOP_EXPR
937 : 326 : && TREE_CODE (TREE_OPERAND (t, 1)) == NOP_EXPR))
938 : : return true;
939 : :
940 : 712073 : tree call = extract_call_expr (t);
941 : 712073 : if (call == NULL_TREE
942 : 118202 : || call == error_mark_node
943 : 830275 : || !CALL_EXPR_OPERATOR_SYNTAX (call))
944 : : return false;
945 : :
946 : 4321 : tree fndecl = cp_get_callee_fndecl_nofold (call);
947 : 4321 : return fndecl != NULL_TREE
948 : 4294 : && DECL_ASSIGNMENT_OPERATOR_P (fndecl)
949 : 4372 : && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR);
950 : : }
951 : :
952 : : /* Return true if TYPE is a class type that is convertible to
953 : : and assignable from bool. */
954 : :
955 : : static GTY((deletable)) hash_map<tree, bool> *boolish_class_type_p_cache;
956 : :
957 : : static bool
958 : 60 : boolish_class_type_p (tree type)
959 : : {
960 : 60 : type = TYPE_MAIN_VARIANT (type);
961 : 60 : if (!CLASS_TYPE_P (type) || !COMPLETE_TYPE_P (type))
962 : : return false;
963 : :
964 : 78 : if (bool *r = hash_map_safe_get (boolish_class_type_p_cache, type))
965 : 27 : return *r;
966 : :
967 : 18 : tree ops;
968 : 18 : bool has_bool_assignment = false;
969 : 18 : bool has_bool_conversion = false;
970 : :
971 : 18 : ops = lookup_fnfields (type, assign_op_identifier, /*protect=*/0, tf_none);
972 : 55 : for (tree op : ovl_range (BASELINK_FUNCTIONS (ops)))
973 : : {
974 : 29 : op = STRIP_TEMPLATE (op);
975 : 29 : if (TREE_CODE (op) != FUNCTION_DECL)
976 : 0 : continue;
977 : 29 : tree parm = DECL_CHAIN (DECL_ARGUMENTS (op));
978 : 29 : tree parm_type = non_reference (TREE_TYPE (parm));
979 : 29 : if (TREE_CODE (parm_type) == BOOLEAN_TYPE)
980 : : {
981 : : has_bool_assignment = true;
982 : : break;
983 : : }
984 : : }
985 : :
986 : 18 : if (has_bool_assignment)
987 : : {
988 : 3 : ops = lookup_conversions (type);
989 : 3 : for (; ops; ops = TREE_CHAIN (ops))
990 : : {
991 : 3 : tree op = TREE_VALUE (ops);
992 : 3 : if (!DECL_NONCONVERTING_P (op)
993 : 3 : && TREE_CODE (DECL_CONV_FN_TYPE (op)) == BOOLEAN_TYPE)
994 : : {
995 : : has_bool_conversion = true;
996 : : break;
997 : : }
998 : : }
999 : : }
1000 : :
1001 : 18 : bool boolish = has_bool_assignment && has_bool_conversion;
1002 : 18 : hash_map_safe_put<true> (boolish_class_type_p_cache, type, boolish);
1003 : 18 : return boolish;
1004 : : }
1005 : :
1006 : :
1007 : : /* Maybe warn about an unparenthesized 'a = b' (appearing in a
1008 : : boolean context where 'a == b' might have been intended).
1009 : : NESTED_P is true if T is the RHS of another assignment. */
1010 : :
1011 : : void
1012 : 58500948 : maybe_warn_unparenthesized_assignment (tree t, bool nested_p,
1013 : : tsubst_flags_t complain)
1014 : : {
1015 : 58500948 : tree type = TREE_TYPE (t);
1016 : 58500948 : t = STRIP_REFERENCE_REF (t);
1017 : :
1018 : 58500948 : if ((complain & tf_warning)
1019 : 58465797 : && warn_parentheses
1020 : 712654 : && is_assignment_op_expr_p (t)
1021 : : /* A parenthesized expression would've had this warning
1022 : : suppressed by finish_parenthesized_expr. */
1023 : 632 : && !warning_suppressed_p (t, OPT_Wparentheses)
1024 : : /* In c = a = b, don't warn if a has type bool or bool-like class. */
1025 : 58501199 : && (!nested_p
1026 : 80 : || (TREE_CODE (type) != BOOLEAN_TYPE
1027 : 60 : && !boolish_class_type_p (type))))
1028 : : {
1029 : 219 : warning_at (cp_expr_loc_or_input_loc (t), OPT_Wparentheses,
1030 : : "suggest parentheses around assignment used as truth value");
1031 : 219 : suppress_warning (t, OPT_Wparentheses);
1032 : : }
1033 : 58500948 : }
1034 : :
1035 : : /* Helper class for saving/restoring ANNOTATE_EXPRs. For a tree node t, users
1036 : : can construct one of these like so:
1037 : :
1038 : : annotate_saver s (&t);
1039 : :
1040 : : and t will be updated to have any annotations removed. The user can then
1041 : : transform t, and later restore the ANNOTATE_EXPRs with:
1042 : :
1043 : : t = s.restore (t).
1044 : :
1045 : : The intent is to ensure that any ANNOTATE_EXPRs remain the outermost
1046 : : expressions following any operations on t. */
1047 : :
1048 : : class annotate_saver {
1049 : : /* The chain of saved annotations, if there were any. Otherwise null. */
1050 : : tree m_annotations;
1051 : :
1052 : : /* If M_ANNOTATIONS is non-null, then M_INNER points to TREE_OPERAND (A, 0)
1053 : : for the innermost annotation A. */
1054 : : tree *m_inner;
1055 : :
1056 : : public:
1057 : : annotate_saver (tree *);
1058 : : tree restore (tree);
1059 : : };
1060 : :
1061 : : /* If *COND is an ANNOTATE_EXPR, walk through the chain of annotations, and set
1062 : : *COND equal to the first non-ANNOTATE_EXPR (saving a pointer to the
1063 : : original chain of annotations for later use in restore). */
1064 : :
1065 : 38105575 : annotate_saver::annotate_saver (tree *cond) : m_annotations (nullptr)
1066 : : {
1067 : 38105575 : tree *t = cond;
1068 : 38108507 : while (TREE_CODE (*t) == ANNOTATE_EXPR)
1069 : 2932 : t = &TREE_OPERAND (*t, 0);
1070 : :
1071 : 38105575 : if (t != cond)
1072 : : {
1073 : 2929 : m_annotations = *cond;
1074 : 2929 : *cond = *t;
1075 : 2929 : m_inner = t;
1076 : : }
1077 : 38105575 : }
1078 : :
1079 : : /* If we didn't strip any annotations on construction, return NEW_INNER
1080 : : unmodified. Otherwise, wrap the saved annotations around NEW_INNER (updating
1081 : : the types and flags of the annotations if needed) and return the resulting
1082 : : expression. */
1083 : :
1084 : : tree
1085 : 38105575 : annotate_saver::restore (tree new_inner)
1086 : : {
1087 : 38105575 : if (!m_annotations)
1088 : : return new_inner;
1089 : :
1090 : : /* If the type of the inner expression changed, we need to update the types
1091 : : of all the ANNOTATE_EXPRs. We may need to update the flags too, but we
1092 : : assume they only change if the type of the inner expression changes.
1093 : : The flag update logic assumes that the other operands to the
1094 : : ANNOTATE_EXPRs are always INTEGER_CSTs. */
1095 : 2929 : if (TREE_TYPE (new_inner) != TREE_TYPE (*m_inner))
1096 : : {
1097 : 6 : const bool new_readonly
1098 : 6 : = TREE_READONLY (new_inner) || CONSTANT_CLASS_P (new_inner);
1099 : :
1100 : 12 : for (tree c = m_annotations; c != *m_inner; c = TREE_OPERAND (c, 0))
1101 : : {
1102 : 6 : gcc_checking_assert (TREE_CODE (c) == ANNOTATE_EXPR
1103 : : && TREE_CODE (TREE_OPERAND (c, 1)) == INTEGER_CST
1104 : : && TREE_CODE (TREE_OPERAND (c, 2)) == INTEGER_CST);
1105 : 6 : TREE_TYPE (c) = TREE_TYPE (new_inner);
1106 : 6 : TREE_SIDE_EFFECTS (c) = TREE_SIDE_EFFECTS (new_inner);
1107 : 6 : TREE_READONLY (c) = new_readonly;
1108 : : }
1109 : : }
1110 : :
1111 : 2929 : *m_inner = new_inner;
1112 : 2929 : return m_annotations;
1113 : : }
1114 : :
1115 : : /* COND is the condition-expression for an if, while, etc.,
1116 : : statement. Convert it to a boolean value, if appropriate.
1117 : : In addition, verify sequence points if -Wsequence-point is enabled. */
1118 : :
1119 : : static tree
1120 : 66065902 : maybe_convert_cond (tree cond)
1121 : : {
1122 : : /* Empty conditions remain empty. */
1123 : 66065902 : if (!cond)
1124 : : return NULL_TREE;
1125 : :
1126 : : /* Wait until we instantiate templates before doing conversion. */
1127 : 65800517 : if (type_dependent_expression_p (cond))
1128 : 27694942 : return cond;
1129 : :
1130 : : /* Strip any ANNOTATE_EXPRs from COND. */
1131 : 38105575 : annotate_saver annotations (&cond);
1132 : :
1133 : : /* For structured binding used in condition, the conversion needs to be
1134 : : evaluated before the individual variables are initialized in the
1135 : : std::tuple_{size,elemenet} case. cp_finish_decomp saved the conversion
1136 : : result in a TARGET_EXPR, pick it up from there. */
1137 : 339127 : if (DECL_DECOMPOSITION_P (cond)
1138 : 177 : && DECL_DECOMP_IS_BASE (cond)
1139 : 177 : && DECL_DECOMP_BASE (cond)
1140 : 38105749 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1141 : 48 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1142 : :
1143 : 38105575 : if (warn_sequence_point && !processing_template_decl)
1144 : 284774 : verify_sequence_points (cond);
1145 : :
1146 : 38105575 : maybe_warn_unparenthesized_assignment (cond, /*nested_p=*/false,
1147 : : tf_warning_or_error);
1148 : :
1149 : : /* Do the conversion. */
1150 : 38105575 : cond = convert_from_reference (cond);
1151 : 38105575 : cond = condition_conversion (cond);
1152 : :
1153 : : /* Restore any ANNOTATE_EXPRs around COND. */
1154 : 38105575 : return annotations.restore (cond);
1155 : : }
1156 : :
1157 : : /* Finish an expression-statement, whose EXPRESSION is as indicated. */
1158 : :
1159 : : tree
1160 : 136283507 : finish_expr_stmt (tree expr)
1161 : : {
1162 : 136283507 : tree r = NULL_TREE;
1163 : 136283507 : location_t loc = EXPR_LOCATION (expr);
1164 : :
1165 : 136094091 : if (expr != NULL_TREE)
1166 : : {
1167 : : /* If we ran into a problem, make sure we complained. */
1168 : 136282743 : gcc_assert (expr != error_mark_node || seen_error ());
1169 : :
1170 : 136282743 : if (!processing_template_decl)
1171 : : {
1172 : 52721991 : if (warn_sequence_point)
1173 : 785956 : verify_sequence_points (expr);
1174 : 52721991 : expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1175 : : }
1176 : 83560752 : else if (!type_dependent_expression_p (expr))
1177 : 17283653 : convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
1178 : :
1179 : 136282740 : if (check_for_bare_parameter_packs (expr))
1180 : 24 : expr = error_mark_node;
1181 : :
1182 : : /* Simplification of inner statement expressions, compound exprs,
1183 : : etc can result in us already having an EXPR_STMT. */
1184 : 136282740 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
1185 : : {
1186 : 136282567 : if (TREE_CODE (expr) != EXPR_STMT)
1187 : 134609157 : expr = build_stmt (loc, EXPR_STMT, expr);
1188 : 136282567 : expr = maybe_cleanup_point_expr_void (expr);
1189 : : }
1190 : :
1191 : 136282740 : r = add_stmt (expr);
1192 : : }
1193 : :
1194 : 136283504 : return r;
1195 : : }
1196 : :
1197 : :
1198 : : /* Begin an if-statement. Returns a newly created IF_STMT if
1199 : : appropriate. */
1200 : :
1201 : : tree
1202 : 51497805 : begin_if_stmt (void)
1203 : : {
1204 : 51497805 : tree r, scope;
1205 : 51497805 : scope = do_pushlevel (sk_cond);
1206 : 51497805 : r = build_stmt (input_location, IF_STMT, NULL_TREE,
1207 : : NULL_TREE, NULL_TREE, scope);
1208 : 51497805 : current_binding_level->this_entity = r;
1209 : 51497805 : begin_cond (&IF_COND (r));
1210 : 51497805 : return r;
1211 : : }
1212 : :
1213 : : /* Returns true if FN, a CALL_EXPR, is a call to
1214 : : std::is_constant_evaluated or __builtin_is_constant_evaluated. */
1215 : :
1216 : : static bool
1217 : 219207 : is_std_constant_evaluated_p (tree fn)
1218 : : {
1219 : : /* std::is_constant_evaluated takes no arguments. */
1220 : 219207 : if (call_expr_nargs (fn) != 0)
1221 : : return false;
1222 : :
1223 : 74861 : tree fndecl = cp_get_callee_fndecl_nofold (fn);
1224 : 74861 : if (fndecl == NULL_TREE)
1225 : : return false;
1226 : :
1227 : 19937 : if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
1228 : : BUILT_IN_FRONTEND))
1229 : : return true;
1230 : :
1231 : 19912 : if (!decl_in_std_namespace_p (fndecl))
1232 : : return false;
1233 : :
1234 : 6652 : tree name = DECL_NAME (fndecl);
1235 : 6652 : return name && id_equal (name, "is_constant_evaluated");
1236 : : }
1237 : :
1238 : : /* Callback function for maybe_warn_for_constant_evaluated that looks
1239 : : for calls to std::is_constant_evaluated in TP. */
1240 : :
1241 : : static tree
1242 : 4069818 : find_std_constant_evaluated_r (tree *tp, int *walk_subtrees, void *)
1243 : : {
1244 : 4069818 : tree t = *tp;
1245 : :
1246 : 4069818 : if (TYPE_P (t) || TREE_CONSTANT (t))
1247 : : {
1248 : 695194 : *walk_subtrees = false;
1249 : 695194 : return NULL_TREE;
1250 : : }
1251 : :
1252 : 3374624 : switch (TREE_CODE (t))
1253 : : {
1254 : 219207 : case CALL_EXPR:
1255 : 219207 : if (is_std_constant_evaluated_p (t))
1256 : : return t;
1257 : : break;
1258 : 6 : case EXPR_STMT:
1259 : : /* Don't warn in statement expressions. */
1260 : 6 : *walk_subtrees = false;
1261 : 6 : return NULL_TREE;
1262 : : default:
1263 : : break;
1264 : : }
1265 : :
1266 : : return NULL_TREE;
1267 : : }
1268 : :
1269 : : /* In certain contexts, std::is_constant_evaluated() is always true (for
1270 : : instance, in a consteval function or in a constexpr if), or always false
1271 : : (e.g., in a non-constexpr non-consteval function) so give the user a clue. */
1272 : :
1273 : : static void
1274 : 51573560 : maybe_warn_for_constant_evaluated (tree cond, bool constexpr_if,
1275 : : bool trivial_infinite)
1276 : : {
1277 : 51573560 : if (!warn_tautological_compare)
1278 : : return;
1279 : :
1280 : : /* Suppress warning for std::is_constant_evaluated if the conditional
1281 : : comes from a macro. */
1282 : 1227388 : if (from_macro_expansion_at (EXPR_LOCATION (cond)))
1283 : : return;
1284 : :
1285 : 508478 : cond = cp_walk_tree_without_duplicates (&cond, find_std_constant_evaluated_r,
1286 : : NULL);
1287 : 508478 : if (cond)
1288 : : {
1289 : 736 : if (constexpr_if)
1290 : 32 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1291 : : "%<std::is_constant_evaluated%> always evaluates to "
1292 : : "true in %<if constexpr%>");
1293 : 704 : else if (trivial_infinite)
1294 : : {
1295 : 8 : auto_diagnostic_group d;
1296 : 8 : if (warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1297 : : "%<std::is_constant_evaluated%> evaluates to "
1298 : : "true when checking if trivially empty iteration "
1299 : : "statement is trivial infinite loop")
1300 : 8 : && !maybe_constexpr_fn (current_function_decl))
1301 : 8 : inform (EXPR_LOCATION (cond),
1302 : : "and evaluates to false when actually evaluating "
1303 : : "the condition in non-%<constexpr%> function");
1304 : 8 : }
1305 : 696 : else if (!maybe_constexpr_fn (current_function_decl))
1306 : 22 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1307 : : "%<std::is_constant_evaluated%> always evaluates to "
1308 : : "false in a non-%<constexpr%> function");
1309 : 1348 : else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1310 : 3 : warning_at (EXPR_LOCATION (cond), OPT_Wtautological_compare,
1311 : : "%<std::is_constant_evaluated%> always evaluates to "
1312 : : "true in a %<consteval%> function");
1313 : : }
1314 : : }
1315 : :
1316 : : /* Process the COND of an if-statement, which may be given by
1317 : : IF_STMT. */
1318 : :
1319 : : tree
1320 : 51497805 : finish_if_stmt_cond (tree orig_cond, tree if_stmt)
1321 : : {
1322 : 51497805 : tree cond = maybe_convert_cond (orig_cond);
1323 : 51497805 : maybe_warn_for_constant_evaluated (cond, IF_STMT_CONSTEXPR_P (if_stmt),
1324 : : /*trivial_infinite=*/false);
1325 : 51497805 : if (IF_STMT_CONSTEXPR_P (if_stmt)
1326 : 6839147 : && !type_dependent_expression_p (cond)
1327 : 4361397 : && require_constant_expression (cond)
1328 : 4361370 : && !instantiation_dependent_expression_p (cond)
1329 : : /* Wait until instantiation time, since only then COND has been
1330 : : converted to bool. */
1331 : 54089464 : && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
1332 : : {
1333 : 2591659 : cond = instantiate_non_dependent_expr (cond);
1334 : 2591659 : cond = cxx_constant_value (cond);
1335 : : }
1336 : 48906146 : else if (processing_template_decl)
1337 : 35239154 : cond = orig_cond;
1338 : 51497805 : finish_cond (&IF_COND (if_stmt), cond);
1339 : 51497805 : add_stmt (if_stmt);
1340 : 51497805 : THEN_CLAUSE (if_stmt) = push_stmt_list ();
1341 : 51497805 : return cond;
1342 : : }
1343 : :
1344 : : /* Finish the then-clause of an if-statement, which may be given by
1345 : : IF_STMT. */
1346 : :
1347 : : tree
1348 : 51490308 : finish_then_clause (tree if_stmt)
1349 : : {
1350 : 51490308 : THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
1351 : 51490308 : return if_stmt;
1352 : : }
1353 : :
1354 : : /* Begin the else-clause of an if-statement. */
1355 : :
1356 : : void
1357 : 18518296 : begin_else_clause (tree if_stmt)
1358 : : {
1359 : 18518296 : ELSE_CLAUSE (if_stmt) = push_stmt_list ();
1360 : 18518296 : }
1361 : :
1362 : : /* Finish the else-clause of an if-statement, which may be given by
1363 : : IF_STMT. */
1364 : :
1365 : : void
1366 : 18518296 : finish_else_clause (tree if_stmt)
1367 : : {
1368 : 18518296 : ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
1369 : 18518296 : }
1370 : :
1371 : : /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1372 : : read. */
1373 : :
1374 : : static tree
1375 : 343461994 : maybe_mark_exp_read_r (tree *tp, int *, void *)
1376 : : {
1377 : 343461994 : tree t = *tp;
1378 : 343461994 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
1379 : 21262993 : mark_exp_read (t);
1380 : 343461994 : return NULL_TREE;
1381 : : }
1382 : :
1383 : : /* Finish an if-statement. */
1384 : :
1385 : : void
1386 : 51488257 : finish_if_stmt (tree if_stmt)
1387 : : {
1388 : 51488257 : tree scope = IF_SCOPE (if_stmt);
1389 : 51488257 : IF_SCOPE (if_stmt) = NULL;
1390 : 51488257 : if (IF_STMT_CONSTEXPR_P (if_stmt))
1391 : : {
1392 : : /* Prevent various -Wunused warnings. We might not instantiate
1393 : : either of these branches, so we would not mark the variables
1394 : : used in that branch as read. */
1395 : 6831650 : cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt),
1396 : : maybe_mark_exp_read_r, NULL);
1397 : 6831650 : cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt),
1398 : : maybe_mark_exp_read_r, NULL);
1399 : : }
1400 : 51488257 : add_stmt (do_poplevel (scope));
1401 : 51488257 : }
1402 : :
1403 : : /* Determine if iteration statement with *CONDP condition and
1404 : : loop BODY is trivially empty iteration statement or even
1405 : : trivial infinite loop. In the latter case for -ffinite-loops
1406 : : add ANNOTATE_EXPR to mark the loop as maybe validly infinite.
1407 : : Also, emit -Wtautological-compare warning for std::is_constant_evaluated ()
1408 : : calls in the condition when needed. */
1409 : :
1410 : : static void
1411 : 14300005 : finish_loop_cond (tree *condp, tree body)
1412 : : {
1413 : 14300005 : if (TREE_CODE (*condp) == INTEGER_CST)
1414 : : return;
1415 : 10387539 : bool trivially_empty = expr_first (body) == NULL_TREE;
1416 : 10387539 : bool trivial_infinite = false;
1417 : 10387539 : if (trivially_empty)
1418 : : {
1419 : 72553 : tree c = fold_non_dependent_expr (*condp, tf_none,
1420 : : /*manifestly_const_eval=*/true);
1421 : 72553 : trivial_infinite = c && integer_nonzerop (c);
1422 : : }
1423 : 10387539 : if (warn_tautological_compare)
1424 : : {
1425 : 75913 : tree cond = *condp;
1426 : 76258 : while (TREE_CODE (cond) == ANNOTATE_EXPR)
1427 : 345 : cond = TREE_OPERAND (cond, 0);
1428 : 75913 : if (trivial_infinite
1429 : 75977 : && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1430 : 64 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1431 : : /*trivial_infinite=*/true);
1432 : 75849 : else if (!trivially_empty
1433 : 310 : || !processing_template_decl
1434 : 76165 : || DECL_IMMEDIATE_FUNCTION_P (current_function_decl))
1435 : 75691 : maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/false,
1436 : : /*trivial_infinite=*/false);
1437 : : }
1438 : 10387539 : if (trivial_infinite && flag_finite_loops && !processing_template_decl)
1439 : 64 : *condp = build3 (ANNOTATE_EXPR, TREE_TYPE (*condp), *condp,
1440 : 64 : build_int_cst (integer_type_node,
1441 : 64 : annot_expr_maybe_infinite_kind),
1442 : : integer_zero_node);
1443 : : }
1444 : :
1445 : : /* Begin a while-statement. Returns a newly created WHILE_STMT if
1446 : : appropriate. */
1447 : :
1448 : : tree
1449 : 3695291 : begin_while_stmt (void)
1450 : : {
1451 : 3695291 : tree r;
1452 : 3695291 : r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1453 : : NULL_TREE, NULL_TREE);
1454 : 3695291 : add_stmt (r);
1455 : 3695291 : WHILE_BODY (r) = do_pushlevel (sk_block);
1456 : 3695291 : begin_cond (&WHILE_COND (r));
1457 : 3695291 : return r;
1458 : : }
1459 : :
1460 : : /* Process the COND of a while-statement, which may be given by
1461 : : WHILE_STMT. */
1462 : :
1463 : : void
1464 : 3695291 : finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
1465 : : tree unroll, bool novector)
1466 : : {
1467 : 3695291 : cond = maybe_convert_cond (cond);
1468 : 3695291 : finish_cond (&WHILE_COND (while_stmt), cond);
1469 : 3695291 : begin_maybe_infinite_loop (cond);
1470 : 3695291 : if (ivdep && cond != error_mark_node)
1471 : 24 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1472 : 12 : TREE_TYPE (WHILE_COND (while_stmt)),
1473 : 12 : WHILE_COND (while_stmt),
1474 : 12 : build_int_cst (integer_type_node,
1475 : 12 : annot_expr_ivdep_kind),
1476 : : integer_zero_node);
1477 : 3695291 : if (unroll && cond != error_mark_node)
1478 : 25028 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1479 : 12514 : TREE_TYPE (WHILE_COND (while_stmt)),
1480 : 12514 : WHILE_COND (while_stmt),
1481 : 12514 : build_int_cst (integer_type_node,
1482 : 12514 : annot_expr_unroll_kind),
1483 : : unroll);
1484 : 3695291 : if (novector && cond != error_mark_node)
1485 : 42 : WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
1486 : 21 : TREE_TYPE (WHILE_COND (while_stmt)),
1487 : 21 : WHILE_COND (while_stmt),
1488 : 21 : build_int_cst (integer_type_node,
1489 : 21 : annot_expr_no_vector_kind),
1490 : : integer_zero_node);
1491 : 3695291 : adjust_loop_decl_cond (&WHILE_BODY (while_stmt),
1492 : : &WHILE_COND_PREP (while_stmt),
1493 : : &WHILE_COND_CLEANUP (while_stmt));
1494 : 3695291 : }
1495 : :
1496 : : /* Finish a while-statement, which may be given by WHILE_STMT. */
1497 : :
1498 : : void
1499 : 3695291 : finish_while_stmt (tree while_stmt)
1500 : : {
1501 : 3695291 : end_maybe_infinite_loop (boolean_true_node);
1502 : 3695291 : if (WHILE_COND_PREP (while_stmt))
1503 : 9631 : finish_loop_cond_prep (&WHILE_BODY (while_stmt),
1504 : : &WHILE_COND_PREP (while_stmt),
1505 : 9631 : WHILE_COND_CLEANUP (while_stmt));
1506 : : else
1507 : 3685660 : WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
1508 : 3695291 : finish_loop_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
1509 : 3695291 : }
1510 : :
1511 : : /* Begin a do-statement. Returns a newly created DO_STMT if
1512 : : appropriate. */
1513 : :
1514 : : tree
1515 : 4486930 : begin_do_stmt (void)
1516 : : {
1517 : 4486930 : tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE,
1518 : : NULL_TREE);
1519 : 4486930 : begin_maybe_infinite_loop (boolean_true_node);
1520 : 4486930 : add_stmt (r);
1521 : 4486930 : DO_BODY (r) = push_stmt_list ();
1522 : 4486930 : return r;
1523 : : }
1524 : :
1525 : : /* Finish the body of a do-statement, which may be given by DO_STMT. */
1526 : :
1527 : : void
1528 : 4486930 : finish_do_body (tree do_stmt)
1529 : : {
1530 : 4486930 : tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
1531 : :
1532 : 4486930 : if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
1533 : 432512 : body = STATEMENT_LIST_TAIL (body)->stmt;
1534 : :
1535 : 4486930 : if (IS_EMPTY_STMT (body))
1536 : 28 : warning (OPT_Wempty_body,
1537 : : "suggest explicit braces around empty body in %<do%> statement");
1538 : 4486930 : }
1539 : :
1540 : : /* Finish a do-statement, which may be given by DO_STMT, and whose
1541 : : COND is as indicated. */
1542 : :
1543 : : void
1544 : 4486930 : finish_do_stmt (tree cond, tree do_stmt, bool ivdep, tree unroll,
1545 : : bool novector)
1546 : : {
1547 : 4486930 : cond = maybe_convert_cond (cond);
1548 : 4486930 : end_maybe_infinite_loop (cond);
1549 : : /* Unlike other iteration statements, the condition may not contain
1550 : : a declaration, so we don't call finish_cond which checks for
1551 : : unexpanded parameter packs. */
1552 : 4486930 : if (check_for_bare_parameter_packs (cond))
1553 : 3 : cond = error_mark_node;
1554 : 4486930 : if (ivdep && cond != error_mark_node)
1555 : 3 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1556 : 3 : build_int_cst (integer_type_node, annot_expr_ivdep_kind),
1557 : : integer_zero_node);
1558 : 4486930 : if (unroll && cond != error_mark_node)
1559 : 9 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1560 : 9 : build_int_cst (integer_type_node, annot_expr_unroll_kind),
1561 : : unroll);
1562 : 4486930 : if (novector && cond != error_mark_node)
1563 : 0 : cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
1564 : 0 : build_int_cst (integer_type_node, annot_expr_no_vector_kind),
1565 : : integer_zero_node);
1566 : 4486930 : DO_COND (do_stmt) = cond;
1567 : 4486930 : tree do_body = DO_BODY (do_stmt);
1568 : 4486902 : if (CONVERT_EXPR_P (do_body)
1569 : 28 : && integer_zerop (TREE_OPERAND (do_body, 0))
1570 : 4486958 : && VOID_TYPE_P (TREE_TYPE (do_body)))
1571 : : do_body = NULL_TREE;
1572 : 4486930 : finish_loop_cond (&DO_COND (do_stmt), do_body);
1573 : 4486930 : }
1574 : :
1575 : : /* Finish a return-statement. The EXPRESSION returned, if any, is as
1576 : : indicated. */
1577 : :
1578 : : tree
1579 : 98213158 : finish_return_stmt (tree expr)
1580 : : {
1581 : 98213158 : tree r;
1582 : 98213158 : bool no_warning;
1583 : 98213158 : bool dangling;
1584 : :
1585 : 98213158 : expr = check_return_expr (expr, &no_warning, &dangling);
1586 : :
1587 : 98213158 : if (error_operand_p (expr)
1588 : 98213158 : || (flag_openmp && !check_omp_return ()))
1589 : : {
1590 : : /* Suppress -Wreturn-type for this function. */
1591 : 1187 : if (warn_return_type)
1592 : 1181 : suppress_warning (current_function_decl, OPT_Wreturn_type);
1593 : 1187 : return error_mark_node;
1594 : : }
1595 : :
1596 : 98211971 : if (!processing_template_decl)
1597 : : {
1598 : 34263705 : if (warn_sequence_point)
1599 : 998543 : verify_sequence_points (expr);
1600 : : }
1601 : :
1602 : 98211971 : r = build_stmt (input_location, RETURN_EXPR, expr);
1603 : 98211971 : RETURN_EXPR_LOCAL_ADDR_P (r) = dangling;
1604 : 98211971 : if (no_warning)
1605 : 35 : suppress_warning (r, OPT_Wreturn_type);
1606 : 98211971 : r = maybe_cleanup_point_expr_void (r);
1607 : 98211971 : r = add_stmt (r);
1608 : :
1609 : 98211971 : return r;
1610 : : }
1611 : :
1612 : : /* Begin the scope of a for-statement or a range-for-statement.
1613 : : Both the returned trees are to be used in a call to
1614 : : begin_for_stmt or begin_range_for_stmt. */
1615 : :
1616 : : tree
1617 : 6590384 : begin_for_scope (tree *init)
1618 : : {
1619 : 6590384 : tree scope = do_pushlevel (sk_for);
1620 : :
1621 : 6590384 : if (processing_template_decl)
1622 : 5264814 : *init = push_stmt_list ();
1623 : : else
1624 : 1325570 : *init = NULL_TREE;
1625 : :
1626 : 6590384 : return scope;
1627 : : }
1628 : :
1629 : : /* Begin a for-statement. Returns a new FOR_STMT.
1630 : : SCOPE and INIT should be the return of begin_for_scope,
1631 : : or both NULL_TREE */
1632 : :
1633 : : tree
1634 : 6383169 : begin_for_stmt (tree scope, tree init)
1635 : : {
1636 : 6383169 : tree r;
1637 : :
1638 : 6383169 : r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
1639 : : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
1640 : : NULL_TREE, NULL_TREE);
1641 : :
1642 : 6383169 : if (scope == NULL_TREE)
1643 : : {
1644 : 1138502 : gcc_assert (!init);
1645 : 1138502 : scope = begin_for_scope (&init);
1646 : : }
1647 : :
1648 : 6383169 : FOR_INIT_STMT (r) = init;
1649 : 6383169 : FOR_SCOPE (r) = scope;
1650 : :
1651 : 6383169 : return r;
1652 : : }
1653 : :
1654 : : /* Finish the init-statement of a for-statement, which may be
1655 : : given by FOR_STMT. */
1656 : :
1657 : : void
1658 : 6383169 : finish_init_stmt (tree for_stmt)
1659 : : {
1660 : 6383169 : if (processing_template_decl)
1661 : 5057599 : FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
1662 : 6383169 : add_stmt (for_stmt);
1663 : 6383169 : FOR_BODY (for_stmt) = do_pushlevel (sk_block);
1664 : 6383169 : begin_cond (&FOR_COND (for_stmt));
1665 : 6383169 : }
1666 : :
1667 : : /* Finish the COND of a for-statement, which may be given by
1668 : : FOR_STMT. */
1669 : :
1670 : : void
1671 : 6383169 : finish_for_cond (tree cond, tree for_stmt, bool ivdep, tree unroll,
1672 : : bool novector)
1673 : : {
1674 : 6383169 : cond = maybe_convert_cond (cond);
1675 : 6383169 : finish_cond (&FOR_COND (for_stmt), cond);
1676 : 6383169 : begin_maybe_infinite_loop (cond);
1677 : 6383169 : if (ivdep && cond != error_mark_node)
1678 : 68 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1679 : 34 : TREE_TYPE (FOR_COND (for_stmt)),
1680 : 34 : FOR_COND (for_stmt),
1681 : 34 : build_int_cst (integer_type_node,
1682 : 34 : annot_expr_ivdep_kind),
1683 : : integer_zero_node);
1684 : 6383169 : if (unroll && cond != error_mark_node)
1685 : 408 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1686 : 204 : TREE_TYPE (FOR_COND (for_stmt)),
1687 : 204 : FOR_COND (for_stmt),
1688 : 204 : build_int_cst (integer_type_node,
1689 : 204 : annot_expr_unroll_kind),
1690 : : unroll);
1691 : 6383169 : if (novector && cond && cond != error_mark_node)
1692 : 268 : FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1693 : 134 : TREE_TYPE (FOR_COND (for_stmt)),
1694 : 134 : FOR_COND (for_stmt),
1695 : 134 : build_int_cst (integer_type_node,
1696 : 134 : annot_expr_no_vector_kind),
1697 : : integer_zero_node);
1698 : 6383169 : adjust_loop_decl_cond (&FOR_BODY (for_stmt), &FOR_COND_PREP (for_stmt),
1699 : : &FOR_COND_CLEANUP (for_stmt));
1700 : 6383169 : }
1701 : :
1702 : : /* Finish the increment-EXPRESSION in a for-statement, which may be
1703 : : given by FOR_STMT. */
1704 : :
1705 : : void
1706 : 6377753 : finish_for_expr (tree expr, tree for_stmt)
1707 : : {
1708 : 6377753 : if (!expr)
1709 : : return;
1710 : : /* If EXPR is an overloaded function, issue an error; there is no
1711 : : context available to use to perform overload resolution. */
1712 : 6024328 : if (type_unknown_p (expr))
1713 : : {
1714 : 6 : cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1715 : 6 : expr = error_mark_node;
1716 : : }
1717 : 6024328 : if (!processing_template_decl)
1718 : : {
1719 : 1263925 : if (warn_sequence_point)
1720 : 13449 : verify_sequence_points (expr);
1721 : 1263925 : expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1722 : : tf_warning_or_error);
1723 : : }
1724 : 4760403 : else if (!type_dependent_expression_p (expr))
1725 : 1849229 : convert_to_void (expr, ICV_THIRD_IN_FOR, tf_warning_or_error);
1726 : 6024328 : expr = maybe_cleanup_point_expr_void (expr);
1727 : 6024328 : if (check_for_bare_parameter_packs (expr))
1728 : 0 : expr = error_mark_node;
1729 : 6024328 : FOR_EXPR (for_stmt) = expr;
1730 : : }
1731 : :
1732 : : /* During parsing of the body, range for uses "__for_{range,begin,end} "
1733 : : decl names to make those unaccessible by code in the body.
1734 : : Find those decls and store into RANGE_FOR_DECL array, so that they
1735 : : can be changed later to ones with underscore instead of space, so that
1736 : : it can be inspected in the debugger. */
1737 : :
1738 : : void
1739 : 6590497 : find_range_for_decls (tree range_for_decl[3])
1740 : : {
1741 : 6590497 : gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 1
1742 : : && CPTI_FOR_END__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 2
1743 : : && CPTI_FOR_RANGE_IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 3
1744 : : && CPTI_FOR_BEGIN_IDENTIFIER == CPTI_FOR_BEGIN__IDENTIFIER + 3
1745 : : && CPTI_FOR_END_IDENTIFIER == CPTI_FOR_END__IDENTIFIER + 3);
1746 : 26361988 : for (int i = 0; i < 3; i++)
1747 : : {
1748 : 19771491 : tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1749 : 19771491 : if (IDENTIFIER_BINDING (id)
1750 : 19771491 : && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1751 : : {
1752 : 154069 : range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1753 : 154069 : gcc_assert (VAR_P (range_for_decl[i])
1754 : : && DECL_ARTIFICIAL (range_for_decl[i]));
1755 : : }
1756 : : }
1757 : 6590497 : }
1758 : :
1759 : : /* Finish the body of a for-statement, which may be given by
1760 : : FOR_STMT. The increment-EXPR for the loop must be
1761 : : provided.
1762 : : It can also finish RANGE_FOR_STMT. */
1763 : :
1764 : : void
1765 : 6590384 : finish_for_stmt (tree for_stmt)
1766 : : {
1767 : 6590384 : end_maybe_infinite_loop (boolean_true_node);
1768 : :
1769 : 6590384 : if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1770 : 207215 : RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1771 : : else
1772 : : {
1773 : 6383169 : if (FOR_COND_PREP (for_stmt))
1774 : 174 : finish_loop_cond_prep (&FOR_BODY (for_stmt),
1775 : : &FOR_COND_PREP (for_stmt),
1776 : 174 : FOR_COND_CLEANUP (for_stmt));
1777 : : else
1778 : 6382995 : FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1779 : 6383169 : if (FOR_COND (for_stmt))
1780 : 6117784 : finish_loop_cond (&FOR_COND (for_stmt),
1781 : 6117784 : FOR_EXPR (for_stmt) ? integer_one_node
1782 : 129341 : : FOR_BODY (for_stmt));
1783 : : }
1784 : :
1785 : : /* Pop the scope for the body of the loop. */
1786 : 6590384 : tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1787 : 6590384 : ? &RANGE_FOR_SCOPE (for_stmt)
1788 : 6383169 : : &FOR_SCOPE (for_stmt));
1789 : 6590384 : tree scope = *scope_ptr;
1790 : 6590384 : *scope_ptr = NULL;
1791 : :
1792 : : /* During parsing of the body, range for uses "__for_{range,begin,end} "
1793 : : decl names to make those unaccessible by code in the body.
1794 : : Change it to ones with underscore instead of space, so that it can
1795 : : be inspected in the debugger. */
1796 : 6590384 : tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1797 : 6590384 : find_range_for_decls (range_for_decl);
1798 : :
1799 : 6590384 : add_stmt (do_poplevel (scope));
1800 : :
1801 : : /* If we're being called from build_vec_init, don't mess with the names of
1802 : : the variables for an enclosing range-for. */
1803 : 6590384 : if (!stmts_are_full_exprs_p ())
1804 : 5416 : return;
1805 : :
1806 : 26339872 : for (int i = 0; i < 3; i++)
1807 : 19754904 : if (range_for_decl[i])
1808 : 153953 : DECL_NAME (range_for_decl[i])
1809 : 153953 : = cp_global_trees[CPTI_FOR_RANGE_IDENTIFIER + i];
1810 : : }
1811 : :
1812 : : /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1813 : : SCOPE and INIT should be the return of begin_for_scope,
1814 : : or both NULL_TREE .
1815 : : To finish it call finish_for_stmt(). */
1816 : :
1817 : : tree
1818 : 207215 : begin_range_for_stmt (tree scope, tree init)
1819 : : {
1820 : 207215 : begin_maybe_infinite_loop (boolean_false_node);
1821 : :
1822 : 207215 : tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1823 : : NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1824 : :
1825 : 207215 : if (scope == NULL_TREE)
1826 : : {
1827 : 6 : gcc_assert (!init);
1828 : 6 : scope = begin_for_scope (&init);
1829 : : }
1830 : :
1831 : : /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1832 : 207215 : RANGE_FOR_INIT_STMT (r) = init;
1833 : 207215 : RANGE_FOR_SCOPE (r) = scope;
1834 : :
1835 : 207215 : return r;
1836 : : }
1837 : :
1838 : : /* Finish the head of a range-based for statement, which may
1839 : : be given by RANGE_FOR_STMT. DECL must be the declaration
1840 : : and EXPR must be the loop expression. */
1841 : :
1842 : : void
1843 : 207215 : finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1844 : : {
1845 : 207215 : if (processing_template_decl)
1846 : 414430 : RANGE_FOR_INIT_STMT (range_for_stmt)
1847 : 414430 : = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1848 : 207215 : RANGE_FOR_DECL (range_for_stmt) = decl;
1849 : 207215 : RANGE_FOR_EXPR (range_for_stmt) = expr;
1850 : 207215 : add_stmt (range_for_stmt);
1851 : 207215 : RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1852 : 207215 : }
1853 : :
1854 : : /* Finish a break-statement. */
1855 : :
1856 : : tree
1857 : 3349126 : finish_break_stmt (void)
1858 : : {
1859 : : /* In switch statements break is sometimes stylistically used after
1860 : : a return statement. This can lead to spurious warnings about
1861 : : control reaching the end of a non-void function when it is
1862 : : inlined. Note that we are calling block_may_fallthru with
1863 : : language specific tree nodes; this works because
1864 : : block_may_fallthru returns true when given something it does not
1865 : : understand. */
1866 : 3349126 : if (!block_may_fallthru (cur_stmt_list))
1867 : 993 : return void_node;
1868 : 3348133 : note_break_stmt ();
1869 : 3348133 : return add_stmt (build_stmt (input_location, BREAK_STMT, NULL_TREE));
1870 : : }
1871 : :
1872 : : /* Finish a continue-statement. */
1873 : :
1874 : : tree
1875 : 157569 : finish_continue_stmt (void)
1876 : : {
1877 : 157569 : return add_stmt (build_stmt (input_location, CONTINUE_STMT, NULL_TREE));
1878 : : }
1879 : :
1880 : : /* Begin a switch-statement. Returns a new SWITCH_STMT if
1881 : : appropriate. */
1882 : :
1883 : : tree
1884 : 429446 : begin_switch_stmt (void)
1885 : : {
1886 : 429446 : tree r, scope;
1887 : :
1888 : 429446 : scope = do_pushlevel (sk_cond);
1889 : 429446 : r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE,
1890 : : scope, NULL_TREE);
1891 : :
1892 : 429446 : begin_cond (&SWITCH_STMT_COND (r));
1893 : :
1894 : 429446 : return r;
1895 : : }
1896 : :
1897 : : /* Finish the cond of a switch-statement. */
1898 : :
1899 : : void
1900 : 429446 : finish_switch_cond (tree cond, tree switch_stmt)
1901 : : {
1902 : 429446 : tree orig_type = NULL;
1903 : :
1904 : 429446 : if (!processing_template_decl)
1905 : : {
1906 : : /* Convert the condition to an integer or enumeration type. */
1907 : 274860 : tree orig_cond = cond;
1908 : : /* For structured binding used in condition, the conversion needs to be
1909 : : evaluated before the individual variables are initialized in the
1910 : : std::tuple_{size,elemenet} case. cp_finish_decomp saved the
1911 : : conversion result in a TARGET_EXPR, pick it up from there. */
1912 : 122 : if (DECL_DECOMPOSITION_P (cond)
1913 : 57 : && DECL_DECOMP_IS_BASE (cond)
1914 : 57 : && DECL_DECOMP_BASE (cond)
1915 : 274914 : && TREE_CODE (DECL_DECOMP_BASE (cond)) == TARGET_EXPR)
1916 : 18 : cond = TARGET_EXPR_SLOT (DECL_DECOMP_BASE (cond));
1917 : 274860 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1918 : 274860 : if (cond == NULL_TREE)
1919 : : {
1920 : 42 : error_at (cp_expr_loc_or_input_loc (orig_cond),
1921 : : "switch quantity not an integer");
1922 : 27 : cond = error_mark_node;
1923 : : }
1924 : : /* We want unlowered type here to handle enum bit-fields. */
1925 : 274860 : orig_type = unlowered_expr_type (cond);
1926 : 274860 : if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1927 : 162825 : orig_type = TREE_TYPE (cond);
1928 : 274860 : if (cond != error_mark_node)
1929 : : {
1930 : : /* [stmt.switch]
1931 : :
1932 : : Integral promotions are performed. */
1933 : 274827 : cond = perform_integral_promotions (cond);
1934 : 274827 : cond = maybe_cleanup_point_expr (cond);
1935 : : }
1936 : : }
1937 : 429446 : if (check_for_bare_parameter_packs (cond))
1938 : 0 : cond = error_mark_node;
1939 : 429446 : else if (!processing_template_decl && warn_sequence_point)
1940 : 2294 : verify_sequence_points (cond);
1941 : :
1942 : 429446 : finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1943 : 429446 : SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1944 : 429446 : add_stmt (switch_stmt);
1945 : 429446 : push_switch (switch_stmt);
1946 : 429446 : SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1947 : 429446 : }
1948 : :
1949 : : /* Finish the body of a switch-statement, which may be given by
1950 : : SWITCH_STMT. The COND to switch on is indicated. */
1951 : :
1952 : : void
1953 : 429446 : finish_switch_stmt (tree switch_stmt)
1954 : : {
1955 : 429446 : tree scope;
1956 : :
1957 : 858892 : SWITCH_STMT_BODY (switch_stmt) =
1958 : 429446 : pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1959 : 429446 : pop_switch ();
1960 : :
1961 : 429446 : scope = SWITCH_STMT_SCOPE (switch_stmt);
1962 : 429446 : SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1963 : 429446 : add_stmt (do_poplevel (scope));
1964 : 429446 : }
1965 : :
1966 : : /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1967 : : appropriate. */
1968 : :
1969 : : tree
1970 : 1099687 : begin_try_block (void)
1971 : : {
1972 : 1099687 : tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1973 : 1099687 : add_stmt (r);
1974 : 1099687 : TRY_STMTS (r) = push_stmt_list ();
1975 : 1099687 : return r;
1976 : : }
1977 : :
1978 : : /* Likewise, for a function-try-block. The block returned in
1979 : : *COMPOUND_STMT is an artificial outer scope, containing the
1980 : : function-try-block. */
1981 : :
1982 : : tree
1983 : 337 : begin_function_try_block (tree *compound_stmt)
1984 : : {
1985 : 337 : tree r;
1986 : : /* This outer scope does not exist in the C++ standard, but we need
1987 : : a place to put __FUNCTION__ and similar variables. */
1988 : 337 : *compound_stmt = begin_compound_stmt (0);
1989 : 337 : current_binding_level->artificial = 1;
1990 : 337 : r = begin_try_block ();
1991 : 337 : FN_TRY_BLOCK_P (r) = 1;
1992 : 337 : return r;
1993 : : }
1994 : :
1995 : : /* Finish a try-block, which may be given by TRY_BLOCK. */
1996 : :
1997 : : void
1998 : 1099683 : finish_try_block (tree try_block)
1999 : : {
2000 : 1099683 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2001 : 1099683 : TRY_HANDLERS (try_block) = push_stmt_list ();
2002 : 1099683 : }
2003 : :
2004 : : /* Finish the body of a cleanup try-block, which may be given by
2005 : : TRY_BLOCK. */
2006 : :
2007 : : void
2008 : 0 : finish_cleanup_try_block (tree try_block)
2009 : : {
2010 : 0 : TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
2011 : 0 : }
2012 : :
2013 : : /* Finish an implicitly generated try-block, with a cleanup is given
2014 : : by CLEANUP. */
2015 : :
2016 : : void
2017 : 0 : finish_cleanup (tree cleanup, tree try_block)
2018 : : {
2019 : 0 : TRY_HANDLERS (try_block) = cleanup;
2020 : 0 : CLEANUP_P (try_block) = 1;
2021 : 0 : }
2022 : :
2023 : : /* Likewise, for a function-try-block. */
2024 : :
2025 : : void
2026 : 337 : finish_function_try_block (tree try_block)
2027 : : {
2028 : 337 : finish_try_block (try_block);
2029 : : /* FIXME : something queer about CTOR_INITIALIZER somehow following
2030 : : the try block, but moving it inside. */
2031 : 337 : in_function_try_handler = 1;
2032 : 337 : }
2033 : :
2034 : : /* Finish a handler-sequence for a try-block, which may be given by
2035 : : TRY_BLOCK. */
2036 : :
2037 : : void
2038 : 1099683 : finish_handler_sequence (tree try_block)
2039 : : {
2040 : 1099683 : TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
2041 : 1099683 : check_handlers (TRY_HANDLERS (try_block));
2042 : 1099683 : }
2043 : :
2044 : : /* Finish the handler-seq for a function-try-block, given by
2045 : : TRY_BLOCK. COMPOUND_STMT is the outer block created by
2046 : : begin_function_try_block. */
2047 : :
2048 : : void
2049 : 337 : finish_function_handler_sequence (tree try_block, tree compound_stmt)
2050 : : {
2051 : 337 : in_function_try_handler = 0;
2052 : 337 : finish_handler_sequence (try_block);
2053 : 337 : finish_compound_stmt (compound_stmt);
2054 : 337 : }
2055 : :
2056 : : /* Begin a handler. Returns a HANDLER if appropriate. */
2057 : :
2058 : : tree
2059 : 1551470 : begin_handler (void)
2060 : : {
2061 : 1551470 : tree r;
2062 : :
2063 : 1551470 : r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
2064 : 1551470 : add_stmt (r);
2065 : :
2066 : : /* Create a binding level for the eh_info and the exception object
2067 : : cleanup. */
2068 : 1551470 : HANDLER_BODY (r) = do_pushlevel (sk_catch);
2069 : :
2070 : 1551470 : return r;
2071 : : }
2072 : :
2073 : : /* Finish the handler-parameters for a handler, which may be given by
2074 : : HANDLER. DECL is the declaration for the catch parameter, or NULL
2075 : : if this is a `catch (...)' clause. */
2076 : :
2077 : : void
2078 : 1551470 : finish_handler_parms (tree decl, tree handler)
2079 : : {
2080 : 1551470 : tree type = NULL_TREE;
2081 : 1551470 : if (processing_template_decl)
2082 : : {
2083 : 1418308 : if (decl)
2084 : : {
2085 : 476128 : decl = pushdecl (decl);
2086 : 476128 : decl = push_template_decl (decl);
2087 : 476128 : HANDLER_PARMS (handler) = decl;
2088 : 476128 : type = TREE_TYPE (decl);
2089 : : }
2090 : : }
2091 : : else
2092 : : {
2093 : 133162 : type = expand_start_catch_block (decl);
2094 : 133162 : if (warn_catch_value
2095 : 2031 : && type != NULL_TREE
2096 : 707 : && type != error_mark_node
2097 : 133869 : && !TYPE_REF_P (TREE_TYPE (decl)))
2098 : : {
2099 : 210 : tree orig_type = TREE_TYPE (decl);
2100 : 210 : if (CLASS_TYPE_P (orig_type))
2101 : : {
2102 : 96 : if (TYPE_POLYMORPHIC_P (orig_type))
2103 : 48 : warning_at (DECL_SOURCE_LOCATION (decl),
2104 : : OPT_Wcatch_value_,
2105 : : "catching polymorphic type %q#T by value",
2106 : : orig_type);
2107 : 48 : else if (warn_catch_value > 1)
2108 : 36 : warning_at (DECL_SOURCE_LOCATION (decl),
2109 : : OPT_Wcatch_value_,
2110 : : "catching type %q#T by value", orig_type);
2111 : : }
2112 : 114 : else if (warn_catch_value > 2)
2113 : 54 : warning_at (DECL_SOURCE_LOCATION (decl),
2114 : : OPT_Wcatch_value_,
2115 : : "catching non-reference type %q#T", orig_type);
2116 : : }
2117 : : }
2118 : 1551470 : HANDLER_TYPE (handler) = type;
2119 : 1551470 : }
2120 : :
2121 : : /* Finish a handler, which may be given by HANDLER. The BLOCKs are
2122 : : the return value from the matching call to finish_handler_parms. */
2123 : :
2124 : : void
2125 : 1551470 : finish_handler (tree handler)
2126 : : {
2127 : 1551470 : if (!processing_template_decl)
2128 : 133162 : expand_end_catch_block ();
2129 : 1551470 : HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
2130 : 1551470 : }
2131 : :
2132 : : /* Begin a compound statement. FLAGS contains some bits that control the
2133 : : behavior and context. If BCS_NO_SCOPE is set, the compound statement
2134 : : does not define a scope. If BCS_FN_BODY is set, this is the outermost
2135 : : block of a function. If BCS_TRY_BLOCK is set, this is the block
2136 : : created on behalf of a TRY statement. Returns a token to be passed to
2137 : : finish_compound_stmt. */
2138 : :
2139 : : tree
2140 : 222195979 : begin_compound_stmt (unsigned int flags)
2141 : : {
2142 : 222195979 : tree r;
2143 : :
2144 : 222195979 : if (flags & BCS_NO_SCOPE)
2145 : : {
2146 : 3650124 : r = push_stmt_list ();
2147 : 3650124 : STATEMENT_LIST_NO_SCOPE (r) = 1;
2148 : :
2149 : : /* Normally, we try hard to keep the BLOCK for a statement-expression.
2150 : : But, if it's a statement-expression with a scopeless block, there's
2151 : : nothing to keep, and we don't want to accidentally keep a block
2152 : : *inside* the scopeless block. */
2153 : 3650124 : keep_next_level (false);
2154 : : }
2155 : : else
2156 : : {
2157 : 218545855 : scope_kind sk = sk_block;
2158 : 218545855 : if (flags & BCS_TRY_BLOCK)
2159 : : sk = sk_try;
2160 : 217446168 : else if (flags & BCS_TRANSACTION)
2161 : : sk = sk_transaction;
2162 : 217445933 : else if (flags & BCS_STMT_EXPR)
2163 : 28974 : sk = sk_stmt_expr;
2164 : 218545855 : r = do_pushlevel (sk);
2165 : : }
2166 : :
2167 : : /* When processing a template, we need to remember where the braces were,
2168 : : so that we can set up identical scopes when instantiating the template
2169 : : later. BIND_EXPR is a handy candidate for this.
2170 : : Note that do_poplevel won't create a BIND_EXPR itself here (and thus
2171 : : result in nested BIND_EXPRs), since we don't build BLOCK nodes when
2172 : : processing templates. */
2173 : 222195979 : if (processing_template_decl)
2174 : : {
2175 : 150143971 : r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
2176 : 150143971 : BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
2177 : 150143971 : BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
2178 : 150143971 : TREE_SIDE_EFFECTS (r) = 1;
2179 : : }
2180 : :
2181 : 222195979 : return r;
2182 : : }
2183 : :
2184 : : /* Finish a compound-statement, which is given by STMT. */
2185 : :
2186 : : void
2187 : 222195935 : finish_compound_stmt (tree stmt)
2188 : : {
2189 : 222195935 : if (TREE_CODE (stmt) == BIND_EXPR)
2190 : : {
2191 : 150143971 : tree body = do_poplevel (BIND_EXPR_BODY (stmt));
2192 : : /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
2193 : : discard the BIND_EXPR so it can be merged with the containing
2194 : : STATEMENT_LIST. */
2195 : 150143971 : if (TREE_CODE (body) == STATEMENT_LIST
2196 : 137829844 : && STATEMENT_LIST_HEAD (body) == NULL
2197 : 10221534 : && !BIND_EXPR_BODY_BLOCK (stmt)
2198 : 159868695 : && !BIND_EXPR_TRY_BLOCK (stmt))
2199 : : stmt = body;
2200 : : else
2201 : 140419348 : BIND_EXPR_BODY (stmt) = body;
2202 : : }
2203 : 72051964 : else if (STATEMENT_LIST_NO_SCOPE (stmt))
2204 : 3641538 : stmt = pop_stmt_list (stmt);
2205 : : else
2206 : : {
2207 : : /* Destroy any ObjC "super" receivers that may have been
2208 : : created. */
2209 : 68410426 : objc_clear_super_receiver ();
2210 : :
2211 : 68410426 : stmt = do_poplevel (stmt);
2212 : : }
2213 : :
2214 : : /* ??? See c_end_compound_stmt wrt statement expressions. */
2215 : 222195935 : add_stmt (stmt);
2216 : 222195935 : }
2217 : :
2218 : : /* Finish an asm string literal, which can be a string literal
2219 : : or parenthesized constant expression. Extract the string literal
2220 : : from the latter. */
2221 : :
2222 : : tree
2223 : 46391 : finish_asm_string_expression (location_t loc, tree string)
2224 : : {
2225 : 46391 : if (string == error_mark_node
2226 : 46380 : || TREE_CODE (string) == STRING_CST
2227 : 705 : || processing_template_decl)
2228 : : return string;
2229 : 454 : string = cxx_constant_value (string, tf_error);
2230 : 454 : if (TREE_CODE (string) == STRING_CST)
2231 : 8 : string = build1_loc (loc, PAREN_EXPR, TREE_TYPE (string),
2232 : : string);
2233 : 454 : cexpr_str cstr (string);
2234 : 454 : if (!cstr.type_check (loc))
2235 : 136 : return error_mark_node;
2236 : 318 : if (!cstr.extract (loc, string))
2237 : 46 : string = error_mark_node;
2238 : 318 : return string;
2239 : 454 : }
2240 : :
2241 : : /* Finish an asm-statement, whose components are a STRING, some
2242 : : OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
2243 : : LABELS. Also note whether the asm-statement should be
2244 : : considered volatile, and whether it is asm inline. TOPLEV_P
2245 : : is true if finishing namespace scope extended asm. */
2246 : :
2247 : : tree
2248 : 11720 : finish_asm_stmt (location_t loc, int volatile_p, tree string,
2249 : : tree output_operands, tree input_operands, tree clobbers,
2250 : : tree labels, bool inline_p, bool toplev_p)
2251 : : {
2252 : 11720 : tree r;
2253 : 11720 : tree t;
2254 : 11720 : int ninputs = list_length (input_operands);
2255 : 11720 : int noutputs = list_length (output_operands);
2256 : :
2257 : 11720 : if (!processing_template_decl)
2258 : : {
2259 : 11108 : const char *constraint;
2260 : 11108 : const char **oconstraints;
2261 : 11108 : bool allows_mem, allows_reg, is_inout;
2262 : 11108 : tree operand;
2263 : 11108 : int i;
2264 : :
2265 : 11108 : oconstraints = XALLOCAVEC (const char *, noutputs);
2266 : :
2267 : 22133 : string = finish_asm_string_expression (cp_expr_loc_or_loc (string, loc),
2268 : : string);
2269 : 11108 : if (string == error_mark_node)
2270 : 85 : return error_mark_node;
2271 : 33105 : for (int i = 0; i < 2; ++i)
2272 : 74148 : for (t = i ? input_operands : output_operands; t; t = TREE_CHAIN (t))
2273 : : {
2274 : 30008 : tree s = TREE_VALUE (TREE_PURPOSE (t));
2275 : 59999 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2276 : 30008 : if (s == error_mark_node)
2277 : : return error_mark_node;
2278 : 29984 : TREE_VALUE (TREE_PURPOSE (t)) = s;
2279 : : }
2280 : 15820 : for (t = clobbers; t; t = TREE_CHAIN (t))
2281 : : {
2282 : 4797 : tree s = TREE_VALUE (t);
2283 : 9588 : s = finish_asm_string_expression (cp_expr_loc_or_loc (s, loc), s);
2284 : 4797 : TREE_VALUE (t) = s;
2285 : : }
2286 : :
2287 : 11023 : string = resolve_asm_operand_names (string, output_operands,
2288 : : input_operands, labels);
2289 : :
2290 : 27142 : for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
2291 : : {
2292 : 16119 : operand = TREE_VALUE (t);
2293 : :
2294 : : /* ??? Really, this should not be here. Users should be using a
2295 : : proper lvalue, dammit. But there's a long history of using
2296 : : casts in the output operands. In cases like longlong.h, this
2297 : : becomes a primitive form of typechecking -- if the cast can be
2298 : : removed, then the output operand had a type of the proper width;
2299 : : otherwise we'll get an error. Gross, but ... */
2300 : 16119 : STRIP_NOPS (operand);
2301 : :
2302 : 16119 : operand = mark_lvalue_use (operand);
2303 : :
2304 : 16119 : if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
2305 : 9 : operand = error_mark_node;
2306 : :
2307 : 16119 : if (operand != error_mark_node
2308 : 16119 : && (TREE_READONLY (operand)
2309 : 16104 : || CP_TYPE_CONST_P (TREE_TYPE (operand))
2310 : : /* Functions are not modifiable, even though they are
2311 : : lvalues. */
2312 : 16104 : || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand))
2313 : : /* If it's an aggregate and any field is const, then it is
2314 : : effectively const. */
2315 : 16104 : || (CLASS_TYPE_P (TREE_TYPE (operand))
2316 : 22 : && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
2317 : 6 : cxx_readonly_error (loc, operand, lv_asm);
2318 : :
2319 : : tree *op = &operand;
2320 : 16126 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2321 : 7 : op = &TREE_OPERAND (*op, 1);
2322 : 16119 : switch (TREE_CODE (*op))
2323 : : {
2324 : 30 : case PREINCREMENT_EXPR:
2325 : 30 : case PREDECREMENT_EXPR:
2326 : 30 : case MODIFY_EXPR:
2327 : 30 : *op = genericize_compound_lvalue (*op);
2328 : 30 : op = &TREE_OPERAND (*op, 1);
2329 : 30 : break;
2330 : : default:
2331 : : break;
2332 : : }
2333 : :
2334 : 16119 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2335 : 16119 : oconstraints[i] = constraint;
2336 : :
2337 : 16119 : if (parse_output_constraint (&constraint, i, ninputs, noutputs,
2338 : : &allows_mem, &allows_reg, &is_inout))
2339 : : {
2340 : : /* If the operand is going to end up in memory,
2341 : : mark it addressable. */
2342 : 16110 : if (!allows_reg && !cxx_mark_addressable (*op))
2343 : 0 : operand = error_mark_node;
2344 : 16110 : if (allows_reg && toplev_p)
2345 : : {
2346 : 3 : error_at (loc, "constraint allows registers outside of "
2347 : : "a function");
2348 : 3 : operand = error_mark_node;
2349 : : }
2350 : : }
2351 : : else
2352 : 9 : operand = error_mark_node;
2353 : :
2354 : 244 : if (toplev_p && operand != error_mark_node)
2355 : : {
2356 : 21 : if (TREE_SIDE_EFFECTS (operand))
2357 : : {
2358 : 0 : error_at (loc, "side-effects in output operand outside "
2359 : : "of a function");
2360 : 0 : operand = error_mark_node;
2361 : : }
2362 : : else
2363 : : {
2364 : 21 : tree addr
2365 : 21 : = cp_build_addr_expr (operand, tf_warning_or_error);
2366 : 21 : if (addr == error_mark_node)
2367 : 0 : operand = error_mark_node;
2368 : : else
2369 : : {
2370 : 21 : addr = maybe_constant_value (addr);
2371 : 21 : if (!initializer_constant_valid_p (addr,
2372 : 21 : TREE_TYPE (addr)))
2373 : : {
2374 : 3 : error_at (loc, "output operand outside of a "
2375 : : "function is not constant");
2376 : 3 : operand = error_mark_node;
2377 : : }
2378 : : else
2379 : 18 : operand = build_fold_indirect_ref (addr);
2380 : : }
2381 : : }
2382 : : }
2383 : 16098 : else if (operand != error_mark_node && strstr (constraint, "-"))
2384 : : {
2385 : 3 : error_at (loc, "%<-%> modifier used inside of a function");
2386 : 3 : operand = error_mark_node;
2387 : : }
2388 : :
2389 : 16119 : TREE_VALUE (t) = operand;
2390 : : }
2391 : :
2392 : 24884 : for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
2393 : : {
2394 : 13861 : constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
2395 : 13861 : bool constraint_parsed
2396 : 13861 : = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
2397 : : oconstraints, &allows_mem, &allows_reg);
2398 : : /* If the operand is going to end up in memory, don't call
2399 : : decay_conversion. */
2400 : 13861 : if (constraint_parsed && !allows_reg && allows_mem)
2401 : 104 : operand = mark_lvalue_use (TREE_VALUE (t));
2402 : : else
2403 : 13757 : operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error);
2404 : :
2405 : : /* If the type of the operand hasn't been determined (e.g.,
2406 : : because it involves an overloaded function), then issue
2407 : : an error message. There's no context available to
2408 : : resolve the overloading. */
2409 : 13861 : if (TREE_TYPE (operand) == unknown_type_node)
2410 : : {
2411 : 3 : error_at (loc,
2412 : : "type of %<asm%> operand %qE could not be determined",
2413 : 3 : TREE_VALUE (t));
2414 : 3 : operand = error_mark_node;
2415 : : }
2416 : :
2417 : 13861 : if (constraint_parsed)
2418 : : {
2419 : : /* If the operand is going to end up in memory,
2420 : : mark it addressable. */
2421 : 13843 : if (!allows_reg && allows_mem)
2422 : : {
2423 : : /* Strip the nops as we allow this case. FIXME, this really
2424 : : should be rejected or made deprecated. */
2425 : 104 : STRIP_NOPS (operand);
2426 : :
2427 : 104 : tree *op = &operand;
2428 : 111 : while (TREE_CODE (*op) == COMPOUND_EXPR)
2429 : 7 : op = &TREE_OPERAND (*op, 1);
2430 : 104 : switch (TREE_CODE (*op))
2431 : : {
2432 : 27 : case PREINCREMENT_EXPR:
2433 : 27 : case PREDECREMENT_EXPR:
2434 : 27 : case MODIFY_EXPR:
2435 : 27 : *op = genericize_compound_lvalue (*op);
2436 : 27 : op = &TREE_OPERAND (*op, 1);
2437 : 27 : break;
2438 : : default:
2439 : : break;
2440 : : }
2441 : :
2442 : 104 : if (!cxx_mark_addressable (*op))
2443 : 0 : operand = error_mark_node;
2444 : : }
2445 : 13739 : else if (!allows_reg && !allows_mem)
2446 : : {
2447 : : /* If constraint allows neither register nor memory,
2448 : : try harder to get a constant. */
2449 : 248 : tree constop = maybe_constant_value (operand);
2450 : 248 : if (TREE_CONSTANT (constop))
2451 : 221 : operand = constop;
2452 : : }
2453 : 13843 : if (allows_reg && toplev_p)
2454 : : {
2455 : 3 : error_at (loc, "constraint allows registers outside of "
2456 : : "a function");
2457 : 3 : operand = error_mark_node;
2458 : : }
2459 : 13843 : if (constraint[0] == ':' && operand != error_mark_node)
2460 : : {
2461 : 36 : tree t = operand;
2462 : 36 : STRIP_NOPS (t);
2463 : 36 : if (TREE_CODE (t) != ADDR_EXPR
2464 : 36 : || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
2465 : 24 : || (VAR_P (TREE_OPERAND (t, 0))
2466 : 18 : && is_global_var (TREE_OPERAND (t, 0)))))
2467 : : {
2468 : 15 : error_at (loc, "%<:%> constraint operand is not address "
2469 : : "of a function or non-automatic variable");
2470 : 15 : operand = error_mark_node;
2471 : : }
2472 : : }
2473 : : }
2474 : : else
2475 : 18 : operand = error_mark_node;
2476 : :
2477 : 13861 : if (toplev_p && operand != error_mark_node)
2478 : : {
2479 : 96 : if (TREE_SIDE_EFFECTS (operand))
2480 : : {
2481 : 6 : error_at (loc, "side-effects in input operand outside "
2482 : : "of a function");
2483 : 6 : operand = error_mark_node;
2484 : : }
2485 : 90 : else if (allows_mem && lvalue_or_else (operand, lv_asm, tf_none))
2486 : : {
2487 : 21 : tree addr = cp_build_addr_expr (operand, tf_warning_or_error);
2488 : 21 : if (addr == error_mark_node)
2489 : 0 : operand = error_mark_node;
2490 : : else
2491 : : {
2492 : 21 : addr = maybe_constant_value (addr);
2493 : 21 : if (!initializer_constant_valid_p (addr,
2494 : 21 : TREE_TYPE (addr)))
2495 : : {
2496 : 3 : error_at (loc, "input operand outside of a "
2497 : : "function is not constant");
2498 : 3 : operand = error_mark_node;
2499 : : }
2500 : : else
2501 : 18 : operand = build_fold_indirect_ref (addr);
2502 : : }
2503 : : }
2504 : : else
2505 : : {
2506 : 69 : operand = maybe_constant_value (operand);
2507 : 69 : if (!initializer_constant_valid_p (operand,
2508 : 69 : TREE_TYPE (operand)))
2509 : : {
2510 : 3 : error_at (loc, "input operand outside of a "
2511 : : "function is not constant");
2512 : 3 : operand = error_mark_node;
2513 : : }
2514 : : }
2515 : : }
2516 : 13765 : else if (operand != error_mark_node && strstr (constraint, "-"))
2517 : : {
2518 : 9 : error_at (loc, "%<-%> modifier used inside of a function");
2519 : 9 : operand = error_mark_node;
2520 : : }
2521 : :
2522 : 13861 : TREE_VALUE (t) = operand;
2523 : : }
2524 : : }
2525 : :
2526 : 11635 : r = build_stmt (loc, ASM_EXPR, string,
2527 : : output_operands, input_operands,
2528 : : clobbers, labels);
2529 : 11635 : ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
2530 : 11635 : ASM_INLINE_P (r) = inline_p;
2531 : 11635 : if (toplev_p)
2532 : : {
2533 : 93 : symtab->finalize_toplevel_asm (r);
2534 : 93 : return r;
2535 : : }
2536 : 11542 : r = maybe_cleanup_point_expr_void (r);
2537 : 11542 : return add_stmt (r);
2538 : : }
2539 : :
2540 : : /* Finish a label with the indicated NAME. Returns the new label. */
2541 : :
2542 : : tree
2543 : 1934 : finish_label_stmt (tree name)
2544 : : {
2545 : 1934 : tree decl = define_label (input_location, name);
2546 : :
2547 : 1934 : if (decl == error_mark_node)
2548 : : return error_mark_node;
2549 : :
2550 : 1928 : add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
2551 : :
2552 : 1928 : return decl;
2553 : : }
2554 : :
2555 : : /* Finish a series of declarations for local labels. G++ allows users
2556 : : to declare "local" labels, i.e., labels with scope. This extension
2557 : : is useful when writing code involving statement-expressions. */
2558 : :
2559 : : void
2560 : 195 : finish_label_decl (tree name)
2561 : : {
2562 : 195 : if (!at_function_scope_p ())
2563 : : {
2564 : 0 : error ("%<__label__%> declarations are only allowed in function scopes");
2565 : 0 : return;
2566 : : }
2567 : :
2568 : 195 : add_decl_expr (declare_local_label (name));
2569 : : }
2570 : :
2571 : : /* When DECL goes out of scope, make sure that CLEANUP is executed. */
2572 : :
2573 : : void
2574 : 3039939 : finish_decl_cleanup (tree decl, tree cleanup)
2575 : : {
2576 : 3039939 : push_cleanup (decl, cleanup, false);
2577 : 3039939 : }
2578 : :
2579 : : /* If the current scope exits with an exception, run CLEANUP. */
2580 : :
2581 : : void
2582 : 2022956 : finish_eh_cleanup (tree cleanup)
2583 : : {
2584 : 2022956 : push_cleanup (NULL, cleanup, true);
2585 : 2022956 : }
2586 : :
2587 : : /* The MEM_INITS is a list of mem-initializers, in reverse of the
2588 : : order they were written by the user. Each node is as for
2589 : : emit_mem_initializers. */
2590 : :
2591 : : void
2592 : 17647128 : finish_mem_initializers (tree mem_inits)
2593 : : {
2594 : : /* Reorder the MEM_INITS so that they are in the order they appeared
2595 : : in the source program. */
2596 : 17647128 : mem_inits = nreverse (mem_inits);
2597 : :
2598 : 17647128 : if (processing_template_decl)
2599 : : {
2600 : : tree mem;
2601 : :
2602 : 30866458 : for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
2603 : : {
2604 : : /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
2605 : : check for bare parameter packs in the TREE_VALUE, because
2606 : : any parameter packs in the TREE_VALUE have already been
2607 : : bound as part of the TREE_PURPOSE. See
2608 : : make_pack_expansion for more information. */
2609 : 18227699 : if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
2610 : 18227699 : && check_for_bare_parameter_packs (TREE_VALUE (mem)))
2611 : 3 : TREE_VALUE (mem) = error_mark_node;
2612 : : }
2613 : :
2614 : 12638759 : add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
2615 : : CTOR_INITIALIZER, mem_inits));
2616 : : }
2617 : : else
2618 : 5008369 : emit_mem_initializers (mem_inits);
2619 : 17647128 : }
2620 : :
2621 : : /* Obfuscate EXPR if it looks like an id-expression or member access so
2622 : : that the call to finish_decltype in do_auto_deduction will give the
2623 : : right result. If EVEN_UNEVAL, do this even in unevaluated context. */
2624 : :
2625 : : tree
2626 : 29908602 : force_paren_expr (tree expr, bool even_uneval /* = false */)
2627 : : {
2628 : : /* This is only needed for decltype(auto) in C++14. */
2629 : 29908602 : if (cxx_dialect < cxx14)
2630 : : return expr;
2631 : :
2632 : : /* If we're in unevaluated context, we can't be deducing a
2633 : : return/initializer type, so we don't need to mess with this. */
2634 : 29303584 : if (cp_unevaluated_operand && !even_uneval)
2635 : : return expr;
2636 : :
2637 : 27047442 : if (TREE_CODE (expr) == COMPONENT_REF
2638 : 26988983 : || TREE_CODE (expr) == SCOPE_REF
2639 : 54031785 : || REFERENCE_REF_P (expr))
2640 : 277131 : REF_PARENTHESIZED_P (expr) = true;
2641 : 26770311 : else if (DECL_P (tree_strip_any_location_wrapper (expr)))
2642 : : {
2643 : 1850220 : location_t loc = cp_expr_location (expr);
2644 : 1850220 : const tree_code code = processing_template_decl ? PAREN_EXPR
2645 : : : VIEW_CONVERT_EXPR;
2646 : 1850220 : expr = build1_loc (loc, code, TREE_TYPE (expr), expr);
2647 : 1850220 : REF_PARENTHESIZED_P (expr) = true;
2648 : : }
2649 : : return expr;
2650 : : }
2651 : :
2652 : : /* If T is an id-expression obfuscated by force_paren_expr, undo the
2653 : : obfuscation and return the underlying id-expression. Otherwise
2654 : : return T. */
2655 : :
2656 : : tree
2657 : 693567628 : maybe_undo_parenthesized_ref (tree t)
2658 : : {
2659 : 693567628 : if (cxx_dialect < cxx14)
2660 : : return t;
2661 : :
2662 : 683984044 : if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR)
2663 : 760711310 : && REF_PARENTHESIZED_P (t))
2664 : 261993 : t = TREE_OPERAND (t, 0);
2665 : :
2666 : : return t;
2667 : : }
2668 : :
2669 : : /* Finish a parenthesized expression EXPR. */
2670 : :
2671 : : cp_expr
2672 : 26955533 : finish_parenthesized_expr (cp_expr expr)
2673 : : {
2674 : 26955533 : if (EXPR_P (expr))
2675 : : {
2676 : : /* This inhibits warnings in maybe_warn_unparenthesized_assignment
2677 : : and c_common_truthvalue_conversion. */
2678 : 53660765 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wparentheses);
2679 : : /* And maybe_warn_sizeof_array_div. */
2680 : 53660765 : suppress_warning (STRIP_REFERENCE_REF (*expr), OPT_Wsizeof_array_div);
2681 : : }
2682 : :
2683 : 26955533 : if (TREE_CODE (expr) == OFFSET_REF
2684 : 26955533 : || TREE_CODE (expr) == SCOPE_REF)
2685 : : /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
2686 : : enclosed in parentheses. */
2687 : 10879 : PTRMEM_OK_P (expr) = 0;
2688 : :
2689 : 26955533 : tree stripped_expr = tree_strip_any_location_wrapper (expr);
2690 : 26955533 : if (TREE_CODE (stripped_expr) == STRING_CST)
2691 : 834105 : PAREN_STRING_LITERAL_P (stripped_expr) = 1;
2692 : 26121428 : else if (TREE_CODE (stripped_expr) == PACK_INDEX_EXPR)
2693 : 38 : PACK_INDEX_PARENTHESIZED_P (stripped_expr) = true;
2694 : :
2695 : 26955533 : expr = cp_expr (force_paren_expr (expr), expr.get_location ());
2696 : :
2697 : 26955533 : return expr;
2698 : : }
2699 : :
2700 : : /* Finish a reference to a non-static data member (DECL) that is not
2701 : : preceded by `.' or `->'. */
2702 : :
2703 : : tree
2704 : 60914691 : finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
2705 : : tsubst_flags_t complain /* = tf_warning_or_error */)
2706 : : {
2707 : 60914691 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
2708 : 60914691 : bool try_omp_private = !object && omp_private_member_map;
2709 : 54333022 : tree ret;
2710 : :
2711 : 54333022 : if (!object)
2712 : : {
2713 : 54333022 : tree scope = qualifying_scope;
2714 : 54333022 : if (scope == NULL_TREE)
2715 : : {
2716 : 54286933 : scope = context_for_name_lookup (decl);
2717 : 54286933 : if (!TYPE_P (scope))
2718 : : {
2719 : : /* Can happen during error recovery (c++/85014). */
2720 : 3 : gcc_assert (seen_error ());
2721 : 3 : return error_mark_node;
2722 : : }
2723 : : }
2724 : 54333019 : object = maybe_dummy_object (scope, NULL);
2725 : : }
2726 : :
2727 : 60914688 : object = maybe_resolve_dummy (object, true);
2728 : 60914688 : if (object == error_mark_node)
2729 : : return error_mark_node;
2730 : :
2731 : : /* DR 613/850: Can use non-static data members without an associated
2732 : : object in sizeof/decltype/alignof. */
2733 : 60914685 : if (is_dummy_object (object)
2734 : 37894 : && !cp_unevaluated_operand
2735 : 60914777 : && (!processing_template_decl || !current_class_ref))
2736 : : {
2737 : 77 : if (complain & tf_error)
2738 : : {
2739 : 74 : auto_diagnostic_group d;
2740 : 74 : if (current_function_decl
2741 : 74 : && DECL_STATIC_FUNCTION_P (current_function_decl))
2742 : 3 : error ("invalid use of member %qD in static member function", decl);
2743 : 71 : else if (current_function_decl
2744 : 65 : && processing_contract_condition
2745 : 75 : && DECL_CONSTRUCTOR_P (current_function_decl))
2746 : 1 : error ("invalid use of member %qD in constructor %<pre%> contract", decl);
2747 : 70 : else if (current_function_decl
2748 : 64 : && processing_contract_condition
2749 : 72 : && DECL_DESTRUCTOR_P (current_function_decl))
2750 : 1 : error ("invalid use of member %qD in destructor %<post%> contract", decl);
2751 : : else
2752 : 69 : error ("invalid use of non-static data member %qD", decl);
2753 : 74 : inform (DECL_SOURCE_LOCATION (decl), "declared here");
2754 : 74 : }
2755 : :
2756 : 77 : return error_mark_node;
2757 : : }
2758 : :
2759 : 60914608 : if (current_class_ptr)
2760 : 60857348 : TREE_USED (current_class_ptr) = 1;
2761 : 60914608 : if (processing_template_decl)
2762 : : {
2763 : 49203977 : tree type = TREE_TYPE (decl);
2764 : :
2765 : 49203977 : if (TYPE_REF_P (type))
2766 : : /* Quals on the object don't matter. */;
2767 : 47402171 : else if (PACK_EXPANSION_P (type))
2768 : : /* Don't bother trying to represent this. */
2769 : : type = NULL_TREE;
2770 : 47402091 : else if (WILDCARD_TYPE_P (TREE_TYPE (object)))
2771 : : /* We don't know what the eventual quals will be, so punt until
2772 : : instantiation time.
2773 : :
2774 : : This can happen when called from build_capture_proxy for an explicit
2775 : : object lambda. It's a bit marginal to call this function in that
2776 : : case, since this function is for references to members of 'this',
2777 : : but the deduced type is required to be derived from the closure
2778 : : type, so it works. */
2779 : : type = NULL_TREE;
2780 : : else
2781 : : {
2782 : : /* Set the cv qualifiers. */
2783 : 47397574 : int quals = cp_type_quals (TREE_TYPE (object));
2784 : :
2785 : 47397574 : if (DECL_MUTABLE_P (decl))
2786 : 230897 : quals &= ~TYPE_QUAL_CONST;
2787 : :
2788 : 47397574 : quals |= cp_type_quals (TREE_TYPE (decl));
2789 : 47397574 : type = cp_build_qualified_type (type, quals);
2790 : : }
2791 : :
2792 : 49203977 : if (qualifying_scope)
2793 : : /* Wrap this in a SCOPE_REF for now. */
2794 : 31128 : ret = build_qualified_name (type, qualifying_scope, decl,
2795 : : /*template_p=*/false);
2796 : : else
2797 : 49172849 : ret = (convert_from_reference
2798 : 49172849 : (build_min (COMPONENT_REF, type, object, decl, NULL_TREE)));
2799 : : }
2800 : : /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
2801 : : QUALIFYING_SCOPE is also non-null. */
2802 : : else
2803 : : {
2804 : 11710631 : tree access_type = TREE_TYPE (object);
2805 : :
2806 : 11710631 : if (!perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
2807 : : decl, complain))
2808 : 0 : return error_mark_node;
2809 : :
2810 : : /* If the data member was named `C::M', convert `*this' to `C'
2811 : : first. */
2812 : 11710631 : if (qualifying_scope)
2813 : : {
2814 : 14928 : tree binfo = NULL_TREE;
2815 : 14928 : object = build_scoped_ref (object, qualifying_scope,
2816 : : &binfo);
2817 : : }
2818 : :
2819 : 11710631 : ret = build_class_member_access_expr (object, decl,
2820 : : /*access_path=*/NULL_TREE,
2821 : : /*preserve_reference=*/false,
2822 : : complain);
2823 : : }
2824 : 60914608 : if (try_omp_private)
2825 : : {
2826 : 1650 : tree *v = omp_private_member_map->get (decl);
2827 : 1650 : if (v)
2828 : 1225 : ret = convert_from_reference (*v);
2829 : : }
2830 : : return ret;
2831 : : }
2832 : :
2833 : : /* DECL was the declaration to which a qualified-id resolved. Issue
2834 : : an error message if it is not accessible. If OBJECT_TYPE is
2835 : : non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2836 : : type of `*x', or `x', respectively. If the DECL was named as
2837 : : `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like
2838 : : perform_access_checks above. */
2839 : :
2840 : : bool
2841 : 3767020730 : check_accessibility_of_qualified_id (tree decl,
2842 : : tree object_type,
2843 : : tree nested_name_specifier,
2844 : : tsubst_flags_t complain)
2845 : : {
2846 : : /* If we're not checking, return immediately. */
2847 : 3767020730 : if (deferred_access_no_check)
2848 : : return true;
2849 : :
2850 : : /* Determine the SCOPE of DECL. */
2851 : 3758953327 : tree scope = context_for_name_lookup (decl);
2852 : : /* If the SCOPE is not a type, then DECL is not a member. */
2853 : 3758953327 : if (!TYPE_P (scope)
2854 : : /* If SCOPE is dependent then we can't perform this access check now,
2855 : : and since we'll perform this access check again after substitution
2856 : : there's no need to explicitly defer it. */
2857 : 3758953327 : || dependent_type_p (scope))
2858 : 3470117377 : return true;
2859 : :
2860 : 288835950 : tree qualifying_type = NULL_TREE;
2861 : : /* Compute the scope through which DECL is being accessed. */
2862 : 288835950 : if (object_type
2863 : : /* OBJECT_TYPE might not be a class type; consider:
2864 : :
2865 : : class A { typedef int I; };
2866 : : I *p;
2867 : : p->A::I::~I();
2868 : :
2869 : : In this case, we will have "A::I" as the DECL, but "I" as the
2870 : : OBJECT_TYPE. */
2871 : 74969 : && CLASS_TYPE_P (object_type)
2872 : 288910902 : && DERIVED_FROM_P (scope, object_type))
2873 : : {
2874 : : /* If we are processing a `->' or `.' expression, use the type of the
2875 : : left-hand side. */
2876 : 74943 : if (tree open = currently_open_class (object_type))
2877 : : qualifying_type = open;
2878 : : else
2879 : : qualifying_type = object_type;
2880 : : }
2881 : 288761007 : else if (nested_name_specifier)
2882 : : {
2883 : : /* If the reference is to a non-static member of the
2884 : : current class, treat it as if it were referenced through
2885 : : `this'. */
2886 : 355267111 : if (DECL_NONSTATIC_MEMBER_P (decl)
2887 : 177803833 : && current_class_ptr)
2888 : 160382 : if (tree current = current_nonlambda_class_type ())
2889 : : {
2890 : 160355 : if (dependent_type_p (current))
2891 : : /* In general we can't know whether this access goes through
2892 : : `this' until instantiation time. Punt now, or else we might
2893 : : create a deferred access check that's not relative to `this'
2894 : : when it ought to be. We'll check this access again after
2895 : : substitution, e.g. from tsubst_qualified_id. */
2896 : : return true;
2897 : :
2898 : 16616 : if (DERIVED_FROM_P (scope, current))
2899 : : qualifying_type = current;
2900 : : }
2901 : : /* Otherwise, use the type indicated by the
2902 : : nested-name-specifier. */
2903 : : if (!qualifying_type)
2904 : : qualifying_type = nested_name_specifier;
2905 : : }
2906 : : else
2907 : : /* Otherwise, the name must be from the current class or one of
2908 : : its bases. */
2909 : 111127450 : qualifying_type = currently_open_derived_class (scope);
2910 : :
2911 : 288627763 : if (qualifying_type
2912 : : /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2913 : : or similar in a default argument value. */
2914 : 288692211 : && CLASS_TYPE_P (qualifying_type))
2915 : 282225670 : return perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2916 : 282225670 : decl, complain);
2917 : :
2918 : : return true;
2919 : : }
2920 : :
2921 : : /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2922 : : class named to the left of the "::" operator. DONE is true if this
2923 : : expression is a complete postfix-expression; it is false if this
2924 : : expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2925 : : iff this expression is the operand of '&'. TEMPLATE_P is true iff
2926 : : the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2927 : : is true iff this qualified name appears as a template argument. */
2928 : :
2929 : : tree
2930 : 57904331 : finish_qualified_id_expr (tree qualifying_class,
2931 : : tree expr,
2932 : : bool done,
2933 : : bool address_p,
2934 : : bool template_p,
2935 : : bool template_arg_p,
2936 : : tsubst_flags_t complain)
2937 : : {
2938 : 57904331 : gcc_assert (TYPE_P (qualifying_class));
2939 : :
2940 : 57904331 : if (error_operand_p (expr))
2941 : 18 : return error_mark_node;
2942 : :
2943 : 57904313 : if (DECL_P (expr)
2944 : : /* Functions are marked after overload resolution; avoid redundant
2945 : : warnings. */
2946 : 49094798 : && TREE_CODE (expr) != FUNCTION_DECL
2947 : 106999087 : && !mark_used (expr, complain))
2948 : 0 : return error_mark_node;
2949 : :
2950 : 57904313 : if (template_p)
2951 : : {
2952 : 2988707 : if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE)
2953 : : {
2954 : : /* cp_parser_lookup_name thought we were looking for a type,
2955 : : but we're actually looking for a declaration. */
2956 : 9 : qualifying_class = TYPE_CONTEXT (expr);
2957 : 9 : expr = TYPE_IDENTIFIER (expr);
2958 : : }
2959 : : else
2960 : 2988698 : check_template_keyword (expr);
2961 : : }
2962 : :
2963 : : /* If EXPR occurs as the operand of '&', use special handling that
2964 : : permits a pointer-to-member. */
2965 : 57904313 : if (address_p && done
2966 : 157579 : && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
2967 : : {
2968 : 157577 : if (TREE_CODE (expr) == SCOPE_REF)
2969 : 0 : expr = TREE_OPERAND (expr, 1);
2970 : 157577 : expr = build_offset_ref (qualifying_class, expr,
2971 : : /*address_p=*/true, complain);
2972 : 157577 : return expr;
2973 : : }
2974 : :
2975 : : /* No need to check access within an enum. */
2976 : 57746736 : if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
2977 : 1607251 : && TREE_CODE (expr) != IDENTIFIER_NODE)
2978 : : return expr;
2979 : :
2980 : : /* Within the scope of a class, turn references to non-static
2981 : : members into expression of the form "this->...". */
2982 : 56139488 : if (template_arg_p)
2983 : : /* But, within a template argument, we do not want make the
2984 : : transformation, as there is no "this" pointer. */
2985 : : ;
2986 : 56136933 : else if (TREE_CODE (expr) == FIELD_DECL)
2987 : : {
2988 : 46089 : push_deferring_access_checks (dk_no_check);
2989 : 46089 : expr = finish_non_static_data_member (expr, NULL_TREE,
2990 : : qualifying_class, complain);
2991 : 46089 : pop_deferring_access_checks ();
2992 : : }
2993 : 56090844 : else if (BASELINK_P (expr))
2994 : : {
2995 : : /* See if any of the functions are non-static members. */
2996 : : /* If so, the expression may be relative to 'this'. */
2997 : 8410650 : if (!shared_member_p (expr)
2998 : 237492 : && current_class_ptr
2999 : 8647718 : && DERIVED_FROM_P (qualifying_class,
3000 : : current_nonlambda_class_type ()))
3001 : 236924 : expr = (build_class_member_access_expr
3002 : 236924 : (maybe_dummy_object (qualifying_class, NULL),
3003 : : expr,
3004 : 236924 : BASELINK_ACCESS_BINFO (expr),
3005 : : /*preserve_reference=*/false,
3006 : : complain));
3007 : 8173726 : else if (done)
3008 : : /* The expression is a qualified name whose address is not
3009 : : being taken. */
3010 : 331 : expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
3011 : : complain);
3012 : : }
3013 : 47680194 : else if (!template_p
3014 : 47441406 : && TREE_CODE (expr) == TEMPLATE_DECL
3015 : 47680309 : && !DECL_FUNCTION_TEMPLATE_P (expr))
3016 : : {
3017 : 115 : if (complain & tf_error)
3018 : 3 : error ("%qE missing template arguments", expr);
3019 : 115 : return error_mark_node;
3020 : : }
3021 : : else
3022 : : {
3023 : : /* In a template, return a SCOPE_REF for most qualified-ids
3024 : : so that we can check access at instantiation time. But if
3025 : : we're looking at a member of the current instantiation, we
3026 : : know we have access and building up the SCOPE_REF confuses
3027 : : non-type template argument handling. */
3028 : 47680079 : if (processing_template_decl
3029 : 47680079 : && (!currently_open_class (qualifying_class)
3030 : 3493 : || TREE_CODE (expr) == IDENTIFIER_NODE
3031 : 3493 : || TREE_CODE (expr) == TEMPLATE_ID_EXPR
3032 : 82 : || TREE_CODE (expr) == BIT_NOT_EXPR))
3033 : 9793459 : expr = build_qualified_name (TREE_TYPE (expr),
3034 : : qualifying_class, expr,
3035 : : template_p);
3036 : 37886620 : else if (tree wrap = maybe_get_tls_wrapper_call (expr))
3037 : 9 : expr = wrap;
3038 : :
3039 : 47680079 : expr = convert_from_reference (expr);
3040 : : }
3041 : :
3042 : : return expr;
3043 : : }
3044 : :
3045 : : /* Begin a statement-expression. The value returned must be passed to
3046 : : finish_stmt_expr. */
3047 : :
3048 : : tree
3049 : 3672255 : begin_stmt_expr (void)
3050 : : {
3051 : 3672255 : return push_stmt_list ();
3052 : : }
3053 : :
3054 : : /* Process the final expression of a statement expression. EXPR can be
3055 : : NULL, if the final expression is empty. Return a STATEMENT_LIST
3056 : : containing all the statements in the statement-expression, or
3057 : : ERROR_MARK_NODE if there was an error. */
3058 : :
3059 : : tree
3060 : 22689 : finish_stmt_expr_expr (tree expr, tree stmt_expr)
3061 : : {
3062 : 22689 : if (error_operand_p (expr))
3063 : : {
3064 : : /* The type of the statement-expression is the type of the last
3065 : : expression. */
3066 : 3 : TREE_TYPE (stmt_expr) = error_mark_node;
3067 : 3 : return error_mark_node;
3068 : : }
3069 : :
3070 : : /* If the last statement does not have "void" type, then the value
3071 : : of the last statement is the value of the entire expression. */
3072 : 22686 : if (expr)
3073 : : {
3074 : 22671 : tree type = TREE_TYPE (expr);
3075 : :
3076 : 22671 : if (type && type_unknown_p (type))
3077 : : {
3078 : 15 : error ("a statement expression is an insufficient context"
3079 : : " for overload resolution");
3080 : 15 : TREE_TYPE (stmt_expr) = error_mark_node;
3081 : 15 : return error_mark_node;
3082 : : }
3083 : 22656 : else if (processing_template_decl)
3084 : : {
3085 : 133 : expr = build_stmt (input_location, EXPR_STMT, expr);
3086 : 133 : expr = add_stmt (expr);
3087 : : /* Mark the last statement so that we can recognize it as such at
3088 : : template-instantiation time. */
3089 : 133 : EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
3090 : : }
3091 : 22523 : else if (VOID_TYPE_P (type))
3092 : : {
3093 : : /* Just treat this like an ordinary statement. */
3094 : 31 : expr = finish_expr_stmt (expr);
3095 : : }
3096 : : else
3097 : : {
3098 : : /* It actually has a value we need to deal with. First, force it
3099 : : to be an rvalue so that we won't need to build up a copy
3100 : : constructor call later when we try to assign it to something. */
3101 : 22492 : expr = force_rvalue (expr, tf_warning_or_error);
3102 : 22492 : if (error_operand_p (expr))
3103 : 0 : return error_mark_node;
3104 : :
3105 : : /* Update for array-to-pointer decay. */
3106 : 22492 : type = TREE_TYPE (expr);
3107 : :
3108 : : /* This TARGET_EXPR will initialize the outer one added by
3109 : : finish_stmt_expr. */
3110 : 22492 : set_target_expr_eliding (expr);
3111 : :
3112 : : /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
3113 : : normal statement, but don't convert to void or actually add
3114 : : the EXPR_STMT. */
3115 : 22492 : if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
3116 : 22492 : expr = maybe_cleanup_point_expr (expr);
3117 : 22492 : add_stmt (expr);
3118 : : }
3119 : :
3120 : : /* The type of the statement-expression is the type of the last
3121 : : expression. */
3122 : 22656 : TREE_TYPE (stmt_expr) = type;
3123 : : }
3124 : :
3125 : : return stmt_expr;
3126 : : }
3127 : :
3128 : : /* Finish a statement-expression. EXPR should be the value returned
3129 : : by the previous begin_stmt_expr. Returns an expression
3130 : : representing the statement-expression. */
3131 : :
3132 : : tree
3133 : 3672255 : finish_stmt_expr (tree stmt_expr, bool has_no_scope)
3134 : : {
3135 : 3672255 : tree type;
3136 : 3672255 : tree result;
3137 : :
3138 : 3672255 : if (error_operand_p (stmt_expr))
3139 : : {
3140 : 18 : pop_stmt_list (stmt_expr);
3141 : 18 : return error_mark_node;
3142 : : }
3143 : :
3144 : 3672237 : gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
3145 : :
3146 : 3672237 : type = TREE_TYPE (stmt_expr);
3147 : 3672237 : result = pop_stmt_list (stmt_expr);
3148 : 3672237 : TREE_TYPE (result) = type;
3149 : :
3150 : 3672237 : if (processing_template_decl)
3151 : : {
3152 : 8743 : result = build_min (STMT_EXPR, type, result);
3153 : 8743 : TREE_SIDE_EFFECTS (result) = 1;
3154 : 8743 : STMT_EXPR_NO_SCOPE (result) = has_no_scope;
3155 : : }
3156 : 3663494 : else if (CLASS_TYPE_P (type))
3157 : : {
3158 : : /* Wrap the statement-expression in a TARGET_EXPR so that the
3159 : : temporary object created by the final expression is destroyed at
3160 : : the end of the full-expression containing the
3161 : : statement-expression. */
3162 : 98 : result = force_target_expr (type, result, tf_warning_or_error);
3163 : : }
3164 : :
3165 : : return result;
3166 : : }
3167 : :
3168 : : /* Returns the expression which provides the value of STMT_EXPR. */
3169 : :
3170 : : tree
3171 : 151 : stmt_expr_value_expr (tree stmt_expr)
3172 : : {
3173 : 151 : tree t = STMT_EXPR_STMT (stmt_expr);
3174 : :
3175 : 151 : if (TREE_CODE (t) == BIND_EXPR)
3176 : 151 : t = BIND_EXPR_BODY (t);
3177 : :
3178 : 151 : if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
3179 : 118 : t = STATEMENT_LIST_TAIL (t)->stmt;
3180 : :
3181 : 151 : if (TREE_CODE (t) == EXPR_STMT)
3182 : 133 : t = EXPR_STMT_EXPR (t);
3183 : :
3184 : 151 : return t;
3185 : : }
3186 : :
3187 : : /* Return TRUE iff EXPR_STMT is an empty list of
3188 : : expression statements. */
3189 : :
3190 : : bool
3191 : 43694182 : empty_expr_stmt_p (tree expr_stmt)
3192 : : {
3193 : 43694185 : tree body = NULL_TREE;
3194 : :
3195 : 43694185 : if (expr_stmt == void_node)
3196 : : return true;
3197 : :
3198 : 43694182 : if (expr_stmt)
3199 : : {
3200 : 43694182 : if (TREE_CODE (expr_stmt) == EXPR_STMT)
3201 : 3 : body = EXPR_STMT_EXPR (expr_stmt);
3202 : 43694179 : else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
3203 : : body = expr_stmt;
3204 : : }
3205 : :
3206 : 3 : if (body)
3207 : : {
3208 : 43111596 : if (TREE_CODE (body) == STATEMENT_LIST)
3209 : 43111593 : return tsi_end_p (tsi_start (body));
3210 : : else
3211 : : return empty_expr_stmt_p (body);
3212 : : }
3213 : : return false;
3214 : : }
3215 : :
3216 : : /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
3217 : : the function (or functions) to call; ARGS are the arguments to the
3218 : : call. Returns the functions to be considered by overload resolution. */
3219 : :
3220 : : cp_expr
3221 : 15523351 : perform_koenig_lookup (cp_expr fn_expr, vec<tree, va_gc> *args,
3222 : : tsubst_flags_t complain)
3223 : : {
3224 : 15523351 : tree identifier = NULL_TREE;
3225 : 15523351 : tree functions = NULL_TREE;
3226 : 15523351 : tree tmpl_args = NULL_TREE;
3227 : 15523351 : bool template_id = false;
3228 : 15523351 : location_t loc = fn_expr.get_location ();
3229 : 15523351 : tree fn = fn_expr.get_value ();
3230 : :
3231 : 15523351 : STRIP_ANY_LOCATION_WRAPPER (fn);
3232 : :
3233 : 15523351 : if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
3234 : : {
3235 : : /* Use a separate flag to handle null args. */
3236 : 1905216 : template_id = true;
3237 : 1905216 : tmpl_args = TREE_OPERAND (fn, 1);
3238 : 1905216 : fn = TREE_OPERAND (fn, 0);
3239 : : }
3240 : :
3241 : : /* Find the name of the overloaded function. */
3242 : 15523351 : if (identifier_p (fn))
3243 : : identifier = fn;
3244 : : else
3245 : : {
3246 : 21384494 : functions = fn;
3247 : 15430972 : identifier = OVL_NAME (functions);
3248 : : }
3249 : :
3250 : : /* A call to a namespace-scope function using an unqualified name.
3251 : :
3252 : : Do Koenig lookup -- unless any of the arguments are
3253 : : type-dependent. */
3254 : 15523351 : if (!any_type_dependent_arguments_p (args)
3255 : 15523351 : && !any_dependent_template_arguments_p (tmpl_args))
3256 : : {
3257 : 14684884 : fn = lookup_arg_dependent (identifier, functions, args);
3258 : 14684884 : if (!fn)
3259 : : {
3260 : : /* The unqualified name could not be resolved. */
3261 : 22251 : if (complain & tf_error)
3262 : 387 : fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
3263 : : else
3264 : : fn = identifier;
3265 : : }
3266 : : }
3267 : :
3268 : 15523351 : if (fn && template_id && fn != error_mark_node)
3269 : 1905205 : fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
3270 : :
3271 : 15523351 : return cp_expr (fn, loc);
3272 : : }
3273 : :
3274 : : /* Generate an expression for `FN (ARGS)'. This may change the
3275 : : contents of ARGS.
3276 : :
3277 : : If DISALLOW_VIRTUAL is true, the call to FN will be not generated
3278 : : as a virtual call, even if FN is virtual. (This flag is set when
3279 : : encountering an expression where the function name is explicitly
3280 : : qualified. For example a call to `X::f' never generates a virtual
3281 : : call.)
3282 : :
3283 : : Returns code for the call. */
3284 : :
3285 : : tree
3286 : 270537978 : finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
3287 : : bool koenig_p, tsubst_flags_t complain)
3288 : : {
3289 : 270537978 : tree result;
3290 : 270537978 : tree orig_fn;
3291 : 270537978 : vec<tree, va_gc> *orig_args = *args;
3292 : :
3293 : 270537978 : if (fn == error_mark_node)
3294 : : return error_mark_node;
3295 : :
3296 : 270536977 : gcc_assert (!TYPE_P (fn));
3297 : :
3298 : : /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
3299 : : it so that we can tell this is a call to a known function. */
3300 : 270536977 : fn = maybe_undo_parenthesized_ref (fn);
3301 : :
3302 : 270536977 : STRIP_ANY_LOCATION_WRAPPER (fn);
3303 : :
3304 : 270536977 : orig_fn = fn;
3305 : :
3306 : 270536977 : if (processing_template_decl)
3307 : : {
3308 : : /* If FN is a local extern declaration (or set thereof) in a template,
3309 : : look it up again at instantiation time. */
3310 : 187617863 : if (is_overloaded_fn (fn))
3311 : : {
3312 : 115481061 : tree ifn = get_first_fn (fn);
3313 : 115481061 : if (TREE_CODE (ifn) == FUNCTION_DECL
3314 : 115481061 : && dependent_local_decl_p (ifn))
3315 : 15789 : orig_fn = DECL_NAME (ifn);
3316 : : }
3317 : :
3318 : : /* If the call expression is dependent, build a CALL_EXPR node
3319 : : with no type; type_dependent_expression_p recognizes
3320 : : expressions with no type as being dependent. */
3321 : 187617863 : if (type_dependent_expression_p (fn)
3322 : 187617863 : || any_type_dependent_arguments_p (*args))
3323 : : {
3324 : 168240958 : result = build_min_nt_call_vec (orig_fn, *args);
3325 : 223817946 : SET_EXPR_LOCATION (result, cp_expr_loc_or_input_loc (fn));
3326 : 168240958 : KOENIG_LOOKUP_P (result) = koenig_p;
3327 : : /* Disable the std::move warnings since this call was dependent
3328 : : (c++/89780, c++/107363). This also suppresses the
3329 : : -Wredundant-move warning. */
3330 : 168240958 : suppress_warning (result, OPT_Wpessimizing_move);
3331 : :
3332 : 168240958 : if (cfun && cp_function_chain && !cp_unevaluated_operand)
3333 : : {
3334 : 146111532 : bool abnormal = true;
3335 : 146282953 : for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter)
3336 : : {
3337 : 81228102 : tree fndecl = STRIP_TEMPLATE (*iter);
3338 : 81228102 : if (TREE_CODE (fndecl) != FUNCTION_DECL
3339 : 81228102 : || !TREE_THIS_VOLATILE (fndecl))
3340 : : {
3341 : : abnormal = false;
3342 : : break;
3343 : : }
3344 : : }
3345 : : /* FIXME: Stop warning about falling off end of non-void
3346 : : function. But this is wrong. Even if we only see
3347 : : no-return fns at this point, we could select a
3348 : : future-defined return fn during instantiation. Or
3349 : : vice-versa. */
3350 : 146111532 : if (abnormal)
3351 : 65054851 : current_function_returns_abnormally = 1;
3352 : : }
3353 : 168240958 : if (TREE_CODE (fn) == COMPONENT_REF)
3354 : 83752929 : maybe_generic_this_capture (TREE_OPERAND (fn, 0),
3355 : 83752929 : TREE_OPERAND (fn, 1));
3356 : 168240958 : return result;
3357 : : }
3358 : 19376905 : orig_args = make_tree_vector_copy (*args);
3359 : : }
3360 : :
3361 : 102296019 : if (TREE_CODE (fn) == COMPONENT_REF)
3362 : : {
3363 : 21363825 : tree member = TREE_OPERAND (fn, 1);
3364 : 21363825 : if (BASELINK_P (member))
3365 : : {
3366 : 21183644 : tree object = TREE_OPERAND (fn, 0);
3367 : 42169396 : return build_new_method_call (object, member,
3368 : : args, NULL_TREE,
3369 : : (disallow_virtual
3370 : : ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
3371 : : : LOOKUP_NORMAL),
3372 : : /*fn_p=*/NULL,
3373 : 21183644 : complain);
3374 : : }
3375 : : }
3376 : :
3377 : : /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
3378 : 81112375 : if (TREE_CODE (fn) == ADDR_EXPR
3379 : 81112375 : && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
3380 : 9 : fn = TREE_OPERAND (fn, 0);
3381 : :
3382 : 81112375 : if (is_overloaded_fn (fn))
3383 : 78101084 : fn = baselink_for_fns (fn);
3384 : :
3385 : 81112375 : result = NULL_TREE;
3386 : 81112375 : if (BASELINK_P (fn))
3387 : : {
3388 : 14640205 : tree object;
3389 : :
3390 : : /* A call to a member function. From [over.call.func]:
3391 : :
3392 : : If the keyword this is in scope and refers to the class of
3393 : : that member function, or a derived class thereof, then the
3394 : : function call is transformed into a qualified function call
3395 : : using (*this) as the postfix-expression to the left of the
3396 : : . operator.... [Otherwise] a contrived object of type T
3397 : : becomes the implied object argument.
3398 : :
3399 : : In this situation:
3400 : :
3401 : : struct A { void f(); };
3402 : : struct B : public A {};
3403 : : struct C : public A { void g() { B::f(); }};
3404 : :
3405 : : "the class of that member function" refers to `A'. But 11.2
3406 : : [class.access.base] says that we need to convert 'this' to B* as
3407 : : part of the access, so we pass 'B' to maybe_dummy_object. */
3408 : :
3409 : 14640205 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
3410 : : {
3411 : : /* A constructor call always uses a dummy object. (This constructor
3412 : : call which has the form A::A () is actually invalid and we are
3413 : : going to reject it later in build_new_method_call.) */
3414 : 39 : object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
3415 : : }
3416 : : else
3417 : 14640166 : object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
3418 : : NULL);
3419 : :
3420 : 16082333 : result = build_new_method_call (object, fn, args, NULL_TREE,
3421 : : (disallow_virtual
3422 : : ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
3423 : : : LOOKUP_NORMAL),
3424 : : /*fn_p=*/NULL,
3425 : : complain);
3426 : : }
3427 : 66472170 : else if (concept_check_p (fn))
3428 : : {
3429 : 3 : error_at (EXPR_LOC_OR_LOC (fn, input_location),
3430 : : "cannot call a concept as a function");
3431 : 3 : return error_mark_node;
3432 : : }
3433 : 66472167 : else if (is_overloaded_fn (fn))
3434 : : {
3435 : : /* If the function is an overloaded builtin, resolve it. */
3436 : 63460879 : if (TREE_CODE (fn) == FUNCTION_DECL
3437 : 63460879 : && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
3438 : 14888377 : || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
3439 : 8038963 : result = resolve_overloaded_builtin (input_location, fn, *args,
3440 : : complain & tf_error);
3441 : :
3442 : 8038963 : if (!result)
3443 : : {
3444 : 63221674 : tree alloc_size_attr = NULL_TREE;
3445 : 63221674 : if (warn_calloc_transposed_args
3446 : 553069 : && TREE_CODE (fn) == FUNCTION_DECL
3447 : 63221674 : && (alloc_size_attr
3448 : 410572 : = lookup_attribute ("alloc_size",
3449 : 410572 : TYPE_ATTRIBUTES (TREE_TYPE (fn)))))
3450 : 3215 : if (TREE_VALUE (alloc_size_attr) == NULL_TREE
3451 : 3215 : || TREE_CHAIN (TREE_VALUE (alloc_size_attr)) == NULL_TREE)
3452 : : alloc_size_attr = NULL_TREE;
3453 : 61637102 : if ((warn_sizeof_pointer_memaccess || alloc_size_attr)
3454 : 1584632 : && (complain & tf_warning)
3455 : 1482849 : && !vec_safe_is_empty (*args)
3456 : 64370360 : && !processing_template_decl)
3457 : : {
3458 : : location_t sizeof_arg_loc[6];
3459 : : tree sizeof_arg[6];
3460 : : unsigned int i;
3461 : 8290300 : for (i = 0; i < (alloc_size_attr ? 6 : 3); i++)
3462 : : {
3463 : 3109065 : tree t;
3464 : :
3465 : 3109065 : sizeof_arg_loc[i] = UNKNOWN_LOCATION;
3466 : 3109065 : sizeof_arg[i] = NULL_TREE;
3467 : 3109065 : if (i >= (*args)->length ())
3468 : 610015 : continue;
3469 : 2499050 : t = (**args)[i];
3470 : 2499050 : if (TREE_CODE (t) != SIZEOF_EXPR)
3471 : 2492806 : continue;
3472 : 6244 : if (SIZEOF_EXPR_TYPE_P (t))
3473 : 2304 : sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
3474 : : else
3475 : 3940 : sizeof_arg[i] = TREE_OPERAND (t, 0);
3476 : 6244 : sizeof_arg_loc[i] = EXPR_LOCATION (t);
3477 : : }
3478 : 1036295 : if (warn_sizeof_pointer_memaccess)
3479 : : {
3480 : 1036235 : auto same_p = same_type_ignoring_top_level_qualifiers_p;
3481 : 1036235 : sizeof_pointer_memaccess_warning (sizeof_arg_loc, fn, *args,
3482 : : sizeof_arg, same_p);
3483 : : }
3484 : 1036295 : if (alloc_size_attr)
3485 : 60 : warn_for_calloc (sizeof_arg_loc, fn, *args, sizeof_arg,
3486 : : alloc_size_attr);
3487 : : }
3488 : :
3489 : 63221674 : if ((complain & tf_warning)
3490 : 44267089 : && TREE_CODE (fn) == FUNCTION_DECL
3491 : 21499204 : && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
3492 : 110067 : && vec_safe_length (*args) == 3
3493 : 63331741 : && !any_type_dependent_arguments_p (*args))
3494 : : {
3495 : 110067 : tree arg0 = (*orig_args)[0];
3496 : 110067 : tree arg1 = (*orig_args)[1];
3497 : 110067 : tree arg2 = (*orig_args)[2];
3498 : 110067 : int literal_mask = ((literal_integer_zerop (arg1) << 1)
3499 : 110067 : | (literal_integer_zerop (arg2) << 2));
3500 : 110067 : warn_for_memset (input_location, arg0, arg2, literal_mask);
3501 : : }
3502 : :
3503 : : /* A call to a namespace-scope function. */
3504 : 63221674 : result = build_new_function_call (fn, args, complain);
3505 : : }
3506 : : }
3507 : 3011288 : else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
3508 : : {
3509 : 38516 : if (!vec_safe_is_empty (*args))
3510 : 0 : error ("arguments to destructor are not allowed");
3511 : : /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
3512 : : which case the postfix-expression is a possibly-parenthesized class
3513 : : member access), the function call destroys the object of scalar type
3514 : : denoted by the object expression of the class member access. */
3515 : 38516 : tree ob = TREE_OPERAND (fn, 0);
3516 : 38516 : if (obvalue_p (ob))
3517 : 38498 : result = build_trivial_dtor_call (ob, true);
3518 : : else
3519 : : /* No location to clobber. */
3520 : 18 : result = convert_to_void (ob, ICV_STATEMENT, complain);
3521 : : }
3522 : 2972772 : else if (CLASS_TYPE_P (TREE_TYPE (fn)))
3523 : : /* If the "function" is really an object of class type, it might
3524 : : have an overloaded `operator ()'. */
3525 : 1533015 : result = build_op_call (fn, args, complain);
3526 : :
3527 : 79419892 : if (!result)
3528 : : /* A call where the function is unknown. */
3529 : 1439757 : result = cp_build_function_call_vec (fn, args, complain);
3530 : :
3531 : 81098854 : if (processing_template_decl && result != error_mark_node)
3532 : : {
3533 : 15510027 : if (INDIRECT_REF_P (result))
3534 : 1029062 : result = TREE_OPERAND (result, 0);
3535 : :
3536 : : /* Prune all but the selected function from the original overload
3537 : : set so that we can avoid some duplicate work at instantiation time. */
3538 : 15510027 : if (TREE_CODE (result) == CALL_EXPR
3539 : 15495880 : && really_overloaded_fn (orig_fn))
3540 : : {
3541 : 7170880 : tree sel_fn = CALL_EXPR_FN (result);
3542 : 7170880 : if (TREE_CODE (sel_fn) == COMPONENT_REF)
3543 : : {
3544 : : /* The non-dependent result of build_new_method_call. */
3545 : 2177786 : sel_fn = TREE_OPERAND (sel_fn, 1);
3546 : 2177786 : gcc_assert (BASELINK_P (sel_fn));
3547 : : }
3548 : 4993094 : else if (TREE_CODE (sel_fn) == ADDR_EXPR)
3549 : : /* Our original callee wasn't wrapped in an ADDR_EXPR,
3550 : : so strip this ADDR_EXPR added by build_over_call. */
3551 : 4993094 : sel_fn = TREE_OPERAND (sel_fn, 0);
3552 : : orig_fn = sel_fn;
3553 : : }
3554 : :
3555 : 15510027 : tree r = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
3556 : 15510027 : SET_EXPR_LOCATION (r, input_location);
3557 : 15510027 : KOENIG_LOOKUP_P (r) = koenig_p;
3558 : 15510027 : TREE_NO_WARNING (r) = TREE_NO_WARNING (result);
3559 : 15510027 : release_tree_vector (orig_args);
3560 : 15510027 : result = convert_from_reference (r);
3561 : : }
3562 : :
3563 : : return result;
3564 : : }
3565 : :
3566 : : /* Finish a call to a postfix increment or decrement or EXPR. (Which
3567 : : is indicated by CODE, which should be POSTINCREMENT_EXPR or
3568 : : POSTDECREMENT_EXPR.) */
3569 : :
3570 : : cp_expr
3571 : 2186814 : finish_increment_expr (cp_expr expr, enum tree_code code)
3572 : : {
3573 : : /* input_location holds the location of the trailing operator token.
3574 : : Build a location of the form:
3575 : : expr++
3576 : : ~~~~^~
3577 : : with the caret at the operator token, ranging from the start
3578 : : of EXPR to the end of the operator token. */
3579 : 2186814 : location_t combined_loc = make_location (input_location,
3580 : : expr.get_start (),
3581 : : get_finish (input_location));
3582 : 2186814 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3583 : 2186814 : NULL_TREE, tf_warning_or_error);
3584 : : /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3585 : 2186814 : result.set_location (combined_loc);
3586 : 2186814 : return result;
3587 : : }
3588 : :
3589 : : /* Finish a use of `this'. Returns an expression for `this'. */
3590 : :
3591 : : tree
3592 : 30544403 : finish_this_expr (void)
3593 : : {
3594 : 30544403 : tree result = NULL_TREE;
3595 : :
3596 : 30544403 : if (current_class_ptr)
3597 : : {
3598 : 30544359 : tree type = TREE_TYPE (current_class_ref);
3599 : :
3600 : : /* In a lambda expression, 'this' refers to the captured 'this'. */
3601 : 61088694 : if (LAMBDA_TYPE_P (type))
3602 : 203034 : result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type), true);
3603 : : else
3604 : 30341325 : result = current_class_ptr;
3605 : : }
3606 : :
3607 : 30544359 : if (result)
3608 : : /* The keyword 'this' is a prvalue expression. */
3609 : 30544356 : return rvalue (result);
3610 : :
3611 : 47 : tree fn = current_nonlambda_function ();
3612 : 47 : if (fn && DECL_XOBJ_MEMBER_FUNCTION_P (fn))
3613 : : {
3614 : 4 : auto_diagnostic_group d;
3615 : 4 : error ("%<this%> is unavailable for explicit object member "
3616 : : "functions");
3617 : 4 : tree xobj_parm = DECL_ARGUMENTS (fn);
3618 : 4 : gcc_assert (xobj_parm);
3619 : 4 : tree parm_name = DECL_NAME (xobj_parm);
3620 : :
3621 : 4 : static tree remembered_fn = NULL_TREE;
3622 : : /* Only output this diagnostic once per function. */
3623 : 4 : if (remembered_fn == fn)
3624 : : /* Early escape. */;
3625 : 4 : else if (parm_name)
3626 : 4 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3627 : : "use explicit object parameter %qs instead",
3628 : 2 : IDENTIFIER_POINTER (parm_name));
3629 : : else
3630 : 2 : inform (DECL_SOURCE_LOCATION (xobj_parm),
3631 : : "name the explicit object parameter");
3632 : :
3633 : 4 : remembered_fn = fn;
3634 : 4 : }
3635 : 43 : else if (fn && DECL_STATIC_FUNCTION_P (fn))
3636 : 3 : error ("%<this%> is unavailable for static member functions");
3637 : 40 : else if (fn && processing_contract_condition && DECL_CONSTRUCTOR_P (fn))
3638 : 0 : error ("invalid use of %<this%> before it is valid");
3639 : 40 : else if (fn && processing_contract_condition && DECL_DESTRUCTOR_P (fn))
3640 : 0 : error ("invalid use of %<this%> after it is valid");
3641 : 40 : else if (fn)
3642 : 22 : error ("invalid use of %<this%> in non-member function");
3643 : : else
3644 : 18 : error ("invalid use of %<this%> at top level");
3645 : 47 : return error_mark_node;
3646 : : }
3647 : :
3648 : : /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3649 : : expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3650 : : the TYPE for the type given. If SCOPE is non-NULL, the expression
3651 : : was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3652 : :
3653 : : tree
3654 : 38567 : finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
3655 : : location_t loc, tsubst_flags_t complain)
3656 : : {
3657 : 38567 : if (object == error_mark_node || destructor == error_mark_node)
3658 : : return error_mark_node;
3659 : :
3660 : 38558 : gcc_assert (TYPE_P (destructor));
3661 : :
3662 : 38558 : if (!processing_template_decl)
3663 : : {
3664 : 38537 : if (scope == error_mark_node)
3665 : : {
3666 : 0 : if (complain & tf_error)
3667 : 0 : error_at (loc, "invalid qualifying scope in pseudo-destructor name");
3668 : 0 : return error_mark_node;
3669 : : }
3670 : 38537 : if (is_auto (destructor))
3671 : 3 : destructor = TREE_TYPE (object);
3672 : 38537 : if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
3673 : : {
3674 : 3 : if (complain & tf_error)
3675 : 3 : error_at (loc,
3676 : : "qualified type %qT does not match destructor name ~%qT",
3677 : : scope, destructor);
3678 : 3 : return error_mark_node;
3679 : : }
3680 : :
3681 : :
3682 : : /* [expr.pseudo] says both:
3683 : :
3684 : : The type designated by the pseudo-destructor-name shall be
3685 : : the same as the object type.
3686 : :
3687 : : and:
3688 : :
3689 : : The cv-unqualified versions of the object type and of the
3690 : : type designated by the pseudo-destructor-name shall be the
3691 : : same type.
3692 : :
3693 : : We implement the more generous second sentence, since that is
3694 : : what most other compilers do. */
3695 : 38534 : if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
3696 : : destructor))
3697 : : {
3698 : 12 : if (complain & tf_error)
3699 : 9 : error_at (loc, "%qE is not of type %qT", object, destructor);
3700 : 12 : return error_mark_node;
3701 : : }
3702 : : }
3703 : :
3704 : 38543 : tree type = (type_dependent_expression_p (object)
3705 : 38543 : ? NULL_TREE : void_type_node);
3706 : :
3707 : 38543 : return build3_loc (loc, PSEUDO_DTOR_EXPR, type, object,
3708 : 38543 : scope, destructor);
3709 : : }
3710 : :
3711 : : /* Finish an expression of the form CODE EXPR. */
3712 : :
3713 : : cp_expr
3714 : 30016134 : finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
3715 : : tsubst_flags_t complain)
3716 : : {
3717 : : /* Build a location of the form:
3718 : : ++expr
3719 : : ^~~~~~
3720 : : with the caret at the operator token, ranging from the start
3721 : : of the operator token to the end of EXPR. */
3722 : 30016134 : location_t combined_loc = make_location (op_loc,
3723 : : op_loc, expr.get_finish ());
3724 : 30016134 : cp_expr result = build_x_unary_op (combined_loc, code, expr,
3725 : 30016134 : NULL_TREE, complain);
3726 : : /* TODO: build_x_unary_op doesn't always honor the location. */
3727 : 30016134 : result.set_location (combined_loc);
3728 : :
3729 : 30016134 : if (result == error_mark_node)
3730 : : return result;
3731 : :
3732 : 30015731 : if (!(complain & tf_warning))
3733 : : return result;
3734 : :
3735 : 30015731 : tree result_ovl = result;
3736 : 30015731 : tree expr_ovl = expr;
3737 : :
3738 : 30015731 : if (!processing_template_decl)
3739 : 2416507 : expr_ovl = cp_fully_fold (expr_ovl);
3740 : :
3741 : 30015731 : if (!CONSTANT_CLASS_P (expr_ovl)
3742 : 30015731 : || TREE_OVERFLOW_P (expr_ovl))
3743 : : return result;
3744 : :
3745 : 194849 : if (!processing_template_decl)
3746 : 185006 : result_ovl = cp_fully_fold (result_ovl);
3747 : :
3748 : 194849 : if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
3749 : 9 : overflow_warning (combined_loc, result_ovl);
3750 : :
3751 : : return result;
3752 : : }
3753 : :
3754 : : /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3755 : : elements. */
3756 : :
3757 : : static bool
3758 : 12 : maybe_zero_constructor_nelts (tree expr)
3759 : : {
3760 : 12 : if (CONSTRUCTOR_NELTS (expr) == 0)
3761 : : return true;
3762 : 12 : if (!processing_template_decl)
3763 : : return false;
3764 : 30 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (expr))
3765 : 21 : if (!PACK_EXPANSION_P (elt.value))
3766 : : return false;
3767 : : return true;
3768 : : }
3769 : :
3770 : : /* Finish a compound-literal expression or C++11 functional cast with aggregate
3771 : : initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3772 : : is being cast. */
3773 : :
3774 : : tree
3775 : 6479500 : finish_compound_literal (tree type, tree compound_literal,
3776 : : tsubst_flags_t complain,
3777 : : fcl_t fcl_context)
3778 : : {
3779 : 6479500 : if (type == error_mark_node)
3780 : : return error_mark_node;
3781 : :
3782 : 6479487 : if (TYPE_REF_P (type))
3783 : : {
3784 : 12 : compound_literal
3785 : 12 : = finish_compound_literal (TREE_TYPE (type), compound_literal,
3786 : : complain, fcl_context);
3787 : : /* The prvalue is then used to direct-initialize the reference. */
3788 : 12 : tree r = (perform_implicit_conversion_flags
3789 : 12 : (type, compound_literal, complain, LOOKUP_NORMAL));
3790 : 12 : return convert_from_reference (r);
3791 : : }
3792 : :
3793 : 6479475 : if (!TYPE_OBJ_P (type))
3794 : : {
3795 : : /* DR2351 */
3796 : 60 : if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
3797 : : {
3798 : 12 : if (!processing_template_decl)
3799 : 9 : return void_node;
3800 : 3 : TREE_TYPE (compound_literal) = type;
3801 : 3 : TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
3802 : 3 : CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
3803 : 3 : return compound_literal;
3804 : : }
3805 : 21 : else if (VOID_TYPE_P (type)
3806 : 15 : && processing_template_decl
3807 : 33 : && maybe_zero_constructor_nelts (compound_literal))
3808 : : /* If there are only packs in compound_literal, it could
3809 : : be void{} after pack expansion. */;
3810 : : else
3811 : : {
3812 : 12 : if (complain & tf_error)
3813 : 9 : error ("compound literal of non-object type %qT", type);
3814 : 12 : return error_mark_node;
3815 : : }
3816 : : }
3817 : :
3818 : 6479451 : if (template_placeholder_p (type))
3819 : : {
3820 : 44555 : type = do_auto_deduction (type, compound_literal, type, complain,
3821 : : adc_variable_type);
3822 : 44555 : if (type == error_mark_node)
3823 : : return error_mark_node;
3824 : : }
3825 : : /* C++23 auto{x}. */
3826 : 6434896 : else if (is_auto (type)
3827 : 109 : && !AUTO_IS_DECLTYPE (type)
3828 : 6435003 : && CONSTRUCTOR_NELTS (compound_literal) == 1)
3829 : : {
3830 : 101 : if (is_constrained_auto (type))
3831 : : {
3832 : 2 : if (complain & tf_error)
3833 : 2 : error ("%<auto{x}%> cannot be constrained");
3834 : 2 : return error_mark_node;
3835 : : }
3836 : 99 : else if (cxx_dialect < cxx23)
3837 : 1 : pedwarn (input_location, OPT_Wc__23_extensions,
3838 : : "%<auto{x}%> only available with "
3839 : : "%<-std=c++23%> or %<-std=gnu++23%>");
3840 : 99 : type = do_auto_deduction (type, compound_literal, type, complain,
3841 : : adc_variable_type);
3842 : 99 : if (type == error_mark_node)
3843 : : return error_mark_node;
3844 : : }
3845 : :
3846 : : /* Used to hold a copy of the compound literal in a template. */
3847 : 6479348 : tree orig_cl = NULL_TREE;
3848 : :
3849 : 6479348 : if (processing_template_decl)
3850 : : {
3851 : 3088441 : const bool dependent_p
3852 : 3088441 : = (instantiation_dependent_expression_p (compound_literal)
3853 : 3088441 : || dependent_type_p (type));
3854 : 639373 : if (dependent_p)
3855 : : /* We're about to return, no need to copy. */
3856 : : orig_cl = compound_literal;
3857 : : else
3858 : : /* We're going to need a copy. */
3859 : 639373 : orig_cl = unshare_constructor (compound_literal);
3860 : 3088441 : TREE_TYPE (orig_cl) = type;
3861 : : /* Mark the expression as a compound literal. */
3862 : 3088441 : TREE_HAS_CONSTRUCTOR (orig_cl) = 1;
3863 : : /* And as instantiation-dependent. */
3864 : 3088441 : CONSTRUCTOR_IS_DEPENDENT (orig_cl) = dependent_p;
3865 : 3088441 : if (fcl_context == fcl_c99)
3866 : 84 : CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl) = 1;
3867 : : /* If the compound literal is dependent, we're done for now. */
3868 : 3088441 : if (dependent_p)
3869 : : return orig_cl;
3870 : : /* Otherwise, do go on to e.g. check narrowing. */
3871 : : }
3872 : :
3873 : 4030280 : type = complete_type (type);
3874 : :
3875 : 4030280 : if (TYPE_NON_AGGREGATE_CLASS (type))
3876 : : {
3877 : : /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3878 : : everywhere that deals with function arguments would be a pain, so
3879 : : just wrap it in a TREE_LIST. The parser set a flag so we know
3880 : : that it came from T{} rather than T({}). */
3881 : 506336 : CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
3882 : 506336 : compound_literal = build_tree_list (NULL_TREE, compound_literal);
3883 : 506336 : return build_functional_cast (input_location, type,
3884 : 506336 : compound_literal, complain);
3885 : : }
3886 : :
3887 : 3523944 : if (TREE_CODE (type) == ARRAY_TYPE
3888 : 3523944 : && check_array_initializer (NULL_TREE, type, compound_literal))
3889 : 9 : return error_mark_node;
3890 : 3523935 : compound_literal = reshape_init (type, compound_literal, complain);
3891 : 3327176 : if (SCALAR_TYPE_P (type)
3892 : 397969 : && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
3893 : 3573756 : && !check_narrowing (type, compound_literal, complain))
3894 : 102 : return error_mark_node;
3895 : 3523833 : if (TREE_CODE (type) == ARRAY_TYPE
3896 : 3523833 : && TYPE_DOMAIN (type) == NULL_TREE)
3897 : : {
3898 : 734 : cp_complete_array_type_or_error (&type, compound_literal,
3899 : : false, complain);
3900 : 734 : if (type == error_mark_node)
3901 : : return error_mark_node;
3902 : : }
3903 : 3523830 : compound_literal = digest_init_flags (type, compound_literal,
3904 : : LOOKUP_NORMAL | LOOKUP_NO_NARROWING,
3905 : : complain);
3906 : 3523830 : if (compound_literal == error_mark_node)
3907 : : return error_mark_node;
3908 : :
3909 : : /* If we're in a template, return the original compound literal. */
3910 : 3523281 : if (orig_cl)
3911 : : return orig_cl;
3912 : :
3913 : 2923810 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3914 : : {
3915 : 2568183 : TREE_HAS_CONSTRUCTOR (compound_literal) = true;
3916 : 2568183 : if (fcl_context == fcl_c99)
3917 : 32270 : CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
3918 : : }
3919 : :
3920 : : /* Put static/constant array temporaries in static variables. */
3921 : : /* FIXME all C99 compound literals should be variables rather than C++
3922 : : temporaries, unless they are used as an aggregate initializer. */
3923 : 3748943 : if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
3924 : 2101805 : && fcl_context == fcl_c99
3925 : 80 : && TREE_CODE (type) == ARRAY_TYPE
3926 : 28 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
3927 : 2923838 : && initializer_constant_valid_p (compound_literal, type))
3928 : : {
3929 : 28 : tree decl = create_temporary_var (type);
3930 : 28 : DECL_CONTEXT (decl) = NULL_TREE;
3931 : 28 : DECL_INITIAL (decl) = compound_literal;
3932 : 28 : TREE_STATIC (decl) = 1;
3933 : 28 : if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
3934 : : {
3935 : : /* 5.19 says that a constant expression can include an
3936 : : lvalue-rvalue conversion applied to "a glvalue of literal type
3937 : : that refers to a non-volatile temporary object initialized
3938 : : with a constant expression". Rather than try to communicate
3939 : : that this VAR_DECL is a temporary, just mark it constexpr. */
3940 : 24 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
3941 : 24 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
3942 : 24 : TREE_CONSTANT (decl) = true;
3943 : : }
3944 : 28 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
3945 : 28 : decl = pushdecl_top_level (decl);
3946 : 28 : DECL_NAME (decl) = make_anon_name ();
3947 : 28 : SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
3948 : : /* Make sure the destructor is callable. */
3949 : 28 : tree clean = cxx_maybe_build_cleanup (decl, complain);
3950 : 28 : if (clean == error_mark_node)
3951 : : return error_mark_node;
3952 : 28 : return decl;
3953 : : }
3954 : :
3955 : : /* Represent other compound literals with TARGET_EXPR so we produce
3956 : : a prvalue, and can elide copies. */
3957 : 2923782 : if (!VECTOR_TYPE_P (type)
3958 : 2892150 : && (TREE_CODE (compound_literal) == CONSTRUCTOR
3959 : 355621 : || TREE_CODE (compound_literal) == VEC_INIT_EXPR))
3960 : : {
3961 : : /* The CONSTRUCTOR is now an initializer, not a compound literal. */
3962 : 2536529 : if (TREE_CODE (compound_literal) == CONSTRUCTOR)
3963 : 2536529 : TREE_HAS_CONSTRUCTOR (compound_literal) = false;
3964 : 2536529 : compound_literal = get_target_expr (compound_literal, complain);
3965 : : }
3966 : : else
3967 : : /* For e.g. int{42} just make sure it's a prvalue. */
3968 : 387253 : compound_literal = rvalue (compound_literal);
3969 : :
3970 : : return compound_literal;
3971 : : }
3972 : :
3973 : : /* Return the declaration for the function-name variable indicated by
3974 : : ID. */
3975 : :
3976 : : tree
3977 : 171463 : finish_fname (tree id)
3978 : : {
3979 : 171463 : tree decl;
3980 : :
3981 : 171463 : decl = fname_decl (input_location, C_RID_CODE (id), id);
3982 : 171463 : if (processing_template_decl && current_function_decl
3983 : 102142 : && decl != error_mark_node)
3984 : 102142 : decl = DECL_NAME (decl);
3985 : 171463 : return decl;
3986 : : }
3987 : :
3988 : : /* Finish a translation unit. */
3989 : :
3990 : : void
3991 : 91978 : finish_translation_unit (void)
3992 : : {
3993 : : /* In case there were missing closebraces,
3994 : : get us back to the global binding level. */
3995 : 91978 : pop_everything ();
3996 : 183956 : while (current_namespace != global_namespace)
3997 : 0 : pop_namespace ();
3998 : :
3999 : : /* Do file scope __FUNCTION__ et al. */
4000 : 91978 : finish_fname_decls ();
4001 : :
4002 : 91978 : if (vec_safe_length (scope_chain->omp_declare_target_attribute))
4003 : : {
4004 : 12 : cp_omp_declare_target_attr
4005 : 12 : a = scope_chain->omp_declare_target_attribute->pop ();
4006 : 12 : if (!errorcount)
4007 : 9 : error ("%qs without corresponding %qs",
4008 : : a.device_type >= 0 ? "#pragma omp begin declare target"
4009 : : : "#pragma omp declare target",
4010 : : "#pragma omp end declare target");
4011 : 24 : vec_safe_truncate (scope_chain->omp_declare_target_attribute, 0);
4012 : : }
4013 : 91978 : if (vec_safe_length (scope_chain->omp_begin_assumes))
4014 : : {
4015 : 3 : if (!errorcount)
4016 : 3 : error ("%qs without corresponding %qs",
4017 : : "#pragma omp begin assumes", "#pragma omp end assumes");
4018 : 3 : vec_safe_truncate (scope_chain->omp_begin_assumes, 0);
4019 : : }
4020 : 91978 : }
4021 : :
4022 : : /* Finish a template type parameter, specified as AGGR IDENTIFIER.
4023 : : Returns the parameter. */
4024 : :
4025 : : tree
4026 : 135468089 : finish_template_type_parm (tree aggr, tree identifier)
4027 : : {
4028 : 135468089 : if (aggr != class_type_node)
4029 : : {
4030 : 0 : permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
4031 : 0 : aggr = class_type_node;
4032 : : }
4033 : :
4034 : 135468089 : return build_tree_list (aggr, identifier);
4035 : : }
4036 : :
4037 : : /* Finish a template template parameter, specified as AGGR IDENTIFIER.
4038 : : Returns the parameter. */
4039 : :
4040 : : tree
4041 : 310038 : finish_template_template_parm (tree aggr, tree identifier)
4042 : : {
4043 : 310038 : tree decl = build_decl (input_location,
4044 : : TYPE_DECL, identifier, NULL_TREE);
4045 : :
4046 : 310038 : tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
4047 : 310038 : DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
4048 : 310038 : DECL_TEMPLATE_RESULT (tmpl) = decl;
4049 : 310038 : DECL_ARTIFICIAL (decl) = 1;
4050 : :
4051 : : /* Associate the constraints with the underlying declaration,
4052 : : not the template. */
4053 : 310038 : tree constr = current_template_constraints ();
4054 : 310038 : set_constraints (decl, constr);
4055 : :
4056 : 310038 : end_template_decl ();
4057 : :
4058 : 310038 : gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
4059 : :
4060 : 310038 : check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
4061 : : /*is_primary=*/true, /*is_partial=*/false,
4062 : : /*is_friend=*/0);
4063 : :
4064 : 310038 : return finish_template_type_parm (aggr, tmpl);
4065 : : }
4066 : :
4067 : : /* ARGUMENT is the default-argument value for a template template
4068 : : parameter. If ARGUMENT is invalid, issue error messages and return
4069 : : the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
4070 : :
4071 : : tree
4072 : 839 : check_template_template_default_arg (tree argument)
4073 : : {
4074 : 839 : if (TREE_CODE (argument) != TEMPLATE_DECL
4075 : : && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
4076 : : && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
4077 : : {
4078 : : if (TREE_CODE (argument) == TYPE_DECL)
4079 : : {
4080 : 18 : if (tree t = maybe_get_template_decl_from_type_decl (argument))
4081 : 18 : if (TREE_CODE (t) == TEMPLATE_DECL)
4082 : : return t;
4083 : 15 : error ("invalid use of type %qT as a default value for a template "
4084 : 15 : "template-parameter", TREE_TYPE (argument));
4085 : : }
4086 : : else
4087 : 0 : error ("invalid default argument for a template template parameter");
4088 : 15 : return error_mark_node;
4089 : : }
4090 : :
4091 : : return argument;
4092 : : }
4093 : :
4094 : : /* Begin a class definition, as indicated by T. */
4095 : :
4096 : : tree
4097 : 24701883 : begin_class_definition (tree t)
4098 : : {
4099 : 24701883 : if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
4100 : 39 : return error_mark_node;
4101 : :
4102 : 24701934 : if (processing_template_parmlist && !LAMBDA_TYPE_P (t))
4103 : : {
4104 : 9 : error ("definition of %q#T inside template parameter list", t);
4105 : 9 : return error_mark_node;
4106 : : }
4107 : :
4108 : : /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
4109 : : are passed the same as decimal scalar types. */
4110 : 24701835 : if (TREE_CODE (t) == RECORD_TYPE
4111 : 24267179 : && !processing_template_decl)
4112 : : {
4113 : 8173113 : tree ns = TYPE_CONTEXT (t);
4114 : 8173113 : if (ns && TREE_CODE (ns) == NAMESPACE_DECL
4115 : 6551260 : && DECL_CONTEXT (ns) == std_node
4116 : 780301 : && DECL_NAME (ns)
4117 : 8953394 : && id_equal (DECL_NAME (ns), "decimal"))
4118 : : {
4119 : 150 : const char *n = TYPE_NAME_STRING (t);
4120 : 150 : if ((strcmp (n, "decimal32") == 0)
4121 : 101 : || (strcmp (n, "decimal64") == 0)
4122 : 46 : || (strcmp (n, "decimal128") == 0))
4123 : 147 : TYPE_TRANSPARENT_AGGR (t) = 1;
4124 : : }
4125 : : }
4126 : :
4127 : : /* A non-implicit typename comes from code like:
4128 : :
4129 : : template <typename T> struct A {
4130 : : template <typename U> struct A<T>::B ...
4131 : :
4132 : : This is erroneous. */
4133 : 16528722 : else if (TREE_CODE (t) == TYPENAME_TYPE)
4134 : : {
4135 : 0 : error ("invalid definition of qualified type %qT", t);
4136 : 0 : t = error_mark_node;
4137 : : }
4138 : :
4139 : 24701835 : if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
4140 : : {
4141 : 0 : t = make_class_type (RECORD_TYPE);
4142 : 0 : pushtag (make_anon_name (), t);
4143 : : }
4144 : :
4145 : 24701835 : if (TYPE_BEING_DEFINED (t))
4146 : : {
4147 : 0 : t = make_class_type (TREE_CODE (t));
4148 : 0 : pushtag (TYPE_IDENTIFIER (t), t);
4149 : : }
4150 : :
4151 : 24701835 : if (modules_p ())
4152 : : {
4153 : 101595 : if (!module_may_redeclare (TYPE_NAME (t)))
4154 : 0 : return error_mark_node;
4155 : 101595 : set_instantiating_module (TYPE_NAME (t));
4156 : 101595 : set_defining_module (TYPE_NAME (t));
4157 : : }
4158 : :
4159 : 24701835 : maybe_process_partial_specialization (t);
4160 : 24701835 : pushclass (t);
4161 : 24701835 : TYPE_BEING_DEFINED (t) = 1;
4162 : 24701835 : class_binding_level->defining_class_p = 1;
4163 : :
4164 : 24701835 : if (flag_pack_struct)
4165 : : {
4166 : 90 : tree v;
4167 : 90 : TYPE_PACKED (t) = 1;
4168 : : /* Even though the type is being defined for the first time
4169 : : here, there might have been a forward declaration, so there
4170 : : might be cv-qualified variants of T. */
4171 : 90 : for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
4172 : 0 : TYPE_PACKED (v) = 1;
4173 : : }
4174 : : /* Reset the interface data, at the earliest possible
4175 : : moment, as it might have been set via a class foo;
4176 : : before. */
4177 : 50809590 : if (! TYPE_UNNAMED_P (t))
4178 : : {
4179 : 24064360 : struct c_fileinfo *finfo = \
4180 : 24064360 : get_fileinfo (LOCATION_FILE (input_location));
4181 : 24064360 : CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
4182 : 24064360 : SET_CLASSTYPE_INTERFACE_UNKNOWN_X
4183 : : (t, finfo->interface_unknown);
4184 : : }
4185 : 24701835 : reset_specialization ();
4186 : :
4187 : : /* Make a declaration for this class in its own scope. */
4188 : 24701835 : build_self_reference ();
4189 : :
4190 : 24701835 : return t;
4191 : : }
4192 : :
4193 : : /* Finish the member declaration given by DECL. */
4194 : :
4195 : : void
4196 : 328640602 : finish_member_declaration (tree decl)
4197 : : {
4198 : 328640602 : if (decl == error_mark_node || decl == NULL_TREE)
4199 : : return;
4200 : :
4201 : 328639674 : if (decl == void_type_node)
4202 : : /* The COMPONENT was a friend, not a member, and so there's
4203 : : nothing for us to do. */
4204 : : return;
4205 : :
4206 : : /* We should see only one DECL at a time. */
4207 : 328639674 : gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
4208 : :
4209 : : /* Don't add decls after definition. */
4210 : 328639695 : gcc_assert (TYPE_BEING_DEFINED (current_class_type)
4211 : : /* We can add lambda types when late parsing default
4212 : : arguments. */
4213 : : || LAMBDA_TYPE_P (TREE_TYPE (decl)));
4214 : :
4215 : : /* Set up access control for DECL. */
4216 : 328639674 : TREE_PRIVATE (decl)
4217 : 328639674 : = (current_access_specifier == access_private_node);
4218 : 328639674 : TREE_PROTECTED (decl)
4219 : 328639674 : = (current_access_specifier == access_protected_node);
4220 : 328639674 : if (TREE_CODE (decl) == TEMPLATE_DECL)
4221 : : {
4222 : 37934856 : TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
4223 : 37934856 : TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
4224 : : }
4225 : :
4226 : : /* Mark the DECL as a member of the current class, unless it's
4227 : : a member of an enumeration. */
4228 : 328639674 : if (TREE_CODE (decl) != CONST_DECL)
4229 : 326439538 : DECL_CONTEXT (decl) = current_class_type;
4230 : :
4231 : : /* Remember the single FIELD_DECL an anonymous aggregate type is used for. */
4232 : 328639674 : if (TREE_CODE (decl) == FIELD_DECL
4233 : 328639674 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
4234 : : {
4235 : 148859 : gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))));
4236 : 148859 : ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl))) = decl;
4237 : : }
4238 : :
4239 : 328639674 : if (TREE_CODE (decl) == USING_DECL)
4240 : : /* Avoid debug info for class-scope USING_DECLS for now, we'll
4241 : : call cp_emit_debug_info_for_using later. */
4242 : 2757198 : DECL_IGNORED_P (decl) = 1;
4243 : :
4244 : : /* Check for bare parameter packs in the non-static data member
4245 : : declaration. */
4246 : 328639674 : if (TREE_CODE (decl) == FIELD_DECL)
4247 : : {
4248 : 23720468 : if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
4249 : 9 : TREE_TYPE (decl) = error_mark_node;
4250 : 23720468 : if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
4251 : 0 : DECL_ATTRIBUTES (decl) = NULL_TREE;
4252 : : }
4253 : :
4254 : : /* [dcl.link]
4255 : :
4256 : : A C language linkage is ignored for the names of class members
4257 : : and the member function type of class member functions. */
4258 : 328639674 : if (DECL_LANG_SPECIFIC (decl))
4259 : 299824520 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
4260 : :
4261 : 328639674 : bool add = false;
4262 : :
4263 : : /* Functions and non-functions are added differently. */
4264 : 328639674 : if (DECL_DECLARES_FUNCTION_P (decl))
4265 : 174602522 : add = add_method (current_class_type, decl, false);
4266 : : /* Enter the DECL into the scope of the class, if the class
4267 : : isn't a closure (whose fields are supposed to be unnamed). */
4268 : 154037152 : else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
4269 : 152162976 : || maybe_push_used_methods (decl)
4270 : 304777925 : || pushdecl_class_level (decl))
4271 : : add = true;
4272 : :
4273 : 174602522 : if (add)
4274 : : {
4275 : : /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
4276 : : go at the beginning. The reason is that
4277 : : legacy_nonfn_member_lookup searches the list in order, and we
4278 : : want a field name to override a type name so that the "struct
4279 : : stat hack" will work. In particular:
4280 : :
4281 : : struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
4282 : :
4283 : : is valid. */
4284 : :
4285 : 328634004 : if (TREE_CODE (decl) == TYPE_DECL)
4286 : 108432757 : TYPE_FIELDS (current_class_type)
4287 : 216865514 : = chainon (TYPE_FIELDS (current_class_type), decl);
4288 : : else
4289 : : {
4290 : 220201247 : DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
4291 : 220201247 : TYPE_FIELDS (current_class_type) = decl;
4292 : : }
4293 : :
4294 : 328634004 : maybe_add_class_template_decl_list (current_class_type, decl,
4295 : : /*friend_p=*/0);
4296 : : }
4297 : : }
4298 : :
4299 : : /* Finish processing a complete template declaration. The PARMS are
4300 : : the template parameters. */
4301 : :
4302 : : void
4303 : 77239667 : finish_template_decl (tree parms)
4304 : : {
4305 : 77239667 : if (parms)
4306 : 77239661 : end_template_decl ();
4307 : : else
4308 : 6 : end_specialization ();
4309 : 77239667 : }
4310 : :
4311 : : // Returns the template type of the class scope being entered. If we're
4312 : : // entering a constrained class scope. TYPE is the class template
4313 : : // scope being entered and we may need to match the intended type with
4314 : : // a constrained specialization. For example:
4315 : : //
4316 : : // template<Object T>
4317 : : // struct S { void f(); }; #1
4318 : : //
4319 : : // template<Object T>
4320 : : // void S<T>::f() { } #2
4321 : : //
4322 : : // We check, in #2, that S<T> refers precisely to the type declared by
4323 : : // #1 (i.e., that the constraints match). Note that the following should
4324 : : // be an error since there is no specialization of S<T> that is
4325 : : // unconstrained, but this is not diagnosed here.
4326 : : //
4327 : : // template<typename T>
4328 : : // void S<T>::f() { }
4329 : : //
4330 : : // We cannot diagnose this problem here since this function also matches
4331 : : // qualified template names that are not part of a definition. For example:
4332 : : //
4333 : : // template<Integral T, Floating_point U>
4334 : : // typename pair<T, U>::first_type void f(T, U);
4335 : : //
4336 : : // Here, it is unlikely that there is a partial specialization of
4337 : : // pair constrained for Integral and Floating_point arguments.
4338 : : //
4339 : : // The general rule is: if a constrained specialization with matching
4340 : : // constraints is found return that type. Also note that if TYPE is not a
4341 : : // class-type (e.g. a typename type), then no fixup is needed.
4342 : :
4343 : : static tree
4344 : 4084090 : fixup_template_type (tree type)
4345 : : {
4346 : : // Find the template parameter list at the a depth appropriate to
4347 : : // the scope we're trying to enter.
4348 : 4084090 : tree parms = current_template_parms;
4349 : 4084090 : int depth = template_class_depth (type);
4350 : 9061792 : for (int n = current_template_depth; n > depth && parms; --n)
4351 : 893612 : parms = TREE_CHAIN (parms);
4352 : 4084090 : if (!parms)
4353 : : return type;
4354 : 4084085 : tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
4355 : 4084085 : tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
4356 : :
4357 : : // Search for a specialization whose type and constraints match.
4358 : 4084085 : tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
4359 : 4084085 : tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
4360 : 8076783 : while (specs)
4361 : : {
4362 : 4088431 : tree spec_constr = get_constraints (TREE_VALUE (specs));
4363 : :
4364 : : // If the type and constraints match a specialization, then we
4365 : : // are entering that type.
4366 : 4088431 : if (same_type_p (type, TREE_TYPE (specs))
4367 : 4088431 : && equivalent_constraints (cur_constr, spec_constr))
4368 : 95733 : return TREE_TYPE (specs);
4369 : 3992698 : specs = TREE_CHAIN (specs);
4370 : : }
4371 : :
4372 : : // If no specialization matches, then must return the type
4373 : : // previously found.
4374 : : return type;
4375 : : }
4376 : :
4377 : : /* Finish processing a template-id (which names a type) of the form
4378 : : NAME < ARGS >. Return the TYPE_DECL for the type named by the
4379 : : template-id. If ENTERING_SCOPE is nonzero we are about to enter
4380 : : the scope of template-id indicated. */
4381 : :
4382 : : tree
4383 : 157998082 : finish_template_type (tree name, tree args, int entering_scope)
4384 : : {
4385 : 157998082 : tree type;
4386 : :
4387 : 157998082 : type = lookup_template_class (name, args,
4388 : : NULL_TREE, NULL_TREE,
4389 : : tf_warning_or_error | tf_user);
4390 : 157998079 : if (entering_scope)
4391 : 18310982 : type = adjust_type_for_entering_scope (type);
4392 : :
4393 : : /* If we might be entering the scope of a partial specialization,
4394 : : find the one with the right constraints. */
4395 : 157998079 : if (flag_concepts
4396 : 43514583 : && entering_scope
4397 : 4230149 : && CLASS_TYPE_P (type)
4398 : 4196399 : && CLASSTYPE_TEMPLATE_INFO (type)
4399 : 4196393 : && dependent_type_p (type)
4400 : 162082169 : && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
4401 : 4084090 : type = fixup_template_type (type);
4402 : :
4403 : 157998079 : if (type == error_mark_node)
4404 : : return type;
4405 : 157995838 : else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
4406 : 134527945 : return TYPE_STUB_DECL (type);
4407 : : else
4408 : 23467893 : return TYPE_NAME (type);
4409 : : }
4410 : :
4411 : : /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
4412 : : Return a TREE_LIST containing the ACCESS_SPECIFIER and the
4413 : : BASE_CLASS, or NULL_TREE if an error occurred. The
4414 : : ACCESS_SPECIFIER is one of
4415 : : access_{default,public,protected_private}_node. For a virtual base
4416 : : we set TREE_TYPE. */
4417 : :
4418 : : tree
4419 : 10527888 : finish_base_specifier (tree base, tree access, bool virtual_p)
4420 : : {
4421 : 10527888 : tree result;
4422 : :
4423 : 10527888 : if (base == error_mark_node)
4424 : : {
4425 : 0 : error ("invalid base-class specification");
4426 : 0 : result = NULL_TREE;
4427 : : }
4428 : 10527888 : else if (! MAYBE_CLASS_TYPE_P (base))
4429 : : {
4430 : 3 : error ("%qT is not a class type", base);
4431 : 3 : result = NULL_TREE;
4432 : : }
4433 : : else
4434 : : {
4435 : 10527885 : if (cp_type_quals (base) != 0)
4436 : : {
4437 : : /* DR 484: Can a base-specifier name a cv-qualified
4438 : : class type? */
4439 : 12 : base = TYPE_MAIN_VARIANT (base);
4440 : : }
4441 : 10527885 : result = build_tree_list (access, base);
4442 : 10527885 : if (virtual_p)
4443 : 25132 : TREE_TYPE (result) = integer_type_node;
4444 : : }
4445 : :
4446 : 10527888 : return result;
4447 : : }
4448 : :
4449 : : /* If FNS is a member function, a set of member functions, or a
4450 : : template-id referring to one or more member functions, return a
4451 : : BASELINK for FNS, incorporating the current access context.
4452 : : Otherwise, return FNS unchanged. */
4453 : :
4454 : : tree
4455 : 121710176 : baselink_for_fns (tree fns)
4456 : : {
4457 : 121710176 : tree scope;
4458 : 121710176 : tree cl;
4459 : :
4460 : 121710176 : if (BASELINK_P (fns)
4461 : 121710176 : || error_operand_p (fns))
4462 : : return fns;
4463 : :
4464 : 107094569 : scope = ovl_scope (fns);
4465 : 107094569 : if (!CLASS_TYPE_P (scope))
4466 : : return fns;
4467 : :
4468 : 5959947 : cl = currently_open_derived_class (scope);
4469 : 5959947 : if (!cl)
4470 : 4163274 : cl = scope;
4471 : 5959947 : tree access_path = TYPE_BINFO (cl);
4472 : 5959947 : tree conv_path = (cl == scope ? access_path
4473 : 744582 : : lookup_base (cl, scope, ba_any, NULL, tf_none));
4474 : 5959947 : return build_baselink (conv_path, access_path, fns, /*optype=*/NULL_TREE);
4475 : : }
4476 : :
4477 : : /* Returns true iff DECL is a variable from a function outside
4478 : : the current one. */
4479 : :
4480 : : static bool
4481 : 1869270821 : outer_var_p (tree decl)
4482 : : {
4483 : : /* These should have been stripped or otherwise handled by the caller. */
4484 : 1869270821 : gcc_checking_assert (!REFERENCE_REF_P (decl));
4485 : :
4486 : 1213488710 : return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
4487 : 1684696385 : && DECL_FUNCTION_SCOPE_P (decl)
4488 : : /* Don't get confused by temporaries. */
4489 : 1428393267 : && DECL_NAME (decl)
4490 : 3286672980 : && (DECL_CONTEXT (decl) != current_function_decl
4491 : 1412526707 : || parsing_nsdmi ()));
4492 : : }
4493 : :
4494 : : /* As above, but also checks that DECL is automatic. */
4495 : :
4496 : : bool
4497 : 1869270821 : outer_automatic_var_p (tree decl)
4498 : : {
4499 : 1869270821 : return (outer_var_p (decl)
4500 : 1869270821 : && !TREE_STATIC (decl));
4501 : : }
4502 : :
4503 : : /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
4504 : : rewrite it for lambda capture.
4505 : :
4506 : : If ODR_USE is true, we're being called from mark_use, and we complain about
4507 : : use of constant variables. If ODR_USE is false, we're being called for the
4508 : : id-expression, and we do lambda capture. */
4509 : :
4510 : : tree
4511 : 2144923 : process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
4512 : : {
4513 : 2144923 : if (cp_unevaluated_operand)
4514 : : {
4515 : 1207144 : tree type = TREE_TYPE (decl);
4516 : 1207144 : if (!dependent_type_p (type)
4517 : 1207144 : && variably_modified_type_p (type, NULL_TREE))
4518 : : /* VLAs are used even in unevaluated context. */;
4519 : : else
4520 : : /* It's not a use (3.2) if we're in an unevaluated context. */
4521 : 1207138 : return decl;
4522 : : }
4523 : 937785 : if (decl == error_mark_node)
4524 : : return decl;
4525 : :
4526 : 937785 : tree context = DECL_CONTEXT (decl);
4527 : 937785 : tree containing_function = current_function_decl;
4528 : 937785 : tree lambda_stack = NULL_TREE;
4529 : 937785 : tree lambda_expr = NULL_TREE;
4530 : 937785 : tree initializer = convert_from_reference (decl);
4531 : 937785 : tree var = strip_normal_capture_proxy (decl);
4532 : :
4533 : : /* Mark it as used now even if the use is ill-formed. */
4534 : 937785 : if (!mark_used (decl, complain))
4535 : 3 : return error_mark_node;
4536 : :
4537 : 937782 : if (parsing_nsdmi ())
4538 : : containing_function = NULL_TREE;
4539 : :
4540 : 1875156 : if (containing_function && LAMBDA_FUNCTION_P (containing_function))
4541 : : {
4542 : : /* Check whether we've already built a proxy. */
4543 : 937488 : tree d = retrieve_local_specialization (var);
4544 : :
4545 : 937488 : if (d && d != decl && is_capture_proxy (d))
4546 : : {
4547 : 506172 : if (DECL_CONTEXT (d) == containing_function)
4548 : : /* We already have an inner proxy. */
4549 : : return d;
4550 : : else
4551 : : /* We need to capture an outer proxy. */
4552 : 2495 : return process_outer_var_ref (d, complain, odr_use);
4553 : : }
4554 : : }
4555 : :
4556 : : /* If we are in a lambda function, we can move out until we hit
4557 : : 1. the context,
4558 : : 2. a non-lambda function, or
4559 : : 3. a non-default capturing lambda function. */
4560 : 865102 : while (context != containing_function
4561 : : /* containing_function can be null with invalid generic lambdas. */
4562 : 865102 : && containing_function
4563 : 1298930 : && LAMBDA_FUNCTION_P (containing_function))
4564 : : {
4565 : 433828 : tree closure = DECL_CONTEXT (containing_function);
4566 : 433828 : lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
4567 : :
4568 : 433828 : if (TYPE_CLASS_SCOPE_P (closure))
4569 : : /* A lambda in an NSDMI (c++/64496). */
4570 : : break;
4571 : :
4572 : 433825 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4573 : : break;
4574 : :
4575 : 433492 : lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
4576 : :
4577 : 433492 : containing_function = decl_function_context (containing_function);
4578 : : }
4579 : :
4580 : : /* In a lambda within a template, wait until instantiation time to implicitly
4581 : : capture a parameter pack. We want to wait because we don't know if we're
4582 : : capturing the whole pack or a single element, and it's OK to wait because
4583 : : find_parameter_packs_r walks into the lambda body. */
4584 : 431610 : if (context == containing_function
4585 : 431610 : && DECL_PACK_P (decl))
4586 : : return decl;
4587 : :
4588 : 402940 : if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
4589 : : {
4590 : 6 : if (complain & tf_error)
4591 : 6 : error ("cannot capture member %qD of anonymous union", decl);
4592 : 6 : return error_mark_node;
4593 : : }
4594 : : /* Do lambda capture when processing the id-expression, not when
4595 : : odr-using a variable. */
4596 : 402934 : if (!odr_use && context == containing_function)
4597 : 804608 : decl = add_default_capture (lambda_stack,
4598 : 402304 : /*id=*/DECL_NAME (decl), initializer);
4599 : : /* Only an odr-use of an outer automatic variable causes an
4600 : : error, and a constant variable can decay to a prvalue
4601 : : constant without odr-use. So don't complain yet. */
4602 : 630 : else if (!odr_use && decl_constant_var_p (var))
4603 : : return var;
4604 : 257 : else if (lambda_expr)
4605 : : {
4606 : 42 : if (complain & tf_error)
4607 : : {
4608 : 42 : auto_diagnostic_group d;
4609 : 42 : error ("%qD is not captured", decl);
4610 : 42 : tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
4611 : 42 : if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
4612 : 39 : inform (location_of (closure),
4613 : : "the lambda has no capture-default");
4614 : 3 : else if (TYPE_CLASS_SCOPE_P (closure))
4615 : 3 : inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
4616 : : "capture variables from the enclosing context",
4617 : 3 : TYPE_CONTEXT (closure));
4618 : 42 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4619 : 42 : }
4620 : 42 : return error_mark_node;
4621 : : }
4622 : 215 : else if (processing_contract_condition && (TREE_CODE (decl) == PARM_DECL))
4623 : : /* Use of a parameter in a contract condition is fine. */
4624 : : return decl;
4625 : : else
4626 : : {
4627 : 45 : if (complain & tf_error)
4628 : : {
4629 : 39 : auto_diagnostic_group d;
4630 : 57 : error (VAR_P (decl)
4631 : : ? G_("use of local variable with automatic storage from "
4632 : : "containing function")
4633 : : : G_("use of parameter from containing function"));
4634 : 39 : inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
4635 : 39 : }
4636 : 45 : return error_mark_node;
4637 : : }
4638 : 402304 : return decl;
4639 : : }
4640 : :
4641 : : /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4642 : : id-expression. (See cp_parser_id_expression for details.) SCOPE,
4643 : : if non-NULL, is the type or namespace used to explicitly qualify
4644 : : ID_EXPRESSION. DECL is the entity to which that name has been
4645 : : resolved.
4646 : :
4647 : : *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4648 : : constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4649 : : be set to true if this expression isn't permitted in a
4650 : : constant-expression, but it is otherwise not set by this function.
4651 : : *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4652 : : constant-expression, but a non-constant expression is also
4653 : : permissible.
4654 : :
4655 : : DONE is true if this expression is a complete postfix-expression;
4656 : : it is false if this expression is followed by '->', '[', '(', etc.
4657 : : ADDRESS_P is true iff this expression is the operand of '&'.
4658 : : TEMPLATE_P is true iff the qualified-id was of the form
4659 : : "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4660 : : appears as a template argument.
4661 : :
4662 : : If an error occurs, and it is the kind of error that might cause
4663 : : the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4664 : : is the caller's responsibility to issue the message. *ERROR_MSG
4665 : : will be a string with static storage duration, so the caller need
4666 : : not "free" it.
4667 : :
4668 : : Return an expression for the entity, after issuing appropriate
4669 : : diagnostics. This function is also responsible for transforming a
4670 : : reference to a non-static member into a COMPONENT_REF that makes
4671 : : the use of "this" explicit.
4672 : :
4673 : : Upon return, *IDK will be filled in appropriately. */
4674 : : static cp_expr
4675 : 595587978 : finish_id_expression_1 (tree id_expression,
4676 : : tree decl,
4677 : : tree scope,
4678 : : cp_id_kind *idk,
4679 : : bool integral_constant_expression_p,
4680 : : bool allow_non_integral_constant_expression_p,
4681 : : bool *non_integral_constant_expression_p,
4682 : : bool template_p,
4683 : : bool done,
4684 : : bool address_p,
4685 : : bool template_arg_p,
4686 : : const char **error_msg,
4687 : : location_t location)
4688 : : {
4689 : 595587978 : decl = strip_using_decl (decl);
4690 : :
4691 : : /* Initialize the output parameters. */
4692 : 595587978 : *idk = CP_ID_KIND_NONE;
4693 : 595587978 : *error_msg = NULL;
4694 : :
4695 : 595587978 : if (id_expression == error_mark_node)
4696 : 12 : return error_mark_node;
4697 : : /* If we have a template-id, then no further lookup is
4698 : : required. If the template-id was for a template-class, we
4699 : : will sometimes have a TYPE_DECL at this point. */
4700 : 595587966 : else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4701 : 566362141 : || TREE_CODE (decl) == TYPE_DECL)
4702 : : ;
4703 : : /* Look up the name. */
4704 : : else
4705 : : {
4706 : 566361263 : if (decl == error_mark_node)
4707 : : {
4708 : : /* Name lookup failed. */
4709 : 89045 : if (scope
4710 : 89045 : && (!TYPE_P (scope)
4711 : 116 : || (!dependentish_scope_p (scope)
4712 : 112 : && !(identifier_p (id_expression)
4713 : 97 : && IDENTIFIER_CONV_OP_P (id_expression)
4714 : 3 : && dependent_type_p (TREE_TYPE (id_expression))))))
4715 : : {
4716 : : /* If the qualifying type is non-dependent (and the name
4717 : : does not name a conversion operator to a dependent
4718 : : type), issue an error. */
4719 : 357 : qualified_name_lookup_error (scope, id_expression, decl, location);
4720 : 357 : return error_mark_node;
4721 : : }
4722 : 88688 : else if (!scope)
4723 : : {
4724 : : /* It may be resolved via Koenig lookup. */
4725 : 88678 : *idk = CP_ID_KIND_UNQUALIFIED;
4726 : 88678 : return id_expression;
4727 : : }
4728 : : else
4729 : : decl = id_expression;
4730 : : }
4731 : :
4732 : : /* Remember that the name was used in the definition of
4733 : : the current class so that we can check later to see if
4734 : : the meaning would have been different after the class
4735 : : was entirely defined. */
4736 : 566272218 : if (!scope && decl != error_mark_node && identifier_p (id_expression))
4737 : 514311055 : maybe_note_name_used_in_class (id_expression, decl);
4738 : :
4739 : : /* A use in unevaluated operand might not be instantiated appropriately
4740 : : if tsubst_copy builds a dummy parm, or if we never instantiate a
4741 : : generic lambda, so mark it now. */
4742 : 566272228 : if (processing_template_decl && cp_unevaluated_operand)
4743 : 9093066 : mark_type_use (decl);
4744 : :
4745 : : /* Disallow uses of local variables from containing functions, except
4746 : : within lambda-expressions. */
4747 : 566272228 : if (outer_automatic_var_p (decl))
4748 : : {
4749 : 1743870 : decl = process_outer_var_ref (decl, tf_warning_or_error);
4750 : 1743870 : if (decl == error_mark_node)
4751 : 81 : return error_mark_node;
4752 : : }
4753 : :
4754 : : /* Also disallow uses of function parameters outside the function
4755 : : body, except inside an unevaluated context (i.e. decltype). */
4756 : 566272147 : if (TREE_CODE (decl) == PARM_DECL
4757 : 239202392 : && DECL_CONTEXT (decl) == NULL_TREE
4758 : 4094076 : && !cp_unevaluated_operand
4759 : 448 : && !processing_contract_condition
4760 : 566272190 : && !processing_omp_trait_property_expr)
4761 : : {
4762 : 25 : *error_msg = G_("use of parameter outside function body");
4763 : 25 : return error_mark_node;
4764 : : }
4765 : : }
4766 : :
4767 : : /* If we didn't find anything, or what we found was a type,
4768 : : then this wasn't really an id-expression. */
4769 : 595498825 : if (TREE_CODE (decl) == TEMPLATE_DECL
4770 : 595498825 : && !DECL_FUNCTION_TEMPLATE_P (decl))
4771 : : {
4772 : 59 : *error_msg = G_("missing template arguments");
4773 : 59 : return error_mark_node;
4774 : : }
4775 : 595498766 : else if (TREE_CODE (decl) == TYPE_DECL
4776 : 595497888 : || TREE_CODE (decl) == NAMESPACE_DECL)
4777 : : {
4778 : 893 : *error_msg = G_("expected primary-expression");
4779 : 893 : return error_mark_node;
4780 : : }
4781 : :
4782 : : /* If the name resolved to a template parameter, there is no
4783 : : need to look it up again later. */
4784 : 27286239 : if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
4785 : 605271557 : || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4786 : : {
4787 : 17512555 : tree r;
4788 : :
4789 : 17512555 : *idk = CP_ID_KIND_NONE;
4790 : 17512555 : if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
4791 : 0 : decl = TEMPLATE_PARM_DECL (decl);
4792 : 17512555 : r = DECL_INITIAL (decl);
4793 : 17512555 : if (CLASS_TYPE_P (TREE_TYPE (r)) && !CP_TYPE_CONST_P (TREE_TYPE (r)))
4794 : : {
4795 : : /* If the entity is a template parameter object for a template
4796 : : parameter of type T, the type of the expression is const T. */
4797 : 135 : tree ctype = TREE_TYPE (r);
4798 : 135 : ctype = cp_build_qualified_type (ctype, (cp_type_quals (ctype)
4799 : : | TYPE_QUAL_CONST));
4800 : 135 : r = build1 (VIEW_CONVERT_EXPR, ctype, r);
4801 : : }
4802 : 17512555 : r = convert_from_reference (r);
4803 : 17512555 : if (integral_constant_expression_p
4804 : 2861729 : && !dependent_type_p (TREE_TYPE (decl))
4805 : 19893071 : && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
4806 : : {
4807 : 81 : if (!allow_non_integral_constant_expression_p)
4808 : 6 : error ("template parameter %qD of type %qT is not allowed in "
4809 : : "an integral constant expression because it is not of "
4810 : 6 : "integral or enumeration type", decl, TREE_TYPE (decl));
4811 : 81 : *non_integral_constant_expression_p = true;
4812 : : }
4813 : 17512555 : return r;
4814 : : }
4815 : 577985318 : else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE)
4816 : : {
4817 : 9 : gcc_checking_assert (scope);
4818 : 9 : *idk = CP_ID_KIND_QUALIFIED;
4819 : 9 : cp_warn_deprecated_use_scopes (scope);
4820 : 9 : decl = finish_qualified_id_expr (scope, decl, done, address_p,
4821 : : template_p, template_arg_p,
4822 : : tf_warning_or_error);
4823 : : }
4824 : : else
4825 : : {
4826 : 577985309 : if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4827 : 29225825 : && variable_template_p (TREE_OPERAND (decl, 0))
4828 : 583740410 : && !concept_check_p (decl))
4829 : : /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
4830 : : considered type-dependent) now, so that the dependence test that
4831 : : follows gives us the right answer: if it represents a non-dependent
4832 : : variable template-id then finish_template_variable will yield the
4833 : : corresponding non-dependent VAR_DECL. */
4834 : 5755101 : decl = finish_template_variable (decl);
4835 : :
4836 : 577985309 : bool dependent_p = type_dependent_expression_p (decl);
4837 : :
4838 : : /* If the declaration was explicitly qualified indicate
4839 : : that. The semantics of `A::f(3)' are different than
4840 : : `f(3)' if `f' is virtual. */
4841 : 1155970618 : *idk = (scope
4842 : 577985309 : ? CP_ID_KIND_QUALIFIED
4843 : 510593121 : : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
4844 : 510593121 : ? CP_ID_KIND_TEMPLATE_ID
4845 : : : (dependent_p
4846 : 496883614 : ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
4847 : : : CP_ID_KIND_UNQUALIFIED)));
4848 : :
4849 : 577985309 : if (dependent_p
4850 : 577985309 : && !scope
4851 : 339038218 : && DECL_P (decl)
4852 : 895834460 : && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
4853 : : /* Dependent type attributes on the decl mean that the TREE_TYPE is
4854 : : wrong, so just return the identifier. */
4855 : 39 : return id_expression;
4856 : :
4857 : 577985270 : if (DECL_CLASS_TEMPLATE_P (decl))
4858 : : {
4859 : 0 : error ("use of class template %qT as expression", decl);
4860 : 0 : return error_mark_node;
4861 : : }
4862 : :
4863 : 577985270 : if (TREE_CODE (decl) == TREE_LIST)
4864 : : {
4865 : : /* Ambiguous reference to base members. */
4866 : 0 : auto_diagnostic_group d;
4867 : 0 : error ("request for member %qD is ambiguous in "
4868 : : "multiple inheritance lattice", id_expression);
4869 : 0 : print_candidates (decl);
4870 : 0 : return error_mark_node;
4871 : 0 : }
4872 : :
4873 : : /* Mark variable-like entities as used. Functions are similarly
4874 : : marked either below or after overload resolution. */
4875 : 577985270 : if ((VAR_P (decl)
4876 : 421355543 : || TREE_CODE (decl) == PARM_DECL
4877 : 182153182 : || TREE_CODE (decl) == CONST_DECL
4878 : 172379498 : || TREE_CODE (decl) == RESULT_DECL)
4879 : 826961315 : && !mark_used (decl))
4880 : 12 : return error_mark_node;
4881 : :
4882 : : /* Only certain kinds of names are allowed in constant
4883 : : expression. Template parameters have already
4884 : : been handled above. */
4885 : 577985255 : if (! error_operand_p (decl)
4886 : 577984970 : && !dependent_p
4887 : 577984970 : && integral_constant_expression_p
4888 : 54736160 : && !decl_constant_var_p (decl)
4889 : 45519943 : && TREE_CODE (decl) != CONST_DECL
4890 : 39673007 : && !builtin_valid_in_constant_expr_p (decl)
4891 : 617617008 : && !concept_check_p (decl))
4892 : : {
4893 : 39492326 : if (!allow_non_integral_constant_expression_p)
4894 : : {
4895 : 30 : error ("%qD cannot appear in a constant-expression", decl);
4896 : 30 : return error_mark_node;
4897 : : }
4898 : 39492296 : *non_integral_constant_expression_p = true;
4899 : : }
4900 : :
4901 : 577985225 : if (tree wrap = maybe_get_tls_wrapper_call (decl))
4902 : : /* Replace an evaluated use of the thread_local variable with
4903 : : a call to its wrapper. */
4904 : : decl = wrap;
4905 : 577984748 : else if (concept_check_p (decl))
4906 : : {
4907 : : /* Nothing more to do. All of the analysis for concept checks
4908 : : is done by build_conept_id, called from the parser. */
4909 : : }
4910 : 573468712 : else if (scope)
4911 : : {
4912 : 66839156 : if (TREE_CODE (decl) == SCOPE_REF)
4913 : : {
4914 : 4363 : gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
4915 : 4363 : decl = TREE_OPERAND (decl, 1);
4916 : : }
4917 : :
4918 : 66839156 : decl = (adjust_result_of_qualified_name_lookup
4919 : 66839156 : (decl, scope, current_nonlambda_class_type()));
4920 : :
4921 : 66839156 : cp_warn_deprecated_use_scopes (scope);
4922 : :
4923 : 66839156 : if (TYPE_P (scope))
4924 : 10078872 : decl = finish_qualified_id_expr (scope,
4925 : : decl,
4926 : : done,
4927 : : address_p,
4928 : : template_p,
4929 : : template_arg_p,
4930 : : tf_warning_or_error);
4931 : : else
4932 : 56760284 : decl = convert_from_reference (decl);
4933 : : }
4934 : 506629556 : else if (TREE_CODE (decl) == FIELD_DECL)
4935 : : {
4936 : : /* Since SCOPE is NULL here, this is an unqualified name.
4937 : : Access checking has been performed during name lookup
4938 : : already. Turn off checking to avoid duplicate errors. */
4939 : 54286045 : push_deferring_access_checks (dk_no_check);
4940 : 54286045 : decl = finish_non_static_data_member (decl, NULL_TREE,
4941 : : /*qualifying_scope=*/NULL_TREE);
4942 : 54286045 : pop_deferring_access_checks ();
4943 : : }
4944 : 452343511 : else if (is_overloaded_fn (decl))
4945 : : {
4946 : : /* We only need to look at the first function,
4947 : : because all the fns share the attribute we're
4948 : : concerned with (all member fns or all non-members). */
4949 : 51903496 : tree first_fn = get_first_fn (decl);
4950 : 51903496 : first_fn = STRIP_TEMPLATE (first_fn);
4951 : :
4952 : 51903496 : if (!template_arg_p
4953 : 51903496 : && (TREE_CODE (first_fn) == USING_DECL
4954 : 51901724 : || (TREE_CODE (first_fn) == FUNCTION_DECL
4955 : 51901724 : && DECL_FUNCTION_MEMBER_P (first_fn)
4956 : 30313238 : && !shared_member_p (decl))))
4957 : : {
4958 : : /* A set of member functions. */
4959 : 24378830 : decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
4960 : 24378830 : return finish_class_member_access_expr (decl, id_expression,
4961 : : /*template_p=*/false,
4962 : 24378830 : tf_warning_or_error);
4963 : : }
4964 : :
4965 : 27524666 : decl = baselink_for_fns (decl);
4966 : : }
4967 : : else
4968 : : {
4969 : 395073192 : if (DECL_P (decl) && DECL_NONLOCAL (decl)
4970 : 401764563 : && DECL_CLASS_SCOPE_P (decl))
4971 : : {
4972 : 1324548 : tree context = context_for_name_lookup (decl);
4973 : 1324548 : if (context != current_class_type)
4974 : : {
4975 : 772928 : tree path = currently_open_derived_class (context);
4976 : 772928 : if (!path)
4977 : : /* PATH can be null for using an enum of an unrelated
4978 : : class; we checked its access in lookup_using_decl.
4979 : :
4980 : : ??? Should this case make a clone instead, like
4981 : : handle_using_decl? */
4982 : 10 : gcc_assert (TREE_CODE (decl) == CONST_DECL);
4983 : : else
4984 : 772918 : perform_or_defer_access_check (TYPE_BINFO (path),
4985 : : decl, decl,
4986 : : tf_warning_or_error);
4987 : : }
4988 : : }
4989 : :
4990 : 400440015 : decl = convert_from_reference (decl);
4991 : : }
4992 : : }
4993 : :
4994 : 553606404 : return cp_expr (decl, location);
4995 : : }
4996 : :
4997 : : /* As per finish_id_expression_1, but adding a wrapper node
4998 : : around the result if needed to express LOCATION. */
4999 : :
5000 : : cp_expr
5001 : 595587978 : finish_id_expression (tree id_expression,
5002 : : tree decl,
5003 : : tree scope,
5004 : : cp_id_kind *idk,
5005 : : bool integral_constant_expression_p,
5006 : : bool allow_non_integral_constant_expression_p,
5007 : : bool *non_integral_constant_expression_p,
5008 : : bool template_p,
5009 : : bool done,
5010 : : bool address_p,
5011 : : bool template_arg_p,
5012 : : const char **error_msg,
5013 : : location_t location)
5014 : : {
5015 : 595587978 : cp_expr result
5016 : 595587978 : = finish_id_expression_1 (id_expression, decl, scope, idk,
5017 : : integral_constant_expression_p,
5018 : : allow_non_integral_constant_expression_p,
5019 : : non_integral_constant_expression_p,
5020 : : template_p, done, address_p, template_arg_p,
5021 : : error_msg, location);
5022 : 595587975 : return result.maybe_add_location_wrapper ();
5023 : : }
5024 : :
5025 : : /* Implement the __typeof keyword: Return the type of EXPR, suitable for
5026 : : use as a type-specifier. */
5027 : :
5028 : : tree
5029 : 18890480 : finish_typeof (tree expr)
5030 : : {
5031 : 18890480 : tree type;
5032 : :
5033 : 18890480 : if (type_dependent_expression_p (expr))
5034 : : {
5035 : 18799122 : type = cxx_make_type (TYPEOF_TYPE);
5036 : 18799122 : TYPEOF_TYPE_EXPR (type) = expr;
5037 : 18799122 : SET_TYPE_STRUCTURAL_EQUALITY (type);
5038 : :
5039 : 18799122 : return type;
5040 : : }
5041 : :
5042 : 91358 : expr = mark_type_use (expr);
5043 : :
5044 : 91358 : type = unlowered_expr_type (expr);
5045 : :
5046 : 91358 : if (!type || type == unknown_type_node)
5047 : : {
5048 : 3 : error ("type of %qE is unknown", expr);
5049 : 3 : return error_mark_node;
5050 : : }
5051 : :
5052 : : return type;
5053 : : }
5054 : :
5055 : : /* Implement the __underlying_type keyword: Return the underlying
5056 : : type of TYPE, suitable for use as a type-specifier. */
5057 : :
5058 : : tree
5059 : 39595 : finish_underlying_type (tree type)
5060 : : {
5061 : 39595 : if (!complete_type_or_else (type, NULL_TREE))
5062 : 3 : return error_mark_node;
5063 : :
5064 : 39592 : if (TREE_CODE (type) != ENUMERAL_TYPE)
5065 : : {
5066 : 24 : error ("%qT is not an enumeration type", type);
5067 : 24 : return error_mark_node;
5068 : : }
5069 : :
5070 : 39568 : tree underlying_type = ENUM_UNDERLYING_TYPE (type);
5071 : :
5072 : : /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
5073 : : includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
5074 : : See finish_enum_value_list for details. */
5075 : 39568 : if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
5076 : 52 : underlying_type
5077 : 52 : = c_common_type_for_mode (TYPE_MODE (underlying_type),
5078 : 52 : TYPE_UNSIGNED (underlying_type));
5079 : :
5080 : : return underlying_type;
5081 : : }
5082 : :
5083 : : /* Implement the __type_pack_element keyword: Return the type
5084 : : at index IDX within TYPES. */
5085 : :
5086 : : static tree
5087 : 83752 : finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
5088 : : {
5089 : 83752 : idx = maybe_constant_value (idx);
5090 : 83752 : if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx)))
5091 : : {
5092 : 7 : if (complain & tf_error)
5093 : 4 : error ("pack index is not an integral constant");
5094 : 7 : return error_mark_node;
5095 : : }
5096 : 83745 : if (tree_int_cst_sgn (idx) < 0)
5097 : : {
5098 : 5 : if (complain & tf_error)
5099 : 5 : error ("pack index is negative");
5100 : 5 : return error_mark_node;
5101 : : }
5102 : 83740 : if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
5103 : : {
5104 : 25 : if (complain & tf_error)
5105 : 19 : error ("pack index is out of range");
5106 : 25 : return error_mark_node;
5107 : : }
5108 : 83715 : return TREE_VEC_ELT (types, tree_to_shwi (idx));
5109 : : }
5110 : :
5111 : : /* In a pack-index T...[N], return the element at index IDX within TYPES.
5112 : : PARENTHESIZED_P is true iff the pack index was wrapped in (). */
5113 : :
5114 : : tree
5115 : 133 : pack_index_element (tree idx, tree types, bool parenthesized_p,
5116 : : tsubst_flags_t complain)
5117 : : {
5118 : 133 : tree r = finish_type_pack_element (idx, types, complain);
5119 : 133 : if (parenthesized_p)
5120 : : /* For the benefit of decltype(auto). */
5121 : 22 : r = force_paren_expr (r);
5122 : 133 : return r;
5123 : : }
5124 : :
5125 : : /* Implement the __direct_bases keyword: Return the direct base classes
5126 : : of type. */
5127 : :
5128 : : tree
5129 : 15 : calculate_direct_bases (tree type, tsubst_flags_t complain)
5130 : : {
5131 : 15 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5132 : 15 : || !NON_UNION_CLASS_TYPE_P (type))
5133 : 8 : return make_tree_vec (0);
5134 : :
5135 : 7 : releasing_vec vector;
5136 : 7 : vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
5137 : 7 : tree binfo;
5138 : 7 : unsigned i;
5139 : :
5140 : : /* Virtual bases are initialized first */
5141 : 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5142 : 13 : if (BINFO_VIRTUAL_P (binfo))
5143 : 2 : vec_safe_push (vector, binfo);
5144 : :
5145 : : /* Now non-virtuals */
5146 : 20 : for (i = 0; base_binfos->iterate (i, &binfo); i++)
5147 : 13 : if (!BINFO_VIRTUAL_P (binfo))
5148 : 11 : vec_safe_push (vector, binfo);
5149 : :
5150 : 7 : tree bases_vec = make_tree_vec (vector->length ());
5151 : :
5152 : 27 : for (i = 0; i < vector->length (); ++i)
5153 : 13 : TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
5154 : :
5155 : 7 : return bases_vec;
5156 : 7 : }
5157 : :
5158 : : /* Implement the __bases keyword: Return the base classes
5159 : : of type */
5160 : :
5161 : : /* Find morally non-virtual base classes by walking binfo hierarchy */
5162 : : /* Virtual base classes are handled separately in finish_bases */
5163 : :
5164 : : static tree
5165 : 73 : dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
5166 : : {
5167 : : /* Don't walk bases of virtual bases */
5168 : 73 : return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
5169 : : }
5170 : :
5171 : : static tree
5172 : 73 : dfs_calculate_bases_post (tree binfo, void *data_)
5173 : : {
5174 : 73 : vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
5175 : 73 : if (!BINFO_VIRTUAL_P (binfo))
5176 : 48 : vec_safe_push (*data, BINFO_TYPE (binfo));
5177 : 73 : return NULL_TREE;
5178 : : }
5179 : :
5180 : : /* Calculates the morally non-virtual base classes of a class */
5181 : : static vec<tree, va_gc> *
5182 : 16 : calculate_bases_helper (tree type)
5183 : : {
5184 : 16 : vec<tree, va_gc> *vector = make_tree_vector ();
5185 : :
5186 : : /* Now add non-virtual base classes in order of construction */
5187 : 16 : if (TYPE_BINFO (type))
5188 : 16 : dfs_walk_all (TYPE_BINFO (type),
5189 : : dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
5190 : 16 : return vector;
5191 : : }
5192 : :
5193 : : tree
5194 : 12 : calculate_bases (tree type, tsubst_flags_t complain)
5195 : : {
5196 : 12 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
5197 : 12 : || !NON_UNION_CLASS_TYPE_P (type))
5198 : 5 : return make_tree_vec (0);
5199 : :
5200 : 7 : releasing_vec vector;
5201 : 7 : tree bases_vec = NULL_TREE;
5202 : 7 : unsigned i;
5203 : 7 : vec<tree, va_gc> *vbases;
5204 : 7 : tree binfo;
5205 : :
5206 : : /* First go through virtual base classes */
5207 : 7 : for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
5208 : 16 : vec_safe_iterate (vbases, i, &binfo); i++)
5209 : : {
5210 : 9 : releasing_vec vbase_bases
5211 : 9 : = calculate_bases_helper (BINFO_TYPE (binfo));
5212 : 9 : vec_safe_splice (vector, vbase_bases);
5213 : 9 : }
5214 : :
5215 : : /* Now for the non-virtual bases */
5216 : 7 : releasing_vec nonvbases = calculate_bases_helper (type);
5217 : 7 : vec_safe_splice (vector, nonvbases);
5218 : :
5219 : : /* Note that during error recovery vector->length can even be zero. */
5220 : 7 : if (vector->length () > 1)
5221 : : {
5222 : : /* Last element is entire class, so don't copy */
5223 : 6 : bases_vec = make_tree_vec (vector->length () - 1);
5224 : :
5225 : 53 : for (i = 0; i < vector->length () - 1; ++i)
5226 : 41 : TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
5227 : : }
5228 : : else
5229 : 1 : bases_vec = make_tree_vec (0);
5230 : :
5231 : 7 : return bases_vec;
5232 : 7 : }
5233 : :
5234 : : tree
5235 : 28 : finish_bases (tree type, bool direct)
5236 : : {
5237 : 28 : tree bases = NULL_TREE;
5238 : :
5239 : 28 : if (!processing_template_decl)
5240 : : {
5241 : : /* Parameter packs can only be used in templates */
5242 : 0 : error ("parameter pack %<__bases%> only valid in template declaration");
5243 : 0 : return error_mark_node;
5244 : : }
5245 : :
5246 : 28 : bases = cxx_make_type (BASES);
5247 : 28 : BASES_TYPE (bases) = type;
5248 : 28 : BASES_DIRECT (bases) = direct;
5249 : 28 : SET_TYPE_STRUCTURAL_EQUALITY (bases);
5250 : :
5251 : 28 : return bases;
5252 : : }
5253 : :
5254 : : /* Perform C++-specific checks for __builtin_offsetof before calling
5255 : : fold_offsetof. */
5256 : :
5257 : : tree
5258 : 2381 : finish_offsetof (tree object_ptr, tree expr, location_t loc)
5259 : : {
5260 : : /* If we're processing a template, we can't finish the semantics yet.
5261 : : Otherwise we can fold the entire expression now. */
5262 : 2381 : if (processing_template_decl)
5263 : : {
5264 : 60 : expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
5265 : 60 : SET_EXPR_LOCATION (expr, loc);
5266 : 60 : return expr;
5267 : : }
5268 : :
5269 : 2321 : if (expr == error_mark_node)
5270 : : return error_mark_node;
5271 : :
5272 : 2304 : if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
5273 : : {
5274 : 6 : error ("cannot apply %<offsetof%> to destructor %<~%T%>",
5275 : 6 : TREE_OPERAND (expr, 2));
5276 : 6 : return error_mark_node;
5277 : : }
5278 : 4581 : if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr))
5279 : 4581 : || TREE_TYPE (expr) == unknown_type_node)
5280 : : {
5281 : 30 : while (TREE_CODE (expr) == COMPONENT_REF
5282 : 30 : || TREE_CODE (expr) == COMPOUND_EXPR)
5283 : 12 : expr = TREE_OPERAND (expr, 1);
5284 : :
5285 : 18 : if (DECL_P (expr))
5286 : : {
5287 : 0 : auto_diagnostic_group d;
5288 : 0 : error ("cannot apply %<offsetof%> to member function %qD", expr);
5289 : 0 : inform (DECL_SOURCE_LOCATION (expr), "declared here");
5290 : 0 : }
5291 : : else
5292 : 18 : error ("cannot apply %<offsetof%> to member function");
5293 : 18 : return error_mark_node;
5294 : : }
5295 : 2280 : if (TREE_CODE (expr) == CONST_DECL)
5296 : : {
5297 : 3 : error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
5298 : 3 : return error_mark_node;
5299 : : }
5300 : 2277 : if (REFERENCE_REF_P (expr))
5301 : 9 : expr = TREE_OPERAND (expr, 0);
5302 : 2277 : if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
5303 : 3 : return error_mark_node;
5304 : 2274 : if (warn_invalid_offsetof
5305 : 2274 : && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
5306 : 2274 : && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
5307 : 2319 : && cp_unevaluated_operand == 0)
5308 : 45 : warning_at (loc, OPT_Winvalid_offsetof, "%<offsetof%> within "
5309 : : "non-standard-layout type %qT is conditionally-supported",
5310 : 45 : TREE_TYPE (TREE_TYPE (object_ptr)));
5311 : 2274 : return fold_offsetof (expr);
5312 : : }
5313 : :
5314 : : /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
5315 : : function is broken out from the above for the benefit of the tree-ssa
5316 : : project. */
5317 : :
5318 : : void
5319 : 335592 : simplify_aggr_init_expr (tree *tp)
5320 : : {
5321 : 335592 : tree aggr_init_expr = *tp;
5322 : :
5323 : : /* Form an appropriate CALL_EXPR. */
5324 : 335592 : tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
5325 : 335592 : tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
5326 : 335592 : tree type = TREE_TYPE (slot);
5327 : :
5328 : 335592 : tree call_expr;
5329 : 335592 : enum style_t { ctor, arg, pcc } style;
5330 : :
5331 : 335592 : if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
5332 : : style = ctor;
5333 : : #ifdef PCC_STATIC_STRUCT_RETURN
5334 : : else if (1)
5335 : : style = pcc;
5336 : : #endif
5337 : : else
5338 : : {
5339 : 84957 : gcc_assert (TREE_ADDRESSABLE (type));
5340 : : style = arg;
5341 : : }
5342 : :
5343 : 335592 : call_expr = build_call_array_loc (input_location,
5344 : 335592 : TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
5345 : : fn,
5346 : 335592 : aggr_init_expr_nargs (aggr_init_expr),
5347 : 335592 : AGGR_INIT_EXPR_ARGP (aggr_init_expr));
5348 : 335592 : TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
5349 : 335592 : CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
5350 : 335592 : CALL_EXPR_OPERATOR_SYNTAX (call_expr)
5351 : 335592 : = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
5352 : 335592 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
5353 : 335592 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
5354 : 335592 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = AGGR_INIT_EXPR_MUST_TAIL (aggr_init_expr);
5355 : :
5356 : 335592 : if (style == ctor)
5357 : : {
5358 : : /* Replace the first argument to the ctor with the address of the
5359 : : slot. */
5360 : 250635 : cxx_mark_addressable (slot);
5361 : 250635 : CALL_EXPR_ARG (call_expr, 0) =
5362 : 250635 : build1 (ADDR_EXPR, build_pointer_type (type), slot);
5363 : : }
5364 : 84957 : else if (style == arg)
5365 : : {
5366 : : /* Just mark it addressable here, and leave the rest to
5367 : : expand_call{,_inline}. */
5368 : 84957 : cxx_mark_addressable (slot);
5369 : 84957 : CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
5370 : 84957 : call_expr = cp_build_init_expr (slot, call_expr);
5371 : : }
5372 : : else if (style == pcc)
5373 : : {
5374 : : /* If we're using the non-reentrant PCC calling convention, then we
5375 : : need to copy the returned value out of the static buffer into the
5376 : : SLOT. */
5377 : : push_deferring_access_checks (dk_no_check);
5378 : : call_expr = build_aggr_init (slot, call_expr,
5379 : : DIRECT_BIND | LOOKUP_ONLYCONVERTING,
5380 : : tf_warning_or_error);
5381 : : pop_deferring_access_checks ();
5382 : : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
5383 : : }
5384 : :
5385 : 335592 : if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
5386 : : {
5387 : 2899 : tree init = build_zero_init (type, NULL_TREE,
5388 : : /*static_storage_p=*/false);
5389 : 2899 : init = cp_build_init_expr (slot, init);
5390 : 2899 : call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
5391 : : init, call_expr);
5392 : : }
5393 : :
5394 : 335592 : *tp = call_expr;
5395 : 335592 : }
5396 : :
5397 : : /* Emit all thunks to FN that should be emitted when FN is emitted. */
5398 : :
5399 : : void
5400 : 46532495 : emit_associated_thunks (tree fn)
5401 : : {
5402 : : /* When we use vcall offsets, we emit thunks with the virtual
5403 : : functions to which they thunk. The whole point of vcall offsets
5404 : : is so that you can know statically the entire set of thunks that
5405 : : will ever be needed for a given virtual function, thereby
5406 : : enabling you to output all the thunks with the function itself. */
5407 : 46532495 : if (DECL_VIRTUAL_P (fn)
5408 : : /* Do not emit thunks for extern template instantiations. */
5409 : 919049 : && ! DECL_REALLY_EXTERN (fn)
5410 : : /* Do not emit thunks for tentative decls, those will be processed
5411 : : again at_eof if really needed. */
5412 : 47397112 : && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn)))
5413 : : {
5414 : 863978 : tree thunk;
5415 : :
5416 : 1732156 : for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
5417 : : {
5418 : 4200 : if (!THUNK_ALIAS (thunk))
5419 : : {
5420 : 4200 : use_thunk (thunk, /*emit_p=*/1);
5421 : 4200 : if (DECL_RESULT_THUNK_P (thunk))
5422 : : {
5423 : 178 : tree probe;
5424 : :
5425 : 178 : for (probe = DECL_THUNKS (thunk);
5426 : 327 : probe; probe = DECL_CHAIN (probe))
5427 : 149 : use_thunk (probe, /*emit_p=*/1);
5428 : : }
5429 : : }
5430 : : else
5431 : 0 : gcc_assert (!DECL_THUNKS (thunk));
5432 : : }
5433 : : }
5434 : 46532495 : }
5435 : :
5436 : : /* Generate RTL for FN. */
5437 : :
5438 : : bool
5439 : 134010965 : expand_or_defer_fn_1 (tree fn)
5440 : : {
5441 : : /* When the parser calls us after finishing the body of a template
5442 : : function, we don't really want to expand the body. */
5443 : 134010965 : if (processing_template_decl)
5444 : : {
5445 : : /* Normally, collection only occurs in rest_of_compilation. So,
5446 : : if we don't collect here, we never collect junk generated
5447 : : during the processing of templates until we hit a
5448 : : non-template function. It's not safe to do this inside a
5449 : : nested class, though, as the parser may have local state that
5450 : : is not a GC root. */
5451 : 81029243 : if (!function_depth)
5452 : 80672276 : ggc_collect ();
5453 : 81029243 : return false;
5454 : : }
5455 : :
5456 : 52981722 : gcc_assert (DECL_SAVED_TREE (fn));
5457 : :
5458 : : /* We make a decision about linkage for these functions at the end
5459 : : of the compilation. Until that point, we do not want the back
5460 : : end to output them -- but we do want it to see the bodies of
5461 : : these functions so that it can inline them as appropriate. */
5462 : 52981722 : if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn))
5463 : : {
5464 : 52732847 : if (DECL_INTERFACE_KNOWN (fn))
5465 : : /* We've already made a decision as to how this function will
5466 : : be handled. */;
5467 : 36132610 : else if (!at_eof
5468 : 13082039 : || DECL_IMMEDIATE_FUNCTION_P (fn)
5469 : 49148325 : || DECL_OMP_DECLARE_REDUCTION_P (fn))
5470 : 23116895 : tentative_decl_linkage (fn);
5471 : : else
5472 : 13015715 : import_export_decl (fn);
5473 : :
5474 : : /* If the user wants us to keep all inline functions, then mark
5475 : : this function as needed so that finish_file will make sure to
5476 : : output it later. Similarly, all dllexport'd functions must
5477 : : be emitted; there may be callers in other DLLs. */
5478 : 52732847 : if (DECL_DECLARED_INLINE_P (fn)
5479 : 50972990 : && !DECL_REALLY_EXTERN (fn)
5480 : 47957861 : && !DECL_IMMEDIATE_FUNCTION_P (fn)
5481 : 47804926 : && !DECL_OMP_DECLARE_REDUCTION_P (fn)
5482 : 100537773 : && (flag_keep_inline_functions
5483 : 47802571 : || (flag_keep_inline_dllexport
5484 : 47802571 : && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
5485 : : {
5486 : 2355 : mark_needed (fn);
5487 : 2355 : DECL_EXTERNAL (fn) = 0;
5488 : : }
5489 : : }
5490 : :
5491 : : /* If this is a constructor or destructor body, we have to clone
5492 : : it. */
5493 : 52981722 : if (maybe_clone_body (fn))
5494 : : {
5495 : : /* We don't want to process FN again, so pretend we've written
5496 : : it out, even though we haven't. */
5497 : 6441707 : TREE_ASM_WRITTEN (fn) = 1;
5498 : : /* If this is a constexpr function we still need the body to be
5499 : : able to evaluate it. Similarly, with modules we only stream
5500 : : the maybe-in-charge cdtor and regenerate the clones from it on
5501 : : demand, so we also need to keep the body. Otherwise we don't
5502 : : need it anymore. */
5503 : 6441707 : if (!DECL_DECLARED_CONSTEXPR_P (fn)
5504 : 6441707 : && !(module_maybe_has_cmi_p () && vague_linkage_p (fn)))
5505 : 4439575 : DECL_SAVED_TREE (fn) = void_node;
5506 : 6441707 : return false;
5507 : : }
5508 : :
5509 : : /* There's no reason to do any of the work here if we're only doing
5510 : : semantic analysis; this code just generates RTL. */
5511 : 46540015 : if (flag_syntax_only)
5512 : : {
5513 : : /* Pretend that this function has been written out so that we don't try
5514 : : to expand it again. */
5515 : 7504 : TREE_ASM_WRITTEN (fn) = 1;
5516 : 7504 : return false;
5517 : : }
5518 : :
5519 : 46532511 : if (DECL_OMP_DECLARE_REDUCTION_P (fn))
5520 : : return false;
5521 : :
5522 : : return true;
5523 : : }
5524 : :
5525 : : void
5526 : 127587744 : expand_or_defer_fn (tree fn)
5527 : : {
5528 : 127587744 : if (expand_or_defer_fn_1 (fn))
5529 : : {
5530 : 40110069 : function_depth++;
5531 : :
5532 : : /* Expand or defer, at the whim of the compilation unit manager. */
5533 : 40110069 : cgraph_node::finalize_function (fn, function_depth > 1);
5534 : 40110069 : emit_associated_thunks (fn);
5535 : :
5536 : 40110069 : function_depth--;
5537 : :
5538 : 80220138 : if (DECL_IMMEDIATE_FUNCTION_P (fn))
5539 : : {
5540 : 142658 : if (cgraph_node *node = cgraph_node::get (fn))
5541 : : {
5542 : 142658 : node->body_removed = true;
5543 : 142658 : node->analyzed = false;
5544 : 142658 : node->definition = false;
5545 : 142658 : node->force_output = false;
5546 : : }
5547 : : }
5548 : : }
5549 : 127587744 : }
5550 : :
5551 : 335894 : class nrv_data
5552 : : {
5553 : : public:
5554 : 167947 : nrv_data () : visited (37) {}
5555 : :
5556 : : tree var;
5557 : : tree result;
5558 : : hash_set<tree> visited;
5559 : : bool simple;
5560 : : bool in_nrv_cleanup;
5561 : : };
5562 : :
5563 : : /* Helper function for walk_tree, used by finalize_nrv below. */
5564 : :
5565 : : static tree
5566 : 18490182 : finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
5567 : : {
5568 : 18490182 : class nrv_data *dp = (class nrv_data *)data;
5569 : :
5570 : : /* No need to walk into types. There wouldn't be any need to walk into
5571 : : non-statements, except that we have to consider STMT_EXPRs. */
5572 : 18490182 : if (TYPE_P (*tp))
5573 : 160934 : *walk_subtrees = 0;
5574 : :
5575 : : /* Replace all uses of the NRV with the RESULT_DECL. */
5576 : 18329248 : else if (*tp == dp->var)
5577 : 452264 : *tp = dp->result;
5578 : :
5579 : : /* Avoid walking into the same tree more than once. Unfortunately, we
5580 : : can't just use walk_tree_without duplicates because it would only call
5581 : : us for the first occurrence of dp->var in the function body. */
5582 : 17876984 : else if (dp->visited.add (*tp))
5583 : 3969671 : *walk_subtrees = 0;
5584 : :
5585 : : /* If there's a label, we might need to destroy the NRV on goto (92407). */
5586 : 13907313 : else if (TREE_CODE (*tp) == LABEL_EXPR && !dp->in_nrv_cleanup)
5587 : 3 : dp->simple = false;
5588 : : /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
5589 : : but differs from using NULL_TREE in that it indicates that we care
5590 : : about the value of the RESULT_DECL. But preserve anything appended
5591 : : by check_return_expr. */
5592 : 13907310 : else if (TREE_CODE (*tp) == RETURN_EXPR)
5593 : : {
5594 : 178285 : tree *p = &TREE_OPERAND (*tp, 0);
5595 : 487730 : while (TREE_CODE (*p) == COMPOUND_EXPR)
5596 : 131160 : p = &TREE_OPERAND (*p, 0);
5597 : 178285 : if (TREE_CODE (*p) == INIT_EXPR
5598 : 178285 : && INIT_EXPR_NRV_P (*p))
5599 : 178221 : *p = dp->result;
5600 : : }
5601 : : /* Change all cleanups for the NRV to only run when not returning. */
5602 : 13729025 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5603 : 13729025 : && CLEANUP_DECL (*tp) == dp->var)
5604 : : {
5605 : 121619 : dp->in_nrv_cleanup = true;
5606 : 121619 : cp_walk_tree (&CLEANUP_BODY (*tp), finalize_nrv_r, data, 0);
5607 : 121619 : dp->in_nrv_cleanup = false;
5608 : 121619 : cp_walk_tree (&CLEANUP_EXPR (*tp), finalize_nrv_r, data, 0);
5609 : 121619 : *walk_subtrees = 0;
5610 : :
5611 : 121619 : if (dp->simple)
5612 : : /* For a simple NRV, just run it on the EH path. */
5613 : 121080 : CLEANUP_EH_ONLY (*tp) = true;
5614 : : else
5615 : : {
5616 : : /* Not simple, we need to check current_retval_sentinel to decide
5617 : : whether to run it. If it's set, we're returning normally and
5618 : : don't want to destroy the NRV. If the sentinel is not set, we're
5619 : : leaving scope some other way, either by flowing off the end of its
5620 : : scope or throwing an exception. */
5621 : 1617 : tree cond = build3 (COND_EXPR, void_type_node,
5622 : 539 : current_retval_sentinel,
5623 : 539 : void_node, CLEANUP_EXPR (*tp));
5624 : 539 : CLEANUP_EXPR (*tp) = cond;
5625 : : }
5626 : :
5627 : : /* If a cleanup might throw, we need to clear current_retval_sentinel on
5628 : : the exception path, both so the check above succeeds and so an outer
5629 : : cleanup added by maybe_splice_retval_cleanup doesn't run. */
5630 : 121619 : if (cp_function_chain->throwing_cleanup)
5631 : : {
5632 : 157 : tree clear = build2 (MODIFY_EXPR, boolean_type_node,
5633 : : current_retval_sentinel,
5634 : : boolean_false_node);
5635 : 157 : if (dp->simple)
5636 : : {
5637 : : /* We're already only on the EH path, just prepend it. */
5638 : 147 : tree &exp = CLEANUP_EXPR (*tp);
5639 : 147 : exp = build2 (COMPOUND_EXPR, void_type_node, clear, exp);
5640 : : }
5641 : : else
5642 : : {
5643 : : /* The cleanup runs on both normal and EH paths, we need another
5644 : : CLEANUP_STMT to clear the flag only on the EH path. */
5645 : 10 : tree &bod = CLEANUP_BODY (*tp);
5646 : 10 : bod = build_stmt (EXPR_LOCATION (*tp), CLEANUP_STMT,
5647 : 10 : bod, clear, current_retval_sentinel);
5648 : 10 : CLEANUP_EH_ONLY (bod) = true;
5649 : : }
5650 : : }
5651 : : }
5652 : : /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
5653 : : want to destroy the retval before the variable goes out of scope. */
5654 : 13607406 : else if (TREE_CODE (*tp) == CLEANUP_STMT
5655 : 6238 : && dp->in_nrv_cleanup
5656 : 13613069 : && CLEANUP_DECL (*tp) == dp->result)
5657 : 6 : CLEANUP_EXPR (*tp) = void_node;
5658 : : /* Replace the DECL_EXPR for the NRV with an initialization of the
5659 : : RESULT_DECL, if needed. */
5660 : 13607400 : else if (TREE_CODE (*tp) == DECL_EXPR
5661 : 13607400 : && DECL_EXPR_DECL (*tp) == dp->var)
5662 : : {
5663 : 167949 : tree init;
5664 : 167949 : if (DECL_INITIAL (dp->var)
5665 : 167949 : && DECL_INITIAL (dp->var) != error_mark_node)
5666 : 36173 : init = cp_build_init_expr (dp->result,
5667 : 36173 : DECL_INITIAL (dp->var));
5668 : : else
5669 : 131776 : init = build_empty_stmt (EXPR_LOCATION (*tp));
5670 : 167949 : DECL_INITIAL (dp->var) = NULL_TREE;
5671 : 167949 : SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
5672 : 167949 : *tp = init;
5673 : : }
5674 : :
5675 : : /* Keep iterating. */
5676 : 18490182 : return NULL_TREE;
5677 : : }
5678 : :
5679 : : /* Called from finish_function to implement the named return value
5680 : : optimization by overriding all the RETURN_EXPRs and pertinent
5681 : : CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5682 : : RESULT_DECL for the function. */
5683 : :
5684 : : void
5685 : 167947 : finalize_nrv (tree fndecl, tree var)
5686 : : {
5687 : 167947 : class nrv_data data;
5688 : 167947 : tree result = DECL_RESULT (fndecl);
5689 : :
5690 : : /* Copy name from VAR to RESULT. */
5691 : 167947 : DECL_NAME (result) = DECL_NAME (var);
5692 : : /* Don't forget that we take its address. */
5693 : 167947 : TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
5694 : : /* Finally set DECL_VALUE_EXPR to avoid assigning
5695 : : a stack slot at -O0 for the original var and debug info
5696 : : uses RESULT location for VAR. */
5697 : 167947 : SET_DECL_VALUE_EXPR (var, result);
5698 : 167947 : DECL_HAS_VALUE_EXPR_P (var) = 1;
5699 : :
5700 : 167947 : data.var = var;
5701 : 167947 : data.result = result;
5702 : 167947 : data.in_nrv_cleanup = false;
5703 : :
5704 : : /* This is simpler for variables declared in the outer scope of
5705 : : the function so we know that their lifetime always ends with a
5706 : : return; see g++.dg/opt/nrv6.C. */
5707 : 167947 : tree outer = outer_curly_brace_block (fndecl);
5708 : 167947 : data.simple = chain_member (var, BLOCK_VARS (outer));
5709 : :
5710 : 167947 : cp_walk_tree (&DECL_SAVED_TREE (fndecl), finalize_nrv_r, &data, 0);
5711 : 167947 : }
5712 : :
5713 : : /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5714 : :
5715 : : bool
5716 : 2234 : cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
5717 : : bool need_copy_ctor, bool need_copy_assignment,
5718 : : bool need_dtor)
5719 : : {
5720 : 2234 : int save_errorcount = errorcount;
5721 : 2234 : tree info, t;
5722 : :
5723 : : /* Always allocate 3 elements for simplicity. These are the
5724 : : function decls for the ctor, dtor, and assignment op.
5725 : : This layout is known to the three lang hooks,
5726 : : cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
5727 : : and cxx_omp_clause_assign_op. */
5728 : 2234 : info = make_tree_vec (3);
5729 : 2234 : CP_OMP_CLAUSE_INFO (c) = info;
5730 : :
5731 : 2234 : if (need_default_ctor || need_copy_ctor)
5732 : : {
5733 : 1653 : if (need_default_ctor)
5734 : 1254 : t = get_default_ctor (type);
5735 : : else
5736 : 399 : t = get_copy_ctor (type, tf_warning_or_error);
5737 : :
5738 : 1653 : if (t && !trivial_fn_p (t))
5739 : 1400 : TREE_VEC_ELT (info, 0) = t;
5740 : : }
5741 : :
5742 : 2234 : if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
5743 : 1635 : TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
5744 : :
5745 : 2234 : if (need_copy_assignment)
5746 : : {
5747 : 397 : t = get_copy_assign (type);
5748 : :
5749 : 397 : if (t && !trivial_fn_p (t))
5750 : 344 : TREE_VEC_ELT (info, 2) = t;
5751 : : }
5752 : :
5753 : 2234 : return errorcount != save_errorcount;
5754 : : }
5755 : :
5756 : : /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
5757 : : FIELD_DECL, otherwise return DECL itself. */
5758 : :
5759 : : static tree
5760 : 26374 : omp_clause_decl_field (tree decl)
5761 : : {
5762 : 26374 : if (VAR_P (decl)
5763 : 18356 : && DECL_HAS_VALUE_EXPR_P (decl)
5764 : 359 : && DECL_ARTIFICIAL (decl)
5765 : 359 : && DECL_LANG_SPECIFIC (decl)
5766 : 26709 : && DECL_OMP_PRIVATIZED_MEMBER (decl))
5767 : : {
5768 : 328 : tree f = DECL_VALUE_EXPR (decl);
5769 : 328 : if (INDIRECT_REF_P (f))
5770 : 0 : f = TREE_OPERAND (f, 0);
5771 : 328 : if (TREE_CODE (f) == COMPONENT_REF)
5772 : : {
5773 : 328 : f = TREE_OPERAND (f, 1);
5774 : 328 : gcc_assert (TREE_CODE (f) == FIELD_DECL);
5775 : : return f;
5776 : : }
5777 : : }
5778 : : return NULL_TREE;
5779 : : }
5780 : :
5781 : : /* Adjust DECL if needed for printing using %qE. */
5782 : :
5783 : : static tree
5784 : 187 : omp_clause_printable_decl (tree decl)
5785 : : {
5786 : 0 : tree t = omp_clause_decl_field (decl);
5787 : 187 : if (t)
5788 : 45 : return t;
5789 : : return decl;
5790 : : }
5791 : :
5792 : : /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
5793 : : VAR_DECL T that doesn't need a DECL_EXPR added, record it for
5794 : : privatization. */
5795 : :
5796 : : static void
5797 : 219 : omp_note_field_privatization (tree f, tree t)
5798 : : {
5799 : 219 : if (!omp_private_member_map)
5800 : 71 : omp_private_member_map = new hash_map<tree, tree>;
5801 : 219 : tree &v = omp_private_member_map->get_or_insert (f);
5802 : 219 : if (v == NULL_TREE)
5803 : : {
5804 : 146 : v = t;
5805 : 146 : omp_private_member_vec.safe_push (f);
5806 : : /* Signal that we don't want to create DECL_EXPR for this dummy var. */
5807 : 146 : omp_private_member_vec.safe_push (integer_zero_node);
5808 : : }
5809 : 219 : }
5810 : :
5811 : : /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
5812 : : dummy VAR_DECL. */
5813 : :
5814 : : tree
5815 : 852 : omp_privatize_field (tree t, bool shared)
5816 : : {
5817 : 852 : tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
5818 : 852 : if (m == error_mark_node)
5819 : : return error_mark_node;
5820 : 852 : if (!omp_private_member_map && !shared)
5821 : 362 : omp_private_member_map = new hash_map<tree, tree>;
5822 : 852 : if (TYPE_REF_P (TREE_TYPE (t)))
5823 : : {
5824 : 123 : gcc_assert (INDIRECT_REF_P (m));
5825 : 123 : m = TREE_OPERAND (m, 0);
5826 : : }
5827 : 852 : tree vb = NULL_TREE;
5828 : 852 : tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
5829 : 852 : if (v == NULL_TREE)
5830 : : {
5831 : 764 : v = create_temporary_var (TREE_TYPE (m));
5832 : 764 : retrofit_lang_decl (v);
5833 : 764 : DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
5834 : 764 : SET_DECL_VALUE_EXPR (v, m);
5835 : 764 : DECL_HAS_VALUE_EXPR_P (v) = 1;
5836 : 764 : if (!shared)
5837 : 684 : omp_private_member_vec.safe_push (t);
5838 : : }
5839 : 852 : return v;
5840 : : }
5841 : :
5842 : : /* C++ specialisation of the c_omp_address_inspector class. */
5843 : :
5844 : : class cp_omp_address_inspector : public c_omp_address_inspector
5845 : : {
5846 : : public:
5847 : 29549 : cp_omp_address_inspector (location_t loc, tree t)
5848 : 29549 : : c_omp_address_inspector (loc, t)
5849 : : {
5850 : : }
5851 : :
5852 : 29549 : ~cp_omp_address_inspector ()
5853 : : {
5854 : 21657 : }
5855 : :
5856 : 126608 : bool processing_template_decl_p ()
5857 : : {
5858 : 126608 : return processing_template_decl;
5859 : : }
5860 : :
5861 : 0 : void emit_unmappable_type_notes (tree t)
5862 : : {
5863 : 0 : if (TREE_TYPE (t) != error_mark_node
5864 : 0 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
5865 : 0 : cxx_incomplete_type_inform (TREE_TYPE (t));
5866 : 0 : }
5867 : :
5868 : 1034 : tree convert_from_reference (tree x)
5869 : : {
5870 : 1034 : return ::convert_from_reference (x);
5871 : : }
5872 : :
5873 : 143 : tree build_array_ref (location_t loc, tree arr, tree idx)
5874 : : {
5875 : 143 : return ::build_array_ref (loc, arr, idx);
5876 : : }
5877 : :
5878 : 21601 : bool check_clause (tree clause)
5879 : : {
5880 : 21601 : if (TREE_CODE (orig) == COMPONENT_REF
5881 : 21601 : && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig), orig,
5882 : : tf_warning_or_error))
5883 : : return false;
5884 : 21598 : if (!c_omp_address_inspector::check_clause (clause))
5885 : : return false;
5886 : : return true;
5887 : : }
5888 : : };
5889 : :
5890 : : /* Helper function for handle_omp_array_sections. Called recursively
5891 : : to handle multiple array-section-subscripts. C is the clause,
5892 : : T current expression (initially OMP_CLAUSE_DECL), which is either
5893 : : a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
5894 : : expression if specified, TREE_VALUE length expression if specified,
5895 : : TREE_CHAIN is what it has been specified after, or some decl.
5896 : : TYPES vector is populated with array section types, MAYBE_ZERO_LEN
5897 : : set to true if any of the array-section-subscript could have length
5898 : : of zero (explicit or implicit), FIRST_NON_ONE is the index of the
5899 : : first array-section-subscript which is known not to have length
5900 : : of one. Given say:
5901 : : map(a[:b][2:1][:c][:2][:d][e:f][2:5])
5902 : : FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
5903 : : all are or may have length of 1, array-section-subscript [:2] is the
5904 : : first one known not to have length 1. For array-section-subscript
5905 : : <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
5906 : : 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
5907 : : can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
5908 : : case though, as some lengths could be zero. */
5909 : :
5910 : : static tree
5911 : 20602 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
5912 : : bool &maybe_zero_len, unsigned int &first_non_one,
5913 : : enum c_omp_region_type ort)
5914 : : {
5915 : 20602 : tree ret, low_bound, length, type;
5916 : 20602 : bool openacc = (ort & C_ORT_ACC) != 0;
5917 : 20602 : if (TREE_CODE (t) != OMP_ARRAY_SECTION)
5918 : : {
5919 : 9289 : if (error_operand_p (t))
5920 : 6 : return error_mark_node;
5921 : :
5922 : 9283 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
5923 : 9283 : tree t_refto = ai.maybe_unconvert_ref (t);
5924 : :
5925 : 9283 : if (!ai.check_clause (c))
5926 : 0 : return error_mark_node;
5927 : 9283 : else if (ai.component_access_p ()
5928 : 10613 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
5929 : 64 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
5930 : 40 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
5931 : 1330 : t = ai.get_root_term (true);
5932 : : else
5933 : 7953 : t = ai.unconverted_ref_origin ();
5934 : 9283 : if (t == error_mark_node)
5935 : : return error_mark_node;
5936 : 9283 : ret = t_refto;
5937 : 9283 : if (TREE_CODE (t) == FIELD_DECL)
5938 : 33 : ret = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
5939 : 9250 : else if (!VAR_P (t)
5940 : 2719 : && (openacc || !EXPR_P (t))
5941 : 2536 : && TREE_CODE (t) != PARM_DECL)
5942 : : {
5943 : 51 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
5944 : : return NULL_TREE;
5945 : 33 : if (DECL_P (t))
5946 : 33 : error_at (OMP_CLAUSE_LOCATION (c),
5947 : : "%qD is not a variable in %qs clause", t,
5948 : 33 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5949 : : else
5950 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
5951 : : "%qE is not a variable in %qs clause", t,
5952 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5953 : 33 : return error_mark_node;
5954 : : }
5955 : 9199 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
5956 : 8869 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
5957 : 17147 : && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
5958 : : {
5959 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
5960 : : "%qD is threadprivate variable in %qs clause", t,
5961 : 18 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
5962 : 18 : return error_mark_node;
5963 : : }
5964 : 9214 : if (type_dependent_expression_p (ret))
5965 : : return NULL_TREE;
5966 : 8557 : ret = convert_from_reference (ret);
5967 : 8557 : return ret;
5968 : 9283 : }
5969 : :
5970 : 11313 : if ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
5971 : 7392 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
5972 : 6090 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
5973 : 4806 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
5974 : 14027 : && TREE_CODE (TREE_OPERAND (t, 0)) == FIELD_DECL)
5975 : 43 : TREE_OPERAND (t, 0) = omp_privatize_field (TREE_OPERAND (t, 0), false);
5976 : 11313 : ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
5977 : : maybe_zero_len, first_non_one, ort);
5978 : 11313 : if (ret == error_mark_node || ret == NULL_TREE)
5979 : : return ret;
5980 : :
5981 : 10306 : type = TREE_TYPE (ret);
5982 : 10306 : low_bound = TREE_OPERAND (t, 1);
5983 : 10306 : length = TREE_OPERAND (t, 2);
5984 : 8388 : if ((low_bound && type_dependent_expression_p (low_bound))
5985 : 18611 : || (length && type_dependent_expression_p (length)))
5986 : 88 : return NULL_TREE;
5987 : :
5988 : 10218 : if (low_bound == error_mark_node || length == error_mark_node)
5989 : : return error_mark_node;
5990 : :
5991 : 10218 : if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
5992 : : {
5993 : 75 : error_at (OMP_CLAUSE_LOCATION (c),
5994 : : "low bound %qE of array section does not have integral type",
5995 : : low_bound);
5996 : 75 : return error_mark_node;
5997 : : }
5998 : 10143 : if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
5999 : : {
6000 : 69 : error_at (OMP_CLAUSE_LOCATION (c),
6001 : : "length %qE of array section does not have integral type",
6002 : : length);
6003 : 69 : return error_mark_node;
6004 : : }
6005 : 10074 : if (low_bound)
6006 : 8216 : low_bound = mark_rvalue_use (low_bound);
6007 : 10074 : if (length)
6008 : 9057 : length = mark_rvalue_use (length);
6009 : : /* We need to reduce to real constant-values for checks below. */
6010 : 9057 : if (length)
6011 : 9057 : length = fold_simple (length);
6012 : 10074 : if (low_bound)
6013 : 8216 : low_bound = fold_simple (low_bound);
6014 : 8216 : if (low_bound
6015 : 8216 : && TREE_CODE (low_bound) == INTEGER_CST
6016 : 15503 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6017 : 7287 : > TYPE_PRECISION (sizetype))
6018 : 0 : low_bound = fold_convert (sizetype, low_bound);
6019 : 10074 : if (length
6020 : 9057 : && TREE_CODE (length) == INTEGER_CST
6021 : 17167 : && TYPE_PRECISION (TREE_TYPE (length))
6022 : 7093 : > TYPE_PRECISION (sizetype))
6023 : 0 : length = fold_convert (sizetype, length);
6024 : 10074 : if (low_bound == NULL_TREE)
6025 : 1858 : low_bound = integer_zero_node;
6026 : :
6027 : 10074 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6028 : 10074 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
6029 : 4888 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
6030 : : {
6031 : 60 : if (length != integer_one_node)
6032 : : {
6033 : 36 : error_at (OMP_CLAUSE_LOCATION (c),
6034 : : "expected single pointer in %qs clause",
6035 : : user_omp_clause_code_name (c, openacc));
6036 : 36 : return error_mark_node;
6037 : : }
6038 : : }
6039 : 10038 : if (length != NULL_TREE)
6040 : : {
6041 : 9045 : if (!integer_nonzerop (length))
6042 : : {
6043 : 2013 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6044 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6045 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6046 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6047 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6048 : : {
6049 : 469 : if (integer_zerop (length))
6050 : : {
6051 : 36 : error_at (OMP_CLAUSE_LOCATION (c),
6052 : : "zero length array section in %qs clause",
6053 : 36 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6054 : 36 : return error_mark_node;
6055 : : }
6056 : : }
6057 : : else
6058 : 1544 : maybe_zero_len = true;
6059 : : }
6060 : 9009 : if (first_non_one == types.length ()
6061 : 9009 : && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
6062 : 3834 : first_non_one++;
6063 : : }
6064 : 10002 : if (TREE_CODE (type) == ARRAY_TYPE)
6065 : : {
6066 : 5604 : if (length == NULL_TREE
6067 : 5604 : && (TYPE_DOMAIN (type) == NULL_TREE
6068 : 915 : || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
6069 : : {
6070 : 33 : error_at (OMP_CLAUSE_LOCATION (c),
6071 : : "for unknown bound array type length expression must "
6072 : : "be specified");
6073 : 33 : return error_mark_node;
6074 : : }
6075 : 5571 : if (TREE_CODE (low_bound) == INTEGER_CST
6076 : 5571 : && tree_int_cst_sgn (low_bound) == -1)
6077 : : {
6078 : 174 : error_at (OMP_CLAUSE_LOCATION (c),
6079 : : "negative low bound in array section in %qs clause",
6080 : 174 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6081 : 174 : return error_mark_node;
6082 : : }
6083 : 5397 : if (length != NULL_TREE
6084 : 4536 : && TREE_CODE (length) == INTEGER_CST
6085 : 9018 : && tree_int_cst_sgn (length) == -1)
6086 : : {
6087 : 174 : error_at (OMP_CLAUSE_LOCATION (c),
6088 : : "negative length in array section in %qs clause",
6089 : 174 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6090 : 174 : return error_mark_node;
6091 : : }
6092 : 5223 : if (TYPE_DOMAIN (type)
6093 : 5124 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6094 : 10347 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
6095 : : == INTEGER_CST)
6096 : : {
6097 : 4728 : tree size
6098 : 4728 : = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
6099 : 4728 : size = size_binop (PLUS_EXPR, size, size_one_node);
6100 : 4728 : if (TREE_CODE (low_bound) == INTEGER_CST)
6101 : : {
6102 : 3959 : if (tree_int_cst_lt (size, low_bound))
6103 : : {
6104 : 60 : error_at (OMP_CLAUSE_LOCATION (c),
6105 : : "low bound %qE above array section size "
6106 : : "in %qs clause", low_bound,
6107 : 60 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6108 : 60 : return error_mark_node;
6109 : : }
6110 : 3899 : if (tree_int_cst_equal (size, low_bound))
6111 : : {
6112 : 21 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
6113 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6114 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6115 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6116 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6117 : : {
6118 : 21 : error_at (OMP_CLAUSE_LOCATION (c),
6119 : : "zero length array section in %qs clause",
6120 : 21 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6121 : 21 : return error_mark_node;
6122 : : }
6123 : 0 : maybe_zero_len = true;
6124 : : }
6125 : 3878 : else if (length == NULL_TREE
6126 : 1514 : && first_non_one == types.length ()
6127 : 4199 : && tree_int_cst_equal
6128 : 321 : (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6129 : : low_bound))
6130 : 207 : first_non_one++;
6131 : : }
6132 : 769 : else if (length == NULL_TREE)
6133 : : {
6134 : 22 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6135 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6136 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6137 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6138 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6139 : 13 : maybe_zero_len = true;
6140 : 44 : if (first_non_one == types.length ())
6141 : 19 : first_non_one++;
6142 : : }
6143 : 4647 : if (length && TREE_CODE (length) == INTEGER_CST)
6144 : : {
6145 : 3327 : if (tree_int_cst_lt (size, length))
6146 : : {
6147 : 63 : error_at (OMP_CLAUSE_LOCATION (c),
6148 : : "length %qE above array section size "
6149 : : "in %qs clause", length,
6150 : 63 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6151 : 63 : return error_mark_node;
6152 : : }
6153 : 3264 : if (TREE_CODE (low_bound) == INTEGER_CST)
6154 : : {
6155 : 2932 : tree lbpluslen
6156 : 2932 : = size_binop (PLUS_EXPR,
6157 : : fold_convert (sizetype, low_bound),
6158 : : fold_convert (sizetype, length));
6159 : 2932 : if (TREE_CODE (lbpluslen) == INTEGER_CST
6160 : 2932 : && tree_int_cst_lt (size, lbpluslen))
6161 : : {
6162 : 60 : error_at (OMP_CLAUSE_LOCATION (c),
6163 : : "high bound %qE above array section size "
6164 : : "in %qs clause", lbpluslen,
6165 : 60 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6166 : 60 : return error_mark_node;
6167 : : }
6168 : : }
6169 : : }
6170 : : }
6171 : 495 : else if (length == NULL_TREE)
6172 : : {
6173 : 1 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6174 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6175 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
6176 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
6177 : : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
6178 : 0 : maybe_zero_len = true;
6179 : 2 : if (first_non_one == types.length ())
6180 : 1 : first_non_one++;
6181 : : }
6182 : :
6183 : : /* For [lb:] we will need to evaluate lb more than once. */
6184 : 3985 : if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6185 : : {
6186 : 699 : tree lb = cp_save_expr (low_bound);
6187 : 699 : if (lb != low_bound)
6188 : : {
6189 : 11 : TREE_OPERAND (t, 1) = lb;
6190 : 11 : low_bound = lb;
6191 : : }
6192 : : }
6193 : : }
6194 : 4398 : else if (TYPE_PTR_P (type))
6195 : : {
6196 : 4338 : if (length == NULL_TREE)
6197 : : {
6198 : 45 : if (TREE_CODE (ret) == PARM_DECL && DECL_ARRAY_PARAMETER_P (ret))
6199 : 39 : error_at (OMP_CLAUSE_LOCATION (c),
6200 : : "for array function parameter length expression "
6201 : : "must be specified");
6202 : : else
6203 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
6204 : : "for pointer type length expression must be specified");
6205 : 45 : return error_mark_node;
6206 : : }
6207 : 4293 : if (length != NULL_TREE
6208 : 4293 : && TREE_CODE (length) == INTEGER_CST
6209 : 3244 : && tree_int_cst_sgn (length) == -1)
6210 : : {
6211 : 96 : error_at (OMP_CLAUSE_LOCATION (c),
6212 : : "negative length in array section in %qs clause",
6213 : 96 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6214 : 96 : return error_mark_node;
6215 : : }
6216 : : /* If there is a pointer type anywhere but in the very first
6217 : : array-section-subscript, the array section could be non-contiguous. */
6218 : 4197 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
6219 : 4095 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
6220 : 7809 : && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
6221 : : {
6222 : : /* If any prior dimension has a non-one length, then deem this
6223 : : array section as non-contiguous. */
6224 : 77 : for (tree d = TREE_OPERAND (t, 0); TREE_CODE (d) == OMP_ARRAY_SECTION;
6225 : 28 : d = TREE_OPERAND (d, 0))
6226 : : {
6227 : 49 : tree d_length = TREE_OPERAND (d, 2);
6228 : 49 : if (d_length == NULL_TREE || !integer_onep (d_length))
6229 : : {
6230 : 21 : error_at (OMP_CLAUSE_LOCATION (c),
6231 : : "array section is not contiguous in %qs clause",
6232 : 21 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6233 : 21 : return error_mark_node;
6234 : : }
6235 : : }
6236 : : }
6237 : : }
6238 : : else
6239 : : {
6240 : 60 : error_at (OMP_CLAUSE_LOCATION (c),
6241 : : "%qE does not have pointer or array type", ret);
6242 : 60 : return error_mark_node;
6243 : : }
6244 : 9195 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
6245 : 8298 : types.safe_push (TREE_TYPE (ret));
6246 : : /* We will need to evaluate lb more than once. */
6247 : 9195 : tree lb = cp_save_expr (low_bound);
6248 : 9195 : if (lb != low_bound)
6249 : : {
6250 : 718 : TREE_OPERAND (t, 1) = lb;
6251 : 718 : low_bound = lb;
6252 : : }
6253 : : /* Temporarily disable -fstrong-eval-order for array reductions.
6254 : : The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
6255 : : is something the middle-end can't cope with and more importantly,
6256 : : it needs to be the actual base variable that is privatized, not some
6257 : : temporary assigned previous value of it. That, together with OpenMP
6258 : : saying how many times the side-effects are evaluated is unspecified,
6259 : : makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
6260 : 9195 : warning_sentinel s (flag_strong_eval_order,
6261 : 9195 : OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6262 : 8098 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6263 : 18509 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION);
6264 : 9195 : ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, NULL,
6265 : : tf_warning_or_error);
6266 : 9195 : return ret;
6267 : 9195 : }
6268 : :
6269 : : /* Handle array sections for clause C. */
6270 : :
6271 : : static bool
6272 : 9289 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
6273 : : {
6274 : 9289 : bool maybe_zero_len = false;
6275 : 9289 : unsigned int first_non_one = 0;
6276 : 9289 : auto_vec<tree, 10> types;
6277 : 9289 : tree *tp = &OMP_CLAUSE_DECL (c);
6278 : 9289 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6279 : 8338 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6280 : 1299 : && TREE_CODE (*tp) == TREE_LIST
6281 : 258 : && TREE_PURPOSE (*tp)
6282 : 9547 : && TREE_CODE (TREE_PURPOSE (*tp)) == TREE_VEC)
6283 : 258 : tp = &TREE_VALUE (*tp);
6284 : 9289 : tree first = handle_omp_array_sections_1 (c, *tp, types,
6285 : : maybe_zero_len, first_non_one,
6286 : : ort);
6287 : 9289 : if (first == error_mark_node)
6288 : : return true;
6289 : 8209 : if (first == NULL_TREE)
6290 : : return false;
6291 : 7446 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
6292 : 7446 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
6293 : : {
6294 : 909 : tree t = *tp;
6295 : 909 : tree tem = NULL_TREE;
6296 : 909 : if (processing_template_decl)
6297 : : return false;
6298 : : /* Need to evaluate side effects in the length expressions
6299 : : if any. */
6300 : 810 : while (TREE_CODE (t) == TREE_LIST)
6301 : : {
6302 : 0 : if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
6303 : : {
6304 : 0 : if (tem == NULL_TREE)
6305 : : tem = TREE_VALUE (t);
6306 : : else
6307 : 0 : tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
6308 : 0 : TREE_VALUE (t), tem);
6309 : : }
6310 : 0 : t = TREE_CHAIN (t);
6311 : : }
6312 : 810 : if (tem)
6313 : 0 : first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
6314 : 810 : *tp = first;
6315 : : }
6316 : : else
6317 : : {
6318 : 6537 : unsigned int num = types.length (), i;
6319 : 6537 : tree t, side_effects = NULL_TREE, size = NULL_TREE;
6320 : 6537 : tree condition = NULL_TREE;
6321 : :
6322 : 6537 : if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
6323 : 3 : maybe_zero_len = true;
6324 : 6537 : if (processing_template_decl && maybe_zero_len)
6325 : : return false;
6326 : :
6327 : 13737 : for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
6328 : 7278 : t = TREE_OPERAND (t, 0))
6329 : : {
6330 : 7353 : gcc_assert (TREE_CODE (t) == OMP_ARRAY_SECTION);
6331 : :
6332 : 7353 : tree low_bound = TREE_OPERAND (t, 1);
6333 : 7353 : tree length = TREE_OPERAND (t, 2);
6334 : :
6335 : 7353 : i--;
6336 : 7353 : if (low_bound
6337 : 6070 : && TREE_CODE (low_bound) == INTEGER_CST
6338 : 12814 : && TYPE_PRECISION (TREE_TYPE (low_bound))
6339 : 5461 : > TYPE_PRECISION (sizetype))
6340 : 0 : low_bound = fold_convert (sizetype, low_bound);
6341 : 7353 : if (length
6342 : 6821 : && TREE_CODE (length) == INTEGER_CST
6343 : 12331 : && TYPE_PRECISION (TREE_TYPE (length))
6344 : 4978 : > TYPE_PRECISION (sizetype))
6345 : 0 : length = fold_convert (sizetype, length);
6346 : 7353 : if (low_bound == NULL_TREE)
6347 : 1283 : low_bound = integer_zero_node;
6348 : 7353 : if (!maybe_zero_len && i > first_non_one)
6349 : : {
6350 : 642 : if (integer_nonzerop (low_bound))
6351 : 36 : goto do_warn_noncontiguous;
6352 : 606 : if (length != NULL_TREE
6353 : 278 : && TREE_CODE (length) == INTEGER_CST
6354 : 278 : && TYPE_DOMAIN (types[i])
6355 : 278 : && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
6356 : 884 : && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
6357 : : == INTEGER_CST)
6358 : : {
6359 : 278 : tree size;
6360 : 278 : size = size_binop (PLUS_EXPR,
6361 : : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6362 : : size_one_node);
6363 : 278 : if (!tree_int_cst_equal (length, size))
6364 : : {
6365 : 39 : do_warn_noncontiguous:
6366 : 150 : error_at (OMP_CLAUSE_LOCATION (c),
6367 : : "array section is not contiguous in %qs "
6368 : : "clause",
6369 : 75 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6370 : 75 : return true;
6371 : : }
6372 : : }
6373 : 567 : if (!processing_template_decl
6374 : 397 : && length != NULL_TREE
6375 : 734 : && TREE_SIDE_EFFECTS (length))
6376 : : {
6377 : 0 : if (side_effects == NULL_TREE)
6378 : : side_effects = length;
6379 : : else
6380 : 0 : side_effects = build2 (COMPOUND_EXPR,
6381 : 0 : TREE_TYPE (side_effects),
6382 : : length, side_effects);
6383 : : }
6384 : : }
6385 : 6711 : else if (processing_template_decl)
6386 : 726 : continue;
6387 : : else
6388 : : {
6389 : 5985 : tree l;
6390 : :
6391 : 5985 : if (i > first_non_one
6392 : 5985 : && ((length && integer_nonzerop (length))
6393 : 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6394 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6395 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
6396 : 0 : continue;
6397 : 5985 : if (length)
6398 : 5863 : l = fold_convert (sizetype, length);
6399 : : else
6400 : : {
6401 : 122 : l = size_binop (PLUS_EXPR,
6402 : : TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
6403 : : size_one_node);
6404 : 122 : l = size_binop (MINUS_EXPR, l,
6405 : : fold_convert (sizetype, low_bound));
6406 : : }
6407 : 5985 : if (i > first_non_one)
6408 : : {
6409 : 0 : l = fold_build2 (NE_EXPR, boolean_type_node, l,
6410 : : size_zero_node);
6411 : 0 : if (condition == NULL_TREE)
6412 : : condition = l;
6413 : : else
6414 : 0 : condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
6415 : : l, condition);
6416 : : }
6417 : 5985 : else if (size == NULL_TREE)
6418 : : {
6419 : 5739 : size = size_in_bytes (TREE_TYPE (types[i]));
6420 : 5739 : tree eltype = TREE_TYPE (types[num - 1]);
6421 : 5810 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6422 : 71 : eltype = TREE_TYPE (eltype);
6423 : 5739 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6424 : 4929 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6425 : 9915 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6426 : 1659 : size = size_binop (EXACT_DIV_EXPR, size,
6427 : : size_in_bytes (eltype));
6428 : 5739 : size = size_binop (MULT_EXPR, size, l);
6429 : 5739 : if (condition)
6430 : 0 : size = fold_build3 (COND_EXPR, sizetype, condition,
6431 : : size, size_zero_node);
6432 : : }
6433 : : else
6434 : 246 : size = size_binop (MULT_EXPR, size, l);
6435 : : }
6436 : : }
6437 : 6384 : if (!processing_template_decl)
6438 : : {
6439 : 5739 : if (side_effects)
6440 : 0 : size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
6441 : 5739 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
6442 : 4929 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
6443 : 9915 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
6444 : : {
6445 : 1659 : size = size_binop (MINUS_EXPR, size, size_one_node);
6446 : 1659 : size = save_expr (size);
6447 : 1659 : tree index_type = build_index_type (size);
6448 : 1659 : tree eltype = TREE_TYPE (first);
6449 : 1688 : while (TREE_CODE (eltype) == ARRAY_TYPE)
6450 : 29 : eltype = TREE_TYPE (eltype);
6451 : 1659 : tree type = build_array_type (eltype, index_type);
6452 : 1659 : tree ptype = build_pointer_type (eltype);
6453 : 1659 : if (TYPE_REF_P (TREE_TYPE (t))
6454 : 1659 : && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
6455 : 170 : t = convert_from_reference (t);
6456 : 1489 : else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6457 : 641 : t = build_fold_addr_expr (t);
6458 : 1659 : tree t2 = build_fold_addr_expr (first);
6459 : 1659 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6460 : : ptrdiff_type_node, t2);
6461 : 1659 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
6462 : : ptrdiff_type_node, t2,
6463 : 1659 : fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6464 : : ptrdiff_type_node, t));
6465 : 1659 : if (tree_fits_shwi_p (t2))
6466 : 1321 : t = build2 (MEM_REF, type, t,
6467 : 1321 : build_int_cst (ptype, tree_to_shwi (t2)));
6468 : : else
6469 : : {
6470 : 338 : t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
6471 : : sizetype, t2);
6472 : 338 : t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
6473 : 338 : TREE_TYPE (t), t, t2);
6474 : 338 : t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
6475 : : }
6476 : 1659 : OMP_CLAUSE_DECL (c) = t;
6477 : 7398 : return false;
6478 : : }
6479 : 4080 : OMP_CLAUSE_DECL (c) = first;
6480 : 4080 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
6481 : : return false;
6482 : 4054 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
6483 : 4054 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
6484 : 3531 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
6485 : 3519 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
6486 : 4030 : OMP_CLAUSE_SIZE (c) = size;
6487 : 4054 : if (TREE_CODE (t) == FIELD_DECL)
6488 : 3 : t = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
6489 : :
6490 : 4054 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6491 : : return false;
6492 : :
6493 : 3543 : if (TREE_CODE (first) == INDIRECT_REF)
6494 : : {
6495 : : /* Detect and skip adding extra nodes for pointer-to-member
6496 : : mappings. These are unsupported for now. */
6497 : 2294 : tree tmp = TREE_OPERAND (first, 0);
6498 : :
6499 : 2294 : if (TREE_CODE (tmp) == NON_LVALUE_EXPR)
6500 : 1832 : tmp = TREE_OPERAND (tmp, 0);
6501 : :
6502 : 2294 : if (TREE_CODE (tmp) == INDIRECT_REF)
6503 : 140 : tmp = TREE_OPERAND (tmp, 0);
6504 : :
6505 : 2294 : if (TREE_CODE (tmp) == POINTER_PLUS_EXPR)
6506 : : {
6507 : 423 : tree offset = TREE_OPERAND (tmp, 1);
6508 : 423 : STRIP_NOPS (offset);
6509 : 423 : if (TYPE_PTRMEM_P (TREE_TYPE (offset)))
6510 : : {
6511 : 36 : sorry_at (OMP_CLAUSE_LOCATION (c),
6512 : : "pointer-to-member mapping %qE not supported",
6513 : 18 : OMP_CLAUSE_DECL (c));
6514 : 18 : return true;
6515 : : }
6516 : : }
6517 : : }
6518 : :
6519 : : /* FIRST represents the first item of data that we are mapping.
6520 : : E.g. if we're mapping an array, FIRST might resemble
6521 : : "foo.bar.myarray[0]". */
6522 : :
6523 : 3525 : auto_vec<omp_addr_token *, 10> addr_tokens;
6524 : :
6525 : 3525 : if (!omp_parse_expr (addr_tokens, first))
6526 : : return true;
6527 : :
6528 : 3525 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
6529 : :
6530 : 3525 : tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
6531 : 3525 : if (nc != error_mark_node)
6532 : : {
6533 : 3525 : using namespace omp_addr_tokenizer;
6534 : :
6535 : 3525 : if (ai.maybe_zero_length_array_section (c))
6536 : 3501 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
6537 : :
6538 : : /* !!! If we're accessing a base decl via chained access
6539 : : methods (e.g. multiple indirections), duplicate clause
6540 : : detection won't work properly. Skip it in that case. */
6541 : 3525 : if ((addr_tokens[0]->type == STRUCTURE_BASE
6542 : 2566 : || addr_tokens[0]->type == ARRAY_BASE)
6543 : 3525 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
6544 : 3514 : && addr_tokens[1]->type == ACCESS_METHOD
6545 : 7039 : && omp_access_chain_p (addr_tokens, 1))
6546 : 199 : c = nc;
6547 : :
6548 : 3525 : return false;
6549 : : }
6550 : 7050 : }
6551 : : }
6552 : : return false;
6553 : 9289 : }
6554 : :
6555 : : /* Return identifier to look up for omp declare reduction. */
6556 : :
6557 : : tree
6558 : 7069 : omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
6559 : : {
6560 : 7069 : const char *p = NULL;
6561 : 7069 : const char *m = NULL;
6562 : 7069 : switch (reduction_code)
6563 : : {
6564 : 4188 : case PLUS_EXPR:
6565 : 4188 : case MULT_EXPR:
6566 : 4188 : case MINUS_EXPR:
6567 : 4188 : case BIT_AND_EXPR:
6568 : 4188 : case BIT_XOR_EXPR:
6569 : 4188 : case BIT_IOR_EXPR:
6570 : 4188 : case TRUTH_ANDIF_EXPR:
6571 : 4188 : case TRUTH_ORIF_EXPR:
6572 : 4188 : reduction_id = ovl_op_identifier (false, reduction_code);
6573 : 4188 : break;
6574 : : case MIN_EXPR:
6575 : : p = "min";
6576 : : break;
6577 : : case MAX_EXPR:
6578 : : p = "max";
6579 : : break;
6580 : : default:
6581 : : break;
6582 : : }
6583 : :
6584 : 4188 : if (p == NULL)
6585 : : {
6586 : 6905 : if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
6587 : 0 : return error_mark_node;
6588 : 6905 : p = IDENTIFIER_POINTER (reduction_id);
6589 : : }
6590 : :
6591 : 7069 : if (type != NULL_TREE)
6592 : 2025 : m = mangle_type_string (TYPE_MAIN_VARIANT (type));
6593 : :
6594 : 7069 : const char prefix[] = "omp declare reduction ";
6595 : 7069 : size_t lenp = sizeof (prefix);
6596 : 7069 : if (strncmp (p, prefix, lenp - 1) == 0)
6597 : 2025 : lenp = 1;
6598 : 7069 : size_t len = strlen (p);
6599 : 7069 : size_t lenm = m ? strlen (m) + 1 : 0;
6600 : 7069 : char *name = XALLOCAVEC (char, lenp + len + lenm);
6601 : 7069 : if (lenp > 1)
6602 : 5044 : memcpy (name, prefix, lenp - 1);
6603 : 7069 : memcpy (name + lenp - 1, p, len + 1);
6604 : 7069 : if (m)
6605 : : {
6606 : 2025 : name[lenp + len - 1] = '~';
6607 : 2025 : memcpy (name + lenp + len, m, lenm);
6608 : : }
6609 : 7069 : return get_identifier (name);
6610 : : }
6611 : :
6612 : : /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
6613 : : FUNCTION_DECL or NULL_TREE if not found. */
6614 : :
6615 : : static tree
6616 : 1284 : omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
6617 : : vec<tree> *ambiguousp)
6618 : : {
6619 : 1284 : tree orig_id = id;
6620 : 1284 : tree baselink = NULL_TREE;
6621 : 1284 : if (identifier_p (id))
6622 : : {
6623 : 1256 : cp_id_kind idk;
6624 : 1256 : bool nonint_cst_expression_p;
6625 : 1256 : const char *error_msg;
6626 : 1256 : id = omp_reduction_id (ERROR_MARK, id, type);
6627 : 1256 : tree decl = lookup_name (id);
6628 : 1256 : if (decl == NULL_TREE)
6629 : 80 : decl = error_mark_node;
6630 : 1256 : id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
6631 : : &nonint_cst_expression_p, false, true, false,
6632 : : false, &error_msg, loc);
6633 : 1256 : if (idk == CP_ID_KIND_UNQUALIFIED
6634 : 1336 : && identifier_p (id))
6635 : : {
6636 : 80 : vec<tree, va_gc> *args = NULL;
6637 : 80 : vec_safe_push (args, build_reference_type (type));
6638 : 80 : id = perform_koenig_lookup (id, args, tf_none);
6639 : : }
6640 : : }
6641 : 28 : else if (TREE_CODE (id) == SCOPE_REF)
6642 : 28 : id = lookup_qualified_name (TREE_OPERAND (id, 0),
6643 : : omp_reduction_id (ERROR_MARK,
6644 : 28 : TREE_OPERAND (id, 1),
6645 : : type),
6646 : : LOOK_want::NORMAL, false);
6647 : 1284 : tree fns = id;
6648 : 1284 : id = NULL_TREE;
6649 : 1284 : if (fns && is_overloaded_fn (fns))
6650 : : {
6651 : 1210 : for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
6652 : : {
6653 : 1210 : tree fndecl = *iter;
6654 : 1210 : if (TREE_CODE (fndecl) == FUNCTION_DECL)
6655 : : {
6656 : 1210 : tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
6657 : 1210 : if (same_type_p (TREE_TYPE (argtype), type))
6658 : : {
6659 : 1210 : id = fndecl;
6660 : 1210 : break;
6661 : : }
6662 : : }
6663 : : }
6664 : :
6665 : 1210 : if (id && BASELINK_P (fns))
6666 : : {
6667 : 74 : if (baselinkp)
6668 : 0 : *baselinkp = fns;
6669 : : else
6670 : 74 : baselink = fns;
6671 : : }
6672 : : }
6673 : :
6674 : 1284 : if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
6675 : : {
6676 : 35 : auto_vec<tree> ambiguous;
6677 : 35 : tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
6678 : 35 : unsigned int ix;
6679 : 35 : if (ambiguousp == NULL)
6680 : 19 : ambiguousp = &ambiguous;
6681 : 73 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
6682 : : {
6683 : 52 : id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
6684 : : baselinkp ? baselinkp : &baselink,
6685 : : ambiguousp);
6686 : 38 : if (id == NULL_TREE)
6687 : 14 : continue;
6688 : 24 : if (!ambiguousp->is_empty ())
6689 : 3 : ambiguousp->safe_push (id);
6690 : 21 : else if (ret != NULL_TREE)
6691 : : {
6692 : 6 : ambiguousp->safe_push (ret);
6693 : 6 : ambiguousp->safe_push (id);
6694 : 6 : ret = NULL_TREE;
6695 : : }
6696 : : else
6697 : 15 : ret = id;
6698 : : }
6699 : 35 : if (ambiguousp != &ambiguous)
6700 : 16 : return ret;
6701 : 19 : if (!ambiguous.is_empty ())
6702 : : {
6703 : 6 : auto_diagnostic_group d;
6704 : 6 : const char *str = _("candidates are:");
6705 : 6 : unsigned int idx;
6706 : 6 : tree udr;
6707 : 6 : error_at (loc, "user defined reduction lookup is ambiguous");
6708 : 27 : FOR_EACH_VEC_ELT (ambiguous, idx, udr)
6709 : : {
6710 : 15 : inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
6711 : 15 : if (idx == 0)
6712 : 6 : str = get_spaces (str);
6713 : : }
6714 : 6 : ret = error_mark_node;
6715 : 6 : baselink = NULL_TREE;
6716 : 6 : }
6717 : 19 : id = ret;
6718 : 35 : }
6719 : 1268 : if (id && baselink)
6720 : 74 : perform_or_defer_access_check (BASELINK_BINFO (baselink),
6721 : : id, id, tf_warning_or_error);
6722 : : return id;
6723 : : }
6724 : :
6725 : : /* Helper function for cp_parser_omp_declare_reduction_exprs
6726 : : and tsubst_omp_udr.
6727 : : Remove CLEANUP_STMT for data (omp_priv variable).
6728 : : Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
6729 : : DECL_EXPR. */
6730 : :
6731 : : tree
6732 : 4341 : cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
6733 : : {
6734 : 4341 : if (TYPE_P (*tp))
6735 : 221 : *walk_subtrees = 0;
6736 : 4120 : else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
6737 : 52 : *tp = CLEANUP_BODY (*tp);
6738 : 4068 : else if (TREE_CODE (*tp) == DECL_EXPR)
6739 : : {
6740 : 298 : tree decl = DECL_EXPR_DECL (*tp);
6741 : 298 : if (!processing_template_decl
6742 : 252 : && decl == (tree) data
6743 : 252 : && DECL_INITIAL (decl)
6744 : 387 : && DECL_INITIAL (decl) != error_mark_node)
6745 : : {
6746 : 89 : tree list = NULL_TREE;
6747 : 89 : append_to_statement_list_force (*tp, &list);
6748 : 89 : tree init_expr = build2 (INIT_EXPR, void_type_node,
6749 : 89 : decl, DECL_INITIAL (decl));
6750 : 89 : DECL_INITIAL (decl) = NULL_TREE;
6751 : 89 : append_to_statement_list_force (init_expr, &list);
6752 : 89 : *tp = list;
6753 : : }
6754 : : }
6755 : 4341 : return NULL_TREE;
6756 : : }
6757 : :
6758 : : /* Data passed from cp_check_omp_declare_reduction to
6759 : : cp_check_omp_declare_reduction_r. */
6760 : :
6761 : : struct cp_check_omp_declare_reduction_data
6762 : : {
6763 : : location_t loc;
6764 : : tree stmts[7];
6765 : : bool combiner_p;
6766 : : };
6767 : :
6768 : : /* Helper function for cp_check_omp_declare_reduction, called via
6769 : : cp_walk_tree. */
6770 : :
6771 : : static tree
6772 : 14808 : cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
6773 : : {
6774 : 14808 : struct cp_check_omp_declare_reduction_data *udr_data
6775 : : = (struct cp_check_omp_declare_reduction_data *) data;
6776 : 14808 : if (SSA_VAR_P (*tp)
6777 : 2666 : && !DECL_ARTIFICIAL (*tp)
6778 : 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
6779 : 225 : && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
6780 : : {
6781 : 135 : location_t loc = udr_data->loc;
6782 : 135 : if (udr_data->combiner_p)
6783 : 45 : error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
6784 : : "variable %qD which is not %<omp_out%> nor %<omp_in%>",
6785 : : *tp);
6786 : : else
6787 : 90 : error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
6788 : : "to variable %qD which is not %<omp_priv%> nor "
6789 : : "%<omp_orig%>",
6790 : : *tp);
6791 : 135 : return *tp;
6792 : : }
6793 : : return NULL_TREE;
6794 : : }
6795 : :
6796 : : /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
6797 : :
6798 : : bool
6799 : 1090 : cp_check_omp_declare_reduction (tree udr)
6800 : : {
6801 : 1090 : tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
6802 : 1090 : gcc_assert (TYPE_REF_P (type));
6803 : 1090 : type = TREE_TYPE (type);
6804 : 1090 : int i;
6805 : 1090 : location_t loc = DECL_SOURCE_LOCATION (udr);
6806 : :
6807 : 1090 : if (type == error_mark_node)
6808 : : return false;
6809 : 1090 : if (ARITHMETIC_TYPE_P (type))
6810 : : {
6811 : : static enum tree_code predef_codes[]
6812 : : = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
6813 : : BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
6814 : 3276 : for (i = 0; i < 8; i++)
6815 : : {
6816 : 2918 : tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
6817 : 2918 : const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
6818 : 2918 : const char *n2 = IDENTIFIER_POINTER (id);
6819 : 2918 : if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
6820 : 2918 : && (n1[IDENTIFIER_LENGTH (id)] == '~'
6821 : 0 : || n1[IDENTIFIER_LENGTH (id)] == '\0'))
6822 : : break;
6823 : : }
6824 : :
6825 : 376 : if (i == 8
6826 : 358 : && TREE_CODE (type) != COMPLEX_EXPR)
6827 : : {
6828 : 358 : const char prefix_minmax[] = "omp declare reduction m";
6829 : 358 : size_t prefix_size = sizeof (prefix_minmax) - 1;
6830 : 358 : const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
6831 : 358 : if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
6832 : : prefix_minmax, prefix_size) == 0
6833 : 10 : && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
6834 : 4 : || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
6835 : 368 : && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
6836 : 6 : i = 0;
6837 : : }
6838 : 376 : if (i < 8)
6839 : : {
6840 : 24 : error_at (loc, "predeclared arithmetic type %qT in "
6841 : : "%<#pragma omp declare reduction%>", type);
6842 : 24 : return false;
6843 : : }
6844 : : }
6845 : : else if (FUNC_OR_METHOD_TYPE_P (type)
6846 : : || TREE_CODE (type) == ARRAY_TYPE)
6847 : : {
6848 : 24 : error_at (loc, "function or array type %qT in "
6849 : : "%<#pragma omp declare reduction%>", type);
6850 : 24 : return false;
6851 : : }
6852 : : else if (TYPE_REF_P (type))
6853 : : {
6854 : 0 : error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
6855 : : type);
6856 : 0 : return false;
6857 : : }
6858 : 690 : else if (TYPE_QUALS_NO_ADDR_SPACE (type))
6859 : : {
6860 : 24 : error_at (loc, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
6861 : : "type %qT in %<#pragma omp declare reduction%>", type);
6862 : 24 : return false;
6863 : : }
6864 : :
6865 : 1018 : tree body = DECL_SAVED_TREE (udr);
6866 : 1018 : if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
6867 : : return true;
6868 : :
6869 : 835 : tree_stmt_iterator tsi;
6870 : 835 : struct cp_check_omp_declare_reduction_data data;
6871 : 835 : memset (data.stmts, 0, sizeof data.stmts);
6872 : 835 : for (i = 0, tsi = tsi_start (body);
6873 : 4627 : i < 7 && !tsi_end_p (tsi);
6874 : 3792 : i++, tsi_next (&tsi))
6875 : 3792 : data.stmts[i] = tsi_stmt (tsi);
6876 : 835 : data.loc = loc;
6877 : 835 : gcc_assert (tsi_end_p (tsi));
6878 : 835 : if (i >= 3)
6879 : : {
6880 : 835 : gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
6881 : : && TREE_CODE (data.stmts[1]) == DECL_EXPR);
6882 : 835 : if (warning_suppressed_p (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */))
6883 : : return true;
6884 : 790 : data.combiner_p = true;
6885 : 790 : if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
6886 : : &data, NULL))
6887 : 45 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* What warning? */);
6888 : : }
6889 : 790 : if (i >= 6)
6890 : : {
6891 : 330 : gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
6892 : : && TREE_CODE (data.stmts[4]) == DECL_EXPR);
6893 : 330 : data.combiner_p = false;
6894 : 330 : if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
6895 : : &data, NULL)
6896 : 330 : || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
6897 : : cp_check_omp_declare_reduction_r, &data, NULL))
6898 : 90 : suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /* Wat warning? */);
6899 : 330 : if (i == 7)
6900 : 192 : gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
6901 : : }
6902 : : return true;
6903 : : }
6904 : :
6905 : : /* Helper function of finish_omp_clauses. Clone STMT as if we were making
6906 : : an inline call. But, remap
6907 : : the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
6908 : : and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
6909 : :
6910 : : static tree
6911 : 2191 : clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
6912 : : tree decl, tree placeholder)
6913 : : {
6914 : 2191 : copy_body_data id;
6915 : 2191 : hash_map<tree, tree> decl_map;
6916 : :
6917 : 2191 : decl_map.put (omp_decl1, placeholder);
6918 : 2191 : decl_map.put (omp_decl2, decl);
6919 : 2191 : memset (&id, 0, sizeof (id));
6920 : 2191 : id.src_fn = DECL_CONTEXT (omp_decl1);
6921 : 2191 : id.dst_fn = current_function_decl;
6922 : 2191 : id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
6923 : 2191 : id.decl_map = &decl_map;
6924 : :
6925 : 2191 : id.copy_decl = copy_decl_no_change;
6926 : 2191 : id.transform_call_graph_edges = CB_CGE_DUPLICATE;
6927 : 2191 : id.transform_new_cfg = true;
6928 : 2191 : id.transform_return_to_modify = false;
6929 : 2191 : id.eh_lp_nr = 0;
6930 : 2191 : walk_tree (&stmt, copy_tree_body_r, &id, NULL);
6931 : 2191 : return stmt;
6932 : 2191 : }
6933 : :
6934 : : /* Helper function of finish_omp_clauses, called via cp_walk_tree.
6935 : : Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
6936 : :
6937 : : static tree
6938 : 15231 : find_omp_placeholder_r (tree *tp, int *, void *data)
6939 : : {
6940 : 15231 : if (*tp == (tree) data)
6941 : 265 : return *tp;
6942 : : return NULL_TREE;
6943 : : }
6944 : :
6945 : : /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
6946 : : Return true if there is some error and the clause should be removed. */
6947 : :
6948 : : static bool
6949 : 8910 : finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
6950 : : {
6951 : 8910 : tree t = OMP_CLAUSE_DECL (c);
6952 : 8910 : bool predefined = false;
6953 : 8910 : if (TREE_CODE (t) == TREE_LIST)
6954 : : {
6955 : 0 : gcc_assert (processing_template_decl);
6956 : : return false;
6957 : : }
6958 : 8910 : tree type = TREE_TYPE (t);
6959 : 8910 : if (TREE_CODE (t) == MEM_REF)
6960 : 1656 : type = TREE_TYPE (type);
6961 : 8910 : if (TYPE_REF_P (type))
6962 : 557 : type = TREE_TYPE (type);
6963 : 8910 : if (TREE_CODE (type) == ARRAY_TYPE)
6964 : : {
6965 : 377 : tree oatype = type;
6966 : 377 : gcc_assert (TREE_CODE (t) != MEM_REF);
6967 : 757 : while (TREE_CODE (type) == ARRAY_TYPE)
6968 : 380 : type = TREE_TYPE (type);
6969 : 377 : if (!processing_template_decl)
6970 : : {
6971 : 270 : t = require_complete_type (t);
6972 : 270 : if (t == error_mark_node
6973 : 270 : || !complete_type_or_else (oatype, NULL_TREE))
6974 : 9 : return true;
6975 : 261 : tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
6976 : : TYPE_SIZE_UNIT (type));
6977 : 261 : if (integer_zerop (size))
6978 : : {
6979 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
6980 : : "%qE in %<reduction%> clause is a zero size array",
6981 : : omp_clause_printable_decl (t));
6982 : 3 : return true;
6983 : : }
6984 : 258 : size = size_binop (MINUS_EXPR, size, size_one_node);
6985 : 258 : size = save_expr (size);
6986 : 258 : tree index_type = build_index_type (size);
6987 : 258 : tree atype = build_array_type (type, index_type);
6988 : 258 : tree ptype = build_pointer_type (type);
6989 : 258 : if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6990 : 152 : t = build_fold_addr_expr (t);
6991 : 258 : t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
6992 : 258 : OMP_CLAUSE_DECL (c) = t;
6993 : : }
6994 : : }
6995 : 8898 : if (type == error_mark_node)
6996 : : return true;
6997 : 8895 : else if (ARITHMETIC_TYPE_P (type))
6998 : 7644 : switch (OMP_CLAUSE_REDUCTION_CODE (c))
6999 : : {
7000 : : case PLUS_EXPR:
7001 : : case MULT_EXPR:
7002 : : case MINUS_EXPR:
7003 : : case TRUTH_ANDIF_EXPR:
7004 : : case TRUTH_ORIF_EXPR:
7005 : : predefined = true;
7006 : : break;
7007 : 246 : case MIN_EXPR:
7008 : 246 : case MAX_EXPR:
7009 : 246 : if (TREE_CODE (type) == COMPLEX_TYPE)
7010 : : break;
7011 : : predefined = true;
7012 : : break;
7013 : 111 : case BIT_AND_EXPR:
7014 : 111 : case BIT_IOR_EXPR:
7015 : 111 : case BIT_XOR_EXPR:
7016 : 111 : if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
7017 : : break;
7018 : : predefined = true;
7019 : : break;
7020 : : default:
7021 : : break;
7022 : : }
7023 : 1251 : else if (TYPE_READONLY (type))
7024 : : {
7025 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
7026 : : "%qE has const type for %<reduction%>",
7027 : : omp_clause_printable_decl (t));
7028 : 9 : return true;
7029 : : }
7030 : 1242 : else if (!processing_template_decl)
7031 : : {
7032 : 1033 : t = require_complete_type (t);
7033 : 1033 : if (t == error_mark_node)
7034 : : return true;
7035 : 1033 : OMP_CLAUSE_DECL (c) = t;
7036 : : }
7037 : :
7038 : 1033 : if (predefined)
7039 : : {
7040 : 7422 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7041 : 7422 : return false;
7042 : : }
7043 : 1464 : else if (processing_template_decl)
7044 : : {
7045 : 218 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
7046 : : return true;
7047 : : return false;
7048 : : }
7049 : :
7050 : 1246 : tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
7051 : :
7052 : 1246 : type = TYPE_MAIN_VARIANT (type);
7053 : 1246 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
7054 : 1246 : if (id == NULL_TREE)
7055 : 924 : id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
7056 : : NULL_TREE, NULL_TREE);
7057 : 1246 : id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
7058 : 1246 : if (id)
7059 : : {
7060 : 1201 : if (id == error_mark_node)
7061 : : return true;
7062 : 1195 : mark_used (id);
7063 : 1195 : tree body = DECL_SAVED_TREE (id);
7064 : 1195 : if (!body)
7065 : : return true;
7066 : 1192 : if (TREE_CODE (body) == STATEMENT_LIST)
7067 : : {
7068 : 1192 : tree_stmt_iterator tsi;
7069 : 1192 : tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
7070 : 1192 : int i;
7071 : 1192 : tree stmts[7];
7072 : 1192 : tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
7073 : 1192 : atype = TREE_TYPE (atype);
7074 : 1192 : bool need_static_cast = !same_type_p (type, atype);
7075 : 1192 : memset (stmts, 0, sizeof stmts);
7076 : 1192 : for (i = 0, tsi = tsi_start (body);
7077 : 8490 : i < 7 && !tsi_end_p (tsi);
7078 : 7298 : i++, tsi_next (&tsi))
7079 : 7298 : stmts[i] = tsi_stmt (tsi);
7080 : 1192 : gcc_assert (tsi_end_p (tsi));
7081 : :
7082 : 1192 : if (i >= 3)
7083 : : {
7084 : 1192 : gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
7085 : : && TREE_CODE (stmts[1]) == DECL_EXPR);
7086 : 1192 : placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
7087 : 1192 : DECL_ARTIFICIAL (placeholder) = 1;
7088 : 1192 : DECL_IGNORED_P (placeholder) = 1;
7089 : 1192 : OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
7090 : 1192 : if (TREE_CODE (t) == MEM_REF)
7091 : : {
7092 : 600 : decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
7093 : : type);
7094 : 600 : DECL_ARTIFICIAL (decl_placeholder) = 1;
7095 : 600 : DECL_IGNORED_P (decl_placeholder) = 1;
7096 : 600 : OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
7097 : : }
7098 : 1192 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
7099 : 282 : cxx_mark_addressable (placeholder);
7100 : 1192 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
7101 : 1192 : && (decl_placeholder
7102 : 146 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7103 : 366 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7104 : 115 : : OMP_CLAUSE_DECL (c));
7105 : 1192 : tree omp_out = placeholder;
7106 : 1192 : tree omp_in = decl_placeholder ? decl_placeholder
7107 : 592 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7108 : 1192 : if (need_static_cast)
7109 : : {
7110 : 7 : tree rtype = build_reference_type (atype);
7111 : 7 : omp_out = build_static_cast (input_location,
7112 : : rtype, omp_out,
7113 : : tf_warning_or_error);
7114 : 7 : omp_in = build_static_cast (input_location,
7115 : : rtype, omp_in,
7116 : : tf_warning_or_error);
7117 : 7 : if (omp_out == error_mark_node || omp_in == error_mark_node)
7118 : 3 : return true;
7119 : 7 : omp_out = convert_from_reference (omp_out);
7120 : 7 : omp_in = convert_from_reference (omp_in);
7121 : : }
7122 : 1192 : OMP_CLAUSE_REDUCTION_MERGE (c)
7123 : 1192 : = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
7124 : 1192 : DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
7125 : : }
7126 : 1192 : if (i >= 6)
7127 : : {
7128 : 1002 : gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
7129 : : && TREE_CODE (stmts[4]) == DECL_EXPR);
7130 : 1002 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3]))
7131 : 1002 : && (decl_placeholder
7132 : 232 : || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))))
7133 : 844 : cxx_mark_addressable (decl_placeholder ? decl_placeholder
7134 : 170 : : OMP_CLAUSE_DECL (c));
7135 : 1002 : if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
7136 : 216 : cxx_mark_addressable (placeholder);
7137 : 1002 : tree omp_priv = decl_placeholder ? decl_placeholder
7138 : 426 : : convert_from_reference (OMP_CLAUSE_DECL (c));
7139 : 1002 : tree omp_orig = placeholder;
7140 : 1002 : if (need_static_cast)
7141 : : {
7142 : 5 : if (i == 7)
7143 : : {
7144 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
7145 : : "user defined reduction with constructor "
7146 : : "initializer for base class %qT", atype);
7147 : 3 : return true;
7148 : : }
7149 : 2 : tree rtype = build_reference_type (atype);
7150 : 2 : omp_priv = build_static_cast (input_location,
7151 : : rtype, omp_priv,
7152 : : tf_warning_or_error);
7153 : 2 : omp_orig = build_static_cast (input_location,
7154 : : rtype, omp_orig,
7155 : : tf_warning_or_error);
7156 : 2 : if (omp_priv == error_mark_node
7157 : 2 : || omp_orig == error_mark_node)
7158 : : return true;
7159 : 2 : omp_priv = convert_from_reference (omp_priv);
7160 : 2 : omp_orig = convert_from_reference (omp_orig);
7161 : : }
7162 : 999 : if (i == 6)
7163 : 286 : *need_default_ctor = true;
7164 : 999 : OMP_CLAUSE_REDUCTION_INIT (c)
7165 : 999 : = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
7166 : 999 : DECL_EXPR_DECL (stmts[3]),
7167 : : omp_priv, omp_orig);
7168 : 999 : if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
7169 : : find_omp_placeholder_r, placeholder, NULL))
7170 : 238 : OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
7171 : : }
7172 : 190 : else if (i >= 3)
7173 : : {
7174 : 190 : if (CLASS_TYPE_P (type) && !pod_type_p (type))
7175 : 175 : *need_default_ctor = true;
7176 : : else
7177 : : {
7178 : 15 : tree init;
7179 : 15 : tree v = decl_placeholder ? decl_placeholder
7180 : 15 : : convert_from_reference (t);
7181 : 15 : if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
7182 : 6 : init = build_constructor (TREE_TYPE (v), NULL);
7183 : : else
7184 : 9 : init = fold_convert (TREE_TYPE (v), integer_zero_node);
7185 : 30 : OMP_CLAUSE_REDUCTION_INIT (c)
7186 : 30 : = cp_build_init_expr (v, init);
7187 : : }
7188 : : }
7189 : : }
7190 : : }
7191 : 1234 : if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
7192 : 1189 : *need_dtor = true;
7193 : : else
7194 : : {
7195 : 90 : error_at (OMP_CLAUSE_LOCATION (c),
7196 : : "user defined reduction not found for %qE",
7197 : : omp_clause_printable_decl (t));
7198 : 45 : return true;
7199 : : }
7200 : 1189 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
7201 : 600 : gcc_assert (TYPE_SIZE_UNIT (type)
7202 : : && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
7203 : : return false;
7204 : : }
7205 : :
7206 : : /* Called from finish_struct_1. linear(this) or linear(this:step)
7207 : : clauses might not be finalized yet because the class has been incomplete
7208 : : when parsing #pragma omp declare simd methods. Fix those up now. */
7209 : :
7210 : : void
7211 : 36943 : finish_omp_declare_simd_methods (tree t)
7212 : : {
7213 : 36943 : if (processing_template_decl)
7214 : : return;
7215 : :
7216 : 244715 : for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
7217 : : {
7218 : 350227 : if (TREE_CODE (x) == USING_DECL
7219 : 207772 : || !DECL_IOBJ_MEMBER_FUNCTION_P (x))
7220 : 142455 : continue;
7221 : 65317 : tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
7222 : 65425 : if (!ods || !TREE_VALUE (ods))
7223 : 65209 : continue;
7224 : 366 : for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
7225 : 258 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
7226 : 66 : && integer_zerop (OMP_CLAUSE_DECL (c))
7227 : 18 : && OMP_CLAUSE_LINEAR_STEP (c)
7228 : 276 : && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
7229 : : {
7230 : 18 : tree s = OMP_CLAUSE_LINEAR_STEP (c);
7231 : 18 : s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
7232 : 18 : s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
7233 : 18 : sizetype, s, TYPE_SIZE_UNIT (t));
7234 : 18 : OMP_CLAUSE_LINEAR_STEP (c) = s;
7235 : : }
7236 : : }
7237 : : }
7238 : :
7239 : : /* Adjust sink depend/doacross clause to take into account pointer offsets.
7240 : :
7241 : : Return TRUE if there was a problem processing the offset, and the
7242 : : whole clause should be removed. */
7243 : :
7244 : : static bool
7245 : 295 : cp_finish_omp_clause_doacross_sink (tree sink_clause)
7246 : : {
7247 : 295 : tree t = OMP_CLAUSE_DECL (sink_clause);
7248 : 295 : gcc_assert (TREE_CODE (t) == TREE_LIST);
7249 : :
7250 : : /* Make sure we don't adjust things twice for templates. */
7251 : 295 : if (processing_template_decl)
7252 : : return false;
7253 : :
7254 : 665 : for (; t; t = TREE_CHAIN (t))
7255 : : {
7256 : 388 : tree decl = TREE_VALUE (t);
7257 : 388 : if (TYPE_PTR_P (TREE_TYPE (decl)))
7258 : : {
7259 : 6 : tree offset = TREE_PURPOSE (t);
7260 : 6 : bool neg = wi::neg_p (wi::to_wide (offset));
7261 : 6 : offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
7262 : 6 : decl = mark_rvalue_use (decl);
7263 : 6 : decl = convert_from_reference (decl);
7264 : 12 : tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
7265 : : neg ? MINUS_EXPR : PLUS_EXPR,
7266 : : decl, offset);
7267 : 6 : t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
7268 : : MINUS_EXPR, sizetype,
7269 : : fold_convert (sizetype, t2),
7270 : : fold_convert (sizetype, decl));
7271 : 6 : if (t2 == error_mark_node)
7272 : : return true;
7273 : 6 : TREE_PURPOSE (t) = t2;
7274 : : }
7275 : : }
7276 : : return false;
7277 : : }
7278 : :
7279 : : /* Finish OpenMP iterators ITER. Return true if they are errorneous
7280 : : and clauses containing them should be removed. */
7281 : :
7282 : : static bool
7283 : 523 : cp_omp_finish_iterators (tree iter)
7284 : : {
7285 : 523 : bool ret = false;
7286 : 1157 : for (tree it = iter; it; it = TREE_CHAIN (it))
7287 : : {
7288 : 634 : tree var = TREE_VEC_ELT (it, 0);
7289 : 634 : tree begin = TREE_VEC_ELT (it, 1);
7290 : 634 : tree end = TREE_VEC_ELT (it, 2);
7291 : 634 : tree step = TREE_VEC_ELT (it, 3);
7292 : 634 : tree orig_step;
7293 : 634 : tree type = TREE_TYPE (var);
7294 : 634 : location_t loc = DECL_SOURCE_LOCATION (var);
7295 : 634 : if (type == error_mark_node)
7296 : : {
7297 : 0 : ret = true;
7298 : 218 : continue;
7299 : : }
7300 : 634 : if (type_dependent_expression_p (var))
7301 : 59 : continue;
7302 : 575 : if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
7303 : : {
7304 : 27 : error_at (loc, "iterator %qD has neither integral nor pointer type",
7305 : : var);
7306 : 27 : ret = true;
7307 : 27 : continue;
7308 : : }
7309 : 548 : else if (TYPE_READONLY (type))
7310 : : {
7311 : 24 : error_at (loc, "iterator %qD has const qualified type", var);
7312 : 24 : ret = true;
7313 : 24 : continue;
7314 : : }
7315 : 524 : if (type_dependent_expression_p (begin)
7316 : 515 : || type_dependent_expression_p (end)
7317 : 1039 : || type_dependent_expression_p (step))
7318 : 15 : continue;
7319 : 509 : else if (error_operand_p (step))
7320 : : {
7321 : 0 : ret = true;
7322 : 0 : continue;
7323 : : }
7324 : 509 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
7325 : : {
7326 : 33 : error_at (EXPR_LOC_OR_LOC (step, loc),
7327 : : "iterator step with non-integral type");
7328 : 21 : ret = true;
7329 : 21 : continue;
7330 : : }
7331 : :
7332 : 488 : begin = mark_rvalue_use (begin);
7333 : 488 : end = mark_rvalue_use (end);
7334 : 488 : step = mark_rvalue_use (step);
7335 : 488 : begin = cp_build_c_cast (input_location, type, begin,
7336 : : tf_warning_or_error);
7337 : 488 : end = cp_build_c_cast (input_location, type, end,
7338 : : tf_warning_or_error);
7339 : 488 : orig_step = step;
7340 : 488 : if (!processing_template_decl)
7341 : 411 : step = orig_step = save_expr (step);
7342 : 488 : tree stype = POINTER_TYPE_P (type) ? sizetype : type;
7343 : 488 : step = cp_build_c_cast (input_location, stype, step,
7344 : : tf_warning_or_error);
7345 : 488 : if (POINTER_TYPE_P (type) && !processing_template_decl)
7346 : : {
7347 : 66 : begin = save_expr (begin);
7348 : 66 : step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
7349 : 66 : step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
7350 : : fold_convert (sizetype, step),
7351 : : fold_convert (sizetype, begin));
7352 : 66 : step = fold_convert (ssizetype, step);
7353 : : }
7354 : 488 : if (!processing_template_decl)
7355 : : {
7356 : 411 : begin = maybe_constant_value (begin);
7357 : 411 : end = maybe_constant_value (end);
7358 : 411 : step = maybe_constant_value (step);
7359 : 411 : orig_step = maybe_constant_value (orig_step);
7360 : : }
7361 : 488 : if (integer_zerop (step))
7362 : : {
7363 : 27 : error_at (loc, "iterator %qD has zero step", var);
7364 : 27 : ret = true;
7365 : 27 : continue;
7366 : : }
7367 : :
7368 : 461 : if (begin == error_mark_node
7369 : 452 : || end == error_mark_node
7370 : 443 : || step == error_mark_node
7371 : 443 : || orig_step == error_mark_node)
7372 : : {
7373 : 18 : ret = true;
7374 : 18 : continue;
7375 : : }
7376 : :
7377 : 443 : if (!processing_template_decl)
7378 : : {
7379 : 366 : begin = fold_build_cleanup_point_expr (TREE_TYPE (begin), begin);
7380 : 366 : end = fold_build_cleanup_point_expr (TREE_TYPE (end), end);
7381 : 366 : step = fold_build_cleanup_point_expr (TREE_TYPE (step), step);
7382 : 366 : orig_step = fold_build_cleanup_point_expr (TREE_TYPE (orig_step),
7383 : : orig_step);
7384 : : }
7385 : 443 : hash_set<tree> pset;
7386 : 443 : tree it2;
7387 : 527 : for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
7388 : : {
7389 : 111 : tree var2 = TREE_VEC_ELT (it2, 0);
7390 : 111 : tree begin2 = TREE_VEC_ELT (it2, 1);
7391 : 111 : tree end2 = TREE_VEC_ELT (it2, 2);
7392 : 111 : tree step2 = TREE_VEC_ELT (it2, 3);
7393 : 111 : location_t loc2 = DECL_SOURCE_LOCATION (var2);
7394 : 111 : if (cp_walk_tree (&begin2, find_omp_placeholder_r, var, &pset))
7395 : : {
7396 : 9 : error_at (EXPR_LOC_OR_LOC (begin2, loc2),
7397 : : "begin expression refers to outer iterator %qD", var);
7398 : 36 : break;
7399 : : }
7400 : 102 : else if (cp_walk_tree (&end2, find_omp_placeholder_r, var, &pset))
7401 : : {
7402 : 9 : error_at (EXPR_LOC_OR_LOC (end2, loc2),
7403 : : "end expression refers to outer iterator %qD", var);
7404 : 9 : break;
7405 : : }
7406 : 93 : else if (cp_walk_tree (&step2, find_omp_placeholder_r, var, &pset))
7407 : : {
7408 : 9 : error_at (EXPR_LOC_OR_LOC (step2, loc2),
7409 : : "step expression refers to outer iterator %qD", var);
7410 : 9 : break;
7411 : : }
7412 : : }
7413 : 443 : if (it2)
7414 : : {
7415 : 27 : ret = true;
7416 : 27 : continue;
7417 : : }
7418 : 416 : TREE_VEC_ELT (it, 1) = begin;
7419 : 416 : TREE_VEC_ELT (it, 2) = end;
7420 : 416 : if (processing_template_decl)
7421 : 71 : TREE_VEC_ELT (it, 3) = orig_step;
7422 : : else
7423 : : {
7424 : 345 : TREE_VEC_ELT (it, 3) = step;
7425 : 345 : TREE_VEC_ELT (it, 4) = orig_step;
7426 : : }
7427 : 443 : }
7428 : 523 : return ret;
7429 : : }
7430 : :
7431 : : /* Ensure that pointers are used in OpenACC attach and detach clauses.
7432 : : Return true if an error has been detected. */
7433 : :
7434 : : static bool
7435 : 17513 : cp_oacc_check_attachments (tree c)
7436 : : {
7437 : 17513 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
7438 : : return false;
7439 : :
7440 : : /* OpenACC attach / detach clauses must be pointers. */
7441 : 13615 : if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
7442 : 13615 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
7443 : : {
7444 : 185 : tree t = OMP_CLAUSE_DECL (c);
7445 : 185 : tree type;
7446 : :
7447 : 221 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7448 : 36 : t = TREE_OPERAND (t, 0);
7449 : :
7450 : 185 : type = TREE_TYPE (t);
7451 : :
7452 : 185 : if (TREE_CODE (type) == REFERENCE_TYPE)
7453 : 36 : type = TREE_TYPE (type);
7454 : :
7455 : 185 : if (TREE_CODE (type) != POINTER_TYPE)
7456 : : {
7457 : 36 : error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
7458 : : user_omp_clause_code_name (c, true));
7459 : 36 : return true;
7460 : : }
7461 : : }
7462 : :
7463 : : return false;
7464 : : }
7465 : :
7466 : : /* Update OMP_CLAUSE_INIT_PREFER_TYPE in case template substitution
7467 : : happened. */
7468 : :
7469 : : static void
7470 : 601 : cp_omp_init_prefer_type_update (tree c)
7471 : : {
7472 : 601 : if (processing_template_decl
7473 : 532 : || OMP_CLAUSE_INIT_PREFER_TYPE (c) == NULL_TREE
7474 : 804 : || TREE_CODE (OMP_CLAUSE_INIT_PREFER_TYPE (c)) != TREE_LIST)
7475 : : return;
7476 : :
7477 : 54 : tree t = TREE_PURPOSE (OMP_CLAUSE_INIT_PREFER_TYPE (c));
7478 : 54 : char *str = const_cast<char *> (TREE_STRING_POINTER (t));
7479 : 54 : tree fr_list = TREE_VALUE (OMP_CLAUSE_INIT_PREFER_TYPE (c));
7480 : 54 : int len = TREE_VEC_LENGTH (fr_list);
7481 : 54 : int cnt = 0;
7482 : :
7483 : 216 : while (str[0] == (char) GOMP_INTEROP_IFR_SEPARATOR)
7484 : : {
7485 : 216 : str++;
7486 : 216 : if (str[0] == (char) GOMP_INTEROP_IFR_UNKNOWN)
7487 : : {
7488 : : /* Assume a no or a single 'fr'. */
7489 : 96 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7490 : 96 : location_t loc = UNKNOWN_LOCATION;
7491 : 96 : tree value = TREE_VEC_ELT (fr_list, cnt);
7492 : 96 : if (value != NULL_TREE && value != error_mark_node)
7493 : : {
7494 : 72 : loc = EXPR_LOCATION (value);
7495 : 72 : if (value && TREE_CODE (value) == NOP_EXPR)
7496 : 39 : value = TREE_OPERAND (value, 0);
7497 : 72 : value = cp_fully_fold (value);
7498 : : }
7499 : 72 : if (value != NULL_TREE && value != error_mark_node)
7500 : : {
7501 : 72 : if (TREE_CODE (value) != INTEGER_CST
7502 : 72 : || !tree_fits_shwi_p (value))
7503 : 0 : error_at (loc,
7504 : : "expected string literal or "
7505 : : "constant integer expression instead of %qE", value); // FIXME of 'qE' and no 'loc'?
7506 : : else
7507 : : {
7508 : 72 : HOST_WIDE_INT n = tree_to_shwi (value);
7509 : 72 : if (n < 1 || n > GOMP_INTEROP_IFR_LAST)
7510 : : {
7511 : 48 : warning_at (loc, OPT_Wopenmp,
7512 : : "unknown foreign runtime identifier %qwd", n);
7513 : 48 : n = GOMP_INTEROP_IFR_UNKNOWN;
7514 : : }
7515 : 72 : str[0] = (char) n;
7516 : : }
7517 : : }
7518 : 96 : str++;
7519 : : }
7520 : 120 : else if (str[0] != (char) GOMP_INTEROP_IFR_SEPARATOR)
7521 : : {
7522 : : /* Assume a no or a single 'fr'. */
7523 : 120 : gcc_checking_assert (str[1] == (char) GOMP_INTEROP_IFR_SEPARATOR);
7524 : 120 : str++;
7525 : : }
7526 : 216 : str++;
7527 : 228 : while (str[0] != '\0')
7528 : 12 : str += strlen (str) + 1;
7529 : 216 : str++;
7530 : 216 : cnt++;
7531 : 216 : if (cnt >= len)
7532 : : break;
7533 : : }
7534 : 54 : OMP_CLAUSE_INIT_PREFER_TYPE (c) = t;
7535 : : }
7536 : :
7537 : : /* For all elements of CLAUSES, validate them vs OpenMP constraints.
7538 : : Remove any elements from the list that are invalid. */
7539 : :
7540 : : tree
7541 : 61981 : finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
7542 : : {
7543 : 61981 : bitmap_head generic_head, firstprivate_head, lastprivate_head;
7544 : 61981 : bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
7545 : 61981 : bitmap_head oacc_reduction_head, is_on_device_head;
7546 : 61981 : tree c, t, *pc;
7547 : 61981 : tree safelen = NULL_TREE;
7548 : 61981 : bool openacc = (ort & C_ORT_ACC) != 0;
7549 : 61981 : bool branch_seen = false;
7550 : 61981 : bool copyprivate_seen = false;
7551 : 61981 : bool ordered_seen = false;
7552 : 61981 : bool order_seen = false;
7553 : 61981 : bool schedule_seen = false;
7554 : 61981 : bool oacc_async = false;
7555 : 61981 : bool indir_component_ref_p = false;
7556 : 61981 : tree last_iterators = NULL_TREE;
7557 : 61981 : bool last_iterators_remove = false;
7558 : : /* 1 if normal/task reduction has been seen, -1 if inscan reduction
7559 : : has been seen, -2 if mixed inscan/normal reduction diagnosed. */
7560 : 61981 : int reduction_seen = 0;
7561 : 61981 : bool allocate_seen = false;
7562 : 61981 : tree detach_seen = NULL_TREE;
7563 : 61981 : bool mergeable_seen = false;
7564 : 61981 : bool implicit_moved = false;
7565 : 61981 : bool target_in_reduction_seen = false;
7566 : 61981 : bool num_tasks_seen = false;
7567 : 61981 : bool partial_seen = false;
7568 : 61981 : bool init_seen = false;
7569 : 61981 : bool init_use_destroy_seen = false;
7570 : 61981 : tree init_no_targetsync_clause = NULL_TREE;
7571 : 61981 : tree depend_clause = NULL_TREE;
7572 : :
7573 : 61981 : bitmap_obstack_initialize (NULL);
7574 : 61981 : bitmap_initialize (&generic_head, &bitmap_default_obstack);
7575 : 61981 : bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
7576 : 61981 : bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
7577 : 61981 : bitmap_initialize (&aligned_head, &bitmap_default_obstack);
7578 : : /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
7579 : 61981 : bitmap_initialize (&map_head, &bitmap_default_obstack);
7580 : 61981 : bitmap_initialize (&map_field_head, &bitmap_default_obstack);
7581 : 61981 : bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
7582 : : /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
7583 : : instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
7584 : 61981 : bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
7585 : 61981 : bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
7586 : :
7587 : 61981 : if (openacc)
7588 : 28433 : for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
7589 : 15985 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
7590 : : {
7591 : : oacc_async = true;
7592 : : break;
7593 : : }
7594 : :
7595 : 61981 : tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
7596 : :
7597 : 158630 : for (pc = &clauses, c = clauses; c ; c = *pc)
7598 : : {
7599 : 96649 : bool remove = false;
7600 : 96649 : bool field_ok = false;
7601 : :
7602 : : /* We've reached the end of a list of expanded nodes. Reset the group
7603 : : start pointer. */
7604 : 96649 : if (c == grp_sentinel)
7605 : 5129 : grp_start_p = NULL;
7606 : :
7607 : 96649 : switch (OMP_CLAUSE_CODE (c))
7608 : : {
7609 : 2094 : case OMP_CLAUSE_SHARED:
7610 : 2094 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7611 : 2094 : goto check_dup_generic;
7612 : 2532 : case OMP_CLAUSE_PRIVATE:
7613 : 2532 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7614 : 2532 : goto check_dup_generic;
7615 : 7443 : case OMP_CLAUSE_REDUCTION:
7616 : 7443 : if (reduction_seen == 0)
7617 : 6339 : reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
7618 : 1104 : else if (reduction_seen != -2
7619 : 2208 : && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
7620 : 1104 : ? -1 : 1))
7621 : : {
7622 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7623 : : "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
7624 : : "on the same construct");
7625 : 6 : reduction_seen = -2;
7626 : : }
7627 : : /* FALLTHRU */
7628 : 9585 : case OMP_CLAUSE_IN_REDUCTION:
7629 : 9585 : case OMP_CLAUSE_TASK_REDUCTION:
7630 : 9585 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7631 : 9585 : t = OMP_CLAUSE_DECL (c);
7632 : 9585 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7633 : : {
7634 : 2315 : if (handle_omp_array_sections (c, ort))
7635 : : {
7636 : : remove = true;
7637 : : break;
7638 : : }
7639 : 2273 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
7640 : 2273 : && OMP_CLAUSE_REDUCTION_INSCAN (c))
7641 : : {
7642 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
7643 : : "%<inscan%> %<reduction%> clause with array "
7644 : : "section");
7645 : 3 : remove = true;
7646 : 3 : break;
7647 : : }
7648 : 2270 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
7649 : : {
7650 : 4888 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
7651 : 2618 : t = TREE_OPERAND (t, 0);
7652 : : }
7653 : : else
7654 : : {
7655 : 0 : gcc_assert (TREE_CODE (t) == MEM_REF);
7656 : 0 : t = TREE_OPERAND (t, 0);
7657 : 0 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
7658 : 0 : t = TREE_OPERAND (t, 0);
7659 : 0 : if (TREE_CODE (t) == ADDR_EXPR
7660 : 0 : || INDIRECT_REF_P (t))
7661 : 0 : t = TREE_OPERAND (t, 0);
7662 : : }
7663 : 2270 : tree n = omp_clause_decl_field (t);
7664 : 2270 : if (n)
7665 : 59 : t = n;
7666 : 2270 : goto check_dup_generic_t;
7667 : : }
7668 : 7270 : if (oacc_async)
7669 : 7 : cxx_mark_addressable (t);
7670 : 7270 : goto check_dup_generic;
7671 : 98 : case OMP_CLAUSE_COPYPRIVATE:
7672 : 98 : copyprivate_seen = true;
7673 : 98 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7674 : 98 : goto check_dup_generic;
7675 : 277 : case OMP_CLAUSE_COPYIN:
7676 : 277 : goto check_dup_generic;
7677 : 1613 : case OMP_CLAUSE_LINEAR:
7678 : 1613 : field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
7679 : 1613 : t = OMP_CLAUSE_DECL (c);
7680 : 1613 : if (ort != C_ORT_OMP_DECLARE_SIMD
7681 : 1613 : && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
7682 : : {
7683 : 84 : if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
7684 : : {
7685 : 42 : error_at (OMP_CLAUSE_LOCATION (c),
7686 : : "modifier should not be specified in %<linear%> "
7687 : : "clause on %<simd%> or %<for%> constructs when "
7688 : : "not using OpenMP 5.2 modifiers");
7689 : 42 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
7690 : : }
7691 : 42 : else if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_VAL)
7692 : : {
7693 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
7694 : : "modifier other than %<val%> specified in "
7695 : : "%<linear%> clause on %<simd%> or %<for%> "
7696 : : "constructs when using OpenMP 5.2 modifiers");
7697 : 18 : OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
7698 : : }
7699 : : }
7700 : 993 : if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
7701 : 2535 : && !type_dependent_expression_p (t))
7702 : : {
7703 : 1511 : tree type = TREE_TYPE (t);
7704 : 1511 : if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7705 : 1436 : || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
7706 : 1574 : && !TYPE_REF_P (type))
7707 : : {
7708 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
7709 : : "linear clause with %qs modifier applied to "
7710 : : "non-reference variable with %qT type",
7711 : 12 : OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
7712 : 12 : ? "ref" : "uval", TREE_TYPE (t));
7713 : 12 : remove = true;
7714 : 12 : break;
7715 : : }
7716 : 1499 : if (TYPE_REF_P (type))
7717 : 269 : type = TREE_TYPE (type);
7718 : 1499 : if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
7719 : : {
7720 : 1430 : if (!INTEGRAL_TYPE_P (type)
7721 : 85 : && !TYPE_PTR_P (type))
7722 : : {
7723 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
7724 : : "linear clause applied to non-integral "
7725 : : "non-pointer variable with %qT type",
7726 : 18 : TREE_TYPE (t));
7727 : 18 : remove = true;
7728 : 18 : break;
7729 : : }
7730 : : }
7731 : : }
7732 : 1583 : t = OMP_CLAUSE_LINEAR_STEP (c);
7733 : 1583 : if (t == NULL_TREE)
7734 : 6 : t = integer_one_node;
7735 : 1583 : if (t == error_mark_node)
7736 : : {
7737 : : remove = true;
7738 : : break;
7739 : : }
7740 : 1583 : else if (!type_dependent_expression_p (t)
7741 : 1581 : && !INTEGRAL_TYPE_P (TREE_TYPE (t))
7742 : 1595 : && (ort != C_ORT_OMP_DECLARE_SIMD
7743 : 9 : || TREE_CODE (t) != PARM_DECL
7744 : 6 : || !TYPE_REF_P (TREE_TYPE (t))
7745 : 6 : || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
7746 : : {
7747 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7748 : : "linear step expression must be integral");
7749 : 6 : remove = true;
7750 : 6 : break;
7751 : : }
7752 : : else
7753 : : {
7754 : 1577 : t = mark_rvalue_use (t);
7755 : 1577 : if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
7756 : : {
7757 : 42 : OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
7758 : 42 : goto check_dup_generic;
7759 : : }
7760 : 1535 : if (!processing_template_decl
7761 : 1535 : && (VAR_P (OMP_CLAUSE_DECL (c))
7762 : 817 : || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
7763 : : {
7764 : 1354 : if (ort == C_ORT_OMP_DECLARE_SIMD)
7765 : : {
7766 : 571 : t = maybe_constant_value (t);
7767 : 571 : if (TREE_CODE (t) != INTEGER_CST)
7768 : : {
7769 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7770 : : "%<linear%> clause step %qE is neither "
7771 : : "constant nor a parameter", t);
7772 : 6 : remove = true;
7773 : 6 : break;
7774 : : }
7775 : : }
7776 : 1348 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7777 : 1348 : tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
7778 : 1348 : if (TYPE_REF_P (type))
7779 : 245 : type = TREE_TYPE (type);
7780 : 1348 : if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
7781 : : {
7782 : 60 : type = build_pointer_type (type);
7783 : 60 : tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
7784 : 60 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
7785 : : d, t);
7786 : 60 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
7787 : : MINUS_EXPR, sizetype,
7788 : : fold_convert (sizetype, t),
7789 : : fold_convert (sizetype, d));
7790 : 60 : if (t == error_mark_node)
7791 : : {
7792 : : remove = true;
7793 : : break;
7794 : : }
7795 : : }
7796 : 1288 : else if (TYPE_PTR_P (type)
7797 : : /* Can't multiply the step yet if *this
7798 : : is still incomplete type. */
7799 : 1288 : && (ort != C_ORT_OMP_DECLARE_SIMD
7800 : 45 : || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
7801 : 45 : || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
7802 : 30 : || DECL_NAME (OMP_CLAUSE_DECL (c))
7803 : 30 : != this_identifier
7804 : 30 : || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
7805 : : {
7806 : 37 : tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
7807 : 37 : t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
7808 : : d, t);
7809 : 37 : t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
7810 : : MINUS_EXPR, sizetype,
7811 : : fold_convert (sizetype, t),
7812 : : fold_convert (sizetype, d));
7813 : 37 : if (t == error_mark_node)
7814 : : {
7815 : : remove = true;
7816 : : break;
7817 : : }
7818 : : }
7819 : : else
7820 : 1251 : t = fold_convert (type, t);
7821 : : }
7822 : 1529 : OMP_CLAUSE_LINEAR_STEP (c) = t;
7823 : : }
7824 : 1529 : goto check_dup_generic;
7825 : 14799 : check_dup_generic:
7826 : 14799 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
7827 : 14799 : if (t)
7828 : : {
7829 : 101 : if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
7830 : 101 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
7831 : : }
7832 : : else
7833 : 14698 : t = OMP_CLAUSE_DECL (c);
7834 : 17335 : check_dup_generic_t:
7835 : 17335 : if (t == current_class_ptr
7836 : 17335 : && ((ort != C_ORT_OMP_DECLARE_SIMD && !openacc)
7837 : 102 : || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
7838 : 72 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
7839 : : {
7840 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
7841 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
7842 : : " clauses");
7843 : 24 : remove = true;
7844 : 24 : break;
7845 : : }
7846 : 17311 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
7847 : 586 : && (!field_ok || TREE_CODE (t) != FIELD_DECL))
7848 : : {
7849 : 59 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
7850 : : break;
7851 : 39 : if (DECL_P (t))
7852 : 30 : error_at (OMP_CLAUSE_LOCATION (c),
7853 : : "%qD is not a variable in clause %qs", t,
7854 : 15 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
7855 : : else
7856 : 48 : error_at (OMP_CLAUSE_LOCATION (c),
7857 : : "%qE is not a variable in clause %qs", t,
7858 : 24 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
7859 : : remove = true;
7860 : : }
7861 : 17252 : else if ((openacc
7862 : 2708 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
7863 : 14782 : || (ort == C_ORT_OMP
7864 : 12511 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
7865 : 12480 : || (OMP_CLAUSE_CODE (c)
7866 : : == OMP_CLAUSE_USE_DEVICE_ADDR)))
7867 : 31927 : || (ort == C_ORT_OMP_TARGET
7868 : 894 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
7869 : : {
7870 : 2855 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
7871 : 2855 : && (bitmap_bit_p (&generic_head, DECL_UID (t))
7872 : 275 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
7873 : : {
7874 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7875 : : "%qD appears more than once in data-sharing "
7876 : : "clauses", t);
7877 : 6 : remove = true;
7878 : 6 : break;
7879 : : }
7880 : 2849 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
7881 : 272 : target_in_reduction_seen = true;
7882 : 2849 : if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
7883 : : {
7884 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
7885 : : openacc
7886 : : ? "%qD appears more than once in reduction clauses"
7887 : : : "%qD appears more than once in data clauses",
7888 : : t);
7889 : 6 : remove = true;
7890 : : }
7891 : : else
7892 : 2843 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
7893 : : }
7894 : 14397 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
7895 : 14325 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
7896 : 14322 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
7897 : 28719 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
7898 : : {
7899 : 75 : error_at (OMP_CLAUSE_LOCATION (c),
7900 : : "%qD appears more than once in data clauses", t);
7901 : 75 : remove = true;
7902 : : }
7903 : 14322 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
7904 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
7905 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
7906 : 3064 : && bitmap_bit_p (&map_head, DECL_UID (t)))
7907 : : {
7908 : 9 : if (openacc)
7909 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
7910 : : "%qD appears more than once in data clauses", t);
7911 : : else
7912 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
7913 : : "%qD appears both in data and map clauses", t);
7914 : : remove = true;
7915 : : }
7916 : : else
7917 : 14313 : bitmap_set_bit (&generic_head, DECL_UID (t));
7918 : 17285 : if (!field_ok)
7919 : : break;
7920 : 12895 : handle_field_decl:
7921 : 21514 : if (!remove
7922 : 21320 : && TREE_CODE (t) == FIELD_DECL
7923 : 16682 : && t == OMP_CLAUSE_DECL (c))
7924 : : {
7925 : 786 : OMP_CLAUSE_DECL (c)
7926 : 786 : = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
7927 : : == OMP_CLAUSE_SHARED));
7928 : 786 : if (OMP_CLAUSE_DECL (c) == error_mark_node)
7929 : 96215 : remove = true;
7930 : : }
7931 : : break;
7932 : :
7933 : 3430 : case OMP_CLAUSE_FIRSTPRIVATE:
7934 : 3430 : if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
7935 : : {
7936 : 434 : move_implicit:
7937 : 434 : implicit_moved = true;
7938 : : /* Move firstprivate and map clauses with
7939 : : OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
7940 : : clauses chain. */
7941 : 434 : tree cl1 = NULL_TREE, cl2 = NULL_TREE;
7942 : 434 : tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
7943 : 2778 : while (*pc1)
7944 : 2344 : if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
7945 : 2344 : && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
7946 : : {
7947 : 275 : *pc3 = *pc1;
7948 : 275 : pc3 = &OMP_CLAUSE_CHAIN (*pc3);
7949 : 275 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
7950 : : }
7951 : 2069 : else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
7952 : 2069 : && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
7953 : : {
7954 : 390 : *pc2 = *pc1;
7955 : 390 : pc2 = &OMP_CLAUSE_CHAIN (*pc2);
7956 : 390 : *pc1 = OMP_CLAUSE_CHAIN (*pc1);
7957 : : }
7958 : : else
7959 : 1679 : pc1 = &OMP_CLAUSE_CHAIN (*pc1);
7960 : 434 : *pc3 = NULL;
7961 : 434 : *pc2 = cl2;
7962 : 434 : *pc1 = cl1;
7963 : 434 : continue;
7964 : 434 : }
7965 : 3173 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
7966 : 3173 : if (t)
7967 : 69 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
7968 : : else
7969 : 3104 : t = OMP_CLAUSE_DECL (c);
7970 : 3173 : if (!openacc && t == current_class_ptr)
7971 : : {
7972 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7973 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
7974 : : " clauses");
7975 : 6 : remove = true;
7976 : 6 : break;
7977 : : }
7978 : 3167 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
7979 : 327 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
7980 : 327 : || TREE_CODE (t) != FIELD_DECL))
7981 : : {
7982 : 41 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
7983 : : break;
7984 : 18 : if (DECL_P (t))
7985 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
7986 : : "%qD is not a variable in clause %<firstprivate%>",
7987 : : t);
7988 : : else
7989 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
7990 : : "%qE is not a variable in clause %<firstprivate%>",
7991 : : t);
7992 : 18 : remove = true;
7993 : : }
7994 : 3126 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
7995 : 275 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
7996 : 3380 : && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
7997 : : remove = true;
7998 : 3126 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
7999 : 3117 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8000 : 6240 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
8001 : : {
8002 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
8003 : : "%qD appears more than once in data clauses", t);
8004 : 15 : remove = true;
8005 : : }
8006 : 3111 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
8007 : 3111 : || bitmap_bit_p (&map_field_head, DECL_UID (t)))
8008 : : {
8009 : 21 : if (openacc)
8010 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8011 : : "%qD appears more than once in data clauses", t);
8012 : 21 : else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
8013 : 21 : && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
8014 : : /* Silently drop the clause. */;
8015 : : else
8016 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
8017 : : "%qD appears both in data and map clauses", t);
8018 : 21 : remove = true;
8019 : : }
8020 : : else
8021 : 3090 : bitmap_set_bit (&firstprivate_head, DECL_UID (t));
8022 : 3144 : goto handle_field_decl;
8023 : :
8024 : 2784 : case OMP_CLAUSE_LASTPRIVATE:
8025 : 2784 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8026 : 2784 : if (t)
8027 : 35 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8028 : : else
8029 : 2749 : t = OMP_CLAUSE_DECL (c);
8030 : 2784 : if (!openacc && t == current_class_ptr)
8031 : : {
8032 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8033 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
8034 : : " clauses");
8035 : 6 : remove = true;
8036 : 6 : break;
8037 : : }
8038 : 2778 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
8039 : 256 : && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
8040 : 256 : || TREE_CODE (t) != FIELD_DECL))
8041 : : {
8042 : 35 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8043 : : break;
8044 : 9 : if (DECL_P (t))
8045 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8046 : : "%qD is not a variable in clause %<lastprivate%>",
8047 : : t);
8048 : : else
8049 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8050 : : "%qE is not a variable in clause %<lastprivate%>",
8051 : : t);
8052 : 9 : remove = true;
8053 : : }
8054 : 2743 : else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8055 : 2743 : || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8056 : : {
8057 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8058 : : "%qD appears more than once in data clauses", t);
8059 : 12 : remove = true;
8060 : : }
8061 : : else
8062 : 2731 : bitmap_set_bit (&lastprivate_head, DECL_UID (t));
8063 : 2752 : goto handle_field_decl;
8064 : :
8065 : 2194 : case OMP_CLAUSE_IF:
8066 : 2194 : case OMP_CLAUSE_SELF:
8067 : 2194 : t = OMP_CLAUSE_OPERAND (c, 0);
8068 : 2194 : t = maybe_convert_cond (t);
8069 : 2194 : if (t == error_mark_node)
8070 : : remove = true;
8071 : 2179 : else if (!processing_template_decl)
8072 : 2118 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8073 : 2194 : OMP_CLAUSE_OPERAND (c, 0) = t;
8074 : 2194 : break;
8075 : :
8076 : 286 : case OMP_CLAUSE_FINAL:
8077 : 286 : t = OMP_CLAUSE_FINAL_EXPR (c);
8078 : 286 : t = maybe_convert_cond (t);
8079 : 286 : if (t == error_mark_node)
8080 : : remove = true;
8081 : 286 : else if (!processing_template_decl)
8082 : 280 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8083 : 286 : OMP_CLAUSE_FINAL_EXPR (c) = t;
8084 : 286 : break;
8085 : :
8086 : 89 : case OMP_CLAUSE_NOCONTEXT:
8087 : 89 : t = OMP_CLAUSE_NOCONTEXT_EXPR (c);
8088 : 89 : t = maybe_convert_cond (t);
8089 : 89 : if (t == error_mark_node)
8090 : : remove = true;
8091 : 86 : else if (!processing_template_decl)
8092 : 80 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8093 : 89 : OMP_CLAUSE_NOCONTEXT_EXPR (c) = t;
8094 : 89 : break;
8095 : :
8096 : 77 : case OMP_CLAUSE_NOVARIANTS:
8097 : 77 : t = OMP_CLAUSE_NOVARIANTS_EXPR (c);
8098 : 77 : t = maybe_convert_cond (t);
8099 : 77 : if (t == error_mark_node)
8100 : : remove = true;
8101 : 74 : else if (!processing_template_decl)
8102 : 68 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8103 : 77 : OMP_CLAUSE_NOVARIANTS_EXPR (c) = t;
8104 : 77 : break;
8105 : :
8106 : 1250 : case OMP_CLAUSE_GANG:
8107 : : /* Operand 1 is the gang static: argument. */
8108 : 1250 : t = OMP_CLAUSE_OPERAND (c, 1);
8109 : 1250 : if (t != NULL_TREE)
8110 : : {
8111 : 129 : if (t == error_mark_node)
8112 : : remove = true;
8113 : 129 : else if (!type_dependent_expression_p (t)
8114 : 129 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8115 : : {
8116 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8117 : : "%<gang%> static expression must be integral");
8118 : 6 : remove = true;
8119 : : }
8120 : : else
8121 : : {
8122 : 123 : t = mark_rvalue_use (t);
8123 : 123 : if (!processing_template_decl)
8124 : : {
8125 : 123 : t = maybe_constant_value (t);
8126 : 123 : if (TREE_CODE (t) == INTEGER_CST
8127 : 109 : && tree_int_cst_sgn (t) != 1
8128 : 176 : && t != integer_minus_one_node)
8129 : : {
8130 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8131 : : "%<gang%> static value must be "
8132 : : "positive");
8133 : 0 : t = integer_one_node;
8134 : : }
8135 : 123 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8136 : : }
8137 : : }
8138 : 129 : OMP_CLAUSE_OPERAND (c, 1) = t;
8139 : : }
8140 : : /* Check operand 0, the num argument. */
8141 : : /* FALLTHRU */
8142 : :
8143 : 3484 : case OMP_CLAUSE_WORKER:
8144 : 3484 : case OMP_CLAUSE_VECTOR:
8145 : 3484 : if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
8146 : : break;
8147 : : /* FALLTHRU */
8148 : :
8149 : 481 : case OMP_CLAUSE_NUM_TASKS:
8150 : 481 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TASKS)
8151 : 133 : num_tasks_seen = true;
8152 : : /* FALLTHRU */
8153 : :
8154 : 3002 : case OMP_CLAUSE_NUM_TEAMS:
8155 : 3002 : case OMP_CLAUSE_NUM_THREADS:
8156 : 3002 : case OMP_CLAUSE_NUM_GANGS:
8157 : 3002 : case OMP_CLAUSE_NUM_WORKERS:
8158 : 3002 : case OMP_CLAUSE_VECTOR_LENGTH:
8159 : 3002 : t = OMP_CLAUSE_OPERAND (c, 0);
8160 : 3002 : if (t == error_mark_node)
8161 : : remove = true;
8162 : 3002 : else if (!type_dependent_expression_p (t)
8163 : 3002 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8164 : : {
8165 : 93 : switch (OMP_CLAUSE_CODE (c))
8166 : : {
8167 : 12 : case OMP_CLAUSE_GANG:
8168 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8169 : 12 : "%<gang%> num expression must be integral"); break;
8170 : 12 : case OMP_CLAUSE_VECTOR:
8171 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8172 : : "%<vector%> length expression must be integral");
8173 : 12 : break;
8174 : 12 : case OMP_CLAUSE_WORKER:
8175 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8176 : : "%<worker%> num expression must be integral");
8177 : 12 : break;
8178 : 57 : default:
8179 : 57 : error_at (OMP_CLAUSE_LOCATION (c),
8180 : : "%qs expression must be integral",
8181 : 57 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8182 : : }
8183 : : remove = true;
8184 : : }
8185 : : else
8186 : : {
8187 : 2909 : t = mark_rvalue_use (t);
8188 : 2909 : if (!processing_template_decl)
8189 : : {
8190 : 2661 : t = maybe_constant_value (t);
8191 : 2661 : if (TREE_CODE (t) == INTEGER_CST
8192 : 2661 : && tree_int_cst_sgn (t) != 1)
8193 : : {
8194 : 85 : switch (OMP_CLAUSE_CODE (c))
8195 : : {
8196 : 3 : case OMP_CLAUSE_GANG:
8197 : 3 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8198 : : "%<gang%> num value must be positive");
8199 : 3 : break;
8200 : 0 : case OMP_CLAUSE_VECTOR:
8201 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8202 : : "%<vector%> length value must be "
8203 : : "positive");
8204 : 0 : break;
8205 : 0 : case OMP_CLAUSE_WORKER:
8206 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), 0,
8207 : : "%<worker%> num value must be "
8208 : : "positive");
8209 : 0 : break;
8210 : 82 : default:
8211 : 82 : warning_at (OMP_CLAUSE_LOCATION (c),
8212 : 46 : (flag_openmp || flag_openmp_simd)
8213 : : ? OPT_Wopenmp : 0,
8214 : : "%qs value must be positive",
8215 : : omp_clause_code_name
8216 : 82 : [OMP_CLAUSE_CODE (c)]);
8217 : : }
8218 : 85 : t = integer_one_node;
8219 : : }
8220 : 2661 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8221 : : }
8222 : 2909 : OMP_CLAUSE_OPERAND (c, 0) = t;
8223 : : }
8224 : 3002 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS
8225 : 764 : && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c)
8226 : 3281 : && !remove)
8227 : : {
8228 : 279 : t = OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c);
8229 : 279 : if (t == error_mark_node)
8230 : : remove = true;
8231 : 279 : else if (!type_dependent_expression_p (t)
8232 : 279 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8233 : : {
8234 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8235 : : "%qs expression must be integral",
8236 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8237 : 0 : remove = true;
8238 : : }
8239 : : else
8240 : : {
8241 : 279 : t = mark_rvalue_use (t);
8242 : 279 : if (!processing_template_decl)
8243 : : {
8244 : 213 : t = maybe_constant_value (t);
8245 : 213 : if (TREE_CODE (t) == INTEGER_CST
8246 : 213 : && tree_int_cst_sgn (t) != 1)
8247 : : {
8248 : 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8249 : : "%qs value must be positive",
8250 : : omp_clause_code_name
8251 : 18 : [OMP_CLAUSE_CODE (c)]);
8252 : 18 : t = NULL_TREE;
8253 : : }
8254 : : else
8255 : 195 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8256 : 213 : tree upper = OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c);
8257 : 213 : if (t
8258 : 195 : && TREE_CODE (t) == INTEGER_CST
8259 : 43 : && TREE_CODE (upper) == INTEGER_CST
8260 : 250 : && tree_int_cst_lt (upper, t))
8261 : : {
8262 : 18 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8263 : : "%<num_teams%> lower bound %qE bigger "
8264 : : "than upper bound %qE", t, upper);
8265 : 18 : t = NULL_TREE;
8266 : : }
8267 : : }
8268 : 279 : OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c) = t;
8269 : : }
8270 : : }
8271 : : break;
8272 : :
8273 : 3856 : case OMP_CLAUSE_SCHEDULE:
8274 : 3856 : t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
8275 : 3856 : if (t == NULL)
8276 : : ;
8277 : 2072 : else if (t == error_mark_node)
8278 : : remove = true;
8279 : 2072 : else if (!type_dependent_expression_p (t)
8280 : 2072 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8281 : : {
8282 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
8283 : : "schedule chunk size expression must be integral");
8284 : 9 : remove = true;
8285 : : }
8286 : : else
8287 : : {
8288 : 2063 : t = mark_rvalue_use (t);
8289 : 2063 : if (!processing_template_decl)
8290 : : {
8291 : 2023 : t = maybe_constant_value (t);
8292 : 2023 : if (TREE_CODE (t) == INTEGER_CST
8293 : 2023 : && tree_int_cst_sgn (t) != 1)
8294 : : {
8295 : 6 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8296 : : "chunk size value must be positive");
8297 : 6 : t = integer_one_node;
8298 : : }
8299 : 2023 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8300 : : }
8301 : 2063 : OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
8302 : : }
8303 : 2072 : if (!remove)
8304 : : schedule_seen = true;
8305 : : break;
8306 : :
8307 : 1268 : case OMP_CLAUSE_SIMDLEN:
8308 : 1268 : case OMP_CLAUSE_SAFELEN:
8309 : 1268 : t = OMP_CLAUSE_OPERAND (c, 0);
8310 : 1268 : if (t == error_mark_node)
8311 : : remove = true;
8312 : 1268 : else if (!type_dependent_expression_p (t)
8313 : 1268 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8314 : : {
8315 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8316 : : "%qs length expression must be integral",
8317 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8318 : 0 : remove = true;
8319 : : }
8320 : : else
8321 : : {
8322 : 1268 : t = mark_rvalue_use (t);
8323 : 1268 : if (!processing_template_decl)
8324 : : {
8325 : 1219 : t = maybe_constant_value (t);
8326 : 1219 : if (TREE_CODE (t) != INTEGER_CST
8327 : 1219 : || tree_int_cst_sgn (t) != 1)
8328 : : {
8329 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8330 : : "%qs length expression must be positive "
8331 : : "constant integer expression",
8332 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8333 : 0 : remove = true;
8334 : : }
8335 : : }
8336 : 1268 : OMP_CLAUSE_OPERAND (c, 0) = t;
8337 : 1268 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
8338 : 470 : safelen = c;
8339 : : }
8340 : : break;
8341 : :
8342 : 378 : case OMP_CLAUSE_ASYNC:
8343 : 378 : t = OMP_CLAUSE_ASYNC_EXPR (c);
8344 : 378 : if (t == error_mark_node)
8345 : : remove = true;
8346 : 363 : else if (!type_dependent_expression_p (t)
8347 : 363 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8348 : : {
8349 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8350 : : "%<async%> expression must be integral");
8351 : 12 : remove = true;
8352 : : }
8353 : : else
8354 : : {
8355 : 351 : t = mark_rvalue_use (t);
8356 : 351 : if (!processing_template_decl)
8357 : 342 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8358 : 351 : OMP_CLAUSE_ASYNC_EXPR (c) = t;
8359 : : }
8360 : : break;
8361 : :
8362 : 196 : case OMP_CLAUSE_WAIT:
8363 : 196 : t = OMP_CLAUSE_WAIT_EXPR (c);
8364 : 196 : if (t == error_mark_node)
8365 : : remove = true;
8366 : 196 : else if (!processing_template_decl)
8367 : 188 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8368 : 196 : OMP_CLAUSE_WAIT_EXPR (c) = t;
8369 : 196 : break;
8370 : :
8371 : 637 : case OMP_CLAUSE_THREAD_LIMIT:
8372 : 637 : t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
8373 : 637 : if (t == error_mark_node)
8374 : : remove = true;
8375 : 637 : else if (!type_dependent_expression_p (t)
8376 : 637 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8377 : : {
8378 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8379 : : "%<thread_limit%> expression must be integral");
8380 : 0 : remove = true;
8381 : : }
8382 : : else
8383 : : {
8384 : 637 : t = mark_rvalue_use (t);
8385 : 637 : if (!processing_template_decl)
8386 : : {
8387 : 583 : t = maybe_constant_value (t);
8388 : 583 : if (TREE_CODE (t) == INTEGER_CST
8389 : 583 : && tree_int_cst_sgn (t) != 1)
8390 : : {
8391 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8392 : : "%<thread_limit%> value must be positive");
8393 : 0 : t = integer_one_node;
8394 : : }
8395 : 583 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8396 : : }
8397 : 637 : OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
8398 : : }
8399 : : break;
8400 : :
8401 : 762 : case OMP_CLAUSE_DEVICE:
8402 : 762 : t = OMP_CLAUSE_DEVICE_ID (c);
8403 : 762 : if (t == error_mark_node)
8404 : : remove = true;
8405 : 762 : else if (!type_dependent_expression_p (t)
8406 : 762 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8407 : : {
8408 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8409 : : "%<device%> id must be integral");
8410 : 6 : remove = true;
8411 : : }
8412 : 756 : else if (OMP_CLAUSE_DEVICE_ANCESTOR (c)
8413 : 66 : && TREE_CODE (t) == INTEGER_CST
8414 : 816 : && !integer_onep (t))
8415 : : {
8416 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8417 : : "the %<device%> clause expression must evaluate to "
8418 : : "%<1%>");
8419 : 3 : remove = true;
8420 : : }
8421 : : else
8422 : : {
8423 : 753 : t = mark_rvalue_use (t);
8424 : 753 : if (!processing_template_decl)
8425 : 742 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8426 : 753 : OMP_CLAUSE_DEVICE_ID (c) = t;
8427 : : }
8428 : : break;
8429 : :
8430 : 1836 : case OMP_CLAUSE_DIST_SCHEDULE:
8431 : 1836 : t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
8432 : 1836 : if (t == NULL)
8433 : : ;
8434 : 1815 : else if (t == error_mark_node)
8435 : : remove = true;
8436 : 1815 : else if (!type_dependent_expression_p (t)
8437 : 1815 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8438 : : {
8439 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8440 : : "%<dist_schedule%> chunk size expression must be "
8441 : : "integral");
8442 : 0 : remove = true;
8443 : : }
8444 : : else
8445 : : {
8446 : 1815 : t = mark_rvalue_use (t);
8447 : 1815 : if (!processing_template_decl)
8448 : 1815 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8449 : 1815 : OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
8450 : : }
8451 : : break;
8452 : :
8453 : 807 : case OMP_CLAUSE_ALIGNED:
8454 : 807 : t = OMP_CLAUSE_DECL (c);
8455 : 807 : if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
8456 : : {
8457 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8458 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
8459 : : " clauses");
8460 : 0 : remove = true;
8461 : 0 : break;
8462 : : }
8463 : 807 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8464 : : {
8465 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8466 : : break;
8467 : 0 : if (DECL_P (t))
8468 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8469 : : "%qD is not a variable in %<aligned%> clause", t);
8470 : : else
8471 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8472 : : "%qE is not a variable in %<aligned%> clause", t);
8473 : : remove = true;
8474 : : }
8475 : 807 : else if (!type_dependent_expression_p (t)
8476 : 789 : && !TYPE_PTR_P (TREE_TYPE (t))
8477 : 111 : && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
8478 : 864 : && (!TYPE_REF_P (TREE_TYPE (t))
8479 : 39 : || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
8480 : 30 : && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
8481 : : != ARRAY_TYPE))))
8482 : : {
8483 : 33 : error_at (OMP_CLAUSE_LOCATION (c),
8484 : : "%qE in %<aligned%> clause is neither a pointer nor "
8485 : : "an array nor a reference to pointer or array", t);
8486 : 33 : remove = true;
8487 : : }
8488 : 774 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8489 : : {
8490 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8491 : : "%qD appears more than once in %<aligned%> clauses",
8492 : : t);
8493 : 0 : remove = true;
8494 : : }
8495 : : else
8496 : 774 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8497 : 807 : t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
8498 : 807 : if (t == error_mark_node)
8499 : : remove = true;
8500 : 807 : else if (t == NULL_TREE)
8501 : : break;
8502 : 744 : else if (!type_dependent_expression_p (t)
8503 : 744 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
8504 : : {
8505 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8506 : : "%<aligned%> clause alignment expression must "
8507 : : "be integral");
8508 : 0 : remove = true;
8509 : : }
8510 : : else
8511 : : {
8512 : 744 : t = mark_rvalue_use (t);
8513 : 744 : if (!processing_template_decl)
8514 : : {
8515 : 690 : t = maybe_constant_value (t);
8516 : 690 : if (TREE_CODE (t) != INTEGER_CST
8517 : 690 : || tree_int_cst_sgn (t) != 1)
8518 : : {
8519 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8520 : : "%<aligned%> clause alignment expression must "
8521 : : "be positive constant integer expression");
8522 : 0 : remove = true;
8523 : : }
8524 : : }
8525 : 744 : OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
8526 : : }
8527 : : break;
8528 : :
8529 : 369 : case OMP_CLAUSE_NONTEMPORAL:
8530 : 369 : t = OMP_CLAUSE_DECL (c);
8531 : 369 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
8532 : : {
8533 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8534 : : break;
8535 : 0 : if (DECL_P (t))
8536 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8537 : : "%qD is not a variable in %<nontemporal%> clause",
8538 : : t);
8539 : : else
8540 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8541 : : "%qE is not a variable in %<nontemporal%> clause",
8542 : : t);
8543 : : remove = true;
8544 : : }
8545 : 369 : else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
8546 : : {
8547 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8548 : : "%qD appears more than once in %<nontemporal%> "
8549 : : "clauses", t);
8550 : 6 : remove = true;
8551 : : }
8552 : : else
8553 : 363 : bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
8554 : : break;
8555 : :
8556 : 2739 : case OMP_CLAUSE_ALLOCATE:
8557 : 2739 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
8558 : 2739 : if (t)
8559 : 14 : omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
8560 : : else
8561 : 2725 : t = OMP_CLAUSE_DECL (c);
8562 : 2739 : if (t == current_class_ptr)
8563 : : {
8564 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8565 : : "%<this%> not allowed in %<allocate%> clause");
8566 : 0 : remove = true;
8567 : 0 : break;
8568 : : }
8569 : 2739 : if (!VAR_P (t)
8570 : 678 : && TREE_CODE (t) != PARM_DECL
8571 : 45 : && TREE_CODE (t) != FIELD_DECL)
8572 : : {
8573 : 3 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8574 : : break;
8575 : 3 : if (DECL_P (t))
8576 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8577 : : "%qD is not a variable in %<allocate%> clause", t);
8578 : : else
8579 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8580 : : "%qE is not a variable in %<allocate%> clause", t);
8581 : : remove = true;
8582 : : }
8583 : 2736 : else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
8584 : : {
8585 : 12 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
8586 : : "%qD appears more than once in %<allocate%> clauses",
8587 : : t);
8588 : 12 : remove = true;
8589 : : }
8590 : : else
8591 : : {
8592 : 2724 : bitmap_set_bit (&aligned_head, DECL_UID (t));
8593 : 2724 : allocate_seen = true;
8594 : : }
8595 : 2739 : tree allocator, align;
8596 : 2739 : align = OMP_CLAUSE_ALLOCATE_ALIGN (c);
8597 : 2739 : if (error_operand_p (align))
8598 : : {
8599 : : remove = true;
8600 : : break;
8601 : : }
8602 : 2739 : if (align)
8603 : : {
8604 : 171 : if (!type_dependent_expression_p (align)
8605 : 171 : && !INTEGRAL_TYPE_P (TREE_TYPE (align)))
8606 : : {
8607 : 4 : error_at (OMP_CLAUSE_LOCATION (c),
8608 : : "%<allocate%> clause %<align%> modifier "
8609 : : "argument needs to be positive constant "
8610 : : "power of two integer expression");
8611 : 4 : remove = true;
8612 : : }
8613 : : else
8614 : : {
8615 : 167 : align = mark_rvalue_use (align);
8616 : 167 : if (!processing_template_decl)
8617 : : {
8618 : 152 : align = maybe_constant_value (align);
8619 : 152 : if (TREE_CODE (align) != INTEGER_CST
8620 : 149 : || !tree_fits_uhwi_p (align)
8621 : 301 : || !integer_pow2p (align))
8622 : : {
8623 : 10 : error_at (OMP_CLAUSE_LOCATION (c),
8624 : : "%<allocate%> clause %<align%> modifier "
8625 : : "argument needs to be positive constant "
8626 : : "power of two integer expression");
8627 : 10 : remove = true;
8628 : : }
8629 : : }
8630 : : }
8631 : 171 : OMP_CLAUSE_ALLOCATE_ALIGN (c) = align;
8632 : : }
8633 : 2739 : allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
8634 : 2739 : if (error_operand_p (allocator))
8635 : : {
8636 : : remove = true;
8637 : : break;
8638 : : }
8639 : 2739 : if (allocator == NULL_TREE)
8640 : 1745 : goto handle_field_decl;
8641 : 994 : tree allocatort;
8642 : 994 : allocatort = TYPE_MAIN_VARIANT (TREE_TYPE (allocator));
8643 : 994 : if (!type_dependent_expression_p (allocator)
8644 : 994 : && (TREE_CODE (allocatort) != ENUMERAL_TYPE
8645 : 975 : || TYPE_NAME (allocatort) == NULL_TREE
8646 : 975 : || TREE_CODE (TYPE_NAME (allocatort)) != TYPE_DECL
8647 : 1950 : || (DECL_NAME (TYPE_NAME (allocatort))
8648 : 975 : != get_identifier ("omp_allocator_handle_t"))
8649 : 975 : || (TYPE_CONTEXT (allocatort)
8650 : 975 : != DECL_CONTEXT (global_namespace))))
8651 : : {
8652 : 16 : error_at (OMP_CLAUSE_LOCATION (c),
8653 : : "%<allocate%> clause allocator expression has "
8654 : : "type %qT rather than %<omp_allocator_handle_t%>",
8655 : 16 : TREE_TYPE (allocator));
8656 : 16 : remove = true;
8657 : 16 : break;
8658 : : }
8659 : : else
8660 : : {
8661 : 978 : allocator = mark_rvalue_use (allocator);
8662 : 978 : if (!processing_template_decl)
8663 : 959 : allocator = maybe_constant_value (allocator);
8664 : 978 : OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) = allocator;
8665 : : }
8666 : 978 : goto handle_field_decl;
8667 : :
8668 : 648 : case OMP_CLAUSE_DOACROSS:
8669 : 648 : t = OMP_CLAUSE_DECL (c);
8670 : 648 : if (t == NULL_TREE)
8671 : : break;
8672 : 295 : if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
8673 : : {
8674 : 295 : if (cp_finish_omp_clause_doacross_sink (c))
8675 : 9 : remove = true;
8676 : : break;
8677 : : }
8678 : 0 : gcc_unreachable ();
8679 : 1793 : case OMP_CLAUSE_DEPEND:
8680 : 1793 : depend_clause = c;
8681 : : /* FALLTHRU */
8682 : 2333 : case OMP_CLAUSE_AFFINITY:
8683 : 2333 : t = OMP_CLAUSE_DECL (c);
8684 : 2333 : if (TREE_CODE (t) == TREE_LIST
8685 : 621 : && TREE_PURPOSE (t)
8686 : 2954 : && TREE_CODE (TREE_PURPOSE (t)) == TREE_VEC)
8687 : : {
8688 : 621 : if (TREE_PURPOSE (t) != last_iterators)
8689 : 523 : last_iterators_remove
8690 : 523 : = cp_omp_finish_iterators (TREE_PURPOSE (t));
8691 : 621 : last_iterators = TREE_PURPOSE (t);
8692 : 621 : t = TREE_VALUE (t);
8693 : 621 : if (last_iterators_remove)
8694 : 144 : t = error_mark_node;
8695 : : }
8696 : : else
8697 : : last_iterators = NULL_TREE;
8698 : :
8699 : 2333 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
8700 : : {
8701 : 1299 : if (handle_omp_array_sections (c, ort))
8702 : : remove = true;
8703 : 972 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
8704 : 972 : && (OMP_CLAUSE_DEPEND_KIND (c)
8705 : : == OMP_CLAUSE_DEPEND_DEPOBJ))
8706 : : {
8707 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8708 : : "%<depend%> clause with %<depobj%> dependence "
8709 : : "type on array section");
8710 : 6 : remove = true;
8711 : : }
8712 : : break;
8713 : : }
8714 : 1034 : if (t == error_mark_node)
8715 : : remove = true;
8716 : 872 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
8717 : 872 : && t == ridpointers[RID_OMP_ALL_MEMORY])
8718 : : {
8719 : 33 : if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
8720 : 33 : && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
8721 : : {
8722 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
8723 : : "%<omp_all_memory%> used with %<depend%> kind "
8724 : : "other than %<out%> or %<inout%>");
8725 : 9 : remove = true;
8726 : : }
8727 : 33 : if (processing_template_decl)
8728 : : break;
8729 : : }
8730 : 839 : else if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
8731 : : break;
8732 : 647 : else if (!lvalue_p (t))
8733 : : {
8734 : 21 : if (DECL_P (t))
8735 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
8736 : : "%qD is not lvalue expression nor array section "
8737 : : "in %qs clause", t,
8738 : 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8739 : : else
8740 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
8741 : : "%qE is not lvalue expression nor array section "
8742 : : "in %qs clause", t,
8743 : 9 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8744 : : remove = true;
8745 : : }
8746 : 626 : else if (TREE_CODE (t) == COMPONENT_REF
8747 : 36 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
8748 : 662 : && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
8749 : : {
8750 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8751 : : "bit-field %qE in %qs clause", t,
8752 : 6 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8753 : 6 : remove = true;
8754 : : }
8755 : 620 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
8756 : 620 : && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
8757 : : {
8758 : 124 : if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
8759 : 8 : ? TREE_TYPE (TREE_TYPE (t))
8760 : 54 : : TREE_TYPE (t)))
8761 : : {
8762 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
8763 : : "%qE does not have %<omp_depend_t%> type in "
8764 : : "%<depend%> clause with %<depobj%> dependence "
8765 : : "type", t);
8766 : 12 : remove = true;
8767 : : }
8768 : : }
8769 : 558 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
8770 : 996 : && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t))
8771 : 4 : ? TREE_TYPE (TREE_TYPE (t))
8772 : 434 : : TREE_TYPE (t)))
8773 : : {
8774 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
8775 : : "%qE should not have %<omp_depend_t%> type in "
8776 : : "%<depend%> clause with dependence type other than "
8777 : : "%<depobj%>", t);
8778 : 15 : remove = true;
8779 : : }
8780 : 66 : if (!remove)
8781 : : {
8782 : 617 : if (t == ridpointers[RID_OMP_ALL_MEMORY])
8783 : 24 : t = null_pointer_node;
8784 : : else
8785 : : {
8786 : 593 : tree addr = cp_build_addr_expr (t, tf_warning_or_error);
8787 : 593 : if (addr == error_mark_node)
8788 : : {
8789 : : remove = true;
8790 : : break;
8791 : : }
8792 : 593 : t = cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c),
8793 : : addr, RO_UNARY_STAR,
8794 : : tf_warning_or_error);
8795 : 593 : if (t == error_mark_node)
8796 : : {
8797 : : remove = true;
8798 : : break;
8799 : : }
8800 : : }
8801 : 617 : if (TREE_CODE (OMP_CLAUSE_DECL (c)) == TREE_LIST
8802 : 135 : && TREE_PURPOSE (OMP_CLAUSE_DECL (c))
8803 : 752 : && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c)))
8804 : : == TREE_VEC))
8805 : 135 : TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
8806 : : else
8807 : 482 : OMP_CLAUSE_DECL (c) = t;
8808 : : }
8809 : : break;
8810 : 69 : case OMP_CLAUSE_DETACH:
8811 : 69 : t = OMP_CLAUSE_DECL (c);
8812 : 69 : if (detach_seen)
8813 : : {
8814 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
8815 : : "too many %qs clauses on a task construct",
8816 : : "detach");
8817 : 3 : remove = true;
8818 : 3 : break;
8819 : : }
8820 : 66 : else if (error_operand_p (t))
8821 : : {
8822 : : remove = true;
8823 : : break;
8824 : : }
8825 : : else
8826 : : {
8827 : 63 : tree type = TYPE_MAIN_VARIANT (TREE_TYPE (t));
8828 : 63 : if (!type_dependent_expression_p (t)
8829 : 63 : && (!INTEGRAL_TYPE_P (type)
8830 : : || TREE_CODE (type) != ENUMERAL_TYPE
8831 : 51 : || TYPE_NAME (type) == NULL_TREE
8832 : 102 : || (DECL_NAME (TYPE_NAME (type))
8833 : 51 : != get_identifier ("omp_event_handle_t"))))
8834 : : {
8835 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8836 : : "%<detach%> clause event handle "
8837 : : "has type %qT rather than "
8838 : : "%<omp_event_handle_t%>",
8839 : : type);
8840 : 6 : remove = true;
8841 : : }
8842 : 63 : detach_seen = c;
8843 : 63 : cxx_mark_addressable (t);
8844 : : }
8845 : 63 : break;
8846 : :
8847 : 15004 : case OMP_CLAUSE_MAP:
8848 : 15004 : if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
8849 : 177 : goto move_implicit;
8850 : : /* FALLTHRU */
8851 : 18816 : case OMP_CLAUSE_TO:
8852 : 18816 : case OMP_CLAUSE_FROM:
8853 : 18816 : case OMP_CLAUSE__CACHE_:
8854 : 18816 : {
8855 : 18816 : using namespace omp_addr_tokenizer;
8856 : 18816 : auto_vec<omp_addr_token *, 10> addr_tokens;
8857 : :
8858 : 18816 : t = OMP_CLAUSE_DECL (c);
8859 : 18816 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
8860 : : {
8861 : 5647 : grp_start_p = pc;
8862 : 5647 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
8863 : :
8864 : 5647 : if (handle_omp_array_sections (c, ort))
8865 : : remove = true;
8866 : : else
8867 : : {
8868 : 4843 : t = OMP_CLAUSE_DECL (c);
8869 : 4843 : if (TREE_CODE (t) != OMP_ARRAY_SECTION
8870 : 4036 : && !type_dependent_expression_p (t)
8871 : 8879 : && !omp_mappable_type (TREE_TYPE (t)))
8872 : : {
8873 : 3 : auto_diagnostic_group d;
8874 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
8875 : : "array section does not have mappable type "
8876 : : "in %qs clause",
8877 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
8878 : 3 : if (TREE_TYPE (t) != error_mark_node
8879 : 3 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
8880 : 3 : cxx_incomplete_type_inform (TREE_TYPE (t));
8881 : 3 : remove = true;
8882 : 3 : }
8883 : 6626 : while (TREE_CODE (t) == ARRAY_REF)
8884 : 1783 : t = TREE_OPERAND (t, 0);
8885 : :
8886 : 4843 : if (type_dependent_expression_p (t))
8887 : : break;
8888 : :
8889 : 4423 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
8890 : :
8891 : 4423 : if (!ai.map_supported_p ()
8892 : 4423 : || !omp_parse_expr (addr_tokens, t))
8893 : : {
8894 : 18 : sorry_at (OMP_CLAUSE_LOCATION (c),
8895 : : "unsupported map expression %qE",
8896 : 9 : OMP_CLAUSE_DECL (c));
8897 : 9 : remove = true;
8898 : 9 : break;
8899 : : }
8900 : :
8901 : : /* This check is to determine if this will be the only map
8902 : : node created for this clause. Otherwise, we'll check
8903 : : the following FIRSTPRIVATE_POINTER,
8904 : : FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
8905 : : iteration(s) of the loop. */
8906 : 8781 : if (addr_tokens.length () >= 4
8907 : 999 : && addr_tokens[0]->type == STRUCTURE_BASE
8908 : 999 : && addr_tokens[0]->u.structure_base_kind == BASE_DECL
8909 : 999 : && addr_tokens[1]->type == ACCESS_METHOD
8910 : 999 : && addr_tokens[2]->type == COMPONENT_SELECTOR
8911 : 919 : && addr_tokens[3]->type == ACCESS_METHOD
8912 : 5081 : && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
8913 : 509 : || (addr_tokens[3]->u.access_kind
8914 : : == ACCESS_INDEXED_ARRAY)))
8915 : : {
8916 : 160 : tree rt = addr_tokens[1]->expr;
8917 : :
8918 : 160 : gcc_assert (DECL_P (rt));
8919 : :
8920 : 160 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8921 : 149 : && OMP_CLAUSE_MAP_IMPLICIT (c)
8922 : 160 : && (bitmap_bit_p (&map_head, DECL_UID (rt))
8923 : 0 : || bitmap_bit_p (&map_field_head, DECL_UID (rt))
8924 : 0 : || bitmap_bit_p (&map_firstprivate_head,
8925 : 0 : DECL_UID (rt))))
8926 : : {
8927 : : remove = true;
8928 : : break;
8929 : : }
8930 : 160 : if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
8931 : : break;
8932 : 113 : if (bitmap_bit_p (&map_head, DECL_UID (rt)))
8933 : : {
8934 : 0 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
8935 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8936 : : "%qD appears more than once in motion"
8937 : : " clauses", rt);
8938 : 0 : else if (openacc)
8939 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8940 : : "%qD appears more than once in data"
8941 : : " clauses", rt);
8942 : : else
8943 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
8944 : : "%qD appears more than once in map"
8945 : : " clauses", rt);
8946 : : remove = true;
8947 : : }
8948 : : else
8949 : : {
8950 : 113 : bitmap_set_bit (&map_head, DECL_UID (rt));
8951 : 113 : bitmap_set_bit (&map_field_head, DECL_UID (rt));
8952 : : }
8953 : : }
8954 : 4423 : }
8955 : 5171 : if (cp_oacc_check_attachments (c))
8956 : 12 : remove = true;
8957 : 5171 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8958 : 4230 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
8959 : 4185 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
8960 : 5250 : && !OMP_CLAUSE_SIZE (c))
8961 : : /* In this case, we have a single array element which is a
8962 : : pointer, and we already set OMP_CLAUSE_SIZE in
8963 : : handle_omp_array_sections above. For attach/detach
8964 : : clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
8965 : : to zero here. */
8966 : 60 : OMP_CLAUSE_SIZE (c) = size_zero_node;
8967 : : break;
8968 : : }
8969 : 13169 : else if (type_dependent_expression_p (t))
8970 : : break;
8971 : 12411 : else if (!omp_parse_expr (addr_tokens, t))
8972 : : {
8973 : 0 : sorry_at (OMP_CLAUSE_LOCATION (c),
8974 : : "unsupported map expression %qE",
8975 : 0 : OMP_CLAUSE_DECL (c));
8976 : 0 : remove = true;
8977 : 0 : break;
8978 : : }
8979 : 12411 : if (t == error_mark_node)
8980 : : {
8981 : : remove = true;
8982 : : break;
8983 : : }
8984 : : /* OpenACC attach / detach clauses must be pointers. */
8985 : 12342 : if (cp_oacc_check_attachments (c))
8986 : : {
8987 : : remove = true;
8988 : : break;
8989 : : }
8990 : 12318 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
8991 : 9361 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
8992 : 9308 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
8993 : 12400 : && !OMP_CLAUSE_SIZE (c))
8994 : : /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
8995 : : bias) to zero here, so it is not set erroneously to the
8996 : : pointer size later on in gimplify.cc. */
8997 : 74 : OMP_CLAUSE_SIZE (c) = size_zero_node;
8998 : :
8999 : 12318 : cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
9000 : :
9001 : 12318 : if (!ai.check_clause (c))
9002 : : {
9003 : : remove = true;
9004 : : break;
9005 : : }
9006 : :
9007 : 12297 : if (!ai.map_supported_p ())
9008 : : {
9009 : 76 : sorry_at (OMP_CLAUSE_LOCATION (c),
9010 : : "unsupported map expression %qE",
9011 : 38 : OMP_CLAUSE_DECL (c));
9012 : 38 : remove = true;
9013 : 38 : break;
9014 : : }
9015 : :
9016 : 24518 : gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
9017 : : || addr_tokens[0]->type == STRUCTURE_BASE)
9018 : : && addr_tokens[1]->type == ACCESS_METHOD);
9019 : :
9020 : 12259 : t = addr_tokens[1]->expr;
9021 : :
9022 : : /* This is used to prevent cxx_mark_addressable from being called
9023 : : on 'this' for expressions like 'this->a', i.e. typical member
9024 : : accesses. */
9025 : 12259 : indir_component_ref_p
9026 : 24518 : = (addr_tokens[0]->type == STRUCTURE_BASE
9027 : 12259 : && addr_tokens[1]->u.access_kind != ACCESS_DIRECT);
9028 : :
9029 : 12259 : if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
9030 : 1 : goto skip_decl_checks;
9031 : :
9032 : : /* For OpenMP, we can access a struct "t" and "t.d" on the same
9033 : : mapping. OpenACC allows multiple fields of the same structure
9034 : : to be written. */
9035 : 12258 : if (addr_tokens[0]->type == STRUCTURE_BASE
9036 : 12258 : && (bitmap_bit_p (&map_field_head, DECL_UID (t))
9037 : 1148 : || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
9038 : 1066 : goto skip_decl_checks;
9039 : :
9040 : 11192 : if (!processing_template_decl && TREE_CODE (t) == FIELD_DECL)
9041 : : {
9042 : 0 : OMP_CLAUSE_DECL (c)
9043 : 0 : = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
9044 : 0 : break;
9045 : : }
9046 : 11192 : if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9047 : : {
9048 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9049 : : break;
9050 : 0 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9051 : 0 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9052 : 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER
9053 : 0 : || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH_DETACH
9054 : 0 : || (!openacc && EXPR_P (t))))
9055 : : break;
9056 : 0 : if (DECL_P (t))
9057 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9058 : : "%qD is not a variable in %qs clause", t,
9059 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9060 : : else
9061 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9062 : : "%qE is not a variable in %qs clause", t,
9063 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9064 : : remove = true;
9065 : : }
9066 : 11192 : else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
9067 : : {
9068 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9069 : : "%qD is threadprivate variable in %qs clause", t,
9070 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9071 : 0 : remove = true;
9072 : : }
9073 : 11192 : else if (!processing_template_decl
9074 : 11049 : && !TYPE_REF_P (TREE_TYPE (t))
9075 : 10402 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9076 : 7495 : || (OMP_CLAUSE_MAP_KIND (c)
9077 : : != GOMP_MAP_FIRSTPRIVATE_POINTER))
9078 : 8540 : && !indir_component_ref_p
9079 : 8182 : && (t != current_class_ptr
9080 : 18 : || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9081 : 6 : || OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH)
9082 : 19374 : && !cxx_mark_addressable (t))
9083 : : remove = true;
9084 : 11192 : else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9085 : 8267 : && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
9086 : 8267 : || (OMP_CLAUSE_MAP_KIND (c)
9087 : : == GOMP_MAP_FIRSTPRIVATE_POINTER)
9088 : 6405 : || (OMP_CLAUSE_MAP_KIND (c)
9089 : : == GOMP_MAP_ATTACH_DETACH)))
9090 : 8717 : && t == OMP_CLAUSE_DECL (c)
9091 : 8095 : && !type_dependent_expression_p (t)
9092 : 27382 : && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
9093 : 250 : ? TREE_TYPE (TREE_TYPE (t))
9094 : 7845 : : TREE_TYPE (t)))
9095 : : {
9096 : 42 : auto_diagnostic_group d;
9097 : 84 : error_at (OMP_CLAUSE_LOCATION (c),
9098 : : "%qD does not have a mappable type in %qs clause", t,
9099 : 42 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9100 : 42 : if (TREE_TYPE (t) != error_mark_node
9101 : 42 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9102 : 39 : cxx_incomplete_type_inform (TREE_TYPE (t));
9103 : 42 : remove = true;
9104 : 42 : }
9105 : 11150 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9106 : 8231 : && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
9107 : 87 : && !type_dependent_expression_p (t)
9108 : 11237 : && !INDIRECT_TYPE_P (TREE_TYPE (t)))
9109 : : {
9110 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9111 : : "%qD is not a pointer variable", t);
9112 : 6 : remove = true;
9113 : : }
9114 : 11144 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9115 : 8225 : && OMP_CLAUSE_MAP_IMPLICIT (c)
9116 : 11534 : && (bitmap_bit_p (&map_head, DECL_UID (t))
9117 : 354 : || bitmap_bit_p (&map_field_head, DECL_UID (t))
9118 : 354 : || bitmap_bit_p (&map_firstprivate_head,
9119 : 354 : DECL_UID (t))))
9120 : : remove = true;
9121 : 11105 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9122 : 11105 : && (OMP_CLAUSE_MAP_KIND (c)
9123 : : == GOMP_MAP_FIRSTPRIVATE_POINTER))
9124 : : {
9125 : 1856 : if (bitmap_bit_p (&generic_head, DECL_UID (t))
9126 : 1856 : || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9127 : 3709 : || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
9128 : : {
9129 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
9130 : : "%qD appears more than once in data clauses", t);
9131 : 15 : remove = true;
9132 : : }
9133 : 1841 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9134 : 12 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9135 : 1849 : && openacc)
9136 : : {
9137 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9138 : : "%qD appears more than once in data clauses", t);
9139 : 3 : remove = true;
9140 : : }
9141 : : else
9142 : 1838 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9143 : : }
9144 : 9249 : else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
9145 : 9249 : && (OMP_CLAUSE_MAP_KIND (c)
9146 : : == GOMP_MAP_FIRSTPRIVATE_REFERENCE))
9147 : 91 : bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
9148 : 9158 : else if (bitmap_bit_p (&map_head, DECL_UID (t))
9149 : 168 : && !bitmap_bit_p (&map_field_head, DECL_UID (t))
9150 : 28 : && ort != C_ORT_OMP
9151 : 9186 : && ort != C_ORT_OMP_EXIT_DATA)
9152 : : {
9153 : 18 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
9154 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9155 : : "%qD appears more than once in motion clauses", t);
9156 : 18 : else if (openacc)
9157 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9158 : : "%qD appears more than once in data clauses", t);
9159 : : else
9160 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9161 : : "%qD appears more than once in map clauses", t);
9162 : : remove = true;
9163 : : }
9164 : 9140 : else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
9165 : : {
9166 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9167 : : "%qD appears more than once in data clauses", t);
9168 : 0 : remove = true;
9169 : : }
9170 : 9140 : else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
9171 : 9140 : || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
9172 : : {
9173 : 27 : if (openacc)
9174 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9175 : : "%qD appears more than once in data clauses", t);
9176 : : else
9177 : 27 : error_at (OMP_CLAUSE_LOCATION (c),
9178 : : "%qD appears both in data and map clauses", t);
9179 : : remove = true;
9180 : : }
9181 : 9113 : else if (!omp_access_chain_p (addr_tokens, 1))
9182 : : {
9183 : 9033 : bitmap_set_bit (&map_head, DECL_UID (t));
9184 : :
9185 : 9033 : tree decl = OMP_CLAUSE_DECL (c);
9186 : 9033 : if (t != decl
9187 : 9033 : && (TREE_CODE (decl) == COMPONENT_REF
9188 : 162 : || (INDIRECT_REF_P (decl)
9189 : 162 : && (TREE_CODE (TREE_OPERAND (decl, 0))
9190 : : == COMPONENT_REF)
9191 : 150 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl,
9192 : : 0))))))
9193 : 1050 : bitmap_set_bit (&map_field_head, DECL_UID (t));
9194 : : }
9195 : :
9196 : 4112 : skip_decl_checks:
9197 : : /* If we call ai.expand_map_clause in handle_omp_array_sections,
9198 : : the containing loop (here) iterates through the new nodes
9199 : : created by that expansion. Avoid expanding those again (just
9200 : : by checking the node type). */
9201 : 4112 : if (!remove
9202 : 12109 : && !processing_template_decl
9203 : 11969 : && ort != C_ORT_DECLARE_SIMD
9204 : 11969 : && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
9205 : 9030 : || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
9206 : 7192 : && (OMP_CLAUSE_MAP_KIND (c)
9207 : : != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
9208 : 7101 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
9209 : 7101 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
9210 : 6163 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
9211 : 6110 : && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
9212 : : {
9213 : 9020 : grp_start_p = pc;
9214 : 9020 : grp_sentinel = OMP_CLAUSE_CHAIN (c);
9215 : 9020 : tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
9216 : : addr_tokens, ort);
9217 : 9020 : if (nc != error_mark_node)
9218 : 9020 : c = nc;
9219 : : }
9220 : 18875 : }
9221 : 12259 : break;
9222 : :
9223 : 577 : case OMP_CLAUSE_ENTER:
9224 : 577 : case OMP_CLAUSE_LINK:
9225 : 577 : t = OMP_CLAUSE_DECL (c);
9226 : 577 : const char *cname;
9227 : 577 : cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
9228 : 577 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
9229 : 577 : && OMP_CLAUSE_ENTER_TO (c))
9230 : : cname = "to";
9231 : 577 : if (TREE_CODE (t) == FUNCTION_DECL
9232 : 577 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9233 : : ;
9234 : 364 : else if (!VAR_P (t))
9235 : : {
9236 : 12 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
9237 : : {
9238 : 9 : if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
9239 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9240 : : "template %qE in clause %qs", t, cname);
9241 : 3 : else if (really_overloaded_fn (t))
9242 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9243 : : "overloaded function name %qE in clause %qs", t,
9244 : : cname);
9245 : : else
9246 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9247 : : "%qE is neither a variable nor a function name "
9248 : : "in clause %qs", t, cname);
9249 : : }
9250 : : else
9251 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9252 : : "%qE is not a variable in clause %qs", t, cname);
9253 : : remove = true;
9254 : : }
9255 : 352 : else if (DECL_THREAD_LOCAL_P (t))
9256 : : {
9257 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9258 : : "%qD is threadprivate variable in %qs clause", t,
9259 : : cname);
9260 : 6 : remove = true;
9261 : : }
9262 : 346 : else if (!omp_mappable_type (TREE_TYPE (t)))
9263 : : {
9264 : 18 : auto_diagnostic_group d;
9265 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
9266 : : "%qD does not have a mappable type in %qs clause", t,
9267 : : cname);
9268 : 18 : if (TREE_TYPE (t) != error_mark_node
9269 : 18 : && !COMPLETE_TYPE_P (TREE_TYPE (t)))
9270 : 18 : cxx_incomplete_type_inform (TREE_TYPE (t));
9271 : 18 : remove = true;
9272 : 18 : }
9273 : 24 : if (remove)
9274 : : break;
9275 : 541 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9276 : : {
9277 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
9278 : : "%qE appears more than once on the same "
9279 : : "%<declare target%> directive", t);
9280 : 24 : remove = true;
9281 : : }
9282 : : else
9283 : 517 : bitmap_set_bit (&generic_head, DECL_UID (t));
9284 : : break;
9285 : :
9286 : 457 : case OMP_CLAUSE_UNIFORM:
9287 : 457 : t = OMP_CLAUSE_DECL (c);
9288 : 457 : if (TREE_CODE (t) != PARM_DECL)
9289 : : {
9290 : 0 : if (processing_template_decl)
9291 : : break;
9292 : 0 : if (DECL_P (t))
9293 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9294 : : "%qD is not an argument in %<uniform%> clause", t);
9295 : : else
9296 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9297 : : "%qE is not an argument in %<uniform%> clause", t);
9298 : : remove = true;
9299 : : break;
9300 : : }
9301 : : /* map_head bitmap is used as uniform_head if declare_simd. */
9302 : 457 : bitmap_set_bit (&map_head, DECL_UID (t));
9303 : 457 : goto check_dup_generic;
9304 : :
9305 : 165 : case OMP_CLAUSE_GRAINSIZE:
9306 : 165 : t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
9307 : 165 : if (t == error_mark_node)
9308 : : remove = true;
9309 : 165 : else if (!type_dependent_expression_p (t)
9310 : 165 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9311 : : {
9312 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9313 : : "%<grainsize%> expression must be integral");
9314 : 0 : remove = true;
9315 : : }
9316 : : else
9317 : : {
9318 : 165 : t = mark_rvalue_use (t);
9319 : 165 : if (!processing_template_decl)
9320 : : {
9321 : 164 : t = maybe_constant_value (t);
9322 : 164 : if (TREE_CODE (t) == INTEGER_CST
9323 : 164 : && tree_int_cst_sgn (t) != 1)
9324 : : {
9325 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9326 : : "%<grainsize%> value must be positive");
9327 : 0 : t = integer_one_node;
9328 : : }
9329 : 164 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9330 : : }
9331 : 165 : OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
9332 : : }
9333 : : break;
9334 : :
9335 : 273 : case OMP_CLAUSE_PRIORITY:
9336 : 273 : t = OMP_CLAUSE_PRIORITY_EXPR (c);
9337 : 273 : if (t == error_mark_node)
9338 : : remove = true;
9339 : 273 : else if (!type_dependent_expression_p (t)
9340 : 273 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9341 : : {
9342 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9343 : : "%<priority%> expression must be integral");
9344 : 0 : remove = true;
9345 : : }
9346 : : else
9347 : : {
9348 : 273 : t = mark_rvalue_use (t);
9349 : 273 : if (!processing_template_decl)
9350 : : {
9351 : 273 : t = maybe_constant_value (t);
9352 : 273 : if (TREE_CODE (t) == INTEGER_CST
9353 : 273 : && tree_int_cst_sgn (t) == -1)
9354 : : {
9355 : 0 : warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
9356 : : "%<priority%> value must be non-negative");
9357 : 0 : t = integer_one_node;
9358 : : }
9359 : 273 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9360 : : }
9361 : 273 : OMP_CLAUSE_PRIORITY_EXPR (c) = t;
9362 : : }
9363 : : break;
9364 : :
9365 : 228 : case OMP_CLAUSE_HINT:
9366 : 228 : t = OMP_CLAUSE_HINT_EXPR (c);
9367 : 228 : if (t == error_mark_node)
9368 : : remove = true;
9369 : 228 : else if (!type_dependent_expression_p (t)
9370 : 228 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9371 : : {
9372 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9373 : : "%<hint%> expression must be integral");
9374 : 9 : remove = true;
9375 : : }
9376 : : else
9377 : : {
9378 : 219 : t = mark_rvalue_use (t);
9379 : 219 : if (!processing_template_decl)
9380 : : {
9381 : 171 : t = maybe_constant_value (t);
9382 : 171 : if (TREE_CODE (t) != INTEGER_CST)
9383 : : {
9384 : 16 : error_at (OMP_CLAUSE_LOCATION (c),
9385 : : "%<hint%> expression must be constant integer "
9386 : : "expression");
9387 : 16 : remove = true;
9388 : : }
9389 : : }
9390 : 219 : OMP_CLAUSE_HINT_EXPR (c) = t;
9391 : : }
9392 : : break;
9393 : :
9394 : 183 : case OMP_CLAUSE_FILTER:
9395 : 183 : t = OMP_CLAUSE_FILTER_EXPR (c);
9396 : 183 : if (t == error_mark_node)
9397 : : remove = true;
9398 : 183 : else if (!type_dependent_expression_p (t)
9399 : 183 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9400 : : {
9401 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9402 : : "%<filter%> expression must be integral");
9403 : 6 : remove = true;
9404 : : }
9405 : : else
9406 : : {
9407 : 177 : t = mark_rvalue_use (t);
9408 : 177 : if (!processing_template_decl)
9409 : : {
9410 : 174 : t = maybe_constant_value (t);
9411 : 174 : t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
9412 : : }
9413 : 177 : OMP_CLAUSE_FILTER_EXPR (c) = t;
9414 : : }
9415 : : break;
9416 : :
9417 : 424 : case OMP_CLAUSE_IS_DEVICE_PTR:
9418 : 424 : case OMP_CLAUSE_USE_DEVICE_PTR:
9419 : 424 : field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
9420 : 424 : t = OMP_CLAUSE_DECL (c);
9421 : 424 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
9422 : 320 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9423 : 424 : if (!type_dependent_expression_p (t))
9424 : : {
9425 : 422 : tree type = TREE_TYPE (t);
9426 : 422 : if (!TYPE_PTR_P (type)
9427 : 422 : && (!TYPE_REF_P (type) || !TYPE_PTR_P (TREE_TYPE (type))))
9428 : : {
9429 : 57 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
9430 : 57 : && ort == C_ORT_OMP)
9431 : : {
9432 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9433 : : "%qs variable is neither a pointer "
9434 : : "nor reference to pointer",
9435 : 3 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9436 : 3 : remove = true;
9437 : : }
9438 : 54 : else if (TREE_CODE (type) != ARRAY_TYPE
9439 : 54 : && (!TYPE_REF_P (type)
9440 : 2 : || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
9441 : : {
9442 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
9443 : : "%qs variable is neither a pointer, nor an "
9444 : : "array nor reference to pointer or array",
9445 : 12 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9446 : 12 : remove = true;
9447 : : }
9448 : : }
9449 : : }
9450 : 424 : goto check_dup_generic;
9451 : :
9452 : 266 : case OMP_CLAUSE_HAS_DEVICE_ADDR:
9453 : 266 : t = OMP_CLAUSE_DECL (c);
9454 : 266 : if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9455 : : {
9456 : 28 : if (handle_omp_array_sections (c, ort))
9457 : : remove = true;
9458 : : else
9459 : : {
9460 : 28 : t = OMP_CLAUSE_DECL (c);
9461 : 30 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
9462 : 2 : t = TREE_OPERAND (t, 0);
9463 : 64 : while (INDIRECT_REF_P (t)
9464 : 64 : || TREE_CODE (t) == ARRAY_REF)
9465 : 36 : t = TREE_OPERAND (t, 0);
9466 : : }
9467 : : }
9468 : 266 : if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9469 : : {
9470 : 266 : bitmap_set_bit (&is_on_device_head, DECL_UID (t));
9471 : 266 : if (!processing_template_decl
9472 : 266 : && !cxx_mark_addressable (t))
9473 : : remove = true;
9474 : : }
9475 : 266 : goto check_dup_generic_t;
9476 : :
9477 : 76 : case OMP_CLAUSE_USE_DEVICE_ADDR:
9478 : 76 : field_ok = true;
9479 : 76 : t = OMP_CLAUSE_DECL (c);
9480 : 76 : if (!processing_template_decl
9481 : 74 : && (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
9482 : 74 : && !TYPE_REF_P (TREE_TYPE (t))
9483 : 143 : && !cxx_mark_addressable (t))
9484 : : remove = true;
9485 : 76 : goto check_dup_generic;
9486 : :
9487 : : case OMP_CLAUSE_NOWAIT:
9488 : : case OMP_CLAUSE_DEFAULT:
9489 : : case OMP_CLAUSE_UNTIED:
9490 : : case OMP_CLAUSE_COLLAPSE:
9491 : : case OMP_CLAUSE_PARALLEL:
9492 : : case OMP_CLAUSE_FOR:
9493 : : case OMP_CLAUSE_SECTIONS:
9494 : : case OMP_CLAUSE_TASKGROUP:
9495 : : case OMP_CLAUSE_PROC_BIND:
9496 : : case OMP_CLAUSE_DEVICE_TYPE:
9497 : : case OMP_CLAUSE_NOGROUP:
9498 : : case OMP_CLAUSE_THREADS:
9499 : : case OMP_CLAUSE_SIMD:
9500 : : case OMP_CLAUSE_DEFAULTMAP:
9501 : : case OMP_CLAUSE_BIND:
9502 : : case OMP_CLAUSE_AUTO:
9503 : : case OMP_CLAUSE_INDEPENDENT:
9504 : : case OMP_CLAUSE_SEQ:
9505 : : case OMP_CLAUSE_IF_PRESENT:
9506 : : case OMP_CLAUSE_FINALIZE:
9507 : : case OMP_CLAUSE_NOHOST:
9508 : : case OMP_CLAUSE_INDIRECT:
9509 : : break;
9510 : :
9511 : 228 : case OMP_CLAUSE_MERGEABLE:
9512 : 228 : mergeable_seen = true;
9513 : 228 : break;
9514 : :
9515 : 322 : case OMP_CLAUSE_TILE:
9516 : 754 : for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
9517 : 432 : list = TREE_CHAIN (list))
9518 : : {
9519 : 432 : t = TREE_VALUE (list);
9520 : :
9521 : 432 : if (t == error_mark_node)
9522 : : remove = true;
9523 : 403 : else if (!type_dependent_expression_p (t)
9524 : 403 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9525 : : {
9526 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9527 : : "%<tile%> argument needs integral type");
9528 : 3 : remove = true;
9529 : : }
9530 : : else
9531 : : {
9532 : 400 : t = mark_rvalue_use (t);
9533 : 400 : if (!processing_template_decl)
9534 : : {
9535 : : /* Zero is used to indicate '*', we permit you
9536 : : to get there via an ICE of value zero. */
9537 : 385 : t = maybe_constant_value (t);
9538 : 385 : if (!tree_fits_shwi_p (t)
9539 : 369 : || tree_to_shwi (t) < 0)
9540 : : {
9541 : 40 : error_at (OMP_CLAUSE_LOCATION (c),
9542 : : "%<tile%> argument needs positive "
9543 : : "integral constant");
9544 : 40 : remove = true;
9545 : : }
9546 : : }
9547 : : }
9548 : :
9549 : : /* Update list item. */
9550 : 432 : TREE_VALUE (list) = t;
9551 : : }
9552 : : break;
9553 : :
9554 : 1027 : case OMP_CLAUSE_SIZES:
9555 : 1027 : for (tree list = OMP_CLAUSE_SIZES_LIST (c);
9556 : 2688 : !remove && list; list = TREE_CHAIN (list))
9557 : : {
9558 : 1661 : t = TREE_VALUE (list);
9559 : :
9560 : 1661 : if (t == error_mark_node)
9561 : 0 : t = integer_one_node;
9562 : 1661 : else if (!type_dependent_expression_p (t)
9563 : 1661 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9564 : : {
9565 : 8 : error_at (OMP_CLAUSE_LOCATION (c),
9566 : : "%<sizes%> argument needs positive integral "
9567 : : "constant");
9568 : 8 : t = integer_one_node;
9569 : : }
9570 : : else
9571 : : {
9572 : 1653 : t = mark_rvalue_use (t);
9573 : 1653 : if (!processing_template_decl)
9574 : : {
9575 : 1636 : t = maybe_constant_value (t);
9576 : 1636 : HOST_WIDE_INT n;
9577 : 1636 : if (!tree_fits_shwi_p (t)
9578 : 1632 : || !INTEGRAL_TYPE_P (TREE_TYPE (t))
9579 : 1632 : || (n = tree_to_shwi (t)) <= 0
9580 : 3240 : || (int)n != n)
9581 : : {
9582 : 32 : error_at (OMP_CLAUSE_LOCATION (c),
9583 : : "%<sizes%> argument needs positive "
9584 : : "integral constant");
9585 : 32 : t = integer_one_node;
9586 : : }
9587 : : }
9588 : : }
9589 : :
9590 : : /* Update list item. */
9591 : 1661 : TREE_VALUE (list) = t;
9592 : : }
9593 : : break;
9594 : :
9595 : 627 : case OMP_CLAUSE_ORDERED:
9596 : 627 : ordered_seen = true;
9597 : 627 : break;
9598 : :
9599 : 1546 : case OMP_CLAUSE_ORDER:
9600 : 1546 : if (order_seen)
9601 : : remove = true;
9602 : : else
9603 : : order_seen = true;
9604 : : break;
9605 : :
9606 : 638 : case OMP_CLAUSE_INBRANCH:
9607 : 638 : case OMP_CLAUSE_NOTINBRANCH:
9608 : 638 : if (branch_seen)
9609 : : {
9610 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9611 : : "%<inbranch%> clause is incompatible with "
9612 : : "%<notinbranch%>");
9613 : 3 : remove = true;
9614 : : }
9615 : : branch_seen = true;
9616 : : break;
9617 : :
9618 : 297 : case OMP_CLAUSE_INCLUSIVE:
9619 : 297 : case OMP_CLAUSE_EXCLUSIVE:
9620 : 297 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
9621 : 297 : if (!t)
9622 : 297 : t = OMP_CLAUSE_DECL (c);
9623 : 297 : if (t == current_class_ptr)
9624 : : {
9625 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9626 : : "%<this%> allowed in OpenMP only in %<declare simd%>"
9627 : : " clauses");
9628 : 0 : remove = true;
9629 : 0 : break;
9630 : : }
9631 : 297 : if (!VAR_P (t)
9632 : : && TREE_CODE (t) != PARM_DECL
9633 : : && TREE_CODE (t) != FIELD_DECL)
9634 : : {
9635 : 0 : if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
9636 : : break;
9637 : 0 : if (DECL_P (t))
9638 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9639 : : "%qD is not a variable in clause %qs", t,
9640 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9641 : : else
9642 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9643 : : "%qE is not a variable in clause %qs", t,
9644 : 0 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
9645 : : remove = true;
9646 : : }
9647 : : break;
9648 : :
9649 : : case OMP_CLAUSE_FULL:
9650 : : break;
9651 : :
9652 : 470 : case OMP_CLAUSE_PARTIAL:
9653 : 470 : partial_seen = true;
9654 : 470 : t = OMP_CLAUSE_PARTIAL_EXPR (c);
9655 : 470 : if (!t)
9656 : : break;
9657 : :
9658 : 313 : if (t == error_mark_node)
9659 : : t = NULL_TREE;
9660 : 313 : else if (!type_dependent_expression_p (t)
9661 : 313 : && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
9662 : : {
9663 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9664 : : "%<partial%> argument needs positive constant "
9665 : : "integer expression");
9666 : 3 : t = NULL_TREE;
9667 : : }
9668 : : else
9669 : : {
9670 : 310 : t = mark_rvalue_use (t);
9671 : 310 : if (!processing_template_decl)
9672 : : {
9673 : 292 : t = maybe_constant_value (t);
9674 : :
9675 : 292 : HOST_WIDE_INT n;
9676 : 584 : if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
9677 : 292 : || !tree_fits_shwi_p (t)
9678 : 286 : || (n = tree_to_shwi (t)) <= 0
9679 : 560 : || (int)n != n)
9680 : : {
9681 : 24 : error_at (OMP_CLAUSE_LOCATION (c),
9682 : : "%<partial%> argument needs positive "
9683 : : "constant integer expression");
9684 : 24 : t = NULL_TREE;
9685 : : }
9686 : : }
9687 : : }
9688 : :
9689 : 313 : OMP_CLAUSE_PARTIAL_EXPR (c) = t;
9690 : 313 : break;
9691 : 601 : case OMP_CLAUSE_INIT:
9692 : 601 : init_seen = true;
9693 : 601 : cp_omp_init_prefer_type_update (c);
9694 : 601 : if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
9695 : 370 : init_no_targetsync_clause = c;
9696 : : /* FALLTHRU */
9697 : 891 : case OMP_CLAUSE_DESTROY:
9698 : 891 : case OMP_CLAUSE_USE:
9699 : 891 : init_use_destroy_seen = true;
9700 : 891 : t = OMP_CLAUSE_DECL (c);
9701 : 891 : if (bitmap_bit_p (&generic_head, DECL_UID (t)))
9702 : : {
9703 : 18 : error_at (OMP_CLAUSE_LOCATION (c),
9704 : : "%qD appears more than once in action clauses", t);
9705 : 18 : remove = true;
9706 : 18 : break;
9707 : : }
9708 : 873 : bitmap_set_bit (&generic_head, DECL_UID (t));
9709 : : /* FALLTHRU */
9710 : 1131 : case OMP_CLAUSE_INTEROP:
9711 : 1131 : if (!processing_template_decl)
9712 : : {
9713 : 1035 : if (/* (ort == C_ORT_OMP_INTEROP [uncomment for depobj init]
9714 : : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INTEROP) && */
9715 : 1035 : !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
9716 : : {
9717 : 126 : error_at (OMP_CLAUSE_LOCATION (c),
9718 : : "%qD must be of %<omp_interop_t%>",
9719 : 63 : OMP_CLAUSE_DECL (c));
9720 : 63 : remove = true;
9721 : : }
9722 : 972 : else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
9723 : 470 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
9724 : 1087 : && TREE_READONLY (OMP_CLAUSE_DECL (c)))
9725 : : {
9726 : 36 : error_at (OMP_CLAUSE_LOCATION (c),
9727 : 18 : "%qD shall not be const", OMP_CLAUSE_DECL (c));
9728 : 18 : remove = true;
9729 : : }
9730 : : }
9731 : 1131 : pc = &OMP_CLAUSE_CHAIN (c);
9732 : 1131 : break;
9733 : 0 : default:
9734 : 0 : gcc_unreachable ();
9735 : : }
9736 : :
9737 : 96215 : if (remove)
9738 : : {
9739 : 2586 : if (grp_start_p)
9740 : : {
9741 : : /* If we found a clause to remove, we want to remove the whole
9742 : : expanded group, otherwise gimplify
9743 : : (omp_resolve_clause_dependencies) can get confused. */
9744 : 858 : *grp_start_p = grp_sentinel;
9745 : 858 : pc = grp_start_p;
9746 : 858 : grp_start_p = NULL;
9747 : : }
9748 : : else
9749 : 1728 : *pc = OMP_CLAUSE_CHAIN (c);
9750 : : }
9751 : : else
9752 : 93629 : pc = &OMP_CLAUSE_CHAIN (c);
9753 : : }
9754 : :
9755 : 61981 : if (reduction_seen < 0 && (ordered_seen || schedule_seen))
9756 : 61981 : reduction_seen = -2;
9757 : :
9758 : 156472 : for (pc = &clauses, c = clauses; c ; c = *pc)
9759 : : {
9760 : 94491 : enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
9761 : 94491 : bool remove = false;
9762 : 94491 : bool need_complete_type = false;
9763 : 94491 : bool need_default_ctor = false;
9764 : 94491 : bool need_copy_ctor = false;
9765 : 94491 : bool need_copy_assignment = false;
9766 : 94491 : bool need_implicitly_determined = false;
9767 : 94491 : bool need_dtor = false;
9768 : 94491 : tree type, inner_type;
9769 : :
9770 : 94491 : switch (c_kind)
9771 : : {
9772 : : case OMP_CLAUSE_SHARED:
9773 : : need_implicitly_determined = true;
9774 : : break;
9775 : 2499 : case OMP_CLAUSE_PRIVATE:
9776 : 2499 : need_complete_type = true;
9777 : 2499 : need_default_ctor = true;
9778 : 2499 : need_dtor = true;
9779 : 2499 : need_implicitly_determined = true;
9780 : 2499 : break;
9781 : 3113 : case OMP_CLAUSE_FIRSTPRIVATE:
9782 : 3113 : need_complete_type = true;
9783 : 3113 : need_copy_ctor = true;
9784 : 3113 : need_dtor = true;
9785 : 3113 : need_implicitly_determined = true;
9786 : 3113 : break;
9787 : 2757 : case OMP_CLAUSE_LASTPRIVATE:
9788 : 2757 : need_complete_type = true;
9789 : 2757 : need_copy_assignment = true;
9790 : 2757 : need_implicitly_determined = true;
9791 : 2757 : break;
9792 : 7392 : case OMP_CLAUSE_REDUCTION:
9793 : 7392 : if (reduction_seen == -2)
9794 : 27 : OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
9795 : 7392 : if (OMP_CLAUSE_REDUCTION_INSCAN (c))
9796 : 421 : need_copy_assignment = true;
9797 : : need_implicitly_determined = true;
9798 : : break;
9799 : : case OMP_CLAUSE_IN_REDUCTION:
9800 : : case OMP_CLAUSE_TASK_REDUCTION:
9801 : : case OMP_CLAUSE_INCLUSIVE:
9802 : : case OMP_CLAUSE_EXCLUSIVE:
9803 : : need_implicitly_determined = true;
9804 : : break;
9805 : 1532 : case OMP_CLAUSE_LINEAR:
9806 : 1532 : if (ort != C_ORT_OMP_DECLARE_SIMD)
9807 : : need_implicitly_determined = true;
9808 : 661 : else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
9809 : 703 : && !bitmap_bit_p (&map_head,
9810 : 42 : DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
9811 : : {
9812 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9813 : : "%<linear%> clause step is a parameter %qD not "
9814 : : "specified in %<uniform%> clause",
9815 : 6 : OMP_CLAUSE_LINEAR_STEP (c));
9816 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
9817 : 73024 : continue;
9818 : : }
9819 : : break;
9820 : : case OMP_CLAUSE_COPYPRIVATE:
9821 : 366 : need_copy_assignment = true;
9822 : : break;
9823 : : case OMP_CLAUSE_COPYIN:
9824 : 366 : need_copy_assignment = true;
9825 : : break;
9826 : 798 : case OMP_CLAUSE_SIMDLEN:
9827 : 798 : if (safelen
9828 : 345 : && !processing_template_decl
9829 : 1143 : && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
9830 : 345 : OMP_CLAUSE_SIMDLEN_EXPR (c)))
9831 : : {
9832 : 0 : error_at (OMP_CLAUSE_LOCATION (c),
9833 : : "%<simdlen%> clause value is bigger than "
9834 : : "%<safelen%> clause value");
9835 : 0 : OMP_CLAUSE_SIMDLEN_EXPR (c)
9836 : 0 : = OMP_CLAUSE_SAFELEN_EXPR (safelen);
9837 : : }
9838 : 798 : pc = &OMP_CLAUSE_CHAIN (c);
9839 : 798 : continue;
9840 : 3847 : case OMP_CLAUSE_SCHEDULE:
9841 : 3847 : if (ordered_seen
9842 : 3847 : && (OMP_CLAUSE_SCHEDULE_KIND (c)
9843 : : & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
9844 : : {
9845 : 21 : error_at (OMP_CLAUSE_LOCATION (c),
9846 : : "%<nonmonotonic%> schedule modifier specified "
9847 : : "together with %<ordered%> clause");
9848 : 42 : OMP_CLAUSE_SCHEDULE_KIND (c)
9849 : 21 : = (enum omp_clause_schedule_kind)
9850 : 21 : (OMP_CLAUSE_SCHEDULE_KIND (c)
9851 : : & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
9852 : : }
9853 : 3847 : if (reduction_seen == -2)
9854 : 9 : error_at (OMP_CLAUSE_LOCATION (c),
9855 : : "%qs clause specified together with %<inscan%> "
9856 : : "%<reduction%> clause", "schedule");
9857 : 3847 : pc = &OMP_CLAUSE_CHAIN (c);
9858 : 3847 : continue;
9859 : 51 : case OMP_CLAUSE_NOGROUP:
9860 : 51 : if (reduction_seen)
9861 : : {
9862 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
9863 : : "%<nogroup%> clause must not be used together with "
9864 : : "%<reduction%> clause");
9865 : 3 : *pc = OMP_CLAUSE_CHAIN (c);
9866 : 3 : continue;
9867 : : }
9868 : 48 : pc = &OMP_CLAUSE_CHAIN (c);
9869 : 48 : continue;
9870 : 165 : case OMP_CLAUSE_GRAINSIZE:
9871 : 165 : if (num_tasks_seen)
9872 : : {
9873 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9874 : : "%<grainsize%> clause must not be used together with "
9875 : : "%<num_tasks%> clause");
9876 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
9877 : 6 : continue;
9878 : : }
9879 : 159 : pc = &OMP_CLAUSE_CHAIN (c);
9880 : 159 : continue;
9881 : 627 : case OMP_CLAUSE_ORDERED:
9882 : 627 : if (reduction_seen == -2)
9883 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9884 : : "%qs clause specified together with %<inscan%> "
9885 : : "%<reduction%> clause", "ordered");
9886 : 627 : pc = &OMP_CLAUSE_CHAIN (c);
9887 : 627 : continue;
9888 : 1522 : case OMP_CLAUSE_ORDER:
9889 : 1522 : if (ordered_seen)
9890 : : {
9891 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
9892 : : "%<order%> clause must not be used together "
9893 : : "with %<ordered%> clause");
9894 : 12 : *pc = OMP_CLAUSE_CHAIN (c);
9895 : 12 : continue;
9896 : : }
9897 : 1510 : pc = &OMP_CLAUSE_CHAIN (c);
9898 : 1510 : continue;
9899 : 57 : case OMP_CLAUSE_DETACH:
9900 : 57 : if (mergeable_seen)
9901 : : {
9902 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9903 : : "%<detach%> clause must not be used together with "
9904 : : "%<mergeable%> clause");
9905 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
9906 : 6 : continue;
9907 : : }
9908 : 51 : pc = &OMP_CLAUSE_CHAIN (c);
9909 : 51 : continue;
9910 : 14733 : case OMP_CLAUSE_MAP:
9911 : 14733 : if (target_in_reduction_seen && !processing_template_decl)
9912 : : {
9913 : 684 : t = OMP_CLAUSE_DECL (c);
9914 : 684 : while (handled_component_p (t)
9915 : : || INDIRECT_REF_P (t)
9916 : : || TREE_CODE (t) == ADDR_EXPR
9917 : : || TREE_CODE (t) == MEM_REF
9918 : 804 : || TREE_CODE (t) == NON_LVALUE_EXPR)
9919 : 120 : t = TREE_OPERAND (t, 0);
9920 : 684 : if (DECL_P (t)
9921 : 684 : && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
9922 : 342 : OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
9923 : : }
9924 : 14733 : pc = &OMP_CLAUSE_CHAIN (c);
9925 : 14733 : continue;
9926 : 225 : case OMP_CLAUSE_FULL:
9927 : 225 : if (partial_seen)
9928 : : {
9929 : 12 : error_at (OMP_CLAUSE_LOCATION (c),
9930 : : "%<full%> clause must not be used together "
9931 : : "with %<partial%> clause");
9932 : 12 : *pc = OMP_CLAUSE_CHAIN (c);
9933 : 12 : continue;
9934 : : }
9935 : 213 : pc = &OMP_CLAUSE_CHAIN (c);
9936 : 213 : continue;
9937 : 6902 : case OMP_CLAUSE_NOWAIT:
9938 : 6902 : if (copyprivate_seen)
9939 : : {
9940 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
9941 : : "%<nowait%> clause must not be used together "
9942 : : "with %<copyprivate%> clause");
9943 : 6 : *pc = OMP_CLAUSE_CHAIN (c);
9944 : 6 : continue;
9945 : : }
9946 : : /* FALLTHRU */
9947 : 50301 : default:
9948 : 50301 : pc = &OMP_CLAUSE_CHAIN (c);
9949 : 50301 : continue;
9950 : : }
9951 : :
9952 : 22153 : t = OMP_CLAUSE_DECL (c);
9953 : 22153 : switch (c_kind)
9954 : : {
9955 : 2757 : case OMP_CLAUSE_LASTPRIVATE:
9956 : 2757 : if (DECL_P (t)
9957 : 2757 : && !bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
9958 : : {
9959 : 2660 : need_default_ctor = true;
9960 : 2660 : need_dtor = true;
9961 : : }
9962 : : break;
9963 : :
9964 : 9528 : case OMP_CLAUSE_REDUCTION:
9965 : 9528 : case OMP_CLAUSE_IN_REDUCTION:
9966 : 9528 : case OMP_CLAUSE_TASK_REDUCTION:
9967 : 9528 : if (allocate_seen)
9968 : : {
9969 : 1711 : if (TREE_CODE (t) == MEM_REF)
9970 : : {
9971 : 222 : t = TREE_OPERAND (t, 0);
9972 : 222 : if (TREE_CODE (t) == POINTER_PLUS_EXPR)
9973 : 0 : t = TREE_OPERAND (t, 0);
9974 : 222 : if (TREE_CODE (t) == ADDR_EXPR
9975 : 168 : || INDIRECT_REF_P (t))
9976 : 110 : t = TREE_OPERAND (t, 0);
9977 : 222 : if (DECL_P (t))
9978 : 222 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
9979 : : }
9980 : 1489 : else if (TREE_CODE (t) == OMP_ARRAY_SECTION)
9981 : : {
9982 : 288 : while (TREE_CODE (t) == OMP_ARRAY_SECTION)
9983 : 144 : t = TREE_OPERAND (t, 0);
9984 : 144 : if (DECL_P (t))
9985 : 144 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
9986 : 144 : t = OMP_CLAUSE_DECL (c);
9987 : : }
9988 : 1345 : else if (DECL_P (t))
9989 : 1345 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
9990 : 1711 : t = OMP_CLAUSE_DECL (c);
9991 : : }
9992 : 9528 : if (processing_template_decl
9993 : 925 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
9994 : : break;
9995 : 8910 : if (finish_omp_reduction_clause (c, &need_default_ctor,
9996 : : &need_dtor))
9997 : : remove = true;
9998 : : else
9999 : 8826 : t = OMP_CLAUSE_DECL (c);
10000 : : break;
10001 : :
10002 : 274 : case OMP_CLAUSE_COPYIN:
10003 : 274 : if (processing_template_decl
10004 : 0 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10005 : : break;
10006 : 274 : if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
10007 : : {
10008 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
10009 : : "%qE must be %<threadprivate%> for %<copyin%>", t);
10010 : 15 : remove = true;
10011 : : }
10012 : : break;
10013 : :
10014 : : default:
10015 : : break;
10016 : : }
10017 : :
10018 : 22153 : if (processing_template_decl
10019 : 1606 : && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
10020 : : {
10021 : 680 : pc = &OMP_CLAUSE_CHAIN (c);
10022 : 680 : continue;
10023 : : }
10024 : :
10025 : 21473 : if (need_complete_type || need_copy_assignment)
10026 : : {
10027 : 9100 : t = require_complete_type (t);
10028 : 9100 : if (t == error_mark_node)
10029 : : remove = true;
10030 : 9076 : else if (!processing_template_decl
10031 : 8693 : && TYPE_REF_P (TREE_TYPE (t))
10032 : 9604 : && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
10033 : : remove = true;
10034 : : }
10035 : 21473 : if (need_implicitly_determined)
10036 : : {
10037 : 20453 : const char *share_name = NULL;
10038 : :
10039 : 20453 : if (allocate_seen
10040 : 5047 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10041 : 24621 : && DECL_P (t))
10042 : 3883 : bitmap_clear_bit (&aligned_head, DECL_UID (t));
10043 : :
10044 : 20453 : if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
10045 : : share_name = "threadprivate";
10046 : 20411 : else switch (cxx_omp_predetermined_sharing_1 (t))
10047 : : {
10048 : : case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
10049 : : break;
10050 : 47 : case OMP_CLAUSE_DEFAULT_SHARED:
10051 : 47 : if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10052 : 30 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
10053 : 64 : && c_omp_predefined_variable (t))
10054 : : /* The __func__ variable and similar function-local predefined
10055 : : variables may be listed in a shared or firstprivate
10056 : : clause. */
10057 : : break;
10058 : 31 : if (VAR_P (t)
10059 : 31 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10060 : 9 : && TREE_STATIC (t)
10061 : 40 : && cxx_omp_const_qual_no_mutable (t))
10062 : : {
10063 : 6 : tree ctx = CP_DECL_CONTEXT (t);
10064 : : /* const qualified static data members without mutable
10065 : : member may be specified in firstprivate clause. */
10066 : 6 : if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
10067 : : break;
10068 : : }
10069 : : share_name = "shared";
10070 : : break;
10071 : : case OMP_CLAUSE_DEFAULT_PRIVATE:
10072 : : share_name = "private";
10073 : : break;
10074 : 0 : default:
10075 : 0 : gcc_unreachable ();
10076 : : }
10077 : : if (share_name)
10078 : : {
10079 : 67 : error_at (OMP_CLAUSE_LOCATION (c),
10080 : : "%qE is predetermined %qs for %qs",
10081 : : omp_clause_printable_decl (t), share_name,
10082 : 67 : omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
10083 : 67 : remove = true;
10084 : : }
10085 : 20386 : else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
10086 : 18333 : && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
10087 : 35635 : && cxx_omp_const_qual_no_mutable (t))
10088 : : {
10089 : 126 : error_at (OMP_CLAUSE_LOCATION (c),
10090 : : "%<const%> qualified %qE without %<mutable%> member "
10091 : : "may appear only in %<shared%> or %<firstprivate%> "
10092 : : "clauses", omp_clause_printable_decl (t));
10093 : 63 : remove = true;
10094 : : }
10095 : : }
10096 : :
10097 : 21473 : if (detach_seen
10098 : 16 : && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
10099 : 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
10100 : 10 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
10101 : 0 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
10102 : 21489 : && OMP_CLAUSE_DECL (c) == OMP_CLAUSE_DECL (detach_seen))
10103 : : {
10104 : 6 : error_at (OMP_CLAUSE_LOCATION (c),
10105 : : "the event handle of a %<detach%> clause "
10106 : : "should not be in a data-sharing clause");
10107 : 6 : remove = true;
10108 : : }
10109 : :
10110 : : /* We're interested in the base element, not arrays. */
10111 : 21473 : inner_type = type = TREE_TYPE (t);
10112 : 21473 : if ((need_complete_type
10113 : : || need_copy_assignment
10114 : 12373 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
10115 : 5681 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
10116 : 4211 : || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
10117 : 29962 : && TYPE_REF_P (inner_type))
10118 : 871 : inner_type = TREE_TYPE (inner_type);
10119 : 24095 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
10120 : 2622 : inner_type = TREE_TYPE (inner_type);
10121 : :
10122 : : /* Check for special function availability by building a call to one.
10123 : : Save the results, because later we won't be in the right context
10124 : : for making these queries. */
10125 : 2378 : if (CLASS_TYPE_P (inner_type)
10126 : 2378 : && COMPLETE_TYPE_P (inner_type)
10127 : 2312 : && (need_default_ctor || need_copy_ctor
10128 : 1076 : || need_copy_assignment || need_dtor)
10129 : 1988 : && !type_dependent_expression_p (t)
10130 : 23461 : && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
10131 : : need_copy_ctor, need_copy_assignment,
10132 : : need_dtor))
10133 : : remove = true;
10134 : :
10135 : 21473 : if (!remove
10136 : 21473 : && c_kind == OMP_CLAUSE_SHARED
10137 : 2050 : && processing_template_decl)
10138 : : {
10139 : 125 : t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
10140 : 125 : if (t)
10141 : 5 : OMP_CLAUSE_DECL (c) = t;
10142 : : }
10143 : :
10144 : 21473 : if (remove)
10145 : 292 : *pc = OMP_CLAUSE_CHAIN (c);
10146 : : else
10147 : 21181 : pc = &OMP_CLAUSE_CHAIN (c);
10148 : : }
10149 : :
10150 : 61981 : if (allocate_seen)
10151 : 17255 : for (pc = &clauses, c = clauses; c ; c = *pc)
10152 : : {
10153 : 14799 : bool remove = false;
10154 : 14799 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
10155 : 2694 : && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
10156 : 2245 : && DECL_P (OMP_CLAUSE_DECL (c))
10157 : 17044 : && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
10158 : : {
10159 : 15 : error_at (OMP_CLAUSE_LOCATION (c),
10160 : : "%qD specified in %<allocate%> clause but not in "
10161 : 15 : "an explicit privatization clause", OMP_CLAUSE_DECL (c));
10162 : 15 : remove = true;
10163 : : }
10164 : 14799 : if (remove)
10165 : 15 : *pc = OMP_CLAUSE_CHAIN (c);
10166 : : else
10167 : 14784 : pc = &OMP_CLAUSE_CHAIN (c);
10168 : : }
10169 : :
10170 : 61981 : if (ort == C_ORT_OMP_INTEROP
10171 : 61981 : && depend_clause
10172 : 56 : && (!init_use_destroy_seen
10173 : 53 : || (init_seen && init_no_targetsync_clause)))
10174 : : {
10175 : 9 : error_at (OMP_CLAUSE_LOCATION (depend_clause),
10176 : : "%<depend%> clause requires action clauses with "
10177 : : "%<targetsync%> interop-type");
10178 : 9 : if (init_no_targetsync_clause)
10179 : 6 : inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
10180 : : "%<init%> clause lacks the %<targetsync%> modifier");
10181 : : }
10182 : :
10183 : 61981 : bitmap_obstack_release (NULL);
10184 : 61981 : return clauses;
10185 : : }
10186 : :
10187 : : /* Start processing OpenMP clauses that can include any
10188 : : privatization clauses for non-static data members. */
10189 : :
10190 : : tree
10191 : 48040 : push_omp_privatization_clauses (bool ignore_next)
10192 : : {
10193 : 48040 : if (omp_private_member_ignore_next)
10194 : : {
10195 : 708 : omp_private_member_ignore_next = ignore_next;
10196 : 708 : return NULL_TREE;
10197 : : }
10198 : 47332 : omp_private_member_ignore_next = ignore_next;
10199 : 47332 : if (omp_private_member_map)
10200 : 24 : omp_private_member_vec.safe_push (error_mark_node);
10201 : 47332 : return push_stmt_list ();
10202 : : }
10203 : :
10204 : : /* Revert remapping of any non-static data members since
10205 : : the last push_omp_privatization_clauses () call. */
10206 : :
10207 : : void
10208 : 48034 : pop_omp_privatization_clauses (tree stmt)
10209 : : {
10210 : 48034 : if (stmt == NULL_TREE)
10211 : : return;
10212 : 47326 : stmt = pop_stmt_list (stmt);
10213 : 47326 : if (omp_private_member_map)
10214 : : {
10215 : 1271 : while (!omp_private_member_vec.is_empty ())
10216 : : {
10217 : 844 : tree t = omp_private_member_vec.pop ();
10218 : 844 : if (t == error_mark_node)
10219 : : {
10220 : 24 : add_stmt (stmt);
10221 : 24 : return;
10222 : : }
10223 : 820 : bool no_decl_expr = t == integer_zero_node;
10224 : 820 : if (no_decl_expr)
10225 : 136 : t = omp_private_member_vec.pop ();
10226 : 820 : tree *v = omp_private_member_map->get (t);
10227 : 820 : gcc_assert (v);
10228 : 820 : if (!no_decl_expr)
10229 : 684 : add_decl_expr (*v);
10230 : 820 : omp_private_member_map->remove (t);
10231 : : }
10232 : 854 : delete omp_private_member_map;
10233 : 427 : omp_private_member_map = NULL;
10234 : : }
10235 : 47302 : add_stmt (stmt);
10236 : : }
10237 : :
10238 : : /* Remember OpenMP privatization clauses mapping and clear it.
10239 : : Used for lambdas. */
10240 : :
10241 : : void
10242 : 7502637 : save_omp_privatization_clauses (vec<tree> &save)
10243 : : {
10244 : 7502637 : save = vNULL;
10245 : 7502637 : if (omp_private_member_ignore_next)
10246 : 2 : save.safe_push (integer_one_node);
10247 : 7502637 : omp_private_member_ignore_next = false;
10248 : 7502637 : if (!omp_private_member_map)
10249 : : return;
10250 : :
10251 : 0 : while (!omp_private_member_vec.is_empty ())
10252 : : {
10253 : 0 : tree t = omp_private_member_vec.pop ();
10254 : 0 : if (t == error_mark_node)
10255 : : {
10256 : 0 : save.safe_push (t);
10257 : 0 : continue;
10258 : : }
10259 : 0 : tree n = t;
10260 : 0 : if (t == integer_zero_node)
10261 : 0 : t = omp_private_member_vec.pop ();
10262 : 0 : tree *v = omp_private_member_map->get (t);
10263 : 0 : gcc_assert (v);
10264 : 0 : save.safe_push (*v);
10265 : 0 : save.safe_push (t);
10266 : 0 : if (n != t)
10267 : 0 : save.safe_push (n);
10268 : : }
10269 : 0 : delete omp_private_member_map;
10270 : 0 : omp_private_member_map = NULL;
10271 : : }
10272 : :
10273 : : /* Restore OpenMP privatization clauses mapping saved by the
10274 : : above function. */
10275 : :
10276 : : void
10277 : 7502637 : restore_omp_privatization_clauses (vec<tree> &save)
10278 : : {
10279 : 7502637 : gcc_assert (omp_private_member_vec.is_empty ());
10280 : 7502637 : omp_private_member_ignore_next = false;
10281 : 7502637 : if (save.is_empty ())
10282 : : return;
10283 : 4 : if (save.length () == 1 && save[0] == integer_one_node)
10284 : : {
10285 : 2 : omp_private_member_ignore_next = true;
10286 : 2 : save.release ();
10287 : 2 : return;
10288 : : }
10289 : :
10290 : 0 : omp_private_member_map = new hash_map <tree, tree>;
10291 : 0 : while (!save.is_empty ())
10292 : : {
10293 : 0 : tree t = save.pop ();
10294 : 0 : tree n = t;
10295 : 0 : if (t != error_mark_node)
10296 : : {
10297 : 0 : if (t == integer_one_node)
10298 : : {
10299 : 0 : omp_private_member_ignore_next = true;
10300 : 0 : gcc_assert (save.is_empty ());
10301 : 0 : break;
10302 : : }
10303 : 0 : if (t == integer_zero_node)
10304 : 0 : t = save.pop ();
10305 : 0 : tree &v = omp_private_member_map->get_or_insert (t);
10306 : 0 : v = save.pop ();
10307 : : }
10308 : 0 : omp_private_member_vec.safe_push (t);
10309 : 0 : if (n != t)
10310 : 0 : omp_private_member_vec.safe_push (n);
10311 : : }
10312 : 0 : save.release ();
10313 : : }
10314 : :
10315 : : /* For all variables in the tree_list VARS, mark them as thread local. */
10316 : :
10317 : : void
10318 : 241 : finish_omp_threadprivate (tree vars)
10319 : : {
10320 : 241 : tree t;
10321 : :
10322 : : /* Mark every variable in VARS to be assigned thread local storage. */
10323 : 515 : for (t = vars; t; t = TREE_CHAIN (t))
10324 : : {
10325 : 274 : tree v = TREE_PURPOSE (t);
10326 : 274 : location_t loc = EXPR_LOCATION (TREE_VALUE (t));
10327 : :
10328 : 274 : if (error_operand_p (v))
10329 : : ;
10330 : 274 : else if (!VAR_P (v))
10331 : 6 : error_at (loc, "%<threadprivate%> %qD is not file, namespace "
10332 : : "or block scope variable", v);
10333 : : /* If V had already been marked threadprivate, it doesn't matter
10334 : : whether it had been used prior to this point. */
10335 : 268 : else if (TREE_USED (v)
10336 : 268 : && (DECL_LANG_SPECIFIC (v) == NULL
10337 : 3 : || !CP_DECL_THREADPRIVATE_P (v)))
10338 : 6 : error_at (loc, "%qE declared %<threadprivate%> after first use", v);
10339 : 262 : else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
10340 : 6 : error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
10341 : 256 : else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
10342 : 3 : error_at (loc, "%<threadprivate%> %qE has incomplete type", v);
10343 : 204 : else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
10344 : 276 : && CP_DECL_CONTEXT (v) != current_class_type)
10345 : 6 : error_at (loc, "%<threadprivate%> %qE directive not "
10346 : 6 : "in %qT definition", v, CP_DECL_CONTEXT (v));
10347 : : else
10348 : : {
10349 : : /* Allocate a LANG_SPECIFIC structure for V, if needed. */
10350 : 247 : if (DECL_LANG_SPECIFIC (v) == NULL)
10351 : 203 : retrofit_lang_decl (v);
10352 : :
10353 : 247 : if (! CP_DECL_THREAD_LOCAL_P (v))
10354 : : {
10355 : 247 : CP_DECL_THREAD_LOCAL_P (v) = true;
10356 : 247 : set_decl_tls_model (v, decl_default_tls_model (v));
10357 : : /* If rtl has been already set for this var, call
10358 : : make_decl_rtl once again, so that encode_section_info
10359 : : has a chance to look at the new decl flags. */
10360 : 247 : if (DECL_RTL_SET_P (v))
10361 : 0 : make_decl_rtl (v);
10362 : : }
10363 : 247 : CP_DECL_THREADPRIVATE_P (v) = 1;
10364 : : }
10365 : : }
10366 : 241 : }
10367 : :
10368 : : /* Build an OpenMP structured block. */
10369 : :
10370 : : tree
10371 : 63298 : begin_omp_structured_block (void)
10372 : : {
10373 : 63298 : return do_pushlevel (sk_omp);
10374 : : }
10375 : :
10376 : : tree
10377 : 63295 : finish_omp_structured_block (tree block)
10378 : : {
10379 : 63295 : return do_poplevel (block);
10380 : : }
10381 : :
10382 : : /* Similarly, except force the retention of the BLOCK. */
10383 : :
10384 : : tree
10385 : 14886 : begin_omp_parallel (void)
10386 : : {
10387 : 14886 : keep_next_level (true);
10388 : 14886 : return begin_omp_structured_block ();
10389 : : }
10390 : :
10391 : : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
10392 : : statement. */
10393 : :
10394 : : tree
10395 : 771 : finish_oacc_data (tree clauses, tree block)
10396 : : {
10397 : 771 : tree stmt;
10398 : :
10399 : 771 : block = finish_omp_structured_block (block);
10400 : :
10401 : 771 : stmt = make_node (OACC_DATA);
10402 : 771 : TREE_TYPE (stmt) = void_type_node;
10403 : 771 : OACC_DATA_CLAUSES (stmt) = clauses;
10404 : 771 : OACC_DATA_BODY (stmt) = block;
10405 : :
10406 : 771 : return add_stmt (stmt);
10407 : : }
10408 : :
10409 : : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
10410 : : statement. */
10411 : :
10412 : : tree
10413 : 55 : finish_oacc_host_data (tree clauses, tree block)
10414 : : {
10415 : 55 : tree stmt;
10416 : :
10417 : 55 : block = finish_omp_structured_block (block);
10418 : :
10419 : 55 : stmt = make_node (OACC_HOST_DATA);
10420 : 55 : TREE_TYPE (stmt) = void_type_node;
10421 : 55 : OACC_HOST_DATA_CLAUSES (stmt) = clauses;
10422 : 55 : OACC_HOST_DATA_BODY (stmt) = block;
10423 : :
10424 : 55 : return add_stmt (stmt);
10425 : : }
10426 : :
10427 : : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
10428 : : statement. */
10429 : :
10430 : : tree
10431 : 4698 : finish_omp_construct (enum tree_code code, tree body, tree clauses)
10432 : : {
10433 : 4698 : body = finish_omp_structured_block (body);
10434 : :
10435 : 4698 : tree stmt = make_node (code);
10436 : 4698 : TREE_TYPE (stmt) = void_type_node;
10437 : 4698 : OMP_BODY (stmt) = body;
10438 : 4698 : OMP_CLAUSES (stmt) = clauses;
10439 : :
10440 : 4698 : return add_stmt (stmt);
10441 : : }
10442 : :
10443 : : /* Used to walk OpenMP target directive body. */
10444 : :
10445 : : struct omp_target_walk_data
10446 : : {
10447 : : /* Holds the 'this' expression found in current function. */
10448 : : tree current_object;
10449 : :
10450 : : /* True if the 'this' expression was accessed in the target body. */
10451 : : bool this_expr_accessed;
10452 : :
10453 : : /* For non-static functions, record which pointer-typed members were
10454 : : accessed, and the whole expression. */
10455 : : hash_map<tree, tree> ptr_members_accessed;
10456 : :
10457 : : /* Record which lambda objects were accessed in target body. */
10458 : : hash_set<tree> lambda_objects_accessed;
10459 : :
10460 : : /* For lambda functions, the __closure object expression of the current
10461 : : function, and the set of captured variables accessed in target body. */
10462 : : tree current_closure;
10463 : : hash_set<tree> closure_vars_accessed;
10464 : :
10465 : : /* Local variables declared inside a BIND_EXPR, used to filter out such
10466 : : variables when recording lambda_objects_accessed. */
10467 : : hash_set<tree> local_decls;
10468 : : };
10469 : :
10470 : : /* Helper function of finish_omp_target_clauses, called via
10471 : : cp_walk_tree_without_duplicates. Traverse body of OpenMP target
10472 : : directive *TP, and fill out omp_target_walk_data passed in *PTR. */
10473 : :
10474 : : static tree
10475 : 198873 : finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr)
10476 : : {
10477 : 198873 : tree t = *tp;
10478 : 198873 : struct omp_target_walk_data *data = (struct omp_target_walk_data *) ptr;
10479 : 198873 : tree current_object = data->current_object;
10480 : 198873 : tree current_closure = data->current_closure;
10481 : :
10482 : : /* References inside of these expression codes shouldn't incur any
10483 : : form of mapping, so return early. */
10484 : 198873 : if (TREE_CODE (t) == SIZEOF_EXPR
10485 : 198866 : || TREE_CODE (t) == ALIGNOF_EXPR)
10486 : : {
10487 : 7 : *walk_subtrees = 0;
10488 : 7 : return NULL_TREE;
10489 : : }
10490 : :
10491 : 198866 : if (TREE_CODE (t) == OMP_CLAUSE)
10492 : : return NULL_TREE;
10493 : :
10494 : 186354 : if (current_object)
10495 : : {
10496 : 2307 : tree this_expr = TREE_OPERAND (current_object, 0);
10497 : :
10498 : 2307 : if (operand_equal_p (t, this_expr))
10499 : : {
10500 : 33 : data->this_expr_accessed = true;
10501 : 33 : *walk_subtrees = 0;
10502 : 33 : return NULL_TREE;
10503 : : }
10504 : :
10505 : 2274 : if (TREE_CODE (t) == COMPONENT_REF
10506 : 107 : && POINTER_TYPE_P (TREE_TYPE (t))
10507 : 34 : && operand_equal_p (TREE_OPERAND (t, 0), current_object)
10508 : 2308 : && TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL)
10509 : : {
10510 : 34 : data->this_expr_accessed = true;
10511 : 34 : tree fld = TREE_OPERAND (t, 1);
10512 : 34 : if (data->ptr_members_accessed.get (fld) == NULL)
10513 : : {
10514 : 14 : if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
10515 : 4 : t = convert_from_reference (t);
10516 : 14 : data->ptr_members_accessed.put (fld, t);
10517 : : }
10518 : 34 : *walk_subtrees = 0;
10519 : 34 : return NULL_TREE;
10520 : : }
10521 : : }
10522 : :
10523 : : /* When the current_function_decl is a lambda function, the closure object
10524 : : argument's type seems to not yet have fields layed out, so a recording
10525 : : of DECL_VALUE_EXPRs during the target body walk seems the only way to
10526 : : find them. */
10527 : 186287 : if (current_closure
10528 : 300 : && (VAR_P (t)
10529 : : || TREE_CODE (t) == PARM_DECL
10530 : : || TREE_CODE (t) == RESULT_DECL)
10531 : 24 : && DECL_HAS_VALUE_EXPR_P (t)
10532 : 10 : && TREE_CODE (DECL_VALUE_EXPR (t)) == COMPONENT_REF
10533 : 186297 : && operand_equal_p (current_closure,
10534 : 10 : TREE_OPERAND (DECL_VALUE_EXPR (t), 0)))
10535 : : {
10536 : 9 : if (!data->closure_vars_accessed.contains (t))
10537 : 9 : data->closure_vars_accessed.add (t);
10538 : 9 : *walk_subtrees = 0;
10539 : 9 : return NULL_TREE;
10540 : : }
10541 : :
10542 : 186278 : if (TREE_CODE (t) == BIND_EXPR)
10543 : : {
10544 : 18720 : tree block = BIND_EXPR_BLOCK (t);
10545 : 20503 : for (tree var = BLOCK_VARS (block); var; var = DECL_CHAIN (var))
10546 : 1783 : if (!data->local_decls.contains (var))
10547 : 1783 : data->local_decls.add (var);
10548 : 18720 : return NULL_TREE;
10549 : : }
10550 : :
10551 : 170194 : if (TREE_TYPE (t) && LAMBDA_TYPE_P (TREE_TYPE (t)))
10552 : : {
10553 : 17 : tree lt = TREE_TYPE (t);
10554 : 17 : gcc_assert (CLASS_TYPE_P (lt));
10555 : :
10556 : 17 : if (!data->lambda_objects_accessed.contains (t)
10557 : : /* Do not prepare to create target maps for locally declared
10558 : : lambdas or anonymous ones. */
10559 : 17 : && !data->local_decls.contains (t)
10560 : 32 : && TREE_CODE (t) != TARGET_EXPR)
10561 : 4 : data->lambda_objects_accessed.add (t);
10562 : 17 : *walk_subtrees = 0;
10563 : 17 : return NULL_TREE;
10564 : : }
10565 : :
10566 : : return NULL_TREE;
10567 : : }
10568 : :
10569 : : /* Helper function for finish_omp_target, and also from tsubst_expr.
10570 : : Create additional clauses for mapping of non-static members, lambda objects,
10571 : : etc. */
10572 : :
10573 : : void
10574 : 6300 : finish_omp_target_clauses (location_t loc, tree body, tree *clauses_ptr)
10575 : : {
10576 : 6300 : omp_target_walk_data data;
10577 : 6300 : data.this_expr_accessed = false;
10578 : 6300 : data.current_object = NULL_TREE;
10579 : :
10580 : 6300 : if (DECL_NONSTATIC_MEMBER_P (current_function_decl) && current_class_ptr)
10581 : 92 : if (tree ct = current_nonlambda_class_type ())
10582 : : {
10583 : 91 : tree object = maybe_dummy_object (ct, NULL);
10584 : 91 : object = maybe_resolve_dummy (object, true);
10585 : 91 : data.current_object = object;
10586 : : }
10587 : :
10588 : 6300 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
10589 : : {
10590 : 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
10591 : 8 : data.current_closure = build_indirect_ref (loc, closure, RO_UNARY_STAR);
10592 : : }
10593 : : else
10594 : 6292 : data.current_closure = NULL_TREE;
10595 : :
10596 : 6300 : cp_walk_tree_without_duplicates (&body, finish_omp_target_clauses_r, &data);
10597 : :
10598 : 6300 : auto_vec<tree, 16> new_clauses;
10599 : :
10600 : 6300 : tree omp_target_this_expr = NULL_TREE;
10601 : 6300 : tree *explicit_this_deref_map = NULL;
10602 : 6300 : if (data.this_expr_accessed)
10603 : : {
10604 : 29 : omp_target_this_expr = TREE_OPERAND (data.current_object, 0);
10605 : :
10606 : : /* See if explicit user-specified map(this[:]) clause already exists.
10607 : : If not, we create an implicit map(tofrom:this[:1]) clause. */
10608 : 71 : for (tree *cp = clauses_ptr; *cp; cp = &OMP_CLAUSE_CHAIN (*cp))
10609 : 43 : if (OMP_CLAUSE_CODE (*cp) == OMP_CLAUSE_MAP
10610 : 40 : && (TREE_CODE (OMP_CLAUSE_DECL (*cp)) == INDIRECT_REF
10611 : 35 : || TREE_CODE (OMP_CLAUSE_DECL (*cp)) == MEM_REF)
10612 : 48 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp), 0),
10613 : : omp_target_this_expr))
10614 : : {
10615 : : explicit_this_deref_map = cp;
10616 : : break;
10617 : : }
10618 : : }
10619 : :
10620 : 6300 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl)
10621 : 6300 : && (data.this_expr_accessed
10622 : 1 : || !data.closure_vars_accessed.is_empty ()))
10623 : : {
10624 : : /* For lambda functions, we need to first create a copy of the
10625 : : __closure object. */
10626 : 8 : tree closure = DECL_ARGUMENTS (current_function_decl);
10627 : 8 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10628 : 8 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
10629 : 8 : OMP_CLAUSE_DECL (c)
10630 : 8 : = build_indirect_ref (loc, closure, RO_UNARY_STAR);
10631 : 8 : OMP_CLAUSE_SIZE (c)
10632 : 8 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure)));
10633 : 8 : new_clauses.safe_push (c);
10634 : :
10635 : 8 : tree closure_obj = OMP_CLAUSE_DECL (c);
10636 : 8 : tree closure_type = TREE_TYPE (closure_obj);
10637 : :
10638 : 16 : gcc_assert (LAMBDA_TYPE_P (closure_type)
10639 : : && CLASS_TYPE_P (closure_type));
10640 : :
10641 : 8 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
10642 : 8 : OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
10643 : 8 : OMP_CLAUSE_DECL (c2) = closure;
10644 : 8 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
10645 : 8 : new_clauses.safe_push (c2);
10646 : : }
10647 : :
10648 : 6300 : if (data.this_expr_accessed)
10649 : : {
10650 : : /* If the this-expr was accessed, create a map(*this) clause. */
10651 : 29 : enum gomp_map_kind kind = GOMP_MAP_TOFROM;
10652 : 29 : if (explicit_this_deref_map)
10653 : : {
10654 : 1 : tree this_map = *explicit_this_deref_map;
10655 : 1 : tree nc = OMP_CLAUSE_CHAIN (this_map);
10656 : 2 : gcc_assert (nc != NULL_TREE
10657 : : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
10658 : : && (OMP_CLAUSE_MAP_KIND (nc)
10659 : : == GOMP_MAP_FIRSTPRIVATE_POINTER));
10660 : 1 : kind = OMP_CLAUSE_MAP_KIND (this_map);
10661 : : /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
10662 : : two-map sequence away from the chain. */
10663 : 1 : *explicit_this_deref_map = OMP_CLAUSE_CHAIN (nc);
10664 : : }
10665 : 29 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10666 : 29 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
10667 : 29 : OMP_CLAUSE_DECL (c)
10668 : 29 : = build_indirect_ref (loc, omp_target_this_expr, RO_UNARY_STAR);
10669 : 29 : OMP_CLAUSE_SIZE (c)
10670 : 29 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr)));
10671 : 29 : new_clauses.safe_push (c);
10672 : :
10673 : : /* If we're in a lambda function, the this-pointer will actually be
10674 : : '__closure->this', a mapped member of __closure, hence always_pointer.
10675 : : Otherwise it's a firstprivate pointer. */
10676 : 29 : enum gomp_map_kind ptr_kind
10677 : 29 : = (DECL_LAMBDA_FUNCTION_P (current_function_decl)
10678 : 29 : ? GOMP_MAP_ALWAYS_POINTER
10679 : 29 : : GOMP_MAP_FIRSTPRIVATE_POINTER);
10680 : 29 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10681 : 29 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
10682 : 29 : OMP_CLAUSE_DECL (c) = omp_target_this_expr;
10683 : 29 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10684 : 29 : new_clauses.safe_push (c);
10685 : : }
10686 : :
10687 : 6300 : if (DECL_LAMBDA_FUNCTION_P (current_function_decl))
10688 : : {
10689 : 8 : if (omp_target_this_expr)
10690 : : {
10691 : 7 : STRIP_NOPS (omp_target_this_expr);
10692 : 7 : gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr));
10693 : 7 : omp_target_this_expr = DECL_VALUE_EXPR (omp_target_this_expr);
10694 : : }
10695 : :
10696 : 17 : for (hash_set<tree>::iterator i = data.closure_vars_accessed.begin ();
10697 : 34 : i != data.closure_vars_accessed.end (); ++i)
10698 : : {
10699 : 9 : tree orig_decl = *i;
10700 : 9 : tree closure_expr = DECL_VALUE_EXPR (orig_decl);
10701 : :
10702 : 9 : if (TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE
10703 : 9 : || TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE)
10704 : : {
10705 : : /* this-pointer is processed above, outside this loop. */
10706 : 3 : if (omp_target_this_expr
10707 : 3 : && operand_equal_p (closure_expr, omp_target_this_expr))
10708 : 0 : continue;
10709 : :
10710 : 3 : bool ptr_p = TREE_CODE (TREE_TYPE (orig_decl)) == POINTER_TYPE;
10711 : 3 : enum gomp_map_kind kind, ptr_kind, nc_kind;
10712 : 3 : tree size;
10713 : :
10714 : 3 : if (ptr_p)
10715 : : {
10716 : : /* For pointers, default mapped as zero-length array
10717 : : section. */
10718 : 2 : kind = GOMP_MAP_ALLOC;
10719 : 2 : nc_kind = GOMP_MAP_FIRSTPRIVATE_POINTER;
10720 : 2 : ptr_kind = GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION;
10721 : 2 : size = size_zero_node;
10722 : : }
10723 : : else
10724 : : {
10725 : : /* For references, default mapped as appearing on map
10726 : : clause. */
10727 : 1 : kind = GOMP_MAP_TOFROM;
10728 : 1 : nc_kind = GOMP_MAP_FIRSTPRIVATE_REFERENCE;
10729 : 1 : ptr_kind = GOMP_MAP_ALWAYS_POINTER;
10730 : 1 : size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr)));
10731 : : }
10732 : :
10733 : 6 : for (tree *p = clauses_ptr; *p; p = &OMP_CLAUSE_CHAIN (*p))
10734 : 3 : if (OMP_CLAUSE_CODE (*p) == OMP_CLAUSE_MAP
10735 : 1 : && (TREE_CODE (OMP_CLAUSE_DECL (*p)) == INDIRECT_REF
10736 : 1 : || TREE_CODE (OMP_CLAUSE_DECL (*p)) == MEM_REF)
10737 : 3 : && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p), 0),
10738 : : orig_decl))
10739 : : {
10740 : : /* If this was already specified by user as a map,
10741 : : save the user specified map kind, delete the
10742 : : "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
10743 : : and insert our own sequence:
10744 : : "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
10745 : : */
10746 : 0 : tree nc = OMP_CLAUSE_CHAIN (*p);
10747 : 0 : gcc_assert (nc != NULL_TREE
10748 : : && OMP_CLAUSE_CODE (nc) == OMP_CLAUSE_MAP
10749 : : && OMP_CLAUSE_MAP_KIND (nc) == nc_kind);
10750 : : /* Update with user specified kind and size. */
10751 : 0 : kind = OMP_CLAUSE_MAP_KIND (*p);
10752 : 0 : size = OMP_CLAUSE_SIZE (*p);
10753 : 0 : *p = OMP_CLAUSE_CHAIN (nc);
10754 : 0 : break;
10755 : : }
10756 : :
10757 : 3 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10758 : 3 : OMP_CLAUSE_SET_MAP_KIND (c, kind);
10759 : 3 : OMP_CLAUSE_DECL (c)
10760 : 3 : = build_indirect_ref (loc, closure_expr, RO_UNARY_STAR);
10761 : 3 : OMP_CLAUSE_SIZE (c) = size;
10762 : 3 : if (ptr_p)
10763 : 2 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
10764 : 3 : new_clauses.safe_push (c);
10765 : :
10766 : 3 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10767 : 3 : OMP_CLAUSE_SET_MAP_KIND (c, ptr_kind);
10768 : 3 : OMP_CLAUSE_DECL (c) = closure_expr;
10769 : 3 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10770 : 3 : new_clauses.safe_push (c);
10771 : : }
10772 : : }
10773 : : }
10774 : :
10775 : 6300 : if (!data.ptr_members_accessed.is_empty ())
10776 : 14 : for (hash_map<tree, tree>::iterator i = data.ptr_members_accessed.begin ();
10777 : 56 : i != data.ptr_members_accessed.end (); ++i)
10778 : : {
10779 : : /* For each referenced member that is of pointer or reference-to-pointer
10780 : : type, create the equivalent of map(alloc:this->ptr[:0]). */
10781 : 14 : tree field_decl = (*i).first;
10782 : 14 : tree ptr_member = (*i).second;
10783 : :
10784 : 26 : for (tree c = *clauses_ptr; c; c = OMP_CLAUSE_CHAIN (c))
10785 : : {
10786 : 16 : if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
10787 : 2 : continue;
10788 : : /* If map(this->ptr[:N]) already exists, avoid creating another
10789 : : such map. */
10790 : 14 : tree decl = OMP_CLAUSE_DECL (c);
10791 : 14 : if ((TREE_CODE (decl) == INDIRECT_REF
10792 : 10 : || TREE_CODE (decl) == MEM_REF)
10793 : 14 : && operand_equal_p (TREE_OPERAND (decl, 0), ptr_member))
10794 : 4 : goto next_ptr_member;
10795 : : }
10796 : :
10797 : 10 : if (!cxx_mark_addressable (ptr_member))
10798 : 0 : gcc_unreachable ();
10799 : :
10800 : 10 : if (TREE_CODE (TREE_TYPE (field_decl)) == REFERENCE_TYPE)
10801 : : {
10802 : : /* For reference to pointers, we need to map the referenced
10803 : : pointer first for things to be correct. */
10804 : 4 : tree ptr_member_type = TREE_TYPE (ptr_member);
10805 : :
10806 : : /* Map pointer target as zero-length array section. */
10807 : 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10808 : 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
10809 : 4 : OMP_CLAUSE_DECL (c)
10810 : 4 : = build1 (INDIRECT_REF, TREE_TYPE (ptr_member_type), ptr_member);
10811 : 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10812 : 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
10813 : :
10814 : : /* Map pointer to zero-length array section. */
10815 : 4 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
10816 : 4 : OMP_CLAUSE_SET_MAP_KIND
10817 : : (c2, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION);
10818 : 4 : OMP_CLAUSE_DECL (c2) = ptr_member;
10819 : 4 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
10820 : :
10821 : : /* Attach reference-to-pointer field to pointer. */
10822 : 4 : tree c3 = build_omp_clause (loc, OMP_CLAUSE_MAP);
10823 : 4 : OMP_CLAUSE_SET_MAP_KIND (c3, GOMP_MAP_ATTACH);
10824 : 4 : OMP_CLAUSE_DECL (c3) = TREE_OPERAND (ptr_member, 0);
10825 : 4 : OMP_CLAUSE_SIZE (c3) = size_zero_node;
10826 : :
10827 : 4 : new_clauses.safe_push (c);
10828 : 4 : new_clauses.safe_push (c2);
10829 : 4 : new_clauses.safe_push (c3);
10830 : : }
10831 : 6 : else if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
10832 : : {
10833 : : /* Map pointer target as zero-length array section. */
10834 : 6 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10835 : 6 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
10836 : 6 : OMP_CLAUSE_DECL (c) = build_indirect_ref (loc, ptr_member,
10837 : : RO_UNARY_STAR);
10838 : 6 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10839 : 6 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
10840 : :
10841 : : /* Attach zero-length array section to pointer. */
10842 : 6 : tree c2 = build_omp_clause (loc, OMP_CLAUSE_MAP);
10843 : 6 : OMP_CLAUSE_SET_MAP_KIND
10844 : : (c2, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
10845 : 6 : OMP_CLAUSE_DECL (c2) = ptr_member;
10846 : 6 : OMP_CLAUSE_SIZE (c2) = size_zero_node;
10847 : :
10848 : 6 : new_clauses.safe_push (c);
10849 : 6 : new_clauses.safe_push (c2);
10850 : : }
10851 : : else
10852 : 0 : gcc_unreachable ();
10853 : :
10854 : 14 : next_ptr_member:
10855 : 14 : ;
10856 : : }
10857 : :
10858 : 6304 : for (hash_set<tree>::iterator i = data.lambda_objects_accessed.begin ();
10859 : 6308 : i != data.lambda_objects_accessed.end (); ++i)
10860 : : {
10861 : 4 : tree lobj = *i;
10862 : 4 : if (TREE_CODE (lobj) == TARGET_EXPR)
10863 : 0 : lobj = TARGET_EXPR_SLOT (lobj);
10864 : :
10865 : 4 : tree lt = TREE_TYPE (lobj);
10866 : 8 : gcc_assert (LAMBDA_TYPE_P (lt) && CLASS_TYPE_P (lt));
10867 : :
10868 : 4 : tree lc = build_omp_clause (loc, OMP_CLAUSE_MAP);
10869 : 4 : OMP_CLAUSE_SET_MAP_KIND (lc, GOMP_MAP_TO);
10870 : 4 : OMP_CLAUSE_DECL (lc) = lobj;
10871 : 4 : OMP_CLAUSE_SIZE (lc) = TYPE_SIZE_UNIT (lt);
10872 : 4 : new_clauses.safe_push (lc);
10873 : :
10874 : 50 : for (tree fld = TYPE_FIELDS (lt); fld; fld = DECL_CHAIN (fld))
10875 : : {
10876 : 46 : if (TREE_CODE (TREE_TYPE (fld)) == POINTER_TYPE)
10877 : : {
10878 : 4 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
10879 : : lobj, fld, NULL_TREE);
10880 : 4 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10881 : 4 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALLOC);
10882 : 4 : OMP_CLAUSE_DECL (c)
10883 : 4 : = build_indirect_ref (loc, exp, RO_UNARY_STAR);
10884 : 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10885 : 4 : OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
10886 : 4 : new_clauses.safe_push (c);
10887 : :
10888 : 4 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10889 : 4 : OMP_CLAUSE_SET_MAP_KIND
10890 : : (c, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION);
10891 : 4 : OMP_CLAUSE_DECL (c) = exp;
10892 : 4 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10893 : 4 : new_clauses.safe_push (c);
10894 : : }
10895 : 42 : else if (TREE_CODE (TREE_TYPE (fld)) == REFERENCE_TYPE)
10896 : : {
10897 : 0 : tree exp = build3 (COMPONENT_REF, TREE_TYPE (fld),
10898 : : lobj, fld, NULL_TREE);
10899 : 0 : tree c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10900 : 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
10901 : 0 : OMP_CLAUSE_DECL (c)
10902 : 0 : = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (exp)), exp);
10903 : 0 : OMP_CLAUSE_SIZE (c)
10904 : 0 : = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp)));
10905 : 0 : new_clauses.safe_push (c);
10906 : :
10907 : 0 : c = build_omp_clause (loc, OMP_CLAUSE_MAP);
10908 : 0 : OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_ALWAYS_POINTER);
10909 : 0 : OMP_CLAUSE_DECL (c) = exp;
10910 : 0 : OMP_CLAUSE_SIZE (c) = size_zero_node;
10911 : 0 : new_clauses.safe_push (c);
10912 : : }
10913 : : }
10914 : : }
10915 : :
10916 : 6300 : tree c = *clauses_ptr;
10917 : 12716 : for (int i = new_clauses.length () - 1; i >= 0; i--)
10918 : : {
10919 : 116 : OMP_CLAUSE_CHAIN (new_clauses[i]) = c;
10920 : 116 : c = new_clauses[i];
10921 : : }
10922 : 6300 : *clauses_ptr = c;
10923 : 6300 : }
10924 : :
10925 : : /* Called from cp_parser_omp_target. Create additional implicit clauses for
10926 : : OpenMP target directives, and do sanity checks. */
10927 : :
10928 : : tree
10929 : 6292 : finish_omp_target (location_t loc, tree clauses, tree body, bool combined_p)
10930 : : {
10931 : 6292 : if (!processing_template_decl)
10932 : 5522 : finish_omp_target_clauses (loc, body, &clauses);
10933 : :
10934 : 6292 : tree stmt = make_node (OMP_TARGET);
10935 : 6292 : TREE_TYPE (stmt) = void_type_node;
10936 : 6292 : OMP_TARGET_CLAUSES (stmt) = clauses;
10937 : 6292 : OMP_TARGET_BODY (stmt) = body;
10938 : 6292 : OMP_TARGET_COMBINED (stmt) = combined_p;
10939 : 6292 : SET_EXPR_LOCATION (stmt, loc);
10940 : :
10941 : 6292 : tree c = clauses;
10942 : 14926 : while (c)
10943 : : {
10944 : 8634 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
10945 : 4900 : switch (OMP_CLAUSE_MAP_KIND (c))
10946 : : {
10947 : : case GOMP_MAP_TO:
10948 : : case GOMP_MAP_ALWAYS_TO:
10949 : : case GOMP_MAP_PRESENT_TO:
10950 : : case GOMP_MAP_ALWAYS_PRESENT_TO:
10951 : : case GOMP_MAP_FROM:
10952 : : case GOMP_MAP_ALWAYS_FROM:
10953 : : case GOMP_MAP_PRESENT_FROM:
10954 : : case GOMP_MAP_ALWAYS_PRESENT_FROM:
10955 : : case GOMP_MAP_TOFROM:
10956 : : case GOMP_MAP_ALWAYS_TOFROM:
10957 : : case GOMP_MAP_PRESENT_TOFROM:
10958 : : case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
10959 : : case GOMP_MAP_ALLOC:
10960 : : case GOMP_MAP_PRESENT_ALLOC:
10961 : : case GOMP_MAP_FIRSTPRIVATE_POINTER:
10962 : : case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
10963 : : case GOMP_MAP_ALWAYS_POINTER:
10964 : : case GOMP_MAP_ATTACH_DETACH:
10965 : : case GOMP_MAP_ATTACH:
10966 : : case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION:
10967 : : case GOMP_MAP_POINTER:
10968 : : case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION:
10969 : : break;
10970 : 3 : default:
10971 : 3 : error_at (OMP_CLAUSE_LOCATION (c),
10972 : : "%<#pragma omp target%> with map-type other "
10973 : : "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
10974 : : "on %<map%> clause");
10975 : 3 : break;
10976 : : }
10977 : 8634 : c = OMP_CLAUSE_CHAIN (c);
10978 : : }
10979 : 6292 : return add_stmt (stmt);
10980 : : }
10981 : :
10982 : : tree
10983 : 9362 : finish_omp_parallel (tree clauses, tree body)
10984 : : {
10985 : 9362 : tree stmt;
10986 : :
10987 : 9362 : body = finish_omp_structured_block (body);
10988 : :
10989 : 9362 : stmt = make_node (OMP_PARALLEL);
10990 : 9362 : TREE_TYPE (stmt) = void_type_node;
10991 : 9362 : OMP_PARALLEL_CLAUSES (stmt) = clauses;
10992 : 9362 : OMP_PARALLEL_BODY (stmt) = body;
10993 : :
10994 : 9362 : return add_stmt (stmt);
10995 : : }
10996 : :
10997 : : tree
10998 : 2330 : begin_omp_task (void)
10999 : : {
11000 : 2330 : keep_next_level (true);
11001 : 2330 : return begin_omp_structured_block ();
11002 : : }
11003 : :
11004 : : tree
11005 : 2330 : finish_omp_task (tree clauses, tree body)
11006 : : {
11007 : 2330 : tree stmt;
11008 : :
11009 : 2330 : body = finish_omp_structured_block (body);
11010 : :
11011 : 2330 : stmt = make_node (OMP_TASK);
11012 : 2330 : TREE_TYPE (stmt) = void_type_node;
11013 : 2330 : OMP_TASK_CLAUSES (stmt) = clauses;
11014 : 2330 : OMP_TASK_BODY (stmt) = body;
11015 : :
11016 : 2330 : return add_stmt (stmt);
11017 : : }
11018 : :
11019 : : /* Helper function for finish_omp_for. Convert Ith random access iterator
11020 : : into integral iterator. Return FALSE if successful. */
11021 : :
11022 : : static bool
11023 : 813 : handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
11024 : : tree declv, tree orig_declv, tree initv,
11025 : : tree condv, tree incrv, tree *body,
11026 : : tree *pre_body, tree &clauses,
11027 : : int collapse, int ordered)
11028 : : {
11029 : 813 : tree diff, iter_init, iter_incr = NULL, last;
11030 : 813 : tree incr_var = NULL, orig_pre_body, orig_body, c;
11031 : 813 : tree decl = TREE_VEC_ELT (declv, i);
11032 : 813 : tree init = TREE_VEC_ELT (initv, i);
11033 : 813 : tree cond = TREE_VEC_ELT (condv, i);
11034 : 813 : tree incr = TREE_VEC_ELT (incrv, i);
11035 : 813 : tree iter = decl;
11036 : 813 : location_t elocus = locus;
11037 : :
11038 : 813 : if (init && EXPR_HAS_LOCATION (init))
11039 : 12 : elocus = EXPR_LOCATION (init);
11040 : :
11041 : 813 : switch (TREE_CODE (cond))
11042 : : {
11043 : 810 : case GT_EXPR:
11044 : 810 : case GE_EXPR:
11045 : 810 : case LT_EXPR:
11046 : 810 : case LE_EXPR:
11047 : 810 : case NE_EXPR:
11048 : 810 : if (TREE_OPERAND (cond, 1) == iter)
11049 : 42 : cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
11050 : 42 : TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
11051 : 810 : if (TREE_OPERAND (cond, 0) != iter)
11052 : 0 : cond = error_mark_node;
11053 : : else
11054 : : {
11055 : 810 : tree tem = build_x_binary_op (EXPR_LOCATION (cond),
11056 : 810 : TREE_CODE (cond),
11057 : : iter, ERROR_MARK,
11058 : 810 : TREE_OPERAND (cond, 1), ERROR_MARK,
11059 : : NULL_TREE, NULL, tf_warning_or_error);
11060 : 810 : if (error_operand_p (tem))
11061 : : return true;
11062 : : }
11063 : : break;
11064 : 3 : default:
11065 : 3 : cond = error_mark_node;
11066 : 3 : break;
11067 : : }
11068 : 810 : if (cond == error_mark_node)
11069 : : {
11070 : 3 : error_at (elocus, "invalid controlling predicate");
11071 : 3 : return true;
11072 : : }
11073 : 807 : diff = build_x_binary_op (elocus, MINUS_EXPR,
11074 : 807 : TREE_OPERAND (cond, 1), ERROR_MARK,
11075 : : iter, ERROR_MARK,
11076 : : NULL_TREE, NULL, tf_warning_or_error);
11077 : 807 : diff = cp_fully_fold (diff);
11078 : 807 : if (error_operand_p (diff))
11079 : : return true;
11080 : 807 : if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
11081 : : {
11082 : 0 : error_at (elocus, "difference between %qE and %qD does not have integer type",
11083 : 0 : TREE_OPERAND (cond, 1), iter);
11084 : 0 : return true;
11085 : : }
11086 : 807 : if (!c_omp_check_loop_iv_exprs (locus, code, orig_declv, i,
11087 : 807 : TREE_VEC_ELT (declv, i), NULL_TREE,
11088 : : cond, cp_walk_subtrees))
11089 : : return true;
11090 : :
11091 : 762 : switch (TREE_CODE (incr))
11092 : : {
11093 : 370 : case PREINCREMENT_EXPR:
11094 : 370 : case PREDECREMENT_EXPR:
11095 : 370 : case POSTINCREMENT_EXPR:
11096 : 370 : case POSTDECREMENT_EXPR:
11097 : 370 : if (TREE_OPERAND (incr, 0) != iter)
11098 : : {
11099 : 0 : incr = error_mark_node;
11100 : 0 : break;
11101 : : }
11102 : 370 : iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
11103 : : TREE_CODE (incr), iter,
11104 : : NULL_TREE, tf_warning_or_error);
11105 : 370 : if (error_operand_p (iter_incr))
11106 : : return true;
11107 : 370 : else if (TREE_CODE (incr) == PREINCREMENT_EXPR
11108 : 219 : || TREE_CODE (incr) == POSTINCREMENT_EXPR)
11109 : 299 : incr = integer_one_node;
11110 : : else
11111 : 71 : incr = integer_minus_one_node;
11112 : : break;
11113 : 392 : case MODIFY_EXPR:
11114 : 392 : if (TREE_OPERAND (incr, 0) != iter)
11115 : 0 : incr = error_mark_node;
11116 : 392 : else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
11117 : 392 : || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
11118 : : {
11119 : 392 : tree rhs = TREE_OPERAND (incr, 1);
11120 : 392 : if (TREE_OPERAND (rhs, 0) == iter)
11121 : : {
11122 : 299 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
11123 : : != INTEGER_TYPE)
11124 : 0 : incr = error_mark_node;
11125 : : else
11126 : : {
11127 : 299 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11128 : 299 : iter, TREE_CODE (rhs),
11129 : 299 : TREE_OPERAND (rhs, 1),
11130 : : NULL_TREE,
11131 : : tf_warning_or_error);
11132 : 299 : if (error_operand_p (iter_incr))
11133 : : return true;
11134 : 299 : incr = TREE_OPERAND (rhs, 1);
11135 : 299 : incr = cp_convert (TREE_TYPE (diff), incr,
11136 : : tf_warning_or_error);
11137 : 299 : if (TREE_CODE (rhs) == MINUS_EXPR)
11138 : : {
11139 : 16 : incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
11140 : 16 : incr = fold_simple (incr);
11141 : : }
11142 : 299 : if (TREE_CODE (incr) != INTEGER_CST
11143 : 299 : && (TREE_CODE (incr) != NOP_EXPR
11144 : 66 : || (TREE_CODE (TREE_OPERAND (incr, 0))
11145 : : != INTEGER_CST)))
11146 : : iter_incr = NULL;
11147 : : }
11148 : : }
11149 : 93 : else if (TREE_OPERAND (rhs, 1) == iter)
11150 : : {
11151 : 93 : if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
11152 : 93 : || TREE_CODE (rhs) != PLUS_EXPR)
11153 : 0 : incr = error_mark_node;
11154 : : else
11155 : : {
11156 : 93 : iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
11157 : : PLUS_EXPR,
11158 : 93 : TREE_OPERAND (rhs, 0),
11159 : : ERROR_MARK, iter,
11160 : : ERROR_MARK, NULL_TREE, NULL,
11161 : : tf_warning_or_error);
11162 : 93 : if (error_operand_p (iter_incr))
11163 : : return true;
11164 : 93 : iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
11165 : : iter, NOP_EXPR,
11166 : : iter_incr, NULL_TREE,
11167 : : tf_warning_or_error);
11168 : 93 : if (error_operand_p (iter_incr))
11169 : : return true;
11170 : 93 : incr = TREE_OPERAND (rhs, 0);
11171 : 93 : iter_incr = NULL;
11172 : : }
11173 : : }
11174 : : else
11175 : 0 : incr = error_mark_node;
11176 : : }
11177 : : else
11178 : 0 : incr = error_mark_node;
11179 : : break;
11180 : 0 : default:
11181 : 0 : incr = error_mark_node;
11182 : 0 : break;
11183 : : }
11184 : :
11185 : 762 : if (incr == error_mark_node)
11186 : : {
11187 : 0 : error_at (elocus, "invalid increment expression");
11188 : 0 : return true;
11189 : : }
11190 : :
11191 : 762 : incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
11192 : 762 : incr = cp_fully_fold (incr);
11193 : 762 : tree loop_iv_seen = NULL_TREE;
11194 : 1735 : for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
11195 : 1093 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
11196 : 1093 : && OMP_CLAUSE_DECL (c) == iter)
11197 : : {
11198 : 120 : if (code == OMP_TASKLOOP || code == OMP_LOOP)
11199 : : {
11200 : 60 : loop_iv_seen = c;
11201 : 60 : OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c) = 1;
11202 : : }
11203 : : break;
11204 : : }
11205 : 973 : else if ((code == OMP_TASKLOOP || code == OMP_LOOP)
11206 : 113 : && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
11207 : 1007 : && OMP_CLAUSE_DECL (c) == iter)
11208 : : {
11209 : 30 : loop_iv_seen = c;
11210 : 30 : if (code == OMP_TASKLOOP)
11211 : 25 : OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
11212 : : }
11213 : :
11214 : 762 : decl = create_temporary_var (TREE_TYPE (diff));
11215 : 762 : pushdecl (decl);
11216 : 762 : add_decl_expr (decl);
11217 : 762 : last = create_temporary_var (TREE_TYPE (diff));
11218 : 762 : pushdecl (last);
11219 : 762 : add_decl_expr (last);
11220 : 762 : if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
11221 : 10 : && (!ordered || (i < collapse && collapse > 1)))
11222 : : {
11223 : 10 : incr_var = create_temporary_var (TREE_TYPE (diff));
11224 : 10 : pushdecl (incr_var);
11225 : 10 : add_decl_expr (incr_var);
11226 : : }
11227 : 762 : gcc_assert (stmts_are_full_exprs_p ());
11228 : 762 : tree diffvar = NULL_TREE;
11229 : 762 : if (code == OMP_TASKLOOP)
11230 : : {
11231 : 101 : if (!loop_iv_seen)
11232 : : {
11233 : 38 : tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11234 : 38 : OMP_CLAUSE_DECL (ivc) = iter;
11235 : 38 : cxx_omp_finish_clause (ivc, NULL, false);
11236 : 38 : OMP_CLAUSE_CHAIN (ivc) = clauses;
11237 : 38 : clauses = ivc;
11238 : : }
11239 : 101 : tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11240 : 101 : OMP_CLAUSE_DECL (lvc) = last;
11241 : 101 : OMP_CLAUSE_CHAIN (lvc) = clauses;
11242 : 101 : clauses = lvc;
11243 : 101 : diffvar = create_temporary_var (TREE_TYPE (diff));
11244 : 101 : pushdecl (diffvar);
11245 : 101 : add_decl_expr (diffvar);
11246 : : }
11247 : 661 : else if (code == OMP_LOOP)
11248 : : {
11249 : 43 : if (!loop_iv_seen)
11250 : : {
11251 : : /* While iterators on the loop construct are predetermined
11252 : : lastprivate, if the decl is not declared inside of the
11253 : : loop, OMP_CLAUSE_LASTPRIVATE should have been added
11254 : : already. */
11255 : 16 : loop_iv_seen = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
11256 : 16 : OMP_CLAUSE_DECL (loop_iv_seen) = iter;
11257 : 16 : OMP_CLAUSE_CHAIN (loop_iv_seen) = clauses;
11258 : 16 : clauses = loop_iv_seen;
11259 : : }
11260 : 27 : else if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_PRIVATE)
11261 : : {
11262 : 5 : OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen) = 0;
11263 : 5 : OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen) = 0;
11264 : 5 : OMP_CLAUSE_CODE (loop_iv_seen) = OMP_CLAUSE_FIRSTPRIVATE;
11265 : : }
11266 : 43 : if (OMP_CLAUSE_CODE (loop_iv_seen) == OMP_CLAUSE_FIRSTPRIVATE)
11267 : 21 : cxx_omp_finish_clause (loop_iv_seen, NULL, false);
11268 : : }
11269 : :
11270 : 762 : orig_pre_body = *pre_body;
11271 : 762 : *pre_body = push_stmt_list ();
11272 : 762 : if (orig_pre_body)
11273 : 610 : add_stmt (orig_pre_body);
11274 : 762 : if (init != NULL)
11275 : 61 : finish_expr_stmt (build_x_modify_expr (elocus,
11276 : : iter, NOP_EXPR, init,
11277 : : NULL_TREE, tf_warning_or_error));
11278 : 762 : init = build_int_cst (TREE_TYPE (diff), 0);
11279 : 762 : if (c && iter_incr == NULL
11280 : 28 : && (!ordered || (i < collapse && collapse > 1)))
11281 : : {
11282 : 28 : if (incr_var)
11283 : : {
11284 : 10 : finish_expr_stmt (build_x_modify_expr (elocus,
11285 : : incr_var, NOP_EXPR,
11286 : : incr, NULL_TREE,
11287 : : tf_warning_or_error));
11288 : 10 : incr = incr_var;
11289 : : }
11290 : 28 : iter_incr = build_x_modify_expr (elocus,
11291 : : iter, PLUS_EXPR, incr,
11292 : : NULL_TREE, tf_warning_or_error);
11293 : : }
11294 : 762 : if (c && ordered && i < collapse && collapse > 1)
11295 : 762 : iter_incr = incr;
11296 : 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11297 : : last, NOP_EXPR, init,
11298 : : NULL_TREE, tf_warning_or_error));
11299 : 762 : if (diffvar)
11300 : : {
11301 : 101 : finish_expr_stmt (build_x_modify_expr (elocus,
11302 : : diffvar, NOP_EXPR,
11303 : : diff, NULL_TREE, tf_warning_or_error));
11304 : 101 : diff = diffvar;
11305 : : }
11306 : 762 : *pre_body = pop_stmt_list (*pre_body);
11307 : :
11308 : 1524 : cond = cp_build_binary_op (elocus,
11309 : 762 : TREE_CODE (cond), decl, diff,
11310 : : tf_warning_or_error);
11311 : 762 : incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
11312 : : elocus, incr, NULL_TREE);
11313 : :
11314 : 762 : orig_body = *body;
11315 : 762 : *body = push_stmt_list ();
11316 : 762 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
11317 : 762 : iter_init = build_x_modify_expr (elocus,
11318 : : iter, PLUS_EXPR, iter_init,
11319 : : NULL_TREE, tf_warning_or_error);
11320 : 762 : if (iter_init != error_mark_node)
11321 : 759 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11322 : 762 : finish_expr_stmt (iter_init);
11323 : 762 : finish_expr_stmt (build_x_modify_expr (elocus,
11324 : : last, NOP_EXPR, decl,
11325 : : NULL_TREE, tf_warning_or_error));
11326 : 762 : add_stmt (orig_body);
11327 : 762 : *body = pop_stmt_list (*body);
11328 : :
11329 : 762 : if (c)
11330 : : {
11331 : 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
11332 : 120 : if (!ordered)
11333 : 114 : finish_expr_stmt (iter_incr);
11334 : : else
11335 : : {
11336 : 6 : iter_init = decl;
11337 : 6 : if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
11338 : 2 : iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
11339 : : iter_init, iter_incr);
11340 : 6 : iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
11341 : 6 : iter_init = build_x_modify_expr (elocus,
11342 : : iter, PLUS_EXPR, iter_init,
11343 : : NULL_TREE, tf_warning_or_error);
11344 : 6 : if (iter_init != error_mark_node)
11345 : 6 : iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
11346 : 6 : finish_expr_stmt (iter_init);
11347 : : }
11348 : 120 : OMP_CLAUSE_LASTPRIVATE_STMT (c)
11349 : 240 : = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
11350 : : }
11351 : :
11352 : 762 : if (TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST)
11353 : : {
11354 : 116 : tree t = TREE_VEC_ELT (orig_declv, i);
11355 : 116 : gcc_assert (TREE_PURPOSE (t) == NULL_TREE
11356 : : && TREE_VALUE (t) == NULL_TREE
11357 : : && TREE_CODE (TREE_CHAIN (t)) == TREE_VEC);
11358 : 116 : TREE_PURPOSE (t) = TREE_VEC_ELT (declv, i);
11359 : 116 : TREE_VALUE (t) = last;
11360 : : }
11361 : : else
11362 : 646 : TREE_VEC_ELT (orig_declv, i)
11363 : 1292 : = tree_cons (TREE_VEC_ELT (declv, i), last, NULL_TREE);
11364 : 762 : TREE_VEC_ELT (declv, i) = decl;
11365 : 762 : TREE_VEC_ELT (initv, i) = init;
11366 : 762 : TREE_VEC_ELT (condv, i) = cond;
11367 : 762 : TREE_VEC_ELT (incrv, i) = incr;
11368 : :
11369 : 762 : return false;
11370 : : }
11371 : :
11372 : : /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
11373 : : are directly for their associated operands in the statement. DECL
11374 : : and INIT are a combo; if DECL is NULL then INIT ought to be a
11375 : : MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
11376 : : optional statements that need to go before the loop into its
11377 : : sk_omp scope. */
11378 : :
11379 : : tree
11380 : 21147 : finish_omp_for (location_t locus, enum tree_code code, tree declv,
11381 : : tree orig_declv, tree initv, tree condv, tree incrv,
11382 : : tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
11383 : : {
11384 : 21147 : tree omp_for = NULL, orig_incr = NULL;
11385 : 21147 : tree decl = NULL, init, cond, incr;
11386 : 21147 : location_t elocus;
11387 : 21147 : int i;
11388 : 21147 : int collapse = 1;
11389 : 21147 : int ordered = 0;
11390 : 21147 : auto_vec<location_t> init_locv;
11391 : :
11392 : 21147 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
11393 : 21147 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
11394 : 21147 : gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
11395 : 21147 : if (TREE_VEC_LENGTH (declv) > 1)
11396 : : {
11397 : 4026 : if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
11398 : 83 : collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
11399 : : else
11400 : : {
11401 : 3943 : if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
11402 : 3473 : collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
11403 : 470 : else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
11404 : 394 : collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
11405 : 3943 : if (collapse != TREE_VEC_LENGTH (declv))
11406 : 100 : ordered = TREE_VEC_LENGTH (declv);
11407 : : }
11408 : : }
11409 : 48608 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
11410 : : {
11411 : 27497 : decl = TREE_VEC_ELT (declv, i);
11412 : 27497 : init = TREE_VEC_ELT (initv, i);
11413 : 27497 : cond = TREE_VEC_ELT (condv, i);
11414 : 27497 : incr = TREE_VEC_ELT (incrv, i);
11415 : 27497 : elocus = locus;
11416 : :
11417 : 27497 : if (decl == global_namespace)
11418 : : {
11419 : 1101 : gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
11420 : 1101 : TREE_VEC_ELT (declv, i) = NULL_TREE;
11421 : 1101 : init_locv.safe_push (UNKNOWN_LOCATION);
11422 : 1101 : continue;
11423 : : }
11424 : : /* We are going to throw out the init's original MODIFY_EXPR or
11425 : : MODOP_EXPR below. Save its location so we can use it when
11426 : : reconstructing the expression farther down. Alternatively, if the
11427 : : initializer is a binding of the iteration variable, save
11428 : : that location. Any of these locations in the initialization clause
11429 : : for the current nested loop are better than using the argument locus,
11430 : : that points to the "for" of the outermost loop in the nest. */
11431 : 26396 : if (init && EXPR_HAS_LOCATION (init))
11432 : 17895 : elocus = EXPR_LOCATION (init);
11433 : 8501 : else if (decl && INDIRECT_REF_P (decl) && EXPR_HAS_LOCATION (decl))
11434 : : /* This can happen for class iterators. */
11435 : 0 : elocus = EXPR_LOCATION (decl);
11436 : 8501 : else if (decl && DECL_P (decl))
11437 : : {
11438 : 8474 : if (DECL_SOURCE_LOCATION (decl) != UNKNOWN_LOCATION)
11439 : 8474 : elocus = DECL_SOURCE_LOCATION (decl);
11440 : 0 : else if (DECL_INITIAL (decl)
11441 : 0 : && EXPR_HAS_LOCATION (DECL_INITIAL (decl)))
11442 : 0 : elocus = EXPR_LOCATION (DECL_INITIAL (decl));
11443 : : }
11444 : 26396 : init_locv.safe_push (elocus);
11445 : :
11446 : 26396 : if (decl == NULL)
11447 : : {
11448 : 16583 : if (init != NULL)
11449 : 16580 : switch (TREE_CODE (init))
11450 : : {
11451 : 16173 : case MODIFY_EXPR:
11452 : 16173 : decl = TREE_OPERAND (init, 0);
11453 : 16173 : init = TREE_OPERAND (init, 1);
11454 : 16173 : break;
11455 : 389 : case MODOP_EXPR:
11456 : 389 : if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
11457 : : {
11458 : 389 : decl = TREE_OPERAND (init, 0);
11459 : 389 : init = TREE_OPERAND (init, 2);
11460 : : }
11461 : : break;
11462 : : default:
11463 : : break;
11464 : : }
11465 : :
11466 : 16583 : if (decl == NULL)
11467 : : {
11468 : 21 : error_at (locus,
11469 : : "expected iteration declaration or initialization");
11470 : 21 : return NULL;
11471 : : }
11472 : : }
11473 : :
11474 : 26375 : if (cond == global_namespace)
11475 : 170 : continue;
11476 : :
11477 : 26205 : if (cond == NULL)
11478 : : {
11479 : 9 : error_at (elocus, "missing controlling predicate");
11480 : 9 : return NULL;
11481 : : }
11482 : :
11483 : 26196 : if (incr == NULL)
11484 : : {
11485 : 6 : error_at (elocus, "missing increment expression");
11486 : 6 : return NULL;
11487 : : }
11488 : :
11489 : 26190 : TREE_VEC_ELT (declv, i) = decl;
11490 : 26190 : TREE_VEC_ELT (initv, i) = init;
11491 : : }
11492 : :
11493 : 21111 : if (orig_inits)
11494 : : {
11495 : : bool fail = false;
11496 : : tree orig_init;
11497 : 21219 : FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
11498 : 1181 : if (orig_init
11499 : 3396 : && !c_omp_check_loop_iv_exprs (locus, code,
11500 : : orig_declv ? orig_declv : declv, i,
11501 : 1164 : TREE_VEC_ELT (declv, i), orig_init,
11502 : : NULL_TREE, cp_walk_subtrees))
11503 : : fail = true;
11504 : 20038 : if (fail)
11505 : 887 : return NULL;
11506 : : }
11507 : :
11508 : 21054 : if (dependent_omp_for_p (declv, initv, condv, incrv, body))
11509 : : {
11510 : 453 : tree stmt;
11511 : :
11512 : 453 : stmt = make_node (code);
11513 : :
11514 : 1499 : for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
11515 : : {
11516 : 593 : if (TREE_VEC_ELT (declv, i) == NULL_TREE)
11517 : 9 : continue;
11518 : : /* This is really just a place-holder. We'll be decomposing this
11519 : : again and going through the cp_build_modify_expr path below when
11520 : : we instantiate the thing. */
11521 : 584 : TREE_VEC_ELT (initv, i)
11522 : 1168 : = build2_loc (init_locv[i], MODIFY_EXPR, void_type_node,
11523 : 584 : TREE_VEC_ELT (declv, i), TREE_VEC_ELT (initv, i));
11524 : : }
11525 : :
11526 : 453 : TREE_TYPE (stmt) = void_type_node;
11527 : 453 : OMP_FOR_INIT (stmt) = initv;
11528 : 453 : OMP_FOR_COND (stmt) = condv;
11529 : 453 : OMP_FOR_INCR (stmt) = incrv;
11530 : 453 : OMP_FOR_BODY (stmt) = body;
11531 : 453 : OMP_FOR_PRE_BODY (stmt) = pre_body;
11532 : 453 : OMP_FOR_CLAUSES (stmt) = clauses;
11533 : :
11534 : 453 : SET_EXPR_LOCATION (stmt, locus);
11535 : 453 : return add_stmt (stmt);
11536 : : }
11537 : :
11538 : 20601 : if (!orig_declv)
11539 : 19800 : orig_declv = copy_node (declv);
11540 : :
11541 : 20601 : if (processing_template_decl)
11542 : 627 : orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
11543 : :
11544 : 48037 : for (i = 0; i < TREE_VEC_LENGTH (declv); )
11545 : : {
11546 : 27528 : decl = TREE_VEC_ELT (declv, i);
11547 : 27528 : init = TREE_VEC_ELT (initv, i);
11548 : 27528 : cond = TREE_VEC_ELT (condv, i);
11549 : 27528 : incr = TREE_VEC_ELT (incrv, i);
11550 : 27528 : if (orig_incr)
11551 : 856 : TREE_VEC_ELT (orig_incr, i) = incr;
11552 : 27528 : elocus = init_locv[i];
11553 : :
11554 : 27528 : if (decl == NULL_TREE)
11555 : : {
11556 : 1092 : i++;
11557 : 1092 : continue;
11558 : : }
11559 : :
11560 : 26436 : if (!DECL_P (decl))
11561 : : {
11562 : 6 : error_at (elocus, "expected iteration declaration or initialization");
11563 : 6 : return NULL;
11564 : : }
11565 : :
11566 : 26430 : if (incr && TREE_CODE (incr) == MODOP_EXPR)
11567 : : {
11568 : 1 : if (orig_incr)
11569 : 1 : TREE_VEC_ELT (orig_incr, i) = incr;
11570 : 1 : incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
11571 : 1 : TREE_CODE (TREE_OPERAND (incr, 1)),
11572 : 1 : TREE_OPERAND (incr, 2),
11573 : : tf_warning_or_error);
11574 : : }
11575 : :
11576 : 26430 : if (CLASS_TYPE_P (TREE_TYPE (decl)))
11577 : : {
11578 : 825 : if (code == OMP_SIMD)
11579 : : {
11580 : 12 : error_at (elocus, "%<#pragma omp simd%> used with class "
11581 : : "iteration variable %qE", decl);
11582 : 12 : return NULL;
11583 : : }
11584 : 813 : if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
11585 : : initv, condv, incrv, &body,
11586 : : &pre_body, clauses,
11587 : : collapse, ordered))
11588 : : return NULL;
11589 : 762 : continue;
11590 : : }
11591 : :
11592 : 51210 : if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
11593 : 27188 : && !TYPE_PTR_P (TREE_TYPE (decl)))
11594 : : {
11595 : 14 : error_at (elocus, "invalid type for iteration variable %qE", decl);
11596 : 14 : return NULL;
11597 : : }
11598 : :
11599 : 25591 : if (!processing_template_decl && TREE_CODE (init) != TREE_VEC)
11600 : 24818 : init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
11601 : : tf_warning_or_error);
11602 : : else
11603 : 773 : init = build2_loc (elocus, MODIFY_EXPR, void_type_node, decl, init);
11604 : 25591 : if (decl == error_mark_node || init == error_mark_node)
11605 : : return NULL;
11606 : :
11607 : 25582 : TREE_VEC_ELT (declv, i) = decl;
11608 : 25582 : TREE_VEC_ELT (initv, i) = init;
11609 : 25582 : TREE_VEC_ELT (condv, i) = cond;
11610 : 25582 : TREE_VEC_ELT (incrv, i) = incr;
11611 : 25582 : i++;
11612 : : }
11613 : :
11614 : 20509 : if (pre_body && IS_EMPTY_STMT (pre_body))
11615 : 0 : pre_body = NULL;
11616 : :
11617 : 41018 : omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
11618 : : incrv, body, pre_body,
11619 : 20509 : !processing_template_decl);
11620 : :
11621 : : /* Check for iterators appearing in lb, b or incr expressions. */
11622 : 20509 : if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
11623 : : omp_for = NULL_TREE;
11624 : :
11625 : 20023 : if (omp_for == NULL)
11626 : 702 : return NULL;
11627 : :
11628 : 19807 : add_stmt (omp_for);
11629 : :
11630 : 45455 : for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
11631 : : {
11632 : 25648 : init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
11633 : 25648 : if (init == NULL_TREE)
11634 : 1032 : continue;
11635 : 24616 : decl = TREE_OPERAND (init, 0);
11636 : 24616 : cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
11637 : 24616 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
11638 : :
11639 : 24616 : if (!processing_template_decl)
11640 : : {
11641 : 24083 : if (TREE_CODE (TREE_OPERAND (init, 1)) == TREE_VEC)
11642 : : {
11643 : 106 : tree t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 1);
11644 : 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 1)
11645 : 106 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11646 : 106 : t = TREE_VEC_ELT (TREE_OPERAND (init, 1), 2);
11647 : 106 : TREE_VEC_ELT (TREE_OPERAND (init, 1), 2)
11648 : 212 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11649 : : }
11650 : : else
11651 : : {
11652 : 23977 : tree t = TREE_OPERAND (init, 1);
11653 : 23977 : TREE_OPERAND (init, 1)
11654 : 47954 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11655 : : }
11656 : 24083 : if (TREE_CODE (TREE_OPERAND (cond, 1)) == TREE_VEC)
11657 : : {
11658 : 121 : tree t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1);
11659 : 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 1)
11660 : 121 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11661 : 121 : t = TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2);
11662 : 121 : TREE_VEC_ELT (TREE_OPERAND (cond, 1), 2)
11663 : 242 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11664 : : }
11665 : : else
11666 : : {
11667 : 23962 : tree t = TREE_OPERAND (cond, 1);
11668 : 23962 : TREE_OPERAND (cond, 1)
11669 : 47924 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11670 : : }
11671 : : }
11672 : :
11673 : 24616 : if (TREE_CODE (incr) != MODIFY_EXPR)
11674 : 18423 : continue;
11675 : :
11676 : 6193 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
11677 : 70 : && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
11678 : 6263 : && !processing_template_decl)
11679 : : {
11680 : 64 : tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
11681 : 64 : if (TREE_SIDE_EFFECTS (t)
11682 : 8 : && t != decl
11683 : 70 : && (TREE_CODE (t) != NOP_EXPR
11684 : 0 : || TREE_OPERAND (t, 0) != decl))
11685 : 6 : TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
11686 : 12 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11687 : :
11688 : 64 : t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
11689 : 64 : if (TREE_SIDE_EFFECTS (t)
11690 : 56 : && t != decl
11691 : 120 : && (TREE_CODE (t) != NOP_EXPR
11692 : 7 : || TREE_OPERAND (t, 0) != decl))
11693 : 56 : TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
11694 : 112 : = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
11695 : : }
11696 : :
11697 : 6193 : if (orig_incr)
11698 : 177 : TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
11699 : : }
11700 : 19807 : OMP_FOR_CLAUSES (omp_for) = clauses;
11701 : :
11702 : : /* For simd loops with non-static data member iterators, we could have added
11703 : : OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
11704 : : step at this point, fill it in. */
11705 : 4732 : if (code == OMP_SIMD && !processing_template_decl
11706 : 24495 : && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
11707 : 4619 : for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
11708 : 561 : c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
11709 : 561 : if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
11710 : : {
11711 : 4 : decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
11712 : 4 : gcc_assert (decl == OMP_CLAUSE_DECL (c));
11713 : 4 : incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
11714 : 4 : tree step, stept;
11715 : 4 : switch (TREE_CODE (incr))
11716 : : {
11717 : 0 : case PREINCREMENT_EXPR:
11718 : 0 : case POSTINCREMENT_EXPR:
11719 : : /* c_omp_for_incr_canonicalize_ptr() should have been
11720 : : called to massage things appropriately. */
11721 : 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
11722 : 0 : OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
11723 : 0 : break;
11724 : 0 : case PREDECREMENT_EXPR:
11725 : 0 : case POSTDECREMENT_EXPR:
11726 : : /* c_omp_for_incr_canonicalize_ptr() should have been
11727 : : called to massage things appropriately. */
11728 : 0 : gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
11729 : 0 : OMP_CLAUSE_LINEAR_STEP (c)
11730 : 0 : = build_int_cst (TREE_TYPE (decl), -1);
11731 : 0 : break;
11732 : 4 : case MODIFY_EXPR:
11733 : 4 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
11734 : 4 : incr = TREE_OPERAND (incr, 1);
11735 : 4 : switch (TREE_CODE (incr))
11736 : : {
11737 : 4 : case PLUS_EXPR:
11738 : 4 : if (TREE_OPERAND (incr, 1) == decl)
11739 : 0 : step = TREE_OPERAND (incr, 0);
11740 : : else
11741 : 4 : step = TREE_OPERAND (incr, 1);
11742 : : break;
11743 : 0 : case MINUS_EXPR:
11744 : 0 : case POINTER_PLUS_EXPR:
11745 : 0 : gcc_assert (TREE_OPERAND (incr, 0) == decl);
11746 : 0 : step = TREE_OPERAND (incr, 1);
11747 : 0 : break;
11748 : 0 : default:
11749 : 0 : gcc_unreachable ();
11750 : : }
11751 : 4 : stept = TREE_TYPE (decl);
11752 : 4 : if (INDIRECT_TYPE_P (stept))
11753 : 0 : stept = sizetype;
11754 : 4 : step = fold_convert (stept, step);
11755 : 4 : if (TREE_CODE (incr) == MINUS_EXPR)
11756 : 0 : step = fold_build1 (NEGATE_EXPR, stept, step);
11757 : 4 : OMP_CLAUSE_LINEAR_STEP (c) = step;
11758 : 4 : break;
11759 : 0 : default:
11760 : 0 : gcc_unreachable ();
11761 : : }
11762 : : }
11763 : : /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
11764 : : clauses, we need copy ctor for those rather than default ctor,
11765 : : plus as for other lastprivates assignment op and dtor. */
11766 : 19807 : if (code == OMP_LOOP && !processing_template_decl)
11767 : 1979 : for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
11768 : 1270 : if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
11769 : 204 : && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)
11770 : 1292 : && cxx_omp_create_clause_info (c, TREE_TYPE (OMP_CLAUSE_DECL (c)),
11771 : : false, true, true, true))
11772 : 0 : CP_OMP_CLAUSE_INFO (c) = NULL_TREE;
11773 : :
11774 : : return omp_for;
11775 : 21147 : }
11776 : :
11777 : : /* Code walker for finish_omp_for_block: extract binding of DP->var
11778 : : from its current block and move it to a new BIND_EXPR DP->b
11779 : : surrounding the body of DP->omp_for. */
11780 : :
11781 : : struct fofb_data {
11782 : : tree var;
11783 : : tree b;
11784 : : tree omp_for;
11785 : : };
11786 : :
11787 : : static tree
11788 : 389 : finish_omp_for_block_walker (tree *tp, int *walk_subtrees, void *dp)
11789 : : {
11790 : 389 : struct fofb_data *fofb = (struct fofb_data *)dp;
11791 : 389 : if (TREE_CODE (*tp) == BIND_EXPR)
11792 : 578 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
11793 : : {
11794 : 576 : if (*p == fofb->var)
11795 : : {
11796 : 363 : *p = DECL_CHAIN (*p);
11797 : 363 : if (fofb->b == NULL_TREE)
11798 : : {
11799 : 214 : fofb->b = make_node (BLOCK);
11800 : 214 : fofb->b = build3 (BIND_EXPR, void_type_node, NULL_TREE,
11801 : 214 : OMP_FOR_BODY (fofb->omp_for), fofb->b);
11802 : 214 : TREE_SIDE_EFFECTS (fofb->b) = 1;
11803 : 214 : OMP_FOR_BODY (fofb->omp_for) = fofb->b;
11804 : : }
11805 : 363 : DECL_CHAIN (fofb->var) = BIND_EXPR_VARS (fofb->b);
11806 : 363 : BIND_EXPR_VARS (fofb->b) = fofb->var;
11807 : 363 : BLOCK_VARS (BIND_EXPR_BLOCK (fofb->b)) = fofb->var;
11808 : 363 : BLOCK_VARS (BIND_EXPR_BLOCK (*tp)) = BIND_EXPR_VARS (*tp);
11809 : 363 : return *tp;
11810 : : }
11811 : : }
11812 : 26 : if (TREE_CODE (*tp) != BIND_EXPR && TREE_CODE (*tp) != STATEMENT_LIST)
11813 : 22 : *walk_subtrees = false;
11814 : : return NULL_TREE;
11815 : : }
11816 : :
11817 : : /* Fix up range for decls. Those decls were pushed into BIND's
11818 : : BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
11819 : : and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
11820 : : so that processing of combined loop directives can find them. */
11821 : : tree
11822 : 14538 : finish_omp_for_block (tree bind, tree omp_for)
11823 : : {
11824 : 14538 : if (omp_for == NULL_TREE
11825 : 14491 : || !OMP_FOR_ORIG_DECLS (omp_for)
11826 : 28442 : || bind == NULL_TREE)
11827 : 634 : return bind;
11828 : 13904 : struct fofb_data fofb;
11829 : 13904 : fofb.b = NULL_TREE;
11830 : 13904 : fofb.omp_for = omp_for;
11831 : 33304 : for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
11832 : 19400 : if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
11833 : 19178 : && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
11834 : : == TREE_LIST)
11835 : 20231 : && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
11836 : : {
11837 : 237 : tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
11838 : 602 : for (int j = 2; j < TREE_VEC_LENGTH (v); j++)
11839 : : {
11840 : 365 : fofb.var = TREE_VEC_ELT (v, j);
11841 : 365 : cp_walk_tree (&bind, finish_omp_for_block_walker,
11842 : : (void *)&fofb, NULL);
11843 : : }
11844 : : }
11845 : 13904 : return bind;
11846 : : }
11847 : :
11848 : : void
11849 : 3345 : finish_omp_atomic (location_t loc, enum tree_code code, enum tree_code opcode,
11850 : : tree lhs, tree rhs, tree v, tree lhs1, tree rhs1, tree r,
11851 : : tree clauses, enum omp_memory_order mo, bool weak)
11852 : : {
11853 : 3345 : tree orig_lhs;
11854 : 3345 : tree orig_rhs;
11855 : 3345 : tree orig_v;
11856 : 3345 : tree orig_lhs1;
11857 : 3345 : tree orig_rhs1;
11858 : 3345 : tree orig_r;
11859 : 3345 : bool dependent_p;
11860 : 3345 : tree stmt;
11861 : :
11862 : 3345 : orig_lhs = lhs;
11863 : 3345 : orig_rhs = rhs;
11864 : 3345 : orig_v = v;
11865 : 3345 : orig_lhs1 = lhs1;
11866 : 3345 : orig_rhs1 = rhs1;
11867 : 3345 : orig_r = r;
11868 : 3345 : dependent_p = false;
11869 : 3345 : stmt = NULL_TREE;
11870 : :
11871 : : /* Even in a template, we can detect invalid uses of the atomic
11872 : : pragma if neither LHS nor RHS is type-dependent. */
11873 : 3345 : if (processing_template_decl)
11874 : : {
11875 : 600 : dependent_p = (type_dependent_expression_p (lhs)
11876 : 237 : || (rhs && type_dependent_expression_p (rhs))
11877 : 234 : || (v && type_dependent_expression_p (v))
11878 : 234 : || (lhs1 && type_dependent_expression_p (lhs1))
11879 : 234 : || (rhs1 && type_dependent_expression_p (rhs1))
11880 : 834 : || (r
11881 : 25 : && r != void_list_node
11882 : 16 : && type_dependent_expression_p (r)));
11883 : 600 : if (clauses)
11884 : : {
11885 : 30 : gcc_assert (TREE_CODE (clauses) == OMP_CLAUSE
11886 : : && OMP_CLAUSE_CODE (clauses) == OMP_CLAUSE_HINT
11887 : : && OMP_CLAUSE_CHAIN (clauses) == NULL_TREE);
11888 : 30 : if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses))
11889 : 30 : || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses)) != INTEGER_CST)
11890 : : dependent_p = true;
11891 : : }
11892 : : }
11893 : 576 : if (!dependent_p)
11894 : : {
11895 : 2961 : bool swapped = false;
11896 : 2961 : if (rhs1 && opcode != COND_EXPR && cp_tree_equal (lhs, rhs))
11897 : : {
11898 : 143 : std::swap (rhs, rhs1);
11899 : 143 : swapped = !commutative_tree_code (opcode);
11900 : : }
11901 : 2961 : if (rhs1 && opcode != COND_EXPR && !cp_tree_equal (lhs, rhs1))
11902 : : {
11903 : 0 : if (code == OMP_ATOMIC)
11904 : 0 : error ("%<#pragma omp atomic update%> uses two different "
11905 : : "expressions for memory");
11906 : : else
11907 : 0 : error ("%<#pragma omp atomic capture%> uses two different "
11908 : : "expressions for memory");
11909 : 0 : return;
11910 : : }
11911 : 2961 : if (lhs1 && !cp_tree_equal (lhs, lhs1))
11912 : : {
11913 : 0 : if (code == OMP_ATOMIC)
11914 : 0 : error ("%<#pragma omp atomic update%> uses two different "
11915 : : "expressions for memory");
11916 : : else
11917 : 0 : error ("%<#pragma omp atomic capture%> uses two different "
11918 : : "expressions for memory");
11919 : 0 : return;
11920 : : }
11921 : 5922 : stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs,
11922 : : v, lhs1, rhs1, r, swapped, mo, weak,
11923 : 2961 : processing_template_decl != 0);
11924 : 2961 : if (stmt == error_mark_node)
11925 : : return;
11926 : : }
11927 : 3315 : if (processing_template_decl)
11928 : : {
11929 : 591 : if (code == OMP_ATOMIC_READ)
11930 : : {
11931 : 167 : stmt = build_min_nt_loc (loc, OMP_ATOMIC_READ, orig_lhs);
11932 : 167 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
11933 : 167 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
11934 : : }
11935 : : else
11936 : : {
11937 : 424 : if (opcode == NOP_EXPR)
11938 : 35 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
11939 : 389 : else if (opcode == COND_EXPR)
11940 : : {
11941 : 124 : stmt = build2 (EQ_EXPR, boolean_type_node, orig_lhs, orig_rhs);
11942 : 124 : if (orig_r)
11943 : 50 : stmt = build2 (MODIFY_EXPR, boolean_type_node, orig_r,
11944 : : stmt);
11945 : 124 : stmt = build3 (COND_EXPR, void_type_node, stmt, orig_rhs1,
11946 : : orig_lhs);
11947 : 124 : orig_rhs1 = NULL_TREE;
11948 : : }
11949 : : else
11950 : 265 : stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
11951 : 424 : if (orig_rhs1)
11952 : 182 : stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
11953 : : COMPOUND_EXPR, orig_rhs1, stmt);
11954 : 424 : if (code != OMP_ATOMIC)
11955 : : {
11956 : 233 : stmt = build_min_nt_loc (loc, code, orig_lhs1, stmt);
11957 : 233 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
11958 : 233 : OMP_ATOMIC_WEAK (stmt) = weak;
11959 : 233 : stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
11960 : : }
11961 : : }
11962 : 591 : stmt = build2 (OMP_ATOMIC, void_type_node,
11963 : : clauses ? clauses : integer_zero_node, stmt);
11964 : 591 : OMP_ATOMIC_MEMORY_ORDER (stmt) = mo;
11965 : 591 : OMP_ATOMIC_WEAK (stmt) = weak;
11966 : 591 : SET_EXPR_LOCATION (stmt, loc);
11967 : : }
11968 : :
11969 : : /* Avoid -Wunused-value warnings here, the whole construct has side-effects
11970 : : and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
11971 : : in some tree that appears to be unused, the value is not unused. */
11972 : 3315 : warning_sentinel w (warn_unused_value);
11973 : 3315 : finish_expr_stmt (stmt);
11974 : 3315 : }
11975 : :
11976 : : void
11977 : 371 : finish_omp_barrier (void)
11978 : : {
11979 : 371 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
11980 : 371 : releasing_vec vec;
11981 : 371 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
11982 : 371 : finish_expr_stmt (stmt);
11983 : 371 : }
11984 : :
11985 : : void
11986 : 395 : finish_omp_depobj (location_t loc, tree depobj,
11987 : : enum omp_clause_depend_kind kind, tree clause)
11988 : : {
11989 : 395 : if (!error_operand_p (depobj) && !type_dependent_expression_p (depobj))
11990 : : {
11991 : 341 : if (!lvalue_p (depobj))
11992 : : {
11993 : 6 : error_at (EXPR_LOC_OR_LOC (depobj, loc),
11994 : : "%<depobj%> expression is not lvalue expression");
11995 : 6 : depobj = error_mark_node;
11996 : : }
11997 : : }
11998 : :
11999 : 395 : if (processing_template_decl)
12000 : : {
12001 : 114 : if (clause == NULL_TREE)
12002 : 47 : clause = build_int_cst (integer_type_node, kind);
12003 : 114 : add_stmt (build_min_nt_loc (loc, OMP_DEPOBJ, depobj, clause));
12004 : 114 : return;
12005 : : }
12006 : :
12007 : 281 : if (!error_operand_p (depobj))
12008 : : {
12009 : 272 : tree addr = cp_build_addr_expr (depobj, tf_warning_or_error);
12010 : 272 : if (addr == error_mark_node)
12011 : : depobj = error_mark_node;
12012 : : else
12013 : 272 : depobj = cp_build_indirect_ref (loc, addr, RO_UNARY_STAR,
12014 : : tf_warning_or_error);
12015 : : }
12016 : :
12017 : 281 : c_finish_omp_depobj (loc, depobj, kind, clause);
12018 : : }
12019 : :
12020 : : void
12021 : 165 : finish_omp_flush (int mo)
12022 : : {
12023 : 165 : tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
12024 : 165 : releasing_vec vec;
12025 : 165 : if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
12026 : : {
12027 : 54 : fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
12028 : 54 : vec->quick_push (build_int_cst (integer_type_node, mo));
12029 : : }
12030 : 165 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12031 : 165 : finish_expr_stmt (stmt);
12032 : 165 : }
12033 : :
12034 : : void
12035 : 110 : finish_omp_taskwait (void)
12036 : : {
12037 : 110 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
12038 : 110 : releasing_vec vec;
12039 : 110 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12040 : 110 : finish_expr_stmt (stmt);
12041 : 110 : }
12042 : :
12043 : : void
12044 : 16 : finish_omp_taskyield (void)
12045 : : {
12046 : 16 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
12047 : 16 : releasing_vec vec;
12048 : 16 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12049 : 16 : finish_expr_stmt (stmt);
12050 : 16 : }
12051 : :
12052 : : void
12053 : 596 : finish_omp_cancel (tree clauses)
12054 : : {
12055 : 596 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
12056 : 596 : int mask = 0;
12057 : 596 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12058 : : mask = 1;
12059 : 414 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12060 : : mask = 2;
12061 : 285 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12062 : : mask = 4;
12063 : 164 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12064 : : mask = 8;
12065 : : else
12066 : : {
12067 : 0 : error ("%<#pragma omp cancel%> must specify one of "
12068 : : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12069 : 0 : return;
12070 : : }
12071 : 596 : releasing_vec vec;
12072 : 596 : tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
12073 : 596 : if (ifc != NULL_TREE)
12074 : : {
12075 : 70 : if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
12076 : 70 : && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
12077 : 6 : error_at (OMP_CLAUSE_LOCATION (ifc),
12078 : : "expected %<cancel%> %<if%> clause modifier");
12079 : : else
12080 : : {
12081 : 64 : tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
12082 : 64 : if (ifc2 != NULL_TREE)
12083 : : {
12084 : 3 : gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
12085 : : && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
12086 : : && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
12087 : 3 : error_at (OMP_CLAUSE_LOCATION (ifc2),
12088 : : "expected %<cancel%> %<if%> clause modifier");
12089 : : }
12090 : : }
12091 : :
12092 : 70 : if (!processing_template_decl)
12093 : 61 : ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc));
12094 : : else
12095 : 9 : ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
12096 : 9 : OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK,
12097 : : integer_zero_node, ERROR_MARK,
12098 : : NULL_TREE, NULL, tf_warning_or_error);
12099 : : }
12100 : : else
12101 : 526 : ifc = boolean_true_node;
12102 : 596 : vec->quick_push (build_int_cst (integer_type_node, mask));
12103 : 596 : vec->quick_push (ifc);
12104 : 596 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12105 : 596 : finish_expr_stmt (stmt);
12106 : 596 : }
12107 : :
12108 : : void
12109 : 494 : finish_omp_cancellation_point (tree clauses)
12110 : : {
12111 : 494 : tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
12112 : 494 : int mask = 0;
12113 : 494 : if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
12114 : : mask = 1;
12115 : 366 : else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
12116 : : mask = 2;
12117 : 261 : else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
12118 : : mask = 4;
12119 : 156 : else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
12120 : : mask = 8;
12121 : : else
12122 : : {
12123 : 3 : error ("%<#pragma omp cancellation point%> must specify one of "
12124 : : "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
12125 : 3 : return;
12126 : : }
12127 : 491 : releasing_vec vec
12128 : 491 : = make_tree_vector_single (build_int_cst (integer_type_node, mask));
12129 : 491 : tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
12130 : 491 : finish_expr_stmt (stmt);
12131 : 491 : }
12132 : :
12133 : : /* Begin a __transaction_atomic or __transaction_relaxed statement.
12134 : : If PCOMPOUND is non-null, this is for a function-transaction-block, and we
12135 : : should create an extra compound stmt. */
12136 : :
12137 : : tree
12138 : 303 : begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
12139 : : {
12140 : 303 : tree r;
12141 : :
12142 : 303 : if (pcompound)
12143 : 21 : *pcompound = begin_compound_stmt (0);
12144 : :
12145 : 303 : r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
12146 : :
12147 : : /* Only add the statement to the function if support enabled. */
12148 : 303 : if (flag_tm)
12149 : 297 : add_stmt (r);
12150 : : else
12151 : 12 : error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
12152 : : ? G_("%<__transaction_relaxed%> without "
12153 : : "transactional memory support enabled")
12154 : : : G_("%<__transaction_atomic%> without "
12155 : : "transactional memory support enabled")));
12156 : :
12157 : 303 : TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
12158 : 303 : TREE_SIDE_EFFECTS (r) = 1;
12159 : 303 : return r;
12160 : : }
12161 : :
12162 : : /* End a __transaction_atomic or __transaction_relaxed statement.
12163 : : If COMPOUND_STMT is non-null, this is for a function-transaction-block,
12164 : : and we should end the compound. If NOEX is non-NULL, we wrap the body in
12165 : : a MUST_NOT_THROW_EXPR with NOEX as condition. */
12166 : :
12167 : : void
12168 : 303 : finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
12169 : : {
12170 : 303 : TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
12171 : 303 : TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
12172 : 303 : TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
12173 : 303 : TRANSACTION_EXPR_IS_STMT (stmt) = 1;
12174 : :
12175 : : /* noexcept specifications are not allowed for function transactions. */
12176 : 303 : gcc_assert (!(noex && compound_stmt));
12177 : 303 : if (noex)
12178 : : {
12179 : 51 : tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
12180 : : noex);
12181 : 51 : protected_set_expr_location
12182 : 51 : (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
12183 : 51 : TREE_SIDE_EFFECTS (body) = 1;
12184 : 51 : TRANSACTION_EXPR_BODY (stmt) = body;
12185 : : }
12186 : :
12187 : 303 : if (compound_stmt)
12188 : 21 : finish_compound_stmt (compound_stmt);
12189 : 303 : }
12190 : :
12191 : : /* Build a __transaction_atomic or __transaction_relaxed expression. If
12192 : : NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
12193 : : condition. */
12194 : :
12195 : : tree
12196 : 116 : build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
12197 : : {
12198 : 116 : tree ret;
12199 : 116 : if (noex)
12200 : : {
12201 : 57 : expr = build_must_not_throw_expr (expr, noex);
12202 : 57 : protected_set_expr_location (expr, loc);
12203 : 57 : TREE_SIDE_EFFECTS (expr) = 1;
12204 : : }
12205 : 116 : ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
12206 : 116 : if (flags & TM_STMT_ATTR_RELAXED)
12207 : 4 : TRANSACTION_EXPR_RELAXED (ret) = 1;
12208 : 116 : TREE_SIDE_EFFECTS (ret) = 1;
12209 : 116 : SET_EXPR_LOCATION (ret, loc);
12210 : 116 : return ret;
12211 : : }
12212 : :
12213 : : void
12214 : 93374 : init_cp_semantics (void)
12215 : : {
12216 : 93374 : }
12217 : :
12218 : :
12219 : : /* Get constant string at LOCATION. Returns true if successful,
12220 : : otherwise false. */
12221 : :
12222 : : bool
12223 : 8294830 : cexpr_str::type_check (location_t location)
12224 : : {
12225 : 8294830 : tsubst_flags_t complain = tf_warning_or_error;
12226 : :
12227 : 8294830 : if (message == NULL_TREE
12228 : 8294830 : || message == error_mark_node
12229 : 16589657 : || check_for_bare_parameter_packs (message))
12230 : 3 : return false;
12231 : :
12232 : 8294827 : if (TREE_CODE (message) != STRING_CST
12233 : 8294827 : && !type_dependent_expression_p (message))
12234 : : {
12235 : 702 : message_sz
12236 : 702 : = finish_class_member_access_expr (message,
12237 : : get_identifier ("size"),
12238 : : false, complain);
12239 : 702 : if (message_sz != error_mark_node)
12240 : 643 : message_data
12241 : 643 : = finish_class_member_access_expr (message,
12242 : : get_identifier ("data"),
12243 : : false, complain);
12244 : 702 : if (message_sz == error_mark_node || message_data == error_mark_node)
12245 : : {
12246 : 83 : error_at (location, "constexpr string must be a string "
12247 : : "literal or object with %<size%> and "
12248 : : "%<data%> members");
12249 : 209 : return false;
12250 : : }
12251 : 619 : releasing_vec size_args, data_args;
12252 : 619 : message_sz = finish_call_expr (message_sz, &size_args, false, false,
12253 : : complain);
12254 : 619 : message_data = finish_call_expr (message_data, &data_args, false, false,
12255 : : complain);
12256 : 619 : if (message_sz == error_mark_node || message_data == error_mark_node)
12257 : : return false;
12258 : 529 : message_sz = build_converted_constant_expr (size_type_node, message_sz,
12259 : : complain);
12260 : 529 : if (message_sz == error_mark_node)
12261 : : {
12262 : 12 : error_at (location, "constexpr string %<size()%> "
12263 : : "must be implicitly convertible to "
12264 : : "%<std::size_t%>");
12265 : 12 : return false;
12266 : : }
12267 : 517 : message_data = build_converted_constant_expr (const_string_type_node,
12268 : : message_data, complain);
12269 : 517 : if (message_data == error_mark_node)
12270 : : {
12271 : 24 : error_at (location, "constexpr string %<data()%> "
12272 : : "must be implicitly convertible to "
12273 : : "%<const char*%>");
12274 : 24 : return false;
12275 : : }
12276 : 619 : }
12277 : : return true;
12278 : : }
12279 : :
12280 : : /* Extract constant string at LOCATON into output string STR.
12281 : : Returns true if successful, otherwise false. */
12282 : :
12283 : : bool
12284 : 318 : cexpr_str::extract (location_t location, tree &str)
12285 : : {
12286 : 318 : const char *msg;
12287 : 318 : int len;
12288 : 318 : if (!extract (location, msg, len))
12289 : : return false;
12290 : 272 : str = build_string (len, msg);
12291 : 272 : return true;
12292 : : }
12293 : :
12294 : : /* Extract constant string at LOCATION into output string MSG with LEN.
12295 : : Returns true if successful, otherwise false. */
12296 : :
12297 : : bool
12298 : 1545 : cexpr_str::extract (location_t location, const char * & msg, int &len)
12299 : : {
12300 : 1545 : tsubst_flags_t complain = tf_warning_or_error;
12301 : :
12302 : 1545 : msg = NULL;
12303 : 1545 : if (message_sz && message_data)
12304 : : {
12305 : 437 : tree msz = cxx_constant_value (message_sz, NULL_TREE, complain);
12306 : 437 : if (!tree_fits_uhwi_p (msz))
12307 : : {
12308 : 23 : error_at (location,
12309 : : "constexpr string %<size()%> "
12310 : : "must be a constant expression");
12311 : 23 : return false;
12312 : : }
12313 : 414 : else if ((unsigned HOST_WIDE_INT) (int) tree_to_uhwi (msz)
12314 : : != tree_to_uhwi (msz))
12315 : : {
12316 : 0 : error_at (location,
12317 : : "constexpr string message %<size()%> "
12318 : : "%qE too large", msz);
12319 : 0 : return false;
12320 : : }
12321 : 414 : len = tree_to_uhwi (msz);
12322 : 414 : tree data = maybe_constant_value (message_data, NULL_TREE,
12323 : : mce_true);
12324 : 414 : if (!reduced_constant_expression_p (data))
12325 : 73 : data = NULL_TREE;
12326 : 414 : if (len)
12327 : : {
12328 : 353 : if (data)
12329 : 297 : msg = c_getstr (data);
12330 : 353 : if (msg == NULL)
12331 : 92 : buf = XNEWVEC (char, len);
12332 : 1138 : for (int i = 0; i < len; ++i)
12333 : : {
12334 : 806 : tree t = message_data;
12335 : 806 : if (i)
12336 : 906 : t = build2 (POINTER_PLUS_EXPR,
12337 : 453 : TREE_TYPE (message_data), message_data,
12338 : 453 : size_int (i));
12339 : 806 : t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
12340 : 806 : tree t2 = cxx_constant_value (t, NULL_TREE, complain);
12341 : 806 : if (!tree_fits_shwi_p (t2))
12342 : : {
12343 : 21 : error_at (location,
12344 : : "constexpr string %<data()[%d]%> "
12345 : : "must be a constant expression", i);
12346 : 21 : return false;
12347 : : }
12348 : 785 : if (msg == NULL)
12349 : 288 : buf[i] = tree_to_shwi (t2);
12350 : : /* If c_getstr worked, just verify the first and
12351 : : last characters using constant evaluation. */
12352 : 497 : else if (len > 2 && i == 0)
12353 : 205 : i = len - 2;
12354 : : }
12355 : 332 : if (msg == NULL)
12356 : 83 : msg = buf;
12357 : : }
12358 : 61 : else if (!data)
12359 : : {
12360 : : /* We don't have any function to test whether some
12361 : : expression is a core constant expression. So, instead
12362 : : test whether (message.data (), 0) is a constant
12363 : : expression. */
12364 : 17 : data = build2 (COMPOUND_EXPR, integer_type_node,
12365 : : message_data, integer_zero_node);
12366 : 17 : tree t = cxx_constant_value (data, NULL_TREE, complain);
12367 : 17 : if (!integer_zerop (t))
12368 : : {
12369 : 17 : error_at (location,
12370 : : "constexpr string %<data()%> "
12371 : : "must be a core constant expression");
12372 : 17 : return false;
12373 : : }
12374 : : }
12375 : : }
12376 : : else
12377 : : {
12378 : 1108 : tree eltype = TREE_TYPE (TREE_TYPE (message));
12379 : 1108 : int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype));
12380 : 1108 : msg = TREE_STRING_POINTER (message);
12381 : 1108 : len = TREE_STRING_LENGTH (message) / sz - 1;
12382 : : }
12383 : :
12384 : : return true;
12385 : : }
12386 : :
12387 : : /* Build a STATIC_ASSERT for a static assertion with the condition
12388 : : CONDITION and the message text MESSAGE. LOCATION is the location
12389 : : of the static assertion in the source code. When MEMBER_P, this
12390 : : static assertion is a member of a class. If SHOW_EXPR_P is true,
12391 : : print the condition (because it was instantiation-dependent). */
12392 : :
12393 : : void
12394 : 8294560 : finish_static_assert (tree condition, tree message, location_t location,
12395 : : bool member_p, bool show_expr_p)
12396 : : {
12397 : 8294560 : tsubst_flags_t complain = tf_warning_or_error;
12398 : :
12399 : 8294560 : if (condition == NULL_TREE
12400 : 8294560 : || condition == error_mark_node)
12401 : 3747048 : return;
12402 : :
12403 : 8294379 : if (check_for_bare_parameter_packs (condition))
12404 : : return;
12405 : :
12406 : 8294376 : cexpr_str cstr(message);
12407 : 8294376 : if (!cstr.type_check (location))
12408 : : return;
12409 : :
12410 : : /* Save the condition in case it was a concept check. */
12411 : 8294300 : tree orig_condition = condition;
12412 : :
12413 : 8294300 : if (instantiation_dependent_expression_p (condition)
12414 : 8294300 : || instantiation_dependent_expression_p (message))
12415 : : {
12416 : : /* We're in a template; build a STATIC_ASSERT and put it in
12417 : : the right place. */
12418 : 3746773 : defer:
12419 : 3746773 : tree assertion = make_node (STATIC_ASSERT);
12420 : 3746773 : STATIC_ASSERT_CONDITION (assertion) = orig_condition;
12421 : 3746773 : STATIC_ASSERT_MESSAGE (assertion) = cstr.message;
12422 : 3746773 : STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
12423 : :
12424 : 3746773 : if (member_p)
12425 : 2087364 : maybe_add_class_template_decl_list (current_class_type,
12426 : : assertion,
12427 : : /*friend_p=*/0);
12428 : : else
12429 : 1659409 : add_stmt (assertion);
12430 : :
12431 : 3746773 : return;
12432 : : }
12433 : :
12434 : : /* Fold the expression and convert it to a boolean value. */
12435 : 4548797 : condition = contextual_conv_bool (condition, complain);
12436 : 4548797 : condition = fold_non_dependent_expr (condition, complain,
12437 : : /*manifestly_const_eval=*/true);
12438 : :
12439 : 4548797 : if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
12440 : : /* Do nothing; the condition is satisfied. */
12441 : : ;
12442 : : else
12443 : : {
12444 : 2686 : iloc_sentinel ils (location);
12445 : :
12446 : 2686 : if (integer_zerop (condition))
12447 : : {
12448 : : /* CWG2518: static_assert failure in a template is not IFNDR. */
12449 : 2497 : if (processing_template_decl)
12450 : 1270 : goto defer;
12451 : :
12452 : 1227 : int len;
12453 : 1227 : const char *msg = NULL;
12454 : 1227 : if (!cstr.extract (location, msg, len))
12455 : 15 : return;
12456 : :
12457 : : /* See if we can find which clause was failing (for logical AND). */
12458 : 1212 : tree bad = find_failing_clause (NULL, orig_condition);
12459 : : /* If not, or its location is unusable, fall back to the previous
12460 : : location. */
12461 : 1212 : location_t cloc = cp_expr_loc_or_loc (bad, location);
12462 : :
12463 : 1212 : auto_diagnostic_group d;
12464 : :
12465 : : /* Report the error. */
12466 : 1212 : if (len == 0)
12467 : 669 : error_at (cloc, "static assertion failed");
12468 : : else
12469 : 543 : error_at (cloc, "static assertion failed: %.*s", len, msg);
12470 : :
12471 : 1212 : diagnose_failing_condition (bad, cloc, show_expr_p);
12472 : 1212 : }
12473 : 189 : else if (condition && condition != error_mark_node)
12474 : : {
12475 : 186 : error ("non-constant condition for static assertion");
12476 : 186 : if (require_rvalue_constant_expression (condition))
12477 : 131 : cxx_constant_value (condition);
12478 : : }
12479 : 2686 : }
12480 : 8294376 : }
12481 : :
12482 : : /* Implements the C++0x decltype keyword. Returns the type of EXPR,
12483 : : suitable for use as a type-specifier.
12484 : :
12485 : : ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
12486 : : id-expression or a class member access, FALSE when it was parsed as
12487 : : a full expression. */
12488 : :
12489 : : tree
12490 : 19113274 : finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
12491 : : tsubst_flags_t complain)
12492 : : {
12493 : 19113274 : tree type = NULL_TREE;
12494 : :
12495 : 19113274 : if (!expr || error_operand_p (expr))
12496 : 90142 : return error_mark_node;
12497 : :
12498 : 19023132 : if (TYPE_P (expr)
12499 : 19023132 : || TREE_CODE (expr) == TYPE_DECL
12500 : 38046246 : || (TREE_CODE (expr) == BIT_NOT_EXPR
12501 : 12472 : && TYPE_P (TREE_OPERAND (expr, 0))))
12502 : : {
12503 : 27 : if (complain & tf_error)
12504 : 27 : error ("argument to %<decltype%> must be an expression");
12505 : 27 : return error_mark_node;
12506 : : }
12507 : :
12508 : : /* decltype is an unevaluated context. */
12509 : 19023105 : cp_unevaluated u;
12510 : :
12511 : 19023105 : processing_template_decl_sentinel ptds (/*reset=*/false);
12512 : :
12513 : : /* Depending on the resolution of DR 1172, we may later need to distinguish
12514 : : instantiation-dependent but not type-dependent expressions so that, say,
12515 : : A<decltype(sizeof(T))>::U doesn't require 'typename'. */
12516 : 19023105 : if (instantiation_dependent_uneval_expression_p (expr))
12517 : : {
12518 : 4289179 : dependent:
12519 : 4289563 : type = cxx_make_type (DECLTYPE_TYPE);
12520 : 4289563 : DECLTYPE_TYPE_EXPR (type) = expr;
12521 : 8579126 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
12522 : 4289563 : = id_expression_or_member_access_p;
12523 : 4289563 : SET_TYPE_STRUCTURAL_EQUALITY (type);
12524 : :
12525 : 4289563 : return type;
12526 : : }
12527 : 14733926 : else if (processing_template_decl)
12528 : : {
12529 : 6193 : expr = instantiate_non_dependent_expr (expr, complain|tf_decltype);
12530 : 6193 : if (expr == error_mark_node)
12531 : : return error_mark_node;
12532 : : /* Keep processing_template_decl cleared for the rest of the function
12533 : : (for sake of the call to lvalue_kind below, which handles templated
12534 : : and non-templated COND_EXPR differently). */
12535 : 6155 : processing_template_decl = 0;
12536 : : }
12537 : :
12538 : : /* The type denoted by decltype(e) is defined as follows: */
12539 : :
12540 : 14733888 : expr = resolve_nondeduced_context (expr, complain);
12541 : 14733888 : if (!mark_single_function (expr, complain))
12542 : 0 : return error_mark_node;
12543 : :
12544 : 14733888 : if (invalid_nonstatic_memfn_p (input_location, expr, complain))
12545 : 18 : return error_mark_node;
12546 : :
12547 : 14733870 : if (type_unknown_p (expr))
12548 : : {
12549 : 18 : if (complain & tf_error)
12550 : 6 : error ("%<decltype%> cannot resolve address of overloaded function");
12551 : 18 : return error_mark_node;
12552 : : }
12553 : :
12554 : 14733852 : if (id_expression_or_member_access_p)
12555 : : {
12556 : : /* If e is an id-expression or a class member access (5.2.5
12557 : : [expr.ref]), decltype(e) is defined as the type of the entity
12558 : : named by e. If there is no such entity, or e names a set of
12559 : : overloaded functions, the program is ill-formed. */
12560 : 695208 : if (identifier_p (expr))
12561 : 0 : expr = lookup_name (expr);
12562 : :
12563 : 695208 : if (INDIRECT_REF_P (expr)
12564 : 695208 : || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
12565 : : /* This can happen when the expression is, e.g., "a.b". Just
12566 : : look at the underlying operand. */
12567 : 575769 : expr = TREE_OPERAND (expr, 0);
12568 : :
12569 : 695208 : if (TREE_CODE (expr) == OFFSET_REF
12570 : 695208 : || TREE_CODE (expr) == MEMBER_REF
12571 : 695208 : || TREE_CODE (expr) == SCOPE_REF)
12572 : : /* We're only interested in the field itself. If it is a
12573 : : BASELINK, we will need to see through it in the next
12574 : : step. */
12575 : 0 : expr = TREE_OPERAND (expr, 1);
12576 : :
12577 : 695208 : if (BASELINK_P (expr))
12578 : : /* See through BASELINK nodes to the underlying function. */
12579 : 3 : expr = BASELINK_FUNCTIONS (expr);
12580 : :
12581 : : /* decltype of a decomposition name drops references in the tuple case
12582 : : (unlike decltype of a normal variable) and keeps cv-qualifiers from
12583 : : the containing object in the other cases (unlike decltype of a member
12584 : : access expression). */
12585 : 695208 : if (DECL_DECOMPOSITION_P (expr))
12586 : : {
12587 : 129 : if (ptds.saved)
12588 : : {
12589 : 6 : gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr));
12590 : : /* DECL_HAS_VALUE_EXPR_P is always set if
12591 : : processing_template_decl. If lookup_decomp_type
12592 : : returns non-NULL, it is the tuple case. */
12593 : 6 : if (tree ret = lookup_decomp_type (expr))
12594 : : return ret;
12595 : : }
12596 : 126 : if (DECL_HAS_VALUE_EXPR_P (expr))
12597 : : /* Expr is an array or struct subobject proxy, handle
12598 : : bit-fields properly. */
12599 : 78 : return unlowered_expr_type (expr);
12600 : : else
12601 : : /* Expr is a reference variable for the tuple case. */
12602 : 48 : return lookup_decomp_type (expr);
12603 : : }
12604 : :
12605 : 695079 : switch (TREE_CODE (expr))
12606 : : {
12607 : 9 : case FIELD_DECL:
12608 : 9 : if (DECL_BIT_FIELD_TYPE (expr))
12609 : : {
12610 : : type = DECL_BIT_FIELD_TYPE (expr);
12611 : : break;
12612 : : }
12613 : : /* Fall through for fields that aren't bitfields. */
12614 : 107621 : gcc_fallthrough ();
12615 : :
12616 : 107621 : case VAR_DECL:
12617 : 107621 : if (is_capture_proxy (expr))
12618 : : {
12619 : 57 : if (is_normal_capture_proxy (expr))
12620 : : {
12621 : 21 : expr = DECL_CAPTURED_VARIABLE (expr);
12622 : 21 : type = TREE_TYPE (expr);
12623 : : }
12624 : : else
12625 : : {
12626 : 36 : expr = DECL_VALUE_EXPR (expr);
12627 : 36 : gcc_assert (TREE_CODE (expr) == COMPONENT_REF);
12628 : 36 : expr = TREE_OPERAND (expr, 1);
12629 : 36 : type = TREE_TYPE (expr);
12630 : : }
12631 : : break;
12632 : : }
12633 : : /* Fall through for variables that aren't capture proxies. */
12634 : 692347 : gcc_fallthrough ();
12635 : :
12636 : 692347 : case FUNCTION_DECL:
12637 : 692347 : case CONST_DECL:
12638 : 692347 : case PARM_DECL:
12639 : 692347 : case RESULT_DECL:
12640 : 692347 : case TEMPLATE_PARM_INDEX:
12641 : 692347 : expr = mark_type_use (expr);
12642 : 692347 : type = TREE_TYPE (expr);
12643 : 692347 : if (VAR_P (expr) && DECL_NTTP_OBJECT_P (expr))
12644 : : {
12645 : : /* decltype of an NTTP object is the type of the template
12646 : : parameter, which is the object type modulo cv-quals. */
12647 : 21 : int quals = cp_type_quals (type);
12648 : 21 : gcc_checking_assert (quals & TYPE_QUAL_CONST);
12649 : 21 : type = cv_unqualified (type);
12650 : : }
12651 : : break;
12652 : :
12653 : 0 : case ERROR_MARK:
12654 : 0 : type = error_mark_node;
12655 : 0 : break;
12656 : :
12657 : 2530 : case COMPONENT_REF:
12658 : 2530 : case COMPOUND_EXPR:
12659 : 2530 : mark_type_use (expr);
12660 : 2530 : type = is_bitfield_expr_with_lowered_type (expr);
12661 : 2530 : if (!type)
12662 : 2497 : type = TREE_TYPE (TREE_OPERAND (expr, 1));
12663 : : break;
12664 : :
12665 : 0 : case BIT_FIELD_REF:
12666 : 0 : gcc_unreachable ();
12667 : :
12668 : 99 : case INTEGER_CST:
12669 : 99 : case PTRMEM_CST:
12670 : : /* We can get here when the id-expression refers to an
12671 : : enumerator or non-type template parameter. */
12672 : 99 : type = TREE_TYPE (expr);
12673 : 99 : break;
12674 : :
12675 : 46 : default:
12676 : : /* Handle instantiated template non-type arguments. */
12677 : 46 : type = TREE_TYPE (expr);
12678 : 46 : break;
12679 : : }
12680 : : }
12681 : : else
12682 : : {
12683 : 26910578 : if (outer_automatic_var_p (STRIP_REFERENCE_REF (expr))
12684 : 800 : && current_function_decl
12685 : 14040244 : && LAMBDA_FUNCTION_P (current_function_decl))
12686 : : {
12687 : : /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
12688 : : unevaluated operand within S would refer to an entity captured by
12689 : : copy in some intervening lambda-expression, then let E be the
12690 : : innermost such lambda-expression.
12691 : :
12692 : : If there is such a lambda-expression and if P is in E's function
12693 : : parameter scope but not its parameter-declaration-clause, then the
12694 : : type of the expression is the type of a class member access
12695 : : expression naming the non-static data member that would be declared
12696 : : for such a capture in the object parameter of the function call
12697 : : operator of E." */
12698 : : /* FIXME: This transformation needs to happen for all uses of an outer
12699 : : local variable inside decltype, not just decltype((x)) (PR83167).
12700 : : And we don't handle nested lambdas properly, where we need to
12701 : : consider the outer lambdas as well (PR112926). */
12702 : 800 : tree decl = STRIP_REFERENCE_REF (expr);
12703 : 800 : tree lam = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl));
12704 : 800 : tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK,
12705 : : LOOK_want::HIDDEN_LAMBDA);
12706 : :
12707 : 800 : if (cap && is_capture_proxy (cap))
12708 : 261 : type = TREE_TYPE (cap);
12709 : 539 : else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_COPY)
12710 : : {
12711 : 431 : type = TREE_TYPE (decl);
12712 : 431 : if (TYPE_REF_P (type)
12713 : 431 : && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
12714 : 3 : type = TREE_TYPE (type);
12715 : : }
12716 : :
12717 : 692 : if (type && !TYPE_REF_P (type))
12718 : : {
12719 : 638 : tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
12720 : 638 : if (WILDCARD_TYPE_P (non_reference (obtype)))
12721 : : /* We don't know what the eventual obtype quals will be. */
12722 : 384 : goto dependent;
12723 : 508 : auto direct_type = [](tree t){
12724 : 254 : if (INDIRECT_TYPE_P (t))
12725 : 146 : return TREE_TYPE (t);
12726 : : return t;
12727 : : };
12728 : 254 : int const quals = cp_type_quals (type)
12729 : 254 : | cp_type_quals (direct_type (obtype));
12730 : 254 : type = cp_build_qualified_type (type, quals);
12731 : 254 : type = build_reference_type (type);
12732 : : }
12733 : : }
12734 : 14037844 : else if (error_operand_p (expr))
12735 : 0 : type = error_mark_node;
12736 : 14037844 : else if (expr == current_class_ptr)
12737 : : /* If the expression is just "this", we want the
12738 : : cv-unqualified pointer for the "this" type. */
12739 : 0 : type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
12740 : :
12741 : 254 : if (!type)
12742 : : {
12743 : : /* Otherwise, where T is the type of e, if e is an lvalue,
12744 : : decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
12745 : 14037952 : cp_lvalue_kind clk = lvalue_kind (expr);
12746 : 14037952 : type = unlowered_expr_type (expr);
12747 : 14037952 : gcc_assert (!TYPE_REF_P (type));
12748 : :
12749 : : /* For vector types, pick a non-opaque variant. */
12750 : 14037952 : if (VECTOR_TYPE_P (type))
12751 : 127 : type = strip_typedefs (type);
12752 : :
12753 : 14037952 : if (clk != clk_none && !(clk & clk_class))
12754 : 2169560 : type = cp_build_reference_type (type, (clk & clk_rvalueref));
12755 : : }
12756 : : }
12757 : :
12758 : : return type;
12759 : 19023105 : }
12760 : :
12761 : : /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
12762 : : __has_nothrow_copy, depending on assign_p. Returns true iff all
12763 : : the copy {ctor,assign} fns are nothrow. */
12764 : :
12765 : : static bool
12766 : 279 : classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
12767 : : {
12768 : 279 : tree fns = NULL_TREE;
12769 : :
12770 : 279 : if (assign_p || TYPE_HAS_COPY_CTOR (type))
12771 : 276 : fns = get_class_binding (type, assign_p ? assign_op_identifier
12772 : : : ctor_identifier);
12773 : :
12774 : 279 : bool saw_copy = false;
12775 : 696 : for (ovl_iterator iter (fns); iter; ++iter)
12776 : : {
12777 : 441 : tree fn = *iter;
12778 : :
12779 : 441 : if (copy_fn_p (fn) > 0)
12780 : : {
12781 : 423 : saw_copy = true;
12782 : 423 : if (!maybe_instantiate_noexcept (fn)
12783 : 423 : || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
12784 : 192 : return false;
12785 : : }
12786 : : }
12787 : :
12788 : 87 : return saw_copy;
12789 : : }
12790 : :
12791 : : /* Return true if DERIVED is pointer interconvertible base of BASE. */
12792 : :
12793 : : static bool
12794 : 128 : pointer_interconvertible_base_of_p (tree base, tree derived)
12795 : : {
12796 : 128 : if (base == error_mark_node || derived == error_mark_node)
12797 : : return false;
12798 : 128 : base = TYPE_MAIN_VARIANT (base);
12799 : 128 : derived = TYPE_MAIN_VARIANT (derived);
12800 : 117 : if (!NON_UNION_CLASS_TYPE_P (base)
12801 : 245 : || !NON_UNION_CLASS_TYPE_P (derived))
12802 : : return false;
12803 : :
12804 : 117 : if (same_type_p (base, derived))
12805 : : return true;
12806 : :
12807 : 86 : if (!std_layout_type_p (derived))
12808 : : return false;
12809 : :
12810 : 81 : return uniquely_derived_from_p (base, derived);
12811 : : }
12812 : :
12813 : : /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
12814 : : return true if MEMBERTYPE is the type of the first non-static data member
12815 : : of TYPE or for unions of any members. */
12816 : : static bool
12817 : 696 : first_nonstatic_data_member_p (tree type, tree membertype)
12818 : : {
12819 : 1416 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
12820 : : {
12821 : 1329 : if (TREE_CODE (field) != FIELD_DECL)
12822 : 159 : continue;
12823 : 1170 : if (DECL_FIELD_IS_BASE (field) && is_empty_field (field))
12824 : 60 : continue;
12825 : 1110 : if (DECL_FIELD_IS_BASE (field))
12826 : 45 : return first_nonstatic_data_member_p (TREE_TYPE (field), membertype);
12827 : 1065 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
12828 : : {
12829 : 237 : if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
12830 : 156 : || std_layout_type_p (TREE_TYPE (field)))
12831 : 324 : && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
12832 : : return true;
12833 : : }
12834 : 828 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
12835 : : membertype))
12836 : : return true;
12837 : 596 : if (TREE_CODE (type) != UNION_TYPE)
12838 : : return false;
12839 : : }
12840 : : return false;
12841 : : }
12842 : :
12843 : : /* Fold __builtin_is_pointer_interconvertible_with_class call. */
12844 : :
12845 : : tree
12846 : 605 : fold_builtin_is_pointer_inverconvertible_with_class (location_t loc, int nargs,
12847 : : tree *args)
12848 : : {
12849 : : /* Unless users call the builtin directly, the following 3 checks should be
12850 : : ensured from std::is_pointer_interconvertible_with_class function
12851 : : template. */
12852 : 605 : if (nargs != 1)
12853 : : {
12854 : 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
12855 : : "needs a single argument");
12856 : 6 : return boolean_false_node;
12857 : : }
12858 : 599 : tree arg = args[0];
12859 : 599 : if (error_operand_p (arg))
12860 : 0 : return boolean_false_node;
12861 : 599 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg)))
12862 : : {
12863 : 6 : error_at (loc, "%<__builtin_is_pointer_interconvertible_with_class%> "
12864 : : "argument is not pointer to member");
12865 : 6 : return boolean_false_node;
12866 : : }
12867 : :
12868 : 593 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg)))
12869 : 26 : return boolean_false_node;
12870 : :
12871 : 567 : tree membertype = TREE_TYPE (TREE_TYPE (arg));
12872 : 567 : tree basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg));
12873 : 567 : if (!complete_type_or_else (basetype, NULL_TREE))
12874 : 3 : return boolean_false_node;
12875 : :
12876 : 564 : if (TREE_CODE (basetype) != UNION_TYPE
12877 : 564 : && !std_layout_type_p (basetype))
12878 : 36 : return boolean_false_node;
12879 : :
12880 : 528 : if (!first_nonstatic_data_member_p (basetype, membertype))
12881 : 161 : return boolean_false_node;
12882 : :
12883 : 367 : if (TREE_CODE (arg) == PTRMEM_CST)
12884 : 76 : arg = cplus_expand_constant (arg);
12885 : :
12886 : 367 : if (integer_nonzerop (arg))
12887 : 22 : return boolean_false_node;
12888 : 345 : if (integer_zerop (arg))
12889 : 73 : return boolean_true_node;
12890 : :
12891 : 272 : return fold_build2 (EQ_EXPR, boolean_type_node, arg,
12892 : : build_zero_cst (TREE_TYPE (arg)));
12893 : : }
12894 : :
12895 : : /* Helper function for is_corresponding_member_aggr. Return true if
12896 : : MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
12897 : : union or structure BASETYPE. */
12898 : :
12899 : : static bool
12900 : 96 : is_corresponding_member_union (tree basetype, tree membertype, tree arg)
12901 : : {
12902 : 231 : for (tree field = TYPE_FIELDS (basetype); field; field = DECL_CHAIN (field))
12903 : 201 : if (TREE_CODE (field) != FIELD_DECL || DECL_BIT_FIELD_TYPE (field))
12904 : 36 : continue;
12905 : 165 : else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field),
12906 : : membertype))
12907 : : {
12908 : 54 : if (TREE_CODE (arg) != INTEGER_CST
12909 : 54 : || tree_int_cst_equal (arg, byte_position (field)))
12910 : 54 : return true;
12911 : : }
12912 : 111 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
12913 : : {
12914 : 18 : tree narg = arg;
12915 : 18 : if (TREE_CODE (basetype) != UNION_TYPE
12916 : 0 : && TREE_CODE (narg) == INTEGER_CST)
12917 : 0 : narg = size_binop (MINUS_EXPR, arg, byte_position (field));
12918 : 18 : if (is_corresponding_member_union (TREE_TYPE (field),
12919 : : membertype, narg))
12920 : : return true;
12921 : : }
12922 : : return false;
12923 : : }
12924 : :
12925 : : /* Helper function for fold_builtin_is_corresponding_member call.
12926 : : Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
12927 : : MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
12928 : : boolean_true_node if they are corresponding members, or for
12929 : : non-constant ARG2 the highest member offset for corresponding
12930 : : members. */
12931 : :
12932 : : static tree
12933 : 550 : is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1,
12934 : : tree arg1, tree basetype2, tree membertype2,
12935 : : tree arg2)
12936 : : {
12937 : 550 : tree field1 = TYPE_FIELDS (basetype1);
12938 : 550 : tree field2 = TYPE_FIELDS (basetype2);
12939 : 550 : tree ret = boolean_false_node;
12940 : 2402 : while (1)
12941 : : {
12942 : 1476 : bool r = next_common_initial_sequence (field1, field2);
12943 : 1476 : if (field1 == NULL_TREE || field2 == NULL_TREE)
12944 : : break;
12945 : 1350 : if (r
12946 : 1050 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1),
12947 : : membertype1)
12948 : 1872 : && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2),
12949 : : membertype2))
12950 : : {
12951 : 516 : tree pos = byte_position (field1);
12952 : 516 : if (TREE_CODE (arg1) == INTEGER_CST
12953 : 516 : && tree_int_cst_equal (arg1, pos))
12954 : : {
12955 : 88 : if (TREE_CODE (arg2) == INTEGER_CST)
12956 : 88 : return boolean_true_node;
12957 : : return pos;
12958 : : }
12959 : 428 : else if (TREE_CODE (arg1) != INTEGER_CST)
12960 : 1208 : ret = pos;
12961 : : }
12962 : 1668 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1))
12963 : 960 : && ANON_AGGR_TYPE_P (TREE_TYPE (field2)))
12964 : : {
12965 : 126 : if ((!lookup_attribute ("no_unique_address",
12966 : 126 : DECL_ATTRIBUTES (field1)))
12967 : 126 : != !lookup_attribute ("no_unique_address",
12968 : 126 : DECL_ATTRIBUTES (field2)))
12969 : : break;
12970 : 126 : if (!tree_int_cst_equal (bit_position (field1),
12971 : 126 : bit_position (field2)))
12972 : : break;
12973 : 108 : bool overlap = true;
12974 : 108 : tree pos = byte_position (field1);
12975 : 108 : if (TREE_CODE (arg1) == INTEGER_CST)
12976 : : {
12977 : 36 : tree off1 = fold_convert (sizetype, arg1);
12978 : 36 : tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (field1));
12979 : 36 : if (tree_int_cst_lt (off1, pos)
12980 : 36 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz1), off1))
12981 : : overlap = false;
12982 : : }
12983 : 108 : if (TREE_CODE (arg2) == INTEGER_CST)
12984 : : {
12985 : 36 : tree off2 = fold_convert (sizetype, arg2);
12986 : 36 : tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (field2));
12987 : 36 : if (tree_int_cst_lt (off2, pos)
12988 : 36 : || tree_int_cst_le (size_binop (PLUS_EXPR, pos, sz2), off2))
12989 : : overlap = false;
12990 : : }
12991 : 90 : if (overlap
12992 : 90 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1))
12993 : 129 : && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2)))
12994 : : {
12995 : 39 : tree narg1 = arg1;
12996 : 39 : if (TREE_CODE (arg1) == INTEGER_CST)
12997 : 9 : narg1 = size_binop (MINUS_EXPR,
12998 : : fold_convert (sizetype, arg1), pos);
12999 : 39 : tree narg2 = arg2;
13000 : 39 : if (TREE_CODE (arg2) == INTEGER_CST)
13001 : 9 : narg2 = size_binop (MINUS_EXPR,
13002 : : fold_convert (sizetype, arg2), pos);
13003 : 39 : tree t1 = TREE_TYPE (field1);
13004 : 39 : tree t2 = TREE_TYPE (field2);
13005 : 39 : tree nret = is_corresponding_member_aggr (loc, t1, membertype1,
13006 : : narg1, t2, membertype2,
13007 : : narg2);
13008 : 39 : if (nret != boolean_false_node)
13009 : : {
13010 : 39 : if (nret == boolean_true_node)
13011 : : return nret;
13012 : 30 : if (TREE_CODE (arg1) == INTEGER_CST)
13013 : 0 : return size_binop (PLUS_EXPR, nret, pos);
13014 : 30 : ret = size_binop (PLUS_EXPR, nret, pos);
13015 : : }
13016 : : }
13017 : 69 : else if (overlap
13018 : 51 : && TREE_CODE (TREE_TYPE (field1)) == UNION_TYPE
13019 : 120 : && TREE_CODE (TREE_TYPE (field2)) == UNION_TYPE)
13020 : : {
13021 : 51 : tree narg1 = arg1;
13022 : 51 : if (TREE_CODE (arg1) == INTEGER_CST)
13023 : 9 : narg1 = size_binop (MINUS_EXPR,
13024 : : fold_convert (sizetype, arg1), pos);
13025 : 51 : tree narg2 = arg2;
13026 : 51 : if (TREE_CODE (arg2) == INTEGER_CST)
13027 : 9 : narg2 = size_binop (MINUS_EXPR,
13028 : : fold_convert (sizetype, arg2), pos);
13029 : 51 : if (is_corresponding_member_union (TREE_TYPE (field1),
13030 : : membertype1, narg1)
13031 : 51 : && is_corresponding_member_union (TREE_TYPE (field2),
13032 : : membertype2, narg2))
13033 : : {
13034 : 27 : sorry_at (loc, "%<__builtin_is_corresponding_member%> "
13035 : : "not well defined for anonymous unions");
13036 : 27 : return boolean_false_node;
13037 : : }
13038 : : }
13039 : : }
13040 : 1208 : if (!r)
13041 : : break;
13042 : 926 : field1 = DECL_CHAIN (field1);
13043 : 926 : field2 = DECL_CHAIN (field2);
13044 : 926 : }
13045 : : return ret;
13046 : : }
13047 : :
13048 : : /* Fold __builtin_is_corresponding_member call. */
13049 : :
13050 : : tree
13051 : 797 : fold_builtin_is_corresponding_member (location_t loc, int nargs,
13052 : : tree *args)
13053 : : {
13054 : : /* Unless users call the builtin directly, the following 3 checks should be
13055 : : ensured from std::is_corresponding_member function template. */
13056 : 797 : if (nargs != 2)
13057 : : {
13058 : 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13059 : : "needs two arguments");
13060 : 9 : return boolean_false_node;
13061 : : }
13062 : 788 : tree arg1 = args[0];
13063 : 788 : tree arg2 = args[1];
13064 : 788 : if (error_operand_p (arg1) || error_operand_p (arg2))
13065 : 0 : return boolean_false_node;
13066 : 812 : if (!TYPE_PTRMEM_P (TREE_TYPE (arg1))
13067 : 806 : || !TYPE_PTRMEM_P (TREE_TYPE (arg2)))
13068 : : {
13069 : 9 : error_at (loc, "%<__builtin_is_corresponding_member%> "
13070 : : "argument is not pointer to member");
13071 : 9 : return boolean_false_node;
13072 : : }
13073 : :
13074 : 779 : if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1))
13075 : 779 : || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2)))
13076 : 18 : return boolean_false_node;
13077 : :
13078 : 761 : tree membertype1 = TREE_TYPE (TREE_TYPE (arg1));
13079 : 761 : tree basetype1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1));
13080 : 761 : if (!complete_type_or_else (basetype1, NULL_TREE))
13081 : 12 : return boolean_false_node;
13082 : :
13083 : 749 : tree membertype2 = TREE_TYPE (TREE_TYPE (arg2));
13084 : 749 : tree basetype2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2));
13085 : 749 : if (!complete_type_or_else (basetype2, NULL_TREE))
13086 : 12 : return boolean_false_node;
13087 : :
13088 : 719 : if (!NON_UNION_CLASS_TYPE_P (basetype1)
13089 : 719 : || !NON_UNION_CLASS_TYPE_P (basetype2)
13090 : 719 : || !std_layout_type_p (basetype1)
13091 : 1406 : || !std_layout_type_p (basetype2))
13092 : 68 : return boolean_false_node;
13093 : :
13094 : : /* If the member types aren't layout compatible, then they
13095 : : can't be corresponding members. */
13096 : 669 : if (!layout_compatible_type_p (membertype1, membertype2))
13097 : 36 : return boolean_false_node;
13098 : :
13099 : 633 : if (TREE_CODE (arg1) == PTRMEM_CST)
13100 : 250 : arg1 = cplus_expand_constant (arg1);
13101 : 633 : if (TREE_CODE (arg2) == PTRMEM_CST)
13102 : 256 : arg2 = cplus_expand_constant (arg2);
13103 : :
13104 : 633 : if (null_member_pointer_value_p (arg1)
13105 : 633 : || null_member_pointer_value_p (arg2))
13106 : 18 : return boolean_false_node;
13107 : :
13108 : 615 : if (TREE_CODE (arg1) == INTEGER_CST
13109 : 253 : && TREE_CODE (arg2) == INTEGER_CST
13110 : 868 : && !tree_int_cst_equal (arg1, arg2))
13111 : 104 : return boolean_false_node;
13112 : :
13113 : 511 : if (TREE_CODE (arg2) == INTEGER_CST
13114 : 149 : && TREE_CODE (arg1) != INTEGER_CST)
13115 : : {
13116 : : std::swap (arg1, arg2);
13117 : : std::swap (membertype1, membertype2);
13118 : : std::swap (basetype1, basetype2);
13119 : : }
13120 : :
13121 : 511 : tree ret = is_corresponding_member_aggr (loc, basetype1, membertype1, arg1,
13122 : : basetype2, membertype2, arg2);
13123 : 511 : if (TREE_TYPE (ret) == boolean_type_node)
13124 : : return ret;
13125 : : /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
13126 : : already returns boolean_{true,false}_node whether those particular
13127 : : members are corresponding members or not. Otherwise, if only
13128 : : one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
13129 : : above), it returns boolean_false_node if it is certainly not a
13130 : : corresponding member and otherwise we need to do a runtime check that
13131 : : those two OFFSET_TYPE offsets are equal.
13132 : : If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
13133 : : returns the largest offset at which the members would be corresponding
13134 : : members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
13135 : 296 : gcc_assert (TREE_CODE (arg2) != INTEGER_CST);
13136 : 296 : if (TREE_CODE (arg1) == INTEGER_CST)
13137 : 0 : return fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13138 : : fold_convert (TREE_TYPE (arg1), arg2));
13139 : 296 : ret = fold_build2 (LE_EXPR, boolean_type_node,
13140 : : fold_convert (pointer_sized_int_node, arg1),
13141 : : fold_convert (pointer_sized_int_node, ret));
13142 : 296 : return fold_build2 (TRUTH_AND_EXPR, boolean_type_node, ret,
13143 : : fold_build2 (EQ_EXPR, boolean_type_node, arg1,
13144 : : fold_convert (TREE_TYPE (arg1), arg2)));
13145 : : }
13146 : :
13147 : : /* [basic.types] 8. True iff TYPE is an object type. */
13148 : :
13149 : : static bool
13150 : 1628095 : object_type_p (const_tree type)
13151 : : {
13152 : 1628095 : return (TREE_CODE (type) != FUNCTION_TYPE
13153 : 0 : && !TYPE_REF_P (type)
13154 : 1628095 : && !VOID_TYPE_P (type));
13155 : : }
13156 : :
13157 : : /* Actually evaluates the trait. */
13158 : :
13159 : : static bool
13160 : 8741350 : trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
13161 : : {
13162 : 8741350 : enum tree_code type_code1;
13163 : 8741350 : tree t;
13164 : :
13165 : 8741350 : type_code1 = TREE_CODE (type1);
13166 : :
13167 : 8741350 : switch (kind)
13168 : : {
13169 : 317 : case CPTK_HAS_NOTHROW_ASSIGN:
13170 : 317 : type1 = strip_array_types (type1);
13171 : 601 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
13172 : 601 : && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
13173 : 173 : || (CLASS_TYPE_P (type1)
13174 : 129 : && classtype_has_nothrow_assign_or_copy_p (type1,
13175 : : true))));
13176 : :
13177 : 215 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
13178 : 215 : type1 = strip_array_types (type1);
13179 : 215 : return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
13180 : 215 : || (CLASS_TYPE_P (type1)
13181 : 93 : && (t = locate_ctor (type1))
13182 : 60 : && maybe_instantiate_noexcept (t)
13183 : 58 : && TYPE_NOTHROW_P (TREE_TYPE (t))));
13184 : :
13185 : 305 : case CPTK_HAS_NOTHROW_COPY:
13186 : 305 : type1 = strip_array_types (type1);
13187 : 305 : return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
13188 : 305 : || (CLASS_TYPE_P (type1)
13189 : 150 : && classtype_has_nothrow_assign_or_copy_p (type1, false)));
13190 : :
13191 : 517 : case CPTK_HAS_TRIVIAL_ASSIGN:
13192 : : /* ??? The standard seems to be missing the "or array of such a class
13193 : : type" wording for this trait. */
13194 : 517 : type1 = strip_array_types (type1);
13195 : 1016 : return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
13196 : 1001 : && (trivial_type_p (type1)
13197 : 307 : || (CLASS_TYPE_P (type1)
13198 : 222 : && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
13199 : :
13200 : 503 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
13201 : 503 : type1 = strip_array_types (type1);
13202 : 503 : return (trivial_type_p (type1)
13203 : 503 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
13204 : :
13205 : 526 : case CPTK_HAS_TRIVIAL_COPY:
13206 : : /* ??? The standard seems to be missing the "or array of such a class
13207 : : type" wording for this trait. */
13208 : 526 : type1 = strip_array_types (type1);
13209 : 878 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
13210 : 863 : || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
13211 : :
13212 : 25251 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
13213 : 25251 : type1 = strip_array_types (type1);
13214 : 28497 : return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
13215 : 28490 : || (CLASS_TYPE_P (type1)
13216 : 3186 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
13217 : :
13218 : 15079 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
13219 : 15079 : return type_has_unique_obj_representations (type1);
13220 : :
13221 : 264 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
13222 : 264 : return type_has_virtual_destructor (type1);
13223 : :
13224 : 56832 : case CPTK_IS_ABSTRACT:
13225 : 56832 : return ABSTRACT_CLASS_TYPE_P (type1);
13226 : :
13227 : 813 : case CPTK_IS_AGGREGATE:
13228 : 813 : return CP_AGGREGATE_TYPE_P (type1);
13229 : :
13230 : 183444 : case CPTK_IS_ARRAY:
13231 : 183444 : return (type_code1 == ARRAY_TYPE
13232 : : /* We don't want to report T[0] as being an array type.
13233 : : This is for compatibility with an implementation of
13234 : : std::is_array by template argument deduction, because
13235 : : compute_array_index_type_loc rejects a zero-size array
13236 : : in SFINAE context. */
13237 : 183444 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
13238 : :
13239 : 530019 : case CPTK_IS_ASSIGNABLE:
13240 : 530019 : return is_xible (MODIFY_EXPR, type1, type2);
13241 : :
13242 : 162656 : case CPTK_IS_BASE_OF:
13243 : 162565 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
13244 : 305858 : && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
13245 : 134164 : || DERIVED_FROM_P (type1, type2)));
13246 : :
13247 : 23658 : case CPTK_IS_BOUNDED_ARRAY:
13248 : 23658 : return (type_code1 == ARRAY_TYPE
13249 : 3525 : && TYPE_DOMAIN (type1)
13250 : : /* We don't want to report T[0] as being a bounded array type.
13251 : : This is for compatibility with an implementation of
13252 : : std::is_bounded_array by template argument deduction, because
13253 : : compute_array_index_type_loc rejects a zero-size array
13254 : : in SFINAE context. */
13255 : 27047 : && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
13256 : :
13257 : 157625 : case CPTK_IS_CLASS:
13258 : 157625 : return NON_UNION_CLASS_TYPE_P (type1);
13259 : :
13260 : 189573 : case CPTK_IS_CONST:
13261 : 189573 : return CP_TYPE_CONST_P (type1);
13262 : :
13263 : 1006640 : case CPTK_IS_CONSTRUCTIBLE:
13264 : 1006640 : return is_xible (INIT_EXPR, type1, type2);
13265 : :
13266 : 909998 : case CPTK_IS_CONVERTIBLE:
13267 : 909998 : return is_convertible (type1, type2);
13268 : :
13269 : 212269 : case CPTK_IS_EMPTY:
13270 : 212269 : return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
13271 : :
13272 : 357291 : case CPTK_IS_ENUM:
13273 : 357291 : return type_code1 == ENUMERAL_TYPE;
13274 : :
13275 : 381389 : case CPTK_IS_FINAL:
13276 : 381389 : return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
13277 : :
13278 : 506744 : case CPTK_IS_FUNCTION:
13279 : 506744 : return type_code1 == FUNCTION_TYPE;
13280 : :
13281 : 7259 : case CPTK_IS_INVOCABLE:
13282 : 7259 : return !error_operand_p (build_invoke (type1, type2, tf_none));
13283 : :
13284 : 189 : case CPTK_IS_LAYOUT_COMPATIBLE:
13285 : 189 : return layout_compatible_type_p (type1, type2);
13286 : :
13287 : 209 : case CPTK_IS_LITERAL_TYPE:
13288 : 209 : return literal_type_p (type1);
13289 : :
13290 : 87458 : case CPTK_IS_MEMBER_FUNCTION_POINTER:
13291 : 87458 : return TYPE_PTRMEMFUNC_P (type1);
13292 : :
13293 : 87330 : case CPTK_IS_MEMBER_OBJECT_POINTER:
13294 : 87330 : return TYPE_PTRDATAMEM_P (type1);
13295 : :
13296 : 24312 : case CPTK_IS_MEMBER_POINTER:
13297 : 24312 : return TYPE_PTRMEM_P (type1);
13298 : :
13299 : 245301 : case CPTK_IS_NOTHROW_ASSIGNABLE:
13300 : 245301 : return is_nothrow_xible (MODIFY_EXPR, type1, type2);
13301 : :
13302 : 487469 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
13303 : 487469 : return is_nothrow_xible (INIT_EXPR, type1, type2);
13304 : :
13305 : 27011 : case CPTK_IS_NOTHROW_CONVERTIBLE:
13306 : 27011 : return is_nothrow_convertible (type1, type2);
13307 : :
13308 : 1750 : case CPTK_IS_NOTHROW_INVOCABLE:
13309 : 1750 : return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none);
13310 : :
13311 : 114093 : case CPTK_IS_OBJECT:
13312 : 114093 : return object_type_p (type1);
13313 : :
13314 : 128 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
13315 : 128 : return pointer_interconvertible_base_of_p (type1, type2);
13316 : :
13317 : 11364 : case CPTK_IS_POD:
13318 : 11364 : return pod_type_p (type1);
13319 : :
13320 : 105116 : case CPTK_IS_POINTER:
13321 : 105116 : return TYPE_PTR_P (type1);
13322 : :
13323 : 261 : case CPTK_IS_POLYMORPHIC:
13324 : 261 : return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
13325 : :
13326 : 688327 : case CPTK_IS_REFERENCE:
13327 : 688327 : return type_code1 == REFERENCE_TYPE;
13328 : :
13329 : 1577505 : case CPTK_IS_SAME:
13330 : 1577505 : return same_type_p (type1, type2);
13331 : :
13332 : 373 : case CPTK_IS_SCOPED_ENUM:
13333 : 373 : return SCOPED_ENUM_P (type1);
13334 : :
13335 : 47533 : case CPTK_IS_STD_LAYOUT:
13336 : 47533 : return std_layout_type_p (type1);
13337 : :
13338 : 28944 : case CPTK_IS_TRIVIAL:
13339 : 28944 : return trivial_type_p (type1);
13340 : :
13341 : 7137 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
13342 : 7137 : return is_trivially_xible (MODIFY_EXPR, type1, type2);
13343 : :
13344 : 54486 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
13345 : 54486 : return is_trivially_xible (INIT_EXPR, type1, type2);
13346 : :
13347 : 61385 : case CPTK_IS_TRIVIALLY_COPYABLE:
13348 : 61385 : return trivially_copyable_p (type1);
13349 : :
13350 : 21825 : case CPTK_IS_UNBOUNDED_ARRAY:
13351 : 21825 : return array_of_unknown_bound_p (type1);
13352 : :
13353 : 36016 : case CPTK_IS_UNION:
13354 : 36016 : return type_code1 == UNION_TYPE;
13355 : :
13356 : 679 : case CPTK_IS_VIRTUAL_BASE_OF:
13357 : 616 : return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
13358 : 1280 : && lookup_base (type2, type1, ba_require_virtual,
13359 : : NULL, tf_none) != NULL_TREE);
13360 : :
13361 : 185616 : case CPTK_IS_VOLATILE:
13362 : 185616 : return CP_TYPE_VOLATILE_P (type1);
13363 : :
13364 : 57163 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
13365 : 57163 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
13366 : :
13367 : 53109 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
13368 : 53109 : return ref_xes_from_temporary (type1, type2, /*direct_init=*/false);
13369 : :
13370 : 74 : case CPTK_IS_DEDUCIBLE:
13371 : 74 : return type_targs_deducible_from (type1, type2);
13372 : :
13373 : : /* __array_rank is handled in finish_trait_expr. */
13374 : 0 : case CPTK_RANK:
13375 : 0 : gcc_unreachable ();
13376 : :
13377 : : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
13378 : : case CPTK_##CODE:
13379 : : #include "cp-trait.def"
13380 : : #undef DEFTRAIT_TYPE
13381 : : /* Type-yielding traits are handled in finish_trait_type. */
13382 : : break;
13383 : : }
13384 : :
13385 : 0 : gcc_unreachable ();
13386 : : }
13387 : :
13388 : : /* Returns true if TYPE meets the requirements for the specified KIND,
13389 : : false otherwise.
13390 : :
13391 : : When KIND == 1, TYPE must be an array of unknown bound,
13392 : : or (possibly cv-qualified) void, or a complete type.
13393 : :
13394 : : When KIND == 2, TYPE must be a complete type, or array of complete type,
13395 : : or (possibly cv-qualified) void.
13396 : :
13397 : : When KIND == 3:
13398 : : If TYPE is a non-union class type, it must be complete.
13399 : :
13400 : : When KIND == 4:
13401 : : If TYPE is a class type, it must be complete. */
13402 : :
13403 : : static bool
13404 : 8343335 : check_trait_type (tree type, int kind = 1)
13405 : : {
13406 : 8343335 : if (type == NULL_TREE)
13407 : : return true;
13408 : :
13409 : 8343335 : if (TREE_CODE (type) == TREE_VEC)
13410 : : {
13411 : 2596179 : for (tree arg : tree_vec_range (type))
13412 : 1041163 : if (!check_trait_type (arg, kind))
13413 : 21 : return false;
13414 : 1555016 : return true;
13415 : : }
13416 : :
13417 : 6788298 : if (kind == 1 && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
13418 : : return true; // Array of unknown bound. Don't care about completeness.
13419 : :
13420 : 6787808 : if (kind == 3 && !NON_UNION_CLASS_TYPE_P (type))
13421 : : return true; // Not a non-union class type. Don't care about completeness.
13422 : :
13423 : 6688837 : if (kind == 4 && TREE_CODE (type) == ARRAY_TYPE)
13424 : : return true; // Not a class type. Don't care about completeness.
13425 : :
13426 : 6688412 : if (VOID_TYPE_P (type))
13427 : : return true;
13428 : :
13429 : 6687382 : type = complete_type (strip_array_types (type));
13430 : 6687382 : if (!COMPLETE_TYPE_P (type)
13431 : 149 : && cxx_incomplete_type_diagnostic (NULL_TREE, type, DK_PERMERROR)
13432 : 6687531 : && !flag_permissive)
13433 : : return false;
13434 : : return true;
13435 : : }
13436 : :
13437 : : /* True iff the conversion (if any) would be a direct reference
13438 : : binding, not requiring complete types. This is LWG2939. */
13439 : :
13440 : : static bool
13441 : 2604945 : same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2)
13442 : : {
13443 : 2604945 : tree from, to;
13444 : 2604945 : switch (kind)
13445 : : {
13446 : : /* These put the target type first. */
13447 : : case CPTK_IS_CONSTRUCTIBLE:
13448 : : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
13449 : : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
13450 : : case CPTK_IS_INVOCABLE:
13451 : : case CPTK_IS_NOTHROW_INVOCABLE:
13452 : : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
13453 : : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
13454 : : to = type1;
13455 : : from = type2;
13456 : : break;
13457 : :
13458 : : /* These put it second. */
13459 : 937009 : case CPTK_IS_CONVERTIBLE:
13460 : 937009 : case CPTK_IS_NOTHROW_CONVERTIBLE:
13461 : 937009 : to = type2;
13462 : 937009 : from = type1;
13463 : 937009 : break;
13464 : :
13465 : 0 : default:
13466 : 0 : gcc_unreachable ();
13467 : : }
13468 : :
13469 : 2604945 : if (TREE_CODE (to) != REFERENCE_TYPE || !from)
13470 : : return false;
13471 : 165845 : if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1)
13472 : 5724 : from = TREE_VEC_ELT (from, 0);
13473 : 165845 : return (TYPE_P (from)
13474 : 327901 : && (same_type_ignoring_top_level_qualifiers_p
13475 : 162056 : (non_reference (to), non_reference (from))));
13476 : : }
13477 : :
13478 : : /* [defns.referenceable] True iff TYPE is a referenceable type. */
13479 : :
13480 : : static bool
13481 : 1670113 : referenceable_type_p (const_tree type)
13482 : : {
13483 : 1670113 : return (TYPE_REF_P (type)
13484 : 1670461 : || object_type_p (type)
13485 : 1670461 : || (FUNC_OR_METHOD_TYPE_P (type)
13486 : 289 : && (type_memfn_quals (type) == TYPE_UNQUALIFIED
13487 : 233 : && type_memfn_rqual (type) == REF_QUAL_NONE)));
13488 : : }
13489 : :
13490 : : /* Process a trait expression. */
13491 : :
13492 : : tree
13493 : 11572711 : finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
13494 : : {
13495 : 11572711 : if (type1 == error_mark_node
13496 : 11572708 : || type2 == error_mark_node)
13497 : : return error_mark_node;
13498 : :
13499 : 11572708 : if (processing_template_decl)
13500 : : {
13501 : 2831933 : tree trait_expr = make_node (TRAIT_EXPR);
13502 : 2831933 : if (kind == CPTK_RANK)
13503 : 28430 : TREE_TYPE (trait_expr) = size_type_node;
13504 : : else
13505 : 2803503 : TREE_TYPE (trait_expr) = boolean_type_node;
13506 : 2831933 : TRAIT_EXPR_TYPE1 (trait_expr) = type1;
13507 : 2831933 : TRAIT_EXPR_TYPE2 (trait_expr) = type2;
13508 : 2831933 : TRAIT_EXPR_KIND (trait_expr) = kind;
13509 : 2831933 : TRAIT_EXPR_LOCATION (trait_expr) = loc;
13510 : 2831933 : return trait_expr;
13511 : : }
13512 : :
13513 : 8740775 : switch (kind)
13514 : : {
13515 : 26851 : case CPTK_HAS_NOTHROW_ASSIGN:
13516 : 26851 : case CPTK_HAS_TRIVIAL_ASSIGN:
13517 : 26851 : case CPTK_HAS_NOTHROW_CONSTRUCTOR:
13518 : 26851 : case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
13519 : 26851 : case CPTK_HAS_NOTHROW_COPY:
13520 : 26851 : case CPTK_HAS_TRIVIAL_COPY:
13521 : 26851 : case CPTK_HAS_TRIVIAL_DESTRUCTOR:
13522 : 26851 : if (!check_trait_type (type1))
13523 : 21 : return error_mark_node;
13524 : : break;
13525 : :
13526 : 164547 : case CPTK_IS_LITERAL_TYPE:
13527 : 164547 : case CPTK_IS_POD:
13528 : 164547 : case CPTK_IS_STD_LAYOUT:
13529 : 164547 : case CPTK_IS_TRIVIAL:
13530 : 164547 : case CPTK_IS_TRIVIALLY_COPYABLE:
13531 : 164547 : case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
13532 : 164547 : if (!check_trait_type (type1, /* kind = */ 2))
13533 : 33 : return error_mark_node;
13534 : : break;
13535 : :
13536 : 269641 : case CPTK_IS_ABSTRACT:
13537 : 269641 : case CPTK_IS_EMPTY:
13538 : 269641 : case CPTK_IS_POLYMORPHIC:
13539 : 269641 : case CPTK_HAS_VIRTUAL_DESTRUCTOR:
13540 : 269641 : if (!check_trait_type (type1, /* kind = */ 3))
13541 : 15 : return error_mark_node;
13542 : : break;
13543 : :
13544 : : /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
13545 : : type to know whether an array is an aggregate, so use kind=4 here. */
13546 : 382216 : case CPTK_IS_AGGREGATE:
13547 : 382216 : case CPTK_IS_FINAL:
13548 : 382216 : if (!check_trait_type (type1, /* kind = */ 4))
13549 : 14 : return error_mark_node;
13550 : : break;
13551 : :
13552 : 2604945 : case CPTK_IS_CONSTRUCTIBLE:
13553 : 2604945 : case CPTK_IS_CONVERTIBLE:
13554 : 2604945 : case CPTK_IS_INVOCABLE:
13555 : 2604945 : case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
13556 : 2604945 : case CPTK_IS_NOTHROW_CONVERTIBLE:
13557 : 2604945 : case CPTK_IS_NOTHROW_INVOCABLE:
13558 : 2604945 : case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
13559 : 2604945 : case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
13560 : 2604945 : case CPTK_REF_CONVERTS_FROM_TEMPORARY:
13561 : 2604945 : /* Don't check completeness for direct reference binding. */;
13562 : 2604945 : if (same_type_ref_bind_p (kind, type1, type2))
13563 : : break;
13564 : 3229478 : gcc_fallthrough ();
13565 : :
13566 : 3229478 : case CPTK_IS_ASSIGNABLE:
13567 : 3229478 : case CPTK_IS_NOTHROW_ASSIGNABLE:
13568 : 3229478 : case CPTK_IS_TRIVIALLY_ASSIGNABLE:
13569 : 3229478 : if (!check_trait_type (type1)
13570 : 3229478 : || !check_trait_type (type2))
13571 : 63 : return error_mark_node;
13572 : : break;
13573 : :
13574 : 162815 : case CPTK_IS_BASE_OF:
13575 : 162815 : case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
13576 : 162713 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
13577 : 143350 : && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
13578 : 297096 : && !complete_type_or_else (type2, NULL_TREE))
13579 : : /* We already issued an error. */
13580 : 31 : return error_mark_node;
13581 : : break;
13582 : :
13583 : 682 : case CPTK_IS_VIRTUAL_BASE_OF:
13584 : 619 : if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
13585 : 1286 : && !complete_type_or_else (type2, NULL_TREE))
13586 : : /* We already issued an error. */
13587 : 3 : return error_mark_node;
13588 : : break;
13589 : :
13590 : : case CPTK_IS_ARRAY:
13591 : : case CPTK_IS_BOUNDED_ARRAY:
13592 : : case CPTK_IS_CLASS:
13593 : : case CPTK_IS_CONST:
13594 : : case CPTK_IS_ENUM:
13595 : : case CPTK_IS_FUNCTION:
13596 : : case CPTK_IS_MEMBER_FUNCTION_POINTER:
13597 : : case CPTK_IS_MEMBER_OBJECT_POINTER:
13598 : : case CPTK_IS_MEMBER_POINTER:
13599 : : case CPTK_IS_OBJECT:
13600 : : case CPTK_IS_POINTER:
13601 : : case CPTK_IS_REFERENCE:
13602 : : case CPTK_IS_SAME:
13603 : : case CPTK_IS_SCOPED_ENUM:
13604 : : case CPTK_IS_UNBOUNDED_ARRAY:
13605 : : case CPTK_IS_UNION:
13606 : : case CPTK_IS_VOLATILE:
13607 : : case CPTK_RANK:
13608 : : break;
13609 : :
13610 : 198 : case CPTK_IS_LAYOUT_COMPATIBLE:
13611 : 198 : if (!array_of_unknown_bound_p (type1)
13612 : 181 : && TREE_CODE (type1) != VOID_TYPE
13613 : 372 : && !complete_type_or_else (type1, NULL_TREE))
13614 : : /* We already issued an error. */
13615 : 6 : return error_mark_node;
13616 : 192 : if (!array_of_unknown_bound_p (type2)
13617 : 167 : && TREE_CODE (type2) != VOID_TYPE
13618 : 352 : && !complete_type_or_else (type2, NULL_TREE))
13619 : : /* We already issued an error. */
13620 : 3 : return error_mark_node;
13621 : : break;
13622 : :
13623 : 74 : case CPTK_IS_DEDUCIBLE:
13624 : 74 : if (!DECL_TYPE_TEMPLATE_P (type1))
13625 : : {
13626 : 0 : error ("%qD is not a class or alias template", type1);
13627 : 0 : return error_mark_node;
13628 : : }
13629 : : break;
13630 : :
13631 : : #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
13632 : : case CPTK_##CODE:
13633 : : #include "cp-trait.def"
13634 : : #undef DEFTRAIT_TYPE
13635 : : /* Type-yielding traits are handled in finish_trait_type. */
13636 : 0 : gcc_unreachable ();
13637 : : }
13638 : :
13639 : 8740586 : tree val;
13640 : 8740586 : if (kind == CPTK_RANK)
13641 : : {
13642 : : size_t rank = 0;
13643 : 118 : for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1))
13644 : 78 : ++rank;
13645 : 40 : val = build_int_cst (size_type_node, rank);
13646 : : }
13647 : : else
13648 : 8740546 : val = (trait_expr_value (kind, type1, type2)
13649 : 8740546 : ? boolean_true_node : boolean_false_node);
13650 : :
13651 : 8740586 : return maybe_wrap_with_location (val, loc);
13652 : : }
13653 : :
13654 : : /* Process a trait type. */
13655 : :
13656 : : tree
13657 : 4090652 : finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
13658 : : tsubst_flags_t complain)
13659 : : {
13660 : 4090652 : if (type1 == error_mark_node
13661 : 4090649 : || type2 == error_mark_node)
13662 : : return error_mark_node;
13663 : :
13664 : 4090649 : if (processing_template_decl)
13665 : : {
13666 : 199692 : tree type = cxx_make_type (TRAIT_TYPE);
13667 : 199692 : TRAIT_TYPE_TYPE1 (type) = type1;
13668 : 199692 : TRAIT_TYPE_TYPE2 (type) = type2;
13669 : 199692 : TRAIT_TYPE_KIND_RAW (type) = build_int_cstu (integer_type_node, kind);
13670 : : /* These traits are intended to be used in the definition of the ::type
13671 : : member of the corresponding standard library type trait and aren't
13672 : : mangleable (and thus won't appear directly in template signatures),
13673 : : so structural equality should suffice. */
13674 : 199692 : SET_TYPE_STRUCTURAL_EQUALITY (type);
13675 : 199692 : return type;
13676 : : }
13677 : :
13678 : 3890957 : switch (kind)
13679 : : {
13680 : 715651 : case CPTK_ADD_LVALUE_REFERENCE:
13681 : : /* [meta.trans.ref]. */
13682 : 715651 : if (referenceable_type_p (type1))
13683 : 715578 : return cp_build_reference_type (type1, /*rval=*/false);
13684 : : return type1;
13685 : :
13686 : 42474 : case CPTK_ADD_POINTER:
13687 : : /* [meta.trans.ptr]. */
13688 : 42474 : if (VOID_TYPE_P (type1) || referenceable_type_p (type1))
13689 : : {
13690 : 42442 : if (TYPE_REF_P (type1))
13691 : 41362 : type1 = TREE_TYPE (type1);
13692 : 42442 : return build_pointer_type (type1);
13693 : : }
13694 : : return type1;
13695 : :
13696 : 912004 : case CPTK_ADD_RVALUE_REFERENCE:
13697 : : /* [meta.trans.ref]. */
13698 : 912004 : if (referenceable_type_p (type1))
13699 : 911958 : return cp_build_reference_type (type1, /*rval=*/true);
13700 : : return type1;
13701 : :
13702 : 159705 : case CPTK_DECAY:
13703 : 159705 : if (TYPE_REF_P (type1))
13704 : 25670 : type1 = TREE_TYPE (type1);
13705 : :
13706 : 159705 : if (TREE_CODE (type1) == ARRAY_TYPE)
13707 : 696 : return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2,
13708 : 696 : complain);
13709 : 159009 : else if (TREE_CODE (type1) == FUNCTION_TYPE)
13710 : 151 : return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain);
13711 : : else
13712 : 158858 : return cv_unqualified (type1);
13713 : :
13714 : 24288 : case CPTK_REMOVE_ALL_EXTENTS:
13715 : 24288 : return strip_array_types (type1);
13716 : :
13717 : 570742 : case CPTK_REMOVE_CV:
13718 : 570742 : return cv_unqualified (type1);
13719 : :
13720 : 147072 : case CPTK_REMOVE_CVREF:
13721 : 147072 : if (TYPE_REF_P (type1))
13722 : 75373 : type1 = TREE_TYPE (type1);
13723 : 147072 : return cv_unqualified (type1);
13724 : :
13725 : 50434 : case CPTK_REMOVE_EXTENT:
13726 : 50434 : if (TREE_CODE (type1) == ARRAY_TYPE)
13727 : 202 : type1 = TREE_TYPE (type1);
13728 : : return type1;
13729 : :
13730 : 10308 : case CPTK_REMOVE_POINTER:
13731 : 10308 : if (TYPE_PTR_P (type1))
13732 : 8242 : type1 = TREE_TYPE (type1);
13733 : : return type1;
13734 : :
13735 : 1135123 : case CPTK_REMOVE_REFERENCE:
13736 : 1135123 : if (TYPE_REF_P (type1))
13737 : 704344 : type1 = TREE_TYPE (type1);
13738 : : return type1;
13739 : :
13740 : 83619 : case CPTK_TYPE_PACK_ELEMENT:
13741 : 83619 : return finish_type_pack_element (type1, type2, complain);
13742 : :
13743 : 39537 : case CPTK_UNDERLYING_TYPE:
13744 : 39537 : return finish_underlying_type (type1);
13745 : :
13746 : : #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
13747 : : case CPTK_##CODE:
13748 : : #include "cp-trait.def"
13749 : : #undef DEFTRAIT_EXPR
13750 : : /* Expression-yielding traits are handled in finish_trait_expr. */
13751 : : case CPTK_BASES:
13752 : : case CPTK_DIRECT_BASES:
13753 : : /* BASES and DIRECT_BASES are handled in finish_bases. */
13754 : : break;
13755 : : }
13756 : :
13757 : 0 : gcc_unreachable ();
13758 : : }
13759 : :
13760 : : /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
13761 : : which is ignored for C++. */
13762 : :
13763 : : void
13764 : 0 : set_float_const_decimal64 (void)
13765 : : {
13766 : 0 : }
13767 : :
13768 : : void
13769 : 0 : clear_float_const_decimal64 (void)
13770 : : {
13771 : 0 : }
13772 : :
13773 : : bool
13774 : 1907953 : float_const_decimal64_p (void)
13775 : : {
13776 : 1907953 : return 0;
13777 : : }
13778 : :
13779 : :
13780 : : /* Return true if T designates the implied `this' parameter. */
13781 : :
13782 : : bool
13783 : 117930519 : is_this_parameter (tree t)
13784 : : {
13785 : 117930519 : if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
13786 : : return false;
13787 : 38040129 : gcc_assert (TREE_CODE (t) == PARM_DECL
13788 : : || (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t))
13789 : : || (cp_binding_oracle && VAR_P (t)));
13790 : : return true;
13791 : : }
13792 : :
13793 : : /* As above, or a C++23 explicit object parameter. */
13794 : :
13795 : : bool
13796 : 456 : is_object_parameter (tree t)
13797 : : {
13798 : 456 : if (is_this_parameter (t))
13799 : : return true;
13800 : 91 : if (TREE_CODE (t) != PARM_DECL)
13801 : : return false;
13802 : 34 : tree ctx = DECL_CONTEXT (t);
13803 : 34 : return (ctx && DECL_XOBJ_MEMBER_FUNCTION_P (ctx)
13804 : 62 : && t == DECL_ARGUMENTS (ctx));
13805 : : }
13806 : :
13807 : : /* Insert the deduced return type for an auto function. */
13808 : :
13809 : : void
13810 : 633247 : apply_deduced_return_type (tree fco, tree return_type)
13811 : : {
13812 : 633247 : tree result;
13813 : :
13814 : 633247 : if (return_type == error_mark_node)
13815 : : return;
13816 : :
13817 : 633244 : if (DECL_CONV_FN_P (fco))
13818 : 24 : DECL_NAME (fco) = make_conv_op_name (return_type);
13819 : :
13820 : 633244 : TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
13821 : :
13822 : 633244 : maybe_update_postconditions (fco);
13823 : :
13824 : : /* Apply the type to the result object. */
13825 : :
13826 : 633244 : result = DECL_RESULT (fco);
13827 : 633244 : if (result == NULL_TREE)
13828 : : return;
13829 : 631009 : if (TREE_TYPE (result) == return_type)
13830 : : return;
13831 : :
13832 : 631006 : if (!processing_template_decl && !VOID_TYPE_P (return_type)
13833 : 1057425 : && !complete_type_or_else (return_type, NULL_TREE))
13834 : : return;
13835 : :
13836 : : /* We already have a DECL_RESULT from start_preparsed_function.
13837 : : Now we need to redo the work it and allocate_struct_function
13838 : : did to reflect the new type. */
13839 : 631006 : result = build_decl (DECL_SOURCE_LOCATION (result), RESULT_DECL, NULL_TREE,
13840 : 631006 : TYPE_MAIN_VARIANT (return_type));
13841 : 631006 : DECL_ARTIFICIAL (result) = 1;
13842 : 631006 : DECL_IGNORED_P (result) = 1;
13843 : 631006 : cp_apply_type_quals_to_decl (cp_type_quals (return_type),
13844 : : result);
13845 : 631006 : DECL_RESULT (fco) = result;
13846 : :
13847 : 631006 : if (!processing_template_decl)
13848 : 631006 : if (function *fun = DECL_STRUCT_FUNCTION (fco))
13849 : : {
13850 : 630886 : bool aggr = aggregate_value_p (result, fco);
13851 : : #ifdef PCC_STATIC_STRUCT_RETURN
13852 : : fun->returns_pcc_struct = aggr;
13853 : : #endif
13854 : 630886 : fun->returns_struct = aggr;
13855 : : }
13856 : : }
13857 : :
13858 : : /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
13859 : : this is a right unary fold. Otherwise it is a left unary fold. */
13860 : :
13861 : : static tree
13862 : 546441 : finish_unary_fold_expr (location_t loc, tree expr, int op, tree_code dir)
13863 : : {
13864 : : /* Build a pack expansion (assuming expr has pack type). */
13865 : 546441 : if (!uses_parameter_packs (expr))
13866 : : {
13867 : 3 : error_at (location_of (expr), "operand of fold expression has no "
13868 : : "unexpanded parameter packs");
13869 : 3 : return error_mark_node;
13870 : : }
13871 : 546438 : tree pack = make_pack_expansion (expr);
13872 : :
13873 : : /* Build the fold expression. */
13874 : 546438 : tree code = build_int_cstu (integer_type_node, abs (op));
13875 : 546438 : tree fold = build_min_nt_loc (loc, dir, code, pack);
13876 : 546438 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
13877 : 546438 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
13878 : 546438 : FOLD_EXPR_OP (fold),
13879 : 546438 : FOLD_EXPR_MODIFY_P (fold));
13880 : 546438 : return fold;
13881 : : }
13882 : :
13883 : : tree
13884 : 17174 : finish_left_unary_fold_expr (location_t loc, tree expr, int op)
13885 : : {
13886 : 17174 : return finish_unary_fold_expr (loc, expr, op, UNARY_LEFT_FOLD_EXPR);
13887 : : }
13888 : :
13889 : : tree
13890 : 529267 : finish_right_unary_fold_expr (location_t loc, tree expr, int op)
13891 : : {
13892 : 529267 : return finish_unary_fold_expr (loc, expr, op, UNARY_RIGHT_FOLD_EXPR);
13893 : : }
13894 : :
13895 : : /* Build a binary fold expression over EXPR1 and EXPR2. The
13896 : : associativity of the fold is determined by EXPR1 and EXPR2 (whichever
13897 : : has an unexpanded parameter pack). */
13898 : :
13899 : : static tree
13900 : 13219 : finish_binary_fold_expr (location_t loc, tree pack, tree init,
13901 : : int op, tree_code dir)
13902 : : {
13903 : 13219 : pack = make_pack_expansion (pack);
13904 : 13219 : tree code = build_int_cstu (integer_type_node, abs (op));
13905 : 13219 : tree fold = build_min_nt_loc (loc, dir, code, pack, init);
13906 : 13219 : FOLD_EXPR_MODIFY_P (fold) = (op < 0);
13907 : 13219 : TREE_TYPE (fold) = build_dependent_operator_type (NULL_TREE,
13908 : 13219 : FOLD_EXPR_OP (fold),
13909 : 13219 : FOLD_EXPR_MODIFY_P (fold));
13910 : 13219 : return fold;
13911 : : }
13912 : :
13913 : : tree
13914 : 13219 : finish_binary_fold_expr (location_t loc, tree expr1, tree expr2, int op)
13915 : : {
13916 : : // Determine which expr has an unexpanded parameter pack and
13917 : : // set the pack and initial term.
13918 : 13219 : bool pack1 = uses_parameter_packs (expr1);
13919 : 13219 : bool pack2 = uses_parameter_packs (expr2);
13920 : 13219 : if (pack1 && !pack2)
13921 : 288 : return finish_binary_fold_expr (loc, expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
13922 : 12931 : else if (pack2 && !pack1)
13923 : 12931 : return finish_binary_fold_expr (loc, expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
13924 : : else
13925 : : {
13926 : 0 : if (pack1)
13927 : 0 : error ("both arguments in binary fold have unexpanded parameter packs");
13928 : : else
13929 : 0 : error ("no unexpanded parameter packs in binary fold");
13930 : : }
13931 : 0 : return error_mark_node;
13932 : : }
13933 : :
13934 : : /* Finish __builtin_launder (arg). */
13935 : :
13936 : : tree
13937 : 12381 : finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
13938 : : {
13939 : 12381 : tree orig_arg = arg;
13940 : 12381 : if (!type_dependent_expression_p (arg))
13941 : 84 : arg = decay_conversion (arg, complain);
13942 : 12381 : if (error_operand_p (arg))
13943 : 0 : return error_mark_node;
13944 : 12381 : if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
13945 : : {
13946 : 24 : error_at (loc, "type %qT of argument to %<__builtin_launder%> "
13947 : 24 : "is not a pointer to object type", TREE_TYPE (arg));
13948 : 24 : return error_mark_node;
13949 : : }
13950 : 12357 : if (processing_template_decl)
13951 : 12297 : arg = orig_arg;
13952 : 12357 : return build_call_expr_internal_loc (loc, IFN_LAUNDER,
13953 : 24714 : TREE_TYPE (arg), 1, arg);
13954 : : }
13955 : :
13956 : : /* Finish __builtin_convertvector (arg, type). */
13957 : :
13958 : : tree
13959 : 185 : cp_build_vec_convert (tree arg, location_t loc, tree type,
13960 : : tsubst_flags_t complain)
13961 : : {
13962 : 185 : if (error_operand_p (type))
13963 : 9 : return error_mark_node;
13964 : 176 : if (error_operand_p (arg))
13965 : 0 : return error_mark_node;
13966 : :
13967 : 176 : tree ret = NULL_TREE;
13968 : 176 : if (!type_dependent_expression_p (arg) && !dependent_type_p (type))
13969 : 194 : ret = c_build_vec_convert (cp_expr_loc_or_input_loc (arg),
13970 : : decay_conversion (arg, complain),
13971 : : loc, type, (complain & tf_error) != 0);
13972 : :
13973 : 176 : if (!processing_template_decl)
13974 : : return ret;
13975 : :
13976 : 24 : return build_call_expr_internal_loc (loc, IFN_VEC_CONVERT, type, 1, arg);
13977 : : }
13978 : :
13979 : : /* Finish __builtin_bit_cast (type, arg). */
13980 : :
13981 : : tree
13982 : 32758 : cp_build_bit_cast (location_t loc, tree type, tree arg,
13983 : : tsubst_flags_t complain)
13984 : : {
13985 : 32758 : if (error_operand_p (type))
13986 : 0 : return error_mark_node;
13987 : 32758 : if (!dependent_type_p (type))
13988 : : {
13989 : 23371 : if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
13990 : 9 : return error_mark_node;
13991 : 23362 : if (TREE_CODE (type) == ARRAY_TYPE)
13992 : : {
13993 : : /* std::bit_cast for destination ARRAY_TYPE is not possible,
13994 : : as functions may not return an array, so don't bother trying
13995 : : to support this (and then deal with VLAs etc.). */
13996 : 9 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
13997 : : "is an array type", type);
13998 : 9 : return error_mark_node;
13999 : : }
14000 : 23353 : if (!trivially_copyable_p (type))
14001 : : {
14002 : 18 : error_at (loc, "%<__builtin_bit_cast%> destination type %qT "
14003 : : "is not trivially copyable", type);
14004 : 18 : return error_mark_node;
14005 : : }
14006 : : }
14007 : :
14008 : 32722 : if (error_operand_p (arg))
14009 : 0 : return error_mark_node;
14010 : :
14011 : 32722 : if (!type_dependent_expression_p (arg))
14012 : : {
14013 : 462 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
14014 : : {
14015 : : /* Don't perform array-to-pointer conversion. */
14016 : 26 : arg = mark_rvalue_use (arg, loc, true);
14017 : 26 : if (!complete_type_or_maybe_complain (TREE_TYPE (arg), arg, complain))
14018 : 0 : return error_mark_node;
14019 : : }
14020 : : else
14021 : 436 : arg = decay_conversion (arg, complain);
14022 : :
14023 : 462 : if (error_operand_p (arg))
14024 : 12 : return error_mark_node;
14025 : :
14026 : 450 : if (!trivially_copyable_p (TREE_TYPE (arg)))
14027 : : {
14028 : 9 : error_at (cp_expr_loc_or_loc (arg, loc),
14029 : : "%<__builtin_bit_cast%> source type %qT "
14030 : 9 : "is not trivially copyable", TREE_TYPE (arg));
14031 : 9 : return error_mark_node;
14032 : : }
14033 : 441 : if (!dependent_type_p (type)
14034 : 870 : && !cp_tree_equal (TYPE_SIZE_UNIT (type),
14035 : 429 : TYPE_SIZE_UNIT (TREE_TYPE (arg))))
14036 : : {
14037 : 18 : error_at (loc, "%<__builtin_bit_cast%> source size %qE "
14038 : : "not equal to destination type size %qE",
14039 : 18 : TYPE_SIZE_UNIT (TREE_TYPE (arg)),
14040 : 18 : TYPE_SIZE_UNIT (type));
14041 : 18 : return error_mark_node;
14042 : : }
14043 : : }
14044 : :
14045 : 32683 : tree ret = build_min (BIT_CAST_EXPR, type, arg);
14046 : 32683 : SET_EXPR_LOCATION (ret, loc);
14047 : :
14048 : 32683 : if (!processing_template_decl && CLASS_TYPE_P (type))
14049 : 220 : ret = get_target_expr (ret, complain);
14050 : :
14051 : : return ret;
14052 : : }
14053 : :
14054 : : /* Diagnose invalid #pragma GCC unroll argument and adjust
14055 : : it if needed. */
14056 : :
14057 : : tree
14058 : 15701 : cp_check_pragma_unroll (location_t loc, tree unroll)
14059 : : {
14060 : 15701 : HOST_WIDE_INT lunroll = 0;
14061 : 15701 : if (type_dependent_expression_p (unroll))
14062 : : ;
14063 : 31330 : else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll))
14064 : 31284 : || (!value_dependent_expression_p (unroll)
14065 : 15589 : && (!tree_fits_shwi_p (unroll)
14066 : 15563 : || (lunroll = tree_to_shwi (unroll)) < 0
14067 : 15548 : || lunroll >= USHRT_MAX)))
14068 : : {
14069 : 90 : error_at (loc, "%<#pragma GCC unroll%> requires an"
14070 : : " assignment-expression that evaluates to a non-negative"
14071 : : " integral constant less than %u", USHRT_MAX);
14072 : 90 : unroll = integer_one_node;
14073 : : }
14074 : 15575 : else if (TREE_CODE (unroll) == INTEGER_CST)
14075 : : {
14076 : 15545 : unroll = fold_convert (integer_type_node, unroll);
14077 : 15545 : if (integer_zerop (unroll))
14078 : 12 : unroll = integer_one_node;
14079 : : }
14080 : 15701 : return unroll;
14081 : : }
14082 : :
14083 : : #include "gt-cp-semantics.h"
|