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