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 : 2175046829 : lvalue_kind (const_tree ref)
57 : : {
58 : 2375280942 : cp_lvalue_kind op1_lvalue_kind = clk_none;
59 : 2375280942 : 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 : 2375280942 : if (REFERENCE_REF_P (ref))
66 : 188447758 : return lvalue_kind (TREE_OPERAND (ref, 0));
67 : :
68 : 2186833184 : if (TREE_TYPE (ref)
69 : 2186833184 : && TYPE_REF_P (TREE_TYPE (ref)))
70 : : {
71 : : /* unnamed rvalue references are rvalues */
72 : 191786520 : 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 : 230057834 : && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
78 : : {
79 : 38270703 : op1_lvalue_kind = clk_rvalueref;
80 : 38270703 : if (implicit_rvalue_p (ref))
81 : 6120371 : op1_lvalue_kind |= clk_implicit_rval;
82 : 38270703 : return op1_lvalue_kind;
83 : : }
84 : :
85 : : /* lvalue references and named rvalue references are lvalues. */
86 : : return clk_ordinary;
87 : : }
88 : :
89 : 1995046664 : if (ref == current_class_ptr)
90 : : return clk_none;
91 : :
92 : : /* Expressions with cv void type are prvalues. */
93 : 1993047393 : if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
94 : : return clk_none;
95 : :
96 : 1992543383 : 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 : 267675147 : case PREINCREMENT_EXPR:
104 : 267675147 : case PREDECREMENT_EXPR:
105 : 267675147 : case TRY_CATCH_EXPR:
106 : 267675147 : case REALPART_EXPR:
107 : 267675147 : case IMAGPART_EXPR:
108 : 267675147 : case VIEW_CONVERT_EXPR:
109 : 267675147 : 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 : 267675147 : if (op1_lvalue_kind == clk_class
115 : 267675161 : && !(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 : 3028652 : case ARRAY_REF:
122 : 3028652 : {
123 : 3028652 : tree op1 = TREE_OPERAND (ref, 0);
124 : 3028652 : if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
125 : : {
126 : 2539087 : op1_lvalue_kind = lvalue_kind (op1);
127 : 2539087 : 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 : 1775 : op1_lvalue_kind = clk_rvalueref;
131 : 2539087 : 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 : 144731403 : case COMPONENT_REF:
153 : 144731403 : 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 : 144731376 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
165 : 144731376 : 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 : 144462847 : if (!op1_lvalue_kind)
172 : : ;
173 : 144731352 : 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 : 144731261 : else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
179 : : /* This can be IDENTIFIER_NODE in a template. */;
180 : 138254936 : 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 : 9216269 : op1_lvalue_kind &= ~clk_ordinary;
185 : : /* The lvalue is for a bitfield. */
186 : 9216269 : op1_lvalue_kind |= clk_bitfield;
187 : : }
188 : 129038667 : 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 : 1508831 : 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 : 1508831 : if (! TREE_STATIC (ref))
205 : : return clk_none;
206 : : /* FALLTHRU */
207 : 216094850 : case VAR_DECL:
208 : 216094850 : if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
209 : 787245 : return lvalue_kind (DECL_VALUE_EXPR (CONST_CAST_TREE (ref)));
210 : :
211 : 297255551 : if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
212 : 13768973 : && DECL_LANG_SPECIFIC (ref)
213 : 216039700 : && DECL_IN_AGGR_P (ref))
214 : : return clk_none;
215 : :
216 : 215307605 : 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 : 8846858 : case SCOPE_REF:
230 : 8846858 : gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
231 : 8846858 : {
232 : 8846858 : tree op = TREE_OPERAND (ref, 1);
233 : 8846858 : if (TREE_CODE (op) == FIELD_DECL)
234 : 19561 : 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 : 10064856 : case COND_EXPR:
250 : 10064856 : 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 : 1014445 : gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
259 : 1014445 : goto default_;
260 : : }
261 : 9050411 : {
262 : 9050411 : tree op1 = TREE_OPERAND (ref, 1);
263 : 9050411 : if (!op1) op1 = TREE_OPERAND (ref, 0);
264 : 9050411 : tree op2 = TREE_OPERAND (ref, 2);
265 : 9050411 : op1_lvalue_kind = lvalue_kind (op1);
266 : 9050411 : op2_lvalue_kind = lvalue_kind (op2);
267 : 9050411 : 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 : 548478 : if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
273 : : op2_lvalue_kind = op1_lvalue_kind;
274 : 548436 : else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
275 : 9050896 : op1_lvalue_kind = op2_lvalue_kind;
276 : : }
277 : : }
278 : : break;
279 : :
280 : 72467 : case MODOP_EXPR:
281 : : /* We expect to see unlowered MODOP_EXPRs only during
282 : : template processing. */
283 : 72467 : gcc_assert (processing_template_decl);
284 : 72467 : 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 : 2135034 : case COMPOUND_EXPR:
294 : 2135034 : 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 : 100328849 : case CALL_EXPR:
303 : : /* We can see calls outside of TARGET_EXPR in templates. */
304 : 100328849 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
305 : : return clk_class;
306 : : return clk_none;
307 : :
308 : 105882279 : case FUNCTION_DECL:
309 : : /* All functions (except non-static-member functions) are
310 : : lvalues. */
311 : 105882279 : return (DECL_IOBJ_MEMBER_FUNCTION_P (ref)
312 : 105882279 : ? clk_none : clk_ordinary);
313 : :
314 : 3206 : 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 : 3206 : return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
320 : :
321 : 33546 : case PAREN_EXPR:
322 : 33546 : return lvalue_kind (TREE_OPERAND (ref, 0));
323 : :
324 : 16127638 : case TEMPLATE_PARM_INDEX:
325 : 16127638 : 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 : 794754114 : default:
331 : 794754114 : default_:
332 : 794754114 : if (!TREE_TYPE (ref))
333 : : return clk_none;
334 : 1589508228 : if (CLASS_TYPE_P (TREE_TYPE (ref))
335 : 1587588039 : || 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 : 9050896 : 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 : 2013681 : op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
348 : : /* It's not an ordinary lvalue if it involves any other kind. */
349 : 2013681 : if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
350 : 338871 : 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 : 338871 : if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
354 : 26306 : && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
355 : 906592567 : 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 : 38270097 : real_lvalue_p (const_tree ref)
363 : : {
364 : 38270097 : cp_lvalue_kind kind = lvalue_kind (ref);
365 : 38270097 : if (kind & (clk_rvalueref|clk_class))
366 : : return clk_none;
367 : : else
368 : 36492561 : return kind;
369 : : }
370 : :
371 : : /* c-common wants us to return bool. */
372 : :
373 : : bool
374 : 37764507 : lvalue_p (const_tree t)
375 : : {
376 : 37764507 : return real_lvalue_p (t);
377 : : }
378 : :
379 : : /* This differs from lvalue_p in that xvalues are included. */
380 : :
381 : : bool
382 : 128942844 : glvalue_p (const_tree ref)
383 : : {
384 : 128942844 : cp_lvalue_kind kind = lvalue_kind (ref);
385 : 128942844 : if (kind & clk_class)
386 : : return false;
387 : : else
388 : 127007538 : return (kind != clk_none);
389 : : }
390 : :
391 : : /* This differs from glvalue_p in that class prvalues are included. */
392 : :
393 : : bool
394 : 1022568341 : obvalue_p (const_tree ref)
395 : : {
396 : 1022568341 : 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 : 5433496 : xvalue_p (const_tree ref)
404 : : {
405 : 5433496 : return (lvalue_kind (ref) & clk_rvalueref);
406 : : }
407 : :
408 : : /* True if REF is a bit-field. */
409 : :
410 : : bool
411 : 178559099 : bitfield_p (const_tree ref)
412 : : {
413 : 178559099 : 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 : 4398982 : cp_stabilize_reference (tree ref)
431 : : {
432 : 4398982 : if (processing_template_decl)
433 : : /* As in cp_save_expr. */
434 : : return ref;
435 : :
436 : 3736991 : STRIP_ANY_LOCATION_WRAPPER (ref);
437 : 3736991 : 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 : 3736991 : 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 : 423843484 : builtin_valid_in_constant_expr_p (const_tree decl)
477 : : {
478 : 423843484 : STRIP_ANY_LOCATION_WRAPPER (decl);
479 : 423843484 : if (TREE_CODE (decl) != FUNCTION_DECL)
480 : : /* Not a function. */
481 : : return false;
482 : 190955799 : if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
483 : : {
484 : 156753455 : if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
485 : 157849 : 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 : 34202344 : 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 : 27912895 : build_target_expr (tree decl, tree value, tsubst_flags_t complain)
527 : : {
528 : 27912895 : tree t;
529 : 27912895 : tree type = TREE_TYPE (decl);
530 : :
531 : 27912895 : value = mark_rvalue_use (value);
532 : :
533 : 27912895 : 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 : 27912895 : if (CP_TYPE_CONST_NON_VOLATILE_P (type)
544 : 1693172 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
545 : 1520597 : && !VOID_TYPE_P (TREE_TYPE (value))
546 : 935421 : && !TYPE_HAS_MUTABLE_P (type)
547 : 28848310 : && reduced_constant_expression_p (value))
548 : 327715 : TREE_READONLY (decl) = true;
549 : :
550 : 27912895 : 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 : 27548902 : t = cxx_maybe_build_cleanup (decl, complain);
556 : 27548902 : if (t == error_mark_node)
557 : : return error_mark_node;
558 : : }
559 : :
560 : 27912865 : set_target_expr_eliding (value);
561 : :
562 : 27912865 : t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
563 : 27912865 : if (location_t eloc = cp_expr_location (value))
564 : 17885231 : 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 : 27912865 : TREE_SIDE_EFFECTS (t) = 1;
570 : :
571 : 27912865 : 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 : 31030234 : build_local_temp (tree type)
579 : : {
580 : 31030234 : tree slot = build_decl (input_location,
581 : : VAR_DECL, NULL_TREE, type);
582 : 31030234 : DECL_ARTIFICIAL (slot) = 1;
583 : 31030234 : DECL_IGNORED_P (slot) = 1;
584 : 31030234 : DECL_CONTEXT (slot) = current_function_decl;
585 : 31030234 : layout_decl (slot, 0);
586 : 31030234 : 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 : 52119301 : is_local_temp (tree decl)
594 : : {
595 : 52119301 : return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
596 : 52603723 : && !TREE_STATIC (decl));
597 : : }
598 : :
599 : : /* Set various status flags when building an AGGR_INIT_EXPR object T. */
600 : :
601 : : static void
602 : 9236271 : process_aggr_init_operands (tree t)
603 : : {
604 : 9236271 : bool side_effects;
605 : :
606 : 9236271 : side_effects = TREE_SIDE_EFFECTS (t);
607 : 9236271 : if (!side_effects)
608 : : {
609 : 9236271 : int i, n;
610 : 9236271 : n = TREE_OPERAND_LENGTH (t);
611 : 41001358 : for (i = 1; i < n; i++)
612 : : {
613 : 34301082 : tree op = TREE_OPERAND (t, i);
614 : 34301082 : if (op && TREE_SIDE_EFFECTS (op))
615 : : {
616 : : side_effects = 1;
617 : : break;
618 : : }
619 : : }
620 : : }
621 : 9236271 : TREE_SIDE_EFFECTS (t) = side_effects;
622 : 9236271 : }
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 : 9236271 : build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
630 : : tree *args)
631 : : {
632 : 9236271 : tree t;
633 : 9236271 : int i;
634 : :
635 : 9236271 : t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
636 : 9236271 : TREE_TYPE (t) = return_type;
637 : 9236271 : AGGR_INIT_EXPR_FN (t) = fn;
638 : 9236271 : AGGR_INIT_EXPR_SLOT (t) = slot;
639 : 26204254 : for (i = 0; i < nargs; i++)
640 : 16967983 : AGGR_INIT_EXPR_ARG (t, i) = args[i];
641 : 9236271 : process_aggr_init_operands (t);
642 : 9236271 : 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 : 30916321 : build_aggr_init_expr (tree type, tree init)
657 : : {
658 : 30916321 : tree fn;
659 : 30916321 : tree slot;
660 : 30916321 : tree rval;
661 : 30916321 : int is_ctor;
662 : :
663 : 30916321 : gcc_assert (!VOID_TYPE_P (type));
664 : :
665 : : /* Don't build AGGR_INIT_EXPR in a template. */
666 : 30916321 : if (processing_template_decl)
667 : : return init;
668 : :
669 : 30832253 : fn = cp_get_callee (init);
670 : 30832253 : if (fn == NULL_TREE)
671 : 13126005 : return convert (type, init);
672 : :
673 : 36603946 : is_ctor = (TREE_CODE (fn) == ADDR_EXPR
674 : 17646034 : && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
675 : 52998316 : && 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 : 9661427 : if (is_ctor || TREE_ADDRESSABLE (type))
689 : : {
690 : 9236271 : slot = build_local_temp (type);
691 : :
692 : 9236271 : if (TREE_CODE (init) == CALL_EXPR)
693 : : {
694 : 35555124 : rval = build_aggr_init_array (void_type_node, fn, slot,
695 : 8888781 : call_expr_nargs (init),
696 : 8888781 : CALL_EXPR_ARGP (init));
697 : 8888781 : AGGR_INIT_FROM_THUNK_P (rval)
698 : 8888781 : = CALL_FROM_THUNK_P (init);
699 : : }
700 : : else
701 : : {
702 : 347490 : rval = build_aggr_init_array (void_type_node, fn, slot,
703 : 347490 : aggr_init_expr_nargs (init),
704 : 347490 : AGGR_INIT_EXPR_ARGP (init));
705 : 347490 : AGGR_INIT_FROM_THUNK_P (rval)
706 : 347490 : = AGGR_INIT_FROM_THUNK_P (init);
707 : : }
708 : 9236271 : TREE_SIDE_EFFECTS (rval) = 1;
709 : 9236271 : AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
710 : 9236271 : TREE_NOTHROW (rval) = TREE_NOTHROW (init);
711 : 9236271 : CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
712 : 9236271 : CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
713 : 9236271 : CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
714 : 9236271 : 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 : 27060943 : 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 : 27060943 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
737 : : {
738 : 285 : gcc_assert (cxx_dialect >= cxx20);
739 : 285 : return finish_compound_literal (type, init, complain);
740 : : }
741 : :
742 : 27060658 : tree rval = build_aggr_init_expr (type, init);
743 : 27060658 : tree slot;
744 : :
745 : 27060658 : if (init == error_mark_node)
746 : : return error_mark_node;
747 : :
748 : 27058703 : 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 : 27058697 : if (abstract_virtuals_error (NULL_TREE, type, complain))
754 : 15 : return error_mark_node;
755 : :
756 : 27058682 : if (TREE_CODE (rval) == AGGR_INIT_EXPR)
757 : 5579094 : slot = AGGR_INIT_EXPR_SLOT (rval);
758 : 21479588 : else if (TREE_CODE (rval) == CALL_EXPR
759 : 12925552 : || TREE_CODE (rval) == CONSTRUCTOR)
760 : 8554053 : slot = build_local_temp (type);
761 : : else
762 : : return rval;
763 : :
764 : 14133147 : rval = build_target_expr (slot, rval, complain);
765 : :
766 : 14133147 : if (rval != error_mark_node)
767 : 14133147 : 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 : 1167 : build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
785 : : {
786 : 1167 : tree inner_type = strip_array_types (type);
787 : :
788 : 1167 : if (integer_zerop (array_type_nelts_total (type))
789 : 1167 : || !CLASS_TYPE_P (inner_type))
790 : : /* No interesting initialization to do. */
791 : 220 : return integer_zero_node;
792 : 947 : 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 : 120 : 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 : 86 : init = void_type_node;
804 : : }
805 : 913 : if (init == void_type_node)
806 : 117 : return build_value_init (inner_type, complain);
807 : :
808 : 796 : releasing_vec argvec;
809 : 796 : 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 : 796 : 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 : 796 : if (TREE_CODE (init) == TARGET_EXPR)
824 : 32 : init = TARGET_EXPR_INITIAL (init);
825 : :
826 : 796 : return init;
827 : 796 : }
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 : 1184 : build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
835 : : {
836 : 1184 : if (tree vi = get_vec_init_expr (init))
837 : : return vi;
838 : :
839 : 1169 : tree elt_init;
840 : 561 : if (init && TREE_CODE (init) == CONSTRUCTOR
841 : 1293 : && !BRACE_ENCLOSED_INITIALIZER_P (init))
842 : : /* We built any needed constructor calls in digest_init. */
843 : : elt_init = init;
844 : : else
845 : 1165 : elt_init = build_vec_init_elt (type, init, complain);
846 : :
847 : 1169 : bool value_init = false;
848 : 1169 : if (init == void_type_node)
849 : : {
850 : 230 : value_init = true;
851 : 230 : init = NULL_TREE;
852 : : }
853 : :
854 : 1169 : tree slot = build_local_temp (type);
855 : 1169 : init = build2 (VEC_INIT_EXPR, type, slot, init);
856 : 1169 : TREE_SIDE_EFFECTS (init) = true;
857 : 1169 : SET_EXPR_LOCATION (init, input_location);
858 : :
859 : 1169 : if (cxx_dialect >= cxx11)
860 : : {
861 : 1106 : bool cx = potential_constant_expression (elt_init);
862 : 1106 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
863 : 0 : cx &= potential_constant_expression (init);
864 : 1106 : VEC_INIT_EXPR_IS_CONSTEXPR (init) = cx;
865 : : }
866 : 1169 : VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
867 : :
868 : 1169 : 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 : 1184 : expand_vec_init_expr (tree target, tree vec_init, tsubst_flags_t complain,
876 : : vec<tree,va_gc> **flags)
877 : : {
878 : 1184 : iloc_sentinel ils = EXPR_LOCATION (vec_init);
879 : :
880 : 1184 : if (!target)
881 : 0 : target = VEC_INIT_EXPR_SLOT (vec_init);
882 : 1184 : tree init = VEC_INIT_EXPR_INIT (vec_init);
883 : 1184 : int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
884 : 3552 : return build_vec_init (target, NULL_TREE, init,
885 : 1184 : VEC_INIT_EXPR_VALUE_INIT (vec_init),
886 : 1184 : from_array, complain, flags);
887 : 1184 : }
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 : 2 : diagnose_non_constexpr_vec_init (tree expr)
894 : : {
895 : 2 : tree type = TREE_TYPE (VEC_INIT_EXPR_SLOT (expr));
896 : 2 : tree init, elt_init;
897 : 2 : if (VEC_INIT_EXPR_VALUE_INIT (expr))
898 : 2 : init = void_type_node;
899 : : else
900 : 0 : init = VEC_INIT_EXPR_INIT (expr);
901 : :
902 : 2 : elt_init = build_vec_init_elt (type, init, tf_warning_or_error);
903 : 2 : require_potential_constant_expression (elt_init);
904 : 2 : }
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 : 7777270 : build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
918 : : {
919 : 7777270 : gcc_assert (!VOID_TYPE_P (type));
920 : 7777270 : gcc_assert (!VOID_TYPE_P (TREE_TYPE (init)));
921 : :
922 : 7777270 : if (TREE_CODE (init) == TARGET_EXPR
923 : 7058970 : || init == error_mark_node)
924 : : return init;
925 : 5096271 : else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
926 : 64598 : && TREE_CODE (init) != COND_EXPR
927 : : && TREE_CODE (init) != CONSTRUCTOR
928 : : && TREE_CODE (init) != VA_ARG_EXPR
929 : 7058673 : && 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 : 7058673 : 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 : 13238718 : force_target_expr (tree type, tree init, tsubst_flags_t complain)
948 : : {
949 : 13238718 : tree slot;
950 : :
951 : 13238718 : gcc_assert (!VOID_TYPE_P (type));
952 : :
953 : 13238718 : slot = build_local_temp (type);
954 : 13238718 : 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 : 6215757 : get_target_expr (tree init, tsubst_flags_t complain /* = tf_warning_or_error */)
961 : : {
962 : 6215757 : if (TREE_CODE (init) == AGGR_INIT_EXPR)
963 : 540735 : return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
964 : 5675022 : else if (TREE_CODE (init) == VEC_INIT_EXPR)
965 : 295 : return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
966 : : else
967 : : {
968 : 5674727 : init = convert_bitfield_to_declared_type (init);
969 : 5674727 : 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 : 1790400 : get_internal_target_expr (tree init)
984 : : {
985 : 1790400 : init = convert_bitfield_to_declared_type (init);
986 : 1790400 : tree t = force_target_expr (TREE_TYPE (init), init, tf_warning_or_error);
987 : 1790400 : TARGET_EXPR_INTERNAL_P (t) = true;
988 : 1790400 : 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 : 907738228 : convert_bitfield_to_declared_type (tree expr)
997 : : {
998 : 907738228 : tree bitfield_type;
999 : :
1000 : 907738228 : bitfield_type = is_bitfield_expr_with_lowered_type (expr);
1001 : 907738228 : if (bitfield_type)
1002 : 666001 : expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
1003 : : expr);
1004 : 907738228 : 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 : 164390051 : rvalue (tree expr)
1012 : : {
1013 : 164390051 : tree type;
1014 : :
1015 : 164390051 : if (error_operand_p (expr))
1016 : : return expr;
1017 : :
1018 : 164389724 : 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 : 164389724 : type = TREE_TYPE (expr);
1024 : 164389724 : if (!CLASS_TYPE_P (type) && TREE_CODE (type) != ARRAY_TYPE
1025 : 326845376 : && cv_qualified_p (type))
1026 : 33095103 : 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 : 164389724 : 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 : 8658958 : gcc_checking_assert (!CLASS_TYPE_P (type));
1035 : 8658958 : expr = build1 (NON_LVALUE_EXPR, type, expr);
1036 : : }
1037 : 155730766 : else if (type != TREE_TYPE (expr))
1038 : 32843169 : 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 : 31264264 : cplus_array_hasher::hash (tree t)
1062 : : {
1063 : 31264264 : hashval_t hash;
1064 : :
1065 : 31264264 : hash = TYPE_UID (TREE_TYPE (t));
1066 : 31264264 : if (TYPE_DOMAIN (t))
1067 : 28991888 : hash ^= TYPE_UID (TYPE_DOMAIN (t));
1068 : 31264264 : 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 : 38310223 : cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
1076 : : {
1077 : 40669612 : 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 : 4469416 : build_min_array_type (tree elt_type, tree index_type)
1088 : : {
1089 : 4469416 : tree t = cxx_make_type (ARRAY_TYPE);
1090 : 4469416 : TREE_TYPE (t) = elt_type;
1091 : 4469416 : TYPE_DOMAIN (t) = index_type;
1092 : 4469416 : 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 : 4469416 : 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 : 4469416 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
1103 : 4469416 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
1104 : 1089247 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1105 : 3380169 : else if (TYPE_CANONICAL (elt_type) != elt_type
1106 : 3380169 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
1107 : 938434 : TYPE_CANONICAL (t)
1108 : 2435826 : = build_cplus_array_type (TYPE_CANONICAL (elt_type),
1109 : : index_type
1110 : 558958 : ? TYPE_CANONICAL (index_type) : index_type,
1111 : : dep);
1112 : : else
1113 : 2441735 : TYPE_CANONICAL (t) = t;
1114 : 4469416 : }
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 : 57626753 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
1123 : : {
1124 : 57626753 : tree t;
1125 : :
1126 : 57626753 : if (elt_type == error_mark_node || index_type == error_mark_node)
1127 : : return error_mark_node;
1128 : :
1129 : 57626750 : if (dependent < 0)
1130 : 59675604 : dependent = (uses_template_parms (elt_type)
1131 : 29837802 : || (index_type && uses_template_parms (index_type)));
1132 : :
1133 : 57626750 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1134 : : /* Start with an array of the TYPE_MAIN_VARIANT. */
1135 : 24923865 : t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
1136 : : index_type, dependent);
1137 : 32702885 : else if (dependent)
1138 : : {
1139 : : /* Since type_hash_canon calls layout_type, we need to use our own
1140 : : hash table. */
1141 : 3806834 : cplus_array_info cai;
1142 : 3806834 : hashval_t hash;
1143 : :
1144 : 3806834 : if (cplus_array_htab == NULL)
1145 : 17201 : cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61);
1146 : :
1147 : 3806834 : hash = TYPE_UID (elt_type);
1148 : 3806834 : if (index_type)
1149 : 2025652 : hash ^= TYPE_UID (index_type);
1150 : 3806834 : cai.type = elt_type;
1151 : 3806834 : cai.domain = index_type;
1152 : :
1153 : 3806834 : tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
1154 : 3806834 : if (*e)
1155 : : /* We have found the type: we're done. */
1156 : 2240554 : return (tree) *e;
1157 : : else
1158 : : {
1159 : : /* Build a new array type. */
1160 : 1566280 : t = build_min_array_type (elt_type, index_type);
1161 : :
1162 : : /* Store it in the hash table. */
1163 : 1566280 : *e = t;
1164 : :
1165 : : /* Set the canonical type for this new node. */
1166 : 1566280 : set_array_type_canon (t, elt_type, index_type, dependent);
1167 : :
1168 : : /* Mark it as dependent now, this saves time later. */
1169 : 1566280 : TYPE_DEPENDENT_P_VALID (t) = true;
1170 : 1566280 : TYPE_DEPENDENT_P (t) = true;
1171 : : }
1172 : : }
1173 : : else
1174 : : {
1175 : 28896051 : bool typeless_storage = is_byte_access_type (elt_type);
1176 : 28896051 : t = build_array_type (elt_type, index_type, typeless_storage);
1177 : :
1178 : : /* Mark as non-dependenty now, this will save time later. */
1179 : 28896051 : TYPE_DEPENDENT_P_VALID (t) = true;
1180 : : }
1181 : :
1182 : : /* Now check whether we already have this array variant. */
1183 : 55386196 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1184 : : {
1185 : : tree m = t;
1186 : 50436414 : for (t = m; t; t = TYPE_NEXT_VARIANT (t))
1187 : 47533278 : if (TREE_TYPE (t) == elt_type
1188 : 22028059 : && TYPE_NAME (t) == NULL_TREE
1189 : 22020732 : && TYPE_ATTRIBUTES (t) == NULL_TREE
1190 : 22020732 : && (!TYPE_USER_ALIGN (t)
1191 : 5177 : || (TYPE_USER_ALIGN (elt_type)
1192 : 5174 : && TYPE_ALIGN (t) == TYPE_ALIGN (elt_type)))
1193 : 22020729 : && !TREE_DEPRECATED (t)
1194 : 69554007 : && !TREE_UNAVAILABLE (t))
1195 : : break;
1196 : 24923865 : if (!t)
1197 : : {
1198 : 2903136 : t = build_min_array_type (elt_type, index_type);
1199 : : /* Mark dependency now, this saves time later. */
1200 : 2903136 : TYPE_DEPENDENT_P_VALID (t) = true;
1201 : 2903136 : TYPE_DEPENDENT_P (t) = dependent;
1202 : 2903136 : set_array_type_canon (t, elt_type, index_type, dependent);
1203 : 2903136 : if (!dependent)
1204 : : {
1205 : 2405518 : 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 : 2405518 : TYPE_SIZE (t) = TYPE_SIZE (m);
1210 : 2405518 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
1211 : 2405518 : TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
1212 : : }
1213 : :
1214 : 2903136 : TYPE_MAIN_VARIANT (t) = m;
1215 : 2903136 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
1216 : 2903136 : TYPE_NEXT_VARIANT (m) = t;
1217 : : }
1218 : : }
1219 : :
1220 : : /* Avoid spurious warnings with VLAs (c++/54583). */
1221 : 55386196 : if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
1222 : 1982 : 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 : 110772392 : bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t)
1227 : 55386196 : = TYPE_NEEDS_CONSTRUCTING (elt_type));
1228 : 110772392 : bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1229 : 55386196 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
1230 : :
1231 : 53174945 : if (!dependent && t == TYPE_MAIN_VARIANT (t)
1232 : 84282247 : && !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 : 1610419 : layout_type (t);
1238 : 2675084 : for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
1239 : : {
1240 : 1064665 : TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
1241 : 1064665 : 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 : 2178523 : build_array_of_n_type (tree elt, unsigned HOST_WIDE_INT n)
1252 : : {
1253 : 2178523 : 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 : 6157452 : array_of_unknown_bound_p (const_tree t)
1260 : : {
1261 : 6157452 : return (TREE_CODE (t) == ARRAY_TYPE
1262 : 6157452 : && !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 : 335823 : array_of_runtime_bound_p (tree t)
1272 : : {
1273 : 335823 : 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 : 33085329 : vla_type_p (tree t)
1289 : : {
1290 : 33779942 : for (; t && TREE_CODE (t) == ARRAY_TYPE;
1291 : 694613 : t = TREE_TYPE (t))
1292 : 694790 : if (tree dom = TYPE_DOMAIN (t))
1293 : : {
1294 : 694726 : tree max = TYPE_MAX_VALUE (dom);
1295 : 694726 : if (!potential_rvalue_constant_expression (max)
1296 : 694726 : || (!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 : 501744882 : cp_build_reference_type_for_mode (tree to_type, machine_mode mode, bool rval)
1310 : : {
1311 : 501744882 : tree lvalue_ref, t;
1312 : :
1313 : 501744882 : if (to_type == error_mark_node)
1314 : : return error_mark_node;
1315 : :
1316 : 501744877 : if (TYPE_REF_P (to_type))
1317 : : {
1318 : 1375 : rval = rval && TYPE_REF_IS_RVALUE (to_type);
1319 : 1375 : to_type = TREE_TYPE (to_type);
1320 : : }
1321 : :
1322 : 501744877 : lvalue_ref = build_reference_type_for_mode (to_type, mode, false);
1323 : :
1324 : 501744877 : 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 : 87453839 : for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
1336 : 63896077 : if (TYPE_REF_IS_RVALUE (t))
1337 : : return t;
1338 : :
1339 : 23557762 : t = build_distinct_type_copy (lvalue_ref);
1340 : :
1341 : 23557762 : TYPE_REF_IS_RVALUE (t) = true;
1342 : 23557762 : TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
1343 : 23557762 : TYPE_NEXT_REF_TO (lvalue_ref) = t;
1344 : :
1345 : 23557762 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
1346 : 765954 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1347 : 22791808 : else if (TYPE_CANONICAL (to_type) != to_type)
1348 : 13313540 : TYPE_CANONICAL (t)
1349 : 26627080 : = cp_build_reference_type_for_mode (TYPE_CANONICAL (to_type), mode, rval);
1350 : : else
1351 : 9478268 : TYPE_CANONICAL (t) = t;
1352 : :
1353 : 23557762 : layout_type (t);
1354 : :
1355 : 23557762 : 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 : 428786694 : cp_build_reference_type (tree to_type, bool rval)
1365 : : {
1366 : 428786694 : 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 : 1674085 : move (tree expr)
1373 : : {
1374 : 1674085 : tree type = TREE_TYPE (expr);
1375 : 1674085 : gcc_assert (!TYPE_REF_P (type));
1376 : 1674085 : if (xvalue_p (expr))
1377 : : return expr;
1378 : 1673879 : type = cp_build_reference_type (type, /*rval*/true);
1379 : 1673879 : return build_static_cast (input_location, type, expr,
1380 : 1673879 : 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 : 23780995 : c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */,
1388 : : size_t /* orig_qual_indirect */)
1389 : : {
1390 : 23780995 : 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 : 14767499016 : cp_build_qualified_type (tree type, int type_quals,
1416 : : tsubst_flags_t complain /* = tf_warning_or_error */)
1417 : : {
1418 : 14767499016 : tree result;
1419 : 14767499016 : int bad_quals = TYPE_UNQUALIFIED;
1420 : :
1421 : 14767499016 : if (type == error_mark_node)
1422 : : return type;
1423 : :
1424 : 14735417446 : if (type_quals == cp_type_quals (type))
1425 : : return type;
1426 : :
1427 : 2545415128 : 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 : 27562320 : tree t;
1432 : 27562320 : tree element_type
1433 : 27562320 : = cp_build_qualified_type (TREE_TYPE (type), type_quals, complain);
1434 : :
1435 : 27562320 : 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 : 52275015 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1441 : 29188217 : if (TREE_TYPE (t) == element_type
1442 : 4528782 : && TYPE_NAME (t) == TYPE_NAME (type)
1443 : 4475522 : && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
1444 : 33663739 : && attribute_list_equal (TYPE_ATTRIBUTES (t),
1445 : 4475522 : TYPE_ATTRIBUTES (type)))
1446 : : break;
1447 : :
1448 : 27562320 : 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 : 23086798 : t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
1454 : 23086798 : TYPE_DEPENDENT_P_VALID (type)
1455 : 406440 : ? int (TYPE_DEPENDENT_P (type)) : -1);
1456 : :
1457 : : /* Keep the typedef name. */
1458 : 23086798 : if (TYPE_NAME (t) != TYPE_NAME (type))
1459 : : {
1460 : 10161 : t = build_variant_type_copy (t);
1461 : 10161 : TYPE_NAME (t) = TYPE_NAME (type);
1462 : 10161 : SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
1463 : 10161 : 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 : 55124640 : TYPE_NEEDS_CONSTRUCTING (t)
1475 : 27562320 : = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
1476 : 55124640 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1477 : 27562320 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
1478 : 27562320 : return t;
1479 : : }
1480 : 2517852808 : 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 : 2517852805 : if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
1498 : 880396977 : && (TYPE_REF_P (type)
1499 : 880126206 : || FUNC_OR_METHOD_TYPE_P (type)))
1500 : : {
1501 : 271535 : if (TYPE_REF_P (type)
1502 : 271535 : && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
1503 : : bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1504 : 271535 : type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1505 : : }
1506 : :
1507 : : /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1508 : 2517852805 : 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 : 2517852805 : if ((type_quals & TYPE_QUAL_RESTRICT)
1514 : 8663595 : && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1515 : 8663558 : && TREE_CODE (type) != TYPENAME_TYPE
1516 : 8663552 : && !INDIRECT_TYPE_P (type))
1517 : : {
1518 : 25 : bad_quals |= TYPE_QUAL_RESTRICT;
1519 : 25 : type_quals &= ~TYPE_QUAL_RESTRICT;
1520 : : }
1521 : :
1522 : 2517852805 : if (bad_quals == TYPE_UNQUALIFIED
1523 : 204463 : || (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 : 2517852805 : result = build_qualified_type (type, type_quals);
1536 : :
1537 : 2517852805 : 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 : 244247461 : cp_build_function_type (tree value_type, tree arg_types)
1547 : : {
1548 : 244247461 : return build_function_type (value_type, arg_types,
1549 : 244247461 : cxx_dialect >= cxx26
1550 : 244247461 : && arg_types == NULL_TREE);
1551 : : }
1552 : :
1553 : : /* Return TYPE with const and volatile removed. */
1554 : :
1555 : : tree
1556 : 1349513917 : cv_unqualified (tree type)
1557 : : {
1558 : 1349513917 : int quals;
1559 : :
1560 : 1349513917 : if (type == error_mark_node)
1561 : : return type;
1562 : :
1563 : 1349513724 : quals = cp_type_quals (type);
1564 : 1349513724 : quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
1565 : 1349513724 : 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 : 4391224 : apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
1574 : : {
1575 : 4391224 : tree first_ident = NULL_TREE;
1576 : 4391224 : tree new_attribs = NULL_TREE;
1577 : 4391224 : tree *p = &new_attribs;
1578 : :
1579 : 4391224 : if (OVERLOAD_TYPE_P (result))
1580 : : {
1581 : : /* On classes and enums all attributes are ingrained. */
1582 : 4390447 : gcc_assert (attribs == TYPE_ATTRIBUTES (result));
1583 : : return result;
1584 : : }
1585 : :
1586 : 1557 : for (tree a = attribs; a; a = TREE_CHAIN (a))
1587 : : {
1588 : 780 : const attribute_spec *as
1589 : 780 : = lookup_attribute_spec (get_attribute_name (a));
1590 : 780 : if (as && as->affects_type_identity)
1591 : : {
1592 : 180 : 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 : 777 : if (first_ident != error_mark_node)
1611 : 777 : new_attribs = first_ident;
1612 : :
1613 : 777 : if (first_ident == attribs)
1614 : : /* All attributes affected type identity. */;
1615 : : else
1616 : 597 : *remove_attributes = true;
1617 : :
1618 : 777 : 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 : 2382477926 : strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
1651 : : unsigned int flags /* = 0 */)
1652 : : {
1653 : 2382477926 : tree result = NULL, type = NULL, t0 = NULL;
1654 : :
1655 : 2382477926 : if (!t || t == error_mark_node)
1656 : : return t;
1657 : :
1658 : 2353192605 : if (!TYPE_P (t))
1659 : 154921767 : return strip_typedefs_expr (t, remove_attributes, flags);
1660 : :
1661 : 2198270838 : if (t == TYPE_CANONICAL (t))
1662 : : return t;
1663 : :
1664 : 806642588 : if (typedef_variant_p (t))
1665 : : {
1666 : 250572194 : if ((flags & STF_USER_VISIBLE)
1667 : 250572194 : && !user_facing_original_type_p (t))
1668 : : return t;
1669 : :
1670 : 250572078 : if ((flags & STF_KEEP_INJ_CLASS_NAME)
1671 : 39967 : && CLASS_TYPE_P (t)
1672 : 250582213 : && DECL_SELF_REFERENCE_P (TYPE_NAME (t)))
1673 : : return t;
1674 : :
1675 : 250572077 : if (dependent_opaque_alias_p (t))
1676 : : return t;
1677 : :
1678 : 250571976 : if (alias_template_specialization_p (t, nt_opaque))
1679 : : {
1680 : 66336792 : if (dependent_alias_template_spec_p (t, nt_opaque)
1681 : 66336792 : && !(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 : 184235184 : flags |= STF_STRIP_DEPENDENT;
1691 : :
1692 : 242518856 : result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
1693 : : remove_attributes, flags);
1694 : 242518856 : goto stripped;
1695 : : }
1696 : :
1697 : 556070394 : switch (TREE_CODE (t))
1698 : : {
1699 : 10030569 : case POINTER_TYPE:
1700 : 10030569 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1701 : 10030569 : result = build_pointer_type_for_mode (type, TYPE_MODE (t), false);
1702 : 10030569 : break;
1703 : 59644648 : case REFERENCE_TYPE:
1704 : 59644648 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1705 : 59644648 : result = cp_build_reference_type_for_mode (type, TYPE_MODE (t), TYPE_REF_IS_RVALUE (t));
1706 : 59644648 : break;
1707 : 326934 : case OFFSET_TYPE:
1708 : 326934 : t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags);
1709 : 326934 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1710 : 326934 : result = build_offset_type (t0, type);
1711 : 326934 : break;
1712 : 23075165 : case RECORD_TYPE:
1713 : 23075165 : if (TYPE_PTRMEMFUNC_P (t))
1714 : : {
1715 : 1646331 : t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t),
1716 : : remove_attributes, flags);
1717 : 1646331 : result = build_ptrmemfunc_type (t0);
1718 : : }
1719 : : break;
1720 : 1501085 : case ARRAY_TYPE:
1721 : 1501085 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1722 : 1501085 : t0 = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags);
1723 : 1501085 : gcc_checking_assert (TYPE_DEPENDENT_P_VALID (t)
1724 : : || !dependent_type_p (t));
1725 : 1501085 : result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t));
1726 : 1501085 : break;
1727 : 5232865 : case FUNCTION_TYPE:
1728 : 5232865 : case METHOD_TYPE:
1729 : 5232865 : {
1730 : 5232865 : tree arg_types = NULL, arg_node, arg_node2, arg_type;
1731 : 5232865 : 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 : 5232865 : bool is_variant = typedef_variant_p (t);
1739 : 5232865 : if (remove_attributes
1740 : 5232865 : && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t)))
1741 : : is_variant = true;
1742 : :
1743 : 5232865 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1744 : 5232865 : tree canon_spec = (flag_noexcept_type
1745 : 5222422 : ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t))
1746 : 5232865 : : NULL_TREE);
1747 : 8132489 : changed = (type != TREE_TYPE (t) || is_variant
1748 : 8132284 : || TYPE_RAISES_EXCEPTIONS (t) != canon_spec);
1749 : :
1750 : 5232865 : for (arg_node = TYPE_ARG_TYPES (t);
1751 : 10154691 : arg_node;
1752 : 4921826 : arg_node = TREE_CHAIN (arg_node))
1753 : : {
1754 : 9319429 : if (arg_node == void_list_node)
1755 : : break;
1756 : 4921826 : arg_type = strip_typedefs (TREE_VALUE (arg_node),
1757 : : remove_attributes, flags);
1758 : 4921826 : gcc_assert (arg_type);
1759 : 4921826 : if (arg_type == TREE_VALUE (arg_node) && !changed)
1760 : 4649876 : continue;
1761 : :
1762 : 271950 : if (!changed)
1763 : : {
1764 : 41803 : changed = true;
1765 : 41803 : for (arg_node2 = TYPE_ARG_TYPES (t);
1766 : 53491 : arg_node2 != arg_node;
1767 : 11688 : arg_node2 = TREE_CHAIN (arg_node2))
1768 : 11688 : arg_types
1769 : 11688 : = tree_cons (TREE_PURPOSE (arg_node2),
1770 : 11688 : TREE_VALUE (arg_node2), arg_types);
1771 : : }
1772 : :
1773 : 271950 : arg_types
1774 : 271950 : = tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
1775 : : }
1776 : :
1777 : 5232865 : if (!changed)
1778 : : return t;
1779 : :
1780 : 2376123 : if (arg_types)
1781 : 63515 : arg_types = nreverse (arg_types);
1782 : :
1783 : : /* A list of parameters not ending with an ellipsis
1784 : : must end with void_list_node. */
1785 : 2376123 : if (arg_node)
1786 : 2376079 : arg_types = chainon (arg_types, void_list_node);
1787 : :
1788 : 2376123 : if (TREE_CODE (t) == METHOD_TYPE)
1789 : : {
1790 : 29761 : tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
1791 : 29761 : gcc_assert (class_type);
1792 : 29761 : result =
1793 : 29761 : build_method_type_directly (class_type, type,
1794 : 29761 : TREE_CHAIN (arg_types));
1795 : : }
1796 : : else
1797 : : {
1798 : 7039086 : result = build_function_type (type, arg_types,
1799 : 2346362 : TYPE_NO_NAMED_ARGS_STDARG_P (t));
1800 : 2346362 : result = apply_memfn_quals (result, type_memfn_quals (t));
1801 : : }
1802 : :
1803 : 7128369 : result = build_cp_fntype_variant (result,
1804 : : type_memfn_rqual (t), canon_spec,
1805 : 2376123 : TYPE_HAS_LATE_RETURN_TYPE (t));
1806 : : }
1807 : 2376123 : break;
1808 : 50786144 : case TYPENAME_TYPE:
1809 : 50786144 : {
1810 : 50786144 : bool changed = false;
1811 : 50786144 : tree fullname = TYPENAME_TYPE_FULLNAME (t);
1812 : 50786144 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
1813 : 50786144 : && TREE_OPERAND (fullname, 1))
1814 : : {
1815 : 2861012 : tree args = TREE_OPERAND (fullname, 1);
1816 : 2861012 : tree new_args = copy_node (args);
1817 : 7545767 : for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
1818 : : {
1819 : 4684755 : tree arg = TREE_VEC_ELT (args, i);
1820 : 4684755 : tree strip_arg = strip_typedefs (arg, remove_attributes, flags);
1821 : 4684755 : TREE_VEC_ELT (new_args, i) = strip_arg;
1822 : 4684755 : if (strip_arg != arg)
1823 : 186561 : changed = true;
1824 : : }
1825 : 2861012 : if (changed)
1826 : : {
1827 : 186561 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
1828 : 186561 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
1829 : 186561 : fullname
1830 : 186561 : = lookup_template_function (TREE_OPERAND (fullname, 0),
1831 : : new_args);
1832 : : }
1833 : : else
1834 : 2674451 : ggc_free (new_args);
1835 : : }
1836 : 50786144 : tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes, flags);
1837 : 50786144 : if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t))
1838 : : return t;
1839 : 4318064 : tree name = fullname;
1840 : 4318064 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
1841 : 204253 : 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 : 4318064 : result = build_typename_type (ctx, name, fullname, typename_type);
1845 : : }
1846 : 4318064 : break;
1847 : 6256525 : case DECLTYPE_TYPE:
1848 : 6256525 : result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t),
1849 : : remove_attributes, flags);
1850 : 6256525 : if (result == DECLTYPE_TYPE_EXPR (t))
1851 : : result = NULL_TREE;
1852 : : else
1853 : 246407 : result = (finish_decltype_type
1854 : 246407 : (result,
1855 : 246407 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
1856 : : tf_none));
1857 : : break;
1858 : 804787 : case TRAIT_TYPE:
1859 : 804787 : {
1860 : 804787 : tree type1 = strip_typedefs (TRAIT_TYPE_TYPE1 (t),
1861 : : remove_attributes, flags);
1862 : 804787 : tree type2 = strip_typedefs (TRAIT_TYPE_TYPE2 (t),
1863 : : remove_attributes, flags);
1864 : 804787 : 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 : 23427233 : case TYPE_PACK_EXPANSION:
1872 : 23427233 : {
1873 : 23427233 : tree pat = PACK_EXPANSION_PATTERN (t);
1874 : 23427233 : if (TYPE_P (pat))
1875 : : {
1876 : 23427233 : type = strip_typedefs (pat, remove_attributes, flags);
1877 : 23427233 : if (type != pat)
1878 : : {
1879 : 193796 : result = build_distinct_type_copy (t);
1880 : 193796 : PACK_EXPANSION_PATTERN (result) = type;
1881 : : }
1882 : : }
1883 : : }
1884 : : break;
1885 : : default:
1886 : : break;
1887 : : }
1888 : :
1889 : 80283957 : if (!result)
1890 : 426461615 : result = TYPE_MAIN_VARIANT (t);
1891 : :
1892 : 80283957 : 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 : 749264428 : 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 : 749264422 : if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
1905 : 749264422 : || 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 : 749264422 : if (TYPE_ATTRIBUTES (t))
1921 : : {
1922 : 4401696 : if (remove_attributes)
1923 : 4391224 : result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t),
1924 : : remove_attributes);
1925 : : else
1926 : 10472 : result = cp_build_type_attribute_variant (result,
1927 : 10472 : TYPE_ATTRIBUTES (t));
1928 : : }
1929 : : }
1930 : :
1931 : 749264428 : 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 : 304431105 : strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags)
1947 : : {
1948 : 304431105 : unsigned i,n;
1949 : 304431105 : tree r, type, *ops;
1950 : 304431105 : enum tree_code code;
1951 : :
1952 : 304431105 : if (t == NULL_TREE || t == error_mark_node)
1953 : : return t;
1954 : :
1955 : 304431105 : STRIP_ANY_LOCATION_WRAPPER (t);
1956 : :
1957 : 304431105 : if (DECL_P (t) || CONSTANT_CLASS_P (t))
1958 : : return t;
1959 : :
1960 : 177081547 : code = TREE_CODE (t);
1961 : 177081547 : 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 : 2251532 : case TRAIT_EXPR:
1971 : 2251532 : {
1972 : 2251532 : tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t),
1973 : : remove_attributes, flags);
1974 : 2251532 : tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t),
1975 : : remove_attributes, flags);
1976 : 2251532 : if (type1 == TRAIT_EXPR_TYPE1 (t)
1977 : 2251532 : && type2 == TRAIT_EXPR_TYPE2 (t))
1978 : : return t;
1979 : 51689 : r = copy_node (t);
1980 : 51689 : TRAIT_EXPR_TYPE1 (r) = type1;
1981 : 51689 : TRAIT_EXPR_TYPE2 (r) = type2;
1982 : 51689 : return r;
1983 : : }
1984 : :
1985 : 1041829 : case TREE_LIST:
1986 : 1041829 : {
1987 : 1041829 : bool changed = false;
1988 : 1041829 : auto_vec<tree_pair, 4> vec;
1989 : 1041829 : r = t;
1990 : 2192670 : for (; t; t = TREE_CHAIN (t))
1991 : : {
1992 : 1150841 : tree purpose = strip_typedefs (TREE_PURPOSE (t),
1993 : 1150841 : remove_attributes, flags);
1994 : 1150841 : tree value = strip_typedefs (TREE_VALUE (t),
1995 : 1150841 : remove_attributes, flags);
1996 : 1150841 : if (purpose != TREE_PURPOSE (t) || value != TREE_VALUE (t))
1997 : : changed = true;
1998 : 1150841 : vec.safe_push ({purpose, value});
1999 : : }
2000 : 1041829 : if (changed)
2001 : : {
2002 : 204251 : r = NULL_TREE;
2003 : 662892 : for (int i = vec.length () - 1; i >= 0; i--)
2004 : 254390 : r = tree_cons (vec[i].first, vec[i].second, r);
2005 : : }
2006 : 1041829 : return r;
2007 : 1041829 : }
2008 : :
2009 : 14845937 : case TREE_VEC:
2010 : 14845937 : {
2011 : 14845937 : bool changed = false;
2012 : 14845937 : releasing_vec vec;
2013 : 14845937 : n = TREE_VEC_LENGTH (t);
2014 : 14845937 : vec_safe_reserve (vec, n);
2015 : 33819800 : for (i = 0; i < n; ++i)
2016 : : {
2017 : 18973863 : tree op = strip_typedefs (TREE_VEC_ELT (t, i),
2018 : 18973863 : remove_attributes, flags);
2019 : 18973863 : vec->quick_push (op);
2020 : 18973863 : if (op != TREE_VEC_ELT (t, i))
2021 : 129469 : changed = true;
2022 : : }
2023 : 14845937 : if (changed)
2024 : : {
2025 : 129469 : r = copy_node (t);
2026 : 408672 : for (i = 0; i < n; ++i)
2027 : 149734 : TREE_VEC_ELT (r, i) = (*vec)[i];
2028 : 258938 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
2029 : 258938 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
2030 : : }
2031 : : else
2032 : : r = t;
2033 : 14845937 : return r;
2034 : 14845937 : }
2035 : :
2036 : 183094 : case CONSTRUCTOR:
2037 : 183094 : {
2038 : 183094 : bool changed = false;
2039 : 183094 : vec<constructor_elt, va_gc> *vec
2040 : 183094 : = vec_safe_copy (CONSTRUCTOR_ELTS (t));
2041 : 183094 : n = CONSTRUCTOR_NELTS (t);
2042 : 183094 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
2043 : 204871 : for (i = 0; i < n; ++i)
2044 : : {
2045 : 21777 : constructor_elt *e = &(*vec)[i];
2046 : 21777 : tree op = strip_typedefs (e->value, remove_attributes, flags);
2047 : 21777 : if (op != e->value)
2048 : : {
2049 : 6 : changed = true;
2050 : 6 : e->value = op;
2051 : : }
2052 : 21777 : gcc_checking_assert
2053 : : (e->index == strip_typedefs (e->index, remove_attributes,
2054 : : flags));
2055 : : }
2056 : :
2057 : 183094 : if (!changed && type == TREE_TYPE (t))
2058 : : {
2059 : 160580 : vec_free (vec);
2060 : 160580 : return t;
2061 : : }
2062 : : else
2063 : : {
2064 : 22514 : r = copy_node (t);
2065 : 22514 : TREE_TYPE (r) = type;
2066 : 22514 : CONSTRUCTOR_ELTS (r) = vec;
2067 : 22514 : return r;
2068 : : }
2069 : : }
2070 : :
2071 : : case LAMBDA_EXPR:
2072 : : case STMT_EXPR:
2073 : : return t;
2074 : :
2075 : 95176056 : default:
2076 : 95176056 : break;
2077 : : }
2078 : :
2079 : 95176056 : gcc_assert (EXPR_P (t));
2080 : :
2081 : 95176056 : n = cp_tree_operand_length (t);
2082 : 95176056 : ops = XALLOCAVEC (tree, n);
2083 : 95176056 : type = TREE_TYPE (t);
2084 : :
2085 : 95176056 : switch (code)
2086 : : {
2087 : 6870163 : CASE_CONVERT:
2088 : 6870163 : case IMPLICIT_CONV_EXPR:
2089 : 6870163 : case DYNAMIC_CAST_EXPR:
2090 : 6870163 : case STATIC_CAST_EXPR:
2091 : 6870163 : case CONST_CAST_EXPR:
2092 : 6870163 : case REINTERPRET_CAST_EXPR:
2093 : 6870163 : case CAST_EXPR:
2094 : 6870163 : case NEW_EXPR:
2095 : 6870163 : type = strip_typedefs (type, remove_attributes, flags);
2096 : : /* fallthrough */
2097 : :
2098 : 95176056 : default:
2099 : 300058494 : for (i = 0; i < n; ++i)
2100 : 204882438 : ops[i] = strip_typedefs (TREE_OPERAND (t, i),
2101 : : remove_attributes, flags);
2102 : : break;
2103 : : }
2104 : :
2105 : : /* If nothing changed, return t. */
2106 : 294127285 : for (i = 0; i < n; ++i)
2107 : 202540727 : if (ops[i] != TREE_OPERAND (t, i))
2108 : : break;
2109 : 95176056 : if (i == n && type == TREE_TYPE (t))
2110 : : return t;
2111 : :
2112 : 3846973 : r = copy_node (t);
2113 : 3846973 : TREE_TYPE (r) = type;
2114 : 12174874 : for (i = 0; i < n; ++i)
2115 : 8327901 : 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 : 34121519 : copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
2139 : : {
2140 : 34121519 : tree new_binfo;
2141 : :
2142 : 34121519 : if (virt)
2143 : : {
2144 : : /* See if we've already made this virtual base. */
2145 : 300661 : new_binfo = binfo_for_vbase (type, t);
2146 : 300661 : if (new_binfo)
2147 : : return new_binfo;
2148 : : }
2149 : :
2150 : 61420099 : new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
2151 : 34049211 : BINFO_TYPE (new_binfo) = type;
2152 : :
2153 : : /* Chain it into the inheritance graph. */
2154 : 34049211 : TREE_CHAIN (*igo_prev) = new_binfo;
2155 : 34049211 : *igo_prev = new_binfo;
2156 : :
2157 : 61420099 : if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
2158 : : {
2159 : 27370879 : int ix;
2160 : 27370879 : tree base_binfo;
2161 : :
2162 : 27370879 : gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
2163 : :
2164 : 27370879 : BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
2165 : 27370879 : BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
2166 : :
2167 : : /* We do not need to copy the accesses, as they are read only. */
2168 : 27370879 : BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
2169 : :
2170 : : /* Recursively copy base binfos of BINFO. */
2171 : 31138546 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
2172 : : {
2173 : 3767667 : tree new_base_binfo;
2174 : 3767667 : new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
2175 : : t, igo_prev,
2176 : 3767667 : BINFO_VIRTUAL_P (base_binfo));
2177 : :
2178 : 3767667 : if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
2179 : 3538106 : BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
2180 : 3767667 : BINFO_BASE_APPEND (new_binfo, new_base_binfo);
2181 : : }
2182 : : }
2183 : : else
2184 : 6678332 : BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
2185 : :
2186 : 34049211 : if (virt)
2187 : : {
2188 : : /* Push it onto the list after any virtual bases it contains
2189 : : will have been pushed. */
2190 : 228353 : CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo);
2191 : 228353 : BINFO_VIRTUAL_P (new_binfo) = 1;
2192 : 228353 : 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 : 2181323914 : list_hasher::equal (tree t, list_proxy *proxy)
2229 : : {
2230 : 2181323914 : return (TREE_VALUE (t) == proxy->value
2231 : 149601347 : && TREE_PURPOSE (t) == proxy->purpose
2232 : 2329096858 : && 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 : 2000557748 : list_hash_pieces (tree purpose, tree value, tree chain)
2241 : : {
2242 : 2000557748 : hashval_t hashcode = 0;
2243 : :
2244 : 2000557748 : if (chain)
2245 : 2000004251 : hashcode += TREE_HASH (chain);
2246 : :
2247 : 2000557748 : if (value)
2248 : 2000557748 : hashcode += TREE_HASH (value);
2249 : : else
2250 : 0 : hashcode += 1007;
2251 : 2000557748 : if (purpose)
2252 : 152286580 : hashcode += TREE_HASH (purpose);
2253 : : else
2254 : 1848271168 : hashcode += 1009;
2255 : 2000557748 : return hashcode;
2256 : : }
2257 : :
2258 : : /* Hash an already existing TREE_LIST. */
2259 : :
2260 : : hashval_t
2261 : 1728130844 : list_hasher::hash (tree t)
2262 : : {
2263 : 1728130844 : return list_hash_pieces (TREE_PURPOSE (t),
2264 : 1728130844 : TREE_VALUE (t),
2265 : 1728130844 : 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 : 272426904 : hash_tree_cons (tree purpose, tree value, tree chain)
2274 : : {
2275 : 272426904 : int hashcode = 0;
2276 : 272426904 : tree *slot;
2277 : 272426904 : struct list_proxy proxy;
2278 : :
2279 : : /* Hash the list node. */
2280 : 272426904 : 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 : 272426904 : proxy.purpose = purpose;
2284 : 272426904 : proxy.value = value;
2285 : 272426904 : proxy.chain = chain;
2286 : : /* See if it is already in the table. */
2287 : 272426904 : slot = list_hash_table->find_slot_with_hash (&proxy, hashcode, INSERT);
2288 : : /* If not, create a new node. */
2289 : 272426904 : if (!*slot)
2290 : 131041356 : *slot = tree_cons (purpose, value, chain);
2291 : 272426904 : return (tree) *slot;
2292 : : }
2293 : :
2294 : : /* Constructor for hashed lists. */
2295 : :
2296 : : tree
2297 : 2245856 : hash_tree_chain (tree value, tree chain)
2298 : : {
2299 : 2245856 : 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 : 156861303 : build_qualified_name (tree type, tree scope, tree name, bool template_p)
2344 : : {
2345 : 156861303 : tree t;
2346 : 156861303 : if (type == error_mark_node
2347 : 156861303 : || scope == error_mark_node
2348 : 156861300 : || name == error_mark_node)
2349 : : return error_mark_node;
2350 : 156861300 : gcc_assert (TREE_CODE (name) != SCOPE_REF);
2351 : 156861300 : t = build2 (SCOPE_REF, type, scope, name);
2352 : 156861300 : QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
2353 : 156861300 : PTRMEM_OK_P (t) = true;
2354 : 156861300 : if (type)
2355 : 10136359 : 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 : 1118214241 : cp_check_qualified_type (const_tree cand, const_tree base, int type_quals,
2365 : : cp_ref_qualifier rqual, tree raises, bool late)
2366 : : {
2367 : 1118214241 : return (TYPE_QUALS (cand) == type_quals
2368 : 1118129907 : && check_base_type (cand, base)
2369 : 1118084884 : && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand),
2370 : : ce_exact)
2371 : 548731132 : && TYPE_HAS_LATE_RETURN_TYPE (cand) == late
2372 : 1630706699 : && type_memfn_rqual (cand) == rqual);
2373 : : }
2374 : :
2375 : : /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */
2376 : :
2377 : : tree
2378 : 713327 : build_ref_qualified_type (tree type, cp_ref_qualifier rqual)
2379 : : {
2380 : 713327 : tree raises = TYPE_RAISES_EXCEPTIONS (type);
2381 : 713327 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
2382 : 713327 : return build_cp_fntype_variant (type, rqual, raises, late);
2383 : : }
2384 : :
2385 : : tree
2386 : 189686 : 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 : 189686 : gcc_checking_assert (clusters <= (unsigned short)(~0));
2391 : 189686 : size_t length = (offsetof (tree_binding_vec, vec)
2392 : 189686 : + clusters * sizeof (binding_cluster));
2393 : 189686 : tree vec = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2394 : 189686 : TREE_SET_CODE (vec, BINDING_VECTOR);
2395 : 189686 : BINDING_VECTOR_NAME (vec) = name;
2396 : 189686 : BINDING_VECTOR_ALLOC_CLUSTERS (vec) = clusters;
2397 : 189686 : BINDING_VECTOR_NUM_CLUSTERS (vec) = 0;
2398 : :
2399 : 189686 : return vec;
2400 : : }
2401 : :
2402 : : /* Make a raw overload node containing FN. */
2403 : :
2404 : : tree
2405 : 322993803 : ovl_make (tree fn, tree next)
2406 : : {
2407 : 322993803 : tree result = make_node (OVERLOAD);
2408 : :
2409 : 322993803 : if (TREE_CODE (fn) == OVERLOAD)
2410 : 11444254 : OVL_NESTED_P (result) = true;
2411 : :
2412 : 431792846 : TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL
2413 : 431792846 : ? unknown_type_node : TREE_TYPE (fn));
2414 : 322993803 : if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
2415 : 15509315 : OVL_DEDUP_P (result) = true;
2416 : 322993803 : OVL_FUNCTION (result) = fn;
2417 : 322993803 : OVL_CHAIN (result) = next;
2418 : 322993803 : 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 : 643082845 : ovl_insert (tree fn, tree maybe_ovl, int using_or_hidden)
2429 : : {
2430 : 643082845 : tree result = maybe_ovl;
2431 : 643082845 : tree insert_after = NULL_TREE;
2432 : :
2433 : : /* Skip hidden. */
2434 : 881646196 : for (; maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD
2435 : 901464649 : && OVL_HIDDEN_P (maybe_ovl);
2436 : 69488312 : maybe_ovl = OVL_CHAIN (maybe_ovl))
2437 : : {
2438 : 69488312 : gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl));
2439 : 69488312 : insert_after = maybe_ovl;
2440 : : }
2441 : :
2442 : 643082845 : if (maybe_ovl || using_or_hidden || TREE_CODE (fn) == TEMPLATE_DECL)
2443 : : {
2444 : 275349276 : maybe_ovl = ovl_make (fn, maybe_ovl);
2445 : :
2446 : 275349276 : if (using_or_hidden < 0)
2447 : 76643235 : OVL_HIDDEN_P (maybe_ovl) = true;
2448 : 275349276 : if (using_or_hidden > 0)
2449 : : {
2450 : 12863543 : OVL_DEDUP_P (maybe_ovl) = OVL_USING_P (maybe_ovl) = true;
2451 : 12863543 : if (using_or_hidden > 1)
2452 : 13284 : OVL_PURVIEW_P (maybe_ovl) = true;
2453 : 13284 : if (using_or_hidden > 2)
2454 : 12764 : OVL_EXPORT_P (maybe_ovl) = true;
2455 : : }
2456 : : }
2457 : : else
2458 : : maybe_ovl = fn;
2459 : :
2460 : 643082845 : if (insert_after)
2461 : : {
2462 : 9650999 : OVL_CHAIN (insert_after) = maybe_ovl;
2463 : 9650999 : TREE_TYPE (insert_after) = unknown_type_node;
2464 : : }
2465 : : else
2466 : : result = maybe_ovl;
2467 : :
2468 : 643082845 : return result;
2469 : : }
2470 : :
2471 : : /* Skip any hidden names at the beginning of OVL. */
2472 : :
2473 : : tree
2474 : 1675893850 : ovl_skip_hidden (tree ovl)
2475 : : {
2476 : 2708460068 : while (ovl && TREE_CODE (ovl) == OVERLOAD && OVL_HIDDEN_P (ovl))
2477 : 1032566218 : ovl = OVL_CHAIN (ovl);
2478 : :
2479 : 1675893850 : return ovl;
2480 : : }
2481 : :
2482 : : /* NODE is an OVL_HIDDEN_P node that is now revealed. */
2483 : :
2484 : : tree
2485 : 4159117 : 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 : 4159117 : OVL_HIDDEN_P (node) = false;
2491 : 4159117 : if (tree chain = OVL_CHAIN (node))
2492 : 182131 : if (TREE_CODE (chain) == OVERLOAD)
2493 : : {
2494 : 172243 : if (OVL_HIDDEN_P (chain))
2495 : : {
2496 : : /* The node needs moving, and the simplest way is to remove it
2497 : : and reinsert. */
2498 : 78857 : overload = remove_node (overload, node);
2499 : 78857 : overload = ovl_insert (OVL_FUNCTION (node), overload);
2500 : : }
2501 : 93386 : else if (OVL_DEDUP_P (chain))
2502 : 9 : OVL_DEDUP_P (node) = true;
2503 : : }
2504 : 4159117 : 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 : 271877 : ovl_iterator::remove_node (tree overload, tree node)
2514 : : {
2515 : 271877 : tree *slot = &overload;
2516 : 1716407 : while (*slot != node)
2517 : : {
2518 : 1444530 : tree probe = *slot;
2519 : 1444530 : gcc_checking_assert (!OVL_LOOKUP_P (probe));
2520 : :
2521 : 1444530 : 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 : 271877 : if (TREE_CODE (node) != OVERLOAD)
2529 : : /* Cloned inherited ctors don't mark themselves as via_using. */
2530 : 129871 : *slot = NULL_TREE;
2531 : : else
2532 : 142006 : *slot = OVL_CHAIN (node);
2533 : :
2534 : 271877 : return overload;
2535 : : }
2536 : :
2537 : : /* Mark or unmark a lookup set. */
2538 : :
2539 : : void
2540 : 101119284 : lookup_mark (tree ovl, bool val)
2541 : : {
2542 : 1180430691 : for (lkp_iterator iter (ovl); iter; ++iter)
2543 : : {
2544 : 1079311407 : gcc_checking_assert (LOOKUP_SEEN_P (*iter) != val);
2545 : 1079311407 : LOOKUP_SEEN_P (*iter) = val;
2546 : : }
2547 : 101119284 : }
2548 : :
2549 : : /* Add a set of new FNS into a lookup. */
2550 : :
2551 : : tree
2552 : 533868637 : lookup_add (tree fns, tree lookup)
2553 : : {
2554 : 533868637 : if (fns == error_mark_node || lookup == error_mark_node)
2555 : : return error_mark_node;
2556 : :
2557 : 533868625 : if (lookup || TREE_CODE (fns) == TEMPLATE_DECL)
2558 : : {
2559 : 43351829 : lookup = ovl_make (fns, lookup);
2560 : 43351829 : 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 : 530857170 : lookup_maybe_add (tree fns, tree lookup, bool deduping)
2573 : : {
2574 : 530857170 : if (deduping)
2575 : 627375511 : for (tree next, probe = fns; probe; probe = next)
2576 : : {
2577 : 566211323 : tree fn = probe;
2578 : 566211323 : next = NULL_TREE;
2579 : :
2580 : 566211323 : if (TREE_CODE (probe) == OVERLOAD)
2581 : : {
2582 : 548226206 : fn = OVL_FUNCTION (probe);
2583 : 548226206 : next = OVL_CHAIN (probe);
2584 : : }
2585 : :
2586 : 566211323 : if (!LOOKUP_SEEN_P (fn))
2587 : 430674439 : LOOKUP_SEEN_P (fn) = true;
2588 : : else
2589 : : {
2590 : : /* This function was already seen. Insert all the
2591 : : predecessors onto the lookup. */
2592 : 149712052 : for (; fns != probe; fns = OVL_CHAIN (fns))
2593 : : {
2594 : : /* Propagate OVL_USING, but OVL_HIDDEN &
2595 : : OVL_DEDUP_P don't matter. */
2596 : 14175168 : if (OVL_USING_P (fns))
2597 : : {
2598 : 27503 : lookup = ovl_make (OVL_FUNCTION (fns), lookup);
2599 : 27503 : OVL_USING_P (lookup) = true;
2600 : : }
2601 : : else
2602 : 14147665 : lookup = lookup_add (OVL_FUNCTION (fns), lookup);
2603 : : }
2604 : :
2605 : : /* And now skip this function. */
2606 : : fns = next;
2607 : : }
2608 : : }
2609 : :
2610 : 530857170 : if (fns)
2611 : : /* We ended in a set of new functions. Add them all in one go. */
2612 : 518951319 : lookup = lookup_add (fns, lookup);
2613 : :
2614 : 530857170 : 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 : 6040690499 : is_overloaded_fn (tree x)
2626 : : {
2627 : 6040690499 : STRIP_ANY_LOCATION_WRAPPER (x);
2628 : :
2629 : : /* A baselink is also considered an overloaded function. */
2630 : 6040690499 : if (TREE_CODE (x) == OFFSET_REF
2631 : 6040621635 : || TREE_CODE (x) == COMPONENT_REF)
2632 : 270047528 : x = TREE_OPERAND (x, 1);
2633 : 6040690499 : x = MAYBE_BASELINK_FUNCTIONS (x);
2634 : 6040690499 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2635 : 150806277 : x = TREE_OPERAND (x, 0);
2636 : :
2637 : 6924285809 : if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x))
2638 : 6062474647 : || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x)))
2639 : : return 2;
2640 : :
2641 : 6315779655 : 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 : 163015257 : 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 : 163015257 : if (identifier_p (x))
2654 : : return x;
2655 : 162840887 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2656 : 58217926 : x = TREE_OPERAND (x, 0);
2657 : 162840887 : if (OVL_P (x))
2658 : 102880471 : 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 : 161939974 : call_expr_dependent_name (tree x)
2667 : : {
2668 : 161939974 : if (TREE_TYPE (x) != NULL_TREE)
2669 : : /* X isn't dependent, so its callee isn't a dependent name. */
2670 : : return NULL_TREE;
2671 : 159708357 : 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 : 541796734 : really_overloaded_fn (tree x)
2680 : : {
2681 : 541796734 : 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 : 4009857776 : maybe_get_fns (tree from)
2689 : : {
2690 : 4009857776 : STRIP_ANY_LOCATION_WRAPPER (from);
2691 : :
2692 : : /* A baselink is also considered an overloaded function. */
2693 : 4009857776 : if (TREE_CODE (from) == OFFSET_REF
2694 : 4009793918 : || TREE_CODE (from) == COMPONENT_REF)
2695 : 138100712 : from = TREE_OPERAND (from, 1);
2696 : 4009857776 : if (BASELINK_P (from))
2697 : 143549415 : from = BASELINK_FUNCTIONS (from);
2698 : 4009857776 : if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
2699 : 100528459 : from = TREE_OPERAND (from, 0);
2700 : :
2701 : 4009857776 : if (OVL_P (from))
2702 : 962852686 : return from;
2703 : :
2704 : : return NULL;
2705 : : }
2706 : :
2707 : : /* FROM refers to an overload set. Return that set (or die). */
2708 : :
2709 : : tree
2710 : 660037148 : get_fns (tree from)
2711 : : {
2712 : 660037148 : tree res = maybe_get_fns (from);
2713 : :
2714 : 660037148 : gcc_assert (res);
2715 : 660037148 : return res;
2716 : : }
2717 : :
2718 : : /* Return the first function of the overload set FROM refers to. */
2719 : :
2720 : : tree
2721 : 419015566 : get_first_fn (tree from)
2722 : : {
2723 : 419015566 : return OVL_FIRST (get_fns (from));
2724 : : }
2725 : :
2726 : : /* Return the scope where the overloaded functions OVL were found. */
2727 : :
2728 : : tree
2729 : 178088000 : ovl_scope (tree ovl)
2730 : : {
2731 : 178088000 : if (TREE_CODE (ovl) == OFFSET_REF
2732 : 178088000 : || TREE_CODE (ovl) == COMPONENT_REF)
2733 : 0 : ovl = TREE_OPERAND (ovl, 1);
2734 : 178088000 : if (TREE_CODE (ovl) == BASELINK)
2735 : 42276330 : return BINFO_TYPE (BASELINK_BINFO (ovl));
2736 : 135811670 : if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
2737 : 52840824 : ovl = TREE_OPERAND (ovl, 0);
2738 : : /* Skip using-declarations. */
2739 : 135811670 : lkp_iterator iter (ovl);
2740 : 146049401 : do
2741 : 146049401 : ovl = *iter;
2742 : 281861071 : while (iter.using_p () && ++iter);
2743 : :
2744 : 135811670 : return CP_DECL_CONTEXT (ovl);
2745 : : }
2746 : :
2747 : : #define PRINT_RING_SIZE 4
2748 : :
2749 : : static const char *
2750 : 145356 : cxx_printable_name_internal (tree decl, int v, bool translate)
2751 : : {
2752 : 145356 : static unsigned int uid_ring[PRINT_RING_SIZE];
2753 : 145356 : static char *print_ring[PRINT_RING_SIZE];
2754 : 145356 : static bool trans_ring[PRINT_RING_SIZE];
2755 : 145356 : static int ring_counter;
2756 : 145356 : int i;
2757 : :
2758 : : /* Only cache functions. */
2759 : 145356 : if (v < 2
2760 : 67202 : || TREE_CODE (decl) != FUNCTION_DECL
2761 : 209046 : || DECL_LANG_SPECIFIC (decl) == 0)
2762 : 82906 : return lang_decl_name (decl, v, translate);
2763 : :
2764 : : /* See if this print name is lying around. */
2765 : 288503 : for (i = 0; i < PRINT_RING_SIZE; i++)
2766 : 235688 : if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
2767 : : /* yes, so return it. */
2768 : 9635 : return print_ring[i];
2769 : :
2770 : 52815 : if (++ring_counter == PRINT_RING_SIZE)
2771 : 10364 : ring_counter = 0;
2772 : :
2773 : 52815 : if (current_function_decl != NULL_TREE)
2774 : : {
2775 : : /* There may be both translated and untranslated versions of the
2776 : : name cached. */
2777 : 139563 : for (i = 0; i < 2; i++)
2778 : : {
2779 : 93042 : if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
2780 : 73 : ring_counter += 1;
2781 : 93042 : if (ring_counter == PRINT_RING_SIZE)
2782 : 7 : ring_counter = 0;
2783 : : }
2784 : 46521 : gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
2785 : : }
2786 : :
2787 : 52815 : free (print_ring[ring_counter]);
2788 : :
2789 : 52815 : print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate));
2790 : 52815 : uid_ring[ring_counter] = DECL_UID (decl);
2791 : 52815 : trans_ring[ring_counter] = translate;
2792 : 52815 : return print_ring[ring_counter];
2793 : : }
2794 : :
2795 : : const char *
2796 : 145356 : cxx_printable_name (tree decl, int v)
2797 : : {
2798 : 145356 : 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 : 180771576 : canonical_eh_spec (tree raises)
2812 : : {
2813 : 180771576 : if (raises == NULL_TREE)
2814 : : return raises;
2815 : 162927374 : else if (DEFERRED_NOEXCEPT_SPEC_P (raises)
2816 : 135316390 : || UNPARSED_NOEXCEPT_SPEC_P (raises)
2817 : 128682180 : || uses_template_parms (raises)
2818 : 128682180 : || uses_template_parms (TREE_PURPOSE (raises)))
2819 : : /* Keep a dependent or deferred exception specification. */
2820 : 36479873 : return raises;
2821 : 126447501 : else if (nothrow_spec_p (raises))
2822 : : /* throw() -> noexcept. */
2823 : 125993175 : return noexcept_true_spec;
2824 : : else
2825 : : /* For C++17 type matching, anything else -> nothing. */
2826 : : return NULL_TREE;
2827 : : }
2828 : :
2829 : : tree
2830 : 672047847 : build_cp_fntype_variant (tree type, cp_ref_qualifier rqual,
2831 : : tree raises, bool late)
2832 : : {
2833 : 672047847 : cp_cv_quals type_quals = TYPE_QUALS (type);
2834 : :
2835 : 672047847 : if (cp_check_qualified_type (type, type, type_quals, rqual, raises, late))
2836 : : return type;
2837 : :
2838 : 280566786 : tree v = TYPE_MAIN_VARIANT (type);
2839 : 607917993 : for (; v; v = TYPE_NEXT_VARIANT (v))
2840 : 446166394 : if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late))
2841 : : return v;
2842 : :
2843 : : /* Need to build a new variant. */
2844 : 161751599 : v = build_variant_type_copy (type);
2845 : 161751599 : if (!TYPE_DEPENDENT_P (v))
2846 : : /* We no longer know that it's not type-dependent. */
2847 : 160953541 : TYPE_DEPENDENT_P_VALID (v) = false;
2848 : 161751599 : TYPE_RAISES_EXCEPTIONS (v) = raises;
2849 : 161751599 : TYPE_HAS_LATE_RETURN_TYPE (v) = late;
2850 : 161751599 : switch (rqual)
2851 : : {
2852 : 792324 : case REF_QUAL_RVALUE:
2853 : 792324 : FUNCTION_RVALUE_QUALIFIED (v) = 1;
2854 : 792324 : FUNCTION_REF_QUALIFIED (v) = 1;
2855 : 792324 : break;
2856 : 794586 : case REF_QUAL_LVALUE:
2857 : 794586 : FUNCTION_RVALUE_QUALIFIED (v) = 0;
2858 : 794586 : FUNCTION_REF_QUALIFIED (v) = 1;
2859 : 794586 : break;
2860 : 160164689 : default:
2861 : 160164689 : FUNCTION_REF_QUALIFIED (v) = 0;
2862 : 160164689 : break;
2863 : : }
2864 : :
2865 : : /* Canonicalize the exception specification. */
2866 : 161751599 : tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE;
2867 : 153643699 : bool complex_eh_spec_p = (cr && cr != noexcept_true_spec
2868 : 196425785 : && !UNPARSED_NOEXCEPT_SPEC_P (cr));
2869 : :
2870 : 132758035 : 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 : 4892822 : type = build_cp_fntype_variant (type, rqual, /*raises=*/NULL_TREE, late);
2874 : 161751599 : 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 : 41271380 : SET_TYPE_STRUCTURAL_EQUALITY (v);
2879 : 120480219 : else if (TYPE_CANONICAL (type) != type || cr != raises || late)
2880 : : /* Build the underlying canonical type, since it is different
2881 : : from TYPE. */
2882 : 51467779 : TYPE_CANONICAL (v) = build_cp_fntype_variant (TYPE_CANONICAL (type),
2883 : : rqual, cr, false);
2884 : : else
2885 : : /* T is its own canonical type. */
2886 : 69012440 : 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 : 2730332 : fixup_deferred_exception_variants (tree type, tree raises)
2898 : : {
2899 : 2730332 : tree original = TYPE_RAISES_EXCEPTIONS (type);
2900 : :
2901 : 5460664 : gcc_checking_assert (UNPARSED_NOEXCEPT_SPEC_P (original));
2902 : :
2903 : 2730332 : for (tree variant = TYPE_MAIN_VARIANT (type);
2904 : 9125797 : variant; variant = TYPE_NEXT_VARIANT (variant))
2905 : 6395465 : if (TYPE_RAISES_EXCEPTIONS (variant) == original)
2906 : : {
2907 : 3006738 : gcc_checking_assert (variant != TYPE_MAIN_VARIANT (type));
2908 : :
2909 : 3006738 : SET_TYPE_STRUCTURAL_EQUALITY (variant);
2910 : 3006738 : TYPE_RAISES_EXCEPTIONS (variant) = raises;
2911 : :
2912 : 3006738 : if (!TYPE_DEPENDENT_P (variant))
2913 : : /* We no longer know that it's not type-dependent. */
2914 : 284153 : TYPE_DEPENDENT_P_VALID (variant) = false;
2915 : : }
2916 : 2730332 : }
2917 : :
2918 : : /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
2919 : : listed in RAISES. */
2920 : :
2921 : : tree
2922 : 164323530 : build_exception_variant (tree type, tree raises)
2923 : : {
2924 : 164323530 : cp_ref_qualifier rqual = type_memfn_rqual (type);
2925 : 164323530 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
2926 : 164323530 : 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 : 269092 : bind_template_template_parm (tree t, tree newargs)
2935 : : {
2936 : 269092 : tree decl = TYPE_NAME (t);
2937 : 269092 : tree t2;
2938 : :
2939 : 269092 : t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
2940 : 269092 : decl = build_decl (input_location,
2941 : 269092 : TYPE_DECL, DECL_NAME (decl), NULL_TREE);
2942 : 269092 : SET_DECL_TEMPLATE_PARM_P (decl);
2943 : :
2944 : : /* These nodes have to be created to reflect new TYPE_DECL and template
2945 : : arguments. */
2946 : 269092 : TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
2947 : 269092 : TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
2948 : 269092 : TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
2949 : 538184 : = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
2950 : :
2951 : 269092 : TREE_TYPE (decl) = t2;
2952 : 269092 : TYPE_NAME (t2) = decl;
2953 : 269092 : TYPE_STUB_DECL (t2) = decl;
2954 : 269092 : TYPE_SIZE (t2) = 0;
2955 : :
2956 : 269092 : if (any_template_arguments_need_structural_equality_p (newargs))
2957 : 13 : SET_TYPE_STRUCTURAL_EQUALITY (t2);
2958 : : else
2959 : 269079 : TYPE_CANONICAL (t2) = canonical_type_parameter (t2);
2960 : :
2961 : 269092 : 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 : 307385024 : no_linkage_check (tree t, bool relaxed_p)
3030 : : {
3031 : 307385024 : 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 : 346311519 : if (LAMBDA_TYPE_P (t)
3040 : 309839240 : && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node)
3041 : : {
3042 : 1410167 : tree extra = LAMBDA_TYPE_EXTRA_SCOPE (t);
3043 : 1410167 : 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 : 307384089 : if (processing_template_decl)
3050 : : return NULL_TREE;
3051 : :
3052 : 185828477 : switch (TREE_CODE (t))
3053 : : {
3054 : 95753104 : case RECORD_TYPE:
3055 : 95753104 : if (TYPE_PTRMEMFUNC_P (t))
3056 : 131119 : goto ptrmem;
3057 : : /* Fall through. */
3058 : 96851118 : case UNION_TYPE:
3059 : 96851118 : if (!CLASS_TYPE_P (t))
3060 : : return NULL_TREE;
3061 : : /* Fall through. */
3062 : 100807949 : 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 : 205363633 : if (TYPE_UNNAMED_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
3066 : : return t;
3067 : :
3068 : 100051963 : 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 : 102395046 : if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
3074 : 83256 : return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
3075 : 102311790 : else if (TREE_CODE (r) == FUNCTION_DECL)
3076 : : {
3077 : 2734887 : if (relaxed_p
3078 : 2734887 : && (vague_linkage_p (r)
3079 : 7321 : || (TREE_PUBLIC (r) && module_maybe_has_cmi_p ())))
3080 : 2343083 : r = CP_DECL_CONTEXT (r);
3081 : : else
3082 : 391804 : return t;
3083 : : }
3084 : : else
3085 : : break;
3086 : : }
3087 : :
3088 : : return NULL_TREE;
3089 : :
3090 : 24322913 : case ARRAY_TYPE:
3091 : 24322913 : case POINTER_TYPE:
3092 : 24322913 : case REFERENCE_TYPE:
3093 : 24322913 : case VECTOR_TYPE:
3094 : 24322913 : return no_linkage_check (TREE_TYPE (t), relaxed_p);
3095 : :
3096 : 134492 : case OFFSET_TYPE:
3097 : 134492 : ptrmem:
3098 : 134492 : r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
3099 : : relaxed_p);
3100 : 134492 : if (r)
3101 : : return r;
3102 : 134492 : return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
3103 : :
3104 : 21471717 : case METHOD_TYPE:
3105 : 21471717 : case FUNCTION_TYPE:
3106 : 21471717 : {
3107 : 21471717 : tree parm = TYPE_ARG_TYPES (t);
3108 : 21471717 : 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 : 11152378 : parm = TREE_CHAIN (parm);
3112 : 27092787 : for (;
3113 : 48564504 : parm && parm != void_list_node;
3114 : 27092787 : parm = TREE_CHAIN (parm))
3115 : : {
3116 : 27468537 : r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
3117 : 27468537 : if (r)
3118 : : return r;
3119 : : }
3120 : 21095967 : 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 : 3212 : array_type_nelts_total (tree type)
3145 : : {
3146 : 3212 : tree sz = array_type_nelts_top (type);
3147 : 3212 : type = TREE_TYPE (type);
3148 : 3472 : 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 : 3212 : 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 : 25094902 : bot_manip (tree* tp, int* walk_subtrees, void* data_)
3168 : : {
3169 : 25094902 : bot_data &data = *(bot_data*)data_;
3170 : 25094902 : splay_tree target_remap = data.target_remap;
3171 : 25094902 : tree t = *tp;
3172 : :
3173 : 25094902 : 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 : 9558447 : *walk_subtrees = 0;
3181 : 9558447 : *tp = unshare_expr (t);
3182 : 9558447 : return NULL_TREE;
3183 : : }
3184 : 15536455 : if (TREE_CODE (t) == TARGET_EXPR)
3185 : : {
3186 : 458050 : tree u;
3187 : :
3188 : 458050 : if (TREE_CODE (TARGET_EXPR_INITIAL (t)) == AGGR_INIT_EXPR)
3189 : : {
3190 : 347490 : u = build_cplus_new (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
3191 : : tf_warning_or_error);
3192 : 347490 : if (u == error_mark_node)
3193 : : return u;
3194 : 347490 : if (AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (t)))
3195 : 2036 : AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (u)) = true;
3196 : : }
3197 : : else
3198 : 110560 : u = force_target_expr (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
3199 : : tf_warning_or_error);
3200 : :
3201 : 458050 : TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
3202 : 458050 : TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
3203 : 458050 : TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
3204 : 458050 : TARGET_EXPR_ELIDING_P (u) = TARGET_EXPR_ELIDING_P (t);
3205 : :
3206 : : /* Map the old variable to the new one. */
3207 : 1374150 : splay_tree_insert (target_remap,
3208 : 458050 : (splay_tree_key) TARGET_EXPR_SLOT (t),
3209 : 458050 : (splay_tree_value) TARGET_EXPR_SLOT (u));
3210 : :
3211 : 458050 : TARGET_EXPR_INITIAL (u) = break_out_target_exprs (TARGET_EXPR_INITIAL (u),
3212 : 458050 : data.clear_location);
3213 : 458050 : if (TARGET_EXPR_INITIAL (u) == error_mark_node)
3214 : : return error_mark_node;
3215 : :
3216 : 458050 : if (data.clear_location)
3217 : 303296 : SET_EXPR_LOCATION (u, input_location);
3218 : :
3219 : : /* Replace the old expression with the new version. */
3220 : 458050 : *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 : 458050 : *walk_subtrees = 0;
3225 : 458050 : return NULL_TREE;
3226 : : }
3227 : 15078405 : if (TREE_CODE (*tp) == SAVE_EXPR)
3228 : : {
3229 : 100099 : t = *tp;
3230 : 100099 : splay_tree_node n = splay_tree_lookup (target_remap,
3231 : : (splay_tree_key) t);
3232 : 100099 : if (n)
3233 : : {
3234 : 50055 : *tp = (tree)n->value;
3235 : 50055 : *walk_subtrees = 0;
3236 : : }
3237 : : else
3238 : : {
3239 : 50044 : copy_tree_r (tp, walk_subtrees, NULL);
3240 : 50044 : splay_tree_insert (target_remap,
3241 : : (splay_tree_key)t,
3242 : 50044 : (splay_tree_value)*tp);
3243 : : /* Make sure we don't remap an already-remapped SAVE_EXPR. */
3244 : 50044 : splay_tree_insert (target_remap,
3245 : : (splay_tree_key)*tp,
3246 : 50044 : (splay_tree_value)*tp);
3247 : : }
3248 : 100099 : return NULL_TREE;
3249 : : }
3250 : 14978306 : if (TREE_CODE (*tp) == DECL_EXPR
3251 : 241 : && VAR_P (DECL_EXPR_DECL (*tp))
3252 : 241 : && DECL_ARTIFICIAL (DECL_EXPR_DECL (*tp))
3253 : 14978547 : && !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 : 14978065 : 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 : 14978064 : t = copy_tree_r (tp, walk_subtrees, NULL);
3295 : 14978064 : if (TREE_CODE (*tp) == CALL_EXPR || TREE_CODE (*tp) == AGGR_INIT_EXPR)
3296 : 2054902 : if (!processing_template_decl)
3297 : 2054902 : set_flags_from_callee (*tp);
3298 : 14978064 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3299 : 336312 : 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 : 37602510 : bot_replace (tree* t, int */*walk_subtrees*/, void* data_)
3309 : : {
3310 : 37602510 : bot_data &data = *(bot_data*)data_;
3311 : 37602510 : splay_tree target_remap = data.target_remap;
3312 : :
3313 : 37602510 : if (VAR_P (*t))
3314 : : {
3315 : 1699806 : splay_tree_node n = splay_tree_lookup (target_remap,
3316 : : (splay_tree_key) *t);
3317 : 1699806 : if (n)
3318 : 2382 : *t = (tree) n->value;
3319 : : }
3320 : 35902704 : else if (TREE_CODE (*t) == PARM_DECL
3321 : 3213510 : && DECL_NAME (*t) == this_identifier
3322 : 37024609 : && !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 : 25964 : *t = current_class_ptr;
3327 : : }
3328 : 35876740 : else if (TREE_CODE (*t) == CONVERT_EXPR
3329 : 35876740 : && 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 : 37602510 : 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 : 8754967 : break_out_target_exprs (tree t, bool clear_location /* = false */)
3352 : : {
3353 : 8754967 : static int target_remap_count;
3354 : 8754967 : static splay_tree target_remap;
3355 : :
3356 : : /* We shouldn't be called on templated trees, nor do we want to
3357 : : produce them. */
3358 : 8754967 : gcc_checking_assert (!processing_template_decl);
3359 : :
3360 : 8754967 : if (!target_remap_count++)
3361 : 8296917 : target_remap = splay_tree_new (splay_tree_compare_pointers,
3362 : : /*splay_tree_delete_key_fn=*/NULL,
3363 : : /*splay_tree_delete_value_fn=*/NULL);
3364 : 8754967 : bot_data data = { target_remap, clear_location };
3365 : 8754967 : if (cp_walk_tree (&t, bot_manip, &data, NULL) == error_mark_node)
3366 : 0 : t = error_mark_node;
3367 : 8754967 : if (cp_walk_tree (&t, bot_replace, &data, NULL) == error_mark_node)
3368 : 0 : t = error_mark_node;
3369 : :
3370 : 8754967 : if (!--target_remap_count)
3371 : : {
3372 : 8296917 : splay_tree_delete (target_remap);
3373 : 8296917 : target_remap = NULL;
3374 : : }
3375 : :
3376 : 8754967 : 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 : 536853 : build_ctor_subob_ref (tree index, tree type, tree obj)
3384 : : {
3385 : 536853 : if (index == NULL_TREE)
3386 : : /* Can't refer to a particular member of a vector. */
3387 : : obj = NULL_TREE;
3388 : 536853 : else if (TREE_CODE (index) == INTEGER_CST)
3389 : 7015 : obj = cp_build_array_ref (input_location, obj, index, tf_none);
3390 : : else
3391 : 529838 : obj = build_class_member_access_expr (obj, index, NULL_TREE,
3392 : : /*reference*/false, tf_none);
3393 : 536853 : if (obj)
3394 : : {
3395 : 536853 : tree objtype = TREE_TYPE (obj);
3396 : 536853 : 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 : 536770 : gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, objtype));
3407 : : }
3408 : :
3409 : 536853 : 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 : 20818926 : replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
3425 : : {
3426 : 20818926 : replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);
3427 : 20818926 : tree obj = d->obj;
3428 : :
3429 : 20818926 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3430 : : {
3431 : 6843850 : *walk_subtrees = false;
3432 : 6843850 : return NULL_TREE;
3433 : : }
3434 : :
3435 : 13975076 : switch (TREE_CODE (*t))
3436 : : {
3437 : : case PLACEHOLDER_EXPR:
3438 : : {
3439 : : tree x = obj;
3440 : 635 : for (; !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (*t),
3441 : 635 : TREE_TYPE (x));
3442 : 77 : x = TREE_OPERAND (x, 0))
3443 : 77 : gcc_assert (handled_component_p (x));
3444 : 558 : *t = unshare_expr (x);
3445 : 558 : *walk_subtrees = false;
3446 : 558 : d->seen = true;
3447 : : }
3448 : 558 : break;
3449 : :
3450 : 315657 : case CONSTRUCTOR:
3451 : 315657 : {
3452 : 315657 : constructor_elt *ce;
3453 : 315657 : 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 : 315657 : if ((CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t)
3458 : 621 : && *t != d->exp)
3459 : 316173 : || d->pset->add (*t))
3460 : : {
3461 : 105 : *walk_subtrees = false;
3462 : 105 : return NULL_TREE;
3463 : : }
3464 : 1044384 : for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i)
3465 : : {
3466 : 728832 : tree *valp = &ce->value;
3467 : 728832 : tree type = TREE_TYPE (*valp);
3468 : 728832 : tree subob = obj;
3469 : :
3470 : : /* Elements with RANGE_EXPR index shouldn't have any
3471 : : placeholders in them. */
3472 : 728832 : if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
3473 : 2 : continue;
3474 : :
3475 : 728830 : 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 : 728830 : d->obj = subob;
3488 : 728830 : cp_walk_tree (valp, replace_placeholders_r, data_, NULL);
3489 : 728830 : d->obj = obj;
3490 : : }
3491 : 315552 : *walk_subtrees = false;
3492 : 315552 : break;
3493 : : }
3494 : :
3495 : 13658861 : default:
3496 : 13658861 : if (d->pset->add (*t))
3497 : 456501 : *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 : 53378539 : replace_placeholders (tree exp, tree obj, bool *seen_p /*= NULL*/)
3509 : : {
3510 : : /* This is only relevant for C++14. */
3511 : 53378539 : if (cxx_dialect < cxx14)
3512 : 864495 : return exp;
3513 : :
3514 : : /* If the object isn't a (member of a) class, do nothing. */
3515 : : tree op0 = obj;
3516 : 53179443 : while (handled_component_p (op0))
3517 : 665399 : op0 = TREE_OPERAND (op0, 0);
3518 : 52514044 : if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0))))
3519 : 48033558 : return exp;
3520 : :
3521 : 4480486 : tree *tp = &exp;
3522 : 4480486 : if (TREE_CODE (exp) == TARGET_EXPR)
3523 : 368828 : tp = &TARGET_EXPR_INITIAL (exp);
3524 : 4480486 : hash_set<tree> pset;
3525 : 4480486 : replace_placeholders_t data = { obj, *tp, false, &pset };
3526 : 4480486 : cp_walk_tree (tp, replace_placeholders_r, &data, NULL);
3527 : 4480486 : if (seen_p)
3528 : 136975 : *seen_p = data.seen;
3529 : 4480486 : return exp;
3530 : 4480486 : }
3531 : :
3532 : : /* Callback function for find_placeholders. */
3533 : :
3534 : : static tree
3535 : 107674 : find_placeholders_r (tree *t, int *walk_subtrees, void *)
3536 : : {
3537 : 107674 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3538 : : {
3539 : 98388 : *walk_subtrees = false;
3540 : 98388 : return NULL_TREE;
3541 : : }
3542 : :
3543 : 9286 : 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 : 98438 : find_placeholders (tree exp)
3565 : : {
3566 : : /* This is only relevant for C++14. */
3567 : 98438 : if (cxx_dialect < cxx14)
3568 : : return false;
3569 : :
3570 : 98438 : 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 : 295436859 : build_min_nt_loc (location_t loc, enum tree_code code, ...)
3578 : : {
3579 : 295436859 : tree t;
3580 : 295436859 : int length;
3581 : 295436859 : int i;
3582 : 295436859 : va_list p;
3583 : :
3584 : 295436859 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3585 : :
3586 : 295436859 : va_start (p, code);
3587 : :
3588 : 295436859 : t = make_node (code);
3589 : 295436859 : SET_EXPR_LOCATION (t, loc);
3590 : 295436859 : length = TREE_CODE_LENGTH (code);
3591 : :
3592 : 966835011 : for (i = 0; i < length; i++)
3593 : 671398152 : TREE_OPERAND (t, i) = va_arg (p, tree);
3594 : :
3595 : 295436859 : va_end (p);
3596 : 295436859 : return t;
3597 : : }
3598 : :
3599 : : /* Similar to `build', but for template definitions. */
3600 : :
3601 : : tree
3602 : 223723954 : build_min (enum tree_code code, tree tt, ...)
3603 : : {
3604 : 223723954 : tree t;
3605 : 223723954 : int length;
3606 : 223723954 : int i;
3607 : 223723954 : va_list p;
3608 : :
3609 : 223723954 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3610 : :
3611 : 223723954 : va_start (p, tt);
3612 : :
3613 : 223723954 : t = make_node (code);
3614 : 223723954 : length = TREE_CODE_LENGTH (code);
3615 : 223723954 : TREE_TYPE (t) = tt;
3616 : :
3617 : 599616231 : for (i = 0; i < length; i++)
3618 : : {
3619 : 375892277 : tree x = va_arg (p, tree);
3620 : 375892277 : TREE_OPERAND (t, i) = x;
3621 : 375892277 : if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
3622 : 2334495 : TREE_SIDE_EFFECTS (t) = 1;
3623 : : }
3624 : :
3625 : 223723954 : va_end (p);
3626 : :
3627 : 223723954 : 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 : 112493871 : build_min_non_dep (enum tree_code code, tree non_dep, ...)
3636 : : {
3637 : 112493871 : tree t;
3638 : 112493871 : int length;
3639 : 112493871 : int i;
3640 : 112493871 : va_list p;
3641 : :
3642 : 112493871 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3643 : :
3644 : 112493871 : va_start (p, non_dep);
3645 : :
3646 : 112493871 : if (REFERENCE_REF_P (non_dep))
3647 : 505464 : non_dep = TREE_OPERAND (non_dep, 0);
3648 : :
3649 : 112493871 : t = make_node (code);
3650 : 150144602 : SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep));
3651 : 112493871 : length = TREE_CODE_LENGTH (code);
3652 : 112493871 : TREE_TYPE (t) = unlowered_expr_type (non_dep);
3653 : 112493871 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3654 : :
3655 : 396638184 : for (i = 0; i < length; i++)
3656 : : {
3657 : 284144313 : tree x = va_arg (p, tree);
3658 : 284144313 : TREE_OPERAND (t, i) = x;
3659 : 284144313 : if (x && !TYPE_P (x))
3660 : 220576780 : TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
3661 : : }
3662 : :
3663 : 112493871 : va_end (p);
3664 : 112493871 : return convert_from_reference (t);
3665 : : }
3666 : :
3667 : : /* Similar to build_min_nt, but call expressions */
3668 : :
3669 : : tree
3670 : 196053664 : build_min_nt_call_vec (tree fn, vec<tree, va_gc> *args)
3671 : : {
3672 : 196053664 : tree ret, t;
3673 : 196053664 : unsigned int ix;
3674 : :
3675 : 392002697 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
3676 : 196053664 : CALL_EXPR_FN (ret) = fn;
3677 : 196053664 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
3678 : 400728077 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
3679 : 204674413 : CALL_EXPR_ARG (ret, ix) = t;
3680 : :
3681 : 196053664 : 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 : 12408314 : build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec)
3690 : : {
3691 : 12408314 : tree t = build_min_nt_call_vec (fn, argvec);
3692 : 12408314 : if (REFERENCE_REF_P (non_dep))
3693 : 6 : non_dep = TREE_OPERAND (non_dep, 0);
3694 : 12408314 : TREE_TYPE (t) = TREE_TYPE (non_dep);
3695 : 12408314 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3696 : 12408314 : if (argvec)
3697 : 21877356 : for (tree x : *argvec)
3698 : 9573673 : if (x && !TYPE_P (x))
3699 : 9573673 : TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
3700 : 12408314 : 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 : 4254315 : build_min_non_dep_op_overload (enum tree_code op,
3711 : : tree non_dep,
3712 : : tree overload, ...)
3713 : : {
3714 : 4254315 : va_list p;
3715 : 4254315 : int nargs, expected_nargs;
3716 : 4254315 : tree fn, call, obj = NULL_TREE;
3717 : :
3718 : 4254315 : releasing_vec args;
3719 : 4254315 : va_start (p, overload);
3720 : :
3721 : 4254315 : bool negated = false, rewritten = false, reversed = false;
3722 : 4254315 : 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 : 163002 : gcc_checking_assert (TREE_CODE_CLASS (op) == tcc_comparison
3728 : : || op == SPACESHIP_EXPR);
3729 : 163002 : int flags = TREE_INT_CST_LOW (TREE_PURPOSE (overload));
3730 : 163002 : if (TREE_CODE (non_dep) == TRUTH_NOT_EXPR)
3731 : : {
3732 : 149885 : negated = true;
3733 : 149885 : non_dep = TREE_OPERAND (non_dep, 0);
3734 : : }
3735 : 163002 : if (flags & LOOKUP_REWRITTEN)
3736 : 163002 : rewritten = true;
3737 : 163002 : if (flags & LOOKUP_REVERSED)
3738 : 66 : reversed = true;
3739 : 163002 : if (rewritten
3740 : 163002 : && 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 : 13111 : tree spaceship_non_dep = (TREE_CODE (non_dep) == CALL_EXPR
3748 : 26162 : ? CALL_EXPR_ARG (non_dep, reversed ? 1 : 0)
3749 : 13123 : : TREE_OPERAND (non_dep, reversed ? 1 : 0));
3750 : 13111 : gcc_checking_assert (TREE_CODE (spaceship_non_dep) == CALL_EXPR);
3751 : 13111 : tree spaceship_op0 = va_arg (p, tree);
3752 : 13111 : tree spaceship_op1 = va_arg (p, tree);
3753 : 13111 : 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 : 13111 : tree op0 = build_min_non_dep_op_overload (SPACESHIP_EXPR,
3759 : : spaceship_non_dep,
3760 : 13111 : TREE_VALUE (overload),
3761 : : spaceship_op0,
3762 : 13111 : spaceship_op1);
3763 : 13111 : tree op1 = (TREE_CODE (non_dep) == CALL_EXPR
3764 : 26186 : ? CALL_EXPR_ARG (non_dep, reversed ? 0 : 1)
3765 : 36 : : TREE_OPERAND (non_dep, reversed ? 0 : 1));
3766 : 13111 : gcc_checking_assert (integer_zerop (op1));
3767 : :
3768 : 13111 : 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 : 13087 : vec_safe_push (args, op0);
3777 : 13087 : vec_safe_push (args, op1);
3778 : 13087 : overload = CALL_EXPR_FN (non_dep);
3779 : : }
3780 : : else
3781 : 149891 : overload = TREE_VALUE (overload);
3782 : : }
3783 : 4254291 : non_dep = extract_call_expr (non_dep);
3784 : :
3785 : 4254291 : nargs = call_expr_nargs (non_dep);
3786 : :
3787 : 4254291 : expected_nargs = cp_tree_code_length (op);
3788 : 7786879 : 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 : 7785261 : || op == ARRAY_REF)
3795 : 723328 : expected_nargs -= 1;
3796 : 4254291 : if ((op == POSTINCREMENT_EXPR
3797 : 4254291 : || op == POSTDECREMENT_EXPR)
3798 : : /* With -fpermissive non_dep could be operator++(). */
3799 : 10914 : && (!flag_permissive || nargs != expected_nargs))
3800 : 10911 : expected_nargs += 1;
3801 : 4254291 : gcc_assert (nargs == expected_nargs);
3802 : :
3803 : 4254291 : if (!DECL_OBJECT_MEMBER_FUNCTION_P (overload))
3804 : : {
3805 : 3530970 : fn = overload;
3806 : 3530970 : if (vec_safe_length (args) != 0)
3807 : : /* The correct arguments were already pushed above. */
3808 : 13087 : gcc_checking_assert (rewritten);
3809 : : else
3810 : : {
3811 : 3517883 : if (op == ARRAY_REF)
3812 : 7 : obj = va_arg (p, tree);
3813 : 10467496 : for (int i = 0; i < nargs; i++)
3814 : : {
3815 : 6949613 : tree arg = va_arg (p, tree);
3816 : 6949613 : vec_safe_push (args, arg);
3817 : : }
3818 : : }
3819 : 3530970 : if (reversed)
3820 : 36 : std::swap ((*args)[0], (*args)[1]);
3821 : : }
3822 : : else
3823 : : {
3824 : 723321 : gcc_checking_assert (vec_safe_length (args) == 0);
3825 : 723321 : tree object = va_arg (p, tree);
3826 : 1226586 : for (int i = 0; i < nargs; i++)
3827 : : {
3828 : 503265 : tree arg = va_arg (p, tree);
3829 : 503265 : vec_safe_push (args, arg);
3830 : : }
3831 : 723321 : if (reversed)
3832 : 18 : std::swap (object, (*args)[0]);
3833 : 723321 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
3834 : 723321 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
3835 : 723321 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
3836 : : object, method, NULL_TREE);
3837 : : }
3838 : :
3839 : 4254291 : va_end (p);
3840 : 4254291 : call = build_min_non_dep_call_vec (non_dep, fn, args);
3841 : :
3842 : 4254291 : tree call_expr = extract_call_expr (call);
3843 : 4254291 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
3844 : 4254291 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
3845 : 4254291 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
3846 : 4254291 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
3847 : :
3848 : 4254291 : if (negated)
3849 : 149885 : call = build_min (TRUTH_NOT_EXPR, boolean_type_node, call);
3850 : 4254291 : if (obj)
3851 : 7 : return keep_unused_object_arg (call, obj, overload);
3852 : : return call;
3853 : 4254315 : }
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 : 2619 : vec_copy_and_insert (vec<tree, va_gc> *old_vec, tree elt, unsigned idx)
3893 : : {
3894 : 2619 : unsigned len = vec_safe_length (old_vec);
3895 : 2619 : gcc_assert (idx <= len);
3896 : :
3897 : 2619 : vec<tree, va_gc> *new_vec = NULL;
3898 : 2619 : vec_alloc (new_vec, len + 1);
3899 : :
3900 : 2619 : unsigned i;
3901 : 7886 : for (i = 0; i < len; ++i)
3902 : : {
3903 : 2648 : if (i == idx)
3904 : 29 : new_vec->quick_push (elt);
3905 : 2648 : new_vec->quick_push ((*old_vec)[i]);
3906 : : }
3907 : 2619 : if (i == idx)
3908 : 2590 : new_vec->quick_push (elt);
3909 : :
3910 : 2619 : return new_vec;
3911 : : }
3912 : :
3913 : : tree
3914 : 141082 : get_type_decl (tree t)
3915 : : {
3916 : 141082 : if (TREE_CODE (t) == TYPE_DECL)
3917 : : return t;
3918 : 141082 : if (TYPE_P (t))
3919 : 141082 : 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 : 1033356245 : decl_namespace_context (tree decl)
3929 : : {
3930 : 2148516240 : while (1)
3931 : : {
3932 : 2148516240 : if (TREE_CODE (decl) == NAMESPACE_DECL)
3933 : 1033356245 : return decl;
3934 : 1115159995 : else if (TYPE_P (decl))
3935 : 672547214 : decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
3936 : : else
3937 : 442612781 : 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 : 1216790482 : decl_internal_context_p (const_tree decl)
3954 : : {
3955 : 2437446588 : while (TREE_CODE (decl) != NAMESPACE_DECL)
3956 : : {
3957 : : /* Classes inside anonymous namespaces have TREE_PUBLIC == 0. */
3958 : 1524538322 : if (TYPE_P (decl))
3959 : 303882216 : return !TREE_PUBLIC (TYPE_MAIN_DECL (decl));
3960 : :
3961 : 1220656106 : decl = CP_DECL_CONTEXT (decl);
3962 : : }
3963 : 912908266 : 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 : 46533346 : 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 : 46533346 : tree name1 = call_expr_dependent_name (t1);
3975 : 46533346 : tree name2 = call_expr_dependent_name (t2);
3976 : 46533346 : t1 = CALL_EXPR_FN (t1);
3977 : 46533346 : t2 = CALL_EXPR_FN (t2);
3978 : 46533346 : if (name1 || name2)
3979 : : {
3980 : 22495634 : tree targs1 = NULL_TREE, targs2 = NULL_TREE;
3981 : :
3982 : 22495634 : 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 : 21937913 : if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
3990 : 43906247 : && (DECL_CONTEXT (get_first_fn (t1))
3991 : 21937910 : != DECL_CONTEXT (get_first_fn (t2))))
3992 : : return false;
3993 : :
3994 : 21968337 : if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
3995 : 13870570 : targs1 = TREE_OPERAND (t1, 1);
3996 : 21968337 : if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
3997 : 13870570 : targs2 = TREE_OPERAND (t2, 1);
3998 : 21968337 : return cp_tree_equal (targs1, targs2);
3999 : : }
4000 : : else
4001 : 24037712 : 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 : 1767059245 : cp_tree_equal (tree t1, tree t2)
4053 : : {
4054 : 1770396840 : enum tree_code code1, code2;
4055 : :
4056 : 1770396840 : if (t1 == t2)
4057 : : return true;
4058 : 782313046 : if (!t1 || !t2)
4059 : : return false;
4060 : :
4061 : 782056317 : code1 = TREE_CODE (t1);
4062 : 782056317 : code2 = TREE_CODE (t2);
4063 : :
4064 : 782056317 : if (code1 != code2)
4065 : : return false;
4066 : :
4067 : 636769034 : if (CONSTANT_CLASS_P (t1)
4068 : 636769034 : && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4069 : : return false;
4070 : :
4071 : 636690140 : 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 : 36744794 : case INTEGER_CST:
4079 : 36744794 : return tree_int_cst_equal (t1, t2);
4080 : :
4081 : 123276 : case REAL_CST:
4082 : 123276 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
4083 : :
4084 : 53424 : case STRING_CST:
4085 : 53424 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
4086 : 53424 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
4087 : 53424 : 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 : 1663635 : 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 : 1663635 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
4105 : 3666911 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
4106 : : return false;
4107 : : {
4108 : : tree field, value;
4109 : : unsigned int i;
4110 : 1839175 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
4111 : : {
4112 : 251817 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
4113 : 251817 : if (!cp_tree_equal (field, elt2->index)
4114 : 251817 : || !cp_tree_equal (value, elt2->value))
4115 : 14 : return false;
4116 : : }
4117 : : }
4118 : : return true;
4119 : :
4120 : 2899419 : case TREE_LIST:
4121 : 2899419 : if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
4122 : : return false;
4123 : 2899419 : if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
4124 : : return false;
4125 : 45624 : 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 : 46560940 : case CALL_EXPR:
4131 : 46560940 : {
4132 : 46560940 : if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
4133 : : return false;
4134 : :
4135 : 46533346 : if (!called_fns_equal (t1, t2))
4136 : : return false;
4137 : :
4138 : 15907900 : call_expr_arg_iterator iter1, iter2;
4139 : 15907900 : init_call_expr_arg_iterator (t1, &iter1);
4140 : 15907900 : init_call_expr_arg_iterator (t2, &iter2);
4141 : 15907900 : if (iter1.n != iter2.n)
4142 : : return false;
4143 : :
4144 : 16700053 : while (more_call_expr_args_p (&iter1))
4145 : : {
4146 : 8571283 : tree arg1 = next_call_expr_arg (&iter1);
4147 : 8571283 : tree arg2 = next_call_expr_arg (&iter2);
4148 : :
4149 : 8571283 : gcc_checking_assert (arg1 && arg2);
4150 : 8571283 : if (!cp_tree_equal (arg1, arg2))
4151 : : return false;
4152 : : }
4153 : :
4154 : : return true;
4155 : : }
4156 : :
4157 : 222548 : case TARGET_EXPR:
4158 : 222548 : {
4159 : 222548 : tree o1 = TARGET_EXPR_SLOT (t1);
4160 : 222548 : 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 : 222548 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
4167 : 445096 : && !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 : 222548 : return cp_tree_equal (TARGET_EXPR_INITIAL (t1),
4176 : 445096 : 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 : 916405 : 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 : 916405 : if (comparing_specializations
4219 : 916405 : && 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 : 810747 : if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4227 : : {
4228 : 345799 : if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
4229 : : return false;
4230 : 345799 : if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
4231 : : return false;
4232 : 345799 : if (DECL_ARTIFICIAL (t1)
4233 : 345799 : || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
4234 : 345154 : && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
4235 : : return true;
4236 : : }
4237 : : return false;
4238 : :
4239 : 34071018 : case TEMPLATE_DECL:
4240 : 34071018 : if (DECL_TEMPLATE_TEMPLATE_PARM_P (t1)
4241 : 35697162 : && DECL_TEMPLATE_TEMPLATE_PARM_P (t2))
4242 : 143800 : 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 : 14211178 : case BASELINK:
4255 : 14211178 : return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
4256 : 13494035 : && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
4257 : 13494035 : && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
4258 : 27705201 : && cp_tree_equal (BASELINK_FUNCTIONS (t1),
4259 : 13494023 : BASELINK_FUNCTIONS (t2)));
4260 : :
4261 : 13905742 : case TEMPLATE_PARM_INDEX:
4262 : 13905742 : return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
4263 : 13188647 : && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
4264 : 12522615 : && (TEMPLATE_PARM_PARAMETER_PACK (t1)
4265 : 12522615 : == TEMPLATE_PARM_PARAMETER_PACK (t2))
4266 : 26411916 : && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
4267 : : TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
4268 : :
4269 : 27342848 : case TEMPLATE_ID_EXPR:
4270 : 27342848 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4271 : : return false;
4272 : 21344866 : if (!comp_template_args (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)))
4273 : : return false;
4274 : : return true;
4275 : :
4276 : 2923123 : case CONSTRAINT_INFO:
4277 : 8769369 : return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1),
4278 : 8769369 : CI_ASSOCIATED_CONSTRAINTS (t2));
4279 : :
4280 : 31374507 : 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 : 31374507 : if (!comp_template_args (t1, t2))
4284 : : return false;
4285 : : return true;
4286 : :
4287 : 986298 : case SIZEOF_EXPR:
4288 : 986298 : case ALIGNOF_EXPR:
4289 : 986298 : {
4290 : 986298 : tree o1 = TREE_OPERAND (t1, 0);
4291 : 986298 : tree o2 = TREE_OPERAND (t2, 0);
4292 : :
4293 : 986298 : if (code1 == SIZEOF_EXPR)
4294 : : {
4295 : 976463 : if (SIZEOF_EXPR_TYPE_P (t1))
4296 : 0 : o1 = TREE_TYPE (o1);
4297 : 976463 : if (SIZEOF_EXPR_TYPE_P (t2))
4298 : 0 : o2 = TREE_TYPE (o2);
4299 : : }
4300 : 9835 : else if (ALIGNOF_EXPR_STD_P (t1) != ALIGNOF_EXPR_STD_P (t2))
4301 : : return false;
4302 : :
4303 : 986292 : if (TREE_CODE (o1) != TREE_CODE (o2))
4304 : : return false;
4305 : :
4306 : 986280 : if (ARGUMENT_PACK_P (o1))
4307 : 4 : return template_args_equal (o1, o2);
4308 : 986276 : else if (TYPE_P (o1))
4309 : 984605 : return same_type_p (o1, o2);
4310 : : else
4311 : : return cp_tree_equal (o1, o2);
4312 : : }
4313 : :
4314 : 216 : case MODOP_EXPR:
4315 : 216 : {
4316 : 216 : tree t1_op1, t2_op1;
4317 : :
4318 : 216 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4319 : : return false;
4320 : :
4321 : 216 : t1_op1 = TREE_OPERAND (t1, 1);
4322 : 216 : t2_op1 = TREE_OPERAND (t2, 1);
4323 : 216 : if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
4324 : : return false;
4325 : :
4326 : 178 : return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
4327 : : }
4328 : :
4329 : 596 : 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 : 596 : if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
4333 : : return false;
4334 : :
4335 : 680 : return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
4336 : :
4337 : 4130344 : case OVERLOAD:
4338 : 4130344 : {
4339 : : /* Two overloads. Must be exactly the same set of decls. */
4340 : 4130344 : lkp_iterator first (t1);
4341 : 4130344 : lkp_iterator second (t2);
4342 : :
4343 : 4138931 : for (; first && second; ++first, ++second)
4344 : 4130851 : if (*first != *second)
4345 : : return false;
4346 : 8080 : return !(first || second);
4347 : : }
4348 : :
4349 : 10228480 : case TRAIT_EXPR:
4350 : 10228480 : if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
4351 : : return false;
4352 : 827854 : return cp_tree_equal (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
4353 : 1636127 : && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
4354 : :
4355 : 603037 : case NON_LVALUE_EXPR:
4356 : 603037 : case VIEW_CONVERT_EXPR:
4357 : : /* Used for location wrappers with possibly NULL types. */
4358 : 603037 : if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
4359 : : {
4360 : 23 : if (TREE_TYPE (t1) || TREE_TYPE (t2))
4361 : : return false;
4362 : : break;
4363 : : }
4364 : : /* FALLTHROUGH */
4365 : :
4366 : 3216195 : case CAST_EXPR:
4367 : 3216195 : case STATIC_CAST_EXPR:
4368 : 3216195 : case REINTERPRET_CAST_EXPR:
4369 : 3216195 : case CONST_CAST_EXPR:
4370 : 3216195 : case DYNAMIC_CAST_EXPR:
4371 : 3216195 : case IMPLICIT_CONV_EXPR:
4372 : 3216195 : case NEW_EXPR:
4373 : 3216195 : case BIT_CAST_EXPR:
4374 : 3216195 : CASE_CONVERT:
4375 : 3216195 : 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 : 324952596 : case TYPE_ARGUMENT_PACK:
4391 : 324952596 : case NONTYPE_ARGUMENT_PACK:
4392 : 324952596 : {
4393 : 324952596 : tree p1 = ARGUMENT_PACK_ARGS (t1);
4394 : 324952596 : tree p2 = ARGUMENT_PACK_ARGS (t2);
4395 : 324952596 : int len = TREE_VEC_LENGTH (p1);
4396 : 324952596 : if (TREE_VEC_LENGTH (p2) != len)
4397 : : return false;
4398 : :
4399 : 443539967 : for (int ix = 0; ix != len; ix++)
4400 : 367011623 : if (!template_args_equal (TREE_VEC_ELT (p1, ix),
4401 : 367011623 : TREE_VEC_ELT (p2, ix)))
4402 : : return false;
4403 : : return true;
4404 : : }
4405 : :
4406 : 360794 : case EXPR_PACK_EXPANSION:
4407 : 360794 : if (!cp_tree_equal (PACK_EXPANSION_PATTERN (t1),
4408 : 360794 : PACK_EXPANSION_PATTERN (t2)))
4409 : : return false;
4410 : 26126 : if (!comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
4411 : 26126 : PACK_EXPANSION_EXTRA_ARGS (t2)))
4412 : : return false;
4413 : : return true;
4414 : :
4415 : 2169 : case PACK_INDEX_EXPR:
4416 : 2169 : if (!cp_tree_equal (PACK_INDEX_PACK (t1),
4417 : 2169 : PACK_INDEX_PACK (t2)))
4418 : : return false;
4419 : 101 : if (!cp_tree_equal (PACK_INDEX_INDEX (t1),
4420 : 101 : PACK_INDEX_INDEX (t2)))
4421 : : return false;
4422 : : return true;
4423 : :
4424 : 841752 : case COMPONENT_REF:
4425 : : /* If we're comparing contract conditions of overrides, member references
4426 : : compare equal if they designate the same member. */
4427 : 841752 : if (comparing_override_contracts)
4428 : 6 : return equivalent_member_references (t1, t2);
4429 : : break;
4430 : :
4431 : : default:
4432 : : break;
4433 : : }
4434 : :
4435 : 63294189 : switch (TREE_CODE_CLASS (code1))
4436 : : {
4437 : 57112992 : case tcc_unary:
4438 : 57112992 : case tcc_binary:
4439 : 57112992 : case tcc_comparison:
4440 : 57112992 : case tcc_expression:
4441 : 57112992 : case tcc_vl_exp:
4442 : 57112992 : case tcc_reference:
4443 : 57112992 : case tcc_statement:
4444 : 57112992 : {
4445 : 57112992 : int n = cp_tree_operand_length (t1);
4446 : 57112992 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
4447 : 57112992 : && n != TREE_OPERAND_LENGTH (t2))
4448 : : return false;
4449 : :
4450 : 105898048 : for (int i = 0; i < n; ++i)
4451 : 80293589 : if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
4452 : : return false;
4453 : :
4454 : : return true;
4455 : : }
4456 : :
4457 : 6181197 : case tcc_type:
4458 : 6181197 : 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 : 720622302 : lvalue_type (tree arg)
4472 : : {
4473 : 720622302 : tree type = TREE_TYPE (arg);
4474 : 720622302 : return type;
4475 : : }
4476 : :
4477 : : /* The type of ARG for printing error messages; denote lvalues with
4478 : : reference types. */
4479 : :
4480 : : tree
4481 : 3747 : error_type (tree arg)
4482 : : {
4483 : 3747 : tree type = TREE_TYPE (arg);
4484 : :
4485 : 3747 : if (TREE_CODE (type) == ARRAY_TYPE)
4486 : : ;
4487 : 3607 : else if (TREE_CODE (type) == ERROR_MARK)
4488 : : ;
4489 : 3607 : else if (lvalue_p (arg))
4490 : 1245 : type = build_reference_type (lvalue_type (arg));
4491 : 2362 : else if (MAYBE_CLASS_TYPE_P (type))
4492 : 747 : type = lvalue_type (arg);
4493 : :
4494 : 3747 : return type;
4495 : : }
4496 : :
4497 : : /* Does FUNCTION use a variable-length argument list? */
4498 : :
4499 : : int
4500 : 338992 : varargs_function_p (const_tree function)
4501 : : {
4502 : 338992 : return stdarg_p (TREE_TYPE (function));
4503 : : }
4504 : :
4505 : : /* Returns 1 if decl is a member of a class. */
4506 : :
4507 : : int
4508 : 11017 : member_p (const_tree decl)
4509 : : {
4510 : 11017 : const_tree const ctx = DECL_CONTEXT (decl);
4511 : 11017 : 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 : 68860143 : build_dummy_object (tree type)
4520 : : {
4521 : 68860143 : tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node);
4522 : 68860143 : 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 : 101577690 : maybe_dummy_object (tree type, tree* binfop)
4531 : : {
4532 : 101577690 : tree decl, context;
4533 : 101577690 : tree binfo;
4534 : 101577690 : tree current = current_nonlambda_class_type ();
4535 : :
4536 : 101577690 : if (current
4537 : 101577690 : && (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 : 11648042 : context = type;
4544 : 11648042 : binfo = TYPE_BINFO (type);
4545 : : }
4546 : :
4547 : 101577690 : if (binfop)
4548 : 116938 : *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 : 101577690 : tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE;
4554 : 94215033 : if (ctype
4555 : 94215033 : && same_type_ignoring_top_level_qualifiers_p (ctype, context))
4556 : 87024517 : 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 : 14553173 : if (ctype)
4562 : : {
4563 : 7190516 : int quals = TYPE_UNQUALIFIED;
4564 : 7190516 : if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype))
4565 : : {
4566 : 327568 : if (tree cap = lambda_expr_this_capture (lambda, false))
4567 : 319064 : quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap)));
4568 : : }
4569 : : else
4570 : 6862948 : quals = cp_type_quals (ctype);
4571 : 7190516 : context = cp_build_qualified_type (context, quals);
4572 : : }
4573 : 14553173 : decl = build_dummy_object (context);
4574 : : }
4575 : :
4576 : 101577690 : return decl;
4577 : : }
4578 : :
4579 : : /* Returns 1 if OB is a placeholder object, or a pointer to one. */
4580 : :
4581 : : bool
4582 : 454956036 : is_dummy_object (const_tree ob)
4583 : : {
4584 : 454956036 : if (INDIRECT_REF_P (ob))
4585 : 358060224 : ob = TREE_OPERAND (ob, 0);
4586 : 454956036 : return (TREE_CODE (ob) == CONVERT_EXPR
4587 : 454956036 : && TREE_OPERAND (ob, 0) == void_node);
4588 : : }
4589 : :
4590 : : /* Returns true if TYPE is char, unsigned char, or std::byte. */
4591 : :
4592 : : bool
4593 : 28908510 : is_byte_access_type (tree type)
4594 : : {
4595 : 28908510 : type = TYPE_MAIN_VARIANT (type);
4596 : 28908510 : if (type == char_type_node
4597 : 5256135 : || type == unsigned_char_type_node)
4598 : : return true;
4599 : :
4600 : 5126826 : return (TREE_CODE (type) == ENUMERAL_TYPE
4601 : 8170 : && TYPE_CONTEXT (type) == std_node
4602 : 5132262 : && !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 : 51942520 : scalarish_type_p (const_tree t)
4622 : : {
4623 : 51942520 : if (t == error_mark_node)
4624 : : return 1;
4625 : :
4626 : 51942319 : 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 : 326171596 : maybe_warn_parm_abi (tree t, location_t loc)
4655 : : {
4656 : 326171596 : if (!deleted_copy_types
4657 : 326171596 : || !deleted_copy_types->contains (t))
4658 : 326171566 : 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 : 47455807 : type_has_nontrivial_copy_init (const_tree type)
4693 : : {
4694 : 47455807 : tree t = strip_array_types (CONST_CAST_TREE (type));
4695 : :
4696 : 47455807 : if (CLASS_TYPE_P (t))
4697 : : {
4698 : 46819306 : gcc_assert (COMPLETE_TYPE_P (t));
4699 : :
4700 : 46819306 : if (TYPE_HAS_COMPLEX_COPY_CTOR (t)
4701 : 46819306 : || TYPE_HAS_COMPLEX_MOVE_CTOR (t))
4702 : : /* Nontrivial. */
4703 : : return true;
4704 : :
4705 : 43100144 : 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 : 43009175 : if (!abi_version_at_least (12)
4712 : 8132 : && !(warn_abi && abi_version_crosses (12)))
4713 : : return false;
4714 : :
4715 : 43001273 : bool saw_copy = false;
4716 : 43001273 : bool saw_non_deleted = false;
4717 : 43001273 : bool saw_non_deleted_move = false;
4718 : :
4719 : 43001273 : if (CLASSTYPE_LAZY_MOVE_CTOR (t))
4720 : : saw_copy = saw_non_deleted = true;
4721 : 3602919 : else if (CLASSTYPE_LAZY_COPY_CTOR (t))
4722 : : {
4723 : 516690 : saw_copy = true;
4724 : 516690 : 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 : 14490098 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
4737 : : {
4738 : 8493481 : tree fn = *iter;
4739 : 8493481 : if (copy_fn_p (fn))
4740 : : {
4741 : 3086266 : saw_copy = true;
4742 : 3086266 : if (!DECL_DELETED_FN (fn))
4743 : : {
4744 : : /* Not deleted, therefore trivial. */
4745 : : saw_non_deleted = true;
4746 : : break;
4747 : : }
4748 : : }
4749 : 5407215 : else if (move_fn_p (fn))
4750 : 2025024 : if (!DECL_DELETED_FN (fn))
4751 : 2018358 : saw_non_deleted_move = true;
4752 : : }
4753 : :
4754 : 43001273 : gcc_assert (saw_copy);
4755 : :
4756 : : /* ABI v12 buggily ignored move constructors. */
4757 : 43001273 : bool v11nontriv = false;
4758 : 43001273 : bool v12nontriv = !saw_non_deleted;
4759 : 43001273 : bool v13nontriv = !saw_non_deleted && !saw_non_deleted_move;
4760 : 43001273 : bool nontriv = (abi_version_at_least (13) ? v13nontriv
4761 : 124 : : flag_abi_version == 12 ? v12nontriv
4762 : 124 : : v11nontriv);
4763 : 43001678 : bool warn_nontriv = (warn_abi_version >= 13 ? v13nontriv
4764 : 405 : : warn_abi_version == 12 ? v12nontriv
4765 : : : v11nontriv);
4766 : 43001273 : if (nontriv != warn_nontriv)
4767 : 9 : remember_deleted_copy (t);
4768 : :
4769 : 43001273 : 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 : 212593 : trivially_copyable_p (const_tree t)
4780 : : {
4781 : 212593 : t = strip_array_types (CONST_CAST_TREE (t));
4782 : :
4783 : 212593 : if (CLASS_TYPE_P (t))
4784 : 45299 : return ((!TYPE_HAS_COPY_CTOR (t)
4785 : 45299 : || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
4786 : 44363 : && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
4787 : 44323 : && (!TYPE_HAS_COPY_ASSIGN (t)
4788 : 44323 : || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
4789 : 43347 : && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
4790 : 88478 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
4791 : : else
4792 : : /* CWG 2094 makes volatile-qualified scalars trivially copyable again. */
4793 : 167294 : 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 : 54242 : trivial_type_p (const_tree t)
4801 : : {
4802 : 54242 : t = strip_array_types (CONST_CAST_TREE (t));
4803 : :
4804 : 54242 : 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 : 20096 : return (type_has_non_deleted_trivial_default_ctor (CONST_CAST_TREE (t))
4808 : 20096 : && trivially_copyable_p (t));
4809 : : else
4810 : 34146 : 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 : 424 : && (!CLASSTYPE_DESTRUCTOR (t)
4830 : 46 : || !user_provided_p (CLASSTYPE_DESTRUCTOR (t))))
4831 : 91 : return true;
4832 : 221 : if (is_trivially_xible (BIT_NOT_EXPR, t, NULL_TREE))
4833 : : {
4834 : 188 : if (is_trivially_xible (INIT_EXPR, t, make_tree_vec (0)))
4835 : : return true;
4836 : 111 : tree arg = make_tree_vec (1);
4837 : 111 : tree ct
4838 : 111 : = cp_build_qualified_type (t, (cp_type_quals (t) | TYPE_QUAL_CONST));
4839 : 111 : TREE_VEC_ELT (arg, 0) = cp_build_reference_type (ct, /*rval=*/false);
4840 : 111 : 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 : 12021 : 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 : 12021 : t = strip_array_types (CONST_CAST_TREE(t));
4857 : :
4858 : 12021 : if (!CLASS_TYPE_P (t))
4859 : 706 : return scalarish_type_p (t);
4860 : 11315 : 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 : 11086 : return (std_layout_type_p (t) && trivial_type_p (t));
4868 : : else
4869 : : /* The C++98 definition of POD is different. */
4870 : 229 : 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 : 16245129 : layout_pod_type_p (const_tree t)
4878 : : {
4879 : 16245129 : t = strip_array_types (CONST_CAST_TREE (t));
4880 : :
4881 : 16245129 : if (CLASS_TYPE_P (t))
4882 : 3088569 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
4883 : : else
4884 : 13156560 : 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 : 16308709 : std_layout_type_p (const_tree t)
4892 : : {
4893 : 16308709 : t = strip_array_types (CONST_CAST_TREE (t));
4894 : :
4895 : 16308709 : if (CLASS_TYPE_P (t))
4896 : 3101887 : return !CLASSTYPE_NON_STD_LAYOUT (t);
4897 : : else
4898 : 13206822 : return scalarish_type_p (t);
4899 : : }
4900 : :
4901 : : static bool record_has_unique_obj_representations (const_tree, const_tree, bool);
4902 : :
4903 : : /* Returns true iff T satisfies std::has_unique_object_representations<T>,
4904 : : as defined in [meta.unary.prop]. If EXPLAIN is true, explain why not. */
4905 : :
4906 : : bool
4907 : 26361 : type_has_unique_obj_representations (const_tree t, bool explain/*=false*/)
4908 : : {
4909 : 26361 : bool ret;
4910 : :
4911 : 26361 : t = strip_array_types (CONST_CAST_TREE (t));
4912 : :
4913 : 26361 : if (t == error_mark_node)
4914 : : return false;
4915 : :
4916 : 26358 : location_t loc = input_location;
4917 : 26358 : if (tree m = TYPE_MAIN_DECL (t))
4918 : 2808 : loc = DECL_SOURCE_LOCATION (m);
4919 : :
4920 : 26358 : if (!trivially_copyable_p (t))
4921 : : {
4922 : 22 : if (explain)
4923 : 6 : inform (loc, "%qT is not trivially copyable", t);
4924 : 22 : return false;
4925 : : }
4926 : :
4927 : 202 : if (CLASS_TYPE_P (t)
4928 : 199 : && CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t)
4929 : 26432 : && !explain)
4930 : 72 : return CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t);
4931 : :
4932 : 26264 : switch (TREE_CODE (t))
4933 : : {
4934 : : case INTEGER_TYPE:
4935 : : case POINTER_TYPE:
4936 : : case REFERENCE_TYPE:
4937 : : /* If some backend has any paddings in these types, we should add
4938 : : a target hook for this and handle it there. */
4939 : : return true;
4940 : :
4941 : : case BOOLEAN_TYPE:
4942 : : /* For bool values other than 0 and 1 should only appear with
4943 : : undefined behavior. */
4944 : : return true;
4945 : :
4946 : 2591 : case ENUMERAL_TYPE:
4947 : 2591 : return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t),
4948 : 2591 : explain);
4949 : :
4950 : 15518 : case REAL_TYPE:
4951 : : /* XFmode certainly contains padding on x86, which the CPU doesn't store
4952 : : when storing long double values, so for that we have to return false.
4953 : : Other kinds of floating point values are questionable due to +.0/-.0
4954 : : and NaNs, let's play safe for now. */
4955 : 15518 : if (explain)
4956 : 0 : inform (loc, "%qT is a floating-point type", t);
4957 : : return false;
4958 : :
4959 : 0 : case FIXED_POINT_TYPE:
4960 : 0 : if (explain)
4961 : 0 : inform (loc, "%qT is a fixed-point type", t);
4962 : : return false;
4963 : :
4964 : : case OFFSET_TYPE:
4965 : : return true;
4966 : :
4967 : 18 : case COMPLEX_TYPE:
4968 : 18 : case VECTOR_TYPE:
4969 : 18 : return type_has_unique_obj_representations (TREE_TYPE (t), explain);
4970 : :
4971 : 109 : case RECORD_TYPE:
4972 : 109 : ret = record_has_unique_obj_representations (t, TYPE_SIZE (t), explain);
4973 : 109 : if (CLASS_TYPE_P (t))
4974 : : {
4975 : 106 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
4976 : 106 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
4977 : : }
4978 : : return ret;
4979 : :
4980 : 21 : case UNION_TYPE:
4981 : 21 : ret = true;
4982 : 21 : bool any_fields;
4983 : 21 : any_fields = false;
4984 : 42 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
4985 : 33 : if (TREE_CODE (field) == FIELD_DECL)
4986 : : {
4987 : 24 : any_fields = true;
4988 : 24 : if (simple_cst_equal (DECL_SIZE (field), TYPE_SIZE (t)) != 1)
4989 : : {
4990 : 12 : if (explain)
4991 : 3 : inform (DECL_SOURCE_LOCATION (field),
4992 : : "%qD does not fill all bits of %q#T", field, t);
4993 : : ret = false;
4994 : : break;
4995 : : }
4996 : 12 : if (!type_has_unique_obj_representations (TREE_TYPE (field)))
4997 : : {
4998 : 0 : if (explain)
4999 : 0 : inform (DECL_SOURCE_LOCATION (field),
5000 : : "%qD has type %qT that does not have "
5001 : : "unique object representations",
5002 : 0 : field, TREE_TYPE (field));
5003 : : ret = false;
5004 : : break;
5005 : : }
5006 : : }
5007 : 9 : if (!any_fields && !integer_zerop (TYPE_SIZE (t)))
5008 : : {
5009 : 6 : if (explain)
5010 : 3 : inform (loc, "%q#T has no data fields", t);
5011 : : ret = false;
5012 : : }
5013 : 21 : if (CLASS_TYPE_P (t))
5014 : : {
5015 : 21 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
5016 : 21 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
5017 : : }
5018 : : return ret;
5019 : :
5020 : 3 : case NULLPTR_TYPE:
5021 : 3 : if (explain)
5022 : 0 : inform (loc, "%<std::nullptr_t%> has padding bits and no value bits");
5023 : : return false;
5024 : :
5025 : 0 : default:
5026 : 0 : gcc_unreachable ();
5027 : : }
5028 : : }
5029 : :
5030 : : /* Helper function for type_has_unique_obj_representations. */
5031 : :
5032 : : static bool
5033 : 120 : record_has_unique_obj_representations (const_tree t, const_tree sz,
5034 : : bool explain)
5035 : : {
5036 : 638 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5037 : 548 : if (TREE_CODE (field) != FIELD_DECL)
5038 : : ;
5039 : : /* For bases, can't use type_has_unique_obj_representations here, as in
5040 : : struct S { int i : 24; S (); };
5041 : : struct T : public S { int j : 8; T (); };
5042 : : S doesn't have unique obj representations, but T does. */
5043 : 167 : else if (DECL_FIELD_IS_BASE (field))
5044 : : {
5045 : 11 : if (!record_has_unique_obj_representations (TREE_TYPE (field),
5046 : 11 : DECL_SIZE (field),
5047 : : /*explain=*/false))
5048 : : {
5049 : 6 : if (explain)
5050 : 3 : inform (DECL_SOURCE_LOCATION (field),
5051 : : "base %qT does not have unique object representations",
5052 : 3 : TREE_TYPE (field));
5053 : 6 : return false;
5054 : : }
5055 : : }
5056 : 156 : else if (DECL_C_BIT_FIELD (field) && !DECL_UNNAMED_BIT_FIELD (field))
5057 : : {
5058 : 55 : tree btype = DECL_BIT_FIELD_TYPE (field);
5059 : 55 : if (!type_has_unique_obj_representations (btype))
5060 : : {
5061 : 0 : if (explain)
5062 : 0 : inform (DECL_SOURCE_LOCATION (field),
5063 : : "%qD with type %qT does not have "
5064 : : "unique object representations",
5065 : : field, btype);
5066 : 0 : return false;
5067 : : }
5068 : : }
5069 : 101 : else if (!type_has_unique_obj_representations (TREE_TYPE (field)))
5070 : : {
5071 : 24 : if (explain)
5072 : 6 : inform (DECL_SOURCE_LOCATION (field),
5073 : : "%qD with type %qT does not have "
5074 : : "unique object representations",
5075 : 6 : field, TREE_TYPE (field));
5076 : 24 : return false;
5077 : : }
5078 : :
5079 : 90 : offset_int cur = 0;
5080 : 90 : tree last_field = NULL_TREE;
5081 : 90 : tree last_named_field = NULL_TREE;
5082 : 547 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5083 : 486 : if (TREE_CODE (field) == FIELD_DECL)
5084 : : {
5085 : 134 : if (DECL_UNNAMED_BIT_FIELD (field))
5086 : : {
5087 : 15 : last_field = field;
5088 : 15 : continue;
5089 : : }
5090 : 119 : offset_int fld = wi::to_offset (DECL_FIELD_OFFSET (field));
5091 : 119 : offset_int bitpos = wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
5092 : 119 : fld = fld * BITS_PER_UNIT + bitpos;
5093 : 119 : if (cur != fld)
5094 : : {
5095 : 29 : if (explain)
5096 : : {
5097 : 6 : if (last_named_field)
5098 : 3 : inform (DECL_SOURCE_LOCATION (last_named_field),
5099 : : "padding occurs between %qD and %qD",
5100 : : last_named_field, field);
5101 : 3 : else if (last_field)
5102 : 3 : inform (DECL_SOURCE_LOCATION (last_field),
5103 : : "unnamed bit-field inserts padding before %qD",
5104 : : field);
5105 : : else
5106 : 0 : inform (DECL_SOURCE_LOCATION (field),
5107 : : "padding occurs before %qD", field);
5108 : : }
5109 : 29 : return false;
5110 : : }
5111 : 90 : if (DECL_SIZE (field))
5112 : : {
5113 : 87 : offset_int size = wi::to_offset (DECL_SIZE (field));
5114 : 87 : cur += size;
5115 : : }
5116 : 90 : last_named_field = last_field = field;
5117 : : }
5118 : 61 : if (cur != wi::to_offset (sz))
5119 : : {
5120 : 22 : if (explain)
5121 : : {
5122 : 3 : if (last_named_field)
5123 : 3 : inform (DECL_SOURCE_LOCATION (last_named_field),
5124 : : "padding occurs after %qD", last_named_field);
5125 : : else
5126 : 0 : inform (DECL_SOURCE_LOCATION (t),
5127 : : "%qT has padding and no data fields", t);
5128 : : }
5129 : 22 : return false;
5130 : : }
5131 : :
5132 : : return true;
5133 : : }
5134 : :
5135 : : /* Nonzero iff type T is a class template implicit specialization. */
5136 : :
5137 : : bool
5138 : 110614486 : class_tmpl_impl_spec_p (const_tree t)
5139 : : {
5140 : 110614486 : return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
5141 : : }
5142 : :
5143 : : /* Returns 1 iff zero initialization of type T means actually storing
5144 : : zeros in it. */
5145 : :
5146 : : int
5147 : 18375476 : zero_init_p (const_tree t)
5148 : : {
5149 : : /* This CONST_CAST is okay because strip_array_types returns its
5150 : : argument unmodified and we assign it to a const_tree. */
5151 : 18375476 : t = strip_array_types (CONST_CAST_TREE(t));
5152 : :
5153 : 18375476 : if (t == error_mark_node)
5154 : : return 1;
5155 : :
5156 : : /* NULL pointers to data members are initialized with -1. */
5157 : 18375476 : if (TYPE_PTRDATAMEM_P (t))
5158 : : return 0;
5159 : :
5160 : : /* Classes that contain types that can't be zero-initialized, cannot
5161 : : be zero-initialized themselves. */
5162 : 18374868 : if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
5163 : 154 : return 0;
5164 : :
5165 : : return 1;
5166 : : }
5167 : :
5168 : : /* Returns true if the expression or initializer T is the result of
5169 : : zero-initialization for its type, taking pointers to members
5170 : : into consideration. */
5171 : :
5172 : : bool
5173 : 269803 : zero_init_expr_p (tree t)
5174 : : {
5175 : 269803 : tree type = TREE_TYPE (t);
5176 : 269803 : if (!type || uses_template_parms (type))
5177 : 0 : return false;
5178 : 269803 : if (TYPE_PTRMEM_P (type))
5179 : 1251 : return null_member_pointer_value_p (t);
5180 : 268552 : if (TREE_CODE (t) == CONSTRUCTOR)
5181 : : {
5182 : 114871 : if (COMPOUND_LITERAL_P (t)
5183 : 114871 : || BRACE_ENCLOSED_INITIALIZER_P (t))
5184 : : /* Undigested, conversions might change the zeroness. */
5185 : : return false;
5186 : 339634 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (t))
5187 : : {
5188 : 113216 : if (TREE_CODE (type) == UNION_TYPE
5189 : 113216 : && elt.index != first_field (type))
5190 : : return false;
5191 : 113207 : if (!zero_init_expr_p (elt.value))
5192 : : return false;
5193 : : }
5194 : : return true;
5195 : : }
5196 : 153681 : if (zero_init_p (type))
5197 : 153681 : return initializer_zerop (t);
5198 : : return false;
5199 : : }
5200 : :
5201 : : /* True IFF T is a C++20 structural type (P1907R1) that can be used as a
5202 : : non-type template parameter. If EXPLAIN, explain why not. */
5203 : :
5204 : : bool
5205 : 18617 : structural_type_p (tree t, bool explain)
5206 : : {
5207 : : /* A structural type is one of the following: */
5208 : :
5209 : : /* a scalar type, or */
5210 : 18617 : if (SCALAR_TYPE_P (t))
5211 : : return true;
5212 : : /* an lvalue reference type, or */
5213 : 10535 : if (TYPE_REF_P (t) && !TYPE_REF_IS_RVALUE (t))
5214 : : return true;
5215 : : /* a literal class type with the following properties:
5216 : : - all base classes and non-static data members are public and non-mutable
5217 : : and
5218 : : - the types of all bases classes and non-static data members are
5219 : : structural types or (possibly multi-dimensional) array thereof. */
5220 : 10527 : if (!CLASS_TYPE_P (t))
5221 : : return false;
5222 : 10523 : if (!literal_type_p (t))
5223 : : {
5224 : 14 : if (explain)
5225 : 6 : explain_non_literal_class (t);
5226 : 14 : return false;
5227 : : }
5228 : 19326 : for (tree m = next_aggregate_field (TYPE_FIELDS (t)); m;
5229 : 8817 : m = next_aggregate_field (DECL_CHAIN (m)))
5230 : : {
5231 : 8862 : if (TREE_PRIVATE (m) || TREE_PROTECTED (m))
5232 : : {
5233 : 27 : if (explain)
5234 : : {
5235 : 3 : if (DECL_FIELD_IS_BASE (m))
5236 : 3 : inform (location_of (m), "base class %qT is not public",
5237 : 3 : TREE_TYPE (m));
5238 : : else
5239 : 0 : inform (location_of (m), "%qD is not public", m);
5240 : : }
5241 : 27 : return false;
5242 : : }
5243 : 8835 : if (DECL_MUTABLE_P (m))
5244 : : {
5245 : 0 : if (explain)
5246 : 0 : inform (location_of (m), "%qD is mutable", m);
5247 : 0 : return false;
5248 : : }
5249 : 8835 : tree mtype = strip_array_types (TREE_TYPE (m));
5250 : 8835 : if (!structural_type_p (mtype))
5251 : : {
5252 : 18 : if (explain)
5253 : : {
5254 : 0 : inform (location_of (m), "%qD has a non-structural type", m);
5255 : 0 : structural_type_p (mtype, true);
5256 : : }
5257 : 18 : return false;
5258 : : }
5259 : : }
5260 : : return true;
5261 : : }
5262 : :
5263 : : /* Partially handle the C++11 [[carries_dependency]] attribute.
5264 : : Just emit a different diagnostics when it is used on something the
5265 : : spec doesn't allow vs. where it allows and we just choose to ignore
5266 : : it. */
5267 : :
5268 : : static tree
5269 : 142 : handle_carries_dependency_attribute (tree *node, tree name,
5270 : : tree ARG_UNUSED (args),
5271 : : int ARG_UNUSED (flags),
5272 : : bool *no_add_attrs)
5273 : : {
5274 : 142 : if (TREE_CODE (*node) != FUNCTION_DECL
5275 : 121 : && TREE_CODE (*node) != PARM_DECL)
5276 : : {
5277 : 76 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5278 : : "functions or parameters", name);
5279 : 76 : *no_add_attrs = true;
5280 : : }
5281 : : else
5282 : : {
5283 : 66 : warning (OPT_Wattributes, "%qE attribute ignored", name);
5284 : 66 : *no_add_attrs = true;
5285 : : }
5286 : 142 : return NULL_TREE;
5287 : : }
5288 : :
5289 : : /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
5290 : : warn_unused_result attribute. */
5291 : :
5292 : : static tree
5293 : 11905227 : handle_nodiscard_attribute (tree *node, tree name, tree args,
5294 : : int /*flags*/, bool *no_add_attrs)
5295 : : {
5296 : 11905368 : if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
5297 : : {
5298 : 6 : error ("%qE attribute argument must be a string constant", name);
5299 : 6 : *no_add_attrs = true;
5300 : : }
5301 : 11905227 : if (TREE_CODE (*node) == FUNCTION_DECL)
5302 : : {
5303 : 11904885 : if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))
5304 : 12012865 : && !DECL_CONSTRUCTOR_P (*node))
5305 : 9 : warning_at (DECL_SOURCE_LOCATION (*node),
5306 : 9 : OPT_Wattributes, "%qE attribute applied to %qD with void "
5307 : : "return type", name, *node);
5308 : : }
5309 : 342 : else if (OVERLOAD_TYPE_P (*node))
5310 : : /* OK */;
5311 : : else
5312 : : {
5313 : 148 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5314 : : "functions or to class or enumeration types", name);
5315 : 148 : *no_add_attrs = true;
5316 : : }
5317 : 11905227 : return NULL_TREE;
5318 : : }
5319 : :
5320 : : /* Handle a C++20 "no_unique_address" attribute; arguments as in
5321 : : struct attribute_spec.handler. */
5322 : : static tree
5323 : 348195 : handle_no_unique_addr_attribute (tree* node,
5324 : : tree name,
5325 : : tree /*args*/,
5326 : : int /*flags*/,
5327 : : bool* no_add_attrs)
5328 : : {
5329 : 348195 : if (TREE_CODE (*node) == VAR_DECL)
5330 : : {
5331 : 48 : DECL_MERGEABLE (*node) = true;
5332 : 48 : if (pedantic)
5333 : 42 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5334 : : "non-static data members", name);
5335 : : }
5336 : 348147 : else if (TREE_CODE (*node) != FIELD_DECL)
5337 : : {
5338 : 82 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5339 : : "non-static data members", name);
5340 : 82 : *no_add_attrs = true;
5341 : : }
5342 : 348065 : else if (DECL_C_BIT_FIELD (*node))
5343 : : {
5344 : 6 : warning (OPT_Wattributes, "%qE attribute cannot be applied to "
5345 : : "a bit-field", name);
5346 : 6 : *no_add_attrs = true;
5347 : : }
5348 : :
5349 : 348195 : return NULL_TREE;
5350 : : }
5351 : :
5352 : : /* The C++20 [[likely]] and [[unlikely]] attributes on labels map to the GNU
5353 : : hot/cold attributes. */
5354 : :
5355 : : static tree
5356 : 392 : handle_likeliness_attribute (tree *node, tree name, tree args,
5357 : : int flags, bool *no_add_attrs)
5358 : : {
5359 : 392 : *no_add_attrs = true;
5360 : 392 : if (TREE_CODE (*node) == LABEL_DECL
5361 : 392 : || TREE_CODE (*node) == FUNCTION_DECL)
5362 : : {
5363 : 90 : if (args)
5364 : 0 : warning (OPT_Wattributes, "%qE attribute takes no arguments", name);
5365 : 90 : tree bname = (is_attribute_p ("likely", name)
5366 : 90 : ? get_identifier ("hot") : get_identifier ("cold"));
5367 : 90 : if (TREE_CODE (*node) == FUNCTION_DECL)
5368 : 33 : warning (OPT_Wattributes, "ISO C++ %qE attribute does not apply to "
5369 : : "functions; treating as %<[[gnu::%E]]%>", name, bname);
5370 : 90 : tree battr = build_tree_list (bname, NULL_TREE);
5371 : 90 : decl_attributes (node, battr, flags);
5372 : 90 : return NULL_TREE;
5373 : : }
5374 : : else
5375 : 302 : return error_mark_node;
5376 : : }
5377 : :
5378 : : /* The C++11 alignment specifier. It mostly maps to GNU aligned attribute,
5379 : : but we need to do some extra pedantic checking. */
5380 : :
5381 : : static tree
5382 : 239368 : handle_alignas_attribute (tree *node, tree name, tree args, int flags,
5383 : : bool *no_add_attrs)
5384 : : {
5385 : 239368 : tree t = *node;
5386 : 239368 : tree ret = handle_aligned_attribute (node, name, args, flags, no_add_attrs);
5387 : 239368 : if (pedantic)
5388 : : {
5389 : 1181 : if (TREE_CODE (*node) == FUNCTION_DECL)
5390 : 15 : pedwarn (input_location, OPT_Wattributes,
5391 : : "%<alignas%> on function declaration");
5392 : 1166 : else if (TREE_CODE (*node) == ENUMERAL_TYPE)
5393 : 9 : pedwarn (input_location, OPT_Wattributes,
5394 : : "%<alignas%> on enumerated type");
5395 : 1157 : else if (TYPE_P (*node) && t != *node)
5396 : 56 : pedwarn (input_location, OPT_Wattributes,
5397 : : "%<alignas%> on a type other than class");
5398 : 1101 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_C_BIT_FIELD (*node))
5399 : 9 : pedwarn (input_location, OPT_Wattributes, "%<alignas%> on bit-field");
5400 : 1092 : else if (TREE_CODE (t) == TYPE_DECL)
5401 : 9 : pedwarn (input_location, OPT_Wattributes,
5402 : : "%<alignas%> on a type alias");
5403 : : }
5404 : 239368 : return ret;
5405 : : }
5406 : :
5407 : : /* The C++14 [[deprecated]] attribute mostly maps to the GNU deprecated
5408 : : attribute. */
5409 : :
5410 : : static tree
5411 : 640658 : handle_std_deprecated_attribute (tree *node, tree name, tree args, int flags,
5412 : : bool *no_add_attrs)
5413 : : {
5414 : 640658 : tree t = *node;
5415 : 640658 : tree ret = handle_deprecated_attribute (node, name, args, flags,
5416 : : no_add_attrs);
5417 : 640658 : if (TYPE_P (*node) && t != *node)
5418 : 48 : pedwarn (input_location, OPT_Wattributes,
5419 : : "%qE on a type other than class or enumeration definition", name);
5420 : 640610 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5421 : 4 : pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
5422 : : name);
5423 : 640658 : return ret;
5424 : : }
5425 : :
5426 : : /* The C++17 [[maybe_unused]] attribute mostly maps to the GNU unused
5427 : : attribute. */
5428 : :
5429 : : static tree
5430 : 70705 : handle_maybe_unused_attribute (tree *node, tree name, tree args, int flags,
5431 : : bool *no_add_attrs)
5432 : : {
5433 : 70705 : tree t = *node;
5434 : 70705 : tree ret = handle_unused_attribute (node, name, args, flags, no_add_attrs);
5435 : 70705 : if (TYPE_P (*node) && t != *node)
5436 : 36 : pedwarn (input_location, OPT_Wattributes,
5437 : : "%qE on a type other than class or enumeration definition", name);
5438 : 70669 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5439 : 3 : pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
5440 : : name);
5441 : 70666 : else if (TREE_CODE (*node) == LABEL_DECL && DECL_NAME (*node) == NULL_TREE)
5442 : 6 : pedwarn (input_location, OPT_Wattributes,
5443 : : "%qE on %<case%> or %<default%> label", name);
5444 : 70705 : return ret;
5445 : : }
5446 : :
5447 : : /* The C++26 [[indeterminate]] attribute. */
5448 : :
5449 : : static tree
5450 : 207 : handle_indeterminate_attribute (tree *node, tree name, tree, int,
5451 : : bool *no_add_attrs)
5452 : : {
5453 : 207 : if (TREE_CODE (*node) != PARM_DECL
5454 : 207 : && (!VAR_P (*node) || is_global_var (*node)))
5455 : : {
5456 : 67 : pedwarn (input_location, OPT_Wattributes,
5457 : : "%qE on declaration other than parameter or automatic variable",
5458 : : name);
5459 : 67 : *no_add_attrs = true;
5460 : : }
5461 : 207 : return NULL_TREE;
5462 : : }
5463 : :
5464 : : /* Table of valid C++ attributes. */
5465 : : static const attribute_spec cxx_gnu_attributes[] =
5466 : : {
5467 : : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5468 : : affects_type_identity, handler, exclude } */
5469 : : { "init_priority", 1, 1, true, false, false, false,
5470 : : handle_init_priority_attribute, NULL },
5471 : : { "abi_tag", 1, -1, false, false, false, true,
5472 : : handle_abi_tag_attribute, NULL },
5473 : : { "no_dangling", 0, 1, false, true, false, false,
5474 : : handle_no_dangling_attribute, NULL },
5475 : : };
5476 : :
5477 : : const scoped_attribute_specs cxx_gnu_attribute_table =
5478 : : {
5479 : : "gnu", { cxx_gnu_attributes }
5480 : : };
5481 : :
5482 : : /* Table of C++ standard attributes. */
5483 : : static const attribute_spec std_attributes[] =
5484 : : {
5485 : : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5486 : : affects_type_identity, handler, exclude } */
5487 : : { "deprecated", 0, 1, false, false, false, false,
5488 : : handle_std_deprecated_attribute, NULL },
5489 : : { "maybe_unused", 0, 0, false, false, false, false,
5490 : : handle_maybe_unused_attribute, NULL },
5491 : : { "nodiscard", 0, 1, false, false, false, false,
5492 : : handle_nodiscard_attribute, NULL },
5493 : : { "no_unique_address", 0, 0, true, false, false, false,
5494 : : handle_no_unique_addr_attribute, NULL },
5495 : : { "likely", 0, 0, false, false, false, false,
5496 : : handle_likeliness_attribute, attr_cold_hot_exclusions },
5497 : : { "unlikely", 0, 0, false, false, false, false,
5498 : : handle_likeliness_attribute, attr_cold_hot_exclusions },
5499 : : { "noreturn", 0, 0, true, false, false, false,
5500 : : handle_noreturn_attribute, attr_noreturn_exclusions },
5501 : : { "carries_dependency", 0, 0, true, false, false, false,
5502 : : handle_carries_dependency_attribute, NULL },
5503 : : { "indeterminate", 0, 0, true, false, false, false,
5504 : : handle_indeterminate_attribute, NULL },
5505 : : { "pre", 0, -1, false, false, false, false,
5506 : : handle_contract_attribute, NULL },
5507 : : { "post", 0, -1, false, false, false, false,
5508 : : handle_contract_attribute, NULL }
5509 : : };
5510 : :
5511 : : const scoped_attribute_specs std_attribute_table =
5512 : : {
5513 : : nullptr, { std_attributes }
5514 : : };
5515 : :
5516 : : /* Table of internal attributes. */
5517 : : static const attribute_spec internal_attributes[] =
5518 : : {
5519 : : { "aligned", 0, 1, false, false, false, false,
5520 : : handle_alignas_attribute, attr_aligned_exclusions }
5521 : : };
5522 : :
5523 : : const scoped_attribute_specs internal_attribute_table =
5524 : : {
5525 : : "internal ", { internal_attributes }
5526 : : };
5527 : :
5528 : : /* Handle an "init_priority" attribute; arguments as in
5529 : : struct attribute_spec.handler. */
5530 : : static tree
5531 : 35 : handle_init_priority_attribute (tree* node,
5532 : : tree name,
5533 : : tree args,
5534 : : int /*flags*/,
5535 : : bool* no_add_attrs)
5536 : : {
5537 : 35 : if (!SUPPORTS_INIT_PRIORITY)
5538 : : /* Treat init_priority as an unrecognized attribute (mirroring
5539 : : __has_attribute) if the target doesn't support init priorities. */
5540 : : return error_mark_node;
5541 : :
5542 : 35 : tree initp_expr = TREE_VALUE (args);
5543 : 35 : tree decl = *node;
5544 : 35 : tree type = TREE_TYPE (decl);
5545 : 35 : int pri;
5546 : :
5547 : 35 : STRIP_NOPS (initp_expr);
5548 : 35 : initp_expr = default_conversion (initp_expr);
5549 : 35 : if (initp_expr)
5550 : 35 : initp_expr = maybe_constant_value (initp_expr);
5551 : :
5552 : 35 : if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
5553 : : {
5554 : 0 : error ("requested %<init_priority%> is not an integer constant");
5555 : 0 : cxx_constant_value (initp_expr);
5556 : 0 : *no_add_attrs = true;
5557 : 0 : return NULL_TREE;
5558 : : }
5559 : :
5560 : 35 : pri = TREE_INT_CST_LOW (initp_expr);
5561 : :
5562 : 35 : type = strip_array_types (type);
5563 : :
5564 : 35 : if (decl == NULL_TREE
5565 : 35 : || !VAR_P (decl)
5566 : 35 : || !TREE_STATIC (decl)
5567 : 35 : || DECL_EXTERNAL (decl)
5568 : 35 : || (TREE_CODE (type) != RECORD_TYPE
5569 : 35 : && TREE_CODE (type) != UNION_TYPE)
5570 : : /* Static objects in functions are initialized the
5571 : : first time control passes through that
5572 : : function. This is not precise enough to pin down an
5573 : : init_priority value, so don't allow it. */
5574 : 70 : || current_function_decl)
5575 : : {
5576 : 0 : error ("can only use %qE attribute on file-scope definitions "
5577 : : "of objects of class type", name);
5578 : 0 : *no_add_attrs = true;
5579 : 0 : return NULL_TREE;
5580 : : }
5581 : :
5582 : 35 : if (pri > MAX_INIT_PRIORITY || pri <= 0)
5583 : : {
5584 : 0 : error ("requested %<init_priority%> %i is out of range [0, %i]",
5585 : : pri, MAX_INIT_PRIORITY);
5586 : 0 : *no_add_attrs = true;
5587 : 0 : return NULL_TREE;
5588 : : }
5589 : :
5590 : : /* Check for init_priorities that are reserved for
5591 : : language and runtime support implementations.*/
5592 : 35 : if (pri <= MAX_RESERVED_INIT_PRIORITY
5593 : 35 : && !in_system_header_at (input_location))
5594 : : {
5595 : 10 : warning
5596 : 10 : (OPT_Wprio_ctor_dtor,
5597 : : "requested %<init_priority%> %i is reserved for internal use",
5598 : : pri);
5599 : : }
5600 : :
5601 : 35 : SET_DECL_INIT_PRIORITY (decl, pri);
5602 : 35 : DECL_HAS_INIT_PRIORITY_P (decl) = 1;
5603 : 35 : return NULL_TREE;
5604 : : }
5605 : :
5606 : : /* DECL is being redeclared; the old declaration had the abi tags in OLD,
5607 : : and the new one has the tags in NEW_. Give an error if there are tags
5608 : : in NEW_ that weren't in OLD. */
5609 : :
5610 : : bool
5611 : 11141933 : check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_)
5612 : : {
5613 : 11177975 : if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST)
5614 : : old = TREE_VALUE (old);
5615 : 11164773 : if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST)
5616 : : new_ = TREE_VALUE (new_);
5617 : 11141933 : bool err = false;
5618 : 11141933 : auto_diagnostic_group d;
5619 : 11164773 : for (const_tree t = new_; t; t = TREE_CHAIN (t))
5620 : : {
5621 : 22840 : tree str = TREE_VALUE (t);
5622 : 22840 : for (const_tree in = old; in; in = TREE_CHAIN (in))
5623 : : {
5624 : 22831 : tree ostr = TREE_VALUE (in);
5625 : 22831 : if (cp_tree_equal (str, ostr))
5626 : 22831 : goto found;
5627 : : }
5628 : 9 : error ("redeclaration of %qD adds abi tag %qE", decl, str);
5629 : 9 : err = true;
5630 : 22840 : found:;
5631 : : }
5632 : 11141933 : if (err)
5633 : : {
5634 : 9 : inform (DECL_SOURCE_LOCATION (decl), "previous declaration here");
5635 : 9 : return false;
5636 : : }
5637 : : return true;
5638 : 11141933 : }
5639 : :
5640 : : /* The abi_tag attribute with the name NAME was given ARGS. If they are
5641 : : ill-formed, give an error and return false; otherwise, return true. */
5642 : :
5643 : : bool
5644 : 396843 : check_abi_tag_args (tree args, tree name)
5645 : : {
5646 : 396843 : if (!args)
5647 : : {
5648 : 0 : error ("the %qE attribute requires arguments", name);
5649 : 0 : return false;
5650 : : }
5651 : 793725 : for (tree arg = args; arg; arg = TREE_CHAIN (arg))
5652 : : {
5653 : 396894 : tree elt = TREE_VALUE (arg);
5654 : 396894 : if (TREE_CODE (elt) != STRING_CST
5655 : 793782 : || (!same_type_ignoring_top_level_qualifiers_p
5656 : 396888 : (strip_array_types (TREE_TYPE (elt)),
5657 : : char_type_node)))
5658 : : {
5659 : 9 : error ("arguments to the %qE attribute must be narrow string "
5660 : : "literals", name);
5661 : 9 : return false;
5662 : : }
5663 : 396885 : const char *begin = TREE_STRING_POINTER (elt);
5664 : 396885 : const char *end = begin + TREE_STRING_LENGTH (elt);
5665 : 2793809 : for (const char *p = begin; p != end; ++p)
5666 : : {
5667 : 2396927 : char c = *p;
5668 : 2396927 : if (p == begin)
5669 : : {
5670 : 396885 : if (!ISALPHA (c) && c != '_')
5671 : : {
5672 : 3 : auto_diagnostic_group d;
5673 : 3 : error ("arguments to the %qE attribute must contain valid "
5674 : : "identifiers", name);
5675 : 3 : inform (input_location, "%<%c%> is not a valid first "
5676 : : "character for an identifier", c);
5677 : 3 : return false;
5678 : 3 : }
5679 : : }
5680 : 2000042 : else if (p == end - 1)
5681 : 396882 : gcc_assert (c == 0);
5682 : : else
5683 : : {
5684 : 1603160 : if (!ISALNUM (c) && c != '_')
5685 : : {
5686 : 0 : auto_diagnostic_group d;
5687 : 0 : error ("arguments to the %qE attribute must contain valid "
5688 : : "identifiers", name);
5689 : 0 : inform (input_location, "%<%c%> is not a valid character "
5690 : : "in an identifier", c);
5691 : 0 : return false;
5692 : 0 : }
5693 : : }
5694 : : }
5695 : : }
5696 : : return true;
5697 : : }
5698 : :
5699 : : /* Handle an "abi_tag" attribute; arguments as in
5700 : : struct attribute_spec.handler. */
5701 : :
5702 : : static tree
5703 : 349141 : handle_abi_tag_attribute (tree* node, tree name, tree args,
5704 : : int flags, bool* no_add_attrs)
5705 : : {
5706 : 349141 : if (!check_abi_tag_args (args, name))
5707 : 12 : goto fail;
5708 : :
5709 : 349129 : if (TYPE_P (*node))
5710 : : {
5711 : 11615 : if (!OVERLOAD_TYPE_P (*node))
5712 : : {
5713 : 0 : error ("%qE attribute applied to non-class, non-enum type %qT",
5714 : : name, *node);
5715 : 0 : goto fail;
5716 : : }
5717 : 11615 : else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE))
5718 : : {
5719 : 0 : error ("%qE attribute applied to %qT after its definition",
5720 : : name, *node);
5721 : 0 : goto fail;
5722 : : }
5723 : 11612 : else if (CLASS_TYPE_P (*node)
5724 : 23227 : && CLASSTYPE_TEMPLATE_INSTANTIATION (*node))
5725 : : {
5726 : 3 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5727 : : "template instantiation %qT", name, *node);
5728 : 3 : goto fail;
5729 : : }
5730 : 11609 : else if (CLASS_TYPE_P (*node)
5731 : 23221 : && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node))
5732 : : {
5733 : 3 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5734 : : "template specialization %qT", name, *node);
5735 : 3 : goto fail;
5736 : : }
5737 : :
5738 : 11609 : tree attributes = TYPE_ATTRIBUTES (*node);
5739 : 11609 : tree decl = TYPE_NAME (*node);
5740 : :
5741 : : /* Make sure all declarations have the same abi tags. */
5742 : 11609 : if (DECL_SOURCE_LOCATION (decl) != input_location)
5743 : : {
5744 : 6 : if (!check_abi_tag_redeclaration (decl,
5745 : 6 : lookup_attribute ("abi_tag",
5746 : : attributes),
5747 : : args))
5748 : 6 : goto fail;
5749 : : }
5750 : : }
5751 : : else
5752 : : {
5753 : 337514 : if (!VAR_OR_FUNCTION_DECL_P (*node))
5754 : : {
5755 : 0 : error ("%qE attribute applied to non-function, non-variable %qD",
5756 : : name, *node);
5757 : 0 : goto fail;
5758 : : }
5759 : 337514 : else if (DECL_LANGUAGE (*node) == lang_c)
5760 : : {
5761 : 0 : error ("%qE attribute applied to extern \"C\" declaration %qD",
5762 : : name, *node);
5763 : 0 : goto fail;
5764 : : }
5765 : : }
5766 : :
5767 : : return NULL_TREE;
5768 : :
5769 : 24 : fail:
5770 : 24 : *no_add_attrs = true;
5771 : 24 : return NULL_TREE;
5772 : : }
5773 : :
5774 : : /* Perform checking for contract attributes. */
5775 : :
5776 : : tree
5777 : 677 : handle_contract_attribute (tree *ARG_UNUSED (node), tree ARG_UNUSED (name),
5778 : : tree ARG_UNUSED (args), int ARG_UNUSED (flags),
5779 : : bool *ARG_UNUSED (no_add_attrs))
5780 : : {
5781 : : /* TODO: Is there any checking we could do here? */
5782 : 677 : return NULL_TREE;
5783 : : }
5784 : :
5785 : : /* Handle a "no_dangling" attribute; arguments as in
5786 : : struct attribute_spec.handler. */
5787 : :
5788 : : tree
5789 : 96 : handle_no_dangling_attribute (tree *node, tree name, tree args, int,
5790 : : bool *no_add_attrs)
5791 : : {
5792 : 147 : if (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
5793 : : {
5794 : 3 : error ("%qE attribute argument must be an expression that evaluates "
5795 : : "to true or false", name);
5796 : 3 : *no_add_attrs = true;
5797 : : }
5798 : 93 : else if (!FUNC_OR_METHOD_TYPE_P (*node)
5799 : 51 : && !RECORD_OR_UNION_TYPE_P (*node))
5800 : : {
5801 : 18 : warning (OPT_Wattributes, "%qE attribute ignored", name);
5802 : 18 : *no_add_attrs = true;
5803 : : }
5804 : :
5805 : 96 : return NULL_TREE;
5806 : : }
5807 : :
5808 : : /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
5809 : : thing pointed to by the constant. */
5810 : :
5811 : : tree
5812 : 66868 : make_ptrmem_cst (tree type, tree member)
5813 : : {
5814 : 66868 : tree ptrmem_cst = make_node (PTRMEM_CST);
5815 : 66868 : TREE_TYPE (ptrmem_cst) = type;
5816 : 66868 : PTRMEM_CST_MEMBER (ptrmem_cst) = member;
5817 : 66868 : PTRMEM_CST_LOCATION (ptrmem_cst) = input_location;
5818 : 66868 : return ptrmem_cst;
5819 : : }
5820 : :
5821 : : /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
5822 : : return an existing type if an appropriate type already exists. */
5823 : :
5824 : : tree
5825 : 16243445 : cp_build_type_attribute_variant (tree type, tree attributes)
5826 : : {
5827 : 16243445 : tree new_type;
5828 : :
5829 : 16243445 : new_type = build_type_attribute_variant (type, attributes);
5830 : 16243445 : if (FUNC_OR_METHOD_TYPE_P (new_type))
5831 : 16172848 : gcc_checking_assert (cxx_type_hash_eq (type, new_type));
5832 : :
5833 : : /* Making a new main variant of a class type is broken. */
5834 : 16243445 : gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
5835 : :
5836 : 16243445 : return new_type;
5837 : : }
5838 : :
5839 : : /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
5840 : : Called only after doing all language independent checks. */
5841 : :
5842 : : bool
5843 : 311735194 : cxx_type_hash_eq (const_tree typea, const_tree typeb)
5844 : : {
5845 : 311735194 : gcc_assert (FUNC_OR_METHOD_TYPE_P (typea));
5846 : :
5847 : 311735194 : if (type_memfn_rqual (typea) != type_memfn_rqual (typeb))
5848 : : return false;
5849 : 311723190 : if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb))
5850 : : return false;
5851 : 311722540 : return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
5852 : 623445080 : TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
5853 : : }
5854 : :
5855 : : /* Copy the language-specific type variant modifiers from TYPEB to TYPEA. For
5856 : : C++, these are the exception-specifier and ref-qualifier. */
5857 : :
5858 : : tree
5859 : 25710388 : cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
5860 : : {
5861 : 25710388 : tree type = CONST_CAST_TREE (typea);
5862 : 25710388 : if (FUNC_OR_METHOD_TYPE_P (type))
5863 : 25709483 : type = build_cp_fntype_variant (type, type_memfn_rqual (typeb),
5864 : 25709483 : TYPE_RAISES_EXCEPTIONS (typeb),
5865 : 25709483 : TYPE_HAS_LATE_RETURN_TYPE (typeb));
5866 : 25710388 : return type;
5867 : : }
5868 : :
5869 : : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
5870 : : traversal. Called from walk_tree. */
5871 : :
5872 : : tree
5873 : 16751589366 : cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
5874 : : void *data, hash_set<tree> *pset)
5875 : : {
5876 : 16751589366 : tree t = *tp;
5877 : 16751589366 : enum tree_code code = TREE_CODE (t);
5878 : 16751589366 : tree result;
5879 : :
5880 : : #define WALK_SUBTREE(NODE) \
5881 : : do \
5882 : : { \
5883 : : result = cp_walk_tree (&(NODE), func, data, pset); \
5884 : : if (result) goto out; \
5885 : : } \
5886 : : while (0)
5887 : :
5888 : 16751589366 : if (TYPE_P (t))
5889 : : {
5890 : : /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
5891 : : the argument, so don't look through typedefs, but do walk into
5892 : : template arguments for alias templates (and non-typedefed classes).
5893 : :
5894 : : If *WALK_SUBTREES_P > 1, we're interested in type identity or
5895 : : equivalence, so look through typedefs, ignoring template arguments for
5896 : : alias templates, and walk into template args of classes.
5897 : :
5898 : : See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
5899 : : when that's the behavior the walk_tree_fn wants. */
5900 : 5804215972 : if (*walk_subtrees_p == 1 && typedef_variant_p (t))
5901 : : {
5902 : 16792212 : if (tree ti = TYPE_ALIAS_TEMPLATE_INFO (t))
5903 : 12255523 : WALK_SUBTREE (TI_ARGS (ti));
5904 : 16684963 : *walk_subtrees_p = 0;
5905 : 16684963 : return NULL_TREE;
5906 : : }
5907 : :
5908 : 5787423760 : if (tree ti = TYPE_TEMPLATE_INFO (t))
5909 : 553851922 : WALK_SUBTREE (TI_ARGS (ti));
5910 : : }
5911 : :
5912 : : /* Not one of the easy cases. We must explicitly go through the
5913 : : children. */
5914 : 16734660252 : result = NULL_TREE;
5915 : 16734660252 : switch (code)
5916 : : {
5917 : 1612870881 : case TEMPLATE_TYPE_PARM:
5918 : 1612870881 : if (template_placeholder_p (t))
5919 : 912366 : WALK_SUBTREE (CLASS_PLACEHOLDER_TEMPLATE (t));
5920 : : /* Fall through. */
5921 : 1754249501 : case DEFERRED_PARSE:
5922 : 1754249501 : case TEMPLATE_TEMPLATE_PARM:
5923 : 1754249501 : case BOUND_TEMPLATE_TEMPLATE_PARM:
5924 : 1754249501 : case UNBOUND_CLASS_TEMPLATE:
5925 : 1754249501 : case TEMPLATE_PARM_INDEX:
5926 : 1754249501 : case TYPEOF_TYPE:
5927 : : /* None of these have subtrees other than those already walked
5928 : : above. */
5929 : 1754249501 : *walk_subtrees_p = 0;
5930 : 1754249501 : break;
5931 : :
5932 : 153712748 : case TYPENAME_TYPE:
5933 : 153712748 : WALK_SUBTREE (TYPE_CONTEXT (t));
5934 : 153671581 : WALK_SUBTREE (TYPENAME_TYPE_FULLNAME (t));
5935 : 153668477 : *walk_subtrees_p = 0;
5936 : 153668477 : break;
5937 : :
5938 : 72527304 : case BASELINK:
5939 : 72527304 : if (BASELINK_QUALIFIED_P (t))
5940 : 4962369 : WALK_SUBTREE (BINFO_TYPE (BASELINK_ACCESS_BINFO (t)));
5941 : 72527304 : WALK_SUBTREE (BASELINK_FUNCTIONS (t));
5942 : 72491060 : *walk_subtrees_p = 0;
5943 : 72491060 : break;
5944 : :
5945 : 57818 : case PTRMEM_CST:
5946 : 57818 : WALK_SUBTREE (TREE_TYPE (t));
5947 : 57818 : *walk_subtrees_p = 0;
5948 : 57818 : break;
5949 : :
5950 : 229935668 : case TREE_LIST:
5951 : 229935668 : WALK_SUBTREE (TREE_PURPOSE (t));
5952 : : break;
5953 : :
5954 : 256901499 : case OVERLOAD:
5955 : 256901499 : WALK_SUBTREE (OVL_FUNCTION (t));
5956 : 256901494 : WALK_SUBTREE (OVL_CHAIN (t));
5957 : 256901494 : *walk_subtrees_p = 0;
5958 : 256901494 : break;
5959 : :
5960 : 4441487 : case USING_DECL:
5961 : 4441487 : WALK_SUBTREE (DECL_NAME (t));
5962 : 4441487 : WALK_SUBTREE (USING_DECL_SCOPE (t));
5963 : 4441484 : WALK_SUBTREE (USING_DECL_DECLS (t));
5964 : 4441484 : *walk_subtrees_p = 0;
5965 : 4441484 : break;
5966 : :
5967 : 630859913 : case RECORD_TYPE:
5968 : 630859913 : if (TYPE_PTRMEMFUNC_P (t))
5969 : 5388655 : WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (t));
5970 : : break;
5971 : :
5972 : 116932357 : case TYPE_ARGUMENT_PACK:
5973 : 116932357 : case NONTYPE_ARGUMENT_PACK:
5974 : 116932357 : {
5975 : 116932357 : tree args = ARGUMENT_PACK_ARGS (t);
5976 : 303822384 : for (tree arg : tree_vec_range (args))
5977 : 187080123 : WALK_SUBTREE (arg);
5978 : : }
5979 : 116742261 : break;
5980 : :
5981 : 25411540 : case TYPE_PACK_EXPANSION:
5982 : 25411540 : WALK_SUBTREE (TREE_TYPE (t));
5983 : 25397717 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
5984 : 25397717 : *walk_subtrees_p = 0;
5985 : 25397717 : break;
5986 : :
5987 : 3600427 : case EXPR_PACK_EXPANSION:
5988 : 3600427 : WALK_SUBTREE (TREE_OPERAND (t, 0));
5989 : 3597507 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
5990 : 3597507 : *walk_subtrees_p = 0;
5991 : 3597507 : break;
5992 : :
5993 : 17538 : case PACK_INDEX_TYPE:
5994 : 17538 : case PACK_INDEX_EXPR:
5995 : 17538 : WALK_SUBTREE (PACK_INDEX_PACK (t));
5996 : 17538 : WALK_SUBTREE (PACK_INDEX_INDEX (t));
5997 : 17538 : *walk_subtrees_p = 0;
5998 : 17538 : break;
5999 : :
6000 : 85661684 : case CAST_EXPR:
6001 : 85661684 : case REINTERPRET_CAST_EXPR:
6002 : 85661684 : case STATIC_CAST_EXPR:
6003 : 85661684 : case CONST_CAST_EXPR:
6004 : 85661684 : case DYNAMIC_CAST_EXPR:
6005 : 85661684 : case IMPLICIT_CONV_EXPR:
6006 : 85661684 : case BIT_CAST_EXPR:
6007 : 85661684 : if (TREE_TYPE (t))
6008 : 85661684 : WALK_SUBTREE (TREE_TYPE (t));
6009 : : break;
6010 : :
6011 : 60960691 : case CONSTRUCTOR:
6012 : 60960691 : if (COMPOUND_LITERAL_P (t))
6013 : 5529589 : WALK_SUBTREE (TREE_TYPE (t));
6014 : : break;
6015 : :
6016 : 13084105 : case TRAIT_EXPR:
6017 : 13084105 : WALK_SUBTREE (TRAIT_EXPR_TYPE1 (t));
6018 : 13084093 : WALK_SUBTREE (TRAIT_EXPR_TYPE2 (t));
6019 : 13084093 : *walk_subtrees_p = 0;
6020 : 13084093 : break;
6021 : :
6022 : 1274992 : case TRAIT_TYPE:
6023 : 1274992 : WALK_SUBTREE (TRAIT_TYPE_TYPE1 (t));
6024 : 1274992 : WALK_SUBTREE (TRAIT_TYPE_TYPE2 (t));
6025 : 1274992 : *walk_subtrees_p = 0;
6026 : 1274992 : break;
6027 : :
6028 : 8120714 : case DECLTYPE_TYPE:
6029 : 8120714 : {
6030 : 8120714 : cp_unevaluated u;
6031 : 8120714 : WALK_SUBTREE (DECLTYPE_TYPE_EXPR (t));
6032 : 7989575 : *walk_subtrees_p = 0;
6033 : 7989575 : break;
6034 : 8120714 : }
6035 : :
6036 : 19692314 : case ALIGNOF_EXPR:
6037 : 19692314 : case SIZEOF_EXPR:
6038 : 19692314 : case NOEXCEPT_EXPR:
6039 : 19692314 : {
6040 : 19692314 : cp_unevaluated u;
6041 : 19692314 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6042 : 17126983 : *walk_subtrees_p = 0;
6043 : 17126983 : break;
6044 : 19692314 : }
6045 : :
6046 : 4987466 : case REQUIRES_EXPR:
6047 : 4987466 : {
6048 : 4987466 : cp_unevaluated u;
6049 : 8554394 : for (tree parm = REQUIRES_EXPR_PARMS (t); parm; parm = DECL_CHAIN (parm))
6050 : : /* Walk the types of each parameter, but not the parameter itself,
6051 : : since doing so would cause false positives in the unexpanded pack
6052 : : checker if the requires-expr introduces a function parameter pack,
6053 : : e.g. requires (Ts... ts) { }. */
6054 : 3567024 : WALK_SUBTREE (TREE_TYPE (parm));
6055 : 4987370 : WALK_SUBTREE (REQUIRES_EXPR_REQS (t));
6056 : 4983449 : *walk_subtrees_p = 0;
6057 : 4983449 : break;
6058 : 4987466 : }
6059 : :
6060 : 74586706 : case DECL_EXPR:
6061 : : /* User variables should be mentioned in BIND_EXPR_VARS
6062 : : and their initializers and sizes walked when walking
6063 : : the containing BIND_EXPR. Compiler temporaries are
6064 : : handled here. And also normal variables in templates,
6065 : : since do_poplevel doesn't build a BIND_EXPR then. */
6066 : 74586706 : if (VAR_P (TREE_OPERAND (t, 0))
6067 : 74586706 : && (processing_template_decl
6068 : 67640482 : || (DECL_ARTIFICIAL (TREE_OPERAND (t, 0))
6069 : 4396844 : && !TREE_STATIC (TREE_OPERAND (t, 0)))))
6070 : : {
6071 : 8801833 : tree decl = TREE_OPERAND (t, 0);
6072 : 8801833 : WALK_SUBTREE (TREE_TYPE (decl));
6073 : 8801833 : WALK_SUBTREE (DECL_INITIAL (decl));
6074 : 8801803 : WALK_SUBTREE (DECL_SIZE (decl));
6075 : 8801803 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
6076 : : }
6077 : : break;
6078 : :
6079 : 1216119 : case LAMBDA_EXPR:
6080 : : /* Don't walk into the body of the lambda, but the capture initializers
6081 : : are part of the enclosing context. */
6082 : 2616781 : for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (t); cap;
6083 : 1400662 : cap = TREE_CHAIN (cap))
6084 : 1400662 : WALK_SUBTREE (TREE_VALUE (cap));
6085 : : break;
6086 : :
6087 : 6649 : case CO_YIELD_EXPR:
6088 : 6649 : if (TREE_OPERAND (t, 1))
6089 : : /* Operand 1 is the tree for the relevant co_await which has any
6090 : : interesting sub-trees. */
6091 : 595 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6092 : : break;
6093 : :
6094 : 26799 : case CO_AWAIT_EXPR:
6095 : 26799 : if (TREE_OPERAND (t, 1))
6096 : : /* Operand 1 is frame variable. */
6097 : 26611 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6098 : 26799 : if (TREE_OPERAND (t, 2))
6099 : : /* Operand 2 has the initialiser, and we need to walk any subtrees
6100 : : there. */
6101 : 5363 : WALK_SUBTREE (TREE_OPERAND (t, 2));
6102 : : break;
6103 : :
6104 : 881 : case CO_RETURN_EXPR:
6105 : 881 : if (TREE_OPERAND (t, 0))
6106 : : {
6107 : 698 : if (VOID_TYPE_P (TREE_OPERAND (t, 0)))
6108 : : /* For void expressions, operand 1 is a trivial call, and any
6109 : : interesting subtrees will be part of operand 0. */
6110 : 0 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6111 : 698 : else if (TREE_OPERAND (t, 1))
6112 : : /* Interesting sub-trees will be in the return_value () call
6113 : : arguments. */
6114 : 656 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6115 : : }
6116 : : break;
6117 : :
6118 : 323267 : case STATIC_ASSERT:
6119 : 323267 : WALK_SUBTREE (STATIC_ASSERT_CONDITION (t));
6120 : 323267 : WALK_SUBTREE (STATIC_ASSERT_MESSAGE (t));
6121 : : break;
6122 : :
6123 : 564875920 : case INTEGER_TYPE:
6124 : : /* Removed from walk_type_fields in r119481. */
6125 : 564875920 : WALK_SUBTREE (TYPE_MIN_VALUE (t));
6126 : 564875920 : WALK_SUBTREE (TYPE_MAX_VALUE (t));
6127 : : break;
6128 : :
6129 : : default:
6130 : : return NULL_TREE;
6131 : : }
6132 : :
6133 : : /* We didn't find what we were looking for. */
6134 : : out:
6135 : : return result;
6136 : :
6137 : : #undef WALK_SUBTREE
6138 : : }
6139 : :
6140 : : /* Like save_expr, but for C++. */
6141 : :
6142 : : tree
6143 : 335311 : cp_save_expr (tree expr)
6144 : : {
6145 : : /* There is no reason to create a SAVE_EXPR within a template; if
6146 : : needed, we can create the SAVE_EXPR when instantiating the
6147 : : template. Furthermore, the middle-end cannot handle C++-specific
6148 : : tree codes. */
6149 : 335311 : if (processing_template_decl)
6150 : : return expr;
6151 : :
6152 : : /* TARGET_EXPRs are only expanded once. */
6153 : 258398 : if (TREE_CODE (expr) == TARGET_EXPR)
6154 : : return expr;
6155 : :
6156 : 258398 : return save_expr (expr);
6157 : : }
6158 : :
6159 : : /* Initialize tree.cc. */
6160 : :
6161 : : void
6162 : 96838 : init_tree (void)
6163 : : {
6164 : 96838 : list_hash_table = hash_table<list_hasher>::create_ggc (61);
6165 : 96838 : }
6166 : :
6167 : : /* Returns the kind of special function that DECL (a FUNCTION_DECL)
6168 : : is. Note that sfk_none is zero, so this function can be used as a
6169 : : predicate to test whether or not DECL is a special function. */
6170 : :
6171 : : special_function_kind
6172 : 223697794 : special_function_p (const_tree decl)
6173 : : {
6174 : : /* Rather than doing all this stuff with magic names, we should
6175 : : probably have a field of type `special_function_kind' in
6176 : : DECL_LANG_SPECIFIC. */
6177 : 447395588 : if (DECL_INHERITED_CTOR (decl))
6178 : : return sfk_inheriting_constructor;
6179 : 446583500 : if (DECL_COPY_CONSTRUCTOR_P (decl))
6180 : : return sfk_copy_constructor;
6181 : 420487954 : if (DECL_MOVE_CONSTRUCTOR_P (decl))
6182 : : return sfk_move_constructor;
6183 : 403914196 : if (DECL_CONSTRUCTOR_P (decl))
6184 : : return sfk_constructor;
6185 : 177836346 : if (DECL_ASSIGNMENT_OPERATOR_P (decl)
6186 : 177836346 : && DECL_OVERLOADED_OPERATOR_IS (decl, NOP_EXPR))
6187 : : {
6188 : 11037941 : if (copy_fn_p (decl))
6189 : : return sfk_copy_assignment;
6190 : 4313897 : if (move_fn_p (decl))
6191 : : return sfk_move_assignment;
6192 : : }
6193 : 167292302 : if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
6194 : : return sfk_destructor;
6195 : 130074087 : if (DECL_COMPLETE_DESTRUCTOR_P (decl))
6196 : : return sfk_complete_destructor;
6197 : 111214589 : if (DECL_BASE_DESTRUCTOR_P (decl))
6198 : : return sfk_base_destructor;
6199 : 108903587 : if (DECL_DELETING_DESTRUCTOR_P (decl))
6200 : : return sfk_deleting_destructor;
6201 : 97183204 : if (DECL_CONV_FN_P (decl))
6202 : : return sfk_conversion;
6203 : 96317091 : if (deduction_guide_p (decl))
6204 : : return sfk_deduction_guide;
6205 : 96277191 : if (DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) >= OVL_OP_EQ_EXPR
6206 : 96277191 : && DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) <= OVL_OP_SPACESHIP_EXPR)
6207 : 3894820 : return sfk_comparison;
6208 : :
6209 : : return sfk_none;
6210 : : }
6211 : :
6212 : : /* As above, but only if DECL is a special member function as per 11.3.3
6213 : : [special]: default/copy/move ctor, copy/move assignment, or destructor. */
6214 : :
6215 : : special_function_kind
6216 : 87596905 : special_memfn_p (const_tree decl)
6217 : : {
6218 : 87596905 : switch (special_function_kind sfk = special_function_p (decl))
6219 : : {
6220 : 9826453 : case sfk_constructor:
6221 : 9826453 : if (!default_ctor_p (decl))
6222 : : break;
6223 : : gcc_fallthrough();
6224 : : case sfk_copy_constructor:
6225 : : case sfk_copy_assignment:
6226 : : case sfk_move_assignment:
6227 : : case sfk_move_constructor:
6228 : : case sfk_destructor:
6229 : : return sfk;
6230 : :
6231 : : default:
6232 : : break;
6233 : : }
6234 : : return sfk_none;
6235 : : }
6236 : :
6237 : : /* Returns nonzero if TYPE is a character type, including wchar_t. */
6238 : :
6239 : : int
6240 : 9950900 : char_type_p (tree type)
6241 : : {
6242 : 9950900 : return (same_type_p (type, char_type_node)
6243 : 8842142 : || same_type_p (type, unsigned_char_type_node)
6244 : 8781420 : || same_type_p (type, signed_char_type_node)
6245 : 8780846 : || same_type_p (type, char8_type_node)
6246 : 8780754 : || same_type_p (type, char16_type_node)
6247 : 8780246 : || same_type_p (type, char32_type_node)
6248 : 18685345 : || same_type_p (type, wchar_type_node));
6249 : : }
6250 : :
6251 : : /* Returns the kind of linkage associated with the indicated DECL. The
6252 : : value returned is as specified by the language standard; it is
6253 : : independent of implementation details regarding template
6254 : : instantiation, etc. For example, it is possible that a declaration
6255 : : to which this function assigns external linkage would not show up
6256 : : as a global symbol when you run `nm' on the resulting object file. */
6257 : :
6258 : : linkage_kind
6259 : 433257897 : decl_linkage (tree decl)
6260 : : {
6261 : : /* This function doesn't attempt to calculate the linkage from first
6262 : : principles as given in [basic.link]. Instead, it makes use of
6263 : : the fact that we have already set TREE_PUBLIC appropriately, and
6264 : : then handles a few special cases. Ideally, we would calculate
6265 : : linkage first, and then transform that into a concrete
6266 : : implementation. */
6267 : :
6268 : : /* An explicit type alias has no linkage. Nor do the built-in declarations
6269 : : of 'int' and such. */
6270 : 472057838 : if (TREE_CODE (decl) == TYPE_DECL
6271 : 472057838 : && !DECL_IMPLICIT_TYPEDEF_P (decl))
6272 : : {
6273 : : /* But this could be a typedef name for linkage purposes, in which
6274 : : case we're interested in the linkage of the main decl. */
6275 : 957645 : if (decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl)))
6276 : : /* Likewise for the injected-class-name. */
6277 : 957645 : || DECL_SELF_REFERENCE_P (decl))
6278 : 32632 : decl = TYPE_MAIN_DECL (TREE_TYPE (decl));
6279 : : else
6280 : : return lk_none;
6281 : : }
6282 : :
6283 : : /* Namespace-scope entities with no name usually have no linkage. */
6284 : 471132825 : if (NAMESPACE_SCOPE_P (decl)
6285 : 900089152 : && (!DECL_NAME (decl) || IDENTIFIER_ANON_P (DECL_NAME (decl))))
6286 : : {
6287 : 3721922 : if (TREE_CODE (decl) == TYPE_DECL && !TYPE_UNNAMED_P (TREE_TYPE (decl)))
6288 : : /* This entity has a name for linkage purposes. */;
6289 : 3712380 : else if (DECL_DECOMPOSITION_P (decl) && DECL_DECOMP_IS_BASE (decl))
6290 : : /* Namespace-scope structured bindings can have linkage. */;
6291 : 3712298 : else if (TREE_CODE (decl) == NAMESPACE_DECL && cxx_dialect >= cxx11)
6292 : : /* An anonymous namespace has internal linkage since C++11. */
6293 : : return lk_internal;
6294 : : else
6295 : : return lk_none;
6296 : : }
6297 : :
6298 : : /* Fields and parameters have no linkage. */
6299 : 467420527 : if (TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == PARM_DECL)
6300 : : return lk_none;
6301 : :
6302 : : /* Things in block scope do not have linkage. */
6303 : 419765848 : if (decl_function_context (decl))
6304 : : return lk_none;
6305 : :
6306 : : /* Things in class scope have the linkage of their owning class. */
6307 : 416390806 : if (tree ctype = DECL_CLASS_CONTEXT (decl))
6308 : 38799941 : return decl_linkage (TYPE_NAME (ctype));
6309 : :
6310 : : /* Anonymous namespaces don't provide internal linkage in C++98,
6311 : : but otherwise consider such declarations to be internal. */
6312 : 377590865 : if (cxx_dialect >= cxx11 && decl_internal_context_p (decl))
6313 : : return lk_internal;
6314 : :
6315 : : /* Templates don't properly propagate TREE_PUBLIC, consider the
6316 : : template result instead. Any template that isn't a variable
6317 : : or function must be external linkage by this point. */
6318 : 377414301 : if (TREE_CODE (decl) == TEMPLATE_DECL)
6319 : : {
6320 : 690125 : decl = DECL_TEMPLATE_RESULT (decl);
6321 : 690125 : if (!decl || !VAR_OR_FUNCTION_DECL_P (decl))
6322 : : return lk_external;
6323 : : }
6324 : :
6325 : : /* Things that are TREE_PUBLIC have external linkage. */
6326 : 377127037 : if (TREE_PUBLIC (decl))
6327 : : return lk_external;
6328 : :
6329 : : /* All types have external linkage in C++98, since anonymous namespaces
6330 : : didn't explicitly confer internal linkage. */
6331 : 82510007 : if (TREE_CODE (decl) == TYPE_DECL && cxx_dialect < cxx11)
6332 : : return lk_external;
6333 : :
6334 : : /* Variables or function decls not marked as TREE_PUBLIC might still
6335 : : be external linkage, such as for template instantiations on targets
6336 : : without weak symbols, decls referring to internal-linkage entities,
6337 : : or compiler-generated entities; in such cases, decls really meant to
6338 : : have internal linkage will have DECL_THIS_STATIC set. */
6339 : 82510003 : if (VAR_OR_FUNCTION_DECL_P (decl) && !DECL_THIS_STATIC (decl))
6340 : : return lk_external;
6341 : :
6342 : : /* Everything else has internal linkage. */
6343 : : return lk_internal;
6344 : : }
6345 : :
6346 : : /* Returns the storage duration of the object or reference associated with
6347 : : the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
6348 : :
6349 : : duration_kind
6350 : 49633232 : decl_storage_duration (tree decl)
6351 : : {
6352 : 49633232 : if (TREE_CODE (decl) == PARM_DECL)
6353 : : return dk_auto;
6354 : 49633232 : if (TREE_CODE (decl) == FUNCTION_DECL)
6355 : : return dk_static;
6356 : 49633232 : gcc_assert (VAR_P (decl));
6357 : 49633232 : if (!TREE_STATIC (decl)
6358 : 49633232 : && !DECL_EXTERNAL (decl))
6359 : : return dk_auto;
6360 : 25635422 : if (CP_DECL_THREAD_LOCAL_P (decl))
6361 : 21770 : return dk_thread;
6362 : : return dk_static;
6363 : : }
6364 : :
6365 : : /* EXP is an expression that we want to pre-evaluate. Returns (in
6366 : : *INITP) an expression that will perform the pre-evaluation. The
6367 : : value returned by this function is a side-effect free expression
6368 : : equivalent to the pre-evaluated expression. Callers must ensure
6369 : : that *INITP is evaluated before EXP.
6370 : :
6371 : : Note that if EXPR is a glvalue, the return value is a glvalue denoting the
6372 : : same address; this function does not guard against modification of the
6373 : : stored value like save_expr or get_target_expr do. */
6374 : :
6375 : : tree
6376 : 4859786 : stabilize_expr (tree exp, tree* initp)
6377 : : {
6378 : 4859786 : tree init_expr;
6379 : :
6380 : 4859786 : if (!TREE_SIDE_EFFECTS (exp))
6381 : : init_expr = NULL_TREE;
6382 : 597811 : else if (VOID_TYPE_P (TREE_TYPE (exp)))
6383 : : {
6384 : 0 : init_expr = exp;
6385 : 0 : exp = void_node;
6386 : : }
6387 : : /* There are no expressions with REFERENCE_TYPE, but there can be call
6388 : : arguments with such a type; just treat it as a pointer. */
6389 : 597811 : else if (TYPE_REF_P (TREE_TYPE (exp))
6390 : 597677 : || SCALAR_TYPE_P (TREE_TYPE (exp))
6391 : 597857 : || !glvalue_p (exp))
6392 : : {
6393 : 597805 : init_expr = get_target_expr (exp);
6394 : 597805 : exp = TARGET_EXPR_SLOT (init_expr);
6395 : 597805 : if (CLASS_TYPE_P (TREE_TYPE (exp)))
6396 : 9 : exp = move (exp);
6397 : : else
6398 : 597796 : exp = rvalue (exp);
6399 : : }
6400 : : else
6401 : : {
6402 : 6 : bool xval = !lvalue_p (exp);
6403 : 6 : exp = cp_build_addr_expr (exp, tf_warning_or_error);
6404 : 6 : init_expr = get_target_expr (exp);
6405 : 6 : exp = TARGET_EXPR_SLOT (init_expr);
6406 : 6 : exp = cp_build_fold_indirect_ref (exp);
6407 : 6 : if (xval)
6408 : 0 : exp = move (exp);
6409 : : }
6410 : 4859786 : *initp = init_expr;
6411 : :
6412 : 4859786 : gcc_assert (!TREE_SIDE_EFFECTS (exp) || TREE_THIS_VOLATILE (exp));
6413 : 4859786 : return exp;
6414 : : }
6415 : :
6416 : : /* Add NEW_EXPR, an expression whose value we don't care about, after the
6417 : : similar expression ORIG. */
6418 : :
6419 : : tree
6420 : 636230 : add_stmt_to_compound (tree orig, tree new_expr)
6421 : : {
6422 : 636230 : if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
6423 : : return orig;
6424 : 321704 : if (!orig || !TREE_SIDE_EFFECTS (orig))
6425 : : return new_expr;
6426 : 12756 : return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
6427 : : }
6428 : :
6429 : : /* Like stabilize_expr, but for a call whose arguments we want to
6430 : : pre-evaluate. CALL is modified in place to use the pre-evaluated
6431 : : arguments, while, upon return, *INITP contains an expression to
6432 : : compute the arguments. */
6433 : :
6434 : : void
6435 : 310303 : stabilize_call (tree call, tree *initp)
6436 : : {
6437 : 310303 : tree inits = NULL_TREE;
6438 : 310303 : int i;
6439 : 310303 : int nargs = call_expr_nargs (call);
6440 : :
6441 : 310303 : if (call == error_mark_node || processing_template_decl)
6442 : : {
6443 : 31 : *initp = NULL_TREE;
6444 : 31 : return;
6445 : : }
6446 : :
6447 : 310272 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
6448 : :
6449 : 930897 : for (i = 0; i < nargs; i++)
6450 : : {
6451 : 620625 : tree init;
6452 : 620625 : CALL_EXPR_ARG (call, i) =
6453 : 620625 : stabilize_expr (CALL_EXPR_ARG (call, i), &init);
6454 : 620625 : inits = add_stmt_to_compound (inits, init);
6455 : : }
6456 : :
6457 : 310272 : *initp = inits;
6458 : : }
6459 : :
6460 : : /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
6461 : : to pre-evaluate. CALL is modified in place to use the pre-evaluated
6462 : : arguments, while, upon return, *INITP contains an expression to
6463 : : compute the arguments. */
6464 : :
6465 : : static void
6466 : 0 : stabilize_aggr_init (tree call, tree *initp)
6467 : : {
6468 : 0 : tree inits = NULL_TREE;
6469 : 0 : int i;
6470 : 0 : int nargs = aggr_init_expr_nargs (call);
6471 : :
6472 : 0 : if (call == error_mark_node)
6473 : : return;
6474 : :
6475 : 0 : gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
6476 : :
6477 : 0 : for (i = 0; i < nargs; i++)
6478 : : {
6479 : 0 : tree init;
6480 : 0 : AGGR_INIT_EXPR_ARG (call, i) =
6481 : 0 : stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
6482 : 0 : inits = add_stmt_to_compound (inits, init);
6483 : : }
6484 : :
6485 : 0 : *initp = inits;
6486 : : }
6487 : :
6488 : : /* Like stabilize_expr, but for an initialization.
6489 : :
6490 : : If the initialization is for an object of class type, this function
6491 : : takes care not to introduce additional temporaries.
6492 : :
6493 : : Returns TRUE iff the expression was successfully pre-evaluated,
6494 : : i.e., if INIT is now side-effect free, except for, possibly, a
6495 : : single call to a constructor. */
6496 : :
6497 : : bool
6498 : 0 : stabilize_init (tree init, tree *initp)
6499 : : {
6500 : 0 : tree t = init;
6501 : :
6502 : 0 : *initp = NULL_TREE;
6503 : :
6504 : 0 : if (t == error_mark_node || processing_template_decl)
6505 : : return true;
6506 : :
6507 : 0 : if (TREE_CODE (t) == INIT_EXPR)
6508 : 0 : t = TREE_OPERAND (t, 1);
6509 : 0 : if (TREE_CODE (t) == TARGET_EXPR)
6510 : 0 : t = TARGET_EXPR_INITIAL (t);
6511 : :
6512 : : /* If the RHS can be stabilized without breaking copy elision, stabilize
6513 : : it. We specifically don't stabilize class prvalues here because that
6514 : : would mean an extra copy, but they might be stabilized below. */
6515 : 0 : if (TREE_CODE (init) == INIT_EXPR
6516 : 0 : && TREE_CODE (t) != CONSTRUCTOR
6517 : 0 : && TREE_CODE (t) != AGGR_INIT_EXPR
6518 : 0 : && (SCALAR_TYPE_P (TREE_TYPE (t))
6519 : 0 : || glvalue_p (t)))
6520 : : {
6521 : 0 : TREE_OPERAND (init, 1) = stabilize_expr (t, initp);
6522 : 0 : return true;
6523 : : }
6524 : :
6525 : 0 : if (TREE_CODE (t) == COMPOUND_EXPR
6526 : 0 : && TREE_CODE (init) == INIT_EXPR)
6527 : : {
6528 : 0 : tree last = expr_last (t);
6529 : : /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */
6530 : 0 : if (!TREE_SIDE_EFFECTS (last))
6531 : : {
6532 : 0 : *initp = t;
6533 : 0 : TREE_OPERAND (init, 1) = last;
6534 : 0 : return true;
6535 : : }
6536 : : }
6537 : :
6538 : 0 : if (TREE_CODE (t) == CONSTRUCTOR)
6539 : : {
6540 : : /* Aggregate initialization: stabilize each of the field
6541 : : initializers. */
6542 : 0 : unsigned i;
6543 : 0 : constructor_elt *ce;
6544 : 0 : bool good = true;
6545 : 0 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
6546 : 0 : for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
6547 : : {
6548 : 0 : tree type = TREE_TYPE (ce->value);
6549 : 0 : tree subinit;
6550 : 0 : if (TYPE_REF_P (type)
6551 : 0 : || SCALAR_TYPE_P (type))
6552 : 0 : ce->value = stabilize_expr (ce->value, &subinit);
6553 : 0 : else if (!stabilize_init (ce->value, &subinit))
6554 : 0 : good = false;
6555 : 0 : *initp = add_stmt_to_compound (*initp, subinit);
6556 : : }
6557 : : return good;
6558 : : }
6559 : :
6560 : 0 : if (TREE_CODE (t) == CALL_EXPR)
6561 : : {
6562 : 0 : stabilize_call (t, initp);
6563 : 0 : return true;
6564 : : }
6565 : :
6566 : 0 : if (TREE_CODE (t) == AGGR_INIT_EXPR)
6567 : : {
6568 : 0 : stabilize_aggr_init (t, initp);
6569 : 0 : return true;
6570 : : }
6571 : :
6572 : : /* The initialization is being performed via a bitwise copy -- and
6573 : : the item copied may have side effects. */
6574 : 0 : return !TREE_SIDE_EFFECTS (init);
6575 : : }
6576 : :
6577 : : /* Returns true if a cast to TYPE may appear in an integral constant
6578 : : expression. */
6579 : :
6580 : : bool
6581 : 87113469 : cast_valid_in_integral_constant_expression_p (tree type)
6582 : : {
6583 : 87113469 : return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
6584 : 64170883 : || cxx_dialect >= cxx11
6585 : 471116 : || dependent_type_p (type)
6586 : 87489650 : || type == error_mark_node);
6587 : : }
6588 : :
6589 : : /* Return true if we need to fix linkage information of DECL. */
6590 : :
6591 : : static bool
6592 : 72740 : cp_fix_function_decl_p (tree decl)
6593 : : {
6594 : : /* Skip if DECL is not externally visible. */
6595 : 72740 : if (!TREE_PUBLIC (decl))
6596 : : return false;
6597 : :
6598 : : /* We need to fix DECL if it a appears to be exported but with no
6599 : : function body. Thunks do not have CFGs and we may need to
6600 : : handle them specially later. */
6601 : 70549 : if (!gimple_has_body_p (decl)
6602 : 26418 : && !DECL_THUNK_P (decl)
6603 : 96585 : && !DECL_EXTERNAL (decl))
6604 : : {
6605 : 12431 : struct cgraph_node *node = cgraph_node::get (decl);
6606 : :
6607 : : /* Don't fix same_body aliases. Although they don't have their own
6608 : : CFG, they share it with what they alias to. */
6609 : 12431 : if (!node || !node->alias || !node->num_references ())
6610 : : return true;
6611 : : }
6612 : :
6613 : : return false;
6614 : : }
6615 : :
6616 : : /* Clean the C++ specific parts of the tree T. */
6617 : :
6618 : : void
6619 : 706677 : cp_free_lang_data (tree t)
6620 : : {
6621 : 706677 : if (FUNC_OR_METHOD_TYPE_P (t))
6622 : : {
6623 : : /* Default args are not interesting anymore. */
6624 : 57172 : tree argtypes = TYPE_ARG_TYPES (t);
6625 : 206076 : while (argtypes)
6626 : : {
6627 : 148904 : TREE_PURPOSE (argtypes) = 0;
6628 : 148904 : argtypes = TREE_CHAIN (argtypes);
6629 : : }
6630 : : }
6631 : 649505 : else if (TREE_CODE (t) == FUNCTION_DECL
6632 : 649505 : && cp_fix_function_decl_p (t))
6633 : : {
6634 : : /* If T is used in this translation unit at all, the definition
6635 : : must exist somewhere else since we have decided to not emit it
6636 : : in this TU. So make it an external reference. */
6637 : 6526 : DECL_EXTERNAL (t) = 1;
6638 : 6526 : TREE_STATIC (t) = 0;
6639 : : }
6640 : 706677 : if (TREE_CODE (t) == NAMESPACE_DECL)
6641 : : /* We do not need the leftover chaining of namespaces from the
6642 : : binding level. */
6643 : 1622 : DECL_CHAIN (t) = NULL_TREE;
6644 : 706677 : }
6645 : :
6646 : : /* Stub for c-common. Please keep in sync with c-decl.cc.
6647 : : FIXME: If address space support is target specific, then this
6648 : : should be a C target hook. But currently this is not possible,
6649 : : because this function is called via REGISTER_TARGET_PRAGMAS. */
6650 : : void
6651 : 193676 : c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
6652 : : {
6653 : 193676 : }
6654 : :
6655 : : /* Return the number of operands in T that we care about for things like
6656 : : mangling. */
6657 : :
6658 : : int
6659 : 489907458 : cp_tree_operand_length (const_tree t)
6660 : : {
6661 : 489907458 : enum tree_code code = TREE_CODE (t);
6662 : :
6663 : 489907458 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
6664 : 56040622 : return VL_EXP_OPERAND_LENGTH (t);
6665 : :
6666 : 433866836 : return cp_tree_code_length (code);
6667 : : }
6668 : :
6669 : : /* Like cp_tree_operand_length, but takes a tree_code CODE. */
6670 : :
6671 : : int
6672 : 438121127 : cp_tree_code_length (enum tree_code code)
6673 : : {
6674 : 438121127 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
6675 : :
6676 : 438121127 : switch (code)
6677 : : {
6678 : : case PREINCREMENT_EXPR:
6679 : : case PREDECREMENT_EXPR:
6680 : : case POSTINCREMENT_EXPR:
6681 : : case POSTDECREMENT_EXPR:
6682 : : return 1;
6683 : :
6684 : 430934 : case ARRAY_REF:
6685 : 430934 : return 2;
6686 : :
6687 : : case EXPR_PACK_EXPANSION:
6688 : : return 1;
6689 : :
6690 : 435474270 : default:
6691 : 435474270 : return TREE_CODE_LENGTH (code);
6692 : : }
6693 : : }
6694 : :
6695 : : /* Implement -Wzero_as_null_pointer_constant. Return true if the
6696 : : conditions for the warning hold, false otherwise. */
6697 : : bool
6698 : 5985194 : maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
6699 : : {
6700 : 5985194 : if (c_inhibit_evaluation_warnings == 0
6701 : 11306497 : && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
6702 : : {
6703 : 2124924 : warning_at (loc, OPT_Wzero_as_null_pointer_constant,
6704 : : "zero as null pointer constant");
6705 : 2124924 : return true;
6706 : : }
6707 : : return false;
6708 : : }
6709 : :
6710 : : /* FNDECL is a function declaration whose type may have been altered by
6711 : : adding extra parameters such as this, in-charge, or VTT. When this
6712 : : takes place, the positional arguments supplied by the user (as in the
6713 : : 'format' attribute arguments) may refer to the wrong argument. This
6714 : : function returns an integer indicating how many arguments should be
6715 : : skipped. */
6716 : :
6717 : : int
6718 : 36783847 : maybe_adjust_arg_pos_for_attribute (const_tree fndecl)
6719 : : {
6720 : 36783847 : if (!fndecl)
6721 : : return 0;
6722 : 7062333 : int n = num_artificial_parms_for (fndecl);
6723 : : /* The manual states that it's the user's responsibility to account
6724 : : for the implicit this parameter. */
6725 : 7062333 : return n > 0 ? n - 1 : 0;
6726 : : }
6727 : :
6728 : :
6729 : : /* Release memory we no longer need after parsing. */
6730 : : void
6731 : 95173 : cp_tree_c_finish_parsing ()
6732 : : {
6733 : 95173 : if (previous_class_level)
6734 : 67587 : invalidate_class_lookup_cache ();
6735 : 95173 : deleted_copy_types = NULL;
6736 : 95173 : }
6737 : :
6738 : : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
6739 : : /* Complain that some language-specific thing hanging off a tree
6740 : : node has been accessed improperly. */
6741 : :
6742 : : void
6743 : 0 : lang_check_failed (const char* file, int line, const char* function)
6744 : : {
6745 : 0 : internal_error ("%<lang_*%> check: failed in %s, at %s:%d",
6746 : : function, trim_filename (file), line);
6747 : : }
6748 : : #endif /* ENABLE_TREE_CHECKING */
6749 : :
6750 : : #if CHECKING_P
6751 : :
6752 : : namespace selftest {
6753 : :
6754 : : /* Verify that lvalue_kind () works, for various expressions,
6755 : : and that location wrappers don't affect the results. */
6756 : :
6757 : : static void
6758 : 1 : test_lvalue_kind ()
6759 : : {
6760 : 1 : location_t loc = BUILTINS_LOCATION;
6761 : :
6762 : : /* Verify constants and parameters, without and with
6763 : : location wrappers. */
6764 : 1 : tree int_cst = build_int_cst (integer_type_node, 42);
6765 : 1 : ASSERT_EQ (clk_none, lvalue_kind (int_cst));
6766 : :
6767 : 1 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
6768 : 1 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
6769 : 1 : ASSERT_EQ (clk_none, lvalue_kind (wrapped_int_cst));
6770 : :
6771 : 1 : tree string_lit = build_string (4, "foo");
6772 : 1 : TREE_TYPE (string_lit) = char_array_type_node;
6773 : 1 : string_lit = fix_string_type (string_lit);
6774 : 1 : ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (string_lit));
6775 : :
6776 : 1 : tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
6777 : 1 : ASSERT_TRUE (location_wrapper_p (wrapped_string_lit));
6778 : 1 : ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (wrapped_string_lit));
6779 : :
6780 : 1 : tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL,
6781 : : get_identifier ("some_parm"),
6782 : : integer_type_node);
6783 : 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (parm));
6784 : :
6785 : 1 : tree wrapped_parm = maybe_wrap_with_location (parm, loc);
6786 : 1 : ASSERT_TRUE (location_wrapper_p (wrapped_parm));
6787 : 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_parm));
6788 : :
6789 : : /* Verify that lvalue_kind of std::move on a parm isn't
6790 : : affected by location wrappers. */
6791 : 1 : tree rvalue_ref_of_parm = move (parm);
6792 : 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm));
6793 : 1 : tree rvalue_ref_of_wrapped_parm = move (wrapped_parm);
6794 : 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm));
6795 : :
6796 : : /* Verify lvalue_p. */
6797 : 1 : ASSERT_FALSE (lvalue_p (int_cst));
6798 : 1 : ASSERT_FALSE (lvalue_p (wrapped_int_cst));
6799 : 1 : ASSERT_TRUE (lvalue_p (parm));
6800 : 1 : ASSERT_TRUE (lvalue_p (wrapped_parm));
6801 : 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm));
6802 : 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm));
6803 : 1 : }
6804 : :
6805 : : /* Run all of the selftests within this file. */
6806 : :
6807 : : void
6808 : 1 : cp_tree_cc_tests ()
6809 : : {
6810 : 1 : test_lvalue_kind ();
6811 : 1 : }
6812 : :
6813 : : } // namespace selftest
6814 : :
6815 : : #endif /* #if CHECKING_P */
6816 : :
6817 : :
6818 : : #include "gt-cp-tree.h"
|