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