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 2528922059 : lvalue_kind (const_tree ref)
59 : {
60 2777981993 : cp_lvalue_kind op1_lvalue_kind = clk_none;
61 2777981993 : 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 2777981993 : if (REFERENCE_REF_P (ref))
68 233979238 : return lvalue_kind (TREE_OPERAND (ref, 0));
69 :
70 2544002755 : if (TREE_TYPE (ref)
71 2544002755 : && TYPE_REF_P (TREE_TYPE (ref)))
72 : {
73 : /* unnamed rvalue references are rvalues */
74 237919938 : 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 284916870 : && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
80 : {
81 46996141 : op1_lvalue_kind = clk_rvalueref;
82 46996141 : if (implicit_rvalue_p (ref))
83 7934402 : op1_lvalue_kind |= clk_implicit_rval;
84 46996141 : return op1_lvalue_kind;
85 : }
86 :
87 : /* lvalue references and named rvalue references are lvalues. */
88 : return clk_ordinary;
89 : }
90 :
91 2306082817 : if (ref == current_class_ptr)
92 : return clk_none;
93 :
94 : /* Expressions with cv void type are prvalues. */
95 2303130087 : if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
96 : return clk_none;
97 :
98 2302840243 : 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 290086159 : case PREINCREMENT_EXPR:
106 290086159 : case PREDECREMENT_EXPR:
107 290086159 : case TRY_CATCH_EXPR:
108 290086159 : case REALPART_EXPR:
109 290086159 : case IMAGPART_EXPR:
110 290086159 : case VIEW_CONVERT_EXPR:
111 290086159 : 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 290086159 : if (op1_lvalue_kind == clk_class
117 290086173 : && !(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 3445166 : case ARRAY_REF:
124 3445166 : {
125 3445166 : tree op1 = TREE_OPERAND (ref, 0);
126 3445166 : if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
127 : {
128 2982305 : op1_lvalue_kind = lvalue_kind (op1);
129 2982305 : 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 2982305 : 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 149766538 : case COMPONENT_REF:
155 149766538 : if (BASELINK_P (TREE_OPERAND (ref, 1)))
156 : {
157 126 : 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 126 : if (TREE_CODE (fn) == FUNCTION_DECL && DECL_STATIC_FUNCTION_P (fn))
164 27 : return lvalue_kind (TREE_OPERAND (ref, 1));
165 : }
166 149766511 : op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
167 149766511 : 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 149599739 : if (!op1_lvalue_kind)
174 : ;
175 149766487 : 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 149766388 : else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
181 : /* This can be IDENTIFIER_NODE in a template. */;
182 142241564 : 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 5156430 : op1_lvalue_kind &= ~clk_ordinary;
187 : /* The lvalue is for a bitfield. */
188 5156430 : op1_lvalue_kind |= clk_bitfield;
189 : }
190 137085134 : 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 2833321 : 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 2833321 : if (! TREE_STATIC (ref))
207 : return clk_none;
208 : /* FALLTHRU */
209 239524956 : case VAR_DECL:
210 239524956 : if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
211 833802 : return lvalue_kind (DECL_VALUE_EXPR (const_cast<tree> (ref)));
212 :
213 341027147 : if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
214 13081081 : && DECL_LANG_SPECIFIC (ref)
215 239530530 : && DECL_IN_AGGR_P (ref))
216 : return clk_none;
217 :
218 238691154 : 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 11164997 : case SCOPE_REF:
232 11164997 : gcc_assert (!type_dependent_expression_p (const_cast<tree> (ref)));
233 11164997 : {
234 11164997 : tree op = TREE_OPERAND (ref, 1);
235 11164997 : if (TREE_CODE (op) == FIELD_DECL)
236 17995 : 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 12341099 : case COND_EXPR:
252 12341099 : 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 1183221 : gcc_assert (!type_dependent_expression_p (const_cast<tree> (ref)));
261 1183221 : goto default_;
262 : }
263 11157878 : {
264 11157878 : tree op1 = TREE_OPERAND (ref, 1);
265 11157878 : if (!op1) op1 = TREE_OPERAND (ref, 0);
266 11157878 : tree op2 = TREE_OPERAND (ref, 2);
267 11157878 : op1_lvalue_kind = lvalue_kind (op1);
268 11157878 : op2_lvalue_kind = lvalue_kind (op2);
269 11157878 : 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 550393 : if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
275 : op2_lvalue_kind = op1_lvalue_kind;
276 550351 : else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
277 11158363 : op1_lvalue_kind = op2_lvalue_kind;
278 : }
279 : }
280 : break;
281 :
282 93368 : case MODOP_EXPR:
283 : /* We expect to see unlowered MODOP_EXPRs only during
284 : template processing. */
285 93368 : gcc_assert (processing_template_decl);
286 93368 : 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 3064259 : case COMPOUND_EXPR:
296 3064259 : return lvalue_kind (TREE_OPERAND (ref, 1));
297 :
298 : case TARGET_EXPR:
299 : return clk_class;
300 :
301 1411 : case VA_ARG_EXPR:
302 1411 : return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
303 :
304 113645559 : case CALL_EXPR:
305 : /* We can see calls outside of TARGET_EXPR in templates. */
306 113645559 : if (CLASS_TYPE_P (TREE_TYPE (ref)))
307 : return clk_class;
308 : return clk_none;
309 :
310 118227983 : case FUNCTION_DECL:
311 : /* All functions (except non-static-member functions) are
312 : lvalues. */
313 118227983 : return (DECL_IOBJ_MEMBER_FUNCTION_P (ref)
314 118227983 : ? clk_none : clk_ordinary);
315 :
316 1620 : 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 1620 : return lvalue_kind (BASELINK_FUNCTIONS (const_cast<tree> (ref)));
322 :
323 33986 : case PAREN_EXPR:
324 33986 : return lvalue_kind (TREE_OPERAND (ref, 0));
325 :
326 16618010 : case TEMPLATE_PARM_INDEX:
327 16618010 : 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 967661517 : default:
333 967661517 : default_:
334 967661517 : if (!TREE_TYPE (ref))
335 : return clk_none;
336 1935323034 : if (CLASS_TYPE_P (TREE_TYPE (ref))
337 1931965595 : || 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 11158363 : 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 3344124 : op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
350 : /* It's not an ordinary lvalue if it involves any other kind. */
351 3344124 : if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
352 154375 : 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 154375 : if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
356 37488 : && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
357 1085224617 : 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 43104247 : real_lvalue_p (const_tree ref)
365 : {
366 43104247 : cp_lvalue_kind kind = lvalue_kind (ref);
367 43104247 : if (kind & (clk_rvalueref|clk_class))
368 : return clk_none;
369 : else
370 41206457 : return kind;
371 : }
372 :
373 : /* c-common wants us to return bool. */
374 :
375 : bool
376 42289121 : lvalue_p (const_tree t)
377 : {
378 42289121 : return real_lvalue_p (t);
379 : }
380 :
381 : /* This differs from lvalue_p in that xvalues are included. */
382 :
383 : bool
384 146316647 : glvalue_p (const_tree ref)
385 : {
386 146316647 : cp_lvalue_kind kind = lvalue_kind (ref);
387 146316647 : if (kind & clk_class)
388 : return false;
389 : else
390 143224679 : return (kind != clk_none);
391 : }
392 :
393 : /* This differs from glvalue_p in that class prvalues are included. */
394 :
395 : bool
396 1217003761 : obvalue_p (const_tree ref)
397 : {
398 1217003761 : 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 6660566 : xvalue_p (const_tree ref)
406 : {
407 6660566 : return (lvalue_kind (ref) & clk_rvalueref);
408 : }
409 :
410 : /* True if REF is a bit-field. */
411 :
412 : bool
413 197878190 : bitfield_p (const_tree ref)
414 : {
415 197878190 : 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 4639340 : cp_stabilize_reference (tree ref)
510 : {
511 4639340 : if (processing_template_decl)
512 : /* As in cp_save_expr. */
513 : return ref;
514 :
515 3922533 : STRIP_ANY_LOCATION_WRAPPER (ref);
516 3922533 : 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 3922509 : 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 514020891 : builtin_valid_in_constant_expr_p (const_tree decl)
558 : {
559 514020891 : STRIP_ANY_LOCATION_WRAPPER (decl);
560 514020891 : if (TREE_CODE (decl) != FUNCTION_DECL)
561 : /* Not a function. */
562 : return false;
563 242408402 : if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
564 : {
565 205456238 : if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
566 255775 : 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 36952164 : 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 34572986 : build_target_expr (tree decl, tree value, tsubst_flags_t complain)
612 : {
613 34572986 : tree t;
614 34572986 : tree type = TREE_TYPE (decl);
615 :
616 34572986 : value = mark_rvalue_use (value);
617 :
618 34572986 : 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 34572986 : if (CP_TYPE_CONST_NON_VOLATILE_P (type)
629 1952788 : && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
630 1777553 : && !VOID_TYPE_P (TREE_TYPE (value))
631 1106488 : && !TYPE_HAS_MUTABLE_P (type)
632 35679466 : && reduced_constant_expression_p (value))
633 329727 : TREE_READONLY (decl) = true;
634 :
635 34572986 : 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 33919879 : t = cxx_maybe_build_cleanup (decl, complain);
641 33919879 : if (t == error_mark_node)
642 : return error_mark_node;
643 : }
644 :
645 34572938 : set_target_expr_eliding (value);
646 :
647 34572938 : t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
648 34572938 : if (location_t eloc = cp_expr_location (value))
649 22927397 : 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 34572938 : TREE_SIDE_EFFECTS (t) = 1;
655 :
656 34572938 : 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 38999278 : build_local_temp (tree type)
664 : {
665 38999278 : tree slot = build_decl (input_location,
666 : VAR_DECL, NULL_TREE, type);
667 38999278 : DECL_ARTIFICIAL (slot) = 1;
668 38999278 : DECL_IGNORED_P (slot) = 1;
669 38999278 : DECL_CONTEXT (slot) = current_function_decl;
670 38999278 : layout_decl (slot, 0);
671 38999278 : 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 49225682 : is_local_temp (tree decl)
679 : {
680 49225682 : return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
681 49737203 : && !TREE_STATIC (decl));
682 : }
683 :
684 : /* Set various status flags when building an AGGR_INIT_EXPR object T. */
685 :
686 : static void
687 12353268 : process_aggr_init_operands (tree t)
688 : {
689 12353268 : bool side_effects;
690 :
691 12353268 : side_effects = TREE_SIDE_EFFECTS (t);
692 12353268 : if (!side_effects)
693 : {
694 12353268 : int i, n;
695 12353268 : n = TREE_OPERAND_LENGTH (t);
696 55360393 : for (i = 1; i < n; i++)
697 : {
698 46466713 : tree op = TREE_OPERAND (t, i);
699 46466713 : if (op && TREE_SIDE_EFFECTS (op))
700 : {
701 : side_effects = 1;
702 : break;
703 : }
704 : }
705 : }
706 12353268 : TREE_SIDE_EFFECTS (t) = side_effects;
707 12353268 : }
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 12353268 : build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
715 : tree *args)
716 : {
717 12353268 : tree t;
718 12353268 : int i;
719 :
720 12353268 : t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
721 12353268 : TREE_TYPE (t) = return_type;
722 12353268 : AGGR_INIT_EXPR_FN (t) = fn;
723 12353268 : AGGR_INIT_EXPR_SLOT (t) = slot;
724 35622618 : for (i = 0; i < nargs; i++)
725 23269350 : AGGR_INIT_EXPR_ARG (t, i) = args[i];
726 12353268 : process_aggr_init_operands (t);
727 12353268 : 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 38077166 : build_aggr_init_expr (tree type, tree init)
742 : {
743 38077166 : tree fn;
744 38077166 : tree slot;
745 38077166 : tree rval;
746 38077166 : int is_ctor;
747 :
748 38077166 : gcc_assert (!VOID_TYPE_P (type));
749 :
750 : /* Don't build AGGR_INIT_EXPR in a template. */
751 38077166 : if (processing_template_decl)
752 : return init;
753 :
754 37938861 : fn = cp_get_callee (init);
755 37938861 : if (fn == NULL_TREE)
756 15263924 : return convert (type, init);
757 :
758 46509172 : is_ctor = (TREE_CODE (fn) == ADDR_EXPR
759 22631755 : && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
760 67938447 : && 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 11480967 : if (is_ctor || TREE_ADDRESSABLE (type))
774 : {
775 12353268 : slot = build_local_temp (type);
776 :
777 12353268 : if (TREE_CODE (init) == CALL_EXPR)
778 : {
779 47420328 : rval = build_aggr_init_array (void_type_node, fn, slot,
780 11855082 : call_expr_nargs (init),
781 11855082 : CALL_EXPR_ARGP (init));
782 11855082 : AGGR_INIT_FROM_THUNK_P (rval)
783 11855082 : = CALL_FROM_THUNK_P (init);
784 : }
785 : else
786 : {
787 498186 : rval = build_aggr_init_array (void_type_node, fn, slot,
788 498186 : aggr_init_expr_nargs (init),
789 498186 : AGGR_INIT_EXPR_ARGP (init));
790 498186 : AGGR_INIT_FROM_THUNK_P (rval)
791 498186 : = AGGR_INIT_FROM_THUNK_P (init);
792 : }
793 12353268 : TREE_SIDE_EFFECTS (rval) = 1;
794 12353268 : AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
795 12353268 : TREE_NOTHROW (rval) = TREE_NOTHROW (init);
796 12353268 : CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
797 12353268 : CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
798 12353268 : CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
799 12353268 : 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 32832273 : 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 32832273 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
822 : {
823 320 : gcc_assert (cxx_dialect >= cxx20);
824 320 : return finish_compound_literal (type, init, complain);
825 : }
826 :
827 32831953 : tree rval = build_aggr_init_expr (type, init);
828 32831953 : tree slot;
829 :
830 32831953 : if (init == error_mark_node)
831 : return error_mark_node;
832 :
833 32829846 : 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 32829840 : if (abstract_virtuals_error (NULL_TREE, type, complain))
839 17 : return error_mark_node;
840 :
841 32829823 : if (TREE_CODE (rval) == AGGR_INIT_EXPR)
842 7374086 : slot = AGGR_INIT_EXPR_SLOT (rval);
843 25455737 : else if (TREE_CODE (rval) == CALL_EXPR
844 15013897 : || TREE_CODE (rval) == CONSTRUCTOR)
845 10442232 : slot = build_local_temp (type);
846 : else
847 : return rval;
848 :
849 17816318 : rval = build_target_expr (slot, rval, complain);
850 :
851 17816318 : if (rval != error_mark_node)
852 17816318 : 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 : initialization 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 1259 : build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
870 : {
871 1259 : tree inner_type = strip_array_types (type);
872 :
873 1259 : if (integer_zerop (array_type_nelts_total (type))
874 1259 : || !CLASS_TYPE_P (inner_type))
875 : /* No interesting initialization to do. */
876 216 : return integer_zero_node;
877 1043 : 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 203 : if (CP_AGGREGATE_TYPE_P (inner_type))
882 : {
883 58 : tree empty = build_constructor (init_list_type_node, nullptr);
884 58 : return digest_init (inner_type, empty, complain);
885 : }
886 : else
887 : /* It's equivalent to value-init. */
888 145 : init = void_type_node;
889 : }
890 985 : if (init == void_type_node)
891 176 : return build_value_init (inner_type, complain);
892 :
893 809 : releasing_vec argvec;
894 809 : 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 809 : 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 809 : if (TREE_CODE (init) == TARGET_EXPR)
909 32 : init = TARGET_EXPR_INITIAL (init);
910 :
911 809 : return init;
912 809 : }
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 1276 : build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
920 : {
921 1276 : if (tree vi = get_vec_init_expr (init))
922 : return vi;
923 :
924 1261 : tree elt_init;
925 648 : if (init && TREE_CODE (init) == CONSTRUCTOR
926 1468 : && !BRACE_ENCLOSED_INITIALIZER_P (init))
927 : /* We built any needed constructor calls in digest_init. */
928 : elt_init = init;
929 : else
930 1257 : elt_init = build_vec_init_elt (type, init, complain);
931 :
932 1261 : bool value_init = false;
933 1261 : if (init == void_type_node)
934 : {
935 226 : value_init = true;
936 226 : init = NULL_TREE;
937 : }
938 :
939 1261 : tree slot = build_local_temp (type);
940 1261 : init = build2 (VEC_INIT_EXPR, type, slot, init);
941 1261 : TREE_SIDE_EFFECTS (init) = true;
942 1261 : SET_EXPR_LOCATION (init, input_location);
943 :
944 1261 : if (cxx_dialect >= cxx11)
945 : {
946 1175 : bool cx = potential_constant_expression (elt_init);
947 1175 : if (BRACE_ENCLOSED_INITIALIZER_P (init))
948 0 : cx &= potential_constant_expression (init);
949 1175 : VEC_INIT_EXPR_IS_CONSTEXPR (init) = cx;
950 : }
951 1261 : VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
952 :
953 1261 : 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 1253 : expand_vec_init_expr (tree target, tree vec_init, tsubst_flags_t complain,
961 : vec<tree,va_gc> **flags)
962 : {
963 1253 : iloc_sentinel ils = EXPR_LOCATION (vec_init);
964 :
965 1253 : if (!target)
966 0 : target = VEC_INIT_EXPR_SLOT (vec_init);
967 1253 : tree init = VEC_INIT_EXPR_INIT (vec_init);
968 1253 : int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
969 3759 : return build_vec_init (target, NULL_TREE, init,
970 1253 : VEC_INIT_EXPR_VALUE_INIT (vec_init),
971 1253 : from_array, complain, flags);
972 1253 : }
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 9052646 : build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
1003 : {
1004 9052646 : gcc_assert (!VOID_TYPE_P (type));
1005 9052646 : gcc_assert (!VOID_TYPE_P (TREE_TYPE (init)));
1006 :
1007 9052646 : if (TREE_CODE (init) == TARGET_EXPR
1008 7964177 : || init == error_mark_node)
1009 : return init;
1010 5793384 : else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
1011 71130 : && TREE_CODE (init) != COND_EXPR
1012 : && TREE_CODE (init) != CONSTRUCTOR
1013 : && TREE_CODE (init) != VA_ARG_EXPR
1014 7963919 : && 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 7963919 : 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 16202494 : force_target_expr (tree type, tree init, tsubst_flags_t complain)
1033 : {
1034 16202494 : tree slot;
1035 :
1036 16202494 : gcc_assert (!VOID_TYPE_P (type));
1037 :
1038 16202494 : slot = build_local_temp (type);
1039 16202494 : 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 7235044 : get_target_expr (tree init, tsubst_flags_t complain /* = tf_warning_or_error */)
1046 : {
1047 7235044 : if (TREE_CODE (init) == AGGR_INIT_EXPR)
1048 553796 : return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
1049 6681248 : else if (TREE_CODE (init) == VEC_INIT_EXPR)
1050 378 : return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
1051 : else
1052 : {
1053 6680870 : init = convert_bitfield_to_declared_type (init);
1054 6680870 : 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 2962633 : get_internal_target_expr (tree init)
1069 : {
1070 2962633 : init = convert_bitfield_to_declared_type (init);
1071 2962633 : tree t = force_target_expr (TREE_TYPE (init), init, tf_warning_or_error);
1072 2962633 : TARGET_EXPR_INTERNAL_P (t) = true;
1073 2962633 : 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 1028997405 : convert_bitfield_to_declared_type (tree expr)
1082 : {
1083 1028997405 : tree bitfield_type;
1084 :
1085 1028997405 : bitfield_type = is_bitfield_expr_with_lowered_type (expr);
1086 1028997405 : if (bitfield_type)
1087 566716 : expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
1088 : expr);
1089 1028997405 : 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 183736551 : rvalue (tree expr)
1097 : {
1098 183736551 : tree type;
1099 :
1100 183736551 : if (error_operand_p (expr))
1101 : return expr;
1102 :
1103 183736230 : 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 183736230 : type = TREE_TYPE (expr);
1109 183736230 : if (!CLASS_TYPE_P (type) && TREE_CODE (type) != ARRAY_TYPE
1110 364362918 : && cv_qualified_p (type))
1111 36099913 : 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 183736230 : 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 10052907 : gcc_checking_assert (!CLASS_TYPE_P (type));
1120 10052907 : expr = build1 (NON_LVALUE_EXPR, type, expr);
1121 : }
1122 173683323 : else if (type != TREE_TYPE (expr))
1123 35771184 : 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 40177526 : cplus_array_hasher::hash (tree t)
1147 : {
1148 40177526 : hashval_t hash;
1149 :
1150 40177526 : hash = TYPE_UID (TREE_TYPE (t));
1151 40177526 : if (TYPE_DOMAIN (t))
1152 36376724 : hash ^= TYPE_UID (TYPE_DOMAIN (t));
1153 40177526 : 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 50492753 : cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
1161 : {
1162 53247750 : 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 5292075 : build_min_array_type (tree elt_type, tree index_type)
1173 : {
1174 5292075 : tree t = cxx_make_type (ARRAY_TYPE);
1175 5292075 : TREE_TYPE (t) = elt_type;
1176 5292075 : TYPE_DOMAIN (t) = index_type;
1177 5292075 : 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 5292075 : 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 5292075 : if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
1188 5292075 : || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
1189 1310129 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1190 3981946 : else if (TYPE_CANONICAL (elt_type) != elt_type
1191 3981946 : || (index_type && TYPE_CANONICAL (index_type) != index_type))
1192 1173982 : TYPE_CANONICAL (t)
1193 3074812 : = build_cplus_array_type (TYPE_CANONICAL (elt_type),
1194 : index_type
1195 726848 : ? TYPE_CANONICAL (index_type) : index_type,
1196 : dep);
1197 : else
1198 2807964 : TYPE_CANONICAL (t) = t;
1199 5292075 : }
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 64461874 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
1208 : {
1209 64461874 : tree t;
1210 :
1211 64461874 : if (elt_type == error_mark_node || index_type == error_mark_node)
1212 : return error_mark_node;
1213 :
1214 64461871 : if (dependent < 0)
1215 67166564 : dependent = (uses_template_parms (elt_type)
1216 33583282 : || (index_type && uses_template_parms (index_type)));
1217 :
1218 64461871 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1219 : /* Start with an array of the TYPE_MAIN_VARIANT. */
1220 27377400 : t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
1221 : index_type, dependent);
1222 37084471 : else if (dependent)
1223 : {
1224 : /* Since type_hash_canon calls layout_type, we need to use our own
1225 : hash table. */
1226 4595760 : cplus_array_info cai;
1227 4595760 : hashval_t hash;
1228 :
1229 4595760 : if (cplus_array_htab == NULL)
1230 17401 : cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61);
1231 :
1232 4595760 : hash = TYPE_UID (elt_type);
1233 4595760 : if (index_type)
1234 2487470 : hash ^= TYPE_UID (index_type);
1235 4595760 : cai.type = elt_type;
1236 4595760 : cai.domain = index_type;
1237 :
1238 4595760 : tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
1239 4595760 : if (*e)
1240 : /* We have found the type: we're done. */
1241 2645311 : return (tree) *e;
1242 : else
1243 : {
1244 : /* Build a new array type. */
1245 1950449 : t = build_min_array_type (elt_type, index_type);
1246 :
1247 : /* Store it in the hash table. */
1248 1950449 : *e = t;
1249 :
1250 : /* Set the canonical type for this new node. */
1251 1950449 : set_array_type_canon (t, elt_type, index_type, dependent);
1252 :
1253 : /* Mark it as dependent now, this saves time later. */
1254 1950449 : TYPE_DEPENDENT_P_VALID (t) = true;
1255 1950449 : TYPE_DEPENDENT_P (t) = true;
1256 : }
1257 : }
1258 : else
1259 : {
1260 32488711 : bool typeless_storage = is_byte_access_type (elt_type);
1261 32488711 : t = build_array_type (elt_type, index_type, typeless_storage);
1262 :
1263 : /* Mark as non-dependenty now, this will save time later. */
1264 32488711 : TYPE_DEPENDENT_P_VALID (t) = true;
1265 : }
1266 :
1267 : /* Now check whether we already have this array variant. */
1268 61816560 : if (elt_type != TYPE_MAIN_VARIANT (elt_type))
1269 : {
1270 : tree m = t;
1271 55629160 : for (t = m; t; t = TYPE_NEXT_VARIANT (t))
1272 52287534 : if (TREE_TYPE (t) == elt_type
1273 24043011 : && TYPE_NAME (t) == NULL_TREE
1274 24035777 : && TYPE_ATTRIBUTES (t) == NULL_TREE
1275 24035777 : && (!TYPE_USER_ALIGN (t)
1276 17947 : || (TYPE_USER_ALIGN (elt_type)
1277 17944 : && TYPE_ALIGN (t) == TYPE_ALIGN (elt_type)))
1278 24035774 : && !TREE_DEPRECATED (t)
1279 76323308 : && !TREE_UNAVAILABLE (t))
1280 : break;
1281 27377400 : if (!t)
1282 : {
1283 3341626 : t = build_min_array_type (elt_type, index_type);
1284 : /* Mark dependency now, this saves time later. */
1285 3341626 : TYPE_DEPENDENT_P_VALID (t) = true;
1286 3341626 : TYPE_DEPENDENT_P (t) = dependent;
1287 3341626 : set_array_type_canon (t, elt_type, index_type, dependent);
1288 3341626 : if (!dependent)
1289 : {
1290 2779524 : 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 2779524 : TYPE_SIZE (t) = TYPE_SIZE (m);
1295 2779524 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
1296 2779524 : TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
1297 : }
1298 :
1299 3341626 : TYPE_MAIN_VARIANT (t) = m;
1300 3341626 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
1301 3341626 : TYPE_NEXT_VARIANT (m) = t;
1302 : }
1303 : }
1304 :
1305 : /* Avoid spurious warnings with VLAs (c++/54583). */
1306 61816560 : if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
1307 2060 : 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 123633120 : bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t)
1312 61816560 : = TYPE_NEEDS_CONSTRUCTING (elt_type));
1313 123633120 : bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1314 61816560 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
1315 :
1316 59161723 : if (!dependent && t == TYPE_MAIN_VARIANT (t)
1317 94305271 : && !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 2790504 : layout_type (t);
1323 4027717 : for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
1324 : {
1325 1237213 : TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
1326 1237213 : 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 2165005 : build_array_of_n_type (tree elt, unsigned HOST_WIDE_INT n)
1337 : {
1338 2165005 : 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 7184472 : array_of_unknown_bound_p (const_tree t)
1345 : {
1346 7184472 : return (TREE_CODE (t) == ARRAY_TYPE
1347 7184472 : && !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 549357 : array_of_runtime_bound_p (tree t)
1357 : {
1358 549357 : 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 41892922 : vla_type_p (tree t)
1374 : {
1375 42670537 : for (; t && TREE_CODE (t) == ARRAY_TYPE;
1376 777615 : t = TREE_TYPE (t))
1377 777798 : if (tree dom = TYPE_DOMAIN (t))
1378 : {
1379 777734 : tree max = TYPE_MAX_VALUE (dom);
1380 777734 : if (!potential_rvalue_constant_expression (max)
1381 777734 : || (!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 613446590 : cp_build_reference_type_for_mode (tree to_type, machine_mode mode, bool rval)
1395 : {
1396 613446590 : tree lvalue_ref, t;
1397 :
1398 613446590 : if (to_type == error_mark_node)
1399 : return error_mark_node;
1400 :
1401 613446585 : if (TYPE_REF_P (to_type))
1402 : {
1403 1909 : rval = rval && TYPE_REF_IS_RVALUE (to_type);
1404 1909 : to_type = TREE_TYPE (to_type);
1405 : }
1406 :
1407 613446585 : lvalue_ref = build_reference_type_for_mode (to_type, mode, false);
1408 :
1409 613446585 : 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 106579626 : for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
1421 79028744 : if (TYPE_REF_IS_RVALUE (t))
1422 : return t;
1423 :
1424 27550882 : t = build_distinct_type_copy (lvalue_ref);
1425 :
1426 27550882 : TYPE_REF_IS_RVALUE (t) = true;
1427 27550882 : TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
1428 27550882 : TYPE_NEXT_REF_TO (lvalue_ref) = t;
1429 :
1430 27550882 : if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
1431 973521 : SET_TYPE_STRUCTURAL_EQUALITY (t);
1432 26577361 : else if (TYPE_CANONICAL (to_type) != to_type)
1433 15092577 : TYPE_CANONICAL (t)
1434 30185154 : = cp_build_reference_type_for_mode (TYPE_CANONICAL (to_type), mode, rval);
1435 : else
1436 11484784 : TYPE_CANONICAL (t) = t;
1437 :
1438 27550882 : layout_type (t);
1439 :
1440 27550882 : 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 503858990 : cp_build_reference_type (tree to_type, bool rval)
1450 : {
1451 503858990 : 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 2079632 : move (tree expr)
1458 : {
1459 2079632 : tree type = TREE_TYPE (expr);
1460 2079632 : gcc_assert (!TYPE_REF_P (type));
1461 2079632 : if (xvalue_p (expr))
1462 : return expr;
1463 2079400 : type = cp_build_reference_type (type, /*rval*/true);
1464 2079400 : return build_static_cast (input_location, type, expr,
1465 2079400 : 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 26277806 : c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */,
1473 : size_t /* orig_qual_indirect */)
1474 : {
1475 26277806 : 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 17716673586 : cp_build_qualified_type (tree type, int type_quals,
1501 : tsubst_flags_t complain /* = tf_warning_or_error */)
1502 : {
1503 17716673586 : tree result;
1504 17716673586 : int bad_quals = TYPE_UNQUALIFIED;
1505 :
1506 17716673586 : if (type == error_mark_node)
1507 : return type;
1508 :
1509 17682696976 : if (type_quals == cp_type_quals (type))
1510 : return type;
1511 :
1512 3060923714 : 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 31359747 : tree t;
1517 31359747 : tree element_type
1518 31359747 : = cp_build_qualified_type (TREE_TYPE (type), type_quals, complain);
1519 :
1520 31359747 : 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 59776325 : for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1526 34645294 : if (TREE_TYPE (t) == element_type
1527 6497608 : && TYPE_NAME (t) == TYPE_NAME (type)
1528 6228716 : && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
1529 40874010 : && attribute_list_equal (TYPE_ATTRIBUTES (t),
1530 6228716 : TYPE_ATTRIBUTES (type)))
1531 : break;
1532 :
1533 31359747 : 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 25131031 : t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
1539 25131031 : TYPE_DEPENDENT_P_VALID (type)
1540 532063 : ? int (TYPE_DEPENDENT_P (type)) : -1);
1541 :
1542 : /* Keep the typedef name. */
1543 25131031 : if (TYPE_NAME (t) != TYPE_NAME (type))
1544 : {
1545 12948 : t = build_variant_type_copy (t);
1546 12948 : TYPE_NAME (t) = TYPE_NAME (type);
1547 12948 : SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
1548 12948 : 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 62719494 : TYPE_NEEDS_CONSTRUCTING (t)
1560 31359747 : = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
1561 62719494 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
1562 31359747 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
1563 31359747 : return t;
1564 : }
1565 3029563967 : 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 3029563964 : if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
1583 968432415 : && (TYPE_REF_P (type)
1584 968008204 : || FUNC_OR_METHOD_TYPE_P (type)))
1585 : {
1586 424988 : if (TYPE_REF_P (type)
1587 424988 : && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
1588 : bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1589 424988 : type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
1590 : }
1591 :
1592 : /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1593 3029563964 : if (TREE_CODE (type) == FUNCTION_TYPE)
1594 780 : 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 3029563964 : if ((type_quals & TYPE_QUAL_RESTRICT)
1599 8513676 : && TREE_CODE (type) != TEMPLATE_TYPE_PARM
1600 8513639 : && TREE_CODE (type) != TYPENAME_TYPE
1601 8513633 : && !INDIRECT_TYPE_P (type))
1602 : {
1603 25 : bad_quals |= TYPE_QUAL_RESTRICT;
1604 25 : type_quals &= ~TYPE_QUAL_RESTRICT;
1605 : }
1606 :
1607 3029563964 : if (bad_quals == TYPE_UNQUALIFIED
1608 267798 : || (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 3029563964 : result = build_qualified_type (type, type_quals);
1621 :
1622 3029563964 : 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 262295875 : cp_build_function_type (tree value_type, tree arg_types)
1632 : {
1633 262295875 : return build_function_type (value_type, arg_types,
1634 262295875 : cxx_dialect >= cxx26
1635 262295875 : && arg_types == NULL_TREE);
1636 : }
1637 :
1638 : /* Return TYPE with const and volatile removed. */
1639 :
1640 : tree
1641 1617298360 : cv_unqualified (tree type)
1642 : {
1643 1617298360 : int quals;
1644 :
1645 1617298360 : if (type == error_mark_node)
1646 : return type;
1647 :
1648 1617298169 : quals = cp_type_quals (type);
1649 1617298169 : quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
1650 1617298169 : 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 8649618 : apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
1659 : {
1660 8649618 : tree first_ident = NULL_TREE;
1661 8649618 : tree new_attribs = NULL_TREE;
1662 8649618 : tree *p = &new_attribs;
1663 :
1664 8649618 : if (OVERLOAD_TYPE_P (result))
1665 : {
1666 : /* On classes and enums all attributes are ingrained. */
1667 8648735 : 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) doesn'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 2816486792 : strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
1736 : unsigned int flags /* = 0 */)
1737 : {
1738 2816486792 : tree result = NULL, type = NULL, t0 = NULL;
1739 :
1740 2816486792 : if (!t || t == error_mark_node)
1741 : return t;
1742 :
1743 2780157422 : if (!TYPE_P (t))
1744 178034544 : return strip_typedefs_expr (t, remove_attributes, flags);
1745 :
1746 2602122878 : if (t == TYPE_CANONICAL (t))
1747 : return t;
1748 :
1749 1011303363 : if (typedef_variant_p (t))
1750 : {
1751 331613825 : if ((flags & STF_USER_VISIBLE)
1752 331613825 : && !user_facing_original_type_p (t))
1753 : return t;
1754 :
1755 331613707 : if ((flags & STF_KEEP_INJ_CLASS_NAME)
1756 32756 : && CLASS_TYPE_P (t)
1757 331623147 : && DECL_SELF_REFERENCE_P (TYPE_NAME (t)))
1758 : return t;
1759 :
1760 331613706 : if (dependent_opaque_alias_p (t))
1761 : return t;
1762 :
1763 331611876 : if (alias_template_specialization_p (t, nt_opaque))
1764 : {
1765 95573250 : if (dependent_alias_template_spec_p (t, nt_opaque)
1766 95573250 : && !(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 236038626 : flags |= STF_STRIP_DEPENDENT;
1776 :
1777 317438562 : result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
1778 : remove_attributes, flags);
1779 317438562 : goto stripped;
1780 : }
1781 :
1782 679689538 : switch (TREE_CODE (t))
1783 : {
1784 10404866 : case POINTER_TYPE:
1785 10404866 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1786 10404866 : result = build_pointer_type_for_mode (type, TYPE_MODE (t), false);
1787 10404866 : break;
1788 94495023 : case REFERENCE_TYPE:
1789 94495023 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1790 94495023 : result = cp_build_reference_type_for_mode (type, TYPE_MODE (t), TYPE_REF_IS_RVALUE (t));
1791 94495023 : break;
1792 315559 : case OFFSET_TYPE:
1793 315559 : t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags);
1794 315559 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1795 315559 : result = build_offset_type (t0, type);
1796 315559 : break;
1797 24453009 : case RECORD_TYPE:
1798 24453009 : if (TYPE_PTRMEMFUNC_P (t))
1799 : {
1800 1527962 : t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t),
1801 : remove_attributes, flags);
1802 1527962 : result = build_ptrmemfunc_type (t0);
1803 : }
1804 : break;
1805 1773774 : case ARRAY_TYPE:
1806 1773774 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1807 1773774 : t0 = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags);
1808 1773774 : gcc_checking_assert (TYPE_DEPENDENT_P_VALID (t)
1809 : || !dependent_type_p (t));
1810 1773774 : result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t));
1811 1773774 : break;
1812 7543693 : case FUNCTION_TYPE:
1813 7543693 : case METHOD_TYPE:
1814 7543693 : {
1815 7543693 : tree arg_types = NULL, arg_node, arg_node2, arg_type;
1816 7543693 : 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 7543693 : bool is_variant = typedef_variant_p (t);
1824 7543693 : if (remove_attributes
1825 7543693 : && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t)))
1826 : is_variant = true;
1827 :
1828 7543693 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
1829 7543693 : tree canon_spec = (flag_noexcept_type
1830 7532884 : ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t))
1831 7543693 : : NULL_TREE);
1832 10049904 : changed = (type != TREE_TYPE (t) || is_variant
1833 10049701 : || TYPE_RAISES_EXCEPTIONS (t) != canon_spec);
1834 :
1835 7543693 : for (arg_node = TYPE_ARG_TYPES (t);
1836 11752061 : arg_node;
1837 4208368 : arg_node = TREE_CHAIN (arg_node))
1838 : {
1839 10971546 : if (arg_node == void_list_node)
1840 : break;
1841 4208368 : arg_type = strip_typedefs (TREE_VALUE (arg_node),
1842 : remove_attributes, flags);
1843 4208368 : gcc_assert (arg_type);
1844 4208368 : if (arg_type == TREE_VALUE (arg_node) && !changed)
1845 3957331 : continue;
1846 :
1847 251037 : if (!changed)
1848 : {
1849 38458 : changed = true;
1850 38458 : for (arg_node2 = TYPE_ARG_TYPES (t);
1851 48655 : arg_node2 != arg_node;
1852 10197 : arg_node2 = TREE_CHAIN (arg_node2))
1853 10197 : arg_types
1854 10197 : = tree_cons (TREE_PURPOSE (arg_node2),
1855 10197 : TREE_VALUE (arg_node2), arg_types);
1856 : }
1857 :
1858 251037 : arg_types
1859 251037 : = tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
1860 : }
1861 :
1862 7543693 : if (!changed)
1863 : return t;
1864 :
1865 5077124 : if (arg_types)
1866 59071 : arg_types = nreverse (arg_types);
1867 :
1868 : /* A list of parameters not ending with an ellipsis
1869 : must end with void_list_node. */
1870 5077124 : if (arg_node)
1871 5077083 : arg_types = chainon (arg_types, void_list_node);
1872 :
1873 5077124 : if (TREE_CODE (t) == METHOD_TYPE)
1874 : {
1875 27420 : tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
1876 27420 : gcc_assert (class_type);
1877 27420 : result =
1878 27420 : build_method_type_directly (class_type, type,
1879 27420 : TREE_CHAIN (arg_types));
1880 : }
1881 : else
1882 : {
1883 15149112 : result = build_function_type (type, arg_types,
1884 5049704 : TYPE_NO_NAMED_ARGS_STDARG_P (t));
1885 5049704 : result = apply_memfn_quals (result, type_memfn_quals (t));
1886 : }
1887 :
1888 15231372 : result = build_cp_fntype_variant (result,
1889 : type_memfn_rqual (t), canon_spec,
1890 5077124 : TYPE_HAS_LATE_RETURN_TYPE (t));
1891 : }
1892 5077124 : break;
1893 74284459 : case TYPENAME_TYPE:
1894 74284459 : {
1895 74284459 : bool changed = false;
1896 74284459 : tree fullname = TYPENAME_TYPE_FULLNAME (t);
1897 74284459 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
1898 74284459 : && TREE_OPERAND (fullname, 1))
1899 : {
1900 4595617 : tree args = TREE_OPERAND (fullname, 1);
1901 4595617 : tree new_args = copy_node (args);
1902 12744176 : for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
1903 : {
1904 8148559 : tree arg = TREE_VEC_ELT (args, i);
1905 8148559 : tree strip_arg = strip_typedefs (arg, remove_attributes, flags);
1906 8148559 : TREE_VEC_ELT (new_args, i) = strip_arg;
1907 8148559 : if (strip_arg != arg)
1908 243414 : changed = true;
1909 : }
1910 4595617 : if (changed)
1911 : {
1912 243414 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
1913 243414 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
1914 243414 : fullname
1915 243414 : = lookup_template_function (TREE_OPERAND (fullname, 0),
1916 : new_args);
1917 : }
1918 : else
1919 4352203 : ggc_free (new_args);
1920 : }
1921 74284459 : tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes, flags);
1922 74284459 : if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t))
1923 : return t;
1924 4582871 : tree name = fullname;
1925 4582871 : if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
1926 266502 : 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 4582871 : result = build_typename_type (ctx, name, fullname, typename_type);
1930 : }
1931 4582871 : break;
1932 12672879 : case DECLTYPE_TYPE:
1933 12672879 : result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t),
1934 : remove_attributes, flags);
1935 12672879 : if (result == DECLTYPE_TYPE_EXPR (t))
1936 : result = NULL_TREE;
1937 : else
1938 360056 : result = (finish_decltype_type
1939 360056 : (result,
1940 360056 : DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
1941 : tf_none));
1942 : break;
1943 813129 : case TRAIT_TYPE:
1944 813129 : {
1945 813129 : tree type1 = strip_typedefs (TRAIT_TYPE_TYPE1 (t),
1946 : remove_attributes, flags);
1947 813129 : tree type2 = strip_typedefs (TRAIT_TYPE_TYPE2 (t),
1948 : remove_attributes, flags);
1949 813129 : 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 23523801 : case TYPE_PACK_EXPANSION:
1957 23523801 : {
1958 23523801 : tree pat = PACK_EXPANSION_PATTERN (t);
1959 23523801 : if (TYPE_P (pat))
1960 : {
1961 23523801 : type = strip_typedefs (pat, remove_attributes, flags);
1962 23523801 : if (type != pat)
1963 : {
1964 290410 : result = build_distinct_type_copy (t);
1965 290410 : PACK_EXPANSION_PATTERN (result) = type;
1966 : }
1967 : }
1968 : }
1969 : break;
1970 : default:
1971 : break;
1972 : }
1973 :
1974 118827645 : if (!result)
1975 488693736 : result = TYPE_MAIN_VARIANT (t);
1976 :
1977 118827645 : 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 924959943 : 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 924959937 : if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
1990 924959937 : || 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 924959937 : if (TYPE_ATTRIBUTES (t))
2006 : {
2007 8659391 : if (remove_attributes)
2008 8649618 : result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t),
2009 : remove_attributes);
2010 : else
2011 9773 : result = cp_build_type_attribute_variant (result,
2012 9773 : TYPE_ATTRIBUTES (t));
2013 : }
2014 : }
2015 :
2016 924959943 : 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 349908575 : strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags)
2032 : {
2033 349908575 : unsigned i,n;
2034 349908575 : tree r, type, *ops;
2035 349908575 : enum tree_code code;
2036 :
2037 349908575 : if (t == NULL_TREE || t == error_mark_node)
2038 : return t;
2039 :
2040 349908575 : STRIP_ANY_LOCATION_WRAPPER (t);
2041 :
2042 349908575 : if (DECL_P (t) || CONSTANT_CLASS_P (t))
2043 : return t;
2044 :
2045 189689756 : code = TREE_CODE (t);
2046 189689756 : 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 2251933 : case TRAIT_EXPR:
2056 2251933 : {
2057 2251933 : tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t),
2058 : remove_attributes, flags);
2059 2251933 : tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t),
2060 : remove_attributes, flags);
2061 2251933 : if (type1 == TRAIT_EXPR_TYPE1 (t)
2062 2251933 : && type2 == TRAIT_EXPR_TYPE2 (t))
2063 : return t;
2064 52071 : r = copy_node (t);
2065 52071 : TRAIT_EXPR_TYPE1 (r) = type1;
2066 52071 : TRAIT_EXPR_TYPE2 (r) = type2;
2067 52071 : return r;
2068 : }
2069 :
2070 978089 : case TREE_LIST:
2071 978089 : {
2072 978089 : bool changed = false;
2073 978089 : auto_vec<tree_pair, 4> vec;
2074 978089 : r = t;
2075 2090251 : for (; t; t = TREE_CHAIN (t))
2076 : {
2077 1112162 : tree purpose = strip_typedefs (TREE_PURPOSE (t),
2078 1112162 : remove_attributes, flags);
2079 1112162 : tree value = strip_typedefs (TREE_VALUE (t),
2080 1112162 : remove_attributes, flags);
2081 1112162 : if (purpose != TREE_PURPOSE (t) || value != TREE_VALUE (t))
2082 : changed = true;
2083 1112162 : vec.safe_push ({purpose, value});
2084 : }
2085 978089 : if (changed)
2086 : {
2087 235315 : r = NULL_TREE;
2088 769788 : for (int i = vec.length () - 1; i >= 0; i--)
2089 299158 : r = tree_cons (vec[i].first, vec[i].second, r);
2090 : }
2091 978089 : return r;
2092 978089 : }
2093 :
2094 19308291 : case TREE_VEC:
2095 19308291 : {
2096 19308291 : bool changed = false;
2097 19308291 : releasing_vec vec;
2098 19308291 : n = TREE_VEC_LENGTH (t);
2099 19308291 : vec_safe_reserve (vec, n);
2100 41147861 : for (i = 0; i < n; ++i)
2101 : {
2102 21839570 : tree op = strip_typedefs (TREE_VEC_ELT (t, i),
2103 21839570 : remove_attributes, flags);
2104 21839570 : vec->quick_push (op);
2105 21839570 : if (op != TREE_VEC_ELT (t, i))
2106 206284 : changed = true;
2107 : }
2108 19308291 : if (changed)
2109 : {
2110 206284 : r = copy_node (t);
2111 638093 : for (i = 0; i < n; ++i)
2112 225525 : TREE_VEC_ELT (r, i) = (*vec)[i];
2113 412568 : NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
2114 412568 : = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
2115 : }
2116 : else
2117 : r = t;
2118 19308291 : return r;
2119 19308291 : }
2120 :
2121 299558 : case CONSTRUCTOR:
2122 299558 : {
2123 299558 : bool changed = false;
2124 299558 : vec<constructor_elt, va_gc> *vec
2125 299558 : = vec_safe_copy (CONSTRUCTOR_ELTS (t));
2126 299558 : n = CONSTRUCTOR_NELTS (t);
2127 299558 : type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
2128 319151 : for (i = 0; i < n; ++i)
2129 : {
2130 19593 : constructor_elt *e = &(*vec)[i];
2131 19593 : tree op = strip_typedefs (e->value, remove_attributes, flags);
2132 19593 : if (op != e->value)
2133 : {
2134 6 : changed = true;
2135 6 : e->value = op;
2136 : }
2137 19593 : gcc_checking_assert
2138 : (e->index == strip_typedefs (e->index, remove_attributes,
2139 : flags));
2140 : }
2141 :
2142 299558 : if (!changed && type == TREE_TYPE (t))
2143 : {
2144 277674 : vec_free (vec);
2145 277674 : return t;
2146 : }
2147 : else
2148 : {
2149 21884 : r = copy_node (t);
2150 21884 : TREE_TYPE (r) = type;
2151 21884 : CONSTRUCTOR_ELTS (r) = vec;
2152 21884 : 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 100851444 : default:
2163 100851444 : break;
2164 : }
2165 :
2166 100851444 : gcc_assert (EXPR_P (t));
2167 :
2168 100851444 : n = cp_tree_operand_length (t);
2169 100851444 : ops = XALLOCAVEC (tree, n);
2170 100851444 : type = TREE_TYPE (t);
2171 :
2172 100851444 : switch (code)
2173 : {
2174 7217261 : CASE_CONVERT:
2175 7217261 : case IMPLICIT_CONV_EXPR:
2176 7217261 : case DYNAMIC_CAST_EXPR:
2177 7217261 : case STATIC_CAST_EXPR:
2178 7217261 : case CONST_CAST_EXPR:
2179 7217261 : case REINTERPRET_CAST_EXPR:
2180 7217261 : case CAST_EXPR:
2181 7217261 : case NEW_EXPR:
2182 7217261 : type = strip_typedefs (type, remove_attributes, flags);
2183 : /* fallthrough */
2184 :
2185 100851444 : default:
2186 331241818 : for (i = 0; i < n; ++i)
2187 230390374 : ops[i] = strip_typedefs (TREE_OPERAND (t, i),
2188 : remove_attributes, flags);
2189 : break;
2190 : }
2191 :
2192 : /* If nothing changed, return t. */
2193 325353301 : for (i = 0; i < n; ++i)
2194 228330864 : if (ops[i] != TREE_OPERAND (t, i))
2195 : break;
2196 100851444 : if (i == n && type == TREE_TYPE (t))
2197 : return t;
2198 :
2199 4091070 : r = copy_node (t);
2200 4091070 : TREE_TYPE (r) = type;
2201 13000103 : for (i = 0; i < n; ++i)
2202 8909033 : 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 36477344 : copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
2226 : {
2227 36477344 : tree new_binfo;
2228 :
2229 36477344 : if (virt)
2230 : {
2231 : /* See if we've already made this virtual base. */
2232 281507 : new_binfo = binfo_for_vbase (type, t);
2233 281507 : if (new_binfo)
2234 : return new_binfo;
2235 : }
2236 :
2237 65975963 : new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
2238 36409353 : BINFO_TYPE (new_binfo) = type;
2239 :
2240 : /* Chain it into the inheritance graph. */
2241 36409353 : TREE_CHAIN (*igo_prev) = new_binfo;
2242 36409353 : *igo_prev = new_binfo;
2243 :
2244 65975963 : if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
2245 : {
2246 29566601 : int ix;
2247 29566601 : tree base_binfo;
2248 :
2249 29566601 : gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
2250 :
2251 29566601 : BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
2252 29566601 : BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
2253 :
2254 : /* We do not need to copy the accesses, as they are read only. */
2255 29566601 : BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
2256 :
2257 : /* Recursively copy base binfos of BINFO. */
2258 33721360 : for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
2259 : {
2260 4154759 : tree new_base_binfo;
2261 4154759 : new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
2262 : t, igo_prev,
2263 4154759 : BINFO_VIRTUAL_P (base_binfo));
2264 :
2265 4154759 : if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
2266 3940296 : BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
2267 4154759 : BINFO_BASE_APPEND (new_binfo, new_base_binfo);
2268 : }
2269 : }
2270 : else
2271 6842752 : BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
2272 :
2273 36409353 : if (virt)
2274 : {
2275 : /* Push it onto the list after any virtual bases it contains
2276 : will have been pushed. */
2277 213516 : CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo);
2278 213516 : BINFO_VIRTUAL_P (new_binfo) = 1;
2279 213516 : 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 2482535980 : list_hasher::equal (tree t, list_proxy *proxy)
2316 : {
2317 2482535980 : return (TREE_VALUE (t) == proxy->value
2318 165546156 : && TREE_PURPOSE (t) == proxy->purpose
2319 2646205587 : && 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 2314749124 : list_hash_pieces (tree purpose, tree value, tree chain)
2328 : {
2329 2314749124 : hashval_t hashcode = 0;
2330 :
2331 2314749124 : if (chain)
2332 2314562721 : hashcode += TREE_HASH (chain);
2333 :
2334 2314749124 : if (value)
2335 2314749124 : hashcode += TREE_HASH (value);
2336 : else
2337 0 : hashcode += 1007;
2338 2314749124 : if (purpose)
2339 149888163 : hashcode += TREE_HASH (purpose);
2340 : else
2341 2164860961 : hashcode += 1009;
2342 2314749124 : return hashcode;
2343 : }
2344 :
2345 : /* Hash an already existing TREE_LIST. */
2346 :
2347 : hashval_t
2348 2010806892 : list_hasher::hash (tree t)
2349 : {
2350 2010806892 : return list_hash_pieces (TREE_PURPOSE (t),
2351 2010806892 : TREE_VALUE (t),
2352 2010806892 : 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 303942232 : hash_tree_cons (tree purpose, tree value, tree chain)
2361 : {
2362 303942232 : int hashcode = 0;
2363 303942232 : tree *slot;
2364 303942232 : struct list_proxy proxy;
2365 :
2366 : /* Hash the list node. */
2367 303942232 : 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 303942232 : proxy.purpose = purpose;
2371 303942232 : proxy.value = value;
2372 303942232 : proxy.chain = chain;
2373 : /* See if it is already in the table. */
2374 303942232 : slot = list_hash_table->find_slot_with_hash (&proxy, hashcode, INSERT);
2375 : /* If not, create a new node. */
2376 303942232 : if (!*slot)
2377 146212001 : *slot = tree_cons (purpose, value, chain);
2378 303942232 : return (tree) *slot;
2379 : }
2380 :
2381 : /* Constructor for hashed lists. */
2382 :
2383 : tree
2384 2242096 : hash_tree_chain (tree value, tree chain)
2385 : {
2386 2242096 : 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 151066612 : build_qualified_name (tree type, tree scope, tree name, bool template_p)
2431 : {
2432 151066612 : tree t;
2433 151066612 : if (type == error_mark_node
2434 151066612 : || scope == error_mark_node
2435 151066609 : || name == error_mark_node)
2436 : return error_mark_node;
2437 151066609 : gcc_assert (TREE_CODE (name) != SCOPE_REF);
2438 151066609 : t = build2 (SCOPE_REF, type, scope, name);
2439 151066609 : QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
2440 151066609 : PTRMEM_OK_P (t) = true;
2441 151066609 : if (type)
2442 10276725 : 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 1243376981 : cp_check_qualified_type (const_tree cand, const_tree base, int type_quals,
2452 : cp_ref_qualifier rqual, tree raises, bool late)
2453 : {
2454 1243376981 : return (TYPE_QUALS (cand) == type_quals
2455 1243312520 : && check_base_type (cand, base)
2456 1243211842 : && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand),
2457 : ce_exact)
2458 595003613 : && TYPE_HAS_LATE_RETURN_TYPE (cand) == late
2459 1799596046 : && type_memfn_rqual (cand) == rqual);
2460 : }
2461 :
2462 : /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */
2463 :
2464 : tree
2465 616057 : build_ref_qualified_type (tree type, cp_ref_qualifier rqual)
2466 : {
2467 616057 : tree raises = TYPE_RAISES_EXCEPTIONS (type);
2468 616057 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
2469 616057 : return build_cp_fntype_variant (type, rqual, raises, late);
2470 : }
2471 :
2472 : tree
2473 212543 : 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 212543 : gcc_checking_assert (clusters <= (unsigned short)(~0));
2478 212543 : size_t length = (offsetof (tree_binding_vec, vec)
2479 212543 : + clusters * sizeof (binding_cluster));
2480 212543 : tree vec = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
2481 212543 : TREE_SET_CODE (vec, BINDING_VECTOR);
2482 212543 : BINDING_VECTOR_NAME (vec) = name;
2483 212543 : BINDING_VECTOR_ALLOC_CLUSTERS (vec) = clusters;
2484 212543 : BINDING_VECTOR_NUM_CLUSTERS (vec) = 0;
2485 :
2486 212543 : return vec;
2487 : }
2488 :
2489 : /* Make a raw overload node containing FN. */
2490 :
2491 : tree
2492 376041145 : ovl_make (tree fn, tree next)
2493 : {
2494 376041145 : tree result = make_node (OVERLOAD);
2495 :
2496 376041145 : if (TREE_CODE (fn) == OVERLOAD)
2497 13820953 : OVL_NESTED_P (result) = true;
2498 :
2499 493390088 : TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL
2500 493390088 : ? unknown_type_node : TREE_TYPE (fn));
2501 376041145 : if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
2502 15202477 : OVL_DEDUP_P (result) = true;
2503 376041145 : OVL_FUNCTION (result) = fn;
2504 376041145 : OVL_CHAIN (result) = next;
2505 376041145 : 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 693914386 : ovl_insert (tree fn, tree maybe_ovl, int using_or_hidden)
2516 : {
2517 693914386 : tree result = maybe_ovl;
2518 693914386 : tree insert_after = NULL_TREE;
2519 :
2520 : /* Skip hidden. */
2521 968561243 : for (; maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD
2522 999733293 : && OVL_HIDDEN_P (maybe_ovl);
2523 87830709 : maybe_ovl = OVL_CHAIN (maybe_ovl))
2524 : {
2525 87830709 : gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl));
2526 87830709 : insert_after = maybe_ovl;
2527 : }
2528 :
2529 693914386 : if (maybe_ovl || using_or_hidden || TREE_CODE (fn) == TEMPLATE_DECL)
2530 : {
2531 300091238 : maybe_ovl = ovl_make (fn, maybe_ovl);
2532 :
2533 300091238 : if (using_or_hidden < 0)
2534 79403299 : OVL_HIDDEN_P (maybe_ovl) = true;
2535 300091238 : if (using_or_hidden > 0)
2536 : {
2537 12925632 : OVL_DEDUP_P (maybe_ovl) = OVL_USING_P (maybe_ovl) = true;
2538 12925632 : if (using_or_hidden > 1)
2539 28318 : OVL_PURVIEW_P (maybe_ovl) = true;
2540 28318 : if (using_or_hidden > 2)
2541 27801 : OVL_EXPORT_P (maybe_ovl) = true;
2542 : }
2543 : }
2544 : else
2545 : maybe_ovl = fn;
2546 :
2547 693914386 : if (insert_after)
2548 : {
2549 8881071 : OVL_CHAIN (insert_after) = maybe_ovl;
2550 8881071 : TREE_TYPE (insert_after) = unknown_type_node;
2551 : }
2552 : else
2553 : result = maybe_ovl;
2554 :
2555 693914386 : return result;
2556 : }
2557 :
2558 : /* Skip any hidden names at the beginning of OVL. */
2559 :
2560 : tree
2561 2003471014 : ovl_skip_hidden (tree ovl)
2562 : {
2563 3611132813 : while (ovl && TREE_CODE (ovl) == OVERLOAD && OVL_HIDDEN_P (ovl))
2564 1607661799 : ovl = OVL_CHAIN (ovl);
2565 :
2566 2003471014 : return ovl;
2567 : }
2568 :
2569 : /* NODE is an OVL_HIDDEN_P node that is now revealed. */
2570 :
2571 : tree
2572 3936513 : 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 3936513 : OVL_HIDDEN_P (node) = false;
2578 3936513 : if (tree chain = OVL_CHAIN (node))
2579 167481 : if (TREE_CODE (chain) == OVERLOAD)
2580 : {
2581 158369 : if (OVL_HIDDEN_P (chain))
2582 : {
2583 : /* The node needs moving, and the simplest way is to remove it
2584 : and reinsert. */
2585 72596 : overload = remove_node (overload, node);
2586 72596 : overload = ovl_insert (OVL_FUNCTION (node), overload);
2587 : }
2588 85773 : else if (OVL_DEDUP_P (chain))
2589 9 : OVL_DEDUP_P (node) = true;
2590 : }
2591 3936513 : 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 377000 : ovl_iterator::remove_node (tree overload, tree node)
2601 : {
2602 377000 : tree *slot = &overload;
2603 2226060 : while (*slot != node)
2604 : {
2605 1849060 : tree probe = *slot;
2606 1849060 : gcc_checking_assert (!OVL_LOOKUP_P (probe));
2607 :
2608 1849060 : 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 377000 : if (TREE_CODE (node) != OVERLOAD)
2616 : /* Cloned inherited ctors don't mark themselves as via_using. */
2617 230872 : *slot = NULL_TREE;
2618 : else
2619 146128 : *slot = OVL_CHAIN (node);
2620 :
2621 377000 : return overload;
2622 : }
2623 :
2624 : /* Mark or unmark a lookup set. */
2625 :
2626 : void
2627 114802818 : lookup_mark (tree ovl, bool val)
2628 : {
2629 1391378059 : for (lkp_iterator iter (ovl); iter; ++iter)
2630 : {
2631 1276575241 : gcc_checking_assert (LOOKUP_SEEN_P (*iter) != val);
2632 1276575241 : LOOKUP_SEEN_P (*iter) = val;
2633 : }
2634 114802818 : }
2635 :
2636 : /* Add a set of new FNS into a lookup. */
2637 :
2638 : tree
2639 645992653 : lookup_add (tree fns, tree lookup)
2640 : {
2641 645992653 : if (fns == error_mark_node || lookup == error_mark_node)
2642 : return error_mark_node;
2643 :
2644 645992641 : if (lookup || TREE_CODE (fns) == TEMPLATE_DECL)
2645 : {
2646 70159787 : lookup = ovl_make (fns, lookup);
2647 70159787 : 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 647603257 : lookup_maybe_add (tree fns, tree lookup, bool deduping)
2660 : {
2661 647603257 : if (deduping)
2662 742340419 : for (tree next, probe = fns; probe; probe = next)
2663 : {
2664 664150404 : tree fn = probe;
2665 664150404 : next = NULL_TREE;
2666 :
2667 664150404 : if (TREE_CODE (probe) == OVERLOAD)
2668 : {
2669 633872925 : fn = OVL_FUNCTION (probe);
2670 633872925 : next = OVL_CHAIN (probe);
2671 : }
2672 :
2673 664150404 : if (!LOOKUP_SEEN_P (fn))
2674 485941181 : LOOKUP_SEEN_P (fn) = true;
2675 : else
2676 : {
2677 : /* This function was already seen. Insert all the
2678 : predecessors onto the lookup. */
2679 194266651 : for (; fns != probe; fns = OVL_CHAIN (fns))
2680 : {
2681 : /* Propagate OVL_USING, but OVL_HIDDEN &
2682 : OVL_DEDUP_P don't matter. */
2683 16057428 : if (OVL_USING_P (fns))
2684 : {
2685 377715 : lookup = ovl_make (OVL_FUNCTION (fns), lookup);
2686 377715 : OVL_USING_P (lookup) = true;
2687 : }
2688 : else
2689 15679713 : lookup = lookup_add (OVL_FUNCTION (fns), lookup);
2690 : }
2691 :
2692 : /* And now skip this function. */
2693 : fns = next;
2694 : }
2695 : }
2696 :
2697 647603257 : if (fns)
2698 : /* We ended in a set of new functions. Add them all in one go. */
2699 629454660 : lookup = lookup_add (fns, lookup);
2700 :
2701 647603257 : 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 6925942170 : is_overloaded_fn (tree x)
2713 : {
2714 6925942170 : STRIP_ANY_LOCATION_WRAPPER (x);
2715 :
2716 : /* A baselink is also considered an overloaded function. */
2717 6925942170 : if (TREE_CODE (x) == OFFSET_REF
2718 6925878156 : || TREE_CODE (x) == COMPONENT_REF)
2719 339733421 : x = TREE_OPERAND (x, 1);
2720 6925942170 : x = MAYBE_BASELINK_FUNCTIONS (x);
2721 6925942170 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2722 194175581 : x = TREE_OPERAND (x, 0);
2723 :
2724 7989276178 : if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x))
2725 6960751809 : || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x)))
2726 : return 2;
2727 :
2728 7241605361 : 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 321174091 : 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 321174091 : if (identifier_p (x))
2741 : return x;
2742 321001154 : if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
2743 121995487 : x = TREE_OPERAND (x, 0);
2744 321001154 : if (OVL_P (x))
2745 218275895 : 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 320631609 : call_expr_dependent_name (tree x)
2754 : {
2755 320631609 : if (TREE_TYPE (x) != NULL_TREE)
2756 : /* X isn't dependent, so its callee isn't a dependent name. */
2757 : return NULL_TREE;
2758 316522095 : 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 601402836 : really_overloaded_fn (tree x)
2767 : {
2768 601402836 : 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 4531102792 : maybe_get_fns (tree from)
2776 : {
2777 4531102792 : STRIP_ANY_LOCATION_WRAPPER (from);
2778 :
2779 : /* A baselink is also considered an overloaded function. */
2780 4531102792 : if (TREE_CODE (from) == OFFSET_REF
2781 4531043700 : || TREE_CODE (from) == COMPONENT_REF)
2782 146375482 : from = TREE_OPERAND (from, 1);
2783 4531102792 : if (BASELINK_P (from))
2784 135643495 : from = BASELINK_FUNCTIONS (from);
2785 4531102792 : if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
2786 116891456 : from = TREE_OPERAND (from, 0);
2787 :
2788 4531102792 : if (OVL_P (from))
2789 1112934196 : 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 783637555 : get_fns (tree from)
2798 : {
2799 783637555 : tree res = maybe_get_fns (from);
2800 :
2801 783637555 : gcc_assert (res);
2802 783637555 : return res;
2803 : }
2804 :
2805 : /* Return the first function of the overload set FROM refers to. */
2806 :
2807 : tree
2808 498324755 : get_first_fn (tree from)
2809 : {
2810 498324755 : 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 197434 : maybe_get_first_fn (tree from)
2818 : {
2819 197434 : if (tree res = maybe_get_fns (from))
2820 197434 : return OVL_FIRST (res);
2821 : return from;
2822 : }
2823 :
2824 : /* Return the scope where the overloaded functions OVL were found. */
2825 :
2826 : tree
2827 201654599 : ovl_scope (tree ovl)
2828 : {
2829 201654599 : if (TREE_CODE (ovl) == OFFSET_REF
2830 201654599 : || TREE_CODE (ovl) == COMPONENT_REF)
2831 0 : ovl = TREE_OPERAND (ovl, 1);
2832 201654599 : if (TREE_CODE (ovl) == BASELINK)
2833 44425487 : return BINFO_TYPE (BASELINK_BINFO (ovl));
2834 157229112 : if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
2835 69629357 : ovl = TREE_OPERAND (ovl, 0);
2836 : /* Skip using-declarations. */
2837 157229112 : lkp_iterator iter (ovl);
2838 164458172 : do
2839 164458172 : ovl = *iter;
2840 321687284 : while (iter.using_p () && ++iter);
2841 :
2842 157229112 : return CP_DECL_CONTEXT (ovl);
2843 : }
2844 :
2845 : #define PRINT_RING_SIZE 4
2846 :
2847 : static const char *
2848 169249 : cxx_printable_name_internal (tree decl, int v, bool translate)
2849 : {
2850 169249 : static unsigned int uid_ring[PRINT_RING_SIZE];
2851 169249 : static char *print_ring[PRINT_RING_SIZE];
2852 169249 : static bool trans_ring[PRINT_RING_SIZE];
2853 169249 : static int ring_counter;
2854 169249 : int i;
2855 :
2856 : /* Only cache functions. */
2857 169249 : if (v < 2
2858 88367 : || TREE_CODE (decl) != FUNCTION_DECL
2859 254436 : || DECL_LANG_SPECIFIC (decl) == 0)
2860 85269 : return lang_decl_name (decl, v, translate);
2861 :
2862 : /* See if this print name is lying around. */
2863 389021 : for (i = 0; i < PRINT_RING_SIZE; i++)
2864 317635 : if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
2865 : /* yes, so return it. */
2866 12594 : return print_ring[i];
2867 :
2868 71386 : 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 428316 : for (i = 0; i < PRINT_RING_SIZE; i++)
2873 285544 : if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
2874 : /* yes, so return it. */
2875 0 : return print_ring[i];
2876 :
2877 71386 : if (++ring_counter == PRINT_RING_SIZE)
2878 14697 : ring_counter = 0;
2879 :
2880 71386 : if (current_function_decl != NULL_TREE)
2881 : {
2882 : /* There may be both translated and untranslated versions of the
2883 : name cached. */
2884 195117 : for (i = 0; i < 2; i++)
2885 : {
2886 130078 : if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
2887 76 : ring_counter += 1;
2888 130078 : if (ring_counter == PRINT_RING_SIZE)
2889 10 : ring_counter = 0;
2890 : }
2891 65039 : gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
2892 : }
2893 :
2894 71386 : free (print_ring[ring_counter]);
2895 :
2896 71386 : print_ring[ring_counter] = xstrdup (ret);
2897 71386 : uid_ring[ring_counter] = DECL_UID (decl);
2898 71386 : trans_ring[ring_counter] = translate;
2899 71386 : return print_ring[ring_counter];
2900 : }
2901 :
2902 : const char *
2903 169249 : cxx_printable_name (tree decl, int v)
2904 : {
2905 169249 : 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 213535047 : canonical_eh_spec (tree raises)
2919 : {
2920 213535047 : if (raises == NULL_TREE)
2921 : return raises;
2922 188762576 : else if (DEFERRED_NOEXCEPT_SPEC_P (raises)
2923 154558160 : || UNPARSED_NOEXCEPT_SPEC_P (raises)
2924 146120995 : || uses_template_parms (raises)
2925 146120995 : || uses_template_parms (TREE_PURPOSE (raises)))
2926 : /* Keep a dependent or deferred exception specification. */
2927 44401862 : return raises;
2928 144360714 : else if (nothrow_spec_p (raises))
2929 : /* throw() -> noexcept. */
2930 143862194 : return noexcept_true_spec;
2931 : else
2932 : /* For C++17 type matching, anything else -> nothing. */
2933 : return NULL_TREE;
2934 : }
2935 :
2936 : tree
2937 740733028 : build_cp_fntype_variant (tree type, cp_ref_qualifier rqual,
2938 : tree raises, bool late)
2939 : {
2940 740733028 : cp_cv_quals type_quals = TYPE_QUALS (type);
2941 :
2942 740733028 : if (cp_check_qualified_type (type, type, type_quals, rqual, raises, late))
2943 : return type;
2944 :
2945 314821105 : tree v = TYPE_MAIN_VARIANT (type);
2946 690854382 : for (; v; v = TYPE_NEXT_VARIANT (v))
2947 502643953 : if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late))
2948 : return v;
2949 :
2950 : /* Need to build a new variant. */
2951 188210429 : v = build_variant_type_copy (type);
2952 188210429 : if (!TYPE_DEPENDENT_P (v))
2953 : /* We no longer know that it's not type-dependent. */
2954 187409782 : TYPE_DEPENDENT_P_VALID (v) = false;
2955 188210429 : TYPE_RAISES_EXCEPTIONS (v) = raises;
2956 188210429 : TYPE_HAS_LATE_RETURN_TYPE (v) = late;
2957 188210429 : switch (rqual)
2958 : {
2959 1204601 : case REF_QUAL_RVALUE:
2960 1204601 : FUNCTION_RVALUE_QUALIFIED (v) = 1;
2961 1204601 : FUNCTION_REF_QUALIFIED (v) = 1;
2962 1204601 : break;
2963 1143311 : case REF_QUAL_LVALUE:
2964 1143311 : FUNCTION_RVALUE_QUALIFIED (v) = 0;
2965 1143311 : FUNCTION_REF_QUALIFIED (v) = 1;
2966 1143311 : break;
2967 185862517 : default:
2968 185862517 : FUNCTION_REF_QUALIFIED (v) = 0;
2969 185862517 : break;
2970 : }
2971 :
2972 : /* Canonicalize the exception specification. */
2973 188210429 : tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE;
2974 177702129 : bool complex_eh_spec_p = (cr && cr != noexcept_true_spec
2975 231092887 : && !UNPARSED_NOEXCEPT_SPEC_P (cr));
2976 :
2977 152792274 : 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 5370559 : type = build_cp_fntype_variant (type, rqual, /*raises=*/NULL_TREE, late);
2981 188210429 : 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 48747323 : SET_TYPE_STRUCTURAL_EQUALITY (v);
2986 139463106 : else if (TYPE_CANONICAL (type) != type || cr != raises || late)
2987 : /* Build the underlying canonical type, since it is different
2988 : from TYPE. */
2989 60012220 : TYPE_CANONICAL (v) = build_cp_fntype_variant (TYPE_CANONICAL (type),
2990 : rqual, cr, false);
2991 : else
2992 : /* T is its own canonical type. */
2993 79450886 : 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 3418023 : fixup_deferred_exception_variants (tree type, tree raises)
3005 : {
3006 3418023 : tree original = TYPE_RAISES_EXCEPTIONS (type);
3007 :
3008 6836046 : gcc_checking_assert (UNPARSED_NOEXCEPT_SPEC_P (original));
3009 :
3010 3418023 : for (tree variant = TYPE_MAIN_VARIANT (type);
3011 11084126 : variant; variant = TYPE_NEXT_VARIANT (variant))
3012 7666103 : if (TYPE_RAISES_EXCEPTIONS (variant) == original)
3013 : {
3014 3692895 : gcc_checking_assert (variant != TYPE_MAIN_VARIANT (type));
3015 :
3016 3692895 : SET_TYPE_STRUCTURAL_EQUALITY (variant);
3017 3692895 : TYPE_RAISES_EXCEPTIONS (variant) = raises;
3018 :
3019 3692895 : if (!TYPE_DEPENDENT_P (variant))
3020 : /* We no longer know that it's not type-dependent. */
3021 278620 : TYPE_DEPENDENT_P_VALID (variant) = false;
3022 : }
3023 3418023 : }
3024 :
3025 : /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
3026 : listed in RAISES. */
3027 :
3028 : tree
3029 186618945 : build_exception_variant (tree type, tree raises)
3030 : {
3031 186618945 : cp_ref_qualifier rqual = type_memfn_rqual (type);
3032 186618945 : bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
3033 186618945 : 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 350609 : bind_template_template_parm (tree t, tree newargs)
3042 : {
3043 350609 : tree decl = TYPE_NAME (t);
3044 350609 : tree t2;
3045 :
3046 350609 : t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
3047 350609 : decl = build_decl (input_location,
3048 350609 : TYPE_DECL, DECL_NAME (decl), NULL_TREE);
3049 350609 : SET_DECL_TEMPLATE_PARM_P (decl);
3050 :
3051 : /* These nodes have to be created to reflect new TYPE_DECL and template
3052 : arguments. */
3053 350609 : TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
3054 350609 : TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
3055 350609 : TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
3056 701218 : = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
3057 :
3058 350609 : TREE_TYPE (decl) = t2;
3059 350609 : TYPE_NAME (t2) = decl;
3060 350609 : TYPE_STUB_DECL (t2) = decl;
3061 350609 : TYPE_SIZE (t2) = 0;
3062 :
3063 350609 : if (any_template_arguments_need_structural_equality_p (newargs))
3064 13 : SET_TYPE_STRUCTURAL_EQUALITY (t2);
3065 : else
3066 350596 : TYPE_CANONICAL (t2) = canonical_type_parameter (t2);
3067 :
3068 350609 : 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 628996 : verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data)
3099 : {
3100 628996 : tree t = *tp;
3101 628996 : hash_table<nofree_ptr_hash <tree_node> > *statements
3102 : = static_cast <hash_table<nofree_ptr_hash <tree_node> > *> (data);
3103 628996 : tree_node **slot;
3104 :
3105 628996 : 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 32837 : gcc_assert (!statements->find (t));
3111 :
3112 32837 : slot = statements->find_slot (t, INSERT);
3113 32837 : *slot = t;
3114 :
3115 32837 : 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 1616 : verify_stmt_tree (tree t)
3124 : {
3125 1616 : hash_table<nofree_ptr_hash <tree_node> > statements (37);
3126 1616 : cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
3127 1616 : }
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 347198376 : no_linkage_check (tree t, bool relaxed_p)
3137 : {
3138 347198376 : 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 391533299 : if (LAMBDA_TYPE_P (t)
3147 350609789 : && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node)
3148 : {
3149 1943322 : tree extra = LAMBDA_TYPE_EXTRA_SCOPE (t);
3150 1943322 : 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 347195885 : if (processing_template_decl)
3157 : return NULL_TREE;
3158 :
3159 216244273 : switch (TREE_CODE (t))
3160 : {
3161 113276461 : case RECORD_TYPE:
3162 113276461 : if (TYPE_PTRMEMFUNC_P (t))
3163 120907 : goto ptrmem;
3164 : /* Fall through. */
3165 114412151 : case UNION_TYPE:
3166 114412151 : if (!CLASS_TYPE_P (t))
3167 : return NULL_TREE;
3168 : /* Fall through. */
3169 118956096 : 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 242091554 : if (TYPE_UNNAMED_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
3173 : return t;
3174 :
3175 118217913 : 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 120636776 : if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
3181 77683 : return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
3182 120559093 : else if (TREE_CODE (r) == FUNCTION_DECL)
3183 : {
3184 2916337 : if (relaxed_p
3185 2916337 : && (vague_linkage_p (r)
3186 7369 : || (TREE_PUBLIC (r) && module_maybe_has_cmi_p ())))
3187 2418863 : r = CP_DECL_CONTEXT (r);
3188 : else
3189 497474 : return t;
3190 : }
3191 : else
3192 : break;
3193 : }
3194 :
3195 : return NULL_TREE;
3196 :
3197 27436801 : case ARRAY_TYPE:
3198 27436801 : case POINTER_TYPE:
3199 27436801 : case REFERENCE_TYPE:
3200 27436801 : case VECTOR_TYPE:
3201 27436801 : return no_linkage_check (TREE_TYPE (t), relaxed_p);
3202 :
3203 123807 : case OFFSET_TYPE:
3204 123807 : ptrmem:
3205 123807 : r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
3206 : relaxed_p);
3207 123807 : if (r)
3208 : return r;
3209 123807 : return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
3210 :
3211 23445375 : case METHOD_TYPE:
3212 23445375 : case FUNCTION_TYPE:
3213 23445375 : {
3214 23445375 : tree parm = TYPE_ARG_TYPES (t);
3215 23445375 : 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 11812338 : parm = TREE_CHAIN (parm);
3219 30120835 : for (;
3220 53566210 : parm && parm != void_list_node;
3221 30120835 : parm = TREE_CHAIN (parm))
3222 : {
3223 30604048 : r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
3224 30604048 : if (r)
3225 : return r;
3226 : }
3227 22962162 : 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 6244 : array_type_nelts_total (tree type)
3252 : {
3253 6244 : tree sz = array_type_nelts_top (type);
3254 6244 : type = TREE_TYPE (type);
3255 6512 : while (TREE_CODE (type) == ARRAY_TYPE)
3256 : {
3257 268 : tree n = array_type_nelts_top (type);
3258 268 : sz = fold_build2_loc (input_location,
3259 : MULT_EXPR, sizetype, sz, n);
3260 268 : type = TREE_TYPE (type);
3261 : }
3262 6244 : 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 43964472 : bot_manip (tree* tp, int* walk_subtrees, void* data_)
3275 : {
3276 43964472 : bot_data &data = *(bot_data*)data_;
3277 43964472 : splay_tree target_remap = data.target_remap;
3278 43964472 : tree t = *tp;
3279 :
3280 43964472 : 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 16863265 : *walk_subtrees = 0;
3288 16863265 : *tp = unshare_expr (t);
3289 16863265 : return NULL_TREE;
3290 : }
3291 27101207 : if (TREE_CODE (t) == TARGET_EXPR)
3292 : {
3293 701158 : tree u;
3294 :
3295 701158 : if (TREE_CODE (TARGET_EXPR_INITIAL (t)) == AGGR_INIT_EXPR)
3296 : {
3297 498186 : u = build_cplus_new (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
3298 : tf_warning_or_error);
3299 498186 : if (u == error_mark_node)
3300 : return u;
3301 498186 : if (AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (t)))
3302 3039 : AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (u)) = true;
3303 : }
3304 : else
3305 202972 : u = force_target_expr (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
3306 : tf_warning_or_error);
3307 :
3308 701158 : TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
3309 701158 : TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
3310 701158 : TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
3311 701158 : TARGET_EXPR_ELIDING_P (u) = TARGET_EXPR_ELIDING_P (t);
3312 701158 : TREE_CONSTANT (u) = TREE_CONSTANT (t);
3313 :
3314 : /* Map the old variable to the new one. */
3315 2103474 : splay_tree_insert (target_remap,
3316 701158 : (splay_tree_key) TARGET_EXPR_SLOT (t),
3317 701158 : (splay_tree_value) TARGET_EXPR_SLOT (u));
3318 :
3319 701158 : TARGET_EXPR_INITIAL (u) = break_out_target_exprs (TARGET_EXPR_INITIAL (u),
3320 701158 : data.clear_location);
3321 701158 : if (TARGET_EXPR_INITIAL (u) == error_mark_node)
3322 : return error_mark_node;
3323 :
3324 701158 : if (data.clear_location)
3325 380968 : SET_EXPR_LOCATION (u, input_location);
3326 :
3327 : /* Replace the old expression with the new version. */
3328 701158 : *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 701158 : *walk_subtrees = 0;
3333 701158 : return NULL_TREE;
3334 : }
3335 26400049 : if (TREE_CODE (*tp) == SAVE_EXPR)
3336 : {
3337 101464 : t = *tp;
3338 101464 : splay_tree_node n = splay_tree_lookup (target_remap,
3339 : (splay_tree_key) t);
3340 101464 : if (n)
3341 : {
3342 51100 : *tp = (tree)n->value;
3343 51100 : *walk_subtrees = 0;
3344 : }
3345 : else
3346 : {
3347 50364 : copy_tree_r (tp, walk_subtrees, NULL);
3348 50364 : splay_tree_insert (target_remap,
3349 : (splay_tree_key)t,
3350 50364 : (splay_tree_value)*tp);
3351 : /* Make sure we don't remap an already-remapped SAVE_EXPR. */
3352 50364 : splay_tree_insert (target_remap,
3353 : (splay_tree_key)*tp,
3354 50364 : (splay_tree_value)*tp);
3355 : }
3356 101464 : return NULL_TREE;
3357 : }
3358 26298585 : if (TREE_CODE (*tp) == DECL_EXPR
3359 199 : && VAR_P (DECL_EXPR_DECL (*tp))
3360 199 : && DECL_ARTIFICIAL (DECL_EXPR_DECL (*tp))
3361 26298784 : && !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 26298386 : 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 26298385 : t = copy_tree_r (tp, walk_subtrees, NULL);
3403 26298385 : if (TREE_CODE (*tp) == CALL_EXPR || TREE_CODE (*tp) == AGGR_INIT_EXPR)
3404 4026191 : if (!processing_template_decl)
3405 4026191 : set_flags_from_callee (*tp);
3406 26298385 : if (data.clear_location && EXPR_HAS_LOCATION (*tp))
3407 3573873 : 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 62270434 : bot_replace (tree* t, int */*walk_subtrees*/, void* data_)
3417 : {
3418 62270434 : bot_data &data = *(bot_data*)data_;
3419 62270434 : splay_tree target_remap = data.target_remap;
3420 :
3421 62270434 : if (VAR_P (*t))
3422 : {
3423 2412255 : splay_tree_node n = splay_tree_lookup (target_remap,
3424 : (splay_tree_key) *t);
3425 2412255 : if (n)
3426 2203 : *t = (tree) n->value;
3427 : }
3428 59858179 : else if (TREE_CODE (*t) == PARM_DECL
3429 5274328 : && DECL_NAME (*t) == this_identifier
3430 61702849 : && !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 23650 : *t = current_class_ptr;
3435 : }
3436 59834529 : else if (TREE_CODE (*t) == CONVERT_EXPR
3437 59834529 : && 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 62270434 : 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 11996753 : break_out_target_exprs (tree t, bool clear_location /* = false */)
3460 : {
3461 11996753 : static int target_remap_count;
3462 11996753 : static splay_tree target_remap;
3463 :
3464 : /* We shouldn't be called on templated trees, nor do we want to
3465 : produce them. */
3466 11996753 : gcc_checking_assert (!processing_template_decl);
3467 :
3468 11996753 : if (!target_remap_count++)
3469 11295595 : target_remap = splay_tree_new (splay_tree_compare_pointers,
3470 : /*splay_tree_delete_key_fn=*/NULL,
3471 : /*splay_tree_delete_value_fn=*/NULL);
3472 11996753 : bot_data data = { target_remap, clear_location };
3473 11996753 : if (cp_walk_tree (&t, bot_manip, &data, NULL) == error_mark_node)
3474 0 : t = error_mark_node;
3475 11996753 : if (cp_walk_tree (&t, bot_replace, &data, NULL) == error_mark_node)
3476 0 : t = error_mark_node;
3477 :
3478 11996753 : if (!--target_remap_count)
3479 : {
3480 11295595 : splay_tree_delete (target_remap);
3481 11295595 : target_remap = NULL;
3482 : }
3483 :
3484 11996753 : 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 1366788 : build_ctor_subob_ref (tree index, tree type, tree obj)
3492 : {
3493 1366788 : if (index == NULL_TREE)
3494 : /* Can't refer to a particular member of a vector. */
3495 : obj = NULL_TREE;
3496 1366788 : else if (TREE_CODE (index) == INTEGER_CST)
3497 28639 : obj = cp_build_array_ref (input_location, obj, index, tf_none);
3498 : else
3499 1338149 : obj = build_class_member_access_expr (obj, index, NULL_TREE,
3500 : /*reference*/false, tf_none);
3501 1366788 : if (obj)
3502 : {
3503 1366788 : tree objtype = TREE_TYPE (obj);
3504 1366788 : 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 1366705 : gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, objtype));
3515 : }
3516 :
3517 1366788 : 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 24792776 : replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
3533 : {
3534 24792776 : replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);
3535 24792776 : tree obj = d->obj;
3536 :
3537 24792776 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3538 : {
3539 8744905 : *walk_subtrees = false;
3540 8744905 : return NULL_TREE;
3541 : }
3542 :
3543 16047871 : 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 309460 : case CONSTRUCTOR:
3559 309460 : {
3560 309460 : constructor_elt *ce;
3561 309460 : 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 309460 : if ((CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t)
3566 621 : && *t != d->exp)
3567 309976 : || d->pset->add (*t))
3568 : {
3569 105 : *walk_subtrees = false;
3570 105 : return NULL_TREE;
3571 : }
3572 917877 : for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i)
3573 : {
3574 608522 : tree *valp = &ce->value;
3575 608522 : tree type = TREE_TYPE (*valp);
3576 608522 : tree subob = obj;
3577 :
3578 : /* Elements with RANGE_EXPR index shouldn't have any
3579 : placeholders in them. */
3580 608522 : if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
3581 9 : continue;
3582 :
3583 608513 : if (TREE_CODE (*valp) == CONSTRUCTOR
3584 2110 : && 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 2096 : if (same_type_ignoring_top_level_qualifiers_p
3590 2096 : (TREE_TYPE (*t), TREE_TYPE (obj)))
3591 2046 : subob = build_ctor_subob_ref (ce->index, type, obj);
3592 2096 : if (TREE_CODE (*valp) == TARGET_EXPR)
3593 0 : valp = &TARGET_EXPR_INITIAL (*valp);
3594 : }
3595 608513 : d->obj = subob;
3596 608513 : cp_walk_tree (valp, replace_placeholders_r, data_, NULL);
3597 608513 : d->obj = obj;
3598 : }
3599 309355 : *walk_subtrees = false;
3600 309355 : break;
3601 : }
3602 :
3603 15737853 : default:
3604 15737853 : if (d->pset->add (*t))
3605 601081 : *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 62661331 : replace_placeholders (tree exp, tree obj, bool *seen_p /*= NULL*/)
3617 : {
3618 : /* This is only relevant for C++14. */
3619 62661331 : if (cxx_dialect < cxx14)
3620 868738 : return exp;
3621 :
3622 : /* If the object isn't a (member of a) class, do nothing. */
3623 : tree op0 = obj;
3624 62388749 : while (handled_component_p (op0))
3625 596156 : op0 = TREE_OPERAND (op0, 0);
3626 61792593 : if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0))))
3627 56079389 : return exp;
3628 :
3629 5713204 : tree *tp = &exp;
3630 5713204 : if (TREE_CODE (exp) == TARGET_EXPR)
3631 730062 : tp = &TARGET_EXPR_INITIAL (exp);
3632 5713204 : hash_set<tree> pset;
3633 5713204 : replace_placeholders_t data = { obj, *tp, false, &pset };
3634 5713204 : cp_walk_tree (tp, replace_placeholders_r, &data, NULL);
3635 5713204 : if (seen_p)
3636 195051 : *seen_p = data.seen;
3637 5713204 : return exp;
3638 5713204 : }
3639 :
3640 : /* Callback function for find_placeholders. */
3641 :
3642 : static tree
3643 2986402 : find_placeholders_r (tree *t, int *walk_subtrees, void *)
3644 : {
3645 2986402 : if (TYPE_P (*t) || TREE_CONSTANT (*t))
3646 : {
3647 1394239 : *walk_subtrees = false;
3648 1394239 : return NULL_TREE;
3649 : }
3650 :
3651 1592163 : 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 199254 : find_placeholders (tree exp)
3673 : {
3674 : /* This is only relevant for C++14. */
3675 199254 : if (cxx_dialect < cxx14)
3676 : return false;
3677 :
3678 199254 : 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 321679659 : build_min_nt_loc (location_t loc, enum tree_code code, ...)
3686 : {
3687 321679659 : tree t;
3688 321679659 : int length;
3689 321679659 : int i;
3690 321679659 : va_list p;
3691 :
3692 321679659 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3693 :
3694 321679659 : va_start (p, code);
3695 :
3696 321679659 : t = make_node (code);
3697 321679659 : SET_EXPR_LOCATION (t, loc);
3698 321679659 : length = TREE_CODE_LENGTH (code);
3699 :
3700 1057457371 : for (i = 0; i < length; i++)
3701 735777712 : TREE_OPERAND (t, i) = va_arg (p, tree);
3702 :
3703 321679659 : va_end (p);
3704 321679659 : return t;
3705 : }
3706 :
3707 : /* Similar to `build', but for template definitions. */
3708 :
3709 : tree
3710 247018329 : build_min (enum tree_code code, tree tt, ...)
3711 : {
3712 247018329 : tree t;
3713 247018329 : int length;
3714 247018329 : int i;
3715 247018329 : va_list p;
3716 :
3717 247018329 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3718 :
3719 247018329 : va_start (p, tt);
3720 :
3721 247018329 : t = make_node (code);
3722 247018329 : length = TREE_CODE_LENGTH (code);
3723 247018329 : TREE_TYPE (t) = tt;
3724 :
3725 665866308 : for (i = 0; i < length; i++)
3726 : {
3727 418847979 : tree x = va_arg (p, tree);
3728 418847979 : TREE_OPERAND (t, i) = x;
3729 418847979 : if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
3730 3220096 : TREE_SIDE_EFFECTS (t) = 1;
3731 : }
3732 :
3733 247018329 : va_end (p);
3734 :
3735 247018329 : 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 125035299 : build_min_non_dep (enum tree_code code, tree non_dep, ...)
3744 : {
3745 125035299 : tree t;
3746 125035299 : int length;
3747 125035299 : int i;
3748 125035299 : va_list p;
3749 :
3750 125035299 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3751 :
3752 125035299 : va_start (p, non_dep);
3753 :
3754 125035299 : if (REFERENCE_REF_P (non_dep))
3755 1269341 : non_dep = TREE_OPERAND (non_dep, 0);
3756 :
3757 125035299 : t = make_node (code);
3758 168339427 : SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep));
3759 125035299 : length = TREE_CODE_LENGTH (code);
3760 125035299 : TREE_TYPE (t) = unlowered_expr_type (non_dep);
3761 125035299 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3762 :
3763 438773609 : for (i = 0; i < length; i++)
3764 : {
3765 313738310 : tree x = va_arg (p, tree);
3766 313738310 : TREE_OPERAND (t, i) = x;
3767 313738310 : if (x && !TYPE_P (x))
3768 246798767 : TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
3769 : }
3770 :
3771 125035299 : va_end (p);
3772 125035299 : return convert_from_reference (t);
3773 : }
3774 :
3775 : /* Similar to build_min_nt, but call expressions */
3776 :
3777 : tree
3778 221567300 : build_min_nt_call_vec (tree fn, vec<tree, va_gc> *args)
3779 : {
3780 221567300 : tree ret, t;
3781 221567300 : unsigned int ix;
3782 :
3783 442998622 : ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
3784 221567300 : CALL_EXPR_FN (ret) = fn;
3785 221567300 : CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
3786 467764916 : FOR_EACH_VEC_SAFE_ELT (args, ix, t)
3787 246197616 : CALL_EXPR_ARG (ret, ix) = t;
3788 :
3789 221567300 : 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 13693876 : build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec)
3798 : {
3799 13693876 : tree t = build_min_nt_call_vec (fn, argvec);
3800 13693876 : if (REFERENCE_REF_P (non_dep))
3801 6 : non_dep = TREE_OPERAND (non_dep, 0);
3802 13693876 : TREE_TYPE (t) = TREE_TYPE (non_dep);
3803 13693876 : TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
3804 13693876 : if (argvec)
3805 27585860 : for (tree x : *argvec)
3806 14027962 : if (x && !TYPE_P (x))
3807 14027962 : TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
3808 13693876 : 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 6293615 : build_min_non_dep_op_overload (enum tree_code op,
3819 : tree non_dep,
3820 : tree overload, ...)
3821 : {
3822 6293615 : va_list p;
3823 6293615 : int nargs, expected_nargs;
3824 6293615 : tree fn, call, obj = NULL_TREE;
3825 :
3826 6293615 : releasing_vec args;
3827 6293615 : va_start (p, overload);
3828 :
3829 6293615 : bool negated = false, rewritten = false, reversed = false;
3830 6293615 : 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 521892 : gcc_checking_assert (TREE_CODE_CLASS (op) == tcc_comparison
3836 : || op == SPACESHIP_EXPR);
3837 521892 : int flags = TREE_INT_CST_LOW (TREE_PURPOSE (overload));
3838 521892 : if (TREE_CODE (non_dep) == TRUTH_NOT_EXPR)
3839 : {
3840 476730 : negated = true;
3841 476730 : non_dep = TREE_OPERAND (non_dep, 0);
3842 : }
3843 521892 : if (flags & LOOKUP_REWRITTEN)
3844 521892 : rewritten = true;
3845 521892 : if (flags & LOOKUP_REVERSED)
3846 113 : reversed = true;
3847 521892 : if (rewritten
3848 521892 : && 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 45148 : tree spaceship_non_dep = (TREE_CODE (non_dep) == CALL_EXPR
3856 90179 : ? CALL_EXPR_ARG (non_dep, reversed ? 1 : 0)
3857 45184 : : TREE_OPERAND (non_dep, reversed ? 1 : 0));
3858 :
3859 45148 : tree int_promotion = NULL_TREE;
3860 45148 : if (TREE_CODE (spaceship_non_dep) == NOP_EXPR)
3861 : {
3862 27 : gcc_checking_assert (TREE_CODE (non_dep) != CALL_EXPR);
3863 27 : int_promotion = TREE_TYPE (spaceship_non_dep);
3864 27 : spaceship_non_dep = TREE_OPERAND (spaceship_non_dep, 0);
3865 : }
3866 :
3867 45148 : gcc_checking_assert (TREE_CODE (spaceship_non_dep) == CALL_EXPR);
3868 45148 : tree spaceship_op0 = va_arg (p, tree);
3869 45148 : tree spaceship_op1 = va_arg (p, tree);
3870 45148 : if (reversed)
3871 81 : std::swap (spaceship_op0, spaceship_op1);
3872 :
3873 : /* Push the correct arguments for the operator OP expression, and
3874 : set OVERLOAD appropriately. */
3875 45148 : tree op0 = build_min_non_dep_op_overload (SPACESHIP_EXPR,
3876 : spaceship_non_dep,
3877 45148 : TREE_VALUE (overload),
3878 : spaceship_op0,
3879 45148 : spaceship_op1);
3880 45148 : tree op1 = (TREE_CODE (non_dep) == CALL_EXPR
3881 90260 : ? CALL_EXPR_ARG (non_dep, reversed ? 0 : 1)
3882 117 : : TREE_OPERAND (non_dep, reversed ? 0 : 1));
3883 45148 : gcc_checking_assert (integer_zerop (op1));
3884 :
3885 45148 : if (TREE_CODE (non_dep) != CALL_EXPR)
3886 : {
3887 81 : gcc_checking_assert (COMPARISON_CLASS_P (non_dep)
3888 : || TREE_CODE (non_dep) == SPACESHIP_EXPR);
3889 81 : if (int_promotion)
3890 27 : op0 = build_nop (int_promotion, op0);
3891 81 : if (reversed)
3892 45 : std::swap (op0, op1);
3893 81 : return build_min_non_dep (TREE_CODE (non_dep), non_dep, op0, op1);
3894 : }
3895 :
3896 45067 : vec_safe_push (args, op0);
3897 45067 : vec_safe_push (args, op1);
3898 45067 : overload = CALL_EXPR_FN (non_dep);
3899 : }
3900 : else
3901 476744 : overload = TREE_VALUE (overload);
3902 : }
3903 6293534 : non_dep = extract_call_expr (non_dep);
3904 :
3905 6293534 : nargs = call_expr_nargs (non_dep);
3906 :
3907 6293534 : expected_nargs = cp_tree_code_length (op);
3908 11806059 : if (DECL_OBJECT_MEMBER_FUNCTION_P (overload)
3909 : /* For ARRAY_REF, operator[] is either a non-static member or newly
3910 : static member, never out of class and for the static member case
3911 : if user uses single index the operator[] needs to have a single
3912 : argument as well, but the function is called with 2 - the object
3913 : it is invoked on and the index. */
3914 11803632 : || op == ARRAY_REF)
3915 783445 : expected_nargs -= 1;
3916 6293534 : if ((op == POSTINCREMENT_EXPR
3917 6293534 : || op == POSTDECREMENT_EXPR)
3918 : /* With -fpermissive non_dep could be operator++(). */
3919 10984 : && (!flag_permissive || nargs != expected_nargs))
3920 10981 : expected_nargs += 1;
3921 6293534 : gcc_assert (nargs == expected_nargs);
3922 :
3923 6293534 : if (!DECL_OBJECT_MEMBER_FUNCTION_P (overload))
3924 : {
3925 5510098 : fn = overload;
3926 5510098 : if (vec_safe_length (args) != 0)
3927 : /* The correct arguments were already pushed above. */
3928 45067 : gcc_checking_assert (rewritten);
3929 : else
3930 : {
3931 5465031 : if (op == ARRAY_REF)
3932 9 : obj = va_arg (p, tree);
3933 16315036 : for (int i = 0; i < nargs; i++)
3934 : {
3935 10850005 : tree arg = va_arg (p, tree);
3936 10850005 : vec_safe_push (args, arg);
3937 : }
3938 : }
3939 5510098 : if (reversed)
3940 44 : std::swap ((*args)[0], (*args)[1]);
3941 : }
3942 : else
3943 : {
3944 783436 : gcc_checking_assert (vec_safe_length (args) == 0);
3945 783436 : tree object = va_arg (p, tree);
3946 1338262 : for (int i = 0; i < nargs; i++)
3947 : {
3948 554826 : tree arg = va_arg (p, tree);
3949 554826 : vec_safe_push (args, arg);
3950 : }
3951 783436 : if (reversed)
3952 24 : std::swap (object, (*args)[0]);
3953 783436 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
3954 783436 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
3955 783436 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
3956 : object, method, NULL_TREE);
3957 : }
3958 :
3959 6293534 : va_end (p);
3960 6293534 : call = build_min_non_dep_call_vec (non_dep, fn, args);
3961 :
3962 6293534 : tree call_expr = extract_call_expr (call);
3963 6293534 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
3964 6293534 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
3965 6293534 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
3966 6293534 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
3967 :
3968 6293534 : if (negated)
3969 476730 : call = build_min (TRUTH_NOT_EXPR, boolean_type_node, call);
3970 6293534 : if (obj)
3971 9 : return keep_unused_object_arg (call, obj, overload);
3972 : return call;
3973 6293615 : }
3974 :
3975 : /* Similar to above build_min_non_dep_op_overload, but arguments
3976 : are taken from ARGS vector. */
3977 :
3978 : tree
3979 29 : build_min_non_dep_op_overload (tree non_dep, tree overload, tree object,
3980 : vec<tree, va_gc> *args)
3981 : {
3982 29 : non_dep = extract_call_expr (non_dep);
3983 :
3984 29 : unsigned int nargs = call_expr_nargs (non_dep);
3985 29 : tree fn = overload;
3986 29 : if (DECL_OBJECT_MEMBER_FUNCTION_P (overload))
3987 : {
3988 17 : tree binfo = TYPE_BINFO (TREE_TYPE (object));
3989 17 : tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
3990 17 : fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
3991 : object, method, NULL_TREE);
3992 17 : object = NULL_TREE;
3993 : }
3994 58 : gcc_assert (vec_safe_length (args) == nargs);
3995 :
3996 29 : tree call = build_min_non_dep_call_vec (non_dep, fn, args);
3997 :
3998 29 : tree call_expr = extract_call_expr (call);
3999 29 : KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
4000 29 : CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
4001 29 : CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
4002 29 : CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
4003 :
4004 29 : if (object)
4005 12 : return keep_unused_object_arg (call, object, overload);
4006 : return call;
4007 : }
4008 :
4009 : /* Return a new tree vec copied from VEC, with ELT inserted at index IDX. */
4010 :
4011 : vec<tree, va_gc> *
4012 9004 : vec_copy_and_insert (vec<tree, va_gc> *old_vec, tree elt, unsigned idx)
4013 : {
4014 9004 : unsigned len = vec_safe_length (old_vec);
4015 9004 : gcc_assert (idx <= len);
4016 :
4017 9004 : vec<tree, va_gc> *new_vec = NULL;
4018 9004 : vec_alloc (new_vec, len + 1);
4019 :
4020 9004 : unsigned i;
4021 27041 : for (i = 0; i < len; ++i)
4022 : {
4023 9033 : if (i == idx)
4024 29 : new_vec->quick_push (elt);
4025 9033 : new_vec->quick_push ((*old_vec)[i]);
4026 : }
4027 9004 : if (i == idx)
4028 8975 : new_vec->quick_push (elt);
4029 :
4030 9004 : return new_vec;
4031 : }
4032 :
4033 : tree
4034 141038 : get_type_decl (tree t)
4035 : {
4036 141038 : if (TREE_CODE (t) == TYPE_DECL)
4037 : return t;
4038 141038 : if (TYPE_P (t))
4039 141038 : return TYPE_STUB_DECL (t);
4040 0 : gcc_assert (t == error_mark_node);
4041 : return t;
4042 : }
4043 :
4044 : /* Returns the namespace that contains DECL, whether directly or
4045 : indirectly. */
4046 :
4047 : tree
4048 1281466224 : decl_namespace_context (tree decl)
4049 : {
4050 2658429745 : while (1)
4051 : {
4052 2658429745 : if (TREE_CODE (decl) == NAMESPACE_DECL)
4053 1281466224 : return decl;
4054 1376963521 : else if (TYPE_P (decl))
4055 834786759 : decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
4056 : else
4057 542176762 : decl = CP_DECL_CONTEXT (decl);
4058 : }
4059 : }
4060 :
4061 : /* Returns true if decl is within an anonymous namespace, however deeply
4062 : nested, or false otherwise. */
4063 :
4064 : bool
4065 2009 : decl_anon_ns_mem_p (tree decl)
4066 : {
4067 2009 : return !TREE_PUBLIC (decl_namespace_context (decl));
4068 : }
4069 :
4070 : /* Returns true if the enclosing scope of DECL has internal or no linkage. */
4071 :
4072 : bool
4073 1335975101 : decl_internal_context_p (const_tree decl)
4074 : {
4075 2676510530 : while (TREE_CODE (decl) != NAMESPACE_DECL)
4076 : {
4077 : /* Classes inside anonymous namespaces have TREE_PUBLIC == 0. */
4078 1683612575 : if (TYPE_P (decl))
4079 343077146 : return !TREE_PUBLIC (TYPE_MAIN_DECL (decl));
4080 :
4081 1340535429 : decl = CP_DECL_CONTEXT (decl);
4082 : }
4083 992897955 : return !TREE_PUBLIC (decl);
4084 : }
4085 :
4086 : /* Subroutine of cp_tree_equal: t1 and t2 are two CALL_EXPRs.
4087 : Return whether their CALL_EXPR_FNs are equivalent. */
4088 :
4089 : static bool
4090 51211894 : called_fns_equal (tree t1, tree t2)
4091 : {
4092 : /* Core 1321: dependent names are equivalent even if the overload sets
4093 : are different. But do compare explicit template arguments. */
4094 51211894 : tree name1 = call_expr_dependent_name (t1);
4095 51211894 : tree name2 = call_expr_dependent_name (t2);
4096 51211894 : t1 = CALL_EXPR_FN (t1);
4097 51211894 : t2 = CALL_EXPR_FN (t2);
4098 51211894 : if (name1 || name2)
4099 : {
4100 44107920 : tree targs1 = NULL_TREE, targs2 = NULL_TREE;
4101 :
4102 44107920 : if (name1 != name2)
4103 : return false;
4104 :
4105 : /* FIXME dependent_name currently returns an unqualified name regardless
4106 : of whether the function was named with a qualified- or unqualified-id.
4107 : Until that's fixed, check that we aren't looking at overload sets from
4108 : different scopes. */
4109 43514543 : if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
4110 87060732 : && (DECL_CONTEXT (get_first_fn (t1))
4111 43514540 : != DECL_CONTEXT (get_first_fn (t2))))
4112 : return false;
4113 :
4114 43546192 : if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
4115 27289504 : targs1 = TREE_OPERAND (t1, 1);
4116 43546192 : if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
4117 27289504 : targs2 = TREE_OPERAND (t2, 1);
4118 43546192 : return cp_tree_equal (targs1, targs2);
4119 : }
4120 : else
4121 7103974 : return cp_tree_equal (t1, t2);
4122 : }
4123 :
4124 : /* Return truthvalue of whether T1 is the same tree structure as T2.
4125 : Return 1 if they are the same. Return 0 if they are different. */
4126 :
4127 : bool
4128 2596611479 : cp_tree_equal (tree t1, tree t2)
4129 : {
4130 2604184954 : enum tree_code code1, code2;
4131 :
4132 2604184954 : if (t1 == t2)
4133 : return true;
4134 1198842281 : if (!t1 || !t2)
4135 : return false;
4136 :
4137 1198173108 : code1 = TREE_CODE (t1);
4138 1198173108 : code2 = TREE_CODE (t2);
4139 :
4140 1198173108 : if (comparing_contracts)
4141 : {
4142 : /* When comparing contracts, one declaration may already be
4143 : genericized. Check for invisible references and unravel them
4144 : for comparison purposes. Remember that a parameter is an invisible
4145 : reference so we can compare the parameter types accordingly. */
4146 225 : if (code1 == VIEW_CONVERT_EXPR
4147 225 : && is_invisiref_parm (TREE_OPERAND(t1, 0)))
4148 : {
4149 3 : t1 = TREE_OPERAND(t1, 0);
4150 3 : code1 = TREE_CODE(t1);
4151 : }
4152 225 : if (code2 == VIEW_CONVERT_EXPR
4153 225 : && is_invisiref_parm (TREE_OPERAND(t2, 0)))
4154 : {
4155 0 : t2 = TREE_OPERAND(t2, 0);
4156 0 : code2 = TREE_CODE(t2);
4157 : }
4158 : }
4159 :
4160 1198173108 : if (code1 != code2)
4161 : return false;
4162 :
4163 1071163748 : if (CONSTANT_CLASS_P (t1)
4164 1071163748 : && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4165 : return false;
4166 :
4167 1071085850 : switch (code1)
4168 : {
4169 0 : case VOID_CST:
4170 : /* There's only a single VOID_CST node, so we should never reach
4171 : here. */
4172 0 : gcc_unreachable ();
4173 :
4174 167479498 : case INTEGER_CST:
4175 167479498 : return tree_int_cst_equal (t1, t2);
4176 :
4177 107836 : case REAL_CST:
4178 107836 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
4179 :
4180 97822 : case STRING_CST:
4181 97822 : return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
4182 97822 : && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
4183 97822 : TREE_STRING_LENGTH (t1));
4184 :
4185 0 : case FIXED_CST:
4186 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
4187 : TREE_FIXED_CST (t2));
4188 :
4189 1 : case COMPLEX_CST:
4190 1 : return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
4191 2 : && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
4192 :
4193 7318 : case VECTOR_CST:
4194 7318 : return operand_equal_p (t1, t2, OEP_ONLY_CONST);
4195 :
4196 1463835 : case CONSTRUCTOR:
4197 : /* We need to do this when determining whether or not two
4198 : non-type pointer to member function template arguments
4199 : are the same. */
4200 1463835 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
4201 3160503 : || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
4202 : return false;
4203 : {
4204 : tree field, value;
4205 : unsigned int i;
4206 1596766 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
4207 : {
4208 177246 : constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
4209 177246 : if (!cp_tree_equal (field, elt2->index)
4210 177246 : || !cp_tree_equal (value, elt2->value))
4211 22 : return false;
4212 : }
4213 : }
4214 : return true;
4215 :
4216 5716413 : case TREE_LIST:
4217 5716413 : if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
4218 : return false;
4219 5716413 : if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
4220 : return false;
4221 23060 : return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
4222 :
4223 743 : case SAVE_EXPR:
4224 743 : return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
4225 :
4226 51273302 : case CALL_EXPR:
4227 51273302 : {
4228 51273302 : if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
4229 : return false;
4230 :
4231 51211894 : if (!called_fns_equal (t1, t2))
4232 : return false;
4233 :
4234 23207150 : call_expr_arg_iterator iter1, iter2;
4235 23207150 : init_call_expr_arg_iterator (t1, &iter1);
4236 23207150 : init_call_expr_arg_iterator (t2, &iter2);
4237 23207150 : if (iter1.n != iter2.n)
4238 : return false;
4239 :
4240 24637062 : while (more_call_expr_args_p (&iter1))
4241 : {
4242 16939987 : tree arg1 = next_call_expr_arg (&iter1);
4243 16939987 : tree arg2 = next_call_expr_arg (&iter2);
4244 :
4245 16939987 : gcc_checking_assert (arg1 && arg2);
4246 16939987 : if (!cp_tree_equal (arg1, arg2))
4247 : return false;
4248 : }
4249 :
4250 : return true;
4251 : }
4252 :
4253 397411 : case TARGET_EXPR:
4254 397411 : {
4255 397411 : tree o1 = TARGET_EXPR_SLOT (t1);
4256 397411 : tree o2 = TARGET_EXPR_SLOT (t2);
4257 :
4258 : /* Special case: if either target is an unallocated VAR_DECL,
4259 : it means that it's going to be unified with whatever the
4260 : TARGET_EXPR is really supposed to initialize, so treat it
4261 : as being equivalent to anything. */
4262 397411 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
4263 794822 : && !DECL_RTL_SET_P (o1))
4264 : /*Nop*/;
4265 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
4266 0 : && !DECL_RTL_SET_P (o2))
4267 : /*Nop*/;
4268 0 : else if (!cp_tree_equal (o1, o2))
4269 : return false;
4270 :
4271 397411 : return cp_tree_equal (TARGET_EXPR_INITIAL (t1),
4272 794822 : TARGET_EXPR_INITIAL (t2));
4273 : }
4274 :
4275 27 : case AGGR_INIT_EXPR:
4276 27 : {
4277 27 : int n = aggr_init_expr_nargs (t1);
4278 27 : if (n != aggr_init_expr_nargs (t2))
4279 : return false;
4280 :
4281 54 : if (!cp_tree_equal (AGGR_INIT_EXPR_FN (t1),
4282 27 : AGGR_INIT_EXPR_FN (t2)))
4283 : return false;
4284 :
4285 27 : tree o1 = AGGR_INIT_EXPR_SLOT (t1);
4286 27 : tree o2 = AGGR_INIT_EXPR_SLOT (t2);
4287 :
4288 : /* Similarly to TARGET_EXPRs, if the VAR_DECL is unallocated we're
4289 : going to unify the initialization, so treat it as equivalent
4290 : to anything. */
4291 27 : if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
4292 54 : && !DECL_RTL_SET_P (o1))
4293 : /*Nop*/;
4294 0 : else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
4295 0 : && !DECL_RTL_SET_P (o2))
4296 : /*Nop*/;
4297 0 : else if (!cp_tree_equal (o1, o2))
4298 : return false;
4299 :
4300 56 : for (int i = 0; i < n; ++i)
4301 35 : if (!cp_tree_equal (AGGR_INIT_EXPR_ARG (t1, i),
4302 35 : AGGR_INIT_EXPR_ARG (t2, i)))
4303 : return false;
4304 :
4305 : return true;
4306 : }
4307 :
4308 1694312 : case PARM_DECL:
4309 : /* For comparing uses of parameters in late-specified return types
4310 : with an out-of-class definition of the function, but can also come
4311 : up for expressions that involve 'this' in a member function
4312 : template. */
4313 :
4314 1694312 : if (comparing_specializations
4315 1694312 : && DECL_CONTEXT (t1) != DECL_CONTEXT (t2))
4316 : /* When comparing hash table entries, only an exact match is
4317 : good enough; we don't want to replace 'this' with the
4318 : version from another function. But be more flexible
4319 : with parameters with identical contexts. */
4320 : return false;
4321 :
4322 1474041 : if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) || comparing_contracts)
4323 : {
4324 : /* When comparing contracts, we already know the declarations match,
4325 : and that the arguments have the same type. If one of the declarations
4326 : has been genericised, then the type of arguments in that declaration
4327 : will be adjusted for an invisible reference and the type comparison
4328 : would spuriosly fail. The only thing we care about when comparing
4329 : contractsis that we're using the same parameter. */
4330 763199 : if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
4331 : return false;
4332 763199 : if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
4333 : return false;
4334 763199 : if (DECL_ARTIFICIAL (t1)
4335 763199 : || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
4336 762560 : && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
4337 : return true;
4338 : }
4339 : return false;
4340 :
4341 38239027 : case TEMPLATE_DECL:
4342 38239027 : if (DECL_TEMPLATE_TEMPLATE_PARM_P (t1)
4343 38639218 : && DECL_TEMPLATE_TEMPLATE_PARM_P (t2))
4344 148019 : return cp_tree_equal (TREE_TYPE (t1), TREE_TYPE (t2));
4345 : /* Fall through. */
4346 : case VAR_DECL:
4347 : case CONST_DECL:
4348 : case FIELD_DECL:
4349 : case FUNCTION_DECL:
4350 : case IDENTIFIER_NODE:
4351 : case SSA_NAME:
4352 : case USING_DECL:
4353 : case DEFERRED_PARSE:
4354 : case NAMESPACE_DECL:
4355 : return false;
4356 :
4357 4836819 : case BASELINK:
4358 4836819 : return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
4359 4102804 : && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
4360 4102804 : && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
4361 8939609 : && cp_tree_equal (BASELINK_FUNCTIONS (t1),
4362 4102790 : BASELINK_FUNCTIONS (t2)));
4363 :
4364 13527055 : case TEMPLATE_PARM_INDEX:
4365 13527055 : return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
4366 12888115 : && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
4367 12329883 : && (TEMPLATE_PARM_PARAMETER_PACK (t1)
4368 12329883 : == TEMPLATE_PARM_PARAMETER_PACK (t2))
4369 25795588 : && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
4370 : TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
4371 :
4372 20257887 : case TEMPLATE_ID_EXPR:
4373 20257887 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4374 : return false;
4375 19643791 : if (!comp_template_args (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)))
4376 : return false;
4377 : return true;
4378 :
4379 7003031 : case CONSTRAINT_INFO:
4380 21009093 : return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1),
4381 21009093 : CI_ASSOCIATED_CONSTRAINTS (t2));
4382 :
4383 48503447 : case TREE_VEC:
4384 : /* These are template args. Really we should be getting the
4385 : caller to do this as it knows it to be true. */
4386 48503447 : if (!comp_template_args (t1, t2))
4387 : return false;
4388 : return true;
4389 :
4390 1485178 : case SIZEOF_EXPR:
4391 1485178 : case ALIGNOF_EXPR:
4392 1485178 : {
4393 1485178 : tree o1 = TREE_OPERAND (t1, 0);
4394 1485178 : tree o2 = TREE_OPERAND (t2, 0);
4395 :
4396 1485178 : if (code1 == SIZEOF_EXPR)
4397 : {
4398 1476128 : if (SIZEOF_EXPR_TYPE_P (t1))
4399 0 : o1 = TREE_TYPE (o1);
4400 1476128 : if (SIZEOF_EXPR_TYPE_P (t2))
4401 0 : o2 = TREE_TYPE (o2);
4402 : }
4403 9050 : else if (ALIGNOF_EXPR_STD_P (t1) != ALIGNOF_EXPR_STD_P (t2))
4404 : return false;
4405 :
4406 1485172 : if (TREE_CODE (o1) != TREE_CODE (o2))
4407 : return false;
4408 :
4409 1485164 : if (ARGUMENT_PACK_P (o1))
4410 2 : return template_args_equal (o1, o2);
4411 1485162 : else if (TYPE_P (o1))
4412 1484228 : return same_type_p (o1, o2);
4413 : else
4414 : return cp_tree_equal (o1, o2);
4415 : }
4416 :
4417 5058 : case MODOP_EXPR:
4418 5058 : {
4419 5058 : tree t1_op1, t2_op1;
4420 :
4421 5058 : if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
4422 : return false;
4423 :
4424 4677 : t1_op1 = TREE_OPERAND (t1, 1);
4425 4677 : t2_op1 = TREE_OPERAND (t2, 1);
4426 4677 : if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
4427 : return false;
4428 :
4429 277 : return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
4430 : }
4431 :
4432 775 : case PTRMEM_CST:
4433 : /* Two pointer-to-members are the same if they point to the same
4434 : field or function in the same class. */
4435 775 : if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
4436 : return false;
4437 :
4438 816 : return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
4439 :
4440 20936 : case OVERLOAD:
4441 20936 : {
4442 : /* Two overloads. Must be exactly the same set of decls. */
4443 20936 : lkp_iterator first (t1);
4444 20936 : lkp_iterator second (t2);
4445 :
4446 30149 : for (; first && second; ++first, ++second)
4447 21479 : if (*first != *second)
4448 : return false;
4449 8670 : return !(first || second);
4450 : }
4451 :
4452 8850394 : case TRAIT_EXPR:
4453 8850394 : if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
4454 : return false;
4455 756346 : return cp_tree_equal (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
4456 1450068 : && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
4457 :
4458 1061482 : case NON_LVALUE_EXPR:
4459 1061482 : case VIEW_CONVERT_EXPR:
4460 : /* Used for location wrappers with possibly NULL types. */
4461 1061482 : if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
4462 : {
4463 23 : if (TREE_TYPE (t1) || TREE_TYPE (t2))
4464 : return false;
4465 : break;
4466 : }
4467 : /* FALLTHROUGH */
4468 :
4469 4095385 : case CAST_EXPR:
4470 4095385 : case STATIC_CAST_EXPR:
4471 4095385 : case REINTERPRET_CAST_EXPR:
4472 4095385 : case CONST_CAST_EXPR:
4473 4095385 : case DYNAMIC_CAST_EXPR:
4474 4095385 : case IMPLICIT_CONV_EXPR:
4475 4095385 : case NEW_EXPR:
4476 4095385 : case BIT_CAST_EXPR:
4477 4095385 : CASE_CONVERT:
4478 4095385 : if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
4479 : return false;
4480 : /* Now compare operands as usual. */
4481 : break;
4482 :
4483 0 : case DEFERRED_NOEXCEPT:
4484 0 : return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1),
4485 0 : DEFERRED_NOEXCEPT_PATTERN (t2))
4486 0 : && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1),
4487 0 : DEFERRED_NOEXCEPT_ARGS (t2)));
4488 :
4489 : case LAMBDA_EXPR:
4490 : /* Two lambda-expressions are never considered equivalent. */
4491 : return false;
4492 :
4493 592122237 : case TYPE_ARGUMENT_PACK:
4494 592122237 : case NONTYPE_ARGUMENT_PACK:
4495 592122237 : {
4496 592122237 : tree p1 = ARGUMENT_PACK_ARGS (t1);
4497 592122237 : tree p2 = ARGUMENT_PACK_ARGS (t2);
4498 592122237 : int len = TREE_VEC_LENGTH (p1);
4499 592122237 : if (TREE_VEC_LENGTH (p2) != len)
4500 : return false;
4501 :
4502 712953511 : for (int ix = 0; ix != len; ix++)
4503 634223694 : if (!template_args_equal (TREE_VEC_ELT (p1, ix),
4504 634223694 : TREE_VEC_ELT (p2, ix)))
4505 : return false;
4506 : return true;
4507 : }
4508 :
4509 727604 : case EXPR_PACK_EXPANSION:
4510 727604 : if (!cp_tree_equal (PACK_EXPANSION_PATTERN (t1),
4511 727604 : PACK_EXPANSION_PATTERN (t2)))
4512 : return false;
4513 20837 : if (!comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
4514 20837 : PACK_EXPANSION_EXTRA_ARGS (t2)))
4515 : return false;
4516 : return true;
4517 :
4518 2169 : case PACK_INDEX_EXPR:
4519 2169 : if (!cp_tree_equal (PACK_INDEX_PACK (t1),
4520 2169 : PACK_INDEX_PACK (t2)))
4521 : return false;
4522 94 : if (!cp_tree_equal (PACK_INDEX_INDEX (t1),
4523 94 : PACK_INDEX_INDEX (t2)))
4524 : return false;
4525 : return true;
4526 :
4527 2144 : case REFLECT_EXPR:
4528 2144 : return compare_reflections (t1, t2);
4529 :
4530 : default:
4531 : break;
4532 : }
4533 :
4534 71546215 : switch (TREE_CODE_CLASS (code1))
4535 : {
4536 65397612 : case tcc_unary:
4537 65397612 : case tcc_binary:
4538 65397612 : case tcc_comparison:
4539 65397612 : case tcc_expression:
4540 65397612 : case tcc_vl_exp:
4541 65397612 : case tcc_reference:
4542 65397612 : case tcc_statement:
4543 65397612 : {
4544 65397612 : int n = cp_tree_operand_length (t1);
4545 65397612 : if (TREE_CODE_CLASS (code1) == tcc_vl_exp
4546 65397612 : && n != TREE_OPERAND_LENGTH (t2))
4547 : return false;
4548 :
4549 110633247 : for (int i = 0; i < n; ++i)
4550 86958333 : if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
4551 : return false;
4552 :
4553 : return true;
4554 : }
4555 :
4556 6148603 : case tcc_type:
4557 6148603 : return same_type_p (t1, t2);
4558 :
4559 0 : default:
4560 0 : gcc_unreachable ();
4561 : }
4562 :
4563 : /* We can get here with --disable-checking. */
4564 : return false;
4565 : }
4566 :
4567 : /* The type of ARG when used as an lvalue. */
4568 :
4569 : tree
4570 834317198 : lvalue_type (tree arg)
4571 : {
4572 834317198 : tree type = TREE_TYPE (arg);
4573 834317198 : return type;
4574 : }
4575 :
4576 : /* The type of ARG for printing error messages; denote lvalues with
4577 : reference types. */
4578 :
4579 : tree
4580 3757 : error_type (tree arg)
4581 : {
4582 3757 : tree type = TREE_TYPE (arg);
4583 :
4584 3757 : if (TREE_CODE (type) == ARRAY_TYPE)
4585 : ;
4586 3646 : else if (TREE_CODE (type) == ERROR_MARK)
4587 : ;
4588 3646 : else if (lvalue_p (arg))
4589 1255 : type = build_reference_type (lvalue_type (arg));
4590 2391 : else if (MAYBE_CLASS_TYPE_P (type))
4591 754 : type = lvalue_type (arg);
4592 :
4593 3757 : return type;
4594 : }
4595 :
4596 : /* Does FUNCTION use a variable-length argument list? */
4597 :
4598 : int
4599 470563 : varargs_function_p (const_tree function)
4600 : {
4601 470563 : return stdarg_p (TREE_TYPE (function));
4602 : }
4603 :
4604 : /* Returns 1 if decl is a member of a class. */
4605 :
4606 : int
4607 11136 : member_p (const_tree decl)
4608 : {
4609 11136 : const_tree const ctx = DECL_CONTEXT (decl);
4610 11136 : return (ctx && TYPE_P (ctx));
4611 : }
4612 :
4613 : /* Create a placeholder for member access where we don't actually have an
4614 : object that the access is against. For a general declval<T> equivalent,
4615 : use build_stub_object instead. */
4616 :
4617 : tree
4618 80940903 : build_dummy_object (tree type)
4619 : {
4620 80940903 : tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node);
4621 80940903 : return cp_build_fold_indirect_ref (decl);
4622 : }
4623 :
4624 : /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
4625 : or a dummy object otherwise. If BINFOP is non-0, it is filled with the
4626 : binfo path from current_class_type to TYPE, or 0. */
4627 :
4628 : tree
4629 107952460 : maybe_dummy_object (tree type, tree* binfop)
4630 : {
4631 107952460 : tree decl, context;
4632 107952460 : tree binfo;
4633 107952460 : tree current = current_nonlambda_class_type ();
4634 :
4635 107952460 : if (current
4636 107952460 : && (binfo = lookup_base (current, type, ba_any, NULL,
4637 : tf_warning_or_error)))
4638 : context = current;
4639 : else
4640 : {
4641 : /* Reference from a nested class member function. */
4642 8060403 : context = type;
4643 8060403 : binfo = TYPE_BINFO (type);
4644 : }
4645 :
4646 107952460 : if (binfop)
4647 106375 : *binfop = binfo;
4648 :
4649 : /* current_class_ref might not correspond to current_class_type if
4650 : we're in tsubst_default_argument or a lambda-declarator; in either
4651 : case, we want to use current_class_ref if it matches CONTEXT. */
4652 107952460 : tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE;
4653 99148596 : if (ctype
4654 99148596 : && same_type_ignoring_top_level_qualifiers_p (ctype, context))
4655 96035225 : decl = current_class_ref;
4656 : else
4657 : {
4658 : /* Return a dummy object whose cv-quals are consistent with (the
4659 : non-lambda) 'this' if available. */
4660 11917235 : if (ctype)
4661 : {
4662 3113371 : int quals = TYPE_UNQUALIFIED;
4663 3113371 : if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype))
4664 : {
4665 390843 : if (tree cap = lambda_expr_this_capture (lambda, false))
4666 379776 : quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap)));
4667 : }
4668 : else
4669 2722528 : quals = cp_type_quals (ctype);
4670 3113371 : context = cp_build_qualified_type (context, quals);
4671 : }
4672 11917235 : decl = build_dummy_object (context);
4673 : }
4674 :
4675 107952460 : return decl;
4676 : }
4677 :
4678 : /* Returns 1 if OB is a placeholder object, or a pointer to one. */
4679 :
4680 : bool
4681 503694267 : is_dummy_object (const_tree ob)
4682 : {
4683 503694267 : if (INDIRECT_REF_P (ob))
4684 389980245 : ob = TREE_OPERAND (ob, 0);
4685 503694267 : return (TREE_CODE (ob) == CONVERT_EXPR
4686 503694267 : && TREE_OPERAND (ob, 0) == void_node);
4687 : }
4688 :
4689 : /* Returns true if TYPE is char, unsigned char, or std::byte. */
4690 :
4691 : bool
4692 32501192 : is_byte_access_type (tree type)
4693 : {
4694 32501192 : type = TYPE_MAIN_VARIANT (type);
4695 32501192 : if (type == char_type_node
4696 7013300 : || type == unsigned_char_type_node)
4697 : return true;
4698 :
4699 6876468 : return (TREE_CODE (type) == ENUMERAL_TYPE
4700 15384 : && TYPE_CONTEXT (type) == std_node
4701 6894646 : && !strcmp ("byte", TYPE_NAME_STRING (type)));
4702 : }
4703 :
4704 : /* Returns true if TYPE is unsigned char or std::byte. */
4705 :
4706 : bool
4707 1946 : is_byte_access_type_not_plain_char (tree type)
4708 : {
4709 1946 : type = TYPE_MAIN_VARIANT (type);
4710 1946 : if (type == char_type_node)
4711 : return false;
4712 :
4713 1698 : return is_byte_access_type (type);
4714 : }
4715 :
4716 : /* Returns 1 iff type T is something we want to treat as a scalar type for
4717 : the purpose of deciding whether it is trivial/POD/standard-layout. */
4718 :
4719 : bool
4720 72307981 : scalarish_type_p (const_tree t)
4721 : {
4722 72307981 : if (t == error_mark_node)
4723 : return 1;
4724 :
4725 72307717 : return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
4726 : }
4727 :
4728 : /* Returns true iff T requires non-trivial default initialization. */
4729 :
4730 : bool
4731 0 : type_has_nontrivial_default_init (const_tree t)
4732 : {
4733 0 : t = strip_array_types (const_cast<tree> (t));
4734 :
4735 0 : if (CLASS_TYPE_P (t))
4736 0 : return TYPE_HAS_COMPLEX_DFLT (t);
4737 : else
4738 : return 0;
4739 : }
4740 :
4741 : /* Track classes with only deleted copy/move constructors so that we can warn
4742 : if they are used in call/return by value. */
4743 :
4744 : static GTY(()) hash_set<tree>* deleted_copy_types;
4745 : static void
4746 9 : remember_deleted_copy (const_tree t)
4747 : {
4748 9 : if (!deleted_copy_types)
4749 9 : deleted_copy_types = hash_set<tree>::create_ggc(37);
4750 9 : deleted_copy_types->add (const_cast<tree> (t));
4751 9 : }
4752 : void
4753 355713672 : maybe_warn_parm_abi (tree t, location_t loc)
4754 : {
4755 355713672 : if (!deleted_copy_types
4756 355713672 : || !deleted_copy_types->contains (t))
4757 355713642 : return;
4758 :
4759 30 : if ((flag_abi_version == 12 || warn_abi_version == 12)
4760 36 : && classtype_has_non_deleted_move_ctor (t))
4761 : {
4762 6 : bool w;
4763 6 : auto_diagnostic_group d;
4764 6 : if (flag_abi_version > 12)
4765 0 : w = warning_at (loc, OPT_Wabi, "%<-fabi-version=13%> (GCC 8.2) fixes "
4766 : "the calling convention for %qT, which was "
4767 : "accidentally changed in 8.1", t);
4768 : else
4769 6 : w = warning_at (loc, OPT_Wabi, "%<-fabi-version=12%> (GCC 8.1) "
4770 : "accidentally changes the calling convention for %qT",
4771 : t);
4772 6 : if (w)
4773 6 : inform (location_of (t), " declared here");
4774 6 : return;
4775 6 : }
4776 :
4777 30 : auto_diagnostic_group d;
4778 30 : if (warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in "
4779 : "%<-fabi-version=13%> (GCC 8.2)", t))
4780 30 : inform (location_of (t), " because all of its copy and move "
4781 : "constructors are deleted");
4782 30 : }
4783 :
4784 : /* Returns true iff copying an object of type T (including via move
4785 : constructor) is non-trivial. That is, T has no non-trivial copy
4786 : constructors and no non-trivial move constructors, and not all copy/move
4787 : constructors are deleted. This function implements the ABI notion of
4788 : non-trivial copy, which has diverged from the one in the standard. */
4789 :
4790 : bool
4791 56488095 : type_has_nontrivial_copy_init (const_tree type)
4792 : {
4793 56488095 : tree t = strip_array_types (const_cast<tree> (type));
4794 :
4795 56488095 : if (CLASS_TYPE_P (t))
4796 : {
4797 55871251 : gcc_assert (COMPLETE_TYPE_P (t));
4798 :
4799 55871251 : if (TYPE_HAS_COMPLEX_COPY_CTOR (t)
4800 55871251 : || TYPE_HAS_COMPLEX_MOVE_CTOR (t))
4801 : /* Nontrivial. */
4802 : return true;
4803 :
4804 51909484 : if (cxx_dialect < cxx11)
4805 : /* No deleted functions before C++11. */
4806 : return false;
4807 :
4808 : /* Before ABI v12 we did a bitwise copy of types with only deleted
4809 : copy/move constructors. */
4810 51818042 : if (!abi_version_at_least (12)
4811 8132 : && !(warn_abi && abi_version_crosses (12)))
4812 : return false;
4813 :
4814 51810140 : bool saw_copy = false;
4815 51810140 : bool saw_non_deleted = false;
4816 51810140 : bool saw_non_deleted_move = false;
4817 :
4818 51810140 : if (CLASSTYPE_LAZY_MOVE_CTOR (t))
4819 : saw_copy = saw_non_deleted = true;
4820 4519536 : else if (CLASSTYPE_LAZY_COPY_CTOR (t))
4821 : {
4822 557882 : saw_copy = true;
4823 557882 : if (classtype_has_move_assign_or_move_ctor_p (t, true))
4824 : /* [class.copy]/8 If the class definition declares a move
4825 : constructor or move assignment operator, the implicitly declared
4826 : copy constructor is defined as deleted.... */;
4827 : else
4828 : /* Any other reason the implicitly-declared function would be
4829 : deleted would also cause TYPE_HAS_COMPLEX_COPY_CTOR to be
4830 : set. */
4831 : saw_non_deleted = true;
4832 : }
4833 :
4834 : if (!saw_non_deleted)
4835 17280730 : for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
4836 : {
4837 10305115 : tree fn = *iter;
4838 10305115 : if (copy_fn_p (fn))
4839 : {
4840 3961700 : saw_copy = true;
4841 3961700 : if (!DECL_DELETED_FN (fn))
4842 : {
4843 : /* Not deleted, therefore trivial. */
4844 : saw_non_deleted = true;
4845 : break;
4846 : }
4847 : }
4848 6343415 : else if (move_fn_p (fn))
4849 2788029 : if (!DECL_DELETED_FN (fn))
4850 2766901 : saw_non_deleted_move = true;
4851 : }
4852 :
4853 51810140 : gcc_assert (saw_copy);
4854 :
4855 : /* ABI v12 buggily ignored move constructors. */
4856 51810140 : bool v11nontriv = false;
4857 51810140 : bool v12nontriv = !saw_non_deleted;
4858 51810140 : bool v13nontriv = !saw_non_deleted && !saw_non_deleted_move;
4859 51810140 : bool nontriv = (abi_version_at_least (13) ? v13nontriv
4860 124 : : flag_abi_version == 12 ? v12nontriv
4861 124 : : v11nontriv);
4862 51810548 : bool warn_nontriv = (warn_abi_version >= 13 ? v13nontriv
4863 408 : : warn_abi_version == 12 ? v12nontriv
4864 : : v11nontriv);
4865 51810140 : if (nontriv != warn_nontriv)
4866 9 : remember_deleted_copy (t);
4867 :
4868 51810140 : return nontriv;
4869 : }
4870 : else
4871 : return 0;
4872 : }
4873 :
4874 : /* Returns 1 iff type T is a trivially copyable type, as defined in
4875 : [basic.types] and [class]. */
4876 :
4877 : bool
4878 506144 : trivially_copyable_p (const_tree t)
4879 : {
4880 506144 : t = strip_array_types (const_cast<tree> (t));
4881 :
4882 506144 : if (CLASS_TYPE_P (t))
4883 64937 : return ((!TYPE_HAS_COPY_CTOR (t)
4884 64937 : || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
4885 64016 : && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
4886 63982 : && (!TYPE_HAS_COPY_ASSIGN (t)
4887 63982 : || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
4888 63002 : && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
4889 127770 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
4890 : else
4891 : /* CWG 2094 makes volatile-qualified scalars trivially copyable again. */
4892 441207 : return scalarish_type_p (t);
4893 : }
4894 :
4895 : /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
4896 : [class]. */
4897 :
4898 : bool
4899 75044 : trivial_type_p (const_tree t)
4900 : {
4901 75044 : t = strip_array_types (const_cast<tree> (t));
4902 :
4903 75044 : if (CLASS_TYPE_P (t))
4904 : /* A trivial class is a class that is trivially copyable and has one or
4905 : more eligible default constructors, all of which are trivial. */
4906 19345 : return (type_has_non_deleted_trivial_default_ctor (const_cast<tree> (t))
4907 19345 : && trivially_copyable_p (t));
4908 : else
4909 55699 : return scalarish_type_p (t);
4910 : }
4911 :
4912 : /* Returns 1 iff type T is an implicit-lifetime type, as defined in
4913 : [basic.types.general] and [class.prop]. */
4914 :
4915 : bool
4916 948 : implicit_lifetime_type_p (tree t)
4917 : {
4918 948 : if (SCALAR_TYPE_P (t)
4919 667 : || (TREE_CODE (t) == ARRAY_TYPE
4920 84 : && !(TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t))))
4921 : /* GNU extension. */
4922 588 : || TREE_CODE (t) == VECTOR_TYPE)
4923 365 : return true;
4924 583 : if (!CLASS_TYPE_P (t))
4925 : return false;
4926 513 : t = TYPE_MAIN_VARIANT (t);
4927 1026 : if (CP_AGGREGATE_TYPE_P (t)
4928 678 : && (!CLASSTYPE_DESTRUCTOR (t)
4929 87 : || !user_provided_p (CLASSTYPE_DESTRUCTOR (t))))
4930 140 : return true;
4931 373 : if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
4932 : return false;
4933 334 : if (TYPE_HAS_COMPLEX_DFLT (t)
4934 124 : && TYPE_HAS_COMPLEX_COPY_CTOR (t)
4935 397 : && TYPE_HAS_COMPLEX_MOVE_CTOR (t))
4936 : return false;
4937 308 : if (CLASSTYPE_LAZY_DESTRUCTOR (t))
4938 120 : lazily_declare_fn (sfk_destructor, t);
4939 308 : tree fn = CLASSTYPE_DESTRUCTOR (t);
4940 308 : if (!fn || DECL_DELETED_FN (fn))
4941 : return false;
4942 378 : for (ovl_iterator iter (get_class_binding (t, complete_ctor_identifier));
4943 378 : iter; ++iter)
4944 : {
4945 363 : fn = *iter;
4946 663 : if ((default_ctor_p (fn) || copy_fn_p (fn) || move_fn_p (fn))
4947 363 : && trivial_fn_p (fn)
4948 656 : && !DECL_DELETED_FN (fn))
4949 293 : return true;
4950 : }
4951 15 : return false;
4952 : }
4953 :
4954 : /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
4955 :
4956 : bool
4957 11246 : pod_type_p (const_tree t)
4958 : {
4959 : /* This CONST_CAST is okay because strip_array_types returns its
4960 : argument unmodified and we assign it to a const_tree. */
4961 11246 : t = strip_array_types (const_cast<tree>(t));
4962 :
4963 11246 : if (!CLASS_TYPE_P (t))
4964 694 : return scalarish_type_p (t);
4965 10552 : else if (cxx_dialect > cxx98)
4966 : /* [class]/10: A POD struct is a class that is both a trivial class and a
4967 : standard-layout class, and has no non-static data members of type
4968 : non-POD struct, non-POD union (or array of such types).
4969 :
4970 : We don't need to check individual members because if a member is
4971 : non-std-layout or non-trivial, the class will be too. */
4972 10331 : return (std_layout_type_p (t) && trivial_type_p (t));
4973 : else
4974 : /* The C++98 definition of POD is different. */
4975 221 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
4976 : }
4977 :
4978 : /* Returns true iff T is POD for the purpose of layout, as defined in the
4979 : C++ ABI. */
4980 :
4981 : bool
4982 17226034 : layout_pod_type_p (const_tree t)
4983 : {
4984 17226034 : t = strip_array_types (const_cast<tree> (t));
4985 :
4986 17226034 : if (CLASS_TYPE_P (t))
4987 3501465 : return !CLASSTYPE_NON_LAYOUT_POD_P (t);
4988 : else
4989 13724569 : return scalarish_type_p (t);
4990 : }
4991 :
4992 : /* Returns true iff T is a standard-layout type, as defined in
4993 : [basic.types]. */
4994 :
4995 : bool
4996 17297442 : std_layout_type_p (const_tree t)
4997 : {
4998 17297442 : t = strip_array_types (const_cast<tree> (t));
4999 :
5000 17297442 : if (CLASS_TYPE_P (t))
5001 3514370 : return !CLASSTYPE_NON_STD_LAYOUT (t);
5002 : else
5003 13783072 : return scalarish_type_p (t);
5004 : }
5005 :
5006 : static bool record_has_unique_obj_representations (const_tree, const_tree, bool);
5007 :
5008 : /* Returns true iff T satisfies std::has_unique_object_representations<T>,
5009 : as defined in [meta.unary.prop]. If EXPLAIN is true, explain why not. */
5010 :
5011 : bool
5012 67135 : type_has_unique_obj_representations (const_tree t, bool explain/*=false*/)
5013 : {
5014 67135 : bool ret;
5015 :
5016 67135 : t = strip_array_types (const_cast<tree> (t));
5017 :
5018 67135 : if (t == error_mark_node)
5019 : return false;
5020 :
5021 67132 : location_t loc = input_location;
5022 67132 : if (tree m = TYPE_MAIN_DECL (t))
5023 9231 : loc = DECL_SOURCE_LOCATION (m);
5024 :
5025 67132 : if (!trivially_copyable_p (t))
5026 : {
5027 24 : if (explain)
5028 6 : inform (loc, "%qT is not trivially copyable", t);
5029 24 : return false;
5030 : }
5031 :
5032 230 : if (CLASS_TYPE_P (t)
5033 227 : && CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t)
5034 67228 : && !explain)
5035 96 : return CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t);
5036 :
5037 67012 : switch (TREE_CODE (t))
5038 : {
5039 : case INTEGER_TYPE:
5040 : case POINTER_TYPE:
5041 : case REFERENCE_TYPE:
5042 : /* If some backend has any paddings in these types, we should add
5043 : a target hook for this and handle it there. */
5044 : return true;
5045 :
5046 : case BOOLEAN_TYPE:
5047 : /* For bool values other than 0 and 1 should only appear with
5048 : undefined behavior. */
5049 : return true;
5050 :
5051 8986 : case ENUMERAL_TYPE:
5052 8986 : return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t),
5053 8986 : explain);
5054 :
5055 30654 : case REAL_TYPE:
5056 : /* XFmode certainly contains padding on x86, which the CPU doesn't store
5057 : when storing long double values, so for that we have to return false.
5058 : Other kinds of floating point values are questionable due to +.0/-.0
5059 : and NaNs, let's play safe for now. */
5060 30654 : if (explain)
5061 0 : inform (loc, "%qT is a floating-point type", t);
5062 : return false;
5063 :
5064 0 : case FIXED_POINT_TYPE:
5065 0 : if (explain)
5066 0 : inform (loc, "%qT is a fixed-point type", t);
5067 : return false;
5068 :
5069 : case OFFSET_TYPE:
5070 : return true;
5071 :
5072 18 : case COMPLEX_TYPE:
5073 18 : case VECTOR_TYPE:
5074 18 : return type_has_unique_obj_representations (TREE_TYPE (t), explain);
5075 :
5076 113 : case RECORD_TYPE:
5077 113 : ret = record_has_unique_obj_representations (t, TYPE_SIZE (t), explain);
5078 113 : if (CLASS_TYPE_P (t))
5079 : {
5080 110 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
5081 110 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
5082 : }
5083 : return ret;
5084 :
5085 21 : case UNION_TYPE:
5086 21 : ret = true;
5087 21 : bool any_fields;
5088 21 : any_fields = false;
5089 42 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5090 33 : if (TREE_CODE (field) == FIELD_DECL)
5091 : {
5092 24 : any_fields = true;
5093 24 : if (simple_cst_equal (DECL_SIZE (field), TYPE_SIZE (t)) != 1)
5094 : {
5095 12 : if (explain)
5096 3 : inform (DECL_SOURCE_LOCATION (field),
5097 : "%qD does not fill all bits of %q#T", field, t);
5098 : ret = false;
5099 : break;
5100 : }
5101 12 : if (!type_has_unique_obj_representations (TREE_TYPE (field)))
5102 : {
5103 0 : if (explain)
5104 0 : inform (DECL_SOURCE_LOCATION (field),
5105 : "%qD has type %qT that does not have "
5106 : "unique object representations",
5107 0 : field, TREE_TYPE (field));
5108 : ret = false;
5109 : break;
5110 : }
5111 : }
5112 9 : if (!any_fields && !integer_zerop (TYPE_SIZE (t)))
5113 : {
5114 6 : if (explain)
5115 3 : inform (loc, "%q#T has no data fields", t);
5116 : ret = false;
5117 : }
5118 21 : if (CLASS_TYPE_P (t))
5119 : {
5120 21 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
5121 21 : CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
5122 : }
5123 : return ret;
5124 :
5125 3 : case NULLPTR_TYPE:
5126 3 : if (explain)
5127 0 : inform (loc, "%<std::nullptr_t%> has padding bits and no value bits");
5128 : return false;
5129 :
5130 0 : default:
5131 0 : gcc_unreachable ();
5132 : }
5133 : }
5134 :
5135 : /* Helper function for type_has_unique_obj_representations. */
5136 :
5137 : static bool
5138 124 : record_has_unique_obj_representations (const_tree t, const_tree sz,
5139 : bool explain)
5140 : {
5141 638 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5142 544 : if (TREE_CODE (field) != FIELD_DECL)
5143 : ;
5144 : /* For bases, can't use type_has_unique_obj_representations here, as in
5145 : struct S { int i : 24; S (); };
5146 : struct T : public S { int j : 8; T (); };
5147 : S doesn't have unique obj representations, but T does. */
5148 178 : else if (DECL_FIELD_IS_BASE (field))
5149 : {
5150 11 : if (!record_has_unique_obj_representations (TREE_TYPE (field),
5151 11 : DECL_SIZE (field),
5152 : /*explain=*/false))
5153 : {
5154 6 : if (explain)
5155 3 : inform (DECL_SOURCE_LOCATION (field),
5156 : "base %qT does not have unique object representations",
5157 3 : TREE_TYPE (field));
5158 6 : return false;
5159 : }
5160 : }
5161 167 : else if (DECL_C_BIT_FIELD (field) && !DECL_UNNAMED_BIT_FIELD (field))
5162 : {
5163 59 : tree btype = DECL_BIT_FIELD_TYPE (field);
5164 59 : if (!type_has_unique_obj_representations (btype))
5165 : {
5166 0 : if (explain)
5167 0 : inform (DECL_SOURCE_LOCATION (field),
5168 : "%qD with type %qT does not have "
5169 : "unique object representations",
5170 : field, btype);
5171 0 : return false;
5172 : }
5173 : }
5174 108 : else if (!type_has_unique_obj_representations (TREE_TYPE (field)))
5175 : {
5176 24 : if (explain)
5177 6 : inform (DECL_SOURCE_LOCATION (field),
5178 : "%qD with type %qT does not have "
5179 : "unique object representations",
5180 6 : field, TREE_TYPE (field));
5181 24 : return false;
5182 : }
5183 :
5184 94 : offset_int cur = 0;
5185 94 : tree last_field = NULL_TREE;
5186 94 : tree last_named_field = NULL_TREE;
5187 537 : for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5188 475 : if (TREE_CODE (field) == FIELD_DECL)
5189 : {
5190 142 : if (DECL_UNNAMED_BIT_FIELD (field))
5191 : {
5192 16 : last_field = field;
5193 16 : continue;
5194 : }
5195 126 : offset_int fld = wi::to_offset (DECL_FIELD_OFFSET (field));
5196 126 : offset_int bitpos = wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
5197 126 : fld = fld * BITS_PER_UNIT + bitpos;
5198 126 : if (cur != fld)
5199 : {
5200 32 : if (explain)
5201 : {
5202 6 : if (last_named_field)
5203 3 : inform (DECL_SOURCE_LOCATION (last_named_field),
5204 : "padding occurs between %qD and %qD",
5205 : last_named_field, field);
5206 3 : else if (last_field)
5207 3 : inform (DECL_SOURCE_LOCATION (last_field),
5208 : "unnamed bit-field inserts padding before %qD",
5209 : field);
5210 : else
5211 0 : inform (DECL_SOURCE_LOCATION (field),
5212 : "padding occurs before %qD", field);
5213 : }
5214 32 : return false;
5215 : }
5216 94 : if (DECL_SIZE (field))
5217 : {
5218 91 : offset_int size = wi::to_offset (DECL_SIZE (field));
5219 91 : cur += size;
5220 : }
5221 94 : last_named_field = last_field = field;
5222 : }
5223 62 : if (cur != wi::to_offset (sz))
5224 : {
5225 27 : if (explain)
5226 : {
5227 3 : if (last_named_field)
5228 3 : inform (DECL_SOURCE_LOCATION (last_named_field),
5229 : "padding occurs after %qD", last_named_field);
5230 : else
5231 0 : inform (DECL_SOURCE_LOCATION (t),
5232 : "%qT has padding and no data fields", t);
5233 : }
5234 27 : return false;
5235 : }
5236 :
5237 : return true;
5238 : }
5239 :
5240 : /* Nonzero iff type T is a class template implicit specialization. */
5241 :
5242 : bool
5243 131952558 : class_tmpl_impl_spec_p (const_tree t)
5244 : {
5245 131952558 : return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
5246 : }
5247 :
5248 : /* Returns 1 iff zero initialization of type T means actually storing
5249 : zeros in it. */
5250 :
5251 : int
5252 19148145 : zero_init_p (const_tree t)
5253 : {
5254 : /* This CONST_CAST is okay because strip_array_types returns its
5255 : argument unmodified and we assign it to a const_tree. */
5256 19148145 : t = strip_array_types (const_cast<tree> (t));
5257 :
5258 19148145 : if (t == error_mark_node)
5259 : return 1;
5260 :
5261 : /* NULL pointers to data members are initialized with -1. */
5262 19148145 : if (TYPE_PTRDATAMEM_P (t))
5263 : return 0;
5264 :
5265 : /* Classes that contain types that can't be zero-initialized, cannot
5266 : be zero-initialized themselves. */
5267 19147543 : if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
5268 143 : return 0;
5269 :
5270 : return 1;
5271 : }
5272 :
5273 : /* Returns true if the expression or initializer T is the result of
5274 : zero-initialization for its type, taking pointers to members
5275 : into consideration. */
5276 :
5277 : bool
5278 399503 : zero_init_expr_p (tree t)
5279 : {
5280 399503 : tree type = TREE_TYPE (t);
5281 399503 : if (!type || uses_template_parms (type))
5282 0 : return false;
5283 399503 : if (TYPE_PTRMEM_P (type))
5284 1224 : return null_member_pointer_value_p (t);
5285 398279 : if (TREE_CODE (t) == CONSTRUCTOR)
5286 : {
5287 167048 : if (COMPOUND_LITERAL_P (t)
5288 167048 : || BRACE_ENCLOSED_INITIALIZER_P (t))
5289 : /* Undigested, conversions might change the zeroness. */
5290 : return false;
5291 498924 : for (constructor_elt &elt : CONSTRUCTOR_ELTS (t))
5292 : {
5293 169293 : if (TREE_CODE (type) == UNION_TYPE
5294 169293 : && elt.index != first_field (type))
5295 : return false;
5296 169282 : if (!zero_init_expr_p (elt.value))
5297 : return false;
5298 : }
5299 : return true;
5300 : }
5301 231231 : if (zero_init_p (type))
5302 231231 : return initializer_zerop (t);
5303 : return false;
5304 : }
5305 :
5306 : /* True IFF T is a C++20 structural type (P1907R1) that can be used as a
5307 : non-type template parameter. If EXPLAIN, explain why not. */
5308 :
5309 : bool
5310 86103 : structural_type_p (tree t, bool explain)
5311 : {
5312 : /* A structural type is one of the following: */
5313 :
5314 : /* a scalar type, or */
5315 86103 : if (SCALAR_TYPE_P (t))
5316 : return true;
5317 : /* an lvalue reference type, or */
5318 42576 : if (TYPE_REF_P (t) && !TYPE_REF_IS_RVALUE (t))
5319 : return true;
5320 : /* a literal class type with the following properties:
5321 : - all base classes and non-static data members are public and non-mutable
5322 : and
5323 : - the types of all bases classes and non-static data members are
5324 : structural types or (possibly multi-dimensional) array thereof. */
5325 42562 : if (!CLASS_TYPE_P (t))
5326 : return false;
5327 42537 : if (!literal_type_p (t))
5328 : {
5329 40 : if (explain)
5330 10 : explain_non_literal_class (t);
5331 40 : return false;
5332 : }
5333 91153 : for (tree m = next_aggregate_field (TYPE_FIELDS (t)); m;
5334 48656 : m = next_aggregate_field (DECL_CHAIN (m)))
5335 : {
5336 48947 : if (TREE_PRIVATE (m) || TREE_PROTECTED (m))
5337 : {
5338 229 : if (explain)
5339 : {
5340 97 : if (DECL_FIELD_IS_BASE (m))
5341 3 : inform (location_of (m), "base class %qT is not public",
5342 3 : TREE_TYPE (m));
5343 : else
5344 94 : inform (location_of (m), "%qD is not public", m);
5345 : }
5346 229 : return false;
5347 : }
5348 48718 : if (DECL_MUTABLE_P (m))
5349 : {
5350 48 : if (explain)
5351 8 : inform (location_of (m), "%qD is mutable", m);
5352 48 : return false;
5353 : }
5354 48670 : tree mtype = strip_array_types (TREE_TYPE (m));
5355 48670 : if (!structural_type_p (mtype))
5356 : {
5357 14 : if (explain)
5358 : {
5359 2 : inform (location_of (m), "%qD has a non-structural type", m);
5360 2 : structural_type_p (mtype, true);
5361 : }
5362 14 : return false;
5363 : }
5364 : }
5365 : return true;
5366 : }
5367 :
5368 : /* Partially handle the C++11 [[carries_dependency]] attribute.
5369 : Just emit a different diagnostics when it is used on something the
5370 : spec doesn't allow vs. where it allows and we just choose to ignore
5371 : it. */
5372 :
5373 : static tree
5374 142 : handle_carries_dependency_attribute (tree *node, tree name,
5375 : tree ARG_UNUSED (args),
5376 : int ARG_UNUSED (flags),
5377 : bool *no_add_attrs)
5378 : {
5379 142 : if (TREE_CODE (*node) != FUNCTION_DECL
5380 121 : && TREE_CODE (*node) != PARM_DECL)
5381 : {
5382 76 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5383 : "functions or parameters", name);
5384 76 : *no_add_attrs = true;
5385 : }
5386 : else
5387 : {
5388 66 : warning (OPT_Wattributes, "%qE attribute ignored", name);
5389 66 : *no_add_attrs = true;
5390 : }
5391 142 : return NULL_TREE;
5392 : }
5393 :
5394 : /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
5395 : warn_unused_result attribute. */
5396 :
5397 : static tree
5398 13055700 : handle_nodiscard_attribute (tree *node, tree name, tree args,
5399 : int /*flags*/, bool *no_add_attrs)
5400 : {
5401 13055868 : if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
5402 : {
5403 6 : error ("%qE attribute argument must be a string constant", name);
5404 6 : *no_add_attrs = true;
5405 : }
5406 13055700 : if (TREE_CODE (*node) == FUNCTION_DECL)
5407 : {
5408 13054544 : if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))
5409 13153881 : && !DECL_CONSTRUCTOR_P (*node))
5410 9 : warning_at (DECL_SOURCE_LOCATION (*node),
5411 9 : OPT_Wattributes, "%qE attribute applied to %qD with void "
5412 : "return type", name, *node);
5413 : }
5414 1156 : else if (OVERLOAD_TYPE_P (*node))
5415 : /* OK */;
5416 : else
5417 : {
5418 148 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5419 : "functions or to class or enumeration types", name);
5420 148 : *no_add_attrs = true;
5421 : }
5422 13055700 : return NULL_TREE;
5423 : }
5424 :
5425 : /* Handle a C++20 "no_unique_address" attribute; arguments as in
5426 : struct attribute_spec.handler. */
5427 : static tree
5428 699194 : handle_no_unique_addr_attribute (tree* node,
5429 : tree name,
5430 : tree /*args*/,
5431 : int /*flags*/,
5432 : bool* no_add_attrs)
5433 : {
5434 699194 : if (TREE_CODE (*node) == VAR_DECL)
5435 : {
5436 48 : DECL_MERGEABLE (*node) = true;
5437 48 : if (pedantic)
5438 42 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5439 : "non-static data members", name);
5440 : }
5441 699146 : else if (TREE_CODE (*node) != FIELD_DECL)
5442 : {
5443 82 : warning (OPT_Wattributes, "%qE attribute can only be applied to "
5444 : "non-static data members", name);
5445 82 : *no_add_attrs = true;
5446 : }
5447 699064 : else if (DECL_C_BIT_FIELD (*node))
5448 : {
5449 6 : warning (OPT_Wattributes, "%qE attribute cannot be applied to "
5450 : "a bit-field", name);
5451 6 : *no_add_attrs = true;
5452 : }
5453 :
5454 699194 : return NULL_TREE;
5455 : }
5456 :
5457 : /* The C++20 [[likely]] and [[unlikely]] attributes on labels map to the GNU
5458 : hot/cold attributes. */
5459 :
5460 : static tree
5461 392 : handle_likeliness_attribute (tree *node, tree name, tree args,
5462 : int flags, bool *no_add_attrs)
5463 : {
5464 392 : *no_add_attrs = true;
5465 392 : if (TREE_CODE (*node) == LABEL_DECL
5466 392 : || TREE_CODE (*node) == FUNCTION_DECL)
5467 : {
5468 90 : if (args)
5469 0 : warning (OPT_Wattributes, "%qE attribute takes no arguments", name);
5470 90 : tree bname = (is_attribute_p ("likely", name)
5471 90 : ? get_identifier ("hot") : get_identifier ("cold"));
5472 90 : if (TREE_CODE (*node) == FUNCTION_DECL)
5473 33 : warning (OPT_Wattributes, "ISO C++ %qE attribute does not apply to "
5474 : "functions; treating as %<[[gnu::%E]]%>", name, bname);
5475 90 : tree battr = build_tree_list (bname, NULL_TREE);
5476 90 : decl_attributes (node, battr, flags);
5477 90 : return NULL_TREE;
5478 : }
5479 : else
5480 302 : return error_mark_node;
5481 : }
5482 :
5483 : /* The C++11 alignment specifier. It mostly maps to GNU aligned attribute,
5484 : but we need to do some extra pedantic checking. */
5485 :
5486 : static tree
5487 301362 : handle_alignas_attribute (tree *node, tree name, tree args, int flags,
5488 : bool *no_add_attrs)
5489 : {
5490 301362 : tree t = *node;
5491 301362 : tree ret = handle_aligned_attribute (node, name, args, flags, no_add_attrs);
5492 301362 : if (pedantic)
5493 : {
5494 1241 : if (TREE_CODE (*node) == FUNCTION_DECL)
5495 15 : pedwarn (input_location, OPT_Wattributes,
5496 : "%<alignas%> on function declaration");
5497 1226 : else if (TREE_CODE (*node) == ENUMERAL_TYPE)
5498 9 : pedwarn (input_location, OPT_Wattributes,
5499 : "%<alignas%> on enumerated type");
5500 1217 : else if (TYPE_P (*node) && t != *node)
5501 56 : pedwarn (input_location, OPT_Wattributes,
5502 : "%<alignas%> on a type other than class");
5503 1161 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_C_BIT_FIELD (*node))
5504 9 : pedwarn (input_location, OPT_Wattributes, "%<alignas%> on bit-field");
5505 1152 : else if (TREE_CODE (t) == TYPE_DECL)
5506 9 : pedwarn (input_location, OPT_Wattributes,
5507 : "%<alignas%> on a type alias");
5508 : }
5509 301362 : return ret;
5510 : }
5511 :
5512 : /* The C++14 [[deprecated]] attribute mostly maps to the GNU deprecated
5513 : attribute. */
5514 :
5515 : static tree
5516 273253 : handle_std_deprecated_attribute (tree *node, tree name, tree args, int flags,
5517 : bool *no_add_attrs)
5518 : {
5519 273253 : tree t = *node;
5520 273253 : tree ret = handle_deprecated_attribute (node, name, args, flags,
5521 : no_add_attrs);
5522 273253 : if (TYPE_P (*node) && t != *node)
5523 48 : pedwarn (input_location, OPT_Wattributes,
5524 : "%qE on a type other than class or enumeration definition", name);
5525 273205 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5526 4 : pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
5527 : name);
5528 273253 : return ret;
5529 : }
5530 :
5531 : /* The C++17 [[maybe_unused]] attribute mostly maps to the GNU unused
5532 : attribute. */
5533 :
5534 : static tree
5535 98776 : handle_maybe_unused_attribute (tree *node, tree name, tree args, int flags,
5536 : bool *no_add_attrs)
5537 : {
5538 98776 : tree t = *node;
5539 98776 : tree ret = handle_unused_attribute (node, name, args, flags, no_add_attrs);
5540 98776 : if (TYPE_P (*node) && t != *node)
5541 36 : pedwarn (input_location, OPT_Wattributes,
5542 : "%qE on a type other than class or enumeration definition", name);
5543 98740 : else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5544 3 : pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
5545 : name);
5546 98737 : else if (TREE_CODE (*node) == LABEL_DECL && DECL_NAME (*node) == NULL_TREE)
5547 6 : pedwarn (input_location, OPT_Wattributes,
5548 : "%qE on %<case%> or %<default%> label", name);
5549 98776 : return ret;
5550 : }
5551 :
5552 : /* The C++26 [[indeterminate]] attribute. */
5553 :
5554 : static tree
5555 231 : handle_indeterminate_attribute (tree *node, tree name, tree, int,
5556 : bool *no_add_attrs)
5557 : {
5558 231 : if (TREE_CODE (*node) != PARM_DECL
5559 231 : && (!VAR_P (*node) || is_global_var (*node)))
5560 : {
5561 67 : pedwarn (input_location, OPT_Wattributes,
5562 : "%qE on declaration other than parameter or automatic variable",
5563 : name);
5564 67 : *no_add_attrs = true;
5565 : }
5566 231 : return NULL_TREE;
5567 : }
5568 :
5569 : /* Table of valid C++ attributes. */
5570 : // clang-format off
5571 : static const attribute_spec cxx_gnu_attributes[] =
5572 : {
5573 : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5574 : affects_type_identity, handler, exclude } */
5575 : { "init_priority", 1, 1, true, false, false, false,
5576 : handle_init_priority_attribute, NULL },
5577 : { "abi_tag", 1, -1, false, false, false, true,
5578 : handle_abi_tag_attribute, NULL },
5579 : { "no_dangling", 0, 1, false, true, false, false,
5580 : handle_no_dangling_attribute, NULL },
5581 : { "trivial_abi", 0, 0, false, true, false, true,
5582 : handle_gnu_trivial_abi_attribute, NULL },
5583 : };
5584 : // clang-format on
5585 :
5586 : const scoped_attribute_specs cxx_gnu_attribute_table =
5587 : {
5588 : "gnu", { cxx_gnu_attributes }
5589 : };
5590 :
5591 : /* Table of C++ standard attributes. */
5592 : static const attribute_spec std_attributes[] =
5593 : {
5594 : /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
5595 : affects_type_identity, handler, exclude } */
5596 : { "deprecated", 0, 1, false, false, false, false,
5597 : handle_std_deprecated_attribute, NULL },
5598 : { "maybe_unused", 0, 0, false, false, false, false,
5599 : handle_maybe_unused_attribute, NULL },
5600 : { "nodiscard", 0, 1, false, false, false, false,
5601 : handle_nodiscard_attribute, NULL },
5602 : { "no_unique_address", 0, 0, true, false, false, false,
5603 : handle_no_unique_addr_attribute, NULL },
5604 : { "likely", 0, 0, false, false, false, false,
5605 : handle_likeliness_attribute, attr_cold_hot_exclusions },
5606 : { "unlikely", 0, 0, false, false, false, false,
5607 : handle_likeliness_attribute, attr_cold_hot_exclusions },
5608 : { "noreturn", 0, 0, true, false, false, false,
5609 : handle_noreturn_attribute, attr_noreturn_exclusions },
5610 : { "carries_dependency", 0, 0, true, false, false, false,
5611 : handle_carries_dependency_attribute, NULL },
5612 : { "indeterminate", 0, 0, true, false, false, false,
5613 : handle_indeterminate_attribute, NULL },
5614 : };
5615 :
5616 : const scoped_attribute_specs std_attribute_table =
5617 : {
5618 : nullptr, { std_attributes }
5619 : };
5620 :
5621 : /* Table of internal attributes. */
5622 : static const attribute_spec internal_attributes[] =
5623 : {
5624 : { "aligned", 0, 1, false, false, false, false,
5625 : handle_alignas_attribute, attr_aligned_exclusions },
5626 : { "annotation ", 1, 1, false, false, false, false,
5627 : handle_annotation_attribute, NULL }
5628 : };
5629 :
5630 : const scoped_attribute_specs internal_attribute_table =
5631 : {
5632 : "internal ", { internal_attributes }
5633 : };
5634 :
5635 : /* Table of C++ attributes also recognized in the clang:: namespace. */
5636 : // clang-format off
5637 : static const attribute_spec cxx_clang_attributes[] =
5638 : {
5639 : { "trivial_abi", 0, 0, false, true, false, true,
5640 : handle_trivial_abi_attribute, NULL },
5641 : };
5642 :
5643 : const scoped_attribute_specs cxx_clang_attribute_table =
5644 : {
5645 : "clang", { cxx_clang_attributes }
5646 : };
5647 : // clang-format on
5648 :
5649 : /* Handle an "init_priority" attribute; arguments as in
5650 : struct attribute_spec.handler. */
5651 : static tree
5652 35 : handle_init_priority_attribute (tree* node,
5653 : tree name,
5654 : tree args,
5655 : int /*flags*/,
5656 : bool* no_add_attrs)
5657 : {
5658 35 : if (!SUPPORTS_INIT_PRIORITY)
5659 : /* Treat init_priority as an unrecognized attribute (mirroring
5660 : __has_attribute) if the target doesn't support init priorities. */
5661 : return error_mark_node;
5662 :
5663 35 : tree initp_expr = TREE_VALUE (args);
5664 35 : tree decl = *node;
5665 35 : tree type = TREE_TYPE (decl);
5666 35 : int pri;
5667 :
5668 35 : STRIP_NOPS (initp_expr);
5669 35 : initp_expr = default_conversion (initp_expr);
5670 35 : if (initp_expr)
5671 35 : initp_expr = maybe_constant_value (initp_expr);
5672 :
5673 35 : if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
5674 : {
5675 0 : error ("requested %<init_priority%> is not an integer constant");
5676 0 : cxx_constant_value (initp_expr);
5677 0 : *no_add_attrs = true;
5678 0 : return NULL_TREE;
5679 : }
5680 :
5681 35 : pri = TREE_INT_CST_LOW (initp_expr);
5682 :
5683 35 : type = strip_array_types (type);
5684 :
5685 35 : if (decl == NULL_TREE
5686 35 : || !VAR_P (decl)
5687 35 : || !TREE_STATIC (decl)
5688 35 : || DECL_EXTERNAL (decl)
5689 35 : || (TREE_CODE (type) != RECORD_TYPE
5690 35 : && TREE_CODE (type) != UNION_TYPE)
5691 : /* Static objects in functions are initialized the
5692 : first time control passes through that
5693 : function. This is not precise enough to pin down an
5694 : init_priority value, so don't allow it. */
5695 70 : || current_function_decl)
5696 : {
5697 0 : error ("can only use %qE attribute on file-scope definitions "
5698 : "of objects of class type", name);
5699 0 : *no_add_attrs = true;
5700 0 : return NULL_TREE;
5701 : }
5702 :
5703 35 : if (pri > MAX_INIT_PRIORITY || pri <= 0)
5704 : {
5705 0 : error ("requested %<init_priority%> %i is out of range [0, %i]",
5706 : pri, MAX_INIT_PRIORITY);
5707 0 : *no_add_attrs = true;
5708 0 : return NULL_TREE;
5709 : }
5710 :
5711 : /* Check for init_priorities that are reserved for
5712 : language and runtime support implementations.*/
5713 35 : if (pri <= MAX_RESERVED_INIT_PRIORITY
5714 35 : && !in_system_header_at (input_location))
5715 : {
5716 10 : warning
5717 10 : (OPT_Wprio_ctor_dtor,
5718 : "requested %<init_priority%> %i is reserved for internal use",
5719 : pri);
5720 : }
5721 :
5722 35 : SET_DECL_INIT_PRIORITY (decl, pri);
5723 35 : DECL_HAS_INIT_PRIORITY_P (decl) = 1;
5724 35 : return NULL_TREE;
5725 : }
5726 :
5727 : /* DECL is being redeclared; the old declaration had the abi tags in OLD,
5728 : and the new one has the tags in NEW_. Give an error if there are tags
5729 : in NEW_ that weren't in OLD. */
5730 :
5731 : bool
5732 11042279 : check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_)
5733 : {
5734 11109011 : if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST)
5735 : old = TREE_VALUE (old);
5736 11063663 : if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST)
5737 : new_ = TREE_VALUE (new_);
5738 11042279 : bool err = false;
5739 11042279 : auto_diagnostic_group d;
5740 11063663 : for (const_tree t = new_; t; t = TREE_CHAIN (t))
5741 : {
5742 21384 : tree str = TREE_VALUE (t);
5743 21384 : for (const_tree in = old; in; in = TREE_CHAIN (in))
5744 : {
5745 21375 : tree ostr = TREE_VALUE (in);
5746 21375 : if (cp_tree_equal (str, ostr))
5747 21375 : goto found;
5748 : }
5749 9 : error ("redeclaration of %qD adds abi tag %qE", decl, str);
5750 9 : err = true;
5751 21384 : found:;
5752 : }
5753 11042279 : if (err)
5754 : {
5755 9 : inform (DECL_SOURCE_LOCATION (decl), "previous declaration here");
5756 9 : return false;
5757 : }
5758 : return true;
5759 11042279 : }
5760 :
5761 : /* The abi_tag attribute with the name NAME was given ARGS. If they are
5762 : ill-formed, give an error and return false; otherwise, return true. */
5763 :
5764 : bool
5765 422474 : check_abi_tag_args (tree args, tree name)
5766 : {
5767 422474 : if (!args)
5768 : {
5769 0 : error ("the %qE attribute requires arguments", name);
5770 0 : return false;
5771 : }
5772 844987 : for (tree arg = args; arg; arg = TREE_CHAIN (arg))
5773 : {
5774 422525 : tree elt = TREE_VALUE (arg);
5775 422525 : if (TREE_CODE (elt) != STRING_CST
5776 845044 : || (!same_type_ignoring_top_level_qualifiers_p
5777 422519 : (strip_array_types (TREE_TYPE (elt)),
5778 : char_type_node)))
5779 : {
5780 9 : error ("arguments to the %qE attribute must be narrow string "
5781 : "literals", name);
5782 9 : return false;
5783 : }
5784 422516 : const char *begin = TREE_STRING_POINTER (elt);
5785 422516 : const char *end = begin + TREE_STRING_LENGTH (elt);
5786 3011620 : for (const char *p = begin; p != end; ++p)
5787 : {
5788 2589107 : char c = *p;
5789 2589107 : if (p == begin)
5790 : {
5791 422516 : if (!ISALPHA (c) && c != '_')
5792 : {
5793 3 : auto_diagnostic_group d;
5794 3 : error ("arguments to the %qE attribute must contain valid "
5795 : "identifiers", name);
5796 3 : inform (input_location, "%<%c%> is not a valid first "
5797 : "character for an identifier", c);
5798 3 : return false;
5799 3 : }
5800 : }
5801 2166591 : else if (p == end - 1)
5802 422513 : gcc_assert (c == 0);
5803 : else
5804 : {
5805 1744078 : if (!ISALNUM (c) && c != '_')
5806 : {
5807 0 : auto_diagnostic_group d;
5808 0 : error ("arguments to the %qE attribute must contain valid "
5809 : "identifiers", name);
5810 0 : inform (input_location, "%<%c%> is not a valid character "
5811 : "in an identifier", c);
5812 0 : return false;
5813 0 : }
5814 : }
5815 : }
5816 : }
5817 : return true;
5818 : }
5819 :
5820 : /* Handle an "abi_tag" attribute; arguments as in
5821 : struct attribute_spec.handler. */
5822 :
5823 : static tree
5824 375259 : handle_abi_tag_attribute (tree* node, tree name, tree args,
5825 : int flags, bool* no_add_attrs)
5826 : {
5827 375259 : if (!check_abi_tag_args (args, name))
5828 12 : goto fail;
5829 :
5830 375247 : if (TYPE_P (*node))
5831 : {
5832 10984 : if (!OVERLOAD_TYPE_P (*node))
5833 : {
5834 0 : error ("%qE attribute applied to non-class, non-enum type %qT",
5835 : name, *node);
5836 0 : goto fail;
5837 : }
5838 10984 : else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE))
5839 : {
5840 0 : error ("%qE attribute applied to %qT after its definition",
5841 : name, *node);
5842 0 : goto fail;
5843 : }
5844 10981 : else if (CLASS_TYPE_P (*node)
5845 21965 : && CLASSTYPE_TEMPLATE_INSTANTIATION (*node))
5846 : {
5847 3 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5848 : "template instantiation %qT", name, *node);
5849 3 : goto fail;
5850 : }
5851 10978 : else if (CLASS_TYPE_P (*node)
5852 21959 : && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node))
5853 : {
5854 3 : warning (OPT_Wattributes, "ignoring %qE attribute applied to "
5855 : "template specialization %qT", name, *node);
5856 3 : goto fail;
5857 : }
5858 :
5859 10978 : tree attributes = TYPE_ATTRIBUTES (*node);
5860 10978 : tree decl = TYPE_NAME (*node);
5861 :
5862 : /* Make sure all declarations have the same abi tags. */
5863 10978 : if (DECL_SOURCE_LOCATION (decl) != input_location)
5864 : {
5865 6 : if (!check_abi_tag_redeclaration (decl,
5866 6 : lookup_attribute ("abi_tag",
5867 : attributes),
5868 : args))
5869 6 : goto fail;
5870 : }
5871 : }
5872 : else
5873 : {
5874 364263 : if (!VAR_OR_FUNCTION_DECL_P (*node))
5875 : {
5876 0 : error ("%qE attribute applied to non-function, non-variable %qD",
5877 : name, *node);
5878 0 : goto fail;
5879 : }
5880 364263 : else if (DECL_LANGUAGE (*node) == lang_c)
5881 : {
5882 0 : error ("%qE attribute applied to extern \"C\" declaration %qD",
5883 : name, *node);
5884 0 : goto fail;
5885 : }
5886 : }
5887 :
5888 : return NULL_TREE;
5889 :
5890 24 : fail:
5891 24 : *no_add_attrs = true;
5892 24 : return NULL_TREE;
5893 : }
5894 :
5895 : /* Handle a "no_dangling" attribute; arguments as in
5896 : struct attribute_spec.handler. */
5897 :
5898 : tree
5899 96 : handle_no_dangling_attribute (tree *node, tree name, tree args, int,
5900 : bool *no_add_attrs)
5901 : {
5902 147 : if (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
5903 : {
5904 3 : error ("%qE attribute argument must be an expression that evaluates "
5905 : "to true or false", name);
5906 3 : *no_add_attrs = true;
5907 : }
5908 93 : else if (!FUNC_OR_METHOD_TYPE_P (*node)
5909 51 : && !RECORD_OR_UNION_TYPE_P (*node))
5910 : {
5911 18 : warning (OPT_Wattributes, "%qE attribute ignored", name);
5912 18 : *no_add_attrs = true;
5913 : }
5914 :
5915 96 : return NULL_TREE;
5916 : }
5917 :
5918 : /* Perform checking for annotations. */
5919 :
5920 : tree
5921 846 : handle_annotation_attribute (tree *node, tree ARG_UNUSED (name),
5922 : tree args, int ARG_UNUSED (flags),
5923 : bool *no_add_attrs)
5924 : {
5925 846 : if (TYPE_P (*node)
5926 118 : && TREE_CODE (*node) != ENUMERAL_TYPE
5927 110 : && TREE_CODE (*node) != RECORD_TYPE
5928 24 : && TREE_CODE (*node) != UNION_TYPE)
5929 : {
5930 24 : error ("annotation on a type other than class or enumeration "
5931 : "definition");
5932 24 : *no_add_attrs = true;
5933 24 : return NULL_TREE;
5934 : }
5935 822 : if (TREE_CODE (*node) == LABEL_DECL)
5936 : {
5937 6 : error ("annotation applied to a label");
5938 6 : *no_add_attrs = true;
5939 6 : return NULL_TREE;
5940 : }
5941 816 : if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
5942 : {
5943 2 : error ("annotation on unnamed bit-field");
5944 2 : *no_add_attrs = true;
5945 2 : return NULL_TREE;
5946 : }
5947 814 : if (TREE_CODE (*node) == PARM_DECL && VOID_TYPE_P (TREE_TYPE (*node)))
5948 : {
5949 2 : error ("annotation on void parameter");
5950 2 : *no_add_attrs = true;
5951 2 : return NULL_TREE;
5952 : }
5953 :
5954 : /* Annotations are treated as late attributes so we shouldn't see
5955 : anything type-dependent now. */
5956 812 : gcc_assert (!type_dependent_expression_p (TREE_VALUE (args)));
5957 : /* FIXME We should be using convert_reflect_constant_arg here to
5958 : implement std::meta::reflect_constant(constant-expression)
5959 : properly, but that introduces new crashes. */
5960 812 : TREE_VALUE (args) = decay_conversion (TREE_VALUE (args), tf_warning_or_error);
5961 :
5962 812 : if (!structural_type_p (TREE_TYPE (TREE_VALUE (args))))
5963 : {
5964 102 : auto_diagnostic_group d;
5965 102 : error ("annotation does not have structural type");
5966 102 : structural_type_p (TREE_TYPE (TREE_VALUE (args)), true);
5967 102 : *no_add_attrs = true;
5968 102 : return NULL_TREE;
5969 102 : }
5970 710 : if (CLASS_TYPE_P (TREE_TYPE (TREE_VALUE (args))))
5971 : {
5972 62 : tree arg = make_tree_vec (1);
5973 62 : tree type = TREE_TYPE (TREE_VALUE (args));
5974 62 : TREE_VEC_ELT (arg, 0)
5975 62 : = build_stub_type (type, cp_type_quals (type) | TYPE_QUAL_CONST,
5976 : /*rvalue=*/false);
5977 62 : if (!is_xible (INIT_EXPR, type, arg))
5978 : {
5979 4 : auto_diagnostic_group d;
5980 4 : error ("annotation does not have copy constructible type");
5981 4 : is_xible (INIT_EXPR, type, arg, /*explain=*/true);
5982 4 : *no_add_attrs = true;
5983 4 : return NULL_TREE;
5984 4 : }
5985 : }
5986 706 : if (!processing_template_decl)
5987 : {
5988 698 : location_t loc = EXPR_LOCATION (TREE_VALUE (args));
5989 698 : TREE_VALUE (args) = cxx_constant_value (TREE_VALUE (args));
5990 698 : if (error_operand_p (TREE_VALUE (args)))
5991 4 : *no_add_attrs = true;
5992 698 : auto suppression
5993 698 : = make_temp_override (suppress_location_wrappers, 0);
5994 698 : TREE_VALUE (args) = maybe_wrap_with_location (TREE_VALUE (args), loc);
5995 698 : }
5996 706 : ATTR_UNIQUE_VALUE_P (args) = 1;
5997 706 : return NULL_TREE;
5998 : }
5999 :
6000 : /* Handle a "trivial_abi" attribute applied via [[gnu::trivial_abi]].
6001 : We reject that spelling; suggest [[clang::trivial_abi]] or
6002 : __attribute__((trivial_abi)) instead. */
6003 :
6004 : static tree
6005 84 : handle_gnu_trivial_abi_attribute (tree *node, tree name, tree args, int flags,
6006 : bool *no_add_attrs)
6007 : {
6008 84 : if (flags & ATTR_FLAG_CXX11)
6009 : {
6010 3 : warning (OPT_Wattributes,
6011 : "%<[[gnu::trivial_abi]]%> is not supported; use "
6012 : "%<[[clang::trivial_abi]]%> or "
6013 : "%<__attribute__((trivial_abi))%> instead");
6014 3 : *no_add_attrs = true;
6015 3 : return NULL_TREE;
6016 : }
6017 165 : return handle_trivial_abi_attribute (node, name, args, flags, no_add_attrs);
6018 : }
6019 :
6020 : /* Handle a "trivial_abi" attribute. */
6021 :
6022 : static tree
6023 138 : handle_trivial_abi_attribute (tree *node, tree name, tree, int,
6024 : bool *no_add_attrs)
6025 : {
6026 138 : tree type = *node;
6027 :
6028 : /* Only allow on class types (struct, class, union) */
6029 138 : if (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE)
6030 : {
6031 9 : warning (OPT_Wattributes, "%qE attribute only applies to classes", name);
6032 9 : *no_add_attrs = true;
6033 9 : return NULL_TREE;
6034 : }
6035 :
6036 : return NULL_TREE;
6037 : }
6038 :
6039 : /* Return true if TYPE has the trivial_abi attribute. */
6040 :
6041 : bool
6042 207091288 : has_trivial_abi_attribute (tree type)
6043 : {
6044 207091288 : if (type == NULL_TREE || !TYPE_P (type))
6045 : return false;
6046 207091255 : return lookup_attribute ("trivial_abi", TYPE_ATTRIBUTES (type));
6047 : }
6048 :
6049 : /* Validate the trivial_abi attribute on a completed class type.
6050 : Called from finish_struct after the class is complete. */
6051 :
6052 : void
6053 50048773 : validate_trivial_abi_attribute (tree type)
6054 : {
6055 50048773 : if (!has_trivial_abi_attribute (type))
6056 : return;
6057 :
6058 129 : gcc_assert (COMPLETE_TYPE_P (type));
6059 :
6060 : /* Check for virtual bases. */
6061 129 : if (CLASSTYPE_VBASECLASSES (type))
6062 : {
6063 6 : auto_diagnostic_group d;
6064 6 : if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
6065 : type))
6066 6 : inform (input_location, "has a virtual base");
6067 6 : TYPE_ATTRIBUTES (type)
6068 6 : = remove_attribute ("trivial_abi", TYPE_ATTRIBUTES (type));
6069 6 : return;
6070 6 : }
6071 :
6072 : /* Check for virtual member functions. */
6073 123 : if (TYPE_POLYMORPHIC_P (type))
6074 : {
6075 9 : auto_diagnostic_group d;
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 9 : }
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 : auto_diagnostic_group d;
6096 3 : if (warning (OPT_Wattributes,
6097 : "%<trivial_abi%> cannot be applied to %qT", type))
6098 3 : inform (input_location, "has a non-trivial base class %qT",
6099 : base_type);
6100 3 : TYPE_ATTRIBUTES (type)
6101 3 : = remove_attribute ("trivial_abi", TYPE_ATTRIBUTES (type));
6102 3 : return;
6103 3 : }
6104 : }
6105 : }
6106 :
6107 : /* Check for non-trivial member types. */
6108 624 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6109 : {
6110 525 : if (TREE_CODE (field) == FIELD_DECL && !DECL_ARTIFICIAL (field))
6111 : {
6112 102 : tree field_type = strip_array_types (TREE_TYPE (field));
6113 :
6114 102 : if (CLASS_TYPE_P (field_type) && TREE_ADDRESSABLE (field_type))
6115 : {
6116 12 : auto_diagnostic_group d;
6117 12 : if (warning (OPT_Wattributes,
6118 : "%<trivial_abi%> cannot be applied to %qT", type))
6119 12 : inform (input_location, "has a non-static data member "
6120 : "of non-trivial type %qT", field_type);
6121 12 : TYPE_ATTRIBUTES (type)
6122 12 : = remove_attribute ("trivial_abi", TYPE_ATTRIBUTES (type));
6123 12 : return;
6124 12 : }
6125 : }
6126 : }
6127 :
6128 : /* Check that not all copy/move constructors are deleted. */
6129 99 : if (!classtype_has_non_deleted_copy_or_move_ctor (type))
6130 : {
6131 9 : auto_diagnostic_group d;
6132 9 : if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
6133 : type))
6134 9 : inform (input_location,
6135 : "copy constructors and move constructors are all deleted");
6136 9 : TYPE_ATTRIBUTES (type)
6137 9 : = remove_attribute ("trivial_abi", TYPE_ATTRIBUTES (type));
6138 9 : return;
6139 9 : }
6140 : }
6141 : /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
6142 : thing pointed to by the constant. */
6143 :
6144 : tree
6145 61867 : make_ptrmem_cst (tree type, tree member)
6146 : {
6147 61867 : tree ptrmem_cst = make_node (PTRMEM_CST);
6148 61867 : TREE_TYPE (ptrmem_cst) = type;
6149 61867 : PTRMEM_CST_MEMBER (ptrmem_cst) = member;
6150 61867 : PTRMEM_CST_LOCATION (ptrmem_cst) = input_location;
6151 61867 : return ptrmem_cst;
6152 : }
6153 :
6154 : /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
6155 : return an existing type if an appropriate type already exists. */
6156 :
6157 : tree
6158 15761343 : cp_build_type_attribute_variant (tree type, tree attributes)
6159 : {
6160 15761343 : tree new_type;
6161 :
6162 15761343 : new_type = build_type_attribute_variant (type, attributes);
6163 15761343 : if (FUNC_OR_METHOD_TYPE_P (new_type))
6164 15690675 : gcc_checking_assert (cxx_type_hash_eq (type, new_type));
6165 :
6166 : /* Making a new main variant of a class type is broken. */
6167 15761343 : gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
6168 :
6169 15761343 : return new_type;
6170 : }
6171 :
6172 : /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
6173 : Called only after doing all language independent checks. */
6174 :
6175 : bool
6176 328059717 : cxx_type_hash_eq (const_tree typea, const_tree typeb)
6177 : {
6178 328059717 : gcc_assert (FUNC_OR_METHOD_TYPE_P (typea));
6179 :
6180 328059717 : if (type_memfn_rqual (typea) != type_memfn_rqual (typeb))
6181 : return false;
6182 328054216 : if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb))
6183 : return false;
6184 328053179 : return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
6185 656106358 : TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
6186 : }
6187 :
6188 : /* Copy the language-specific type variant modifiers from TYPEB to TYPEA. For
6189 : C++, these are the exception-specifier and ref-qualifier. */
6190 :
6191 : tree
6192 25494681 : cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
6193 : {
6194 25494681 : tree type = const_cast<tree> (typea);
6195 25494681 : if (FUNC_OR_METHOD_TYPE_P (type))
6196 25493619 : type = build_cp_fntype_variant (type, type_memfn_rqual (typeb),
6197 25493619 : TYPE_RAISES_EXCEPTIONS (typeb),
6198 25493619 : TYPE_HAS_LATE_RETURN_TYPE (typeb));
6199 25494681 : return type;
6200 : }
6201 :
6202 : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
6203 : traversal. Called from walk_tree. */
6204 :
6205 : tree
6206 23906670354 : cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
6207 : void *data, hash_set<tree> *pset)
6208 : {
6209 23906670354 : tree t = *tp;
6210 23906670354 : enum tree_code code = TREE_CODE (t);
6211 23906670354 : tree result;
6212 :
6213 : #define WALK_SUBTREE(NODE) \
6214 : do \
6215 : { \
6216 : result = cp_walk_tree (&(NODE), func, data, pset); \
6217 : if (result) goto out; \
6218 : } \
6219 : while (0)
6220 :
6221 23906670354 : if (TYPE_P (t))
6222 : {
6223 : /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
6224 : the argument, so don't look through typedefs, but do walk into
6225 : template arguments for alias templates (and non-typedefed classes).
6226 :
6227 : If *WALK_SUBTREES_P > 1, we're interested in type identity or
6228 : equivalence, so look through typedefs, ignoring template arguments for
6229 : alias templates, and walk into template args of classes.
6230 :
6231 : See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
6232 : when that's the behavior the walk_tree_fn wants. */
6233 7116308840 : if (*walk_subtrees_p == 1 && typedef_variant_p (t))
6234 : {
6235 72244807 : if (tree ti = TYPE_ALIAS_TEMPLATE_INFO (t))
6236 55426072 : WALK_SUBTREE (TI_ARGS (ti));
6237 72204836 : *walk_subtrees_p = 0;
6238 72204836 : return NULL_TREE;
6239 : }
6240 :
6241 7044064033 : if (tree ti = TYPE_TEMPLATE_INFO (t))
6242 805223032 : WALK_SUBTREE (TI_ARGS (ti));
6243 : }
6244 :
6245 : /* Not one of the easy cases. We must explicitly go through the
6246 : children. */
6247 23834266283 : result = NULL_TREE;
6248 23834266283 : switch (code)
6249 : {
6250 1839675387 : case TEMPLATE_TYPE_PARM:
6251 1839675387 : if (template_placeholder_p (t))
6252 1273611 : WALK_SUBTREE (CLASS_PLACEHOLDER_TEMPLATE (t));
6253 : /* Fall through. */
6254 1989157334 : case DEFERRED_PARSE:
6255 1989157334 : case TEMPLATE_TEMPLATE_PARM:
6256 1989157334 : case BOUND_TEMPLATE_TEMPLATE_PARM:
6257 1989157334 : case UNBOUND_CLASS_TEMPLATE:
6258 1989157334 : case TEMPLATE_PARM_INDEX:
6259 1989157334 : case TYPEOF_TYPE:
6260 : /* None of these have subtrees other than those already walked
6261 : above. */
6262 1989157334 : *walk_subtrees_p = 0;
6263 1989157334 : break;
6264 :
6265 209321634 : case TYPENAME_TYPE:
6266 209321634 : WALK_SUBTREE (TYPE_CONTEXT (t));
6267 209234058 : WALK_SUBTREE (TYPENAME_TYPE_FULLNAME (t));
6268 209232409 : *walk_subtrees_p = 0;
6269 209232409 : break;
6270 :
6271 80942496 : case BASELINK:
6272 80942496 : if (BASELINK_QUALIFIED_P (t))
6273 1465483 : WALK_SUBTREE (BINFO_TYPE (BASELINK_ACCESS_BINFO (t)));
6274 80942496 : WALK_SUBTREE (BASELINK_FUNCTIONS (t));
6275 80845172 : *walk_subtrees_p = 0;
6276 80845172 : break;
6277 :
6278 127884 : case PTRMEM_CST:
6279 127884 : WALK_SUBTREE (TREE_TYPE (t));
6280 127884 : *walk_subtrees_p = 0;
6281 127884 : break;
6282 :
6283 263030612 : case TREE_LIST:
6284 263030612 : WALK_SUBTREE (TREE_PURPOSE (t));
6285 : break;
6286 :
6287 300327592 : case OVERLOAD:
6288 300327592 : WALK_SUBTREE (OVL_FUNCTION (t));
6289 300327587 : WALK_SUBTREE (OVL_CHAIN (t));
6290 300327587 : *walk_subtrees_p = 0;
6291 300327587 : break;
6292 :
6293 7752040 : case USING_DECL:
6294 7752040 : WALK_SUBTREE (DECL_NAME (t));
6295 7752040 : WALK_SUBTREE (USING_DECL_SCOPE (t));
6296 7752037 : WALK_SUBTREE (USING_DECL_DECLS (t));
6297 7752037 : *walk_subtrees_p = 0;
6298 7752037 : break;
6299 :
6300 931209303 : case RECORD_TYPE:
6301 931209303 : if (TYPE_PTRMEMFUNC_P (t))
6302 5478228 : WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (t));
6303 : break;
6304 :
6305 143239947 : case TYPE_ARGUMENT_PACK:
6306 143239947 : case NONTYPE_ARGUMENT_PACK:
6307 143239947 : {
6308 143239947 : tree args = ARGUMENT_PACK_ARGS (t);
6309 375104104 : for (tree arg : tree_vec_range (args))
6310 231952131 : WALK_SUBTREE (arg);
6311 : }
6312 143151973 : break;
6313 :
6314 29110142 : case TYPE_PACK_EXPANSION:
6315 29110142 : WALK_SUBTREE (TREE_TYPE (t));
6316 29103711 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
6317 29103711 : *walk_subtrees_p = 0;
6318 29103711 : break;
6319 :
6320 5888950 : case EXPR_PACK_EXPANSION:
6321 5888950 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6322 5885920 : WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
6323 5885920 : *walk_subtrees_p = 0;
6324 5885920 : break;
6325 :
6326 10506 : case PACK_INDEX_TYPE:
6327 10506 : case PACK_INDEX_EXPR:
6328 10506 : WALK_SUBTREE (PACK_INDEX_PACK (t));
6329 10506 : WALK_SUBTREE (PACK_INDEX_INDEX (t));
6330 10506 : *walk_subtrees_p = 0;
6331 10506 : break;
6332 :
6333 108086341 : case CAST_EXPR:
6334 108086341 : case REINTERPRET_CAST_EXPR:
6335 108086341 : case STATIC_CAST_EXPR:
6336 108086341 : case CONST_CAST_EXPR:
6337 108086341 : case DYNAMIC_CAST_EXPR:
6338 108086341 : case IMPLICIT_CONV_EXPR:
6339 108086341 : case BIT_CAST_EXPR:
6340 108086341 : if (TREE_TYPE (t))
6341 108086341 : WALK_SUBTREE (TREE_TYPE (t));
6342 : break;
6343 :
6344 96339600 : case CONSTRUCTOR:
6345 96339600 : if (COMPOUND_LITERAL_P (t))
6346 8898772 : WALK_SUBTREE (TREE_TYPE (t));
6347 : break;
6348 :
6349 15081984 : case TRAIT_EXPR:
6350 15081984 : WALK_SUBTREE (TRAIT_EXPR_TYPE1 (t));
6351 15081972 : WALK_SUBTREE (TRAIT_EXPR_TYPE2 (t));
6352 15081972 : *walk_subtrees_p = 0;
6353 15081972 : break;
6354 :
6355 2061507 : case TRAIT_TYPE:
6356 2061507 : WALK_SUBTREE (TRAIT_TYPE_TYPE1 (t));
6357 2061507 : WALK_SUBTREE (TRAIT_TYPE_TYPE2 (t));
6358 2061507 : *walk_subtrees_p = 0;
6359 2061507 : break;
6360 :
6361 20349076 : case DECLTYPE_TYPE:
6362 20349076 : {
6363 20349076 : cp_unevaluated u;
6364 20349076 : WALK_SUBTREE (DECLTYPE_TYPE_EXPR (t));
6365 20003491 : *walk_subtrees_p = 0;
6366 20003491 : break;
6367 20349076 : }
6368 :
6369 26742687 : case ALIGNOF_EXPR:
6370 26742687 : case SIZEOF_EXPR:
6371 26742687 : case NOEXCEPT_EXPR:
6372 26742687 : {
6373 26742687 : cp_unevaluated u;
6374 26742687 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6375 23775245 : *walk_subtrees_p = 0;
6376 23775245 : break;
6377 26742687 : }
6378 :
6379 12549971 : case REQUIRES_EXPR:
6380 12549971 : {
6381 12549971 : cp_unevaluated u;
6382 21066925 : for (tree parm = REQUIRES_EXPR_PARMS (t); parm; parm = DECL_CHAIN (parm))
6383 : /* Walk the types of each parameter, but not the parameter itself,
6384 : since doing so would cause false positives in the unexpanded pack
6385 : checker if the requires-expr introduces a function parameter pack,
6386 : e.g. requires (Ts... ts) { }. */
6387 8517362 : WALK_SUBTREE (TREE_TYPE (parm));
6388 12549563 : WALK_SUBTREE (REQUIRES_EXPR_REQS (t));
6389 12546502 : *walk_subtrees_p = 0;
6390 12546502 : break;
6391 12549971 : }
6392 :
6393 125054997 : case DECL_EXPR:
6394 : /* User variables should be mentioned in BIND_EXPR_VARS
6395 : and their initializers and sizes walked when walking
6396 : the containing BIND_EXPR. Compiler temporaries are
6397 : handled here. And also normal variables in templates,
6398 : since do_poplevel doesn't build a BIND_EXPR then. */
6399 125054997 : if (VAR_P (TREE_OPERAND (t, 0))
6400 125054997 : && (processing_template_decl
6401 110438617 : || (DECL_ARTIFICIAL (TREE_OPERAND (t, 0))
6402 5506192 : && !TREE_STATIC (TREE_OPERAND (t, 0)))))
6403 : {
6404 13394475 : tree decl = TREE_OPERAND (t, 0);
6405 13394475 : WALK_SUBTREE (TREE_TYPE (decl));
6406 13394475 : WALK_SUBTREE (DECL_INITIAL (decl));
6407 13394445 : WALK_SUBTREE (DECL_SIZE (decl));
6408 13394445 : WALK_SUBTREE (DECL_SIZE_UNIT (decl));
6409 : }
6410 : break;
6411 :
6412 1802125 : case LAMBDA_EXPR:
6413 : /* Don't walk into the body of the lambda, but the capture initializers
6414 : are part of the enclosing context. */
6415 4260353 : for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (t); cap;
6416 2458228 : cap = TREE_CHAIN (cap))
6417 2458228 : WALK_SUBTREE (TREE_VALUE (cap));
6418 : break;
6419 :
6420 3415 : case CO_YIELD_EXPR:
6421 3415 : if (TREE_OPERAND (t, 1))
6422 : /* Operand 1 is the tree for the relevant co_await which has any
6423 : interesting sub-trees. */
6424 601 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6425 : break;
6426 :
6427 27399 : case CO_AWAIT_EXPR:
6428 27399 : if (TREE_OPERAND (t, 1))
6429 : /* Operand 1 is frame variable. */
6430 27211 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6431 27399 : if (TREE_OPERAND (t, 2))
6432 : /* Operand 2 has the initialiser, and we need to walk any subtrees
6433 : there. */
6434 5488 : WALK_SUBTREE (TREE_OPERAND (t, 2));
6435 : break;
6436 :
6437 882 : case CO_RETURN_EXPR:
6438 882 : if (TREE_OPERAND (t, 0))
6439 : {
6440 699 : if (VOID_TYPE_P (TREE_OPERAND (t, 0)))
6441 : /* For void expressions, operand 1 is a trivial call, and any
6442 : interesting subtrees will be part of operand 0. */
6443 0 : WALK_SUBTREE (TREE_OPERAND (t, 0));
6444 699 : else if (TREE_OPERAND (t, 1))
6445 : /* Interesting sub-trees will be in the return_value () call
6446 : arguments. */
6447 657 : WALK_SUBTREE (TREE_OPERAND (t, 1));
6448 : }
6449 : break;
6450 :
6451 590567 : case STATIC_ASSERT:
6452 590567 : WALK_SUBTREE (STATIC_ASSERT_CONDITION (t));
6453 590567 : WALK_SUBTREE (STATIC_ASSERT_MESSAGE (t));
6454 : break;
6455 :
6456 739752115 : case INTEGER_TYPE:
6457 : /* Removed from walk_type_fields in r119481. */
6458 739752115 : WALK_SUBTREE (TYPE_MIN_VALUE (t));
6459 739752115 : WALK_SUBTREE (TYPE_MAX_VALUE (t));
6460 : break;
6461 :
6462 588 : case SPLICE_SCOPE:
6463 588 : WALK_SUBTREE (SPLICE_SCOPE_EXPR (t));
6464 582 : *walk_subtrees_p = 0;
6465 582 : break;
6466 :
6467 : default:
6468 : return NULL_TREE;
6469 : }
6470 :
6471 : /* We didn't find what we were looking for. */
6472 : out:
6473 : return result;
6474 :
6475 : #undef WALK_SUBTREE
6476 : }
6477 :
6478 : /* Like save_expr, but for C++. */
6479 :
6480 : tree
6481 316732 : cp_save_expr (tree expr)
6482 : {
6483 : /* There is no reason to create a SAVE_EXPR within a template; if
6484 : needed, we can create the SAVE_EXPR when instantiating the
6485 : template. Furthermore, the middle-end cannot handle C++-specific
6486 : tree codes. */
6487 316732 : if (processing_template_decl)
6488 : return expr;
6489 :
6490 : /* TARGET_EXPRs are only expanded once. */
6491 245124 : if (TREE_CODE (expr) == TARGET_EXPR)
6492 : return expr;
6493 :
6494 245124 : return save_expr (expr);
6495 : }
6496 :
6497 : /* Initialize tree.cc. */
6498 :
6499 : void
6500 99679 : init_tree (void)
6501 : {
6502 99679 : list_hash_table = hash_table<list_hasher>::create_ggc (61);
6503 99679 : }
6504 :
6505 : /* Returns the kind of special function that DECL (a FUNCTION_DECL)
6506 : is. Note that sfk_none is zero, so this function can be used as a
6507 : predicate to test whether or not DECL is a special function. */
6508 :
6509 : special_function_kind
6510 146731022 : special_function_p (const_tree decl)
6511 : {
6512 : /* Rather than doing all this stuff with magic names, we should
6513 : probably have a field of type `special_function_kind' in
6514 : DECL_LANG_SPECIFIC. */
6515 293462044 : if (DECL_INHERITED_CTOR (decl))
6516 : return sfk_inheriting_constructor;
6517 292751468 : if (DECL_COPY_CONSTRUCTOR_P (decl))
6518 : return sfk_copy_constructor;
6519 265009276 : if (DECL_MOVE_CONSTRUCTOR_P (decl))
6520 : return sfk_move_constructor;
6521 246199664 : if (DECL_CONSTRUCTOR_P (decl))
6522 : return sfk_constructor;
6523 105813841 : if (DECL_ASSIGNMENT_OPERATOR_P (decl)
6524 105813841 : && DECL_OVERLOADED_OPERATOR_IS (decl, NOP_EXPR))
6525 : {
6526 11880007 : if (copy_fn_p (decl))
6527 : return sfk_copy_assignment;
6528 4783533 : if (move_fn_p (decl))
6529 : return sfk_move_assignment;
6530 : }
6531 94138513 : if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
6532 : return sfk_destructor;
6533 54542760 : if (DECL_COMPLETE_DESTRUCTOR_P (decl))
6534 : return sfk_complete_destructor;
6535 41378485 : if (DECL_BASE_DESTRUCTOR_P (decl))
6536 : return sfk_base_destructor;
6537 40474874 : if (DECL_DELETING_DESTRUCTOR_P (decl))
6538 : return sfk_deleting_destructor;
6539 29091960 : if (DECL_CONV_FN_P (decl))
6540 : return sfk_conversion;
6541 29090239 : if (deduction_guide_p (decl))
6542 : return sfk_deduction_guide;
6543 29067019 : if (DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) >= OVL_OP_EQ_EXPR
6544 29067019 : && DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) <= OVL_OP_SPACESHIP_EXPR)
6545 4004182 : return sfk_comparison;
6546 :
6547 : return sfk_none;
6548 : }
6549 :
6550 : /* As above, but only if DECL is a special member function as per 11.3.3
6551 : [special]: default/copy/move ctor, copy/move assignment, or destructor. */
6552 :
6553 : special_function_kind
6554 2845126 : special_memfn_p (const_tree decl)
6555 : {
6556 2845126 : switch (special_function_kind sfk = special_function_p (decl))
6557 : {
6558 2632070 : case sfk_constructor:
6559 2632070 : if (!default_ctor_p (decl))
6560 : break;
6561 : gcc_fallthrough();
6562 : case sfk_copy_constructor:
6563 : case sfk_copy_assignment:
6564 : case sfk_move_assignment:
6565 : case sfk_move_constructor:
6566 : case sfk_destructor:
6567 : return sfk;
6568 :
6569 : default:
6570 : break;
6571 : }
6572 : return sfk_none;
6573 : }
6574 :
6575 : /* Returns nonzero if TYPE is a character type, including wchar_t. */
6576 :
6577 : int
6578 12105358 : char_type_p (tree type)
6579 : {
6580 12105358 : return (same_type_p (type, char_type_node)
6581 10959015 : || same_type_p (type, unsigned_char_type_node)
6582 10908154 : || same_type_p (type, signed_char_type_node)
6583 10907616 : || same_type_p (type, char8_type_node)
6584 10907476 : || same_type_p (type, char16_type_node)
6585 10906966 : || same_type_p (type, char32_type_node)
6586 22896023 : || same_type_p (type, wchar_type_node));
6587 : }
6588 :
6589 : /* Returns the kind of linkage associated with the indicated DECL. The
6590 : value returned is as specified by the language standard; it is
6591 : independent of implementation details regarding template
6592 : instantiation, etc. For example, it is possible that a declaration
6593 : to which this function assigns external linkage would not show up
6594 : as a global symbol when you run `nm' on the resulting object file. */
6595 :
6596 : linkage_kind
6597 463018809 : decl_linkage (tree decl)
6598 : {
6599 : /* This function doesn't attempt to calculate the linkage from first
6600 : principles as given in [basic.link]. Instead, it makes use of
6601 : the fact that we have already set TREE_PUBLIC appropriately, and
6602 : then handles a few special cases. Ideally, we would calculate
6603 : linkage first, and then transform that into a concrete
6604 : implementation. */
6605 :
6606 : /* An explicit type alias has no linkage. Nor do the built-in declarations
6607 : of 'int' and such. */
6608 508276438 : if (TREE_CODE (decl) == TYPE_DECL
6609 508276438 : && !DECL_IMPLICIT_TYPEDEF_P (decl))
6610 : {
6611 : /* But this could be a typedef name for linkage purposes, in which
6612 : case we're interested in the linkage of the main decl. */
6613 975388 : tree type = TREE_TYPE (decl);
6614 975388 : if (type == error_mark_node)
6615 : return lk_none;
6616 975386 : else if (decl == TYPE_NAME (TYPE_MAIN_VARIANT (type))
6617 : /* Likewise for the injected-class-name. */
6618 975386 : || DECL_SELF_REFERENCE_P (decl))
6619 66097 : decl = TYPE_MAIN_DECL (type);
6620 : else
6621 : return lk_none;
6622 : }
6623 :
6624 : /* Namespace-scope entities with no name usually have no linkage. */
6625 507367147 : if (NAMESPACE_SCOPE_P (decl)
6626 966167830 : && (!DECL_NAME (decl) || IDENTIFIER_ANON_P (DECL_NAME (decl))))
6627 : {
6628 3715122 : if (TREE_CODE (decl) == TYPE_DECL && !TYPE_UNNAMED_P (TREE_TYPE (decl)))
6629 : /* This entity has a name for linkage purposes. */;
6630 3699491 : else if (DECL_DECOMPOSITION_P (decl) && DECL_DECOMP_IS_BASE (decl))
6631 : /* Namespace-scope structured bindings can have linkage. */;
6632 3699386 : else if (TREE_CODE (decl) == NAMESPACE_DECL && cxx_dialect >= cxx11)
6633 : /* An anonymous namespace has internal linkage since C++11. */
6634 : return lk_internal;
6635 : else
6636 : return lk_none;
6637 : }
6638 :
6639 : /* Fields and parameters have no linkage. */
6640 503667761 : if (TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == PARM_DECL)
6641 : return lk_none;
6642 :
6643 : /* Things in block scope do not have linkage. */
6644 458165014 : if (decl_function_context (decl))
6645 : return lk_none;
6646 :
6647 : /* Things in class scope have the linkage of their owning class. */
6648 454858038 : if (tree ctype = DECL_CLASS_CONTEXT (decl))
6649 45257629 : return decl_linkage (TYPE_NAME (ctype));
6650 :
6651 : /* Anonymous namespaces don't provide internal linkage in C++98,
6652 : but otherwise consider such declarations to be internal. */
6653 409600409 : if (cxx_dialect >= cxx11 && decl_internal_context_p (decl))
6654 : return lk_internal;
6655 :
6656 : /* Helper to decide if T is lk_module or lk_external. */
6657 818675513 : auto external_or_module = [] (tree t)
6658 : {
6659 409257525 : if (t
6660 409257492 : && DECL_LANG_SPECIFIC (t)
6661 303737769 : && DECL_MODULE_ATTACH_P (t)
6662 409275438 : && !DECL_MODULE_EXPORT_P (t))
6663 7553 : return lk_module;
6664 :
6665 : return lk_external;
6666 : };
6667 :
6668 : /* Templates don't properly propagate TREE_PUBLIC, consider the
6669 : template result instead. Any template that isn't a variable
6670 : or function must be external linkage by this point. */
6671 409417988 : if (TREE_CODE (decl) == TEMPLATE_DECL)
6672 : {
6673 1232792 : decl = DECL_TEMPLATE_RESULT (decl);
6674 1232792 : if (!decl || !VAR_OR_FUNCTION_DECL_P (decl))
6675 568494 : return external_or_module (decl);
6676 : }
6677 :
6678 : /* Things that are TREE_PUBLIC have external linkage. */
6679 408849494 : if (TREE_PUBLIC (decl))
6680 321177928 : return external_or_module (decl);
6681 :
6682 : /* All types have external linkage in C++98, since anonymous namespaces
6683 : didn't explicitly confer internal linkage. */
6684 87671566 : if (TREE_CODE (decl) == TYPE_DECL && cxx_dialect < cxx11)
6685 4 : return external_or_module (decl);
6686 :
6687 : /* Variables or function decls not marked as TREE_PUBLIC might still
6688 : be external linkage, such as for template instantiations on targets
6689 : without weak symbols, decls referring to internal-linkage entities,
6690 : or compiler-generated entities; in such cases, decls really meant to
6691 : have internal linkage will have DECL_THIS_STATIC set. */
6692 87671562 : if (VAR_OR_FUNCTION_DECL_P (decl) && !DECL_THIS_STATIC (decl))
6693 87511099 : return external_or_module (decl);
6694 :
6695 : /* Everything else has internal linkage. */
6696 : return lk_internal;
6697 : }
6698 :
6699 : /* Returns the storage duration of the object or reference associated with
6700 : the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
6701 :
6702 : duration_kind
6703 59888297 : decl_storage_duration (tree decl)
6704 : {
6705 59888297 : if (TREE_CODE (decl) == PARM_DECL)
6706 : return dk_auto;
6707 59888285 : if (TREE_CODE (decl) == FUNCTION_DECL)
6708 : return dk_static;
6709 59888285 : gcc_assert (VAR_P (decl));
6710 59888285 : if (!TREE_STATIC (decl)
6711 59888285 : && !DECL_EXTERNAL (decl))
6712 : return dk_auto;
6713 35912241 : if (CP_DECL_THREAD_LOCAL_P (decl))
6714 20299 : return dk_thread;
6715 : return dk_static;
6716 : }
6717 :
6718 : /* EXP is an expression that we want to pre-evaluate. Returns (in
6719 : *INITP) an expression that will perform the pre-evaluation. The
6720 : value returned by this function is a side-effect free expression
6721 : equivalent to the pre-evaluated expression. Callers must ensure
6722 : that *INITP is evaluated before EXP.
6723 :
6724 : Note that if EXPR is a glvalue, the return value is a glvalue denoting the
6725 : same address; this function does not guard against modification of the
6726 : stored value like save_expr or get_target_expr do. */
6727 :
6728 : tree
6729 5657555 : stabilize_expr (tree exp, tree* initp)
6730 : {
6731 5657555 : tree init_expr;
6732 :
6733 5657555 : if (!TREE_SIDE_EFFECTS (exp))
6734 : init_expr = NULL_TREE;
6735 892439 : else if (VOID_TYPE_P (TREE_TYPE (exp)))
6736 : {
6737 0 : init_expr = exp;
6738 0 : exp = void_node;
6739 : }
6740 : /* There are no expressions with REFERENCE_TYPE, but there can be call
6741 : arguments with such a type; just treat it as a pointer. */
6742 892439 : else if (TYPE_REF_P (TREE_TYPE (exp))
6743 892305 : || SCALAR_TYPE_P (TREE_TYPE (exp))
6744 892485 : || !glvalue_p (exp))
6745 : {
6746 892433 : init_expr = get_target_expr (exp);
6747 892433 : exp = TARGET_EXPR_SLOT (init_expr);
6748 892433 : if (CLASS_TYPE_P (TREE_TYPE (exp)))
6749 9 : exp = move (exp);
6750 : else
6751 892424 : exp = rvalue (exp);
6752 : }
6753 : else
6754 : {
6755 6 : bool xval = !lvalue_p (exp);
6756 6 : exp = cp_build_addr_expr (exp, tf_warning_or_error);
6757 6 : init_expr = get_target_expr (exp);
6758 6 : exp = TARGET_EXPR_SLOT (init_expr);
6759 6 : exp = cp_build_fold_indirect_ref (exp);
6760 6 : if (xval)
6761 0 : exp = move (exp);
6762 : }
6763 5657555 : *initp = init_expr;
6764 :
6765 5657555 : gcc_assert (!TREE_SIDE_EFFECTS (exp) || TREE_THIS_VOLATILE (exp));
6766 5657555 : return exp;
6767 : }
6768 :
6769 : /* Add NEW_EXPR, an expression whose value we don't care about, after the
6770 : similar expression ORIG. */
6771 :
6772 : tree
6773 1301868 : add_stmt_to_compound (tree orig, tree new_expr)
6774 : {
6775 1301868 : if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
6776 : return orig;
6777 654459 : if (!orig || !TREE_SIDE_EFFECTS (orig))
6778 : return new_expr;
6779 12579 : return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
6780 : }
6781 :
6782 : /* Like stabilize_expr, but for a call whose arguments we want to
6783 : pre-evaluate. CALL is modified in place to use the pre-evaluated
6784 : arguments, while, upon return, *INITP contains an expression to
6785 : compute the arguments. */
6786 :
6787 : void
6788 643253 : stabilize_call (tree call, tree *initp)
6789 : {
6790 643253 : tree inits = NULL_TREE;
6791 643253 : int i;
6792 643253 : int nargs = call_expr_nargs (call);
6793 :
6794 643253 : if (call == error_mark_node || processing_template_decl)
6795 : {
6796 39 : *initp = NULL_TREE;
6797 39 : return;
6798 : }
6799 :
6800 643214 : gcc_assert (TREE_CODE (call) == CALL_EXPR);
6801 :
6802 1929723 : for (i = 0; i < nargs; i++)
6803 : {
6804 1286509 : tree init;
6805 1286509 : CALL_EXPR_ARG (call, i) =
6806 1286509 : stabilize_expr (CALL_EXPR_ARG (call, i), &init);
6807 1286509 : inits = add_stmt_to_compound (inits, init);
6808 : }
6809 :
6810 643214 : *initp = inits;
6811 : }
6812 :
6813 : /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
6814 : to pre-evaluate. CALL is modified in place to use the pre-evaluated
6815 : arguments, while, upon return, *INITP contains an expression to
6816 : compute the arguments. */
6817 :
6818 : static void
6819 0 : stabilize_aggr_init (tree call, tree *initp)
6820 : {
6821 0 : tree inits = NULL_TREE;
6822 0 : int i;
6823 0 : int nargs = aggr_init_expr_nargs (call);
6824 :
6825 0 : if (call == error_mark_node)
6826 : return;
6827 :
6828 0 : gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
6829 :
6830 0 : for (i = 0; i < nargs; i++)
6831 : {
6832 0 : tree init;
6833 0 : AGGR_INIT_EXPR_ARG (call, i) =
6834 0 : stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
6835 0 : inits = add_stmt_to_compound (inits, init);
6836 : }
6837 :
6838 0 : *initp = inits;
6839 : }
6840 :
6841 : /* Like stabilize_expr, but for an initialization.
6842 :
6843 : If the initialization is for an object of class type, this function
6844 : takes care not to introduce additional temporaries.
6845 :
6846 : Returns TRUE iff the expression was successfully pre-evaluated,
6847 : i.e., if INIT is now side-effect free, except for, possibly, a
6848 : single call to a constructor. */
6849 :
6850 : bool
6851 0 : stabilize_init (tree init, tree *initp)
6852 : {
6853 0 : tree t = init;
6854 :
6855 0 : *initp = NULL_TREE;
6856 :
6857 0 : if (t == error_mark_node || processing_template_decl)
6858 : return true;
6859 :
6860 0 : if (TREE_CODE (t) == INIT_EXPR)
6861 0 : t = TREE_OPERAND (t, 1);
6862 0 : if (TREE_CODE (t) == TARGET_EXPR)
6863 0 : t = TARGET_EXPR_INITIAL (t);
6864 :
6865 : /* If the RHS can be stabilized without breaking copy elision, stabilize
6866 : it. We specifically don't stabilize class prvalues here because that
6867 : would mean an extra copy, but they might be stabilized below. */
6868 0 : if (TREE_CODE (init) == INIT_EXPR
6869 0 : && TREE_CODE (t) != CONSTRUCTOR
6870 0 : && TREE_CODE (t) != AGGR_INIT_EXPR
6871 0 : && (SCALAR_TYPE_P (TREE_TYPE (t))
6872 0 : || glvalue_p (t)))
6873 : {
6874 0 : TREE_OPERAND (init, 1) = stabilize_expr (t, initp);
6875 0 : return true;
6876 : }
6877 :
6878 0 : if (TREE_CODE (t) == COMPOUND_EXPR
6879 0 : && TREE_CODE (init) == INIT_EXPR)
6880 : {
6881 0 : tree last = expr_last (t);
6882 : /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */
6883 0 : if (!TREE_SIDE_EFFECTS (last))
6884 : {
6885 0 : *initp = t;
6886 0 : TREE_OPERAND (init, 1) = last;
6887 0 : return true;
6888 : }
6889 : }
6890 :
6891 0 : if (TREE_CODE (t) == CONSTRUCTOR)
6892 : {
6893 : /* Aggregate initialization: stabilize each of the field
6894 : initializers. */
6895 0 : unsigned i;
6896 0 : constructor_elt *ce;
6897 0 : bool good = true;
6898 0 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
6899 0 : for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
6900 : {
6901 0 : tree type = TREE_TYPE (ce->value);
6902 0 : tree subinit;
6903 0 : if (TYPE_REF_P (type)
6904 0 : || SCALAR_TYPE_P (type))
6905 0 : ce->value = stabilize_expr (ce->value, &subinit);
6906 0 : else if (!stabilize_init (ce->value, &subinit))
6907 0 : good = false;
6908 0 : *initp = add_stmt_to_compound (*initp, subinit);
6909 : }
6910 : return good;
6911 : }
6912 :
6913 0 : if (TREE_CODE (t) == CALL_EXPR)
6914 : {
6915 0 : stabilize_call (t, initp);
6916 0 : return true;
6917 : }
6918 :
6919 0 : if (TREE_CODE (t) == AGGR_INIT_EXPR)
6920 : {
6921 0 : stabilize_aggr_init (t, initp);
6922 0 : return true;
6923 : }
6924 :
6925 : /* The initialization is being performed via a bitwise copy -- and
6926 : the item copied may have side effects. */
6927 0 : return !TREE_SIDE_EFFECTS (init);
6928 : }
6929 :
6930 : /* Returns true if a cast to TYPE may appear in an integral constant
6931 : expression. */
6932 :
6933 : bool
6934 93290292 : cast_valid_in_integral_constant_expression_p (tree type)
6935 : {
6936 93290292 : return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
6937 66718072 : || cxx_dialect >= cxx11
6938 473078 : || dependent_type_p (type)
6939 93667666 : || type == error_mark_node);
6940 : }
6941 :
6942 : /* Return true if we need to fix linkage information of DECL. */
6943 :
6944 : static bool
6945 75427 : cp_fix_function_decl_p (tree decl)
6946 : {
6947 : /* Skip if DECL is not externally visible. */
6948 75427 : if (!TREE_PUBLIC (decl))
6949 : return false;
6950 :
6951 : /* We need to fix DECL if it a appears to be exported but with no
6952 : function body. Thunks do not have CFGs and we may need to
6953 : handle them specially later. */
6954 73020 : if (!gimple_has_body_p (decl)
6955 27278 : && !DECL_THUNK_P (decl)
6956 99912 : && !DECL_EXTERNAL (decl))
6957 : {
6958 12668 : struct cgraph_node *node = cgraph_node::get (decl);
6959 :
6960 : /* Don't fix same_body aliases. Although they don't have their own
6961 : CFG, they share it with what they alias to. */
6962 12668 : if (!node || !node->alias || !node->num_references ())
6963 : return true;
6964 : }
6965 :
6966 : return false;
6967 : }
6968 :
6969 : /* Clean the C++ specific parts of the tree T. */
6970 :
6971 : void
6972 734248 : cp_free_lang_data (tree t)
6973 : {
6974 734248 : if (FUNC_OR_METHOD_TYPE_P (t))
6975 : {
6976 : /* Default args are not interesting anymore. */
6977 60385 : tree argtypes = TYPE_ARG_TYPES (t);
6978 217380 : while (argtypes)
6979 : {
6980 156995 : TREE_PURPOSE (argtypes) = 0;
6981 156995 : argtypes = TREE_CHAIN (argtypes);
6982 : }
6983 : }
6984 673863 : else if (TREE_CODE (t) == FUNCTION_DECL
6985 673863 : && cp_fix_function_decl_p (t))
6986 : {
6987 : /* If T is used in this translation unit at all, the definition
6988 : must exist somewhere else since we have decided to not emit it
6989 : in this TU. So make it an external reference. */
6990 6648 : DECL_EXTERNAL (t) = 1;
6991 6648 : TREE_STATIC (t) = 0;
6992 : }
6993 734248 : if (TREE_CODE (t) == NAMESPACE_DECL)
6994 : /* We do not need the leftover chaining of namespaces from the
6995 : binding level. */
6996 1660 : DECL_CHAIN (t) = NULL_TREE;
6997 734248 : }
6998 :
6999 : /* Stub for c-common. Please keep in sync with c-decl.cc.
7000 : FIXME: If address space support is target specific, then this
7001 : should be a C target hook. But currently this is not possible,
7002 : because this function is called via REGISTER_TARGET_PRAGMAS. */
7003 : void
7004 199358 : c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
7005 : {
7006 199358 : }
7007 :
7008 : /* Return the number of operands in T that we care about for things like
7009 : mangling. */
7010 :
7011 : int
7012 621528525 : cp_tree_operand_length (const_tree t)
7013 : {
7014 621528525 : enum tree_code code = TREE_CODE (t);
7015 :
7016 621528525 : if (TREE_CODE_CLASS (code) == tcc_vl_exp)
7017 63411141 : return VL_EXP_OPERAND_LENGTH (t);
7018 :
7019 558117384 : return cp_tree_code_length (code);
7020 : }
7021 :
7022 : /* Like cp_tree_operand_length, but takes a tree_code CODE. */
7023 :
7024 : int
7025 564410918 : cp_tree_code_length (enum tree_code code)
7026 : {
7027 564410918 : gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
7028 :
7029 564410918 : switch (code)
7030 : {
7031 : case PREINCREMENT_EXPR:
7032 : case PREDECREMENT_EXPR:
7033 : case POSTINCREMENT_EXPR:
7034 : case POSTDECREMENT_EXPR:
7035 : return 1;
7036 :
7037 1141898 : case ARRAY_REF:
7038 1141898 : return 2;
7039 :
7040 : case EXPR_PACK_EXPANSION:
7041 : return 1;
7042 :
7043 560931480 : default:
7044 560931480 : return TREE_CODE_LENGTH (code);
7045 : }
7046 : }
7047 :
7048 : /* Implement -Wzero_as_null_pointer_constant. Return true if the
7049 : conditions for the warning hold, false otherwise. */
7050 : bool
7051 7261017 : maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
7052 : {
7053 7261017 : if (c_inhibit_evaluation_warnings == 0
7054 13523689 : && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
7055 : {
7056 2586417 : warning_at (loc, OPT_Wzero_as_null_pointer_constant,
7057 : "zero as null pointer constant");
7058 2586417 : return true;
7059 : }
7060 : return false;
7061 : }
7062 :
7063 : /* FNDECL is a function declaration whose type may have been altered by
7064 : adding extra parameters such as this, in-charge, or VTT. When this
7065 : takes place, the positional arguments supplied by the user (as in the
7066 : 'format' attribute arguments) may refer to the wrong argument. This
7067 : function returns an integer indicating how many arguments should be
7068 : skipped. */
7069 :
7070 : int
7071 37325028 : maybe_adjust_arg_pos_for_attribute (const_tree fndecl)
7072 : {
7073 37325028 : if (!fndecl)
7074 : return 0;
7075 7245377 : int n = num_artificial_parms_for (fndecl);
7076 : /* The manual states that it's the user's responsibility to account
7077 : for the implicit this parameter. */
7078 7245377 : return n > 0 ? n - 1 : 0;
7079 : }
7080 :
7081 : /* True if ATTR is annotation. */
7082 :
7083 : bool
7084 55793607 : annotation_p (tree attr)
7085 : {
7086 55793607 : return is_attribute_p ("annotation ", get_attribute_name (attr));
7087 : }
7088 :
7089 : /* Lookup the annotation in ATTR, if present. */
7090 :
7091 : tree
7092 66085 : lookup_annotation (tree attr)
7093 : {
7094 66085 : return lookup_attribute ("internal ", "annotation ", attr);
7095 : }
7096 :
7097 :
7098 : /* Release memory we no longer need after parsing. */
7099 : void
7100 98071 : cp_tree_c_finish_parsing ()
7101 : {
7102 98071 : if (previous_class_level)
7103 69087 : invalidate_class_lookup_cache ();
7104 98071 : deleted_copy_types = NULL;
7105 98071 : }
7106 :
7107 : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
7108 : /* Complain that some language-specific thing hanging off a tree
7109 : node has been accessed improperly. */
7110 :
7111 : void
7112 0 : lang_check_failed (const char* file, int line, const char* function)
7113 : {
7114 0 : internal_error ("%<lang_*%> check: failed in %s, at %s:%d",
7115 : function, trim_filename (file), line);
7116 : }
7117 : #endif /* ENABLE_TREE_CHECKING */
7118 :
7119 : #if CHECKING_P
7120 :
7121 : namespace selftest {
7122 :
7123 : /* Verify that lvalue_kind () works, for various expressions,
7124 : and that location wrappers don't affect the results. */
7125 :
7126 : static void
7127 1 : test_lvalue_kind ()
7128 : {
7129 1 : location_t loc = BUILTINS_LOCATION;
7130 :
7131 : /* Verify constants and parameters, without and with
7132 : location wrappers. */
7133 1 : tree int_cst = build_int_cst (integer_type_node, 42);
7134 1 : ASSERT_EQ (clk_none, lvalue_kind (int_cst));
7135 :
7136 1 : tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
7137 1 : ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
7138 1 : ASSERT_EQ (clk_none, lvalue_kind (wrapped_int_cst));
7139 :
7140 1 : tree string_lit = build_string (4, "foo");
7141 1 : TREE_TYPE (string_lit) = char_array_type_node;
7142 1 : string_lit = fix_string_type (string_lit);
7143 1 : ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (string_lit));
7144 :
7145 1 : tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
7146 1 : ASSERT_TRUE (location_wrapper_p (wrapped_string_lit));
7147 1 : ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (wrapped_string_lit));
7148 :
7149 1 : tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL,
7150 : get_identifier ("some_parm"),
7151 : integer_type_node);
7152 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (parm));
7153 :
7154 1 : tree wrapped_parm = maybe_wrap_with_location (parm, loc);
7155 1 : ASSERT_TRUE (location_wrapper_p (wrapped_parm));
7156 1 : ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_parm));
7157 :
7158 : /* Verify that lvalue_kind of std::move on a parm isn't
7159 : affected by location wrappers. */
7160 1 : tree rvalue_ref_of_parm = move (parm);
7161 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm));
7162 1 : tree rvalue_ref_of_wrapped_parm = move (wrapped_parm);
7163 1 : ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm));
7164 :
7165 : /* Verify lvalue_p. */
7166 1 : ASSERT_FALSE (lvalue_p (int_cst));
7167 1 : ASSERT_FALSE (lvalue_p (wrapped_int_cst));
7168 1 : ASSERT_TRUE (lvalue_p (parm));
7169 1 : ASSERT_TRUE (lvalue_p (wrapped_parm));
7170 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm));
7171 1 : ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm));
7172 1 : }
7173 :
7174 : /* Run all of the selftests within this file. */
7175 :
7176 : void
7177 1 : cp_tree_cc_tests ()
7178 : {
7179 1 : test_lvalue_kind ();
7180 1 : }
7181 :
7182 : } // namespace selftest
7183 :
7184 : #endif /* #if CHECKING_P */
7185 :
7186 :
7187 : #include "gt-cp-tree.h"
|