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 : 2017138784 : lvalue_kind (const_tree ref)
57 : : {
58 : 2191765566 : cp_lvalue_kind op1_lvalue_kind = clk_none;
59 : 2191765566 : 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 : 2191765566 : if (REFERENCE_REF_P (ref))
66 : 163966367 : return lvalue_kind (TREE_OPERAND (ref, 0));
67 : :
68 : 2027799199 : if (TREE_TYPE (ref)
69 : 2027799199 : && TYPE_REF_P (TREE_TYPE (ref)))
70 : : {
71 : : /* unnamed rvalue references are rvalues */
72 : 166944750 : 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 : 200593768 : && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
78 : : {
79 : 33648407 : op1_lvalue_kind = clk_rvalueref;
80 : 33648407 : if (implicit_rvalue_p (ref))
81 : 5621439 : op1_lvalue_kind |= clk_implicit_rval;
82 : 33648407 : return op1_lvalue_kind;
83 : : }
84 : :
85 : : /* lvalue references and named rvalue references are lvalues. */
86 : : return clk_ordinary;
87 : : }
88 : :
89 : 1860854449 : if (ref == current_class_ptr)
90 : : return clk_none;
91 : :
92 : : /* Expressions with cv void type are prvalues. */
93 : 1858999650 : if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
94 : : return clk_none;
95 : :
96 : 1858521878 : 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 : 250422517 : case PREINCREMENT_EXPR:
104 : 250422517 : case PREDECREMENT_EXPR:
105 : 250422517 : case TRY_CATCH_EXPR:
106 : 250422517 : case REALPART_EXPR:
107 : 250422517 : case IMAGPART_EXPR:
108 : 250422517 : case VIEW_CONVERT_EXPR:
109 : 250422517 : 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 : 250422517 : if (op1_lvalue_kind == clk_class
115 : 250422531 : && !(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 : 2958403 : case ARRAY_REF:
122 : 2958403 : {
123 : 2958403 : tree op1 = TREE_OPERAND (ref, 0);
124 : 2958403 : if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
125 : : {
126 : 2477758 : op1_lvalue_kind = lvalue_kind (op1);
127 : 2477758 : 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 : 2477758 : 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 : 136357326 : case COMPONENT_REF:
153 : 136357326 : 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 : 136357299 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
165 : 136357299 : 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 : 136106032 : if (!op1_lvalue_kind)
172 : : ;
173 : 136357275 : 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 : 136357184 : else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
179 : : /* This can be IDENTIFIER_NODE in a template. */;
180 : 130144159 : 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 : 8218330 : op1_lvalue_kind &= ~clk_ordinary;
185 : : /* The lvalue is for a bitfield. */
186 : 8218330 : op1_lvalue_kind |= clk_bitfield;
187 : : }
188 : 121925829 : 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 : 1399413 : 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 : 1399413 : if (! TREE_STATIC (ref))
205 : : return clk_none;
206 : : /* FALLTHRU */
207 : 201322912 : case VAR_DECL:
208 : 201322912 : if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
209 : 721992 : return lvalue_kind (DECL_VALUE_EXPR (CONST_CAST_TREE (ref)));
210 : :
211 : 274766689 : if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
212 : 12986963 : && DECL_LANG_SPECIFIC (ref)
213 : 201280354 : && DECL_IN_AGGR_P (ref))
214 : : return clk_none;
215 : :
216 : 200600920 : 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 : 8423599 : case SCOPE_REF:
230 : 8423599 : gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
231 : 8423599 : {
232 : 8423599 : tree op = TREE_OPERAND (ref, 1);
233 : 8423599 : if (TREE_CODE (op) == FIELD_DECL)
234 : 19241 : 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 : 9326450 : case COND_EXPR:
250 : 9326450 : 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 : 947790 : gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
259 : 947790 : goto default_;
260 : : }
261 : 8378660 : {
262 : 8378660 : tree op1 = TREE_OPERAND (ref, 1);
263 : 8378660 : if (!op1) op1 = TREE_OPERAND (ref, 0);
264 : 8378660 : tree op2 = TREE_OPERAND (ref, 2);
265 : 8378660 : op1_lvalue_kind = lvalue_kind (op1);
266 : 8378660 : op2_lvalue_kind = lvalue_kind (op2);
267 : 8378660 : 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 : 566947 : if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
273 : : op2_lvalue_kind = op1_lvalue_kind;
274 : 566905 : else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
275 : 8379145 : op1_lvalue_kind = op2_lvalue_kind;
276 : : }
277 : : }
278 : : break;
279 : :
280 : 70233 : case MODOP_EXPR:
281 : : /* We expect to see unlowered MODOP_EXPRs only during
282 : : template processing. */
283 : 70233 : gcc_assert (processing_template_decl);
284 : 70233 : 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 : 1498118 : case COMPOUND_EXPR:
294 : 1498118 : return lvalue_kind (TREE_OPERAND (ref, 1));
295 : :
296 : : case TARGET_EXPR:
297 : : return clk_class;
298 : :
299 : 1373 : case VA_ARG_EXPR:
300 : 1373 : return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
301 : :
302 : 94225928 : case CALL_EXPR:
303 : : /* We can see calls outside of TARGET_EXPR in templates. */
304 : 94225928 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
305 : : return clk_class;
306 : : return clk_none;
307 : :
308 : 97648008 : case FUNCTION_DECL:
309 : : /* All functions (except non-static-member functions) are
310 : : lvalues. */
311 : 97648008 : return (DECL_IOBJ_MEMBER_FUNCTION_P (ref)
312 : 97648008 : ? clk_none : clk_ordinary);
313 : :
314 : 2984 : 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 : 2984 : return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
320 : :
321 : 32936 : case PAREN_EXPR:
322 : 32936 : return lvalue_kind (TREE_OPERAND (ref, 0));
323 : :
324 : 15709351 : case TEMPLATE_PARM_INDEX:
325 : 15709351 : 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 : 740184482 : default:
331 : 740184482 : default_:
332 : 740184482 : if (!TREE_TYPE (ref))
333 : : return clk_none;
334 : 1480368964 : if (CLASS_TYPE_P (TREE_TYPE (ref))
335 : 1478600628 : || 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 : 8379145 : 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 : 1422929 : op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
348 : : /* It's not an ordinary lvalue if it involves any other kind. */
349 : 1422929 : if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
350 : 305458 : 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 : 305458 : if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
354 : 25341 : && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
355 : 847347694 : 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 : 35690214 : real_lvalue_p (const_tree ref)
363 : : {
364 : 35690214 : cp_lvalue_kind kind = lvalue_kind (ref);
365 : 35690214 : if (kind & (clk_rvalueref|clk_class))
366 : : return clk_none;
367 : : else
368 : 34010752 : return kind;
369 : : }
370 : :
371 : : /* c-common wants us to return bool. */
372 : :
373 : : bool
374 : 35271828 : lvalue_p (const_tree t)
375 : : {
376 : 35271828 : return real_lvalue_p (t);
377 : : }
378 : :
379 : : /* This differs from lvalue_p in that xvalues are included. */
380 : :
381 : : bool
382 : 120621662 : glvalue_p (const_tree ref)
383 : : {
384 : 120621662 : cp_lvalue_kind kind = lvalue_kind (ref);
385 : 120621662 : if (kind & clk_class)
386 : : return false;
387 : : else
388 : 118895548 : return (kind != clk_none);
389 : : }
390 : :
391 : : /* This differs from glvalue_p in that class prvalues are included. */
392 : :
393 : : bool
394 : 950209297 : obvalue_p (const_tree ref)
395 : : {
396 : 950209297 : 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 : 5206838 : xvalue_p (const_tree ref)
404 : : {
405 : 5206838 : return (lvalue_kind (ref) & clk_rvalueref);
406 : : }
407 : :
408 : : /* True if REF is a bit-field. */
409 : :
410 : : bool
411 : 165602841 : bitfield_p (const_tree ref)
412 : : {
413 : 165602841 : 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 : 4127402 : cp_stabilize_reference (tree ref)
431 : : {
432 : 4127402 : if (processing_template_decl)
433 : : /* As in cp_save_expr. */
434 : : return ref;
435 : :
436 : 3487455 : STRIP_ANY_LOCATION_WRAPPER (ref);
437 : 3487455 : 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 : 3487455 : 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 : 400040640 : builtin_valid_in_constant_expr_p (const_tree decl)
477 : : {
478 : 400040640 : STRIP_ANY_LOCATION_WRAPPER (decl);
479 : 400040640 : if (TREE_CODE (decl) != FUNCTION_DECL)
480 : : /* Not a function. */
481 : : return false;
482 : 176395956 : if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
483 : : {
484 : 143895816 : if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
485 : 139055 : 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 : 32500140 : 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 : 25340782 : build_target_expr (tree decl, tree value, tsubst_flags_t complain)
527 : : {
528 : 25340782 : tree t;
529 : 25340782 : tree type = TREE_TYPE (decl);
530 : :
531 : 25340782 : value = mark_rvalue_use (value);
532 : :
533 : 25340782 : 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 : 25340782 : if (CP_TYPE_CONST_NON_VOLATILE_P (type)
544 : 1560063 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
545 : 1390925 : && !VOID_TYPE_P (TREE_TYPE (value))
546 : 874351 : && !TYPE_HAS_MUTABLE_P (type)
547 : 26215127 : && reduced_constant_expression_p (value))
548 : 314313 : TREE_READONLY (decl) = true;
549 : :
550 : 25340782 : 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 : 25008657 : t = cxx_maybe_build_cleanup (decl, complain);
556 : 25008657 : if (t == error_mark_node)
557 : : return error_mark_node;
558 : : }
559 : :
560 : 25340752 : set_target_expr_eliding (value);
561 : :
562 : 25340752 : t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
563 : 25340752 : if (location_t eloc = cp_expr_location (value))
564 : 16180565 : 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 : 25340752 : TREE_SIDE_EFFECTS (t) = 1;
570 : :
571 : 25340752 : 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 : 28151294 : build_local_temp (tree type)
579 : : {
580 : 28151294 : tree slot = build_decl (input_location,
581 : : VAR_DECL, NULL_TREE, type);
582 : 28151294 : DECL_ARTIFICIAL (slot) = 1;
583 : 28151294 : DECL_IGNORED_P (slot) = 1;
584 : 28151294 : DECL_CONTEXT (slot) = current_function_decl;
585 : 28151294 : layout_decl (slot, 0);
586 : 28151294 : 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 : 275458 : is_local_temp (tree decl)
594 : : {
595 : 275458 : return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
596 : 276215 : && !TREE_STATIC (decl));
597 : : }
598 : :
599 : : /* Set various status flags when building an AGGR_INIT_EXPR object T. */
600 : :
601 : : static void
602 : 8415451 : process_aggr_init_operands (tree t)
603 : : {
604 : 8415451 : bool side_effects;
605 : :
606 : 8415451 : side_effects = TREE_SIDE_EFFECTS (t);
607 : 8415451 : if (!side_effects)
608 : : {
609 : 8415451 : int i, n;
610 : 8415451 : n = TREE_OPERAND_LENGTH (t);
611 : 37314061 : for (i = 1; i < n; i++)
612 : : {
613 : 31232318 : tree op = TREE_OPERAND (t, i);
614 : 31232318 : if (op && TREE_SIDE_EFFECTS (op))
615 : : {
616 : : side_effects = 1;
617 : : break;
618 : : }
619 : : }
620 : : }
621 : 8415451 : TREE_SIDE_EFFECTS (t) = side_effects;
622 : 8415451 : }
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 : 8415451 : build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
630 : : tree *args)
631 : : {
632 : 8415451 : tree t;
633 : 8415451 : int i;
634 : :
635 : 8415451 : t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
636 : 8415451 : TREE_TYPE (t) = return_type;
637 : 8415451 : AGGR_INIT_EXPR_FN (t) = fn;
638 : 8415451 : AGGR_INIT_EXPR_SLOT (t) = slot;
639 : 23846862 : for (i = 0; i < nargs; i++)
640 : 15431411 : AGGR_INIT_EXPR_ARG (t, i) = args[i];
641 : 8415451 : process_aggr_init_operands (t);
642 : 8415451 : 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 : 28069818 : build_aggr_init_expr (tree type, tree init)
657 : : {
658 : 28069818 : tree fn;
659 : 28069818 : tree slot;
660 : 28069818 : tree rval;
661 : 28069818 : int is_ctor;
662 : :
663 : 28069818 : gcc_assert (!VOID_TYPE_P (type));
664 : :
665 : : /* Don't build AGGR_INIT_EXPR in a template. */
666 : 28069818 : if (processing_template_decl)
667 : : return init;
668 : :
669 : 27990464 : fn = cp_get_callee (init);
670 : 27990464 : if (fn == NULL_TREE)
671 : 11957045 : return convert (type, init);
672 : :
673 : 33211139 : is_ctor = (TREE_CODE (fn) == ADDR_EXPR
674 : 15976024 : && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
675 : 47985467 : && 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 : 8762269 : if (is_ctor || TREE_ADDRESSABLE (type))
689 : : {
690 : 8415451 : slot = build_local_temp (type);
691 : :
692 : 8415451 : if (TREE_CODE (init) == CALL_EXPR)
693 : : {
694 : 32350740 : rval = build_aggr_init_array (void_type_node, fn, slot,
695 : 8087685 : call_expr_nargs (init),
696 : 8087685 : CALL_EXPR_ARGP (init));
697 : 8087685 : AGGR_INIT_FROM_THUNK_P (rval)
698 : 8087685 : = CALL_FROM_THUNK_P (init);
699 : : }
700 : : else
701 : : {
702 : 327766 : rval = build_aggr_init_array (void_type_node, fn, slot,
703 : 327766 : aggr_init_expr_nargs (init),
704 : 327766 : AGGR_INIT_EXPR_ARGP (init));
705 : 327766 : AGGR_INIT_FROM_THUNK_P (rval)
706 : 327766 : = AGGR_INIT_FROM_THUNK_P (init);
707 : : }
708 : 8415451 : TREE_SIDE_EFFECTS (rval) = 1;
709 : 8415451 : AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
710 : 8415451 : TREE_NOTHROW (rval) = TREE_NOTHROW (init);
711 : 8415451 : CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
712 : 8415451 : CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
713 : 8415451 : CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
714 : 8415451 : 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 : 24530754 : 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 : 24530754 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
737 : : {
738 : 211 : gcc_assert (cxx_dialect >= cxx20);
739 : 211 : return finish_compound_literal (type, init, complain);
740 : : }
741 : :
742 : 24530543 : tree rval = build_aggr_init_expr (type, init);
743 : 24530543 : tree slot;
744 : :
745 : 24530543 : if (init == error_mark_node)
746 : : return error_mark_node;
747 : :
748 : 24528590 : 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 : 24528584 : if (abstract_virtuals_error (NULL_TREE, type, complain))
754 : 15 : return error_mark_node;
755 : :
756 : 24528569 : if (TREE_CODE (rval) == AGGR_INIT_EXPR)
757 : 5115349 : slot = AGGR_INIT_EXPR_SLOT (rval);
758 : 19413220 : else if (TREE_CODE (rval) == CALL_EXPR
759 : 11715907 : || TREE_CODE (rval) == CONSTRUCTOR)
760 : 7697330 : slot = build_local_temp (type);
761 : : else
762 : : return rval;
763 : :
764 : 12812679 : rval = build_target_expr (slot, rval, complain);
765 : :
766 : 12812679 : if (rval != error_mark_node)
767 : 12812679 : 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 : 1137 : build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
785 : : {
786 : 1137 : tree inner_type = strip_array_types (type);
787 : :
788 : 1137 : if (integer_zerop (array_type_nelts_total (type))
789 : 1137 : || !CLASS_TYPE_P (inner_type))
790 : : /* No interesting initialization to do. */
791 : 220 : return integer_zero_node;
792 : 917 : 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 : 116 : 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 : 82 : init = void_type_node;
804 : : }
805 : 883 : if (init == void_type_node)
806 : 111 : return build_value_init (inner_type, complain);
807 : :
808 : 772 : releasing_vec argvec;
809 : 772 : 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 : 772 : 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 : 772 : if (TREE_CODE (init) == TARGET_EXPR)
824 : 32 : init = TARGET_EXPR_INITIAL (init);
825 : :
826 : 772 : return init;
827 : 772 : }
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 : 1150 : build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
835 : : {
836 : 1150 : if (tree vi = get_vec_init_expr (init))
837 : : return vi;
838 : :
839 : 1138 : tree elt_init;
840 : 554 : if (init && TREE_CODE (init) == CONSTRUCTOR
841 : 1258 : && !BRACE_ENCLOSED_INITIALIZER_P (init))
842 : : /* We built any needed constructor calls in digest_init. */
843 : : elt_init = init;
844 : : else
845 : 1134 : elt_init = build_vec_init_elt (type, init, complain);
846 : :
847 : 1138 : bool value_init = false;
848 : 1138 : if (init == void_type_node)
849 : : {
850 : 227 : value_init = true;
851 : 227 : init = NULL_TREE;
852 : : }
853 : :
854 : 1138 : tree slot = build_local_temp (type);
855 : 1138 : init = build2 (VEC_INIT_EXPR, type, slot, init);
856 : 1138 : TREE_SIDE_EFFECTS (init) = true;
857 : 1138 : SET_EXPR_LOCATION (init, input_location);
858 : :
859 : 1138 : if (cxx_dialect >= cxx11)
860 : : {
861 : 1075 : bool cx = potential_constant_expression (elt_init);
862 : 1075 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
863 : 0 : cx &= potential_constant_expression (init);
864 : 1075 : VEC_INIT_EXPR_IS_CONSTEXPR (init) = cx;
865 : : }
866 : 1138 : VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
867 : :
868 : 1138 : 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 : 1154 : expand_vec_init_expr (tree target, tree vec_init, tsubst_flags_t complain,
876 : : vec<tree,va_gc> **flags)
877 : : {
878 : 1154 : iloc_sentinel ils = EXPR_LOCATION (vec_init);
879 : :
880 : 1154 : if (!target)
881 : 0 : target = VEC_INIT_EXPR_SLOT (vec_init);
882 : 1154 : tree init = VEC_INIT_EXPR_INIT (vec_init);
883 : 1154 : int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
884 : 3462 : return build_vec_init (target, NULL_TREE, init,
885 : 1154 : VEC_INIT_EXPR_VALUE_INIT (vec_init),
886 : 1154 : from_array, complain, flags);
887 : 1154 : }
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 : 7285602 : build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
918 : : {
919 : 7285602 : gcc_assert (!VOID_TYPE_P (type));
920 : 7285602 : gcc_assert (!VOID_TYPE_P (TREE_TYPE (init)));
921 : :
922 : 7285602 : if (TREE_CODE (init) == TARGET_EXPR
923 : 6674282 : || init == error_mark_node)
924 : : return init;
925 : 4805142 : else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
926 : 61276 : && TREE_CODE (init) != COND_EXPR
927 : : && TREE_CODE (init) != CONSTRUCTOR
928 : : && TREE_CODE (init) != VA_ARG_EXPR
929 : 6674005 : && 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 : 6674005 : 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 : 12037352 : force_target_expr (tree type, tree init, tsubst_flags_t complain)
948 : : {
949 : 12037352 : tree slot;
950 : :
951 : 12037352 : gcc_assert (!VOID_TYPE_P (type));
952 : :
953 : 12037352 : slot = build_local_temp (type);
954 : 12037352 : 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 : 5812976 : get_target_expr (tree init, tsubst_flags_t complain /* = tf_warning_or_error */)
961 : : {
962 : 5812976 : if (TREE_CODE (init) == AGGR_INIT_EXPR)
963 : 490466 : return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
964 : 5322510 : else if (TREE_CODE (init) == VEC_INIT_EXPR)
965 : 285 : return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
966 : : else
967 : : {
968 : 5322225 : init = convert_bitfield_to_declared_type (init);
969 : 5322225 : 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 : 1518149 : get_internal_target_expr (tree init)
984 : : {
985 : 1518149 : init = convert_bitfield_to_declared_type (init);
986 : 1518149 : tree t = force_target_expr (TREE_TYPE (init), init, tf_warning_or_error);
987 : 1518149 : TARGET_EXPR_INTERNAL_P (t) = true;
988 : 1518149 : 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 : 849685963 : convert_bitfield_to_declared_type (tree expr)
997 : : {
998 : 849685963 : tree bitfield_type;
999 : :
1000 : 849685963 : bitfield_type = is_bitfield_expr_with_lowered_type (expr);
1001 : 849685963 : if (bitfield_type)
1002 : 575535 : expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
1003 : : expr);
1004 : 849685963 : 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 : 154839320 : rvalue (tree expr)
1012 : : {
1013 : 154839320 : tree type;
1014 : :
1015 : 154839320 : if (error_operand_p (expr))
1016 : : return expr;
1017 : :
1018 : 154839046 : 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 : 154839046 : type = TREE_TYPE (expr);
1024 : 154839046 : if (!CLASS_TYPE_P (type) && TREE_CODE (type) != ARRAY_TYPE
1025 : 307954137 : && cv_qualified_p (type))
1026 : 31928241 : 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 : 154839046 : 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 : 7793769 : gcc_checking_assert (!CLASS_TYPE_P (type));
1035 : 7793769 : expr = build1 (NON_LVALUE_EXPR, type, expr);
1036 : : }
1037 : 147045277 : else if (type != TREE_TYPE (expr))
1038 : 31681057 : 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 : 30992440 : cplus_array_hasher::hash (tree t)
1062 : : {
1063 : 30992440 : hashval_t hash;
1064 : :
1065 : 30992440 : hash = TYPE_UID (TREE_TYPE (t));
1066 : 30992440 : if (TYPE_DOMAIN (t))
1067 : 28510197 : hash ^= TYPE_UID (TYPE_DOMAIN (t));
1068 : 30992440 : 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 : 36651027 : cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
1076 : : {
1077 : 38843725 : 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 : 4248584 : build_min_array_type (tree elt_type, tree index_type)
1088 : : {
1089 : 4248584 : tree t = cxx_make_type (ARRAY_TYPE);
1090 : 4248584 : TREE_TYPE (t) = elt_type;
1091 : 4248584 : TYPE_DOMAIN (t) = index_type;
1092 : 4248584 : 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 : 4248584 : 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 : 4248584 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
1103 : 4248584 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
1104 : 985338 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1105 : 3263246 : else if (TYPE_CANONICAL (elt_type) != elt_type
1106 : 3263246 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
1107 : 893975 : TYPE_CANONICAL (t)
1108 : 2325487 : = build_cplus_array_type (TYPE_CANONICAL (elt_type),
1109 : : index_type
1110 : 537537 : ? TYPE_CANONICAL (index_type) : index_type,
1111 : : dep);
1112 : : else
1113 : 2369271 : TYPE_CANONICAL (t) = t;
1114 : 4248584 : }
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 : 54439961 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
1123 : : {
1124 : 54439961 : tree t;
1125 : :
1126 : 54439961 : if (elt_type == error_mark_node || index_type == error_mark_node)
1127 : : return error_mark_node;
1128 : :
1129 : 54439958 : if (dependent < 0)
1130 : 56453692 : dependent = (uses_template_parms (elt_type)
1131 : 28226846 : || (index_type && uses_template_parms (index_type)));
1132 : :
1133 : 54439958 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1134 : : /* Start with an array of the TYPE_MAIN_VARIANT. */
1135 : 23500176 : t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
1136 : : index_type, dependent);
1137 : 30939782 : else if (dependent)
1138 : : {
1139 : : /* Since type_hash_canon calls layout_type, we need to use our own
1140 : : hash table. */
1141 : 3590343 : cplus_array_info cai;
1142 : 3590343 : hashval_t hash;
1143 : :
1144 : 3590343 : if (cplus_array_htab == NULL)
1145 : 16891 : cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61);
1146 : :
1147 : 3590343 : hash = TYPE_UID (elt_type);
1148 : 3590343 : if (index_type)
1149 : 1919632 : hash ^= TYPE_UID (index_type);
1150 : 3590343 : cai.type = elt_type;
1151 : 3590343 : cai.domain = index_type;
1152 : :
1153 : 3590343 : tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
1154 : 3590343 : if (*e)
1155 : : /* We have found the type: we're done. */
1156 : 2120249 : return (tree) *e;
1157 : : else
1158 : : {
1159 : : /* Build a new array type. */
1160 : 1470094 : t = build_min_array_type (elt_type, index_type);
1161 : :
1162 : : /* Store it in the hash table. */
1163 : 1470094 : *e = t;
1164 : :
1165 : : /* Set the canonical type for this new node. */
1166 : 1470094 : set_array_type_canon (t, elt_type, index_type, dependent);
1167 : :
1168 : : /* Mark it as dependent now, this saves time later. */
1169 : 1470094 : TYPE_DEPENDENT_P_VALID (t) = true;
1170 : 1470094 : TYPE_DEPENDENT_P (t) = true;
1171 : : }
1172 : : }
1173 : : else
1174 : : {
1175 : 27349439 : bool typeless_storage = is_byte_access_type (elt_type);
1176 : 27349439 : t = build_array_type (elt_type, index_type, typeless_storage);
1177 : :
1178 : : /* Mark as non-dependenty now, this will save time later. */
1179 : 27349439 : TYPE_DEPENDENT_P_VALID (t) = true;
1180 : : }
1181 : :
1182 : : /* Now check whether we already have this array variant. */
1183 : 52319709 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1184 : : {
1185 : : tree m = t;
1186 : 47535310 : for (t = m; t; t = TYPE_NEXT_VARIANT (t))
1187 : 44756820 : if (TREE_TYPE (t) == elt_type
1188 : 20735315 : && TYPE_NAME (t) == NULL_TREE
1189 : 65478506 : && TYPE_ATTRIBUTES (t) == NULL_TREE)
1190 : : break;
1191 : 23500176 : if (!t)
1192 : : {
1193 : 2778490 : t = build_min_array_type (elt_type, index_type);
1194 : : /* Mark dependency now, this saves time later. */
1195 : 2778490 : TYPE_DEPENDENT_P_VALID (t) = true;
1196 : 2778490 : TYPE_DEPENDENT_P (t) = dependent;
1197 : 2778490 : set_array_type_canon (t, elt_type, index_type, dependent);
1198 : 2778490 : if (!dependent)
1199 : : {
1200 : 2323579 : layout_type (t);
1201 : : /* Make sure sizes are shared with the main variant.
1202 : : layout_type can't be called after setting TYPE_NEXT_VARIANT,
1203 : : as it will overwrite alignment etc. of all variants. */
1204 : 2323579 : TYPE_SIZE (t) = TYPE_SIZE (m);
1205 : 2323579 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
1206 : 2323579 : TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
1207 : : }
1208 : :
1209 : 2778490 : TYPE_MAIN_VARIANT (t) = m;
1210 : 2778490 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
1211 : 2778490 : TYPE_NEXT_VARIANT (m) = t;
1212 : : }
1213 : : }
1214 : :
1215 : : /* Avoid spurious warnings with VLAs (c++/54583). */
1216 : 52319709 : if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
1217 : 1788 : suppress_warning (TYPE_SIZE (t), OPT_Wunused);
1218 : :
1219 : : /* Push these needs up to the ARRAY_TYPE so that initialization takes
1220 : : place more easily. */
1221 : 104639418 : bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t)
1222 : 52319709 : = TYPE_NEEDS_CONSTRUCTING (elt_type));
1223 : 104639418 : bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1224 : 52319709 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
1225 : :
1226 : 50252564 : if (!dependent && t == TYPE_MAIN_VARIANT (t)
1227 : 79669148 : && !COMPLETE_TYPE_P (t) && COMPLETE_TYPE_P (elt_type))
1228 : : {
1229 : : /* The element type has been completed since the last time we saw
1230 : : this array type; update the layout and 'tor flags for any variants
1231 : : that need it. */
1232 : 1506353 : layout_type (t);
1233 : 2506372 : for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
1234 : : {
1235 : 1000019 : TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
1236 : 1000019 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (v) = needs_dtor;
1237 : : }
1238 : : }
1239 : :
1240 : : return t;
1241 : : }
1242 : :
1243 : : /* Return an ARRAY_TYPE with element type ELT and length N. */
1244 : :
1245 : : tree
1246 : 2128339 : build_array_of_n_type (tree elt, unsigned HOST_WIDE_INT n)
1247 : : {
1248 : 2128339 : return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
1249 : : }
1250 : :
1251 : : /* True iff T is an array of unknown bound. */
1252 : :
1253 : : bool
1254 : 5852146 : array_of_unknown_bound_p (const_tree t)
1255 : : {
1256 : 5852146 : return (TREE_CODE (t) == ARRAY_TYPE
1257 : 5852146 : && !TYPE_DOMAIN (t));
1258 : : }
1259 : :
1260 : : /* True iff T is an N3639 array of runtime bound (VLA). These were approved
1261 : : for C++14 but then removed. This should only be used for N3639
1262 : : specifically; code wondering more generally if something is a VLA should use
1263 : : vla_type_p. */
1264 : :
1265 : : bool
1266 : 307245 : array_of_runtime_bound_p (tree t)
1267 : : {
1268 : 307245 : if (!t || TREE_CODE (t) != ARRAY_TYPE)
1269 : : return false;
1270 : 259 : if (variably_modified_type_p (TREE_TYPE (t), NULL_TREE))
1271 : : return false;
1272 : 247 : tree dom = TYPE_DOMAIN (t);
1273 : 247 : if (!dom)
1274 : : return false;
1275 : 244 : tree max = TYPE_MAX_VALUE (dom);
1276 : 244 : return (!potential_rvalue_constant_expression (max)
1277 : 244 : || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)));
1278 : : }
1279 : :
1280 : : /* True iff T is a variable length array. */
1281 : :
1282 : : bool
1283 : 29044959 : vla_type_p (tree t)
1284 : : {
1285 : 29714833 : for (; t && TREE_CODE (t) == ARRAY_TYPE;
1286 : 669874 : t = TREE_TYPE (t))
1287 : 670051 : if (tree dom = TYPE_DOMAIN (t))
1288 : : {
1289 : 669987 : tree max = TYPE_MAX_VALUE (dom);
1290 : 669987 : if (!potential_rvalue_constant_expression (max)
1291 : 669987 : || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)))
1292 : 177 : return true;
1293 : : }
1294 : : return false;
1295 : : }
1296 : :
1297 : :
1298 : : /* Return a reference type node of MODE referring to TO_TYPE. If MODE
1299 : : is VOIDmode the standard pointer mode will be picked. If RVAL is
1300 : : true, return an rvalue reference type, otherwise return an lvalue
1301 : : reference type. If a type node exists, reuse it, otherwise create
1302 : : a new one. */
1303 : : tree
1304 : 458095151 : cp_build_reference_type_for_mode (tree to_type, machine_mode mode, bool rval)
1305 : : {
1306 : 458095151 : tree lvalue_ref, t;
1307 : :
1308 : 458095151 : if (to_type == error_mark_node)
1309 : : return error_mark_node;
1310 : :
1311 : 458095146 : if (TYPE_REF_P (to_type))
1312 : : {
1313 : 1197 : rval = rval && TYPE_REF_IS_RVALUE (to_type);
1314 : 1197 : to_type = TREE_TYPE (to_type);
1315 : : }
1316 : :
1317 : 458095146 : lvalue_ref = build_reference_type_for_mode (to_type, mode, false);
1318 : :
1319 : 458095146 : if (!rval)
1320 : : return lvalue_ref;
1321 : :
1322 : : /* This code to create rvalue reference types is based on and tied
1323 : : to the code creating lvalue reference types in the middle-end
1324 : : functions build_reference_type_for_mode and build_reference_type.
1325 : :
1326 : : It works by putting the rvalue reference type nodes after the
1327 : : lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
1328 : : they will effectively be ignored by the middle end. */
1329 : :
1330 : 81908009 : for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
1331 : 59628860 : if (TYPE_REF_IS_RVALUE (t))
1332 : : return t;
1333 : :
1334 : 22279149 : t = build_distinct_type_copy (lvalue_ref);
1335 : :
1336 : 22279149 : TYPE_REF_IS_RVALUE (t) = true;
1337 : 22279149 : TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
1338 : 22279149 : TYPE_NEXT_REF_TO (lvalue_ref) = t;
1339 : :
1340 : 22279149 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
1341 : 763191 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1342 : 21515958 : else if (TYPE_CANONICAL (to_type) != to_type)
1343 : 12655640 : TYPE_CANONICAL (t)
1344 : 25311280 : = cp_build_reference_type_for_mode (TYPE_CANONICAL (to_type), mode, rval);
1345 : : else
1346 : 8860318 : TYPE_CANONICAL (t) = t;
1347 : :
1348 : 22279149 : layout_type (t);
1349 : :
1350 : 22279149 : return t;
1351 : :
1352 : : }
1353 : :
1354 : : /* Return a reference type node referring to TO_TYPE. If RVAL is
1355 : : true, return an rvalue reference type, otherwise return an lvalue
1356 : : reference type. If a type node exists, reuse it, otherwise create
1357 : : a new one. */
1358 : : tree
1359 : 396009113 : cp_build_reference_type (tree to_type, bool rval)
1360 : : {
1361 : 396009113 : return cp_build_reference_type_for_mode (to_type, VOIDmode, rval);
1362 : : }
1363 : :
1364 : : /* Returns EXPR cast to rvalue reference type, like std::move. */
1365 : :
1366 : : tree
1367 : 1513187 : move (tree expr)
1368 : : {
1369 : 1513187 : tree type = TREE_TYPE (expr);
1370 : 1513187 : gcc_assert (!TYPE_REF_P (type));
1371 : 1513187 : if (xvalue_p (expr))
1372 : : return expr;
1373 : 1513055 : type = cp_build_reference_type (type, /*rval*/true);
1374 : 1513055 : return build_static_cast (input_location, type, expr,
1375 : 1513055 : tf_warning_or_error);
1376 : : }
1377 : :
1378 : : /* Used by the C++ front end to build qualified array types. However,
1379 : : the C version of this function does not properly maintain canonical
1380 : : types (which are not used in C). */
1381 : : tree
1382 : 22396821 : c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */,
1383 : : size_t /* orig_qual_indirect */)
1384 : : {
1385 : 22396821 : return cp_build_qualified_type (type, type_quals);
1386 : : }
1387 : :
1388 : :
1389 : : /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
1390 : : arrays correctly. In particular, if TYPE is an array of T's, and
1391 : : TYPE_QUALS is non-empty, returns an array of qualified T's.
1392 : :
1393 : : FLAGS determines how to deal with ill-formed qualifications. If
1394 : : tf_ignore_bad_quals is set, then bad qualifications are dropped
1395 : : (this is permitted if TYPE was introduced via a typedef or template
1396 : : type parameter). If bad qualifications are dropped and tf_warning
1397 : : is set, then a warning is issued for non-const qualifications. If
1398 : : tf_ignore_bad_quals is not set and tf_error is not set, we
1399 : : return error_mark_node. Otherwise, we issue an error, and ignore
1400 : : the qualifications.
1401 : :
1402 : : Qualification of a reference type is valid when the reference came
1403 : : via a typedef or template type argument. [dcl.ref] No such
1404 : : dispensation is provided for qualifying a function type. [dcl.fct]
1405 : : DR 295 queries this and the proposed resolution brings it into line
1406 : : with qualifying a reference. We implement the DR. We also behave
1407 : : in a similar manner for restricting non-pointer types. */
1408 : :
1409 : : tree
1410 : 13706153817 : cp_build_qualified_type (tree type, int type_quals,
1411 : : tsubst_flags_t complain /* = tf_warning_or_error */)
1412 : : {
1413 : 13706153817 : tree result;
1414 : 13706153817 : int bad_quals = TYPE_UNQUALIFIED;
1415 : :
1416 : 13706153817 : if (type == error_mark_node)
1417 : : return type;
1418 : :
1419 : 13676476412 : if (type_quals == cp_type_quals (type))
1420 : : return type;
1421 : :
1422 : 2339249006 : if (TREE_CODE (type) == ARRAY_TYPE)
1423 : : {
1424 : : /* In C++, the qualification really applies to the array element
1425 : : type. Obtain the appropriately qualified element type. */
1426 : 25871249 : tree t;
1427 : 25871249 : tree element_type
1428 : 25871249 : = cp_build_qualified_type (TREE_TYPE (type), type_quals, complain);
1429 : :
1430 : 25871249 : if (element_type == error_mark_node)
1431 : : return error_mark_node;
1432 : :
1433 : : /* See if we already have an identically qualified type. Tests
1434 : : should be equivalent to those in check_qualified_type. */
1435 : 49072128 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1436 : 27292708 : if (TREE_TYPE (t) == element_type
1437 : 4131899 : && TYPE_NAME (t) == TYPE_NAME (type)
1438 : 4091829 : && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
1439 : 31384537 : && attribute_list_equal (TYPE_ATTRIBUTES (t),
1440 : 4091829 : TYPE_ATTRIBUTES (type)))
1441 : : break;
1442 : :
1443 : 25871249 : if (!t)
1444 : : {
1445 : : /* If we already know the dependentness, tell the array type
1446 : : constructor. This is important for module streaming, as we cannot
1447 : : dynamically determine that on read in. */
1448 : 21779420 : t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
1449 : 21779420 : TYPE_DEPENDENT_P_VALID (type)
1450 : 381141 : ? int (TYPE_DEPENDENT_P (type)) : -1);
1451 : :
1452 : : /* Keep the typedef name. */
1453 : 21779420 : if (TYPE_NAME (t) != TYPE_NAME (type))
1454 : : {
1455 : 9170 : t = build_variant_type_copy (t);
1456 : 9170 : TYPE_NAME (t) = TYPE_NAME (type);
1457 : 9170 : SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
1458 : 9170 : TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
1459 : : }
1460 : : }
1461 : :
1462 : : /* Even if we already had this variant, we update
1463 : : TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
1464 : : they changed since the variant was originally created.
1465 : :
1466 : : This seems hokey; if there is some way to use a previous
1467 : : variant *without* coming through here,
1468 : : TYPE_NEEDS_CONSTRUCTING will never be updated. */
1469 : 51742498 : TYPE_NEEDS_CONSTRUCTING (t)
1470 : 25871249 : = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
1471 : 51742498 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1472 : 25871249 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
1473 : 25871249 : return t;
1474 : : }
1475 : 2313377757 : else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
1476 : : {
1477 : 3 : tree t = PACK_EXPANSION_PATTERN (type);
1478 : :
1479 : 3 : t = cp_build_qualified_type (t, type_quals, complain);
1480 : 3 : return make_pack_expansion (t, complain);
1481 : : }
1482 : :
1483 : : /* A reference or method type shall not be cv-qualified.
1484 : : [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
1485 : : (in CD1) we always ignore extra cv-quals on functions. */
1486 : :
1487 : : /* [dcl.ref/1] Cv-qualified references are ill-formed except when
1488 : : the cv-qualifiers are introduced through the use of a typedef-name
1489 : : ([dcl.typedef], [temp.param]) or decltype-specifier
1490 : : ([dcl.type.decltype]),in which case the cv-qualifiers are
1491 : : ignored. */
1492 : 2313377754 : if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
1493 : 834015835 : && (TYPE_REF_P (type)
1494 : 833743330 : || FUNC_OR_METHOD_TYPE_P (type)))
1495 : : {
1496 : 273224 : if (TYPE_REF_P (type)
1497 : 273224 : && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
1498 : : bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1499 : 273224 : type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1500 : : }
1501 : :
1502 : : /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1503 : 2313377754 : if (TREE_CODE (type) == FUNCTION_TYPE)
1504 : 722 : type_quals |= type_memfn_quals (type);
1505 : :
1506 : : /* A restrict-qualified type must be a pointer (or reference)
1507 : : to object or incomplete type. */
1508 : 2313377754 : if ((type_quals & TYPE_QUAL_RESTRICT)
1509 : 8502961 : && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1510 : 8502924 : && TREE_CODE (type) != TYPENAME_TYPE
1511 : 8502918 : && !INDIRECT_TYPE_P (type))
1512 : : {
1513 : 25 : bad_quals |= TYPE_QUAL_RESTRICT;
1514 : 25 : type_quals &= ~TYPE_QUAL_RESTRICT;
1515 : : }
1516 : :
1517 : 2313377754 : if (bad_quals == TYPE_UNQUALIFIED
1518 : 209302 : || (complain & tf_ignore_bad_quals))
1519 : : /*OK*/;
1520 : 12 : else if (!(complain & tf_error))
1521 : 0 : return error_mark_node;
1522 : : else
1523 : : {
1524 : 12 : tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
1525 : 12 : error ("%qV qualifiers cannot be applied to %qT",
1526 : : bad_type, type);
1527 : : }
1528 : :
1529 : : /* Retrieve (or create) the appropriately qualified variant. */
1530 : 2313377754 : result = build_qualified_type (type, type_quals);
1531 : :
1532 : 2313377754 : return result;
1533 : : }
1534 : :
1535 : : /* Return TYPE with const and volatile removed. */
1536 : :
1537 : : tree
1538 : 1258037130 : cv_unqualified (tree type)
1539 : : {
1540 : 1258037130 : int quals;
1541 : :
1542 : 1258037130 : if (type == error_mark_node)
1543 : : return type;
1544 : :
1545 : 1258036941 : quals = cp_type_quals (type);
1546 : 1258036941 : quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
1547 : 1258036941 : return cp_build_qualified_type (type, quals);
1548 : : }
1549 : :
1550 : : /* Subroutine of strip_typedefs. We want to apply to RESULT the attributes
1551 : : from ATTRIBS that affect type identity, and no others. If any are not
1552 : : applied, set *remove_attributes to true. */
1553 : :
1554 : : static tree
1555 : 4942620 : apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
1556 : : {
1557 : 4942620 : tree first_ident = NULL_TREE;
1558 : 4942620 : tree new_attribs = NULL_TREE;
1559 : 4942620 : tree *p = &new_attribs;
1560 : :
1561 : 4942620 : if (OVERLOAD_TYPE_P (result))
1562 : : {
1563 : : /* On classes and enums all attributes are ingrained. */
1564 : 4941674 : gcc_assert (attribs == TYPE_ATTRIBUTES (result));
1565 : : return result;
1566 : : }
1567 : :
1568 : 1895 : for (tree a = attribs; a; a = TREE_CHAIN (a))
1569 : : {
1570 : 949 : const attribute_spec *as
1571 : 949 : = lookup_attribute_spec (get_attribute_name (a));
1572 : 949 : if (as && as->affects_type_identity)
1573 : : {
1574 : 349 : if (!first_ident)
1575 : : first_ident = a;
1576 : 0 : else if (first_ident == error_mark_node)
1577 : : {
1578 : 0 : *p = tree_cons (TREE_PURPOSE (a), TREE_VALUE (a), NULL_TREE);
1579 : 0 : p = &TREE_CHAIN (*p);
1580 : : }
1581 : : }
1582 : 600 : else if (first_ident && first_ident != error_mark_node)
1583 : : {
1584 : 0 : for (tree a2 = first_ident; a2 != a; a2 = TREE_CHAIN (a2))
1585 : : {
1586 : 0 : *p = tree_cons (TREE_PURPOSE (a2), TREE_VALUE (a2), NULL_TREE);
1587 : 0 : p = &TREE_CHAIN (*p);
1588 : : }
1589 : 0 : first_ident = error_mark_node;
1590 : : }
1591 : : }
1592 : 946 : if (first_ident != error_mark_node)
1593 : 946 : new_attribs = first_ident;
1594 : :
1595 : 946 : if (first_ident == attribs)
1596 : : /* All attributes affected type identity. */;
1597 : : else
1598 : 597 : *remove_attributes = true;
1599 : :
1600 : 946 : return cp_build_type_attribute_variant (result, new_attribs);
1601 : : }
1602 : :
1603 : : /* Builds a qualified variant of T that is either not a typedef variant
1604 : : (the default behavior) or not a typedef variant of a user-facing type
1605 : : (if FLAGS contains STF_USER_VISIBLE). If T is not a type, then this
1606 : : just dispatches to strip_typedefs_expr.
1607 : :
1608 : : E.g. consider the following declarations:
1609 : : typedef const int ConstInt;
1610 : : typedef ConstInt* PtrConstInt;
1611 : : If T is PtrConstInt, this function returns a type representing
1612 : : const int*.
1613 : : In other words, if T is a typedef, the function returns the underlying type.
1614 : : The cv-qualification and attributes of the type returned match the
1615 : : input type.
1616 : : They will always be compatible types.
1617 : : The returned type is built so that all of its subtypes
1618 : : recursively have their typedefs stripped as well.
1619 : :
1620 : : This is different from just returning TYPE_CANONICAL (T)
1621 : : Because of several reasons:
1622 : : * If T is a type that needs structural equality
1623 : : its TYPE_CANONICAL (T) will be NULL.
1624 : : * TYPE_CANONICAL (T) desn't carry type attributes
1625 : : and loses template parameter names.
1626 : :
1627 : : If REMOVE_ATTRIBUTES is non-null, also strip attributes that don't
1628 : : affect type identity, and set the referent to true if any were
1629 : : stripped. */
1630 : :
1631 : : tree
1632 : 2206430147 : strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
1633 : : unsigned int flags /* = 0 */)
1634 : : {
1635 : 2206430147 : tree result = NULL, type = NULL, t0 = NULL;
1636 : :
1637 : 2206430147 : if (!t || t == error_mark_node)
1638 : : return t;
1639 : :
1640 : 2178508279 : if (!TYPE_P (t))
1641 : 149073599 : return strip_typedefs_expr (t, remove_attributes, flags);
1642 : :
1643 : 2029434680 : if (t == TYPE_CANONICAL (t))
1644 : : return t;
1645 : :
1646 : 732601484 : if (typedef_variant_p (t))
1647 : : {
1648 : 210626439 : if ((flags & STF_USER_VISIBLE)
1649 : 210626439 : && !user_facing_original_type_p (t))
1650 : : return t;
1651 : :
1652 : 210626331 : if ((flags & STF_KEEP_INJ_CLASS_NAME)
1653 : 38729 : && CLASS_TYPE_P (t)
1654 : 210636291 : && DECL_SELF_REFERENCE_P (TYPE_NAME (t)))
1655 : : return t;
1656 : :
1657 : 210626330 : if (dependent_opaque_alias_p (t))
1658 : : return t;
1659 : :
1660 : 210626229 : if (alias_template_specialization_p (t, nt_opaque))
1661 : : {
1662 : 56265769 : if (dependent_alias_template_spec_p (t, nt_opaque)
1663 : 56265769 : && !(flags & STF_STRIP_DEPENDENT))
1664 : : /* DR 1558: However, if the template-id is dependent, subsequent
1665 : : template argument substitution still applies to the template-id. */
1666 : : return t;
1667 : : }
1668 : : else
1669 : : /* If T is a non-template alias or typedef, we can assume that
1670 : : instantiating its definition will hit any substitution failure,
1671 : : so we don't need to retain it here as well. */
1672 : 154360460 : flags |= STF_STRIP_DEPENDENT;
1673 : :
1674 : 203320762 : result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
1675 : : remove_attributes, flags);
1676 : 203320762 : goto stripped;
1677 : : }
1678 : :
1679 : 521975045 : switch (TREE_CODE (t))
1680 : : {
1681 : 10259197 : case POINTER_TYPE:
1682 : 10259197 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1683 : 10259197 : result = build_pointer_type_for_mode (type, TYPE_MODE (t), false);
1684 : 10259197 : break;
1685 : 49430398 : case REFERENCE_TYPE:
1686 : 49430398 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1687 : 49430398 : result = cp_build_reference_type_for_mode (type, TYPE_MODE (t), TYPE_REF_IS_RVALUE (t));
1688 : 49430398 : break;
1689 : 327394 : case OFFSET_TYPE:
1690 : 327394 : t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags);
1691 : 327394 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1692 : 327394 : result = build_offset_type (t0, type);
1693 : 327394 : break;
1694 : 22314188 : case RECORD_TYPE:
1695 : 22314188 : if (TYPE_PTRMEMFUNC_P (t))
1696 : : {
1697 : 1886505 : t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t),
1698 : : remove_attributes, flags);
1699 : 1886505 : result = build_ptrmemfunc_type (t0);
1700 : : }
1701 : : break;
1702 : 1421396 : case ARRAY_TYPE:
1703 : 1421396 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1704 : 1421396 : t0 = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags);
1705 : 1421396 : gcc_checking_assert (TYPE_DEPENDENT_P_VALID (t)
1706 : : || !dependent_type_p (t));
1707 : 1421396 : result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t));
1708 : 1421396 : break;
1709 : 4569109 : case FUNCTION_TYPE:
1710 : 4569109 : case METHOD_TYPE:
1711 : 4569109 : {
1712 : 4569109 : tree arg_types = NULL, arg_node, arg_node2, arg_type;
1713 : 4569109 : bool changed;
1714 : :
1715 : : /* Because we stomp on TREE_PURPOSE of TYPE_ARG_TYPES in many places
1716 : : around the compiler (e.g. cp_parser_late_parsing_default_args), we
1717 : : can't expect that re-hashing a function type will find a previous
1718 : : equivalent type, so try to reuse the input type if nothing has
1719 : : changed. If the type is itself a variant, that will change. */
1720 : 4569109 : bool is_variant = typedef_variant_p (t);
1721 : 4569109 : if (remove_attributes
1722 : 4569109 : && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t)))
1723 : : is_variant = true;
1724 : :
1725 : 4569109 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1726 : 4569109 : tree canon_spec = (flag_noexcept_type
1727 : 4538750 : ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t))
1728 : 4569109 : : NULL_TREE);
1729 : 7845652 : changed = (type != TREE_TYPE (t) || is_variant
1730 : 7845278 : || TYPE_RAISES_EXCEPTIONS (t) != canon_spec);
1731 : :
1732 : 4569109 : for (arg_node = TYPE_ARG_TYPES (t);
1733 : 10135466 : arg_node;
1734 : 5566357 : arg_node = TREE_CHAIN (arg_node))
1735 : : {
1736 : 9168084 : if (arg_node == void_list_node)
1737 : : break;
1738 : 5566357 : arg_type = strip_typedefs (TREE_VALUE (arg_node),
1739 : : remove_attributes, flags);
1740 : 5566357 : gcc_assert (arg_type);
1741 : 5566357 : if (arg_type == TREE_VALUE (arg_node) && !changed)
1742 : 5298748 : continue;
1743 : :
1744 : 267609 : if (!changed)
1745 : : {
1746 : 41056 : changed = true;
1747 : 41056 : for (arg_node2 = TYPE_ARG_TYPES (t);
1748 : 52476 : arg_node2 != arg_node;
1749 : 11420 : arg_node2 = TREE_CHAIN (arg_node2))
1750 : 11420 : arg_types
1751 : 11420 : = tree_cons (TREE_PURPOSE (arg_node2),
1752 : 11420 : TREE_VALUE (arg_node2), arg_types);
1753 : : }
1754 : :
1755 : 267609 : arg_types
1756 : 267609 : = tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
1757 : : }
1758 : :
1759 : 4569109 : if (!changed)
1760 : : return t;
1761 : :
1762 : 1334819 : if (arg_types)
1763 : 62541 : arg_types = nreverse (arg_types);
1764 : :
1765 : : /* A list of parameters not ending with an ellipsis
1766 : : must end with void_list_node. */
1767 : 1334819 : if (arg_node)
1768 : 1334772 : arg_types = chainon (arg_types, void_list_node);
1769 : :
1770 : 1334819 : if (TREE_CODE (t) == METHOD_TYPE)
1771 : : {
1772 : 29287 : tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
1773 : 29287 : gcc_assert (class_type);
1774 : 29287 : result =
1775 : 29287 : build_method_type_directly (class_type, type,
1776 : 29287 : TREE_CHAIN (arg_types));
1777 : : }
1778 : : else
1779 : : {
1780 : 1305532 : result = build_function_type (type, arg_types);
1781 : 1305532 : result = apply_memfn_quals (result, type_memfn_quals (t));
1782 : : }
1783 : :
1784 : 4004457 : result = build_cp_fntype_variant (result,
1785 : : type_memfn_rqual (t), canon_spec,
1786 : 1334819 : TYPE_HAS_LATE_RETURN_TYPE (t));
1787 : : }
1788 : 1334819 : break;
1789 : 46476758 : case TYPENAME_TYPE:
1790 : 46476758 : {
1791 : 46476758 : bool changed = false;
1792 : 46476758 : tree fullname = TYPENAME_TYPE_FULLNAME (t);
1793 : 46476758 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
1794 : 46476758 : && TREE_OPERAND (fullname, 1))
1795 : : {
1796 : 2646735 : tree args = TREE_OPERAND (fullname, 1);
1797 : 2646735 : tree new_args = copy_node (args);
1798 : 6935693 : for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
1799 : : {
1800 : 4288958 : tree arg = TREE_VEC_ELT (args, i);
1801 : 4288958 : tree strip_arg = strip_typedefs (arg, remove_attributes, flags);
1802 : 4288958 : TREE_VEC_ELT (new_args, i) = strip_arg;
1803 : 4288958 : if (strip_arg != arg)
1804 : 175403 : changed = true;
1805 : : }
1806 : 2646735 : if (changed)
1807 : : {
1808 : 175403 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
1809 : 175403 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
1810 : 175403 : fullname
1811 : 175403 : = lookup_template_function (TREE_OPERAND (fullname, 0),
1812 : : new_args);
1813 : : }
1814 : : else
1815 : 2471332 : ggc_free (new_args);
1816 : : }
1817 : 46476758 : tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes, flags);
1818 : 46476758 : if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t))
1819 : : return t;
1820 : 4111123 : tree name = fullname;
1821 : 4111123 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
1822 : 192551 : name = TREE_OPERAND (fullname, 0);
1823 : : /* Use build_typename_type rather than make_typename_type because we
1824 : : don't want to resolve it here, just strip typedefs. */
1825 : 4111123 : result = build_typename_type (ctx, name, fullname, typename_type);
1826 : : }
1827 : 4111123 : break;
1828 : 5592348 : case DECLTYPE_TYPE:
1829 : 5592348 : result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t),
1830 : : remove_attributes, flags);
1831 : 5592348 : if (result == DECLTYPE_TYPE_EXPR (t))
1832 : : result = NULL_TREE;
1833 : : else
1834 : 218857 : result = (finish_decltype_type
1835 : 218857 : (result,
1836 : 218857 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
1837 : : tf_none));
1838 : : break;
1839 : 790909 : case TRAIT_TYPE:
1840 : 790909 : {
1841 : 790909 : tree type1 = strip_typedefs (TRAIT_TYPE_TYPE1 (t),
1842 : : remove_attributes, flags);
1843 : 790909 : tree type2 = strip_typedefs (TRAIT_TYPE_TYPE2 (t),
1844 : : remove_attributes, flags);
1845 : 790909 : if (type1 == TRAIT_TYPE_TYPE1 (t) && type2 == TRAIT_TYPE_TYPE2 (t))
1846 : : result = NULL_TREE;
1847 : : else
1848 : 0 : result = finish_trait_type (TRAIT_TYPE_KIND (t), type1, type2,
1849 : : tf_warning_or_error);
1850 : : }
1851 : : break;
1852 : 23545232 : case TYPE_PACK_EXPANSION:
1853 : 23545232 : {
1854 : 23545232 : tree pat = PACK_EXPANSION_PATTERN (t);
1855 : 23545232 : if (TYPE_P (pat))
1856 : : {
1857 : 23545232 : type = strip_typedefs (pat, remove_attributes, flags);
1858 : 23545232 : if (type != pat)
1859 : : {
1860 : 143804 : result = build_distinct_type_copy (t);
1861 : 143804 : PACK_EXPANSION_PATTERN (result) = type;
1862 : : }
1863 : : }
1864 : : }
1865 : : break;
1866 : : default:
1867 : : break;
1868 : : }
1869 : :
1870 : 69133493 : if (!result)
1871 : 407241627 : result = TYPE_MAIN_VARIANT (t);
1872 : :
1873 : 69133493 : stripped:
1874 : : /*gcc_assert (!typedef_variant_p (result)
1875 : : || dependent_alias_template_spec_p (result, nt_opaque)
1876 : : || ((flags & STF_USER_VISIBLE)
1877 : : && !user_facing_original_type_p (result)));*/
1878 : :
1879 : 679695882 : if (COMPLETE_TYPE_P (result) && !COMPLETE_TYPE_P (t))
1880 : : /* If RESULT is complete and T isn't, it's likely the case that T
1881 : : is a variant of RESULT which hasn't been updated yet. Skip the
1882 : : attribute handling. */;
1883 : : else
1884 : : {
1885 : 679695876 : if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
1886 : 679695876 : || TYPE_ALIGN (t) != TYPE_ALIGN (result))
1887 : : {
1888 : 21 : gcc_assert (TYPE_USER_ALIGN (t));
1889 : 21 : if (remove_attributes)
1890 : 12 : *remove_attributes = true;
1891 : : else
1892 : : {
1893 : 9 : if (TYPE_ALIGN (t) == TYPE_ALIGN (result))
1894 : 0 : result = build_variant_type_copy (result);
1895 : : else
1896 : 9 : result = build_aligned_type (result, TYPE_ALIGN (t));
1897 : 9 : TYPE_USER_ALIGN (result) = true;
1898 : : }
1899 : : }
1900 : :
1901 : 679695876 : if (TYPE_ATTRIBUTES (t))
1902 : : {
1903 : 4952913 : if (remove_attributes)
1904 : 4942620 : result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t),
1905 : : remove_attributes);
1906 : : else
1907 : 10293 : result = cp_build_type_attribute_variant (result,
1908 : 10293 : TYPE_ATTRIBUTES (t));
1909 : : }
1910 : : }
1911 : :
1912 : 679695882 : return cp_build_qualified_type (result, cp_type_quals (t));
1913 : : }
1914 : :
1915 : : /* Like strip_typedefs above, but works on expressions (and other
1916 : : non-types such as TREE_VEC), so that in
1917 : :
1918 : : template<class T> struct A
1919 : : {
1920 : : typedef T TT;
1921 : : B<sizeof(TT)> b;
1922 : : };
1923 : :
1924 : : sizeof(TT) is replaced by sizeof(T). */
1925 : :
1926 : : tree
1927 : 294982267 : strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags)
1928 : : {
1929 : 294982267 : unsigned i,n;
1930 : 294982267 : tree r, type, *ops;
1931 : 294982267 : enum tree_code code;
1932 : :
1933 : 294982267 : if (t == NULL_TREE || t == error_mark_node)
1934 : : return t;
1935 : :
1936 : 294982267 : STRIP_ANY_LOCATION_WRAPPER (t);
1937 : :
1938 : 294982267 : if (DECL_P (t) || CONSTANT_CLASS_P (t))
1939 : : return t;
1940 : :
1941 : 171653757 : code = TREE_CODE (t);
1942 : 171653757 : switch (code)
1943 : : {
1944 : : case IDENTIFIER_NODE:
1945 : : case TEMPLATE_PARM_INDEX:
1946 : : case OVERLOAD:
1947 : : case BASELINK:
1948 : : case ARGUMENT_PACK_SELECT:
1949 : : return t;
1950 : :
1951 : 2193336 : case TRAIT_EXPR:
1952 : 2193336 : {
1953 : 2193336 : tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t),
1954 : : remove_attributes, flags);
1955 : 2193336 : tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t),
1956 : : remove_attributes, flags);
1957 : 2193336 : if (type1 == TRAIT_EXPR_TYPE1 (t)
1958 : 2193336 : && type2 == TRAIT_EXPR_TYPE2 (t))
1959 : : return t;
1960 : 50773 : r = copy_node (t);
1961 : 50773 : TRAIT_EXPR_TYPE1 (r) = type1;
1962 : 50773 : TRAIT_EXPR_TYPE2 (r) = type2;
1963 : 50773 : return r;
1964 : : }
1965 : :
1966 : 941546 : case TREE_LIST:
1967 : 941546 : {
1968 : 941546 : bool changed = false;
1969 : 941546 : auto_vec<tree_pair, 4> vec;
1970 : 941546 : r = t;
1971 : 1984128 : for (; t; t = TREE_CHAIN (t))
1972 : : {
1973 : 1042582 : tree purpose = strip_typedefs (TREE_PURPOSE (t),
1974 : 1042582 : remove_attributes, flags);
1975 : 1042582 : tree value = strip_typedefs (TREE_VALUE (t),
1976 : 1042582 : remove_attributes, flags);
1977 : 1042582 : if (purpose != TREE_PURPOSE (t) || value != TREE_VALUE (t))
1978 : : changed = true;
1979 : 1042582 : vec.safe_push ({purpose, value});
1980 : : }
1981 : 941546 : if (changed)
1982 : : {
1983 : 187334 : r = NULL_TREE;
1984 : 608219 : for (int i = vec.length () - 1; i >= 0; i--)
1985 : 233551 : r = tree_cons (vec[i].first, vec[i].second, r);
1986 : : }
1987 : 941546 : return r;
1988 : 941546 : }
1989 : :
1990 : 14205444 : case TREE_VEC:
1991 : 14205444 : {
1992 : 14205444 : bool changed = false;
1993 : 14205444 : releasing_vec vec;
1994 : 14205444 : n = TREE_VEC_LENGTH (t);
1995 : 14205444 : vec_safe_reserve (vec, n);
1996 : 32558211 : for (i = 0; i < n; ++i)
1997 : : {
1998 : 18352767 : tree op = strip_typedefs (TREE_VEC_ELT (t, i),
1999 : 18352767 : remove_attributes, flags);
2000 : 18352767 : vec->quick_push (op);
2001 : 18352767 : if (op != TREE_VEC_ELT (t, i))
2002 : 107491 : changed = true;
2003 : : }
2004 : 14205444 : if (changed)
2005 : : {
2006 : 107491 : r = copy_node (t);
2007 : 342388 : for (i = 0; i < n; ++i)
2008 : 127406 : TREE_VEC_ELT (r, i) = (*vec)[i];
2009 : 214982 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
2010 : 214982 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
2011 : : }
2012 : : else
2013 : : r = t;
2014 : 14205444 : return r;
2015 : 14205444 : }
2016 : :
2017 : 155476 : case CONSTRUCTOR:
2018 : 155476 : {
2019 : 155476 : bool changed = false;
2020 : 155476 : vec<constructor_elt, va_gc> *vec
2021 : 155476 : = vec_safe_copy (CONSTRUCTOR_ELTS (t));
2022 : 155476 : n = CONSTRUCTOR_NELTS (t);
2023 : 155476 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
2024 : 176790 : for (i = 0; i < n; ++i)
2025 : : {
2026 : 21314 : constructor_elt *e = &(*vec)[i];
2027 : 21314 : tree op = strip_typedefs (e->value, remove_attributes, flags);
2028 : 21314 : if (op != e->value)
2029 : : {
2030 : 6 : changed = true;
2031 : 6 : e->value = op;
2032 : : }
2033 : 21314 : gcc_checking_assert
2034 : : (e->index == strip_typedefs (e->index, remove_attributes,
2035 : : flags));
2036 : : }
2037 : :
2038 : 155476 : if (!changed && type == TREE_TYPE (t))
2039 : : {
2040 : 133381 : vec_free (vec);
2041 : 133381 : return t;
2042 : : }
2043 : : else
2044 : : {
2045 : 22095 : r = copy_node (t);
2046 : 22095 : TREE_TYPE (r) = type;
2047 : 22095 : CONSTRUCTOR_ELTS (r) = vec;
2048 : 22095 : return r;
2049 : : }
2050 : : }
2051 : :
2052 : : case LAMBDA_EXPR:
2053 : : case STMT_EXPR:
2054 : : return t;
2055 : :
2056 : 92296006 : default:
2057 : 92296006 : break;
2058 : : }
2059 : :
2060 : 92296006 : gcc_assert (EXPR_P (t));
2061 : :
2062 : 92296006 : n = cp_tree_operand_length (t);
2063 : 92296006 : ops = XALLOCAVEC (tree, n);
2064 : 92296006 : type = TREE_TYPE (t);
2065 : :
2066 : 92296006 : switch (code)
2067 : : {
2068 : 6694824 : CASE_CONVERT:
2069 : 6694824 : case IMPLICIT_CONV_EXPR:
2070 : 6694824 : case DYNAMIC_CAST_EXPR:
2071 : 6694824 : case STATIC_CAST_EXPR:
2072 : 6694824 : case CONST_CAST_EXPR:
2073 : 6694824 : case REINTERPRET_CAST_EXPR:
2074 : 6694824 : case CAST_EXPR:
2075 : 6694824 : case NEW_EXPR:
2076 : 6694824 : type = strip_typedefs (type, remove_attributes, flags);
2077 : : /* fallthrough */
2078 : :
2079 : 92296006 : default:
2080 : 290148900 : for (i = 0; i < n; ++i)
2081 : 197852894 : ops[i] = strip_typedefs (TREE_OPERAND (t, i),
2082 : : remove_attributes, flags);
2083 : : break;
2084 : : }
2085 : :
2086 : : /* If nothing changed, return t. */
2087 : 284433030 : for (i = 0; i < n; ++i)
2088 : 195531571 : if (ops[i] != TREE_OPERAND (t, i))
2089 : : break;
2090 : 92296006 : if (i == n && type == TREE_TYPE (t))
2091 : : return t;
2092 : :
2093 : 3642812 : r = copy_node (t);
2094 : 3642812 : TREE_TYPE (r) = type;
2095 : 11545226 : for (i = 0; i < n; ++i)
2096 : 7902414 : TREE_OPERAND (r, i) = ops[i];
2097 : : return r;
2098 : : }
2099 : :
2100 : : /* Makes a copy of BINFO and TYPE, which is to be inherited into a
2101 : : graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
2102 : : and we do a shallow copy. If BINFO is non-NULL, we do a deep copy.
2103 : : VIRT indicates whether TYPE is inherited virtually or not.
2104 : : IGO_PREV points at the previous binfo of the inheritance graph
2105 : : order chain. The newly copied binfo's TREE_CHAIN forms this
2106 : : ordering.
2107 : :
2108 : : The CLASSTYPE_VBASECLASSES vector of T is constructed in the
2109 : : correct order. That is in the order the bases themselves should be
2110 : : constructed in.
2111 : :
2112 : : The BINFO_INHERITANCE of a virtual base class points to the binfo
2113 : : of the most derived type. ??? We could probably change this so that
2114 : : BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
2115 : : remove a field. They currently can only differ for primary virtual
2116 : : virtual bases. */
2117 : :
2118 : : tree
2119 : 32102759 : copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
2120 : : {
2121 : 32102759 : tree new_binfo;
2122 : :
2123 : 32102759 : if (virt)
2124 : : {
2125 : : /* See if we've already made this virtual base. */
2126 : 296151 : new_binfo = binfo_for_vbase (type, t);
2127 : 296151 : if (new_binfo)
2128 : : return new_binfo;
2129 : : }
2130 : :
2131 : 57455475 : new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
2132 : 32031490 : BINFO_TYPE (new_binfo) = type;
2133 : :
2134 : : /* Chain it into the inheritance graph. */
2135 : 32031490 : TREE_CHAIN (*igo_prev) = new_binfo;
2136 : 32031490 : *igo_prev = new_binfo;
2137 : :
2138 : 57455475 : if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
2139 : : {
2140 : 25423976 : int ix;
2141 : 25423976 : tree base_binfo;
2142 : :
2143 : 25423976 : gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
2144 : :
2145 : 25423976 : BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
2146 : 25423976 : BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
2147 : :
2148 : : /* We do not need to copy the accesses, as they are read only. */
2149 : 25423976 : BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
2150 : :
2151 : : /* Recursively copy base binfos of BINFO. */
2152 : 29053714 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
2153 : : {
2154 : 3629738 : tree new_base_binfo;
2155 : 3629738 : new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
2156 : : t, igo_prev,
2157 : 3629738 : BINFO_VIRTUAL_P (base_binfo));
2158 : :
2159 : 3629738 : if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
2160 : 3403592 : BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
2161 : 3629738 : BINFO_BASE_APPEND (new_binfo, new_base_binfo);
2162 : : }
2163 : : }
2164 : : else
2165 : 6607514 : BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
2166 : :
2167 : 32031490 : if (virt)
2168 : : {
2169 : : /* Push it onto the list after any virtual bases it contains
2170 : : will have been pushed. */
2171 : 224882 : CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo);
2172 : 224882 : BINFO_VIRTUAL_P (new_binfo) = 1;
2173 : 224882 : BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
2174 : : }
2175 : :
2176 : : return new_binfo;
2177 : : }
2178 : :
2179 : : /* Hashing of lists so that we don't make duplicates.
2180 : : The entry point is `list_hash_canon'. */
2181 : :
2182 : : struct list_proxy
2183 : : {
2184 : : tree purpose;
2185 : : tree value;
2186 : : tree chain;
2187 : : };
2188 : :
2189 : : struct list_hasher : ggc_ptr_hash<tree_node>
2190 : : {
2191 : : typedef list_proxy *compare_type;
2192 : :
2193 : : static hashval_t hash (tree);
2194 : : static bool equal (tree, list_proxy *);
2195 : : };
2196 : :
2197 : : /* Now here is the hash table. When recording a list, it is added
2198 : : to the slot whose index is the hash code mod the table size.
2199 : : Note that the hash table is used for several kinds of lists.
2200 : : While all these live in the same table, they are completely independent,
2201 : : and the hash code is computed differently for each of these. */
2202 : :
2203 : : static GTY (()) hash_table<list_hasher> *list_hash_table;
2204 : :
2205 : : /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
2206 : : for a node we are thinking about adding). */
2207 : :
2208 : : bool
2209 : 1959723814 : list_hasher::equal (tree t, list_proxy *proxy)
2210 : : {
2211 : 1959723814 : return (TREE_VALUE (t) == proxy->value
2212 : 142433996 : && TREE_PURPOSE (t) == proxy->purpose
2213 : 2100186637 : && TREE_CHAIN (t) == proxy->chain);
2214 : : }
2215 : :
2216 : : /* Compute a hash code for a list (chain of TREE_LIST nodes
2217 : : with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
2218 : : TREE_COMMON slots), by adding the hash codes of the individual entries. */
2219 : :
2220 : : static hashval_t
2221 : 1797659427 : list_hash_pieces (tree purpose, tree value, tree chain)
2222 : : {
2223 : 1797659427 : hashval_t hashcode = 0;
2224 : :
2225 : 1797659427 : if (chain)
2226 : 1797279787 : hashcode += TREE_HASH (chain);
2227 : :
2228 : 1797659427 : if (value)
2229 : 1797659427 : hashcode += TREE_HASH (value);
2230 : : else
2231 : 0 : hashcode += 1007;
2232 : 1797659427 : if (purpose)
2233 : 159052864 : hashcode += TREE_HASH (purpose);
2234 : : else
2235 : 1638606563 : hashcode += 1009;
2236 : 1797659427 : return hashcode;
2237 : : }
2238 : :
2239 : : /* Hash an already existing TREE_LIST. */
2240 : :
2241 : : hashval_t
2242 : 1537704753 : list_hasher::hash (tree t)
2243 : : {
2244 : 1537704753 : return list_hash_pieces (TREE_PURPOSE (t),
2245 : 1537704753 : TREE_VALUE (t),
2246 : 1537704753 : TREE_CHAIN (t));
2247 : : }
2248 : :
2249 : : /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
2250 : : object for an identical list if one already exists. Otherwise, build a
2251 : : new one, and record it as the canonical object. */
2252 : :
2253 : : tree
2254 : 259954674 : hash_tree_cons (tree purpose, tree value, tree chain)
2255 : : {
2256 : 259954674 : int hashcode = 0;
2257 : 259954674 : tree *slot;
2258 : 259954674 : struct list_proxy proxy;
2259 : :
2260 : : /* Hash the list node. */
2261 : 259954674 : hashcode = list_hash_pieces (purpose, value, chain);
2262 : : /* Create a proxy for the TREE_LIST we would like to create. We
2263 : : don't actually create it so as to avoid creating garbage. */
2264 : 259954674 : proxy.purpose = purpose;
2265 : 259954674 : proxy.value = value;
2266 : 259954674 : proxy.chain = chain;
2267 : : /* See if it is already in the table. */
2268 : 259954674 : slot = list_hash_table->find_slot_with_hash (&proxy, hashcode, INSERT);
2269 : : /* If not, create a new node. */
2270 : 259954674 : if (!*slot)
2271 : 125833172 : *slot = tree_cons (purpose, value, chain);
2272 : 259954674 : return (tree) *slot;
2273 : : }
2274 : :
2275 : : /* Constructor for hashed lists. */
2276 : :
2277 : : tree
2278 : 2199276 : hash_tree_chain (tree value, tree chain)
2279 : : {
2280 : 2199276 : return hash_tree_cons (NULL_TREE, value, chain);
2281 : : }
2282 : :
2283 : : void
2284 : 0 : debug_binfo (tree elem)
2285 : : {
2286 : 0 : HOST_WIDE_INT n;
2287 : 0 : tree virtuals;
2288 : :
2289 : 0 : fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
2290 : : "\nvtable type:\n",
2291 : 0 : TYPE_NAME_STRING (BINFO_TYPE (elem)),
2292 : 0 : TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
2293 : 0 : debug_tree (BINFO_TYPE (elem));
2294 : 0 : if (BINFO_VTABLE (elem))
2295 : 0 : fprintf (stderr, "vtable decl \"%s\"\n",
2296 : 0 : IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
2297 : : else
2298 : 0 : fprintf (stderr, "no vtable decl yet\n");
2299 : 0 : fprintf (stderr, "virtuals:\n");
2300 : 0 : virtuals = BINFO_VIRTUALS (elem);
2301 : 0 : n = 0;
2302 : :
2303 : 0 : while (virtuals)
2304 : : {
2305 : 0 : tree fndecl = TREE_VALUE (virtuals);
2306 : 0 : fprintf (stderr, "%s [" HOST_WIDE_INT_PRINT_DEC " =? "
2307 : : HOST_WIDE_INT_PRINT_DEC "]\n",
2308 : 0 : IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
2309 : 0 : n, TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
2310 : 0 : ++n;
2311 : 0 : virtuals = TREE_CHAIN (virtuals);
2312 : : }
2313 : 0 : }
2314 : :
2315 : : /* Build a representation for the qualified name SCOPE::NAME. TYPE is
2316 : : the type of the result expression, if known, or NULL_TREE if the
2317 : : resulting expression is type-dependent. If TEMPLATE_P is true,
2318 : : NAME is known to be a template because the user explicitly used the
2319 : : "template" keyword after the "::".
2320 : :
2321 : : All SCOPE_REFs should be built by use of this function. */
2322 : :
2323 : : tree
2324 : 152765563 : build_qualified_name (tree type, tree scope, tree name, bool template_p)
2325 : : {
2326 : 152765563 : tree t;
2327 : 152765563 : if (type == error_mark_node
2328 : 152765563 : || scope == error_mark_node
2329 : 152765560 : || name == error_mark_node)
2330 : : return error_mark_node;
2331 : 152765560 : gcc_assert (TREE_CODE (name) != SCOPE_REF);
2332 : 152765560 : t = build2 (SCOPE_REF, type, scope, name);
2333 : 152765560 : QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
2334 : 152765560 : PTRMEM_OK_P (t) = true;
2335 : 152765560 : if (type)
2336 : 9857861 : t = convert_from_reference (t);
2337 : : return t;
2338 : : }
2339 : :
2340 : : /* Like check_qualified_type, but also check ref-qualifier, exception
2341 : : specification, and whether the return type was specified after the
2342 : : parameters. */
2343 : :
2344 : : static bool
2345 : 1061094518 : cp_check_qualified_type (const_tree cand, const_tree base, int type_quals,
2346 : : cp_ref_qualifier rqual, tree raises, bool late)
2347 : : {
2348 : 1061094518 : return (TYPE_QUALS (cand) == type_quals
2349 : 1061014416 : && check_base_type (cand, base)
2350 : 1060972843 : && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand),
2351 : : ce_exact)
2352 : 521003192 : && TYPE_HAS_LATE_RETURN_TYPE (cand) == late
2353 : 1549265988 : && type_memfn_rqual (cand) == rqual);
2354 : : }
2355 : :
2356 : : /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */
2357 : :
2358 : : tree
2359 : 664903 : build_ref_qualified_type (tree type, cp_ref_qualifier rqual)
2360 : : {
2361 : 664903 : tree raises = TYPE_RAISES_EXCEPTIONS (type);
2362 : 664903 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
2363 : 664903 : return build_cp_fntype_variant (type, rqual, raises, late);
2364 : : }
2365 : :
2366 : : tree
2367 : 154085 : make_binding_vec (tree name, unsigned clusters MEM_STAT_DECL)
2368 : : {
2369 : : /* Stored in an unsigned short, but we're limited to the number of
2370 : : modules anyway. */
2371 : 154085 : gcc_checking_assert (clusters <= (unsigned short)(~0));
2372 : 154085 : size_t length = (offsetof (tree_binding_vec, vec)
2373 : 154085 : + clusters * sizeof (binding_cluster));
2374 : 154085 : tree vec = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2375 : 154085 : TREE_SET_CODE (vec, BINDING_VECTOR);
2376 : 154085 : BINDING_VECTOR_NAME (vec) = name;
2377 : 154085 : BINDING_VECTOR_ALLOC_CLUSTERS (vec) = clusters;
2378 : 154085 : BINDING_VECTOR_NUM_CLUSTERS (vec) = 0;
2379 : :
2380 : 154085 : return vec;
2381 : : }
2382 : :
2383 : : /* Make a raw overload node containing FN. */
2384 : :
2385 : : tree
2386 : 305721457 : ovl_make (tree fn, tree next)
2387 : : {
2388 : 305721457 : tree result = make_node (OVERLOAD);
2389 : :
2390 : 305721457 : if (TREE_CODE (fn) == OVERLOAD)
2391 : 10079180 : OVL_NESTED_P (result) = true;
2392 : :
2393 : 411322037 : TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL
2394 : 411322037 : ? unknown_type_node : TREE_TYPE (fn));
2395 : 305721457 : if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
2396 : 14781672 : OVL_DEDUP_P (result) = true;
2397 : 305721457 : OVL_FUNCTION (result) = fn;
2398 : 305721457 : OVL_CHAIN (result) = next;
2399 : 305721457 : return result;
2400 : : }
2401 : :
2402 : : /* Add FN to the (potentially NULL) overload set OVL. USING_OR_HIDDEN is > 0
2403 : : if this is a using-decl. It is > 1 if we're revealing the using decl.
2404 : : It is > 2 if we're also exporting it. USING_OR_HIDDEN is < 0, if FN is
2405 : : hidden. (A decl cannot be both using and hidden.) We keep the hidden
2406 : : decls first, but remaining ones are unordered. */
2407 : :
2408 : : tree
2409 : 622866269 : ovl_insert (tree fn, tree maybe_ovl, int using_or_hidden)
2410 : : {
2411 : 622866269 : tree result = maybe_ovl;
2412 : 622866269 : tree insert_after = NULL_TREE;
2413 : :
2414 : : /* Skip hidden. */
2415 : 851116136 : for (; maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD
2416 : 868328000 : && OVL_HIDDEN_P (maybe_ovl);
2417 : 65081669 : maybe_ovl = OVL_CHAIN (maybe_ovl))
2418 : : {
2419 : 65081669 : gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl));
2420 : 65081669 : insert_after = maybe_ovl;
2421 : : }
2422 : :
2423 : 622866269 : if (maybe_ovl || using_or_hidden || TREE_CODE (fn) == TEMPLATE_DECL)
2424 : : {
2425 : 266496252 : maybe_ovl = ovl_make (fn, maybe_ovl);
2426 : :
2427 : 266496252 : if (using_or_hidden < 0)
2428 : 74868489 : OVL_HIDDEN_P (maybe_ovl) = true;
2429 : 266496252 : if (using_or_hidden > 0)
2430 : : {
2431 : 12220582 : OVL_DEDUP_P (maybe_ovl) = OVL_USING_P (maybe_ovl) = true;
2432 : 12220582 : if (using_or_hidden > 1)
2433 : 8605 : OVL_PURVIEW_P (maybe_ovl) = true;
2434 : 8605 : if (using_or_hidden > 2)
2435 : 8085 : OVL_EXPORT_P (maybe_ovl) = true;
2436 : : }
2437 : : }
2438 : : else
2439 : : maybe_ovl = fn;
2440 : :
2441 : 622866269 : if (insert_after)
2442 : : {
2443 : 9088652 : OVL_CHAIN (insert_after) = maybe_ovl;
2444 : 9088652 : TREE_TYPE (insert_after) = unknown_type_node;
2445 : : }
2446 : : else
2447 : : result = maybe_ovl;
2448 : :
2449 : 622866269 : return result;
2450 : : }
2451 : :
2452 : : /* Skip any hidden names at the beginning of OVL. */
2453 : :
2454 : : tree
2455 : 1592153069 : ovl_skip_hidden (tree ovl)
2456 : : {
2457 : 2472712813 : while (ovl && TREE_CODE (ovl) == OVERLOAD && OVL_HIDDEN_P (ovl))
2458 : 880559744 : ovl = OVL_CHAIN (ovl);
2459 : :
2460 : 1592153069 : return ovl;
2461 : : }
2462 : :
2463 : : /* NODE is an OVL_HIDDEN_P node that is now revealed. */
2464 : :
2465 : : tree
2466 : 4038087 : ovl_iterator::reveal_node (tree overload, tree node)
2467 : : {
2468 : : /* We cannot have returned NODE as part of a lookup overload, so we
2469 : : don't have to worry about preserving that. */
2470 : :
2471 : 4038087 : OVL_HIDDEN_P (node) = false;
2472 : 4038087 : if (tree chain = OVL_CHAIN (node))
2473 : 179003 : if (TREE_CODE (chain) == OVERLOAD)
2474 : : {
2475 : 169275 : if (OVL_HIDDEN_P (chain))
2476 : : {
2477 : : /* The node needs moving, and the simplest way is to remove it
2478 : : and reinsert. */
2479 : 77561 : overload = remove_node (overload, node);
2480 : 77561 : overload = ovl_insert (OVL_FUNCTION (node), overload);
2481 : : }
2482 : 91714 : else if (OVL_DEDUP_P (chain))
2483 : 9 : OVL_DEDUP_P (node) = true;
2484 : : }
2485 : 4038087 : return overload;
2486 : : }
2487 : :
2488 : : /* NODE is on the overloads of OVL. Remove it.
2489 : : The removed node is unaltered and may continue to be iterated
2490 : : from (i.e. it is safe to remove a node from an overload one is
2491 : : currently iterating over). */
2492 : :
2493 : : tree
2494 : 261775 : ovl_iterator::remove_node (tree overload, tree node)
2495 : : {
2496 : 261775 : tree *slot = &overload;
2497 : 1642586 : while (*slot != node)
2498 : : {
2499 : 1380811 : tree probe = *slot;
2500 : 1380811 : gcc_checking_assert (!OVL_LOOKUP_P (probe));
2501 : :
2502 : 1380811 : slot = &OVL_CHAIN (probe);
2503 : : }
2504 : :
2505 : : /* Stitch out NODE. We don't have to worry about now making a
2506 : : singleton overload (and consequently maybe setting its type),
2507 : : because all uses of this function will be followed by inserting a
2508 : : new node that must follow the place we've cut this out from. */
2509 : 261775 : if (TREE_CODE (node) != OVERLOAD)
2510 : : /* Cloned inherited ctors don't mark themselves as via_using. */
2511 : 122723 : *slot = NULL_TREE;
2512 : : else
2513 : 139052 : *slot = OVL_CHAIN (node);
2514 : :
2515 : 261775 : return overload;
2516 : : }
2517 : :
2518 : : /* Mark or unmark a lookup set. */
2519 : :
2520 : : void
2521 : 96144244 : lookup_mark (tree ovl, bool val)
2522 : : {
2523 : 1079915725 : for (lkp_iterator iter (ovl); iter; ++iter)
2524 : : {
2525 : 983771481 : gcc_checking_assert (LOOKUP_SEEN_P (*iter) != val);
2526 : 983771481 : LOOKUP_SEEN_P (*iter) = val;
2527 : : }
2528 : 96144244 : }
2529 : :
2530 : : /* Add a set of new FNS into a lookup. */
2531 : :
2532 : : tree
2533 : 505852372 : lookup_add (tree fns, tree lookup)
2534 : : {
2535 : 505852372 : if (fns == error_mark_node || lookup == error_mark_node)
2536 : : return error_mark_node;
2537 : :
2538 : 505852360 : if (lookup || TREE_CODE (fns) == TEMPLATE_DECL)
2539 : : {
2540 : 35156131 : lookup = ovl_make (fns, lookup);
2541 : 35156131 : OVL_LOOKUP_P (lookup) = true;
2542 : : }
2543 : : else
2544 : : lookup = fns;
2545 : :
2546 : : return lookup;
2547 : : }
2548 : :
2549 : : /* FNS is a new overload set, add them to LOOKUP, if they are not
2550 : : already present there. */
2551 : :
2552 : : tree
2553 : 505597802 : lookup_maybe_add (tree fns, tree lookup, bool deduping)
2554 : : {
2555 : 505597802 : if (deduping)
2556 : 580818387 : for (tree next, probe = fns; probe; probe = next)
2557 : : {
2558 : 524077066 : tree fn = probe;
2559 : 524077066 : next = NULL_TREE;
2560 : :
2561 : 524077066 : if (TREE_CODE (probe) == OVERLOAD)
2562 : : {
2563 : 508551527 : fn = OVL_FUNCTION (probe);
2564 : 508551527 : next = OVL_CHAIN (probe);
2565 : : }
2566 : :
2567 : 524077066 : if (!LOOKUP_SEEN_P (fn))
2568 : 398483167 : LOOKUP_SEEN_P (fn) = true;
2569 : : else
2570 : : {
2571 : : /* This function was already seen. Insert all the
2572 : : predecessors onto the lookup. */
2573 : 136132052 : for (; fns != probe; fns = OVL_CHAIN (fns))
2574 : : {
2575 : : /* Propagate OVL_USING, but OVL_HIDDEN &
2576 : : OVL_DEDUP_P don't matter. */
2577 : 10538153 : if (OVL_USING_P (fns))
2578 : : {
2579 : 10473 : lookup = ovl_make (OVL_FUNCTION (fns), lookup);
2580 : 10473 : OVL_USING_P (lookup) = true;
2581 : : }
2582 : : else
2583 : 10527680 : lookup = lookup_add (OVL_FUNCTION (fns), lookup);
2584 : : }
2585 : :
2586 : : /* And now skip this function. */
2587 : : fns = next;
2588 : : }
2589 : : }
2590 : :
2591 : 505597802 : if (fns)
2592 : : /* We ended in a set of new functions. Add them all in one go. */
2593 : 494611602 : lookup = lookup_add (fns, lookup);
2594 : :
2595 : 505597802 : return lookup;
2596 : : }
2597 : :
2598 : : /* Returns nonzero if X is an expression for a (possibly overloaded)
2599 : : function. If "f" is a function or function template, "f", "c->f",
2600 : : "c.f", "C::f", and "f<int>" will all be considered possibly
2601 : : overloaded functions. Returns 2 if the function is actually
2602 : : overloaded, i.e., if it is impossible to know the type of the
2603 : : function without performing overload resolution. */
2604 : :
2605 : : int
2606 : 5641671722 : is_overloaded_fn (tree x)
2607 : : {
2608 : 5641671722 : STRIP_ANY_LOCATION_WRAPPER (x);
2609 : :
2610 : : /* A baselink is also considered an overloaded function. */
2611 : 5641671722 : if (TREE_CODE (x) == OFFSET_REF
2612 : 5641603922 : || TREE_CODE (x) == COMPONENT_REF)
2613 : 250050315 : x = TREE_OPERAND (x, 1);
2614 : 5641671722 : x = MAYBE_BASELINK_FUNCTIONS (x);
2615 : 5641671722 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2616 : 135943001 : x = TREE_OPERAND (x, 0);
2617 : :
2618 : 6461757898 : if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x))
2619 : 5660956496 : || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x)))
2620 : : return 2;
2621 : :
2622 : 5897633088 : return OVL_P (x);
2623 : : }
2624 : :
2625 : : /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
2626 : : (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
2627 : : NULL_TREE. */
2628 : :
2629 : : tree
2630 : 160449263 : dependent_name (tree x)
2631 : : {
2632 : : /* FIXME a dependent name must be unqualified, but this function doesn't
2633 : : distinguish between qualified and unqualified identifiers. */
2634 : 160449263 : if (identifier_p (x))
2635 : : return x;
2636 : 160281972 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2637 : 56498166 : x = TREE_OPERAND (x, 0);
2638 : 160281972 : if (OVL_P (x))
2639 : 100969393 : return OVL_NAME (x);
2640 : : return NULL_TREE;
2641 : : }
2642 : :
2643 : : /* Like dependent_name, but instead takes a CALL_EXPR and also checks
2644 : : its dependence. */
2645 : :
2646 : : tree
2647 : 159682651 : call_expr_dependent_name (tree x)
2648 : : {
2649 : 159682651 : if (TREE_TYPE (x) != NULL_TREE)
2650 : : /* X isn't dependent, so its callee isn't a dependent name. */
2651 : : return NULL_TREE;
2652 : 157699098 : return dependent_name (CALL_EXPR_FN (x));
2653 : : }
2654 : :
2655 : : /* Returns true iff X is an expression for an overloaded function
2656 : : whose type cannot be known without performing overload
2657 : : resolution. */
2658 : :
2659 : : bool
2660 : 511781697 : really_overloaded_fn (tree x)
2661 : : {
2662 : 511781697 : return is_overloaded_fn (x) == 2;
2663 : : }
2664 : :
2665 : : /* Get the overload set FROM refers to. Returns NULL if it's not an
2666 : : overload set. */
2667 : :
2668 : : tree
2669 : 3842630574 : maybe_get_fns (tree from)
2670 : : {
2671 : 3842630574 : STRIP_ANY_LOCATION_WRAPPER (from);
2672 : :
2673 : : /* A baselink is also considered an overloaded function. */
2674 : 3842630574 : if (TREE_CODE (from) == OFFSET_REF
2675 : 3842567709 : || TREE_CODE (from) == COMPONENT_REF)
2676 : 133491366 : from = TREE_OPERAND (from, 1);
2677 : 3842630574 : if (BASELINK_P (from))
2678 : 138918522 : from = BASELINK_FUNCTIONS (from);
2679 : 3842630574 : if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
2680 : 95328446 : from = TREE_OPERAND (from, 0);
2681 : :
2682 : 3842630574 : if (OVL_P (from))
2683 : 909637787 : return from;
2684 : :
2685 : : return NULL;
2686 : : }
2687 : :
2688 : : /* FROM refers to an overload set. Return that set (or die). */
2689 : :
2690 : : tree
2691 : 618070921 : get_fns (tree from)
2692 : : {
2693 : 618070921 : tree res = maybe_get_fns (from);
2694 : :
2695 : 618070921 : gcc_assert (res);
2696 : 618070921 : return res;
2697 : : }
2698 : :
2699 : : /* Return the first function of the overload set FROM refers to. */
2700 : :
2701 : : tree
2702 : 392884594 : get_first_fn (tree from)
2703 : : {
2704 : 392884594 : return OVL_FIRST (get_fns (from));
2705 : : }
2706 : :
2707 : : /* Return the scope where the overloaded functions OVL were found. */
2708 : :
2709 : : tree
2710 : 164232710 : ovl_scope (tree ovl)
2711 : : {
2712 : 164232710 : if (TREE_CODE (ovl) == OFFSET_REF
2713 : 164232710 : || TREE_CODE (ovl) == COMPONENT_REF)
2714 : 0 : ovl = TREE_OPERAND (ovl, 1);
2715 : 164232710 : if (TREE_CODE (ovl) == BASELINK)
2716 : 40721573 : return BINFO_TYPE (BASELINK_BINFO (ovl));
2717 : 123511137 : if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
2718 : 45054835 : ovl = TREE_OPERAND (ovl, 0);
2719 : : /* Skip using-declarations. */
2720 : 123511137 : lkp_iterator iter (ovl);
2721 : 132840133 : do
2722 : 132840133 : ovl = *iter;
2723 : 256351270 : while (iter.using_p () && ++iter);
2724 : :
2725 : 123511137 : return CP_DECL_CONTEXT (ovl);
2726 : : }
2727 : :
2728 : : #define PRINT_RING_SIZE 4
2729 : :
2730 : : static const char *
2731 : 136681 : cxx_printable_name_internal (tree decl, int v, bool translate)
2732 : : {
2733 : 136681 : static unsigned int uid_ring[PRINT_RING_SIZE];
2734 : 136681 : static char *print_ring[PRINT_RING_SIZE];
2735 : 136681 : static bool trans_ring[PRINT_RING_SIZE];
2736 : 136681 : static int ring_counter;
2737 : 136681 : int i;
2738 : :
2739 : : /* Only cache functions. */
2740 : 136681 : if (v < 2
2741 : 60182 : || TREE_CODE (decl) != FUNCTION_DECL
2742 : 193538 : || DECL_LANG_SPECIFIC (decl) == 0)
2743 : 81024 : return lang_decl_name (decl, v, translate);
2744 : :
2745 : : /* See if this print name is lying around. */
2746 : 257857 : for (i = 0; i < PRINT_RING_SIZE; i++)
2747 : 210714 : if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
2748 : : /* yes, so return it. */
2749 : 8514 : return print_ring[i];
2750 : :
2751 : 47143 : if (++ring_counter == PRINT_RING_SIZE)
2752 : 9034 : ring_counter = 0;
2753 : :
2754 : 47143 : if (current_function_decl != NULL_TREE)
2755 : : {
2756 : : /* There may be both translated and untranslated versions of the
2757 : : name cached. */
2758 : 123654 : for (i = 0; i < 2; i++)
2759 : : {
2760 : 82436 : if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
2761 : 67 : ring_counter += 1;
2762 : 82436 : if (ring_counter == PRINT_RING_SIZE)
2763 : 4 : ring_counter = 0;
2764 : : }
2765 : 41218 : gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
2766 : : }
2767 : :
2768 : 47143 : free (print_ring[ring_counter]);
2769 : :
2770 : 47143 : print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate));
2771 : 47143 : uid_ring[ring_counter] = DECL_UID (decl);
2772 : 47143 : trans_ring[ring_counter] = translate;
2773 : 47143 : return print_ring[ring_counter];
2774 : : }
2775 : :
2776 : : const char *
2777 : 136681 : cxx_printable_name (tree decl, int v)
2778 : : {
2779 : 136681 : return cxx_printable_name_internal (decl, v, false);
2780 : : }
2781 : :
2782 : : const char *
2783 : 0 : cxx_printable_name_translate (tree decl, int v)
2784 : : {
2785 : 0 : return cxx_printable_name_internal (decl, v, true);
2786 : : }
2787 : :
2788 : : /* Return the canonical version of exception-specification RAISES for a C++17
2789 : : function type, for use in type comparison and building TYPE_CANONICAL. */
2790 : :
2791 : : tree
2792 : 172645577 : canonical_eh_spec (tree raises)
2793 : : {
2794 : 172645577 : if (raises == NULL_TREE)
2795 : : return raises;
2796 : 155915471 : else if (DEFERRED_NOEXCEPT_SPEC_P (raises)
2797 : 129968880 : || UNPARSED_NOEXCEPT_SPEC_P (raises)
2798 : 123767432 : || uses_template_parms (raises)
2799 : 123767432 : || uses_template_parms (TREE_PURPOSE (raises)))
2800 : : /* Keep a dependent or deferred exception specification. */
2801 : 34371174 : return raises;
2802 : 121544297 : else if (nothrow_spec_p (raises))
2803 : : /* throw() -> noexcept. */
2804 : 121109747 : return noexcept_true_spec;
2805 : : else
2806 : : /* For C++17 type matching, anything else -> nothing. */
2807 : : return NULL_TREE;
2808 : : }
2809 : :
2810 : : tree
2811 : 639731645 : build_cp_fntype_variant (tree type, cp_ref_qualifier rqual,
2812 : : tree raises, bool late)
2813 : : {
2814 : 639731645 : cp_cv_quals type_quals = TYPE_QUALS (type);
2815 : :
2816 : 639731645 : if (cp_check_qualified_type (type, type, type_quals, rqual, raises, late))
2817 : : return type;
2818 : :
2819 : 266013026 : tree v = TYPE_MAIN_VARIANT (type);
2820 : 575155369 : for (; v; v = TYPE_NEXT_VARIANT (v))
2821 : 421362873 : if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late))
2822 : : return v;
2823 : :
2824 : : /* Need to build a new variant. */
2825 : 153792496 : v = build_variant_type_copy (type);
2826 : 153792496 : if (!TYPE_DEPENDENT_P (v))
2827 : : /* We no longer know that it's not type-dependent. */
2828 : 153027650 : TYPE_DEPENDENT_P_VALID (v) = false;
2829 : 153792496 : TYPE_RAISES_EXCEPTIONS (v) = raises;
2830 : 153792496 : TYPE_HAS_LATE_RETURN_TYPE (v) = late;
2831 : 153792496 : switch (rqual)
2832 : : {
2833 : 830005 : case REF_QUAL_RVALUE:
2834 : 830005 : FUNCTION_RVALUE_QUALIFIED (v) = 1;
2835 : 830005 : FUNCTION_REF_QUALIFIED (v) = 1;
2836 : 830005 : break;
2837 : 829212 : case REF_QUAL_LVALUE:
2838 : 829212 : FUNCTION_RVALUE_QUALIFIED (v) = 0;
2839 : 829212 : FUNCTION_REF_QUALIFIED (v) = 1;
2840 : 829212 : break;
2841 : 152133279 : default:
2842 : 152133279 : FUNCTION_REF_QUALIFIED (v) = 0;
2843 : 152133279 : break;
2844 : : }
2845 : :
2846 : : /* Canonicalize the exception specification. */
2847 : 153792496 : tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE;
2848 : 146244424 : bool complex_eh_spec_p = (cr && cr != noexcept_true_spec
2849 : 186317417 : && !UNPARSED_NOEXCEPT_SPEC_P (cr));
2850 : :
2851 : 126517491 : if (!complex_eh_spec_p && TYPE_RAISES_EXCEPTIONS (type))
2852 : : /* We want to consider structural equality of the exception-less
2853 : : variant since we'll be replacing the exception specification. */
2854 : 4389015 : type = build_cp_fntype_variant (type, rqual, /*raises=*/NULL_TREE, late);
2855 : 153792496 : if (TYPE_STRUCTURAL_EQUALITY_P (type) || complex_eh_spec_p)
2856 : : /* Propagate structural equality. And always use structural equality
2857 : : for function types with a complex noexcept-spec since their identity
2858 : : may depend on e.g. whether comparing_specializations is set. */
2859 : 39165130 : SET_TYPE_STRUCTURAL_EQUALITY (v);
2860 : 114627366 : else if (TYPE_CANONICAL (type) != type || cr != raises || late)
2861 : : /* Build the underlying canonical type, since it is different
2862 : : from TYPE. */
2863 : 48915457 : TYPE_CANONICAL (v) = build_cp_fntype_variant (TYPE_CANONICAL (type),
2864 : : rqual, cr, false);
2865 : : else
2866 : : /* T is its own canonical type. */
2867 : 65711909 : TYPE_CANONICAL (v) = v;
2868 : :
2869 : : return v;
2870 : : }
2871 : :
2872 : : /* TYPE is a function or method type with a deferred exception
2873 : : specification that has been parsed to RAISES. Fixup all the type
2874 : : variants that are affected in place. Via decltype &| noexcept
2875 : : tricks, the unparsed spec could have escaped into the type system. */
2876 : :
2877 : : void
2878 : 2558331 : fixup_deferred_exception_variants (tree type, tree raises)
2879 : : {
2880 : 2558331 : tree original = TYPE_RAISES_EXCEPTIONS (type);
2881 : :
2882 : 5116662 : gcc_checking_assert (UNPARSED_NOEXCEPT_SPEC_P (original));
2883 : :
2884 : 2558331 : for (tree variant = TYPE_MAIN_VARIANT (type);
2885 : 8513285 : variant; variant = TYPE_NEXT_VARIANT (variant))
2886 : 5954954 : if (TYPE_RAISES_EXCEPTIONS (variant) == original)
2887 : : {
2888 : 2821734 : gcc_checking_assert (variant != TYPE_MAIN_VARIANT (type));
2889 : :
2890 : 2821734 : SET_TYPE_STRUCTURAL_EQUALITY (variant);
2891 : 2821734 : TYPE_RAISES_EXCEPTIONS (variant) = raises;
2892 : :
2893 : 2821734 : if (!TYPE_DEPENDENT_P (variant))
2894 : : /* We no longer know that it's not type-dependent. */
2895 : 266437 : TYPE_DEPENDENT_P_VALID (variant) = false;
2896 : : }
2897 : 2558331 : }
2898 : :
2899 : : /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
2900 : : listed in RAISES. */
2901 : :
2902 : : tree
2903 : 155467375 : build_exception_variant (tree type, tree raises)
2904 : : {
2905 : 155467375 : cp_ref_qualifier rqual = type_memfn_rqual (type);
2906 : 155467375 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
2907 : 155467375 : return build_cp_fntype_variant (type, rqual, raises, late);
2908 : : }
2909 : :
2910 : : /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
2911 : : BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
2912 : : arguments. */
2913 : :
2914 : : tree
2915 : 250031 : bind_template_template_parm (tree t, tree newargs)
2916 : : {
2917 : 250031 : tree decl = TYPE_NAME (t);
2918 : 250031 : tree t2;
2919 : :
2920 : 250031 : t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
2921 : 250031 : decl = build_decl (input_location,
2922 : 250031 : TYPE_DECL, DECL_NAME (decl), NULL_TREE);
2923 : 250031 : SET_DECL_TEMPLATE_PARM_P (decl);
2924 : :
2925 : : /* These nodes have to be created to reflect new TYPE_DECL and template
2926 : : arguments. */
2927 : 250031 : TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
2928 : 250031 : TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
2929 : 250031 : TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
2930 : 500062 : = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
2931 : :
2932 : 250031 : TREE_TYPE (decl) = t2;
2933 : 250031 : TYPE_NAME (t2) = decl;
2934 : 250031 : TYPE_STUB_DECL (t2) = decl;
2935 : 250031 : TYPE_SIZE (t2) = 0;
2936 : :
2937 : 250031 : if (any_template_arguments_need_structural_equality_p (newargs))
2938 : 13 : SET_TYPE_STRUCTURAL_EQUALITY (t2);
2939 : : else
2940 : 250018 : TYPE_CANONICAL (t2) = canonical_type_parameter (t2);
2941 : :
2942 : 250031 : return t2;
2943 : : }
2944 : :
2945 : : /* Called from count_trees via walk_tree. */
2946 : :
2947 : : static tree
2948 : 0 : count_trees_r (tree *tp, int *walk_subtrees, void *data)
2949 : : {
2950 : 0 : ++*((int *) data);
2951 : :
2952 : 0 : if (TYPE_P (*tp))
2953 : 0 : *walk_subtrees = 0;
2954 : :
2955 : 0 : return NULL_TREE;
2956 : : }
2957 : :
2958 : : /* Debugging function for measuring the rough complexity of a tree
2959 : : representation. */
2960 : :
2961 : : int
2962 : 0 : count_trees (tree t)
2963 : : {
2964 : 0 : int n_trees = 0;
2965 : 0 : cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
2966 : 0 : return n_trees;
2967 : : }
2968 : :
2969 : : /* Called from verify_stmt_tree via walk_tree. */
2970 : :
2971 : : static tree
2972 : 596077 : verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data)
2973 : : {
2974 : 596077 : tree t = *tp;
2975 : 596077 : hash_table<nofree_ptr_hash <tree_node> > *statements
2976 : : = static_cast <hash_table<nofree_ptr_hash <tree_node> > *> (data);
2977 : 596077 : tree_node **slot;
2978 : :
2979 : 596077 : if (!STATEMENT_CODE_P (TREE_CODE (t)))
2980 : : return NULL_TREE;
2981 : :
2982 : : /* If this statement is already present in the hash table, then
2983 : : there is a circularity in the statement tree. */
2984 : 32044 : gcc_assert (!statements->find (t));
2985 : :
2986 : 32044 : slot = statements->find_slot (t, INSERT);
2987 : 32044 : *slot = t;
2988 : :
2989 : 32044 : return NULL_TREE;
2990 : : }
2991 : :
2992 : : /* Debugging function to check that the statement T has not been
2993 : : corrupted. For now, this function simply checks that T contains no
2994 : : circularities. */
2995 : :
2996 : : void
2997 : 1573 : verify_stmt_tree (tree t)
2998 : : {
2999 : 1573 : hash_table<nofree_ptr_hash <tree_node> > statements (37);
3000 : 1573 : cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
3001 : 1573 : }
3002 : :
3003 : : /* Check if the type T depends on a type with no linkage and if so,
3004 : : return it. If RELAXED_P then do not consider a class type declared
3005 : : within a vague-linkage function or in a module CMI to have no linkage,
3006 : : since it can still be accessed within a different TU. Remember:
3007 : : no-linkage is not the same as internal-linkage. */
3008 : :
3009 : : tree
3010 : 290441984 : no_linkage_check (tree t, bool relaxed_p)
3011 : : {
3012 : 290441984 : tree r;
3013 : :
3014 : : /* Lambda types that don't have mangling scope have no linkage. We
3015 : : check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
3016 : : when we get here from pushtag none of the lambda information is
3017 : : set up yet, so we want to assume that the lambda has linkage and
3018 : : fix it up later if not. We need to check this even in templates so
3019 : : that we properly handle a lambda-expression in the signature. */
3020 : 325190927 : if (LAMBDA_TYPE_P (t)
3021 : 292590309 : && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node)
3022 : : {
3023 : 1247390 : tree extra = LAMBDA_TYPE_EXTRA_SCOPE (t);
3024 : 1247390 : if (!extra)
3025 : : return t;
3026 : : }
3027 : :
3028 : : /* Otherwise there's no point in checking linkage on template functions; we
3029 : : can't know their complete types. */
3030 : 290441119 : if (processing_template_decl)
3031 : : return NULL_TREE;
3032 : :
3033 : 172884867 : switch (TREE_CODE (t))
3034 : : {
3035 : 87468333 : case RECORD_TYPE:
3036 : 87468333 : if (TYPE_PTRMEMFUNC_P (t))
3037 : 128792 : goto ptrmem;
3038 : : /* Fall through. */
3039 : 88538937 : case UNION_TYPE:
3040 : 88538937 : if (!CLASS_TYPE_P (t))
3041 : : return NULL_TREE;
3042 : : /* Fall through. */
3043 : 92237557 : case ENUMERAL_TYPE:
3044 : : /* Only treat unnamed types as having no linkage if they're at
3045 : : namespace scope. This is core issue 966. */
3046 : 187960629 : if (TYPE_UNNAMED_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
3047 : : return t;
3048 : :
3049 : 91495481 : for (r = CP_TYPE_CONTEXT (t); ; )
3050 : : {
3051 : : /* If we're a nested type of a !TREE_PUBLIC class, we might not
3052 : : have linkage, or we might just be in an anonymous namespace.
3053 : : If we're in a TREE_PUBLIC class, we have linkage. */
3054 : 93731211 : if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
3055 : 81574 : return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
3056 : 93649637 : else if (TREE_CODE (r) == FUNCTION_DECL)
3057 : : {
3058 : 2604100 : if (relaxed_p
3059 : 2604100 : && (vague_linkage_p (r)
3060 : 7132 : || (TREE_PUBLIC (r) && module_maybe_has_cmi_p ())))
3061 : 2235730 : r = CP_DECL_CONTEXT (r);
3062 : : else
3063 : 368370 : return t;
3064 : : }
3065 : : else
3066 : : break;
3067 : : }
3068 : :
3069 : : return NULL_TREE;
3070 : :
3071 : 23243576 : case ARRAY_TYPE:
3072 : 23243576 : case POINTER_TYPE:
3073 : 23243576 : case REFERENCE_TYPE:
3074 : 23243576 : case VECTOR_TYPE:
3075 : 23243576 : return no_linkage_check (TREE_TYPE (t), relaxed_p);
3076 : :
3077 : 132118 : case OFFSET_TYPE:
3078 : 132118 : ptrmem:
3079 : 132118 : r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
3080 : : relaxed_p);
3081 : 132118 : if (r)
3082 : : return r;
3083 : 132118 : return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
3084 : :
3085 : 20341549 : case METHOD_TYPE:
3086 : 20341549 : case FUNCTION_TYPE:
3087 : 20341549 : {
3088 : 20341549 : tree parm = TYPE_ARG_TYPES (t);
3089 : 20341549 : if (TREE_CODE (t) == METHOD_TYPE)
3090 : : /* The 'this' pointer isn't interesting; a method has the same
3091 : : linkage (or lack thereof) as its enclosing class. */
3092 : 10599953 : parm = TREE_CHAIN (parm);
3093 : 25754099 : for (;
3094 : 46095648 : parm && parm != void_list_node;
3095 : 25754099 : parm = TREE_CHAIN (parm))
3096 : : {
3097 : 26108502 : r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
3098 : 26108502 : if (r)
3099 : : return r;
3100 : : }
3101 : 19987146 : return no_linkage_check (TREE_TYPE (t), relaxed_p);
3102 : : }
3103 : :
3104 : : default:
3105 : : return NULL_TREE;
3106 : : }
3107 : : }
3108 : :
3109 : : extern int depth_reached;
3110 : :
3111 : : void
3112 : 0 : cxx_print_statistics (void)
3113 : : {
3114 : 0 : print_template_statistics ();
3115 : 0 : if (GATHER_STATISTICS)
3116 : : fprintf (stderr, "maximum template instantiation depth reached: %d\n",
3117 : : depth_reached);
3118 : 0 : }
3119 : :
3120 : : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3121 : : (which is an ARRAY_TYPE). This one is a recursive count of all
3122 : : ARRAY_TYPEs that are clumped together. */
3123 : :
3124 : : tree
3125 : 3165 : array_type_nelts_total (tree type)
3126 : : {
3127 : 3165 : tree sz = array_type_nelts_top (type);
3128 : 3165 : type = TREE_TYPE (type);
3129 : 3425 : while (TREE_CODE (type) == ARRAY_TYPE)
3130 : : {
3131 : 260 : tree n = array_type_nelts_top (type);
3132 : 260 : sz = fold_build2_loc (input_location,
3133 : : MULT_EXPR, sizetype, sz, n);
3134 : 260 : type = TREE_TYPE (type);
3135 : : }
3136 : 3165 : return sz;
3137 : : }
3138 : :
3139 : : struct bot_data
3140 : : {
3141 : : splay_tree target_remap;
3142 : : bool clear_location;
3143 : : };
3144 : :
3145 : : /* Called from break_out_target_exprs via mapcar. */
3146 : :
3147 : : static tree
3148 : 22920752 : bot_manip (tree* tp, int* walk_subtrees, void* data_)
3149 : : {
3150 : 22920752 : bot_data &data = *(bot_data*)data_;
3151 : 22920752 : splay_tree target_remap = data.target_remap;
3152 : 22920752 : tree t = *tp;
3153 : :
3154 : 22920752 : if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t))
3155 : : {
3156 : : /* There can't be any TARGET_EXPRs or their slot variables below this
3157 : : point. But we must make a copy, in case subsequent processing
3158 : : alters any part of it. For example, during gimplification a cast
3159 : : of the form (T) &X::f (where "f" is a member function) will lead
3160 : : to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */
3161 : 8854670 : *walk_subtrees = 0;
3162 : 8854670 : *tp = unshare_expr (t);
3163 : 8854670 : return NULL_TREE;
3164 : : }
3165 : 14066082 : if (TREE_CODE (t) == TARGET_EXPR)
3166 : : {
3167 : 410086 : tree u;
3168 : :
3169 : 410086 : if (TREE_CODE (TARGET_EXPR_INITIAL (t)) == AGGR_INIT_EXPR)
3170 : : {
3171 : 327766 : u = build_cplus_new (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
3172 : : tf_warning_or_error);
3173 : 327766 : if (u == error_mark_node)
3174 : : return u;
3175 : 327766 : if (AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (t)))
3176 : 1897 : AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (u)) = true;
3177 : : }
3178 : : else
3179 : 82320 : u = force_target_expr (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
3180 : : tf_warning_or_error);
3181 : :
3182 : 410086 : TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
3183 : 410086 : TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
3184 : 410086 : TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
3185 : 410086 : TARGET_EXPR_ELIDING_P (u) = TARGET_EXPR_ELIDING_P (t);
3186 : :
3187 : : /* Map the old variable to the new one. */
3188 : 1230258 : splay_tree_insert (target_remap,
3189 : 410086 : (splay_tree_key) TARGET_EXPR_SLOT (t),
3190 : 410086 : (splay_tree_value) TARGET_EXPR_SLOT (u));
3191 : :
3192 : 410086 : TARGET_EXPR_INITIAL (u) = break_out_target_exprs (TARGET_EXPR_INITIAL (u),
3193 : 410086 : data.clear_location);
3194 : 410086 : if (TARGET_EXPR_INITIAL (u) == error_mark_node)
3195 : : return error_mark_node;
3196 : :
3197 : 410086 : if (data.clear_location)
3198 : 290917 : SET_EXPR_LOCATION (u, input_location);
3199 : :
3200 : : /* Replace the old expression with the new version. */
3201 : 410086 : *tp = u;
3202 : : /* We don't have to go below this point; the recursive call to
3203 : : break_out_target_exprs will have handled anything below this
3204 : : point. */
3205 : 410086 : *walk_subtrees = 0;
3206 : 410086 : return NULL_TREE;
3207 : : }
3208 : 13655996 : if (TREE_CODE (*tp) == SAVE_EXPR)
3209 : : {
3210 : 99259 : t = *tp;
3211 : 99259 : splay_tree_node n = splay_tree_lookup (target_remap,
3212 : : (splay_tree_key) t);
3213 : 99259 : if (n)
3214 : : {
3215 : 49635 : *tp = (tree)n->value;
3216 : 49635 : *walk_subtrees = 0;
3217 : : }
3218 : : else
3219 : : {
3220 : 49624 : copy_tree_r (tp, walk_subtrees, NULL);
3221 : 49624 : splay_tree_insert (target_remap,
3222 : : (splay_tree_key)t,
3223 : 49624 : (splay_tree_value)*tp);
3224 : : /* Make sure we don't remap an already-remapped SAVE_EXPR. */
3225 : 49624 : splay_tree_insert (target_remap,
3226 : : (splay_tree_key)*tp,
3227 : 49624 : (splay_tree_value)*tp);
3228 : : }
3229 : 99259 : return NULL_TREE;
3230 : : }
3231 : 13556737 : if (TREE_CODE (*tp) == DECL_EXPR
3232 : 25 : && VAR_P (DECL_EXPR_DECL (*tp))
3233 : 25 : && DECL_ARTIFICIAL (DECL_EXPR_DECL (*tp))
3234 : 13556762 : && !TREE_STATIC (DECL_EXPR_DECL (*tp)))
3235 : : {
3236 : 25 : tree t;
3237 : 25 : splay_tree_node n
3238 : 50 : = splay_tree_lookup (target_remap,
3239 : 25 : (splay_tree_key) DECL_EXPR_DECL (*tp));
3240 : 25 : if (n)
3241 : 1 : t = (tree) n->value;
3242 : : else
3243 : : {
3244 : 24 : t = create_temporary_var (TREE_TYPE (DECL_EXPR_DECL (*tp)));
3245 : 24 : DECL_INITIAL (t) = DECL_INITIAL (DECL_EXPR_DECL (*tp));
3246 : 48 : splay_tree_insert (target_remap,
3247 : 24 : (splay_tree_key) DECL_EXPR_DECL (*tp),
3248 : : (splay_tree_value) t);
3249 : : }
3250 : 25 : copy_tree_r (tp, walk_subtrees, NULL);
3251 : 25 : DECL_EXPR_DECL (*tp) = t;
3252 : 25 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3253 : 12 : SET_EXPR_LOCATION (*tp, input_location);
3254 : 25 : return NULL_TREE;
3255 : : }
3256 : 13556712 : if (TREE_CODE (*tp) == BIND_EXPR && BIND_EXPR_VARS (*tp))
3257 : : {
3258 : 1 : copy_tree_r (tp, walk_subtrees, NULL);
3259 : 2 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
3260 : : {
3261 : 1 : gcc_assert (VAR_P (*p) && DECL_ARTIFICIAL (*p) && !TREE_STATIC (*p));
3262 : 1 : tree t = create_temporary_var (TREE_TYPE (*p));
3263 : 1 : DECL_INITIAL (t) = DECL_INITIAL (*p);
3264 : 1 : DECL_CHAIN (t) = DECL_CHAIN (*p);
3265 : 1 : splay_tree_insert (target_remap, (splay_tree_key) *p,
3266 : : (splay_tree_value) t);
3267 : 1 : *p = t;
3268 : : }
3269 : 1 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3270 : 0 : SET_EXPR_LOCATION (*tp, input_location);
3271 : 1 : return NULL_TREE;
3272 : : }
3273 : :
3274 : : /* Make a copy of this node. */
3275 : 13556711 : t = copy_tree_r (tp, walk_subtrees, NULL);
3276 : 13556711 : if (TREE_CODE (*tp) == CALL_EXPR || TREE_CODE (*tp) == AGGR_INIT_EXPR)
3277 : 1864313 : if (!processing_template_decl)
3278 : 1864313 : set_flags_from_callee (*tp);
3279 : 13556711 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3280 : 321751 : SET_EXPR_LOCATION (*tp, input_location);
3281 : : return t;
3282 : : }
3283 : :
3284 : : /* Replace all remapped VAR_DECLs in T with their new equivalents.
3285 : : DATA is really a splay-tree mapping old variables to new
3286 : : variables. */
3287 : :
3288 : : static tree
3289 : 34431829 : bot_replace (tree* t, int */*walk_subtrees*/, void* data_)
3290 : : {
3291 : 34431829 : bot_data &data = *(bot_data*)data_;
3292 : 34431829 : splay_tree target_remap = data.target_remap;
3293 : :
3294 : 34431829 : if (VAR_P (*t))
3295 : : {
3296 : 1565592 : splay_tree_node n = splay_tree_lookup (target_remap,
3297 : : (splay_tree_key) *t);
3298 : 1565592 : if (n)
3299 : 1109 : *t = (tree) n->value;
3300 : : }
3301 : 32866237 : else if (TREE_CODE (*t) == PARM_DECL
3302 : 2856810 : && DECL_NAME (*t) == this_identifier
3303 : 33861092 : && !DECL_CONTEXT (*t))
3304 : : {
3305 : : /* In an NSDMI we need to replace the 'this' parameter we used for
3306 : : parsing with the real one for this function. */
3307 : 24008 : *t = current_class_ptr;
3308 : : }
3309 : 32842229 : else if (TREE_CODE (*t) == CONVERT_EXPR
3310 : 32842229 : && CONVERT_EXPR_VBASE_PATH (*t))
3311 : : {
3312 : : /* In an NSDMI build_base_path defers building conversions to morally
3313 : : virtual bases, and we handle it here. */
3314 : 63 : tree basetype = TREE_TYPE (*t);
3315 : 63 : *t = convert_to_base (TREE_OPERAND (*t, 0), basetype,
3316 : : /*check_access=*/false, /*nonnull=*/true,
3317 : : tf_warning_or_error);
3318 : : }
3319 : :
3320 : 34431829 : return NULL_TREE;
3321 : : }
3322 : :
3323 : : /* When we parse a default argument expression, we may create
3324 : : temporary variables via TARGET_EXPRs. When we actually use the
3325 : : default-argument expression, we make a copy of the expression
3326 : : and replace the temporaries with appropriate local versions.
3327 : :
3328 : : If CLEAR_LOCATION is true, override any EXPR_LOCATION with
3329 : : input_location. */
3330 : :
3331 : : tree
3332 : 8153603 : break_out_target_exprs (tree t, bool clear_location /* = false */)
3333 : : {
3334 : 8153603 : static int target_remap_count;
3335 : 8153603 : static splay_tree target_remap;
3336 : :
3337 : : /* We shouldn't be called on templated trees, nor do we want to
3338 : : produce them. */
3339 : 8153603 : gcc_checking_assert (!processing_template_decl);
3340 : :
3341 : 8153603 : if (!target_remap_count++)
3342 : 7743517 : target_remap = splay_tree_new (splay_tree_compare_pointers,
3343 : : /*splay_tree_delete_key_fn=*/NULL,
3344 : : /*splay_tree_delete_value_fn=*/NULL);
3345 : 8153603 : bot_data data = { target_remap, clear_location };
3346 : 8153603 : if (cp_walk_tree (&t, bot_manip, &data, NULL) == error_mark_node)
3347 : 0 : t = error_mark_node;
3348 : 8153603 : if (cp_walk_tree (&t, bot_replace, &data, NULL) == error_mark_node)
3349 : 0 : t = error_mark_node;
3350 : :
3351 : 8153603 : if (!--target_remap_count)
3352 : : {
3353 : 7743517 : splay_tree_delete (target_remap);
3354 : 7743517 : target_remap = NULL;
3355 : : }
3356 : :
3357 : 8153603 : return t;
3358 : : }
3359 : :
3360 : : /* Build an expression for the subobject of OBJ at CONSTRUCTOR index INDEX,
3361 : : which we expect to have type TYPE. */
3362 : :
3363 : : tree
3364 : 580592 : build_ctor_subob_ref (tree index, tree type, tree obj)
3365 : : {
3366 : 580592 : if (index == NULL_TREE)
3367 : : /* Can't refer to a particular member of a vector. */
3368 : : obj = NULL_TREE;
3369 : 580592 : else if (TREE_CODE (index) == INTEGER_CST)
3370 : 6915 : obj = cp_build_array_ref (input_location, obj, index, tf_none);
3371 : : else
3372 : 573677 : obj = build_class_member_access_expr (obj, index, NULL_TREE,
3373 : : /*reference*/false, tf_none);
3374 : 580592 : if (obj)
3375 : : {
3376 : 580592 : tree objtype = TREE_TYPE (obj);
3377 : 580592 : if (TREE_CODE (objtype) == ARRAY_TYPE && !TYPE_DOMAIN (objtype))
3378 : : {
3379 : : /* When the destination object refers to a flexible array member
3380 : : verify that it matches the type of the source object except
3381 : : for its domain and qualifiers. */
3382 : 83 : gcc_assert (comptypes (TYPE_MAIN_VARIANT (type),
3383 : : TYPE_MAIN_VARIANT (objtype),
3384 : : COMPARE_REDECLARATION));
3385 : : }
3386 : : else
3387 : 580509 : gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, objtype));
3388 : : }
3389 : :
3390 : 580592 : return obj;
3391 : : }
3392 : :
3393 : : struct replace_placeholders_t
3394 : : {
3395 : : tree obj; /* The object to be substituted for a PLACEHOLDER_EXPR. */
3396 : : tree exp; /* The outermost exp. */
3397 : : bool seen; /* Whether we've encountered a PLACEHOLDER_EXPR. */
3398 : : hash_set<tree> *pset; /* To avoid walking same trees multiple times. */
3399 : : };
3400 : :
3401 : : /* Like substitute_placeholder_in_expr, but handle C++ tree codes and
3402 : : build up subexpressions as we go deeper. */
3403 : :
3404 : : static tree
3405 : 19402342 : replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
3406 : : {
3407 : 19402342 : replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);
3408 : 19402342 : tree obj = d->obj;
3409 : :
3410 : 19402342 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3411 : : {
3412 : 6336253 : *walk_subtrees = false;
3413 : 6336253 : return NULL_TREE;
3414 : : }
3415 : :
3416 : 13066089 : switch (TREE_CODE (*t))
3417 : : {
3418 : : case PLACEHOLDER_EXPR:
3419 : : {
3420 : : tree x = obj;
3421 : 636 : for (; !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (*t),
3422 : 636 : TREE_TYPE (x));
3423 : 77 : x = TREE_OPERAND (x, 0))
3424 : 77 : gcc_assert (handled_component_p (x));
3425 : 559 : *t = unshare_expr (x);
3426 : 559 : *walk_subtrees = false;
3427 : 559 : d->seen = true;
3428 : : }
3429 : 559 : break;
3430 : :
3431 : 292688 : case CONSTRUCTOR:
3432 : 292688 : {
3433 : 292688 : constructor_elt *ce;
3434 : 292688 : vec<constructor_elt,va_gc> *v = CONSTRUCTOR_ELTS (*t);
3435 : : /* Don't walk into CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctors
3436 : : other than the d->exp one, those have PLACEHOLDER_EXPRs
3437 : : related to another object. */
3438 : 292688 : if ((CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t)
3439 : 622 : && *t != d->exp)
3440 : 293205 : || d->pset->add (*t))
3441 : : {
3442 : 105 : *walk_subtrees = false;
3443 : 105 : return NULL_TREE;
3444 : : }
3445 : 965374 : for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i)
3446 : : {
3447 : 672791 : tree *valp = &ce->value;
3448 : 672791 : tree type = TREE_TYPE (*valp);
3449 : 672791 : tree subob = obj;
3450 : :
3451 : : /* Elements with RANGE_EXPR index shouldn't have any
3452 : : placeholders in them. */
3453 : 672791 : if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
3454 : 2 : continue;
3455 : :
3456 : 672789 : if (TREE_CODE (*valp) == CONSTRUCTOR
3457 : 823 : && AGGREGATE_TYPE_P (type))
3458 : : {
3459 : : /* If we're looking at the initializer for OBJ, then build
3460 : : a sub-object reference. If we're looking at an
3461 : : initializer for another object, just pass OBJ down. */
3462 : 809 : if (same_type_ignoring_top_level_qualifiers_p
3463 : 809 : (TREE_TYPE (*t), TREE_TYPE (obj)))
3464 : 777 : subob = build_ctor_subob_ref (ce->index, type, obj);
3465 : 809 : if (TREE_CODE (*valp) == TARGET_EXPR)
3466 : 0 : valp = &TARGET_EXPR_INITIAL (*valp);
3467 : : }
3468 : 672789 : d->obj = subob;
3469 : 672789 : cp_walk_tree (valp, replace_placeholders_r, data_, NULL);
3470 : 672789 : d->obj = obj;
3471 : : }
3472 : 292583 : *walk_subtrees = false;
3473 : 292583 : break;
3474 : : }
3475 : :
3476 : 12772842 : default:
3477 : 12772842 : if (d->pset->add (*t))
3478 : 435398 : *walk_subtrees = false;
3479 : : break;
3480 : : }
3481 : :
3482 : : return NULL_TREE;
3483 : : }
3484 : :
3485 : : /* Replace PLACEHOLDER_EXPRs in EXP with object OBJ. SEEN_P is set if
3486 : : a PLACEHOLDER_EXPR has been encountered. */
3487 : :
3488 : : tree
3489 : 48465674 : replace_placeholders (tree exp, tree obj, bool *seen_p /*= NULL*/)
3490 : : {
3491 : : /* This is only relevant for C++14. */
3492 : 48465674 : if (cxx_dialect < cxx14)
3493 : 836727 : return exp;
3494 : :
3495 : : /* If the object isn't a (member of a) class, do nothing. */
3496 : : tree op0 = obj;
3497 : 48263601 : while (handled_component_p (op0))
3498 : 634654 : op0 = TREE_OPERAND (op0, 0);
3499 : 47628947 : if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0))))
3500 : 43543747 : return exp;
3501 : :
3502 : 4085200 : tree *tp = &exp;
3503 : 4085200 : if (TREE_CODE (exp) == TARGET_EXPR)
3504 : 315074 : tp = &TARGET_EXPR_INITIAL (exp);
3505 : 4085200 : hash_set<tree> pset;
3506 : 4085200 : replace_placeholders_t data = { obj, *tp, false, &pset };
3507 : 4085200 : cp_walk_tree (tp, replace_placeholders_r, &data, NULL);
3508 : 4085200 : if (seen_p)
3509 : 132025 : *seen_p = data.seen;
3510 : 4085200 : return exp;
3511 : 4085200 : }
3512 : :
3513 : : /* Callback function for find_placeholders. */
3514 : :
3515 : : static tree
3516 : 85137 : find_placeholders_r (tree *t, int *walk_subtrees, void *)
3517 : : {
3518 : 85137 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3519 : : {
3520 : 75822 : *walk_subtrees = false;
3521 : 75822 : return NULL_TREE;
3522 : : }
3523 : :
3524 : 9315 : switch (TREE_CODE (*t))
3525 : : {
3526 : : case PLACEHOLDER_EXPR:
3527 : : return *t;
3528 : :
3529 : 604 : case CONSTRUCTOR:
3530 : 604 : if (CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t))
3531 : 173 : *walk_subtrees = false;
3532 : : break;
3533 : :
3534 : : default:
3535 : : break;
3536 : : }
3537 : :
3538 : : return NULL_TREE;
3539 : : }
3540 : :
3541 : : /* Return true if EXP contains a PLACEHOLDER_EXPR. Don't walk into
3542 : : ctors with CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag set. */
3543 : :
3544 : : bool
3545 : 75865 : find_placeholders (tree exp)
3546 : : {
3547 : : /* This is only relevant for C++14. */
3548 : 75865 : if (cxx_dialect < cxx14)
3549 : : return false;
3550 : :
3551 : 75865 : return cp_walk_tree_without_duplicates (&exp, find_placeholders_r, NULL);
3552 : : }
3553 : :
3554 : : /* Similar to `build_nt', but for template definitions of dependent
3555 : : expressions */
3556 : :
3557 : : tree
3558 : 284054380 : build_min_nt_loc (location_t loc, enum tree_code code, ...)
3559 : : {
3560 : 284054380 : tree t;
3561 : 284054380 : int length;
3562 : 284054380 : int i;
3563 : 284054380 : va_list p;
3564 : :
3565 : 284054380 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3566 : :
3567 : 284054380 : va_start (p, code);
3568 : :
3569 : 284054380 : t = make_node (code);
3570 : 284054380 : SET_EXPR_LOCATION (t, loc);
3571 : 284054380 : length = TREE_CODE_LENGTH (code);
3572 : :
3573 : 930362538 : for (i = 0; i < length; i++)
3574 : 646308158 : TREE_OPERAND (t, i) = va_arg (p, tree);
3575 : :
3576 : 284054380 : va_end (p);
3577 : 284054380 : return t;
3578 : : }
3579 : :
3580 : : /* Similar to `build', but for template definitions. */
3581 : :
3582 : : tree
3583 : 213075108 : build_min (enum tree_code code, tree tt, ...)
3584 : : {
3585 : 213075108 : tree t;
3586 : 213075108 : int length;
3587 : 213075108 : int i;
3588 : 213075108 : va_list p;
3589 : :
3590 : 213075108 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3591 : :
3592 : 213075108 : va_start (p, tt);
3593 : :
3594 : 213075108 : t = make_node (code);
3595 : 213075108 : length = TREE_CODE_LENGTH (code);
3596 : 213075108 : TREE_TYPE (t) = tt;
3597 : :
3598 : 571364840 : for (i = 0; i < length; i++)
3599 : : {
3600 : 358289732 : tree x = va_arg (p, tree);
3601 : 358289732 : TREE_OPERAND (t, i) = x;
3602 : 358289732 : if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
3603 : 2005981 : TREE_SIDE_EFFECTS (t) = 1;
3604 : : }
3605 : :
3606 : 213075108 : va_end (p);
3607 : :
3608 : 213075108 : return t;
3609 : : }
3610 : :
3611 : : /* Similar to `build', but for template definitions of non-dependent
3612 : : expressions. NON_DEP is the non-dependent expression that has been
3613 : : built. */
3614 : :
3615 : : tree
3616 : 108125969 : build_min_non_dep (enum tree_code code, tree non_dep, ...)
3617 : : {
3618 : 108125969 : tree t;
3619 : 108125969 : int length;
3620 : 108125969 : int i;
3621 : 108125969 : va_list p;
3622 : :
3623 : 108125969 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3624 : :
3625 : 108125969 : va_start (p, non_dep);
3626 : :
3627 : 108125969 : if (REFERENCE_REF_P (non_dep))
3628 : 464897 : non_dep = TREE_OPERAND (non_dep, 0);
3629 : :
3630 : 108125969 : t = make_node (code);
3631 : 143963243 : SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep));
3632 : 108125969 : length = TREE_CODE_LENGTH (code);
3633 : 108125969 : TREE_TYPE (t) = unlowered_expr_type (non_dep);
3634 : 108125969 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3635 : :
3636 : 381637522 : for (i = 0; i < length; i++)
3637 : : {
3638 : 273511553 : tree x = va_arg (p, tree);
3639 : 273511553 : TREE_OPERAND (t, i) = x;
3640 : 273511553 : if (x && !TYPE_P (x))
3641 : 212020195 : TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
3642 : : }
3643 : :
3644 : 108125969 : va_end (p);
3645 : 108125969 : return convert_from_reference (t);
3646 : : }
3647 : :
3648 : : /* Similar to build_min_nt, but call expressions */
3649 : :
3650 : : tree
3651 : 188881047 : build_min_nt_call_vec (tree fn, vec<tree, va_gc> *args)
3652 : : {
3653 : 188881047 : tree ret, t;
3654 : 188881047 : unsigned int ix;
3655 : :
3656 : 377660887 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
3657 : 188881047 : CALL_EXPR_FN (ret) = fn;
3658 : 188881047 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
3659 : 385627161 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
3660 : 196746114 : CALL_EXPR_ARG (ret, ix) = t;
3661 : :
3662 : 188881047 : return ret;
3663 : : }
3664 : :
3665 : : /* Similar to `build_min_nt_call_vec', but for template definitions of
3666 : : non-dependent expressions. NON_DEP is the non-dependent expression
3667 : : that has been built. */
3668 : :
3669 : : tree
3670 : 11838106 : build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec)
3671 : : {
3672 : 11838106 : tree t = build_min_nt_call_vec (fn, argvec);
3673 : 11838106 : if (REFERENCE_REF_P (non_dep))
3674 : 6 : non_dep = TREE_OPERAND (non_dep, 0);
3675 : 11838106 : TREE_TYPE (t) = TREE_TYPE (non_dep);
3676 : 11838106 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3677 : 11838106 : if (argvec)
3678 : 20548014 : for (tree x : *argvec)
3679 : 8811115 : if (x && !TYPE_P (x))
3680 : 8811115 : TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
3681 : 11838106 : return convert_from_reference (t);
3682 : : }
3683 : :
3684 : : /* Similar to build_min_non_dep, but for expressions that have been resolved to
3685 : : a call to an operator overload. OP is the operator that has been
3686 : : overloaded. NON_DEP is the non-dependent expression that's been built,
3687 : : which should be a CALL_EXPR or an INDIRECT_REF to a CALL_EXPR. OVERLOAD is
3688 : : the overload that NON_DEP is calling. */
3689 : :
3690 : : tree
3691 : 3902527 : build_min_non_dep_op_overload (enum tree_code op,
3692 : : tree non_dep,
3693 : : tree overload, ...)
3694 : : {
3695 : 3902527 : va_list p;
3696 : 3902527 : int nargs, expected_nargs;
3697 : 3902527 : tree fn, call, obj = NULL_TREE;
3698 : :
3699 : 3902527 : non_dep = extract_call_expr (non_dep);
3700 : :
3701 : 3902527 : nargs = call_expr_nargs (non_dep);
3702 : :
3703 : 3902527 : expected_nargs = cp_tree_code_length (op);
3704 : 7113323 : if (DECL_OBJECT_MEMBER_FUNCTION_P (overload)
3705 : : /* For ARRAY_REF, operator[] is either a non-static member or newly
3706 : : static member, never out of class and for the static member case
3707 : : if user uses single index the operator[] needs to have a single
3708 : : argument as well, but the function is called with 2 - the object
3709 : : it is invoked on and the index. */
3710 : 7111705 : || op == ARRAY_REF)
3711 : 693356 : expected_nargs -= 1;
3712 : 3902527 : if ((op == POSTINCREMENT_EXPR
3713 : 3902527 : || op == POSTDECREMENT_EXPR)
3714 : : /* With -fpermissive non_dep could be operator++(). */
3715 : 10721 : && (!flag_permissive || nargs != expected_nargs))
3716 : 10718 : expected_nargs += 1;
3717 : 3902527 : gcc_assert (nargs == expected_nargs);
3718 : :
3719 : 3902527 : releasing_vec args;
3720 : 3902527 : va_start (p, overload);
3721 : :
3722 : 3902527 : if (!DECL_OBJECT_MEMBER_FUNCTION_P (overload))
3723 : : {
3724 : 3209178 : fn = overload;
3725 : 3209178 : if (op == ARRAY_REF)
3726 : 7 : obj = va_arg (p, tree);
3727 : 9542876 : for (int i = 0; i < nargs; i++)
3728 : : {
3729 : 6333698 : tree arg = va_arg (p, tree);
3730 : 6333698 : vec_safe_push (args, arg);
3731 : : }
3732 : : }
3733 : : else
3734 : : {
3735 : 693349 : tree object = va_arg (p, tree);
3736 : 693349 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
3737 : 693349 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
3738 : 693349 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
3739 : : object, method, NULL_TREE);
3740 : 1176943 : for (int i = 0; i < nargs; i++)
3741 : : {
3742 : 483594 : tree arg = va_arg (p, tree);
3743 : 483594 : vec_safe_push (args, arg);
3744 : : }
3745 : : }
3746 : :
3747 : 3902527 : va_end (p);
3748 : 3902527 : call = build_min_non_dep_call_vec (non_dep, fn, args);
3749 : :
3750 : 3902527 : tree call_expr = extract_call_expr (call);
3751 : 3902527 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
3752 : 3902527 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
3753 : 3902527 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
3754 : 3902527 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
3755 : :
3756 : 3902527 : if (obj)
3757 : 7 : return keep_unused_object_arg (call, obj, overload);
3758 : : return call;
3759 : 3902527 : }
3760 : :
3761 : : /* Similar to above build_min_non_dep_op_overload, but arguments
3762 : : are taken from ARGS vector. */
3763 : :
3764 : : tree
3765 : 22 : build_min_non_dep_op_overload (tree non_dep, tree overload, tree object,
3766 : : vec<tree, va_gc> *args)
3767 : : {
3768 : 22 : non_dep = extract_call_expr (non_dep);
3769 : :
3770 : 22 : unsigned int nargs = call_expr_nargs (non_dep);
3771 : 22 : tree fn = overload;
3772 : 22 : if (DECL_OBJECT_MEMBER_FUNCTION_P (overload))
3773 : : {
3774 : 14 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
3775 : 14 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
3776 : 14 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
3777 : : object, method, NULL_TREE);
3778 : 14 : object = NULL_TREE;
3779 : : }
3780 : 44 : gcc_assert (vec_safe_length (args) == nargs);
3781 : :
3782 : 22 : tree call = build_min_non_dep_call_vec (non_dep, fn, args);
3783 : :
3784 : 22 : tree call_expr = extract_call_expr (call);
3785 : 22 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
3786 : 22 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
3787 : 22 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
3788 : 22 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
3789 : :
3790 : 22 : if (object)
3791 : 8 : return keep_unused_object_arg (call, object, overload);
3792 : : return call;
3793 : : }
3794 : :
3795 : : /* Return a new tree vec copied from VEC, with ELT inserted at index IDX. */
3796 : :
3797 : : vec<tree, va_gc> *
3798 : 2327 : vec_copy_and_insert (vec<tree, va_gc> *old_vec, tree elt, unsigned idx)
3799 : : {
3800 : 2327 : unsigned len = vec_safe_length (old_vec);
3801 : 2327 : gcc_assert (idx <= len);
3802 : :
3803 : 2327 : vec<tree, va_gc> *new_vec = NULL;
3804 : 2327 : vec_alloc (new_vec, len + 1);
3805 : :
3806 : 2327 : unsigned i;
3807 : 7002 : for (i = 0; i < len; ++i)
3808 : : {
3809 : 2348 : if (i == idx)
3810 : 21 : new_vec->quick_push (elt);
3811 : 2348 : new_vec->quick_push ((*old_vec)[i]);
3812 : : }
3813 : 2327 : if (i == idx)
3814 : 2306 : new_vec->quick_push (elt);
3815 : :
3816 : 2327 : return new_vec;
3817 : : }
3818 : :
3819 : : tree
3820 : 137527 : get_type_decl (tree t)
3821 : : {
3822 : 137527 : if (TREE_CODE (t) == TYPE_DECL)
3823 : : return t;
3824 : 137527 : if (TYPE_P (t))
3825 : 137527 : return TYPE_STUB_DECL (t);
3826 : 0 : gcc_assert (t == error_mark_node);
3827 : : return t;
3828 : : }
3829 : :
3830 : : /* Returns the namespace that contains DECL, whether directly or
3831 : : indirectly. */
3832 : :
3833 : : tree
3834 : 971470353 : decl_namespace_context (tree decl)
3835 : : {
3836 : 2017870998 : while (1)
3837 : : {
3838 : 2017870998 : if (TREE_CODE (decl) == NAMESPACE_DECL)
3839 : 971470353 : return decl;
3840 : 1046400645 : else if (TYPE_P (decl))
3841 : 630849406 : decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
3842 : : else
3843 : 415551239 : decl = CP_DECL_CONTEXT (decl);
3844 : : }
3845 : : }
3846 : :
3847 : : /* Returns true if decl is within an anonymous namespace, however deeply
3848 : : nested, or false otherwise. */
3849 : :
3850 : : bool
3851 : 23 : decl_anon_ns_mem_p (tree decl)
3852 : : {
3853 : 23 : return !TREE_PUBLIC (decl_namespace_context (decl));
3854 : : }
3855 : :
3856 : : /* Returns true if the enclosing scope of DECL has internal or no linkage. */
3857 : :
3858 : : bool
3859 : 1156619710 : decl_internal_context_p (const_tree decl)
3860 : : {
3861 : 2316775972 : while (TREE_CODE (decl) != NAMESPACE_DECL)
3862 : : {
3863 : : /* Classes inside anonymous namespaces have TREE_PUBLIC == 0. */
3864 : 1451135437 : if (TYPE_P (decl))
3865 : 290979175 : return !TREE_PUBLIC (TYPE_MAIN_DECL (decl));
3866 : :
3867 : 1160156262 : decl = CP_DECL_CONTEXT (decl);
3868 : : }
3869 : 865640535 : return !TREE_PUBLIC (decl);
3870 : : }
3871 : :
3872 : : /* Subroutine of cp_tree_equal: t1 and t2 are two CALL_EXPRs.
3873 : : Return whether their CALL_EXPR_FNs are equivalent. */
3874 : :
3875 : : static bool
3876 : 43854684 : called_fns_equal (tree t1, tree t2)
3877 : : {
3878 : : /* Core 1321: dependent names are equivalent even if the overload sets
3879 : : are different. But do compare explicit template arguments. */
3880 : 43854684 : tree name1 = call_expr_dependent_name (t1);
3881 : 43854684 : tree name2 = call_expr_dependent_name (t2);
3882 : 43854684 : t1 = CALL_EXPR_FN (t1);
3883 : 43854684 : t2 = CALL_EXPR_FN (t2);
3884 : 43854684 : if (name1 || name2)
3885 : : {
3886 : 19759458 : tree targs1 = NULL_TREE, targs2 = NULL_TREE;
3887 : :
3888 : 19759458 : if (name1 != name2)
3889 : : return false;
3890 : :
3891 : : /* FIXME dependent_name currently returns an unqualified name regardless
3892 : : of whether the function was named with a qualified- or unqualified-id.
3893 : : Until that's fixed, check that we aren't looking at overload sets from
3894 : : different scopes. */
3895 : 19243157 : if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
3896 : 38516172 : && (DECL_CONTEXT (get_first_fn (t1))
3897 : 19243154 : != DECL_CONTEXT (get_first_fn (t2))))
3898 : : return false;
3899 : :
3900 : 19273018 : if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
3901 : 12212231 : targs1 = TREE_OPERAND (t1, 1);
3902 : 19273018 : if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
3903 : 12212231 : targs2 = TREE_OPERAND (t2, 1);
3904 : 19273018 : return cp_tree_equal (targs1, targs2);
3905 : : }
3906 : : else
3907 : 24095226 : return cp_tree_equal (t1, t2);
3908 : : }
3909 : :
3910 : : bool comparing_override_contracts;
3911 : :
3912 : : /* In a component reference, return the innermost object of
3913 : : the postfix-expression. */
3914 : :
3915 : : static tree
3916 : 12 : get_innermost_component (tree t)
3917 : : {
3918 : 12 : gcc_assert (TREE_CODE (t) == COMPONENT_REF);
3919 : 33 : while (TREE_CODE (t) == COMPONENT_REF)
3920 : 21 : t = TREE_OPERAND (t, 0);
3921 : 12 : return t;
3922 : : }
3923 : :
3924 : : /* Returns true if T is a possibly converted 'this' or '*this' expression. */
3925 : :
3926 : : static bool
3927 : 12 : is_this_expression (tree t)
3928 : : {
3929 : 12 : t = get_innermost_component (t);
3930 : : /* See through deferences and no-op conversions. */
3931 : 12 : if (INDIRECT_REF_P (t))
3932 : 12 : t = TREE_OPERAND (t, 0);
3933 : 12 : if (TREE_CODE (t) == NOP_EXPR)
3934 : 12 : t = TREE_OPERAND (t, 0);
3935 : 12 : return is_this_parameter (t);
3936 : : }
3937 : :
3938 : : static bool
3939 : 6 : comparing_this_references (tree t1, tree t2)
3940 : : {
3941 : 6 : return is_this_expression (t1) && is_this_expression (t2);
3942 : : }
3943 : :
3944 : : static bool
3945 : 6 : equivalent_member_references (tree t1, tree t2)
3946 : : {
3947 : 6 : if (!comparing_this_references (t1, t2))
3948 : : return false;
3949 : 6 : t1 = TREE_OPERAND (t1, 1);
3950 : 6 : t2 = TREE_OPERAND (t2, 1);
3951 : 6 : return t1 == t2;
3952 : : }
3953 : :
3954 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
3955 : : Return 1 if they are the same. Return 0 if they are different. */
3956 : :
3957 : : bool
3958 : 1619977072 : cp_tree_equal (tree t1, tree t2)
3959 : : {
3960 : 1622724491 : enum tree_code code1, code2;
3961 : :
3962 : 1622724491 : if (t1 == t2)
3963 : : return true;
3964 : 708599086 : if (!t1 || !t2)
3965 : : return false;
3966 : :
3967 : 708389104 : code1 = TREE_CODE (t1);
3968 : 708389104 : code2 = TREE_CODE (t2);
3969 : :
3970 : 708389104 : if (code1 != code2)
3971 : : return false;
3972 : :
3973 : 575412400 : if (CONSTANT_CLASS_P (t1)
3974 : 575412400 : && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
3975 : : return false;
3976 : :
3977 : 575334830 : switch (code1)
3978 : : {
3979 : 0 : case VOID_CST:
3980 : : /* There's only a single VOID_CST node, so we should never reach
3981 : : here. */
3982 : 0 : gcc_unreachable ();
3983 : :
3984 : 35898353 : case INTEGER_CST:
3985 : 35898353 : return tree_int_cst_equal (t1, t2);
3986 : :
3987 : 121298 : case REAL_CST:
3988 : 121298 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
3989 : :
3990 : 52015 : case STRING_CST:
3991 : 52015 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3992 : 52015 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3993 : 52015 : TREE_STRING_LENGTH (t1));
3994 : :
3995 : 0 : case FIXED_CST:
3996 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
3997 : : TREE_FIXED_CST (t2));
3998 : :
3999 : 1 : case COMPLEX_CST:
4000 : 1 : return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
4001 : 2 : && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
4002 : :
4003 : 3991 : case VECTOR_CST:
4004 : 3991 : return operand_equal_p (t1, t2, OEP_ONLY_CONST);
4005 : :
4006 : 1475492 : case CONSTRUCTOR:
4007 : : /* We need to do this when determining whether or not two
4008 : : non-type pointer to member function template arguments
4009 : : are the same. */
4010 : 1475492 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
4011 : 3235459 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
4012 : : return false;
4013 : : {
4014 : : tree field, value;
4015 : : unsigned int i;
4016 : 1520205 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
4017 : : {
4018 : 145780 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
4019 : 145780 : if (!cp_tree_equal (field, elt2->index)
4020 : 145780 : || !cp_tree_equal (value, elt2->value))
4021 : 14 : return false;
4022 : : }
4023 : : }
4024 : : return true;
4025 : :
4026 : 2434355 : case TREE_LIST:
4027 : 2434355 : if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
4028 : : return false;
4029 : 2434355 : if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
4030 : : return false;
4031 : 39873 : return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
4032 : :
4033 : 651 : case SAVE_EXPR:
4034 : 651 : return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4035 : :
4036 : 43859748 : case CALL_EXPR:
4037 : 43859748 : {
4038 : 43859748 : if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
4039 : : return false;
4040 : :
4041 : 43854684 : if (!called_fns_equal (t1, t2))
4042 : : return false;
4043 : :
4044 : 14572017 : call_expr_arg_iterator iter1, iter2;
4045 : 14572017 : init_call_expr_arg_iterator (t1, &iter1);
4046 : 14572017 : init_call_expr_arg_iterator (t2, &iter2);
4047 : 14572017 : if (iter1.n != iter2.n)
4048 : : return false;
4049 : :
4050 : 15340301 : while (more_call_expr_args_p (&iter1))
4051 : : {
4052 : 7561251 : tree arg1 = next_call_expr_arg (&iter1);
4053 : 7561251 : tree arg2 = next_call_expr_arg (&iter2);
4054 : :
4055 : 7561251 : gcc_checking_assert (arg1 && arg2);
4056 : 7561251 : if (!cp_tree_equal (arg1, arg2))
4057 : : return false;
4058 : : }
4059 : :
4060 : : return true;
4061 : : }
4062 : :
4063 : 207377 : case TARGET_EXPR:
4064 : 207377 : {
4065 : 207377 : tree o1 = TARGET_EXPR_SLOT (t1);
4066 : 207377 : tree o2 = TARGET_EXPR_SLOT (t2);
4067 : :
4068 : : /* Special case: if either target is an unallocated VAR_DECL,
4069 : : it means that it's going to be unified with whatever the
4070 : : TARGET_EXPR is really supposed to initialize, so treat it
4071 : : as being equivalent to anything. */
4072 : 207377 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
4073 : 414754 : && !DECL_RTL_SET_P (o1))
4074 : : /*Nop*/;
4075 : 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
4076 : 0 : && !DECL_RTL_SET_P (o2))
4077 : : /*Nop*/;
4078 : 0 : else if (!cp_tree_equal (o1, o2))
4079 : : return false;
4080 : :
4081 : 207377 : return cp_tree_equal (TARGET_EXPR_INITIAL (t1),
4082 : 414754 : TARGET_EXPR_INITIAL (t2));
4083 : : }
4084 : :
4085 : 21 : case AGGR_INIT_EXPR:
4086 : 21 : {
4087 : 21 : int n = aggr_init_expr_nargs (t1);
4088 : 21 : if (n != aggr_init_expr_nargs (t2))
4089 : : return false;
4090 : :
4091 : 42 : if (!cp_tree_equal (AGGR_INIT_EXPR_FN (t1),
4092 : 21 : AGGR_INIT_EXPR_FN (t2)))
4093 : : return false;
4094 : :
4095 : 21 : tree o1 = AGGR_INIT_EXPR_SLOT (t1);
4096 : 21 : tree o2 = AGGR_INIT_EXPR_SLOT (t2);
4097 : :
4098 : : /* Similarly to TARGET_EXPRs, if the VAR_DECL is unallocated we're
4099 : : going to unify the initialization, so treat it as equivalent
4100 : : to anything. */
4101 : 21 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
4102 : 42 : && !DECL_RTL_SET_P (o1))
4103 : : /*Nop*/;
4104 : 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
4105 : 0 : && !DECL_RTL_SET_P (o2))
4106 : : /*Nop*/;
4107 : 0 : else if (!cp_tree_equal (o1, o2))
4108 : : return false;
4109 : :
4110 : 41 : for (int i = 0; i < n; ++i)
4111 : 23 : if (!cp_tree_equal (AGGR_INIT_EXPR_ARG (t1, i),
4112 : 23 : AGGR_INIT_EXPR_ARG (t2, i)))
4113 : : return false;
4114 : :
4115 : : return true;
4116 : : }
4117 : :
4118 : 1016181 : case PARM_DECL:
4119 : : /* For comparing uses of parameters in late-specified return types
4120 : : with an out-of-class definition of the function, but can also come
4121 : : up for expressions that involve 'this' in a member function
4122 : : template. */
4123 : :
4124 : 1016181 : if (comparing_specializations
4125 : 1016181 : && DECL_CONTEXT (t1) != DECL_CONTEXT (t2))
4126 : : /* When comparing hash table entries, only an exact match is
4127 : : good enough; we don't want to replace 'this' with the
4128 : : version from another function. But be more flexible
4129 : : with parameters with identical contexts. */
4130 : : return false;
4131 : :
4132 : 710252 : if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4133 : : {
4134 : 300986 : if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
4135 : : return false;
4136 : 300986 : if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
4137 : : return false;
4138 : 300986 : if (DECL_ARTIFICIAL (t1)
4139 : 300986 : || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
4140 : 300341 : && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
4141 : : return true;
4142 : : }
4143 : : return false;
4144 : :
4145 : 23060718 : case TEMPLATE_DECL:
4146 : 23060718 : if (DECL_TEMPLATE_TEMPLATE_PARM_P (t1)
4147 : 29140765 : && DECL_TEMPLATE_TEMPLATE_PARM_P (t2))
4148 : 187810 : return cp_tree_equal (TREE_TYPE (t1), TREE_TYPE (t2));
4149 : : /* Fall through. */
4150 : : case VAR_DECL:
4151 : : case CONST_DECL:
4152 : : case FIELD_DECL:
4153 : : case FUNCTION_DECL:
4154 : : case IDENTIFIER_NODE:
4155 : : case SSA_NAME:
4156 : : case USING_DECL:
4157 : : case DEFERRED_PARSE:
4158 : : return false;
4159 : :
4160 : 14267302 : case BASELINK:
4161 : 14267302 : return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
4162 : 13563828 : && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
4163 : 13563828 : && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
4164 : 27831114 : && cp_tree_equal (BASELINK_FUNCTIONS (t1),
4165 : 13563812 : BASELINK_FUNCTIONS (t2)));
4166 : :
4167 : 13474187 : case TEMPLATE_PARM_INDEX:
4168 : 13474187 : return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
4169 : 12777765 : && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
4170 : 12148215 : && (TEMPLATE_PARM_PARAMETER_PACK (t1)
4171 : 12148215 : == TEMPLATE_PARM_PARAMETER_PACK (t2))
4172 : 25615204 : && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
4173 : : TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
4174 : :
4175 : 25943481 : case TEMPLATE_ID_EXPR:
4176 : 25943481 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4177 : : return false;
4178 : 19961331 : if (!comp_template_args (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)))
4179 : : return false;
4180 : : return true;
4181 : :
4182 : 2311285 : case CONSTRAINT_INFO:
4183 : 6933855 : return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1),
4184 : 6933855 : CI_ASSOCIATED_CONSTRAINTS (t2));
4185 : :
4186 : 28425643 : case TREE_VEC:
4187 : : /* These are template args. Really we should be getting the
4188 : : caller to do this as it knows it to be true. */
4189 : 28425643 : if (!comp_template_args (t1, t2))
4190 : : return false;
4191 : : return true;
4192 : :
4193 : 917711 : case SIZEOF_EXPR:
4194 : 917711 : case ALIGNOF_EXPR:
4195 : 917711 : {
4196 : 917711 : tree o1 = TREE_OPERAND (t1, 0);
4197 : 917711 : tree o2 = TREE_OPERAND (t2, 0);
4198 : :
4199 : 917711 : if (code1 == SIZEOF_EXPR)
4200 : : {
4201 : 908037 : if (SIZEOF_EXPR_TYPE_P (t1))
4202 : 0 : o1 = TREE_TYPE (o1);
4203 : 908037 : if (SIZEOF_EXPR_TYPE_P (t2))
4204 : 0 : o2 = TREE_TYPE (o2);
4205 : : }
4206 : 9674 : else if (ALIGNOF_EXPR_STD_P (t1) != ALIGNOF_EXPR_STD_P (t2))
4207 : : return false;
4208 : :
4209 : 917705 : if (TREE_CODE (o1) != TREE_CODE (o2))
4210 : : return false;
4211 : :
4212 : 917695 : if (ARGUMENT_PACK_P (o1))
4213 : 2 : return template_args_equal (o1, o2);
4214 : 917693 : else if (TYPE_P (o1))
4215 : 917327 : return same_type_p (o1, o2);
4216 : : else
4217 : : return cp_tree_equal (o1, o2);
4218 : : }
4219 : :
4220 : 109 : case MODOP_EXPR:
4221 : 109 : {
4222 : 109 : tree t1_op1, t2_op1;
4223 : :
4224 : 109 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4225 : : return false;
4226 : :
4227 : 109 : t1_op1 = TREE_OPERAND (t1, 1);
4228 : 109 : t2_op1 = TREE_OPERAND (t2, 1);
4229 : 109 : if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
4230 : : return false;
4231 : :
4232 : 57 : return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
4233 : : }
4234 : :
4235 : 679 : case PTRMEM_CST:
4236 : : /* Two pointer-to-members are the same if they point to the same
4237 : : field or function in the same class. */
4238 : 679 : if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
4239 : : return false;
4240 : :
4241 : 658 : return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
4242 : :
4243 : 4215359 : case OVERLOAD:
4244 : 4215359 : {
4245 : : /* Two overloads. Must be exactly the same set of decls. */
4246 : 4215359 : lkp_iterator first (t1);
4247 : 4215359 : lkp_iterator second (t2);
4248 : :
4249 : 4223984 : for (; first && second; ++first, ++second)
4250 : 4215858 : if (*first != *second)
4251 : : return false;
4252 : 8126 : return !(first || second);
4253 : : }
4254 : :
4255 : 7513775 : case TRAIT_EXPR:
4256 : 7513775 : if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
4257 : : return false;
4258 : 757434 : return cp_tree_equal (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
4259 : 1472539 : && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
4260 : :
4261 : 376753 : case NON_LVALUE_EXPR:
4262 : 376753 : case VIEW_CONVERT_EXPR:
4263 : : /* Used for location wrappers with possibly NULL types. */
4264 : 376753 : if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
4265 : : {
4266 : 21 : if (TREE_TYPE (t1) || TREE_TYPE (t2))
4267 : : return false;
4268 : : break;
4269 : : }
4270 : : /* FALLTHROUGH */
4271 : :
4272 : 3541970 : case CAST_EXPR:
4273 : 3541970 : case STATIC_CAST_EXPR:
4274 : 3541970 : case REINTERPRET_CAST_EXPR:
4275 : 3541970 : case CONST_CAST_EXPR:
4276 : 3541970 : case DYNAMIC_CAST_EXPR:
4277 : 3541970 : case IMPLICIT_CONV_EXPR:
4278 : 3541970 : case NEW_EXPR:
4279 : 3541970 : case BIT_CAST_EXPR:
4280 : 3541970 : CASE_CONVERT:
4281 : 3541970 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4282 : : return false;
4283 : : /* Now compare operands as usual. */
4284 : : break;
4285 : :
4286 : 0 : case DEFERRED_NOEXCEPT:
4287 : 0 : return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1),
4288 : 0 : DEFERRED_NOEXCEPT_PATTERN (t2))
4289 : 0 : && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1),
4290 : 0 : DEFERRED_NOEXCEPT_ARGS (t2)));
4291 : :
4292 : : case LAMBDA_EXPR:
4293 : : /* Two lambda-expressions are never considered equivalent. */
4294 : : return false;
4295 : :
4296 : 292152163 : case TYPE_ARGUMENT_PACK:
4297 : 292152163 : case NONTYPE_ARGUMENT_PACK:
4298 : 292152163 : {
4299 : 292152163 : tree p1 = ARGUMENT_PACK_ARGS (t1);
4300 : 292152163 : tree p2 = ARGUMENT_PACK_ARGS (t2);
4301 : 292152163 : int len = TREE_VEC_LENGTH (p1);
4302 : 292152163 : if (TREE_VEC_LENGTH (p2) != len)
4303 : : return false;
4304 : :
4305 : 402504171 : for (int ix = 0; ix != len; ix++)
4306 : 330888146 : if (!template_args_equal (TREE_VEC_ELT (p1, ix),
4307 : 330888146 : TREE_VEC_ELT (p2, ix)))
4308 : : return false;
4309 : : return true;
4310 : : }
4311 : :
4312 : 309169 : case EXPR_PACK_EXPANSION:
4313 : 309169 : if (!cp_tree_equal (PACK_EXPANSION_PATTERN (t1),
4314 : 309169 : PACK_EXPANSION_PATTERN (t2)))
4315 : : return false;
4316 : 19057 : if (!comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
4317 : 19057 : PACK_EXPANSION_EXTRA_ARGS (t2)))
4318 : : return false;
4319 : : return true;
4320 : :
4321 : 18 : case PACK_INDEX_EXPR:
4322 : 18 : if (!cp_tree_equal (PACK_INDEX_PACK (t1),
4323 : 18 : PACK_INDEX_PACK (t2)))
4324 : : return false;
4325 : 8 : if (!cp_tree_equal (PACK_INDEX_INDEX (t1),
4326 : 8 : PACK_INDEX_INDEX (t2)))
4327 : : return false;
4328 : : return true;
4329 : :
4330 : 779055 : case COMPONENT_REF:
4331 : : /* If we're comparing contract conditions of overrides, member references
4332 : : compare equal if they designate the same member. */
4333 : 779055 : if (comparing_override_contracts)
4334 : 6 : return equivalent_member_references (t1, t2);
4335 : : break;
4336 : :
4337 : : default:
4338 : : break;
4339 : : }
4340 : :
4341 : 59757538 : switch (TREE_CODE_CLASS (code1))
4342 : : {
4343 : 53437879 : case tcc_unary:
4344 : 53437879 : case tcc_binary:
4345 : 53437879 : case tcc_comparison:
4346 : 53437879 : case tcc_expression:
4347 : 53437879 : case tcc_vl_exp:
4348 : 53437879 : case tcc_reference:
4349 : 53437879 : case tcc_statement:
4350 : 53437879 : {
4351 : 53437879 : int n = cp_tree_operand_length (t1);
4352 : 53437879 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
4353 : 53437879 : && n != TREE_OPERAND_LENGTH (t2))
4354 : : return false;
4355 : :
4356 : 99951154 : for (int i = 0; i < n; ++i)
4357 : 75401655 : if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
4358 : : return false;
4359 : :
4360 : : return true;
4361 : : }
4362 : :
4363 : 6319659 : case tcc_type:
4364 : 6319659 : return same_type_p (t1, t2);
4365 : :
4366 : 0 : default:
4367 : 0 : gcc_unreachable ();
4368 : : }
4369 : :
4370 : : /* We can get here with --disable-checking. */
4371 : : return false;
4372 : : }
4373 : :
4374 : : /* The type of ARG when used as an lvalue. */
4375 : :
4376 : : tree
4377 : 662364828 : lvalue_type (tree arg)
4378 : : {
4379 : 662364828 : tree type = TREE_TYPE (arg);
4380 : 662364828 : return type;
4381 : : }
4382 : :
4383 : : /* The type of ARG for printing error messages; denote lvalues with
4384 : : reference types. */
4385 : :
4386 : : tree
4387 : 3658 : error_type (tree arg)
4388 : : {
4389 : 3658 : tree type = TREE_TYPE (arg);
4390 : :
4391 : 3658 : if (TREE_CODE (type) == ARRAY_TYPE)
4392 : : ;
4393 : 3526 : else if (TREE_CODE (type) == ERROR_MARK)
4394 : : ;
4395 : 3526 : else if (lvalue_p (arg))
4396 : 1233 : type = build_reference_type (lvalue_type (arg));
4397 : 2293 : else if (MAYBE_CLASS_TYPE_P (type))
4398 : 744 : type = lvalue_type (arg);
4399 : :
4400 : 3658 : return type;
4401 : : }
4402 : :
4403 : : /* Does FUNCTION use a variable-length argument list? */
4404 : :
4405 : : int
4406 : 284454 : varargs_function_p (const_tree function)
4407 : : {
4408 : 284454 : return stdarg_p (TREE_TYPE (function));
4409 : : }
4410 : :
4411 : : /* Returns 1 if decl is a member of a class. */
4412 : :
4413 : : int
4414 : 10916 : member_p (const_tree decl)
4415 : : {
4416 : 10916 : const_tree const ctx = DECL_CONTEXT (decl);
4417 : 10916 : return (ctx && TYPE_P (ctx));
4418 : : }
4419 : :
4420 : : /* Create a placeholder for member access where we don't actually have an
4421 : : object that the access is against. For a general declval<T> equivalent,
4422 : : use build_stub_object instead. */
4423 : :
4424 : : tree
4425 : 63456590 : build_dummy_object (tree type)
4426 : : {
4427 : 63456590 : tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node);
4428 : 63456590 : return cp_build_fold_indirect_ref (decl);
4429 : : }
4430 : :
4431 : : /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
4432 : : or a dummy object otherwise. If BINFOP is non-0, it is filled with the
4433 : : binfo path from current_class_type to TYPE, or 0. */
4434 : :
4435 : : tree
4436 : 97940670 : maybe_dummy_object (tree type, tree* binfop)
4437 : : {
4438 : 97940670 : tree decl, context;
4439 : 97940670 : tree binfo;
4440 : 97940670 : tree current = current_nonlambda_class_type ();
4441 : :
4442 : 97940670 : if (current
4443 : 97940670 : && (binfo = lookup_base (current, type, ba_any, NULL,
4444 : : tf_warning_or_error)))
4445 : : context = current;
4446 : : else
4447 : : {
4448 : : /* Reference from a nested class member function. */
4449 : 11458522 : context = type;
4450 : 11458522 : binfo = TYPE_BINFO (type);
4451 : : }
4452 : :
4453 : 97940670 : if (binfop)
4454 : 114904 : *binfop = binfo;
4455 : :
4456 : : /* current_class_ref might not correspond to current_class_type if
4457 : : we're in tsubst_default_argument or a lambda-declarator; in either
4458 : : case, we want to use current_class_ref if it matches CONTEXT. */
4459 : 97940670 : tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE;
4460 : 90971301 : if (ctype
4461 : 90971301 : && same_type_ignoring_top_level_qualifiers_p (ctype, context))
4462 : 83777723 : decl = current_class_ref;
4463 : : else
4464 : : {
4465 : : /* Return a dummy object whose cv-quals are consistent with (the
4466 : : non-lambda) 'this' if available. */
4467 : 14162947 : if (ctype)
4468 : : {
4469 : 7193578 : int quals = TYPE_UNQUALIFIED;
4470 : 7193578 : if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype))
4471 : : {
4472 : 307599 : if (tree cap = lambda_expr_this_capture (lambda, false))
4473 : 300649 : quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap)));
4474 : : }
4475 : : else
4476 : 6885979 : quals = cp_type_quals (ctype);
4477 : 7193578 : context = cp_build_qualified_type (context, quals);
4478 : : }
4479 : 14162947 : decl = build_dummy_object (context);
4480 : : }
4481 : :
4482 : 97940670 : return decl;
4483 : : }
4484 : :
4485 : : /* Returns 1 if OB is a placeholder object, or a pointer to one. */
4486 : :
4487 : : bool
4488 : 430541827 : is_dummy_object (const_tree ob)
4489 : : {
4490 : 430541827 : if (INDIRECT_REF_P (ob))
4491 : 339699274 : ob = TREE_OPERAND (ob, 0);
4492 : 430541827 : return (TREE_CODE (ob) == CONVERT_EXPR
4493 : 430541827 : && TREE_OPERAND (ob, 0) == void_node);
4494 : : }
4495 : :
4496 : : /* Returns true if TYPE is char, unsigned char, or std::byte. */
4497 : :
4498 : : bool
4499 : 27361892 : is_byte_access_type (tree type)
4500 : : {
4501 : 27361892 : type = TYPE_MAIN_VARIANT (type);
4502 : 27361892 : if (type == char_type_node
4503 : 5033513 : || type == unsigned_char_type_node)
4504 : : return true;
4505 : :
4506 : 4907392 : return (TREE_CODE (type) == ENUMERAL_TYPE
4507 : 7763 : && TYPE_CONTEXT (type) == std_node
4508 : 4912240 : && !strcmp ("byte", TYPE_NAME_STRING (type)));
4509 : : }
4510 : :
4511 : : /* Returns true if TYPE is unsigned char or std::byte. */
4512 : :
4513 : : bool
4514 : 1918 : is_byte_access_type_not_plain_char (tree type)
4515 : : {
4516 : 1918 : type = TYPE_MAIN_VARIANT (type);
4517 : 1918 : if (type == char_type_node)
4518 : : return false;
4519 : :
4520 : 1670 : return is_byte_access_type (type);
4521 : : }
4522 : :
4523 : : /* Returns 1 iff type T is something we want to treat as a scalar type for
4524 : : the purpose of deciding whether it is trivial/POD/standard-layout. */
4525 : :
4526 : : bool
4527 : 46348162 : scalarish_type_p (const_tree t)
4528 : : {
4529 : 46348162 : if (t == error_mark_node)
4530 : : return 1;
4531 : :
4532 : 46347962 : return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
4533 : : }
4534 : :
4535 : : /* Returns true iff T requires non-trivial default initialization. */
4536 : :
4537 : : bool
4538 : 0 : type_has_nontrivial_default_init (const_tree t)
4539 : : {
4540 : 0 : t = strip_array_types (CONST_CAST_TREE (t));
4541 : :
4542 : 0 : if (CLASS_TYPE_P (t))
4543 : 0 : return TYPE_HAS_COMPLEX_DFLT (t);
4544 : : else
4545 : : return 0;
4546 : : }
4547 : :
4548 : : /* Track classes with only deleted copy/move constructors so that we can warn
4549 : : if they are used in call/return by value. */
4550 : :
4551 : : static GTY(()) hash_set<tree>* deleted_copy_types;
4552 : : static void
4553 : 9 : remember_deleted_copy (const_tree t)
4554 : : {
4555 : 9 : if (!deleted_copy_types)
4556 : 9 : deleted_copy_types = hash_set<tree>::create_ggc(37);
4557 : 9 : deleted_copy_types->add (CONST_CAST_TREE (t));
4558 : 9 : }
4559 : : void
4560 : 310554675 : maybe_warn_parm_abi (tree t, location_t loc)
4561 : : {
4562 : 310554675 : if (!deleted_copy_types
4563 : 310554675 : || !deleted_copy_types->contains (t))
4564 : 310554645 : return;
4565 : :
4566 : 30 : if ((flag_abi_version == 12 || warn_abi_version == 12)
4567 : 36 : && classtype_has_non_deleted_move_ctor (t))
4568 : : {
4569 : 6 : bool w;
4570 : 6 : auto_diagnostic_group d;
4571 : 6 : if (flag_abi_version > 12)
4572 : 0 : w = warning_at (loc, OPT_Wabi, "%<-fabi-version=13%> (GCC 8.2) fixes "
4573 : : "the calling convention for %qT, which was "
4574 : : "accidentally changed in 8.1", t);
4575 : : else
4576 : 6 : w = warning_at (loc, OPT_Wabi, "%<-fabi-version=12%> (GCC 8.1) "
4577 : : "accidentally changes the calling convention for %qT",
4578 : : t);
4579 : 6 : if (w)
4580 : 6 : inform (location_of (t), " declared here");
4581 : 6 : return;
4582 : 6 : }
4583 : :
4584 : 30 : auto_diagnostic_group d;
4585 : 30 : if (warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in "
4586 : : "%<-fabi-version=13%> (GCC 8.2)", t))
4587 : 30 : inform (location_of (t), " because all of its copy and move "
4588 : : "constructors are deleted");
4589 : 30 : }
4590 : :
4591 : : /* Returns true iff copying an object of type T (including via move
4592 : : constructor) is non-trivial. That is, T has no non-trivial copy
4593 : : constructors and no non-trivial move constructors, and not all copy/move
4594 : : constructors are deleted. This function implements the ABI notion of
4595 : : non-trivial copy, which has diverged from the one in the standard. */
4596 : :
4597 : : bool
4598 : 43297200 : type_has_nontrivial_copy_init (const_tree type)
4599 : : {
4600 : 43297200 : tree t = strip_array_types (CONST_CAST_TREE (type));
4601 : :
4602 : 43297200 : if (CLASS_TYPE_P (t))
4603 : : {
4604 : 42695153 : gcc_assert (COMPLETE_TYPE_P (t));
4605 : :
4606 : 42695153 : if (TYPE_HAS_COMPLEX_COPY_CTOR (t)
4607 : 42695153 : || TYPE_HAS_COMPLEX_MOVE_CTOR (t))
4608 : : /* Nontrivial. */
4609 : : return true;
4610 : :
4611 : 39080344 : if (cxx_dialect < cxx11)
4612 : : /* No deleted functions before C++11. */
4613 : : return false;
4614 : :
4615 : : /* Before ABI v12 we did a bitwise copy of types with only deleted
4616 : : copy/move constructors. */
4617 : 38988918 : if (!abi_version_at_least (12)
4618 : 8132 : && !(warn_abi && abi_version_crosses (12)))
4619 : : return false;
4620 : :
4621 : 38981016 : bool saw_copy = false;
4622 : 38981016 : bool saw_non_deleted = false;
4623 : 38981016 : bool saw_non_deleted_move = false;
4624 : :
4625 : 38981016 : if (CLASSTYPE_LAZY_MOVE_CTOR (t))
4626 : : saw_copy = saw_non_deleted = true;
4627 : 3498228 : else if (CLASSTYPE_LAZY_COPY_CTOR (t))
4628 : : {
4629 : 495294 : saw_copy = true;
4630 : 495294 : if (classtype_has_move_assign_or_move_ctor_p (t, true))
4631 : : /* [class.copy]/8 If the class definition declares a move
4632 : : constructor or move assignment operator, the implicitly declared
4633 : : copy constructor is defined as deleted.... */;
4634 : : else
4635 : : /* Any other reason the implicitly-declared function would be
4636 : : deleted would also cause TYPE_HAS_COMPLEX_COPY_CTOR to be
4637 : : set. */
4638 : : saw_non_deleted = true;
4639 : : }
4640 : :
4641 : : if (!saw_non_deleted)
4642 : 14016072 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
4643 : : {
4644 : 8221861 : tree fn = *iter;
4645 : 8221861 : if (copy_fn_p (fn))
4646 : : {
4647 : 3002937 : saw_copy = true;
4648 : 3002937 : if (!DECL_DELETED_FN (fn))
4649 : : {
4650 : : /* Not deleted, therefore trivial. */
4651 : : saw_non_deleted = true;
4652 : : break;
4653 : : }
4654 : : }
4655 : 5218924 : else if (move_fn_p (fn))
4656 : 1996380 : if (!DECL_DELETED_FN (fn))
4657 : 1991554 : saw_non_deleted_move = true;
4658 : : }
4659 : :
4660 : 38981016 : gcc_assert (saw_copy);
4661 : :
4662 : : /* ABI v12 buggily ignored move constructors. */
4663 : 38981016 : bool v11nontriv = false;
4664 : 38981016 : bool v12nontriv = !saw_non_deleted;
4665 : 38981016 : bool v13nontriv = !saw_non_deleted && !saw_non_deleted_move;
4666 : 38981016 : bool nontriv = (abi_version_at_least (13) ? v13nontriv
4667 : 124 : : flag_abi_version == 12 ? v12nontriv
4668 : 124 : : v11nontriv);
4669 : 38981421 : bool warn_nontriv = (warn_abi_version >= 13 ? v13nontriv
4670 : 405 : : warn_abi_version == 12 ? v12nontriv
4671 : : : v11nontriv);
4672 : 38981016 : if (nontriv != warn_nontriv)
4673 : 9 : remember_deleted_copy (t);
4674 : :
4675 : 38981016 : return nontriv;
4676 : : }
4677 : : else
4678 : : return 0;
4679 : : }
4680 : :
4681 : : /* Returns 1 iff type T is a trivially copyable type, as defined in
4682 : : [basic.types] and [class]. */
4683 : :
4684 : : bool
4685 : 156162 : trivially_copyable_p (const_tree t)
4686 : : {
4687 : 156162 : t = strip_array_types (CONST_CAST_TREE (t));
4688 : :
4689 : 156162 : if (CLASS_TYPE_P (t))
4690 : 38970 : return ((!TYPE_HAS_COPY_CTOR (t)
4691 : 38970 : || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
4692 : 38069 : && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
4693 : 38029 : && (!TYPE_HAS_COPY_ASSIGN (t)
4694 : 38029 : || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
4695 : 37061 : && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
4696 : 75863 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
4697 : : else
4698 : : /* CWG 2094 makes volatile-qualified scalars trivially copyable again. */
4699 : 117192 : return scalarish_type_p (t);
4700 : : }
4701 : :
4702 : : /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
4703 : : [class]. */
4704 : :
4705 : : bool
4706 : 49567 : trivial_type_p (const_tree t)
4707 : : {
4708 : 49567 : t = strip_array_types (CONST_CAST_TREE (t));
4709 : :
4710 : 49567 : if (CLASS_TYPE_P (t))
4711 : : /* A trivial class is a class that is trivially copyable and has one or
4712 : : more eligible default constructors, all of which are trivial. */
4713 : 19880 : return (type_has_non_deleted_trivial_default_ctor (CONST_CAST_TREE (t))
4714 : 19880 : && trivially_copyable_p (t));
4715 : : else
4716 : 29687 : return scalarish_type_p (t);
4717 : : }
4718 : :
4719 : : /* Returns 1 iff type T is a default-movable type, as defined in
4720 : : [class.prop]. */
4721 : :
4722 : : static bool
4723 : 681 : default_movable_type_p (tree t)
4724 : : {
4725 : 681 : if (!CLASS_TYPE_P (t) || !COMPLETE_TYPE_P (t))
4726 : : return false;
4727 : 681 : if (CLASSTYPE_LAZY_DESTRUCTOR (t))
4728 : 249 : lazily_declare_fn (sfk_destructor, t);
4729 : 681 : if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
4730 : 681 : if (user_provided_p (dtor) || DECL_DELETED_FN (dtor))
4731 : : return false;
4732 : :
4733 : 597 : tree copy_ctor = NULL_TREE, move_ctor = NULL_TREE;
4734 : 597 : tree copy_assign = NULL_TREE, move_assign = NULL_TREE;
4735 : 597 : if (CLASSTYPE_LAZY_MOVE_CTOR (t))
4736 : 132 : move_ctor = lazily_declare_fn (sfk_move_constructor, t);
4737 : 597 : if (CLASSTYPE_LAZY_MOVE_ASSIGN (t))
4738 : 141 : move_assign = lazily_declare_fn (sfk_move_assignment, t);
4739 : 597 : if (!move_ctor)
4740 : 795 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
4741 : 507 : if (TREE_CODE (*iter) == FUNCTION_DECL)
4742 : : {
4743 : 501 : if (copy_fn_p (*iter))
4744 : 180 : copy_ctor = *iter;
4745 : 321 : else if (move_fn_p (*iter))
4746 : : {
4747 : 270 : move_ctor = *iter;
4748 : 270 : break;
4749 : : }
4750 : : }
4751 : 597 : if (!move_assign)
4752 : 96 : for (ovl_iterator iter (get_class_binding_direct (t,
4753 : 456 : assign_op_identifier));
4754 : 552 : iter; ++iter)
4755 : 318 : if (TREE_CODE (*iter) == FUNCTION_DECL)
4756 : : {
4757 : 318 : if (copy_fn_p (*iter))
4758 : 90 : copy_assign = *iter;
4759 : 228 : else if (move_fn_p (*iter))
4760 : : {
4761 : 222 : move_assign = *iter;
4762 : 222 : break;
4763 : : }
4764 : : }
4765 : 597 : if (!move_ctor)
4766 : : {
4767 : 195 : if (CLASSTYPE_LAZY_COPY_CTOR (t))
4768 : 48 : copy_ctor = lazily_declare_fn (sfk_copy_constructor, t);
4769 : 195 : if (!copy_ctor)
4770 : : return false;
4771 : 195 : if (user_provided_p (copy_ctor)
4772 : 165 : || DECL_DELETED_FN (copy_ctor)
4773 : 78 : || DECL_CONTEXT (copy_ctor) != t
4774 : 351 : || DECL_INHERITED_CTOR (copy_ctor))
4775 : : return false;
4776 : : }
4777 : 402 : else if (user_provided_p (move_ctor)
4778 : 357 : || DECL_DELETED_FN (move_ctor)
4779 : 312 : || DECL_CONTEXT (move_ctor) != t
4780 : 1026 : || DECL_INHERITED_CTOR (move_ctor))
4781 : : return false;
4782 : 384 : if (!move_assign)
4783 : : {
4784 : 90 : if (CLASSTYPE_LAZY_COPY_ASSIGN (t))
4785 : 27 : copy_assign = lazily_declare_fn (sfk_copy_assignment, t);
4786 : 90 : if (!copy_assign)
4787 : : return false;
4788 : 90 : if (user_provided_p (copy_assign)
4789 : 72 : || DECL_DELETED_FN (copy_assign)
4790 : 138 : || DECL_CONTEXT (copy_assign) != t)
4791 : : return false;
4792 : : }
4793 : 294 : else if (user_provided_p (move_assign)
4794 : 288 : || DECL_DELETED_FN (move_assign)
4795 : 507 : || DECL_CONTEXT (move_assign) != t)
4796 : : return false;
4797 : : return true;
4798 : : }
4799 : :
4800 : : /* Returns 1 iff type T is a union with no user declared special member
4801 : : functions. */
4802 : :
4803 : : static bool
4804 : 738 : union_with_no_declared_special_member_fns (tree t)
4805 : : {
4806 : 738 : if (TREE_CODE (t) != UNION_TYPE)
4807 : : return false;
4808 : :
4809 : 156 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
4810 : 57 : if (TREE_CODE (*iter) == FUNCTION_DECL
4811 : 57 : && !DECL_ARTIFICIAL (*iter)
4812 : 93 : && (default_ctor_p (*iter) || copy_fn_p (*iter) || move_fn_p (*iter)))
4813 : 36 : return false;
4814 : :
4815 : 93 : for (ovl_iterator iter (get_class_binding_direct (t, assign_op_identifier));
4816 : 93 : iter; ++iter)
4817 : 24 : if (TREE_CODE (*iter) == FUNCTION_DECL
4818 : 24 : && !DECL_ARTIFICIAL (*iter)
4819 : 48 : && (copy_fn_p (*iter) || move_fn_p (*iter)))
4820 : 24 : return false;
4821 : :
4822 : 69 : if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
4823 : 27 : if (!DECL_ARTIFICIAL (dtor))
4824 : : return false;
4825 : :
4826 : : return true;
4827 : : }
4828 : :
4829 : : /* Returns 1 iff type T is a trivially relocatable type, as defined in
4830 : : [basic.types.general] and [class.prop]. */
4831 : :
4832 : : bool
4833 : 833 : trivially_relocatable_type_p (tree t)
4834 : : {
4835 : 833 : t = strip_array_types (t);
4836 : :
4837 : 833 : if (!CLASS_TYPE_P (t))
4838 : 174 : return scalarish_type_p (t);
4839 : :
4840 : 659 : t = TYPE_MAIN_VARIANT (t);
4841 : 659 : if (CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED (t))
4842 : 186 : return CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (t);
4843 : 473 : if (!COMPLETE_TYPE_P (t))
4844 : : return false;
4845 : :
4846 : 473 : if (!CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (t)
4847 : 348 : && !union_with_no_declared_special_member_fns (t)
4848 : 794 : && !default_movable_type_p (t))
4849 : : {
4850 : 264 : nontriv:
4851 : 264 : CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (t) = 0;
4852 : 264 : CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED (t) = 1;
4853 : 264 : return false;
4854 : : }
4855 : :
4856 : 266 : if (CLASSTYPE_VBASECLASSES (t))
4857 : 21 : goto nontriv;
4858 : :
4859 : 245 : if (CLASSTYPE_LAZY_DESTRUCTOR (t))
4860 : 92 : lazily_declare_fn (sfk_destructor, t);
4861 : 245 : if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
4862 : 245 : if (DECL_DELETED_FN (dtor))
4863 : 9 : goto nontriv;
4864 : :
4865 : 236 : tree binfo, base_binfo;
4866 : 236 : unsigned int i;
4867 : 251 : for (binfo = TYPE_BINFO (t), i = 0;
4868 : 251 : BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
4869 : : {
4870 : 24 : tree basetype = TREE_TYPE (base_binfo);
4871 : 24 : if (!trivially_relocatable_type_p (basetype))
4872 : 9 : goto nontriv;
4873 : : }
4874 : :
4875 : 2082 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
4876 : 1873 : if (TREE_CODE (field) == FIELD_DECL
4877 : 229 : && !DECL_ARTIFICIAL (field)
4878 : 2089 : && !DECL_UNNAMED_BIT_FIELD (field))
4879 : : {
4880 : 216 : tree type = TREE_TYPE (field);
4881 : 216 : if (type == error_mark_node)
4882 : 0 : goto nontriv;
4883 : 216 : if (!TYPE_REF_P (type) && !trivially_relocatable_type_p (type))
4884 : 18 : goto nontriv;
4885 : : }
4886 : :
4887 : 209 : CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (t) = 1;
4888 : 209 : CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED (t) = 1;
4889 : 209 : return true;
4890 : : }
4891 : :
4892 : : /* Returns 1 iff type T is a replaceable type, as defined in [basic.types]
4893 : : and [class]. */
4894 : :
4895 : : bool
4896 : 719 : replaceable_type_p (tree t)
4897 : : {
4898 : 719 : t = strip_array_types (t);
4899 : :
4900 : 719 : if (cv_qualified_p (t))
4901 : : return false;
4902 : :
4903 : 680 : if (!CLASS_TYPE_P (t))
4904 : 120 : return scalarish_type_p (t);
4905 : :
4906 : 560 : t = TYPE_MAIN_VARIANT (t);
4907 : 560 : if (CLASSTYPE_REPLACEABLE_COMPUTED (t))
4908 : 69 : return CLASSTYPE_REPLACEABLE_BIT (t);
4909 : 491 : if (!COMPLETE_TYPE_P (t))
4910 : : return false;
4911 : :
4912 : 491 : if (!CLASSTYPE_REPLACEABLE_BIT (t)
4913 : 390 : && !union_with_no_declared_special_member_fns (t)
4914 : 851 : && !default_movable_type_p (t))
4915 : : {
4916 : 315 : nonrepl:
4917 : 315 : CLASSTYPE_REPLACEABLE_BIT (t) = 0;
4918 : 315 : CLASSTYPE_REPLACEABLE_COMPUTED (t) = 1;
4919 : 315 : return false;
4920 : : }
4921 : :
4922 : 272 : if (CLASSTYPE_LAZY_DESTRUCTOR (t))
4923 : 19 : lazily_declare_fn (sfk_destructor, t);
4924 : 272 : if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
4925 : 272 : if (DECL_DELETED_FN (dtor))
4926 : 15 : goto nonrepl;
4927 : :
4928 : 257 : tree copy_ctor = NULL_TREE, move_ctor = NULL_TREE;
4929 : 257 : tree copy_assign = NULL_TREE, move_assign = NULL_TREE;
4930 : 257 : if (CLASSTYPE_LAZY_MOVE_CTOR (t))
4931 : 24 : move_ctor = lazily_declare_fn (sfk_move_constructor, t);
4932 : 257 : if (CLASSTYPE_LAZY_MOVE_ASSIGN (t))
4933 : 24 : move_assign = lazily_declare_fn (sfk_move_assignment, t);
4934 : 257 : if (!move_ctor)
4935 : 281 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
4936 : 239 : if (TREE_CODE (*iter) == FUNCTION_DECL)
4937 : : {
4938 : 239 : if (copy_fn_p (*iter))
4939 : 36 : copy_ctor = *iter;
4940 : 203 : else if (move_fn_p (*iter))
4941 : : {
4942 : 197 : move_ctor = *iter;
4943 : 197 : break;
4944 : : }
4945 : : }
4946 : 257 : if (!move_assign)
4947 : 36 : for (ovl_iterator iter (get_class_binding_direct (t,
4948 : 233 : assign_op_identifier));
4949 : 269 : iter; ++iter)
4950 : 236 : if (TREE_CODE (*iter) == FUNCTION_DECL)
4951 : : {
4952 : 236 : if (copy_fn_p (*iter))
4953 : 33 : copy_assign = *iter;
4954 : 203 : else if (move_fn_p (*iter))
4955 : : {
4956 : 200 : move_assign = *iter;
4957 : 200 : break;
4958 : : }
4959 : : }
4960 : 257 : if (!move_ctor)
4961 : : {
4962 : 36 : if (CLASSTYPE_LAZY_COPY_CTOR (t))
4963 : 0 : copy_ctor = lazily_declare_fn (sfk_copy_constructor, t);
4964 : 36 : if (!copy_ctor || DECL_DELETED_FN (copy_ctor))
4965 : 6 : goto nonrepl;
4966 : : }
4967 : 221 : else if (DECL_DELETED_FN (move_ctor))
4968 : 18 : goto nonrepl;
4969 : 233 : if (!move_assign)
4970 : : {
4971 : 30 : if (CLASSTYPE_LAZY_COPY_ASSIGN (t))
4972 : 0 : copy_assign = lazily_declare_fn (sfk_copy_assignment, t);
4973 : 30 : if (!copy_assign || DECL_DELETED_FN (copy_assign))
4974 : 3 : goto nonrepl;
4975 : : }
4976 : 203 : else if (DECL_DELETED_FN (move_assign))
4977 : 6 : goto nonrepl;
4978 : :
4979 : 224 : tree binfo, base_binfo;
4980 : 224 : unsigned int i;
4981 : 260 : for (binfo = TYPE_BINFO (t), i = 0;
4982 : 260 : BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
4983 : : {
4984 : 48 : tree basetype = TREE_TYPE (base_binfo);
4985 : 48 : if (!replaceable_type_p (basetype))
4986 : 12 : goto nonrepl;
4987 : : }
4988 : :
4989 : 2176 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
4990 : 2000 : if (TREE_CODE (field) == FIELD_DECL
4991 : 187 : && !DECL_ARTIFICIAL (field)
4992 : 2147 : && !DECL_UNNAMED_BIT_FIELD (field))
4993 : : {
4994 : 147 : tree type = TREE_TYPE (field);
4995 : 147 : if (type == error_mark_node)
4996 : 0 : goto nonrepl;
4997 : 147 : if (!replaceable_type_p (type))
4998 : 36 : goto nonrepl;
4999 : : }
5000 : :
5001 : 176 : CLASSTYPE_REPLACEABLE_BIT (t) = 1;
5002 : 176 : CLASSTYPE_REPLACEABLE_COMPUTED (t) = 1;
5003 : 176 : return true;
5004 : : }
5005 : :
5006 : : /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
5007 : :
5008 : : bool
5009 : 11823 : pod_type_p (const_tree t)
5010 : : {
5011 : : /* This CONST_CAST is okay because strip_array_types returns its
5012 : : argument unmodified and we assign it to a const_tree. */
5013 : 11823 : t = strip_array_types (CONST_CAST_TREE(t));
5014 : :
5015 : 11823 : if (!CLASS_TYPE_P (t))
5016 : 694 : return scalarish_type_p (t);
5017 : 11129 : else if (cxx_dialect > cxx98)
5018 : : /* [class]/10: A POD struct is a class that is both a trivial class and a
5019 : : standard-layout class, and has no non-static data members of type
5020 : : non-POD struct, non-POD union (or array of such types).
5021 : :
5022 : : We don't need to check individual members because if a member is
5023 : : non-std-layout or non-trivial, the class will be too. */
5024 : 10912 : return (std_layout_type_p (t) && trivial_type_p (t));
5025 : : else
5026 : : /* The C++98 definition of POD is different. */
5027 : 217 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
5028 : : }
5029 : :
5030 : : /* Returns true iff T is POD for the purpose of layout, as defined in the
5031 : : C++ ABI. */
5032 : :
5033 : : bool
5034 : 15661764 : layout_pod_type_p (const_tree t)
5035 : : {
5036 : 15661764 : t = strip_array_types (CONST_CAST_TREE (t));
5037 : :
5038 : 15661764 : if (CLASS_TYPE_P (t))
5039 : 2937996 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
5040 : : else
5041 : 12723768 : return scalarish_type_p (t);
5042 : : }
5043 : :
5044 : : /* Returns true iff T is a standard-layout type, as defined in
5045 : : [basic.types]. */
5046 : :
5047 : : bool
5048 : 15722427 : std_layout_type_p (const_tree t)
5049 : : {
5050 : 15722427 : t = strip_array_types (CONST_CAST_TREE (t));
5051 : :
5052 : 15722427 : if (CLASS_TYPE_P (t))
5053 : 2950784 : return !CLASSTYPE_NON_STD_LAYOUT (t);
5054 : : else
5055 : 12771643 : return scalarish_type_p (t);
5056 : : }
5057 : :
5058 : : static bool record_has_unique_obj_representations (const_tree, const_tree);
5059 : :
5060 : : /* Returns true iff T satisfies std::has_unique_object_representations<T>,
5061 : : as defined in [meta.unary.prop]. */
5062 : :
5063 : : bool
5064 : 21319 : type_has_unique_obj_representations (const_tree t)
5065 : : {
5066 : 23644 : bool ret;
5067 : :
5068 : 23644 : t = strip_array_types (CONST_CAST_TREE (t));
5069 : :
5070 : 23644 : if (!trivially_copyable_p (t))
5071 : : return false;
5072 : :
5073 : 23631 : if (CLASS_TYPE_P (t) && CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t))
5074 : 66 : return CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t);
5075 : :
5076 : 23565 : switch (TREE_CODE (t))
5077 : : {
5078 : : case INTEGER_TYPE:
5079 : : case POINTER_TYPE:
5080 : : case REFERENCE_TYPE:
5081 : : /* If some backend has any paddings in these types, we should add
5082 : : a target hook for this and handle it there. */
5083 : : return true;
5084 : :
5085 : : case BOOLEAN_TYPE:
5086 : : /* For bool values other than 0 and 1 should only appear with
5087 : : undefined behavior. */
5088 : : return true;
5089 : :
5090 : 2307 : case ENUMERAL_TYPE:
5091 : 2307 : return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t));
5092 : :
5093 : : case REAL_TYPE:
5094 : : /* XFmode certainly contains padding on x86, which the CPU doesn't store
5095 : : when storing long double values, so for that we have to return false.
5096 : : Other kinds of floating point values are questionable due to +.0/-.0
5097 : : and NaNs, let's play safe for now. */
5098 : : return false;
5099 : :
5100 : : case FIXED_POINT_TYPE:
5101 : : return false;
5102 : :
5103 : : case OFFSET_TYPE:
5104 : : return true;
5105 : :
5106 : 18 : case COMPLEX_TYPE:
5107 : 18 : case VECTOR_TYPE:
5108 : 18 : return type_has_unique_obj_representations (TREE_TYPE (t));
5109 : :
5110 : 71 : case RECORD_TYPE:
5111 : 71 : ret = record_has_unique_obj_representations (t, TYPE_SIZE (t));
5112 : 71 : if (CLASS_TYPE_P (t))
5113 : : {
5114 : 68 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
5115 : 68 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
5116 : : }
5117 : : return ret;
5118 : :
5119 : 9 : case UNION_TYPE:
5120 : 9 : ret = true;
5121 : 9 : bool any_fields;
5122 : 9 : any_fields = false;
5123 : 24 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5124 : 21 : if (TREE_CODE (field) == FIELD_DECL)
5125 : : {
5126 : 18 : any_fields = true;
5127 : 18 : if (!type_has_unique_obj_representations (TREE_TYPE (field))
5128 : 18 : || simple_cst_equal (DECL_SIZE (field), TYPE_SIZE (t)) != 1)
5129 : : {
5130 : : ret = false;
5131 : : break;
5132 : : }
5133 : : }
5134 : 9 : if (!any_fields && !integer_zerop (TYPE_SIZE (t)))
5135 : : ret = false;
5136 : 9 : if (CLASS_TYPE_P (t))
5137 : : {
5138 : 9 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
5139 : 9 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
5140 : : }
5141 : : return ret;
5142 : :
5143 : : case NULLPTR_TYPE:
5144 : : return false;
5145 : :
5146 : : case ERROR_MARK:
5147 : : return false;
5148 : :
5149 : 0 : default:
5150 : 0 : gcc_unreachable ();
5151 : : }
5152 : : }
5153 : :
5154 : : /* Helper function for type_has_unique_obj_representations. */
5155 : :
5156 : : static bool
5157 : 76 : record_has_unique_obj_representations (const_tree t, const_tree sz)
5158 : : {
5159 : 504 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5160 : 434 : if (TREE_CODE (field) != FIELD_DECL)
5161 : : ;
5162 : : /* For bases, can't use type_has_unique_obj_representations here, as in
5163 : : struct S { int i : 24; S (); };
5164 : : struct T : public S { int j : 8; T (); };
5165 : : S doesn't have unique obj representations, but T does. */
5166 : 111 : else if (DECL_FIELD_IS_BASE (field))
5167 : : {
5168 : 5 : if (!record_has_unique_obj_representations (TREE_TYPE (field),
5169 : 5 : DECL_SIZE (field)))
5170 : : return false;
5171 : : }
5172 : 106 : else if (DECL_C_BIT_FIELD (field) && !DECL_UNNAMED_BIT_FIELD (field))
5173 : : {
5174 : 37 : tree btype = DECL_BIT_FIELD_TYPE (field);
5175 : 37 : if (!type_has_unique_obj_representations (btype))
5176 : : return false;
5177 : : }
5178 : 69 : else if (!type_has_unique_obj_representations (TREE_TYPE (field)))
5179 : : return false;
5180 : :
5181 : 70 : offset_int cur = 0;
5182 : 461 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5183 : 408 : if (TREE_CODE (field) == FIELD_DECL && !DECL_UNNAMED_BIT_FIELD (field))
5184 : : {
5185 : 93 : offset_int fld = wi::to_offset (DECL_FIELD_OFFSET (field));
5186 : 93 : offset_int bitpos = wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
5187 : 93 : fld = fld * BITS_PER_UNIT + bitpos;
5188 : 93 : if (cur != fld)
5189 : 17 : return false;
5190 : 76 : if (DECL_SIZE (field))
5191 : : {
5192 : 73 : offset_int size = wi::to_offset (DECL_SIZE (field));
5193 : 73 : cur += size;
5194 : : }
5195 : : }
5196 : 53 : if (cur != wi::to_offset (sz))
5197 : : return false;
5198 : :
5199 : : return true;
5200 : : }
5201 : :
5202 : : /* Nonzero iff type T is a class template implicit specialization. */
5203 : :
5204 : : bool
5205 : 100670732 : class_tmpl_impl_spec_p (const_tree t)
5206 : : {
5207 : 100670732 : return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
5208 : : }
5209 : :
5210 : : /* Returns 1 iff zero initialization of type T means actually storing
5211 : : zeros in it. */
5212 : :
5213 : : int
5214 : 17569141 : zero_init_p (const_tree t)
5215 : : {
5216 : : /* This CONST_CAST is okay because strip_array_types returns its
5217 : : argument unmodified and we assign it to a const_tree. */
5218 : 17569141 : t = strip_array_types (CONST_CAST_TREE(t));
5219 : :
5220 : 17569141 : if (t == error_mark_node)
5221 : : return 1;
5222 : :
5223 : : /* NULL pointers to data members are initialized with -1. */
5224 : 17569141 : if (TYPE_PTRDATAMEM_P (t))
5225 : : return 0;
5226 : :
5227 : : /* Classes that contain types that can't be zero-initialized, cannot
5228 : : be zero-initialized themselves. */
5229 : 17568550 : if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
5230 : 120 : return 0;
5231 : :
5232 : : return 1;
5233 : : }
5234 : :
5235 : : /* Returns true if the expression or initializer T is the result of
5236 : : zero-initialization for its type, taking pointers to members
5237 : : into consideration. */
5238 : :
5239 : : bool
5240 : 177853 : zero_init_expr_p (tree t)
5241 : : {
5242 : 177853 : tree type = TREE_TYPE (t);
5243 : 177853 : if (!type || uses_template_parms (type))
5244 : 0 : return false;
5245 : 177853 : if (TYPE_PTRMEM_P (type))
5246 : 1041 : return null_member_pointer_value_p (t);
5247 : 176812 : if (TREE_CODE (t) == CONSTRUCTOR)
5248 : : {
5249 : 74638 : if (COMPOUND_LITERAL_P (t)
5250 : 74638 : || BRACE_ENCLOSED_INITIALIZER_P (t))
5251 : : /* Undigested, conversions might change the zeroness. */
5252 : : return false;
5253 : 220262 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (t))
5254 : : {
5255 : 75378 : if (TREE_CODE (type) == UNION_TYPE
5256 : 75378 : && elt.index != first_field (type))
5257 : : return false;
5258 : 75369 : if (!zero_init_expr_p (elt.value))
5259 : : return false;
5260 : : }
5261 : : return true;
5262 : : }
5263 : 102174 : if (zero_init_p (type))
5264 : 102174 : return initializer_zerop (t);
5265 : : return false;
5266 : : }
5267 : :
5268 : : /* True IFF T is a C++20 structural type (P1907R1) that can be used as a
5269 : : non-type template parameter. If EXPLAIN, explain why not. */
5270 : :
5271 : : bool
5272 : 9511 : structural_type_p (tree t, bool explain)
5273 : : {
5274 : : /* A structural type is one of the following: */
5275 : :
5276 : : /* a scalar type, or */
5277 : 9511 : if (SCALAR_TYPE_P (t))
5278 : : return true;
5279 : : /* an lvalue reference type, or */
5280 : 5383 : if (TYPE_REF_P (t) && !TYPE_REF_IS_RVALUE (t))
5281 : : return true;
5282 : : /* a literal class type with the following properties:
5283 : : - all base classes and non-static data members are public and non-mutable
5284 : : and
5285 : : - the types of all bases classes and non-static data members are
5286 : : structural types or (possibly multi-dimensional) array thereof. */
5287 : 5376 : if (!CLASS_TYPE_P (t))
5288 : : return false;
5289 : 5374 : if (!literal_type_p (t))
5290 : : {
5291 : 13 : if (explain)
5292 : 6 : explain_non_literal_class (t);
5293 : 13 : return false;
5294 : : }
5295 : 9690 : for (tree m = next_aggregate_field (TYPE_FIELDS (t)); m;
5296 : 4329 : m = next_aggregate_field (DECL_CHAIN (m)))
5297 : : {
5298 : 4338 : if (TREE_PRIVATE (m) || TREE_PROTECTED (m))
5299 : : {
5300 : 9 : if (explain)
5301 : : {
5302 : 3 : if (DECL_FIELD_IS_BASE (m))
5303 : 3 : inform (location_of (m), "base class %qT is not public",
5304 : 3 : TREE_TYPE (m));
5305 : : else
5306 : 0 : inform (location_of (m), "%qD is not public", m);
5307 : : }
5308 : 9 : return false;
5309 : : }
5310 : 4329 : if (DECL_MUTABLE_P (m))
5311 : : {
5312 : 0 : if (explain)
5313 : 0 : inform (location_of (m), "%qD is mutable", m);
5314 : 0 : return false;
5315 : : }
5316 : 4329 : tree mtype = strip_array_types (TREE_TYPE (m));
5317 : 4329 : if (!structural_type_p (mtype))
5318 : : {
5319 : 0 : if (explain)
5320 : : {
5321 : 0 : inform (location_of (m), "%qD has a non-structural type", m);
5322 : 0 : structural_type_p (mtype, true);
5323 : : }
5324 : 0 : return false;
5325 : : }
5326 : : }
5327 : : return true;
5328 : : }
5329 : :
5330 : : /* Partially handle the C++11 [[carries_dependency]] attribute.
5331 : : Just emit a different diagnostics when it is used on something the
5332 : : spec doesn't allow vs. where it allows and we just choose to ignore
5333 : : it. */
5334 : :
5335 : : static tree
5336 : 142 : handle_carries_dependency_attribute (tree *node, tree name,
5337 : : tree ARG_UNUSED (args),
5338 : : int ARG_UNUSED (flags),
5339 : : bool *no_add_attrs)
5340 : : {
5341 : 142 : if (TREE_CODE (*node) != FUNCTION_DECL
5342 : 121 : && TREE_CODE (*node) != PARM_DECL)
5343 : : {
5344 : 76 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5345 : : "functions or parameters", name);
5346 : 76 : *no_add_attrs = true;
5347 : : }
5348 : : else
5349 : : {
5350 : 66 : warning (OPT_Wattributes, "%qE attribute ignored", name);
5351 : 66 : *no_add_attrs = true;
5352 : : }
5353 : 142 : return NULL_TREE;
5354 : : }
5355 : :
5356 : : /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
5357 : : warn_unused_result attribute. */
5358 : :
5359 : : static tree
5360 : 11143412 : handle_nodiscard_attribute (tree *node, tree name, tree args,
5361 : : int /*flags*/, bool *no_add_attrs)
5362 : : {
5363 : 11143553 : if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
5364 : : {
5365 : 6 : error ("%qE attribute argument must be a string constant", name);
5366 : 6 : *no_add_attrs = true;
5367 : : }
5368 : 11143412 : if (TREE_CODE (*node) == FUNCTION_DECL)
5369 : : {
5370 : 11140890 : if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))
5371 : 11247065 : && !DECL_CONSTRUCTOR_P (*node))
5372 : 9 : warning_at (DECL_SOURCE_LOCATION (*node),
5373 : 9 : OPT_Wattributes, "%qE attribute applied to %qD with void "
5374 : : "return type", name, *node);
5375 : : }
5376 : 2522 : else if (OVERLOAD_TYPE_P (*node))
5377 : : /* OK */;
5378 : : else
5379 : : {
5380 : 148 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5381 : : "functions or to class or enumeration types", name);
5382 : 148 : *no_add_attrs = true;
5383 : : }
5384 : 11143412 : return NULL_TREE;
5385 : : }
5386 : :
5387 : : /* Handle a C++20 "no_unique_address" attribute; arguments as in
5388 : : struct attribute_spec.handler. */
5389 : : static tree
5390 : 269898 : handle_no_unique_addr_attribute (tree* node,
5391 : : tree name,
5392 : : tree /*args*/,
5393 : : int /*flags*/,
5394 : : bool* no_add_attrs)
5395 : : {
5396 : 269898 : if (TREE_CODE (*node) == VAR_DECL)
5397 : : {
5398 : 48 : DECL_MERGEABLE (*node) = true;
5399 : 48 : if (pedantic)
5400 : 42 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5401 : : "non-static data members", name);
5402 : : }
5403 : 269850 : else if (TREE_CODE (*node) != FIELD_DECL)
5404 : : {
5405 : 82 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5406 : : "non-static data members", name);
5407 : 82 : *no_add_attrs = true;
5408 : : }
5409 : 269768 : else if (DECL_C_BIT_FIELD (*node))
5410 : : {
5411 : 6 : warning (OPT_Wattributes, "%qE attribute cannot be applied to "
5412 : : "a bit-field", name);
5413 : 6 : *no_add_attrs = true;
5414 : : }
5415 : :
5416 : 269898 : return NULL_TREE;
5417 : : }
5418 : :
5419 : : /* The C++20 [[likely]] and [[unlikely]] attributes on labels map to the GNU
5420 : : hot/cold attributes. */
5421 : :
5422 : : static tree
5423 : 392 : handle_likeliness_attribute (tree *node, tree name, tree args,
5424 : : int flags, bool *no_add_attrs)
5425 : : {
5426 : 392 : *no_add_attrs = true;
5427 : 392 : if (TREE_CODE (*node) == LABEL_DECL
5428 : 392 : || TREE_CODE (*node) == FUNCTION_DECL)
5429 : : {
5430 : 90 : if (args)
5431 : 0 : warning (OPT_Wattributes, "%qE attribute takes no arguments", name);
5432 : 90 : tree bname = (is_attribute_p ("likely", name)
5433 : 90 : ? get_identifier ("hot") : get_identifier ("cold"));
5434 : 90 : if (TREE_CODE (*node) == FUNCTION_DECL)
5435 : 33 : warning (OPT_Wattributes, "ISO C++ %qE attribute does not apply to "
5436 : : "functions; treating as %<[[gnu::%E]]%>", name, bname);
5437 : 90 : tree battr = build_tree_list (bname, NULL_TREE);
5438 : 90 : decl_attributes (node, battr, flags);
5439 : 90 : return NULL_TREE;
5440 : : }
5441 : : else
5442 : 302 : return error_mark_node;
5443 : : }
5444 : :
5445 : : /* The C++11 alignment specifier. It mostly maps to GNU aligned attribute,
5446 : : but we need to do some extra pedantic checking. */
5447 : :
5448 : : static tree
5449 : 229068 : handle_alignas_attribute (tree *node, tree name, tree args, int flags,
5450 : : bool *no_add_attrs)
5451 : : {
5452 : 229068 : tree t = *node;
5453 : 229068 : tree ret = handle_aligned_attribute (node, name, args, flags, no_add_attrs);
5454 : 229068 : if (pedantic)
5455 : : {
5456 : 1116 : if (TREE_CODE (*node) == FUNCTION_DECL)
5457 : 15 : pedwarn (input_location, OPT_Wattributes,
5458 : : "%<alignas%> on function declaration");
5459 : 1101 : else if (TREE_CODE (*node) == ENUMERAL_TYPE)
5460 : 9 : pedwarn (input_location, OPT_Wattributes,
5461 : : "%<alignas%> on enumerated type");
5462 : 1092 : else if (TYPE_P (*node) && t != *node)
5463 : 56 : pedwarn (input_location, OPT_Wattributes,
5464 : : "%<alignas%> on a type other than class");
5465 : 1036 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_C_BIT_FIELD (*node))
5466 : 9 : pedwarn (input_location, OPT_Wattributes, "%<alignas%> on bit-field");
5467 : 1027 : else if (TREE_CODE (t) == TYPE_DECL)
5468 : 9 : pedwarn (input_location, OPT_Wattributes,
5469 : : "%<alignas%> on a type alias");
5470 : : }
5471 : 229068 : return ret;
5472 : : }
5473 : :
5474 : : /* The C++14 [[deprecated]] attribute mostly maps to the GNU deprecated
5475 : : attribute. */
5476 : :
5477 : : static tree
5478 : 711357 : handle_std_deprecated_attribute (tree *node, tree name, tree args, int flags,
5479 : : bool *no_add_attrs)
5480 : : {
5481 : 711357 : tree t = *node;
5482 : 711357 : tree ret = handle_deprecated_attribute (node, name, args, flags,
5483 : : no_add_attrs);
5484 : 711357 : if (TYPE_P (*node) && t != *node)
5485 : 48 : pedwarn (input_location, OPT_Wattributes,
5486 : : "%qE on a type other than class or enumeration definition", name);
5487 : 711309 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5488 : 4 : pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
5489 : : name);
5490 : 711357 : return ret;
5491 : : }
5492 : :
5493 : : /* The C++17 [[maybe_unused]] attribute mostly maps to the GNU unused
5494 : : attribute. */
5495 : :
5496 : : static tree
5497 : 68119 : handle_maybe_unused_attribute (tree *node, tree name, tree args, int flags,
5498 : : bool *no_add_attrs)
5499 : : {
5500 : 68119 : tree t = *node;
5501 : 68119 : tree ret = handle_unused_attribute (node, name, args, flags, no_add_attrs);
5502 : 68119 : if (TYPE_P (*node) && t != *node)
5503 : 36 : pedwarn (input_location, OPT_Wattributes,
5504 : : "%qE on a type other than class or enumeration definition", name);
5505 : 68083 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5506 : 3 : pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
5507 : : name);
5508 : 68080 : else if (TREE_CODE (*node) == LABEL_DECL && DECL_NAME (*node) == NULL_TREE)
5509 : 6 : pedwarn (input_location, OPT_Wattributes,
5510 : : "%qE on %<case%> or %<default%> label", name);
5511 : 68119 : return ret;
5512 : : }
5513 : :
5514 : : /* Table of valid C++ attributes. */
5515 : : static const attribute_spec cxx_gnu_attributes[] =
5516 : : {
5517 : : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5518 : : affects_type_identity, handler, exclude } */
5519 : : { "init_priority", 1, 1, true, false, false, false,
5520 : : handle_init_priority_attribute, NULL },
5521 : : { "abi_tag", 1, -1, false, false, false, true,
5522 : : handle_abi_tag_attribute, NULL },
5523 : : { "no_dangling", 0, 1, false, true, false, false,
5524 : : handle_no_dangling_attribute, NULL },
5525 : : };
5526 : :
5527 : : const scoped_attribute_specs cxx_gnu_attribute_table =
5528 : : {
5529 : : "gnu", { cxx_gnu_attributes }
5530 : : };
5531 : :
5532 : : /* Table of C++ standard attributes. */
5533 : : static const attribute_spec std_attributes[] =
5534 : : {
5535 : : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5536 : : affects_type_identity, handler, exclude } */
5537 : : { "deprecated", 0, 1, false, false, false, false,
5538 : : handle_std_deprecated_attribute, NULL },
5539 : : { "maybe_unused", 0, 0, false, false, false, false,
5540 : : handle_maybe_unused_attribute, NULL },
5541 : : { "nodiscard", 0, 1, false, false, false, false,
5542 : : handle_nodiscard_attribute, NULL },
5543 : : { "no_unique_address", 0, 0, true, false, false, false,
5544 : : handle_no_unique_addr_attribute, NULL },
5545 : : { "likely", 0, 0, false, false, false, false,
5546 : : handle_likeliness_attribute, attr_cold_hot_exclusions },
5547 : : { "unlikely", 0, 0, false, false, false, false,
5548 : : handle_likeliness_attribute, attr_cold_hot_exclusions },
5549 : : { "noreturn", 0, 0, true, false, false, false,
5550 : : handle_noreturn_attribute, attr_noreturn_exclusions },
5551 : : { "carries_dependency", 0, 0, true, false, false, false,
5552 : : handle_carries_dependency_attribute, NULL },
5553 : : { "pre", 0, -1, false, false, false, false,
5554 : : handle_contract_attribute, NULL },
5555 : : { "post", 0, -1, false, false, false, false,
5556 : : handle_contract_attribute, NULL }
5557 : : };
5558 : :
5559 : : const scoped_attribute_specs std_attribute_table =
5560 : : {
5561 : : nullptr, { std_attributes }
5562 : : };
5563 : :
5564 : : /* Table of internal attributes. */
5565 : : static const attribute_spec internal_attributes[] =
5566 : : {
5567 : : { "aligned", 0, 1, false, false, false, false,
5568 : : handle_alignas_attribute, attr_aligned_exclusions }
5569 : : };
5570 : :
5571 : : const scoped_attribute_specs internal_attribute_table =
5572 : : {
5573 : : "internal ", { internal_attributes }
5574 : : };
5575 : :
5576 : : /* Handle an "init_priority" attribute; arguments as in
5577 : : struct attribute_spec.handler. */
5578 : : static tree
5579 : 35 : handle_init_priority_attribute (tree* node,
5580 : : tree name,
5581 : : tree args,
5582 : : int /*flags*/,
5583 : : bool* no_add_attrs)
5584 : : {
5585 : 35 : if (!SUPPORTS_INIT_PRIORITY)
5586 : : /* Treat init_priority as an unrecognized attribute (mirroring
5587 : : __has_attribute) if the target doesn't support init priorities. */
5588 : : return error_mark_node;
5589 : :
5590 : 35 : tree initp_expr = TREE_VALUE (args);
5591 : 35 : tree decl = *node;
5592 : 35 : tree type = TREE_TYPE (decl);
5593 : 35 : int pri;
5594 : :
5595 : 35 : STRIP_NOPS (initp_expr);
5596 : 35 : initp_expr = default_conversion (initp_expr);
5597 : 35 : if (initp_expr)
5598 : 35 : initp_expr = maybe_constant_value (initp_expr);
5599 : :
5600 : 35 : if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
5601 : : {
5602 : 0 : error ("requested %<init_priority%> is not an integer constant");
5603 : 0 : cxx_constant_value (initp_expr);
5604 : 0 : *no_add_attrs = true;
5605 : 0 : return NULL_TREE;
5606 : : }
5607 : :
5608 : 35 : pri = TREE_INT_CST_LOW (initp_expr);
5609 : :
5610 : 35 : type = strip_array_types (type);
5611 : :
5612 : 35 : if (decl == NULL_TREE
5613 : 35 : || !VAR_P (decl)
5614 : 35 : || !TREE_STATIC (decl)
5615 : 35 : || DECL_EXTERNAL (decl)
5616 : 35 : || (TREE_CODE (type) != RECORD_TYPE
5617 : 35 : && TREE_CODE (type) != UNION_TYPE)
5618 : : /* Static objects in functions are initialized the
5619 : : first time control passes through that
5620 : : function. This is not precise enough to pin down an
5621 : : init_priority value, so don't allow it. */
5622 : 70 : || current_function_decl)
5623 : : {
5624 : 0 : error ("can only use %qE attribute on file-scope definitions "
5625 : : "of objects of class type", name);
5626 : 0 : *no_add_attrs = true;
5627 : 0 : return NULL_TREE;
5628 : : }
5629 : :
5630 : 35 : if (pri > MAX_INIT_PRIORITY || pri <= 0)
5631 : : {
5632 : 0 : error ("requested %<init_priority%> %i is out of range [0, %i]",
5633 : : pri, MAX_INIT_PRIORITY);
5634 : 0 : *no_add_attrs = true;
5635 : 0 : return NULL_TREE;
5636 : : }
5637 : :
5638 : : /* Check for init_priorities that are reserved for
5639 : : language and runtime support implementations.*/
5640 : 35 : if (pri <= MAX_RESERVED_INIT_PRIORITY
5641 : 35 : && !in_system_header_at (input_location))
5642 : : {
5643 : 10 : warning
5644 : 10 : (OPT_Wprio_ctor_dtor,
5645 : : "requested %<init_priority%> %i is reserved for internal use",
5646 : : pri);
5647 : : }
5648 : :
5649 : 35 : SET_DECL_INIT_PRIORITY (decl, pri);
5650 : 35 : DECL_HAS_INIT_PRIORITY_P (decl) = 1;
5651 : 35 : return NULL_TREE;
5652 : : }
5653 : :
5654 : : /* DECL is being redeclared; the old declaration had the abi tags in OLD,
5655 : : and the new one has the tags in NEW_. Give an error if there are tags
5656 : : in NEW_ that weren't in OLD. */
5657 : :
5658 : : bool
5659 : 10261932 : check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_)
5660 : : {
5661 : 10295793 : if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST)
5662 : : old = TREE_VALUE (old);
5663 : 10284314 : if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST)
5664 : : new_ = TREE_VALUE (new_);
5665 : 10261932 : bool err = false;
5666 : 10261932 : auto_diagnostic_group d;
5667 : 10284314 : for (const_tree t = new_; t; t = TREE_CHAIN (t))
5668 : : {
5669 : 22382 : tree str = TREE_VALUE (t);
5670 : 22382 : for (const_tree in = old; in; in = TREE_CHAIN (in))
5671 : : {
5672 : 22373 : tree ostr = TREE_VALUE (in);
5673 : 22373 : if (cp_tree_equal (str, ostr))
5674 : 22373 : goto found;
5675 : : }
5676 : 9 : error ("redeclaration of %qD adds abi tag %qE", decl, str);
5677 : 9 : err = true;
5678 : 22382 : found:;
5679 : : }
5680 : 10261932 : if (err)
5681 : : {
5682 : 9 : inform (DECL_SOURCE_LOCATION (decl), "previous declaration here");
5683 : 9 : return false;
5684 : : }
5685 : : return true;
5686 : 10261932 : }
5687 : :
5688 : : /* The abi_tag attribute with the name NAME was given ARGS. If they are
5689 : : ill-formed, give an error and return false; otherwise, return true. */
5690 : :
5691 : : bool
5692 : 386565 : check_abi_tag_args (tree args, tree name)
5693 : : {
5694 : 386565 : if (!args)
5695 : : {
5696 : 0 : error ("the %qE attribute requires arguments", name);
5697 : 0 : return false;
5698 : : }
5699 : 773169 : for (tree arg = args; arg; arg = TREE_CHAIN (arg))
5700 : : {
5701 : 386616 : tree elt = TREE_VALUE (arg);
5702 : 386616 : if (TREE_CODE (elt) != STRING_CST
5703 : 773226 : || (!same_type_ignoring_top_level_qualifiers_p
5704 : 386610 : (strip_array_types (TREE_TYPE (elt)),
5705 : : char_type_node)))
5706 : : {
5707 : 9 : error ("arguments to the %qE attribute must be narrow string "
5708 : : "literals", name);
5709 : 9 : return false;
5710 : : }
5711 : 386607 : const char *begin = TREE_STRING_POINTER (elt);
5712 : 386607 : const char *end = begin + TREE_STRING_LENGTH (elt);
5713 : 2719549 : for (const char *p = begin; p != end; ++p)
5714 : : {
5715 : 2332945 : char c = *p;
5716 : 2332945 : if (p == begin)
5717 : : {
5718 : 386607 : if (!ISALPHA (c) && c != '_')
5719 : : {
5720 : 3 : auto_diagnostic_group d;
5721 : 3 : error ("arguments to the %qE attribute must contain valid "
5722 : : "identifiers", name);
5723 : 3 : inform (input_location, "%<%c%> is not a valid first "
5724 : : "character for an identifier", c);
5725 : 3 : return false;
5726 : 3 : }
5727 : : }
5728 : 1946338 : else if (p == end - 1)
5729 : 386604 : gcc_assert (c == 0);
5730 : : else
5731 : : {
5732 : 1559734 : if (!ISALNUM (c) && c != '_')
5733 : : {
5734 : 0 : auto_diagnostic_group d;
5735 : 0 : error ("arguments to the %qE attribute must contain valid "
5736 : : "identifiers", name);
5737 : 0 : inform (input_location, "%<%c%> is not a valid character "
5738 : : "in an identifier", c);
5739 : 0 : return false;
5740 : 0 : }
5741 : : }
5742 : : }
5743 : : }
5744 : : return true;
5745 : : }
5746 : :
5747 : : /* Handle an "abi_tag" attribute; arguments as in
5748 : : struct attribute_spec.handler. */
5749 : :
5750 : : static tree
5751 : 339689 : handle_abi_tag_attribute (tree* node, tree name, tree args,
5752 : : int flags, bool* no_add_attrs)
5753 : : {
5754 : 339689 : if (!check_abi_tag_args (args, name))
5755 : 12 : goto fail;
5756 : :
5757 : 339677 : if (TYPE_P (*node))
5758 : : {
5759 : 11381 : if (!OVERLOAD_TYPE_P (*node))
5760 : : {
5761 : 0 : error ("%qE attribute applied to non-class, non-enum type %qT",
5762 : : name, *node);
5763 : 0 : goto fail;
5764 : : }
5765 : 11381 : else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE))
5766 : : {
5767 : 0 : error ("%qE attribute applied to %qT after its definition",
5768 : : name, *node);
5769 : 0 : goto fail;
5770 : : }
5771 : 11378 : else if (CLASS_TYPE_P (*node)
5772 : 22759 : && CLASSTYPE_TEMPLATE_INSTANTIATION (*node))
5773 : : {
5774 : 3 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5775 : : "template instantiation %qT", name, *node);
5776 : 3 : goto fail;
5777 : : }
5778 : 11375 : else if (CLASS_TYPE_P (*node)
5779 : 22753 : && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node))
5780 : : {
5781 : 3 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5782 : : "template specialization %qT", name, *node);
5783 : 3 : goto fail;
5784 : : }
5785 : :
5786 : 11375 : tree attributes = TYPE_ATTRIBUTES (*node);
5787 : 11375 : tree decl = TYPE_NAME (*node);
5788 : :
5789 : : /* Make sure all declarations have the same abi tags. */
5790 : 11375 : if (DECL_SOURCE_LOCATION (decl) != input_location)
5791 : : {
5792 : 6 : if (!check_abi_tag_redeclaration (decl,
5793 : 6 : lookup_attribute ("abi_tag",
5794 : : attributes),
5795 : : args))
5796 : 6 : goto fail;
5797 : : }
5798 : : }
5799 : : else
5800 : : {
5801 : 328296 : if (!VAR_OR_FUNCTION_DECL_P (*node))
5802 : : {
5803 : 0 : error ("%qE attribute applied to non-function, non-variable %qD",
5804 : : name, *node);
5805 : 0 : goto fail;
5806 : : }
5807 : 328296 : else if (DECL_LANGUAGE (*node) == lang_c)
5808 : : {
5809 : 0 : error ("%qE attribute applied to extern \"C\" declaration %qD",
5810 : : name, *node);
5811 : 0 : goto fail;
5812 : : }
5813 : : }
5814 : :
5815 : : return NULL_TREE;
5816 : :
5817 : 24 : fail:
5818 : 24 : *no_add_attrs = true;
5819 : 24 : return NULL_TREE;
5820 : : }
5821 : :
5822 : : /* Perform checking for contract attributes. */
5823 : :
5824 : : tree
5825 : 677 : handle_contract_attribute (tree *ARG_UNUSED (node), tree ARG_UNUSED (name),
5826 : : tree ARG_UNUSED (args), int ARG_UNUSED (flags),
5827 : : bool *ARG_UNUSED (no_add_attrs))
5828 : : {
5829 : : /* TODO: Is there any checking we could do here? */
5830 : 677 : return NULL_TREE;
5831 : : }
5832 : :
5833 : : /* Handle a "no_dangling" attribute; arguments as in
5834 : : struct attribute_spec.handler. */
5835 : :
5836 : : tree
5837 : 96 : handle_no_dangling_attribute (tree *node, tree name, tree args, int,
5838 : : bool *no_add_attrs)
5839 : : {
5840 : 147 : if (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
5841 : : {
5842 : 3 : error ("%qE attribute argument must be an expression that evaluates "
5843 : : "to true or false", name);
5844 : 3 : *no_add_attrs = true;
5845 : : }
5846 : 93 : else if (!FUNC_OR_METHOD_TYPE_P (*node)
5847 : 51 : && !RECORD_OR_UNION_TYPE_P (*node))
5848 : : {
5849 : 18 : warning (OPT_Wattributes, "%qE attribute ignored", name);
5850 : 18 : *no_add_attrs = true;
5851 : : }
5852 : :
5853 : 96 : return NULL_TREE;
5854 : : }
5855 : :
5856 : : /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
5857 : : thing pointed to by the constant. */
5858 : :
5859 : : tree
5860 : 65833 : make_ptrmem_cst (tree type, tree member)
5861 : : {
5862 : 65833 : tree ptrmem_cst = make_node (PTRMEM_CST);
5863 : 65833 : TREE_TYPE (ptrmem_cst) = type;
5864 : 65833 : PTRMEM_CST_MEMBER (ptrmem_cst) = member;
5865 : 65833 : PTRMEM_CST_LOCATION (ptrmem_cst) = input_location;
5866 : 65833 : return ptrmem_cst;
5867 : : }
5868 : :
5869 : : /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
5870 : : return an existing type if an appropriate type already exists. */
5871 : :
5872 : : tree
5873 : 15753668 : cp_build_type_attribute_variant (tree type, tree attributes)
5874 : : {
5875 : 15753668 : tree new_type;
5876 : :
5877 : 15753668 : new_type = build_type_attribute_variant (type, attributes);
5878 : 15753668 : if (FUNC_OR_METHOD_TYPE_P (new_type))
5879 : 15692310 : gcc_checking_assert (cxx_type_hash_eq (type, new_type));
5880 : :
5881 : : /* Making a new main variant of a class type is broken. */
5882 : 15753668 : gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
5883 : :
5884 : 15753668 : return new_type;
5885 : : }
5886 : :
5887 : : /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
5888 : : Called only after doing all language independent checks. */
5889 : :
5890 : : bool
5891 : 298192868 : cxx_type_hash_eq (const_tree typea, const_tree typeb)
5892 : : {
5893 : 298192868 : gcc_assert (FUNC_OR_METHOD_TYPE_P (typea));
5894 : :
5895 : 298192868 : if (type_memfn_rqual (typea) != type_memfn_rqual (typeb))
5896 : : return false;
5897 : 298181732 : if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb))
5898 : : return false;
5899 : 298181118 : return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
5900 : 596362236 : TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
5901 : : }
5902 : :
5903 : : /* Copy the language-specific type variant modifiers from TYPEB to TYPEA. For
5904 : : C++, these are the exception-specifier and ref-qualifier. */
5905 : :
5906 : : tree
5907 : 24850580 : cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
5908 : : {
5909 : 24850580 : tree type = CONST_CAST_TREE (typea);
5910 : 24850580 : if (FUNC_OR_METHOD_TYPE_P (type))
5911 : 24849690 : type = build_cp_fntype_variant (type, type_memfn_rqual (typeb),
5912 : 24849690 : TYPE_RAISES_EXCEPTIONS (typeb),
5913 : 24849690 : TYPE_HAS_LATE_RETURN_TYPE (typeb));
5914 : 24850580 : return type;
5915 : : }
5916 : :
5917 : : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
5918 : : traversal. Called from walk_tree. */
5919 : :
5920 : : tree
5921 : 15819534747 : cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
5922 : : void *data, hash_set<tree> *pset)
5923 : : {
5924 : 15819534747 : tree t = *tp;
5925 : 15819534747 : enum tree_code code = TREE_CODE (t);
5926 : 15819534747 : tree result;
5927 : :
5928 : : #define WALK_SUBTREE(NODE) \
5929 : : do \
5930 : : { \
5931 : : result = cp_walk_tree (&(NODE), func, data, pset); \
5932 : : if (result) goto out; \
5933 : : } \
5934 : : while (0)
5935 : :
5936 : 15819534747 : if (TYPE_P (t))
5937 : : {
5938 : : /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
5939 : : the argument, so don't look through typedefs, but do walk into
5940 : : template arguments for alias templates (and non-typedefed classes).
5941 : :
5942 : : If *WALK_SUBTREES_P > 1, we're interested in type identity or
5943 : : equivalence, so look through typedefs, ignoring template arguments for
5944 : : alias templates, and walk into template args of classes.
5945 : :
5946 : : See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
5947 : : when that's the behavior the walk_tree_fn wants. */
5948 : 5545103167 : if (*walk_subtrees_p == 1 && typedef_variant_p (t))
5949 : : {
5950 : 15516631 : if (tree ti = TYPE_ALIAS_TEMPLATE_INFO (t))
5951 : 11487220 : WALK_SUBTREE (TI_ARGS (ti));
5952 : 15383736 : *walk_subtrees_p = 0;
5953 : 15383736 : return NULL_TREE;
5954 : : }
5955 : :
5956 : 5529586536 : if (tree ti = TYPE_TEMPLATE_INFO (t))
5957 : 534520579 : WALK_SUBTREE (TI_ARGS (ti));
5958 : : }
5959 : :
5960 : : /* Not one of the easy cases. We must explicitly go through the
5961 : : children. */
5962 : 15803888872 : result = NULL_TREE;
5963 : 15803888872 : switch (code)
5964 : : {
5965 : 1554036072 : case TEMPLATE_TYPE_PARM:
5966 : 1554036072 : if (template_placeholder_p (t))
5967 : 468729 : WALK_SUBTREE (CLASS_PLACEHOLDER_TEMPLATE (t));
5968 : : /* Fall through. */
5969 : 1689573107 : case DEFERRED_PARSE:
5970 : 1689573107 : case TEMPLATE_TEMPLATE_PARM:
5971 : 1689573107 : case BOUND_TEMPLATE_TEMPLATE_PARM:
5972 : 1689573107 : case UNBOUND_CLASS_TEMPLATE:
5973 : 1689573107 : case TEMPLATE_PARM_INDEX:
5974 : 1689573107 : case TYPEOF_TYPE:
5975 : : /* None of these have subtrees other than those already walked
5976 : : above. */
5977 : 1689573107 : *walk_subtrees_p = 0;
5978 : 1689573107 : break;
5979 : :
5980 : 147345635 : case TYPENAME_TYPE:
5981 : 147345635 : WALK_SUBTREE (TYPE_CONTEXT (t));
5982 : 147310709 : WALK_SUBTREE (TYPENAME_TYPE_FULLNAME (t));
5983 : 147307837 : *walk_subtrees_p = 0;
5984 : 147307837 : break;
5985 : :
5986 : 69846758 : case BASELINK:
5987 : 69846758 : if (BASELINK_QUALIFIED_P (t))
5988 : 4931153 : WALK_SUBTREE (BINFO_TYPE (BASELINK_ACCESS_BINFO (t)));
5989 : 69846758 : WALK_SUBTREE (BASELINK_FUNCTIONS (t));
5990 : 69823402 : *walk_subtrees_p = 0;
5991 : 69823402 : break;
5992 : :
5993 : 54330 : case PTRMEM_CST:
5994 : 54330 : WALK_SUBTREE (TREE_TYPE (t));
5995 : 54330 : *walk_subtrees_p = 0;
5996 : 54330 : break;
5997 : :
5998 : 216364023 : case TREE_LIST:
5999 : 216364023 : WALK_SUBTREE (TREE_PURPOSE (t));
6000 : : break;
6001 : :
6002 : 247129847 : case OVERLOAD:
6003 : 247129847 : WALK_SUBTREE (OVL_FUNCTION (t));
6004 : 247129842 : WALK_SUBTREE (OVL_CHAIN (t));
6005 : 247129842 : *walk_subtrees_p = 0;
6006 : 247129842 : break;
6007 : :
6008 : 3990082 : case USING_DECL:
6009 : 3990082 : WALK_SUBTREE (DECL_NAME (t));
6010 : 3990082 : WALK_SUBTREE (USING_DECL_SCOPE (t));
6011 : 3990079 : WALK_SUBTREE (USING_DECL_DECLS (t));
6012 : 3990079 : *walk_subtrees_p = 0;
6013 : 3990079 : break;
6014 : :
6015 : 609031524 : case RECORD_TYPE:
6016 : 609031524 : if (TYPE_PTRMEMFUNC_P (t))
6017 : 5800834 : WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (t));
6018 : : break;
6019 : :
6020 : 112109823 : case TYPE_ARGUMENT_PACK:
6021 : 112109823 : case NONTYPE_ARGUMENT_PACK:
6022 : 112109823 : {
6023 : 112109823 : tree args = ARGUMENT_PACK_ARGS (t);
6024 : 291536808 : for (tree arg : tree_vec_range (args))
6025 : 179639976 : WALK_SUBTREE (arg);
6026 : : }
6027 : 111896832 : break;
6028 : :
6029 : 25707113 : case TYPE_PACK_EXPANSION:
6030 : 25707113 : WALK_SUBTREE (TREE_TYPE (t));
6031 : 25694316 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
6032 : 25694316 : *walk_subtrees_p = 0;
6033 : 25694316 : break;
6034 : :
6035 : 3343827 : case EXPR_PACK_EXPANSION:
6036 : 3343827 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6037 : 3342394 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
6038 : 3342394 : *walk_subtrees_p = 0;
6039 : 3342394 : break;
6040 : :
6041 : 45 : case PACK_INDEX_TYPE:
6042 : 45 : case PACK_INDEX_EXPR:
6043 : 45 : WALK_SUBTREE (PACK_INDEX_PACK (t));
6044 : 45 : WALK_SUBTREE (PACK_INDEX_INDEX (t));
6045 : 45 : *walk_subtrees_p = 0;
6046 : 45 : break;
6047 : :
6048 : 80915732 : case CAST_EXPR:
6049 : 80915732 : case REINTERPRET_CAST_EXPR:
6050 : 80915732 : case STATIC_CAST_EXPR:
6051 : 80915732 : case CONST_CAST_EXPR:
6052 : 80915732 : case DYNAMIC_CAST_EXPR:
6053 : 80915732 : case IMPLICIT_CONV_EXPR:
6054 : 80915732 : case BIT_CAST_EXPR:
6055 : 80915732 : if (TREE_TYPE (t))
6056 : 80915732 : WALK_SUBTREE (TREE_TYPE (t));
6057 : : break;
6058 : :
6059 : 70478618 : case CONSTRUCTOR:
6060 : 70478618 : if (COMPOUND_LITERAL_P (t))
6061 : 4906559 : WALK_SUBTREE (TREE_TYPE (t));
6062 : : break;
6063 : :
6064 : 12663998 : case TRAIT_EXPR:
6065 : 12663998 : WALK_SUBTREE (TRAIT_EXPR_TYPE1 (t));
6066 : 12663986 : WALK_SUBTREE (TRAIT_EXPR_TYPE2 (t));
6067 : 12663986 : *walk_subtrees_p = 0;
6068 : 12663986 : break;
6069 : :
6070 : 1251617 : case TRAIT_TYPE:
6071 : 1251617 : WALK_SUBTREE (TRAIT_TYPE_TYPE1 (t));
6072 : 1251617 : WALK_SUBTREE (TRAIT_TYPE_TYPE2 (t));
6073 : 1251617 : *walk_subtrees_p = 0;
6074 : 1251617 : break;
6075 : :
6076 : 7297605 : case DECLTYPE_TYPE:
6077 : 7297605 : {
6078 : 7297605 : cp_unevaluated u;
6079 : 7297605 : WALK_SUBTREE (DECLTYPE_TYPE_EXPR (t));
6080 : 7199470 : *walk_subtrees_p = 0;
6081 : 7199470 : break;
6082 : 7297605 : }
6083 : :
6084 : 17866700 : case ALIGNOF_EXPR:
6085 : 17866700 : case SIZEOF_EXPR:
6086 : 17866700 : case NOEXCEPT_EXPR:
6087 : 17866700 : {
6088 : 17866700 : cp_unevaluated u;
6089 : 17866700 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6090 : 15521523 : *walk_subtrees_p = 0;
6091 : 15521523 : break;
6092 : 17866700 : }
6093 : :
6094 : 3912792 : case REQUIRES_EXPR:
6095 : 3912792 : {
6096 : 3912792 : cp_unevaluated u;
6097 : 6740870 : for (tree parm = REQUIRES_EXPR_PARMS (t); parm; parm = DECL_CHAIN (parm))
6098 : : /* Walk the types of each parameter, but not the parameter itself,
6099 : : since doing so would cause false positives in the unexpanded pack
6100 : : checker if the requires-expr introduces a function parameter pack,
6101 : : e.g. requires (Ts... ts) { }. */
6102 : 2828132 : WALK_SUBTREE (TREE_TYPE (parm));
6103 : 3912738 : WALK_SUBTREE (REQUIRES_EXPR_REQS (t));
6104 : 3909405 : *walk_subtrees_p = 0;
6105 : 3909405 : break;
6106 : 3912792 : }
6107 : :
6108 : 68647733 : case DECL_EXPR:
6109 : : /* User variables should be mentioned in BIND_EXPR_VARS
6110 : : and their initializers and sizes walked when walking
6111 : : the containing BIND_EXPR. Compiler temporaries are
6112 : : handled here. And also normal variables in templates,
6113 : : since do_poplevel doesn't build a BIND_EXPR then. */
6114 : 68647733 : if (VAR_P (TREE_OPERAND (t, 0))
6115 : 68647733 : && (processing_template_decl
6116 : 62697945 : || (DECL_ARTIFICIAL (TREE_OPERAND (t, 0))
6117 : 4041077 : && !TREE_STATIC (TREE_OPERAND (t, 0)))))
6118 : : {
6119 : 7775974 : tree decl = TREE_OPERAND (t, 0);
6120 : 7775974 : WALK_SUBTREE (TREE_TYPE (decl));
6121 : 7775974 : WALK_SUBTREE (DECL_INITIAL (decl));
6122 : 7775944 : WALK_SUBTREE (DECL_SIZE (decl));
6123 : 7775944 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
6124 : : }
6125 : : break;
6126 : :
6127 : 935033 : case LAMBDA_EXPR:
6128 : : /* Don't walk into the body of the lambda, but the capture initializers
6129 : : are part of the enclosing context. */
6130 : 2069541 : for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (t); cap;
6131 : 1134508 : cap = TREE_CHAIN (cap))
6132 : 1134508 : WALK_SUBTREE (TREE_VALUE (cap));
6133 : : break;
6134 : :
6135 : 6217 : case CO_YIELD_EXPR:
6136 : 6217 : if (TREE_OPERAND (t, 1))
6137 : : /* Operand 1 is the tree for the relevant co_await which has any
6138 : : interesting sub-trees. */
6139 : 595 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6140 : : break;
6141 : :
6142 : 26703 : case CO_AWAIT_EXPR:
6143 : 26703 : if (TREE_OPERAND (t, 1))
6144 : : /* Operand 1 is frame variable. */
6145 : 26515 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6146 : 26703 : if (TREE_OPERAND (t, 2))
6147 : : /* Operand 2 has the initialiser, and we need to walk any subtrees
6148 : : there. */
6149 : 5347 : WALK_SUBTREE (TREE_OPERAND (t, 2));
6150 : : break;
6151 : :
6152 : 881 : case CO_RETURN_EXPR:
6153 : 881 : if (TREE_OPERAND (t, 0))
6154 : : {
6155 : 698 : if (VOID_TYPE_P (TREE_OPERAND (t, 0)))
6156 : : /* For void expressions, operand 1 is a trivial call, and any
6157 : : interesting subtrees will be part of operand 0. */
6158 : 0 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6159 : 698 : else if (TREE_OPERAND (t, 1))
6160 : : /* Interesting sub-trees will be in the return_value () call
6161 : : arguments. */
6162 : 656 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6163 : : }
6164 : : break;
6165 : :
6166 : 235564 : case STATIC_ASSERT:
6167 : 235564 : WALK_SUBTREE (STATIC_ASSERT_CONDITION (t));
6168 : 235564 : WALK_SUBTREE (STATIC_ASSERT_MESSAGE (t));
6169 : : break;
6170 : :
6171 : 530410135 : case INTEGER_TYPE:
6172 : : /* Removed from walk_type_fields in r119481. */
6173 : 530410135 : WALK_SUBTREE (TYPE_MIN_VALUE (t));
6174 : 530410135 : WALK_SUBTREE (TYPE_MAX_VALUE (t));
6175 : : break;
6176 : :
6177 : : default:
6178 : : return NULL_TREE;
6179 : : }
6180 : :
6181 : : /* We didn't find what we were looking for. */
6182 : : out:
6183 : : return result;
6184 : :
6185 : : #undef WALK_SUBTREE
6186 : : }
6187 : :
6188 : : /* Like save_expr, but for C++. */
6189 : :
6190 : : tree
6191 : 330026 : cp_save_expr (tree expr)
6192 : : {
6193 : : /* There is no reason to create a SAVE_EXPR within a template; if
6194 : : needed, we can create the SAVE_EXPR when instantiating the
6195 : : template. Furthermore, the middle-end cannot handle C++-specific
6196 : : tree codes. */
6197 : 330026 : if (processing_template_decl)
6198 : : return expr;
6199 : :
6200 : : /* TARGET_EXPRs are only expanded once. */
6201 : 254435 : if (TREE_CODE (expr) == TARGET_EXPR)
6202 : : return expr;
6203 : :
6204 : 254435 : return save_expr (expr);
6205 : : }
6206 : :
6207 : : /* Initialize tree.cc. */
6208 : :
6209 : : void
6210 : 95198 : init_tree (void)
6211 : : {
6212 : 95198 : list_hash_table = hash_table<list_hasher>::create_ggc (61);
6213 : 95198 : }
6214 : :
6215 : : /* Returns the kind of special function that DECL (a FUNCTION_DECL)
6216 : : is. Note that sfk_none is zero, so this function can be used as a
6217 : : predicate to test whether or not DECL is a special function. */
6218 : :
6219 : : special_function_kind
6220 : 199592933 : special_function_p (const_tree decl)
6221 : : {
6222 : : /* Rather than doing all this stuff with magic names, we should
6223 : : probably have a field of type `special_function_kind' in
6224 : : DECL_LANG_SPECIFIC. */
6225 : 399185866 : if (DECL_INHERITED_CTOR (decl))
6226 : : return sfk_inheriting_constructor;
6227 : 398490232 : if (DECL_COPY_CONSTRUCTOR_P (decl))
6228 : : return sfk_copy_constructor;
6229 : 374942804 : if (DECL_MOVE_CONSTRUCTOR_P (decl))
6230 : : return sfk_move_constructor;
6231 : 359425196 : if (DECL_CONSTRUCTOR_P (decl))
6232 : : return sfk_constructor;
6233 : 157836354 : if (DECL_ASSIGNMENT_OPERATOR_P (decl)
6234 : 157836354 : && DECL_OVERLOADED_OPERATOR_IS (decl, NOP_EXPR))
6235 : : {
6236 : 9962172 : if (copy_fn_p (decl))
6237 : : return sfk_copy_assignment;
6238 : 3828924 : if (move_fn_p (decl))
6239 : : return sfk_move_assignment;
6240 : : }
6241 : 148330068 : if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
6242 : : return sfk_destructor;
6243 : 112410165 : if (DECL_COMPLETE_DESTRUCTOR_P (decl))
6244 : : return sfk_complete_destructor;
6245 : 94889972 : if (DECL_BASE_DESTRUCTOR_P (decl))
6246 : : return sfk_base_destructor;
6247 : 92961105 : if (DECL_DELETING_DESTRUCTOR_P (decl))
6248 : : return sfk_deleting_destructor;
6249 : 81486600 : if (DECL_CONV_FN_P (decl))
6250 : : return sfk_conversion;
6251 : 80750893 : if (deduction_guide_p (decl))
6252 : : return sfk_deduction_guide;
6253 : 80722443 : if (DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) >= OVL_OP_EQ_EXPR
6254 : 80722443 : && DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) <= OVL_OP_SPACESHIP_EXPR)
6255 : 2982148 : return sfk_comparison;
6256 : :
6257 : : return sfk_none;
6258 : : }
6259 : :
6260 : : /* As above, but only if DECL is a special member function as per 11.3.3
6261 : : [special]: default/copy/move ctor, copy/move assignment, or destructor. */
6262 : :
6263 : : special_function_kind
6264 : 71718120 : special_memfn_p (const_tree decl)
6265 : : {
6266 : 71718120 : switch (special_function_kind sfk = special_function_p (decl))
6267 : : {
6268 : 8188355 : case sfk_constructor:
6269 : 8188355 : if (!default_ctor_p (decl))
6270 : : break;
6271 : : gcc_fallthrough();
6272 : : case sfk_copy_constructor:
6273 : : case sfk_copy_assignment:
6274 : : case sfk_move_assignment:
6275 : : case sfk_move_constructor:
6276 : : case sfk_destructor:
6277 : : return sfk;
6278 : :
6279 : : default:
6280 : : break;
6281 : : }
6282 : : return sfk_none;
6283 : : }
6284 : :
6285 : : /* Returns nonzero if TYPE is a character type, including wchar_t. */
6286 : :
6287 : : int
6288 : 9280573 : char_type_p (tree type)
6289 : : {
6290 : 9280573 : return (same_type_p (type, char_type_node)
6291 : 8207727 : || same_type_p (type, unsigned_char_type_node)
6292 : 8148825 : || same_type_p (type, signed_char_type_node)
6293 : 8148281 : || same_type_p (type, char8_type_node)
6294 : 8148207 : || same_type_p (type, char16_type_node)
6295 : 8147707 : || same_type_p (type, char32_type_node)
6296 : 17387211 : || same_type_p (type, wchar_type_node));
6297 : : }
6298 : :
6299 : : /* Returns the kind of linkage associated with the indicated DECL. The
6300 : : value returned is as specified by the language standard; it is
6301 : : independent of implementation details regarding template
6302 : : instantiation, etc. For example, it is possible that a declaration
6303 : : to which this function assigns external linkage would not show up
6304 : : as a global symbol when you run `nm' on the resulting object file. */
6305 : :
6306 : : linkage_kind
6307 : 410466934 : decl_linkage (tree decl)
6308 : : {
6309 : : /* This function doesn't attempt to calculate the linkage from first
6310 : : principles as given in [basic.link]. Instead, it makes use of
6311 : : the fact that we have already set TREE_PUBLIC appropriately, and
6312 : : then handles a few special cases. Ideally, we would calculate
6313 : : linkage first, and then transform that into a concrete
6314 : : implementation. */
6315 : :
6316 : : /* An explicit type alias has no linkage. Nor do the built-in declarations
6317 : : of 'int' and such. */
6318 : 443741406 : if (TREE_CODE (decl) == TYPE_DECL
6319 : 443741406 : && !DECL_IMPLICIT_TYPEDEF_P (decl))
6320 : : {
6321 : : /* But this could be a typedef name for linkage purposes, in which
6322 : : case we're interested in the linkage of the main decl. */
6323 : 932079 : if (decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl)))
6324 : : /* Likewise for the injected-class-name. */
6325 : 932079 : || DECL_SELF_REFERENCE_P (decl))
6326 : 23944 : decl = TYPE_MAIN_DECL (TREE_TYPE (decl));
6327 : : else
6328 : : return lk_none;
6329 : : }
6330 : :
6331 : : /* Namespace-scope entities with no name usually have no linkage. */
6332 : 442833271 : if (NAMESPACE_SCOPE_P (decl)
6333 : 849475403 : && (!DECL_NAME (decl) || IDENTIFIER_ANON_P (DECL_NAME (decl))))
6334 : : {
6335 : 3634245 : if (TREE_CODE (decl) == TYPE_DECL && !TYPE_ANON_P (TREE_TYPE (decl)))
6336 : : /* This entity has a typedef name for linkage purposes. */;
6337 : 3631152 : else if (DECL_DECOMPOSITION_P (decl) && DECL_DECOMP_IS_BASE (decl))
6338 : : /* Namespace-scope structured bindings can have linkage. */;
6339 : 3631070 : else if (TREE_CODE (decl) == NAMESPACE_DECL && cxx_dialect >= cxx11)
6340 : : /* An anonymous namespace has internal linkage since C++11. */
6341 : : return lk_internal;
6342 : : else
6343 : : return lk_none;
6344 : : }
6345 : :
6346 : : /* Fields and parameters have no linkage. */
6347 : 439202201 : if (TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == PARM_DECL)
6348 : : return lk_none;
6349 : :
6350 : : /* Things in block scope do not have linkage. */
6351 : 394495991 : if (decl_function_context (decl))
6352 : : return lk_none;
6353 : :
6354 : : /* Things in class scope have the linkage of their owning class. */
6355 : 391580779 : if (tree ctype = DECL_CLASS_CONTEXT (decl))
6356 : 33274472 : return decl_linkage (TYPE_NAME (ctype));
6357 : :
6358 : : /* Anonymous namespaces don't provide internal linkage in C++98,
6359 : : but otherwise consider such declarations to be internal. */
6360 : 358306307 : if (cxx_dialect >= cxx11 && decl_internal_context_p (decl))
6361 : : return lk_internal;
6362 : :
6363 : : /* Templates don't properly propagate TREE_PUBLIC, consider the
6364 : : template result instead. Any template that isn't a variable
6365 : : or function must be external linkage by this point. */
6366 : 358133459 : if (TREE_CODE (decl) == TEMPLATE_DECL)
6367 : : {
6368 : 242656 : decl = DECL_TEMPLATE_RESULT (decl);
6369 : 242656 : if (!decl || !VAR_OR_FUNCTION_DECL_P (decl))
6370 : : return lk_external;
6371 : : }
6372 : :
6373 : : /* Things that are TREE_PUBLIC have external linkage. */
6374 : 357923466 : if (TREE_PUBLIC (decl))
6375 : : return lk_external;
6376 : :
6377 : : /* All types have external linkage in C++98, since anonymous namespaces
6378 : : didn't explicitly confer internal linkage. */
6379 : 78464280 : if (TREE_CODE (decl) == TYPE_DECL && cxx_dialect < cxx11)
6380 : : return lk_external;
6381 : :
6382 : : /* Variables or function decls not marked as TREE_PUBLIC might still
6383 : : be external linkage, such as for template instantiations on targets
6384 : : without weak symbols, decls referring to internal-linkage entities,
6385 : : or compiler-generated entities; in such cases, decls really meant to
6386 : : have internal linkage will have DECL_THIS_STATIC set. */
6387 : 78464277 : if (VAR_OR_FUNCTION_DECL_P (decl) && !DECL_THIS_STATIC (decl))
6388 : : return lk_external;
6389 : :
6390 : : /* Everything else has internal linkage. */
6391 : : return lk_internal;
6392 : : }
6393 : :
6394 : : /* Returns the storage duration of the object or reference associated with
6395 : : the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
6396 : :
6397 : : duration_kind
6398 : 44899648 : decl_storage_duration (tree decl)
6399 : : {
6400 : 44899648 : if (TREE_CODE (decl) == PARM_DECL)
6401 : : return dk_auto;
6402 : 44899648 : if (TREE_CODE (decl) == FUNCTION_DECL)
6403 : : return dk_static;
6404 : 44899648 : gcc_assert (VAR_P (decl));
6405 : 44899648 : if (!TREE_STATIC (decl)
6406 : 44899648 : && !DECL_EXTERNAL (decl))
6407 : : return dk_auto;
6408 : 21956278 : if (CP_DECL_THREAD_LOCAL_P (decl))
6409 : 21271 : return dk_thread;
6410 : : return dk_static;
6411 : : }
6412 : :
6413 : : /* EXP is an expression that we want to pre-evaluate. Returns (in
6414 : : *INITP) an expression that will perform the pre-evaluation. The
6415 : : value returned by this function is a side-effect free expression
6416 : : equivalent to the pre-evaluated expression. Callers must ensure
6417 : : that *INITP is evaluated before EXP.
6418 : :
6419 : : Note that if EXPR is a glvalue, the return value is a glvalue denoting the
6420 : : same address; this function does not guard against modification of the
6421 : : stored value like save_expr or get_target_expr do. */
6422 : :
6423 : : tree
6424 : 4575463 : stabilize_expr (tree exp, tree* initp)
6425 : : {
6426 : 4575463 : tree init_expr;
6427 : :
6428 : 4575463 : if (!TREE_SIDE_EFFECTS (exp))
6429 : : init_expr = NULL_TREE;
6430 : 536549 : else if (VOID_TYPE_P (TREE_TYPE (exp)))
6431 : : {
6432 : 0 : init_expr = exp;
6433 : 0 : exp = void_node;
6434 : : }
6435 : : /* There are no expressions with REFERENCE_TYPE, but there can be call
6436 : : arguments with such a type; just treat it as a pointer. */
6437 : 536549 : else if (TYPE_REF_P (TREE_TYPE (exp))
6438 : 536415 : || SCALAR_TYPE_P (TREE_TYPE (exp))
6439 : 536595 : || !glvalue_p (exp))
6440 : : {
6441 : 536543 : init_expr = get_target_expr (exp);
6442 : 536543 : exp = TARGET_EXPR_SLOT (init_expr);
6443 : 536543 : if (CLASS_TYPE_P (TREE_TYPE (exp)))
6444 : 9 : exp = move (exp);
6445 : : else
6446 : 536534 : exp = rvalue (exp);
6447 : : }
6448 : : else
6449 : : {
6450 : 6 : bool xval = !lvalue_p (exp);
6451 : 6 : exp = cp_build_addr_expr (exp, tf_warning_or_error);
6452 : 6 : init_expr = get_target_expr (exp);
6453 : 6 : exp = TARGET_EXPR_SLOT (init_expr);
6454 : 6 : exp = cp_build_fold_indirect_ref (exp);
6455 : 6 : if (xval)
6456 : 0 : exp = move (exp);
6457 : : }
6458 : 4575463 : *initp = init_expr;
6459 : :
6460 : 4575463 : gcc_assert (!TREE_SIDE_EFFECTS (exp) || TREE_THIS_VOLATILE (exp));
6461 : 4575463 : return exp;
6462 : : }
6463 : :
6464 : : /* Add NEW_EXPR, an expression whose value we don't care about, after the
6465 : : similar expression ORIG. */
6466 : :
6467 : : tree
6468 : 533221 : add_stmt_to_compound (tree orig, tree new_expr)
6469 : : {
6470 : 533221 : if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
6471 : : return orig;
6472 : 270886 : if (!orig || !TREE_SIDE_EFFECTS (orig))
6473 : : return new_expr;
6474 : 12299 : return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
6475 : : }
6476 : :
6477 : : /* Like stabilize_expr, but for a call whose arguments we want to
6478 : : pre-evaluate. CALL is modified in place to use the pre-evaluated
6479 : : arguments, while, upon return, *INITP contains an expression to
6480 : : compute the arguments. */
6481 : :
6482 : : void
6483 : 259179 : stabilize_call (tree call, tree *initp)
6484 : : {
6485 : 259179 : tree inits = NULL_TREE;
6486 : 259179 : int i;
6487 : 259179 : int nargs = call_expr_nargs (call);
6488 : :
6489 : 259179 : if (call == error_mark_node || processing_template_decl)
6490 : : {
6491 : 31 : *initp = NULL_TREE;
6492 : 31 : return;
6493 : : }
6494 : :
6495 : 259148 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
6496 : :
6497 : 777510 : for (i = 0; i < nargs; i++)
6498 : : {
6499 : 518362 : tree init;
6500 : 518362 : CALL_EXPR_ARG (call, i) =
6501 : 518362 : stabilize_expr (CALL_EXPR_ARG (call, i), &init);
6502 : 518362 : inits = add_stmt_to_compound (inits, init);
6503 : : }
6504 : :
6505 : 259148 : *initp = inits;
6506 : : }
6507 : :
6508 : : /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
6509 : : to pre-evaluate. CALL is modified in place to use the pre-evaluated
6510 : : arguments, while, upon return, *INITP contains an expression to
6511 : : compute the arguments. */
6512 : :
6513 : : static void
6514 : 0 : stabilize_aggr_init (tree call, tree *initp)
6515 : : {
6516 : 0 : tree inits = NULL_TREE;
6517 : 0 : int i;
6518 : 0 : int nargs = aggr_init_expr_nargs (call);
6519 : :
6520 : 0 : if (call == error_mark_node)
6521 : : return;
6522 : :
6523 : 0 : gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
6524 : :
6525 : 0 : for (i = 0; i < nargs; i++)
6526 : : {
6527 : 0 : tree init;
6528 : 0 : AGGR_INIT_EXPR_ARG (call, i) =
6529 : 0 : stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
6530 : 0 : inits = add_stmt_to_compound (inits, init);
6531 : : }
6532 : :
6533 : 0 : *initp = inits;
6534 : : }
6535 : :
6536 : : /* Like stabilize_expr, but for an initialization.
6537 : :
6538 : : If the initialization is for an object of class type, this function
6539 : : takes care not to introduce additional temporaries.
6540 : :
6541 : : Returns TRUE iff the expression was successfully pre-evaluated,
6542 : : i.e., if INIT is now side-effect free, except for, possibly, a
6543 : : single call to a constructor. */
6544 : :
6545 : : bool
6546 : 0 : stabilize_init (tree init, tree *initp)
6547 : : {
6548 : 0 : tree t = init;
6549 : :
6550 : 0 : *initp = NULL_TREE;
6551 : :
6552 : 0 : if (t == error_mark_node || processing_template_decl)
6553 : : return true;
6554 : :
6555 : 0 : if (TREE_CODE (t) == INIT_EXPR)
6556 : 0 : t = TREE_OPERAND (t, 1);
6557 : 0 : if (TREE_CODE (t) == TARGET_EXPR)
6558 : 0 : t = TARGET_EXPR_INITIAL (t);
6559 : :
6560 : : /* If the RHS can be stabilized without breaking copy elision, stabilize
6561 : : it. We specifically don't stabilize class prvalues here because that
6562 : : would mean an extra copy, but they might be stabilized below. */
6563 : 0 : if (TREE_CODE (init) == INIT_EXPR
6564 : 0 : && TREE_CODE (t) != CONSTRUCTOR
6565 : 0 : && TREE_CODE (t) != AGGR_INIT_EXPR
6566 : 0 : && (SCALAR_TYPE_P (TREE_TYPE (t))
6567 : 0 : || glvalue_p (t)))
6568 : : {
6569 : 0 : TREE_OPERAND (init, 1) = stabilize_expr (t, initp);
6570 : 0 : return true;
6571 : : }
6572 : :
6573 : 0 : if (TREE_CODE (t) == COMPOUND_EXPR
6574 : 0 : && TREE_CODE (init) == INIT_EXPR)
6575 : : {
6576 : 0 : tree last = expr_last (t);
6577 : : /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */
6578 : 0 : if (!TREE_SIDE_EFFECTS (last))
6579 : : {
6580 : 0 : *initp = t;
6581 : 0 : TREE_OPERAND (init, 1) = last;
6582 : 0 : return true;
6583 : : }
6584 : : }
6585 : :
6586 : 0 : if (TREE_CODE (t) == CONSTRUCTOR)
6587 : : {
6588 : : /* Aggregate initialization: stabilize each of the field
6589 : : initializers. */
6590 : 0 : unsigned i;
6591 : 0 : constructor_elt *ce;
6592 : 0 : bool good = true;
6593 : 0 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
6594 : 0 : for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
6595 : : {
6596 : 0 : tree type = TREE_TYPE (ce->value);
6597 : 0 : tree subinit;
6598 : 0 : if (TYPE_REF_P (type)
6599 : 0 : || SCALAR_TYPE_P (type))
6600 : 0 : ce->value = stabilize_expr (ce->value, &subinit);
6601 : 0 : else if (!stabilize_init (ce->value, &subinit))
6602 : 0 : good = false;
6603 : 0 : *initp = add_stmt_to_compound (*initp, subinit);
6604 : : }
6605 : : return good;
6606 : : }
6607 : :
6608 : 0 : if (TREE_CODE (t) == CALL_EXPR)
6609 : : {
6610 : 0 : stabilize_call (t, initp);
6611 : 0 : return true;
6612 : : }
6613 : :
6614 : 0 : if (TREE_CODE (t) == AGGR_INIT_EXPR)
6615 : : {
6616 : 0 : stabilize_aggr_init (t, initp);
6617 : 0 : return true;
6618 : : }
6619 : :
6620 : : /* The initialization is being performed via a bitwise copy -- and
6621 : : the item copied may have side effects. */
6622 : 0 : return !TREE_SIDE_EFFECTS (init);
6623 : : }
6624 : :
6625 : : /* Returns true if a cast to TYPE may appear in an integral constant
6626 : : expression. */
6627 : :
6628 : : bool
6629 : 82931242 : cast_valid_in_integral_constant_expression_p (tree type)
6630 : : {
6631 : 82931242 : return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
6632 : 60944550 : || cxx_dialect >= cxx11
6633 : 309150 : || dependent_type_p (type)
6634 : 83147403 : || type == error_mark_node);
6635 : : }
6636 : :
6637 : : /* Return true if we need to fix linkage information of DECL. */
6638 : :
6639 : : static bool
6640 : 2243964 : cp_fix_function_decl_p (tree decl)
6641 : : {
6642 : : /* Skip if DECL is not externally visible. */
6643 : 2243964 : if (!TREE_PUBLIC (decl))
6644 : : return false;
6645 : :
6646 : : /* We need to fix DECL if it a appears to be exported but with no
6647 : : function body. Thunks do not have CFGs and we may need to
6648 : : handle them specially later. */
6649 : 2241576 : if (!gimple_has_body_p (decl)
6650 : 2197588 : && !DECL_THUNK_P (decl)
6651 : 4438632 : && !DECL_EXTERNAL (decl))
6652 : : {
6653 : 15473 : struct cgraph_node *node = cgraph_node::get (decl);
6654 : :
6655 : : /* Don't fix same_body aliases. Although they don't have their own
6656 : : CFG, they share it with what they alias to. */
6657 : 15473 : if (!node || !node->alias || !node->num_references ())
6658 : : return true;
6659 : : }
6660 : :
6661 : : return false;
6662 : : }
6663 : :
6664 : : /* Clean the C++ specific parts of the tree T. */
6665 : :
6666 : : void
6667 : 3812253 : cp_free_lang_data (tree t)
6668 : : {
6669 : 3812253 : if (FUNC_OR_METHOD_TYPE_P (t))
6670 : : {
6671 : : /* Default args are not interesting anymore. */
6672 : 703910 : tree argtypes = TYPE_ARG_TYPES (t);
6673 : 2634923 : while (argtypes)
6674 : : {
6675 : 1931013 : TREE_PURPOSE (argtypes) = 0;
6676 : 1931013 : argtypes = TREE_CHAIN (argtypes);
6677 : : }
6678 : : }
6679 : 3108343 : else if (TREE_CODE (t) == FUNCTION_DECL
6680 : 3108343 : && cp_fix_function_decl_p (t))
6681 : : {
6682 : : /* If T is used in this translation unit at all, the definition
6683 : : must exist somewhere else since we have decided to not emit it
6684 : : in this TU. So make it an external reference. */
6685 : 9523 : DECL_EXTERNAL (t) = 1;
6686 : 9523 : TREE_STATIC (t) = 0;
6687 : : }
6688 : 3812253 : if (TREE_CODE (t) == NAMESPACE_DECL)
6689 : : /* We do not need the leftover chaining of namespaces from the
6690 : : binding level. */
6691 : 3491 : DECL_CHAIN (t) = NULL_TREE;
6692 : 3812253 : }
6693 : :
6694 : : /* Stub for c-common. Please keep in sync with c-decl.cc.
6695 : : FIXME: If address space support is target specific, then this
6696 : : should be a C target hook. But currently this is not possible,
6697 : : because this function is called via REGISTER_TARGET_PRAGMAS. */
6698 : : void
6699 : 190396 : c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
6700 : : {
6701 : 190396 : }
6702 : :
6703 : : /* Return the number of operands in T that we care about for things like
6704 : : mangling. */
6705 : :
6706 : : int
6707 : 468036460 : cp_tree_operand_length (const_tree t)
6708 : : {
6709 : 468036460 : enum tree_code code = TREE_CODE (t);
6710 : :
6711 : 468036460 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
6712 : 53232359 : return VL_EXP_OPERAND_LENGTH (t);
6713 : :
6714 : 414804101 : return cp_tree_code_length (code);
6715 : : }
6716 : :
6717 : : /* Like cp_tree_operand_length, but takes a tree_code CODE. */
6718 : :
6719 : : int
6720 : 418706628 : cp_tree_code_length (enum tree_code code)
6721 : : {
6722 : 418706628 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
6723 : :
6724 : 418706628 : switch (code)
6725 : : {
6726 : : case PREINCREMENT_EXPR:
6727 : : case PREDECREMENT_EXPR:
6728 : : case POSTINCREMENT_EXPR:
6729 : : case POSTDECREMENT_EXPR:
6730 : : return 1;
6731 : :
6732 : 399650 : case ARRAY_REF:
6733 : 399650 : return 2;
6734 : :
6735 : : case EXPR_PACK_EXPANSION:
6736 : : return 1;
6737 : :
6738 : 416228915 : default:
6739 : 416228915 : return TREE_CODE_LENGTH (code);
6740 : : }
6741 : : }
6742 : :
6743 : : /* Implement -Wzero_as_null_pointer_constant. Return true if the
6744 : : conditions for the warning hold, false otherwise. */
6745 : : bool
6746 : 5561743 : maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
6747 : : {
6748 : 5561743 : if (c_inhibit_evaluation_warnings == 0
6749 : 10589134 : && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
6750 : : {
6751 : 1977678 : warning_at (loc, OPT_Wzero_as_null_pointer_constant,
6752 : : "zero as null pointer constant");
6753 : 1977678 : return true;
6754 : : }
6755 : : return false;
6756 : : }
6757 : :
6758 : : /* FNDECL is a function declaration whose type may have been altered by
6759 : : adding extra parameters such as this, in-charge, or VTT. When this
6760 : : takes place, the positional arguments supplied by the user (as in the
6761 : : 'format' attribute arguments) may refer to the wrong argument. This
6762 : : function returns an integer indicating how many arguments should be
6763 : : skipped. */
6764 : :
6765 : : int
6766 : 36134671 : maybe_adjust_arg_pos_for_attribute (const_tree fndecl)
6767 : : {
6768 : 36134671 : if (!fndecl)
6769 : : return 0;
6770 : 6939105 : int n = num_artificial_parms_for (fndecl);
6771 : : /* The manual states that it's the user's responsibility to account
6772 : : for the implicit this parameter. */
6773 : 6939105 : return n > 0 ? n - 1 : 0;
6774 : : }
6775 : :
6776 : :
6777 : : /* Release memory we no longer need after parsing. */
6778 : : void
6779 : 93654 : cp_tree_c_finish_parsing ()
6780 : : {
6781 : 93654 : if (previous_class_level)
6782 : 66555 : invalidate_class_lookup_cache ();
6783 : 93654 : deleted_copy_types = NULL;
6784 : 93654 : }
6785 : :
6786 : : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
6787 : : /* Complain that some language-specific thing hanging off a tree
6788 : : node has been accessed improperly. */
6789 : :
6790 : : void
6791 : 0 : lang_check_failed (const char* file, int line, const char* function)
6792 : : {
6793 : 0 : internal_error ("%<lang_*%> check: failed in %s, at %s:%d",
6794 : : function, trim_filename (file), line);
6795 : : }
6796 : : #endif /* ENABLE_TREE_CHECKING */
6797 : :
6798 : : #if CHECKING_P
6799 : :
6800 : : namespace selftest {
6801 : :
6802 : : /* Verify that lvalue_kind () works, for various expressions,
6803 : : and that location wrappers don't affect the results. */
6804 : :
6805 : : static void
6806 : 1 : test_lvalue_kind ()
6807 : : {
6808 : 1 : location_t loc = BUILTINS_LOCATION;
6809 : :
6810 : : /* Verify constants and parameters, without and with
6811 : : location wrappers. */
6812 : 1 : tree int_cst = build_int_cst (integer_type_node, 42);
6813 : 1 : ASSERT_EQ (clk_none, lvalue_kind (int_cst));
6814 : :
6815 : 1 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
6816 : 1 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
6817 : 1 : ASSERT_EQ (clk_none, lvalue_kind (wrapped_int_cst));
6818 : :
6819 : 1 : tree string_lit = build_string (4, "foo");
6820 : 1 : TREE_TYPE (string_lit) = char_array_type_node;
6821 : 1 : string_lit = fix_string_type (string_lit);
6822 : 1 : ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (string_lit));
6823 : :
6824 : 1 : tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
6825 : 1 : ASSERT_TRUE (location_wrapper_p (wrapped_string_lit));
6826 : 1 : ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (wrapped_string_lit));
6827 : :
6828 : 1 : tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL,
6829 : : get_identifier ("some_parm"),
6830 : : integer_type_node);
6831 : 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (parm));
6832 : :
6833 : 1 : tree wrapped_parm = maybe_wrap_with_location (parm, loc);
6834 : 1 : ASSERT_TRUE (location_wrapper_p (wrapped_parm));
6835 : 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_parm));
6836 : :
6837 : : /* Verify that lvalue_kind of std::move on a parm isn't
6838 : : affected by location wrappers. */
6839 : 1 : tree rvalue_ref_of_parm = move (parm);
6840 : 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm));
6841 : 1 : tree rvalue_ref_of_wrapped_parm = move (wrapped_parm);
6842 : 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm));
6843 : :
6844 : : /* Verify lvalue_p. */
6845 : 1 : ASSERT_FALSE (lvalue_p (int_cst));
6846 : 1 : ASSERT_FALSE (lvalue_p (wrapped_int_cst));
6847 : 1 : ASSERT_TRUE (lvalue_p (parm));
6848 : 1 : ASSERT_TRUE (lvalue_p (wrapped_parm));
6849 : 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm));
6850 : 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm));
6851 : 1 : }
6852 : :
6853 : : /* Run all of the selftests within this file. */
6854 : :
6855 : : void
6856 : 1 : cp_tree_cc_tests ()
6857 : : {
6858 : 1 : test_lvalue_kind ();
6859 : 1 : }
6860 : :
6861 : : } // namespace selftest
6862 : :
6863 : : #endif /* #if CHECKING_P */
6864 : :
6865 : :
6866 : : #include "gt-cp-tree.h"
|