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