Line data Source code
1 : /* Language-dependent node constructors for parse phase of GNU compiler.
2 : Copyright (C) 1987-2026 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_no_dangling_attribute (tree *, tree, tree, int, bool *);
50 : static tree handle_annotation_attribute (tree *, tree, tree, int, bool *);
51 : static tree handle_trivial_abi_attribute (tree *, tree, tree, int, bool *);
52 : static tree handle_gnu_trivial_abi_attribute (tree *, tree, tree, int, bool *);
53 : static tree handle_no_specializations_attribute (tree *, tree, tree, int,
54 : bool *);
55 : static tree handle_gnu_no_specializations_attribute (tree *, tree, tree, int,
56 : bool *);
57 :
58 : /* If REF is an lvalue, returns the kind of lvalue that REF is.
59 : Otherwise, returns clk_none. */
60 :
61 : cp_lvalue_kind
62 2709845324 : lvalue_kind (const_tree ref)
63 : {
64 2979928598 : cp_lvalue_kind op1_lvalue_kind = clk_none;
65 2979928598 : cp_lvalue_kind op2_lvalue_kind = clk_none;
66 :
67 : /* Expressions of reference type are sometimes wrapped in
68 : INDIRECT_REFs. INDIRECT_REFs are just internal compiler
69 : representation, not part of the language, so we have to look
70 : through them. */
71 2979928598 : if (REFERENCE_REF_P (ref))
72 254285835 : return lvalue_kind (TREE_OPERAND (ref, 0));
73 :
74 2725642763 : if (TREE_TYPE (ref)
75 2725642763 : && TYPE_REF_P (TREE_TYPE (ref)))
76 : {
77 : /* unnamed rvalue references are rvalues */
78 258412191 : if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref))
79 : && TREE_CODE (ref) != PARM_DECL
80 : && !VAR_P (ref)
81 : && TREE_CODE (ref) != COMPONENT_REF
82 : /* Functions are always lvalues. */
83 308519551 : && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
84 : {
85 50106335 : op1_lvalue_kind = clk_rvalueref;
86 50106335 : if (implicit_rvalue_p (ref))
87 8316782 : op1_lvalue_kind |= clk_implicit_rval;
88 : return op1_lvalue_kind;
89 : }
90 :
91 : /* lvalue references and named rvalue references are lvalues. */
92 : return clk_ordinary;
93 : }
94 :
95 2467230572 : if (ref == current_class_ptr)
96 : return clk_none;
97 :
98 : /* Expressions with cv void type are prvalues. */
99 2464167048 : if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
100 : return clk_none;
101 :
102 2463833490 : switch (TREE_CODE (ref))
103 : {
104 : case SAVE_EXPR:
105 : return clk_none;
106 :
107 : /* preincrements and predecrements are valid lvals, provided
108 : what they refer to are valid lvals. */
109 310075781 : case PREINCREMENT_EXPR:
110 310075781 : case PREDECREMENT_EXPR:
111 310075781 : case TRY_CATCH_EXPR:
112 310075781 : case REALPART_EXPR:
113 310075781 : case IMAGPART_EXPR:
114 310075781 : case VIEW_CONVERT_EXPR:
115 310075781 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
116 : /* As for ARRAY_REF and COMPONENT_REF, these codes turn a class prvalue
117 : into an xvalue: we need to materialize the temporary before we mess
118 : with it. Except VIEW_CONVERT_EXPR that doesn't actually change the
119 : type, as in location wrapper and REF_PARENTHESIZED_P. */
120 310075781 : if (op1_lvalue_kind == clk_class
121 310075795 : && !(TREE_CODE (ref) == VIEW_CONVERT_EXPR
122 : && (same_type_ignoring_top_level_qualifiers_p
123 14 : (TREE_TYPE (ref), TREE_TYPE (TREE_OPERAND (ref, 0))))))
124 : return clk_rvalueref;
125 : return op1_lvalue_kind;
126 :
127 3594045 : case ARRAY_REF:
128 3594045 : {
129 3594045 : tree op1 = TREE_OPERAND (ref, 0);
130 3594045 : if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
131 : {
132 3116572 : op1_lvalue_kind = lvalue_kind (op1);
133 3116572 : if (op1_lvalue_kind == clk_class)
134 : /* in the case of an array operand, the result is an lvalue if
135 : that operand is an lvalue and an xvalue otherwise */
136 1887 : op1_lvalue_kind = clk_rvalueref;
137 : return op1_lvalue_kind;
138 : }
139 : else
140 : return clk_ordinary;
141 : }
142 :
143 21 : case MEMBER_REF:
144 21 : case DOTSTAR_EXPR:
145 21 : if (TREE_CODE (ref) == MEMBER_REF)
146 : op1_lvalue_kind = clk_ordinary;
147 : else
148 9 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
149 21 : if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref, 1))))
150 : op1_lvalue_kind = clk_none;
151 21 : else if (op1_lvalue_kind == clk_class)
152 : /* The result of a .* expression whose second operand is a pointer to a
153 : data member is an lvalue if the first operand is an lvalue and an
154 : xvalue otherwise. */
155 14 : op1_lvalue_kind = clk_rvalueref;
156 : return op1_lvalue_kind;
157 :
158 159674013 : case COMPONENT_REF:
159 159674013 : if (BASELINK_P (TREE_OPERAND (ref, 1)))
160 : {
161 126 : tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (ref, 1));
162 :
163 : /* For static member function recurse on the BASELINK, we can get
164 : here e.g. from reference_binding. If BASELINK_FUNCTIONS is
165 : OVERLOAD, the overload is resolved first if possible through
166 : resolve_address_of_overloaded_function. */
167 126 : if (TREE_CODE (fn) == FUNCTION_DECL && DECL_STATIC_FUNCTION_P (fn))
168 27 : return lvalue_kind (TREE_OPERAND (ref, 1));
169 : }
170 159673986 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
171 159673986 : if (op1_lvalue_kind == clk_class)
172 : /* If E1 is an lvalue, then E1.E2 is an lvalue;
173 : otherwise E1.E2 is an xvalue. */
174 : op1_lvalue_kind = clk_rvalueref;
175 :
176 : /* Look at the member designator. */
177 159495682 : if (!op1_lvalue_kind)
178 : ;
179 159673962 : else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
180 : /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
181 : situations. If we're seeing a COMPONENT_REF, it's a non-static
182 : member, so it isn't an lvalue. */
183 : op1_lvalue_kind = clk_none;
184 159673863 : else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
185 : /* This can be IDENTIFIER_NODE in a template. */;
186 152575812 : else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
187 : {
188 : /* Clear the ordinary bit. If this object was a class
189 : rvalue we want to preserve that information. */
190 6259046 : op1_lvalue_kind &= ~clk_ordinary;
191 : /* The lvalue is for a bitfield. */
192 6259046 : op1_lvalue_kind |= clk_bitfield;
193 : }
194 146316766 : else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
195 15161 : op1_lvalue_kind |= clk_packed;
196 :
197 : return op1_lvalue_kind;
198 :
199 : case STRING_CST:
200 : return clk_ordinary | clk_mergeable;
201 :
202 : case COMPOUND_LITERAL_EXPR:
203 : return clk_ordinary;
204 :
205 3125834 : case CONST_DECL:
206 : /* CONST_DECL without TREE_STATIC are enumeration values and
207 : thus not lvalues. With TREE_STATIC they are used by ObjC++
208 : in objc_build_string_object and need to be considered as
209 : lvalues. */
210 3125834 : if (! TREE_STATIC (ref))
211 : return clk_none;
212 : /* FALLTHRU */
213 256760938 : case VAR_DECL:
214 256760938 : if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
215 959048 : return lvalue_kind (DECL_VALUE_EXPR (const_cast<tree> (ref)));
216 :
217 365515135 : if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
218 14174347 : && DECL_LANG_SPECIFIC (ref)
219 256709654 : && DECL_IN_AGGR_P (ref))
220 : return clk_none;
221 :
222 255801890 : if (TREE_CODE (ref) == CONST_DECL || DECL_MERGEABLE (ref))
223 : return clk_ordinary | clk_mergeable;
224 :
225 : /* FALLTHRU */
226 : case INDIRECT_REF:
227 : case ARROW_EXPR:
228 : case PARM_DECL:
229 : case RESULT_DECL:
230 : case PLACEHOLDER_EXPR:
231 : return clk_ordinary;
232 :
233 : /* A scope ref in a template, left as SCOPE_REF to support later
234 : access checking. */
235 11520452 : case SCOPE_REF:
236 11520452 : gcc_assert (!type_dependent_expression_p (const_cast<tree> (ref)));
237 11520452 : {
238 11520452 : tree op = TREE_OPERAND (ref, 1);
239 11520452 : if (TREE_CODE (op) == FIELD_DECL)
240 18629 : return (DECL_C_BIT_FIELD (op) ? clk_bitfield : clk_ordinary);
241 : else
242 : return lvalue_kind (op);
243 : }
244 :
245 485 : case MAX_EXPR:
246 485 : case MIN_EXPR:
247 : /* Disallow <? and >? as lvalues if either argument side-effects. */
248 485 : if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
249 485 : || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
250 : return clk_none;
251 485 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
252 485 : op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1));
253 485 : break;
254 :
255 13085747 : case COND_EXPR:
256 13085747 : if (processing_template_decl)
257 : {
258 : /* Within templates, a REFERENCE_TYPE will indicate whether
259 : the COND_EXPR result is an ordinary lvalue or rvalueref.
260 : Since REFERENCE_TYPEs are handled above, if we reach this
261 : point, we know we got a plain rvalue. Unless we have a
262 : type-dependent expr, that is, but we shouldn't be testing
263 : lvalueness if we can't even tell the types yet! */
264 1316237 : gcc_assert (!type_dependent_expression_p (const_cast<tree> (ref)));
265 1316237 : goto default_;
266 : }
267 11769510 : {
268 11769510 : tree op1 = TREE_OPERAND (ref, 1);
269 11769510 : if (!op1) op1 = TREE_OPERAND (ref, 0);
270 11769510 : tree op2 = TREE_OPERAND (ref, 2);
271 11769510 : op1_lvalue_kind = lvalue_kind (op1);
272 11769510 : op2_lvalue_kind = lvalue_kind (op2);
273 11769510 : if (!op1_lvalue_kind != !op2_lvalue_kind)
274 : {
275 : /* The second or the third operand (but not both) is a
276 : throw-expression; the result is of the type
277 : and value category of the other. */
278 570131 : if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
279 : op2_lvalue_kind = op1_lvalue_kind;
280 570086 : else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
281 11769995 : op1_lvalue_kind = op2_lvalue_kind;
282 : }
283 : }
284 : break;
285 :
286 96535 : case MODOP_EXPR:
287 : /* We expect to see unlowered MODOP_EXPRs only during
288 : template processing. */
289 96535 : gcc_assert (processing_template_decl);
290 96535 : if (CLASS_TYPE_P (TREE_TYPE (TREE_OPERAND (ref, 0))))
291 3 : goto default_;
292 : else
293 : return clk_ordinary;
294 :
295 : case MODIFY_EXPR:
296 : case TYPEID_EXPR:
297 : return clk_ordinary;
298 :
299 3299185 : case COMPOUND_EXPR:
300 3299185 : return lvalue_kind (TREE_OPERAND (ref, 1));
301 :
302 : case TARGET_EXPR:
303 : return clk_class;
304 :
305 1411 : case VA_ARG_EXPR:
306 1411 : return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
307 :
308 121787716 : case CALL_EXPR:
309 : /* We can see calls outside of TARGET_EXPR in templates. */
310 121787716 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
311 : return clk_class;
312 : return clk_none;
313 :
314 129691303 : case FUNCTION_DECL:
315 : /* All functions (except non-static-member functions) are
316 : lvalues. */
317 129691303 : return (DECL_IOBJ_MEMBER_FUNCTION_P (ref)
318 129691303 : ? clk_none : clk_ordinary);
319 :
320 2210 : case BASELINK:
321 : /* We now represent a reference to a single static member function
322 : with a BASELINK. */
323 : /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
324 : its argument unmodified and we assign it to a const_tree. */
325 2210 : return lvalue_kind (BASELINK_FUNCTIONS (const_cast<tree> (ref)));
326 :
327 35146 : case PAREN_EXPR:
328 35146 : return lvalue_kind (TREE_OPERAND (ref, 0));
329 :
330 20936222 : case TEMPLATE_PARM_INDEX:
331 20936222 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
332 : /* A template parameter object is an lvalue. */
333 : return clk_ordinary;
334 : return clk_none;
335 :
336 1030970704 : default:
337 1030970704 : default_:
338 1030970704 : if (!TREE_TYPE (ref))
339 : return clk_none;
340 2061941408 : if (CLASS_TYPE_P (TREE_TYPE (ref))
341 2058706381 : || TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE)
342 : return clk_class;
343 : return clk_none;
344 : }
345 :
346 : /* If one operand is not an lvalue at all, then this expression is
347 : not an lvalue. */
348 11769995 : if (!op1_lvalue_kind || !op2_lvalue_kind)
349 : return clk_none;
350 :
351 : /* Otherwise, it's an lvalue, and it has all the odd properties
352 : contributed by either operand. */
353 3586534 : op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
354 : /* It's not an ordinary lvalue if it involves any other kind. */
355 3586534 : if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
356 191752 : op1_lvalue_kind &= ~clk_ordinary;
357 : /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
358 : A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
359 191752 : if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
360 38793 : && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
361 2709845324 : op1_lvalue_kind = clk_none;
362 : return op1_lvalue_kind;
363 : }
364 :
365 : /* Returns the kind of lvalue that REF is, in the sense of [basic.lval]. */
366 :
367 : cp_lvalue_kind
368 44832986 : real_lvalue_p (const_tree ref)
369 : {
370 44832986 : cp_lvalue_kind kind = lvalue_kind (ref);
371 44832986 : if (kind & (clk_rvalueref|clk_class))
372 : return clk_none;
373 : else
374 42712782 : return kind;
375 : }
376 :
377 : /* c-common wants us to return bool. */
378 :
379 : bool
380 43973804 : lvalue_p (const_tree t)
381 : {
382 43973804 : return real_lvalue_p (t);
383 : }
384 :
385 : /* This differs from lvalue_p in that xvalues are included. */
386 :
387 : bool
388 153934210 : glvalue_p (const_tree ref)
389 : {
390 153934210 : cp_lvalue_kind kind = lvalue_kind (ref);
391 153934210 : if (kind & clk_class)
392 : return false;
393 : else
394 150650284 : return (kind != clk_none);
395 : }
396 :
397 : /* This differs from glvalue_p in that class prvalues are included. */
398 :
399 : bool
400 1301514422 : obvalue_p (const_tree ref)
401 : {
402 1301514422 : return (lvalue_kind (ref) != clk_none);
403 : }
404 :
405 : /* Returns true if REF is an xvalue (the result of dereferencing an rvalue
406 : reference), false otherwise. */
407 :
408 : bool
409 7089628 : xvalue_p (const_tree ref)
410 : {
411 7089628 : return (lvalue_kind (ref) & clk_rvalueref);
412 : }
413 :
414 : /* True if REF is a bit-field. */
415 :
416 : bool
417 214996067 : bitfield_p (const_tree ref)
418 : {
419 214996067 : return (lvalue_kind (ref) & clk_bitfield);
420 : }
421 :
422 : /* True if REF is a glvalue with a unique address, excluding mergeable glvalues
423 : such as string constants. */
424 :
425 : bool
426 108 : non_mergeable_glvalue_p (const_tree ref)
427 : {
428 108 : auto kind = lvalue_kind (ref);
429 108 : return (kind != clk_none
430 108 : && !(kind & (clk_class|clk_mergeable)));
431 : }
432 :
433 : /* C++-specific version of stabilize_reference for bit-fields and
434 : DECL_PACKED fields. We can't bind a reference to those. */
435 :
436 : static tree
437 48 : cp_stabilize_bitfield_reference (tree ref)
438 : {
439 48 : tree op1, op2, op3;
440 48 : STRIP_ANY_LOCATION_WRAPPER (ref);
441 48 : switch (TREE_CODE (ref))
442 : {
443 24 : case VAR_DECL:
444 24 : case PARM_DECL:
445 24 : case RESULT_DECL:
446 24 : CASE_CONVERT:
447 24 : case FLOAT_EXPR:
448 24 : case FIX_TRUNC_EXPR:
449 24 : case INDIRECT_REF:
450 24 : case COMPONENT_REF:
451 24 : case BIT_FIELD_REF:
452 24 : case ARRAY_REF:
453 24 : case ARRAY_RANGE_REF:
454 24 : case ERROR_MARK:
455 24 : case REALPART_EXPR:
456 24 : case IMAGPART_EXPR:
457 24 : default:
458 24 : break;
459 24 : case COMPOUND_EXPR:
460 24 : op2 = cp_stabilize_bitfield_reference (TREE_OPERAND (ref, 1));
461 24 : if (op2 == TREE_OPERAND (ref, 1))
462 : return ref;
463 24 : op1 = TREE_OPERAND (ref, 0);
464 24 : if (TREE_SIDE_EFFECTS (op1))
465 : {
466 24 : if (VOID_TYPE_P (TREE_TYPE (op1)))
467 0 : op1 = save_expr (op1);
468 : else
469 : {
470 24 : op1 = build2 (COMPOUND_EXPR, void_type_node, op1,
471 : void_node);
472 24 : op1 = save_expr (op1);
473 : }
474 : }
475 24 : return build2 (COMPOUND_EXPR, TREE_TYPE (op2), op1, op2);
476 0 : case COND_EXPR:
477 0 : op1 = TREE_OPERAND (ref, 0);
478 0 : op2 = TREE_OPERAND (ref, 1);
479 0 : op3 = TREE_OPERAND (ref, 2);
480 0 : if (op2 && TREE_CODE (op2) != THROW_EXPR)
481 0 : op2 = cp_stabilize_bitfield_reference (op2);
482 0 : if (TREE_CODE (op3) != THROW_EXPR)
483 0 : op3 = cp_stabilize_bitfield_reference (op3);
484 0 : if (op2 == NULL_TREE)
485 0 : op1 = cp_stabilize_bitfield_reference (op1);
486 0 : if (op1 == TREE_OPERAND (ref, 0)
487 0 : && op2 == TREE_OPERAND (ref, 1)
488 0 : && op3 == TREE_OPERAND (ref, 2))
489 : return ref;
490 0 : if (op2 != NULL_TREE && TREE_SIDE_EFFECTS (op1))
491 0 : op1 = save_expr (op1);
492 0 : return build3 (COND_EXPR, TREE_TYPE (ref), op1, op2, op3);
493 0 : case PREINCREMENT_EXPR:
494 0 : case PREDECREMENT_EXPR:
495 0 : op1 = cp_stabilize_bitfield_reference (TREE_OPERAND (ref, 0));
496 0 : if (op1 == TREE_OPERAND (ref, 0))
497 : return ref;
498 0 : return build2 (COMPOUND_EXPR, TREE_TYPE (ref),
499 0 : build2 (TREE_CODE (ref), TREE_TYPE (ref), op1,
500 0 : TREE_OPERAND (ref, 0)), op1);
501 0 : case PAREN_EXPR:
502 0 : op1 = cp_stabilize_bitfield_reference (TREE_OPERAND (ref, 0));
503 0 : if (op1 == TREE_OPERAND (ref, 0))
504 : return ref;
505 0 : return build1 (PAREN_EXPR, TREE_TYPE (ref), op1);
506 : }
507 24 : return stabilize_reference (ref);
508 : }
509 :
510 : /* C++-specific version of stabilize_reference. */
511 :
512 : tree
513 5076908 : cp_stabilize_reference (tree ref)
514 : {
515 5076908 : if (processing_template_decl)
516 : /* As in cp_save_expr. */
517 : return ref;
518 :
519 4150505 : STRIP_ANY_LOCATION_WRAPPER (ref);
520 4150505 : switch (TREE_CODE (ref))
521 : {
522 : /* We need to treat specially anything stabilize_reference doesn't
523 : handle specifically. */
524 : case VAR_DECL:
525 : case PARM_DECL:
526 : case RESULT_DECL:
527 : CASE_CONVERT:
528 : case FLOAT_EXPR:
529 : case FIX_TRUNC_EXPR:
530 : case INDIRECT_REF:
531 : case COMPONENT_REF:
532 : case BIT_FIELD_REF:
533 : case ARRAY_REF:
534 : case ARRAY_RANGE_REF:
535 : case ERROR_MARK:
536 : break;
537 475 : default:
538 475 : cp_lvalue_kind kind = lvalue_kind (ref);
539 475 : if ((kind & ~clk_class) != clk_none)
540 : {
541 460 : if (kind & (clk_bitfield | clk_packed))
542 24 : return cp_stabilize_bitfield_reference (ref);
543 436 : tree type = unlowered_expr_type (ref);
544 436 : bool rval = !!(kind & clk_rvalueref);
545 436 : type = cp_build_reference_type (type, rval);
546 : /* This inhibits warnings in, eg, cxx_mark_addressable
547 : (c++/60955). */
548 436 : warning_sentinel s (extra_warnings);
549 436 : ref = build_static_cast (input_location, type, ref,
550 : tf_error);
551 436 : }
552 : }
553 :
554 4150481 : return stabilize_reference (ref);
555 : }
556 :
557 : /* Test whether DECL is a builtin that may appear in a
558 : constant-expression. */
559 :
560 : bool
561 580239564 : builtin_valid_in_constant_expr_p (const_tree decl)
562 : {
563 580239564 : STRIP_ANY_LOCATION_WRAPPER (decl);
564 580239564 : if (TREE_CODE (decl) != FUNCTION_DECL)
565 : /* Not a function. */
566 : return false;
567 296417184 : if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
568 : {
569 248241341 : if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
570 273980 : switch (DECL_FE_FUNCTION_CODE (decl))
571 : {
572 : case CP_BUILT_IN_IS_CONSTANT_EVALUATED:
573 : case CP_BUILT_IN_SOURCE_LOCATION:
574 : case CP_BUILT_IN_IS_CORRESPONDING_MEMBER:
575 : case CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS:
576 : case CP_BUILT_IN_EH_PTR_ADJUST_REF:
577 : case CP_BUILT_IN_IS_STRING_LITERAL:
578 : case CP_BUILT_IN_CONSTEXPR_DIAG:
579 : case CP_BUILT_IN_CURRENT_EXCEPTION:
580 : case CP_BUILT_IN_UNCAUGHT_EXCEPTIONS:
581 : case CP_BUILT_IN_IS_WITHIN_LIFETIME:
582 : case CP_BUILT_IN_START_LIFETIME:
583 : return true;
584 : default:
585 : break;
586 : }
587 : /* Not a built-in. */
588 : return false;
589 : }
590 48175843 : switch (DECL_FUNCTION_CODE (decl))
591 : {
592 : /* These always have constant results like the corresponding
593 : macros/symbol. */
594 : case BUILT_IN_FILE:
595 : case BUILT_IN_FUNCTION:
596 : case BUILT_IN_LINE:
597 :
598 : /* The following built-ins are valid in constant expressions
599 : when their arguments are. */
600 : case BUILT_IN_ADD_OVERFLOW_P:
601 : case BUILT_IN_SUB_OVERFLOW_P:
602 : case BUILT_IN_MUL_OVERFLOW_P:
603 :
604 : /* These have constant results even if their operands are
605 : non-constant. */
606 : case BUILT_IN_CONSTANT_P:
607 : case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE:
608 : return true;
609 : default:
610 : return false;
611 : }
612 : }
613 :
614 : /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
615 :
616 : static tree
617 37556278 : build_target_expr (tree decl, tree value, tsubst_flags_t complain)
618 : {
619 37556278 : tree t;
620 37556278 : tree type = TREE_TYPE (decl);
621 :
622 37556278 : value = mark_rvalue_use (value);
623 :
624 37556278 : gcc_checking_assert (VOID_TYPE_P (TREE_TYPE (value))
625 : || TREE_TYPE (decl) == TREE_TYPE (value)
626 : /* On ARM ctors return 'this'. */
627 : || (TYPE_PTR_P (TREE_TYPE (value))
628 : && TREE_CODE (value) == CALL_EXPR)
629 : || useless_type_conversion_p (TREE_TYPE (decl),
630 : TREE_TYPE (value)));
631 :
632 : /* Set TREE_READONLY for optimization, such as gimplify_init_constructor
633 : moving a constant aggregate into .rodata. */
634 37556278 : if (CP_TYPE_CONST_NON_VOLATILE_P (type)
635 1994855 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
636 1868419 : && !VOID_TYPE_P (TREE_TYPE (value))
637 1152038 : && !TYPE_HAS_MUTABLE_P (type)
638 38708308 : && reduced_constant_expression_p (value))
639 341463 : TREE_READONLY (decl) = true;
640 :
641 37556278 : if (complain & tf_no_cleanup)
642 : /* The caller is building a new-expr and does not need a cleanup. */
643 : t = NULL_TREE;
644 : else
645 : {
646 36638195 : t = cxx_maybe_build_cleanup (decl, complain);
647 36638195 : if (t == error_mark_node)
648 : return error_mark_node;
649 : }
650 :
651 37556230 : set_target_expr_eliding (value);
652 :
653 37556230 : t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
654 37556230 : if (location_t eloc = cp_expr_location (value))
655 24543547 : SET_EXPR_LOCATION (t, eloc);
656 : /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
657 : ignore the TARGET_EXPR. If there really turn out to be no
658 : side-effects, then the optimizer should be able to get rid of
659 : whatever code is generated anyhow. */
660 37556230 : TREE_SIDE_EFFECTS (t) = 1;
661 :
662 37556230 : return t;
663 : }
664 :
665 : /* Return an undeclared local temporary of type TYPE for use in building a
666 : TARGET_EXPR. */
667 :
668 : tree
669 42303987 : build_local_temp (tree type)
670 : {
671 42303987 : tree slot = build_decl (input_location,
672 : VAR_DECL, NULL_TREE, type);
673 42303987 : DECL_ARTIFICIAL (slot) = 1;
674 42303987 : DECL_IGNORED_P (slot) = 1;
675 42303987 : DECL_CONTEXT (slot) = current_function_decl;
676 42303987 : layout_decl (slot, 0);
677 42303987 : return slot;
678 : }
679 :
680 : /* Return whether DECL is such a local temporary (or one from
681 : create_tmp_var_raw). */
682 :
683 : bool
684 55055703 : is_local_temp (tree decl)
685 : {
686 55055703 : return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
687 55631975 : && !TREE_STATIC (decl));
688 : }
689 :
690 : /* Set various status flags when building an AGGR_INIT_EXPR object T. */
691 :
692 : static void
693 13185004 : process_aggr_init_operands (tree t)
694 : {
695 13185004 : bool side_effects;
696 :
697 13185004 : side_effects = TREE_SIDE_EFFECTS (t);
698 13185004 : if (!side_effects)
699 : {
700 13185004 : int i, n;
701 13185004 : n = TREE_OPERAND_LENGTH (t);
702 72300817 : for (i = 1; i < n; i++)
703 : {
704 49590592 : tree op = TREE_OPERAND (t, i);
705 49590592 : if (op && TREE_SIDE_EFFECTS (op))
706 : {
707 : side_effects = 1;
708 : break;
709 : }
710 : }
711 : }
712 13185004 : TREE_SIDE_EFFECTS (t) = side_effects;
713 13185004 : }
714 :
715 : /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
716 : FN, and SLOT. NARGS is the number of call arguments which are specified
717 : as a tree array ARGS. */
718 :
719 : static tree
720 13185004 : build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
721 : tree *args)
722 : {
723 13185004 : tree t;
724 13185004 : int i;
725 :
726 13185004 : t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
727 13185004 : TREE_TYPE (t) = return_type;
728 13185004 : AGGR_INIT_EXPR_FN (t) = fn;
729 13185004 : AGGR_INIT_EXPR_SLOT (t) = slot;
730 38024051 : for (i = 0; i < nargs; i++)
731 24839047 : AGGR_INIT_EXPR_ARG (t, i) = args[i];
732 13185004 : process_aggr_init_operands (t);
733 13185004 : return t;
734 : }
735 :
736 : /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
737 : target. TYPE is the type to be initialized.
738 :
739 : Build an AGGR_INIT_EXPR to represent the initialization. This function
740 : differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
741 : to initialize another object, whereas a TARGET_EXPR can either
742 : initialize another object or create its own temporary object, and as a
743 : result building up a TARGET_EXPR requires that the type's destructor be
744 : callable. */
745 :
746 : tree
747 41288398 : build_aggr_init_expr (tree type, tree init)
748 : {
749 41288398 : tree fn;
750 41288398 : tree slot;
751 41288398 : tree rval;
752 41288398 : int is_ctor;
753 :
754 41288398 : gcc_assert (!VOID_TYPE_P (type));
755 :
756 : /* Don't build AGGR_INIT_EXPR in a template. */
757 41288398 : if (processing_template_decl)
758 : return init;
759 :
760 41182539 : fn = cp_get_callee (init);
761 41182539 : if (fn == NULL_TREE)
762 16774775 : return convert (type, init);
763 :
764 50049715 : is_ctor = (TREE_CODE (fn) == ADDR_EXPR
765 24360727 : && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
766 73129218 : && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
767 :
768 : /* We split the CALL_EXPR into its function and its arguments here.
769 : Then, in expand_expr, we put them back together. The reason for
770 : this is that this expression might be a default argument
771 : expression. In that case, we need a new temporary every time the
772 : expression is used. That's what break_out_target_exprs does; it
773 : replaces every AGGR_INIT_EXPR with a copy that uses a fresh
774 : temporary slot. Then, expand_expr builds up a call-expression
775 : using the new slot. */
776 :
777 : /* If we don't need to use a constructor to create an object of this
778 : type, don't mess with AGGR_INIT_EXPR. */
779 12456947 : if (is_ctor || TREE_ADDRESSABLE (type))
780 : {
781 13185004 : slot = build_local_temp (type);
782 :
783 13185004 : if (TREE_CODE (init) == CALL_EXPR)
784 : {
785 50644400 : rval = build_aggr_init_array (void_type_node, fn, slot,
786 12661100 : call_expr_nargs (init),
787 12661100 : CALL_EXPR_ARGP (init));
788 12661100 : AGGR_INIT_FROM_THUNK_P (rval)
789 12661100 : = CALL_FROM_THUNK_P (init);
790 : }
791 : else
792 : {
793 523904 : rval = build_aggr_init_array (void_type_node, fn, slot,
794 523904 : aggr_init_expr_nargs (init),
795 523904 : AGGR_INIT_EXPR_ARGP (init));
796 523904 : AGGR_INIT_FROM_THUNK_P (rval)
797 523904 : = AGGR_INIT_FROM_THUNK_P (init);
798 : }
799 13185004 : TREE_SIDE_EFFECTS (rval) = 1;
800 13185004 : AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
801 13185004 : TREE_NOTHROW (rval) = TREE_NOTHROW (init);
802 13185004 : CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
803 13185004 : CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
804 13185004 : CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
805 13185004 : SET_EXPR_LOCATION (rval, EXPR_LOCATION (init));
806 : }
807 : else
808 : rval = init;
809 :
810 : return rval;
811 : }
812 :
813 : /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
814 : target. TYPE is the type that this initialization should appear to
815 : have.
816 :
817 : Build an encapsulation of the initialization to perform
818 : and return it so that it can be processed by language-independent
819 : and language-specific expression expanders. */
820 :
821 : tree
822 35655154 : build_cplus_new (tree type, tree init, tsubst_flags_t complain)
823 : {
824 : /* This function should cope with what build_special_member_call
825 : can produce. When performing parenthesized aggregate initialization,
826 : it can produce a { }. */
827 35655154 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
828 : {
829 494 : gcc_assert (cxx_dialect >= cxx20);
830 494 : return finish_compound_literal (type, init, complain);
831 : }
832 :
833 35654660 : tree rval = build_aggr_init_expr (type, init);
834 35654660 : tree slot;
835 :
836 35654660 : if (init == error_mark_node)
837 : return error_mark_node;
838 :
839 35652469 : if (!complete_type_or_maybe_complain (type, init, complain))
840 6 : return error_mark_node;
841 :
842 : /* Make sure that we're not trying to create an instance of an
843 : abstract class. */
844 35652463 : if (abstract_virtuals_error (NULL_TREE, type, complain))
845 33 : return error_mark_node;
846 :
847 35652430 : if (TREE_CODE (rval) == AGGR_INIT_EXPR)
848 7857773 : slot = AGGR_INIT_EXPR_SLOT (rval);
849 27794657 : else if (TREE_CODE (rval) == CALL_EXPR
850 16484856 : || TREE_CODE (rval) == CONSTRUCTOR)
851 11310173 : slot = build_local_temp (type);
852 : else
853 : return rval;
854 :
855 19167946 : rval = build_target_expr (slot, rval, complain);
856 :
857 19167946 : if (rval != error_mark_node)
858 19167946 : TARGET_EXPR_IMPLICIT_P (rval) = 1;
859 :
860 : return rval;
861 : }
862 :
863 : /* Subroutine of build_vec_init_expr: Build up a single element
864 : initialization as a proxy for the full array initialization to get things
865 : marked as used and any appropriate diagnostics.
866 :
867 : This used to be necessary because we were deferring building the actual
868 : constructor calls until gimplification time; now we only do it to set
869 : VEC_INIT_EXPR_IS_CONSTEXPR.
870 :
871 : We assume that init is either NULL_TREE, {}, void_type_node (indicating
872 : value-initialization), or another array to copy. */
873 :
874 : static tree
875 1324 : build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
876 : {
877 1324 : tree inner_type = strip_array_types (type);
878 :
879 1324 : if (integer_zerop (array_type_nelts_total (type))
880 1324 : || !CLASS_TYPE_P (inner_type))
881 : /* No interesting initialization to do. */
882 231 : return integer_zero_node;
883 1093 : if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
884 : {
885 : /* Even if init has initializers for some array elements,
886 : we're interested in the {}-init of trailing elements. */
887 230 : if (CP_AGGREGATE_TYPE_P (inner_type))
888 : {
889 66 : tree empty = build_constructor (init_list_type_node, nullptr);
890 66 : return digest_init (inner_type, empty, complain);
891 : }
892 : else
893 : /* It's equivalent to value-init. */
894 164 : init = void_type_node;
895 : }
896 1027 : if (init == void_type_node)
897 195 : return build_value_init (inner_type, complain);
898 :
899 832 : releasing_vec argvec;
900 832 : if (init && !BRACE_ENCLOSED_INITIALIZER_P (init))
901 : {
902 208 : tree init_type = strip_array_types (TREE_TYPE (init));
903 208 : tree dummy = build_dummy_object (init_type);
904 208 : if (!lvalue_p (init))
905 163 : dummy = move (dummy);
906 208 : argvec->quick_push (dummy);
907 : }
908 832 : init = build_special_member_call (NULL_TREE, complete_ctor_identifier,
909 : &argvec, inner_type, LOOKUP_NORMAL,
910 : complain);
911 :
912 : /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But
913 : we don't want one here because we aren't creating a temporary. */
914 832 : if (TREE_CODE (init) == TARGET_EXPR)
915 32 : init = TARGET_EXPR_INITIAL (init);
916 :
917 832 : return init;
918 832 : }
919 :
920 : /* Return a TARGET_EXPR which expresses the initialization of an array to
921 : be named later, either default-initialization or copy-initialization
922 : from another array of the same type. */
923 :
924 : tree
925 1342 : build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
926 : {
927 1342 : if (tree vi = get_vec_init_expr (init))
928 : return vi;
929 :
930 1326 : tree elt_init;
931 690 : if (init && TREE_CODE (init) == CONSTRUCTOR
932 1560 : && !BRACE_ENCLOSED_INITIALIZER_P (init))
933 : /* We built any needed constructor calls in digest_init. */
934 : elt_init = init;
935 : else
936 1322 : elt_init = build_vec_init_elt (type, init, complain);
937 :
938 1326 : bool value_init = false;
939 1326 : if (init == void_type_node)
940 : {
941 241 : value_init = true;
942 241 : init = NULL_TREE;
943 : }
944 :
945 1326 : tree slot = build_local_temp (type);
946 1326 : init = build2 (VEC_INIT_EXPR, type, slot, init);
947 1326 : TREE_SIDE_EFFECTS (init) = true;
948 1326 : SET_EXPR_LOCATION (init, input_location);
949 :
950 1326 : if (cxx_dialect >= cxx11)
951 : {
952 1237 : bool cx = potential_constant_expression (elt_init);
953 1237 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
954 0 : cx &= potential_constant_expression (init);
955 1237 : VEC_INIT_EXPR_IS_CONSTEXPR (init) = cx;
956 : }
957 1326 : VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
958 :
959 1326 : return init;
960 : }
961 :
962 : /* Call build_vec_init to expand VEC_INIT into TARGET (for which NULL_TREE
963 : means VEC_INIT_EXPR_SLOT). */
964 :
965 : tree
966 1142 : expand_vec_init_expr (tree target, tree vec_init, tsubst_flags_t complain,
967 : vec<tree,va_gc> **flags)
968 : {
969 1142 : iloc_sentinel ils = EXPR_LOCATION (vec_init);
970 :
971 1142 : if (!target)
972 0 : target = VEC_INIT_EXPR_SLOT (vec_init);
973 1142 : tree init = VEC_INIT_EXPR_INIT (vec_init);
974 1142 : int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
975 3426 : return build_vec_init (target, NULL_TREE, init,
976 1142 : VEC_INIT_EXPR_VALUE_INIT (vec_init),
977 1142 : from_array, complain, flags);
978 1142 : }
979 :
980 : /* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context
981 : that requires a constant expression. */
982 :
983 : void
984 2 : diagnose_non_constexpr_vec_init (tree expr)
985 : {
986 2 : tree type = TREE_TYPE (VEC_INIT_EXPR_SLOT (expr));
987 2 : tree init, elt_init;
988 2 : if (VEC_INIT_EXPR_VALUE_INIT (expr))
989 2 : init = void_type_node;
990 : else
991 0 : init = VEC_INIT_EXPR_INIT (expr);
992 :
993 2 : elt_init = build_vec_init_elt (type, init, tf_warning_or_error);
994 2 : require_potential_constant_expression (elt_init);
995 2 : }
996 :
997 : tree
998 19 : build_array_copy (tree init)
999 : {
1000 19 : return get_target_expr (build_vec_init_expr
1001 19 : (TREE_TYPE (init), init, tf_warning_or_error));
1002 : }
1003 :
1004 : /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
1005 : indicated TYPE. */
1006 :
1007 : tree
1008 10037220 : build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
1009 : {
1010 10037220 : gcc_assert (!VOID_TYPE_P (type));
1011 10037220 : gcc_assert (!VOID_TYPE_P (TREE_TYPE (init)));
1012 :
1013 10037220 : if (TREE_CODE (init) == TARGET_EXPR
1014 8886736 : || init == error_mark_node)
1015 : return init;
1016 6591755 : else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
1017 57348 : && TREE_CODE (init) != COND_EXPR
1018 : && TREE_CODE (init) != CONSTRUCTOR
1019 : && TREE_CODE (init) != VA_ARG_EXPR
1020 8886473 : && TREE_CODE (init) != CALL_EXPR)
1021 : /* We need to build up a copy constructor call. COND_EXPR is a special
1022 : case because we already have copies on the arms and we don't want
1023 : another one here. A CONSTRUCTOR is aggregate initialization, which
1024 : is handled separately. A VA_ARG_EXPR is magic creation of an
1025 : aggregate; there's no additional work to be done. A CALL_EXPR
1026 : already creates a prvalue. */
1027 0 : return force_rvalue (init, complain);
1028 :
1029 8886473 : return force_target_expr (type, init, complain);
1030 : }
1031 :
1032 : /* Like the above function, but without the checking. This function should
1033 : only be used by code which is deliberately trying to subvert the type
1034 : system, such as call_builtin_trap. Or build_over_call, to avoid
1035 : infinite recursion. */
1036 :
1037 : tree
1038 17807461 : force_target_expr (tree type, tree init, tsubst_flags_t complain)
1039 : {
1040 17807461 : tree slot;
1041 :
1042 17807461 : gcc_assert (!VOID_TYPE_P (type));
1043 :
1044 17807461 : slot = build_local_temp (type);
1045 17807461 : return build_target_expr (slot, init, complain);
1046 : }
1047 :
1048 : /* Like build_target_expr_with_type, but use the type of INIT. */
1049 :
1050 : tree
1051 8128152 : get_target_expr (tree init, tsubst_flags_t complain /* = tf_warning_or_error */)
1052 : {
1053 8128152 : if (TREE_CODE (init) == AGGR_INIT_EXPR)
1054 580441 : return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
1055 7547711 : else if (TREE_CODE (init) == VEC_INIT_EXPR)
1056 430 : return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
1057 : else
1058 : {
1059 7547281 : init = convert_bitfield_to_declared_type (init);
1060 7547281 : return build_target_expr_with_type (init, TREE_TYPE (init), complain);
1061 : }
1062 : }
1063 :
1064 : /* Like get_target_expr, but for an internal detail like a cleanup flag or loop
1065 : iterator. These variables should not be extended by extend_all_temps.
1066 :
1067 : This function can also be used for an ephemeral copy of a scalar value such
1068 : as the pointer to the allocated memory in build_new_1.
1069 :
1070 : This function should not be used for objects that are part of the abstract
1071 : C++ semantics such as in stabilize_expr. */
1072 :
1073 : tree
1074 3071875 : get_internal_target_expr (tree init)
1075 : {
1076 3071875 : init = convert_bitfield_to_declared_type (init);
1077 3071875 : tree t = force_target_expr (TREE_TYPE (init), init, tf_warning_or_error);
1078 3071875 : TARGET_EXPR_INTERNAL_P (t) = true;
1079 3071875 : return t;
1080 : }
1081 :
1082 : /* If EXPR is a bitfield reference, convert it to the declared type of
1083 : the bitfield, and return the resulting expression. Otherwise,
1084 : return EXPR itself. */
1085 :
1086 : tree
1087 1094269340 : convert_bitfield_to_declared_type (tree expr)
1088 : {
1089 1094269340 : tree bitfield_type;
1090 :
1091 1094269340 : bitfield_type = is_bitfield_expr_with_lowered_type (expr);
1092 1094269340 : if (bitfield_type)
1093 648233 : expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
1094 : expr);
1095 1094269340 : return expr;
1096 : }
1097 :
1098 : /* EXPR is being used in an rvalue context. Return a version of EXPR
1099 : that is marked as an rvalue. */
1100 :
1101 : tree
1102 193127495 : rvalue (tree expr)
1103 : {
1104 193127495 : tree type;
1105 :
1106 193127495 : if (error_operand_p (expr))
1107 : return expr;
1108 :
1109 193127095 : expr = mark_rvalue_use (expr);
1110 :
1111 : /* [expr.type]: "If a prvalue initially has the type "cv T", where T is a
1112 : cv-unqualified non-class, non-array type, the type of the expression is
1113 : adjusted to T prior to any further analysis. */
1114 193127095 : type = TREE_TYPE (expr);
1115 193127095 : if (!CLASS_TYPE_P (type) && TREE_CODE (type) != ARRAY_TYPE
1116 382951931 : && cv_qualified_p (type))
1117 37873891 : type = cv_unqualified (type);
1118 :
1119 : /* We need to do this for rvalue refs as well to get the right answer
1120 : from decltype; see c++/36628. */
1121 193127095 : if (!processing_template_decl && glvalue_p (expr))
1122 : {
1123 : /* But don't use this function for class lvalues; use move (to treat an
1124 : lvalue as an xvalue) or force_rvalue (to make a prvalue copy). */
1125 10484609 : gcc_checking_assert (!CLASS_TYPE_P (type));
1126 10484609 : expr = build1 (NON_LVALUE_EXPR, type, expr);
1127 : }
1128 182642486 : else if (type != TREE_TYPE (expr))
1129 37530200 : expr = build_nop (type, expr);
1130 :
1131 : return expr;
1132 : }
1133 :
1134 :
1135 : struct cplus_array_info
1136 : {
1137 : tree type;
1138 : tree domain;
1139 : };
1140 :
1141 : struct cplus_array_hasher : ggc_ptr_hash<tree_node>
1142 : {
1143 : typedef cplus_array_info *compare_type;
1144 :
1145 : static hashval_t hash (tree t);
1146 : static bool equal (tree, cplus_array_info *);
1147 : };
1148 :
1149 : /* Hash an ARRAY_TYPE. K is really of type `tree'. */
1150 :
1151 : hashval_t
1152 39324690 : cplus_array_hasher::hash (tree t)
1153 : {
1154 39324690 : hashval_t hash;
1155 :
1156 39324690 : hash = TYPE_UID (TREE_TYPE (t));
1157 39324690 : if (TYPE_DOMAIN (t))
1158 37374633 : hash ^= TYPE_UID (TYPE_DOMAIN (t));
1159 39324690 : return hash;
1160 : }
1161 :
1162 : /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
1163 : of type `cplus_array_info*'. */
1164 :
1165 : bool
1166 48609982 : cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
1167 : {
1168 51449752 : return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
1169 : }
1170 :
1171 : /* Hash table containing dependent array types, which are unsuitable for
1172 : the language-independent type hash table. */
1173 : static GTY (()) hash_table<cplus_array_hasher> *cplus_array_htab;
1174 :
1175 : /* Build an ARRAY_TYPE without laying it out. */
1176 :
1177 : static tree
1178 5503008 : build_min_array_type (tree elt_type, tree index_type)
1179 : {
1180 5503008 : tree t = cxx_make_type (ARRAY_TYPE);
1181 5503008 : TREE_TYPE (t) = elt_type;
1182 5503008 : TYPE_DOMAIN (t) = index_type;
1183 5503008 : return t;
1184 : }
1185 :
1186 : /* Set TYPE_CANONICAL like build_array_type_1, but using
1187 : build_cplus_array_type. */
1188 :
1189 : static void
1190 5503008 : set_array_type_canon (tree t, tree elt_type, tree index_type, bool dep)
1191 : {
1192 : /* Set the canonical type for this new node. */
1193 5503008 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
1194 5503008 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
1195 1391677 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1196 4111331 : else if (TYPE_CANONICAL (elt_type) != elt_type
1197 4111331 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
1198 1219780 : TYPE_CANONICAL (t)
1199 3193435 : = build_cplus_array_type (TYPE_CANONICAL (elt_type),
1200 : index_type
1201 753875 : ? TYPE_CANONICAL (index_type) : index_type,
1202 : dep);
1203 : else
1204 2891551 : TYPE_CANONICAL (t) = t;
1205 5503008 : }
1206 :
1207 : /* Like build_array_type, but handle special C++ semantics: an array of a
1208 : variant element type is a variant of the array of the main variant of
1209 : the element type. IS_DEPENDENT is -ve if we should determine the
1210 : dependency. Otherwise its bool value indicates dependency. */
1211 :
1212 : tree
1213 68170281 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
1214 : {
1215 68170281 : tree t;
1216 :
1217 68170281 : if (elt_type == error_mark_node || index_type == error_mark_node)
1218 : return error_mark_node;
1219 :
1220 68170278 : if (dependent < 0)
1221 71051854 : dependent = (uses_template_parms (elt_type)
1222 35525927 : || (index_type && uses_template_parms (index_type)));
1223 :
1224 68170278 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1225 : /* Start with an array of the TYPE_MAIN_VARIANT. */
1226 28989644 : t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
1227 : index_type, dependent);
1228 39180634 : else if (dependent)
1229 : {
1230 : /* Since type_hash_canon calls layout_type, we need to use our own
1231 : hash table. */
1232 4795164 : cplus_array_info cai;
1233 4795164 : hashval_t hash;
1234 :
1235 4795164 : if (cplus_array_htab == NULL)
1236 17859 : cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61);
1237 :
1238 4795164 : hash = TYPE_UID (elt_type);
1239 4795164 : if (index_type)
1240 2592603 : hash ^= TYPE_UID (index_type);
1241 4795164 : cai.type = elt_type;
1242 4795164 : cai.domain = index_type;
1243 :
1244 4795164 : tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
1245 4795164 : if (*e)
1246 : /* We have found the type: we're done. */
1247 2766670 : return (tree) *e;
1248 : else
1249 : {
1250 : /* Build a new array type. */
1251 2028494 : t = build_min_array_type (elt_type, index_type);
1252 :
1253 : /* Store it in the hash table. */
1254 2028494 : *e = t;
1255 :
1256 : /* Set the canonical type for this new node. */
1257 2028494 : set_array_type_canon (t, elt_type, index_type, dependent);
1258 :
1259 : /* Mark it as dependent now, this saves time later. */
1260 2028494 : TYPE_DEPENDENT_P_VALID (t) = true;
1261 2028494 : TYPE_DEPENDENT_P (t) = true;
1262 : }
1263 : }
1264 : else
1265 : {
1266 34385470 : bool typeless_storage = is_byte_access_type (elt_type);
1267 34385470 : t = build_array_type (elt_type, index_type, typeless_storage);
1268 :
1269 : /* Mark as non-dependenty now, this will save time later. */
1270 34385470 : TYPE_DEPENDENT_P_VALID (t) = true;
1271 : }
1272 :
1273 : /* Now check whether we already have this array variant. */
1274 65403608 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1275 : {
1276 : tree m = t;
1277 58917998 : for (t = m; t; t = TYPE_NEXT_VARIANT (t))
1278 55443484 : if (TREE_TYPE (t) == elt_type
1279 25524144 : && TYPE_NAME (t) == NULL_TREE
1280 25515133 : && TYPE_ATTRIBUTES (t) == NULL_TREE
1281 25515133 : && (!TYPE_USER_ALIGN (t)
1282 18579 : || (TYPE_USER_ALIGN (elt_type)
1283 18576 : && TYPE_ALIGN (t) == TYPE_ALIGN (elt_type)))
1284 25515130 : && !TREE_DEPRECATED (t)
1285 80958614 : && !TREE_UNAVAILABLE (t))
1286 : break;
1287 28989644 : if (!t)
1288 : {
1289 3474514 : t = build_min_array_type (elt_type, index_type);
1290 : /* Mark dependency now, this saves time later. */
1291 3474514 : TYPE_DEPENDENT_P_VALID (t) = true;
1292 3474514 : TYPE_DEPENDENT_P (t) = dependent;
1293 3474514 : set_array_type_canon (t, elt_type, index_type, dependent);
1294 3474514 : if (!dependent)
1295 : {
1296 2874515 : layout_type (t);
1297 : /* Make sure sizes are shared with the main variant.
1298 : layout_type can't be called after setting TYPE_NEXT_VARIANT,
1299 : as it will overwrite alignment etc. of all variants. */
1300 2874515 : TYPE_SIZE (t) = TYPE_SIZE (m);
1301 2874515 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
1302 2874515 : TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
1303 : }
1304 :
1305 3474514 : TYPE_MAIN_VARIANT (t) = m;
1306 3474514 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
1307 3474514 : TYPE_NEXT_VARIANT (m) = t;
1308 : }
1309 : }
1310 :
1311 : /* Avoid spurious warnings with VLAs (c++/54583). */
1312 65403608 : if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
1313 2013 : suppress_warning (TYPE_SIZE (t), OPT_Wunused);
1314 :
1315 : /* Push these needs up to the ARRAY_TYPE so that initialization takes
1316 : place more easily. */
1317 130807216 : bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t)
1318 65403608 : = TYPE_NEEDS_CONSTRUCTING (elt_type));
1319 130807216 : bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1320 65403608 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
1321 :
1322 62608540 : if (!dependent && t == TYPE_MAIN_VARIANT (t)
1323 99789078 : && !COMPLETE_TYPE_P (t) && COMPLETE_TYPE_P (elt_type))
1324 : {
1325 : /* The element type has been completed since the last time we saw
1326 : this array type; update the layout and 'tor flags for any variants
1327 : that need it. */
1328 2912086 : layout_type (t);
1329 4234831 : for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
1330 : {
1331 1322745 : TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
1332 1322745 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (v) = needs_dtor;
1333 : }
1334 : }
1335 :
1336 : return t;
1337 : }
1338 :
1339 : /* Return an ARRAY_TYPE with element type ELT and length N. */
1340 :
1341 : tree
1342 2236957 : build_array_of_n_type (tree elt, unsigned HOST_WIDE_INT n)
1343 : {
1344 2236957 : return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
1345 : }
1346 :
1347 : /* True iff T is an array of unknown bound. */
1348 :
1349 : bool
1350 7546126 : array_of_unknown_bound_p (const_tree t)
1351 : {
1352 7546126 : return (TREE_CODE (t) == ARRAY_TYPE
1353 7546126 : && !TYPE_DOMAIN (t));
1354 : }
1355 :
1356 : /* True iff T is an N3639 array of runtime bound (VLA). These were approved
1357 : for C++14 but then removed. This should only be used for N3639
1358 : specifically; code wondering more generally if something is a VLA should use
1359 : vla_type_p. */
1360 :
1361 : bool
1362 601180 : array_of_runtime_bound_p (tree t)
1363 : {
1364 601180 : if (!t || TREE_CODE (t) != ARRAY_TYPE)
1365 : return false;
1366 251 : if (variably_modified_type_p (TREE_TYPE (t), NULL_TREE))
1367 : return false;
1368 239 : tree dom = TYPE_DOMAIN (t);
1369 239 : if (!dom)
1370 : return false;
1371 236 : tree max = TYPE_MAX_VALUE (dom);
1372 236 : return (!potential_rvalue_constant_expression (max)
1373 236 : || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)));
1374 : }
1375 :
1376 : /* True iff T is a variable length array. */
1377 :
1378 : bool
1379 44148038 : vla_type_p (tree t)
1380 : {
1381 44965935 : for (; t && TREE_CODE (t) == ARRAY_TYPE;
1382 817897 : t = TREE_TYPE (t))
1383 818078 : if (tree dom = TYPE_DOMAIN (t))
1384 : {
1385 818014 : tree max = TYPE_MAX_VALUE (dom);
1386 818014 : if (!potential_rvalue_constant_expression (max)
1387 818014 : || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)))
1388 : return true;
1389 : }
1390 : return false;
1391 : }
1392 :
1393 :
1394 : /* Return a reference type node of MODE referring to TO_TYPE. If MODE
1395 : is VOIDmode the standard pointer mode will be picked. If RVAL is
1396 : true, return an rvalue reference type, otherwise return an lvalue
1397 : reference type. If a type node exists, reuse it, otherwise create
1398 : a new one. */
1399 : tree
1400 654957204 : cp_build_reference_type_for_mode (tree to_type, machine_mode mode, bool rval)
1401 : {
1402 654957204 : tree lvalue_ref, t;
1403 :
1404 654957204 : if (to_type == error_mark_node)
1405 : return error_mark_node;
1406 :
1407 654957199 : if (TYPE_REF_P (to_type))
1408 : {
1409 2016 : rval = rval && TYPE_REF_IS_RVALUE (to_type);
1410 2016 : to_type = TREE_TYPE (to_type);
1411 : }
1412 :
1413 654957199 : lvalue_ref = build_reference_type_for_mode (to_type, mode, false);
1414 :
1415 654957199 : if (!rval)
1416 : return lvalue_ref;
1417 :
1418 : /* This code to create rvalue reference types is based on and tied
1419 : to the code creating lvalue reference types in the middle-end
1420 : functions build_reference_type_for_mode and build_reference_type.
1421 :
1422 : It works by putting the rvalue reference type nodes after the
1423 : lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
1424 : they will effectively be ignored by the middle end. */
1425 :
1426 113020021 : for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
1427 84059092 : if (TYPE_REF_IS_RVALUE (t))
1428 : return t;
1429 :
1430 28960929 : t = build_distinct_type_copy (lvalue_ref);
1431 :
1432 28960929 : TYPE_REF_IS_RVALUE (t) = true;
1433 28960929 : TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
1434 28960929 : TYPE_NEXT_REF_TO (lvalue_ref) = t;
1435 :
1436 28960929 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
1437 1017186 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1438 27943743 : else if (TYPE_CANONICAL (to_type) != to_type)
1439 15902344 : TYPE_CANONICAL (t)
1440 31804688 : = cp_build_reference_type_for_mode (TYPE_CANONICAL (to_type), mode, rval);
1441 : else
1442 12041399 : TYPE_CANONICAL (t) = t;
1443 :
1444 28960929 : layout_type (t);
1445 :
1446 28960929 : return t;
1447 :
1448 : }
1449 :
1450 : /* Return a reference type node referring to TO_TYPE. If RVAL is
1451 : true, return an rvalue reference type, otherwise return an lvalue
1452 : reference type. If a type node exists, reuse it, otherwise create
1453 : a new one. */
1454 : tree
1455 536749138 : cp_build_reference_type (tree to_type, bool rval)
1456 : {
1457 536749138 : return cp_build_reference_type_for_mode (to_type, VOIDmode, rval);
1458 : }
1459 :
1460 : /* Returns EXPR cast to rvalue reference type, like std::move. */
1461 :
1462 : tree
1463 2180324 : move (tree expr)
1464 : {
1465 2180324 : tree type = TREE_TYPE (expr);
1466 2180324 : gcc_assert (!TYPE_REF_P (type));
1467 2180324 : if (xvalue_p (expr))
1468 : return expr;
1469 2180092 : type = cp_build_reference_type (type, /*rval*/true);
1470 2180092 : return build_static_cast (input_location, type, expr,
1471 2180092 : tf_warning_or_error);
1472 : }
1473 :
1474 : /* Used by the C++ front end to build qualified array types. However,
1475 : the C version of this function does not properly maintain canonical
1476 : types (which are not used in C). */
1477 : tree
1478 27633853 : c_build_qualified_type (tree type, qualifier_set type_quals,
1479 : tree /* orig_qual_type */,
1480 : size_t /* orig_qual_indirect */)
1481 : {
1482 27633853 : cv_qualifier cv_quals;
1483 27633853 : addr_space_t as;
1484 27633853 : std::tie (cv_quals, as) = type_quals.split ();
1485 : /* No address space support yet. */
1486 27633853 : gcc_assert (ADDR_SPACE_GENERIC_P (as));
1487 27633853 : return cp_build_qualified_type (type, cv_quals);
1488 : }
1489 :
1490 :
1491 : /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
1492 : arrays correctly. In particular, if TYPE is an array of T's, and
1493 : TYPE_QUALS is non-empty, returns an array of qualified T's.
1494 :
1495 : FLAGS determines how to deal with ill-formed qualifications. If
1496 : tf_ignore_bad_quals is set, then bad qualifications are dropped
1497 : (this is permitted if TYPE was introduced via a typedef or template
1498 : type parameter). If bad qualifications are dropped and tf_warning
1499 : is set, then a warning is issued for non-const qualifications. If
1500 : tf_ignore_bad_quals is not set and tf_error is not set, we
1501 : return error_mark_node. Otherwise, we issue an error, and ignore
1502 : the qualifications.
1503 :
1504 : Qualification of a reference type is valid when the reference came
1505 : via a typedef or template type argument. [dcl.ref] No such
1506 : dispensation is provided for qualifying a function type. [dcl.fct]
1507 : DR 295 queries this and the proposed resolution brings it into line
1508 : with qualifying a reference. We implement the DR. We also behave
1509 : in a similar manner for restricting non-pointer types. */
1510 :
1511 : tree
1512 19077584843 : cp_build_qualified_type (tree type, cv_qualifier type_quals,
1513 : tsubst_flags_t complain /* = tf_warning_or_error */)
1514 : {
1515 19077584843 : tree result;
1516 19077584843 : auto bad_quals = TYPE_UNQUALIFIED;
1517 :
1518 19077584843 : if (type == error_mark_node)
1519 : return type;
1520 :
1521 19040204502 : if (type_quals == cp_type_quals (type))
1522 : return type;
1523 :
1524 3291512180 : if (TREE_CODE (type) == ARRAY_TYPE)
1525 : {
1526 : /* In C++, the qualification really applies to the array element
1527 : type. Obtain the appropriately qualified element type. */
1528 33930843 : tree t;
1529 33930843 : tree element_type
1530 33930843 : = cp_build_qualified_type (TREE_TYPE (type), type_quals, complain);
1531 :
1532 33930843 : if (element_type == error_mark_node)
1533 : return error_mark_node;
1534 :
1535 : /* See if we already have an identically qualified type. Tests
1536 : should be equivalent to those in check_qualified_type. */
1537 64469523 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1538 37787288 : if (TREE_TYPE (t) == element_type
1539 7781223 : && TYPE_NAME (t) == TYPE_NAME (type)
1540 7248608 : && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
1541 45035896 : && attribute_list_equal (TYPE_ATTRIBUTES (t),
1542 7248608 : TYPE_ATTRIBUTES (type)))
1543 : break;
1544 :
1545 33930843 : if (!t)
1546 : {
1547 : /* If we already know the dependentness, tell the array type
1548 : constructor. This is important for module streaming, as we cannot
1549 : dynamically determine that on read in. */
1550 26682235 : t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
1551 26682235 : TYPE_DEPENDENT_P_VALID (type)
1552 566392 : ? int (TYPE_DEPENDENT_P (type)) : -1);
1553 :
1554 : /* Keep the typedef name. */
1555 26682235 : if (TYPE_NAME (t) != TYPE_NAME (type))
1556 : {
1557 14382 : t = build_variant_type_copy (t);
1558 14382 : TYPE_NAME (t) = TYPE_NAME (type);
1559 14382 : SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
1560 14382 : TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
1561 : }
1562 : }
1563 :
1564 : /* Even if we already had this variant, we update
1565 : TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
1566 : they changed since the variant was originally created.
1567 :
1568 : This seems hokey; if there is some way to use a previous
1569 : variant *without* coming through here,
1570 : TYPE_NEEDS_CONSTRUCTING will never be updated. */
1571 67861686 : TYPE_NEEDS_CONSTRUCTING (t)
1572 33930843 : = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
1573 67861686 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1574 33930843 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
1575 33930843 : return t;
1576 : }
1577 3257581337 : else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
1578 : {
1579 7 : tree t = PACK_EXPANSION_PATTERN (type);
1580 :
1581 7 : t = cp_build_qualified_type (t, type_quals, complain);
1582 7 : return make_pack_expansion (t, complain);
1583 : }
1584 :
1585 : /* A reference or method type shall not be cv-qualified.
1586 : [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
1587 : (in CD1) we always ignore extra cv-quals on functions. */
1588 :
1589 : /* [dcl.ref/1] Cv-qualified references are ill-formed except when
1590 : the cv-qualifiers are introduced through the use of a typedef-name
1591 : ([dcl.typedef], [temp.param]) or decltype-specifier
1592 : ([dcl.type.decltype]),in which case the cv-qualifiers are
1593 : ignored. */
1594 3257581330 : if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
1595 3257581330 : && (TYPE_REF_P (type)
1596 1021167867 : || FUNC_OR_METHOD_TYPE_P (type)))
1597 : {
1598 428275 : if (TYPE_REF_P (type)
1599 428275 : && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
1600 : bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1601 428275 : type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1602 : }
1603 :
1604 : /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1605 3257581330 : if (TREE_CODE (type) == FUNCTION_TYPE)
1606 830 : type_quals |= type_memfn_quals (type);
1607 :
1608 : /* A restrict-qualified type must be a pointer (or reference)
1609 : to object or incomplete type. */
1610 3257581330 : if ((type_quals & TYPE_QUAL_RESTRICT)
1611 8777482 : && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1612 8777445 : && TREE_CODE (type) != TYPENAME_TYPE
1613 3266358769 : && !INDIRECT_TYPE_P (type))
1614 : {
1615 25 : bad_quals |= TYPE_QUAL_RESTRICT;
1616 25 : type_quals &= ~TYPE_QUAL_RESTRICT;
1617 : }
1618 :
1619 3257581330 : if (bad_quals == TYPE_UNQUALIFIED
1620 291436 : || (complain & tf_ignore_bad_quals))
1621 : /*OK*/;
1622 12 : else if (!(complain & tf_error))
1623 0 : return error_mark_node;
1624 : else
1625 : {
1626 12 : tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
1627 12 : error ("%qV qualifiers cannot be applied to %qT",
1628 : bad_type, type);
1629 : }
1630 :
1631 : /* Retrieve (or create) the appropriately qualified variant. */
1632 3257581330 : result = build_qualified_type (type, type_quals);
1633 :
1634 3257581330 : return result;
1635 : }
1636 :
1637 : /* Return a FUNCTION_TYPE for a function returning VALUE_TYPE
1638 : with ARG_TYPES arguments. Wrapper around build_function_type
1639 : which ensures TYPE_NO_NAMED_ARGS_STDARG_P is set if ARG_TYPES
1640 : is NULL for C++26. */
1641 :
1642 : tree
1643 275213165 : cp_build_function_type (tree value_type, tree arg_types)
1644 : {
1645 309924353 : return build_function_type (value_type, arg_types,
1646 275213165 : cxx_dialect >= cxx26
1647 275213165 : && arg_types == NULL_TREE);
1648 : }
1649 :
1650 : /* Return TYPE with const and volatile removed. */
1651 :
1652 : tree
1653 1782847280 : cv_unqualified (tree type)
1654 : {
1655 1782847280 : if (type == error_mark_node)
1656 : return type;
1657 :
1658 1782847035 : auto quals = cp_type_quals (type);
1659 1782847035 : quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
1660 1782847035 : return cp_build_qualified_type (type, quals);
1661 : }
1662 :
1663 : /* Subroutine of strip_typedefs. We want to apply to RESULT the attributes
1664 : from ATTRIBS that affect type identity, and no others. If any are not
1665 : applied, set *remove_attributes to true. */
1666 :
1667 : static tree
1668 10368560 : apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
1669 : {
1670 10368560 : tree first_ident = NULL_TREE;
1671 10368560 : tree new_attribs = NULL_TREE;
1672 10368560 : tree *p = &new_attribs;
1673 :
1674 10368560 : if (OVERLOAD_TYPE_P (result))
1675 : {
1676 : /* On classes and enums all attributes are ingrained. */
1677 10367569 : gcc_assert (attribs == TYPE_ATTRIBUTES (result));
1678 : return result;
1679 : }
1680 :
1681 1985 : for (tree a = attribs; a; a = TREE_CHAIN (a))
1682 : {
1683 994 : const attribute_spec *as
1684 994 : = lookup_attribute_spec (get_attribute_name (a));
1685 994 : if (as && as->affects_type_identity)
1686 : {
1687 178 : if (!first_ident)
1688 : first_ident = a;
1689 0 : else if (first_ident == error_mark_node)
1690 : {
1691 0 : *p = tree_cons (TREE_PURPOSE (a), TREE_VALUE (a), NULL_TREE);
1692 0 : p = &TREE_CHAIN (*p);
1693 : }
1694 : }
1695 816 : else if (first_ident && first_ident != error_mark_node)
1696 : {
1697 0 : for (tree a2 = first_ident; a2 != a; a2 = TREE_CHAIN (a2))
1698 : {
1699 0 : *p = tree_cons (TREE_PURPOSE (a2), TREE_VALUE (a2), NULL_TREE);
1700 0 : p = &TREE_CHAIN (*p);
1701 : }
1702 0 : first_ident = error_mark_node;
1703 : }
1704 : }
1705 991 : if (first_ident != error_mark_node)
1706 991 : new_attribs = first_ident;
1707 :
1708 991 : if (first_ident == attribs)
1709 : /* All attributes affected type identity. */;
1710 : else
1711 813 : *remove_attributes = true;
1712 :
1713 991 : return cp_build_type_attribute_variant (result, new_attribs);
1714 : }
1715 :
1716 : /* Builds a qualified variant of T that is either not a typedef variant
1717 : (the default behavior) or not a typedef variant of a user-facing type
1718 : (if FLAGS contains STF_USER_VISIBLE). If T is not a type, then this
1719 : just dispatches to strip_typedefs_expr.
1720 :
1721 : E.g. consider the following declarations:
1722 : typedef const int ConstInt;
1723 : typedef ConstInt* PtrConstInt;
1724 : If T is PtrConstInt, this function returns a type representing
1725 : const int*.
1726 : In other words, if T is a typedef, the function returns the underlying type.
1727 : The cv-qualification and attributes of the type returned match the
1728 : input type.
1729 : They will always be compatible types.
1730 : The returned type is built so that all of its subtypes
1731 : recursively have their typedefs stripped as well.
1732 :
1733 : This is different from just returning TYPE_CANONICAL (T)
1734 : Because of several reasons:
1735 : * If T is a type that needs structural equality
1736 : its TYPE_CANONICAL (T) will be NULL.
1737 : * TYPE_CANONICAL (T) doesn't carry type attributes
1738 : and loses template parameter names.
1739 :
1740 : If REMOVE_ATTRIBUTES is non-null, also strip attributes that don't
1741 : affect type identity, and set the referent to true if any were
1742 : stripped. */
1743 :
1744 : tree
1745 3021243705 : strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
1746 : unsigned int flags /* = 0 */)
1747 : {
1748 3021243705 : tree result = NULL, type = NULL, t0 = NULL;
1749 :
1750 3021243705 : if (!t || t == error_mark_node)
1751 : return t;
1752 :
1753 2981151305 : if (!TYPE_P (t))
1754 204528353 : return strip_typedefs_expr (t, remove_attributes, flags);
1755 :
1756 2776622952 : if (t == TYPE_CANONICAL (t))
1757 : return t;
1758 :
1759 1088620512 : if (typedef_variant_p (t))
1760 : {
1761 361495782 : if ((flags & STF_USER_VISIBLE)
1762 361495782 : && !user_facing_original_type_p (t))
1763 : return t;
1764 :
1765 361495654 : if ((flags & STF_KEEP_INJ_CLASS_NAME)
1766 35623 : && CLASS_TYPE_P (t)
1767 361505406 : && DECL_SELF_REFERENCE_P (TYPE_NAME (t)))
1768 : return t;
1769 :
1770 361495653 : if (dependent_opaque_alias_p (t))
1771 : return t;
1772 :
1773 361490783 : if (alias_template_specialization_p (t, nt_opaque))
1774 : {
1775 104174863 : if (dependent_alias_template_spec_p (t, nt_opaque)
1776 104174863 : && !(flags & STF_STRIP_DEPENDENT))
1777 : /* DR 1558: However, if the template-id is dependent, subsequent
1778 : template argument substitution still applies to the template-id. */
1779 : return t;
1780 : }
1781 : else
1782 : /* If T is a non-template alias or typedef, we can assume that
1783 : instantiating its definition will hit any substitution failure,
1784 : so we don't need to retain it here as well. */
1785 257315920 : flags |= STF_STRIP_DEPENDENT;
1786 :
1787 346467238 : result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
1788 : remove_attributes, flags);
1789 346467238 : goto stripped;
1790 : }
1791 :
1792 727124730 : switch (TREE_CODE (t))
1793 : {
1794 11035710 : case POINTER_TYPE:
1795 11035710 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1796 11035710 : result = build_pointer_type_for_mode (type, TYPE_MODE (t), false);
1797 11035710 : break;
1798 102305722 : case REFERENCE_TYPE:
1799 102305722 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1800 102305722 : result = cp_build_reference_type_for_mode (type, TYPE_MODE (t), TYPE_REF_IS_RVALUE (t));
1801 102305722 : break;
1802 325931 : case OFFSET_TYPE:
1803 325931 : t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags);
1804 325931 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1805 325931 : result = build_offset_type (t0, type);
1806 325931 : break;
1807 26120051 : case RECORD_TYPE:
1808 26120051 : if (TYPE_PTRMEMFUNC_P (t))
1809 : {
1810 1585364 : t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t),
1811 : remove_attributes, flags);
1812 1585364 : result = build_ptrmemfunc_type (t0);
1813 : }
1814 : break;
1815 1846575 : case ARRAY_TYPE:
1816 1846575 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1817 1846575 : t0 = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags);
1818 1846575 : gcc_checking_assert (TYPE_DEPENDENT_P_VALID (t)
1819 : || !dependent_type_p (t));
1820 1846575 : result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t));
1821 1846575 : break;
1822 7979514 : case FUNCTION_TYPE:
1823 7979514 : case METHOD_TYPE:
1824 7979514 : {
1825 7979514 : tree arg_types = NULL, arg_node, arg_node2, arg_type;
1826 7979514 : bool changed;
1827 :
1828 : /* Because we stomp on TREE_PURPOSE of TYPE_ARG_TYPES in many places
1829 : around the compiler (e.g. cp_parser_late_parsing_default_args), we
1830 : can't expect that re-hashing a function type will find a previous
1831 : equivalent type, so try to reuse the input type if nothing has
1832 : changed. If the type is itself a variant, that will change. */
1833 7979514 : bool is_variant = typedef_variant_p (t);
1834 7979514 : if (remove_attributes
1835 7979514 : && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t)))
1836 : is_variant = true;
1837 :
1838 7979514 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1839 7979514 : tree canon_spec = (flag_noexcept_type
1840 7968565 : ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t))
1841 7979514 : : NULL_TREE);
1842 10595472 : changed = (type != TREE_TYPE (t) || is_variant
1843 10595269 : || TYPE_RAISES_EXCEPTIONS (t) != canon_spec);
1844 :
1845 7979514 : for (arg_node = TYPE_ARG_TYPES (t);
1846 12364125 : arg_node;
1847 4384611 : arg_node = TREE_CHAIN (arg_node))
1848 : {
1849 11556235 : if (arg_node == void_list_node)
1850 : break;
1851 4384611 : arg_type = strip_typedefs (TREE_VALUE (arg_node),
1852 : remove_attributes, flags);
1853 4384611 : gcc_assert (arg_type);
1854 4384611 : if (arg_type == TREE_VALUE (arg_node) && !changed)
1855 4123054 : continue;
1856 :
1857 261557 : if (!changed)
1858 : {
1859 40444 : changed = true;
1860 40444 : for (arg_node2 = TYPE_ARG_TYPES (t);
1861 51540 : arg_node2 != arg_node;
1862 11096 : arg_node2 = TREE_CHAIN (arg_node2))
1863 11096 : arg_types
1864 11096 : = tree_cons (TREE_PURPOSE (arg_node2),
1865 11096 : TREE_VALUE (arg_node2), arg_types);
1866 : }
1867 :
1868 261557 : arg_types
1869 261557 : = tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
1870 : }
1871 :
1872 7979514 : if (!changed)
1873 : return t;
1874 :
1875 5405678 : if (arg_types)
1876 62698 : arg_types = nreverse (arg_types);
1877 :
1878 : /* A list of parameters not ending with an ellipsis
1879 : must end with void_list_node. */
1880 5405678 : if (arg_node)
1881 5405637 : arg_types = chainon (arg_types, void_list_node);
1882 :
1883 5405678 : if (TREE_CODE (t) == METHOD_TYPE)
1884 : {
1885 28666 : tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
1886 28666 : gcc_assert (class_type);
1887 28666 : result =
1888 28666 : build_method_type_directly (class_type, type,
1889 28666 : TREE_CHAIN (arg_types));
1890 : }
1891 : else
1892 : {
1893 16131036 : result = build_function_type (type, arg_types,
1894 5377012 : TYPE_NO_NAMED_ARGS_STDARG_P (t));
1895 5377012 : result = apply_memfn_quals (result, type_memfn_quals (t));
1896 : }
1897 :
1898 16217034 : result = build_cp_fntype_variant (result,
1899 : type_memfn_rqual (t), canon_spec,
1900 5405678 : TYPE_HAS_LATE_RETURN_TYPE (t));
1901 : }
1902 5405678 : break;
1903 78629920 : case TYPENAME_TYPE:
1904 78629920 : {
1905 78629920 : bool changed = false;
1906 78629920 : tree fullname = TYPENAME_TYPE_FULLNAME (t);
1907 78629920 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
1908 78629920 : && TREE_OPERAND (fullname, 1))
1909 : {
1910 4928628 : tree args = TREE_OPERAND (fullname, 1);
1911 4928628 : tree new_args = copy_node (args);
1912 18603979 : for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
1913 : {
1914 8746723 : tree arg = TREE_VEC_ELT (args, i);
1915 8746723 : tree strip_arg = strip_typedefs (arg, remove_attributes, flags);
1916 8746723 : TREE_VEC_ELT (new_args, i) = strip_arg;
1917 8746723 : if (strip_arg != arg)
1918 255188 : changed = true;
1919 : }
1920 4928628 : if (changed)
1921 : {
1922 255188 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
1923 255188 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
1924 255188 : fullname
1925 255188 : = lookup_template_function (TREE_OPERAND (fullname, 0),
1926 : new_args);
1927 : }
1928 : else
1929 4673440 : ggc_free (new_args);
1930 : }
1931 78629920 : tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes, flags);
1932 78629920 : if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t))
1933 : return t;
1934 4813138 : tree name = fullname;
1935 4813138 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
1936 279106 : name = TREE_OPERAND (fullname, 0);
1937 : /* Use build_typename_type rather than make_typename_type because we
1938 : don't want to resolve it here, just strip typedefs. */
1939 4813138 : result = build_typename_type (ctx, name, fullname, typename_type);
1940 : }
1941 4813138 : break;
1942 13524272 : case DECLTYPE_TYPE:
1943 13524272 : result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t),
1944 : remove_attributes, flags);
1945 13524272 : if (result == DECLTYPE_TYPE_EXPR (t))
1946 : result = NULL_TREE;
1947 : else
1948 377090 : result = (finish_decltype_type
1949 377090 : (result,
1950 377090 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
1951 : tf_none));
1952 : break;
1953 837189 : case TRAIT_TYPE:
1954 837189 : {
1955 837189 : tree type1 = strip_typedefs (TRAIT_TYPE_TYPE1 (t),
1956 : remove_attributes, flags);
1957 837189 : tree type2 = strip_typedefs (TRAIT_TYPE_TYPE2 (t),
1958 : remove_attributes, flags);
1959 837189 : if (type1 == TRAIT_TYPE_TYPE1 (t) && type2 == TRAIT_TYPE_TYPE2 (t))
1960 : result = NULL_TREE;
1961 : else
1962 0 : result = finish_trait_type (TRAIT_TYPE_KIND (t), type1, type2,
1963 : tf_warning_or_error);
1964 : }
1965 : break;
1966 26883524 : case TYPE_PACK_EXPANSION:
1967 26883524 : {
1968 26883524 : tree pat = PACK_EXPANSION_PATTERN (t);
1969 26883524 : if (TYPE_P (pat))
1970 : {
1971 26883524 : type = strip_typedefs (pat, remove_attributes, flags);
1972 26883524 : if (type != pat)
1973 : {
1974 306810 : result = build_distinct_type_copy (t);
1975 306810 : PACK_EXPANSION_PATTERN (result) = type;
1976 : }
1977 : }
1978 : }
1979 : break;
1980 : default:
1981 : break;
1982 : }
1983 :
1984 128002018 : if (!result)
1985 522732094 : result = TYPE_MAIN_VARIANT (t);
1986 :
1987 128002018 : stripped:
1988 : /*gcc_assert (!typedef_variant_p (result)
1989 : || dependent_alias_template_spec_p (result, nt_opaque)
1990 : || ((flags & STF_USER_VISIBLE)
1991 : && !user_facing_original_type_p (result)));*/
1992 :
1993 997201350 : if (COMPLETE_TYPE_P (result) && !COMPLETE_TYPE_P (t))
1994 : /* If RESULT is complete and T isn't, it's likely the case that T
1995 : is a variant of RESULT which hasn't been updated yet. Skip the
1996 : attribute handling. */;
1997 : else
1998 : {
1999 997201344 : if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
2000 997201344 : || TYPE_ALIGN (t) != TYPE_ALIGN (result))
2001 : {
2002 21 : gcc_assert (TYPE_USER_ALIGN (t));
2003 21 : if (remove_attributes)
2004 12 : *remove_attributes = true;
2005 : else
2006 : {
2007 9 : if (TYPE_ALIGN (t) == TYPE_ALIGN (result))
2008 0 : result = build_variant_type_copy (result);
2009 : else
2010 9 : result = build_aligned_type (result, TYPE_ALIGN (t));
2011 9 : TYPE_USER_ALIGN (result) = true;
2012 : }
2013 : }
2014 :
2015 997201344 : if (TYPE_ATTRIBUTES (t))
2016 : {
2017 10378902 : if (remove_attributes)
2018 10368560 : result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t),
2019 : remove_attributes);
2020 : else
2021 10342 : result = cp_build_type_attribute_variant (result,
2022 10342 : TYPE_ATTRIBUTES (t));
2023 : }
2024 : }
2025 :
2026 997201350 : return cp_build_qualified_type (result, cp_type_quals (t));
2027 : }
2028 :
2029 : /* Like strip_typedefs above, but works on expressions (and other
2030 : non-types such as TREE_VEC), so that in
2031 :
2032 : template<class T> struct A
2033 : {
2034 : typedef T TT;
2035 : B<sizeof(TT)> b;
2036 : };
2037 :
2038 : sizeof(TT) is replaced by sizeof(T). */
2039 :
2040 : tree
2041 391639626 : strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags)
2042 : {
2043 391639626 : unsigned i,n;
2044 391639626 : tree r, type, *ops;
2045 391639626 : enum tree_code code;
2046 :
2047 391639626 : if (t == NULL_TREE || t == error_mark_node)
2048 : return t;
2049 :
2050 391639626 : STRIP_ANY_LOCATION_WRAPPER (t);
2051 :
2052 391639626 : if (DECL_P (t) || CONSTANT_CLASS_P (t))
2053 : return t;
2054 :
2055 218099037 : code = TREE_CODE (t);
2056 218099037 : switch (code)
2057 : {
2058 : case IDENTIFIER_NODE:
2059 : case TEMPLATE_PARM_INDEX:
2060 : case OVERLOAD:
2061 : case BASELINK:
2062 : case ARGUMENT_PACK_SELECT:
2063 : case REQUIRES_EXPR:
2064 : return t;
2065 :
2066 2383673 : case TRAIT_EXPR:
2067 2383673 : {
2068 2383673 : tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t),
2069 : remove_attributes, flags);
2070 2383673 : tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t),
2071 : remove_attributes, flags);
2072 2383673 : if (type1 == TRAIT_EXPR_TYPE1 (t)
2073 2383673 : && type2 == TRAIT_EXPR_TYPE2 (t))
2074 : return t;
2075 53728 : r = copy_node (t);
2076 53728 : TRAIT_EXPR_TYPE1 (r) = type1;
2077 53728 : TRAIT_EXPR_TYPE2 (r) = type2;
2078 53728 : return r;
2079 : }
2080 :
2081 1028921 : case TREE_LIST:
2082 1028921 : {
2083 1028921 : bool changed = false;
2084 1028921 : auto_vec<tree_pair, 4> vec;
2085 1028921 : r = t;
2086 2196545 : for (; t; t = TREE_CHAIN (t))
2087 : {
2088 1167624 : tree purpose = strip_typedefs (TREE_PURPOSE (t),
2089 1167624 : remove_attributes, flags);
2090 1167624 : tree value = strip_typedefs (TREE_VALUE (t),
2091 1167624 : remove_attributes, flags);
2092 1167624 : if (purpose != TREE_PURPOSE (t) || value != TREE_VALUE (t))
2093 : changed = true;
2094 1167624 : vec.safe_push ({purpose, value});
2095 : }
2096 1028921 : if (changed)
2097 : {
2098 243475 : r = NULL_TREE;
2099 796472 : for (int i = vec.length () - 1; i >= 0; i--)
2100 309522 : r = tree_cons (vec[i].first, vec[i].second, r);
2101 : }
2102 1028921 : return r;
2103 1028921 : }
2104 :
2105 21240048 : case TREE_VEC:
2106 21240048 : {
2107 21240048 : bool changed = false;
2108 21240048 : releasing_vec vec;
2109 21240048 : n = TREE_VEC_LENGTH (t);
2110 21240048 : vec_safe_reserve (vec, n);
2111 66993892 : for (i = 0; i < n; ++i)
2112 : {
2113 24513796 : tree op = strip_typedefs (TREE_VEC_ELT (t, i),
2114 24513796 : remove_attributes, flags);
2115 24513796 : vec->quick_push (op);
2116 24513796 : if (op != TREE_VEC_ELT (t, i))
2117 217247 : changed = true;
2118 : }
2119 21240048 : if (changed)
2120 : {
2121 217247 : r = copy_node (t);
2122 671972 : for (i = 0; i < n; ++i)
2123 237478 : TREE_VEC_ELT (r, i) = (*vec)[i];
2124 434494 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
2125 434494 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
2126 : }
2127 : else
2128 : r = t;
2129 21240048 : return r;
2130 21240048 : }
2131 :
2132 308677 : case CONSTRUCTOR:
2133 308677 : {
2134 308677 : bool changed = false;
2135 308677 : vec<constructor_elt, va_gc> *vec
2136 308677 : = vec_safe_copy (CONSTRUCTOR_ELTS (t));
2137 308677 : n = CONSTRUCTOR_NELTS (t);
2138 308677 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
2139 638011 : for (i = 0; i < n; ++i)
2140 : {
2141 20657 : constructor_elt *e = &(*vec)[i];
2142 20657 : tree op = strip_typedefs (e->value, remove_attributes, flags);
2143 20657 : if (op != e->value)
2144 : {
2145 6 : changed = true;
2146 6 : e->value = op;
2147 : }
2148 20657 : gcc_checking_assert
2149 : (e->index == strip_typedefs (e->index, remove_attributes,
2150 : flags));
2151 : }
2152 :
2153 308677 : if (!changed && type == TREE_TYPE (t))
2154 : {
2155 286072 : vec_free (vec);
2156 : return t;
2157 : }
2158 : else
2159 : {
2160 22605 : r = copy_node (t);
2161 22605 : TREE_TYPE (r) = type;
2162 22605 : CONSTRUCTOR_ELTS (r) = vec;
2163 22605 : return r;
2164 : }
2165 : }
2166 :
2167 : case LAMBDA_EXPR:
2168 : case STMT_EXPR:
2169 : /* ^^alias represents the alias itself, not the underlying type. */
2170 : case REFLECT_EXPR:
2171 : return t;
2172 :
2173 116781908 : default:
2174 116781908 : break;
2175 : }
2176 :
2177 116781908 : gcc_assert (EXPR_P (t));
2178 :
2179 116781908 : n = cp_tree_operand_length (t);
2180 116781908 : ops = XALLOCAVEC (tree, n);
2181 116781908 : type = TREE_TYPE (t);
2182 :
2183 116781908 : switch (code)
2184 : {
2185 7841990 : CASE_CONVERT:
2186 7841990 : case IMPLICIT_CONV_EXPR:
2187 7841990 : case DYNAMIC_CAST_EXPR:
2188 7841990 : case STATIC_CAST_EXPR:
2189 7841990 : case CONST_CAST_EXPR:
2190 7841990 : case REINTERPRET_CAST_EXPR:
2191 7841990 : case CAST_EXPR:
2192 7841990 : case NEW_EXPR:
2193 7841990 : type = strip_typedefs (type, remove_attributes, flags);
2194 : /* fallthrough */
2195 :
2196 116781908 : default:
2197 384484137 : for (i = 0; i < n; ++i)
2198 267702229 : ops[i] = strip_typedefs (TREE_OPERAND (t, i),
2199 : remove_attributes, flags);
2200 : break;
2201 : }
2202 :
2203 : /* If nothing changed, return t. */
2204 378352129 : for (i = 0; i < n; ++i)
2205 265558771 : if (ops[i] != TREE_OPERAND (t, i))
2206 : break;
2207 116781908 : if (i == n && type == TREE_TYPE (t))
2208 : return t;
2209 :
2210 4261568 : r = copy_node (t);
2211 4261568 : TREE_TYPE (r) = type;
2212 13554201 : for (i = 0; i < n; ++i)
2213 9292633 : TREE_OPERAND (r, i) = ops[i];
2214 : return r;
2215 : }
2216 :
2217 : /* Makes a copy of BINFO and TYPE, which is to be inherited into a
2218 : graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
2219 : and we do a shallow copy. If BINFO is non-NULL, we do a deep copy.
2220 : VIRT indicates whether TYPE is inherited virtually or not.
2221 : IGO_PREV points at the previous binfo of the inheritance graph
2222 : order chain. The newly copied binfo's TREE_CHAIN forms this
2223 : ordering.
2224 :
2225 : The CLASSTYPE_VBASECLASSES vector of T is constructed in the
2226 : correct order. That is in the order the bases themselves should be
2227 : constructed in.
2228 :
2229 : The BINFO_INHERITANCE of a virtual base class points to the binfo
2230 : of the most derived type. ??? We could probably change this so that
2231 : BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
2232 : remove a field. They currently can only differ for primary virtual
2233 : virtual bases. */
2234 :
2235 : tree
2236 37850577 : copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
2237 : {
2238 37850577 : tree new_binfo;
2239 :
2240 37850577 : if (virt)
2241 : {
2242 : /* See if we've already made this virtual base. */
2243 289397 : new_binfo = binfo_for_vbase (type, t);
2244 289397 : if (new_binfo)
2245 : return new_binfo;
2246 : }
2247 :
2248 68448618 : new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
2249 37780774 : BINFO_TYPE (new_binfo) = type;
2250 :
2251 : /* Chain it into the inheritance graph. */
2252 37780774 : TREE_CHAIN (*igo_prev) = new_binfo;
2253 37780774 : *igo_prev = new_binfo;
2254 :
2255 68448618 : if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
2256 : {
2257 30667835 : int ix;
2258 30667835 : tree base_binfo;
2259 :
2260 30667835 : gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
2261 :
2262 30667835 : BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
2263 30667835 : BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
2264 :
2265 : /* We do not need to copy the accesses, as they are read only. */
2266 30667835 : BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
2267 :
2268 : /* Recursively copy base binfos of BINFO. */
2269 34912391 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
2270 : {
2271 4244556 : tree new_base_binfo;
2272 4244556 : new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
2273 : t, igo_prev,
2274 4244556 : BINFO_VIRTUAL_P (base_binfo));
2275 :
2276 4244556 : if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
2277 4023990 : BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
2278 4244556 : BINFO_BASE_APPEND (new_binfo, new_base_binfo);
2279 : }
2280 : }
2281 : else
2282 7112939 : BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
2283 :
2284 37780774 : if (virt)
2285 : {
2286 : /* Push it onto the list after any virtual bases it contains
2287 : will have been pushed. */
2288 219594 : CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo);
2289 219594 : BINFO_VIRTUAL_P (new_binfo) = 1;
2290 219594 : BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
2291 : }
2292 :
2293 : return new_binfo;
2294 : }
2295 :
2296 : /* Hashing of lists so that we don't make duplicates.
2297 : The entry point is `list_hash_canon'. */
2298 :
2299 : struct list_proxy
2300 : {
2301 : tree purpose;
2302 : tree value;
2303 : tree chain;
2304 : };
2305 :
2306 : struct list_hasher : ggc_ptr_hash<tree_node>
2307 : {
2308 : typedef list_proxy *compare_type;
2309 :
2310 : static hashval_t hash (tree);
2311 : static bool equal (tree, list_proxy *);
2312 : };
2313 :
2314 : /* Now here is the hash table. When recording a list, it is added
2315 : to the slot whose index is the hash code mod the table size.
2316 : Note that the hash table is used for several kinds of lists.
2317 : While all these live in the same table, they are completely independent,
2318 : and the hash code is computed differently for each of these. */
2319 :
2320 : static GTY (()) hash_table<list_hasher> *list_hash_table;
2321 :
2322 : /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
2323 : for a node we are thinking about adding). */
2324 :
2325 : bool
2326 2602615392 : list_hasher::equal (tree t, list_proxy *proxy)
2327 : {
2328 2602615392 : return (TREE_VALUE (t) == proxy->value
2329 174663312 : && TREE_PURPOSE (t) == proxy->purpose
2330 2775196253 : && TREE_CHAIN (t) == proxy->chain);
2331 : }
2332 :
2333 : /* Compute a hash code for a list (chain of TREE_LIST nodes
2334 : with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
2335 : TREE_COMMON slots), by adding the hash codes of the individual entries. */
2336 :
2337 : static hashval_t
2338 2414683588 : list_hash_pieces (tree purpose, tree value, tree chain)
2339 : {
2340 2414683588 : hashval_t hashcode = 0;
2341 :
2342 2414683588 : if (chain)
2343 2414545461 : hashcode += TREE_HASH (chain);
2344 :
2345 2414683588 : if (value)
2346 2414683588 : hashcode += TREE_HASH (value);
2347 : else
2348 0 : hashcode += 1007;
2349 2414683588 : if (purpose)
2350 210668907 : hashcode += TREE_HASH (purpose);
2351 : else
2352 2204014681 : hashcode += 1009;
2353 2414683588 : return hashcode;
2354 : }
2355 :
2356 : /* Hash an already existing TREE_LIST. */
2357 :
2358 : hashval_t
2359 2095249879 : list_hasher::hash (tree t)
2360 : {
2361 2095249879 : return list_hash_pieces (TREE_PURPOSE (t),
2362 2095249879 : TREE_VALUE (t),
2363 2095249879 : TREE_CHAIN (t));
2364 : }
2365 :
2366 : /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
2367 : object for an identical list if one already exists. Otherwise, build a
2368 : new one, and record it as the canonical object. */
2369 :
2370 : tree
2371 319433709 : hash_tree_cons (tree purpose, tree value, tree chain)
2372 : {
2373 319433709 : int hashcode = 0;
2374 319433709 : tree *slot;
2375 319433709 : struct list_proxy proxy;
2376 :
2377 : /* Hash the list node. */
2378 319433709 : hashcode = list_hash_pieces (purpose, value, chain);
2379 : /* Create a proxy for the TREE_LIST we would like to create. We
2380 : don't actually create it so as to avoid creating garbage. */
2381 319433709 : proxy.purpose = purpose;
2382 319433709 : proxy.value = value;
2383 319433709 : proxy.chain = chain;
2384 : /* See if it is already in the table. */
2385 319433709 : slot = list_hash_table->find_slot_with_hash (&proxy, hashcode, INSERT);
2386 : /* If not, create a new node. */
2387 319433709 : if (!*slot)
2388 153276701 : *slot = tree_cons (purpose, value, chain);
2389 319433709 : return (tree) *slot;
2390 : }
2391 :
2392 : /* Constructor for hashed lists. */
2393 :
2394 : tree
2395 2313074 : hash_tree_chain (tree value, tree chain)
2396 : {
2397 2313074 : return hash_tree_cons (NULL_TREE, value, chain);
2398 : }
2399 :
2400 : void
2401 0 : debug_binfo (tree elem)
2402 : {
2403 0 : HOST_WIDE_INT n;
2404 0 : tree virtuals;
2405 :
2406 0 : fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
2407 : "\nvtable type:\n",
2408 0 : TYPE_NAME_STRING (BINFO_TYPE (elem)),
2409 0 : TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
2410 0 : debug_tree (BINFO_TYPE (elem));
2411 0 : if (BINFO_VTABLE (elem))
2412 0 : fprintf (stderr, "vtable decl \"%s\"\n",
2413 0 : IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
2414 : else
2415 0 : fprintf (stderr, "no vtable decl yet\n");
2416 0 : fprintf (stderr, "virtuals:\n");
2417 0 : virtuals = BINFO_VIRTUALS (elem);
2418 0 : n = 0;
2419 :
2420 0 : while (virtuals)
2421 : {
2422 0 : tree fndecl = TREE_VALUE (virtuals);
2423 0 : fprintf (stderr, "%s [" HOST_WIDE_INT_PRINT_DEC " =? "
2424 : HOST_WIDE_INT_PRINT_DEC "]\n",
2425 0 : IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
2426 0 : n, TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
2427 0 : ++n;
2428 0 : virtuals = TREE_CHAIN (virtuals);
2429 : }
2430 0 : }
2431 :
2432 : /* Build a representation for the qualified name SCOPE::NAME. TYPE is
2433 : the type of the result expression, if known, or NULL_TREE if the
2434 : resulting expression is type-dependent. If TEMPLATE_P is true,
2435 : NAME is known to be a template because the user explicitly used the
2436 : "template" keyword after the "::".
2437 :
2438 : All SCOPE_REFs should be built by use of this function. */
2439 :
2440 : tree
2441 157190300 : build_qualified_name (tree type, tree scope, tree name, bool template_p)
2442 : {
2443 157190300 : tree t;
2444 157190300 : if (type == error_mark_node
2445 157190300 : || scope == error_mark_node
2446 157190297 : || name == error_mark_node)
2447 : return error_mark_node;
2448 157190297 : gcc_assert (TREE_CODE (name) != SCOPE_REF);
2449 157190297 : t = build2 (SCOPE_REF, type, scope, name);
2450 157190297 : QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
2451 157190297 : PTRMEM_OK_P (t) = true;
2452 157190297 : if (type)
2453 10595017 : t = convert_from_reference (t);
2454 : return t;
2455 : }
2456 :
2457 : /* Like check_qualified_type, but also check ref-qualifier, exception
2458 : specification, and whether the return type was specified after the
2459 : parameters. */
2460 :
2461 : static bool
2462 1294030182 : cp_check_qualified_type (const_tree cand, const_tree base,
2463 : cv_qualifier type_quals, cp_ref_qualifier rqual,
2464 : tree raises, bool late)
2465 : {
2466 1294030182 : return (TYPE_QUALS (cand) == type_quals
2467 1293933730 : && check_base_type (cand, base)
2468 1293816747 : && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand),
2469 : ce_exact)
2470 619414347 : && TYPE_HAS_LATE_RETURN_TYPE (cand) == late
2471 578498365 : && type_memfn_rqual (cand) == rqual);
2472 : }
2473 :
2474 : /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */
2475 :
2476 : tree
2477 743796 : build_ref_qualified_type (tree type, cp_ref_qualifier rqual)
2478 : {
2479 743796 : tree raises = TYPE_RAISES_EXCEPTIONS (type);
2480 743796 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
2481 743796 : return build_cp_fntype_variant (type, rqual, raises, late);
2482 : }
2483 :
2484 : tree
2485 193399 : make_binding_vec (tree name, unsigned clusters MEM_STAT_DECL)
2486 : {
2487 : /* Stored in an unsigned short, but we're limited to the number of
2488 : modules anyway. */
2489 193399 : gcc_checking_assert (clusters <= (unsigned short)(~0));
2490 193399 : size_t length = (offsetof (tree_binding_vec, vec)
2491 : + clusters * sizeof (binding_cluster));
2492 193399 : tree vec = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2493 193399 : TREE_SET_CODE (vec, BINDING_VECTOR);
2494 193399 : BINDING_VECTOR_NAME (vec) = name;
2495 193399 : BINDING_VECTOR_ALLOC_CLUSTERS (vec) = clusters;
2496 193399 : BINDING_VECTOR_NUM_CLUSTERS (vec) = 0;
2497 :
2498 193399 : return vec;
2499 : }
2500 :
2501 : /* Make a raw overload node containing FN. */
2502 :
2503 : tree
2504 395197830 : ovl_make (tree fn, tree next)
2505 : {
2506 395197830 : tree result = make_node (OVERLOAD);
2507 :
2508 395197830 : if (TREE_CODE (fn) == OVERLOAD)
2509 15162354 : OVL_NESTED_P (result) = true;
2510 :
2511 517472251 : TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL
2512 517472251 : ? unknown_type_node : TREE_TYPE (fn));
2513 395197830 : if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
2514 15969882 : OVL_DEDUP_P (result) = true;
2515 395197830 : OVL_FUNCTION (result) = fn;
2516 395197830 : OVL_CHAIN (result) = next;
2517 395197830 : return result;
2518 : }
2519 :
2520 : /* Add FN to the (potentially NULL) overload set OVL. USING_OR_HIDDEN is > 0
2521 : if this is a using-decl. It is > 1 if we're revealing the using decl.
2522 : It is > 2 if we're also exporting it. USING_OR_HIDDEN is < 0, if FN is
2523 : hidden. (A decl cannot be both using and hidden.) We keep the hidden
2524 : decls first, but remaining ones are unordered. */
2525 :
2526 : tree
2527 722963049 : ovl_insert (tree fn, tree maybe_ovl, int using_or_hidden)
2528 : {
2529 722963049 : tree result = maybe_ovl;
2530 722963049 : tree insert_after = NULL_TREE;
2531 :
2532 : /* Skip hidden. */
2533 1038116284 : for (; maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD
2534 1098320505 : && OVL_HIDDEN_P (maybe_ovl);
2535 119459261 : maybe_ovl = OVL_CHAIN (maybe_ovl))
2536 : {
2537 119459261 : gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl));
2538 119459261 : insert_after = maybe_ovl;
2539 : }
2540 :
2541 722963049 : if (maybe_ovl || using_or_hidden || TREE_CODE (fn) == TEMPLATE_DECL)
2542 : {
2543 313712720 : maybe_ovl = ovl_make (fn, maybe_ovl);
2544 :
2545 313712720 : if (using_or_hidden < 0)
2546 82196594 : OVL_HIDDEN_P (maybe_ovl) = true;
2547 313712720 : if (using_or_hidden > 0)
2548 : {
2549 13533106 : OVL_DEDUP_P (maybe_ovl) = OVL_USING_P (maybe_ovl) = true;
2550 13533106 : if (using_or_hidden > 1)
2551 30690 : OVL_PURVIEW_P (maybe_ovl) = true;
2552 30690 : if (using_or_hidden > 2)
2553 30173 : OVL_EXPORT_P (maybe_ovl) = true;
2554 : }
2555 : }
2556 : else
2557 : maybe_ovl = fn;
2558 :
2559 722963049 : if (insert_after)
2560 : {
2561 9342868 : OVL_CHAIN (insert_after) = maybe_ovl;
2562 9342868 : TREE_TYPE (insert_after) = unknown_type_node;
2563 : }
2564 : else
2565 : result = maybe_ovl;
2566 :
2567 722963049 : return result;
2568 : }
2569 :
2570 : /* Skip any hidden names at the beginning of OVL. */
2571 :
2572 : tree
2573 2102990102 : ovl_skip_hidden (tree ovl)
2574 : {
2575 3902937858 : while (ovl && TREE_CODE (ovl) == OVERLOAD && OVL_HIDDEN_P (ovl))
2576 1799947756 : ovl = OVL_CHAIN (ovl);
2577 :
2578 2102990102 : return ovl;
2579 : }
2580 :
2581 : /* NODE is an OVL_HIDDEN_P node that is now revealed. */
2582 :
2583 : tree
2584 4070970 : ovl_iterator::reveal_node (tree overload, tree node)
2585 : {
2586 : /* We cannot have returned NODE as part of a lookup overload, so we
2587 : don't have to worry about preserving that. */
2588 :
2589 4070970 : OVL_HIDDEN_P (node) = false;
2590 4070970 : if (tree chain = OVL_CHAIN (node))
2591 173464 : if (TREE_CODE (chain) == OVERLOAD)
2592 : {
2593 164035 : if (OVL_HIDDEN_P (chain))
2594 : {
2595 : /* The node needs moving, and the simplest way is to remove it
2596 : and reinsert. */
2597 75153 : overload = remove_node (overload, node);
2598 75153 : overload = ovl_insert (OVL_FUNCTION (node), overload);
2599 : }
2600 88882 : else if (OVL_DEDUP_P (chain))
2601 9 : OVL_DEDUP_P (node) = true;
2602 : }
2603 4070970 : return overload;
2604 : }
2605 :
2606 : /* NODE is on the overloads of OVL. Remove it.
2607 : The removed node is unaltered and may continue to be iterated
2608 : from (i.e. it is safe to remove a node from an overload one is
2609 : currently iterating over). */
2610 :
2611 : tree
2612 391701 : ovl_iterator::remove_node (tree overload, tree node)
2613 : {
2614 391701 : tree *slot = &overload;
2615 2313454 : while (*slot != node)
2616 : {
2617 1921753 : tree probe = *slot;
2618 1921753 : gcc_checking_assert (!OVL_LOOKUP_P (probe));
2619 :
2620 1921753 : slot = &OVL_CHAIN (probe);
2621 : }
2622 :
2623 : /* Stitch out NODE. We don't have to worry about now making a
2624 : singleton overload (and consequently maybe setting its type),
2625 : because all uses of this function will be followed by inserting a
2626 : new node that must follow the place we've cut this out from. */
2627 391701 : if (TREE_CODE (node) != OVERLOAD)
2628 : /* Cloned inherited ctors don't mark themselves as via_using. */
2629 : *slot = NULL_TREE;
2630 : else
2631 151693 : *slot = OVL_CHAIN (node);
2632 :
2633 391701 : return overload;
2634 : }
2635 :
2636 : /* Mark or unmark a lookup set. */
2637 :
2638 : void
2639 121168036 : lookup_mark (tree ovl, bool val)
2640 : {
2641 1517406874 : for (lkp_iterator iter (ovl); iter; ++iter)
2642 : {
2643 1396238838 : gcc_checking_assert (LOOKUP_SEEN_P (*iter) != val);
2644 1396238838 : LOOKUP_SEEN_P (*iter) = val;
2645 : }
2646 121168036 : }
2647 :
2648 : /* Add a set of new FNS into a lookup. */
2649 :
2650 : tree
2651 679366500 : lookup_add (tree fns, tree lookup)
2652 : {
2653 679366500 : if (fns == error_mark_node || lookup == error_mark_node)
2654 : return error_mark_node;
2655 :
2656 679366488 : if (lookup || TREE_CODE (fns) == TEMPLATE_DECL)
2657 : {
2658 75372359 : lookup = ovl_make (fns, lookup);
2659 75372359 : OVL_LOOKUP_P (lookup) = true;
2660 : }
2661 : else
2662 : lookup = fns;
2663 :
2664 : return lookup;
2665 : }
2666 :
2667 : /* FNS is a new overload set, add them to LOOKUP, if they are not
2668 : already present there. */
2669 :
2670 : tree
2671 680364169 : lookup_maybe_add (tree fns, tree lookup, bool deduping)
2672 : {
2673 680364169 : if (deduping)
2674 788272998 : for (tree next, probe = fns; probe; probe = next)
2675 : {
2676 706124760 : tree fn = probe;
2677 706124760 : next = NULL_TREE;
2678 :
2679 706124760 : if (TREE_CODE (probe) == OVERLOAD)
2680 : {
2681 674109248 : fn = OVL_FUNCTION (probe);
2682 674109248 : next = OVL_CHAIN (probe);
2683 : }
2684 :
2685 706124760 : if (!LOOKUP_SEEN_P (fn))
2686 522037428 : LOOKUP_SEEN_P (fn) = true;
2687 : else
2688 : {
2689 : /* This function was already seen. Insert all the
2690 : predecessors onto the lookup. */
2691 201471815 : for (; fns != probe; fns = OVL_CHAIN (fns))
2692 : {
2693 : /* Propagate OVL_USING, but OVL_HIDDEN &
2694 : OVL_DEDUP_P don't matter. */
2695 17384483 : if (OVL_USING_P (fns))
2696 : {
2697 485208 : lookup = ovl_make (OVL_FUNCTION (fns), lookup);
2698 485208 : OVL_USING_P (lookup) = true;
2699 : }
2700 : else
2701 16899275 : lookup = lookup_add (OVL_FUNCTION (fns), lookup);
2702 : }
2703 :
2704 : /* And now skip this function. */
2705 : fns = next;
2706 : }
2707 : }
2708 :
2709 680364169 : if (fns)
2710 : /* We ended in a set of new functions. Add them all in one go. */
2711 661544831 : lookup = lookup_add (fns, lookup);
2712 :
2713 680364169 : return lookup;
2714 : }
2715 :
2716 : /* Returns nonzero if X is an expression for a (possibly overloaded)
2717 : function. If "f" is a function or function template, "f", "c->f",
2718 : "c.f", "C::f", and "f<int>" will all be considered possibly
2719 : overloaded functions. Returns 2 if the function is actually
2720 : overloaded, i.e., if it is impossible to know the type of the
2721 : function without performing overload resolution. */
2722 :
2723 : int
2724 7445398455 : is_overloaded_fn (tree x)
2725 : {
2726 7445398455 : STRIP_ANY_LOCATION_WRAPPER (x);
2727 :
2728 : /* A baselink is also considered an overloaded function. */
2729 7445398455 : if (TREE_CODE (x) == OFFSET_REF
2730 7445331947 : || TREE_CODE (x) == COMPONENT_REF)
2731 399412014 : x = TREE_OPERAND (x, 1);
2732 7445398455 : x = MAYBE_BASELINK_FUNCTIONS (x);
2733 7445398455 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2734 212170317 : x = TREE_OPERAND (x, 0);
2735 :
2736 8597776753 : if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x))
2737 7482507905 : || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x)))
2738 : return 2;
2739 :
2740 7809285107 : return OVL_P (x);
2741 : }
2742 :
2743 : /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
2744 : (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
2745 : NULL_TREE. */
2746 :
2747 : tree
2748 263068456 : dependent_name (tree x)
2749 : {
2750 : /* FIXME a dependent name must be unqualified, but this function doesn't
2751 : distinguish between qualified and unqualified identifiers. */
2752 263068456 : if (identifier_p (x))
2753 : return x;
2754 262873844 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2755 133800127 : x = TREE_OPERAND (x, 0);
2756 262873844 : if (OVL_P (x))
2757 234788017 : return OVL_NAME (x);
2758 : return NULL_TREE;
2759 : }
2760 :
2761 : /* Like dependent_name, but instead takes a CALL_EXPR and also checks
2762 : its dependence. */
2763 :
2764 : tree
2765 262370788 : call_expr_dependent_name (tree x)
2766 : {
2767 262370788 : if (TREE_TYPE (x) != NULL_TREE)
2768 : /* X isn't dependent, so its callee isn't a dependent name. */
2769 : return NULL_TREE;
2770 257955863 : return dependent_name (CALL_EXPR_FN (x));
2771 : }
2772 :
2773 : /* Returns true iff X is an expression for an overloaded function
2774 : whose type cannot be known without performing overload
2775 : resolution. */
2776 :
2777 : bool
2778 640058438 : really_overloaded_fn (tree x)
2779 : {
2780 640058438 : return is_overloaded_fn (x) == 2;
2781 : }
2782 :
2783 : /* Get the overload set FROM refers to. Returns NULL if it's not an
2784 : overload set. */
2785 :
2786 : tree
2787 4792344391 : maybe_get_fns (tree from)
2788 : {
2789 4792344391 : STRIP_ANY_LOCATION_WRAPPER (from);
2790 :
2791 : /* A baselink is also considered an overloaded function. */
2792 4792344391 : if (TREE_CODE (from) == OFFSET_REF
2793 4792283040 : || TREE_CODE (from) == COMPONENT_REF)
2794 153089258 : from = TREE_OPERAND (from, 1);
2795 4792344391 : if (BASELINK_P (from))
2796 141718661 : from = BASELINK_FUNCTIONS (from);
2797 4792344391 : if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
2798 125021387 : from = TREE_OPERAND (from, 0);
2799 :
2800 4792344391 : if (OVL_P (from))
2801 1212815223 : return from;
2802 :
2803 : return NULL_TREE;
2804 : }
2805 :
2806 : /* FROM refers to an overload set. Return that set (or die). */
2807 :
2808 : tree
2809 866889675 : get_fns (tree from)
2810 : {
2811 866889675 : tree res = maybe_get_fns (from);
2812 :
2813 866889675 : gcc_assert (res);
2814 866889675 : return res;
2815 : }
2816 :
2817 : /* Return the first function of the overload set FROM refers to. */
2818 :
2819 : tree
2820 532596378 : get_first_fn (tree from)
2821 : {
2822 532596378 : return OVL_FIRST (get_fns (from));
2823 : }
2824 :
2825 : /* Return the first function of the overload set FROM refers to if
2826 : there is an overload set, otherwise return FROM unchanged. */
2827 :
2828 : tree
2829 181693 : maybe_get_first_fn (tree from)
2830 : {
2831 181693 : if (tree res = maybe_get_fns (from))
2832 181693 : return OVL_FIRST (res);
2833 : return from;
2834 : }
2835 :
2836 : /* Return the scope where the overloaded functions OVL were found. */
2837 :
2838 : tree
2839 219929865 : ovl_scope (tree ovl)
2840 : {
2841 219929865 : if (TREE_CODE (ovl) == OFFSET_REF
2842 219929865 : || TREE_CODE (ovl) == COMPONENT_REF)
2843 0 : ovl = TREE_OPERAND (ovl, 1);
2844 219929865 : if (TREE_CODE (ovl) == BASELINK)
2845 46708529 : return BINFO_TYPE (BASELINK_BINFO (ovl));
2846 173221336 : if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
2847 78715142 : ovl = TREE_OPERAND (ovl, 0);
2848 : /* Skip using-declarations. */
2849 173221336 : lkp_iterator iter (ovl);
2850 181800335 : do
2851 181800335 : ovl = *iter;
2852 355021671 : while (iter.using_p () && ++iter);
2853 :
2854 173221336 : return CP_DECL_CONTEXT (ovl);
2855 : }
2856 :
2857 : #define PRINT_RING_SIZE 4
2858 :
2859 : static const char *
2860 184067 : cxx_printable_name_internal (tree decl, int v, bool translate)
2861 : {
2862 184067 : static unsigned int uid_ring[PRINT_RING_SIZE];
2863 184067 : static char *print_ring[PRINT_RING_SIZE];
2864 184067 : static bool trans_ring[PRINT_RING_SIZE];
2865 184067 : static int ring_counter;
2866 184067 : int i;
2867 :
2868 : /* Only cache functions. */
2869 184067 : if (v < 2
2870 96934 : || TREE_CODE (decl) != FUNCTION_DECL
2871 279354 : || DECL_LANG_SPECIFIC (decl) == 0)
2872 90448 : return lang_decl_name (decl, v, translate);
2873 :
2874 : /* See if this print name is lying around. */
2875 426531 : for (i = 0; i < PRINT_RING_SIZE; i++)
2876 349924 : if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
2877 : /* yes, so return it. */
2878 17012 : return print_ring[i];
2879 :
2880 76607 : const char *ret = lang_decl_name (decl, v, translate);
2881 :
2882 : /* The lang_decl_name call could have called this function recursively,
2883 : so check again. */
2884 459642 : for (i = 0; i < PRINT_RING_SIZE; i++)
2885 306428 : if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
2886 : /* yes, so return it. */
2887 0 : return print_ring[i];
2888 :
2889 76607 : if (++ring_counter == PRINT_RING_SIZE)
2890 15895 : ring_counter = 0;
2891 :
2892 76607 : if (current_function_decl != NULL_TREE)
2893 : {
2894 : /* There may be both translated and untranslated versions of the
2895 : name cached. */
2896 210318 : for (i = 0; i < 2; i++)
2897 : {
2898 140212 : if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
2899 79 : ring_counter += 1;
2900 140212 : if (ring_counter == PRINT_RING_SIZE)
2901 7 : ring_counter = 0;
2902 : }
2903 70106 : gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
2904 : }
2905 :
2906 76607 : free (print_ring[ring_counter]);
2907 :
2908 76607 : print_ring[ring_counter] = xstrdup (ret);
2909 76607 : uid_ring[ring_counter] = DECL_UID (decl);
2910 76607 : trans_ring[ring_counter] = translate;
2911 76607 : return print_ring[ring_counter];
2912 : }
2913 :
2914 : const char *
2915 184067 : cxx_printable_name (tree decl, int v)
2916 : {
2917 184067 : return cxx_printable_name_internal (decl, v, false);
2918 : }
2919 :
2920 : const char *
2921 0 : cxx_printable_name_translate (tree decl, int v)
2922 : {
2923 0 : return cxx_printable_name_internal (decl, v, true);
2924 : }
2925 :
2926 : /* Return the canonical version of exception-specification RAISES for a C++17
2927 : function type, for use in type comparison and building TYPE_CANONICAL. */
2928 :
2929 : tree
2930 214601531 : canonical_eh_spec (tree raises)
2931 : {
2932 214601531 : if (raises == NULL_TREE)
2933 : return raises;
2934 193216631 : else if (DEFERRED_NOEXCEPT_SPEC_P (raises)
2935 157193833 : || UNPARSED_NOEXCEPT_SPEC_P (raises)
2936 148300260 : || uses_template_parms (raises)
2937 148300260 : || uses_template_parms (TREE_PURPOSE (raises)))
2938 : /* Keep a dependent or deferred exception specification. */
2939 : return raises;
2940 146412346 : else if (nothrow_spec_p (raises))
2941 : /* throw() -> noexcept. */
2942 145879654 : return noexcept_true_spec;
2943 : else
2944 : /* For C++17 type matching, anything else -> nothing. */
2945 : return NULL_TREE;
2946 : }
2947 :
2948 : tree
2949 771902930 : build_cp_fntype_variant (tree type, cp_ref_qualifier rqual,
2950 : tree raises, bool late)
2951 : {
2952 771902930 : cv_qualifier type_quals;
2953 771902930 : addr_space_t as;
2954 771902930 : std::tie (type_quals, as) = TYPE_QUALS (type).split ();
2955 : /* AS here is the address space of the method or function. For the latter,
2956 : it won't ever make sense. For the former, it may, one day, if we support
2957 : address space qualification on non-static member functions. But not
2958 : today. */
2959 771902930 : gcc_assert (ADDR_SPACE_GENERIC_P (as));
2960 :
2961 771902930 : if (cp_check_qualified_type (type, type, type_quals, rqual, raises, late))
2962 : return type;
2963 :
2964 325116375 : tree v = TYPE_MAIN_VARIANT (type);
2965 719528329 : for (; v; v = TYPE_NEXT_VARIANT (v))
2966 522127252 : if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late))
2967 : return v;
2968 :
2969 : /* Need to build a new variant. */
2970 197401077 : v = build_variant_type_copy (type);
2971 197401077 : if (!TYPE_DEPENDENT_P (v))
2972 : /* We no longer know that it's not type-dependent. */
2973 196563566 : TYPE_DEPENDENT_P_VALID (v) = false;
2974 197401077 : TYPE_RAISES_EXCEPTIONS (v) = raises;
2975 197401077 : TYPE_HAS_LATE_RETURN_TYPE (v) = late;
2976 197401077 : switch (rqual)
2977 : {
2978 1297163 : case REF_QUAL_RVALUE:
2979 1297163 : FUNCTION_RVALUE_QUALIFIED (v) = 1;
2980 1297163 : FUNCTION_REF_QUALIFIED (v) = 1;
2981 1297163 : break;
2982 1217905 : case REF_QUAL_LVALUE:
2983 1217905 : FUNCTION_RVALUE_QUALIFIED (v) = 0;
2984 1217905 : FUNCTION_REF_QUALIFIED (v) = 1;
2985 1217905 : break;
2986 194886009 : default:
2987 194886009 : FUNCTION_REF_QUALIFIED (v) = 0;
2988 194886009 : break;
2989 : }
2990 :
2991 : /* Canonicalize the exception specification. */
2992 197401077 : tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE;
2993 186343049 : bool complex_eh_spec_p = (cr && cr != noexcept_true_spec
2994 242630598 : && !UNPARSED_NOEXCEPT_SPEC_P (cr));
2995 :
2996 160093644 : if (!complex_eh_spec_p && TYPE_RAISES_EXCEPTIONS (type))
2997 : /* We want to consider structural equality of the exception-less
2998 : variant since we'll be replacing the exception specification. */
2999 5700756 : type = build_cp_fntype_variant (type, rqual, /*raises=*/NULL_TREE, late);
3000 197401077 : if (TYPE_STRUCTURAL_EQUALITY_P (type) || complex_eh_spec_p)
3001 : /* Propagate structural equality. And always use structural equality
3002 : for function types with a complex noexcept-spec since their identity
3003 : may depend on e.g. whether comparing_specializations is set. */
3004 51245917 : SET_TYPE_STRUCTURAL_EQUALITY (v);
3005 146155160 : else if (TYPE_CANONICAL (type) != type || cr != raises || late)
3006 : /* Build the underlying canonical type, since it is different
3007 : from TYPE. */
3008 62923670 : TYPE_CANONICAL (v) = build_cp_fntype_variant (TYPE_CANONICAL (type),
3009 : rqual, cr, false);
3010 : else
3011 : /* T is its own canonical type. */
3012 83231490 : TYPE_CANONICAL (v) = v;
3013 :
3014 : return v;
3015 : }
3016 :
3017 : /* TYPE is a function or method type with a deferred exception
3018 : specification that has been parsed to RAISES. Fixup all the type
3019 : variants that are affected in place. Via decltype &| noexcept
3020 : tricks, the unparsed spec could have escaped into the type system. */
3021 :
3022 : void
3023 3594784 : fixup_deferred_exception_variants (tree type, tree raises)
3024 : {
3025 3594784 : tree original = TYPE_RAISES_EXCEPTIONS (type);
3026 :
3027 7189568 : gcc_checking_assert (UNPARSED_NOEXCEPT_SPEC_P (original));
3028 :
3029 3594784 : for (tree variant = TYPE_MAIN_VARIANT (type);
3030 11662901 : variant; variant = TYPE_NEXT_VARIANT (variant))
3031 8068117 : if (TYPE_RAISES_EXCEPTIONS (variant) == original)
3032 : {
3033 3878125 : gcc_checking_assert (variant != TYPE_MAIN_VARIANT (type));
3034 :
3035 3878125 : SET_TYPE_STRUCTURAL_EQUALITY (variant);
3036 3878125 : TYPE_RAISES_EXCEPTIONS (variant) = raises;
3037 :
3038 3878125 : if (!TYPE_DEPENDENT_P (variant))
3039 : /* We no longer know that it's not type-dependent. */
3040 288482 : TYPE_DEPENDENT_P_VALID (variant) = false;
3041 : }
3042 3594784 : }
3043 :
3044 : /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
3045 : listed in RAISES. */
3046 :
3047 : tree
3048 190934979 : build_exception_variant (tree type, tree raises)
3049 : {
3050 190934979 : cp_ref_qualifier rqual = type_memfn_rqual (type);
3051 190934979 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
3052 190934979 : return build_cp_fntype_variant (type, rqual, raises, late);
3053 : }
3054 :
3055 : /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
3056 : BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
3057 : arguments. */
3058 :
3059 : tree
3060 503282 : bind_template_template_parm (tree t, tree newargs)
3061 : {
3062 503282 : tree decl = TYPE_NAME (t);
3063 503282 : tree t2;
3064 :
3065 503282 : t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
3066 503282 : decl = build_decl (input_location,
3067 503282 : TYPE_DECL, DECL_NAME (decl), NULL_TREE);
3068 503282 : SET_DECL_TEMPLATE_PARM_P (decl);
3069 :
3070 : /* These nodes have to be created to reflect new TYPE_DECL and template
3071 : arguments. */
3072 503282 : TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
3073 503282 : TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
3074 503282 : TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
3075 1006564 : = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
3076 :
3077 503282 : TREE_TYPE (decl) = t2;
3078 503282 : TYPE_NAME (t2) = decl;
3079 503282 : TYPE_STUB_DECL (t2) = decl;
3080 503282 : TYPE_SIZE (t2) = 0;
3081 :
3082 503282 : if (any_template_arguments_need_structural_equality_p (newargs))
3083 13 : SET_TYPE_STRUCTURAL_EQUALITY (t2);
3084 : else
3085 503269 : TYPE_CANONICAL (t2) = canonical_type_parameter (t2);
3086 :
3087 503282 : return t2;
3088 : }
3089 :
3090 : /* Called from count_trees via walk_tree. */
3091 :
3092 : static tree
3093 0 : count_trees_r (tree *tp, int *walk_subtrees, void *data)
3094 : {
3095 0 : ++*((int *) data);
3096 :
3097 0 : if (TYPE_P (*tp))
3098 0 : *walk_subtrees = 0;
3099 :
3100 0 : return NULL_TREE;
3101 : }
3102 :
3103 : /* Debugging function for measuring the rough complexity of a tree
3104 : representation. */
3105 :
3106 : int
3107 0 : count_trees (tree t)
3108 : {
3109 0 : int n_trees = 0;
3110 0 : cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
3111 0 : return n_trees;
3112 : }
3113 :
3114 : /* Called from verify_stmt_tree via walk_tree. */
3115 :
3116 : static tree
3117 638921 : verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data)
3118 : {
3119 638921 : tree t = *tp;
3120 638921 : hash_table<nofree_ptr_hash <tree_node> > *statements
3121 : = static_cast <hash_table<nofree_ptr_hash <tree_node> > *> (data);
3122 638921 : tree_node **slot;
3123 :
3124 638921 : if (!STATEMENT_CODE_P (TREE_CODE (t)))
3125 : return NULL_TREE;
3126 :
3127 : /* If this statement is already present in the hash table, then
3128 : there is a circularity in the statement tree. */
3129 33394 : gcc_assert (!statements->find (t));
3130 :
3131 33394 : slot = statements->find_slot (t, INSERT);
3132 33394 : *slot = t;
3133 :
3134 33394 : return NULL_TREE;
3135 : }
3136 :
3137 : /* Debugging function to check that the statement T has not been
3138 : corrupted. For now, this function simply checks that T contains no
3139 : circularities. */
3140 :
3141 : void
3142 1644 : verify_stmt_tree (tree t)
3143 : {
3144 1644 : hash_table<nofree_ptr_hash <tree_node> > statements (37);
3145 1644 : cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
3146 1644 : }
3147 :
3148 : /* Check if the type T depends on a type with no linkage and if so,
3149 : return it. If RELAXED_P then do not consider a class type declared
3150 : within a vague-linkage function or in a module CMI to have no linkage,
3151 : since it can still be accessed within a different TU. Remember:
3152 : no-linkage is not the same as internal-linkage. */
3153 :
3154 : tree
3155 310820642 : no_linkage_check (tree t, bool relaxed_p)
3156 : {
3157 363744740 : tree r;
3158 :
3159 : /* Lambda types that don't have mangling scope have no linkage. We
3160 : check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
3161 : when we get here from pushtag none of the lambda information is
3162 : set up yet, so we want to assume that the lambda has linkage and
3163 : fix it up later if not. We need to check this even in templates so
3164 : that we properly handle a lambda-expression in the signature. */
3165 410189587 : if (LAMBDA_TYPE_P (t)
3166 367610288 : && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node)
3167 : {
3168 2197526 : tree extra = LAMBDA_TYPE_EXTRA_SCOPE (t);
3169 2197526 : if (!extra)
3170 : return t;
3171 : }
3172 :
3173 : /* Otherwise there's no point in checking linkage on template functions; we
3174 : can't know their complete types. */
3175 363740219 : if (processing_template_decl)
3176 : return NULL_TREE;
3177 :
3178 226597065 : switch (TREE_CODE (t))
3179 : {
3180 118887498 : case RECORD_TYPE:
3181 118887498 : if (TYPE_PTRMEMFUNC_P (t))
3182 125147 : goto ptrmem;
3183 : /* Fall through. */
3184 120109824 : case UNION_TYPE:
3185 120109824 : if (!CLASS_TYPE_P (t))
3186 : return NULL_TREE;
3187 : /* Fall through. */
3188 124842183 : case ENUMERAL_TYPE:
3189 : /* Only treat unnamed types as having no linkage if they're at
3190 : namespace scope. This is core issue 966. */
3191 254194670 : if (TYPE_UNNAMED_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
3192 : return t;
3193 :
3194 124080729 : for (r = CP_TYPE_CONTEXT (t); ; )
3195 : {
3196 : /* If we're a nested type of a !TREE_PUBLIC class, we might not
3197 : have linkage, or we might just be in an anonymous namespace.
3198 : If we're in a TREE_PUBLIC class, we have linkage. */
3199 126687513 : if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
3200 80259 : return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
3201 126607254 : else if (TREE_CODE (r) == FUNCTION_DECL)
3202 : {
3203 3161161 : if (relaxed_p
3204 3161161 : && (vague_linkage_p (r)
3205 8243 : || (TREE_PUBLIC (r) && module_maybe_has_cmi_p ())))
3206 2606784 : r = CP_DECL_CONTEXT (r);
3207 : else
3208 : return t;
3209 : }
3210 : else
3211 : break;
3212 : }
3213 :
3214 : return NULL_TREE;
3215 :
3216 28620674 : case ARRAY_TYPE:
3217 28620674 : case POINTER_TYPE:
3218 28620674 : case REFERENCE_TYPE:
3219 28620674 : case VECTOR_TYPE:
3220 28620674 : return no_linkage_check (TREE_TYPE (t), relaxed_p);
3221 :
3222 128315 : case OFFSET_TYPE:
3223 128315 : ptrmem:
3224 128315 : r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
3225 : relaxed_p);
3226 128315 : if (r)
3227 : return r;
3228 128315 : return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
3229 :
3230 24633407 : case METHOD_TYPE:
3231 24633407 : case FUNCTION_TYPE:
3232 24633407 : {
3233 24633407 : tree parm = TYPE_ARG_TYPES (t);
3234 24633407 : if (TREE_CODE (t) == METHOD_TYPE)
3235 : /* The 'this' pointer isn't interesting; a method has the same
3236 : linkage (or lack thereof) as its enclosing class. */
3237 12442120 : parm = TREE_CHAIN (parm);
3238 31541748 : for (;
3239 56175155 : parm && parm != void_list_node;
3240 31541748 : parm = TREE_CHAIN (parm))
3241 : {
3242 32080305 : r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
3243 32080305 : if (r)
3244 : return r;
3245 : }
3246 24094850 : return no_linkage_check (TREE_TYPE (t), relaxed_p);
3247 : }
3248 :
3249 : default:
3250 : return NULL_TREE;
3251 : }
3252 : }
3253 :
3254 : extern int depth_reached;
3255 :
3256 : void
3257 0 : cxx_print_statistics (void)
3258 : {
3259 0 : print_template_statistics ();
3260 0 : if (GATHER_STATISTICS)
3261 : fprintf (stderr, "maximum template instantiation depth reached: %d\n",
3262 : depth_reached);
3263 0 : }
3264 :
3265 : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3266 : (which is an ARRAY_TYPE). This one is a recursive count of all
3267 : ARRAY_TYPEs that are clumped together. */
3268 :
3269 : tree
3270 6896 : array_type_nelts_total (tree type)
3271 : {
3272 6896 : tree sz = array_type_nelts_top (type);
3273 6896 : type = TREE_TYPE (type);
3274 7170 : while (TREE_CODE (type) == ARRAY_TYPE)
3275 : {
3276 274 : tree n = array_type_nelts_top (type);
3277 274 : sz = fold_build2_loc (input_location,
3278 : MULT_EXPR, sizetype, sz, n);
3279 274 : type = TREE_TYPE (type);
3280 : }
3281 6896 : return sz;
3282 : }
3283 :
3284 : struct bot_data
3285 : {
3286 : splay_tree target_remap;
3287 : bool clear_location;
3288 : };
3289 :
3290 : /* Called from break_out_target_exprs via mapcar. */
3291 :
3292 : static tree
3293 59992675 : bot_manip (tree* tp, int* walk_subtrees, void* data_)
3294 : {
3295 59992675 : bot_data &data = *(bot_data*)data_;
3296 59992675 : splay_tree target_remap = data.target_remap;
3297 59992675 : tree t = *tp;
3298 :
3299 59992675 : if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t))
3300 : {
3301 : /* There can't be any TARGET_EXPRs or their slot variables below this
3302 : point. But we must make a copy, in case subsequent processing
3303 : alters any part of it. For example, during gimplification a cast
3304 : of the form (T) &X::f (where "f" is a member function) will lead
3305 : to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */
3306 24514522 : *walk_subtrees = 0;
3307 24514522 : *tp = unshare_expr (t);
3308 24514522 : return NULL_TREE;
3309 : }
3310 35478153 : if (TREE_CODE (t) == TARGET_EXPR)
3311 : {
3312 755706 : tree u;
3313 :
3314 755706 : if (TREE_CODE (TARGET_EXPR_INITIAL (t)) == AGGR_INIT_EXPR)
3315 : {
3316 523904 : u = build_cplus_new (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
3317 : tf_warning_or_error);
3318 523904 : if (u == error_mark_node)
3319 : return u;
3320 523904 : if (AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (t)))
3321 6275 : AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (u)) = true;
3322 : }
3323 : else
3324 231802 : u = force_target_expr (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
3325 : tf_warning_or_error);
3326 :
3327 755706 : TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
3328 755706 : TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
3329 755706 : TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
3330 755706 : TARGET_EXPR_ELIDING_P (u) = TARGET_EXPR_ELIDING_P (t);
3331 755706 : TREE_CONSTANT (u) = TREE_CONSTANT (t);
3332 :
3333 : /* Map the old variable to the new one. */
3334 2267118 : splay_tree_insert (target_remap,
3335 755706 : (splay_tree_key) TARGET_EXPR_SLOT (t),
3336 755706 : (splay_tree_value) TARGET_EXPR_SLOT (u));
3337 :
3338 755706 : TARGET_EXPR_INITIAL (u) = break_out_target_exprs (TARGET_EXPR_INITIAL (u),
3339 : data.clear_location);
3340 755706 : if (TARGET_EXPR_INITIAL (u) == error_mark_node)
3341 : return error_mark_node;
3342 :
3343 755706 : if (data.clear_location)
3344 405289 : SET_EXPR_LOCATION (u, input_location);
3345 :
3346 : /* Replace the old expression with the new version. */
3347 755706 : *tp = u;
3348 : /* We don't have to go below this point; the recursive call to
3349 : break_out_target_exprs will have handled anything below this
3350 : point. */
3351 755706 : *walk_subtrees = 0;
3352 755706 : return NULL_TREE;
3353 : }
3354 34722447 : if (TREE_CODE (*tp) == SAVE_EXPR)
3355 : {
3356 103062 : t = *tp;
3357 103062 : splay_tree_node n = splay_tree_lookup (target_remap,
3358 : (splay_tree_key) t);
3359 103062 : if (n)
3360 : {
3361 52252 : *tp = (tree)n->value;
3362 52252 : *walk_subtrees = 0;
3363 : }
3364 : else
3365 : {
3366 50810 : copy_tree_r (tp, walk_subtrees, NULL);
3367 50810 : splay_tree_insert (target_remap,
3368 : (splay_tree_key)t,
3369 50810 : (splay_tree_value)*tp);
3370 : /* Make sure we don't remap an already-remapped SAVE_EXPR. */
3371 50810 : splay_tree_insert (target_remap,
3372 : (splay_tree_key)*tp,
3373 50810 : (splay_tree_value)*tp);
3374 : }
3375 : return NULL_TREE;
3376 : }
3377 34619385 : if (TREE_CODE (*tp) == DECL_EXPR
3378 199 : && VAR_P (DECL_EXPR_DECL (*tp))
3379 199 : && DECL_ARTIFICIAL (DECL_EXPR_DECL (*tp))
3380 34619584 : && !TREE_STATIC (DECL_EXPR_DECL (*tp)))
3381 : {
3382 199 : tree t;
3383 199 : splay_tree_node n
3384 398 : = splay_tree_lookup (target_remap,
3385 199 : (splay_tree_key) DECL_EXPR_DECL (*tp));
3386 199 : if (n)
3387 1 : t = (tree) n->value;
3388 : else
3389 : {
3390 198 : t = create_temporary_var (TREE_TYPE (DECL_EXPR_DECL (*tp)));
3391 198 : DECL_INITIAL (t) = DECL_INITIAL (DECL_EXPR_DECL (*tp));
3392 396 : splay_tree_insert (target_remap,
3393 198 : (splay_tree_key) DECL_EXPR_DECL (*tp),
3394 : (splay_tree_value) t);
3395 : }
3396 199 : copy_tree_r (tp, walk_subtrees, NULL);
3397 199 : DECL_EXPR_DECL (*tp) = t;
3398 199 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3399 12 : SET_EXPR_LOCATION (*tp, input_location);
3400 : return NULL_TREE;
3401 : }
3402 34619186 : if (TREE_CODE (*tp) == BIND_EXPR && BIND_EXPR_VARS (*tp))
3403 : {
3404 1 : copy_tree_r (tp, walk_subtrees, NULL);
3405 2 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
3406 : {
3407 1 : gcc_assert (VAR_P (*p) && DECL_ARTIFICIAL (*p) && !TREE_STATIC (*p));
3408 1 : tree t = create_temporary_var (TREE_TYPE (*p));
3409 1 : DECL_INITIAL (t) = DECL_INITIAL (*p);
3410 1 : DECL_CHAIN (t) = DECL_CHAIN (*p);
3411 1 : splay_tree_insert (target_remap, (splay_tree_key) *p,
3412 : (splay_tree_value) t);
3413 1 : *p = t;
3414 : }
3415 1 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3416 0 : SET_EXPR_LOCATION (*tp, input_location);
3417 : return NULL_TREE;
3418 : }
3419 :
3420 : /* Make a copy of this node. */
3421 34619185 : t = copy_tree_r (tp, walk_subtrees, NULL);
3422 34619185 : if (TREE_CODE (*tp) == CALL_EXPR || TREE_CODE (*tp) == AGGR_INIT_EXPR)
3423 5945779 : if (!processing_template_decl)
3424 5945779 : set_flags_from_callee (*tp);
3425 34619185 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3426 10402887 : SET_EXPR_LOCATION (*tp, input_location);
3427 : return t;
3428 : }
3429 :
3430 : /* Replace all remapped VAR_DECLs in T with their new equivalents.
3431 : DATA is really a splay-tree mapping old variables to new
3432 : variables. */
3433 :
3434 : static tree
3435 84560066 : bot_replace (tree* t, int */*walk_subtrees*/, void* data_)
3436 : {
3437 84560066 : bot_data &data = *(bot_data*)data_;
3438 84560066 : splay_tree target_remap = data.target_remap;
3439 :
3440 84560066 : if (VAR_P (*t))
3441 : {
3442 2570836 : splay_tree_node n = splay_tree_lookup (target_remap,
3443 : (splay_tree_key) *t);
3444 2570836 : if (n)
3445 2204 : *t = (tree) n->value;
3446 : }
3447 81989230 : else if (TREE_CODE (*t) == PARM_DECL
3448 5605553 : && DECL_NAME (*t) == this_identifier
3449 83953530 : && !DECL_CONTEXT (*t))
3450 : {
3451 : /* In an NSDMI we need to replace the 'this' parameter we used for
3452 : parsing with the real one for this function. */
3453 24688 : *t = current_class_ptr;
3454 : }
3455 81964542 : else if (TREE_CODE (*t) == CONVERT_EXPR
3456 81964542 : && CONVERT_EXPR_VBASE_PATH (*t))
3457 : {
3458 : /* In an NSDMI build_base_path defers building conversions to morally
3459 : virtual bases, and we handle it here. */
3460 63 : tree basetype = TREE_TYPE (*t);
3461 63 : *t = convert_to_base (TREE_OPERAND (*t, 0), basetype,
3462 : /*check_access=*/false, /*nonnull=*/true,
3463 : tf_warning_or_error);
3464 : }
3465 :
3466 84560066 : return NULL_TREE;
3467 : }
3468 :
3469 : /* When we parse a default argument expression, we may create
3470 : temporary variables via TARGET_EXPRs. When we actually use the
3471 : default-argument expression, we make a copy of the expression
3472 : and replace the temporaries with appropriate local versions.
3473 :
3474 : If CLEAR_LOCATION is true, override any EXPR_LOCATION with
3475 : input_location. */
3476 :
3477 : tree
3478 12741181 : break_out_target_exprs (tree t, bool clear_location /* = false */)
3479 : {
3480 12741181 : static int target_remap_count;
3481 12741181 : static splay_tree target_remap;
3482 :
3483 : /* We shouldn't be called on templated trees, nor do we want to
3484 : produce them. */
3485 12741181 : gcc_checking_assert (!processing_template_decl);
3486 :
3487 12741181 : if (!target_remap_count++)
3488 11985475 : target_remap = splay_tree_new (splay_tree_compare_pointers,
3489 : /*splay_tree_delete_key_fn=*/NULL,
3490 : /*splay_tree_delete_value_fn=*/NULL);
3491 12741181 : bot_data data = { target_remap, clear_location };
3492 12741181 : if (cp_walk_tree (&t, bot_manip, &data, NULL) == error_mark_node)
3493 0 : t = error_mark_node;
3494 12741181 : if (cp_walk_tree (&t, bot_replace, &data, NULL) == error_mark_node)
3495 0 : t = error_mark_node;
3496 :
3497 12741181 : if (!--target_remap_count)
3498 : {
3499 11985475 : splay_tree_delete (target_remap);
3500 11985475 : target_remap = NULL;
3501 : }
3502 :
3503 12741181 : return t;
3504 : }
3505 :
3506 : /* Build an expression for the subobject of OBJ at CONSTRUCTOR index INDEX,
3507 : which we expect to have type TYPE. */
3508 :
3509 : tree
3510 1523038 : build_ctor_subob_ref (tree index, tree type, tree obj)
3511 : {
3512 1523038 : if (index == NULL_TREE)
3513 : /* Can't refer to a particular member of a vector. */
3514 : obj = NULL_TREE;
3515 1523038 : else if (TREE_CODE (index) == INTEGER_CST)
3516 56924 : obj = cp_build_array_ref (input_location, obj, index, tf_none);
3517 : else
3518 1466114 : obj = build_class_member_access_expr (obj, index, NULL_TREE,
3519 : /*reference*/false, tf_none);
3520 1523038 : if (obj)
3521 : {
3522 1523038 : tree objtype = TREE_TYPE (obj);
3523 1523038 : if (TREE_CODE (objtype) == ARRAY_TYPE && !TYPE_DOMAIN (objtype))
3524 : {
3525 : /* When the destination object refers to a flexible array member
3526 : verify that it matches the type of the source object except
3527 : for its domain and qualifiers. */
3528 83 : gcc_assert (comptypes (TYPE_MAIN_VARIANT (type),
3529 : TYPE_MAIN_VARIANT (objtype),
3530 : COMPARE_REDECLARATION));
3531 : }
3532 : else
3533 1522955 : gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, objtype));
3534 : }
3535 :
3536 1523038 : return obj;
3537 : }
3538 :
3539 : struct replace_placeholders_t
3540 : {
3541 : tree obj; /* The object to be substituted for a PLACEHOLDER_EXPR. */
3542 : tree exp; /* The outermost exp. */
3543 : bool seen; /* Whether we've encountered a PLACEHOLDER_EXPR. */
3544 : hash_set<tree> *pset; /* To avoid walking same trees multiple times. */
3545 : };
3546 :
3547 : /* Like substitute_placeholder_in_expr, but handle C++ tree codes and
3548 : build up subexpressions as we go deeper. */
3549 :
3550 : static tree
3551 27828253 : replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
3552 : {
3553 27828253 : replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);
3554 27828253 : tree obj = d->obj;
3555 :
3556 27828253 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3557 : {
3558 9676107 : *walk_subtrees = false;
3559 9676107 : return NULL_TREE;
3560 : }
3561 :
3562 18152146 : switch (TREE_CODE (*t))
3563 : {
3564 : case PLACEHOLDER_EXPR:
3565 : {
3566 : tree x = obj;
3567 659 : for (; !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (*t),
3568 659 : TREE_TYPE (x));
3569 77 : x = TREE_OPERAND (x, 0))
3570 77 : gcc_assert (handled_component_p (x));
3571 582 : *t = unshare_expr (x);
3572 582 : *walk_subtrees = false;
3573 582 : d->seen = true;
3574 : }
3575 582 : break;
3576 :
3577 362245 : case CONSTRUCTOR:
3578 362245 : {
3579 362245 : constructor_elt *ce;
3580 362245 : vec<constructor_elt,va_gc> *v = CONSTRUCTOR_ELTS (*t);
3581 : /* Don't walk into CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctors
3582 : other than the d->exp one, those have PLACEHOLDER_EXPRs
3583 : related to another object. */
3584 362245 : if ((CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t)
3585 648 : && *t != d->exp)
3586 362788 : || d->pset->add (*t))
3587 : {
3588 105 : *walk_subtrees = false;
3589 105 : return NULL_TREE;
3590 : }
3591 1107340 : for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i)
3592 : {
3593 745200 : tree *valp = &ce->value;
3594 745200 : tree type = TREE_TYPE (*valp);
3595 745200 : tree subob = obj;
3596 :
3597 : /* Elements with RANGE_EXPR index shouldn't have any
3598 : placeholders in them. */
3599 745200 : if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
3600 9 : continue;
3601 :
3602 745191 : if (TREE_CODE (*valp) == CONSTRUCTOR
3603 3016 : && AGGREGATE_TYPE_P (type))
3604 : {
3605 : /* If we're looking at the initializer for OBJ, then build
3606 : a sub-object reference. If we're looking at an
3607 : initializer for another object, just pass OBJ down. */
3608 3002 : if (same_type_ignoring_top_level_qualifiers_p
3609 3002 : (TREE_TYPE (*t), TREE_TYPE (obj)))
3610 2948 : subob = build_ctor_subob_ref (ce->index, type, obj);
3611 3002 : if (TREE_CODE (*valp) == TARGET_EXPR)
3612 0 : valp = &TARGET_EXPR_INITIAL (*valp);
3613 : }
3614 745191 : d->obj = subob;
3615 745191 : cp_walk_tree (valp, replace_placeholders_r, data_, NULL);
3616 745191 : d->obj = obj;
3617 : }
3618 362140 : *walk_subtrees = false;
3619 362140 : break;
3620 : }
3621 :
3622 17789319 : default:
3623 17789319 : if (d->pset->add (*t))
3624 685323 : *walk_subtrees = false;
3625 : break;
3626 : }
3627 :
3628 : return NULL_TREE;
3629 : }
3630 :
3631 : /* Replace PLACEHOLDER_EXPRs in EXP with object OBJ. SEEN_P is set if
3632 : a PLACEHOLDER_EXPR has been encountered. */
3633 :
3634 : tree
3635 66300622 : replace_placeholders (tree exp, tree obj, bool *seen_p /*= NULL*/)
3636 : {
3637 : /* This is only relevant for C++14. */
3638 66300622 : if (cxx_dialect < cxx14)
3639 871406 : return exp;
3640 :
3641 : /* If the object isn't a (member of a) class, do nothing. */
3642 : tree op0 = obj;
3643 66113446 : while (handled_component_p (op0))
3644 684230 : op0 = TREE_OPERAND (op0, 0);
3645 65429216 : if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0))))
3646 59170358 : return exp;
3647 :
3648 6258858 : tree *tp = &exp;
3649 6258858 : if (TREE_CODE (exp) == TARGET_EXPR)
3650 822246 : tp = &TARGET_EXPR_INITIAL (exp);
3651 6258858 : hash_set<tree> pset;
3652 6258858 : replace_placeholders_t data = { obj, *tp, false, &pset };
3653 6258858 : cp_walk_tree (tp, replace_placeholders_r, &data, NULL);
3654 6258858 : if (seen_p)
3655 202332 : *seen_p = data.seen;
3656 6258858 : return exp;
3657 6258858 : }
3658 :
3659 : /* Callback function for find_placeholders. */
3660 :
3661 : static tree
3662 8984577 : find_placeholders_r (tree *t, int *walk_subtrees, void *)
3663 : {
3664 8984577 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3665 : {
3666 3997623 : *walk_subtrees = false;
3667 3997623 : return NULL_TREE;
3668 : }
3669 :
3670 4986954 : switch (TREE_CODE (*t))
3671 : {
3672 : case PLACEHOLDER_EXPR:
3673 : return *t;
3674 :
3675 604 : case CONSTRUCTOR:
3676 604 : if (CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t))
3677 173 : *walk_subtrees = false;
3678 : break;
3679 :
3680 : default:
3681 : break;
3682 : }
3683 :
3684 : return NULL_TREE;
3685 : }
3686 :
3687 : /* Return true if EXP contains a PLACEHOLDER_EXPR. Don't walk into
3688 : ctors with CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag set. */
3689 :
3690 : bool
3691 237621 : find_placeholders (tree exp)
3692 : {
3693 : /* This is only relevant for C++14. */
3694 237621 : if (cxx_dialect < cxx14)
3695 : return false;
3696 :
3697 237621 : return cp_walk_tree_without_duplicates (&exp, find_placeholders_r, NULL);
3698 : }
3699 :
3700 : /* Similar to `build_nt', but for template definitions of dependent
3701 : expressions */
3702 :
3703 : tree
3704 336472229 : build_min_nt_loc (location_t loc, enum tree_code code, ...)
3705 : {
3706 336472229 : tree t;
3707 336472229 : int length;
3708 336472229 : int i;
3709 336472229 : va_list p;
3710 :
3711 336472229 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3712 :
3713 336472229 : va_start (p, code);
3714 :
3715 336472229 : t = make_node (code);
3716 336472229 : SET_EXPR_LOCATION (t, loc);
3717 336472229 : length = TREE_CODE_LENGTH (code);
3718 :
3719 1106161818 : for (i = 0; i < length; i++)
3720 769689589 : TREE_OPERAND (t, i) = va_arg (p, tree);
3721 :
3722 336472229 : va_end (p);
3723 336472229 : return t;
3724 : }
3725 :
3726 : /* Similar to `build', but for template definitions. */
3727 :
3728 : tree
3729 256090991 : build_min (enum tree_code code, tree tt, ...)
3730 : {
3731 256090991 : tree t;
3732 256090991 : int length;
3733 256090991 : int i;
3734 256090991 : va_list p;
3735 :
3736 256090991 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3737 :
3738 256090991 : va_start (p, tt);
3739 :
3740 256090991 : t = make_node (code);
3741 256090991 : length = TREE_CODE_LENGTH (code);
3742 256090991 : TREE_TYPE (t) = tt;
3743 :
3744 684003245 : for (i = 0; i < length; i++)
3745 : {
3746 427912254 : tree x = va_arg (p, tree);
3747 427912254 : TREE_OPERAND (t, i) = x;
3748 427912254 : if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
3749 3357877 : TREE_SIDE_EFFECTS (t) = 1;
3750 : }
3751 :
3752 256090991 : va_end (p);
3753 :
3754 256090991 : return t;
3755 : }
3756 :
3757 : /* Similar to `build', but for template definitions of non-dependent
3758 : expressions. NON_DEP is the non-dependent expression that has been
3759 : built. */
3760 :
3761 : tree
3762 131720474 : build_min_non_dep (enum tree_code code, tree non_dep, ...)
3763 : {
3764 131720474 : tree t;
3765 131720474 : int length;
3766 131720474 : int i;
3767 131720474 : va_list p;
3768 :
3769 131720474 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3770 :
3771 131720474 : va_start (p, non_dep);
3772 :
3773 131720474 : if (REFERENCE_REF_P (non_dep))
3774 1315748 : non_dep = TREE_OPERAND (non_dep, 0);
3775 :
3776 131720474 : t = make_node (code);
3777 178026930 : SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep));
3778 131720474 : length = TREE_CODE_LENGTH (code);
3779 131720474 : TREE_TYPE (t) = unlowered_expr_type (non_dep);
3780 131720474 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3781 :
3782 461455985 : for (i = 0; i < length; i++)
3783 : {
3784 329735511 : tree x = va_arg (p, tree);
3785 329735511 : TREE_OPERAND (t, i) = x;
3786 329735511 : if (x && !TYPE_P (x))
3787 260030819 : TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
3788 : }
3789 :
3790 131720474 : va_end (p);
3791 131720474 : return convert_from_reference (t);
3792 : }
3793 :
3794 : /* Similar to build_min_nt, but call expressions */
3795 :
3796 : tree
3797 231633962 : build_min_nt_call_vec (tree fn, vec<tree, va_gc> *args)
3798 : {
3799 231633962 : tree ret, t;
3800 231633962 : unsigned int ix;
3801 :
3802 463183213 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
3803 231633962 : CALL_EXPR_FN (ret) = fn;
3804 231633962 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
3805 488823381 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
3806 257189419 : CALL_EXPR_ARG (ret, ix) = t;
3807 :
3808 231633962 : return ret;
3809 : }
3810 :
3811 : /* Similar to `build_min_nt_call_vec', but for template definitions of
3812 : non-dependent expressions. NON_DEP is the non-dependent expression
3813 : that has been built. */
3814 :
3815 : tree
3816 13540074 : build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec)
3817 : {
3818 13540074 : tree t = build_min_nt_call_vec (fn, argvec);
3819 13540074 : if (REFERENCE_REF_P (non_dep))
3820 6 : non_dep = TREE_OPERAND (non_dep, 0);
3821 13540074 : TREE_TYPE (t) = TREE_TYPE (non_dep);
3822 13540074 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3823 13540074 : if (argvec)
3824 27842891 : for (tree x : *argvec)
3825 14387528 : if (x && !TYPE_P (x))
3826 14387528 : TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
3827 13540074 : return convert_from_reference (t);
3828 : }
3829 :
3830 : /* Similar to build_min_non_dep, but for expressions that have been resolved to
3831 : a call to an operator overload. OP is the operator that has been
3832 : overloaded. NON_DEP is the non-dependent expression that's been built,
3833 : which should be a CALL_EXPR or an INDIRECT_REF to a CALL_EXPR. OVERLOAD is
3834 : the overload that NON_DEP is calling. */
3835 :
3836 : tree
3837 6436781 : build_min_non_dep_op_overload (enum tree_code op,
3838 : tree non_dep,
3839 : tree overload, ...)
3840 : {
3841 6436781 : va_list p;
3842 6436781 : int nargs, expected_nargs;
3843 6436781 : tree fn, call, obj = NULL_TREE;
3844 :
3845 6436781 : releasing_vec args;
3846 6436781 : va_start (p, overload);
3847 :
3848 6436781 : bool negated = false, rewritten = false, reversed = false;
3849 6436781 : if (cxx_dialect >= cxx20 && TREE_CODE (overload) == TREE_LIST)
3850 : {
3851 : /* Handle rebuilding a C++20 rewritten comparison operator expression,
3852 : e.g. !(x == y), y <=> x, (x <=> y) @ 0 etc, that resolved to a call
3853 : to a user-defined operator<=>/==. */
3854 540768 : gcc_checking_assert (TREE_CODE_CLASS (op) == tcc_comparison
3855 : || op == SPACESHIP_EXPR);
3856 540768 : int flags = TREE_INT_CST_LOW (TREE_PURPOSE (overload));
3857 540768 : if (TREE_CODE (non_dep) == TRUTH_NOT_EXPR)
3858 : {
3859 494005 : negated = true;
3860 494005 : non_dep = TREE_OPERAND (non_dep, 0);
3861 : }
3862 540768 : if (flags & LOOKUP_REWRITTEN)
3863 540768 : rewritten = true;
3864 540768 : if (flags & LOOKUP_REVERSED)
3865 121 : reversed = true;
3866 540768 : if (rewritten
3867 540768 : && DECL_OVERLOADED_OPERATOR_IS (TREE_VALUE (overload),
3868 : SPACESHIP_EXPR))
3869 : {
3870 : /* Handle (x <=> y) @ 0 and 0 @ (y <=> x) by recursing to first
3871 : rebuild the <=>. Note that both OVERLOAD and the provided arguments
3872 : in this case already correspond to the selected operator<=>. */
3873 :
3874 46741 : tree spaceship_non_dep = (TREE_CODE (non_dep) == CALL_EXPR
3875 93365 : ? CALL_EXPR_ARG (non_dep, reversed ? 1 : 0)
3876 46777 : : TREE_OPERAND (non_dep, reversed ? 1 : 0));
3877 :
3878 46741 : tree int_promotion = NULL_TREE;
3879 46741 : if (TREE_CODE (spaceship_non_dep) == NOP_EXPR)
3880 : {
3881 27 : gcc_checking_assert (TREE_CODE (non_dep) != CALL_EXPR);
3882 27 : int_promotion = TREE_TYPE (spaceship_non_dep);
3883 27 : spaceship_non_dep = TREE_OPERAND (spaceship_non_dep, 0);
3884 : }
3885 :
3886 46741 : gcc_checking_assert (TREE_CODE (spaceship_non_dep) == CALL_EXPR);
3887 46741 : tree spaceship_op0 = va_arg (p, tree);
3888 46741 : tree spaceship_op1 = va_arg (p, tree);
3889 46741 : if (reversed)
3890 81 : std::swap (spaceship_op0, spaceship_op1);
3891 :
3892 : /* Push the correct arguments for the operator OP expression, and
3893 : set OVERLOAD appropriately. */
3894 46741 : tree op0 = build_min_non_dep_op_overload (SPACESHIP_EXPR,
3895 : spaceship_non_dep,
3896 46741 : TREE_VALUE (overload),
3897 : spaceship_op0,
3898 46741 : spaceship_op1);
3899 46741 : tree op1 = (TREE_CODE (non_dep) == CALL_EXPR
3900 93446 : ? CALL_EXPR_ARG (non_dep, reversed ? 0 : 1)
3901 117 : : TREE_OPERAND (non_dep, reversed ? 0 : 1));
3902 46741 : gcc_checking_assert (integer_zerop (op1));
3903 :
3904 46741 : if (TREE_CODE (non_dep) != CALL_EXPR)
3905 : {
3906 81 : gcc_checking_assert (COMPARISON_CLASS_P (non_dep)
3907 : || TREE_CODE (non_dep) == SPACESHIP_EXPR);
3908 81 : if (int_promotion)
3909 27 : op0 = build_nop (int_promotion, op0);
3910 81 : if (reversed)
3911 45 : std::swap (op0, op1);
3912 81 : return build_min_non_dep (TREE_CODE (non_dep), non_dep, op0, op1);
3913 : }
3914 :
3915 46660 : vec_safe_push (args, op0);
3916 46660 : vec_safe_push (args, op1);
3917 46660 : overload = CALL_EXPR_FN (non_dep);
3918 : }
3919 : else
3920 494027 : overload = TREE_VALUE (overload);
3921 : }
3922 6436700 : non_dep = extract_call_expr (non_dep);
3923 :
3924 6436700 : nargs = call_expr_nargs (non_dep);
3925 :
3926 6436700 : expected_nargs = cp_tree_code_length (op);
3927 12130243 : if (DECL_OBJECT_MEMBER_FUNCTION_P (overload)
3928 : /* For ARRAY_REF, operator[] is either a non-static member or newly
3929 : static member, never out of class and for the static member case
3930 : if user uses single index the operator[] needs to have a single
3931 : argument as well, but the function is called with 2 - the object
3932 : it is invoked on and the index. */
3933 12127816 : || op == ARRAY_REF)
3934 745593 : expected_nargs -= 1;
3935 6436700 : if ((op == POSTINCREMENT_EXPR
3936 6436700 : || op == POSTDECREMENT_EXPR)
3937 : /* With -fpermissive non_dep could be operator++(). */
3938 11391 : && (!flag_permissive || nargs != expected_nargs))
3939 11388 : expected_nargs += 1;
3940 6436700 : gcc_assert (nargs == expected_nargs);
3941 :
3942 6436700 : if (!DECL_OBJECT_MEMBER_FUNCTION_P (overload))
3943 : {
3944 5691116 : fn = overload;
3945 5691116 : if (vec_safe_length (args) != 0)
3946 : /* The correct arguments were already pushed above. */
3947 46660 : gcc_checking_assert (rewritten);
3948 : else
3949 : {
3950 5644456 : if (op == ARRAY_REF)
3951 9 : obj = va_arg (p, tree);
3952 16850922 : for (int i = 0; i < nargs; i++)
3953 : {
3954 11206466 : tree arg = va_arg (p, tree);
3955 11206466 : vec_safe_push (args, arg);
3956 : }
3957 : }
3958 5691116 : if (reversed)
3959 52 : std::swap ((*args)[0], (*args)[1]);
3960 : }
3961 : else
3962 : {
3963 745584 : gcc_checking_assert (vec_safe_length (args) == 0);
3964 745584 : tree object = va_arg (p, tree);
3965 1997836 : for (int i = 0; i < nargs; i++)
3966 : {
3967 506668 : tree arg = va_arg (p, tree);
3968 506668 : vec_safe_push (args, arg);
3969 : }
3970 745584 : if (reversed)
3971 24 : std::swap (object, (*args)[0]);
3972 745584 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
3973 745584 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
3974 745584 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
3975 : object, method, NULL_TREE);
3976 : }
3977 :
3978 6436700 : va_end (p);
3979 6436700 : call = build_min_non_dep_call_vec (non_dep, fn, args);
3980 :
3981 6436700 : tree call_expr = extract_call_expr (call);
3982 6436700 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
3983 6436700 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
3984 6436700 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
3985 6436700 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
3986 :
3987 6436700 : if (negated)
3988 494005 : call = build_min (TRUTH_NOT_EXPR, boolean_type_node, call);
3989 6436700 : if (obj)
3990 9 : return keep_unused_object_arg (call, obj, overload);
3991 : return call;
3992 6436781 : }
3993 :
3994 : /* Similar to above build_min_non_dep_op_overload, but arguments
3995 : are taken from ARGS vector. */
3996 :
3997 : tree
3998 29 : build_min_non_dep_op_overload (tree non_dep, tree overload, tree object,
3999 : vec<tree, va_gc> *args)
4000 : {
4001 29 : non_dep = extract_call_expr (non_dep);
4002 :
4003 29 : unsigned int nargs = call_expr_nargs (non_dep);
4004 29 : tree fn = overload;
4005 29 : if (DECL_OBJECT_MEMBER_FUNCTION_P (overload))
4006 : {
4007 17 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
4008 17 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
4009 17 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
4010 : object, method, NULL_TREE);
4011 17 : object = NULL_TREE;
4012 : }
4013 58 : gcc_assert (vec_safe_length (args) == nargs);
4014 :
4015 29 : tree call = build_min_non_dep_call_vec (non_dep, fn, args);
4016 :
4017 29 : tree call_expr = extract_call_expr (call);
4018 29 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
4019 29 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
4020 29 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
4021 29 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
4022 :
4023 29 : if (object)
4024 12 : return keep_unused_object_arg (call, object, overload);
4025 : return call;
4026 : }
4027 :
4028 : /* Return a new tree vec copied from VEC, with ELT inserted at index IDX. */
4029 :
4030 : vec<tree, va_gc> *
4031 9352 : vec_copy_and_insert (vec<tree, va_gc> *old_vec, tree elt, unsigned idx)
4032 : {
4033 9352 : unsigned len = vec_safe_length (old_vec);
4034 9352 : gcc_assert (idx <= len);
4035 :
4036 9352 : vec<tree, va_gc> *new_vec = NULL;
4037 9352 : vec_alloc (new_vec, len + 1);
4038 :
4039 9352 : unsigned i;
4040 28117 : for (i = 0; i < len; ++i)
4041 : {
4042 9413 : if (i == idx)
4043 61 : new_vec->quick_push (elt);
4044 9413 : new_vec->quick_push ((*old_vec)[i]);
4045 : }
4046 9352 : if (i == idx)
4047 9291 : new_vec->quick_push (elt);
4048 :
4049 9352 : return new_vec;
4050 : }
4051 :
4052 : tree
4053 148639 : get_type_decl (tree t)
4054 : {
4055 148639 : if (TREE_CODE (t) == TYPE_DECL)
4056 : return t;
4057 148639 : if (TYPE_P (t))
4058 148639 : return TYPE_STUB_DECL (t);
4059 0 : gcc_assert (t == error_mark_node);
4060 : return t;
4061 : }
4062 :
4063 : /* Returns the namespace that contains DECL, whether directly or
4064 : indirectly. */
4065 :
4066 : tree
4067 1354354217 : decl_namespace_context (tree decl)
4068 : {
4069 2811758529 : while (1)
4070 : {
4071 2811758529 : if (TREE_CODE (decl) == NAMESPACE_DECL)
4072 1354354217 : return decl;
4073 1457404312 : else if (TYPE_P (decl))
4074 881641499 : decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
4075 : else
4076 575762813 : decl = CP_DECL_CONTEXT (decl);
4077 : }
4078 : }
4079 :
4080 : /* Returns true if decl is within an anonymous namespace, however deeply
4081 : nested, or false otherwise. */
4082 :
4083 : bool
4084 2061 : decl_anon_ns_mem_p (tree decl)
4085 : {
4086 2061 : return !TREE_PUBLIC (decl_namespace_context (decl));
4087 : }
4088 :
4089 : /* Returns true if the enclosing scope of DECL has internal or no linkage. */
4090 :
4091 : bool
4092 1394780129 : decl_internal_context_p (const_tree decl)
4093 : {
4094 2794587395 : while (TREE_CODE (decl) != NAMESPACE_DECL)
4095 : {
4096 : /* Classes inside anonymous namespaces have TREE_PUBLIC == 0. */
4097 1758389229 : if (TYPE_P (decl))
4098 358581963 : return !TREE_PUBLIC (TYPE_MAIN_DECL (decl));
4099 :
4100 1399807266 : decl = CP_DECL_CONTEXT (decl);
4101 : }
4102 1036198166 : return !TREE_PUBLIC (decl);
4103 : }
4104 :
4105 : /* Subroutine of cp_tree_equal: t1 and t2 are two CALL_EXPRs.
4106 : Return whether their CALL_EXPR_FNs are equivalent. */
4107 :
4108 : static bool
4109 55431098 : called_fns_equal (tree t1, tree t2)
4110 : {
4111 : /* Core 1321: dependent names are equivalent even if the overload sets
4112 : are different. But do compare explicit template arguments. */
4113 55431098 : tree name1 = call_expr_dependent_name (t1);
4114 55431098 : tree name2 = call_expr_dependent_name (t2);
4115 55431098 : t1 = CALL_EXPR_FN (t1);
4116 55431098 : t2 = CALL_EXPR_FN (t2);
4117 55431098 : if (name1 || name2)
4118 : {
4119 47727302 : tree targs1 = NULL_TREE, targs2 = NULL_TREE;
4120 :
4121 47727302 : if (name1 != name2)
4122 : return false;
4123 :
4124 : /* FIXME dependent_name currently returns an unqualified name regardless
4125 : of whether the function was named with a qualified- or unqualified-id.
4126 : Until that's fixed, check that we aren't looking at overload sets from
4127 : different scopes. */
4128 47034114 : if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
4129 94101608 : && (DECL_CONTEXT (get_first_fn (t1))
4130 47034111 : != DECL_CONTEXT (get_first_fn (t2))))
4131 : return false;
4132 :
4133 47067497 : if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
4134 29529622 : targs1 = TREE_OPERAND (t1, 1);
4135 47067497 : if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
4136 29529622 : targs2 = TREE_OPERAND (t2, 1);
4137 47067497 : return cp_tree_equal (targs1, targs2);
4138 : }
4139 : else
4140 7703796 : return cp_tree_equal (t1, t2);
4141 : }
4142 :
4143 : /* Return truthvalue of whether T1 is the same tree structure as T2.
4144 : Return 1 if they are the same. Return 0 if they are different. */
4145 :
4146 : bool
4147 2757129280 : cp_tree_equal (tree t1, tree t2)
4148 : {
4149 2765714025 : enum tree_code code1, code2;
4150 :
4151 2765714025 : if (t1 == t2)
4152 : return true;
4153 1255126437 : if (!t1 || !t2)
4154 : return false;
4155 :
4156 1254440394 : code1 = TREE_CODE (t1);
4157 1254440394 : code2 = TREE_CODE (t2);
4158 :
4159 1254440394 : if (comparing_contracts)
4160 : {
4161 : /* When comparing contracts, one declaration may already be
4162 : genericized. Check for invisible references and unravel them
4163 : for comparison purposes. Remember that a parameter is an invisible
4164 : reference so we can compare the parameter types accordingly. */
4165 213 : if (code1 == VIEW_CONVERT_EXPR
4166 213 : && is_invisiref_parm (TREE_OPERAND(t1, 0)))
4167 : {
4168 3 : t1 = TREE_OPERAND(t1, 0);
4169 3 : code1 = TREE_CODE(t1);
4170 : }
4171 213 : if (code2 == VIEW_CONVERT_EXPR
4172 213 : && is_invisiref_parm (TREE_OPERAND(t2, 0)))
4173 : {
4174 0 : t2 = TREE_OPERAND(t2, 0);
4175 0 : code2 = TREE_CODE(t2);
4176 : }
4177 : }
4178 :
4179 1254440394 : if (code1 != code2)
4180 : return false;
4181 :
4182 1130315045 : if (CONSTANT_CLASS_P (t1)
4183 1130315045 : && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4184 : return false;
4185 :
4186 1130230198 : switch (code1)
4187 : {
4188 0 : case VOID_CST:
4189 : /* There's only a single VOID_CST node, so we should never reach
4190 : here. */
4191 0 : gcc_unreachable ();
4192 :
4193 177306780 : case INTEGER_CST:
4194 177306780 : return tree_int_cst_equal (t1, t2);
4195 :
4196 111637 : case REAL_CST:
4197 111637 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
4198 :
4199 153387 : case STRING_CST:
4200 153387 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
4201 153387 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
4202 153387 : TREE_STRING_LENGTH (t1));
4203 :
4204 0 : case FIXED_CST:
4205 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
4206 : TREE_FIXED_CST (t2));
4207 :
4208 25 : case COMPLEX_CST:
4209 25 : return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
4210 50 : && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
4211 :
4212 15045 : case VECTOR_CST:
4213 15045 : return operand_equal_p (t1, t2, OEP_ONLY_CONST);
4214 :
4215 1570702 : case CONSTRUCTOR:
4216 : /* We need to do this when determining whether or not two
4217 : non-type pointer to member function template arguments
4218 : are the same. */
4219 1570702 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
4220 3397008 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
4221 : return false;
4222 : {
4223 : tree field, value;
4224 : unsigned int i;
4225 1719645 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
4226 : {
4227 194397 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
4228 194397 : if (!cp_tree_equal (field, elt2->index)
4229 194397 : || !cp_tree_equal (value, elt2->value))
4230 : return false;
4231 : }
4232 : }
4233 : return true;
4234 :
4235 6261924 : case TREE_LIST:
4236 6261924 : if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
4237 : return false;
4238 6261924 : if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
4239 : return false;
4240 29522 : return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
4241 :
4242 743 : case SAVE_EXPR:
4243 743 : return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4244 :
4245 55445421 : case CALL_EXPR:
4246 55445421 : {
4247 55445421 : if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
4248 : return false;
4249 :
4250 55431098 : if (!called_fns_equal (t1, t2))
4251 : return false;
4252 :
4253 25001265 : call_expr_arg_iterator iter1, iter2;
4254 25001265 : init_call_expr_arg_iterator (t1, &iter1);
4255 25001265 : init_call_expr_arg_iterator (t2, &iter2);
4256 25001265 : if (iter1.n != iter2.n)
4257 : return false;
4258 :
4259 26546366 : while (more_call_expr_args_p (&iter1))
4260 : {
4261 18287578 : tree arg1 = next_call_expr_arg (&iter1);
4262 18287578 : tree arg2 = next_call_expr_arg (&iter2);
4263 :
4264 18287578 : gcc_checking_assert (arg1 && arg2);
4265 18287578 : if (!cp_tree_equal (arg1, arg2))
4266 : return false;
4267 : }
4268 :
4269 : return true;
4270 : }
4271 :
4272 418887 : case TARGET_EXPR:
4273 418887 : {
4274 418887 : tree o1 = TARGET_EXPR_SLOT (t1);
4275 418887 : tree o2 = TARGET_EXPR_SLOT (t2);
4276 :
4277 : /* Special case: if either target is an unallocated VAR_DECL,
4278 : it means that it's going to be unified with whatever the
4279 : TARGET_EXPR is really supposed to initialize, so treat it
4280 : as being equivalent to anything. */
4281 418887 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
4282 837774 : && !DECL_RTL_SET_P (o1))
4283 : /*Nop*/;
4284 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
4285 0 : && !DECL_RTL_SET_P (o2))
4286 : /*Nop*/;
4287 0 : else if (!cp_tree_equal (o1, o2))
4288 : return false;
4289 :
4290 418887 : return cp_tree_equal (TARGET_EXPR_INITIAL (t1),
4291 837774 : TARGET_EXPR_INITIAL (t2));
4292 : }
4293 :
4294 29 : case AGGR_INIT_EXPR:
4295 29 : {
4296 29 : int n = aggr_init_expr_nargs (t1);
4297 29 : if (n != aggr_init_expr_nargs (t2))
4298 : return false;
4299 :
4300 58 : if (!cp_tree_equal (AGGR_INIT_EXPR_FN (t1),
4301 29 : AGGR_INIT_EXPR_FN (t2)))
4302 : return false;
4303 :
4304 29 : tree o1 = AGGR_INIT_EXPR_SLOT (t1);
4305 29 : tree o2 = AGGR_INIT_EXPR_SLOT (t2);
4306 :
4307 : /* Similarly to TARGET_EXPRs, if the VAR_DECL is unallocated we're
4308 : going to unify the initialization, so treat it as equivalent
4309 : to anything. */
4310 29 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
4311 58 : && !DECL_RTL_SET_P (o1))
4312 : /*Nop*/;
4313 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
4314 0 : && !DECL_RTL_SET_P (o2))
4315 : /*Nop*/;
4316 0 : else if (!cp_tree_equal (o1, o2))
4317 : return false;
4318 :
4319 58 : for (int i = 0; i < n; ++i)
4320 35 : if (!cp_tree_equal (AGGR_INIT_EXPR_ARG (t1, i),
4321 35 : AGGR_INIT_EXPR_ARG (t2, i)))
4322 : return false;
4323 :
4324 : return true;
4325 : }
4326 :
4327 1970474 : case PARM_DECL:
4328 : /* For comparing uses of parameters in late-specified return types
4329 : with an out-of-class definition of the function, but can also come
4330 : up for expressions that involve 'this' in a member function
4331 : template. */
4332 :
4333 1970474 : if (comparing_specializations
4334 1970474 : && DECL_CONTEXT (t1) != DECL_CONTEXT (t2))
4335 : /* When comparing hash table entries, only an exact match is
4336 : good enough; we don't want to replace 'this' with the
4337 : version from another function. But be more flexible
4338 : with parameters with identical contexts. */
4339 : return false;
4340 :
4341 1573757 : if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) || comparing_contracts)
4342 : {
4343 : /* When comparing contracts, we already know the declarations match,
4344 : and that the arguments have the same type. If one of the declarations
4345 : has been genericised, then the type of arguments in that declaration
4346 : will be adjusted for an invisible reference and the type comparison
4347 : would spuriosly fail. The only thing we care about when comparing
4348 : contractsis that we're using the same parameter. */
4349 808962 : if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
4350 : return false;
4351 808962 : if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
4352 : return false;
4353 808962 : if (DECL_ARTIFICIAL (t1)
4354 808962 : || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
4355 808325 : && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
4356 : return true;
4357 : }
4358 : return false;
4359 :
4360 17040150 : case TEMPLATE_DECL:
4361 17040150 : if (DECL_TEMPLATE_TEMPLATE_PARM_P (t1)
4362 18018102 : && DECL_TEMPLATE_TEMPLATE_PARM_P (t2))
4363 657427 : return cp_tree_equal (TREE_TYPE (t1), TREE_TYPE (t2));
4364 : /* Fall through. */
4365 : case VAR_DECL:
4366 : case CONST_DECL:
4367 : case FIELD_DECL:
4368 : case FUNCTION_DECL:
4369 : case IDENTIFIER_NODE:
4370 : case SSA_NAME:
4371 : case USING_DECL:
4372 : case DEFERRED_PARSE:
4373 : case NAMESPACE_DECL:
4374 : return false;
4375 :
4376 5186497 : case BASELINK:
4377 5186497 : return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
4378 4403772 : && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
4379 4403772 : && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
4380 9590257 : && cp_tree_equal (BASELINK_FUNCTIONS (t1),
4381 4403760 : BASELINK_FUNCTIONS (t2)));
4382 :
4383 14086725 : case TEMPLATE_PARM_INDEX:
4384 14086725 : return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
4385 13419041 : && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
4386 12729627 : && (TEMPLATE_PARM_PARAMETER_PACK (t1)
4387 12729627 : == TEMPLATE_PARM_PARAMETER_PACK (t2))
4388 26769794 : && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
4389 : TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
4390 :
4391 23913010 : case TEMPLATE_ID_EXPR:
4392 23913010 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4393 : return false;
4394 22455764 : if (!comp_template_args (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)))
4395 : return false;
4396 : return true;
4397 :
4398 7476483 : case CONSTRAINT_INFO:
4399 22429449 : return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1),
4400 22429449 : CI_ASSOCIATED_CONSTRAINTS (t2));
4401 :
4402 57605825 : case TREE_VEC:
4403 : /* These are template args. Really we should be getting the
4404 : caller to do this as it knows it to be true. */
4405 57605825 : if (!comp_template_args (t1, t2))
4406 : return false;
4407 : return true;
4408 :
4409 1704915 : case SIZEOF_EXPR:
4410 1704915 : case ALIGNOF_EXPR:
4411 1704915 : {
4412 1704915 : tree o1 = TREE_OPERAND (t1, 0);
4413 1704915 : tree o2 = TREE_OPERAND (t2, 0);
4414 :
4415 1704915 : if (code1 == SIZEOF_EXPR)
4416 : {
4417 1695548 : if (SIZEOF_EXPR_TYPE_P (t1))
4418 0 : o1 = TREE_TYPE (o1);
4419 1695548 : if (SIZEOF_EXPR_TYPE_P (t2))
4420 0 : o2 = TREE_TYPE (o2);
4421 : }
4422 9367 : else if (ALIGNOF_EXPR_STD_P (t1) != ALIGNOF_EXPR_STD_P (t2))
4423 : return false;
4424 :
4425 1704909 : if (TREE_CODE (o1) != TREE_CODE (o2))
4426 : return false;
4427 :
4428 1704883 : if (ARGUMENT_PACK_P (o1))
4429 6 : return template_args_equal (o1, o2);
4430 1704877 : else if (TYPE_P (o1))
4431 1703467 : return same_type_p (o1, o2);
4432 : else
4433 : return cp_tree_equal (o1, o2);
4434 : }
4435 :
4436 3405 : case MODOP_EXPR:
4437 3405 : {
4438 3405 : tree t1_op1, t2_op1;
4439 :
4440 3405 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4441 : return false;
4442 :
4443 2841 : t1_op1 = TREE_OPERAND (t1, 1);
4444 2841 : t2_op1 = TREE_OPERAND (t2, 1);
4445 2841 : if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
4446 : return false;
4447 :
4448 273 : return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
4449 : }
4450 :
4451 772 : case PTRMEM_CST:
4452 : /* Two pointer-to-members are the same if they point to the same
4453 : field or function in the same class. */
4454 772 : if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
4455 : return false;
4456 :
4457 924 : return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
4458 :
4459 20639 : case OVERLOAD:
4460 20639 : {
4461 : /* Two overloads. Must be exactly the same set of decls. */
4462 20639 : lkp_iterator first (t1);
4463 20639 : lkp_iterator second (t2);
4464 :
4465 29422 : for (; first && second; ++first, ++second)
4466 21173 : if (*first != *second)
4467 : return false;
4468 8249 : return !(first || second);
4469 : }
4470 :
4471 9026698 : case TRAIT_EXPR:
4472 9026698 : if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
4473 : return false;
4474 886597 : return cp_tree_equal (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
4475 1708582 : && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
4476 :
4477 1140340 : case NON_LVALUE_EXPR:
4478 1140340 : case VIEW_CONVERT_EXPR:
4479 : /* Used for location wrappers with possibly NULL types. */
4480 1140340 : if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
4481 : {
4482 20 : if (TREE_TYPE (t1) || TREE_TYPE (t2))
4483 : return false;
4484 : break;
4485 : }
4486 : /* FALLTHROUGH */
4487 :
4488 6958529 : case CAST_EXPR:
4489 6958529 : case STATIC_CAST_EXPR:
4490 6958529 : case REINTERPRET_CAST_EXPR:
4491 6958529 : case CONST_CAST_EXPR:
4492 6958529 : case DYNAMIC_CAST_EXPR:
4493 6958529 : case IMPLICIT_CONV_EXPR:
4494 6958529 : case NEW_EXPR:
4495 6958529 : case BIT_CAST_EXPR:
4496 6958529 : CASE_CONVERT:
4497 6958529 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4498 : return false;
4499 : /* Now compare operands as usual. */
4500 : break;
4501 :
4502 0 : case DEFERRED_NOEXCEPT:
4503 0 : return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1),
4504 0 : DEFERRED_NOEXCEPT_PATTERN (t2))
4505 0 : && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1),
4506 0 : DEFERRED_NOEXCEPT_ARGS (t2)));
4507 :
4508 : case LAMBDA_EXPR:
4509 : /* Two lambda-expressions are never considered equivalent. */
4510 : return false;
4511 :
4512 633708814 : case TYPE_ARGUMENT_PACK:
4513 633708814 : case NONTYPE_ARGUMENT_PACK:
4514 633708814 : {
4515 633708814 : tree p1 = ARGUMENT_PACK_ARGS (t1);
4516 633708814 : tree p2 = ARGUMENT_PACK_ARGS (t2);
4517 633708814 : int len = TREE_VEC_LENGTH (p1);
4518 633708814 : if (TREE_VEC_LENGTH (p2) != len)
4519 : return false;
4520 :
4521 762702880 : for (int ix = 0; ix != len; ix++)
4522 678466257 : if (!template_args_equal (TREE_VEC_ELT (p1, ix),
4523 678466257 : TREE_VEC_ELT (p2, ix)))
4524 : return false;
4525 : return true;
4526 : }
4527 :
4528 779706 : case EXPR_PACK_EXPANSION:
4529 779706 : if (!cp_tree_equal (PACK_EXPANSION_PATTERN (t1),
4530 779706 : PACK_EXPANSION_PATTERN (t2)))
4531 : return false;
4532 26717 : if (!comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
4533 26717 : PACK_EXPANSION_EXTRA_ARGS (t2)))
4534 : return false;
4535 : return true;
4536 :
4537 2443 : case PACK_INDEX_EXPR:
4538 2443 : if (!cp_tree_equal (PACK_INDEX_PACK (t1),
4539 2443 : PACK_INDEX_PACK (t2)))
4540 : return false;
4541 124 : if (!cp_tree_equal (PACK_INDEX_INDEX (t1),
4542 124 : PACK_INDEX_INDEX (t2)))
4543 : return false;
4544 : return true;
4545 :
4546 2250 : case REFLECT_EXPR:
4547 2250 : return compare_reflections (t1, t2);
4548 :
4549 6374985 : case REQUIRES_EXPR:
4550 12749970 : if (cp_tree_equal (REQUIRES_EXPR_PARMS (t1),
4551 6374985 : REQUIRES_EXPR_PARMS (t2))
4552 6204319 : && cp_tree_equal (REQUIRES_EXPR_REQS (t1),
4553 6204319 : REQUIRES_EXPR_REQS (t2))
4554 6385371 : && cp_tree_equal (REQUIRES_EXPR_EXTRA_ARGS (t1),
4555 10386 : REQUIRES_EXPR_EXTRA_ARGS (t2)))
4556 : return true;
4557 : return false;
4558 :
4559 : default:
4560 : break;
4561 : }
4562 :
4563 72210834 : switch (TREE_CODE_CLASS (code1))
4564 : {
4565 67012127 : case tcc_unary:
4566 67012127 : case tcc_binary:
4567 67012127 : case tcc_comparison:
4568 67012127 : case tcc_expression:
4569 67012127 : case tcc_vl_exp:
4570 67012127 : case tcc_reference:
4571 67012127 : case tcc_statement:
4572 67012127 : {
4573 67012127 : int n = cp_tree_operand_length (t1);
4574 67012127 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
4575 67012127 : && n != TREE_OPERAND_LENGTH (t2))
4576 : return false;
4577 :
4578 112072994 : for (int i = 0; i < n; ++i)
4579 84591606 : if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
4580 : return false;
4581 :
4582 : return true;
4583 : }
4584 :
4585 5198707 : case tcc_type:
4586 5198707 : return same_type_p (t1, t2);
4587 :
4588 0 : default:
4589 0 : gcc_unreachable ();
4590 : }
4591 :
4592 : /* We can get here with --disable-checking. */
4593 : return false;
4594 : }
4595 :
4596 : /* The type of ARG when used as an lvalue. */
4597 :
4598 : tree
4599 899801023 : lvalue_type (tree arg)
4600 : {
4601 899801023 : tree type = TREE_TYPE (arg);
4602 899801023 : return type;
4603 : }
4604 :
4605 : /* The type of ARG for printing error messages; denote lvalues with
4606 : reference types. */
4607 :
4608 : tree
4609 3795 : error_type (tree arg)
4610 : {
4611 3795 : tree type = TREE_TYPE (arg);
4612 :
4613 3795 : if (TREE_CODE (type) == ARRAY_TYPE)
4614 : ;
4615 3684 : else if (TREE_CODE (type) == ERROR_MARK)
4616 : ;
4617 3684 : else if (lvalue_p (arg))
4618 1284 : type = build_reference_type (lvalue_type (arg));
4619 2400 : else if (MAYBE_CLASS_TYPE_P (type))
4620 754 : type = lvalue_type (arg);
4621 :
4622 3795 : return type;
4623 : }
4624 :
4625 : /* Does FUNCTION use a variable-length argument list? */
4626 :
4627 : int
4628 507059 : varargs_function_p (const_tree function)
4629 : {
4630 507059 : return stdarg_p (TREE_TYPE (function));
4631 : }
4632 :
4633 : /* Returns 1 if decl is a member of a class. */
4634 :
4635 : int
4636 11370 : member_p (const_tree decl)
4637 : {
4638 11370 : const_tree const ctx = DECL_CONTEXT (decl);
4639 11370 : return (ctx && TYPE_P (ctx));
4640 : }
4641 :
4642 : /* Create a placeholder for member access where we don't actually have an
4643 : object that the access is against. For a general declval<T> equivalent,
4644 : use build_stub_object instead. */
4645 :
4646 : tree
4647 87363057 : build_dummy_object (tree type)
4648 : {
4649 87363057 : tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node);
4650 87363057 : return cp_build_fold_indirect_ref (decl);
4651 : }
4652 :
4653 : /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
4654 : or a dummy object otherwise. If BINFOP is non-0, it is filled with the
4655 : binfo path from current_class_type to TYPE, or 0. */
4656 :
4657 : tree
4658 113318339 : maybe_dummy_object (tree type, tree* binfop)
4659 : {
4660 113318339 : tree decl, context;
4661 113318339 : tree binfo;
4662 113318339 : tree current = current_nonlambda_class_type ();
4663 :
4664 113318339 : if (current
4665 113318339 : && (binfo = lookup_base (current, type, ba_any, NULL,
4666 : tf_warning_or_error)))
4667 : context = current;
4668 : else
4669 : {
4670 : /* Reference from a nested class member function. */
4671 8391333 : context = type;
4672 8391333 : binfo = TYPE_BINFO (type);
4673 : }
4674 :
4675 113318339 : if (binfop)
4676 111010 : *binfop = binfo;
4677 :
4678 : /* current_class_ref might not correspond to current_class_type if
4679 : we're in tsubst_default_argument or a lambda-declarator; in either
4680 : case, we want to use current_class_ref if it matches CONTEXT. */
4681 113318339 : tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE;
4682 104120476 : if (ctype
4683 104120476 : && same_type_ignoring_top_level_qualifiers_p (ctype, context))
4684 100861717 : decl = current_class_ref;
4685 : else
4686 : {
4687 : /* Return a dummy object whose cv-quals are consistent with (the
4688 : non-lambda) 'this' if available. */
4689 12456622 : if (ctype)
4690 : {
4691 3258759 : auto quals = TYPE_UNQUALIFIED;
4692 3258759 : if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype))
4693 : {
4694 424369 : if (tree cap = lambda_expr_this_capture (lambda, false))
4695 409437 : quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap)));
4696 : }
4697 : else
4698 2834390 : quals = cp_type_quals (ctype);
4699 3258759 : context = cp_build_qualified_type (context, quals);
4700 : }
4701 12456622 : decl = build_dummy_object (context);
4702 : }
4703 :
4704 113318339 : return decl;
4705 : }
4706 :
4707 : /* Returns 1 if OB is a placeholder object, or a pointer to one. */
4708 :
4709 : bool
4710 534887836 : is_dummy_object (const_tree ob)
4711 : {
4712 534887836 : if (INDIRECT_REF_P (ob))
4713 410453685 : ob = TREE_OPERAND (ob, 0);
4714 534887836 : return (TREE_CODE (ob) == CONVERT_EXPR
4715 534887836 : && TREE_OPERAND (ob, 0) == void_node);
4716 : }
4717 :
4718 : /* Returns true if TYPE is char, unsigned char, or std::byte. */
4719 :
4720 : bool
4721 34410419 : is_byte_access_type (tree type)
4722 : {
4723 34410419 : type = TYPE_MAIN_VARIANT (type);
4724 34410419 : if (type == char_type_node
4725 7382630 : || type == unsigned_char_type_node)
4726 : return true;
4727 :
4728 7240309 : return (TREE_CODE (type) == ENUMERAL_TYPE
4729 28406 : && TYPE_CONTEXT (type) == std_node
4730 7259123 : && !strcmp ("byte", TYPE_NAME_STRING (type)));
4731 : }
4732 :
4733 : /* Returns true if TYPE is unsigned char or std::byte. */
4734 :
4735 : bool
4736 14414 : is_byte_access_type_not_plain_char (tree type)
4737 : {
4738 14414 : type = TYPE_MAIN_VARIANT (type);
4739 14414 : if (type == char_type_node)
4740 : return false;
4741 :
4742 14166 : return is_byte_access_type (type);
4743 : }
4744 :
4745 : /* Returns 1 iff type T is something we want to treat as a scalar type for
4746 : the purpose of deciding whether it is trivial/POD/standard-layout. */
4747 :
4748 : bool
4749 91302810 : scalarish_type_p (const_tree t)
4750 : {
4751 91302810 : if (t == error_mark_node)
4752 : return 1;
4753 :
4754 91302595 : return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
4755 : }
4756 :
4757 : /* Returns true iff T requires non-trivial default initialization. */
4758 :
4759 : bool
4760 0 : type_has_nontrivial_default_init (const_tree t)
4761 : {
4762 0 : t = strip_array_types (const_cast<tree> (t));
4763 :
4764 0 : if (CLASS_TYPE_P (t))
4765 0 : return TYPE_HAS_COMPLEX_DFLT (t);
4766 : else
4767 : return 0;
4768 : }
4769 :
4770 : /* Track classes with only deleted copy/move constructors so that we can warn
4771 : if they are used in call/return by value. */
4772 :
4773 : static GTY(()) hash_set<tree>* deleted_copy_types;
4774 : static void
4775 9 : remember_deleted_copy (const_tree t)
4776 : {
4777 9 : if (!deleted_copy_types)
4778 9 : deleted_copy_types = hash_set<tree>::create_ggc(37);
4779 9 : deleted_copy_types->add (const_cast<tree> (t));
4780 9 : }
4781 : void
4782 374308619 : maybe_warn_parm_abi (tree t, location_t loc)
4783 : {
4784 374308619 : if (!deleted_copy_types
4785 374308619 : || !deleted_copy_types->contains (t))
4786 374308589 : return;
4787 :
4788 30 : if ((flag_abi_version == 12 || warn_abi_version == 12)
4789 36 : && classtype_has_non_deleted_move_ctor (t))
4790 : {
4791 6 : bool w;
4792 6 : auto_diagnostic_group d;
4793 6 : if (flag_abi_version > 12)
4794 0 : w = warning_at (loc, OPT_Wabi, "%<-fabi-version=13%> (GCC 8.2) fixes "
4795 : "the calling convention for %qT, which was "
4796 : "accidentally changed in 8.1", t);
4797 : else
4798 6 : w = warning_at (loc, OPT_Wabi, "%<-fabi-version=12%> (GCC 8.1) "
4799 : "accidentally changes the calling convention for %qT",
4800 : t);
4801 6 : if (w)
4802 6 : inform (location_of (t), " declared here");
4803 6 : return;
4804 6 : }
4805 :
4806 30 : auto_diagnostic_group d;
4807 30 : if (warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in "
4808 : "%<-fabi-version=13%> (GCC 8.2)", t))
4809 30 : inform (location_of (t), " because all of its copy and move "
4810 : "constructors are deleted");
4811 30 : }
4812 :
4813 : /* Returns true iff copying an object of type T (including via move
4814 : constructor) is non-trivial. That is, T has no non-trivial copy
4815 : constructors and no non-trivial move constructors, and not all copy/move
4816 : constructors are deleted. This function implements the ABI notion of
4817 : non-trivial copy, which has diverged from the one in the standard. */
4818 :
4819 : bool
4820 59764412 : type_has_nontrivial_copy_init (const_tree type)
4821 : {
4822 59764412 : tree t = strip_array_types (const_cast<tree> (type));
4823 :
4824 59764412 : if (CLASS_TYPE_P (t))
4825 : {
4826 59077196 : gcc_assert (COMPLETE_TYPE_P (t));
4827 :
4828 59077196 : if (TYPE_HAS_COMPLEX_COPY_CTOR (t)
4829 59077196 : || TYPE_HAS_COMPLEX_MOVE_CTOR (t))
4830 : /* Nontrivial. */
4831 : return true;
4832 :
4833 54989018 : if (cxx_dialect < cxx11)
4834 : /* No deleted functions before C++11. */
4835 : return false;
4836 :
4837 : /* Before ABI v12 we did a bitwise copy of types with only deleted
4838 : copy/move constructors. */
4839 54899137 : if (!abi_version_at_least (12)
4840 8132 : && !(warn_abi && abi_version_crosses (12)))
4841 : return false;
4842 :
4843 54891235 : bool saw_copy = false;
4844 54891235 : bool saw_non_deleted = false;
4845 54891235 : bool saw_non_deleted_move = false;
4846 :
4847 54891235 : if (CLASSTYPE_LAZY_MOVE_CTOR (t))
4848 : saw_copy = saw_non_deleted = true;
4849 5072841 : else if (CLASSTYPE_LAZY_COPY_CTOR (t))
4850 : {
4851 580365 : saw_copy = true;
4852 580365 : if (classtype_has_move_assign_or_move_ctor_p (t, true))
4853 : /* [class.copy]/8 If the class definition declares a move
4854 : constructor or move assignment operator, the implicitly declared
4855 : copy constructor is defined as deleted.... */;
4856 : else
4857 : /* Any other reason the implicitly-declared function would be
4858 : deleted would also cause TYPE_HAS_COMPLEX_COPY_CTOR to be
4859 : set. */
4860 : saw_non_deleted = true;
4861 : }
4862 :
4863 : if (!saw_non_deleted)
4864 20386122 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
4865 : {
4866 12111064 : tree fn = *iter;
4867 12111064 : if (copy_fn_p (fn))
4868 : {
4869 4492531 : saw_copy = true;
4870 4492531 : if (!DECL_DELETED_FN (fn))
4871 : {
4872 : /* Not deleted, therefore trivial. */
4873 : saw_non_deleted = true;
4874 : break;
4875 : }
4876 : }
4877 7618533 : else if (move_fn_p (fn))
4878 3152089 : if (!DECL_DELETED_FN (fn))
4879 3129956 : saw_non_deleted_move = true;
4880 : }
4881 :
4882 54891235 : gcc_assert (saw_copy);
4883 :
4884 : /* ABI v12 buggily ignored move constructors. */
4885 54891235 : bool v11nontriv = false;
4886 54891235 : bool v12nontriv = !saw_non_deleted;
4887 54891235 : bool v13nontriv = !saw_non_deleted && !saw_non_deleted_move;
4888 54891235 : bool nontriv = (abi_version_at_least (13) ? v13nontriv
4889 124 : : flag_abi_version == 12 ? v12nontriv
4890 124 : : v11nontriv);
4891 54891235 : bool warn_nontriv = (warn_abi_version >= 13 ? v13nontriv
4892 428 : : warn_abi_version == 12 ? v12nontriv
4893 : : v11nontriv);
4894 54891235 : if (nontriv != warn_nontriv)
4895 9 : remember_deleted_copy (t);
4896 :
4897 : return nontriv;
4898 : }
4899 : else
4900 : return 0;
4901 : }
4902 :
4903 : /* Returns 1 iff type T is a trivially copyable type, as defined in
4904 : [basic.types] and [class]. */
4905 :
4906 : bool
4907 546782 : trivially_copyable_p (const_tree t)
4908 : {
4909 546782 : t = strip_array_types (const_cast<tree> (t));
4910 :
4911 546782 : if (CLASS_TYPE_P (t))
4912 85173 : return ((!TYPE_HAS_COPY_CTOR (t)
4913 85173 : || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
4914 84228 : && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
4915 84190 : && (!TYPE_HAS_COPY_ASSIGN (t)
4916 84190 : || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
4917 83174 : && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
4918 168178 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
4919 : else
4920 : /* CWG 2094 makes volatile-qualified scalars trivially copyable again. */
4921 461609 : return scalarish_type_p (t);
4922 : }
4923 :
4924 : /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
4925 : [class]. */
4926 :
4927 : bool
4928 77608 : trivial_type_p (const_tree t)
4929 : {
4930 77608 : t = strip_array_types (const_cast<tree> (t));
4931 :
4932 77608 : if (CLASS_TYPE_P (t))
4933 : /* A trivial class is a class that is trivially copyable and has one or
4934 : more eligible default constructors, all of which are trivial. */
4935 19966 : return (type_has_non_deleted_trivial_default_ctor (const_cast<tree> (t))
4936 19966 : && trivially_copyable_p (t));
4937 : else
4938 57642 : return scalarish_type_p (t);
4939 : }
4940 :
4941 : /* Returns true iff type T is a trivially copy constructible type. */
4942 :
4943 : bool
4944 89 : trivially_copy_constructible_p (tree t)
4945 : {
4946 89 : tree arg = make_tree_vec (1);
4947 89 : TREE_VEC_ELT (arg, 0) = build_const_lref (t);
4948 89 : return is_trivially_xible (INIT_EXPR, t, arg);
4949 : }
4950 :
4951 : /* Returns true iff FN (which is a special member function) is
4952 : an eligible special member function, as defined in [special]/6.
4953 : The "no special member function of the same kind whose associated
4954 : constraints, if any, are satisfied is more constrained" condition
4955 : is not checked, this is checked during add_method instead. */
4956 :
4957 : static bool
4958 494 : eligible_special_member_function_p (tree fn)
4959 : {
4960 : /* The function is not deleted. */
4961 494 : if (DECL_DELETED_FN (fn))
4962 : return false;
4963 : /* The associated constraints, if any, are satisfied. */
4964 494 : if (!constraints_satisfied_p (fn))
4965 : return false;
4966 : return true;
4967 : }
4968 :
4969 : /* Returns true iff type T is an implicit-lifetime type, as defined in
4970 : [basic.types.general] and [class.prop]. */
4971 :
4972 : bool
4973 1742 : implicit_lifetime_type_p (tree t)
4974 : {
4975 1742 : if (SCALAR_TYPE_P (t)
4976 1438 : || (TREE_CODE (t) == ARRAY_TYPE
4977 495 : && !(TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t))))
4978 : /* GNU extension. */
4979 948 : || TREE_CODE (t) == VECTOR_TYPE)
4980 : return true;
4981 943 : if (!CLASS_TYPE_P (t))
4982 : return false;
4983 871 : t = TYPE_MAIN_VARIANT (t);
4984 : /* It is an aggregate whose destructor is not user-provided. */
4985 1742 : if (CP_AGGREGATE_TYPE_P (t)
4986 1187 : && (!CLASSTYPE_DESTRUCTOR (t)
4987 231 : || !user_provided_p (CLASSTYPE_DESTRUCTOR (t))))
4988 : return true;
4989 584 : if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
4990 : return false;
4991 535 : if (TYPE_HAS_COMPLEX_DFLT (t)
4992 172 : && TYPE_HAS_COMPLEX_COPY_CTOR (t)
4993 598 : && TYPE_HAS_COMPLEX_MOVE_CTOR (t))
4994 : return false;
4995 509 : if (CLASSTYPE_LAZY_DESTRUCTOR (t))
4996 126 : lazily_declare_fn (sfk_destructor, t);
4997 : /* It has at least one trivial eligible constructor and a trivial,
4998 : non-deleted destructor. */
4999 509 : tree fn = CLASSTYPE_DESTRUCTOR (t);
5000 509 : if (!fn || DECL_DELETED_FN (fn))
5001 : return false;
5002 613 : for (ovl_iterator iter (get_class_binding (t, complete_ctor_identifier));
5003 613 : iter; ++iter)
5004 : {
5005 595 : fn = *iter;
5006 1109 : if ((default_ctor_p (fn) || copy_fn_p (fn) || move_fn_p (fn))
5007 579 : && trivial_fn_p (fn)
5008 1089 : && eligible_special_member_function_p (fn))
5009 491 : return true;
5010 : }
5011 18 : return false;
5012 : }
5013 :
5014 : /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
5015 :
5016 : bool
5017 11650 : pod_type_p (const_tree t)
5018 : {
5019 : /* This CONST_CAST is okay because strip_array_types returns its
5020 : argument unmodified and we assign it to a const_tree. */
5021 11650 : t = strip_array_types (const_cast<tree>(t));
5022 :
5023 11650 : if (!CLASS_TYPE_P (t))
5024 736 : return scalarish_type_p (t);
5025 10914 : else if (cxx_dialect > cxx98)
5026 : /* [class]/10: A POD struct is a class that is both a trivial class and a
5027 : standard-layout class, and has no non-static data members of type
5028 : non-POD struct, non-POD union (or array of such types).
5029 :
5030 : We don't need to check individual members because if a member is
5031 : non-std-layout or non-trivial, the class will be too. */
5032 10717 : return (std_layout_type_p (t) && trivial_type_p (t));
5033 : else
5034 : /* The C++98 definition of POD is different. */
5035 197 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
5036 : }
5037 :
5038 : /* Returns true iff T is POD for the purpose of layout, as defined in the
5039 : C++ ABI. */
5040 :
5041 : bool
5042 18406626 : layout_pod_type_p (const_tree t)
5043 : {
5044 18406626 : t = strip_array_types (const_cast<tree> (t));
5045 :
5046 18406626 : if (CLASS_TYPE_P (t))
5047 3741826 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
5048 : else
5049 14664800 : return scalarish_type_p (t);
5050 : }
5051 :
5052 : /* Returns true iff T is a standard-layout type, as defined in
5053 : [basic.types]. */
5054 :
5055 : bool
5056 18480770 : std_layout_type_p (const_tree t)
5057 : {
5058 18480770 : t = strip_array_types (const_cast<tree> (t));
5059 :
5060 18480770 : if (CLASS_TYPE_P (t))
5061 3755505 : return !CLASSTYPE_NON_STD_LAYOUT (t);
5062 : else
5063 14725265 : return scalarish_type_p (t);
5064 : }
5065 :
5066 : static bool record_has_unique_obj_representations (const_tree, const_tree, bool);
5067 :
5068 : /* Returns true iff T satisfies std::has_unique_object_representations<T>,
5069 : as defined in [meta.unary.prop]. If EXPLAIN is true, explain why not. */
5070 :
5071 : bool
5072 61429 : type_has_unique_obj_representations (const_tree t, bool explain/*=false*/)
5073 : {
5074 70749 : bool ret;
5075 :
5076 70749 : t = strip_array_types (const_cast<tree> (t));
5077 :
5078 70749 : if (t == error_mark_node)
5079 : return false;
5080 :
5081 70746 : location_t loc = input_location;
5082 70746 : if (tree m = TYPE_MAIN_DECL (t))
5083 9560 : loc = DECL_SOURCE_LOCATION (m);
5084 :
5085 70746 : if (!trivially_copyable_p (t))
5086 : {
5087 30 : if (explain)
5088 6 : inform (loc, "%qT is not trivially copyable", t);
5089 : return false;
5090 : }
5091 :
5092 239 : if (CLASS_TYPE_P (t)
5093 236 : && CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t)
5094 70839 : && !explain)
5095 96 : return CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t);
5096 :
5097 70620 : switch (TREE_CODE (t))
5098 : {
5099 : case INTEGER_TYPE:
5100 : case POINTER_TYPE:
5101 : case REFERENCE_TYPE:
5102 : /* If some backend has any paddings in these types, we should add
5103 : a target hook for this and handle it there. */
5104 : return true;
5105 :
5106 : case BOOLEAN_TYPE:
5107 : /* For bool values other than 0 and 1 should only appear with
5108 : undefined behavior. */
5109 : return true;
5110 :
5111 9302 : case ENUMERAL_TYPE:
5112 9302 : return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t),
5113 9302 : explain);
5114 :
5115 32973 : case REAL_TYPE:
5116 : /* XFmode certainly contains padding on x86, which the CPU doesn't store
5117 : when storing long double values, so for that we have to return false.
5118 : Other kinds of floating point values are questionable due to +.0/-.0
5119 : and NaNs, let's play safe for now. */
5120 32973 : if (explain)
5121 0 : inform (loc, "%qT is a floating-point type", t);
5122 : return false;
5123 :
5124 0 : case FIXED_POINT_TYPE:
5125 0 : if (explain)
5126 0 : inform (loc, "%qT is a fixed-point type", t);
5127 : return false;
5128 :
5129 : case OFFSET_TYPE:
5130 : return true;
5131 :
5132 18 : case COMPLEX_TYPE:
5133 18 : case VECTOR_TYPE:
5134 18 : return type_has_unique_obj_representations (TREE_TYPE (t), explain);
5135 :
5136 122 : case RECORD_TYPE:
5137 122 : ret = record_has_unique_obj_representations (t, TYPE_SIZE (t), explain);
5138 122 : if (CLASS_TYPE_P (t))
5139 : {
5140 119 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
5141 119 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
5142 : }
5143 : return ret;
5144 :
5145 21 : case UNION_TYPE:
5146 21 : ret = true;
5147 21 : bool any_fields;
5148 21 : any_fields = false;
5149 42 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5150 33 : if (TREE_CODE (field) == FIELD_DECL)
5151 : {
5152 24 : any_fields = true;
5153 24 : if (simple_cst_equal (DECL_SIZE (field), TYPE_SIZE (t)) != 1)
5154 : {
5155 12 : if (explain)
5156 3 : inform (DECL_SOURCE_LOCATION (field),
5157 : "%qD does not fill all bits of %q#T", field, t);
5158 : ret = false;
5159 : break;
5160 : }
5161 12 : if (!type_has_unique_obj_representations (TREE_TYPE (field)))
5162 : {
5163 0 : if (explain)
5164 0 : inform (DECL_SOURCE_LOCATION (field),
5165 : "%qD has type %qT that does not have "
5166 : "unique object representations",
5167 0 : field, TREE_TYPE (field));
5168 : ret = false;
5169 : break;
5170 : }
5171 : }
5172 12 : if (!any_fields && !integer_zerop (TYPE_SIZE (t)))
5173 : {
5174 6 : if (explain)
5175 3 : inform (loc, "%q#T has no data fields", t);
5176 : ret = false;
5177 : }
5178 21 : if (CLASS_TYPE_P (t))
5179 : {
5180 21 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
5181 21 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
5182 : }
5183 : return ret;
5184 :
5185 3 : case NULLPTR_TYPE:
5186 3 : if (explain)
5187 0 : inform (loc, "%<std::nullptr_t%> has padding bits and no value bits");
5188 : return false;
5189 :
5190 8 : case OPAQUE_TYPE:
5191 8 : if (REFLECTION_TYPE_P (t))
5192 : {
5193 8 : if (explain)
5194 0 : inform (loc, "%<std::meta::info%> has an unspecified object "
5195 : "representation");
5196 : return false;
5197 : }
5198 0 : gcc_fallthrough ();
5199 :
5200 0 : default:
5201 0 : gcc_unreachable ();
5202 : }
5203 : }
5204 :
5205 : /* Helper function for type_has_unique_obj_representations. */
5206 :
5207 : static bool
5208 133 : record_has_unique_obj_representations (const_tree t, const_tree sz,
5209 : bool explain)
5210 : {
5211 668 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5212 567 : if (TREE_CODE (field) != FIELD_DECL)
5213 : ;
5214 : /* For bases, can't use type_has_unique_obj_representations here, as in
5215 : struct S { int i : 24; S (); };
5216 : struct T : public S { int j : 8; T (); };
5217 : S doesn't have unique obj representations, but T does. */
5218 182 : else if (DECL_FIELD_IS_BASE (field))
5219 : {
5220 11 : if (!record_has_unique_obj_representations (TREE_TYPE (field),
5221 11 : DECL_SIZE (field),
5222 : /*explain=*/false))
5223 : {
5224 6 : if (explain)
5225 3 : inform (DECL_SOURCE_LOCATION (field),
5226 : "base %qT does not have unique object representations",
5227 3 : TREE_TYPE (field));
5228 : return false;
5229 : }
5230 : }
5231 171 : else if (DECL_C_BIT_FIELD (field) && !DECL_UNNAMED_BIT_FIELD (field))
5232 : {
5233 59 : tree btype = DECL_BIT_FIELD_TYPE (field);
5234 59 : if (!type_has_unique_obj_representations (btype))
5235 : {
5236 0 : if (explain)
5237 0 : inform (DECL_SOURCE_LOCATION (field),
5238 : "%qD with type %qT does not have "
5239 : "unique object representations",
5240 : field, btype);
5241 : return false;
5242 : }
5243 : }
5244 112 : else if (!type_has_unique_obj_representations (TREE_TYPE (field)))
5245 : {
5246 26 : if (explain)
5247 6 : inform (DECL_SOURCE_LOCATION (field),
5248 : "%qD with type %qT does not have "
5249 : "unique object representations",
5250 6 : field, TREE_TYPE (field));
5251 : return false;
5252 : }
5253 :
5254 101 : offset_int cur = 0;
5255 101 : tree last_field = NULL_TREE;
5256 101 : tree last_named_field = NULL_TREE;
5257 565 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5258 496 : if (TREE_CODE (field) == FIELD_DECL)
5259 : {
5260 144 : if (DECL_UNNAMED_BIT_FIELD (field))
5261 : {
5262 16 : last_field = field;
5263 16 : continue;
5264 : }
5265 128 : offset_int fld = wi::to_offset (DECL_FIELD_OFFSET (field));
5266 128 : offset_int bitpos = wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
5267 128 : fld = fld * BITS_PER_UNIT + bitpos;
5268 128 : if (cur != fld)
5269 : {
5270 32 : if (explain)
5271 : {
5272 6 : if (last_named_field)
5273 3 : inform (DECL_SOURCE_LOCATION (last_named_field),
5274 : "padding occurs between %qD and %qD",
5275 : last_named_field, field);
5276 3 : else if (last_field)
5277 3 : inform (DECL_SOURCE_LOCATION (last_field),
5278 : "unnamed bit-field inserts padding before %qD",
5279 : field);
5280 : else
5281 0 : inform (DECL_SOURCE_LOCATION (field),
5282 : "padding occurs before %qD", field);
5283 : }
5284 32 : return false;
5285 : }
5286 96 : if (DECL_SIZE (field))
5287 : {
5288 93 : offset_int size = wi::to_offset (DECL_SIZE (field));
5289 93 : cur += size;
5290 : }
5291 96 : last_named_field = last_field = field;
5292 : }
5293 69 : if (cur != wi::to_offset (sz))
5294 : {
5295 33 : if (explain)
5296 : {
5297 6 : if (last_named_field)
5298 3 : inform (DECL_SOURCE_LOCATION (last_named_field),
5299 : "padding occurs after %qD", last_named_field);
5300 : else
5301 3 : inform (location_of (const_cast <tree> (t)),
5302 : "%qT has padding and no data fields", t);
5303 : }
5304 : return false;
5305 : }
5306 :
5307 : return true;
5308 : }
5309 :
5310 : /* Nonzero iff type T is a class template implicit specialization. */
5311 :
5312 : bool
5313 138042660 : class_tmpl_impl_spec_p (const_tree t)
5314 : {
5315 138042660 : return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
5316 : }
5317 :
5318 : /* Returns 1 iff zero initialization of type T means actually storing
5319 : zeros in it. */
5320 :
5321 : int
5322 20676102 : zero_init_p (const_tree t)
5323 : {
5324 : /* This CONST_CAST is okay because strip_array_types returns its
5325 : argument unmodified and we assign it to a const_tree. */
5326 20676102 : t = strip_array_types (const_cast<tree> (t));
5327 :
5328 20676102 : if (t == error_mark_node)
5329 : return 1;
5330 :
5331 : /* NULL pointers to data members are initialized with -1. */
5332 20676102 : if (TYPE_PTRDATAMEM_P (t))
5333 : return 0;
5334 :
5335 : /* Classes that contain types that can't be zero-initialized, cannot
5336 : be zero-initialized themselves. */
5337 20675493 : if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
5338 143 : return 0;
5339 :
5340 : return 1;
5341 : }
5342 :
5343 : /* Returns true if the expression or initializer T is the result of
5344 : zero-initialization for its type, taking pointers to members
5345 : into consideration. */
5346 :
5347 : bool
5348 686810 : zero_init_expr_p (tree t)
5349 : {
5350 686810 : tree type = TREE_TYPE (t);
5351 686810 : if (!type || uses_template_parms (type))
5352 : return false;
5353 686810 : if (TYPE_PTRMEM_P (type))
5354 1224 : return null_member_pointer_value_p (t);
5355 685586 : if (REFLECTION_TYPE_P (type))
5356 404 : return null_reflection_p (t);
5357 685182 : if (TREE_CODE (t) == CONSTRUCTOR)
5358 : {
5359 283099 : if (COMPOUND_LITERAL_P (t)
5360 283099 : || BRACE_ENCLOSED_INITIALIZER_P (t))
5361 : /* Undigested, conversions might change the zeroness. */
5362 : return false;
5363 851931 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (t))
5364 : {
5365 289897 : if (TREE_CODE (type) == UNION_TYPE
5366 289897 : && elt.index != first_field (type))
5367 : return false;
5368 289886 : if (!zero_init_expr_p (elt.value))
5369 : return false;
5370 : }
5371 : return true;
5372 : }
5373 402083 : if (zero_init_p (type))
5374 402083 : return initializer_zerop (t);
5375 : return false;
5376 : }
5377 :
5378 : /* True IFF T is a C++20 structural type (P1907R1) that can be used as a
5379 : non-type template parameter. If EXPLAIN, explain why not. */
5380 :
5381 : bool
5382 212766 : structural_type_p (tree t, bool explain)
5383 : {
5384 : /* A structural type is one of the following: */
5385 :
5386 : /* a scalar type, or */
5387 212766 : if (SCALAR_TYPE_P (t))
5388 : return true;
5389 : /* an lvalue reference type, or */
5390 106645 : if (TYPE_REF_P (t) && !TYPE_REF_IS_RVALUE (t))
5391 : return true;
5392 : /* a literal class type with the following properties:
5393 : - all base classes and non-static data members are public and non-mutable
5394 : and
5395 : - the types of all bases classes and non-static data members are
5396 : structural types or (possibly multi-dimensional) array thereof. */
5397 106629 : if (!CLASS_TYPE_P (t))
5398 : return false;
5399 106589 : if (!literal_type_p (t))
5400 : {
5401 73 : if (explain)
5402 10 : explain_non_literal_class (t);
5403 : return false;
5404 : }
5405 106516 : int structural_type_attr = -1;
5406 234858 : for (tree m = next_aggregate_field (TYPE_FIELDS (t)); m;
5407 128342 : m = next_aggregate_field (DECL_CHAIN (m)))
5408 : {
5409 128731 : if (TREE_PRIVATE (m) || TREE_PROTECTED (m))
5410 : {
5411 351 : if (structural_type_attr == -1)
5412 333 : structural_type_attr = !!lookup_attribute ("structural_type",
5413 333 : TYPE_ATTRIBUTES (t));
5414 351 : if (!structural_type_attr)
5415 : {
5416 277 : if (explain)
5417 : {
5418 97 : if (DECL_FIELD_IS_BASE (m))
5419 3 : inform (location_of (m), "base class %qT is not public",
5420 3 : TREE_TYPE (m));
5421 : else
5422 94 : inform (location_of (m), "%qD is not public", m);
5423 : }
5424 : return false;
5425 : }
5426 : }
5427 128454 : if (DECL_MUTABLE_P (m))
5428 : {
5429 58 : if (explain)
5430 8 : inform (location_of (m), "%qD is mutable", m);
5431 : return false;
5432 : }
5433 128396 : tree mtype = strip_array_types (TREE_TYPE (m));
5434 128396 : if (!structural_type_p (mtype))
5435 : {
5436 54 : if (explain)
5437 : {
5438 2 : inform (location_of (m), "%qD has a non-structural type", m);
5439 2 : structural_type_p (mtype, true);
5440 : }
5441 : return false;
5442 : }
5443 : }
5444 : return true;
5445 : }
5446 :
5447 : /* Handle the [[gnu::structural_type]] attribute. */
5448 :
5449 : static tree
5450 36693 : handle_structural_type_attribute (tree *node, tree name, tree, int,
5451 : bool *no_add_attrs)
5452 : {
5453 36693 : if (!CLASS_TYPE_P (*node))
5454 : {
5455 24 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5456 : "class types", name);
5457 24 : *no_add_attrs = true;
5458 : }
5459 36693 : return NULL_TREE;
5460 : }
5461 :
5462 : /* Partially handle the C++11 [[carries_dependency]] attribute.
5463 : Just emit a different diagnostics when it is used on something the
5464 : spec doesn't allow vs. where it allows and we just choose to ignore
5465 : it. */
5466 :
5467 : static tree
5468 142 : handle_carries_dependency_attribute (tree *node, tree name,
5469 : tree ARG_UNUSED (args),
5470 : int ARG_UNUSED (flags),
5471 : bool *no_add_attrs)
5472 : {
5473 142 : if (TREE_CODE (*node) != FUNCTION_DECL
5474 121 : && TREE_CODE (*node) != PARM_DECL)
5475 : {
5476 76 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5477 : "functions or parameters", name);
5478 76 : *no_add_attrs = true;
5479 : }
5480 : else
5481 : {
5482 66 : warning (OPT_Wattributes, "%qE attribute ignored", name);
5483 66 : *no_add_attrs = true;
5484 : }
5485 142 : return NULL_TREE;
5486 : }
5487 :
5488 : /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
5489 : warn_unused_result attribute. */
5490 :
5491 : static tree
5492 13564857 : handle_nodiscard_attribute (tree *node, tree name, tree args,
5493 : int /*flags*/, bool *no_add_attrs)
5494 : {
5495 13565025 : if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
5496 : {
5497 6 : error ("%qE attribute argument must be a string constant", name);
5498 6 : *no_add_attrs = true;
5499 : }
5500 13564857 : if (TREE_CODE (*node) == FUNCTION_DECL)
5501 : {
5502 13563701 : if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))
5503 13666501 : && !DECL_CONSTRUCTOR_P (*node))
5504 9 : warning_at (DECL_SOURCE_LOCATION (*node),
5505 9 : OPT_Wattributes, "%qE attribute applied to %qD with void "
5506 : "return type", name, *node);
5507 : }
5508 1156 : else if (OVERLOAD_TYPE_P (*node))
5509 : /* OK */;
5510 : else
5511 : {
5512 148 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5513 : "functions or to class or enumeration types", name);
5514 148 : *no_add_attrs = true;
5515 : }
5516 13564857 : return NULL_TREE;
5517 : }
5518 :
5519 : /* Handle a C++20 "no_unique_address" attribute; arguments as in
5520 : struct attribute_spec.handler. */
5521 : static tree
5522 735182 : handle_no_unique_addr_attribute (tree* node,
5523 : tree name,
5524 : tree /*args*/,
5525 : int /*flags*/,
5526 : bool* no_add_attrs)
5527 : {
5528 735182 : if (TREE_CODE (*node) == VAR_DECL)
5529 : {
5530 48 : DECL_MERGEABLE (*node) = true;
5531 48 : if (pedantic)
5532 42 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5533 : "non-static data members", name);
5534 : }
5535 735134 : else if (TREE_CODE (*node) != FIELD_DECL)
5536 : {
5537 82 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5538 : "non-static data members", name);
5539 82 : *no_add_attrs = true;
5540 : }
5541 735052 : else if (DECL_C_BIT_FIELD (*node))
5542 : {
5543 6 : warning (OPT_Wattributes, "%qE attribute cannot be applied to "
5544 : "a bit-field", name);
5545 6 : *no_add_attrs = true;
5546 : }
5547 :
5548 735182 : return NULL_TREE;
5549 : }
5550 :
5551 : /* The C++20 [[likely]] and [[unlikely]] attributes on labels map to the GNU
5552 : hot/cold attributes. */
5553 :
5554 : static tree
5555 392 : handle_likeliness_attribute (tree *node, tree name, tree args,
5556 : int flags, bool *no_add_attrs)
5557 : {
5558 392 : *no_add_attrs = true;
5559 392 : if (TREE_CODE (*node) == LABEL_DECL
5560 392 : || TREE_CODE (*node) == FUNCTION_DECL)
5561 : {
5562 90 : if (args)
5563 0 : warning (OPT_Wattributes, "%qE attribute takes no arguments", name);
5564 90 : tree bname = (is_attribute_p ("likely", name)
5565 90 : ? get_identifier ("hot") : get_identifier ("cold"));
5566 90 : if (TREE_CODE (*node) == FUNCTION_DECL)
5567 33 : warning (OPT_Wattributes, "ISO C++ %qE attribute does not apply to "
5568 : "functions; treating as %<[[gnu::%E]]%>", name, bname);
5569 90 : tree battr = build_tree_list (bname, NULL_TREE);
5570 90 : decl_attributes (node, battr, flags);
5571 90 : return NULL_TREE;
5572 : }
5573 : else
5574 302 : return error_mark_node;
5575 : }
5576 :
5577 : /* The C++11 alignment specifier. It mostly maps to GNU aligned attribute,
5578 : but we need to do some extra pedantic checking. */
5579 :
5580 : static tree
5581 314532 : handle_alignas_attribute (tree *node, tree name, tree args, int flags,
5582 : bool *no_add_attrs)
5583 : {
5584 314532 : tree t = *node;
5585 314532 : tree ret = handle_aligned_attribute (node, name, args, flags, no_add_attrs);
5586 314532 : if (pedantic)
5587 : {
5588 1312 : if (TREE_CODE (*node) == FUNCTION_DECL)
5589 15 : pedwarn (input_location, OPT_Wattributes,
5590 : "%<alignas%> on function declaration");
5591 1297 : else if (TREE_CODE (*node) == ENUMERAL_TYPE)
5592 9 : pedwarn (input_location, OPT_Wattributes,
5593 : "%<alignas%> on enumerated type");
5594 1288 : else if (TYPE_P (*node) && t != *node)
5595 56 : pedwarn (input_location, OPT_Wattributes,
5596 : "%<alignas%> on a type other than class");
5597 1232 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_C_BIT_FIELD (*node))
5598 9 : pedwarn (input_location, OPT_Wattributes, "%<alignas%> on bit-field");
5599 1223 : else if (TREE_CODE (t) == TYPE_DECL)
5600 9 : pedwarn (input_location, OPT_Wattributes,
5601 : "%<alignas%> on a type alias");
5602 : }
5603 314532 : return ret;
5604 : }
5605 :
5606 : /* The C++14 [[deprecated]] attribute mostly maps to the GNU deprecated
5607 : attribute. */
5608 :
5609 : static tree
5610 312746 : handle_std_deprecated_attribute (tree *node, tree name, tree args, int flags,
5611 : bool *no_add_attrs)
5612 : {
5613 312746 : tree t = *node;
5614 312746 : tree ret = handle_deprecated_attribute (node, name, args, flags,
5615 : no_add_attrs);
5616 312746 : if (TYPE_P (*node) && t != *node)
5617 48 : pedwarn (input_location, OPT_Wattributes,
5618 : "%qE on a type other than class or enumeration definition", name);
5619 312698 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5620 4 : pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
5621 : name);
5622 312746 : return ret;
5623 : }
5624 :
5625 : /* The C++17 [[maybe_unused]] attribute mostly maps to the GNU unused
5626 : attribute. */
5627 :
5628 : static tree
5629 102517 : handle_maybe_unused_attribute (tree *node, tree name, tree args, int flags,
5630 : bool *no_add_attrs)
5631 : {
5632 102517 : tree t = *node;
5633 102517 : tree ret = handle_unused_attribute (node, name, args, flags, no_add_attrs);
5634 102517 : if (TYPE_P (*node) && t != *node)
5635 36 : pedwarn (input_location, OPT_Wattributes,
5636 : "%qE on a type other than class or enumeration definition", name);
5637 102481 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5638 3 : pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
5639 : name);
5640 102478 : else if (TREE_CODE (*node) == LABEL_DECL && DECL_NAME (*node) == NULL_TREE)
5641 6 : pedwarn (input_location, OPT_Wattributes,
5642 : "%qE on %<case%> or %<default%> label", name);
5643 102517 : return ret;
5644 : }
5645 :
5646 : /* The C++26 [[indeterminate]] attribute. */
5647 :
5648 : static tree
5649 231 : handle_indeterminate_attribute (tree *node, tree name, tree, int,
5650 : bool *no_add_attrs)
5651 : {
5652 231 : if (TREE_CODE (*node) != PARM_DECL
5653 231 : && (!VAR_P (*node) || is_global_var (*node)))
5654 : {
5655 67 : pedwarn (input_location, OPT_Wattributes,
5656 : "%qE on declaration other than parameter or automatic variable",
5657 : name);
5658 67 : *no_add_attrs = true;
5659 : }
5660 231 : return NULL_TREE;
5661 : }
5662 :
5663 : /* Table of valid C++ attributes. */
5664 : // clang-format off
5665 : static const attribute_spec cxx_gnu_attributes[] =
5666 : {
5667 : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5668 : affects_type_identity, handler, exclude } */
5669 : { "init_priority", 1, 1, true, false, false, false,
5670 : handle_init_priority_attribute, NULL },
5671 : { "abi_tag", 1, -1, false, false, false, true,
5672 : handle_abi_tag_attribute, NULL },
5673 : { "no_dangling", 0, 1, false, true, false, false,
5674 : handle_no_dangling_attribute, NULL },
5675 : { "no_specializations", 0, 1, false, false, false, false,
5676 : handle_gnu_no_specializations_attribute, NULL },
5677 : { "trivial_abi", 0, 0, false, true, false, true,
5678 : handle_gnu_trivial_abi_attribute, NULL },
5679 : { "structural_type", 0, 0, false, true, false, false,
5680 : handle_structural_type_attribute, NULL }
5681 : };
5682 : // clang-format on
5683 :
5684 : const scoped_attribute_specs cxx_gnu_attribute_table =
5685 : {
5686 : "gnu", { cxx_gnu_attributes }
5687 : };
5688 :
5689 : /* Table of C++ standard attributes. */
5690 : static const attribute_spec std_attributes[] =
5691 : {
5692 : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5693 : affects_type_identity, handler, exclude } */
5694 : { "deprecated", 0, 1, false, false, false, false,
5695 : handle_std_deprecated_attribute, NULL },
5696 : { "maybe_unused", 0, 0, false, false, false, false,
5697 : handle_maybe_unused_attribute, NULL },
5698 : { "nodiscard", 0, 1, false, false, false, false,
5699 : handle_nodiscard_attribute, NULL },
5700 : { "no_unique_address", 0, 0, true, false, false, false,
5701 : handle_no_unique_addr_attribute, NULL },
5702 : { "likely", 0, 0, false, false, false, false,
5703 : handle_likeliness_attribute, attr_cold_hot_exclusions },
5704 : { "unlikely", 0, 0, false, false, false, false,
5705 : handle_likeliness_attribute, attr_cold_hot_exclusions },
5706 : { "noreturn", 0, 0, true, false, false, false,
5707 : handle_noreturn_attribute, attr_noreturn_exclusions },
5708 : { "carries_dependency", 0, 0, true, false, false, false,
5709 : handle_carries_dependency_attribute, NULL },
5710 : { "indeterminate", 0, 0, true, false, false, false,
5711 : handle_indeterminate_attribute, NULL },
5712 : };
5713 :
5714 : const scoped_attribute_specs std_attribute_table =
5715 : {
5716 : nullptr, { std_attributes }
5717 : };
5718 :
5719 : /* Table of internal attributes. */
5720 : static const attribute_spec internal_attributes[] =
5721 : {
5722 : { "aligned", 0, 1, false, false, false, false,
5723 : handle_alignas_attribute, attr_aligned_exclusions },
5724 : { "annotation ", 1, 1, false, false, false, false,
5725 : handle_annotation_attribute, NULL }
5726 : };
5727 :
5728 : const scoped_attribute_specs internal_attribute_table =
5729 : {
5730 : "internal ", { internal_attributes }
5731 : };
5732 :
5733 : /* Table of C++ attributes also recognized in the clang:: namespace. */
5734 : // clang-format off
5735 : static const attribute_spec cxx_clang_attributes[] =
5736 : {
5737 : { "no_specializations", 0, 1, false, false, false, false,
5738 : handle_no_specializations_attribute, NULL },
5739 : { "trivial_abi", 0, 0, false, true, false, true,
5740 : handle_trivial_abi_attribute, NULL },
5741 : };
5742 :
5743 : const scoped_attribute_specs cxx_clang_attribute_table =
5744 : {
5745 : "clang", { cxx_clang_attributes }
5746 : };
5747 : // clang-format on
5748 :
5749 : /* Handle an "init_priority" attribute; arguments as in
5750 : struct attribute_spec.handler. */
5751 : static tree
5752 35 : handle_init_priority_attribute (tree* node,
5753 : tree name,
5754 : tree args,
5755 : int /*flags*/,
5756 : bool* no_add_attrs)
5757 : {
5758 35 : if (!SUPPORTS_INIT_PRIORITY)
5759 : /* Treat init_priority as an unrecognized attribute (mirroring
5760 : __has_attribute) if the target doesn't support init priorities. */
5761 : return error_mark_node;
5762 :
5763 35 : tree initp_expr = TREE_VALUE (args);
5764 35 : tree decl = *node;
5765 35 : tree type = TREE_TYPE (decl);
5766 35 : int pri;
5767 :
5768 35 : STRIP_NOPS (initp_expr);
5769 35 : initp_expr = default_conversion (initp_expr);
5770 35 : if (initp_expr)
5771 35 : initp_expr = maybe_constant_value (initp_expr);
5772 :
5773 35 : if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
5774 : {
5775 0 : error ("requested %<init_priority%> is not an integer constant");
5776 0 : cxx_constant_value (initp_expr);
5777 0 : *no_add_attrs = true;
5778 0 : return NULL_TREE;
5779 : }
5780 :
5781 35 : pri = TREE_INT_CST_LOW (initp_expr);
5782 :
5783 35 : type = strip_array_types (type);
5784 :
5785 35 : if (decl == NULL_TREE
5786 35 : || !VAR_P (decl)
5787 35 : || !TREE_STATIC (decl)
5788 35 : || DECL_EXTERNAL (decl)
5789 35 : || (TREE_CODE (type) != RECORD_TYPE
5790 35 : && TREE_CODE (type) != UNION_TYPE)
5791 : /* Static objects in functions are initialized the
5792 : first time control passes through that
5793 : function. This is not precise enough to pin down an
5794 : init_priority value, so don't allow it. */
5795 70 : || current_function_decl)
5796 : {
5797 0 : error ("can only use %qE attribute on file-scope definitions "
5798 : "of objects of class type", name);
5799 0 : *no_add_attrs = true;
5800 0 : return NULL_TREE;
5801 : }
5802 :
5803 35 : if (pri > MAX_INIT_PRIORITY || pri <= 0)
5804 : {
5805 0 : error ("requested %<init_priority%> %i is out of range [0, %i]",
5806 : pri, MAX_INIT_PRIORITY);
5807 0 : *no_add_attrs = true;
5808 0 : return NULL_TREE;
5809 : }
5810 :
5811 : /* Check for init_priorities that are reserved for
5812 : language and runtime support implementations.*/
5813 35 : if (pri <= MAX_RESERVED_INIT_PRIORITY
5814 35 : && !in_system_header_at (input_location))
5815 : {
5816 10 : warning
5817 10 : (OPT_Wprio_ctor_dtor,
5818 : "requested %<init_priority%> %i is reserved for internal use",
5819 : pri);
5820 : }
5821 :
5822 35 : SET_DECL_INIT_PRIORITY (decl, pri);
5823 35 : DECL_HAS_INIT_PRIORITY_P (decl) = 1;
5824 35 : return NULL_TREE;
5825 : }
5826 :
5827 : /* DECL is being redeclared; the old declaration had the abi tags in OLD,
5828 : and the new one has the tags in NEW_. Give an error if there are tags
5829 : in NEW_ that weren't in OLD. */
5830 :
5831 : bool
5832 11637814 : check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_)
5833 : {
5834 11706697 : if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST)
5835 : old = TREE_VALUE (old);
5836 11659782 : if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST)
5837 : new_ = TREE_VALUE (new_);
5838 11637814 : bool err = false;
5839 11637814 : auto_diagnostic_group d;
5840 23297596 : for (const_tree t = new_; t; t = TREE_CHAIN (t))
5841 : {
5842 21968 : tree str = TREE_VALUE (t);
5843 21968 : for (const_tree in = old; in; in = TREE_CHAIN (in))
5844 : {
5845 21959 : tree ostr = TREE_VALUE (in);
5846 21959 : if (cp_tree_equal (str, ostr))
5847 21959 : goto found;
5848 : }
5849 9 : error ("redeclaration of %qD adds abi tag %qE", decl, str);
5850 9 : err = true;
5851 21968 : found:;
5852 : }
5853 11637814 : if (err)
5854 : {
5855 9 : inform (DECL_SOURCE_LOCATION (decl), "previous declaration here");
5856 9 : return false;
5857 : }
5858 : return true;
5859 11637814 : }
5860 :
5861 : /* The abi_tag attribute with the name NAME was given ARGS. If they are
5862 : ill-formed, give an error and return false; otherwise, return true. */
5863 :
5864 : bool
5865 455308 : check_abi_tag_args (tree args, tree name)
5866 : {
5867 455308 : if (!args)
5868 : {
5869 0 : error ("the %qE attribute requires arguments", name);
5870 0 : return false;
5871 : }
5872 910655 : for (tree arg = args; arg; arg = TREE_CHAIN (arg))
5873 : {
5874 455359 : tree elt = TREE_VALUE (arg);
5875 455359 : if (TREE_CODE (elt) != STRING_CST
5876 910712 : || (!same_type_ignoring_top_level_qualifiers_p
5877 455353 : (strip_array_types (TREE_TYPE (elt)),
5878 : char_type_node)))
5879 : {
5880 9 : error ("arguments to the %qE attribute must be narrow string "
5881 : "literals", name);
5882 9 : return false;
5883 : }
5884 455350 : const char *begin = TREE_STRING_POINTER (elt);
5885 455350 : const char *end = begin + TREE_STRING_LENGTH (elt);
5886 3224608 : for (const char *p = begin; p != end; ++p)
5887 : {
5888 2769261 : char c = *p;
5889 2769261 : if (p == begin)
5890 : {
5891 455350 : if (!ISALPHA (c) && c != '_')
5892 : {
5893 3 : auto_diagnostic_group d;
5894 3 : error ("arguments to the %qE attribute must contain valid "
5895 : "identifiers", name);
5896 3 : inform (input_location, "%<%c%> is not a valid first "
5897 : "character for an identifier", c);
5898 3 : return false;
5899 3 : }
5900 : }
5901 2313911 : else if (p == end - 1)
5902 455347 : gcc_assert (c == 0);
5903 : else
5904 : {
5905 1858564 : if (!ISALNUM (c) && c != '_')
5906 : {
5907 0 : auto_diagnostic_group d;
5908 0 : error ("arguments to the %qE attribute must contain valid "
5909 : "identifiers", name);
5910 0 : inform (input_location, "%<%c%> is not a valid character "
5911 : "in an identifier", c);
5912 0 : return false;
5913 0 : }
5914 : }
5915 : }
5916 : }
5917 : return true;
5918 : }
5919 :
5920 : /* Handle an "abi_tag" attribute; arguments as in
5921 : struct attribute_spec.handler. */
5922 :
5923 : static tree
5924 406537 : handle_abi_tag_attribute (tree* node, tree name, tree args,
5925 : int flags, bool* no_add_attrs)
5926 : {
5927 406537 : if (!check_abi_tag_args (args, name))
5928 12 : goto fail;
5929 :
5930 406525 : if (TYPE_P (*node))
5931 : {
5932 11286 : if (!OVERLOAD_TYPE_P (*node))
5933 : {
5934 0 : error ("%qE attribute applied to non-class, non-enum type %qT",
5935 : name, *node);
5936 0 : goto fail;
5937 : }
5938 11286 : else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE))
5939 : {
5940 0 : error ("%qE attribute applied to %qT after its definition",
5941 : name, *node);
5942 0 : goto fail;
5943 : }
5944 11283 : else if (CLASS_TYPE_P (*node)
5945 22569 : && CLASSTYPE_TEMPLATE_INSTANTIATION (*node))
5946 : {
5947 3 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5948 : "template instantiation %qT", name, *node);
5949 3 : goto fail;
5950 : }
5951 11280 : else if (CLASS_TYPE_P (*node)
5952 22563 : && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node))
5953 : {
5954 3 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5955 : "template specialization %qT", name, *node);
5956 3 : goto fail;
5957 : }
5958 :
5959 11280 : tree attributes = TYPE_ATTRIBUTES (*node);
5960 11280 : tree decl = TYPE_NAME (*node);
5961 :
5962 : /* Make sure all declarations have the same abi tags. */
5963 11280 : if (DECL_SOURCE_LOCATION (decl) != input_location)
5964 : {
5965 6 : if (!check_abi_tag_redeclaration (decl,
5966 6 : lookup_attribute ("abi_tag",
5967 : attributes),
5968 : args))
5969 6 : goto fail;
5970 : }
5971 : }
5972 : else
5973 : {
5974 395239 : if (!VAR_OR_FUNCTION_DECL_P (*node))
5975 : {
5976 0 : error ("%qE attribute applied to non-function, non-variable %qD",
5977 : name, *node);
5978 0 : goto fail;
5979 : }
5980 395239 : else if (DECL_LANGUAGE (*node) == lang_c)
5981 : {
5982 0 : error ("%qE attribute applied to extern \"C\" declaration %qD",
5983 : name, *node);
5984 0 : goto fail;
5985 : }
5986 : }
5987 :
5988 : return NULL_TREE;
5989 :
5990 24 : fail:
5991 24 : *no_add_attrs = true;
5992 24 : return NULL_TREE;
5993 : }
5994 :
5995 : /* Handle a "no_dangling" attribute; arguments as in
5996 : struct attribute_spec.handler. */
5997 :
5998 : tree
5999 96 : handle_no_dangling_attribute (tree *node, tree name, tree args, int,
6000 : bool *no_add_attrs)
6001 : {
6002 147 : if (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
6003 : {
6004 3 : error ("%qE attribute argument must be an expression that evaluates "
6005 : "to true or false", name);
6006 3 : *no_add_attrs = true;
6007 : }
6008 93 : else if (!FUNC_OR_METHOD_TYPE_P (*node)
6009 51 : && !RECORD_OR_UNION_TYPE_P (*node))
6010 : {
6011 18 : warning (OPT_Wattributes, "%qE attribute ignored", name);
6012 18 : *no_add_attrs = true;
6013 : }
6014 :
6015 96 : return NULL_TREE;
6016 : }
6017 :
6018 : /* Perform checking for annotations. */
6019 :
6020 : tree
6021 846 : handle_annotation_attribute (tree *node, tree ARG_UNUSED (name),
6022 : tree args, int ARG_UNUSED (flags),
6023 : bool *no_add_attrs)
6024 : {
6025 846 : if (TYPE_P (*node)
6026 118 : && TREE_CODE (*node) != ENUMERAL_TYPE
6027 110 : && TREE_CODE (*node) != RECORD_TYPE
6028 24 : && TREE_CODE (*node) != UNION_TYPE)
6029 : {
6030 24 : error ("annotation on a type other than class or enumeration "
6031 : "definition");
6032 24 : *no_add_attrs = true;
6033 24 : return NULL_TREE;
6034 : }
6035 822 : if (TREE_CODE (*node) == LABEL_DECL)
6036 : {
6037 6 : error ("annotation applied to a label");
6038 6 : *no_add_attrs = true;
6039 6 : return NULL_TREE;
6040 : }
6041 816 : if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
6042 : {
6043 2 : error ("annotation on unnamed bit-field");
6044 2 : *no_add_attrs = true;
6045 2 : return NULL_TREE;
6046 : }
6047 814 : if (TREE_CODE (*node) == PARM_DECL && VOID_TYPE_P (TREE_TYPE (*node)))
6048 : {
6049 2 : error ("annotation on void parameter");
6050 2 : *no_add_attrs = true;
6051 2 : return NULL_TREE;
6052 : }
6053 :
6054 : /* Annotations are treated as late attributes so we shouldn't see
6055 : anything type-dependent now. */
6056 812 : gcc_assert (!type_dependent_expression_p (TREE_VALUE (args)));
6057 : /* FIXME We should be using convert_reflect_constant_arg here to
6058 : implement std::meta::reflect_constant(constant-expression)
6059 : properly, but that introduces new crashes. */
6060 812 : TREE_VALUE (args) = decay_conversion (TREE_VALUE (args), tf_warning_or_error);
6061 :
6062 812 : if (!structural_type_p (TREE_TYPE (TREE_VALUE (args))))
6063 : {
6064 102 : auto_diagnostic_group d;
6065 102 : error ("annotation does not have structural type");
6066 102 : structural_type_p (TREE_TYPE (TREE_VALUE (args)), true);
6067 102 : *no_add_attrs = true;
6068 102 : return NULL_TREE;
6069 102 : }
6070 710 : if (CLASS_TYPE_P (TREE_TYPE (TREE_VALUE (args))))
6071 : {
6072 62 : tree arg = make_tree_vec (1);
6073 62 : tree type = TREE_TYPE (TREE_VALUE (args));
6074 62 : TREE_VEC_ELT (arg, 0) = build_const_lref (type);
6075 62 : if (!is_xible (INIT_EXPR, type, arg))
6076 : {
6077 4 : auto_diagnostic_group d;
6078 4 : error ("annotation does not have copy constructible type");
6079 4 : is_xible (INIT_EXPR, type, arg, /*explain=*/true);
6080 4 : *no_add_attrs = true;
6081 4 : return NULL_TREE;
6082 4 : }
6083 : }
6084 706 : if (!processing_template_decl)
6085 : {
6086 698 : location_t loc = EXPR_LOCATION (TREE_VALUE (args));
6087 698 : TREE_VALUE (args) = cxx_constant_value (TREE_VALUE (args));
6088 698 : if (error_operand_p (TREE_VALUE (args)))
6089 4 : *no_add_attrs = true;
6090 698 : auto suppression
6091 698 : = make_temp_override (suppress_location_wrappers, 0);
6092 698 : TREE_VALUE (args) = maybe_wrap_with_location (TREE_VALUE (args), loc);
6093 698 : }
6094 706 : ATTR_UNIQUE_VALUE_P (args) = 1;
6095 706 : return NULL_TREE;
6096 : }
6097 :
6098 : /* Handle a "trivial_abi" attribute applied via [[gnu::trivial_abi]].
6099 : We reject that spelling; suggest [[clang::trivial_abi]] or
6100 : __attribute__((trivial_abi)) instead. */
6101 :
6102 : static tree
6103 84 : handle_gnu_trivial_abi_attribute (tree *node, tree name, tree args, int flags,
6104 : bool *no_add_attrs)
6105 : {
6106 84 : if (flags & ATTR_FLAG_CXX11)
6107 : {
6108 3 : warning (OPT_Wattributes,
6109 : "%<[[gnu::trivial_abi]]%> is not supported; use "
6110 : "%<[[clang::trivial_abi]]%> or "
6111 : "%<__attribute__((trivial_abi))%> instead");
6112 3 : *no_add_attrs = true;
6113 3 : return NULL_TREE;
6114 : }
6115 165 : return handle_trivial_abi_attribute (node, name, args, flags, no_add_attrs);
6116 : }
6117 :
6118 : /* Handle a "trivial_abi" attribute. */
6119 :
6120 : static tree
6121 160 : handle_trivial_abi_attribute (tree *node, tree name, tree, int,
6122 : bool *no_add_attrs)
6123 : {
6124 160 : tree type = *node;
6125 :
6126 : /* Only allow on class types (struct, class, union) */
6127 160 : if (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE)
6128 : {
6129 9 : warning (OPT_Wattributes, "%qE attribute only applies to classes", name);
6130 9 : *no_add_attrs = true;
6131 9 : return NULL_TREE;
6132 : }
6133 :
6134 : return NULL_TREE;
6135 : }
6136 :
6137 : /* Return true if TYPE has the trivial_abi attribute. */
6138 :
6139 : bool
6140 187844046 : has_trivial_abi_attribute (tree type)
6141 : {
6142 187844046 : if (type == NULL_TREE || !TYPE_P (type))
6143 : return false;
6144 187844005 : return lookup_attribute ("trivial_abi", TYPE_ATTRIBUTES (type));
6145 : }
6146 :
6147 : /* Handle a "no_specializations" attribute applied via
6148 : [[gnu::no_specializations]].
6149 : We reject that spelling; suggest [[clang::no_specializations]] or
6150 : __attribute__((no_specializations)) instead. */
6151 :
6152 : static tree
6153 122 : handle_gnu_no_specializations_attribute (tree *node, tree name, tree args,
6154 : int flags, bool *no_add_attrs)
6155 : {
6156 122 : if (flags & ATTR_FLAG_CXX11)
6157 : {
6158 8 : warning (OPT_Wattributes,
6159 : "%<[[gnu::no_specializations]]%> is not supported; use "
6160 : "%<[[clang::no_specializations]]%> or "
6161 : "%<__attribute__((no_specializations))%> instead");
6162 8 : *no_add_attrs = true;
6163 8 : return NULL_TREE;
6164 : }
6165 114 : return handle_no_specializations_attribute (node, name, args, flags,
6166 114 : no_add_attrs);
6167 : }
6168 :
6169 : /* Handle a "no_specializations" attribute. */
6170 :
6171 : static tree
6172 73264 : handle_no_specializations_attribute (tree *node, tree name, tree args, int,
6173 : bool *no_add_attrs)
6174 : {
6175 73417 : if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
6176 : {
6177 3 : error ("%qE attribute argument must be a string constant", name);
6178 3 : *no_add_attrs = true;
6179 3 : return NULL_TREE;
6180 : }
6181 : /* Only allow on class templates, variable templates
6182 : and function templates. */
6183 73261 : if (!CLASS_TYPE_P (*node) && !VAR_OR_FUNCTION_DECL_P (*node))
6184 : {
6185 343 : invalid:
6186 343 : warning (OPT_Wattributes, "%qE attribute only applies to class, "
6187 : "function or variable templates", name);
6188 343 : *no_add_attrs = true;
6189 343 : return NULL_TREE;
6190 : }
6191 73125 : tree ti = NULL_TREE;
6192 73125 : if (TYPE_P (*node))
6193 : {
6194 72932 : if (!TYPE_NAME (*node)
6195 72932 : || !DECL_IMPLICIT_TYPEDEF_P (TYPE_NAME (*node))
6196 218784 : || LAMBDA_TYPE_P (*node))
6197 0 : goto invalid;
6198 72932 : if (TYPE_LANG_SPECIFIC (*node))
6199 : {
6200 72932 : if (CLASSTYPE_TEMPLATE_SPECIALIZATION (*node)
6201 72932 : || CLASSTYPE_EXPLICIT_INSTANTIATION (*node))
6202 39 : goto invalid;
6203 72893 : ti = CLASSTYPE_TEMPLATE_INFO (*node);
6204 : }
6205 : }
6206 193 : else if (DECL_LANG_SPECIFIC (*node))
6207 : {
6208 157 : if (DECL_TEMPLATE_SPECIALIZATION (*node)
6209 157 : || DECL_EXPLICIT_INSTANTIATION (*node))
6210 36 : goto invalid;
6211 121 : ti = DECL_TEMPLATE_INFO (*node);
6212 : }
6213 73014 : if (ti)
6214 : {
6215 72889 : if (!PRIMARY_TEMPLATE_P (TI_TEMPLATE (ti)))
6216 24 : goto invalid;
6217 72865 : if (TYPE_P (*node) && DECL_ALIAS_TEMPLATE_P (TI_TEMPLATE (ti)))
6218 0 : goto invalid;
6219 : }
6220 161 : else if (!processing_template_decl || !template_parm_scope_p ())
6221 108 : goto invalid;
6222 :
6223 : return NULL_TREE;
6224 : }
6225 :
6226 : /* Validate the trivial_abi attribute on a completed class type.
6227 : Called from finish_struct after the class is complete. */
6228 :
6229 : void
6230 52457346 : validate_trivial_abi_attribute (tree type)
6231 : {
6232 52457346 : if (!has_trivial_abi_attribute (type))
6233 52457237 : return;
6234 :
6235 151 : gcc_assert (COMPLETE_TYPE_P (type));
6236 :
6237 193 : auto remove_trivial_abi_attribute = [type] {
6238 138 : for (tree variant = TYPE_MAIN_VARIANT (type); variant;
6239 96 : variant = TYPE_NEXT_VARIANT (variant))
6240 96 : TYPE_ATTRIBUTES (variant)
6241 192 : = remove_attribute ("trivial_abi", TYPE_ATTRIBUTES (variant));
6242 193 : };
6243 :
6244 : /* Check for virtual bases. */
6245 151 : if (CLASSTYPE_VBASECLASSES (type))
6246 : {
6247 6 : auto_diagnostic_group d;
6248 6 : if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
6249 : type))
6250 6 : inform (input_location, "has a virtual base");
6251 6 : remove_trivial_abi_attribute ();
6252 6 : return;
6253 6 : }
6254 :
6255 : /* Check for virtual member functions. */
6256 145 : if (TYPE_POLYMORPHIC_P (type))
6257 : {
6258 9 : auto_diagnostic_group d;
6259 9 : if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
6260 : type))
6261 9 : inform (input_location, "is polymorphic");
6262 9 : remove_trivial_abi_attribute ();
6263 9 : return;
6264 9 : }
6265 :
6266 : /* Check for non-trivial base classes. */
6267 136 : if (TYPE_BINFO (type))
6268 : {
6269 136 : unsigned int n_bases = BINFO_N_BASE_BINFOS (TYPE_BINFO (type));
6270 151 : for (unsigned int i = 0; i < n_bases; ++i)
6271 : {
6272 18 : tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
6273 18 : tree base_type = BINFO_TYPE (base_binfo);
6274 :
6275 18 : if (TREE_ADDRESSABLE (base_type))
6276 : {
6277 3 : auto_diagnostic_group d;
6278 3 : if (warning (OPT_Wattributes,
6279 : "%<trivial_abi%> cannot be applied to %qT", type))
6280 3 : inform (input_location, "has a non-trivial base class %qT",
6281 : base_type);
6282 3 : remove_trivial_abi_attribute ();
6283 3 : return;
6284 3 : }
6285 : }
6286 : }
6287 :
6288 : /* Check for non-trivial member types. */
6289 741 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6290 : {
6291 620 : if (TREE_CODE (field) == FIELD_DECL && !DECL_ARTIFICIAL (field))
6292 : {
6293 118 : tree field_type = strip_array_types (TREE_TYPE (field));
6294 :
6295 118 : if (CLASS_TYPE_P (field_type) && TREE_ADDRESSABLE (field_type))
6296 : {
6297 12 : auto_diagnostic_group d;
6298 12 : if (warning (OPT_Wattributes,
6299 : "%<trivial_abi%> cannot be applied to %qT", type))
6300 12 : inform (input_location, "has a non-static data member "
6301 : "of non-trivial type %qT", field_type);
6302 12 : remove_trivial_abi_attribute ();
6303 12 : return;
6304 12 : }
6305 : }
6306 : }
6307 :
6308 : /* Check that not all copy/move constructors are deleted. */
6309 121 : if (!classtype_has_non_deleted_copy_or_move_ctor (type))
6310 : {
6311 12 : auto_diagnostic_group d;
6312 12 : if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
6313 : type))
6314 12 : inform (input_location,
6315 : "copy constructors and move constructors are all deleted");
6316 12 : remove_trivial_abi_attribute ();
6317 12 : return;
6318 12 : }
6319 : }
6320 : /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
6321 : thing pointed to by the constant. */
6322 :
6323 : tree
6324 64181 : make_ptrmem_cst (tree type, tree member)
6325 : {
6326 64181 : tree ptrmem_cst = make_node (PTRMEM_CST);
6327 64181 : TREE_TYPE (ptrmem_cst) = type;
6328 64181 : PTRMEM_CST_MEMBER (ptrmem_cst) = member;
6329 64181 : PTRMEM_CST_LOCATION (ptrmem_cst) = input_location;
6330 64181 : return ptrmem_cst;
6331 : }
6332 :
6333 : /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
6334 : return an existing type if an appropriate type already exists. */
6335 :
6336 : tree
6337 16426351 : cp_build_type_attribute_variant (tree type, tree attributes)
6338 : {
6339 16426351 : tree new_type;
6340 :
6341 16426351 : new_type = build_type_attribute_variant (type, attributes);
6342 16426351 : if (FUNC_OR_METHOD_TYPE_P (new_type))
6343 16354258 : gcc_checking_assert (cxx_type_hash_eq (type, new_type));
6344 :
6345 : /* Making a new main variant of a class type is broken. */
6346 16426351 : gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
6347 :
6348 16426351 : return new_type;
6349 : }
6350 :
6351 : /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
6352 : Called only after doing all language independent checks. */
6353 :
6354 : bool
6355 342753285 : cxx_type_hash_eq (const_tree typea, const_tree typeb)
6356 : {
6357 342753285 : gcc_assert (FUNC_OR_METHOD_TYPE_P (typea));
6358 :
6359 342753285 : if (type_memfn_rqual (typea) != type_memfn_rqual (typeb))
6360 : return false;
6361 342745432 : if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb))
6362 : return false;
6363 342744199 : return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
6364 685488398 : TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
6365 : }
6366 :
6367 : /* Copy the language-specific type variant modifiers from TYPEB to TYPEA. For
6368 : C++, these are the exception-specifier and ref-qualifier. */
6369 :
6370 : tree
6371 26642264 : cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
6372 : {
6373 26642264 : tree type = const_cast<tree> (typea);
6374 26642264 : if (FUNC_OR_METHOD_TYPE_P (type))
6375 26640957 : type = build_cp_fntype_variant (type, type_memfn_rqual (typeb),
6376 26640957 : TYPE_RAISES_EXCEPTIONS (typeb),
6377 26640957 : TYPE_HAS_LATE_RETURN_TYPE (typeb));
6378 26642264 : return type;
6379 : }
6380 :
6381 : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
6382 : traversal. Called from walk_tree. */
6383 :
6384 : tree
6385 25255335692 : cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
6386 : void *data, hash_set<tree> *pset)
6387 : {
6388 25255335692 : tree t = *tp;
6389 25255335692 : enum tree_code code = TREE_CODE (t);
6390 25255335692 : tree result;
6391 :
6392 : #define WALK_SUBTREE(NODE) \
6393 : do \
6394 : { \
6395 : result = cp_walk_tree (&(NODE), func, data, pset); \
6396 : if (result) goto out; \
6397 : } \
6398 : while (0)
6399 :
6400 25255335692 : if (TYPE_P (t))
6401 : {
6402 : /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
6403 : the argument, so don't look through typedefs, but do walk into
6404 : template arguments for alias templates (and non-typedefed classes).
6405 :
6406 : If *WALK_SUBTREES_P > 1, we're interested in type identity or
6407 : equivalence, so look through typedefs, ignoring template arguments for
6408 : alias templates, and walk into template args of classes.
6409 :
6410 : See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
6411 : when that's the behavior the walk_tree_fn wants. */
6412 7475847397 : if (*walk_subtrees_p == 1 && typedef_variant_p (t))
6413 : {
6414 77079226 : if (tree ti = TYPE_ALIAS_TEMPLATE_INFO (t))
6415 59343381 : WALK_SUBTREE (TI_ARGS (ti));
6416 77018356 : *walk_subtrees_p = 0;
6417 77018356 : return NULL_TREE;
6418 : }
6419 :
6420 7398768171 : if (tree ti = TYPE_TEMPLATE_INFO (t))
6421 848409456 : WALK_SUBTREE (TI_ARGS (ti));
6422 : }
6423 :
6424 : /* Not one of the easy cases. We must explicitly go through the
6425 : children. */
6426 25178087229 : result = NULL_TREE;
6427 25178087229 : switch (code)
6428 : {
6429 1937516335 : case TEMPLATE_TYPE_PARM:
6430 1937516335 : if (template_placeholder_p (t))
6431 1362277 : WALK_SUBTREE (CLASS_PLACEHOLDER_TEMPLATE (t));
6432 : /* Fall through. */
6433 2099035428 : case DEFERRED_PARSE:
6434 2099035428 : case TEMPLATE_TEMPLATE_PARM:
6435 2099035428 : case BOUND_TEMPLATE_TEMPLATE_PARM:
6436 2099035428 : case UNBOUND_CLASS_TEMPLATE:
6437 2099035428 : case TEMPLATE_PARM_INDEX:
6438 2099035428 : case TYPEOF_TYPE:
6439 : /* None of these have subtrees other than those already walked
6440 : above. */
6441 2099035428 : *walk_subtrees_p = 0;
6442 2099035428 : break;
6443 :
6444 219636677 : case TYPENAME_TYPE:
6445 219636677 : WALK_SUBTREE (TYPE_CONTEXT (t));
6446 219545656 : WALK_SUBTREE (TYPENAME_TYPE_FULLNAME (t));
6447 219543449 : *walk_subtrees_p = 0;
6448 219543449 : break;
6449 :
6450 84343597 : case BASELINK:
6451 84343597 : if (BASELINK_QUALIFIED_P (t))
6452 1532381 : WALK_SUBTREE (BINFO_TYPE (BASELINK_ACCESS_BINFO (t)));
6453 84343597 : WALK_SUBTREE (BASELINK_FUNCTIONS (t));
6454 84243105 : *walk_subtrees_p = 0;
6455 84243105 : break;
6456 :
6457 133355 : case PTRMEM_CST:
6458 133355 : WALK_SUBTREE (TREE_TYPE (t));
6459 133355 : *walk_subtrees_p = 0;
6460 133355 : break;
6461 :
6462 281019603 : case TREE_LIST:
6463 281019603 : WALK_SUBTREE (TREE_PURPOSE (t));
6464 : break;
6465 :
6466 318413289 : case OVERLOAD:
6467 318413289 : WALK_SUBTREE (OVL_FUNCTION (t));
6468 318413284 : WALK_SUBTREE (OVL_CHAIN (t));
6469 318413284 : *walk_subtrees_p = 0;
6470 318413284 : break;
6471 :
6472 8093131 : case USING_DECL:
6473 8093131 : WALK_SUBTREE (DECL_NAME (t));
6474 8093131 : WALK_SUBTREE (USING_DECL_SCOPE (t));
6475 8093128 : WALK_SUBTREE (USING_DECL_DECLS (t));
6476 8093128 : *walk_subtrees_p = 0;
6477 8093128 : break;
6478 :
6479 979657465 : case RECORD_TYPE:
6480 979657465 : if (TYPE_PTRMEMFUNC_P (t))
6481 5692150 : WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (t));
6482 : break;
6483 :
6484 151629402 : case TYPE_ARGUMENT_PACK:
6485 151629402 : case NONTYPE_ARGUMENT_PACK:
6486 151629402 : {
6487 151629402 : tree args = ARGUMENT_PACK_ARGS (t);
6488 395767961 : for (tree arg : tree_vec_range (args))
6489 244235090 : WALK_SUBTREE (arg);
6490 : }
6491 151532871 : break;
6492 :
6493 30692375 : case TYPE_PACK_EXPANSION:
6494 30692375 : WALK_SUBTREE (TREE_TYPE (t));
6495 30683163 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
6496 30683163 : *walk_subtrees_p = 0;
6497 30683163 : break;
6498 :
6499 6264132 : case EXPR_PACK_EXPANSION:
6500 6264132 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6501 6260284 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
6502 6260284 : *walk_subtrees_p = 0;
6503 6260284 : break;
6504 :
6505 19384 : case PACK_INDEX_TYPE:
6506 19384 : case PACK_INDEX_EXPR:
6507 19384 : WALK_SUBTREE (PACK_INDEX_PACK (t));
6508 19384 : WALK_SUBTREE (PACK_INDEX_INDEX (t));
6509 19384 : *walk_subtrees_p = 0;
6510 19384 : break;
6511 :
6512 114465147 : case CAST_EXPR:
6513 114465147 : case REINTERPRET_CAST_EXPR:
6514 114465147 : case STATIC_CAST_EXPR:
6515 114465147 : case CONST_CAST_EXPR:
6516 114465147 : case DYNAMIC_CAST_EXPR:
6517 114465147 : case IMPLICIT_CONV_EXPR:
6518 114465147 : case BIT_CAST_EXPR:
6519 114465147 : if (TREE_TYPE (t))
6520 114465147 : WALK_SUBTREE (TREE_TYPE (t));
6521 : break;
6522 :
6523 109281405 : case CONSTRUCTOR:
6524 109281405 : if (COMPOUND_LITERAL_P (t))
6525 10058371 : WALK_SUBTREE (TREE_TYPE (t));
6526 : break;
6527 :
6528 15834560 : case TRAIT_EXPR:
6529 15834560 : WALK_SUBTREE (TRAIT_EXPR_TYPE1 (t));
6530 15834548 : WALK_SUBTREE (TRAIT_EXPR_TYPE2 (t));
6531 15834548 : *walk_subtrees_p = 0;
6532 15834548 : break;
6533 :
6534 2122938 : case TRAIT_TYPE:
6535 2122938 : WALK_SUBTREE (TRAIT_TYPE_TYPE1 (t));
6536 2122938 : WALK_SUBTREE (TRAIT_TYPE_TYPE2 (t));
6537 2122938 : *walk_subtrees_p = 0;
6538 2122938 : break;
6539 :
6540 21703750 : case DECLTYPE_TYPE:
6541 21703750 : {
6542 21703750 : cp_unevaluated u;
6543 21703750 : WALK_SUBTREE (DECLTYPE_TYPE_EXPR (t));
6544 21343341 : *walk_subtrees_p = 0;
6545 21343341 : break;
6546 21703750 : }
6547 :
6548 29001931 : case ALIGNOF_EXPR:
6549 29001931 : case SIZEOF_EXPR:
6550 29001931 : case NOEXCEPT_EXPR:
6551 29001931 : {
6552 29001931 : cp_unevaluated u;
6553 29001931 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6554 25907402 : *walk_subtrees_p = 0;
6555 25907402 : break;
6556 29001931 : }
6557 :
6558 13246543 : case REQUIRES_EXPR:
6559 13246543 : {
6560 13246543 : cp_unevaluated u;
6561 22232361 : for (tree parm = REQUIRES_EXPR_PARMS (t); parm; parm = DECL_CHAIN (parm))
6562 : /* Walk the types of each parameter, but not the parameter itself,
6563 : since doing so would cause false positives in the unexpanded pack
6564 : checker if the requires-expr introduces a function parameter pack,
6565 : e.g. requires (Ts... ts) { }. */
6566 8986718 : WALK_SUBTREE (TREE_TYPE (parm));
6567 13245643 : WALK_SUBTREE (REQUIRES_EXPR_REQS (t));
6568 13241909 : *walk_subtrees_p = 0;
6569 13241909 : break;
6570 13246543 : }
6571 :
6572 133686348 : case DECL_EXPR:
6573 : /* User variables should be mentioned in BIND_EXPR_VARS
6574 : and their initializers and sizes walked when walking
6575 : the containing BIND_EXPR. Compiler temporaries are
6576 : handled here. And also normal variables in templates,
6577 : since do_poplevel doesn't build a BIND_EXPR then. */
6578 133686348 : if (VAR_P (TREE_OPERAND (t, 0))
6579 133686348 : && (processing_template_decl
6580 117606462 : || (DECL_ARTIFICIAL (TREE_OPERAND (t, 0))
6581 6596911 : && !TREE_STATIC (TREE_OPERAND (t, 0)))))
6582 : {
6583 15562768 : tree decl = TREE_OPERAND (t, 0);
6584 15562768 : WALK_SUBTREE (TREE_TYPE (decl));
6585 15562768 : WALK_SUBTREE (DECL_INITIAL (decl));
6586 15562738 : WALK_SUBTREE (DECL_SIZE (decl));
6587 15562738 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
6588 : }
6589 133686318 : if (is_typedef_decl (TREE_OPERAND (t, 0)))
6590 : /* We avoid walking into typedefs above, but we do want to walk
6591 : into them if we're looking at the actual declaration. */
6592 1319822 : WALK_SUBTREE (DECL_ORIGINAL_TYPE (TREE_OPERAND (t, 0)));
6593 : break;
6594 :
6595 2078666 : case LAMBDA_EXPR:
6596 : /* Don't walk into the body of the lambda, but the capture initializers
6597 : are part of the enclosing context. */
6598 4975874 : for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (t); cap;
6599 2897208 : cap = TREE_CHAIN (cap))
6600 2897208 : WALK_SUBTREE (TREE_VALUE (cap));
6601 : break;
6602 :
6603 4511 : case CO_YIELD_EXPR:
6604 4511 : if (TREE_OPERAND (t, 1))
6605 : /* Operand 1 is the tree for the relevant co_await which has any
6606 : interesting sub-trees. */
6607 601 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6608 : break;
6609 :
6610 27816 : case CO_AWAIT_EXPR:
6611 27816 : if (TREE_OPERAND (t, 1))
6612 : /* Operand 1 is frame variable. */
6613 27628 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6614 27816 : if (TREE_OPERAND (t, 2))
6615 : /* Operand 2 has the initialiser, and we need to walk any subtrees
6616 : there. */
6617 5557 : WALK_SUBTREE (TREE_OPERAND (t, 2));
6618 : break;
6619 :
6620 885 : case CO_RETURN_EXPR:
6621 885 : if (TREE_OPERAND (t, 0))
6622 : {
6623 699 : if (VOID_TYPE_P (TREE_OPERAND (t, 0)))
6624 : /* For void expressions, operand 1 is a trivial call, and any
6625 : interesting subtrees will be part of operand 0. */
6626 0 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6627 699 : else if (TREE_OPERAND (t, 1))
6628 : /* Interesting sub-trees will be in the return_value () call
6629 : arguments. */
6630 657 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6631 : }
6632 : break;
6633 :
6634 661870 : case STATIC_ASSERT:
6635 661870 : WALK_SUBTREE (STATIC_ASSERT_CONDITION (t));
6636 661870 : WALK_SUBTREE (STATIC_ASSERT_MESSAGE (t));
6637 : break;
6638 :
6639 770037876 : case INTEGER_TYPE:
6640 : /* Removed from walk_type_fields in r119481. */
6641 770037876 : WALK_SUBTREE (TYPE_MIN_VALUE (t));
6642 770037876 : WALK_SUBTREE (TYPE_MAX_VALUE (t));
6643 : break;
6644 :
6645 754 : case SPLICE_SCOPE:
6646 754 : WALK_SUBTREE (SPLICE_SCOPE_EXPR (t));
6647 748 : *walk_subtrees_p = 0;
6648 748 : break;
6649 :
6650 : default:
6651 : return NULL_TREE;
6652 : }
6653 :
6654 : /* We didn't find what we were looking for. */
6655 25255335692 : out:
6656 : return result;
6657 :
6658 : #undef WALK_SUBTREE
6659 : }
6660 :
6661 : /* Like save_expr, but for C++. */
6662 :
6663 : tree
6664 327709 : cp_save_expr (tree expr)
6665 : {
6666 : /* There is no reason to create a SAVE_EXPR within a template; if
6667 : needed, we can create the SAVE_EXPR when instantiating the
6668 : template. Furthermore, the middle-end cannot handle C++-specific
6669 : tree codes. */
6670 327709 : if (processing_template_decl)
6671 : return expr;
6672 :
6673 : /* TARGET_EXPRs are only expanded once. */
6674 253878 : if (TREE_CODE (expr) == TARGET_EXPR)
6675 : return expr;
6676 :
6677 253878 : return save_expr (expr);
6678 : }
6679 :
6680 : /* Initialize tree.cc. */
6681 :
6682 : void
6683 102674 : init_tree (void)
6684 : {
6685 102674 : list_hash_table = hash_table<list_hasher>::create_ggc (61);
6686 102674 : }
6687 :
6688 : /* Returns the kind of special function that DECL (a FUNCTION_DECL)
6689 : is. Note that sfk_none is zero, so this function can be used as a
6690 : predicate to test whether or not DECL is a special function. */
6691 :
6692 : special_function_kind
6693 153661276 : special_function_p (const_tree decl)
6694 : {
6695 : /* Rather than doing all this stuff with magic names, we should
6696 : probably have a field of type `special_function_kind' in
6697 : DECL_LANG_SPECIFIC. */
6698 307322552 : if (DECL_INHERITED_CTOR (decl))
6699 : return sfk_inheriting_constructor;
6700 306549852 : if (DECL_COPY_CONSTRUCTOR_P (decl))
6701 : return sfk_copy_constructor;
6702 276632790 : if (DECL_MOVE_CONSTRUCTOR_P (decl))
6703 : return sfk_move_constructor;
6704 256739694 : if (DECL_CONSTRUCTOR_P (decl))
6705 : return sfk_constructor;
6706 109903792 : if (DECL_ASSIGNMENT_OPERATOR_P (decl)
6707 109903792 : && DECL_OVERLOADED_OPERATOR_IS (decl, NOP_EXPR))
6708 : {
6709 12766343 : if (copy_fn_p (decl))
6710 : return sfk_copy_assignment;
6711 5094536 : if (move_fn_p (decl))
6712 : return sfk_move_assignment;
6713 : }
6714 97349440 : if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
6715 : return sfk_destructor;
6716 56086787 : if (DECL_COMPLETE_DESTRUCTOR_P (decl))
6717 : return sfk_complete_destructor;
6718 42487082 : if (DECL_BASE_DESTRUCTOR_P (decl))
6719 : return sfk_base_destructor;
6720 41549658 : if (DECL_DELETING_DESTRUCTOR_P (decl))
6721 : return sfk_deleting_destructor;
6722 29797783 : if (DECL_CONV_FN_P (decl))
6723 : return sfk_conversion;
6724 29796176 : if (deduction_guide_p (decl))
6725 : return sfk_deduction_guide;
6726 29766240 : if (DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) >= OVL_OP_EQ_EXPR
6727 29766240 : && DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) <= OVL_OP_SPACESHIP_EXPR)
6728 4315950 : return sfk_comparison;
6729 :
6730 : return sfk_none;
6731 : }
6732 :
6733 : /* As above, but only if DECL is a special member function as per 11.3.3
6734 : [special]: default/copy/move ctor, copy/move assignment, or destructor. */
6735 :
6736 : special_function_kind
6737 3088978 : special_memfn_p (const_tree decl)
6738 : {
6739 3088978 : switch (special_function_kind sfk = special_function_p (decl))
6740 : {
6741 2849694 : case sfk_constructor:
6742 2849694 : if (!default_ctor_p (decl))
6743 : break;
6744 : gcc_fallthrough();
6745 : case sfk_copy_constructor:
6746 : case sfk_copy_assignment:
6747 : case sfk_move_assignment:
6748 : case sfk_move_constructor:
6749 : case sfk_destructor:
6750 : return sfk;
6751 :
6752 : default:
6753 : break;
6754 : }
6755 : return sfk_none;
6756 : }
6757 :
6758 : /* Returns nonzero if TYPE is a character type, including wchar_t. */
6759 :
6760 : int
6761 12657140 : char_type_p (tree type)
6762 : {
6763 12657140 : return (same_type_p (type, char_type_node)
6764 11465874 : || same_type_p (type, unsigned_char_type_node)
6765 11412958 : || same_type_p (type, signed_char_type_node)
6766 11412381 : || same_type_p (type, char8_type_node)
6767 11412241 : || same_type_p (type, char16_type_node)
6768 11411731 : || same_type_p (type, char32_type_node)
6769 23947268 : || same_type_p (type, wchar_type_node));
6770 : }
6771 :
6772 : /* Returns the kind of linkage associated with the indicated DECL. The
6773 : value returned is as specified by the language standard; it is
6774 : independent of implementation details regarding template
6775 : instantiation, etc. For example, it is possible that a declaration
6776 : to which this function assigns external linkage would not show up
6777 : as a global symbol when you run `nm' on the resulting object file. */
6778 :
6779 : linkage_kind
6780 482389475 : decl_linkage (tree decl)
6781 : {
6782 : /* This function doesn't attempt to calculate the linkage from first
6783 : principles as given in [basic.link]. Instead, it makes use of
6784 : the fact that we have already set TREE_PUBLIC appropriately, and
6785 : then handles a few special cases. Ideally, we would calculate
6786 : linkage first, and then transform that into a concrete
6787 : implementation. */
6788 :
6789 : /* An explicit type alias has no linkage. Nor do the built-in declarations
6790 : of 'int' and such. */
6791 529830023 : if (TREE_CODE (decl) == TYPE_DECL
6792 529830023 : && !DECL_IMPLICIT_TYPEDEF_P (decl))
6793 : {
6794 : /* But this could be a typedef name for linkage purposes, in which
6795 : case we're interested in the linkage of the main decl. */
6796 1013729 : tree type = TREE_TYPE (decl);
6797 1013729 : if (type == error_mark_node)
6798 : return lk_none;
6799 1013727 : else if (decl == TYPE_NAME (TYPE_MAIN_VARIANT (type))
6800 : /* Likewise for the injected-class-name. */
6801 1013727 : || DECL_SELF_REFERENCE_P (decl))
6802 73925 : decl = TYPE_MAIN_DECL (type);
6803 : else
6804 : return lk_none;
6805 : }
6806 :
6807 : /* Namespace-scope entities with no name usually have no linkage. */
6808 528890219 : if (NAMESPACE_SCOPE_P (decl)
6809 1006634351 : && (!DECL_NAME (decl) || IDENTIFIER_ANON_P (DECL_NAME (decl))))
6810 : {
6811 3878275 : if (TREE_CODE (decl) == TYPE_DECL && !TYPE_UNNAMED_P (TREE_TYPE (decl)))
6812 : /* This entity has a name for linkage purposes. */;
6813 3856950 : else if (DECL_DECOMPOSITION_P (decl) && DECL_DECOMP_IS_BASE (decl))
6814 : /* Namespace-scope structured bindings can have linkage. */;
6815 3856845 : else if (TREE_CODE (decl) == NAMESPACE_DECL && cxx_dialect >= cxx11)
6816 : /* An anonymous namespace has internal linkage since C++11. */
6817 : return lk_internal;
6818 : else
6819 3856845 : return lk_none;
6820 : }
6821 :
6822 : /* Fields and parameters have no linkage. */
6823 525033374 : if (TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == PARM_DECL)
6824 : return lk_none;
6825 :
6826 : /* Things in block scope do not have linkage. */
6827 477718797 : if (decl_function_context (decl))
6828 : return lk_none;
6829 :
6830 : /* Things in class scope have the linkage of their owning class. */
6831 474015650 : if (tree ctype = DECL_CLASS_CONTEXT (decl))
6832 47440548 : return decl_linkage (TYPE_NAME (ctype));
6833 :
6834 : /* Anonymous namespaces don't provide internal linkage in C++98,
6835 : but otherwise consider such declarations to be internal. */
6836 426575102 : if (cxx_dialect >= cxx11 && decl_internal_context_p (decl))
6837 : return lk_internal;
6838 :
6839 : /* Helper to decide if T is lk_module or lk_external. */
6840 852607304 : auto external_or_module = [] (tree t)
6841 : {
6842 426220339 : if (t
6843 426220306 : && DECL_LANG_SPECIFIC (t)
6844 315605149 : && DECL_MODULE_ATTACH_P (t)
6845 426238495 : && !DECL_MODULE_EXPORT_P (t))
6846 7585 : return lk_module;
6847 :
6848 : return lk_external;
6849 : };
6850 :
6851 : /* Templates don't properly propagate TREE_PUBLIC, consider the
6852 : template result instead. Any template that isn't a variable
6853 : or function must be external linkage by this point. */
6854 426386965 : if (TREE_CODE (decl) == TEMPLATE_DECL)
6855 : {
6856 1318423 : decl = DECL_TEMPLATE_RESULT (decl);
6857 1318423 : if (!decl || !VAR_OR_FUNCTION_DECL_P (decl))
6858 610547 : return external_or_module (decl);
6859 : }
6860 :
6861 : /* Things that are TREE_PUBLIC have external linkage. */
6862 425776418 : if (TREE_PUBLIC (decl))
6863 334204013 : return external_or_module (decl);
6864 :
6865 : /* All types have external linkage in C++98, since anonymous namespaces
6866 : didn't explicitly confer internal linkage. */
6867 91572405 : if (TREE_CODE (decl) == TYPE_DECL && cxx_dialect < cxx11)
6868 4 : return external_or_module (decl);
6869 :
6870 : /* Variables or function decls not marked as TREE_PUBLIC might still
6871 : be external linkage, such as for template instantiations on targets
6872 : without weak symbols, decls referring to internal-linkage entities,
6873 : or compiler-generated entities; in such cases, decls really meant to
6874 : have internal linkage will have DECL_THIS_STATIC set. */
6875 91572401 : if (VAR_OR_FUNCTION_DECL_P (decl) && !DECL_THIS_STATIC (decl))
6876 91405775 : return external_or_module (decl);
6877 :
6878 : /* Everything else has internal linkage. */
6879 : return lk_internal;
6880 : }
6881 :
6882 : /* Returns the storage duration of the object or reference associated with
6883 : the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
6884 :
6885 : duration_kind
6886 63052194 : decl_storage_duration (tree decl)
6887 : {
6888 63052194 : if (TREE_CODE (decl) == PARM_DECL)
6889 : return dk_auto;
6890 63052182 : if (TREE_CODE (decl) == FUNCTION_DECL)
6891 : return dk_static;
6892 63052182 : gcc_assert (VAR_P (decl));
6893 63052182 : if (!TREE_STATIC (decl)
6894 63052182 : && !DECL_EXTERNAL (decl))
6895 : return dk_auto;
6896 37755206 : if (CP_DECL_THREAD_LOCAL_P (decl))
6897 21012 : return dk_thread;
6898 : return dk_static;
6899 : }
6900 :
6901 : /* EXP is an expression that we want to pre-evaluate. Returns (in
6902 : *INITP) an expression that will perform the pre-evaluation. The
6903 : value returned by this function is a side-effect free expression
6904 : equivalent to the pre-evaluated expression. Callers must ensure
6905 : that *INITP is evaluated before EXP.
6906 :
6907 : Note that if EXPR is a glvalue, the return value is a glvalue denoting the
6908 : same address; this function does not guard against modification of the
6909 : stored value like save_expr or get_target_expr do. */
6910 :
6911 : tree
6912 6120395 : stabilize_expr (tree exp, tree* initp)
6913 : {
6914 6120395 : tree init_expr;
6915 :
6916 6120395 : if (!TREE_SIDE_EFFECTS (exp))
6917 : init_expr = NULL_TREE;
6918 960331 : else if (VOID_TYPE_P (TREE_TYPE (exp)))
6919 : {
6920 0 : init_expr = exp;
6921 0 : exp = void_node;
6922 : }
6923 : /* There are no expressions with REFERENCE_TYPE, but there can be call
6924 : arguments with such a type; just treat it as a pointer. */
6925 960331 : else if (TYPE_REF_P (TREE_TYPE (exp))
6926 960196 : || SCALAR_TYPE_P (TREE_TYPE (exp))
6927 960391 : || !glvalue_p (exp))
6928 : {
6929 960325 : init_expr = get_target_expr (exp);
6930 960325 : exp = TARGET_EXPR_SLOT (init_expr);
6931 960325 : if (CLASS_TYPE_P (TREE_TYPE (exp)))
6932 9 : exp = move (exp);
6933 : else
6934 960316 : exp = rvalue (exp);
6935 : }
6936 : else
6937 : {
6938 6 : bool xval = !lvalue_p (exp);
6939 6 : exp = cp_build_addr_expr (exp, tf_warning_or_error);
6940 6 : init_expr = get_target_expr (exp);
6941 6 : exp = TARGET_EXPR_SLOT (init_expr);
6942 6 : exp = cp_build_fold_indirect_ref (exp);
6943 6 : if (xval)
6944 0 : exp = move (exp);
6945 : }
6946 6120395 : *initp = init_expr;
6947 :
6948 6120395 : gcc_assert (!TREE_SIDE_EFFECTS (exp) || TREE_THIS_VOLATILE (exp));
6949 6120395 : return exp;
6950 : }
6951 :
6952 : /* Add NEW_EXPR, an expression whose value we don't care about, after the
6953 : similar expression ORIG. */
6954 :
6955 : tree
6956 1350576 : add_stmt_to_compound (tree orig, tree new_expr)
6957 : {
6958 1350576 : if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
6959 : return orig;
6960 678874 : if (!orig || !TREE_SIDE_EFFECTS (orig))
6961 : return new_expr;
6962 12846 : return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
6963 : }
6964 :
6965 : /* Like stabilize_expr, but for a call whose arguments we want to
6966 : pre-evaluate. CALL is modified in place to use the pre-evaluated
6967 : arguments, while, upon return, *INITP contains an expression to
6968 : compute the arguments. */
6969 :
6970 : void
6971 667440 : stabilize_call (tree call, tree *initp)
6972 : {
6973 667440 : tree inits = NULL_TREE;
6974 667440 : int i;
6975 667440 : int nargs = call_expr_nargs (call);
6976 :
6977 667440 : if (call == error_mark_node || processing_template_decl)
6978 : {
6979 39 : *initp = NULL_TREE;
6980 39 : return;
6981 : }
6982 :
6983 667401 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
6984 :
6985 2002321 : for (i = 0; i < nargs; i++)
6986 : {
6987 1334920 : tree init;
6988 1334920 : CALL_EXPR_ARG (call, i) =
6989 1334920 : stabilize_expr (CALL_EXPR_ARG (call, i), &init);
6990 1334920 : inits = add_stmt_to_compound (inits, init);
6991 : }
6992 :
6993 667401 : *initp = inits;
6994 : }
6995 :
6996 : /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
6997 : to pre-evaluate. CALL is modified in place to use the pre-evaluated
6998 : arguments, while, upon return, *INITP contains an expression to
6999 : compute the arguments. */
7000 :
7001 : static void
7002 0 : stabilize_aggr_init (tree call, tree *initp)
7003 : {
7004 0 : tree inits = NULL_TREE;
7005 0 : int i;
7006 0 : int nargs = aggr_init_expr_nargs (call);
7007 :
7008 0 : if (call == error_mark_node)
7009 : return;
7010 :
7011 0 : gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
7012 :
7013 0 : for (i = 0; i < nargs; i++)
7014 : {
7015 0 : tree init;
7016 0 : AGGR_INIT_EXPR_ARG (call, i) =
7017 0 : stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
7018 0 : inits = add_stmt_to_compound (inits, init);
7019 : }
7020 :
7021 0 : *initp = inits;
7022 : }
7023 :
7024 : /* Like stabilize_expr, but for an initialization.
7025 :
7026 : If the initialization is for an object of class type, this function
7027 : takes care not to introduce additional temporaries.
7028 :
7029 : Returns TRUE iff the expression was successfully pre-evaluated,
7030 : i.e., if INIT is now side-effect free, except for, possibly, a
7031 : single call to a constructor. */
7032 :
7033 : bool
7034 0 : stabilize_init (tree init, tree *initp)
7035 : {
7036 0 : tree t = init;
7037 :
7038 0 : *initp = NULL_TREE;
7039 :
7040 0 : if (t == error_mark_node || processing_template_decl)
7041 : return true;
7042 :
7043 0 : if (TREE_CODE (t) == INIT_EXPR)
7044 0 : t = TREE_OPERAND (t, 1);
7045 0 : if (TREE_CODE (t) == TARGET_EXPR)
7046 0 : t = TARGET_EXPR_INITIAL (t);
7047 :
7048 : /* If the RHS can be stabilized without breaking copy elision, stabilize
7049 : it. We specifically don't stabilize class prvalues here because that
7050 : would mean an extra copy, but they might be stabilized below. */
7051 0 : if (TREE_CODE (init) == INIT_EXPR
7052 0 : && TREE_CODE (t) != CONSTRUCTOR
7053 0 : && TREE_CODE (t) != AGGR_INIT_EXPR
7054 0 : && (SCALAR_TYPE_P (TREE_TYPE (t))
7055 0 : || glvalue_p (t)))
7056 : {
7057 0 : TREE_OPERAND (init, 1) = stabilize_expr (t, initp);
7058 0 : return true;
7059 : }
7060 :
7061 0 : if (TREE_CODE (t) == COMPOUND_EXPR
7062 0 : && TREE_CODE (init) == INIT_EXPR)
7063 : {
7064 0 : tree last = expr_last (t);
7065 : /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */
7066 0 : if (!TREE_SIDE_EFFECTS (last))
7067 : {
7068 0 : *initp = t;
7069 0 : TREE_OPERAND (init, 1) = last;
7070 0 : return true;
7071 : }
7072 : }
7073 :
7074 0 : if (TREE_CODE (t) == CONSTRUCTOR)
7075 : {
7076 : /* Aggregate initialization: stabilize each of the field
7077 : initializers. */
7078 0 : unsigned i;
7079 0 : constructor_elt *ce;
7080 0 : bool good = true;
7081 0 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
7082 0 : for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
7083 : {
7084 0 : tree type = TREE_TYPE (ce->value);
7085 0 : tree subinit;
7086 0 : if (TYPE_REF_P (type)
7087 0 : || SCALAR_TYPE_P (type))
7088 0 : ce->value = stabilize_expr (ce->value, &subinit);
7089 0 : else if (!stabilize_init (ce->value, &subinit))
7090 0 : good = false;
7091 0 : *initp = add_stmt_to_compound (*initp, subinit);
7092 : }
7093 : return good;
7094 : }
7095 :
7096 0 : if (TREE_CODE (t) == CALL_EXPR)
7097 : {
7098 0 : stabilize_call (t, initp);
7099 0 : return true;
7100 : }
7101 :
7102 0 : if (TREE_CODE (t) == AGGR_INIT_EXPR)
7103 : {
7104 0 : stabilize_aggr_init (t, initp);
7105 0 : return true;
7106 : }
7107 :
7108 : /* The initialization is being performed via a bitwise copy -- and
7109 : the item copied may have side effects. */
7110 0 : return !TREE_SIDE_EFFECTS (init);
7111 : }
7112 :
7113 : /* Returns true if a cast to TYPE may appear in an integral constant
7114 : expression. */
7115 :
7116 : bool
7117 98133169 : cast_valid_in_integral_constant_expression_p (tree type)
7118 : {
7119 98133169 : return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
7120 70239061 : || cxx_dialect >= cxx11
7121 463649 : || dependent_type_p (type)
7122 98504772 : || type == error_mark_node);
7123 : }
7124 :
7125 : /* Return true if we need to fix linkage information of DECL. */
7126 :
7127 : static bool
7128 77087 : cp_fix_function_decl_p (tree decl)
7129 : {
7130 : /* Skip if DECL is not externally visible. */
7131 77087 : if (!TREE_PUBLIC (decl))
7132 : return false;
7133 :
7134 : /* We need to fix DECL if it a appears to be exported but with no
7135 : function body. Thunks do not have CFGs and we may need to
7136 : handle them specially later. */
7137 74638 : if (!gimple_has_body_p (decl)
7138 27881 : && !DECL_THUNK_P (decl)
7139 102125 : && !DECL_EXTERNAL (decl))
7140 : {
7141 12963 : struct cgraph_node *node = cgraph_node::get (decl);
7142 :
7143 : /* Don't fix same_body aliases. Although they don't have their own
7144 : CFG, they share it with what they alias to. */
7145 12963 : if (!node || !node->alias || !node->num_references ())
7146 6795 : return true;
7147 : }
7148 :
7149 : return false;
7150 : }
7151 :
7152 : /* Clean the C++ specific parts of the tree T. */
7153 :
7154 : void
7155 752956 : cp_free_lang_data (tree t)
7156 : {
7157 752956 : if (FUNC_OR_METHOD_TYPE_P (t))
7158 : {
7159 : /* Default args are not interesting anymore. */
7160 62347 : tree argtypes = TYPE_ARG_TYPES (t);
7161 224090 : while (argtypes)
7162 : {
7163 161743 : TREE_PURPOSE (argtypes) = 0;
7164 161743 : argtypes = TREE_CHAIN (argtypes);
7165 : }
7166 : }
7167 690609 : else if (TREE_CODE (t) == FUNCTION_DECL
7168 690609 : && cp_fix_function_decl_p (t))
7169 : {
7170 : /* If T is used in this translation unit at all, the definition
7171 : must exist somewhere else since we have decided to not emit it
7172 : in this TU. So make it an external reference. */
7173 6795 : DECL_EXTERNAL (t) = 1;
7174 6795 : TREE_STATIC (t) = 0;
7175 : }
7176 752956 : if (TREE_CODE (t) == NAMESPACE_DECL)
7177 : /* We do not need the leftover chaining of namespaces from the
7178 : binding level. */
7179 1693 : DECL_CHAIN (t) = NULL_TREE;
7180 752956 : }
7181 :
7182 : /* Stub for c-common. Please keep in sync with c-decl.cc.
7183 : FIXME: If address space support is target specific, then this
7184 : should be a C target hook. But currently this is not possible,
7185 : because this function is called via REGISTER_TARGET_PRAGMAS. */
7186 : void
7187 205348 : c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
7188 : {
7189 205348 : }
7190 :
7191 : /* Return the number of operands in T that we care about for things like
7192 : mangling. */
7193 :
7194 : int
7195 640567723 : cp_tree_operand_length (const_tree t)
7196 : {
7197 640567723 : enum tree_code code = TREE_CODE (t);
7198 :
7199 640567723 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
7200 68959940 : return VL_EXP_OPERAND_LENGTH (t);
7201 :
7202 571607783 : return cp_tree_code_length (code);
7203 : }
7204 :
7205 : /* Like cp_tree_operand_length, but takes a tree_code CODE. */
7206 :
7207 : int
7208 578044483 : cp_tree_code_length (enum tree_code code)
7209 : {
7210 578044483 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
7211 :
7212 578044483 : switch (code)
7213 : {
7214 : case PREINCREMENT_EXPR:
7215 : case PREDECREMENT_EXPR:
7216 : case POSTINCREMENT_EXPR:
7217 : case POSTDECREMENT_EXPR:
7218 : return 1;
7219 :
7220 1120531 : case ARRAY_REF:
7221 1120531 : return 2;
7222 :
7223 : case EXPR_PACK_EXPANSION:
7224 : return 1;
7225 :
7226 574371884 : default:
7227 574371884 : return TREE_CODE_LENGTH (code);
7228 : }
7229 : }
7230 :
7231 : /* Implement -Wzero_as_null_pointer_constant. Return true if the
7232 : conditions for the warning hold, false otherwise. */
7233 : bool
7234 7571698 : maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
7235 : {
7236 7571698 : if (c_inhibit_evaluation_warnings == 0
7237 14102136 : && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
7238 : {
7239 2681189 : warning_at (loc, OPT_Wzero_as_null_pointer_constant,
7240 : "zero as null pointer constant");
7241 2681189 : return true;
7242 : }
7243 : return false;
7244 : }
7245 :
7246 : /* FNDECL is a function declaration whose type may have been altered by
7247 : adding extra parameters such as this, in-charge, or VTT. When this
7248 : takes place, the positional arguments supplied by the user (as in the
7249 : 'format' attribute arguments) may refer to the wrong argument. This
7250 : function returns an integer indicating how many arguments should be
7251 : skipped. */
7252 :
7253 : int
7254 38644573 : maybe_adjust_arg_pos_for_attribute (const_tree fndecl)
7255 : {
7256 38644573 : if (!fndecl)
7257 : return 0;
7258 7604408 : int n = num_artificial_parms_for (fndecl);
7259 : /* The manual states that it's the user's responsibility to account
7260 : for the implicit this parameter. */
7261 7604408 : return n > 0 ? n - 1 : 0;
7262 : }
7263 :
7264 : /* True if ATTR is annotation. */
7265 :
7266 : bool
7267 59823934 : annotation_p (tree attr)
7268 : {
7269 59823934 : return is_attribute_p ("annotation ", get_attribute_name (attr));
7270 : }
7271 :
7272 : /* Lookup the annotation in ATTR, if present. */
7273 :
7274 : tree
7275 78724 : lookup_annotation (tree attr)
7276 : {
7277 78724 : return lookup_attribute ("internal ", "annotation ", attr);
7278 : }
7279 :
7280 :
7281 : /* Release memory we no longer need after parsing. */
7282 : void
7283 100997 : cp_tree_c_finish_parsing ()
7284 : {
7285 100997 : if (previous_class_level)
7286 70535 : invalidate_class_lookup_cache ();
7287 100997 : deleted_copy_types = NULL;
7288 100997 : }
7289 :
7290 : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
7291 : /* Complain that some language-specific thing hanging off a tree
7292 : node has been accessed improperly. */
7293 :
7294 : void
7295 0 : lang_check_failed (const char* file, int line, const char* function)
7296 : {
7297 0 : internal_error ("%<lang_*%> check: failed in %s, at %s:%d",
7298 : function, trim_filename (file), line);
7299 : }
7300 : #endif /* ENABLE_TREE_CHECKING */
7301 :
7302 : #if CHECKING_P
7303 :
7304 : namespace selftest {
7305 :
7306 : /* Verify that lvalue_kind () works, for various expressions,
7307 : and that location wrappers don't affect the results. */
7308 :
7309 : static void
7310 1 : test_lvalue_kind ()
7311 : {
7312 1 : location_t loc = BUILTINS_LOCATION;
7313 :
7314 : /* Verify constants and parameters, without and with
7315 : location wrappers. */
7316 1 : tree int_cst = build_int_cst (integer_type_node, 42);
7317 1 : ASSERT_EQ (clk_none, lvalue_kind (int_cst));
7318 :
7319 1 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
7320 1 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
7321 1 : ASSERT_EQ (clk_none, lvalue_kind (wrapped_int_cst));
7322 :
7323 1 : tree string_lit = build_string (4, "foo");
7324 1 : TREE_TYPE (string_lit) = char_array_type_node;
7325 1 : string_lit = fix_string_type (string_lit);
7326 1 : ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (string_lit));
7327 :
7328 1 : tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
7329 1 : ASSERT_TRUE (location_wrapper_p (wrapped_string_lit));
7330 1 : ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (wrapped_string_lit));
7331 :
7332 1 : tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL,
7333 : get_identifier ("some_parm"),
7334 : integer_type_node);
7335 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (parm));
7336 :
7337 1 : tree wrapped_parm = maybe_wrap_with_location (parm, loc);
7338 1 : ASSERT_TRUE (location_wrapper_p (wrapped_parm));
7339 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_parm));
7340 :
7341 : /* Verify that lvalue_kind of std::move on a parm isn't
7342 : affected by location wrappers. */
7343 1 : tree rvalue_ref_of_parm = move (parm);
7344 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm));
7345 1 : tree rvalue_ref_of_wrapped_parm = move (wrapped_parm);
7346 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm));
7347 :
7348 : /* Verify lvalue_p. */
7349 1 : ASSERT_FALSE (lvalue_p (int_cst));
7350 1 : ASSERT_FALSE (lvalue_p (wrapped_int_cst));
7351 1 : ASSERT_TRUE (lvalue_p (parm));
7352 1 : ASSERT_TRUE (lvalue_p (wrapped_parm));
7353 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm));
7354 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm));
7355 1 : }
7356 :
7357 : /* Run all of the selftests within this file. */
7358 :
7359 : void
7360 1 : cp_tree_cc_tests ()
7361 : {
7362 1 : test_lvalue_kind ();
7363 1 : }
7364 :
7365 : } // namespace selftest
7366 :
7367 : #endif /* #if CHECKING_P */
7368 :
7369 :
7370 : #include "gt-cp-tree.h"
|