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