1 /* Language-dependent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GCC.
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)
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.
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/>. */
23 #include "coretypes.h"
26 #include "stor-layout.h"
27 #include "print-tree.h"
28 #include "tree-iterator.h"
31 #include "tree-inline.h"
35 #include "splay-tree.h"
36 #include "hash-table.h"
37 #include "gimple-expr.h"
40 static tree
bot_manip (tree
*, int *, void *);
41 static tree
bot_replace (tree
*, int *, void *);
42 static int list_hash_eq (const void *, const void *);
43 static hashval_t
list_hash_pieces (tree
, tree
, tree
);
44 static hashval_t
list_hash (const void *);
45 static tree
build_target_expr (tree
, tree
, tsubst_flags_t
);
46 static tree
count_trees_r (tree
*, int *, void *);
47 static tree
verify_stmt_tree_r (tree
*, int *, void *);
48 static tree
build_local_temp (tree
);
50 static tree
handle_java_interface_attribute (tree
*, tree
, tree
, int, bool *);
51 static tree
handle_com_interface_attribute (tree
*, tree
, tree
, int, bool *);
52 static tree
handle_init_priority_attribute (tree
*, tree
, tree
, int, bool *);
53 static tree
handle_abi_tag_attribute (tree
*, tree
, tree
, int, bool *);
55 /* If REF is an lvalue, returns the kind of lvalue that REF is.
56 Otherwise, returns clk_none. */
59 lvalue_kind (const_tree ref
)
61 cp_lvalue_kind op1_lvalue_kind
= clk_none
;
62 cp_lvalue_kind op2_lvalue_kind
= clk_none
;
64 /* Expressions of reference type are sometimes wrapped in
65 INDIRECT_REFs. INDIRECT_REFs are just internal compiler
66 representation, not part of the language, so we have to look
68 if (REFERENCE_REF_P (ref
))
69 return lvalue_kind (TREE_OPERAND (ref
, 0));
72 && TREE_CODE (TREE_TYPE (ref
)) == REFERENCE_TYPE
)
74 /* unnamed rvalue references are rvalues */
75 if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref
))
76 && TREE_CODE (ref
) != PARM_DECL
78 && TREE_CODE (ref
) != COMPONENT_REF
79 /* Functions are always lvalues. */
80 && TREE_CODE (TREE_TYPE (TREE_TYPE (ref
))) != FUNCTION_TYPE
)
83 /* lvalue references and named rvalue references are lvalues. */
87 if (ref
== current_class_ptr
)
90 switch (TREE_CODE (ref
))
94 /* preincrements and predecrements are valid lvals, provided
95 what they refer to are valid lvals. */
96 case PREINCREMENT_EXPR
:
97 case PREDECREMENT_EXPR
:
99 case WITH_CLEANUP_EXPR
:
102 return lvalue_kind (TREE_OPERAND (ref
, 0));
106 if (TREE_CODE (ref
) == MEMBER_REF
)
107 op1_lvalue_kind
= clk_ordinary
;
109 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
110 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref
, 1))))
111 op1_lvalue_kind
= clk_none
;
112 return op1_lvalue_kind
;
115 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
116 /* Look at the member designator. */
117 if (!op1_lvalue_kind
)
119 else if (is_overloaded_fn (TREE_OPERAND (ref
, 1)))
120 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
121 situations. If we're seeing a COMPONENT_REF, it's a non-static
122 member, so it isn't an lvalue. */
123 op1_lvalue_kind
= clk_none
;
124 else if (TREE_CODE (TREE_OPERAND (ref
, 1)) != FIELD_DECL
)
125 /* This can be IDENTIFIER_NODE in a template. */;
126 else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref
, 1)))
128 /* Clear the ordinary bit. If this object was a class
129 rvalue we want to preserve that information. */
130 op1_lvalue_kind
&= ~clk_ordinary
;
131 /* The lvalue is for a bitfield. */
132 op1_lvalue_kind
|= clk_bitfield
;
134 else if (DECL_PACKED (TREE_OPERAND (ref
, 1)))
135 op1_lvalue_kind
|= clk_packed
;
137 return op1_lvalue_kind
;
140 case COMPOUND_LITERAL_EXPR
:
144 /* CONST_DECL without TREE_STATIC are enumeration values and
145 thus not lvalues. With TREE_STATIC they are used by ObjC++
146 in objc_build_string_object and need to be considered as
148 if (! TREE_STATIC (ref
))
151 if (TREE_READONLY (ref
) && ! TREE_STATIC (ref
)
152 && DECL_LANG_SPECIFIC (ref
)
153 && DECL_IN_AGGR_P (ref
))
158 case ARRAY_NOTATION_REF
:
163 /* A scope ref in a template, left as SCOPE_REF to support later
166 gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref
)));
168 tree op
= TREE_OPERAND (ref
, 1);
169 if (TREE_CODE (op
) == FIELD_DECL
)
170 return (DECL_C_BIT_FIELD (op
) ? clk_bitfield
: clk_ordinary
);
172 return lvalue_kind (op
);
177 /* Disallow <? and >? as lvalues if either argument side-effects. */
178 if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref
, 0))
179 || TREE_SIDE_EFFECTS (TREE_OPERAND (ref
, 1)))
181 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 0));
182 op2_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 1));
186 op1_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 1)
187 ? TREE_OPERAND (ref
, 1)
188 : TREE_OPERAND (ref
, 0));
189 op2_lvalue_kind
= lvalue_kind (TREE_OPERAND (ref
, 2));
197 return lvalue_kind (TREE_OPERAND (ref
, 1));
203 return (CLASS_TYPE_P (TREE_TYPE (ref
)) ? clk_class
: clk_none
);
206 /* We can see calls outside of TARGET_EXPR in templates. */
207 if (CLASS_TYPE_P (TREE_TYPE (ref
)))
212 /* All functions (except non-static-member functions) are
214 return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref
)
215 ? clk_none
: clk_ordinary
);
218 /* We now represent a reference to a single static member function
220 /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
221 its argument unmodified and we assign it to a const_tree. */
222 return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref
)));
224 case NON_DEPENDENT_EXPR
:
225 /* We just return clk_ordinary for NON_DEPENDENT_EXPR in C++98, but
226 in C++11 lvalues don't bind to rvalue references, so we need to
227 work harder to avoid bogus errors (c++/44870). */
228 if (cxx_dialect
< cxx11
)
231 return lvalue_kind (TREE_OPERAND (ref
, 0));
234 if (!TREE_TYPE (ref
))
236 if (CLASS_TYPE_P (TREE_TYPE (ref
)))
241 /* If one operand is not an lvalue at all, then this expression is
243 if (!op1_lvalue_kind
|| !op2_lvalue_kind
)
246 /* Otherwise, it's an lvalue, and it has all the odd properties
247 contributed by either operand. */
248 op1_lvalue_kind
= op1_lvalue_kind
| op2_lvalue_kind
;
249 /* It's not an ordinary lvalue if it involves any other kind. */
250 if ((op1_lvalue_kind
& ~clk_ordinary
) != clk_none
)
251 op1_lvalue_kind
&= ~clk_ordinary
;
252 /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
253 A COND_EXPR of those should be wrapped in a TARGET_EXPR. */
254 if ((op1_lvalue_kind
& (clk_rvalueref
|clk_class
))
255 && (op1_lvalue_kind
& (clk_bitfield
|clk_packed
)))
256 op1_lvalue_kind
= clk_none
;
257 return op1_lvalue_kind
;
260 /* Returns the kind of lvalue that REF is, in the sense of
261 [basic.lval]. This function should really be named lvalue_p; it
262 computes the C++ definition of lvalue. */
265 real_lvalue_p (const_tree ref
)
267 cp_lvalue_kind kind
= lvalue_kind (ref
);
268 if (kind
& (clk_rvalueref
|clk_class
))
274 /* This differs from real_lvalue_p in that class rvalues are considered
278 lvalue_p (const_tree ref
)
280 return (lvalue_kind (ref
) != clk_none
);
283 /* This differs from real_lvalue_p in that rvalues formed by dereferencing
284 rvalue references are considered rvalues. */
287 lvalue_or_rvalue_with_address_p (const_tree ref
)
289 cp_lvalue_kind kind
= lvalue_kind (ref
);
290 if (kind
& clk_class
)
293 return (kind
!= clk_none
);
296 /* Returns true if REF is an xvalue, false otherwise. */
299 xvalue_p (const_tree ref
)
301 return (lvalue_kind (ref
) == clk_rvalueref
);
304 /* Test whether DECL is a builtin that may appear in a
305 constant-expression. */
308 builtin_valid_in_constant_expr_p (const_tree decl
)
310 /* At present BUILT_IN_CONSTANT_P is the only builtin we're allowing
311 in constant-expressions. We may want to add other builtins later. */
312 return DECL_IS_BUILTIN_CONSTANT_P (decl
);
315 /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */
318 build_target_expr (tree decl
, tree value
, tsubst_flags_t complain
)
321 tree type
= TREE_TYPE (decl
);
323 #ifdef ENABLE_CHECKING
324 gcc_assert (VOID_TYPE_P (TREE_TYPE (value
))
325 || TREE_TYPE (decl
) == TREE_TYPE (value
)
326 /* On ARM ctors return 'this'. */
327 || (TYPE_PTR_P (TREE_TYPE (value
))
328 && TREE_CODE (value
) == CALL_EXPR
)
329 || useless_type_conversion_p (TREE_TYPE (decl
),
333 t
= cxx_maybe_build_cleanup (decl
, complain
);
334 if (t
== error_mark_node
)
335 return error_mark_node
;
336 t
= build4 (TARGET_EXPR
, type
, decl
, value
, t
, NULL_TREE
);
337 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
338 ignore the TARGET_EXPR. If there really turn out to be no
339 side-effects, then the optimizer should be able to get rid of
340 whatever code is generated anyhow. */
341 TREE_SIDE_EFFECTS (t
) = 1;
346 /* Return an undeclared local temporary of type TYPE for use in building a
350 build_local_temp (tree type
)
352 tree slot
= build_decl (input_location
,
353 VAR_DECL
, NULL_TREE
, type
);
354 DECL_ARTIFICIAL (slot
) = 1;
355 DECL_IGNORED_P (slot
) = 1;
356 DECL_CONTEXT (slot
) = current_function_decl
;
357 layout_decl (slot
, 0);
361 /* Set various status flags when building an AGGR_INIT_EXPR object T. */
364 process_aggr_init_operands (tree t
)
368 side_effects
= TREE_SIDE_EFFECTS (t
);
372 n
= TREE_OPERAND_LENGTH (t
);
373 for (i
= 1; i
< n
; i
++)
375 tree op
= TREE_OPERAND (t
, i
);
376 if (op
&& TREE_SIDE_EFFECTS (op
))
383 TREE_SIDE_EFFECTS (t
) = side_effects
;
386 /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
387 FN, and SLOT. NARGS is the number of call arguments which are specified
388 as a tree array ARGS. */
391 build_aggr_init_array (tree return_type
, tree fn
, tree slot
, int nargs
,
397 t
= build_vl_exp (AGGR_INIT_EXPR
, nargs
+ 3);
398 TREE_TYPE (t
) = return_type
;
399 AGGR_INIT_EXPR_FN (t
) = fn
;
400 AGGR_INIT_EXPR_SLOT (t
) = slot
;
401 for (i
= 0; i
< nargs
; i
++)
402 AGGR_INIT_EXPR_ARG (t
, i
) = args
[i
];
403 process_aggr_init_operands (t
);
407 /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
408 target. TYPE is the type to be initialized.
410 Build an AGGR_INIT_EXPR to represent the initialization. This function
411 differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
412 to initialize another object, whereas a TARGET_EXPR can either
413 initialize another object or create its own temporary object, and as a
414 result building up a TARGET_EXPR requires that the type's destructor be
418 build_aggr_init_expr (tree type
, tree init
)
425 /* Don't build AGGR_INIT_EXPR in a template. */
426 if (processing_template_decl
)
429 if (TREE_CODE (init
) == CALL_EXPR
)
430 fn
= CALL_EXPR_FN (init
);
431 else if (TREE_CODE (init
) == AGGR_INIT_EXPR
)
432 fn
= AGGR_INIT_EXPR_FN (init
);
434 return convert (type
, init
);
436 is_ctor
= (TREE_CODE (fn
) == ADDR_EXPR
437 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
438 && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn
, 0)));
440 /* We split the CALL_EXPR into its function and its arguments here.
441 Then, in expand_expr, we put them back together. The reason for
442 this is that this expression might be a default argument
443 expression. In that case, we need a new temporary every time the
444 expression is used. That's what break_out_target_exprs does; it
445 replaces every AGGR_INIT_EXPR with a copy that uses a fresh
446 temporary slot. Then, expand_expr builds up a call-expression
447 using the new slot. */
449 /* If we don't need to use a constructor to create an object of this
450 type, don't mess with AGGR_INIT_EXPR. */
451 if (is_ctor
|| TREE_ADDRESSABLE (type
))
453 slot
= build_local_temp (type
);
455 if (TREE_CODE(init
) == CALL_EXPR
)
456 rval
= build_aggr_init_array (void_type_node
, fn
, slot
,
457 call_expr_nargs (init
),
458 CALL_EXPR_ARGP (init
));
460 rval
= build_aggr_init_array (void_type_node
, fn
, slot
,
461 aggr_init_expr_nargs (init
),
462 AGGR_INIT_EXPR_ARGP (init
));
463 TREE_SIDE_EFFECTS (rval
) = 1;
464 AGGR_INIT_VIA_CTOR_P (rval
) = is_ctor
;
465 TREE_NOTHROW (rval
) = TREE_NOTHROW (init
);
466 CALL_EXPR_LIST_INIT_P (rval
) = CALL_EXPR_LIST_INIT_P (init
);
474 /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
475 target. TYPE is the type that this initialization should appear to
478 Build an encapsulation of the initialization to perform
479 and return it so that it can be processed by language-independent
480 and language-specific expression expanders. */
483 build_cplus_new (tree type
, tree init
, tsubst_flags_t complain
)
485 tree rval
= build_aggr_init_expr (type
, init
);
488 if (!complete_type_or_maybe_complain (type
, init
, complain
))
489 return error_mark_node
;
491 /* Make sure that we're not trying to create an instance of an
493 if (abstract_virtuals_error_sfinae (NULL_TREE
, type
, complain
))
494 return error_mark_node
;
496 if (TREE_CODE (rval
) == AGGR_INIT_EXPR
)
497 slot
= AGGR_INIT_EXPR_SLOT (rval
);
498 else if (TREE_CODE (rval
) == CALL_EXPR
499 || TREE_CODE (rval
) == CONSTRUCTOR
)
500 slot
= build_local_temp (type
);
504 rval
= build_target_expr (slot
, rval
, complain
);
506 if (rval
!= error_mark_node
)
507 TARGET_EXPR_IMPLICIT_P (rval
) = 1;
512 /* Subroutine of build_vec_init_expr: Build up a single element
513 intialization as a proxy for the full array initialization to get things
514 marked as used and any appropriate diagnostics.
516 Since we're deferring building the actual constructor calls until
517 gimplification time, we need to build one now and throw it away so
518 that the relevant constructor gets mark_used before cgraph decides
519 what functions are needed. Here we assume that init is either
520 NULL_TREE, void_type_node (indicating value-initialization), or
521 another array to copy. */
524 build_vec_init_elt (tree type
, tree init
, tsubst_flags_t complain
)
526 tree inner_type
= strip_array_types (type
);
527 vec
<tree
, va_gc
> *argvec
;
529 if (integer_zerop (array_type_nelts_total (type
))
530 || !CLASS_TYPE_P (inner_type
))
531 /* No interesting initialization to do. */
532 return integer_zero_node
;
533 else if (init
== void_type_node
)
534 return build_value_init (inner_type
, complain
);
536 gcc_assert (init
== NULL_TREE
537 || (same_type_ignoring_top_level_qualifiers_p
538 (type
, TREE_TYPE (init
))));
540 argvec
= make_tree_vector ();
543 tree init_type
= strip_array_types (TREE_TYPE (init
));
544 tree dummy
= build_dummy_object (init_type
);
545 if (!real_lvalue_p (init
))
546 dummy
= move (dummy
);
547 argvec
->quick_push (dummy
);
549 init
= build_special_member_call (NULL_TREE
, complete_ctor_identifier
,
550 &argvec
, inner_type
, LOOKUP_NORMAL
,
552 release_tree_vector (argvec
);
554 /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But
555 we don't want one here because we aren't creating a temporary. */
556 if (TREE_CODE (init
) == TARGET_EXPR
)
557 init
= TARGET_EXPR_INITIAL (init
);
562 /* Return a TARGET_EXPR which expresses the initialization of an array to
563 be named later, either default-initialization or copy-initialization
564 from another array of the same type. */
567 build_vec_init_expr (tree type
, tree init
, tsubst_flags_t complain
)
570 bool value_init
= false;
571 tree elt_init
= build_vec_init_elt (type
, init
, complain
);
573 if (init
== void_type_node
)
579 slot
= build_local_temp (type
);
580 init
= build2 (VEC_INIT_EXPR
, type
, slot
, init
);
581 TREE_SIDE_EFFECTS (init
) = true;
582 SET_EXPR_LOCATION (init
, input_location
);
584 if (cxx_dialect
>= cxx11
585 && potential_constant_expression (elt_init
))
586 VEC_INIT_EXPR_IS_CONSTEXPR (init
) = true;
587 VEC_INIT_EXPR_VALUE_INIT (init
) = value_init
;
592 /* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context
593 that requires a constant expression. */
596 diagnose_non_constexpr_vec_init (tree expr
)
598 tree type
= TREE_TYPE (VEC_INIT_EXPR_SLOT (expr
));
600 if (VEC_INIT_EXPR_VALUE_INIT (expr
))
601 init
= void_type_node
;
603 init
= VEC_INIT_EXPR_INIT (expr
);
605 elt_init
= build_vec_init_elt (type
, init
, tf_warning_or_error
);
606 require_potential_constant_expression (elt_init
);
610 build_array_copy (tree init
)
612 return build_vec_init_expr (TREE_TYPE (init
), init
, tf_warning_or_error
);
615 /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
619 build_target_expr_with_type (tree init
, tree type
, tsubst_flags_t complain
)
621 gcc_assert (!VOID_TYPE_P (type
));
623 if (TREE_CODE (init
) == TARGET_EXPR
624 || init
== error_mark_node
)
626 else if (CLASS_TYPE_P (type
) && type_has_nontrivial_copy_init (type
)
627 && !VOID_TYPE_P (TREE_TYPE (init
))
628 && TREE_CODE (init
) != COND_EXPR
629 && TREE_CODE (init
) != CONSTRUCTOR
630 && TREE_CODE (init
) != VA_ARG_EXPR
)
631 /* We need to build up a copy constructor call. A void initializer
632 means we're being called from bot_manip. COND_EXPR is a special
633 case because we already have copies on the arms and we don't want
634 another one here. A CONSTRUCTOR is aggregate initialization, which
635 is handled separately. A VA_ARG_EXPR is magic creation of an
636 aggregate; there's no additional work to be done. */
637 return force_rvalue (init
, complain
);
639 return force_target_expr (type
, init
, complain
);
642 /* Like the above function, but without the checking. This function should
643 only be used by code which is deliberately trying to subvert the type
644 system, such as call_builtin_trap. Or build_over_call, to avoid
645 infinite recursion. */
648 force_target_expr (tree type
, tree init
, tsubst_flags_t complain
)
652 gcc_assert (!VOID_TYPE_P (type
));
654 slot
= build_local_temp (type
);
655 return build_target_expr (slot
, init
, complain
);
658 /* Like build_target_expr_with_type, but use the type of INIT. */
661 get_target_expr_sfinae (tree init
, tsubst_flags_t complain
)
663 if (TREE_CODE (init
) == AGGR_INIT_EXPR
)
664 return build_target_expr (AGGR_INIT_EXPR_SLOT (init
), init
, complain
);
665 else if (TREE_CODE (init
) == VEC_INIT_EXPR
)
666 return build_target_expr (VEC_INIT_EXPR_SLOT (init
), init
, complain
);
668 return build_target_expr_with_type (init
, TREE_TYPE (init
), complain
);
672 get_target_expr (tree init
)
674 return get_target_expr_sfinae (init
, tf_warning_or_error
);
677 /* If EXPR is a bitfield reference, convert it to the declared type of
678 the bitfield, and return the resulting expression. Otherwise,
679 return EXPR itself. */
682 convert_bitfield_to_declared_type (tree expr
)
686 bitfield_type
= is_bitfield_expr_with_lowered_type (expr
);
688 expr
= convert_to_integer (TYPE_MAIN_VARIANT (bitfield_type
),
693 /* EXPR is being used in an rvalue context. Return a version of EXPR
694 that is marked as an rvalue. */
701 if (error_operand_p (expr
))
704 expr
= mark_rvalue_use (expr
);
708 Non-class rvalues always have cv-unqualified types. */
709 type
= TREE_TYPE (expr
);
710 if (!CLASS_TYPE_P (type
) && cv_qualified_p (type
))
711 type
= cv_unqualified (type
);
713 /* We need to do this for rvalue refs as well to get the right answer
714 from decltype; see c++/36628. */
715 if (!processing_template_decl
&& lvalue_or_rvalue_with_address_p (expr
))
716 expr
= build1 (NON_LVALUE_EXPR
, type
, expr
);
717 else if (type
!= TREE_TYPE (expr
))
718 expr
= build_nop (type
, expr
);
724 /* Hash an ARRAY_TYPE. K is really of type `tree'. */
727 cplus_array_hash (const void* k
)
730 const_tree
const t
= (const_tree
) k
;
732 hash
= TYPE_UID (TREE_TYPE (t
));
734 hash
^= TYPE_UID (TYPE_DOMAIN (t
));
738 typedef struct cplus_array_info
{
743 /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really
744 of type `cplus_array_info*'. */
747 cplus_array_compare (const void * k1
, const void * k2
)
749 const_tree
const t1
= (const_tree
) k1
;
750 const cplus_array_info
*const t2
= (const cplus_array_info
*) k2
;
752 return (TREE_TYPE (t1
) == t2
->type
&& TYPE_DOMAIN (t1
) == t2
->domain
);
755 /* Hash table containing dependent array types, which are unsuitable for
756 the language-independent type hash table. */
757 static GTY ((param_is (union tree_node
))) htab_t cplus_array_htab
;
759 /* Like build_array_type, but handle special C++ semantics. */
762 build_cplus_array_type (tree elt_type
, tree index_type
)
766 if (elt_type
== error_mark_node
|| index_type
== error_mark_node
)
767 return error_mark_node
;
769 if (processing_template_decl
770 && (dependent_type_p (elt_type
)
771 || (index_type
&& !TREE_CONSTANT (TYPE_MAX_VALUE (index_type
)))))
774 cplus_array_info cai
;
777 if (cplus_array_htab
== NULL
)
778 cplus_array_htab
= htab_create_ggc (61, &cplus_array_hash
,
779 &cplus_array_compare
, NULL
);
781 hash
= TYPE_UID (elt_type
);
783 hash
^= TYPE_UID (index_type
);
785 cai
.domain
= index_type
;
787 e
= htab_find_slot_with_hash (cplus_array_htab
, &cai
, hash
, INSERT
);
789 /* We have found the type: we're done. */
793 /* Build a new array type. */
794 t
= cxx_make_type (ARRAY_TYPE
);
795 TREE_TYPE (t
) = elt_type
;
796 TYPE_DOMAIN (t
) = index_type
;
798 /* Store it in the hash table. */
801 /* Set the canonical type for this new node. */
802 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
803 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
804 SET_TYPE_STRUCTURAL_EQUALITY (t
);
805 else if (TYPE_CANONICAL (elt_type
) != elt_type
807 && TYPE_CANONICAL (index_type
) != index_type
))
809 = build_cplus_array_type
810 (TYPE_CANONICAL (elt_type
),
811 index_type
? TYPE_CANONICAL (index_type
) : index_type
);
813 TYPE_CANONICAL (t
) = t
;
818 if (!TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
819 && !(index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
))
820 && (TYPE_CANONICAL (elt_type
) != elt_type
821 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
)))
822 /* Make sure that the canonical type is on the appropriate
824 build_cplus_array_type
825 (TYPE_CANONICAL (elt_type
),
826 index_type
? TYPE_CANONICAL (index_type
) : index_type
);
827 t
= build_array_type (elt_type
, index_type
);
830 /* Push these needs up so that initialization takes place
833 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type
));
834 TYPE_NEEDS_CONSTRUCTING (t
) = needs_ctor
;
836 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type
));
837 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
) = needs_dtor
;
839 /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the
840 element type as well, so fix it up if needed. */
841 if (elt_type
!= TYPE_MAIN_VARIANT (elt_type
))
843 tree m
= build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type
),
846 if (TYPE_MAIN_VARIANT (t
) != m
)
848 if (COMPLETE_TYPE_P (TREE_TYPE (t
)) && !COMPLETE_TYPE_P (m
))
850 /* m was built before the element type was complete, so we
851 also need to copy the layout info from t. We might
852 end up doing this multiple times if t is an array of
854 tree size
= TYPE_SIZE (t
);
855 tree size_unit
= TYPE_SIZE_UNIT (t
);
856 unsigned int align
= TYPE_ALIGN (t
);
857 unsigned int user_align
= TYPE_USER_ALIGN (t
);
858 enum machine_mode mode
= TYPE_MODE (t
);
859 for (tree var
= m
; var
; var
= TYPE_NEXT_VARIANT (var
))
861 TYPE_SIZE (var
) = size
;
862 TYPE_SIZE_UNIT (var
) = size_unit
;
863 TYPE_ALIGN (var
) = align
;
864 TYPE_USER_ALIGN (var
) = user_align
;
865 SET_TYPE_MODE (var
, mode
);
866 TYPE_NEEDS_CONSTRUCTING (var
) = needs_ctor
;
867 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (var
) = needs_dtor
;
871 TYPE_MAIN_VARIANT (t
) = m
;
872 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
873 TYPE_NEXT_VARIANT (m
) = t
;
877 /* Avoid spurious warnings with VLAs (c++/54583). */
878 if (TYPE_SIZE (t
) && EXPR_P (TYPE_SIZE (t
)))
879 TREE_NO_WARNING (TYPE_SIZE (t
)) = 1;
884 /* Return an ARRAY_TYPE with element type ELT and length N. */
887 build_array_of_n_type (tree elt
, int n
)
889 return build_cplus_array_type (elt
, build_index_type (size_int (n
- 1)));
892 /* True iff T is a C++1y array of runtime bound (VLA). */
895 array_of_runtime_bound_p (tree t
)
897 if (!t
|| TREE_CODE (t
) != ARRAY_TYPE
)
899 tree dom
= TYPE_DOMAIN (t
);
902 tree max
= TYPE_MAX_VALUE (dom
);
903 return (!potential_rvalue_constant_expression (max
)
904 || (!value_dependent_expression_p (max
) && !TREE_CONSTANT (max
)));
907 /* Return a reference type node referring to TO_TYPE. If RVAL is
908 true, return an rvalue reference type, otherwise return an lvalue
909 reference type. If a type node exists, reuse it, otherwise create
912 cp_build_reference_type (tree to_type
, bool rval
)
915 lvalue_ref
= build_reference_type (to_type
);
919 /* This code to create rvalue reference types is based on and tied
920 to the code creating lvalue reference types in the middle-end
921 functions build_reference_type_for_mode and build_reference_type.
923 It works by putting the rvalue reference type nodes after the
924 lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
925 they will effectively be ignored by the middle end. */
927 for (t
= lvalue_ref
; (t
= TYPE_NEXT_REF_TO (t
)); )
928 if (TYPE_REF_IS_RVALUE (t
))
931 t
= build_distinct_type_copy (lvalue_ref
);
933 TYPE_REF_IS_RVALUE (t
) = true;
934 TYPE_NEXT_REF_TO (t
) = TYPE_NEXT_REF_TO (lvalue_ref
);
935 TYPE_NEXT_REF_TO (lvalue_ref
) = t
;
937 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
938 SET_TYPE_STRUCTURAL_EQUALITY (t
);
939 else if (TYPE_CANONICAL (to_type
) != to_type
)
941 = cp_build_reference_type (TYPE_CANONICAL (to_type
), rval
);
943 TYPE_CANONICAL (t
) = t
;
951 /* Returns EXPR cast to rvalue reference type, like std::move. */
956 tree type
= TREE_TYPE (expr
);
957 gcc_assert (TREE_CODE (type
) != REFERENCE_TYPE
);
958 type
= cp_build_reference_type (type
, /*rval*/true);
959 return build_static_cast (type
, expr
, tf_warning_or_error
);
962 /* Used by the C++ front end to build qualified array types. However,
963 the C version of this function does not properly maintain canonical
964 types (which are not used in C). */
966 c_build_qualified_type (tree type
, int type_quals
)
968 return cp_build_qualified_type (type
, type_quals
);
972 /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles
973 arrays correctly. In particular, if TYPE is an array of T's, and
974 TYPE_QUALS is non-empty, returns an array of qualified T's.
976 FLAGS determines how to deal with ill-formed qualifications. If
977 tf_ignore_bad_quals is set, then bad qualifications are dropped
978 (this is permitted if TYPE was introduced via a typedef or template
979 type parameter). If bad qualifications are dropped and tf_warning
980 is set, then a warning is issued for non-const qualifications. If
981 tf_ignore_bad_quals is not set and tf_error is not set, we
982 return error_mark_node. Otherwise, we issue an error, and ignore
985 Qualification of a reference type is valid when the reference came
986 via a typedef or template type argument. [dcl.ref] No such
987 dispensation is provided for qualifying a function type. [dcl.fct]
988 DR 295 queries this and the proposed resolution brings it into line
989 with qualifying a reference. We implement the DR. We also behave
990 in a similar manner for restricting non-pointer types. */
993 cp_build_qualified_type_real (tree type
,
995 tsubst_flags_t complain
)
998 int bad_quals
= TYPE_UNQUALIFIED
;
1000 if (type
== error_mark_node
)
1003 if (type_quals
== cp_type_quals (type
))
1006 if (TREE_CODE (type
) == ARRAY_TYPE
)
1008 /* In C++, the qualification really applies to the array element
1009 type. Obtain the appropriately qualified element type. */
1012 = cp_build_qualified_type_real (TREE_TYPE (type
),
1016 if (element_type
== error_mark_node
)
1017 return error_mark_node
;
1019 /* See if we already have an identically qualified type. Tests
1020 should be equivalent to those in check_qualified_type. */
1021 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
1022 if (TREE_TYPE (t
) == element_type
1023 && TYPE_NAME (t
) == TYPE_NAME (type
)
1024 && TYPE_CONTEXT (t
) == TYPE_CONTEXT (type
)
1025 && attribute_list_equal (TYPE_ATTRIBUTES (t
),
1026 TYPE_ATTRIBUTES (type
)))
1031 t
= build_cplus_array_type (element_type
, TYPE_DOMAIN (type
));
1033 /* Keep the typedef name. */
1034 if (TYPE_NAME (t
) != TYPE_NAME (type
))
1036 t
= build_variant_type_copy (t
);
1037 TYPE_NAME (t
) = TYPE_NAME (type
);
1041 /* Even if we already had this variant, we update
1042 TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
1043 they changed since the variant was originally created.
1045 This seems hokey; if there is some way to use a previous
1046 variant *without* coming through here,
1047 TYPE_NEEDS_CONSTRUCTING will never be updated. */
1048 TYPE_NEEDS_CONSTRUCTING (t
)
1049 = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type
));
1050 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t
)
1051 = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type
));
1054 else if (TYPE_PTRMEMFUNC_P (type
))
1056 /* For a pointer-to-member type, we can't just return a
1057 cv-qualified version of the RECORD_TYPE. If we do, we
1058 haven't changed the field that contains the actual pointer to
1059 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */
1062 t
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
1063 t
= cp_build_qualified_type_real (t
, type_quals
, complain
);
1064 return build_ptrmemfunc_type (t
);
1066 else if (TREE_CODE (type
) == TYPE_PACK_EXPANSION
)
1068 tree t
= PACK_EXPANSION_PATTERN (type
);
1070 t
= cp_build_qualified_type_real (t
, type_quals
, complain
);
1071 return make_pack_expansion (t
);
1074 /* A reference or method type shall not be cv-qualified.
1075 [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295
1076 (in CD1) we always ignore extra cv-quals on functions. */
1077 if (type_quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
)
1078 && (TREE_CODE (type
) == REFERENCE_TYPE
1079 || TREE_CODE (type
) == FUNCTION_TYPE
1080 || TREE_CODE (type
) == METHOD_TYPE
))
1082 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1083 bad_quals
|= type_quals
& (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
1084 type_quals
&= ~(TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
);
1087 /* But preserve any function-cv-quals on a FUNCTION_TYPE. */
1088 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1089 type_quals
|= type_memfn_quals (type
);
1091 /* A restrict-qualified type must be a pointer (or reference)
1092 to object or incomplete type. */
1093 if ((type_quals
& TYPE_QUAL_RESTRICT
)
1094 && TREE_CODE (type
) != TEMPLATE_TYPE_PARM
1095 && TREE_CODE (type
) != TYPENAME_TYPE
1096 && !POINTER_TYPE_P (type
))
1098 bad_quals
|= TYPE_QUAL_RESTRICT
;
1099 type_quals
&= ~TYPE_QUAL_RESTRICT
;
1102 if (bad_quals
== TYPE_UNQUALIFIED
1103 || (complain
& tf_ignore_bad_quals
))
1105 else if (!(complain
& tf_error
))
1106 return error_mark_node
;
1109 tree bad_type
= build_qualified_type (ptr_type_node
, bad_quals
);
1110 error ("%qV qualifiers cannot be applied to %qT",
1114 /* Retrieve (or create) the appropriately qualified variant. */
1115 result
= build_qualified_type (type
, type_quals
);
1117 /* Preserve exception specs and ref-qualifier since build_qualified_type
1118 doesn't know about them. */
1119 if (TREE_CODE (result
) == FUNCTION_TYPE
1120 || TREE_CODE (result
) == METHOD_TYPE
)
1122 result
= build_exception_variant (result
, TYPE_RAISES_EXCEPTIONS (type
));
1123 result
= build_ref_qualified_type (result
, type_memfn_rqual (type
));
1126 /* If this was a pointer-to-method type, and we just made a copy,
1127 then we need to unshare the record that holds the cached
1128 pointer-to-member-function type, because these will be distinct
1129 between the unqualified and qualified types. */
1131 && TYPE_PTR_P (type
)
1132 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
1133 && TYPE_LANG_SPECIFIC (result
) == TYPE_LANG_SPECIFIC (type
))
1134 TYPE_LANG_SPECIFIC (result
) = NULL
;
1136 /* We may also have ended up building a new copy of the canonical
1137 type of a pointer-to-method type, which could have the same
1138 sharing problem described above. */
1139 if (TYPE_CANONICAL (result
) != TYPE_CANONICAL (type
)
1140 && TYPE_PTR_P (type
)
1141 && TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
1142 && (TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result
))
1143 == TYPE_LANG_SPECIFIC (TYPE_CANONICAL (type
))))
1144 TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result
)) = NULL
;
1149 /* Return TYPE with const and volatile removed. */
1152 cv_unqualified (tree type
)
1156 if (type
== error_mark_node
)
1159 quals
= cp_type_quals (type
);
1160 quals
&= ~(TYPE_QUAL_CONST
|TYPE_QUAL_VOLATILE
);
1161 return cp_build_qualified_type (type
, quals
);
1164 /* Builds a qualified variant of T that is not a typedef variant.
1165 E.g. consider the following declarations:
1166 typedef const int ConstInt;
1167 typedef ConstInt* PtrConstInt;
1168 If T is PtrConstInt, this function returns a type representing
1170 In other words, if T is a typedef, the function returns the underlying type.
1171 The cv-qualification and attributes of the type returned match the
1173 They will always be compatible types.
1174 The returned type is built so that all of its subtypes
1175 recursively have their typedefs stripped as well.
1177 This is different from just returning TYPE_CANONICAL (T)
1178 Because of several reasons:
1179 * If T is a type that needs structural equality
1180 its TYPE_CANONICAL (T) will be NULL.
1181 * TYPE_CANONICAL (T) desn't carry type attributes
1182 and loses template parameter names. */
1185 strip_typedefs (tree t
)
1187 tree result
= NULL
, type
= NULL
, t0
= NULL
;
1189 if (!t
|| t
== error_mark_node
|| t
== TYPE_CANONICAL (t
))
1192 gcc_assert (TYPE_P (t
));
1194 switch (TREE_CODE (t
))
1197 type
= strip_typedefs (TREE_TYPE (t
));
1198 result
= build_pointer_type (type
);
1200 case REFERENCE_TYPE
:
1201 type
= strip_typedefs (TREE_TYPE (t
));
1202 result
= cp_build_reference_type (type
, TYPE_REF_IS_RVALUE (t
));
1205 t0
= strip_typedefs (TYPE_OFFSET_BASETYPE (t
));
1206 type
= strip_typedefs (TREE_TYPE (t
));
1207 result
= build_offset_type (t0
, type
);
1210 if (TYPE_PTRMEMFUNC_P (t
))
1212 t0
= strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t
));
1213 result
= build_ptrmemfunc_type (t0
);
1217 type
= strip_typedefs (TREE_TYPE (t
));
1218 t0
= strip_typedefs (TYPE_DOMAIN (t
));;
1219 result
= build_cplus_array_type (type
, t0
);
1224 tree arg_types
= NULL
, arg_node
, arg_type
;
1225 for (arg_node
= TYPE_ARG_TYPES (t
);
1227 arg_node
= TREE_CHAIN (arg_node
))
1229 if (arg_node
== void_list_node
)
1231 arg_type
= strip_typedefs (TREE_VALUE (arg_node
));
1232 gcc_assert (arg_type
);
1235 tree_cons (TREE_PURPOSE (arg_node
), arg_type
, arg_types
);
1239 arg_types
= nreverse (arg_types
);
1241 /* A list of parameters not ending with an ellipsis
1242 must end with void_list_node. */
1244 arg_types
= chainon (arg_types
, void_list_node
);
1246 type
= strip_typedefs (TREE_TYPE (t
));
1247 if (TREE_CODE (t
) == METHOD_TYPE
)
1249 tree class_type
= TREE_TYPE (TREE_VALUE (arg_types
));
1250 gcc_assert (class_type
);
1252 build_method_type_directly (class_type
, type
,
1253 TREE_CHAIN (arg_types
));
1255 = build_ref_qualified_type (result
, type_memfn_rqual (t
));
1259 result
= build_function_type (type
,
1261 result
= apply_memfn_quals (result
,
1262 type_memfn_quals (t
),
1263 type_memfn_rqual (t
));
1266 if (TYPE_RAISES_EXCEPTIONS (t
))
1267 result
= build_exception_variant (result
,
1268 TYPE_RAISES_EXCEPTIONS (t
));
1273 tree fullname
= TYPENAME_TYPE_FULLNAME (t
);
1274 if (TREE_CODE (fullname
) == TEMPLATE_ID_EXPR
1275 && TREE_OPERAND (fullname
, 1))
1277 tree args
= TREE_OPERAND (fullname
, 1);
1278 tree new_args
= copy_node (args
);
1279 bool changed
= false;
1280 for (int i
= 0; i
< TREE_VEC_LENGTH (args
); ++i
)
1282 tree arg
= TREE_VEC_ELT (args
, i
);
1285 strip_arg
= strip_typedefs (arg
);
1287 strip_arg
= strip_typedefs_expr (arg
);
1288 TREE_VEC_ELT (new_args
, i
) = strip_arg
;
1289 if (strip_arg
!= arg
)
1294 NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args
)
1295 = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args
);
1297 = lookup_template_function (TREE_OPERAND (fullname
, 0),
1301 ggc_free (new_args
);
1303 result
= make_typename_type (strip_typedefs (TYPE_CONTEXT (t
)),
1304 fullname
, typename_type
, tf_none
);
1308 result
= strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t
));
1309 if (result
== DECLTYPE_TYPE_EXPR (t
))
1312 result
= (finish_decltype_type
1314 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t
),
1322 result
= TYPE_MAIN_VARIANT (t
);
1323 if (TYPE_USER_ALIGN (t
) != TYPE_USER_ALIGN (result
)
1324 || TYPE_ALIGN (t
) != TYPE_ALIGN (result
))
1326 gcc_assert (TYPE_USER_ALIGN (t
));
1327 if (TYPE_ALIGN (t
) == TYPE_ALIGN (result
))
1328 result
= build_variant_type_copy (result
);
1330 result
= build_aligned_type (result
, TYPE_ALIGN (t
));
1331 TYPE_USER_ALIGN (result
) = true;
1333 if (TYPE_ATTRIBUTES (t
))
1334 result
= cp_build_type_attribute_variant (result
, TYPE_ATTRIBUTES (t
));
1335 return cp_build_qualified_type (result
, cp_type_quals (t
));
1338 /* Like strip_typedefs above, but works on expressions, so that in
1340 template<class T> struct A
1346 sizeof(TT) is replaced by sizeof(T). */
1349 strip_typedefs_expr (tree t
)
1353 enum tree_code code
;
1355 if (t
== NULL_TREE
|| t
== error_mark_node
)
1358 if (DECL_P (t
) || CONSTANT_CLASS_P (t
))
1361 /* Some expressions have type operands, so let's handle types here rather
1362 than check TYPE_P in multiple places below. */
1364 return strip_typedefs (t
);
1366 code
= TREE_CODE (t
);
1369 case IDENTIFIER_NODE
:
1370 case TEMPLATE_PARM_INDEX
:
1373 case ARGUMENT_PACK_SELECT
:
1378 tree type1
= strip_typedefs (TRAIT_EXPR_TYPE1 (t
));
1379 tree type2
= strip_typedefs (TRAIT_EXPR_TYPE2 (t
));
1380 if (type1
== TRAIT_EXPR_TYPE1 (t
)
1381 && type2
== TRAIT_EXPR_TYPE2 (t
))
1384 TRAIT_EXPR_TYPE1 (t
) = type1
;
1385 TRAIT_EXPR_TYPE2 (t
) = type2
;
1391 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
1392 bool changed
= false;
1394 for (it
= t
; it
; it
= TREE_CHAIN (it
))
1396 tree val
= strip_typedefs_expr (TREE_VALUE (t
));
1397 vec_safe_push (vec
, val
);
1398 if (val
!= TREE_VALUE (t
))
1400 gcc_assert (TREE_PURPOSE (it
) == NULL_TREE
);
1405 FOR_EACH_VEC_ELT_REVERSE (*vec
, i
, it
)
1406 r
= tree_cons (NULL_TREE
, it
, r
);
1410 release_tree_vector (vec
);
1416 bool changed
= false;
1417 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
1418 n
= TREE_VEC_LENGTH (t
);
1419 vec_safe_reserve (vec
, n
);
1420 for (i
= 0; i
< n
; ++i
)
1422 tree op
= strip_typedefs_expr (TREE_VEC_ELT (t
, i
));
1423 vec
->quick_push (op
);
1424 if (op
!= TREE_VEC_ELT (t
, i
))
1430 for (i
= 0; i
< n
; ++i
)
1431 TREE_VEC_ELT (r
, i
) = (*vec
)[i
];
1432 NON_DEFAULT_TEMPLATE_ARGS_COUNT (r
)
1433 = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t
);
1437 release_tree_vector (vec
);
1443 bool changed
= false;
1444 vec
<constructor_elt
, va_gc
> *vec
1445 = vec_safe_copy (CONSTRUCTOR_ELTS (t
));
1446 n
= CONSTRUCTOR_NELTS (t
);
1447 type
= strip_typedefs (TREE_TYPE (t
));
1448 for (i
= 0; i
< n
; ++i
)
1450 constructor_elt
*e
= &(*vec
)[i
];
1451 tree op
= strip_typedefs_expr (e
->value
);
1457 gcc_checking_assert (e
->index
== strip_typedefs_expr (e
->index
));
1460 if (!changed
&& type
== TREE_TYPE (t
))
1468 TREE_TYPE (r
) = type
;
1469 CONSTRUCTOR_ELTS (r
) = vec
;
1475 error ("lambda-expression in a constant expression");
1476 return error_mark_node
;
1482 gcc_assert (EXPR_P (t
));
1484 n
= TREE_OPERAND_LENGTH (t
);
1485 ops
= XALLOCAVEC (tree
, n
);
1486 type
= TREE_TYPE (t
);
1491 case IMPLICIT_CONV_EXPR
:
1492 case DYNAMIC_CAST_EXPR
:
1493 case STATIC_CAST_EXPR
:
1494 case CONST_CAST_EXPR
:
1495 case REINTERPRET_CAST_EXPR
:
1498 type
= strip_typedefs (type
);
1502 for (i
= 0; i
< n
; ++i
)
1503 ops
[i
] = strip_typedefs_expr (TREE_OPERAND (t
, i
));
1507 /* If nothing changed, return t. */
1508 for (i
= 0; i
< n
; ++i
)
1509 if (ops
[i
] != TREE_OPERAND (t
, i
))
1511 if (i
== n
&& type
== TREE_TYPE (t
))
1515 TREE_TYPE (r
) = type
;
1516 for (i
= 0; i
< n
; ++i
)
1517 TREE_OPERAND (r
, i
) = ops
[i
];
1521 /* Makes a copy of BINFO and TYPE, which is to be inherited into a
1522 graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
1523 and we do a shallow copy. If BINFO is non-NULL, we do a deep copy.
1524 VIRT indicates whether TYPE is inherited virtually or not.
1525 IGO_PREV points at the previous binfo of the inheritance graph
1526 order chain. The newly copied binfo's TREE_CHAIN forms this
1529 The CLASSTYPE_VBASECLASSES vector of T is constructed in the
1530 correct order. That is in the order the bases themselves should be
1533 The BINFO_INHERITANCE of a virtual base class points to the binfo
1534 of the most derived type. ??? We could probably change this so that
1535 BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
1536 remove a field. They currently can only differ for primary virtual
1540 copy_binfo (tree binfo
, tree type
, tree t
, tree
*igo_prev
, int virt
)
1546 /* See if we've already made this virtual base. */
1547 new_binfo
= binfo_for_vbase (type
, t
);
1552 new_binfo
= make_tree_binfo (binfo
? BINFO_N_BASE_BINFOS (binfo
) : 0);
1553 BINFO_TYPE (new_binfo
) = type
;
1555 /* Chain it into the inheritance graph. */
1556 TREE_CHAIN (*igo_prev
) = new_binfo
;
1557 *igo_prev
= new_binfo
;
1559 if (binfo
&& !BINFO_DEPENDENT_BASE_P (binfo
))
1564 gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo
), type
));
1566 BINFO_OFFSET (new_binfo
) = BINFO_OFFSET (binfo
);
1567 BINFO_VIRTUALS (new_binfo
) = BINFO_VIRTUALS (binfo
);
1569 /* We do not need to copy the accesses, as they are read only. */
1570 BINFO_BASE_ACCESSES (new_binfo
) = BINFO_BASE_ACCESSES (binfo
);
1572 /* Recursively copy base binfos of BINFO. */
1573 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
1575 tree new_base_binfo
;
1576 new_base_binfo
= copy_binfo (base_binfo
, BINFO_TYPE (base_binfo
),
1578 BINFO_VIRTUAL_P (base_binfo
));
1580 if (!BINFO_INHERITANCE_CHAIN (new_base_binfo
))
1581 BINFO_INHERITANCE_CHAIN (new_base_binfo
) = new_binfo
;
1582 BINFO_BASE_APPEND (new_binfo
, new_base_binfo
);
1586 BINFO_DEPENDENT_BASE_P (new_binfo
) = 1;
1590 /* Push it onto the list after any virtual bases it contains
1591 will have been pushed. */
1592 CLASSTYPE_VBASECLASSES (t
)->quick_push (new_binfo
);
1593 BINFO_VIRTUAL_P (new_binfo
) = 1;
1594 BINFO_INHERITANCE_CHAIN (new_binfo
) = TYPE_BINFO (t
);
1600 /* Hashing of lists so that we don't make duplicates.
1601 The entry point is `list_hash_canon'. */
1603 /* Now here is the hash table. When recording a list, it is added
1604 to the slot whose index is the hash code mod the table size.
1605 Note that the hash table is used for several kinds of lists.
1606 While all these live in the same table, they are completely independent,
1607 and the hash code is computed differently for each of these. */
1609 static GTY ((param_is (union tree_node
))) htab_t list_hash_table
;
1618 /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
1619 for a node we are thinking about adding). */
1622 list_hash_eq (const void* entry
, const void* data
)
1624 const_tree
const t
= (const_tree
) entry
;
1625 const struct list_proxy
*const proxy
= (const struct list_proxy
*) data
;
1627 return (TREE_VALUE (t
) == proxy
->value
1628 && TREE_PURPOSE (t
) == proxy
->purpose
1629 && TREE_CHAIN (t
) == proxy
->chain
);
1632 /* Compute a hash code for a list (chain of TREE_LIST nodes
1633 with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
1634 TREE_COMMON slots), by adding the hash codes of the individual entries. */
1637 list_hash_pieces (tree purpose
, tree value
, tree chain
)
1639 hashval_t hashcode
= 0;
1642 hashcode
+= TREE_HASH (chain
);
1645 hashcode
+= TREE_HASH (value
);
1649 hashcode
+= TREE_HASH (purpose
);
1655 /* Hash an already existing TREE_LIST. */
1658 list_hash (const void* p
)
1660 const_tree
const t
= (const_tree
) p
;
1661 return list_hash_pieces (TREE_PURPOSE (t
),
1666 /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
1667 object for an identical list if one already exists. Otherwise, build a
1668 new one, and record it as the canonical object. */
1671 hash_tree_cons (tree purpose
, tree value
, tree chain
)
1675 struct list_proxy proxy
;
1677 /* Hash the list node. */
1678 hashcode
= list_hash_pieces (purpose
, value
, chain
);
1679 /* Create a proxy for the TREE_LIST we would like to create. We
1680 don't actually create it so as to avoid creating garbage. */
1681 proxy
.purpose
= purpose
;
1682 proxy
.value
= value
;
1683 proxy
.chain
= chain
;
1684 /* See if it is already in the table. */
1685 slot
= htab_find_slot_with_hash (list_hash_table
, &proxy
, hashcode
,
1687 /* If not, create a new node. */
1689 *slot
= tree_cons (purpose
, value
, chain
);
1690 return (tree
) *slot
;
1693 /* Constructor for hashed lists. */
1696 hash_tree_chain (tree value
, tree chain
)
1698 return hash_tree_cons (NULL_TREE
, value
, chain
);
1702 debug_binfo (tree elem
)
1707 fprintf (stderr
, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
1709 TYPE_NAME_STRING (BINFO_TYPE (elem
)),
1710 TREE_INT_CST_LOW (BINFO_OFFSET (elem
)));
1711 debug_tree (BINFO_TYPE (elem
));
1712 if (BINFO_VTABLE (elem
))
1713 fprintf (stderr
, "vtable decl \"%s\"\n",
1714 IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem
))));
1716 fprintf (stderr
, "no vtable decl yet\n");
1717 fprintf (stderr
, "virtuals:\n");
1718 virtuals
= BINFO_VIRTUALS (elem
);
1723 tree fndecl
= TREE_VALUE (virtuals
);
1724 fprintf (stderr
, "%s [%ld =? %ld]\n",
1725 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl
)),
1726 (long) n
, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl
)));
1728 virtuals
= TREE_CHAIN (virtuals
);
1732 /* Build a representation for the qualified name SCOPE::NAME. TYPE is
1733 the type of the result expression, if known, or NULL_TREE if the
1734 resulting expression is type-dependent. If TEMPLATE_P is true,
1735 NAME is known to be a template because the user explicitly used the
1736 "template" keyword after the "::".
1738 All SCOPE_REFs should be built by use of this function. */
1741 build_qualified_name (tree type
, tree scope
, tree name
, bool template_p
)
1744 if (type
== error_mark_node
1745 || scope
== error_mark_node
1746 || name
== error_mark_node
)
1747 return error_mark_node
;
1748 t
= build2 (SCOPE_REF
, type
, scope
, name
);
1749 QUALIFIED_NAME_IS_TEMPLATE (t
) = template_p
;
1750 PTRMEM_OK_P (t
) = true;
1752 t
= convert_from_reference (t
);
1756 /* Like check_qualified_type, but also check ref-qualifier and exception
1760 cp_check_qualified_type (const_tree cand
, const_tree base
, int type_quals
,
1761 cp_ref_qualifier rqual
, tree raises
)
1763 return (check_qualified_type (cand
, base
, type_quals
)
1764 && comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (cand
),
1766 && type_memfn_rqual (cand
) == rqual
);
1769 /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */
1772 build_ref_qualified_type (tree type
, cp_ref_qualifier rqual
)
1776 if (rqual
== type_memfn_rqual (type
))
1779 int type_quals
= TYPE_QUALS (type
);
1780 tree raises
= TYPE_RAISES_EXCEPTIONS (type
);
1781 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
1782 if (cp_check_qualified_type (t
, type
, type_quals
, rqual
, raises
))
1785 t
= build_variant_type_copy (type
);
1788 case REF_QUAL_RVALUE
:
1789 FUNCTION_RVALUE_QUALIFIED (t
) = 1;
1790 FUNCTION_REF_QUALIFIED (t
) = 1;
1792 case REF_QUAL_LVALUE
:
1793 FUNCTION_RVALUE_QUALIFIED (t
) = 0;
1794 FUNCTION_REF_QUALIFIED (t
) = 1;
1797 FUNCTION_REF_QUALIFIED (t
) = 0;
1801 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
1802 /* Propagate structural equality. */
1803 SET_TYPE_STRUCTURAL_EQUALITY (t
);
1804 else if (TYPE_CANONICAL (type
) != type
)
1805 /* Build the underlying canonical type, since it is different
1807 TYPE_CANONICAL (t
) = build_ref_qualified_type (TYPE_CANONICAL (type
),
1810 /* T is its own canonical type. */
1811 TYPE_CANONICAL (t
) = t
;
1816 /* Returns nonzero if X is an expression for a (possibly overloaded)
1817 function. If "f" is a function or function template, "f", "c->f",
1818 "c.f", "C::f", and "f<int>" will all be considered possibly
1819 overloaded functions. Returns 2 if the function is actually
1820 overloaded, i.e., if it is impossible to know the type of the
1821 function without performing overload resolution. */
1824 is_overloaded_fn (tree x
)
1826 /* A baselink is also considered an overloaded function. */
1827 if (TREE_CODE (x
) == OFFSET_REF
1828 || TREE_CODE (x
) == COMPONENT_REF
)
1829 x
= TREE_OPERAND (x
, 1);
1831 x
= BASELINK_FUNCTIONS (x
);
1832 if (TREE_CODE (x
) == TEMPLATE_ID_EXPR
)
1833 x
= TREE_OPERAND (x
, 0);
1834 if (DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x
))
1835 || (TREE_CODE (x
) == OVERLOAD
&& OVL_CHAIN (x
)))
1837 return (TREE_CODE (x
) == FUNCTION_DECL
1838 || TREE_CODE (x
) == OVERLOAD
);
1841 /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name
1842 (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return
1846 dependent_name (tree x
)
1848 if (identifier_p (x
))
1850 if (TREE_CODE (x
) != COMPONENT_REF
1851 && TREE_CODE (x
) != OFFSET_REF
1852 && TREE_CODE (x
) != BASELINK
1853 && is_overloaded_fn (x
))
1854 return DECL_NAME (get_first_fn (x
));
1858 /* Returns true iff X is an expression for an overloaded function
1859 whose type cannot be known without performing overload
1863 really_overloaded_fn (tree x
)
1865 return is_overloaded_fn (x
) == 2;
1871 gcc_assert (is_overloaded_fn (from
));
1872 /* A baselink is also considered an overloaded function. */
1873 if (TREE_CODE (from
) == OFFSET_REF
1874 || TREE_CODE (from
) == COMPONENT_REF
)
1875 from
= TREE_OPERAND (from
, 1);
1876 if (BASELINK_P (from
))
1877 from
= BASELINK_FUNCTIONS (from
);
1878 if (TREE_CODE (from
) == TEMPLATE_ID_EXPR
)
1879 from
= TREE_OPERAND (from
, 0);
1884 get_first_fn (tree from
)
1886 return OVL_CURRENT (get_fns (from
));
1889 /* Return a new OVL node, concatenating it with the old one. */
1892 ovl_cons (tree decl
, tree chain
)
1894 tree result
= make_node (OVERLOAD
);
1895 TREE_TYPE (result
) = unknown_type_node
;
1896 OVL_FUNCTION (result
) = decl
;
1897 TREE_CHAIN (result
) = chain
;
1902 /* Build a new overloaded function. If this is the first one,
1903 just return it; otherwise, ovl_cons the _DECLs */
1906 build_overload (tree decl
, tree chain
)
1908 if (! chain
&& TREE_CODE (decl
) != TEMPLATE_DECL
)
1910 return ovl_cons (decl
, chain
);
1913 /* Return the scope where the overloaded functions OVL were found. */
1916 ovl_scope (tree ovl
)
1918 if (TREE_CODE (ovl
) == OFFSET_REF
1919 || TREE_CODE (ovl
) == COMPONENT_REF
)
1920 ovl
= TREE_OPERAND (ovl
, 1);
1921 if (TREE_CODE (ovl
) == BASELINK
)
1922 return BINFO_TYPE (BASELINK_BINFO (ovl
));
1923 if (TREE_CODE (ovl
) == TEMPLATE_ID_EXPR
)
1924 ovl
= TREE_OPERAND (ovl
, 0);
1925 /* Skip using-declarations. */
1926 while (TREE_CODE (ovl
) == OVERLOAD
&& OVL_USED (ovl
) && OVL_CHAIN (ovl
))
1927 ovl
= OVL_CHAIN (ovl
);
1928 return CP_DECL_CONTEXT (OVL_CURRENT (ovl
));
1931 /* Return TRUE if FN is a non-static member function, FALSE otherwise.
1932 This function looks into BASELINK and OVERLOAD nodes. */
1935 non_static_member_function_p (tree fn
)
1937 if (fn
== NULL_TREE
)
1940 if (is_overloaded_fn (fn
))
1941 fn
= get_first_fn (fn
);
1944 && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn
));
1948 #define PRINT_RING_SIZE 4
1951 cxx_printable_name_internal (tree decl
, int v
, bool translate
)
1953 static unsigned int uid_ring
[PRINT_RING_SIZE
];
1954 static char *print_ring
[PRINT_RING_SIZE
];
1955 static bool trans_ring
[PRINT_RING_SIZE
];
1956 static int ring_counter
;
1959 /* Only cache functions. */
1961 || TREE_CODE (decl
) != FUNCTION_DECL
1962 || DECL_LANG_SPECIFIC (decl
) == 0)
1963 return lang_decl_name (decl
, v
, translate
);
1965 /* See if this print name is lying around. */
1966 for (i
= 0; i
< PRINT_RING_SIZE
; i
++)
1967 if (uid_ring
[i
] == DECL_UID (decl
) && translate
== trans_ring
[i
])
1968 /* yes, so return it. */
1969 return print_ring
[i
];
1971 if (++ring_counter
== PRINT_RING_SIZE
)
1974 if (current_function_decl
!= NULL_TREE
)
1976 /* There may be both translated and untranslated versions of the
1978 for (i
= 0; i
< 2; i
++)
1980 if (uid_ring
[ring_counter
] == DECL_UID (current_function_decl
))
1982 if (ring_counter
== PRINT_RING_SIZE
)
1985 gcc_assert (uid_ring
[ring_counter
] != DECL_UID (current_function_decl
));
1988 free (print_ring
[ring_counter
]);
1990 print_ring
[ring_counter
] = xstrdup (lang_decl_name (decl
, v
, translate
));
1991 uid_ring
[ring_counter
] = DECL_UID (decl
);
1992 trans_ring
[ring_counter
] = translate
;
1993 return print_ring
[ring_counter
];
1997 cxx_printable_name (tree decl
, int v
)
1999 return cxx_printable_name_internal (decl
, v
, false);
2003 cxx_printable_name_translate (tree decl
, int v
)
2005 return cxx_printable_name_internal (decl
, v
, true);
2008 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
2009 listed in RAISES. */
2012 build_exception_variant (tree type
, tree raises
)
2017 if (comp_except_specs (raises
, TYPE_RAISES_EXCEPTIONS (type
), ce_exact
))
2020 type_quals
= TYPE_QUALS (type
);
2021 cp_ref_qualifier rqual
= type_memfn_rqual (type
);
2022 for (v
= TYPE_MAIN_VARIANT (type
); v
; v
= TYPE_NEXT_VARIANT (v
))
2023 if (cp_check_qualified_type (v
, type
, type_quals
, rqual
, raises
))
2026 /* Need to build a new variant. */
2027 v
= build_variant_type_copy (type
);
2028 TYPE_RAISES_EXCEPTIONS (v
) = raises
;
2032 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
2033 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
2037 bind_template_template_parm (tree t
, tree newargs
)
2039 tree decl
= TYPE_NAME (t
);
2042 t2
= cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM
);
2043 decl
= build_decl (input_location
,
2044 TYPE_DECL
, DECL_NAME (decl
), NULL_TREE
);
2046 /* These nodes have to be created to reflect new TYPE_DECL and template
2048 TEMPLATE_TYPE_PARM_INDEX (t2
) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t
));
2049 TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2
)) = decl
;
2050 TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2
)
2051 = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t
), newargs
);
2053 TREE_TYPE (decl
) = t2
;
2054 TYPE_NAME (t2
) = decl
;
2055 TYPE_STUB_DECL (t2
) = decl
;
2057 SET_TYPE_STRUCTURAL_EQUALITY (t2
);
2062 /* Called from count_trees via walk_tree. */
2065 count_trees_r (tree
*tp
, int *walk_subtrees
, void *data
)
2075 /* Debugging function for measuring the rough complexity of a tree
2079 count_trees (tree t
)
2082 cp_walk_tree_without_duplicates (&t
, count_trees_r
, &n_trees
);
2086 /* Called from verify_stmt_tree via walk_tree. */
2089 verify_stmt_tree_r (tree
* tp
, int * /*walk_subtrees*/, void* data
)
2092 hash_table
<pointer_hash
<tree_node
> > *statements
2093 = static_cast <hash_table
<pointer_hash
<tree_node
> > *> (data
);
2096 if (!STATEMENT_CODE_P (TREE_CODE (t
)))
2099 /* If this statement is already present in the hash table, then
2100 there is a circularity in the statement tree. */
2101 gcc_assert (!statements
->find (t
));
2103 slot
= statements
->find_slot (t
, INSERT
);
2109 /* Debugging function to check that the statement T has not been
2110 corrupted. For now, this function simply checks that T contains no
2114 verify_stmt_tree (tree t
)
2116 hash_table
<pointer_hash
<tree_node
> > statements
;
2117 statements
.create (37);
2118 cp_walk_tree (&t
, verify_stmt_tree_r
, &statements
, NULL
);
2119 statements
.dispose ();
2122 /* Check if the type T depends on a type with no linkage and if so, return
2123 it. If RELAXED_P then do not consider a class type declared within
2124 a vague-linkage function to have no linkage. */
2127 no_linkage_check (tree t
, bool relaxed_p
)
2131 /* There's no point in checking linkage on template functions; we
2132 can't know their complete types. */
2133 if (processing_template_decl
)
2136 switch (TREE_CODE (t
))
2139 if (TYPE_PTRMEMFUNC_P (t
))
2141 /* Lambda types that don't have mangling scope have no linkage. We
2142 check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
2143 when we get here from pushtag none of the lambda information is
2144 set up yet, so we want to assume that the lambda has linkage and
2145 fix it up later if not. */
2146 if (CLASSTYPE_LAMBDA_EXPR (t
)
2147 && CLASSTYPE_LAMBDA_EXPR (t
) != error_mark_node
2148 && LAMBDA_TYPE_EXTRA_SCOPE (t
) == NULL_TREE
)
2152 if (!CLASS_TYPE_P (t
))
2156 /* Only treat anonymous types as having no linkage if they're at
2157 namespace scope. This is core issue 966. */
2158 if (TYPE_ANONYMOUS_P (t
) && TYPE_NAMESPACE_SCOPE_P (t
))
2161 for (r
= CP_TYPE_CONTEXT (t
); ; )
2163 /* If we're a nested type of a !TREE_PUBLIC class, we might not
2164 have linkage, or we might just be in an anonymous namespace.
2165 If we're in a TREE_PUBLIC class, we have linkage. */
2166 if (TYPE_P (r
) && !TREE_PUBLIC (TYPE_NAME (r
)))
2167 return no_linkage_check (TYPE_CONTEXT (t
), relaxed_p
);
2168 else if (TREE_CODE (r
) == FUNCTION_DECL
)
2170 if (!relaxed_p
|| !vague_linkage_p (r
))
2173 r
= CP_DECL_CONTEXT (r
);
2183 case REFERENCE_TYPE
:
2185 return no_linkage_check (TREE_TYPE (t
), relaxed_p
);
2189 r
= no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t
),
2193 return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t
), relaxed_p
);
2198 tree parm
= TYPE_ARG_TYPES (t
);
2199 if (TREE_CODE (t
) == METHOD_TYPE
)
2200 /* The 'this' pointer isn't interesting; a method has the same
2201 linkage (or lack thereof) as its enclosing class. */
2202 parm
= TREE_CHAIN (parm
);
2204 parm
&& parm
!= void_list_node
;
2205 parm
= TREE_CHAIN (parm
))
2207 r
= no_linkage_check (TREE_VALUE (parm
), relaxed_p
);
2211 return no_linkage_check (TREE_TYPE (t
), relaxed_p
);
2219 extern int depth_reached
;
2222 cxx_print_statistics (void)
2224 print_search_statistics ();
2225 print_class_statistics ();
2226 print_template_statistics ();
2227 if (GATHER_STATISTICS
)
2228 fprintf (stderr
, "maximum template instantiation depth reached: %d\n",
2232 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2233 (which is an ARRAY_TYPE). This counts only elements of the top
2237 array_type_nelts_top (tree type
)
2239 return fold_build2_loc (input_location
,
2240 PLUS_EXPR
, sizetype
,
2241 array_type_nelts (type
),
2245 /* Return, as an INTEGER_CST node, the number of elements for TYPE
2246 (which is an ARRAY_TYPE). This one is a recursive count of all
2247 ARRAY_TYPEs that are clumped together. */
2250 array_type_nelts_total (tree type
)
2252 tree sz
= array_type_nelts_top (type
);
2253 type
= TREE_TYPE (type
);
2254 while (TREE_CODE (type
) == ARRAY_TYPE
)
2256 tree n
= array_type_nelts_top (type
);
2257 sz
= fold_build2_loc (input_location
,
2258 MULT_EXPR
, sizetype
, sz
, n
);
2259 type
= TREE_TYPE (type
);
2264 /* Called from break_out_target_exprs via mapcar. */
2267 bot_manip (tree
* tp
, int* walk_subtrees
, void* data
)
2269 splay_tree target_remap
= ((splay_tree
) data
);
2272 if (!TYPE_P (t
) && TREE_CONSTANT (t
) && !TREE_SIDE_EFFECTS (t
))
2274 /* There can't be any TARGET_EXPRs or their slot variables below this
2275 point. But we must make a copy, in case subsequent processing
2276 alters any part of it. For example, during gimplification a cast
2277 of the form (T) &X::f (where "f" is a member function) will lead
2278 to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */
2280 *tp
= unshare_expr (t
);
2283 if (TREE_CODE (t
) == TARGET_EXPR
)
2287 if (TREE_CODE (TREE_OPERAND (t
, 1)) == AGGR_INIT_EXPR
)
2289 u
= build_cplus_new (TREE_TYPE (t
), TREE_OPERAND (t
, 1),
2290 tf_warning_or_error
);
2291 if (AGGR_INIT_ZERO_FIRST (TREE_OPERAND (t
, 1)))
2292 AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u
, 1)) = true;
2295 u
= build_target_expr_with_type (TREE_OPERAND (t
, 1), TREE_TYPE (t
),
2296 tf_warning_or_error
);
2298 TARGET_EXPR_IMPLICIT_P (u
) = TARGET_EXPR_IMPLICIT_P (t
);
2299 TARGET_EXPR_LIST_INIT_P (u
) = TARGET_EXPR_LIST_INIT_P (t
);
2300 TARGET_EXPR_DIRECT_INIT_P (u
) = TARGET_EXPR_DIRECT_INIT_P (t
);
2302 /* Map the old variable to the new one. */
2303 splay_tree_insert (target_remap
,
2304 (splay_tree_key
) TREE_OPERAND (t
, 0),
2305 (splay_tree_value
) TREE_OPERAND (u
, 0));
2307 TREE_OPERAND (u
, 1) = break_out_target_exprs (TREE_OPERAND (u
, 1));
2309 /* Replace the old expression with the new version. */
2311 /* We don't have to go below this point; the recursive call to
2312 break_out_target_exprs will have handled anything below this
2318 /* Make a copy of this node. */
2319 t
= copy_tree_r (tp
, walk_subtrees
, NULL
);
2320 if (TREE_CODE (*tp
) == CALL_EXPR
)
2322 set_flags_from_callee (*tp
);
2324 /* builtin_LINE and builtin_FILE get the location where the default
2325 argument is expanded, not where the call was written. */
2326 tree callee
= get_callee_fndecl (*tp
);
2327 if (callee
&& DECL_BUILT_IN (callee
))
2328 switch (DECL_FUNCTION_CODE (callee
))
2332 SET_EXPR_LOCATION (*tp
, input_location
);
2338 /* Replace all remapped VAR_DECLs in T with their new equivalents.
2339 DATA is really a splay-tree mapping old variables to new
2343 bot_replace (tree
* t
, int* /*walk_subtrees*/, void* data
)
2345 splay_tree target_remap
= ((splay_tree
) data
);
2349 splay_tree_node n
= splay_tree_lookup (target_remap
,
2350 (splay_tree_key
) *t
);
2352 *t
= (tree
) n
->value
;
2354 else if (TREE_CODE (*t
) == PARM_DECL
2355 && DECL_NAME (*t
) == this_identifier
)
2357 /* In an NSDMI we need to replace the 'this' parameter we used for
2358 parsing with the real one for this function. */
2359 *t
= current_class_ptr
;
2361 else if (TREE_CODE (*t
) == CONVERT_EXPR
2362 && CONVERT_EXPR_VBASE_PATH (*t
))
2364 /* In an NSDMI build_base_path defers building conversions to virtual
2365 bases, and we handle it here. */
2366 tree basetype
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (*t
)));
2367 vec
<tree
, va_gc
> *vbases
= CLASSTYPE_VBASECLASSES (current_class_type
);
2369 FOR_EACH_VEC_SAFE_ELT (vbases
, i
, binfo
)
2370 if (BINFO_TYPE (binfo
) == basetype
)
2372 *t
= build_base_path (PLUS_EXPR
, TREE_OPERAND (*t
, 0), binfo
, true,
2373 tf_warning_or_error
);
2379 /* When we parse a default argument expression, we may create
2380 temporary variables via TARGET_EXPRs. When we actually use the
2381 default-argument expression, we make a copy of the expression
2382 and replace the temporaries with appropriate local versions. */
2385 break_out_target_exprs (tree t
)
2387 static int target_remap_count
;
2388 static splay_tree target_remap
;
2390 if (!target_remap_count
++)
2391 target_remap
= splay_tree_new (splay_tree_compare_pointers
,
2392 /*splay_tree_delete_key_fn=*/NULL
,
2393 /*splay_tree_delete_value_fn=*/NULL
);
2394 cp_walk_tree (&t
, bot_manip
, target_remap
, NULL
);
2395 cp_walk_tree (&t
, bot_replace
, target_remap
, NULL
);
2397 if (!--target_remap_count
)
2399 splay_tree_delete (target_remap
);
2400 target_remap
= NULL
;
2406 /* Similar to `build_nt', but for template definitions of dependent
2410 build_min_nt_loc (location_t loc
, enum tree_code code
, ...)
2417 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
2421 t
= make_node (code
);
2422 SET_EXPR_LOCATION (t
, loc
);
2423 length
= TREE_CODE_LENGTH (code
);
2425 for (i
= 0; i
< length
; i
++)
2427 tree x
= va_arg (p
, tree
);
2428 TREE_OPERAND (t
, i
) = x
;
2436 /* Similar to `build', but for template definitions. */
2439 build_min (enum tree_code code
, tree tt
, ...)
2446 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
2450 t
= make_node (code
);
2451 length
= TREE_CODE_LENGTH (code
);
2454 for (i
= 0; i
< length
; i
++)
2456 tree x
= va_arg (p
, tree
);
2457 TREE_OPERAND (t
, i
) = x
;
2458 if (x
&& !TYPE_P (x
) && TREE_SIDE_EFFECTS (x
))
2459 TREE_SIDE_EFFECTS (t
) = 1;
2466 /* Similar to `build', but for template definitions of non-dependent
2467 expressions. NON_DEP is the non-dependent expression that has been
2471 build_min_non_dep (enum tree_code code
, tree non_dep
, ...)
2478 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
2480 va_start (p
, non_dep
);
2482 if (REFERENCE_REF_P (non_dep
))
2483 non_dep
= TREE_OPERAND (non_dep
, 0);
2485 t
= make_node (code
);
2486 length
= TREE_CODE_LENGTH (code
);
2487 TREE_TYPE (t
) = TREE_TYPE (non_dep
);
2488 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (non_dep
);
2490 for (i
= 0; i
< length
; i
++)
2492 tree x
= va_arg (p
, tree
);
2493 TREE_OPERAND (t
, i
) = x
;
2496 if (code
== COMPOUND_EXPR
&& TREE_CODE (non_dep
) != COMPOUND_EXPR
)
2497 /* This should not be considered a COMPOUND_EXPR, because it
2498 resolves to an overload. */
2499 COMPOUND_EXPR_OVERLOADED (t
) = 1;
2502 return convert_from_reference (t
);
2505 /* Similar to `build_nt_call_vec', but for template definitions of
2506 non-dependent expressions. NON_DEP is the non-dependent expression
2507 that has been built. */
2510 build_min_non_dep_call_vec (tree non_dep
, tree fn
, vec
<tree
, va_gc
> *argvec
)
2512 tree t
= build_nt_call_vec (fn
, argvec
);
2513 if (REFERENCE_REF_P (non_dep
))
2514 non_dep
= TREE_OPERAND (non_dep
, 0);
2515 TREE_TYPE (t
) = TREE_TYPE (non_dep
);
2516 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (non_dep
);
2517 return convert_from_reference (t
);
2521 get_type_decl (tree t
)
2523 if (TREE_CODE (t
) == TYPE_DECL
)
2526 return TYPE_STUB_DECL (t
);
2527 gcc_assert (t
== error_mark_node
);
2531 /* Returns the namespace that contains DECL, whether directly or
2535 decl_namespace_context (tree decl
)
2539 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
2541 else if (TYPE_P (decl
))
2542 decl
= CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl
));
2544 decl
= CP_DECL_CONTEXT (decl
);
2548 /* Returns true if decl is within an anonymous namespace, however deeply
2549 nested, or false otherwise. */
2552 decl_anon_ns_mem_p (const_tree decl
)
2556 if (decl
== NULL_TREE
|| decl
== error_mark_node
)
2558 if (TREE_CODE (decl
) == NAMESPACE_DECL
2559 && DECL_NAME (decl
) == NULL_TREE
)
2561 /* Classes and namespaces inside anonymous namespaces have
2562 TREE_PUBLIC == 0, so we can shortcut the search. */
2563 else if (TYPE_P (decl
))
2564 return (TREE_PUBLIC (TYPE_MAIN_DECL (decl
)) == 0);
2565 else if (TREE_CODE (decl
) == NAMESPACE_DECL
)
2566 return (TREE_PUBLIC (decl
) == 0);
2568 decl
= DECL_CONTEXT (decl
);
2572 /* Subroutine of cp_tree_equal: t1 and t2 are the CALL_EXPR_FNs of two
2573 CALL_EXPRS. Return whether they are equivalent. */
2576 called_fns_equal (tree t1
, tree t2
)
2578 /* Core 1321: dependent names are equivalent even if the overload sets
2579 are different. But do compare explicit template arguments. */
2580 tree name1
= dependent_name (t1
);
2581 tree name2
= dependent_name (t2
);
2584 tree targs1
= NULL_TREE
, targs2
= NULL_TREE
;
2589 if (TREE_CODE (t1
) == TEMPLATE_ID_EXPR
)
2590 targs1
= TREE_OPERAND (t1
, 1);
2591 if (TREE_CODE (t2
) == TEMPLATE_ID_EXPR
)
2592 targs2
= TREE_OPERAND (t2
, 1);
2593 return cp_tree_equal (targs1
, targs2
);
2596 return cp_tree_equal (t1
, t2
);
2599 /* Return truthvalue of whether T1 is the same tree structure as T2.
2600 Return 1 if they are the same. Return 0 if they are different. */
2603 cp_tree_equal (tree t1
, tree t2
)
2605 enum tree_code code1
, code2
;
2612 for (code1
= TREE_CODE (t1
);
2613 CONVERT_EXPR_CODE_P (code1
)
2614 || code1
== NON_LVALUE_EXPR
;
2615 code1
= TREE_CODE (t1
))
2616 t1
= TREE_OPERAND (t1
, 0);
2617 for (code2
= TREE_CODE (t2
);
2618 CONVERT_EXPR_CODE_P (code2
)
2619 || code2
== NON_LVALUE_EXPR
;
2620 code2
= TREE_CODE (t2
))
2621 t2
= TREE_OPERAND (t2
, 0);
2623 /* They might have become equal now. */
2633 return TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
2634 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
);
2637 return REAL_VALUES_EQUAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2640 return TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2641 && !memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2642 TREE_STRING_LENGTH (t1
));
2645 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
),
2646 TREE_FIXED_CST (t2
));
2649 return cp_tree_equal (TREE_REALPART (t1
), TREE_REALPART (t2
))
2650 && cp_tree_equal (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
));
2653 return operand_equal_p (t1
, t2
, OEP_ONLY_CONST
);
2656 /* We need to do this when determining whether or not two
2657 non-type pointer to member function template arguments
2659 if (!same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
2660 || CONSTRUCTOR_NELTS (t1
) != CONSTRUCTOR_NELTS (t2
))
2665 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1
), i
, field
, value
)
2667 constructor_elt
*elt2
= CONSTRUCTOR_ELT (t2
, i
);
2668 if (!cp_tree_equal (field
, elt2
->index
)
2669 || !cp_tree_equal (value
, elt2
->value
))
2676 if (!cp_tree_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
)))
2678 if (!cp_tree_equal (TREE_VALUE (t1
), TREE_VALUE (t2
)))
2680 return cp_tree_equal (TREE_CHAIN (t1
), TREE_CHAIN (t2
));
2683 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2688 call_expr_arg_iterator iter1
, iter2
;
2689 if (!called_fns_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
)))
2691 for (arg1
= first_call_expr_arg (t1
, &iter1
),
2692 arg2
= first_call_expr_arg (t2
, &iter2
);
2694 arg1
= next_call_expr_arg (&iter1
),
2695 arg2
= next_call_expr_arg (&iter2
))
2696 if (!cp_tree_equal (arg1
, arg2
))
2705 tree o1
= TREE_OPERAND (t1
, 0);
2706 tree o2
= TREE_OPERAND (t2
, 0);
2708 /* Special case: if either target is an unallocated VAR_DECL,
2709 it means that it's going to be unified with whatever the
2710 TARGET_EXPR is really supposed to initialize, so treat it
2711 as being equivalent to anything. */
2712 if (VAR_P (o1
) && DECL_NAME (o1
) == NULL_TREE
2713 && !DECL_RTL_SET_P (o1
))
2715 else if (VAR_P (o2
) && DECL_NAME (o2
) == NULL_TREE
2716 && !DECL_RTL_SET_P (o2
))
2718 else if (!cp_tree_equal (o1
, o2
))
2721 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
2724 case WITH_CLEANUP_EXPR
:
2725 if (!cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0)))
2727 return cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
2730 if (TREE_OPERAND (t1
, 1) != TREE_OPERAND (t2
, 1))
2732 return cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2735 /* For comparing uses of parameters in late-specified return types
2736 with an out-of-class definition of the function, but can also come
2737 up for expressions that involve 'this' in a member function
2740 if (comparing_specializations
)
2741 /* When comparing hash table entries, only an exact match is
2742 good enough; we don't want to replace 'this' with the
2743 version from another function. */
2746 if (same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2748 if (DECL_ARTIFICIAL (t1
) ^ DECL_ARTIFICIAL (t2
))
2750 if (DECL_ARTIFICIAL (t1
)
2751 || (DECL_PARM_LEVEL (t1
) == DECL_PARM_LEVEL (t2
)
2752 && DECL_PARM_INDEX (t1
) == DECL_PARM_INDEX (t2
)))
2762 case IDENTIFIER_NODE
:
2767 return (BASELINK_BINFO (t1
) == BASELINK_BINFO (t2
)
2768 && BASELINK_ACCESS_BINFO (t1
) == BASELINK_ACCESS_BINFO (t2
)
2769 && BASELINK_QUALIFIED_P (t1
) == BASELINK_QUALIFIED_P (t2
)
2770 && cp_tree_equal (BASELINK_FUNCTIONS (t1
),
2771 BASELINK_FUNCTIONS (t2
)));
2773 case TEMPLATE_PARM_INDEX
:
2774 return (TEMPLATE_PARM_IDX (t1
) == TEMPLATE_PARM_IDX (t2
)
2775 && TEMPLATE_PARM_LEVEL (t1
) == TEMPLATE_PARM_LEVEL (t2
)
2776 && (TEMPLATE_PARM_PARAMETER_PACK (t1
)
2777 == TEMPLATE_PARM_PARAMETER_PACK (t2
))
2778 && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1
)),
2779 TREE_TYPE (TEMPLATE_PARM_DECL (t2
))));
2781 case TEMPLATE_ID_EXPR
:
2782 return (cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2783 && cp_tree_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2788 if (TREE_VEC_LENGTH (t1
) != TREE_VEC_LENGTH (t2
))
2790 for (ix
= TREE_VEC_LENGTH (t1
); ix
--;)
2791 if (!cp_tree_equal (TREE_VEC_ELT (t1
, ix
),
2792 TREE_VEC_ELT (t2
, ix
)))
2800 tree o1
= TREE_OPERAND (t1
, 0);
2801 tree o2
= TREE_OPERAND (t2
, 0);
2803 if (code1
== SIZEOF_EXPR
)
2805 if (SIZEOF_EXPR_TYPE_P (t1
))
2806 o1
= TREE_TYPE (o1
);
2807 if (SIZEOF_EXPR_TYPE_P (t2
))
2808 o2
= TREE_TYPE (o2
);
2810 if (TREE_CODE (o1
) != TREE_CODE (o2
))
2813 return same_type_p (o1
, o2
);
2815 return cp_tree_equal (o1
, o2
);
2820 tree t1_op1
, t2_op1
;
2822 if (!cp_tree_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0)))
2825 t1_op1
= TREE_OPERAND (t1
, 1);
2826 t2_op1
= TREE_OPERAND (t2
, 1);
2827 if (TREE_CODE (t1_op1
) != TREE_CODE (t2_op1
))
2830 return cp_tree_equal (TREE_OPERAND (t1
, 2), TREE_OPERAND (t2
, 2));
2834 /* Two pointer-to-members are the same if they point to the same
2835 field or function in the same class. */
2836 if (PTRMEM_CST_MEMBER (t1
) != PTRMEM_CST_MEMBER (t2
))
2839 return same_type_p (PTRMEM_CST_CLASS (t1
), PTRMEM_CST_CLASS (t2
));
2842 if (OVL_FUNCTION (t1
) != OVL_FUNCTION (t2
))
2844 return cp_tree_equal (OVL_CHAIN (t1
), OVL_CHAIN (t2
));
2847 if (TRAIT_EXPR_KIND (t1
) != TRAIT_EXPR_KIND (t2
))
2849 return same_type_p (TRAIT_EXPR_TYPE1 (t1
), TRAIT_EXPR_TYPE1 (t2
))
2850 && same_type_p (TRAIT_EXPR_TYPE2 (t1
), TRAIT_EXPR_TYPE2 (t2
));
2853 case STATIC_CAST_EXPR
:
2854 case REINTERPRET_CAST_EXPR
:
2855 case CONST_CAST_EXPR
:
2856 case DYNAMIC_CAST_EXPR
:
2857 case IMPLICIT_CONV_EXPR
:
2859 if (!same_type_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
2861 /* Now compare operands as usual. */
2864 case DEFERRED_NOEXCEPT
:
2865 return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1
),
2866 DEFERRED_NOEXCEPT_PATTERN (t2
))
2867 && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1
),
2868 DEFERRED_NOEXCEPT_ARGS (t2
)));
2875 switch (TREE_CODE_CLASS (code1
))
2879 case tcc_comparison
:
2880 case tcc_expression
:
2887 n
= cp_tree_operand_length (t1
);
2888 if (TREE_CODE_CLASS (code1
) == tcc_vl_exp
2889 && n
!= TREE_OPERAND_LENGTH (t2
))
2892 for (i
= 0; i
< n
; ++i
)
2893 if (!cp_tree_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
)))
2900 return same_type_p (t1
, t2
);
2904 /* We can get here with --disable-checking. */
2908 /* The type of ARG when used as an lvalue. */
2911 lvalue_type (tree arg
)
2913 tree type
= TREE_TYPE (arg
);
2917 /* The type of ARG for printing error messages; denote lvalues with
2921 error_type (tree arg
)
2923 tree type
= TREE_TYPE (arg
);
2925 if (TREE_CODE (type
) == ARRAY_TYPE
)
2927 else if (TREE_CODE (type
) == ERROR_MARK
)
2929 else if (real_lvalue_p (arg
))
2930 type
= build_reference_type (lvalue_type (arg
));
2931 else if (MAYBE_CLASS_TYPE_P (type
))
2932 type
= lvalue_type (arg
);
2937 /* Does FUNCTION use a variable-length argument list? */
2940 varargs_function_p (const_tree function
)
2942 return stdarg_p (TREE_TYPE (function
));
2945 /* Returns 1 if decl is a member of a class. */
2948 member_p (const_tree decl
)
2950 const_tree
const ctx
= DECL_CONTEXT (decl
);
2951 return (ctx
&& TYPE_P (ctx
));
2954 /* Create a placeholder for member access where we don't actually have an
2955 object that the access is against. */
2958 build_dummy_object (tree type
)
2960 tree decl
= build1 (NOP_EXPR
, build_pointer_type (type
), void_zero_node
);
2961 return cp_build_indirect_ref (decl
, RO_NULL
, tf_warning_or_error
);
2964 /* We've gotten a reference to a member of TYPE. Return *this if appropriate,
2965 or a dummy object otherwise. If BINFOP is non-0, it is filled with the
2966 binfo path from current_class_type to TYPE, or 0. */
2969 maybe_dummy_object (tree type
, tree
* binfop
)
2973 tree current
= current_nonlambda_class_type ();
2976 && (binfo
= lookup_base (current
, type
, ba_any
, NULL
,
2977 tf_warning_or_error
)))
2981 /* Reference from a nested class member function. */
2983 binfo
= TYPE_BINFO (type
);
2989 if (current_class_ref
2990 /* current_class_ref might not correspond to current_class_type if
2991 we're in tsubst_default_argument or a lambda-declarator; in either
2992 case, we want to use current_class_ref if it matches CONTEXT. */
2993 && (same_type_ignoring_top_level_qualifiers_p
2994 (TREE_TYPE (current_class_ref
), context
)))
2995 decl
= current_class_ref
;
2997 decl
= build_dummy_object (context
);
3002 /* Returns 1 if OB is a placeholder object, or a pointer to one. */
3005 is_dummy_object (const_tree ob
)
3007 if (INDIRECT_REF_P (ob
))
3008 ob
= TREE_OPERAND (ob
, 0);
3009 return (TREE_CODE (ob
) == NOP_EXPR
3010 && TREE_OPERAND (ob
, 0) == void_zero_node
);
3013 /* Returns 1 iff type T is something we want to treat as a scalar type for
3014 the purpose of deciding whether it is trivial/POD/standard-layout. */
3017 scalarish_type_p (const_tree t
)
3019 if (t
== error_mark_node
)
3022 return (SCALAR_TYPE_P (t
)
3023 || TREE_CODE (t
) == VECTOR_TYPE
);
3026 /* Returns true iff T requires non-trivial default initialization. */
3029 type_has_nontrivial_default_init (const_tree t
)
3031 t
= strip_array_types (CONST_CAST_TREE (t
));
3033 if (CLASS_TYPE_P (t
))
3034 return TYPE_HAS_COMPLEX_DFLT (t
);
3039 /* Returns true iff copying an object of type T (including via move
3040 constructor) is non-trivial. That is, T has no non-trivial copy
3041 constructors and no non-trivial move constructors. */
3044 type_has_nontrivial_copy_init (const_tree t
)
3046 t
= strip_array_types (CONST_CAST_TREE (t
));
3048 if (CLASS_TYPE_P (t
))
3050 gcc_assert (COMPLETE_TYPE_P (t
));
3051 return ((TYPE_HAS_COPY_CTOR (t
)
3052 && TYPE_HAS_COMPLEX_COPY_CTOR (t
))
3053 || TYPE_HAS_COMPLEX_MOVE_CTOR (t
));
3059 /* Returns 1 iff type T is a trivially copyable type, as defined in
3060 [basic.types] and [class]. */
3063 trivially_copyable_p (const_tree t
)
3065 t
= strip_array_types (CONST_CAST_TREE (t
));
3067 if (CLASS_TYPE_P (t
))
3068 return ((!TYPE_HAS_COPY_CTOR (t
)
3069 || !TYPE_HAS_COMPLEX_COPY_CTOR (t
))
3070 && !TYPE_HAS_COMPLEX_MOVE_CTOR (t
)
3071 && (!TYPE_HAS_COPY_ASSIGN (t
)
3072 || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t
))
3073 && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t
)
3074 && TYPE_HAS_TRIVIAL_DESTRUCTOR (t
));
3076 return scalarish_type_p (t
);
3079 /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
3083 trivial_type_p (const_tree t
)
3085 t
= strip_array_types (CONST_CAST_TREE (t
));
3087 if (CLASS_TYPE_P (t
))
3088 return (TYPE_HAS_TRIVIAL_DFLT (t
)
3089 && trivially_copyable_p (t
));
3091 return scalarish_type_p (t
);
3094 /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */
3097 pod_type_p (const_tree t
)
3099 /* This CONST_CAST is okay because strip_array_types returns its
3100 argument unmodified and we assign it to a const_tree. */
3101 t
= strip_array_types (CONST_CAST_TREE(t
));
3103 if (!CLASS_TYPE_P (t
))
3104 return scalarish_type_p (t
);
3105 else if (cxx_dialect
> cxx98
)
3106 /* [class]/10: A POD struct is a class that is both a trivial class and a
3107 standard-layout class, and has no non-static data members of type
3108 non-POD struct, non-POD union (or array of such types).
3110 We don't need to check individual members because if a member is
3111 non-std-layout or non-trivial, the class will be too. */
3112 return (std_layout_type_p (t
) && trivial_type_p (t
));
3114 /* The C++98 definition of POD is different. */
3115 return !CLASSTYPE_NON_LAYOUT_POD_P (t
);
3118 /* Returns true iff T is POD for the purpose of layout, as defined in the
3122 layout_pod_type_p (const_tree t
)
3124 t
= strip_array_types (CONST_CAST_TREE (t
));
3126 if (CLASS_TYPE_P (t
))
3127 return !CLASSTYPE_NON_LAYOUT_POD_P (t
);
3129 return scalarish_type_p (t
);
3132 /* Returns true iff T is a standard-layout type, as defined in
3136 std_layout_type_p (const_tree t
)
3138 t
= strip_array_types (CONST_CAST_TREE (t
));
3140 if (CLASS_TYPE_P (t
))
3141 return !CLASSTYPE_NON_STD_LAYOUT (t
);
3143 return scalarish_type_p (t
);
3146 /* Nonzero iff type T is a class template implicit specialization. */
3149 class_tmpl_impl_spec_p (const_tree t
)
3151 return CLASS_TYPE_P (t
) && CLASSTYPE_TEMPLATE_INSTANTIATION (t
);
3154 /* Returns 1 iff zero initialization of type T means actually storing
3158 zero_init_p (const_tree t
)
3160 /* This CONST_CAST is okay because strip_array_types returns its
3161 argument unmodified and we assign it to a const_tree. */
3162 t
= strip_array_types (CONST_CAST_TREE(t
));
3164 if (t
== error_mark_node
)
3167 /* NULL pointers to data members are initialized with -1. */
3168 if (TYPE_PTRDATAMEM_P (t
))
3171 /* Classes that contain types that can't be zero-initialized, cannot
3172 be zero-initialized themselves. */
3173 if (CLASS_TYPE_P (t
) && CLASSTYPE_NON_ZERO_INIT_P (t
))
3179 /* Table of valid C++ attributes. */
3180 const struct attribute_spec cxx_attribute_table
[] =
3182 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
3183 affects_type_identity } */
3184 { "java_interface", 0, 0, false, false, false,
3185 handle_java_interface_attribute
, false },
3186 { "com_interface", 0, 0, false, false, false,
3187 handle_com_interface_attribute
, false },
3188 { "init_priority", 1, 1, true, false, false,
3189 handle_init_priority_attribute
, false },
3190 { "abi_tag", 1, -1, false, false, false,
3191 handle_abi_tag_attribute
, true },
3192 { NULL
, 0, 0, false, false, false, NULL
, false }
3195 /* Handle a "java_interface" attribute; arguments as in
3196 struct attribute_spec.handler. */
3198 handle_java_interface_attribute (tree
* node
,
3205 || !CLASS_TYPE_P (*node
)
3206 || !TYPE_FOR_JAVA (*node
))
3208 error ("%qE attribute can only be applied to Java class definitions",
3210 *no_add_attrs
= true;
3213 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
3214 *node
= build_variant_type_copy (*node
);
3215 TYPE_JAVA_INTERFACE (*node
) = 1;
3220 /* Handle a "com_interface" attribute; arguments as in
3221 struct attribute_spec.handler. */
3223 handle_com_interface_attribute (tree
* node
,
3231 *no_add_attrs
= true;
3234 || !CLASS_TYPE_P (*node
)
3235 || *node
!= TYPE_MAIN_VARIANT (*node
))
3237 warning (OPT_Wattributes
, "%qE attribute can only be applied "
3238 "to class definitions", name
);
3243 warning (0, "%qE is obsolete; g++ vtables are now COM-compatible by default",
3249 /* Handle an "init_priority" attribute; arguments as in
3250 struct attribute_spec.handler. */
3252 handle_init_priority_attribute (tree
* node
,
3258 tree initp_expr
= TREE_VALUE (args
);
3260 tree type
= TREE_TYPE (decl
);
3263 STRIP_NOPS (initp_expr
);
3264 initp_expr
= default_conversion (initp_expr
);
3266 if (!initp_expr
|| TREE_CODE (initp_expr
) != INTEGER_CST
)
3268 error ("requested init_priority is not an integer constant");
3269 *no_add_attrs
= true;
3273 pri
= TREE_INT_CST_LOW (initp_expr
);
3275 type
= strip_array_types (type
);
3277 if (decl
== NULL_TREE
3279 || !TREE_STATIC (decl
)
3280 || DECL_EXTERNAL (decl
)
3281 || (TREE_CODE (type
) != RECORD_TYPE
3282 && TREE_CODE (type
) != UNION_TYPE
)
3283 /* Static objects in functions are initialized the
3284 first time control passes through that
3285 function. This is not precise enough to pin down an
3286 init_priority value, so don't allow it. */
3287 || current_function_decl
)
3289 error ("can only use %qE attribute on file-scope definitions "
3290 "of objects of class type", name
);
3291 *no_add_attrs
= true;
3295 if (pri
> MAX_INIT_PRIORITY
|| pri
<= 0)
3297 error ("requested init_priority is out of range");
3298 *no_add_attrs
= true;
3302 /* Check for init_priorities that are reserved for
3303 language and runtime support implementations.*/
3304 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
3307 (0, "requested init_priority is reserved for internal use");
3310 if (SUPPORTS_INIT_PRIORITY
)
3312 SET_DECL_INIT_PRIORITY (decl
, pri
);
3313 DECL_HAS_INIT_PRIORITY_P (decl
) = 1;
3318 error ("%qE attribute is not supported on this platform", name
);
3319 *no_add_attrs
= true;
3324 /* DECL is being redeclared; the old declaration had the abi tags in OLD,
3325 and the new one has the tags in NEW_. Give an error if there are tags
3326 in NEW_ that weren't in OLD. */
3329 check_abi_tag_redeclaration (const_tree decl
, const_tree old
, const_tree new_
)
3331 if (old
&& TREE_CODE (TREE_VALUE (old
)) == TREE_LIST
)
3332 old
= TREE_VALUE (old
);
3333 if (new_
&& TREE_CODE (TREE_VALUE (new_
)) == TREE_LIST
)
3334 new_
= TREE_VALUE (new_
);
3336 for (const_tree t
= new_
; t
; t
= TREE_CHAIN (t
))
3338 tree str
= TREE_VALUE (t
);
3339 for (const_tree in
= old
; in
; in
= TREE_CHAIN (in
))
3341 tree ostr
= TREE_VALUE (in
);
3342 if (cp_tree_equal (str
, ostr
))
3345 error ("redeclaration of %qD adds abi tag %E", decl
, str
);
3351 inform (DECL_SOURCE_LOCATION (decl
), "previous declaration here");
3357 /* Handle an "abi_tag" attribute; arguments as in
3358 struct attribute_spec.handler. */
3361 handle_abi_tag_attribute (tree
* node
, tree name
, tree args
,
3362 int flags
, bool* no_add_attrs
)
3366 if (!OVERLOAD_TYPE_P (*node
))
3368 error ("%qE attribute applied to non-class, non-enum type %qT",
3372 else if (!(flags
& (int)ATTR_FLAG_TYPE_IN_PLACE
))
3374 error ("%qE attribute applied to %qT after its definition",
3378 else if (CLASSTYPE_TEMPLATE_INSTANTIATION (*node
))
3380 warning (OPT_Wattributes
, "ignoring %qE attribute applied to "
3381 "template instantiation %qT", name
, *node
);
3384 else if (CLASSTYPE_TEMPLATE_SPECIALIZATION (*node
))
3386 warning (OPT_Wattributes
, "ignoring %qE attribute applied to "
3387 "template specialization %qT", name
, *node
);
3391 tree attributes
= TYPE_ATTRIBUTES (*node
);
3392 tree decl
= TYPE_NAME (*node
);
3394 /* Make sure all declarations have the same abi tags. */
3395 if (DECL_SOURCE_LOCATION (decl
) != input_location
)
3397 if (!check_abi_tag_redeclaration (decl
,
3398 lookup_attribute ("abi_tag",
3406 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3408 error ("%qE attribute applied to non-function %qD", name
, *node
);
3411 else if (DECL_LANGUAGE (*node
) == lang_c
)
3413 error ("%qE attribute applied to extern \"C\" function %qD",
3422 *no_add_attrs
= true;
3426 /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the
3427 thing pointed to by the constant. */
3430 make_ptrmem_cst (tree type
, tree member
)
3432 tree ptrmem_cst
= make_node (PTRMEM_CST
);
3433 TREE_TYPE (ptrmem_cst
) = type
;
3434 PTRMEM_CST_MEMBER (ptrmem_cst
) = member
;
3438 /* Build a variant of TYPE that has the indicated ATTRIBUTES. May
3439 return an existing type if an appropriate type already exists. */
3442 cp_build_type_attribute_variant (tree type
, tree attributes
)
3446 new_type
= build_type_attribute_variant (type
, attributes
);
3447 if (TREE_CODE (new_type
) == FUNCTION_TYPE
3448 || TREE_CODE (new_type
) == METHOD_TYPE
)
3450 new_type
= build_exception_variant (new_type
,
3451 TYPE_RAISES_EXCEPTIONS (type
));
3452 new_type
= build_ref_qualified_type (new_type
,
3453 type_memfn_rqual (type
));
3456 /* Making a new main variant of a class type is broken. */
3457 gcc_assert (!CLASS_TYPE_P (type
) || new_type
== type
);
3462 /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
3463 Called only after doing all language independent checks. Only
3464 to check TYPE_RAISES_EXCEPTIONS for FUNCTION_TYPE, the rest is already
3465 compared in type_hash_eq. */
3468 cxx_type_hash_eq (const_tree typea
, const_tree typeb
)
3470 gcc_assert (TREE_CODE (typea
) == FUNCTION_TYPE
3471 || TREE_CODE (typea
) == METHOD_TYPE
);
3473 return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea
),
3474 TYPE_RAISES_EXCEPTIONS (typeb
), ce_exact
);
3477 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
3478 traversal. Called from walk_tree. */
3481 cp_walk_subtrees (tree
*tp
, int *walk_subtrees_p
, walk_tree_fn func
,
3482 void *data
, struct pointer_set_t
*pset
)
3484 enum tree_code code
= TREE_CODE (*tp
);
3487 #define WALK_SUBTREE(NODE) \
3490 result = cp_walk_tree (&(NODE), func, data, pset); \
3491 if (result) goto out; \
3495 /* Not one of the easy cases. We must explicitly go through the
3501 case TEMPLATE_TEMPLATE_PARM
:
3502 case BOUND_TEMPLATE_TEMPLATE_PARM
:
3503 case UNBOUND_CLASS_TEMPLATE
:
3504 case TEMPLATE_PARM_INDEX
:
3505 case TEMPLATE_TYPE_PARM
:
3508 case UNDERLYING_TYPE
:
3509 /* None of these have subtrees other than those already walked
3511 *walk_subtrees_p
= 0;
3515 WALK_SUBTREE (BASELINK_FUNCTIONS (*tp
));
3516 *walk_subtrees_p
= 0;
3520 WALK_SUBTREE (TREE_TYPE (*tp
));
3521 *walk_subtrees_p
= 0;
3525 WALK_SUBTREE (TREE_PURPOSE (*tp
));
3529 WALK_SUBTREE (OVL_FUNCTION (*tp
));
3530 WALK_SUBTREE (OVL_CHAIN (*tp
));
3531 *walk_subtrees_p
= 0;
3535 WALK_SUBTREE (DECL_NAME (*tp
));
3536 WALK_SUBTREE (USING_DECL_SCOPE (*tp
));
3537 WALK_SUBTREE (USING_DECL_DECLS (*tp
));
3538 *walk_subtrees_p
= 0;
3542 if (TYPE_PTRMEMFUNC_P (*tp
))
3543 WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp
));
3546 case TYPE_ARGUMENT_PACK
:
3547 case NONTYPE_ARGUMENT_PACK
:
3549 tree args
= ARGUMENT_PACK_ARGS (*tp
);
3550 int i
, len
= TREE_VEC_LENGTH (args
);
3551 for (i
= 0; i
< len
; i
++)
3552 WALK_SUBTREE (TREE_VEC_ELT (args
, i
));
3556 case TYPE_PACK_EXPANSION
:
3557 WALK_SUBTREE (TREE_TYPE (*tp
));
3558 WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp
));
3559 *walk_subtrees_p
= 0;
3562 case EXPR_PACK_EXPANSION
:
3563 WALK_SUBTREE (TREE_OPERAND (*tp
, 0));
3564 WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp
));
3565 *walk_subtrees_p
= 0;
3569 case REINTERPRET_CAST_EXPR
:
3570 case STATIC_CAST_EXPR
:
3571 case CONST_CAST_EXPR
:
3572 case DYNAMIC_CAST_EXPR
:
3573 case IMPLICIT_CONV_EXPR
:
3574 if (TREE_TYPE (*tp
))
3575 WALK_SUBTREE (TREE_TYPE (*tp
));
3579 for (i
= 0; i
< TREE_CODE_LENGTH (TREE_CODE (*tp
)); ++i
)
3580 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
3582 *walk_subtrees_p
= 0;
3586 WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp
));
3587 WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp
));
3588 *walk_subtrees_p
= 0;
3592 WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp
));
3593 *walk_subtrees_p
= 0;
3601 /* We didn't find what we were looking for. */
3608 /* Like save_expr, but for C++. */
3611 cp_save_expr (tree expr
)
3613 /* There is no reason to create a SAVE_EXPR within a template; if
3614 needed, we can create the SAVE_EXPR when instantiating the
3615 template. Furthermore, the middle-end cannot handle C++-specific
3617 if (processing_template_decl
)
3619 return save_expr (expr
);
3622 /* Initialize tree.c. */
3627 list_hash_table
= htab_create_ggc (31, list_hash
, list_hash_eq
, NULL
);
3630 /* Returns the kind of special function that DECL (a FUNCTION_DECL)
3631 is. Note that sfk_none is zero, so this function can be used as a
3632 predicate to test whether or not DECL is a special function. */
3634 special_function_kind
3635 special_function_p (const_tree decl
)
3637 /* Rather than doing all this stuff with magic names, we should
3638 probably have a field of type `special_function_kind' in
3639 DECL_LANG_SPECIFIC. */
3640 if (DECL_INHERITED_CTOR_BASE (decl
))
3641 return sfk_inheriting_constructor
;
3642 if (DECL_COPY_CONSTRUCTOR_P (decl
))
3643 return sfk_copy_constructor
;
3644 if (DECL_MOVE_CONSTRUCTOR_P (decl
))
3645 return sfk_move_constructor
;
3646 if (DECL_CONSTRUCTOR_P (decl
))
3647 return sfk_constructor
;
3648 if (DECL_OVERLOADED_OPERATOR_P (decl
) == NOP_EXPR
)
3650 if (copy_fn_p (decl
))
3651 return sfk_copy_assignment
;
3652 if (move_fn_p (decl
))
3653 return sfk_move_assignment
;
3655 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl
))
3656 return sfk_destructor
;
3657 if (DECL_COMPLETE_DESTRUCTOR_P (decl
))
3658 return sfk_complete_destructor
;
3659 if (DECL_BASE_DESTRUCTOR_P (decl
))
3660 return sfk_base_destructor
;
3661 if (DECL_DELETING_DESTRUCTOR_P (decl
))
3662 return sfk_deleting_destructor
;
3663 if (DECL_CONV_FN_P (decl
))
3664 return sfk_conversion
;
3669 /* Returns nonzero if TYPE is a character type, including wchar_t. */
3672 char_type_p (tree type
)
3674 return (same_type_p (type
, char_type_node
)
3675 || same_type_p (type
, unsigned_char_type_node
)
3676 || same_type_p (type
, signed_char_type_node
)
3677 || same_type_p (type
, char16_type_node
)
3678 || same_type_p (type
, char32_type_node
)
3679 || same_type_p (type
, wchar_type_node
));
3682 /* Returns the kind of linkage associated with the indicated DECL. Th
3683 value returned is as specified by the language standard; it is
3684 independent of implementation details regarding template
3685 instantiation, etc. For example, it is possible that a declaration
3686 to which this function assigns external linkage would not show up
3687 as a global symbol when you run `nm' on the resulting object file. */
3690 decl_linkage (tree decl
)
3692 /* This function doesn't attempt to calculate the linkage from first
3693 principles as given in [basic.link]. Instead, it makes use of
3694 the fact that we have already set TREE_PUBLIC appropriately, and
3695 then handles a few special cases. Ideally, we would calculate
3696 linkage first, and then transform that into a concrete
3699 /* Things that don't have names have no linkage. */
3700 if (!DECL_NAME (decl
))
3703 /* Fields have no linkage. */
3704 if (TREE_CODE (decl
) == FIELD_DECL
)
3707 /* Things that are TREE_PUBLIC have external linkage. */
3708 if (TREE_PUBLIC (decl
))
3711 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3714 /* Linkage of a CONST_DECL depends on the linkage of the enumeration
3716 if (TREE_CODE (decl
) == CONST_DECL
)
3717 return decl_linkage (TYPE_NAME (DECL_CONTEXT (decl
)));
3719 /* Some things that are not TREE_PUBLIC have external linkage, too.
3720 For example, on targets that don't have weak symbols, we make all
3721 template instantiations have internal linkage (in the object
3722 file), but the symbols should still be treated as having external
3723 linkage from the point of view of the language. */
3724 if (VAR_OR_FUNCTION_DECL_P (decl
)
3725 && DECL_COMDAT (decl
))
3728 /* Things in local scope do not have linkage, if they don't have
3730 if (decl_function_context (decl
))
3733 /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
3734 are considered to have external linkage for language purposes. DECLs
3735 really meant to have internal linkage have DECL_THIS_STATIC set. */
3736 if (TREE_CODE (decl
) == TYPE_DECL
)
3738 if (VAR_OR_FUNCTION_DECL_P (decl
))
3740 if (!DECL_THIS_STATIC (decl
))
3743 /* Static data members and static member functions from classes
3744 in anonymous namespace also don't have TREE_PUBLIC set. */
3745 if (DECL_CLASS_CONTEXT (decl
))
3749 /* Everything else has internal linkage. */
3753 /* Returns the storage duration of the object or reference associated with
3754 the indicated DECL, which should be a VAR_DECL or PARM_DECL. */
3757 decl_storage_duration (tree decl
)
3759 if (TREE_CODE (decl
) == PARM_DECL
)
3761 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3763 gcc_assert (VAR_P (decl
));
3764 if (!TREE_STATIC (decl
)
3765 && !DECL_EXTERNAL (decl
))
3767 if (DECL_THREAD_LOCAL_P (decl
))
3772 /* EXP is an expression that we want to pre-evaluate. Returns (in
3773 *INITP) an expression that will perform the pre-evaluation. The
3774 value returned by this function is a side-effect free expression
3775 equivalent to the pre-evaluated expression. Callers must ensure
3776 that *INITP is evaluated before EXP. */
3779 stabilize_expr (tree exp
, tree
* initp
)
3783 if (!TREE_SIDE_EFFECTS (exp
))
3784 init_expr
= NULL_TREE
;
3785 else if (VOID_TYPE_P (TREE_TYPE (exp
)))
3788 exp
= void_zero_node
;
3790 /* There are no expressions with REFERENCE_TYPE, but there can be call
3791 arguments with such a type; just treat it as a pointer. */
3792 else if (TREE_CODE (TREE_TYPE (exp
)) == REFERENCE_TYPE
3793 || SCALAR_TYPE_P (TREE_TYPE (exp
))
3794 || !lvalue_or_rvalue_with_address_p (exp
))
3796 init_expr
= get_target_expr (exp
);
3797 exp
= TARGET_EXPR_SLOT (init_expr
);
3798 if (CLASS_TYPE_P (TREE_TYPE (exp
)))
3805 bool xval
= !real_lvalue_p (exp
);
3806 exp
= cp_build_addr_expr (exp
, tf_warning_or_error
);
3807 init_expr
= get_target_expr (exp
);
3808 exp
= TARGET_EXPR_SLOT (init_expr
);
3809 exp
= cp_build_indirect_ref (exp
, RO_NULL
, tf_warning_or_error
);
3815 gcc_assert (!TREE_SIDE_EFFECTS (exp
));
3819 /* Add NEW_EXPR, an expression whose value we don't care about, after the
3820 similar expression ORIG. */
3823 add_stmt_to_compound (tree orig
, tree new_expr
)
3825 if (!new_expr
|| !TREE_SIDE_EFFECTS (new_expr
))
3827 if (!orig
|| !TREE_SIDE_EFFECTS (orig
))
3829 return build2 (COMPOUND_EXPR
, void_type_node
, orig
, new_expr
);
3832 /* Like stabilize_expr, but for a call whose arguments we want to
3833 pre-evaluate. CALL is modified in place to use the pre-evaluated
3834 arguments, while, upon return, *INITP contains an expression to
3835 compute the arguments. */
3838 stabilize_call (tree call
, tree
*initp
)
3840 tree inits
= NULL_TREE
;
3842 int nargs
= call_expr_nargs (call
);
3844 if (call
== error_mark_node
|| processing_template_decl
)
3850 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
3852 for (i
= 0; i
< nargs
; i
++)
3855 CALL_EXPR_ARG (call
, i
) =
3856 stabilize_expr (CALL_EXPR_ARG (call
, i
), &init
);
3857 inits
= add_stmt_to_compound (inits
, init
);
3863 /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
3864 to pre-evaluate. CALL is modified in place to use the pre-evaluated
3865 arguments, while, upon return, *INITP contains an expression to
3866 compute the arguments. */
3869 stabilize_aggr_init (tree call
, tree
*initp
)
3871 tree inits
= NULL_TREE
;
3873 int nargs
= aggr_init_expr_nargs (call
);
3875 if (call
== error_mark_node
)
3878 gcc_assert (TREE_CODE (call
) == AGGR_INIT_EXPR
);
3880 for (i
= 0; i
< nargs
; i
++)
3883 AGGR_INIT_EXPR_ARG (call
, i
) =
3884 stabilize_expr (AGGR_INIT_EXPR_ARG (call
, i
), &init
);
3885 inits
= add_stmt_to_compound (inits
, init
);
3891 /* Like stabilize_expr, but for an initialization.
3893 If the initialization is for an object of class type, this function
3894 takes care not to introduce additional temporaries.
3896 Returns TRUE iff the expression was successfully pre-evaluated,
3897 i.e., if INIT is now side-effect free, except for, possibly, a
3898 single call to a constructor. */
3901 stabilize_init (tree init
, tree
*initp
)
3907 if (t
== error_mark_node
|| processing_template_decl
)
3910 if (TREE_CODE (t
) == INIT_EXPR
)
3911 t
= TREE_OPERAND (t
, 1);
3912 if (TREE_CODE (t
) == TARGET_EXPR
)
3913 t
= TARGET_EXPR_INITIAL (t
);
3915 /* If the RHS can be stabilized without breaking copy elision, stabilize
3916 it. We specifically don't stabilize class prvalues here because that
3917 would mean an extra copy, but they might be stabilized below. */
3918 if (TREE_CODE (init
) == INIT_EXPR
3919 && TREE_CODE (t
) != CONSTRUCTOR
3920 && TREE_CODE (t
) != AGGR_INIT_EXPR
3921 && (SCALAR_TYPE_P (TREE_TYPE (t
))
3922 || lvalue_or_rvalue_with_address_p (t
)))
3924 TREE_OPERAND (init
, 1) = stabilize_expr (t
, initp
);
3928 if (TREE_CODE (t
) == COMPOUND_EXPR
3929 && TREE_CODE (init
) == INIT_EXPR
)
3931 tree last
= expr_last (t
);
3932 /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */
3933 if (!TREE_SIDE_EFFECTS (last
))
3936 TREE_OPERAND (init
, 1) = last
;
3941 if (TREE_CODE (t
) == CONSTRUCTOR
)
3943 /* Aggregate initialization: stabilize each of the field
3946 constructor_elt
*ce
;
3948 vec
<constructor_elt
, va_gc
> *v
= CONSTRUCTOR_ELTS (t
);
3949 for (i
= 0; vec_safe_iterate (v
, i
, &ce
); ++i
)
3951 tree type
= TREE_TYPE (ce
->value
);
3953 if (TREE_CODE (type
) == REFERENCE_TYPE
3954 || SCALAR_TYPE_P (type
))
3955 ce
->value
= stabilize_expr (ce
->value
, &subinit
);
3956 else if (!stabilize_init (ce
->value
, &subinit
))
3958 *initp
= add_stmt_to_compound (*initp
, subinit
);
3963 if (TREE_CODE (t
) == CALL_EXPR
)
3965 stabilize_call (t
, initp
);
3969 if (TREE_CODE (t
) == AGGR_INIT_EXPR
)
3971 stabilize_aggr_init (t
, initp
);
3975 /* The initialization is being performed via a bitwise copy -- and
3976 the item copied may have side effects. */
3977 return !TREE_SIDE_EFFECTS (init
);
3980 /* Like "fold", but should be used whenever we might be processing the
3981 body of a template. */
3984 fold_if_not_in_template (tree expr
)
3986 /* In the body of a template, there is never any need to call
3987 "fold". We will call fold later when actually instantiating the
3988 template. Integral constant expressions in templates will be
3989 evaluated via fold_non_dependent_expr, as necessary. */
3990 if (processing_template_decl
)
3993 /* Fold C++ front-end specific tree codes. */
3994 if (TREE_CODE (expr
) == UNARY_PLUS_EXPR
)
3995 return fold_convert (TREE_TYPE (expr
), TREE_OPERAND (expr
, 0));
4000 /* Returns true if a cast to TYPE may appear in an integral constant
4004 cast_valid_in_integral_constant_expression_p (tree type
)
4006 return (INTEGRAL_OR_ENUMERATION_TYPE_P (type
)
4007 || cxx_dialect
>= cxx11
4008 || dependent_type_p (type
)
4009 || type
== error_mark_node
);
4012 /* Return true if we need to fix linkage information of DECL. */
4015 cp_fix_function_decl_p (tree decl
)
4017 /* Skip if DECL is not externally visible. */
4018 if (!TREE_PUBLIC (decl
))
4021 /* We need to fix DECL if it a appears to be exported but with no
4022 function body. Thunks do not have CFGs and we may need to
4023 handle them specially later. */
4024 if (!gimple_has_body_p (decl
)
4025 && !DECL_THUNK_P (decl
)
4026 && !DECL_EXTERNAL (decl
))
4028 struct cgraph_node
*node
= cgraph_get_node (decl
);
4030 /* Don't fix same_body aliases. Although they don't have their own
4031 CFG, they share it with what they alias to. */
4032 if (!node
|| !node
->alias
4033 || !vec_safe_length (node
->ref_list
.references
))
4040 /* Clean the C++ specific parts of the tree T. */
4043 cp_free_lang_data (tree t
)
4045 if (TREE_CODE (t
) == METHOD_TYPE
4046 || TREE_CODE (t
) == FUNCTION_TYPE
)
4048 /* Default args are not interesting anymore. */
4049 tree argtypes
= TYPE_ARG_TYPES (t
);
4052 TREE_PURPOSE (argtypes
) = 0;
4053 argtypes
= TREE_CHAIN (argtypes
);
4056 else if (TREE_CODE (t
) == FUNCTION_DECL
4057 && cp_fix_function_decl_p (t
))
4059 /* If T is used in this translation unit at all, the definition
4060 must exist somewhere else since we have decided to not emit it
4061 in this TU. So make it an external reference. */
4062 DECL_EXTERNAL (t
) = 1;
4063 TREE_STATIC (t
) = 0;
4065 if (TREE_CODE (t
) == NAMESPACE_DECL
)
4067 /* The list of users of a namespace isn't useful for the middle-end
4068 or debug generators. */
4069 DECL_NAMESPACE_USERS (t
) = NULL_TREE
;
4070 /* Neither do we need the leftover chaining of namespaces
4071 from the binding level. */
4072 DECL_CHAIN (t
) = NULL_TREE
;
4076 /* Stub for c-common. Please keep in sync with c-decl.c.
4077 FIXME: If address space support is target specific, then this
4078 should be a C target hook. But currently this is not possible,
4079 because this function is called via REGISTER_TARGET_PRAGMAS. */
4081 c_register_addr_space (const char * /*word*/, addr_space_t
/*as*/)
4085 /* Return the number of operands in T that we care about for things like
4089 cp_tree_operand_length (const_tree t
)
4091 enum tree_code code
= TREE_CODE (t
);
4095 case PREINCREMENT_EXPR
:
4096 case PREDECREMENT_EXPR
:
4097 case POSTINCREMENT_EXPR
:
4098 case POSTDECREMENT_EXPR
:
4104 case EXPR_PACK_EXPANSION
:
4108 return TREE_OPERAND_LENGTH (t
);
4112 /* Implement -Wzero_as_null_pointer_constant. Return true if the
4113 conditions for the warning hold, false otherwise. */
4115 maybe_warn_zero_as_null_pointer_constant (tree expr
, location_t loc
)
4117 if (c_inhibit_evaluation_warnings
== 0
4118 && !NULLPTR_TYPE_P (TREE_TYPE (expr
)))
4120 warning_at (loc
, OPT_Wzero_as_null_pointer_constant
,
4121 "zero as null pointer constant");
4127 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
4128 /* Complain that some language-specific thing hanging off a tree
4129 node has been accessed improperly. */
4132 lang_check_failed (const char* file
, int line
, const char* function
)
4134 internal_error ("lang_* check: failed in %s, at %s:%d",
4135 function
, trim_filename (file
), line
);
4137 #endif /* ENABLE_TREE_CHECKING */
4139 #include "gt-cp-tree.h"