Line data Source code
1 : /* Language-dependent node constructors for parse phase of GNU compiler.
2 : Copyright (C) 1987-2023 Free Software Foundation, Inc.
3 : Hacked by Michael Tiemann (tiemann@cygnus.com)
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify
8 : it under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3, or (at your option)
10 : any later version.
11 :
12 : GCC is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #include "config.h"
22 : #include "system.h"
23 : #include "coretypes.h"
24 : #include "tree.h"
25 : #include "cp-tree.h"
26 : #include "gimple-expr.h"
27 : #include "cgraph.h"
28 : #include "stor-layout.h"
29 : #include "print-tree.h"
30 : #include "tree-iterator.h"
31 : #include "tree-inline.h"
32 : #include "debug.h"
33 : #include "convert.h"
34 : #include "gimplify.h"
35 : #include "stringpool.h"
36 : #include "attribs.h"
37 : #include "flags.h"
38 : #include "selftest.h"
39 :
40 : static tree bot_manip (tree *, int *, void *);
41 : static tree bot_replace (tree *, int *, void *);
42 : static hashval_t list_hash_pieces (tree, tree, tree);
43 : static tree build_target_expr (tree, tree, tsubst_flags_t);
44 : static tree count_trees_r (tree *, int *, void *);
45 : static tree verify_stmt_tree_r (tree *, int *, void *);
46 :
47 : static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
48 : static tree handle_abi_tag_attribute (tree *, tree, tree, int, bool *);
49 : static tree handle_contract_attribute (tree *, tree, tree, int, bool *);
50 :
51 : /* If REF is an lvalue, returns the kind of lvalue that REF is.
52 : Otherwise, returns clk_none. */
53 :
54 : cp_lvalue_kind
55 1084703754 : lvalue_kind (const_tree ref)
56 : {
57 1187064956 : cp_lvalue_kind op1_lvalue_kind = clk_none;
58 1187064956 : cp_lvalue_kind op2_lvalue_kind = clk_none;
59 :
60 : /* Expressions of reference type are sometimes wrapped in
61 : INDIRECT_REFs. INDIRECT_REFs are just internal compiler
62 : representation, not part of the language, so we have to look
63 : through them. */
64 1187064956 : if (REFERENCE_REF_P (ref))
65 64793663 : return lvalue_kind (TREE_OPERAND (ref, 0));
66 :
67 1122271293 : if (TREE_TYPE (ref)
68 1122271293 : && TYPE_REF_P (TREE_TYPE (ref)))
69 : {
70 : /* unnamed rvalue references are rvalues */
71 66285908 : if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref))
72 : && TREE_CODE (ref) != PARM_DECL
73 : && !VAR_P (ref)
74 : && TREE_CODE (ref) != COMPONENT_REF
75 : /* Functions are always lvalues. */
76 82856769 : && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
77 : {
78 16570567 : op1_lvalue_kind = clk_rvalueref;
79 16570567 : if (implicit_rvalue_p (ref))
80 3260722 : op1_lvalue_kind |= clk_implicit_rval;
81 16570567 : return op1_lvalue_kind;
82 : }
83 :
84 : /* lvalue references and named rvalue references are lvalues. */
85 : return clk_ordinary;
86 : }
87 :
88 1055985385 : if (ref == current_class_ptr)
89 : return clk_none;
90 :
91 : /* Expressions with cv void type are prvalues. */
92 1054876785 : if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
93 : return clk_none;
94 :
95 1054670766 : switch (TREE_CODE (ref))
96 : {
97 : case SAVE_EXPR:
98 : return clk_none;
99 :
100 : /* preincrements and predecrements are valid lvals, provided
101 : what they refer to are valid lvals. */
102 138374693 : case PREINCREMENT_EXPR:
103 138374693 : case PREDECREMENT_EXPR:
104 138374693 : case TRY_CATCH_EXPR:
105 138374693 : case REALPART_EXPR:
106 138374693 : case IMAGPART_EXPR:
107 138374693 : case VIEW_CONVERT_EXPR:
108 138374693 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
109 : /* As for ARRAY_REF and COMPONENT_REF, these codes turn a class prvalue
110 : into an xvalue: we need to materialize the temporary before we mess
111 : with it. Except VIEW_CONVERT_EXPR that doesn't actually change the
112 : type, as in location wrapper and REF_PARENTHESIZED_P. */
113 138374693 : if (op1_lvalue_kind == clk_class
114 138374707 : && !(TREE_CODE (ref) == VIEW_CONVERT_EXPR
115 : && (same_type_ignoring_top_level_qualifiers_p
116 14 : (TREE_TYPE (ref), TREE_TYPE (TREE_OPERAND (ref, 0))))))
117 14 : return clk_rvalueref;
118 : return op1_lvalue_kind;
119 :
120 1628942 : case ARRAY_REF:
121 1628942 : {
122 1628942 : tree op1 = TREE_OPERAND (ref, 0);
123 1628942 : if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
124 : {
125 1559969 : op1_lvalue_kind = lvalue_kind (op1);
126 1559969 : if (op1_lvalue_kind == clk_class)
127 : /* in the case of an array operand, the result is an lvalue if
128 : that operand is an lvalue and an xvalue otherwise */
129 784 : op1_lvalue_kind = clk_rvalueref;
130 1559969 : return op1_lvalue_kind;
131 : }
132 : else
133 : return clk_ordinary;
134 : }
135 :
136 20 : case MEMBER_REF:
137 20 : case DOTSTAR_EXPR:
138 20 : if (TREE_CODE (ref) == MEMBER_REF)
139 : op1_lvalue_kind = clk_ordinary;
140 : else
141 4 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
142 20 : if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref, 1))))
143 : op1_lvalue_kind = clk_none;
144 20 : else if (op1_lvalue_kind == clk_class)
145 : /* The result of a .* expression whose second operand is a pointer to a
146 : data member is an lvalue if the first operand is an lvalue and an
147 : xvalue otherwise. */
148 14 : op1_lvalue_kind = clk_rvalueref;
149 : return op1_lvalue_kind;
150 :
151 67423560 : case COMPONENT_REF:
152 67423560 : if (BASELINK_P (TREE_OPERAND (ref, 1)))
153 : {
154 136 : tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (ref, 1));
155 :
156 : /* For static member function recurse on the BASELINK, we can get
157 : here e.g. from reference_binding. If BASELINK_FUNCTIONS is
158 : OVERLOAD, the overload is resolved first if possible through
159 : resolve_address_of_overloaded_function. */
160 136 : if (TREE_CODE (fn) == FUNCTION_DECL && DECL_STATIC_FUNCTION_P (fn))
161 36 : return lvalue_kind (TREE_OPERAND (ref, 1));
162 : }
163 67423524 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
164 67423524 : if (op1_lvalue_kind == clk_class)
165 : /* If E1 is an lvalue, then E1.E2 is an lvalue;
166 : otherwise E1.E2 is an xvalue. */
167 : op1_lvalue_kind = clk_rvalueref;
168 :
169 : /* Look at the member designator. */
170 67387119 : if (!op1_lvalue_kind)
171 : ;
172 67395803 : else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
173 : /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
174 : situations. If we're seeing a COMPONENT_REF, it's a non-static
175 : member, so it isn't an lvalue. */
176 : op1_lvalue_kind = clk_none;
177 67395703 : else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
178 : /* This can be IDENTIFIER_NODE in a template. */;
179 64660410 : else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
180 : {
181 : /* Clear the ordinary bit. If this object was a class
182 : rvalue we want to preserve that information. */
183 479484 : op1_lvalue_kind &= ~clk_ordinary;
184 : /* The lvalue is for a bitfield. */
185 479484 : op1_lvalue_kind |= clk_bitfield;
186 : }
187 64180926 : else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
188 15777 : op1_lvalue_kind |= clk_packed;
189 :
190 : return op1_lvalue_kind;
191 :
192 : case STRING_CST:
193 : case COMPOUND_LITERAL_EXPR:
194 : return clk_ordinary;
195 :
196 703637 : case CONST_DECL:
197 : /* CONST_DECL without TREE_STATIC are enumeration values and
198 : thus not lvalues. With TREE_STATIC they are used by ObjC++
199 : in objc_build_string_object and need to be considered as
200 : lvalues. */
201 703637 : if (! TREE_STATIC (ref))
202 : return clk_none;
203 : /* FALLTHRU */
204 109191367 : case VAR_DECL:
205 109191367 : if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
206 114290 : return lvalue_kind (DECL_VALUE_EXPR (CONST_CAST_TREE (ref)));
207 :
208 148435419 : if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
209 5709774 : && DECL_LANG_SPECIFIC (ref)
210 109262367 : && DECL_IN_AGGR_P (ref))
211 : return clk_none;
212 : /* FALLTHRU */
213 : case INDIRECT_REF:
214 : case ARROW_EXPR:
215 : case PARM_DECL:
216 : case RESULT_DECL:
217 : case PLACEHOLDER_EXPR:
218 : return clk_ordinary;
219 :
220 : /* A scope ref in a template, left as SCOPE_REF to support later
221 : access checking. */
222 5001885 : case SCOPE_REF:
223 5001885 : gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
224 5001885 : {
225 5001885 : tree op = TREE_OPERAND (ref, 1);
226 5001885 : if (TREE_CODE (op) == FIELD_DECL)
227 13990 : return (DECL_C_BIT_FIELD (op) ? clk_bitfield : clk_ordinary);
228 : else
229 : return lvalue_kind (op);
230 : }
231 :
232 588 : case MAX_EXPR:
233 588 : case MIN_EXPR:
234 : /* Disallow <? and >? as lvalues if either argument side-effects. */
235 588 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
236 588 : || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
237 : return clk_none;
238 588 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
239 588 : op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1));
240 588 : break;
241 :
242 5070955 : case COND_EXPR:
243 5070955 : if (processing_template_decl)
244 : {
245 : /* Within templates, a REFERENCE_TYPE will indicate whether
246 : the COND_EXPR result is an ordinary lvalue or rvalueref.
247 : Since REFERENCE_TYPEs are handled above, if we reach this
248 : point, we know we got a plain rvalue. Unless we have a
249 : type-dependent expr, that is, but we shouldn't be testing
250 : lvalueness if we can't even tell the types yet! */
251 574713 : gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
252 574713 : goto default_;
253 : }
254 4496242 : {
255 4496242 : tree op1 = TREE_OPERAND (ref, 1);
256 4496242 : if (!op1) op1 = TREE_OPERAND (ref, 0);
257 4496242 : tree op2 = TREE_OPERAND (ref, 2);
258 4496242 : op1_lvalue_kind = lvalue_kind (op1);
259 4496242 : op2_lvalue_kind = lvalue_kind (op2);
260 4496242 : if (!op1_lvalue_kind != !op2_lvalue_kind)
261 : {
262 : /* The second or the third operand (but not both) is a
263 : throw-expression; the result is of the type
264 : and value category of the other. */
265 384833 : if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
266 : op2_lvalue_kind = op1_lvalue_kind;
267 384785 : else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
268 4496830 : op1_lvalue_kind = op2_lvalue_kind;
269 : }
270 : }
271 : break;
272 :
273 6919 : case MODOP_EXPR:
274 : /* We expect to see unlowered MODOP_EXPRs only during
275 : template processing. */
276 6919 : gcc_assert (processing_template_decl);
277 : return clk_ordinary;
278 :
279 : case MODIFY_EXPR:
280 : case TYPEID_EXPR:
281 : return clk_ordinary;
282 :
283 702435 : case COMPOUND_EXPR:
284 702435 : return lvalue_kind (TREE_OPERAND (ref, 1));
285 :
286 : case TARGET_EXPR:
287 : return clk_class;
288 :
289 1491 : case VA_ARG_EXPR:
290 1491 : return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
291 :
292 51768341 : case CALL_EXPR:
293 : /* We can see calls outside of TARGET_EXPR in templates. */
294 51768341 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
295 : return clk_class;
296 : return clk_none;
297 :
298 51164793 : case FUNCTION_DECL:
299 : /* All functions (except non-static-member functions) are
300 : lvalues. */
301 51164793 : return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref)
302 51164793 : ? clk_none : clk_ordinary);
303 :
304 242 : case BASELINK:
305 : /* We now represent a reference to a single static member function
306 : with a BASELINK. */
307 : /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
308 : its argument unmodified and we assign it to a const_tree. */
309 242 : return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
310 :
311 31762641 : case NON_DEPENDENT_EXPR:
312 31762641 : case PAREN_EXPR:
313 31762641 : return lvalue_kind (TREE_OPERAND (ref, 0));
314 :
315 11140587 : case TEMPLATE_PARM_INDEX:
316 11140587 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
317 : /* A template parameter object is an lvalue. */
318 : return clk_ordinary;
319 : return clk_none;
320 :
321 426952934 : default:
322 426952934 : default_:
323 426952934 : if (!TREE_TYPE (ref))
324 : return clk_none;
325 853905868 : if (CLASS_TYPE_P (TREE_TYPE (ref))
326 853144530 : || TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE)
327 : return clk_class;
328 : return clk_none;
329 : }
330 :
331 : /* If one operand is not an lvalue at all, then this expression is
332 : not an lvalue. */
333 4496830 : if (!op1_lvalue_kind || !op2_lvalue_kind)
334 : return clk_none;
335 :
336 : /* Otherwise, it's an lvalue, and it has all the odd properties
337 : contributed by either operand. */
338 338229 : op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
339 : /* It's not an ordinary lvalue if it involves any other kind. */
340 338229 : if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
341 15116 : op1_lvalue_kind &= ~clk_ordinary;
342 : /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
343 : A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
344 338229 : if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
345 14896 : && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
346 492132754 : op1_lvalue_kind = clk_none;
347 : return op1_lvalue_kind;
348 : }
349 :
350 : /* Returns the kind of lvalue that REF is, in the sense of [basic.lval]. */
351 :
352 : cp_lvalue_kind
353 25780023 : real_lvalue_p (const_tree ref)
354 : {
355 181417 : cp_lvalue_kind kind = lvalue_kind (ref);
356 25780023 : if (kind & (clk_rvalueref|clk_class))
357 : return clk_none;
358 : else
359 24744880 : return kind;
360 : }
361 :
362 : /* c-common wants us to return bool. */
363 :
364 : bool
365 25598606 : lvalue_p (const_tree t)
366 : {
367 25598606 : return real_lvalue_p (t);
368 : }
369 :
370 : /* This differs from lvalue_p in that xvalues are included. */
371 :
372 : bool
373 73421281 : glvalue_p (const_tree ref)
374 : {
375 73421281 : cp_lvalue_kind kind = lvalue_kind (ref);
376 73421281 : if (kind & clk_class)
377 : return false;
378 : else
379 72770456 : return (kind != clk_none);
380 : }
381 :
382 : /* This differs from glvalue_p in that class prvalues are included. */
383 :
384 : bool
385 530806116 : obvalue_p (const_tree ref)
386 : {
387 530806116 : return (lvalue_kind (ref) != clk_none);
388 : }
389 :
390 : /* Returns true if REF is an xvalue (the result of dereferencing an rvalue
391 : reference), false otherwise. */
392 :
393 : bool
394 2938097 : xvalue_p (const_tree ref)
395 : {
396 2092967 : return (lvalue_kind (ref) & clk_rvalueref);
397 : }
398 :
399 : /* True if REF is a bit-field. */
400 :
401 : bool
402 84466513 : bitfield_p (const_tree ref)
403 : {
404 84466513 : return (lvalue_kind (ref) & clk_bitfield);
405 : }
406 :
407 : /* C++-specific version of stabilize_reference. */
408 :
409 : tree
410 2712985 : cp_stabilize_reference (tree ref)
411 : {
412 2712985 : STRIP_ANY_LOCATION_WRAPPER (ref);
413 2712985 : switch (TREE_CODE (ref))
414 : {
415 : case NON_DEPENDENT_EXPR:
416 : /* We aren't actually evaluating this. */
417 : return ref;
418 :
419 : /* We need to treat specially anything stabilize_reference doesn't
420 : handle specifically. */
421 : case VAR_DECL:
422 : case PARM_DECL:
423 : case RESULT_DECL:
424 : CASE_CONVERT:
425 : case FLOAT_EXPR:
426 : case FIX_TRUNC_EXPR:
427 : case INDIRECT_REF:
428 : case COMPONENT_REF:
429 : case BIT_FIELD_REF:
430 : case ARRAY_REF:
431 : case ARRAY_RANGE_REF:
432 : case ERROR_MARK:
433 : break;
434 408 : default:
435 408 : cp_lvalue_kind kind = lvalue_kind (ref);
436 408 : if ((kind & ~clk_class) != clk_none)
437 : {
438 404 : tree type = unlowered_expr_type (ref);
439 404 : bool rval = !!(kind & clk_rvalueref);
440 808 : type = cp_build_reference_type (type, rval);
441 : /* This inhibits warnings in, eg, cxx_mark_addressable
442 : (c++/60955). */
443 404 : warning_sentinel s (extra_warnings);
444 404 : ref = build_static_cast (input_location, type, ref,
445 : tf_error);
446 404 : }
447 : }
448 :
449 2579378 : return stabilize_reference (ref);
450 : }
451 :
452 : /* Test whether DECL is a builtin that may appear in a
453 : constant-expression. */
454 :
455 : bool
456 238977785 : builtin_valid_in_constant_expr_p (const_tree decl)
457 : {
458 238977785 : STRIP_ANY_LOCATION_WRAPPER (decl);
459 238977785 : if (TREE_CODE (decl) != FUNCTION_DECL)
460 : /* Not a function. */
461 : return false;
462 98226473 : if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
463 : {
464 76309001 : if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
465 105336 : switch (DECL_FE_FUNCTION_CODE (decl))
466 : {
467 : case CP_BUILT_IN_IS_CONSTANT_EVALUATED:
468 : case CP_BUILT_IN_SOURCE_LOCATION:
469 : case CP_BUILT_IN_IS_CORRESPONDING_MEMBER:
470 : case CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS:
471 : return true;
472 : default:
473 : break;
474 : }
475 : /* Not a built-in. */
476 : return false;
477 : }
478 21917472 : switch (DECL_FUNCTION_CODE (decl))
479 : {
480 : /* These always have constant results like the corresponding
481 : macros/symbol. */
482 : case BUILT_IN_FILE:
483 : case BUILT_IN_FUNCTION:
484 : case BUILT_IN_LINE:
485 :
486 : /* The following built-ins are valid in constant expressions
487 : when their arguments are. */
488 : case BUILT_IN_ADD_OVERFLOW_P:
489 : case BUILT_IN_SUB_OVERFLOW_P:
490 : case BUILT_IN_MUL_OVERFLOW_P:
491 :
492 : /* These have constant results even if their operands are
493 : non-constant. */
494 : case BUILT_IN_CONSTANT_P:
495 : case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE:
496 : return true;
497 : default:
498 : return false;
499 : }
500 : }
501 :
502 : /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
503 :
504 : static tree
505 12042210 : build_target_expr (tree decl, tree value, tsubst_flags_t complain)
506 : {
507 12042210 : tree t;
508 12042210 : tree type = TREE_TYPE (decl);
509 :
510 12042210 : value = mark_rvalue_use (value);
511 :
512 12042210 : gcc_checking_assert (VOID_TYPE_P (TREE_TYPE (value))
513 : || TREE_TYPE (decl) == TREE_TYPE (value)
514 : /* On ARM ctors return 'this'. */
515 : || (TYPE_PTR_P (TREE_TYPE (value))
516 : && TREE_CODE (value) == CALL_EXPR)
517 : || useless_type_conversion_p (TREE_TYPE (decl),
518 : TREE_TYPE (value)));
519 :
520 : /* Set TREE_READONLY for optimization, such as gimplify_init_constructor
521 : moving a constant aggregate into .rodata. */
522 12042210 : if (CP_TYPE_CONST_NON_VOLATILE_P (type)
523 992008 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
524 860949 : && !VOID_TYPE_P (TREE_TYPE (value))
525 621761 : && !TYPE_HAS_MUTABLE_P (type)
526 12663948 : && reduced_constant_expression_p (value))
527 302587 : TREE_READONLY (decl) = true;
528 :
529 12042210 : if (complain & tf_no_cleanup)
530 : /* The caller is building a new-expr and does not need a cleanup. */
531 : t = NULL_TREE;
532 : else
533 : {
534 11677144 : t = cxx_maybe_build_cleanup (decl, complain);
535 11677144 : if (t == error_mark_node)
536 : return error_mark_node;
537 : }
538 :
539 12042189 : set_target_expr_eliding (value);
540 :
541 12042189 : t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
542 12042189 : if (location_t eloc = cp_expr_location (value))
543 4448919 : SET_EXPR_LOCATION (t, eloc);
544 : /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
545 : ignore the TARGET_EXPR. If there really turn out to be no
546 : side-effects, then the optimizer should be able to get rid of
547 : whatever code is generated anyhow. */
548 12042189 : TREE_SIDE_EFFECTS (t) = 1;
549 :
550 12042189 : return t;
551 : }
552 :
553 : /* Return an undeclared local temporary of type TYPE for use in building a
554 : TARGET_EXPR. */
555 :
556 : tree
557 12187674 : build_local_temp (tree type)
558 : {
559 12187674 : tree slot = build_decl (input_location,
560 : VAR_DECL, NULL_TREE, type);
561 12187674 : DECL_ARTIFICIAL (slot) = 1;
562 12187674 : DECL_IGNORED_P (slot) = 1;
563 12187674 : DECL_CONTEXT (slot) = current_function_decl;
564 12187674 : layout_decl (slot, 0);
565 12187674 : return slot;
566 : }
567 :
568 : /* Return whether DECL is such a local temporary (or one from
569 : create_tmp_var_raw). */
570 :
571 : bool
572 26669 : is_local_temp (tree decl)
573 : {
574 26669 : return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
575 27225 : && !TREE_STATIC (decl));
576 : }
577 :
578 : /* Set various status flags when building an AGGR_INIT_EXPR object T. */
579 :
580 : static void
581 3045394 : process_aggr_init_operands (tree t)
582 : {
583 3045394 : bool side_effects;
584 :
585 3045394 : side_effects = TREE_SIDE_EFFECTS (t);
586 3045394 : if (!side_effects)
587 : {
588 3045394 : int i, n;
589 3045394 : n = TREE_OPERAND_LENGTH (t);
590 13587332 : for (i = 1; i < n; i++)
591 : {
592 11645372 : tree op = TREE_OPERAND (t, i);
593 11645372 : if (op && TREE_SIDE_EFFECTS (op))
594 : {
595 : side_effects = 1;
596 : break;
597 : }
598 : }
599 : }
600 3045394 : TREE_SIDE_EFFECTS (t) = side_effects;
601 3045394 : }
602 :
603 : /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
604 : FN, and SLOT. NARGS is the number of call arguments which are specified
605 : as a tree array ARGS. */
606 :
607 : static tree
608 3045394 : build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
609 : tree *args)
610 : {
611 3045394 : tree t;
612 3045394 : int i;
613 :
614 3045394 : t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
615 3045394 : TREE_TYPE (t) = return_type;
616 3045394 : AGGR_INIT_EXPR_FN (t) = fn;
617 3045394 : AGGR_INIT_EXPR_SLOT (t) = slot;
618 9151351 : for (i = 0; i < nargs; i++)
619 6105957 : AGGR_INIT_EXPR_ARG (t, i) = args[i];
620 3045394 : process_aggr_init_operands (t);
621 3045394 : return t;
622 : }
623 :
624 : /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
625 : target. TYPE is the type to be initialized.
626 :
627 : Build an AGGR_INIT_EXPR to represent the initialization. This function
628 : differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
629 : to initialize another object, whereas a TARGET_EXPR can either
630 : initialize another object or create its own temporary object, and as a
631 : result building up a TARGET_EXPR requires that the type's destructor be
632 : callable. */
633 :
634 : tree
635 11286722 : build_aggr_init_expr (tree type, tree init)
636 : {
637 11286722 : tree fn;
638 11286722 : tree slot;
639 11286722 : tree rval;
640 11286722 : int is_ctor;
641 :
642 11286722 : gcc_assert (!VOID_TYPE_P (type));
643 :
644 : /* Don't build AGGR_INIT_EXPR in a template. */
645 11286722 : if (processing_template_decl)
646 : return init;
647 :
648 11244367 : fn = cp_get_callee (init);
649 11244367 : if (fn == NULL_TREE)
650 5321031 : return convert (type, init);
651 :
652 12486594 : is_ctor = (TREE_CODE (fn) == ADDR_EXPR
653 5895820 : && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
654 17714976 : && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
655 :
656 : /* We split the CALL_EXPR into its function and its arguments here.
657 : Then, in expand_expr, we put them back together. The reason for
658 : this is that this expression might be a default argument
659 : expression. In that case, we need a new temporary every time the
660 : expression is used. That's what break_out_target_exprs does; it
661 : replaces every AGGR_INIT_EXPR with a copy that uses a fresh
662 : temporary slot. Then, expand_expr builds up a call-expression
663 : using the new slot. */
664 :
665 : /* If we don't need to use a constructor to create an object of this
666 : type, don't mess with AGGR_INIT_EXPR. */
667 3517864 : if (is_ctor || TREE_ADDRESSABLE (type))
668 : {
669 3045394 : slot = build_local_temp (type);
670 :
671 3045394 : if (TREE_CODE (init) == CALL_EXPR)
672 : {
673 11161856 : rval = build_aggr_init_array (void_type_node, fn, slot,
674 2790464 : call_expr_nargs (init),
675 2790464 : CALL_EXPR_ARGP (init));
676 2790464 : AGGR_INIT_FROM_THUNK_P (rval)
677 2790464 : = CALL_FROM_THUNK_P (init);
678 : }
679 : else
680 : {
681 254930 : rval = build_aggr_init_array (void_type_node, fn, slot,
682 254930 : aggr_init_expr_nargs (init),
683 254930 : AGGR_INIT_EXPR_ARGP (init));
684 254930 : AGGR_INIT_FROM_THUNK_P (rval)
685 254930 : = AGGR_INIT_FROM_THUNK_P (init);
686 : }
687 3045394 : TREE_SIDE_EFFECTS (rval) = 1;
688 3045394 : AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
689 3045394 : TREE_NOTHROW (rval) = TREE_NOTHROW (init);
690 3045394 : CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
691 3045394 : CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
692 3045394 : CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
693 : }
694 : else
695 : rval = init;
696 :
697 : return rval;
698 : }
699 :
700 : /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
701 : target. TYPE is the type that this initialization should appear to
702 : have.
703 :
704 : Build an encapsulation of the initialization to perform
705 : and return it so that it can be processed by language-independent
706 : and language-specific expression expanders. */
707 :
708 : tree
709 10670893 : build_cplus_new (tree type, tree init, tsubst_flags_t complain)
710 : {
711 : /* This function should cope with what build_special_member_call
712 : can produce. When performing parenthesized aggregate initialization,
713 : it can produce a { }. */
714 10670893 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
715 : {
716 59 : gcc_assert (cxx_dialect >= cxx20);
717 59 : return finish_compound_literal (type, init, complain);
718 : }
719 :
720 10670834 : tree rval = build_aggr_init_expr (type, init);
721 10670834 : tree slot;
722 :
723 10670834 : if (init == error_mark_node)
724 : return error_mark_node;
725 :
726 10669069 : if (!complete_type_or_maybe_complain (type, init, complain))
727 6 : return error_mark_node;
728 :
729 : /* Make sure that we're not trying to create an instance of an
730 : abstract class. */
731 10669063 : if (abstract_virtuals_error (NULL_TREE, type, complain))
732 6 : return error_mark_node;
733 :
734 10669057 : if (TREE_CODE (rval) == AGGR_INIT_EXPR)
735 2571527 : slot = AGGR_INIT_EXPR_SLOT (rval);
736 8097530 : else if (TREE_CODE (rval) == CALL_EXPR
737 5177242 : || TREE_CODE (rval) == CONSTRUCTOR)
738 2920295 : slot = build_local_temp (type);
739 : else
740 : return rval;
741 :
742 5491822 : rval = build_target_expr (slot, rval, complain);
743 :
744 5491822 : if (rval != error_mark_node)
745 5491822 : TARGET_EXPR_IMPLICIT_P (rval) = 1;
746 :
747 : return rval;
748 : }
749 :
750 : /* Subroutine of build_vec_init_expr: Build up a single element
751 : intialization as a proxy for the full array initialization to get things
752 : marked as used and any appropriate diagnostics.
753 :
754 : This used to be necessary because we were deferring building the actual
755 : constructor calls until gimplification time; now we only do it to set
756 : VEC_INIT_EXPR_IS_CONSTEXPR.
757 :
758 : We assume that init is either NULL_TREE, {}, void_type_node (indicating
759 : value-initialization), or another array to copy. */
760 :
761 : static tree
762 1051 : build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
763 : {
764 1051 : tree inner_type = strip_array_types (type);
765 :
766 1051 : if (integer_zerop (array_type_nelts_total (type))
767 1051 : || !CLASS_TYPE_P (inner_type))
768 : /* No interesting initialization to do. */
769 202 : return integer_zero_node;
770 849 : if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
771 : {
772 : /* Even if init has initializers for some array elements,
773 : we're interested in the {}-init of trailing elements. */
774 101 : if (CP_AGGREGATE_TYPE_P (inner_type))
775 : {
776 49 : tree empty = build_constructor (init_list_type_node, nullptr);
777 49 : return digest_init (inner_type, empty, complain);
778 : }
779 : else
780 : /* It's equivalent to value-init. */
781 52 : init = void_type_node;
782 : }
783 800 : if (init == void_type_node)
784 79 : return build_value_init (inner_type, complain);
785 :
786 721 : releasing_vec argvec;
787 721 : if (init && !BRACE_ENCLOSED_INITIALIZER_P (init))
788 : {
789 167 : tree init_type = strip_array_types (TREE_TYPE (init));
790 167 : tree dummy = build_dummy_object (init_type);
791 167 : if (!lvalue_p (init))
792 134 : dummy = move (dummy);
793 167 : argvec->quick_push (dummy);
794 : }
795 721 : init = build_special_member_call (NULL_TREE, complete_ctor_identifier,
796 : &argvec, inner_type, LOOKUP_NORMAL,
797 : complain);
798 :
799 : /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But
800 : we don't want one here because we aren't creating a temporary. */
801 721 : if (TREE_CODE (init) == TARGET_EXPR)
802 22 : init = TARGET_EXPR_INITIAL (init);
803 :
804 721 : return init;
805 1051 : }
806 :
807 : /* Return a TARGET_EXPR which expresses the initialization of an array to
808 : be named later, either default-initialization or copy-initialization
809 : from another array of the same type. */
810 :
811 : tree
812 1054 : build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
813 : {
814 1054 : if (tree vi = get_vec_init_expr (init))
815 : return vi;
816 :
817 1051 : tree elt_init;
818 482 : if (init && TREE_CODE (init) == CONSTRUCTOR
819 1155 : && !BRACE_ENCLOSED_INITIALIZER_P (init))
820 : /* We built any needed constructor calls in digest_init. */
821 : elt_init = init;
822 : else
823 1048 : elt_init = build_vec_init_elt (type, init, complain);
824 :
825 1051 : bool value_init = false;
826 1051 : if (init == void_type_node)
827 : {
828 204 : value_init = true;
829 204 : init = NULL_TREE;
830 : }
831 :
832 1051 : tree slot = build_local_temp (type);
833 1051 : init = build2 (VEC_INIT_EXPR, type, slot, init);
834 1051 : TREE_SIDE_EFFECTS (init) = true;
835 1051 : SET_EXPR_LOCATION (init, input_location);
836 :
837 1051 : if (cxx_dialect >= cxx11)
838 : {
839 993 : bool cx = potential_constant_expression (elt_init);
840 993 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
841 0 : cx &= potential_constant_expression (init);
842 993 : VEC_INIT_EXPR_IS_CONSTEXPR (init) = cx;
843 : }
844 1051 : VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
845 :
846 1051 : return init;
847 : }
848 :
849 : /* Call build_vec_init to expand VEC_INIT into TARGET (for which NULL_TREE
850 : means VEC_INIT_EXPR_SLOT). */
851 :
852 : tree
853 1079 : expand_vec_init_expr (tree target, tree vec_init, tsubst_flags_t complain,
854 : vec<tree,va_gc> **flags)
855 : {
856 1079 : iloc_sentinel ils = EXPR_LOCATION (vec_init);
857 :
858 1079 : if (!target)
859 0 : target = VEC_INIT_EXPR_SLOT (vec_init);
860 1079 : tree init = VEC_INIT_EXPR_INIT (vec_init);
861 1079 : int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
862 3237 : return build_vec_init (target, NULL_TREE, init,
863 1079 : VEC_INIT_EXPR_VALUE_INIT (vec_init),
864 1079 : from_array, complain, flags);
865 1079 : }
866 :
867 : /* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context
868 : that requires a constant expression. */
869 :
870 : void
871 3 : diagnose_non_constexpr_vec_init (tree expr)
872 : {
873 3 : tree type = TREE_TYPE (VEC_INIT_EXPR_SLOT (expr));
874 3 : tree init, elt_init;
875 3 : if (VEC_INIT_EXPR_VALUE_INIT (expr))
876 3 : init = void_type_node;
877 : else
878 0 : init = VEC_INIT_EXPR_INIT (expr);
879 :
880 3 : elt_init = build_vec_init_elt (type, init, tf_warning_or_error);
881 3 : require_potential_constant_expression (elt_init);
882 3 : }
883 :
884 : tree
885 19 : build_array_copy (tree init)
886 : {
887 19 : return get_target_expr (build_vec_init_expr
888 19 : (TREE_TYPE (init), init, tf_warning_or_error));
889 : }
890 :
891 : /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
892 : indicated TYPE. */
893 :
894 : tree
895 5024356 : build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
896 : {
897 5024356 : gcc_assert (!VOID_TYPE_P (type));
898 5024356 : gcc_assert (!VOID_TYPE_P (TREE_TYPE (init)));
899 :
900 5024356 : if (TREE_CODE (init) == TARGET_EXPR
901 4786138 : || init == error_mark_node)
902 : return init;
903 3086674 : else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
904 37192 : && TREE_CODE (init) != COND_EXPR
905 1644 : && TREE_CODE (init) != CONSTRUCTOR
906 0 : && TREE_CODE (init) != VA_ARG_EXPR
907 4786019 : && TREE_CODE (init) != CALL_EXPR)
908 : /* We need to build up a copy constructor call. COND_EXPR is a special
909 : case because we already have copies on the arms and we don't want
910 : another one here. A CONSTRUCTOR is aggregate initialization, which
911 : is handled separately. A VA_ARG_EXPR is magic creation of an
912 : aggregate; there's no additional work to be done. A CALL_EXPR
913 : already creates a prvalue. */
914 0 : return force_rvalue (init, complain);
915 :
916 4786019 : return force_target_expr (type, init, complain);
917 : }
918 :
919 : /* Like the above function, but without the checking. This function should
920 : only be used by code which is deliberately trying to subvert the type
921 : system, such as call_builtin_trap. Or build_over_call, to avoid
922 : infinite recursion. */
923 :
924 : tree
925 6220865 : force_target_expr (tree type, tree init, tsubst_flags_t complain)
926 : {
927 6220865 : tree slot;
928 :
929 6220865 : gcc_assert (!VOID_TYPE_P (type));
930 :
931 6220865 : slot = build_local_temp (type);
932 6220865 : return build_target_expr (slot, init, complain);
933 : }
934 :
935 : /* Like build_target_expr_with_type, but use the type of INIT. */
936 :
937 : tree
938 4111589 : get_target_expr (tree init, tsubst_flags_t complain /* = tf_warning_or_error */)
939 : {
940 4111589 : if (TREE_CODE (init) == AGGR_INIT_EXPR)
941 329285 : return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
942 3782304 : else if (TREE_CODE (init) == VEC_INIT_EXPR)
943 238 : return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
944 : else
945 : {
946 3782066 : init = convert_bitfield_to_declared_type (init);
947 3782066 : return build_target_expr_with_type (init, TREE_TYPE (init), complain);
948 : }
949 : }
950 :
951 : /* If EXPR is a bitfield reference, convert it to the declared type of
952 : the bitfield, and return the resulting expression. Otherwise,
953 : return EXPR itself. */
954 :
955 : tree
956 504072184 : convert_bitfield_to_declared_type (tree expr)
957 : {
958 504072184 : tree bitfield_type;
959 :
960 504072184 : bitfield_type = is_bitfield_expr_with_lowered_type (expr);
961 504072184 : if (bitfield_type)
962 40458 : expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
963 : expr);
964 504072184 : return expr;
965 : }
966 :
967 : /* EXPR is being used in an rvalue context. Return a version of EXPR
968 : that is marked as an rvalue. */
969 :
970 : tree
971 93389468 : rvalue (tree expr)
972 : {
973 93389468 : tree type;
974 :
975 93389468 : if (error_operand_p (expr))
976 : return expr;
977 :
978 93389257 : expr = mark_rvalue_use (expr);
979 :
980 : /* [basic.lval]
981 :
982 : Non-class rvalues always have cv-unqualified types. */
983 93389257 : type = TREE_TYPE (expr);
984 93389257 : if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
985 20913594 : type = cv_unqualified (type);
986 :
987 : /* We need to do this for rvalue refs as well to get the right answer
988 : from decltype; see c++/36628. */
989 93389257 : if (!processing_template_decl && glvalue_p (expr))
990 : {
991 : /* But don't use this function for class lvalues; use move (to treat an
992 : lvalue as an xvalue) or force_rvalue (to make a prvalue copy). */
993 4767953 : gcc_checking_assert (!CLASS_TYPE_P (type));
994 4767953 : expr = build1 (NON_LVALUE_EXPR, type, expr);
995 : }
996 88621304 : else if (type != TREE_TYPE (expr))
997 20738679 : expr = build_nop (type, expr);
998 :
999 : return expr;
1000 : }
1001 :
1002 :
1003 : struct cplus_array_info
1004 : {
1005 : tree type;
1006 : tree domain;
1007 : };
1008 :
1009 : struct cplus_array_hasher : ggc_ptr_hash<tree_node>
1010 : {
1011 : typedef cplus_array_info *compare_type;
1012 :
1013 : static hashval_t hash (tree t);
1014 : static bool equal (tree, cplus_array_info *);
1015 : };
1016 :
1017 : /* Hash an ARRAY_TYPE. K is really of type `tree'. */
1018 :
1019 : hashval_t
1020 23036221 : cplus_array_hasher::hash (tree t)
1021 : {
1022 23036221 : hashval_t hash;
1023 :
1024 23036221 : hash = TYPE_UID (TREE_TYPE (t));
1025 23036221 : if (TYPE_DOMAIN (t))
1026 18302655 : hash ^= TYPE_UID (TYPE_DOMAIN (t));
1027 23036221 : return hash;
1028 : }
1029 :
1030 : /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
1031 : of type `cplus_array_info*'. */
1032 :
1033 : bool
1034 31148937 : cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
1035 : {
1036 33169052 : return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
1037 : }
1038 :
1039 : /* Hash table containing dependent array types, which are unsuitable for
1040 : the language-independent type hash table. */
1041 : static GTY (()) hash_table<cplus_array_hasher> *cplus_array_htab;
1042 :
1043 : /* Build an ARRAY_TYPE without laying it out. */
1044 :
1045 : static tree
1046 2887596 : build_min_array_type (tree elt_type, tree index_type)
1047 : {
1048 2887596 : tree t = cxx_make_type (ARRAY_TYPE);
1049 2887596 : TREE_TYPE (t) = elt_type;
1050 2887596 : TYPE_DOMAIN (t) = index_type;
1051 2887596 : return t;
1052 : }
1053 :
1054 : /* Set TYPE_CANONICAL like build_array_type_1, but using
1055 : build_cplus_array_type. */
1056 :
1057 : static void
1058 2887596 : set_array_type_canon (tree t, tree elt_type, tree index_type, bool dep)
1059 : {
1060 : /* Set the canonical type for this new node. */
1061 2887596 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
1062 2887596 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
1063 701632 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1064 2185964 : else if (TYPE_CANONICAL (elt_type) != elt_type
1065 2185964 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
1066 641183 : TYPE_CANONICAL (t)
1067 1609751 : = build_cplus_array_type (TYPE_CANONICAL (elt_type),
1068 : index_type
1069 327385 : ? TYPE_CANONICAL (index_type) : index_type,
1070 : dep);
1071 : else
1072 1544781 : TYPE_CANONICAL (t) = t;
1073 2887596 : }
1074 :
1075 : /* Like build_array_type, but handle special C++ semantics: an array of a
1076 : variant element type is a variant of the array of the main variant of
1077 : the element type. IS_DEPENDENT is -ve if we should determine the
1078 : dependency. Otherwise its bool value indicates dependency. */
1079 :
1080 : tree
1081 30246451 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
1082 : {
1083 30246451 : tree t;
1084 :
1085 30246451 : if (elt_type == error_mark_node || index_type == error_mark_node)
1086 : return error_mark_node;
1087 :
1088 30246448 : if (dependent < 0)
1089 30983392 : dependent = (uses_template_parms (elt_type)
1090 15491696 : || (index_type && uses_template_parms (index_type)));
1091 :
1092 30246448 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1093 : /* Start with an array of the TYPE_MAIN_VARIANT. */
1094 12377274 : t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
1095 : index_type, dependent);
1096 17869174 : else if (dependent)
1097 : {
1098 : /* Since type_hash_canon calls layout_type, we need to use our own
1099 : hash table. */
1100 3099030 : cplus_array_info cai;
1101 3099030 : hashval_t hash;
1102 :
1103 3099030 : if (cplus_array_htab == NULL)
1104 13296 : cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61);
1105 :
1106 3099030 : hash = TYPE_UID (elt_type);
1107 3099030 : if (index_type)
1108 1592104 : hash ^= TYPE_UID (index_type);
1109 3099030 : cai.type = elt_type;
1110 3099030 : cai.domain = index_type;
1111 :
1112 3099030 : tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
1113 3099030 : if (*e)
1114 : /* We have found the type: we're done. */
1115 1996433 : return (tree) *e;
1116 : else
1117 : {
1118 : /* Build a new array type. */
1119 1102597 : t = build_min_array_type (elt_type, index_type);
1120 :
1121 : /* Store it in the hash table. */
1122 1102597 : *e = t;
1123 :
1124 : /* Set the canonical type for this new node. */
1125 1102597 : set_array_type_canon (t, elt_type, index_type, dependent);
1126 :
1127 : /* Mark it as dependent now, this saves time later. */
1128 1102597 : TYPE_DEPENDENT_P_VALID (t) = true;
1129 1102597 : TYPE_DEPENDENT_P (t) = true;
1130 : }
1131 : }
1132 : else
1133 : {
1134 14770144 : bool typeless_storage = is_byte_access_type (elt_type);
1135 14770144 : t = build_array_type (elt_type, index_type, typeless_storage);
1136 :
1137 : /* Mark as non-dependenty now, this will save time later. */
1138 14770144 : TYPE_DEPENDENT_P_VALID (t) = true;
1139 : }
1140 :
1141 : /* Now check whether we already have this array variant. */
1142 28250015 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1143 : {
1144 : tree m = t;
1145 24884642 : for (t = m; t; t = TYPE_NEXT_VARIANT (t))
1146 23099643 : if (TREE_TYPE (t) == elt_type
1147 10605967 : && TYPE_NAME (t) == NULL_TREE
1148 33691918 : && TYPE_ATTRIBUTES (t) == NULL_TREE)
1149 : break;
1150 12377274 : if (!t)
1151 : {
1152 1784999 : t = build_min_array_type (elt_type, index_type);
1153 : /* Mark dependency now, this saves time later. */
1154 1784999 : TYPE_DEPENDENT_P_VALID (t) = true;
1155 1784999 : TYPE_DEPENDENT_P (t) = dependent;
1156 1784999 : set_array_type_canon (t, elt_type, index_type, dependent);
1157 1784999 : if (!dependent)
1158 : {
1159 1513584 : layout_type (t);
1160 : /* Make sure sizes are shared with the main variant.
1161 : layout_type can't be called after setting TYPE_NEXT_VARIANT,
1162 : as it will overwrite alignment etc. of all variants. */
1163 1513584 : TYPE_SIZE (t) = TYPE_SIZE (m);
1164 1513584 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
1165 1513584 : TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
1166 : }
1167 :
1168 1784999 : TYPE_MAIN_VARIANT (t) = m;
1169 1784999 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
1170 1784999 : TYPE_NEXT_VARIANT (m) = t;
1171 : }
1172 : }
1173 :
1174 : /* Avoid spurious warnings with VLAs (c++/54583). */
1175 28250015 : if (CAN_HAVE_LOCATION_P (TYPE_SIZE (t)))
1176 1877 : suppress_warning (TYPE_SIZE (t), OPT_Wunused);
1177 :
1178 : /* Push these needs up to the ARRAY_TYPE so that initialization takes
1179 : place more easily. */
1180 56500030 : bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t)
1181 28250015 : = TYPE_NEEDS_CONSTRUCTING (elt_type));
1182 56500030 : bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1183 28250015 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
1184 :
1185 26775184 : if (!dependent && t == TYPE_MAIN_VARIANT (t)
1186 43020159 : && !COMPLETE_TYPE_P (t) && COMPLETE_TYPE_P (elt_type))
1187 : {
1188 : /* The element type has been completed since the last time we saw
1189 : this array type; update the layout and 'tor flags for any variants
1190 : that need it. */
1191 747452 : layout_type (t);
1192 1215889 : for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
1193 : {
1194 468437 : TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
1195 468437 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (v) = needs_dtor;
1196 : }
1197 : }
1198 :
1199 : return t;
1200 : }
1201 :
1202 : /* Return an ARRAY_TYPE with element type ELT and length N. */
1203 :
1204 : tree
1205 1475713 : build_array_of_n_type (tree elt, int n)
1206 : {
1207 1475713 : return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
1208 : }
1209 :
1210 : /* True iff T is an array of unknown bound. */
1211 :
1212 : bool
1213 3426909 : array_of_unknown_bound_p (const_tree t)
1214 : {
1215 3426909 : return (TREE_CODE (t) == ARRAY_TYPE
1216 3426909 : && !TYPE_DOMAIN (t));
1217 : }
1218 :
1219 : /* True iff T is an N3639 array of runtime bound (VLA). These were approved
1220 : for C++14 but then removed. This should only be used for N3639
1221 : specifically; code wondering more generally if something is a VLA should use
1222 : vla_type_p. */
1223 :
1224 : bool
1225 87790 : array_of_runtime_bound_p (tree t)
1226 : {
1227 87790 : if (!t || TREE_CODE (t) != ARRAY_TYPE)
1228 : return false;
1229 207 : if (variably_modified_type_p (TREE_TYPE (t), NULL_TREE))
1230 : return false;
1231 195 : tree dom = TYPE_DOMAIN (t);
1232 195 : if (!dom)
1233 : return false;
1234 192 : tree max = TYPE_MAX_VALUE (dom);
1235 192 : return (!potential_rvalue_constant_expression (max)
1236 192 : || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)));
1237 : }
1238 :
1239 : /* True iff T is a variable length array. */
1240 :
1241 : bool
1242 15345509 : vla_type_p (tree t)
1243 : {
1244 15764569 : for (; t && TREE_CODE (t) == ARRAY_TYPE;
1245 419060 : t = TREE_TYPE (t))
1246 419272 : if (tree dom = TYPE_DOMAIN (t))
1247 : {
1248 419190 : tree max = TYPE_MAX_VALUE (dom);
1249 419190 : if (!potential_rvalue_constant_expression (max)
1250 419190 : || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)))
1251 212 : return true;
1252 : }
1253 : return false;
1254 : }
1255 :
1256 :
1257 : /* Return a reference type node of MODE referring to TO_TYPE. If MODE
1258 : is VOIDmode the standard pointer mode will be picked. If RVAL is
1259 : true, return an rvalue reference type, otherwise return an lvalue
1260 : reference type. If a type node exists, reuse it, otherwise create
1261 : a new one. */
1262 : tree
1263 240128961 : cp_build_reference_type_for_mode (tree to_type, machine_mode mode, bool rval)
1264 : {
1265 240128961 : tree lvalue_ref, t;
1266 :
1267 240128961 : if (to_type == error_mark_node)
1268 : return error_mark_node;
1269 :
1270 240128958 : if (TYPE_REF_P (to_type))
1271 : {
1272 30 : rval = rval && TYPE_REF_IS_RVALUE (to_type);
1273 30 : to_type = TREE_TYPE (to_type);
1274 : }
1275 :
1276 240128958 : lvalue_ref = build_reference_type_for_mode (to_type, mode, false);
1277 :
1278 240128958 : if (!rval)
1279 : return lvalue_ref;
1280 :
1281 : /* This code to create rvalue reference types is based on and tied
1282 : to the code creating lvalue reference types in the middle-end
1283 : functions build_reference_type_for_mode and build_reference_type.
1284 :
1285 : It works by putting the rvalue reference type nodes after the
1286 : lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
1287 : they will effectively be ignored by the middle end. */
1288 :
1289 49819583 : for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
1290 35903565 : if (TYPE_REF_IS_RVALUE (t))
1291 35903565 : return t;
1292 :
1293 13916018 : t = build_distinct_type_copy (lvalue_ref);
1294 :
1295 13916018 : TYPE_REF_IS_RVALUE (t) = true;
1296 13916018 : TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
1297 13916018 : TYPE_NEXT_REF_TO (lvalue_ref) = t;
1298 :
1299 13916018 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
1300 485352 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1301 13430666 : else if (TYPE_CANONICAL (to_type) != to_type)
1302 7936642 : TYPE_CANONICAL (t)
1303 15873284 : = cp_build_reference_type_for_mode (TYPE_CANONICAL (to_type), mode, rval);
1304 : else
1305 5494024 : TYPE_CANONICAL (t) = t;
1306 :
1307 13916018 : layout_type (t);
1308 :
1309 13916018 : return t;
1310 :
1311 : }
1312 :
1313 : /* Return a reference type node referring to TO_TYPE. If RVAL is
1314 : true, return an rvalue reference type, otherwise return an lvalue
1315 : reference type. If a type node exists, reuse it, otherwise create
1316 : a new one. */
1317 : tree
1318 214842344 : cp_build_reference_type (tree to_type, bool rval)
1319 : {
1320 213997306 : return cp_build_reference_type_for_mode (to_type, VOIDmode, rval);
1321 : }
1322 :
1323 : /* Returns EXPR cast to rvalue reference type, like std::move. */
1324 :
1325 : tree
1326 845130 : move (tree expr)
1327 : {
1328 845130 : tree type = TREE_TYPE (expr);
1329 845130 : gcc_assert (!TYPE_REF_P (type));
1330 845130 : if (xvalue_p (expr))
1331 : return expr;
1332 845038 : type = cp_build_reference_type (type, /*rval*/true);
1333 845038 : return build_static_cast (input_location, type, expr,
1334 845038 : tf_warning_or_error);
1335 : }
1336 :
1337 : /* Used by the C++ front end to build qualified array types. However,
1338 : the C version of this function does not properly maintain canonical
1339 : types (which are not used in C). */
1340 : tree
1341 11746129 : c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */,
1342 : size_t /* orig_qual_indirect */)
1343 : {
1344 11746129 : return cp_build_qualified_type (type, type_quals);
1345 : }
1346 :
1347 :
1348 : /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
1349 : arrays correctly. In particular, if TYPE is an array of T's, and
1350 : TYPE_QUALS is non-empty, returns an array of qualified T's.
1351 :
1352 : FLAGS determines how to deal with ill-formed qualifications. If
1353 : tf_ignore_bad_quals is set, then bad qualifications are dropped
1354 : (this is permitted if TYPE was introduced via a typedef or template
1355 : type parameter). If bad qualifications are dropped and tf_warning
1356 : is set, then a warning is issued for non-const qualifications. If
1357 : tf_ignore_bad_quals is not set and tf_error is not set, we
1358 : return error_mark_node. Otherwise, we issue an error, and ignore
1359 : the qualifications.
1360 :
1361 : Qualification of a reference type is valid when the reference came
1362 : via a typedef or template type argument. [dcl.ref] No such
1363 : dispensation is provided for qualifying a function type. [dcl.fct]
1364 : DR 295 queries this and the proposed resolution brings it into line
1365 : with qualifying a reference. We implement the DR. We also behave
1366 : in a similar manner for restricting non-pointer types. */
1367 :
1368 : tree
1369 7803575956 : cp_build_qualified_type (tree type, int type_quals,
1370 : tsubst_flags_t complain /* = tf_warning_or_error */)
1371 : {
1372 7803575956 : tree result;
1373 7803575956 : int bad_quals = TYPE_UNQUALIFIED;
1374 :
1375 7803575956 : if (type == error_mark_node)
1376 : return type;
1377 :
1378 7786556241 : if (type_quals == cp_type_quals (type))
1379 : return type;
1380 :
1381 1175656120 : if (TREE_CODE (type) == ARRAY_TYPE)
1382 : {
1383 : /* In C++, the qualification really applies to the array element
1384 : type. Obtain the appropriately qualified element type. */
1385 14099303 : tree t;
1386 14099303 : tree element_type
1387 14099303 : = cp_build_qualified_type (TREE_TYPE (type), type_quals, complain);
1388 :
1389 14099303 : if (element_type == error_mark_node)
1390 : return error_mark_node;
1391 :
1392 : /* See if we already have an identically qualified type. Tests
1393 : should be equivalent to those in check_qualified_type. */
1394 26162177 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1395 14850365 : if (TREE_TYPE (t) == element_type
1396 2799755 : && TYPE_NAME (t) == TYPE_NAME (type)
1397 2787491 : && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
1398 17637856 : && attribute_list_equal (TYPE_ATTRIBUTES (t),
1399 2787491 : TYPE_ATTRIBUTES (type)))
1400 : break;
1401 :
1402 14099303 : if (!t)
1403 : {
1404 : /* If we already know the dependentness, tell the array type
1405 : constructor. This is important for module streaming, as we cannot
1406 : dynamically determine that on read in. */
1407 11311812 : t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
1408 11311812 : TYPE_DEPENDENT_P_VALID (type)
1409 230649 : ? int (TYPE_DEPENDENT_P (type)) : -1);
1410 :
1411 : /* Keep the typedef name. */
1412 11311812 : if (TYPE_NAME (t) != TYPE_NAME (type))
1413 : {
1414 535 : t = build_variant_type_copy (t);
1415 535 : TYPE_NAME (t) = TYPE_NAME (type);
1416 535 : SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
1417 535 : TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
1418 : }
1419 : }
1420 :
1421 : /* Even if we already had this variant, we update
1422 : TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
1423 : they changed since the variant was originally created.
1424 :
1425 : This seems hokey; if there is some way to use a previous
1426 : variant *without* coming through here,
1427 : TYPE_NEEDS_CONSTRUCTING will never be updated. */
1428 28198606 : TYPE_NEEDS_CONSTRUCTING (t)
1429 14099303 : = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
1430 28198606 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1431 14099303 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
1432 14099303 : return t;
1433 : }
1434 1161556817 : else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
1435 : {
1436 3 : tree t = PACK_EXPANSION_PATTERN (type);
1437 :
1438 3 : t = cp_build_qualified_type (t, type_quals, complain);
1439 3 : return make_pack_expansion (t, complain);
1440 : }
1441 :
1442 : /* A reference or method type shall not be cv-qualified.
1443 : [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
1444 : (in CD1) we always ignore extra cv-quals on functions. */
1445 :
1446 : /* [dcl.ref/1] Cv-qualified references are ill-formed except when
1447 : the cv-qualifiers are introduced through the use of a typedef-name
1448 : ([dcl.typedef], [temp.param]) or decltype-specifier
1449 : ([dcl.type.decltype]),in which case the cv-qualifiers are
1450 : ignored. */
1451 1161556814 : if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
1452 482104623 : && (TYPE_REF_P (type)
1453 481917825 : || FUNC_OR_METHOD_TYPE_P (type)))
1454 : {
1455 201398 : if (TYPE_REF_P (type)
1456 201398 : && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
1457 : bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1458 201398 : type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1459 : }
1460 :
1461 : /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1462 1161556814 : if (TREE_CODE (type) == FUNCTION_TYPE)
1463 14604 : type_quals |= type_memfn_quals (type);
1464 :
1465 : /* A restrict-qualified type must be a pointer (or reference)
1466 : to object or incomplete type. */
1467 1161556814 : if ((type_quals & TYPE_QUAL_RESTRICT)
1468 5774755 : && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1469 5774718 : && TREE_CODE (type) != TYPENAME_TYPE
1470 5774710 : && !INDIRECT_TYPE_P (type))
1471 : {
1472 27 : bad_quals |= TYPE_QUAL_RESTRICT;
1473 27 : type_quals &= ~TYPE_QUAL_RESTRICT;
1474 : }
1475 :
1476 1161556814 : if (bad_quals == TYPE_UNQUALIFIED
1477 181965 : || (complain & tf_ignore_bad_quals))
1478 : /*OK*/;
1479 16 : else if (!(complain & tf_error))
1480 0 : return error_mark_node;
1481 : else
1482 : {
1483 16 : tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
1484 16 : error ("%qV qualifiers cannot be applied to %qT",
1485 : bad_type, type);
1486 : }
1487 :
1488 : /* Retrieve (or create) the appropriately qualified variant. */
1489 1161556814 : result = build_qualified_type (type, type_quals);
1490 :
1491 1161556814 : return result;
1492 : }
1493 :
1494 : /* Return TYPE with const and volatile removed. */
1495 :
1496 : tree
1497 809716042 : cv_unqualified (tree type)
1498 : {
1499 809716042 : int quals;
1500 :
1501 809716042 : if (type == error_mark_node)
1502 : return type;
1503 :
1504 809715820 : quals = cp_type_quals (type);
1505 809715820 : quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
1506 809715820 : return cp_build_qualified_type (type, quals);
1507 : }
1508 :
1509 : /* Subroutine of strip_typedefs. We want to apply to RESULT the attributes
1510 : from ATTRIBS that affect type identity, and no others. If any are not
1511 : applied, set *remove_attributes to true. */
1512 :
1513 : static tree
1514 388956 : apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
1515 : {
1516 388956 : tree first_ident = NULL_TREE;
1517 388956 : tree new_attribs = NULL_TREE;
1518 388956 : tree *p = &new_attribs;
1519 :
1520 388956 : if (OVERLOAD_TYPE_P (result))
1521 : {
1522 : /* On classes and enums all attributes are ingrained. */
1523 387935 : gcc_assert (attribs == TYPE_ATTRIBUTES (result));
1524 : return result;
1525 : }
1526 :
1527 2045 : for (tree a = attribs; a; a = TREE_CHAIN (a))
1528 : {
1529 1024 : const attribute_spec *as
1530 1024 : = lookup_attribute_spec (get_attribute_name (a));
1531 1024 : if (as && as->affects_type_identity)
1532 : {
1533 518 : if (!first_ident)
1534 : first_ident = a;
1535 0 : else if (first_ident == error_mark_node)
1536 : {
1537 0 : *p = tree_cons (TREE_PURPOSE (a), TREE_VALUE (a), NULL_TREE);
1538 0 : p = &TREE_CHAIN (*p);
1539 : }
1540 : }
1541 506 : else if (first_ident && first_ident != error_mark_node)
1542 : {
1543 0 : for (tree a2 = first_ident; a2 != a; a2 = TREE_CHAIN (a2))
1544 : {
1545 0 : *p = tree_cons (TREE_PURPOSE (a2), TREE_VALUE (a2), NULL_TREE);
1546 0 : p = &TREE_CHAIN (*p);
1547 : }
1548 0 : first_ident = error_mark_node;
1549 : }
1550 : }
1551 1021 : if (first_ident != error_mark_node)
1552 1021 : new_attribs = first_ident;
1553 :
1554 1021 : if (first_ident == attribs)
1555 : /* All attributes affected type identity. */;
1556 : else
1557 503 : *remove_attributes = true;
1558 :
1559 1021 : return cp_build_type_attribute_variant (result, new_attribs);
1560 : }
1561 :
1562 : /* Builds a qualified variant of T that is either not a typedef variant
1563 : (the default behavior) or not a typedef variant of a user-facing type
1564 : (if FLAGS contains STF_USER_FACING). If T is not a type, then this
1565 : just dispatches to strip_typedefs_expr.
1566 :
1567 : E.g. consider the following declarations:
1568 : typedef const int ConstInt;
1569 : typedef ConstInt* PtrConstInt;
1570 : If T is PtrConstInt, this function returns a type representing
1571 : const int*.
1572 : In other words, if T is a typedef, the function returns the underlying type.
1573 : The cv-qualification and attributes of the type returned match the
1574 : input type.
1575 : They will always be compatible types.
1576 : The returned type is built so that all of its subtypes
1577 : recursively have their typedefs stripped as well.
1578 :
1579 : This is different from just returning TYPE_CANONICAL (T)
1580 : Because of several reasons:
1581 : * If T is a type that needs structural equality
1582 : its TYPE_CANONICAL (T) will be NULL.
1583 : * TYPE_CANONICAL (T) desn't carry type attributes
1584 : and loses template parameter names.
1585 :
1586 : If REMOVE_ATTRIBUTES is non-null, also strip attributes that don't
1587 : affect type identity, and set the referent to true if any were
1588 : stripped. */
1589 :
1590 : tree
1591 1418037946 : strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
1592 : unsigned int flags /* = 0 */)
1593 : {
1594 1418037946 : tree result = NULL, type = NULL, t0 = NULL;
1595 :
1596 1418037946 : if (!t || t == error_mark_node)
1597 : return t;
1598 :
1599 1396348645 : if (!TYPE_P (t))
1600 123673274 : return strip_typedefs_expr (t, remove_attributes, flags);
1601 :
1602 1272675371 : if (t == TYPE_CANONICAL (t))
1603 : return t;
1604 :
1605 391527551 : if (!(flags & STF_STRIP_DEPENDENT)
1606 391527551 : && dependent_alias_template_spec_p (t, nt_opaque))
1607 : /* DR 1558: However, if the template-id is dependent, subsequent
1608 : template argument substitution still applies to the template-id. */
1609 : return t;
1610 :
1611 388114168 : switch (TREE_CODE (t))
1612 : {
1613 10619312 : case POINTER_TYPE:
1614 10619312 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1615 10619312 : result = build_pointer_type_for_mode (type, TYPE_MODE (t), false);
1616 10619312 : break;
1617 17349975 : case REFERENCE_TYPE:
1618 17349975 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1619 17349975 : result = cp_build_reference_type_for_mode (type, TYPE_MODE (t), TYPE_REF_IS_RVALUE (t));
1620 17349975 : break;
1621 347793 : case OFFSET_TYPE:
1622 347793 : t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags);
1623 347793 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1624 347793 : result = build_offset_type (t0, type);
1625 347793 : break;
1626 40213828 : case RECORD_TYPE:
1627 40213828 : if (TYPE_PTRMEMFUNC_P (t))
1628 : {
1629 1439655 : t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t),
1630 : remove_attributes, flags);
1631 1439655 : result = build_ptrmemfunc_type (t0);
1632 : }
1633 : break;
1634 1482191 : case ARRAY_TYPE:
1635 1482191 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1636 1482191 : t0 = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags);
1637 1482191 : gcc_checking_assert (TYPE_DEPENDENT_P_VALID (t)
1638 : || !dependent_type_p (t));
1639 1482191 : result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t));
1640 1482191 : break;
1641 2685198 : case FUNCTION_TYPE:
1642 2685198 : case METHOD_TYPE:
1643 2685198 : {
1644 2685198 : tree arg_types = NULL, arg_node, arg_node2, arg_type;
1645 2685198 : bool changed;
1646 :
1647 : /* Because we stomp on TREE_PURPOSE of TYPE_ARG_TYPES in many places
1648 : around the compiler (e.g. cp_parser_late_parsing_default_args), we
1649 : can't expect that re-hashing a function type will find a previous
1650 : equivalent type, so try to reuse the input type if nothing has
1651 : changed. If the type is itself a variant, that will change. */
1652 2685198 : bool is_variant = typedef_variant_p (t);
1653 2685198 : if (remove_attributes
1654 2685198 : && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t)))
1655 : is_variant = true;
1656 :
1657 2685198 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1658 2685198 : tree canon_spec = (flag_noexcept_type
1659 2685198 : ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t))
1660 2685198 : : NULL_TREE);
1661 5132905 : changed = (type != TREE_TYPE (t) || is_variant
1662 5130140 : || TYPE_RAISES_EXCEPTIONS (t) != canon_spec);
1663 :
1664 2685198 : for (arg_node = TYPE_ARG_TYPES (t);
1665 6775642 : arg_node;
1666 4090444 : arg_node = TREE_CHAIN (arg_node))
1667 : {
1668 6066865 : if (arg_node == void_list_node)
1669 : break;
1670 4090444 : arg_type = strip_typedefs (TREE_VALUE (arg_node),
1671 : remove_attributes, flags);
1672 4090444 : gcc_assert (arg_type);
1673 4090444 : if (arg_type == TREE_VALUE (arg_node) && !changed)
1674 3892611 : continue;
1675 :
1676 197833 : if (!changed)
1677 : {
1678 35247 : changed = true;
1679 35247 : for (arg_node2 = TYPE_ARG_TYPES (t);
1680 42450 : arg_node2 != arg_node;
1681 7203 : arg_node2 = TREE_CHAIN (arg_node2))
1682 7203 : arg_types
1683 7203 : = tree_cons (TREE_PURPOSE (arg_node2),
1684 7203 : TREE_VALUE (arg_node2), arg_types);
1685 : }
1686 :
1687 197833 : arg_types
1688 197833 : = tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
1689 : }
1690 :
1691 2685198 : if (!changed)
1692 : return t;
1693 :
1694 275720 : if (arg_types)
1695 52255 : arg_types = nreverse (arg_types);
1696 :
1697 : /* A list of parameters not ending with an ellipsis
1698 : must end with void_list_node. */
1699 275720 : if (arg_node)
1700 275566 : arg_types = chainon (arg_types, void_list_node);
1701 :
1702 275720 : if (TREE_CODE (t) == METHOD_TYPE)
1703 : {
1704 20801 : tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
1705 20801 : gcc_assert (class_type);
1706 20801 : result =
1707 20801 : build_method_type_directly (class_type, type,
1708 20801 : TREE_CHAIN (arg_types));
1709 : }
1710 : else
1711 : {
1712 254919 : result = build_function_type (type, arg_types);
1713 254919 : result = apply_memfn_quals (result, type_memfn_quals (t));
1714 : }
1715 :
1716 827160 : result = build_cp_fntype_variant (result,
1717 : type_memfn_rqual (t), canon_spec,
1718 275720 : TYPE_HAS_LATE_RETURN_TYPE (t));
1719 : }
1720 275720 : break;
1721 25920492 : case TYPENAME_TYPE:
1722 25920492 : {
1723 25920492 : bool changed = false;
1724 25920492 : tree fullname = TYPENAME_TYPE_FULLNAME (t);
1725 25920492 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
1726 25920492 : && TREE_OPERAND (fullname, 1))
1727 : {
1728 647720 : tree args = TREE_OPERAND (fullname, 1);
1729 647720 : tree new_args = copy_node (args);
1730 1520100 : for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
1731 : {
1732 872380 : tree arg = TREE_VEC_ELT (args, i);
1733 872380 : tree strip_arg = strip_typedefs (arg, remove_attributes, flags);
1734 872380 : TREE_VEC_ELT (new_args, i) = strip_arg;
1735 872380 : if (strip_arg != arg)
1736 57884 : changed = true;
1737 : }
1738 647720 : if (changed)
1739 : {
1740 57884 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
1741 57884 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
1742 57884 : fullname
1743 57884 : = lookup_template_function (TREE_OPERAND (fullname, 0),
1744 : new_args);
1745 : }
1746 : else
1747 589836 : ggc_free (new_args);
1748 : }
1749 25920492 : tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes, flags);
1750 25920492 : if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t))
1751 : return t;
1752 8296474 : tree name = fullname;
1753 8296474 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
1754 196030 : name = TREE_OPERAND (fullname, 0);
1755 : /* Use build_typename_type rather than make_typename_type because we
1756 : don't want to resolve it here, just strip typedefs. */
1757 8296474 : result = build_typename_type (ctx, name, fullname, typename_type);
1758 : }
1759 8296474 : break;
1760 2863636 : case DECLTYPE_TYPE:
1761 2863636 : result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t),
1762 : remove_attributes, flags);
1763 2863636 : if (result == DECLTYPE_TYPE_EXPR (t))
1764 : result = NULL_TREE;
1765 : else
1766 57756 : result = (finish_decltype_type
1767 57756 : (result,
1768 57756 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
1769 : tf_none));
1770 : break;
1771 27 : case TRAIT_TYPE:
1772 27 : {
1773 27 : tree type1 = strip_typedefs (TRAIT_TYPE_TYPE1 (t),
1774 : remove_attributes, flags);
1775 27 : tree type2 = strip_typedefs (TRAIT_TYPE_TYPE2 (t),
1776 : remove_attributes, flags);
1777 27 : if (type1 == TRAIT_TYPE_TYPE1 (t) && type2 == TRAIT_TYPE_TYPE2 (t))
1778 : result = NULL_TREE;
1779 : else
1780 0 : result = finish_trait_type (TRAIT_TYPE_KIND (t), type1, type2,
1781 : tf_warning_or_error);
1782 : }
1783 : break;
1784 16346078 : case TYPE_PACK_EXPANSION:
1785 16346078 : {
1786 16346078 : tree pat = PACK_EXPANSION_PATTERN (t);
1787 16346078 : if (TYPE_P (pat))
1788 : {
1789 16346078 : type = strip_typedefs (pat, remove_attributes, flags);
1790 16346078 : if (type != pat)
1791 : {
1792 50249 : result = build_distinct_type_copy (t);
1793 50249 : PACK_EXPANSION_PATTERN (result) = type;
1794 : }
1795 : }
1796 : }
1797 : break;
1798 : default:
1799 : break;
1800 : }
1801 :
1802 39919125 : if (!result)
1803 : {
1804 328161547 : if (typedef_variant_p (t))
1805 : {
1806 46187703 : if ((flags & STF_USER_VISIBLE)
1807 46187703 : && !user_facing_original_type_p (t))
1808 : return t;
1809 : /* If T is a non-template alias or typedef, we can assume that
1810 : instantiating its definition will hit any substitution failure,
1811 : so we don't need to retain it here as well. */
1812 46186624 : if (!alias_template_specialization_p (t, nt_opaque))
1813 38455957 : flags |= STF_STRIP_DEPENDENT;
1814 46186624 : result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
1815 : remove_attributes, flags);
1816 : }
1817 : else
1818 281973844 : result = TYPE_MAIN_VARIANT (t);
1819 : }
1820 : /*gcc_assert (!typedef_variant_p (result)
1821 : || dependent_alias_template_spec_p (result, nt_opaque)
1822 : || ((flags & STF_USER_VISIBLE)
1823 : && !user_facing_original_type_p (result)));*/
1824 :
1825 368079593 : if (COMPLETE_TYPE_P (result) && !COMPLETE_TYPE_P (t))
1826 : /* If RESULT is complete and T isn't, it's likely the case that T
1827 : is a variant of RESULT which hasn't been updated yet. Skip the
1828 : attribute handling. */;
1829 : else
1830 : {
1831 368079585 : if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
1832 368079585 : || TYPE_ALIGN (t) != TYPE_ALIGN (result))
1833 : {
1834 24 : gcc_assert (TYPE_USER_ALIGN (t));
1835 24 : if (remove_attributes)
1836 12 : *remove_attributes = true;
1837 : else
1838 : {
1839 12 : if (TYPE_ALIGN (t) == TYPE_ALIGN (result))
1840 0 : result = build_variant_type_copy (result);
1841 : else
1842 12 : result = build_aligned_type (result, TYPE_ALIGN (t));
1843 12 : TYPE_USER_ALIGN (result) = true;
1844 : }
1845 : }
1846 :
1847 368079585 : if (TYPE_ATTRIBUTES (t))
1848 : {
1849 395992 : if (remove_attributes)
1850 388956 : result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t),
1851 : remove_attributes);
1852 : else
1853 7036 : result = cp_build_type_attribute_variant (result,
1854 7036 : TYPE_ATTRIBUTES (t));
1855 : }
1856 : }
1857 :
1858 368079593 : return cp_build_qualified_type (result, cp_type_quals (t));
1859 : }
1860 :
1861 : /* Like strip_typedefs above, but works on expressions (and other
1862 : non-types such as TREE_VEC), so that in
1863 :
1864 : template<class T> struct A
1865 : {
1866 : typedef T TT;
1867 : B<sizeof(TT)> b;
1868 : };
1869 :
1870 : sizeof(TT) is replaced by sizeof(T). */
1871 :
1872 : tree
1873 235841979 : strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags)
1874 : {
1875 235841979 : unsigned i,n;
1876 235841979 : tree r, type, *ops;
1877 235841979 : enum tree_code code;
1878 :
1879 235841979 : if (t == NULL_TREE || t == error_mark_node)
1880 : return t;
1881 :
1882 235841979 : STRIP_ANY_LOCATION_WRAPPER (t);
1883 :
1884 235841979 : if (DECL_P (t) || CONSTANT_CLASS_P (t))
1885 : return t;
1886 :
1887 144505878 : code = TREE_CODE (t);
1888 144505878 : switch (code)
1889 : {
1890 : case IDENTIFIER_NODE:
1891 : case TEMPLATE_PARM_INDEX:
1892 : case OVERLOAD:
1893 : case BASELINK:
1894 : case ARGUMENT_PACK_SELECT:
1895 : return t;
1896 :
1897 2067656 : case TRAIT_EXPR:
1898 2067656 : {
1899 2067656 : tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t),
1900 : remove_attributes, flags);
1901 2067656 : tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t),
1902 : remove_attributes, flags);
1903 2067656 : if (type1 == TRAIT_EXPR_TYPE1 (t)
1904 2067656 : && type2 == TRAIT_EXPR_TYPE2 (t))
1905 : return t;
1906 63983 : r = copy_node (t);
1907 63983 : TRAIT_EXPR_TYPE1 (r) = type1;
1908 63983 : TRAIT_EXPR_TYPE2 (r) = type2;
1909 63983 : return r;
1910 : }
1911 :
1912 780452 : case TREE_LIST:
1913 780452 : {
1914 780452 : bool changed = false;
1915 780452 : releasing_vec vec;
1916 780452 : r = t;
1917 1628952 : for (; t; t = TREE_CHAIN (t))
1918 : {
1919 848500 : gcc_assert (!TREE_PURPOSE (t));
1920 848500 : tree elt = strip_typedefs (TREE_VALUE (t),
1921 848500 : remove_attributes, flags);
1922 848500 : if (elt != TREE_VALUE (t))
1923 155701 : changed = true;
1924 848500 : vec_safe_push (vec, elt);
1925 : }
1926 780452 : if (changed)
1927 141159 : r = build_tree_list_vec (vec);
1928 780452 : return r;
1929 780452 : }
1930 :
1931 11338253 : case TREE_VEC:
1932 11338253 : {
1933 11338253 : bool changed = false;
1934 11338253 : releasing_vec vec;
1935 11338253 : n = TREE_VEC_LENGTH (t);
1936 11338253 : vec_safe_reserve (vec, n);
1937 27018297 : for (i = 0; i < n; ++i)
1938 : {
1939 15680044 : tree op = strip_typedefs (TREE_VEC_ELT (t, i),
1940 15680044 : remove_attributes, flags);
1941 15680044 : vec->quick_push (op);
1942 15680044 : if (op != TREE_VEC_ELT (t, i))
1943 37968 : changed = true;
1944 : }
1945 11338253 : if (changed)
1946 : {
1947 37968 : r = copy_node (t);
1948 113904 : for (i = 0; i < n; ++i)
1949 37968 : TREE_VEC_ELT (r, i) = (*vec)[i];
1950 75936 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
1951 75936 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
1952 : }
1953 : else
1954 : r = t;
1955 11338253 : return r;
1956 11338253 : }
1957 :
1958 188905 : case CONSTRUCTOR:
1959 188905 : {
1960 188905 : bool changed = false;
1961 188905 : vec<constructor_elt, va_gc> *vec
1962 188905 : = vec_safe_copy (CONSTRUCTOR_ELTS (t));
1963 188905 : n = CONSTRUCTOR_NELTS (t);
1964 188905 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1965 230891 : for (i = 0; i < n; ++i)
1966 : {
1967 41986 : constructor_elt *e = &(*vec)[i];
1968 41986 : tree op = strip_typedefs (e->value, remove_attributes, flags);
1969 41986 : if (op != e->value)
1970 : {
1971 4 : changed = true;
1972 4 : e->value = op;
1973 : }
1974 41986 : gcc_checking_assert
1975 : (e->index == strip_typedefs (e->index, remove_attributes,
1976 : flags));
1977 : }
1978 :
1979 188905 : if (!changed && type == TREE_TYPE (t))
1980 : {
1981 172717 : vec_free (vec);
1982 172717 : return t;
1983 : }
1984 : else
1985 : {
1986 16188 : r = copy_node (t);
1987 16188 : TREE_TYPE (r) = type;
1988 16188 : CONSTRUCTOR_ELTS (r) = vec;
1989 16188 : return r;
1990 : }
1991 : }
1992 :
1993 : case LAMBDA_EXPR:
1994 : return t;
1995 :
1996 3 : case STATEMENT_LIST:
1997 3 : error ("statement-expression in a constant expression");
1998 3 : return error_mark_node;
1999 :
2000 78627271 : default:
2001 78627271 : break;
2002 : }
2003 :
2004 78627271 : gcc_assert (EXPR_P (t));
2005 :
2006 78627271 : n = cp_tree_operand_length (t);
2007 78627271 : ops = XALLOCAVEC (tree, n);
2008 78627271 : type = TREE_TYPE (t);
2009 :
2010 78627271 : switch (code)
2011 : {
2012 1263428 : CASE_CONVERT:
2013 1263428 : case IMPLICIT_CONV_EXPR:
2014 1263428 : case DYNAMIC_CAST_EXPR:
2015 1263428 : case STATIC_CAST_EXPR:
2016 1263428 : case CONST_CAST_EXPR:
2017 1263428 : case REINTERPRET_CAST_EXPR:
2018 1263428 : case CAST_EXPR:
2019 1263428 : case NEW_EXPR:
2020 1263428 : type = strip_typedefs (type, remove_attributes, flags);
2021 : /* fallthrough */
2022 :
2023 78627271 : default:
2024 247671035 : for (i = 0; i < n; ++i)
2025 169043764 : ops[i] = strip_typedefs (TREE_OPERAND (t, i),
2026 : remove_attributes, flags);
2027 : break;
2028 : }
2029 :
2030 : /* If nothing changed, return t. */
2031 243605549 : for (i = 0; i < n; ++i)
2032 167382386 : if (ops[i] != TREE_OPERAND (t, i))
2033 : break;
2034 78627271 : if (i == n && type == TREE_TYPE (t))
2035 : return t;
2036 :
2037 2572678 : r = copy_node (t);
2038 2572678 : TREE_TYPE (r) = type;
2039 8057929 : for (i = 0; i < n; ++i)
2040 5485251 : TREE_OPERAND (r, i) = ops[i];
2041 : return r;
2042 : }
2043 :
2044 : /* Makes a copy of BINFO and TYPE, which is to be inherited into a
2045 : graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
2046 : and we do a shallow copy. If BINFO is non-NULL, we do a deep copy.
2047 : VIRT indicates whether TYPE is inherited virtually or not.
2048 : IGO_PREV points at the previous binfo of the inheritance graph
2049 : order chain. The newly copied binfo's TREE_CHAIN forms this
2050 : ordering.
2051 :
2052 : The CLASSTYPE_VBASECLASSES vector of T is constructed in the
2053 : correct order. That is in the order the bases themselves should be
2054 : constructed in.
2055 :
2056 : The BINFO_INHERITANCE of a virtual base class points to the binfo
2057 : of the most derived type. ??? We could probably change this so that
2058 : BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
2059 : remove a field. They currently can only differ for primary virtual
2060 : virtual bases. */
2061 :
2062 : tree
2063 23992421 : copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
2064 : {
2065 23992421 : tree new_binfo;
2066 :
2067 23992421 : if (virt)
2068 : {
2069 : /* See if we've already made this virtual base. */
2070 222228 : new_binfo = binfo_for_vbase (type, t);
2071 222228 : if (new_binfo)
2072 : return new_binfo;
2073 : }
2074 :
2075 43096856 : new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
2076 23937884 : BINFO_TYPE (new_binfo) = type;
2077 :
2078 : /* Chain it into the inheritance graph. */
2079 23937884 : TREE_CHAIN (*igo_prev) = new_binfo;
2080 23937884 : *igo_prev = new_binfo;
2081 :
2082 43096856 : if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
2083 : {
2084 19158968 : int ix;
2085 19158968 : tree base_binfo;
2086 :
2087 19158968 : gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
2088 :
2089 19158968 : BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
2090 19158968 : BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
2091 :
2092 : /* We do not need to copy the accesses, as they are read only. */
2093 19158968 : BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
2094 :
2095 : /* Recursively copy base binfos of BINFO. */
2096 22295403 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
2097 : {
2098 3136435 : tree new_base_binfo;
2099 3136435 : new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
2100 : t, igo_prev,
2101 3136435 : BINFO_VIRTUAL_P (base_binfo));
2102 :
2103 3136435 : if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
2104 2966952 : BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
2105 3136435 : BINFO_BASE_APPEND (new_binfo, new_base_binfo);
2106 : }
2107 : }
2108 : else
2109 4778916 : BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
2110 :
2111 23937884 : if (virt)
2112 : {
2113 : /* Push it onto the list after any virtual bases it contains
2114 : will have been pushed. */
2115 167691 : CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo);
2116 167691 : BINFO_VIRTUAL_P (new_binfo) = 1;
2117 167691 : BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
2118 : }
2119 :
2120 : return new_binfo;
2121 : }
2122 :
2123 : /* Hashing of lists so that we don't make duplicates.
2124 : The entry point is `list_hash_canon'. */
2125 :
2126 : struct list_proxy
2127 : {
2128 : tree purpose;
2129 : tree value;
2130 : tree chain;
2131 : };
2132 :
2133 : struct list_hasher : ggc_ptr_hash<tree_node>
2134 : {
2135 : typedef list_proxy *compare_type;
2136 :
2137 : static hashval_t hash (tree);
2138 : static bool equal (tree, list_proxy *);
2139 : };
2140 :
2141 : /* Now here is the hash table. When recording a list, it is added
2142 : to the slot whose index is the hash code mod the table size.
2143 : Note that the hash table is used for several kinds of lists.
2144 : While all these live in the same table, they are completely independent,
2145 : and the hash code is computed differently for each of these. */
2146 :
2147 : static GTY (()) hash_table<list_hasher> *list_hash_table;
2148 :
2149 : /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
2150 : for a node we are thinking about adding). */
2151 :
2152 : bool
2153 1225535490 : list_hasher::equal (tree t, list_proxy *proxy)
2154 : {
2155 1225535490 : return (TREE_VALUE (t) == proxy->value
2156 96820722 : && TREE_PURPOSE (t) == proxy->purpose
2157 1320869561 : && TREE_CHAIN (t) == proxy->chain);
2158 : }
2159 :
2160 : /* Compute a hash code for a list (chain of TREE_LIST nodes
2161 : with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
2162 : TREE_COMMON slots), by adding the hash codes of the individual entries. */
2163 :
2164 : static hashval_t
2165 1124062118 : list_hash_pieces (tree purpose, tree value, tree chain)
2166 : {
2167 1124062118 : hashval_t hashcode = 0;
2168 :
2169 1124062118 : if (chain)
2170 1123408349 : hashcode += TREE_HASH (chain);
2171 :
2172 1124062118 : if (value)
2173 1124062118 : hashcode += TREE_HASH (value);
2174 : else
2175 0 : hashcode += 1007;
2176 1124062118 : if (purpose)
2177 97860067 : hashcode += TREE_HASH (purpose);
2178 : else
2179 1026202051 : hashcode += 1009;
2180 1124062118 : return hashcode;
2181 : }
2182 :
2183 : /* Hash an already existing TREE_LIST. */
2184 :
2185 : hashval_t
2186 951690805 : list_hasher::hash (tree t)
2187 : {
2188 951690805 : return list_hash_pieces (TREE_PURPOSE (t),
2189 951690805 : TREE_VALUE (t),
2190 951690805 : TREE_CHAIN (t));
2191 : }
2192 :
2193 : /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
2194 : object for an identical list if one already exists. Otherwise, build a
2195 : new one, and record it as the canonical object. */
2196 :
2197 : tree
2198 172371313 : hash_tree_cons (tree purpose, tree value, tree chain)
2199 : {
2200 172371313 : int hashcode = 0;
2201 172371313 : tree *slot;
2202 172371313 : struct list_proxy proxy;
2203 :
2204 : /* Hash the list node. */
2205 172371313 : hashcode = list_hash_pieces (purpose, value, chain);
2206 : /* Create a proxy for the TREE_LIST we would like to create. We
2207 : don't actually create it so as to avoid creating garbage. */
2208 172371313 : proxy.purpose = purpose;
2209 172371313 : proxy.value = value;
2210 172371313 : proxy.chain = chain;
2211 : /* See if it is already in the table. */
2212 172371313 : slot = list_hash_table->find_slot_with_hash (&proxy, hashcode, INSERT);
2213 : /* If not, create a new node. */
2214 172371313 : if (!*slot)
2215 81743430 : *slot = tree_cons (purpose, value, chain);
2216 172371313 : return (tree) *slot;
2217 : }
2218 :
2219 : /* Constructor for hashed lists. */
2220 :
2221 : tree
2222 7339618 : hash_tree_chain (tree value, tree chain)
2223 : {
2224 7339618 : return hash_tree_cons (NULL_TREE, value, chain);
2225 : }
2226 :
2227 : void
2228 0 : debug_binfo (tree elem)
2229 : {
2230 0 : HOST_WIDE_INT n;
2231 0 : tree virtuals;
2232 :
2233 0 : fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
2234 : "\nvtable type:\n",
2235 0 : TYPE_NAME_STRING (BINFO_TYPE (elem)),
2236 0 : TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
2237 0 : debug_tree (BINFO_TYPE (elem));
2238 0 : if (BINFO_VTABLE (elem))
2239 0 : fprintf (stderr, "vtable decl \"%s\"\n",
2240 0 : IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
2241 : else
2242 0 : fprintf (stderr, "no vtable decl yet\n");
2243 0 : fprintf (stderr, "virtuals:\n");
2244 0 : virtuals = BINFO_VIRTUALS (elem);
2245 0 : n = 0;
2246 :
2247 0 : while (virtuals)
2248 : {
2249 0 : tree fndecl = TREE_VALUE (virtuals);
2250 0 : fprintf (stderr, "%s [%ld =? %ld]\n",
2251 0 : IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
2252 0 : (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
2253 0 : ++n;
2254 0 : virtuals = TREE_CHAIN (virtuals);
2255 : }
2256 0 : }
2257 :
2258 : /* Build a representation for the qualified name SCOPE::NAME. TYPE is
2259 : the type of the result expression, if known, or NULL_TREE if the
2260 : resulting expression is type-dependent. If TEMPLATE_P is true,
2261 : NAME is known to be a template because the user explicitly used the
2262 : "template" keyword after the "::".
2263 :
2264 : All SCOPE_REFs should be built by use of this function. */
2265 :
2266 : tree
2267 114935569 : build_qualified_name (tree type, tree scope, tree name, bool template_p)
2268 : {
2269 114935569 : tree t;
2270 114935569 : if (type == error_mark_node
2271 114935569 : || scope == error_mark_node
2272 114935565 : || name == error_mark_node)
2273 : return error_mark_node;
2274 114935565 : gcc_assert (TREE_CODE (name) != SCOPE_REF);
2275 114935565 : t = build2 (SCOPE_REF, type, scope, name);
2276 114935565 : QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
2277 114935565 : PTRMEM_OK_P (t) = true;
2278 114935565 : if (type)
2279 6971949 : t = convert_from_reference (t);
2280 : return t;
2281 : }
2282 :
2283 : /* Like check_qualified_type, but also check ref-qualifier, exception
2284 : specification, and whether the return type was specified after the
2285 : parameters. */
2286 :
2287 : static bool
2288 721819888 : cp_check_qualified_type (const_tree cand, const_tree base, int type_quals,
2289 : cp_ref_qualifier rqual, tree raises, bool late)
2290 : {
2291 721819888 : return (TYPE_QUALS (cand) == type_quals
2292 721764019 : && check_base_type (cand, base)
2293 721751157 : && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand),
2294 : ce_exact)
2295 348969319 : && TYPE_HAS_LATE_RETURN_TYPE (cand) == late
2296 1048172155 : && type_memfn_rqual (cand) == rqual);
2297 : }
2298 :
2299 : /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */
2300 :
2301 : tree
2302 256606 : build_ref_qualified_type (tree type, cp_ref_qualifier rqual)
2303 : {
2304 256606 : tree raises = TYPE_RAISES_EXCEPTIONS (type);
2305 256606 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
2306 256606 : return build_cp_fntype_variant (type, rqual, raises, late);
2307 : }
2308 :
2309 : tree
2310 253852 : make_binding_vec (tree name, unsigned clusters MEM_STAT_DECL)
2311 : {
2312 : /* Stored in an unsigned short, but we're limited to the number of
2313 : modules anyway. */
2314 253852 : gcc_checking_assert (clusters <= (unsigned short)(~0));
2315 253852 : size_t length = (offsetof (tree_binding_vec, vec)
2316 253852 : + clusters * sizeof (binding_cluster));
2317 253852 : tree vec = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2318 253852 : TREE_SET_CODE (vec, BINDING_VECTOR);
2319 253852 : BINDING_VECTOR_NAME (vec) = name;
2320 253852 : BINDING_VECTOR_ALLOC_CLUSTERS (vec) = clusters;
2321 253852 : BINDING_VECTOR_NUM_CLUSTERS (vec) = 0;
2322 :
2323 253852 : return vec;
2324 : }
2325 :
2326 : /* Make a raw overload node containing FN. */
2327 :
2328 : tree
2329 204483431 : ovl_make (tree fn, tree next)
2330 : {
2331 204483431 : tree result = make_node (OVERLOAD);
2332 :
2333 204483431 : if (TREE_CODE (fn) == OVERLOAD)
2334 4615482 : OVL_NESTED_P (result) = true;
2335 :
2336 289831028 : TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL
2337 289831028 : ? unknown_type_node : TREE_TYPE (fn));
2338 204483431 : if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
2339 8787006 : OVL_DEDUP_P (result) = true;
2340 204483431 : OVL_FUNCTION (result) = fn;
2341 204483431 : OVL_CHAIN (result) = next;
2342 204483431 : return result;
2343 : }
2344 :
2345 : /* Add FN to the (potentially NULL) overload set OVL. USING_OR_HIDDEN is >
2346 : zero if this is a using-decl. It is > 1 if we're exporting the
2347 : using decl. USING_OR_HIDDEN is < 0, if FN is hidden. (A decl
2348 : cannot be both using and hidden.) We keep the hidden decls first,
2349 : but remaining ones are unordered. */
2350 :
2351 : tree
2352 462559961 : ovl_insert (tree fn, tree maybe_ovl, int using_or_hidden)
2353 : {
2354 462559961 : tree result = maybe_ovl;
2355 462559961 : tree insert_after = NULL_TREE;
2356 :
2357 : /* Skip hidden. */
2358 603692073 : for (; maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD
2359 608904972 : && OVL_HIDDEN_P (maybe_ovl);
2360 35896842 : maybe_ovl = OVL_CHAIN (maybe_ovl))
2361 : {
2362 35896842 : gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl));
2363 35896842 : insert_after = maybe_ovl;
2364 : }
2365 :
2366 462559961 : if (maybe_ovl || using_or_hidden || TREE_CODE (fn) == TEMPLATE_DECL)
2367 : {
2368 189586817 : maybe_ovl = ovl_make (fn, maybe_ovl);
2369 :
2370 189586817 : if (using_or_hidden < 0)
2371 65921987 : OVL_HIDDEN_P (maybe_ovl) = true;
2372 189586817 : if (using_or_hidden > 0)
2373 : {
2374 7049117 : OVL_DEDUP_P (maybe_ovl) = OVL_USING_P (maybe_ovl) = true;
2375 7049117 : if (using_or_hidden > 1)
2376 12531 : OVL_EXPORT_P (maybe_ovl) = true;
2377 : }
2378 : }
2379 : else
2380 : maybe_ovl = fn;
2381 :
2382 462559961 : if (insert_after)
2383 : {
2384 5472836 : OVL_CHAIN (insert_after) = maybe_ovl;
2385 5472836 : TREE_TYPE (insert_after) = unknown_type_node;
2386 : }
2387 : else
2388 : result = maybe_ovl;
2389 :
2390 462559961 : return result;
2391 : }
2392 :
2393 : /* Skip any hidden names at the beginning of OVL. */
2394 :
2395 : tree
2396 974081560 : ovl_skip_hidden (tree ovl)
2397 : {
2398 1329256395 : while (ovl && TREE_CODE (ovl) == OVERLOAD && OVL_HIDDEN_P (ovl))
2399 355174835 : ovl = OVL_CHAIN (ovl);
2400 :
2401 974081560 : return ovl;
2402 : }
2403 :
2404 : /* NODE is an OVL_HIDDEN_P node that is now revealed. */
2405 :
2406 : tree
2407 2765865 : ovl_iterator::reveal_node (tree overload, tree node)
2408 : {
2409 : /* We cannot have returned NODE as part of a lookup overload, so we
2410 : don't have to worry about preserving that. */
2411 :
2412 2765865 : OVL_HIDDEN_P (node) = false;
2413 2765865 : if (tree chain = OVL_CHAIN (node))
2414 126094 : if (TREE_CODE (chain) == OVERLOAD)
2415 : {
2416 119202 : if (OVL_HIDDEN_P (chain))
2417 : {
2418 : /* The node needs moving, and the simplest way is to remove it
2419 : and reinsert. */
2420 54920 : overload = remove_node (overload, node);
2421 54920 : overload = ovl_insert (OVL_FUNCTION (node), overload);
2422 : }
2423 64282 : else if (OVL_DEDUP_P (chain))
2424 12 : OVL_DEDUP_P (node) = true;
2425 : }
2426 2765865 : return overload;
2427 : }
2428 :
2429 : /* NODE is on the overloads of OVL. Remove it.
2430 : The removed node is unaltered and may continue to be iterated
2431 : from (i.e. it is safe to remove a node from an overload one is
2432 : currently iterating over). */
2433 :
2434 : tree
2435 58547 : ovl_iterator::remove_node (tree overload, tree node)
2436 : {
2437 58547 : tree *slot = &overload;
2438 591749 : while (*slot != node)
2439 : {
2440 533202 : tree probe = *slot;
2441 533202 : gcc_checking_assert (!OVL_LOOKUP_P (probe));
2442 :
2443 533202 : slot = &OVL_CHAIN (probe);
2444 : }
2445 :
2446 : /* Stitch out NODE. We don't have to worry about now making a
2447 : singleton overload (and consequently maybe setting its type),
2448 : because all uses of this function will be followed by inserting a
2449 : new node that must follow the place we've cut this out from. */
2450 58547 : if (TREE_CODE (node) != OVERLOAD)
2451 : /* Cloned inherited ctors don't mark themselves as via_using. */
2452 1513 : *slot = NULL_TREE;
2453 : else
2454 57034 : *slot = OVL_CHAIN (node);
2455 :
2456 58547 : return overload;
2457 : }
2458 :
2459 : /* Mark or unmark a lookup set. */
2460 :
2461 : void
2462 58789278 : lookup_mark (tree ovl, bool val)
2463 : {
2464 599466285 : for (lkp_iterator iter (ovl); iter; ++iter)
2465 : {
2466 481887729 : gcc_checking_assert (LOOKUP_SEEN_P (*iter) != val);
2467 481887729 : LOOKUP_SEEN_P (*iter) = val;
2468 : }
2469 58789278 : }
2470 :
2471 : /* Add a set of new FNS into a lookup. */
2472 :
2473 : tree
2474 303685466 : lookup_add (tree fns, tree lookup)
2475 : {
2476 303685466 : if (fns == error_mark_node || lookup == error_mark_node)
2477 : return error_mark_node;
2478 :
2479 303685462 : if (lookup || TREE_CODE (fns) == TEMPLATE_DECL)
2480 : {
2481 12561820 : lookup = ovl_make (fns, lookup);
2482 12561820 : OVL_LOOKUP_P (lookup) = true;
2483 : }
2484 : else
2485 : lookup = fns;
2486 :
2487 : return lookup;
2488 : }
2489 :
2490 : /* FNS is a new overload set, add them to LOOKUP, if they are not
2491 : already present there. */
2492 :
2493 : tree
2494 301435782 : lookup_maybe_add (tree fns, tree lookup, bool deduping)
2495 : {
2496 301435782 : if (deduping)
2497 324267577 : for (tree next, probe = fns; probe; probe = next)
2498 : {
2499 292640161 : tree fn = probe;
2500 292640161 : next = NULL_TREE;
2501 :
2502 292640161 : if (TREE_CODE (probe) == OVERLOAD)
2503 : {
2504 287430105 : fn = OVL_FUNCTION (probe);
2505 287430105 : next = OVL_CHAIN (probe);
2506 : }
2507 :
2508 292640161 : if (!LOOKUP_SEEN_P (fn))
2509 211742815 : LOOKUP_SEEN_P (fn) = true;
2510 : else
2511 : {
2512 : /* This function was already seen. Insert all the
2513 : predecessors onto the lookup. */
2514 85916544 : for (; fns != probe; fns = OVL_CHAIN (fns))
2515 : {
2516 5019198 : lookup = lookup_add (OVL_FUNCTION (fns), lookup);
2517 : /* Propagate OVL_USING, but OVL_HIDDEN &
2518 : OVL_DEDUP_P don't matter. */
2519 5019198 : if (OVL_USING_P (fns))
2520 7457 : OVL_USING_P (lookup) = true;
2521 : }
2522 :
2523 : /* And now skip this function. */
2524 : fns = next;
2525 : }
2526 : }
2527 :
2528 301435782 : if (fns)
2529 : /* We ended in a set of new functions. Add them all in one go. */
2530 295434055 : lookup = lookup_add (fns, lookup);
2531 :
2532 301435782 : return lookup;
2533 : }
2534 :
2535 : /* Returns nonzero if X is an expression for a (possibly overloaded)
2536 : function. If "f" is a function or function template, "f", "c->f",
2537 : "c.f", "C::f", and "f<int>" will all be considered possibly
2538 : overloaded functions. Returns 2 if the function is actually
2539 : overloaded, i.e., if it is impossible to know the type of the
2540 : function without performing overload resolution. */
2541 :
2542 : int
2543 3414909677 : is_overloaded_fn (tree x)
2544 : {
2545 3414909677 : STRIP_ANY_LOCATION_WRAPPER (x);
2546 :
2547 : /* A baselink is also considered an overloaded function. */
2548 3414909677 : if (TREE_CODE (x) == OFFSET_REF
2549 3414859607 : || TREE_CODE (x) == COMPONENT_REF)
2550 85977791 : x = TREE_OPERAND (x, 1);
2551 3414909677 : x = MAYBE_BASELINK_FUNCTIONS (x);
2552 3414909677 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2553 82169403 : x = TREE_OPERAND (x, 0);
2554 :
2555 3909945615 : if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x))
2556 3422432596 : || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x)))
2557 : return 2;
2558 :
2559 3076477219 : return OVL_P (x);
2560 : }
2561 :
2562 : /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
2563 : (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
2564 : NULL_TREE. */
2565 :
2566 : tree
2567 309304793 : dependent_name (tree x)
2568 : {
2569 : /* FIXME a dependent name must be unqualified, but this function doesn't
2570 : distinguish between qualified and unqualified identifiers. */
2571 309304793 : if (identifier_p (x))
2572 : return x;
2573 308930317 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2574 99377181 : x = TREE_OPERAND (x, 0);
2575 308930317 : if (OVL_P (x))
2576 111563797 : return OVL_NAME (x);
2577 : return NULL_TREE;
2578 : }
2579 :
2580 : /* Like dependent_name, but instead takes a CALL_EXPR and also checks
2581 : its dependence. */
2582 :
2583 : tree
2584 310906371 : call_expr_dependent_name (tree x)
2585 : {
2586 310906371 : if (TREE_TYPE (x) != NULL_TREE)
2587 : /* X isn't dependent, so its callee isn't a dependent name. */
2588 : return NULL_TREE;
2589 309222314 : return dependent_name (CALL_EXPR_FN (x));
2590 : }
2591 :
2592 : /* Returns true iff X is an expression for an overloaded function
2593 : whose type cannot be known without performing overload
2594 : resolution. */
2595 :
2596 : bool
2597 306002142 : really_overloaded_fn (tree x)
2598 : {
2599 306002142 : return is_overloaded_fn (x) == 2;
2600 : }
2601 :
2602 : /* Get the overload set FROM refers to. Returns NULL if it's not an
2603 : overload set. */
2604 :
2605 : tree
2606 2449418933 : maybe_get_fns (tree from)
2607 : {
2608 2449418933 : STRIP_ANY_LOCATION_WRAPPER (from);
2609 :
2610 : /* A baselink is also considered an overloaded function. */
2611 2449418933 : if (TREE_CODE (from) == OFFSET_REF
2612 2449373138 : || TREE_CODE (from) == COMPONENT_REF)
2613 6921407 : from = TREE_OPERAND (from, 1);
2614 2449418933 : if (BASELINK_P (from))
2615 148846611 : from = BASELINK_FUNCTIONS (from);
2616 2449418933 : if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
2617 151743541 : from = TREE_OPERAND (from, 0);
2618 :
2619 2449418933 : if (OVL_P (from))
2620 591634866 : return from;
2621 :
2622 : return NULL;
2623 : }
2624 :
2625 : /* FROM refers to an overload set. Return that set (or die). */
2626 :
2627 : tree
2628 459055597 : get_fns (tree from)
2629 : {
2630 459055597 : tree res = maybe_get_fns (from);
2631 :
2632 459055597 : gcc_assert (res);
2633 459055597 : return res;
2634 : }
2635 :
2636 : /* Return the first function of the overload set FROM refers to. */
2637 :
2638 : tree
2639 279187962 : get_first_fn (tree from)
2640 : {
2641 279187962 : return OVL_FIRST (get_fns (from));
2642 : }
2643 :
2644 : /* Return the scope where the overloaded functions OVL were found. */
2645 :
2646 : tree
2647 88522023 : ovl_scope (tree ovl)
2648 : {
2649 88522023 : if (TREE_CODE (ovl) == OFFSET_REF
2650 88522023 : || TREE_CODE (ovl) == COMPONENT_REF)
2651 0 : ovl = TREE_OPERAND (ovl, 1);
2652 88522023 : if (TREE_CODE (ovl) == BASELINK)
2653 26951393 : return BINFO_TYPE (BASELINK_BINFO (ovl));
2654 61570630 : if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
2655 14257130 : ovl = TREE_OPERAND (ovl, 0);
2656 : /* Skip using-declarations. */
2657 61570630 : lkp_iterator iter (ovl);
2658 64040273 : do
2659 64040273 : ovl = *iter;
2660 125610903 : while (iter.using_p () && ++iter);
2661 :
2662 61570630 : return CP_DECL_CONTEXT (ovl);
2663 : }
2664 :
2665 : #define PRINT_RING_SIZE 4
2666 :
2667 : static const char *
2668 85376 : cxx_printable_name_internal (tree decl, int v, bool translate)
2669 : {
2670 85376 : static unsigned int uid_ring[PRINT_RING_SIZE];
2671 85376 : static char *print_ring[PRINT_RING_SIZE];
2672 85376 : static bool trans_ring[PRINT_RING_SIZE];
2673 85376 : static int ring_counter;
2674 85376 : int i;
2675 :
2676 : /* Only cache functions. */
2677 85376 : if (v < 2
2678 37542 : || TREE_CODE (decl) != FUNCTION_DECL
2679 121018 : || DECL_LANG_SPECIFIC (decl) == 0)
2680 51012 : return lang_decl_name (decl, v, translate);
2681 :
2682 : /* See if this print name is lying around. */
2683 146456 : for (i = 0; i < PRINT_RING_SIZE; i++)
2684 122586 : if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
2685 : /* yes, so return it. */
2686 10494 : return print_ring[i];
2687 :
2688 23870 : if (++ring_counter == PRINT_RING_SIZE)
2689 4005 : ring_counter = 0;
2690 :
2691 23870 : if (current_function_decl != NULL_TREE)
2692 : {
2693 : /* There may be both translated and untranslated versions of the
2694 : name cached. */
2695 48528 : for (i = 0; i < 2; i++)
2696 : {
2697 32352 : if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
2698 73 : ring_counter += 1;
2699 32352 : if (ring_counter == PRINT_RING_SIZE)
2700 25 : ring_counter = 0;
2701 : }
2702 16176 : gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
2703 : }
2704 :
2705 23870 : free (print_ring[ring_counter]);
2706 :
2707 23870 : print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate));
2708 23870 : uid_ring[ring_counter] = DECL_UID (decl);
2709 23870 : trans_ring[ring_counter] = translate;
2710 23870 : return print_ring[ring_counter];
2711 : }
2712 :
2713 : const char *
2714 85376 : cxx_printable_name (tree decl, int v)
2715 : {
2716 85376 : return cxx_printable_name_internal (decl, v, false);
2717 : }
2718 :
2719 : const char *
2720 0 : cxx_printable_name_translate (tree decl, int v)
2721 : {
2722 0 : return cxx_printable_name_internal (decl, v, true);
2723 : }
2724 :
2725 : /* Return the canonical version of exception-specification RAISES for a C++17
2726 : function type, for use in type comparison and building TYPE_CANONICAL. */
2727 :
2728 : tree
2729 116939245 : canonical_eh_spec (tree raises)
2730 : {
2731 116939245 : if (raises == NULL_TREE)
2732 : return raises;
2733 107175368 : else if (DEFERRED_NOEXCEPT_SPEC_P (raises)
2734 87340819 : || UNPARSED_NOEXCEPT_SPEC_P (raises)
2735 83545785 : || uses_template_parms (raises)
2736 83545785 : || uses_template_parms (TREE_PURPOSE (raises)))
2737 : /* Keep a dependent or deferred exception specification. */
2738 26802121 : return raises;
2739 80373247 : else if (nothrow_spec_p (raises))
2740 : /* throw() -> noexcept. */
2741 80083263 : return noexcept_true_spec;
2742 : else
2743 : /* For C++17 type matching, anything else -> nothing. */
2744 : return NULL_TREE;
2745 : }
2746 :
2747 : tree
2748 429652063 : build_cp_fntype_variant (tree type, cp_ref_qualifier rqual,
2749 : tree raises, bool late)
2750 : {
2751 429652063 : cp_cv_quals type_quals = TYPE_QUALS (type);
2752 :
2753 429652063 : if (cp_check_qualified_type (type, type, type_quals, rqual, raises, late))
2754 : return type;
2755 :
2756 183821150 : tree v = TYPE_MAIN_VARIANT (type);
2757 394135858 : for (; v; v = TYPE_NEXT_VARIANT (v))
2758 290131426 : if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late))
2759 79816718 : return v;
2760 :
2761 : /* Need to build a new variant. */
2762 104004432 : v = build_variant_type_copy (type);
2763 104004432 : if (!TYPE_DEPENDENT_P (v))
2764 : /* We no longer know that it's not type-dependent. */
2765 103524212 : TYPE_DEPENDENT_P_VALID (v) = false;
2766 104004432 : TYPE_RAISES_EXCEPTIONS (v) = raises;
2767 104004432 : TYPE_HAS_LATE_RETURN_TYPE (v) = late;
2768 104004432 : switch (rqual)
2769 : {
2770 324181 : case REF_QUAL_RVALUE:
2771 324181 : FUNCTION_RVALUE_QUALIFIED (v) = 1;
2772 324181 : FUNCTION_REF_QUALIFIED (v) = 1;
2773 324181 : break;
2774 338169 : case REF_QUAL_LVALUE:
2775 338169 : FUNCTION_RVALUE_QUALIFIED (v) = 0;
2776 338169 : FUNCTION_REF_QUALIFIED (v) = 1;
2777 338169 : break;
2778 103342082 : default:
2779 103342082 : FUNCTION_REF_QUALIFIED (v) = 0;
2780 103342082 : break;
2781 : }
2782 :
2783 : /* Canonicalize the exception specification. */
2784 104004432 : tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE;
2785 :
2786 104004432 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
2787 : /* Propagate structural equality. */
2788 8602596 : SET_TYPE_STRUCTURAL_EQUALITY (v);
2789 95401836 : else if (TYPE_CANONICAL (type) != type || cr != raises || late)
2790 : /* Build the underlying canonical type, since it is different
2791 : from TYPE. */
2792 33341404 : TYPE_CANONICAL (v) = build_cp_fntype_variant (TYPE_CANONICAL (type),
2793 : rqual, cr, false);
2794 : else
2795 : /* T is its own canonical type. */
2796 62060432 : TYPE_CANONICAL (v) = v;
2797 :
2798 : return v;
2799 : }
2800 :
2801 : /* TYPE is a function or method type with a deferred exception
2802 : specification that has been parsed to RAISES. Fixup all the type
2803 : variants that are affected in place. Via decltype &| noexcept
2804 : tricks, the unparsed spec could have escaped into the type system.
2805 : The general case is hard to fixup canonical types for. */
2806 :
2807 : void
2808 1636832 : fixup_deferred_exception_variants (tree type, tree raises)
2809 : {
2810 1636832 : tree original = TYPE_RAISES_EXCEPTIONS (type);
2811 1636832 : tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE;
2812 :
2813 3273664 : gcc_checking_assert (UNPARSED_NOEXCEPT_SPEC_P (original));
2814 :
2815 : /* Though sucky, this walk will process the canonical variants
2816 : first. */
2817 1636832 : tree prev = NULL_TREE;
2818 1636832 : for (tree variant = TYPE_MAIN_VARIANT (type);
2819 5350913 : variant; prev = variant, variant = TYPE_NEXT_VARIANT (variant))
2820 3714081 : if (TYPE_RAISES_EXCEPTIONS (variant) == original)
2821 : {
2822 1851975 : gcc_checking_assert (variant != TYPE_MAIN_VARIANT (type));
2823 :
2824 1851975 : if (!TYPE_STRUCTURAL_EQUALITY_P (variant))
2825 : {
2826 911687 : cp_cv_quals var_quals = TYPE_QUALS (variant);
2827 911687 : cp_ref_qualifier rqual = type_memfn_rqual (variant);
2828 :
2829 : /* If VARIANT would become a dup (cp_check_qualified_type-wise)
2830 : of an existing variant in the variant list of TYPE after its
2831 : exception specification has been parsed, elide it. Otherwise,
2832 : build_cp_fntype_variant could use it, leading to "canonical
2833 : types differ for identical types." */
2834 911687 : tree v = TYPE_MAIN_VARIANT (type);
2835 2837747 : for (; v; v = TYPE_NEXT_VARIANT (v))
2836 2036399 : if (cp_check_qualified_type (v, variant, var_quals,
2837 : rqual, cr, false))
2838 : {
2839 : /* The main variant will not match V, so PREV will never
2840 : be null. */
2841 110339 : TYPE_NEXT_VARIANT (prev) = TYPE_NEXT_VARIANT (variant);
2842 110339 : break;
2843 : }
2844 911687 : TYPE_RAISES_EXCEPTIONS (variant) = raises;
2845 :
2846 911687 : if (!v)
2847 801348 : v = build_cp_fntype_variant (TYPE_CANONICAL (variant),
2848 : rqual, cr, false);
2849 911687 : TYPE_CANONICAL (variant) = TYPE_CANONICAL (v);
2850 : }
2851 : else
2852 940288 : TYPE_RAISES_EXCEPTIONS (variant) = raises;
2853 :
2854 1851975 : if (!TYPE_DEPENDENT_P (variant))
2855 : /* We no longer know that it's not type-dependent. */
2856 215328 : TYPE_DEPENDENT_P_VALID (variant) = false;
2857 : }
2858 1636832 : }
2859 :
2860 : /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
2861 : listed in RAISES. */
2862 :
2863 : tree
2864 97015105 : build_exception_variant (tree type, tree raises)
2865 : {
2866 97015105 : cp_ref_qualifier rqual = type_memfn_rqual (type);
2867 97015105 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
2868 97015105 : return build_cp_fntype_variant (type, rqual, raises, late);
2869 : }
2870 :
2871 : /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
2872 : BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
2873 : arguments. */
2874 :
2875 : tree
2876 164144 : bind_template_template_parm (tree t, tree newargs)
2877 : {
2878 164144 : tree decl = TYPE_NAME (t);
2879 164144 : tree t2;
2880 :
2881 164144 : t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
2882 164144 : decl = build_decl (input_location,
2883 164144 : TYPE_DECL, DECL_NAME (decl), NULL_TREE);
2884 164144 : SET_DECL_TEMPLATE_PARM_P (decl);
2885 :
2886 : /* These nodes have to be created to reflect new TYPE_DECL and template
2887 : arguments. */
2888 164144 : TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
2889 164144 : TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
2890 164144 : TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
2891 328288 : = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
2892 :
2893 164144 : TREE_TYPE (decl) = t2;
2894 164144 : TYPE_NAME (t2) = decl;
2895 164144 : TYPE_STUB_DECL (t2) = decl;
2896 164144 : TYPE_SIZE (t2) = 0;
2897 :
2898 164144 : if (any_template_arguments_need_structural_equality_p (newargs))
2899 10 : SET_TYPE_STRUCTURAL_EQUALITY (t2);
2900 : else
2901 164134 : TYPE_CANONICAL (t2) = canonical_type_parameter (t2);
2902 :
2903 164144 : return t2;
2904 : }
2905 :
2906 : /* Called from count_trees via walk_tree. */
2907 :
2908 : static tree
2909 0 : count_trees_r (tree *tp, int *walk_subtrees, void *data)
2910 : {
2911 0 : ++*((int *) data);
2912 :
2913 0 : if (TYPE_P (*tp))
2914 0 : *walk_subtrees = 0;
2915 :
2916 0 : return NULL_TREE;
2917 : }
2918 :
2919 : /* Debugging function for measuring the rough complexity of a tree
2920 : representation. */
2921 :
2922 : int
2923 0 : count_trees (tree t)
2924 : {
2925 0 : int n_trees = 0;
2926 0 : cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
2927 0 : return n_trees;
2928 : }
2929 :
2930 : /* Called from verify_stmt_tree via walk_tree. */
2931 :
2932 : static tree
2933 1175789 : verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data)
2934 : {
2935 1175789 : tree t = *tp;
2936 1175789 : hash_table<nofree_ptr_hash <tree_node> > *statements
2937 : = static_cast <hash_table<nofree_ptr_hash <tree_node> > *> (data);
2938 1175789 : tree_node **slot;
2939 :
2940 1175789 : if (!STATEMENT_CODE_P (TREE_CODE (t)))
2941 : return NULL_TREE;
2942 :
2943 : /* If this statement is already present in the hash table, then
2944 : there is a circularity in the statement tree. */
2945 75553 : gcc_assert (!statements->find (t));
2946 :
2947 75553 : slot = statements->find_slot (t, INSERT);
2948 75553 : *slot = t;
2949 :
2950 75553 : return NULL_TREE;
2951 : }
2952 :
2953 : /* Debugging function to check that the statement T has not been
2954 : corrupted. For now, this function simply checks that T contains no
2955 : circularities. */
2956 :
2957 : void
2958 2376 : verify_stmt_tree (tree t)
2959 : {
2960 2376 : hash_table<nofree_ptr_hash <tree_node> > statements (37);
2961 2376 : cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
2962 2376 : }
2963 :
2964 : /* Check if the type T depends on a type with no linkage and if so,
2965 : return it. If RELAXED_P then do not consider a class type declared
2966 : within a vague-linkage function to have no linkage. Remember:
2967 : no-linkage is not the same as internal-linkage. */
2968 :
2969 : tree
2970 193555850 : no_linkage_check (tree t, bool relaxed_p)
2971 : {
2972 193555850 : tree r;
2973 :
2974 : /* Lambda types that don't have mangling scope have no linkage. We
2975 : check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
2976 : when we get here from pushtag none of the lambda information is
2977 : set up yet, so we want to assume that the lambda has linkage and
2978 : fix it up later if not. We need to check this even in templates so
2979 : that we properly handle a lambda-expression in the signature. */
2980 220425943 : if (LAMBDA_TYPE_P (t)
2981 194093978 : && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node)
2982 : {
2983 290782 : tree extra = LAMBDA_TYPE_EXTRA_SCOPE (t);
2984 290782 : if (!extra)
2985 : return t;
2986 : }
2987 :
2988 : /* Otherwise there's no point in checking linkage on template functions; we
2989 : can't know their complete types. */
2990 193555444 : if (processing_template_decl)
2991 : return NULL_TREE;
2992 :
2993 108963045 : switch (TREE_CODE (t))
2994 : {
2995 57577913 : case RECORD_TYPE:
2996 57577913 : if (TYPE_PTRMEMFUNC_P (t))
2997 92161 : goto ptrmem;
2998 : /* Fall through. */
2999 58406699 : case UNION_TYPE:
3000 58406699 : if (!CLASS_TYPE_P (t))
3001 : return NULL_TREE;
3002 : /* Fall through. */
3003 60765628 : case ENUMERAL_TYPE:
3004 : /* Only treat unnamed types as having no linkage if they're at
3005 : namespace scope. This is core issue 966. */
3006 123518977 : if (TYPE_UNNAMED_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
3007 : return t;
3008 :
3009 60221442 : for (r = CP_TYPE_CONTEXT (t); ; )
3010 : {
3011 : /* If we're a nested type of a !TREE_PUBLIC class, we might not
3012 : have linkage, or we might just be in an anonymous namespace.
3013 : If we're in a TREE_PUBLIC class, we have linkage. */
3014 61267239 : if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
3015 60159 : return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
3016 61207080 : else if (TREE_CODE (r) == FUNCTION_DECL)
3017 : {
3018 1102943 : if (!relaxed_p || !vague_linkage_p (r))
3019 57146 : return t;
3020 : else
3021 1045797 : r = CP_DECL_CONTEXT (r);
3022 : }
3023 : else
3024 : break;
3025 : }
3026 :
3027 : return NULL_TREE;
3028 :
3029 14114868 : case ARRAY_TYPE:
3030 14114868 : case POINTER_TYPE:
3031 14114868 : case REFERENCE_TYPE:
3032 14114868 : case VECTOR_TYPE:
3033 14114868 : return no_linkage_check (TREE_TYPE (t), relaxed_p);
3034 :
3035 94412 : case OFFSET_TYPE:
3036 94412 : ptrmem:
3037 94412 : r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
3038 : relaxed_p);
3039 94412 : if (r)
3040 : return r;
3041 94412 : return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
3042 :
3043 12026094 : case METHOD_TYPE:
3044 12026094 : case FUNCTION_TYPE:
3045 12026094 : {
3046 12026094 : tree parm = TYPE_ARG_TYPES (t);
3047 12026094 : if (TREE_CODE (t) == METHOD_TYPE)
3048 : /* The 'this' pointer isn't interesting; a method has the same
3049 : linkage (or lack thereof) as its enclosing class. */
3050 6071568 : parm = TREE_CHAIN (parm);
3051 15850927 : for (;
3052 27877021 : parm && parm != void_list_node;
3053 15850927 : parm = TREE_CHAIN (parm))
3054 : {
3055 15898278 : r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
3056 15898278 : if (r)
3057 47351 : return r;
3058 : }
3059 11978743 : return no_linkage_check (TREE_TYPE (t), relaxed_p);
3060 : }
3061 :
3062 : default:
3063 : return NULL_TREE;
3064 : }
3065 : }
3066 :
3067 : extern int depth_reached;
3068 :
3069 : void
3070 0 : cxx_print_statistics (void)
3071 : {
3072 0 : print_template_statistics ();
3073 0 : if (GATHER_STATISTICS)
3074 : fprintf (stderr, "maximum template instantiation depth reached: %d\n",
3075 : depth_reached);
3076 0 : }
3077 :
3078 : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3079 : (which is an ARRAY_TYPE). This counts only elements of the top
3080 : array. */
3081 :
3082 : tree
3083 1715169 : array_type_nelts_top (tree type)
3084 : {
3085 1715169 : return fold_build2_loc (input_location,
3086 : PLUS_EXPR, sizetype,
3087 : array_type_nelts (type),
3088 1715169 : size_one_node);
3089 : }
3090 :
3091 : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3092 : (which is an ARRAY_TYPE). This one is a recursive count of all
3093 : ARRAY_TYPEs that are clumped together. */
3094 :
3095 : tree
3096 2937 : array_type_nelts_total (tree type)
3097 : {
3098 2937 : tree sz = array_type_nelts_top (type);
3099 2937 : type = TREE_TYPE (type);
3100 3230 : while (TREE_CODE (type) == ARRAY_TYPE)
3101 : {
3102 293 : tree n = array_type_nelts_top (type);
3103 293 : sz = fold_build2_loc (input_location,
3104 : MULT_EXPR, sizetype, sz, n);
3105 293 : type = TREE_TYPE (type);
3106 : }
3107 2937 : return sz;
3108 : }
3109 :
3110 : struct bot_data
3111 : {
3112 : splay_tree target_remap;
3113 : bool clear_location;
3114 : };
3115 :
3116 : /* Called from break_out_target_exprs via mapcar. */
3117 :
3118 : static tree
3119 11610898 : bot_manip (tree* tp, int* walk_subtrees, void* data_)
3120 : {
3121 11610898 : bot_data &data = *(bot_data*)data_;
3122 11610898 : splay_tree target_remap = data.target_remap;
3123 11610898 : tree t = *tp;
3124 :
3125 11610898 : if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t))
3126 : {
3127 : /* There can't be any TARGET_EXPRs or their slot variables below this
3128 : point. But we must make a copy, in case subsequent processing
3129 : alters any part of it. For example, during gimplification a cast
3130 : of the form (T) &X::f (where "f" is a member function) will lead
3131 : to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */
3132 5246600 : *walk_subtrees = 0;
3133 5246600 : *tp = unshare_expr (t);
3134 5246600 : return NULL_TREE;
3135 : }
3136 6364298 : if (TREE_CODE (t) == TARGET_EXPR)
3137 : {
3138 271751 : tree u;
3139 :
3140 271751 : if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR)
3141 : {
3142 254930 : u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1),
3143 : tf_warning_or_error);
3144 254930 : if (u == error_mark_node)
3145 : return u;
3146 254930 : if (AGGR_INIT_ZERO_FIRST (TREE_OPERAND (t, 1)))
3147 441 : AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u, 1)) = true;
3148 : }
3149 : else
3150 16821 : u = force_target_expr (TREE_TYPE (t), TREE_OPERAND (t, 1),
3151 : tf_warning_or_error);
3152 :
3153 271751 : TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
3154 271751 : TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
3155 271751 : TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
3156 271751 : TARGET_EXPR_ELIDING_P (u) = TARGET_EXPR_ELIDING_P (t);
3157 :
3158 : /* Map the old variable to the new one. */
3159 815253 : splay_tree_insert (target_remap,
3160 271751 : (splay_tree_key) TREE_OPERAND (t, 0),
3161 271751 : (splay_tree_value) TREE_OPERAND (u, 0));
3162 :
3163 271751 : TREE_OPERAND (u, 1) = break_out_target_exprs (TREE_OPERAND (u, 1),
3164 271751 : data.clear_location);
3165 271751 : if (TREE_OPERAND (u, 1) == error_mark_node)
3166 : return error_mark_node;
3167 :
3168 : /* Replace the old expression with the new version. */
3169 271751 : *tp = u;
3170 : /* We don't have to go below this point; the recursive call to
3171 : break_out_target_exprs will have handled anything below this
3172 : point. */
3173 271751 : *walk_subtrees = 0;
3174 271751 : return NULL_TREE;
3175 : }
3176 6092547 : if (TREE_CODE (*tp) == SAVE_EXPR)
3177 : {
3178 82264 : t = *tp;
3179 82264 : splay_tree_node n = splay_tree_lookup (target_remap,
3180 : (splay_tree_key) t);
3181 82264 : if (n)
3182 : {
3183 41136 : *tp = (tree)n->value;
3184 41136 : *walk_subtrees = 0;
3185 : }
3186 : else
3187 : {
3188 41128 : copy_tree_r (tp, walk_subtrees, NULL);
3189 41128 : splay_tree_insert (target_remap,
3190 : (splay_tree_key)t,
3191 41128 : (splay_tree_value)*tp);
3192 : /* Make sure we don't remap an already-remapped SAVE_EXPR. */
3193 41128 : splay_tree_insert (target_remap,
3194 : (splay_tree_key)*tp,
3195 41128 : (splay_tree_value)*tp);
3196 : }
3197 82264 : return NULL_TREE;
3198 : }
3199 6010283 : if (TREE_CODE (*tp) == DECL_EXPR
3200 22 : && VAR_P (DECL_EXPR_DECL (*tp))
3201 22 : && DECL_ARTIFICIAL (DECL_EXPR_DECL (*tp))
3202 6010305 : && !TREE_STATIC (DECL_EXPR_DECL (*tp)))
3203 : {
3204 22 : tree t;
3205 22 : splay_tree_node n
3206 44 : = splay_tree_lookup (target_remap,
3207 22 : (splay_tree_key) DECL_EXPR_DECL (*tp));
3208 22 : if (n)
3209 0 : t = (tree) n->value;
3210 : else
3211 : {
3212 22 : t = create_temporary_var (TREE_TYPE (DECL_EXPR_DECL (*tp)));
3213 22 : DECL_INITIAL (t) = DECL_INITIAL (DECL_EXPR_DECL (*tp));
3214 44 : splay_tree_insert (target_remap,
3215 22 : (splay_tree_key) DECL_EXPR_DECL (*tp),
3216 : (splay_tree_value) t);
3217 : }
3218 22 : copy_tree_r (tp, walk_subtrees, NULL);
3219 22 : DECL_EXPR_DECL (*tp) = t;
3220 22 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3221 14 : SET_EXPR_LOCATION (*tp, input_location);
3222 22 : return NULL_TREE;
3223 : }
3224 6010261 : if (TREE_CODE (*tp) == BIND_EXPR && BIND_EXPR_VARS (*tp))
3225 : {
3226 0 : copy_tree_r (tp, walk_subtrees, NULL);
3227 0 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
3228 : {
3229 0 : gcc_assert (VAR_P (*p) && DECL_ARTIFICIAL (*p) && !TREE_STATIC (*p));
3230 0 : tree t = create_temporary_var (TREE_TYPE (*p));
3231 0 : DECL_INITIAL (t) = DECL_INITIAL (*p);
3232 0 : DECL_CHAIN (t) = DECL_CHAIN (*p);
3233 0 : splay_tree_insert (target_remap, (splay_tree_key) *p,
3234 : (splay_tree_value) t);
3235 0 : *p = t;
3236 : }
3237 0 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3238 0 : SET_EXPR_LOCATION (*tp, input_location);
3239 0 : return NULL_TREE;
3240 : }
3241 :
3242 : /* Make a copy of this node. */
3243 6010261 : t = copy_tree_r (tp, walk_subtrees, NULL);
3244 6010261 : if (TREE_CODE (*tp) == CALL_EXPR || TREE_CODE (*tp) == AGGR_INIT_EXPR)
3245 874311 : if (!processing_template_decl)
3246 874311 : set_flags_from_callee (*tp);
3247 6010261 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3248 23868 : SET_EXPR_LOCATION (*tp, input_location);
3249 : return t;
3250 : }
3251 :
3252 : /* Replace all remapped VAR_DECLs in T with their new equivalents.
3253 : DATA is really a splay-tree mapping old variables to new
3254 : variables. */
3255 :
3256 : static tree
3257 18573790 : bot_replace (tree* t, int* walk_subtrees, void* data_)
3258 : {
3259 18573790 : bot_data &data = *(bot_data*)data_;
3260 18573790 : splay_tree target_remap = data.target_remap;
3261 :
3262 18573790 : if (VAR_P (*t))
3263 : {
3264 1101266 : splay_tree_node n = splay_tree_lookup (target_remap,
3265 : (splay_tree_key) *t);
3266 1101266 : if (n)
3267 825 : *t = (tree) n->value;
3268 : }
3269 17472524 : else if (TREE_CODE (*t) == PARM_DECL
3270 1218729 : && DECL_NAME (*t) == this_identifier
3271 17854299 : && !DECL_CONTEXT (*t))
3272 : {
3273 : /* In an NSDMI we need to replace the 'this' parameter we used for
3274 : parsing with the real one for this function. */
3275 16897 : *t = current_class_ptr;
3276 : }
3277 17455627 : else if (TREE_CODE (*t) == CONVERT_EXPR
3278 17455627 : && CONVERT_EXPR_VBASE_PATH (*t))
3279 : {
3280 : /* In an NSDMI build_base_path defers building conversions to morally
3281 : virtual bases, and we handle it here. */
3282 63 : tree basetype = TREE_TYPE (*t);
3283 63 : *t = convert_to_base (TREE_OPERAND (*t, 0), basetype,
3284 : /*check_access=*/false, /*nonnull=*/true,
3285 : tf_warning_or_error);
3286 : }
3287 17455564 : else if (cxx_dialect >= cxx20
3288 1282338 : && (TREE_CODE (*t) == CALL_EXPR
3289 1201567 : || TREE_CODE (*t) == AGGR_INIT_EXPR)
3290 17563932 : && !in_immediate_context ())
3291 : {
3292 : /* Expand immediate invocations. */
3293 106865 : if (tree fndecl = cp_get_callee_fndecl_nofold (*t))
3294 213700 : if (DECL_IMMEDIATE_FUNCTION_P (fndecl))
3295 : {
3296 : /* Make in_immediate_context true within the args. */
3297 27 : in_consteval_if_p_temp_override ito;
3298 27 : in_consteval_if_p = true;
3299 27 : int nargs = call_expr_nargs (*t);
3300 53 : for (int i = 0; i < nargs; ++i)
3301 26 : cp_walk_tree (&get_nth_callarg (*t, i), bot_replace, data_, NULL);
3302 27 : *t = cxx_constant_value (*t);
3303 27 : if (*t == error_mark_node)
3304 0 : return error_mark_node;
3305 27 : *walk_subtrees = 0;
3306 27 : }
3307 : }
3308 :
3309 : return NULL_TREE;
3310 : }
3311 :
3312 : /* When we parse a default argument expression, we may create
3313 : temporary variables via TARGET_EXPRs. When we actually use the
3314 : default-argument expression, we make a copy of the expression
3315 : and replace the temporaries with appropriate local versions.
3316 :
3317 : If CLEAR_LOCATION is true, override any EXPR_LOCATION with
3318 : input_location. */
3319 :
3320 : tree
3321 5076251 : break_out_target_exprs (tree t, bool clear_location /* = false */)
3322 : {
3323 5076251 : static int target_remap_count;
3324 5076251 : static splay_tree target_remap;
3325 :
3326 : /* We shouldn't be called on templated trees, nor do we want to
3327 : produce them. */
3328 5076251 : gcc_checking_assert (!processing_template_decl);
3329 :
3330 5076251 : if (!target_remap_count++)
3331 4804500 : target_remap = splay_tree_new (splay_tree_compare_pointers,
3332 : /*splay_tree_delete_key_fn=*/NULL,
3333 : /*splay_tree_delete_value_fn=*/NULL);
3334 5076251 : bot_data data = { target_remap, clear_location };
3335 5076251 : if (cp_walk_tree (&t, bot_manip, &data, NULL) == error_mark_node)
3336 0 : t = error_mark_node;
3337 5076251 : if (cp_walk_tree (&t, bot_replace, &data, NULL) == error_mark_node)
3338 0 : t = error_mark_node;
3339 :
3340 5076251 : if (!--target_remap_count)
3341 : {
3342 4804500 : splay_tree_delete (target_remap);
3343 4804500 : target_remap = NULL;
3344 : }
3345 :
3346 5076251 : return t;
3347 : }
3348 :
3349 : /* Build an expression for the subobject of OBJ at CONSTRUCTOR index INDEX,
3350 : which we expect to have type TYPE. */
3351 :
3352 : tree
3353 236757 : build_ctor_subob_ref (tree index, tree type, tree obj)
3354 : {
3355 236757 : if (index == NULL_TREE)
3356 : /* Can't refer to a particular member of a vector. */
3357 : obj = NULL_TREE;
3358 236757 : else if (TREE_CODE (index) == INTEGER_CST)
3359 11055 : obj = cp_build_array_ref (input_location, obj, index, tf_none);
3360 : else
3361 225702 : obj = build_class_member_access_expr (obj, index, NULL_TREE,
3362 : /*reference*/false, tf_none);
3363 236757 : if (obj)
3364 : {
3365 236757 : tree objtype = TREE_TYPE (obj);
3366 236757 : if (TREE_CODE (objtype) == ARRAY_TYPE && !TYPE_DOMAIN (objtype))
3367 : {
3368 : /* When the destination object refers to a flexible array member
3369 : verify that it matches the type of the source object except
3370 : for its domain and qualifiers. */
3371 111 : gcc_assert (comptypes (TYPE_MAIN_VARIANT (type),
3372 : TYPE_MAIN_VARIANT (objtype),
3373 : COMPARE_REDECLARATION));
3374 : }
3375 : else
3376 236646 : gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, objtype));
3377 : }
3378 :
3379 236757 : return obj;
3380 : }
3381 :
3382 : struct replace_placeholders_t
3383 : {
3384 : tree obj; /* The object to be substituted for a PLACEHOLDER_EXPR. */
3385 : tree exp; /* The outermost exp. */
3386 : bool seen; /* Whether we've encountered a PLACEHOLDER_EXPR. */
3387 : hash_set<tree> *pset; /* To avoid walking same trees multiple times. */
3388 : };
3389 :
3390 : /* Like substitute_placeholder_in_expr, but handle C++ tree codes and
3391 : build up subexpressions as we go deeper. */
3392 :
3393 : static tree
3394 7548880 : replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
3395 : {
3396 7548880 : replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);
3397 7548880 : tree obj = d->obj;
3398 :
3399 7548880 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3400 : {
3401 2612923 : *walk_subtrees = false;
3402 2612923 : return NULL_TREE;
3403 : }
3404 :
3405 4935957 : switch (TREE_CODE (*t))
3406 : {
3407 : case PLACEHOLDER_EXPR:
3408 : {
3409 : tree x = obj;
3410 421 : for (; !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (*t),
3411 421 : TREE_TYPE (x));
3412 78 : x = TREE_OPERAND (x, 0))
3413 78 : gcc_assert (handled_component_p (x));
3414 343 : *t = unshare_expr (x);
3415 343 : *walk_subtrees = false;
3416 343 : d->seen = true;
3417 : }
3418 343 : break;
3419 :
3420 35713 : case CONSTRUCTOR:
3421 35713 : {
3422 35713 : constructor_elt *ce;
3423 35713 : vec<constructor_elt,va_gc> *v = CONSTRUCTOR_ELTS (*t);
3424 : /* Don't walk into CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctors
3425 : other than the d->exp one, those have PLACEHOLDER_EXPRs
3426 : related to another object. */
3427 35713 : if ((CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t)
3428 319 : && *t != d->exp)
3429 35972 : || d->pset->add (*t))
3430 : {
3431 60 : *walk_subtrees = false;
3432 60 : return NULL_TREE;
3433 : }
3434 120969 : for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i)
3435 : {
3436 85316 : tree *valp = &ce->value;
3437 85316 : tree type = TREE_TYPE (*valp);
3438 85316 : tree subob = obj;
3439 :
3440 : /* Elements with RANGE_EXPR index shouldn't have any
3441 : placeholders in them. */
3442 85316 : if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
3443 3 : continue;
3444 :
3445 85313 : if (TREE_CODE (*valp) == CONSTRUCTOR
3446 655 : && AGGREGATE_TYPE_P (type))
3447 : {
3448 : /* If we're looking at the initializer for OBJ, then build
3449 : a sub-object reference. If we're looking at an
3450 : initializer for another object, just pass OBJ down. */
3451 634 : if (same_type_ignoring_top_level_qualifiers_p
3452 634 : (TREE_TYPE (*t), TREE_TYPE (obj)))
3453 612 : subob = build_ctor_subob_ref (ce->index, type, obj);
3454 634 : if (TREE_CODE (*valp) == TARGET_EXPR)
3455 0 : valp = &TARGET_EXPR_INITIAL (*valp);
3456 : }
3457 85313 : d->obj = subob;
3458 85313 : cp_walk_tree (valp, replace_placeholders_r, data_, NULL);
3459 85313 : d->obj = obj;
3460 : }
3461 35653 : *walk_subtrees = false;
3462 35653 : break;
3463 : }
3464 :
3465 4899901 : default:
3466 4899901 : if (d->pset->add (*t))
3467 185686 : *walk_subtrees = false;
3468 : break;
3469 : }
3470 :
3471 : return NULL_TREE;
3472 : }
3473 :
3474 : /* Replace PLACEHOLDER_EXPRs in EXP with object OBJ. SEEN_P is set if
3475 : a PLACEHOLDER_EXPR has been encountered. */
3476 :
3477 : tree
3478 28087158 : replace_placeholders (tree exp, tree obj, bool *seen_p /*= NULL*/)
3479 : {
3480 : /* This is only relevant for C++14. */
3481 28087158 : if (cxx_dialect < cxx14)
3482 684819 : return exp;
3483 :
3484 : /* If the object isn't a (member of a) class, do nothing. */
3485 : tree op0 = obj;
3486 27675195 : while (handled_component_p (op0))
3487 272856 : op0 = TREE_OPERAND (op0, 0);
3488 27402339 : if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0))))
3489 25751321 : return exp;
3490 :
3491 1651018 : tree *tp = &exp;
3492 1651018 : if (TREE_CODE (exp) == TARGET_EXPR)
3493 52921 : tp = &TARGET_EXPR_INITIAL (exp);
3494 1651018 : hash_set<tree> pset;
3495 1651018 : replace_placeholders_t data = { obj, *tp, false, &pset };
3496 1651018 : cp_walk_tree (tp, replace_placeholders_r, &data, NULL);
3497 1651018 : if (seen_p)
3498 63336 : *seen_p = data.seen;
3499 1651018 : return exp;
3500 28087158 : }
3501 :
3502 : /* Callback function for find_placeholders. */
3503 :
3504 : static tree
3505 12474 : find_placeholders_r (tree *t, int *walk_subtrees, void *)
3506 : {
3507 12474 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3508 : {
3509 5471 : *walk_subtrees = false;
3510 5471 : return NULL_TREE;
3511 : }
3512 :
3513 7003 : switch (TREE_CODE (*t))
3514 : {
3515 : case PLACEHOLDER_EXPR:
3516 : return *t;
3517 :
3518 546 : case CONSTRUCTOR:
3519 546 : if (CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t))
3520 168 : *walk_subtrees = false;
3521 : break;
3522 :
3523 : default:
3524 : break;
3525 : }
3526 :
3527 : return NULL_TREE;
3528 : }
3529 :
3530 : /* Return true if EXP contains a PLACEHOLDER_EXPR. Don't walk into
3531 : ctors with CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag set. */
3532 :
3533 : bool
3534 5771 : find_placeholders (tree exp)
3535 : {
3536 : /* This is only relevant for C++14. */
3537 5771 : if (cxx_dialect < cxx14)
3538 : return false;
3539 :
3540 5771 : return cp_walk_tree_without_duplicates (&exp, find_placeholders_r, NULL);
3541 : }
3542 :
3543 : /* Similar to `build_nt', but for template definitions of dependent
3544 : expressions */
3545 :
3546 : tree
3547 211300015 : build_min_nt_loc (location_t loc, enum tree_code code, ...)
3548 : {
3549 211300015 : tree t;
3550 211300015 : int length;
3551 211300015 : int i;
3552 211300015 : va_list p;
3553 :
3554 211300015 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3555 :
3556 211300015 : va_start (p, code);
3557 :
3558 211300015 : t = make_node (code);
3559 211300015 : SET_EXPR_LOCATION (t, loc);
3560 211300015 : length = TREE_CODE_LENGTH (code);
3561 :
3562 667577956 : for (i = 0; i < length; i++)
3563 456277941 : TREE_OPERAND (t, i) = va_arg (p, tree);
3564 :
3565 211300015 : va_end (p);
3566 211300015 : return t;
3567 : }
3568 :
3569 : /* Similar to `build', but for template definitions. */
3570 :
3571 : tree
3572 99646089 : build_min (enum tree_code code, tree tt, ...)
3573 : {
3574 99646089 : tree t;
3575 99646089 : int length;
3576 99646089 : int i;
3577 99646089 : va_list p;
3578 :
3579 99646089 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3580 :
3581 99646089 : va_start (p, tt);
3582 :
3583 99646089 : t = make_node (code);
3584 99646089 : length = TREE_CODE_LENGTH (code);
3585 99646089 : TREE_TYPE (t) = tt;
3586 :
3587 282452848 : for (i = 0; i < length; i++)
3588 : {
3589 182806759 : tree x = va_arg (p, tree);
3590 182806759 : TREE_OPERAND (t, i) = x;
3591 182806759 : if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
3592 1161037 : TREE_SIDE_EFFECTS (t) = 1;
3593 : }
3594 :
3595 99646089 : va_end (p);
3596 :
3597 99646089 : return t;
3598 : }
3599 :
3600 : /* Similar to `build', but for template definitions of non-dependent
3601 : expressions. NON_DEP is the non-dependent expression that has been
3602 : built. */
3603 :
3604 : tree
3605 63981440 : build_min_non_dep (enum tree_code code, tree non_dep, ...)
3606 : {
3607 63981440 : tree t;
3608 63981440 : int length;
3609 63981440 : int i;
3610 63981440 : va_list p;
3611 :
3612 63981440 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3613 :
3614 63981440 : va_start (p, non_dep);
3615 :
3616 63981440 : if (REFERENCE_REF_P (non_dep))
3617 27665 : non_dep = TREE_OPERAND (non_dep, 0);
3618 :
3619 63981440 : t = make_node (code);
3620 86796621 : SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep));
3621 63981440 : length = TREE_CODE_LENGTH (code);
3622 63981440 : TREE_TYPE (t) = unlowered_expr_type (non_dep);
3623 63981440 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3624 :
3625 224575659 : for (i = 0; i < length; i++)
3626 160594219 : TREE_OPERAND (t, i) = va_arg (p, tree);
3627 :
3628 63981440 : va_end (p);
3629 63981440 : return convert_from_reference (t);
3630 : }
3631 :
3632 : /* Similar to build_min_nt, but call expressions */
3633 :
3634 : tree
3635 122795337 : build_min_nt_call_vec (tree fn, vec<tree, va_gc> *args)
3636 : {
3637 122795337 : tree ret, t;
3638 122795337 : unsigned int ix;
3639 :
3640 245528880 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
3641 122795337 : CALL_EXPR_FN (ret) = fn;
3642 122795337 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
3643 247979014 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
3644 125183677 : CALL_EXPR_ARG (ret, ix) = t;
3645 :
3646 122795337 : return ret;
3647 : }
3648 :
3649 : /* Similar to `build_min_nt_call_vec', but for template definitions of
3650 : non-dependent expressions. NON_DEP is the non-dependent expression
3651 : that has been built. */
3652 :
3653 : tree
3654 7869028 : build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec)
3655 : {
3656 7869028 : tree t = build_min_nt_call_vec (fn, argvec);
3657 7869028 : if (REFERENCE_REF_P (non_dep))
3658 4 : non_dep = TREE_OPERAND (non_dep, 0);
3659 7869028 : TREE_TYPE (t) = TREE_TYPE (non_dep);
3660 7869028 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3661 7869028 : return convert_from_reference (t);
3662 : }
3663 :
3664 : /* Similar to build_min_non_dep, but for expressions that have been resolved to
3665 : a call to an operator overload. OP is the operator that has been
3666 : overloaded. NON_DEP is the non-dependent expression that's been built,
3667 : which should be a CALL_EXPR or an INDIRECT_REF to a CALL_EXPR. OVERLOAD is
3668 : the overload that NON_DEP is calling. */
3669 :
3670 : tree
3671 2257867 : build_min_non_dep_op_overload (enum tree_code op,
3672 : tree non_dep,
3673 : tree overload, ...)
3674 : {
3675 2257867 : va_list p;
3676 2257867 : int nargs, expected_nargs;
3677 2257867 : tree fn, call, obj = NULL_TREE;
3678 :
3679 2257867 : non_dep = extract_call_expr (non_dep);
3680 :
3681 2257867 : nargs = call_expr_nargs (non_dep);
3682 :
3683 2257867 : expected_nargs = cp_tree_code_length (op);
3684 2257867 : if (TREE_CODE (TREE_TYPE (overload)) == METHOD_TYPE
3685 : /* For ARRAY_REF, operator[] is either a non-static member or newly
3686 : static member, never out of class and for the static member case
3687 : if user uses single index the operator[] needs to have a single
3688 : argument as well, but the function is called with 2 - the object
3689 : it is invoked on and the index. */
3690 2257867 : || op == ARRAY_REF)
3691 451576 : expected_nargs -= 1;
3692 2257867 : if ((op == POSTINCREMENT_EXPR
3693 2257867 : || op == POSTDECREMENT_EXPR)
3694 : /* With -fpermissive non_dep could be operator++(). */
3695 7784 : && (!flag_permissive || nargs != expected_nargs))
3696 7780 : expected_nargs += 1;
3697 2257867 : gcc_assert (nargs == expected_nargs);
3698 :
3699 2257867 : releasing_vec args;
3700 2257867 : va_start (p, overload);
3701 :
3702 2257867 : if (TREE_CODE (TREE_TYPE (overload)) == FUNCTION_TYPE)
3703 : {
3704 1806298 : fn = overload;
3705 1806298 : if (op == ARRAY_REF)
3706 7 : obj = va_arg (p, tree);
3707 5358271 : for (int i = 0; i < nargs; i++)
3708 : {
3709 3551973 : tree arg = va_arg (p, tree);
3710 3551973 : vec_safe_push (args, arg);
3711 : }
3712 : }
3713 451569 : else if (TREE_CODE (TREE_TYPE (overload)) == METHOD_TYPE)
3714 : {
3715 451569 : tree object = va_arg (p, tree);
3716 451569 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
3717 451569 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
3718 451569 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
3719 : object, method, NULL_TREE);
3720 768117 : for (int i = 0; i < nargs; i++)
3721 : {
3722 316548 : tree arg = va_arg (p, tree);
3723 316548 : vec_safe_push (args, arg);
3724 : }
3725 : }
3726 : else
3727 0 : gcc_unreachable ();
3728 :
3729 2257867 : va_end (p);
3730 2257867 : call = build_min_non_dep_call_vec (non_dep, fn, args);
3731 :
3732 2257867 : tree call_expr = extract_call_expr (call);
3733 2257867 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
3734 2257867 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
3735 2257867 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
3736 2257867 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
3737 :
3738 2257867 : if (obj)
3739 7 : return keep_unused_object_arg (call, obj, overload);
3740 : return call;
3741 2257867 : }
3742 :
3743 : /* Similar to above build_min_non_dep_op_overload, but arguments
3744 : are taken from ARGS vector. */
3745 :
3746 : tree
3747 16 : build_min_non_dep_op_overload (tree non_dep, tree overload, tree object,
3748 : vec<tree, va_gc> *args)
3749 : {
3750 16 : non_dep = extract_call_expr (non_dep);
3751 :
3752 16 : unsigned int nargs = call_expr_nargs (non_dep);
3753 16 : tree fn = overload;
3754 16 : if (TREE_CODE (TREE_TYPE (overload)) == METHOD_TYPE)
3755 : {
3756 8 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
3757 8 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
3758 8 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
3759 : object, method, NULL_TREE);
3760 8 : object = NULL_TREE;
3761 : }
3762 32 : gcc_assert (vec_safe_length (args) == nargs);
3763 :
3764 16 : tree call = build_min_non_dep_call_vec (non_dep, fn, args);
3765 :
3766 16 : tree call_expr = extract_call_expr (call);
3767 16 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
3768 16 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
3769 16 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
3770 16 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
3771 :
3772 16 : if (object)
3773 8 : return keep_unused_object_arg (call, object, overload);
3774 : return call;
3775 : }
3776 :
3777 : /* Return a new tree vec copied from VEC, with ELT inserted at index IDX. */
3778 :
3779 : vec<tree, va_gc> *
3780 25 : vec_copy_and_insert (vec<tree, va_gc> *old_vec, tree elt, unsigned idx)
3781 : {
3782 25 : unsigned len = vec_safe_length (old_vec);
3783 25 : gcc_assert (idx <= len);
3784 :
3785 25 : vec<tree, va_gc> *new_vec = NULL;
3786 25 : vec_alloc (new_vec, len + 1);
3787 :
3788 25 : unsigned i;
3789 81 : for (i = 0; i < len; ++i)
3790 : {
3791 31 : if (i == idx)
3792 6 : new_vec->quick_push (elt);
3793 31 : new_vec->quick_push ((*old_vec)[i]);
3794 : }
3795 25 : if (i == idx)
3796 19 : new_vec->quick_push (elt);
3797 :
3798 25 : return new_vec;
3799 : }
3800 :
3801 : tree
3802 66647 : get_type_decl (tree t)
3803 : {
3804 66647 : if (TREE_CODE (t) == TYPE_DECL)
3805 : return t;
3806 66647 : if (TYPE_P (t))
3807 66647 : return TYPE_STUB_DECL (t);
3808 0 : gcc_assert (t == error_mark_node);
3809 : return t;
3810 : }
3811 :
3812 : /* Returns the namespace that contains DECL, whether directly or
3813 : indirectly. */
3814 :
3815 : tree
3816 561111129 : decl_namespace_context (tree decl)
3817 : {
3818 1160779431 : while (1)
3819 : {
3820 1160779431 : if (TREE_CODE (decl) == NAMESPACE_DECL)
3821 561111129 : return decl;
3822 599668302 : else if (TYPE_P (decl))
3823 367742682 : decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
3824 : else
3825 231925620 : decl = CP_DECL_CONTEXT (decl);
3826 : }
3827 : }
3828 :
3829 : /* Returns true if decl is within an anonymous namespace, however deeply
3830 : nested, or false otherwise. */
3831 :
3832 : bool
3833 33 : decl_anon_ns_mem_p (tree decl)
3834 : {
3835 33 : return !TREE_PUBLIC (decl_namespace_context (decl));
3836 : }
3837 :
3838 : /* Returns true if the enclosing scope of DECL has internal or no linkage. */
3839 :
3840 : bool
3841 600123064 : decl_internal_context_p (const_tree decl)
3842 : {
3843 1201896439 : while (TREE_CODE (decl) != NAMESPACE_DECL)
3844 : {
3845 : /* Classes inside anonymous namespaces have TREE_PUBLIC == 0. */
3846 789338411 : if (TYPE_P (decl))
3847 187565036 : return !TREE_PUBLIC (TYPE_MAIN_DECL (decl));
3848 :
3849 601773375 : decl = CP_DECL_CONTEXT (decl);
3850 : }
3851 412558028 : return !TREE_PUBLIC (decl);
3852 : }
3853 :
3854 : /* Subroutine of cp_tree_equal: t1 and t2 are two CALL_EXPRs.
3855 : Return whether their CALL_EXPR_FNs are equivalent. */
3856 :
3857 : static bool
3858 25369124 : called_fns_equal (tree t1, tree t2)
3859 : {
3860 : /* Core 1321: dependent names are equivalent even if the overload sets
3861 : are different. But do compare explicit template arguments. */
3862 25369124 : tree name1 = call_expr_dependent_name (t1);
3863 25369124 : tree name2 = call_expr_dependent_name (t2);
3864 25369124 : t1 = CALL_EXPR_FN (t1);
3865 25369124 : t2 = CALL_EXPR_FN (t2);
3866 25369124 : if (name1 || name2)
3867 : {
3868 1801662 : tree targs1 = NULL_TREE, targs2 = NULL_TREE;
3869 :
3870 1801662 : if (name1 != name2)
3871 : return false;
3872 :
3873 : /* FIXME dependent_name currently returns an unqualified name regardless
3874 : of whether the function was named with a qualified- or unqualified-id.
3875 : Until that's fixed, check that we aren't looking at overload sets from
3876 : different scopes. */
3877 1695426 : if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
3878 3412256 : && (DECL_CONTEXT (get_first_fn (t1))
3879 1695423 : != DECL_CONTEXT (get_first_fn (t2))))
3880 : return false;
3881 :
3882 1716833 : if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
3883 1336584 : targs1 = TREE_OPERAND (t1, 1);
3884 1716833 : if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
3885 1336584 : targs2 = TREE_OPERAND (t2, 1);
3886 1716833 : return cp_tree_equal (targs1, targs2);
3887 : }
3888 : else
3889 23567462 : return cp_tree_equal (t1, t2);
3890 : }
3891 :
3892 : bool comparing_override_contracts;
3893 :
3894 : /* In a component reference, return the innermost object of
3895 : the postfix-expression. */
3896 :
3897 : static tree
3898 12 : get_innermost_component (tree t)
3899 : {
3900 12 : gcc_assert (TREE_CODE (t) == COMPONENT_REF);
3901 33 : while (TREE_CODE (t) == COMPONENT_REF)
3902 21 : t = TREE_OPERAND (t, 0);
3903 12 : return t;
3904 : }
3905 :
3906 : /* Returns true if T is a possibly converted 'this' or '*this' expression. */
3907 :
3908 : static bool
3909 12 : is_this_expression (tree t)
3910 : {
3911 12 : t = get_innermost_component (t);
3912 : /* See through deferences and no-op conversions. */
3913 12 : if (INDIRECT_REF_P (t))
3914 12 : t = TREE_OPERAND (t, 0);
3915 12 : if (TREE_CODE (t) == NOP_EXPR)
3916 12 : t = TREE_OPERAND (t, 0);
3917 12 : return is_this_parameter (t);
3918 : }
3919 :
3920 : static bool
3921 6 : comparing_this_references (tree t1, tree t2)
3922 : {
3923 6 : return is_this_expression (t1) && is_this_expression (t2);
3924 : }
3925 :
3926 : static bool
3927 6 : equivalent_member_references (tree t1, tree t2)
3928 : {
3929 6 : if (!comparing_this_references (t1, t2))
3930 : return false;
3931 6 : t1 = TREE_OPERAND (t1, 1);
3932 6 : t2 = TREE_OPERAND (t2, 1);
3933 6 : return t1 == t2;
3934 : }
3935 :
3936 : /* Return truthvalue of whether T1 is the same tree structure as T2.
3937 : Return 1 if they are the same. Return 0 if they are different. */
3938 :
3939 : bool
3940 497228280 : cp_tree_equal (tree t1, tree t2)
3941 : {
3942 497581538 : enum tree_code code1, code2;
3943 :
3944 497581538 : if (t1 == t2)
3945 : return true;
3946 420064778 : if (!t1 || !t2)
3947 : return false;
3948 :
3949 419694300 : code1 = TREE_CODE (t1);
3950 419694300 : code2 = TREE_CODE (t2);
3951 :
3952 419694300 : if (code1 != code2)
3953 : return false;
3954 :
3955 244453130 : if (CONSTANT_CLASS_P (t1)
3956 244453130 : && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
3957 : return false;
3958 :
3959 244398263 : switch (code1)
3960 : {
3961 0 : case VOID_CST:
3962 : /* There's only a single VOID_CST node, so we should never reach
3963 : here. */
3964 0 : gcc_unreachable ();
3965 :
3966 30065820 : case INTEGER_CST:
3967 30065820 : return tree_int_cst_equal (t1, t2);
3968 :
3969 67365 : case REAL_CST:
3970 67365 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
3971 :
3972 17264 : case STRING_CST:
3973 17264 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3974 17264 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3975 17264 : TREE_STRING_LENGTH (t1));
3976 :
3977 0 : case FIXED_CST:
3978 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
3979 : TREE_FIXED_CST (t2));
3980 :
3981 1 : case COMPLEX_CST:
3982 1 : return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
3983 2 : && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
3984 :
3985 2770 : case VECTOR_CST:
3986 2770 : return operand_equal_p (t1, t2, OEP_ONLY_CONST);
3987 :
3988 1003595 : case CONSTRUCTOR:
3989 : /* We need to do this when determining whether or not two
3990 : non-type pointer to member function template arguments
3991 : are the same. */
3992 1003595 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
3993 2136208 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
3994 : return false;
3995 : {
3996 : tree field, value;
3997 : unsigned int i;
3998 974425 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
3999 : {
4000 44684 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
4001 44684 : if (!cp_tree_equal (field, elt2->index)
4002 44684 : || !cp_tree_equal (value, elt2->value))
4003 16 : return false;
4004 : }
4005 : }
4006 : return true;
4007 :
4008 147569 : case TREE_LIST:
4009 147569 : if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
4010 : return false;
4011 147569 : if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
4012 : return false;
4013 54429 : return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
4014 :
4015 753 : case SAVE_EXPR:
4016 753 : return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4017 :
4018 25381337 : case CALL_EXPR:
4019 25381337 : {
4020 25381337 : if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
4021 : return false;
4022 :
4023 25369124 : if (!called_fns_equal (t1, t2))
4024 : return false;
4025 :
4026 7223853 : call_expr_arg_iterator iter1, iter2;
4027 7223853 : init_call_expr_arg_iterator (t1, &iter1);
4028 7223853 : init_call_expr_arg_iterator (t2, &iter2);
4029 7223853 : if (iter1.n != iter2.n)
4030 : return false;
4031 :
4032 7464726 : while (more_call_expr_args_p (&iter1))
4033 : {
4034 564349 : tree arg1 = next_call_expr_arg (&iter1);
4035 564349 : tree arg2 = next_call_expr_arg (&iter2);
4036 :
4037 564349 : gcc_checking_assert (arg1 && arg2);
4038 564349 : if (!cp_tree_equal (arg1, arg2))
4039 : return false;
4040 : }
4041 :
4042 : return true;
4043 : }
4044 :
4045 81491 : case TARGET_EXPR:
4046 81491 : {
4047 81491 : tree o1 = TREE_OPERAND (t1, 0);
4048 81491 : tree o2 = TREE_OPERAND (t2, 0);
4049 :
4050 : /* Special case: if either target is an unallocated VAR_DECL,
4051 : it means that it's going to be unified with whatever the
4052 : TARGET_EXPR is really supposed to initialize, so treat it
4053 : as being equivalent to anything. */
4054 81491 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
4055 162982 : && !DECL_RTL_SET_P (o1))
4056 : /*Nop*/;
4057 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
4058 0 : && !DECL_RTL_SET_P (o2))
4059 : /*Nop*/;
4060 0 : else if (!cp_tree_equal (o1, o2))
4061 : return false;
4062 :
4063 81491 : return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
4064 : }
4065 :
4066 217324 : case PARM_DECL:
4067 : /* For comparing uses of parameters in late-specified return types
4068 : with an out-of-class definition of the function, but can also come
4069 : up for expressions that involve 'this' in a member function
4070 : template. */
4071 :
4072 217324 : if (comparing_specializations
4073 217324 : && DECL_CONTEXT (t1) != DECL_CONTEXT (t2))
4074 : /* When comparing hash table entries, only an exact match is
4075 : good enough; we don't want to replace 'this' with the
4076 : version from another function. But be more flexible
4077 : with parameters with identical contexts. */
4078 : return false;
4079 :
4080 66043 : if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4081 : {
4082 9792 : if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
4083 : return false;
4084 9792 : if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
4085 : return false;
4086 9792 : if (DECL_ARTIFICIAL (t1)
4087 9792 : || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
4088 8508 : && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
4089 : return true;
4090 : }
4091 : return false;
4092 :
4093 : case VAR_DECL:
4094 : case CONST_DECL:
4095 : case FIELD_DECL:
4096 : case FUNCTION_DECL:
4097 : case TEMPLATE_DECL:
4098 : case IDENTIFIER_NODE:
4099 : case SSA_NAME:
4100 : case USING_DECL:
4101 : case DEFERRED_PARSE:
4102 : return false;
4103 :
4104 14111309 : case BASELINK:
4105 14111309 : return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
4106 13512002 : && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
4107 13512002 : && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
4108 27623290 : && cp_tree_equal (BASELINK_FUNCTIONS (t1),
4109 13511981 : BASELINK_FUNCTIONS (t2)));
4110 :
4111 8642122 : case TEMPLATE_PARM_INDEX:
4112 8642122 : return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
4113 8161861 : && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
4114 8050190 : && (TEMPLATE_PARM_PARAMETER_PACK (t1)
4115 8050190 : == TEMPLATE_PARM_PARAMETER_PACK (t2))
4116 16690759 : && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
4117 : TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
4118 :
4119 18128419 : case TEMPLATE_ID_EXPR:
4120 18128419 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4121 : return false;
4122 12544120 : if (!comp_template_args (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)))
4123 : return false;
4124 : return true;
4125 :
4126 216031 : case CONSTRAINT_INFO:
4127 648093 : return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1),
4128 648093 : CI_ASSOCIATED_CONSTRAINTS (t2));
4129 :
4130 0 : case CHECK_CONSTR:
4131 0 : return (CHECK_CONSTR_CONCEPT (t1) == CHECK_CONSTR_CONCEPT (t2)
4132 0 : && comp_template_args (CHECK_CONSTR_ARGS (t1),
4133 0 : CHECK_CONSTR_ARGS (t2)));
4134 :
4135 13296954 : case TREE_VEC:
4136 : /* These are template args. Really we should be getting the
4137 : caller to do this as it knows it to be true. */
4138 13296954 : if (!comp_template_args (t1, t2, NULL, NULL, false))
4139 : return false;
4140 : return true;
4141 :
4142 364753 : case SIZEOF_EXPR:
4143 364753 : case ALIGNOF_EXPR:
4144 364753 : {
4145 364753 : tree o1 = TREE_OPERAND (t1, 0);
4146 364753 : tree o2 = TREE_OPERAND (t2, 0);
4147 :
4148 364753 : if (code1 == SIZEOF_EXPR)
4149 : {
4150 350239 : if (SIZEOF_EXPR_TYPE_P (t1))
4151 0 : o1 = TREE_TYPE (o1);
4152 350239 : if (SIZEOF_EXPR_TYPE_P (t2))
4153 0 : o2 = TREE_TYPE (o2);
4154 : }
4155 14514 : else if (ALIGNOF_EXPR_STD_P (t1) != ALIGNOF_EXPR_STD_P (t2))
4156 : return false;
4157 :
4158 364747 : if (TREE_CODE (o1) != TREE_CODE (o2))
4159 : return false;
4160 :
4161 364731 : if (ARGUMENT_PACK_P (o1))
4162 2 : return template_args_equal (o1, o2);
4163 364729 : else if (TYPE_P (o1))
4164 364291 : return same_type_p (o1, o2);
4165 : else
4166 : return cp_tree_equal (o1, o2);
4167 : }
4168 :
4169 227 : case MODOP_EXPR:
4170 227 : {
4171 227 : tree t1_op1, t2_op1;
4172 :
4173 227 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4174 : return false;
4175 :
4176 227 : t1_op1 = TREE_OPERAND (t1, 1);
4177 227 : t2_op1 = TREE_OPERAND (t2, 1);
4178 227 : if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
4179 : return false;
4180 :
4181 116 : return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
4182 : }
4183 :
4184 701 : case PTRMEM_CST:
4185 : /* Two pointer-to-members are the same if they point to the same
4186 : field or function in the same class. */
4187 701 : if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
4188 : return false;
4189 :
4190 610 : return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
4191 :
4192 4023309 : case OVERLOAD:
4193 4023309 : {
4194 : /* Two overloads. Must be exactly the same set of decls. */
4195 4023309 : lkp_iterator first (t1);
4196 4023309 : lkp_iterator second (t2);
4197 :
4198 4033968 : for (; first && second; ++first, ++second)
4199 4024466 : if (*first != *second)
4200 : return false;
4201 9502 : return !(first || second);
4202 : }
4203 :
4204 3458488 : case TRAIT_EXPR:
4205 3458488 : if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
4206 : return false;
4207 256417 : return cp_tree_equal (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
4208 475656 : && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
4209 :
4210 24457 : case NON_LVALUE_EXPR:
4211 24457 : case VIEW_CONVERT_EXPR:
4212 : /* Used for location wrappers with possibly NULL types. */
4213 24457 : if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
4214 : {
4215 32 : if (TREE_TYPE (t1) || TREE_TYPE (t2))
4216 : return false;
4217 : break;
4218 : }
4219 : /* FALLTHROUGH */
4220 :
4221 342753 : case CAST_EXPR:
4222 342753 : case STATIC_CAST_EXPR:
4223 342753 : case REINTERPRET_CAST_EXPR:
4224 342753 : case CONST_CAST_EXPR:
4225 342753 : case DYNAMIC_CAST_EXPR:
4226 342753 : case IMPLICIT_CONV_EXPR:
4227 342753 : case NEW_EXPR:
4228 342753 : case BIT_CAST_EXPR:
4229 342753 : CASE_CONVERT:
4230 342753 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4231 : return false;
4232 : /* Now compare operands as usual. */
4233 : break;
4234 :
4235 611983 : case DEFERRED_NOEXCEPT:
4236 1223966 : return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1),
4237 611983 : DEFERRED_NOEXCEPT_PATTERN (t2))
4238 993623 : && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1),
4239 381640 : DEFERRED_NOEXCEPT_ARGS (t2)));
4240 :
4241 : case LAMBDA_EXPR:
4242 : /* Two lambda-expressions are never considered equivalent. */
4243 : return false;
4244 :
4245 80733352 : case TYPE_ARGUMENT_PACK:
4246 80733352 : case NONTYPE_ARGUMENT_PACK:
4247 80733352 : {
4248 80733352 : tree p1 = ARGUMENT_PACK_ARGS (t1);
4249 80733352 : tree p2 = ARGUMENT_PACK_ARGS (t2);
4250 80733352 : int len = TREE_VEC_LENGTH (p1);
4251 80733352 : if (TREE_VEC_LENGTH (p2) != len)
4252 : return false;
4253 :
4254 141633510 : for (int ix = 0; ix != len; ix++)
4255 99421682 : if (!template_args_equal (TREE_VEC_ELT (p1, ix),
4256 99421682 : TREE_VEC_ELT (p2, ix)))
4257 : return false;
4258 : return true;
4259 : }
4260 :
4261 8493 : case EXPR_PACK_EXPANSION:
4262 8493 : if (!cp_tree_equal (PACK_EXPANSION_PATTERN (t1),
4263 8493 : PACK_EXPANSION_PATTERN (t2)))
4264 : return false;
4265 8483 : if (!comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
4266 8483 : PACK_EXPANSION_EXTRA_ARGS (t2)))
4267 : return false;
4268 : return true;
4269 :
4270 353335 : case COMPONENT_REF:
4271 : /* If we're comparing contract conditions of overrides, member references
4272 : compare equal if they designate the same member. */
4273 353335 : if (comparing_override_contracts)
4274 6 : return equivalent_member_references (t1, t2);
4275 : break;
4276 :
4277 : default:
4278 : break;
4279 : }
4280 :
4281 34357940 : switch (TREE_CODE_CLASS (code1))
4282 : {
4283 30077799 : case tcc_unary:
4284 30077799 : case tcc_binary:
4285 30077799 : case tcc_comparison:
4286 30077799 : case tcc_expression:
4287 30077799 : case tcc_vl_exp:
4288 30077799 : case tcc_reference:
4289 30077799 : case tcc_statement:
4290 30077799 : {
4291 30077799 : int n = cp_tree_operand_length (t1);
4292 30077799 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
4293 30077799 : && n != TREE_OPERAND_LENGTH (t2))
4294 : return false;
4295 :
4296 65202864 : for (int i = 0; i < n; ++i)
4297 47027041 : if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
4298 : return false;
4299 :
4300 : return true;
4301 : }
4302 :
4303 4280141 : case tcc_type:
4304 4280141 : return same_type_p (t1, t2);
4305 :
4306 0 : default:
4307 0 : gcc_unreachable ();
4308 : }
4309 :
4310 : /* We can get here with --disable-checking. */
4311 : return false;
4312 : }
4313 :
4314 : /* The type of ARG when used as an lvalue. */
4315 :
4316 : tree
4317 326415845 : lvalue_type (tree arg)
4318 : {
4319 326415845 : tree type = TREE_TYPE (arg);
4320 326415845 : return type;
4321 : }
4322 :
4323 : /* The type of ARG for printing error messages; denote lvalues with
4324 : reference types. */
4325 :
4326 : tree
4327 3073 : error_type (tree arg)
4328 : {
4329 3073 : tree type = TREE_TYPE (arg);
4330 :
4331 3073 : if (TREE_CODE (type) == ARRAY_TYPE)
4332 : ;
4333 3002 : else if (TREE_CODE (type) == ERROR_MARK)
4334 : ;
4335 3002 : else if (lvalue_p (arg))
4336 1165 : type = build_reference_type (lvalue_type (arg));
4337 1837 : else if (MAYBE_CLASS_TYPE_P (type))
4338 706 : type = lvalue_type (arg);
4339 :
4340 3073 : return type;
4341 : }
4342 :
4343 : /* Does FUNCTION use a variable-length argument list? */
4344 :
4345 : int
4346 132001 : varargs_function_p (const_tree function)
4347 : {
4348 132001 : return stdarg_p (TREE_TYPE (function));
4349 : }
4350 :
4351 : /* Returns 1 if decl is a member of a class. */
4352 :
4353 : int
4354 9156 : member_p (const_tree decl)
4355 : {
4356 9156 : const_tree const ctx = DECL_CONTEXT (decl);
4357 9156 : return (ctx && TYPE_P (ctx));
4358 : }
4359 :
4360 : /* Create a placeholder for member access where we don't actually have an
4361 : object that the access is against. For a general declval<T> equivalent,
4362 : use build_stub_object instead. */
4363 :
4364 : tree
4365 34133985 : build_dummy_object (tree type)
4366 : {
4367 34133985 : tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node);
4368 34133985 : return cp_build_fold_indirect_ref (decl);
4369 : }
4370 :
4371 : /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
4372 : or a dummy object otherwise. If BINFOP is non-0, it is filled with the
4373 : binfo path from current_class_type to TYPE, or 0. */
4374 :
4375 : tree
4376 63677685 : maybe_dummy_object (tree type, tree* binfop)
4377 : {
4378 63677685 : tree decl, context;
4379 63677685 : tree binfo;
4380 63677685 : tree current = current_nonlambda_class_type ();
4381 :
4382 63677685 : if (current
4383 63677685 : && (binfo = lookup_base (current, type, ba_any, NULL,
4384 : tf_warning_or_error)))
4385 : context = current;
4386 : else
4387 : {
4388 : /* Reference from a nested class member function. */
4389 9407159 : context = type;
4390 9407159 : binfo = TYPE_BINFO (type);
4391 : }
4392 :
4393 63677685 : if (binfop)
4394 80920 : *binfop = binfo;
4395 :
4396 : /* current_class_ref might not correspond to current_class_type if
4397 : we're in tsubst_default_argument or a lambda-declarator; in either
4398 : case, we want to use current_class_ref if it matches CONTEXT. */
4399 63677685 : tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE;
4400 59201234 : if (ctype
4401 59201234 : && same_type_ignoring_top_level_qualifiers_p (ctype, context))
4402 52734094 : decl = current_class_ref;
4403 : else
4404 : {
4405 : /* Return a dummy object whose cv-quals are consistent with (the
4406 : non-lambda) 'this' if available. */
4407 10943591 : if (ctype)
4408 : {
4409 6467140 : int quals = TYPE_UNQUALIFIED;
4410 6467140 : if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype))
4411 : {
4412 129480 : if (tree cap = lambda_expr_this_capture (lambda, false))
4413 125538 : quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap)));
4414 : }
4415 : else
4416 6337660 : quals = cp_type_quals (ctype);
4417 6467140 : context = cp_build_qualified_type (context, quals);
4418 : }
4419 10943591 : decl = build_dummy_object (context);
4420 : }
4421 :
4422 63677685 : return decl;
4423 : }
4424 :
4425 : /* Returns 1 if OB is a placeholder object, or a pointer to one. */
4426 :
4427 : bool
4428 354426220 : is_dummy_object (const_tree ob)
4429 : {
4430 354426220 : if (INDIRECT_REF_P (ob))
4431 234087493 : ob = TREE_OPERAND (ob, 0);
4432 354426220 : return (TREE_CODE (ob) == CONVERT_EXPR
4433 354426220 : && TREE_OPERAND (ob, 0) == void_node);
4434 : }
4435 :
4436 : /* Returns true if TYPE is char, unsigned char, or std::byte. */
4437 :
4438 : bool
4439 14772376 : is_byte_access_type (tree type)
4440 : {
4441 14772376 : type = TYPE_MAIN_VARIANT (type);
4442 14772376 : if (type == char_type_node
4443 3062321 : || type == unsigned_char_type_node)
4444 : return true;
4445 :
4446 2985596 : return (TREE_CODE (type) == ENUMERAL_TYPE
4447 3515 : && TYPE_CONTEXT (type) == std_node
4448 2985870 : && !strcmp ("byte", TYPE_NAME_STRING (type)));
4449 : }
4450 :
4451 : /* Returns true if TYPE is unsigned char or std::byte. */
4452 :
4453 : bool
4454 1773 : is_byte_access_type_not_plain_char (tree type)
4455 : {
4456 1773 : type = TYPE_MAIN_VARIANT (type);
4457 1773 : if (type == char_type_node)
4458 : return false;
4459 :
4460 1525 : return is_byte_access_type (type);
4461 : }
4462 :
4463 : /* Returns 1 iff type T is something we want to treat as a scalar type for
4464 : the purpose of deciding whether it is trivial/POD/standard-layout. */
4465 :
4466 : bool
4467 21016042 : scalarish_type_p (const_tree t)
4468 : {
4469 21016042 : if (t == error_mark_node)
4470 : return 1;
4471 :
4472 21015846 : return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
4473 : }
4474 :
4475 : /* Returns true iff T requires non-trivial default initialization. */
4476 :
4477 : bool
4478 0 : type_has_nontrivial_default_init (const_tree t)
4479 : {
4480 0 : t = strip_array_types (CONST_CAST_TREE (t));
4481 :
4482 0 : if (CLASS_TYPE_P (t))
4483 0 : return TYPE_HAS_COMPLEX_DFLT (t);
4484 : else
4485 : return 0;
4486 : }
4487 :
4488 : /* Track classes with only deleted copy/move constructors so that we can warn
4489 : if they are used in call/return by value. */
4490 :
4491 : static GTY(()) hash_set<tree>* deleted_copy_types;
4492 : static void
4493 977 : remember_deleted_copy (const_tree t)
4494 : {
4495 977 : if (!deleted_copy_types)
4496 221 : deleted_copy_types = hash_set<tree>::create_ggc(37);
4497 977 : deleted_copy_types->add (CONST_CAST_TREE (t));
4498 977 : }
4499 : void
4500 191470450 : maybe_warn_parm_abi (tree t, location_t loc)
4501 : {
4502 191470450 : if (!deleted_copy_types
4503 191470450 : || !deleted_copy_types->contains (t))
4504 191470420 : return;
4505 :
4506 30 : if ((flag_abi_version == 12 || warn_abi_version == 12)
4507 36 : && classtype_has_non_deleted_move_ctor (t))
4508 : {
4509 6 : bool w;
4510 6 : auto_diagnostic_group d;
4511 6 : if (flag_abi_version > 12)
4512 0 : w = warning_at (loc, OPT_Wabi, "%<-fabi-version=13%> (GCC 8.2) fixes "
4513 : "the calling convention for %qT, which was "
4514 : "accidentally changed in 8.1", t);
4515 : else
4516 6 : w = warning_at (loc, OPT_Wabi, "%<-fabi-version=12%> (GCC 8.1) "
4517 : "accidentally changes the calling convention for %qT",
4518 : t);
4519 6 : if (w)
4520 6 : inform (location_of (t), " declared here");
4521 6 : return;
4522 6 : }
4523 :
4524 30 : auto_diagnostic_group d;
4525 30 : if (warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in "
4526 : "%<-fabi-version=13%> (GCC 8.2)", t))
4527 30 : inform (location_of (t), " because all of its copy and move "
4528 : "constructors are deleted");
4529 30 : }
4530 :
4531 : /* Returns true iff copying an object of type T (including via move
4532 : constructor) is non-trivial. That is, T has no non-trivial copy
4533 : constructors and no non-trivial move constructors, and not all copy/move
4534 : constructors are deleted. This function implements the ABI notion of
4535 : non-trivial copy, which has diverged from the one in the standard. */
4536 :
4537 : bool
4538 28713008 : type_has_nontrivial_copy_init (const_tree type)
4539 : {
4540 28713008 : tree t = strip_array_types (CONST_CAST_TREE (type));
4541 :
4542 28713008 : if (CLASS_TYPE_P (t))
4543 : {
4544 28278829 : gcc_assert (COMPLETE_TYPE_P (t));
4545 :
4546 28278829 : if (TYPE_HAS_COMPLEX_COPY_CTOR (t)
4547 28278829 : || TYPE_HAS_COMPLEX_MOVE_CTOR (t))
4548 : /* Nontrivial. */
4549 : return true;
4550 :
4551 25843124 : if (cxx_dialect < cxx11)
4552 : /* No deleted functions before C++11. */
4553 : return false;
4554 :
4555 : /* Before ABI v12 we did a bitwise copy of types with only deleted
4556 : copy/move constructors. */
4557 25770808 : if (!abi_version_at_least (12)
4558 8326 : && !(warn_abi && abi_version_crosses (12)))
4559 : return false;
4560 :
4561 25762806 : bool saw_copy = false;
4562 25762806 : bool saw_non_deleted = false;
4563 25762806 : bool saw_non_deleted_move = false;
4564 :
4565 25762806 : if (CLASSTYPE_LAZY_MOVE_CTOR (t))
4566 : saw_copy = saw_non_deleted = true;
4567 2227909 : else if (CLASSTYPE_LAZY_COPY_CTOR (t))
4568 : {
4569 283652 : saw_copy = true;
4570 283652 : if (classtype_has_move_assign_or_move_ctor_p (t, true))
4571 : /* [class.copy]/8 If the class definition declares a move
4572 : constructor or move assignment operator, the implicitly declared
4573 : copy constructor is defined as deleted.... */;
4574 : else
4575 : /* Any other reason the implicitly-declared function would be
4576 : deleted would also cause TYPE_HAS_COMPLEX_COPY_CTOR to be
4577 : set. */
4578 23817109 : saw_non_deleted = true;
4579 : }
4580 :
4581 25762806 : if (!saw_non_deleted)
4582 15722091 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
4583 : {
4584 8473687 : tree fn = *iter;
4585 8473687 : if (copy_fn_p (fn))
4586 : {
4587 1944258 : saw_copy = true;
4588 1944258 : if (!DECL_DELETED_FN (fn))
4589 : {
4590 : /* Not deleted, therefore trivial. */
4591 : saw_non_deleted = true;
4592 : break;
4593 : }
4594 : }
4595 6529429 : else if (move_fn_p (fn))
4596 1358225 : if (!DECL_DELETED_FN (fn))
4597 1356218 : saw_non_deleted_move = true;
4598 : }
4599 :
4600 25762806 : gcc_assert (saw_copy);
4601 :
4602 : /* ABI v12 buggily ignored move constructors. */
4603 25762806 : bool v11nontriv = false;
4604 25762806 : bool v12nontriv = !saw_non_deleted;
4605 25762806 : bool v13nontriv = !saw_non_deleted && !saw_non_deleted_move;
4606 25762977 : bool nontriv = (abi_version_at_least (13) ? v13nontriv
4607 171 : : flag_abi_version == 12 ? v12nontriv
4608 25762806 : : v11nontriv);
4609 25910923 : bool warn_nontriv = (warn_abi_version >= 13 ? v13nontriv
4610 148117 : : warn_abi_version == 12 ? v12nontriv
4611 : : v11nontriv);
4612 25762806 : if (nontriv != warn_nontriv)
4613 977 : remember_deleted_copy (t);
4614 :
4615 25762806 : return nontriv;
4616 : }
4617 : else
4618 : return 0;
4619 : }
4620 :
4621 : /* Returns 1 iff type T is a trivially copyable type, as defined in
4622 : [basic.types] and [class]. */
4623 :
4624 : bool
4625 33897 : trivially_copyable_p (const_tree t)
4626 : {
4627 33897 : t = strip_array_types (CONST_CAST_TREE (t));
4628 :
4629 33897 : if (CLASS_TYPE_P (t))
4630 25575 : return ((!TYPE_HAS_COPY_CTOR (t)
4631 25575 : || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
4632 24513 : && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
4633 24468 : && (!TYPE_HAS_COPY_ASSIGN (t)
4634 24468 : || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
4635 23465 : && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
4636 48788 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
4637 : else
4638 : /* CWG 2094 makes volatile-qualified scalars trivially copyable again. */
4639 8322 : return scalarish_type_p (t);
4640 : }
4641 :
4642 : /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
4643 : [class]. */
4644 :
4645 : bool
4646 91866 : trivial_type_p (const_tree t)
4647 : {
4648 91866 : t = strip_array_types (CONST_CAST_TREE (t));
4649 :
4650 91866 : if (CLASS_TYPE_P (t))
4651 45862 : return (TYPE_HAS_TRIVIAL_DFLT (t)
4652 39479 : && trivially_copyable_p (t));
4653 : else
4654 68185 : return scalarish_type_p (t);
4655 : }
4656 :
4657 : /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
4658 :
4659 : bool
4660 8666 : pod_type_p (const_tree t)
4661 : {
4662 : /* This CONST_CAST is okay because strip_array_types returns its
4663 : argument unmodified and we assign it to a const_tree. */
4664 8666 : t = strip_array_types (CONST_CAST_TREE(t));
4665 :
4666 8666 : if (!CLASS_TYPE_P (t))
4667 636 : return scalarish_type_p (t);
4668 8030 : else if (cxx_dialect > cxx98)
4669 : /* [class]/10: A POD struct is a class that is both a trivial class and a
4670 : standard-layout class, and has no non-static data members of type
4671 : non-POD struct, non-POD union (or array of such types).
4672 :
4673 : We don't need to check individual members because if a member is
4674 : non-std-layout or non-trivial, the class will be too. */
4675 7956 : return (std_layout_type_p (t) && trivial_type_p (t));
4676 : else
4677 : /* The C++98 definition of POD is different. */
4678 74 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
4679 : }
4680 :
4681 : /* Returns true iff T is POD for the purpose of layout, as defined in the
4682 : C++ ABI. */
4683 :
4684 : bool
4685 9906712 : layout_pod_type_p (const_tree t)
4686 : {
4687 9906712 : t = strip_array_types (CONST_CAST_TREE (t));
4688 :
4689 9906712 : if (CLASS_TYPE_P (t))
4690 1743243 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
4691 : else
4692 8163469 : return scalarish_type_p (t);
4693 : }
4694 :
4695 : /* Returns true iff T is a standard-layout type, as defined in
4696 : [basic.types]. */
4697 :
4698 : bool
4699 9947553 : std_layout_type_p (const_tree t)
4700 : {
4701 9947553 : t = strip_array_types (CONST_CAST_TREE (t));
4702 :
4703 9947553 : if (CLASS_TYPE_P (t))
4704 1751499 : return !CLASSTYPE_NON_STD_LAYOUT (t);
4705 : else
4706 8196054 : return scalarish_type_p (t);
4707 : }
4708 :
4709 : static bool record_has_unique_obj_representations (const_tree, const_tree);
4710 :
4711 : /* Returns true iff T satisfies std::has_unique_object_representations<T>,
4712 : as defined in [meta.unary.prop]. */
4713 :
4714 : bool
4715 466 : type_has_unique_obj_representations (const_tree t)
4716 : {
4717 510 : bool ret;
4718 :
4719 510 : t = strip_array_types (CONST_CAST_TREE (t));
4720 :
4721 510 : if (!trivially_copyable_p (t))
4722 : return false;
4723 :
4724 501 : if (CLASS_TYPE_P (t) && CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t))
4725 57 : return CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t);
4726 :
4727 444 : switch (TREE_CODE (t))
4728 : {
4729 : case INTEGER_TYPE:
4730 : case POINTER_TYPE:
4731 : case REFERENCE_TYPE:
4732 : /* If some backend has any paddings in these types, we should add
4733 : a target hook for this and handle it there. */
4734 : return true;
4735 :
4736 : case BOOLEAN_TYPE:
4737 : /* For bool values other than 0 and 1 should only appear with
4738 : undefined behavior. */
4739 : return true;
4740 :
4741 26 : case ENUMERAL_TYPE:
4742 26 : return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t));
4743 :
4744 : case REAL_TYPE:
4745 : /* XFmode certainly contains padding on x86, which the CPU doesn't store
4746 : when storing long double values, so for that we have to return false.
4747 : Other kinds of floating point values are questionable due to +.0/-.0
4748 : and NaNs, let's play safe for now. */
4749 : return false;
4750 :
4751 : case FIXED_POINT_TYPE:
4752 : return false;
4753 :
4754 : case OFFSET_TYPE:
4755 : return true;
4756 :
4757 18 : case COMPLEX_TYPE:
4758 18 : case VECTOR_TYPE:
4759 18 : return type_has_unique_obj_representations (TREE_TYPE (t));
4760 :
4761 65 : case RECORD_TYPE:
4762 65 : ret = record_has_unique_obj_representations (t, TYPE_SIZE (t));
4763 65 : if (CLASS_TYPE_P (t))
4764 : {
4765 62 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
4766 62 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
4767 : }
4768 : return ret;
4769 :
4770 10 : case UNION_TYPE:
4771 10 : ret = true;
4772 10 : bool any_fields;
4773 10 : any_fields = false;
4774 26 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
4775 23 : if (TREE_CODE (field) == FIELD_DECL)
4776 : {
4777 20 : any_fields = true;
4778 20 : if (!type_has_unique_obj_representations (TREE_TYPE (field))
4779 20 : || simple_cst_equal (DECL_SIZE (field), TYPE_SIZE (t)) != 1)
4780 : {
4781 : ret = false;
4782 : break;
4783 : }
4784 : }
4785 10 : if (!any_fields && !integer_zerop (TYPE_SIZE (t)))
4786 : ret = false;
4787 10 : if (CLASS_TYPE_P (t))
4788 : {
4789 10 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
4790 10 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
4791 : }
4792 : return ret;
4793 :
4794 : case NULLPTR_TYPE:
4795 : return false;
4796 :
4797 : case ERROR_MARK:
4798 : return false;
4799 :
4800 0 : default:
4801 0 : gcc_unreachable ();
4802 : }
4803 : }
4804 :
4805 : /* Helper function for type_has_unique_obj_representations. */
4806 :
4807 : static bool
4808 70 : record_has_unique_obj_representations (const_tree t, const_tree sz)
4809 : {
4810 411 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
4811 348 : if (TREE_CODE (field) != FIELD_DECL)
4812 : ;
4813 : /* For bases, can't use type_has_unique_obj_representations here, as in
4814 : struct S { int i : 24; S (); };
4815 : struct T : public S { int j : 8; T (); };
4816 : S doesn't have unique obj representations, but T does. */
4817 102 : else if (DECL_FIELD_IS_BASE (field))
4818 : {
4819 5 : if (!record_has_unique_obj_representations (TREE_TYPE (field),
4820 5 : DECL_SIZE (field)))
4821 : return false;
4822 : }
4823 97 : else if (DECL_C_BIT_FIELD (field) && !DECL_UNNAMED_BIT_FIELD (field))
4824 : {
4825 37 : tree btype = DECL_BIT_FIELD_TYPE (field);
4826 37 : if (!type_has_unique_obj_representations (btype))
4827 : return false;
4828 : }
4829 60 : else if (!type_has_unique_obj_representations (TREE_TYPE (field)))
4830 : return false;
4831 :
4832 63 : offset_int cur = 0;
4833 371 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
4834 323 : if (TREE_CODE (field) == FIELD_DECL && !DECL_UNNAMED_BIT_FIELD (field))
4835 : {
4836 83 : offset_int fld = wi::to_offset (DECL_FIELD_OFFSET (field));
4837 83 : offset_int bitpos = wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
4838 83 : fld = fld * BITS_PER_UNIT + bitpos;
4839 83 : if (cur != fld)
4840 15 : return false;
4841 68 : if (DECL_SIZE (field))
4842 : {
4843 65 : offset_int size = wi::to_offset (DECL_SIZE (field));
4844 65 : cur += size;
4845 : }
4846 : }
4847 48 : if (cur != wi::to_offset (sz))
4848 : return false;
4849 :
4850 : return true;
4851 : }
4852 :
4853 : /* Nonzero iff type T is a class template implicit specialization. */
4854 :
4855 : bool
4856 67320420 : class_tmpl_impl_spec_p (const_tree t)
4857 : {
4858 67320420 : return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
4859 : }
4860 :
4861 : /* Returns 1 iff zero initialization of type T means actually storing
4862 : zeros in it. */
4863 :
4864 : int
4865 10523912 : zero_init_p (const_tree t)
4866 : {
4867 : /* This CONST_CAST is okay because strip_array_types returns its
4868 : argument unmodified and we assign it to a const_tree. */
4869 10523912 : t = strip_array_types (CONST_CAST_TREE(t));
4870 :
4871 10523912 : if (t == error_mark_node)
4872 : return 1;
4873 :
4874 : /* NULL pointers to data members are initialized with -1. */
4875 10523912 : if (TYPE_PTRDATAMEM_P (t))
4876 : return 0;
4877 :
4878 : /* Classes that contain types that can't be zero-initialized, cannot
4879 : be zero-initialized themselves. */
4880 10523359 : if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
4881 125 : return 0;
4882 :
4883 : return 1;
4884 : }
4885 :
4886 : /* Returns true if the expression or initializer T is the result of
4887 : zero-initialization for its type, taking pointers to members
4888 : into consideration. */
4889 :
4890 : bool
4891 5518 : zero_init_expr_p (tree t)
4892 : {
4893 5518 : tree type = TREE_TYPE (t);
4894 5518 : if (!type || uses_template_parms (type))
4895 0 : return false;
4896 5518 : if (TYPE_PTRMEM_P (type))
4897 467 : return null_member_pointer_value_p (t);
4898 5051 : if (TREE_CODE (t) == CONSTRUCTOR)
4899 : {
4900 2984 : if (COMPOUND_LITERAL_P (t)
4901 2984 : || BRACE_ENCLOSED_INITIALIZER_P (t))
4902 : /* Undigested, conversions might change the zeroness. */
4903 : return false;
4904 8134 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (t))
4905 : {
4906 2637 : if (TREE_CODE (type) == UNION_TYPE
4907 2637 : && elt.index != first_field (type))
4908 : return false;
4909 2634 : if (!zero_init_expr_p (elt.value))
4910 : return false;
4911 : }
4912 : return true;
4913 : }
4914 2067 : if (zero_init_p (type))
4915 2067 : return initializer_zerop (t);
4916 : return false;
4917 : }
4918 :
4919 : /* True IFF T is a C++20 structural type (P1907R1) that can be used as a
4920 : non-type template parameter. If EXPLAIN, explain why not. */
4921 :
4922 : bool
4923 1833 : structural_type_p (tree t, bool explain)
4924 : {
4925 : /* A structural type is one of the following: */
4926 :
4927 : /* a scalar type, or */
4928 1833 : if (SCALAR_TYPE_P (t))
4929 : return true;
4930 : /* an lvalue reference type, or */
4931 822 : if (TYPE_REF_P (t) && !TYPE_REF_IS_RVALUE (t))
4932 : return true;
4933 : /* a literal class type with the following properties:
4934 : - all base classes and non-static data members are public and non-mutable
4935 : and
4936 : - the types of all bases classes and non-static data members are
4937 : structural types or (possibly multi-dimensional) array thereof. */
4938 819 : if (!CLASS_TYPE_P (t))
4939 : return false;
4940 817 : if (!literal_type_p (t))
4941 : {
4942 3 : if (explain)
4943 1 : explain_non_literal_class (t);
4944 3 : return false;
4945 : }
4946 1891 : for (tree m = next_aggregate_field (TYPE_FIELDS (t)); m;
4947 1077 : m = next_aggregate_field (DECL_CHAIN (m)))
4948 : {
4949 1080 : if (TREE_PRIVATE (m) || TREE_PROTECTED (m))
4950 : {
4951 3 : if (explain)
4952 : {
4953 1 : if (DECL_FIELD_IS_BASE (m))
4954 1 : inform (location_of (m), "base class %qT is not public",
4955 1 : TREE_TYPE (m));
4956 : else
4957 0 : inform (location_of (m), "%qD is not public", m);
4958 : }
4959 3 : return false;
4960 : }
4961 1077 : if (DECL_MUTABLE_P (m))
4962 : {
4963 0 : if (explain)
4964 0 : inform (location_of (m), "%qD is mutable", m);
4965 0 : return false;
4966 : }
4967 1077 : tree mtype = strip_array_types (TREE_TYPE (m));
4968 1077 : if (!structural_type_p (mtype))
4969 : {
4970 0 : if (explain)
4971 : {
4972 0 : inform (location_of (m), "%qD has a non-structural type", m);
4973 0 : structural_type_p (mtype, true);
4974 : }
4975 0 : return false;
4976 : }
4977 : }
4978 : return true;
4979 : }
4980 :
4981 : /* Partially handle the C++11 [[carries_dependency]] attribute.
4982 : Just emit a different diagnostics when it is used on something the
4983 : spec doesn't allow vs. where it allows and we just choose to ignore
4984 : it. */
4985 :
4986 : static tree
4987 15 : handle_carries_dependency_attribute (tree *node, tree name,
4988 : tree ARG_UNUSED (args),
4989 : int ARG_UNUSED (flags),
4990 : bool *no_add_attrs)
4991 : {
4992 15 : if (TREE_CODE (*node) != FUNCTION_DECL
4993 9 : && TREE_CODE (*node) != PARM_DECL)
4994 : {
4995 3 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
4996 : "functions or parameters", name);
4997 3 : *no_add_attrs = true;
4998 : }
4999 : else
5000 : {
5001 12 : warning (OPT_Wattributes, "%qE attribute ignored", name);
5002 12 : *no_add_attrs = true;
5003 : }
5004 15 : return NULL_TREE;
5005 : }
5006 :
5007 : /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
5008 : warn_unused_result attribute. */
5009 :
5010 : static tree
5011 5844726 : handle_nodiscard_attribute (tree *node, tree name, tree args,
5012 : int /*flags*/, bool *no_add_attrs)
5013 : {
5014 5844743 : if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
5015 : {
5016 1 : error ("%qE attribute argument must be a string constant", name);
5017 1 : *no_add_attrs = true;
5018 : }
5019 5844726 : if (TREE_CODE (*node) == FUNCTION_DECL)
5020 : {
5021 5844627 : if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))
5022 5844641 : && !DECL_CONSTRUCTOR_P (*node))
5023 3 : warning_at (DECL_SOURCE_LOCATION (*node),
5024 : OPT_Wattributes, "%qE attribute applied to %qD with void "
5025 : "return type", name, *node);
5026 : }
5027 99 : else if (OVERLOAD_TYPE_P (*node))
5028 : /* OK */;
5029 : else
5030 : {
5031 3 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5032 : "functions or to class or enumeration types", name);
5033 3 : *no_add_attrs = true;
5034 : }
5035 5844726 : return NULL_TREE;
5036 : }
5037 :
5038 : /* Handle a C++20 "no_unique_address" attribute; arguments as in
5039 : struct attribute_spec.handler. */
5040 : static tree
5041 41883 : handle_no_unique_addr_attribute (tree* node,
5042 : tree name,
5043 : tree /*args*/,
5044 : int /*flags*/,
5045 : bool* no_add_attrs)
5046 : {
5047 41883 : if (TREE_CODE (*node) == VAR_DECL)
5048 : {
5049 8 : DECL_MERGEABLE (*node) = true;
5050 8 : if (pedantic)
5051 2 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5052 : "non-static data members", name);
5053 : }
5054 41875 : else if (TREE_CODE (*node) != FIELD_DECL)
5055 : {
5056 2 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5057 : "non-static data members", name);
5058 2 : *no_add_attrs = true;
5059 : }
5060 41873 : else if (DECL_C_BIT_FIELD (*node))
5061 : {
5062 0 : warning (OPT_Wattributes, "%qE attribute cannot be applied to "
5063 : "a bit-field", name);
5064 0 : *no_add_attrs = true;
5065 : }
5066 :
5067 41883 : return NULL_TREE;
5068 : }
5069 :
5070 : /* The C++20 [[likely]] and [[unlikely]] attributes on labels map to the GNU
5071 : hot/cold attributes. */
5072 :
5073 : static tree
5074 18 : handle_likeliness_attribute (tree *node, tree name, tree args,
5075 : int flags, bool *no_add_attrs)
5076 : {
5077 18 : *no_add_attrs = true;
5078 18 : if (TREE_CODE (*node) == LABEL_DECL
5079 18 : || TREE_CODE (*node) == FUNCTION_DECL)
5080 : {
5081 18 : if (args)
5082 0 : warning (OPT_Wattributes, "%qE attribute takes no arguments", name);
5083 18 : tree bname = (is_attribute_p ("likely", name)
5084 18 : ? get_identifier ("hot") : get_identifier ("cold"));
5085 18 : if (TREE_CODE (*node) == FUNCTION_DECL)
5086 1 : warning (OPT_Wattributes, "ISO C++ %qE attribute does not apply to "
5087 : "functions; treating as %<[[gnu::%E]]%>", name, bname);
5088 18 : tree battr = build_tree_list (bname, NULL_TREE);
5089 18 : decl_attributes (node, battr, flags);
5090 18 : return NULL_TREE;
5091 : }
5092 : else
5093 0 : return error_mark_node;
5094 : }
5095 :
5096 : /* Table of valid C++ attributes. */
5097 : const struct attribute_spec cxx_attribute_table[] =
5098 : {
5099 : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5100 : affects_type_identity, handler, exclude } */
5101 : { "init_priority", 1, 1, true, false, false, false,
5102 : handle_init_priority_attribute, NULL },
5103 : { "abi_tag", 1, -1, false, false, false, true,
5104 : handle_abi_tag_attribute, NULL },
5105 : { NULL, 0, 0, false, false, false, false, NULL, NULL }
5106 : };
5107 :
5108 : /* Table of C++ standard attributes. */
5109 : const struct attribute_spec std_attribute_table[] =
5110 : {
5111 : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5112 : affects_type_identity, handler, exclude } */
5113 : { "maybe_unused", 0, 0, false, false, false, false,
5114 : handle_unused_attribute, NULL },
5115 : { "nodiscard", 0, 1, false, false, false, false,
5116 : handle_nodiscard_attribute, NULL },
5117 : { "no_unique_address", 0, 0, true, false, false, false,
5118 : handle_no_unique_addr_attribute, NULL },
5119 : { "likely", 0, 0, false, false, false, false,
5120 : handle_likeliness_attribute, attr_cold_hot_exclusions },
5121 : { "unlikely", 0, 0, false, false, false, false,
5122 : handle_likeliness_attribute, attr_cold_hot_exclusions },
5123 : { "noreturn", 0, 0, true, false, false, false,
5124 : handle_noreturn_attribute, attr_noreturn_exclusions },
5125 : { "carries_dependency", 0, 0, true, false, false, false,
5126 : handle_carries_dependency_attribute, NULL },
5127 : { "pre", 0, -1, false, false, false, false,
5128 : handle_contract_attribute, NULL },
5129 : { "post", 0, -1, false, false, false, false,
5130 : handle_contract_attribute, NULL },
5131 : { NULL, 0, 0, false, false, false, false, NULL, NULL }
5132 : };
5133 :
5134 : /* Handle an "init_priority" attribute; arguments as in
5135 : struct attribute_spec.handler. */
5136 : static tree
5137 25 : handle_init_priority_attribute (tree* node,
5138 : tree name,
5139 : tree args,
5140 : int /*flags*/,
5141 : bool* no_add_attrs)
5142 : {
5143 25 : if (!SUPPORTS_INIT_PRIORITY)
5144 : /* Treat init_priority as an unrecognized attribute (mirroring
5145 : __has_attribute) if the target doesn't support init priorities. */
5146 : return error_mark_node;
5147 :
5148 25 : tree initp_expr = TREE_VALUE (args);
5149 25 : tree decl = *node;
5150 25 : tree type = TREE_TYPE (decl);
5151 25 : int pri;
5152 :
5153 25 : STRIP_NOPS (initp_expr);
5154 25 : initp_expr = default_conversion (initp_expr);
5155 25 : if (initp_expr)
5156 25 : initp_expr = maybe_constant_value (initp_expr);
5157 :
5158 25 : if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
5159 : {
5160 0 : error ("requested %<init_priority%> is not an integer constant");
5161 0 : cxx_constant_value (initp_expr);
5162 0 : *no_add_attrs = true;
5163 0 : return NULL_TREE;
5164 : }
5165 :
5166 25 : pri = TREE_INT_CST_LOW (initp_expr);
5167 :
5168 25 : type = strip_array_types (type);
5169 :
5170 25 : if (decl == NULL_TREE
5171 : || !VAR_P (decl)
5172 25 : || !TREE_STATIC (decl)
5173 25 : || DECL_EXTERNAL (decl)
5174 25 : || (TREE_CODE (type) != RECORD_TYPE
5175 25 : && TREE_CODE (type) != UNION_TYPE)
5176 : /* Static objects in functions are initialized the
5177 : first time control passes through that
5178 : function. This is not precise enough to pin down an
5179 : init_priority value, so don't allow it. */
5180 50 : || current_function_decl)
5181 : {
5182 0 : error ("can only use %qE attribute on file-scope definitions "
5183 : "of objects of class type", name);
5184 0 : *no_add_attrs = true;
5185 0 : return NULL_TREE;
5186 : }
5187 :
5188 25 : if (pri > MAX_INIT_PRIORITY || pri <= 0)
5189 : {
5190 0 : error ("requested %<init_priority%> %i is out of range [0, %i]",
5191 : pri, MAX_INIT_PRIORITY);
5192 0 : *no_add_attrs = true;
5193 0 : return NULL_TREE;
5194 : }
5195 :
5196 : /* Check for init_priorities that are reserved for
5197 : language and runtime support implementations.*/
5198 25 : if (pri <= MAX_RESERVED_INIT_PRIORITY)
5199 : {
5200 2 : warning
5201 2 : (0, "requested %<init_priority%> %i is reserved for internal use",
5202 : pri);
5203 : }
5204 :
5205 25 : SET_DECL_INIT_PRIORITY (decl, pri);
5206 25 : DECL_HAS_INIT_PRIORITY_P (decl) = 1;
5207 25 : return NULL_TREE;
5208 : }
5209 :
5210 : /* DECL is being redeclared; the old declaration had the abi tags in OLD,
5211 : and the new one has the tags in NEW_. Give an error if there are tags
5212 : in NEW_ that weren't in OLD. */
5213 :
5214 : bool
5215 6999666 : check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_)
5216 : {
5217 7015733 : if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST)
5218 : old = TREE_VALUE (old);
5219 7015548 : if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST)
5220 : new_ = TREE_VALUE (new_);
5221 : bool err = false;
5222 7015548 : for (const_tree t = new_; t; t = TREE_CHAIN (t))
5223 : {
5224 15882 : tree str = TREE_VALUE (t);
5225 15882 : for (const_tree in = old; in; in = TREE_CHAIN (in))
5226 : {
5227 15874 : tree ostr = TREE_VALUE (in);
5228 15874 : if (cp_tree_equal (str, ostr))
5229 15874 : goto found;
5230 : }
5231 8 : error ("redeclaration of %qD adds abi tag %qE", decl, str);
5232 8 : err = true;
5233 15882 : found:;
5234 : }
5235 6999666 : if (err)
5236 : {
5237 8 : inform (DECL_SOURCE_LOCATION (decl), "previous declaration here");
5238 8 : return false;
5239 : }
5240 : return true;
5241 : }
5242 :
5243 : /* The abi_tag attribute with the name NAME was given ARGS. If they are
5244 : ill-formed, give an error and return false; otherwise, return true. */
5245 :
5246 : bool
5247 266443 : check_abi_tag_args (tree args, tree name)
5248 : {
5249 266443 : if (!args)
5250 : {
5251 0 : error ("the %qE attribute requires arguments", name);
5252 0 : return false;
5253 : }
5254 532882 : for (tree arg = args; arg; arg = TREE_CHAIN (arg))
5255 : {
5256 266455 : tree elt = TREE_VALUE (arg);
5257 266455 : if (TREE_CODE (elt) != STRING_CST
5258 532902 : || (!same_type_ignoring_top_level_qualifiers_p
5259 266447 : (strip_array_types (TREE_TYPE (elt)),
5260 : char_type_node)))
5261 : {
5262 12 : error ("arguments to the %qE attribute must be narrow string "
5263 : "literals", name);
5264 12 : return false;
5265 : }
5266 266443 : const char *begin = TREE_STRING_POINTER (elt);
5267 266443 : const char *end = begin + TREE_STRING_LENGTH (elt);
5268 1865089 : for (const char *p = begin; p != end; ++p)
5269 : {
5270 1598650 : char c = *p;
5271 1598650 : if (p == begin)
5272 : {
5273 266443 : if (!ISALPHA (c) && c != '_')
5274 : {
5275 4 : error ("arguments to the %qE attribute must contain valid "
5276 : "identifiers", name);
5277 4 : inform (input_location, "%<%c%> is not a valid first "
5278 : "character for an identifier", c);
5279 4 : return false;
5280 : }
5281 : }
5282 1332207 : else if (p == end - 1)
5283 266439 : gcc_assert (c == 0);
5284 : else
5285 : {
5286 1065768 : if (!ISALNUM (c) && c != '_')
5287 : {
5288 0 : error ("arguments to the %qE attribute must contain valid "
5289 : "identifiers", name);
5290 0 : inform (input_location, "%<%c%> is not a valid character "
5291 : "in an identifier", c);
5292 0 : return false;
5293 : }
5294 : }
5295 : }
5296 : }
5297 : return true;
5298 : }
5299 :
5300 : /* Handle an "abi_tag" attribute; arguments as in
5301 : struct attribute_spec.handler. */
5302 :
5303 : static tree
5304 230868 : handle_abi_tag_attribute (tree* node, tree name, tree args,
5305 : int flags, bool* no_add_attrs)
5306 : {
5307 230868 : if (!check_abi_tag_args (args, name))
5308 16 : goto fail;
5309 :
5310 230852 : if (TYPE_P (*node))
5311 : {
5312 8244 : if (!OVERLOAD_TYPE_P (*node))
5313 : {
5314 0 : error ("%qE attribute applied to non-class, non-enum type %qT",
5315 : name, *node);
5316 0 : goto fail;
5317 : }
5318 8244 : else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE))
5319 : {
5320 0 : error ("%qE attribute applied to %qT after its definition",
5321 : name, *node);
5322 0 : goto fail;
5323 : }
5324 8240 : else if (CLASS_TYPE_P (*node)
5325 16484 : && CLASSTYPE_TEMPLATE_INSTANTIATION (*node))
5326 : {
5327 4 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5328 : "template instantiation %qT", name, *node);
5329 4 : goto fail;
5330 : }
5331 8236 : else if (CLASS_TYPE_P (*node)
5332 16476 : && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node))
5333 : {
5334 4 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5335 : "template specialization %qT", name, *node);
5336 4 : goto fail;
5337 : }
5338 :
5339 8236 : tree attributes = TYPE_ATTRIBUTES (*node);
5340 8236 : tree decl = TYPE_NAME (*node);
5341 :
5342 : /* Make sure all declarations have the same abi tags. */
5343 8236 : if (DECL_SOURCE_LOCATION (decl) != input_location)
5344 : {
5345 4 : if (!check_abi_tag_redeclaration (decl,
5346 4 : lookup_attribute ("abi_tag",
5347 : attributes),
5348 : args))
5349 4 : goto fail;
5350 : }
5351 : }
5352 : else
5353 : {
5354 222608 : if (!VAR_OR_FUNCTION_DECL_P (*node))
5355 : {
5356 0 : error ("%qE attribute applied to non-function, non-variable %qD",
5357 : name, *node);
5358 0 : goto fail;
5359 : }
5360 222608 : else if (DECL_LANGUAGE (*node) == lang_c)
5361 : {
5362 0 : error ("%qE attribute applied to extern \"C\" declaration %qD",
5363 : name, *node);
5364 0 : goto fail;
5365 : }
5366 : }
5367 :
5368 : return NULL_TREE;
5369 :
5370 28 : fail:
5371 28 : *no_add_attrs = true;
5372 28 : return NULL_TREE;
5373 : }
5374 :
5375 : /* Perform checking for contract attributes. */
5376 :
5377 : tree
5378 660 : handle_contract_attribute (tree *ARG_UNUSED (node), tree ARG_UNUSED (name),
5379 : tree ARG_UNUSED (args), int ARG_UNUSED (flags),
5380 : bool *ARG_UNUSED (no_add_attrs))
5381 : {
5382 : /* TODO: Is there any checking we could do here? */
5383 660 : return NULL_TREE;
5384 : }
5385 :
5386 : /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
5387 : thing pointed to by the constant. */
5388 :
5389 : tree
5390 48054 : make_ptrmem_cst (tree type, tree member)
5391 : {
5392 48054 : tree ptrmem_cst = make_node (PTRMEM_CST);
5393 48054 : TREE_TYPE (ptrmem_cst) = type;
5394 48054 : PTRMEM_CST_MEMBER (ptrmem_cst) = member;
5395 48054 : PTRMEM_CST_LOCATION (ptrmem_cst) = input_location;
5396 48054 : return ptrmem_cst;
5397 : }
5398 :
5399 : /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
5400 : return an existing type if an appropriate type already exists. */
5401 :
5402 : tree
5403 106788970 : cp_build_type_attribute_variant (tree type, tree attributes)
5404 : {
5405 106788970 : tree new_type;
5406 :
5407 106788970 : new_type = build_type_attribute_variant (type, attributes);
5408 106788970 : if (FUNC_OR_METHOD_TYPE_P (new_type))
5409 106728700 : gcc_checking_assert (cxx_type_hash_eq (type, new_type));
5410 :
5411 : /* Making a new main variant of a class type is broken. */
5412 106788970 : gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
5413 :
5414 106788970 : return new_type;
5415 : }
5416 :
5417 : /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
5418 : Called only after doing all language independent checks. */
5419 :
5420 : bool
5421 360174841 : cxx_type_hash_eq (const_tree typea, const_tree typeb)
5422 : {
5423 360174841 : gcc_assert (FUNC_OR_METHOD_TYPE_P (typea));
5424 :
5425 360174841 : if (type_memfn_rqual (typea) != type_memfn_rqual (typeb))
5426 : return false;
5427 360174311 : if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb))
5428 : return false;
5429 360174037 : return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
5430 720348074 : TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
5431 : }
5432 :
5433 : /* Copy the language-specific type variant modifiers from TYPEB to TYPEA. For
5434 : C++, these are the exception-specifier and ref-qualifier. */
5435 :
5436 : tree
5437 33435416 : cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
5438 : {
5439 33435416 : tree type = CONST_CAST_TREE (typea);
5440 33435416 : if (FUNC_OR_METHOD_TYPE_P (type))
5441 33434630 : type = build_cp_fntype_variant (type, type_memfn_rqual (typeb),
5442 33434630 : TYPE_RAISES_EXCEPTIONS (typeb),
5443 33434630 : TYPE_HAS_LATE_RETURN_TYPE (typeb));
5444 33435416 : return type;
5445 : }
5446 :
5447 : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
5448 : traversal. Called from walk_tree. */
5449 :
5450 : tree
5451 8628244376 : cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
5452 : void *data, hash_set<tree> *pset)
5453 : {
5454 8628244376 : tree t = *tp;
5455 8628244376 : enum tree_code code = TREE_CODE (t);
5456 8628244376 : tree result;
5457 :
5458 : #define WALK_SUBTREE(NODE) \
5459 : do \
5460 : { \
5461 : result = cp_walk_tree (&(NODE), func, data, pset); \
5462 : if (result) goto out; \
5463 : } \
5464 : while (0)
5465 :
5466 8628244376 : if (TYPE_P (t))
5467 : {
5468 : /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
5469 : the argument, so don't look through typedefs, but do walk into
5470 : template arguments for alias templates (and non-typedefed classes).
5471 :
5472 : If *WALK_SUBTREES_P > 1, we're interested in type identity or
5473 : equivalence, so look through typedefs, ignoring template arguments for
5474 : alias templates, and walk into template args of classes.
5475 :
5476 : See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
5477 : when that's the behavior the walk_tree_fn wants. */
5478 3345181814 : if (*walk_subtrees_p == 1 && typedef_variant_p (t))
5479 : {
5480 3448873 : if (tree ti = TYPE_ALIAS_TEMPLATE_INFO (t))
5481 2851690 : WALK_SUBTREE (TI_ARGS (ti));
5482 3357197 : *walk_subtrees_p = 0;
5483 3357197 : return NULL_TREE;
5484 : }
5485 :
5486 3341732941 : if (tree ti = TYPE_TEMPLATE_INFO (t))
5487 330766018 : WALK_SUBTREE (TI_ARGS (ti));
5488 : }
5489 :
5490 : /* Not one of the easy cases. We must explicitly go through the
5491 : children. */
5492 8624726084 : result = NULL_TREE;
5493 8624726084 : switch (code)
5494 : {
5495 1011673200 : case TEMPLATE_TYPE_PARM:
5496 1011673200 : if (template_placeholder_p (t))
5497 21583 : WALK_SUBTREE (CLASS_PLACEHOLDER_TEMPLATE (t));
5498 : /* Fall through. */
5499 1100633278 : case DEFERRED_PARSE:
5500 1100633278 : case TEMPLATE_TEMPLATE_PARM:
5501 1100633278 : case BOUND_TEMPLATE_TEMPLATE_PARM:
5502 1100633278 : case UNBOUND_CLASS_TEMPLATE:
5503 1100633278 : case TEMPLATE_PARM_INDEX:
5504 1100633278 : case TYPEOF_TYPE:
5505 : /* None of these have subtrees other than those already walked
5506 : above. */
5507 1100633278 : *walk_subtrees_p = 0;
5508 1100633278 : break;
5509 :
5510 89474041 : case TYPENAME_TYPE:
5511 89474041 : WALK_SUBTREE (TYPE_CONTEXT (t));
5512 89452030 : WALK_SUBTREE (TYPENAME_TYPE_FULLNAME (t));
5513 89451986 : *walk_subtrees_p = 0;
5514 89451986 : break;
5515 :
5516 45608057 : case BASELINK:
5517 45608057 : if (BASELINK_QUALIFIED_P (t))
5518 5001162 : WALK_SUBTREE (BINFO_TYPE (BASELINK_ACCESS_BINFO (t)));
5519 45608057 : WALK_SUBTREE (BASELINK_FUNCTIONS (t));
5520 45599492 : *walk_subtrees_p = 0;
5521 45599492 : break;
5522 :
5523 28269 : case PTRMEM_CST:
5524 28269 : WALK_SUBTREE (TREE_TYPE (t));
5525 28269 : *walk_subtrees_p = 0;
5526 28269 : break;
5527 :
5528 129926583 : case TREE_LIST:
5529 129926583 : WALK_SUBTREE (TREE_PURPOSE (t));
5530 : break;
5531 :
5532 150407224 : case OVERLOAD:
5533 150407224 : WALK_SUBTREE (OVL_FUNCTION (t));
5534 150407221 : WALK_SUBTREE (OVL_CHAIN (t));
5535 150407221 : *walk_subtrees_p = 0;
5536 150407221 : break;
5537 :
5538 1770843 : case USING_DECL:
5539 1770843 : WALK_SUBTREE (DECL_NAME (t));
5540 1770843 : WALK_SUBTREE (USING_DECL_SCOPE (t));
5541 1770843 : WALK_SUBTREE (USING_DECL_DECLS (t));
5542 1770843 : *walk_subtrees_p = 0;
5543 1770843 : break;
5544 :
5545 379176105 : case RECORD_TYPE:
5546 379176105 : if (TYPE_PTRMEMFUNC_P (t))
5547 4562080 : WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (t));
5548 : break;
5549 :
5550 73900638 : case TYPE_ARGUMENT_PACK:
5551 73900638 : case NONTYPE_ARGUMENT_PACK:
5552 73900638 : {
5553 73900638 : tree args = ARGUMENT_PACK_ARGS (t);
5554 201654171 : for (tree arg : tree_vec_range (args))
5555 128031843 : WALK_SUBTREE (arg);
5556 : }
5557 73622328 : break;
5558 :
5559 18108555 : case TYPE_PACK_EXPANSION:
5560 18108555 : WALK_SUBTREE (TREE_TYPE (t));
5561 18108336 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
5562 18108336 : *walk_subtrees_p = 0;
5563 18108336 : break;
5564 :
5565 2522480 : case EXPR_PACK_EXPANSION:
5566 2522480 : WALK_SUBTREE (TREE_OPERAND (t, 0));
5567 2522463 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
5568 2522463 : *walk_subtrees_p = 0;
5569 2522463 : break;
5570 :
5571 44764545 : case CAST_EXPR:
5572 44764545 : case REINTERPRET_CAST_EXPR:
5573 44764545 : case STATIC_CAST_EXPR:
5574 44764545 : case CONST_CAST_EXPR:
5575 44764545 : case DYNAMIC_CAST_EXPR:
5576 44764545 : case IMPLICIT_CONV_EXPR:
5577 44764545 : case BIT_CAST_EXPR:
5578 44764545 : if (TREE_TYPE (t))
5579 44764545 : WALK_SUBTREE (TREE_TYPE (t));
5580 : break;
5581 :
5582 25807106 : case CONSTRUCTOR:
5583 25807106 : if (COMPOUND_LITERAL_P (t))
5584 2508160 : WALK_SUBTREE (TREE_TYPE (t));
5585 : break;
5586 :
5587 10104907 : case TRAIT_EXPR:
5588 10104907 : WALK_SUBTREE (TRAIT_EXPR_TYPE1 (t));
5589 10104903 : WALK_SUBTREE (TRAIT_EXPR_TYPE2 (t));
5590 10104903 : *walk_subtrees_p = 0;
5591 10104903 : break;
5592 :
5593 45972 : case TRAIT_TYPE:
5594 45972 : WALK_SUBTREE (TRAIT_TYPE_TYPE1 (t));
5595 45972 : WALK_SUBTREE (TRAIT_TYPE_TYPE2 (t));
5596 45972 : *walk_subtrees_p = 0;
5597 45972 : break;
5598 :
5599 3364204 : case DECLTYPE_TYPE:
5600 3364204 : {
5601 3364204 : cp_unevaluated u;
5602 3364204 : WALK_SUBTREE (DECLTYPE_TYPE_EXPR (t));
5603 3337347 : *walk_subtrees_p = 0;
5604 3337347 : break;
5605 3364204 : }
5606 :
5607 12159999 : case ALIGNOF_EXPR:
5608 12159999 : case SIZEOF_EXPR:
5609 12159999 : case NOEXCEPT_EXPR:
5610 12159999 : {
5611 12159999 : cp_unevaluated u;
5612 12159999 : WALK_SUBTREE (TREE_OPERAND (t, 0));
5613 9712376 : *walk_subtrees_p = 0;
5614 9712376 : break;
5615 12159999 : }
5616 :
5617 508947 : case REQUIRES_EXPR:
5618 508947 : {
5619 508947 : cp_unevaluated u;
5620 869484 : for (tree parm = REQUIRES_EXPR_PARMS (t); parm; parm = DECL_CHAIN (parm))
5621 : /* Walk the types of each parameter, but not the parameter itself,
5622 : since doing so would cause false positives in the unexpanded pack
5623 : checker if the requires-expr introduces a function parameter pack,
5624 : e.g. requires (Ts... ts) { }. */
5625 360537 : WALK_SUBTREE (TREE_TYPE (parm));
5626 508947 : WALK_SUBTREE (REQUIRES_EXPR_REQS (t));
5627 508773 : *walk_subtrees_p = 0;
5628 508773 : break;
5629 508947 : }
5630 :
5631 31012650 : case DECL_EXPR:
5632 : /* User variables should be mentioned in BIND_EXPR_VARS
5633 : and their initializers and sizes walked when walking
5634 : the containing BIND_EXPR. Compiler temporaries are
5635 : handled here. And also normal variables in templates,
5636 : since do_poplevel doesn't build a BIND_EXPR then. */
5637 31012650 : if (VAR_P (TREE_OPERAND (t, 0))
5638 31012650 : && (processing_template_decl
5639 29270495 : || (DECL_ARTIFICIAL (TREE_OPERAND (t, 0))
5640 835256 : && !TREE_STATIC (TREE_OPERAND (t, 0)))))
5641 : {
5642 2118183 : tree decl = TREE_OPERAND (t, 0);
5643 2118183 : WALK_SUBTREE (DECL_INITIAL (decl));
5644 2118143 : WALK_SUBTREE (DECL_SIZE (decl));
5645 2118143 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
5646 : }
5647 : break;
5648 :
5649 316132 : case LAMBDA_EXPR:
5650 : /* Don't walk into the body of the lambda, but the capture initializers
5651 : are part of the enclosing context. */
5652 711854 : for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (t); cap;
5653 395722 : cap = TREE_CHAIN (cap))
5654 395722 : WALK_SUBTREE (TREE_VALUE (cap));
5655 : break;
5656 :
5657 446 : case CO_YIELD_EXPR:
5658 446 : if (TREE_OPERAND (t, 1))
5659 : /* Operand 1 is the tree for the relevant co_await which has any
5660 : interesting sub-trees. */
5661 386 : WALK_SUBTREE (TREE_OPERAND (t, 1));
5662 : break;
5663 :
5664 20666 : case CO_AWAIT_EXPR:
5665 20666 : if (TREE_OPERAND (t, 1))
5666 : /* Operand 1 is frame variable. */
5667 20520 : WALK_SUBTREE (TREE_OPERAND (t, 1));
5668 20666 : if (TREE_OPERAND (t, 2))
5669 : /* Operand 2 has the initialiser, and we need to walk any subtrees
5670 : there. */
5671 4186 : WALK_SUBTREE (TREE_OPERAND (t, 2));
5672 : break;
5673 :
5674 811 : case CO_RETURN_EXPR:
5675 811 : if (TREE_OPERAND (t, 0))
5676 : {
5677 723 : if (VOID_TYPE_P (TREE_OPERAND (t, 0)))
5678 : /* For void expressions, operand 1 is a trivial call, and any
5679 : interesting subtrees will be part of operand 0. */
5680 0 : WALK_SUBTREE (TREE_OPERAND (t, 0));
5681 723 : else if (TREE_OPERAND (t, 1))
5682 : /* Interesting sub-trees will be in the return_value () call
5683 : arguments. */
5684 675 : WALK_SUBTREE (TREE_OPERAND (t, 1));
5685 : }
5686 : break;
5687 :
5688 141803 : case STATIC_ASSERT:
5689 141803 : WALK_SUBTREE (STATIC_ASSERT_CONDITION (t));
5690 141803 : WALK_SUBTREE (STATIC_ASSERT_MESSAGE (t));
5691 : break;
5692 :
5693 : default:
5694 : return NULL_TREE;
5695 : }
5696 :
5697 : /* We didn't find what we were looking for. */
5698 : out:
5699 : return result;
5700 :
5701 : #undef WALK_SUBTREE
5702 : }
5703 :
5704 : /* Like save_expr, but for C++. */
5705 :
5706 : tree
5707 83528 : cp_save_expr (tree expr)
5708 : {
5709 : /* There is no reason to create a SAVE_EXPR within a template; if
5710 : needed, we can create the SAVE_EXPR when instantiating the
5711 : template. Furthermore, the middle-end cannot handle C++-specific
5712 : tree codes. */
5713 83528 : if (processing_template_decl)
5714 : return expr;
5715 :
5716 : /* TARGET_EXPRs are only expanded once. */
5717 29891 : if (TREE_CODE (expr) == TARGET_EXPR)
5718 : return expr;
5719 :
5720 29891 : return save_expr (expr);
5721 : }
5722 :
5723 : /* Initialize tree.cc. */
5724 :
5725 : void
5726 89260 : init_tree (void)
5727 : {
5728 89260 : list_hash_table = hash_table<list_hasher>::create_ggc (61);
5729 89260 : register_scoped_attributes (std_attribute_table, NULL);
5730 89260 : }
5731 :
5732 : /* Returns the kind of special function that DECL (a FUNCTION_DECL)
5733 : is. Note that sfk_none is zero, so this function can be used as a
5734 : predicate to test whether or not DECL is a special function. */
5735 :
5736 : special_function_kind
5737 78657001 : special_function_p (const_tree decl)
5738 : {
5739 : /* Rather than doing all this stuff with magic names, we should
5740 : probably have a field of type `special_function_kind' in
5741 : DECL_LANG_SPECIFIC. */
5742 157314002 : if (DECL_INHERITED_CTOR (decl))
5743 : return sfk_inheriting_constructor;
5744 156991430 : if (DECL_COPY_CONSTRUCTOR_P (decl))
5745 : return sfk_copy_constructor;
5746 144976674 : if (DECL_MOVE_CONSTRUCTOR_P (decl))
5747 : return sfk_move_constructor;
5748 136017390 : if (DECL_CONSTRUCTOR_P (decl))
5749 : return sfk_constructor;
5750 60411875 : if (DECL_ASSIGNMENT_OPERATOR_P (decl)
5751 60411875 : && DECL_OVERLOADED_OPERATOR_IS (decl, NOP_EXPR))
5752 : {
5753 4255161 : if (copy_fn_p (decl))
5754 : return sfk_copy_assignment;
5755 1590053 : if (move_fn_p (decl))
5756 : return sfk_move_assignment;
5757 : }
5758 56307769 : if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
5759 : return sfk_destructor;
5760 32598834 : if (DECL_COMPLETE_DESTRUCTOR_P (decl))
5761 : return sfk_complete_destructor;
5762 23459760 : if (DECL_BASE_DESTRUCTOR_P (decl))
5763 : return sfk_base_destructor;
5764 22853884 : if (DECL_DELETING_DESTRUCTOR_P (decl))
5765 : return sfk_deleting_destructor;
5766 14825717 : if (DECL_CONV_FN_P (decl))
5767 : return sfk_conversion;
5768 14824977 : if (deduction_guide_p (decl))
5769 : return sfk_deduction_guide;
5770 14822485 : if (DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) >= OVL_OP_EQ_EXPR
5771 14822485 : && DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) <= OVL_OP_SPACESHIP_EXPR)
5772 311999 : return sfk_comparison;
5773 :
5774 : return sfk_none;
5775 : }
5776 :
5777 : /* As above, but only if DECL is a special member function as per 11.3.3
5778 : [special]: default/copy/move ctor, copy/move assignment, or destructor. */
5779 :
5780 : special_function_kind
5781 13269 : special_memfn_p (const_tree decl)
5782 : {
5783 13269 : switch (special_function_kind sfk = special_function_p (decl))
5784 : {
5785 8787 : case sfk_constructor:
5786 8787 : if (!default_ctor_p (decl))
5787 : break;
5788 : gcc_fallthrough();
5789 : case sfk_copy_constructor:
5790 : case sfk_copy_assignment:
5791 : case sfk_move_assignment:
5792 : case sfk_move_constructor:
5793 : case sfk_destructor:
5794 : return sfk;
5795 :
5796 : default:
5797 : break;
5798 : }
5799 : return sfk_none;
5800 : }
5801 :
5802 : /* Returns nonzero if TYPE is a character type, including wchar_t. */
5803 :
5804 : int
5805 5758622 : char_type_p (tree type)
5806 : {
5807 5758622 : return (same_type_p (type, char_type_node)
5808 5040464 : || same_type_p (type, unsigned_char_type_node)
5809 5005256 : || same_type_p (type, signed_char_type_node)
5810 5004989 : || same_type_p (type, char8_type_node)
5811 5004939 : || same_type_p (type, char16_type_node)
5812 5004559 : || same_type_p (type, char32_type_node)
5813 10762858 : || same_type_p (type, wchar_type_node));
5814 : }
5815 :
5816 : /* Returns the kind of linkage associated with the indicated DECL. Th
5817 : value returned is as specified by the language standard; it is
5818 : independent of implementation details regarding template
5819 : instantiation, etc. For example, it is possible that a declaration
5820 : to which this function assigns external linkage would not show up
5821 : as a global symbol when you run `nm' on the resulting object file. */
5822 :
5823 : linkage_kind
5824 313251802 : decl_linkage (tree decl)
5825 : {
5826 : /* This function doesn't attempt to calculate the linkage from first
5827 : principles as given in [basic.link]. Instead, it makes use of
5828 : the fact that we have already set TREE_PUBLIC appropriately, and
5829 : then handles a few special cases. Ideally, we would calculate
5830 : linkage first, and then transform that into a concrete
5831 : implementation. */
5832 :
5833 : /* Things that don't have names have no linkage. */
5834 313251845 : if (!DECL_NAME (decl))
5835 : return lk_none;
5836 :
5837 : /* Fields have no linkage. */
5838 310670560 : if (TREE_CODE (decl) == FIELD_DECL)
5839 : return lk_none;
5840 :
5841 : /* Things in local scope do not have linkage. */
5842 310670556 : if (decl_function_context (decl))
5843 : return lk_none;
5844 :
5845 : /* Things that are TREE_PUBLIC have external linkage. */
5846 309523953 : if (TREE_PUBLIC (decl))
5847 : return lk_external;
5848 :
5849 : /* maybe_thunk_body clears TREE_PUBLIC on the maybe-in-charge 'tor variants,
5850 : check one of the "clones" for the real linkage. */
5851 171736382 : if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl)
5852 1300 : && DECL_CHAIN (decl)
5853 85868790 : && DECL_CLONED_FUNCTION_P (DECL_CHAIN (decl)))
5854 43 : return decl_linkage (DECL_CHAIN (decl));
5855 :
5856 85868704 : if (TREE_CODE (decl) == NAMESPACE_DECL)
5857 : return lk_external;
5858 :
5859 : /* Linkage of a CONST_DECL depends on the linkage of the enumeration
5860 : type. */
5861 85690172 : if (TREE_CODE (decl) == CONST_DECL)
5862 0 : return decl_linkage (TYPE_NAME (DECL_CONTEXT (decl)));
5863 :
5864 : /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
5865 : are considered to have external linkage for language purposes, as do
5866 : template instantiations on targets without weak symbols. DECLs really
5867 : meant to have internal linkage have DECL_THIS_STATIC set. */
5868 85690172 : if (TREE_CODE (decl) == TYPE_DECL)
5869 : return lk_external;
5870 85009351 : if (VAR_OR_FUNCTION_DECL_P (decl))
5871 : {
5872 52994857 : if (!DECL_THIS_STATIC (decl))
5873 : return lk_external;
5874 :
5875 : /* Static data members and static member functions from classes
5876 : in anonymous namespace also don't have TREE_PUBLIC set. */
5877 297854 : if (DECL_CLASS_CONTEXT (decl))
5878 6593 : return lk_external;
5879 : }
5880 :
5881 : /* Everything else has internal linkage. */
5882 : return lk_internal;
5883 : }
5884 :
5885 : /* Returns the storage duration of the object or reference associated with
5886 : the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
5887 :
5888 : duration_kind
5889 25164376 : decl_storage_duration (tree decl)
5890 : {
5891 25164376 : if (TREE_CODE (decl) == PARM_DECL)
5892 : return dk_auto;
5893 25164376 : if (TREE_CODE (decl) == FUNCTION_DECL)
5894 : return dk_static;
5895 25164376 : gcc_assert (VAR_P (decl));
5896 25164376 : if (!TREE_STATIC (decl)
5897 25164376 : && !DECL_EXTERNAL (decl))
5898 : return dk_auto;
5899 11040713 : if (CP_DECL_THREAD_LOCAL_P (decl))
5900 15203 : return dk_thread;
5901 : return dk_static;
5902 : }
5903 :
5904 : /* EXP is an expression that we want to pre-evaluate. Returns (in
5905 : *INITP) an expression that will perform the pre-evaluation. The
5906 : value returned by this function is a side-effect free expression
5907 : equivalent to the pre-evaluated expression. Callers must ensure
5908 : that *INITP is evaluated before EXP. */
5909 :
5910 : tree
5911 2891063 : stabilize_expr (tree exp, tree* initp)
5912 : {
5913 2891063 : tree init_expr;
5914 :
5915 2891063 : if (!TREE_SIDE_EFFECTS (exp))
5916 : init_expr = NULL_TREE;
5917 236531 : else if (VOID_TYPE_P (TREE_TYPE (exp)))
5918 : {
5919 0 : init_expr = exp;
5920 0 : exp = void_node;
5921 : }
5922 : /* There are no expressions with REFERENCE_TYPE, but there can be call
5923 : arguments with such a type; just treat it as a pointer. */
5924 236531 : else if (TYPE_REF_P (TREE_TYPE (exp))
5925 236564 : || SCALAR_TYPE_P (TREE_TYPE (exp))
5926 236564 : || !glvalue_p (exp))
5927 : {
5928 236531 : init_expr = get_target_expr (exp);
5929 236531 : exp = TARGET_EXPR_SLOT (init_expr);
5930 236531 : if (CLASS_TYPE_P (TREE_TYPE (exp)))
5931 9 : exp = move (exp);
5932 : else
5933 236522 : exp = rvalue (exp);
5934 : }
5935 : else
5936 : {
5937 0 : bool xval = !lvalue_p (exp);
5938 0 : exp = cp_build_addr_expr (exp, tf_warning_or_error);
5939 0 : init_expr = get_target_expr (exp);
5940 0 : exp = TARGET_EXPR_SLOT (init_expr);
5941 0 : exp = cp_build_fold_indirect_ref (exp);
5942 0 : if (xval)
5943 0 : exp = move (exp);
5944 : }
5945 2891063 : *initp = init_expr;
5946 :
5947 2891063 : gcc_assert (!TREE_SIDE_EFFECTS (exp));
5948 2891063 : return exp;
5949 : }
5950 :
5951 : /* Add NEW_EXPR, an expression whose value we don't care about, after the
5952 : similar expression ORIG. */
5953 :
5954 : tree
5955 206755 : add_stmt_to_compound (tree orig, tree new_expr)
5956 : {
5957 206755 : if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
5958 : return orig;
5959 106594 : if (!orig || !TREE_SIDE_EFFECTS (orig))
5960 : return new_expr;
5961 10199 : return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
5962 : }
5963 :
5964 : /* Like stabilize_expr, but for a call whose arguments we want to
5965 : pre-evaluate. CALL is modified in place to use the pre-evaluated
5966 : arguments, while, upon return, *INITP contains an expression to
5967 : compute the arguments. */
5968 :
5969 : void
5970 97109 : stabilize_call (tree call, tree *initp)
5971 : {
5972 97109 : tree inits = NULL_TREE;
5973 97109 : int i;
5974 97109 : int nargs = call_expr_nargs (call);
5975 :
5976 97109 : if (call == error_mark_node || processing_template_decl)
5977 : {
5978 15 : *initp = NULL_TREE;
5979 15 : return;
5980 : }
5981 :
5982 97094 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
5983 :
5984 291350 : for (i = 0; i < nargs; i++)
5985 : {
5986 194256 : tree init;
5987 194256 : CALL_EXPR_ARG (call, i) =
5988 194256 : stabilize_expr (CALL_EXPR_ARG (call, i), &init);
5989 194256 : inits = add_stmt_to_compound (inits, init);
5990 : }
5991 :
5992 97094 : *initp = inits;
5993 : }
5994 :
5995 : /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
5996 : to pre-evaluate. CALL is modified in place to use the pre-evaluated
5997 : arguments, while, upon return, *INITP contains an expression to
5998 : compute the arguments. */
5999 :
6000 : static void
6001 0 : stabilize_aggr_init (tree call, tree *initp)
6002 : {
6003 0 : tree inits = NULL_TREE;
6004 0 : int i;
6005 0 : int nargs = aggr_init_expr_nargs (call);
6006 :
6007 0 : if (call == error_mark_node)
6008 : return;
6009 :
6010 0 : gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
6011 :
6012 0 : for (i = 0; i < nargs; i++)
6013 : {
6014 0 : tree init;
6015 0 : AGGR_INIT_EXPR_ARG (call, i) =
6016 0 : stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
6017 0 : inits = add_stmt_to_compound (inits, init);
6018 : }
6019 :
6020 0 : *initp = inits;
6021 : }
6022 :
6023 : /* Like stabilize_expr, but for an initialization.
6024 :
6025 : If the initialization is for an object of class type, this function
6026 : takes care not to introduce additional temporaries.
6027 :
6028 : Returns TRUE iff the expression was successfully pre-evaluated,
6029 : i.e., if INIT is now side-effect free, except for, possibly, a
6030 : single call to a constructor. */
6031 :
6032 : bool
6033 0 : stabilize_init (tree init, tree *initp)
6034 : {
6035 0 : tree t = init;
6036 :
6037 0 : *initp = NULL_TREE;
6038 :
6039 0 : if (t == error_mark_node || processing_template_decl)
6040 : return true;
6041 :
6042 0 : if (TREE_CODE (t) == INIT_EXPR)
6043 0 : t = TREE_OPERAND (t, 1);
6044 0 : if (TREE_CODE (t) == TARGET_EXPR)
6045 0 : t = TARGET_EXPR_INITIAL (t);
6046 :
6047 : /* If the RHS can be stabilized without breaking copy elision, stabilize
6048 : it. We specifically don't stabilize class prvalues here because that
6049 : would mean an extra copy, but they might be stabilized below. */
6050 0 : if (TREE_CODE (init) == INIT_EXPR
6051 0 : && TREE_CODE (t) != CONSTRUCTOR
6052 0 : && TREE_CODE (t) != AGGR_INIT_EXPR
6053 0 : && (SCALAR_TYPE_P (TREE_TYPE (t))
6054 0 : || glvalue_p (t)))
6055 : {
6056 0 : TREE_OPERAND (init, 1) = stabilize_expr (t, initp);
6057 0 : return true;
6058 : }
6059 :
6060 0 : if (TREE_CODE (t) == COMPOUND_EXPR
6061 0 : && TREE_CODE (init) == INIT_EXPR)
6062 : {
6063 0 : tree last = expr_last (t);
6064 : /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */
6065 0 : if (!TREE_SIDE_EFFECTS (last))
6066 : {
6067 0 : *initp = t;
6068 0 : TREE_OPERAND (init, 1) = last;
6069 0 : return true;
6070 : }
6071 : }
6072 :
6073 0 : if (TREE_CODE (t) == CONSTRUCTOR)
6074 : {
6075 : /* Aggregate initialization: stabilize each of the field
6076 : initializers. */
6077 0 : unsigned i;
6078 0 : constructor_elt *ce;
6079 0 : bool good = true;
6080 0 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
6081 0 : for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
6082 : {
6083 0 : tree type = TREE_TYPE (ce->value);
6084 0 : tree subinit;
6085 0 : if (TYPE_REF_P (type)
6086 0 : || SCALAR_TYPE_P (type))
6087 0 : ce->value = stabilize_expr (ce->value, &subinit);
6088 0 : else if (!stabilize_init (ce->value, &subinit))
6089 0 : good = false;
6090 0 : *initp = add_stmt_to_compound (*initp, subinit);
6091 : }
6092 0 : return good;
6093 : }
6094 :
6095 0 : if (TREE_CODE (t) == CALL_EXPR)
6096 : {
6097 0 : stabilize_call (t, initp);
6098 0 : return true;
6099 : }
6100 :
6101 0 : if (TREE_CODE (t) == AGGR_INIT_EXPR)
6102 : {
6103 0 : stabilize_aggr_init (t, initp);
6104 0 : return true;
6105 : }
6106 :
6107 : /* The initialization is being performed via a bitwise copy -- and
6108 : the item copied may have side effects. */
6109 0 : return !TREE_SIDE_EFFECTS (init);
6110 : }
6111 :
6112 : /* Returns true if a cast to TYPE may appear in an integral constant
6113 : expression. */
6114 :
6115 : bool
6116 65831514 : cast_valid_in_integral_constant_expression_p (tree type)
6117 : {
6118 65831514 : return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
6119 46356990 : || cxx_dialect >= cxx11
6120 264969 : || dependent_type_p (type)
6121 66024676 : || type == error_mark_node);
6122 : }
6123 :
6124 : /* Return true if we need to fix linkage information of DECL. */
6125 :
6126 : static bool
6127 1920468 : cp_fix_function_decl_p (tree decl)
6128 : {
6129 : /* Skip if DECL is not externally visible. */
6130 1920468 : if (!TREE_PUBLIC (decl))
6131 : return false;
6132 :
6133 : /* We need to fix DECL if it a appears to be exported but with no
6134 : function body. Thunks do not have CFGs and we may need to
6135 : handle them specially later. */
6136 1918325 : if (!gimple_has_body_p (decl)
6137 1877271 : && !DECL_THUNK_P (decl)
6138 3795064 : && !DECL_EXTERNAL (decl))
6139 : {
6140 11317 : struct cgraph_node *node = cgraph_node::get (decl);
6141 :
6142 : /* Don't fix same_body aliases. Although they don't have their own
6143 : CFG, they share it with what they alias to. */
6144 11317 : if (!node || !node->alias || !node->num_references ())
6145 : return true;
6146 : }
6147 :
6148 : return false;
6149 : }
6150 :
6151 : /* Clean the C++ specific parts of the tree T. */
6152 :
6153 : void
6154 3347062 : cp_free_lang_data (tree t)
6155 : {
6156 3347062 : if (FUNC_OR_METHOD_TYPE_P (t))
6157 : {
6158 : /* Default args are not interesting anymore. */
6159 627952 : tree argtypes = TYPE_ARG_TYPES (t);
6160 2347950 : while (argtypes)
6161 : {
6162 1719998 : TREE_PURPOSE (argtypes) = 0;
6163 1719998 : argtypes = TREE_CHAIN (argtypes);
6164 : }
6165 : }
6166 2719110 : else if (TREE_CODE (t) == FUNCTION_DECL
6167 2719110 : && cp_fix_function_decl_p (t))
6168 : {
6169 : /* If T is used in this translation unit at all, the definition
6170 : must exist somewhere else since we have decided to not emit it
6171 : in this TU. So make it an external reference. */
6172 5866 : DECL_EXTERNAL (t) = 1;
6173 5866 : TREE_STATIC (t) = 0;
6174 : }
6175 3347062 : if (TREE_CODE (t) == NAMESPACE_DECL)
6176 : /* We do not need the leftover chaining of namespaces from the
6177 : binding level. */
6178 2821 : DECL_CHAIN (t) = NULL_TREE;
6179 3347062 : }
6180 :
6181 : /* Stub for c-common. Please keep in sync with c-decl.cc.
6182 : FIXME: If address space support is target specific, then this
6183 : should be a C target hook. But currently this is not possible,
6184 : because this function is called via REGISTER_TARGET_PRAGMAS. */
6185 : void
6186 178520 : c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
6187 : {
6188 178520 : }
6189 :
6190 : /* Return the number of operands in T that we care about for things like
6191 : mangling. */
6192 :
6193 : int
6194 799178276 : cp_tree_operand_length (const_tree t)
6195 : {
6196 799178276 : enum tree_code code = TREE_CODE (t);
6197 :
6198 799178276 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
6199 17861737 : return VL_EXP_OPERAND_LENGTH (t);
6200 :
6201 781316539 : return cp_tree_code_length (code);
6202 : }
6203 :
6204 : /* Like cp_tree_operand_length, but takes a tree_code CODE. */
6205 :
6206 : int
6207 783574406 : cp_tree_code_length (enum tree_code code)
6208 : {
6209 783574406 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
6210 :
6211 783574406 : switch (code)
6212 : {
6213 : case PREINCREMENT_EXPR:
6214 : case PREDECREMENT_EXPR:
6215 : case POSTINCREMENT_EXPR:
6216 : case POSTDECREMENT_EXPR:
6217 : return 1;
6218 :
6219 171290 : case ARRAY_REF:
6220 171290 : return 2;
6221 :
6222 : case EXPR_PACK_EXPANSION:
6223 : return 1;
6224 :
6225 781677563 : default:
6226 781677563 : return TREE_CODE_LENGTH (code);
6227 : }
6228 : }
6229 :
6230 : /* Implement -Wzero_as_null_pointer_constant. Return true if the
6231 : conditions for the warning hold, false otherwise. */
6232 : bool
6233 3506379 : maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
6234 : {
6235 3506379 : if (c_inhibit_evaluation_warnings == 0
6236 6698110 : && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
6237 : {
6238 1375972 : warning_at (loc, OPT_Wzero_as_null_pointer_constant,
6239 : "zero as null pointer constant");
6240 1375972 : return true;
6241 : }
6242 : return false;
6243 : }
6244 :
6245 : /* FNDECL is a function declaration whose type may have been altered by
6246 : adding extra parameters such as this, in-charge, or VTT. When this
6247 : takes place, the positional arguments supplied by the user (as in the
6248 : 'format' attribute arguments) may refer to the wrong argument. This
6249 : function returns an integer indicating how many arguments should be
6250 : skipped. */
6251 :
6252 : int
6253 18638673 : maybe_adjust_arg_pos_for_attribute (const_tree fndecl)
6254 : {
6255 18638673 : if (!fndecl)
6256 : return 0;
6257 6425042 : int n = num_artificial_parms_for (fndecl);
6258 : /* The manual states that it's the user's responsibility to account
6259 : for the implicit this parameter. */
6260 6425042 : return n > 0 ? n - 1 : 0;
6261 : }
6262 :
6263 :
6264 : /* Release memory we no longer need after parsing. */
6265 : void
6266 88316 : cp_tree_c_finish_parsing ()
6267 : {
6268 88316 : if (previous_class_level)
6269 63642 : invalidate_class_lookup_cache ();
6270 88316 : deleted_copy_types = NULL;
6271 88316 : }
6272 :
6273 : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
6274 : /* Complain that some language-specific thing hanging off a tree
6275 : node has been accessed improperly. */
6276 :
6277 : void
6278 0 : lang_check_failed (const char* file, int line, const char* function)
6279 : {
6280 0 : internal_error ("%<lang_*%> check: failed in %s, at %s:%d",
6281 : function, trim_filename (file), line);
6282 : }
6283 : #endif /* ENABLE_TREE_CHECKING */
6284 :
6285 : #if CHECKING_P
6286 :
6287 : namespace selftest {
6288 :
6289 : /* Verify that lvalue_kind () works, for various expressions,
6290 : and that location wrappers don't affect the results. */
6291 :
6292 : static void
6293 1 : test_lvalue_kind ()
6294 : {
6295 1 : location_t loc = BUILTINS_LOCATION;
6296 :
6297 : /* Verify constants and parameters, without and with
6298 : location wrappers. */
6299 1 : tree int_cst = build_int_cst (integer_type_node, 42);
6300 1 : ASSERT_EQ (clk_none, lvalue_kind (int_cst));
6301 :
6302 1 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
6303 1 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
6304 1 : ASSERT_EQ (clk_none, lvalue_kind (wrapped_int_cst));
6305 :
6306 1 : tree string_lit = build_string (4, "foo");
6307 1 : TREE_TYPE (string_lit) = char_array_type_node;
6308 1 : string_lit = fix_string_type (string_lit);
6309 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (string_lit));
6310 :
6311 1 : tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
6312 1 : ASSERT_TRUE (location_wrapper_p (wrapped_string_lit));
6313 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_string_lit));
6314 :
6315 1 : tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL,
6316 : get_identifier ("some_parm"),
6317 : integer_type_node);
6318 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (parm));
6319 :
6320 1 : tree wrapped_parm = maybe_wrap_with_location (parm, loc);
6321 1 : ASSERT_TRUE (location_wrapper_p (wrapped_parm));
6322 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_parm));
6323 :
6324 : /* Verify that lvalue_kind of std::move on a parm isn't
6325 : affected by location wrappers. */
6326 1 : tree rvalue_ref_of_parm = move (parm);
6327 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm));
6328 1 : tree rvalue_ref_of_wrapped_parm = move (wrapped_parm);
6329 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm));
6330 :
6331 : /* Verify lvalue_p. */
6332 1 : ASSERT_FALSE (lvalue_p (int_cst));
6333 1 : ASSERT_FALSE (lvalue_p (wrapped_int_cst));
6334 1 : ASSERT_TRUE (lvalue_p (parm));
6335 1 : ASSERT_TRUE (lvalue_p (wrapped_parm));
6336 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm));
6337 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm));
6338 1 : }
6339 :
6340 : /* Run all of the selftests within this file. */
6341 :
6342 : void
6343 1 : cp_tree_cc_tests ()
6344 : {
6345 1 : test_lvalue_kind ();
6346 1 : }
6347 :
6348 : } // namespace selftest
6349 :
6350 : #endif /* #if CHECKING_P */
6351 :
6352 :
6353 : #include "gt-cp-tree.h"
|