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