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 : 1869102910 : lvalue_kind (const_tree ref)
57 : : {
58 : 2021235211 : cp_lvalue_kind op1_lvalue_kind = clk_none;
59 : 2021235211 : 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 : 2021235211 : if (REFERENCE_REF_P (ref))
66 : 142013430 : return lvalue_kind (TREE_OPERAND (ref, 0));
67 : :
68 : 1879221781 : if (TREE_TYPE (ref)
69 : 1879221781 : && TYPE_REF_P (TREE_TYPE (ref)))
70 : : {
71 : : /* unnamed rvalue references are rvalues */
72 : 144658080 : 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 : 174474402 : && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
78 : : {
79 : 29815942 : op1_lvalue_kind = clk_rvalueref;
80 : 29815942 : if (implicit_rvalue_p (ref))
81 : 5255016 : op1_lvalue_kind |= clk_implicit_rval;
82 : 29815942 : return op1_lvalue_kind;
83 : : }
84 : :
85 : : /* lvalue references and named rvalue references are lvalues. */
86 : : return clk_ordinary;
87 : : }
88 : :
89 : 1734563701 : if (ref == current_class_ptr)
90 : : return clk_none;
91 : :
92 : : /* Expressions with cv void type are prvalues. */
93 : 1732772947 : if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
94 : : return clk_none;
95 : :
96 : 1732406871 : 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 : 233239919 : case PREINCREMENT_EXPR:
104 : 233239919 : case PREDECREMENT_EXPR:
105 : 233239919 : case TRY_CATCH_EXPR:
106 : 233239919 : case REALPART_EXPR:
107 : 233239919 : case IMAGPART_EXPR:
108 : 233239919 : case VIEW_CONVERT_EXPR:
109 : 233239919 : 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 : 233239919 : if (op1_lvalue_kind == clk_class
115 : 233239933 : && !(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 : 2877008 : case ARRAY_REF:
122 : 2877008 : {
123 : 2877008 : tree op1 = TREE_OPERAND (ref, 0);
124 : 2877008 : if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
125 : : {
126 : 2408006 : op1_lvalue_kind = lvalue_kind (op1);
127 : 2408006 : 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 : 1020 : op1_lvalue_kind = clk_rvalueref;
131 : 2408006 : 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 : 129887509 : case COMPONENT_REF:
153 : 129887509 : 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 : 129887482 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
165 : 129887482 : 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 : 129697271 : if (!op1_lvalue_kind)
172 : : ;
173 : 129887458 : 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 : 129887367 : else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
179 : : /* This can be IDENTIFIER_NODE in a template. */;
180 : 123641112 : 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 : 7760722 : op1_lvalue_kind &= ~clk_ordinary;
185 : : /* The lvalue is for a bitfield. */
186 : 7760722 : op1_lvalue_kind |= clk_bitfield;
187 : : }
188 : 115880390 : else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
189 : 15180 : 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 : 1303171 : 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 : 1303171 : if (! TREE_STATIC (ref))
205 : : return clk_none;
206 : : /* FALLTHRU */
207 : 188215515 : case VAR_DECL:
208 : 188215515 : if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
209 : 622567 : return lvalue_kind (DECL_VALUE_EXPR (CONST_CAST_TREE (ref)));
210 : :
211 : 254983624 : if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
212 : 11919496 : && DECL_LANG_SPECIFIC (ref)
213 : 188178092 : && DECL_IN_AGGR_P (ref))
214 : : return clk_none;
215 : :
216 : 187592948 : 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 : 8102971 : case SCOPE_REF:
230 : 8102971 : gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
231 : 8102971 : {
232 : 8102971 : tree op = TREE_OPERAND (ref, 1);
233 : 8102971 : if (TREE_CODE (op) == FIELD_DECL)
234 : 23242 : 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 : 8622383 : case COND_EXPR:
250 : 8622383 : 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 : 913398 : gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref)));
259 : 913398 : goto default_;
260 : : }
261 : 7708985 : {
262 : 7708985 : tree op1 = TREE_OPERAND (ref, 1);
263 : 7708985 : if (!op1) op1 = TREE_OPERAND (ref, 0);
264 : 7708985 : tree op2 = TREE_OPERAND (ref, 2);
265 : 7708985 : op1_lvalue_kind = lvalue_kind (op1);
266 : 7708985 : op2_lvalue_kind = lvalue_kind (op2);
267 : 7708985 : 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 : 549000 : if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
273 : : op2_lvalue_kind = op1_lvalue_kind;
274 : 548958 : else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
275 : 7709470 : op1_lvalue_kind = op2_lvalue_kind;
276 : : }
277 : : }
278 : : break;
279 : :
280 : 68208 : case MODOP_EXPR:
281 : : /* We expect to see unlowered MODOP_EXPRs only during
282 : : template processing. */
283 : 68208 : gcc_assert (processing_template_decl);
284 : 68208 : 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 : 1379300 : case COMPOUND_EXPR:
294 : 1379300 : return lvalue_kind (TREE_OPERAND (ref, 1));
295 : :
296 : : case TARGET_EXPR:
297 : : return clk_class;
298 : :
299 : 1373 : case VA_ARG_EXPR:
300 : 1373 : return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
301 : :
302 : 86483748 : case CALL_EXPR:
303 : : /* We can see calls outside of TARGET_EXPR in templates. */
304 : 86483748 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
305 : : return clk_class;
306 : : return clk_none;
307 : :
308 : 85858214 : case FUNCTION_DECL:
309 : : /* All functions (except non-static-member functions) are
310 : : lvalues. */
311 : 85858214 : return (DECL_IOBJ_MEMBER_FUNCTION_P (ref)
312 : 85858214 : ? clk_none : clk_ordinary);
313 : :
314 : 5140 : 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 : 5140 : return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref)));
320 : :
321 : 32108 : case PAREN_EXPR:
322 : 32108 : return lvalue_kind (TREE_OPERAND (ref, 0));
323 : :
324 : 14995502 : case TEMPLATE_PARM_INDEX:
325 : 14995502 : 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 : 689212395 : default:
331 : 689212395 : default_:
332 : 689212395 : if (!TREE_TYPE (ref))
333 : : return clk_none;
334 : 1378424790 : if (CLASS_TYPE_P (TREE_TYPE (ref))
335 : 1376733885 : || 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 : 7709470 : 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 : 1206045 : op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
348 : : /* It's not an ordinary lvalue if it involves any other kind. */
349 : 1206045 : if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
350 : 278547 : 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 : 278547 : if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
354 : 22390 : && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
355 : 788444333 : 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 : 40161170 : real_lvalue_p (const_tree ref)
363 : : {
364 : 40161170 : cp_lvalue_kind kind = lvalue_kind (ref);
365 : 40161170 : if (kind & (clk_rvalueref|clk_class))
366 : : return clk_none;
367 : : else
368 : 38512305 : return kind;
369 : : }
370 : :
371 : : /* c-common wants us to return bool. */
372 : :
373 : : bool
374 : 39773562 : lvalue_p (const_tree t)
375 : : {
376 : 39773562 : return real_lvalue_p (t);
377 : : }
378 : :
379 : : /* This differs from lvalue_p in that xvalues are included. */
380 : :
381 : : bool
382 : 112451497 : glvalue_p (const_tree ref)
383 : : {
384 : 112451497 : cp_lvalue_kind kind = lvalue_kind (ref);
385 : 112451497 : if (kind & clk_class)
386 : : return false;
387 : : else
388 : 110953180 : return (kind != clk_none);
389 : : }
390 : :
391 : : /* This differs from glvalue_p in that class prvalues are included. */
392 : :
393 : : bool
394 : 883848422 : obvalue_p (const_tree ref)
395 : : {
396 : 883848422 : 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 : 4817121 : xvalue_p (const_tree ref)
404 : : {
405 : 4817121 : return (lvalue_kind (ref) & clk_rvalueref);
406 : : }
407 : :
408 : : /* True if REF is a bit-field. */
409 : :
410 : : bool
411 : 147924437 : bitfield_p (const_tree ref)
412 : : {
413 : 147924437 : 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 : 3981295 : cp_stabilize_reference (tree ref)
431 : : {
432 : 3981295 : if (processing_template_decl)
433 : : /* As in cp_save_expr. */
434 : : return ref;
435 : :
436 : 3362101 : STRIP_ANY_LOCATION_WRAPPER (ref);
437 : 3362101 : 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 : 419 : default:
455 : 419 : cp_lvalue_kind kind = lvalue_kind (ref);
456 : 419 : 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 : 3362101 : 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 : 374199137 : builtin_valid_in_constant_expr_p (const_tree decl)
477 : : {
478 : 374199137 : STRIP_ANY_LOCATION_WRAPPER (decl);
479 : 374199137 : if (TREE_CODE (decl) != FUNCTION_DECL)
480 : : /* Not a function. */
481 : : return false;
482 : 161204364 : if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
483 : : {
484 : 131089545 : if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
485 : 126831 : 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 : : return true;
492 : : default:
493 : : break;
494 : : }
495 : : /* Not a built-in. */
496 : : return false;
497 : : }
498 : 30114819 : switch (DECL_FUNCTION_CODE (decl))
499 : : {
500 : : /* These always have constant results like the corresponding
501 : : macros/symbol. */
502 : : case BUILT_IN_FILE:
503 : : case BUILT_IN_FUNCTION:
504 : : case BUILT_IN_LINE:
505 : :
506 : : /* The following built-ins are valid in constant expressions
507 : : when their arguments are. */
508 : : case BUILT_IN_ADD_OVERFLOW_P:
509 : : case BUILT_IN_SUB_OVERFLOW_P:
510 : : case BUILT_IN_MUL_OVERFLOW_P:
511 : :
512 : : /* These have constant results even if their operands are
513 : : non-constant. */
514 : : case BUILT_IN_CONSTANT_P:
515 : : case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE:
516 : : return true;
517 : : default:
518 : : return false;
519 : : }
520 : : }
521 : :
522 : : /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
523 : :
524 : : static tree
525 : 23343574 : build_target_expr (tree decl, tree value, tsubst_flags_t complain)
526 : : {
527 : 23343574 : tree t;
528 : 23343574 : tree type = TREE_TYPE (decl);
529 : :
530 : 23343574 : value = mark_rvalue_use (value);
531 : :
532 : 23343574 : gcc_checking_assert (VOID_TYPE_P (TREE_TYPE (value))
533 : : || TREE_TYPE (decl) == TREE_TYPE (value)
534 : : /* On ARM ctors return 'this'. */
535 : : || (TYPE_PTR_P (TREE_TYPE (value))
536 : : && TREE_CODE (value) == CALL_EXPR)
537 : : || useless_type_conversion_p (TREE_TYPE (decl),
538 : : TREE_TYPE (value)));
539 : :
540 : : /* Set TREE_READONLY for optimization, such as gimplify_init_constructor
541 : : moving a constant aggregate into .rodata. */
542 : 23343574 : if (CP_TYPE_CONST_NON_VOLATILE_P (type)
543 : 1495578 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
544 : 1330983 : && !VOID_TYPE_P (TREE_TYPE (value))
545 : 848445 : && !TYPE_HAS_MUTABLE_P (type)
546 : 24192013 : && reduced_constant_expression_p (value))
547 : 295257 : TREE_READONLY (decl) = true;
548 : :
549 : 23343574 : if (complain & tf_no_cleanup)
550 : : /* The caller is building a new-expr and does not need a cleanup. */
551 : : t = NULL_TREE;
552 : : else
553 : : {
554 : 22374150 : t = cxx_maybe_build_cleanup (decl, complain);
555 : 22374150 : if (t == error_mark_node)
556 : : return error_mark_node;
557 : : }
558 : :
559 : 23343544 : set_target_expr_eliding (value);
560 : :
561 : 23343544 : t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
562 : 23343544 : if (location_t eloc = cp_expr_location (value))
563 : 14566022 : SET_EXPR_LOCATION (t, eloc);
564 : : /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
565 : : ignore the TARGET_EXPR. If there really turn out to be no
566 : : side-effects, then the optimizer should be able to get rid of
567 : : whatever code is generated anyhow. */
568 : 23343544 : TREE_SIDE_EFFECTS (t) = 1;
569 : :
570 : 23343544 : return t;
571 : : }
572 : :
573 : : /* Return an undeclared local temporary of type TYPE for use in building a
574 : : TARGET_EXPR. */
575 : :
576 : : tree
577 : 25500501 : build_local_temp (tree type)
578 : : {
579 : 25500501 : tree slot = build_decl (input_location,
580 : : VAR_DECL, NULL_TREE, type);
581 : 25500501 : DECL_ARTIFICIAL (slot) = 1;
582 : 25500501 : DECL_IGNORED_P (slot) = 1;
583 : 25500501 : DECL_CONTEXT (slot) = current_function_decl;
584 : 25500501 : layout_decl (slot, 0);
585 : 25500501 : return slot;
586 : : }
587 : :
588 : : /* Return whether DECL is such a local temporary (or one from
589 : : create_tmp_var_raw). */
590 : :
591 : : bool
592 : 247357 : is_local_temp (tree decl)
593 : : {
594 : 247357 : return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
595 : 248014 : && !TREE_STATIC (decl));
596 : : }
597 : :
598 : : /* Set various status flags when building an AGGR_INIT_EXPR object T. */
599 : :
600 : : static void
601 : 7274137 : process_aggr_init_operands (tree t)
602 : : {
603 : 7274137 : bool side_effects;
604 : :
605 : 7274137 : side_effects = TREE_SIDE_EFFECTS (t);
606 : 7274137 : if (!side_effects)
607 : : {
608 : 7274137 : int i, n;
609 : 7274137 : n = TREE_OPERAND_LENGTH (t);
610 : 32163989 : for (i = 1; i < n; i++)
611 : : {
612 : 27006483 : tree op = TREE_OPERAND (t, i);
613 : 27006483 : if (op && TREE_SIDE_EFFECTS (op))
614 : : {
615 : : side_effects = 1;
616 : : break;
617 : : }
618 : : }
619 : : }
620 : 7274137 : TREE_SIDE_EFFECTS (t) = side_effects;
621 : 7274137 : }
622 : :
623 : : /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
624 : : FN, and SLOT. NARGS is the number of call arguments which are specified
625 : : as a tree array ARGS. */
626 : :
627 : : static tree
628 : 7274137 : build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
629 : : tree *args)
630 : : {
631 : 7274137 : tree t;
632 : 7274137 : int i;
633 : :
634 : 7274137 : t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
635 : 7274137 : TREE_TYPE (t) = return_type;
636 : 7274137 : AGGR_INIT_EXPR_FN (t) = fn;
637 : 7274137 : AGGR_INIT_EXPR_SLOT (t) = slot;
638 : 20670283 : for (i = 0; i < nargs; i++)
639 : 13396146 : AGGR_INIT_EXPR_ARG (t, i) = args[i];
640 : 7274137 : process_aggr_init_operands (t);
641 : 7274137 : return t;
642 : : }
643 : :
644 : : /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
645 : : target. TYPE is the type to be initialized.
646 : :
647 : : Build an AGGR_INIT_EXPR to represent the initialization. This function
648 : : differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
649 : : to initialize another object, whereas a TARGET_EXPR can either
650 : : initialize another object or create its own temporary object, and as a
651 : : result building up a TARGET_EXPR requires that the type's destructor be
652 : : callable. */
653 : :
654 : : tree
655 : 24416725 : build_aggr_init_expr (tree type, tree init)
656 : : {
657 : 24416725 : tree fn;
658 : 24416725 : tree slot;
659 : 24416725 : tree rval;
660 : 24416725 : int is_ctor;
661 : :
662 : 24416725 : gcc_assert (!VOID_TYPE_P (type));
663 : :
664 : : /* Don't build AGGR_INIT_EXPR in a template. */
665 : 24416725 : if (processing_template_decl)
666 : : return init;
667 : :
668 : 24340314 : fn = cp_get_callee (init);
669 : 24340314 : if (fn == NULL_TREE)
670 : 10458741 : return convert (type, init);
671 : :
672 : 28844867 : is_ctor = (TREE_CODE (fn) == ADDR_EXPR
673 : 13829058 : && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
674 : 41539689 : && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
675 : :
676 : : /* We split the CALL_EXPR into its function and its arguments here.
677 : : Then, in expand_expr, we put them back together. The reason for
678 : : this is that this expression might be a default argument
679 : : expression. In that case, we need a new temporary every time the
680 : : expression is used. That's what break_out_target_exprs does; it
681 : : replaces every AGGR_INIT_EXPR with a copy that uses a fresh
682 : : temporary slot. Then, expand_expr builds up a call-expression
683 : : using the new slot. */
684 : :
685 : : /* If we don't need to use a constructor to create an object of this
686 : : type, don't mess with AGGR_INIT_EXPR. */
687 : 7689157 : if (is_ctor || TREE_ADDRESSABLE (type))
688 : : {
689 : 7274137 : slot = build_local_temp (type);
690 : :
691 : 7274137 : if (TREE_CODE (init) == CALL_EXPR)
692 : : {
693 : 27932116 : rval = build_aggr_init_array (void_type_node, fn, slot,
694 : 6983029 : call_expr_nargs (init),
695 : 6983029 : CALL_EXPR_ARGP (init));
696 : 6983029 : AGGR_INIT_FROM_THUNK_P (rval)
697 : 6983029 : = CALL_FROM_THUNK_P (init);
698 : : }
699 : : else
700 : : {
701 : 291108 : rval = build_aggr_init_array (void_type_node, fn, slot,
702 : 291108 : aggr_init_expr_nargs (init),
703 : 291108 : AGGR_INIT_EXPR_ARGP (init));
704 : 291108 : AGGR_INIT_FROM_THUNK_P (rval)
705 : 291108 : = AGGR_INIT_FROM_THUNK_P (init);
706 : : }
707 : 7274137 : TREE_SIDE_EFFECTS (rval) = 1;
708 : 7274137 : AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
709 : 7274137 : TREE_NOTHROW (rval) = TREE_NOTHROW (init);
710 : 7274137 : CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
711 : 7274137 : CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
712 : 7274137 : CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
713 : 7274137 : SET_EXPR_LOCATION (rval, EXPR_LOCATION (init));
714 : : }
715 : : else
716 : : rval = init;
717 : :
718 : : return rval;
719 : : }
720 : :
721 : : /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
722 : : target. TYPE is the type that this initialization should appear to
723 : : have.
724 : :
725 : : Build an encapsulation of the initialization to perform
726 : : and return it so that it can be processed by language-independent
727 : : and language-specific expression expanders. */
728 : :
729 : : tree
730 : 21585130 : build_cplus_new (tree type, tree init, tsubst_flags_t complain)
731 : : {
732 : : /* This function should cope with what build_special_member_call
733 : : can produce. When performing parenthesized aggregate initialization,
734 : : it can produce a { }. */
735 : 21585130 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
736 : : {
737 : 170 : gcc_assert (cxx_dialect >= cxx20);
738 : 170 : return finish_compound_literal (type, init, complain);
739 : : }
740 : :
741 : 21584960 : tree rval = build_aggr_init_expr (type, init);
742 : 21584960 : tree slot;
743 : :
744 : 21584960 : if (init == error_mark_node)
745 : : return error_mark_node;
746 : :
747 : 21583077 : if (!complete_type_or_maybe_complain (type, init, complain))
748 : 6 : return error_mark_node;
749 : :
750 : : /* Make sure that we're not trying to create an instance of an
751 : : abstract class. */
752 : 21583071 : if (abstract_virtuals_error (NULL_TREE, type, complain))
753 : 15 : return error_mark_node;
754 : :
755 : 21583056 : if (TREE_CODE (rval) == AGGR_INIT_EXPR)
756 : 4662711 : slot = AGGR_INIT_EXPR_SLOT (rval);
757 : 16920345 : else if (TREE_CODE (rval) == CALL_EXPR
758 : 10236507 : || TREE_CODE (rval) == CONSTRUCTOR)
759 : 6683855 : slot = build_local_temp (type);
760 : : else
761 : : return rval;
762 : :
763 : 11346566 : rval = build_target_expr (slot, rval, complain);
764 : :
765 : 11346566 : if (rval != error_mark_node)
766 : 11346566 : TARGET_EXPR_IMPLICIT_P (rval) = 1;
767 : :
768 : : return rval;
769 : : }
770 : :
771 : : /* Subroutine of build_vec_init_expr: Build up a single element
772 : : intialization as a proxy for the full array initialization to get things
773 : : marked as used and any appropriate diagnostics.
774 : :
775 : : This used to be necessary because we were deferring building the actual
776 : : constructor calls until gimplification time; now we only do it to set
777 : : VEC_INIT_EXPR_IS_CONSTEXPR.
778 : :
779 : : We assume that init is either NULL_TREE, {}, void_type_node (indicating
780 : : value-initialization), or another array to copy. */
781 : :
782 : : static tree
783 : 1127 : build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
784 : : {
785 : 1127 : tree inner_type = strip_array_types (type);
786 : :
787 : 1127 : if (integer_zerop (array_type_nelts_total (type))
788 : 1127 : || !CLASS_TYPE_P (inner_type))
789 : : /* No interesting initialization to do. */
790 : 215 : return integer_zero_node;
791 : 912 : if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
792 : : {
793 : : /* Even if init has initializers for some array elements,
794 : : we're interested in the {}-init of trailing elements. */
795 : 113 : if (CP_AGGREGATE_TYPE_P (inner_type))
796 : : {
797 : 34 : tree empty = build_constructor (init_list_type_node, nullptr);
798 : 34 : return digest_init (inner_type, empty, complain);
799 : : }
800 : : else
801 : : /* It's equivalent to value-init. */
802 : 79 : init = void_type_node;
803 : : }
804 : 878 : if (init == void_type_node)
805 : 108 : return build_value_init (inner_type, complain);
806 : :
807 : 770 : releasing_vec argvec;
808 : 770 : if (init && !BRACE_ENCLOSED_INITIALIZER_P (init))
809 : : {
810 : 198 : tree init_type = strip_array_types (TREE_TYPE (init));
811 : 198 : tree dummy = build_dummy_object (init_type);
812 : 198 : if (!lvalue_p (init))
813 : 156 : dummy = move (dummy);
814 : 198 : argvec->quick_push (dummy);
815 : : }
816 : 770 : init = build_special_member_call (NULL_TREE, complete_ctor_identifier,
817 : : &argvec, inner_type, LOOKUP_NORMAL,
818 : : complain);
819 : :
820 : : /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But
821 : : we don't want one here because we aren't creating a temporary. */
822 : 770 : if (TREE_CODE (init) == TARGET_EXPR)
823 : 32 : init = TARGET_EXPR_INITIAL (init);
824 : :
825 : 770 : return init;
826 : 770 : }
827 : :
828 : : /* Return a TARGET_EXPR which expresses the initialization of an array to
829 : : be named later, either default-initialization or copy-initialization
830 : : from another array of the same type. */
831 : :
832 : : tree
833 : 1140 : build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
834 : : {
835 : 1140 : if (tree vi = get_vec_init_expr (init))
836 : : return vi;
837 : :
838 : 1128 : tree elt_init;
839 : 544 : if (init && TREE_CODE (init) == CONSTRUCTOR
840 : 1245 : && !BRACE_ENCLOSED_INITIALIZER_P (init))
841 : : /* We built any needed constructor calls in digest_init. */
842 : : elt_init = init;
843 : : else
844 : 1124 : elt_init = build_vec_init_elt (type, init, complain);
845 : :
846 : 1128 : bool value_init = false;
847 : 1128 : if (init == void_type_node)
848 : : {
849 : 222 : value_init = true;
850 : 222 : init = NULL_TREE;
851 : : }
852 : :
853 : 1128 : tree slot = build_local_temp (type);
854 : 1128 : init = build2 (VEC_INIT_EXPR, type, slot, init);
855 : 1128 : TREE_SIDE_EFFECTS (init) = true;
856 : 1128 : SET_EXPR_LOCATION (init, input_location);
857 : :
858 : 1128 : if (cxx_dialect >= cxx11)
859 : : {
860 : 1065 : bool cx = potential_constant_expression (elt_init);
861 : 1065 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
862 : 0 : cx &= potential_constant_expression (init);
863 : 1065 : VEC_INIT_EXPR_IS_CONSTEXPR (init) = cx;
864 : : }
865 : 1128 : VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
866 : :
867 : 1128 : return init;
868 : : }
869 : :
870 : : /* Call build_vec_init to expand VEC_INIT into TARGET (for which NULL_TREE
871 : : means VEC_INIT_EXPR_SLOT). */
872 : :
873 : : tree
874 : 1146 : expand_vec_init_expr (tree target, tree vec_init, tsubst_flags_t complain,
875 : : vec<tree,va_gc> **flags)
876 : : {
877 : 1146 : iloc_sentinel ils = EXPR_LOCATION (vec_init);
878 : :
879 : 1146 : if (!target)
880 : 0 : target = VEC_INIT_EXPR_SLOT (vec_init);
881 : 1146 : tree init = VEC_INIT_EXPR_INIT (vec_init);
882 : 1146 : int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
883 : 3438 : return build_vec_init (target, NULL_TREE, init,
884 : 1146 : VEC_INIT_EXPR_VALUE_INIT (vec_init),
885 : 1146 : from_array, complain, flags);
886 : 1146 : }
887 : :
888 : : /* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context
889 : : that requires a constant expression. */
890 : :
891 : : void
892 : 3 : diagnose_non_constexpr_vec_init (tree expr)
893 : : {
894 : 3 : tree type = TREE_TYPE (VEC_INIT_EXPR_SLOT (expr));
895 : 3 : tree init, elt_init;
896 : 3 : if (VEC_INIT_EXPR_VALUE_INIT (expr))
897 : 3 : init = void_type_node;
898 : : else
899 : 0 : init = VEC_INIT_EXPR_INIT (expr);
900 : :
901 : 3 : elt_init = build_vec_init_elt (type, init, tf_warning_or_error);
902 : 3 : require_potential_constant_expression (elt_init);
903 : 3 : }
904 : :
905 : : tree
906 : 19 : build_array_copy (tree init)
907 : : {
908 : 19 : return get_target_expr (build_vec_init_expr
909 : 19 : (TREE_TYPE (init), init, tf_warning_or_error));
910 : : }
911 : :
912 : : /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
913 : : indicated TYPE. */
914 : :
915 : : tree
916 : 7641903 : build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
917 : : {
918 : 7641903 : gcc_assert (!VOID_TYPE_P (type));
919 : 7641903 : gcc_assert (!VOID_TYPE_P (TREE_TYPE (init)));
920 : :
921 : 7641903 : if (TREE_CODE (init) == TARGET_EXPR
922 : 7079215 : || init == error_mark_node)
923 : : return init;
924 : 5216414 : else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
925 : 191513 : && TREE_CODE (init) != COND_EXPR
926 : : && TREE_CODE (init) != CONSTRUCTOR
927 : : && TREE_CODE (init) != VA_ARG_EXPR
928 : 7078980 : && TREE_CODE (init) != CALL_EXPR)
929 : : /* We need to build up a copy constructor call. COND_EXPR is a special
930 : : case because we already have copies on the arms and we don't want
931 : : another one here. A CONSTRUCTOR is aggregate initialization, which
932 : : is handled separately. A VA_ARG_EXPR is magic creation of an
933 : : aggregate; there's no additional work to be done. A CALL_EXPR
934 : : already creates a prvalue. */
935 : 0 : return force_rvalue (init, complain);
936 : :
937 : 7078980 : return force_target_expr (type, init, complain);
938 : : }
939 : :
940 : : /* Like the above function, but without the checking. This function should
941 : : only be used by code which is deliberately trying to subvert the type
942 : : system, such as call_builtin_trap. Or build_over_call, to avoid
943 : : infinite recursion. */
944 : :
945 : : tree
946 : 11541358 : force_target_expr (tree type, tree init, tsubst_flags_t complain)
947 : : {
948 : 11541358 : tree slot;
949 : :
950 : 11541358 : gcc_assert (!VOID_TYPE_P (type));
951 : :
952 : 11541358 : slot = build_local_temp (type);
953 : 11541358 : return build_target_expr (slot, init, complain);
954 : : }
955 : :
956 : : /* Like build_target_expr_with_type, but use the type of INIT. */
957 : :
958 : : tree
959 : 6154154 : get_target_expr (tree init, tsubst_flags_t complain /* = tf_warning_or_error */)
960 : : {
961 : 6154154 : if (TREE_CODE (init) == AGGR_INIT_EXPR)
962 : 455370 : return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
963 : 5698784 : else if (TREE_CODE (init) == VEC_INIT_EXPR)
964 : 280 : return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
965 : : else
966 : : {
967 : 5698504 : init = convert_bitfield_to_declared_type (init);
968 : 5698504 : return build_target_expr_with_type (init, TREE_TYPE (init), complain);
969 : : }
970 : : }
971 : :
972 : : /* Like get_target_expr, but for an internal detail like a cleanup flag or loop
973 : : iterator. These variables should not be extended by extend_all_temps.
974 : :
975 : : This function can also be used for an ephemeral copy of a scalar value such
976 : : as the pointer to the allocated memory in build_new_1.
977 : :
978 : : This function should not be used for objects that are part of the abstract
979 : : C++ semantics such as in stabilize_expr. */
980 : :
981 : : tree
982 : 1310661 : get_internal_target_expr (tree init)
983 : : {
984 : 1310661 : init = convert_bitfield_to_declared_type (init);
985 : 1310661 : tree t = force_target_expr (TREE_TYPE (init), init, tf_warning_or_error);
986 : 1310661 : TARGET_EXPR_INTERNAL_P (t) = true;
987 : 1310661 : return t;
988 : : }
989 : :
990 : : /* If EXPR is a bitfield reference, convert it to the declared type of
991 : : the bitfield, and return the resulting expression. Otherwise,
992 : : return EXPR itself. */
993 : :
994 : : tree
995 : 794059577 : convert_bitfield_to_declared_type (tree expr)
996 : : {
997 : 794059577 : tree bitfield_type;
998 : :
999 : 794059577 : bitfield_type = is_bitfield_expr_with_lowered_type (expr);
1000 : 794059577 : if (bitfield_type)
1001 : 268217 : expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
1002 : : expr);
1003 : 794059577 : return expr;
1004 : : }
1005 : :
1006 : : /* EXPR is being used in an rvalue context. Return a version of EXPR
1007 : : that is marked as an rvalue. */
1008 : :
1009 : : tree
1010 : 145347674 : rvalue (tree expr)
1011 : : {
1012 : 145347674 : tree type;
1013 : :
1014 : 145347674 : if (error_operand_p (expr))
1015 : : return expr;
1016 : :
1017 : 145347460 : expr = mark_rvalue_use (expr);
1018 : :
1019 : : /* [expr.type]: "If a prvalue initially has the type "cv T", where T is a
1020 : : cv-unqualified non-class, non-array type, the type of the expression is
1021 : : adjusted to T prior to any further analysis. */
1022 : 145347460 : type = TREE_TYPE (expr);
1023 : 145347460 : if (!CLASS_TYPE_P (type) && TREE_CODE (type) != ARRAY_TYPE
1024 : 289198287 : && cv_qualified_p (type))
1025 : 31219900 : type = cv_unqualified (type);
1026 : :
1027 : : /* We need to do this for rvalue refs as well to get the right answer
1028 : : from decltype; see c++/36628. */
1029 : 145347460 : if (!processing_template_decl && glvalue_p (expr))
1030 : : {
1031 : : /* But don't use this function for class lvalues; use move (to treat an
1032 : : lvalue as an xvalue) or force_rvalue (to make a prvalue copy). */
1033 : 7411761 : gcc_checking_assert (!CLASS_TYPE_P (type));
1034 : 7411761 : expr = build1 (NON_LVALUE_EXPR, type, expr);
1035 : : }
1036 : 137935699 : else if (type != TREE_TYPE (expr))
1037 : 30951060 : expr = build_nop (type, expr);
1038 : :
1039 : : return expr;
1040 : : }
1041 : :
1042 : :
1043 : : struct cplus_array_info
1044 : : {
1045 : : tree type;
1046 : : tree domain;
1047 : : };
1048 : :
1049 : : struct cplus_array_hasher : ggc_ptr_hash<tree_node>
1050 : : {
1051 : : typedef cplus_array_info *compare_type;
1052 : :
1053 : : static hashval_t hash (tree t);
1054 : : static bool equal (tree, cplus_array_info *);
1055 : : };
1056 : :
1057 : : /* Hash an ARRAY_TYPE. K is really of type `tree'. */
1058 : :
1059 : : hashval_t
1060 : 26609897 : cplus_array_hasher::hash (tree t)
1061 : : {
1062 : 26609897 : hashval_t hash;
1063 : :
1064 : 26609897 : hash = TYPE_UID (TREE_TYPE (t));
1065 : 26609897 : if (TYPE_DOMAIN (t))
1066 : 21749776 : hash ^= TYPE_UID (TYPE_DOMAIN (t));
1067 : 26609897 : return hash;
1068 : : }
1069 : :
1070 : : /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
1071 : : of type `cplus_array_info*'. */
1072 : :
1073 : : bool
1074 : 33515544 : cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
1075 : : {
1076 : 35547130 : return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
1077 : : }
1078 : :
1079 : : /* Hash table containing dependent array types, which are unsuitable for
1080 : : the language-independent type hash table. */
1081 : : static GTY (()) hash_table<cplus_array_hasher> *cplus_array_htab;
1082 : :
1083 : : /* Build an ARRAY_TYPE without laying it out. */
1084 : :
1085 : : static tree
1086 : 4000192 : build_min_array_type (tree elt_type, tree index_type)
1087 : : {
1088 : 4000192 : tree t = cxx_make_type (ARRAY_TYPE);
1089 : 4000192 : TREE_TYPE (t) = elt_type;
1090 : 4000192 : TYPE_DOMAIN (t) = index_type;
1091 : 4000192 : return t;
1092 : : }
1093 : :
1094 : : /* Set TYPE_CANONICAL like build_array_type_1, but using
1095 : : build_cplus_array_type. */
1096 : :
1097 : : static void
1098 : 4000192 : set_array_type_canon (tree t, tree elt_type, tree index_type, bool dep)
1099 : : {
1100 : : /* Set the canonical type for this new node. */
1101 : 4000192 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
1102 : 4000192 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
1103 : 918276 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1104 : 3081916 : else if (TYPE_CANONICAL (elt_type) != elt_type
1105 : 3081916 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
1106 : 832893 : TYPE_CANONICAL (t)
1107 : 2167728 : = build_cplus_array_type (TYPE_CANONICAL (elt_type),
1108 : : index_type
1109 : 501942 : ? TYPE_CANONICAL (index_type) : index_type,
1110 : : dep);
1111 : : else
1112 : 2249023 : TYPE_CANONICAL (t) = t;
1113 : 4000192 : }
1114 : :
1115 : : /* Like build_array_type, but handle special C++ semantics: an array of a
1116 : : variant element type is a variant of the array of the main variant of
1117 : : the element type. IS_DEPENDENT is -ve if we should determine the
1118 : : dependency. Otherwise its bool value indicates dependency. */
1119 : :
1120 : : tree
1121 : 50478485 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
1122 : : {
1123 : 50478485 : tree t;
1124 : :
1125 : 50478485 : if (elt_type == error_mark_node || index_type == error_mark_node)
1126 : : return error_mark_node;
1127 : :
1128 : 50478482 : if (dependent < 0)
1129 : 52176674 : dependent = (uses_template_parms (elt_type)
1130 : 26088337 : || (index_type && uses_template_parms (index_type)));
1131 : :
1132 : 50478482 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1133 : : /* Start with an array of the TYPE_MAIN_VARIANT. */
1134 : 21879282 : t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
1135 : : index_type, dependent);
1136 : 28599200 : else if (dependent)
1137 : : {
1138 : : /* Since type_hash_canon calls layout_type, we need to use our own
1139 : : hash table. */
1140 : 3331151 : cplus_array_info cai;
1141 : 3331151 : hashval_t hash;
1142 : :
1143 : 3331151 : if (cplus_array_htab == NULL)
1144 : 16269 : cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61);
1145 : :
1146 : 3331151 : hash = TYPE_UID (elt_type);
1147 : 3331151 : if (index_type)
1148 : 1810797 : hash ^= TYPE_UID (index_type);
1149 : 3331151 : cai.type = elt_type;
1150 : 3331151 : cai.domain = index_type;
1151 : :
1152 : 3331151 : tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
1153 : 3331151 : if (*e)
1154 : : /* We have found the type: we're done. */
1155 : 1961875 : return (tree) *e;
1156 : : else
1157 : : {
1158 : : /* Build a new array type. */
1159 : 1369276 : t = build_min_array_type (elt_type, index_type);
1160 : :
1161 : : /* Store it in the hash table. */
1162 : 1369276 : *e = t;
1163 : :
1164 : : /* Set the canonical type for this new node. */
1165 : 1369276 : set_array_type_canon (t, elt_type, index_type, dependent);
1166 : :
1167 : : /* Mark it as dependent now, this saves time later. */
1168 : 1369276 : TYPE_DEPENDENT_P_VALID (t) = true;
1169 : 1369276 : TYPE_DEPENDENT_P (t) = true;
1170 : : }
1171 : : }
1172 : : else
1173 : : {
1174 : 25268049 : bool typeless_storage = is_byte_access_type (elt_type);
1175 : 25268049 : t = build_array_type (elt_type, index_type, typeless_storage);
1176 : :
1177 : : /* Mark as non-dependenty now, this will save time later. */
1178 : 25268049 : TYPE_DEPENDENT_P_VALID (t) = true;
1179 : : }
1180 : :
1181 : : /* Now check whether we already have this array variant. */
1182 : 48516607 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1183 : : {
1184 : : tree m = t;
1185 : 44126755 : for (t = m; t; t = TYPE_NEXT_VARIANT (t))
1186 : 41495839 : if (TREE_TYPE (t) == elt_type
1187 : 19258339 : && TYPE_NAME (t) == NULL_TREE
1188 : 60744205 : && TYPE_ATTRIBUTES (t) == NULL_TREE)
1189 : : break;
1190 : 21879282 : if (!t)
1191 : : {
1192 : 2630916 : t = build_min_array_type (elt_type, index_type);
1193 : : /* Mark dependency now, this saves time later. */
1194 : 2630916 : TYPE_DEPENDENT_P_VALID (t) = true;
1195 : 2630916 : TYPE_DEPENDENT_P (t) = dependent;
1196 : 2630916 : set_array_type_canon (t, elt_type, index_type, dependent);
1197 : 2630916 : if (!dependent)
1198 : : {
1199 : 2205522 : layout_type (t);
1200 : : /* Make sure sizes are shared with the main variant.
1201 : : layout_type can't be called after setting TYPE_NEXT_VARIANT,
1202 : : as it will overwrite alignment etc. of all variants. */
1203 : 2205522 : TYPE_SIZE (t) = TYPE_SIZE (m);
1204 : 2205522 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
1205 : 2205522 : TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
1206 : : }
1207 : :
1208 : 2630916 : TYPE_MAIN_VARIANT (t) = m;
1209 : 2630916 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
1210 : 2630916 : TYPE_NEXT_VARIANT (m) = t;
1211 : : }
1212 : : }
1213 : :
1214 : : /* Avoid spurious warnings with VLAs (c++/54583). */
1215 : 48516607 : if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
1216 : 1786 : suppress_warning (TYPE_SIZE (t), OPT_Wunused);
1217 : :
1218 : : /* Push these needs up to the ARRAY_TYPE so that initialization takes
1219 : : place more easily. */
1220 : 97033214 : bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t)
1221 : 48516607 : = TYPE_NEEDS_CONSTRUCTING (elt_type));
1222 : 97033214 : bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1223 : 48516607 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
1224 : :
1225 : 46583166 : if (!dependent && t == TYPE_MAIN_VARIANT (t)
1226 : 73784656 : && !COMPLETE_TYPE_P (t) && COMPLETE_TYPE_P (elt_type))
1227 : : {
1228 : : /* The element type has been completed since the last time we saw
1229 : : this array type; update the layout and 'tor flags for any variants
1230 : : that need it. */
1231 : 1064559 : layout_type (t);
1232 : 1853217 : for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
1233 : : {
1234 : 788658 : TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
1235 : 788658 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (v) = needs_dtor;
1236 : : }
1237 : : }
1238 : :
1239 : : return t;
1240 : : }
1241 : :
1242 : : /* Return an ARRAY_TYPE with element type ELT and length N. */
1243 : :
1244 : : tree
1245 : 2062078 : build_array_of_n_type (tree elt, unsigned HOST_WIDE_INT n)
1246 : : {
1247 : 2062078 : return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
1248 : : }
1249 : :
1250 : : /* True iff T is an array of unknown bound. */
1251 : :
1252 : : bool
1253 : 5320814 : array_of_unknown_bound_p (const_tree t)
1254 : : {
1255 : 5320814 : return (TREE_CODE (t) == ARRAY_TYPE
1256 : 5320814 : && !TYPE_DOMAIN (t));
1257 : : }
1258 : :
1259 : : /* True iff T is an N3639 array of runtime bound (VLA). These were approved
1260 : : for C++14 but then removed. This should only be used for N3639
1261 : : specifically; code wondering more generally if something is a VLA should use
1262 : : vla_type_p. */
1263 : :
1264 : : bool
1265 : 285624 : array_of_runtime_bound_p (tree t)
1266 : : {
1267 : 285624 : if (!t || TREE_CODE (t) != ARRAY_TYPE)
1268 : : return false;
1269 : 243 : if (variably_modified_type_p (TREE_TYPE (t), NULL_TREE))
1270 : : return false;
1271 : 231 : tree dom = TYPE_DOMAIN (t);
1272 : 231 : if (!dom)
1273 : : return false;
1274 : 228 : tree max = TYPE_MAX_VALUE (dom);
1275 : 228 : return (!potential_rvalue_constant_expression (max)
1276 : 228 : || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)));
1277 : : }
1278 : :
1279 : : /* True iff T is a variable length array. */
1280 : :
1281 : : bool
1282 : 26491485 : vla_type_p (tree t)
1283 : : {
1284 : 27112425 : for (; t && TREE_CODE (t) == ARRAY_TYPE;
1285 : 620940 : t = TREE_TYPE (t))
1286 : 621117 : if (tree dom = TYPE_DOMAIN (t))
1287 : : {
1288 : 621053 : tree max = TYPE_MAX_VALUE (dom);
1289 : 621053 : if (!potential_rvalue_constant_expression (max)
1290 : 621053 : || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)))
1291 : 177 : return true;
1292 : : }
1293 : : return false;
1294 : : }
1295 : :
1296 : :
1297 : : /* Return a reference type node of MODE referring to TO_TYPE. If MODE
1298 : : is VOIDmode the standard pointer mode will be picked. If RVAL is
1299 : : true, return an rvalue reference type, otherwise return an lvalue
1300 : : reference type. If a type node exists, reuse it, otherwise create
1301 : : a new one. */
1302 : : tree
1303 : 410323848 : cp_build_reference_type_for_mode (tree to_type, machine_mode mode, bool rval)
1304 : : {
1305 : 410323848 : tree lvalue_ref, t;
1306 : :
1307 : 410323848 : if (to_type == error_mark_node)
1308 : : return error_mark_node;
1309 : :
1310 : 410323843 : if (TYPE_REF_P (to_type))
1311 : : {
1312 : 1096 : rval = rval && TYPE_REF_IS_RVALUE (to_type);
1313 : 1096 : to_type = TREE_TYPE (to_type);
1314 : : }
1315 : :
1316 : 410323843 : lvalue_ref = build_reference_type_for_mode (to_type, mode, false);
1317 : :
1318 : 410323843 : if (!rval)
1319 : : return lvalue_ref;
1320 : :
1321 : : /* This code to create rvalue reference types is based on and tied
1322 : : to the code creating lvalue reference types in the middle-end
1323 : : functions build_reference_type_for_mode and build_reference_type.
1324 : :
1325 : : It works by putting the rvalue reference type nodes after the
1326 : : lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
1327 : : they will effectively be ignored by the middle end. */
1328 : :
1329 : 78384581 : for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
1330 : 57228550 : if (TYPE_REF_IS_RVALUE (t))
1331 : : return t;
1332 : :
1333 : 21156031 : t = build_distinct_type_copy (lvalue_ref);
1334 : :
1335 : 21156031 : TYPE_REF_IS_RVALUE (t) = true;
1336 : 21156031 : TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
1337 : 21156031 : TYPE_NEXT_REF_TO (lvalue_ref) = t;
1338 : :
1339 : 21156031 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
1340 : 737234 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1341 : 20418797 : else if (TYPE_CANONICAL (to_type) != to_type)
1342 : 11981336 : TYPE_CANONICAL (t)
1343 : 23962672 : = cp_build_reference_type_for_mode (TYPE_CANONICAL (to_type), mode, rval);
1344 : : else
1345 : 8437461 : TYPE_CANONICAL (t) = t;
1346 : :
1347 : 21156031 : layout_type (t);
1348 : :
1349 : 21156031 : return t;
1350 : :
1351 : : }
1352 : :
1353 : : /* Return a reference type node referring to TO_TYPE. If RVAL is
1354 : : true, return an rvalue reference type, otherwise return an lvalue
1355 : : reference type. If a type node exists, reuse it, otherwise create
1356 : : a new one. */
1357 : : tree
1358 : 356439686 : cp_build_reference_type (tree to_type, bool rval)
1359 : : {
1360 : 356439686 : return cp_build_reference_type_for_mode (to_type, VOIDmode, rval);
1361 : : }
1362 : :
1363 : : /* Returns EXPR cast to rvalue reference type, like std::move. */
1364 : :
1365 : : tree
1366 : 1422319 : move (tree expr)
1367 : : {
1368 : 1422319 : tree type = TREE_TYPE (expr);
1369 : 1422319 : gcc_assert (!TYPE_REF_P (type));
1370 : 1422319 : if (xvalue_p (expr))
1371 : : return expr;
1372 : 1422208 : type = cp_build_reference_type (type, /*rval*/true);
1373 : 1422208 : return build_static_cast (input_location, type, expr,
1374 : 1422208 : tf_warning_or_error);
1375 : : }
1376 : :
1377 : : /* Used by the C++ front end to build qualified array types. However,
1378 : : the C version of this function does not properly maintain canonical
1379 : : types (which are not used in C). */
1380 : : tree
1381 : 20832249 : c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */,
1382 : : size_t /* orig_qual_indirect */)
1383 : : {
1384 : 20832249 : return cp_build_qualified_type (type, type_quals);
1385 : : }
1386 : :
1387 : :
1388 : : /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
1389 : : arrays correctly. In particular, if TYPE is an array of T's, and
1390 : : TYPE_QUALS is non-empty, returns an array of qualified T's.
1391 : :
1392 : : FLAGS determines how to deal with ill-formed qualifications. If
1393 : : tf_ignore_bad_quals is set, then bad qualifications are dropped
1394 : : (this is permitted if TYPE was introduced via a typedef or template
1395 : : type parameter). If bad qualifications are dropped and tf_warning
1396 : : is set, then a warning is issued for non-const qualifications. If
1397 : : tf_ignore_bad_quals is not set and tf_error is not set, we
1398 : : return error_mark_node. Otherwise, we issue an error, and ignore
1399 : : the qualifications.
1400 : :
1401 : : Qualification of a reference type is valid when the reference came
1402 : : via a typedef or template type argument. [dcl.ref] No such
1403 : : dispensation is provided for qualifying a function type. [dcl.fct]
1404 : : DR 295 queries this and the proposed resolution brings it into line
1405 : : with qualifying a reference. We implement the DR. We also behave
1406 : : in a similar manner for restricting non-pointer types. */
1407 : :
1408 : : tree
1409 : 12859834235 : cp_build_qualified_type (tree type, int type_quals,
1410 : : tsubst_flags_t complain /* = tf_warning_or_error */)
1411 : : {
1412 : 12859834235 : tree result;
1413 : 12859834235 : int bad_quals = TYPE_UNQUALIFIED;
1414 : :
1415 : 12859834235 : if (type == error_mark_node)
1416 : : return type;
1417 : :
1418 : 12832139228 : if (type_quals == cp_type_quals (type))
1419 : : return type;
1420 : :
1421 : 2213095003 : if (TREE_CODE (type) == ARRAY_TYPE)
1422 : : {
1423 : : /* In C++, the qualification really applies to the array element
1424 : : type. Obtain the appropriately qualified element type. */
1425 : 23861337 : tree t;
1426 : 23861337 : tree element_type
1427 : 23861337 : = cp_build_qualified_type (TREE_TYPE (type), type_quals, complain);
1428 : :
1429 : 23861337 : if (element_type == error_mark_node)
1430 : : return error_mark_node;
1431 : :
1432 : : /* See if we already have an identically qualified type. Tests
1433 : : should be equivalent to those in check_qualified_type. */
1434 : 45380575 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1435 : 25058506 : if (TREE_TYPE (t) == element_type
1436 : 3563420 : && TYPE_NAME (t) == TYPE_NAME (type)
1437 : 3539268 : && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
1438 : 28597774 : && attribute_list_equal (TYPE_ATTRIBUTES (t),
1439 : 3539268 : TYPE_ATTRIBUTES (type)))
1440 : : break;
1441 : :
1442 : 23861337 : if (!t)
1443 : : {
1444 : : /* If we already know the dependentness, tell the array type
1445 : : constructor. This is important for module streaming, as we cannot
1446 : : dynamically determine that on read in. */
1447 : 20322069 : t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
1448 : 20322069 : TYPE_DEPENDENT_P_VALID (type)
1449 : 357953 : ? int (TYPE_DEPENDENT_P (type)) : -1);
1450 : :
1451 : : /* Keep the typedef name. */
1452 : 20322069 : if (TYPE_NAME (t) != TYPE_NAME (type))
1453 : : {
1454 : 5352 : t = build_variant_type_copy (t);
1455 : 5352 : TYPE_NAME (t) = TYPE_NAME (type);
1456 : 5352 : SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
1457 : 5352 : TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
1458 : : }
1459 : : }
1460 : :
1461 : : /* Even if we already had this variant, we update
1462 : : TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
1463 : : they changed since the variant was originally created.
1464 : :
1465 : : This seems hokey; if there is some way to use a previous
1466 : : variant *without* coming through here,
1467 : : TYPE_NEEDS_CONSTRUCTING will never be updated. */
1468 : 47722674 : TYPE_NEEDS_CONSTRUCTING (t)
1469 : 23861337 : = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
1470 : 47722674 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1471 : 23861337 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
1472 : 23861337 : return t;
1473 : : }
1474 : 2189233666 : else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
1475 : : {
1476 : 3 : tree t = PACK_EXPANSION_PATTERN (type);
1477 : :
1478 : 3 : t = cp_build_qualified_type (t, type_quals, complain);
1479 : 3 : return make_pack_expansion (t, complain);
1480 : : }
1481 : :
1482 : : /* A reference or method type shall not be cv-qualified.
1483 : : [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
1484 : : (in CD1) we always ignore extra cv-quals on functions. */
1485 : :
1486 : : /* [dcl.ref/1] Cv-qualified references are ill-formed except when
1487 : : the cv-qualifiers are introduced through the use of a typedef-name
1488 : : ([dcl.typedef], [temp.param]) or decltype-specifier
1489 : : ([dcl.type.decltype]),in which case the cv-qualifiers are
1490 : : ignored. */
1491 : 2189233663 : if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
1492 : 781651361 : && (TYPE_REF_P (type)
1493 : 781396515 : || FUNC_OR_METHOD_TYPE_P (type)))
1494 : : {
1495 : 255562 : if (TYPE_REF_P (type)
1496 : 255562 : && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
1497 : : bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1498 : 255562 : type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1499 : : }
1500 : :
1501 : : /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1502 : 2189233663 : if (TREE_CODE (type) == FUNCTION_TYPE)
1503 : 719 : type_quals |= type_memfn_quals (type);
1504 : :
1505 : : /* A restrict-qualified type must be a pointer (or reference)
1506 : : to object or incomplete type. */
1507 : 2189233663 : if ((type_quals & TYPE_QUAL_RESTRICT)
1508 : 8301830 : && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1509 : 8301793 : && TREE_CODE (type) != TYPENAME_TYPE
1510 : 8301787 : && !INDIRECT_TYPE_P (type))
1511 : : {
1512 : 25 : bad_quals |= TYPE_QUAL_RESTRICT;
1513 : 25 : type_quals &= ~TYPE_QUAL_RESTRICT;
1514 : : }
1515 : :
1516 : 2189233663 : if (bad_quals == TYPE_UNQUALIFIED
1517 : 200499 : || (complain & tf_ignore_bad_quals))
1518 : : /*OK*/;
1519 : 12 : else if (!(complain & tf_error))
1520 : 0 : return error_mark_node;
1521 : : else
1522 : : {
1523 : 12 : tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
1524 : 12 : error ("%qV qualifiers cannot be applied to %qT",
1525 : : bad_type, type);
1526 : : }
1527 : :
1528 : : /* Retrieve (or create) the appropriately qualified variant. */
1529 : 2189233663 : result = build_qualified_type (type, type_quals);
1530 : :
1531 : 2189233663 : return result;
1532 : : }
1533 : :
1534 : : /* Return TYPE with const and volatile removed. */
1535 : :
1536 : : tree
1537 : 1193051847 : cv_unqualified (tree type)
1538 : : {
1539 : 1193051847 : int quals;
1540 : :
1541 : 1193051847 : if (type == error_mark_node)
1542 : : return type;
1543 : :
1544 : 1193051668 : quals = cp_type_quals (type);
1545 : 1193051668 : quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
1546 : 1193051668 : return cp_build_qualified_type (type, quals);
1547 : : }
1548 : :
1549 : : /* Subroutine of strip_typedefs. We want to apply to RESULT the attributes
1550 : : from ATTRIBS that affect type identity, and no others. If any are not
1551 : : applied, set *remove_attributes to true. */
1552 : :
1553 : : static tree
1554 : 3391153 : apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
1555 : : {
1556 : 3391153 : tree first_ident = NULL_TREE;
1557 : 3391153 : tree new_attribs = NULL_TREE;
1558 : 3391153 : tree *p = &new_attribs;
1559 : :
1560 : 3391153 : if (OVERLOAD_TYPE_P (result))
1561 : : {
1562 : : /* On classes and enums all attributes are ingrained. */
1563 : 3390187 : gcc_assert (attribs == TYPE_ATTRIBUTES (result));
1564 : : return result;
1565 : : }
1566 : :
1567 : 1935 : for (tree a = attribs; a; a = TREE_CHAIN (a))
1568 : : {
1569 : 969 : const attribute_spec *as
1570 : 969 : = lookup_attribute_spec (get_attribute_name (a));
1571 : 969 : if (as && as->affects_type_identity)
1572 : : {
1573 : 369 : if (!first_ident)
1574 : : first_ident = a;
1575 : 0 : else if (first_ident == error_mark_node)
1576 : : {
1577 : 0 : *p = tree_cons (TREE_PURPOSE (a), TREE_VALUE (a), NULL_TREE);
1578 : 0 : p = &TREE_CHAIN (*p);
1579 : : }
1580 : : }
1581 : 600 : else if (first_ident && first_ident != error_mark_node)
1582 : : {
1583 : 0 : for (tree a2 = first_ident; a2 != a; a2 = TREE_CHAIN (a2))
1584 : : {
1585 : 0 : *p = tree_cons (TREE_PURPOSE (a2), TREE_VALUE (a2), NULL_TREE);
1586 : 0 : p = &TREE_CHAIN (*p);
1587 : : }
1588 : 0 : first_ident = error_mark_node;
1589 : : }
1590 : : }
1591 : 966 : if (first_ident != error_mark_node)
1592 : 966 : new_attribs = first_ident;
1593 : :
1594 : 966 : if (first_ident == attribs)
1595 : : /* All attributes affected type identity. */;
1596 : : else
1597 : 597 : *remove_attributes = true;
1598 : :
1599 : 966 : return cp_build_type_attribute_variant (result, new_attribs);
1600 : : }
1601 : :
1602 : : /* Builds a qualified variant of T that is either not a typedef variant
1603 : : (the default behavior) or not a typedef variant of a user-facing type
1604 : : (if FLAGS contains STF_USER_VISIBLE). If T is not a type, then this
1605 : : just dispatches to strip_typedefs_expr.
1606 : :
1607 : : E.g. consider the following declarations:
1608 : : typedef const int ConstInt;
1609 : : typedef ConstInt* PtrConstInt;
1610 : : If T is PtrConstInt, this function returns a type representing
1611 : : const int*.
1612 : : In other words, if T is a typedef, the function returns the underlying type.
1613 : : The cv-qualification and attributes of the type returned match the
1614 : : input type.
1615 : : They will always be compatible types.
1616 : : The returned type is built so that all of its subtypes
1617 : : recursively have their typedefs stripped as well.
1618 : :
1619 : : This is different from just returning TYPE_CANONICAL (T)
1620 : : Because of several reasons:
1621 : : * If T is a type that needs structural equality
1622 : : its TYPE_CANONICAL (T) will be NULL.
1623 : : * TYPE_CANONICAL (T) desn't carry type attributes
1624 : : and loses template parameter names.
1625 : :
1626 : : If REMOVE_ATTRIBUTES is non-null, also strip attributes that don't
1627 : : affect type identity, and set the referent to true if any were
1628 : : stripped. */
1629 : :
1630 : : tree
1631 : 2039582252 : strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
1632 : : unsigned int flags /* = 0 */)
1633 : : {
1634 : 2039582252 : tree result = NULL, type = NULL, t0 = NULL;
1635 : :
1636 : 2039582252 : if (!t || t == error_mark_node)
1637 : : return t;
1638 : :
1639 : 2013251661 : if (!TYPE_P (t))
1640 : 141986914 : return strip_typedefs_expr (t, remove_attributes, flags);
1641 : :
1642 : 1871264747 : if (t == TYPE_CANONICAL (t))
1643 : : return t;
1644 : :
1645 : 669873737 : if (typedef_variant_p (t))
1646 : : {
1647 : 175104973 : if ((flags & STF_USER_VISIBLE)
1648 : 175104973 : && !user_facing_original_type_p (t))
1649 : : return t;
1650 : :
1651 : 175104865 : if ((flags & STF_KEEP_INJ_CLASS_NAME)
1652 : 37047 : && CLASS_TYPE_P (t)
1653 : 175114599 : && DECL_SELF_REFERENCE_P (TYPE_NAME (t)))
1654 : : return t;
1655 : :
1656 : 175104864 : if (dependent_opaque_alias_p (t))
1657 : : return t;
1658 : :
1659 : 175104763 : if (alias_template_specialization_p (t, nt_opaque))
1660 : : {
1661 : 46665051 : if (dependent_alias_template_spec_p (t, nt_opaque)
1662 : 46665051 : && !(flags & STF_STRIP_DEPENDENT))
1663 : : /* DR 1558: However, if the template-id is dependent, subsequent
1664 : : template argument substitution still applies to the template-id. */
1665 : : return t;
1666 : : }
1667 : : else
1668 : : /* If T is a non-template alias or typedef, we can assume that
1669 : : instantiating its definition will hit any substitution failure,
1670 : : so we don't need to retain it here as well. */
1671 : 128439712 : flags |= STF_STRIP_DEPENDENT;
1672 : :
1673 : 168382462 : result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
1674 : : remove_attributes, flags);
1675 : 168382462 : goto stripped;
1676 : : }
1677 : :
1678 : 494768764 : switch (TREE_CODE (t))
1679 : : {
1680 : 9697924 : case POINTER_TYPE:
1681 : 9697924 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1682 : 9697924 : result = build_pointer_type_for_mode (type, TYPE_MODE (t), false);
1683 : 9697924 : break;
1684 : 41902826 : case REFERENCE_TYPE:
1685 : 41902826 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1686 : 41902826 : result = cp_build_reference_type_for_mode (type, TYPE_MODE (t), TYPE_REF_IS_RVALUE (t));
1687 : 41902826 : break;
1688 : 317383 : case OFFSET_TYPE:
1689 : 317383 : t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags);
1690 : 317383 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1691 : 317383 : result = build_offset_type (t0, type);
1692 : 317383 : break;
1693 : 21948018 : case RECORD_TYPE:
1694 : 21948018 : if (TYPE_PTRMEMFUNC_P (t))
1695 : : {
1696 : 1819533 : t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t),
1697 : : remove_attributes, flags);
1698 : 1819533 : result = build_ptrmemfunc_type (t0);
1699 : : }
1700 : : break;
1701 : 1305291 : case ARRAY_TYPE:
1702 : 1305291 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1703 : 1305291 : t0 = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags);
1704 : 1305291 : gcc_checking_assert (TYPE_DEPENDENT_P_VALID (t)
1705 : : || !dependent_type_p (t));
1706 : 1305291 : result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t));
1707 : 1305291 : break;
1708 : 4113171 : case FUNCTION_TYPE:
1709 : 4113171 : case METHOD_TYPE:
1710 : 4113171 : {
1711 : 4113171 : tree arg_types = NULL, arg_node, arg_node2, arg_type;
1712 : 4113171 : bool changed;
1713 : :
1714 : : /* Because we stomp on TREE_PURPOSE of TYPE_ARG_TYPES in many places
1715 : : around the compiler (e.g. cp_parser_late_parsing_default_args), we
1716 : : can't expect that re-hashing a function type will find a previous
1717 : : equivalent type, so try to reuse the input type if nothing has
1718 : : changed. If the type is itself a variant, that will change. */
1719 : 4113171 : bool is_variant = typedef_variant_p (t);
1720 : 4113171 : if (remove_attributes
1721 : 4113171 : && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t)))
1722 : : is_variant = true;
1723 : :
1724 : 4113171 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1725 : 4113171 : tree canon_spec = (flag_noexcept_type
1726 : 4113171 : ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t))
1727 : 4113171 : : NULL_TREE);
1728 : 7253039 : changed = (type != TREE_TYPE (t) || is_variant
1729 : 7252645 : || TYPE_RAISES_EXCEPTIONS (t) != canon_spec);
1730 : :
1731 : 4113171 : for (arg_node = TYPE_ARG_TYPES (t);
1732 : 9468077 : arg_node;
1733 : 5354906 : arg_node = TREE_CHAIN (arg_node))
1734 : : {
1735 : 8528016 : if (arg_node == void_list_node)
1736 : : break;
1737 : 5354906 : arg_type = strip_typedefs (TREE_VALUE (arg_node),
1738 : : remove_attributes, flags);
1739 : 5354906 : gcc_assert (arg_type);
1740 : 5354906 : if (arg_type == TREE_VALUE (arg_node) && !changed)
1741 : 5093615 : continue;
1742 : :
1743 : 261291 : if (!changed)
1744 : : {
1745 : 39957 : changed = true;
1746 : 39957 : for (arg_node2 = TYPE_ARG_TYPES (t);
1747 : 50994 : arg_node2 != arg_node;
1748 : 11037 : arg_node2 = TREE_CHAIN (arg_node2))
1749 : 11037 : arg_types
1750 : 11037 : = tree_cons (TREE_PURPOSE (arg_node2),
1751 : 11037 : TREE_VALUE (arg_node2), arg_types);
1752 : : }
1753 : :
1754 : 261291 : arg_types
1755 : 261291 : = tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
1756 : : }
1757 : :
1758 : 4113171 : if (!changed)
1759 : : return t;
1760 : :
1761 : 1013990 : if (arg_types)
1762 : 60723 : arg_types = nreverse (arg_types);
1763 : :
1764 : : /* A list of parameters not ending with an ellipsis
1765 : : must end with void_list_node. */
1766 : 1013990 : if (arg_node)
1767 : 1013943 : arg_types = chainon (arg_types, void_list_node);
1768 : :
1769 : 1013990 : if (TREE_CODE (t) == METHOD_TYPE)
1770 : : {
1771 : 28665 : tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
1772 : 28665 : gcc_assert (class_type);
1773 : 28665 : result =
1774 : 28665 : build_method_type_directly (class_type, type,
1775 : 28665 : TREE_CHAIN (arg_types));
1776 : : }
1777 : : else
1778 : : {
1779 : 985325 : result = build_function_type (type, arg_types);
1780 : 985325 : result = apply_memfn_quals (result, type_memfn_quals (t));
1781 : : }
1782 : :
1783 : 3041970 : result = build_cp_fntype_variant (result,
1784 : : type_memfn_rqual (t), canon_spec,
1785 : 1013990 : TYPE_HAS_LATE_RETURN_TYPE (t));
1786 : : }
1787 : 1013990 : break;
1788 : 42868847 : case TYPENAME_TYPE:
1789 : 42868847 : {
1790 : 42868847 : bool changed = false;
1791 : 42868847 : tree fullname = TYPENAME_TYPE_FULLNAME (t);
1792 : 42868847 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
1793 : 42868847 : && TREE_OPERAND (fullname, 1))
1794 : : {
1795 : 2284913 : tree args = TREE_OPERAND (fullname, 1);
1796 : 2284913 : tree new_args = copy_node (args);
1797 : 6051525 : for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
1798 : : {
1799 : 3766612 : tree arg = TREE_VEC_ELT (args, i);
1800 : 3766612 : tree strip_arg = strip_typedefs (arg, remove_attributes, flags);
1801 : 3766612 : TREE_VEC_ELT (new_args, i) = strip_arg;
1802 : 3766612 : if (strip_arg != arg)
1803 : 158825 : changed = true;
1804 : : }
1805 : 2284913 : if (changed)
1806 : : {
1807 : 158825 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
1808 : 158825 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
1809 : 158825 : fullname
1810 : 158825 : = lookup_template_function (TREE_OPERAND (fullname, 0),
1811 : : new_args);
1812 : : }
1813 : : else
1814 : 2126088 : ggc_free (new_args);
1815 : : }
1816 : 42868847 : tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes, flags);
1817 : 42868847 : if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t))
1818 : : return t;
1819 : 3846016 : tree name = fullname;
1820 : 3846016 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
1821 : 175195 : name = TREE_OPERAND (fullname, 0);
1822 : : /* Use build_typename_type rather than make_typename_type because we
1823 : : don't want to resolve it here, just strip typedefs. */
1824 : 3846016 : result = build_typename_type (ctx, name, fullname, typename_type);
1825 : : }
1826 : 3846016 : break;
1827 : 4965136 : case DECLTYPE_TYPE:
1828 : 4965136 : result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t),
1829 : : remove_attributes, flags);
1830 : 4965136 : if (result == DECLTYPE_TYPE_EXPR (t))
1831 : : result = NULL_TREE;
1832 : : else
1833 : 183811 : result = (finish_decltype_type
1834 : 183811 : (result,
1835 : 183811 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
1836 : : tf_none));
1837 : : break;
1838 : 758509 : case TRAIT_TYPE:
1839 : 758509 : {
1840 : 758509 : tree type1 = strip_typedefs (TRAIT_TYPE_TYPE1 (t),
1841 : : remove_attributes, flags);
1842 : 758509 : tree type2 = strip_typedefs (TRAIT_TYPE_TYPE2 (t),
1843 : : remove_attributes, flags);
1844 : 758509 : if (type1 == TRAIT_TYPE_TYPE1 (t) && type2 == TRAIT_TYPE_TYPE2 (t))
1845 : : result = NULL_TREE;
1846 : : else
1847 : 0 : result = finish_trait_type (TRAIT_TYPE_KIND (t), type1, type2,
1848 : : tf_warning_or_error);
1849 : : }
1850 : : break;
1851 : 22476083 : case TYPE_PACK_EXPANSION:
1852 : 22476083 : {
1853 : 22476083 : tree pat = PACK_EXPANSION_PATTERN (t);
1854 : 22476083 : if (TYPE_P (pat))
1855 : : {
1856 : 22476083 : type = strip_typedefs (pat, remove_attributes, flags);
1857 : 22476083 : if (type != pat)
1858 : : {
1859 : 131507 : result = build_distinct_type_copy (t);
1860 : 131507 : PACK_EXPANSION_PATTERN (result) = type;
1861 : : }
1862 : : }
1863 : : }
1864 : : break;
1865 : : default:
1866 : : break;
1867 : : }
1868 : :
1869 : 60218281 : if (!result)
1870 : 392428471 : result = TYPE_MAIN_VARIANT (t);
1871 : :
1872 : 60218281 : stripped:
1873 : : /*gcc_assert (!typedef_variant_p (result)
1874 : : || dependent_alias_template_spec_p (result, nt_opaque)
1875 : : || ((flags & STF_USER_VISIBLE)
1876 : : && !user_facing_original_type_p (result)));*/
1877 : :
1878 : 621029214 : if (COMPLETE_TYPE_P (result) && !COMPLETE_TYPE_P (t))
1879 : : /* If RESULT is complete and T isn't, it's likely the case that T
1880 : : is a variant of RESULT which hasn't been updated yet. Skip the
1881 : : attribute handling. */;
1882 : : else
1883 : : {
1884 : 621029208 : if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
1885 : 621029208 : || TYPE_ALIGN (t) != TYPE_ALIGN (result))
1886 : : {
1887 : 21 : gcc_assert (TYPE_USER_ALIGN (t));
1888 : 21 : if (remove_attributes)
1889 : 12 : *remove_attributes = true;
1890 : : else
1891 : : {
1892 : 9 : if (TYPE_ALIGN (t) == TYPE_ALIGN (result))
1893 : 0 : result = build_variant_type_copy (result);
1894 : : else
1895 : 9 : result = build_aligned_type (result, TYPE_ALIGN (t));
1896 : 9 : TYPE_USER_ALIGN (result) = true;
1897 : : }
1898 : : }
1899 : :
1900 : 621029208 : if (TYPE_ATTRIBUTES (t))
1901 : : {
1902 : 3401240 : if (remove_attributes)
1903 : 3391153 : result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t),
1904 : : remove_attributes);
1905 : : else
1906 : 10087 : result = cp_build_type_attribute_variant (result,
1907 : 10087 : TYPE_ATTRIBUTES (t));
1908 : : }
1909 : : }
1910 : :
1911 : 621029214 : return cp_build_qualified_type (result, cp_type_quals (t));
1912 : : }
1913 : :
1914 : : /* Like strip_typedefs above, but works on expressions (and other
1915 : : non-types such as TREE_VEC), so that in
1916 : :
1917 : : template<class T> struct A
1918 : : {
1919 : : typedef T TT;
1920 : : B<sizeof(TT)> b;
1921 : : };
1922 : :
1923 : : sizeof(TT) is replaced by sizeof(T). */
1924 : :
1925 : : tree
1926 : 277602604 : strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags)
1927 : : {
1928 : 277602604 : unsigned i,n;
1929 : 277602604 : tree r, type, *ops;
1930 : 277602604 : enum tree_code code;
1931 : :
1932 : 277602604 : if (t == NULL_TREE || t == error_mark_node)
1933 : : return t;
1934 : :
1935 : 277602604 : STRIP_ANY_LOCATION_WRAPPER (t);
1936 : :
1937 : 277602604 : if (DECL_P (t) || CONSTANT_CLASS_P (t))
1938 : : return t;
1939 : :
1940 : 163977989 : code = TREE_CODE (t);
1941 : 163977989 : switch (code)
1942 : : {
1943 : : case IDENTIFIER_NODE:
1944 : : case TEMPLATE_PARM_INDEX:
1945 : : case OVERLOAD:
1946 : : case BASELINK:
1947 : : case ARGUMENT_PACK_SELECT:
1948 : : return t;
1949 : :
1950 : 2017823 : case TRAIT_EXPR:
1951 : 2017823 : {
1952 : 2017823 : tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t),
1953 : : remove_attributes, flags);
1954 : 2017823 : tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t),
1955 : : remove_attributes, flags);
1956 : 2017823 : if (type1 == TRAIT_EXPR_TYPE1 (t)
1957 : 2017823 : && type2 == TRAIT_EXPR_TYPE2 (t))
1958 : : return t;
1959 : 49006 : r = copy_node (t);
1960 : 49006 : TRAIT_EXPR_TYPE1 (r) = type1;
1961 : 49006 : TRAIT_EXPR_TYPE2 (r) = type2;
1962 : 49006 : return r;
1963 : : }
1964 : :
1965 : 907503 : case TREE_LIST:
1966 : 907503 : {
1967 : 907503 : bool changed = false;
1968 : 907503 : auto_vec<tree_pair, 4> vec;
1969 : 907503 : r = t;
1970 : 1912940 : for (; t; t = TREE_CHAIN (t))
1971 : : {
1972 : 1005437 : tree purpose = strip_typedefs (TREE_PURPOSE (t),
1973 : 1005437 : remove_attributes, flags);
1974 : 1005437 : tree value = strip_typedefs (TREE_VALUE (t),
1975 : 1005437 : remove_attributes, flags);
1976 : 1005437 : if (purpose != TREE_PURPOSE (t) || value != TREE_VALUE (t))
1977 : : changed = true;
1978 : 1005437 : vec.safe_push ({purpose, value});
1979 : : }
1980 : 907503 : if (changed)
1981 : : {
1982 : 180289 : r = NULL_TREE;
1983 : 585622 : for (int i = vec.length () - 1; i >= 0; i--)
1984 : 225044 : r = tree_cons (vec[i].first, vec[i].second, r);
1985 : : }
1986 : 907503 : return r;
1987 : 907503 : }
1988 : :
1989 : 13326914 : case TREE_VEC:
1990 : 13326914 : {
1991 : 13326914 : bool changed = false;
1992 : 13326914 : releasing_vec vec;
1993 : 13326914 : n = TREE_VEC_LENGTH (t);
1994 : 13326914 : vec_safe_reserve (vec, n);
1995 : 30628646 : for (i = 0; i < n; ++i)
1996 : : {
1997 : 17301732 : tree op = strip_typedefs (TREE_VEC_ELT (t, i),
1998 : 17301732 : remove_attributes, flags);
1999 : 17301732 : vec->quick_push (op);
2000 : 17301732 : if (op != TREE_VEC_ELT (t, i))
2001 : 102236 : changed = true;
2002 : : }
2003 : 13326914 : if (changed)
2004 : : {
2005 : 102236 : r = copy_node (t);
2006 : 326171 : for (i = 0; i < n; ++i)
2007 : 121699 : TREE_VEC_ELT (r, i) = (*vec)[i];
2008 : 204472 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
2009 : 204472 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
2010 : : }
2011 : : else
2012 : : r = t;
2013 : 13326914 : return r;
2014 : 13326914 : }
2015 : :
2016 : 146534 : case CONSTRUCTOR:
2017 : 146534 : {
2018 : 146534 : bool changed = false;
2019 : 146534 : vec<constructor_elt, va_gc> *vec
2020 : 146534 : = vec_safe_copy (CONSTRUCTOR_ELTS (t));
2021 : 146534 : n = CONSTRUCTOR_NELTS (t);
2022 : 146534 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
2023 : 165933 : for (i = 0; i < n; ++i)
2024 : : {
2025 : 19399 : constructor_elt *e = &(*vec)[i];
2026 : 19399 : tree op = strip_typedefs (e->value, remove_attributes, flags);
2027 : 19399 : if (op != e->value)
2028 : : {
2029 : 6 : changed = true;
2030 : 6 : e->value = op;
2031 : : }
2032 : 19399 : gcc_checking_assert
2033 : : (e->index == strip_typedefs (e->index, remove_attributes,
2034 : : flags));
2035 : : }
2036 : :
2037 : 146534 : if (!changed && type == TREE_TYPE (t))
2038 : : {
2039 : 125024 : vec_free (vec);
2040 : 125024 : return t;
2041 : : }
2042 : : else
2043 : : {
2044 : 21510 : r = copy_node (t);
2045 : 21510 : TREE_TYPE (r) = type;
2046 : 21510 : CONSTRUCTOR_ELTS (r) = vec;
2047 : 21510 : return r;
2048 : : }
2049 : : }
2050 : :
2051 : : case LAMBDA_EXPR:
2052 : : case STMT_EXPR:
2053 : : return t;
2054 : :
2055 : 88495684 : default:
2056 : 88495684 : break;
2057 : : }
2058 : :
2059 : 88495684 : gcc_assert (EXPR_P (t));
2060 : :
2061 : 88495684 : n = cp_tree_operand_length (t);
2062 : 88495684 : ops = XALLOCAVEC (tree, n);
2063 : 88495684 : type = TREE_TYPE (t);
2064 : :
2065 : 88495684 : switch (code)
2066 : : {
2067 : 6440507 : CASE_CONVERT:
2068 : 6440507 : case IMPLICIT_CONV_EXPR:
2069 : 6440507 : case DYNAMIC_CAST_EXPR:
2070 : 6440507 : case STATIC_CAST_EXPR:
2071 : 6440507 : case CONST_CAST_EXPR:
2072 : 6440507 : case REINTERPRET_CAST_EXPR:
2073 : 6440507 : case CAST_EXPR:
2074 : 6440507 : case NEW_EXPR:
2075 : 6440507 : type = strip_typedefs (type, remove_attributes, flags);
2076 : : /* fallthrough */
2077 : :
2078 : 88495684 : default:
2079 : 277374162 : for (i = 0; i < n; ++i)
2080 : 188878478 : ops[i] = strip_typedefs (TREE_OPERAND (t, i),
2081 : : remove_attributes, flags);
2082 : : break;
2083 : : }
2084 : :
2085 : : /* If nothing changed, return t. */
2086 : 271953453 : for (i = 0; i < n; ++i)
2087 : 186672678 : if (ops[i] != TREE_OPERAND (t, i))
2088 : : break;
2089 : 88495684 : if (i == n && type == TREE_TYPE (t))
2090 : : return t;
2091 : :
2092 : 3454189 : r = copy_node (t);
2093 : 3454189 : TREE_TYPE (r) = type;
2094 : 10904513 : for (i = 0; i < n; ++i)
2095 : 7450324 : TREE_OPERAND (r, i) = ops[i];
2096 : : return r;
2097 : : }
2098 : :
2099 : : /* Makes a copy of BINFO and TYPE, which is to be inherited into a
2100 : : graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
2101 : : and we do a shallow copy. If BINFO is non-NULL, we do a deep copy.
2102 : : VIRT indicates whether TYPE is inherited virtually or not.
2103 : : IGO_PREV points at the previous binfo of the inheritance graph
2104 : : order chain. The newly copied binfo's TREE_CHAIN forms this
2105 : : ordering.
2106 : :
2107 : : The CLASSTYPE_VBASECLASSES vector of T is constructed in the
2108 : : correct order. That is in the order the bases themselves should be
2109 : : constructed in.
2110 : :
2111 : : The BINFO_INHERITANCE of a virtual base class points to the binfo
2112 : : of the most derived type. ??? We could probably change this so that
2113 : : BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
2114 : : remove a field. They currently can only differ for primary virtual
2115 : : virtual bases. */
2116 : :
2117 : : tree
2118 : 30782388 : copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
2119 : : {
2120 : 30782388 : tree new_binfo;
2121 : :
2122 : 30782388 : if (virt)
2123 : : {
2124 : : /* See if we've already made this virtual base. */
2125 : 289277 : new_binfo = binfo_for_vbase (type, t);
2126 : 289277 : if (new_binfo)
2127 : : return new_binfo;
2128 : : }
2129 : :
2130 : 55007903 : new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
2131 : 30712782 : BINFO_TYPE (new_binfo) = type;
2132 : :
2133 : : /* Chain it into the inheritance graph. */
2134 : 30712782 : TREE_CHAIN (*igo_prev) = new_binfo;
2135 : 30712782 : *igo_prev = new_binfo;
2136 : :
2137 : 55007903 : if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
2138 : : {
2139 : 24295112 : int ix;
2140 : 24295112 : tree base_binfo;
2141 : :
2142 : 24295112 : gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
2143 : :
2144 : 24295112 : BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
2145 : 24295112 : BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
2146 : :
2147 : : /* We do not need to copy the accesses, as they are read only. */
2148 : 24295112 : BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
2149 : :
2150 : : /* Recursively copy base binfos of BINFO. */
2151 : 27830307 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
2152 : : {
2153 : 3535195 : tree new_base_binfo;
2154 : 3535195 : new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
2155 : : t, igo_prev,
2156 : 3535195 : BINFO_VIRTUAL_P (base_binfo));
2157 : :
2158 : 3535195 : if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
2159 : 3313850 : BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
2160 : 3535195 : BINFO_BASE_APPEND (new_binfo, new_base_binfo);
2161 : : }
2162 : : }
2163 : : else
2164 : 6417670 : BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
2165 : :
2166 : 30712782 : if (virt)
2167 : : {
2168 : : /* Push it onto the list after any virtual bases it contains
2169 : : will have been pushed. */
2170 : 219671 : CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo);
2171 : 219671 : BINFO_VIRTUAL_P (new_binfo) = 1;
2172 : 219671 : BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
2173 : : }
2174 : :
2175 : : return new_binfo;
2176 : : }
2177 : :
2178 : : /* Hashing of lists so that we don't make duplicates.
2179 : : The entry point is `list_hash_canon'. */
2180 : :
2181 : : struct list_proxy
2182 : : {
2183 : : tree purpose;
2184 : : tree value;
2185 : : tree chain;
2186 : : };
2187 : :
2188 : : struct list_hasher : ggc_ptr_hash<tree_node>
2189 : : {
2190 : : typedef list_proxy *compare_type;
2191 : :
2192 : : static hashval_t hash (tree);
2193 : : static bool equal (tree, list_proxy *);
2194 : : };
2195 : :
2196 : : /* Now here is the hash table. When recording a list, it is added
2197 : : to the slot whose index is the hash code mod the table size.
2198 : : Note that the hash table is used for several kinds of lists.
2199 : : While all these live in the same table, they are completely independent,
2200 : : and the hash code is computed differently for each of these. */
2201 : :
2202 : : static GTY (()) hash_table<list_hasher> *list_hash_table;
2203 : :
2204 : : /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
2205 : : for a node we are thinking about adding). */
2206 : :
2207 : : bool
2208 : 1762080784 : list_hasher::equal (tree t, list_proxy *proxy)
2209 : : {
2210 : 1762080784 : return (TREE_VALUE (t) == proxy->value
2211 : 133709472 : && TREE_PURPOSE (t) == proxy->purpose
2212 : 1894036216 : && TREE_CHAIN (t) == proxy->chain);
2213 : : }
2214 : :
2215 : : /* Compute a hash code for a list (chain of TREE_LIST nodes
2216 : : with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
2217 : : TREE_COMMON slots), by adding the hash codes of the individual entries. */
2218 : :
2219 : : static hashval_t
2220 : 1611357300 : list_hash_pieces (tree purpose, tree value, tree chain)
2221 : : {
2222 : 1611357300 : hashval_t hashcode = 0;
2223 : :
2224 : 1611357300 : if (chain)
2225 : 1609385426 : hashcode += TREE_HASH (chain);
2226 : :
2227 : 1611357300 : if (value)
2228 : 1611357300 : hashcode += TREE_HASH (value);
2229 : : else
2230 : 0 : hashcode += 1007;
2231 : 1611357300 : if (purpose)
2232 : 167078788 : hashcode += TREE_HASH (purpose);
2233 : : else
2234 : 1444278512 : hashcode += 1009;
2235 : 1611357300 : return hashcode;
2236 : : }
2237 : :
2238 : : /* Hash an already existing TREE_LIST. */
2239 : :
2240 : : hashval_t
2241 : 1364644666 : list_hasher::hash (tree t)
2242 : : {
2243 : 1364644666 : return list_hash_pieces (TREE_PURPOSE (t),
2244 : 1364644666 : TREE_VALUE (t),
2245 : 1364644666 : TREE_CHAIN (t));
2246 : : }
2247 : :
2248 : : /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
2249 : : object for an identical list if one already exists. Otherwise, build a
2250 : : new one, and record it as the canonical object. */
2251 : :
2252 : : tree
2253 : 246712634 : hash_tree_cons (tree purpose, tree value, tree chain)
2254 : : {
2255 : 246712634 : int hashcode = 0;
2256 : 246712634 : tree *slot;
2257 : 246712634 : struct list_proxy proxy;
2258 : :
2259 : : /* Hash the list node. */
2260 : 246712634 : hashcode = list_hash_pieces (purpose, value, chain);
2261 : : /* Create a proxy for the TREE_LIST we would like to create. We
2262 : : don't actually create it so as to avoid creating garbage. */
2263 : 246712634 : proxy.purpose = purpose;
2264 : 246712634 : proxy.value = value;
2265 : 246712634 : proxy.chain = chain;
2266 : : /* See if it is already in the table. */
2267 : 246712634 : slot = list_hash_table->find_slot_with_hash (&proxy, hashcode, INSERT);
2268 : : /* If not, create a new node. */
2269 : 246712634 : if (!*slot)
2270 : 120120140 : *slot = tree_cons (purpose, value, chain);
2271 : 246712634 : return (tree) *slot;
2272 : : }
2273 : :
2274 : : /* Constructor for hashed lists. */
2275 : :
2276 : : tree
2277 : 2144518 : hash_tree_chain (tree value, tree chain)
2278 : : {
2279 : 2144518 : return hash_tree_cons (NULL_TREE, value, chain);
2280 : : }
2281 : :
2282 : : void
2283 : 0 : debug_binfo (tree elem)
2284 : : {
2285 : 0 : HOST_WIDE_INT n;
2286 : 0 : tree virtuals;
2287 : :
2288 : 0 : fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
2289 : : "\nvtable type:\n",
2290 : 0 : TYPE_NAME_STRING (BINFO_TYPE (elem)),
2291 : 0 : TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
2292 : 0 : debug_tree (BINFO_TYPE (elem));
2293 : 0 : if (BINFO_VTABLE (elem))
2294 : 0 : fprintf (stderr, "vtable decl \"%s\"\n",
2295 : 0 : IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
2296 : : else
2297 : 0 : fprintf (stderr, "no vtable decl yet\n");
2298 : 0 : fprintf (stderr, "virtuals:\n");
2299 : 0 : virtuals = BINFO_VIRTUALS (elem);
2300 : 0 : n = 0;
2301 : :
2302 : 0 : while (virtuals)
2303 : : {
2304 : 0 : tree fndecl = TREE_VALUE (virtuals);
2305 : 0 : fprintf (stderr, "%s [" HOST_WIDE_INT_PRINT_DEC " =? "
2306 : : HOST_WIDE_INT_PRINT_DEC "]\n",
2307 : 0 : IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
2308 : 0 : n, TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
2309 : 0 : ++n;
2310 : 0 : virtuals = TREE_CHAIN (virtuals);
2311 : : }
2312 : 0 : }
2313 : :
2314 : : /* Build a representation for the qualified name SCOPE::NAME. TYPE is
2315 : : the type of the result expression, if known, or NULL_TREE if the
2316 : : resulting expression is type-dependent. If TEMPLATE_P is true,
2317 : : NAME is known to be a template because the user explicitly used the
2318 : : "template" keyword after the "::".
2319 : :
2320 : : All SCOPE_REFs should be built by use of this function. */
2321 : :
2322 : : tree
2323 : 147412843 : build_qualified_name (tree type, tree scope, tree name, bool template_p)
2324 : : {
2325 : 147412843 : tree t;
2326 : 147412843 : if (type == error_mark_node
2327 : 147412843 : || scope == error_mark_node
2328 : 147412840 : || name == error_mark_node)
2329 : : return error_mark_node;
2330 : 147412840 : gcc_assert (TREE_CODE (name) != SCOPE_REF);
2331 : 147412840 : t = build2 (SCOPE_REF, type, scope, name);
2332 : 147412840 : QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
2333 : 147412840 : PTRMEM_OK_P (t) = true;
2334 : 147412840 : if (type)
2335 : 9582213 : t = convert_from_reference (t);
2336 : : return t;
2337 : : }
2338 : :
2339 : : /* Like check_qualified_type, but also check ref-qualifier, exception
2340 : : specification, and whether the return type was specified after the
2341 : : parameters. */
2342 : :
2343 : : static bool
2344 : 1012020144 : cp_check_qualified_type (const_tree cand, const_tree base, int type_quals,
2345 : : cp_ref_qualifier rqual, tree raises, bool late)
2346 : : {
2347 : 1012020144 : return (TYPE_QUALS (cand) == type_quals
2348 : 1011970681 : && check_base_type (cand, base)
2349 : 1011932989 : && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand),
2350 : : ce_exact)
2351 : 497736615 : && TYPE_HAS_LATE_RETURN_TYPE (cand) == late
2352 : 1478496884 : && type_memfn_rqual (cand) == rqual);
2353 : : }
2354 : :
2355 : : /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */
2356 : :
2357 : : tree
2358 : 583429 : build_ref_qualified_type (tree type, cp_ref_qualifier rqual)
2359 : : {
2360 : 583429 : tree raises = TYPE_RAISES_EXCEPTIONS (type);
2361 : 583429 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
2362 : 583429 : return build_cp_fntype_variant (type, rqual, raises, late);
2363 : : }
2364 : :
2365 : : tree
2366 : 153522 : make_binding_vec (tree name, unsigned clusters MEM_STAT_DECL)
2367 : : {
2368 : : /* Stored in an unsigned short, but we're limited to the number of
2369 : : modules anyway. */
2370 : 153522 : gcc_checking_assert (clusters <= (unsigned short)(~0));
2371 : 153522 : size_t length = (offsetof (tree_binding_vec, vec)
2372 : 153522 : + clusters * sizeof (binding_cluster));
2373 : 153522 : tree vec = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2374 : 153522 : TREE_SET_CODE (vec, BINDING_VECTOR);
2375 : 153522 : BINDING_VECTOR_NAME (vec) = name;
2376 : 153522 : BINDING_VECTOR_ALLOC_CLUSTERS (vec) = clusters;
2377 : 153522 : BINDING_VECTOR_NUM_CLUSTERS (vec) = 0;
2378 : :
2379 : 153522 : return vec;
2380 : : }
2381 : :
2382 : : /* Make a raw overload node containing FN. */
2383 : :
2384 : : tree
2385 : 288415778 : ovl_make (tree fn, tree next)
2386 : : {
2387 : 288415778 : tree result = make_node (OVERLOAD);
2388 : :
2389 : 288415778 : if (TREE_CODE (fn) == OVERLOAD)
2390 : 9939543 : OVL_NESTED_P (result) = true;
2391 : :
2392 : 387912420 : TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL
2393 : 387912420 : ? unknown_type_node : TREE_TYPE (fn));
2394 : 288415778 : if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
2395 : 14180611 : OVL_DEDUP_P (result) = true;
2396 : 288415778 : OVL_FUNCTION (result) = fn;
2397 : 288415778 : OVL_CHAIN (result) = next;
2398 : 288415778 : return result;
2399 : : }
2400 : :
2401 : : /* Add FN to the (potentially NULL) overload set OVL. USING_OR_HIDDEN is > 0
2402 : : if this is a using-decl. It is > 1 if we're revealing the using decl.
2403 : : It is > 2 if we're also exporting it. USING_OR_HIDDEN is < 0, if FN is
2404 : : hidden. (A decl cannot be both using and hidden.) We keep the hidden
2405 : : decls first, but remaining ones are unordered. */
2406 : :
2407 : : tree
2408 : 594011626 : ovl_insert (tree fn, tree maybe_ovl, int using_or_hidden)
2409 : : {
2410 : 594011626 : tree result = maybe_ovl;
2411 : 594011626 : tree insert_after = NULL_TREE;
2412 : :
2413 : : /* Skip hidden. */
2414 : 805888554 : for (; maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD
2415 : 815553810 : && OVL_HIDDEN_P (maybe_ovl);
2416 : 55602191 : maybe_ovl = OVL_CHAIN (maybe_ovl))
2417 : : {
2418 : 55602191 : gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl));
2419 : 55602191 : insert_after = maybe_ovl;
2420 : : }
2421 : :
2422 : 594011626 : if (maybe_ovl || using_or_hidden || TREE_CODE (fn) == TEMPLATE_DECL)
2423 : : {
2424 : 254018915 : maybe_ovl = ovl_make (fn, maybe_ovl);
2425 : :
2426 : 254018915 : if (using_or_hidden < 0)
2427 : 70575853 : OVL_HIDDEN_P (maybe_ovl) = true;
2428 : 254018915 : if (using_or_hidden > 0)
2429 : : {
2430 : 11618777 : OVL_DEDUP_P (maybe_ovl) = OVL_USING_P (maybe_ovl) = true;
2431 : 11618777 : if (using_or_hidden > 1)
2432 : 8396 : OVL_PURVIEW_P (maybe_ovl) = true;
2433 : 8396 : if (using_or_hidden > 2)
2434 : 7878 : OVL_EXPORT_P (maybe_ovl) = true;
2435 : : }
2436 : : }
2437 : : else
2438 : : maybe_ovl = fn;
2439 : :
2440 : 594011626 : if (insert_after)
2441 : : {
2442 : 7976393 : OVL_CHAIN (insert_after) = maybe_ovl;
2443 : 7976393 : TREE_TYPE (insert_after) = unknown_type_node;
2444 : : }
2445 : : else
2446 : : result = maybe_ovl;
2447 : :
2448 : 594011626 : return result;
2449 : : }
2450 : :
2451 : : /* Skip any hidden names at the beginning of OVL. */
2452 : :
2453 : : tree
2454 : 1513237637 : ovl_skip_hidden (tree ovl)
2455 : : {
2456 : 2327833010 : while (ovl && TREE_CODE (ovl) == OVERLOAD && OVL_HIDDEN_P (ovl))
2457 : 814595373 : ovl = OVL_CHAIN (ovl);
2458 : :
2459 : 1513237637 : return ovl;
2460 : : }
2461 : :
2462 : : /* NODE is an OVL_HIDDEN_P node that is now revealed. */
2463 : :
2464 : : tree
2465 : 3743983 : ovl_iterator::reveal_node (tree overload, tree node)
2466 : : {
2467 : : /* We cannot have returned NODE as part of a lookup overload, so we
2468 : : don't have to worry about preserving that. */
2469 : :
2470 : 3743983 : OVL_HIDDEN_P (node) = false;
2471 : 3743983 : if (tree chain = OVL_CHAIN (node))
2472 : 174895 : if (TREE_CODE (chain) == OVERLOAD)
2473 : : {
2474 : 165374 : if (OVL_HIDDEN_P (chain))
2475 : : {
2476 : : /* The node needs moving, and the simplest way is to remove it
2477 : : and reinsert. */
2478 : 75895 : overload = remove_node (overload, node);
2479 : 75895 : overload = ovl_insert (OVL_FUNCTION (node), overload);
2480 : : }
2481 : 89479 : else if (OVL_DEDUP_P (chain))
2482 : 9 : OVL_DEDUP_P (node) = true;
2483 : : }
2484 : 3743983 : return overload;
2485 : : }
2486 : :
2487 : : /* NODE is on the overloads of OVL. Remove it.
2488 : : The removed node is unaltered and may continue to be iterated
2489 : : from (i.e. it is safe to remove a node from an overload one is
2490 : : currently iterating over). */
2491 : :
2492 : : tree
2493 : 244119 : ovl_iterator::remove_node (tree overload, tree node)
2494 : : {
2495 : 244119 : tree *slot = &overload;
2496 : 1557735 : while (*slot != node)
2497 : : {
2498 : 1313616 : tree probe = *slot;
2499 : 1313616 : gcc_checking_assert (!OVL_LOOKUP_P (probe));
2500 : :
2501 : 1313616 : slot = &OVL_CHAIN (probe);
2502 : : }
2503 : :
2504 : : /* Stitch out NODE. We don't have to worry about now making a
2505 : : singleton overload (and consequently maybe setting its type),
2506 : : because all uses of this function will be followed by inserting a
2507 : : new node that must follow the place we've cut this out from. */
2508 : 244119 : if (TREE_CODE (node) != OVERLOAD)
2509 : : /* Cloned inherited ctors don't mark themselves as via_using. */
2510 : 110991 : *slot = NULL_TREE;
2511 : : else
2512 : 133128 : *slot = OVL_CHAIN (node);
2513 : :
2514 : 244119 : return overload;
2515 : : }
2516 : :
2517 : : /* Mark or unmark a lookup set. */
2518 : :
2519 : : void
2520 : 90042390 : lookup_mark (tree ovl, bool val)
2521 : : {
2522 : 989741712 : for (lkp_iterator iter (ovl); iter; ++iter)
2523 : : {
2524 : 899699322 : gcc_checking_assert (LOOKUP_SEEN_P (*iter) != val);
2525 : 899699322 : LOOKUP_SEEN_P (*iter) = val;
2526 : : }
2527 : 90042390 : }
2528 : :
2529 : : /* Add a set of new FNS into a lookup. */
2530 : :
2531 : : tree
2532 : 478186365 : lookup_add (tree fns, tree lookup)
2533 : : {
2534 : 478186365 : if (fns == error_mark_node || lookup == error_mark_node)
2535 : : return error_mark_node;
2536 : :
2537 : 478186353 : if (lookup || TREE_CODE (fns) == TEMPLATE_DECL)
2538 : : {
2539 : 30855261 : lookup = ovl_make (fns, lookup);
2540 : 30855261 : OVL_LOOKUP_P (lookup) = true;
2541 : : }
2542 : : else
2543 : : lookup = fns;
2544 : :
2545 : : return lookup;
2546 : : }
2547 : :
2548 : : /* FNS is a new overload set, add them to LOOKUP, if they are not
2549 : : already present there. */
2550 : :
2551 : : tree
2552 : 478556335 : lookup_maybe_add (tree fns, tree lookup, bool deduping)
2553 : : {
2554 : 478556335 : if (deduping)
2555 : 547271780 : for (tree next, probe = fns; probe; probe = next)
2556 : : {
2557 : 495114984 : tree fn = probe;
2558 : 495114984 : next = NULL_TREE;
2559 : :
2560 : 495114984 : if (TREE_CODE (probe) == OVERLOAD)
2561 : : {
2562 : 482872396 : fn = OVL_FUNCTION (probe);
2563 : 482872396 : next = OVL_CHAIN (probe);
2564 : : }
2565 : :
2566 : 495114984 : if (!LOOKUP_SEEN_P (fn))
2567 : 363581922 : LOOKUP_SEEN_P (fn) = true;
2568 : : else
2569 : : {
2570 : : /* This function was already seen. Insert all the
2571 : : predecessors onto the lookup. */
2572 : 141207086 : for (; fns != probe; fns = OVL_CHAIN (fns))
2573 : : {
2574 : : /* Propagate OVL_USING, but OVL_HIDDEN &
2575 : : OVL_DEDUP_P don't matter. */
2576 : 9674024 : if (OVL_USING_P (fns))
2577 : : {
2578 : 10260 : lookup = ovl_make (OVL_FUNCTION (fns), lookup);
2579 : 10260 : OVL_USING_P (lookup) = true;
2580 : : }
2581 : : else
2582 : 9663764 : lookup = lookup_add (OVL_FUNCTION (fns), lookup);
2583 : : }
2584 : :
2585 : : /* And now skip this function. */
2586 : : fns = next;
2587 : : }
2588 : : }
2589 : :
2590 : 478556335 : if (fns)
2591 : : /* We ended in a set of new functions. Add them all in one go. */
2592 : 467849746 : lookup = lookup_add (fns, lookup);
2593 : :
2594 : 478556335 : return lookup;
2595 : : }
2596 : :
2597 : : /* Returns nonzero if X is an expression for a (possibly overloaded)
2598 : : function. If "f" is a function or function template, "f", "c->f",
2599 : : "c.f", "C::f", and "f<int>" will all be considered possibly
2600 : : overloaded functions. Returns 2 if the function is actually
2601 : : overloaded, i.e., if it is impossible to know the type of the
2602 : : function without performing overload resolution. */
2603 : :
2604 : : int
2605 : 5227751728 : is_overloaded_fn (tree x)
2606 : : {
2607 : 5227751728 : STRIP_ANY_LOCATION_WRAPPER (x);
2608 : :
2609 : : /* A baselink is also considered an overloaded function. */
2610 : 5227751728 : if (TREE_CODE (x) == OFFSET_REF
2611 : 5227685528 : || TREE_CODE (x) == COMPONENT_REF)
2612 : 241785372 : x = TREE_OPERAND (x, 1);
2613 : 5227751728 : x = MAYBE_BASELINK_FUNCTIONS (x);
2614 : 5227751728 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2615 : 120672075 : x = TREE_OPERAND (x, 0);
2616 : :
2617 : 5954527740 : if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x))
2618 : 5244744754 : || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x)))
2619 : : return 2;
2620 : :
2621 : 5463745809 : return OVL_P (x);
2622 : : }
2623 : :
2624 : : /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
2625 : : (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
2626 : : NULL_TREE. */
2627 : :
2628 : : tree
2629 : 143382745 : dependent_name (tree x)
2630 : : {
2631 : : /* FIXME a dependent name must be unqualified, but this function doesn't
2632 : : distinguish between qualified and unqualified identifiers. */
2633 : 143382745 : if (identifier_p (x))
2634 : : return x;
2635 : 143219702 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2636 : 49447357 : x = TREE_OPERAND (x, 0);
2637 : 143219702 : if (OVL_P (x))
2638 : 87177590 : return OVL_NAME (x);
2639 : : return NULL_TREE;
2640 : : }
2641 : :
2642 : : /* Like dependent_name, but instead takes a CALL_EXPR and also checks
2643 : : its dependence. */
2644 : :
2645 : : tree
2646 : 143177118 : call_expr_dependent_name (tree x)
2647 : : {
2648 : 143177118 : if (TREE_TYPE (x) != NULL_TREE)
2649 : : /* X isn't dependent, so its callee isn't a dependent name. */
2650 : : return NULL_TREE;
2651 : 142263445 : return dependent_name (CALL_EXPR_FN (x));
2652 : : }
2653 : :
2654 : : /* Returns true iff X is an expression for an overloaded function
2655 : : whose type cannot be known without performing overload
2656 : : resolution. */
2657 : :
2658 : : bool
2659 : 477501483 : really_overloaded_fn (tree x)
2660 : : {
2661 : 477501483 : return is_overloaded_fn (x) == 2;
2662 : : }
2663 : :
2664 : : /* Get the overload set FROM refers to. Returns NULL if it's not an
2665 : : overload set. */
2666 : :
2667 : : tree
2668 : 3651530764 : maybe_get_fns (tree from)
2669 : : {
2670 : 3651530764 : STRIP_ANY_LOCATION_WRAPPER (from);
2671 : :
2672 : : /* A baselink is also considered an overloaded function. */
2673 : 3651530764 : if (TREE_CODE (from) == OFFSET_REF
2674 : 3651469238 : || TREE_CODE (from) == COMPONENT_REF)
2675 : 126709527 : from = TREE_OPERAND (from, 1);
2676 : 3651530764 : if (BASELINK_P (from))
2677 : 131857736 : from = BASELINK_FUNCTIONS (from);
2678 : 3651530764 : if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
2679 : 89979637 : from = TREE_OPERAND (from, 0);
2680 : :
2681 : 3651530764 : if (OVL_P (from))
2682 : 846269062 : return from;
2683 : :
2684 : : return NULL;
2685 : : }
2686 : :
2687 : : /* FROM refers to an overload set. Return that set (or die). */
2688 : :
2689 : : tree
2690 : 570450492 : get_fns (tree from)
2691 : : {
2692 : 570450492 : tree res = maybe_get_fns (from);
2693 : :
2694 : 570450492 : gcc_assert (res);
2695 : 570450492 : return res;
2696 : : }
2697 : :
2698 : : /* Return the first function of the overload set FROM refers to. */
2699 : :
2700 : : tree
2701 : 361891632 : get_first_fn (tree from)
2702 : : {
2703 : 361891632 : return OVL_FIRST (get_fns (from));
2704 : : }
2705 : :
2706 : : /* Return the scope where the overloaded functions OVL were found. */
2707 : :
2708 : : tree
2709 : 145933557 : ovl_scope (tree ovl)
2710 : : {
2711 : 145933557 : if (TREE_CODE (ovl) == OFFSET_REF
2712 : 145933557 : || TREE_CODE (ovl) == COMPONENT_REF)
2713 : 0 : ovl = TREE_OPERAND (ovl, 1);
2714 : 145933557 : if (TREE_CODE (ovl) == BASELINK)
2715 : 38838862 : return BINFO_TYPE (BASELINK_BINFO (ovl));
2716 : 107094695 : if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
2717 : 35639577 : ovl = TREE_OPERAND (ovl, 0);
2718 : : /* Skip using-declarations. */
2719 : 107094695 : lkp_iterator iter (ovl);
2720 : 115280538 : do
2721 : 115280538 : ovl = *iter;
2722 : 222375233 : while (iter.using_p () && ++iter);
2723 : :
2724 : 107094695 : return CP_DECL_CONTEXT (ovl);
2725 : : }
2726 : :
2727 : : #define PRINT_RING_SIZE 4
2728 : :
2729 : : static const char *
2730 : 126876 : cxx_printable_name_internal (tree decl, int v, bool translate)
2731 : : {
2732 : 126876 : static unsigned int uid_ring[PRINT_RING_SIZE];
2733 : 126876 : static char *print_ring[PRINT_RING_SIZE];
2734 : 126876 : static bool trans_ring[PRINT_RING_SIZE];
2735 : 126876 : static int ring_counter;
2736 : 126876 : int i;
2737 : :
2738 : : /* Only cache functions. */
2739 : 126876 : if (v < 2
2740 : 53591 : || TREE_CODE (decl) != FUNCTION_DECL
2741 : 177193 : || DECL_LANG_SPECIFIC (decl) == 0)
2742 : 77756 : return lang_decl_name (decl, v, translate);
2743 : :
2744 : : /* See if this print name is lying around. */
2745 : 225370 : for (i = 0; i < PRINT_RING_SIZE; i++)
2746 : 184651 : if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
2747 : : /* yes, so return it. */
2748 : 8401 : return print_ring[i];
2749 : :
2750 : 40719 : if (++ring_counter == PRINT_RING_SIZE)
2751 : 7548 : ring_counter = 0;
2752 : :
2753 : 40719 : if (current_function_decl != NULL_TREE)
2754 : : {
2755 : : /* There may be both translated and untranslated versions of the
2756 : : name cached. */
2757 : 104445 : for (i = 0; i < 2; i++)
2758 : : {
2759 : 69630 : if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
2760 : 67 : ring_counter += 1;
2761 : 69630 : if (ring_counter == PRINT_RING_SIZE)
2762 : 4 : ring_counter = 0;
2763 : : }
2764 : 34815 : gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
2765 : : }
2766 : :
2767 : 40719 : free (print_ring[ring_counter]);
2768 : :
2769 : 40719 : print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate));
2770 : 40719 : uid_ring[ring_counter] = DECL_UID (decl);
2771 : 40719 : trans_ring[ring_counter] = translate;
2772 : 40719 : return print_ring[ring_counter];
2773 : : }
2774 : :
2775 : : const char *
2776 : 126876 : cxx_printable_name (tree decl, int v)
2777 : : {
2778 : 126876 : return cxx_printable_name_internal (decl, v, false);
2779 : : }
2780 : :
2781 : : const char *
2782 : 0 : cxx_printable_name_translate (tree decl, int v)
2783 : : {
2784 : 0 : return cxx_printable_name_internal (decl, v, true);
2785 : : }
2786 : :
2787 : : /* Return the canonical version of exception-specification RAISES for a C++17
2788 : : function type, for use in type comparison and building TYPE_CANONICAL. */
2789 : :
2790 : : tree
2791 : 164359639 : canonical_eh_spec (tree raises)
2792 : : {
2793 : 164359639 : if (raises == NULL_TREE)
2794 : : return raises;
2795 : 148824625 : else if (DEFERRED_NOEXCEPT_SPEC_P (raises)
2796 : 124657087 : || UNPARSED_NOEXCEPT_SPEC_P (raises)
2797 : 118838985 : || uses_template_parms (raises)
2798 : 118838985 : || uses_template_parms (TREE_PURPOSE (raises)))
2799 : : /* Keep a dependent or deferred exception specification. */
2800 : 32023930 : return raises;
2801 : 116800695 : else if (nothrow_spec_p (raises))
2802 : : /* throw() -> noexcept. */
2803 : 116407251 : return noexcept_true_spec;
2804 : : else
2805 : : /* For C++17 type matching, anything else -> nothing. */
2806 : : return NULL_TREE;
2807 : : }
2808 : :
2809 : : tree
2810 : 611103299 : build_cp_fntype_variant (tree type, cp_ref_qualifier rqual,
2811 : : tree raises, bool late)
2812 : : {
2813 : 611103299 : cp_cv_quals type_quals = TYPE_QUALS (type);
2814 : :
2815 : 611103299 : if (cp_check_qualified_type (type, type, type_quals, rqual, raises, late))
2816 : : return type;
2817 : :
2818 : 253816350 : tree v = TYPE_MAIN_VARIANT (type);
2819 : 547581363 : for (; v; v = TYPE_NEXT_VARIANT (v))
2820 : 400916845 : if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late))
2821 : : return v;
2822 : :
2823 : : /* Need to build a new variant. */
2824 : 146664518 : v = build_variant_type_copy (type);
2825 : 146664518 : if (!TYPE_DEPENDENT_P (v))
2826 : : /* We no longer know that it's not type-dependent. */
2827 : 145937410 : TYPE_DEPENDENT_P_VALID (v) = false;
2828 : 146664518 : TYPE_RAISES_EXCEPTIONS (v) = raises;
2829 : 146664518 : TYPE_HAS_LATE_RETURN_TYPE (v) = late;
2830 : 146664518 : switch (rqual)
2831 : : {
2832 : 772078 : case REF_QUAL_RVALUE:
2833 : 772078 : FUNCTION_RVALUE_QUALIFIED (v) = 1;
2834 : 772078 : FUNCTION_REF_QUALIFIED (v) = 1;
2835 : 772078 : break;
2836 : 769449 : case REF_QUAL_LVALUE:
2837 : 769449 : FUNCTION_RVALUE_QUALIFIED (v) = 0;
2838 : 769449 : FUNCTION_REF_QUALIFIED (v) = 1;
2839 : 769449 : break;
2840 : 145122991 : default:
2841 : 145122991 : FUNCTION_REF_QUALIFIED (v) = 0;
2842 : 145122991 : break;
2843 : : }
2844 : :
2845 : : /* Canonicalize the exception specification. */
2846 : 146664518 : tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE;
2847 : 139641530 : bool complex_eh_spec_p = (cr && cr != noexcept_true_spec
2848 : 176940866 : && !UNPARSED_NOEXCEPT_SPEC_P (cr));
2849 : :
2850 : 121259414 : if (!complex_eh_spec_p && TYPE_RAISES_EXCEPTIONS (type))
2851 : : /* We want to consider structural equality of the exception-less
2852 : : variant since we'll be replacing the exception specification. */
2853 : 4018404 : type = build_cp_fntype_variant (type, rqual, /*raises=*/NULL_TREE, late);
2854 : 146664518 : if (TYPE_STRUCTURAL_EQUALITY_P (type) || complex_eh_spec_p)
2855 : : /* Propagate structural equality. And always use structural equality
2856 : : for function types with a complex noexcept-spec since their identity
2857 : : may depend on e.g. whether comparing_specializations is set. */
2858 : 36590786 : SET_TYPE_STRUCTURAL_EQUALITY (v);
2859 : 110073732 : else if (TYPE_CANONICAL (type) != type || cr != raises || late)
2860 : : /* Build the underlying canonical type, since it is different
2861 : : from TYPE. */
2862 : 46941569 : TYPE_CANONICAL (v) = build_cp_fntype_variant (TYPE_CANONICAL (type),
2863 : : rqual, cr, false);
2864 : : else
2865 : : /* T is its own canonical type. */
2866 : 63132163 : TYPE_CANONICAL (v) = v;
2867 : :
2868 : : return v;
2869 : : }
2870 : :
2871 : : /* TYPE is a function or method type with a deferred exception
2872 : : specification that has been parsed to RAISES. Fixup all the type
2873 : : variants that are affected in place. Via decltype &| noexcept
2874 : : tricks, the unparsed spec could have escaped into the type system. */
2875 : :
2876 : : void
2877 : 2413731 : fixup_deferred_exception_variants (tree type, tree raises)
2878 : : {
2879 : 2413731 : tree original = TYPE_RAISES_EXCEPTIONS (type);
2880 : :
2881 : 4827462 : gcc_checking_assert (UNPARSED_NOEXCEPT_SPEC_P (original));
2882 : :
2883 : 2413731 : for (tree variant = TYPE_MAIN_VARIANT (type);
2884 : 8046274 : variant; variant = TYPE_NEXT_VARIANT (variant))
2885 : 5632543 : if (TYPE_RAISES_EXCEPTIONS (variant) == original)
2886 : : {
2887 : 2668899 : gcc_checking_assert (variant != TYPE_MAIN_VARIANT (type));
2888 : :
2889 : 2668899 : SET_TYPE_STRUCTURAL_EQUALITY (variant);
2890 : 2668899 : TYPE_RAISES_EXCEPTIONS (variant) = raises;
2891 : :
2892 : 2668899 : if (!TYPE_DEPENDENT_P (variant))
2893 : : /* We no longer know that it's not type-dependent. */
2894 : 255363 : TYPE_DEPENDENT_P_VALID (variant) = false;
2895 : : }
2896 : 2413731 : }
2897 : :
2898 : : /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
2899 : : listed in RAISES. */
2900 : :
2901 : : tree
2902 : 147990168 : build_exception_variant (tree type, tree raises)
2903 : : {
2904 : 147990168 : cp_ref_qualifier rqual = type_memfn_rqual (type);
2905 : 147990168 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
2906 : 147990168 : return build_cp_fntype_variant (type, rqual, raises, late);
2907 : : }
2908 : :
2909 : : /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
2910 : : BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
2911 : : arguments. */
2912 : :
2913 : : tree
2914 : 237621 : bind_template_template_parm (tree t, tree newargs)
2915 : : {
2916 : 237621 : tree decl = TYPE_NAME (t);
2917 : 237621 : tree t2;
2918 : :
2919 : 237621 : t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
2920 : 237621 : decl = build_decl (input_location,
2921 : 237621 : TYPE_DECL, DECL_NAME (decl), NULL_TREE);
2922 : 237621 : SET_DECL_TEMPLATE_PARM_P (decl);
2923 : :
2924 : : /* These nodes have to be created to reflect new TYPE_DECL and template
2925 : : arguments. */
2926 : 237621 : TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
2927 : 237621 : TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
2928 : 237621 : TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
2929 : 475242 : = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
2930 : :
2931 : 237621 : TREE_TYPE (decl) = t2;
2932 : 237621 : TYPE_NAME (t2) = decl;
2933 : 237621 : TYPE_STUB_DECL (t2) = decl;
2934 : 237621 : TYPE_SIZE (t2) = 0;
2935 : :
2936 : 237621 : if (any_template_arguments_need_structural_equality_p (newargs))
2937 : 13 : SET_TYPE_STRUCTURAL_EQUALITY (t2);
2938 : : else
2939 : 237608 : TYPE_CANONICAL (t2) = canonical_type_parameter (t2);
2940 : :
2941 : 237621 : return t2;
2942 : : }
2943 : :
2944 : : /* Called from count_trees via walk_tree. */
2945 : :
2946 : : static tree
2947 : 0 : count_trees_r (tree *tp, int *walk_subtrees, void *data)
2948 : : {
2949 : 0 : ++*((int *) data);
2950 : :
2951 : 0 : if (TYPE_P (*tp))
2952 : 0 : *walk_subtrees = 0;
2953 : :
2954 : 0 : return NULL_TREE;
2955 : : }
2956 : :
2957 : : /* Debugging function for measuring the rough complexity of a tree
2958 : : representation. */
2959 : :
2960 : : int
2961 : 0 : count_trees (tree t)
2962 : : {
2963 : 0 : int n_trees = 0;
2964 : 0 : cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
2965 : 0 : return n_trees;
2966 : : }
2967 : :
2968 : : /* Called from verify_stmt_tree via walk_tree. */
2969 : :
2970 : : static tree
2971 : 511338 : verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data)
2972 : : {
2973 : 511338 : tree t = *tp;
2974 : 511338 : hash_table<nofree_ptr_hash <tree_node> > *statements
2975 : : = static_cast <hash_table<nofree_ptr_hash <tree_node> > *> (data);
2976 : 511338 : tree_node **slot;
2977 : :
2978 : 511338 : if (!STATEMENT_CODE_P (TREE_CODE (t)))
2979 : : return NULL_TREE;
2980 : :
2981 : : /* If this statement is already present in the hash table, then
2982 : : there is a circularity in the statement tree. */
2983 : 25770 : gcc_assert (!statements->find (t));
2984 : :
2985 : 25770 : slot = statements->find_slot (t, INSERT);
2986 : 25770 : *slot = t;
2987 : :
2988 : 25770 : return NULL_TREE;
2989 : : }
2990 : :
2991 : : /* Debugging function to check that the statement T has not been
2992 : : corrupted. For now, this function simply checks that T contains no
2993 : : circularities. */
2994 : :
2995 : : void
2996 : 1356 : verify_stmt_tree (tree t)
2997 : : {
2998 : 1356 : hash_table<nofree_ptr_hash <tree_node> > statements (37);
2999 : 1356 : cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
3000 : 1356 : }
3001 : :
3002 : : /* Check if the type T depends on a type with no linkage and if so,
3003 : : return it. If RELAXED_P then do not consider a class type declared
3004 : : within a vague-linkage function or in a module CMI to have no linkage,
3005 : : since it can still be accessed within a different TU. Remember:
3006 : : no-linkage is not the same as internal-linkage. */
3007 : :
3008 : : tree
3009 : 275614370 : no_linkage_check (tree t, bool relaxed_p)
3010 : : {
3011 : 275614370 : tree r;
3012 : :
3013 : : /* Lambda types that don't have mangling scope have no linkage. We
3014 : : check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
3015 : : when we get here from pushtag none of the lambda information is
3016 : : set up yet, so we want to assume that the lambda has linkage and
3017 : : fix it up later if not. We need to check this even in templates so
3018 : : that we properly handle a lambda-expression in the signature. */
3019 : 309109853 : if (LAMBDA_TYPE_P (t)
3020 : 277481265 : && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node)
3021 : : {
3022 : 1100642 : tree extra = LAMBDA_TYPE_EXTRA_SCOPE (t);
3023 : 1100642 : if (!extra)
3024 : : return t;
3025 : : }
3026 : :
3027 : : /* Otherwise there's no point in checking linkage on template functions; we
3028 : : can't know their complete types. */
3029 : 275613568 : if (processing_template_decl)
3030 : : return NULL_TREE;
3031 : :
3032 : 162620701 : switch (TREE_CODE (t))
3033 : : {
3034 : 82377605 : case RECORD_TYPE:
3035 : 82377605 : if (TYPE_PTRMEMFUNC_P (t))
3036 : 126098 : goto ptrmem;
3037 : : /* Fall through. */
3038 : 83416579 : case UNION_TYPE:
3039 : 83416579 : if (!CLASS_TYPE_P (t))
3040 : : return NULL_TREE;
3041 : : /* Fall through. */
3042 : 86840474 : case ENUMERAL_TYPE:
3043 : : /* Only treat unnamed types as having no linkage if they're at
3044 : : namespace scope. This is core issue 966. */
3045 : 176988457 : if (TYPE_UNNAMED_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
3046 : : return t;
3047 : :
3048 : 86114094 : for (r = CP_TYPE_CONTEXT (t); ; )
3049 : : {
3050 : : /* If we're a nested type of a !TREE_PUBLIC class, we might not
3051 : : have linkage, or we might just be in an anonymous namespace.
3052 : : If we're in a TREE_PUBLIC class, we have linkage. */
3053 : 88233400 : if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
3054 : 78246 : return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
3055 : 88155154 : else if (TREE_CODE (r) == FUNCTION_DECL)
3056 : : {
3057 : 2473846 : if (relaxed_p
3058 : 2473846 : && (vague_linkage_p (r)
3059 : 6746 : || (TREE_PUBLIC (r) && module_maybe_has_cmi_p ())))
3060 : 2119306 : r = CP_DECL_CONTEXT (r);
3061 : : else
3062 : 354540 : return t;
3063 : : }
3064 : : else
3065 : : break;
3066 : : }
3067 : :
3068 : : return NULL_TREE;
3069 : :
3070 : 22219422 : case ARRAY_TYPE:
3071 : 22219422 : case POINTER_TYPE:
3072 : 22219422 : case REFERENCE_TYPE:
3073 : 22219422 : case VECTOR_TYPE:
3074 : 22219422 : return no_linkage_check (TREE_TYPE (t), relaxed_p);
3075 : :
3076 : 129393 : case OFFSET_TYPE:
3077 : 129393 : ptrmem:
3078 : 129393 : r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
3079 : : relaxed_p);
3080 : 129393 : if (r)
3081 : : return r;
3082 : 129393 : return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
3083 : :
3084 : 18918896 : case METHOD_TYPE:
3085 : 18918896 : case FUNCTION_TYPE:
3086 : 18918896 : {
3087 : 18918896 : tree parm = TYPE_ARG_TYPES (t);
3088 : 18918896 : if (TREE_CODE (t) == METHOD_TYPE)
3089 : : /* The 'this' pointer isn't interesting; a method has the same
3090 : : linkage (or lack thereof) as its enclosing class. */
3091 : 9821658 : parm = TREE_CHAIN (parm);
3092 : 24230889 : for (;
3093 : 43149785 : parm && parm != void_list_node;
3094 : 24230889 : parm = TREE_CHAIN (parm))
3095 : : {
3096 : 24572270 : r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
3097 : 24572270 : if (r)
3098 : : return r;
3099 : : }
3100 : 18577515 : return no_linkage_check (TREE_TYPE (t), relaxed_p);
3101 : : }
3102 : :
3103 : : default:
3104 : : return NULL_TREE;
3105 : : }
3106 : : }
3107 : :
3108 : : extern int depth_reached;
3109 : :
3110 : : void
3111 : 0 : cxx_print_statistics (void)
3112 : : {
3113 : 0 : print_template_statistics ();
3114 : 0 : if (GATHER_STATISTICS)
3115 : : fprintf (stderr, "maximum template instantiation depth reached: %d\n",
3116 : : depth_reached);
3117 : 0 : }
3118 : :
3119 : : /* Return, as an INTEGER_CST node, the number of elements for TYPE
3120 : : (which is an ARRAY_TYPE). This one is a recursive count of all
3121 : : ARRAY_TYPEs that are clumped together. */
3122 : :
3123 : : tree
3124 : 3068 : array_type_nelts_total (tree type)
3125 : : {
3126 : 3068 : tree sz = array_type_nelts_top (type);
3127 : 3068 : type = TREE_TYPE (type);
3128 : 3328 : while (TREE_CODE (type) == ARRAY_TYPE)
3129 : : {
3130 : 260 : tree n = array_type_nelts_top (type);
3131 : 260 : sz = fold_build2_loc (input_location,
3132 : : MULT_EXPR, sizetype, sz, n);
3133 : 260 : type = TREE_TYPE (type);
3134 : : }
3135 : 3068 : return sz;
3136 : : }
3137 : :
3138 : : struct bot_data
3139 : : {
3140 : : splay_tree target_remap;
3141 : : bool clear_location;
3142 : : };
3143 : :
3144 : : /* Called from break_out_target_exprs via mapcar. */
3145 : :
3146 : : static tree
3147 : 21322673 : bot_manip (tree* tp, int* walk_subtrees, void* data_)
3148 : : {
3149 : 21322673 : bot_data &data = *(bot_data*)data_;
3150 : 21322673 : splay_tree target_remap = data.target_remap;
3151 : 21322673 : tree t = *tp;
3152 : :
3153 : 21322673 : if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t))
3154 : : {
3155 : : /* There can't be any TARGET_EXPRs or their slot variables below this
3156 : : point. But we must make a copy, in case subsequent processing
3157 : : alters any part of it. For example, during gimplification a cast
3158 : : of the form (T) &X::f (where "f" is a member function) will lead
3159 : : to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */
3160 : 8746353 : *walk_subtrees = 0;
3161 : 8746353 : *tp = unshare_expr (t);
3162 : 8746353 : return NULL_TREE;
3163 : : }
3164 : 12576320 : if (TREE_CODE (t) == TARGET_EXPR)
3165 : : {
3166 : 371949 : tree u;
3167 : :
3168 : 371949 : if (TREE_CODE (TARGET_EXPR_INITIAL (t)) == AGGR_INIT_EXPR)
3169 : : {
3170 : 291108 : u = build_cplus_new (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
3171 : : tf_warning_or_error);
3172 : 291108 : if (u == error_mark_node)
3173 : : return u;
3174 : 291108 : if (AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (t)))
3175 : 1156 : AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (u)) = true;
3176 : : }
3177 : : else
3178 : 80841 : u = force_target_expr (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
3179 : : tf_warning_or_error);
3180 : :
3181 : 371949 : TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
3182 : 371949 : TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
3183 : 371949 : TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
3184 : 371949 : TARGET_EXPR_ELIDING_P (u) = TARGET_EXPR_ELIDING_P (t);
3185 : :
3186 : : /* Map the old variable to the new one. */
3187 : 1115847 : splay_tree_insert (target_remap,
3188 : 371949 : (splay_tree_key) TARGET_EXPR_SLOT (t),
3189 : 371949 : (splay_tree_value) TARGET_EXPR_SLOT (u));
3190 : :
3191 : 371949 : TARGET_EXPR_INITIAL (u) = break_out_target_exprs (TARGET_EXPR_INITIAL (u),
3192 : 371949 : data.clear_location);
3193 : 371949 : if (TARGET_EXPR_INITIAL (u) == error_mark_node)
3194 : : return error_mark_node;
3195 : :
3196 : 371949 : if (data.clear_location)
3197 : 278084 : SET_EXPR_LOCATION (u, input_location);
3198 : :
3199 : : /* Replace the old expression with the new version. */
3200 : 371949 : *tp = u;
3201 : : /* We don't have to go below this point; the recursive call to
3202 : : break_out_target_exprs will have handled anything below this
3203 : : point. */
3204 : 371949 : *walk_subtrees = 0;
3205 : 371949 : return NULL_TREE;
3206 : : }
3207 : 12204371 : if (TREE_CODE (*tp) == SAVE_EXPR)
3208 : : {
3209 : 98745 : t = *tp;
3210 : 98745 : splay_tree_node n = splay_tree_lookup (target_remap,
3211 : : (splay_tree_key) t);
3212 : 98745 : if (n)
3213 : : {
3214 : 49380 : *tp = (tree)n->value;
3215 : 49380 : *walk_subtrees = 0;
3216 : : }
3217 : : else
3218 : : {
3219 : 49365 : copy_tree_r (tp, walk_subtrees, NULL);
3220 : 49365 : splay_tree_insert (target_remap,
3221 : : (splay_tree_key)t,
3222 : 49365 : (splay_tree_value)*tp);
3223 : : /* Make sure we don't remap an already-remapped SAVE_EXPR. */
3224 : 49365 : splay_tree_insert (target_remap,
3225 : : (splay_tree_key)*tp,
3226 : 49365 : (splay_tree_value)*tp);
3227 : : }
3228 : 98745 : return NULL_TREE;
3229 : : }
3230 : 12105626 : if (TREE_CODE (*tp) == DECL_EXPR
3231 : 25 : && VAR_P (DECL_EXPR_DECL (*tp))
3232 : 25 : && DECL_ARTIFICIAL (DECL_EXPR_DECL (*tp))
3233 : 12105651 : && !TREE_STATIC (DECL_EXPR_DECL (*tp)))
3234 : : {
3235 : 25 : tree t;
3236 : 25 : splay_tree_node n
3237 : 50 : = splay_tree_lookup (target_remap,
3238 : 25 : (splay_tree_key) DECL_EXPR_DECL (*tp));
3239 : 25 : if (n)
3240 : 1 : t = (tree) n->value;
3241 : : else
3242 : : {
3243 : 24 : t = create_temporary_var (TREE_TYPE (DECL_EXPR_DECL (*tp)));
3244 : 24 : DECL_INITIAL (t) = DECL_INITIAL (DECL_EXPR_DECL (*tp));
3245 : 48 : splay_tree_insert (target_remap,
3246 : 24 : (splay_tree_key) DECL_EXPR_DECL (*tp),
3247 : : (splay_tree_value) t);
3248 : : }
3249 : 25 : copy_tree_r (tp, walk_subtrees, NULL);
3250 : 25 : DECL_EXPR_DECL (*tp) = t;
3251 : 25 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3252 : 12 : SET_EXPR_LOCATION (*tp, input_location);
3253 : 25 : return NULL_TREE;
3254 : : }
3255 : 12105601 : if (TREE_CODE (*tp) == BIND_EXPR && BIND_EXPR_VARS (*tp))
3256 : : {
3257 : 1 : copy_tree_r (tp, walk_subtrees, NULL);
3258 : 2 : for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
3259 : : {
3260 : 1 : gcc_assert (VAR_P (*p) && DECL_ARTIFICIAL (*p) && !TREE_STATIC (*p));
3261 : 1 : tree t = create_temporary_var (TREE_TYPE (*p));
3262 : 1 : DECL_INITIAL (t) = DECL_INITIAL (*p);
3263 : 1 : DECL_CHAIN (t) = DECL_CHAIN (*p);
3264 : 1 : splay_tree_insert (target_remap, (splay_tree_key) *p,
3265 : : (splay_tree_value) t);
3266 : 1 : *p = t;
3267 : : }
3268 : 1 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3269 : 0 : SET_EXPR_LOCATION (*tp, input_location);
3270 : 1 : return NULL_TREE;
3271 : : }
3272 : :
3273 : : /* Make a copy of this node. */
3274 : 12105600 : t = copy_tree_r (tp, walk_subtrees, NULL);
3275 : 12105600 : if (TREE_CODE (*tp) == CALL_EXPR || TREE_CODE (*tp) == AGGR_INIT_EXPR)
3276 : 1640934 : if (!processing_template_decl)
3277 : 1640934 : set_flags_from_callee (*tp);
3278 : 12105600 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3279 : 295954 : SET_EXPR_LOCATION (*tp, input_location);
3280 : : return t;
3281 : : }
3282 : :
3283 : : /* Replace all remapped VAR_DECLs in T with their new equivalents.
3284 : : DATA is really a splay-tree mapping old variables to new
3285 : : variables. */
3286 : :
3287 : : static tree
3288 : 31810053 : bot_replace (tree* t, int */*walk_subtrees*/, void* data_)
3289 : : {
3290 : 31810053 : bot_data &data = *(bot_data*)data_;
3291 : 31810053 : splay_tree target_remap = data.target_remap;
3292 : :
3293 : 31810053 : if (VAR_P (*t))
3294 : : {
3295 : 1395842 : splay_tree_node n = splay_tree_lookup (target_remap,
3296 : : (splay_tree_key) *t);
3297 : 1395842 : if (n)
3298 : 1014 : *t = (tree) n->value;
3299 : : }
3300 : 30414211 : else if (TREE_CODE (*t) == PARM_DECL
3301 : 2535052 : && DECL_NAME (*t) == this_identifier
3302 : 31270867 : && !DECL_CONTEXT (*t))
3303 : : {
3304 : : /* In an NSDMI we need to replace the 'this' parameter we used for
3305 : : parsing with the real one for this function. */
3306 : 23332 : *t = current_class_ptr;
3307 : : }
3308 : 30390879 : else if (TREE_CODE (*t) == CONVERT_EXPR
3309 : 30390879 : && CONVERT_EXPR_VBASE_PATH (*t))
3310 : : {
3311 : : /* In an NSDMI build_base_path defers building conversions to morally
3312 : : virtual bases, and we handle it here. */
3313 : 63 : tree basetype = TREE_TYPE (*t);
3314 : 63 : *t = convert_to_base (TREE_OPERAND (*t, 0), basetype,
3315 : : /*check_access=*/false, /*nonnull=*/true,
3316 : : tf_warning_or_error);
3317 : : }
3318 : :
3319 : 31810053 : return NULL_TREE;
3320 : : }
3321 : :
3322 : : /* When we parse a default argument expression, we may create
3323 : : temporary variables via TARGET_EXPRs. When we actually use the
3324 : : default-argument expression, we make a copy of the expression
3325 : : and replace the temporaries with appropriate local versions.
3326 : :
3327 : : If CLEAR_LOCATION is true, override any EXPR_LOCATION with
3328 : : input_location. */
3329 : :
3330 : : tree
3331 : 8210970 : break_out_target_exprs (tree t, bool clear_location /* = false */)
3332 : : {
3333 : 8210970 : static int target_remap_count;
3334 : 8210970 : static splay_tree target_remap;
3335 : :
3336 : : /* We shouldn't be called on templated trees, nor do we want to
3337 : : produce them. */
3338 : 8210970 : gcc_checking_assert (!processing_template_decl);
3339 : :
3340 : 8210970 : if (!target_remap_count++)
3341 : 7839021 : target_remap = splay_tree_new (splay_tree_compare_pointers,
3342 : : /*splay_tree_delete_key_fn=*/NULL,
3343 : : /*splay_tree_delete_value_fn=*/NULL);
3344 : 8210970 : bot_data data = { target_remap, clear_location };
3345 : 8210970 : if (cp_walk_tree (&t, bot_manip, &data, NULL) == error_mark_node)
3346 : 0 : t = error_mark_node;
3347 : 8210970 : if (cp_walk_tree (&t, bot_replace, &data, NULL) == error_mark_node)
3348 : 0 : t = error_mark_node;
3349 : :
3350 : 8210970 : if (!--target_remap_count)
3351 : : {
3352 : 7839021 : splay_tree_delete (target_remap);
3353 : 7839021 : target_remap = NULL;
3354 : : }
3355 : :
3356 : 8210970 : return t;
3357 : : }
3358 : :
3359 : : /* Build an expression for the subobject of OBJ at CONSTRUCTOR index INDEX,
3360 : : which we expect to have type TYPE. */
3361 : :
3362 : : tree
3363 : 591661 : build_ctor_subob_ref (tree index, tree type, tree obj)
3364 : : {
3365 : 591661 : if (index == NULL_TREE)
3366 : : /* Can't refer to a particular member of a vector. */
3367 : : obj = NULL_TREE;
3368 : 591661 : else if (TREE_CODE (index) == INTEGER_CST)
3369 : 6793 : obj = cp_build_array_ref (input_location, obj, index, tf_none);
3370 : : else
3371 : 584868 : obj = build_class_member_access_expr (obj, index, NULL_TREE,
3372 : : /*reference*/false, tf_none);
3373 : 591661 : if (obj)
3374 : : {
3375 : 591661 : tree objtype = TREE_TYPE (obj);
3376 : 591661 : if (TREE_CODE (objtype) == ARRAY_TYPE && !TYPE_DOMAIN (objtype))
3377 : : {
3378 : : /* When the destination object refers to a flexible array member
3379 : : verify that it matches the type of the source object except
3380 : : for its domain and qualifiers. */
3381 : 83 : gcc_assert (comptypes (TYPE_MAIN_VARIANT (type),
3382 : : TYPE_MAIN_VARIANT (objtype),
3383 : : COMPARE_REDECLARATION));
3384 : : }
3385 : : else
3386 : 591578 : gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, objtype));
3387 : : }
3388 : :
3389 : 591661 : return obj;
3390 : : }
3391 : :
3392 : : struct replace_placeholders_t
3393 : : {
3394 : : tree obj; /* The object to be substituted for a PLACEHOLDER_EXPR. */
3395 : : tree exp; /* The outermost exp. */
3396 : : bool seen; /* Whether we've encountered a PLACEHOLDER_EXPR. */
3397 : : hash_set<tree> *pset; /* To avoid walking same trees multiple times. */
3398 : : };
3399 : :
3400 : : /* Like substitute_placeholder_in_expr, but handle C++ tree codes and
3401 : : build up subexpressions as we go deeper. */
3402 : :
3403 : : static tree
3404 : 17046419 : replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
3405 : : {
3406 : 17046419 : replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);
3407 : 17046419 : tree obj = d->obj;
3408 : :
3409 : 17046419 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3410 : : {
3411 : 5662377 : *walk_subtrees = false;
3412 : 5662377 : return NULL_TREE;
3413 : : }
3414 : :
3415 : 11384042 : switch (TREE_CODE (*t))
3416 : : {
3417 : : case PLACEHOLDER_EXPR:
3418 : : {
3419 : : tree x = obj;
3420 : 528 : for (; !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (*t),
3421 : 528 : TREE_TYPE (x));
3422 : 77 : x = TREE_OPERAND (x, 0))
3423 : 77 : gcc_assert (handled_component_p (x));
3424 : 451 : *t = unshare_expr (x);
3425 : 451 : *walk_subtrees = false;
3426 : 451 : d->seen = true;
3427 : : }
3428 : 451 : break;
3429 : :
3430 : 261875 : case CONSTRUCTOR:
3431 : 261875 : {
3432 : 261875 : constructor_elt *ce;
3433 : 261875 : vec<constructor_elt,va_gc> *v = CONSTRUCTOR_ELTS (*t);
3434 : : /* Don't walk into CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctors
3435 : : other than the d->exp one, those have PLACEHOLDER_EXPRs
3436 : : related to another object. */
3437 : 261875 : if ((CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t)
3438 : 514 : && *t != d->exp)
3439 : 262284 : || d->pset->add (*t))
3440 : : {
3441 : 105 : *walk_subtrees = false;
3442 : 105 : return NULL_TREE;
3443 : : }
3444 : 857007 : for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i)
3445 : : {
3446 : 595237 : tree *valp = &ce->value;
3447 : 595237 : tree type = TREE_TYPE (*valp);
3448 : 595237 : tree subob = obj;
3449 : :
3450 : : /* Elements with RANGE_EXPR index shouldn't have any
3451 : : placeholders in them. */
3452 : 595237 : if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
3453 : 2 : continue;
3454 : :
3455 : 595235 : if (TREE_CODE (*valp) == CONSTRUCTOR
3456 : 712 : && AGGREGATE_TYPE_P (type))
3457 : : {
3458 : : /* If we're looking at the initializer for OBJ, then build
3459 : : a sub-object reference. If we're looking at an
3460 : : initializer for another object, just pass OBJ down. */
3461 : 698 : if (same_type_ignoring_top_level_qualifiers_p
3462 : 698 : (TREE_TYPE (*t), TREE_TYPE (obj)))
3463 : 666 : subob = build_ctor_subob_ref (ce->index, type, obj);
3464 : 698 : if (TREE_CODE (*valp) == TARGET_EXPR)
3465 : 0 : valp = &TARGET_EXPR_INITIAL (*valp);
3466 : : }
3467 : 595235 : d->obj = subob;
3468 : 595235 : cp_walk_tree (valp, replace_placeholders_r, data_, NULL);
3469 : 595235 : d->obj = obj;
3470 : : }
3471 : 261770 : *walk_subtrees = false;
3472 : 261770 : break;
3473 : : }
3474 : :
3475 : 11121716 : default:
3476 : 11121716 : if (d->pset->add (*t))
3477 : 355363 : *walk_subtrees = false;
3478 : : break;
3479 : : }
3480 : :
3481 : : return NULL_TREE;
3482 : : }
3483 : :
3484 : : /* Replace PLACEHOLDER_EXPRs in EXP with object OBJ. SEEN_P is set if
3485 : : a PLACEHOLDER_EXPR has been encountered. */
3486 : :
3487 : : tree
3488 : 44670673 : replace_placeholders (tree exp, tree obj, bool *seen_p /*= NULL*/)
3489 : : {
3490 : : /* This is only relevant for C++14. */
3491 : 44670673 : if (cxx_dialect < cxx14)
3492 : 833209 : return exp;
3493 : :
3494 : : /* If the object isn't a (member of a) class, do nothing. */
3495 : : tree op0 = obj;
3496 : 44275939 : while (handled_component_p (op0))
3497 : 438475 : op0 = TREE_OPERAND (op0, 0);
3498 : 43837464 : if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0))))
3499 : 40223887 : return exp;
3500 : :
3501 : 3613577 : tree *tp = &exp;
3502 : 3613577 : if (TREE_CODE (exp) == TARGET_EXPR)
3503 : 264338 : tp = &TARGET_EXPR_INITIAL (exp);
3504 : 3613577 : hash_set<tree> pset;
3505 : 3613577 : replace_placeholders_t data = { obj, *tp, false, &pset };
3506 : 3613577 : cp_walk_tree (tp, replace_placeholders_r, &data, NULL);
3507 : 3613577 : if (seen_p)
3508 : 126199 : *seen_p = data.seen;
3509 : 3613577 : return exp;
3510 : 3613577 : }
3511 : :
3512 : : /* Callback function for find_placeholders. */
3513 : :
3514 : : static tree
3515 : 55519 : find_placeholders_r (tree *t, int *walk_subtrees, void *)
3516 : : {
3517 : 55519 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3518 : : {
3519 : 46973 : *walk_subtrees = false;
3520 : 46973 : return NULL_TREE;
3521 : : }
3522 : :
3523 : 8546 : switch (TREE_CODE (*t))
3524 : : {
3525 : : case PLACEHOLDER_EXPR:
3526 : : return *t;
3527 : :
3528 : 604 : case CONSTRUCTOR:
3529 : 604 : if (CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t))
3530 : 173 : *walk_subtrees = false;
3531 : : break;
3532 : :
3533 : : default:
3534 : : break;
3535 : : }
3536 : :
3537 : : return NULL_TREE;
3538 : : }
3539 : :
3540 : : /* Return true if EXP contains a PLACEHOLDER_EXPR. Don't walk into
3541 : : ctors with CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag set. */
3542 : :
3543 : : bool
3544 : 47128 : find_placeholders (tree exp)
3545 : : {
3546 : : /* This is only relevant for C++14. */
3547 : 47128 : if (cxx_dialect < cxx14)
3548 : : return false;
3549 : :
3550 : 47128 : return cp_walk_tree_without_duplicates (&exp, find_placeholders_r, NULL);
3551 : : }
3552 : :
3553 : : /* Similar to `build_nt', but for template definitions of dependent
3554 : : expressions */
3555 : :
3556 : : tree
3557 : 271845687 : build_min_nt_loc (location_t loc, enum tree_code code, ...)
3558 : : {
3559 : 271845687 : tree t;
3560 : 271845687 : int length;
3561 : 271845687 : int i;
3562 : 271845687 : va_list p;
3563 : :
3564 : 271845687 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3565 : :
3566 : 271845687 : va_start (p, code);
3567 : :
3568 : 271845687 : t = make_node (code);
3569 : 271845687 : SET_EXPR_LOCATION (t, loc);
3570 : 271845687 : length = TREE_CODE_LENGTH (code);
3571 : :
3572 : 890426250 : for (i = 0; i < length; i++)
3573 : 618580563 : TREE_OPERAND (t, i) = va_arg (p, tree);
3574 : :
3575 : 271845687 : va_end (p);
3576 : 271845687 : return t;
3577 : : }
3578 : :
3579 : : /* Similar to `build', but for template definitions. */
3580 : :
3581 : : tree
3582 : 203721046 : build_min (enum tree_code code, tree tt, ...)
3583 : : {
3584 : 203721046 : tree t;
3585 : 203721046 : int length;
3586 : 203721046 : int i;
3587 : 203721046 : va_list p;
3588 : :
3589 : 203721046 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3590 : :
3591 : 203721046 : va_start (p, tt);
3592 : :
3593 : 203721046 : t = make_node (code);
3594 : 203721046 : length = TREE_CODE_LENGTH (code);
3595 : 203721046 : TREE_TYPE (t) = tt;
3596 : :
3597 : 546403086 : for (i = 0; i < length; i++)
3598 : : {
3599 : 342682040 : tree x = va_arg (p, tree);
3600 : 342682040 : TREE_OPERAND (t, i) = x;
3601 : 342682040 : if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
3602 : 1921752 : TREE_SIDE_EFFECTS (t) = 1;
3603 : : }
3604 : :
3605 : 203721046 : va_end (p);
3606 : :
3607 : 203721046 : return t;
3608 : : }
3609 : :
3610 : : /* Similar to `build', but for template definitions of non-dependent
3611 : : expressions. NON_DEP is the non-dependent expression that has been
3612 : : built. */
3613 : :
3614 : : tree
3615 : 103023879 : build_min_non_dep (enum tree_code code, tree non_dep, ...)
3616 : : {
3617 : 103023879 : tree t;
3618 : 103023879 : int length;
3619 : 103023879 : int i;
3620 : 103023879 : va_list p;
3621 : :
3622 : 103023879 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3623 : :
3624 : 103023879 : va_start (p, non_dep);
3625 : :
3626 : 103023879 : if (REFERENCE_REF_P (non_dep))
3627 : 416866 : non_dep = TREE_OPERAND (non_dep, 0);
3628 : :
3629 : 103023879 : t = make_node (code);
3630 : 137477451 : SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep));
3631 : 103023879 : length = TREE_CODE_LENGTH (code);
3632 : 103023879 : TREE_TYPE (t) = unlowered_expr_type (non_dep);
3633 : 103023879 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3634 : :
3635 : 363298845 : for (i = 0; i < length; i++)
3636 : : {
3637 : 260274966 : tree x = va_arg (p, tree);
3638 : 260274966 : TREE_OPERAND (t, i) = x;
3639 : 260274966 : if (x && !TYPE_P (x))
3640 : 201914795 : TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
3641 : : }
3642 : :
3643 : 103023879 : va_end (p);
3644 : 103023879 : return convert_from_reference (t);
3645 : : }
3646 : :
3647 : : /* Similar to build_min_nt, but call expressions */
3648 : :
3649 : : tree
3650 : 179712978 : build_min_nt_call_vec (tree fn, vec<tree, va_gc> *args)
3651 : : {
3652 : 179712978 : tree ret, t;
3653 : 179712978 : unsigned int ix;
3654 : :
3655 : 359327739 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
3656 : 179712978 : CALL_EXPR_FN (ret) = fn;
3657 : 179712978 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
3658 : 366246074 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
3659 : 186533096 : CALL_EXPR_ARG (ret, ix) = t;
3660 : :
3661 : 179712978 : return ret;
3662 : : }
3663 : :
3664 : : /* Similar to `build_min_nt_call_vec', but for template definitions of
3665 : : non-dependent expressions. NON_DEP is the non-dependent expression
3666 : : that has been built. */
3667 : :
3668 : : tree
3669 : 11210211 : build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec)
3670 : : {
3671 : 11210211 : tree t = build_min_nt_call_vec (fn, argvec);
3672 : 11210211 : if (REFERENCE_REF_P (non_dep))
3673 : 6 : non_dep = TREE_OPERAND (non_dep, 0);
3674 : 11210211 : TREE_TYPE (t) = TREE_TYPE (non_dep);
3675 : 11210211 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3676 : 11210211 : if (argvec)
3677 : 19376174 : for (tree x : *argvec)
3678 : 8264180 : if (x && !TYPE_P (x))
3679 : 8264180 : TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
3680 : 11210211 : return convert_from_reference (t);
3681 : : }
3682 : :
3683 : : /* Similar to build_min_non_dep, but for expressions that have been resolved to
3684 : : a call to an operator overload. OP is the operator that has been
3685 : : overloaded. NON_DEP is the non-dependent expression that's been built,
3686 : : which should be a CALL_EXPR or an INDIRECT_REF to a CALL_EXPR. OVERLOAD is
3687 : : the overload that NON_DEP is calling. */
3688 : :
3689 : : tree
3690 : 3637390 : build_min_non_dep_op_overload (enum tree_code op,
3691 : : tree non_dep,
3692 : : tree overload, ...)
3693 : : {
3694 : 3637390 : va_list p;
3695 : 3637390 : int nargs, expected_nargs;
3696 : 3637390 : tree fn, call, obj = NULL_TREE;
3697 : :
3698 : 3637390 : non_dep = extract_call_expr (non_dep);
3699 : :
3700 : 3637390 : nargs = call_expr_nargs (non_dep);
3701 : :
3702 : 3637390 : expected_nargs = cp_tree_code_length (op);
3703 : 6601995 : if (DECL_OBJECT_MEMBER_FUNCTION_P (overload)
3704 : : /* For ARRAY_REF, operator[] is either a non-static member or newly
3705 : : static member, never out of class and for the static member case
3706 : : if user uses single index the operator[] needs to have a single
3707 : : argument as well, but the function is called with 2 - the object
3708 : : it is invoked on and the index. */
3709 : 6600377 : || op == ARRAY_REF)
3710 : 674410 : expected_nargs -= 1;
3711 : 3637390 : if ((op == POSTINCREMENT_EXPR
3712 : 3637390 : || op == POSTDECREMENT_EXPR)
3713 : : /* With -fpermissive non_dep could be operator++(). */
3714 : 10459 : && (!flag_permissive || nargs != expected_nargs))
3715 : 10456 : expected_nargs += 1;
3716 : 3637390 : gcc_assert (nargs == expected_nargs);
3717 : :
3718 : 3637390 : releasing_vec args;
3719 : 3637390 : va_start (p, overload);
3720 : :
3721 : 3637390 : if (!DECL_OBJECT_MEMBER_FUNCTION_P (overload))
3722 : : {
3723 : 2962987 : fn = overload;
3724 : 2962987 : if (op == ARRAY_REF)
3725 : 7 : obj = va_arg (p, tree);
3726 : 8806370 : for (int i = 0; i < nargs; i++)
3727 : : {
3728 : 5843383 : tree arg = va_arg (p, tree);
3729 : 5843383 : vec_safe_push (args, arg);
3730 : : }
3731 : : }
3732 : : else
3733 : : {
3734 : 674403 : tree object = va_arg (p, tree);
3735 : 674403 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
3736 : 674403 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
3737 : 674403 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
3738 : : object, method, NULL_TREE);
3739 : 1144995 : for (int i = 0; i < nargs; i++)
3740 : : {
3741 : 470592 : tree arg = va_arg (p, tree);
3742 : 470592 : vec_safe_push (args, arg);
3743 : : }
3744 : : }
3745 : :
3746 : 3637390 : va_end (p);
3747 : 3637390 : call = build_min_non_dep_call_vec (non_dep, fn, args);
3748 : :
3749 : 3637390 : tree call_expr = extract_call_expr (call);
3750 : 3637390 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
3751 : 3637390 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
3752 : 3637390 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
3753 : 3637390 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
3754 : :
3755 : 3637390 : if (obj)
3756 : 7 : return keep_unused_object_arg (call, obj, overload);
3757 : : return call;
3758 : 3637390 : }
3759 : :
3760 : : /* Similar to above build_min_non_dep_op_overload, but arguments
3761 : : are taken from ARGS vector. */
3762 : :
3763 : : tree
3764 : 22 : build_min_non_dep_op_overload (tree non_dep, tree overload, tree object,
3765 : : vec<tree, va_gc> *args)
3766 : : {
3767 : 22 : non_dep = extract_call_expr (non_dep);
3768 : :
3769 : 22 : unsigned int nargs = call_expr_nargs (non_dep);
3770 : 22 : tree fn = overload;
3771 : 22 : if (DECL_OBJECT_MEMBER_FUNCTION_P (overload))
3772 : : {
3773 : 14 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
3774 : 14 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
3775 : 14 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
3776 : : object, method, NULL_TREE);
3777 : 14 : object = NULL_TREE;
3778 : : }
3779 : 44 : gcc_assert (vec_safe_length (args) == nargs);
3780 : :
3781 : 22 : tree call = build_min_non_dep_call_vec (non_dep, fn, args);
3782 : :
3783 : 22 : tree call_expr = extract_call_expr (call);
3784 : 22 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
3785 : 22 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
3786 : 22 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
3787 : 22 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
3788 : :
3789 : 22 : if (object)
3790 : 8 : return keep_unused_object_arg (call, object, overload);
3791 : : return call;
3792 : : }
3793 : :
3794 : : /* Return a new tree vec copied from VEC, with ELT inserted at index IDX. */
3795 : :
3796 : : vec<tree, va_gc> *
3797 : 44 : vec_copy_and_insert (vec<tree, va_gc> *old_vec, tree elt, unsigned idx)
3798 : : {
3799 : 44 : unsigned len = vec_safe_length (old_vec);
3800 : 44 : gcc_assert (idx <= len);
3801 : :
3802 : 44 : vec<tree, va_gc> *new_vec = NULL;
3803 : 44 : vec_alloc (new_vec, len + 1);
3804 : :
3805 : 44 : unsigned i;
3806 : 147 : for (i = 0; i < len; ++i)
3807 : : {
3808 : 59 : if (i == idx)
3809 : 15 : new_vec->quick_push (elt);
3810 : 59 : new_vec->quick_push ((*old_vec)[i]);
3811 : : }
3812 : 44 : if (i == idx)
3813 : 29 : new_vec->quick_push (elt);
3814 : :
3815 : 44 : return new_vec;
3816 : : }
3817 : :
3818 : : tree
3819 : 132651 : get_type_decl (tree t)
3820 : : {
3821 : 132651 : if (TREE_CODE (t) == TYPE_DECL)
3822 : : return t;
3823 : 132651 : if (TYPE_P (t))
3824 : 132651 : return TYPE_STUB_DECL (t);
3825 : 0 : gcc_assert (t == error_mark_node);
3826 : : return t;
3827 : : }
3828 : :
3829 : : /* Returns the namespace that contains DECL, whether directly or
3830 : : indirectly. */
3831 : :
3832 : : tree
3833 : 858563507 : decl_namespace_context (tree decl)
3834 : : {
3835 : 1783847519 : while (1)
3836 : : {
3837 : 1783847519 : if (TREE_CODE (decl) == NAMESPACE_DECL)
3838 : 858563507 : return decl;
3839 : 925284012 : else if (TYPE_P (decl))
3840 : 589079509 : decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
3841 : : else
3842 : 336204503 : decl = CP_DECL_CONTEXT (decl);
3843 : : }
3844 : : }
3845 : :
3846 : : /* Returns true if decl is within an anonymous namespace, however deeply
3847 : : nested, or false otherwise. */
3848 : :
3849 : : bool
3850 : 23 : decl_anon_ns_mem_p (tree decl)
3851 : : {
3852 : 23 : return !TREE_PUBLIC (decl_namespace_context (decl));
3853 : : }
3854 : :
3855 : : /* Returns true if the enclosing scope of DECL has internal or no linkage. */
3856 : :
3857 : : bool
3858 : 1095954653 : decl_internal_context_p (const_tree decl)
3859 : : {
3860 : 2195194732 : while (TREE_CODE (decl) != NAMESPACE_DECL)
3861 : : {
3862 : : /* Classes inside anonymous namespaces have TREE_PUBLIC == 0. */
3863 : 1376526131 : if (TYPE_P (decl))
3864 : 277286052 : return !TREE_PUBLIC (TYPE_MAIN_DECL (decl));
3865 : :
3866 : 1099240079 : decl = CP_DECL_CONTEXT (decl);
3867 : : }
3868 : 818668601 : return !TREE_PUBLIC (decl);
3869 : : }
3870 : :
3871 : : /* Subroutine of cp_tree_equal: t1 and t2 are two CALL_EXPRs.
3872 : : Return whether their CALL_EXPR_FNs are equivalent. */
3873 : :
3874 : : static bool
3875 : 40120375 : called_fns_equal (tree t1, tree t2)
3876 : : {
3877 : : /* Core 1321: dependent names are equivalent even if the overload sets
3878 : : are different. But do compare explicit template arguments. */
3879 : 40120375 : tree name1 = call_expr_dependent_name (t1);
3880 : 40120375 : tree name2 = call_expr_dependent_name (t2);
3881 : 40120375 : t1 = CALL_EXPR_FN (t1);
3882 : 40120375 : t2 = CALL_EXPR_FN (t2);
3883 : 40120375 : if (name1 || name2)
3884 : : {
3885 : 17288515 : tree targs1 = NULL_TREE, targs2 = NULL_TREE;
3886 : :
3887 : 17288515 : if (name1 != name2)
3888 : : return false;
3889 : :
3890 : : /* FIXME dependent_name currently returns an unqualified name regardless
3891 : : of whether the function was named with a qualified- or unqualified-id.
3892 : : Until that's fixed, check that we aren't looking at overload sets from
3893 : : different scopes. */
3894 : 16930536 : if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
3895 : 33890284 : && (DECL_CONTEXT (get_first_fn (t1))
3896 : 16930533 : != DECL_CONTEXT (get_first_fn (t2))))
3897 : : return false;
3898 : :
3899 : 16959751 : if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
3900 : 10918177 : targs1 = TREE_OPERAND (t1, 1);
3901 : 16959751 : if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
3902 : 10918177 : targs2 = TREE_OPERAND (t2, 1);
3903 : 16959751 : return cp_tree_equal (targs1, targs2);
3904 : : }
3905 : : else
3906 : 22831860 : return cp_tree_equal (t1, t2);
3907 : : }
3908 : :
3909 : : bool comparing_override_contracts;
3910 : :
3911 : : /* In a component reference, return the innermost object of
3912 : : the postfix-expression. */
3913 : :
3914 : : static tree
3915 : 12 : get_innermost_component (tree t)
3916 : : {
3917 : 12 : gcc_assert (TREE_CODE (t) == COMPONENT_REF);
3918 : 33 : while (TREE_CODE (t) == COMPONENT_REF)
3919 : 21 : t = TREE_OPERAND (t, 0);
3920 : 12 : return t;
3921 : : }
3922 : :
3923 : : /* Returns true if T is a possibly converted 'this' or '*this' expression. */
3924 : :
3925 : : static bool
3926 : 12 : is_this_expression (tree t)
3927 : : {
3928 : 12 : t = get_innermost_component (t);
3929 : : /* See through deferences and no-op conversions. */
3930 : 12 : if (INDIRECT_REF_P (t))
3931 : 12 : t = TREE_OPERAND (t, 0);
3932 : 12 : if (TREE_CODE (t) == NOP_EXPR)
3933 : 12 : t = TREE_OPERAND (t, 0);
3934 : 12 : return is_this_parameter (t);
3935 : : }
3936 : :
3937 : : static bool
3938 : 6 : comparing_this_references (tree t1, tree t2)
3939 : : {
3940 : 6 : return is_this_expression (t1) && is_this_expression (t2);
3941 : : }
3942 : :
3943 : : static bool
3944 : 6 : equivalent_member_references (tree t1, tree t2)
3945 : : {
3946 : 6 : if (!comparing_this_references (t1, t2))
3947 : : return false;
3948 : 6 : t1 = TREE_OPERAND (t1, 1);
3949 : 6 : t2 = TREE_OPERAND (t2, 1);
3950 : 6 : return t1 == t2;
3951 : : }
3952 : :
3953 : : /* Return truthvalue of whether T1 is the same tree structure as T2.
3954 : : Return 1 if they are the same. Return 0 if they are different. */
3955 : :
3956 : : bool
3957 : 1343580339 : cp_tree_equal (tree t1, tree t2)
3958 : : {
3959 : 1345677072 : enum tree_code code1, code2;
3960 : :
3961 : 1345677072 : if (t1 == t2)
3962 : : return true;
3963 : 634657504 : if (!t1 || !t2)
3964 : : return false;
3965 : :
3966 : 634497585 : code1 = TREE_CODE (t1);
3967 : 634497585 : code2 = TREE_CODE (t2);
3968 : :
3969 : 634497585 : if (code1 != code2)
3970 : : return false;
3971 : :
3972 : 492821995 : if (CONSTANT_CLASS_P (t1)
3973 : 492821995 : && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
3974 : : return false;
3975 : :
3976 : 492746042 : switch (code1)
3977 : : {
3978 : 0 : case VOID_CST:
3979 : : /* There's only a single VOID_CST node, so we should never reach
3980 : : here. */
3981 : 0 : gcc_unreachable ();
3982 : :
3983 : 36346796 : case INTEGER_CST:
3984 : 36346796 : return tree_int_cst_equal (t1, t2);
3985 : :
3986 : 98175 : case REAL_CST:
3987 : 98175 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
3988 : :
3989 : 27892 : case STRING_CST:
3990 : 27892 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3991 : 27892 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3992 : 27892 : TREE_STRING_LENGTH (t1));
3993 : :
3994 : 0 : case FIXED_CST:
3995 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
3996 : : TREE_FIXED_CST (t2));
3997 : :
3998 : 1 : case COMPLEX_CST:
3999 : 1 : return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
4000 : 2 : && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
4001 : :
4002 : 3836 : case VECTOR_CST:
4003 : 3836 : return operand_equal_p (t1, t2, OEP_ONLY_CONST);
4004 : :
4005 : 1389524 : case CONSTRUCTOR:
4006 : : /* We need to do this when determining whether or not two
4007 : : non-type pointer to member function template arguments
4008 : : are the same. */
4009 : 1389524 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
4010 : 2990391 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
4011 : : return false;
4012 : : {
4013 : : tree field, value;
4014 : : unsigned int i;
4015 : 1379795 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
4016 : : {
4017 : 89703 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
4018 : 89703 : if (!cp_tree_equal (field, elt2->index)
4019 : 89703 : || !cp_tree_equal (value, elt2->value))
4020 : 15 : return false;
4021 : : }
4022 : : }
4023 : : return true;
4024 : :
4025 : 629484 : case TREE_LIST:
4026 : 629484 : if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
4027 : : return false;
4028 : 629484 : if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
4029 : : return false;
4030 : 63538 : return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
4031 : :
4032 : 651 : case SAVE_EXPR:
4033 : 651 : return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4034 : :
4035 : 40228642 : case CALL_EXPR:
4036 : 40228642 : {
4037 : 40228642 : if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
4038 : : return false;
4039 : :
4040 : 40120375 : if (!called_fns_equal (t1, t2))
4041 : : return false;
4042 : :
4043 : 12935156 : call_expr_arg_iterator iter1, iter2;
4044 : 12935156 : init_call_expr_arg_iterator (t1, &iter1);
4045 : 12935156 : init_call_expr_arg_iterator (t2, &iter2);
4046 : 12935156 : if (iter1.n != iter2.n)
4047 : : return false;
4048 : :
4049 : 13627863 : while (more_call_expr_args_p (&iter1))
4050 : : {
4051 : 6350389 : tree arg1 = next_call_expr_arg (&iter1);
4052 : 6350389 : tree arg2 = next_call_expr_arg (&iter2);
4053 : :
4054 : 6350389 : gcc_checking_assert (arg1 && arg2);
4055 : 6350389 : if (!cp_tree_equal (arg1, arg2))
4056 : : return false;
4057 : : }
4058 : :
4059 : : return true;
4060 : : }
4061 : :
4062 : 132270 : case TARGET_EXPR:
4063 : 132270 : {
4064 : 132270 : tree o1 = TARGET_EXPR_SLOT (t1);
4065 : 132270 : tree o2 = TARGET_EXPR_SLOT (t2);
4066 : :
4067 : : /* Special case: if either target is an unallocated VAR_DECL,
4068 : : it means that it's going to be unified with whatever the
4069 : : TARGET_EXPR is really supposed to initialize, so treat it
4070 : : as being equivalent to anything. */
4071 : 132270 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
4072 : 264540 : && !DECL_RTL_SET_P (o1))
4073 : : /*Nop*/;
4074 : 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
4075 : 0 : && !DECL_RTL_SET_P (o2))
4076 : : /*Nop*/;
4077 : 0 : else if (!cp_tree_equal (o1, o2))
4078 : : return false;
4079 : :
4080 : 132270 : return cp_tree_equal (TARGET_EXPR_INITIAL (t1),
4081 : 264540 : TARGET_EXPR_INITIAL (t2));
4082 : : }
4083 : :
4084 : 21 : case AGGR_INIT_EXPR:
4085 : 21 : {
4086 : 21 : int n = aggr_init_expr_nargs (t1);
4087 : 21 : if (n != aggr_init_expr_nargs (t2))
4088 : : return false;
4089 : :
4090 : 42 : if (!cp_tree_equal (AGGR_INIT_EXPR_FN (t1),
4091 : 21 : AGGR_INIT_EXPR_FN (t2)))
4092 : : return false;
4093 : :
4094 : 21 : tree o1 = AGGR_INIT_EXPR_SLOT (t1);
4095 : 21 : tree o2 = AGGR_INIT_EXPR_SLOT (t2);
4096 : :
4097 : : /* Similarly to TARGET_EXPRs, if the VAR_DECL is unallocated we're
4098 : : going to unify the initialization, so treat it as equivalent
4099 : : to anything. */
4100 : 21 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
4101 : 42 : && !DECL_RTL_SET_P (o1))
4102 : : /*Nop*/;
4103 : 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
4104 : 0 : && !DECL_RTL_SET_P (o2))
4105 : : /*Nop*/;
4106 : 0 : else if (!cp_tree_equal (o1, o2))
4107 : : return false;
4108 : :
4109 : 41 : for (int i = 0; i < n; ++i)
4110 : 23 : if (!cp_tree_equal (AGGR_INIT_EXPR_ARG (t1, i),
4111 : 23 : AGGR_INIT_EXPR_ARG (t2, i)))
4112 : : return false;
4113 : :
4114 : : return true;
4115 : : }
4116 : :
4117 : 386915 : case PARM_DECL:
4118 : : /* For comparing uses of parameters in late-specified return types
4119 : : with an out-of-class definition of the function, but can also come
4120 : : up for expressions that involve 'this' in a member function
4121 : : template. */
4122 : :
4123 : 386915 : if (comparing_specializations
4124 : 386915 : && DECL_CONTEXT (t1) != DECL_CONTEXT (t2))
4125 : : /* When comparing hash table entries, only an exact match is
4126 : : good enough; we don't want to replace 'this' with the
4127 : : version from another function. But be more flexible
4128 : : with parameters with identical contexts. */
4129 : : return false;
4130 : :
4131 : 110786 : if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4132 : : {
4133 : 32751 : if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
4134 : : return false;
4135 : 32751 : if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
4136 : : return false;
4137 : 32751 : if (DECL_ARTIFICIAL (t1)
4138 : 32751 : || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
4139 : 32106 : && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
4140 : : return true;
4141 : : }
4142 : : return false;
4143 : :
4144 : 15969581 : case TEMPLATE_DECL:
4145 : 15969581 : if (DECL_TEMPLATE_TEMPLATE_PARM_P (t1)
4146 : 17605327 : && DECL_TEMPLATE_TEMPLATE_PARM_P (t2))
4147 : 155737 : return cp_tree_equal (TREE_TYPE (t1), TREE_TYPE (t2));
4148 : : /* Fall through. */
4149 : : case VAR_DECL:
4150 : : case CONST_DECL:
4151 : : case FIELD_DECL:
4152 : : case FUNCTION_DECL:
4153 : : case IDENTIFIER_NODE:
4154 : : case SSA_NAME:
4155 : : case USING_DECL:
4156 : : case DEFERRED_PARSE:
4157 : : return false;
4158 : :
4159 : 13761160 : case BASELINK:
4160 : 13761160 : return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
4161 : 13147662 : && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
4162 : 13147662 : && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
4163 : 26908804 : && cp_tree_equal (BASELINK_FUNCTIONS (t1),
4164 : 13147644 : BASELINK_FUNCTIONS (t2)));
4165 : :
4166 : 12843084 : case TEMPLATE_PARM_INDEX:
4167 : 12843084 : return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
4168 : 12191204 : && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
4169 : 11652613 : && (TEMPLATE_PARM_PARAMETER_PACK (t1)
4170 : 11652613 : == TEMPLATE_PARM_PARAMETER_PACK (t2))
4171 : 24484448 : && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
4172 : : TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
4173 : :
4174 : 20481881 : case TEMPLATE_ID_EXPR:
4175 : 20481881 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4176 : : return false;
4177 : 14417902 : if (!comp_template_args (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)))
4178 : : return false;
4179 : : return true;
4180 : :
4181 : 1744126 : case CONSTRAINT_INFO:
4182 : 5232378 : return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1),
4183 : 5232378 : CI_ASSOCIATED_CONSTRAINTS (t2));
4184 : :
4185 : 25593895 : case TREE_VEC:
4186 : : /* These are template args. Really we should be getting the
4187 : : caller to do this as it knows it to be true. */
4188 : 25593895 : if (!comp_template_args (t1, t2))
4189 : : return false;
4190 : : return true;
4191 : :
4192 : 804955 : case SIZEOF_EXPR:
4193 : 804955 : case ALIGNOF_EXPR:
4194 : 804955 : {
4195 : 804955 : tree o1 = TREE_OPERAND (t1, 0);
4196 : 804955 : tree o2 = TREE_OPERAND (t2, 0);
4197 : :
4198 : 804955 : if (code1 == SIZEOF_EXPR)
4199 : : {
4200 : 795486 : if (SIZEOF_EXPR_TYPE_P (t1))
4201 : 0 : o1 = TREE_TYPE (o1);
4202 : 795486 : if (SIZEOF_EXPR_TYPE_P (t2))
4203 : 0 : o2 = TREE_TYPE (o2);
4204 : : }
4205 : 9469 : else if (ALIGNOF_EXPR_STD_P (t1) != ALIGNOF_EXPR_STD_P (t2))
4206 : : return false;
4207 : :
4208 : 804949 : if (TREE_CODE (o1) != TREE_CODE (o2))
4209 : : return false;
4210 : :
4211 : 804933 : if (ARGUMENT_PACK_P (o1))
4212 : 6 : return template_args_equal (o1, o2);
4213 : 804927 : else if (TYPE_P (o1))
4214 : 804573 : return same_type_p (o1, o2);
4215 : : else
4216 : : return cp_tree_equal (o1, o2);
4217 : : }
4218 : :
4219 : 127 : case MODOP_EXPR:
4220 : 127 : {
4221 : 127 : tree t1_op1, t2_op1;
4222 : :
4223 : 127 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4224 : : return false;
4225 : :
4226 : 127 : t1_op1 = TREE_OPERAND (t1, 1);
4227 : 127 : t2_op1 = TREE_OPERAND (t2, 1);
4228 : 127 : if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
4229 : : return false;
4230 : :
4231 : 57 : return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
4232 : : }
4233 : :
4234 : 615 : case PTRMEM_CST:
4235 : : /* Two pointer-to-members are the same if they point to the same
4236 : : field or function in the same class. */
4237 : 615 : if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
4238 : : return false;
4239 : :
4240 : 618 : return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
4241 : :
4242 : 4198504 : case OVERLOAD:
4243 : 4198504 : {
4244 : : /* Two overloads. Must be exactly the same set of decls. */
4245 : 4198504 : lkp_iterator first (t1);
4246 : 4198504 : lkp_iterator second (t2);
4247 : :
4248 : 4207108 : for (; first && second; ++first, ++second)
4249 : 4199026 : if (*first != *second)
4250 : : return false;
4251 : 8082 : return !(first || second);
4252 : : }
4253 : :
4254 : 5508355 : case TRAIT_EXPR:
4255 : 5508355 : if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
4256 : : return false;
4257 : 668772 : return cp_tree_equal (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
4258 : 1327569 : && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
4259 : :
4260 : 302261 : case NON_LVALUE_EXPR:
4261 : 302261 : case VIEW_CONVERT_EXPR:
4262 : : /* Used for location wrappers with possibly NULL types. */
4263 : 302261 : if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
4264 : : {
4265 : 21 : if (TREE_TYPE (t1) || TREE_TYPE (t2))
4266 : : return false;
4267 : : break;
4268 : : }
4269 : : /* FALLTHROUGH */
4270 : :
4271 : 2402594 : case CAST_EXPR:
4272 : 2402594 : case STATIC_CAST_EXPR:
4273 : 2402594 : case REINTERPRET_CAST_EXPR:
4274 : 2402594 : case CONST_CAST_EXPR:
4275 : 2402594 : case DYNAMIC_CAST_EXPR:
4276 : 2402594 : case IMPLICIT_CONV_EXPR:
4277 : 2402594 : case NEW_EXPR:
4278 : 2402594 : case BIT_CAST_EXPR:
4279 : 2402594 : CASE_CONVERT:
4280 : 2402594 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4281 : : return false;
4282 : : /* Now compare operands as usual. */
4283 : : break;
4284 : :
4285 : 0 : case DEFERRED_NOEXCEPT:
4286 : 0 : return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1),
4287 : 0 : DEFERRED_NOEXCEPT_PATTERN (t2))
4288 : 0 : && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1),
4289 : 0 : DEFERRED_NOEXCEPT_ARGS (t2)));
4290 : :
4291 : : case LAMBDA_EXPR:
4292 : : /* Two lambda-expressions are never considered equivalent. */
4293 : : return false;
4294 : :
4295 : 251776095 : case TYPE_ARGUMENT_PACK:
4296 : 251776095 : case NONTYPE_ARGUMENT_PACK:
4297 : 251776095 : {
4298 : 251776095 : tree p1 = ARGUMENT_PACK_ARGS (t1);
4299 : 251776095 : tree p2 = ARGUMENT_PACK_ARGS (t2);
4300 : 251776095 : int len = TREE_VEC_LENGTH (p1);
4301 : 251776095 : if (TREE_VEC_LENGTH (p2) != len)
4302 : : return false;
4303 : :
4304 : 349319165 : for (int ix = 0; ix != len; ix++)
4305 : 285692712 : if (!template_args_equal (TREE_VEC_ELT (p1, ix),
4306 : 285692712 : TREE_VEC_ELT (p2, ix)))
4307 : : return false;
4308 : : return true;
4309 : : }
4310 : :
4311 : 39308 : case EXPR_PACK_EXPANSION:
4312 : 39308 : if (!cp_tree_equal (PACK_EXPANSION_PATTERN (t1),
4313 : 39308 : PACK_EXPANSION_PATTERN (t2)))
4314 : : return false;
4315 : 17009 : if (!comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
4316 : 17009 : PACK_EXPANSION_EXTRA_ARGS (t2)))
4317 : : return false;
4318 : : return true;
4319 : :
4320 : 10 : case PACK_INDEX_EXPR:
4321 : 10 : if (!cp_tree_equal (PACK_INDEX_PACK (t1),
4322 : 10 : PACK_INDEX_PACK (t2)))
4323 : : return false;
4324 : 8 : if (!cp_tree_equal (PACK_INDEX_INDEX (t1),
4325 : 8 : PACK_INDEX_INDEX (t2)))
4326 : : return false;
4327 : : return true;
4328 : :
4329 : 433794 : case COMPONENT_REF:
4330 : : /* If we're comparing contract conditions of overrides, member references
4331 : : compare equal if they designate the same member. */
4332 : 433794 : if (comparing_override_contracts)
4333 : 6 : return equivalent_member_references (t1, t2);
4334 : : break;
4335 : :
4336 : : default:
4337 : : break;
4338 : : }
4339 : :
4340 : 44909159 : switch (TREE_CODE_CLASS (code1))
4341 : : {
4342 : 39616855 : case tcc_unary:
4343 : 39616855 : case tcc_binary:
4344 : 39616855 : case tcc_comparison:
4345 : 39616855 : case tcc_expression:
4346 : 39616855 : case tcc_vl_exp:
4347 : 39616855 : case tcc_reference:
4348 : 39616855 : case tcc_statement:
4349 : 39616855 : {
4350 : 39616855 : int n = cp_tree_operand_length (t1);
4351 : 39616855 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
4352 : 39616855 : && n != TREE_OPERAND_LENGTH (t2))
4353 : : return false;
4354 : :
4355 : 78937131 : for (int i = 0; i < n; ++i)
4356 : 58545917 : if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
4357 : : return false;
4358 : :
4359 : : return true;
4360 : : }
4361 : :
4362 : 5292304 : case tcc_type:
4363 : 5292304 : return same_type_p (t1, t2);
4364 : :
4365 : 0 : default:
4366 : 0 : gcc_unreachable ();
4367 : : }
4368 : :
4369 : : /* We can get here with --disable-checking. */
4370 : : return false;
4371 : : }
4372 : :
4373 : : /* The type of ARG when used as an lvalue. */
4374 : :
4375 : : tree
4376 : 599256580 : lvalue_type (tree arg)
4377 : : {
4378 : 599256580 : tree type = TREE_TYPE (arg);
4379 : 599256580 : return type;
4380 : : }
4381 : :
4382 : : /* The type of ARG for printing error messages; denote lvalues with
4383 : : reference types. */
4384 : :
4385 : : tree
4386 : 3643 : error_type (tree arg)
4387 : : {
4388 : 3643 : tree type = TREE_TYPE (arg);
4389 : :
4390 : 3643 : if (TREE_CODE (type) == ARRAY_TYPE)
4391 : : ;
4392 : 3535 : else if (TREE_CODE (type) == ERROR_MARK)
4393 : : ;
4394 : 3535 : else if (lvalue_p (arg))
4395 : 1251 : type = build_reference_type (lvalue_type (arg));
4396 : 2284 : else if (MAYBE_CLASS_TYPE_P (type))
4397 : 744 : type = lvalue_type (arg);
4398 : :
4399 : 3643 : return type;
4400 : : }
4401 : :
4402 : : /* Does FUNCTION use a variable-length argument list? */
4403 : :
4404 : : int
4405 : 250986 : varargs_function_p (const_tree function)
4406 : : {
4407 : 250986 : return stdarg_p (TREE_TYPE (function));
4408 : : }
4409 : :
4410 : : /* Returns 1 if decl is a member of a class. */
4411 : :
4412 : : int
4413 : 10336 : member_p (const_tree decl)
4414 : : {
4415 : 10336 : const_tree const ctx = DECL_CONTEXT (decl);
4416 : 10336 : return (ctx && TYPE_P (ctx));
4417 : : }
4418 : :
4419 : : /* Create a placeholder for member access where we don't actually have an
4420 : : object that the access is against. For a general declval<T> equivalent,
4421 : : use build_stub_object instead. */
4422 : :
4423 : : tree
4424 : 59023988 : build_dummy_object (tree type)
4425 : : {
4426 : 59023988 : tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node);
4427 : 59023988 : return cp_build_fold_indirect_ref (decl);
4428 : : }
4429 : :
4430 : : /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
4431 : : or a dummy object otherwise. If BINFOP is non-0, it is filled with the
4432 : : binfo path from current_class_type to TYPE, or 0. */
4433 : :
4434 : : tree
4435 : 93697357 : maybe_dummy_object (tree type, tree* binfop)
4436 : : {
4437 : 93697357 : tree decl, context;
4438 : 93697357 : tree binfo;
4439 : 93697357 : tree current = current_nonlambda_class_type ();
4440 : :
4441 : 93697357 : if (current
4442 : 93697357 : && (binfo = lookup_base (current, type, ba_any, NULL,
4443 : : tf_warning_or_error)))
4444 : : context = current;
4445 : : else
4446 : : {
4447 : : /* Reference from a nested class member function. */
4448 : 11122687 : context = type;
4449 : 11122687 : binfo = TYPE_BINFO (type);
4450 : : }
4451 : :
4452 : 93697357 : if (binfop)
4453 : 108309 : *binfop = binfo;
4454 : :
4455 : : /* current_class_ref might not correspond to current_class_type if
4456 : : we're in tsubst_default_argument or a lambda-declarator; in either
4457 : : case, we want to use current_class_ref if it matches CONTEXT. */
4458 : 93697357 : tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE;
4459 : 87104222 : if (ctype
4460 : 87104222 : && same_type_ignoring_top_level_qualifiers_p (ctype, context))
4461 : 80044291 : decl = current_class_ref;
4462 : : else
4463 : : {
4464 : : /* Return a dummy object whose cv-quals are consistent with (the
4465 : : non-lambda) 'this' if available. */
4466 : 13653066 : if (ctype)
4467 : : {
4468 : 7059931 : int quals = TYPE_UNQUALIFIED;
4469 : 7059931 : if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype))
4470 : : {
4471 : 269469 : if (tree cap = lambda_expr_this_capture (lambda, false))
4472 : 264504 : quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap)));
4473 : : }
4474 : : else
4475 : 6790462 : quals = cp_type_quals (ctype);
4476 : 7059931 : context = cp_build_qualified_type (context, quals);
4477 : : }
4478 : 13653066 : decl = build_dummy_object (context);
4479 : : }
4480 : :
4481 : 93697357 : return decl;
4482 : : }
4483 : :
4484 : : /* Returns 1 if OB is a placeholder object, or a pointer to one. */
4485 : :
4486 : : bool
4487 : 405902779 : is_dummy_object (const_tree ob)
4488 : : {
4489 : 405902779 : if (INDIRECT_REF_P (ob))
4490 : 319505891 : ob = TREE_OPERAND (ob, 0);
4491 : 405902779 : return (TREE_CODE (ob) == CONVERT_EXPR
4492 : 405902779 : && TREE_OPERAND (ob, 0) == void_node);
4493 : : }
4494 : :
4495 : : /* Returns true if TYPE is char, unsigned char, or std::byte. */
4496 : :
4497 : : bool
4498 : 25280729 : is_byte_access_type (tree type)
4499 : : {
4500 : 25280729 : type = TYPE_MAIN_VARIANT (type);
4501 : 25280729 : if (type == char_type_node
4502 : 4452486 : || type == unsigned_char_type_node)
4503 : : return true;
4504 : :
4505 : 4332262 : return (TREE_CODE (type) == ENUMERAL_TYPE
4506 : 7038 : && TYPE_CONTEXT (type) == std_node
4507 : 4336750 : && !strcmp ("byte", TYPE_NAME_STRING (type)));
4508 : : }
4509 : :
4510 : : /* Returns true if TYPE is unsigned char or std::byte. */
4511 : :
4512 : : bool
4513 : 2145 : is_byte_access_type_not_plain_char (tree type)
4514 : : {
4515 : 2145 : type = TYPE_MAIN_VARIANT (type);
4516 : 2145 : if (type == char_type_node)
4517 : : return false;
4518 : :
4519 : 1897 : return is_byte_access_type (type);
4520 : : }
4521 : :
4522 : : /* Returns 1 iff type T is something we want to treat as a scalar type for
4523 : : the purpose of deciding whether it is trivial/POD/standard-layout. */
4524 : :
4525 : : bool
4526 : 56492058 : scalarish_type_p (const_tree t)
4527 : : {
4528 : 56492058 : if (t == error_mark_node)
4529 : : return 1;
4530 : :
4531 : 56491859 : return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
4532 : : }
4533 : :
4534 : : /* Returns true iff T requires non-trivial default initialization. */
4535 : :
4536 : : bool
4537 : 0 : type_has_nontrivial_default_init (const_tree t)
4538 : : {
4539 : 0 : t = strip_array_types (CONST_CAST_TREE (t));
4540 : :
4541 : 0 : if (CLASS_TYPE_P (t))
4542 : 0 : return TYPE_HAS_COMPLEX_DFLT (t);
4543 : : else
4544 : : return 0;
4545 : : }
4546 : :
4547 : : /* Track classes with only deleted copy/move constructors so that we can warn
4548 : : if they are used in call/return by value. */
4549 : :
4550 : : static GTY(()) hash_set<tree>* deleted_copy_types;
4551 : : static void
4552 : 9 : remember_deleted_copy (const_tree t)
4553 : : {
4554 : 9 : if (!deleted_copy_types)
4555 : 9 : deleted_copy_types = hash_set<tree>::create_ggc(37);
4556 : 9 : deleted_copy_types->add (CONST_CAST_TREE (t));
4557 : 9 : }
4558 : : void
4559 : 293057135 : maybe_warn_parm_abi (tree t, location_t loc)
4560 : : {
4561 : 293057135 : if (!deleted_copy_types
4562 : 293057135 : || !deleted_copy_types->contains (t))
4563 : 293057105 : return;
4564 : :
4565 : 30 : if ((flag_abi_version == 12 || warn_abi_version == 12)
4566 : 36 : && classtype_has_non_deleted_move_ctor (t))
4567 : : {
4568 : 6 : bool w;
4569 : 6 : auto_diagnostic_group d;
4570 : 6 : if (flag_abi_version > 12)
4571 : 0 : w = warning_at (loc, OPT_Wabi, "%<-fabi-version=13%> (GCC 8.2) fixes "
4572 : : "the calling convention for %qT, which was "
4573 : : "accidentally changed in 8.1", t);
4574 : : else
4575 : 6 : w = warning_at (loc, OPT_Wabi, "%<-fabi-version=12%> (GCC 8.1) "
4576 : : "accidentally changes the calling convention for %qT",
4577 : : t);
4578 : 6 : if (w)
4579 : 6 : inform (location_of (t), " declared here");
4580 : 6 : return;
4581 : 6 : }
4582 : :
4583 : 30 : auto_diagnostic_group d;
4584 : 30 : if (warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in "
4585 : : "%<-fabi-version=13%> (GCC 8.2)", t))
4586 : 30 : inform (location_of (t), " because all of its copy and move "
4587 : : "constructors are deleted");
4588 : 30 : }
4589 : :
4590 : : /* Returns true iff copying an object of type T (including via move
4591 : : constructor) is non-trivial. That is, T has no non-trivial copy
4592 : : constructors and no non-trivial move constructors, and not all copy/move
4593 : : constructors are deleted. This function implements the ABI notion of
4594 : : non-trivial copy, which has diverged from the one in the standard. */
4595 : :
4596 : : bool
4597 : 41422236 : type_has_nontrivial_copy_init (const_tree type)
4598 : : {
4599 : 41422236 : tree t = strip_array_types (CONST_CAST_TREE (type));
4600 : :
4601 : 41422236 : if (CLASS_TYPE_P (t))
4602 : : {
4603 : 40882852 : gcc_assert (COMPLETE_TYPE_P (t));
4604 : :
4605 : 40882852 : if (TYPE_HAS_COMPLEX_COPY_CTOR (t)
4606 : 40882852 : || TYPE_HAS_COMPLEX_MOVE_CTOR (t))
4607 : : /* Nontrivial. */
4608 : : return true;
4609 : :
4610 : 37281399 : if (cxx_dialect < cxx11)
4611 : : /* No deleted functions before C++11. */
4612 : : return false;
4613 : :
4614 : : /* Before ABI v12 we did a bitwise copy of types with only deleted
4615 : : copy/move constructors. */
4616 : 37191017 : if (!abi_version_at_least (12)
4617 : 8144 : && !(warn_abi && abi_version_crosses (12)))
4618 : : return false;
4619 : :
4620 : 37183103 : bool saw_copy = false;
4621 : 37183103 : bool saw_non_deleted = false;
4622 : 37183103 : bool saw_non_deleted_move = false;
4623 : :
4624 : 37183103 : if (CLASSTYPE_LAZY_MOVE_CTOR (t))
4625 : : saw_copy = saw_non_deleted = true;
4626 : 3877417 : else if (CLASSTYPE_LAZY_COPY_CTOR (t))
4627 : : {
4628 : 480784 : saw_copy = true;
4629 : 480784 : if (classtype_has_move_assign_or_move_ctor_p (t, true))
4630 : : /* [class.copy]/8 If the class definition declares a move
4631 : : constructor or move assignment operator, the implicitly declared
4632 : : copy constructor is defined as deleted.... */;
4633 : : else
4634 : : /* Any other reason the implicitly-declared function would be
4635 : : deleted would also cause TYPE_HAS_COMPLEX_COPY_CTOR to be
4636 : : set. */
4637 : : saw_non_deleted = true;
4638 : : }
4639 : :
4640 : : if (!saw_non_deleted)
4641 : 23986513 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
4642 : : {
4643 : 13407701 : tree fn = *iter;
4644 : 13407701 : if (copy_fn_p (fn))
4645 : : {
4646 : 3396634 : saw_copy = true;
4647 : 3396634 : if (!DECL_DELETED_FN (fn))
4648 : : {
4649 : : /* Not deleted, therefore trivial. */
4650 : : saw_non_deleted = true;
4651 : : break;
4652 : : }
4653 : : }
4654 : 10011067 : else if (move_fn_p (fn))
4655 : 2403285 : if (!DECL_DELETED_FN (fn))
4656 : 2398809 : saw_non_deleted_move = true;
4657 : : }
4658 : :
4659 : 37183103 : gcc_assert (saw_copy);
4660 : :
4661 : : /* ABI v12 buggily ignored move constructors. */
4662 : 37183103 : bool v11nontriv = false;
4663 : 37183103 : bool v12nontriv = !saw_non_deleted;
4664 : 37183103 : bool v13nontriv = !saw_non_deleted && !saw_non_deleted_move;
4665 : 37183227 : bool nontriv = (abi_version_at_least (13) ? v13nontriv
4666 : 124 : : flag_abi_version == 12 ? v12nontriv
4667 : 37183103 : : v11nontriv);
4668 : 37183498 : bool warn_nontriv = (warn_abi_version >= 13 ? v13nontriv
4669 : 395 : : warn_abi_version == 12 ? v12nontriv
4670 : : : v11nontriv);
4671 : 37183103 : if (nontriv != warn_nontriv)
4672 : 9 : remember_deleted_copy (t);
4673 : :
4674 : 37183103 : return nontriv;
4675 : : }
4676 : : else
4677 : : return 0;
4678 : : }
4679 : :
4680 : : /* Returns 1 iff type T is a trivially copyable type, as defined in
4681 : : [basic.types] and [class]. */
4682 : :
4683 : : bool
4684 : 127641 : trivially_copyable_p (const_tree t)
4685 : : {
4686 : 127641 : t = strip_array_types (CONST_CAST_TREE (t));
4687 : :
4688 : 127641 : if (CLASS_TYPE_P (t))
4689 : 37575 : return ((!TYPE_HAS_COPY_CTOR (t)
4690 : 37575 : || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
4691 : 36678 : && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
4692 : 36644 : && (!TYPE_HAS_COPY_ASSIGN (t)
4693 : 36644 : || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
4694 : 35688 : && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
4695 : 73093 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
4696 : : else
4697 : : /* CWG 2094 makes volatile-qualified scalars trivially copyable again. */
4698 : 90066 : return scalarish_type_p (t);
4699 : : }
4700 : :
4701 : : /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
4702 : : [class]. */
4703 : :
4704 : : bool
4705 : 72586 : trivial_type_p (const_tree t)
4706 : : {
4707 : 72586 : t = strip_array_types (CONST_CAST_TREE (t));
4708 : :
4709 : 72586 : if (CLASS_TYPE_P (t))
4710 : : /* A trivial class is a class that is trivially copyable and has one or
4711 : : more eligible default constructors, all of which are trivial. */
4712 : 23228 : return (type_has_non_deleted_trivial_default_ctor (CONST_CAST_TREE (t))
4713 : 23228 : && trivially_copyable_p (t));
4714 : : else
4715 : 49358 : return scalarish_type_p (t);
4716 : : }
4717 : :
4718 : : /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
4719 : :
4720 : : bool
4721 : 11545 : pod_type_p (const_tree t)
4722 : : {
4723 : : /* This CONST_CAST is okay because strip_array_types returns its
4724 : : argument unmodified and we assign it to a const_tree. */
4725 : 11545 : t = strip_array_types (CONST_CAST_TREE(t));
4726 : :
4727 : 11545 : if (!CLASS_TYPE_P (t))
4728 : 669 : return scalarish_type_p (t);
4729 : 10876 : else if (cxx_dialect > cxx98)
4730 : : /* [class]/10: A POD struct is a class that is both a trivial class and a
4731 : : standard-layout class, and has no non-static data members of type
4732 : : non-POD struct, non-POD union (or array of such types).
4733 : :
4734 : : We don't need to check individual members because if a member is
4735 : : non-std-layout or non-trivial, the class will be too. */
4736 : 10667 : return (std_layout_type_p (t) && trivial_type_p (t));
4737 : : else
4738 : : /* The C++98 definition of POD is different. */
4739 : 209 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
4740 : : }
4741 : :
4742 : : /* Returns true iff T is POD for the purpose of layout, as defined in the
4743 : : C++ ABI. */
4744 : :
4745 : : bool
4746 : 15003475 : layout_pod_type_p (const_tree t)
4747 : : {
4748 : 15003475 : t = strip_array_types (CONST_CAST_TREE (t));
4749 : :
4750 : 15003475 : if (CLASS_TYPE_P (t))
4751 : 2754258 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
4752 : : else
4753 : 12249217 : return scalarish_type_p (t);
4754 : : }
4755 : :
4756 : : /* Returns true iff T is a standard-layout type, as defined in
4757 : : [basic.types]. */
4758 : :
4759 : : bool
4760 : 15062724 : std_layout_type_p (const_tree t)
4761 : : {
4762 : 15062724 : t = strip_array_types (CONST_CAST_TREE (t));
4763 : :
4764 : 15062724 : if (CLASS_TYPE_P (t))
4765 : 2767118 : return !CLASSTYPE_NON_STD_LAYOUT (t);
4766 : : else
4767 : 12295606 : return scalarish_type_p (t);
4768 : : }
4769 : :
4770 : : static bool record_has_unique_obj_representations (const_tree, const_tree);
4771 : :
4772 : : /* Returns true iff T satisfies std::has_unique_object_representations<T>,
4773 : : as defined in [meta.unary.prop]. */
4774 : :
4775 : : bool
4776 : 15203 : type_has_unique_obj_representations (const_tree t)
4777 : : {
4778 : 15251 : bool ret;
4779 : :
4780 : 15251 : t = strip_array_types (CONST_CAST_TREE (t));
4781 : :
4782 : 15251 : if (!trivially_copyable_p (t))
4783 : : return false;
4784 : :
4785 : 15238 : if (CLASS_TYPE_P (t) && CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t))
4786 : 66 : return CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t);
4787 : :
4788 : 15172 : switch (TREE_CODE (t))
4789 : : {
4790 : : case INTEGER_TYPE:
4791 : : case POINTER_TYPE:
4792 : : case REFERENCE_TYPE:
4793 : : /* If some backend has any paddings in these types, we should add
4794 : : a target hook for this and handle it there. */
4795 : : return true;
4796 : :
4797 : : case BOOLEAN_TYPE:
4798 : : /* For bool values other than 0 and 1 should only appear with
4799 : : undefined behavior. */
4800 : : return true;
4801 : :
4802 : 30 : case ENUMERAL_TYPE:
4803 : 30 : return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t));
4804 : :
4805 : : case REAL_TYPE:
4806 : : /* XFmode certainly contains padding on x86, which the CPU doesn't store
4807 : : when storing long double values, so for that we have to return false.
4808 : : Other kinds of floating point values are questionable due to +.0/-.0
4809 : : and NaNs, let's play safe for now. */
4810 : : return false;
4811 : :
4812 : : case FIXED_POINT_TYPE:
4813 : : return false;
4814 : :
4815 : : case OFFSET_TYPE:
4816 : : return true;
4817 : :
4818 : 18 : case COMPLEX_TYPE:
4819 : 18 : case VECTOR_TYPE:
4820 : 18 : return type_has_unique_obj_representations (TREE_TYPE (t));
4821 : :
4822 : 71 : case RECORD_TYPE:
4823 : 71 : ret = record_has_unique_obj_representations (t, TYPE_SIZE (t));
4824 : 71 : if (CLASS_TYPE_P (t))
4825 : : {
4826 : 68 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
4827 : 68 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
4828 : : }
4829 : : return ret;
4830 : :
4831 : 9 : case UNION_TYPE:
4832 : 9 : ret = true;
4833 : 9 : bool any_fields;
4834 : 9 : any_fields = false;
4835 : 24 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
4836 : 21 : if (TREE_CODE (field) == FIELD_DECL)
4837 : : {
4838 : 18 : any_fields = true;
4839 : 18 : if (!type_has_unique_obj_representations (TREE_TYPE (field))
4840 : 18 : || simple_cst_equal (DECL_SIZE (field), TYPE_SIZE (t)) != 1)
4841 : : {
4842 : : ret = false;
4843 : : break;
4844 : : }
4845 : : }
4846 : 9 : if (!any_fields && !integer_zerop (TYPE_SIZE (t)))
4847 : : ret = false;
4848 : 9 : if (CLASS_TYPE_P (t))
4849 : : {
4850 : 9 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
4851 : 9 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
4852 : : }
4853 : : return ret;
4854 : :
4855 : : case NULLPTR_TYPE:
4856 : : return false;
4857 : :
4858 : : case ERROR_MARK:
4859 : : return false;
4860 : :
4861 : 0 : default:
4862 : 0 : gcc_unreachable ();
4863 : : }
4864 : : }
4865 : :
4866 : : /* Helper function for type_has_unique_obj_representations. */
4867 : :
4868 : : static bool
4869 : 76 : record_has_unique_obj_representations (const_tree t, const_tree sz)
4870 : : {
4871 : 504 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
4872 : 434 : if (TREE_CODE (field) != FIELD_DECL)
4873 : : ;
4874 : : /* For bases, can't use type_has_unique_obj_representations here, as in
4875 : : struct S { int i : 24; S (); };
4876 : : struct T : public S { int j : 8; T (); };
4877 : : S doesn't have unique obj representations, but T does. */
4878 : 111 : else if (DECL_FIELD_IS_BASE (field))
4879 : : {
4880 : 5 : if (!record_has_unique_obj_representations (TREE_TYPE (field),
4881 : 5 : DECL_SIZE (field)))
4882 : : return false;
4883 : : }
4884 : 106 : else if (DECL_C_BIT_FIELD (field) && !DECL_UNNAMED_BIT_FIELD (field))
4885 : : {
4886 : 37 : tree btype = DECL_BIT_FIELD_TYPE (field);
4887 : 37 : if (!type_has_unique_obj_representations (btype))
4888 : : return false;
4889 : : }
4890 : 69 : else if (!type_has_unique_obj_representations (TREE_TYPE (field)))
4891 : : return false;
4892 : :
4893 : 70 : offset_int cur = 0;
4894 : 461 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
4895 : 408 : if (TREE_CODE (field) == FIELD_DECL && !DECL_UNNAMED_BIT_FIELD (field))
4896 : : {
4897 : 93 : offset_int fld = wi::to_offset (DECL_FIELD_OFFSET (field));
4898 : 93 : offset_int bitpos = wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
4899 : 93 : fld = fld * BITS_PER_UNIT + bitpos;
4900 : 93 : if (cur != fld)
4901 : 17 : return false;
4902 : 76 : if (DECL_SIZE (field))
4903 : : {
4904 : 73 : offset_int size = wi::to_offset (DECL_SIZE (field));
4905 : 73 : cur += size;
4906 : : }
4907 : : }
4908 : 53 : if (cur != wi::to_offset (sz))
4909 : : return false;
4910 : :
4911 : : return true;
4912 : : }
4913 : :
4914 : : /* Nonzero iff type T is a class template implicit specialization. */
4915 : :
4916 : : bool
4917 : 95440615 : class_tmpl_impl_spec_p (const_tree t)
4918 : : {
4919 : 95440615 : return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
4920 : : }
4921 : :
4922 : : /* Returns 1 iff zero initialization of type T means actually storing
4923 : : zeros in it. */
4924 : :
4925 : : int
4926 : 16966228 : zero_init_p (const_tree t)
4927 : : {
4928 : : /* This CONST_CAST is okay because strip_array_types returns its
4929 : : argument unmodified and we assign it to a const_tree. */
4930 : 16966228 : t = strip_array_types (CONST_CAST_TREE(t));
4931 : :
4932 : 16966228 : if (t == error_mark_node)
4933 : : return 1;
4934 : :
4935 : : /* NULL pointers to data members are initialized with -1. */
4936 : 16966228 : if (TYPE_PTRDATAMEM_P (t))
4937 : : return 0;
4938 : :
4939 : : /* Classes that contain types that can't be zero-initialized, cannot
4940 : : be zero-initialized themselves. */
4941 : 16965645 : if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
4942 : 120 : return 0;
4943 : :
4944 : : return 1;
4945 : : }
4946 : :
4947 : : /* Returns true if the expression or initializer T is the result of
4948 : : zero-initialization for its type, taking pointers to members
4949 : : into consideration. */
4950 : :
4951 : : bool
4952 : 18219 : zero_init_expr_p (tree t)
4953 : : {
4954 : 18219 : tree type = TREE_TYPE (t);
4955 : 18219 : if (!type || uses_template_parms (type))
4956 : 0 : return false;
4957 : 18219 : if (TYPE_PTRMEM_P (type))
4958 : 1041 : return null_member_pointer_value_p (t);
4959 : 17178 : if (TREE_CODE (t) == CONSTRUCTOR)
4960 : : {
4961 : 10408 : if (COMPOUND_LITERAL_P (t)
4962 : 10408 : || BRACE_ENCLOSED_INITIALIZER_P (t))
4963 : : /* Undigested, conversions might change the zeroness. */
4964 : : return false;
4965 : 23565 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (t))
4966 : : {
4967 : 6864 : if (TREE_CODE (type) == UNION_TYPE
4968 : 6864 : && elt.index != first_field (type))
4969 : : return false;
4970 : 6855 : if (!zero_init_expr_p (elt.value))
4971 : : return false;
4972 : : }
4973 : : return true;
4974 : : }
4975 : 6770 : if (zero_init_p (type))
4976 : 6770 : return initializer_zerop (t);
4977 : : return false;
4978 : : }
4979 : :
4980 : : /* True IFF T is a C++20 structural type (P1907R1) that can be used as a
4981 : : non-type template parameter. If EXPLAIN, explain why not. */
4982 : :
4983 : : bool
4984 : 5430 : structural_type_p (tree t, bool explain)
4985 : : {
4986 : : /* A structural type is one of the following: */
4987 : :
4988 : : /* a scalar type, or */
4989 : 5430 : if (SCALAR_TYPE_P (t))
4990 : : return true;
4991 : : /* an lvalue reference type, or */
4992 : 2436 : if (TYPE_REF_P (t) && !TYPE_REF_IS_RVALUE (t))
4993 : : return true;
4994 : : /* a literal class type with the following properties:
4995 : : - all base classes and non-static data members are public and non-mutable
4996 : : and
4997 : : - the types of all bases classes and non-static data members are
4998 : : structural types or (possibly multi-dimensional) array thereof. */
4999 : 2429 : if (!CLASS_TYPE_P (t))
5000 : : return false;
5001 : 2427 : if (!literal_type_p (t))
5002 : : {
5003 : 13 : if (explain)
5004 : 6 : explain_non_literal_class (t);
5005 : 13 : return false;
5006 : : }
5007 : 5557 : for (tree m = next_aggregate_field (TYPE_FIELDS (t)); m;
5008 : 3143 : m = next_aggregate_field (DECL_CHAIN (m)))
5009 : : {
5010 : 3152 : if (TREE_PRIVATE (m) || TREE_PROTECTED (m))
5011 : : {
5012 : 9 : if (explain)
5013 : : {
5014 : 3 : if (DECL_FIELD_IS_BASE (m))
5015 : 3 : inform (location_of (m), "base class %qT is not public",
5016 : 3 : TREE_TYPE (m));
5017 : : else
5018 : 0 : inform (location_of (m), "%qD is not public", m);
5019 : : }
5020 : 9 : return false;
5021 : : }
5022 : 3143 : if (DECL_MUTABLE_P (m))
5023 : : {
5024 : 0 : if (explain)
5025 : 0 : inform (location_of (m), "%qD is mutable", m);
5026 : 0 : return false;
5027 : : }
5028 : 3143 : tree mtype = strip_array_types (TREE_TYPE (m));
5029 : 3143 : if (!structural_type_p (mtype))
5030 : : {
5031 : 0 : if (explain)
5032 : : {
5033 : 0 : inform (location_of (m), "%qD has a non-structural type", m);
5034 : 0 : structural_type_p (mtype, true);
5035 : : }
5036 : 0 : return false;
5037 : : }
5038 : : }
5039 : : return true;
5040 : : }
5041 : :
5042 : : /* Partially handle the C++11 [[carries_dependency]] attribute.
5043 : : Just emit a different diagnostics when it is used on something the
5044 : : spec doesn't allow vs. where it allows and we just choose to ignore
5045 : : it. */
5046 : :
5047 : : static tree
5048 : 142 : handle_carries_dependency_attribute (tree *node, tree name,
5049 : : tree ARG_UNUSED (args),
5050 : : int ARG_UNUSED (flags),
5051 : : bool *no_add_attrs)
5052 : : {
5053 : 142 : if (TREE_CODE (*node) != FUNCTION_DECL
5054 : 121 : && TREE_CODE (*node) != PARM_DECL)
5055 : : {
5056 : 76 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5057 : : "functions or parameters", name);
5058 : 76 : *no_add_attrs = true;
5059 : : }
5060 : : else
5061 : : {
5062 : 66 : warning (OPT_Wattributes, "%qE attribute ignored", name);
5063 : 66 : *no_add_attrs = true;
5064 : : }
5065 : 142 : return NULL_TREE;
5066 : : }
5067 : :
5068 : : /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
5069 : : warn_unused_result attribute. */
5070 : :
5071 : : static tree
5072 : 10790653 : handle_nodiscard_attribute (tree *node, tree name, tree args,
5073 : : int /*flags*/, bool *no_add_attrs)
5074 : : {
5075 : 10790794 : if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
5076 : : {
5077 : 6 : error ("%qE attribute argument must be a string constant", name);
5078 : 6 : *no_add_attrs = true;
5079 : : }
5080 : 10790653 : if (TREE_CODE (*node) == FUNCTION_DECL)
5081 : : {
5082 : 10788312 : if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))
5083 : 10892396 : && !DECL_CONSTRUCTOR_P (*node))
5084 : 9 : warning_at (DECL_SOURCE_LOCATION (*node),
5085 : : OPT_Wattributes, "%qE attribute applied to %qD with void "
5086 : : "return type", name, *node);
5087 : : }
5088 : 2341 : else if (OVERLOAD_TYPE_P (*node))
5089 : : /* OK */;
5090 : : else
5091 : : {
5092 : 148 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5093 : : "functions or to class or enumeration types", name);
5094 : 148 : *no_add_attrs = true;
5095 : : }
5096 : 10790653 : return NULL_TREE;
5097 : : }
5098 : :
5099 : : /* Handle a C++20 "no_unique_address" attribute; arguments as in
5100 : : struct attribute_spec.handler. */
5101 : : static tree
5102 : 217779 : handle_no_unique_addr_attribute (tree* node,
5103 : : tree name,
5104 : : tree /*args*/,
5105 : : int /*flags*/,
5106 : : bool* no_add_attrs)
5107 : : {
5108 : 217779 : if (TREE_CODE (*node) == VAR_DECL)
5109 : : {
5110 : 48 : DECL_MERGEABLE (*node) = true;
5111 : 48 : if (pedantic)
5112 : 42 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5113 : : "non-static data members", name);
5114 : : }
5115 : 217731 : else if (TREE_CODE (*node) != FIELD_DECL)
5116 : : {
5117 : 82 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5118 : : "non-static data members", name);
5119 : 82 : *no_add_attrs = true;
5120 : : }
5121 : 217649 : else if (DECL_C_BIT_FIELD (*node))
5122 : : {
5123 : 6 : warning (OPT_Wattributes, "%qE attribute cannot be applied to "
5124 : : "a bit-field", name);
5125 : 6 : *no_add_attrs = true;
5126 : : }
5127 : :
5128 : 217779 : return NULL_TREE;
5129 : : }
5130 : :
5131 : : /* The C++20 [[likely]] and [[unlikely]] attributes on labels map to the GNU
5132 : : hot/cold attributes. */
5133 : :
5134 : : static tree
5135 : 392 : handle_likeliness_attribute (tree *node, tree name, tree args,
5136 : : int flags, bool *no_add_attrs)
5137 : : {
5138 : 392 : *no_add_attrs = true;
5139 : 392 : if (TREE_CODE (*node) == LABEL_DECL
5140 : 392 : || TREE_CODE (*node) == FUNCTION_DECL)
5141 : : {
5142 : 90 : if (args)
5143 : 0 : warning (OPT_Wattributes, "%qE attribute takes no arguments", name);
5144 : 90 : tree bname = (is_attribute_p ("likely", name)
5145 : 90 : ? get_identifier ("hot") : get_identifier ("cold"));
5146 : 90 : if (TREE_CODE (*node) == FUNCTION_DECL)
5147 : 33 : warning (OPT_Wattributes, "ISO C++ %qE attribute does not apply to "
5148 : : "functions; treating as %<[[gnu::%E]]%>", name, bname);
5149 : 90 : tree battr = build_tree_list (bname, NULL_TREE);
5150 : 90 : decl_attributes (node, battr, flags);
5151 : 90 : return NULL_TREE;
5152 : : }
5153 : : else
5154 : 302 : return error_mark_node;
5155 : : }
5156 : :
5157 : : /* The C++11 alignment specifier. It mostly maps to GNU aligned attribute,
5158 : : but we need to do some extra pedantic checking. */
5159 : :
5160 : : static tree
5161 : 219603 : handle_alignas_attribute (tree *node, tree name, tree args, int flags,
5162 : : bool *no_add_attrs)
5163 : : {
5164 : 219603 : tree t = *node;
5165 : 219603 : tree ret = handle_aligned_attribute (node, name, args, flags, no_add_attrs);
5166 : 219603 : if (pedantic)
5167 : : {
5168 : 1069 : if (TREE_CODE (*node) == FUNCTION_DECL)
5169 : 15 : pedwarn (input_location, OPT_Wattributes,
5170 : : "%<alignas%> on function declaration");
5171 : 1054 : else if (TREE_CODE (*node) == ENUMERAL_TYPE)
5172 : 9 : pedwarn (input_location, OPT_Wattributes,
5173 : : "%<alignas%> on enumerated type");
5174 : 1045 : else if (TYPE_P (*node) && t != *node)
5175 : 56 : pedwarn (input_location, OPT_Wattributes,
5176 : : "%<alignas%> on a type other than class");
5177 : 989 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_C_BIT_FIELD (*node))
5178 : 9 : pedwarn (input_location, OPT_Wattributes, "%<alignas%> on bit-field");
5179 : 980 : else if (TREE_CODE (t) == TYPE_DECL)
5180 : 9 : pedwarn (input_location, OPT_Wattributes,
5181 : : "%<alignas%> on a type alias");
5182 : : }
5183 : 219603 : return ret;
5184 : : }
5185 : :
5186 : : /* The C++14 [[deprecated]] attribute mostly maps to the GNU deprecated
5187 : : attribute. */
5188 : :
5189 : : static tree
5190 : 701188 : handle_std_deprecated_attribute (tree *node, tree name, tree args, int flags,
5191 : : bool *no_add_attrs)
5192 : : {
5193 : 701188 : tree t = *node;
5194 : 701188 : tree ret = handle_deprecated_attribute (node, name, args, flags,
5195 : : no_add_attrs);
5196 : 701188 : if (TYPE_P (*node) && t != *node)
5197 : 48 : pedwarn (input_location, OPT_Wattributes,
5198 : : "%qE on a type other than class or enumeration definition", name);
5199 : 701140 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5200 : 4 : pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
5201 : : name);
5202 : 701188 : return ret;
5203 : : }
5204 : :
5205 : : /* The C++17 [[maybe_unused]] attribute mostly maps to the GNU unused
5206 : : attribute. */
5207 : :
5208 : : static tree
5209 : 65714 : handle_maybe_unused_attribute (tree *node, tree name, tree args, int flags,
5210 : : bool *no_add_attrs)
5211 : : {
5212 : 65714 : tree t = *node;
5213 : 65714 : tree ret = handle_unused_attribute (node, name, args, flags, no_add_attrs);
5214 : 65714 : if (TYPE_P (*node) && t != *node)
5215 : 36 : pedwarn (input_location, OPT_Wattributes,
5216 : : "%qE on a type other than class or enumeration definition", name);
5217 : 65678 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5218 : 3 : pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
5219 : : name);
5220 : 65675 : else if (TREE_CODE (*node) == LABEL_DECL && DECL_NAME (*node) == NULL_TREE)
5221 : 6 : pedwarn (input_location, OPT_Wattributes,
5222 : : "%qE on %<case%> or %<default%> label", name);
5223 : 65714 : return ret;
5224 : : }
5225 : :
5226 : : /* Table of valid C++ attributes. */
5227 : : static const attribute_spec cxx_gnu_attributes[] =
5228 : : {
5229 : : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5230 : : affects_type_identity, handler, exclude } */
5231 : : { "init_priority", 1, 1, true, false, false, false,
5232 : : handle_init_priority_attribute, NULL },
5233 : : { "abi_tag", 1, -1, false, false, false, true,
5234 : : handle_abi_tag_attribute, NULL },
5235 : : { "no_dangling", 0, 1, false, true, false, false,
5236 : : handle_no_dangling_attribute, NULL },
5237 : : };
5238 : :
5239 : : const scoped_attribute_specs cxx_gnu_attribute_table =
5240 : : {
5241 : : "gnu", { cxx_gnu_attributes }
5242 : : };
5243 : :
5244 : : /* Table of C++ standard attributes. */
5245 : : static const attribute_spec std_attributes[] =
5246 : : {
5247 : : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5248 : : affects_type_identity, handler, exclude } */
5249 : : { "deprecated", 0, 1, false, false, false, false,
5250 : : handle_std_deprecated_attribute, NULL },
5251 : : { "maybe_unused", 0, 0, false, false, false, false,
5252 : : handle_maybe_unused_attribute, NULL },
5253 : : { "nodiscard", 0, 1, false, false, false, false,
5254 : : handle_nodiscard_attribute, NULL },
5255 : : { "no_unique_address", 0, 0, true, false, false, false,
5256 : : handle_no_unique_addr_attribute, NULL },
5257 : : { "likely", 0, 0, false, false, false, false,
5258 : : handle_likeliness_attribute, attr_cold_hot_exclusions },
5259 : : { "unlikely", 0, 0, false, false, false, false,
5260 : : handle_likeliness_attribute, attr_cold_hot_exclusions },
5261 : : { "noreturn", 0, 0, true, false, false, false,
5262 : : handle_noreturn_attribute, attr_noreturn_exclusions },
5263 : : { "carries_dependency", 0, 0, true, false, false, false,
5264 : : handle_carries_dependency_attribute, NULL },
5265 : : { "pre", 0, -1, false, false, false, false,
5266 : : handle_contract_attribute, NULL },
5267 : : { "post", 0, -1, false, false, false, false,
5268 : : handle_contract_attribute, NULL }
5269 : : };
5270 : :
5271 : : const scoped_attribute_specs std_attribute_table =
5272 : : {
5273 : : nullptr, { std_attributes }
5274 : : };
5275 : :
5276 : : /* Table of internal attributes. */
5277 : : static const attribute_spec internal_attributes[] =
5278 : : {
5279 : : { "aligned", 0, 1, false, false, false, false,
5280 : : handle_alignas_attribute, attr_aligned_exclusions }
5281 : : };
5282 : :
5283 : : const scoped_attribute_specs internal_attribute_table =
5284 : : {
5285 : : "internal ", { internal_attributes }
5286 : : };
5287 : :
5288 : : /* Handle an "init_priority" attribute; arguments as in
5289 : : struct attribute_spec.handler. */
5290 : : static tree
5291 : 31 : handle_init_priority_attribute (tree* node,
5292 : : tree name,
5293 : : tree args,
5294 : : int /*flags*/,
5295 : : bool* no_add_attrs)
5296 : : {
5297 : 31 : if (!SUPPORTS_INIT_PRIORITY)
5298 : : /* Treat init_priority as an unrecognized attribute (mirroring
5299 : : __has_attribute) if the target doesn't support init priorities. */
5300 : : return error_mark_node;
5301 : :
5302 : 31 : tree initp_expr = TREE_VALUE (args);
5303 : 31 : tree decl = *node;
5304 : 31 : tree type = TREE_TYPE (decl);
5305 : 31 : int pri;
5306 : :
5307 : 31 : STRIP_NOPS (initp_expr);
5308 : 31 : initp_expr = default_conversion (initp_expr);
5309 : 31 : if (initp_expr)
5310 : 31 : initp_expr = maybe_constant_value (initp_expr);
5311 : :
5312 : 31 : if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
5313 : : {
5314 : 0 : error ("requested %<init_priority%> is not an integer constant");
5315 : 0 : cxx_constant_value (initp_expr);
5316 : 0 : *no_add_attrs = true;
5317 : 0 : return NULL_TREE;
5318 : : }
5319 : :
5320 : 31 : pri = TREE_INT_CST_LOW (initp_expr);
5321 : :
5322 : 31 : type = strip_array_types (type);
5323 : :
5324 : 31 : if (decl == NULL_TREE
5325 : : || !VAR_P (decl)
5326 : 31 : || !TREE_STATIC (decl)
5327 : 31 : || DECL_EXTERNAL (decl)
5328 : 31 : || (TREE_CODE (type) != RECORD_TYPE
5329 : 31 : && TREE_CODE (type) != UNION_TYPE)
5330 : : /* Static objects in functions are initialized the
5331 : : first time control passes through that
5332 : : function. This is not precise enough to pin down an
5333 : : init_priority value, so don't allow it. */
5334 : 62 : || current_function_decl)
5335 : : {
5336 : 0 : error ("can only use %qE attribute on file-scope definitions "
5337 : : "of objects of class type", name);
5338 : 0 : *no_add_attrs = true;
5339 : 0 : return NULL_TREE;
5340 : : }
5341 : :
5342 : 31 : if (pri > MAX_INIT_PRIORITY || pri <= 0)
5343 : : {
5344 : 0 : error ("requested %<init_priority%> %i is out of range [0, %i]",
5345 : : pri, MAX_INIT_PRIORITY);
5346 : 0 : *no_add_attrs = true;
5347 : 0 : return NULL_TREE;
5348 : : }
5349 : :
5350 : : /* Check for init_priorities that are reserved for
5351 : : language and runtime support implementations.*/
5352 : 31 : if (pri <= MAX_RESERVED_INIT_PRIORITY
5353 : 31 : && !in_system_header_at (input_location))
5354 : : {
5355 : 10 : warning
5356 : 10 : (OPT_Wprio_ctor_dtor,
5357 : : "requested %<init_priority%> %i is reserved for internal use",
5358 : : pri);
5359 : : }
5360 : :
5361 : 31 : SET_DECL_INIT_PRIORITY (decl, pri);
5362 : 31 : DECL_HAS_INIT_PRIORITY_P (decl) = 1;
5363 : 31 : return NULL_TREE;
5364 : : }
5365 : :
5366 : : /* DECL is being redeclared; the old declaration had the abi tags in OLD,
5367 : : and the new one has the tags in NEW_. Give an error if there are tags
5368 : : in NEW_ that weren't in OLD. */
5369 : :
5370 : : bool
5371 : 9977415 : check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_)
5372 : : {
5373 : 10009801 : if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST)
5374 : : old = TREE_VALUE (old);
5375 : 9999220 : if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST)
5376 : : new_ = TREE_VALUE (new_);
5377 : 9977415 : bool err = false;
5378 : 9977415 : auto_diagnostic_group d;
5379 : 9999220 : for (const_tree t = new_; t; t = TREE_CHAIN (t))
5380 : : {
5381 : 21805 : tree str = TREE_VALUE (t);
5382 : 21805 : for (const_tree in = old; in; in = TREE_CHAIN (in))
5383 : : {
5384 : 21799 : tree ostr = TREE_VALUE (in);
5385 : 21799 : if (cp_tree_equal (str, ostr))
5386 : 21799 : goto found;
5387 : : }
5388 : 6 : error ("redeclaration of %qD adds abi tag %qE", decl, str);
5389 : 6 : err = true;
5390 : 21805 : found:;
5391 : : }
5392 : 9977415 : if (err)
5393 : : {
5394 : 6 : inform (DECL_SOURCE_LOCATION (decl), "previous declaration here");
5395 : 6 : return false;
5396 : : }
5397 : : return true;
5398 : 9977415 : }
5399 : :
5400 : : /* The abi_tag attribute with the name NAME was given ARGS. If they are
5401 : : ill-formed, give an error and return false; otherwise, return true. */
5402 : :
5403 : : bool
5404 : 375513 : check_abi_tag_args (tree args, tree name)
5405 : : {
5406 : 375513 : if (!args)
5407 : : {
5408 : 0 : error ("the %qE attribute requires arguments", name);
5409 : 0 : return false;
5410 : : }
5411 : 751026 : for (tree arg = args; arg; arg = TREE_CHAIN (arg))
5412 : : {
5413 : 375525 : tree elt = TREE_VALUE (arg);
5414 : 375525 : if (TREE_CODE (elt) != STRING_CST
5415 : 751044 : || (!same_type_ignoring_top_level_qualifiers_p
5416 : 375519 : (strip_array_types (TREE_TYPE (elt)),
5417 : : char_type_node)))
5418 : : {
5419 : 9 : error ("arguments to the %qE attribute must be narrow string "
5420 : : "literals", name);
5421 : 9 : return false;
5422 : : }
5423 : 375516 : const char *begin = TREE_STRING_POINTER (elt);
5424 : 375516 : const char *end = begin + TREE_STRING_LENGTH (elt);
5425 : 2641038 : for (const char *p = begin; p != end; ++p)
5426 : : {
5427 : 2265525 : char c = *p;
5428 : 2265525 : if (p == begin)
5429 : : {
5430 : 375516 : if (!ISALPHA (c) && c != '_')
5431 : : {
5432 : 3 : auto_diagnostic_group d;
5433 : 3 : error ("arguments to the %qE attribute must contain valid "
5434 : : "identifiers", name);
5435 : 3 : inform (input_location, "%<%c%> is not a valid first "
5436 : : "character for an identifier", c);
5437 : 3 : return false;
5438 : 3 : }
5439 : : }
5440 : 1890009 : else if (p == end - 1)
5441 : 375513 : gcc_assert (c == 0);
5442 : : else
5443 : : {
5444 : 1514496 : if (!ISALNUM (c) && c != '_')
5445 : : {
5446 : 0 : auto_diagnostic_group d;
5447 : 0 : error ("arguments to the %qE attribute must contain valid "
5448 : : "identifiers", name);
5449 : 0 : inform (input_location, "%<%c%> is not a valid character "
5450 : : "in an identifier", c);
5451 : 0 : return false;
5452 : 0 : }
5453 : : }
5454 : : }
5455 : : }
5456 : : return true;
5457 : : }
5458 : :
5459 : : /* Handle an "abi_tag" attribute; arguments as in
5460 : : struct attribute_spec.handler. */
5461 : :
5462 : : static tree
5463 : 330400 : handle_abi_tag_attribute (tree* node, tree name, tree args,
5464 : : int flags, bool* no_add_attrs)
5465 : : {
5466 : 330400 : if (!check_abi_tag_args (args, name))
5467 : 12 : goto fail;
5468 : :
5469 : 330388 : if (TYPE_P (*node))
5470 : : {
5471 : 11064 : if (!OVERLOAD_TYPE_P (*node))
5472 : : {
5473 : 0 : error ("%qE attribute applied to non-class, non-enum type %qT",
5474 : : name, *node);
5475 : 0 : goto fail;
5476 : : }
5477 : 11064 : else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE))
5478 : : {
5479 : 0 : error ("%qE attribute applied to %qT after its definition",
5480 : : name, *node);
5481 : 0 : goto fail;
5482 : : }
5483 : 11061 : else if (CLASS_TYPE_P (*node)
5484 : 22125 : && CLASSTYPE_TEMPLATE_INSTANTIATION (*node))
5485 : : {
5486 : 3 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5487 : : "template instantiation %qT", name, *node);
5488 : 3 : goto fail;
5489 : : }
5490 : 11058 : else if (CLASS_TYPE_P (*node)
5491 : 22119 : && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node))
5492 : : {
5493 : 3 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5494 : : "template specialization %qT", name, *node);
5495 : 3 : goto fail;
5496 : : }
5497 : :
5498 : 11058 : tree attributes = TYPE_ATTRIBUTES (*node);
5499 : 11058 : tree decl = TYPE_NAME (*node);
5500 : :
5501 : : /* Make sure all declarations have the same abi tags. */
5502 : 11058 : if (DECL_SOURCE_LOCATION (decl) != input_location)
5503 : : {
5504 : 3 : if (!check_abi_tag_redeclaration (decl,
5505 : 3 : lookup_attribute ("abi_tag",
5506 : : attributes),
5507 : : args))
5508 : 3 : goto fail;
5509 : : }
5510 : : }
5511 : : else
5512 : : {
5513 : 319324 : if (!VAR_OR_FUNCTION_DECL_P (*node))
5514 : : {
5515 : 0 : error ("%qE attribute applied to non-function, non-variable %qD",
5516 : : name, *node);
5517 : 0 : goto fail;
5518 : : }
5519 : 319324 : else if (DECL_LANGUAGE (*node) == lang_c)
5520 : : {
5521 : 0 : error ("%qE attribute applied to extern \"C\" declaration %qD",
5522 : : name, *node);
5523 : 0 : goto fail;
5524 : : }
5525 : : }
5526 : :
5527 : : return NULL_TREE;
5528 : :
5529 : 21 : fail:
5530 : 21 : *no_add_attrs = true;
5531 : 21 : return NULL_TREE;
5532 : : }
5533 : :
5534 : : /* Perform checking for contract attributes. */
5535 : :
5536 : : tree
5537 : 673 : handle_contract_attribute (tree *ARG_UNUSED (node), tree ARG_UNUSED (name),
5538 : : tree ARG_UNUSED (args), int ARG_UNUSED (flags),
5539 : : bool *ARG_UNUSED (no_add_attrs))
5540 : : {
5541 : : /* TODO: Is there any checking we could do here? */
5542 : 673 : return NULL_TREE;
5543 : : }
5544 : :
5545 : : /* Handle a "no_dangling" attribute; arguments as in
5546 : : struct attribute_spec.handler. */
5547 : :
5548 : : tree
5549 : 96 : handle_no_dangling_attribute (tree *node, tree name, tree args, int,
5550 : : bool *no_add_attrs)
5551 : : {
5552 : 147 : if (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
5553 : : {
5554 : 3 : error ("%qE attribute argument must be an expression that evaluates "
5555 : : "to true or false", name);
5556 : 3 : *no_add_attrs = true;
5557 : : }
5558 : 93 : else if (!FUNC_OR_METHOD_TYPE_P (*node)
5559 : 51 : && !RECORD_OR_UNION_TYPE_P (*node))
5560 : : {
5561 : 18 : warning (OPT_Wattributes, "%qE attribute ignored", name);
5562 : 18 : *no_add_attrs = true;
5563 : : }
5564 : :
5565 : 96 : return NULL_TREE;
5566 : : }
5567 : :
5568 : : /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
5569 : : thing pointed to by the constant. */
5570 : :
5571 : : tree
5572 : 64405 : make_ptrmem_cst (tree type, tree member)
5573 : : {
5574 : 64405 : tree ptrmem_cst = make_node (PTRMEM_CST);
5575 : 64405 : TREE_TYPE (ptrmem_cst) = type;
5576 : 64405 : PTRMEM_CST_MEMBER (ptrmem_cst) = member;
5577 : 64405 : PTRMEM_CST_LOCATION (ptrmem_cst) = input_location;
5578 : 64405 : return ptrmem_cst;
5579 : : }
5580 : :
5581 : : /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
5582 : : return an existing type if an appropriate type already exists. */
5583 : :
5584 : : tree
5585 : 15060114 : cp_build_type_attribute_variant (tree type, tree attributes)
5586 : : {
5587 : 15060114 : tree new_type;
5588 : :
5589 : 15060114 : new_type = build_type_attribute_variant (type, attributes);
5590 : 15060114 : if (FUNC_OR_METHOD_TYPE_P (new_type))
5591 : 14999583 : gcc_checking_assert (cxx_type_hash_eq (type, new_type));
5592 : :
5593 : : /* Making a new main variant of a class type is broken. */
5594 : 15060114 : gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
5595 : :
5596 : 15060114 : return new_type;
5597 : : }
5598 : :
5599 : : /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
5600 : : Called only after doing all language independent checks. */
5601 : :
5602 : : bool
5603 : 280934753 : cxx_type_hash_eq (const_tree typea, const_tree typeb)
5604 : : {
5605 : 280934753 : gcc_assert (FUNC_OR_METHOD_TYPE_P (typea));
5606 : :
5607 : 280934753 : if (type_memfn_rqual (typea) != type_memfn_rqual (typeb))
5608 : : return false;
5609 : 280924281 : if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb))
5610 : : return false;
5611 : 280923668 : return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
5612 : 561847336 : TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
5613 : : }
5614 : :
5615 : : /* Copy the language-specific type variant modifiers from TYPEB to TYPEA. For
5616 : : C++, these are the exception-specifier and ref-qualifier. */
5617 : :
5618 : : tree
5619 : 23565390 : cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
5620 : : {
5621 : 23565390 : tree type = CONST_CAST_TREE (typea);
5622 : 23565390 : if (FUNC_OR_METHOD_TYPE_P (type))
5623 : 23564504 : type = build_cp_fntype_variant (type, type_memfn_rqual (typeb),
5624 : 23564504 : TYPE_RAISES_EXCEPTIONS (typeb),
5625 : 23564504 : TYPE_HAS_LATE_RETURN_TYPE (typeb));
5626 : 23565390 : return type;
5627 : : }
5628 : :
5629 : : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
5630 : : traversal. Called from walk_tree. */
5631 : :
5632 : : tree
5633 : 14331071463 : cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
5634 : : void *data, hash_set<tree> *pset)
5635 : : {
5636 : 14331071463 : tree t = *tp;
5637 : 14331071463 : enum tree_code code = TREE_CODE (t);
5638 : 14331071463 : tree result;
5639 : :
5640 : : #define WALK_SUBTREE(NODE) \
5641 : : do \
5642 : : { \
5643 : : result = cp_walk_tree (&(NODE), func, data, pset); \
5644 : : if (result) goto out; \
5645 : : } \
5646 : : while (0)
5647 : :
5648 : 14331071463 : if (TYPE_P (t))
5649 : : {
5650 : : /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
5651 : : the argument, so don't look through typedefs, but do walk into
5652 : : template arguments for alias templates (and non-typedefed classes).
5653 : :
5654 : : If *WALK_SUBTREES_P > 1, we're interested in type identity or
5655 : : equivalence, so look through typedefs, ignoring template arguments for
5656 : : alias templates, and walk into template args of classes.
5657 : :
5658 : : See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
5659 : : when that's the behavior the walk_tree_fn wants. */
5660 : 4942826282 : if (*walk_subtrees_p == 1 && typedef_variant_p (t))
5661 : : {
5662 : 7277259 : if (tree ti = TYPE_ALIAS_TEMPLATE_INFO (t))
5663 : 5385140 : WALK_SUBTREE (TI_ARGS (ti));
5664 : 7164519 : *walk_subtrees_p = 0;
5665 : 7164519 : return NULL_TREE;
5666 : : }
5667 : :
5668 : 4935549023 : if (tree ti = TYPE_TEMPLATE_INFO (t))
5669 : 491223552 : WALK_SUBTREE (TI_ARGS (ti));
5670 : : }
5671 : :
5672 : : /* Not one of the easy cases. We must explicitly go through the
5673 : : children. */
5674 : 14323677594 : result = NULL_TREE;
5675 : 14323677594 : switch (code)
5676 : : {
5677 : 1444139351 : case TEMPLATE_TYPE_PARM:
5678 : 1444139351 : if (template_placeholder_p (t))
5679 : 407953 : WALK_SUBTREE (CLASS_PLACEHOLDER_TEMPLATE (t));
5680 : : /* Fall through. */
5681 : 1570993423 : case DEFERRED_PARSE:
5682 : 1570993423 : case TEMPLATE_TEMPLATE_PARM:
5683 : 1570993423 : case BOUND_TEMPLATE_TEMPLATE_PARM:
5684 : 1570993423 : case UNBOUND_CLASS_TEMPLATE:
5685 : 1570993423 : case TEMPLATE_PARM_INDEX:
5686 : 1570993423 : case TYPEOF_TYPE:
5687 : : /* None of these have subtrees other than those already walked
5688 : : above. */
5689 : 1570993423 : *walk_subtrees_p = 0;
5690 : 1570993423 : break;
5691 : :
5692 : 138303941 : case TYPENAME_TYPE:
5693 : 138303941 : WALK_SUBTREE (TYPE_CONTEXT (t));
5694 : 138261521 : WALK_SUBTREE (TYPENAME_TYPE_FULLNAME (t));
5695 : 138258989 : *walk_subtrees_p = 0;
5696 : 138258989 : break;
5697 : :
5698 : 66039906 : case BASELINK:
5699 : 66039906 : if (BASELINK_QUALIFIED_P (t))
5700 : 4887913 : WALK_SUBTREE (BINFO_TYPE (BASELINK_ACCESS_BINFO (t)));
5701 : 66039906 : WALK_SUBTREE (BASELINK_FUNCTIONS (t));
5702 : 66018542 : *walk_subtrees_p = 0;
5703 : 66018542 : break;
5704 : :
5705 : 52603 : case PTRMEM_CST:
5706 : 52603 : WALK_SUBTREE (TREE_TYPE (t));
5707 : 52603 : *walk_subtrees_p = 0;
5708 : 52603 : break;
5709 : :
5710 : 200598816 : case TREE_LIST:
5711 : 200598816 : WALK_SUBTREE (TREE_PURPOSE (t));
5712 : : break;
5713 : :
5714 : 233208376 : case OVERLOAD:
5715 : 233208376 : WALK_SUBTREE (OVL_FUNCTION (t));
5716 : 233208371 : WALK_SUBTREE (OVL_CHAIN (t));
5717 : 233208371 : *walk_subtrees_p = 0;
5718 : 233208371 : break;
5719 : :
5720 : 2728040 : case USING_DECL:
5721 : 2728040 : WALK_SUBTREE (DECL_NAME (t));
5722 : 2728040 : WALK_SUBTREE (USING_DECL_SCOPE (t));
5723 : 2728037 : WALK_SUBTREE (USING_DECL_DECLS (t));
5724 : 2728037 : *walk_subtrees_p = 0;
5725 : 2728037 : break;
5726 : :
5727 : 561061914 : case RECORD_TYPE:
5728 : 561061914 : if (TYPE_PTRMEMFUNC_P (t))
5729 : 5789198 : WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (t));
5730 : : break;
5731 : :
5732 : 105474513 : case TYPE_ARGUMENT_PACK:
5733 : 105474513 : case NONTYPE_ARGUMENT_PACK:
5734 : 105474513 : {
5735 : 105474513 : tree args = ARGUMENT_PACK_ARGS (t);
5736 : 281260716 : for (tree arg : tree_vec_range (args))
5737 : 175966251 : WALK_SUBTREE (arg);
5738 : : }
5739 : 105294465 : break;
5740 : :
5741 : 23149793 : case TYPE_PACK_EXPANSION:
5742 : 23149793 : WALK_SUBTREE (TREE_TYPE (t));
5743 : 23138409 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
5744 : 23138409 : *walk_subtrees_p = 0;
5745 : 23138409 : break;
5746 : :
5747 : 3221420 : case EXPR_PACK_EXPANSION:
5748 : 3221420 : WALK_SUBTREE (TREE_OPERAND (t, 0));
5749 : 3219519 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
5750 : 3219519 : *walk_subtrees_p = 0;
5751 : 3219519 : break;
5752 : :
5753 : 47 : case PACK_INDEX_TYPE:
5754 : 47 : case PACK_INDEX_EXPR:
5755 : 47 : WALK_SUBTREE (PACK_INDEX_PACK (t));
5756 : 47 : WALK_SUBTREE (PACK_INDEX_INDEX (t));
5757 : 47 : *walk_subtrees_p = 0;
5758 : 47 : break;
5759 : :
5760 : 76886035 : case CAST_EXPR:
5761 : 76886035 : case REINTERPRET_CAST_EXPR:
5762 : 76886035 : case STATIC_CAST_EXPR:
5763 : 76886035 : case CONST_CAST_EXPR:
5764 : 76886035 : case DYNAMIC_CAST_EXPR:
5765 : 76886035 : case IMPLICIT_CONV_EXPR:
5766 : 76886035 : case BIT_CAST_EXPR:
5767 : 76886035 : if (TREE_TYPE (t))
5768 : 76886035 : WALK_SUBTREE (TREE_TYPE (t));
5769 : : break;
5770 : :
5771 : 63218454 : case CONSTRUCTOR:
5772 : 63218454 : if (COMPOUND_LITERAL_P (t))
5773 : 4685093 : WALK_SUBTREE (TREE_TYPE (t));
5774 : : break;
5775 : :
5776 : 11704438 : case TRAIT_EXPR:
5777 : 11704438 : WALK_SUBTREE (TRAIT_EXPR_TYPE1 (t));
5778 : 11704426 : WALK_SUBTREE (TRAIT_EXPR_TYPE2 (t));
5779 : 11704426 : *walk_subtrees_p = 0;
5780 : 11704426 : break;
5781 : :
5782 : 1200352 : case TRAIT_TYPE:
5783 : 1200352 : WALK_SUBTREE (TRAIT_TYPE_TYPE1 (t));
5784 : 1200352 : WALK_SUBTREE (TRAIT_TYPE_TYPE2 (t));
5785 : 1200352 : *walk_subtrees_p = 0;
5786 : 1200352 : break;
5787 : :
5788 : 6650816 : case DECLTYPE_TYPE:
5789 : 6650816 : {
5790 : 6650816 : cp_unevaluated u;
5791 : 6650816 : WALK_SUBTREE (DECLTYPE_TYPE_EXPR (t));
5792 : 6570166 : *walk_subtrees_p = 0;
5793 : 6570166 : break;
5794 : 6650816 : }
5795 : :
5796 : 17277484 : case ALIGNOF_EXPR:
5797 : 17277484 : case SIZEOF_EXPR:
5798 : 17277484 : case NOEXCEPT_EXPR:
5799 : 17277484 : {
5800 : 17277484 : cp_unevaluated u;
5801 : 17277484 : WALK_SUBTREE (TREE_OPERAND (t, 0));
5802 : 14989364 : *walk_subtrees_p = 0;
5803 : 14989364 : break;
5804 : 17277484 : }
5805 : :
5806 : 3398197 : case REQUIRES_EXPR:
5807 : 3398197 : {
5808 : 3398197 : cp_unevaluated u;
5809 : 5852651 : for (tree parm = REQUIRES_EXPR_PARMS (t); parm; parm = DECL_CHAIN (parm))
5810 : : /* Walk the types of each parameter, but not the parameter itself,
5811 : : since doing so would cause false positives in the unexpanded pack
5812 : : checker if the requires-expr introduces a function parameter pack,
5813 : : e.g. requires (Ts... ts) { }. */
5814 : 2454502 : WALK_SUBTREE (TREE_TYPE (parm));
5815 : 3398149 : WALK_SUBTREE (REQUIRES_EXPR_REQS (t));
5816 : 3395651 : *walk_subtrees_p = 0;
5817 : 3395651 : break;
5818 : 3398197 : }
5819 : :
5820 : 62102259 : case DECL_EXPR:
5821 : : /* User variables should be mentioned in BIND_EXPR_VARS
5822 : : and their initializers and sizes walked when walking
5823 : : the containing BIND_EXPR. Compiler temporaries are
5824 : : handled here. And also normal variables in templates,
5825 : : since do_poplevel doesn't build a BIND_EXPR then. */
5826 : 62102259 : if (VAR_P (TREE_OPERAND (t, 0))
5827 : 62102259 : && (processing_template_decl
5828 : 57812463 : || (DECL_ARTIFICIAL (TREE_OPERAND (t, 0))
5829 : 3336110 : && !TREE_STATIC (TREE_OPERAND (t, 0)))))
5830 : : {
5831 : 6618558 : tree decl = TREE_OPERAND (t, 0);
5832 : 6618558 : WALK_SUBTREE (TREE_TYPE (decl));
5833 : 6618558 : WALK_SUBTREE (DECL_INITIAL (decl));
5834 : 6618528 : WALK_SUBTREE (DECL_SIZE (decl));
5835 : 6618528 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
5836 : : }
5837 : : break;
5838 : :
5839 : 783021 : case LAMBDA_EXPR:
5840 : : /* Don't walk into the body of the lambda, but the capture initializers
5841 : : are part of the enclosing context. */
5842 : 1730577 : for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (t); cap;
5843 : 947556 : cap = TREE_CHAIN (cap))
5844 : 947556 : WALK_SUBTREE (TREE_VALUE (cap));
5845 : : break;
5846 : :
5847 : 5495 : case CO_YIELD_EXPR:
5848 : 5495 : if (TREE_OPERAND (t, 1))
5849 : : /* Operand 1 is the tree for the relevant co_await which has any
5850 : : interesting sub-trees. */
5851 : 540 : WALK_SUBTREE (TREE_OPERAND (t, 1));
5852 : : break;
5853 : :
5854 : 23891 : case CO_AWAIT_EXPR:
5855 : 23891 : if (TREE_OPERAND (t, 1))
5856 : : /* Operand 1 is frame variable. */
5857 : 23723 : WALK_SUBTREE (TREE_OPERAND (t, 1));
5858 : 23891 : if (TREE_OPERAND (t, 2))
5859 : : /* Operand 2 has the initialiser, and we need to walk any subtrees
5860 : : there. */
5861 : 4862 : WALK_SUBTREE (TREE_OPERAND (t, 2));
5862 : : break;
5863 : :
5864 : 864 : case CO_RETURN_EXPR:
5865 : 864 : if (TREE_OPERAND (t, 0))
5866 : : {
5867 : 760 : if (VOID_TYPE_P (TREE_OPERAND (t, 0)))
5868 : : /* For void expressions, operand 1 is a trivial call, and any
5869 : : interesting subtrees will be part of operand 0. */
5870 : 0 : WALK_SUBTREE (TREE_OPERAND (t, 0));
5871 : 760 : else if (TREE_OPERAND (t, 1))
5872 : : /* Interesting sub-trees will be in the return_value () call
5873 : : arguments. */
5874 : 712 : WALK_SUBTREE (TREE_OPERAND (t, 1));
5875 : : }
5876 : : break;
5877 : :
5878 : 210901 : case STATIC_ASSERT:
5879 : 210901 : WALK_SUBTREE (STATIC_ASSERT_CONDITION (t));
5880 : 210901 : WALK_SUBTREE (STATIC_ASSERT_MESSAGE (t));
5881 : : break;
5882 : :
5883 : 441553237 : case INTEGER_TYPE:
5884 : : /* Removed from walk_type_fields in r119481. */
5885 : 441553237 : WALK_SUBTREE (TYPE_MIN_VALUE (t));
5886 : 441553237 : WALK_SUBTREE (TYPE_MAX_VALUE (t));
5887 : : break;
5888 : :
5889 : : default:
5890 : : return NULL_TREE;
5891 : : }
5892 : :
5893 : : /* We didn't find what we were looking for. */
5894 : : out:
5895 : : return result;
5896 : :
5897 : : #undef WALK_SUBTREE
5898 : : }
5899 : :
5900 : : /* Like save_expr, but for C++. */
5901 : :
5902 : : tree
5903 : 315728 : cp_save_expr (tree expr)
5904 : : {
5905 : : /* There is no reason to create a SAVE_EXPR within a template; if
5906 : : needed, we can create the SAVE_EXPR when instantiating the
5907 : : template. Furthermore, the middle-end cannot handle C++-specific
5908 : : tree codes. */
5909 : 315728 : if (processing_template_decl)
5910 : : return expr;
5911 : :
5912 : : /* TARGET_EXPRs are only expanded once. */
5913 : 241900 : if (TREE_CODE (expr) == TARGET_EXPR)
5914 : : return expr;
5915 : :
5916 : 241900 : return save_expr (expr);
5917 : : }
5918 : :
5919 : : /* Initialize tree.cc. */
5920 : :
5921 : : void
5922 : 93374 : init_tree (void)
5923 : : {
5924 : 93374 : list_hash_table = hash_table<list_hasher>::create_ggc (61);
5925 : 93374 : }
5926 : :
5927 : : /* Returns the kind of special function that DECL (a FUNCTION_DECL)
5928 : : is. Note that sfk_none is zero, so this function can be used as a
5929 : : predicate to test whether or not DECL is a special function. */
5930 : :
5931 : : special_function_kind
5932 : 179807279 : special_function_p (const_tree decl)
5933 : : {
5934 : : /* Rather than doing all this stuff with magic names, we should
5935 : : probably have a field of type `special_function_kind' in
5936 : : DECL_LANG_SPECIFIC. */
5937 : 359614558 : if (DECL_INHERITED_CTOR (decl))
5938 : : return sfk_inheriting_constructor;
5939 : 359027442 : if (DECL_COPY_CONSTRUCTOR_P (decl))
5940 : : return sfk_copy_constructor;
5941 : 338510458 : if (DECL_MOVE_CONSTRUCTOR_P (decl))
5942 : : return sfk_move_constructor;
5943 : 324132438 : if (DECL_CONSTRUCTOR_P (decl))
5944 : : return sfk_constructor;
5945 : 143435577 : if (DECL_ASSIGNMENT_OPERATOR_P (decl)
5946 : 143435577 : && DECL_OVERLOADED_OPERATOR_IS (decl, NOP_EXPR))
5947 : : {
5948 : 8859150 : if (copy_fn_p (decl))
5949 : : return sfk_copy_assignment;
5950 : 3396148 : if (move_fn_p (decl))
5951 : : return sfk_move_assignment;
5952 : : }
5953 : 134981316 : if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
5954 : : return sfk_destructor;
5955 : 100438667 : if (DECL_COMPLETE_DESTRUCTOR_P (decl))
5956 : : return sfk_complete_destructor;
5957 : 83845326 : if (DECL_BASE_DESTRUCTOR_P (decl))
5958 : : return sfk_base_destructor;
5959 : 82159003 : if (DECL_DELETING_DESTRUCTOR_P (decl))
5960 : : return sfk_deleting_destructor;
5961 : 70968486 : if (DECL_CONV_FN_P (decl))
5962 : : return sfk_conversion;
5963 : 70301547 : if (deduction_guide_p (decl))
5964 : : return sfk_deduction_guide;
5965 : 70277719 : if (DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) >= OVL_OP_EQ_EXPR
5966 : 70277719 : && DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) <= OVL_OP_SPACESHIP_EXPR)
5967 : 3312593 : return sfk_comparison;
5968 : :
5969 : : return sfk_none;
5970 : : }
5971 : :
5972 : : /* As above, but only if DECL is a special member function as per 11.3.3
5973 : : [special]: default/copy/move ctor, copy/move assignment, or destructor. */
5974 : :
5975 : : special_function_kind
5976 : 57912450 : special_memfn_p (const_tree decl)
5977 : : {
5978 : 57912450 : switch (special_function_kind sfk = special_function_p (decl))
5979 : : {
5980 : 6242080 : case sfk_constructor:
5981 : 6242080 : if (!default_ctor_p (decl))
5982 : : break;
5983 : : gcc_fallthrough();
5984 : : case sfk_copy_constructor:
5985 : : case sfk_copy_assignment:
5986 : : case sfk_move_assignment:
5987 : : case sfk_move_constructor:
5988 : : case sfk_destructor:
5989 : : return sfk;
5990 : :
5991 : : default:
5992 : : break;
5993 : : }
5994 : : return sfk_none;
5995 : : }
5996 : :
5997 : : /* Returns nonzero if TYPE is a character type, including wchar_t. */
5998 : :
5999 : : int
6000 : 8785345 : char_type_p (tree type)
6001 : : {
6002 : 8785345 : return (same_type_p (type, char_type_node)
6003 : 7788524 : || same_type_p (type, unsigned_char_type_node)
6004 : 7731472 : || same_type_p (type, signed_char_type_node)
6005 : 7730966 : || same_type_p (type, char8_type_node)
6006 : 7730892 : || same_type_p (type, char16_type_node)
6007 : 7730392 : || same_type_p (type, char32_type_node)
6008 : 16482712 : || same_type_p (type, wchar_type_node));
6009 : : }
6010 : :
6011 : : /* Returns the kind of linkage associated with the indicated DECL. The
6012 : : value returned is as specified by the language standard; it is
6013 : : independent of implementation details regarding template
6014 : : instantiation, etc. For example, it is possible that a declaration
6015 : : to which this function assigns external linkage would not show up
6016 : : as a global symbol when you run `nm' on the resulting object file. */
6017 : :
6018 : : linkage_kind
6019 : 388979140 : decl_linkage (tree decl)
6020 : : {
6021 : : /* This function doesn't attempt to calculate the linkage from first
6022 : : principles as given in [basic.link]. Instead, it makes use of
6023 : : the fact that we have already set TREE_PUBLIC appropriately, and
6024 : : then handles a few special cases. Ideally, we would calculate
6025 : : linkage first, and then transform that into a concrete
6026 : : implementation. */
6027 : :
6028 : : /* An explicit type alias has no linkage. Nor do the built-in declarations
6029 : : of 'int' and such. */
6030 : 418466398 : if (TREE_CODE (decl) == TYPE_DECL
6031 : 418466398 : && !DECL_IMPLICIT_TYPEDEF_P (decl))
6032 : : {
6033 : : /* But this could be a typedef name for linkage purposes, in which
6034 : : case we're interested in the linkage of the main decl. */
6035 : 908084 : if (decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl)))
6036 : : /* Likewise for the injected-class-name. */
6037 : 908084 : || DECL_SELF_REFERENCE_P (decl))
6038 : 20973 : decl = TYPE_MAIN_DECL (TREE_TYPE (decl));
6039 : : else
6040 : : return lk_none;
6041 : : }
6042 : :
6043 : : /* Namespace-scope entities with no name usually have no linkage. */
6044 : 417579287 : if (NAMESPACE_SCOPE_P (decl)
6045 : 803021363 : && (!DECL_NAME (decl) || IDENTIFIER_ANON_P (DECL_NAME (decl))))
6046 : : {
6047 : 3535139 : if (TREE_CODE (decl) == TYPE_DECL && !TYPE_ANON_P (TREE_TYPE (decl)))
6048 : : /* This entity has a typedef name for linkage purposes. */;
6049 : 3532232 : else if (DECL_DECOMPOSITION_P (decl) && DECL_DECOMP_IS_BASE (decl))
6050 : : /* Namespace-scope structured bindings can have linkage. */;
6051 : 3532182 : else if (TREE_CODE (decl) == NAMESPACE_DECL && cxx_dialect >= cxx11)
6052 : : /* An anonymous namespace has internal linkage since C++11. */
6053 : : return lk_internal;
6054 : : else
6055 : : return lk_none;
6056 : : }
6057 : :
6058 : : /* Fields and parameters have no linkage. */
6059 : 414047105 : if (TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == PARM_DECL)
6060 : : return lk_none;
6061 : :
6062 : : /* Things in block scope do not have linkage. */
6063 : 370316096 : if (decl_function_context (decl))
6064 : : return lk_none;
6065 : :
6066 : : /* Things in class scope have the linkage of their owning class. */
6067 : 367667588 : if (tree ctype = DECL_CLASS_CONTEXT (decl))
6068 : 29487258 : return decl_linkage (TYPE_NAME (ctype));
6069 : :
6070 : : /* Anonymous namespaces don't provide internal linkage in C++98,
6071 : : but otherwise consider such declarations to be internal. */
6072 : 338180330 : if (cxx_dialect >= cxx11 && decl_internal_context_p (decl))
6073 : : return lk_internal;
6074 : :
6075 : : /* Templates don't properly propagate TREE_PUBLIC, consider the
6076 : : template result instead. Any template that isn't a variable
6077 : : or function must be external linkage by this point. */
6078 : 338011084 : if (TREE_CODE (decl) == TEMPLATE_DECL)
6079 : : {
6080 : 226252 : decl = DECL_TEMPLATE_RESULT (decl);
6081 : 226252 : if (!decl || !VAR_OR_FUNCTION_DECL_P (decl))
6082 : : return lk_external;
6083 : : }
6084 : :
6085 : : /* Things that are TREE_PUBLIC have external linkage. */
6086 : 337813804 : if (TREE_PUBLIC (decl))
6087 : : return lk_external;
6088 : :
6089 : : /* All types have external linkage in C++98, since anonymous namespaces
6090 : : didn't explicitly confer internal linkage. */
6091 : 75816871 : if (TREE_CODE (decl) == TYPE_DECL && cxx_dialect < cxx11)
6092 : : return lk_external;
6093 : :
6094 : : /* Variables or function decls not marked as TREE_PUBLIC might still
6095 : : be external linkage, such as for template instantiations on targets
6096 : : without weak symbols, decls referring to internal-linkage entities,
6097 : : or compiler-generated entities; in such cases, decls really meant to
6098 : : have internal linkage will have DECL_THIS_STATIC set. */
6099 : 75816868 : if (VAR_OR_FUNCTION_DECL_P (decl) && !DECL_THIS_STATIC (decl))
6100 : : return lk_external;
6101 : :
6102 : : /* Everything else has internal linkage. */
6103 : : return lk_internal;
6104 : : }
6105 : :
6106 : : /* Returns the storage duration of the object or reference associated with
6107 : : the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
6108 : :
6109 : : duration_kind
6110 : 41539738 : decl_storage_duration (tree decl)
6111 : : {
6112 : 41539738 : if (TREE_CODE (decl) == PARM_DECL)
6113 : : return dk_auto;
6114 : 41539738 : if (TREE_CODE (decl) == FUNCTION_DECL)
6115 : : return dk_static;
6116 : 41539738 : gcc_assert (VAR_P (decl));
6117 : 41539738 : if (!TREE_STATIC (decl)
6118 : 41539738 : && !DECL_EXTERNAL (decl))
6119 : : return dk_auto;
6120 : 19763328 : if (CP_DECL_THREAD_LOCAL_P (decl))
6121 : 20732 : return dk_thread;
6122 : : return dk_static;
6123 : : }
6124 : :
6125 : : /* EXP is an expression that we want to pre-evaluate. Returns (in
6126 : : *INITP) an expression that will perform the pre-evaluation. The
6127 : : value returned by this function is a side-effect free expression
6128 : : equivalent to the pre-evaluated expression. Callers must ensure
6129 : : that *INITP is evaluated before EXP.
6130 : :
6131 : : Note that if EXPR is a glvalue, the return value is a glvalue denoting the
6132 : : same address; this function does not guard against modification of the
6133 : : stored value like save_expr or get_target_expr do. */
6134 : :
6135 : : tree
6136 : 4398838 : stabilize_expr (tree exp, tree* initp)
6137 : : {
6138 : 4398838 : tree init_expr;
6139 : :
6140 : 4398838 : if (!TREE_SIDE_EFFECTS (exp))
6141 : : init_expr = NULL_TREE;
6142 : 502614 : else if (VOID_TYPE_P (TREE_TYPE (exp)))
6143 : : {
6144 : 0 : init_expr = exp;
6145 : 0 : exp = void_node;
6146 : : }
6147 : : /* There are no expressions with REFERENCE_TYPE, but there can be call
6148 : : arguments with such a type; just treat it as a pointer. */
6149 : 502614 : else if (TYPE_REF_P (TREE_TYPE (exp))
6150 : 502480 : || SCALAR_TYPE_P (TREE_TYPE (exp))
6151 : 502660 : || !glvalue_p (exp))
6152 : : {
6153 : 502608 : init_expr = get_target_expr (exp);
6154 : 502608 : exp = TARGET_EXPR_SLOT (init_expr);
6155 : 502608 : if (CLASS_TYPE_P (TREE_TYPE (exp)))
6156 : 9 : exp = move (exp);
6157 : : else
6158 : 502599 : exp = rvalue (exp);
6159 : : }
6160 : : else
6161 : : {
6162 : 6 : bool xval = !lvalue_p (exp);
6163 : 6 : exp = cp_build_addr_expr (exp, tf_warning_or_error);
6164 : 6 : init_expr = get_target_expr (exp);
6165 : 6 : exp = TARGET_EXPR_SLOT (init_expr);
6166 : 6 : exp = cp_build_fold_indirect_ref (exp);
6167 : 6 : if (xval)
6168 : 0 : exp = move (exp);
6169 : : }
6170 : 4398838 : *initp = init_expr;
6171 : :
6172 : 4398838 : gcc_assert (!TREE_SIDE_EFFECTS (exp) || TREE_THIS_VOLATILE (exp));
6173 : 4398838 : return exp;
6174 : : }
6175 : :
6176 : : /* Add NEW_EXPR, an expression whose value we don't care about, after the
6177 : : similar expression ORIG. */
6178 : :
6179 : : tree
6180 : 496323 : add_stmt_to_compound (tree orig, tree new_expr)
6181 : : {
6182 : 496323 : if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
6183 : : return orig;
6184 : 252260 : if (!orig || !TREE_SIDE_EFFECTS (orig))
6185 : : return new_expr;
6186 : 11894 : return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
6187 : : }
6188 : :
6189 : : /* Like stabilize_expr, but for a call whose arguments we want to
6190 : : pre-evaluate. CALL is modified in place to use the pre-evaluated
6191 : : arguments, while, upon return, *INITP contains an expression to
6192 : : compute the arguments. */
6193 : :
6194 : : void
6195 : 240956 : stabilize_call (tree call, tree *initp)
6196 : : {
6197 : 240956 : tree inits = NULL_TREE;
6198 : 240956 : int i;
6199 : 240956 : int nargs = call_expr_nargs (call);
6200 : :
6201 : 240956 : if (call == error_mark_node || processing_template_decl)
6202 : : {
6203 : 31 : *initp = NULL_TREE;
6204 : 31 : return;
6205 : : }
6206 : :
6207 : 240925 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
6208 : :
6209 : 722841 : for (i = 0; i < nargs; i++)
6210 : : {
6211 : 481916 : tree init;
6212 : 481916 : CALL_EXPR_ARG (call, i) =
6213 : 481916 : stabilize_expr (CALL_EXPR_ARG (call, i), &init);
6214 : 481916 : inits = add_stmt_to_compound (inits, init);
6215 : : }
6216 : :
6217 : 240925 : *initp = inits;
6218 : : }
6219 : :
6220 : : /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
6221 : : to pre-evaluate. CALL is modified in place to use the pre-evaluated
6222 : : arguments, while, upon return, *INITP contains an expression to
6223 : : compute the arguments. */
6224 : :
6225 : : static void
6226 : 0 : stabilize_aggr_init (tree call, tree *initp)
6227 : : {
6228 : 0 : tree inits = NULL_TREE;
6229 : 0 : int i;
6230 : 0 : int nargs = aggr_init_expr_nargs (call);
6231 : :
6232 : 0 : if (call == error_mark_node)
6233 : : return;
6234 : :
6235 : 0 : gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
6236 : :
6237 : 0 : for (i = 0; i < nargs; i++)
6238 : : {
6239 : 0 : tree init;
6240 : 0 : AGGR_INIT_EXPR_ARG (call, i) =
6241 : 0 : stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
6242 : 0 : inits = add_stmt_to_compound (inits, init);
6243 : : }
6244 : :
6245 : 0 : *initp = inits;
6246 : : }
6247 : :
6248 : : /* Like stabilize_expr, but for an initialization.
6249 : :
6250 : : If the initialization is for an object of class type, this function
6251 : : takes care not to introduce additional temporaries.
6252 : :
6253 : : Returns TRUE iff the expression was successfully pre-evaluated,
6254 : : i.e., if INIT is now side-effect free, except for, possibly, a
6255 : : single call to a constructor. */
6256 : :
6257 : : bool
6258 : 0 : stabilize_init (tree init, tree *initp)
6259 : : {
6260 : 0 : tree t = init;
6261 : :
6262 : 0 : *initp = NULL_TREE;
6263 : :
6264 : 0 : if (t == error_mark_node || processing_template_decl)
6265 : : return true;
6266 : :
6267 : 0 : if (TREE_CODE (t) == INIT_EXPR)
6268 : 0 : t = TREE_OPERAND (t, 1);
6269 : 0 : if (TREE_CODE (t) == TARGET_EXPR)
6270 : 0 : t = TARGET_EXPR_INITIAL (t);
6271 : :
6272 : : /* If the RHS can be stabilized without breaking copy elision, stabilize
6273 : : it. We specifically don't stabilize class prvalues here because that
6274 : : would mean an extra copy, but they might be stabilized below. */
6275 : 0 : if (TREE_CODE (init) == INIT_EXPR
6276 : 0 : && TREE_CODE (t) != CONSTRUCTOR
6277 : 0 : && TREE_CODE (t) != AGGR_INIT_EXPR
6278 : 0 : && (SCALAR_TYPE_P (TREE_TYPE (t))
6279 : 0 : || glvalue_p (t)))
6280 : : {
6281 : 0 : TREE_OPERAND (init, 1) = stabilize_expr (t, initp);
6282 : 0 : return true;
6283 : : }
6284 : :
6285 : 0 : if (TREE_CODE (t) == COMPOUND_EXPR
6286 : 0 : && TREE_CODE (init) == INIT_EXPR)
6287 : : {
6288 : 0 : tree last = expr_last (t);
6289 : : /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */
6290 : 0 : if (!TREE_SIDE_EFFECTS (last))
6291 : : {
6292 : 0 : *initp = t;
6293 : 0 : TREE_OPERAND (init, 1) = last;
6294 : 0 : return true;
6295 : : }
6296 : : }
6297 : :
6298 : 0 : if (TREE_CODE (t) == CONSTRUCTOR)
6299 : : {
6300 : : /* Aggregate initialization: stabilize each of the field
6301 : : initializers. */
6302 : 0 : unsigned i;
6303 : 0 : constructor_elt *ce;
6304 : 0 : bool good = true;
6305 : 0 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
6306 : 0 : for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
6307 : : {
6308 : 0 : tree type = TREE_TYPE (ce->value);
6309 : 0 : tree subinit;
6310 : 0 : if (TYPE_REF_P (type)
6311 : 0 : || SCALAR_TYPE_P (type))
6312 : 0 : ce->value = stabilize_expr (ce->value, &subinit);
6313 : 0 : else if (!stabilize_init (ce->value, &subinit))
6314 : 0 : good = false;
6315 : 0 : *initp = add_stmt_to_compound (*initp, subinit);
6316 : : }
6317 : : return good;
6318 : : }
6319 : :
6320 : 0 : if (TREE_CODE (t) == CALL_EXPR)
6321 : : {
6322 : 0 : stabilize_call (t, initp);
6323 : 0 : return true;
6324 : : }
6325 : :
6326 : 0 : if (TREE_CODE (t) == AGGR_INIT_EXPR)
6327 : : {
6328 : 0 : stabilize_aggr_init (t, initp);
6329 : 0 : return true;
6330 : : }
6331 : :
6332 : : /* The initialization is being performed via a bitwise copy -- and
6333 : : the item copied may have side effects. */
6334 : 0 : return !TREE_SIDE_EFFECTS (init);
6335 : : }
6336 : :
6337 : : /* Returns true if a cast to TYPE may appear in an integral constant
6338 : : expression. */
6339 : :
6340 : : bool
6341 : 79940228 : cast_valid_in_integral_constant_expression_p (tree type)
6342 : : {
6343 : 79940228 : return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
6344 : 58961097 : || cxx_dialect >= cxx11
6345 : 312701 : || dependent_type_p (type)
6346 : 80163253 : || type == error_mark_node);
6347 : : }
6348 : :
6349 : : /* Return true if we need to fix linkage information of DECL. */
6350 : :
6351 : : static bool
6352 : 2195388 : cp_fix_function_decl_p (tree decl)
6353 : : {
6354 : : /* Skip if DECL is not externally visible. */
6355 : 2195388 : if (!TREE_PUBLIC (decl))
6356 : : return false;
6357 : :
6358 : : /* We need to fix DECL if it a appears to be exported but with no
6359 : : function body. Thunks do not have CFGs and we may need to
6360 : : handle them specially later. */
6361 : 2193053 : if (!gimple_has_body_p (decl)
6362 : 2148954 : && !DECL_THUNK_P (decl)
6363 : 4341475 : && !DECL_EXTERNAL (decl))
6364 : : {
6365 : 15142 : struct cgraph_node *node = cgraph_node::get (decl);
6366 : :
6367 : : /* Don't fix same_body aliases. Although they don't have their own
6368 : : CFG, they share it with what they alias to. */
6369 : 15142 : if (!node || !node->alias || !node->num_references ())
6370 : : return true;
6371 : : }
6372 : :
6373 : : return false;
6374 : : }
6375 : :
6376 : : /* Clean the C++ specific parts of the tree T. */
6377 : :
6378 : : void
6379 : 3772721 : cp_free_lang_data (tree t)
6380 : : {
6381 : 3772721 : if (FUNC_OR_METHOD_TYPE_P (t))
6382 : : {
6383 : : /* Default args are not interesting anymore. */
6384 : 716501 : tree argtypes = TYPE_ARG_TYPES (t);
6385 : 2683740 : while (argtypes)
6386 : : {
6387 : 1967239 : TREE_PURPOSE (argtypes) = 0;
6388 : 1967239 : argtypes = TREE_CHAIN (argtypes);
6389 : : }
6390 : : }
6391 : 3056220 : else if (TREE_CODE (t) == FUNCTION_DECL
6392 : 3056220 : && cp_fix_function_decl_p (t))
6393 : : {
6394 : : /* If T is used in this translation unit at all, the definition
6395 : : must exist somewhere else since we have decided to not emit it
6396 : : in this TU. So make it an external reference. */
6397 : 9230 : DECL_EXTERNAL (t) = 1;
6398 : 9230 : TREE_STATIC (t) = 0;
6399 : : }
6400 : 3772721 : if (TREE_CODE (t) == NAMESPACE_DECL)
6401 : : /* We do not need the leftover chaining of namespaces from the
6402 : : binding level. */
6403 : 3412 : DECL_CHAIN (t) = NULL_TREE;
6404 : 3772721 : }
6405 : :
6406 : : /* Stub for c-common. Please keep in sync with c-decl.cc.
6407 : : FIXME: If address space support is target specific, then this
6408 : : should be a C target hook. But currently this is not possible,
6409 : : because this function is called via REGISTER_TARGET_PRAGMAS. */
6410 : : void
6411 : 186748 : c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
6412 : : {
6413 : 186748 : }
6414 : :
6415 : : /* Return the number of operands in T that we care about for things like
6416 : : mangling. */
6417 : :
6418 : : int
6419 : 244214933 : cp_tree_operand_length (const_tree t)
6420 : : {
6421 : 244214933 : enum tree_code code = TREE_CODE (t);
6422 : :
6423 : 244214933 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
6424 : 20393320 : return VL_EXP_OPERAND_LENGTH (t);
6425 : :
6426 : 223821613 : return cp_tree_code_length (code);
6427 : : }
6428 : :
6429 : : /* Like cp_tree_operand_length, but takes a tree_code CODE. */
6430 : :
6431 : : int
6432 : 227459003 : cp_tree_code_length (enum tree_code code)
6433 : : {
6434 : 227459003 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
6435 : :
6436 : 227459003 : switch (code)
6437 : : {
6438 : : case PREINCREMENT_EXPR:
6439 : : case PREDECREMENT_EXPR:
6440 : : case POSTINCREMENT_EXPR:
6441 : : case POSTDECREMENT_EXPR:
6442 : : return 1;
6443 : :
6444 : 248521 : case ARRAY_REF:
6445 : 248521 : return 2;
6446 : :
6447 : : case EXPR_PACK_EXPANSION:
6448 : : return 1;
6449 : :
6450 : 225382232 : default:
6451 : 225382232 : return TREE_CODE_LENGTH (code);
6452 : : }
6453 : : }
6454 : :
6455 : : /* Implement -Wzero_as_null_pointer_constant. Return true if the
6456 : : conditions for the warning hold, false otherwise. */
6457 : : bool
6458 : 5320743 : maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
6459 : : {
6460 : 5320743 : if (c_inhibit_evaluation_warnings == 0
6461 : 10142255 : && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
6462 : : {
6463 : 1921534 : warning_at (loc, OPT_Wzero_as_null_pointer_constant,
6464 : : "zero as null pointer constant");
6465 : 1921534 : return true;
6466 : : }
6467 : : return false;
6468 : : }
6469 : :
6470 : : /* FNDECL is a function declaration whose type may have been altered by
6471 : : adding extra parameters such as this, in-charge, or VTT. When this
6472 : : takes place, the positional arguments supplied by the user (as in the
6473 : : 'format' attribute arguments) may refer to the wrong argument. This
6474 : : function returns an integer indicating how many arguments should be
6475 : : skipped. */
6476 : :
6477 : : int
6478 : 34149564 : maybe_adjust_arg_pos_for_attribute (const_tree fndecl)
6479 : : {
6480 : 34149564 : if (!fndecl)
6481 : : return 0;
6482 : 6805448 : int n = num_artificial_parms_for (fndecl);
6483 : : /* The manual states that it's the user's responsibility to account
6484 : : for the implicit this parameter. */
6485 : 6805448 : return n > 0 ? n - 1 : 0;
6486 : : }
6487 : :
6488 : :
6489 : : /* Release memory we no longer need after parsing. */
6490 : : void
6491 : 91869 : cp_tree_c_finish_parsing ()
6492 : : {
6493 : 91869 : if (previous_class_level)
6494 : 65144 : invalidate_class_lookup_cache ();
6495 : 91869 : deleted_copy_types = NULL;
6496 : 91869 : }
6497 : :
6498 : : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
6499 : : /* Complain that some language-specific thing hanging off a tree
6500 : : node has been accessed improperly. */
6501 : :
6502 : : void
6503 : 0 : lang_check_failed (const char* file, int line, const char* function)
6504 : : {
6505 : 0 : internal_error ("%<lang_*%> check: failed in %s, at %s:%d",
6506 : : function, trim_filename (file), line);
6507 : : }
6508 : : #endif /* ENABLE_TREE_CHECKING */
6509 : :
6510 : : #if CHECKING_P
6511 : :
6512 : : namespace selftest {
6513 : :
6514 : : /* Verify that lvalue_kind () works, for various expressions,
6515 : : and that location wrappers don't affect the results. */
6516 : :
6517 : : static void
6518 : 1 : test_lvalue_kind ()
6519 : : {
6520 : 1 : location_t loc = BUILTINS_LOCATION;
6521 : :
6522 : : /* Verify constants and parameters, without and with
6523 : : location wrappers. */
6524 : 1 : tree int_cst = build_int_cst (integer_type_node, 42);
6525 : 1 : ASSERT_EQ (clk_none, lvalue_kind (int_cst));
6526 : :
6527 : 1 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
6528 : 1 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
6529 : 1 : ASSERT_EQ (clk_none, lvalue_kind (wrapped_int_cst));
6530 : :
6531 : 1 : tree string_lit = build_string (4, "foo");
6532 : 1 : TREE_TYPE (string_lit) = char_array_type_node;
6533 : 1 : string_lit = fix_string_type (string_lit);
6534 : 1 : ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (string_lit));
6535 : :
6536 : 1 : tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
6537 : 1 : ASSERT_TRUE (location_wrapper_p (wrapped_string_lit));
6538 : 1 : ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (wrapped_string_lit));
6539 : :
6540 : 1 : tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL,
6541 : : get_identifier ("some_parm"),
6542 : : integer_type_node);
6543 : 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (parm));
6544 : :
6545 : 1 : tree wrapped_parm = maybe_wrap_with_location (parm, loc);
6546 : 1 : ASSERT_TRUE (location_wrapper_p (wrapped_parm));
6547 : 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_parm));
6548 : :
6549 : : /* Verify that lvalue_kind of std::move on a parm isn't
6550 : : affected by location wrappers. */
6551 : 1 : tree rvalue_ref_of_parm = move (parm);
6552 : 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm));
6553 : 1 : tree rvalue_ref_of_wrapped_parm = move (wrapped_parm);
6554 : 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm));
6555 : :
6556 : : /* Verify lvalue_p. */
6557 : 1 : ASSERT_FALSE (lvalue_p (int_cst));
6558 : 1 : ASSERT_FALSE (lvalue_p (wrapped_int_cst));
6559 : 1 : ASSERT_TRUE (lvalue_p (parm));
6560 : 1 : ASSERT_TRUE (lvalue_p (wrapped_parm));
6561 : 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm));
6562 : 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm));
6563 : 1 : }
6564 : :
6565 : : /* Run all of the selftests within this file. */
6566 : :
6567 : : void
6568 : 1 : cp_tree_cc_tests ()
6569 : : {
6570 : 1 : test_lvalue_kind ();
6571 : 1 : }
6572 : :
6573 : : } // namespace selftest
6574 : :
6575 : : #endif /* #if CHECKING_P */
6576 : :
6577 : :
6578 : : #include "gt-cp-tree.h"
|