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